config

package
v6.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config provides configuration management for the CLI Proxy API server. It handles loading and parsing YAML configuration files, and provides structured access to application settings including server port, authentication directory, debug settings, proxy configuration, and API keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveConfigPreserveComments

func SaveConfigPreserveComments(configFile string, cfg *Config) error

SaveConfigPreserveComments writes the config back to YAML while preserving existing comments and key ordering by loading the original file into a yaml.Node tree and updating values in-place.

func SaveConfigPreserveCommentsUpdateNestedScalar

func SaveConfigPreserveCommentsUpdateNestedScalar(configFile string, path []string, value string) error

SaveConfigPreserveCommentsUpdateNestedScalar updates a nested scalar key path like ["a","b"] while preserving comments and positions.

Types

type ClaudeKey

type ClaudeKey struct {
	// APIKey is the authentication key for accessing Claude API services.
	APIKey string `yaml:"api-key" json:"api-key"`

	// BaseURL is the base URL for the Claude API endpoint.
	// If empty, the default Claude API URL will be used.
	BaseURL string `yaml:"base-url" json:"base-url"`
}

ClaudeKey represents the configuration for a Claude API key, including the API key itself and an optional base URL for the API endpoint.

type CodexKey

type CodexKey struct {
	// APIKey is the authentication key for accessing Codex API services.
	APIKey string `yaml:"api-key" json:"api-key"`

	// BaseURL is the base URL for the Codex API endpoint.
	// If empty, the default Codex API URL will be used.
	BaseURL string `yaml:"base-url" json:"base-url"`
}

CodexKey represents the configuration for a Codex API key, including the API key itself and an optional base URL for the API endpoint.

type Config

type Config struct {
	config.SDKConfig `yaml:",inline"`
	// Port is the network port on which the API server will listen.
	Port int `yaml:"port" json:"-"`

	// AuthDir is the directory where authentication token files are stored.
	AuthDir string `yaml:"auth-dir" json:"-"`

	// Debug enables or disables debug-level logging and other debug features.
	Debug bool `yaml:"debug" json:"debug"`

	// LoggingToFile controls whether application logs are written to rotating files or stdout.
	LoggingToFile bool `yaml:"logging-to-file" json:"logging-to-file"`

	// UsageStatisticsEnabled toggles in-memory usage aggregation; when false, usage data is discarded.
	UsageStatisticsEnabled bool `yaml:"usage-statistics-enabled" json:"usage-statistics-enabled"`

	// QuotaExceeded defines the behavior when a quota is exceeded.
	QuotaExceeded QuotaExceeded `yaml:"quota-exceeded" json:"quota-exceeded"`

	// GlAPIKey is the API key for the generative language API.
	GlAPIKey []string `yaml:"generative-language-api-key" json:"generative-language-api-key"`

	// RequestRetry defines the retry times when the request failed.
	RequestRetry int `yaml:"request-retry" json:"request-retry"`

	// ClaudeKey defines a list of Claude API key configurations as specified in the YAML configuration file.
	ClaudeKey []ClaudeKey `yaml:"claude-api-key" json:"claude-api-key"`

	// Codex defines a list of Codex API key configurations as specified in the YAML configuration file.
	CodexKey []CodexKey `yaml:"codex-api-key" json:"codex-api-key"`

	// OpenAICompatibility defines OpenAI API compatibility configurations for external providers.
	OpenAICompatibility []OpenAICompatibility `yaml:"openai-compatibility" json:"openai-compatibility"`

	// RemoteManagement nests management-related options under 'remote-management'.
	RemoteManagement RemoteManagement `yaml:"remote-management" json:"-"`

	// GeminiWeb groups configuration for Gemini Web client
	GeminiWeb GeminiWebConfig `yaml:"gemini-web" json:"gemini-web"`
}

Config represents the application's configuration, loaded from a YAML file.

func LoadConfig

func LoadConfig(configFile string) (*Config, error)

LoadConfig reads a YAML configuration file from the given path, unmarshals it into a Config struct, applies environment variable overrides, and returns it.

Parameters:

  • configFile: The path to the YAML configuration file

Returns:

  • *Config: The loaded configuration
  • error: An error if the configuration could not be loaded

type GeminiWebConfig

type GeminiWebConfig struct {
	// Context enables JSON-based conversation reuse.
	// Defaults to true if not set in YAML (see LoadConfig).
	Context bool `yaml:"context" json:"context"`

	// CodeMode, when true, enables coding mode behaviors for Gemini Web:
	// - Attach the predefined "Coding partner" Gem
	// - Enable XML wrapping hint for tool markup
	// - Merge <think> content into visible content for tool-friendly output
	CodeMode bool `yaml:"code-mode" json:"code-mode"`

	// MaxCharsPerRequest caps the number of characters (runes) sent to
	// Gemini Web in a single request. Long prompts will be split into
	// multiple requests with a continuation hint, and only the final
	// request will carry any files. When unset or <=0, a conservative
	// default of 1,000,000 will be used.
	MaxCharsPerRequest int `yaml:"max-chars-per-request" json:"max-chars-per-request"`

	// DisableContinuationHint, when true, disables the continuation hint for split prompts.
	// The hint is enabled by default.
	DisableContinuationHint bool `yaml:"disable-continuation-hint,omitempty" json:"disable-continuation-hint,omitempty"`
}

GeminiWebConfig nests Gemini Web related options under 'gemini-web'.

type OpenAICompatibility

type OpenAICompatibility struct {
	// Name is the identifier for this OpenAI compatibility configuration.
	Name string `yaml:"name" json:"name"`

	// BaseURL is the base URL for the external OpenAI-compatible API endpoint.
	BaseURL string `yaml:"base-url" json:"base-url"`

	// APIKeys are the authentication keys for accessing the external API services.
	APIKeys []string `yaml:"api-keys" json:"api-keys"`

	// Models defines the model configurations including aliases for routing.
	Models []OpenAICompatibilityModel `yaml:"models" json:"models"`
}

OpenAICompatibility represents the configuration for OpenAI API compatibility with external providers, allowing model aliases to be routed through OpenAI API format.

type OpenAICompatibilityModel

type OpenAICompatibilityModel struct {
	// Name is the actual model name used by the external provider.
	Name string `yaml:"name" json:"name"`

	// Alias is the model name alias that clients will use to reference this model.
	Alias string `yaml:"alias" json:"alias"`
}

OpenAICompatibilityModel represents a model configuration for OpenAI compatibility, including the actual model name and its alias for API routing.

type QuotaExceeded

type QuotaExceeded struct {
	// SwitchProject indicates whether to automatically switch to another project when a quota is exceeded.
	SwitchProject bool `yaml:"switch-project" json:"switch-project"`

	// SwitchPreviewModel indicates whether to automatically switch to a preview model when a quota is exceeded.
	SwitchPreviewModel bool `yaml:"switch-preview-model" json:"switch-preview-model"`
}

QuotaExceeded defines the behavior when API quota limits are exceeded. It provides configuration options for automatic failover mechanisms.

type RemoteManagement

type RemoteManagement struct {
	// AllowRemote toggles remote (non-localhost) access to management API.
	AllowRemote bool `yaml:"allow-remote"`
	// SecretKey is the management key (plaintext or bcrypt hashed). YAML key intentionally 'secret-key'.
	SecretKey string `yaml:"secret-key"`
}

RemoteManagement holds management API configuration under 'remote-management'.

Jump to

Keyboard shortcuts

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