Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateModelToken() (string, error)
- func GenerateSecureToken(prefix string) (string, error)
- func GenerateUUID() string
- func GenerateUserToken() (string, error)
- func InstallNotifyScript() (scriptPath string, created bool, err error)
- func InstallStatusLineScript() (scriptPath string, created bool, err error)
- func IsDefaultToken(token string) bool
- func IsTacticValid(tactic *typ.Tactic) bool
- func IsWildcardRuleName(name string) bool
- func Migrate(c *Config) error
- func NotifyHookEntries() map[string]interface{}
- func SmartGuideRuleUUID(botUUID string) string
- type ApplyOption
- type ApplyResult
- func ApplyClaudeOnboarding(payload map[string]interface{}) (*ApplyResult, error)
- func ApplyClaudeSettingsFromEnv(env map[string]string, opts ...ApplyOption) (*ApplyResult, error)
- func ApplyClaudeSettingsToPath(targetPath string, env map[string]string, opts ...ApplyOption) (*ApplyResult, error)
- func ApplyNotifyHooks() (*ApplyResult, error)
- func ApplyOpenCodeConfig(payload map[string]interface{}) (*ApplyResult, error)
- 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) ApplyHTTPTransportConfig()
- func (c *Config) CreateDefaultConfig() error
- func (c *Config) CreateProfile(baseScenario typ.RuleScenario, name string, unified bool) (typ.ProfileMeta, error)
- func (c *Config) DeleteProfile(baseScenario typ.RuleScenario, profileID string) error
- func (c *Config) DeleteProvider(uuid string) error
- func (c *Config) DeleteRule(ruleUUID string) error
- func (c *Config) EnsureDefaultScenarioConfigs()
- func (c *Config) EnsureSmartGuideRule(providerUUID, modelID string) error
- func (c *Config) EnsureSmartGuideRuleForBot(botUUID, botName, providerUUID, modelID string) error
- func (c *Config) FetchAndSaveProviderModels(uid string) error
- func (c *Config) GetAPITokenAlgorithm() string
- func (c *Config) GetAPITokenIssuer() string
- func (c *Config) GetAPITokenSecret() string
- 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) GetEffectiveToolConfig(providerUUID, toolType string, ...) (interface{}, bool)
- func (c *Config) GetErrorLogFilterExpression() string
- func (c *Config) GetGUIDebug() bool
- func (c *Config) GetGUIPort() int
- func (c *Config) GetGUIVerbose() bool
- func (c *Config) GetInternalAPIToken() string
- func (c *Config) GetJWTSecret() string
- func (c *Config) GetMCPRuntimeConfig() *typ.MCPRuntimeConfig
- func (c *Config) GetModelManager() *data.ModelListManager
- func (c *Config) GetModelToken() string
- func (c *Config) GetOpenBrowser() bool
- func (c *Config) GetProfile(baseScenario typ.RuleScenario, profileID string) (typ.ProfileMeta, bool)
- func (c *Config) GetProfiles(baseScenario typ.RuleScenario) []typ.ProfileMeta
- func (c *Config) GetProviderByName(name string) (*typ.Provider, error)
- func (c *Config) GetProviderByUUID(uuid string) (*typ.Provider, error)
- func (c *Config) GetProviderStore() *db.ProviderStore
- 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) GetScenarioExtensionBool(scenario typ.RuleScenario, key string) bool
- func (c *Config) GetScenarioExtensionString(scenario typ.RuleScenario, key string) string
- func (c *Config) GetScenarioFlag(scenario typ.RuleScenario, flagName string) bool
- func (c *Config) GetScenarioRecordingMode(scenario typ.RuleScenario) typ.RecordingMode
- func (c *Config) GetScenarioStringFlag(scenario typ.RuleScenario, flagName string) string
- func (c *Config) GetScenarios() []typ.ScenarioConfig
- func (c *Config) GetServerPort() int
- func (c *Config) GetSmartGuideRule() *typ.Rule
- func (c *Config) GetSmartGuideRuleForBot(botUUID string) *typ.Rule
- func (c *Config) GetTemplateManager() *data.TemplateManager
- func (c *Config) GetToken() string
- func (c *Config) GetToolConfig(toolType string, target interface{}) bool
- func (c *Config) GetUUIDByRequestModel(requestModel string) string
- func (c *Config) GetUUIDByRequestModelAndScenario(requestModel string, scenario typ.RuleScenario) string
- 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) IsGlobalTokenDisabled() bool
- func (c *Config) IsMultiTenantEnabled() bool
- func (c *Config) IsRequestModel(modelName string) bool
- func (c *Config) IsRequestModelInScenario(modelName string, scenario typ.RuleScenario) bool
- func (c *Config) IsScenarioRecordingEnabled(scenario typ.RuleScenario) bool
- func (c *Config) ListOAuthProviders() ([]*typ.Provider, error)
- func (c *Config) ListProviders() []*typ.Provider
- func (c *Config) MatchRuleByModelAndScenario(requestModel string, scenario typ.RuleScenario) *typ.Rule
- func (c *Config) RefreshStatsFromStore() error
- func (c *Config) RegisterProviderDeleteHook(hook ProviderDeleteHook)
- func (c *Config) RegisterProviderUpdateHook(hook ProviderUpdateHook)
- func (c *Config) RemoveRequestConfig(index int) error
- func (c *Config) ResolveProfileNameOrID(baseScenario typ.RuleScenario, input string) (string, error)
- func (c *Config) Save() error
- func (c *Config) SaveCurrentServiceID(ruleUUID string, serviceID string) 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) SetErrorLogFilterExpression(expr string) error
- func (c *Config) SetGUIDebug(debug bool) error
- func (c *Config) SetGUIPort(port int) error
- func (c *Config) SetGUIVerbose(verbose bool) error
- func (c *Config) SetModelToken(token string) error
- func (c *Config) SetMultiTenantConfig(config MultiTenantConfig) error
- func (c *Config) SetMultiTenantEnabled(enabled bool) 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) SetScenarioExtensions(scenario typ.RuleScenario, values map[string]interface{}) error
- func (c *Config) SetScenarioFlag(scenario typ.RuleScenario, flagName string, value bool) error
- func (c *Config) SetScenarioStringFlag(scenario typ.RuleScenario, flagName string, value string) error
- func (c *Config) SetServerPort(port int) error
- func (c *Config) SetTemplateManager(tm *data.TemplateManager)
- func (c *Config) SetToken(token string) error
- func (c *Config) SetToolConfig(toolType string, config interface{}) error
- func (c *Config) SetUserToken(token string) error
- func (c *Config) SetVerbose(verbose bool) error
- func (c *Config) StoreManager() *db.StoreManager
- func (c *Config) UpdateProfile(baseScenario typ.RuleScenario, profileID string, name string, unified *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 ConfigOption
- type EnterpriseContextJWTConfig
- type EnterpriseContextPublicKey
- type GUIConfig
- type HTTPTransportConfig
- type MultiTenantConfig
- type OpenCodeConfigPayload
- type OpenCodeProviderConfig
- type ProviderDeleteHook
- type ProviderUpdateHook
- type RemoteCoderConfig
- type Watcher
- func (cw *Watcher) AddCallback(callback func(*Config))
- func (cw *Watcher) AddWatchFile(filepath string) error
- func (cw *Watcher) GetWatchFiles() []string
- func (cw *Watcher) RemoveWatchFile(filepath string) error
- func (cw *Watcher) Start() error
- func (cw *Watcher) Stop() error
- func (cw *Watcher) TriggerReload() error
Constants ¶
const ( WildcardRuleName = "*" WildcardRuleNameAlt = "[any]" )
Wildcard rule names that match any model
const ( RuleUUIDTingly = "tingly" RuleUUIDBuiltinOpenAI = "built-in-openai" RuleUUIDBuiltinAnthropic = "built-in-anthropic" RuleUUIDBuiltinCodex = "built-in-codex" 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
const (
FeatureSmartCompact = "smart_compact"
)
Experimental feature flag names
const SmartGuideRuleUUIDPrefix = "_internal_smart_guide_"
SmartGuideRuleUUIDPrefix is the prefix for internal SmartGuide rules Each bot will have its own rule: _internal_smart_guide_{botUUID}
Variables ¶
var DefaultRules []typ.Rule
Functions ¶
func GenerateModelToken ¶ added in v0.260409.1540
func GenerateSecureToken ¶
GenerateSecureToken generates a cryptographically random token for user authentication The token is a 256-bit (32 byte) random value, hex-encoded, with a "tingly-box-" prefix
func GenerateUserToken ¶ added in v0.260409.1540
func InstallNotifyScript ¶
InstallNotifyScript installs the claude-notify.sh script to ~/.claude/ Returns the path to the installed script and whether it was newly created
func InstallStatusLineScript ¶
InstallStatusLineScript installs the tingly-statusline.sh script to ~/.claude/ Returns the path to the installed script and whether it was newly created
func IsDefaultToken ¶
IsDefaultToken checks if the given token is the default token
func IsTacticValid ¶
IsTacticValid checks if the tactic params are valid (not zero values)
func IsWildcardRuleName ¶
IsWildcardRuleName checks if the given rule name is a wildcard that matches any model. This function is thread-safe as it only performs constant string comparisons and does not access any shared state. It can be called without holding Config.mu.
func NotifyHookEntries ¶
func NotifyHookEntries() map[string]interface{}
NotifyHookEntries defines the Claude Code hooks to install for notifications. This can be passed to ApplyNotifyHooks or used directly in settings.json.
func SmartGuideRuleUUID ¶
SmartGuideRuleUUID generates a unique rule UUID for a specific bot
Types ¶
type ApplyOption ¶ added in v0.260423.0
type ApplyOption func(*applyOptions)
ApplyOption is a functional option for ApplyClaudeSettingsToPath
func WithBackup ¶ added in v0.260423.0
func WithBackup(enable bool) ApplyOption
WithBackup enables or disables backup when applying settings. Default is true (create backup).
func WithExtra ¶ added in v0.260423.0
func WithExtra(key string, value any) ApplyOption
WithExtra sets a single extra key-value pair to merge into the settings.
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, opts ...ApplyOption) (*ApplyResult, error)
ApplyClaudeSettingsFromEnv applies Claude settings configuration with env vars This is the safe version - env map is controlled by backend
func ApplyClaudeSettingsToPath ¶
func ApplyClaudeSettingsToPath(targetPath string, env map[string]string, opts ...ApplyOption) (*ApplyResult, error)
ApplyClaudeSettingsToPath applies Claude settings env vars to a specific target file. If the file exists, it merges the env section into the existing config (with backup). If not, it creates a new file with only the env section.
func ApplyNotifyHooks ¶
func ApplyNotifyHooks() (*ApplyResult, error)
ApplyNotifyHooks installs the notify script and merges notification hooks into settings.json. This is independent of the agent apply flow — it can be called standalone. Existing hooks with different matchers are preserved.
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
InternalAPIToken string `json:"-"` // Internal API token for probe testing (generated at startup, not persisted)
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
RandomUUID string `json:"random_uuid"` // A random uuid to help protocol transform for some special provider
ClaudeCodeDeviceID string `json:"claude_code_device_id"` // Calc from random claude code device id with sha256
// 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/' || Path matches '^/tbe/')")
// Health monitor settings
HealthMonitor loadbalance.HealthMonitorConfig `json:"health_monitor,omitempty" yaml:"health_monitor,omitempty"`
// Profiles stores scenario profile metadata, keyed by base scenario name.
// Each entry is a list of profiles for that scenario.
Profiles map[string][]typ.ProfileMeta `json:"profiles" yaml:"profiles"`
// Enterprise context JWT validation settings for TBE->TB proxy calls.
EnterpriseContextJWT EnterpriseContextJWTConfig `json:"enterprise_context_jwt,omitempty" yaml:"enterprise_context_jwt,omitempty"`
// HTTP Transport settings for upstream API connections
HTTPTransport HTTPTransportConfig `json:"http_transport,omitempty" yaml:"http_transport,omitempty"`
// ProviderTemplateSource supports three modes:
// 1. Empty/default -> use embedded templates (default GitHub sync behavior)
// 2. file:///path/to/template.json -> load from local file
// 3. https://example.com/template.json -> load from HTTP URL
ProviderTemplateSource string `yaml:"provider_template_source,omitempty" json:"provider_template_source,omitempty"`
// MultiTenantConfig holds settings for multi-tenant API token authentication
MultiTenantConfig MultiTenantConfig `yaml:"multi_tenant,omitempty" json:"multi_tenant,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(opts ...ConfigOption) (*Config, error)
NewConfig creates a new global configuration manager with the given options If no config directory is specified, uses the default tingly config directory
func NewConfigWithDir ¶
func NewConfigWithDir(configDir string, opts ...ConfigOption) (*Config, error)
NewConfigWithDir creates a new global configuration manager with a custom config directory This is a convenience function that calls NewConfig with WithConfigDir option For backward compatibility with existing code
func NewDefaultConfig ¶
NewDefaultConfig creates a new global configuration manager with default settings Uses the default tingly config directory and runs migrations
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. If a rule with the same UUID already exists, it is rejected instead of adding a duplicate.
func (*Config) ApplyHTTPTransportConfig ¶
func (c *Config) ApplyHTTPTransportConfig()
ApplyHTTPTransportConfig applies the HTTP transport configuration to the global transport pool This is called by TBE during initialization to configure connection pooling For TB (tingly-box), this applies the proxy settings (default: respect_env_proxy=true)
func (*Config) CreateDefaultConfig ¶
func (*Config) CreateProfile ¶
func (c *Config) CreateProfile(baseScenario typ.RuleScenario, name string, unified bool) (typ.ProfileMeta, error)
CreateProfile adds a new profile to a base scenario. Returns the created ProfileMeta. The unified parameter determines whether to use unified mode (single model) or separate mode (individual models).
func (*Config) DeleteProfile ¶
func (c *Config) DeleteProfile(baseScenario typ.RuleScenario, profileID string) error
DeleteProfile removes a profile by ID and cleans up all associated rules.
func (*Config) DeleteProvider ¶
DeleteProvider removes a provider by UUID
func (*Config) DeleteRule ¶
func (*Config) EnsureDefaultScenarioConfigs ¶
func (c *Config) EnsureDefaultScenarioConfigs()
EnsureDefaultScenarioConfigs ensures that all scenarios have default config with appropriate flags
func (*Config) EnsureSmartGuideRule ¶
EnsureSmartGuideRule ensures the _smart_guide rule exists (backward compatible) This method creates a rule without bot-specific identification Deprecated: Use EnsureSmartGuideRuleForBot for bot-specific rules
func (*Config) EnsureSmartGuideRuleForBot ¶
EnsureSmartGuideRuleForBot ensures the _smart_guide rule exists for a specific bot If the rule doesn't exist, it creates it. If it exists but the configuration differs, it updates the rule. The rule is persisted to config.json.
Each bot gets its own rule with UUID: _internal_smart_guide_{botUUID} The rule name uses the bot's name (if provided), otherwise uses botUUID
func (*Config) FetchAndSaveProviderModels ¶
FetchAndSaveProviderModels fetches models from a provider with fallback hierarchy
func (*Config) GetAPITokenAlgorithm ¶ added in v0.260418.2200
GetAPITokenAlgorithm returns the JWT signing algorithm for API tokens
func (*Config) GetAPITokenIssuer ¶ added in v0.260418.2200
GetAPITokenIssuer returns the issuer claim for API tokens
func (*Config) GetAPITokenSecret ¶ added in v0.260418.2200
GetAPITokenSecret returns the API token secret, falling back to JWTSecret
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) 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: load global config with GetToolConfig(), then call this helper to merge provider-specific overrides by tool type.
func (*Config) GetErrorLogFilterExpression ¶
GetErrorLogFilterExpression returns the error log filter expression
func (*Config) GetGUIDebug ¶
GetGUIDebug returns the GUI debug setting
func (*Config) GetGUIPort ¶
GetGUIPort returns the GUI port setting (0 means use ServerPort)
func (*Config) GetGUIVerbose ¶
GetGUIVerbose returns the GUI verbose setting
func (*Config) GetInternalAPIToken ¶
GetInternalAPIToken returns the internal API token for probe testing The token is generated at startup and stored in memory only (not persisted to config file)
func (*Config) GetJWTSecret ¶
GetJWTSecret returns the JWT secret for token generation
func (*Config) GetMCPRuntimeConfig ¶ added in v0.260409.1540
func (c *Config) GetMCPRuntimeConfig() *typ.MCPRuntimeConfig
GetMCPRuntimeConfig returns the global MCP runtime config.
func (*Config) GetModelManager ¶
func (c *Config) GetModelManager() *data.ModelListManager
func (*Config) GetModelToken ¶
GetModelToken returns the model token
func (*Config) GetOpenBrowser ¶
GetOpenBrowser returns the open browser setting
func (*Config) GetProfile ¶
func (c *Config) GetProfile(baseScenario typ.RuleScenario, profileID string) (typ.ProfileMeta, bool)
GetProfile returns a single profile by base scenario and profile ID.
func (*Config) GetProfiles ¶
func (c *Config) GetProfiles(baseScenario typ.RuleScenario) []typ.ProfileMeta
GetProfiles returns all profiles for a base scenario.
func (*Config) GetProviderByName ¶
func (*Config) GetProviderByUUID ¶
GetProviderByUUID returns a provider from database
func (*Config) GetProviderStore ¶
func (c *Config) GetProviderStore() *db.ProviderStore
GetProviderStore returns the provider store instance
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) GetScenarioExtensionBool ¶ added in v0.260409.1540
func (c *Config) GetScenarioExtensionBool(scenario typ.RuleScenario, key string) bool
GetScenarioExtensionBool returns a boolean value from scenario extensions.
func (*Config) GetScenarioExtensionString ¶ added in v0.260409.1540
func (c *Config) GetScenarioExtensionString(scenario typ.RuleScenario, key string) string
GetScenarioExtensionString returns a string value from scenario extensions.
func (*Config) GetScenarioFlag ¶
func (c *Config) GetScenarioFlag(scenario typ.RuleScenario, flagName string) bool
func (*Config) GetScenarioRecordingMode ¶
func (c *Config) GetScenarioRecordingMode(scenario typ.RuleScenario) typ.RecordingMode
GetScenarioRecordingMode returns the effective recording mode for a scenario It checks both legacy Recording (bool) and new RecordV2 (RecordingMode) Priority: RecordV2 > legacy Recording
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 ¶
GetServerPort returns the configured server port
func (*Config) GetSmartGuideRule ¶
GetSmartGuideRule returns the _smart_guide rule (backward compatible, non-bot-specific) Deprecated: Use GetSmartGuideRuleForBot for bot-specific rules
func (*Config) GetSmartGuideRuleForBot ¶
GetSmartGuideRuleForBot returns the _smart_guide rule for a specific bot
func (*Config) GetTemplateManager ¶
func (c *Config) GetTemplateManager() *data.TemplateManager
GetTemplateManager returns the template manager
func (*Config) GetToolConfig ¶
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) 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) 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) IsGlobalTokenDisabled ¶ added in v0.260418.2200
IsGlobalTokenDisabled returns whether the global model token is disabled
func (*Config) IsMultiTenantEnabled ¶ added in v0.260418.2200
IsMultiTenantEnabled returns whether multi-tenant mode is enabled
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) IsScenarioRecordingEnabled ¶
func (c *Config) IsScenarioRecordingEnabled(scenario typ.RuleScenario) bool
IsScenarioRecordingEnabled checks if recording is enabled for a scenario
func (*Config) ListOAuthProviders ¶
ListOAuthProviders returns all OAuth-enabled providers
func (*Config) ListProviders ¶
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 ¶
RefreshStatsFromStore hydrates service stats and rule state from the SQLite store.
func (*Config) RegisterProviderDeleteHook ¶
func (c *Config) RegisterProviderDeleteHook(hook ProviderDeleteHook)
RegisterProviderDeleteHook adds a hook to be called when a provider is deleted
func (*Config) RegisterProviderUpdateHook ¶
func (c *Config) RegisterProviderUpdateHook(hook ProviderUpdateHook)
RegisterProviderUpdateHook adds a hook to be called when a provider is updated
func (*Config) RemoveRequestConfig ¶
RemoveRequestConfig removes the Rule at the given index
func (*Config) ResolveProfileNameOrID ¶
func (c *Config) ResolveProfileNameOrID(baseScenario typ.RuleScenario, input string) (string, error)
ResolveProfileNameOrID resolves a profile identifier to a profile ID. If the input matches an existing ID (e.g. "p1"), returns it directly. If the input matches an existing name, returns the corresponding ID.
func (*Config) SaveCurrentServiceID ¶
SaveCurrentServiceID persists the current service ID for a rule to SQLite
func (*Config) SetDefaultMaxTokens ¶
SetDefaultMaxTokens updates the default max_tokens
func (*Config) SetDefaultRequestID ¶
SetDefaultRequestID sets the index of the default Rule
func (*Config) SetErrorLogFilterExpression ¶
SetErrorLogFilterExpression updates the error log filter expression
func (*Config) SetGUIDebug ¶
SetGUIDebug updates the GUI debug setting
func (*Config) SetGUIPort ¶
SetGUIPort updates the GUI port setting
func (*Config) SetGUIVerbose ¶
SetGUIVerbose updates the GUI verbose setting
func (*Config) SetModelToken ¶
SetModelToken sets the model token for OpenAI and Anthropic APIs
func (*Config) SetMultiTenantConfig ¶ added in v0.260418.2200
func (c *Config) SetMultiTenantConfig(config MultiTenantConfig) error
SetMultiTenantConfig updates the entire multi-tenant configuration
func (*Config) SetMultiTenantEnabled ¶ added in v0.260418.2200
SetMultiTenantEnabled updates the multi-tenant enabled flag
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) SetScenarioExtensions ¶ added in v0.260409.1540
func (c *Config) SetScenarioExtensions(scenario typ.RuleScenario, values map[string]interface{}) error
SetScenarioExtensions merges extension values into a scenario config.
func (*Config) SetScenarioFlag ¶
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 ¶
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) SetToolConfig ¶
SetToolConfig sets the global config for a specific tool type
func (*Config) SetUserToken ¶
SetUserToken sets the user token for UI and control API
func (*Config) SetVerbose ¶
SetVerbose updates the verbose setting
func (*Config) StoreManager ¶
func (c *Config) StoreManager() *db.StoreManager
StoreManager returns the unified store manager (may be nil in tests). This provides access to all database stores through a single interface. External consumers should use this method instead of the individual GetXxxStore() methods.
func (*Config) UpdateProfile ¶
func (c *Config) UpdateProfile(baseScenario typ.RuleScenario, profileID string, name string, unified *bool) error
UpdateProfile updates the name of an existing profile. The unified parameter is accepted for API compatibility but ignored — mode is fixed at creation time. To switch modes, delete and recreate the profile.
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 ConfigOption ¶
type ConfigOption func(*configOptions)
ConfigOption is a function that modifies a Config during initialization
func WithConfigDir ¶
func WithConfigDir(dir string) ConfigOption
WithConfigDir returns a ConfigOption that sets a custom config directory
func WithDisableBuiltIn ¶
func WithDisableBuiltIn() ConfigOption
WithDisableBuiltIn returns a ConfigOption that disables the built-in rules creation
func WithDisableMigration ¶
func WithDisableMigration() ConfigOption
WithDisableMigration returns a ConfigOption that disables the migration step Useful when using tingly-box as a library in external projects
type EnterpriseContextJWTConfig ¶
type EnterpriseContextJWTConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
AllowedIssuers []string `json:"allowed_issuers,omitempty" yaml:"allowed_issuers,omitempty"`
AllowedAudiences []string `json:"allowed_audiences,omitempty" yaml:"allowed_audiences,omitempty"`
AlgAllowlist []string `json:"alg_allowlist,omitempty" yaml:"alg_allowlist,omitempty"`
HS256SecretRef string `json:"hs256_secret_ref,omitempty" yaml:"hs256_secret_ref,omitempty"`
RS256PublicKeyRef string `json:"rs256_public_key_ref,omitempty" yaml:"rs256_public_key_ref,omitempty"`
JWKSURL string `json:"jwks_url,omitempty" yaml:"jwks_url,omitempty"`
PublicKeys []EnterpriseContextPublicKey `json:"public_keys,omitempty" yaml:"public_keys,omitempty"`
ClockSkewSeconds int `json:"clock_skew_seconds,omitempty" yaml:"clock_skew_seconds,omitempty"`
RequireJTI bool `json:"require_jti" yaml:"require_jti"`
}
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 HTTPTransportConfig ¶
type HTTPTransportConfig struct {
// MaxIdleConns is the maximum number of idle connections across all hosts
// Default (nil): 100 (Go stdlib default)
// Recommended for 200 concurrent users: 200-300
MaxIdleConns *int `json:"max_idle_conns,omitempty" yaml:"max_idle_conns,omitempty"`
// MaxIdleConnsPerHost is the maximum number of idle connections per host
// Default (nil): 2 (Go stdlib default)
// Recommended for 200 concurrent users: 20-50
MaxIdleConnsPerHost *int `json:"max_idle_conns_per_host,omitempty" yaml:"max_idle_conns_per_host,omitempty"`
// MaxConnsPerHost limits the total number of connections per host (active + idle)
// Default (nil): 0 (no limit)
// Set to control maximum concurrent connections to a single upstream host
MaxConnsPerHost *int `json:"max_conns_per_host,omitempty" yaml:"max_conns_per_host,omitempty"`
// DisableKeepAlives disables HTTP/1.1 keep-alive connections
// Default (nil): false
// WARNING: Setting this to true will significantly impact performance
DisableKeepAlives *bool `json:"disable_keep_alives,omitempty" yaml:"disable_keep_alives,omitempty"`
// RespectEnvProxy controls whether providers without explicit proxy configuration
// should use environment/system proxy settings (HTTP_PROXY, HTTPS_PROXY, macOS system proxy, etc.)
// Default (nil): false - providers without proxy_url connect directly
// Set to true: providers without proxy_url will use system/environment proxy
RespectEnvProxy *bool `json:"respect_env_proxy,omitempty" yaml:"respect_env_proxy,omitempty"`
}
HTTPTransportConfig holds HTTP transport connection pool settings These settings control the connection pooling behavior for upstream API requests All fields use pointers so that omitting them means "use Go default" (backward compatible)
type MultiTenantConfig ¶ added in v0.260418.2200
type MultiTenantConfig struct {
// Enabled enables multi-tenant mode with JWT API token authentication
// When false, only the global model token is accepted (backward compatible)
Enabled bool `json:"enabled" yaml:"enabled"`
// DisableGlobalToken disables the global model token when true
// When enabled, only JWT API tokens are accepted for authentication
DisableGlobalToken bool `json:"disable_global_token" yaml:"disable_global_token"`
// APITokenSecret is the secret key for signing JWT tokens
// Use env: or file: references for secure secret management
// Default: Uses JWTSecret from main config
APITokenSecret string `json:"api_token_secret,omitempty" yaml:"api_token_secret,omitempty"`
// APITokenAlgorithm specifies the JWT signing algorithm
// Supported: "HS256" (default), "RS256"
APITokenAlgorithm string `json:"api_token_algorithm,omitempty" yaml:"api_token_algorithm,omitempty"`
// APITokenIssuer is the issuer claim for JWT tokens
// Default: "tingly-box"
APITokenIssuer string `json:"api_token_issuer,omitempty" yaml:"api_token_issuer,omitempty"`
}
MultiTenantConfig holds settings for multi-tenant API token authentication
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 ProviderDeleteHook ¶
type ProviderDeleteHook interface {
OnProviderDelete(uuid string)
}
ProviderDeleteHook is called when a provider is deleted
type ProviderUpdateHook ¶
ProviderUpdateHook is called when a provider is updated
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 ¶
NewConfigWatcher creates a new configuration watcher
func (*Watcher) AddCallback ¶
AddCallback adds a callback function to be called when configuration changes
func (*Watcher) AddWatchFile ¶
AddWatchFile adds a file to the watch list If the watcher is already running, the file will be added immediately
func (*Watcher) GetWatchFiles ¶
GetWatchFiles returns a copy of the current watch file list
func (*Watcher) RemoveWatchFile ¶
RemoveWatchFile removes a file from the watch list
func (*Watcher) TriggerReload ¶
TriggerReload manually triggers a configuration reload