config

package
v0.4.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultMagicHome = "~/.magic"
	ConfigFileName   = "config.json"
)

Variables

View Source
var ErrNoConfig = fmt.Errorf("config file not found")

ErrNoConfig indicates that no config file exists (first run).

Functions

func CreateProvider added in v0.3.0

func CreateProvider(cfg *Config) (provider.Provider, error)

CreateProvider creates a provider.Provider from the given Config. It uses cfg.Provider as the provider name and looks up cfg.Providers[cfg.Provider] for API key, base URL, and model overrides. Returns an error if the provider is unknown or not configured.

func GetConfigDir added in v0.2.0

func GetConfigDir() string

GetConfigDir returns the configuration directory path.

Types

type Config

type Config struct {
	Profile       string                    `json:"profile"`
	MagicHome     string                    `json:"magic_home"`
	WorkingDir    string                    `json:"working_dir,omitempty"`
	Provider      string                    `json:"provider"`
	Model         string                    `json:"model"`
	Providers     map[string]ProviderConfig `json:"providers"`
	Tools         ToolsConfig               `json:"tools"`
	Memory        MemoryConfig              `json:"memory"`
	Gateway       GatewayConfig             `json:"gateway"`
	CortexEnabled bool                      `json:"cortex_enabled,omitempty"`
	MCP           *MCPConfig                `json:"mcp,omitempty"`
	SubAgent      *SubAgentConfig           `json:"subagent,omitempty"`
	Voice         *VoiceConfig              `json:"voice,omitempty"`
	Privacy       *privacy.Config           `json:"privacy,omitempty"`
	Display       DisplayConfig             `json:"display,omitempty"`
	// Agent settings
	SecretRedaction bool   `json:"secret_redaction,omitempty"`
	Mode            string `json:"mode,omitempty"` // chat, plan, act
	Agent           struct {
		GoalMaxTurns int `json:"goal_max_turns"`
	} `json:"agent,omitempty"`
}

Config represents the application configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration (exported version)

func Load

func Load() (*Config, error)

func (*Config) Save

func (c *Config) Save() error

Save saves the configuration to disk. It uses a safe write approach to avoid data loss: 1. First reads existing config from disk to preserve any fields not in memory 2. Merges in-memory changes on top 3. Writes result to a temp file, then renames

type DisplayConfig added in v0.2.0

type DisplayConfig struct {
	Skin        string `json:"skin,omitempty"`         // Active skin name
	NoColor     bool   `json:"no_color,omitempty"`     // Disable colors
	ShowBanner  bool   `json:"show_banner,omitempty"`  // Show startup banner
	ShowVersion bool   `json:"show_version,omitempty"` // Show version info
}

DisplayConfig represents display/UI configuration

type GatewayConfig

type GatewayConfig struct {
	Enabled   bool                      `json:"enabled"`
	Platforms map[string]PlatformConfig `json:"platforms"`
}

GatewayConfig represents gateway configuration

type MCPConfig

type MCPConfig struct {
	Servers map[string]mcp.ServerConfig `json:"servers,omitempty"`
}

MCPConfig represents MCP server configuration

type MemoryConfig added in v0.3.0

type MemoryConfig struct {
	Enabled bool `json:"enabled"`
}

MemoryConfig represents memory configuration

type PlatformConfig

type PlatformConfig struct {
	Token   string `json:"token,omitempty"`
	Enabled bool   `json:"enabled"`
	// Channel allowlist/blocklist - only respond to messages from allowed channels
	AllowedChannels []string `json:"allowed_channels,omitempty"` // Whitelist of channel/chat IDs; empty means allow all
	BlockedChannels []string `json:"blocked_channels,omitempty"` // Blacklist of channel/chat IDs; takes precedence over whitelist
	// WeCom fields
	CorpID  string `json:"corp_id,omitempty"`
	AgentID string `json:"agent_id,omitempty"`
	Secret  string `json:"secret,omitempty"`
	// QQ fields
	Number   string `json:"number,omitempty"`
	Password string `json:"password,omitempty"`
	// DingTalk fields
	AppKey    string `json:"app_key,omitempty"`
	AppSecret string `json:"app_secret,omitempty"`
	// Feishu/Lark fields
	AppID  string `json:"app_id,omitempty"`
	APIURL string `json:"api_url,omitempty"`
	APIKey string `json:"api_key,omitempty"`
	// WhatsApp fields
	VerifyToken string `json:"verify_token,omitempty"`
	Mode        string `json:"mode,omitempty"` // WhatsApp: "personal" (QR login, default) or "business" (API)
	// WeCom fields: Mode = "qr" (QR code login, default) or "app" (API callback mode)
	// WeChat fields: Mode = "qr" (QR code login, default) or "callback" (webhook mode)
	// WeChat ClawBot fields
	AESKey string `json:"aes_key,omitempty"`
	// WeChat ClawBot fields
	ClientID  string `json:"client_id,omitempty"`
	DataDir   string `json:"data_dir,omitempty"`
	AutoLogin bool   `json:"auto_login,omitempty"`
}

PlatformConfig represents platform-specific configuration

type ProviderConfig

type ProviderConfig struct {
	APIKey  string `json:"api_key,omitempty"`
	BaseURL string `json:"base_url,omitempty"`
	Model   string `json:"model,omitempty"`
}

ProviderConfig represents provider configuration Note: api_key uses omitempty to prevent accidentally overwriting with empty value on Save()

type ProviderInfo added in v0.3.0

type ProviderInfo struct {
	Name         string   `json:"name"`
	DisplayName  string   `json:"display_name"`
	Description  string   `json:"description"`
	Models       []string `json:"models"`
	NeedsAPIKey  bool     `json:"needs_api_key"`
	NeedsBaseURL bool     `json:"needs_base_url"`
}

ProviderInfo contains metadata about a supported provider.

func ListProviders added in v0.3.0

func ListProviders() []ProviderInfo

ListProviders returns all supported providers with their metadata.

type SubAgentConfig

type SubAgentConfig struct {
	MaxConcurrent int           `json:"max_concurrent"`
	MaxDepth      int           `json:"max_depth"`
	Timeout       time.Duration `json:"timeout"`
}

SubAgentConfig represents subagent configuration

func DefaultSubAgentConfig

func DefaultSubAgentConfig() *SubAgentConfig

DefaultSubAgentConfig returns default subagent configuration

type ToolsConfig

type ToolsConfig struct {
	Enabled  []string `json:"enabled"`
	Disabled []string `json:"disabled"`
}

ToolsConfig represents tools configuration

type VoiceConfig

type VoiceConfig = voice.VoiceConfig

VoiceConfig represents voice configuration (alias for voice.VoiceConfig)

Jump to

Keyboard shortcuts

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