package plugin import ( "fmt" "strings" "gopkg.in/yaml.v3" ) type Config struct { Enabled bool `yaml:"enabled"` CodexOnly bool `yaml:"codex_only"` DatabasePath string `yaml:"database_path"` BootstrapName string `yaml:"bootstrap_name"` BootstrapKey string `yaml:"bootstrap_key"` } func defaultConfig() Config { return Config{ Enabled: true, CodexOnly: true, DatabasePath: "data/cpa-ext.db", BootstrapName: "default", BootstrapKey: "000000", } } func decodeConfig(raw []byte) (Config, error) { cfg := defaultConfig() if len(raw) == 0 { return cfg, nil } if err := yaml.Unmarshal(raw, &cfg); err != nil { return Config{}, fmt.Errorf("解析插件配置: %w", err) } if strings.TrimSpace(cfg.DatabasePath) == "" { return Config{}, fmt.Errorf("database_path 不能为空") } if strings.TrimSpace(cfg.BootstrapName) == "" || strings.TrimSpace(cfg.BootstrapKey) == "" { return Config{}, fmt.Errorf("bootstrap_name 和 bootstrap_key 不能为空") } return cfg, nil } func (c Config) accepts(record UsageRecord) bool { if !c.Enabled { return false } if !c.CodexOnly { return true } provider := strings.ToLower(strings.TrimSpace(record.Provider)) model := strings.ToLower(strings.TrimSpace(record.Model)) return provider == "codex" || strings.Contains(model, "codex") || strings.HasPrefix(model, "gpt-") }