config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelTierStrong = "strong"
	ModelTierFast   = "fast"
)

Model tier constants.

Variables

This section is empty.

Functions

func AnnaHome

func AnnaHome() string

AnnaHome returns the anna home directory. Priority: ANNA_HOME env -> ~/.anna The result is cached after the first call.

func CachePath

func CachePath() string

CachePath returns the cache directory inside the anna home.

func DBPath added in v0.8.0

func DBPath() string

DBPath returns the default database path inside the anna home.

func ModelConfigToAI added in v0.8.0

func ModelConfigToAI(provider string, m ModelConfig) ai.Model

ModelConfigToAI converts a ModelConfig to an ai.Model.

func ParseModelRef added in v0.8.0

func ParseModelRef(ref string) (provider, model string)

ParseModelRef splits a "provider/model" string into its parts. If the string contains no "/", it returns ("", ref) as fallback.

func ResetAnnaHome

func ResetAnnaHome()

ResetAnnaHome clears the cached AnnaHome value (for testing).

Types

type Agent added in v0.8.0

type Agent struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Model        string `json:"model"`
	ModelStrong  string `json:"model_strong"`
	ModelFast    string `json:"model_fast"`
	SystemPrompt string `json:"system_prompt"`
	Workspace    string `json:"workspace"`
	Enabled      bool   `json:"enabled"`
}

Agent represents an agent definition. Model fields use {provider}/{model} format (e.g. "anthropic/claude-sonnet-4-6").

type Channel added in v0.8.0

type Channel struct {
	ID      string `json:"id"`
	Enabled bool   `json:"enabled"`
	Config  string `json:"config"`
}

Channel represents a platform channel configuration.

type CompactionConfig

type CompactionConfig struct {
	// MaxTokens triggers compaction when the estimated token count exceeds this.
	// 0 (or omitted) uses the default of 80000. Negative values disable
	// automatic compaction. Manual /compact still works.
	MaxTokens int `json:"max_tokens"`
	// KeepTail is the number of recent message entries to preserve verbatim
	// after compaction. Default: 20.
	KeepTail int `json:"keep_tail"`
}

CompactionConfig controls automatic session compaction.

type DBStore added in v0.8.0

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

DBStore implements Store using sqlc queries backed by SQLite.

func NewDBStore added in v0.8.0

func NewDBStore(db *sql.DB) *DBStore

NewDBStore creates a new DBStore wrapping the given database connection. It sets MaxOpenConns(1) to mitigate SQLite concurrency issues.

func (*DBStore) CreateAgent added in v0.8.0

func (s *DBStore) CreateAgent(ctx context.Context, a Agent) error

func (*DBStore) CreateProvider added in v0.8.0

func (s *DBStore) CreateProvider(ctx context.Context, p Provider) error

func (*DBStore) DeleteAgent added in v0.8.0

func (s *DBStore) DeleteAgent(ctx context.Context, id string) error

func (*DBStore) DeleteChatAgent added in v0.8.0

func (s *DBStore) DeleteChatAgent(ctx context.Context, platform, chatID string) error

func (*DBStore) DeleteProvider added in v0.8.0

func (s *DBStore) DeleteProvider(ctx context.Context, id string) error

func (*DBStore) DeleteUserAgentMemory added in v0.8.0

func (s *DBStore) DeleteUserAgentMemory(ctx context.Context, userID int64, agentID string) error

func (*DBStore) GetAgent added in v0.8.0

func (s *DBStore) GetAgent(ctx context.Context, id string) (Agent, error)

func (*DBStore) GetChannel added in v0.8.0

func (s *DBStore) GetChannel(ctx context.Context, id string) (Channel, error)

func (*DBStore) GetChatAgent added in v0.8.0

func (s *DBStore) GetChatAgent(ctx context.Context, platform, chatID string) (string, error)

func (*DBStore) GetProvider added in v0.8.0

func (s *DBStore) GetProvider(ctx context.Context, id string) (Provider, error)

func (*DBStore) GetSetting added in v0.8.0

func (s *DBStore) GetSetting(ctx context.Context, key string) (string, error)

func (*DBStore) GetUser added in v0.8.0

func (s *DBStore) GetUser(ctx context.Context, id int64) (User, error)

func (*DBStore) GetUserAgentMemory added in v0.8.0

func (s *DBStore) GetUserAgentMemory(ctx context.Context, userID int64, agentID string) (string, error)

func (*DBStore) ListAgents added in v0.8.0

func (s *DBStore) ListAgents(ctx context.Context) ([]Agent, error)

func (*DBStore) ListChannels added in v0.8.0

func (s *DBStore) ListChannels(ctx context.Context) ([]Channel, error)

func (*DBStore) ListEnabledAgents added in v0.8.0

func (s *DBStore) ListEnabledAgents(ctx context.Context) ([]Agent, error)

func (*DBStore) ListProviders added in v0.8.0

func (s *DBStore) ListProviders(ctx context.Context) ([]Provider, error)

func (*DBStore) ListUserMemories added in v0.8.0

func (s *DBStore) ListUserMemories(ctx context.Context, userID int64) ([]UserAgentMemory, error)

func (*DBStore) ListUsers added in v0.8.0

func (s *DBStore) ListUsers(ctx context.Context) ([]User, error)

func (*DBStore) SeedDefaults added in v0.8.0

func (s *DBStore) SeedDefaults(ctx context.Context) error

SeedDefaults populates the DB with sensible defaults on first bootstrap. It is idempotent: if providers/agents already exist, it does nothing.

func (*DBStore) SetChatAgent added in v0.8.0

func (s *DBStore) SetChatAgent(ctx context.Context, platform, chatID, agentID string) error

func (*DBStore) SetSetting added in v0.8.0

func (s *DBStore) SetSetting(ctx context.Context, key, value string) error

func (*DBStore) SetUserAgentMemory added in v0.8.0

func (s *DBStore) SetUserAgentMemory(ctx context.Context, userID int64, agentID, content string) error

func (*DBStore) Snapshot added in v0.8.0

func (s *DBStore) Snapshot(ctx context.Context, agentID string) (*Snapshot, error)

func (*DBStore) UpdateAgent added in v0.8.0

func (s *DBStore) UpdateAgent(ctx context.Context, a Agent) error

func (*DBStore) UpdateProvider added in v0.8.0

func (s *DBStore) UpdateProvider(ctx context.Context, p Provider) error

func (*DBStore) UpdateUserDefaultAgent added in v0.8.0

func (s *DBStore) UpdateUserDefaultAgent(ctx context.Context, userID int64, agentID string) error

func (*DBStore) UpsertChannel added in v0.8.0

func (s *DBStore) UpsertChannel(ctx context.Context, ch Channel) error

func (*DBStore) UpsertUser added in v0.8.0

func (s *DBStore) UpsertUser(ctx context.Context, externalID, platform, name string) (User, error)

type HeartbeatConfig

type HeartbeatConfig struct {
	Enabled *bool  `json:"enabled"`
	Every   string `json:"every"`
	File    string `json:"file"`
}

HeartbeatConfig configures periodic heartbeat checks.

func (HeartbeatConfig) FilePath

func (c HeartbeatConfig) FilePath(workspace string) string

FilePath resolves the configured heartbeat file relative to the workspace.

func (HeartbeatConfig) Interval

func (c HeartbeatConfig) Interval() string

Interval returns the configured heartbeat cadence.

func (HeartbeatConfig) IsEnabled

func (c HeartbeatConfig) IsEnabled() bool

IsEnabled returns whether heartbeat is enabled (defaults to false).

type ModelConfig

type ModelConfig struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	API           string            `json:"api"`
	Reasoning     bool              `json:"reasoning"`
	Input         []string          `json:"input"`
	ContextWindow int               `json:"context_window"`
	MaxTokens     int               `json:"max_tokens"`
	Headers       map[string]string `json:"headers"`
	Cost          *ModelCostConfig  `json:"cost"`
}

ModelConfig describes a model's metadata (used in model listing/caching).

type ModelCostConfig

type ModelCostConfig struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cache_read"`
	CacheWrite float64 `json:"cache_write"`
}

ModelCostConfig describes the cost of a model per million tokens.

type PluginConfig added in v0.7.0

type PluginConfig struct {
	Path   string         `json:"path"`
	Config map[string]any `json:"config"`
}

PluginConfig describes a single plugin entry.

type Provider added in v0.8.0

type Provider struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	APIKey  string `json:"api_key"`
	BaseURL string `json:"base_url"`
}

Provider represents an LLM API provider.

type ProviderCreds added in v0.8.0

type ProviderCreds struct {
	APIKey  string
	BaseURL string
}

ProviderCreds holds credentials for a single provider.

type RunnerConfig

type RunnerConfig struct {
	Type        string           `json:"type"`
	System      string           `json:"system"`
	IdleTimeout int              `json:"idle_timeout"`
	Compaction  CompactionConfig `json:"compaction"`
}

RunnerConfig configures the agent runner.

type SchedulerConfig added in v0.6.2

type SchedulerConfig struct {
	Enabled *bool  `json:"enabled"`
	DataDir string `json:"data_dir"`
}

SchedulerConfig configures the scheduler subsystem.

func (SchedulerConfig) IsEnabled added in v0.6.2

func (c SchedulerConfig) IsEnabled() bool

IsEnabled returns whether the scheduler is enabled (defaults to true).

type Snapshot added in v0.8.0

type Snapshot struct {
	// Provider, APIKey, BaseURL are the default provider credentials derived
	// from the Model field's provider prefix. Kept for backward compatibility.
	Provider     string
	Model        string
	ModelStrong  string
	ModelFast    string
	Workspace    string
	APIKey       string
	BaseURL      string
	SystemPrompt string // agent's soul/personality from DB
	Runner       RunnerConfig
	Compaction   CompactionConfig
	Heartbeat    HeartbeatConfig
	Scheduler    SchedulerConfig
	Plugins      []PluginConfig

	// Providers maps provider ID to credentials, enabling per-tier provider
	// resolution when model_strong or model_fast use a different provider.
	Providers map[string]ProviderCreds
}

Snapshot is a read-only config snapshot assembled from DB for downstream consumption. It replaces the old *Config for code that needs provider/model information for a specific agent.

func (*Snapshot) LogPath added in v0.8.0

func (s *Snapshot) LogPath() string

LogPath returns the log file path inside the workspace.

func (*Snapshot) ResolveModel added in v0.8.0

func (s *Snapshot) ResolveModel() ai.Model

ResolveModel returns the ai.Model for the default (strong) tier.

func (*Snapshot) ResolveModelID added in v0.8.0

func (s *Snapshot) ResolveModelID(tier string) string

ResolveModelID returns the model ID string for the given tier, falling back to Model if the tier-specific value is not set.

func (*Snapshot) ResolveModelTier added in v0.8.0

func (s *Snapshot) ResolveModelTier(tier string) ai.Model

ResolveModelTier returns the ai.Model for the given tier, constructing a minimal Model from the snapshot's provider and model information. It parses the provider from the model ref and looks up per-provider credentials from the Providers map.

func (*Snapshot) ResolveProviderCreds added in v0.8.0

func (s *Snapshot) ResolveProviderCreds(providerID string) ProviderCreds

ResolveProviderCreds returns the API key and base URL for the given provider ID, falling back to the default Provider credentials.

func (*Snapshot) SkillsPath added in v0.8.0

func (s *Snapshot) SkillsPath() string

SkillsPath returns the skills directory inside the workspace.

type Store added in v0.8.0

type Store interface {
	// Providers
	ListProviders(ctx context.Context) ([]Provider, error)
	GetProvider(ctx context.Context, id string) (Provider, error)
	CreateProvider(ctx context.Context, p Provider) error
	UpdateProvider(ctx context.Context, p Provider) error
	DeleteProvider(ctx context.Context, id string) error

	// Agents
	ListAgents(ctx context.Context) ([]Agent, error)
	ListEnabledAgents(ctx context.Context) ([]Agent, error)
	GetAgent(ctx context.Context, id string) (Agent, error)
	CreateAgent(ctx context.Context, a Agent) error
	UpdateAgent(ctx context.Context, a Agent) error
	DeleteAgent(ctx context.Context, id string) error

	// Channels
	ListChannels(ctx context.Context) ([]Channel, error)
	GetChannel(ctx context.Context, id string) (Channel, error)
	UpsertChannel(ctx context.Context, ch Channel) error

	// Users
	ListUsers(ctx context.Context) ([]User, error)
	GetUser(ctx context.Context, id int64) (User, error)
	UpsertUser(ctx context.Context, externalID, platform, name string) (User, error)
	UpdateUserDefaultAgent(ctx context.Context, userID int64, agentID string) error

	// Chat Agents (group -> agent mapping)
	GetChatAgent(ctx context.Context, platform, chatID string) (string, error) // returns agentID
	SetChatAgent(ctx context.Context, platform, chatID, agentID string) error
	DeleteChatAgent(ctx context.Context, platform, chatID string) error

	// User Agent Memory
	GetUserAgentMemory(ctx context.Context, userID int64, agentID string) (string, error)
	SetUserAgentMemory(ctx context.Context, userID int64, agentID, content string) error
	ListUserMemories(ctx context.Context, userID int64) ([]UserAgentMemory, error)
	DeleteUserAgentMemory(ctx context.Context, userID int64, agentID string) error

	// Settings (key-value JSON)
	GetSetting(ctx context.Context, key string) (string, error) // returns JSON string
	SetSetting(ctx context.Context, key, value string) error

	// Snapshot assembles a read-only config snapshot for an agent.
	Snapshot(ctx context.Context, agentID string) (*Snapshot, error)

	// Bootstrap
	SeedDefaults(ctx context.Context) error
}

Store provides typed access to configuration stored in the database.

type User added in v0.8.0

type User struct {
	ID             int64  `json:"id"`
	ExternalID     string `json:"external_id"`
	Platform       string `json:"platform"`
	Name           string `json:"name"`
	DefaultAgentID string `json:"default_agent_id"`
}

User represents a platform user.

type UserAgentMemory added in v0.8.0

type UserAgentMemory struct {
	UserID    int64  `json:"user_id"`
	AgentID   string `json:"agent_id"`
	Content   string `json:"content"`
	UpdatedAt string `json:"updated_at"`
}

UserAgentMemory represents a stored memory entry for a user-agent pair.

Jump to

Keyboard shortcuts

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