mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 00:17:34 +08:00
132 lines
5.0 KiB
Go
132 lines
5.0 KiB
Go
package config
|
|
|
|
import "fmt"
|
|
|
|
// Validate returns configuration problems found in cfg.
|
|
// It does not mutate cfg.
|
|
func Validate(cfg *Config) []error {
|
|
if cfg == nil {
|
|
return []error{fmt.Errorf("config is nil")}
|
|
}
|
|
|
|
var errs []error
|
|
|
|
if cfg.Agents.Defaults.Model == "" {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.model is required"))
|
|
}
|
|
if cfg.Agents.Defaults.MaxToolIterations <= 0 {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.max_tool_iterations must be > 0"))
|
|
}
|
|
if cfg.Agents.Defaults.ContextCompaction.Enabled {
|
|
cc := cfg.Agents.Defaults.ContextCompaction
|
|
if cc.TriggerMessages <= 0 {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.trigger_messages must be > 0 when enabled=true"))
|
|
}
|
|
if cc.KeepRecentMessages <= 0 {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.keep_recent_messages must be > 0 when enabled=true"))
|
|
}
|
|
if cc.TriggerMessages > 0 && cc.KeepRecentMessages >= cc.TriggerMessages {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.keep_recent_messages must be < trigger_messages"))
|
|
}
|
|
if cc.MaxSummaryChars <= 0 {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.max_summary_chars must be > 0 when enabled=true"))
|
|
}
|
|
if cc.MaxTranscriptChars <= 0 {
|
|
errs = append(errs, fmt.Errorf("agents.defaults.context_compaction.max_transcript_chars must be > 0 when enabled=true"))
|
|
}
|
|
}
|
|
|
|
if cfg.Providers.Proxy.APIBase == "" {
|
|
errs = append(errs, fmt.Errorf("providers.proxy.api_base is required"))
|
|
}
|
|
if cfg.Providers.Proxy.TimeoutSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("providers.proxy.timeout_sec must be > 0"))
|
|
}
|
|
|
|
if cfg.Gateway.Port <= 0 || cfg.Gateway.Port > 65535 {
|
|
errs = append(errs, fmt.Errorf("gateway.port must be in 1..65535"))
|
|
}
|
|
if cfg.Cron.MinSleepSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("cron.min_sleep_sec must be > 0"))
|
|
}
|
|
if cfg.Cron.MaxSleepSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("cron.max_sleep_sec must be > 0"))
|
|
}
|
|
if cfg.Cron.MinSleepSec > cfg.Cron.MaxSleepSec {
|
|
errs = append(errs, fmt.Errorf("cron.min_sleep_sec must be <= cron.max_sleep_sec"))
|
|
}
|
|
if cfg.Cron.RetryBackoffBaseSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("cron.retry_backoff_base_sec must be > 0"))
|
|
}
|
|
if cfg.Cron.RetryBackoffMaxSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("cron.retry_backoff_max_sec must be > 0"))
|
|
}
|
|
if cfg.Cron.RetryBackoffBaseSec > cfg.Cron.RetryBackoffMaxSec {
|
|
errs = append(errs, fmt.Errorf("cron.retry_backoff_base_sec must be <= cron.retry_backoff_max_sec"))
|
|
}
|
|
if cfg.Cron.MaxConsecutiveFailureRetries < 0 {
|
|
errs = append(errs, fmt.Errorf("cron.max_consecutive_failure_retries must be >= 0"))
|
|
}
|
|
if cfg.Cron.MaxWorkers <= 0 {
|
|
errs = append(errs, fmt.Errorf("cron.max_workers must be > 0"))
|
|
}
|
|
|
|
if cfg.Logging.Enabled {
|
|
if cfg.Logging.Dir == "" {
|
|
errs = append(errs, fmt.Errorf("logging.dir is required when logging.enabled=true"))
|
|
}
|
|
if cfg.Logging.Filename == "" {
|
|
errs = append(errs, fmt.Errorf("logging.filename is required when logging.enabled=true"))
|
|
}
|
|
if cfg.Logging.MaxSizeMB <= 0 {
|
|
errs = append(errs, fmt.Errorf("logging.max_size_mb must be > 0"))
|
|
}
|
|
if cfg.Logging.RetentionDays <= 0 {
|
|
errs = append(errs, fmt.Errorf("logging.retention_days must be > 0"))
|
|
}
|
|
}
|
|
|
|
if cfg.Sentinel.Enabled && cfg.Sentinel.IntervalSec <= 0 {
|
|
errs = append(errs, fmt.Errorf("sentinel.interval_sec must be > 0 when sentinel.enabled=true"))
|
|
}
|
|
if cfg.Memory.RecentDays <= 0 {
|
|
errs = append(errs, fmt.Errorf("memory.recent_days must be > 0"))
|
|
}
|
|
|
|
if cfg.Channels.Telegram.Enabled && cfg.Channels.Telegram.Token == "" {
|
|
errs = append(errs, fmt.Errorf("channels.telegram.token is required when channels.telegram.enabled=true"))
|
|
}
|
|
if cfg.Channels.Discord.Enabled && cfg.Channels.Discord.Token == "" {
|
|
errs = append(errs, fmt.Errorf("channels.discord.token is required when channels.discord.enabled=true"))
|
|
}
|
|
if cfg.Channels.WhatsApp.Enabled && cfg.Channels.WhatsApp.BridgeURL == "" {
|
|
errs = append(errs, fmt.Errorf("channels.whatsapp.bridge_url is required when channels.whatsapp.enabled=true"))
|
|
}
|
|
if cfg.Channels.DingTalk.Enabled {
|
|
if cfg.Channels.DingTalk.ClientID == "" {
|
|
errs = append(errs, fmt.Errorf("channels.dingtalk.client_id is required when channels.dingtalk.enabled=true"))
|
|
}
|
|
if cfg.Channels.DingTalk.ClientSecret == "" {
|
|
errs = append(errs, fmt.Errorf("channels.dingtalk.client_secret is required when channels.dingtalk.enabled=true"))
|
|
}
|
|
}
|
|
if cfg.Channels.Feishu.Enabled {
|
|
if cfg.Channels.Feishu.AppID == "" {
|
|
errs = append(errs, fmt.Errorf("channels.feishu.app_id is required when channels.feishu.enabled=true"))
|
|
}
|
|
if cfg.Channels.Feishu.AppSecret == "" {
|
|
errs = append(errs, fmt.Errorf("channels.feishu.app_secret is required when channels.feishu.enabled=true"))
|
|
}
|
|
}
|
|
if cfg.Channels.QQ.Enabled {
|
|
if cfg.Channels.QQ.AppID == "" {
|
|
errs = append(errs, fmt.Errorf("channels.qq.app_id is required when channels.qq.enabled=true"))
|
|
}
|
|
if cfg.Channels.QQ.AppSecret == "" {
|
|
errs = append(errs, fmt.Errorf("channels.qq.app_secret is required when channels.qq.enabled=true"))
|
|
}
|
|
}
|
|
|
|
return errs
|
|
}
|