Documentation
¶
Overview ¶
Package models contains the public data structures used by the text package. These types are intentionally small and decoupled from internal representations so that they can remain stable for external consumers.
The main entry points are:
- Chat: a conversation consisting of ordered Messages.
- Message: a single chat message, optionally containing tool calls or rich content such as images.
- Configurations: basic configuration parameters for constructing text queriers.
- LLMTool, Specification, InputSchema, ParameterObject: types that describe and carry calls to LLM tools, and that are compatible with Model Context Protocol (MCP) style schemas.
- McpServer: describes an MCP server that can be registered and used by the underlying text engine.
- CallUsageRecorder, CompletedModelCall, ToolCallRecorder, ToolCall: telemetry seams observed by the session runner per model step and per tool invocation (worklog 26-08-11-clai-prometheus-metrics).
These types are designed to be serializable (where appropriate) and safe to pass across package boundaries without leaking internal implementation details.
Index ¶
- type Call
- type CallUsageRecorder
- type Chat
- type CompletedModelCall
- type CompletionTokensDetails
- type Configurations
- type ImageOrTextInput
- type ImageOrTextInputTypes
- type ImageURL
- type Input
- type InputSchema
- type JSONSchema
- type LLMTool
- type McpServer
- type Message
- type ParameterObject
- type PromptTokensDetails
- type QueryCost
- type ReasoningItem
- type ResponseFormat
- type Specification
- type ToolCall
- type ToolCallRecorder
- type ToolName
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Inputs *Input `json:"inputs,omitempty"`
Function Specification `json:"function"`
ExtraContent map[string]any `json:"extra_content,omitempty"`
ReasoningContent string `json:"-"`
// ReasoningItems are the opaque reasoning items (id + encrypted_content) that
// preceded this call in the same Responses turn. They are replayed before the
// function call so stateless (store:false) reasoning-model tool loops keep
// reasoning continuity. OpenAI-only; empty for other vendors.
ReasoningItems []ReasoningItem `json:"-"`
}
func (*Call) Patch ¶
func (c *Call) Patch()
Patch the call, filling structs and initializing fields so that all vendors become as happy as they can be, padding initialization inconsistencies
func (Call) PrettyPrint ¶
PrettyPrint the call, showing name and what input params is used on a concise way
type CallUsageRecorder ¶ added in v1.10.22
type CallUsageRecorder interface {
Record(context.Context, CompletedModelCall) error
}
CallUsageRecorder observes completed model calls. A nil recorder keeps clai's noop path. A Record error is logged by the session runner and never aborts the agent loop: telemetry must never break the run.
type Chat ¶
type Chat struct {
Created time.Time `json:"created"`
ID string `json:"id"`
// Source is a stable, human-readable origin label.
// Empty ("") for native clai chats.
// Examples: "claude-code", "codex", "cursor", "clai" (forked from another clai chat).
Source string `json:"source,omitempty"`
// SourceID is the originating tool's conversation identifier, or the
// parent chat ID when Source == "clai" (fork).
SourceID string `json:"source_id,omitempty"`
Profile string `json:"profile,omitempty"`
// OriginDir is the canonical working directory the chat was first persisted
// from. It is stamped once on first persist and never rewritten, enabling
// directory-anchored conversation search. Empty for conversations saved
// before origin stamping existed (forward-only).
OriginDir string `json:"origin_dir,omitempty"`
// GroupKey is the hex-encoded SHA-256 of the first user message's canonical
// text content. Empty when no user message exists, the first message is
// image-only, or the chat predates this feature. Stamped once on first
// persist; never rewritten.
GroupKey string `json:"group_key,omitempty"`
Messages []Message `json:"messages"`
// TokenUsage is the billable usage accumulated across all model calls in
// the latest session. RecentTokenUsage is only the final model call, which
// is the closest persisted gauge of the next request's context size.
TokenUsage *Usage `json:"usage,omitempty"`
RecentTokenUsage *Usage `json:"recent_usage,omitempty"`
Queries []QueryCost `json:"queries,omitempty"`
}
func (*Chat) FirstSystemMessage ¶
FirstSystemMessage returns the first encountered Message with role 'system'
func (*Chat) FirstUserMessage ¶
func (Chat) HasCostEstimates ¶ added in v1.10.4
func (*Chat) LastOfRole ¶
LastOfRole returns the last Message with the given role, along with its index position in the Messages slice. Returns an error if no message with that role is found.
func (Chat) TotalCostUSD ¶ added in v1.10.4
func (Chat) TotalTokens ¶
type CompletedModelCall ¶ added in v1.10.22
type CompletedModelCall struct {
StepIndex int
Model string
StartedAt time.Time
FinishedAt time.Time
Usage *Usage
EndedWithTool bool
EndedWithReply bool
EndedWithStop bool
}
CompletedModelCall is a record of one finished model step in a session. The session runner invokes CallUsageRecorder.Record once per model round-trip, before any tool execution the step requested. Embedded consumers (e.g. sakfraga) implement CallUsageRecorder to emit per-step telemetry.
type CompletionTokensDetails ¶
type Configurations ¶
type ImageOrTextInput ¶
type ImageOrTextInputTypes ¶
type ImageOrTextInputTypes string
const (
Image ImageOrTextInputTypes = "image_url"
)
type InputSchema ¶
type InputSchema struct {
Type string `json:"type"`
Required []string `json:"required"`
Properties map[string]ParameterObject `json:"properties"`
}
func (*InputSchema) Patch ¶
func (is *InputSchema) Patch()
Patch the input schema, making it compatible with mcp server everything https://github.com/modelcontextprotocol/servers/tree/main/src/everything which I'm calibrating towards
type JSONSchema ¶ added in v1.10.9
type JSONSchema struct {
// Name of the schema. Required by the API.
Name string
// Description of what the schema represents. Optional.
Description string
// Strict enables strict mode. When true, the model will be forced to comply.
Strict bool
// Schema is the JSON Schema definition as a map.
Schema map[string]any
}
JSONSchema defines the JSON Schema for structured output.
type LLMTool ¶
type LLMTool interface {
// Call the LLM tool with the given Input. Returns output from the tool or an error
// if the call returned an error-like. An error-like is either exit code non-zero or
// http response which isn't 2xx or 3xx.
Call(Input) (string, error)
// Return the Specification, later on used
// by text queriers to send to their respective
// models
Specification() Specification
}
type McpServer ¶
type McpServer struct {
Name string `json:"name"`
Command string `json:"command"`
Args []string `json:"args"`
Env map[string]string `json:"env"`
EnvFile string `json:"envfile,omitempty"`
// TimeoutSeconds bounds a single tool call. 0 means unbounded: the call
// waits for the server or for the caller's context, whichever comes first.
TimeoutSeconds int `json:"timeout_seconds,omitempty"`
}
type Message ¶
type Message struct {
Role string `json:"role"`
ToolCalls []Call `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
// ReasoningItems carry opaque reasoning continuity for a tool-bearing assistant
// turn. They are stored out-of-band and keyed by the first persisted tool-call
// ID, so the conversation JSON stays human-readable and portable.
ReasoningItems []ReasoningItem `json:"-"`
// Content and ContentParts is like this since
// making Message generic would cause changes in 70+ places.
//
// This way we can use ContentParts (ImageInput) without
// updating all places
Content string `json:"-"`
ContentParts []ImageOrTextInput `json:"-"`
}
func (Message) MarshalJSON ¶
func (*Message) UnmarshalJSON ¶
type ParameterObject ¶
type ParameterObject struct {
Type string `json:"-"`
Description string `json:"description"`
Enum *[]string `json:"enum,omitempty"`
Items *ParameterObject `json:"items,omitempty"`
AllOf []ParameterObject `json:"allOf,omitempty"`
AnyOf []ParameterObject `json:"anyOf,omitempty"`
OneOf []ParameterObject `json:"oneOf,omitempty"`
}
func (ParameterObject) MarshalJSON ¶
func (p ParameterObject) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshaling to always output type as a string
func (*ParameterObject) UnmarshalJSON ¶
func (p *ParameterObject) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling to handle type field as string or array and composition keywords (allOf, anyOf, oneOf)
type PromptTokensDetails ¶
type ReasoningItem ¶ added in v1.10.12
type ReasoningItem struct {
ID string `json:"id"`
EncryptedContent string `json:"encrypted_content"`
Summary []string `json:"summary,omitempty"`
}
ReasoningItem is an opaque reasoning output item from the OpenAI Responses API. EncryptedContent is sealed by OpenAI: it cannot be read locally and is only meaningful when replayed to the OpenAI Responses API for a reasoning model. It is never sent to other vendors. Persisted out-of-band in a per-chat sidecar so the conversation JSON stays human-readable.
type ResponseFormat ¶ added in v1.10.9
type ResponseFormat struct {
// Type of response format: "text", "json_object", or "json_schema".
Type string
// Schema is used when Type is "json_schema".
Schema *JSONSchema
}
ResponseFormat configures structured output for compatible models. Supported types: "text", "json_object", "json_schema".
type Specification ¶
type Specification struct {
// Name of the tool. Prefer snake_case names
Name string `json:"name"`
// Description of the tool. This will be sent to the LLM. Simple instructions on how to use the tool is suitable here
Description string `json:"description,omitempty"`
// Inputs for the tool. Describe the inputs and how to use them. This will be sent to the LLM.
Inputs *InputSchema `json:"input_schema,omitempty"`
// Arguments which may be left unfilled. This field is requirement by ChatGPT
Arguments string `json:"arguments,omitempty"`
}
Specification of the tool which will be sent to some LLM
type ToolCall ¶ added in v1.10.22
ToolCall is a record of one tool invocation executed by a session. Err is nil for a successful invocation; tools.Invoke folds failures into its output using the "ERROR: " convention, which the tool executor surfaces on this field.
type ToolCallRecorder ¶ added in v1.10.22
ToolCallRecorder observes tool invocations. A nil recorder keeps the noop path. A RecordToolCall error is logged and never aborts the agent loop.
type ToolName ¶
type ToolName string
ToolName is an enum-like type for available tools.
const ( FileTreeTool ToolName = "file_tree" CatTool ToolName = "cat" FindTool ToolName = "find" FileTypeTool ToolName = "file_type" LSTool ToolName = "ls" CpTool ToolName = "cp" RsyncTool ToolName = "rsync" MktempTool ToolName = "mktemp" WebsiteTextTool ToolName = "website_text" RipGrepTool ToolName = "rg" GoTool ToolName = "go" WriteFileTool ToolName = "write_file" ApplyPatchTool ToolName = "apply_patch" FreetextCmdTool ToolName = "freetext_command" CmdTool ToolName = "cmd" SedTool ToolName = "sed" RowsBetweenTool ToolName = "rows_between" LineCountTool ToolName = "line_count" GitTool ToolName = "git" RecallTool ToolName = "recall" FFProbeTool ToolName = "ffprobe" DateTool ToolName = "date" PwdTool ToolName = "pwd" ClaiHelpTool ToolName = "clai_help" ClaiRunTool ToolName = "clai_run" ClaiCheckTool ToolName = "clai_check" ClaiResultTool ToolName = "clai_result" ClaiWaitForWorkersTool ToolName = "clai_wait_for_workers" LoadSkillTool ToolName = "load_skill" SearchConversationsTool ToolName = "search_conversations" InspectConversationTool ToolName = "inspect_conversation" ReadMessageTool ToolName = "read_message" )
type Usage ¶
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
PromptTokensDetails PromptTokensDetails `json:"prompt_tokens_details"`
CompletionTokensDetails CompletionTokensDetails `json:"completion_tokens_details"`
}