config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config handles configuration loading and management.

Index

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

func ProjectConfigPath(projectRoot string) string

ProjectConfigPath returns the project config file path.

func Save

func Save(cfg *Config, path string) error

Save saves configuration to a file.

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 Defaults

func Defaults() *Config

Defaults returns the default configuration.

func Load

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

Load loads configuration from a file, interpolating ${VAR} references.

func LoadRaw

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

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

func LoadWithOverride(projectRoot string) (*Config, string, error)

LoadWithOverride loads project config if exists, otherwise global.

func (*Config) GetActiveRoutes

func (cfg *Config) GetActiveRoutes(profileName string) map[string]string

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

func (cfg *Config) GetDefaultProfile() string

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

func (cfg *Config) GetProfileNames() []string

GetProfileNames returns a sorted list of profile names.

func (*Config) HasProfiles

func (cfg *Config) HasProfiles() bool

HasProfiles returns true if profiles are configured.

type LogLevel

type LogLevel int

LogLevel represents the severity level for logging.

const (
	// LevelDebug is the lowest level, most verbose logging.
	LevelDebug LogLevel = iota
	// LevelInfo is the default level for general information.
	LevelInfo
	// LevelWarn is for warning messages.
	LevelWarn
	// LevelError is for error messages only, least verbose.
	LevelError
)

func ParseLogLevel

func ParseLogLevel(s string) LogLevel

ParseLogLevel parses a string into a LogLevel. The comparison is case-insensitive. Empty or invalid strings default to LevelInfo.

func (LogLevel) ShouldLog

func (l LogLevel) ShouldLog(msgLevel LogLevel) bool

ShouldLog returns true if the given message level should be logged based on the current log level. Messages with a level equal to or higher than the current level will be logged.

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the LogLevel.

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

type RouteTarget struct {
	Provider string
	Model    string
}

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

type ServerConfig struct {
	Port int    `json:"port"`
	Host string `json:"host"`
}

ServerConfig represents server configuration.

Jump to

Keyboard shortcuts

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