mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 09:28:14 +00:00
PluginSDK: - 添加 InjectInput / InjectInputSync / InjectInterrupt 泛型接口 - 插件现在可注入 image/audio/file 等任意类型输入 Provider: - 添加 ContentBlock / ImageURL / AudioURL 类型 - Message 增加 Blocks 字段,Content 在非空 Blocks 时序列化为数组(多模态格式) Agent: - handleInput 新增 image/audio 类型分发 → processMediaInput - processMediaInput 将媒体数据附着到对话上下文,LLM 自主决策处理策略 - 新增内置工具:describe_image / transcribe_audio / ocr_image(pendingMedia 驱动) - 工具仅当有未处理媒体数据时注册,通过 Provider 直接调用多模态模型 Config: - 新增 InputProcessingConfig(image/audio 处理配置) - 含 fallback_provider / describe_prompt / ocr_enabled 等选项 Waiter CLI 重写: - 配置文件 ~/.config/homeagent/cli.yaml(自动发现 socket) - 原始终端行编辑 + 命令历史持久化 + 彩色输出 - 内置命令:/help /reconnect /connect /remote /local /prompt - 断线自动重连
117 lines
3.6 KiB
Go
117 lines
3.6 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"gitcode.com/JianFeeeee/HomeAgent/pkg/types"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
const DefaultConfigPath = "/etc/homeagent/config.yaml"
|
|
|
|
func DefaultConfig() types.Config {
|
|
return types.Config{
|
|
Daemon: types.DaemonConfig{
|
|
ListenAddr: ":8080",
|
|
DataDir: "/var/lib/homeagent",
|
|
HeartbeatInterval: 15 * time.Second,
|
|
CheckInterval: 30 * time.Second,
|
|
LogLevel: "info",
|
|
},
|
|
LLM: types.LLMConfig{
|
|
Provider: "deepseek",
|
|
Model: "deepseek-v4-flash",
|
|
BaseURL: "https://api.deepseek.com",
|
|
APIKey: "",
|
|
Adapter: "deepseek",
|
|
Temperature: 0.7,
|
|
MaxTokens: 4096,
|
|
Sources: []types.LLMSource{
|
|
{Name: "deepseek", BaseURL: "https://api.deepseek.com", Model: "deepseek-v4-flash", Adapter: "deepseek", AdapterPath: "adapters/deepseek.lua"},
|
|
{Name: "openai", BaseURL: "https://api.openai.com/v1", Model: "gpt-4o", Adapter: "openai", AdapterPath: "adapters/openai.lua"},
|
|
{Name: "anthropic", BaseURL: "https://api.anthropic.com", Model: "claude-sonnet-4-20250514", Adapter: "anthropic", AdapterPath: "adapters/anthropic.lua"},
|
|
{Name: "gemini", BaseURL: "https://generativelanguage.googleapis.com", Model: "gemini-2.0-flash", Adapter: "gemini", AdapterPath: "adapters/gemini.lua"},
|
|
{Name: "mistral", BaseURL: "https://api.mistral.ai", Model: "mistral-large-latest", Adapter: "mistral", AdapterPath: "adapters/mistral.lua"},
|
|
{Name: "groq", BaseURL: "https://api.groq.com", Model: "llama3-70b-8192", Adapter: "groq", AdapterPath: "adapters/groq.lua"},
|
|
{Name: "github", BaseURL: "https://models.inference.ai.azure.com", Model: "gpt-4o", Adapter: "github", AdapterPath: "adapters/github.lua"},
|
|
{Name: "ollama", BaseURL: "http://localhost:11434", Model: "llama3", Adapter: "ollama", AdapterPath: "adapters/ollama.lua"},
|
|
},
|
|
},
|
|
InputProcessing: types.InputProcessingConfig{
|
|
Image: types.ImageProcessingConfig{
|
|
FallbackProvider: "",
|
|
FallbackModel: "",
|
|
DescribePrompt: "请详细描述这张图片的内容",
|
|
OCREnabled: true,
|
|
},
|
|
Audio: types.AudioProcessingConfig{
|
|
FallbackProvider: "",
|
|
FallbackModel: "",
|
|
DescribePrompt: "请描述这段音频的内容",
|
|
},
|
|
},
|
|
Defaults: types.AgentConfig{
|
|
Image: "homeagent/agent-base:latest",
|
|
LLMEndpoints: []string{"https://api.openai.com/v1"},
|
|
SnapshotPolicy: types.SnapshotPolicy{
|
|
Interval: 10 * time.Minute,
|
|
MaxSnapshots: 20,
|
|
PreAction: true,
|
|
PostAction: false,
|
|
},
|
|
RollbackPolicy: types.RollbackPolicy{
|
|
MaxRetries: 3,
|
|
HealthThreshold: types.HealthDown,
|
|
CooldownPeriod: 30 * time.Second,
|
|
AutoRollback: true,
|
|
},
|
|
ResourceLimit: types.ResourceLimit{
|
|
CPU: "2",
|
|
Memory: "2g",
|
|
Disk: "10g",
|
|
Network: true,
|
|
},
|
|
OpenClawEnabled: true,
|
|
},
|
|
}
|
|
}
|
|
|
|
func Load(path string) (*types.Config, error) {
|
|
cfg := DefaultConfig()
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return &cfg, nil
|
|
}
|
|
return nil, fmt.Errorf("read config: %w", err)
|
|
}
|
|
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("parse config: %w", err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
func Save(path string, cfg *types.Config) error {
|
|
dir := filepath.Dir(path)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
return fmt.Errorf("create config dir: %w", err)
|
|
}
|
|
|
|
data, err := yaml.Marshal(cfg)
|
|
if err != nil {
|
|
return fmt.Errorf("marshal config: %w", err)
|
|
}
|
|
|
|
if err := os.WriteFile(path, data, 0644); err != nil {
|
|
return fmt.Errorf("write config: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|