@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
114 lines (113 loc) • 3.42 kB
TypeScript
/**
* 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<Omit<AgentMessage, "id" | "topic" | "senderId" | "payload" | "timestamp">>): Promise<void>;
/**
* Send a direct message to a specific agent
*/
sendDirect(senderId: string, recipientId: string, payload: unknown, options?: Partial<Omit<AgentMessage, "id" | "senderId" | "recipientId" | "payload" | "timestamp">>): Promise<void>;
/**
* Send a request and wait for response
*/
request(topic: string, senderId: string, payload: unknown, timeout?: number): Promise<AgentMessage>;
/**
* Reply to a request
*/
reply(originalMessage: AgentMessage, senderId: string, payload: unknown): Promise<void>;
/**
* Broadcast a message to all subscribers
*/
broadcast(senderId: string, payload: unknown, excludeTopics?: string[]): Promise<void>;
/**
* 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<void>;
/**
* 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;
}