Documentation
¶
Index ¶
- func DefaultProviders() map[string]ProviderConfig
- func EnsureDir(dir string) error
- func LoadProviders(providersFile string) (map[string]ProviderConfig, error)
- type AdminAuthConfig
- type AdminConfig
- type Config
- type EventsConfig
- type FileLogging
- type LedgerConfig
- type LoggingConfig
- type ProviderConfig
- type RedisConfig
- type RemoteConfig
- type SecurityConfig
- type ServerConfig
- type SessionConfig
- type StorageConfig
- type TLSConfig
- type WebhookEndpoint
- type WebhookReceiver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultProviders ¶
func DefaultProviders() map[string]ProviderConfig
DefaultProviders returns a copy of the built-in provider defaults.
func EnsureDir ¶
EnsureDir creates the .tokenomics directory and bootstrap files if they don't exist.
func LoadProviders ¶
func LoadProviders(providersFile string) (map[string]ProviderConfig, error)
LoadProviders loads provider definitions from a providers.yaml file. If providersFile is empty, searches standard paths (., $HOME/.tokenomics). Returns default built-in providers if no file is found. External file entries override defaults.
Types ¶
type AdminAuthConfig ¶ added in v0.1.3
type AdminAuthConfig struct {
Username string `mapstructure:"username"` // Empty means auth disabled
Password string `mapstructure:"password"` // Empty means auth disabled
}
AdminAuthConfig configures optional basic auth for admin routes.
type AdminConfig ¶ added in v0.1.3
type AdminConfig struct {
Enabled bool `mapstructure:"enabled"` // Enable embedded admin UI/API (default true)
Auth AdminAuthConfig `mapstructure:"auth"`
}
AdminConfig controls the embedded local admin UI and API.
type Config ¶
type Config struct {
Dir string `mapstructure:"dir"` // base .tokenomics directory (default ".tokenomics")
Server ServerConfig `mapstructure:"server"`
Admin AdminConfig `mapstructure:"admin"`
Storage StorageConfig `mapstructure:"storage"`
Session SessionConfig `mapstructure:"session"`
Security SecurityConfig `mapstructure:"security"`
Logging LoggingConfig `mapstructure:"logging"`
Providers map[string]ProviderConfig `mapstructure:"providers"`
Events EventsConfig `mapstructure:"events"`
Remote RemoteConfig `mapstructure:"remote"`
Ledger LedgerConfig `mapstructure:"ledger"`
CLIMaps map[string]string `mapstructure:"cli_maps"` // Map CLI names to providers (e.g. "claude" -> "anthropic")
DefaultProvider string `mapstructure:"default_provider"` // Default provider when not specified in policy
}
func (*Config) GetProvider ¶
func (c *Config) GetProvider(name string) (ProviderConfig, bool)
GetProvider returns the provider config by name, if it exists.
type EventsConfig ¶
type EventsConfig struct {
Webhooks []WebhookEndpoint `mapstructure:"webhooks"`
}
EventsConfig holds webhook and future event emitter configuration.
type FileLogging ¶ added in v0.1.2
type FileLogging struct {
Enabled bool `mapstructure:"enabled"` // Enable file logging (default false)
Level string `mapstructure:"level"` // Log level for file: "debug", "info", "warn", "error" (default "info")
Path string `mapstructure:"path"` // Log file path (default: {dir}/tokenomics.log)
}
FileLogging controls application log file output.
type LedgerConfig ¶
type LedgerConfig struct {
Enabled bool `mapstructure:"enabled"` // Enable session ledger (default true)
Memory bool `mapstructure:"memory"` // Record conversation content (default true)
EventLedger bool `mapstructure:"event_ledger"` // Capture structured communication events (default false, dual-write phase)
}
LedgerConfig controls per-session token tracking. Files are always written to the main `dir` setting (typically ~/.tokenomics).
type LoggingConfig ¶
type LoggingConfig struct {
Level string `mapstructure:"level"` // "debug", "info" (default), "warn", "error"
Format string `mapstructure:"format"` // "json" (default), "text"
RequestBody bool `mapstructure:"request_body"` // Log full request bodies (default false)
ResponseBody bool `mapstructure:"response_body"` // Log full response bodies (default false)
HideTokenHash bool `mapstructure:"hide_token_hash"` // Mask token hashes in logs (default false)
DisableRequest bool `mapstructure:"disable_request"` // Suppress per-request structured logs (default false)
ProxyLogFile string `mapstructure:"proxy_log_file"` // Proxy debug log filename under `dir` (default "proxy.log")
File FileLogging `mapstructure:"file"` // Application log file configuration
}
LoggingConfig controls request and event logging behavior.
type ProviderConfig ¶
type ProviderConfig struct {
UpstreamURL string `mapstructure:"upstream_url" json:"upstream_url"`
APIKeyEnv string `mapstructure:"api_key_env" json:"api_key_env"`
BaseURLEnv string `mapstructure:"base_url_env" json:"base_url_env,omitempty"` // Env var for base URL override (e.g. "OPENAI_BASE_URL")
AuthHeader string `mapstructure:"auth_header" json:"auth_header,omitempty"` // Custom auth header name (default: "Authorization")
AuthScheme string `mapstructure:"auth_scheme" json:"auth_scheme,omitempty"` // "bearer" (default), "header" (raw value in auth_header), "query" (appended as ?key=)
Headers map[string]string `mapstructure:"headers" json:"headers,omitempty"` // Extra headers sent with every request
Models []string `mapstructure:"models" json:"models,omitempty"` // Known model prefixes (informational)
ChatPath string `mapstructure:"chat_path" json:"chat_path,omitempty"` // Override chat completions path (default: /v1/chat/completions)
}
ProviderConfig defines a known upstream AI provider. Policies reference providers by name instead of repeating connection details.
type RedisConfig ¶
type RemoteConfig ¶
type RemoteConfig struct {
URL string `mapstructure:"url"` // Central server URL (e.g. http://config-server:9090)
APIKey string `mapstructure:"api_key"` // Shared API key for authentication
SyncSec int `mapstructure:"sync"` // Sync interval in seconds (0 = startup only)
Insecure bool `mapstructure:"insecure"` // Skip TLS verification
Webhook WebhookReceiver `mapstructure:"webhook"` // Inbound webhook for push-based sync
}
RemoteConfig configures loading tokens and config from a central server.
type SecurityConfig ¶
type ServerConfig ¶
type SessionConfig ¶
type SessionConfig struct {
Backend string `mapstructure:"backend"`
Redis RedisConfig `mapstructure:"redis"`
}
type StorageConfig ¶
type StorageConfig struct {
DBPath string `mapstructure:"db_path"`
}
type WebhookEndpoint ¶
type WebhookEndpoint struct {
URL string `mapstructure:"url"`
Secret string `mapstructure:"secret"` // Shared secret sent as X-Webhook-Secret
SigningKey string `mapstructure:"signing_key"` // HMAC-SHA256 signing key for X-Webhook-Signature
Events []string `mapstructure:"events"` // Event type filter (supports trailing * wildcard); empty = all
TimeoutSec int `mapstructure:"timeout"` // HTTP timeout in seconds (default 10)
Insecure bool `mapstructure:"insecure"` // Skip TLS certificate verification (for self-signed certs)
}
WebhookEndpoint configures a single webhook destination.
type WebhookReceiver ¶
type WebhookReceiver struct {
Enabled bool `mapstructure:"enabled"` // Enable the webhook receiver endpoint
Path string `mapstructure:"path"` // URL path (default: /v1/webhook)
Secret string `mapstructure:"secret"` // Expected X-Webhook-Secret header value
SigningKey string `mapstructure:"signing_key"` // HMAC-SHA256 key for X-Webhook-Signature verification
AutoRegister bool `mapstructure:"auto_register"` // Auto-register this proxy's webhook with the central server on startup
CallbackURL string `mapstructure:"callback_url"` // Webhook callback URL the central server will POST to (required if auto_register is true)
Insecure bool `mapstructure:"insecure"` // Tell the server to skip TLS verification when delivering webhooks to this client
}
WebhookReceiver configures the inbound webhook endpoint on the proxy. The central config server pushes token lifecycle events here to trigger immediate sync instead of waiting for the poll interval.