mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-15 03:52:25 +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:
62
internal/sdk/adapter_impl.go
Normal file
62
internal/sdk/adapter_impl.go
Normal file
@ -0,0 +1,62 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
luaVM "gitcode.com/JianFeeeee/HomeAgent/internal/lua"
|
||||
)
|
||||
|
||||
// adapterImpl 桥接 Lua VM 的协议适配器管理。
|
||||
type adapterImpl struct {
|
||||
vm *luaVM.VM
|
||||
}
|
||||
|
||||
func NewAdapter(vm *luaVM.VM) AdapterAPI {
|
||||
return &adapterImpl{vm: vm}
|
||||
}
|
||||
|
||||
func (a *adapterImpl) List() []APIAdapter {
|
||||
if a.vm == nil {
|
||||
return nil
|
||||
}
|
||||
got := a.vm.ListAdapters()
|
||||
out := make([]APIAdapter, len(got))
|
||||
for i, ad := range got {
|
||||
out[i] = APIAdapter{Name: ad.Name, Version: ad.Version}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (a *adapterImpl) Load(name, code string) error {
|
||||
if a.vm == nil {
|
||||
return errors.New("lua vm not available")
|
||||
}
|
||||
path := filepath.Join(a.vm.AdapterDir(), name+".lua")
|
||||
if err := os.WriteFile(path, []byte(code), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.vm.LoadAdapter(path)
|
||||
}
|
||||
|
||||
func (a *adapterImpl) Remove(name string) error {
|
||||
if a.vm == nil {
|
||||
return errors.New("lua vm not available")
|
||||
}
|
||||
path := filepath.Join(a.vm.AdapterDir(), name+".lua")
|
||||
if err := os.Remove(path); err != nil {
|
||||
return err
|
||||
}
|
||||
a.vm.RemoveAdapter(name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *adapterImpl) AdapterDir() string {
|
||||
if a.vm == nil {
|
||||
return ""
|
||||
}
|
||||
return a.vm.AdapterDir()
|
||||
}
|
||||
|
||||
var _ AdapterAPI = (*adapterImpl)(nil)
|
||||
Reference in New Issue
Block a user