Files
HomeAgent/internal/plugin/sdk/bus.go
root 3e3c6a24d2 v4 architecture: pipeline stages, SDK, event bus, LLM-driven memory consolidation
- SDK PluginAPI (internal/plugin/sdk/): RegisterTool/RegisterStage/Subscribe/Publish
- EventBus (internal/events/): system-level pub/sub with wildcard support
- StageHost (internal/agent/core/stages.go): 7-stage message pipeline
- Agent core: on_input/pre_action/post_action/before_toolcall/after_toolcall/before_output/after_output
- Plugin Registry: SDK plugin registration and tool routing
- GraphDB.MergeEntities: entity consolidation with relation redirection
- memory_merge tool: allows LLM to merge similar entities
- Consolidation task: heartbeat detects conflicts, enqueues via IO for LLM decision
- _consolidation_ internal channel for system-level memory maintenance
- Comprehensive documentation: ARCHITECTURE.md, PLAN.md, DESIGN.md, README.md
- 54 tests across all packages, all passing
2026-07-03 08:04:39 +08:00

43 lines
850 B
Go

package sdk
import "fmt"
type EventBus interface {
Publish(event *Event)
Subscribe(eventType EventType, handler EventHandler) func()
}
type InProcessBus struct {
subs map[EventType][]EventHandler
}
func NewInProcessBus() *InProcessBus {
return &InProcessBus{
subs: make(map[EventType][]EventHandler),
}
}
func (b *InProcessBus) Publish(evt *Event) {
for _, h := range b.subs[EventAll] {
h(evt)
}
if evt.Type != EventAll {
for _, h := range b.subs[evt.Type] {
h(evt)
}
}
}
func (b *InProcessBus) Subscribe(eventType EventType, handler EventHandler) func() {
b.subs[eventType] = append(b.subs[eventType], handler)
return func() {
list := b.subs[eventType]
for i, h := range list {
if fmt.Sprintf("%p", h) == fmt.Sprintf("%p", handler) {
b.subs[eventType] = append(list[:i], list[i+1:]...)
break
}
}
}
}