mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-07 16:14:30 +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:
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/network"
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/tracker"
|
||||
sdk "gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
|
||||
"gitcode.com/JianFeeeee/HomeAgent/pkg/types"
|
||||
)
|
||||
|
||||
@ -224,11 +225,5 @@ func (d *Daemon) RollbackAgent(id types.AgentID, snapID types.SnapshotID) error
|
||||
return fmt.Errorf("no tracker available for rollback")
|
||||
}
|
||||
|
||||
type AgentStatus struct {
|
||||
ID types.AgentID `json:"id"`
|
||||
State types.AgentState `json:"state"`
|
||||
Health types.HealthStatus `json:"health"`
|
||||
Uptime time.Duration `json:"uptime,omitempty"`
|
||||
Network types.NetworkCheckResult `json:"network,omitempty"`
|
||||
TrackerStats map[string]interface{} `json:"tracker_stats,omitempty"`
|
||||
}
|
||||
// AgentStatus 已迁入内置 SDK,此处保留别名以兼容现有调用方。
|
||||
type AgentStatus = sdk.AgentStatus
|
||||
|
||||
48
internal/supervisor/sdk_adapter.go
Normal file
48
internal/supervisor/sdk_adapter.go
Normal file
@ -0,0 +1,48 @@
|
||||
package supervisor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
|
||||
"gitcode.com/JianFeeeee/HomeAgent/pkg/types"
|
||||
)
|
||||
|
||||
// sdkAdapter 实现 sdk.SupervisorAPI,将字符串签名的中立接口桥接到
|
||||
// Daemon 的强类型签名(types.AgentID / types.SnapshotID)。
|
||||
type sdkAdapter struct {
|
||||
d *Daemon
|
||||
}
|
||||
|
||||
func NewSDKAdapter(d *Daemon) sdk.SupervisorAPI {
|
||||
return &sdkAdapter{d: d}
|
||||
}
|
||||
|
||||
func (a *sdkAdapter) ListAgents() []sdk.AgentStatus {
|
||||
if a.d == nil {
|
||||
return nil
|
||||
}
|
||||
return a.d.ListAgents()
|
||||
}
|
||||
|
||||
func (a *sdkAdapter) GetAgentStatus(id string) (*sdk.AgentStatus, error) {
|
||||
if a.d == nil {
|
||||
return nil, errors.New("supervisor not available")
|
||||
}
|
||||
return a.d.GetAgentStatus(types.AgentID(id))
|
||||
}
|
||||
|
||||
func (a *sdkAdapter) PreActionSnapshot(id string) (*types.Snapshot, error) {
|
||||
if a.d == nil {
|
||||
return nil, errors.New("supervisor not available")
|
||||
}
|
||||
return a.d.PreActionSnapshot(types.AgentID(id))
|
||||
}
|
||||
|
||||
func (a *sdkAdapter) RollbackAgent(id string, snapID string) error {
|
||||
if a.d == nil {
|
||||
return errors.New("supervisor not available")
|
||||
}
|
||||
return a.d.RollbackAgent(types.AgentID(id), types.SnapshotID(snapID))
|
||||
}
|
||||
|
||||
var _ sdk.SupervisorAPI = (*sdkAdapter)(nil)
|
||||
Reference in New Issue
Block a user