Documentation
¶
Index ¶
- func CreateTitleFromMessage(content string) string
- func FormatChannelSessionID(channel, senderID string) string
- func FormatModelPricingLabel(pricingService PricingService, model string) string
- func NewToolCallEntries(toolCall sdk.ChatCompletionMessageToolCall, ...) (ConversationEntry, ConversationEntry)
- func ParseChannelSessionID(sessionID string) (channel, recipientID string, ok bool)
- type ConversationEntry
- type ConversationMetadata
- type ConversationOptimizer
- type ConversationRepository
- type ConversationSummary
- type ExportFormat
- type MessageQueue
- type ModelCostStats
- type ModelService
- type PlanApprovalStatus
- type PricingService
- type QueuedMessage
- type SessionCostStats
- type SessionID
- type SessionTokenStats
- type TokenEstimator
- type ToolApprovalStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTitleFromMessage ¶
CreateTitleFromMessage creates a short title from message content (fallback title)
func FormatChannelSessionID ¶
FormatChannelSessionID builds the session ID the daemon's channel manager uses for a channel/sender pair, the inverse of ParseChannelSessionID. ponytail: channel names must not contain '-' (they're a fixed enum today; sender IDs may contain dashes and are parsed back as the tail).
func FormatModelPricingLabel ¶
func FormatModelPricingLabel(pricingService PricingService, model string) string
FormatModelPricingLabel builds a human-readable pricing/availability label for a model, combining the per-token price with a subscription marker. A subscription model has no per-token price ($0/$0 → "free"), which would be misleading, so the bare "free" token is replaced by "subscription". A model that is both priced and subscription-gated keeps its price and gains the marker. Returns "" when there is nothing to show (pricing disabled, no entry, and not subscription-gated).
func NewToolCallEntries ¶ added in v0.182.0
func NewToolCallEntries(toolCall sdk.ChatCompletionMessageToolCall, result *agentdomain.ToolExecutionResult, content string, now time.Time) (ConversationEntry, ConversationEntry)
NewToolCallEntries builds the assistant tool_call entry and its paired tool result entry for a single directly-executed tool call, as persisted by the TUI direct-exec path and the browser extension bridge. content is what the LLM sees as the tool result on later turns.
func ParseChannelSessionID ¶
ParseChannelSessionID extracts the channel name and recipient ID from a session ID created by the daemon's channel manager. The channel manager builds session IDs as "channel-<name>-<sender_id>" (see channel_manager.go).
Returns ok=false when the session ID does not match this format (e.g. for chat-mode or generic agent sessions). Channel names cannot contain a '-'; recipient IDs may.
Types ¶
type ConversationEntry ¶
type ConversationEntry struct {
// Core message fields
Message sdk.Message `json:"message"`
Model string `json:"model,omitempty"`
Time time.Time `json:"time"`
Hidden bool `json:"hidden,omitempty"`
Images []agentdomain.ImageAttachment `json:"images,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
// Tool-related fields
ToolExecution *agentdomain.ToolExecutionResult `json:"tool_execution,omitempty"`
PendingToolCall *sdk.ChatCompletionMessageToolCall `json:"pending_tool_call,omitempty"`
ToolApprovalStatus ToolApprovalStatus `json:"tool_approval_status,omitempty"`
// Plan mode fields
Rejected bool `json:"rejected,omitempty"`
IsPlan bool `json:"is_plan,omitempty"`
PlanApprovalStatus PlanApprovalStatus `json:"plan_approval_status,omitempty"`
}
ConversationEntry represents a message in the conversation with metadata
type ConversationMetadata ¶
type ConversationMetadata struct {
ID string `json:"id"`
Title string `json:"title"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MessageCount int `json:"message_count"`
TokenStats SessionTokenStats `json:"token_stats"`
CostStats SessionCostStats `json:"cost_stats,omitempty"`
Model string `json:"model,omitempty"`
Tags []string `json:"tags,omitempty"`
TitleGenerated bool `json:"title_generated,omitempty"`
TitleInvalidated bool `json:"title_invalidated,omitempty"`
TitleGenerationTime *time.Time `json:"title_generation_time,omitempty"`
ContextID string `json:"context_id,omitempty"`
// ParentSessionID is the orchestrator session that spawned this one
// (e.g. a subagent's parent). Empty for top-level sessions.
ParentSessionID string `json:"parent_session_id"`
// InvokedBy indicates who started the session: "human" or "agent".
// Defaults to "human" for sessions with no explicit invoker.
InvokedBy string `json:"invoked_by"`
}
ConversationMetadata contains metadata about a conversation
type ConversationOptimizer ¶
type ConversationOptimizer interface {
OptimizeMessages(messages []sdk.Message, model string, force bool) []sdk.Message
}
ConversationOptimizer optimizes conversation history to reduce token usage
type ConversationRepository ¶
type ConversationRepository interface {
AddMessage(msg ConversationEntry) error
GetMessages() []ConversationEntry
Clear() error
ClearExceptFirstUserMessage() error
GetMessageCount() int
UpdateLastMessage(content string) error
UpdateLastMessageToolCalls(toolCalls *[]sdk.ChatCompletionMessageToolCall) error
DeleteMessagesAfterIndex(index int) error
AddTokenUsage(model string, inputTokens, outputTokens, totalTokens, cachedTokens, cacheWriteTokens int) error
AddCachedTokens(tokens int)
GetSessionTokens() SessionTokenStats
GetSessionCostStats() SessionCostStats
FormatToolResultForLLM(result *agentdomain.ToolExecutionResult) string
FormatToolResultForUI(result *agentdomain.ToolExecutionResult, terminalWidth int) string
FormatToolResultExpanded(result *agentdomain.ToolExecutionResult, terminalWidth int) string
RemovePendingToolCallByID(toolCallID string)
StartNewConversation(title string) error
LoadConversation(ctx context.Context, conversationID string) error
GetCurrentConversationTitle() string
GetCurrentConversationID() string
Export(format ExportFormat) ([]byte, error)
}
ConversationRepository is the composed interface for all conversation storage and retrieval operations. New code should depend on the narrower sub-interfaces above.
type ConversationSummary ¶
type ConversationSummary struct {
ID string `json:"id"`
Title string `json:"title"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MessageCount int `json:"message_count"`
TokenStats SessionTokenStats `json:"token_stats"`
CostStats SessionCostStats `json:"cost_stats,omitempty"`
Model string `json:"model,omitempty"`
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
TitleGenerated bool `json:"title_generated,omitempty"`
TitleInvalidated bool `json:"title_invalidated,omitempty"`
TitleGenerationTime *time.Time `json:"title_generation_time,omitempty"`
// ParentSessionID is the orchestrator session that spawned this one.
ParentSessionID string `json:"parent_session_id"`
// InvokedBy indicates who started the session: "human" or "agent".
InvokedBy string `json:"invoked_by"`
}
ConversationSummary contains summary information about a conversation
type ExportFormat ¶
type ExportFormat string
ExportFormat defines the format for exporting conversations
const ( ExportMarkdown ExportFormat = "markdown" ExportJSON ExportFormat = "json" ExportText ExportFormat = "text" )
type MessageQueue ¶
type MessageQueue interface {
// Enqueue adds a message to the queue
Enqueue(message sdk.Message, requestID string)
// Dequeue removes and returns the next message from the queue
// Returns nil if the queue is empty
Dequeue() *QueuedMessage
// Peek returns the next message without removing it
// Returns nil if the queue is empty
Peek() *QueuedMessage
// Size returns the number of messages in the queue
Size() int
// IsEmpty returns true if the queue has no messages
IsEmpty() bool
// Clear removes all messages from the queue
Clear()
// GetAll returns all messages in the queue without removing them
GetAll() []QueuedMessage
}
MessageQueue handles centralized message queuing for all components
type ModelCostStats ¶
type ModelCostStats struct {
Model string
InputTokens int
OutputTokens int
InputCost float64
OutputCost float64
TotalCost float64
RequestCount int
}
ModelCostStats tracks cost statistics for a specific model within a session. This allows detailed breakdown when multiple models are used in the same conversation.
type ModelService ¶
type ModelService interface {
ListModels(ctx context.Context) ([]string, error)
SelectModel(modelID string) error
GetCurrentModel() string
IsModelAvailable(modelID string) bool
ValidateModel(modelID string) error
}
ModelService handles model selection and information
type PlanApprovalStatus ¶
type PlanApprovalStatus int
PlanApprovalStatus represents the approval status of a plan
const ( PlanApprovalPending PlanApprovalStatus = iota PlanApprovalAccepted PlanApprovalRejected )
type PricingService ¶
type PricingService interface {
// IsEnabled returns whether pricing is enabled in the configuration.
IsEnabled() bool
// GetInputPrice retrieves the input price per million tokens for a specific model.
// Returns 0.0 for unknown models (e.g., Ollama, custom models).
GetInputPrice(model string) float64
// GetOutputPrice retrieves the output price per million tokens for a specific model.
// Returns 0.0 for unknown models (e.g., Ollama, custom models).
GetOutputPrice(model string) float64
// CalculateCost computes the total cost for a given number of input and
// output tokens. cachedTokens and cacheWriteTokens are the cache-read and
// cache-creation subsets of inputTokens, billed at the gateway's
// cache-read/cache-write rates when known (full input rate otherwise).
CalculateCost(model string, inputTokens, outputTokens, cachedTokens, cacheWriteTokens int) (inputCost, outputCost, totalCost float64)
// RequiresPro reports whether the model is gated behind a paid Pro
// subscription (e.g. some Ollama Cloud models). Resolves custom prices
// first, then defaults. Returns false when pricing is disabled or the
// model has no entry.
RequiresPro(model string) bool
// FormatModelPricing returns a formatted string describing the model's pricing.
// Returns empty string if pricing is disabled or the model has no pricing entry.
// Returns "free" only when an explicit pricing entry sets both prices to 0.0.
// Returns "$X.XX/$Y.YY per MTok" for paid models.
FormatModelPricing(model string) string
}
PricingService provides pricing information and cost calculation for different models. Note: This interface returns float64 for pricing to avoid import cycles. The actual ModelPricing struct is defined in the config package.
type QueuedMessage ¶
QueuedMessage represents a message in the input queue
type SessionCostStats ¶
type SessionCostStats struct {
TotalCost float64
TotalInputCost float64
TotalOutputCost float64
PerModelStats map[string]*ModelCostStats
Currency string
}
SessionCostStats aggregates cost information for an entire session. It provides both total costs and per-model breakdowns.
type SessionID ¶
type SessionID string
SessionID represents a unique identifier for a chat session. Format: {unix-timestamp}-{8-char-random-hex} Example: 1733678400-a3f2bc8d
func GenerateSessionID ¶
func GenerateSessionID() SessionID
GenerateSessionID creates a new unique session identifier. The ID combines a Unix timestamp (for temporal uniqueness) with random hex characters (for collision resistance).
func (SessionID) Age ¶
Age returns the duration since the session was created. Returns 0 if the session ID format is invalid.
type SessionTokenStats ¶
type SessionTokenStats struct {
TotalInputTokens int `json:"total_input_tokens"`
TotalOutputTokens int `json:"total_output_tokens"`
TotalTokens int `json:"total_tokens"`
RequestCount int `json:"request_count"`
LastInputTokens int `json:"last_input_tokens"`
TotalCachedTokens int `json:"total_cached_tokens"`
TotalCacheWriteTokens int `json:"total_cache_write_tokens"`
}
SessionTokenStats tracks accumulated token usage across a session
type TokenEstimator ¶
type TokenEstimator interface {
// GetToolStats returns token count and tool count for a given agent mode
GetToolStats(toolService agentdomain.ToolService, agentMode agentdomain.AgentMode) (tokens int, count int)
// EstimateMessagesTokens estimates the total tokens for a slice of messages
EstimateMessagesTokens(messages []sdk.Message) int
// EffectiveContextTokens estimates what the *next* request will carry: the
// larger of the gateway-reported last-request size and a fresh estimate of
// the current buffer. The max catches a single-turn tool-output spike that a
// stale lastInputTokens alone would miss.
EffectiveContextTokens(lastInputTokens int, messages []sdk.Message) int
}
TokenEstimator provides token count estimation for LLM content
type ToolApprovalStatus ¶
type ToolApprovalStatus int
ToolApprovalStatus represents the approval status of a tool
const ( ToolApprovalPending ToolApprovalStatus = iota ToolApprovalApproved ToolApprovalRejected )