Documentation
¶
Overview ¶
Package message is the conversation data hosts, models and the harness exchange: messages, their content parts, and tool calls.
Index ¶
- Constants
- func DataURL(mime, data string) string
- func IsTextMIME(mime string) bool
- func MIMEFromDataURL(u string) string
- func NormalizeMIME(mime string) string
- type Annotation
- type ContentPart
- type FileData
- type ImageURL
- type ItemStatus
- type Message
- type Role
- type ToolCall
- type ToolCategory
- type URLAnnotation
Constants ¶
const ( ContentTypeOutputText = "output_text" ContentTypeInputText = "input_text" ContentTypeInputImage = "input_image" ContentTypeInputFile = "input_file" )
Variables ¶
This section is empty.
Functions ¶
func IsTextMIME ¶
IsTextMIME is true for empty and text/* types (always model-safe as text).
func MIMEFromDataURL ¶
MIMEFromDataURL extracts the MIME type from a data: URL, or empty.
func NormalizeMIME ¶
NormalizeMIME lowercases a MIME type and strips parameters (after ';').
Types ¶
type Annotation ¶
type Annotation struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
FileID string `json:"file_id,omitempty"`
URL *URLAnnotation `json:"url,omitempty"`
}
Annotation attaches file/URL citations to output_text content.
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Refusal string `json:"refusal,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
FileData *FileData `json:"file_data,omitempty"`
Annotations []Annotation `json:"annotations,omitempty"`
}
ContentPart is a single content block within a message. Discriminated by Type — oneOf{output_text, input_text, input_image, input_file}.
type FileData ¶
type FileData struct {
FileID string `json:"file_id,omitempty"`
URL string `json:"url,omitempty"`
Data string `json:"data,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
// Filename is preferred by providers for input_file (e.g. PDF data URLs).
Filename string `json:"filename,omitempty"`
}
FileData represents an image or file input by ID, URL, or base64 data.
type ItemStatus ¶
type ItemStatus string
ItemStatus is the lifecycle state of an output item, such as a tool call.
const ( StatusInProgress ItemStatus = "in_progress" StatusCompleted ItemStatus = "completed" StatusIncomplete ItemStatus = "incomplete" )
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content,omitempty"`
// MessageID is the provider-assigned identifier for this output item,
// used when serializing prior assistant or reasoning turns as typed
// response items.
MessageID string `json:"message_id,omitempty"`
// EncryptedContent is the provider's opaque data for a reasoning
// message. The provider client that wrote it replays it on later
// requests; nothing else reads it.
EncryptedContent string `json:"encrypted_content,omitempty"`
ContentParts []ContentPart `json:"content_parts,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
StructuredOutput any `json:"-"`
}
Message is the primary conversation unit in the context window. It handles both simple text and structured content, tool calls, tool results, and reasoning content produced by reasoning models. The Role field determines the purpose:
- system/developer: system instructions
- user: user input (Content or ContentParts)
- assistant: model response (Content + optional ToolCalls)
- reasoning: model reasoning content (a distinct previous-response item)
- tool: result of a tool execution (ToolCallID + Content)
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
CallID string `json:"call_id"`
Name string `json:"name,omitempty"` // programmatic tool id (model-facing)
Title string `json:"title,omitempty"` // human-readable invocation label for UIs/protocols
Category ToolCategory `json:"category,omitempty"`
Namespace string `json:"namespace,omitempty"`
Arguments string `json:"arguments,omitempty"`
Status string `json:"status,omitempty"`
}
ToolCall represents an assistant request to invoke a tool.
type ToolCategory ¶
type ToolCategory string
const ( ToolCategoryRead ToolCategory = "read" ToolCategoryEdit ToolCategory = "edit" ToolCategorySearch ToolCategory = "search" ToolCategoryFetch ToolCategory = "fetch" ToolCategoryMove ToolCategory = "move" ToolCategoryThink ToolCategory = "think" ToolCategoryExecute ToolCategory = "execute" ToolCategoryDelete ToolCategory = "delete" )
type URLAnnotation ¶
URLAnnotation references a specific URL as a citation source.