mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-04 00:03:59 +00:00
refactor: P0-P3 fixes, C1 cleanup, architecture diagrams, go.work upgrade
- P0-1: ProviderError type + ReportStatus for precise 401/403 detection - P0-2: Remove -config flag from deploy/homeagent.service - P2-1: 5s debounce on context.go Save() - P2-2→C1: Delete output_set_channel entirely - P2-3: Extract mediaDataURL/mediaChat helpers - P2-4: Dedup defaultSources var - P3: Delete dead packages (embed/tokenizer/container/snapshot) - P3: Delete dead functions (messagesToMap, RunStageAll) - CL: Update .gitignore, docs, Makefile, gojieba removal - Config: Delete config/config.yaml, update docs - Arch: Remove EmitOutputTo from emitResponse - CL-1: go.work 1.19→1.21 - Docs: Add Mermaid architecture diagrams to README - Docs: Add kernel-rebuild requires plugin-rebuild note to PLUGIN_DEV.md
This commit is contained in:
102
internal/sdk/settings_impl.go
Normal file
102
internal/sdk/settings_impl.go
Normal file
@ -0,0 +1,102 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
internalConfig "gitcode.com/JianFeeeee/HomeAgent/internal/config"
|
||||
)
|
||||
|
||||
type settingsImpl struct {
|
||||
pluginName string
|
||||
reg *internalConfig.ConfigRegistry
|
||||
}
|
||||
|
||||
func NewSettings(name string, reg *internalConfig.ConfigRegistry) SettingsAPI {
|
||||
return &settingsImpl{pluginName: name, reg: reg}
|
||||
}
|
||||
|
||||
func (s *settingsImpl) Get(key string) (interface{}, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.PluginConfig(s.pluginName).Get(key)
|
||||
}
|
||||
func (s *settingsImpl) Set(key string, value interface{}) error {
|
||||
if s.reg == nil { return nil }
|
||||
return s.reg.PluginConfig(s.pluginName).Set(key, value)
|
||||
}
|
||||
func (s *settingsImpl) List(prefix string) ([]string, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.PluginConfig(s.pluginName).List(prefix)
|
||||
}
|
||||
func (s *settingsImpl) GetCore(key string) (interface{}, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.Get(key)
|
||||
}
|
||||
func (s *settingsImpl) SetCore(key string, value interface{}) error {
|
||||
if s.reg == nil { return nil }
|
||||
return s.reg.Set(key, value)
|
||||
}
|
||||
func (s *settingsImpl) ListCore(prefix string) ([]string, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.List(prefix), nil
|
||||
}
|
||||
func (s *settingsImpl) GetPlugin(plugin, key string) (interface{}, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.PluginConfig(plugin).Get(key)
|
||||
}
|
||||
func (s *settingsImpl) SetPlugin(plugin, key string, value interface{}) error {
|
||||
if s.reg == nil { return nil }
|
||||
return s.reg.PluginConfig(plugin).Set(key, value)
|
||||
}
|
||||
func (s *settingsImpl) ListPlugin(plugin, prefix string) ([]string, error) {
|
||||
if s.reg == nil { return nil, nil }
|
||||
return s.reg.PluginConfig(plugin).List(prefix)
|
||||
}
|
||||
func (s *settingsImpl) RegisterDef(def ConfigDef) {
|
||||
if s.reg == nil { return }
|
||||
s.reg.PluginConfig(s.pluginName).RegisterDef(internalConfig.ConfigDef{
|
||||
Key: def.Key, Type: def.Type, DisplayName: def.DisplayName, Description: def.Description,
|
||||
Category: def.Category, Options: def.Options,
|
||||
Default: stringifyDefault(def.Default),
|
||||
})
|
||||
}
|
||||
func (s *settingsImpl) Defs(prefix string) []*ConfigDef {
|
||||
if s.reg == nil { return nil }
|
||||
defs := s.reg.PluginConfig(s.pluginName).ListDefs(prefix)
|
||||
out := make([]*ConfigDef, len(defs))
|
||||
for i, d := range defs {
|
||||
// ConfigDef = pubsdk.ConfigDef (type alias), so direct conversion works
|
||||
cpy := ConfigDef{
|
||||
Key: d.Key, Type: d.Type, DisplayName: d.DisplayName, Description: d.Description,
|
||||
Category: d.Category, Options: d.Options,
|
||||
}
|
||||
out[i] = &cpy
|
||||
}
|
||||
return out
|
||||
}
|
||||
func (s *settingsImpl) Dump() map[string]interface{} {
|
||||
if s.reg == nil { return nil }
|
||||
return s.reg.Dump()
|
||||
}
|
||||
func (s *settingsImpl) Plugins() []string {
|
||||
if s.reg == nil { return nil }
|
||||
keys := s.reg.List("config_")
|
||||
names := make([]string, 0, len(keys)+1)
|
||||
names = append(names, "core")
|
||||
for _, k := range keys {
|
||||
if len(k) > 7 { names = append(names, k[7:]) }
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func stringifyDefault(v interface{}) string {
|
||||
if v == nil { return "" }
|
||||
switch x := v.(type) {
|
||||
case string: return x
|
||||
case bool:
|
||||
if x { return "true" }
|
||||
return "false"
|
||||
default: return fmt.Sprint(v)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure settingsImpl satisfies SettingsAPI (pubsdk.SettingsAPI via type alias).
|
||||
var _ SettingsAPI = (*settingsImpl)(nil)
|
||||
Reference in New Issue
Block a user