2026-02-04 11:06:13 +00:00
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
2026-02-12 05:45:45 +00:00
|
|
|
|
"fmt"
|
2026-02-04 11:06:13 +00:00
|
|
|
|
"os"
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
"path/filepath"
|
2026-03-10 08:34:11 +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-02-04 11:06:13 +00:00
|
|
|
|
|
|
|
|
|
|
"github.com/caarlos0/env/v11"
|
2026-02-26 12:38:11 +00:00
|
|
|
|
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
"github.com/sipeed/picoclaw/pkg/credential"
|
2026-02-24 15:57:13 +00:00
|
|
|
|
"github.com/sipeed/picoclaw/pkg/fileutil"
|
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-02-12 05:45:45 +00:00
|
|
|
|
// FlexibleStringSlice is a []string that also accepts JSON numbers,
|
|
|
|
|
|
// so allow_from can contain both "123" and 123.
|
2026-03-11 18:33:33 +00:00
|
|
|
|
// It also supports parsing comma-separated strings from environment variables,
|
|
|
|
|
|
// including both English (,) and Chinese (,) commas.
|
2026-02-12 05:45:45 +00:00
|
|
|
|
type FlexibleStringSlice []string
|
|
|
|
|
|
|
|
|
|
|
|
func (f *FlexibleStringSlice) UnmarshalJSON(data []byte) error {
|
|
|
|
|
|
// Try []string first
|
|
|
|
|
|
var ss []string
|
|
|
|
|
|
if err := json.Unmarshal(data, &ss); err == nil {
|
|
|
|
|
|
*f = ss
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try []interface{} to handle mixed types
|
2026-02-20 18:03:11 +00:00
|
|
|
|
var raw []any
|
2026-02-12 05:45:45 +00:00
|
|
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result := make([]string, 0, len(raw))
|
|
|
|
|
|
for _, v := range raw {
|
|
|
|
|
|
switch val := v.(type) {
|
|
|
|
|
|
case string:
|
|
|
|
|
|
result = append(result, val)
|
|
|
|
|
|
case float64:
|
|
|
|
|
|
result = append(result, fmt.Sprintf("%.0f", val))
|
|
|
|
|
|
default:
|
|
|
|
|
|
result = append(result, fmt.Sprintf("%v", val))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*f = result
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-11 18:33:33 +00:00
|
|
|
|
// UnmarshalText implements encoding.TextUnmarshaler to support env variable parsing.
|
|
|
|
|
|
// It handles comma-separated values with both English (,) and Chinese (,) commas.
|
|
|
|
|
|
func (f *FlexibleStringSlice) UnmarshalText(text []byte) error {
|
|
|
|
|
|
if len(text) == 0 {
|
|
|
|
|
|
*f = nil
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s := string(text)
|
|
|
|
|
|
// Replace Chinese comma with English comma, then split
|
|
|
|
|
|
s = strings.ReplaceAll(s, ",", ",")
|
|
|
|
|
|
parts := strings.Split(s, ",")
|
|
|
|
|
|
|
|
|
|
|
|
result := make([]string, 0, len(parts))
|
|
|
|
|
|
for _, part := range parts {
|
|
|
|
|
|
part = strings.TrimSpace(part)
|
|
|
|
|
|
if part != "" {
|
|
|
|
|
|
result = append(result, part)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*f = result
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type Config struct {
|
2026-02-20 03:34:52 +00:00
|
|
|
|
Agents AgentsConfig `json:"agents"`
|
|
|
|
|
|
Bindings []AgentBinding `json:"bindings,omitempty"`
|
|
|
|
|
|
Session SessionConfig `json:"session,omitempty"`
|
|
|
|
|
|
Channels ChannelsConfig `json:"channels"`
|
|
|
|
|
|
Providers ProvidersConfig `json:"providers,omitempty"`
|
|
|
|
|
|
ModelList []ModelConfig `json:"model_list"` // New model-centric provider configuration
|
|
|
|
|
|
Gateway GatewayConfig `json:"gateway"`
|
|
|
|
|
|
Tools ToolsConfig `json:"tools"`
|
|
|
|
|
|
Heartbeat HeartbeatConfig `json:"heartbeat"`
|
|
|
|
|
|
Devices DevicesConfig `json:"devices"`
|
2026-03-10 23:17:10 +00:00
|
|
|
|
Voice VoiceConfig `json:"voice"`
|
2026-03-10 09:42:05 +00:00
|
|
|
|
// BuildInfo contains build-time version information
|
|
|
|
|
|
BuildInfo BuildInfo `json:"build_info,omitempty"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
// to omit providers section when empty and session when empty
|
|
|
|
|
|
func (c Config) MarshalJSON() ([]byte, error) {
|
|
|
|
|
|
type Alias Config
|
|
|
|
|
|
aux := &struct {
|
|
|
|
|
|
Providers *ProvidersConfig `json:"providers,omitempty"`
|
|
|
|
|
|
Session *SessionConfig `json:"session,omitempty"`
|
|
|
|
|
|
*Alias
|
|
|
|
|
|
}{
|
|
|
|
|
|
Alias: (*Alias)(&c),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Only include providers if not empty
|
|
|
|
|
|
if !c.Providers.IsEmpty() {
|
|
|
|
|
|
aux.Providers = &c.Providers
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Only include session if not empty
|
|
|
|
|
|
if c.Session.DMScope != "" || len(c.Session.IdentityLinks) > 0 {
|
|
|
|
|
|
aux.Session = &c.Session
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return json.Marshal(aux)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type AgentsConfig struct {
|
|
|
|
|
|
Defaults AgentDefaults `json:"defaults"`
|
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
|
|
|
|
List []AgentConfig `json:"list,omitempty"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type PeerMatch struct {
|
|
|
|
|
|
Kind string `json:"kind"`
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type BindingMatch struct {
|
|
|
|
|
|
Channel string `json:"channel"`
|
|
|
|
|
|
AccountID string `json:"account_id,omitempty"`
|
|
|
|
|
|
Peer *PeerMatch `json:"peer,omitempty"`
|
|
|
|
|
|
GuildID string `json:"guild_id,omitempty"`
|
|
|
|
|
|
TeamID string `json:"team_id,omitempty"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type AgentBinding struct {
|
|
|
|
|
|
AgentID string `json:"agent_id"`
|
|
|
|
|
|
Match BindingMatch `json:"match"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SessionConfig struct {
|
|
|
|
|
|
DMScope string `json:"dm_scope,omitempty"`
|
|
|
|
|
|
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 10:08:50 +00:00
|
|
|
|
// ToolFeedbackConfig controls whether tool execution details are sent to the
|
|
|
|
|
|
// chat channel as real-time feedback messages. When enabled, every tool call
|
|
|
|
|
|
// produces a short notification with the tool name and its parameters.
|
|
|
|
|
|
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-03-19 10:08:50 +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"`
|
|
|
|
|
|
Model string `json:"model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_MODEL"` // Deprecated: use model_name instead
|
|
|
|
|
|
ModelFallbacks []string `json:"model_fallbacks,omitempty"`
|
|
|
|
|
|
ImageModel string `json:"image_model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_IMAGE_MODEL"`
|
|
|
|
|
|
ImageModelFallbacks []string `json:"image_model_fallbacks,omitempty"`
|
|
|
|
|
|
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
|
|
|
|
|
|
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"`
|
|
|
|
|
|
Routing *RoutingConfig `json:"routing,omitempty"`
|
|
|
|
|
|
ToolFeedback ToolFeedbackConfig `json:"tool_feedback,omitempty"`
|
2026-03-03 05:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-19 16:23:40 +00:00
|
|
|
|
const (
|
|
|
|
|
|
DefaultMaxMediaSize = 20 * 1024 * 1024 // 20 MB
|
|
|
|
|
|
DefaultWeComAIBotProcessingMessage = "⏳ Processing, please wait. The results will be sent shortly."
|
|
|
|
|
|
)
|
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 {
|
|
|
|
|
|
if d.ModelName != "" {
|
|
|
|
|
|
return d.ModelName
|
|
|
|
|
|
}
|
|
|
|
|
|
return d.Model
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ChannelsConfig struct {
|
2026-02-28 05:25:37 +00:00
|
|
|
|
WhatsApp WhatsAppConfig `json:"whatsapp"`
|
|
|
|
|
|
Telegram TelegramConfig `json:"telegram"`
|
|
|
|
|
|
Feishu FeishuConfig `json:"feishu"`
|
|
|
|
|
|
Discord DiscordConfig `json:"discord"`
|
|
|
|
|
|
MaixCam MaixCamConfig `json:"maixcam"`
|
|
|
|
|
|
QQ QQConfig `json:"qq"`
|
|
|
|
|
|
DingTalk DingTalkConfig `json:"dingtalk"`
|
|
|
|
|
|
Slack SlackConfig `json:"slack"`
|
2026-03-07 17:44:24 +00:00
|
|
|
|
Matrix MatrixConfig `json:"matrix"`
|
2026-02-28 05:25:37 +00:00
|
|
|
|
LINE LINEConfig `json:"line"`
|
|
|
|
|
|
OneBot OneBotConfig `json:"onebot"`
|
|
|
|
|
|
WeCom WeComConfig `json:"wecom"`
|
|
|
|
|
|
WeComApp WeComAppConfig `json:"wecom_app"`
|
|
|
|
|
|
WeComAIBot WeComAIBotConfig `json:"wecom_aibot"`
|
|
|
|
|
|
Pico PicoConfig `json:"pico"`
|
2026-03-20 12:43:40 +00:00
|
|
|
|
PicoClient PicoClientConfig `json:"pico_client"`
|
2026-03-05 10:46:01 +00:00
|
|
|
|
IRC IRCConfig `json:"irc"`
|
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 {
|
|
|
|
|
|
Enabled bool `json:"enabled,omitempty"`
|
|
|
|
|
|
Text string `json:"text,omitempty"`
|
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-02-27 12:25:02 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WHATSAPP_ENABLED"`
|
|
|
|
|
|
BridgeURL string `json:"bridge_url" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"`
|
|
|
|
|
|
UseNative bool `json:"use_native" env:"PICOCLAW_CHANNELS_WHATSAPP_USE_NATIVE"`
|
|
|
|
|
|
SessionStorePath string `json:"session_store_path" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WHATSAPP_ALLOW_FROM"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_WHATSAPP_REASONING_CHANNEL_ID"`
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TelegramConfig struct {
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_TELEGRAM_ENABLED"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_TELEGRAM_TOKEN"`
|
2026-03-03 09:27:57 +00:00
|
|
|
|
BaseURL string `json:"base_url" env:"PICOCLAW_CHANNELS_TELEGRAM_BASE_URL"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Proxy string `json:"proxy" env:"PICOCLAW_CHANNELS_TELEGRAM_PROXY"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_TELEGRAM_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
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
|
|
|
|
Streaming StreamingConfig `json:"streaming,omitempty"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_TELEGRAM_REASONING_CHANNEL_ID"`
|
2026-03-18 13:29:21 +00:00
|
|
|
|
UseMarkdownV2 bool `json:"use_markdown_v2" env:"PICOCLAW_CHANNELS_TELEGRAM_USE_MARKDOWN_V2"`
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type FeishuConfig struct {
|
2026-03-08 09:32:24 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_FEISHU_ENABLED"`
|
|
|
|
|
|
AppID string `json:"app_id" env:"PICOCLAW_CHANNELS_FEISHU_APP_ID"`
|
|
|
|
|
|
AppSecret string `json:"app_secret" env:"PICOCLAW_CHANNELS_FEISHU_APP_SECRET"`
|
|
|
|
|
|
EncryptKey string `json:"encrypt_key" env:"PICOCLAW_CHANNELS_FEISHU_ENCRYPT_KEY"`
|
|
|
|
|
|
VerificationToken string `json:"verification_token" env:"PICOCLAW_CHANNELS_FEISHU_VERIFICATION_TOKEN"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_FEISHU_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_FEISHU_REASONING_CHANNEL_ID"`
|
2026-03-06 04:53:47 +00:00
|
|
|
|
RandomReactionEmoji FlexibleStringSlice `json:"random_reaction_emoji" env:"PICOCLAW_CHANNELS_FEISHU_RANDOM_REACTION_EMOJI"`
|
2026-03-18 16:29:55 +00:00
|
|
|
|
IsLark bool `json:"is_lark" env:"PICOCLAW_CHANNELS_FEISHU_IS_LARK"`
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DiscordConfig struct {
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_DISCORD_ENABLED"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_DISCORD_TOKEN"`
|
2026-03-02 10:17:51 +00:00
|
|
|
|
Proxy string `json:"proxy" env:"PICOCLAW_CHANNELS_DISCORD_PROXY"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_DISCORD_ALLOW_FROM"`
|
|
|
|
|
|
MentionOnly bool `json:"mention_only" env:"PICOCLAW_CHANNELS_DISCORD_MENTION_ONLY"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" 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-19 08:27:34 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_QQ_ENABLED"`
|
|
|
|
|
|
AppID string `json:"app_id" env:"PICOCLAW_CHANNELS_QQ_APP_ID"`
|
|
|
|
|
|
AppSecret string `json:"app_secret" env:"PICOCLAW_CHANNELS_QQ_APP_SECRET"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_QQ_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
MaxMessageLength int `json:"max_message_length" env:"PICOCLAW_CHANNELS_QQ_MAX_MESSAGE_LENGTH"`
|
|
|
|
|
|
MaxBase64FileSizeMiB int64 `json:"max_base64_file_size_mib" env:"PICOCLAW_CHANNELS_QQ_MAX_BASE64_FILE_SIZE_MIB"`
|
|
|
|
|
|
SendMarkdown bool `json:"send_markdown" env:"PICOCLAW_CHANNELS_QQ_SEND_MARKDOWN"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" 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-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_DINGTALK_ENABLED"`
|
|
|
|
|
|
ClientID string `json:"client_id" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_ID"`
|
|
|
|
|
|
ClientSecret string `json:"client_secret" env:"PICOCLAW_CHANNELS_DINGTALK_CLIENT_SECRET"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_DINGTALK_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" 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-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_SLACK_ENABLED"`
|
|
|
|
|
|
BotToken string `json:"bot_token" env:"PICOCLAW_CHANNELS_SLACK_BOT_TOKEN"`
|
|
|
|
|
|
AppToken string `json:"app_token" env:"PICOCLAW_CHANNELS_SLACK_APP_TOKEN"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_SLACK_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" 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-11 17:25:28 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_MATRIX_ENABLED"`
|
|
|
|
|
|
Homeserver string `json:"homeserver" env:"PICOCLAW_CHANNELS_MATRIX_HOMESERVER"`
|
|
|
|
|
|
UserID string `json:"user_id" env:"PICOCLAW_CHANNELS_MATRIX_USER_ID"`
|
|
|
|
|
|
AccessToken string `json:"access_token" env:"PICOCLAW_CHANNELS_MATRIX_ACCESS_TOKEN"`
|
|
|
|
|
|
DeviceID string `json:"device_id,omitempty" env:"PICOCLAW_CHANNELS_MATRIX_DEVICE_ID"`
|
|
|
|
|
|
JoinOnInvite bool `json:"join_on_invite" env:"PICOCLAW_CHANNELS_MATRIX_JOIN_ON_INVITE"`
|
|
|
|
|
|
MessageFormat string `json:"message_format,omitempty" env:"PICOCLAW_CHANNELS_MATRIX_MESSAGE_FORMAT"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_MATRIX_ALLOW_FROM"`
|
2026-03-07 17:44:24 +00:00
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
2026-03-11 17:25:28 +00:00
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_MATRIX_REASONING_CHANNEL_ID"`
|
2026-03-07 17:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 01:01:20 +00:00
|
|
|
|
type LINEConfig struct {
|
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
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_LINE_ENABLED"`
|
|
|
|
|
|
ChannelSecret string `json:"channel_secret" env:"PICOCLAW_CHANNELS_LINE_CHANNEL_SECRET"`
|
|
|
|
|
|
ChannelAccessToken string `json:"channel_access_token" env:"PICOCLAW_CHANNELS_LINE_CHANNEL_ACCESS_TOKEN"`
|
|
|
|
|
|
WebhookHost string `json:"webhook_host" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_HOST"`
|
|
|
|
|
|
WebhookPort int `json:"webhook_port" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_PORT"`
|
|
|
|
|
|
WebhookPath string `json:"webhook_path" env:"PICOCLAW_CHANNELS_LINE_WEBHOOK_PATH"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_LINE_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_LINE_REASONING_CHANNEL_ID"`
|
2026-02-14 01:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 08:50:21 +00:00
|
|
|
|
type OneBotConfig struct {
|
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
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_ONEBOT_ENABLED"`
|
|
|
|
|
|
WSUrl string `json:"ws_url" env:"PICOCLAW_CHANNELS_ONEBOT_WS_URL"`
|
|
|
|
|
|
AccessToken string `json:"access_token" env:"PICOCLAW_CHANNELS_ONEBOT_ACCESS_TOKEN"`
|
|
|
|
|
|
ReconnectInterval int `json:"reconnect_interval" env:"PICOCLAW_CHANNELS_ONEBOT_RECONNECT_INTERVAL"`
|
|
|
|
|
|
GroupTriggerPrefix []string `json:"group_trigger_prefix" env:"PICOCLAW_CHANNELS_ONEBOT_GROUP_TRIGGER_PREFIX"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_ONEBOT_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_ONEBOT_REASONING_CHANNEL_ID"`
|
2026-02-14 08:50:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-20 07:33:24 +00:00
|
|
|
|
type WeComConfig struct {
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WECOM_ENABLED"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_WECOM_TOKEN"`
|
|
|
|
|
|
EncodingAESKey string `json:"encoding_aes_key" env:"PICOCLAW_CHANNELS_WECOM_ENCODING_AES_KEY"`
|
|
|
|
|
|
WebhookURL string `json:"webhook_url" env:"PICOCLAW_CHANNELS_WECOM_WEBHOOK_URL"`
|
|
|
|
|
|
WebhookHost string `json:"webhook_host" env:"PICOCLAW_CHANNELS_WECOM_WEBHOOK_HOST"`
|
|
|
|
|
|
WebhookPort int `json:"webhook_port" env:"PICOCLAW_CHANNELS_WECOM_WEBHOOK_PORT"`
|
|
|
|
|
|
WebhookPath string `json:"webhook_path" env:"PICOCLAW_CHANNELS_WECOM_WEBHOOK_PATH"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WECOM_ALLOW_FROM"`
|
|
|
|
|
|
ReplyTimeout int `json:"reply_timeout" env:"PICOCLAW_CHANNELS_WECOM_REPLY_TIMEOUT"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_WECOM_REASONING_CHANNEL_ID"`
|
2026-02-20 07:33:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type WeComAppConfig struct {
|
2026-02-26 05:24:51 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WECOM_APP_ENABLED"`
|
|
|
|
|
|
CorpID string `json:"corp_id" env:"PICOCLAW_CHANNELS_WECOM_APP_CORP_ID"`
|
|
|
|
|
|
CorpSecret string `json:"corp_secret" env:"PICOCLAW_CHANNELS_WECOM_APP_CORP_SECRET"`
|
|
|
|
|
|
AgentID int64 `json:"agent_id" env:"PICOCLAW_CHANNELS_WECOM_APP_AGENT_ID"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_WECOM_APP_TOKEN"`
|
|
|
|
|
|
EncodingAESKey string `json:"encoding_aes_key" env:"PICOCLAW_CHANNELS_WECOM_APP_ENCODING_AES_KEY"`
|
|
|
|
|
|
WebhookHost string `json:"webhook_host" env:"PICOCLAW_CHANNELS_WECOM_APP_WEBHOOK_HOST"`
|
|
|
|
|
|
WebhookPort int `json:"webhook_port" env:"PICOCLAW_CHANNELS_WECOM_APP_WEBHOOK_PORT"`
|
|
|
|
|
|
WebhookPath string `json:"webhook_path" env:"PICOCLAW_CHANNELS_WECOM_APP_WEBHOOK_PATH"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WECOM_APP_ALLOW_FROM"`
|
|
|
|
|
|
ReplyTimeout int `json:"reply_timeout" env:"PICOCLAW_CHANNELS_WECOM_APP_REPLY_TIMEOUT"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_WECOM_APP_REASONING_CHANNEL_ID"`
|
2026-02-20 07:33:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-28 05:25:37 +00:00
|
|
|
|
type WeComAIBotConfig struct {
|
2026-03-19 16:23:40 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_ENABLED"`
|
|
|
|
|
|
BotID string `json:"bot_id,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_BOT_ID"`
|
|
|
|
|
|
Secret string `json:"secret,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_SECRET"`
|
|
|
|
|
|
Token string `json:"token,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_TOKEN"`
|
|
|
|
|
|
EncodingAESKey string `json:"encoding_aes_key,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_ENCODING_AES_KEY"`
|
|
|
|
|
|
WebhookPath string `json:"webhook_path,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_WEBHOOK_PATH"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_ALLOW_FROM"`
|
|
|
|
|
|
ReplyTimeout int `json:"reply_timeout" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_REPLY_TIMEOUT"`
|
|
|
|
|
|
MaxSteps int `json:"max_steps" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_MAX_STEPS"` // Maximum streaming steps
|
|
|
|
|
|
WelcomeMessage string `json:"welcome_message" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_WELCOME_MESSAGE"` // Sent on enter_chat event; empty = no welcome
|
|
|
|
|
|
ProcessingMessage string `json:"processing_message,omitempty" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_PROCESSING_MESSAGE"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_WECOM_AIBOT_REASONING_CHANNEL_ID"`
|
2026-02-28 05:25:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 20:55:15 +00:00
|
|
|
|
type PicoConfig struct {
|
2026-02-22 22:03:23 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_PICO_ENABLED"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_PICO_TOKEN"`
|
|
|
|
|
|
AllowTokenQuery bool `json:"allow_token_query,omitempty"`
|
|
|
|
|
|
AllowOrigins []string `json:"allow_origins,omitempty"`
|
|
|
|
|
|
PingInterval int `json:"ping_interval,omitempty"`
|
|
|
|
|
|
ReadTimeout int `json:"read_timeout,omitempty"`
|
|
|
|
|
|
WriteTimeout int `json:"write_timeout,omitempty"`
|
|
|
|
|
|
MaxConnections int `json:"max_connections,omitempty"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_PICO_ALLOW_FROM"`
|
2026-02-26 19:02:40 +00:00
|
|
|
|
Placeholder PlaceholderConfig `json:"placeholder,omitempty"`
|
2026-02-14 08:50:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 12:43:40 +00:00
|
|
|
|
type PicoClientConfig struct {
|
|
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_PICO_CLIENT_ENABLED"`
|
|
|
|
|
|
URL string `json:"url" env:"PICOCLAW_CHANNELS_PICO_CLIENT_URL"`
|
|
|
|
|
|
Token string `json:"token" env:"PICOCLAW_CHANNELS_PICO_CLIENT_TOKEN"`
|
|
|
|
|
|
SessionID string `json:"session_id,omitempty"`
|
|
|
|
|
|
PingInterval int `json:"ping_interval,omitempty"`
|
|
|
|
|
|
ReadTimeout int `json:"read_timeout,omitempty"`
|
|
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_PICO_CLIENT_ALLOW_FROM"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-05 10:46:01 +00:00
|
|
|
|
type IRCConfig struct {
|
|
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_IRC_ENABLED"`
|
|
|
|
|
|
Server string `json:"server" env:"PICOCLAW_CHANNELS_IRC_SERVER"`
|
|
|
|
|
|
TLS bool `json:"tls" env:"PICOCLAW_CHANNELS_IRC_TLS"`
|
|
|
|
|
|
Nick string `json:"nick" env:"PICOCLAW_CHANNELS_IRC_NICK"`
|
2026-03-06 19:09:37 +00:00
|
|
|
|
User string `json:"user,omitempty" env:"PICOCLAW_CHANNELS_IRC_USER"`
|
|
|
|
|
|
RealName string `json:"real_name,omitempty" env:"PICOCLAW_CHANNELS_IRC_REAL_NAME"`
|
2026-03-05 10:46:01 +00:00
|
|
|
|
Password string `json:"password" env:"PICOCLAW_CHANNELS_IRC_PASSWORD"`
|
|
|
|
|
|
NickServPassword string `json:"nickserv_password" env:"PICOCLAW_CHANNELS_IRC_NICKSERV_PASSWORD"`
|
|
|
|
|
|
SASLUser string `json:"sasl_user" env:"PICOCLAW_CHANNELS_IRC_SASL_USER"`
|
|
|
|
|
|
SASLPassword string `json:"sasl_password" env:"PICOCLAW_CHANNELS_IRC_SASL_PASSWORD"`
|
|
|
|
|
|
Channels FlexibleStringSlice `json:"channels" env:"PICOCLAW_CHANNELS_IRC_CHANNELS"`
|
2026-03-06 19:09:37 +00:00
|
|
|
|
RequestCaps FlexibleStringSlice `json:"request_caps,omitempty" env:"PICOCLAW_CHANNELS_IRC_REQUEST_CAPS"`
|
2026-03-05 10:46:01 +00:00
|
|
|
|
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_IRC_ALLOW_FROM"`
|
|
|
|
|
|
GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"`
|
|
|
|
|
|
Typing TypingConfig `json:"typing,omitempty"`
|
|
|
|
|
|
ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_IRC_REASONING_CHANNEL_ID"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-10 23:17:10 +00:00
|
|
|
|
type VoiceConfig struct {
|
|
|
|
|
|
EchoTranscription bool `json:"echo_transcription" env:"PICOCLAW_VOICE_ECHO_TRANSCRIPTION"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type ProvidersConfig struct {
|
2026-02-18 08:30:30 +00:00
|
|
|
|
Anthropic ProviderConfig `json:"anthropic"`
|
|
|
|
|
|
OpenAI OpenAIProviderConfig `json:"openai"`
|
2026-03-02 21:23:55 +00:00
|
|
|
|
LiteLLM ProviderConfig `json:"litellm"`
|
2026-02-18 08:30:30 +00:00
|
|
|
|
OpenRouter ProviderConfig `json:"openrouter"`
|
|
|
|
|
|
Groq ProviderConfig `json:"groq"`
|
|
|
|
|
|
Zhipu ProviderConfig `json:"zhipu"`
|
|
|
|
|
|
VLLM ProviderConfig `json:"vllm"`
|
|
|
|
|
|
Gemini ProviderConfig `json:"gemini"`
|
|
|
|
|
|
Nvidia ProviderConfig `json:"nvidia"`
|
|
|
|
|
|
Ollama ProviderConfig `json:"ollama"`
|
|
|
|
|
|
Moonshot ProviderConfig `json:"moonshot"`
|
|
|
|
|
|
ShengSuanYun ProviderConfig `json:"shengsuanyun"`
|
|
|
|
|
|
DeepSeek ProviderConfig `json:"deepseek"`
|
2026-02-19 16:11:46 +00:00
|
|
|
|
Cerebras ProviderConfig `json:"cerebras"`
|
2026-03-04 17:19:03 +00:00
|
|
|
|
Vivgrid ProviderConfig `json:"vivgrid"`
|
2026-02-19 16:11:46 +00:00
|
|
|
|
VolcEngine ProviderConfig `json:"volcengine"`
|
2026-02-18 08:30:30 +00:00
|
|
|
|
GitHubCopilot ProviderConfig `json:"github_copilot"`
|
2026-02-19 16:11:46 +00:00
|
|
|
|
Antigravity ProviderConfig `json:"antigravity"`
|
|
|
|
|
|
Qwen ProviderConfig `json:"qwen"`
|
2026-02-20 15:31:35 +00:00
|
|
|
|
Mistral ProviderConfig `json:"mistral"`
|
2026-02-27 03:02:07 +00:00
|
|
|
|
Avian ProviderConfig `json:"avian"`
|
2026-03-09 10:43:58 +00:00
|
|
|
|
Minimax ProviderConfig `json:"minimax"`
|
2026-03-11 18:34:42 +00:00
|
|
|
|
LongCat ProviderConfig `json:"longcat"`
|
2026-03-13 06:02:23 +00:00
|
|
|
|
ModelScope ProviderConfig `json:"modelscope"`
|
2026-03-18 10:29:27 +00:00
|
|
|
|
Novita ProviderConfig `json:"novita"`
|
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
|
|
|
|
// IsEmpty checks if all provider configs are empty (no API keys or API bases set)
|
|
|
|
|
|
// Note: WebSearch is an optimization option and doesn't count as "non-empty"
|
|
|
|
|
|
func (p ProvidersConfig) IsEmpty() bool {
|
|
|
|
|
|
return p.Anthropic.APIKey == "" && p.Anthropic.APIBase == "" &&
|
|
|
|
|
|
p.OpenAI.APIKey == "" && p.OpenAI.APIBase == "" &&
|
2026-03-02 21:23:55 +00:00
|
|
|
|
p.LiteLLM.APIKey == "" && p.LiteLLM.APIBase == "" &&
|
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
|
|
|
|
p.OpenRouter.APIKey == "" && p.OpenRouter.APIBase == "" &&
|
|
|
|
|
|
p.Groq.APIKey == "" && p.Groq.APIBase == "" &&
|
|
|
|
|
|
p.Zhipu.APIKey == "" && p.Zhipu.APIBase == "" &&
|
|
|
|
|
|
p.VLLM.APIKey == "" && p.VLLM.APIBase == "" &&
|
|
|
|
|
|
p.Gemini.APIKey == "" && p.Gemini.APIBase == "" &&
|
|
|
|
|
|
p.Nvidia.APIKey == "" && p.Nvidia.APIBase == "" &&
|
|
|
|
|
|
p.Ollama.APIKey == "" && p.Ollama.APIBase == "" &&
|
|
|
|
|
|
p.Moonshot.APIKey == "" && p.Moonshot.APIBase == "" &&
|
|
|
|
|
|
p.ShengSuanYun.APIKey == "" && p.ShengSuanYun.APIBase == "" &&
|
|
|
|
|
|
p.DeepSeek.APIKey == "" && p.DeepSeek.APIBase == "" &&
|
|
|
|
|
|
p.Cerebras.APIKey == "" && p.Cerebras.APIBase == "" &&
|
2026-03-04 17:19:03 +00:00
|
|
|
|
p.Vivgrid.APIKey == "" && p.Vivgrid.APIBase == "" &&
|
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
|
|
|
|
p.VolcEngine.APIKey == "" && p.VolcEngine.APIBase == "" &&
|
|
|
|
|
|
p.GitHubCopilot.APIKey == "" && p.GitHubCopilot.APIBase == "" &&
|
|
|
|
|
|
p.Antigravity.APIKey == "" && p.Antigravity.APIBase == "" &&
|
2026-02-20 15:31:35 +00:00
|
|
|
|
p.Qwen.APIKey == "" && p.Qwen.APIBase == "" &&
|
2026-02-27 03:02:07 +00:00
|
|
|
|
p.Mistral.APIKey == "" && p.Mistral.APIBase == "" &&
|
2026-03-09 10:43:58 +00:00
|
|
|
|
p.Avian.APIKey == "" && p.Avian.APIBase == "" &&
|
2026-03-11 18:34:42 +00:00
|
|
|
|
p.Minimax.APIKey == "" && p.Minimax.APIBase == "" &&
|
2026-03-13 06:02:23 +00:00
|
|
|
|
p.LongCat.APIKey == "" && p.LongCat.APIBase == "" &&
|
2026-03-18 10:29:27 +00:00
|
|
|
|
p.ModelScope.APIKey == "" && p.ModelScope.APIBase == "" &&
|
|
|
|
|
|
p.Novita.APIKey == "" && p.Novita.APIBase == ""
|
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 ProvidersConfig
|
|
|
|
|
|
// to omit the entire section when empty
|
|
|
|
|
|
func (p ProvidersConfig) MarshalJSON() ([]byte, error) {
|
|
|
|
|
|
if p.IsEmpty() {
|
|
|
|
|
|
return []byte("null"), nil
|
|
|
|
|
|
}
|
|
|
|
|
|
type Alias ProvidersConfig
|
|
|
|
|
|
return json.Marshal((*Alias)(&p))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type ProviderConfig struct {
|
2026-02-26 08:08:19 +00:00
|
|
|
|
APIKey string `json:"api_key" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_KEY"`
|
|
|
|
|
|
APIBase string `json:"api_base" env:"PICOCLAW_PROVIDERS_{{.Name}}_API_BASE"`
|
|
|
|
|
|
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_PROXY"`
|
|
|
|
|
|
RequestTimeout int `json:"request_timeout,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_REQUEST_TIMEOUT"`
|
|
|
|
|
|
AuthMethod string `json:"auth_method,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_AUTH_METHOD"`
|
|
|
|
|
|
ConnectMode string `json:"connect_mode,omitempty" env:"PICOCLAW_PROVIDERS_{{.Name}}_CONNECT_MODE"` // only for Github Copilot, `stdio` or `grpc`
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-18 08:30:30 +00:00
|
|
|
|
type OpenAIProviderConfig struct {
|
|
|
|
|
|
ProviderConfig
|
|
|
|
|
|
WebSearch bool `json:"web_search" env:"PICOCLAW_PROVIDERS_OPENAI_WEB_SEARCH"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
|
APIKey string `json:"api_key"` // API authentication key (single key)
|
|
|
|
|
|
APIKeys []string `json:"api_keys,omitempty"` // API authentication keys (multiple keys for failover)
|
|
|
|
|
|
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-02-19 17:27:00 +00:00
|
|
|
|
RPM int `json:"rpm,omitempty"` // Requests per minute limit
|
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
|
|
|
|
MaxTokensField string `json:"max_tokens_field,omitempty"` // Field name for max tokens (e.g., "max_completion_tokens")
|
2026-02-26 08:08:19 +00:00
|
|
|
|
RequestTimeout int `json:"request_timeout,omitempty"`
|
2026-03-05 01:51:18 +00:00
|
|
|
|
ThinkingLevel string `json:"thinking_level,omitempty"` // Extended thinking: off|low|medium|high|xhigh|adaptive
|
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-02-04 11:06:13 +00:00
|
|
|
|
type GatewayConfig struct {
|
2026-03-17 10:46:00 +00:00
|
|
|
|
Host string `json:"host" env:"PICOCLAW_GATEWAY_HOST"`
|
|
|
|
|
|
Port int `json:"port" env:"PICOCLAW_GATEWAY_PORT"`
|
|
|
|
|
|
HotReload bool `json:"hot_reload" env:"PICOCLAW_GATEWAY_HOT_RELOAD"`
|
2026-02-04 11:06:13 +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 {
|
|
|
|
|
|
Enabled bool `json:"enabled" env:"ENABLED"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-13 09:12:55 +00:00
|
|
|
|
type BraveConfig struct {
|
2026-03-10 08:34:11 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_BRAVE_ENABLED"`
|
|
|
|
|
|
APIKey string `json:"api_key" env:"PICOCLAW_TOOLS_WEB_BRAVE_API_KEY"`
|
|
|
|
|
|
APIKeys []string `json:"api_keys" env:"PICOCLAW_TOOLS_WEB_BRAVE_API_KEYS"`
|
|
|
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_BRAVE_MAX_RESULTS"`
|
2026-02-13 09:12:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 16:30:14 +00:00
|
|
|
|
type TavilyConfig struct {
|
2026-03-10 08:34:11 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_TAVILY_ENABLED"`
|
|
|
|
|
|
APIKey string `json:"api_key" env:"PICOCLAW_TOOLS_WEB_TAVILY_API_KEY"`
|
|
|
|
|
|
APIKeys []string `json:"api_keys" env:"PICOCLAW_TOOLS_WEB_TAVILY_API_KEYS"`
|
|
|
|
|
|
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_TAVILY_BASE_URL"`
|
|
|
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_TAVILY_MAX_RESULTS"`
|
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-10 08:34:11 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_ENABLED"`
|
|
|
|
|
|
APIKey string `json:"api_key" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_API_KEY"`
|
|
|
|
|
|
APIKeys []string `json:"api_keys" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_API_KEYS"`
|
|
|
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_MAX_RESULTS"`
|
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 {
|
|
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"`
|
|
|
|
|
|
APIKey string `json:"api_key" env:"PICOCLAW_TOOLS_WEB_GLM_API_KEY"`
|
|
|
|
|
|
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"`
|
|
|
|
|
|
// SearchEngine specifies the search backend: "search_std" (default),
|
|
|
|
|
|
// "search_pro", "search_pro_sogou", or "search_pro_quark".
|
|
|
|
|
|
SearchEngine string `json:"search_engine" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"`
|
|
|
|
|
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_GLM_MAX_RESULTS"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type WebToolsConfig struct {
|
2026-03-05 06:53:26 +00:00
|
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_TOOLS_WEB_"`
|
|
|
|
|
|
Brave BraveConfig ` json:"brave"`
|
|
|
|
|
|
Tavily TavilyConfig ` json:"tavily"`
|
|
|
|
|
|
DuckDuckGo DuckDuckGoConfig ` json:"duckduckgo"`
|
|
|
|
|
|
Perplexity PerplexityConfig ` json:"perplexity"`
|
2026-03-05 20:36:05 +00:00
|
|
|
|
SearXNG SearXNGConfig ` json:"searxng"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
GLMSearch GLMSearchConfig ` json:"glm_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.
|
|
|
|
|
|
PreferNative bool `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-03-17 15:22:05 +00:00
|
|
|
|
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_TOOLS_WEB_PROXY"`
|
|
|
|
|
|
FetchLimitBytes int64 `json:"fetch_limit_bytes,omitempty" env:"PICOCLAW_TOOLS_WEB_FETCH_LIMIT_BYTES"`
|
2026-03-17 16:14:23 +00:00
|
|
|
|
Format string `json:"format,omitempty" env:"PICOCLAW_TOOLS_WEB_FORMAT"`
|
2026-03-17 15:22:05 +00:00
|
|
|
|
PrivateHostWhitelist FlexibleStringSlice `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_"`
|
|
|
|
|
|
ExecTimeoutMinutes int ` env:"PICOCLAW_TOOLS_CRON_EXEC_TIMEOUT_MINUTES" json:"exec_timeout_minutes"` // 0 means no timeout
|
|
|
|
|
|
AllowCommand bool ` env:"PICOCLAW_TOOLS_CRON_ALLOW_COMMAND" json:"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_"`
|
|
|
|
|
|
EnableDenyPatterns bool ` env:"PICOCLAW_TOOLS_EXEC_ENABLE_DENY_PATTERNS" json:"enable_deny_patterns"`
|
2026-03-11 11:22:20 +00:00
|
|
|
|
AllowRemote bool ` env:"PICOCLAW_TOOLS_EXEC_ALLOW_REMOTE" json:"allow_remote"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
CustomDenyPatterns []string ` env:"PICOCLAW_TOOLS_EXEC_CUSTOM_DENY_PATTERNS" json:"custom_deny_patterns"`
|
|
|
|
|
|
CustomAllowPatterns []string ` env:"PICOCLAW_TOOLS_EXEC_CUSTOM_ALLOW_PATTERNS" json:"custom_allow_patterns"`
|
2026-03-06 03:19:25 +00:00
|
|
|
|
TimeoutSeconds int ` env:"PICOCLAW_TOOLS_EXEC_TIMEOUT_SECONDS" json:"timeout_seconds"` // 0 means use default (60s)
|
2026-03-05 06:53:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SkillsToolsConfig struct {
|
|
|
|
|
|
ToolConfig ` envPrefix:"PICOCLAW_TOOLS_SKILLS_"`
|
|
|
|
|
|
Registries SkillsRegistriesConfig ` json:"registries"`
|
2026-03-13 06:04:02 +00:00
|
|
|
|
Github SkillsGithubConfig ` json:"github"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
MaxConcurrentSearches int ` json:"max_concurrent_searches" env:"PICOCLAW_TOOLS_SKILLS_MAX_CONCURRENT_SEARCHES"`
|
|
|
|
|
|
SearchCache SearchCacheConfig ` 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_"`
|
|
|
|
|
|
MaxAge int ` env:"PICOCLAW_MEDIA_CLEANUP_MAX_AGE" json:"max_age_minutes"`
|
|
|
|
|
|
Interval int ` env:"PICOCLAW_MEDIA_CLEANUP_INTERVAL" json:"interval_minutes"`
|
2026-02-04 11:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-09 08:32:21 +00:00
|
|
|
|
type ReadFileToolConfig struct {
|
|
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
|
|
MaxReadFileSize int `json:"max_read_file_size"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
type ToolsConfig struct {
|
fix(tools): allow /dev/null redirection and add read/write sandbox split (#967)
* fix(tools): allow /dev/null redirection and add read/write sandbox split
- Remove deny pattern that incorrectly blocked redirects to /dev/null
- Expand block device write pattern to cover nvme, mmcblk, vd, xvd,
hd, loop, dm-, md, sr and nbd in addition to sd
- Add safe path whitelist for kernel pseudo-devices so workspace path
check does not reject /dev/null, /dev/zero, /dev/random, /dev/urandom,
/dev/stdin, /dev/stdout and /dev/stderr
- Add allow_read_outside_workspace config option (default true) so file
read and list tools are unrestricted while write tools stay sandboxed
Closes https://github.com/sipeed/picoclaw/issues/964
Closes https://github.com/sipeed/picoclaw/issues/965
Signed-off-by: Huang Rui <vowstar@gmail.com>
* feat(tools): add configurable allow patterns and path whitelists
- Add custom_allow_patterns to exec config so users can exempt specific
commands from deny pattern checks
- Add allow_read_paths and allow_write_paths regex lists to tools config
for whitelisting specific paths outside the workspace
- Introduce whitelistFs that wraps sandboxFs and falls through to hostFs
for paths matching whitelist patterns
- Use variadic constructor signatures to keep backward compatibility
Suggested-by: lxowalle
Signed-off-by: Huang Rui <vowstar@gmail.com>
---------
Signed-off-by: Huang Rui <vowstar@gmail.com>
2026-03-02 04:22:02 +00:00
|
|
|
|
AllowReadPaths []string `json:"allow_read_paths" env:"PICOCLAW_TOOLS_ALLOW_READ_PATHS"`
|
|
|
|
|
|
AllowWritePaths []string `json:"allow_write_paths" env:"PICOCLAW_TOOLS_ALLOW_WRITE_PATHS"`
|
|
|
|
|
|
Web WebToolsConfig `json:"web"`
|
|
|
|
|
|
Cron CronToolsConfig `json:"cron"`
|
|
|
|
|
|
Exec ExecConfig `json:"exec"`
|
|
|
|
|
|
Skills SkillsToolsConfig `json:"skills"`
|
|
|
|
|
|
MediaCleanup MediaCleanupConfig `json:"media_cleanup"`
|
2026-03-02 16:17:39 +00:00
|
|
|
|
MCP MCPConfig `json:"mcp"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
AppendFile ToolConfig `json:"append_file" envPrefix:"PICOCLAW_TOOLS_APPEND_FILE_"`
|
|
|
|
|
|
EditFile ToolConfig `json:"edit_file" envPrefix:"PICOCLAW_TOOLS_EDIT_FILE_"`
|
|
|
|
|
|
FindSkills ToolConfig `json:"find_skills" envPrefix:"PICOCLAW_TOOLS_FIND_SKILLS_"`
|
|
|
|
|
|
I2C ToolConfig `json:"i2c" envPrefix:"PICOCLAW_TOOLS_I2C_"`
|
|
|
|
|
|
InstallSkill ToolConfig `json:"install_skill" envPrefix:"PICOCLAW_TOOLS_INSTALL_SKILL_"`
|
|
|
|
|
|
ListDir ToolConfig `json:"list_dir" envPrefix:"PICOCLAW_TOOLS_LIST_DIR_"`
|
|
|
|
|
|
Message ToolConfig `json:"message" envPrefix:"PICOCLAW_TOOLS_MESSAGE_"`
|
2026-03-09 08:32:21 +00:00
|
|
|
|
ReadFile ReadFileToolConfig `json:"read_file" envPrefix:"PICOCLAW_TOOLS_READ_FILE_"`
|
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
|
|
|
|
SendFile ToolConfig `json:"send_file" envPrefix:"PICOCLAW_TOOLS_SEND_FILE_"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
Spawn ToolConfig `json:"spawn" envPrefix:"PICOCLAW_TOOLS_SPAWN_"`
|
2026-03-17 06:41:43 +00:00
|
|
|
|
SpawnStatus ToolConfig `json:"spawn_status" envPrefix:"PICOCLAW_TOOLS_SPAWN_STATUS_"`
|
2026-03-05 06:53:26 +00:00
|
|
|
|
SPI ToolConfig `json:"spi" envPrefix:"PICOCLAW_TOOLS_SPI_"`
|
|
|
|
|
|
Subagent ToolConfig `json:"subagent" envPrefix:"PICOCLAW_TOOLS_SUBAGENT_"`
|
|
|
|
|
|
WebFetch ToolConfig `json:"web_fetch" envPrefix:"PICOCLAW_TOOLS_WEB_FETCH_"`
|
|
|
|
|
|
WriteFile ToolConfig `json:"write_file" envPrefix:"PICOCLAW_TOOLS_WRITE_FILE_"`
|
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 {
|
|
|
|
|
|
ClawHub ClawHubRegistryConfig `json:"clawhub"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 06:04:02 +00:00
|
|
|
|
type SkillsGithubConfig struct {
|
|
|
|
|
|
Token string `json:"token,omitempty" env:"PICOCLAW_TOOLS_SKILLS_GITHUB_AUTH_TOKEN"`
|
|
|
|
|
|
Proxy string `json:"proxy,omitempty" env:"PICOCLAW_TOOLS_SKILLS_GITHUB_PROXY"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-20 10:55:04 +00:00
|
|
|
|
type ClawHubRegistryConfig struct {
|
2026-02-20 18:03:11 +00:00
|
|
|
|
Enabled bool `json:"enabled" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_ENABLED"`
|
|
|
|
|
|
BaseURL string `json:"base_url" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_BASE_URL"`
|
|
|
|
|
|
AuthToken string `json:"auth_token" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_AUTH_TOKEN"`
|
|
|
|
|
|
SearchPath string `json:"search_path" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_SEARCH_PATH"`
|
|
|
|
|
|
SkillsPath string `json:"skills_path" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_SKILLS_PATH"`
|
|
|
|
|
|
DownloadPath string `json:"download_path" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_DOWNLOAD_PATH"`
|
|
|
|
|
|
Timeout int `json:"timeout" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_TIMEOUT"`
|
|
|
|
|
|
MaxZipSize int `json:"max_zip_size" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_MAX_ZIP_SIZE"`
|
2026-02-20 10:55:04 +00:00
|
|
|
|
MaxResponseSize int `json:"max_response_size" env:"PICOCLAW_SKILLS_REGISTRIES_CLAWHUB_MAX_RESPONSE_SIZE"`
|
2026-02-04 11:06:13 +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-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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
|
|
|
|
cfg := DefaultConfig()
|
|
|
|
|
|
|
|
|
|
|
|
data, err := os.ReadFile(path)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
|
return cfg, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-24 09:57:28 +00:00
|
|
|
|
// Pre-scan the JSON to check how many model_list entries the user provided.
|
|
|
|
|
|
// Go's JSON decoder reuses existing slice backing-array elements rather than
|
|
|
|
|
|
// zero-initializing them, so fields absent from the user's JSON (e.g. api_base)
|
|
|
|
|
|
// would silently inherit values from the DefaultConfig template at the same
|
|
|
|
|
|
// index position. We only reset cfg.ModelList when the user actually provides
|
|
|
|
|
|
// entries; when count is 0 we keep DefaultConfig's built-in list as fallback.
|
|
|
|
|
|
var tmp Config
|
|
|
|
|
|
if err := json.Unmarshal(data, &tmp); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(tmp.ModelList) > 0 {
|
|
|
|
|
|
cfg.ModelList = nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
if err := json.Unmarshal(data, cfg); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
if passphrase := credential.PassphraseProvider(); passphrase != "" {
|
|
|
|
|
|
for _, m := range cfg.ModelList {
|
|
|
|
|
|
if m.APIKey != "" && !strings.HasPrefix(m.APIKey, "enc://") && !strings.HasPrefix(m.APIKey, "file://") {
|
|
|
|
|
|
fmt.Fprintf(os.Stderr,
|
|
|
|
|
|
"picoclaw: warning: model %q has a plaintext api_key; call SaveConfig to encrypt it\n",
|
|
|
|
|
|
m.ModelName)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
if err := env.Parse(cfg); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
if err := resolveAPIKeys(cfg.ModelList, filepath.Dir(path)); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
|
cfg.ModelList = ExpandMultiKeyModels(cfg.ModelList)
|
|
|
|
|
|
|
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
|
|
|
|
// Migrate legacy channel config fields to new unified structures
|
|
|
|
|
|
cfg.migrateChannelConfigs()
|
|
|
|
|
|
|
2026-02-18 17:30:19 +00:00
|
|
|
|
// Auto-migrate: if only legacy providers config exists, convert to model_list
|
|
|
|
|
|
if len(cfg.ModelList) == 0 && cfg.HasProvidersConfig() {
|
|
|
|
|
|
cfg.ModelList = ConvertProvidersToModelList(cfg)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-19 13:24:46 +00:00
|
|
|
|
// Inherit credentials from providers to model_list entries (#1635).
|
|
|
|
|
|
// When both providers and model_list are present, model_list entries
|
|
|
|
|
|
// whose api_key/api_base are empty will inherit from the matching
|
|
|
|
|
|
// provider (matched by protocol prefix). Explicit model_list values
|
|
|
|
|
|
// always take precedence.
|
|
|
|
|
|
if cfg.HasProvidersConfig() {
|
|
|
|
|
|
InheritProviderCredentials(cfg.ModelList, cfg.Providers)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-19 04:45:12 +00:00
|
|
|
|
// Validate model_list for uniqueness and required fields
|
|
|
|
|
|
if err := cfg.ValidateModelList(); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
return cfg, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
// encryptPlaintextAPIKeys returns a copy of models with plaintext api_key values
|
|
|
|
|
|
// encrypted. Returns (nil, nil) when nothing changed (all keys already sealed or
|
|
|
|
|
|
// empty). Returns (nil, error) if any key fails to encrypt — callers must treat
|
|
|
|
|
|
// this as a hard failure to prevent a mixed plaintext/ciphertext state on disk.
|
|
|
|
|
|
// Symmetric counterpart of resolveAPIKeys: both operate purely on []ModelConfig
|
|
|
|
|
|
// and leave JSON marshaling to the caller.
|
|
|
|
|
|
func encryptPlaintextAPIKeys(models []ModelConfig, passphrase string) ([]ModelConfig, error) {
|
|
|
|
|
|
sealed := make([]ModelConfig, len(models))
|
|
|
|
|
|
copy(sealed, models)
|
|
|
|
|
|
changed := false
|
|
|
|
|
|
for i := range sealed {
|
|
|
|
|
|
m := &sealed[i]
|
|
|
|
|
|
if m.APIKey == "" || strings.HasPrefix(m.APIKey, "enc://") || strings.HasPrefix(m.APIKey, "file://") {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
encrypted, err := credential.Encrypt(passphrase, "", m.APIKey)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, fmt.Errorf("cannot seal api_key for model %q: %w", m.ModelName, err)
|
|
|
|
|
|
}
|
|
|
|
|
|
m.APIKey = encrypted
|
|
|
|
|
|
changed = true
|
|
|
|
|
|
}
|
|
|
|
|
|
if !changed {
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
return sealed, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// resolveAPIKeys decrypts or dereferences each api_key in models in-place.
|
|
|
|
|
|
// Supports plaintext (no-op), file:// (read from configDir), and enc:// (AES-GCM decrypt).
|
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
|
|
|
|
// Also resolves api_keys array if present.
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
func resolveAPIKeys(models []ModelConfig, configDir string) error {
|
|
|
|
|
|
cr := credential.NewResolver(configDir)
|
|
|
|
|
|
for i := range models {
|
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
|
|
|
|
// Resolve single APIKey
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
resolved, err := cr.Resolve(models[i].APIKey)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return fmt.Errorf("model_list[%d] (%s): %w", i, models[i].ModelName, err)
|
|
|
|
|
|
}
|
|
|
|
|
|
models[i].APIKey = resolved
|
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
|
|
|
|
|
|
|
|
|
|
// Resolve APIKeys array
|
|
|
|
|
|
for j, key := range models[i].APIKeys {
|
|
|
|
|
|
resolved, err := cr.Resolve(key)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return fmt.Errorf("model_list[%d] (%s): api_keys[%d]: %w", i, models[i].ModelName, j, err)
|
|
|
|
|
|
}
|
|
|
|
|
|
models[i].APIKeys[j] = resolved
|
|
|
|
|
|
}
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
return 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
|
|
|
|
func (c *Config) migrateChannelConfigs() {
|
|
|
|
|
|
// Discord: mention_only -> group_trigger.mention_only
|
|
|
|
|
|
if c.Channels.Discord.MentionOnly && !c.Channels.Discord.GroupTrigger.MentionOnly {
|
|
|
|
|
|
c.Channels.Discord.GroupTrigger.MentionOnly = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OneBot: group_trigger_prefix -> group_trigger.prefixes
|
2026-02-28 05:25:37 +00:00
|
|
|
|
if len(c.Channels.OneBot.GroupTriggerPrefix) > 0 &&
|
|
|
|
|
|
len(c.Channels.OneBot.GroupTrigger.Prefixes) == 0 {
|
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
|
|
|
|
c.Channels.OneBot.GroupTrigger.Prefixes = c.Channels.OneBot.GroupTriggerPrefix
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
func SaveConfig(path string, cfg *Config) error {
|
feat(credential): part1 add AES-GCM encryption, SecureStore, and onboard ke… (#1521)
* feat(credential): add AES-GCM encryption, SecureStore, and onboard keygen
- pkg/credential: new package with AES-256-GCM enc:// credential format,
HKDF-SHA256 key derivation (passphrase + optional SSH key binding),
ErrPassphraseRequired / ErrDecryptionFailed sentinel errors,
and PassphraseProvider hook for runtime passphrase injection
- pkg/credential/store: lock-free SecureStore via atomic.Pointer[string];
passphrase never written to disk or os.Environ
- pkg/credential/keygen: ed25519 SSH key generation helper used by onboard
- pkg/config: replace os.Getenv(PassphraseEnvVar) with
credential.PassphraseProvider() at all three call sites so that
LoadConfig and SaveConfig use whatever passphrase source is active
- cmd/picoclaw/onboard: prompt for passphrase with echo-off, generate
picoclaw-specific SSH key, re-encrypt existing config on re-onboard
- docs/credential_encryption.md: design doc for the enc:// format
* fix(credential): address Copilot review comments on PR #1521
- credential.go: decouple ErrPassphraseRequired from env var name;
message is now 'enc:// passphrase required' since PassphraseProvider
may come from any source, not just os.Environ
- credential.go: Resolver resolves symlinks via EvalSymlinks before the
isWithinDir containment check, preventing symlink-based path traversal
for file:// credential references
- store.go: tighten comment to describe only what SecureStore guarantees
(in-memory only); remove claims about how callers transport the value
- store_test.go: replace the meaningless GetReturnsCopy test (Go strings
are immutable, equality across two calls proves nothing) with
TestSecureStore_ConcurrentSetGet that exercises atomic.Pointer under
10-goroutine concurrent Set/Get load
- config_test.go: update error-message assertion to match new sentinel text
- docs/credential_encryption.md: remove reference to non-existent
'picoclaw encrypt' subcommand; describe the onboard flow instead
* fix(config): encryptPlaintextAPIKeys: struct-based encryption, fail-fast, remove raw []byte
* fix(credential): require SSH private key for encryption/decryption, remove passphrase-only mode
* lint: fix credential keygen lint, fix test keygen
* onboard: make encryption opt-in via --enc flag
Encryption (passphrase prompt + SSH key generation) is now only
triggered when the user passes --enc to 'picoclaw onboard'.
Without the flag, onboard skips the credential-encryption setup and
writes a plain config + workspace templates directly.
- Add --enc BoolFlag in NewOnboardCommand()
- Pass encrypt bool into onboard()
- Guard passphrase prompt, SSH key generation, and related env-var
setup behind the encrypt branch
- Adjust 'Next steps' output so the passphrase reminder only appears
when --enc was used
2026-03-16 06:06:32 +00:00
|
|
|
|
if passphrase := credential.PassphraseProvider(); passphrase != "" {
|
|
|
|
|
|
sealed, err := encryptPlaintextAPIKeys(cfg.ModelList, passphrase)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if sealed != nil {
|
|
|
|
|
|
tmp := *cfg
|
|
|
|
|
|
tmp.ModelList = sealed
|
|
|
|
|
|
cfg = &tmp
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-04 11:06:13 +00:00
|
|
|
|
data, err := json.MarshalIndent(cfg, "", " ")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
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 (c *Config) GetAPIKey() string {
|
|
|
|
|
|
if c.Providers.OpenRouter.APIKey != "" {
|
|
|
|
|
|
return c.Providers.OpenRouter.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.Anthropic.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Anthropic.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.OpenAI.APIKey != "" {
|
|
|
|
|
|
return c.Providers.OpenAI.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.Gemini.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Gemini.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.Zhipu.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Zhipu.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.Groq.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Groq.APIKey
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.VLLM.APIKey != "" {
|
|
|
|
|
|
return c.Providers.VLLM.APIKey
|
|
|
|
|
|
}
|
2026-02-13 07:55:59 +00:00
|
|
|
|
if c.Providers.ShengSuanYun.APIKey != "" {
|
|
|
|
|
|
return c.Providers.ShengSuanYun.APIKey
|
|
|
|
|
|
}
|
2026-02-16 23:23:44 +00:00
|
|
|
|
if c.Providers.Cerebras.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Cerebras.APIKey
|
|
|
|
|
|
}
|
2026-02-04 11:06:13 +00:00
|
|
|
|
return ""
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Config) GetAPIBase() string {
|
|
|
|
|
|
if c.Providers.OpenRouter.APIKey != "" {
|
|
|
|
|
|
if c.Providers.OpenRouter.APIBase != "" {
|
|
|
|
|
|
return c.Providers.OpenRouter.APIBase
|
|
|
|
|
|
}
|
|
|
|
|
|
return "https://openrouter.ai/api/v1"
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.Zhipu.APIKey != "" {
|
|
|
|
|
|
return c.Providers.Zhipu.APIBase
|
|
|
|
|
|
}
|
|
|
|
|
|
if c.Providers.VLLM.APIKey != "" && c.Providers.VLLM.APIBase != "" {
|
|
|
|
|
|
return c.Providers.VLLM.APIBase
|
|
|
|
|
|
}
|
|
|
|
|
|
return ""
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
return &matches[0], nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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))
|
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
|
|
|
|
return &matches[idx], nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-20 03:34:52 +00:00
|
|
|
|
// findMatches finds all ModelConfig entries with the given model_name.
|
|
|
|
|
|
func (c *Config) findMatches(modelName string) []ModelConfig {
|
2026-02-18 17:03:34 +00:00
|
|
|
|
var matches []ModelConfig
|
|
|
|
|
|
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
|
|
|
|
// HasProvidersConfig checks if any provider in the old providers config has configuration.
|
|
|
|
|
|
func (c *Config) HasProvidersConfig() bool {
|
2026-03-01 07:17:32 +00:00
|
|
|
|
return !c.Providers.IsEmpty()
|
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-10 08:34:11 +00:00
|
|
|
|
func MergeAPIKeys(apiKey string, apiKeys []string) []string {
|
|
|
|
|
|
seen := make(map[string]struct{})
|
|
|
|
|
|
var all []string
|
|
|
|
|
|
|
|
|
|
|
|
if k := strings.TrimSpace(apiKey); k != "" {
|
|
|
|
|
|
if _, exists := seen[k]; !exists {
|
|
|
|
|
|
seen[k] = struct{}{}
|
|
|
|
|
|
all = append(all, k)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, k := range apiKeys {
|
|
|
|
|
|
if trimmed := strings.TrimSpace(k); trimmed != "" {
|
|
|
|
|
|
if _, exists := seen[trimmed]; !exists {
|
|
|
|
|
|
seen[trimmed] = struct{}{}
|
|
|
|
|
|
all = append(all, trimmed)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return all
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
// ExpandMultiKeyModels expands ModelConfig entries with multiple API keys into
|
|
|
|
|
|
// 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:
|
|
|
|
|
|
// - {"model_name": "gpt-4", "api_key": "k1", "fallbacks": ["gpt-4__key_1", "gpt-4__key_2"]}
|
|
|
|
|
|
// - {"model_name": "gpt-4__key_1", "api_key": "k2"}
|
|
|
|
|
|
// - {"model_name": "gpt-4__key_2", "api_key": "k3"}
|
|
|
|
|
|
func ExpandMultiKeyModels(models []ModelConfig) []ModelConfig {
|
|
|
|
|
|
var expanded []ModelConfig
|
|
|
|
|
|
|
|
|
|
|
|
for _, m := range models {
|
|
|
|
|
|
keys := MergeAPIKeys(m.APIKey, m.APIKeys)
|
|
|
|
|
|
|
|
|
|
|
|
// Single key or no keys: keep as-is
|
|
|
|
|
|
if len(keys) <= 1 {
|
|
|
|
|
|
// Ensure APIKey is set from APIKeys if needed
|
|
|
|
|
|
if m.APIKey == "" && len(keys) == 1 {
|
|
|
|
|
|
m.APIKey = keys[0]
|
|
|
|
|
|
}
|
|
|
|
|
|
m.APIKeys = nil // Clear APIKeys to avoid confusion
|
|
|
|
|
|
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
|
|
|
|
|
|
additionalEntry := ModelConfig{
|
|
|
|
|
|
ModelName: expandedName,
|
|
|
|
|
|
Model: m.Model,
|
|
|
|
|
|
APIBase: m.APIBase,
|
|
|
|
|
|
APIKey: keys[i],
|
|
|
|
|
|
Proxy: m.Proxy,
|
|
|
|
|
|
AuthMethod: m.AuthMethod,
|
|
|
|
|
|
ConnectMode: m.ConnectMode,
|
|
|
|
|
|
Workspace: m.Workspace,
|
|
|
|
|
|
RPM: m.RPM,
|
|
|
|
|
|
MaxTokensField: m.MaxTokensField,
|
|
|
|
|
|
RequestTimeout: m.RequestTimeout,
|
|
|
|
|
|
ThinkingLevel: m.ThinkingLevel,
|
|
|
|
|
|
}
|
|
|
|
|
|
expanded = append(expanded, additionalEntry)
|
|
|
|
|
|
fallbackNames = append(fallbackNames, expandedName)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the primary entry with first key and fallbacks
|
|
|
|
|
|
primaryEntry := ModelConfig{
|
|
|
|
|
|
ModelName: originalName,
|
|
|
|
|
|
Model: m.Model,
|
|
|
|
|
|
APIBase: m.APIBase,
|
|
|
|
|
|
APIKey: keys[0],
|
|
|
|
|
|
Proxy: m.Proxy,
|
|
|
|
|
|
AuthMethod: m.AuthMethod,
|
|
|
|
|
|
ConnectMode: m.ConnectMode,
|
|
|
|
|
|
Workspace: m.Workspace,
|
|
|
|
|
|
RPM: m.RPM,
|
|
|
|
|
|
MaxTokensField: m.MaxTokensField,
|
|
|
|
|
|
RequestTimeout: m.RequestTimeout,
|
|
|
|
|
|
ThinkingLevel: m.ThinkingLevel,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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-03-05 06:53:26 +00:00
|
|
|
|
case "write_file":
|
|
|
|
|
|
return t.WriteFile.Enabled
|
|
|
|
|
|
case "mcp":
|
|
|
|
|
|
return t.MCP.Enabled
|
|
|
|
|
|
default:
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|