config

package
v0.260307.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WildcardRuleName    = "*"
	WildcardRuleNameAlt = "[any]"
)

Wildcard rule names that match any model

View Source
const (
	RuleUUIDTingly            = "tingly"
	RuleUUIDBuiltinOpenAI     = "built-in-openai"
	RuleUUIDBuiltinAnthropic  = "built-in-anthropic"
	RuleUUIDBuiltinCC         = "built-in-cc"
	RuleUUIDClaudeCode        = "claude-code"
	RuleUUIDBuiltinCCHaiku    = "built-in-cc-haiku"
	RuleUUIDBuiltinCCSonnet   = "built-in-cc-sonnet"
	RuleUUIDBuiltinCCOpus     = "built-in-cc-opus"
	RuleUUIDBuiltinCCDefault  = "built-in-cc-default"
	RuleUUIDBuiltinCCSubagent = "built-in-cc-subagent"
)

Built-in rule UUID constants

Variables

View Source
var DefaultRules []typ.Rule

Functions

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a new UUID string

func InstallStatusLineScript

func InstallStatusLineScript() (scriptPath string, created bool, err error)

InstallStatusLineScript installs the tingly-statusline.sh script to ~/.claude/ Returns the path to the installed script and whether it was newly created

func IsTacticValid

func IsTacticValid(tactic *typ.Tactic) bool

IsTacticValid checks if the tactic params are valid (not zero values)

func IsWildcardRuleName

func IsWildcardRuleName(name string) bool

IsWildcardRuleName checks if the given rule name is a wildcard that matches any model

func Migrate

func Migrate(c *Config) error

Types

type ApplyResult

type ApplyResult struct {
	Success    bool   `json:"success"`
	BackupPath string `json:"backupPath,omitempty"`
	Message    string `json:"message"`
	Created    bool   `json:"created,omitempty"`
	Updated    bool   `json:"updated,omitempty"`
}

ApplyResult contains the result of applying a configuration

func ApplyClaudeOnboarding

func ApplyClaudeOnboarding(payload map[string]interface{}) (*ApplyResult, error)

ApplyClaudeOnboarding applies Claude onboarding configuration It merges top-level keys, preserving existing keys not in payload

func ApplyClaudeSettingsFromEnv

func ApplyClaudeSettingsFromEnv(env map[string]string, extras ...KV) (*ApplyResult, error)

ApplyClaudeSettingsFromEnv applies Claude settings configuration with env vars This is the safe version - env map is controlled by backend

func ApplyOpenCodeConfig

func ApplyOpenCodeConfig(payload map[string]interface{}) (*ApplyResult, error)

ApplyOpenCodeConfig applies OpenCode configuration It merges the provider map while preserving other providers and settings

type ClaudeSettingsPayload

type ClaudeSettingsPayload struct {
	Env map[string]string `json:"env"`
}

ClaudeSettingsPayload contains the payload for applying Claude settings

type Config

type Config struct {
	Rules             []typ.Rule           `yaml:"rules" json:"rules"`                             // List of request configurations
	DefaultRequestID  int                  `yaml:"default_request_id" json:"default_request_id"`   // Index of the default Rule
	UserToken         string               `yaml:"user_token" json:"user_token"`                   // User token for UI and control API authentication
	ModelToken        string               `yaml:"model_token" json:"model_token"`                 // Model token for OpenAI and Anthropic API authentication
	VirtualModelToken string               `yaml:"virtual_model_token" json:"virtual_model_token"` // Virtual model token for testing (independent from ModelToken)
	EncryptProviders  bool                 `yaml:"encrypt_providers" json:"encrypt_providers"`     // Whether to encrypt provider info (default false)
	Scenarios         []typ.ScenarioConfig `yaml:"scenarios" json:"scenarios"`                     // Scenario-specific configurations
	GUI               GUIConfig            `json:"gui"`                                            // GUI-specific settings
	RemoteCoder       RemoteCoderConfig    `json:"remote_coder"`                                   // Remote-coder service settings

	// Merged fields from Config struct
	ProvidersV1 map[string]*typ.Provider `json:"providers"`
	Providers   []*typ.Provider          `json:"providers_v2,omitempty"`
	ServerPort  int                      `json:"-"`
	JWTSecret   string                   `json:"jwt_secret"`

	// Server settings
	DefaultMaxTokens int  `json:"default_max_tokens"` // Default max_tokens for anthropic API requests
	Verbose          bool `json:"verbose"`            // Verbose mode for detailed logging
	Debug            bool `json:"-"`                  // Debug mode for Gin debug level logging
	OpenBrowser      bool `yaml:"-" json:"-"`         // Auto-open browser in web UI mode (default: true)

	// Generic tool configs map for all tool types
	// Key is tool_type (e.g., "tool_interceptor", "code_execution")
	// Value is the JSON-encoded config for that tool type
	ToolConfigs map[string]json.RawMessage `json:"tool_configs,omitempty"`

	// Error log settings
	ErrorLogFilterExpression string `json:"error_log_filter_expression"` // Expression for filtering error log entries (default: "StatusCode >= 400 && Path matches '^/api/'")

	// Health monitor settings
	HealthMonitor loadbalance.HealthMonitorConfig `json:"health_monitor,omitempty" yaml:"health_monitor,omitempty"`

	ConfigFile string `yaml:"-" json:"-"` // Not serialized to YAML (exported to preserve field)
	ConfigDir  string `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

Config represents the global configuration

func NewConfig

func NewConfig() (*Config, error)

NewConfig creates a new global configuration manager

func NewConfigWithDir

func NewConfigWithDir(configDir string) (*Config, error)

NewConfigWithDir creates a new global configuration manager with a custom config directory

func (*Config) AddOrUpdateRequestConfigByRequestModel

func (c *Config) AddOrUpdateRequestConfigByRequestModel(reqConfig typ.Rule) error

AddOrUpdateRequestConfigByRequestModel adds a new Rule or updates an existing one by request model name

func (*Config) AddProvider

func (c *Config) AddProvider(provider *typ.Provider) error

AddProvider adds a new provider using Provider struct

func (*Config) AddProviderByName

func (c *Config) AddProviderByName(name, apiBase, token string) error

AddProviderByName adds a new AI provider configuration by name, API base, and token

func (*Config) AddRequestConfig

func (c *Config) AddRequestConfig(reqConfig typ.Rule) error

AddRequestConfig adds a new Rule

func (*Config) AddRule

func (c *Config) AddRule(rule typ.Rule) error

AddRule updates the default Rule

func (*Config) CreateDefaultConfig

func (c *Config) CreateDefaultConfig() error

func (*Config) DeleteProvider

func (c *Config) DeleteProvider(uuid string) error

DeleteProvider removes a provider by UUID

func (*Config) DeleteRule

func (c *Config) DeleteRule(ruleUUID string) error

func (*Config) EnsureDefaultScenarioConfigs

func (c *Config) EnsureDefaultScenarioConfigs()

EnsureDefaultScenarioConfigs ensures that all scenarios have default config with appropriate flags

func (*Config) FetchAndSaveProviderModels

func (c *Config) FetchAndSaveProviderModels(uid string) error

FetchAndSaveProviderModels fetches models from a provider with fallback hierarchy

func (*Config) GetDebug

func (c *Config) GetDebug() bool

GetDebug returns the debug setting

func (*Config) GetDefaultMaxTokens

func (c *Config) GetDefaultMaxTokens() int

GetDefaultMaxTokens returns the configured default max_tokens

func (*Config) GetDefaultRequestConfig

func (c *Config) GetDefaultRequestConfig() *typ.Rule

GetDefaultRequestConfig returns the default Rule

func (*Config) GetDefaultRequestID

func (c *Config) GetDefaultRequestID() int

GetDefaultRequestID returns the index of the default Rule

func (*Config) GetDefaults

func (c *Config) GetDefaults() (requestModel, responseModel string)

GetDefaults returns all default values from the default Rule

func (*Config) GetEffectiveToolConfig

func (c *Config) GetEffectiveToolConfig(providerUUID, toolType string, mergeFunc func(global, provider interface{}) interface{}, globalConfig interface{}) (interface{}, bool)

GetEffectiveToolConfig returns the effective tool config for a specific provider and tool type This is a generic method that works for any tool type The mergeFunc parameter defines how to merge global and provider-specific configs

Usage:

var globalCfg typ.ToolInterceptorConfig
if !c.GetToolConfig(db.ToolTypeInterceptor, &globalCfg) {
    // No global config
    return nil, false
}

effective, enabled := c.GetEffectiveToolConfig(providerUUID, db.ToolTypeInterceptor,
    func(globalJSON, providerJSON []byte) ([]byte, error) {
        // Custom merge logic
        return mergedJSON, nil
    },
    &globalCfg,
)

func (*Config) GetErrorLogFilterExpression

func (c *Config) GetErrorLogFilterExpression() string

GetErrorLogFilterExpression returns the error log filter expression

func (*Config) GetGUIDebug

func (c *Config) GetGUIDebug() bool

GetGUIDebug returns the GUI debug setting

func (*Config) GetGUIPort

func (c *Config) GetGUIPort() int

GetGUIPort returns the GUI port setting (0 means use ServerPort)

func (*Config) GetGUIVerbose

func (c *Config) GetGUIVerbose() bool

GetGUIVerbose returns the GUI verbose setting

func (*Config) GetImBotSettingsStore added in v0.260305.1400

func (c *Config) GetImBotSettingsStore() *db.ImBotSettingsStore

GetImBotSettingsStore returns the ImBot settings store (may be nil in tests).

func (*Config) GetJWTSecret

func (c *Config) GetJWTSecret() string

GetJWTSecret returns the JWT secret for token generation

func (*Config) GetModelManager

func (c *Config) GetModelManager() *data.ModelListManager

func (*Config) GetModelToken

func (c *Config) GetModelToken() string

GetModelToken returns the model token

func (*Config) GetOpenBrowser

func (c *Config) GetOpenBrowser() bool

GetOpenBrowser returns the open browser setting

func (*Config) GetProviderByName

func (c *Config) GetProviderByName(name string) (*typ.Provider, error)

func (*Config) GetProviderByUUID

func (c *Config) GetProviderByUUID(uuid string) (*typ.Provider, error)

GetProviderByUUID returns a provider

func (*Config) GetRequestConfigs

func (c *Config) GetRequestConfigs() []typ.Rule

GetRequestConfigs returns all Rules

func (*Config) GetRequestModel

func (c *Config) GetRequestModel() string

GetRequestModel returns the request model from the default Rule

func (*Config) GetResponseModel

func (c *Config) GetResponseModel() string

GetResponseModel returns the response model from the default Rule

func (*Config) GetRuleByRequestModelAndScenario

func (c *Config) GetRuleByRequestModelAndScenario(requestModel string, scenario typ.RuleScenario) *typ.Rule

GetRuleByRequestModelAndScenario returns the Rule for the given request model and scenario

func (*Config) GetRuleByUUID

func (c *Config) GetRuleByUUID(UUID string) *typ.Rule

GetRuleByUUID returns the Rule for the given request uuid

func (*Config) GetScenarioConfig

func (c *Config) GetScenarioConfig(scenario typ.RuleScenario) *typ.ScenarioConfig

GetScenarioConfig returns the configuration for a specific scenario

func (*Config) GetScenarioFlag

func (c *Config) GetScenarioFlag(scenario typ.RuleScenario, flagName string) bool

GetScenarioFlag returns a specific flag value for a scenario

func (*Config) GetScenarioStringFlag

func (c *Config) GetScenarioStringFlag(scenario typ.RuleScenario, flagName string) string

GetScenarioStringFlag returns a string flag value for a scenario

func (*Config) GetScenarios

func (c *Config) GetScenarios() []typ.ScenarioConfig

GetScenarios returns all scenario configurations

func (*Config) GetServerPort

func (c *Config) GetServerPort() int

GetServerPort returns the configured server port

func (*Config) GetStatsStore added in v0.260124.900

func (c *Config) GetStatsStore() *db.StatsStore

GetStatsStore returns the dedicated stats store (may be nil in tests).

func (*Config) GetTemplateManager

func (c *Config) GetTemplateManager() *data.TemplateManager

GetTemplateManager returns the template manager

func (*Config) GetToken

func (c *Config) GetToken() string

GetToken returns the user token (for backward compatibility)

func (*Config) GetToolConfig

func (c *Config) GetToolConfig(toolType string, target interface{}) bool

GetToolConfig returns the global config for a specific tool type target is a pointer to the config struct to unmarshal into Returns true if config was found and successfully unmarshaled

func (*Config) GetToolInterceptorConfig

func (c *Config) GetToolInterceptorConfig() *typ.ToolInterceptorConfig

GetToolInterceptorConfig returns the global tool interceptor config

func (*Config) GetToolInterceptorConfigForProvider

func (c *Config) GetToolInterceptorConfigForProvider(providerUUID string) (*typ.ToolInterceptorConfig, bool)

GetToolInterceptorConfigForProvider returns the effective tool interceptor config for a specific provider This merges the global config with provider-specific config from the tool config store

func (*Config) GetUUIDByRequestModel

func (c *Config) GetUUIDByRequestModel(requestModel string) string

GetUUIDByRequestModel returns the UUID for the given request model name

func (*Config) GetUUIDByRequestModelAndScenario

func (c *Config) GetUUIDByRequestModelAndScenario(requestModel string, scenario typ.RuleScenario) string

GetUUIDByRequestModelAndScenario returns the UUID for the given request model and scenario

func (*Config) GetUsageStore added in v0.260124.900

func (c *Config) GetUsageStore() *db.UsageStore

GetUsageStore returns the usage store (may be nil in tests).

func (*Config) GetUserToken

func (c *Config) GetUserToken() string

GetUserToken returns the user token

func (*Config) GetVerbose

func (c *Config) GetVerbose() bool

GetVerbose returns the verbose setting

func (*Config) GetVirtualModelToken

func (c *Config) GetVirtualModelToken() string

GetVirtualModelToken returns the virtual model token

func (*Config) HasModelToken

func (c *Config) HasModelToken() bool

HasModelToken checks if a model token is configured

func (*Config) HasToken

func (c *Config) HasToken() bool

HasToken checks if a user token is configured (for backward compatibility)

func (*Config) HasUserToken

func (c *Config) HasUserToken() bool

HasUserToken checks if a user token is configured

func (*Config) HasVirtualModelToken

func (c *Config) HasVirtualModelToken() bool

HasVirtualModelToken checks if a virtual model token is configured

func (*Config) InsertDefaultRule

func (c *Config) InsertDefaultRule() error

func (*Config) IsRequestModel

func (c *Config) IsRequestModel(modelName string) bool

IsRequestModel checks if the given model name is a request model in any config

func (*Config) IsRequestModelInScenario

func (c *Config) IsRequestModelInScenario(modelName string, scenario typ.RuleScenario) bool

IsRequestModelInScenario checks if the given model name is a request model in the given scenario

func (*Config) ListOAuthProviders

func (c *Config) ListOAuthProviders() ([]*typ.Provider, error)

ListOAuthProviders returns all OAuth-enabled providers

func (*Config) ListProviders

func (c *Config) ListProviders() []*typ.Provider

ListProviders returns all providers

func (*Config) MatchRuleByModelAndScenario

func (c *Config) MatchRuleByModelAndScenario(requestModel string, scenario typ.RuleScenario) *typ.Rule

MatchRuleByModelAndScenario finds a rule by model name with wildcard support Priority: exact match > wildcard match Returns nil if no rule matches

func (*Config) RefreshStatsFromStore

func (c *Config) RefreshStatsFromStore() error

RefreshStatsFromStore hydrates service stats and rule state from the SQLite store.

func (*Config) RemoveRequestConfig

func (c *Config) RemoveRequestConfig(index int) error

RemoveRequestConfig removes the Rule at the given index

func (*Config) Save

func (c *Config) Save() error

Save saves the global configuration to file

func (*Config) SaveCurrentServiceID

func (c *Config) SaveCurrentServiceID(ruleUUID string, serviceID string) error

SaveCurrentServiceID persists the current service ID for a rule to SQLite

func (*Config) SetDebug

func (c *Config) SetDebug(debug bool) error

SetDebug updates the debug setting

func (*Config) SetDefaultMaxTokens

func (c *Config) SetDefaultMaxTokens(maxTokens int) error

SetDefaultMaxTokens updates the default max_tokens

func (*Config) SetDefaultRequestID

func (c *Config) SetDefaultRequestID(id int) error

SetDefaultRequestID sets the index of the default Rule

func (*Config) SetErrorLogFilterExpression

func (c *Config) SetErrorLogFilterExpression(expr string) error

SetErrorLogFilterExpression updates the error log filter expression

func (*Config) SetGUIDebug

func (c *Config) SetGUIDebug(debug bool) error

SetGUIDebug updates the GUI debug setting

func (*Config) SetGUIPort

func (c *Config) SetGUIPort(port int) error

SetGUIPort updates the GUI port setting

func (*Config) SetGUIVerbose

func (c *Config) SetGUIVerbose(verbose bool) error

SetGUIVerbose updates the GUI verbose setting

func (*Config) SetModelToken

func (c *Config) SetModelToken(token string) error

SetModelToken sets the model token for OpenAI and Anthropic APIs

func (*Config) SetOpenBrowser

func (c *Config) SetOpenBrowser(openBrowser bool) error

SetOpenBrowser updates the open browser setting (runtime only, not persisted)

func (*Config) SetRequestConfigs

func (c *Config) SetRequestConfigs(requestConfigs []typ.Rule) error

SetRequestConfigs updates all Rules

func (*Config) SetScenarioConfig

func (c *Config) SetScenarioConfig(config typ.ScenarioConfig) error

SetScenarioConfig updates or creates a scenario configuration

func (*Config) SetScenarioFlag

func (c *Config) SetScenarioFlag(scenario typ.RuleScenario, flagName string, value bool) error

SetScenarioFlag sets a specific flag value for a scenario

func (*Config) SetScenarioStringFlag

func (c *Config) SetScenarioStringFlag(scenario typ.RuleScenario, flagName string, value string) error

SetScenarioStringFlag sets a string flag value for a scenario

func (*Config) SetServerPort

func (c *Config) SetServerPort(port int) error

SetServerPort updates the server port

func (*Config) SetTemplateManager

func (c *Config) SetTemplateManager(tm *data.TemplateManager)

SetTemplateManager sets the template manager for provider templates

func (*Config) SetToken

func (c *Config) SetToken(token string) error

SetToken sets the user token (for backward compatibility)

func (*Config) SetToolConfig

func (c *Config) SetToolConfig(toolType string, config interface{}) error

SetToolConfig sets the global config for a specific tool type

func (*Config) SetUserToken

func (c *Config) SetUserToken(token string) error

SetUserToken sets the user token for UI and control API

func (*Config) SetVerbose

func (c *Config) SetVerbose(verbose bool) error

SetVerbose updates the verbose setting

func (*Config) SetVirtualModelToken

func (c *Config) SetVirtualModelToken(token string) error

SetVirtualModelToken sets the virtual model token for testing

func (*Config) UpdateProvider

func (c *Config) UpdateProvider(uuid string, provider *typ.Provider) error

UpdateProvider updates an existing provider by UUID

func (*Config) UpdateRequestConfigAt

func (c *Config) UpdateRequestConfigAt(index int, reqConfig typ.Rule) error

UpdateRequestConfigAt updates the Rule at the given index

func (*Config) UpdateRequestConfigByRequestModel

func (c *Config) UpdateRequestConfigByRequestModel(requestModel string, reqConfig typ.Rule) error

UpdateRequestConfigByRequestModel updates a Rule by its request model name

func (*Config) UpdateRequestConfigByUUID

func (c *Config) UpdateRequestConfigByUUID(uuid string, reqConfig typ.Rule) error

UpdateRequestConfigByUUID updates a Rule by its UUID

func (*Config) UpdateRule

func (c *Config) UpdateRule(uid string, rule typ.Rule) error

type GUIConfig

type GUIConfig struct {
	// Debug enables debug mode for GUI (gin debug logging, detailed logs)
	Debug bool `json:"debug"`
	// Port specifies the GUI server port. 0 means use ServerPort from global config
	Port int `json:"port"`
	// Verbose enables verbose logging for GUI
	Verbose bool `json:"verbose"`
}

GUIConfig holds GUI-specific settings (slim/gui mode)

type KV

type KV struct {
	Key   string
	Value any
}

type OpenCodeConfigPayload

type OpenCodeConfigPayload struct {
	Provider map[string]OpenCodeProviderConfig `json:"provider"`
}

OpenCodeConfigPayload contains the payload for applying OpenCode config

type OpenCodeProviderConfig

type OpenCodeProviderConfig struct {
	Name    string                 `json:"name"`
	NPM     string                 `json:"npm"`
	Options map[string]interface{} `json:"options"`
	Models  map[string]interface{} `json:"models"`
}

OpenCodeProviderConfig contains the provider configuration for OpenCode

type RemoteCoderConfig

type RemoteCoderConfig struct {
	Port                 int    `json:"port"`
	DBPath               string `json:"db_path"`
	SessionTimeout       string `json:"session_timeout"`
	MessageRetentionDays int    `json:"message_retention_days"`
	RateLimitMax         int    `json:"rate_limit_max"`
	RateLimitWindow      string `json:"rate_limit_window"`
	RateLimitBlock       string `json:"rate_limit_block"`
}

RemoteCoderConfig holds configuration for the remote-coder service. AgentBoot and Permission configuration are loaded from environment variables via agentboot.LoadConfigFromEnv() and agentboot.ParsePermissionConfig().

type Watcher

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

Watcher monitors configuration changes and triggers reloads

func NewConfigWatcher

func NewConfigWatcher(config *Config) (*Watcher, error)

NewConfigWatcher creates a new configuration watcher

func (*Watcher) AddCallback

func (cw *Watcher) AddCallback(callback func(*Config))

AddCallback adds a callback function to be called when configuration changes

func (*Watcher) Start

func (cw *Watcher) Start() error

Start starts watching for configuration changes

func (*Watcher) Stop

func (cw *Watcher) Stop() error

Stop stops the configuration watcher

func (*Watcher) TriggerReload

func (cw *Watcher) TriggerReload() error

TriggerReload manually triggers a configuration reload

Jump to

Keyboard shortcuts

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