sse

package
v0.260514.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MPL-2.0 Imports: 7 Imported by: 0 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

This section is empty.

Variables

This section is empty.

Functions

func ParseSSEDataPayload

func ParseSSEDataPayload(line string) (payload string, ok bool)

ParseSSEDataPayload checks if a line is an SSE data line and extracts the payload. Handles both Gin-style ("data:{json}") and standard SSE ("data: {json}") formats.

func ReadSSELines

func ReadSSELines(r io.Reader) (lines []string, raw []byte)

ReadSSELines reads an SSE response body and returns each non-empty line as a string. Blank lines (SSE message separators) are skipped. The raw bytes of all non-empty lines (with newlines) are also returned for inspection.

func WriteSSEResponse

func WriteSSEResponse(w http.ResponseWriter, events []string)

WriteSSEResponse writes pre-built SSE event strings to an HTTP response. Events that start with "event:" are grouped with the following "data:" line into a single SSE message (separated by a blank line), matching the SSE spec. A 5 ms flush interval is applied between messages.

Types

type ParsedResult

type ParsedResult struct {
	Role            string
	Content         string
	Model           string
	FinishReason    string
	ThinkingContent string
	ToolCalls       []ParsedToolCall
	Usage           *ParsedTokenUsage
}

ParsedResult is a protocol-agnostic view of an AI response, extracted from raw JSON (non-streaming) or SSE event lines (streaming). Used by test infrastructure and virtual model servers to inspect gateway responses without importing SDK types.

func AssembleAnthropicStream

func AssembleAnthropicStream(events []string) *ParsedResult

AssembleAnthropicStream assembles a ParsedResult from Anthropic SSE event lines.

func AssembleGoogleStream

func AssembleGoogleStream(events []string) *ParsedResult

AssembleGoogleStream assembles a ParsedResult from Google GenerateContent SSE event lines.

func AssembleOpenAIChatStream

func AssembleOpenAIChatStream(events []string) *ParsedResult

AssembleOpenAIChatStream assembles a ParsedResult from OpenAI Chat SSE event lines.

func AssembleOpenAIResponsesStream

func AssembleOpenAIResponsesStream(events []string) *ParsedResult

AssembleOpenAIResponsesStream assembles a ParsedResult from OpenAI Responses API SSE event lines.

func AssembleOpenAIStream

func AssembleOpenAIStream(events []string) *ParsedResult

AssembleOpenAIStream auto-detects whether events are Responses API or Chat format and delegates accordingly.

func ParseAnthropicResult

func ParseAnthropicResult(m map[string]interface{}) *ParsedResult

ParseAnthropicResult extracts fields from an Anthropic Messages API response.

func ParseGoogleResult

func ParseGoogleResult(m map[string]interface{}) *ParsedResult

ParseGoogleResult extracts fields from a Google GenerateContent response.

func ParseOpenAIChatResult

func ParseOpenAIChatResult(m map[string]interface{}) *ParsedResult

ParseOpenAIChatResult extracts fields from an OpenAI Chat Completion response (map[string]interface{} already JSON-decoded).

func ParseOpenAIResponsesResult

func ParseOpenAIResponsesResult(m map[string]interface{}) *ParsedResult

ParseOpenAIResponsesResult extracts fields from an OpenAI Responses API response.

type ParsedTokenUsage

type ParsedTokenUsage struct {
	InputTokens  int
	OutputTokens int
}

ParsedTokenUsage holds token counts extracted from a parsed response.

type ParsedToolCall

type ParsedToolCall struct {
	ID        string
	Name      string
	Arguments string // raw JSON string
}

ParsedToolCall holds a single tool/function call extracted from a response.

Jump to

Keyboard shortcuts

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