agl 43.0.4 → 43.1.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.
Files changed (165) hide show
  1. package/changelog.md +25 -0
  2. package/dist_serve/bundle.js +5186 -4683
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_serve/bundle.js.third-party-notices.json +29 -29
  5. package/dist_serve/bundle.js.third-party-notices.txt +29 -29
  6. package/dist_serve/third-party-notices.md +1 -1
  7. package/dist_ts/00_commitinfo_data.js +1 -1
  8. package/dist_ts/aglapi/aglapisurface.document.js +475 -4
  9. package/dist_ts/aglapi/interfaces.d.ts +10 -0
  10. package/dist_ts/aglapi/interfaces.js +3 -1
  11. package/dist_ts/classes.claudeharness.d.ts +14 -5
  12. package/dist_ts/classes.claudeharness.js +62 -2
  13. package/dist_ts/classes.codexclientadapter.d.ts +7 -5
  14. package/dist_ts/classes.codexclientadapter.js +38 -3
  15. package/dist_ts/classes.controller.d.ts +9 -2
  16. package/dist_ts/classes.controller.js +116 -24
  17. package/dist_ts/classes.flexservice.d.ts +6 -7
  18. package/dist_ts/classes.flexservice.js +12 -45
  19. package/dist_ts/classes.flexsupervisor.d.ts +37 -3
  20. package/dist_ts/classes.flexsupervisor.js +164 -37
  21. package/dist_ts/classes.inferencegateway.d.ts +8 -5
  22. package/dist_ts/classes.inferencegateway.js +62 -19
  23. package/dist_ts/classes.inferencespend.d.ts +9 -3
  24. package/dist_ts/classes.inferencespend.js +44 -16
  25. package/dist_ts/classes.mcpclient.d.ts +6 -4
  26. package/dist_ts/classes.mcpclient.js +6 -2
  27. package/dist_ts/classes.mcpcontrollerhost.js +5 -1
  28. package/dist_ts/classes.mcptools.d.ts +1 -1
  29. package/dist_ts/classes.mcptools.js +17 -4
  30. package/dist_ts/classes.opencodeclient.js +3 -1
  31. package/dist_ts/classes.proxycontrol.d.ts +22 -11
  32. package/dist_ts/classes.proxycontrol.js +6 -3
  33. package/dist_ts/classes.proxycontrolclient.d.ts +6 -5
  34. package/dist_ts/classes.proxycontrolclient.js +8 -6
  35. package/dist_ts/classes.proxydaemon.d.ts +8 -6
  36. package/dist_ts/classes.proxydaemon.js +35 -21
  37. package/dist_ts/classes.proxyleaseholder.d.ts +12 -4
  38. package/dist_ts/classes.proxyleaseholder.js +39 -9
  39. package/dist_ts/classes.proxystore.d.ts +4 -3
  40. package/dist_ts/classes.proxystore.js +17 -7
  41. package/dist_ts/classes.sessionfeed.d.ts +1 -1
  42. package/dist_ts/classes.validation.d.ts +7 -0
  43. package/dist_ts/classes.validation.js +49 -2
  44. package/dist_ts/driver/functions.drivertools.js +2 -2
  45. package/dist_ts/fleet/classes.codexworkers.d.ts +4 -11
  46. package/dist_ts/fleet/classes.codexworkers.js +6 -3
  47. package/dist_ts/fleet/classes.workers.d.ts +25 -13
  48. package/dist_ts/fleet/classes.workers.js +105 -9
  49. package/dist_ts/fleet/functions.workervalidation.d.ts +26 -1
  50. package/dist_ts/fleet/functions.workervalidation.js +40 -11
  51. package/dist_ts/fleet/interfaces.workers.d.ts +17 -11
  52. package/dist_ts/fleet/interfaces.workers.js +10 -1
  53. package/dist_ts/flexharness.child.js +9 -4
  54. package/dist_ts/functions.confinedrelay.d.ts +21 -0
  55. package/dist_ts/functions.confinedrelay.js +65 -0
  56. package/dist_ts/functions.deviceapi.d.ts +4 -2
  57. package/dist_ts/functions.deviceapi.js +20 -2
  58. package/dist_ts/functions.elicitation.d.ts +49 -0
  59. package/dist_ts/functions.elicitation.js +418 -0
  60. package/dist_ts/functions.flexchildshutdown.d.ts +7 -0
  61. package/dist_ts/functions.flexchildshutdown.js +18 -1
  62. package/dist_ts/functions.inferencecli.d.ts +3 -3
  63. package/dist_ts/functions.inferencecli.js +33 -10
  64. package/dist_ts/functions.inferencecliarguments.d.ts +2 -1
  65. package/dist_ts/functions.inferencecliarguments.js +29 -8
  66. package/dist_ts/functions.inferencelaunch.d.ts +35 -7
  67. package/dist_ts/functions.inferencelaunch.js +143 -16
  68. package/dist_ts/functions.mcpfleetworkertools.d.ts +63 -70
  69. package/dist_ts/functions.mcpfleetworkertools.js +32 -4
  70. package/dist_ts/functions.proxycontract.d.ts +21 -4
  71. package/dist_ts/functions.proxycontract.js +12 -5
  72. package/dist_ts/functions.proxyharnessconfig.d.ts +7 -0
  73. package/dist_ts/functions.proxyharnessconfig.js +11 -1
  74. package/dist_ts/interfaces.auth.d.ts +1 -1
  75. package/dist_ts/interfaces.auth.js +2 -1
  76. package/dist_ts_interfaces/devices.d.ts +133 -3
  77. package/dist_ts_interfaces/devices.js +3 -2
  78. package/dist_ts_interfaces/elicitations.d.ts +125 -0
  79. package/dist_ts_interfaces/elicitations.js +7 -0
  80. package/dist_ts_interfaces/fleetworkers.d.ts +119 -5
  81. package/dist_ts_interfaces/fleetworkers.js +14 -2
  82. package/dist_ts_interfaces/index.d.ts +1 -0
  83. package/dist_ts_interfaces/index.js +2 -1
  84. package/dist_ts_interfaces/interfaces.d.ts +3 -1
  85. package/dist_ts_interfaces/interfaces.js +2 -2
  86. package/dist_ts_interfaces/mcprequests.d.ts +5 -1
  87. package/dist_ts_interfaces/mcprequests.js +2 -1
  88. package/dist_ts_interfaces/nativesessions.d.ts +14 -0
  89. package/dist_ts_interfaces/requests.d.ts +3 -3
  90. package/dist_ts_interfaces/requests.fleetworkers.js +2 -2
  91. package/dist_ts_interfaces/requests.js +1 -1
  92. package/dist_ts_interfaces/requests.promptreply.d.ts +18 -0
  93. package/dist_ts_interfaces/sessionfeed.d.ts +3 -2
  94. package/dist_ts_interfaces/sessionfeed.js +1 -1
  95. package/dist_ts_migration/index.d.ts +0 -2
  96. package/dist_ts_migration/index.js +1 -3
  97. package/dist_ts_migration/v43_flexpostharnessmigrationmarkers.d.ts +6 -17
  98. package/dist_ts_migration/v43_flexpostharnessmigrationmarkers.js +6 -36
  99. package/package.json +3 -3
  100. package/readme.md +191 -24
  101. package/third-party-notices.md +1 -1
  102. package/ts/00_commitinfo_data.ts +1 -1
  103. package/ts/aglapi/aglapisurface.document.ts +474 -3
  104. package/ts/aglapi/interfaces.ts +2 -0
  105. package/ts/classes.claudeharness.ts +80 -9
  106. package/ts/classes.codexclientadapter.ts +41 -5
  107. package/ts/classes.controller.ts +142 -29
  108. package/ts/classes.flexservice.ts +10 -66
  109. package/ts/classes.flexsupervisor.ts +214 -37
  110. package/ts/classes.inferencegateway.ts +69 -23
  111. package/ts/classes.inferencespend.ts +46 -13
  112. package/ts/classes.mcpclient.ts +8 -4
  113. package/ts/classes.mcpcontrollerhost.ts +4 -0
  114. package/ts/classes.mcptools.ts +17 -3
  115. package/ts/classes.opencodeclient.ts +2 -0
  116. package/ts/classes.proxycontrol.ts +27 -13
  117. package/ts/classes.proxycontrolclient.ts +9 -6
  118. package/ts/classes.proxydaemon.ts +49 -27
  119. package/ts/classes.proxyleaseholder.ts +43 -11
  120. package/ts/classes.proxystore.ts +21 -8
  121. package/ts/classes.sessionfeed.ts +1 -1
  122. package/ts/classes.validation.ts +52 -0
  123. package/ts/driver/functions.drivertools.ts +1 -1
  124. package/ts/fleet/classes.codexworkers.ts +8 -6
  125. package/ts/fleet/classes.workers.ts +101 -17
  126. package/ts/fleet/functions.workervalidation.ts +35 -9
  127. package/ts/fleet/interfaces.workers.ts +11 -4
  128. package/ts/flexharness.child.ts +8 -3
  129. package/ts/functions.confinedrelay.ts +65 -0
  130. package/ts/functions.deviceapi.ts +24 -1
  131. package/ts/functions.elicitation.ts +443 -0
  132. package/ts/functions.flexchildshutdown.ts +22 -0
  133. package/ts/functions.inferencecli.ts +38 -13
  134. package/ts/functions.inferencecliarguments.ts +26 -5
  135. package/ts/functions.inferencelaunch.ts +143 -16
  136. package/ts/functions.mcpfleetworkertools.ts +34 -4
  137. package/ts/functions.proxycontract.ts +17 -4
  138. package/ts/functions.proxyharnessconfig.ts +11 -0
  139. package/ts/interfaces.auth.ts +1 -0
  140. package/ts_interfaces/devices.schema.json +476 -2
  141. package/ts_interfaces/devices.ts +146 -2
  142. package/ts_interfaces/elicitations.ts +148 -0
  143. package/ts_interfaces/fleetworkers.ts +96 -4
  144. package/ts_interfaces/index.ts +1 -0
  145. package/ts_interfaces/interfaces.ts +3 -1
  146. package/ts_interfaces/mcprequests.ts +1 -0
  147. package/ts_interfaces/nativesessions.ts +16 -0
  148. package/ts_interfaces/requests.fleetworkers.ts +1 -1
  149. package/ts_interfaces/requests.promptreply.ts +22 -0
  150. package/ts_interfaces/requests.ts +4 -0
  151. package/ts_interfaces/sessionfeed.ts +3 -2
  152. package/ts_migration/index.ts +0 -2
  153. package/ts_migration/v43_flexpostharnessmigrationmarkers.ts +6 -49
  154. package/ts_web/00_commitinfo_data.ts +1 -1
  155. package/ts_web/classes.elicitationcards.ts +106 -0
  156. package/ts_web/classes.nativesessionstate.ts +38 -1
  157. package/ts_web/elements.fleetworker.ts +27 -2
  158. package/ts_web/elements.harnesscontrollerapp.ts +68 -1
  159. package/ts_web/functions.sessionchat.ts +5 -0
  160. package/dist_ts_migration/classes.flexpostharnessmigrationrunner.d.ts +0 -19
  161. package/dist_ts_migration/classes.flexpostharnessmigrationrunner.js +0 -34
  162. package/dist_ts_migration/v19_flexprojectmanagement.d.ts +0 -14
  163. package/dist_ts_migration/v19_flexprojectmanagement.js +0 -23
  164. package/ts_migration/classes.flexpostharnessmigrationrunner.ts +0 -54
  165. package/ts_migration/v19_flexprojectmanagement.ts +0 -32
@@ -5,8 +5,8 @@ import { InferenceService } from './classes.inferenceservice.js';
5
5
  import { inferenceGatewayCredentialDigest, type IInferenceGatewayGrant, type IInferenceGatewayLease,
6
6
  type IInferenceGatewayLimits, type TInferenceGatewayRoute } from './classes.inferencegateway.js';
7
7
  import { InferenceRoutingError, type IInferenceRoutingPolicy } from './classes.inferencerouter.js';
8
- import { aglProxyConfinedClient, aglProxyConfinedOrigin, proxyClientNamePattern, type TInferenceProvider,
9
- type TProxyCredentialDelivery } from './functions.proxycontract.js';
8
+ import { aglProxyConfinedClient, aglProxyConfinedCodexClient, aglProxyConfinedOrigin, proxyClientNamePattern,
9
+ type TAglProxyConfinedHarness, type TInferenceProvider, type TProxyCredentialDelivery } from './functions.proxycontract.js';
10
10
  import { AglProxyControlRefusal, AglProxyControlServer, type IAglProxyConfinedGrant, type IAglProxyConnection,
11
11
  type IAglProxyStatus, type IReq_AglProxyCatalog, type IReq_AglProxyConfined, type IReq_AglProxyReclaim,
12
12
  type TAglProxyLeaseCatalog } from './classes.proxycontrol.js';
@@ -63,13 +63,25 @@ const confinedPolicies: Readonly<Record<TInferenceProvider, IInferenceRoutingPol
63
63
  openai: Object.freeze({ provider: 'openai' }),
64
64
  });
65
65
 
66
+ /**
67
+ * The policy of a Codex run's credential (AGL-1614): the ChatGPT pool's ChatGPT accounts alone, unrestricted. Codex's
68
+ * Responses requests and its catalog never reach an OpenAI API key, which no ChatGPT sign-in's terms cover.
69
+ */
70
+ const confinedCodexPolicy: Readonly<IInferenceRoutingPolicy> = Object.freeze({ provider: 'openai', credential: 'subscription' });
71
+
72
+ /** A kept confined run's harness, by the client its sessions are (see `IProxyLeaseDocument.route`). */
73
+ const confinedHarnessOf = (clientArg: string): TAglProxyConfinedHarness =>
74
+ clientArg === aglProxyConfinedCodexClient ? 'codex' : 'claude';
75
+
66
76
  /** A confined run's id, as the operator names it: the first 12 hex characters of its credential's digest. */
67
77
  const confinedRunId = (digestArg: string): string => digestArg.slice(0, 12);
68
78
 
69
- /** A lease the proxy serves: held by the control connection it was issued or reclaimed on, or awaiting its holder. */
70
- interface IHeldLease {
79
+ /**
80
+ * What every lease the proxy serves holds: held by the control connection it was issued or reclaimed on, or awaiting its
81
+ * holder.
82
+ */
83
+ interface IHeldLeaseBase {
71
84
  grant: IInferenceGatewayGrant;
72
- route: TInferenceGatewayRoute;
73
85
  /** The pool the lease is served from; a policy that names none is the ChatGPT pool's, as the router reads it. */
74
86
  provider: TInferenceProvider;
75
87
  createdAt: Date;
@@ -79,6 +91,9 @@ interface IHeldLease {
79
91
  reclaimTimer?: ReturnType<typeof setTimeout>;
80
92
  }
81
93
 
94
+ /** A lease the proxy serves: one of the loopback listener, or a confined run's credential with the harness it serves. */
95
+ type THeldLease = IHeldLeaseBase & ({ route: 'loopback' } | { route: 'confined'; harness: TAglProxyConfinedHarness });
96
+
82
97
  interface IClientLease {
83
98
  lease: IInferenceGatewayLease;
84
99
  generation: number;
@@ -88,7 +103,7 @@ interface IClientLease {
88
103
  }
89
104
 
90
105
  /**
91
- * The permanent proxy: one loopback listener, one credential per client, a confined listener for Claude Code in
106
+ * The permanent proxy: one loopback listener, one credential per client, a confined listener for Claude Code and Codex in
92
107
  * containers, and a private control socket that hands a client its credential, a child a lease and a confined run its
93
108
  * credential. The control socket is claimed first; it is the proof that no other proxy runs for this AGL home, so the
94
109
  * proxy's database is opened by this process alone.
@@ -97,7 +112,7 @@ export class AglProxyDaemon {
97
112
  private readonly control: AglProxyControlServer;
98
113
  private readonly clients = new Map<string, IClientLease>();
99
114
  /** The leases served, by their credential's digest. */
100
- private readonly leases = new Map<string, IHeldLease>();
115
+ private readonly leases = new Map<string, THeldLease>();
101
116
  /** Store writes for leases in flight; a stop waits for them before it closes the store. */
102
117
  private readonly leaseWrites = new Set<Promise<void>>();
103
118
  /** The clients whose credential the proxy keeps in a file. */
@@ -177,10 +192,11 @@ export class AglProxyDaemon {
177
192
  leases: status.leases, inFlight: status.inFlight, limits: status.limits, authority: status.authority,
178
193
  accounts: status.accounts, usageObservations: status.usageObservations, nextPlacement: status.nextPlacement,
179
194
  recentPlacements: status.recentPlacements, confinedSocketPath: this.options.confinedSocketPath ?? null,
180
- confinedRuns: [...this.leases].filter(([, heldArg]) => heldArg.route === 'confined')
181
- .sort(([, left], [, right]) => left.createdAt.getTime() - right.createdAt.getTime())
182
- .map(([digestArg, heldArg]) => ({ id: confinedRunId(digestArg), provider: heldArg.provider,
183
- createdAt: heldArg.createdAt.toISOString(), held: heldArg.reclaimTimer === undefined })),
195
+ confinedRuns: [...this.leases]
196
+ .flatMap(([digestArg, heldArg]) => heldArg.route === 'confined' ? [{ digest: digestArg, held: heldArg }] : [])
197
+ .sort((left, right) => left.held.createdAt.getTime() - right.held.createdAt.getTime())
198
+ .map(({ digest, held }) => ({ id: confinedRunId(digest), provider: held.provider, harness: held.harness,
199
+ createdAt: held.createdAt.toISOString(), held: held.reclaimTimer === undefined })),
184
200
  };
185
201
  }
186
202
 
@@ -300,7 +316,7 @@ export class AglProxyDaemon {
300
316
  // The lease continues the sessions of the client it is taken for (see `IReq_AglProxyLease`).
301
317
  try { lease = await service.open(policyArg, { sessionScope: clientArg }); }
302
318
  catch (errorArg) { throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The lease could not be opened.'); }
303
- const held: IHeldLease = { grant: lease, route: 'loopback', provider: policyArg.provider ?? 'openai', createdAt: new Date(),
319
+ const held: THeldLease = { grant: lease, route: 'loopback', provider: policyArg.provider ?? 'openai', createdAt: new Date(),
304
320
  holder: connectionArg };
305
321
  this.leases.set(lease.digest, held);
306
322
  try {
@@ -331,38 +347,42 @@ export class AglProxyDaemon {
331
347
  * proves the caller holds the credential the lease was issued with.
332
348
  */
333
349
  /**
334
- * A confined run's credential (see `IReq_AglProxyConfined`): a lease of the pool the request names -- the Claude pool
335
- * when it names none -- that continues the confined client's sessions on that pool and is accepted on the confined
336
- * listener alone. It is kept, as its digest, before it is handed out, and ends when its holder's connection closes or
337
- * the operator ends it (`confinedEnd`). A Claude-pool run gets no model list: Claude Code reads the pool's models
338
- * through the confined listener, and the pool is judged at each request. A ChatGPT-pool run gets the pool's models, as
350
+ * A confined run's credential (see `IReq_AglProxyConfined`). A Claude Code run's is a lease of the pool the request
351
+ * names -- the Claude pool when it names none -- that continues the confined client's sessions on that pool; a Codex
352
+ * run's is a lease of the ChatGPT pool's ChatGPT accounts alone (`confinedCodexPolicy`) that continues the confined Codex
353
+ * client's sessions. Either is accepted on the confined listener alone, kept, as its digest, before it is handed out, and
354
+ * ends when its holder's connection closes or the operator ends it (`confinedEnd`). A Claude-pool run gets no model list:
355
+ * Claude Code reads the pool's models through the confined listener, and the pool is judged at each request; nor does a
356
+ * Codex run, whose Codex reads the pool's Codex catalog there. A ChatGPT-pool Claude Code run gets the pool's models, as
339
357
  * an `agl proxy run` lease does, for its launcher to configure Claude Code with.
340
358
  */
341
359
  private async confined(requestArg: IReq_AglProxyConfined['request'],
342
360
  connectionArg: IAglProxyConnection): Promise<IAglProxyConfinedGrant> {
343
361
  const socketPath = this.options.confinedSocketPath;
344
362
  if (socketPath === undefined) throw new AglProxyControlRefusal('This AGL proxy has no confined listener.');
345
- const provider = requestArg.provider ?? 'anthropic';
346
- const policy = confinedPolicies[provider];
363
+ const harness: TAglProxyConfinedHarness = requestArg.harness ?? 'claude';
364
+ const provider = harness === 'codex' ? 'openai' : requestArg.provider ?? 'anthropic';
365
+ const policy = harness === 'codex' ? confinedCodexPolicy : confinedPolicies[provider];
366
+ const client = harness === 'codex' ? aglProxyConfinedCodexClient : aglProxyConfinedClient;
347
367
  const service = this.service!;
348
368
  let lease: IInferenceGatewayLease;
349
- try { lease = await service.open(policy, { sessionScope: aglProxyConfinedClient, route: 'confined' }); }
369
+ try { lease = await service.open(policy, { sessionScope: client, route: 'confined' }); }
350
370
  catch (errorArg) {
351
371
  throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The confined credential could not be issued.');
352
372
  }
353
- const held: IHeldLease = { grant: lease, route: 'confined', provider, createdAt: new Date(), holder: connectionArg };
373
+ const held: THeldLease = { grant: lease, route: 'confined', provider, harness, createdAt: new Date(), holder: connectionArg };
354
374
  this.leases.set(lease.digest, held);
355
375
  try {
356
- await this.trackLeaseWrite(this.store!.recordLease({ digest: lease.digest, client: aglProxyConfinedClient,
357
- policy, createdAt: held.createdAt, route: 'confined' }));
376
+ await this.trackLeaseWrite(this.store!.recordLease({ digest: lease.digest, client, policy, createdAt: held.createdAt,
377
+ route: 'confined' }));
358
378
  } catch (errorArg) {
359
379
  this.endLease(lease.digest, held);
360
380
  throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The confined credential could not be recorded.');
361
381
  }
362
382
  connectionArg.onClose(() => this.endLease(lease.digest, held));
363
- const grant: IAglProxyConfinedGrant = { id: confinedRunId(lease.digest), provider, token: lease.token, socketPath,
383
+ const grant: IAglProxyConfinedGrant = { id: confinedRunId(lease.digest), provider, harness, token: lease.token, socketPath,
364
384
  baseUrl: aglProxyConfinedOrigin };
365
- if (provider === 'anthropic') return grant;
385
+ if (provider === 'anthropic' || harness === 'codex') return grant;
366
386
  try {
367
387
  // A launcher that goes away stops the model list read it asked for.
368
388
  return { ...grant, models: await service.router.models(policy, AbortSignal.any([connectionArg.signal, AbortSignal.timeout(60_000)])) };
@@ -441,7 +461,9 @@ export class AglProxyDaemon {
441
461
  await this.forgetLease(kept.digest);
442
462
  continue;
443
463
  }
444
- const held: IHeldLease = { grant, route: kept.route, provider: kept.policy.provider ?? 'openai', createdAt: kept.createdAt };
464
+ const base: IHeldLeaseBase = { grant, provider: kept.policy.provider ?? 'openai', createdAt: kept.createdAt };
465
+ const held: THeldLease = kept.route === 'confined' ? { ...base, route: 'confined', harness: confinedHarnessOf(kept.client) }
466
+ : { ...base, route: 'loopback' };
445
467
  held.reclaimTimer = setTimeout(() => this.endLease(kept.digest, held), Math.max(0, deadline - Date.now()));
446
468
  this.leases.set(kept.digest, held);
447
469
  }
@@ -451,7 +473,7 @@ export class AglProxyDaemon {
451
473
  * Ends a lease: its credential stops working and the store forgets it. A stopping proxy ends none -- its holders'
452
474
  * connections close because it stops -- so the next start serves them again.
453
475
  */
454
- private endLease(digestArg: string, heldArg: IHeldLease): void {
476
+ private endLease(digestArg: string, heldArg: THeldLease): void {
455
477
  if (this.abort.signal.aborted || this.leases.get(digestArg) !== heldArg) return;
456
478
  clearTimeout(heldArg.reclaimTimer);
457
479
  heldArg.holder = undefined;
@@ -1,7 +1,7 @@
1
1
  import * as plugins from './plugins.js';
2
2
  import type { IInferenceRoutingPolicy, TInferenceModel } from './classes.inferencerouter.js';
3
3
  import type { IAglProxyConfinedGrant, IReq_AglProxyReclaim, TAglProxyLeaseCatalog } from './classes.proxycontrol.js';
4
- import type { TInferenceProvider } from './functions.proxycontract.js';
4
+ import type { TAglProxyConfinedHarness, TAglProxyConfinedRun, TInferenceProvider } from './functions.proxycontract.js';
5
5
  import { AglProxyControlClient, AglProxyRefusedError, type IAglProxyLeaseConnection } from './classes.proxycontrolclient.js';
6
6
 
7
7
  /** The delays between attempts to take a lease back from a restarting proxy; the last one repeats. */
@@ -161,16 +161,27 @@ export class AglProxyLeaseHolder extends AglProxyHeldCredential {
161
161
  }
162
162
 
163
163
  export interface IAglProxyConfinedHolderOptions extends IAglProxyHolderOptions {
164
- /** The run's pool: Claude accounts (`anthropic`) or, translated, the ChatGPT accounts (`openai`). */
165
- provider: TInferenceProvider;
164
+ /**
165
+ * The run's harness and pool: Claude Code on Claude accounts (`anthropic`) or, translated, on the ChatGPT accounts
166
+ * (`openai`), or Codex on the ChatGPT accounts.
167
+ */
168
+ run: TAglProxyConfinedRun;
166
169
  }
167
170
 
168
171
  /**
169
- * Why a confined grant does not serve the pool it was asked for, or `undefined` when it does: a proxy older than
170
- * ChatGPT-pool runs names no pool and issues Claude-pool runs alone, and a ChatGPT-pool run comes with the pool's models.
172
+ * Why a confined grant does not serve the harness and pool it was asked for, or `undefined` when it does: a proxy older
173
+ * than ChatGPT-pool runs names no pool and issues Claude-pool runs alone, a proxy older than Codex runs names no harness
174
+ * and issues Claude Code runs alone, and a ChatGPT-pool Claude Code run comes with the pool's models.
171
175
  */
172
- const confinedGrantMismatch = (providerArg: TInferenceProvider, grantArg: IAglProxyConfinedGrant): string | undefined => {
173
- if (providerArg === 'anthropic') {
176
+ const confinedGrantMismatch = (runArg: TAglProxyConfinedRun, grantArg: IAglProxyConfinedGrant): string | undefined => {
177
+ if (runArg.harness === 'codex') {
178
+ return grantArg.harness === 'codex' && grantArg.provider === 'openai' ? undefined
179
+ : 'The AGL proxy issued no Codex confined run on the ChatGPT pool; it may run an AGL older than Codex confined runs.';
180
+ }
181
+ if (grantArg.harness !== undefined && grantArg.harness !== 'claude') {
182
+ return 'The AGL proxy issued a confined run of another harness than the Claude Code run asked for.';
183
+ }
184
+ if (runArg.provider === 'anthropic') {
174
185
  return grantArg.provider === undefined || grantArg.provider === 'anthropic' ? undefined
175
186
  : 'The AGL proxy issued a confined run of another pool than the Claude pool asked for.';
176
187
  }
@@ -178,6 +189,12 @@ const confinedGrantMismatch = (providerArg: TInferenceProvider, grantArg: IAglPr
178
189
  : 'The AGL proxy issued no ChatGPT-pool confined run with the pool\'s models; it may run an AGL older than ChatGPT-pool runs.';
179
190
  };
180
191
 
192
+ /**
193
+ * The refusal a proxy older than Codex runs answers a Codex run's request with: it takes no `harness`, so it refuses the
194
+ * request as invalid, as it refuses every unknown key.
195
+ */
196
+ const olderProxyRefusal = 'Invalid proxy confined request.';
197
+
181
198
  /**
182
199
  * A confined run's credential (see `IReq_AglProxyConfined`), held for as long as its container runs. It is configured
183
200
  * with the confined listener's socket, so one taken back on another socket cannot continue.
@@ -186,8 +203,17 @@ export class AglProxyConfinedHolder extends AglProxyHeldCredential {
186
203
  /** Takes a new confined run's credential of the proxy on `optionsArg.socketPath`, its control socket. */
187
204
  public static async take(optionsArg: IAglProxyConfinedHolderOptions, signalArg: AbortSignal): Promise<AglProxyConfinedHolder> {
188
205
  const control = new AglProxyControlClient(optionsArg.socketPath);
189
- const grant = await control.confined(optionsArg.provider, signalArg);
190
- const mismatch = confinedGrantMismatch(optionsArg.provider, grant);
206
+ let grant: Awaited<ReturnType<AglProxyControlClient['confined']>>;
207
+ try { grant = await control.confined(optionsArg.run, signalArg); }
208
+ catch (errorArg) {
209
+ if (optionsArg.run.harness === 'codex' && errorArg instanceof AglProxyRefusedError && errorArg.message === olderProxyRefusal) {
210
+ throw new Error('The AGL proxy refused a Codex confined run: it runs an AGL older than Codex confined runs, which refuses '
211
+ + 'the request\'s `harness`. `agl proxy status` names the release it runs; restart it onto the installed AGL with '
212
+ + '`agl proxy service stop`, then `agl proxy service start`.', { cause: errorArg });
213
+ }
214
+ throw errorArg;
215
+ }
216
+ const mismatch = confinedGrantMismatch(optionsArg.run, grant);
191
217
  if (mismatch !== undefined) {
192
218
  grant.close();
193
219
  throw new Error(mismatch);
@@ -199,7 +225,12 @@ export class AglProxyConfinedHolder extends AglProxyHeldCredential {
199
225
  public readonly id: string;
200
226
  /** The run's pool. */
201
227
  public readonly provider: TInferenceProvider;
202
- /** A ChatGPT-pool run's models as the proxy read them when it issued the credential; empty for a Claude-pool run. */
228
+ /** The run's harness. */
229
+ public readonly harness: TAglProxyConfinedHarness;
230
+ /**
231
+ * A ChatGPT-pool Claude Code run's models as the proxy read them when it issued the credential; empty for a Claude-pool
232
+ * run and for a Codex run.
233
+ */
203
234
  public readonly models: readonly TInferenceModel[];
204
235
  /** The confined listener's socket, on the host. */
205
236
  public readonly confinedSocketPath: string;
@@ -208,7 +239,8 @@ export class AglProxyConfinedHolder extends AglProxyHeldCredential {
208
239
  optionsArg: IAglProxyConfinedHolderOptions) {
209
240
  super(controlArg, grantArg, optionsArg);
210
241
  this.id = grantArg.id;
211
- this.provider = optionsArg.provider;
242
+ this.provider = optionsArg.run.provider;
243
+ this.harness = optionsArg.run.harness;
212
244
  this.models = grantArg.models ?? [];
213
245
  this.confinedSocketPath = grantArg.socketPath;
214
246
  }
@@ -10,6 +10,7 @@ import { assertInferenceRoutingPolicy, type TInferenceGatewayRoute } from './cla
10
10
  import type { IInferenceRoutingPolicy } from './classes.inferencerouter.js';
11
11
  import {
12
12
  aglProxyConfinedClient,
13
+ aglProxyConfinedCodexClient,
13
14
  defaultProxyClientProvider,
14
15
  defaultProxyClients,
15
16
  inferenceProviders,
@@ -130,9 +131,10 @@ export interface IProxyLeaseDocument {
130
131
  */
131
132
  orphanedAt?: Date;
132
133
  /**
133
- * `confined` for a confined run's credential, accepted on the confined listener alone, with the policy of its pool,
134
- * the Claude pool's or the ChatGPT pool's, unrestricted, and the confined client's sessions on that pool; absent for a
135
- * lease of the loopback listener.
134
+ * `confined` for a confined run's credential, accepted on the confined listener alone: a Claude Code run's, with the
135
+ * policy of its pool, the Claude pool's or the ChatGPT pool's, unrestricted, and the confined client's sessions on that
136
+ * pool, or a Codex run's, with the ChatGPT pool's ChatGPT accounts alone and the confined Codex client's sessions; absent
137
+ * for a lease of the loopback listener.
136
138
  */
137
139
  route?: 'confined';
138
140
  }
@@ -154,9 +156,21 @@ const assertLeasePolicy = (valueArg: unknown): IProxyLeasePolicyDocument => {
154
156
  return value;
155
157
  };
156
158
 
157
- /** A confined run's policy, as kept: one pool, unrestricted (see `IProxyLeaseDocument.route`). */
158
- const confinedLeasePolicies: ReadonlySet<string> = new Set([JSON.stringify({ provider: 'anthropic' }),
159
- JSON.stringify({ provider: 'openai' })]);
159
+ /**
160
+ * A confined run's client and policy, as kept (see `IProxyLeaseDocument.route`): a Claude Code run's, the confined client
161
+ * on one pool, unrestricted, or a Codex run's, the confined Codex client on the ChatGPT pool's ChatGPT accounts alone.
162
+ */
163
+ const confinedLeasePairs: ReadonlyArray<{ client: string; policy: Readonly<Record<string, string>> }> = [
164
+ { client: aglProxyConfinedClient, policy: { provider: 'anthropic' } },
165
+ { client: aglProxyConfinedClient, policy: { provider: 'openai' } },
166
+ { client: aglProxyConfinedCodexClient, policy: { provider: 'openai', credential: 'subscription' } },
167
+ ];
168
+
169
+ /** Whether a kept lease's client and policy are exactly one of `confinedLeasePairs`, whatever order the policy's keys have. */
170
+ const isConfinedLeasePair = (clientArg: unknown, policyArg: unknown): boolean => !!policyArg && typeof policyArg === 'object'
171
+ && !Array.isArray(policyArg) && confinedLeasePairs.some((pairArg) => pairArg.client === clientArg
172
+ && Object.keys(policyArg).length === Object.keys(pairArg.policy).length
173
+ && Object.entries(pairArg.policy).every(([keyArg, valueArg]) => (policyArg as Record<string, unknown>)[keyArg] === valueArg));
160
174
 
161
175
  const assertLease: (valueArg: unknown) => asserts valueArg is IProxyLeaseDocument = (valueArg) => {
162
176
  const value = valueArg as Partial<IProxyLeaseDocument> | null;
@@ -165,8 +179,7 @@ const assertLease: (valueArg: unknown) => asserts valueArg is IProxyLeaseDocumen
165
179
  || typeof value.id !== 'string' || !/^[a-f0-9]{64}$/.test(value.id)
166
180
  || typeof value.client !== 'string' || !proxyClientNamePattern.test(value.client)
167
181
  || !isDate(value.createdAt) || (Object.hasOwn(value, 'orphanedAt') && !isDate(value.orphanedAt))
168
- || (Object.hasOwn(value, 'route') && (value.route !== 'confined' || value.client !== aglProxyConfinedClient
169
- || !confinedLeasePolicies.has(JSON.stringify(value.policy))))) {
182
+ || (Object.hasOwn(value, 'route') && (value.route !== 'confined' || !isConfinedLeasePair(value.client, value.policy)))) {
170
183
  throw new Error('Invalid proxy lease.');
171
184
  }
172
185
  assertLeasePolicy(value.policy);
@@ -119,7 +119,7 @@ const harnessLabels: Record<TControllerSessionFeedHarness, string> = { claude: '
119
119
 
120
120
  /** What one source tells of a session, for `sessionFeedState` to group. */
121
121
  export interface ISessionFeedFacts {
122
- /** AGL holds a question or permission for the session that the owner answers in AGL. */
122
+ /** AGL holds a question, permission or MCP elicitation for the session that the owner answers in AGL (`attention`). */
123
123
  request?: boolean;
124
124
  /** The harness signals a wait in its own client. */
125
125
  nativeWait?: IControllerNativeWait;
@@ -10,6 +10,8 @@ import {
10
10
  controllerRuntimeIdKey,
11
11
  controllerLayoutItemRefKey,
12
12
  controllerSessionHarnessIds,
13
+ controllerElicitationMaxContentBytes,
14
+ controllerElicitationMaxFields,
13
15
  controllerSessionLayoutGroupLimit,
14
16
  controllerSessionLayoutUngroupedLimit,
15
17
  controllerStandardProjectDirectoryLimit,
@@ -1780,6 +1782,15 @@ export const assertNativeSessionQuestionReplyRequest = (
1780
1782
  return { session, requestId: assertNativeSessionRequestId(value.requestId, session), answers: assertQuestionAnswers(value.answers) };
1781
1783
  };
1782
1784
 
1785
+ export const assertNativeSessionElicitationReplyRequest = (
1786
+ valueArg: unknown,
1787
+ ): interfaces.IReq_ControllerNativeSessionElicitationReply['request'] => {
1788
+ const value = assertObject(valueArg, 'native session elicitation reply request');
1789
+ assertKeys(value, ['session', 'requestId', 'reply']);
1790
+ const session = assertNativeSessionRef(value.session);
1791
+ return { session, requestId: assertNativeSessionRequestId(value.requestId, session), reply: assertElicitationReply(value.reply) };
1792
+ };
1793
+
1783
1794
  export const assertSingleLineText = (valueArg: unknown, nameArg: string, maximumArg: number): string => {
1784
1795
  const text = assertString(valueArg, nameArg, 1, maximumArg);
1785
1796
  // eslint-disable-next-line no-control-regex
@@ -2708,3 +2719,44 @@ export const assertQuestionReplyRequest = (
2708
2719
  assertRelatedRuntimeIds(sessionId, requestId, 'requestId');
2709
2720
  return { projectId, sessionId, requestId, answers: assertQuestionAnswers(value.answers) };
2710
2721
  };
2722
+
2723
+ /**
2724
+ * The shape of an elicitation reply: an action, and for `accept` at most a flat object of field values. Whether the
2725
+ * values fit the request's form is checked against the pending request itself. No refusal repeats a value.
2726
+ */
2727
+ export const assertElicitationReply = (valueArg: unknown): interfaces.TControllerElicitationReply => {
2728
+ const value = assertObject(valueArg, 'reply');
2729
+ if (value.action === 'decline' || value.action === 'cancel') {
2730
+ assertKeys(value, ['action']);
2731
+ return { action: value.action };
2732
+ }
2733
+ if (value.action !== 'accept') throw new Error('reply.action must be accept, decline or cancel.');
2734
+ assertKeys(value, ['action'], ['content']);
2735
+ if (value.content === undefined) return { action: 'accept' };
2736
+ if (!isPlainObject(value.content)) throw new Error('reply.content must be an object of field values.');
2737
+ const entries = Object.entries(value.content);
2738
+ if (entries.length > controllerElicitationMaxFields) throw new Error('reply.content names more fields than a form has.');
2739
+ if (Buffer.byteLength(JSON.stringify(value.content), 'utf8') > controllerElicitationMaxContentBytes) {
2740
+ throw new Error('reply.content is larger than AGL sends.');
2741
+ }
2742
+ const isValue = (entryArg: unknown): boolean => typeof entryArg === 'string' || typeof entryArg === 'boolean'
2743
+ || (typeof entryArg === 'number' && Number.isFinite(entryArg))
2744
+ || (Array.isArray(entryArg) && entryArg.every((itemArg) => typeof itemArg === 'string'));
2745
+ if (entries.some(([, entryArg]) => !isValue(entryArg))) {
2746
+ throw new Error('reply.content values must be text, numbers, yes or no, or lists of text.');
2747
+ }
2748
+ return { action: 'accept', content: Object.fromEntries(entries) as interfaces.TControllerElicitationContent };
2749
+ };
2750
+
2751
+ export const assertElicitationReplyRequest = (
2752
+ valueArg: unknown,
2753
+ ): interfaces.IReq_ControllerElicitationReply['request'] => {
2754
+ const value = assertObject(valueArg, 'elicitation reply request');
2755
+ assertKeys(value, ['projectId', 'sessionId', 'requestId', 'reply']);
2756
+ const projectId = assertProjectId(value.projectId, 'projectId');
2757
+ // Claude Code and Codex are the harnesses that hand MCP elicitations to AGL.
2758
+ const sessionId = assertControllerRuntimeId(value.sessionId, 'sessionId', ['codex', 'claude']);
2759
+ const requestId = assertControllerRuntimeId(value.requestId, 'requestId', ['codex', 'claude']);
2760
+ assertRelatedRuntimeIds(sessionId, requestId, 'requestId');
2761
+ return { projectId, sessionId, requestId, reply: assertElicitationReply(value.reply) };
2762
+ };
@@ -31,7 +31,7 @@ export interface IDriverToolDefinition {
31
31
  * Observing a job or the event stream polls state that changes outside the turn, so a repeated call
32
32
  * must run again instead of returning the turn's earlier answer.
33
33
  */
34
- const pollingToolNames: ReadonlySet<string> = new Set(['fleet_status', 'fleet_worker_status', 'fleet_watch', 'deploy_status', 'deploy_history', 'release_status']);
34
+ const pollingToolNames: ReadonlySet<string> = new Set(['fleet_status', 'fleet_worker_status', 'fleet_worker_job_wait', 'fleet_watch', 'deploy_status', 'deploy_history', 'release_status']);
35
35
 
36
36
  /** A direct report's conversation is read in bundles, the newest first in reverse. */
37
37
  export const driverDirectReportReadDefaultLimit = 10;
@@ -5,9 +5,10 @@ import { codexRecord, codexArray, codexString, codexSession, codexTimestamp, cod
5
5
  import { isCodexThreadId } from '../functions.codexidentity.js';
6
6
  import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerTurnOutcome } from '../../ts_interfaces/fleetworkers.js';
7
7
  import { controllerSessionFeedExcerpt } from '../../ts_interfaces/sessionfeed.js';
8
- import type { IControllerMessageBundle, IControllerPermission, IControllerQuestion, TControllerPermissionReply } from '../../ts_interfaces/index.js';
8
+ import type { IControllerAttention, IControllerMessageBundle } from '../../ts_interfaces/index.js';
9
+ import { controllerAttentionPending } from '../../ts_interfaces/index.js';
9
10
  import type { FleetWorkerLaunches, IFleetCodexCallerRuntime } from './classes.workerlaunches.js';
10
- import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt } from './interfaces.workers.js';
11
+ import { FleetDispatchError, FleetNativeTurnError, fleetReportMarker, boundedFleetReport, type IFleetWorkerBackend, type IFleetWorkerObservedTurn, type IFleetNativeEvent, type IFleetNativeThread, type IFleetNativeSession, type IFleetNativePage, type IFleetNativeSendTurn, type IFleetNativeSendReceipt, type TFleetNativeReply } from './interfaces.workers.js';
11
12
 
12
13
  /** `turns` and `items` are the poll baseline; `turn` stays when the baseline is forgotten, so a failure stays observed. */
13
14
  interface ICodexObservation { turns?: Set<string>; items?: Map<string, string>; status?: IFleetWorkerReport['status']; excerpt?: string; turn?: IFleetWorkerObservedTurn }
@@ -140,7 +141,7 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
140
141
  const message = items.find((entry) => codexRecord(entry.item).type === 'agentMessage');
141
142
  const item = message ? codexRecord(message.item) : undefined;
142
143
  const attention = adapter.attention(worker.nativeId!), outcome = (latest ? codexObservedTurn(latest) : this.observations.get(worker.nativeId!)?.turn)?.outcome;
143
- return { worker, status: worker.state === 'archived' ? 'archived' : latest?.status === 'inProgress' ? attention.permissions.length || attention.questions.length ? 'blocked' : 'busy' : 'idle',
144
+ return { worker, status: worker.state === 'archived' ? 'archived' : latest?.status === 'inProgress' ? controllerAttentionPending(attention) ? 'blocked' : 'busy' : 'idle',
144
145
  ...boundedFleetReport(typeof item?.text === 'string' ? item.text : ''), ...(item ? { reportId: codexString(item.id) } : {}),
145
146
  ...(latest ? { turnId: codexString(latest.id), turnStatus: codexString(latest.status) } : {}), ...(outcome ? { outcome } : {}) };
146
147
  }
@@ -148,7 +149,7 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
148
149
  const adapter = await this.scoped(worker), id = worker.nativeId!, previous = this.observations.get(id);
149
150
  const turns = await this.turns(adapter, id, previous?.turns), items = await this.items(adapter, id, previous?.items);
150
151
  const terminal = turns.filter((turn) => turn.status !== 'inProgress'), attention = adapter.attention(id);
151
- const status = turns[0]?.status === 'inProgress' ? attention.permissions.length || attention.questions.length ? 'blocked' : 'busy' : 'idle';
152
+ const status = turns[0]?.status === 'inProgress' ? controllerAttentionPending(attention) ? 'blocked' : 'busy' : 'idle';
152
153
  const message = items.map((entry) => codexRecord(entry.item)).find((item) => item.type === 'agentMessage' && typeof item.text === 'string' && item.text.trim());
153
154
  const excerpt = controllerSessionFeedExcerpt(message?.text as string | undefined) ?? previous?.excerpt;
154
155
  // The newest listed turn replaces the observed one; a thread listing none leaves it.
@@ -253,12 +254,13 @@ export class FleetCodexWorkers implements IFleetWorkerBackend {
253
254
  return latest?.status === 'inProgress' ? codexString(latest.id) : undefined;
254
255
  }
255
256
  /** The requests of turns this connection runs in the thread that wait for an answer. */
256
- public async nativeAttention(session: IFleetNativeSession): Promise<{ permissions: IControllerPermission[]; questions: IControllerQuestion[] }> {
257
+ public async nativeAttention(session: IFleetNativeSession): Promise<IControllerAttention> {
257
258
  return (await this.scoped(session)).attention(session.nativeId);
258
259
  }
259
- public async nativeReply(session: IFleetNativeSession, requestId: string, reply: { permission: TControllerPermissionReply } | { answers: string[][] | null }): Promise<void> {
260
+ public async nativeReply(session: IFleetNativeSession, requestId: string, reply: TFleetNativeReply): Promise<void> {
260
261
  const adapter = await this.scoped(session);
261
262
  if ('permission' in reply) adapter.replyPermission(session.nativeId, requestId, reply.permission);
263
+ else if ('elicitation' in reply) adapter.replyElicitation(session.nativeId, requestId, reply.elicitation);
262
264
  else adapter.replyQuestion(session.nativeId, requestId, reply.answers);
263
265
  }
264
266
  public observed(worker: IFleetWorker): IFleetWorkerReport['status'] | undefined {