eventbus

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 3 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 BudgetAlertEvent added in v0.5.0

type BudgetAlertEvent struct {
	TaskID    string
	Threshold float64 // the threshold percentage that was crossed (e.g. 0.5, 0.8)
}

BudgetAlertEvent is published when a task budget crosses a configured threshold.

func (BudgetAlertEvent) EventName added in v0.5.0

func (e BudgetAlertEvent) EventName() string

EventName implements Event.

type BudgetExhaustedEvent added in v0.5.0

type BudgetExhaustedEvent struct {
	TaskID     string
	TotalSpent *big.Int
}

BudgetExhaustedEvent is published when a task budget is fully consumed.

func (BudgetExhaustedEvent) EventName added in v0.5.0

func (e BudgetExhaustedEvent) 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 EscrowCreatedEvent added in v0.5.0

type EscrowCreatedEvent struct {
	EscrowID string
	PayerDID string
	PayeeDID string
	Amount   *big.Int
}

EscrowCreatedEvent is published when an escrow is locked.

func (EscrowCreatedEvent) EventName added in v0.5.0

func (e EscrowCreatedEvent) EventName() string

EventName implements Event.

type EscrowDanglingEvent added in v0.6.0

type EscrowDanglingEvent struct {
	EscrowID     string
	BuyerDID     string
	SellerDID    string
	Amount       string // string representation of *big.Int
	PendingSince time.Time
	Action       string // "expired", "refunded"
}

EscrowDanglingEvent is published when an escrow is stuck in Pending too long.

func (EscrowDanglingEvent) EventName added in v0.6.0

func (e EscrowDanglingEvent) EventName() string

EventName implements Event.

type EscrowMilestoneEvent added in v0.5.0

type EscrowMilestoneEvent struct {
	EscrowID    string
	MilestoneID string
	Index       int
}

EscrowMilestoneEvent is published when an escrow milestone is completed.

func (EscrowMilestoneEvent) EventName added in v0.5.0

func (e EscrowMilestoneEvent) EventName() string

EventName implements Event.

type EscrowOnChainDepositEvent added in v0.5.0

type EscrowOnChainDepositEvent struct {
	EscrowID string
	DealID   string
	Buyer    string
	Amount   *big.Int
	TxHash   string
}

EscrowOnChainDepositEvent is published when tokens are deposited into an on-chain escrow.

func (EscrowOnChainDepositEvent) EventName added in v0.5.0

func (e EscrowOnChainDepositEvent) EventName() string

EventName implements Event.

type EscrowOnChainDisputeEvent added in v0.5.0

type EscrowOnChainDisputeEvent struct {
	EscrowID  string
	DealID    string
	Initiator string
	TxHash    string
}

EscrowOnChainDisputeEvent is published when an on-chain dispute is raised.

func (EscrowOnChainDisputeEvent) EventName added in v0.5.0

func (e EscrowOnChainDisputeEvent) EventName() string

EventName implements Event.

type EscrowOnChainRefundEvent added in v0.5.0

type EscrowOnChainRefundEvent struct {
	EscrowID string
	DealID   string
	Buyer    string
	Amount   *big.Int
	TxHash   string
}

EscrowOnChainRefundEvent is published when on-chain escrow funds are refunded.

func (EscrowOnChainRefundEvent) EventName added in v0.5.0

func (e EscrowOnChainRefundEvent) EventName() string

EventName implements Event.

type EscrowOnChainReleaseEvent added in v0.5.0

type EscrowOnChainReleaseEvent struct {
	EscrowID string
	DealID   string
	Seller   string
	Amount   *big.Int
	TxHash   string
}

EscrowOnChainReleaseEvent is published when on-chain escrow funds are released.

func (EscrowOnChainReleaseEvent) EventName added in v0.5.0

func (e EscrowOnChainReleaseEvent) EventName() string

EventName implements Event.

type EscrowOnChainResolvedEvent added in v0.5.0

type EscrowOnChainResolvedEvent struct {
	EscrowID    string
	DealID      string
	SellerFavor bool
	Amount      *big.Int
	TxHash      string
}

EscrowOnChainResolvedEvent is published when an on-chain dispute is resolved.

func (EscrowOnChainResolvedEvent) EventName added in v0.5.0

func (e EscrowOnChainResolvedEvent) EventName() string

EventName implements Event.

type EscrowOnChainWorkEvent added in v0.5.0

type EscrowOnChainWorkEvent struct {
	EscrowID string
	DealID   string
	Seller   string
	WorkHash string
	TxHash   string
}

EscrowOnChainWorkEvent is published when work proof is submitted on-chain.

func (EscrowOnChainWorkEvent) EventName added in v0.5.0

func (e EscrowOnChainWorkEvent) EventName() string

EventName implements Event.

type EscrowReleasedEvent added in v0.5.0

type EscrowReleasedEvent struct {
	EscrowID string
	Amount   *big.Int
}

EscrowReleasedEvent is published when escrow funds are released on-chain.

func (EscrowReleasedEvent) EventName added in v0.5.0

func (e EscrowReleasedEvent) EventName() string

EventName implements Event.

type EscrowReorgDetectedEvent added in v0.6.0

type EscrowReorgDetectedEvent struct {
	PreviousBlock uint64
	NewBlock      uint64
	Depth         uint64
	ExceedsDepth  bool // reorg deeper than confirmationDepth
}

EscrowReorgDetectedEvent is published when a chain reorganization is detected by the event monitor (safeBlock < lastBlock).

func (EscrowReorgDetectedEvent) EventName added in v0.6.0

func (e EscrowReorgDetectedEvent) EventName() string

EventName implements Event.

type Event

type Event interface {
	EventName() string
}

Event is implemented by all event types.

type GitDivergenceInfo added in v0.6.0

type GitDivergenceInfo struct {
	MemberDID string
	HeadHash  string
}

GitDivergenceInfo describes a member whose HEAD diverges from the majority.

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 NegotiationCompletedEvent added in v0.5.0

type NegotiationCompletedEvent struct {
	SessionID    string
	InitiatorDID string
	ResponderDID string
	AgreedPrice  *big.Int
}

NegotiationCompletedEvent is published when negotiation terms are agreed.

func (NegotiationCompletedEvent) EventName added in v0.5.0

func (e NegotiationCompletedEvent) EventName() string

EventName implements Event.

type NegotiationFailedEvent added in v0.5.0

type NegotiationFailedEvent struct {
	SessionID string
	Reason    string // "rejected", "expired", "cancelled"
}

NegotiationFailedEvent is published when a negotiation fails or expires.

func (NegotiationFailedEvent) EventName added in v0.5.0

func (e NegotiationFailedEvent) EventName() string

EventName implements Event.

type NegotiationStartedEvent added in v0.5.0

type NegotiationStartedEvent struct {
	SessionID    string
	InitiatorDID string
	ResponderDID string
	ToolName     string
}

NegotiationStartedEvent is published when a negotiation session begins.

func (NegotiationStartedEvent) EventName added in v0.5.0

func (e NegotiationStartedEvent) 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 TeamBudgetWarningEvent added in v0.6.0

type TeamBudgetWarningEvent struct {
	TeamID    string
	Threshold float64
	Spent     float64
	Budget    float64
}

TeamBudgetWarningEvent is published when a team's budget crosses a warning threshold.

func (TeamBudgetWarningEvent) EventName added in v0.6.0

func (e TeamBudgetWarningEvent) 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 TeamGracefulShutdownEvent added in v0.6.0

type TeamGracefulShutdownEvent struct {
	TeamID         string
	Reason         string
	BundlesCreated int
	MembersSettled int
}

TeamGracefulShutdownEvent is published when a team undergoes graceful shutdown.

func (TeamGracefulShutdownEvent) EventName added in v0.6.0

func (e TeamGracefulShutdownEvent) 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 TeamMemberUnhealthyEvent added in v0.6.0

type TeamMemberUnhealthyEvent struct {
	TeamID      string
	MemberDID   string
	MemberName  string
	MissedPings int
	LastSeenAt  time.Time
}

TeamMemberUnhealthyEvent is published when a team member misses too many health pings.

func (TeamMemberUnhealthyEvent) EventName added in v0.6.0

func (e TeamMemberUnhealthyEvent) 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 TokenUsageEvent added in v0.5.0

type TokenUsageEvent struct {
	Provider     string
	Model        string
	SessionKey   string
	AgentName    string
	InputTokens  int64
	OutputTokens int64
	TotalTokens  int64
	CacheTokens  int64
}

TokenUsageEvent is published when an LLM provider returns token usage data. The observability TokenTracker subscribes to this event.

func (TokenUsageEvent) EventName added in v0.5.0

func (e TokenUsageEvent) 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.

type WorkspaceArchivedEvent added in v0.6.0

type WorkspaceArchivedEvent struct {
	WorkspaceID string
	ArchivedAt  time.Time
}

WorkspaceArchivedEvent is published when a workspace is archived.

func (WorkspaceArchivedEvent) EventName added in v0.6.0

func (e WorkspaceArchivedEvent) EventName() string

EventName implements Event.

type WorkspaceCommitReceivedEvent added in v0.6.0

type WorkspaceCommitReceivedEvent struct {
	WorkspaceID string
	CommitHash  string
	SenderDID   string
	Message     string
	ReceivedAt  time.Time
}

WorkspaceCommitReceivedEvent is published when a git commit is received in a workspace.

func (WorkspaceCommitReceivedEvent) EventName added in v0.6.0

func (e WorkspaceCommitReceivedEvent) EventName() string

EventName implements Event.

type WorkspaceCreatedEvent added in v0.6.0

type WorkspaceCreatedEvent struct {
	WorkspaceID string
	Name        string
	Goal        string
	CreatorDID  string
	CreatedAt   time.Time
}

WorkspaceCreatedEvent is published when a new workspace is created.

func (WorkspaceCreatedEvent) EventName added in v0.6.0

func (e WorkspaceCreatedEvent) EventName() string

EventName implements Event.

type WorkspaceGitDivergenceEvent added in v0.6.0

type WorkspaceGitDivergenceEvent struct {
	WorkspaceID  string
	MajorityHead string
	Divergent    []GitDivergenceInfo
	DetectedAt   time.Time
}

WorkspaceGitDivergenceEvent is published when team members have divergent git HEADs.

func (WorkspaceGitDivergenceEvent) EventName added in v0.6.0

func (e WorkspaceGitDivergenceEvent) EventName() string

EventName implements Event.

type WorkspaceMemberJoinedEvent added in v0.6.0

type WorkspaceMemberJoinedEvent struct {
	WorkspaceID string
	MemberDID   string
	JoinedAt    time.Time
}

WorkspaceMemberJoinedEvent is published when a member joins a workspace.

func (WorkspaceMemberJoinedEvent) EventName added in v0.6.0

func (e WorkspaceMemberJoinedEvent) EventName() string

EventName implements Event.

type WorkspaceMemberLeftEvent added in v0.6.0

type WorkspaceMemberLeftEvent struct {
	WorkspaceID string
	MemberDID   string
	LeftAt      time.Time
}

WorkspaceMemberLeftEvent is published when a member leaves a workspace.

func (WorkspaceMemberLeftEvent) EventName added in v0.6.0

func (e WorkspaceMemberLeftEvent) EventName() string

EventName implements Event.

type WorkspaceMessagePostedEvent added in v0.6.0

type WorkspaceMessagePostedEvent struct {
	WorkspaceID string
	MessageID   string
	MessageType string
	SenderDID   string
	PostedAt    time.Time
}

WorkspaceMessagePostedEvent is published when a message is posted to a workspace.

func (WorkspaceMessagePostedEvent) EventName added in v0.6.0

func (e WorkspaceMessagePostedEvent) EventName() string

EventName implements Event.

Jump to

Keyboard shortcuts

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