msg

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func Assistant

func Assistant(parts ...IntoPart) *Builder

func BuildFrom

func BuildFrom(intoMsg IntoMessage) *Builder

func Developer

func Developer(text string) *Builder

func System

func System(text string) *Builder

func User

func User(text string) *Builder

func (*Builder) Build

func (b *Builder) Build() Message

func (*Builder) Cache

func (b *Builder) Cache(opts ...CacheOpt) *Builder

func (*Builder) IntoMessage

func (b *Builder) IntoMessage() Message

func (*Builder) IntoMessages

func (b *Builder) IntoMessages() []Message

func (*Builder) Part

func (b *Builder) Part(part IntoPart) *Builder

func (*Builder) Parts

func (b *Builder) Parts(parts ...IntoPart) *Builder

func (*Builder) Text

func (b *Builder) Text(text string) *Builder

func (*Builder) Thought

func (b *Builder) Thought(thought, signature string) *Builder

func (*Builder) ToolCalls

func (b *Builder) ToolCalls(toolCalls ...ToolCall) *Builder

type CacheHint

type CacheHint struct {
	// Enabled marks this content as a cache breakpoint candidate.
	// For Anthropic/Bedrock: emits cache_control / cachePoint at this position.
	// For OpenAI: no-op (caching is automatic).
	Enabled bool `json:"enabled,omitempty"`

	// TTL requests a specific cache duration.
	// Valid values: "" (provider default, typically 5m), "5m", "1h".
	// The "1h" option requires a supporting model (Claude Haiku/Sonnet/Opus 4.5+).
	TTL string `json:"ttl,omitempty"`
}

CacheHint requests provider-side prompt caching for a message or request. It is a provider-neutral instruction: Anthropic and Bedrock translate it to explicit cache breakpoints on content blocks; OpenAI caching is always automatic and ignores per-message hints, but honours TTL on Request.CacheHint.

func NewCacheHint

func NewCacheHint(opts ...CacheOpt) *CacheHint

type CacheOpt

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

type CacheTTL

type CacheTTL string
const (
	CacheTTLUnspecified CacheTTL = ""
	CacheTTL5m          CacheTTL = "5m"
	CacheTTL1h          CacheTTL = "1h"
	CacheTTLDefault              = CacheTTL5m
)

func (CacheTTL) Duration

func (ttl CacheTTL) Duration() time.Duration

func (CacheTTL) String

func (ttl CacheTTL) String() string

type IntoMessage

type IntoMessage interface{ IntoMessage() Message }

type IntoMessages

type IntoMessages interface{ IntoMessages() []Message }

type IntoPart

type IntoPart interface{ IntoPart() Part }

type IntoParts

type IntoParts interface{ IntoParts() Parts }

type IntoToolResults

type IntoToolResults interface {
	IntoToolResults() ToolResults
}

type Message

type Message struct {
	Role      Role       `json:"role"`
	Parts     Parts      `json:"parts"`
	CacheHint *CacheHint `json:"cache_hint,omitempty"`
}

func (Message) IntoMessage

func (m Message) IntoMessage() Message

func (Message) IntoMessages

func (m Message) IntoMessages() []Message

func (Message) IsAssistant

func (m Message) IsAssistant() bool

func (Message) IsDeveloper

func (m Message) IsDeveloper() bool

func (Message) IsEmpty

func (m Message) IsEmpty() bool

func (Message) IsEmptyText

func (m Message) IsEmptyText() bool

func (Message) IsSystem

func (m Message) IsSystem() bool

func (Message) IsTool

func (m Message) IsTool() bool

func (Message) IsUser

func (m Message) IsUser() bool

func (Message) Text

func (m Message) Text() string

func (Message) ToolCalls

func (m Message) ToolCalls() ToolCalls

func (Message) ToolResults

func (m Message) ToolResults() ToolResults

func (Message) Validate

func (m Message) Validate() error

type Messages

type Messages []Message

func BuildTranscript

func BuildTranscript(msg ...IntoMessages) Messages

func (Messages) Append

func (t Messages) Append(m IntoMessages) Messages

func (Messages) Filter

func (t Messages) Filter(pred func(Message) bool) Messages

func (Messages) FilterByRole

func (t Messages) FilterByRole(role Role) Messages

func (Messages) IntoMessages

func (t Messages) IntoMessages() []Message

func (Messages) PartsByType

func (t Messages) PartsByType(partType PartType) Parts

func (Messages) System

func (t Messages) System() Messages

func (Messages) Validate

func (t Messages) Validate() error

type Part

type Part struct {
	Type       PartType      `json:"type"`
	Text       string        `json:"text,omitempty"`
	ToolCall   *ToolCall     `json:"tool_call,omitempty"`
	ToolResult *ToolResult   `json:"tool_result,omitempty"`
	Thinking   *ThinkingPart `json:"thinking,omitempty"`
}

func Text

func Text(text string) Part

func Thinking

func Thinking(thought, signature string) Part

func (Part) IntoPart

func (p Part) IntoPart() Part

func (Part) Validate

func (p Part) Validate() error

type PartType

type PartType string
const (
	PartTypeText       PartType = "text"
	PartTypeThinking   PartType = "thinking"
	PartTypeToolCall   PartType = "tool_call"
	PartTypeToolResult PartType = "tool_result"
)

type Parts

type Parts []Part

func (Parts) Append

func (p Parts) Append(parts ...IntoPart) Parts

func (Parts) ByType

func (p Parts) ByType(t PartType) Parts

func (Parts) Text

func (p Parts) Text() string

func (Parts) ToolCalls

func (p Parts) ToolCalls() ToolCalls

func (Parts) ToolResults

func (p Parts) ToolResults() ToolResults

func (Parts) Validate

func (p Parts) Validate() error

type PartsBuilder

type PartsBuilder struct {
	// contains filtered or unexported fields
}

func BuildParts

func BuildParts() *PartsBuilder

func (*PartsBuilder) Build

func (b *PartsBuilder) Build() Parts

func (*PartsBuilder) IntoParts

func (b *PartsBuilder) IntoParts() Parts

func (*PartsBuilder) Part

func (b *PartsBuilder) Part(part Part) *PartsBuilder

func (*PartsBuilder) Parts

func (b *PartsBuilder) Parts(parts Parts) *PartsBuilder

func (*PartsBuilder) PartsFrom

func (b *PartsBuilder) PartsFrom(parts IntoParts) *PartsBuilder

func (*PartsBuilder) Text

func (b *PartsBuilder) Text(text string) *PartsBuilder

func (*PartsBuilder) Thinking

func (b *PartsBuilder) Thinking(thought, signature string) *PartsBuilder

func (*PartsBuilder) ToolCall

func (b *PartsBuilder) ToolCall(toolCall ToolCall) *PartsBuilder

func (*PartsBuilder) ToolResult

func (b *PartsBuilder) ToolResult(toolResult ToolResult) Part

type Role

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

type ThinkingPart

type ThinkingPart struct {
	Provider  string `json:"provider,omitempty"`
	Text      string `json:"text,omitempty"`
	Signature string `json:"signature,omitempty"`
}

func (ThinkingPart) IntoMessage

func (p ThinkingPart) IntoMessage() Message

func (ThinkingPart) IntoPart

func (p ThinkingPart) IntoPart() Part

func (ThinkingPart) Validate

func (p ThinkingPart) Validate() error

type ToolArgs

type ToolArgs map[string]any

type ToolCall

type ToolCall struct {
	ID   string   `json:"id"`
	Name string   `json:"name"`
	Args ToolArgs `json:"args"`
}

func NewToolCall

func NewToolCall(id, name string, args ToolArgs) ToolCall

NewToolCall creates a ToolCall with a non-nil Args map.

func (ToolCall) IntoPart

func (t ToolCall) IntoPart() Part

func (ToolCall) Validate

func (t ToolCall) Validate() error

type ToolCalls

type ToolCalls []ToolCall

func (ToolCalls) IntoParts

func (ts ToolCalls) IntoParts() []Part

type ToolMsgBuilder

type ToolMsgBuilder struct {
	// contains filtered or unexported fields
}

func Tool

func Tool() *ToolMsgBuilder

func (*ToolMsgBuilder) Empty

func (b *ToolMsgBuilder) Empty() *Builder

func (*ToolMsgBuilder) Results

func (b *ToolMsgBuilder) Results(src IntoToolResults) *Builder

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	ToolOutput string `json:"output"`
	IsError    bool   `json:"is_error,omitempty"`
}

func (ToolResult) IntoMessage

func (t ToolResult) IntoMessage() Message

func (ToolResult) IntoMessages

func (t ToolResult) IntoMessages() []Message

func (ToolResult) IntoPart

func (t ToolResult) IntoPart() Part

func (ToolResult) IntoParts

func (t ToolResult) IntoParts() []Part

func (ToolResult) IntoToolResults

func (t ToolResult) IntoToolResults() ToolResults

func (ToolResult) Validate

func (t ToolResult) Validate() error

type ToolResults

type ToolResults []ToolResult

func (ToolResults) IntoParts

func (t ToolResults) IntoParts() []Part

func (ToolResults) IntoToolResults

func (t ToolResults) IntoToolResults() ToolResults

Jump to

Keyboard shortcuts

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