agents-relay 1.0.9 → 1.0.10

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/pool.js CHANGED
@@ -21,6 +21,7 @@ export class RepositoryWorkerPool {
21
21
  makeReconciler;
22
22
  running = false;
23
23
  pending = false;
24
+ jobTargets = new Map();
24
25
  constructor(client, repository, trustedAuthors, concurrency, makeReconciler) {
25
26
  this.client = client;
26
27
  this.trustedAuthors = trustedAuthors;
@@ -30,6 +31,8 @@ export class RepositoryWorkerPool {
30
31
  }
31
32
  repositories;
32
33
  async reconcileDiscovered(discovered) {
34
+ for (const item of discovered)
35
+ this.jobTargets.set(item.job.id, { repository: item.job.repository, prNumber: item.job.prNumber });
33
36
  // Terminal PRs must be reconciled before OPEN-job scheduling. Otherwise the
34
37
  // OPEN-only runnable filter can strand durable jobs after GitHub merges/closes them.
35
38
  for (const job of terminalManagedJobs(discovered)) {
@@ -71,11 +74,25 @@ export class RepositoryWorkerPool {
71
74
  async reconcileTarget(repository, prNumber, jobId) {
72
75
  if (!this.repositories.includes(repository))
73
76
  return;
77
+ this.jobTargets.set(jobId, { repository, prNumber });
74
78
  const store = new GitHubStore(this.client, repository, prNumber, this.trustedAuthors);
75
79
  await this.makeReconciler(store, Math.max(1, this.concurrency)).reconcile(jobId);
76
80
  }
81
+ async handleTerminalEvent(event) {
82
+ const target = this.jobTargets.get(event.job_id);
83
+ if (!target || !this.repositories.includes(target.repository)) {
84
+ process.stderr.write(`warning: terminal event target unknown for job ${event.job_id}\n`);
85
+ return;
86
+ }
87
+ const store = new GitHubStore(this.client, target.repository, target.prNumber, this.trustedAuthors);
88
+ await this.makeReconciler(store, Math.max(1, this.concurrency)).handleEvent(event);
89
+ }
77
90
  async watch(bus) {
78
91
  return bus.subscribeAll(async (event) => {
92
+ if (['task.completed', 'task.failed', 'task.blocked'].includes(event.type)) {
93
+ await this.handleTerminalEvent(event);
94
+ return;
95
+ }
79
96
  if (event.type === 'job.wake' || event.type === 'github.webhook') {
80
97
  const repository = typeof event.data?.repository === 'string' ? event.data.repository : '';
81
98
  const prNumber = Number(event.data?.prNumber);
@@ -50,18 +50,19 @@ export class Reconciler {
50
50
  this.store = store;
51
51
  this.options = options;
52
52
  }
53
+ async handleEvent(event) {
54
+ if (['task.completed', 'task.failed', 'task.blocked'].includes(event.type)) {
55
+ await this.applyTerminalEvent(event);
56
+ return;
57
+ }
58
+ if (event.type === 'job.wake' || event.type === 'github.webhook')
59
+ await this.reconcile(event.job_id);
60
+ }
53
61
  async watch(jobId) {
54
62
  if (!this.options.eventBus)
55
63
  return async () => { };
56
64
  try {
57
- return await this.options.eventBus.subscribe(jobId, async (event) => {
58
- if (['task.completed', 'task.failed', 'task.blocked'].includes(event.type)) {
59
- await this.applyTerminalEvent(event);
60
- return;
61
- }
62
- if (event.type === 'job.wake' || event.type === 'github.webhook')
63
- await this.reconcile(jobId);
64
- });
65
+ return await this.options.eventBus.subscribe(jobId, event => this.handleEvent(event));
65
66
  }
66
67
  catch (error) {
67
68
  await this.reportTransportFailure(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "type": "module",
6
6
  "bin": {