agl 43.0.4 → 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 +25 -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.flexservice.d.ts +6 -7
- package/dist_ts/classes.flexservice.js +12 -45
- package/dist_ts/classes.flexsupervisor.d.ts +37 -3
- package/dist_ts/classes.flexsupervisor.js +164 -37
- 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/flexharness.child.js +9 -4
- 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.flexchildshutdown.d.ts +7 -0
- package/dist_ts/functions.flexchildshutdown.js +18 -1
- 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/dist_ts_migration/index.d.ts +0 -2
- package/dist_ts_migration/index.js +1 -3
- package/dist_ts_migration/v43_flexpostharnessmigrationmarkers.d.ts +6 -17
- package/dist_ts_migration/v43_flexpostharnessmigrationmarkers.js +6 -36
- 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.flexservice.ts +10 -66
- package/ts/classes.flexsupervisor.ts +214 -37
- 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/flexharness.child.ts +8 -3
- package/ts/functions.confinedrelay.ts +65 -0
- package/ts/functions.deviceapi.ts +24 -1
- package/ts/functions.elicitation.ts +443 -0
- package/ts/functions.flexchildshutdown.ts +22 -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_migration/index.ts +0 -2
- package/ts_migration/v43_flexpostharnessmigrationmarkers.ts +6 -49
- 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
- package/dist_ts_migration/classes.flexpostharnessmigrationrunner.d.ts +0 -19
- package/dist_ts_migration/classes.flexpostharnessmigrationrunner.js +0 -34
- package/dist_ts_migration/v19_flexprojectmanagement.d.ts +0 -14
- package/dist_ts_migration/v19_flexprojectmanagement.js +0 -23
- package/ts_migration/classes.flexpostharnessmigrationrunner.ts +0 -54
- package/ts_migration/v19_flexprojectmanagement.ts +0 -32
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IControllerElicitationOption, IControllerElicitationSchema, IControllerElicitationUnsupported, IControllerRuntimeId,
|
|
3
|
+
TControllerElicitation, TControllerElicitationContent, TControllerElicitationField, TControllerElicitationReply,
|
|
4
|
+
TControllerElicitationTextFormat, TControllerElicitationValue,
|
|
5
|
+
} from '../ts_interfaces/index.js';
|
|
6
|
+
import {
|
|
7
|
+
controllerElicitationMaxContentBytes, controllerElicitationMaxFields, controllerElicitationMaxOptions,
|
|
8
|
+
} from '../ts_interfaces/index.js';
|
|
9
|
+
import { boundToolText } from './functions.livetoolbounding.js';
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* MCP elicitation as AGL holds it (`TControllerElicitation`): what a harness hands over is read into a card here, by the
|
|
13
|
+
* one normaliser `controllerElicitation`, and the owner's answer is checked against the card here before the harness
|
|
14
|
+
* sends it. Every text this module writes names
|
|
15
|
+
* fields and rules only, never a value the owner entered, so a refusal can travel to the browser, an audit record or a
|
|
16
|
+
* log without carrying what the owner typed.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** A refused answer: `not_found` when the request is no longer pending, `invalid_request` when it does not fit. */
|
|
20
|
+
export class ControllerElicitationReplyError extends Error {
|
|
21
|
+
constructor(messageArg: string, public readonly code: 'invalid_request' | 'not_found') {
|
|
22
|
+
super(messageArg);
|
|
23
|
+
this.name = 'ControllerElicitationReplyError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** What the harness sends back to the MCP server, once the answer fits the card. */
|
|
28
|
+
export interface IControllerElicitationAnswer {
|
|
29
|
+
action: 'accept' | 'decline' | 'cancel';
|
|
30
|
+
content?: TControllerElicitationContent;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const maxServerNameBytes = 512;
|
|
34
|
+
const maxMessageBytes = 16 * 1024;
|
|
35
|
+
const maxUrlBytes = 8 * 1024;
|
|
36
|
+
const maxFieldNameBytes = 256;
|
|
37
|
+
const maxTitleBytes = 512;
|
|
38
|
+
const maxDescriptionBytes = 4 * 1024;
|
|
39
|
+
const maxOptionValueBytes = 1024;
|
|
40
|
+
const maxOptionLabelBytes = 1024;
|
|
41
|
+
/** A card's shown texts together, as for permission and question cards. */
|
|
42
|
+
const maxControllerElicitationCardBytes = 64 * 1024;
|
|
43
|
+
|
|
44
|
+
const textFormats: readonly TControllerElicitationTextFormat[] = ['email', 'uri', 'date', 'date-time'];
|
|
45
|
+
|
|
46
|
+
const record = (valueArg: unknown): Record<string, unknown> | undefined => (
|
|
47
|
+
typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg) ? valueArg as Record<string, unknown> : undefined
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** A text shown on the card, cut to its bound with a closing ellipsis. */
|
|
51
|
+
const controllerElicitationText = (valueArg: string, maxBytesArg: number): string => {
|
|
52
|
+
const bounded = boundToolText(valueArg, maxBytesArg);
|
|
53
|
+
return bounded.truncated ? `${bounded.text}…` : bounded.text;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** How a field is named in a reason: its name as the server wrote it, quoted and bounded. */
|
|
57
|
+
const fieldName = (nameArg: string): string => JSON.stringify(boundToolText(nameArg, 128).text);
|
|
58
|
+
|
|
59
|
+
const nonNegativeInteger = (valueArg: unknown): valueArg is number => Number.isSafeInteger(valueArg) && (valueArg as number) >= 0;
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------------------------------------- reading a request
|
|
62
|
+
|
|
63
|
+
/** A URL request's address, shown as text; an address AGL cannot show whole makes the request unsupported. */
|
|
64
|
+
const readUrl = (urlArg: unknown): { url: string } | { unsupported: string } => {
|
|
65
|
+
if (typeof urlArg !== 'string' || urlArg.length === 0) return { unsupported: 'The server asks to visit an address it did not name.' };
|
|
66
|
+
if (Buffer.byteLength(urlArg, 'utf8') > maxUrlBytes) return { unsupported: 'The server asks to visit an address too long for AGL to show.' };
|
|
67
|
+
return { url: urlArg };
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type TFieldRead = { field: TControllerElicitationField } | { unsupported: string };
|
|
71
|
+
|
|
72
|
+
const malformed = (nameArg: string): { unsupported: string } => ({ unsupported: `The form's field ${fieldName(nameArg)} is malformed.` });
|
|
73
|
+
|
|
74
|
+
/** Reads the choices a field offers: MCP's `enum` (with legacy `enumNames` labels) or `oneOf`/`anyOf` of `{ const, title }`. */
|
|
75
|
+
const readOptions = (
|
|
76
|
+
nameArg: string,
|
|
77
|
+
enumArg: unknown,
|
|
78
|
+
enumNamesArg: unknown,
|
|
79
|
+
titledArg: unknown,
|
|
80
|
+
): IControllerElicitationOption[] | { unsupported: string } => {
|
|
81
|
+
let options: IControllerElicitationOption[];
|
|
82
|
+
if (enumArg !== undefined) {
|
|
83
|
+
if (titledArg !== undefined || !Array.isArray(enumArg) || enumArg.some((entry) => typeof entry !== 'string')) return malformed(nameArg);
|
|
84
|
+
const labels = enumNamesArg;
|
|
85
|
+
if (labels !== undefined && (!Array.isArray(labels) || labels.length !== enumArg.length || labels.some((entry) => typeof entry !== 'string'))) {
|
|
86
|
+
return malformed(nameArg);
|
|
87
|
+
}
|
|
88
|
+
options = (enumArg as string[]).map((value, index) => ({ value, label: Array.isArray(labels) ? labels[index] as string : value }));
|
|
89
|
+
} else {
|
|
90
|
+
if (!Array.isArray(titledArg)) return malformed(nameArg);
|
|
91
|
+
const entries = titledArg.map(record);
|
|
92
|
+
if (entries.some((entry) => typeof entry?.const !== 'string' || typeof entry.title !== 'string')) return malformed(nameArg);
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const unchecked = uncheckedKeyword(entry!, 'option');
|
|
95
|
+
if (unchecked !== undefined) return { unsupported: `A choice of the form's field ${fieldName(nameArg)} uses the rule "${unchecked}", which AGL cannot check.` };
|
|
96
|
+
}
|
|
97
|
+
options = entries.map((entry) => ({ value: entry!.const as string, label: entry!.title as string }));
|
|
98
|
+
}
|
|
99
|
+
if (options.length === 0) return { unsupported: `The form's field ${fieldName(nameArg)} offers no choice.` };
|
|
100
|
+
if (options.length > controllerElicitationMaxOptions) return { unsupported: `The form's field ${fieldName(nameArg)} offers more choices than AGL shows.` };
|
|
101
|
+
if (options.some((option) => Buffer.byteLength(option.value, 'utf8') > maxOptionValueBytes)) {
|
|
102
|
+
return { unsupported: `A choice of the form's field ${fieldName(nameArg)} is too long for AGL to send.` };
|
|
103
|
+
}
|
|
104
|
+
if (new Set(options.map((option) => option.value)).size !== options.length) return malformed(nameArg);
|
|
105
|
+
return options.map((option) => ({ value: option.value, label: controllerElicitationText(option.label, maxOptionLabelBytes) }));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Where a schema object sits in a form, for the keywords AGL checks there: a field of each kind (`number` for number
|
|
110
|
+
* and integer alike), the `items` of a list of choices, an option of `oneOf` or `anyOf`, and the form itself.
|
|
111
|
+
*/
|
|
112
|
+
type TElicitationFieldPlace = 'text' | 'choice' | 'number' | 'boolean' | 'choices';
|
|
113
|
+
type TElicitationSchemaPlace = TElicitationFieldPlace | 'items' | 'option' | 'form';
|
|
114
|
+
|
|
115
|
+
/** The JSON Schema keywords (drafts 7 to 2020-12) a validator enforces; every other keyword is an annotation. */
|
|
116
|
+
const constraintKeywords: ReadonlySet<string> = new Set([
|
|
117
|
+
'type', 'const', 'enum', 'multipleOf', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'minLength', 'maxLength',
|
|
118
|
+
'pattern', 'format', 'minItems', 'maxItems', 'uniqueItems', 'contains', 'minContains', 'maxContains', 'items',
|
|
119
|
+
'prefixItems', 'additionalItems', 'unevaluatedItems', 'properties', 'patternProperties', 'additionalProperties',
|
|
120
|
+
'propertyNames', 'unevaluatedProperties', 'required', 'minProperties', 'maxProperties', 'dependentRequired',
|
|
121
|
+
'dependentSchemas', 'dependencies', 'allOf', 'anyOf', 'oneOf', 'not', 'if', 'then', 'else', '$ref', '$dynamicRef',
|
|
122
|
+
'$recursiveRef',
|
|
123
|
+
]);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The keywords AGL reads into a card and checks an answer against, for each place. `uniqueItems` holds either way for
|
|
127
|
+
* a list of choices, as an answer never names a choice twice; the form's `additionalProperties` holds either way, as
|
|
128
|
+
* an answer never carries a field the form does not define.
|
|
129
|
+
*/
|
|
130
|
+
const mappedKeywords: Record<TElicitationSchemaPlace, ReadonlySet<string>> = {
|
|
131
|
+
text: new Set(['type', 'format', 'minLength', 'maxLength']),
|
|
132
|
+
choice: new Set(['type', 'enum', 'enumNames', 'oneOf']),
|
|
133
|
+
number: new Set(['type', 'minimum', 'maximum']),
|
|
134
|
+
boolean: new Set(['type']),
|
|
135
|
+
choices: new Set(['type', 'items', 'minItems', 'maxItems', 'uniqueItems']),
|
|
136
|
+
items: new Set(['type', 'enum', 'anyOf']),
|
|
137
|
+
option: new Set(['const']),
|
|
138
|
+
form: new Set(['type', 'properties', 'required', 'additionalProperties']),
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** The first keyword of `schemaArg` a validator enforces and AGL does not check at `placeArg`. */
|
|
142
|
+
const uncheckedKeyword = (schemaArg: Record<string, unknown>, placeArg: TElicitationSchemaPlace): string | undefined => (
|
|
143
|
+
Object.keys(schemaArg).find((keyword) => constraintKeywords.has(keyword) && !mappedKeywords[placeArg].has(keyword))
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
/** The place of a field by the kind of value it takes; `undefined` for a kind AGL cannot show. */
|
|
147
|
+
const fieldPlace = (propertyArg: Record<string, unknown>): TElicitationFieldPlace | undefined => {
|
|
148
|
+
switch (propertyArg.type) {
|
|
149
|
+
case 'string': return propertyArg.enum !== undefined || propertyArg.oneOf !== undefined ? 'choice' : 'text';
|
|
150
|
+
case 'number': case 'integer': return 'number';
|
|
151
|
+
case 'boolean': return 'boolean';
|
|
152
|
+
case 'array': return 'choices';
|
|
153
|
+
default: return undefined;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const readField = (nameArg: string, valueArg: unknown, requiredArg: boolean): TFieldRead => {
|
|
158
|
+
if (nameArg.length === 0 || Buffer.byteLength(nameArg, 'utf8') > maxFieldNameBytes) return { unsupported: 'A field of the form has a name AGL cannot send.' };
|
|
159
|
+
const property = record(valueArg);
|
|
160
|
+
if (!property) return malformed(nameArg);
|
|
161
|
+
if ((property.title !== undefined && typeof property.title !== 'string')
|
|
162
|
+
|| (property.description !== undefined && typeof property.description !== 'string')) return malformed(nameArg);
|
|
163
|
+
const place = fieldPlace(property);
|
|
164
|
+
if (place === undefined) {
|
|
165
|
+
return { unsupported: property.type === 'object'
|
|
166
|
+
? `The form's field ${fieldName(nameArg)} asks for a nested object, which AGL cannot show.`
|
|
167
|
+
: `The form's field ${fieldName(nameArg)} asks for a kind of value AGL cannot show.` };
|
|
168
|
+
}
|
|
169
|
+
const unchecked = uncheckedKeyword(property, place);
|
|
170
|
+
if (unchecked !== undefined) return { unsupported: `The form's field ${fieldName(nameArg)} uses the rule "${unchecked}", which AGL cannot check.` };
|
|
171
|
+
const base = {
|
|
172
|
+
name: nameArg,
|
|
173
|
+
...(typeof property.title === 'string' ? { title: controllerElicitationText(property.title, maxTitleBytes) } : {}),
|
|
174
|
+
...(typeof property.description === 'string' ? { description: controllerElicitationText(property.description, maxDescriptionBytes) } : {}),
|
|
175
|
+
required: requiredArg,
|
|
176
|
+
};
|
|
177
|
+
let field: TControllerElicitationField;
|
|
178
|
+
switch (place) {
|
|
179
|
+
case 'choice': {
|
|
180
|
+
const options = readOptions(nameArg, property.enum, property.enumNames, property.oneOf);
|
|
181
|
+
if (!Array.isArray(options)) return options;
|
|
182
|
+
field = { ...base, kind: 'choice', options, ...(property.default === undefined ? {} : { default: property.default as string }) };
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case 'text': {
|
|
186
|
+
const { format, minLength, maxLength } = property;
|
|
187
|
+
if (format !== undefined && !textFormats.includes(format as TControllerElicitationTextFormat)) {
|
|
188
|
+
return { unsupported: `The form's field ${fieldName(nameArg)} asks for a format AGL cannot check.` };
|
|
189
|
+
}
|
|
190
|
+
if ((minLength !== undefined && !nonNegativeInteger(minLength)) || (maxLength !== undefined && !nonNegativeInteger(maxLength))
|
|
191
|
+
|| (minLength !== undefined && maxLength !== undefined && (minLength as number) > (maxLength as number))) return malformed(nameArg);
|
|
192
|
+
field = {
|
|
193
|
+
...base, kind: 'text',
|
|
194
|
+
...(format === undefined ? {} : { format: format as TControllerElicitationTextFormat }),
|
|
195
|
+
...(minLength === undefined ? {} : { minLength: minLength as number }),
|
|
196
|
+
...(maxLength === undefined ? {} : { maxLength: maxLength as number }),
|
|
197
|
+
...(property.default === undefined ? {} : { default: property.default as string }),
|
|
198
|
+
};
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'number': {
|
|
202
|
+
const { minimum, maximum } = property;
|
|
203
|
+
const finite = (entryArg: unknown) => typeof entryArg === 'number' && Number.isFinite(entryArg);
|
|
204
|
+
if ((minimum !== undefined && !finite(minimum)) || (maximum !== undefined && !finite(maximum))
|
|
205
|
+
|| (minimum !== undefined && maximum !== undefined && (minimum as number) > (maximum as number))) return malformed(nameArg);
|
|
206
|
+
field = {
|
|
207
|
+
...base, kind: 'number', integer: property.type === 'integer',
|
|
208
|
+
...(minimum === undefined ? {} : { minimum: minimum as number }),
|
|
209
|
+
...(maximum === undefined ? {} : { maximum: maximum as number }),
|
|
210
|
+
...(property.default === undefined ? {} : { default: property.default as number }),
|
|
211
|
+
};
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'boolean':
|
|
215
|
+
field = { ...base, kind: 'boolean', ...(property.default === undefined ? {} : { default: property.default as boolean }) };
|
|
216
|
+
break;
|
|
217
|
+
case 'choices': {
|
|
218
|
+
const items = record(property.items);
|
|
219
|
+
if (!items) return { unsupported: `The form's field ${fieldName(nameArg)} asks for a list AGL cannot show.` };
|
|
220
|
+
const uncheckedItem = uncheckedKeyword(items, 'items');
|
|
221
|
+
if (uncheckedItem !== undefined) {
|
|
222
|
+
return { unsupported: `The choices of the form's field ${fieldName(nameArg)} use the rule "${uncheckedItem}", which AGL cannot check.` };
|
|
223
|
+
}
|
|
224
|
+
if ((items.enum === undefined && items.anyOf === undefined) || (items.type !== undefined && items.type !== 'string')) {
|
|
225
|
+
return { unsupported: `The form's field ${fieldName(nameArg)} asks for a list AGL cannot show.` };
|
|
226
|
+
}
|
|
227
|
+
const options = readOptions(nameArg, items.enum, undefined, items.anyOf);
|
|
228
|
+
if (!Array.isArray(options)) return options;
|
|
229
|
+
const { minItems, maxItems, uniqueItems } = property;
|
|
230
|
+
if ((minItems !== undefined && !nonNegativeInteger(minItems)) || (maxItems !== undefined && !nonNegativeInteger(maxItems))
|
|
231
|
+
|| (minItems !== undefined && maxItems !== undefined && (minItems as number) > (maxItems as number))
|
|
232
|
+
|| (uniqueItems !== undefined && typeof uniqueItems !== 'boolean')) return malformed(nameArg);
|
|
233
|
+
field = {
|
|
234
|
+
...base, kind: 'choices', options,
|
|
235
|
+
...(minItems === undefined ? {} : { minItems: minItems as number }),
|
|
236
|
+
...(maxItems === undefined ? {} : { maxItems: maxItems as number }),
|
|
237
|
+
...(property.default === undefined ? {} : { default: property.default as string[] }),
|
|
238
|
+
};
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// A default is a value the owner could send unchanged, so it must pass the field's own rules.
|
|
243
|
+
if (field.default !== undefined && controllerElicitationValueProblem(field, field.default) !== undefined) {
|
|
244
|
+
return { unsupported: `The form's field ${fieldName(nameArg)} has a default its own rules refuse.` };
|
|
245
|
+
}
|
|
246
|
+
return { field };
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Reads a form request's schema (MCP `requestedSchema`) into the fields AGL collects, or names why AGL cannot collect
|
|
251
|
+
* it: anything outside MCP's flat primitive subset. Annotations are left out; a keyword a validator enforces that AGL
|
|
252
|
+
* cannot check (`constraintKeywords` beyond `mappedKeywords`, in a field, its `items` or the form) makes the form
|
|
253
|
+
* unsupported, so the owner never answers a form whose rules AGL did not check.
|
|
254
|
+
*/
|
|
255
|
+
export const controllerElicitationForm = (schemaArg: unknown): { schema: IControllerElicitationSchema } | { unsupported: string } => {
|
|
256
|
+
const schema = record(schemaArg);
|
|
257
|
+
const properties = record(schema?.properties);
|
|
258
|
+
if (!schema || schema.type !== 'object' || !properties) return { unsupported: 'The server sent no form AGL can read.' };
|
|
259
|
+
const unchecked = uncheckedKeyword(schema, 'form');
|
|
260
|
+
if (unchecked !== undefined) return { unsupported: `The form uses the rule "${unchecked}", which AGL cannot check.` };
|
|
261
|
+
if (schema.required !== undefined && (!Array.isArray(schema.required) || schema.required.some((entry) => typeof entry !== 'string'))) {
|
|
262
|
+
return { unsupported: 'The server sent no form AGL can read.' };
|
|
263
|
+
}
|
|
264
|
+
const required = new Set(schema.required as string[] | undefined);
|
|
265
|
+
const entries = Object.entries(properties);
|
|
266
|
+
if (entries.length > controllerElicitationMaxFields) return { unsupported: 'The form has more fields than AGL shows.' };
|
|
267
|
+
if ([...required].some((name) => !Object.hasOwn(properties, name))) return { unsupported: 'The form requires a field it does not define.' };
|
|
268
|
+
const fields: TControllerElicitationField[] = [];
|
|
269
|
+
for (const [name, value] of entries) {
|
|
270
|
+
const read = readField(name, value, required.has(name));
|
|
271
|
+
if ('unsupported' in read) return read;
|
|
272
|
+
fields.push(read.field);
|
|
273
|
+
}
|
|
274
|
+
return { schema: { fields } };
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/** What a harness hands over of an MCP elicitation, as it arrived: the normaliser trusts none of it. */
|
|
278
|
+
export interface IControllerElicitationRequest {
|
|
279
|
+
id: IControllerRuntimeId;
|
|
280
|
+
sessionId: IControllerRuntimeId;
|
|
281
|
+
serverName: unknown;
|
|
282
|
+
message: unknown;
|
|
283
|
+
/** MCP's `mode`; absent is a form, as MCP defines it. */
|
|
284
|
+
mode: unknown;
|
|
285
|
+
url?: unknown;
|
|
286
|
+
requestedSchema?: unknown;
|
|
287
|
+
createdAt: number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** A mode is named in a reason only while it is a short token, so a reason never carries arbitrary text. */
|
|
291
|
+
const modeReason = (modeArg: unknown): string => (
|
|
292
|
+
typeof modeArg === 'string' && /^[A-Za-z0-9][A-Za-z0-9._/-]{0,63}$/u.test(modeArg)
|
|
293
|
+
? `The request is of the kind ${JSON.stringify(modeArg)}, which AGL cannot show.`
|
|
294
|
+
: 'The request is of a kind AGL cannot show.'
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The one reading of an MCP elicitation into its card, for every harness: a form of MCP's flat primitive subset, a
|
|
299
|
+
* URL, or, for anything else (another mode, a nested or otherwise unknown field, a rule AGL cannot check, a malformed
|
|
300
|
+
* form, a card larger than AGL shows), an unsupported card with the reason. A field AGL cannot collect is never left out of a form.
|
|
301
|
+
*/
|
|
302
|
+
export const controllerElicitation = (requestArg: IControllerElicitationRequest): TControllerElicitation => {
|
|
303
|
+
const base = {
|
|
304
|
+
id: requestArg.id,
|
|
305
|
+
sessionId: requestArg.sessionId,
|
|
306
|
+
serverName: controllerElicitationText(typeof requestArg.serverName === 'string' ? requestArg.serverName : '', maxServerNameBytes),
|
|
307
|
+
message: controllerElicitationText(typeof requestArg.message === 'string' ? requestArg.message : '', maxMessageBytes),
|
|
308
|
+
createdAt: requestArg.createdAt,
|
|
309
|
+
};
|
|
310
|
+
const unsupported = (reasonArg: string): IControllerElicitationUnsupported => ({ ...base, mode: 'unsupported', reason: reasonArg });
|
|
311
|
+
const mode = requestArg.mode === undefined ? 'form' : requestArg.mode;
|
|
312
|
+
let card: TControllerElicitation;
|
|
313
|
+
if (mode === 'form') {
|
|
314
|
+
const read = controllerElicitationForm(requestArg.requestedSchema);
|
|
315
|
+
card = 'schema' in read ? { ...base, mode: 'form', schema: read.schema } : unsupported(read.unsupported);
|
|
316
|
+
} else if (mode === 'url') {
|
|
317
|
+
const read = readUrl(requestArg.url);
|
|
318
|
+
card = 'url' in read ? { ...base, mode: 'url', url: read.url } : unsupported(read.unsupported);
|
|
319
|
+
} else {
|
|
320
|
+
card = unsupported(modeReason(mode));
|
|
321
|
+
}
|
|
322
|
+
// A card fits the same display budget as a permission or question card; its bounded texts always do.
|
|
323
|
+
return Buffer.byteLength(JSON.stringify(card), 'utf8') <= maxControllerElicitationCardBytes
|
|
324
|
+
? card
|
|
325
|
+
: unsupported('The form is larger than AGL shows.');
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// ----------------------------------------------------------------------------------------------- checking an answer
|
|
329
|
+
|
|
330
|
+
const codePoints = (valueArg: string): number => [...valueArg].length;
|
|
331
|
+
|
|
332
|
+
const validDate = (yearArg: string, monthArg: string, dayArg: string): boolean => {
|
|
333
|
+
const year = Number(yearArg), month = Number(monthArg), day = Number(dayArg);
|
|
334
|
+
if (month < 1 || month > 12 || day < 1) return false;
|
|
335
|
+
return day <= new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const formatValid: Record<TControllerElicitationTextFormat, (valueArg: string) => boolean> = {
|
|
339
|
+
// An address with one @ between a local part and a domain, neither with white space (RFC 5321 in practice).
|
|
340
|
+
email: (valueArg) => /^[^\s@]+@[^\s@]+$/u.test(valueArg),
|
|
341
|
+
// An absolute URI: a scheme, then what URL parsing accepts.
|
|
342
|
+
uri: (valueArg) => /^[A-Za-z][A-Za-z0-9+.-]*:\S*$/u.test(valueArg) && URL.canParse(valueArg),
|
|
343
|
+
// RFC 3339 full-date.
|
|
344
|
+
date: (valueArg) => {
|
|
345
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/u.exec(valueArg);
|
|
346
|
+
return match !== null && validDate(match[1]!, match[2]!, match[3]!);
|
|
347
|
+
},
|
|
348
|
+
// RFC 3339 date-time.
|
|
349
|
+
'date-time': (valueArg) => {
|
|
350
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/u.exec(valueArg);
|
|
351
|
+
if (!match || !validDate(match[1]!, match[2]!, match[3]!)) return false;
|
|
352
|
+
const [hour, minute, second] = [Number(match[4]), Number(match[5]), Number(match[6])];
|
|
353
|
+
if (hour > 23 || minute > 59 || second > 60) return false;
|
|
354
|
+
return match[7] === undefined || (Number(match[7]) <= 23 && Number(match[8]) <= 59);
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const formatNames: Record<TControllerElicitationTextFormat, string> = {
|
|
359
|
+
email: 'an email address', uri: 'an absolute URI', date: 'a date (YYYY-MM-DD)', 'date-time': 'a date and time (RFC 3339)',
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/** Why `valueArg` does not fit the field, in words that name the field and its rule, never the value; `undefined` when it fits. */
|
|
363
|
+
export const controllerElicitationValueProblem = (fieldArg: TControllerElicitationField, valueArg: unknown): string | undefined => {
|
|
364
|
+
const name = fieldName(fieldArg.name);
|
|
365
|
+
switch (fieldArg.kind) {
|
|
366
|
+
case 'text': {
|
|
367
|
+
if (typeof valueArg !== 'string') return `The form's field ${name} takes text.`;
|
|
368
|
+
const length = codePoints(valueArg);
|
|
369
|
+
if (fieldArg.minLength !== undefined && length < fieldArg.minLength) return `The form's field ${name} takes at least ${fieldArg.minLength} characters.`;
|
|
370
|
+
if (fieldArg.maxLength !== undefined && length > fieldArg.maxLength) return `The form's field ${name} takes at most ${fieldArg.maxLength} characters.`;
|
|
371
|
+
if (fieldArg.format !== undefined && !formatValid[fieldArg.format](valueArg)) return `The form's field ${name} takes ${formatNames[fieldArg.format]}.`;
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
case 'number': {
|
|
375
|
+
if (typeof valueArg !== 'number' || !Number.isFinite(valueArg)) return `The form's field ${name} takes a number.`;
|
|
376
|
+
if (fieldArg.integer && !Number.isInteger(valueArg)) return `The form's field ${name} takes a whole number.`;
|
|
377
|
+
if (fieldArg.minimum !== undefined && valueArg < fieldArg.minimum) return `The form's field ${name} takes a number of at least ${fieldArg.minimum}.`;
|
|
378
|
+
if (fieldArg.maximum !== undefined && valueArg > fieldArg.maximum) return `The form's field ${name} takes a number of at most ${fieldArg.maximum}.`;
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
case 'boolean':
|
|
382
|
+
return typeof valueArg === 'boolean' ? undefined : `The form's field ${name} takes yes or no.`;
|
|
383
|
+
case 'choice':
|
|
384
|
+
return typeof valueArg === 'string' && fieldArg.options.some((option) => option.value === valueArg)
|
|
385
|
+
? undefined
|
|
386
|
+
: `The form's field ${name} takes one of its choices.`;
|
|
387
|
+
case 'choices': {
|
|
388
|
+
if (!Array.isArray(valueArg) || valueArg.some((entry) => typeof entry !== 'string' || !fieldArg.options.some((option) => option.value === entry))) {
|
|
389
|
+
return `The form's field ${name} takes some of its choices.`;
|
|
390
|
+
}
|
|
391
|
+
if (new Set(valueArg).size !== valueArg.length) return `The form's field ${name} takes each choice at most once.`;
|
|
392
|
+
if (fieldArg.minItems !== undefined && valueArg.length < fieldArg.minItems) return `The form's field ${name} takes at least ${fieldArg.minItems} choices.`;
|
|
393
|
+
if (fieldArg.maxItems !== undefined && valueArg.length > fieldArg.maxItems) return `The form's field ${name} takes at most ${fieldArg.maxItems} choices.`;
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/** Checks a form's answer against its fields: every field it carries fits, and every required field is there. */
|
|
400
|
+
export const controllerElicitationContent = (schemaArg: IControllerElicitationSchema, contentArg: unknown): TControllerElicitationContent => {
|
|
401
|
+
const content = record(contentArg);
|
|
402
|
+
if (!content) throw new ControllerElicitationReplyError('The answer to a form is an object of field values.', 'invalid_request');
|
|
403
|
+
if (Buffer.byteLength(JSON.stringify(content), 'utf8') > controllerElicitationMaxContentBytes) {
|
|
404
|
+
throw new ControllerElicitationReplyError('The answer is larger than AGL sends.', 'invalid_request');
|
|
405
|
+
}
|
|
406
|
+
const fields = new Map(schemaArg.fields.map((field) => [field.name, field]));
|
|
407
|
+
// The unknown name itself is the owner's input, so it is not repeated.
|
|
408
|
+
if (Object.keys(content).some((key) => !fields.has(key))) throw new ControllerElicitationReplyError('The answer carries a field the form does not define.', 'invalid_request');
|
|
409
|
+
const entries: Array<[string, TControllerElicitationValue]> = [];
|
|
410
|
+
for (const field of schemaArg.fields) {
|
|
411
|
+
if (!Object.hasOwn(content, field.name)) {
|
|
412
|
+
if (field.required) throw new ControllerElicitationReplyError(`The form's field ${fieldName(field.name)} needs a value.`, 'invalid_request');
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
const value = content[field.name];
|
|
416
|
+
const problem = controllerElicitationValueProblem(field, value);
|
|
417
|
+
if (problem !== undefined) throw new ControllerElicitationReplyError(problem, 'invalid_request');
|
|
418
|
+
entries.push([field.name, Array.isArray(value) ? [...value as string[]] : value as TControllerElicitationValue]);
|
|
419
|
+
}
|
|
420
|
+
// `fromEntries` defines each name as a property of its own, also a name such as `__proto__`.
|
|
421
|
+
return Object.fromEntries(entries);
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* The answer the harness sends for the owner's reply to `elicitationArg`. Decline and cancel always pass; accept
|
|
426
|
+
* passes only for a request AGL collects: a form with its content checked against its fields, a URL without content.
|
|
427
|
+
*/
|
|
428
|
+
export const controllerElicitationAnswer = (
|
|
429
|
+
elicitationArg: TControllerElicitation,
|
|
430
|
+
replyArg: TControllerElicitationReply,
|
|
431
|
+
): IControllerElicitationAnswer => {
|
|
432
|
+
if (replyArg.action === 'decline' || replyArg.action === 'cancel') return { action: replyArg.action };
|
|
433
|
+
switch (elicitationArg.mode) {
|
|
434
|
+
case 'unsupported':
|
|
435
|
+
throw new ControllerElicitationReplyError('AGL cannot collect what this request asks for: decline or cancel it.', 'invalid_request');
|
|
436
|
+
case 'url':
|
|
437
|
+
if (replyArg.content !== undefined) throw new ControllerElicitationReplyError('A visit to an address is accepted without content.', 'invalid_request');
|
|
438
|
+
return { action: 'accept' };
|
|
439
|
+
case 'form':
|
|
440
|
+
if (replyArg.content === undefined) throw new ControllerElicitationReplyError('An accepted form carries its content.', 'invalid_request');
|
|
441
|
+
return { action: 'accept', content: controllerElicitationContent(elicitationArg.schema, replyArg.content) };
|
|
442
|
+
}
|
|
443
|
+
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { describeFailure } from './functions.failuredescription.js';
|
|
3
|
+
|
|
1
4
|
export interface IFlexChildShutdownOptions {
|
|
2
5
|
dispose: () => Promise<void>;
|
|
3
6
|
closeDescriptors: () => void;
|
|
@@ -48,3 +51,22 @@ export const createFlexChildShutdown = (
|
|
|
48
51
|
});
|
|
49
52
|
};
|
|
50
53
|
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* What the Flex child writes to its stderr for a fault nothing else handled, before it shuts down
|
|
57
|
+
* with exit code 1: the error's name and message, its causes included, then its stack, one line
|
|
58
|
+
* each. The supervisor writes every stderr line to the controller log with credentials hidden. A
|
|
59
|
+
* thrown value that is not an Error is named by its type and inspected shallowly.
|
|
60
|
+
*/
|
|
61
|
+
export const formatFlexChildFault = (
|
|
62
|
+
kindArg: 'uncaught exception' | 'unhandled rejection',
|
|
63
|
+
errorArg: unknown,
|
|
64
|
+
): string => {
|
|
65
|
+
if (!(errorArg instanceof Error)) {
|
|
66
|
+
const value = plugins.util.inspect(errorArg, { depth: 1, breakLength: Infinity });
|
|
67
|
+
return `Flex child ${kindArg}: a thrown ${typeof errorArg} that is not an Error: ${value}\n`;
|
|
68
|
+
}
|
|
69
|
+
const failure = describeFailure(errorArg);
|
|
70
|
+
const stack = typeof errorArg.stack === 'string' ? errorArg.stack : '';
|
|
71
|
+
return `Flex child ${kindArg}: ${failure.name}: ${failure.message}\n${stack ? `${stack}\n` : ''}`;
|
|
72
|
+
};
|
|
@@ -9,7 +9,9 @@ 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';
|
|
15
17
|
import { currentProxyCredentialHelper, writeProxyCredentialHelper } from './functions.proxycredentialhelper.js';
|
|
@@ -20,14 +22,14 @@ type TAccountPlacementKey = 'lifecycle' | 'lapsesAt' | 'placementScore' | 'place
|
|
|
20
22
|
/**
|
|
21
23
|
* The status a running proxy answers with: one started from an AGL before 38.3.0 reports no accounts and no usage
|
|
22
24
|
* 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.
|
|
25
|
+
* its confined listener nor its runs, one before ChatGPT-pool confined runs no run's pool: its runs are all of the
|
|
26
|
+
* Claude pool, and one before Codex confined runs no run's harness: its runs are all Claude Code's.
|
|
25
27
|
*/
|
|
26
28
|
export type TReportedProxyStatus = Omit<IAglProxyStatus, 'accounts' | 'usageObservations' | 'nextPlacement'
|
|
27
29
|
| 'recentPlacements' | 'confinedSocketPath' | 'confinedRuns'>
|
|
28
30
|
& Partial<Pick<IAglProxyStatus, 'usageObservations' | 'nextPlacement' | 'recentPlacements' | 'confinedSocketPath'>>
|
|
29
|
-
& { confinedRuns?: Array<Omit<IAglProxyStatus['confinedRuns'][number], 'provider'>
|
|
30
|
-
& Partial<Pick<IAglProxyStatus['confinedRuns'][number], 'provider'>>> }
|
|
31
|
+
& { confinedRuns?: Array<Omit<IAglProxyStatus['confinedRuns'][number], 'provider' | 'harness'>
|
|
32
|
+
& Partial<Pick<IAglProxyStatus['confinedRuns'][number], 'provider' | 'harness'>>> }
|
|
31
33
|
& { accounts?: Array<Omit<IAglProxyStatus['accounts'][number], TAccountPlacementKey>
|
|
32
34
|
& Partial<Pick<IAglProxyStatus['accounts'][number], TAccountPlacementKey>>> };
|
|
33
35
|
|
|
@@ -76,8 +78,9 @@ export const formatProxyStatus = (unitArg: string, statusArg: TReportedProxyStat
|
|
|
76
78
|
if (statusArg.confinedSocketPath !== undefined) {
|
|
77
79
|
lines.push(`Confined listener: ${statusArg.confinedSocketPath ?? 'none'}`);
|
|
78
80
|
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.
|
|
81
|
+
// An older proxy names no run's pool: it issues Claude-pool runs alone; nor its harness: it issues Claude Code runs alone.
|
|
82
|
+
lines.push(`Confined run ${run.id}: ${run.harness === 'codex' ? 'Codex on the ChatGPT pool (ChatGPT accounts only)'
|
|
83
|
+
: run.provider === 'openai' ? 'ChatGPT pool' : 'Claude pool'}, issued ${run.createdAt}`
|
|
81
84
|
+ `${run.held ? '' : ', waiting for its launcher to take it back after a proxy restart'}`
|
|
82
85
|
+ ` (end it with \`agl proxy confined end ${run.id}\`)`);
|
|
83
86
|
}
|
|
@@ -214,21 +217,43 @@ const run = (optionsArg: IInferenceCliArguments): Promise<void> => withSignals(a
|
|
|
214
217
|
/**
|
|
215
218
|
* Runs a confined run's container (see `confinedDockerLaunch`) on a credential of its own, which ends when the container
|
|
216
219
|
* 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.
|
|
220
|
+
* ended, stops the container (`docker run` passes the signal on to it), and the run ends with the reason. A Codex run's
|
|
221
|
+
* relay is written to a directory of the run's own before the credential is taken, and removed once the container is gone.
|
|
218
222
|
*/
|
|
219
223
|
const confinedRun = (optionsArg: IInferenceCliArguments): Promise<void> => withSignals(async (signalArg) => {
|
|
220
224
|
await preflightAGLHomeMigration();
|
|
221
225
|
const paths = resolveAGLHomePaths();
|
|
222
|
-
const
|
|
226
|
+
const asked: TAglProxyConfinedRun = optionsArg.harness === 'codex' ? { harness: 'codex', provider: 'openai' }
|
|
227
|
+
: { harness: 'claude', provider: optionsArg.provider ?? 'anthropic' };
|
|
228
|
+
const relay = asked.harness === 'codex' ? await writeConfinedRelay() : undefined;
|
|
229
|
+
try {
|
|
230
|
+
await confinedContainer(optionsArg, signalArg, paths.proxySocket, asked, relay?.directory);
|
|
231
|
+
} finally {
|
|
232
|
+
// A directory left behind holds AGL's relay alone, never a credential; its path is named so it can be removed.
|
|
233
|
+
await relay?.remove().catch((errorArg: unknown) => {
|
|
234
|
+
process.stderr.write(`AGL proxy confined run: the relay directory ${relay.directory} could not be removed: `
|
|
235
|
+
+ `${errorArg instanceof Error ? errorArg.message : String(errorArg)}\n`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
/** One confined run's container on its credential (see `confinedRun`). */
|
|
241
|
+
const confinedContainer = async (optionsArg: IInferenceCliArguments, signalArg: AbortSignal, proxySocketArg: string,
|
|
242
|
+
askedArg: TAglProxyConfinedRun, relayDirectoryArg: string | undefined): Promise<void> => {
|
|
243
|
+
const run = await AglProxyConfinedHolder.take({ socketPath: proxySocketArg, run: askedArg },
|
|
223
244
|
AbortSignal.any([signalArg, AbortSignal.timeout(90_000)]));
|
|
224
245
|
let lost: AglProxyLeaseLostError | undefined;
|
|
225
246
|
try {
|
|
226
247
|
const launch = confinedDockerLaunch({ args: optionsArg.args, socketPath: run.confinedSocketPath, baseUrl: run.baseUrl,
|
|
227
248
|
token: run.token, environment: process.env,
|
|
228
|
-
pool:
|
|
229
|
-
|
|
249
|
+
pool: relayDirectoryArg !== undefined ? { harness: 'codex', relayDirectory: relayDirectoryArg }
|
|
250
|
+
: run.provider === 'anthropic' ? { provider: 'anthropic' } : { provider: 'openai', models: run.models } });
|
|
251
|
+
// A Claude-pool run says what it said before ChatGPT-pool runs; a ChatGPT-pool run says so, and a Codex run where its
|
|
252
|
+
// relay is.
|
|
230
253
|
process.stderr.write(`AGL proxy confined run ${run.id}: ${plugins.path.dirname(run.confinedSocketPath)} is mounted read-only `
|
|
231
|
-
+ `at ${aglProxyConfinedMountPoint}${run.
|
|
254
|
+
+ `at ${aglProxyConfinedMountPoint}${run.harness === 'codex'
|
|
255
|
+
? `, Codex on the ChatGPT pool (ChatGPT accounts only), AGL's relay at ${aglProxyRelayMountPoint}`
|
|
256
|
+
: run.provider === 'openai' ? ', served from the ChatGPT pool' : ''}; `
|
|
232
257
|
+ `end it at once with \`agl proxy confined end ${run.id}\`.\n`);
|
|
233
258
|
signalArg.throwIfAborted();
|
|
234
259
|
const child = plugins.childProcess.spawn(launch.command, launch.args, { env: launch.environment, stdio: 'inherit', shell: false });
|
|
@@ -252,7 +277,7 @@ const confinedRun = (optionsArg: IInferenceCliArguments): Promise<void> => withS
|
|
|
252
277
|
}
|
|
253
278
|
} finally { run.close(); }
|
|
254
279
|
if (lost) throw new Error(`${lost.message} The container was stopped; start the run again to continue.`);
|
|
255
|
-
}
|
|
280
|
+
};
|
|
256
281
|
|
|
257
282
|
const unitState = async (serviceArg: AglProxyService): Promise<string> => {
|
|
258
283
|
try {
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
aglProxyConfinedIdPattern,
|
|
6
6
|
aglProxyConfinedMountPoint,
|
|
7
7
|
aglProxyDefaultPort,
|
|
8
|
+
aglProxyRelayDefaultPort,
|
|
9
|
+
aglProxyRelayFile,
|
|
10
|
+
aglProxyRelayMountPoint,
|
|
8
11
|
aglProxyUnitName,
|
|
9
12
|
defaultProxyClientProvider,
|
|
10
13
|
inferencePlanPattern,
|
|
@@ -27,6 +30,8 @@ export const inferenceCliHelp = `Usage:
|
|
|
27
30
|
agl proxy credential <client> [--provider openai|anthropic] [--delivery file|none] [--write <path>] [--rotate] | --version
|
|
28
31
|
agl proxy run codex|claude|opencode [--provider openai|anthropic] [--account <id>] [--plan <name>] [--model <id>] -- [harness arguments]
|
|
29
32
|
agl proxy confined run [--provider anthropic|openai] -- docker run [docker options] <image> [command]
|
|
33
|
+
agl proxy confined run --harness codex [--provider openai] -- docker run [docker options] <image> \\
|
|
34
|
+
node ${aglProxyRelayMountPoint}/${aglProxyRelayFile} -- codex exec …
|
|
30
35
|
agl proxy confined end <run id>
|
|
31
36
|
|
|
32
37
|
The proxy runs as the ${aglProxyUnitName} user unit (serve runs it in a terminal instead).
|
|
@@ -47,8 +52,14 @@ ChatGPT accounts answer it translated, as for run claude --provider openai. It a
|
|
|
47
52
|
--provider openai sets) right after docker run, prints the run's id on standard error, and ends the credential when the
|
|
48
53
|
container exits. The socket is the proxy user's (0600): run the container as that uid (--user), or as root under
|
|
49
54
|
rootless Docker. Root of a rootful daemon connects as well while it keeps CAP_DAC_OVERRIDE (--cap-drop ALL takes it).
|
|
55
|
+
--harness codex starts Codex's container instead, on the ChatGPT pool's ChatGPT accounts alone (never an OpenAI API
|
|
56
|
+
key): the listener serves it GET /openai/v1/models and POST /openai/v1/responses alone, and refuses a request that
|
|
57
|
+
declares a hosted tool. Codex reaches the socket through AGL's relay, mounted read-only at ${aglProxyRelayMountPoint}:
|
|
58
|
+
the container's command runs node ${aglProxyRelayMountPoint}/${aglProxyRelayFile} -- codex exec …, and the relay listens
|
|
59
|
+
on 127.0.0.1:${aglProxyRelayDefaultPort} inside the container, which therefore keeps a network of its own: --network host
|
|
60
|
+
and --network container:… are refused. It passes AGL_PROXY_SOCKET and MODELPROFILE_PROXY_TOKEN, and no model.
|
|
50
61
|
confined end ends a run's credential at once, and its launcher stops the container; agl proxy status lists the runs
|
|
51
|
-
with their pools.
|
|
62
|
+
with their harnesses and pools.
|
|
52
63
|
Repeat --account or --plan to restrict automatic routing. Only accounts the account service holds are eligible.
|
|
53
64
|
ChatGPT pools: /openai/v1/responses, /anthropic/v1/messages (translated), and each prefix's /models.
|
|
54
65
|
Claude pools: /anthropic/v1/messages, /anthropic/v1/messages/count_tokens and /anthropic/v1/models, sent on as Claude Code sent them.
|
|
@@ -64,6 +75,7 @@ export type TInferenceConfinedAction = 'run' | 'end';
|
|
|
64
75
|
|
|
65
76
|
export interface IInferenceCliArguments {
|
|
66
77
|
command: TInferenceCommand;
|
|
78
|
+
/** `run`'s harness; for `confined run`, `codex` when `--harness codex` names it (Claude Code otherwise). */
|
|
67
79
|
harness?: TInferenceHarness;
|
|
68
80
|
client?: string;
|
|
69
81
|
serviceAction?: TInferenceServiceAction;
|
|
@@ -128,11 +140,20 @@ export const parseInferenceCliArguments = (argvArg: readonly string[]): IInferen
|
|
|
128
140
|
return result;
|
|
129
141
|
}
|
|
130
142
|
if (action !== 'run') throw new Error(inferenceCliHelp);
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
// Each option at most once, before `--`.
|
|
144
|
+
while (argv.length && argv[0] !== '--') {
|
|
145
|
+
const name = argv.shift();
|
|
133
146
|
const value = argv.shift();
|
|
134
|
-
if (
|
|
135
|
-
|
|
147
|
+
if (name === '--provider' && result.provider === undefined) {
|
|
148
|
+
if (!inferenceProviders.includes(value as TInferenceProvider)) throw new Error('--provider is openai or anthropic.');
|
|
149
|
+
result.provider = value as TInferenceProvider;
|
|
150
|
+
} else if (name === '--harness' && result.harness === undefined) {
|
|
151
|
+
if (value !== 'codex') throw new Error('--harness is codex: Codex on the ChatGPT pool. Claude Code runs without it.');
|
|
152
|
+
result.harness = 'codex';
|
|
153
|
+
} else throw new Error(inferenceCliHelp);
|
|
154
|
+
}
|
|
155
|
+
if (result.harness === 'codex' && result.provider === 'anthropic') {
|
|
156
|
+
throw new Error('Codex runs on the ChatGPT pool\'s ChatGPT accounts; --provider anthropic serves Claude Code alone.');
|
|
136
157
|
}
|
|
137
158
|
if (argv.shift() !== '--' || !argv.length) throw new Error(inferenceCliHelp);
|
|
138
159
|
result.confinedAction = 'run';
|