mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-22 18:08:04 +00:00
原 Handle 是一个 550 行的巨型 switch(C ABI 51 个 case 的整块平移),
按协议面拆进同包 5 个新文件、14 个小函数:
corehandler_register.go handleRegister 注册面(tool/stage/output/api/input)
corehandler_inject.go handleInject IO 注入 + SetToolBlocks
corehandler_memory.go handleGraphMemory 图记忆
handleDocMemory 文档记忆
handleKnowledge 知识库
handleTextMemory 文本记忆
corehandler_settings.go handleSettings 设置(14 个 method 共用一条实现)
handleLLM LLM 源
handleSocial 社交图只读
handleLifecycle 生命周期开关
corehandler_runtime.go handlePluginMgr 插件管理
handleStageLocks 段锁仲裁
handleEvents 事件订阅
handleArena 共享槽池
Handle 保留 capability 强制检查,只做「method → 分部函数」一跳。
零漂移保证:case 标签由脚本从原文提取(不手抄常量名),case 体逐字搬迁,
逐函数比对确认 59 个标签 / 510 行 case 体与原文件完全一致(仅行首缩进经 gofmt 重排)。
验证:go build ./... / go vet / go test ./internal/plugin/... / -race 全绿。
113 lines
3.8 KiB
Go
113 lines
3.8 KiB
Go
package proc
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
)
|
||
|
||
// handleSettings 处理全部设置项读写(14 个 method 共用一条实现)。
|
||
//
|
||
// 本函数体是 corehandler.go 里 Handle 那一个大 switch 的**整块平移**:
|
||
// case 标签与 case 体逐字保留,只换了宿主函数(§3.2 的平移原则)。
|
||
func (h *coreHandler) handleSettings(method string, params json.RawMessage) (interface{}, error) {
|
||
switch method {
|
||
// ---- 设置(原 case 16/17/18/26~31/42~45/51)----
|
||
case MethodSettingsGet, MethodSettingsSet, MethodSettingsRegisterDef,
|
||
MethodSettingsGetCore, MethodSettingsSetCore, MethodSettingsListCore,
|
||
MethodSettingsGetPlugin, MethodSettingsSetPlugin, MethodSettingsListPlugin,
|
||
MethodSettingsList, MethodSettingsDefs, MethodSettingsDump,
|
||
MethodSettingsPlugins, MethodSettingsDataDir:
|
||
return h.settings(method, params)
|
||
|
||
}
|
||
|
||
// 组内不应到达:Handle 的分派表与本函数的 case 标签同源,
|
||
// 出现即说明两处不同步。
|
||
return nil, fmt.Errorf("未知 method: %s", method)
|
||
}
|
||
|
||
// handleLLM 处理 LLM 源查询与切换。
|
||
//
|
||
// 本函数体是 corehandler.go 里 Handle 那一个大 switch 的**整块平移**:
|
||
// case 标签与 case 体逐字保留,只换了宿主函数(§3.2 的平移原则)。
|
||
func (h *coreHandler) handleLLM(method string, params json.RawMessage) (interface{}, error) {
|
||
switch method {
|
||
// ---- LLM 源(原 case 19/20/37)----
|
||
case MethodLLMListSources:
|
||
llm := h.sdk.LLM()
|
||
if llm == nil {
|
||
return nil, errUnavailable("llm")
|
||
}
|
||
sources := llm.ListSources()
|
||
if sources == nil {
|
||
sources = []string{}
|
||
}
|
||
return map[string]interface{}{"sources": sources}, nil
|
||
case MethodLLMSetSource:
|
||
llm := h.sdk.LLM()
|
||
if llm == nil {
|
||
return nil, errUnavailable("llm")
|
||
}
|
||
var p struct {
|
||
Name string `json:"name"`
|
||
}
|
||
if err := unmarshal(params, &p); err != nil {
|
||
return nil, err
|
||
}
|
||
return nil, llm.SetSource(p.Name)
|
||
case MethodLLMCurrentSource:
|
||
llm := h.sdk.LLM()
|
||
if llm == nil {
|
||
return nil, errUnavailable("llm")
|
||
}
|
||
return map[string]interface{}{"source": llm.CurrentSource()}, nil
|
||
|
||
}
|
||
|
||
// 组内不应到达:Handle 的分派表与本函数的 case 标签同源,
|
||
// 出现即说明两处不同步。
|
||
return nil, fmt.Errorf("未知 method: %s", method)
|
||
}
|
||
|
||
// handleSocial 处理社交图只读查询(人物/网络/特质/关系)。
|
||
//
|
||
// 本函数体是 corehandler.go 里 Handle 那一个大 switch 的**整块平移**:
|
||
// case 标签与 case 体逐字保留,只换了宿主函数(§3.2 的平移原则)。
|
||
func (h *coreHandler) handleSocial(method string, params json.RawMessage) (interface{}, error) {
|
||
switch method {
|
||
// ---- 社交图(只读,原 case 21/22/38/39/40)----
|
||
case MethodSocialGetPerson, MethodSocialGetNetwork, MethodSocialGetTrait,
|
||
MethodSocialGetRelation, MethodSocialListPersons:
|
||
return h.social(method, params)
|
||
|
||
}
|
||
|
||
// 组内不应到达:Handle 的分派表与本函数的 case 标签同源,
|
||
// 出现即说明两处不同步。
|
||
return nil, fmt.Errorf("未知 method: %s", method)
|
||
}
|
||
|
||
// handleLifecycle 处理生命周期开关(当前仅自动重启)。
|
||
//
|
||
// 本函数体是 corehandler.go 里 Handle 那一个大 switch 的**整块平移**:
|
||
// case 标签与 case 体逐字保留,只换了宿主函数(§3.2 的平移原则)。
|
||
func (h *coreHandler) handleLifecycle(method string, params json.RawMessage) (interface{}, error) {
|
||
switch method {
|
||
// ---- 生命周期(原 case 8)----
|
||
case MethodLifecycleAutoRestart:
|
||
var p struct {
|
||
Enabled bool `json:"enabled"`
|
||
}
|
||
if err := unmarshal(params, &p); err != nil {
|
||
return nil, err
|
||
}
|
||
h.sdk.SetAutoRestart(p.Enabled)
|
||
return nil, nil
|
||
|
||
}
|
||
|
||
// 组内不应到达:Handle 的分派表与本函数的 case 标签同源,
|
||
// 出现即说明两处不同步。
|
||
return nil, fmt.Errorf("未知 method: %s", method)
|
||
}
|