schema

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventAssistant = "assistant" // Streamed text chunk from the assistant
	EventThinking  = "thinking"  // Streamed thinking/reasoning chunk
	EventTool      = "tool"      // Tool call feedback (name, description)
	EventUsage     = "usage"     // Token usage update
	EventError     = "error"     // Error during processing
	EventResult    = "result"    // Final complete response
)
View Source
const (
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleSystem    = "system"
	RoleThinking  = "thinking"
	RoleTool      = "tool"
)

Message role constants

View Source
const (
	Gemini    = "gemini"
	Anthropic = "anthropic"
	Mistral   = "mistral"
	Eliza     = "eliza"
)

Provider name constants

View Source
const BuiltinNamespace = "builtin"

BuiltinNamespace is the namespace used for locally-implemented (builtin) tools.

View Source
const DefaultMaxIterations = 10

DefaultMaxIterations is the default maximum number of tool-calling iterations per chat turn.

View Source
const (
	EmbeddingTaskTypeDefault = "DEFAULT"
)
View Source
const ResultOK = ResultStop

ResultOK is an alias for ResultStop (normal completion).

Variables

View Source
var ConnectorURLSchemes = []string{"http", "https"}

ConnectorURLSchemes lists the URL schemes that are accepted for connector registration. Connectors must use one of these schemes.

Functions

func CanonicalNamespace added in v0.4.2

func CanonicalNamespace(ns string) string

CanonicalNamespace normalises a namespace string by lowercasing it, removing spaces and replacing "-" and "." characters with underscores.

func CanonicalURL added in v0.4.2

func CanonicalURL(rawURL string) (string, error)

CanonicalURL validates rawURL and returns a canonical form consisting of scheme://host[:port]/path with a lowercased scheme, host, and path. The URL must be absolute, use a supported scheme (http or https), have a non-empty host, and — if a port is present — a valid port in 1–65535. Any userinfo, query string, or fragment is stripped.

func WithAttachment

func WithAttachment(r io.Reader) opt.Opt

WithAttachmentURL creates an attachment from data read from the provided reader The MIME type is detected from the data. This is suitable for small attachments the caller is responsible for closing the reader after the data is read.

func WithAttachmentURL

func WithAttachmentURL(u string, mimetype string) opt.Opt

WithAttachmentURL creates an attachment from a URL and explicit MIME type

Types

type Agent added in v0.3.0

type Agent struct {
	ID      string    `json:"id"`
	Created time.Time `json:"created"`
	Version uint      `json:"version"`
	AgentMeta
}

Agent is a versioned, stored agent definition.

func (Agent) String added in v0.3.0

func (a Agent) String() string

type AgentMeta added in v0.3.0

type AgentMeta struct {
	GeneratorMeta `yaml:",inline"`
	Name          string     `json:"name" yaml:"name" help:"Unique agent name"`
	Title         string     `json:"title,omitempty" yaml:"title" help:"Human-readable title" optional:""`
	Description   string     `json:"description,omitempty" yaml:"description" help:"Agent description" optional:""`
	Template      string     `json:"template,omitempty" yaml:"-" help:"Go template for the user message" optional:""`
	Input         JSONSchema `json:"input,omitempty" yaml:"input" help:"JSON schema for agent input" optional:""`
	Tools         []string   `json:"tools,omitzero" yaml:"tools" help:"Tool names the agent is allowed to use" optional:""`
}

AgentMeta describes the definition of an agent, including which model and provider to use and the schemas that govern its input and output.

func (AgentMeta) String added in v0.3.0

func (a AgentMeta) String() string

type AgentStore added in v0.3.0

type AgentStore interface {
	// CreateAgent creates a new agent from the given metadata,
	// returning the agent with a unique ID and version 1.
	CreateAgent(ctx context.Context, meta AgentMeta) (*Agent, error)

	// GetAgent retrieves an existing agent by ID or name.
	// Returns an error if the agent does not exist.
	GetAgent(ctx context.Context, id string) (*Agent, error)

	// ListAgents returns agents matching the request, with pagination support.
	// Returns offset, limit and total count in the response.
	ListAgents(ctx context.Context, req ListAgentRequest) (*ListAgentResponse, error)

	// DeleteAgent removes an agent by ID or name. When a name is provided,
	// all versions of the agent are deleted. Returns an error if no matching
	// agent exists.
	DeleteAgent(ctx context.Context, id string) error

	// UpdateAgent applies non-zero fields from the given metadata to an existing
	// agent and increments the version. Returns the updated agent.
	UpdateAgent(ctx context.Context, id string, meta AgentMeta) (*Agent, error)
}

AgentStore is the interface for agent storage backends.

type AgentTable added in v0.3.0

type AgentTable []*Agent

AgentTable implements table.TableData for a list of agents.

func (AgentTable) Header added in v0.3.0

func (t AgentTable) Header() []string

func (AgentTable) Len added in v0.3.0

func (t AgentTable) Len() int

func (AgentTable) Row added in v0.3.0

func (t AgentTable) Row(i int) []any

type AskRequest

type AskRequest struct {
	AskRequestCore
	Attachments []Attachment `json:"attachments,omitempty" help:"File attachments" optional:""`
}

AskRequest represents a stateless request to generate content.

func (AskRequest) String

func (r AskRequest) String() string

type AskRequestCore added in v0.4.0

type AskRequestCore struct {
	GeneratorMeta
	Text string `json:"text" arg:"" help:"User input text"`
}

AskRequestCore contains the core fields of an ask request without attachments.

func (AskRequestCore) String added in v0.4.0

func (r AskRequestCore) String() string

type AskResponse

type AskResponse struct {
	CompletionResponse
	Usage *Usage `json:"usage,omitempty"`
}

AskResponse represents the response from an ask request.

func (AskResponse) String

func (r AskResponse) String() string

type Attachment

type Attachment struct {
	Type string   `json:"type"`           // MIME type: "image/png", "application/pdf", etc.
	Data []byte   `json:"data,omitempty"` // Raw binary data
	URL  *url.URL `json:"url,omitempty"`  // URL reference (http, https, gs, file, etc.)
}

Attachment represents binary or URI-referenced media (images, documents, etc.)

func (Attachment) Description added in v0.4.2

func (a Attachment) Description() string

Description returns an empty string. Satisfies llm.Resource.

func (Attachment) IsText

func (a Attachment) IsText() bool

IsText returns true if the attachment has a text/* MIME type (e.g. text/plain, text/html, text/csv). Handles MIME parameters like charset gracefully. Such attachments can be converted to text blocks when providers don't support them as media uploads.

func (Attachment) MIMEType added in v0.4.2

func (a Attachment) MIMEType() string

MIMEType returns the MIME type of the attachment. Satisfies llm.Resource.

func (Attachment) Name added in v0.4.2

func (a Attachment) Name() string

Name returns the last path segment of the attachment URL, or an empty string for inline data. Satisfies llm.Resource.

func (Attachment) Read added in v0.4.2

func (a Attachment) Read(ctx context.Context) ([]byte, error)

Read returns the attachment's raw bytes. If Data is non-empty it is returned directly. If URL is set and has a supported scheme (http, https, file) the content is fetched. Satisfies llm.Resource.

func (Attachment) TextContent

func (a Attachment) TextContent() string

TextContent returns the attachment's data as a string, optionally prefixed with the filename and content type for context. Only meaningful when IsText() returns true.

func (Attachment) URI added in v0.4.2

func (a Attachment) URI() string

URI returns the URL of the attachment as a string, or an empty string if the attachment is inline data only. Satisfies llm.Resource.

type CallToolRequest added in v0.3.1

type CallToolRequest struct {
	Input json.RawMessage `json:"input,omitempty"`
}

CallToolRequest represents a request to call a tool directly

func (CallToolRequest) String added in v0.3.1

func (r CallToolRequest) String() string

type CallToolResponse added in v0.3.1

type CallToolResponse struct {
	Tool   string          `json:"tool"`
	Result json.RawMessage `json:"result"`
}

CallToolResponse represents the result of calling a tool

func (CallToolResponse) String added in v0.3.1

func (r CallToolResponse) String() string

type Capability added in v0.4.2

type Capability string

Capability represents a named capability advertised by an MCP server.

const (
	// CapabilityTools indicates the server advertises callable tools.
	CapabilityTools Capability = "tools"

	// CapabilityResources indicates the server can serve resources.
	CapabilityResources Capability = "resources"

	// CapabilityPrompts indicates the server provides reusable prompt templates.
	CapabilityPrompts Capability = "prompts"

	// CapabilityLogging indicates the server emits log notifications.
	CapabilityLogging Capability = "logging"

	// CapabilityCompletions indicates the server supports argument/prompt completion.
	CapabilityCompletions Capability = "completions"
)

type ChatRequest

type ChatRequest struct {
	ChatRequestCore
	Attachments []Attachment `json:"attachments,omitempty" help:"File attachments" optional:""`
}

ChatRequest represents a stateful chat request within a session.

func (ChatRequest) String

func (r ChatRequest) String() string

type ChatRequestCore added in v0.4.0

type ChatRequestCore struct {
	Session       string   `json:"session" help:"Session ID"`
	Text          string   `json:"text" arg:"" help:"User input text"`
	Tools         []string `json:"tools,omitzero" help:"Tool names to include (nil means all, empty means none)" optional:""`
	MaxIterations uint     `json:"max_iterations,omitempty" help:"Maximum tool-calling iterations (0 uses default)" optional:""`
	SystemPrompt  string   `json:"system_prompt,omitempty" help:"Per-request system prompt appended to the session prompt" optional:""`
}

ChatRequestCore contains the core fields of a chat request without attachments.

func (ChatRequestCore) String added in v0.4.0

func (r ChatRequestCore) String() string

type ChatResponse

type ChatResponse struct {
	CompletionResponse
	Session string `json:"session"`
	Usage   *Usage `json:"usage,omitempty"`
}

ChatResponse represents the response from a chat request.

func (ChatResponse) String

func (r ChatResponse) String() string

type CompletionResponse

type CompletionResponse struct {
	Role    string         `json:"role"`
	Content []ContentBlock `json:"content"`
	Result  ResultType     `json:"result"`
}

CompletionResponse represents a response from a completion request.

func (CompletionResponse) String

func (r CompletionResponse) String() string

type Connector added in v0.4.2

type Connector struct {
	// URL is the MCP server endpoint (used as the primary key).
	URL string `json:"url"`

	// CreatedAt is the time the connector was first registered.
	CreatedAt time.Time `json:"created_at"`

	// Embedded metadata and state fields
	ConnectorMeta
	ConnectorState
}

Connector combines persisted metadata with runtime state for an MCP server.

func (Connector) String added in v0.4.2

func (c Connector) String() string

type ConnectorMeta added in v0.4.2

type ConnectorMeta struct {
	// Enabled controls whether the server is active. Disabled servers are
	// retained in the registry but not connected on startup.
	// A nil value in a patch request means "preserve the existing value".
	Enabled *bool `json:"enabled,omitempty"`

	// Namespace is an optional prefix used to disambiguate tools from this
	// connector when multiple connectors expose tools with the same name.
	// A nil value in a patch request means "preserve the existing value".
	Namespace *string `json:"namespace,omitempty"`
}

ConnectorMeta holds the user-configurable settings for a registered MCP server.

func (ConnectorMeta) String added in v0.4.2

func (c ConnectorMeta) String() string

type ConnectorState added in v0.4.2

type ConnectorState struct {
	// ConnectedAt is the time of the most recent successful connection.
	ConnectedAt *time.Time `json:"connected_at,omitempty"`

	// Name is the programmatic identifier reported by the server.
	Name *string `json:"name,omitempty"`

	// Title is a human-readable display name reported by the server.
	Title *string `json:"title,omitempty"`

	// Description is the server-reported description.
	Description *string `json:"description,omitempty"`

	// Version is the server-reported version string.
	Version *string `json:"version,omitempty"`

	// Capabilities is the set of capabilities declared at initialization.
	Capabilities []Capability `json:"capabilities,omitempty"`
}

ConnectorState carries the server-reported runtime state of a connector. All fields are pointers so callers can update a subset without overwriting fields they did not observe.

func (ConnectorState) String added in v0.4.2

func (c ConnectorState) String() string

type ConnectorStore added in v0.4.2

type ConnectorStore interface {
	// CreateConnector registers a new MCP server. url is used as the primary
	// key. Returns an error if a connector with that URL already exists.
	CreateConnector(ctx context.Context, url string, meta ConnectorMeta) (*Connector, error)

	// GetConnector returns the connector for the given URL, or an error if not found.
	GetConnector(ctx context.Context, url string) (*Connector, error)

	// UpdateConnector applies meta to the connector identified by url.
	// Only user-editable fields (ConnectorMeta) are updated; server-reported
	// fields are ignored. Returns an error if the connector does not exist.
	UpdateConnector(ctx context.Context, url string, meta ConnectorMeta) (*Connector, error)

	// DeleteConnector removes the connector for the given URL.
	DeleteConnector(ctx context.Context, url string) error

	// ListConnectors returns connectors matching the request filters.
	// Supports pagination via Offset/Limit and optional filtering by Namespace and Enabled.
	ListConnectors(ctx context.Context, req ListConnectorsRequest) (*ListConnectorsResponse, error)

	// UpdateConnectorState merges state into the connector identified by url,
	// updating only the non-nil fields in state. Intended to be called after
	// a successful connection to record server-reported information.
	// Returns an error if the connector does not exist.
	UpdateConnectorState(ctx context.Context, url string, state ConnectorState) (*Connector, error)
}

ConnectorStore is the interface for persisting MCP connector registrations.

type ConnectorTable added in v0.4.2

type ConnectorTable []*Connector

ConnectorTable implements table.TableData for a list of connectors.

func (ConnectorTable) Header added in v0.4.2

func (t ConnectorTable) Header() []string

func (ConnectorTable) Len added in v0.4.2

func (t ConnectorTable) Len() int

func (ConnectorTable) Row added in v0.4.2

func (t ConnectorTable) Row(i int) []any

type ContentBlock

type ContentBlock struct {
	Text       *string     `json:"text,omitempty"`        // Text content
	Thinking   *string     `json:"thinking,omitempty"`    // Thinking/reasoning content
	Attachment *Attachment `json:"attachment,omitempty"`  // Image, document, audio, etc.
	ToolCall   *ToolCall   `json:"tool_call,omitempty"`   // Tool invocation (assistant → user)
	ToolResult *ToolResult `json:"tool_result,omitempty"` // Tool response (user → assistant)
}

ContentBlock represents a single piece of content within a message. Exactly one of the fields should be non-nil/non-empty.

func NewToolError

func NewToolError(id, name string, err error) ContentBlock

NewToolError creates a content block containing a tool error result

func NewToolResult

func NewToolResult(id, name string, v any) ContentBlock

NewToolResult creates a content block containing a successful tool result

type Conversation

type Conversation []*Message

Conversation is a sequence of messages exchanged with an LLM

func (*Conversation) Append

func (s *Conversation) Append(message Message)

Append adds a message to the conversation

func (*Conversation) AppendWithOuput

func (s *Conversation) AppendWithOuput(message Message, input, output uint)

AppendWithOutput adds a message to the conversation, attributing token counts to individual messages. The last message in the conversation (typically the just-appended user message) receives an estimated token count based on its content rather than absorbing overhead such as tool schemas and system prompts. The response message receives the actual output token count from the provider.

func (Conversation) String

func (s Conversation) String() string

func (Conversation) Tokens

func (s Conversation) Tokens() uint

Return the total number of tokens in the conversation

type CreateAgentSessionRequest added in v0.3.0

type CreateAgentSessionRequest struct {
	Parent string          `json:"parent,omitempty" help:"Parent session ID for traceability" optional:""`
	Input  json.RawMessage `json:"input,omitempty" help:"Input data for the agent template" optional:""`
}

CreateAgentSessionRequest represents the body of a request to create a session from an agent definition. The agent is identified by path/query parameters (agent ID or name, optional version) — not included here. The agent's template is executed with Input, and a new session is created with the merged GeneratorMeta and agent labels. If Parent is set, the parent session's GeneratorMeta is used as defaults (agent fields take precedence). The caller can then use the returned text and tools with the Chat endpoint.

func (CreateAgentSessionRequest) String added in v0.3.0

func (r CreateAgentSessionRequest) String() string

type CreateAgentSessionResponse added in v0.3.0

type CreateAgentSessionResponse struct {
	Session string   `json:"session"`         // Created session ID
	Text    string   `json:"text"`            // Rendered template text (first user message)
	Tools   []string `json:"tools,omitempty"` // Tool names the agent is allowed to use
}

CreateAgentSessionResponse is the result of creating a session from an agent. It contains the session ID plus the prepared text and tools, which can be passed directly to a ChatRequest.

func (CreateAgentSessionResponse) String added in v0.3.0

type CredentialStore added in v0.4.0

type CredentialStore interface {
	// GetCredential retrieves the credential for the given server URL.
	GetCredential(ctx context.Context, url string) (*OAuthCredentials, error)

	// SetCredential stores (or updates) the credential for the given server URL.
	SetCredential(ctx context.Context, url string, cred OAuthCredentials) error

	// DeleteCredential removes the credential for the given server URL.
	DeleteCredential(ctx context.Context, url string) error
}

CredentialStore is the interface for credential storage backends.

type EmbeddingRequest

type EmbeddingRequest struct {
	Provider             string   `json:"provider,omitempty" help:"Provider name" optional:""`
	Model                string   `json:"model,omitempty" help:"Model name" optional:""`
	Input                []string `json:"input,omitempty" arg:"" help:"Text inputs to embed"`
	TaskType             string   `` /* 244-byte string literal not displayed */
	Title                string   `json:"title,omitempty" help:"Document title, used with RETRIEVAL_DOCUMENT task type (Google-specific)"`
	OutputDimensionality uint     `json:"output_dimensionality,omitempty" help:"Truncate embedding to this many dimensions (Google-specific)"`
}

EmbeddingRequest represents a request to embed text

func (EmbeddingRequest) String

func (r EmbeddingRequest) String() string

type EmbeddingResponse

type EmbeddingResponse struct {
	EmbeddingRequest
	Output [][]float64 `json:"output,omitempty"`
}

EmbeddingResponse represents a response from an embedding request

func (EmbeddingResponse) String

func (r EmbeddingResponse) String() string

type GeneratorMeta

type GeneratorMeta struct {
	Provider       string     `json:"provider,omitempty" yaml:"provider" help:"Provider name" optional:""`
	Model          string     `json:"model,omitempty" yaml:"model" help:"Model name" optional:""`
	SystemPrompt   string     `json:"system_prompt,omitempty" yaml:"system_prompt" help:"System prompt" optional:""`
	Format         JSONSchema `json:"format,omitempty" yaml:"format" help:"JSON schema for structured output" optional:""`
	Thinking       *bool      `json:"thinking,omitempty" yaml:"thinking" help:"Enable thinking/reasoning" optional:""`
	ThinkingBudget uint       `` /* 142-byte string literal not displayed */
}

GeneratorMeta represents the metadata needed to invoke a generator model.

func (GeneratorMeta) String

func (r GeneratorMeta) String() string

type GetModelRequest

type GetModelRequest struct {
	Provider string `json:"provider,omitempty" help:"Filter by provider name" optional:""`
	Name     string `json:"name,omitempty" help:"Model name"`
}

GetModelRequest represents a request to get a model

func (GetModelRequest) String

func (r GetModelRequest) String() string

type JSONSchema added in v0.3.0

type JSONSchema json.RawMessage

JSONSchema is a JSON-encoded schema that supports unmarshalling from both JSON and YAML sources. When unmarshalling from YAML, the YAML node is first decoded to a native Go value and then marshalled to JSON bytes.

func NewJSONSchema added in v0.3.0

func NewJSONSchema(data json.RawMessage) JSONSchema

NewJSONSchema creates a JSONSchema from raw JSON bytes.

func (JSONSchema) Bytes added in v0.3.0

func (s JSONSchema) Bytes() []byte

Bytes returns the underlying JSON bytes.

func (JSONSchema) MarshalJSON added in v0.3.0

func (s JSONSchema) MarshalJSON() ([]byte, error)

func (*JSONSchema) UnmarshalJSON added in v0.3.0

func (s *JSONSchema) UnmarshalJSON(data []byte) error

func (*JSONSchema) UnmarshalYAML added in v0.3.0

func (s *JSONSchema) UnmarshalYAML(node *yaml.Node) error

type ListAgentRequest added in v0.3.0

type ListAgentRequest struct {
	Name    string `json:"name,omitempty" help:"Filter by agent name" optional:""`
	Version *uint  `json:"version,omitempty" help:"Filter by version number (requires name)" optional:""`
	Limit   *uint  `json:"limit,omitempty" help:"Maximum number of agents to return" default:"100"`
	Offset  uint   `json:"offset,omitempty" help:"Offset for pagination" default:"0"`
}

ListAgentRequest represents a request to list agents

func (ListAgentRequest) String added in v0.3.0

func (r ListAgentRequest) String() string

type ListAgentResponse added in v0.3.0

type ListAgentResponse struct {
	Count  uint     `json:"count"`
	Offset uint     `json:"offset,omitzero"`
	Limit  *uint    `json:"limit,omitzero"`
	Body   []*Agent `json:"body,omitzero"`
}

ListAgentResponse represents a response containing a list of agents

func (ListAgentResponse) String added in v0.3.0

func (r ListAgentResponse) String() string

type ListConnectorsRequest added in v0.4.2

type ListConnectorsRequest struct {
	Namespace string `json:"namespace,omitempty" help:"Filter by namespace" optional:""`
	Enabled   *bool  `json:"enabled,omitempty" help:"Filter by enabled state" optional:""`
	Limit     *uint  `json:"limit,omitempty" help:"Maximum number of connectors to return" default:"100"`
	Offset    uint   `json:"offset,omitempty" help:"Offset for pagination" default:"0"`
}

ListConnectorsRequest represents a request to list registered MCP connectors.

func (ListConnectorsRequest) String added in v0.4.2

func (r ListConnectorsRequest) String() string

type ListConnectorsResponse added in v0.4.2

type ListConnectorsResponse struct {
	Count  uint         `json:"count"`
	Offset uint         `json:"offset,omitzero"`
	Limit  *uint        `json:"limit,omitzero"`
	Body   []*Connector `json:"body,omitzero"`
}

ListConnectorsResponse represents a response containing a list of MCP connectors.

func (ListConnectorsResponse) String added in v0.4.2

func (r ListConnectorsResponse) String() string

type ListModelsRequest

type ListModelsRequest struct {
	Provider string `json:"provider,omitempty" help:"Filter by provider name" optional:""`
	Limit    *uint  `json:"limit,omitempty" help:"Maximum number of models to return" default:"100"`
	Offset   uint   `json:"offset,omitempty" help:"Offset for pagination" default:"0"`
}

ListModelsRequest represents a request to list models

func (ListModelsRequest) String

func (r ListModelsRequest) String() string

type ListModelsResponse

type ListModelsResponse struct {
	Count    uint     `json:"count"`
	Offset   uint     `json:"offset,omitzero"`
	Limit    *uint    `json:"limit,omitzero"`
	Provider []string `json:"provider,omitempty"`
	Body     []Model  `json:"body,omitzero"`
}

ListModelsResponse represents a response containing a list of models and providers

func (ListModelsResponse) String

func (r ListModelsResponse) String() string

type ListSessionRequest

type ListSessionRequest struct {
	Limit  *uint    `json:"limit,omitempty" help:"Maximum number of sessions to return" default:"100"`
	Offset uint     `json:"offset,omitempty" help:"Offset for pagination" default:"0"`
	Label  []string `json:"label,omitempty" help:"Filter by labels (key:value)"`
}

ListSessionRequest represents a request to list sessions

func (ListSessionRequest) String

func (r ListSessionRequest) String() string

type ListSessionResponse

type ListSessionResponse struct {
	Count  uint       `json:"count"`
	Offset uint       `json:"offset,omitzero"`
	Limit  *uint      `json:"limit,omitzero"`
	Body   []*Session `json:"body,omitzero"`
}

ListSessionResponse represents a response containing a list of sessions

func (ListSessionResponse) String

func (r ListSessionResponse) String() string

type ListToolRequest

type ListToolRequest struct {
	Limit  *uint `json:"limit,omitempty" help:"Maximum number of tools to return" default:"100"`
	Offset uint  `json:"offset,omitempty" help:"Offset for pagination" default:"0"`
}

ListToolRequest represents a request to list tools

func (ListToolRequest) String

func (r ListToolRequest) String() string

type ListToolResponse

type ListToolResponse struct {
	Count  uint       `json:"count"`
	Offset uint       `json:"offset,omitzero"`
	Limit  *uint      `json:"limit,omitzero"`
	Body   []ToolMeta `json:"body,omitzero"`
}

ListToolResponse represents a response containing a list of tools

func (ListToolResponse) String

func (r ListToolResponse) String() string

type ListToolsRequest added in v0.4.2

type ListToolsRequest struct {
	// Namespace restricts results to a single namespace.
	// Use BuiltinNamespace for locally-implemented tools, a connector URL for
	// remote tools, or leave empty to include all namespaces.
	Namespace string `json:"namespace,omitempty"`

	// Name restricts results to tools whose names appear in this list.
	// An empty slice means no name filter — all names are included.
	Name []string `json:"name,omitempty"`
}

ListToolsRequest specifies optional filters for the Toolkit.ListTools method. Zero value returns all tools from all namespaces.

type Message

type Message struct {
	Role    string         `json:"role"`             // "user", "assistant", "system"
	Content []ContentBlock `json:"content"`          // Array of content blocks
	Tokens  uint           `json:"tokens,omitempty"` // Number of tokens
	Result  ResultType     `json:"result"`           // Result type
	Meta    map[string]any `json:"meta,omitzero"`    // Provider-specific metadata
}

Message represents a message in a conversation with an LLM. It uses a universal content block representation that can be marshaled to any provider's format.

func NewMessage

func NewMessage(role string, text string, opts ...opt.Opt) (*Message, error)

Create a new message with the given role and text content

func (Message) EstimateTokens

func (m Message) EstimateTokens() uint

EstimateTokens returns a rough token count for the message content. It estimates ~4 characters per token for text, plus a fixed cost per non-text block (attachments, tool calls/results). This is useful for attributing per-message token costs without a provider-specific tokeniser.

func (Message) String

func (m Message) String() string

func (Message) Text

func (m Message) Text() string

Text returns the concatenated text content from all text blocks in the message

func (Message) ToolCalls

func (m Message) ToolCalls() []ToolCall

ToolCalls returns all tool call blocks in the message

type Model

type Model struct {
	Name        string         `json:"name,omitzero"`
	Description string         `json:"description,omitzero"`
	Created     time.Time      `json:"created,omitzero"`
	OwnedBy     string         `json:"owned_by,omitzero"` // Model provider
	Aliases     []string       `json:"aliases,omitzero"`  // Model aliases
	Meta        map[string]any `json:"meta,omitzero"`     // Provider-specific metadata
}

Represents an LLM model

func (Model) String

func (m Model) String() string

type ModelTable added in v0.3.0

type ModelTable struct {
	Models       []Model
	CurrentModel string
}

ModelTable implements table.TableData for a list of models.

func (ModelTable) Header added in v0.3.0

func (t ModelTable) Header() []string

func (ModelTable) Len added in v0.3.0

func (t ModelTable) Len() int

func (ModelTable) Row added in v0.3.0

func (t ModelTable) Row(i int) []any

type MultipartAskRequest

type MultipartAskRequest struct {
	AskRequest
	File types.File `json:"file,omitempty" help:"File attachment (multipart upload)" optional:""`
}

MultipartAskRequest is the HTTP-layer request type supporting both JSON (with base64 attachments) and multipart/form-data file uploads.

func (*MultipartAskRequest) FileAttachment

func (r *MultipartAskRequest) FileAttachment() (*Attachment, error)

FileAttachment reads the multipart file (if present) and returns it as an Attachment with auto-detected MIME type. Returns nil if no file was uploaded.

type MultipartChatRequest

type MultipartChatRequest struct {
	ChatRequest
	File types.File `json:"file,omitempty" help:"File attachment (multipart upload)" optional:""`
}

MultipartChatRequest is the HTTP-layer request type supporting both JSON (with base64 attachments) and multipart/form-data file uploads for chat.

func (*MultipartChatRequest) FileAttachment

func (r *MultipartChatRequest) FileAttachment() (*Attachment, error)

FileAttachment reads the multipart file (if present) and returns it as an Attachment with auto-detected MIME type. Returns nil if no file was uploaded.

type OAuthCredentials added in v0.4.0

type OAuthCredentials struct {
	*oauth2.Token

	// ClientID is the OAuth client ID used to obtain this token.
	ClientID string `json:"client_id"`

	// ClientSecret is the OAuth client secret, if any (for confidential clients).
	// Needed for token refresh with servers that require client authentication.
	ClientSecret string `json:"client_secret,omitempty"`

	// Endpoint is the MCP/OAuth server endpoint (used for discovery).
	Endpoint string `json:"endpoint"`

	// TokenURL is the OAuth token endpoint URL (used for refresh without re-discovery).
	TokenURL string `json:"token_url"`
}

OAuthCredentials bundles an OAuth token with the metadata needed to refresh or reuse it later without re-discovering or re-registering.

type ProviderTable added in v0.3.0

type ProviderTable []string

ProviderTable implements table.TableData for a list of provider names.

func (ProviderTable) Header added in v0.3.0

func (t ProviderTable) Header() []string

func (ProviderTable) Len added in v0.3.0

func (t ProviderTable) Len() int

func (ProviderTable) Row added in v0.3.0

func (t ProviderTable) Row(i int) []any

type ResultType

type ResultType uint

The result of generating a message (stopped, error, etc.)

const (
	ResultStop          ResultType = iota // Normal completion
	ResultMaxTokens                       // Truncated due to max tokens
	ResultBlocked                         // Blocked by safety, recitation, or content filter
	ResultToolCall                        // Model requested a tool call
	ResultError                           // Generation error
	ResultOther                           // Other/unknown finish reason
	ResultMaxIterations                   // Tool-calling loop exhausted max iterations
)

func (ResultType) MarshalJSON

func (r ResultType) MarshalJSON() ([]byte, error)

func (ResultType) String

func (r ResultType) String() string

func (*ResultType) UnmarshalJSON

func (r *ResultType) UnmarshalJSON(data []byte) error

type Session

type Session struct {
	ID string `json:"id"`
	SessionMeta
	Messages Conversation `json:"messages,omitempty"`
	Overhead uint         `json:"overhead,omitempty"` // Constant token cost per turn (tools, system prompt)
	Created  time.Time    `json:"created"`
	Modified time.Time    `json:"modified"`
}

Session represents a stored conversation with an LLM.

func (*Session) Append

func (s *Session) Append(message Message)

Append adds a message to the session and updates the modified timestamp.

func (*Session) Conversation

func (s *Session) Conversation() *Conversation

Conversation returns a pointer to the underlying message slice, compatible with generator.WithSession.

func (*Session) String

func (s *Session) String() string

func (*Session) Tokens

func (s *Session) Tokens() uint

Tokens returns the total token count across all messages.

func (*Session) Validate

func (s *Session) Validate() error

Validate returns an error if the session is missing required fields.

type SessionMeta

type SessionMeta struct {
	GeneratorMeta
	Name   string            `json:"name,omitempty" help:"Session name" optional:""`
	Labels map[string]string `json:"labels,omitempty" help:"User-defined labels for UI storage" optional:""`
}

SessionMeta represents the metadata for a session.

func (SessionMeta) String

func (r SessionMeta) String() string

type SessionStore added in v0.3.0

type SessionStore interface {
	// CreateSession creates a new session from the given metadata,
	// returning the session with a unique ID assigned.
	CreateSession(ctx context.Context, meta SessionMeta) (*Session, error)

	// GetSession retrieves an existing session by ID.
	// Returns an error if the session does not exist.
	GetSession(ctx context.Context, id string) (*Session, error)

	// ListSessions returns sessions matching the request, with pagination support.
	// Returns offset, limit and total count in the response.
	ListSessions(ctx context.Context, req ListSessionRequest) (*ListSessionResponse, error)

	// DeleteSession removes a session by ID.
	// Returns an error if the session does not exist.
	DeleteSession(ctx context.Context, id string) error

	// UpdateSession applies non-zero fields from the given metadata to an existing session.
	// Returns the updated session or an error if the session does not exist.
	UpdateSession(ctx context.Context, id string, meta SessionMeta) (*Session, error)

	// WriteSession persists the current state of a session.
	WriteSession(s *Session) error
}

SessionStore is the interface for session storage backends.

type SessionTable added in v0.3.0

type SessionTable struct {
	Sessions       []*Session
	CurrentSession string
}

SessionTable implements table.TableData for a list of sessions.

func (SessionTable) Header added in v0.3.0

func (t SessionTable) Header() []string

func (SessionTable) Len added in v0.3.0

func (t SessionTable) Len() int

func (SessionTable) Row added in v0.3.0

func (t SessionTable) Row(i int) []any

type StreamDelta

type StreamDelta struct {
	Role string `json:"role"`
	Text string `json:"text"`
}

StreamDelta represents a single streamed text chunk in an SSE stream.

type StreamError

type StreamError struct {
	Error string `json:"error"`
}

StreamError represents an error event in an SSE stream.

type ToolCall

type ToolCall struct {
	ID    string          `json:"id,omitempty"`    // Provider-assigned call ID
	Name  string          `json:"name"`            // Tool function name
	Input json.RawMessage `json:"input,omitempty"` // JSON-encoded arguments
	Meta  map[string]any  `json:"meta,omitempty"`  // Provider-specific metadata (e.g. thought_signature)
}

ToolCall represents a tool invocation requested by the model

type ToolMeta

type ToolMeta struct {
	Name        string     `json:"name"`
	Description string     `json:"description,omitempty"`
	Input       JSONSchema `json:"input,omitempty"`
}

ToolMeta represents a tool's metadata

func NewToolMeta added in v0.3.1

func NewToolMeta(name, description string, inputSchema any) (ToolMeta, error)

NewToolMeta creates a ToolMeta with the given name, description and optional input schema. The schema value (if non-nil) is marshalled to JSON.

func (ToolMeta) String

func (r ToolMeta) String() string

type ToolResult

type ToolResult struct {
	ID      string          `json:"id,omitempty"`      // Matches the ToolCall ID
	Name    string          `json:"name,omitempty"`    // Tool function name
	Content json.RawMessage `json:"content,omitempty"` // JSON-encoded result
	IsError bool            `json:"is_error,omitempty"`
}

ToolResult represents the result of running a tool

type ToolTable added in v0.3.0

type ToolTable []ToolMeta

ToolTable implements table.TableData for a list of tools.

func (ToolTable) Header added in v0.3.0

func (t ToolTable) Header() []string

func (ToolTable) Len added in v0.3.0

func (t ToolTable) Len() int

func (ToolTable) Row added in v0.3.0

func (t ToolTable) Row(i int) []any

type Usage

type Usage struct {
	InputTokens  uint `json:"input_tokens,omitempty"`
	OutputTokens uint `json:"output_tokens,omitempty"`
}

Usage represents the token usage for a single request/response.

Jump to

Keyboard shortcuts

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