mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-04 00:03:59 +00:00
feat: converge dynamic plugins onto canonical homeagent-sdk
- Separate built-in plugin interface from external plugin interface - Route dynamic plugin loading through homeagent-sdk/sdk using reflection - Turn internal/sdk into an enhanced wrapper over canonical SDK types - Vendor SDK repo snapshot under third_party/homeagent-sdk for stable builds - Keep internal constructors/adapters for memory, knowledge, llm, settings - Align dynamic QQ loading with canonical SDK chain
This commit is contained in:
@ -1,55 +1,26 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
sdkext "gitcode.com/JianFeeeee/homeagent-sdk/sdk"
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/memory"
|
||||
doc "gitcode.com/JianFeeeee/HomeAgent/internal/memory/document"
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/memory/text"
|
||||
)
|
||||
|
||||
type MemoryAPI interface {
|
||||
Recall(query []string, depth int) ([]Entity, []Relation, error)
|
||||
Commit(triples []Triple) error
|
||||
Introspect() (map[string]interface{}, error)
|
||||
MergeEntities(source, target string) (int, error)
|
||||
Purge(criteria map[string]string, mode string) (int, error)
|
||||
}
|
||||
type MemoryAPI = sdkext.MemoryAPI
|
||||
type Entity = sdkext.Entity
|
||||
type Relation = sdkext.Relation
|
||||
type Triple = sdkext.Triple
|
||||
|
||||
type Entity struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
MentionCount int `json:"mention_count"`
|
||||
}
|
||||
type TextMemoryAPI = sdkext.TextMemoryAPI
|
||||
type TextEvent = sdkext.TextEvent
|
||||
|
||||
type Relation struct {
|
||||
SourceName string `json:"source_name"`
|
||||
TargetName string `json:"target_name"`
|
||||
RelationType string `json:"relation_type"`
|
||||
}
|
||||
type DocMemoryAPI = sdkext.DocMemoryAPI
|
||||
type Doc = sdkext.Doc
|
||||
|
||||
type Triple struct {
|
||||
Subject string `json:"subject"`
|
||||
Relation string `json:"relation"`
|
||||
Object string `json:"object"`
|
||||
}
|
||||
type graphMemory struct{ db *memory.GraphDB }
|
||||
|
||||
type TextMemoryAPI interface {
|
||||
Append(evt text.Event) error
|
||||
}
|
||||
|
||||
type DocMemoryAPI interface {
|
||||
Query(text string, topK int) []*doc.Doc
|
||||
Insert(doc *doc.Doc) error
|
||||
Remove(id string)
|
||||
Stats() map[string]interface{}
|
||||
}
|
||||
|
||||
type graphMemory struct {
|
||||
db *memory.GraphDB
|
||||
}
|
||||
|
||||
func NewGraphMemory(db *memory.GraphDB) MemoryAPI {
|
||||
return &graphMemory{db: db}
|
||||
}
|
||||
func NewGraphMemory(db *memory.GraphDB) MemoryAPI { return &graphMemory{db: db} }
|
||||
|
||||
func (m *graphMemory) Recall(query []string, depth int) ([]Entity, []Relation, error) {
|
||||
if m.db == nil {
|
||||
@ -71,9 +42,7 @@ func (m *graphMemory) Recall(query []string, depth int) ([]Entity, []Relation, e
|
||||
}
|
||||
|
||||
func (m *graphMemory) Commit(triples []Triple) error {
|
||||
if m.db == nil {
|
||||
return nil
|
||||
}
|
||||
if m.db == nil { return nil }
|
||||
ts := make([]memory.Triple, len(triples))
|
||||
for i, t := range triples {
|
||||
ts[i] = memory.Triple{Subject: t.Subject, Relation: t.Relation, Object: t.Object}
|
||||
@ -83,72 +52,50 @@ func (m *graphMemory) Commit(triples []Triple) error {
|
||||
}
|
||||
|
||||
func (m *graphMemory) Introspect() (map[string]interface{}, error) {
|
||||
if m.db == nil {
|
||||
return map[string]interface{}{}, nil
|
||||
}
|
||||
if m.db == nil { return map[string]interface{}{}, nil }
|
||||
return m.db.Introspect()
|
||||
}
|
||||
|
||||
func (m *graphMemory) MergeEntities(source, target string) (int, error) {
|
||||
if m.db == nil {
|
||||
return 0, nil
|
||||
}
|
||||
if m.db == nil { return 0, nil }
|
||||
return m.db.MergeEntities(source, target)
|
||||
}
|
||||
|
||||
func (m *graphMemory) Purge(criteria map[string]string, mode string) (int, error) {
|
||||
if m.db == nil {
|
||||
return 0, nil
|
||||
}
|
||||
if m.db == nil { return 0, nil }
|
||||
return m.db.Purge(criteria, mode)
|
||||
}
|
||||
|
||||
type textMemoryImpl struct {
|
||||
tm *text.Memory
|
||||
type textMemoryImpl struct{ tm *text.Memory }
|
||||
|
||||
func NewTextMemory(tm *text.Memory) TextMemoryAPI { return &textMemoryImpl{tm: tm} }
|
||||
|
||||
func (m *textMemoryImpl) Append(evt TextEvent) error {
|
||||
if m.tm == nil { return nil }
|
||||
return m.tm.Append(text.Event{Timestamp: evt.Timestamp, Source: evt.Role, Input: evt.Content, AgentID: evt.Channel})
|
||||
}
|
||||
|
||||
func NewTextMemory(tm *text.Memory) TextMemoryAPI {
|
||||
return &textMemoryImpl{tm: tm}
|
||||
}
|
||||
type docMemoryImpl struct{ ds *doc.Store }
|
||||
|
||||
func (m *textMemoryImpl) Append(evt text.Event) error {
|
||||
if m.tm == nil {
|
||||
return nil
|
||||
func NewDocMemory(ds *doc.Store) DocMemoryAPI { return &docMemoryImpl{ds: ds} }
|
||||
|
||||
func (m *docMemoryImpl) Query(text string, topK int) []*Doc {
|
||||
if m.ds == nil { return nil }
|
||||
got := m.ds.Query(text, topK)
|
||||
out := make([]*Doc, len(got))
|
||||
for i, d := range got {
|
||||
out[i] = &Doc{ID: d.ID, Title: d.Summary, Content: d.Content}
|
||||
}
|
||||
return m.tm.Append(evt)
|
||||
return out
|
||||
}
|
||||
|
||||
type docMemoryImpl struct {
|
||||
ds *doc.Store
|
||||
}
|
||||
|
||||
func NewDocMemory(ds *doc.Store) DocMemoryAPI {
|
||||
return &docMemoryImpl{ds: ds}
|
||||
}
|
||||
|
||||
func (m *docMemoryImpl) Query(text string, topK int) []*doc.Doc {
|
||||
if m.ds == nil {
|
||||
return nil
|
||||
}
|
||||
return m.ds.Query(text, topK)
|
||||
}
|
||||
|
||||
func (m *docMemoryImpl) Insert(d *doc.Doc) error {
|
||||
if m.ds == nil {
|
||||
return nil
|
||||
}
|
||||
return m.ds.Insert(d)
|
||||
}
|
||||
|
||||
func (m *docMemoryImpl) Remove(id string) {
|
||||
if m.ds != nil {
|
||||
m.ds.Remove(id)
|
||||
}
|
||||
func (m *docMemoryImpl) Insert(d *Doc) error {
|
||||
if m.ds == nil { return nil }
|
||||
return m.ds.Insert(&doc.Doc{ID: d.ID, Summary: d.Title, Content: d.Content})
|
||||
}
|
||||
|
||||
func (m *docMemoryImpl) Remove(id string) { if m.ds != nil { m.ds.Remove(id) } }
|
||||
func (m *docMemoryImpl) Stats() map[string]interface{} {
|
||||
if m.ds == nil {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
if m.ds == nil { return map[string]interface{}{} }
|
||||
return m.ds.Stats()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user