Documentation
¶
Index ¶
- type ContentBlockDeltaEvent
- type ContentBlockStartEvent
- type ContentBlockStopEvent
- type ContentDelta
- type Error
- type Event
- func (ev Event) AsContentBlockDelta() (*ContentBlockDeltaEvent, error)
- func (ev Event) AsContentBlockStart() (*ContentBlockStartEvent, error)
- func (ev Event) AsContentBlockStop() (*ContentBlockStopEvent, error)
- func (ev Event) AsMessageDelta() (*MessageDeltaEvent, error)
- func (ev Event) AsMessageStart() (*MessageStartEvent, error)
- type MessageDelta
- type MessageDeltaEvent
- type MessageMeta
- type MessageStartEvent
- type Parser
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentBlockDeltaEvent ¶
type ContentBlockDeltaEvent struct {
Type string `json:"type"`
Index int `json:"index"`
Delta ContentDelta `json:"delta"`
}
ContentBlockDeltaEvent — one delta to an in-progress content block.
type ContentBlockStartEvent ¶
type ContentBlockStartEvent struct {
Type string `json:"type"`
Index int `json:"index"`
ContentBlock json.RawMessage `json:"content_block"`
}
ContentBlockStartEvent — the start of a new content block.
type ContentBlockStopEvent ¶
ContentBlockStopEvent — content block closed.
type ContentDelta ¶
type ContentDelta struct {
Type string `json:"type"`
Text string `json:"text,omitempty"` // text_delta
PartialJSON string `json:"partial_json,omitempty"` // input_json_delta
Thinking string `json:"thinking,omitempty"` // thinking_delta
}
ContentDelta is one of: text_delta (most common), input_json_delta (tool inputs streaming in), thinking_delta (extended thinking).
type Event ¶
type Event struct {
// Type is the value of the `event:` field. For Anthropic this is one
// of message_start, message_delta, message_stop, content_block_start,
// content_block_delta, content_block_stop, ping, error.
Type string
// RawData is the concatenated `data:` lines (joined with newlines if
// multi-line). It is the raw JSON payload — call one of the AsXxx
// helpers to decode.
RawData []byte
}
Event is a single Server-Sent Event from the Anthropic stream.
func (Event) AsContentBlockDelta ¶
func (ev Event) AsContentBlockDelta() (*ContentBlockDeltaEvent, error)
AsContentBlockDelta decodes ev into a ContentBlockDeltaEvent. Returns an error when the event type doesn't match.
func (Event) AsContentBlockStart ¶
func (ev Event) AsContentBlockStart() (*ContentBlockStartEvent, error)
AsContentBlockStart decodes ev into a ContentBlockStartEvent.
func (Event) AsContentBlockStop ¶
func (ev Event) AsContentBlockStop() (*ContentBlockStopEvent, error)
AsContentBlockStop decodes ev into a ContentBlockStopEvent.
func (Event) AsMessageDelta ¶
func (ev Event) AsMessageDelta() (*MessageDeltaEvent, error)
AsMessageDelta decodes ev into a MessageDeltaEvent.
func (Event) AsMessageStart ¶
func (ev Event) AsMessageStart() (*MessageStartEvent, error)
AsMessageStart decodes ev into a MessageStartEvent.
type MessageDelta ¶
type MessageDelta struct {
StopReason string `json:"stop_reason"`
StopSequence string `json:"stop_sequence,omitempty"`
}
MessageDelta carries the stop reason at message close.
type MessageDeltaEvent ¶
type MessageDeltaEvent struct {
Type string `json:"type"`
Delta MessageDelta `json:"delta"`
Usage Usage `json:"usage"`
}
MessageDeltaEvent — final usage / stop info.
type MessageMeta ¶
type MessageMeta struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Model string `json:"model"`
Content []json.RawMessage `json:"content"`
StopReason string `json:"stop_reason"`
Usage Usage `json:"usage"`
}
MessageMeta is the message envelope inside message_start.
type MessageStartEvent ¶
type MessageStartEvent struct {
Type string `json:"type"`
Message MessageMeta `json:"message"`
}
MessageStartEvent is the first event in every stream.
type Parser ¶
type Parser struct {
// IncludePings, when true, surfaces `ping` events to callers. Default
// false because nothing in the agent loop needs them.
IncludePings bool
// contains filtered or unexported fields
}
Parser yields Events from an SSE stream. It is not safe for concurrent use; use one Parser per stream.
func NewParser ¶
NewParser wraps r in a Parser. r is read once-through; the parser does not buffer beyond what bufio.Reader keeps.
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"`
}
Usage tracks input/output tokens. cache_* fields are present when prompt caching is in play.