重构: 插件自注册 + .so 动态加载 + 中断打断机制

- 所有内置插件 init() 自注册 (plugin.RegisterFactory), 移除 main.go 硬编码
- 新增 .so 动态加载器 (internal/plugin/dynamic.go), 插件可编译为 plugin.so
- 新增 plugin.json 元数据 (internal/plugin/manifest.go)
- 新增 interceptLoop 独立 goroutine:
  (a) cancelLLM() 取消进行中的 HTTP 请求
  (b) interceptCh → drainInterrupt() 注入 [打断消息] 到 LLM 上下文
  (c) InjectInput 空闲时触发新处理循环
- 新增 internal/plugins/all.go 空白导入触发所有内置插件 init()
- internal/sdk/ 作为 PluginSDK 正式 Go API
- internal/api/ → internal/plugins/webui/ 迁移
- 删除旧 cmd/cli/, 使用 cmd/waiter/ 替代
- 更新 PLAN.md / ARCHITECTURE.md / README.md 文档
This commit is contained in:
root
2026-07-03 16:53:34 +08:00
parent 4442c9cea4
commit 2d314b3e9c
37 changed files with 3376 additions and 1576 deletions

121
internal/sdk/settings.go Normal file
View File

@ -0,0 +1,121 @@
package sdk
import (
internalConfig "gitcode.com/JianFeeeee/HomeAgent/internal/config"
)
type SettingsAPI interface {
// 插件自身配置表 config_<name>
Get(key string) (interface{}, error)
Set(key string, value interface{}) error
List(prefix string) ([]string, error)
// 核心配置表 config
GetCore(key string) (interface{}, error)
SetCore(key string, value interface{}) error
ListCore(prefix string) ([]string, error)
// 任意插件配置表 config_<plugin>
GetPlugin(plugin, key string) (interface{}, error)
SetPlugin(plugin, key string, value interface{}) error
ListPlugin(plugin, prefix string) ([]string, error)
// 全局
Dump() map[string]interface{}
Plugins() []string
}
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) Dump() map[string]interface{} {
if s.reg == nil {
return nil
}
return s.reg.Dump()
}
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) 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 {
// config_xxx → xxx
if len(k) > 7 {
names = append(names, k[7:])
}
}
return names
}