Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateUUID() string
- func IsTacticValid(tactic *typ.Tactic) bool
- func Migrate(c *Config) error
- type ApplyResult
- type ClaudeSettingsPayload
- type Config
- func (c *Config) AddOrUpdateRequestConfigByRequestModel(reqConfig typ.Rule) error
- func (c *Config) AddProvider(provider *typ.Provider) error
- func (c *Config) AddProviderByName(name, apiBase, token string) error
- func (c *Config) AddRequestConfig(reqConfig typ.Rule) error
- func (c *Config) AddRule(rule typ.Rule) error
- func (c *Config) CreateDefaultConfig() error
- func (c *Config) DeleteProvider(uuid string) error
- func (c *Config) DeleteRule(ruleUUID string) error
- func (c *Config) FetchAndSaveProviderModels(uid string) error
- func (c *Config) GetDebug() bool
- func (c *Config) GetDefaultMaxTokens() int
- func (c *Config) GetDefaultRequestConfig() *typ.Rule
- func (c *Config) GetDefaultRequestID() int
- func (c *Config) GetDefaults() (requestModel, responseModel string)
- func (c *Config) GetEncryptProviders() bool
- func (c *Config) GetErrorLogFilterExpression() string
- func (c *Config) GetJWTSecret() string
- func (c *Config) GetModelManager() *template.ModelListManager
- func (c *Config) GetModelToken() string
- func (c *Config) GetOpenBrowser() bool
- func (c *Config) GetProviderByName(name string) (*typ.Provider, error)
- func (c *Config) GetProviderByUUID(uuid string) (*typ.Provider, error)
- func (c *Config) GetRequestConfigs() []typ.Rule
- func (c *Config) GetRequestModel() string
- func (c *Config) GetResponseModel() string
- func (c *Config) GetRuleByRequestModelAndScenario(requestModel string, scenario typ.RuleScenario) *typ.Rule
- func (c *Config) GetRuleByUUID(UUID string) *typ.Rule
- func (c *Config) GetScenarioConfig(scenario typ.RuleScenario) *typ.ScenarioConfig
- func (c *Config) GetScenarioFlag(scenario typ.RuleScenario, flagName string) bool
- func (c *Config) GetScenarios() []typ.ScenarioConfig
- func (c *Config) GetServerPort() int
- func (c *Config) GetStatsStore() *db.StatsStore
- func (c *Config) GetTemplateManager() *template.TemplateManager
- func (c *Config) GetToken() string
- func (c *Config) GetUUIDByRequestModel(requestModel string) string
- func (c *Config) GetUUIDByRequestModelAndScenario(requestModel string, scenario typ.RuleScenario) string
- func (c *Config) GetUsageStore() *db.UsageStore
- func (c *Config) GetUserToken() string
- func (c *Config) GetVerbose() bool
- func (c *Config) HasModelToken() bool
- func (c *Config) HasToken() bool
- func (c *Config) HasUserToken() bool
- func (c *Config) InsertDefaultRule() error
- func (c *Config) IsRequestModel(modelName string) bool
- func (c *Config) IsRequestModelInScenario(modelName string, scenario typ.RuleScenario) bool
- func (c *Config) ListOAuthProviders() ([]*typ.Provider, error)
- func (c *Config) ListProviders() []*typ.Provider
- func (c *Config) RefreshStatsFromStore() error
- func (c *Config) RemoveRequestConfig(index int) error
- func (c *Config) Save() error
- func (c *Config) SetDebug(debug bool) error
- func (c *Config) SetDefaultMaxTokens(maxTokens int) error
- func (c *Config) SetDefaultRequestID(id int) error
- func (c *Config) SetEncryptProviders(encrypt bool) error
- func (c *Config) SetErrorLogFilterExpression(expr string) error
- func (c *Config) SetModelToken(token string) error
- func (c *Config) SetOpenBrowser(openBrowser bool) error
- func (c *Config) SetRequestConfigs(requestConfigs []typ.Rule) error
- func (c *Config) SetScenarioConfig(config typ.ScenarioConfig) error
- func (c *Config) SetScenarioFlag(scenario typ.RuleScenario, flagName string, value bool) error
- func (c *Config) SetServerPort(port int) error
- func (c *Config) SetTemplateManager(tm *template.TemplateManager)
- func (c *Config) SetToken(token string) error
- func (c *Config) SetUserToken(token string) error
- func (c *Config) SetVerbose(verbose bool) error
- func (c *Config) UpdateProvider(uuid string, provider *typ.Provider) error
- func (c *Config) UpdateRequestConfigAt(index int, reqConfig typ.Rule) error
- func (c *Config) UpdateRequestConfigByRequestModel(requestModel string, reqConfig typ.Rule) error
- func (c *Config) UpdateRequestConfigByUUID(uuid string, reqConfig typ.Rule) error
- func (c *Config) UpdateRule(uid string, rule typ.Rule) error
- type OpenCodeConfigPayload
- type OpenCodeProviderConfig
- type Watcher
Constants ¶
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" )
Built-in rule UUID constants
Variables ¶
var DefaultRules []typ.Rule
Functions ¶
func IsTacticValid ¶
IsTacticValid checks if the tactic params are valid (not zero values)
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) (*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 ¶
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
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
// Merged fields from Config struct
ProvidersV1 map[string]*typ.Provider `json:"providers"`
Providers []*typ.Provider `json:"providers_v2,omitempty"`
ServerPort int `json:"server_port"`
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)
// Error log settings
ErrorLogFilterExpression string `json:"error_log_filter_expression"` // Expression for filtering error log entries (default: "StatusCode >= 400 && Path matches '^/api/'")
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 NewConfigWithDir ¶
NewConfigWithDir creates a new global configuration manager with a custom config directory
func (*Config) AddOrUpdateRequestConfigByRequestModel ¶
AddOrUpdateRequestConfigByRequestModel adds a new Rule or updates an existing one by request model name
func (*Config) AddProvider ¶
AddProvider adds a new provider using Provider struct
func (*Config) AddProviderByName ¶
AddProviderByName adds a new AI provider configuration by name, API base, and token
func (*Config) AddRequestConfig ¶
AddRequestConfig adds a new Rule
func (*Config) CreateDefaultConfig ¶
func (*Config) DeleteProvider ¶
DeleteProvider removes a provider by UUID
func (*Config) DeleteRule ¶
func (*Config) FetchAndSaveProviderModels ¶
FetchAndSaveProviderModels fetches models from a provider with fallback hierarchy
func (*Config) GetDefaultMaxTokens ¶
GetDefaultMaxTokens returns the configured default max_tokens
func (*Config) GetDefaultRequestConfig ¶
GetDefaultRequestConfig returns the default Rule
func (*Config) GetDefaultRequestID ¶
GetDefaultRequestID returns the index of the default Rule
func (*Config) GetDefaults ¶
GetDefaults returns all default values from the default Rule
func (*Config) GetEncryptProviders ¶ added in v0.260124.900
GetEncryptProviders returns whether provider information should be encrypted
func (*Config) GetErrorLogFilterExpression ¶
GetErrorLogFilterExpression returns the error log filter expression
func (*Config) GetJWTSecret ¶
GetJWTSecret returns the JWT secret for token generation
func (*Config) GetModelManager ¶
func (c *Config) GetModelManager() *template.ModelListManager
func (*Config) GetModelToken ¶
GetModelToken returns the model token
func (*Config) GetOpenBrowser ¶
GetOpenBrowser returns the open browser setting
func (*Config) GetProviderByName ¶
func (*Config) GetProviderByUUID ¶
GetProviderByUUID returns a provider
func (*Config) GetRequestConfigs ¶
GetRequestConfigs returns all Rules
func (*Config) GetRequestModel ¶
GetRequestModel returns the request model from the default Rule
func (*Config) GetResponseModel ¶
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 ¶
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) GetScenarios ¶
func (c *Config) GetScenarios() []typ.ScenarioConfig
GetScenarios returns all scenario configurations
func (*Config) GetServerPort ¶
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() *template.TemplateManager
GetTemplateManager returns the template manager
func (*Config) GetUUIDByRequestModel ¶
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 ¶
GetUserToken returns the user token
func (*Config) GetVerbose ¶
GetVerbose returns the verbose setting
func (*Config) HasModelToken ¶
HasModelToken checks if a model token is configured
func (*Config) HasToken ¶
HasToken checks if a user token is configured (for backward compatibility)
func (*Config) HasUserToken ¶
HasUserToken checks if a user token is configured
func (*Config) InsertDefaultRule ¶
func (*Config) IsRequestModel ¶
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 ¶
ListOAuthProviders returns all OAuth-enabled providers
func (*Config) ListProviders ¶
ListProviders returns all providers
func (*Config) RefreshStatsFromStore ¶
RefreshStatsFromStore hydrates service stats from the SQLite store.
func (*Config) RemoveRequestConfig ¶
RemoveRequestConfig removes the Rule at the given index
func (*Config) SetDefaultMaxTokens ¶
SetDefaultMaxTokens updates the default max_tokens
func (*Config) SetDefaultRequestID ¶
SetDefaultRequestID sets the index of the default Rule
func (*Config) SetEncryptProviders ¶ added in v0.260124.900
SetEncryptProviders sets whether to encrypt provider information
func (*Config) SetErrorLogFilterExpression ¶
SetErrorLogFilterExpression updates the error log filter expression
func (*Config) SetModelToken ¶
SetModelToken sets the model token for OpenAI and Anthropic APIs
func (*Config) SetOpenBrowser ¶
SetOpenBrowser updates the open browser setting (runtime only, not persisted)
func (*Config) SetRequestConfigs ¶
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 ¶
SetScenarioFlag sets a specific flag value for a scenario
func (*Config) SetServerPort ¶
SetServerPort updates the server port
func (*Config) SetTemplateManager ¶
func (c *Config) SetTemplateManager(tm *template.TemplateManager)
SetTemplateManager sets the template manager for provider templates
func (*Config) SetUserToken ¶
SetUserToken sets the user token for UI and control API
func (*Config) SetVerbose ¶
SetVerbose updates the verbose setting
func (*Config) UpdateProvider ¶
UpdateProvider updates an existing provider by UUID
func (*Config) UpdateRequestConfigAt ¶
UpdateRequestConfigAt updates the Rule at the given index
func (*Config) UpdateRequestConfigByRequestModel ¶
UpdateRequestConfigByRequestModel updates a Rule by its request model name
func (*Config) UpdateRequestConfigByUUID ¶
UpdateRequestConfigByUUID updates a Rule by its UUID
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 Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher monitors configuration changes and triggers reloads
func NewConfigWatcher ¶
NewConfigWatcher creates a new configuration watcher
func (*Watcher) AddCallback ¶
AddCallback adds a callback function to be called when configuration changes
func (*Watcher) TriggerReload ¶
TriggerReload manually triggers a configuration reload