Documentation
¶
Overview ¶
Package chat provides a client for the stateless Chat API.
The Chat API is a pure function: f(messages, context) → stream of blocks. It doesn't read or write messages to any database. The client sends the full conversation history on every request and receives a streamed response.
Message persistence is handled separately by the caller.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Stream sends the conversation to the Chat API and streams the response.
// The onMessage callback is called each time the message is updated with new content.
// The returned StreamResult contains the final message and any metadata.
Stream(ctx context.Context, req Request, onMessage func(*domain.Message)) (*StreamResult, error)
// SetAccountID sets the account ID for requests.
SetAccountID(accountID domain.AccountID)
}
Client sends messages to the Chat API and streams responses.
type EventType ¶
type EventType string
EventType identifies the kind of SSE event from the Chat API.
const ( // Delta events - streaming content fragments. EventTypeTextDelta EventType = "text_delta" EventTypeThinkingDelta EventType = "thinking_delta" EventTypeToolInputDelta EventType = "tool_input_delta" // Complete block events. EventTypeText EventType = "text" EventTypeThinking EventType = "thinking" EventTypeToolUse EventType = "tool_use" EventTypeToolResult EventType = "tool_result" // Stream lifecycle events. EventTypeMessageStart EventType = "message_start" EventTypeMessageStop EventType = "message_stop" EventTypeContentBlockStop EventType = "content_block_stop" // Post-stream metadata. EventTypeMetadataUpdate EventType = "metadata_update" )
type Property ¶
type Property struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Items *Items `json:"items,omitempty"`
}
Property defines a single property in a JSON Schema.
type Request ¶
type Request struct {
ConversationID string `json:"conversation_id"`
Messages []domain.Message `json:"messages"`
Context []domain.ContextEntity `json:"context,omitempty"`
Tools []Tool `json:"tools"`
}
Request is the input to the Chat API. The client sends the full conversation history on every request.
type Schema ¶
type Schema struct {
Type string `json:"type"`
Properties map[string]Property `json:"properties"` // Always required by Anthropic API
Required []string `json:"required,omitempty"`
}
Schema defines the JSON Schema for tool input.
func NewObjectSchema ¶
NewObjectSchema creates an object schema with the given properties.
func (Schema) MarshalJSON ¶
MarshalJSON ensures Properties is never null (Anthropic API requires it).
type StreamMetadata ¶
type StreamMetadata struct {
Title string // AI-generated conversation title, set after first exchange
ContextWindow int // Model's max token capacity (from message_start)
InputTokens int // Tokens consumed by input this turn (from message_stop)
OutputTokens int // Tokens generated by output this turn (from message_stop)
}
StreamMetadata contains post-stream metadata from the Chat API.
type StreamResult ¶
type StreamResult struct {
Message *domain.Message
Metadata *StreamMetadata // nil if no metadata_update event was received
}
StreamResult captures everything the stream produced.