Documentation
¶
Index ¶
- func MarshalParts(parts []ContentPart) ([]byte, error)
- type ContentPart
- type Finish
- type ImageContent
- type Message
- func (m *Message) AddPart(part ContentPart)
- func (m *Message) AddToolCall(tc ToolCall)
- func (m *Message) Content() string
- func (m *Message) Images() []ImageContent
- func (m *Message) Reasoning() ReasoningContent
- func (m *Message) ToFantasyMessages() []fantasy.Message
- func (m *Message) ToolCalls() []ToolCall
- func (m *Message) ToolResults() []ToolResult
- type MessageRole
- type ReasoningContent
- type TextContent
- type ToolCall
- type ToolResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalParts ¶
func MarshalParts(parts []ContentPart) ([]byte, error)
MarshalParts serializes a slice of ContentPart to JSON using type-tagged wrappers. Each part becomes {"type":"...", "data":{...}}.
Types ¶
type ContentPart ¶
type ContentPart interface {
// contains filtered or unexported methods
}
ContentPart is the marker interface for all message content block types. A message contains a heterogeneous slice of ContentPart values, enabling rich structured messages that carry text, reasoning, tool calls, tool results, and finish markers in a single message.
func UnmarshalParts ¶
func UnmarshalParts(data []byte) ([]ContentPart, error)
UnmarshalParts deserializes type-tagged JSON back into a slice of ContentPart.
type Finish ¶
type Finish struct {
Reason string `json:"reason"` // "end_turn", "tool_use", "max_tokens", etc.
}
Finish marks the end of an assistant turn, carrying the stop reason.
type ImageContent ¶ added in v0.7.0
ImageContent holds image data within a message. The data is stored as raw bytes (not base64-encoded); serialization handles encoding. MediaType is a MIME type such as "image/png" or "image/jpeg".
type Message ¶
type Message struct {
ID string `json:"id"`
Role MessageRole `json:"role"`
Parts []ContentPart `json:"parts"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Message is a single conversation message containing a heterogeneous slice of ContentPart blocks. This design (borrowed from crush) enables a single assistant message to carry text, reasoning, and multiple tool calls as discrete, typed blocks rather than flattening everything into strings.
func FromFantasyMessage ¶
FromFantasyMessage converts a fantasy.Message into our Message type, extracting all content parts into the appropriate block types.
func (*Message) AddPart ¶
func (m *Message) AddPart(part ContentPart)
AddPart appends a content part and updates the timestamp.
func (*Message) AddToolCall ¶
AddToolCall appends or updates a ToolCall part. If a call with the same ID already exists, it is replaced (supports streaming where partial calls arrive before the final version).
func (*Message) Images ¶ added in v0.7.0
func (m *Message) Images() []ImageContent
Images returns all ImageContent parts from this message.
func (*Message) Reasoning ¶
func (m *Message) Reasoning() ReasoningContent
Reasoning returns the ReasoningContent if present, or a zero value.
func (*Message) ToFantasyMessages ¶
ToFantasyMessages converts a Message to one or more fantasy.Message values. An assistant message with tool calls produces a single fantasy message with mixed TextPart and ToolCallPart content. Tool-role messages produce ToolResultPart entries.
func (*Message) ToolResults ¶
func (m *Message) ToolResults() []ToolResult
ToolResults returns all ToolResult parts from this message.
type MessageRole ¶
type MessageRole string
MessageRole identifies the sender of a message.
const ( RoleUser MessageRole = "user" RoleAssistant MessageRole = "assistant" RoleTool MessageRole = "tool" RoleSystem MessageRole = "system" )
type ReasoningContent ¶
type ReasoningContent struct {
Thinking string `json:"thinking"`
Signature string `json:"signature,omitempty"` // Anthropic
}
ReasoningContent holds extended thinking / reasoning output from the LLM. Provider-specific metadata (signatures, etc.) is preserved for round-trip fidelity when the conversation is sent back to the provider.
type TextContent ¶
type TextContent struct {
Text string `json:"text"`
}
TextContent holds plain text content within a message.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input string `json:"input"` // JSON string of arguments
Finished bool `json:"finished"`
}
ToolCall represents a tool invocation initiated by the LLM. It is stored as a content part within an assistant message, not as a separate message.
type ToolResult ¶
type ToolResult struct {
ToolCallID string `json:"tool_call_id"`
Name string `json:"name"`
Content string `json:"content"`
IsError bool `json:"is_error"`
}
ToolResult represents the result of executing a tool. It is stored as a content part within a tool-role message, linked to a ToolCall by ID.