agl 43.1.0 → 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 +12 -0
- package/dist_serve/bundle.js +5329 -5116
- 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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +325 -1
- package/dist_ts/aglapi/interfaces.d.ts +3 -0
- package/dist_ts/aglapi/interfaces.js +2 -1
- package/dist_ts/classes.authmodels.js +17 -4
- package/dist_ts/classes.authstore.js +16 -2
- package/dist_ts/classes.cli.d.ts +4 -2
- package/dist_ts/classes.cli.js +6 -3
- package/dist_ts/classes.controller.d.ts +10 -0
- package/dist_ts/classes.controller.js +119 -4
- 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.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.mcpclient.d.ts +4 -1
- package/dist_ts/classes.mcpclient.js +19 -1
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -1
- package/dist_ts/classes.mcpcontrollerhost.js +9 -1
- package/dist_ts/classes.mcptools.d.ts +3 -3
- package/dist_ts/classes.mcptools.js +26 -1
- package/dist_ts/classes.mcpvalidation.js +7 -1
- package/dist_ts/classes.proxycontrol.d.ts +11 -0
- package/dist_ts/classes.proxycontrol.js +7 -1
- package/dist_ts/classes.proxycontrolclient.d.ts +17 -0
- package/dist_ts/classes.proxycontrolclient.js +35 -1
- package/dist_ts/classes.proxydaemon.js +8 -1
- package/dist_ts/classes.proxymonitor.d.ts +7 -0
- package/dist_ts/classes.proxymonitor.js +13 -1
- package/dist_ts/classes.trustedproxysecrets.d.ts +2 -0
- package/dist_ts/classes.trustedproxysecrets.js +5 -1
- package/dist_ts/functions.controllermanagementsurface.d.ts +4 -0
- package/dist_ts/functions.controllermanagementsurface.js +15 -1
- 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.js +30 -1
- package/dist_ts/functions.inferencecliarguments.d.ts +8 -2
- package/dist_ts/functions.inferencecliarguments.js +31 -3
- 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.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 +7 -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/gateway.d.ts +151 -0
- package/dist_ts_interfaces/gateway.js +66 -0
- package/dist_ts_interfaces/index.d.ts +2 -0
- package/dist_ts_interfaces/index.js +3 -1
- package/dist_ts_interfaces/management.d.ts +4 -4
- package/dist_ts_interfaces/management.js +3 -2
- package/dist_ts_interfaces/mcprequests.d.ts +14 -2
- package/dist_ts_interfaces/mcprequests.js +2 -1
- package/dist_ts_interfaces/proxycapacity.d.ts +99 -0
- package/dist_ts_interfaces/proxycapacity.js +74 -0
- package/package.json +4 -3
- package/readme.md +79 -5
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +324 -0
- package/ts/aglapi/interfaces.ts +1 -0
- package/ts/classes.authmodels.ts +22 -3
- package/ts/classes.authstore.ts +15 -1
- package/ts/classes.cli.ts +7 -3
- package/ts/classes.controller.ts +134 -3
- package/ts/classes.controllermanagement.ts +40 -7
- package/ts/classes.gatewayclient.ts +401 -0
- package/ts/classes.gatewayclientstore.ts +272 -0
- package/ts/classes.inferencerouter.ts +12 -0
- package/ts/classes.inferenceservice.ts +27 -0
- package/ts/classes.mcpclient.ts +18 -0
- package/ts/classes.mcpcontrollerhost.ts +13 -0
- package/ts/classes.mcptools.ts +30 -2
- package/ts/classes.mcpvalidation.ts +5 -0
- package/ts/classes.proxycontrol.ts +16 -0
- package/ts/classes.proxycontrolclient.ts +30 -0
- package/ts/classes.proxydaemon.ts +8 -0
- package/ts/classes.proxymonitor.ts +12 -0
- package/ts/classes.trustedproxysecrets.ts +5 -0
- package/ts/functions.controllermanagementsurface.ts +15 -0
- package/ts/functions.gatewaycli.ts +436 -0
- package/ts/functions.gatewayroute.ts +429 -0
- package/ts/functions.inferencecli.ts +24 -0
- package/ts/functions.inferencecliarguments.ts +30 -4
- package/ts/functions.proxycapacity.ts +191 -0
- package/ts/functions.proxycapacitycli.ts +104 -0
- package/ts/functions.remotecli.ts +56 -20
- package/ts/interfaces.auth.ts +28 -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/gateway.ts +242 -0
- package/ts_interfaces/index.ts +2 -0
- package/ts_interfaces/management.ts +6 -4
- package/ts_interfaces/mcprequests.ts +18 -0
- package/ts_interfaces/proxycapacity.ts +162 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.browserpresentation.ts +13 -5
- 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.flexlimitstrip.ts +21 -70
- package/ts_web/elements.harnesscontrollerapp.ts +91 -185
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type { IControllerGatewayDns, IControllerGatewayProblem, TControllerGatewayProblemCode } from '../ts_interfaces/index.js';
|
|
3
|
+
|
|
4
|
+
type IGatewayCapabilities = plugins.servezoneInterfaces.data.IGatewayCapabilities;
|
|
5
|
+
type IGatewayClientOwnership = plugins.servezoneInterfaces.data.IGatewayClientOwnership;
|
|
6
|
+
type IGatewayClientProvisioningSpec = plugins.servezoneInterfaces.data.IGatewayClientProvisioningSpec;
|
|
7
|
+
type IGatewayClientRoute = plugins.servezoneInterfaces.data.IGatewayClientRoute;
|
|
8
|
+
type IGatewayRouteSyncResult = plugins.servezoneInterfaces.data.IGatewayRouteSyncResult;
|
|
9
|
+
type IGatewayTokenCapabilities = plugins.servezoneInterfaces.data.IGatewayTokenCapabilities;
|
|
10
|
+
type IReq_GetGatewayClientContext = plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayClientContext;
|
|
11
|
+
type IReq_GetGatewayClientRoutes = plugins.servezoneInterfaces.requests.gateway.IReq_GetGatewayClientRoutes;
|
|
12
|
+
type IReq_SyncGatewayClientRoute = plugins.servezoneInterfaces.requests.gateway.IReq_SyncGatewayClientRoute;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* AGL's side of the gateway-client protocol of a dcrouter (`@serve.zone/interfaces` `requests.gateway`, served by
|
|
16
|
+
* dcrouter's `GatewayClientHandler`): the route AGL keeps for its own public hostname, the policy it provisions for
|
|
17
|
+
* itself, and how it reads the gateway's answers. Every request carries the credential as `apiToken` and is sent with
|
|
18
|
+
* no TypedRequest hooks, so no hook ever sees it.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** The gateway's source profile AGL's route is bound to, by name on every sync: private networks only. */
|
|
22
|
+
export const gatewayLocalNetworkSourceProfile = 'LOCAL NETWORK';
|
|
23
|
+
|
|
24
|
+
/** The gateway-client type AGL registers as. */
|
|
25
|
+
export const gatewayClientType = 'custom';
|
|
26
|
+
|
|
27
|
+
/** The request header the route sets with the trusted-proxy secret, which the controller's admission checks. */
|
|
28
|
+
export const gatewayRouteSecretHeader = 'x-harness-controller-proxy-secret';
|
|
29
|
+
|
|
30
|
+
/** What the credential must allow: list its routes (stale ones are deleted), write them, and reconcile their DNS. */
|
|
31
|
+
export const gatewayRequiredTokenCapabilities = ['readRoutes', 'syncRoutes', 'syncDnsRecords'] as const satisfies
|
|
32
|
+
ReadonlyArray<keyof IGatewayTokenCapabilities>;
|
|
33
|
+
|
|
34
|
+
/** How long one gateway request may take; DNS reconciliation runs inside a route sync. */
|
|
35
|
+
export const gatewayRequestTimeoutMs = 60_000;
|
|
36
|
+
|
|
37
|
+
/** The route AGL keeps on its gateway: one per controller, for the hostname of its public origin. */
|
|
38
|
+
export interface IGatewayRouteSpec {
|
|
39
|
+
gatewayClientId: string;
|
|
40
|
+
/** `controller-<port>`. */
|
|
41
|
+
appId: string;
|
|
42
|
+
hostname: string;
|
|
43
|
+
targetHost: string;
|
|
44
|
+
targetPort: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** `controller-<port>`: the app of a controller within its gateway client. */
|
|
48
|
+
export const gatewayAppId = (portArg: number): string => `controller-${portArg}`;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The gateway client a controller is: unique per installation and port, so two controllers never share one (a
|
|
52
|
+
* finalized credential revokes every older credential of its client), and stable across restarts and `agl remote set`.
|
|
53
|
+
* Derived from the controller database's issuer id, lowercase, so the gateway keeps it as it is.
|
|
54
|
+
*/
|
|
55
|
+
export const gatewayClientIdFor = (issuerIdArg: string, portArg: number): string => (
|
|
56
|
+
`agl-${plugins.crypto.createHash('sha256').update(issuerIdArg, 'utf8').digest('hex').slice(0, 12)}-${portArg}`
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/** The key the gateway files the route under (dcrouter's `externalKey`), which an admin finds it by. */
|
|
60
|
+
export const gatewayRouteKey = (specArg: Pick<IGatewayRouteSpec, 'gatewayClientId' | 'appId' | 'hostname'>): string => (
|
|
61
|
+
`${gatewayClientType}:${specArg.gatewayClientId}:${specArg.appId}:${specArg.hostname}`
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/** Whether a host is this machine's loopback: `localhost`, 127.0.0.0/8 or `::1` (a URL's hostname without its brackets). */
|
|
65
|
+
export const isLoopbackHost = (hostArg: string): boolean => (
|
|
66
|
+
hostArg === 'localhost' || hostArg === '::1' || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/u.test(hostArg)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Why a gateway URL may not carry a credential, or `undefined` when it may: every request sends the gateway client's
|
|
71
|
+
* credential (an admin token at enrolment), so only `https` qualifies, and `http` only to a gateway on loopback.
|
|
72
|
+
*/
|
|
73
|
+
const insecureGatewayUrlRefusal = (valueArg: string): string | undefined => {
|
|
74
|
+
let url: URL | undefined;
|
|
75
|
+
try { url = new URL(valueArg); } catch { url = undefined; }
|
|
76
|
+
if (url && (url.protocol === 'https:' || (url.protocol === 'http:' && isLoopbackHost(url.hostname.replace(/^\[(.*)\]$/u, '$1'))))) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return `The gateway URL ${JSON.stringify(valueArg.slice(0, 256))} must use https: every request carries a gateway `
|
|
80
|
+
+ 'credential, so plain http is allowed only for a gateway on loopback (127.0.0.0/8, ::1 or localhost).';
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A gateway's API base URL: `https` (`http` only on loopback), no credentials, query or fragment, no trailing slash.
|
|
85
|
+
* Requests go to `<url>/typedrequest`.
|
|
86
|
+
*/
|
|
87
|
+
export const normalizeGatewayUrl = (valueArg: string): string => {
|
|
88
|
+
const refusal = `The gateway URL ${JSON.stringify(valueArg.slice(0, 256))} must be an http or https URL without `
|
|
89
|
+
+ 'credentials, query or fragment, such as https://gateway.example.com:3000.';
|
|
90
|
+
let url: URL;
|
|
91
|
+
try { url = new URL(valueArg); } catch { throw new Error(refusal); }
|
|
92
|
+
if ((url.protocol !== 'https:' && url.protocol !== 'http:') || url.username || url.password || url.search || url.hash
|
|
93
|
+
|| valueArg.length > 2048) throw new Error(refusal);
|
|
94
|
+
const insecure = insecureGatewayUrlRefusal(valueArg);
|
|
95
|
+
if (insecure) throw new Error(insecure);
|
|
96
|
+
return `${url.origin}${url.pathname.replace(/\/+$/u, '')}`;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** A route target: an IP address or a lowercase hostname of two or more labels. */
|
|
100
|
+
export const normalizeGatewayTargetHost = (valueArg: string): string => {
|
|
101
|
+
const value = valueArg.trim().toLowerCase();
|
|
102
|
+
if (plugins.net.isIP(value) || plugins.servezoneInterfaces.data.isGatewayClientHostname(value)) return value;
|
|
103
|
+
throw new Error(`The target host ${JSON.stringify(valueArg.slice(0, 256))} must be an IP address or a fully `
|
|
104
|
+
+ 'qualified hostname the gateway reaches this host by.');
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** The policy AGL provisions for its own gateway client: its hostname, its target and nothing more. */
|
|
108
|
+
export const gatewayClientProvisioningSpec = (specArg: IGatewayRouteSpec): IGatewayClientProvisioningSpec => ({
|
|
109
|
+
id: specArg.gatewayClientId,
|
|
110
|
+
type: gatewayClientType,
|
|
111
|
+
name: `AGL ${specArg.appId} (${specArg.hostname})`,
|
|
112
|
+
description: 'The route of an AGL controller to itself, provisioned by `agl remote gateway enrol`.',
|
|
113
|
+
hostnamePatterns: [specArg.hostname],
|
|
114
|
+
allowedRouteTargets: [{ host: specArg.targetHost, ports: [specArg.targetPort] }],
|
|
115
|
+
allowedDnsRecordAddresses: [],
|
|
116
|
+
capabilities: { readRoutes: true, syncRoutes: true, syncDnsRecords: true },
|
|
117
|
+
enabled: true,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const gatewayRouteOwnership = (specArg: IGatewayRouteSpec): IGatewayClientOwnership => ({
|
|
121
|
+
gatewayClientType,
|
|
122
|
+
gatewayClientId: specArg.gatewayClientId,
|
|
123
|
+
appId: specArg.appId,
|
|
124
|
+
hostname: specArg.hostname,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The request headers the route sets: the trusted-proxy secret, which replaces every copy a client sent. Checked
|
|
129
|
+
* with the contract's own validator, whose refusals name the field and never the value.
|
|
130
|
+
*/
|
|
131
|
+
export const gatewayRouteRequestHeaders = (routeSecretArg: string): Record<string, string> => {
|
|
132
|
+
const headers = { [gatewayRouteSecretHeader]: routeSecretArg };
|
|
133
|
+
const errors = plugins.servezoneInterfaces.data.validateGatewayRouteRequestHeaders(headers);
|
|
134
|
+
if (errors.length > 0) {
|
|
135
|
+
throw new GatewaySyncProblemError(problem('route_refused', `The route's request headers are invalid: ${errors.join('; ')}.`));
|
|
136
|
+
}
|
|
137
|
+
return headers;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The complete sync of AGL's route. Every field is sent on every sync, because the gateway fills an omitted one from
|
|
142
|
+
* the route it stored or a default (an omitted source profile is STANDARD, an omitted `remoteIngress` keeps an
|
|
143
|
+
* export to the edge, and a sync without `requestHeaders` sets none): TLS ends at the gateway with its own
|
|
144
|
+
* certificate, the gateway sets the trusted-proxy secret on every request and WebSocket upgrade it forwards,
|
|
145
|
+
* WebSockets pass, the route is reachable directly at the hub and over its VPN from private networks only
|
|
146
|
+
* (`LOCAL NETWORK`), never through RemoteIngress, and its DNS record is the gateway's own, unproxied.
|
|
147
|
+
*/
|
|
148
|
+
export const gatewayRouteSyncRequest = (
|
|
149
|
+
apiTokenArg: string,
|
|
150
|
+
specArg: IGatewayRouteSpec,
|
|
151
|
+
routeSecretArg: string,
|
|
152
|
+
): IReq_SyncGatewayClientRoute['request'] => ({
|
|
153
|
+
apiToken: apiTokenArg,
|
|
154
|
+
ownership: gatewayRouteOwnership(specArg),
|
|
155
|
+
route: {
|
|
156
|
+
name: specArg.gatewayClientId,
|
|
157
|
+
match: { ports: [443], domains: [specArg.hostname] },
|
|
158
|
+
action: {
|
|
159
|
+
type: 'forward',
|
|
160
|
+
targets: [{ host: specArg.targetHost, port: specArg.targetPort }],
|
|
161
|
+
tls: { mode: 'terminate', certificate: 'auto' },
|
|
162
|
+
websocket: { enabled: true },
|
|
163
|
+
requestHeaders: gatewayRouteRequestHeaders(routeSecretArg),
|
|
164
|
+
},
|
|
165
|
+
ingress: { directHub: true, smartVpn: true },
|
|
166
|
+
remoteIngress: { enabled: false },
|
|
167
|
+
},
|
|
168
|
+
enabled: true,
|
|
169
|
+
sourceProfileRef: gatewayLocalNetworkSourceProfile,
|
|
170
|
+
dnsMode: 'reconcile',
|
|
171
|
+
dnsProxied: false,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Why the route cannot carry the trusted-proxy secret on this gateway, or `undefined` when it can. AGL never writes
|
|
176
|
+
* a route without it: the controller refuses every request off loopback that lacks the secret, and a gateway built
|
|
177
|
+
* before `requestHeaders` refuses a route that carries them, so the route goes only to a gateway that announces
|
|
178
|
+
* `routes.requestHeaders`.
|
|
179
|
+
*/
|
|
180
|
+
export const gatewayRouteHeaderRefusal = (capabilitiesArg: IGatewayCapabilities): IControllerGatewayProblem | undefined => (
|
|
181
|
+
capabilitiesArg.routes.requestHeaders === true ? undefined : problem('request_headers_unsupported', 'The gateway lacks '
|
|
182
|
+
+ 'routes.requestHeaders (dcrouter 34.5.0 or later): waiting for it. Its route cannot carry the trusted-proxy secret, and '
|
|
183
|
+
+ 'AGL writes no route without it.')
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Reads the route back after a sync: it must set the trusted-proxy secret header (`requestHeaderNames`) and be bound
|
|
188
|
+
* to `LOCAL NETWORK` when the gateway names the profile (`sourceProfileName`, matched as the gateway matches it:
|
|
189
|
+
* case-insensitively). A gateway that does not name it (before dcrouter 34.5.0) leaves the binding unverified.
|
|
190
|
+
*/
|
|
191
|
+
export const gatewayRouteReadBack = (
|
|
192
|
+
routesArg: readonly IGatewayClientRoute[],
|
|
193
|
+
specArg: Pick<IGatewayRouteSpec, 'appId' | 'hostname'>,
|
|
194
|
+
): { problem: IControllerGatewayProblem } | { problem?: undefined; sourceProfileVerified: boolean } => {
|
|
195
|
+
const route = routesArg.find((routeArg) => routeArg.ownership.appId === specArg.appId
|
|
196
|
+
&& routeArg.ownership.hostname === specArg.hostname && routeArg.ownership.routeRef === undefined);
|
|
197
|
+
if (!route) return { problem: problem('gateway_error', 'The gateway does not list the route it just wrote.') };
|
|
198
|
+
if (!route.requestHeaderNames?.includes(gatewayRouteSecretHeader)) {
|
|
199
|
+
return { problem: problem('route_refused', 'The gateway does not set the trusted-proxy secret header on the route '
|
|
200
|
+
+ 'it wrote (its requestHeaderNames lack it).') };
|
|
201
|
+
}
|
|
202
|
+
if (route.sourceProfileName === undefined) return { sourceProfileVerified: false };
|
|
203
|
+
if (route.sourceProfileName.trim().toLowerCase() !== gatewayLocalNetworkSourceProfile.toLowerCase()) {
|
|
204
|
+
return { problem: problem('route_refused', `The gateway bound the route to the source profile `
|
|
205
|
+
+ `${JSON.stringify(route.sourceProfileName.slice(0, 128))}, not ${gatewayLocalNetworkSourceProfile}.`) };
|
|
206
|
+
}
|
|
207
|
+
return { sourceProfileVerified: true };
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** A problem that ends a sync, raised from the steps of a sync and read back with `gatewayProblemOf`. */
|
|
211
|
+
export class GatewaySyncProblemError extends Error {
|
|
212
|
+
constructor(public readonly problem: IControllerGatewayProblem) {
|
|
213
|
+
super(problem.message);
|
|
214
|
+
this.name = 'GatewaySyncProblemError';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const problem = (codeArg: TControllerGatewayProblemCode, messageArg: string): IControllerGatewayProblem => ({
|
|
219
|
+
code: codeArg,
|
|
220
|
+
message: messageArg.length <= 4096 ? messageArg : `${messageArg.slice(0, 4093)}...`,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const enrolAgain = 'Enrol again with `agl remote gateway enrol`.';
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The gateway's refusals by their text (dcrouter's `GatewayClientHandler`, `requireGatewayMachineAuth` and
|
|
227
|
+
* `requireOpsAuth`, 34.4.0): the credential ones, which a later sync cannot lift, and the route's own. Any other
|
|
228
|
+
* refusal is the gateway's own state and is retried.
|
|
229
|
+
*/
|
|
230
|
+
const credentialRefusals: ReadonlyArray<[RegExp, TControllerGatewayProblemCode, string]> = [
|
|
231
|
+
[/policy generation is stale/u, 'credential_stale', 'An admin changed this gateway client\'s policy, which invalidates its credential.'],
|
|
232
|
+
[/awaiting finalization/u, 'finalize_pending', 'The gateway has not confirmed this credential.'],
|
|
233
|
+
[/^(?:unauthorized|insufficient scope|admin api token required|admin identity required|testing api required)$/iu,
|
|
234
|
+
'credential_invalid', 'The gateway does not accept the credential: it is unknown, revoked or expired.'],
|
|
235
|
+
[/^gateway client is missing or disabled$/u, 'credential_invalid', 'The gateway client is missing or disabled.'],
|
|
236
|
+
[/^gateway-client credential (?:required|binding is incomplete|binding is inconsistent|type does not match live policy|lifecycle is invalid)$/u,
|
|
237
|
+
'credential_invalid', 'The gateway does not accept the credential as this gateway client\'s.'],
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
const routeRefusals: readonly RegExp[] = [
|
|
241
|
+
/^invalid gateway route: /u,
|
|
242
|
+
/^invalid hostname: /u,
|
|
243
|
+
/^invalid route target host: /u,
|
|
244
|
+
/^hostname is outside token policy$/u,
|
|
245
|
+
/^route target is outside token policy: /u,
|
|
246
|
+
/^gateway client token has no allowed route targets$/u,
|
|
247
|
+
/^route domains must match ownership hostname$/u,
|
|
248
|
+
/^hostname ownership requires exactly one route domain$/u,
|
|
249
|
+
/^routeRef ownership cannot include domains$/u,
|
|
250
|
+
/^gateway route must enable directHub, smartVpn, or RemoteIngress$/u,
|
|
251
|
+
/^gateway route target host must be a string$/u,
|
|
252
|
+
/^gateway client ownership /u,
|
|
253
|
+
/^gateway client token cannot /u,
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
/** The problem a failed gateway request ends a sync with. */
|
|
257
|
+
export const gatewayProblemOf = (errorArg: unknown): IControllerGatewayProblem => {
|
|
258
|
+
if (errorArg instanceof GatewaySyncProblemError) return errorArg.problem;
|
|
259
|
+
if (errorArg instanceof plugins.typedrequest.TypedResponseError) {
|
|
260
|
+
const text = typeof errorArg.errorText === 'string' ? errorArg.errorText.slice(0, 512) : 'refused';
|
|
261
|
+
for (const [pattern, code, explanation] of credentialRefusals) {
|
|
262
|
+
if (pattern.test(text)) {
|
|
263
|
+
return problem(code, `${explanation} (${text}) ${code === 'finalize_pending' ? 'Run `agl remote gateway enrol` again to finish it.' : enrolAgain}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const capability = /^token capability missing: ([A-Za-z]+)$/u.exec(text);
|
|
267
|
+
if (capability) {
|
|
268
|
+
return problem('capability_missing', `The gateway client lacks the ${capability[1]} capability. ${enrolAgain}`);
|
|
269
|
+
}
|
|
270
|
+
if (routeRefusals.some((patternArg) => patternArg.test(text))) {
|
|
271
|
+
return problem('route_refused', `The gateway refused the route: ${text}.`);
|
|
272
|
+
}
|
|
273
|
+
return problem('gateway_error', `The gateway refused the request: ${text}.`);
|
|
274
|
+
}
|
|
275
|
+
const message = errorArg instanceof Error ? errorArg.message : String(errorArg);
|
|
276
|
+
return problem('unreachable', `The gateway did not answer: ${message.slice(0, 512)}`);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Checks the credential's own view (`getGatewayClientContext`): a finalized credential of this very gateway client,
|
|
281
|
+
* allowed to list, write and reconcile its routes, on a gateway that writes routes idempotently.
|
|
282
|
+
*/
|
|
283
|
+
export const gatewayContextProblem = (
|
|
284
|
+
responseArg: IReq_GetGatewayClientContext['response'],
|
|
285
|
+
gatewayClientIdArg: string,
|
|
286
|
+
): IControllerGatewayProblem | undefined => {
|
|
287
|
+
const context = responseArg.context;
|
|
288
|
+
if (context.role !== 'gatewayClient' || context.gatewayClient.id !== gatewayClientIdArg
|
|
289
|
+
|| context.gatewayClient.type !== gatewayClientType) {
|
|
290
|
+
return problem('credential_invalid', `The credential is not one of gateway client ${gatewayClientIdArg}. ${enrolAgain}`);
|
|
291
|
+
}
|
|
292
|
+
if (context.credentialState === 'candidate') {
|
|
293
|
+
return problem('finalize_pending', 'The gateway has not confirmed this credential. Run `agl remote gateway enrol` again to finish it.');
|
|
294
|
+
}
|
|
295
|
+
const missing = gatewayRequiredTokenCapabilities.filter((capabilityArg) => context.capabilities[capabilityArg] !== true);
|
|
296
|
+
if (missing.length > 0) {
|
|
297
|
+
return problem('capability_missing', `The gateway client lacks the ${missing.join(', ')} capabilities. ${enrolAgain}`);
|
|
298
|
+
}
|
|
299
|
+
const routes = responseArg.capabilities.routes;
|
|
300
|
+
if (!routes.read || !routes.write || !routes.idempotentSync) {
|
|
301
|
+
return problem('capability_missing', 'The gateway does not read and write routes idempotently.');
|
|
302
|
+
}
|
|
303
|
+
return undefined;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const ownedDnsStatuses = new Set(['managed-created', 'managed-updated', 'managed-unchanged']);
|
|
307
|
+
|
|
308
|
+
const terminalDnsProblems: Readonly<Record<string, [TControllerGatewayProblemCode, string]>> = {
|
|
309
|
+
'record-conflict': ['dns_record_conflict', 'Another owner or a record the gateway does not manage holds the hostname.'],
|
|
310
|
+
'zone-unmanaged': ['dns_zone_unmanaged', 'The gateway manages no DNS zone that holds the hostname.'],
|
|
311
|
+
'target-invalid': ['dns_target_invalid', 'The gateway cannot publish an address for the route.'],
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/** The gateway's own refusals of a route that are not DNS: a source profile it cannot find, a reserved hostname. */
|
|
315
|
+
const routeResultRefusals: readonly RegExp[] = [
|
|
316
|
+
/^source profile '.*' not found$/u,
|
|
317
|
+
/^STANDARD source profile not found$/u,
|
|
318
|
+
/^Hostname is reserved by a testing grant/u,
|
|
319
|
+
/^route is required unless delete=true$/u,
|
|
320
|
+
];
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Reads a route sync's answer: the route is written when the gateway says so and its DNS is the route's own record
|
|
324
|
+
* or manual records that satisfy it (`manual-satisfied`, which counts as success but is not owned). DNS conflicts,
|
|
325
|
+
* an unmanaged zone and an invalid target are terminal; other DNS failures are the provider's and are retried.
|
|
326
|
+
*/
|
|
327
|
+
export const gatewayRouteSyncOutcome = (
|
|
328
|
+
resultArg: IGatewayRouteSyncResult,
|
|
329
|
+
): { synced: true; dns: IControllerGatewayDns } | { synced: false; problem: IControllerGatewayProblem } => {
|
|
330
|
+
const dns = resultArg.dns;
|
|
331
|
+
const detail = (resultArg.message ?? dns?.message ?? '').slice(0, 512);
|
|
332
|
+
if (resultArg.success && dns?.success) {
|
|
333
|
+
if (ownedDnsStatuses.has(dns.status)) return { synced: true, dns: { status: dns.status, owned: true } };
|
|
334
|
+
if (dns.status === 'manual-satisfied') return { synced: true, dns: { status: dns.status, owned: false } };
|
|
335
|
+
}
|
|
336
|
+
if (dns && Object.hasOwn(terminalDnsProblems, dns.status)) {
|
|
337
|
+
const [code, explanation] = terminalDnsProblems[dns.status]!;
|
|
338
|
+
return { synced: false, problem: problem(code, `${explanation}${detail ? ` (${detail})` : ''}`) };
|
|
339
|
+
}
|
|
340
|
+
if (!dns && routeResultRefusals.some((patternArg) => patternArg.test(detail))) {
|
|
341
|
+
return { synced: false, problem: problem('route_refused', `The gateway refused the route: ${detail}.`) };
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
synced: false,
|
|
345
|
+
problem: problem('gateway_error', `The gateway did not complete the route${dns ? ` (DNS ${dns.status})` : ''}`
|
|
346
|
+
+ `${detail ? `: ${detail}` : ''}.`),
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* One gateway at `<gatewayUrl>/typedrequest`, every request bounded by a timeout and the caller's signal. A URL
|
|
352
|
+
* `normalizeGatewayUrl` refuses for plain http off loopback is refused here too (`gateway_url_insecure`), so no stored
|
|
353
|
+
* enrolment sends its credential over one.
|
|
354
|
+
*/
|
|
355
|
+
export class GatewayClientTransport {
|
|
356
|
+
constructor(
|
|
357
|
+
private readonly gatewayUrl: string,
|
|
358
|
+
private readonly options: { timeoutMs?: number; signal?: AbortSignal } = {},
|
|
359
|
+
) {
|
|
360
|
+
const insecure = insecureGatewayUrlRefusal(gatewayUrl);
|
|
361
|
+
if (insecure) {
|
|
362
|
+
throw new GatewaySyncProblemError(problem('gateway_url_insecure', `${insecure} Forget this enrolment with \`agl remote `
|
|
363
|
+
+ 'gateway remove --abandon` and enrol again with an https gateway URL.'));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
public async fire<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
|
368
|
+
methodArg: T['method'],
|
|
369
|
+
requestArg: T['request'],
|
|
370
|
+
): Promise<T['response']> {
|
|
371
|
+
const request = new plugins.typedrequest.TypedRequest<T>(`${this.gatewayUrl}/typedrequest`, methodArg);
|
|
372
|
+
// The request carries a credential: no hook sees it.
|
|
373
|
+
request.skipHooks = true;
|
|
374
|
+
return await request.fire(requestArg, {
|
|
375
|
+
timeoutMs: this.options.timeoutMs ?? gatewayRequestTimeoutMs,
|
|
376
|
+
...(this.options.signal ? { abortSignal: this.options.signal } : {}),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Deletes every route of the credential's gateway client that `keepArg` does not keep, with its DNS record
|
|
383
|
+
* (`delete: true`, DNS `reconcile`), and returns their keys. The gateway lists only the client's own routes inside
|
|
384
|
+
* its policy.
|
|
385
|
+
*/
|
|
386
|
+
export const deleteGatewayRoutes = async (
|
|
387
|
+
transportArg: GatewayClientTransport,
|
|
388
|
+
apiTokenArg: string,
|
|
389
|
+
keepArg: (routeArg: IGatewayClientRoute) => boolean,
|
|
390
|
+
): Promise<string[]> => {
|
|
391
|
+
const { routes } = await transportArg.fire<IReq_GetGatewayClientRoutes>('getGatewayClientRoutes', { apiToken: apiTokenArg });
|
|
392
|
+
const deleted: string[] = [];
|
|
393
|
+
for (const route of routes) {
|
|
394
|
+
if (keepArg(route)) continue;
|
|
395
|
+
const ownership: IGatewayClientOwnership = {
|
|
396
|
+
...(route.ownership.gatewayClientType === undefined ? {} : { gatewayClientType: route.ownership.gatewayClientType }),
|
|
397
|
+
...(route.ownership.gatewayClientId === undefined ? {} : { gatewayClientId: route.ownership.gatewayClientId }),
|
|
398
|
+
appId: route.ownership.appId,
|
|
399
|
+
...(route.ownership.hostname === undefined ? {} : { hostname: route.ownership.hostname }),
|
|
400
|
+
...(route.ownership.routeRef === undefined ? {} : { routeRef: route.ownership.routeRef }),
|
|
401
|
+
};
|
|
402
|
+
await deleteGatewayRoute(transportArg, apiTokenArg, ownership);
|
|
403
|
+
deleted.push(`${ownership.gatewayClientType ?? gatewayClientType}:${ownership.gatewayClientId ?? ''}:${ownership.appId}:`
|
|
404
|
+
+ `${ownership.hostname ?? `route:${ownership.routeRef ?? ''}`}`);
|
|
405
|
+
}
|
|
406
|
+
return deleted;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/** Deletes one route and its DNS record; deleting a route the gateway does not hold succeeds unchanged. */
|
|
410
|
+
export const deleteGatewayRoute = async (
|
|
411
|
+
transportArg: GatewayClientTransport,
|
|
412
|
+
apiTokenArg: string,
|
|
413
|
+
ownershipArg: IGatewayClientOwnership,
|
|
414
|
+
): Promise<void> => {
|
|
415
|
+
const result = await transportArg.fire<IReq_SyncGatewayClientRoute>('syncGatewayClientRoute', {
|
|
416
|
+
apiToken: apiTokenArg,
|
|
417
|
+
ownership: ownershipArg,
|
|
418
|
+
delete: true,
|
|
419
|
+
dnsMode: 'reconcile',
|
|
420
|
+
});
|
|
421
|
+
if (result.success) return;
|
|
422
|
+
const dns = result.dns;
|
|
423
|
+
const detail = (result.message ?? dns?.message ?? '').slice(0, 512);
|
|
424
|
+
const code: TControllerGatewayProblemCode = dns && Object.hasOwn(terminalDnsProblems, dns.status)
|
|
425
|
+
? terminalDnsProblems[dns.status]![0] : 'gateway_error';
|
|
426
|
+
throw new GatewaySyncProblemError(problem(code, `The gateway did not delete the route for `
|
|
427
|
+
+ `${ownershipArg.hostname ?? ownershipArg.routeRef ?? ownershipArg.appId}${dns ? ` (DNS ${dns.status})` : ''}`
|
|
428
|
+
+ `${detail ? `: ${detail}` : ''}.`));
|
|
429
|
+
};
|
|
@@ -14,6 +14,8 @@ import { aglProxyConfinedMountPoint, aglProxyRelayMountPoint, aglProxyUnitName,
|
|
|
14
14
|
import { writeConfinedRelay } from './functions.confinedrelay.js';
|
|
15
15
|
import { inferenceCliHelp, parseInferenceCliArguments, type IInferenceCliArguments } from './functions.inferencecliarguments.js';
|
|
16
16
|
import { runProxyCredentialCommand } from './functions.proxycredentialcli.js';
|
|
17
|
+
import { runProxyCapacity } from './functions.proxycapacitycli.js';
|
|
18
|
+
import { isProxyCapacityAnswer } from '../ts_interfaces/proxycapacity.js';
|
|
17
19
|
import { currentProxyCredentialHelper, writeProxyCredentialHelper } from './functions.proxycredentialhelper.js';
|
|
18
20
|
|
|
19
21
|
/** An account's lifecycle and placement in `agl proxy status`, which a proxy reports from 38.4.0 on. */
|
|
@@ -307,6 +309,28 @@ export const runInferenceCli = async (argvArg: readonly string[]): Promise<void>
|
|
|
307
309
|
await runProxyCredentialCommand(options, (textArg) => process.stdout.write(textArg));
|
|
308
310
|
return;
|
|
309
311
|
}
|
|
312
|
+
if (options.command === 'capacity') {
|
|
313
|
+
const request = { ...(options.provider ? { provider: options.provider } : {}),
|
|
314
|
+
...(options.minHeadroom === undefined ? {} : { minHeadroom: options.minHeadroom }) };
|
|
315
|
+
process.exitCode = await withSignals((signalArg) => runProxyCapacity({ request, json: options.json, wait: options.wait,
|
|
316
|
+
...(options.maxSeconds === undefined ? {} : { maxSeconds: options.maxSeconds }) }, {
|
|
317
|
+
ask: async (requestArg, askSignalArg) => {
|
|
318
|
+
// A proxy of another release names itself (`AglProxyOutdatedError`); its answer is read only by the contract.
|
|
319
|
+
const answer = await client.capacity(requestArg, AbortSignal.any([askSignalArg, AbortSignal.timeout(10_000)]),
|
|
320
|
+
commitinfo.version);
|
|
321
|
+
if (!isProxyCapacityAnswer(answer)) throw new Error('The proxy answered a capacity this AGL cannot read.');
|
|
322
|
+
return answer;
|
|
323
|
+
},
|
|
324
|
+
now: Date.now,
|
|
325
|
+
sleep: async (msArg, sleepSignalArg) => {
|
|
326
|
+
try { await plugins.timersPromises.setTimeout(msArg, undefined, { signal: sleepSignalArg }); }
|
|
327
|
+
catch (errorArg) { sleepSignalArg.throwIfAborted(); throw errorArg; }
|
|
328
|
+
},
|
|
329
|
+
write: (textArg) => process.stdout.write(textArg),
|
|
330
|
+
note: (textArg) => process.stderr.write(textArg),
|
|
331
|
+
}, signalArg));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
310
334
|
const service = new AglProxyService({ port: options.port });
|
|
311
335
|
if (options.command === 'status') {
|
|
312
336
|
const unit = await unitState(service);
|
|
@@ -27,6 +27,7 @@ export const inferenceCliHelp = `Usage:
|
|
|
27
27
|
agl proxy service install [--port ${aglProxyDefaultPort}] | enable | start | stop | status
|
|
28
28
|
agl proxy serve [--port ${aglProxyDefaultPort}]
|
|
29
29
|
agl proxy status [--json]
|
|
30
|
+
agl proxy capacity [--provider anthropic|openai] [--min-headroom 15] [--json] [--wait [--max-seconds <seconds>]]
|
|
30
31
|
agl proxy credential <client> [--provider openai|anthropic] [--delivery file|none] [--write <path>] [--rotate] | --version
|
|
31
32
|
agl proxy run codex|claude|opencode [--provider openai|anthropic] [--account <id>] [--plan <name>] [--model <id>] -- [harness arguments]
|
|
32
33
|
agl proxy confined run [--provider anthropic|openai] -- docker run [docker options] <image> [command]
|
|
@@ -60,6 +61,14 @@ on 127.0.0.1:${aglProxyRelayDefaultPort} inside the container, which therefore k
|
|
|
60
61
|
and --network container:… are refused. It passes AGL_PROXY_SOCKET and MODELPROFILE_PROXY_TOKEN, and no model.
|
|
61
62
|
confined end ends a run's credential at once, and its launcher stops the container; agl proxy status lists the runs
|
|
62
63
|
with their harnesses and pools.
|
|
64
|
+
capacity answers each pool's room for new work: the headroom its members add now, summed. Its members are its
|
|
65
|
+
subscription sign-ins that have not lapsed and whose reading states a counted plan (Claude accounts: max; ChatGPT
|
|
66
|
+
accounts: every plan but free); one that takes no work now adds nothing. A pool is open when its room reaches
|
|
67
|
+
--min-headroom (15 unless given) and no provider 429 hit a member within five minutes (a proxy watches for five minutes
|
|
68
|
+
after its start before it says so); otherwise it waits until the first moment the members' readings foresee enough room.
|
|
69
|
+
Each member names its binding window and when its headroom next grows. Exit status: 0 when every pool reported is open,
|
|
70
|
+
2 when one waits, 1 on a failure. --wait (with --provider) asks again until the pool is open, at most --max-seconds when
|
|
71
|
+
given, and exits 2 when that time ran out.
|
|
63
72
|
Repeat --account or --plan to restrict automatic routing. Only accounts the account service holds are eligible.
|
|
64
73
|
ChatGPT pools: /openai/v1/responses, /anthropic/v1/messages (translated), and each prefix's /models.
|
|
65
74
|
Claude pools: /anthropic/v1/messages, /anthropic/v1/messages/count_tokens and /anthropic/v1/models, sent on as Claude Code sent them.
|
|
@@ -69,7 +78,7 @@ Use x-agl-session-id for custom clients; native session headers and prompt_cache
|
|
|
69
78
|
Switches use full history with a cold cache. Provider-only references require a full-history retry; opaque account state never crosses accounts.
|
|
70
79
|
`;
|
|
71
80
|
|
|
72
|
-
export type TInferenceCommand = 'serve' | 'run' | 'credential' | 'status' | 'service' | 'confined';
|
|
81
|
+
export type TInferenceCommand = 'serve' | 'run' | 'credential' | 'status' | 'capacity' | 'service' | 'confined';
|
|
73
82
|
export type TInferenceServiceAction = 'install' | 'enable' | 'start' | 'stop' | 'status';
|
|
74
83
|
export type TInferenceConfinedAction = 'run' | 'end';
|
|
75
84
|
|
|
@@ -93,6 +102,12 @@ export interface IInferenceCliArguments {
|
|
|
93
102
|
/** `credential --version`: the release only, no client. */
|
|
94
103
|
version: boolean;
|
|
95
104
|
json: boolean;
|
|
105
|
+
/** `capacity --min-headroom`: the room a pool needs, a non-negative integer. */
|
|
106
|
+
minHeadroom?: number;
|
|
107
|
+
/** `capacity --wait`: ask again until the pool is open. */
|
|
108
|
+
wait: boolean;
|
|
109
|
+
/** `capacity --max-seconds`: how long `--wait` waits at most. */
|
|
110
|
+
maxSeconds?: number;
|
|
96
111
|
args: string[];
|
|
97
112
|
}
|
|
98
113
|
|
|
@@ -101,17 +116,18 @@ const commandOptions: Record<TInferenceCommand, readonly string[]> = {
|
|
|
101
116
|
run: ['--provider', '--account', '--plan', '--model'],
|
|
102
117
|
credential: ['--provider', '--delivery', '--write', '--rotate'],
|
|
103
118
|
status: ['--json'],
|
|
119
|
+
capacity: ['--provider', '--min-headroom', '--json', '--wait', '--max-seconds'],
|
|
104
120
|
service: ['--port'],
|
|
105
121
|
confined: [],
|
|
106
122
|
};
|
|
107
|
-
const flags = new Set(['--rotate', '--json']);
|
|
123
|
+
const flags = new Set(['--rotate', '--json', '--wait']);
|
|
108
124
|
|
|
109
125
|
export const parseInferenceCliArguments = (argvArg: readonly string[]): IInferenceCliArguments => {
|
|
110
126
|
const argv = [...argvArg];
|
|
111
127
|
const command = argv.shift() as TInferenceCommand | undefined;
|
|
112
128
|
if (!command || !Object.hasOwn(commandOptions, command)) throw new Error(inferenceCliHelp);
|
|
113
129
|
const result: IInferenceCliArguments = { command, port: aglProxyDefaultPort, policy: {}, rotate: false, version: false, json: false,
|
|
114
|
-
args: [] };
|
|
130
|
+
wait: false, args: [] };
|
|
115
131
|
if (command === 'run') {
|
|
116
132
|
const harness = argv.shift();
|
|
117
133
|
if (!['codex', 'claude', 'opencode'].includes(harness ?? '')) throw new Error(inferenceCliHelp);
|
|
@@ -169,7 +185,7 @@ export const parseInferenceCliArguments = (argvArg: readonly string[]): IInferen
|
|
|
169
185
|
throw new Error(`Unknown proxy option: ${name}`);
|
|
170
186
|
}
|
|
171
187
|
if (flags.has(name)) {
|
|
172
|
-
if (name === '--rotate') result.rotate = true; else result.json = true;
|
|
188
|
+
if (name === '--rotate') result.rotate = true; else if (name === '--wait') result.wait = true; else result.json = true;
|
|
173
189
|
continue;
|
|
174
190
|
}
|
|
175
191
|
const value = argv.shift();
|
|
@@ -189,6 +205,12 @@ export const parseInferenceCliArguments = (argvArg: readonly string[]): IInferen
|
|
|
189
205
|
} else if (name === '--delivery') {
|
|
190
206
|
if (!proxyCredentialDeliveries.includes(value as TProxyCredentialDelivery)) throw new Error('--delivery is file or none.');
|
|
191
207
|
result.delivery = value as TProxyCredentialDelivery;
|
|
208
|
+
} else if (name === '--min-headroom') {
|
|
209
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(Number(value))) throw new Error('--min-headroom is a whole percent, 0 or more.');
|
|
210
|
+
result.minHeadroom = Number(value);
|
|
211
|
+
} else if (name === '--max-seconds') {
|
|
212
|
+
if (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value))) throw new Error('--max-seconds is a whole number of seconds, 1 or more.');
|
|
213
|
+
result.maxSeconds = Number(value);
|
|
192
214
|
} else if (name === '--write') {
|
|
193
215
|
if (!path.isAbsolute(value)) throw new Error('--write needs an absolute path.');
|
|
194
216
|
result.write = path.normalize(value);
|
|
@@ -197,6 +219,10 @@ export const parseInferenceCliArguments = (argvArg: readonly string[]): IInferen
|
|
|
197
219
|
result.modelId = value;
|
|
198
220
|
}
|
|
199
221
|
}
|
|
222
|
+
if (command === 'capacity') {
|
|
223
|
+
if (result.wait && result.provider === undefined) throw new Error('--wait waits for one pool: name it with --provider.');
|
|
224
|
+
if (result.maxSeconds !== undefined && !result.wait) throw new Error('--max-seconds bounds --wait, which it needs.');
|
|
225
|
+
}
|
|
200
226
|
if (accounts.length > 64 || plans.length > 32) throw new Error('The proxy policy exceeds its account or plan limit.');
|
|
201
227
|
if (accounts.length) result.policy.accountIds = [...new Set(accounts)];
|
|
202
228
|
if (plans.length) result.policy.plans = [...new Set(plans)];
|