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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
-
import { aglProxyConfinedClient, inferenceCredentials, inferencePlanPattern, inferenceProviders,
|
|
3
|
-
type TInferenceProvider } from './functions.proxycontract.js';
|
|
2
|
+
import { aglProxyConfinedClient, aglProxyConfinedCodexClient, inferenceCredentials, inferencePlanPattern, inferenceProviders,
|
|
3
|
+
type TInferenceCredential, type TInferenceProvider } from './functions.proxycontract.js';
|
|
4
4
|
import { InferenceRouter, InferenceRoutingError, inferenceSpendLimitText, type IInferenceAccountUnavailable,
|
|
5
5
|
type IInferenceClaudeRoute, type IInferenceRoute, type IInferenceRoutingPolicy,
|
|
6
6
|
type TInferencePaymentCause } from './classes.inferencerouter.js';
|
|
@@ -10,8 +10,8 @@ import { inferenceSessionId, inferenceSessionKey } from './classes.inferencesess
|
|
|
10
10
|
import type { IInferencePlacementJournal, IInferencePlacementRecord, TInferencePlacementReason } from './classes.inferenceplacement.js';
|
|
11
11
|
import { InferenceClaudeUsageTap, InferenceResponsesUsageTap, type IInferenceUsageTap } from './classes.inferenceusagetap.js';
|
|
12
12
|
import { inferenceAnthropicCheckedBytes, inferenceAnthropicServerToolTypes, inferenceAnthropicSpend,
|
|
13
|
-
inferenceAnthropicUnpricedRequest, inferenceOpenAiCheckedBytes,
|
|
14
|
-
inferenceOpenAiUnpricedRequest } from './classes.inferencespend.js';
|
|
13
|
+
inferenceAnthropicUnpricedRequest, inferenceOpenAiCheckedBytes, inferenceOpenAiServerToolChoiceTypes,
|
|
14
|
+
inferenceOpenAiServerToolTypes, inferenceOpenAiSpend, inferenceOpenAiUnpricedRequest } from './classes.inferencespend.js';
|
|
15
15
|
import { usageSessionPattern, type IInferenceTokenCounts, type IInferenceUsageLedger } from './classes.inferenceusage.js';
|
|
16
16
|
import { claimProxySocketPath } from './functions.proxysocket.js';
|
|
17
17
|
|
|
@@ -92,9 +92,11 @@ export interface IInferenceGatewayOptions {
|
|
|
92
92
|
usageLedger: IInferenceUsageLedger;
|
|
93
93
|
/**
|
|
94
94
|
* The confined listener's Unix socket, bound beside the loopback port and made this user's alone (0600, in a private
|
|
95
|
-
* directory that holds nothing else). It accepts confined credentials alone and serves
|
|
96
|
-
* Code uses (`confinedEndpoints`) of
|
|
97
|
-
* Claude Code on that pool
|
|
95
|
+
* directory that holds nothing else). It accepts confined credentials alone and serves a Claude Code run the three
|
|
96
|
+
* endpoints Claude Code uses (`confinedEndpoints`) of its pool, the Claude or the ChatGPT pool, exactly as the loopback
|
|
97
|
+
* listener serves Claude Code on that pool, and a Codex run Codex's two (`confinedCodexEndpoints`) of the ChatGPT pool's
|
|
98
|
+
* ChatGPT accounts, as the loopback listener serves Codex there, but no request that declares a hosted tool; unset, the
|
|
99
|
+
* gateway has no confined listener and admits no confined credential.
|
|
98
100
|
*/
|
|
99
101
|
confinedSocketPath?: string;
|
|
100
102
|
}
|
|
@@ -231,7 +233,8 @@ export interface IInferenceGatewayClientOptions {
|
|
|
231
233
|
sessionScope?: string;
|
|
232
234
|
/**
|
|
233
235
|
* Where the credential is accepted; `loopback` when unset. A confined credential is a lease of the Claude or the ChatGPT
|
|
234
|
-
* pool, accepted on the confined listener alone, and stays on the pool it was issued for
|
|
236
|
+
* pool, accepted on the confined listener alone, and stays on the pool it was issued for; one whose sessions are those of
|
|
237
|
+
* `aglProxyConfinedCodexClient` is a Codex run's, a lease of the ChatGPT pool's ChatGPT accounts alone.
|
|
235
238
|
*/
|
|
236
239
|
route?: TInferenceGatewayRoute;
|
|
237
240
|
}
|
|
@@ -318,12 +321,21 @@ const maximumErrorBodyBytes = 64 * 1024;
|
|
|
318
321
|
const catalogTag = (modelsArg: unknown): string =>
|
|
319
322
|
`"${plugins.crypto.createHash('sha256').update(JSON.stringify(modelsArg)).digest('base64url')}"`;
|
|
320
323
|
/**
|
|
321
|
-
* What the confined listener serves, by method and path: the endpoints Claude Code uses, of the Claude
|
|
322
|
-
* of the ChatGPT pool. Every other method and path, every `/openai/` path among them, is refused there
|
|
323
|
-
* read or routed.
|
|
324
|
+
* What the confined listener serves a Claude Code run, by method and path: the endpoints Claude Code uses, of the Claude
|
|
325
|
+
* pool or, translated, of the ChatGPT pool. Every other method and path, every `/openai/` path among them, is refused there
|
|
326
|
+
* before anything is read or routed.
|
|
324
327
|
*/
|
|
325
328
|
const confinedEndpoints: ReadonlySet<string> = new Set(['GET /anthropic/v1/models', 'POST /anthropic/v1/messages',
|
|
326
329
|
'POST /anthropic/v1/messages/count_tokens']);
|
|
330
|
+
/**
|
|
331
|
+
* What the confined listener serves a Codex run (AGL-1614), by method and path: Codex's model catalog and its Responses
|
|
332
|
+
* endpoint, of the ChatGPT pool's ChatGPT accounts. Every other method and path -- every `/anthropic/` path,
|
|
333
|
+
* `/openai/v1/messages`, `/responses/compact`, `/memories/*`, `/realtime/*` among them -- and every request that asks to
|
|
334
|
+
* upgrade its connection is refused there before anything is read or routed.
|
|
335
|
+
*/
|
|
336
|
+
const confinedCodexEndpoints: ReadonlySet<string> = new Set(['GET /openai/v1/models', 'POST /openai/v1/responses']);
|
|
337
|
+
/** The session scope of a Codex run's credential (`aglProxyConfinedCodexClient`). */
|
|
338
|
+
const confinedCodexScope = `client:${aglProxyConfinedCodexClient}`;
|
|
327
339
|
const turnStateLimit = 4096;
|
|
328
340
|
const turnStateLifetimeMs = 60 * 60 * 1000;
|
|
329
341
|
const clientVersionPattern = /^\d{1,6}\.\d{1,6}\.\d{1,6}(?:[-+][0-9A-Za-z.-]{1,32})?$/;
|
|
@@ -574,9 +586,11 @@ export const assertInferenceRoutingPolicy = (policyArg: IInferenceRoutingPolicy)
|
|
|
574
586
|
|
|
575
587
|
/**
|
|
576
588
|
* A confined credential is a lease of the Claude or the ChatGPT pool, admitted only by a gateway with a confined listener;
|
|
577
|
-
* `issuedArg` is the policy it was issued with, which a new policy may not move to another pool.
|
|
589
|
+
* `issuedArg` is the policy it was issued with, which a new policy may not move to another pool. A Codex run's
|
|
590
|
+
* (`scopeNameArg` names `aglProxyConfinedCodexClient`) is a lease of the ChatGPT pool's ChatGPT accounts alone, unrestricted,
|
|
591
|
+
* so no request of it reaches an OpenAI API key.
|
|
578
592
|
*/
|
|
579
|
-
const assertConfinedClient = (policyArg: IInferenceRoutingPolicy, nameArg: string | undefined,
|
|
593
|
+
const assertConfinedClient = (policyArg: IInferenceRoutingPolicy, nameArg: string | undefined, scopeNameArg: string | undefined,
|
|
580
594
|
socketPathArg: string | undefined, issuedArg?: IInferenceRoutingPolicy): void => {
|
|
581
595
|
if (socketPathArg === undefined) throw new Error('The gateway has no confined listener.');
|
|
582
596
|
if (nameArg !== undefined || (policyArg.provider !== 'anthropic' && policyArg.provider !== 'openai')) {
|
|
@@ -585,11 +599,18 @@ const assertConfinedClient = (policyArg: IInferenceRoutingPolicy, nameArg: strin
|
|
|
585
599
|
if (issuedArg !== undefined && policyArg.provider !== issuedArg.provider) {
|
|
586
600
|
throw new Error('A confined credential stays on the pool it was issued for.');
|
|
587
601
|
}
|
|
602
|
+
if (scopeNameArg === aglProxyConfinedCodexClient && (policyArg.provider !== 'openai' || policyArg.credential !== 'subscription'
|
|
603
|
+
|| Object.keys(policyArg).length !== 2)) {
|
|
604
|
+
throw new Error('A confined Codex credential is a lease of the ChatGPT pool\'s ChatGPT accounts alone.');
|
|
605
|
+
}
|
|
588
606
|
};
|
|
589
607
|
|
|
608
|
+
/** Whether a client is a confined Codex run's: accepted on the confined listener, its sessions the confined Codex client's. */
|
|
609
|
+
const confinedCodexRun = (clientArg: IClient): boolean => clientArg.route === 'confined' && clientArg.sessionScope === confinedCodexScope;
|
|
610
|
+
|
|
590
611
|
/**
|
|
591
612
|
* Authenticated Responses and Messages endpoints with bounded, cancelable streaming, on a loopback listener and, for
|
|
592
|
-
* confined credentials, a Unix socket that serves Claude Code's endpoints alone.
|
|
613
|
+
* confined credentials, a Unix socket that serves Claude Code's endpoints, or a Codex run Codex's, alone.
|
|
593
614
|
*/
|
|
594
615
|
export class InferenceGateway {
|
|
595
616
|
private readonly clients = new Set<IClient>();
|
|
@@ -672,7 +693,7 @@ export class InferenceGateway {
|
|
|
672
693
|
private async admit(policyArg: IInferenceRoutingPolicy, digestArg: Buffer, scopeNameArg: string | undefined,
|
|
673
694
|
nameArg: string | undefined, routeArg: TInferenceGatewayRoute): Promise<IInferenceGatewayGrant> {
|
|
674
695
|
assertInferenceRoutingPolicy(policyArg);
|
|
675
|
-
if (routeArg === 'confined') assertConfinedClient(policyArg, nameArg, this.options.confinedSocketPath);
|
|
696
|
+
if (routeArg === 'confined') assertConfinedClient(policyArg, nameArg, scopeNameArg, this.options.confinedSocketPath);
|
|
676
697
|
await (this.startTask ??= this.start());
|
|
677
698
|
this.abort.signal.throwIfAborted();
|
|
678
699
|
if (this.clients.size >= 128) throw new Error('The gateway has reached its client limit.');
|
|
@@ -685,7 +706,7 @@ export class InferenceGateway {
|
|
|
685
706
|
this.clients.add(client);
|
|
686
707
|
return { baseUrl: `http://${this.host}`, digest: digestArg.toString('hex'), setPolicy: (nextArg) => {
|
|
687
708
|
assertInferenceRoutingPolicy(nextArg);
|
|
688
|
-
if (routeArg === 'confined') assertConfinedClient(nextArg, nameArg, this.options.confinedSocketPath, client.policy);
|
|
709
|
+
if (routeArg === 'confined') assertConfinedClient(nextArg, nameArg, scopeNameArg, this.options.confinedSocketPath, client.policy);
|
|
689
710
|
client.policy = structuredClone(nextArg);
|
|
690
711
|
}, close: () => {
|
|
691
712
|
this.clients.delete(client);
|
|
@@ -818,17 +839,30 @@ export class InferenceGateway {
|
|
|
818
839
|
let releaseRoute: (() => void) | undefined;
|
|
819
840
|
let protocol: TProtocol | undefined;
|
|
820
841
|
try {
|
|
821
|
-
|
|
842
|
+
const confined = routeArg === 'confined';
|
|
843
|
+
const endpoint = confined ? `${requestArg.method} ${new URL(requestArg.url).pathname}` : '';
|
|
844
|
+
// A refusal on the confined listener before its client is known takes the shape of the API the path names: OpenAI's
|
|
845
|
+
// for an `/openai/` path, which a Codex run asks for, Claude's for any other.
|
|
846
|
+
if (confined) protocol = endpoint.includes(' /openai/') ? undefined : 'claude';
|
|
822
847
|
client = this.authenticate(requestArg, routeArg);
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
848
|
+
const codexRun = confinedCodexRun(client);
|
|
849
|
+
if (confined) protocol = codexRun ? undefined : 'claude';
|
|
850
|
+
// A Codex run is served Codex's two endpoints alone (AGL-1614), as plain HTTP requests: nothing upgrades its
|
|
851
|
+
// connection there, not even to a protocol Codex knows.
|
|
852
|
+
if (codexRun && (!confinedCodexEndpoints.has(endpoint) || requestArg.headers.has('upgrade'))) {
|
|
853
|
+
throw new InferenceRoutingError(404, 'not_found', 'The confined listener serves a Codex run GET /openai/v1/models and '
|
|
854
|
+
+ 'POST /openai/v1/responses alone, without a connection upgrade.');
|
|
855
|
+
}
|
|
856
|
+
// On either pool the confined listener serves a Claude Code run Claude Code's three endpoints alone, as the loopback
|
|
857
|
+
// listener serves Claude Code on that pool; a ChatGPT-pool run never reaches a Responses or OpenAI models endpoint.
|
|
858
|
+
if (confined && !codexRun && !confinedEndpoints.has(endpoint)) {
|
|
826
859
|
throw new InferenceRoutingError(404, 'not_found', 'The confined listener serves GET /anthropic/v1/models, '
|
|
827
860
|
+ 'POST /anthropic/v1/messages and POST /anthropic/v1/messages/count_tokens alone.');
|
|
828
861
|
}
|
|
829
|
-
// From here on a confined request is answered exactly as the loopback listener answers Claude Code
|
|
830
|
-
// errors included; only the refusals above
|
|
831
|
-
|
|
862
|
+
// From here on a confined request is answered exactly as the loopback listener answers Claude Code or Codex on its
|
|
863
|
+
// pool, its errors included; only the refusals above, in Claude's shape for a Claude Code run, and a Codex run's
|
|
864
|
+
// hosted tools below are the confined listener's own.
|
|
865
|
+
if (confined && client.policy.provider !== 'anthropic') protocol = undefined;
|
|
832
866
|
if (this.inFlight >= this.limits.total) throw new InferenceRoutingError(429, 'concurrency_limit', 'The gateway has too many requests in flight.', 1);
|
|
833
867
|
if (client.pending >= this.limits.perClient) throw new InferenceRoutingError(429, 'concurrency_limit', 'This gateway client has too many requests.', 1);
|
|
834
868
|
client.pending += 1;
|
|
@@ -885,6 +919,18 @@ export class InferenceGateway {
|
|
|
885
919
|
if (typeof body.model !== 'string' || !body.model || body.model.length > 256) {
|
|
886
920
|
throw new InferenceRoutingError(400, 'invalid_request', 'A model from /v1/models is required.');
|
|
887
921
|
}
|
|
922
|
+
// A Codex run uses no tool the provider runs (AGL-1614): web search, file search, code interpreter, image generation,
|
|
923
|
+
// remote MCP and every other server tool would reach past the container. Refused before anything is routed, declared
|
|
924
|
+
// or named by `tool_choice` alone, which the route does not leave to the provider to refuse.
|
|
925
|
+
if (codexRun) {
|
|
926
|
+
const hosted = [...inferenceOpenAiServerToolTypes(body), ...inferenceOpenAiServerToolChoiceTypes(body)];
|
|
927
|
+
if (hosted.length) {
|
|
928
|
+
throw new InferenceRoutingError(400, 'hosted_tool_refused', `A confined Codex run uses no hosted tool; this request `
|
|
929
|
+
+ `declares or chooses ${[...new Set(hosted)].slice(0, 8).map((typeArg) => JSON.stringify(refusalText(typeArg, 64))).join(', ')}. `
|
|
930
|
+
+ 'Turn them off in its Codex configuration (web_search = "disabled", features.image_generation = false, '
|
|
931
|
+
+ 'apps and plugins off).');
|
|
932
|
+
}
|
|
933
|
+
}
|
|
888
934
|
const model = body.model;
|
|
889
935
|
const sessionKey = inferenceSessionKey(request.headers, body, client.sessionScope, claude ? 'anthropic' : 'openai');
|
|
890
936
|
if ((this.sessionsInFlight.get(sessionKey) ?? 0) >= this.limits.perSession) {
|
|
@@ -2005,6 +2005,18 @@ export class InferenceRouter {
|
|
|
2005
2005
|
return statuses;
|
|
2006
2006
|
}
|
|
2007
2007
|
|
|
2008
|
+
/**
|
|
2009
|
+
* The newest provider 429 this router saw on the account since it started (epoch milliseconds), or `null`, and until
|
|
2010
|
+
* when the account rests after it as routing judges it on `usageArg` (`cooldownUntil`; 0 when it does not rest): the
|
|
2011
|
+
* proxy's capacity reads both (`proxyPoolCapacity`). Held in memory only, so a restarted proxy starts with none.
|
|
2012
|
+
*/
|
|
2013
|
+
public quotaOf(accountArg: IInferenceAccount,
|
|
2014
|
+
usageArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): { lastAt: number | null; restUntil: number } {
|
|
2015
|
+
const cooldown = this.cooldowns.get(accountArg.id);
|
|
2016
|
+
const until = cooldownUntil(cooldown, accountArg.credential === 'api_key' ? undefined : usageArg);
|
|
2017
|
+
return { lastAt: cooldown?.at ?? null, restUntil: until > this.now() ? until : 0 };
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2008
2020
|
/** Counts one request on an account until its release, which may be called more than once. */
|
|
2009
2021
|
private reserve(idArg: string): () => void {
|
|
2010
2022
|
this.active.set(idArg, (this.active.get(idArg) ?? 0) + 1);
|
|
@@ -15,6 +15,9 @@ import type { IInferenceUsageLedger } from './classes.inferenceusage.js';
|
|
|
15
15
|
import type { TInferenceProvider } from './functions.proxycontract.js';
|
|
16
16
|
import { findAuthorityApiKeyLogin, findAuthorityGatewayLogin, findInferencePool, isAuthorityInstallationId,
|
|
17
17
|
parseAuthorityScope } from '../ts_interfaces/index.js';
|
|
18
|
+
import { proxyCapacityDefaultMinimumHeadroom, proxyCapacityProviders, type IProxyCapacityAnswer,
|
|
19
|
+
type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
20
|
+
import { proxyPoolCapacity } from './functions.proxycapacity.js';
|
|
18
21
|
|
|
19
22
|
export interface IInferenceServiceOptions {
|
|
20
23
|
authorityPaths: IAuthoritySocketPaths;
|
|
@@ -64,6 +67,8 @@ export class InferenceService {
|
|
|
64
67
|
private started = false;
|
|
65
68
|
private baseUrl?: string;
|
|
66
69
|
private stopTask?: Promise<void>;
|
|
70
|
+
/** Since when the router sees this service's requests and their provider 429s (epoch milliseconds): its start. */
|
|
71
|
+
private observingSince = Date.now();
|
|
67
72
|
|
|
68
73
|
constructor(private readonly options: IInferenceServiceOptions) {
|
|
69
74
|
if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65535) {
|
|
@@ -167,6 +172,7 @@ export class InferenceService {
|
|
|
167
172
|
this.started = true;
|
|
168
173
|
try {
|
|
169
174
|
signalArg?.throwIfAborted();
|
|
175
|
+
this.observingSince = Date.now();
|
|
170
176
|
this.baseUrl = await this.gateway.listen();
|
|
171
177
|
signalArg?.throwIfAborted();
|
|
172
178
|
this.authority.start();
|
|
@@ -231,6 +237,27 @@ export class InferenceService {
|
|
|
231
237
|
recentPlacements: recent.map((placementArg) => ({ ...placementArg, at: placementArg.at.toISOString() })) };
|
|
232
238
|
}
|
|
233
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Each asked pool's room for new work (`proxyPoolCapacity`): its accounts judged on the readings a request would route
|
|
242
|
+
* on now, as `status` reads them, with the provider 429s the router saw since this service started. `undefined` while
|
|
243
|
+
* the account service is unavailable, as nothing can be judged then.
|
|
244
|
+
*/
|
|
245
|
+
public async capacity(requestArg: IProxyCapacityRequest, signalArg: AbortSignal): Promise<IProxyCapacityAnswer | undefined> {
|
|
246
|
+
const pool = this.poolAccounts();
|
|
247
|
+
if (!pool) return undefined;
|
|
248
|
+
const readings = new Map(await Promise.all(pool
|
|
249
|
+
.map(async (accountArg) => [accountArg.id, await this.usage.current(accountArg.id, signalArg)] as const)));
|
|
250
|
+
const statuses = this.router.accountStatus(pool, (accountIdArg) => readings.get(accountIdArg));
|
|
251
|
+
const now = Date.now();
|
|
252
|
+
const accounts = pool.map((accountArg, indexArg) => ({ status: statuses[indexArg], usage: readings.get(accountArg.id),
|
|
253
|
+
quota: this.router.quotaOf(accountArg, readings.get(accountArg.id)) }));
|
|
254
|
+
const options = { minHeadroom: requestArg.minHeadroom ?? proxyCapacityDefaultMinimumHeadroom,
|
|
255
|
+
observedSince: this.observingSince, now };
|
|
256
|
+
return { at: new Date(now).toISOString(), observedSince: new Date(this.observingSince).toISOString(),
|
|
257
|
+
pools: (requestArg.provider ? [requestArg.provider] : proxyCapacityProviders)
|
|
258
|
+
.map((providerArg) => proxyPoolCapacity(providerArg, accounts, options)) };
|
|
259
|
+
}
|
|
260
|
+
|
|
234
261
|
public stop(): Promise<void> {
|
|
235
262
|
return this.stopTask ??= (async () => {
|
|
236
263
|
this.ready = false;
|
|
@@ -192,25 +192,58 @@ const openAiClientToolTypes: ReadonlySet<string> = new Set(['function', 'custom'
|
|
|
192
192
|
'computer_use_preview']);
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* tool (`openAiClientToolTypes`, a local `shell`); a type that is no string is named as it reads.
|
|
195
|
+
* Every tool a Responses request declares, in `tools` and in the tools its input adds (`additional_tools` and
|
|
196
|
+
* `tool_search_output` items), a namespace's own tools in its place.
|
|
198
197
|
*/
|
|
199
|
-
|
|
200
|
-
const declared = (toolsArg: unknown):
|
|
201
|
-
|
|
202
|
-
const type = tool.type;
|
|
203
|
-
if (type === 'namespace') return declared(tool.tools);
|
|
204
|
-
if ((typeof type === 'string' && openAiClientToolTypes.has(type))
|
|
205
|
-
|| (type === 'shell' && isRecord(tool.environment) && tool.environment.type === 'local')
|
|
206
|
-
|| (type === 'tool_search' && tool.execution === 'client')) return [];
|
|
207
|
-
return [typeof type === 'string' ? type : String(JSON.stringify(type))];
|
|
208
|
-
});
|
|
198
|
+
const declaredOpenAiTools = (bodyArg: Record<string, unknown>): unknown[] => {
|
|
199
|
+
const declared = (toolsArg: unknown): unknown[] => (Array.isArray(toolsArg) ? toolsArg : [])
|
|
200
|
+
.flatMap((toolArg) => isRecord(toolArg) && toolArg.type === 'namespace' ? declared(toolArg.tools) : [toolArg]);
|
|
209
201
|
const added = (Array.isArray(bodyArg.input) ? bodyArg.input : []).flatMap((itemArg) => isRecord(itemArg)
|
|
210
202
|
&& (itemArg.type === 'additional_tools' || itemArg.type === 'tool_search_output') ? declared(itemArg.tools) : []);
|
|
211
203
|
return [...declared(bodyArg.tools), ...added];
|
|
212
204
|
};
|
|
213
205
|
|
|
206
|
+
/** Whether a declared tool is a client tool (`openAiClientToolTypes`, a local `shell`, a client-run `tool_search`). */
|
|
207
|
+
const isOpenAiClientTool = (toolArg: unknown): boolean => {
|
|
208
|
+
const tool: Record<string, unknown> = isRecord(toolArg) ? toolArg : {};
|
|
209
|
+
const type = tool.type;
|
|
210
|
+
return (typeof type === 'string' && openAiClientToolTypes.has(type))
|
|
211
|
+
|| (type === 'shell' && isRecord(tool.environment) && tool.environment.type === 'local')
|
|
212
|
+
|| (type === 'tool_search' && tool.execution === 'client');
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/** A tool's `type` as a refusal names it: a type that is no string as it reads. */
|
|
216
|
+
const openAiToolTypeText = (toolArg: unknown): string => {
|
|
217
|
+
const type = isRecord(toolArg) ? toolArg.type : undefined;
|
|
218
|
+
return typeof type === 'string' ? type : String(JSON.stringify(type));
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The `type` of every server tool a Responses request declares (`declaredOpenAiTools`): each tool that is no client
|
|
223
|
+
* tool (`isOpenAiClientTool`); a type that is no string is named as it reads.
|
|
224
|
+
*/
|
|
225
|
+
export const inferenceOpenAiServerToolTypes = (bodyArg: Record<string, unknown>): string[] =>
|
|
226
|
+
declaredOpenAiTools(bodyArg).filter((toolArg) => !isOpenAiClientTool(toolArg)).map(openAiToolTypeText);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The `type` of every server tool a Responses request's `tool_choice` names (AGL-1614): an object choice, or each tool
|
|
230
|
+
* of an `allowed_tools` choice, whose type is no client tool's (`openAiClientToolTypes`). A `shell` or `tool_search`
|
|
231
|
+
* choice names the request's declared tool of that type, a client tool's only when the request declares that type and
|
|
232
|
+
* every declared tool of it is a client tool. A string choice (`auto`, `none`, `required`) names no type.
|
|
233
|
+
*/
|
|
234
|
+
export const inferenceOpenAiServerToolChoiceTypes = (bodyArg: Record<string, unknown>): string[] => {
|
|
235
|
+
const choice = bodyArg.tool_choice;
|
|
236
|
+
if (!isRecord(choice)) return [];
|
|
237
|
+
const declared = declaredOpenAiTools(bodyArg);
|
|
238
|
+
const named = choice.type === 'allowed_tools' ? Array.isArray(choice.tools) ? choice.tools : [] : [choice];
|
|
239
|
+
return named.filter((namedArg) => {
|
|
240
|
+
const type = isRecord(namedArg) ? namedArg.type : undefined;
|
|
241
|
+
if (typeof type === 'string' && openAiClientToolTypes.has(type)) return false;
|
|
242
|
+
const ofType = declared.filter((toolArg) => isRecord(toolArg) && toolArg.type === type);
|
|
243
|
+
return !((type === 'shell' || type === 'tool_search') && ofType.length > 0 && ofType.every(isOpenAiClientTool));
|
|
244
|
+
}).map(openAiToolTypeText);
|
|
245
|
+
};
|
|
246
|
+
|
|
214
247
|
/**
|
|
215
248
|
* The service tier a Responses request goes to an OpenAI API key with a spend limit on: the one the client named when it
|
|
216
249
|
* named a tier the price table prices for the model, else Standard (`default`), never `auto`, which a project set to Fast
|
package/ts/classes.mcpclient.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { fleetWorkerErrorCodes, fleetWorkerReadActions, type TFleetWorkerAction, type TFleetWorkerErrorCode, type TFleetWorkerRequest, type TFleetWorkerResponseTo } from '../ts_interfaces/fleetworkers.js';
|
|
2
2
|
import { assertFleetWorkerWireRequest, assertFleetWorkerResponse } from './fleet/functions.workervalidation.js';
|
|
3
3
|
import * as plugins from './plugins.js';
|
|
4
4
|
import { assertWorkerCallerEnrollmentResponse } from './functions.workercallervalidation.js';
|
|
@@ -12,6 +12,7 @@ import { assertSessionFeedWireRequest, assertSessionFeedWireResponse } from './f
|
|
|
12
12
|
import { assertFleetDeployResponse, assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
13
13
|
import type { IFleetDeployOperations, TFleetDeployOperation } from '../ts_interfaces/deployments.js';
|
|
14
14
|
import type { IReq_ControllerMcpSessionFeedAcknowledge, IReq_ControllerMcpSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
15
|
+
import { isProxyCapacityAnswer, type IProxyCapacityAnswer, type IProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
15
16
|
import {
|
|
16
17
|
controllerMcpSessionDetailFields,
|
|
17
18
|
controllerMcpTypedResponseMaximumBytes,
|
|
@@ -110,7 +111,11 @@ export type TControllerMcpClientErrorCode =
|
|
|
110
111
|
| 'MESSAGE_RATE_LIMITED'
|
|
111
112
|
| 'DELIVERY_UNSUPPORTED'
|
|
112
113
|
| 'REQUEST_FAILED'
|
|
113
|
-
| 'OUTCOME_UNKNOWN'
|
|
114
|
+
| 'OUTCOME_UNKNOWN'
|
|
115
|
+
| 'PROXY_UNAVAILABLE'
|
|
116
|
+
| 'PROXY_OUTDATED'
|
|
117
|
+
| 'PROXY_ACCOUNTS_UNAVAILABLE'
|
|
118
|
+
| Uppercase<TFleetWorkerErrorCode>;
|
|
114
119
|
|
|
115
120
|
export class ControllerMcpClientError extends Error {
|
|
116
121
|
public readonly code: TControllerMcpClientErrorCode;
|
|
@@ -279,6 +284,10 @@ const assertResponsePayload = (
|
|
|
279
284
|
if (new Set(models.map(model => model.harnessId)).size !== models.length) throw new Error('invalid');
|
|
280
285
|
return;
|
|
281
286
|
}
|
|
287
|
+
if (methodArg === 'agl.mcp.proxy.capacity') {
|
|
288
|
+
if (!isProxyCapacityAnswer(valueArg)) throw new Error('invalid');
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
282
291
|
if (methodArg === 'agl.mcp.configuration.state') {
|
|
283
292
|
assertControllerMcpExactKeys(valueArg, ['resource', 'projectionRun', 'harnesses', 'history'], ['master', 'projection']);
|
|
284
293
|
if (!controllerMcpValueIsRecord(valueArg.resource) || !controllerMcpValueIsRecord(valueArg.projectionRun)
|
|
@@ -445,6 +454,11 @@ export class ControllerMcpClient {
|
|
|
445
454
|
this.requestTimeoutMs = timeout;
|
|
446
455
|
}
|
|
447
456
|
|
|
457
|
+
/** A pool's room for new work in AGL's inference proxy, or both pools', as the controller asks the proxy for it. */
|
|
458
|
+
public async proxyCapacity(requestArg: IProxyCapacityRequest, signalArg?: AbortSignal): Promise<IProxyCapacityAnswer> {
|
|
459
|
+
return this.dispatchAfterHandshake('agl.mcp.proxy.capacity', requestArg, signalArg, false);
|
|
460
|
+
}
|
|
461
|
+
|
|
448
462
|
public async status(signalArg?: AbortSignal): Promise<IReq_ControllerMcpStatus['response']> {
|
|
449
463
|
const descriptor = await this.readCompatibleDescriptor();
|
|
450
464
|
const status = await this.dispatch(
|
|
@@ -728,10 +742,10 @@ export class ControllerMcpClient {
|
|
|
728
742
|
['create', 'update', 'move', 'comment', 'link', 'unlink', 'ask', 'answer'].includes(methodArg)) as Promise<TTicketResponse<TMethod>>;
|
|
729
743
|
}
|
|
730
744
|
|
|
731
|
-
public async fleetWorker<T extends TFleetWorkerAction
|
|
745
|
+
public async fleetWorker<T extends TFleetWorkerAction, R extends TFleetWorkerRequest<T> & { ownerToken: string } = TFleetWorkerRequest<T> & { ownerToken: string }>(action: T, request: R, signal?: AbortSignal): Promise<TFleetWorkerResponseTo<T, R>> {
|
|
732
746
|
const method = `agl.mcp.fleet.worker.${action}` as const;
|
|
733
747
|
const wireRequest = assertFleetWorkerWireRequest(method, request);
|
|
734
|
-
return this.dispatchAfterHandshake(method, wireRequest as never, signal, !
|
|
748
|
+
return this.dispatchAfterHandshake(method, wireRequest as never, signal, !(fleetWorkerReadActions as readonly string[]).includes(action)) as Promise<TFleetWorkerResponseTo<T, R>>;
|
|
735
749
|
}
|
|
736
750
|
|
|
737
751
|
/** The session feed's rows as the local owner reads them; `state` keeps one group. */
|
|
@@ -986,6 +1000,14 @@ export class ControllerMcpClient {
|
|
|
986
1000
|
if (serverCode === 'agent_messages_disabled') code = 'AGENT_MESSAGES_DISABLED';
|
|
987
1001
|
if (serverCode === 'message_rate_limited') code = 'MESSAGE_RATE_LIMITED';
|
|
988
1002
|
if (serverCode === 'delivery_unsupported') code = 'DELIVERY_UNSUPPORTED';
|
|
1003
|
+
if (methodArg === 'agl.mcp.proxy.capacity') {
|
|
1004
|
+
if (serverCode === 'proxy_unavailable') code = 'PROXY_UNAVAILABLE';
|
|
1005
|
+
if (serverCode === 'proxy_outdated') code = 'PROXY_OUTDATED';
|
|
1006
|
+
if (serverCode === 'proxy_accounts_unavailable') code = 'PROXY_ACCOUNTS_UNAVAILABLE';
|
|
1007
|
+
}
|
|
1008
|
+
if (methodArg.startsWith('agl.mcp.fleet.worker.') && (fleetWorkerErrorCodes as readonly unknown[]).includes(serverCode)) {
|
|
1009
|
+
code = (serverCode as TFleetWorkerErrorCode).toUpperCase() as Uppercase<TFleetWorkerErrorCode>;
|
|
1010
|
+
}
|
|
989
1011
|
}
|
|
990
1012
|
} catch {
|
|
991
1013
|
throw new ControllerMcpClientError('PROTOCOL_MISMATCH', 'The controller response is invalid.');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { controllerMcpFleetWorkerMethods, type TControllerMcpFleetWorkerTypedRequest } from '../ts_interfaces/requests.fleetworkers.js';
|
|
2
|
+
import { fleetWorkerErrorCodes } from '../ts_interfaces/fleetworkers.js';
|
|
2
3
|
import type { TFleetWorkerAction, TFleetWorkerResponse } from '../ts_interfaces/fleetworkers.js';
|
|
3
4
|
import type {
|
|
4
5
|
IReq_ControllerMcpBrowserAction,
|
|
@@ -50,6 +51,7 @@ import {
|
|
|
50
51
|
type IReq_ControllerMcpSessionMessage,
|
|
51
52
|
type IReq_ControllerMcpSessionsList,
|
|
52
53
|
type IReq_ControllerMcpStatus,
|
|
54
|
+
type IReq_ControllerMcpProxyCapacity,
|
|
53
55
|
type IReq_ControllerMcpSettingsGet,
|
|
54
56
|
type IReq_ControllerMcpSettingsUpdate,
|
|
55
57
|
type IReq_ControllerMcpConfigurationState,
|
|
@@ -92,6 +94,9 @@ export interface IControllerMcpPrivateApi {
|
|
|
92
94
|
fleet?: (method: string, request: Record<string, unknown>, signal: AbortSignal) => Promise<IFleetOperation>;
|
|
93
95
|
/** Deploy status, history, a probe now and release state for the local owner (`agl deploy`, `agl release status`). */
|
|
94
96
|
deploy?: (method: TControllerMcpDeployMethod, request: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
|
|
97
|
+
/** A pool's room for new work in AGL's inference proxy, asked of the proxy (AGL-1097); open to every caller. */
|
|
98
|
+
proxyCapacity?: (request: IReq_ControllerMcpProxyCapacity['request'], signal: AbortSignal)
|
|
99
|
+
=> Promise<IReq_ControllerMcpProxyCapacity['response']>;
|
|
95
100
|
/** The session feed for the local owner; each call verifies the owner capability it carries. */
|
|
96
101
|
sessionFeed?: {
|
|
97
102
|
list(request: IReq_ControllerMcpSessionFeedList['request'], signal: AbortSignal): Promise<IReq_ControllerMcpSessionFeedList['response']>;
|
|
@@ -299,6 +304,9 @@ const safeTypedResponseError = (
|
|
|
299
304
|
if (methodArg.startsWith('agl.mcp.deploy.') && (deployErrorCodes as readonly unknown[]).includes(code)) {
|
|
300
305
|
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
301
306
|
}
|
|
307
|
+
if (methodArg.startsWith('agl.mcp.fleet.worker.') && (fleetWorkerErrorCodes as readonly unknown[]).includes(code)) {
|
|
308
|
+
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
309
|
+
}
|
|
302
310
|
if (typeof code === 'string' && /^[a-z0-9_]{1,64}$/.test(code)) {
|
|
303
311
|
const messages: Record<string, string> = {
|
|
304
312
|
...ticketErrorMessages,
|
|
@@ -327,6 +335,9 @@ const safeTypedResponseError = (
|
|
|
327
335
|
sessionfeed_row_not_found: 'The session feed lists no such row; list the feed again.',
|
|
328
336
|
sessionfeed_row_not_failed: 'Only a failed row can be acknowledged.',
|
|
329
337
|
sessionfeed_row_stale: 'The session changed since it was listed; list the feed again.',
|
|
338
|
+
proxy_unavailable: 'The AGL proxy is not running.',
|
|
339
|
+
proxy_outdated: 'The AGL proxy runs an older AGL release and does not answer capacity; restart it onto the installed AGL.',
|
|
340
|
+
proxy_accounts_unavailable: 'The AGL proxy cannot reach its account service, so it cannot judge its pools.',
|
|
330
341
|
};
|
|
331
342
|
const conflict = readTicketRevisionConflict(errorArg.errorData);
|
|
332
343
|
return new plugins.typedrequest.TypedResponseError(
|
|
@@ -680,6 +691,12 @@ export class ControllerMcpHost {
|
|
|
680
691
|
return this.options.api.deploy(method, request as unknown as Record<string, unknown>, tools?.abortSignal ?? new AbortController().signal) as never;
|
|
681
692
|
})));
|
|
682
693
|
}
|
|
694
|
+
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<IReq_ControllerMcpProxyCapacity>(
|
|
695
|
+
'agl.mcp.proxy.capacity', async (requestArg, toolsArg) => run('agl.mcp.proxy.capacity', async () => {
|
|
696
|
+
if (!this.options.api.proxyCapacity) throw new Error('Proxy capacity API is unavailable.');
|
|
697
|
+
return this.options.api.proxyCapacity(requestArg, toolsArg?.abortSignal ?? new AbortController().signal);
|
|
698
|
+
}),
|
|
699
|
+
));
|
|
683
700
|
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<IReq_ControllerMcpSessionFeedList>(
|
|
684
701
|
'agl.mcp.sessionfeed.list', async (requestArg, toolsArg) => run('agl.mcp.sessionfeed.list', async () => {
|
|
685
702
|
if (!this.options.api.sessionFeed) throw new Error('Session feed API is unavailable.');
|
package/ts/classes.mcptools.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { fleetWorkerToolDefinitions } from './functions.mcpfleetworkertools.js';
|
|
1
|
+
import { fleetWorkerToolDefinitions, waitForFleetWorkerJob } from './functions.mcpfleetworkertools.js';
|
|
2
2
|
import { assertControllerMcpWorkspaceRequest, assertControllerMcpWorkspaceResponse } from './classes.mcpvalidation.js';
|
|
3
3
|
import type { TControllerMcpWorkspaceMethod } from '../ts_interfaces/mcpworkspacerequests.js';
|
|
4
|
+
import type { TFleetWorkerRequest } from '../ts_interfaces/fleetworkers.js';
|
|
4
5
|
import * as plugins from './mcp.plugins.js';
|
|
5
6
|
import {
|
|
6
7
|
controllerAgentMessageMaxTextBytes,
|
|
@@ -32,6 +33,7 @@ import { assertControllerMcpJobRequest } from './functions.jobvalidation.js';
|
|
|
32
33
|
export const aglMcpToolNames = [
|
|
33
34
|
workerCallerEnrollmentToolName,
|
|
34
35
|
'controller_status',
|
|
36
|
+
'proxy_capacity',
|
|
35
37
|
'projects_list',
|
|
36
38
|
'sessions_list',
|
|
37
39
|
'session_read',
|
|
@@ -89,7 +91,9 @@ export const aglMcpToolNames = [
|
|
|
89
91
|
'fleet_worker_refresh',
|
|
90
92
|
'fleet_worker_move',
|
|
91
93
|
'fleet_worker_list',
|
|
94
|
+
'fleet_worker_get',
|
|
92
95
|
'fleet_worker_status',
|
|
96
|
+
'fleet_worker_job_wait',
|
|
93
97
|
'fleet_watch',
|
|
94
98
|
'fleet_worker_native_message',
|
|
95
99
|
'deploy_status',
|
|
@@ -129,7 +133,7 @@ export interface IAglMcpToolsOptions {
|
|
|
129
133
|
| 'messageSession'
|
|
130
134
|
| 'readSessionScratchpad'
|
|
131
135
|
| 'updateSessionScratchpad'
|
|
132
|
-
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy'>>;
|
|
136
|
+
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy' | 'proxyCapacity'>>;
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
const maximumIdentifierBytes = 1024;
|
|
@@ -294,12 +298,20 @@ const safeClientMessages: Record<ControllerMcpClientError['code'], string> = {
|
|
|
294
298
|
JOB_CWD_FORBIDDEN: 'cwd must be an existing directory inside the project, reached without symbolic links.',
|
|
295
299
|
JOB_LOG_UNAVAILABLE: 'The job log no longer exists.',
|
|
296
300
|
JOB_OFFSET_INVALID: 'fromOffset lies beyond the end of the job log; read job_status for its size.',
|
|
301
|
+
JOB_UNAVAILABLE: 'The controller holds no such fleet operation job of this owner: jobs are transient and end with a controller restart or eviction. The job did not fail by this; read the worker with fleet_worker_get.',
|
|
302
|
+
WORKER_NOT_FOUND: 'This owner has no fleet worker of that name or id. Use fleet_worker_list.',
|
|
303
|
+
LIST_CURSOR_MISMATCH: 'The cursor pages another filter (archived, ticketKey, state, harness); repeat that filter or list again without cursor.',
|
|
304
|
+
LIST_CURSOR_STALE: 'The cursor continues after a worker this owner no longer holds as it was; list again without cursor.',
|
|
305
|
+
LIST_CURSOR_INVALID: 'The cursor is not the nextCursor of a fleet_worker_list summary page; list again without cursor.',
|
|
297
306
|
REQUEST_FAILED: 'The private AGL controller request failed.',
|
|
298
307
|
TURN_ENDED: 'The turn the message was to steer has ended; nothing was sent. Read the task before sending again.',
|
|
299
308
|
AGENT_MESSAGES_DISABLED: 'The owner does not accept agent messages for this project.',
|
|
300
309
|
MESSAGE_RATE_LIMITED: 'Too many messages to this task; wait at least a minute before sending another.',
|
|
301
310
|
DELIVERY_UNSUPPORTED: 'The task cannot take this delivery: OpenCode cannot be steered, expectedTurnId applies only to a Codex steer, and steering a turn another Codex client runs requires expectedTurnId.',
|
|
302
311
|
OUTCOME_UNKNOWN: 'The operation outcome is unknown; inspect current state before acting again.',
|
|
312
|
+
PROXY_UNAVAILABLE: 'The AGL inference proxy is not running; its owner starts it with agl proxy service start.',
|
|
313
|
+
PROXY_OUTDATED: 'The AGL inference proxy runs an older AGL release and does not answer capacity; its owner restarts it onto the installed AGL with agl proxy service stop, then agl proxy service start.',
|
|
314
|
+
PROXY_ACCOUNTS_UNAVAILABLE: 'The AGL inference proxy cannot reach its account service, so it cannot judge its pools now.',
|
|
303
315
|
};
|
|
304
316
|
|
|
305
317
|
const serializeToolResult = (
|
|
@@ -362,7 +374,7 @@ export class AglMcpTools {
|
|
|
362
374
|
| 'messageSession'
|
|
363
375
|
| 'readSessionScratchpad'
|
|
364
376
|
| 'updateSessionScratchpad'
|
|
365
|
-
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy'>>;
|
|
377
|
+
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy' | 'proxyCapacity'>>;
|
|
366
378
|
private readonly withFleetOwner: <T>(operation: (token: string) => Promise<T>) => Promise<T>;
|
|
367
379
|
private readonly onControllerUpgraded?: IAglMcpToolsOptions['onControllerUpgraded'];
|
|
368
380
|
private readonly workerCaller?: McpWorkerCaller;
|
|
@@ -415,6 +427,30 @@ export class AglMcpTools {
|
|
|
415
427
|
async () => this.client.status(extra.signal),
|
|
416
428
|
),
|
|
417
429
|
));
|
|
430
|
+
registeredTools.push(serverArg.registerTool(
|
|
431
|
+
'proxy_capacity',
|
|
432
|
+
{
|
|
433
|
+
title: 'Read the inference proxy capacity',
|
|
434
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
|
|
435
|
+
description: "Read a pool's room for new work in AGL's inference proxy, as agl proxy capacity --json answers it: "
|
|
436
|
+
+ 'provider anthropic (Claude accounts) or openai (ChatGPT accounts), both when omitted. Its members are its '
|
|
437
|
+
+ 'subscription sign-ins that have not lapsed on a counted plan (Claude: max; ChatGPT: every plan but free); '
|
|
438
|
+
+ "room is the headroom they add now, summed (0 for one that takes no work now). Each member, by account id, names "
|
|
439
|
+
+ 'its plan, state, binding window and growsAt, when its headroom next grows. verdict is open when room reaches '
|
|
440
|
+
+ 'minHeadroom (15 unless given) and no provider 429 hit a member within five minutes; otherwise wait with '
|
|
441
|
+
+ 'reason room, provider-429 or quiet-unobserved and until/seconds, both null when no moment is foreseen. It '
|
|
442
|
+
+ 'does not wait: ask again after verdict.seconds.',
|
|
443
|
+
inputSchema: plugins.z.object({
|
|
444
|
+
provider: plugins.z.enum(['anthropic', 'openai']).optional(),
|
|
445
|
+
minHeadroom: plugins.z.number().int().min(0).max(Number.MAX_SAFE_INTEGER).optional(),
|
|
446
|
+
}).strict(),
|
|
447
|
+
},
|
|
448
|
+
async (args, extra) => this.runToolCall(extra, async () => {
|
|
449
|
+
if (!this.client.proxyCapacity) throw new Error('Proxy capacity API is unavailable.');
|
|
450
|
+
return this.client.proxyCapacity({ ...(args.provider === undefined ? {} : { provider: args.provider }),
|
|
451
|
+
...(args.minHeadroom === undefined ? {} : { minHeadroom: args.minHeadroom }) }, extra.signal);
|
|
452
|
+
}),
|
|
453
|
+
));
|
|
418
454
|
registeredTools.push(serverArg.registerTool(
|
|
419
455
|
'projects_list',
|
|
420
456
|
{
|
|
@@ -651,8 +687,14 @@ export class AglMcpTools {
|
|
|
651
687
|
description: definition.description, inputSchema: definition.inputSchema,
|
|
652
688
|
annotations: { readOnlyHint: definition.readOnly, destructiveHint: !definition.readOnly, openWorldHint: true },
|
|
653
689
|
}, async (input, extra) => this.runToolCall(extra, async () => this.withFleetOwner(async (ownerToken) => {
|
|
654
|
-
|
|
655
|
-
|
|
690
|
+
const client = this.client;
|
|
691
|
+
if (!client.fleetWorker) throw new Error('Fleet worker API is unavailable.');
|
|
692
|
+
if (definition.action === 'job-wait') {
|
|
693
|
+
// One private request is bounded by the private request timeout; the wait runs in slices.
|
|
694
|
+
const { id, timeoutMs } = input as TFleetWorkerRequest<'job-wait'>;
|
|
695
|
+
return waitForFleetWorkerJob((sliceMs) => client.fleetWorker!('job-wait', { id, timeoutMs: sliceMs, ownerToken }, extra.signal), timeoutMs);
|
|
696
|
+
}
|
|
697
|
+
return client.fleetWorker(definition.action, { ...input as Record<string, unknown>, ownerToken } as never, extra.signal);
|
|
656
698
|
}))));
|
|
657
699
|
}
|
|
658
700
|
}
|
|
@@ -28,6 +28,7 @@ import { assertMcpTicketRequest } from './functions.ticketvalidation.js';
|
|
|
28
28
|
import { assertFleetWireRequest } from './fleet/functions.validation.js';
|
|
29
29
|
import { assertSessionFeedWireRequest } from './functions.sessionfeedvalidation.js';
|
|
30
30
|
import { assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
31
|
+
import { isProxyCapacityRequest } from '../ts_interfaces/proxycapacity.js';
|
|
31
32
|
|
|
32
33
|
const maximumIdBytes = 1024;
|
|
33
34
|
const maximumModelPartBytes = 512;
|
|
@@ -144,6 +145,10 @@ const assertMethodRequest = (
|
|
|
144
145
|
return assertSessionFeedWireRequest(methodArg, requestArg);
|
|
145
146
|
}
|
|
146
147
|
if (methodArg.startsWith('agl.mcp.deploy.')) return assertFleetDeployWireRequest(methodArg, requestArg);
|
|
148
|
+
if (methodArg === 'agl.mcp.proxy.capacity') {
|
|
149
|
+
if (!isProxyCapacityRequest(requestArg)) throw new Error('Invalid private controller request.');
|
|
150
|
+
return requestArg;
|
|
151
|
+
}
|
|
147
152
|
if (methodArg.startsWith('agl.mcp.configuration.')) {
|
|
148
153
|
// The authority validates the master document itself; this admits the request's shape.
|
|
149
154
|
const required: Partial<Record<TControllerMcpMethod, string[]>> = {
|
|
@@ -3881,6 +3881,8 @@ export class OpenCodeClientAdapter implements IOpenCodeSessionIdentitySnapshotCa
|
|
|
3881
3881
|
messagePage,
|
|
3882
3882
|
permissions,
|
|
3883
3883
|
questions,
|
|
3884
|
+
// OpenCode hands AGL no MCP elicitations.
|
|
3885
|
+
elicitations: [],
|
|
3884
3886
|
todos,
|
|
3885
3887
|
...(model ? { model } : {}),
|
|
3886
3888
|
...(effort ? { effort } : {}),
|