config

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 11 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. Uses GO_MAGIC_HOME environment variable if set, otherwise ~/.magic.

func GetMagicHome added in v0.4.20

func GetMagicHome() string

Types

type AgentPluginsConfig added in v0.5.5

type AgentPluginsConfig struct {
	Disabled []string `json:"disabled"`
}

AgentPluginsConfig 管理 OpenAI Agent Plugins 1.0.0 插件的禁用列表。 启用为默认状态,仅记录被显式禁用的插件名(即 plugin.json 的 name 字段)。

type ApprovalConfig added in v0.4.12

type ApprovalConfig struct {
	Strategy         string `json:"strategy"`           // "smart", "manual", "auto"
	TrustThreshold   int    `json:"trust_threshold"`    // Auto-approve after N trusted uses
	EnableLearning   bool   `json:"enable_learning"`    // Learn from user decisions
	EnableCLIConfirm bool   `json:"enable_cli_confirm"` // Enable CLI confirmation prompt
	ApprovalTimeout  int    `json:"approval_timeout"`   // Approval timeout in seconds
}

ApprovalConfig represents command approval system configuration

func DefaultApprovalConfig added in v0.4.12

func DefaultApprovalConfig() *ApprovalConfig

DefaultApprovalConfig returns default approval configuration

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"` // Deprecated: Use Providers[].Models[0] instead
	Providers    map[string]ProviderConfig `json:"providers"`
	Tools        ToolsConfig               `json:"tools"`
	Skills       SkillsConfig              `json:"skills"`
	Plugins      PluginsConfig             `json:"plugins"`
	AgentPlugins AgentPluginsConfig        `json:"agent_plugins"`
	Memory       MemoryConfig              `json:"memory"`
	Gateway      GatewayConfig             `json:"gateway"`
	Cortex       CortexConfig              `json:"cortex"`
	MCP          *MCPConfig                `json:"mcp,omitempty"`
	SubAgent     *SubAgentConfig           `json:"subagent,omitempty"`
	Voice        *VoiceConfig              `json:"voice,omitempty"`
	// Privacy / PII 脱敏配置,统一存储于 config.json(团队约定:一个配置管所有)。
	Privacy *privacy.Config `json:"privacy,omitempty"`
	Display DisplayConfig   `json:"display,omitempty"`
	Server  ServerConfig    `json:"server,omitempty"`
	// Agent settings
	SecretRedaction bool   `json:"secret_redaction,omitempty"`
	Mode            string `json:"mode,omitempty"`      // chat, plan, act
	ChatMode        string `json:"chat_mode,omitempty"` // chat, coding - default mode for magic chat
	AutoLinkGoals   bool   `json:"auto_link_goals"`     // Auto-link new sessions to active goals (must save false value)
	Agent           struct {
		GoalMaxTurns int `json:"goal_max_turns"`
	} `json:"agent,omitempty"`
	// Approval settings
	Approval *ApprovalConfig `json:"approval,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) GetCurrentModel added in v0.4.14

func (c *Config) GetCurrentModel() string

GetCurrentModel returns the current model from the configured provider's Models array

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 CortexConfig added in v0.4.16

type CortexConfig struct {
	Enabled             bool `json:"enabled"`                // Enable/disable Cortex system
	SkillMinPatternFreq int  `json:"skill_min_pattern_freq"` // Min frequency for skill pattern detection
}

CortexConfig represents Cortex AI configuration

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 PluginsConfig added in v0.4.10

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

PluginsConfig represents plugins configuration

type ProviderConfig

type ProviderConfig struct {
	APIKey  string   `json:"api_key,omitempty"`
	BaseURL string   `json:"base_url,omitempty"`
	Model   string   `json:"model,omitempty"`  // Deprecated: use Models[0] instead, kept for backward compatibility
	Models  []string `json:"models,omitempty"` // List of supported models, first element is current model
}

ProviderConfig represents provider configuration Note: api_key uses omitempty to prevent accidentally overwriting with empty value on Save() Model is deprecated, use Models[0] as current model instead

func (*ProviderConfig) GetCurrentModel added in v0.4.14

func (p *ProviderConfig) GetCurrentModel() string

GetCurrentModel returns the current model (first element of Models, fallback to Model field)

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 ServerConfig added in v0.4.19

type ServerConfig struct {
	UploadURLPrefix string `json:"upload_url_prefix,omitempty"` // Public URL prefix for uploaded files (e.g., "https://your-domain.com/uploads")
	FileStrategy    string `json:"file_strategy,omitempty"`     // "auto" (default), "url", "base64"
}

ServerConfig represents server-related configuration

func (*ServerConfig) GetFileStrategy added in v0.4.19

func (s *ServerConfig) GetFileStrategy() string

GetFileStrategy returns the file strategy, defaulting to "auto"

type SkillsConfig added in v0.4.10

type SkillsConfig struct {
	Enabled    []string `json:"enabled"`
	Disabled   []string `json:"disabled"`
	DefaultDir string   `json:"default_dir,omitempty"` // Path to built-in default skills
	UserDir    string   `json:"user_dir,omitempty"`    // Path to user-installed skills
}

SkillsConfig represents skills configuration

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