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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
import type {
|
|
3
|
-
IControllerClaudeModelChoice, IControllerEvent, IControllerMessage, IControllerMessageBundle,
|
|
4
|
-
IControllerPermission, IControllerQuestion, IControllerSession, IControllerSessionError,
|
|
5
|
-
TControllerModelRetryReason,
|
|
3
|
+
IControllerAttention, IControllerClaudeModelChoice, IControllerEvent, IControllerMessage, IControllerMessageBundle,
|
|
4
|
+
IControllerMessagePage, IControllerPermission, IControllerQuestion, IControllerSession, IControllerSessionError,
|
|
5
|
+
IControllerSessionRetrying, TControllerElicitation, TControllerElicitationReply, TControllerModelRetryReason,
|
|
6
6
|
} from '../ts_interfaces/index.js';
|
|
7
7
|
import { controllerMaxToolEventBytes } from '../ts_interfaces/index.js';
|
|
8
8
|
import { boundLiveToolExecution, boundToolText, type TLiveToolSnapshot } from './functions.livetoolbounding.js';
|
|
@@ -12,12 +12,15 @@ import {
|
|
|
12
12
|
type IClaudeProjectedTranscript, type IClaudeToolResult,
|
|
13
13
|
} from './classes.claudeprojection.js';
|
|
14
14
|
import { isClaudeSessionNativeId, type IControllerClaudeSessionDocument } from './classes.claudesessionmodels.js';
|
|
15
|
+
import { ControllerElicitationReplyError, controllerElicitation, controllerElicitationAnswer } from './functions.elicitation.js';
|
|
15
16
|
|
|
16
17
|
/** The SDK calls the harness makes; tests hand in a fake. */
|
|
17
18
|
export type TClaudeSdk = Pick<typeof plugins.claudeAgentSdk, 'query' | 'getSessionMessages' | 'getSessionInfo' | 'deleteSession'>;
|
|
18
19
|
type TClaudeQuery = plugins.claudeAgentSdk.Query;
|
|
19
20
|
type TClaudeUserMessage = plugins.claudeAgentSdk.SDKUserMessage;
|
|
20
21
|
type TClaudePermissionResult = plugins.claudeAgentSdk.PermissionResult;
|
|
22
|
+
type TClaudeElicitationRequest = plugins.claudeAgentSdk.ElicitationRequest;
|
|
23
|
+
type TClaudeElicitationResult = plugins.claudeAgentSdk.ElicitationResult;
|
|
21
24
|
type TClaudeEffort = plugins.claudeAgentSdk.EffortLevel;
|
|
22
25
|
type TClaudeToolContext = Parameters<plugins.claudeAgentSdk.CanUseTool>[2];
|
|
23
26
|
type TClaudeInterruptReceipt = plugins.claudeAgentSdk.SDKControlInterruptResponse;
|
|
@@ -183,18 +186,33 @@ interface IClaudeLivePart {
|
|
|
183
186
|
result?: IClaudeToolResult;
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
interface
|
|
189
|
+
interface IClaudePendingBase {
|
|
187
190
|
id: string;
|
|
188
191
|
nativeId: string;
|
|
189
192
|
runtime: IClaudeRuntime;
|
|
190
193
|
bytes: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A tool call Claude Code asks about: a permission card, or a question card for `AskUserQuestion`. */
|
|
197
|
+
interface IClaudePendingTool extends IClaudePendingBase {
|
|
191
198
|
input: Record<string, unknown>;
|
|
192
199
|
resolve: (resultArg: TClaudePermissionResult) => void;
|
|
193
200
|
permission?: IControllerPermission;
|
|
194
201
|
question?: IControllerQuestion;
|
|
195
202
|
questionTexts?: string[];
|
|
203
|
+
elicitation?: never;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** An MCP server's elicitation; Claude Code waits for its answer until the owner gives one or the request is withdrawn. */
|
|
207
|
+
interface IClaudePendingElicitation extends IClaudePendingBase {
|
|
208
|
+
elicitation: TControllerElicitation;
|
|
209
|
+
resolve: (resultArg: TClaudeElicitationResult) => void;
|
|
210
|
+
permission?: never;
|
|
211
|
+
question?: never;
|
|
196
212
|
}
|
|
197
213
|
|
|
214
|
+
type IClaudePendingRequest = IClaudePendingTool | IClaudePendingElicitation;
|
|
215
|
+
|
|
198
216
|
/**
|
|
199
217
|
* What the harness keeps of a conversation. A native session AGL lists outside every project has no `projectId`: it
|
|
200
218
|
* is no AGL conversation record, so the harness reports none of its changes as project events.
|
|
@@ -476,12 +494,13 @@ export class ClaudeHarness {
|
|
|
476
494
|
return [...scopes.values()];
|
|
477
495
|
}
|
|
478
496
|
|
|
479
|
-
public attention(nativeIdArg: string):
|
|
497
|
+
public attention(nativeIdArg: string): IControllerAttention {
|
|
480
498
|
this.state(nativeIdArg);
|
|
481
499
|
const requests = this.requests(nativeIdArg);
|
|
482
500
|
return {
|
|
483
501
|
permissions: requests.flatMap((request) => request.permission ? [structuredClone(request.permission)] : []),
|
|
484
502
|
questions: requests.flatMap((request) => request.question ? [structuredClone(request.question)] : []),
|
|
503
|
+
elicitations: requests.flatMap((request) => request.elicitation ? [structuredClone(request.elicitation)] : []),
|
|
485
504
|
};
|
|
486
505
|
}
|
|
487
506
|
|
|
@@ -507,6 +526,22 @@ export class ClaudeHarness {
|
|
|
507
526
|
this.answer(request, { behavior: 'allow', updatedInput: { ...request.input, answers } });
|
|
508
527
|
}
|
|
509
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Answers an MCP elicitation with the owner's reply, checked against its card first: a reply that does not fit is
|
|
531
|
+
* refused and Claude Code keeps waiting.
|
|
532
|
+
*/
|
|
533
|
+
public replyElicitation(nativeIdArg: string, idArg: string, replyArg: TControllerElicitationReply): void {
|
|
534
|
+
const request = this.pending.get(idArg);
|
|
535
|
+
if (!request?.elicitation || request.nativeId !== nativeIdArg) {
|
|
536
|
+
throw new ControllerElicitationReplyError('The MCP request is no longer pending in this conversation.', 'not_found');
|
|
537
|
+
}
|
|
538
|
+
const { action, content } = controllerElicitationAnswer(request.elicitation, replyArg);
|
|
539
|
+
this.pending.delete(request.id);
|
|
540
|
+
request.resolve(content === undefined ? { action } : { action, content });
|
|
541
|
+
const state = this.states.get(nativeIdArg);
|
|
542
|
+
if (state) this.changed(state, 'permissions.changed');
|
|
543
|
+
}
|
|
544
|
+
|
|
510
545
|
public async listMessagePage(nativeIdArg: string, optionsArg: { limit?: number; before?: string } = {}, signalArg?: AbortSignal): Promise<IControllerMessagePage> {
|
|
511
546
|
const state = this.state(nativeIdArg);
|
|
512
547
|
const projected = await this.transcript(state, signalArg);
|
|
@@ -727,6 +762,7 @@ export class ClaudeHarness {
|
|
|
727
762
|
settingSources: ['user', 'project', 'local'], permissionMode: 'default', includePartialMessages: true,
|
|
728
763
|
systemPrompt: { type: 'preset', preset: 'claude_code' },
|
|
729
764
|
canUseTool: (toolNameArg, toolInputArg, contextArg) => this.canUseTool(runtime, toolNameArg, toolInputArg, contextArg),
|
|
765
|
+
onElicitation: (requestArg, optionsArg) => this.onElicitation(runtime, requestArg, optionsArg.signal),
|
|
730
766
|
stderr: (dataArg) => { runtime.stderr = (runtime.stderr + dataArg).slice(-maxClaudeStderrChars); },
|
|
731
767
|
...(existingTranscript ? { resume: nativeIdArg } : { sessionId: nativeIdArg }),
|
|
732
768
|
...(modelArg ? { model: modelArg.modelID } : {}),
|
|
@@ -825,7 +861,8 @@ export class ClaudeHarness {
|
|
|
825
861
|
for (const request of [...this.pending.values()]) {
|
|
826
862
|
if (request.runtime !== runtimeArg) continue;
|
|
827
863
|
this.pending.delete(request.id);
|
|
828
|
-
request.resolve({
|
|
864
|
+
if (request.elicitation) request.resolve({ action: 'cancel' });
|
|
865
|
+
else request.resolve({ behavior: 'deny', message: 'The Claude Code process ended.' });
|
|
829
866
|
}
|
|
830
867
|
const state = this.states.get(runtimeArg.nativeId);
|
|
831
868
|
if (!state) return;
|
|
@@ -1041,7 +1078,7 @@ export class ClaudeHarness {
|
|
|
1041
1078
|
if (!state || runtimeArg.ended || this.closed) return { behavior: 'deny', message: 'The AGL conversation is closed.' };
|
|
1042
1079
|
const nativeId = runtimeArg.nativeId;
|
|
1043
1080
|
const id = plugins.crypto.randomBytes(24).toString('base64url');
|
|
1044
|
-
let request: Omit<
|
|
1081
|
+
let request: Omit<IClaudePendingTool, 'resolve'>;
|
|
1045
1082
|
try {
|
|
1046
1083
|
const bytes = Buffer.byteLength(JSON.stringify(inputArg ?? null), 'utf8');
|
|
1047
1084
|
if (bytes > 64 * 1024 || this.pending.size >= 128 || [...this.pending.values()].reduce((sum, entry) => sum + entry.bytes, bytes) > 256 * 1024) {
|
|
@@ -1092,7 +1129,7 @@ export class ClaudeHarness {
|
|
|
1092
1129
|
return { behavior: 'deny', message: 'AGL cannot show this request.' };
|
|
1093
1130
|
}
|
|
1094
1131
|
return new Promise<TClaudePermissionResult>((resolve) => {
|
|
1095
|
-
const entry:
|
|
1132
|
+
const entry: IClaudePendingTool = { ...request, resolve };
|
|
1096
1133
|
this.pending.set(id, entry);
|
|
1097
1134
|
const abort = () => {
|
|
1098
1135
|
if (this.pending.get(id) !== entry) return;
|
|
@@ -1106,7 +1143,7 @@ export class ClaudeHarness {
|
|
|
1106
1143
|
});
|
|
1107
1144
|
}
|
|
1108
1145
|
|
|
1109
|
-
private answer(requestArg:
|
|
1146
|
+
private answer(requestArg: IClaudePendingTool, resultArg: TClaudePermissionResult): void {
|
|
1110
1147
|
if (this.pending.get(requestArg.id) !== requestArg) throw new Error('Claude Code request expired before the reply.');
|
|
1111
1148
|
this.pending.delete(requestArg.id);
|
|
1112
1149
|
requestArg.resolve(resultArg);
|
|
@@ -1114,6 +1151,40 @@ export class ClaudeHarness {
|
|
|
1114
1151
|
if (state) this.changed(state, 'permissions.changed');
|
|
1115
1152
|
}
|
|
1116
1153
|
|
|
1154
|
+
/**
|
|
1155
|
+
* An MCP server asks the owner for input: the request becomes a card, and its answer waits for the owner alone. A
|
|
1156
|
+
* request outside what AGL collects is a card too, with its reason, which only decline or cancel answer; one AGL
|
|
1157
|
+
* cannot hold at all (the pending capacity permissions and questions share) is refused with an error, never
|
|
1158
|
+
* answered for the owner. Withdrawing the request (`signalArg`) removes the card, so a later reply is refused.
|
|
1159
|
+
*/
|
|
1160
|
+
private async onElicitation(runtimeArg: IClaudeRuntime, requestArg: TClaudeElicitationRequest, signalArg: AbortSignal): Promise<TClaudeElicitationResult> {
|
|
1161
|
+
const state = this.states.get(runtimeArg.nativeId);
|
|
1162
|
+
if (!state || runtimeArg.ended || this.closed) throw new Error('The AGL conversation is closed.');
|
|
1163
|
+
const nativeId = runtimeArg.nativeId;
|
|
1164
|
+
const id = plugins.crypto.randomBytes(24).toString('base64url');
|
|
1165
|
+
const bytes = Buffer.byteLength(JSON.stringify(requestArg ?? null), 'utf8');
|
|
1166
|
+
if (bytes > 64 * 1024 || this.pending.size >= 128 || [...this.pending.values()].reduce((sum, entry) => sum + entry.bytes, bytes) > 256 * 1024) {
|
|
1167
|
+
throw new Error('AGL cannot hold more requests right now.');
|
|
1168
|
+
}
|
|
1169
|
+
const elicitation = controllerElicitation({
|
|
1170
|
+
id: claudeRuntimeId(id), sessionId: claudeRuntimeId(nativeId), serverName: requestArg.serverName, message: requestArg.message,
|
|
1171
|
+
mode: requestArg.mode, url: requestArg.url, requestedSchema: requestArg.requestedSchema, createdAt: Date.now(),
|
|
1172
|
+
});
|
|
1173
|
+
return new Promise<TClaudeElicitationResult>((resolve) => {
|
|
1174
|
+
const entry: IClaudePendingElicitation = { id, nativeId, runtime: runtimeArg, bytes, elicitation, resolve };
|
|
1175
|
+
this.pending.set(id, entry);
|
|
1176
|
+
const abort = () => {
|
|
1177
|
+
if (this.pending.get(id) !== entry) return;
|
|
1178
|
+
this.pending.delete(id);
|
|
1179
|
+
resolve({ action: 'cancel' });
|
|
1180
|
+
this.changed(state, 'permissions.changed');
|
|
1181
|
+
};
|
|
1182
|
+
signalArg.addEventListener('abort', abort, { once: true });
|
|
1183
|
+
if (signalArg.aborted) { abort(); return; }
|
|
1184
|
+
this.changed(state, 'permissions.changed');
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1117
1188
|
private async transcript(stateArg: IClaudeSessionState, signalArg?: AbortSignal): Promise<IClaudeProjectedTranscript> {
|
|
1118
1189
|
signalArg?.throwIfAborted();
|
|
1119
1190
|
const nativeId = stateArg.document.nativeId;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
-
import type { IControllerUsage, IControllerCodexActivity, IControllerCodexActivitySummary, IControllerCodexCollaborationMode, IControllerCodexModelChoice, IControllerCodexModelOption, IControllerEvent, IControllerMessagePage, IControllerMessageBundle, IControllerNativeWait, IControllerPermission, IControllerQuestion, IControllerSession, IControllerSessionError, TControllerCodexCollaborationMode, TControllerCodexCollaborationModeAuthority, TControllerSessionStatus } from '../ts_interfaces/index.js';
|
|
2
|
+
import type { IControllerAttention, IControllerUsage, IControllerCodexActivity, IControllerCodexActivitySummary, IControllerCodexCollaborationMode, IControllerCodexModelChoice, IControllerCodexModelOption, IControllerEvent, IControllerMessagePage, IControllerMessageBundle, IControllerNativeWait, IControllerPermission, IControllerQuestion, IControllerSession, IControllerSessionError, TControllerCodexCollaborationMode, TControllerCodexCollaborationModeAuthority, TControllerElicitation, TControllerElicitationReply, TControllerSessionStatus } from '../ts_interfaces/index.js';
|
|
3
3
|
import { controllerMaxToolEventBytes } from '../ts_interfaces/index.js';
|
|
4
4
|
import { CodexSupervisor } from './classes.codexsupervisor.js';
|
|
5
5
|
import { codexArray, codexBoundedText, codexNativeWait, codexNonnegativeInteger, codexItemBundle, codexRecord, codexRuntimeId, codexSession, codexSessionId, codexString, codexText, codexThreadId, codexTurnError, codexTurnErrorBundle, codexTurnUsage, codexUsageTotal, isCodexTerminalItemStatus, type ICodexUsageTotal, type TCodexAnswerMeta, type TCodexTerminalTurnStatus } from './classes.codexprojection.js';
|
|
6
6
|
import { codexPublicThreadId, codexQualifiedIdentity } from './functions.codexidentity.js';
|
|
7
|
+
import { ControllerElicitationReplyError, controllerElicitation, controllerElicitationAnswer } from './functions.elicitation.js';
|
|
7
8
|
import { maxCodexTurnPartialReplyBytes, maxCodexTurnRecordsPerSession, maxCodexTurnStopAnchors, type ICodexTurnRecord, type ICodexTurnRecordStore, type ICodexTurnStop } from './classes.codexturnstore.js';
|
|
8
9
|
|
|
9
10
|
interface ICodexSessionScope { projectId: string; directory: string; session: IControllerSession; revision: number; statusRevision: number; closedRevision: number }
|
|
10
11
|
interface ICodexLiveItem { turnId: string; item: Record<string, unknown>; completed: boolean; bytes: number; terminalTurnStatus?: TCodexTerminalTurnStatus }
|
|
11
|
-
interface ICodexPendingRequest { bytes: number; request: plugins.crossharness.ICodexAppServerRequest; permission?: IControllerPermission; question?: IControllerQuestion; questionIds?: string[] }
|
|
12
|
+
interface ICodexPendingRequest { bytes: number; request: plugins.crossharness.ICodexAppServerRequest; permission?: IControllerPermission; question?: IControllerQuestion; questionIds?: string[]; elicitation?: TControllerElicitation }
|
|
12
13
|
interface ICodexTurnAdmission { turnId?: string; clientMessageId: string; onUserMessage?: (idArg: string) => void; terminal: Set<string>; armed: boolean; complete: () => void }
|
|
13
14
|
/**
|
|
14
15
|
* What AGL observed of one turn for the line under its answer, and how a stopped turn ended.
|
|
@@ -116,6 +117,22 @@ export class CodexCollaborationModeOutcomeUnknownError extends Error {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Codex's `mcpServer/elicitation/request` as AGL's card, read by the one normaliser: `form` and `url` as MCP defines
|
|
122
|
+
* them; every other mode Codex names (`openai/form`, `openaiForm`, `openai/userVerification`, any later one) is an
|
|
123
|
+
* unsupported card with the reason, which the owner declines or cancels. A mode without a message
|
|
124
|
+
* (`openai/userVerification`) says what it asks in its title and description; its `challenge` is opaque and is
|
|
125
|
+
* never read into the card.
|
|
126
|
+
*/
|
|
127
|
+
const codexElicitation = (idArg: string, threadIdArg: string, paramsArg: Record<string, unknown>): TControllerElicitation => controllerElicitation({
|
|
128
|
+
id: codexRuntimeId(idArg), sessionId: codexRuntimeId(threadIdArg), serverName: paramsArg.serverName,
|
|
129
|
+
message: typeof paramsArg.message === 'string'
|
|
130
|
+
? paramsArg.message
|
|
131
|
+
: [paramsArg.title, paramsArg.description].filter((entry): entry is string => typeof entry === 'string' && entry.length > 0).join('\n\n'),
|
|
132
|
+
// Codex names the mode on every request; MCP's absent mode (a form) is not Codex's to send.
|
|
133
|
+
mode: paramsArg.mode ?? null, url: paramsArg.url, requestedSchema: paramsArg.requestedSchema, createdAt: Date.now(),
|
|
134
|
+
});
|
|
135
|
+
|
|
119
136
|
/** Native app-server projection. Only explicitly admitted AGL threads may subscribe or answer requests. */
|
|
120
137
|
export class CodexClientAdapter {
|
|
121
138
|
private readonly scopes = new Map<string, ICodexSessionScope>();
|
|
@@ -1086,10 +1103,11 @@ export class CodexClientAdapter {
|
|
|
1086
1103
|
return [...result.values()];
|
|
1087
1104
|
}
|
|
1088
1105
|
|
|
1089
|
-
public attention(threadIdArg: string):
|
|
1106
|
+
public attention(threadIdArg: string): IControllerAttention {
|
|
1090
1107
|
this.scope(threadIdArg);
|
|
1091
1108
|
const requests = [...this.pending.values()].filter((entry) => entry.request.params.threadId === threadIdArg);
|
|
1092
|
-
return { permissions: requests.flatMap((entry) => entry.permission ? [entry.permission] : []), questions: requests.flatMap((entry) => entry.question ? [entry.question] : [])
|
|
1109
|
+
return { permissions: requests.flatMap((entry) => entry.permission ? [entry.permission] : []), questions: requests.flatMap((entry) => entry.question ? [entry.question] : []),
|
|
1110
|
+
elicitations: requests.flatMap((entry) => entry.elicitation ? [entry.elicitation] : []) };
|
|
1093
1111
|
}
|
|
1094
1112
|
|
|
1095
1113
|
public async startTurn(threadIdArg: string, textArg: string, clientMessageIdArg: string, modelArg: IControllerCodexModelChoice | undefined, beforeDispatchArg: () => Promise<void>, completeArg: () => void, signalArg?: AbortSignal, onUserMessageArg?: (idArg: string) => void, cancelUndispatchedArg?: () => Promise<void>, collaborationModeArg?: ICodexPreparedCollaborationMode): Promise<() => void> {
|
|
@@ -1874,8 +1892,10 @@ export class CodexClientAdapter {
|
|
|
1874
1892
|
questions: questions.map((question) => ({ question: codexString(question.question, 16 * 1024), header: codexString(question.header, 512),
|
|
1875
1893
|
custom: question.isOther === true || question.options === null,
|
|
1876
1894
|
options: question.options === null ? [] : codexArray(question.options, 64).map((option) => ({ label: codexString(codexRecord(option).label, 1024), description: codexString(codexRecord(option).description, 4096) })) })) };
|
|
1895
|
+
} else if (requestArg.method === 'mcpServer/elicitation/request') {
|
|
1896
|
+
pending.elicitation = codexElicitation(id, threadId, params);
|
|
1877
1897
|
} else { client.rejectRequest(requestArg.id, -32601, 'This Codex host request is not supported by AGL.'); return; }
|
|
1878
|
-
if (Buffer.byteLength(JSON.stringify(pending.permission ?? pending.question), 'utf8') > 64 * 1024) throw new Error('Codex attention request exceeds its display capacity.');
|
|
1898
|
+
if (Buffer.byteLength(JSON.stringify(pending.permission ?? pending.question ?? pending.elicitation), 'utf8') > 64 * 1024) throw new Error('Codex attention request exceeds its display capacity.');
|
|
1879
1899
|
this.pending.set(id, pending);
|
|
1880
1900
|
requestArg.signal.addEventListener('abort', () => { this.pending.delete(id); this.changed(threadId, 'permissions.changed'); }, { once: true });
|
|
1881
1901
|
if (requestArg.signal.aborted) { this.pending.delete(id); return; }
|
|
@@ -1908,6 +1928,22 @@ export class CodexClientAdapter {
|
|
|
1908
1928
|
if (!this.supervisor.requireClient().respond(pending.request.id, { answers })) throw new Error('Codex question expired before the reply.');
|
|
1909
1929
|
}
|
|
1910
1930
|
|
|
1931
|
+
/**
|
|
1932
|
+
* Answers an MCP elicitation on the JSON-RPC id Codex asked it with, once the owner's reply fits its card: a reply
|
|
1933
|
+
* that does not fit is refused and Codex keeps waiting.
|
|
1934
|
+
*/
|
|
1935
|
+
public replyElicitation(threadIdArg: string, idArg: string, replyArg: TControllerElicitationReply): void {
|
|
1936
|
+
this.scope(threadIdArg);
|
|
1937
|
+
const pending = this.pending.get(idArg);
|
|
1938
|
+
if (!pending?.elicitation || pending.request.params.threadId !== threadIdArg) {
|
|
1939
|
+
throw new ControllerElicitationReplyError('The MCP request is no longer pending in this conversation.', 'not_found');
|
|
1940
|
+
}
|
|
1941
|
+
const answer = controllerElicitationAnswer(pending.elicitation, replyArg);
|
|
1942
|
+
if (!this.supervisor.requireClient().respond(pending.request.id, { action: answer.action, content: answer.content ?? null, _meta: null })) {
|
|
1943
|
+
throw new ControllerElicitationReplyError('The MCP request expired before the reply.', 'not_found');
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1911
1947
|
/**
|
|
1912
1948
|
* A session change carries the live status with it, as OpenCode's status events do: the browser
|
|
1913
1949
|
* follows the turn from these events instead of waiting for its next conversation list.
|
package/ts/classes.controller.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { flexMessageDeliveryProof, type TFlexDeliveryEvidence, type TFlexDeliveryProof } from './functions.flexdeliveryproof.js';
|
|
2
2
|
import { FleetWorkers, fleetNativeSessionNames } from './fleet/classes.workers.js';
|
|
3
3
|
import { FleetTicketEffects } from './fleet/classes.ticketeffects.js';
|
|
4
|
-
import { FleetDispatchError } from './fleet/interfaces.workers.js';
|
|
4
|
+
import { FleetDispatchError, FleetWorkerError } from './fleet/interfaces.workers.js';
|
|
5
5
|
import type { TFleetWorkerAction, TFleetWorkerRequest } from '../ts_interfaces/fleetworkers.js';
|
|
6
6
|
import { ControllerBrowserOperationAuthority } from './classes.browseroperationauthority.js';
|
|
7
7
|
import { ControllerWorkerCallers, type IWorkerCodexCallerOrigin } from './classes.workercallers.js';
|
|
@@ -98,12 +98,14 @@ import {
|
|
|
98
98
|
assertDeviceRevokeRequest,
|
|
99
99
|
assertDevicePermissionReplyRequest,
|
|
100
100
|
assertDeviceQuestionReplyRequest,
|
|
101
|
+
assertDeviceElicitationReplyRequest,
|
|
101
102
|
assertDeviceSessionReadRequest,
|
|
102
103
|
assertDeviceSessionSendRequest,
|
|
103
104
|
deviceEvent,
|
|
104
105
|
deviceMessages,
|
|
105
106
|
devicePermissions,
|
|
106
107
|
deviceQuestions,
|
|
108
|
+
deviceElicitations,
|
|
107
109
|
deviceRelayedEventTypes,
|
|
108
110
|
deviceSessionRow,
|
|
109
111
|
deviceSessionRows,
|
|
@@ -138,6 +140,7 @@ import {
|
|
|
138
140
|
controllerMaximumMessageBundles,
|
|
139
141
|
controllerMaximumTranscriptBytes,
|
|
140
142
|
controllerLiveToolExecutionIsCovered,
|
|
143
|
+
controllerAttentionPending,
|
|
141
144
|
controllerProtocolVersion,
|
|
142
145
|
controllerUpgradeManagementVersion,
|
|
143
146
|
controllerManagementProtocolVersion,
|
|
@@ -179,6 +182,7 @@ import {
|
|
|
179
182
|
type IControllerProject,
|
|
180
183
|
type IControllerProviderConnection,
|
|
181
184
|
type IControllerQuestion,
|
|
185
|
+
type IControllerAttention,
|
|
182
186
|
type IControllerRuntimeId,
|
|
183
187
|
type IControllerSession,
|
|
184
188
|
type IControllerSessionGroup,
|
|
@@ -217,6 +221,7 @@ import {
|
|
|
217
221
|
type IReq_ControllerProviderModelRefreshGet,
|
|
218
222
|
type IReq_ControllerPermissionReply,
|
|
219
223
|
type IReq_ControllerQuestionReply,
|
|
224
|
+
type IReq_ControllerElicitationReply,
|
|
220
225
|
type IReq_ControllerSessionRename,
|
|
221
226
|
type IReq_ControllerSessionArchive,
|
|
222
227
|
type IReq_ControllerSessionYolo,
|
|
@@ -362,6 +367,7 @@ import {
|
|
|
362
367
|
type IReq_DevicePair,
|
|
363
368
|
type IReq_DevicePermissionReply,
|
|
364
369
|
type IReq_DeviceQuestionReply,
|
|
370
|
+
type IReq_DeviceElicitationReply,
|
|
365
371
|
type IReq_DeviceSessionRead,
|
|
366
372
|
type IReq_DeviceSessionSend,
|
|
367
373
|
type IReq_DeviceSessionsList,
|
|
@@ -520,6 +526,7 @@ import type {
|
|
|
520
526
|
IReq_ControllerNativeSessionIntelligenceAsk,
|
|
521
527
|
IReq_ControllerNativeSessionPermissionReply,
|
|
522
528
|
IReq_ControllerNativeSessionQuestionReply,
|
|
529
|
+
IReq_ControllerNativeSessionElicitationReply,
|
|
523
530
|
IReq_ControllerNativeSessionRead,
|
|
524
531
|
IReq_ControllerNativeSessionScratchpadSave,
|
|
525
532
|
IReq_ControllerNativeSessionSend,
|
|
@@ -630,6 +637,7 @@ import {
|
|
|
630
637
|
assertProviderModelRefreshGetRequest,
|
|
631
638
|
assertPermissionReplyRequest,
|
|
632
639
|
assertQuestionReplyRequest,
|
|
640
|
+
assertElicitationReplyRequest,
|
|
633
641
|
assertSessionRenameRequest,
|
|
634
642
|
assertSessionArchiveRequest,
|
|
635
643
|
assertSessionYoloRequest,
|
|
@@ -715,6 +723,7 @@ import {
|
|
|
715
723
|
assertNativeSessionIntelligenceAskRequest,
|
|
716
724
|
assertNativeSessionPermissionReplyRequest,
|
|
717
725
|
assertNativeSessionQuestionReplyRequest,
|
|
726
|
+
assertNativeSessionElicitationReplyRequest,
|
|
718
727
|
assertStandardProjectDirectories,
|
|
719
728
|
assertSessionMessagesPageRequest,
|
|
720
729
|
assertSessionMessageGetRequest,
|
|
@@ -821,7 +830,8 @@ import {
|
|
|
821
830
|
} from './constants.upgradeenvironment.js';
|
|
822
831
|
import { ControllerAgentMessageLimiter } from './classes.agentmessagelimiter.js';
|
|
823
832
|
import { agentMessageSubjects, formatAgentMessage, formatOwnerFleetMessage } from './functions.agentmessage.js';
|
|
824
|
-
import { FleetNativeTurnError } from './fleet/interfaces.workers.js';
|
|
833
|
+
import { FleetNativeTurnError, type TFleetNativeReply } from './fleet/interfaces.workers.js';
|
|
834
|
+
import { ControllerElicitationReplyError } from './functions.elicitation.js';
|
|
825
835
|
import {
|
|
826
836
|
isModelChoiceOffered,
|
|
827
837
|
resolveFlexDefaultModel,
|
|
@@ -2416,6 +2426,16 @@ const assertNativeSessionWritable = (resolvedArg: IResolvedNativeSession): void
|
|
|
2416
2426
|
const { readOnly } = resolvedArg.session;
|
|
2417
2427
|
if (readOnly) throw new plugins.typedrequest.TypedResponseError(readOnly.message, { code: 'session_read_only' });
|
|
2418
2428
|
};
|
|
2429
|
+
/**
|
|
2430
|
+
* A harness's refusal of an elicitation reply -- the answer does not fit the request, or the request is gone -- as the
|
|
2431
|
+
* typed refusal it is; its text never carries what the owner entered. Every other error passes as it is.
|
|
2432
|
+
*/
|
|
2433
|
+
const elicitationRefusal = (errorArg: unknown): unknown => (
|
|
2434
|
+
errorArg instanceof ControllerElicitationReplyError
|
|
2435
|
+
? new plugins.typedrequest.TypedResponseError(errorArg.message, { code: errorArg.code })
|
|
2436
|
+
: errorArg
|
|
2437
|
+
);
|
|
2438
|
+
|
|
2419
2439
|
const validateRequest = <T>(validatorArg: () => T): T => {
|
|
2420
2440
|
try {
|
|
2421
2441
|
return validatorArg();
|
|
@@ -5911,7 +5931,7 @@ export class OpenCodeController {
|
|
|
5911
5931
|
if (!managed) throw new plugins.typedrequest.TypedResponseError('The Codex conversation is not managed by AGL.', { code: 'session_not_found' });
|
|
5912
5932
|
const canonical = client.register(projectIdArg, directoryArg, session);
|
|
5913
5933
|
this.setManagedSessionAuthority(projectIdArg, session.id, 'managed', managed.identity.sessionIdentityId);
|
|
5914
|
-
return { ...canonical, ...(
|
|
5934
|
+
return { ...canonical, ...(controllerAttentionPending(client.attention(nativeIdArg)) ? { attention: true } : {}) };
|
|
5915
5935
|
}
|
|
5916
5936
|
|
|
5917
5937
|
private async listManagedCodexSessions(projectIdArg: string, directoryArg: string, signalArg: AbortSignal,
|
|
@@ -6001,7 +6021,7 @@ export class OpenCodeController {
|
|
|
6001
6021
|
await client.refreshActivity(session.id.nativeId, signalArg).catch(() => undefined);
|
|
6002
6022
|
}
|
|
6003
6023
|
return { ...canonical, codexActivity: client.activitySummary(session.id.nativeId),
|
|
6004
|
-
...(attention
|
|
6024
|
+
...(controllerAttentionPending(attention) ? { attention: true } : {}) };
|
|
6005
6025
|
} catch (error) {
|
|
6006
6026
|
if (!(error instanceof ControllerSessionIdentityError)) throw error;
|
|
6007
6027
|
this.withholdRefusedListedSession(projectIdArg, session.id, error);
|
|
@@ -6028,7 +6048,7 @@ export class OpenCodeController {
|
|
|
6028
6048
|
await client.refreshActivity(session.id.nativeId, signalArg).catch(() => undefined);
|
|
6029
6049
|
}
|
|
6030
6050
|
result.push({ connection: 'connected', session: { ...canonical, codexActivity: client.activitySummary(session.id.nativeId),
|
|
6031
|
-
...(attention
|
|
6051
|
+
...(controllerAttentionPending(attention) ? { attention: true } : {}) } });
|
|
6032
6052
|
}
|
|
6033
6053
|
return result;
|
|
6034
6054
|
}
|
|
@@ -9778,7 +9798,12 @@ export class OpenCodeController {
|
|
|
9778
9798
|
const caller = this.mcpCaller();
|
|
9779
9799
|
const reportsTo = ['start', 'adopt', 'refresh', 'move'].includes(action) && caller.subject.kind !== 'anonymous'
|
|
9780
9800
|
? await this.requireDirectReports().reportOf(owner.resourceId, ticketActorFromCaller(caller).sessionId) : undefined;
|
|
9781
|
-
|
|
9801
|
+
try {
|
|
9802
|
+
return await this.requireFleetWorkers().execute(action, input as TFleetWorkerRequest<typeof action>, master.fleet ?? {}, owner.resourceId, operationSignal, actor, reportsTo);
|
|
9803
|
+
} catch (errorArg) {
|
|
9804
|
+
if (errorArg instanceof FleetWorkerError) throw new plugins.typedrequest.TypedResponseError(errorArg.message, { code: errorArg.code });
|
|
9805
|
+
throw errorArg;
|
|
9806
|
+
}
|
|
9782
9807
|
}),
|
|
9783
9808
|
sessionFeed: {
|
|
9784
9809
|
list: (request, signal) => run(signal, async () => {
|
|
@@ -13878,6 +13903,7 @@ export class OpenCodeController {
|
|
|
13878
13903
|
before: page.nextCursor ?? null,
|
|
13879
13904
|
permissions: devicePermissions(detail.permissions),
|
|
13880
13905
|
questions: deviceQuestions(detail.questions),
|
|
13906
|
+
elicitations: deviceElicitations(detail.elicitations),
|
|
13881
13907
|
};
|
|
13882
13908
|
}
|
|
13883
13909
|
// As for a conversation, `limit` sizes older pages only; the newest page is the controller's own bound.
|
|
@@ -13891,6 +13917,7 @@ export class OpenCodeController {
|
|
|
13891
13917
|
before: native.messagePage.nextCursor ?? null,
|
|
13892
13918
|
permissions: devicePermissions(native.permissions),
|
|
13893
13919
|
questions: deviceQuestions(native.questions),
|
|
13920
|
+
elicitations: deviceElicitations(native.elicitations),
|
|
13894
13921
|
};
|
|
13895
13922
|
}, toolsArg?.abortSignal);
|
|
13896
13923
|
});
|
|
@@ -13963,6 +13990,30 @@ export class OpenCodeController {
|
|
|
13963
13990
|
}, signalArg);
|
|
13964
13991
|
}, toolsArg?.abortSignal);
|
|
13965
13992
|
});
|
|
13993
|
+
|
|
13994
|
+
routerArg.addHandler<IReq_DeviceElicitationReply>('device.elicitation.reply', async (requestArg, toolsArg) => {
|
|
13995
|
+
const request = validateRequest(() => assertDeviceElicitationReplyRequest(requestArg));
|
|
13996
|
+
const { peer, deviceId } = this.requestDevice(toolsArg?.localData);
|
|
13997
|
+
return this.runDeviceOperation(peer, deviceId, async (signalArg) => {
|
|
13998
|
+
const auditPeerId = deviceAuditPeerId(deviceId);
|
|
13999
|
+
const { open } = await this.deviceSessionTarget(request.sessionId);
|
|
14000
|
+
if (open.kind === 'conversation') {
|
|
14001
|
+
return this.replyElicitationForPrincipal('device', auditPeerId, validateRequest(() => assertElicitationReplyRequest({
|
|
14002
|
+
projectId: open.projectId,
|
|
14003
|
+
sessionId: open.sessionId,
|
|
14004
|
+
requestId: { harnessId: open.sessionId.harnessId, nativeId: request.elicitationId },
|
|
14005
|
+
reply: request.reply,
|
|
14006
|
+
})), signalArg);
|
|
14007
|
+
}
|
|
14008
|
+
const ref = nativeSessionRefOfFeed(open);
|
|
14009
|
+
const native = validateRequest(() => assertNativeSessionElicitationReplyRequest({
|
|
14010
|
+
session: ref, requestId: { harnessId: ref.harness, nativeId: request.elicitationId }, reply: request.reply,
|
|
14011
|
+
}));
|
|
14012
|
+
return this.replyNativeSessionForPrincipal('device', auditPeerId, {
|
|
14013
|
+
session: native.session, requestId: native.requestId, elicitation: native.reply,
|
|
14014
|
+
}, signalArg);
|
|
14015
|
+
}, toolsArg?.abortSignal);
|
|
14016
|
+
});
|
|
13966
14017
|
}
|
|
13967
14018
|
|
|
13968
14019
|
/**
|
|
@@ -16735,6 +16786,48 @@ export class OpenCodeController {
|
|
|
16735
16786
|
));
|
|
16736
16787
|
},
|
|
16737
16788
|
);
|
|
16789
|
+
|
|
16790
|
+
protectedRouterArg.addHandler<IReq_ControllerElicitationReply>(
|
|
16791
|
+
'controller.elicitation.reply',
|
|
16792
|
+
async (requestArg, toolsArg) => {
|
|
16793
|
+
const peer = peerFromLocalData(toolsArg?.localData);
|
|
16794
|
+
const request = validateRequest(() => assertElicitationReplyRequest(requestArg));
|
|
16795
|
+
return this.runOperation(peer, async (signalArg) => this.replyElicitationForPrincipal(
|
|
16796
|
+
'browser', peer.id, request, signalArg,
|
|
16797
|
+
));
|
|
16798
|
+
},
|
|
16799
|
+
);
|
|
16800
|
+
}
|
|
16801
|
+
|
|
16802
|
+
/**
|
|
16803
|
+
* Answers an MCP elicitation of a Claude Code or Codex conversation, for the owner's browser and a paired device
|
|
16804
|
+
* alike. The harness checks the reply against the pending request before it sends anything; elicitations are never
|
|
16805
|
+
* answered automatically, auto-accept included.
|
|
16806
|
+
*/
|
|
16807
|
+
private async replyElicitationForPrincipal(
|
|
16808
|
+
principalArg: TControllerOperationPrincipal,
|
|
16809
|
+
peerIdArg: string,
|
|
16810
|
+
requestArg: IReq_ControllerElicitationReply['request'],
|
|
16811
|
+
signalArg: AbortSignal,
|
|
16812
|
+
): Promise<IReq_ControllerElicitationReply['response']> {
|
|
16813
|
+
const { projectId, sessionId, requestId, reply } = requestArg;
|
|
16814
|
+
return this.runAudited(
|
|
16815
|
+
{ type: 'elicitation.reply', peerId: this.auditPeerId(principalArg, peerIdArg), sessionId, requestId },
|
|
16816
|
+
async () => {
|
|
16817
|
+
await this.resolveProject(projectId);
|
|
16818
|
+
await this.assertSessionExists(projectId, sessionId, signalArg);
|
|
16819
|
+
return this.withHarnessSubmissionAdmission(projectId, sessionId, signalArg, async () => {
|
|
16820
|
+
signalArg.throwIfAborted();
|
|
16821
|
+
try {
|
|
16822
|
+
if (sessionId.harnessId === 'codex') this.requireCodexClient(sessionId.nativeId).replyElicitation(sessionId.nativeId, requestId.nativeId, reply);
|
|
16823
|
+
else this.requireClaudeHarness().replyElicitation(sessionId.nativeId, requestId.nativeId, reply);
|
|
16824
|
+
} catch (errorArg) {
|
|
16825
|
+
throw elicitationRefusal(errorArg);
|
|
16826
|
+
}
|
|
16827
|
+
return { success: true };
|
|
16828
|
+
});
|
|
16829
|
+
},
|
|
16830
|
+
);
|
|
16738
16831
|
}
|
|
16739
16832
|
|
|
16740
16833
|
/**
|
|
@@ -17920,6 +18013,17 @@ export class OpenCodeController {
|
|
|
17920
18013
|
), toolsArg?.abortSignal);
|
|
17921
18014
|
},
|
|
17922
18015
|
);
|
|
18016
|
+
|
|
18017
|
+
protectedRouterArg.addHandler<IReq_ControllerNativeSessionElicitationReply>(
|
|
18018
|
+
'controller.nativesession.elicitation.reply',
|
|
18019
|
+
async (requestArg, toolsArg) => {
|
|
18020
|
+
const peer = peerFromLocalData(toolsArg?.localData);
|
|
18021
|
+
const request = validateRequest(() => assertNativeSessionElicitationReplyRequest(requestArg));
|
|
18022
|
+
return this.runOperation(peer, (signalArg) => this.replyNativeSessionForPrincipal(
|
|
18023
|
+
'browser', peer.id, { session: request.session, requestId: request.requestId, elicitation: request.reply }, signalArg,
|
|
18024
|
+
), toolsArg?.abortSignal);
|
|
18025
|
+
},
|
|
18026
|
+
);
|
|
17923
18027
|
}
|
|
17924
18028
|
|
|
17925
18029
|
/**
|
|
@@ -17961,28 +18065,27 @@ export class OpenCodeController {
|
|
|
17961
18065
|
}
|
|
17962
18066
|
|
|
17963
18067
|
/**
|
|
17964
|
-
* Answers a permission (`permission`)
|
|
17965
|
-
* session, for the owner's browser and a paired device alike. The
|
|
18068
|
+
* Answers a permission (`permission`), a question (`answers`, `null` rejects it) or an MCP elicitation
|
|
18069
|
+
* (`elicitation`) of AGL's own turn in a native session, for the owner's browser and a paired device alike. The
|
|
18070
|
+
* request must still be pending.
|
|
17966
18071
|
*/
|
|
17967
18072
|
private async replyNativeSessionForPrincipal(
|
|
17968
18073
|
principalArg: TControllerOperationPrincipal,
|
|
17969
18074
|
peerIdArg: string,
|
|
17970
|
-
requestArg: { session: IControllerNativeSessionRef; requestId: IControllerRuntimeId }
|
|
17971
|
-
& ({ permission: TControllerPermissionReply } | { answers: string[][] | null }),
|
|
18075
|
+
requestArg: { session: IControllerNativeSessionRef; requestId: IControllerRuntimeId } & TFleetNativeReply,
|
|
17972
18076
|
signalArg: AbortSignal,
|
|
17973
18077
|
): Promise<{ success: boolean }> {
|
|
17974
18078
|
const { session: ref, requestId } = requestArg;
|
|
17975
|
-
const kind
|
|
18079
|
+
const [kind, reply]: ['permission' | 'question' | 'elicitation', TFleetNativeReply] = 'permission' in requestArg
|
|
18080
|
+
? ['permission', { permission: requestArg.permission }]
|
|
18081
|
+
: 'elicitation' in requestArg
|
|
18082
|
+
? ['elicitation', { elicitation: requestArg.elicitation }]
|
|
18083
|
+
: ['question', { answers: requestArg.answers }];
|
|
17976
18084
|
return this.runAudited(
|
|
17977
18085
|
{ type: `${kind}.reply`, peerId: this.auditPeerId(principalArg, peerIdArg), sessionId: nativeSessionRuntimeId(ref), requestId },
|
|
17978
18086
|
() => this.serveNativeSession(signalArg, async () => {
|
|
17979
18087
|
const resolved = await this.nativeSessions.resolve(ref);
|
|
17980
|
-
await this.replyNativeSessionRequest(
|
|
17981
|
-
resolved,
|
|
17982
|
-
requestId.nativeId,
|
|
17983
|
-
'permission' in requestArg ? { permission: requestArg.permission } : { answers: requestArg.answers },
|
|
17984
|
-
kind,
|
|
17985
|
-
);
|
|
18088
|
+
await this.replyNativeSessionRequest(resolved, requestId.nativeId, reply, kind);
|
|
17986
18089
|
return { success: true };
|
|
17987
18090
|
}),
|
|
17988
18091
|
);
|
|
@@ -17991,33 +18094,39 @@ export class OpenCodeController {
|
|
|
17991
18094
|
/** The requests of AGL's own turns in a native session that wait for an answer. */
|
|
17992
18095
|
private async nativeSessionAttention(
|
|
17993
18096
|
resolvedArg: IResolvedNativeSession,
|
|
17994
|
-
): Promise<
|
|
18097
|
+
): Promise<IControllerAttention> {
|
|
17995
18098
|
const { session, native } = resolvedArg;
|
|
17996
18099
|
if (session.harness === 'codex') return await this.requireFleetWorkers().nativeAttention('codex', native);
|
|
17997
18100
|
const harness = this.claudeHarness;
|
|
17998
18101
|
return harness && !harness.closed && harness.isRegistered(native.nativeId)
|
|
17999
18102
|
? harness.attention(native.nativeId)
|
|
18000
|
-
: { permissions: [], questions: [] };
|
|
18103
|
+
: { permissions: [], questions: [], elicitations: [] };
|
|
18001
18104
|
}
|
|
18002
18105
|
|
|
18003
18106
|
private async replyNativeSessionRequest(
|
|
18004
18107
|
resolvedArg: IResolvedNativeSession,
|
|
18005
18108
|
requestIdArg: string,
|
|
18006
|
-
replyArg:
|
|
18007
|
-
kindArg: 'permission' | 'question',
|
|
18109
|
+
replyArg: TFleetNativeReply,
|
|
18110
|
+
kindArg: 'permission' | 'question' | 'elicitation',
|
|
18008
18111
|
): Promise<void> {
|
|
18009
18112
|
const { session, native } = resolvedArg;
|
|
18010
18113
|
const attention = await this.nativeSessionAttention(resolvedArg);
|
|
18011
|
-
|
|
18012
|
-
|
|
18114
|
+
const pending = kindArg === 'permission' ? attention.permissions : kindArg === 'question' ? attention.questions : attention.elicitations;
|
|
18115
|
+
if (!pending.some((request) => request.id.nativeId === requestIdArg)) {
|
|
18116
|
+
throw new plugins.typedrequest.TypedResponseError(`The ${kindArg === 'elicitation' ? 'MCP' : kindArg} request is no longer pending.`, { code: 'not_found' });
|
|
18013
18117
|
}
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18118
|
+
try {
|
|
18119
|
+
if (session.harness === 'codex') {
|
|
18120
|
+
await this.requireFleetWorkers().nativeReply('codex', native, requestIdArg, replyArg);
|
|
18121
|
+
return;
|
|
18122
|
+
}
|
|
18123
|
+
const harness = this.requireClaudeHarness();
|
|
18124
|
+
if ('permission' in replyArg) harness.replyPermission(native.nativeId, requestIdArg, replyArg.permission);
|
|
18125
|
+
else if ('elicitation' in replyArg) harness.replyElicitation(native.nativeId, requestIdArg, replyArg.elicitation);
|
|
18126
|
+
else harness.replyQuestion(native.nativeId, requestIdArg, replyArg.answers);
|
|
18127
|
+
} catch (errorArg) {
|
|
18128
|
+
throw elicitationRefusal(errorArg);
|
|
18017
18129
|
}
|
|
18018
|
-
const harness = this.requireClaudeHarness();
|
|
18019
|
-
if ('permission' in replyArg) harness.replyPermission(native.nativeId, requestIdArg, replyArg.permission);
|
|
18020
|
-
else harness.replyQuestion(native.nativeId, requestIdArg, replyArg.answers);
|
|
18021
18130
|
}
|
|
18022
18131
|
|
|
18023
18132
|
/** Native session failures are bounded messages; the session view and the fleet's receipt show them as they are. */
|
|
@@ -18524,6 +18633,7 @@ export class OpenCodeController {
|
|
|
18524
18633
|
: `${errorArg.message} The current revision is ${errorArg.currentRevision}.`);
|
|
18525
18634
|
}
|
|
18526
18635
|
if (errorArg instanceof DriverError) return refuse(errorArg.code, errorArg.message);
|
|
18636
|
+
if (errorArg instanceof FleetWorkerError) return refuse(errorArg.code, errorArg.message);
|
|
18527
18637
|
if (
|
|
18528
18638
|
(errorArg instanceof AuthError && errorArg.code === 'concurrent_change')
|
|
18529
18639
|
|| (
|
|
@@ -24635,6 +24745,7 @@ export class OpenCodeController {
|
|
|
24635
24745
|
messagePage: IControllerMessagePage;
|
|
24636
24746
|
permissions: IControllerPermission[];
|
|
24637
24747
|
questions: IControllerQuestion[];
|
|
24748
|
+
elicitations: IControllerAttention['elicitations'];
|
|
24638
24749
|
todos: IControllerTodo[];
|
|
24639
24750
|
contextCompaction?: IControllerSessionDetail['contextCompaction'];
|
|
24640
24751
|
model?: string;
|
|
@@ -24715,6 +24826,8 @@ export class OpenCodeController {
|
|
|
24715
24826
|
}),
|
|
24716
24827
|
permissions,
|
|
24717
24828
|
questions: [],
|
|
24829
|
+
// Flex hands AGL no MCP elicitations.
|
|
24830
|
+
elicitations: [],
|
|
24718
24831
|
todos,
|
|
24719
24832
|
...(model === undefined ? {} : { model }),
|
|
24720
24833
|
...(effort === undefined ? {} : { effort }),
|