mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 17:38:10 +00:00
- 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
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package sdk
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gitcode.com/JianFeeeee/HomeAgent/internal/memory"
|
|
)
|
|
|
|
// indexerImpl 桥接 memory.Indexer 到中立的 IndexerAPI。
|
|
type indexerImpl struct {
|
|
idx *memory.Indexer
|
|
}
|
|
|
|
func NewIndexer(idx *memory.Indexer) IndexerAPI {
|
|
return &indexerImpl{idx: idx}
|
|
}
|
|
|
|
func (i *indexerImpl) BuildContext(q string) (*IndexContext, error) {
|
|
if i.idx == nil {
|
|
return nil, errors.New("indexer not available")
|
|
}
|
|
ctx := i.idx.BuildContext(q)
|
|
if ctx == nil {
|
|
return &IndexContext{}, nil
|
|
}
|
|
entities := make([]Entity, len(ctx.Entities))
|
|
for j, e := range ctx.Entities {
|
|
entities[j] = Entity{Name: e.Name, Type: e.Type, MentionCount: e.MentionCount}
|
|
}
|
|
relations := make([]Relation, len(ctx.Relations))
|
|
for j, r := range ctx.Relations {
|
|
relations[j] = Relation{SourceName: r.SourceName, TargetName: r.TargetName, RelationType: r.RelationType}
|
|
}
|
|
return &IndexContext{
|
|
Entities: entities,
|
|
Relations: relations,
|
|
Summary: ctx.Summary,
|
|
TokenEstimate: ctx.TokenEstimate,
|
|
}, nil
|
|
}
|
|
|
|
func (i *indexerImpl) FormatContext(ctx *IndexContext) string {
|
|
if i.idx == nil || ctx == nil {
|
|
return ""
|
|
}
|
|
entities := make([]memory.Entity, len(ctx.Entities))
|
|
for j, e := range ctx.Entities {
|
|
entities[j] = memory.Entity{Name: e.Name, Type: e.Type, MentionCount: e.MentionCount}
|
|
}
|
|
return i.idx.FormatContext(&memory.InjectedContext{
|
|
Entities: entities,
|
|
Summary: ctx.Summary,
|
|
TokenEstimate: ctx.TokenEstimate,
|
|
})
|
|
}
|
|
|
|
func (i *indexerImpl) GetToolDefinitions() []map[string]interface{} {
|
|
if i.idx == nil {
|
|
return nil
|
|
}
|
|
return i.idx.GetToolDefinitions()
|
|
}
|
|
|
|
func (i *indexerImpl) BuildToolPrompt() string {
|
|
if i.idx == nil {
|
|
return ""
|
|
}
|
|
return i.idx.BuildToolPrompt()
|
|
}
|
|
|
|
var _ IndexerAPI = (*indexerImpl)(nil)
|