eventbus

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package eventbus provides a synchronous, typed event bus for decoupling components that currently rely on scattered SetXxxCallback() wiring.

Events are dispatched synchronously in registration order. The bus is safe for concurrent use; Subscribe takes a write lock, Publish takes a read lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubscribeTyped

func SubscribeTyped[T Event](bus *Bus, handler func(T))

SubscribeTyped is a generic helper that provides type-safe subscription. It registers a handler that automatically type-asserts the event before calling the typed handler function.

Types

type AgentDiscoveredEvent added in v0.4.0

type AgentDiscoveredEvent struct {
	DID          string
	Name         string
	Capabilities []string
}

AgentDiscoveredEvent is published when a new remote agent is discovered.

func (AgentDiscoveredEvent) EventName added in v0.4.0

func (e AgentDiscoveredEvent) EventName() string

EventName implements Event.

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is a synchronous typed event bus.

func New

func New() *Bus

New creates a new event bus.

func (*Bus) Publish

func (b *Bus) Publish(event Event)

Publish sends an event to all registered handlers synchronously. If no handlers are registered for the event, it is silently ignored.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventName string, handler HandlerFunc)

Subscribe registers a handler for a specific event name.

type ContentSavedEvent

type ContentSavedEvent struct {
	ID         string
	Collection string
	Content    string
	Metadata   map[string]string
	Source     string // "knowledge" or "memory"
}

ContentSavedEvent is published when knowledge or memory content is saved. Replaces: SetEmbedCallback, SetGraphCallback on knowledge and memory stores.

func (ContentSavedEvent) EventName

func (e ContentSavedEvent) EventName() string

EventName implements Event.

type Event

type Event interface {
	EventName() string
}

Event is implemented by all event types.

type HandlerFunc

type HandlerFunc func(event Event)

HandlerFunc processes an event.

type MemoryGraphEvent

type MemoryGraphEvent struct {
	Triples    []Triple
	SessionKey string
	Type       string // "observation" or "reflection"
}

MemoryGraphEvent is published when memory graph hooks fire. Replaces: memory.Store.SetGraphHooks.

func (MemoryGraphEvent) EventName

func (e MemoryGraphEvent) EventName() string

EventName implements Event.

type PaymentNegotiatedEvent added in v0.4.0

type PaymentNegotiatedEvent struct {
	TeamID   string
	AgentDID string
	Mode     string
	Price    float64
}

PaymentNegotiatedEvent is published when payment terms are agreed.

func (PaymentNegotiatedEvent) EventName added in v0.4.0

func (e PaymentNegotiatedEvent) EventName() string

EventName implements Event.

type PaymentSettledEvent added in v0.4.0

type PaymentSettledEvent struct {
	TeamID   string
	AgentDID string
	Amount   float64
	TxHash   string
}

PaymentSettledEvent is published when a payment is settled on-chain.

func (PaymentSettledEvent) EventName added in v0.4.0

func (e PaymentSettledEvent) EventName() string

EventName implements Event.

type ReputationChangedEvent

type ReputationChangedEvent struct {
	PeerDID  string
	NewScore float64
}

ReputationChangedEvent is published when a peer's reputation changes. Replaces: reputation.Store.SetOnChangeCallback.

func (ReputationChangedEvent) EventName

func (e ReputationChangedEvent) EventName() string

EventName implements Event.

type TaskCompletedEvent added in v0.4.0

type TaskCompletedEvent struct {
	TeamID     string
	TaskID     string
	AgentDID   string
	Success    bool
	DurationMs int64
}

TaskCompletedEvent is published when a delegated task completes successfully.

func (TaskCompletedEvent) EventName added in v0.4.0

func (e TaskCompletedEvent) EventName() string

EventName implements Event.

type TaskDelegatedEvent added in v0.4.0

type TaskDelegatedEvent struct {
	TeamID   string
	TaskID   string
	AgentDID string
}

TaskDelegatedEvent is published when a task is delegated to an agent.

func (TaskDelegatedEvent) EventName added in v0.4.0

func (e TaskDelegatedEvent) EventName() string

EventName implements Event.

type TaskFailedEvent added in v0.4.0

type TaskFailedEvent struct {
	TeamID   string
	TaskID   string
	AgentDID string
	Error    string
}

TaskFailedEvent is published when a delegated task fails.

func (TaskFailedEvent) EventName added in v0.4.0

func (e TaskFailedEvent) EventName() string

EventName implements Event.

type TeamConflictDetectedEvent added in v0.4.0

type TeamConflictDetectedEvent struct {
	TeamID   string
	ToolName string
	Members  int
}

TeamConflictDetectedEvent is published when conflicting results are found.

func (TeamConflictDetectedEvent) EventName added in v0.4.0

func (e TeamConflictDetectedEvent) EventName() string

EventName implements Event.

type TeamDisbandedEvent added in v0.4.0

type TeamDisbandedEvent struct {
	TeamID string
	Reason string
}

TeamDisbandedEvent is published when a team is disbanded.

func (TeamDisbandedEvent) EventName added in v0.4.0

func (e TeamDisbandedEvent) EventName() string

EventName implements Event.

type TeamFormedEvent added in v0.4.0

type TeamFormedEvent struct {
	TeamID    string
	Name      string
	Goal      string
	LeaderDID string
	Members   int
}

TeamFormedEvent is published when a new agent team is created.

func (TeamFormedEvent) EventName added in v0.4.0

func (e TeamFormedEvent) EventName() string

EventName implements Event.

type TeamHealthCheckEvent added in v0.4.0

type TeamHealthCheckEvent struct {
	TeamID  string
	Healthy int
	Total   int
}

TeamHealthCheckEvent is published after a team-level health sweep.

func (TeamHealthCheckEvent) EventName added in v0.4.0

func (e TeamHealthCheckEvent) EventName() string

EventName implements Event.

type TeamLeaderChangedEvent added in v0.4.0

type TeamLeaderChangedEvent struct {
	TeamID       string
	OldLeaderDID string
	NewLeaderDID string
}

TeamLeaderChangedEvent is published when a team's leader is replaced.

func (TeamLeaderChangedEvent) EventName added in v0.4.0

func (e TeamLeaderChangedEvent) EventName() string

EventName implements Event.

type TeamMemberJoinedEvent added in v0.4.0

type TeamMemberJoinedEvent struct {
	TeamID    string
	MemberDID string
	Role      string
}

TeamMemberJoinedEvent is published when an agent joins a team.

func (TeamMemberJoinedEvent) EventName added in v0.4.0

func (e TeamMemberJoinedEvent) EventName() string

EventName implements Event.

type TeamMemberLeftEvent added in v0.4.0

type TeamMemberLeftEvent struct {
	TeamID    string
	MemberDID string
	Reason    string
}

TeamMemberLeftEvent is published when an agent leaves a team.

func (TeamMemberLeftEvent) EventName added in v0.4.0

func (e TeamMemberLeftEvent) EventName() string

EventName implements Event.

type TeamPaymentAgreedEvent added in v0.4.0

type TeamPaymentAgreedEvent struct {
	TeamID    string
	MemberDID string
	Mode      string
	Price     string
}

TeamPaymentAgreedEvent is published when payment terms are negotiated.

func (TeamPaymentAgreedEvent) EventName added in v0.4.0

func (e TeamPaymentAgreedEvent) EventName() string

EventName implements Event.

type TeamTaskCompletedEvent added in v0.4.0

type TeamTaskCompletedEvent struct {
	TeamID     string
	ToolName   string
	Successful int
	Failed     int
	Duration   time.Duration
}

TeamTaskCompletedEvent is published when a delegated task finishes.

func (TeamTaskCompletedEvent) EventName added in v0.4.0

func (e TeamTaskCompletedEvent) EventName() string

EventName implements Event.

type TeamTaskDelegatedEvent added in v0.4.0

type TeamTaskDelegatedEvent struct {
	TeamID   string
	ToolName string
	Workers  int
}

TeamTaskDelegatedEvent is published when a task is sent to team workers.

func (TeamTaskDelegatedEvent) EventName added in v0.4.0

func (e TeamTaskDelegatedEvent) EventName() string

EventName implements Event.

type ToolExecutionPaidEvent added in v0.4.0

type ToolExecutionPaidEvent struct {
	PeerDID      string
	ToolName     string
	Auth         interface{} // *eip3009.Authorization (interface to avoid import cycle)
	SettlementID string      // non-empty for post-pay deferred entries
}

ToolExecutionPaidEvent is published after a paid tool execution succeeds. The settlement service subscribes to this event to initiate on-chain settlement.

func (ToolExecutionPaidEvent) EventName added in v0.4.0

func (e ToolExecutionPaidEvent) EventName() string

EventName implements Event.

type Triple

type Triple struct {
	Subject   string
	Predicate string
	Object    string
	Metadata  map[string]string
}

Triple mirrors graph.Triple to avoid an import dependency on the graph package, keeping the eventbus package dependency-free.

type TriplesExtractedEvent

type TriplesExtractedEvent struct {
	Triples []Triple
	Source  string // e.g. "learning", "analysis", "librarian"
}

TriplesExtractedEvent is published when graph triples are extracted. Replaces: SetGraphCallback on learning engines and analyzers.

func (TriplesExtractedEvent) EventName

func (e TriplesExtractedEvent) EventName() string

EventName implements Event.

type TrustUpdatedEvent added in v0.4.0

type TrustUpdatedEvent struct {
	AgentDID string
	OldScore float64
	NewScore float64
}

TrustUpdatedEvent is published when an agent's trust score changes.

func (TrustUpdatedEvent) EventName added in v0.4.0

func (e TrustUpdatedEvent) EventName() string

EventName implements Event.

type TurnCompletedEvent

type TurnCompletedEvent struct {
	SessionKey string
}

TurnCompletedEvent is published when a gateway turn completes. Replaces: Gateway.OnTurnComplete callbacks.

func (TurnCompletedEvent) EventName

func (e TurnCompletedEvent) EventName() string

EventName implements Event.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL