@moxt-ai/mobius 0.0.129 → 0.0.131
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/dist/acp/agent-session.d.ts +0 -4
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +5 -36
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/{session-state.d.ts → agent-turn.d.ts} +5 -22
- package/dist/acp/agent-turn.d.ts.map +1 -0
- package/dist/acp/agent-turn.js +51 -0
- package/dist/acp/agent-turn.js.map +1 -0
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +26 -403
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/codex/settings.d.ts +36 -0
- package/dist/acp/codex/settings.d.ts.map +1 -0
- package/dist/acp/codex/settings.js +388 -0
- package/dist/acp/codex/settings.js.map +1 -0
- package/dist/acp/pending-interactions.d.ts +22 -0
- package/dist/acp/pending-interactions.d.ts.map +1 -0
- package/dist/acp/{session-state.js → pending-interactions.js} +1 -23
- package/dist/acp/pending-interactions.js.map +1 -0
- package/dist/acp/session-interactions.d.ts.map +1 -1
- package/dist/acp/session-interactions.js +1 -1
- package/dist/acp/session-interactions.js.map +1 -1
- package/dist/cli.js +741 -716
- package/dist/cli.js.map +4 -4
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/index.js +890 -865
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +866 -841
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/acp/session-state.d.ts.map +0 -1
- package/dist/acp/session-state.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.131",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -25105,11 +25105,8 @@ function agentMessageMeta(phase) {
|
|
|
25105
25105
|
return { [CODEX_META_KEY]: { phase } };
|
|
25106
25106
|
}
|
|
25107
25107
|
|
|
25108
|
-
// src/acp/codex/
|
|
25109
|
-
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
25108
|
+
// src/acp/codex/settings.ts
|
|
25110
25109
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
25111
|
-
var CODEX_AGENT_VERSION = "0.154.0";
|
|
25112
|
-
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
25113
25110
|
var MODEL_SETTING_ID = "model";
|
|
25114
25111
|
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
25115
25112
|
var MODE_SETTING_ID = "mode";
|
|
@@ -25118,7 +25115,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
|
|
|
25118
25115
|
var MODEL_CATALOG_LIMIT = 1e3;
|
|
25119
25116
|
var FAST_TIER = "fast";
|
|
25120
25117
|
var SERVICE_TIER_FAST = "priority";
|
|
25121
|
-
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
25122
25118
|
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
25123
25119
|
excludeSlashTmp: false,
|
|
25124
25120
|
excludeTmpdirEnvVar: false,
|
|
@@ -25162,94 +25158,6 @@ function initialMode(environment) {
|
|
|
25162
25158
|
function capitalize(value) {
|
|
25163
25159
|
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
25164
25160
|
}
|
|
25165
|
-
var APPROVAL_OPTIONS = Object.freeze([
|
|
25166
|
-
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
25167
|
-
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
25168
|
-
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
25169
|
-
]);
|
|
25170
|
-
function permissionDecision(optionId) {
|
|
25171
|
-
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
25172
|
-
return optionId;
|
|
25173
|
-
}
|
|
25174
|
-
return "cancel";
|
|
25175
|
-
}
|
|
25176
|
-
function promptInput(prompt) {
|
|
25177
|
-
const input2 = [];
|
|
25178
|
-
for (const block of prompt) {
|
|
25179
|
-
if (block.type === "text") {
|
|
25180
|
-
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
25181
|
-
continue;
|
|
25182
|
-
}
|
|
25183
|
-
if (block.type === "image") {
|
|
25184
|
-
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
25185
|
-
continue;
|
|
25186
|
-
}
|
|
25187
|
-
if (block.type === "resource") {
|
|
25188
|
-
const resource = block.resource;
|
|
25189
|
-
input2.push({
|
|
25190
|
-
text: "text" in resource ? resource.text ?? "" : "",
|
|
25191
|
-
text_elements: [],
|
|
25192
|
-
type: "text"
|
|
25193
|
-
});
|
|
25194
|
-
continue;
|
|
25195
|
-
}
|
|
25196
|
-
if (block.type === "resource_link") {
|
|
25197
|
-
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
25198
|
-
}
|
|
25199
|
-
}
|
|
25200
|
-
return input2;
|
|
25201
|
-
}
|
|
25202
|
-
function isCompactPrompt(prompt) {
|
|
25203
|
-
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
25204
|
-
}
|
|
25205
|
-
function steeringPromptInput(prompt) {
|
|
25206
|
-
const input2 = [];
|
|
25207
|
-
for (const block of prompt) {
|
|
25208
|
-
if (typeof block !== "object" || block === null) {
|
|
25209
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25210
|
-
}
|
|
25211
|
-
const type = Reflect.get(block, "type");
|
|
25212
|
-
if (type === "text") {
|
|
25213
|
-
const text2 = Reflect.get(block, "text");
|
|
25214
|
-
if (typeof text2 !== "string") {
|
|
25215
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25216
|
-
}
|
|
25217
|
-
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
25218
|
-
continue;
|
|
25219
|
-
}
|
|
25220
|
-
if (type === "image") {
|
|
25221
|
-
const data = Reflect.get(block, "data");
|
|
25222
|
-
const mimeType = Reflect.get(block, "mimeType");
|
|
25223
|
-
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
25224
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25225
|
-
}
|
|
25226
|
-
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
25227
|
-
continue;
|
|
25228
|
-
}
|
|
25229
|
-
if (type === "resource") {
|
|
25230
|
-
const resource = Reflect.get(block, "resource");
|
|
25231
|
-
if (typeof resource !== "object" || resource === null) {
|
|
25232
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25233
|
-
}
|
|
25234
|
-
const text2 = Reflect.get(resource, "text");
|
|
25235
|
-
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
25236
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25237
|
-
}
|
|
25238
|
-
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
25239
|
-
continue;
|
|
25240
|
-
}
|
|
25241
|
-
if (type === "resource_link") {
|
|
25242
|
-
const uri = Reflect.get(block, "uri");
|
|
25243
|
-
if (typeof uri !== "string") {
|
|
25244
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25245
|
-
}
|
|
25246
|
-
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
25247
|
-
continue;
|
|
25248
|
-
}
|
|
25249
|
-
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
25250
|
-
}
|
|
25251
|
-
return input2;
|
|
25252
|
-
}
|
|
25253
25161
|
function modelValues(models) {
|
|
25254
25162
|
return models.map((model) => ({
|
|
25255
25163
|
description: model.description ?? "",
|
|
@@ -25354,6 +25262,339 @@ function effortSetting(model, currentValue) {
|
|
|
25354
25262
|
type: "select"
|
|
25355
25263
|
};
|
|
25356
25264
|
}
|
|
25265
|
+
var CodexSettings = class {
|
|
25266
|
+
#appServer;
|
|
25267
|
+
#models = [];
|
|
25268
|
+
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
25269
|
+
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
25270
|
+
#policySelected = false;
|
|
25271
|
+
// Whether a collaboration mode choice has been made in this session. A restored thread keeps
|
|
25272
|
+
// the mode Codex already persisted, so the first turn does not reset it to Build.
|
|
25273
|
+
#collaborationModeSelected = false;
|
|
25274
|
+
// Whether the app-server accepts collaboration mode on `turn/start`, probed once per
|
|
25275
|
+
// app-server. An older Codex rejects the experimental field, and the setting must disappear
|
|
25276
|
+
// rather than break every turn.
|
|
25277
|
+
#collaborationModeSupported = null;
|
|
25278
|
+
#selection;
|
|
25279
|
+
constructor(appServer, environment) {
|
|
25280
|
+
this.#appServer = appServer;
|
|
25281
|
+
this.#selection = {
|
|
25282
|
+
collaborationMode: "default",
|
|
25283
|
+
effort: "",
|
|
25284
|
+
fastMode: false,
|
|
25285
|
+
mode: initialMode(environment),
|
|
25286
|
+
model: ""
|
|
25287
|
+
};
|
|
25288
|
+
}
|
|
25289
|
+
selectNewThread = (created) => {
|
|
25290
|
+
const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
|
|
25291
|
+
this.#selection = {
|
|
25292
|
+
...this.#selection,
|
|
25293
|
+
collaborationMode: "default",
|
|
25294
|
+
...supported
|
|
25295
|
+
};
|
|
25296
|
+
this.#collaborationModeSelected = false;
|
|
25297
|
+
};
|
|
25298
|
+
observeCollaborationMode = (mode) => {
|
|
25299
|
+
if (mode === void 0 || mode === this.#selection.collaborationMode) {
|
|
25300
|
+
return false;
|
|
25301
|
+
}
|
|
25302
|
+
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
25303
|
+
return true;
|
|
25304
|
+
};
|
|
25305
|
+
turnParameters = () => {
|
|
25306
|
+
const selection = this.#selection;
|
|
25307
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
25308
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
25309
|
+
return {
|
|
25310
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
25311
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
25312
|
+
// inherited rather than overridden.
|
|
25313
|
+
...this.#policySelected ? {
|
|
25314
|
+
approvalPolicy: mode.approvalPolicy,
|
|
25315
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
25316
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
25317
|
+
} : {},
|
|
25318
|
+
// The collaboration mode rides on the turn: Codex applies it to the
|
|
25319
|
+
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
25320
|
+
// mode, so it is only sent once a choice exists to apply.
|
|
25321
|
+
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
25322
|
+
collaborationMode: {
|
|
25323
|
+
mode: selection.collaborationMode,
|
|
25324
|
+
settings: {
|
|
25325
|
+
developer_instructions: null,
|
|
25326
|
+
model: selection.model,
|
|
25327
|
+
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
25328
|
+
}
|
|
25329
|
+
}
|
|
25330
|
+
} : {},
|
|
25331
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
25332
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
25333
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
|
|
25334
|
+
};
|
|
25335
|
+
};
|
|
25336
|
+
loadModels = async (signal) => {
|
|
25337
|
+
const models = [];
|
|
25338
|
+
let cursor = null;
|
|
25339
|
+
try {
|
|
25340
|
+
do {
|
|
25341
|
+
const decoded = modelListResponseSchema.parse(
|
|
25342
|
+
await this.#appServer.request(
|
|
25343
|
+
"model/list",
|
|
25344
|
+
{ cursor, limit: null },
|
|
25345
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
25346
|
+
)
|
|
25347
|
+
);
|
|
25348
|
+
models.push(...decoded.data);
|
|
25349
|
+
cursor = decoded.nextCursor ?? null;
|
|
25350
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
25351
|
+
} catch (error62) {
|
|
25352
|
+
signal.throwIfAborted();
|
|
25353
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
25354
|
+
`);
|
|
25355
|
+
}
|
|
25356
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
25357
|
+
};
|
|
25358
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
25359
|
+
/**
|
|
25360
|
+
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
25361
|
+
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
25362
|
+
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
25363
|
+
*/
|
|
25364
|
+
probeCollaborationMode = async (threadId, signal) => {
|
|
25365
|
+
if (this.#collaborationModeSupported !== null) {
|
|
25366
|
+
return;
|
|
25367
|
+
}
|
|
25368
|
+
try {
|
|
25369
|
+
await this.#appServer.request(
|
|
25370
|
+
"thread/settings/update",
|
|
25371
|
+
{ threadId },
|
|
25372
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
25373
|
+
);
|
|
25374
|
+
this.#collaborationModeSupported = true;
|
|
25375
|
+
} catch {
|
|
25376
|
+
signal.throwIfAborted();
|
|
25377
|
+
this.#collaborationModeSupported = false;
|
|
25378
|
+
}
|
|
25379
|
+
};
|
|
25380
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
25381
|
+
configOptions = () => {
|
|
25382
|
+
const options = [];
|
|
25383
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
25384
|
+
if (model !== null) {
|
|
25385
|
+
options.push(model);
|
|
25386
|
+
}
|
|
25387
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
25388
|
+
if (effort !== null) {
|
|
25389
|
+
options.push(effort);
|
|
25390
|
+
}
|
|
25391
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
25392
|
+
if (fastMode !== null) {
|
|
25393
|
+
options.push(fastMode);
|
|
25394
|
+
}
|
|
25395
|
+
if (this.#collaborationModeSupported === true) {
|
|
25396
|
+
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
25397
|
+
}
|
|
25398
|
+
options.push(modeSetting(this.#selection.mode));
|
|
25399
|
+
return options;
|
|
25400
|
+
};
|
|
25401
|
+
selectRestoredThread = (thread) => {
|
|
25402
|
+
const supported = supportedSelection(
|
|
25403
|
+
this.#models,
|
|
25404
|
+
thread.model ?? this.#selection.model,
|
|
25405
|
+
thread.reasoningEffort ?? this.#selection.effort
|
|
25406
|
+
);
|
|
25407
|
+
this.#selection = {
|
|
25408
|
+
...this.#selection,
|
|
25409
|
+
...supported,
|
|
25410
|
+
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
25411
|
+
};
|
|
25412
|
+
};
|
|
25413
|
+
/**
|
|
25414
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
25415
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
25416
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
25417
|
+
*/
|
|
25418
|
+
applySelection = (configId, value) => {
|
|
25419
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
25420
|
+
if (typeof value !== "boolean") {
|
|
25421
|
+
throw new AcpExecutionError(
|
|
25422
|
+
"The requested Codex setting is invalid",
|
|
25423
|
+
{},
|
|
25424
|
+
"invalid_session_configuration"
|
|
25425
|
+
);
|
|
25426
|
+
}
|
|
25427
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
25428
|
+
throw new AcpExecutionError(
|
|
25429
|
+
"The selected Codex model has no fast mode",
|
|
25430
|
+
{},
|
|
25431
|
+
"invalid_session_configuration"
|
|
25432
|
+
);
|
|
25433
|
+
}
|
|
25434
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
25435
|
+
return;
|
|
25436
|
+
}
|
|
25437
|
+
if (typeof value !== "string") {
|
|
25438
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
25439
|
+
}
|
|
25440
|
+
if (configId === MODE_SETTING_ID) {
|
|
25441
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
25442
|
+
throw new AcpExecutionError(
|
|
25443
|
+
"The requested Codex mode is unavailable",
|
|
25444
|
+
{},
|
|
25445
|
+
"invalid_session_configuration"
|
|
25446
|
+
);
|
|
25447
|
+
}
|
|
25448
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
25449
|
+
this.#policySelected = true;
|
|
25450
|
+
return;
|
|
25451
|
+
}
|
|
25452
|
+
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
25453
|
+
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
25454
|
+
throw new AcpExecutionError(
|
|
25455
|
+
"The requested Codex collaboration mode is unavailable",
|
|
25456
|
+
{},
|
|
25457
|
+
"invalid_session_configuration"
|
|
25458
|
+
);
|
|
25459
|
+
}
|
|
25460
|
+
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
25461
|
+
this.#collaborationModeSelected = true;
|
|
25462
|
+
return;
|
|
25463
|
+
}
|
|
25464
|
+
if (configId === MODEL_SETTING_ID) {
|
|
25465
|
+
if (value === this.#selection.model) {
|
|
25466
|
+
return;
|
|
25467
|
+
}
|
|
25468
|
+
const model = this.#model(value);
|
|
25469
|
+
if (model === void 0) {
|
|
25470
|
+
throw new AcpExecutionError(
|
|
25471
|
+
"The requested Codex model is unavailable",
|
|
25472
|
+
{},
|
|
25473
|
+
"invalid_session_configuration"
|
|
25474
|
+
);
|
|
25475
|
+
}
|
|
25476
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
25477
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
25478
|
+
this.#selection = {
|
|
25479
|
+
...this.#selection,
|
|
25480
|
+
effort,
|
|
25481
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
25482
|
+
model: value
|
|
25483
|
+
};
|
|
25484
|
+
return;
|
|
25485
|
+
}
|
|
25486
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
25487
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
25488
|
+
(option) => option.reasoningEffort
|
|
25489
|
+
);
|
|
25490
|
+
if (!supported.includes(value)) {
|
|
25491
|
+
throw new AcpExecutionError(
|
|
25492
|
+
"The requested Codex reasoning effort is unavailable",
|
|
25493
|
+
{},
|
|
25494
|
+
"invalid_session_configuration"
|
|
25495
|
+
);
|
|
25496
|
+
}
|
|
25497
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
25498
|
+
return;
|
|
25499
|
+
}
|
|
25500
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
25501
|
+
};
|
|
25502
|
+
};
|
|
25503
|
+
|
|
25504
|
+
// src/acp/codex/agent.ts
|
|
25505
|
+
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
25506
|
+
var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
|
|
25507
|
+
var CODEX_AGENT_VERSION = "0.154.0";
|
|
25508
|
+
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
25509
|
+
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
25510
|
+
var APPROVAL_OPTIONS = Object.freeze([
|
|
25511
|
+
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
25512
|
+
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
25513
|
+
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
25514
|
+
]);
|
|
25515
|
+
function permissionDecision(optionId) {
|
|
25516
|
+
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
25517
|
+
return optionId;
|
|
25518
|
+
}
|
|
25519
|
+
return "cancel";
|
|
25520
|
+
}
|
|
25521
|
+
function promptInput(prompt) {
|
|
25522
|
+
const input2 = [];
|
|
25523
|
+
for (const block of prompt) {
|
|
25524
|
+
if (block.type === "text") {
|
|
25525
|
+
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
25526
|
+
continue;
|
|
25527
|
+
}
|
|
25528
|
+
if (block.type === "image") {
|
|
25529
|
+
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
25530
|
+
continue;
|
|
25531
|
+
}
|
|
25532
|
+
if (block.type === "resource") {
|
|
25533
|
+
const resource = block.resource;
|
|
25534
|
+
input2.push({
|
|
25535
|
+
text: "text" in resource ? resource.text ?? "" : "",
|
|
25536
|
+
text_elements: [],
|
|
25537
|
+
type: "text"
|
|
25538
|
+
});
|
|
25539
|
+
continue;
|
|
25540
|
+
}
|
|
25541
|
+
if (block.type === "resource_link") {
|
|
25542
|
+
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
25543
|
+
}
|
|
25544
|
+
}
|
|
25545
|
+
return input2;
|
|
25546
|
+
}
|
|
25547
|
+
function isCompactPrompt(prompt) {
|
|
25548
|
+
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
25549
|
+
}
|
|
25550
|
+
function steeringPromptInput(prompt) {
|
|
25551
|
+
const input2 = [];
|
|
25552
|
+
for (const block of prompt) {
|
|
25553
|
+
if (typeof block !== "object" || block === null) {
|
|
25554
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25555
|
+
}
|
|
25556
|
+
const type = Reflect.get(block, "type");
|
|
25557
|
+
if (type === "text") {
|
|
25558
|
+
const text2 = Reflect.get(block, "text");
|
|
25559
|
+
if (typeof text2 !== "string") {
|
|
25560
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25561
|
+
}
|
|
25562
|
+
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
25563
|
+
continue;
|
|
25564
|
+
}
|
|
25565
|
+
if (type === "image") {
|
|
25566
|
+
const data = Reflect.get(block, "data");
|
|
25567
|
+
const mimeType = Reflect.get(block, "mimeType");
|
|
25568
|
+
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
25569
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25570
|
+
}
|
|
25571
|
+
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
25572
|
+
continue;
|
|
25573
|
+
}
|
|
25574
|
+
if (type === "resource") {
|
|
25575
|
+
const resource = Reflect.get(block, "resource");
|
|
25576
|
+
if (typeof resource !== "object" || resource === null) {
|
|
25577
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25578
|
+
}
|
|
25579
|
+
const text2 = Reflect.get(resource, "text");
|
|
25580
|
+
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
25581
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25582
|
+
}
|
|
25583
|
+
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
25584
|
+
continue;
|
|
25585
|
+
}
|
|
25586
|
+
if (type === "resource_link") {
|
|
25587
|
+
const uri = Reflect.get(block, "uri");
|
|
25588
|
+
if (typeof uri !== "string") {
|
|
25589
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
25590
|
+
}
|
|
25591
|
+
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
25592
|
+
continue;
|
|
25593
|
+
}
|
|
25594
|
+
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
25595
|
+
}
|
|
25596
|
+
return input2;
|
|
25597
|
+
}
|
|
25357
25598
|
function userInputSchema(questions) {
|
|
25358
25599
|
const properties = {};
|
|
25359
25600
|
const required2 = [];
|
|
@@ -25380,31 +25621,13 @@ var CodexAcpAgent = class {
|
|
|
25380
25621
|
terminated;
|
|
25381
25622
|
#closePromise = null;
|
|
25382
25623
|
#connection = null;
|
|
25383
|
-
#
|
|
25624
|
+
#settings;
|
|
25384
25625
|
#nativeSessionId = "";
|
|
25385
|
-
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
25386
|
-
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
25387
|
-
#policySelected = false;
|
|
25388
|
-
// Whether a collaboration mode choice has been made in this session. A restored thread keeps
|
|
25389
|
-
// the mode Codex already persisted, so the first turn does not reset it to Build.
|
|
25390
|
-
#collaborationModeSelected = false;
|
|
25391
|
-
// Whether the app-server accepts collaboration mode on `turn/start`, probed once per
|
|
25392
|
-
// app-server. An older Codex rejects the experimental field, and the setting must disappear
|
|
25393
|
-
// rather than break every turn.
|
|
25394
|
-
#collaborationModeSupported = null;
|
|
25395
|
-
#selection;
|
|
25396
25626
|
#streamedReasoningItemIds = /* @__PURE__ */ new Set();
|
|
25397
25627
|
#turn = null;
|
|
25398
25628
|
#nativeTurnId = null;
|
|
25399
25629
|
#updateTail = Promise.resolve();
|
|
25400
25630
|
constructor(options) {
|
|
25401
|
-
this.#selection = {
|
|
25402
|
-
collaborationMode: "default",
|
|
25403
|
-
effort: "",
|
|
25404
|
-
fastMode: false,
|
|
25405
|
-
mode: initialMode(options.environment),
|
|
25406
|
-
model: ""
|
|
25407
|
-
};
|
|
25408
25631
|
this.#appServer = new CodexAppServerClient({
|
|
25409
25632
|
command: options.command,
|
|
25410
25633
|
cwd: options.cwd,
|
|
@@ -25418,6 +25641,7 @@ var CodexAcpAgent = class {
|
|
|
25418
25641
|
}
|
|
25419
25642
|
}
|
|
25420
25643
|
});
|
|
25644
|
+
this.#settings = new CodexSettings(this.#appServer, options.environment);
|
|
25421
25645
|
this.terminated = this.#appServer.terminated;
|
|
25422
25646
|
void this.terminated.then((termination) => {
|
|
25423
25647
|
this.#turn?.completion.reject(acpEndpointTerminationError(termination));
|
|
@@ -25444,39 +25668,34 @@ var CodexAcpAgent = class {
|
|
|
25444
25668
|
await this.#appServer.request(
|
|
25445
25669
|
"thread/start",
|
|
25446
25670
|
{ cwd: context.params.cwd },
|
|
25447
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
25671
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
25448
25672
|
)
|
|
25449
25673
|
);
|
|
25450
25674
|
this.#nativeSessionId = created.thread.id;
|
|
25451
|
-
|
|
25452
|
-
this.#
|
|
25453
|
-
...this.#selection,
|
|
25454
|
-
collaborationMode: "default",
|
|
25455
|
-
...supported
|
|
25456
|
-
};
|
|
25457
|
-
this.#collaborationModeSelected = false;
|
|
25458
|
-
await this.#probeCollaborationMode(context.signal);
|
|
25675
|
+
this.#settings.selectNewThread(created);
|
|
25676
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
25459
25677
|
await this.#emitAvailableCommands();
|
|
25460
|
-
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
25678
|
+
return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
|
|
25461
25679
|
}).onRequest(methods.agent.session.setConfigOption, async (context) => {
|
|
25462
|
-
this.#applySelection(context.params.configId, context.params.value);
|
|
25463
|
-
return { configOptions: this.#configOptions() };
|
|
25680
|
+
this.#settings.applySelection(context.params.configId, context.params.value);
|
|
25681
|
+
return { configOptions: this.#settings.configOptions() };
|
|
25464
25682
|
}).onRequest(methods.agent.session.setMode, async (context) => {
|
|
25465
|
-
this.#applySelection(
|
|
25683
|
+
this.#settings.applySelection("mode", context.params.modeId);
|
|
25466
25684
|
return {};
|
|
25467
25685
|
}).onRequest(methods.agent.session.load, async (context) => {
|
|
25468
25686
|
const resumed = threadResumeResponseSchema.parse(
|
|
25469
25687
|
await this.#appServer.request(
|
|
25470
25688
|
"thread/resume",
|
|
25471
25689
|
{ cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
|
|
25472
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
25690
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
25473
25691
|
)
|
|
25474
25692
|
);
|
|
25475
|
-
this.#
|
|
25476
|
-
|
|
25693
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
25694
|
+
this.#settings.selectRestoredThread(resumed);
|
|
25695
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
25477
25696
|
await this.#replayHistory(resumed.turns);
|
|
25478
25697
|
await this.#emitAvailableCommands();
|
|
25479
|
-
return { configOptions: this.#configOptions() };
|
|
25698
|
+
return { configOptions: this.#settings.configOptions() };
|
|
25480
25699
|
}).onRequest(methods.agent.session.fork, async (context) => {
|
|
25481
25700
|
const forked = threadForkResponseSchema.parse(
|
|
25482
25701
|
await this.#appServer.request(
|
|
@@ -25486,26 +25705,28 @@ var CodexAcpAgent = class {
|
|
|
25486
25705
|
excludeTurns: false,
|
|
25487
25706
|
threadId: context.params.sessionId
|
|
25488
25707
|
},
|
|
25489
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
25708
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
25490
25709
|
)
|
|
25491
25710
|
);
|
|
25492
|
-
this.#
|
|
25493
|
-
|
|
25711
|
+
this.#nativeSessionId = forked.thread.id;
|
|
25712
|
+
this.#settings.selectRestoredThread(forked);
|
|
25713
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
25494
25714
|
await this.#replayHistory(forked.turns);
|
|
25495
25715
|
await this.#emitAvailableCommands();
|
|
25496
|
-
return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
|
|
25716
|
+
return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
|
|
25497
25717
|
}).onRequest(methods.agent.session.resume, async (context) => {
|
|
25498
25718
|
const resumed = threadResumeResponseSchema.parse(
|
|
25499
25719
|
await this.#appServer.request(
|
|
25500
25720
|
"thread/resume",
|
|
25501
25721
|
{ cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
|
|
25502
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
25722
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
25503
25723
|
)
|
|
25504
25724
|
);
|
|
25505
|
-
this.#
|
|
25506
|
-
|
|
25725
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
25726
|
+
this.#settings.selectRestoredThread(resumed);
|
|
25727
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
25507
25728
|
await this.#emitAvailableCommands();
|
|
25508
|
-
return { configOptions: this.#configOptions() };
|
|
25729
|
+
return { configOptions: this.#settings.configOptions() };
|
|
25509
25730
|
}).onRequest(methods.agent.session.prompt, async (context) => {
|
|
25510
25731
|
if (isCompactPrompt(context.params.prompt)) {
|
|
25511
25732
|
return await this.#compact(context.signal);
|
|
@@ -25545,7 +25766,7 @@ var CodexAcpAgent = class {
|
|
|
25545
25766
|
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
25546
25767
|
initialize = async (signal) => {
|
|
25547
25768
|
await this.#appServer.initialize(signal);
|
|
25548
|
-
await this.#loadModels(signal);
|
|
25769
|
+
await this.#settings.loadModels(signal);
|
|
25549
25770
|
};
|
|
25550
25771
|
/**
|
|
25551
25772
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
@@ -25571,84 +25792,6 @@ var CodexAcpAgent = class {
|
|
|
25571
25792
|
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
25572
25793
|
* turn lifecycle continues without settings rather than failing initialization.
|
|
25573
25794
|
*/
|
|
25574
|
-
#loadModels = async (signal) => {
|
|
25575
|
-
const models = [];
|
|
25576
|
-
let cursor = null;
|
|
25577
|
-
try {
|
|
25578
|
-
do {
|
|
25579
|
-
const decoded = modelListResponseSchema.parse(
|
|
25580
|
-
await this.#appServer.request(
|
|
25581
|
-
"model/list",
|
|
25582
|
-
{ cursor, limit: null },
|
|
25583
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
25584
|
-
)
|
|
25585
|
-
);
|
|
25586
|
-
models.push(...decoded.data);
|
|
25587
|
-
cursor = decoded.nextCursor ?? null;
|
|
25588
|
-
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
25589
|
-
} catch (error62) {
|
|
25590
|
-
signal.throwIfAborted();
|
|
25591
|
-
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
25592
|
-
`);
|
|
25593
|
-
}
|
|
25594
|
-
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
25595
|
-
};
|
|
25596
|
-
#model = (id) => this.#models.find((model) => model.id === id);
|
|
25597
|
-
/**
|
|
25598
|
-
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
25599
|
-
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
25600
|
-
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
25601
|
-
*/
|
|
25602
|
-
#probeCollaborationMode = async (signal) => {
|
|
25603
|
-
if (this.#collaborationModeSupported !== null) {
|
|
25604
|
-
return;
|
|
25605
|
-
}
|
|
25606
|
-
try {
|
|
25607
|
-
await this.#appServer.request(
|
|
25608
|
-
"thread/settings/update",
|
|
25609
|
-
{ threadId: this.#nativeSessionId },
|
|
25610
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
25611
|
-
);
|
|
25612
|
-
this.#collaborationModeSupported = true;
|
|
25613
|
-
} catch {
|
|
25614
|
-
signal.throwIfAborted();
|
|
25615
|
-
this.#collaborationModeSupported = false;
|
|
25616
|
-
}
|
|
25617
|
-
};
|
|
25618
|
-
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
25619
|
-
#configOptions = () => {
|
|
25620
|
-
const options = [];
|
|
25621
|
-
const model = modelSetting(this.#models, this.#selection.model);
|
|
25622
|
-
if (model !== null) {
|
|
25623
|
-
options.push(model);
|
|
25624
|
-
}
|
|
25625
|
-
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
25626
|
-
if (effort !== null) {
|
|
25627
|
-
options.push(effort);
|
|
25628
|
-
}
|
|
25629
|
-
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
25630
|
-
if (fastMode !== null) {
|
|
25631
|
-
options.push(fastMode);
|
|
25632
|
-
}
|
|
25633
|
-
if (this.#collaborationModeSupported === true) {
|
|
25634
|
-
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
25635
|
-
}
|
|
25636
|
-
options.push(modeSetting(this.#selection.mode));
|
|
25637
|
-
return options;
|
|
25638
|
-
};
|
|
25639
|
-
#selectRestoredThread = (thread) => {
|
|
25640
|
-
this.#nativeSessionId = thread.thread.id;
|
|
25641
|
-
const supported = supportedSelection(
|
|
25642
|
-
this.#models,
|
|
25643
|
-
thread.model ?? this.#selection.model,
|
|
25644
|
-
thread.reasoningEffort ?? this.#selection.effort
|
|
25645
|
-
);
|
|
25646
|
-
this.#selection = {
|
|
25647
|
-
...this.#selection,
|
|
25648
|
-
...supported,
|
|
25649
|
-
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
25650
|
-
};
|
|
25651
|
-
};
|
|
25652
25795
|
#replayHistory = async (turns) => {
|
|
25653
25796
|
for (const turn of turns ?? []) {
|
|
25654
25797
|
for (const rawItem of turn.items) {
|
|
@@ -25690,95 +25833,6 @@ var CodexAcpAgent = class {
|
|
|
25690
25833
|
}
|
|
25691
25834
|
}
|
|
25692
25835
|
};
|
|
25693
|
-
/**
|
|
25694
|
-
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
25695
|
-
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
25696
|
-
* so the reply never advertises an effort the selected model cannot run.
|
|
25697
|
-
*/
|
|
25698
|
-
#applySelection = (configId, value) => {
|
|
25699
|
-
if (configId === FAST_MODE_SETTING_ID) {
|
|
25700
|
-
if (typeof value !== "boolean") {
|
|
25701
|
-
throw new AcpExecutionError(
|
|
25702
|
-
"The requested Codex setting is invalid",
|
|
25703
|
-
{},
|
|
25704
|
-
"invalid_session_configuration"
|
|
25705
|
-
);
|
|
25706
|
-
}
|
|
25707
|
-
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
25708
|
-
throw new AcpExecutionError(
|
|
25709
|
-
"The selected Codex model has no fast mode",
|
|
25710
|
-
{},
|
|
25711
|
-
"invalid_session_configuration"
|
|
25712
|
-
);
|
|
25713
|
-
}
|
|
25714
|
-
this.#selection = { ...this.#selection, fastMode: value };
|
|
25715
|
-
return;
|
|
25716
|
-
}
|
|
25717
|
-
if (typeof value !== "string") {
|
|
25718
|
-
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
25719
|
-
}
|
|
25720
|
-
if (configId === MODE_SETTING_ID) {
|
|
25721
|
-
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
25722
|
-
throw new AcpExecutionError(
|
|
25723
|
-
"The requested Codex mode is unavailable",
|
|
25724
|
-
{},
|
|
25725
|
-
"invalid_session_configuration"
|
|
25726
|
-
);
|
|
25727
|
-
}
|
|
25728
|
-
this.#selection = { ...this.#selection, mode: value };
|
|
25729
|
-
this.#policySelected = true;
|
|
25730
|
-
return;
|
|
25731
|
-
}
|
|
25732
|
-
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
25733
|
-
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
25734
|
-
throw new AcpExecutionError(
|
|
25735
|
-
"The requested Codex collaboration mode is unavailable",
|
|
25736
|
-
{},
|
|
25737
|
-
"invalid_session_configuration"
|
|
25738
|
-
);
|
|
25739
|
-
}
|
|
25740
|
-
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
25741
|
-
this.#collaborationModeSelected = true;
|
|
25742
|
-
return;
|
|
25743
|
-
}
|
|
25744
|
-
if (configId === MODEL_SETTING_ID) {
|
|
25745
|
-
if (value === this.#selection.model) {
|
|
25746
|
-
return;
|
|
25747
|
-
}
|
|
25748
|
-
const model = this.#model(value);
|
|
25749
|
-
if (model === void 0) {
|
|
25750
|
-
throw new AcpExecutionError(
|
|
25751
|
-
"The requested Codex model is unavailable",
|
|
25752
|
-
{},
|
|
25753
|
-
"invalid_session_configuration"
|
|
25754
|
-
);
|
|
25755
|
-
}
|
|
25756
|
-
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
25757
|
-
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
25758
|
-
this.#selection = {
|
|
25759
|
-
...this.#selection,
|
|
25760
|
-
effort,
|
|
25761
|
-
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
25762
|
-
model: value
|
|
25763
|
-
};
|
|
25764
|
-
return;
|
|
25765
|
-
}
|
|
25766
|
-
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
25767
|
-
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
25768
|
-
(option) => option.reasoningEffort
|
|
25769
|
-
);
|
|
25770
|
-
if (!supported.includes(value)) {
|
|
25771
|
-
throw new AcpExecutionError(
|
|
25772
|
-
"The requested Codex reasoning effort is unavailable",
|
|
25773
|
-
{},
|
|
25774
|
-
"invalid_session_configuration"
|
|
25775
|
-
);
|
|
25776
|
-
}
|
|
25777
|
-
this.#selection = { ...this.#selection, effort: value };
|
|
25778
|
-
return;
|
|
25779
|
-
}
|
|
25780
|
-
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
25781
|
-
};
|
|
25782
25836
|
#emit = async (update) => {
|
|
25783
25837
|
const connection = this.#connection;
|
|
25784
25838
|
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
@@ -25803,7 +25857,7 @@ var CodexAcpAgent = class {
|
|
|
25803
25857
|
}
|
|
25804
25858
|
await connection.client.notify(methods.client.session.update, {
|
|
25805
25859
|
sessionId: this.#nativeSessionId,
|
|
25806
|
-
update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
|
|
25860
|
+
update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
|
|
25807
25861
|
});
|
|
25808
25862
|
};
|
|
25809
25863
|
// Notifications are serialized so two app-server items cannot interleave into one ACP update
|
|
@@ -25843,8 +25897,7 @@ var CodexAcpAgent = class {
|
|
|
25843
25897
|
const decoded = threadSettingsUpdatedSchema.safeParse(params);
|
|
25844
25898
|
if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
|
|
25845
25899
|
const mode = decoded.data.threadSettings.collaborationMode?.mode;
|
|
25846
|
-
if (
|
|
25847
|
-
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
25900
|
+
if (this.#settings.observeCollaborationMode(mode)) {
|
|
25848
25901
|
await this.#enqueue(async () => {
|
|
25849
25902
|
await this.#emitConfigOptionsUpdate();
|
|
25850
25903
|
});
|
|
@@ -25966,7 +26019,7 @@ var CodexAcpAgent = class {
|
|
|
25966
26019
|
const decision = await this.#askPermission(
|
|
25967
26020
|
title2,
|
|
25968
26021
|
params.itemId,
|
|
25969
|
-
AbortSignal.timeout(
|
|
26022
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
25970
26023
|
);
|
|
25971
26024
|
void turn;
|
|
25972
26025
|
this.#appServer.respond(request.id, { decision });
|
|
@@ -25988,7 +26041,7 @@ var CodexAcpAgent = class {
|
|
|
25988
26041
|
sessionId: this.#nativeSessionId,
|
|
25989
26042
|
...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
|
|
25990
26043
|
},
|
|
25991
|
-
{ cancellationSignal: AbortSignal.timeout(
|
|
26044
|
+
{ cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
|
|
25992
26045
|
);
|
|
25993
26046
|
const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
|
|
25994
26047
|
const answers = {};
|
|
@@ -26006,7 +26059,7 @@ var CodexAcpAgent = class {
|
|
|
26006
26059
|
return;
|
|
26007
26060
|
}
|
|
26008
26061
|
const params = decoded.data;
|
|
26009
|
-
const signal = AbortSignal.timeout(
|
|
26062
|
+
const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
|
|
26010
26063
|
if (params.mode === "url" && params.url !== void 0) {
|
|
26011
26064
|
const response2 = await connection.client.request(
|
|
26012
26065
|
methods.client.elicitation.create,
|
|
@@ -26055,38 +26108,12 @@ var CodexAcpAgent = class {
|
|
|
26055
26108
|
this.#turn = turn;
|
|
26056
26109
|
this.#nativeTurnId = null;
|
|
26057
26110
|
try {
|
|
26058
|
-
const selection = this.#selection;
|
|
26059
|
-
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
26060
|
-
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
26061
26111
|
const started = turnSchema.parse(
|
|
26062
26112
|
(await this.#appServer.request(
|
|
26063
26113
|
"turn/start",
|
|
26064
26114
|
{
|
|
26065
|
-
|
|
26066
|
-
// policy, and those fields stay off the turn so the host's own setup is
|
|
26067
|
-
// inherited rather than overridden.
|
|
26068
|
-
...this.#policySelected ? {
|
|
26069
|
-
approvalPolicy: mode.approvalPolicy,
|
|
26070
|
-
approvalsReviewer: mode.approvalsReviewer,
|
|
26071
|
-
sandboxPolicy: mode.sandboxPolicy
|
|
26072
|
-
} : {},
|
|
26073
|
-
// The collaboration mode rides on the turn: Codex applies it to the
|
|
26074
|
-
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
26075
|
-
// mode, so it is only sent once a choice exists to apply.
|
|
26076
|
-
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
26077
|
-
collaborationMode: {
|
|
26078
|
-
mode: selection.collaborationMode,
|
|
26079
|
-
settings: {
|
|
26080
|
-
developer_instructions: null,
|
|
26081
|
-
model: selection.model,
|
|
26082
|
-
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
26083
|
-
}
|
|
26084
|
-
}
|
|
26085
|
-
} : {},
|
|
26086
|
-
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
26115
|
+
...this.#settings.turnParameters(),
|
|
26087
26116
|
input: input2,
|
|
26088
|
-
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
26089
|
-
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
26090
26117
|
threadId: this.#nativeSessionId
|
|
26091
26118
|
},
|
|
26092
26119
|
signal
|
|
@@ -26155,7 +26182,7 @@ var CodexAcpAgent = class {
|
|
|
26155
26182
|
await this.#appServer.request(
|
|
26156
26183
|
"turn/steer",
|
|
26157
26184
|
{ expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
|
|
26158
|
-
AbortSignal.any([signal, AbortSignal.timeout(
|
|
26185
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
26159
26186
|
)
|
|
26160
26187
|
);
|
|
26161
26188
|
if (response.turnId !== active.turn.id) {
|
|
@@ -26174,7 +26201,7 @@ var CodexAcpAgent = class {
|
|
|
26174
26201
|
await this.#appServer.request(
|
|
26175
26202
|
"turn/interrupt",
|
|
26176
26203
|
{ threadId: this.#nativeSessionId, turnId: turn.turn.id },
|
|
26177
|
-
AbortSignal.timeout(
|
|
26204
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
26178
26205
|
);
|
|
26179
26206
|
} catch {
|
|
26180
26207
|
}
|
|
@@ -31642,6 +31669,374 @@ var AgentConnection = class {
|
|
|
31642
31669
|
};
|
|
31643
31670
|
};
|
|
31644
31671
|
|
|
31672
|
+
// src/acp/activity.ts
|
|
31673
|
+
var AcpActivityNarration = class {
|
|
31674
|
+
activityId;
|
|
31675
|
+
activityType;
|
|
31676
|
+
sequence;
|
|
31677
|
+
text;
|
|
31678
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
31679
|
+
this.activityId = activityId;
|
|
31680
|
+
this.activityType = activityType;
|
|
31681
|
+
this.sequence = sequence;
|
|
31682
|
+
this.text = text2;
|
|
31683
|
+
}
|
|
31684
|
+
};
|
|
31685
|
+
var AcpActivity = class _AcpActivity {
|
|
31686
|
+
activityId;
|
|
31687
|
+
activityType;
|
|
31688
|
+
input;
|
|
31689
|
+
locations;
|
|
31690
|
+
name;
|
|
31691
|
+
output;
|
|
31692
|
+
sequence;
|
|
31693
|
+
status;
|
|
31694
|
+
title;
|
|
31695
|
+
toolKind;
|
|
31696
|
+
content;
|
|
31697
|
+
detail;
|
|
31698
|
+
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31699
|
+
this.activityId = activityId;
|
|
31700
|
+
this.activityType = activityType;
|
|
31701
|
+
this.input = input2;
|
|
31702
|
+
this.locations = locations;
|
|
31703
|
+
this.name = name;
|
|
31704
|
+
this.output = output2;
|
|
31705
|
+
this.sequence = sequence;
|
|
31706
|
+
this.status = status;
|
|
31707
|
+
this.title = title2;
|
|
31708
|
+
this.toolKind = toolKind;
|
|
31709
|
+
this.content = content;
|
|
31710
|
+
this.detail = detail;
|
|
31711
|
+
}
|
|
31712
|
+
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
31713
|
+
this.activityId,
|
|
31714
|
+
this.activityType,
|
|
31715
|
+
this.input,
|
|
31716
|
+
this.locations,
|
|
31717
|
+
this.name,
|
|
31718
|
+
this.output,
|
|
31719
|
+
this.sequence,
|
|
31720
|
+
"completed",
|
|
31721
|
+
this.title,
|
|
31722
|
+
this.toolKind,
|
|
31723
|
+
this.content,
|
|
31724
|
+
this.detail
|
|
31725
|
+
) : this;
|
|
31726
|
+
};
|
|
31727
|
+
var ActivityIdentity = class {
|
|
31728
|
+
id;
|
|
31729
|
+
sequence;
|
|
31730
|
+
constructor(id, sequence) {
|
|
31731
|
+
this.id = id;
|
|
31732
|
+
this.sequence = sequence;
|
|
31733
|
+
}
|
|
31734
|
+
};
|
|
31735
|
+
var AcpActivityTracker = class {
|
|
31736
|
+
#activities = /* @__PURE__ */ new Map();
|
|
31737
|
+
#identities = /* @__PURE__ */ new Map();
|
|
31738
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
31739
|
+
#onActivity;
|
|
31740
|
+
#onNarration;
|
|
31741
|
+
#prepareContent;
|
|
31742
|
+
#activeNarrativeKey = "";
|
|
31743
|
+
#nextSequence = 0;
|
|
31744
|
+
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
31745
|
+
this.#onActivity = onActivity;
|
|
31746
|
+
this.#onNarration = onNarration;
|
|
31747
|
+
this.#prepareContent = prepareContent;
|
|
31748
|
+
}
|
|
31749
|
+
recordNarrative = async (activityType, messageId, text2) => {
|
|
31750
|
+
const key = `${activityType}:${messageId}`;
|
|
31751
|
+
if (this.#activeNarrativeKey !== key) {
|
|
31752
|
+
await this.finishNarrative();
|
|
31753
|
+
}
|
|
31754
|
+
const identity2 = this.#identity(key);
|
|
31755
|
+
const previous = this.#narrations.get(key);
|
|
31756
|
+
const previousOutput = previous?.output ?? "";
|
|
31757
|
+
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
31758
|
+
this.#narrations.set(key, {
|
|
31759
|
+
activityId: identity2.id,
|
|
31760
|
+
activityType,
|
|
31761
|
+
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
31762
|
+
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
31763
|
+
sequence: identity2.sequence,
|
|
31764
|
+
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
31765
|
+
});
|
|
31766
|
+
if (previous === void 0) {
|
|
31767
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
31768
|
+
}
|
|
31769
|
+
this.#activeNarrativeKey = key;
|
|
31770
|
+
if (text2.length > 0) {
|
|
31771
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
31772
|
+
}
|
|
31773
|
+
};
|
|
31774
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
31775
|
+
identity2.id,
|
|
31776
|
+
activityType,
|
|
31777
|
+
"",
|
|
31778
|
+
[],
|
|
31779
|
+
"",
|
|
31780
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31781
|
+
identity2.sequence,
|
|
31782
|
+
status,
|
|
31783
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
31784
|
+
activityType === "reasoning" ? "think" : ""
|
|
31785
|
+
);
|
|
31786
|
+
recordPlan = async (plan) => {
|
|
31787
|
+
await this.finishNarrative();
|
|
31788
|
+
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
31789
|
+
};
|
|
31790
|
+
recordPlanUpdate = async (update) => {
|
|
31791
|
+
await this.finishNarrative();
|
|
31792
|
+
const plan = update.plan;
|
|
31793
|
+
const key = `plan:${plan.planId}`;
|
|
31794
|
+
if (plan.type === "items") {
|
|
31795
|
+
await this.#recordPlanEntries(key, plan.entries);
|
|
31796
|
+
return;
|
|
31797
|
+
}
|
|
31798
|
+
const identity2 = this.#identity(key);
|
|
31799
|
+
const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
|
|
31800
|
+
await this.#record(
|
|
31801
|
+
key,
|
|
31802
|
+
new AcpActivity(
|
|
31803
|
+
identity2.id,
|
|
31804
|
+
"plan",
|
|
31805
|
+
"",
|
|
31806
|
+
[],
|
|
31807
|
+
"",
|
|
31808
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31809
|
+
identity2.sequence,
|
|
31810
|
+
"running",
|
|
31811
|
+
"Plan",
|
|
31812
|
+
""
|
|
31813
|
+
)
|
|
31814
|
+
);
|
|
31815
|
+
};
|
|
31816
|
+
removePlan = async (update) => {
|
|
31817
|
+
await this.finishNarrative();
|
|
31818
|
+
const key = `plan:${update.planId}`;
|
|
31819
|
+
const previous = this.#activities.get(key);
|
|
31820
|
+
if (previous !== void 0) {
|
|
31821
|
+
await this.#record(
|
|
31822
|
+
key,
|
|
31823
|
+
new AcpActivity(
|
|
31824
|
+
previous.activityId,
|
|
31825
|
+
previous.activityType,
|
|
31826
|
+
previous.input,
|
|
31827
|
+
previous.locations,
|
|
31828
|
+
previous.name,
|
|
31829
|
+
previous.output,
|
|
31830
|
+
previous.sequence,
|
|
31831
|
+
"completed",
|
|
31832
|
+
previous.title,
|
|
31833
|
+
previous.toolKind,
|
|
31834
|
+
previous.content,
|
|
31835
|
+
previous.detail
|
|
31836
|
+
)
|
|
31837
|
+
);
|
|
31838
|
+
}
|
|
31839
|
+
};
|
|
31840
|
+
recordToolCall = async (update) => {
|
|
31841
|
+
await this.finishNarrative();
|
|
31842
|
+
const key = `tool:${update.toolCallId}`;
|
|
31843
|
+
const identity2 = this.#identity(key);
|
|
31844
|
+
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
31845
|
+
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
31846
|
+
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
31847
|
+
const detailContent = await normalizeToolContent(
|
|
31848
|
+
toolContent(update.content, update.rawOutput),
|
|
31849
|
+
this.#prepareContent
|
|
31850
|
+
);
|
|
31851
|
+
await this.#record(
|
|
31852
|
+
key,
|
|
31853
|
+
new AcpActivity(
|
|
31854
|
+
identity2.id,
|
|
31855
|
+
"tool",
|
|
31856
|
+
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
31857
|
+
normalizeLocations(update.locations ?? []),
|
|
31858
|
+
truncate2(update.name ?? "", 128),
|
|
31859
|
+
output2,
|
|
31860
|
+
identity2.sequence,
|
|
31861
|
+
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
31862
|
+
normalizeTitle(update.title, "Tool call"),
|
|
31863
|
+
update.kind ?? "other",
|
|
31864
|
+
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
31865
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
31866
|
+
)
|
|
31867
|
+
);
|
|
31868
|
+
};
|
|
31869
|
+
recordToolCallUpdate = async (update) => {
|
|
31870
|
+
await this.finishNarrative();
|
|
31871
|
+
const key = `tool:${update.toolCallId}`;
|
|
31872
|
+
const previous = this.#activities.get(key);
|
|
31873
|
+
const identity2 = this.#identity(key);
|
|
31874
|
+
const previousDetail = recordedDetail(previous);
|
|
31875
|
+
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
31876
|
+
const nextContent = toolContent(update.content, update.rawOutput);
|
|
31877
|
+
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
31878
|
+
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
31879
|
+
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
31880
|
+
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
31881
|
+
await this.#record(
|
|
31882
|
+
key,
|
|
31883
|
+
new AcpActivity(
|
|
31884
|
+
identity2.id,
|
|
31885
|
+
"tool",
|
|
31886
|
+
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
31887
|
+
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
31888
|
+
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
31889
|
+
output2,
|
|
31890
|
+
identity2.sequence,
|
|
31891
|
+
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
31892
|
+
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
31893
|
+
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
31894
|
+
content.slice(0, 100).map(summarizeDisplayContent),
|
|
31895
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
31896
|
+
)
|
|
31897
|
+
);
|
|
31898
|
+
};
|
|
31899
|
+
finishNarrative = async () => {
|
|
31900
|
+
const key = this.#activeNarrativeKey;
|
|
31901
|
+
if (key.length === 0) {
|
|
31902
|
+
return;
|
|
31903
|
+
}
|
|
31904
|
+
this.#activeNarrativeKey = "";
|
|
31905
|
+
await this.#completeNarrative(key);
|
|
31906
|
+
};
|
|
31907
|
+
finish = async () => {
|
|
31908
|
+
await this.finishNarrative();
|
|
31909
|
+
for (const key of this.#narrations.keys()) {
|
|
31910
|
+
await this.#completeNarrative(key);
|
|
31911
|
+
}
|
|
31912
|
+
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
31913
|
+
for (const [key, activity2] of entries) {
|
|
31914
|
+
const completed = activity2.complete();
|
|
31915
|
+
if (completed !== activity2) {
|
|
31916
|
+
await this.#record(key, completed);
|
|
31917
|
+
}
|
|
31918
|
+
}
|
|
31919
|
+
};
|
|
31920
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
31921
|
+
// incremental events carried the text; this final event gives consumers the
|
|
31922
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
31923
|
+
#completeNarrative = async (key) => {
|
|
31924
|
+
const narration = this.#narrations.get(key);
|
|
31925
|
+
if (narration === void 0) {
|
|
31926
|
+
return;
|
|
31927
|
+
}
|
|
31928
|
+
this.#narrations.delete(key);
|
|
31929
|
+
const previous = this.#activities.get(key);
|
|
31930
|
+
const detail = narration.truncated ? {
|
|
31931
|
+
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
31932
|
+
kind: "truncated",
|
|
31933
|
+
originalBytes: narration.originalBytes
|
|
31934
|
+
} : captureActivityDetail([], "", narration.output);
|
|
31935
|
+
await this.#record(
|
|
31936
|
+
key,
|
|
31937
|
+
new AcpActivity(
|
|
31938
|
+
narration.activityId,
|
|
31939
|
+
narration.activityType,
|
|
31940
|
+
"",
|
|
31941
|
+
[],
|
|
31942
|
+
"",
|
|
31943
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
31944
|
+
narration.sequence,
|
|
31945
|
+
"completed",
|
|
31946
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
31947
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
31948
|
+
previous?.content ?? [],
|
|
31949
|
+
detail
|
|
31950
|
+
)
|
|
31951
|
+
);
|
|
31952
|
+
};
|
|
31953
|
+
#identity = (key) => {
|
|
31954
|
+
const existing = this.#identities.get(key);
|
|
31955
|
+
if (existing !== void 0) {
|
|
31956
|
+
return existing;
|
|
31957
|
+
}
|
|
31958
|
+
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
31959
|
+
this.#nextSequence += 1;
|
|
31960
|
+
this.#identities.set(key, identity2);
|
|
31961
|
+
return identity2;
|
|
31962
|
+
};
|
|
31963
|
+
#record = async (key, activity2) => {
|
|
31964
|
+
this.#activities.set(key, activity2);
|
|
31965
|
+
await this.#onActivity(activity2);
|
|
31966
|
+
};
|
|
31967
|
+
#recordPlanEntries = async (key, entries) => {
|
|
31968
|
+
const identity2 = this.#identity(key);
|
|
31969
|
+
await this.#record(
|
|
31970
|
+
key,
|
|
31971
|
+
new AcpActivity(
|
|
31972
|
+
identity2.id,
|
|
31973
|
+
"plan",
|
|
31974
|
+
"",
|
|
31975
|
+
[],
|
|
31976
|
+
"",
|
|
31977
|
+
formatPlanEntries(entries),
|
|
31978
|
+
identity2.sequence,
|
|
31979
|
+
planStatus(entries),
|
|
31980
|
+
"Plan",
|
|
31981
|
+
""
|
|
31982
|
+
)
|
|
31983
|
+
);
|
|
31984
|
+
};
|
|
31985
|
+
};
|
|
31986
|
+
|
|
31987
|
+
// src/acp/agent-turn.ts
|
|
31988
|
+
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31989
|
+
var AcpTurnState = class {
|
|
31990
|
+
#bufferedText = [];
|
|
31991
|
+
bufferText = (text2, messageId) => {
|
|
31992
|
+
const previous = this.#bufferedText.at(-1);
|
|
31993
|
+
if (previous?.messageId === messageId) {
|
|
31994
|
+
previous.chunks.push(text2);
|
|
31995
|
+
} else {
|
|
31996
|
+
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
31997
|
+
}
|
|
31998
|
+
};
|
|
31999
|
+
flushText = async () => {
|
|
32000
|
+
const buffered = this.#bufferedText;
|
|
32001
|
+
this.#bufferedText = [];
|
|
32002
|
+
for (const message of buffered) {
|
|
32003
|
+
for (const chunk of message.chunks) {
|
|
32004
|
+
await this.onText(chunk, message.messageId);
|
|
32005
|
+
}
|
|
32006
|
+
}
|
|
32007
|
+
};
|
|
32008
|
+
recordTextAsProgress = async () => {
|
|
32009
|
+
const buffered = this.#bufferedText;
|
|
32010
|
+
this.#bufferedText = [];
|
|
32011
|
+
for (const message of buffered) {
|
|
32012
|
+
for (const chunk of message.chunks) {
|
|
32013
|
+
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
32014
|
+
}
|
|
32015
|
+
}
|
|
32016
|
+
};
|
|
32017
|
+
};
|
|
32018
|
+
var IdleAcpTurn = class extends AcpTurnState {
|
|
32019
|
+
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
32020
|
+
running = false;
|
|
32021
|
+
activities = new AcpActivityTracker(
|
|
32022
|
+
() => Promise.resolve(),
|
|
32023
|
+
() => Promise.resolve()
|
|
32024
|
+
);
|
|
32025
|
+
onText = () => Promise.resolve();
|
|
32026
|
+
};
|
|
32027
|
+
var RunningAcpTurn = class extends AcpTurnState {
|
|
32028
|
+
commandId;
|
|
32029
|
+
running = true;
|
|
32030
|
+
activities;
|
|
32031
|
+
onText;
|
|
32032
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32033
|
+
super();
|
|
32034
|
+
this.commandId = commandId;
|
|
32035
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32036
|
+
this.onText = onText;
|
|
32037
|
+
}
|
|
32038
|
+
};
|
|
32039
|
+
|
|
31645
32040
|
// src/acp/native-session.ts
|
|
31646
32041
|
var path2 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
31647
32042
|
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
@@ -31965,321 +32360,6 @@ var AcpAgentSettingsSnapshot = class {
|
|
|
31965
32360
|
}
|
|
31966
32361
|
};
|
|
31967
32362
|
|
|
31968
|
-
// src/acp/activity.ts
|
|
31969
|
-
var AcpActivityNarration = class {
|
|
31970
|
-
activityId;
|
|
31971
|
-
activityType;
|
|
31972
|
-
sequence;
|
|
31973
|
-
text;
|
|
31974
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
31975
|
-
this.activityId = activityId;
|
|
31976
|
-
this.activityType = activityType;
|
|
31977
|
-
this.sequence = sequence;
|
|
31978
|
-
this.text = text2;
|
|
31979
|
-
}
|
|
31980
|
-
};
|
|
31981
|
-
var AcpActivity = class _AcpActivity {
|
|
31982
|
-
activityId;
|
|
31983
|
-
activityType;
|
|
31984
|
-
input;
|
|
31985
|
-
locations;
|
|
31986
|
-
name;
|
|
31987
|
-
output;
|
|
31988
|
-
sequence;
|
|
31989
|
-
status;
|
|
31990
|
-
title;
|
|
31991
|
-
toolKind;
|
|
31992
|
-
content;
|
|
31993
|
-
detail;
|
|
31994
|
-
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31995
|
-
this.activityId = activityId;
|
|
31996
|
-
this.activityType = activityType;
|
|
31997
|
-
this.input = input2;
|
|
31998
|
-
this.locations = locations;
|
|
31999
|
-
this.name = name;
|
|
32000
|
-
this.output = output2;
|
|
32001
|
-
this.sequence = sequence;
|
|
32002
|
-
this.status = status;
|
|
32003
|
-
this.title = title2;
|
|
32004
|
-
this.toolKind = toolKind;
|
|
32005
|
-
this.content = content;
|
|
32006
|
-
this.detail = detail;
|
|
32007
|
-
}
|
|
32008
|
-
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
32009
|
-
this.activityId,
|
|
32010
|
-
this.activityType,
|
|
32011
|
-
this.input,
|
|
32012
|
-
this.locations,
|
|
32013
|
-
this.name,
|
|
32014
|
-
this.output,
|
|
32015
|
-
this.sequence,
|
|
32016
|
-
"completed",
|
|
32017
|
-
this.title,
|
|
32018
|
-
this.toolKind,
|
|
32019
|
-
this.content,
|
|
32020
|
-
this.detail
|
|
32021
|
-
) : this;
|
|
32022
|
-
};
|
|
32023
|
-
var ActivityIdentity = class {
|
|
32024
|
-
id;
|
|
32025
|
-
sequence;
|
|
32026
|
-
constructor(id, sequence) {
|
|
32027
|
-
this.id = id;
|
|
32028
|
-
this.sequence = sequence;
|
|
32029
|
-
}
|
|
32030
|
-
};
|
|
32031
|
-
var AcpActivityTracker = class {
|
|
32032
|
-
#activities = /* @__PURE__ */ new Map();
|
|
32033
|
-
#identities = /* @__PURE__ */ new Map();
|
|
32034
|
-
#narrations = /* @__PURE__ */ new Map();
|
|
32035
|
-
#onActivity;
|
|
32036
|
-
#onNarration;
|
|
32037
|
-
#prepareContent;
|
|
32038
|
-
#activeNarrativeKey = "";
|
|
32039
|
-
#nextSequence = 0;
|
|
32040
|
-
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
32041
|
-
this.#onActivity = onActivity;
|
|
32042
|
-
this.#onNarration = onNarration;
|
|
32043
|
-
this.#prepareContent = prepareContent;
|
|
32044
|
-
}
|
|
32045
|
-
recordNarrative = async (activityType, messageId, text2) => {
|
|
32046
|
-
const key = `${activityType}:${messageId}`;
|
|
32047
|
-
if (this.#activeNarrativeKey !== key) {
|
|
32048
|
-
await this.finishNarrative();
|
|
32049
|
-
}
|
|
32050
|
-
const identity2 = this.#identity(key);
|
|
32051
|
-
const previous = this.#narrations.get(key);
|
|
32052
|
-
const previousOutput = previous?.output ?? "";
|
|
32053
|
-
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
32054
|
-
this.#narrations.set(key, {
|
|
32055
|
-
activityId: identity2.id,
|
|
32056
|
-
activityType,
|
|
32057
|
-
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
32058
|
-
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
32059
|
-
sequence: identity2.sequence,
|
|
32060
|
-
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
32061
|
-
});
|
|
32062
|
-
if (previous === void 0) {
|
|
32063
|
-
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
32064
|
-
}
|
|
32065
|
-
this.#activeNarrativeKey = key;
|
|
32066
|
-
if (text2.length > 0) {
|
|
32067
|
-
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
32068
|
-
}
|
|
32069
|
-
};
|
|
32070
|
-
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
32071
|
-
identity2.id,
|
|
32072
|
-
activityType,
|
|
32073
|
-
"",
|
|
32074
|
-
[],
|
|
32075
|
-
"",
|
|
32076
|
-
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32077
|
-
identity2.sequence,
|
|
32078
|
-
status,
|
|
32079
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
32080
|
-
activityType === "reasoning" ? "think" : ""
|
|
32081
|
-
);
|
|
32082
|
-
recordPlan = async (plan) => {
|
|
32083
|
-
await this.finishNarrative();
|
|
32084
|
-
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
32085
|
-
};
|
|
32086
|
-
recordPlanUpdate = async (update) => {
|
|
32087
|
-
await this.finishNarrative();
|
|
32088
|
-
const plan = update.plan;
|
|
32089
|
-
const key = `plan:${plan.planId}`;
|
|
32090
|
-
if (plan.type === "items") {
|
|
32091
|
-
await this.#recordPlanEntries(key, plan.entries);
|
|
32092
|
-
return;
|
|
32093
|
-
}
|
|
32094
|
-
const identity2 = this.#identity(key);
|
|
32095
|
-
const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
|
|
32096
|
-
await this.#record(
|
|
32097
|
-
key,
|
|
32098
|
-
new AcpActivity(
|
|
32099
|
-
identity2.id,
|
|
32100
|
-
"plan",
|
|
32101
|
-
"",
|
|
32102
|
-
[],
|
|
32103
|
-
"",
|
|
32104
|
-
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32105
|
-
identity2.sequence,
|
|
32106
|
-
"running",
|
|
32107
|
-
"Plan",
|
|
32108
|
-
""
|
|
32109
|
-
)
|
|
32110
|
-
);
|
|
32111
|
-
};
|
|
32112
|
-
removePlan = async (update) => {
|
|
32113
|
-
await this.finishNarrative();
|
|
32114
|
-
const key = `plan:${update.planId}`;
|
|
32115
|
-
const previous = this.#activities.get(key);
|
|
32116
|
-
if (previous !== void 0) {
|
|
32117
|
-
await this.#record(
|
|
32118
|
-
key,
|
|
32119
|
-
new AcpActivity(
|
|
32120
|
-
previous.activityId,
|
|
32121
|
-
previous.activityType,
|
|
32122
|
-
previous.input,
|
|
32123
|
-
previous.locations,
|
|
32124
|
-
previous.name,
|
|
32125
|
-
previous.output,
|
|
32126
|
-
previous.sequence,
|
|
32127
|
-
"completed",
|
|
32128
|
-
previous.title,
|
|
32129
|
-
previous.toolKind,
|
|
32130
|
-
previous.content,
|
|
32131
|
-
previous.detail
|
|
32132
|
-
)
|
|
32133
|
-
);
|
|
32134
|
-
}
|
|
32135
|
-
};
|
|
32136
|
-
recordToolCall = async (update) => {
|
|
32137
|
-
await this.finishNarrative();
|
|
32138
|
-
const key = `tool:${update.toolCallId}`;
|
|
32139
|
-
const identity2 = this.#identity(key);
|
|
32140
|
-
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
32141
|
-
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
32142
|
-
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
32143
|
-
const detailContent = await normalizeToolContent(
|
|
32144
|
-
toolContent(update.content, update.rawOutput),
|
|
32145
|
-
this.#prepareContent
|
|
32146
|
-
);
|
|
32147
|
-
await this.#record(
|
|
32148
|
-
key,
|
|
32149
|
-
new AcpActivity(
|
|
32150
|
-
identity2.id,
|
|
32151
|
-
"tool",
|
|
32152
|
-
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
32153
|
-
normalizeLocations(update.locations ?? []),
|
|
32154
|
-
truncate2(update.name ?? "", 128),
|
|
32155
|
-
output2,
|
|
32156
|
-
identity2.sequence,
|
|
32157
|
-
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
32158
|
-
normalizeTitle(update.title, "Tool call"),
|
|
32159
|
-
update.kind ?? "other",
|
|
32160
|
-
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
32161
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
32162
|
-
)
|
|
32163
|
-
);
|
|
32164
|
-
};
|
|
32165
|
-
recordToolCallUpdate = async (update) => {
|
|
32166
|
-
await this.finishNarrative();
|
|
32167
|
-
const key = `tool:${update.toolCallId}`;
|
|
32168
|
-
const previous = this.#activities.get(key);
|
|
32169
|
-
const identity2 = this.#identity(key);
|
|
32170
|
-
const previousDetail = recordedDetail(previous);
|
|
32171
|
-
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
32172
|
-
const nextContent = toolContent(update.content, update.rawOutput);
|
|
32173
|
-
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
32174
|
-
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
32175
|
-
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
32176
|
-
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
32177
|
-
await this.#record(
|
|
32178
|
-
key,
|
|
32179
|
-
new AcpActivity(
|
|
32180
|
-
identity2.id,
|
|
32181
|
-
"tool",
|
|
32182
|
-
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
32183
|
-
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
32184
|
-
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
32185
|
-
output2,
|
|
32186
|
-
identity2.sequence,
|
|
32187
|
-
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
32188
|
-
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
32189
|
-
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
32190
|
-
content.slice(0, 100).map(summarizeDisplayContent),
|
|
32191
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
32192
|
-
)
|
|
32193
|
-
);
|
|
32194
|
-
};
|
|
32195
|
-
finishNarrative = async () => {
|
|
32196
|
-
const key = this.#activeNarrativeKey;
|
|
32197
|
-
if (key.length === 0) {
|
|
32198
|
-
return;
|
|
32199
|
-
}
|
|
32200
|
-
this.#activeNarrativeKey = "";
|
|
32201
|
-
await this.#completeNarrative(key);
|
|
32202
|
-
};
|
|
32203
|
-
finish = async () => {
|
|
32204
|
-
await this.finishNarrative();
|
|
32205
|
-
for (const key of this.#narrations.keys()) {
|
|
32206
|
-
await this.#completeNarrative(key);
|
|
32207
|
-
}
|
|
32208
|
-
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
32209
|
-
for (const [key, activity2] of entries) {
|
|
32210
|
-
const completed = activity2.complete();
|
|
32211
|
-
if (completed !== activity2) {
|
|
32212
|
-
await this.#record(key, completed);
|
|
32213
|
-
}
|
|
32214
|
-
}
|
|
32215
|
-
};
|
|
32216
|
-
// Materialize a streamed narration as one completed snapshot activity. The
|
|
32217
|
-
// incremental events carried the text; this final event gives consumers the
|
|
32218
|
-
// whole narration with its terminal status, as a single bounded item.
|
|
32219
|
-
#completeNarrative = async (key) => {
|
|
32220
|
-
const narration = this.#narrations.get(key);
|
|
32221
|
-
if (narration === void 0) {
|
|
32222
|
-
return;
|
|
32223
|
-
}
|
|
32224
|
-
this.#narrations.delete(key);
|
|
32225
|
-
const previous = this.#activities.get(key);
|
|
32226
|
-
const detail = narration.truncated ? {
|
|
32227
|
-
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
32228
|
-
kind: "truncated",
|
|
32229
|
-
originalBytes: narration.originalBytes
|
|
32230
|
-
} : captureActivityDetail([], "", narration.output);
|
|
32231
|
-
await this.#record(
|
|
32232
|
-
key,
|
|
32233
|
-
new AcpActivity(
|
|
32234
|
-
narration.activityId,
|
|
32235
|
-
narration.activityType,
|
|
32236
|
-
"",
|
|
32237
|
-
[],
|
|
32238
|
-
"",
|
|
32239
|
-
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
32240
|
-
narration.sequence,
|
|
32241
|
-
"completed",
|
|
32242
|
-
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
32243
|
-
narration.activityType === "reasoning" ? "think" : "",
|
|
32244
|
-
previous?.content ?? [],
|
|
32245
|
-
detail
|
|
32246
|
-
)
|
|
32247
|
-
);
|
|
32248
|
-
};
|
|
32249
|
-
#identity = (key) => {
|
|
32250
|
-
const existing = this.#identities.get(key);
|
|
32251
|
-
if (existing !== void 0) {
|
|
32252
|
-
return existing;
|
|
32253
|
-
}
|
|
32254
|
-
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
32255
|
-
this.#nextSequence += 1;
|
|
32256
|
-
this.#identities.set(key, identity2);
|
|
32257
|
-
return identity2;
|
|
32258
|
-
};
|
|
32259
|
-
#record = async (key, activity2) => {
|
|
32260
|
-
this.#activities.set(key, activity2);
|
|
32261
|
-
await this.#onActivity(activity2);
|
|
32262
|
-
};
|
|
32263
|
-
#recordPlanEntries = async (key, entries) => {
|
|
32264
|
-
const identity2 = this.#identity(key);
|
|
32265
|
-
await this.#record(
|
|
32266
|
-
key,
|
|
32267
|
-
new AcpActivity(
|
|
32268
|
-
identity2.id,
|
|
32269
|
-
"plan",
|
|
32270
|
-
"",
|
|
32271
|
-
[],
|
|
32272
|
-
"",
|
|
32273
|
-
formatPlanEntries(entries),
|
|
32274
|
-
identity2.sequence,
|
|
32275
|
-
planStatus(entries),
|
|
32276
|
-
"Plan",
|
|
32277
|
-
""
|
|
32278
|
-
)
|
|
32279
|
-
);
|
|
32280
|
-
};
|
|
32281
|
-
};
|
|
32282
|
-
|
|
32283
32363
|
// src/acp/session-history.ts
|
|
32284
32364
|
var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
|
|
32285
32365
|
var HISTORY_ACTIVITY_LIMIT = 100;
|
|
@@ -32712,31 +32792,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
32712
32792
|
return validated;
|
|
32713
32793
|
}
|
|
32714
32794
|
|
|
32715
|
-
// src/acp/
|
|
32716
|
-
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
32717
|
-
var AcpTurnState = class {
|
|
32718
|
-
};
|
|
32719
|
-
var IdleAcpTurn = class extends AcpTurnState {
|
|
32720
|
-
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
32721
|
-
running = false;
|
|
32722
|
-
activities = new AcpActivityTracker(
|
|
32723
|
-
() => Promise.resolve(),
|
|
32724
|
-
() => Promise.resolve()
|
|
32725
|
-
);
|
|
32726
|
-
onText = () => Promise.resolve();
|
|
32727
|
-
};
|
|
32728
|
-
var RunningAcpTurn = class extends AcpTurnState {
|
|
32729
|
-
commandId;
|
|
32730
|
-
running = true;
|
|
32731
|
-
activities;
|
|
32732
|
-
onText;
|
|
32733
|
-
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32734
|
-
super();
|
|
32735
|
-
this.commandId = commandId;
|
|
32736
|
-
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32737
|
-
this.onText = onText;
|
|
32738
|
-
}
|
|
32739
|
-
};
|
|
32795
|
+
// src/acp/pending-interactions.ts
|
|
32740
32796
|
var PendingPermission = class {
|
|
32741
32797
|
completion = Promise.withResolvers();
|
|
32742
32798
|
interactionId;
|
|
@@ -38687,7 +38743,6 @@ var AgentSession = class _AgentSession {
|
|
|
38687
38743
|
#verifiedAgentVersion;
|
|
38688
38744
|
#agentName = "";
|
|
38689
38745
|
#agentVersion = "";
|
|
38690
|
-
#bufferedAgentText = [];
|
|
38691
38746
|
#capabilities = unsupportedSessionCapabilities();
|
|
38692
38747
|
#commands = [];
|
|
38693
38748
|
#configRevision = 0;
|
|
@@ -38833,35 +38888,6 @@ var AgentSession = class _AgentSession {
|
|
|
38833
38888
|
this.#replay = { kind: "idle" };
|
|
38834
38889
|
}
|
|
38835
38890
|
};
|
|
38836
|
-
emitAgentMessage = async (chunks, messageId) => {
|
|
38837
|
-
for (const chunk of chunks) {
|
|
38838
|
-
await this.#turn.onText(chunk, messageId);
|
|
38839
|
-
}
|
|
38840
|
-
};
|
|
38841
|
-
bufferAgentText = async (text2, messageId) => {
|
|
38842
|
-
const previous = this.#bufferedAgentText.at(-1);
|
|
38843
|
-
if (previous?.messageId === messageId) {
|
|
38844
|
-
previous.chunks.push(text2);
|
|
38845
|
-
return;
|
|
38846
|
-
}
|
|
38847
|
-
this.#bufferedAgentText.push({ chunks: [text2], messageId });
|
|
38848
|
-
};
|
|
38849
|
-
flushAgentText = async () => {
|
|
38850
|
-
const buffered = this.#bufferedAgentText;
|
|
38851
|
-
this.#bufferedAgentText = [];
|
|
38852
|
-
for (const message of buffered) {
|
|
38853
|
-
await this.emitAgentMessage(message.chunks, message.messageId);
|
|
38854
|
-
}
|
|
38855
|
-
};
|
|
38856
|
-
recordBufferedAgentTextAsProgress = async () => {
|
|
38857
|
-
const buffered = this.#bufferedAgentText;
|
|
38858
|
-
this.#bufferedAgentText = [];
|
|
38859
|
-
for (const message of buffered) {
|
|
38860
|
-
for (const chunk of message.chunks) {
|
|
38861
|
-
await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
|
|
38862
|
-
}
|
|
38863
|
-
}
|
|
38864
|
-
};
|
|
38865
38891
|
prepareAgentContent = async (content) => {
|
|
38866
38892
|
if (content.type === "image" && content.uri.length > 0) {
|
|
38867
38893
|
const signal = AbortSignal.timeout(2e4);
|
|
@@ -39359,7 +39385,7 @@ var AgentSession = class _AgentSession {
|
|
|
39359
39385
|
options.signal
|
|
39360
39386
|
);
|
|
39361
39387
|
await this.#updates.drained();
|
|
39362
|
-
await this.
|
|
39388
|
+
await this.#turn.flushText();
|
|
39363
39389
|
await running.activities.finish();
|
|
39364
39390
|
let result;
|
|
39365
39391
|
try {
|
|
@@ -39391,7 +39417,6 @@ var AgentSession = class _AgentSession {
|
|
|
39391
39417
|
cause: error62
|
|
39392
39418
|
});
|
|
39393
39419
|
} finally {
|
|
39394
|
-
this.#bufferedAgentText = [];
|
|
39395
39420
|
this.#turn = new IdleAcpTurn();
|
|
39396
39421
|
}
|
|
39397
39422
|
};
|
|
@@ -39482,11 +39507,11 @@ var AgentSession = class _AgentSession {
|
|
|
39482
39507
|
);
|
|
39483
39508
|
} else {
|
|
39484
39509
|
await this.#turn.activities.finishNarrative();
|
|
39485
|
-
|
|
39510
|
+
this.#turn.bufferText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
39486
39511
|
}
|
|
39487
39512
|
} else {
|
|
39488
39513
|
await this.#turn.activities.finishNarrative();
|
|
39489
|
-
await this.
|
|
39514
|
+
await this.#turn.flushText();
|
|
39490
39515
|
await this.emitAgentContent(
|
|
39491
39516
|
normalizeContentBlock(update.content),
|
|
39492
39517
|
truncate3(update.messageId ?? "", 255)
|
|
@@ -39505,7 +39530,7 @@ var AgentSession = class _AgentSession {
|
|
|
39505
39530
|
return;
|
|
39506
39531
|
}
|
|
39507
39532
|
if (update.sessionUpdate === "tool_call") {
|
|
39508
|
-
await this.
|
|
39533
|
+
await this.#turn.recordTextAsProgress();
|
|
39509
39534
|
await this.#turn.activities.recordToolCall(update);
|
|
39510
39535
|
return;
|
|
39511
39536
|
}
|