message

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package message is the conversation data hosts, models and the harness exchange: messages, their content parts, and tool calls.

Index

Constants

View Source
const (
	ContentTypeOutputText = "output_text"
	ContentTypeInputText  = "input_text"
	ContentTypeInputImage = "input_image"
	ContentTypeInputFile  = "input_file"
)

Variables

This section is empty.

Functions

func DataURL

func DataURL(mime, data string) string

DataURL builds a data:<mime>;base64,<data> URL. data may already be a data URL.

func IsTextMIME

func IsTextMIME(mime string) bool

IsTextMIME is true for empty and text/* types (always model-safe as text).

func MIMEFromDataURL

func MIMEFromDataURL(u string) string

MIMEFromDataURL extracts the MIME type from a data: URL, or empty.

func NormalizeMIME

func NormalizeMIME(mime string) string

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 ImageURL

type ImageURL struct {
	URL    string `json:"url"`
	Detail string `json:"detail,omitempty"`
}

ImageURL represents an image input by URL or data URI.

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)

func (*Message) MIMETypes

func (m *Message) MIMETypes() []string

MIMETypes returns unique binary MIME types from ContentParts (images/files). Producers set FileData.MIMEType (and image parts via FileData or data URL). Text and refusal parts are ignored. Order is first-seen.

type Role

type Role string

Role indicates who sent a message.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleReasoning Role = "reasoning"
	RoleSystem    Role = "system"
	RoleDeveloper Role = "developer"
	RoleTool      Role = "tool"
)

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.

func (ToolCall) Key

func (tc ToolCall) Key() string

Key is the client/lifecycle id: provider item id, else call_id.

func (ToolCall) WireID

func (tc ToolCall) WireID() string

WireID is the Responses API call_id field: CallID, else ID.

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

type URLAnnotation struct {
	URL   string `json:"url"`
	Title string `json:"title"`
}

URLAnnotation references a specific URL as a citation source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL