2026-02-04 11:06:13 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2026-03-27 16:03:34 +00:00
|
|
|
"errors"
|
2026-02-12 05:45:45 +00:00
|
|
|
"fmt"
|
2026-03-25 09:41:50 +00:00
|
|
|
"math/rand"
|
2026-02-04 11:06:13 +00:00
|
|
|
"os"
|
2026-03-11 08:33:01 +00:00
|
|
|
"path/filepath"
|
2026-04-07 13:19:06 +00:00
|
|
|
"strings"
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
"sync/atomic"
|
2026-03-30 06:01:20 +00:00
|
|
|
"time"
|
2026-02-04 11:06:13 +00:00
|
|
|
|
|
|
|
|
"github.com/caarlos0/env/v11"
|
2026-02-26 12:38:11 +00:00
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
"github.com/sipeed/picoclaw/pkg"
|
2026-02-24 15:57:13 +00:00
|
|
|
"github.com/sipeed/picoclaw/pkg/fileutil"
|
2026-03-11 08:33:01 +00:00
|
|
|
"github.com/sipeed/picoclaw/pkg/logger"
|
2026-02-04 11:06:13 +00:00
|
|
|
)
|
|
|
|
|
|
2026-02-20 03:34:52 +00:00
|
|
|
// rrCounter is a global counter for round-robin load balancing across models.
|
|
|
|
|
var rrCounter atomic.Uint64
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
// CurrentVersion is the latest config schema version
|
2026-03-30 06:01:20 +00:00
|
|
|
const CurrentVersion = 2
|
2026-03-11 08:33:01 +00:00
|
|
|
|
|
|
|
|
// Config is the current config structure with version support
|
2026-02-04 11:06:13 +00:00
|
|
|
type Config struct {
|
2026-04-01 14:51:28 +00:00
|
|
|
// Config schema version for migration.
|
|
|
|
|
Version int `json:"version" yaml:"-"`
|
|
|
|
|
Agents AgentsConfig `json:"agents" yaml:"-"`
|
|
|
|
|
Session SessionConfig `json:"session,omitempty" yaml:"-"`
|
|
|
|
|
Channels ChannelsConfig `json:"channels" yaml:"channels"`
|
|
|
|
|
// New model-centric provider configuration.
|
|
|
|
|
ModelList SecureModelList `json:"model_list" yaml:"model_list"`
|
|
|
|
|
Gateway GatewayConfig `json:"gateway" yaml:"-"`
|
|
|
|
|
Hooks HooksConfig `json:"hooks,omitempty" yaml:"-"`
|
|
|
|
|
Tools ToolsConfig `json:"tools" yaml:",inline"`
|
|
|
|
|
Heartbeat HeartbeatConfig `json:"heartbeat" yaml:"-"`
|
|
|
|
|
Devices DevicesConfig `json:"devices" yaml:"-"`
|
|
|
|
|
Voice VoiceConfig `json:"voice" yaml:"-"`
|
2026-03-10 09:42:05 +00:00
|
|
|
// BuildInfo contains build-time version information
|
2026-03-27 16:03:34 +00:00
|
|
|
BuildInfo BuildInfo `json:"build_info,omitempty" yaml:"-"`
|
2026-03-21 17:55:00 +00:00
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
// cache for sensitive values and compiled regex (computed once)
|
|
|
|
|
sensitiveCache *SensitiveDataCache
|
2026-03-10 09:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:55:41 +00:00
|
|
|
// FilterSensitiveData filters sensitive values from content before sending to LLM.
|
|
|
|
|
// This prevents the LLM from seeing its own credentials.
|
|
|
|
|
// Uses strings.Replacer for O(n+m) performance (computed once per SecurityConfig).
|
|
|
|
|
// Short content (below FilterMinLength) is returned unchanged for performance.
|
|
|
|
|
func (c *Config) FilterSensitiveData(content string) string {
|
|
|
|
|
// Check if filtering is enabled (default: true)
|
|
|
|
|
if !c.Tools.IsFilterSensitiveDataEnabled() {
|
|
|
|
|
return content
|
|
|
|
|
}
|
|
|
|
|
// Fast path: skip filtering for short content
|
|
|
|
|
if len(content) < c.Tools.GetFilterMinLength() {
|
|
|
|
|
return content
|
|
|
|
|
}
|
2026-03-27 16:03:34 +00:00
|
|
|
return c.SensitiveDataReplacer().Replace(content)
|
2026-03-23 12:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-22 11:21:58 +00:00
|
|
|
type HooksConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
Defaults HookDefaultsConfig `json:"defaults,omitempty"`
|
|
|
|
|
Builtins map[string]BuiltinHookConfig `json:"builtins,omitempty"`
|
|
|
|
|
Processes map[string]ProcessHookConfig `json:"processes,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HookDefaultsConfig struct {
|
|
|
|
|
ObserverTimeoutMS int `json:"observer_timeout_ms,omitempty"`
|
|
|
|
|
InterceptorTimeoutMS int `json:"interceptor_timeout_ms,omitempty"`
|
|
|
|
|
ApprovalTimeoutMS int `json:"approval_timeout_ms,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BuiltinHookConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
Priority int `json:"priority,omitempty"`
|
|
|
|
|
Config json.RawMessage `json:"config,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ProcessHookConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
Priority int `json:"priority,omitempty"`
|
|
|
|
|
Transport string `json:"transport,omitempty"`
|
|
|
|
|
Command []string `json:"command,omitempty"`
|
|
|
|
|
Dir string `json:"dir,omitempty"`
|
|
|
|
|
Env map[string]string `json:"env,omitempty"`
|
|
|
|
|
Observe []string `json:"observe,omitempty"`
|
|
|
|
|
Intercept []string `json:"intercept,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 09:42:05 +00:00
|
|
|
// BuildInfo contains build-time version information
|
|
|
|
|
type BuildInfo struct {
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
GitCommit string `json:"git_commit"`
|
|
|
|
|
BuildTime string `json:"build_time"`
|
|
|
|
|
GoVersion string `json:"go_version"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
feat(config): add complete model_list template with all 17 providers
- Include all 17 supported providers in default config as templates
- Each entry has model_name, model, api_base, and empty api_key
- Add comments with API key links for each provider
- Keep onboard message simple (only OpenRouter and Ollama)
- Fix duplicate model_name (cerebras-llama-3.3-70b)
Providers included:
Zhipu, OpenAI, Anthropic, DeepSeek, Gemini, Qwen, Moonshot,
Groq, OpenRouter, NVIDIA, Cerebras, Volcengine, ShengsuanYun,
Antigravity, GitHub Copilot, Ollama, VLLM
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 01:30:09 +00:00
|
|
|
// MarshalJSON implements custom JSON marshaling for Config
|
2026-04-01 12:56:48 +00:00
|
|
|
// to omit providers section when empty and session when empty.
|
2026-03-11 08:33:01 +00:00
|
|
|
func (c *Config) MarshalJSON() ([]byte, error) {
|
feat(config): add complete model_list template with all 17 providers
- Include all 17 supported providers in default config as templates
- Each entry has model_name, model, api_base, and empty api_key
- Add comments with API key links for each provider
- Keep onboard message simple (only OpenRouter and Ollama)
- Fix duplicate model_name (cerebras-llama-3.3-70b)
Providers included:
Zhipu, OpenAI, Anthropic, DeepSeek, Gemini, Qwen, Moonshot,
Groq, OpenRouter, NVIDIA, Cerebras, Volcengine, ShengsuanYun,
Antigravity, GitHub Copilot, Ollama, VLLM
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 01:30:09 +00:00
|
|
|
type Alias Config
|
|
|
|
|
aux := &struct {
|
2026-03-21 17:55:00 +00:00
|
|
|
Session *SessionConfig `json:"session,omitempty"`
|
feat(config): add complete model_list template with all 17 providers
- Include all 17 supported providers in default config as templates
- Each entry has model_name, model, api_base, and empty api_key
- Add comments with API key links for each provider
- Keep onboard message simple (only OpenRouter and Ollama)
- Fix duplicate model_name (cerebras-llama-3.3-70b)
Providers included:
Zhipu, OpenAI, Anthropic, DeepSeek, Gemini, Qwen, Moonshot,
Groq, OpenRouter, NVIDIA, Cerebras, Volcengine, ShengsuanYun,
Antigravity, GitHub Copilot, Ollama, VLLM
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 01:30:09 +00:00
|
|
|
*Alias
|
|
|
|
|
}{
|
2026-03-11 08:33:01 +00:00
|
|
|
Alias: (*Alias)(c),
|
feat(config): add complete model_list template with all 17 providers
- Include all 17 supported providers in default config as templates
- Each entry has model_name, model, api_base, and empty api_key
- Add comments with API key links for each provider
- Keep onboard message simple (only OpenRouter and Ollama)
- Fix duplicate model_name (cerebras-llama-3.3-70b)
Providers included:
Zhipu, OpenAI, Anthropic, DeepSeek, Gemini, Qwen, Moonshot,
Groq, OpenRouter, NVIDIA, Cerebras, Volcengine, ShengsuanYun,
Antigravity, GitHub Copilot, Ollama, VLLM
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 01:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 09:19:50 +00:00
|
|
|
if len(c.Session.Dimensions) > 0 || len(c.Session.IdentityLinks) > 0 {
|
|
|
|
|
sessionCfg := c.Session
|
|
|
|
|
aux.Session = &sessionCfg
|
feat(config): add complete model_list template with all 17 providers
- Include all 17 supported providers in default config as templates
- Each entry has model_name, model, api_base, and empty api_key
- Add comments with API key links for each provider
- Keep onboard message simple (only OpenRouter and Ollama)
- Fix duplicate model_name (cerebras-llama-3.3-70b)
Providers included:
Zhipu, OpenAI, Anthropic, DeepSeek, Gemini, Qwen, Moonshot,
Groq, OpenRouter, NVIDIA, Cerebras, Volcengine, ShengsuanYun,
Antigravity, GitHub Copilot, Ollama, VLLM
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 01:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return json.Marshal(aux)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
type AgentsConfig struct {
|
2026-04-01 14:13:04 +00:00
|
|
|
Defaults AgentDefaults `json:"defaults"`
|
|
|
|
|
List []AgentConfig `json:"list,omitempty"`
|
|
|
|
|
Dispatch *DispatchConfig `json:"dispatch,omitempty"`
|
feat: add multi-agent routing with declarative bindings
Implement per-agent workspace/model/session isolation with 7-level
priority routing cascade (peer > parent_peer > guild > team > account >
channel > default). Backward compatible - empty agents.list creates
implicit "main" agent from defaults.
Core components:
- routing/agent_id.go: ID normalization with pre-compiled regex
- routing/session_key.go: 4 DM scope modes with identity links
- routing/route.go: RouteResolver with priority-based binding matcher
- agent/instance.go: Per-agent state (workspace, sessions, tools, model)
- agent/registry.go: Agent lifecycle, route resolution, subagent ACL
Integration:
- config.go: AgentModelConfig (flexible JSON), bindings, session config
- loop.go: Complete rewrite for multi-agent dispatch
- Channel adapters: peer_kind/peer_id metadata (telegram, discord, slack)
- spawn.go: Subagent allowlist enforcement per agent
Validated end-to-end with Discord channel-based bindings, default
fallback routing, and per-agent session persistence.
2026-02-13 15:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AgentModelConfig supports both string and structured model config.
|
|
|
|
|
// String format: "gpt-4" (just primary, no fallbacks)
|
|
|
|
|
// Object format: {"primary": "gpt-4", "fallbacks": ["claude-haiku"]}
|
|
|
|
|
type AgentModelConfig struct {
|
|
|
|
|
Primary string `json:"primary,omitempty"`
|
|
|
|
|
Fallbacks []string `json:"fallbacks,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *AgentModelConfig) UnmarshalJSON(data []byte) error {
|
|
|
|
|
var s string
|
|
|
|
|
if err := json.Unmarshal(data, &s); err == nil {
|
|
|
|
|
m.Primary = s
|
|
|
|
|
m.Fallbacks = nil
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
type raw struct {
|
|
|
|
|
Primary string `json:"primary"`
|
|
|
|
|
Fallbacks []string `json:"fallbacks"`
|
|
|
|
|
}
|
|
|
|
|
var r raw
|
|
|
|
|
if err := json.Unmarshal(data, &r); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
m.Primary = r.Primary
|
|
|
|
|
m.Fallbacks = r.Fallbacks
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m AgentModelConfig) MarshalJSON() ([]byte, error) {
|
|
|
|
|
if len(m.Fallbacks) == 0 && m.Primary != "" {
|
|
|
|
|
return json.Marshal(m.Primary)
|
|
|
|
|
}
|
|
|
|
|
type raw struct {
|
|
|
|
|
Primary string `json:"primary,omitempty"`
|
|
|
|
|
Fallbacks []string `json:"fallbacks,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
return json.Marshal(raw{Primary: m.Primary, Fallbacks: m.Fallbacks})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AgentConfig struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Default bool `json:"default,omitempty"`
|
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
Workspace string `json:"workspace,omitempty"`
|
|
|
|
|
Model *AgentModelConfig `json:"model,omitempty"`
|
|
|
|
|
Skills []string `json:"skills,omitempty"`
|
|
|
|
|
Subagents *SubagentsConfig `json:"subagents,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SubagentsConfig struct {
|
|
|
|
|
AllowAgents []string `json:"allow_agents,omitempty"`
|
|
|
|
|
Model *AgentModelConfig `json:"model,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 14:13:04 +00:00
|
|
|
type DispatchConfig struct {
|
|
|
|
|
Rules []DispatchRule `json:"rules,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DispatchRule struct {
|
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
Agent string `json:"agent"`
|
|
|
|
|
When DispatchSelector `json:"when"`
|
|
|
|
|
SessionDimensions []string `json:"session_dimensions,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DispatchSelector struct {
|
|
|
|
|
Channel string `json:"channel,omitempty"`
|
|
|
|
|
Account string `json:"account,omitempty"`
|
|
|
|
|
Space string `json:"space,omitempty"`
|
|
|
|
|
Chat string `json:"chat,omitempty"`
|
|
|
|
|
Topic string `json:"topic,omitempty"`
|
|
|
|
|
Sender string `json:"sender,omitempty"`
|
|
|
|
|
Mentioned *bool `json:"mentioned,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
feat: add multi-agent routing with declarative bindings
Implement per-agent workspace/model/session isolation with 7-level
priority routing cascade (peer > parent_peer > guild > team > account >
channel > default). Backward compatible - empty agents.list creates
implicit "main" agent from defaults.
Core components:
- routing/agent_id.go: ID normalization with pre-compiled regex
- routing/session_key.go: 4 DM scope modes with identity links
- routing/route.go: RouteResolver with priority-based binding matcher
- agent/instance.go: Per-agent state (workspace, sessions, tools, model)
- agent/registry.go: Agent lifecycle, route resolution, subagent ACL
Integration:
- config.go: AgentModelConfig (flexible JSON), bindings, session config
- loop.go: Complete rewrite for multi-agent dispatch
- Channel adapters: peer_kind/peer_id metadata (telegram, discord, slack)
- spawn.go: Subagent allowlist enforcement per agent
Validated end-to-end with Discord channel-based bindings, default
fallback routing, and per-agent session persistence.
2026-02-13 15:12:33 +00:00
|
|
|
type SessionConfig struct {
|
2026-04-01 09:19:50 +00:00
|
|
|
Dimensions []string `json:"dimensions,omitempty"`
|
feat: add multi-agent routing with declarative bindings
Implement per-agent workspace/model/session isolation with 7-level
priority routing cascade (peer > parent_peer > guild > team > account >
channel > default). Backward compatible - empty agents.list creates
implicit "main" agent from defaults.
Core components:
- routing/agent_id.go: ID normalization with pre-compiled regex
- routing/session_key.go: 4 DM scope modes with identity links
- routing/route.go: RouteResolver with priority-based binding matcher
- agent/instance.go: Per-agent state (workspace, sessions, tools, model)
- agent/registry.go: Agent lifecycle, route resolution, subagent ACL
Integration:
- config.go: AgentModelConfig (flexible JSON), bindings, session config
- loop.go: Complete rewrite for multi-agent dispatch
- Channel adapters: peer_kind/peer_id metadata (telegram, discord, slack)
- spawn.go: Subagent allowlist enforcement per agent
Validated end-to-end with Discord channel-based bindings, default
fallback routing, and per-agent session persistence.
2026-02-13 15:12:33 +00:00
|
|
|
IdentityLinks map[string][]string `json:"identity_links,omitempty"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 14:40:52 +00:00
|
|
|
// RoutingConfig controls the intelligent model routing feature.
|
|
|
|
|
// When enabled, each incoming message is scored against structural features
|
|
|
|
|
// (message length, code blocks, tool call history, conversation depth, attachments).
|
|
|
|
|
// Messages scoring below Threshold are sent to LightModel; all others use the
|
|
|
|
|
// agent's primary model. This reduces cost and latency for simple tasks without
|
|
|
|
|
// requiring any keyword matching — all scoring is language-agnostic.
|
|
|
|
|
type RoutingConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
LightModel string `json:"light_model"` // model_name from model_list to use for simple tasks
|
|
|
|
|
Threshold float64 `json:"threshold"` // complexity score in [0,1]; score >= threshold → primary model
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 05:08:46 +00:00
|
|
|
// SubTurnConfig configures the SubTurn execution system.
|
|
|
|
|
type SubTurnConfig struct {
|
2026-03-21 09:12:45 +00:00
|
|
|
MaxDepth int `json:"max_depth" env:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_MAX_DEPTH"`
|
|
|
|
|
MaxConcurrent int `json:"max_concurrent" env:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_MAX_CONCURRENT"`
|
|
|
|
|
DefaultTimeoutMinutes int `json:"default_timeout_minutes" env:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_DEFAULT_TIMEOUT_MINUTES"`
|
|
|
|
|
DefaultTokenBudget int `json:"default_token_budget" env:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_DEFAULT_TOKEN_BUDGET"`
|
|
|
|
|
ConcurrencyTimeoutSec int `json:"concurrency_timeout_sec" env:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_CONCURRENCY_TIMEOUT_SEC"`
|
2026-03-19 05:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:08:50 +00:00
|
|
|
type ToolFeedbackConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_ENABLED"`
|
|
|
|
|
MaxArgsLength int `json:"max_args_length" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_MAX_ARGS_LENGTH"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
type AgentDefaults struct {
|
2026-04-07 13:19:06 +00:00
|
|
|
Workspace string `json:"workspace" env:"PICOCLAW_AGENTS_DEFAULTS_WORKSPACE"`
|
|
|
|
|
RestrictToWorkspace bool `json:"restrict_to_workspace" env:"PICOCLAW_AGENTS_DEFAULTS_RESTRICT_TO_WORKSPACE"`
|
|
|
|
|
AllowReadOutsideWorkspace bool `json:"allow_read_outside_workspace" env:"PICOCLAW_AGENTS_DEFAULTS_ALLOW_READ_OUTSIDE_WORKSPACE"`
|
|
|
|
|
Provider string `json:"provider" env:"PICOCLAW_AGENTS_DEFAULTS_PROVIDER"`
|
|
|
|
|
ModelName string `json:"model_name" env:"PICOCLAW_AGENTS_DEFAULTS_MODEL_NAME"`
|
2026-03-19 10:08:50 +00:00
|
|
|
ModelFallbacks []string `json:"model_fallbacks,omitempty"`
|
2026-04-07 13:19:06 +00:00
|
|
|
ImageModel string `json:"image_model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_IMAGE_MODEL"`
|
2026-03-19 10:08:50 +00:00
|
|
|
ImageModelFallbacks []string `json:"image_model_fallbacks,omitempty"`
|
2026-04-07 13:19:06 +00:00
|
|
|
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
|
|
|
|
|
ContextWindow int `json:"context_window,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`
|
|
|
|
|
Temperature *float64 `json:"temperature,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
|
|
|
|
|
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
|
|
|
|
|
SummarizeMessageThreshold int `json:"summarize_message_threshold" env:"PICOCLAW_AGENTS_DEFAULTS_SUMMARIZE_MESSAGE_THRESHOLD"`
|
|
|
|
|
SummarizeTokenPercent int `json:"summarize_token_percent" env:"PICOCLAW_AGENTS_DEFAULTS_SUMMARIZE_TOKEN_PERCENT"`
|
|
|
|
|
MaxMediaSize int `json:"max_media_size,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_MEDIA_SIZE"`
|
2026-03-19 10:08:50 +00:00
|
|
|
Routing *RoutingConfig `json:"routing,omitempty"`
|
2026-04-07 13:19:06 +00:00
|
|
|
SteeringMode string `json:"steering_mode,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_STEERING_MODE"` // "one-at-a-time" (default) or "all"
|
|
|
|
|
SubTurn SubTurnConfig `json:"subturn" envPrefix:"PICOCLAW_AGENTS_DEFAULTS_SUBTURN_"`
|
2026-03-19 10:08:50 +00:00
|
|
|
ToolFeedback ToolFeedbackConfig `json:"tool_feedback,omitempty"`
|
2026-04-07 13:19:06 +00:00
|
|
|
SplitOnMarker bool `json:"split_on_marker" env:"PICOCLAW_AGENTS_DEFAULTS_SPLIT_ON_MARKER"` // split messages on <|[SPLIT]|> marker
|
|
|
|
|
ContextManager string `json:"context_manager,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_MANAGER"`
|
|
|
|
|
ContextManagerConfig json.RawMessage `json:"context_manager_config,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_MANAGER_CONFIG"`
|
2026-03-03 05:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 07:03:41 +00:00
|
|
|
const DefaultMaxMediaSize = 20 * 1024 * 1024 // 20 MB
|
2026-03-03 05:20:44 +00:00
|
|
|
|
|
|
|
|
func (d *AgentDefaults) GetMaxMediaSize() int {
|
|
|
|
|
if d.MaxMediaSize > 0 {
|
|
|
|
|
return d.MaxMediaSize
|
|
|
|
|
}
|
|
|
|
|
return DefaultMaxMediaSize
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 10:08:50 +00:00
|
|
|
// GetToolFeedbackMaxArgsLength returns the max args preview length for tool feedback messages.
|
|
|
|
|
func (d *AgentDefaults) GetToolFeedbackMaxArgsLength() int {
|
|
|
|
|
if d.ToolFeedback.MaxArgsLength > 0 {
|
|
|
|
|
return d.ToolFeedback.MaxArgsLength
|
|
|
|
|
}
|
|
|
|
|
return 300
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsToolFeedbackEnabled returns true when tool feedback messages should be sent to the chat.
|
|
|
|
|
func (d *AgentDefaults) IsToolFeedbackEnabled() bool {
|
|
|
|
|
return d.ToolFeedback.Enabled
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 08:55:06 +00:00
|
|
|
// GetModelName returns the effective model name for the agent defaults.
|
|
|
|
|
// It prefers the new "model_name" field but falls back to "model" for backward compatibility.
|
|
|
|
|
func (d *AgentDefaults) GetModelName() string {
|
2026-03-11 08:33:01 +00:00
|
|
|
return d.ModelName
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChannelsConfig struct {
|
2026-04-07 13:19:06 +00:00
|
|
|
WhatsApp WhatsAppConfig `json:"whatsapp" yaml:"-"`
|
|
|
|
|
Telegram TelegramConfig `json:"telegram" yaml:"telegram,omitempty"`
|
|
|
|
|
Feishu FeishuConfig `json:"feishu" yaml:"feishu,omitempty"`
|
|
|
|
|
Discord DiscordConfig `json:"discord" yaml:"discord,omitempty"`
|
|
|
|
|
MaixCam MaixCamConfig `json:"maixcam" yaml:"-"`
|
|
|
|
|
QQ QQConfig `json:"qq" yaml:"qq,omitempty"`
|
|
|
|
|
DingTalk DingTalkConfig `json:"dingtalk" yaml:"dingtalk,omitempty"`
|
|
|
|
|
Slack SlackConfig `json:"slack" yaml:"slack,omitempty"`
|
|
|
|
|
Matrix MatrixConfig `json:"matrix" yaml:"matrix,omitempty"`
|
|
|
|
|
LINE LINEConfig `json:"line" yaml:"line,omitempty"`
|
|
|
|
|
OneBot OneBotConfig `json:"onebot" yaml:"onebot,omitempty"`
|
|
|
|
|
WeCom WeComConfig `json:"wecom" yaml:"wecom,omitempty" envPrefix:"PICOCLAW_CHANNELS_WECOM_"`
|
|
|
|
|
Weixin WeixinConfig `json:"weixin" yaml:"weixin,omitempty"`
|
|
|
|
|
Pico PicoConfig `json:"pico" yaml:"pico,omitempty"`
|
|
|
|
|
PicoClient PicoClientConfig `json:"pico_client" yaml:"pico_client,omitempty"`
|
|
|
|
|
IRC IRCConfig `json:"irc" yaml:"irc,omitempty"`
|
|
|
|
|
VK VKConfig `json:"vk" yaml:"vk,omitempty"`
|
|
|
|
|
TeamsWebhook TeamsWebhookConfig `json:"teams_webhook" yaml:"teams_webhook,omitempty"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
refactor(channels): standardize group chat trigger filtering (Phase 8)
Add unified ShouldRespondInGroup to BaseChannel, replacing scattered
per-channel group filtering logic. Introduce GroupTriggerConfig (with
mention_only + prefixes), TypingConfig, and PlaceholderConfig types.
Migrate Discord MentionOnly, OneBot checkGroupTrigger, and LINE
hardcoded mention-only to the shared mechanism. Add group trigger
entry points for Slack, Telegram, QQ, Feishu, DingTalk, and WeCom.
Legacy config fields are preserved with automatic migration.
2026-02-22 20:11:11 +00:00
|
|
|
// GroupTriggerConfig controls when the bot responds in group chats.
|
|
|
|
|
type GroupTriggerConfig struct {
|
|
|
|
|
MentionOnly bool `json:"mention_only,omitempty"`
|
|
|
|
|
Prefixes []string `json:"prefixes,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TypingConfig controls typing indicator behavior (Phase 10).
|
|
|
|
|
type TypingConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PlaceholderConfig controls placeholder message behavior (Phase 10).
|
|
|
|
|
type PlaceholderConfig struct {
|
2026-03-25 10:03:27 +00:00
|
|
|
Enabled bool `json:"enabled"`
|
2026-03-25 09:41:50 +00:00
|
|
|
Text FlexibleStringSlice `json:"text,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetRandomText returns a random placeholder text, or default if none set.
|
|
|
|
|
func (p *PlaceholderConfig) GetRandomText() string {
|
|
|
|
|
if len(p.Text) == 0 {
|
|
|
|
|
return "Thinking..."
|
|
|
|
|
}
|
|
|
|
|
if len(p.Text) == 1 {
|
|
|
|
|
return p.Text[0]
|
|
|
|
|
}
|
|
|
|
|
idx := rand.Intn(len(p.Text))
|
|
|
|
|
return p.Text[idx]
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
feat(telegram): stream LLM responses via sendMessageDraft (#1101)
* feat(telegram): stream LLM responses in real-time via sendMessageDraft
Implements real-time token streaming to Telegram using the sendMessageDraft
API (telego v1.6.0). Instead of showing only a "Thinking..." placeholder
until the full response arrives, users now see partial LLM output appear
in the chat as it's generated.
The streaming pipeline threads through all layers:
- StreamingProvider interface (providers/types.go): opt-in ChatStream()
method that receives an onChunk callback with accumulated text
- OpenAI-compatible SSE streaming (openai_compat/provider.go): parses
SSE events with stream:true, handles text deltas and tool call assembly
- Anthropic native streaming (anthropic/provider.go): uses SDK's
NewStreaming() for direct Anthropic API connections
- HTTPProvider delegation (http_provider.go): delegates ChatStream to
the underlying openai_compat provider
- StreamingCapable + Streamer interfaces (channels/interfaces.go):
opt-in channel capability like TypingCapable/PlaceholderCapable
- Telegram streamer (telegram/telegram.go): BeginStream returns a
telegramStreamer that throttles sendMessageDraft calls (3s/200 chars)
with graceful degradation on API errors
- StreamDelegate bridge (bus/bus.go): decouples agent loop from channel
manager without tight imports
- Manager integration (manager.go): implements StreamDelegate, tracks
streamActive state, coordinates with placeholder editing
- Agent loop (loop.go): uses ChatStream when both provider and channel
support streaming, cancels stream on tool calls, skips PublishOutbound
when Finalize already delivered the message
Graceful degradation:
- Bots without forum/topics mode: first sendMessageDraft error sets
failed=true, subsequent Updates become no-ops, Finalize still delivers
via SendMessage. User sees normal non-streaming behavior.
- Non-streaming providers: type assertion fails, falls back to Chat()
- Config opt-out: streaming.enabled (default true) in telegram config
Closes #1098
* fix(telegram): delete placeholder message when streaming delivers response
When streaming was active, the "Thinking..." placeholder message stayed
in the chat because preSend only deleted the tracking entry without
removing the actual Telegram message. Now preSend deletes the placeholder
via the new MessageDeleter interface when streamActive is set.
* refactor(streaming): remove dead code and simplify streaming wiring
- Delete unused Anthropic ChatStream/parseStream (-131 lines) — factory
creates HTTPProvider for all OpenAI-compat providers including OpenRouter
- Simplify runLLMIteration from 4 to 3 return values (remove unused
streamed bool)
- Replace managerStreamer struct with finalizeHookStreamer using embedding
(Update/Cancel promoted, only Finalize overridden)
* fix(streaming): skip streamer acquisition when SendResponse is false
Heartbeat messages set SendResponse=false but the streaming path
was unconditionally acquiring a streamer, causing HEARTBEAT_OK to
leak to Telegram via streamer.Finalize().
* fix(streaming): guard streamer for non-sendable messages, add streaming config
Skip streamer acquisition for heartbeat (NoHistory=true), preventing
HEARTBEAT_OK from leaking to Telegram via streamer.Finalize().
Add streaming.enabled to Telegram defaults and example config.
* feat(telegram): stream LLM responses in real-time via sendMessageDraft
Implements real-time token streaming to Telegram using the sendMessageDraft
API (telego v1.6.0). Instead of showing only a "Thinking..." placeholder
until the full response arrives, users now see partial LLM output appear
in the chat as it's generated.
The streaming pipeline threads through all layers:
- StreamingProvider interface (providers/types.go): opt-in ChatStream()
method that receives an onChunk callback with accumulated text
- OpenAI-compatible SSE streaming (openai_compat/provider.go): parses
SSE events with stream:true, handles text deltas and tool call assembly
- Anthropic native streaming (anthropic/provider.go): uses SDK's
NewStreaming() for direct Anthropic API connections
- HTTPProvider delegation (http_provider.go): delegates ChatStream to
the underlying openai_compat provider
- StreamingCapable + Streamer interfaces (channels/interfaces.go):
opt-in channel capability like TypingCapable/PlaceholderCapable
- Telegram streamer (telegram/telegram.go): BeginStream returns a
telegramStreamer that throttles sendMessageDraft calls (3s/200 chars)
with graceful degradation on API errors
- StreamDelegate bridge (bus/bus.go): decouples agent loop from channel
manager without tight imports
- Manager integration (manager.go): implements StreamDelegate, tracks
streamActive state, coordinates with placeholder editing
- Agent loop (loop.go): uses ChatStream when both provider and channel
support streaming, cancels stream on tool calls, skips PublishOutbound
when Finalize already delivered the message
Graceful degradation:
- Bots without forum/topics mode: first sendMessageDraft error sets
failed=true, subsequent Updates become no-ops, Finalize still delivers
via SendMessage. User sees normal non-streaming behavior.
- Non-streaming providers: type assertion fails, falls back to Chat()
- Config opt-out: streaming.enabled (default true) in telegram config
Closes #1098
* fix(telegram): delete placeholder message when streaming delivers response
When streaming was active, the "Thinking..." placeholder message stayed
in the chat because preSend only deleted the tracking entry without
removing the actual Telegram message. Now preSend deletes the placeholder
via the new MessageDeleter interface when streamActive is set.
* refactor(streaming): remove dead code and simplify streaming wiring
- Delete unused Anthropic ChatStream/parseStream (-131 lines) — factory
creates HTTPProvider for all OpenAI-compat providers including OpenRouter
- Simplify runLLMIteration from 4 to 3 return values (remove unused
streamed bool)
- Replace managerStreamer struct with finalizeHookStreamer using embedding
(Update/Cancel promoted, only Finalize overridden)
* fix(streaming): skip streamer acquisition when SendResponse is false
Heartbeat messages set SendResponse=false but the streaming path
was unconditionally acquiring a streamer, causing HEARTBEAT_OK to
leak to Telegram via streamer.Finalize().
* fix(streaming): guard streamer for non-sendable messages, add streaming config
Skip streamer acquisition for heartbeat (NoHistory=true), preventing
HEARTBEAT_OK from leaking to Telegram via streamer.Finalize().
Add streaming.enabled to Telegram defaults and example config.
* fix(picoclaw): add missing closing brace for StreamingProvider interface
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve golangci-lint formatting issues
Fix gci import ordering in telegram and anthropic provider, and break
long function signature in openai_compat provider to satisfy golines.
* fix: address code review feedback on streaming PR
- Deduplicate Streamer interface: alias channels.Streamer to bus.Streamer
to prevent type drift across packages
- Increase SSE scanner buffer to 10MB max to handle large single-line
responses that exceed bufio.Scanner's 64KB default
- Switch draftID generation from math/rand to crypto/rand for
collision-resistant random IDs
- Add context cancellation check in SSE parsing loop so cancelled
streams stop processing immediately
- Log Finalize failures with chat_id and content length for debugging
silent message delivery failures
* feat: make streaming throttle interval and min growth configurable
Move hardcoded streamThrottleInterval (3s) and streamMinGrowth (200)
into StreamingConfig so they can be tuned per deployment via config
or environment variables.
* fix(telegram): use parseTelegramChatID in DeleteMessage and BeginStream
These two functions called undefined parseChatID. Use
parseTelegramChatID with _ for the unused threadID instead of adding
a wrapper function. Fixes all three CI checks.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(streaming): set streamActive only after successful Finalize
Move onFinalize hook to run after Streamer.Finalize succeeds, so that
if Finalize fails the streamActive flag stays false and the regular
placeholder fallback path remains available.
Addresses review feedback from @alexhoshina.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-20 13:04:14 +00:00
|
|
|
type StreamingConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled,omitempty" env:"PICOCLAW_CHANNELS_TELEGRAM_STREAMING_ENABLED"`
|
|
|
|
|
ThrottleSeconds int `json:"throttle_seconds,omitempty" env:"PICOCLAW_CHANNELS_TELEGRAM_STREAMING_THROTTLE_SECONDS"`
|
|
|
|
|
MinGrowthChars int `json:"min_growth_chars,omitempty" env:"PICOCLAW_CHANNELS_TELEGRAM_STREAMING_MIN_GROWTH_CHARS"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
type WhatsAppConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_ENABLED"`
|
|
|
|
|
BridgeURL string `json:"bridge_url" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"`
|
|
|
|
|
UseNative bool `json:"use_native" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_USE_NATIVE"`
|
|
|
|
|
SessionStorePath string `json:"session_store_path" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_ALLOW_FROM"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_WHATSAPP_REASONING_CHANNEL_ID"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TelegramConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_ENABLED"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_TELEGRAM_TOKEN"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_BASE_URL"`
|
|
|
|
|
Proxy string `json:"proxy" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_PROXY"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
Streaming StreamingConfig `json:"streaming,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_REASONING_CHANNEL_ID"`
|
|
|
|
|
UseMarkdownV2 bool `json:"use_markdown_v2" yaml:"-" env:"PICOCLAW_CHANNELS_TELEGRAM_USE_MARKDOWN_V2"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
func (c *TelegramConfig) SetToken(token string) {
|
|
|
|
|
c.Token = *NewSecureString(token)
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
type FeishuConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_ENABLED"`
|
|
|
|
|
AppID string `json:"app_id" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_APP_ID"`
|
|
|
|
|
AppSecret SecureString `json:"app_secret,omitzero" yaml:"app_secret,omitempty" env:"PICOCLAW_CHANNELS_FEISHU_APP_SECRET"`
|
|
|
|
|
EncryptKey SecureString `json:"encrypt_key,omitzero" yaml:"encrypt_key,omitempty" env:"PICOCLAW_CHANNELS_FEISHU_ENCRYPT_KEY"`
|
|
|
|
|
VerificationToken SecureString `json:"verification_token,omitzero" yaml:"verification_token,omitempty" env:"PICOCLAW_CHANNELS_FEISHU_VERIFICATION_TOKEN"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_REASONING_CHANNEL_ID"`
|
|
|
|
|
RandomReactionEmoji FlexibleStringSlice `json:"random_reaction_emoji" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_RANDOM_REACTION_EMOJI"`
|
|
|
|
|
IsLark bool `json:"is_lark" yaml:"-" env:"PICOCLAW_CHANNELS_FEISHU_IS_LARK"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DiscordConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_DISCORD_ENABLED"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_DISCORD_TOKEN"`
|
|
|
|
|
Proxy string `json:"proxy" yaml:"-" env:"PICOCLAW_CHANNELS_DISCORD_PROXY"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_DISCORD_ALLOW_FROM"`
|
|
|
|
|
MentionOnly bool `json:"mention_only" yaml:"-" env:"PICOCLAW_CHANNELS_DISCORD_MENTION_ONLY"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_DISCORD_REASONING_CHANNEL_ID"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MaixCamConfig struct {
|
2026-02-26 05:24:51 +00:00
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_MAIXCAM_ENABLED"`
|
|
|
|
|
Host string `json:"host" env:"PICOCLAW_CHANNELS_MAIXCAM_HOST"`
|
|
|
|
|
Port int `json:"port" env:"PICOCLAW_CHANNELS_MAIXCAM_PORT"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_MAIXCAM_ALLOW_FROM"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_MAIXCAM_REASONING_CHANNEL_ID"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 01:46:07 +00:00
|
|
|
type QQConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_ENABLED"`
|
|
|
|
|
AppID string `json:"app_id" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_APP_ID"`
|
|
|
|
|
AppSecret SecureString `json:"app_secret,omitzero" yaml:"app_secret,omitempty" env:"PICOCLAW_CHANNELS_QQ_APP_SECRET"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
MaxMessageLength int `json:"max_message_length" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_MAX_MESSAGE_LENGTH"`
|
|
|
|
|
MaxBase64FileSizeMiB int64 `json:"max_base64_file_size_mib" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_MAX_BASE64_FILE_SIZE_MIB"`
|
|
|
|
|
SendMarkdown bool `json:"send_markdown" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_SEND_MARKDOWN"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_QQ_REASONING_CHANNEL_ID"`
|
2026-02-10 01:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 13:33:55 +00:00
|
|
|
type DingTalkConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_DINGTALK_ENABLED"`
|
|
|
|
|
ClientID string `json:"client_id" yaml:"-" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_ID"`
|
|
|
|
|
ClientSecret SecureString `json:"client_secret,omitzero" yaml:"client_secret,omitempty" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_SECRET"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_DINGTALK_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_DINGTALK_REASONING_CHANNEL_ID"`
|
2026-02-10 13:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-11 18:48:32 +00:00
|
|
|
type SlackConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_SLACK_ENABLED"`
|
|
|
|
|
BotToken SecureString `json:"bot_token,omitzero" yaml:"bot_token,omitempty" env:"PICOCLAW_CHANNELS_SLACK_BOT_TOKEN"`
|
|
|
|
|
AppToken SecureString `json:"app_token,omitzero" yaml:"app_token,omitempty" env:"PICOCLAW_CHANNELS_SLACK_APP_TOKEN"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_SLACK_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_SLACK_REASONING_CHANNEL_ID"`
|
2026-02-10 13:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-07 17:44:24 +00:00
|
|
|
type MatrixConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_MATRIX_ENABLED"`
|
|
|
|
|
Homeserver string `json:"homeserver" yaml:"-" env:"PICOCLAW_CHANNELS_MATRIX_HOMESERVER"`
|
|
|
|
|
UserID string `json:"user_id" yaml:"-" env:"PICOCLAW_CHANNELS_MATRIX_USER_ID"`
|
|
|
|
|
AccessToken SecureString `json:"access_token,omitzero" yaml:"access_token,omitempty" env:"PICOCLAW_CHANNELS_MATRIX_ACCESS_TOKEN"`
|
|
|
|
|
DeviceID string `json:"device_id,omitempty" yaml:"-"`
|
|
|
|
|
JoinOnInvite bool `json:"join_on_invite" yaml:"-"`
|
|
|
|
|
MessageFormat string `json:"message_format,omitempty" yaml:"-"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-"`
|
|
|
|
|
CryptoDatabasePath string `json:"crypto_database_path,omitempty" yaml:"-"`
|
|
|
|
|
CryptoPassphrase string `json:"crypto_passphrase,omitempty" yaml:"-"`
|
2026-03-07 17:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 01:01:20 +00:00
|
|
|
type LINEConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_LINE_ENABLED"`
|
|
|
|
|
ChannelSecret SecureString `json:"channel_secret,omitzero" yaml:"channel_secret,omitempty" env:"PICOCLAW_CHANNELS_LINE_CHANNEL_SECRET"`
|
|
|
|
|
ChannelAccessToken SecureString `json:"channel_access_token,omitzero" yaml:"channel_access_token,omitempty" env:"PICOCLAW_CHANNELS_LINE_CHANNEL_ACCESS_TOKEN"`
|
|
|
|
|
WebhookHost string `json:"webhook_host" yaml:"-" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_HOST"`
|
|
|
|
|
WebhookPort int `json:"webhook_port" yaml:"-" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_PORT"`
|
|
|
|
|
WebhookPath string `json:"webhook_path" yaml:"-" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_PATH"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_LINE_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-"`
|
2026-02-14 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 08:50:21 +00:00
|
|
|
type OneBotConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_ONEBOT_ENABLED"`
|
|
|
|
|
WSUrl string `json:"ws_url" yaml:"-" env:"PICOCLAW_CHANNELS_ONEBOT_WS_URL"`
|
|
|
|
|
AccessToken SecureString `json:"access_token,omitzero" yaml:"access_token,omitempty" env:"PICOCLAW_CHANNELS_ONEBOT_ACCESS_TOKEN"`
|
|
|
|
|
ReconnectInterval int `json:"reconnect_interval" yaml:"-" env:"PICOCLAW_CHANNELS_ONEBOT_RECONNECT_INTERVAL"`
|
|
|
|
|
GroupTriggerPrefix []string `json:"group_trigger_prefix" yaml:"-" env:"PICOCLAW_CHANNELS_ONEBOT_GROUP_TRIGGER_PREFIX"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_ONEBOT_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-"`
|
2026-02-14 08:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 07:03:41 +00:00
|
|
|
type WeComGroupConfig struct {
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from,omitempty"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 07:03:41 +00:00
|
|
|
type WeComConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"ENABLED"`
|
|
|
|
|
BotID string `json:"bot_id" yaml:"-" env:"BOT_ID"`
|
|
|
|
|
Secret SecureString `json:"secret,omitzero" yaml:"secret,omitempty" env:"SECRET"`
|
|
|
|
|
WebSocketURL string `json:"websocket_url,omitempty" yaml:"-" env:"WEBSOCKET_URL"`
|
|
|
|
|
SendThinkingMessage bool `json:"send_thinking_message" yaml:"-" env:"SEND_THINKING_MESSAGE"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"ALLOW_FROM"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"REASONING_CHANNEL_ID"`
|
2026-02-28 05:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 07:03:41 +00:00
|
|
|
func (c *WeComConfig) SetSecret(secret string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.Secret = *NewSecureString(secret)
|
2026-02-28 05:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-22 06:23:39 +00:00
|
|
|
type WeixinConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_ENABLED"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_WEIXIN_TOKEN"`
|
|
|
|
|
AccountID string `json:"account_id,omitempty" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_ACCOUNT_ID"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_BASE_URL"`
|
|
|
|
|
CDNBaseURL string `json:"cdn_base_url" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_CDN_BASE_URL"`
|
|
|
|
|
Proxy string `json:"proxy" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_PROXY"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_ALLOW_FROM"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_WEIXIN_REASONING_CHANNEL_ID"`
|
2026-03-22 11:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
// SetToken sets the Weixin token and marks it as dirty for security saving
|
|
|
|
|
func (c *WeixinConfig) SetToken(token string) {
|
|
|
|
|
c.Token = *NewSecureString(token)
|
2026-03-22 06:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 20:55:15 +00:00
|
|
|
type PicoConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_PICO_ENABLED"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_PICO_TOKEN"`
|
|
|
|
|
AllowTokenQuery bool `json:"allow_token_query,omitempty" yaml:"-"`
|
|
|
|
|
AllowOrigins []string `json:"allow_origins,omitempty" yaml:"-"`
|
|
|
|
|
PingInterval int `json:"ping_interval,omitempty" yaml:"-"`
|
|
|
|
|
ReadTimeout int `json:"read_timeout,omitempty" yaml:"-"`
|
|
|
|
|
WriteTimeout int `json:"write_timeout,omitempty" yaml:"-"`
|
|
|
|
|
MaxConnections int `json:"max_connections,omitempty" yaml:"-"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_PICO_ALLOW_FROM"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetToken sets the Pico token and marks it as dirty for security saving
|
2026-03-21 17:55:00 +00:00
|
|
|
func (c *PicoConfig) SetToken(token string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.Token = *NewSecureString(token)
|
2026-02-14 08:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-20 12:43:40 +00:00
|
|
|
type PicoClientConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_PICO_CLIENT_ENABLED"`
|
|
|
|
|
URL string `json:"url" yaml:"-" env:"PICOCLAW_CHANNELS_PICO_CLIENT_URL"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_PICO_CLIENT_TOKEN"`
|
|
|
|
|
SessionID string `json:"session_id,omitempty" yaml:"-"`
|
|
|
|
|
PingInterval int `json:"ping_interval,omitempty" yaml:"-"`
|
|
|
|
|
ReadTimeout int `json:"read_timeout,omitempty" yaml:"-"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_PICO_CLIENT_ALLOW_FROM"`
|
2026-03-20 12:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-05 10:46:01 +00:00
|
|
|
type IRCConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_ENABLED"`
|
|
|
|
|
Server string `json:"server" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_SERVER"`
|
|
|
|
|
TLS bool `json:"tls" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_TLS"`
|
|
|
|
|
Nick string `json:"nick" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_NICK"`
|
|
|
|
|
User string `json:"user,omitempty" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_USER"`
|
|
|
|
|
RealName string `json:"real_name,omitempty" yaml:"-"`
|
|
|
|
|
Password SecureString `json:"password,omitzero" yaml:"password,omitempty" env:"PICOCLAW_CHANNELS_IRC_PASSWORD"`
|
|
|
|
|
NickServPassword SecureString `json:"nickserv_password,omitzero" yaml:"nickserv_password,omitempty" env:"PICOCLAW_CHANNELS_IRC_NICKSERV_PASSWORD"`
|
|
|
|
|
SASLUser string `json:"sasl_user" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_SASL_USER"`
|
|
|
|
|
SASLPassword SecureString `json:"sasl_password,omitzero" yaml:"sasl_password,omitempty" env:"PICOCLAW_CHANNELS_IRC_SASL_PASSWORD"`
|
|
|
|
|
Channels FlexibleStringSlice `json:"channels" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_CHANNELS"`
|
|
|
|
|
RequestCaps FlexibleStringSlice `json:"request_caps,omitempty" yaml:"-"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_IRC_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-"`
|
2026-03-05 10:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-07 13:19:06 +00:00
|
|
|
type VKConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_VK_ENABLED"`
|
|
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_CHANNELS_VK_TOKEN"`
|
|
|
|
|
GroupID int `json:"group_id" yaml:"-" env:"PICOCLAW_CHANNELS_VK_GROUP_ID"`
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" yaml:"-" env:"PICOCLAW_CHANNELS_VK_ALLOW_FROM"`
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty" yaml:"-"`
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty" yaml:"-"`
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty" yaml:"-"`
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" yaml:"-" env:"PICOCLAW_CHANNELS_VK_REASONING_CHANNEL_ID"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *VKConfig) SetToken(token string) {
|
|
|
|
|
c.Token = *NewSecureString(token)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TeamsWebhookConfig configures the output-only Microsoft Teams webhook channel.
|
|
|
|
|
// Multiple webhook targets can be configured and selected via ChatID at send time.
|
|
|
|
|
type TeamsWebhookConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_CHANNELS_TEAMS_WEBHOOK_ENABLED"`
|
|
|
|
|
Webhooks map[string]TeamsWebhookTarget `json:"webhooks" yaml:"webhooks,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TeamsWebhookTarget represents a single Teams webhook destination.
|
|
|
|
|
type TeamsWebhookTarget struct {
|
|
|
|
|
WebhookURL SecureString `json:"webhook_url,omitzero" yaml:"webhook_url,omitempty"`
|
|
|
|
|
Title string `json:"title,omitempty" yaml:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 12:15:43 +00:00
|
|
|
type HeartbeatConfig struct {
|
2026-02-20 18:03:11 +00:00
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_HEARTBEAT_ENABLED"`
|
2026-02-13 03:13:32 +00:00
|
|
|
Interval int `json:"interval" env:"PICOCLAW_HEARTBEAT_INTERVAL"` // minutes, min 5
|
2026-02-12 12:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 05:56:08 +00:00
|
|
|
type DevicesConfig struct {
|
2026-02-20 18:03:11 +00:00
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_DEVICES_ENABLED"`
|
2026-02-14 05:56:08 +00:00
|
|
|
MonitorUSB bool `json:"monitor_usb" env:"PICOCLAW_DEVICES_MONITOR_USB"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
type VoiceConfig struct {
|
2026-03-23 21:11:10 +00:00
|
|
|
ModelName string `json:"model_name,omitempty" env:"PICOCLAW_VOICE_MODEL_NAME"`
|
2026-04-07 13:19:06 +00:00
|
|
|
TTSModelName string `json:"tts_model_name,omitempty" env:"PICOCLAW_VOICE_TTS_MODEL_NAME"`
|
2026-03-23 21:11:10 +00:00
|
|
|
EchoTranscription bool `json:"echo_transcription" env:"PICOCLAW_VOICE_ECHO_TRANSCRIPTION"`
|
|
|
|
|
ElevenLabsAPIKey string `json:"elevenlabs_api_key,omitempty" env:"PICOCLAW_VOICE_ELEVENLABS_API_KEY"`
|
2026-03-11 08:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
// ModelConfig represents a model-centric provider configuration.
|
|
|
|
|
// It allows adding new providers (especially OpenAI-compatible ones) via configuration only.
|
|
|
|
|
// The model field uses protocol prefix format: [protocol/]model-identifier
|
2026-03-18 10:29:27 +00:00
|
|
|
// Supported protocols include openai, anthropic, antigravity, claude-cli,
|
|
|
|
|
// codex-cli, github-copilot, and named OpenAI-compatible protocols such as
|
|
|
|
|
// groq, deepseek, modelscope, and novita.
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
// Default protocol is "openai" if no prefix is specified.
|
|
|
|
|
type ModelConfig struct {
|
|
|
|
|
// Required fields
|
|
|
|
|
ModelName string `json:"model_name"` // User-facing alias for the model
|
2026-02-20 04:15:04 +00:00
|
|
|
Model string `json:"model"` // Protocol/model-identifier (e.g., "openai/gpt-4o", "anthropic/claude-sonnet-4.6")
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
|
|
|
|
|
// HTTP-based providers
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
APIBase string `json:"api_base,omitempty"` // API endpoint URL
|
|
|
|
|
Proxy string `json:"proxy,omitempty"` // HTTP proxy URL
|
|
|
|
|
Fallbacks []string `json:"fallbacks,omitempty"` // Fallback model names for failover
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
|
|
|
|
|
// Special providers (CLI-based, OAuth, etc.)
|
2026-02-19 17:27:00 +00:00
|
|
|
AuthMethod string `json:"auth_method,omitempty"` // Authentication method: oauth, token
|
|
|
|
|
ConnectMode string `json:"connect_mode,omitempty"` // Connection mode: stdio, grpc
|
|
|
|
|
Workspace string `json:"workspace,omitempty"` // Workspace path for CLI-based providers
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
|
|
|
|
|
// Optional optimizations
|
2026-04-07 13:19:06 +00:00
|
|
|
RPM int `json:"rpm,omitempty"` // Requests per minute limit
|
|
|
|
|
MaxTokensField string `json:"max_tokens_field,omitempty"` // Field name for max tokens (e.g., "max_completion_tokens")
|
|
|
|
|
RequestTimeout int `json:"request_timeout,omitempty"`
|
|
|
|
|
ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive
|
|
|
|
|
ExtraBody map[string]any `json:"extra_body,omitempty"` // Additional fields to inject into request body
|
|
|
|
|
CustomHeaders map[string]string `json:"custom_headers,omitempty"` // Additional headers to inject into every HTTP request
|
2026-03-21 17:55:00 +00:00
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
APIKeys SecureStrings `json:"api_keys,omitzero" yaml:"api_keys,omitempty"` // API authentication keys (multiple keys for failover)
|
2026-03-24 15:56:45 +00:00
|
|
|
|
2026-03-30 06:01:20 +00:00
|
|
|
// Enabled indicates whether this model entry is active. When omitted in
|
|
|
|
|
// existing configs, the field is inferred during load: models with API keys
|
|
|
|
|
// or the reserved "local-model" name are auto-enabled.
|
|
|
|
|
Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
|
2026-04-07 13:19:06 +00:00
|
|
|
// UserAgent is the user agent string to use for HTTP requests.
|
|
|
|
|
UserAgent string `json:"user_agent,omitempty" yaml:"-"`
|
2026-03-30 06:01:20 +00:00
|
|
|
|
2026-03-24 15:56:45 +00:00
|
|
|
// isVirtual marks this model as a virtual model generated from multi-key expansion.
|
|
|
|
|
// Virtual models should not be persisted to config files.
|
|
|
|
|
isVirtual bool
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APIKey returns the first API key from apiKeys
|
|
|
|
|
func (c *ModelConfig) APIKey() string {
|
2026-03-27 16:03:34 +00:00
|
|
|
if len(c.APIKeys) > 0 {
|
|
|
|
|
return c.APIKeys[0].String()
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
return ""
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 15:56:45 +00:00
|
|
|
// IsVirtual returns true if this model was generated from multi-key expansion.
|
|
|
|
|
func (c *ModelConfig) IsVirtual() bool {
|
|
|
|
|
return c.isVirtual
|
|
|
|
|
}
|
|
|
|
|
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
// Validate checks if the ModelConfig has all required fields.
|
|
|
|
|
func (c *ModelConfig) Validate() error {
|
|
|
|
|
if c.ModelName == "" {
|
|
|
|
|
return fmt.Errorf("model_name is required")
|
|
|
|
|
}
|
|
|
|
|
if c.Model == "" {
|
|
|
|
|
return fmt.Errorf("model is required")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 17:55:00 +00:00
|
|
|
func (c *ModelConfig) SetAPIKey(value string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
if len(c.APIKeys) > 0 {
|
|
|
|
|
c.APIKeys[0].Set(value)
|
2026-03-21 17:55:00 +00:00
|
|
|
} else {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = append(c.APIKeys, NewSecureString(value))
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-09 17:21:49 +00:00
|
|
|
type ToolDiscoveryConfig struct {
|
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_DISCOVERY_ENABLED"`
|
|
|
|
|
TTL int `json:"ttl" env:"PICOCLAW_TOOLS_DISCOVERY_TTL"`
|
|
|
|
|
MaxSearchResults int `json:"max_search_results" env:"PICOCLAW_MAX_SEARCH_RESULTS"`
|
|
|
|
|
UseBM25 bool `json:"use_bm25" env:"PICOCLAW_TOOLS_DISCOVERY_USE_BM25"`
|
|
|
|
|
UseRegex bool `json:"use_regex" env:"PICOCLAW_TOOLS_DISCOVERY_USE_REGEX"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 06:53:26 +00:00
|
|
|
type ToolConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"ENABLED"`
|
2026-03-05 06:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 09:12:55 +00:00
|
|
|
type BraveConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_BRAVE_ENABLED"`
|
|
|
|
|
APIKeys SecureStrings `json:"api_keys,omitzero" yaml:"api_keys,omitempty" env:"PICOCLAW_TOOLS_WEB_BRAVE_API_KEYS"`
|
|
|
|
|
MaxResults int `json:"max_results" yaml:"-" env:"PICOCLAW_TOOLS_WEB_BRAVE_MAX_RESULTS"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APIKey returns the Brave API key
|
|
|
|
|
func (c *BraveConfig) APIKey() string {
|
2026-03-27 16:03:34 +00:00
|
|
|
if len(c.APIKeys) == 0 {
|
2026-03-21 17:55:00 +00:00
|
|
|
return ""
|
|
|
|
|
}
|
2026-03-27 16:03:34 +00:00
|
|
|
return c.APIKeys[0].String()
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAPIKey sets the Brave API key
|
|
|
|
|
func (c *BraveConfig) SetAPIKey(key string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = SimpleSecureStrings(key)
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *BraveConfig) SetAPIKeys(keys []string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = SimpleSecureStrings(keys...)
|
2026-02-13 09:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-22 16:30:14 +00:00
|
|
|
type TavilyConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_TAVILY_ENABLED"`
|
|
|
|
|
APIKeys SecureStrings `json:"api_keys,omitzero" yaml:"api_keys,omitempty" env:"PICOCLAW_TOOLS_WEB_TAVILY_API_KEYS"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_TOOLS_WEB_TAVILY_BASE_URL"`
|
|
|
|
|
MaxResults int `json:"max_results" yaml:"-" env:"PICOCLAW_TOOLS_WEB_TAVILY_MAX_RESULTS"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APIKey returns the Tavily API key
|
|
|
|
|
func (c *TavilyConfig) APIKey() string {
|
2026-03-27 16:03:34 +00:00
|
|
|
if len(c.APIKeys) == 0 {
|
2026-03-21 17:55:00 +00:00
|
|
|
return ""
|
|
|
|
|
}
|
2026-03-27 16:03:34 +00:00
|
|
|
return c.APIKeys[0].String()
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAPIKey sets the Tavily API key
|
|
|
|
|
func (c *TavilyConfig) SetAPIKey(key string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = SimpleSecureStrings(key)
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAPIKeys sets the Tavily API keys
|
|
|
|
|
func (c *TavilyConfig) SetAPIKeys(keys []string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = make(SecureStrings, len(keys))
|
|
|
|
|
for i, k := range keys {
|
|
|
|
|
c.APIKeys[i] = NewSecureString(k)
|
|
|
|
|
}
|
2026-02-22 16:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 09:12:55 +00:00
|
|
|
type DuckDuckGoConfig struct {
|
2026-02-20 18:03:11 +00:00
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_DUCKDUCKGO_ENABLED"`
|
2026-02-13 09:12:55 +00:00
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_DUCKDUCKGO_MAX_RESULTS"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-17 13:02:56 +00:00
|
|
|
type PerplexityConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_ENABLED"`
|
|
|
|
|
APIKeys SecureStrings `json:"api_keys,omitzero" yaml:"api_keys,omitempty" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_API_KEYS"`
|
|
|
|
|
MaxResults int `json:"max_results" yaml:"-" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_MAX_RESULTS"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// APIKey returns the Perplexity API key
|
|
|
|
|
func (c *PerplexityConfig) APIKey() string {
|
2026-03-27 16:03:34 +00:00
|
|
|
if len(c.APIKeys) == 0 {
|
2026-03-21 17:55:00 +00:00
|
|
|
return ""
|
|
|
|
|
}
|
2026-03-27 16:03:34 +00:00
|
|
|
return c.APIKeys[0].String()
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAPIKey sets the Perplexity API key
|
|
|
|
|
func (c *PerplexityConfig) SetAPIKey(key string) {
|
2026-03-27 16:03:34 +00:00
|
|
|
c.APIKeys = SimpleSecureStrings(key)
|
2026-02-17 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 11:02:00 +00:00
|
|
|
type SearXNGConfig struct {
|
2026-03-04 20:48:36 +00:00
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_SEARXNG_ENABLED"`
|
|
|
|
|
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_SEARXNG_BASE_URL"`
|
2026-02-20 11:02:00 +00:00
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_SEARXNG_MAX_RESULTS"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 06:58:12 +00:00
|
|
|
type GLMSearchConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"`
|
|
|
|
|
APIKey SecureString `json:"api_key,omitzero" yaml:"api_key,omitempty" env:"PICOCLAW_TOOLS_WEB_GLM_API_KEY"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"`
|
2026-03-04 06:58:12 +00:00
|
|
|
// SearchEngine specifies the search backend: "search_std" (default),
|
|
|
|
|
// "search_pro", "search_pro_sogou", or "search_pro_quark".
|
2026-03-27 16:03:34 +00:00
|
|
|
SearchEngine string `json:"search_engine" yaml:"-" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"`
|
|
|
|
|
MaxResults int `json:"max_results" yaml:"-" env:"PICOCLAW_TOOLS_WEB_GLM_MAX_RESULTS"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-22 16:51:27 +00:00
|
|
|
type BaiduSearchConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_BAIDU_ENABLED"`
|
|
|
|
|
APIKey SecureString `json:"api_key,omitzero" yaml:"api_key,omitempty" env:"PICOCLAW_TOOLS_WEB_BAIDU_API_KEY"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_TOOLS_WEB_BAIDU_BASE_URL"`
|
|
|
|
|
MaxResults int `json:"max_results" yaml:"-" env:"PICOCLAW_TOOLS_WEB_BAIDU_MAX_RESULTS"`
|
2026-03-22 16:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
type WebToolsConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
ToolConfig ` yaml:"-" envPrefix:"PICOCLAW_TOOLS_WEB_"`
|
|
|
|
|
Brave BraveConfig `yaml:"brave,omitempty" json:"brave"`
|
|
|
|
|
Tavily TavilyConfig `yaml:"tavily,omitempty" json:"tavily"`
|
|
|
|
|
DuckDuckGo DuckDuckGoConfig `yaml:"-" json:"duckduckgo"`
|
|
|
|
|
Perplexity PerplexityConfig `yaml:"perplexity,omitempty" json:"perplexity"`
|
|
|
|
|
SearXNG SearXNGConfig `yaml:"-" json:"searxng"`
|
|
|
|
|
GLMSearch GLMSearchConfig `yaml:"glm_search,omitempty" json:"glm_search"`
|
|
|
|
|
BaiduSearch BaiduSearchConfig `yaml:"baidu_search,omitempty" json:"baidu_search"`
|
2026-03-18 03:55:30 +00:00
|
|
|
// PreferNative controls whether to use provider-native web search when
|
|
|
|
|
// the active LLM supports it (e.g. OpenAI web_search_preview). When true,
|
|
|
|
|
// the client-side web_search tool is hidden to avoid duplicate search surfaces,
|
|
|
|
|
// and the provider's built-in search is used instead. Falls back to client-side
|
|
|
|
|
// search when the provider does not support native search.
|
2026-04-03 02:56:26 +00:00
|
|
|
PreferNative bool `yaml:"-" json:"prefer_native" env:"PICOCLAW_TOOLS_WEB_PREFER_NATIVE"`
|
2026-02-24 09:16:16 +00:00
|
|
|
// Proxy is an optional proxy URL for web tools (http/https/socks5/socks5h).
|
|
|
|
|
// For authenticated proxies, prefer HTTP_PROXY/HTTPS_PROXY env vars instead of embedding credentials in config.
|
2026-04-03 02:56:26 +00:00
|
|
|
Proxy string `yaml:"-" json:"proxy,omitempty" env:"PICOCLAW_TOOLS_WEB_PROXY"`
|
|
|
|
|
FetchLimitBytes int64 `yaml:"-" json:"fetch_limit_bytes,omitempty" env:"PICOCLAW_TOOLS_WEB_FETCH_LIMIT_BYTES"`
|
|
|
|
|
Format string `yaml:"-" json:"format,omitempty" env:"PICOCLAW_TOOLS_WEB_FORMAT"`
|
|
|
|
|
PrivateHostWhitelist FlexibleStringSlice `yaml:"-" json:"private_host_whitelist,omitempty" env:"PICOCLAW_TOOLS_WEB_PRIVATE_HOST_WHITELIST"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-15 10:41:39 +00:00
|
|
|
type CronToolsConfig struct {
|
2026-03-17 01:44:32 +00:00
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_TOOLS_CRON_"`
|
2026-03-27 16:03:34 +00:00
|
|
|
ExecTimeoutMinutes int ` json:"exec_timeout_minutes" env:"PICOCLAW_TOOLS_CRON_EXEC_TIMEOUT_MINUTES"` // 0 means no timeout
|
|
|
|
|
AllowCommand bool ` json:"allow_command" env:"PICOCLAW_TOOLS_CRON_ALLOW_COMMAND"`
|
2026-02-15 10:41:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 11:31:15 +00:00
|
|
|
type ExecConfig struct {
|
2026-03-05 06:53:26 +00:00
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_TOOLS_EXEC_"`
|
2026-03-27 16:03:34 +00:00
|
|
|
EnableDenyPatterns bool ` json:"enable_deny_patterns" env:"PICOCLAW_TOOLS_EXEC_ENABLE_DENY_PATTERNS"`
|
|
|
|
|
AllowRemote bool ` json:"allow_remote" env:"PICOCLAW_TOOLS_EXEC_ALLOW_REMOTE"`
|
|
|
|
|
CustomDenyPatterns []string ` json:"custom_deny_patterns" env:"PICOCLAW_TOOLS_EXEC_CUSTOM_DENY_PATTERNS"`
|
|
|
|
|
CustomAllowPatterns []string ` json:"custom_allow_patterns" env:"PICOCLAW_TOOLS_EXEC_CUSTOM_ALLOW_PATTERNS"`
|
|
|
|
|
TimeoutSeconds int ` json:"timeout_seconds" env:"PICOCLAW_TOOLS_EXEC_TIMEOUT_SECONDS"` // 0 means use default (60s)
|
2026-03-05 06:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SkillsToolsConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
ToolConfig ` yaml:"-" envPrefix:"PICOCLAW_TOOLS_SKILLS_"`
|
|
|
|
|
Registries SkillsRegistriesConfig `yaml:",inline,omitempty" json:"registries"`
|
|
|
|
|
Github SkillsGithubConfig `yaml:"github,omitempty" json:"github"`
|
|
|
|
|
MaxConcurrentSearches int `yaml:"-" json:"max_concurrent_searches" env:"PICOCLAW_TOOLS_SKILLS_MAX_CONCURRENT_SEARCHES"`
|
|
|
|
|
SearchCache SearchCacheConfig `yaml:"-" json:"search_cache"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 12:24:32 +00:00
|
|
|
type MediaCleanupConfig struct {
|
2026-03-05 06:53:26 +00:00
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_MEDIA_CLEANUP_"`
|
2026-03-27 16:03:34 +00:00
|
|
|
MaxAge int ` json:"max_age_minutes" env:"PICOCLAW_MEDIA_CLEANUP_MAX_AGE"`
|
|
|
|
|
Interval int ` json:"interval_minutes" env:"PICOCLAW_MEDIA_CLEANUP_INTERVAL"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-09 08:32:21 +00:00
|
|
|
type ReadFileToolConfig struct {
|
2026-04-07 13:19:06 +00:00
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
|
MaxReadFileSize int `json:"max_read_file_size"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ReadFileModeBytes = "bytes"
|
|
|
|
|
ReadFileModeLines = "lines"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (c ReadFileToolConfig) EffectiveMode() string {
|
|
|
|
|
switch strings.ToLower(strings.TrimSpace(c.Mode)) {
|
|
|
|
|
case ReadFileModeLines:
|
|
|
|
|
return ReadFileModeLines
|
|
|
|
|
case "", ReadFileModeBytes:
|
|
|
|
|
return ReadFileModeBytes
|
|
|
|
|
default:
|
|
|
|
|
return ReadFileModeBytes
|
|
|
|
|
}
|
2026-03-09 08:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
type ToolsConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
AllowReadPaths []string `json:"allow_read_paths" yaml:"-" env:"PICOCLAW_TOOLS_ALLOW_READ_PATHS"`
|
|
|
|
|
AllowWritePaths []string `json:"allow_write_paths" yaml:"-" env:"PICOCLAW_TOOLS_ALLOW_WRITE_PATHS"`
|
2026-03-23 12:55:41 +00:00
|
|
|
// FilterSensitiveData controls whether to filter sensitive values (API keys,
|
|
|
|
|
// tokens, secrets) from tool results before sending to the LLM.
|
|
|
|
|
// Default: true (enabled)
|
2026-03-27 16:03:34 +00:00
|
|
|
FilterSensitiveData bool `json:"filter_sensitive_data" yaml:"-" env:"PICOCLAW_TOOLS_FILTER_SENSITIVE_DATA"`
|
2026-03-23 12:55:41 +00:00
|
|
|
// FilterMinLength is the minimum content length required for filtering.
|
|
|
|
|
// Content shorter than this will be returned unchanged for performance.
|
|
|
|
|
// Default: 8
|
2026-03-27 16:03:34 +00:00
|
|
|
FilterMinLength int `json:"filter_min_length" yaml:"-" env:"PICOCLAW_TOOLS_FILTER_MIN_LENGTH"`
|
|
|
|
|
Web WebToolsConfig `json:"web" yaml:"web,omitempty"`
|
|
|
|
|
Cron CronToolsConfig `json:"cron" yaml:"-"`
|
|
|
|
|
Exec ExecConfig `json:"exec" yaml:"-"`
|
|
|
|
|
Skills SkillsToolsConfig `json:"skills" yaml:"skills,omitempty"`
|
|
|
|
|
MediaCleanup MediaCleanupConfig `json:"media_cleanup" yaml:"-"`
|
|
|
|
|
MCP MCPConfig `json:"mcp" yaml:"-"`
|
|
|
|
|
AppendFile ToolConfig `json:"append_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_APPEND_FILE_"`
|
|
|
|
|
EditFile ToolConfig `json:"edit_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_EDIT_FILE_"`
|
|
|
|
|
FindSkills ToolConfig `json:"find_skills" yaml:"-" envPrefix:"PICOCLAW_TOOLS_FIND_SKILLS_"`
|
|
|
|
|
I2C ToolConfig `json:"i2c" yaml:"-" envPrefix:"PICOCLAW_TOOLS_I2C_"`
|
|
|
|
|
InstallSkill ToolConfig `json:"install_skill" yaml:"-" envPrefix:"PICOCLAW_TOOLS_INSTALL_SKILL_"`
|
|
|
|
|
ListDir ToolConfig `json:"list_dir" yaml:"-" envPrefix:"PICOCLAW_TOOLS_LIST_DIR_"`
|
|
|
|
|
Message ToolConfig `json:"message" yaml:"-" envPrefix:"PICOCLAW_TOOLS_MESSAGE_"`
|
|
|
|
|
ReadFile ReadFileToolConfig `json:"read_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_READ_FILE_"`
|
|
|
|
|
SendFile ToolConfig `json:"send_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SEND_FILE_"`
|
2026-04-07 13:19:06 +00:00
|
|
|
SendTTS ToolConfig `json:"send_tts" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SEND_TTS_"`
|
2026-03-27 16:03:34 +00:00
|
|
|
Spawn ToolConfig `json:"spawn" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SPAWN_"`
|
|
|
|
|
SpawnStatus ToolConfig `json:"spawn_status" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SPAWN_STATUS_"`
|
|
|
|
|
SPI ToolConfig `json:"spi" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SPI_"`
|
|
|
|
|
Subagent ToolConfig `json:"subagent" yaml:"-" envPrefix:"PICOCLAW_TOOLS_SUBAGENT_"`
|
|
|
|
|
WebFetch ToolConfig `json:"web_fetch" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WEB_FETCH_"`
|
|
|
|
|
WriteFile ToolConfig `json:"write_file" yaml:"-" envPrefix:"PICOCLAW_TOOLS_WRITE_FILE_"`
|
2026-02-20 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-23 12:55:41 +00:00
|
|
|
// IsFilterSensitiveDataEnabled returns true if sensitive data filtering is enabled
|
|
|
|
|
func (c *ToolsConfig) IsFilterSensitiveDataEnabled() bool {
|
|
|
|
|
return c.FilterSensitiveData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetFilterMinLength returns the minimum content length for filtering (default: 8)
|
|
|
|
|
func (c *ToolsConfig) GetFilterMinLength() int {
|
|
|
|
|
if c.FilterMinLength <= 0 {
|
|
|
|
|
return 8
|
|
|
|
|
}
|
|
|
|
|
return c.FilterMinLength
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 10:55:04 +00:00
|
|
|
type SearchCacheConfig struct {
|
2026-02-20 18:03:11 +00:00
|
|
|
MaxSize int `json:"max_size" env:"PICOCLAW_SKILLS_SEARCH_CACHE_MAX_SIZE"`
|
2026-02-20 10:55:04 +00:00
|
|
|
TTLSeconds int `json:"ttl_seconds" env:"PICOCLAW_SKILLS_SEARCH_CACHE_TTL_SECONDS"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SkillsRegistriesConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
ClawHub ClawHubRegistryConfig `json:"clawhub" yaml:"clawhub,omitempty"`
|
2026-02-20 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 06:04:02 +00:00
|
|
|
type SkillsGithubConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Token SecureString `json:"token,omitzero" yaml:"token,omitempty" env:"PICOCLAW_TOOLS_SKILLS_GITHUB_TOKEN"`
|
|
|
|
|
Proxy string `json:"proxy,omitempty" yaml:"-" env:"PICOCLAW_TOOLS_SKILLS_GITHUB_PROXY"`
|
2026-03-13 06:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 10:55:04 +00:00
|
|
|
type ClawHubRegistryConfig struct {
|
2026-03-27 16:03:34 +00:00
|
|
|
Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_ENABLED"`
|
|
|
|
|
BaseURL string `json:"base_url" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_BASE_URL"`
|
|
|
|
|
AuthToken SecureString `json:"auth_token,omitzero" yaml:"auth_token,omitempty" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_AUTH_TOKEN"`
|
|
|
|
|
SearchPath string `json:"search_path" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_SEARCH_PATH"`
|
|
|
|
|
SkillsPath string `json:"skills_path" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_SKILLS_PATH"`
|
|
|
|
|
DownloadPath string `json:"download_path" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_DOWNLOAD_PATH"`
|
|
|
|
|
Timeout int `json:"timeout" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_TIMEOUT"`
|
|
|
|
|
MaxZipSize int `json:"max_zip_size" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_MAX_ZIP_SIZE"`
|
|
|
|
|
MaxResponseSize int `json:"max_response_size" yaml:"-" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_MAX_RESPONSE_SIZE"`
|
2026-03-21 17:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-15 09:26:36 +00:00
|
|
|
// MCPServerConfig defines configuration for a single MCP server
|
|
|
|
|
type MCPServerConfig struct {
|
|
|
|
|
// Enabled indicates whether this MCP server is active
|
|
|
|
|
Enabled bool `json:"enabled"`
|
2026-03-19 09:03:17 +00:00
|
|
|
// Deferred controls whether this server's tools are registered as hidden (deferred/discovery mode).
|
|
|
|
|
// When nil, the global Discovery.Enabled setting applies.
|
|
|
|
|
// When explicitly set to true or false, it overrides the global setting for this server only.
|
|
|
|
|
Deferred *bool `json:"deferred,omitempty"`
|
2026-02-15 09:26:36 +00:00
|
|
|
// Command is the executable to run (e.g., "npx", "python", "/path/to/server")
|
|
|
|
|
Command string `json:"command"`
|
|
|
|
|
// Args are the arguments to pass to the command
|
|
|
|
|
Args []string `json:"args,omitempty"`
|
|
|
|
|
// Env are environment variables to set for the server process (stdio only)
|
|
|
|
|
Env map[string]string `json:"env,omitempty"`
|
|
|
|
|
// EnvFile is the path to a file containing environment variables (stdio only)
|
2026-02-19 11:43:48 +00:00
|
|
|
EnvFile string `json:"env_file,omitempty"`
|
2026-02-15 09:26:36 +00:00
|
|
|
// Type is "stdio", "sse", or "http" (default: stdio if command is set, sse if url is set)
|
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
|
// URL is used for SSE/HTTP transport
|
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
|
// Headers are HTTP headers to send with requests (sse/http only)
|
|
|
|
|
Headers map[string]string `json:"headers,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MCPConfig defines configuration for all MCP servers
|
|
|
|
|
type MCPConfig struct {
|
2026-03-09 17:21:49 +00:00
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_TOOLS_MCP_"`
|
|
|
|
|
Discovery ToolDiscoveryConfig ` json:"discovery"`
|
2026-04-07 13:19:06 +00:00
|
|
|
// MaxInlineTextChars controls how much MCP text stays inline before it is saved as an artifact.
|
|
|
|
|
MaxInlineTextChars int `json:"max_inline_text_chars,omitempty" env:"PICOCLAW_TOOLS_MCP_MAX_INLINE_TEXT_CHARS"`
|
2026-02-15 09:26:36 +00:00
|
|
|
// Servers is a map of server name to server configuration
|
|
|
|
|
Servers map[string]MCPServerConfig `json:"servers,omitempty"`
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-07 13:19:06 +00:00
|
|
|
const DefaultMCPMaxInlineTextChars = 16 * 1024
|
|
|
|
|
|
|
|
|
|
func (c *MCPConfig) GetMaxInlineTextChars() int {
|
|
|
|
|
if c.MaxInlineTextChars > 0 {
|
|
|
|
|
return c.MaxInlineTextChars
|
|
|
|
|
}
|
|
|
|
|
return DefaultMCPMaxInlineTextChars
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
func LoadConfig(path string) (*Config, error) {
|
2026-03-24 02:26:11 +00:00
|
|
|
logger.Debugf("loading config from %s", path)
|
2026-03-27 16:03:34 +00:00
|
|
|
|
|
|
|
|
updateResolver(filepath.Dir(path))
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
data, err := os.ReadFile(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.WarnF(
|
|
|
|
|
"config file not found, using default config",
|
|
|
|
|
map[string]any{"path": path},
|
|
|
|
|
)
|
2026-03-11 08:33:01 +00:00
|
|
|
return DefaultConfig(), nil
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
2026-03-24 02:26:11 +00:00
|
|
|
logger.Errorf("failed to read config file: %v", err)
|
2026-02-04 11:06:13 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
// First, try to detect config version by reading the version field
|
|
|
|
|
var versionInfo struct {
|
|
|
|
|
Version int `json:"version"`
|
2026-02-24 09:57:28 +00:00
|
|
|
}
|
2026-03-11 08:33:01 +00:00
|
|
|
if e := json.Unmarshal(data, &versionInfo); e != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to detect config version: %w", e)
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
2026-03-23 06:50:33 +00:00
|
|
|
if len(data) <= 10 {
|
2026-03-24 02:26:11 +00:00
|
|
|
logger.Warn(fmt.Sprintf("content is [%s]", string(data)))
|
2026-03-27 16:03:34 +00:00
|
|
|
return DefaultConfig(), nil
|
2026-02-24 09:57:28 +00:00
|
|
|
}
|
2026-02-04 11:06:13 +00:00
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
// Load config based on detected version
|
|
|
|
|
var cfg *Config
|
|
|
|
|
switch versionInfo.Version {
|
|
|
|
|
case 0:
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.InfoF(
|
|
|
|
|
"config migrate start",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-11 08:33:01 +00:00
|
|
|
// Legacy config (no version field)
|
|
|
|
|
v, e := loadConfigV0(data)
|
|
|
|
|
if e != nil {
|
|
|
|
|
return nil, e
|
|
|
|
|
}
|
|
|
|
|
cfg, e = v.Migrate()
|
|
|
|
|
if e != nil {
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.ErrorF(
|
|
|
|
|
"config migrate fail",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-11 08:33:01 +00:00
|
|
|
return nil, e
|
|
|
|
|
}
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.InfoF(
|
|
|
|
|
"config migrate success",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-24 02:26:11 +00:00
|
|
|
err = makeBackup(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-03-24 12:02:58 +00:00
|
|
|
// Load existing security config and merge with migrated one to prevent data loss
|
2026-03-27 16:03:34 +00:00
|
|
|
secErr := loadSecurityConfig(cfg, securityPath(path))
|
|
|
|
|
if secErr != nil && !os.IsNotExist(secErr) {
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.WarnF(
|
|
|
|
|
"failed to load existing security config during migration",
|
|
|
|
|
map[string]any{"error": secErr},
|
|
|
|
|
)
|
2026-03-27 16:03:34 +00:00
|
|
|
return nil, fmt.Errorf("failed to load existing security config: %w", secErr)
|
2026-03-24 12:02:58 +00:00
|
|
|
}
|
2026-03-24 02:26:11 +00:00
|
|
|
defer func(cfg *Config) {
|
2026-03-11 08:33:01 +00:00
|
|
|
_ = SaveConfig(path, cfg)
|
2026-03-24 02:26:11 +00:00
|
|
|
}(cfg)
|
2026-03-30 06:01:20 +00:00
|
|
|
case 1:
|
|
|
|
|
// V1→V2 migration: infer Enabled and migrate channel config fields
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.InfoF(
|
|
|
|
|
"config migrate start",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-30 06:01:20 +00:00
|
|
|
cfg, err = loadConfig(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
secPath := securityPath(path)
|
|
|
|
|
err = loadSecurityConfig(cfg, secPath)
|
|
|
|
|
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
|
|
|
return nil, fmt.Errorf("failed to load security config: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldCfg := &configV1{Config: *cfg}
|
|
|
|
|
cfg, err = oldCfg.Migrate()
|
|
|
|
|
if err != nil {
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.ErrorF(
|
|
|
|
|
"config migrate fail",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-30 06:01:20 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = makeBackup(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer func(cfg *Config) {
|
|
|
|
|
_ = SaveConfig(path, cfg)
|
|
|
|
|
}(cfg)
|
2026-04-03 02:56:26 +00:00
|
|
|
logger.InfoF(
|
|
|
|
|
"config migrate success",
|
|
|
|
|
map[string]any{"from": versionInfo.Version, "to": CurrentVersion},
|
|
|
|
|
)
|
2026-03-11 08:33:01 +00:00
|
|
|
case CurrentVersion:
|
|
|
|
|
// Current version
|
|
|
|
|
cfg, err = loadConfig(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-03-27 16:03:34 +00:00
|
|
|
// Load security configuration
|
2026-03-25 07:29:43 +00:00
|
|
|
secPath := securityPath(path)
|
2026-03-27 16:03:34 +00:00
|
|
|
err = loadSecurityConfig(cfg, secPath)
|
|
|
|
|
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
2026-03-24 02:26:11 +00:00
|
|
|
return nil, fmt.Errorf("failed to load security config: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("unsupported config version: %d", versionInfo.Version)
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:01:20 +00:00
|
|
|
if err = env.Parse(cfg); err != nil {
|
2026-02-04 11:06:13 +00:00
|
|
|
return nil, err
|
2026-02-18 17:30:19 +00:00
|
|
|
}
|
|
|
|
|
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
// Expand multi-key configs into separate entries for key-level failover
|
2026-03-21 17:55:00 +00:00
|
|
|
cfg.ModelList = expandMultiKeyModels(cfg.ModelList)
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
|
2026-02-19 04:45:12 +00:00
|
|
|
// Validate model_list for uniqueness and required fields
|
2026-03-30 06:01:20 +00:00
|
|
|
if err = cfg.ValidateModelList(); err != nil {
|
2026-02-19 04:45:12 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
// Ensure Workspace has a default if not set
|
|
|
|
|
if cfg.Agents.Defaults.Workspace == "" {
|
2026-03-28 17:14:39 +00:00
|
|
|
homePath := GetHome()
|
2026-03-11 08:33:01 +00:00
|
|
|
cfg.Agents.Defaults.Workspace = filepath.Join(homePath, pkg.WorkspaceName)
|
refactor(channels): standardize group chat trigger filtering (Phase 8)
Add unified ShouldRespondInGroup to BaseChannel, replacing scattered
per-channel group filtering logic. Introduce GroupTriggerConfig (with
mention_only + prefixes), TypingConfig, and PlaceholderConfig types.
Migrate Discord MentionOnly, OneBot checkGroupTrigger, and LINE
hardcoded mention-only to the shared mechanism. Add group trigger
entry points for Slack, Telegram, QQ, Feishu, DingTalk, and WeCom.
Legacy config fields are preserved with automatic migration.
2026-02-22 20:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:33:01 +00:00
|
|
|
return cfg, nil
|
refactor(channels): standardize group chat trigger filtering (Phase 8)
Add unified ShouldRespondInGroup to BaseChannel, replacing scattered
per-channel group filtering logic. Introduce GroupTriggerConfig (with
mention_only + prefixes), TypingConfig, and PlaceholderConfig types.
Migrate Discord MentionOnly, OneBot checkGroupTrigger, and LINE
hardcoded mention-only to the shared mechanism. Add group trigger
entry points for Slack, Telegram, QQ, Feishu, DingTalk, and WeCom.
Legacy config fields are preserved with automatic migration.
2026-02-22 20:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 02:26:11 +00:00
|
|
|
func makeBackup(path string) error {
|
|
|
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2026-03-30 06:01:20 +00:00
|
|
|
dateSuffix := time.Now().Format(".20060102.bak")
|
|
|
|
|
// Backup config file
|
|
|
|
|
bakPath := path + dateSuffix
|
2026-03-24 02:26:11 +00:00
|
|
|
if err := fileutil.CopyFile(path, bakPath, 0o600); err != nil {
|
|
|
|
|
logger.ErrorF("failed to create config backup", map[string]any{"error": err})
|
|
|
|
|
return fmt.Errorf("failed to create config backup: %w", err)
|
|
|
|
|
}
|
2026-03-30 06:01:20 +00:00
|
|
|
// Backup security config file
|
|
|
|
|
secPath := securityPath(path)
|
|
|
|
|
if _, err := os.Stat(secPath); err == nil {
|
|
|
|
|
secBakPath := secPath + dateSuffix
|
|
|
|
|
if secErr := fileutil.CopyFile(secPath, secBakPath, 0o600); secErr != nil {
|
|
|
|
|
logger.ErrorF("failed to create security backup", map[string]any{"error": secErr})
|
|
|
|
|
return fmt.Errorf("failed to create security backup: %w", secErr)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-24 02:26:11 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-21 17:55:00 +00:00
|
|
|
func toNameIndex(list []*ModelConfig) []string {
|
|
|
|
|
nameList := make([]string, 0, len(list))
|
|
|
|
|
countMap := make(map[string]int)
|
|
|
|
|
for _, model := range list {
|
|
|
|
|
name := model.ModelName
|
|
|
|
|
index := countMap[name]
|
|
|
|
|
nameList = append(nameList, fmt.Sprintf("%s:%d", name, index))
|
|
|
|
|
countMap[name]++
|
|
|
|
|
}
|
|
|
|
|
return nameList
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
func SaveConfig(path string, cfg *Config) error {
|
2026-03-27 16:03:34 +00:00
|
|
|
if cfg.Version < CurrentVersion {
|
2026-03-11 08:33:01 +00:00
|
|
|
cfg.Version = CurrentVersion
|
|
|
|
|
}
|
2026-03-24 15:56:45 +00:00
|
|
|
// Filter out virtual models before serializing to config file
|
|
|
|
|
nonVirtualModels := make([]*ModelConfig, 0, len(cfg.ModelList))
|
|
|
|
|
for _, m := range cfg.ModelList {
|
|
|
|
|
if !m.isVirtual {
|
|
|
|
|
nonVirtualModels = append(nonVirtualModels, m)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Temporarily replace ModelList with filtered version for serialization
|
|
|
|
|
originalModelList := cfg.ModelList
|
2026-03-30 06:01:20 +00:00
|
|
|
defer func() {
|
|
|
|
|
// Restore original ModelList after serialization
|
|
|
|
|
cfg.ModelList = originalModelList
|
|
|
|
|
}()
|
2026-03-24 15:56:45 +00:00
|
|
|
cfg.ModelList = nonVirtualModels
|
|
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
if err := saveSecurityConfig(securityPath(path), cfg); err != nil {
|
|
|
|
|
logger.ErrorCF("config", "cannot save .security.yml", map[string]any{"error": err})
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
data, err := json.MarshalIndent(cfg, "", " ")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2026-03-24 08:24:12 +00:00
|
|
|
logger.Infof("saving config to %s", path)
|
2026-02-24 15:57:13 +00:00
|
|
|
return fileutil.WriteFileAtomic(path, data, 0o600)
|
2026-02-04 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Config) WorkspacePath() string {
|
|
|
|
|
return expandHome(c.Agents.Defaults.Workspace)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func expandHome(path string) string {
|
|
|
|
|
if path == "" {
|
|
|
|
|
return path
|
|
|
|
|
}
|
|
|
|
|
if path[0] == '~' {
|
|
|
|
|
home, _ := os.UserHomeDir()
|
|
|
|
|
if len(path) > 1 && path[1] == '/' {
|
|
|
|
|
return home + path[1:]
|
|
|
|
|
}
|
|
|
|
|
return home
|
|
|
|
|
}
|
|
|
|
|
return path
|
|
|
|
|
}
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
|
|
|
|
|
// GetModelConfig returns the ModelConfig for the given model name.
|
|
|
|
|
// If multiple configs exist with the same model_name, it uses round-robin
|
|
|
|
|
// selection for load balancing. Returns an error if the model is not found.
|
|
|
|
|
func (c *Config) GetModelConfig(modelName string) (*ModelConfig, error) {
|
2026-02-20 03:34:52 +00:00
|
|
|
matches := c.findMatches(modelName)
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
if len(matches) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("model %q not found in model_list or providers", modelName)
|
|
|
|
|
}
|
|
|
|
|
if len(matches) == 1 {
|
2026-03-21 17:55:00 +00:00
|
|
|
return matches[0], nil
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 03:34:52 +00:00
|
|
|
// Multiple configs - use round-robin for load balancing
|
2026-03-17 13:59:04 +00:00
|
|
|
idx := (rrCounter.Add(1) - 1) % uint64(len(matches))
|
2026-03-21 17:55:00 +00:00
|
|
|
return matches[idx], nil
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 03:34:52 +00:00
|
|
|
// findMatches finds all ModelConfig entries with the given model_name.
|
2026-03-21 17:55:00 +00:00
|
|
|
func (c *Config) findMatches(modelName string) []*ModelConfig {
|
|
|
|
|
var matches []*ModelConfig
|
2026-02-18 17:03:34 +00:00
|
|
|
for i := range c.ModelList {
|
|
|
|
|
if c.ModelList[i].ModelName == modelName {
|
|
|
|
|
matches = append(matches, c.ModelList[i])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return matches
|
|
|
|
|
}
|
|
|
|
|
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
// ValidateModelList validates all ModelConfig entries in the model_list.
|
2026-02-20 03:46:28 +00:00
|
|
|
// It checks that each model config is valid.
|
|
|
|
|
// Note: Multiple entries with the same model_name are allowed for load balancing.
|
feat: add model_list configuration for zero-code provider addition
- Add ModelConfig struct with protocol prefix support (openai/, anthropic/, etc.)
- Implement GetModelConfig with round-robin load balancing
- Add CreateProviderFromConfig factory for protocol-based routing
- Add ModelRegistry for thread-safe endpoint selection
- Maintain full backward compatibility with legacy providers config
- Update README.md and README.zh.md with model_list documentation
- Add migration guide at docs/migration/model-list-migration.md
Supported protocols: openai, anthropic, antigravity, claude-cli, codex-cli,
github-copilot, openrouter, groq, deepseek, cerebras, qwen, zhipu, gemini
Closes #283
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 15:26:00 +00:00
|
|
|
func (c *Config) ValidateModelList() error {
|
|
|
|
|
for i := range c.ModelList {
|
|
|
|
|
if err := c.ModelList[i].Validate(); err != nil {
|
|
|
|
|
return fmt.Errorf("model_list[%d]: %w", i, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2026-03-05 06:53:26 +00:00
|
|
|
|
2026-03-27 16:03:34 +00:00
|
|
|
func (c *Config) SecurityCopyFrom(path string) error {
|
|
|
|
|
return loadSecurityConfig(c, securityPath(path))
|
2026-03-24 10:37:41 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-21 17:55:00 +00:00
|
|
|
// expandMultiKeyModels expands ModelConfig entries with multiple API keys into
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
// separate entries for key-level failover. Each key gets its own ModelConfig entry,
|
|
|
|
|
// and the original entry's fallbacks are set up to chain through the expanded entries.
|
|
|
|
|
//
|
|
|
|
|
// Example: {"model_name": "gpt-4", "api_keys": ["k1", "k2", "k3"]}
|
|
|
|
|
// Becomes:
|
2026-03-21 17:55:00 +00:00
|
|
|
// - {"model_name": "gpt-4", "api_keys": ["k1"], "fallbacks": ["gpt-4__key_1", "gpt-4__key_2"]}
|
|
|
|
|
// - {"model_name": "gpt-4__key_1", "api_keys": {"k2"}}
|
|
|
|
|
// - {"model_name": "gpt-4__key_2", "api_keys": {"k3"}}
|
|
|
|
|
func expandMultiKeyModels(models []*ModelConfig) []*ModelConfig {
|
|
|
|
|
var expanded []*ModelConfig
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
|
|
|
|
|
for _, m := range models {
|
2026-03-27 16:03:34 +00:00
|
|
|
keys := m.APIKeys.Values()
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
|
|
|
|
|
// Single key or no keys: keep as-is
|
|
|
|
|
if len(keys) <= 1 {
|
|
|
|
|
expanded = append(expanded, m)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Multiple keys: expand
|
|
|
|
|
originalName := m.ModelName
|
|
|
|
|
|
|
|
|
|
// Create entries for additional keys (key_1, key_2, ...)
|
|
|
|
|
var fallbackNames []string
|
|
|
|
|
for i := 1; i < len(keys); i++ {
|
|
|
|
|
suffix := fmt.Sprintf("__key_%d", i)
|
|
|
|
|
expandedName := originalName + suffix
|
|
|
|
|
|
|
|
|
|
// Create a copy for the additional key
|
2026-03-21 17:55:00 +00:00
|
|
|
additionalEntry := &ModelConfig{
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
ModelName: expandedName,
|
|
|
|
|
Model: m.Model,
|
|
|
|
|
APIBase: m.APIBase,
|
2026-03-27 16:03:34 +00:00
|
|
|
APIKeys: SimpleSecureStrings(keys[i]),
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
Proxy: m.Proxy,
|
|
|
|
|
AuthMethod: m.AuthMethod,
|
|
|
|
|
ConnectMode: m.ConnectMode,
|
|
|
|
|
Workspace: m.Workspace,
|
|
|
|
|
RPM: m.RPM,
|
|
|
|
|
MaxTokensField: m.MaxTokensField,
|
|
|
|
|
RequestTimeout: m.RequestTimeout,
|
|
|
|
|
ThinkingLevel: m.ThinkingLevel,
|
2026-03-22 07:49:25 +00:00
|
|
|
ExtraBody: m.ExtraBody,
|
2026-04-07 13:19:06 +00:00
|
|
|
CustomHeaders: m.CustomHeaders,
|
|
|
|
|
UserAgent: m.UserAgent,
|
2026-03-24 15:56:45 +00:00
|
|
|
isVirtual: true,
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
}
|
|
|
|
|
expanded = append(expanded, additionalEntry)
|
|
|
|
|
fallbackNames = append(fallbackNames, expandedName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the primary entry with first key and fallbacks
|
2026-03-21 17:55:00 +00:00
|
|
|
primaryEntry := &ModelConfig{
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
ModelName: originalName,
|
|
|
|
|
Model: m.Model,
|
|
|
|
|
APIBase: m.APIBase,
|
|
|
|
|
Proxy: m.Proxy,
|
|
|
|
|
AuthMethod: m.AuthMethod,
|
|
|
|
|
ConnectMode: m.ConnectMode,
|
|
|
|
|
Workspace: m.Workspace,
|
|
|
|
|
RPM: m.RPM,
|
|
|
|
|
MaxTokensField: m.MaxTokensField,
|
|
|
|
|
RequestTimeout: m.RequestTimeout,
|
|
|
|
|
ThinkingLevel: m.ThinkingLevel,
|
2026-03-22 07:49:25 +00:00
|
|
|
ExtraBody: m.ExtraBody,
|
2026-04-07 13:19:06 +00:00
|
|
|
CustomHeaders: m.CustomHeaders,
|
|
|
|
|
UserAgent: m.UserAgent,
|
2026-03-27 16:03:34 +00:00
|
|
|
APIKeys: SimpleSecureStrings(keys[0]),
|
feat(config): support multiple API keys for failover (#1707)
* feat(config): support multiple API keys for failover
Add api_keys field to ModelConfig to support multiple API keys with
automatic failover. When multiple keys are configured, they are expanded
into separate model entries with fallbacks set up for key-level failover.
Example config:
{
"model_name": "glm-4.7",
"model": "zhipu/glm-4.7",
"api_keys": ["key1", "key2", "key3"]
}
Expands internally to:
- glm-4.7 (key1) -> fallbacks: [glm-4.7__key_1, glm-4.7__key_2]
- glm-4.7__key_1 (key2)
- glm-4.7__key_2 (key3)
Backward compatible: single api_key still works as before.
* fix(providers): change cooldown tracking from provider to ModelKey
This enables proper key-switching when multiple API keys share the same
provider. Previously, when one key failed, all keys were blocked because
cooldown was tracked per-provider.
Now each (provider, model) combination has independent cooldown, allowing
fallback to alternate keys when one is rate limited.
Includes TestMultiKeyWithModelFallback and related failover tests.
2026-03-18 16:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepend new fallbacks to existing ones
|
|
|
|
|
if len(fallbackNames) > 0 {
|
|
|
|
|
primaryEntry.Fallbacks = append(fallbackNames, m.Fallbacks...)
|
|
|
|
|
} else if len(m.Fallbacks) > 0 {
|
|
|
|
|
primaryEntry.Fallbacks = m.Fallbacks
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expanded = append(expanded, primaryEntry)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return expanded
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 06:53:26 +00:00
|
|
|
func (t *ToolsConfig) IsToolEnabled(name string) bool {
|
|
|
|
|
switch name {
|
|
|
|
|
case "web":
|
|
|
|
|
return t.Web.Enabled
|
|
|
|
|
case "cron":
|
|
|
|
|
return t.Cron.Enabled
|
|
|
|
|
case "exec":
|
|
|
|
|
return t.Exec.Enabled
|
|
|
|
|
case "skills":
|
|
|
|
|
return t.Skills.Enabled
|
|
|
|
|
case "media_cleanup":
|
|
|
|
|
return t.MediaCleanup.Enabled
|
|
|
|
|
case "append_file":
|
|
|
|
|
return t.AppendFile.Enabled
|
|
|
|
|
case "edit_file":
|
|
|
|
|
return t.EditFile.Enabled
|
|
|
|
|
case "find_skills":
|
|
|
|
|
return t.FindSkills.Enabled
|
|
|
|
|
case "i2c":
|
|
|
|
|
return t.I2C.Enabled
|
|
|
|
|
case "install_skill":
|
|
|
|
|
return t.InstallSkill.Enabled
|
|
|
|
|
case "list_dir":
|
|
|
|
|
return t.ListDir.Enabled
|
|
|
|
|
case "message":
|
|
|
|
|
return t.Message.Enabled
|
|
|
|
|
case "read_file":
|
|
|
|
|
return t.ReadFile.Enabled
|
|
|
|
|
case "spawn":
|
|
|
|
|
return t.Spawn.Enabled
|
2026-03-17 06:41:43 +00:00
|
|
|
case "spawn_status":
|
|
|
|
|
return t.SpawnStatus.Enabled
|
2026-03-05 06:53:26 +00:00
|
|
|
case "spi":
|
|
|
|
|
return t.SPI.Enabled
|
|
|
|
|
case "subagent":
|
|
|
|
|
return t.Subagent.Enabled
|
|
|
|
|
case "web_fetch":
|
|
|
|
|
return t.WebFetch.Enabled
|
feat(feishu,tools): add outbound media delivery via send_file tool (#1156)
* feat(feishu): implement SendMedia and add send_file tool
Add outbound media support for the Feishu channel so the agent can send
images and files to users via the MediaStore pipeline.
Feishu channel:
- SendMedia dispatches media parts as image or file uploads
- sendImage uploads via Image.Create then sends image message
- sendFile uploads via File.Create then sends file message
- feishuFileType maps extensions to Feishu file_type values
send_file tool:
- New tool lets the LLM send a local file to the current chat
- Validates path, registers file in MediaStore, returns media ref
- Agent loop wires tool registration, MediaStore propagation, and
context updates
Tested on Radxa Cubie A7A (arm64) with Feishu websocket channel.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(agent): publish outbound media regardless of SendResponse flag
The SendResponse flag controls whether the agent loop publishes the
final text response (callers that publish it themselves set this to
false). However, the media publish path was also gated behind this
flag, which meant tool-produced media was silently dropped for normal
channel messages.
Media should be published immediately when a tool returns media refs,
independent of how the text response is delivered.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(tools): use magic-bytes MIME detection and add file size limit to send_file
- Replace hardcoded extension-to-MIME map with h2non/filetype (magic
bytes) + mime.TypeByExtension fallback, consistent with the vision
pipeline in resolveMediaRefs
- Add configurable max file size check (defaults to config.DefaultMaxMediaSize,
20 MB) to prevent oversized uploads
- Add tests for magic-bytes detection, extension fallback, size limit,
and default max size
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor(agent): add ForEachTool to AgentRegistry for cross-agent tool lookup
Extract the pattern of iterating agents to find a named tool into
AgentRegistry.ForEachTool, simplifying SetMediaStore propagation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(agent,tools): adapt send_file to ctx-based channel injection after upstream refactor
Replace ContextualTool interface (removed upstream) with direct ctx
reading in SendFileTool.Execute, using ToolChannel/ToolChatID helpers.
Remove updateToolContexts which is no longer needed since ExecuteWithContext
already injects channel/chatID into ctx for all tools.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat(tools): support toggling send_file tool via config
Add SendFileConfig with Enabled field to ToolsConfig, defaulting to
true. Wrap send_file tool registration in loop.go with the config
check, consistent with the pattern used by other tools.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 11:42:52 +00:00
|
|
|
case "send_file":
|
|
|
|
|
return t.SendFile.Enabled
|
2026-04-07 13:19:06 +00:00
|
|
|
case "send_tts":
|
|
|
|
|
return t.SendTTS.Enabled
|
2026-03-05 06:53:26 +00:00
|
|
|
case "write_file":
|
|
|
|
|
return t.WriteFile.Enabled
|
|
|
|
|
case "mcp":
|
|
|
|
|
return t.MCP.Enabled
|
|
|
|
|
default:
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|