@juspay/neurolink 9.83.0 → 9.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/agent/agent.d.ts +104 -0
- package/dist/agent/agent.js +401 -0
- package/dist/agent/agentNetwork.d.ts +87 -0
- package/dist/agent/agentNetwork.js +458 -0
- package/dist/agent/communication/index.d.ts +9 -0
- package/dist/agent/communication/index.js +9 -0
- package/dist/agent/communication/message-bus.d.ts +113 -0
- package/dist/agent/communication/message-bus.js +406 -0
- package/dist/agent/coordination/coordinator.d.ts +83 -0
- package/dist/agent/coordination/coordinator.js +598 -0
- package/dist/agent/coordination/index.d.ts +10 -0
- package/dist/agent/coordination/index.js +10 -0
- package/dist/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/agent/coordination/task-distributor.js +585 -0
- package/dist/agent/index.d.ts +38 -0
- package/dist/agent/index.js +44 -0
- package/dist/agent/orchestration/index.d.ts +10 -0
- package/dist/agent/orchestration/index.js +10 -0
- package/dist/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/agent/orchestration/orchestrator.js +476 -0
- package/dist/agent/orchestration/topology.d.ts +164 -0
- package/dist/agent/orchestration/topology.js +520 -0
- package/dist/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/agent/prompts/routingPrompts.js +201 -0
- package/dist/browser/neurolink.min.js +377 -358
- package/dist/cli/commands/agent.d.ts +37 -0
- package/dist/cli/commands/agent.js +718 -0
- package/dist/cli/factories/commandFactory.d.ts +8 -0
- package/dist/cli/factories/commandFactory.js +116 -0
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/cli/parser.js +4 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +19 -0
- package/dist/lib/agent/agent.d.ts +104 -0
- package/dist/lib/agent/agent.js +402 -0
- package/dist/lib/agent/agentNetwork.d.ts +87 -0
- package/dist/lib/agent/agentNetwork.js +459 -0
- package/dist/lib/agent/communication/index.d.ts +9 -0
- package/dist/lib/agent/communication/index.js +10 -0
- package/dist/lib/agent/communication/message-bus.d.ts +113 -0
- package/dist/lib/agent/communication/message-bus.js +407 -0
- package/dist/lib/agent/coordination/coordinator.d.ts +83 -0
- package/dist/lib/agent/coordination/coordinator.js +599 -0
- package/dist/lib/agent/coordination/index.d.ts +10 -0
- package/dist/lib/agent/coordination/index.js +11 -0
- package/dist/lib/agent/coordination/task-distributor.d.ts +113 -0
- package/dist/lib/agent/coordination/task-distributor.js +586 -0
- package/dist/lib/agent/index.d.ts +38 -0
- package/dist/lib/agent/index.js +45 -0
- package/dist/lib/agent/orchestration/index.d.ts +10 -0
- package/dist/lib/agent/orchestration/index.js +11 -0
- package/dist/lib/agent/orchestration/orchestrator.d.ts +114 -0
- package/dist/lib/agent/orchestration/orchestrator.js +477 -0
- package/dist/lib/agent/orchestration/topology.d.ts +164 -0
- package/dist/lib/agent/orchestration/topology.js +521 -0
- package/dist/lib/agent/prompts/routingPrompts.d.ts +63 -0
- package/dist/lib/agent/prompts/routingPrompts.js +202 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +19 -0
- package/dist/lib/neurolink.d.ts +129 -0
- package/dist/lib/neurolink.js +276 -0
- package/dist/lib/processors/config/{fileTypes.js → fileExtensions.js} +1 -1
- package/dist/lib/processors/config/index.d.ts +2 -2
- package/dist/lib/processors/config/index.js +2 -2
- package/dist/lib/processors/config/{mimeTypes.js → mimeConstants.js} +1 -1
- package/dist/lib/processors/index.js +8 -0
- package/dist/lib/providers/googleAiStudio.js +3 -3
- package/dist/lib/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/lib/providers/googleNativeGemini3.js +47 -1
- package/dist/lib/providers/googleVertex.js +5 -5
- package/dist/lib/types/agentNetwork.d.ts +1184 -0
- package/dist/lib/types/agentNetwork.js +8 -0
- package/dist/lib/types/cli.d.ts +66 -0
- package/dist/lib/types/generate.d.ts +53 -0
- package/dist/lib/types/index.d.ts +2 -0
- package/dist/lib/types/index.js +3 -0
- package/dist/lib/types/ioProcessor.d.ts +119 -0
- package/dist/lib/types/ioProcessor.js +10 -0
- package/dist/lib/types/stream.d.ts +36 -0
- package/dist/lib/utils/piiDetector.d.ts +24 -0
- package/dist/lib/utils/piiDetector.js +221 -0
- package/dist/lib/utils/responseValidator.d.ts +21 -0
- package/dist/lib/utils/responseValidator.js +354 -0
- package/dist/lib/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/lib/utils/tripwireEvaluator.js +285 -0
- package/dist/neurolink.d.ts +129 -0
- package/dist/neurolink.js +276 -0
- package/dist/processors/config/index.d.ts +2 -2
- package/dist/processors/config/index.js +2 -2
- package/dist/processors/index.js +8 -0
- package/dist/providers/googleAiStudio.js +3 -3
- package/dist/providers/googleNativeGemini3.d.ts +18 -0
- package/dist/providers/googleNativeGemini3.js +47 -1
- package/dist/providers/googleVertex.js +5 -5
- package/dist/types/agentNetwork.d.ts +1184 -0
- package/dist/types/agentNetwork.js +7 -0
- package/dist/types/cli.d.ts +66 -0
- package/dist/types/generate.d.ts +53 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/ioProcessor.d.ts +119 -0
- package/dist/types/ioProcessor.js +9 -0
- package/dist/types/stream.d.ts +36 -0
- package/dist/utils/piiDetector.d.ts +24 -0
- package/dist/utils/piiDetector.js +220 -0
- package/dist/utils/responseValidator.d.ts +21 -0
- package/dist/utils/responseValidator.js +353 -0
- package/dist/utils/tripwireEvaluator.d.ts +73 -0
- package/dist/utils/tripwireEvaluator.js +284 -0
- package/package.json +1 -1
- /package/dist/lib/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/lib/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.d.ts → fileExtensions.d.ts} +0 -0
- /package/dist/processors/config/{fileTypes.js → fileExtensions.js} +0 -0
- /package/dist/processors/config/{mimeTypes.d.ts → mimeConstants.d.ts} +0 -0
- /package/dist/processors/config/{mimeTypes.js → mimeConstants.js} +0 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Bus - Inter-agent communication infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Provides a publish-subscribe message bus for agent-to-agent communication
|
|
5
|
+
* with support for:
|
|
6
|
+
* - Topic-based messaging
|
|
7
|
+
* - Request-response patterns
|
|
8
|
+
* - Broadcast messaging
|
|
9
|
+
* - Message persistence and replay
|
|
10
|
+
*/
|
|
11
|
+
import { EventEmitter } from "events";
|
|
12
|
+
import { randomUUID } from "crypto";
|
|
13
|
+
import { logger } from "../../utils/logger.js";
|
|
14
|
+
/**
|
|
15
|
+
* Message Bus - Central hub for agent communication
|
|
16
|
+
*/
|
|
17
|
+
export class MessageBus {
|
|
18
|
+
subscriptions = new Map();
|
|
19
|
+
messageHistory = [];
|
|
20
|
+
pendingRequests = new Map();
|
|
21
|
+
deadLetterQueue = [];
|
|
22
|
+
config;
|
|
23
|
+
emitter;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = {
|
|
26
|
+
maxHistorySize: 1000,
|
|
27
|
+
defaultTtl: 60000,
|
|
28
|
+
enablePersistence: false,
|
|
29
|
+
enableDeadLetterQueue: true,
|
|
30
|
+
requestTimeout: 30000,
|
|
31
|
+
...config,
|
|
32
|
+
};
|
|
33
|
+
this.emitter = new EventEmitter();
|
|
34
|
+
// Increase max listeners for large networks
|
|
35
|
+
this.emitter.setMaxListeners(100);
|
|
36
|
+
logger.debug("[MessageBus] Created with config", {
|
|
37
|
+
maxHistorySize: this.config.maxHistorySize,
|
|
38
|
+
enableDeadLetterQueue: this.config.enableDeadLetterQueue,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to a topic
|
|
43
|
+
*/
|
|
44
|
+
subscribe(topic, subscriberId, handler, options) {
|
|
45
|
+
const subscriptionId = randomUUID();
|
|
46
|
+
const subscription = {
|
|
47
|
+
id: subscriptionId,
|
|
48
|
+
topic,
|
|
49
|
+
handler,
|
|
50
|
+
options: options ?? {},
|
|
51
|
+
messageCount: 0,
|
|
52
|
+
subscriberId,
|
|
53
|
+
};
|
|
54
|
+
const topicSubs = this.subscriptions.get(topic) ?? [];
|
|
55
|
+
topicSubs.push(subscription);
|
|
56
|
+
this.subscriptions.set(topic, topicSubs);
|
|
57
|
+
logger.debug(`[MessageBus] Subscription created`, {
|
|
58
|
+
subscriptionId,
|
|
59
|
+
topic,
|
|
60
|
+
subscriberId,
|
|
61
|
+
});
|
|
62
|
+
this.emitter.emit("subscription:created", {
|
|
63
|
+
subscriptionId,
|
|
64
|
+
topic,
|
|
65
|
+
subscriberId,
|
|
66
|
+
});
|
|
67
|
+
return subscriptionId;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribe from a topic
|
|
71
|
+
*/
|
|
72
|
+
unsubscribe(subscriptionId) {
|
|
73
|
+
for (const [topic, subs] of this.subscriptions) {
|
|
74
|
+
const index = subs.findIndex((s) => s.id === subscriptionId);
|
|
75
|
+
if (index !== -1) {
|
|
76
|
+
subs.splice(index, 1);
|
|
77
|
+
if (subs.length === 0) {
|
|
78
|
+
this.subscriptions.delete(topic);
|
|
79
|
+
}
|
|
80
|
+
logger.debug(`[MessageBus] Subscription removed`, {
|
|
81
|
+
subscriptionId,
|
|
82
|
+
topic,
|
|
83
|
+
});
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Unsubscribe all subscriptions for an agent
|
|
91
|
+
*/
|
|
92
|
+
unsubscribeAll(subscriberId) {
|
|
93
|
+
let count = 0;
|
|
94
|
+
for (const [topic, subs] of this.subscriptions) {
|
|
95
|
+
const filtered = subs.filter((s) => s.subscriberId !== subscriberId);
|
|
96
|
+
count += subs.length - filtered.length;
|
|
97
|
+
if (filtered.length === 0) {
|
|
98
|
+
this.subscriptions.delete(topic);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.subscriptions.set(topic, filtered);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return count;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Publish a message to a topic
|
|
108
|
+
*/
|
|
109
|
+
async publish(topic, senderId, payload, options) {
|
|
110
|
+
const message = {
|
|
111
|
+
id: randomUUID(),
|
|
112
|
+
type: options?.type ?? "event",
|
|
113
|
+
topic,
|
|
114
|
+
senderId,
|
|
115
|
+
payload,
|
|
116
|
+
priority: options?.priority ?? "normal",
|
|
117
|
+
timestamp: Date.now(),
|
|
118
|
+
ttl: options?.ttl ?? this.config.defaultTtl,
|
|
119
|
+
recipientId: options?.recipientId,
|
|
120
|
+
correlationId: options?.correlationId,
|
|
121
|
+
replyTo: options?.replyTo,
|
|
122
|
+
metadata: options?.metadata,
|
|
123
|
+
};
|
|
124
|
+
await this.deliverMessage(message);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Send a direct message to a specific agent
|
|
128
|
+
*/
|
|
129
|
+
async sendDirect(senderId, recipientId, payload, options) {
|
|
130
|
+
const topic = `direct:${recipientId}`;
|
|
131
|
+
const message = {
|
|
132
|
+
id: randomUUID(),
|
|
133
|
+
type: "direct",
|
|
134
|
+
topic,
|
|
135
|
+
senderId,
|
|
136
|
+
recipientId,
|
|
137
|
+
payload,
|
|
138
|
+
priority: options?.priority ?? "normal",
|
|
139
|
+
timestamp: Date.now(),
|
|
140
|
+
ttl: options?.ttl ?? this.config.defaultTtl,
|
|
141
|
+
metadata: options?.metadata,
|
|
142
|
+
};
|
|
143
|
+
await this.deliverMessage(message);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Send a request and wait for response
|
|
147
|
+
*/
|
|
148
|
+
async request(topic, senderId, payload, timeout) {
|
|
149
|
+
const correlationId = randomUUID();
|
|
150
|
+
const replyTo = `reply:${correlationId}`;
|
|
151
|
+
// Create a promise that will resolve when we get the response
|
|
152
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
153
|
+
const timeoutMs = timeout ?? this.config.requestTimeout;
|
|
154
|
+
const timeoutHandle = setTimeout(() => {
|
|
155
|
+
this.pendingRequests.delete(correlationId);
|
|
156
|
+
this.unsubscribeByTopic(replyTo, senderId);
|
|
157
|
+
reject(new Error(`Request timed out after ${timeoutMs}ms`));
|
|
158
|
+
}, timeoutMs);
|
|
159
|
+
this.pendingRequests.set(correlationId, {
|
|
160
|
+
resolve,
|
|
161
|
+
reject,
|
|
162
|
+
timeout: timeoutHandle,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
// Subscribe to reply topic
|
|
166
|
+
this.subscribe(replyTo, senderId, (msg) => {
|
|
167
|
+
const pending = this.pendingRequests.get(correlationId);
|
|
168
|
+
if (pending) {
|
|
169
|
+
clearTimeout(pending.timeout);
|
|
170
|
+
this.pendingRequests.delete(correlationId);
|
|
171
|
+
this.unsubscribeByTopic(replyTo, senderId);
|
|
172
|
+
pending.resolve(msg);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
// Send the request
|
|
176
|
+
await this.publish(topic, senderId, payload, {
|
|
177
|
+
type: "request",
|
|
178
|
+
correlationId,
|
|
179
|
+
replyTo,
|
|
180
|
+
});
|
|
181
|
+
return responsePromise;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Reply to a request
|
|
185
|
+
*/
|
|
186
|
+
async reply(originalMessage, senderId, payload) {
|
|
187
|
+
if (!originalMessage.replyTo) {
|
|
188
|
+
throw new Error("Cannot reply to message without replyTo field");
|
|
189
|
+
}
|
|
190
|
+
await this.publish(originalMessage.replyTo, senderId, payload, {
|
|
191
|
+
type: "response",
|
|
192
|
+
correlationId: originalMessage.correlationId,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Broadcast a message to all subscribers
|
|
197
|
+
*/
|
|
198
|
+
async broadcast(senderId, payload, excludeTopics) {
|
|
199
|
+
const message = {
|
|
200
|
+
id: randomUUID(),
|
|
201
|
+
type: "broadcast",
|
|
202
|
+
topic: "broadcast",
|
|
203
|
+
senderId,
|
|
204
|
+
payload,
|
|
205
|
+
priority: "normal",
|
|
206
|
+
timestamp: Date.now(),
|
|
207
|
+
ttl: this.config.defaultTtl,
|
|
208
|
+
};
|
|
209
|
+
// Deliver to all topics except excluded ones
|
|
210
|
+
for (const topic of this.subscriptions.keys()) {
|
|
211
|
+
if (excludeTopics?.includes(topic)) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (topic.startsWith("reply:") || topic.startsWith("direct:")) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
await this.deliverMessage({ ...message, topic });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Deliver a message to subscribers
|
|
222
|
+
*/
|
|
223
|
+
async deliverMessage(message) {
|
|
224
|
+
// Add to history
|
|
225
|
+
this.messageHistory.push(message);
|
|
226
|
+
if (this.messageHistory.length > this.config.maxHistorySize) {
|
|
227
|
+
this.messageHistory.shift();
|
|
228
|
+
}
|
|
229
|
+
// Check if message has expired
|
|
230
|
+
if (message.ttl && Date.now() - message.timestamp > message.ttl) {
|
|
231
|
+
logger.debug(`[MessageBus] Message expired`, { messageId: message.id });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const subs = this.subscriptions.get(message.topic) ?? [];
|
|
235
|
+
const deliveryPromises = [];
|
|
236
|
+
for (const sub of subs) {
|
|
237
|
+
// Check if subscription should receive this message
|
|
238
|
+
if (!this.shouldDeliver(message, sub)) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
// Check max messages limit
|
|
242
|
+
if (sub.options.maxMessages !== undefined &&
|
|
243
|
+
sub.options.maxMessages !== -1 &&
|
|
244
|
+
sub.messageCount >= sub.options.maxMessages) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
sub.messageCount++;
|
|
248
|
+
deliveryPromises.push(Promise.resolve(sub.handler(message)).catch((error) => {
|
|
249
|
+
logger.error(`[MessageBus] Message delivery failed`, {
|
|
250
|
+
messageId: message.id,
|
|
251
|
+
subscriptionId: sub.id,
|
|
252
|
+
error: error instanceof Error ? error.message : String(error),
|
|
253
|
+
});
|
|
254
|
+
// Add to dead letter queue if enabled
|
|
255
|
+
if (this.config.enableDeadLetterQueue) {
|
|
256
|
+
this.deadLetterQueue.push(message);
|
|
257
|
+
}
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
await Promise.all(deliveryPromises);
|
|
261
|
+
this.emitter.emit("message:delivered", {
|
|
262
|
+
messageId: message.id,
|
|
263
|
+
topic: message.topic,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Check if message should be delivered to subscription
|
|
268
|
+
*/
|
|
269
|
+
shouldDeliver(message, sub) {
|
|
270
|
+
const opts = sub.options;
|
|
271
|
+
// Filter by sender
|
|
272
|
+
if (opts.filterBySender &&
|
|
273
|
+
!opts.filterBySender.includes(message.senderId)) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
// Filter by type
|
|
277
|
+
if (opts.filterByType && !opts.filterByType.includes(message.type)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
// Filter by priority
|
|
281
|
+
if (opts.filterByPriority &&
|
|
282
|
+
!opts.filterByPriority.includes(message.priority)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
// Custom filter
|
|
286
|
+
if (opts.customFilter && !opts.customFilter(message)) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
// Direct messages: check recipient
|
|
290
|
+
if (message.type === "direct" && message.recipientId !== sub.subscriberId) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Unsubscribe by topic for a specific subscriber
|
|
297
|
+
*/
|
|
298
|
+
unsubscribeByTopic(topic, subscriberId) {
|
|
299
|
+
const subs = this.subscriptions.get(topic);
|
|
300
|
+
if (subs) {
|
|
301
|
+
const filtered = subs.filter((s) => s.subscriberId !== subscriberId);
|
|
302
|
+
if (filtered.length === 0) {
|
|
303
|
+
this.subscriptions.delete(topic);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.subscriptions.set(topic, filtered);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get message history for a topic
|
|
312
|
+
*/
|
|
313
|
+
getHistory(topic, limit) {
|
|
314
|
+
let messages = topic
|
|
315
|
+
? this.messageHistory.filter((m) => m.topic === topic)
|
|
316
|
+
: this.messageHistory;
|
|
317
|
+
if (limit) {
|
|
318
|
+
messages = messages.slice(-limit);
|
|
319
|
+
}
|
|
320
|
+
return messages;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get dead letter queue messages
|
|
324
|
+
*/
|
|
325
|
+
getDeadLetterQueue() {
|
|
326
|
+
return [...this.deadLetterQueue];
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Clear dead letter queue
|
|
330
|
+
*/
|
|
331
|
+
clearDeadLetterQueue() {
|
|
332
|
+
this.deadLetterQueue = [];
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Replay messages from history
|
|
336
|
+
*/
|
|
337
|
+
async replayHistory(topic, subscriberId, since) {
|
|
338
|
+
const messages = this.messageHistory.filter((m) => m.topic === topic && (!since || m.timestamp >= since));
|
|
339
|
+
const subs = this.subscriptions
|
|
340
|
+
.get(topic)
|
|
341
|
+
?.filter((s) => s.subscriberId === subscriberId) ?? [];
|
|
342
|
+
for (const message of messages) {
|
|
343
|
+
for (const sub of subs) {
|
|
344
|
+
if (this.shouldDeliver(message, sub)) {
|
|
345
|
+
await Promise.resolve(sub.handler(message)).catch(() => {
|
|
346
|
+
// Ignore replay errors
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Get all topics
|
|
354
|
+
*/
|
|
355
|
+
getTopics() {
|
|
356
|
+
return Array.from(this.subscriptions.keys());
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get subscriber count for a topic
|
|
360
|
+
*/
|
|
361
|
+
getSubscriberCount(topic) {
|
|
362
|
+
return this.subscriptions.get(topic)?.length ?? 0;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Get statistics
|
|
366
|
+
*/
|
|
367
|
+
getStats() {
|
|
368
|
+
let totalSubscriptions = 0;
|
|
369
|
+
for (const subs of this.subscriptions.values()) {
|
|
370
|
+
totalSubscriptions += subs.length;
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
topicCount: this.subscriptions.size,
|
|
374
|
+
totalSubscriptions,
|
|
375
|
+
historySize: this.messageHistory.length,
|
|
376
|
+
deadLetterQueueSize: this.deadLetterQueue.length,
|
|
377
|
+
pendingRequests: this.pendingRequests.size,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Subscribe to bus events
|
|
382
|
+
*/
|
|
383
|
+
on(event, handler) {
|
|
384
|
+
this.emitter.on(event, handler);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Unsubscribe from bus events
|
|
388
|
+
*/
|
|
389
|
+
off(event, handler) {
|
|
390
|
+
this.emitter.off(event, handler);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Shutdown the message bus
|
|
394
|
+
*/
|
|
395
|
+
shutdown() {
|
|
396
|
+
// Clear pending requests
|
|
397
|
+
for (const [, pending] of this.pendingRequests) {
|
|
398
|
+
clearTimeout(pending.timeout);
|
|
399
|
+
pending.reject(new Error("Message bus shutdown"));
|
|
400
|
+
}
|
|
401
|
+
this.pendingRequests.clear();
|
|
402
|
+
// Clear subscriptions
|
|
403
|
+
this.subscriptions.clear();
|
|
404
|
+
logger.debug("[MessageBus] Shutdown complete");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
//# sourceMappingURL=message-bus.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Coordinator - Manages coordination between agents in a network
|
|
3
|
+
*
|
|
4
|
+
* The Coordinator is responsible for:
|
|
5
|
+
* - Managing agent lifecycle and state
|
|
6
|
+
* - Coordinating task execution across multiple agents
|
|
7
|
+
* - Handling agent dependencies and execution order
|
|
8
|
+
* - Managing shared context and state between agents
|
|
9
|
+
*/
|
|
10
|
+
import type { Agent } from "../agent.js";
|
|
11
|
+
import type { AgentStatus, CoordinatorConfig, CoordinationResult, TaskAssignment } from "../../types/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Agent Coordinator - Orchestrates multi-agent execution
|
|
14
|
+
*/
|
|
15
|
+
export declare class AgentCoordinator {
|
|
16
|
+
private agents;
|
|
17
|
+
private config;
|
|
18
|
+
private emitter;
|
|
19
|
+
private activeExecutions;
|
|
20
|
+
private executionHistory;
|
|
21
|
+
private roundRobinCursor;
|
|
22
|
+
constructor(config?: Partial<CoordinatorConfig>);
|
|
23
|
+
/**
|
|
24
|
+
* Register an agent with the coordinator
|
|
25
|
+
*/
|
|
26
|
+
registerAgent(agent: Agent): void;
|
|
27
|
+
/**
|
|
28
|
+
* Unregister an agent
|
|
29
|
+
*/
|
|
30
|
+
unregisterAgent(agentId: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get all registered agents
|
|
33
|
+
*/
|
|
34
|
+
getAgents(): Agent[];
|
|
35
|
+
/**
|
|
36
|
+
* Get agent status
|
|
37
|
+
*/
|
|
38
|
+
getAgentStatus(agentId: string): AgentStatus | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a coordinated task across agents
|
|
41
|
+
*/
|
|
42
|
+
coordinate(task: string, options?: Partial<CoordinatorConfig>): Promise<CoordinationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Execute agents sequentially
|
|
45
|
+
*/
|
|
46
|
+
private executeSequential;
|
|
47
|
+
/**
|
|
48
|
+
* Execute agents in parallel
|
|
49
|
+
*/
|
|
50
|
+
private executeParallel;
|
|
51
|
+
/**
|
|
52
|
+
* Execute agents in a pipeline (output feeds into next)
|
|
53
|
+
*/
|
|
54
|
+
private executePipeline;
|
|
55
|
+
/**
|
|
56
|
+
* Execute using round-robin distribution
|
|
57
|
+
*/
|
|
58
|
+
private executeRoundRobin;
|
|
59
|
+
/**
|
|
60
|
+
* Execute using least busy agent
|
|
61
|
+
*/
|
|
62
|
+
private executeLeastBusy;
|
|
63
|
+
/**
|
|
64
|
+
* Execute an agent with timeout
|
|
65
|
+
*/
|
|
66
|
+
private executeAgentWithTimeout;
|
|
67
|
+
/**
|
|
68
|
+
* Execute multiple task assignments with dependencies
|
|
69
|
+
*/
|
|
70
|
+
executeWithDependencies(assignments: TaskAssignment[]): Promise<CoordinationResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Update coordinator configuration
|
|
73
|
+
*/
|
|
74
|
+
updateConfig(config: Partial<CoordinatorConfig>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Subscribe to coordinator events
|
|
77
|
+
*/
|
|
78
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Unsubscribe from coordinator events
|
|
81
|
+
*/
|
|
82
|
+
off(event: string, handler: (...args: unknown[]) => void): void;
|
|
83
|
+
}
|