/** * Message Bus - Inter-agent communication infrastructure * * Provides a publish-subscribe message bus for agent-to-agent communication * with support for: * - Topic-based messaging * - Request-response patterns * - Broadcast messaging * - Message persistence and replay */ import type { AgentMessage, MessageHandler, SubscriptionOptions, MessageBusConfig } from "../../types/index.js"; /** * Message Bus - Central hub for agent communication */ export declare class MessageBus { private subscriptions; private messageHistory; private pendingRequests; private deadLetterQueue; private config; private emitter; constructor(config?: MessageBusConfig); /** * Subscribe to a topic */ subscribe(topic: string, subscriberId: string, handler: MessageHandler, options?: SubscriptionOptions): string; /** * Unsubscribe from a topic */ unsubscribe(subscriptionId: string): boolean; /** * Unsubscribe all subscriptions for an agent */ unsubscribeAll(subscriberId: string): number; /** * Publish a message to a topic */ publish(topic: string, senderId: string, payload: unknown, options?: Partial>): Promise; /** * Send a direct message to a specific agent */ sendDirect(senderId: string, recipientId: string, payload: unknown, options?: Partial>): Promise; /** * Send a request and wait for response */ request(topic: string, senderId: string, payload: unknown, timeout?: number): Promise; /** * Reply to a request */ reply(originalMessage: AgentMessage, senderId: string, payload: unknown): Promise; /** * Broadcast a message to all subscribers */ broadcast(senderId: string, payload: unknown, excludeTopics?: string[]): Promise; /** * Deliver a message to subscribers */ private deliverMessage; /** * Check if message should be delivered to subscription */ private shouldDeliver; /** * Unsubscribe by topic for a specific subscriber */ private unsubscribeByTopic; /** * Get message history for a topic */ getHistory(topic?: string, limit?: number): AgentMessage[]; /** * Get dead letter queue messages */ getDeadLetterQueue(): AgentMessage[]; /** * Clear dead letter queue */ clearDeadLetterQueue(): void; /** * Replay messages from history */ replayHistory(topic: string, subscriberId: string, since?: number): Promise; /** * Get all topics */ getTopics(): string[]; /** * Get subscriber count for a topic */ getSubscriberCount(topic: string): number; /** * Get statistics */ getStats(): { topicCount: number; totalSubscriptions: number; historySize: number; deadLetterQueueSize: number; pendingRequests: number; }; /** * Subscribe to bus events */ on(event: string, handler: (...args: unknown[]) => void): void; /** * Unsubscribe from bus events */ off(event: string, handler: (...args: unknown[]) => void): void; /** * Shutdown the message bus */ shutdown(): void; }