config

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config handles application configuration loading and validation.

Index

Constants

View Source
const DefaultContextMargin = 8192

Variables

This section is empty.

Functions

func ResolveConfigPath

func ResolveConfigPath() string

ResolveConfigPath determines which config file to load.

func SupportsTools added in v0.3.5

func SupportsTools(model ModelConfig) bool

func WatchConfig

func WatchConfig(ctx context.Context, atomic *AtomicConfig) error

WatchConfig monitors the config file for changes and reloads it automatically. It watches the directory containing the config file (not the file itself) to handle editors that save by renaming/creating a new file. It also listens for SIGHUP to allow manual reload triggers on Unix systems.

Types

type AWSBedrockConfig added in v0.3.6

type AWSBedrockConfig struct {
	BaseURL            string   `json:"base_url"`
	AnthropicBaseURL   string   `json:"anthropic_base_url,omitempty"`
	APIKey             string   `json:"api_key,omitempty"`
	APIKeys            []string `json:"api_keys,omitempty"`
	ProjectID          string   `json:"project_id,omitempty"`
	WireFormat         string   `json:"wire_format,omitempty"` // "openai" (default), "anthropic"
	TimeoutMs          int      `json:"timeout_ms"`
	StreamTimeoutMs    int      `json:"stream_timeout_ms"`
	StreamingTimeoutMs int      `json:"streaming_timeout_ms,omitempty"`
}

AWSBedrockConfig holds the upstream AWS Bedrock Mantle API settings.

func (*AWSBedrockConfig) EffectiveAPIKeys added in v0.4.4

func (c *AWSBedrockConfig) EffectiveAPIKeys() []string

EffectiveAPIKeys returns the pool of API keys for AWS Bedrock. APIKeys takes precedence; falls back to the single APIKey field.

type AtomicConfig

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

AtomicConfig provides thread-safe access to the configuration with support for hot reloading. It uses atomic.Pointer for lock-free reads.

func NewAtomicConfig

func NewAtomicConfig(cfg *Config, path string) *AtomicConfig

NewAtomicConfig creates a new AtomicConfig with the given initial config and file path.

func (*AtomicConfig) Get

func (a *AtomicConfig) Get() *Config

Get returns the current configuration pointer. This is safe for concurrent use. Callers must not modify the returned Config.

func (*AtomicConfig) OnReload

func (a *AtomicConfig) OnReload(fn func(*Config))

OnReload registers a callback that will be invoked after each successful reload.

func (*AtomicConfig) Path

func (a *AtomicConfig) Path() string

Path returns the config file path being watched.

func (*AtomicConfig) Reload

func (a *AtomicConfig) Reload() error

Reload reloads the configuration from disk and atomically swaps it in. If the reload fails, the old configuration is preserved and an error is returned. On successful reload, all registered callbacks are invoked.

type Config

type Config struct {
	APIKey                         string                   `json:"api_key"`
	APIKeys                        []string                 `json:"api_keys"`
	Host                           string                   `json:"host"`
	Port                           int                      `json:"port"`
	HotReload                      bool                     `json:"hot_reload"`
	EnableStreamingScenarioRouting bool                     `json:"enable_streaming_scenario_routing"`
	RespectRequestedModel          *bool                    `json:"respect_requested_model,omitempty"`
	Models                         map[string]ModelConfig   `json:"models"`
	Fallbacks                      map[string][]ModelConfig `json:"fallbacks"`
	ModelOverrides                 map[string]ModelConfig   `json:"model_overrides"`
	AWSBedrock                     AWSBedrockConfig         `json:"aws_bedrock"`
	OpenCodeGo                     OpenCodeGoConfig         `json:"opencode_go"`
	OpenCodeZen                    OpenCodeZenConfig        `json:"opencode_zen"`
	Logging                        LoggingConfig            `json:"logging"`
	Debug                          DebugConfig              `json:"debug"`
}

Config holds the complete application configuration.

func Load

func Load() (*Config, error)

Load reads configuration from a JSON file and applies environment variable overrides. Config path resolution:

  1. ROUTATIC_PROXY_CONFIG env var (explicit override)
  2. OC_GO_CC_CONFIG env var (legacy explicit override)
  3. ~/.config/routatic-proxy/config.json (default)
  4. ~/.config/oc-go-cc/config.json (legacy fallback when the new path is absent)

func LoadFromPath

func LoadFromPath(path string) (*Config, error)

LoadFromPath reads configuration from the given JSON file path.

func (*Config) EffectiveAPIKeys

func (c *Config) EffectiveAPIKeys() []string

EffectiveAPIKeys returns the pool of API keys for rotation. APIKeys takes precedence; falls back to the single APIKey field.

type DebugCapture added in v0.4.0

type DebugCapture struct {
	Enabled       bool     `json:"enabled"`
	Directory     string   `json:"directory"`
	MaxFiles      int      `json:"max_files"`
	MaxFileSize   int64    `json:"max_file_size"`
	CapturePhases []string `json:"capture_phases,omitempty"`
	RedactAPIKeys bool     `json:"redact_api_keys"`
}

DebugCapture controls request/response capture for debugging.

type DebugConfig added in v0.4.0

type DebugConfig struct {
	CaptureEnabled bool   `json:"capture_enabled"`
	CaptureDir     string `json:"capture_dir"`
}

DebugConfig holds debug-related configuration.

type LoggingConfig

type LoggingConfig struct {
	Level        string        `json:"level"`
	Requests     bool          `json:"requests"`
	DebugCapture *DebugCapture `json:"debug_capture,omitempty"`
}

LoggingConfig controls application logging behavior.

func (*LoggingConfig) EffectiveDebugCapture added in v0.4.0

func (lc *LoggingConfig) EffectiveDebugCapture() DebugCapture

EffectiveDebugCapture returns the debug capture configuration with defaults applied. Returns zero value DebugCapture if nil.

type ModelConfig

type ModelConfig struct {
	Provider               string          `json:"provider"`
	ModelID                string          `json:"model_id"`
	WireFormat             string          `json:"wire_format,omitempty"` // "auto" (default), "openai", "anthropic", "responses", "gemini"
	Temperature            float64         `json:"temperature"`
	MaxTokens              int             `json:"max_tokens"`
	MaxOutputTokens        int             `json:"max_output_tokens,omitempty"`
	ContextWindow          int             `json:"context_window,omitempty"`
	ContextMargin          int             `json:"context_margin,omitempty"`
	ContextThreshold       int             `json:"context_threshold"`
	SupportsTools          *bool           `json:"supports_tools,omitempty"`
	ReasoningEffort        string          `json:"reasoning_effort"`
	Thinking               json.RawMessage `json:"thinking,omitempty"`
	Vision                 bool            `json:"vision"`
	AnthropicToolsDisabled bool            `json:"anthropic_tools_disabled"`
}

ModelConfig defines routing rules for a specific model.

func ResolveModelConfig added in v0.3.5

func ResolveModelConfig(model ModelConfig) ModelConfig

type ModelMetadata added in v0.3.5

type ModelMetadata struct {
	ContextWindow   int
	MaxOutputTokens int
	Vision          bool
	SupportsTools   bool
}

type OpenCodeGoConfig

type OpenCodeGoConfig struct {
	BaseURL            string   `json:"base_url"`
	AnthropicBaseURL   string   `json:"anthropic_base_url"`
	APIKey             string   `json:"api_key,omitempty"`
	APIKeys            []string `json:"api_keys,omitempty"`
	TimeoutMs          int      `json:"timeout_ms"`
	StreamTimeoutMs    int      `json:"stream_timeout_ms"`
	StreamingTimeoutMs int      `json:"streaming_timeout_ms,omitempty"`
}

OpenCodeGoConfig holds the upstream OpenCode Go API settings.

func (*OpenCodeGoConfig) EffectiveAPIKeys added in v0.4.4

func (c *OpenCodeGoConfig) EffectiveAPIKeys() []string

EffectiveAPIKeys returns the pool of API keys for OpenCode Go. APIKeys takes precedence; falls back to the single APIKey field.

type OpenCodeZenConfig

type OpenCodeZenConfig struct {
	BaseURL            string   `json:"base_url"`
	AnthropicBaseURL   string   `json:"anthropic_base_url"`
	ResponsesBaseURL   string   `json:"responses_base_url"`
	GeminiBaseURL      string   `json:"gemini_base_url"`
	APIKey             string   `json:"api_key,omitempty"`
	APIKeys            []string `json:"api_keys,omitempty"`
	TimeoutMs          int      `json:"timeout_ms"`
	StreamTimeoutMs    int      `json:"stream_timeout_ms"`
	StreamingTimeoutMs int      `json:"streaming_timeout_ms,omitempty"`
}

OpenCodeZenConfig holds the upstream OpenCode Zen API settings.

func (*OpenCodeZenConfig) EffectiveAPIKeys added in v0.4.4

func (c *OpenCodeZenConfig) EffectiveAPIKeys() []string

EffectiveAPIKeys returns the pool of API keys for OpenCode Zen. APIKeys takes precedence; falls back to the single APIKey field.

Jump to

Keyboard shortcuts

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