Documentation
¶
Index ¶
- Constants
- Variables
- type InMemorySessionStore
- func (s *InMemorySessionStore) AddSession(_ context.Context, session *Session) error
- func (s *InMemorySessionStore) DeleteSession(_ context.Context, id string) error
- func (s *InMemorySessionStore) GetSession(_ context.Context, id string) (*Session, error)
- func (s *InMemorySessionStore) GetSessionSummaries(_ context.Context) ([]Summary, error)
- func (s *InMemorySessionStore) GetSessions(_ context.Context) ([]*Session, error)
- func (s *InMemorySessionStore) SetSessionStarred(_ context.Context, id string, starred bool) error
- func (s *InMemorySessionStore) UpdateSession(_ context.Context, session *Session) error
- type Item
- type Message
- type MessageUsageRecord
- type Migration
- type MigrationManager
- type Opt
- func WithHideToolResults(hideToolResults bool) Opt
- func WithImplicitUserMessage(content string) Opt
- func WithMaxIterations(maxIterations int) Opt
- func WithParentID(parentID string) Opt
- func WithPermissions(perms *PermissionsConfig) Opt
- func WithSendUserMessage(sendUserMessage bool) Opt
- func WithSystemMessage(content string) Opt
- func WithThinking(thinking bool) Opt
- func WithTitle(title string) Opt
- func WithToolsApproved(toolsApproved bool) Opt
- func WithUserMessage(content string) Opt
- func WithWorkingDir(workingDir string) Opt
- type PermissionsConfig
- type SQLiteSessionStore
- func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) error
- func (s *SQLiteSessionStore) Close() error
- func (s *SQLiteSessionStore) DeleteSession(ctx context.Context, id string) error
- func (s *SQLiteSessionStore) GetSession(ctx context.Context, id string) (*Session, error)
- func (s *SQLiteSessionStore) GetSessionSummaries(ctx context.Context) ([]Summary, error)
- func (s *SQLiteSessionStore) GetSessions(ctx context.Context) ([]*Session, error)
- func (s *SQLiteSessionStore) SetSessionStarred(ctx context.Context, id string, starred bool) error
- func (s *SQLiteSessionStore) UpdateSession(ctx context.Context, session *Session) error
- type Session
- func (s *Session) AddMessage(msg *Message)
- func (s *Session) AddMessageUsageRecord(agentName, model string, cost float64, usage *chat.Usage)
- func (s *Session) AddSubSession(subSession *Session)
- func (s *Session) AllowedDirectories() []string
- func (s *Session) Duration() time.Duration
- func (s *Session) GetAllMessages() []Message
- func (s *Session) GetLastAssistantMessageContent() string
- func (s *Session) GetLastUserMessageContent() string
- func (s *Session) GetMessages(a *agent.Agent) []chat.Message
- func (s *Session) IsSubSession() bool
- func (s *Session) UpdateLastAssistantMessageUsage(usage *chat.Usage, cost float64, model string)
- type Store
- type Summary
Constants ¶
const ( // MaxToolCallTokens is the maximum number of tokens to keep from tool call // arguments and results. Older tool calls beyond this budget will have their // content replaced with a placeholder. Tokens are approximated as len/4. MaxToolCallTokens = 40000 )
Variables ¶
var ( ErrEmptyID = errors.New("session ID cannot be empty") ErrNotFound = errors.New("session not found") )
Functions ¶
This section is empty.
Types ¶
type InMemorySessionStore ¶ added in v1.8.2
type InMemorySessionStore struct {
// contains filtered or unexported fields
}
func (*InMemorySessionStore) AddSession ¶ added in v1.8.2
func (s *InMemorySessionStore) AddSession(_ context.Context, session *Session) error
func (*InMemorySessionStore) DeleteSession ¶ added in v1.8.2
func (s *InMemorySessionStore) DeleteSession(_ context.Context, id string) error
func (*InMemorySessionStore) GetSession ¶ added in v1.8.2
func (*InMemorySessionStore) GetSessionSummaries ¶ added in v1.8.2
func (s *InMemorySessionStore) GetSessionSummaries(_ context.Context) ([]Summary, error)
func (*InMemorySessionStore) GetSessions ¶ added in v1.8.2
func (s *InMemorySessionStore) GetSessions(_ context.Context) ([]*Session, error)
func (*InMemorySessionStore) SetSessionStarred ¶ added in v1.18.4
SetSessionStarred sets the starred status of a session.
func (*InMemorySessionStore) UpdateSession ¶ added in v1.8.2
func (s *InMemorySessionStore) UpdateSession(_ context.Context, session *Session) error
UpdateSession updates an existing session, or creates it if it doesn't exist (upsert). This enables lazy session persistence - sessions are only stored when they have content.
type Item ¶
type Item struct {
// Message holds a regular conversation message
Message *Message `json:"message,omitempty"`
// SubSession holds a complete sub-session from task transfers
SubSession *Session `json:"sub_session,omitempty"`
// Summary is a summary of the session up until this point
Summary string `json:"summary,omitempty"`
}
Item represents either a message or a sub-session
func NewMessageItem ¶
NewMessageItem creates a SessionItem containing a message
func NewSubSessionItem ¶
NewSubSessionItem creates a SessionItem containing a sub-session
func (*Item) IsSubSession ¶
IsSubSession returns true if this item contains a sub-session
type Message ¶
type Message struct {
AgentName string `json:"agentName"` // TODO: rename to agent_name
Message chat.Message `json:"message"`
// Implicit is an optional field to indicate if the message shouldn't be shown to the user. It's needed for special situations
// like when an agent transfers a task to another agent - new session is created with a default user message, but this shouldn't be shown to the user.
// Such messages should be marked as true
Implicit bool `json:"implicit,omitempty"`
}
Message is a message from an agent
func ImplicitUserMessage ¶ added in v1.6.3
func SystemMessage ¶
func UserMessage ¶
func UserMessage(content string, multiContent ...chat.MessagePart) *Message
type MessageUsageRecord ¶ added in v1.19.3
type MessageUsageRecord struct {
AgentName string `json:"agent_name"`
Model string `json:"model"`
Cost float64 `json:"cost"`
Usage chat.Usage `json:"usage"`
}
MessageUsageRecord stores usage data for a single assistant message. Used in remote mode where messages aren't stored in the client-side session.
type Migration ¶
type Migration struct {
ID int
Name string
Description string
UpSQL string
DownSQL string
AppliedAt time.Time
}
Migration represents a database migration
type MigrationManager ¶
type MigrationManager struct {
// contains filtered or unexported fields
}
MigrationManager handles database migrations
func NewMigrationManager ¶
func NewMigrationManager(db *sql.DB) *MigrationManager
NewMigrationManager creates a new migration manager
func (*MigrationManager) GetAppliedMigrations ¶
func (m *MigrationManager) GetAppliedMigrations(ctx context.Context) ([]Migration, error)
GetAppliedMigrations returns a list of applied migrations
func (*MigrationManager) InitializeMigrations ¶
func (m *MigrationManager) InitializeMigrations(ctx context.Context) error
InitializeMigrations sets up the migrations table and runs pending migrations
func (*MigrationManager) RunPendingMigrations ¶
func (m *MigrationManager) RunPendingMigrations(ctx context.Context) error
RunPendingMigrations executes all migrations that haven't been applied yet
type Opt ¶
type Opt func(s *Session)
func WithHideToolResults ¶ added in v1.8.2
func WithImplicitUserMessage ¶ added in v1.6.3
func WithMaxIterations ¶ added in v1.3.5
func WithParentID ¶ added in v1.19.2
WithParentID marks this session as a sub-session of the given parent. Sub-sessions are not persisted as standalone entries in the session store.
func WithPermissions ¶ added in v1.18.8
func WithPermissions(perms *PermissionsConfig) Opt
func WithSendUserMessage ¶ added in v1.8.2
func WithSystemMessage ¶
func WithThinking ¶ added in v1.19.3
func WithToolsApproved ¶ added in v1.8.2
func WithUserMessage ¶
func WithWorkingDir ¶ added in v1.5.14
type PermissionsConfig ¶ added in v1.18.8
type PermissionsConfig struct {
// Allow lists tool name patterns that are auto-approved without user confirmation.
Allow []string `json:"allow,omitempty"`
// Deny lists tool name patterns that are always rejected.
Deny []string `json:"deny,omitempty"`
}
PermissionsConfig defines session-level tool permission overrides using pattern-based rules (Allow/Deny arrays).
type SQLiteSessionStore ¶
type SQLiteSessionStore struct {
// contains filtered or unexported fields
}
SQLiteSessionStore implements Store using SQLite
func (*SQLiteSessionStore) AddSession ¶
func (s *SQLiteSessionStore) AddSession(ctx context.Context, session *Session) error
AddSession adds a new session to the store
func (*SQLiteSessionStore) Close ¶
func (s *SQLiteSessionStore) Close() error
Close closes the database connection
func (*SQLiteSessionStore) DeleteSession ¶
func (s *SQLiteSessionStore) DeleteSession(ctx context.Context, id string) error
DeleteSession deletes a session by ID
func (*SQLiteSessionStore) GetSession ¶
GetSession retrieves a session by ID
func (*SQLiteSessionStore) GetSessionSummaries ¶ added in v1.8.2
func (s *SQLiteSessionStore) GetSessionSummaries(ctx context.Context) ([]Summary, error)
GetSessionSummaries retrieves lightweight session metadata for listing. This is much faster than GetSessions as it doesn't load message content.
func (*SQLiteSessionStore) GetSessions ¶
func (s *SQLiteSessionStore) GetSessions(ctx context.Context) ([]*Session, error)
GetSessions retrieves all sessions
func (*SQLiteSessionStore) SetSessionStarred ¶ added in v1.18.4
SetSessionStarred sets the starred status of a session.
func (*SQLiteSessionStore) UpdateSession ¶
func (s *SQLiteSessionStore) UpdateSession(ctx context.Context, session *Session) error
UpdateSession updates an existing session, or creates it if it doesn't exist (upsert). This enables lazy session persistence - sessions are only stored when they have content.
type Session ¶
type Session struct {
// ID is the unique identifier for the session
ID string `json:"id"`
// Title is the title of the session, set by the runtime
Title string `json:"title"`
// Messages holds the conversation history (messages and sub-sessions)
Messages []Item `json:"messages"`
// CreatedAt is the time the session was created
CreatedAt time.Time `json:"created_at"`
// ToolsApproved is a flag to indicate if the tools have been approved
ToolsApproved bool `json:"tools_approved"`
// Thinking is a session-level flag to enable thinking/interleaved thinking
// defaults for all providers. When false, providers will not apply auto-thinking budgets
// or interleaved thinking, regardless of model config. This is controlled by the /think
// command in the TUI. Defaults to true (thinking enabled).
Thinking bool `json:"thinking"`
// HideToolResults is a flag to indicate if tool results should be hidden
HideToolResults bool `json:"hide_tool_results"`
// WorkingDir is the base directory used for filesystem-aware tools
WorkingDir string `json:"working_dir,omitempty"`
// SendUserMessage is a flag to indicate if the user message should be sent
SendUserMessage bool
// MaxIterations is the maximum number of agentic loop iterations to prevent infinite loops
// If 0, there is no limit
MaxIterations int `json:"max_iterations"`
// Starred indicates if this session has been starred by the user
Starred bool `json:"starred"`
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
Cost float64 `json:"cost"`
// Permissions holds session-level permission overrides.
// When set, these are evaluated before team-level permissions.
Permissions *PermissionsConfig `json:"permissions,omitempty"`
// AgentModelOverrides stores per-agent model overrides for this session.
// Key is the agent name, value is the model reference (e.g., "openai/gpt-4o" or a named model from config).
// When a session is loaded, these overrides are reapplied to the runtime.
AgentModelOverrides map[string]string `json:"agent_model_overrides,omitempty"`
// CustomModelsUsed tracks custom models (provider/model format) used during this session.
// These are shown in the model picker for easy re-selection.
CustomModelsUsed []string `json:"custom_models_used,omitempty"`
// ParentID indicates this is a sub-session created by task transfer.
// Sub-sessions are not persisted as standalone entries; they are embedded
// within the parent session's Messages array.
ParentID string `json:"-"`
// MessageUsageHistory stores per-message usage data for remote mode.
// In remote mode, messages are managed server-side, so we track usage separately.
// This is not persisted (json:"-") as it's only needed for the current session display.
MessageUsageHistory []MessageUsageRecord `json:"-"`
}
Session represents the agent's state including conversation history and variables
func (*Session) AddMessage ¶
AddMessage adds a message to the session
func (*Session) AddMessageUsageRecord ¶ added in v1.19.3
AddMessageUsageRecord appends a usage record for remote mode where messages aren't stored locally. This enables the /cost dialog to show per-message breakdown even when using a remote runtime.
func (*Session) AddSubSession ¶
AddSubSession adds a sub-session to the session
func (*Session) AllowedDirectories ¶ added in v1.5.14
AllowedDirectories returns the directories that should be considered safe for tools
func (*Session) Duration ¶ added in v1.19.0
Duration calculates the duration of the session from message timestamps.
func (*Session) GetAllMessages ¶
GetAllMessages extracts all messages from the session, including from sub-sessions
func (*Session) GetLastAssistantMessageContent ¶
func (*Session) GetLastUserMessageContent ¶ added in v1.8.2
func (*Session) IsSubSession ¶ added in v1.19.2
IsSubSession returns true if this session is a sub-session (has a parent).
func (*Session) UpdateLastAssistantMessageUsage ¶ added in v1.19.3
UpdateLastAssistantMessageUsage updates the usage and cost fields of the last assistant message. This is used in remote mode to populate per-message cost data from TokenUsageEvent.
type Store ¶
type Store interface {
AddSession(ctx context.Context, session *Session) error
GetSession(ctx context.Context, id string) (*Session, error)
GetSessions(ctx context.Context) ([]*Session, error)
GetSessionSummaries(ctx context.Context) ([]Summary, error)
DeleteSession(ctx context.Context, id string) error
UpdateSession(ctx context.Context, session *Session) error
SetSessionStarred(ctx context.Context, id string, starred bool) error
}
Store defines the interface for session storage
func NewInMemorySessionStore ¶ added in v1.8.2
func NewInMemorySessionStore() Store
func NewSQLiteSessionStore ¶
NewSQLiteSessionStore creates a new SQLite session store