Documentation
¶
Index ¶
- func AnthropicErrorType(err *chat.Error) string
- func AsError(err error) *chat.Error
- func InitialResponse(seed chat.Response, parsed *ParsedRequest) chat.Response
- func RequiresReasoningSummary(event chat.Event) bool
- func ValidateOutputEvent(event chat.Event, info chat.Info) error
- func ValidateRequestedOutput(event chat.Event, modalities chat.Modality) error
- func WriteError(w http.ResponseWriter, kind Kind, err error)
- func WriteJSON(w http.ResponseWriter, status int, value any)
- type Adapter
- type Kind
- type Meta
- type ParsedRequest
- type SSEWriter
- type StreamEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnthropicErrorType ¶
AnthropicErrorType maps a canonical API error to an Anthropic error type string.
func InitialResponse ¶
func InitialResponse(seed chat.Response, parsed *ParsedRequest) chat.Response
InitialResponse assembles the initial response envelope shared by every creation path, applying library defaults for identity and echoing the retrieval fields from the parsed request.
func ValidateOutputEvent ¶
ValidateOutputEvent checks an agent output event against what the selected agent declares it can provide.
func ValidateRequestedOutput ¶
ValidateRequestedOutput checks an agent output event against the modalities the caller actually requested.
func WriteError ¶
func WriteError(w http.ResponseWriter, kind Kind, err error)
WriteError writes the canonical error envelope for the selected protocol.
Types ¶
type Adapter ¶
type Adapter interface {
// ValidateEvent checks whether event can be encoded for this protocol.
ValidateEvent(chat.Event) error
// Response builds a non-streaming response body for result.
Response(chat.Request, execution.Result, Meta) (any, error)
// Stream returns an SSE encoder for the given response writer.
// meta is retained for the stream lifetime so terminal Response
// updates are visible to Complete.
Stream(http.ResponseWriter, ParsedRequest, *Meta, chat.Limits) StreamEncoder
}
Adapter is the protocol-specific boundary used by the HTTP handler.
type Meta ¶
type Meta struct {
Response chat.Response // identity, status, output, and retrieval fields
Activity bool // when true, Responses may encode EventActivity frames
}
Meta contains the response value shared by all protocol encoders.
type ParsedRequest ¶
type ParsedRequest struct {
Kind Kind // wire protocol that parsed the request
Request chat.Request // canonical execution request for Agent.Run
Turn []chat.Item // items submitted in this HTTP request only
Previous *string // prior response ID for continuation
Store *bool // wire store flag; nil when omitted
Metadata map[string]string // application metadata for the response
Retain bool // effective retention after StoreDefault
Stream bool // whether the client requested streaming
IncludeUsage bool // Chat Completions stream_options.include_usage only
}
ParsedRequest is the protocol-neutral request produced by a wire decoder. Request holds agent execution fields. Turn, Previous, Store, Metadata, and Retain are acceptance/persistence concerns filled by parsers and the handler.
type SSEWriter ¶
type SSEWriter struct {
// contains filtered or unexported fields
}
SSEWriter owns the shared HTTP/SSE mechanics. Protocol codecs only provide event names and values; this type handles headers, event-size limits, flushing, and the OpenAI terminal marker.
func NewSSEWriter ¶
func NewSSEWriter(w http.ResponseWriter, limits chat.Limits) *SSEWriter
NewSSEWriter constructs an SSEWriter for the given response writer and limits.
func (*SSEWriter) Done ¶
Done writes the OpenAI-compatible [DONE] marker. Anthropic and audio SSE codecs intentionally do not use it because their protocols have typed terminal events.
type StreamEncoder ¶
type StreamEncoder interface {
// Event encodes one canonical agent event into protocol SSE frames.
Event(chat.Event) error
// Complete emits terminal stream events and closes the SSE lifecycle.
Complete(chat.Outcome, []chat.Item) error
// Fail writes a protocol-specific error response for the stream.
Fail(error) error
// Started reports whether SSE output has begun.
Started() bool
}
StreamEncoder turns canonical events into one protocol's SSE lifecycle.