/** * Event System - PubSub and Event Emitter for agent communication * Inspired by mastra's events module */ import { EventEmitter } from 'events'; export interface Event { id: string; topic: string; data: any; createdAt: Date; metadata?: Record; } export type EventHandler = (event: Event, ack?: () => Promise) => void | Promise; /** * Abstract PubSub base class */ export declare abstract class PubSub { abstract publish(topic: string, data: any, metadata?: Record): Promise; abstract subscribe(topic: string, handler: EventHandler): Promise; abstract unsubscribe(topic: string, handler: EventHandler): Promise; abstract close(): Promise; } /** * In-memory EventEmitter-based PubSub implementation */ export declare class EventEmitterPubSub extends PubSub { private emitter; private handlers; constructor(existingEmitter?: EventEmitter); publish(topic: string, data: any, metadata?: Record): Promise; subscribe(topic: string, handler: EventHandler): Promise; unsubscribe(topic: string, handler: EventHandler): Promise; close(): Promise; /** * Wait for a specific event with optional timeout */ waitFor(topic: string, timeout?: number): Promise; /** * Get the underlying EventEmitter */ getEmitter(): EventEmitter; } /** * Agent Event Bus - Specialized event system for agent communication */ export declare class AgentEventBus { private pubsub; private agentId; constructor(agentId: string, pubsub?: PubSub); /** * Emit an agent event */ emit(eventType: string, data: any): Promise; /** * Listen for agent events */ on(eventType: string, handler: (data: any) => void | Promise): Promise; /** * Broadcast to all agents */ broadcast(eventType: string, data: any): Promise; /** * Listen for broadcast events */ onBroadcast(eventType: string, handler: (data: any, sourceAgentId: string) => void | Promise): Promise; /** * Send message to specific agent */ sendTo(targetAgentId: string, eventType: string, data: any): Promise; close(): Promise; } export declare const AgentEvents: { readonly STARTED: "started"; readonly COMPLETED: "completed"; readonly ERROR: "error"; readonly TOOL_CALLED: "tool_called"; readonly TOOL_RESULT: "tool_result"; readonly MESSAGE_RECEIVED: "message_received"; readonly MESSAGE_SENT: "message_sent"; readonly HANDOFF_INITIATED: "handoff_initiated"; readonly HANDOFF_COMPLETED: "handoff_completed"; }; export declare function createEventBus(agentId: string): AgentEventBus; export declare function createPubSub(): EventEmitterPubSub;