sse

package
v0.14.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SSEContentType       = "text/event-stream"
	SSECacheControl      = "no-cache"
	SSEConnection        = "keep-alive"
	SSEKeepaliveMsg      = ": keepalive\n\n"
	SSEStreamStartMsg    = ": stream-start\n\n"
	SSEKeepaliveInterval = 1 * time.Second
)
View Source
const (
	AiMsgStart               = "start"
	AiMsgTextStart           = "text-start"
	AiMsgTextDelta           = "text-delta"
	AiMsgTextEnd             = "text-end"
	AiMsgReasoningStart      = "reasoning-start"
	AiMsgReasoningDelta      = "reasoning-delta"
	AiMsgReasoningEnd        = "reasoning-end"
	AiMsgToolInputStart      = "tool-input-start"
	AiMsgToolInputDelta      = "tool-input-delta"
	AiMsgToolInputAvailable  = "tool-input-available"
	AiMsgToolOutputAvailable = "tool-output-available" // not used here, but reserved
	AiMsgStartStep           = "start-step"
	AiMsgFinishStep          = "finish-step"
	AiMsgFinish              = "finish"
	AiMsgError               = "error"
)

AI message type constants

Variables

This section is empty.

Functions

This section is empty.

Types

type SSEHandlerCh

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

SSEHandlerCh provides channel-based Server-Sent Events functionality

func MakeSSEHandlerCh

func MakeSSEHandlerCh(w http.ResponseWriter, ctx context.Context) *SSEHandlerCh

MakeSSEHandlerCh creates a new channel-based SSE handler

func (*SSEHandlerCh) AiMsgData

func (h *SSEHandlerCh) AiMsgData(dataType string, id string, data interface{}) error

func (*SSEHandlerCh) AiMsgError

func (h *SSEHandlerCh) AiMsgError(errText string) error

func (*SSEHandlerCh) AiMsgFinish

func (h *SSEHandlerCh) AiMsgFinish(finishReason string, usage interface{}) error

func (*SSEHandlerCh) AiMsgFinishStep

func (h *SSEHandlerCh) AiMsgFinishStep() error

func (*SSEHandlerCh) AiMsgReasoningDelta

func (h *SSEHandlerCh) AiMsgReasoningDelta(reasoningId string, reasoning string) error

func (*SSEHandlerCh) AiMsgReasoningEnd

func (h *SSEHandlerCh) AiMsgReasoningEnd(reasoningId string) error

func (*SSEHandlerCh) AiMsgReasoningStart

func (h *SSEHandlerCh) AiMsgReasoningStart(reasoningId string) error

func (*SSEHandlerCh) AiMsgStart

func (h *SSEHandlerCh) AiMsgStart(messageId string) error

func (*SSEHandlerCh) AiMsgStartStep

func (h *SSEHandlerCh) AiMsgStartStep() error

func (*SSEHandlerCh) AiMsgTextDelta

func (h *SSEHandlerCh) AiMsgTextDelta(textId string, text string) error

func (*SSEHandlerCh) AiMsgTextEnd

func (h *SSEHandlerCh) AiMsgTextEnd(textId string) error

func (*SSEHandlerCh) AiMsgTextStart

func (h *SSEHandlerCh) AiMsgTextStart(textId string) error

func (*SSEHandlerCh) AiMsgToolInputAvailable

func (h *SSEHandlerCh) AiMsgToolInputAvailable(toolCallId, toolName string, input json.RawMessage) error

func (*SSEHandlerCh) AiMsgToolInputDelta

func (h *SSEHandlerCh) AiMsgToolInputDelta(toolCallId, inputTextDelta string) error

func (*SSEHandlerCh) AiMsgToolInputStart

func (h *SSEHandlerCh) AiMsgToolInputStart(toolCallId, toolName string) error

func (*SSEHandlerCh) Close

func (h *SSEHandlerCh) Close()

Close closes the write channel, sends [DONE], and cleans up resources

func (*SSEHandlerCh) Context added in v0.14.0

func (h *SSEHandlerCh) Context() context.Context

func (*SSEHandlerCh) Err

func (h *SSEHandlerCh) Err() error

Err returns any error that occurred during writing

func (*SSEHandlerCh) RegisterOnClose added in v0.14.0

func (h *SSEHandlerCh) RegisterOnClose(fn func()) string

RegisterOnClose registers a handler function to be called when the connection closes Returns an ID that can be used to unregister the handler

func (*SSEHandlerCh) SetupSSE

func (h *SSEHandlerCh) SetupSSE() error

SetupSSE configures the response headers and starts the writer goroutine

func (*SSEHandlerCh) UnregisterOnClose added in v0.14.0

func (h *SSEHandlerCh) UnregisterOnClose(id string)

UnregisterOnClose removes a previously registered onClose handler by ID

func (*SSEHandlerCh) WriteComment

func (h *SSEHandlerCh) WriteComment(comment string) error

WriteComment queues an SSE comment

func (*SSEHandlerCh) WriteData

func (h *SSEHandlerCh) WriteData(data string) error

WriteData queues data to be written in SSE format

func (*SSEHandlerCh) WriteError

func (h *SSEHandlerCh) WriteError(errorMsg string) error

WriteError queues an error message and closes the handler

func (*SSEHandlerCh) WriteEvent

func (h *SSEHandlerCh) WriteEvent(eventType, data string) error

WriteEvent queues an SSE event with optional event type

func (*SSEHandlerCh) WriteJsonData

func (h *SSEHandlerCh) WriteJsonData(data interface{}) error

WriteJsonData marshals data to JSON and queues it for writing

type SSEMessage

type SSEMessage struct {
	Type      SSEMessageType
	Data      string
	EventType string // Only used for SSEMsgEvent
}

SSEMessage represents a message to be written to the SSE stream

type SSEMessageType

type SSEMessageType string

SSEMessageType represents the type of message to write

const (
	SSEMsgData    SSEMessageType = "data"
	SSEMsgEvent   SSEMessageType = "event"
	SSEMsgComment SSEMessageType = "comment"
	SSEMsgError   SSEMessageType = "error"
)

Jump to

Keyboard shortcuts

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