mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-11-01 06:47:29 +00:00
批 1,不含 SDK 仓与目录改名。 - go.mod 第 1 行 module 路径 - 366 个 .go 文件的完整前缀 github.com/JianFeeeee/HomeAgent 机械替换 (857 处,仅完整前缀;展示名/注释里的 HomeAgent 字样留给批 5) - 未改:third_party 目录名、SDK 自身 go.mod module、go.mod replace 目标、 homed/waiter 可执行名、.hmap 后缀
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package sdk
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/JianFeeeee/HologramAgent/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)
|