Help us shape the future of Go! Take the 2026 Go Developer Survey

streaming

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("streaming bus is closed")

Functions

This section is empty.

Types

type Bus

type Bus interface {
	Publisher
	Subscriber
}

type Event

type Event struct {
	ID                   string                 `json:"id,omitempty"`
	StreamID             string                 `json:"streamId,omitempty"`
	ConversationID       string                 `json:"conversationId,omitempty"`
	TurnID               string                 `json:"turnId,omitempty"`
	AgentIDUsed          string                 `json:"agentIdUsed,omitempty"`
	AgentName            string                 `json:"agentName,omitempty"`
	AssistantMessageID   string                 `json:"assistantMessageId,omitempty"`
	ParentMessageID      string                 `json:"parentMessageId,omitempty"`
	RequestID            string                 `json:"requestId,omitempty"`
	ResponseID           string                 `json:"responseId,omitempty"`
	ToolCallID           string                 `json:"toolCallId,omitempty"`
	ToolMessageID        string                 `json:"toolMessageId,omitempty"`
	RequestPayloadID     string                 `json:"requestPayloadId,omitempty"`
	ResponsePayloadID    string                 `json:"responsePayloadId,omitempty"`
	LinkedConversationID string                 `json:"linkedConversationId,omitempty"`
	Type                 EventType              `json:"type"`
	Op                   string                 `json:"op,omitempty"`
	Patch                map[string]interface{} `json:"patch,omitempty"`
	Content              string                 `json:"content,omitempty"`
	Preamble             string                 `json:"preamble,omitempty"`
	ToolName             string                 `json:"toolName,omitempty"`
	Arguments            map[string]interface{} `json:"arguments,omitempty"`
	Error                string                 `json:"error,omitempty"`
	Status               string                 `json:"status,omitempty"`
	Iteration            int                    `json:"iteration,omitempty"`
	PageIndex            int                    `json:"pageIndex,omitempty"`
	PageCount            int                    `json:"pageCount,omitempty"`
	LatestPage           bool                   `json:"latestPage,omitempty"`
	FinalResponse        bool                   `json:"finalResponse,omitempty"`
	Model                *EventModel            `json:"model,omitempty"`
	ToolCallsPlanned     []PlannedToolCall      `json:"toolCallsPlanned,omitempty"`
	CreatedAt            time.Time              `json:"createdAt,omitempty"`
	ElicitationID        string                 `json:"elicitationId,omitempty"`
	ElicitationData      map[string]interface{} `json:"elicitationData,omitempty"`
	CallbackURL          string                 `json:"callbackUrl,omitempty"`
	ResponsePayload      map[string]interface{} `json:"responsePayload,omitempty"`
	CompletedAt          *time.Time             `json:"completedAt,omitempty"`
	StartedAt            *time.Time             `json:"startedAt,omitempty"`
	UserMessageID        string                 `json:"userMessageId,omitempty"`
	ModelCallID          string                 `json:"modelCallId,omitempty"`
	Provider             string                 `json:"provider,omitempty"`
	ModelName            string                 `json:"modelName,omitempty"`
	// Tool feed fields.
	FeedID        string      `json:"feedId,omitempty"`
	FeedTitle     string      `json:"feedTitle,omitempty"`
	FeedItemCount int         `json:"feedItemCount,omitempty"`
	FeedData      interface{} `json:"feedData,omitempty"`
}

Event is a transport-neutral streaming event.

func FromLLMEvent

func FromLLMEvent(streamID string, in llm.StreamEvent) *Event

FromLLMEvent converts an llm stream event to a generic streaming event. When the event carries typed Kind fields, those take precedence over the legacy Response-based inference.

type EventModel

type EventModel struct {
	Provider string `json:"provider,omitempty"`
	Model    string `json:"model,omitempty"`
	Kind     string `json:"kind,omitempty"`
}

type EventType

type EventType string
const (
	// Stream delta types — fine-grained provider output.
	EventTypeTextDelta      EventType = "text_delta"
	EventTypeReasoningDelta EventType = "reasoning_delta"
	EventTypeToolCallDelta  EventType = "tool_call_delta"
	EventTypeError          EventType = "error"

	// Control events (patch-based updates).
	EventTypeControl EventType = "control"

	// Turn lifecycle.
	EventTypeTurnStarted   EventType = "turn_started"
	EventTypeTurnCompleted EventType = "turn_completed"
	EventTypeTurnFailed    EventType = "turn_failed"
	EventTypeTurnCanceled  EventType = "turn_canceled"

	// Model lifecycle.
	EventTypeModelStarted   EventType = "model_started"
	EventTypeModelCompleted EventType = "model_completed"

	// Assistant content (aggregated).
	EventTypeAssistantPreamble EventType = "assistant_preamble"
	EventTypeAssistantFinal    EventType = "assistant_final"

	// Tool call lifecycle.
	EventTypeToolCallsPlanned  EventType = "tool_calls_planned"
	EventTypeToolCallStarted   EventType = "tool_call_started"
	EventTypeToolCallCompleted EventType = "tool_call_completed"

	// Stream metadata / completion.
	EventTypeItemCompleted EventType = "item_completed"
	EventTypeUsage         EventType = "usage"

	// Elicitation lifecycle.
	EventTypeElicitationRequested EventType = "elicitation_requested"
	EventTypeElicitationResolved  EventType = "elicitation_resolved"

	// Linked conversation.
	EventTypeLinkedConversationAttached EventType = "linked_conversation_attached"

	// Tool feed lifecycle.
	EventTypeToolFeedActive   EventType = "tool_feed_active"
	EventTypeToolFeedInactive EventType = "tool_feed_inactive"
)

type Filter

type Filter func(*Event) bool

type MemoryBus

type MemoryBus struct {
	// contains filtered or unexported fields
}

func NewMemoryBus

func NewMemoryBus(buffer int) *MemoryBus

func (*MemoryBus) Close

func (b *MemoryBus) Close() error

func (*MemoryBus) Publish

func (b *MemoryBus) Publish(ctx context.Context, event *Event) error

func (*MemoryBus) Subscribe

func (b *MemoryBus) Subscribe(_ context.Context, filter Filter) (Subscription, error)

type PlannedToolCall

type PlannedToolCall struct {
	ToolCallID string `json:"toolCallId,omitempty"`
	ToolName   string `json:"toolName,omitempty"`
}

type Publisher

type Publisher interface {
	Publish(ctx context.Context, event *Event) error
}

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, filter Filter) (Subscription, error)
}

type Subscription

type Subscription interface {
	ID() string
	C() <-chan *Event
	Close() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL