agl 43.0.5 → 43.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +18 -0
- package/dist_serve/bundle.js +5186 -4683
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +29 -29
- package/dist_serve/bundle.js.third-party-notices.txt +29 -29
- 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 +475 -4
- package/dist_ts/aglapi/interfaces.d.ts +10 -0
- package/dist_ts/aglapi/interfaces.js +3 -1
- package/dist_ts/classes.claudeharness.d.ts +14 -5
- package/dist_ts/classes.claudeharness.js +62 -2
- package/dist_ts/classes.codexclientadapter.d.ts +7 -5
- package/dist_ts/classes.codexclientadapter.js +38 -3
- package/dist_ts/classes.controller.d.ts +9 -2
- package/dist_ts/classes.controller.js +116 -24
- package/dist_ts/classes.inferencegateway.d.ts +8 -5
- package/dist_ts/classes.inferencegateway.js +62 -19
- package/dist_ts/classes.inferencespend.d.ts +9 -3
- package/dist_ts/classes.inferencespend.js +44 -16
- package/dist_ts/classes.mcpclient.d.ts +6 -4
- package/dist_ts/classes.mcpclient.js +6 -2
- package/dist_ts/classes.mcpcontrollerhost.js +5 -1
- package/dist_ts/classes.mcptools.d.ts +1 -1
- package/dist_ts/classes.mcptools.js +17 -4
- package/dist_ts/classes.opencodeclient.js +3 -1
- package/dist_ts/classes.proxycontrol.d.ts +22 -11
- package/dist_ts/classes.proxycontrol.js +6 -3
- package/dist_ts/classes.proxycontrolclient.d.ts +6 -5
- package/dist_ts/classes.proxycontrolclient.js +8 -6
- package/dist_ts/classes.proxydaemon.d.ts +8 -6
- package/dist_ts/classes.proxydaemon.js +35 -21
- package/dist_ts/classes.proxyleaseholder.d.ts +12 -4
- package/dist_ts/classes.proxyleaseholder.js +39 -9
- 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.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.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.inferencecli.d.ts +3 -3
- package/dist_ts/functions.inferencecli.js +33 -10
- package/dist_ts/functions.inferencecliarguments.d.ts +2 -1
- package/dist_ts/functions.inferencecliarguments.js +29 -8
- 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.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/interfaces.auth.d.ts +1 -1
- package/dist_ts/interfaces.auth.js +2 -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/index.d.ts +1 -0
- package/dist_ts_interfaces/index.js +2 -1
- package/dist_ts_interfaces/interfaces.d.ts +3 -1
- package/dist_ts_interfaces/interfaces.js +2 -2
- package/dist_ts_interfaces/mcprequests.d.ts +5 -1
- package/dist_ts_interfaces/mcprequests.js +2 -1
- package/dist_ts_interfaces/nativesessions.d.ts +14 -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 +3 -3
- package/readme.md +191 -24
- package/third-party-notices.md +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +474 -3
- package/ts/aglapi/interfaces.ts +2 -0
- package/ts/classes.claudeharness.ts +80 -9
- package/ts/classes.codexclientadapter.ts +41 -5
- package/ts/classes.controller.ts +142 -29
- package/ts/classes.inferencegateway.ts +69 -23
- package/ts/classes.inferencespend.ts +46 -13
- package/ts/classes.mcpclient.ts +8 -4
- package/ts/classes.mcpcontrollerhost.ts +4 -0
- package/ts/classes.mcptools.ts +17 -3
- package/ts/classes.opencodeclient.ts +2 -0
- package/ts/classes.proxycontrol.ts +27 -13
- package/ts/classes.proxycontrolclient.ts +9 -6
- package/ts/classes.proxydaemon.ts +49 -27
- package/ts/classes.proxyleaseholder.ts +43 -11
- package/ts/classes.proxystore.ts +21 -8
- package/ts/classes.sessionfeed.ts +1 -1
- 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.deviceapi.ts +24 -1
- package/ts/functions.elicitation.ts +443 -0
- package/ts/functions.inferencecli.ts +38 -13
- package/ts/functions.inferencecliarguments.ts +26 -5
- package/ts/functions.inferencelaunch.ts +143 -16
- package/ts/functions.mcpfleetworkertools.ts +34 -4
- package/ts/functions.proxycontract.ts +17 -4
- package/ts/functions.proxyharnessconfig.ts +11 -0
- package/ts/interfaces.auth.ts +1 -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/index.ts +1 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/mcprequests.ts +1 -0
- package/ts_interfaces/nativesessions.ts +16 -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.elicitationcards.ts +106 -0
- package/ts_web/classes.nativesessionstate.ts +38 -1
- package/ts_web/elements.fleetworker.ts +27 -2
- package/ts_web/elements.harnesscontrollerapp.ts +68 -1
- package/ts_web/functions.sessionchat.ts +5 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import type { TInferenceModel } from './classes.inferencerouter.js';
|
|
3
3
|
import type { TAglProxyLeaseCatalog } from './classes.proxycontrol.js';
|
|
4
|
-
import { aglProxyConfinedMountPoint } from './functions.proxycontract.js';
|
|
4
|
+
import { aglProxyConfinedMountPoint, aglProxyRelayMountPoint } from './functions.proxycontract.js';
|
|
5
5
|
import { aglProxyProviderId, claudeProxyEnvironment, claudeProxyReservedVariables, claudeRoutingVariables, codexProxyProvider,
|
|
6
|
-
openCodeProxyProvider, proxyHarnessModels } from './functions.proxyharnessconfig.js';
|
|
6
|
+
codexRoutingVariables, openCodeProxyProvider, proxyHarnessModels } from './functions.proxyharnessconfig.js';
|
|
7
7
|
|
|
8
8
|
export type TInferenceHarness = 'codex' | 'claude' | 'opencode';
|
|
9
9
|
export interface IInferenceLaunchOptions {
|
|
@@ -160,23 +160,140 @@ export const inferenceHarnessLaunch = (optionsArg: IInferenceLaunchOptions): { a
|
|
|
160
160
|
return { environment, args: args[0] !== undefined && openCodeCommands.has(args[0]) ? args : [...selection, ...args] };
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
-
/**
|
|
164
|
-
|
|
163
|
+
/**
|
|
164
|
+
* A confined run's harness and pool, as its launcher configures the container for it: Claude Code on the Claude pool, Claude
|
|
165
|
+
* Code on the ChatGPT pool with the pool's models, or Codex on the ChatGPT pool with the host directory that holds AGL's
|
|
166
|
+
* relay for it (`writeConfinedRelay`).
|
|
167
|
+
*/
|
|
168
|
+
export type TConfinedLaunchPool = { provider: 'anthropic' } | { provider: 'openai'; models: readonly TInferenceModel[] }
|
|
169
|
+
| { harness: 'codex'; relayDirectory: string };
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* `docker run`'s options as Docker 29.7.1 lists them (`docker run --help`, and the hidden `--disable-content-trust`): those
|
|
173
|
+
* that take no value, those that take one, and the one-letter forms of each. `dockerRunNetworks` takes an option it does
|
|
174
|
+
* not know to take a value, but never one that is a network option itself (`dockerNetworkOption`): an unknown option can
|
|
175
|
+
* make it read on into the container's command, so it may find more networks than Docker does, never fewer.
|
|
176
|
+
*/
|
|
177
|
+
const dockerRunFlags: ReadonlySet<string> = new Set(['--detach', '--disable-content-trust', '--help', '--init', '--interactive',
|
|
178
|
+
'--no-healthcheck', '--oom-kill-disable', '--privileged', '--publish-all', '--quiet', '--read-only', '--rm', '--sig-proxy',
|
|
179
|
+
'--tty', '--use-api-socket']);
|
|
180
|
+
const dockerRunValueOptions: ReadonlySet<string> = new Set(['--add-host', '--annotation', '--attach', '--blkio-weight',
|
|
181
|
+
'--blkio-weight-device', '--cap-add', '--cap-drop', '--cgroup-parent', '--cgroupns', '--cidfile', '--cpu-period', '--cpu-quota',
|
|
182
|
+
'--cpu-rt-period', '--cpu-rt-runtime', '--cpu-shares', '--cpus', '--cpuset-cpus', '--cpuset-mems', '--detach-keys', '--device',
|
|
183
|
+
'--device-cgroup-rule', '--device-read-bps', '--device-read-iops', '--device-write-bps', '--device-write-iops', '--dns',
|
|
184
|
+
'--dns-option', '--dns-search', '--domainname', '--entrypoint', '--env', '--env-file', '--expose', '--gpus', '--group-add',
|
|
185
|
+
'--health-cmd', '--health-interval', '--health-retries', '--health-start-interval', '--health-start-period', '--health-timeout',
|
|
186
|
+
'--hostname', '--ip', '--ip6', '--ipc', '--isolation', '--label', '--label-file', '--link', '--link-local-ip', '--log-driver',
|
|
187
|
+
'--log-opt', '--mac-address', '--memory', '--memory-reservation', '--memory-swap', '--memory-swappiness', '--mount', '--name',
|
|
188
|
+
'--network', '--network-alias', '--oom-score-adj', '--pid', '--pids-limit', '--platform', '--publish', '--pull', '--restart',
|
|
189
|
+
'--runtime', '--security-opt', '--shm-size', '--stop-signal', '--stop-timeout', '--storage-opt', '--sysctl', '--tmpfs',
|
|
190
|
+
'--ulimit', '--user', '--userns', '--uts', '--volume', '--volume-driver', '--volumes-from', '--workdir']);
|
|
191
|
+
const dockerRunShortFlags: ReadonlySet<string> = new Set(['d', 'i', 'P', 'q', 't']);
|
|
192
|
+
const dockerRunShortValueOptions: ReadonlySet<string> = new Set(['a', 'c', 'e', 'h', 'l', 'm', 'p', 'u', 'v', 'w']);
|
|
193
|
+
/** `--network` or its alias `--net`, alone or with its value after `=`. */
|
|
194
|
+
const dockerNetworkOption = /^--net(?:work)?(?:=|$)/u;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The `--network` values `docker run`'s options (`optionsArg`, what follows `run`) give the container, in every spelling
|
|
198
|
+
* Docker takes: `--network` or its alias `--net`, with the value after `=` or as the next argument; see
|
|
199
|
+
* `dockerNetworkName` for what a value names. Reading stops at the image, the first argument that is no option, or at `--`.
|
|
200
|
+
* A known option that takes a value takes the next argument whatever it reads like, as Docker does (`-e --network=host`
|
|
201
|
+
* sets a variable); an option only assumed to take one never takes a network option.
|
|
202
|
+
*/
|
|
203
|
+
export const dockerRunNetworks = (optionsArg: readonly string[]): string[] => {
|
|
204
|
+
const networks: string[] = [];
|
|
205
|
+
const takesNext = (knownArg: boolean, indexArg: number): boolean =>
|
|
206
|
+
knownArg || !dockerNetworkOption.test(optionsArg[indexArg + 1] ?? '');
|
|
207
|
+
for (let index = 0; index < optionsArg.length; index++) {
|
|
208
|
+
const argument = optionsArg[index]!;
|
|
209
|
+
if (argument === '--' || !argument.startsWith('-') || argument === '-') break;
|
|
210
|
+
const long = /^(--[^=]+)(?:=(.*))?$/su.exec(argument);
|
|
211
|
+
if (long) {
|
|
212
|
+
const [, name, value] = long;
|
|
213
|
+
if (name === '--network' || name === '--net') {
|
|
214
|
+
const network = value ?? optionsArg[++index];
|
|
215
|
+
if (network !== undefined) networks.push(network);
|
|
216
|
+
} else if (value === undefined && !dockerRunFlags.has(name!) && takesNext(dockerRunValueOptions.has(name!), index)) index++;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
// One-letter options, alone or grouped (`-it`); one that takes a value, or one this list does not know, takes the rest
|
|
220
|
+
// of the group or the next argument.
|
|
221
|
+
for (let at = 1; at < argument.length; at++) {
|
|
222
|
+
if (dockerRunShortFlags.has(argument[at]!)) continue;
|
|
223
|
+
if (at === argument.length - 1 && takesNext(dockerRunShortValueOptions.has(argument[at]!), index)) index++;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return networks;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The network a `--network` value names, as Docker 29.7.1's command line reads it (`NetworkOpt`): a value in which
|
|
232
|
+
* `\w+=\w+` occurs anywhere is its long form, comma-separated `key=value` fields whose keys it trims and lower-cases, and
|
|
233
|
+
* whose last `name` field names the network; any other value is the network's name itself. `undefined` for a long form
|
|
234
|
+
* this does not read whole: one with a quote or a line break (Docker reads the fields as CSV), a field without `=`, or no
|
|
235
|
+
* `name` field.
|
|
236
|
+
*/
|
|
237
|
+
export const dockerNetworkName = (valueArg: string): string | undefined => {
|
|
238
|
+
if (!/\w+=\w+/u.test(valueArg)) return valueArg;
|
|
239
|
+
if (/["\r\n]/u.test(valueArg)) return undefined;
|
|
240
|
+
let name: string | undefined;
|
|
241
|
+
for (const field of valueArg.split(',')) {
|
|
242
|
+
const at = field.indexOf('=');
|
|
243
|
+
if (at < 0) return undefined;
|
|
244
|
+
if (field.slice(0, at).trim().toLowerCase() === 'name') name = field.slice(at + 1).trim();
|
|
245
|
+
}
|
|
246
|
+
return name;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* A Codex run's container keeps a network namespace of its own: AGL's relay listens on `127.0.0.1` inside it, which on
|
|
251
|
+
* the host's network (`host`) or another container's (`container:…`) would be that loopback's, where the proxy's own
|
|
252
|
+
* port is and every process of the host or that container could reach the confined route over TCP (ruling U13-162). A
|
|
253
|
+
* long-form value whose network this cannot read is refused as well.
|
|
254
|
+
*/
|
|
255
|
+
const assertOwnNetwork = (optionsArg: readonly string[]): void => {
|
|
256
|
+
for (const value of dockerRunNetworks(optionsArg)) {
|
|
257
|
+
const network = dockerNetworkName(value);
|
|
258
|
+
if (network === undefined) {
|
|
259
|
+
throw new Error(`A Codex confined run's container needs a network namespace of its own, and AGL cannot read which `
|
|
260
|
+
+ `network --network ${value} names (Docker's long form: comma-separated key=value fields, the network in name=, no `
|
|
261
|
+
+ 'quotes). Use --network none.');
|
|
262
|
+
}
|
|
263
|
+
if (network === 'host' || network.startsWith('container:')) {
|
|
264
|
+
throw new Error(`A Codex confined run's container needs a network namespace of its own, and --network ${value} shares `
|
|
265
|
+
+ 'another\'s: AGL\'s relay listens on 127.0.0.1 inside the container, which would put the confined route on that '
|
|
266
|
+
+ 'loopback. Use --network none.');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/** `--mount` separates its fields with commas and reads quotes; a directory naming either cannot be passed safely. */
|
|
272
|
+
const assertMountable = (directoryArg: string, whatArg: string): void => {
|
|
273
|
+
if (/[,"'\n]/u.test(directoryArg)) {
|
|
274
|
+
throw new Error(`${whatArg} ${directoryArg} cannot be mounted: it holds a comma, quote or line break.`);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
165
277
|
|
|
166
278
|
/**
|
|
167
279
|
* A confined run's `docker run`: the given command, with the confined listener's directory mounted read-only at
|
|
168
|
-
* `aglProxyConfinedMountPoint` and
|
|
280
|
+
* `aglProxyConfinedMountPoint` and the harness's settings for it added right after `run`, before the launcher's own
|
|
169
281
|
* options and image. Claude Code inside reaches the proxy through the socket alone (`ANTHROPIC_UNIX_SOCKET`, which
|
|
170
282
|
* Claude Code sends its API requests through as plain HTTP to `ANTHROPIC_BASE_URL`'s path), on the run's credential
|
|
171
283
|
* (`ANTHROPIC_AUTH_TOKEN`), and sends nothing beyond its model requests. On the Claude pool it reads the pool's models
|
|
172
284
|
* from the proxy; on the ChatGPT pool it gets the variables `agl proxy run claude --provider openai` gives it
|
|
173
285
|
* (`claudeChatGptEnvironment`: the pool's default model for every alias, its context window), but neither that command's
|
|
174
286
|
* configuration directory, which lies in the AGL home, nor its `/model` picker, an option of the container's command
|
|
175
|
-
* that the launcher does not touch.
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
287
|
+
* that the launcher does not touch. A Codex run (AGL-1614) also gets AGL's relay's directory mounted read-only at
|
|
288
|
+
* `aglProxyRelayMountPoint`, which its command runs Codex through, the socket's path in the container
|
|
289
|
+
* (`AGL_PROXY_SOCKET`) for the relay and the run's credential (`MODELPROFILE_PROXY_TOKEN`) for Codex's provider command;
|
|
290
|
+
* no model variable: Codex reads the pool's catalog through the relay, and the command names its model. The container
|
|
291
|
+
* gets each variable by name from the docker command's environment, so the credential never appears on a command line;
|
|
292
|
+
* that environment drops every variable that would give the harness another login or route -- Claude Code's always, and
|
|
293
|
+
* for a Codex run Codex's and OpenAI's (`codexRoutingVariables`) -- and on the ChatGPT pool every model variable a Claude
|
|
294
|
+
* Code run sets, so `-e NAME` of one of them passes nothing. The mount is the socket's own directory, which holds nothing
|
|
295
|
+
* else and survives a proxy restart, unlike a mount of the socket file. Only `docker run` and `docker container run` are
|
|
296
|
+
* taken.
|
|
180
297
|
*/
|
|
181
298
|
export const confinedDockerLaunch = (optionsArg: {
|
|
182
299
|
args: readonly string[];
|
|
@@ -194,25 +311,35 @@ export const confinedDockerLaunch = (optionsArg: {
|
|
|
194
311
|
throw new Error('A confined run starts its container with `docker run` (or `docker container run`) and its arguments.');
|
|
195
312
|
}
|
|
196
313
|
const directory = path.dirname(optionsArg.socketPath);
|
|
197
|
-
|
|
198
|
-
|
|
314
|
+
assertMountable(directory, 'The confined listener\'s directory');
|
|
315
|
+
const pool = optionsArg.pool;
|
|
316
|
+
const relayDirectory = 'harness' in pool ? pool.relayDirectory : undefined;
|
|
317
|
+
if (relayDirectory !== undefined) {
|
|
318
|
+
assertMountable(relayDirectory, 'The confined run\'s relay directory');
|
|
319
|
+
assertOwnNetwork(args.slice(runAt));
|
|
320
|
+
}
|
|
199
321
|
const socket = `${aglProxyConfinedMountPoint}/${path.basename(optionsArg.socketPath)}`;
|
|
200
|
-
const variables: Record<string, string> =
|
|
322
|
+
const variables: Record<string, string> = 'harness' in pool ? {
|
|
323
|
+
AGL_PROXY_SOCKET: socket,
|
|
324
|
+
MODELPROFILE_PROXY_TOKEN: optionsArg.token,
|
|
325
|
+
} : pool.provider === 'anthropic' ? {
|
|
201
326
|
...claudeProxyEnvironment(optionsArg.baseUrl),
|
|
202
327
|
ANTHROPIC_UNIX_SOCKET: socket,
|
|
203
328
|
ANTHROPIC_AUTH_TOKEN: optionsArg.token,
|
|
204
329
|
} : {
|
|
205
|
-
...claudeChatGptEnvironment({ baseUrl: `${optionsArg.baseUrl}/anthropic`, token: optionsArg.token,
|
|
206
|
-
models: optionsArg.pool.models }),
|
|
330
|
+
...claudeChatGptEnvironment({ baseUrl: `${optionsArg.baseUrl}/anthropic`, token: optionsArg.token, models: pool.models }),
|
|
207
331
|
ANTHROPIC_UNIX_SOCKET: socket,
|
|
208
332
|
};
|
|
209
333
|
const environment = { ...optionsArg.environment };
|
|
210
334
|
for (const name of claudeProxyReservedVariables) delete environment[name];
|
|
211
|
-
if (
|
|
335
|
+
if ('harness' in pool) for (const name of codexRoutingVariables) delete environment[name];
|
|
336
|
+
else if (pool.provider === 'openai') for (const name of claudeChatGptVariables) delete environment[name];
|
|
212
337
|
return {
|
|
213
338
|
command,
|
|
214
339
|
args: [...args.slice(0, runAt),
|
|
215
340
|
'--mount', `type=bind,source=${directory},target=${aglProxyConfinedMountPoint},readonly`,
|
|
341
|
+
...(relayDirectory === undefined ? []
|
|
342
|
+
: ['--mount', `type=bind,source=${relayDirectory},target=${aglProxyRelayMountPoint},readonly`]),
|
|
216
343
|
...Object.keys(variables).flatMap((nameArg) => ['--env', nameArg]),
|
|
217
344
|
...args.slice(runAt)],
|
|
218
345
|
environment: { ...environment, ...variables },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
1
2
|
import { fleetWorkerRequestSchemas } from './fleet/functions.workervalidation.js';
|
|
2
|
-
import type
|
|
3
|
+
import { fleetWorkerReadActions, type TFleetWorkerAction, type TFleetWorkerResponse } from '../ts_interfaces/fleetworkers.js';
|
|
3
4
|
|
|
4
5
|
const descriptions: Record<TFleetWorkerAction, string> = {
|
|
5
6
|
start: 'Start a named Claude background worker or a Codex thread on the existing shared daemon, using a Configuration master worker profile. Returns a job handle.',
|
|
@@ -12,12 +13,41 @@ const descriptions: Record<TFleetWorkerAction, string> = {
|
|
|
12
13
|
archive: 'Archive a settled worker. Codex archives natively; Claude archives the AGL registry only and retains its transcript/worktree. Returns a job handle.',
|
|
13
14
|
refresh: 'Start a fresh thread from the settled predecessor\'s self-contained Handoff report. Store the successor before retiring the predecessor. With profile, the successor launches on that configured profile, which must run the predecessor\'s harness (only move changes the harness); without it the successor keeps the predecessor\'s recorded profile. Returns a job handle.',
|
|
14
15
|
move: 'Move a settled Claude lane to a new shared-daemon Codex thread with its Handoff report. Identify the successor before retiring Claude. Returns a job handle.',
|
|
15
|
-
list: 'List this owner\'s
|
|
16
|
-
|
|
16
|
+
list: 'List this owner\'s fleet workers as summaries, newest first, in pages of limit (1-100, default 50): identity, ticket, state, native id, cwd, the native status, newest turn outcome and native wait last observed, and fence flags (an unresolved dispatch with its action and since, a lost or reconfirmed dispatch, a recorded error). total, fenced and failed (recorded errors and failed turn outcomes) count the whole filtered set, so a page never hides a fence. Continue with nextCursor and the same filter (archived, ticketKey, state, harness); a cursor of another filter or one after a worker no longer held as it was is refused. view full returns every full record unpaged; fleet_worker_get returns one worker whole.',
|
|
17
|
+
get: 'Read one of this owner\'s fleet workers, archived ones included, by name or id: its full record (dispatch fence, lost, reconfirmed and re-bind resolutions with their attribution and proof, error) and the native status, turn outcome and start, native wait and excerpt the controller last observed.',
|
|
18
|
+
status: 'Read a fleet operation job (the handle a fleet_worker_* action returns), not a host job. Jobs are transient; bindings and unresolved dispatches survive restart. Inspect unknown native outcomes before retrying.',
|
|
19
|
+
'job-wait': 'Wait until a fleet operation job (the handle a fleet_worker_* action returns, not a host job) succeeds or fails, or timeoutMs (at most 240000) passes; timedOut tells which. Waiting, a timeout or an abandoned wait never cancels the job. A job the controller no longer holds (jobs end with a controller restart or eviction) is JOB_UNAVAILABLE, not failed: read the worker with fleet_worker_get.',
|
|
17
20
|
'native-message': 'Wake a settled (done, blocked or stopped) Claude Code background job that no fleet worker binds with an attributed message, through Claude Code itself (`claude --bg --resume <id> <text>`), as the browser\'s native session send does. nativeId is the full session id or a unique prefix of at least 8 characters; an ambiguous prefix is refused. A running, failed or held job, a fleet worker\'s session and a project conversation are refused with their reason. The message arrives behind the same attribution header as session_message, naming the sender label and the local owner capability, never as the job\'s user. A native wake holds no dispatch fence, writes no ticket comment and does not observe the woken turn; the receipt names the command that adopts the job as a fleet worker. Returns a job handle; an unknown outcome is never retried.',
|
|
18
21
|
watch: 'Read the one bounded fleet event stream: worker turn endings, reports during turns, reaped Claude worker observations, release outcomes, and host load. Continue with the returned epoch/cursor; reset explicitly signals restart or retained-history gaps.',
|
|
19
22
|
};
|
|
23
|
+
/** The tools' own inputs where they differ from the private request's: MCP `fleet_worker_list` lists summaries unless told otherwise. */
|
|
24
|
+
const toolInputSchemas: Partial<Record<TFleetWorkerAction, plugins.z.ZodType<Record<string, unknown>>>> = {
|
|
25
|
+
list: fleetWorkerRequestSchemas.list.extend({ view: plugins.z.enum(['summary', 'full']).default('summary') }),
|
|
26
|
+
};
|
|
20
27
|
export const fleetWorkerToolDefinitions = (Object.keys(fleetWorkerRequestSchemas) as TFleetWorkerAction[]).map((action) => ({
|
|
21
28
|
name: action === 'watch' ? 'fleet_watch' : `fleet_worker_${action.replaceAll('-', '_')}`, action, description: descriptions[action],
|
|
22
|
-
inputSchema: fleetWorkerRequestSchemas[action], readOnly:
|
|
29
|
+
inputSchema: toolInputSchemas[action] ?? fleetWorkerRequestSchemas[action], readOnly: (fleetWorkerReadActions as readonly string[]).includes(action),
|
|
23
30
|
}));
|
|
31
|
+
/**
|
|
32
|
+
* One private controller request is bounded by the private request timeout (30 s), so `fleet_worker_job_wait` waits in
|
|
33
|
+
* slices of at most this long, each a fresh request.
|
|
34
|
+
*/
|
|
35
|
+
export const fleetWorkerJobWaitSliceMs = 20_000;
|
|
36
|
+
/**
|
|
37
|
+
* Waits for a fleet operation job in slices until it settles or `timeoutMs` passed, on a monotonic clock: `slice` asks
|
|
38
|
+
* the controller for one wait of at most `fleetWorkerJobWaitSliceMs`. The controller times each slice, so a timed-out
|
|
39
|
+
* slice that covered the remaining wait ends it.
|
|
40
|
+
*/
|
|
41
|
+
export const waitForFleetWorkerJob = async (
|
|
42
|
+
slice: (timeoutMs: number) => Promise<TFleetWorkerResponse<'job-wait'>>,
|
|
43
|
+
timeoutMs: number,
|
|
44
|
+
monotonicNow: () => number = () => performance.now(),
|
|
45
|
+
): Promise<TFleetWorkerResponse<'job-wait'>> => {
|
|
46
|
+
const deadline = monotonicNow() + timeoutMs;
|
|
47
|
+
while (true) {
|
|
48
|
+
const remainingMs = Math.max(0, Math.ceil(deadline - monotonicNow()));
|
|
49
|
+
const sliceMs = Math.min(fleetWorkerJobWaitSliceMs, remainingMs);
|
|
50
|
+
const result = await slice(sliceMs);
|
|
51
|
+
if (!result.timedOut || sliceMs === remainingMs || monotonicNow() >= deadline) return result;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -35,13 +35,26 @@ export const aglProxyUnitName = 'agl-proxy.service';
|
|
|
35
35
|
export const aglProxyDefaultPort = 4100;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Confined runs (`agl proxy confined run`): Claude Code in a container that reaches the proxy only through the
|
|
39
|
-
* listener, a Unix socket alone in its directory, which the run mounts read-only at `aglProxyConfinedMountPoint`.
|
|
40
|
-
* sessions are those of the client `aglProxyConfinedClient`, and
|
|
41
|
-
* endpoint's origin, whose host the socket makes irrelevant.
|
|
38
|
+
* Confined runs (`agl proxy confined run`): Claude Code or Codex in a container that reaches the proxy only through the
|
|
39
|
+
* confined listener, a Unix socket alone in its directory, which the run mounts read-only at `aglProxyConfinedMountPoint`.
|
|
40
|
+
* Claude Code's sessions are those of the client `aglProxyConfinedClient`, and it names `aglProxyConfinedOrigin` as its
|
|
41
|
+
* endpoint's origin, whose host the socket makes irrelevant. Codex's are those of `aglProxyConfinedCodexClient`; it reaches
|
|
42
|
+
* the socket through AGL's relay (`aglProxyRelaySource`), mounted read-only at `aglProxyRelayMountPoint`.
|
|
42
43
|
*/
|
|
43
44
|
export const aglProxyConfinedClient = 'confined';
|
|
45
|
+
export const aglProxyConfinedCodexClient = 'confined-codex';
|
|
44
46
|
export const aglProxyConfinedOrigin = 'http://localhost';
|
|
45
47
|
export const aglProxyConfinedMountPoint = '/run/agl-proxy';
|
|
46
48
|
/** A confined run's id: the first 12 hex characters of its credential's SHA-256 digest. */
|
|
47
49
|
export const aglProxyConfinedIdPattern = /^[a-f0-9]{12}$/;
|
|
50
|
+
|
|
51
|
+
/** The harness a confined run serves: Claude Code (on the Claude or the ChatGPT pool) or Codex (on the ChatGPT pool). */
|
|
52
|
+
export type TAglProxyConfinedHarness = 'claude' | 'codex';
|
|
53
|
+
/** What a confined run is asked for: Claude Code on either pool, or Codex on the ChatGPT pool. */
|
|
54
|
+
export type TAglProxyConfinedRun = { harness: 'claude'; provider: TInferenceProvider } | { harness: 'codex'; provider: 'openai' };
|
|
55
|
+
|
|
56
|
+
/** Where a Codex run's container finds AGL's relay, read-only, and the relay's file there. */
|
|
57
|
+
export const aglProxyRelayMountPoint = '/run/agl-proxy-relay';
|
|
58
|
+
export const aglProxyRelayFile = 'agl-relay.mjs';
|
|
59
|
+
/** The loopback port the relay listens on inside the container unless `AGL_PROXY_RELAY_PORT` names another. */
|
|
60
|
+
export const aglProxyRelayDefaultPort = 4100;
|
|
@@ -53,6 +53,17 @@ export const claudeRoutingVariables: readonly string[] = ['ANTHROPIC_API_KEY', '
|
|
|
53
53
|
'CLAUDE_CODE_USE_VERTEX', 'CLAUDE_CODE_USE_FOUNDRY', 'CLAUDE_CODE_USE_ANTHROPIC_AWS', 'CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD',
|
|
54
54
|
'CLAUDE_CODE_USE_MANTLE', 'CLAUDE_CODE_USE_GATEWAY', 'ANTHROPIC_UNIX_SOCKET'];
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The variables that make Codex authenticate or route another way than through the proxy's provider, or read a home of
|
|
58
|
+
* its own choosing: an OpenAI or Codex key, token or login, an OpenAI endpoint, organization or project, workload
|
|
59
|
+
* identity federation, a remote or local model server, a CA bundle, and `CODEX_HOME`, which a confined run's container
|
|
60
|
+
* names itself.
|
|
61
|
+
*/
|
|
62
|
+
export const codexRoutingVariables: readonly string[] = ['OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_ORGANIZATION',
|
|
63
|
+
'OPENAI_PROJECT', 'OPENAI_IDENTITY_TOKEN_FILE', 'OPENAI_WORKLOAD_IDENTITY_CONTEXT', 'OPENAI_FEDERATION_RULE_ID',
|
|
64
|
+
'CODEX_API_KEY', 'CODEX_ACCESS_TOKEN', 'CODEX_AUTH', 'CODEX_REMOTE_AUTH_TOKEN', 'CODEX_REMOTE_TOKEN', 'CODEX_HOME',
|
|
65
|
+
'CODEX_CA_CERTIFICATE', 'CODEX_OSS_BASE_URL', 'CODEX_OSS_PORT'];
|
|
66
|
+
|
|
56
67
|
/**
|
|
57
68
|
* The variables a Claude Code settings file routed through the proxy may not set beside the proxy's: its endpoint and
|
|
58
69
|
* routing, and a bearer token, which would take precedence over the `apiKeyHelper` that reads the proxy's credential.
|