Documentation
¶
Overview ¶
Package config handles configuration loading and management.
Index ¶
- func GlobalConfigPath() string
- func ProjectConfigPath(projectRoot string) string
- func Save(cfg *Config, path string) error
- type CompactionConfig
- type Config
- type LogLevel
- type LoggingConfig
- func (lc *LoggingConfig) GetLevel() LogLevel
- func (lc *LoggingConfig) GetLogPath() (string, error)
- func (lc *LoggingConfig) GetLogPathWithInstance(instanceID string) (string, error)
- func (lc *LoggingConfig) GetLogWriter() (io.Writer, error)
- func (lc *LoggingConfig) IsEnabled() bool
- func (lc *LoggingConfig) ShouldLogToConsole() bool
- func (lc *LoggingConfig) ShouldLogToFile() bool
- type ProfileConfig
- type ProviderConfig
- type RouteTarget
- type RouterConfig
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GlobalConfigPath ¶
func GlobalConfigPath() string
GlobalConfigPath returns the global config file path.
func ProjectConfigPath ¶
ProjectConfigPath returns the project config file path.
Types ¶
type CompactionConfig ¶
type CompactionConfig struct {
// Method is "llm" (default) to summarize via LLM, or "trim" to drop oldest messages.
Method string `json:"method,omitempty"`
// SummarizeProvider is the provider name used for summarization (auto-detect if empty).
SummarizeProvider string `json:"summarizeProvider,omitempty"`
// SummarizeModel is the model for summarization (optional, uses provider default).
SummarizeModel string `json:"summarizeModel,omitempty"`
}
CompactionConfig controls how oversized requests are compacted to fit within provider limits.
type Config ¶
type Config struct {
Server ServerConfig `json:"server"`
Providers map[string]ProviderConfig `json:"providers"`
Router RouterConfig `json:"router"`
Logging LoggingConfig `json:"logging,omitempty"`
// Profiles is kept at Config level for backward compatibility when loading old config files.
// It is migrated to Router.Profiles during loading and always nil after that.
Profiles map[string]ProfileConfig `json:"profiles,omitempty"` // Legacy location - migrated to Router.Profiles
}
Config represents the complete configuration.
func LoadRaw ¶
LoadRaw loads configuration from a file without interpolating ${VAR} references. This preserves environment variable placeholders in the in-memory config, so they are not lost when the config is saved back to disk.
func LoadWithOverride ¶
LoadWithOverride loads project config if exists, otherwise global.
func (*Config) GetActiveRoutes ¶
GetActiveRoutes returns the routes to use based on profile name or legacy config. If profiles are configured and profileName is set, returns that profile's routes. Otherwise, falls back to the legacy router.routes for backward compatibility.
func (*Config) GetDefaultProfile ¶
GetDefaultProfile returns the default profile name to use at startup. Returns "default" if it exists, otherwise the first profile alphabetically. Returns "" if no profiles are configured (legacy mode).
func (*Config) GetProfileNames ¶
GetProfileNames returns a sorted list of profile names.
func (*Config) HasProfiles ¶
HasProfiles returns true if profiles are configured.
type LogLevel ¶
type LogLevel int
LogLevel represents the severity level for logging.
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel. The comparison is case-insensitive. Empty or invalid strings default to LevelInfo.
type LoggingConfig ¶
type LoggingConfig struct {
// Enabled controls whether logging is active.
// If false or not specified, logging is disabled.
// Default: false (opt-in only)
Enabled bool `json:"enabled,omitempty"`
// Destination is where logs should be written.
// Valid values: "stdout", "stderr", "file", or a file path.
// If "file", uses the default log file path.
Destination string `json:"destination,omitempty"`
// FilePath is the specific file path when Destination is "file" or a custom path.
// If empty, uses the default: ~/.cc-modelrouter/router.log
FilePath string `json:"filePath,omitempty"`
// Level controls log verbosity.
// Valid values: "debug", "info" (default), "warn", "error".
// - debug: Shows all messages including detailed streaming events
// - info: Shows request/response summaries and warnings
// - warn: Shows only warnings and errors
// - error: Shows only errors
Level string `json:"level,omitempty"`
}
LoggingConfig represents logging configuration.
func (*LoggingConfig) GetLevel ¶
func (lc *LoggingConfig) GetLevel() LogLevel
GetLevel returns the parsed log level, defaulting to LevelInfo.
func (*LoggingConfig) GetLogPath ¶
func (lc *LoggingConfig) GetLogPath() (string, error)
GetLogPath returns the resolved log file path.
func (*LoggingConfig) GetLogPathWithInstance ¶
func (lc *LoggingConfig) GetLogPathWithInstance(instanceID string) (string, error)
GetLogPathWithInstance returns the resolved log file path with an instance ID. The log file will be named <instanceID>.log in the logs directory.
func (*LoggingConfig) GetLogWriter ¶
func (lc *LoggingConfig) GetLogWriter() (io.Writer, error)
GetLogWriter returns the appropriate writer for the log destination.
func (*LoggingConfig) IsEnabled ¶
func (lc *LoggingConfig) IsEnabled() bool
IsEnabled returns true if logging is explicitly enabled.
func (*LoggingConfig) ShouldLogToConsole ¶
func (lc *LoggingConfig) ShouldLogToConsole() bool
ShouldLogToConsole returns true if logs should go to console.
func (*LoggingConfig) ShouldLogToFile ¶
func (lc *LoggingConfig) ShouldLogToFile() bool
ShouldLogToFile returns true if logs should go to a file.
type ProfileConfig ¶
type ProfileConfig struct {
Name string `json:"name"` // Display name for the profile
Description string `json:"description,omitempty"` // Optional description
Routes map[string]string `json:"routes"` // Route name to provider:model chain
}
ProfileConfig represents a named route profile. Profiles allow users to define multiple route configurations and switch between them during a session without restarting.
type ProviderConfig ¶
type ProviderConfig struct {
APIKey string `json:"apiKey"`
BaseURL string `json:"baseURL"`
Models []string `json:"models"`
Transformer string `json:"transformer,omitempty"`
DisableKeepAlives bool `json:"disableKeepAlives,omitempty"` // Disable HTTP keep-alive for providers with connection issues
// MaxRequestBodyBytes is the maximum request body size in bytes for this provider.
// 0 means no limit. Requests exceeding this limit trigger compaction (if configured)
// or are skipped during failover.
MaxRequestBodyBytes int64 `json:"maxRequestBodyBytes,omitempty"`
Compaction *CompactionConfig `json:"compaction,omitempty"`
}
ProviderConfig represents a provider configuration.
func (*ProviderConfig) Validate ¶
func (pc *ProviderConfig) Validate() error
Validate validates the provider configuration.
type RouteTarget ¶
RouteTarget represents a parsed route target.
func ParseRoute ¶
func ParseRoute(route string) []RouteTarget
ParseRoute parses a route string into targets. Format: "provider1:model1;provider2:model2"
type RouterConfig ¶
type RouterConfig struct {
Routes map[string]string `json:"routes,omitempty"` // Legacy routes (empty when profiles are used)
Profiles map[string]ProfileConfig `json:"profiles,omitempty"` // Named route profiles (new location)
MaxRetries int `json:"maxRetries,omitempty"` // Maximum retries for failover
RetryDelay string `json:"retryDelay,omitempty"` // Delay between retries
}
RouterConfig represents router configuration.
func (*RouterConfig) GetRetryDelay ¶
func (rc *RouterConfig) GetRetryDelay() time.Duration
type ServerConfig ¶
ServerConfig represents server configuration.