Documentation
¶
Overview ¶
Package message defines the core message types used in AI conversations. This mirrors the ai-sdk ModelMessage types.
Index ¶
- type Content
- type ContentType
- type FilePart
- type ImagePart
- type Message
- func NewAssistantMessage(text string) Message
- func NewAssistantMessageWithParts(parts ...Part) Message
- func NewSystemMessage(text string) Message
- func NewToolMessage(toolCallID, toolName string, result any, isError bool) Message
- func NewUserMessage(text string) Message
- func NewUserMessageWithParts(parts ...Part) Message
- type Part
- type ReasoningPart
- type Role
- type TextPart
- type ToolApprovalRequestPart
- type ToolApprovalResponsePart
- type ToolCallPart
- type ToolResultPart
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
Content represents message content - either a string or parts.
func (Content) IsMultiPart ¶
IsMultiPart returns true if content has multiple parts.
func (Content) MarshalJSON ¶
MarshalJSON serializes Content. Text-only content serializes as a plain string. Multi-part content serializes as an array of typed objects.
func (*Content) UnmarshalJSON ¶
UnmarshalJSON deserializes Content from either a plain string or a typed array.
type ContentType ¶
type ContentType string
ContentType represents the type of content in a message part.
const ( ContentTypeText ContentType = "text" ContentTypeImage ContentType = "image" ContentTypeFile ContentType = "file" ContentTypeToolCall ContentType = "tool-call" ContentTypeToolResult ContentType = "tool-result" )
type FilePart ¶
type FilePart struct {
Data string `json:"data,omitempty"` // base64 encoded (when inline)
URL string `json:"url,omitempty"` // remote URL (when hosted)
MimeType string `json:"mimeType"` // e.g., "application/pdf"
Filename string `json:"filename,omitempty"` // optional filename
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
FilePart represents file content. Exactly one of Data or URL should be set: Data carries base64-encoded bytes; URL points to a remote file the provider should fetch (matches ai-sdk's file-url content part and the Anthropic/Gemini url-source variants).
type ImagePart ¶
type ImagePart struct {
Image string `json:"image"` // base64 or URL
MimeType string `json:"mimeType,omitempty"` // e.g., "image/png"
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ImagePart represents image content.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content Content `json:"content"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
Message represents a single message in a conversation.
func NewAssistantMessage ¶
NewAssistantMessage creates an assistant message.
func NewAssistantMessageWithParts ¶
NewAssistantMessageWithParts creates an assistant message with parts (e.g., tool calls).
func NewSystemMessage ¶
NewSystemMessage creates a system message.
func NewToolMessage ¶
NewToolMessage creates a tool result message.
func NewUserMessage ¶
NewUserMessage creates a user message with text.
func NewUserMessageWithParts ¶
NewUserMessageWithParts creates a user message with multiple parts.
type Part ¶
type Part interface {
// contains filtered or unexported methods
}
Part represents a single part of message content.
type ReasoningPart ¶
type ReasoningPart struct {
Text string `json:"text"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ReasoningPart represents reasoning/thinking content from the model. Source: ai-sdk/packages/provider-utils/src/message.ts
type TextPart ¶
type TextPart struct {
Text string `json:"text"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
TextPart represents text content.
type ToolApprovalRequestPart ¶
type ToolApprovalRequestPart struct {
ApprovalID string `json:"approvalId"`
ToolCallID string `json:"toolCallId"`
ToolName string `json:"toolName"`
Input any `json:"input"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ToolApprovalRequestPart represents a request for tool execution approval. Source: ai-sdk/packages/provider-utils/src/message.ts
type ToolApprovalResponsePart ¶
type ToolApprovalResponsePart struct {
ApprovalID string `json:"approvalId"`
Approved bool `json:"approved"`
Reason string `json:"reason,omitempty"`
ProviderExecuted bool `json:"providerExecuted,omitempty"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ToolApprovalResponsePart represents a response to tool execution approval. Source: ai-sdk/packages/provider-utils/src/message.ts
type ToolCallPart ¶
type ToolCallPart struct {
ID string `json:"toolCallId"`
Name string `json:"toolName"`
Input json.RawMessage `json:"args"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ToolCallPart represents a tool invocation by the assistant.
type ToolResultPart ¶
type ToolResultPart struct {
ToolCallID string `json:"toolCallId"`
ToolName string `json:"toolName"`
Result any `json:"result"`
IsError bool `json:"isError,omitempty"`
ProviderOptions map[string]any `json:"providerOptions,omitempty"`
}
ToolResultPart represents the result of a tool invocation.