message

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package message defines the core message types used in AI conversations. This mirrors the ai-sdk ModelMessage types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Text  string // Simple text content
	Parts []Part // Multi-part content
}

Content represents message content - either a string or parts.

func (Content) IsMultiPart

func (c Content) IsMultiPart() bool

IsMultiPart returns true if content has multiple parts.

func (Content) MarshalJSON

func (c Content) MarshalJSON() ([]byte, error)

MarshalJSON serializes Content. Text-only content serializes as a plain string. Multi-part content serializes as an array of typed objects.

func (*Content) UnmarshalJSON

func (c *Content) UnmarshalJSON(data []byte) error

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

func NewAssistantMessage(text string) Message

NewAssistantMessage creates an assistant message.

func NewAssistantMessageWithParts

func NewAssistantMessageWithParts(parts ...Part) Message

NewAssistantMessageWithParts creates an assistant message with parts (e.g., tool calls).

func NewSystemMessage

func NewSystemMessage(text string) Message

NewSystemMessage creates a system message.

func NewToolMessage

func NewToolMessage(toolCallID, toolName string, result any, isError bool) Message

NewToolMessage creates a tool result message.

func NewUserMessage

func NewUserMessage(text string) Message

NewUserMessage creates a user message with text.

func NewUserMessageWithParts

func NewUserMessageWithParts(parts ...Part) Message

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 Role

type Role string

Role represents the role of a message sender.

const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

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.

Jump to

Keyboard shortcuts

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