agl 43.0.5 → 43.2.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 +30 -0
- package/dist_serve/bundle.js +5996 -5280
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +30 -30
- package/dist_serve/bundle.js.third-party-notices.txt +30 -30
- package/dist_serve/third-party-notices.md +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +805 -10
- package/dist_ts/aglapi/interfaces.d.ts +13 -0
- package/dist_ts/aglapi/interfaces.js +4 -1
- package/dist_ts/classes.authmodels.js +17 -4
- package/dist_ts/classes.authstore.js +16 -2
- package/dist_ts/classes.claudeharness.d.ts +14 -5
- package/dist_ts/classes.claudeharness.js +62 -2
- package/dist_ts/classes.cli.d.ts +4 -2
- package/dist_ts/classes.cli.js +6 -3
- package/dist_ts/classes.codexclientadapter.d.ts +7 -5
- package/dist_ts/classes.codexclientadapter.js +38 -3
- package/dist_ts/classes.controller.d.ts +19 -2
- package/dist_ts/classes.controller.js +234 -27
- package/dist_ts/classes.controllermanagement.d.ts +14 -4
- package/dist_ts/classes.controllermanagement.js +20 -2
- package/dist_ts/classes.gatewayclient.d.ts +115 -0
- package/dist_ts/classes.gatewayclient.js +336 -0
- package/dist_ts/classes.gatewayclientstore.d.ts +97 -0
- package/dist_ts/classes.gatewayclientstore.js +261 -0
- package/dist_ts/classes.inferencegateway.d.ts +8 -5
- package/dist_ts/classes.inferencegateway.js +62 -19
- package/dist_ts/classes.inferencerouter.d.ts +9 -0
- package/dist_ts/classes.inferencerouter.js +11 -1
- package/dist_ts/classes.inferenceservice.d.ts +9 -0
- package/dist_ts/classes.inferenceservice.js +27 -1
- package/dist_ts/classes.inferencespend.d.ts +9 -3
- package/dist_ts/classes.inferencespend.js +44 -16
- package/dist_ts/classes.mcpclient.d.ts +9 -4
- package/dist_ts/classes.mcpclient.js +24 -2
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -1
- package/dist_ts/classes.mcpcontrollerhost.js +13 -1
- package/dist_ts/classes.mcptools.d.ts +3 -3
- package/dist_ts/classes.mcptools.js +42 -4
- package/dist_ts/classes.mcpvalidation.js +7 -1
- package/dist_ts/classes.opencodeclient.js +3 -1
- package/dist_ts/classes.proxycontrol.d.ts +33 -11
- package/dist_ts/classes.proxycontrol.js +12 -3
- package/dist_ts/classes.proxycontrolclient.d.ts +23 -5
- package/dist_ts/classes.proxycontrolclient.js +42 -6
- package/dist_ts/classes.proxydaemon.d.ts +8 -6
- package/dist_ts/classes.proxydaemon.js +42 -21
- package/dist_ts/classes.proxyleaseholder.d.ts +12 -4
- package/dist_ts/classes.proxyleaseholder.js +39 -9
- package/dist_ts/classes.proxymonitor.d.ts +7 -0
- package/dist_ts/classes.proxymonitor.js +13 -1
- package/dist_ts/classes.proxystore.d.ts +4 -3
- package/dist_ts/classes.proxystore.js +17 -7
- package/dist_ts/classes.sessionfeed.d.ts +1 -1
- package/dist_ts/classes.trustedproxysecrets.d.ts +2 -0
- package/dist_ts/classes.trustedproxysecrets.js +5 -1
- package/dist_ts/classes.validation.d.ts +7 -0
- package/dist_ts/classes.validation.js +49 -2
- package/dist_ts/driver/functions.drivertools.js +2 -2
- package/dist_ts/fleet/classes.codexworkers.d.ts +4 -11
- package/dist_ts/fleet/classes.codexworkers.js +6 -3
- package/dist_ts/fleet/classes.workers.d.ts +25 -13
- package/dist_ts/fleet/classes.workers.js +105 -9
- package/dist_ts/fleet/functions.workervalidation.d.ts +26 -1
- package/dist_ts/fleet/functions.workervalidation.js +40 -11
- package/dist_ts/fleet/interfaces.workers.d.ts +17 -11
- package/dist_ts/fleet/interfaces.workers.js +10 -1
- package/dist_ts/functions.confinedrelay.d.ts +21 -0
- package/dist_ts/functions.confinedrelay.js +65 -0
- package/dist_ts/functions.controllermanagementsurface.d.ts +4 -0
- package/dist_ts/functions.controllermanagementsurface.js +15 -1
- package/dist_ts/functions.deviceapi.d.ts +4 -2
- package/dist_ts/functions.deviceapi.js +20 -2
- package/dist_ts/functions.elicitation.d.ts +49 -0
- package/dist_ts/functions.elicitation.js +418 -0
- package/dist_ts/functions.gatewaycli.d.ts +24 -0
- package/dist_ts/functions.gatewaycli.js +395 -0
- package/dist_ts/functions.gatewayroute.d.ts +135 -0
- package/dist_ts/functions.gatewayroute.js +366 -0
- package/dist_ts/functions.inferencecli.d.ts +3 -3
- package/dist_ts/functions.inferencecli.js +62 -10
- package/dist_ts/functions.inferencecliarguments.d.ts +9 -2
- package/dist_ts/functions.inferencecliarguments.js +59 -10
- package/dist_ts/functions.inferencelaunch.d.ts +35 -7
- package/dist_ts/functions.inferencelaunch.js +143 -16
- package/dist_ts/functions.mcpfleetworkertools.d.ts +63 -70
- package/dist_ts/functions.mcpfleetworkertools.js +32 -4
- package/dist_ts/functions.proxycapacity.d.ts +50 -0
- package/dist_ts/functions.proxycapacity.js +142 -0
- package/dist_ts/functions.proxycapacitycli.d.ts +30 -0
- package/dist_ts/functions.proxycapacitycli.js +65 -0
- package/dist_ts/functions.proxycontract.d.ts +21 -4
- package/dist_ts/functions.proxycontract.js +12 -5
- package/dist_ts/functions.proxyharnessconfig.d.ts +7 -0
- package/dist_ts/functions.proxyharnessconfig.js +11 -1
- package/dist_ts/functions.remotecli.d.ts +30 -3
- package/dist_ts/functions.remotecli.js +44 -18
- package/dist_ts/interfaces.auth.d.ts +25 -4
- package/dist_ts/interfaces.auth.js +8 -1
- package/dist_ts/plugins.d.ts +2 -0
- package/dist_ts/plugins.js +4 -1
- package/dist_ts_authswitch/authority-placement.js +3 -17
- package/dist_ts_authswitch/authority-usagelimit.d.ts +29 -0
- package/dist_ts_authswitch/authority-usagelimit.js +66 -2
- package/dist_ts_authswitch/authority-usagewindows.d.ts +6 -0
- package/dist_ts_authswitch/authority-usagewindows.js +15 -1
- package/dist_ts_interfaces/devices.d.ts +133 -3
- package/dist_ts_interfaces/devices.js +3 -2
- package/dist_ts_interfaces/elicitations.d.ts +125 -0
- package/dist_ts_interfaces/elicitations.js +7 -0
- package/dist_ts_interfaces/fleetworkers.d.ts +119 -5
- package/dist_ts_interfaces/fleetworkers.js +14 -2
- package/dist_ts_interfaces/gateway.d.ts +151 -0
- package/dist_ts_interfaces/gateway.js +66 -0
- package/dist_ts_interfaces/index.d.ts +3 -0
- package/dist_ts_interfaces/index.js +4 -1
- package/dist_ts_interfaces/interfaces.d.ts +3 -1
- package/dist_ts_interfaces/interfaces.js +2 -2
- package/dist_ts_interfaces/management.d.ts +4 -4
- package/dist_ts_interfaces/management.js +3 -2
- package/dist_ts_interfaces/mcprequests.d.ts +18 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/nativesessions.d.ts +14 -0
- package/dist_ts_interfaces/proxycapacity.d.ts +99 -0
- package/dist_ts_interfaces/proxycapacity.js +74 -0
- package/dist_ts_interfaces/requests.d.ts +3 -3
- package/dist_ts_interfaces/requests.fleetworkers.js +2 -2
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.promptreply.d.ts +18 -0
- package/dist_ts_interfaces/sessionfeed.d.ts +3 -2
- package/dist_ts_interfaces/sessionfeed.js +1 -1
- package/package.json +5 -4
- package/readme.md +267 -26
- package/third-party-notices.md +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +804 -9
- package/ts/aglapi/interfaces.ts +3 -0
- package/ts/classes.authmodels.ts +22 -3
- package/ts/classes.authstore.ts +15 -1
- package/ts/classes.claudeharness.ts +80 -9
- package/ts/classes.cli.ts +7 -3
- package/ts/classes.codexclientadapter.ts +41 -5
- package/ts/classes.controller.ts +276 -32
- package/ts/classes.controllermanagement.ts +40 -7
- package/ts/classes.gatewayclient.ts +401 -0
- package/ts/classes.gatewayclientstore.ts +272 -0
- package/ts/classes.inferencegateway.ts +69 -23
- package/ts/classes.inferencerouter.ts +12 -0
- package/ts/classes.inferenceservice.ts +27 -0
- package/ts/classes.inferencespend.ts +46 -13
- package/ts/classes.mcpclient.ts +26 -4
- package/ts/classes.mcpcontrollerhost.ts +17 -0
- package/ts/classes.mcptools.ts +47 -5
- package/ts/classes.mcpvalidation.ts +5 -0
- package/ts/classes.opencodeclient.ts +2 -0
- package/ts/classes.proxycontrol.ts +43 -13
- package/ts/classes.proxycontrolclient.ts +39 -6
- package/ts/classes.proxydaemon.ts +57 -27
- package/ts/classes.proxyleaseholder.ts +43 -11
- package/ts/classes.proxymonitor.ts +12 -0
- package/ts/classes.proxystore.ts +21 -8
- package/ts/classes.sessionfeed.ts +1 -1
- package/ts/classes.trustedproxysecrets.ts +5 -0
- package/ts/classes.validation.ts +52 -0
- package/ts/driver/functions.drivertools.ts +1 -1
- package/ts/fleet/classes.codexworkers.ts +8 -6
- package/ts/fleet/classes.workers.ts +101 -17
- package/ts/fleet/functions.workervalidation.ts +35 -9
- package/ts/fleet/interfaces.workers.ts +11 -4
- package/ts/functions.confinedrelay.ts +65 -0
- package/ts/functions.controllermanagementsurface.ts +15 -0
- package/ts/functions.deviceapi.ts +24 -1
- package/ts/functions.elicitation.ts +443 -0
- package/ts/functions.gatewaycli.ts +436 -0
- package/ts/functions.gatewayroute.ts +429 -0
- package/ts/functions.inferencecli.ts +62 -13
- package/ts/functions.inferencecliarguments.ts +56 -9
- package/ts/functions.inferencelaunch.ts +143 -16
- package/ts/functions.mcpfleetworkertools.ts +34 -4
- package/ts/functions.proxycapacity.ts +191 -0
- package/ts/functions.proxycapacitycli.ts +104 -0
- package/ts/functions.proxycontract.ts +17 -4
- package/ts/functions.proxyharnessconfig.ts +11 -0
- package/ts/functions.remotecli.ts +56 -20
- package/ts/interfaces.auth.ts +29 -4
- package/ts/plugins.ts +5 -0
- package/ts_authswitch/authority-placement.ts +2 -15
- package/ts_authswitch/authority-usagelimit.ts +84 -1
- package/ts_authswitch/authority-usagewindows.ts +13 -0
- package/ts_interfaces/devices.schema.json +476 -2
- package/ts_interfaces/devices.ts +146 -2
- package/ts_interfaces/elicitations.ts +148 -0
- package/ts_interfaces/fleetworkers.ts +96 -4
- package/ts_interfaces/gateway.ts +242 -0
- package/ts_interfaces/index.ts +3 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/management.ts +6 -4
- package/ts_interfaces/mcprequests.ts +19 -0
- package/ts_interfaces/nativesessions.ts +16 -0
- package/ts_interfaces/proxycapacity.ts +162 -0
- package/ts_interfaces/requests.fleetworkers.ts +1 -1
- package/ts_interfaces/requests.promptreply.ts +22 -0
- package/ts_interfaces/requests.ts +4 -0
- package/ts_interfaces/sessionfeed.ts +3 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.browserpresentation.ts +13 -5
- package/ts_web/classes.elicitationcards.ts +106 -0
- package/ts_web/classes.nativesessionstate.ts +38 -1
- package/ts_web/elements.accounts.ts +40 -113
- package/ts_web/elements.configurationpane.ts +24 -37
- package/ts_web/elements.devices.ts +4 -17
- package/ts_web/elements.fleetworker.ts +27 -2
- package/ts_web/elements.flexlimitstrip.ts +21 -70
- package/ts_web/elements.harnesscontrollerapp.ts +159 -186
- package/ts_web/functions.sessionchat.ts +5 -0
|
@@ -12,10 +12,12 @@ import {
|
|
|
12
12
|
proxyClientNamePattern,
|
|
13
13
|
proxyCredentialDeliveries,
|
|
14
14
|
type TInferenceCredential,
|
|
15
|
+
type TAglProxyConfinedHarness,
|
|
15
16
|
type TInferenceProvider,
|
|
16
17
|
type TProxyCredentialDelivery,
|
|
17
18
|
} from './functions.proxycontract.js';
|
|
18
19
|
import { isAuthorityAccountId } from '../ts_interfaces/functions.authorityscope.js';
|
|
20
|
+
import { isProxyCapacityRequest, type IProxyCapacityAnswer, type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
19
21
|
import { proxyControlMaximumFrameBytes, readProxyControlLine } from './classes.proxycontrolclient.js';
|
|
20
22
|
import { claimProxySocketPath } from './functions.proxysocket.js';
|
|
21
23
|
|
|
@@ -74,6 +76,8 @@ export interface IAglProxyConfinedRunStatus {
|
|
|
74
76
|
id: string;
|
|
75
77
|
/** The pool the run is served from: Claude accounts (`anthropic`) or ChatGPT accounts (`openai`). */
|
|
76
78
|
provider: TInferenceProvider;
|
|
79
|
+
/** The harness the run serves: Claude Code on either pool, or Codex on the ChatGPT pool's ChatGPT accounts alone. */
|
|
80
|
+
harness: TAglProxyConfinedHarness;
|
|
77
81
|
createdAt: string;
|
|
78
82
|
/** False while a restarted proxy serves the credential for its reclaim window, waiting for its holder to take it back. */
|
|
79
83
|
held: boolean;
|
|
@@ -113,6 +117,16 @@ export interface IReq_AglProxyStatus extends ITypedRequest {
|
|
|
113
117
|
response: { status: IAglProxyStatus };
|
|
114
118
|
}
|
|
115
119
|
|
|
120
|
+
/**
|
|
121
|
+
* A pool's room for new work, or both pools' when `provider` is absent (AGL-1097): see `IProxyCapacityAnswer` and
|
|
122
|
+
* `proxyPoolCapacity`. Refused while the account service is unavailable. A proxy before AGL-1097 refuses the method.
|
|
123
|
+
*/
|
|
124
|
+
export interface IReq_AglProxyCapacity extends ITypedRequest {
|
|
125
|
+
method: 'agl.proxy.capacity';
|
|
126
|
+
request: IProxyCapacityRequest;
|
|
127
|
+
response: IProxyCapacityAnswer;
|
|
128
|
+
}
|
|
129
|
+
|
|
116
130
|
/**
|
|
117
131
|
* A credential that lives as long as the connection that asked for it. A proxy that restarts keeps the leases its
|
|
118
132
|
* holders have not ended, and serves them for a bounded window in which each holder takes its lease back on a new
|
|
@@ -149,31 +163,39 @@ export interface IReq_AglProxyReclaim extends ITypedRequest {
|
|
|
149
163
|
}
|
|
150
164
|
|
|
151
165
|
/**
|
|
152
|
-
* A confined run's credential: accepted on the confined listener alone, never on the loopback one
|
|
153
|
-
* the pool `provider` names -- the Claude pool when it names none -- exactly as the loopback listener
|
|
154
|
-
* that pool, its sessions those of the client `aglProxyConfinedClient` on that pool
|
|
155
|
-
* pool's ChatGPT accounts alone, since a translated Messages request never goes to an API key.
|
|
156
|
-
*
|
|
166
|
+
* A confined run's credential: accepted on the confined listener alone, never on the loopback one. A Claude Code run is
|
|
167
|
+
* served there from the pool `provider` names -- the Claude pool when it names none -- exactly as the loopback listener
|
|
168
|
+
* serves Claude Code on that pool, its sessions those of the client `aglProxyConfinedClient` on that pool; a ChatGPT-pool
|
|
169
|
+
* run is served by the pool's ChatGPT accounts alone, since a translated Messages request never goes to an API key. A
|
|
170
|
+
* Codex run (`harness: 'codex'`, of the ChatGPT pool alone) is served Codex's model catalog and Responses endpoint by the
|
|
171
|
+
* ChatGPT pool's ChatGPT accounts alone, never an OpenAI API key, its sessions those of `aglProxyConfinedCodexClient`. Like
|
|
172
|
+
* a lease it lives as long as the connection that asked for it, a restarted proxy keeps it for its holder to take back
|
|
157
173
|
* (`agl.proxy.reclaim`), and the proxy keeps only its digest. `agl.proxy.confined.end` ends it at once.
|
|
158
174
|
*/
|
|
159
175
|
export interface IReq_AglProxyConfined extends ITypedRequest {
|
|
160
176
|
method: 'agl.proxy.confined';
|
|
161
|
-
/**
|
|
162
|
-
|
|
177
|
+
/**
|
|
178
|
+
* An empty request asks for a Claude-pool run, as every proxy since confined runs takes it; `harness: 'codex'` asks for
|
|
179
|
+
* a Codex run, which names no pool or the ChatGPT pool. A proxy before Codex runs refuses the key as an invalid request.
|
|
180
|
+
*/
|
|
181
|
+
request: { provider?: TInferenceProvider; harness?: 'codex' };
|
|
163
182
|
response: IAglProxyConfinedGrant;
|
|
164
183
|
}
|
|
165
184
|
|
|
166
185
|
/**
|
|
167
|
-
* What a confined run is given: its id, its pool, its credential, the confined listener's socket and the
|
|
168
|
-
* with it, and, for a ChatGPT-pool run, the pool's models as the proxy read them when it issued
|
|
169
|
-
* launcher configures Claude Code with as `agl proxy run claude --provider openai` does. A
|
|
170
|
-
* Claude Code reads that pool's models through the confined listener
|
|
186
|
+
* What a confined run is given: its id, its pool and harness, its credential, the confined listener's socket and the
|
|
187
|
+
* origin to name with it, and, for a ChatGPT-pool Claude Code run, the pool's models as the proxy read them when it issued
|
|
188
|
+
* the credential, which the launcher configures Claude Code with as `agl proxy run claude --provider openai` does. A
|
|
189
|
+
* Claude-pool run gets none: Claude Code reads that pool's models through the confined listener; nor does a Codex run,
|
|
190
|
+
* whose Codex reads the pool's Codex catalog there.
|
|
171
191
|
*/
|
|
172
192
|
export interface IAglProxyConfinedGrant {
|
|
173
193
|
/** See `IAglProxyConfinedRunStatus.id`. */
|
|
174
194
|
id: string;
|
|
175
195
|
/** The run's pool; a proxy older than ChatGPT-pool runs names none, and issues Claude-pool runs alone. */
|
|
176
196
|
provider?: TInferenceProvider;
|
|
197
|
+
/** The run's harness; a proxy older than Codex runs names none, and issues Claude Code runs alone. */
|
|
198
|
+
harness?: TAglProxyConfinedHarness;
|
|
177
199
|
token: string;
|
|
178
200
|
socketPath: string;
|
|
179
201
|
baseUrl: string;
|
|
@@ -217,6 +239,7 @@ export interface IAglProxyConnection {
|
|
|
217
239
|
export interface IAglProxyControlHandlers {
|
|
218
240
|
credential(requestArg: IReq_AglProxyCredential['request']): Promise<IReq_AglProxyCredential['response']>;
|
|
219
241
|
status(): Promise<IReq_AglProxyStatus['response']>;
|
|
242
|
+
capacity(requestArg: IReq_AglProxyCapacity['request'], connectionArg: IAglProxyConnection): Promise<IReq_AglProxyCapacity['response']>;
|
|
220
243
|
catalog(requestArg: IReq_AglProxyCatalog['request'], connectionArg: IAglProxyConnection): Promise<IReq_AglProxyCatalog['response']>;
|
|
221
244
|
lease(requestArg: IReq_AglProxyLease['request'], connectionArg: IAglProxyConnection): Promise<IReq_AglProxyLease['response']>;
|
|
222
245
|
reclaim(requestArg: IReq_AglProxyReclaim['request'], connectionArg: IAglProxyConnection): Promise<IReq_AglProxyReclaim['response']>;
|
|
@@ -290,6 +313,10 @@ export class AglProxyControlServer {
|
|
|
290
313
|
return this.handlers!.credential(requestArg);
|
|
291
314
|
}));
|
|
292
315
|
this.router.addTypedHandler(handler<IReq_AglProxyStatus>('agl.proxy.status', () => this.handlers!.status()));
|
|
316
|
+
this.router.addTypedHandler(handler<IReq_AglProxyCapacity>('agl.proxy.capacity', (requestArg, connectionArg) => {
|
|
317
|
+
if (!isProxyCapacityRequest(requestArg)) throw new AglProxyControlRefusal('Invalid proxy capacity request.');
|
|
318
|
+
return this.handlers!.capacity(requestArg, connectionArg);
|
|
319
|
+
}));
|
|
293
320
|
this.router.addTypedHandler(handler<IReq_AglProxyCatalog>('agl.proxy.catalog', (requestArg, connectionArg) => {
|
|
294
321
|
if (!isRecord(requestArg)
|
|
295
322
|
|| Object.keys(requestArg).some((keyArg) => !['provider', 'credential', 'accountId'].includes(keyArg))
|
|
@@ -316,8 +343,11 @@ export class AglProxyControlServer {
|
|
|
316
343
|
return this.handlers!.reclaim(requestArg, connectionArg);
|
|
317
344
|
}));
|
|
318
345
|
this.router.addTypedHandler(handler<IReq_AglProxyConfined>('agl.proxy.confined', (requestArg, connectionArg) => {
|
|
319
|
-
|
|
320
|
-
|
|
346
|
+
// A Codex run is of the ChatGPT pool alone.
|
|
347
|
+
if (!isRecord(requestArg) || Object.keys(requestArg).some((keyArg) => keyArg !== 'provider' && keyArg !== 'harness')
|
|
348
|
+
|| (requestArg.provider !== undefined && !inferenceProviders.includes(requestArg.provider))
|
|
349
|
+
|| (requestArg.harness !== undefined && requestArg.harness !== 'codex')
|
|
350
|
+
|| (requestArg.harness === 'codex' && requestArg.provider !== undefined && requestArg.provider !== 'openai')) {
|
|
321
351
|
throw new AglProxyControlRefusal('Invalid proxy confined request.');
|
|
322
352
|
}
|
|
323
353
|
return this.handlers!.confined(requestArg, connectionArg);
|
|
@@ -16,7 +16,9 @@ import type {
|
|
|
16
16
|
} from './classes.proxycontrol.js';
|
|
17
17
|
import type { IInferenceUsageChangesRequest, IInferenceUsageSnapshotPage, IInferenceUsageSnapshotRequest,
|
|
18
18
|
TInferenceUsageChanges } from './classes.inferenceusage.js';
|
|
19
|
-
import type { TInferenceCredential, TInferenceProvider,
|
|
19
|
+
import type { TAglProxyConfinedRun, TInferenceCredential, TInferenceProvider,
|
|
20
|
+
TProxyCredentialDelivery } from './functions.proxycontract.js';
|
|
21
|
+
import type { IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* The client of the proxy's private control socket. It needs nothing but Node's own modules, so the command a harness
|
|
@@ -69,6 +71,18 @@ export class AglProxyRefusedError extends Error {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
/**
|
|
75
|
+
* A proxy of another AGL release refused a request it does not know: it runs the AGL it was started from, as after an
|
|
76
|
+
* upgrade it was not restarted by.
|
|
77
|
+
*/
|
|
78
|
+
export class AglProxyOutdatedError extends Error {
|
|
79
|
+
constructor(public readonly proxyVersion: string, public readonly ownVersion: string) {
|
|
80
|
+
super(`The AGL proxy runs AGL ${proxyVersion}, not ${ownVersion}, and does not answer this request. `
|
|
81
|
+
+ 'Restart it onto the installed AGL with `agl proxy service stop`, then `agl proxy service start`.');
|
|
82
|
+
this.name = 'AglProxyOutdatedError';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
72
86
|
interface IWireAnswer {
|
|
73
87
|
method?: unknown;
|
|
74
88
|
response?: unknown;
|
|
@@ -166,6 +180,23 @@ export class AglProxyControlClient {
|
|
|
166
180
|
return (await exchange<IReq_AglProxyStatus['response']>(this.socketPath, 'agl.proxy.status', {}, signalArg)).status;
|
|
167
181
|
}
|
|
168
182
|
|
|
183
|
+
/**
|
|
184
|
+
* The room for new work of the pool `requestArg` names, or of both (`IReq_AglProxyCapacity`), as the proxy answers it:
|
|
185
|
+
* a caller that may meet another release checks it (`isProxyCapacityAnswer`). A refusal from a proxy of another AGL
|
|
186
|
+
* release than `ownVersionArg` is that proxy not knowing the request (`AglProxyOutdatedError`); any other refusal is the
|
|
187
|
+
* proxy's own (`AglProxyRefusedError`).
|
|
188
|
+
*/
|
|
189
|
+
public async capacity(requestArg: IProxyCapacityRequest, signalArg: AbortSignal, ownVersionArg: string): Promise<unknown> {
|
|
190
|
+
try {
|
|
191
|
+
return await exchange<unknown>(this.socketPath, 'agl.proxy.capacity', requestArg, signalArg);
|
|
192
|
+
} catch (errorArg) {
|
|
193
|
+
if (!(errorArg instanceof AglProxyRefusedError)) throw errorArg;
|
|
194
|
+
const version = (await this.status(signalArg)).version;
|
|
195
|
+
if (version !== ownVersionArg) throw new AglProxyOutdatedError(version, ownVersionArg);
|
|
196
|
+
throw errorArg;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
169
200
|
/**
|
|
170
201
|
* A private credential and endpoint for one child, continuing the sessions of the proxy client `clientArg`; closing
|
|
171
202
|
* the lease ends the credential.
|
|
@@ -190,14 +221,16 @@ export class AglProxyControlClient {
|
|
|
190
221
|
}
|
|
191
222
|
|
|
192
223
|
/**
|
|
193
|
-
* A confined run's credential
|
|
194
|
-
* with it; the credential lives as long as the returned connection (see `IReq_AglProxyConfined`). A Claude-pool run
|
|
195
|
-
* asked for with the empty request every proxy since confined runs takes
|
|
224
|
+
* A confined run's credential for the harness and pool `runArg` names, the confined listener's socket and the origin to
|
|
225
|
+
* name with it; the credential lives as long as the returned connection (see `IReq_AglProxyConfined`). A Claude-pool run
|
|
226
|
+
* is asked for with the empty request every proxy since confined runs takes, a ChatGPT-pool Claude Code run with the
|
|
227
|
+
* pool alone, as proxies since ChatGPT-pool runs take it, and a Codex run with the harness alone.
|
|
196
228
|
*/
|
|
197
|
-
public async confined(
|
|
229
|
+
public async confined(runArg: TAglProxyConfinedRun,
|
|
198
230
|
signalArg: AbortSignal): Promise<IReq_AglProxyConfined['response'] & IAglProxyLeaseConnection> {
|
|
199
231
|
let held: { socket: net.Socket; rest: Buffer } | undefined;
|
|
200
|
-
const request: IReq_AglProxyConfined['request'] =
|
|
232
|
+
const request: IReq_AglProxyConfined['request'] = runArg.harness === 'codex' ? { harness: 'codex' }
|
|
233
|
+
: runArg.provider === 'anthropic' ? {} : { provider: runArg.provider };
|
|
201
234
|
const response = await exchange<IReq_AglProxyConfined['response']>(this.socketPath, 'agl.proxy.confined', request,
|
|
202
235
|
signalArg, (socketArg, restArg) => { held = { socket: socketArg, rest: restArg }; });
|
|
203
236
|
return { ...response, ...leaseConnection(held) };
|
|
@@ -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,
|
|
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
|
-
/**
|
|
70
|
-
|
|
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,
|
|
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. */
|
|
@@ -154,6 +169,14 @@ export class AglProxyDaemon {
|
|
|
154
169
|
credential: (requestArg) => this.heldCredential(requestArg.client, requestArg.rotate === true, requestArg.provider, requestArg.delivery)
|
|
155
170
|
?? this.serialized(() => this.credential(requestArg.client, requestArg.rotate === true, requestArg.provider, requestArg.delivery)),
|
|
156
171
|
status: async () => ({ status: await this.status() }),
|
|
172
|
+
capacity: async (requestArg, connectionArg) => {
|
|
173
|
+
const answer = await this.service!.capacity(requestArg, AbortSignal.any([this.abort.signal, connectionArg.signal]));
|
|
174
|
+
if (!answer) {
|
|
175
|
+
throw new AglProxyControlRefusal('The account service is unavailable, so the proxy cannot judge its pools.',
|
|
176
|
+
'authority_unavailable');
|
|
177
|
+
}
|
|
178
|
+
return answer;
|
|
179
|
+
},
|
|
157
180
|
catalog: (requestArg, connectionArg) => this.catalog(requestArg, connectionArg),
|
|
158
181
|
lease: (requestArg, connectionArg) => this.lease(requestArg.policy, requestArg.client, connectionArg),
|
|
159
182
|
reclaim: async (requestArg, connectionArg) => this.reclaim(requestArg.token, connectionArg),
|
|
@@ -177,10 +200,11 @@ export class AglProxyDaemon {
|
|
|
177
200
|
leases: status.leases, inFlight: status.inFlight, limits: status.limits, authority: status.authority,
|
|
178
201
|
accounts: status.accounts, usageObservations: status.usageObservations, nextPlacement: status.nextPlacement,
|
|
179
202
|
recentPlacements: status.recentPlacements, confinedSocketPath: this.options.confinedSocketPath ?? null,
|
|
180
|
-
confinedRuns: [...this.leases]
|
|
181
|
-
.
|
|
182
|
-
.
|
|
183
|
-
|
|
203
|
+
confinedRuns: [...this.leases]
|
|
204
|
+
.flatMap(([digestArg, heldArg]) => heldArg.route === 'confined' ? [{ digest: digestArg, held: heldArg }] : [])
|
|
205
|
+
.sort((left, right) => left.held.createdAt.getTime() - right.held.createdAt.getTime())
|
|
206
|
+
.map(({ digest, held }) => ({ id: confinedRunId(digest), provider: held.provider, harness: held.harness,
|
|
207
|
+
createdAt: held.createdAt.toISOString(), held: held.reclaimTimer === undefined })),
|
|
184
208
|
};
|
|
185
209
|
}
|
|
186
210
|
|
|
@@ -300,7 +324,7 @@ export class AglProxyDaemon {
|
|
|
300
324
|
// The lease continues the sessions of the client it is taken for (see `IReq_AglProxyLease`).
|
|
301
325
|
try { lease = await service.open(policyArg, { sessionScope: clientArg }); }
|
|
302
326
|
catch (errorArg) { throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The lease could not be opened.'); }
|
|
303
|
-
const held:
|
|
327
|
+
const held: THeldLease = { grant: lease, route: 'loopback', provider: policyArg.provider ?? 'openai', createdAt: new Date(),
|
|
304
328
|
holder: connectionArg };
|
|
305
329
|
this.leases.set(lease.digest, held);
|
|
306
330
|
try {
|
|
@@ -331,38 +355,42 @@ export class AglProxyDaemon {
|
|
|
331
355
|
* proves the caller holds the credential the lease was issued with.
|
|
332
356
|
*/
|
|
333
357
|
/**
|
|
334
|
-
* A confined run's credential (see `IReq_AglProxyConfined`)
|
|
335
|
-
* when it names none -- that continues the confined client's sessions on that pool
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
358
|
+
* A confined run's credential (see `IReq_AglProxyConfined`). A Claude Code run's is a lease of the pool the request
|
|
359
|
+
* names -- the Claude pool when it names none -- that continues the confined client's sessions on that pool; a Codex
|
|
360
|
+
* run's is a lease of the ChatGPT pool's ChatGPT accounts alone (`confinedCodexPolicy`) that continues the confined Codex
|
|
361
|
+
* client's sessions. Either is accepted on the confined listener alone, kept, as its digest, before it is handed out, and
|
|
362
|
+
* ends when its holder's connection closes or the operator ends it (`confinedEnd`). A Claude-pool run gets no model list:
|
|
363
|
+
* Claude Code reads the pool's models through the confined listener, and the pool is judged at each request; nor does a
|
|
364
|
+
* Codex run, whose Codex reads the pool's Codex catalog there. A ChatGPT-pool Claude Code run gets the pool's models, as
|
|
339
365
|
* an `agl proxy run` lease does, for its launcher to configure Claude Code with.
|
|
340
366
|
*/
|
|
341
367
|
private async confined(requestArg: IReq_AglProxyConfined['request'],
|
|
342
368
|
connectionArg: IAglProxyConnection): Promise<IAglProxyConfinedGrant> {
|
|
343
369
|
const socketPath = this.options.confinedSocketPath;
|
|
344
370
|
if (socketPath === undefined) throw new AglProxyControlRefusal('This AGL proxy has no confined listener.');
|
|
345
|
-
const
|
|
346
|
-
const
|
|
371
|
+
const harness: TAglProxyConfinedHarness = requestArg.harness ?? 'claude';
|
|
372
|
+
const provider = harness === 'codex' ? 'openai' : requestArg.provider ?? 'anthropic';
|
|
373
|
+
const policy = harness === 'codex' ? confinedCodexPolicy : confinedPolicies[provider];
|
|
374
|
+
const client = harness === 'codex' ? aglProxyConfinedCodexClient : aglProxyConfinedClient;
|
|
347
375
|
const service = this.service!;
|
|
348
376
|
let lease: IInferenceGatewayLease;
|
|
349
|
-
try { lease = await service.open(policy, { sessionScope:
|
|
377
|
+
try { lease = await service.open(policy, { sessionScope: client, route: 'confined' }); }
|
|
350
378
|
catch (errorArg) {
|
|
351
379
|
throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The confined credential could not be issued.');
|
|
352
380
|
}
|
|
353
|
-
const held:
|
|
381
|
+
const held: THeldLease = { grant: lease, route: 'confined', provider, harness, createdAt: new Date(), holder: connectionArg };
|
|
354
382
|
this.leases.set(lease.digest, held);
|
|
355
383
|
try {
|
|
356
|
-
await this.trackLeaseWrite(this.store!.recordLease({ digest: lease.digest, client:
|
|
357
|
-
|
|
384
|
+
await this.trackLeaseWrite(this.store!.recordLease({ digest: lease.digest, client, policy, createdAt: held.createdAt,
|
|
385
|
+
route: 'confined' }));
|
|
358
386
|
} catch (errorArg) {
|
|
359
387
|
this.endLease(lease.digest, held);
|
|
360
388
|
throw new AglProxyControlRefusal(errorArg instanceof Error ? errorArg.message : 'The confined credential could not be recorded.');
|
|
361
389
|
}
|
|
362
390
|
connectionArg.onClose(() => this.endLease(lease.digest, held));
|
|
363
|
-
const grant: IAglProxyConfinedGrant = { id: confinedRunId(lease.digest), provider, token: lease.token, socketPath,
|
|
391
|
+
const grant: IAglProxyConfinedGrant = { id: confinedRunId(lease.digest), provider, harness, token: lease.token, socketPath,
|
|
364
392
|
baseUrl: aglProxyConfinedOrigin };
|
|
365
|
-
if (provider === 'anthropic') return grant;
|
|
393
|
+
if (provider === 'anthropic' || harness === 'codex') return grant;
|
|
366
394
|
try {
|
|
367
395
|
// A launcher that goes away stops the model list read it asked for.
|
|
368
396
|
return { ...grant, models: await service.router.models(policy, AbortSignal.any([connectionArg.signal, AbortSignal.timeout(60_000)])) };
|
|
@@ -441,7 +469,9 @@ export class AglProxyDaemon {
|
|
|
441
469
|
await this.forgetLease(kept.digest);
|
|
442
470
|
continue;
|
|
443
471
|
}
|
|
444
|
-
const
|
|
472
|
+
const base: IHeldLeaseBase = { grant, provider: kept.policy.provider ?? 'openai', createdAt: kept.createdAt };
|
|
473
|
+
const held: THeldLease = kept.route === 'confined' ? { ...base, route: 'confined', harness: confinedHarnessOf(kept.client) }
|
|
474
|
+
: { ...base, route: 'loopback' };
|
|
445
475
|
held.reclaimTimer = setTimeout(() => this.endLease(kept.digest, held), Math.max(0, deadline - Date.now()));
|
|
446
476
|
this.leases.set(kept.digest, held);
|
|
447
477
|
}
|
|
@@ -451,7 +481,7 @@ export class AglProxyDaemon {
|
|
|
451
481
|
* Ends a lease: its credential stops working and the store forgets it. A stopping proxy ends none -- its holders'
|
|
452
482
|
* connections close because it stops -- so the next start serves them again.
|
|
453
483
|
*/
|
|
454
|
-
private endLease(digestArg: string, heldArg:
|
|
484
|
+
private endLease(digestArg: string, heldArg: THeldLease): void {
|
|
455
485
|
if (this.abort.signal.aborted || this.leases.get(digestArg) !== heldArg) return;
|
|
456
486
|
clearTimeout(heldArg.reclaimTimer);
|
|
457
487
|
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
|
-
/**
|
|
165
|
-
|
|
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
|
|
170
|
-
* ChatGPT-pool runs names no pool and issues Claude-pool runs alone,
|
|
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 = (
|
|
173
|
-
if (
|
|
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
|
-
|
|
190
|
-
|
|
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
|
-
/**
|
|
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
|
}
|
|
@@ -9,6 +9,7 @@ import { aglProxyDefaultPort, type TInferenceCredential, type TInferenceProvider
|
|
|
9
9
|
type TProxyCredentialDelivery } from './functions.proxycontract.js';
|
|
10
10
|
import type { IConfigurationInferenceProxy } from './configuration/classes.inferencereview.js';
|
|
11
11
|
import type { IControllerProxyUnit, TControllerProxyState } from '../ts_interfaces/index.js';
|
|
12
|
+
import { isProxyCapacityAnswer, type IProxyCapacityAnswer, type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
12
13
|
|
|
13
14
|
export interface IAglProxyMonitorOptions {
|
|
14
15
|
/** The proxy's private control socket. */
|
|
@@ -158,6 +159,17 @@ export class AglProxyMonitor implements IConfigurationInferenceProxy {
|
|
|
158
159
|
return (await this.unitState()) ?? undefined;
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/**
|
|
163
|
+
* A pool's room for new work as the proxy judges it (`agl.proxy.capacity`), read only by the contract. A proxy of an
|
|
164
|
+
* older release that does not know the request rejects with `AglProxyOutdatedError`, one that is not running with
|
|
165
|
+
* `AglProxyUnavailableError`.
|
|
166
|
+
*/
|
|
167
|
+
public async capacity(requestArg: IProxyCapacityRequest, signalArg: AbortSignal): Promise<IProxyCapacityAnswer> {
|
|
168
|
+
const answer = await this.client.capacity(requestArg, signalArg, commitinfo.version);
|
|
169
|
+
if (!isProxyCapacityAnswer(answer)) throw new Error('The AGL proxy answered a capacity this AGL cannot read.');
|
|
170
|
+
return answer;
|
|
171
|
+
}
|
|
172
|
+
|
|
161
173
|
/** The token usage the proxy counted, as the metrics board's usage feed reads it. */
|
|
162
174
|
public usage(requestArg: IReq_AglProxyUsage['request'], signalArg: AbortSignal): Promise<IReq_AglProxyUsage['response']> {
|
|
163
175
|
return this.client.usage(requestArg, signalArg);
|
package/ts/classes.proxystore.ts
CHANGED
|
@@ -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
|
|
134
|
-
* the Claude pool's or the ChatGPT pool's, unrestricted, and the confined client's sessions on that
|
|
135
|
-
*
|
|
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
|
-
/**
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
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
|
|
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;
|
|
@@ -180,6 +180,11 @@ export class ControllerTrustedProxySecrets {
|
|
|
180
180
|
return { secret: secret.text.toString('utf8'), generation: secret.generation };
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/** Whether a rotation waits for the route to carry its secret: the next secret is accepted beside the active one. */
|
|
184
|
+
public rotating(): boolean {
|
|
185
|
+
return !this.closed && this.next !== undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
183
188
|
/**
|
|
184
189
|
* Starts a rotation: a new secret, accepted beside the active one from now on, which the route must carry next.
|
|
185
190
|
* A rotation already in progress is returned again, so a sync that failed is retried with the same secret.
|