Files
cpa-plugin/internal/plugin/config.go
T

41 lines
836 B
Go

package plugin
import (
"fmt"
"strings"
"gopkg.in/yaml.v3"
)
type Config struct {
Enabled bool `yaml:"enabled"`
CodexOnly bool `yaml:"codex_only"`
}
func defaultConfig() Config {
return Config{Enabled: true, CodexOnly: true}
}
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)
}
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-")
}