agents-relay 1.0.7 → 1.0.8
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/dist/events.js +26 -8
- package/package.json +1 -1
package/dist/events.js
CHANGED
|
@@ -24,13 +24,31 @@ export class NatsEventBus {
|
|
|
24
24
|
async publish(event) { const nats = await this.moduleLoaded(); const subject = `${this.subjectPrefix}.${subjectToken(event.job_id)}.${event.type}`; (await this.client()).publish(subject, nats.StringCodec().encode(JSON.stringify(event))); }
|
|
25
25
|
async subscribe(jobId, wake) { return this.subscribeSubject(`${this.subjectPrefix}.${subjectToken(jobId)}.>`, wake); }
|
|
26
26
|
async subscribeAll(wake) { return this.subscribeSubject(`${this.subjectPrefix}.>`, wake); }
|
|
27
|
-
async subscribeSubject(subject, wake) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
async subscribeSubject(subject, wake) {
|
|
28
|
+
const nats = await this.moduleLoaded();
|
|
29
|
+
const codec = nats.StringCodec();
|
|
30
|
+
const subscription = (await this.client()).subscribe(subject);
|
|
31
|
+
let active = true;
|
|
32
|
+
void (async () => {
|
|
33
|
+
for await (const message of subscription) {
|
|
34
|
+
if (!active)
|
|
35
|
+
break;
|
|
36
|
+
let event;
|
|
37
|
+
try {
|
|
38
|
+
event = JSON.parse(codec.decode(message.data));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await wake(event);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
process.stderr.write(`warning: event handler failed for ${subject}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
return async () => { active = false; subscription.unsubscribe(); };
|
|
52
|
+
}
|
|
35
53
|
}
|
|
36
54
|
export function eventFor(jobId, taskId, parentTaskId, type, status, message, visibility = 'orchestrator', data) { return { version: 1, event_id: randomUUID(), job_id: jobId, task_id: taskId, parent_task_id: parentTaskId, type, status, timestamp: new Date().toISOString(), visibility, level: status === 'failed' || status === 'blocked' ? 'error' : 'info', message, data }; }
|