Help us shape the future of Go! Take the 2026 Go Developer Survey

message

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(messages []Message, tools []tools.BaseTool) int64

Roughly estimate tokens count from message history This is a rough estimation: ~4 characters per token for most models

Types

type Attachment

type Attachment struct {
	FilePath string
	FileName string
	MimeType string
	Content  []byte
}

type BinaryContent

type BinaryContent struct {
	Path     string
	MIMEType string
	Data     []byte
}

func (BinaryContent) String

func (bc BinaryContent) String(provider models.ModelProvider) string

type ContentPart

type ContentPart interface {
	// contains filtered or unexported methods
}

type CreateMessageParams

type CreateMessageParams struct {
	Role  MessageRole
	Parts []ContentPart
	Model models.ModelID
	Seq   int64
}

type Finish

type Finish struct {
	Reason FinishReason `json:"reason"`
	Time   int64        `json:"time"`
}

type FinishReason

type FinishReason string
const (
	FinishReasonEndTurn          FinishReason = "end_turn"
	FinishReasonMaxTokens        FinishReason = "max_tokens"
	FinishReasonToolUse          FinishReason = "tool_use"
	FinishReasonCanceled         FinishReason = "canceled"
	FinishReasonError            FinishReason = "error"
	FinishReasonPermissionDenied FinishReason = "permission_denied"

	// Should never happen
	FinishReasonUnknown FinishReason = "unknown"
)

type ImageURLContent

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

func (ImageURLContent) String

func (iuc ImageURLContent) String() string

type Message

type Message struct {
	ID        string
	Role      MessageRole
	SessionID string
	Parts     []ContentPart
	Model     models.ModelID
	Seq       int64
	CreatedAt int64
	UpdatedAt int64
}

func (*Message) AddBinary

func (m *Message) AddBinary(mimeType string, data []byte)

func (*Message) AddFinish

func (m *Message) AddFinish(reason FinishReason)

func (*Message) AddImageURL

func (m *Message) AddImageURL(url, detail string)

func (*Message) AddToolCall

func (m *Message) AddToolCall(tc ToolCall)

func (*Message) AddToolResult

func (m *Message) AddToolResult(tr ToolResult)

func (*Message) AppendContent

func (m *Message) AppendContent(delta string)

func (*Message) AppendReasoningContent

func (m *Message) AppendReasoningContent(delta string)

func (*Message) AppendToolCallInput

func (m *Message) AppendToolCallInput(toolCallID string, inputDelta string)

func (*Message) BinaryContent

func (m *Message) BinaryContent() []BinaryContent

func (*Message) Content

func (m *Message) Content() TextContent

func (*Message) FinishPart

func (m *Message) FinishPart() *Finish

func (*Message) FinishReason

func (m *Message) FinishReason() FinishReason

func (*Message) FinishToolCall

func (m *Message) FinishToolCall(toolCallID string)

func (*Message) ImageURLContent

func (m *Message) ImageURLContent() []ImageURLContent

func (*Message) IsFinished

func (m *Message) IsFinished() bool

func (*Message) IsThinking

func (m *Message) IsThinking() bool

func (*Message) ReasoningContent

func (m *Message) ReasoningContent() ReasoningContent

func (*Message) SetToolCalls

func (m *Message) SetToolCalls(tc []ToolCall)

func (*Message) SetToolResults

func (m *Message) SetToolResults(tr []ToolResult)

func (*Message) StructOutput added in v1.3.0

func (m *Message) StructOutput() (result *ToolResult, ok bool)

StructOutput searches session message parts for a struct_output tool result ok is indicating error result (which could also mean no result)

func (*Message) ToolCalls

func (m *Message) ToolCalls() []ToolCall

func (*Message) ToolResults

func (m *Message) ToolResults() []ToolResult

func (*Message) ToolResultsByToolName added in v1.3.0

func (m *Message) ToolResultsByToolName(name string) []ToolResult

func (*Message) UpdateToolCall

func (m *Message) UpdateToolCall(tc ToolCall)

UpdateToolCall updates an existing tool call by ID. If the tool call is not found, it does nothing.

type MessageRole

type MessageRole string
const (
	Assistant MessageRole = "assistant"
	User      MessageRole = "user"
	System    MessageRole = "system"
	Tool      MessageRole = "tool"
)

type ReasoningContent

type ReasoningContent struct {
	Thinking string `json:"thinking"`
}

func (ReasoningContent) String

func (tc ReasoningContent) String() string

type Service

type Service interface {
	pubsub.Subscriber[Message]
	Create(ctx context.Context, sessionID string, params CreateMessageParams) (Message, error)
	Update(ctx context.Context, message Message) error
	Get(ctx context.Context, id string) (Message, error)
	List(ctx context.Context, sessionID string) ([]Message, error)
	Delete(ctx context.Context, id string) error
	DeleteSessionMessages(ctx context.Context, sessionID string) error
}

func NewService

func NewService(q db.QuerierWithTx, database *sql.DB) Service

type TextContent

type TextContent struct {
	Text string `json:"text"`
}

func (TextContent) String

func (tc TextContent) String() string

type ToolCall

type ToolCall struct {
	ID               string `json:"id"`
	Index            int    `json:"index"`
	Name             string `json:"name"`
	Input            string `json:"input"`
	Type             string `json:"type"`
	Finished         bool   `json:"finished"`
	ThoughtSignature string `json:"thought_signature,omitempty"`
}

type ToolResult

type ToolResult struct {
	Type       ToolResultType `json:"type"`
	ToolCallID string         `json:"tool_call_id"`
	Name       string         `json:"name"`
	Content    string         `json:"content"`
	Metadata   string         `json:"metadata"`
	IsError    bool           `json:"is_error"`
}

func (ToolResult) IsImageToolResponse

func (r ToolResult) IsImageToolResponse() bool

type ToolResultType

type ToolResultType string
const (
	ToolResultTypeText  ToolResultType = "text"
	ToolResultTypeImage ToolResultType = "image"
)

Jump to

Keyboard shortcuts

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