Documentation
¶
Overview ¶
Package streamhub provides task-scoped stream buffers for worker-push and client subscribe (SSE).
Package wsconn defines the typed event protocol for WebSocket communication between the portal frontend and the server. All messages are JSON envelopes with a "type" field and a typed "payload".
Index ¶
- Constants
- func DecodePayload[T any](env Envelope) (T, error)
- func Encode(eventType string, payload any) ([]byte, error)
- type ConversationCreate
- type ConversationCreated
- type ConversationError
- type ConversationMessage
- type Envelope
- type MessageCompleted
- type MessageDelta
- type StreamHub
- type SubscribeTask
- type SystemError
- type TaskStatusChanged
- type TaskStreamDelta
- type TaskStreamDone
- type UnsubscribeTask
Constants ¶
const ( TypeConversationCreate = "conversation.create" TypeConversationMessage = "conversation.message" TypeSubscribeTask = "subscribe.task" TypeUnsubscribeTask = "unsubscribe.task" )
const ( TypeConversationCreated = "conversation.created" TypeMessageDelta = "conversation.message.delta" TypeMessageCompleted = "conversation.message.completed" TypeConversationError = "conversation.error" TypeTaskStatusChanged = "task.status.changed" TypeTaskStreamDelta = "task.stream.delta" TypeTaskStreamDone = "task.stream.done" TypeSystemError = "system.error" )
const StreamEventDone = "[[DONE]]"
StreamEventDone is sent on the subscription channel when the run finishes (SUCCEEDED/FAILED).
Variables ¶
This section is empty.
Functions ¶
func DecodePayload ¶
DecodePayload unmarshals the envelope's raw payload into the target type T.
Types ¶
type ConversationCreate ¶
type ConversationCreate struct {
Channel string `json:"channel,omitempty"`
Message string `json:"message"`
}
ConversationCreate is the payload for TypeConversationCreate.
type ConversationCreated ¶
type ConversationCreated struct {
ConversationID string `json:"conversation_id"`
}
ConversationCreated is the payload for TypeConversationCreated.
type ConversationError ¶
type ConversationError struct {
ConversationID string `json:"conversation_id,omitempty"`
Error string `json:"error"`
}
ConversationError is the payload for TypeConversationError.
type ConversationMessage ¶
type ConversationMessage struct {
ConversationID string `json:"conversation_id"`
Content string `json:"content"`
}
ConversationMessage is the payload for TypeConversationMessage.
type Envelope ¶
type Envelope struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
Envelope is the wire format for every WebSocket message (both directions).
type MessageCompleted ¶
type MessageCompleted struct {
ConversationID string `json:"conversation_id"`
}
MessageCompleted is the payload for TypeMessageCompleted.
type MessageDelta ¶
type MessageDelta struct {
ConversationID string `json:"conversation_id"`
Delta string `json:"delta"`
}
MessageDelta is the payload for TypeMessageDelta.
type StreamHub ¶
type StreamHub interface {
// Append adds a delta to the buffer and broadcasts to all subscribers for that task.
Append(taskID, delta string)
// Buffer returns the current buffered content for the task. Empty string if task has no buffer or was Done.
Buffer(taskID string) string
// Done marks the task's current run as finished; sends StreamEventDone to subscribers and clears state.
Done(taskID string)
// Subscribe returns a channel of deltas (and finally StreamEventDone) for the task. unsub must be called when done.
Subscribe(taskID string) (events <-chan string, unsub func())
}
StreamHub is the interface for task-scoped stream buffers. Keys are task_id (one active run per task). Implementations may be in-memory (single instance) or backed by Redis (multi-instance).
func NewStreamHub ¶
func NewStreamHub() StreamHub
NewStreamHub returns an in-memory StreamHub. Multi-instance scaling requires a Redis-backed impl.
type SubscribeTask ¶
type SubscribeTask struct {
TaskID string `json:"task_id"`
}
SubscribeTask is the payload for TypeSubscribeTask.
type SystemError ¶
type SystemError struct {
Error string `json:"error"`
}
SystemError is the payload for TypeSystemError.
type TaskStatusChanged ¶
type TaskStatusChanged struct {
TaskID string `json:"task_id"`
Status string `json:"status"`
Title string `json:"title,omitempty"`
}
TaskStatusChanged is the payload for TypeTaskStatusChanged.
type TaskStreamDelta ¶
TaskStreamDelta is the payload for TypeTaskStreamDelta.
type TaskStreamDone ¶
type TaskStreamDone struct {
TaskID string `json:"task_id"`
}
TaskStreamDone is the payload for TypeTaskStreamDone.
type UnsubscribeTask ¶
type UnsubscribeTask struct {
TaskID string `json:"task_id"`
}
UnsubscribeTask is the payload for TypeUnsubscribeTask.