Files
HomeAgent/internal/plugin/proc/corehandler_register.go
HomeAgent Agent 129a3aeb38 refactor(proc): coreHandler.Handle 550 行按 method 组拆成 14 个分部函数
原 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 全绿。
2026-09-13 23:29:13 +08:00

62 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package proc
import (
"encoding/json"
"fmt"
pubsdk "gitcode.com/JianFeeeee/homeagent-sdk/sdk"
)
// handleRegister 处理注册面:工具 / stage / 输出通道 / 插件 API / 入站通道。
//
// 本函数体是 corehandler.go 里 Handle 那一个大 switch 的**整块平移**
// case 标签与 case 体逐字保留只换了宿主函数§3.2 的平移原则)。
func (h *coreHandler) handleRegister(method string, params json.RawMessage) (interface{}, error) {
switch method {
// ---- 注册面(原 case 1/2/3/4/46----
case MethodToolRegister:
return h.toolRegister(params)
case MethodStageRegister:
return h.stageRegister(params)
case MethodOutputRegister:
return h.outputRegister(params)
case MethodAPIRegister:
var p struct {
Name string `json:"name"`
}
if err := unmarshal(params, &p); err != nil {
return nil, err
}
return nil, h.sdk.RegisterPluginAPI(p.Name)
case MethodInputRegister:
var p struct {
Name string `json:"name"`
Def pubsdk.ChannelDef `json:"def"`
HasCleaner bool `json:"has_cleaner"`
}
if err := unmarshal(params, &p); err != nil {
return nil, err
}
if p.Name == "" {
return nil, fmt.Errorf("input.register: 缺少 name")
}
cleaner, err := h.cleanerProxy(CleanerScopeInput, p.Name, p.HasCleaner)
if err != nil {
return nil, fmt.Errorf("input.register: %w", err)
}
if err := validateContextPolicy("input.register", p.Def.ContextPolicy); err != nil {
return nil, err
}
// 整体传 p.Def只是把函数型的 Cleaner 换成代理),不要手写字段白名单:
// 白名单会让新增字段静默丢失。
def := p.Def
def.Cleaner = cleaner
return nil, h.sdk.RegisterInputChannel(p.Name, def)
}
// 组内不应到达Handle 的分派表与本函数的 case 标签同源,
// 出现即说明两处不同步。
return nil, fmt.Errorf("未知 method: %s", method)
}