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
|
@@ -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
|
+
};
|
|
@@ -9,9 +9,13 @@ import { AglProxyControlClient, AglProxyUnavailableError } from './classes.proxy
|
|
|
9
9
|
import { AglProxyConfinedHolder, AglProxyLeaseHolder, type AglProxyLeaseLostError } from './classes.proxyleaseholder.js';
|
|
10
10
|
import { AglProxyDaemon } from './classes.proxydaemon.js';
|
|
11
11
|
import { AglProxyService, resolveAglExecutable } from './classes.proxyservice.js';
|
|
12
|
-
import { aglProxyConfinedMountPoint, aglProxyUnitName
|
|
12
|
+
import { aglProxyConfinedMountPoint, aglProxyRelayMountPoint, aglProxyUnitName,
|
|
13
|
+
type TAglProxyConfinedRun } from './functions.proxycontract.js';
|
|
14
|
+
import { writeConfinedRelay } from './functions.confinedrelay.js';
|
|
13
15
|
import { inferenceCliHelp, parseInferenceCliArguments, type IInferenceCliArguments } from './functions.inferencecliarguments.js';
|
|
14
16
|
import { runProxyCredentialCommand } from './functions.proxycredentialcli.js';
|
|
17
|
+
import { runProxyCapacity } from './functions.proxycapacitycli.js';
|
|
18
|
+
import { isProxyCapacityAnswer } from '../ts_interfaces/proxycapacity.js';
|
|
15
19
|
import { currentProxyCredentialHelper, writeProxyCredentialHelper } from './functions.proxycredentialhelper.js';
|
|
16
20
|
|
|
17
21
|
/** An account's lifecycle and placement in `agl proxy status`, which a proxy reports from 38.4.0 on. */
|
|
@@ -20,14 +24,14 @@ type TAccountPlacementKey = 'lifecycle' | 'lapsesAt' | 'placementScore' | 'place
|
|
|
20
24
|
/**
|
|
21
25
|
* The status a running proxy answers with: one started from an AGL before 38.3.0 reports no accounts and no usage
|
|
22
26
|
* observations, one before 38.4.0 no lifecycle, placement or placement journal, one before confined runs neither
|
|
23
|
-
* its confined listener nor its runs,
|
|
24
|
-
* Claude pool.
|
|
27
|
+
* its confined listener nor its runs, one before ChatGPT-pool confined runs no run's pool: its runs are all of the
|
|
28
|
+
* Claude pool, and one before Codex confined runs no run's harness: its runs are all Claude Code's.
|
|
25
29
|
*/
|
|
26
30
|
export type TReportedProxyStatus = Omit<IAglProxyStatus, 'accounts' | 'usageObservations' | 'nextPlacement'
|
|
27
31
|
| 'recentPlacements' | 'confinedSocketPath' | 'confinedRuns'>
|
|
28
32
|
& Partial<Pick<IAglProxyStatus, 'usageObservations' | 'nextPlacement' | 'recentPlacements' | 'confinedSocketPath'>>
|
|
29
|
-
& { confinedRuns?: Array<Omit<IAglProxyStatus['confinedRuns'][number], 'provider'>
|
|
30
|
-
& Partial<Pick<IAglProxyStatus['confinedRuns'][number], 'provider'>>> }
|
|
33
|
+
& { confinedRuns?: Array<Omit<IAglProxyStatus['confinedRuns'][number], 'provider' | 'harness'>
|
|
34
|
+
& Partial<Pick<IAglProxyStatus['confinedRuns'][number], 'provider' | 'harness'>>> }
|
|
31
35
|
& { accounts?: Array<Omit<IAglProxyStatus['accounts'][number], TAccountPlacementKey>
|
|
32
36
|
& Partial<Pick<IAglProxyStatus['accounts'][number], TAccountPlacementKey>>> };
|
|
33
37
|
|
|
@@ -76,8 +80,9 @@ export const formatProxyStatus = (unitArg: string, statusArg: TReportedProxyStat
|
|
|
76
80
|
if (statusArg.confinedSocketPath !== undefined) {
|
|
77
81
|
lines.push(`Confined listener: ${statusArg.confinedSocketPath ?? 'none'}`);
|
|
78
82
|
for (const run of statusArg.confinedRuns ?? []) {
|
|
79
|
-
// An older proxy names no run's pool: it issues Claude-pool runs alone.
|
|
80
|
-
lines.push(`Confined run ${run.id}: ${run.
|
|
83
|
+
// An older proxy names no run's pool: it issues Claude-pool runs alone; nor its harness: it issues Claude Code runs alone.
|
|
84
|
+
lines.push(`Confined run ${run.id}: ${run.harness === 'codex' ? 'Codex on the ChatGPT pool (ChatGPT accounts only)'
|
|
85
|
+
: run.provider === 'openai' ? 'ChatGPT pool' : 'Claude pool'}, issued ${run.createdAt}`
|
|
81
86
|
+ `${run.held ? '' : ', waiting for its launcher to take it back after a proxy restart'}`
|
|
82
87
|
+ ` (end it with \`agl proxy confined end ${run.id}\`)`);
|
|
83
88
|
}
|
|
@@ -214,21 +219,43 @@ const run = (optionsArg: IInferenceCliArguments): Promise<void> => withSignals(a
|
|
|
214
219
|
/**
|
|
215
220
|
* Runs a confined run's container (see `confinedDockerLaunch`) on a credential of its own, which ends when the container
|
|
216
221
|
* exits. A proxy that restarts meanwhile hands the credential back; one the proxy no longer hands back, or the operator
|
|
217
|
-
* ended, stops the container (`docker run` passes the signal on to it), and the run ends with the reason.
|
|
222
|
+
* ended, stops the container (`docker run` passes the signal on to it), and the run ends with the reason. A Codex run's
|
|
223
|
+
* relay is written to a directory of the run's own before the credential is taken, and removed once the container is gone.
|
|
218
224
|
*/
|
|
219
225
|
const confinedRun = (optionsArg: IInferenceCliArguments): Promise<void> => withSignals(async (signalArg) => {
|
|
220
226
|
await preflightAGLHomeMigration();
|
|
221
227
|
const paths = resolveAGLHomePaths();
|
|
222
|
-
const
|
|
228
|
+
const asked: TAglProxyConfinedRun = optionsArg.harness === 'codex' ? { harness: 'codex', provider: 'openai' }
|
|
229
|
+
: { harness: 'claude', provider: optionsArg.provider ?? 'anthropic' };
|
|
230
|
+
const relay = asked.harness === 'codex' ? await writeConfinedRelay() : undefined;
|
|
231
|
+
try {
|
|
232
|
+
await confinedContainer(optionsArg, signalArg, paths.proxySocket, asked, relay?.directory);
|
|
233
|
+
} finally {
|
|
234
|
+
// A directory left behind holds AGL's relay alone, never a credential; its path is named so it can be removed.
|
|
235
|
+
await relay?.remove().catch((errorArg: unknown) => {
|
|
236
|
+
process.stderr.write(`AGL proxy confined run: the relay directory ${relay.directory} could not be removed: `
|
|
237
|
+
+ `${errorArg instanceof Error ? errorArg.message : String(errorArg)}\n`);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
/** One confined run's container on its credential (see `confinedRun`). */
|
|
243
|
+
const confinedContainer = async (optionsArg: IInferenceCliArguments, signalArg: AbortSignal, proxySocketArg: string,
|
|
244
|
+
askedArg: TAglProxyConfinedRun, relayDirectoryArg: string | undefined): Promise<void> => {
|
|
245
|
+
const run = await AglProxyConfinedHolder.take({ socketPath: proxySocketArg, run: askedArg },
|
|
223
246
|
AbortSignal.any([signalArg, AbortSignal.timeout(90_000)]));
|
|
224
247
|
let lost: AglProxyLeaseLostError | undefined;
|
|
225
248
|
try {
|
|
226
249
|
const launch = confinedDockerLaunch({ args: optionsArg.args, socketPath: run.confinedSocketPath, baseUrl: run.baseUrl,
|
|
227
250
|
token: run.token, environment: process.env,
|
|
228
|
-
pool:
|
|
229
|
-
|
|
251
|
+
pool: relayDirectoryArg !== undefined ? { harness: 'codex', relayDirectory: relayDirectoryArg }
|
|
252
|
+
: run.provider === 'anthropic' ? { provider: 'anthropic' } : { provider: 'openai', models: run.models } });
|
|
253
|
+
// A Claude-pool run says what it said before ChatGPT-pool runs; a ChatGPT-pool run says so, and a Codex run where its
|
|
254
|
+
// relay is.
|
|
230
255
|
process.stderr.write(`AGL proxy confined run ${run.id}: ${plugins.path.dirname(run.confinedSocketPath)} is mounted read-only `
|
|
231
|
-
+ `at ${aglProxyConfinedMountPoint}${run.
|
|
256
|
+
+ `at ${aglProxyConfinedMountPoint}${run.harness === 'codex'
|
|
257
|
+
? `, Codex on the ChatGPT pool (ChatGPT accounts only), AGL's relay at ${aglProxyRelayMountPoint}`
|
|
258
|
+
: run.provider === 'openai' ? ', served from the ChatGPT pool' : ''}; `
|
|
232
259
|
+ `end it at once with \`agl proxy confined end ${run.id}\`.\n`);
|
|
233
260
|
signalArg.throwIfAborted();
|
|
234
261
|
const child = plugins.childProcess.spawn(launch.command, launch.args, { env: launch.environment, stdio: 'inherit', shell: false });
|
|
@@ -252,7 +279,7 @@ const confinedRun = (optionsArg: IInferenceCliArguments): Promise<void> => withS
|
|
|
252
279
|
}
|
|
253
280
|
} finally { run.close(); }
|
|
254
281
|
if (lost) throw new Error(`${lost.message} The container was stopped; start the run again to continue.`);
|
|
255
|
-
}
|
|
282
|
+
};
|
|
256
283
|
|
|
257
284
|
const unitState = async (serviceArg: AglProxyService): Promise<string> => {
|
|
258
285
|
try {
|
|
@@ -282,6 +309,28 @@ export const runInferenceCli = async (argvArg: readonly string[]): Promise<void>
|
|
|
282
309
|
await runProxyCredentialCommand(options, (textArg) => process.stdout.write(textArg));
|
|
283
310
|
return;
|
|
284
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
|
+
}
|
|
285
334
|
const service = new AglProxyService({ port: options.port });
|
|
286
335
|
if (options.command === 'status') {
|
|
287
336
|
const unit = await unitState(service);
|