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.
Files changed (2) hide show
  1. package/dist/events.js +26 -8
  2. 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) { const nats = await this.moduleLoaded(); const codec = nats.StringCodec(); const subscription = (await this.client()).subscribe(subject); let active = true; void (async () => { for await (const message of subscription) {
28
- if (!active)
29
- break;
30
- try {
31
- await wake(JSON.parse(codec.decode(message.data)));
32
- }
33
- catch { /* malformed events never become durable state */ }
34
- } })(); return async () => { active = false; subscription.unsubscribe(); }; }
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 }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "type": "module",
6
6
  "bin": {