mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-22 01:48:11 +00:00
refactor: migrate built-in plugins to SDK-only interface
- Six-phase plan complete: webui/cli/healthcheck/pluginmgr/clawhubadapter now interact with the kernel exclusively via internal/sdk interfaces; all Configure() calls and package-level global injection removed - buildSDK in internal/plugin/registry.go is the single assembly point - Add internal/sdk/events.go exporting event types/constants - Fix ProviderManager cooldown sharing: LuaAdaptedProvider.Name() now returns the source name instead of lua_<adapter>, so multiple sources sharing an adapter (single script load via shared VM AdapterCache) no longer share failure-cooldown state - Verified: build/vet/tests green, deployed to homeagent.service with full plugin capability testing via local OpenAI-compatible mock
This commit is contained in:
50
internal/sdk/tool_impl.go
Normal file
50
internal/sdk/tool_impl.go
Normal file
@ -0,0 +1,50 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
agentIO "gitcode.com/JianFeeeee/HomeAgent/internal/agent/io"
|
||||
)
|
||||
|
||||
// toolImpl 桥接 StageHost(插件工具)与 IOManager(设备/通道工具)。
|
||||
type toolImpl struct {
|
||||
stageHost ToolSource
|
||||
iom *agentIO.IOManager
|
||||
}
|
||||
|
||||
func NewTool(sh ToolSource, iom *agentIO.IOManager) ToolAPI {
|
||||
return &toolImpl{stageHost: sh, iom: iom}
|
||||
}
|
||||
|
||||
func (t *toolImpl) GetToolDefs() []ToolDef {
|
||||
if t.stageHost == nil {
|
||||
return nil
|
||||
}
|
||||
return t.stageHost.GetToolDefs()
|
||||
}
|
||||
|
||||
func (t *toolImpl) GetAllTools() []ToolDef {
|
||||
if t.iom == nil {
|
||||
return nil
|
||||
}
|
||||
defs := t.iom.GetAllTools()
|
||||
out := make([]ToolDef, 0, len(defs))
|
||||
for _, d := range defs {
|
||||
out = append(out, ToolDef{Name: d.Name, Description: d.Description, Parameters: d.Parameters})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (t *toolImpl) ExecuteTool(name string, args map[string]interface{}) (interface{}, error) {
|
||||
if t.stageHost != nil {
|
||||
if def := t.stageHost.ToolDef(name); def != nil {
|
||||
return t.stageHost.ExecuteTool(name, args)
|
||||
}
|
||||
}
|
||||
if t.iom != nil {
|
||||
return t.iom.ExecuteTool(name, args)
|
||||
}
|
||||
return nil, fmt.Errorf("tool %s not found", name)
|
||||
}
|
||||
|
||||
var _ ToolAPI = (*toolImpl)(nil)
|
||||
Reference in New Issue
Block a user