@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/index.js
CHANGED
|
@@ -23275,429 +23275,106 @@ var AgentConnection = class {
|
|
|
23275
23275
|
};
|
|
23276
23276
|
};
|
|
23277
23277
|
|
|
23278
|
-
// src/acp/
|
|
23279
|
-
var
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
|
|
23288
|
-
|
|
23289
|
-
var nativeSessionPageSchema = external_exports.object({
|
|
23290
|
-
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
23291
|
-
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
23292
|
-
}).readonly();
|
|
23293
|
-
|
|
23294
|
-
// src/acp/agent-update-stream.ts
|
|
23295
|
-
var MAX_PENDING_UPDATES = 100;
|
|
23296
|
-
var MAX_PENDING_BYTES = 1024 * 1024;
|
|
23297
|
-
var AgentUpdateStream = class {
|
|
23298
|
-
#selection = { kind: "awaiting-session", notifications: [], bytes: 0 };
|
|
23299
|
-
#tail = Promise.resolve();
|
|
23300
|
-
#consume;
|
|
23301
|
-
constructor(consume) {
|
|
23302
|
-
this.#consume = consume;
|
|
23278
|
+
// src/acp/activity.ts
|
|
23279
|
+
var AcpActivityNarration = class {
|
|
23280
|
+
activityId;
|
|
23281
|
+
activityType;
|
|
23282
|
+
sequence;
|
|
23283
|
+
text;
|
|
23284
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
23285
|
+
this.activityId = activityId;
|
|
23286
|
+
this.activityType = activityType;
|
|
23287
|
+
this.sequence = sequence;
|
|
23288
|
+
this.text = text2;
|
|
23303
23289
|
}
|
|
23304
|
-
sessionId = () => this.#selection.kind === "selected" ? this.#selection.sessionId : "";
|
|
23305
|
-
drained = () => this.#tail;
|
|
23306
|
-
#enqueue = (notification) => {
|
|
23307
|
-
this.#tail = this.#tail.then(async () => await this.#consume(notification));
|
|
23308
|
-
return this.#tail;
|
|
23309
|
-
};
|
|
23310
|
-
receive = (notification) => {
|
|
23311
|
-
const selection = this.#selection;
|
|
23312
|
-
switch (selection.kind) {
|
|
23313
|
-
case "selected":
|
|
23314
|
-
return this.#enqueue(notification);
|
|
23315
|
-
case "awaiting-session": {
|
|
23316
|
-
const bytes = selection.bytes + Buffer.byteLength(JSON.stringify(notification));
|
|
23317
|
-
if (selection.notifications.length >= MAX_PENDING_UPDATES || bytes > MAX_PENDING_BYTES) {
|
|
23318
|
-
return Promise.reject(
|
|
23319
|
-
new AcpExecutionError(
|
|
23320
|
-
"ACP agent sent too many updates before creating its session",
|
|
23321
|
-
{},
|
|
23322
|
-
"agent_update_limit"
|
|
23323
|
-
)
|
|
23324
|
-
);
|
|
23325
|
-
}
|
|
23326
|
-
this.#selection = {
|
|
23327
|
-
kind: "awaiting-session",
|
|
23328
|
-
notifications: [...selection.notifications, notification],
|
|
23329
|
-
bytes
|
|
23330
|
-
};
|
|
23331
|
-
return Promise.resolve();
|
|
23332
|
-
}
|
|
23333
|
-
}
|
|
23334
|
-
};
|
|
23335
|
-
select = (sessionId) => {
|
|
23336
|
-
const selected = nativeSessionIdSchema.parse(sessionId);
|
|
23337
|
-
const selection = this.#selection;
|
|
23338
|
-
switch (selection.kind) {
|
|
23339
|
-
case "selected":
|
|
23340
|
-
if (selection.sessionId !== selected) {
|
|
23341
|
-
throw new AcpExecutionError(
|
|
23342
|
-
"ACP agent attempted to replace the selected session",
|
|
23343
|
-
{},
|
|
23344
|
-
"invalid_agent_session"
|
|
23345
|
-
);
|
|
23346
|
-
}
|
|
23347
|
-
return;
|
|
23348
|
-
case "awaiting-session":
|
|
23349
|
-
this.#selection = { kind: "selected", sessionId: selected };
|
|
23350
|
-
for (const notification of selection.notifications) {
|
|
23351
|
-
void this.#enqueue(notification);
|
|
23352
|
-
}
|
|
23353
|
-
return;
|
|
23354
|
-
}
|
|
23355
|
-
};
|
|
23356
23290
|
};
|
|
23357
|
-
|
|
23358
|
-
|
|
23359
|
-
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
|
|
23291
|
+
var AcpActivity = class _AcpActivity {
|
|
23292
|
+
activityId;
|
|
23293
|
+
activityType;
|
|
23294
|
+
input;
|
|
23295
|
+
locations;
|
|
23296
|
+
name;
|
|
23297
|
+
output;
|
|
23298
|
+
sequence;
|
|
23299
|
+
status;
|
|
23300
|
+
title;
|
|
23301
|
+
toolKind;
|
|
23302
|
+
content;
|
|
23303
|
+
detail;
|
|
23304
|
+
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
23305
|
+
this.activityId = activityId;
|
|
23306
|
+
this.activityType = activityType;
|
|
23307
|
+
this.input = input2;
|
|
23308
|
+
this.locations = locations;
|
|
23309
|
+
this.name = name;
|
|
23310
|
+
this.output = output2;
|
|
23311
|
+
this.sequence = sequence;
|
|
23312
|
+
this.status = status;
|
|
23313
|
+
this.title = title2;
|
|
23314
|
+
this.toolKind = toolKind;
|
|
23315
|
+
this.content = content;
|
|
23316
|
+
this.detail = detail;
|
|
23366
23317
|
}
|
|
23318
|
+
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
23319
|
+
this.activityId,
|
|
23320
|
+
this.activityType,
|
|
23321
|
+
this.input,
|
|
23322
|
+
this.locations,
|
|
23323
|
+
this.name,
|
|
23324
|
+
this.output,
|
|
23325
|
+
this.sequence,
|
|
23326
|
+
"completed",
|
|
23327
|
+
this.title,
|
|
23328
|
+
this.toolKind,
|
|
23329
|
+
this.content,
|
|
23330
|
+
this.detail
|
|
23331
|
+
) : this;
|
|
23367
23332
|
};
|
|
23368
|
-
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
function truncate3(value, maximum) {
|
|
23375
|
-
return value.length <= maximum ? value : value.slice(0, maximum);
|
|
23376
|
-
}
|
|
23377
|
-
function readBoolean(value, fallback = false) {
|
|
23378
|
-
return typeof value === "boolean" ? value : fallback;
|
|
23379
|
-
}
|
|
23380
|
-
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
23381
|
-
const value = option["value"];
|
|
23382
|
-
if (typeof value !== "string") {
|
|
23383
|
-
return void 0;
|
|
23333
|
+
var ActivityIdentity = class {
|
|
23334
|
+
id;
|
|
23335
|
+
sequence;
|
|
23336
|
+
constructor(id, sequence) {
|
|
23337
|
+
this.id = id;
|
|
23338
|
+
this.sequence = sequence;
|
|
23384
23339
|
}
|
|
23385
|
-
|
|
23386
|
-
|
|
23387
|
-
|
|
23388
|
-
|
|
23389
|
-
|
|
23390
|
-
|
|
23391
|
-
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
|
|
23395
|
-
|
|
23340
|
+
};
|
|
23341
|
+
var AcpActivityTracker = class {
|
|
23342
|
+
#activities = /* @__PURE__ */ new Map();
|
|
23343
|
+
#identities = /* @__PURE__ */ new Map();
|
|
23344
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
23345
|
+
#onActivity;
|
|
23346
|
+
#onNarration;
|
|
23347
|
+
#prepareContent;
|
|
23348
|
+
#activeNarrativeKey = "";
|
|
23349
|
+
#nextSequence = 0;
|
|
23350
|
+
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
23351
|
+
this.#onActivity = onActivity;
|
|
23352
|
+
this.#onNarration = onNarration;
|
|
23353
|
+
this.#prepareContent = prepareContent;
|
|
23396
23354
|
}
|
|
23397
|
-
|
|
23398
|
-
|
|
23399
|
-
if (
|
|
23400
|
-
|
|
23355
|
+
recordNarrative = async (activityType, messageId, text2) => {
|
|
23356
|
+
const key = `${activityType}:${messageId}`;
|
|
23357
|
+
if (this.#activeNarrativeKey !== key) {
|
|
23358
|
+
await this.finishNarrative();
|
|
23401
23359
|
}
|
|
23402
|
-
const
|
|
23403
|
-
|
|
23404
|
-
|
|
23405
|
-
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
|
|
23409
|
-
|
|
23410
|
-
|
|
23411
|
-
|
|
23412
|
-
|
|
23413
|
-
|
|
23414
|
-
|
|
23360
|
+
const identity2 = this.#identity(key);
|
|
23361
|
+
const previous = this.#narrations.get(key);
|
|
23362
|
+
const previousOutput = previous?.output ?? "";
|
|
23363
|
+
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
23364
|
+
this.#narrations.set(key, {
|
|
23365
|
+
activityId: identity2.id,
|
|
23366
|
+
activityType,
|
|
23367
|
+
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
23368
|
+
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
23369
|
+
sequence: identity2.sequence,
|
|
23370
|
+
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
23371
|
+
});
|
|
23372
|
+
if (previous === void 0) {
|
|
23373
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
23415
23374
|
}
|
|
23416
|
-
|
|
23417
|
-
if (
|
|
23418
|
-
|
|
23419
|
-
}
|
|
23420
|
-
}
|
|
23421
|
-
return normalized.slice(0, 500);
|
|
23422
|
-
}
|
|
23423
|
-
function normalizeConfigOptions(value, modes) {
|
|
23424
|
-
const normalized = [];
|
|
23425
|
-
if (Array.isArray(value)) {
|
|
23426
|
-
for (const option of value) {
|
|
23427
|
-
if (!isRecord5(option)) {
|
|
23428
|
-
continue;
|
|
23429
|
-
}
|
|
23430
|
-
const id = truncate3(readString3(option["id"]), 128);
|
|
23431
|
-
const name = truncate3(readString3(option["name"], id), 255);
|
|
23432
|
-
const category = truncate3(readString3(option["category"]), 128);
|
|
23433
|
-
if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
|
|
23434
|
-
continue;
|
|
23435
|
-
}
|
|
23436
|
-
if (option["type"] === "boolean") {
|
|
23437
|
-
normalized.push({
|
|
23438
|
-
booleanValue: readBoolean(option["currentValue"]),
|
|
23439
|
-
category,
|
|
23440
|
-
currentValue: "",
|
|
23441
|
-
description: truncate3(readString3(option["description"]), 500),
|
|
23442
|
-
id,
|
|
23443
|
-
name,
|
|
23444
|
-
type: "boolean",
|
|
23445
|
-
values: []
|
|
23446
|
-
});
|
|
23447
|
-
continue;
|
|
23448
|
-
}
|
|
23449
|
-
if (option["type"] === "select") {
|
|
23450
|
-
const values = normalizeConfigValues(option["options"]);
|
|
23451
|
-
const currentValue = truncate3(readString3(option["currentValue"]), 500);
|
|
23452
|
-
if (values.some((entry) => entry.value === currentValue)) {
|
|
23453
|
-
normalized.push({
|
|
23454
|
-
booleanValue: false,
|
|
23455
|
-
category,
|
|
23456
|
-
currentValue,
|
|
23457
|
-
description: truncate3(readString3(option["description"]), 500),
|
|
23458
|
-
id,
|
|
23459
|
-
name,
|
|
23460
|
-
type: "select",
|
|
23461
|
-
values
|
|
23462
|
-
});
|
|
23463
|
-
}
|
|
23464
|
-
}
|
|
23465
|
-
}
|
|
23466
|
-
}
|
|
23467
|
-
if (isRecord5(modes)) {
|
|
23468
|
-
const values = [];
|
|
23469
|
-
const availableModes = modes["availableModes"];
|
|
23470
|
-
if (Array.isArray(availableModes)) {
|
|
23471
|
-
for (const mode of availableModes) {
|
|
23472
|
-
if (!isRecord5(mode)) {
|
|
23473
|
-
continue;
|
|
23474
|
-
}
|
|
23475
|
-
const id = truncate3(readString3(mode["id"]), 500);
|
|
23476
|
-
if (id.length === 0) {
|
|
23477
|
-
continue;
|
|
23478
|
-
}
|
|
23479
|
-
values.push({
|
|
23480
|
-
description: truncate3(readString3(mode["description"]), 500),
|
|
23481
|
-
groupId: "",
|
|
23482
|
-
groupName: "",
|
|
23483
|
-
name: truncate3(readString3(mode["name"], id), 255),
|
|
23484
|
-
value: id
|
|
23485
|
-
});
|
|
23486
|
-
}
|
|
23487
|
-
}
|
|
23488
|
-
const currentValue = truncate3(readString3(modes["currentModeId"]), 500);
|
|
23489
|
-
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode")) {
|
|
23490
|
-
normalized.unshift({
|
|
23491
|
-
booleanValue: false,
|
|
23492
|
-
category: "mode",
|
|
23493
|
-
currentValue,
|
|
23494
|
-
description: "Agent session mode",
|
|
23495
|
-
id: "mode",
|
|
23496
|
-
name: "Mode",
|
|
23497
|
-
type: "select",
|
|
23498
|
-
values
|
|
23499
|
-
});
|
|
23500
|
-
}
|
|
23501
|
-
}
|
|
23502
|
-
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
23503
|
-
}
|
|
23504
|
-
function normalizeStandardLifecycle(response) {
|
|
23505
|
-
const lifecycle = isRecord5(response) ? response : {};
|
|
23506
|
-
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
23507
|
-
}
|
|
23508
|
-
function replaceStandardConfigOptions(current, value) {
|
|
23509
|
-
const next = normalizeConfigOptions(value, void 0);
|
|
23510
|
-
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
23511
|
-
return withMode;
|
|
23512
|
-
}
|
|
23513
|
-
function updateCurrentValue(current, configId, value) {
|
|
23514
|
-
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
23515
|
-
}
|
|
23516
|
-
var StandardSessionConfigProtocol = class {
|
|
23517
|
-
configure = async (current, change, nativeSessionId, transport) => {
|
|
23518
|
-
const existing = current.find((option) => option.id === change.configId);
|
|
23519
|
-
if (existing === void 0) {
|
|
23520
|
-
return current;
|
|
23521
|
-
}
|
|
23522
|
-
if (existing.type === "select" && existing.category === "mode") {
|
|
23523
|
-
await transport.request(
|
|
23524
|
-
methods2.agent.session.setMode,
|
|
23525
|
-
{ modeId: change.value, sessionId: nativeSessionId },
|
|
23526
|
-
"ACP agent exited while setting the session mode",
|
|
23527
|
-
change.signal
|
|
23528
|
-
);
|
|
23529
|
-
return updateCurrentValue(current, existing.id, change.value);
|
|
23530
|
-
}
|
|
23531
|
-
const params = existing.type === "boolean" ? {
|
|
23532
|
-
configId: existing.id,
|
|
23533
|
-
sessionId: nativeSessionId,
|
|
23534
|
-
type: "boolean",
|
|
23535
|
-
value: change.booleanValue
|
|
23536
|
-
} : {
|
|
23537
|
-
configId: existing.id,
|
|
23538
|
-
sessionId: nativeSessionId,
|
|
23539
|
-
value: change.value
|
|
23540
|
-
};
|
|
23541
|
-
const response = await transport.request(
|
|
23542
|
-
methods2.agent.session.setConfigOption,
|
|
23543
|
-
params,
|
|
23544
|
-
"ACP agent exited while changing session configuration",
|
|
23545
|
-
change.signal
|
|
23546
|
-
);
|
|
23547
|
-
if (!isRecord5(response) || !Array.isArray(response["configOptions"])) {
|
|
23548
|
-
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
23549
|
-
}
|
|
23550
|
-
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
23551
|
-
};
|
|
23552
|
-
normalizeLifecycle = (response) => normalizeStandardLifecycle(response);
|
|
23553
|
-
normalizeUpdate = (current, value) => replaceStandardConfigOptions(current, value);
|
|
23554
|
-
};
|
|
23555
|
-
var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
23556
|
-
|
|
23557
|
-
// src/acp/session-config/session-config-registry.ts
|
|
23558
|
-
function sessionConfigProtocolForAgent(_agentId) {
|
|
23559
|
-
return standardSessionConfigProtocol;
|
|
23560
|
-
}
|
|
23561
|
-
|
|
23562
|
-
// src/acp/session-contracts.ts
|
|
23563
|
-
var NullAcpSessionObserver = class {
|
|
23564
|
-
onCommands = () => Promise.resolve();
|
|
23565
|
-
onConfig = () => Promise.resolve();
|
|
23566
|
-
onContent = () => Promise.resolve();
|
|
23567
|
-
onElicitation = () => Promise.resolve();
|
|
23568
|
-
onElicitationResolved = () => Promise.resolve();
|
|
23569
|
-
onInfo = () => Promise.resolve();
|
|
23570
|
-
onPermission = () => Promise.resolve();
|
|
23571
|
-
onPermissionResolved = () => Promise.resolve();
|
|
23572
|
-
onUsage = () => Promise.resolve();
|
|
23573
|
-
};
|
|
23574
|
-
var AcpPreparedSession = class {
|
|
23575
|
-
agentName;
|
|
23576
|
-
agentVersion;
|
|
23577
|
-
capabilities;
|
|
23578
|
-
commands;
|
|
23579
|
-
configOptions;
|
|
23580
|
-
restored;
|
|
23581
|
-
constructor(agentName, agentVersion, capabilities, commands, configOptions, restored) {
|
|
23582
|
-
this.agentName = agentName;
|
|
23583
|
-
this.agentVersion = agentVersion;
|
|
23584
|
-
this.capabilities = capabilities;
|
|
23585
|
-
this.commands = commands;
|
|
23586
|
-
this.configOptions = configOptions;
|
|
23587
|
-
this.restored = restored;
|
|
23588
|
-
}
|
|
23589
|
-
};
|
|
23590
|
-
var AcpAgentSettingsSnapshot = class {
|
|
23591
|
-
agentName;
|
|
23592
|
-
agentVersion;
|
|
23593
|
-
configOptions;
|
|
23594
|
-
constructor(agentName, agentVersion, configOptions) {
|
|
23595
|
-
this.agentName = agentName;
|
|
23596
|
-
this.agentVersion = agentVersion;
|
|
23597
|
-
this.configOptions = configOptions;
|
|
23598
|
-
}
|
|
23599
|
-
};
|
|
23600
|
-
|
|
23601
|
-
// src/acp/activity.ts
|
|
23602
|
-
var AcpActivityNarration = class {
|
|
23603
|
-
activityId;
|
|
23604
|
-
activityType;
|
|
23605
|
-
sequence;
|
|
23606
|
-
text;
|
|
23607
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
23608
|
-
this.activityId = activityId;
|
|
23609
|
-
this.activityType = activityType;
|
|
23610
|
-
this.sequence = sequence;
|
|
23611
|
-
this.text = text2;
|
|
23612
|
-
}
|
|
23613
|
-
};
|
|
23614
|
-
var AcpActivity = class _AcpActivity {
|
|
23615
|
-
activityId;
|
|
23616
|
-
activityType;
|
|
23617
|
-
input;
|
|
23618
|
-
locations;
|
|
23619
|
-
name;
|
|
23620
|
-
output;
|
|
23621
|
-
sequence;
|
|
23622
|
-
status;
|
|
23623
|
-
title;
|
|
23624
|
-
toolKind;
|
|
23625
|
-
content;
|
|
23626
|
-
detail;
|
|
23627
|
-
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
23628
|
-
this.activityId = activityId;
|
|
23629
|
-
this.activityType = activityType;
|
|
23630
|
-
this.input = input2;
|
|
23631
|
-
this.locations = locations;
|
|
23632
|
-
this.name = name;
|
|
23633
|
-
this.output = output2;
|
|
23634
|
-
this.sequence = sequence;
|
|
23635
|
-
this.status = status;
|
|
23636
|
-
this.title = title2;
|
|
23637
|
-
this.toolKind = toolKind;
|
|
23638
|
-
this.content = content;
|
|
23639
|
-
this.detail = detail;
|
|
23640
|
-
}
|
|
23641
|
-
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
23642
|
-
this.activityId,
|
|
23643
|
-
this.activityType,
|
|
23644
|
-
this.input,
|
|
23645
|
-
this.locations,
|
|
23646
|
-
this.name,
|
|
23647
|
-
this.output,
|
|
23648
|
-
this.sequence,
|
|
23649
|
-
"completed",
|
|
23650
|
-
this.title,
|
|
23651
|
-
this.toolKind,
|
|
23652
|
-
this.content,
|
|
23653
|
-
this.detail
|
|
23654
|
-
) : this;
|
|
23655
|
-
};
|
|
23656
|
-
var ActivityIdentity = class {
|
|
23657
|
-
id;
|
|
23658
|
-
sequence;
|
|
23659
|
-
constructor(id, sequence) {
|
|
23660
|
-
this.id = id;
|
|
23661
|
-
this.sequence = sequence;
|
|
23662
|
-
}
|
|
23663
|
-
};
|
|
23664
|
-
var AcpActivityTracker = class {
|
|
23665
|
-
#activities = /* @__PURE__ */ new Map();
|
|
23666
|
-
#identities = /* @__PURE__ */ new Map();
|
|
23667
|
-
#narrations = /* @__PURE__ */ new Map();
|
|
23668
|
-
#onActivity;
|
|
23669
|
-
#onNarration;
|
|
23670
|
-
#prepareContent;
|
|
23671
|
-
#activeNarrativeKey = "";
|
|
23672
|
-
#nextSequence = 0;
|
|
23673
|
-
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
23674
|
-
this.#onActivity = onActivity;
|
|
23675
|
-
this.#onNarration = onNarration;
|
|
23676
|
-
this.#prepareContent = prepareContent;
|
|
23677
|
-
}
|
|
23678
|
-
recordNarrative = async (activityType, messageId, text2) => {
|
|
23679
|
-
const key = `${activityType}:${messageId}`;
|
|
23680
|
-
if (this.#activeNarrativeKey !== key) {
|
|
23681
|
-
await this.finishNarrative();
|
|
23682
|
-
}
|
|
23683
|
-
const identity2 = this.#identity(key);
|
|
23684
|
-
const previous = this.#narrations.get(key);
|
|
23685
|
-
const previousOutput = previous?.output ?? "";
|
|
23686
|
-
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
23687
|
-
this.#narrations.set(key, {
|
|
23688
|
-
activityId: identity2.id,
|
|
23689
|
-
activityType,
|
|
23690
|
-
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
23691
|
-
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
23692
|
-
sequence: identity2.sequence,
|
|
23693
|
-
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
23694
|
-
});
|
|
23695
|
-
if (previous === void 0) {
|
|
23696
|
-
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
23697
|
-
}
|
|
23698
|
-
this.#activeNarrativeKey = key;
|
|
23699
|
-
if (text2.length > 0) {
|
|
23700
|
-
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
23375
|
+
this.#activeNarrativeKey = key;
|
|
23376
|
+
if (text2.length > 0) {
|
|
23377
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
23701
23378
|
}
|
|
23702
23379
|
};
|
|
23703
23380
|
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
@@ -23884,33 +23561,409 @@ var AcpActivityTracker = class {
|
|
|
23884
23561
|
if (existing !== void 0) {
|
|
23885
23562
|
return existing;
|
|
23886
23563
|
}
|
|
23887
|
-
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
23888
|
-
this.#nextSequence += 1;
|
|
23889
|
-
this.#identities.set(key, identity2);
|
|
23890
|
-
return identity2;
|
|
23891
|
-
};
|
|
23892
|
-
#record = async (key, activity2) => {
|
|
23893
|
-
this.#activities.set(key, activity2);
|
|
23894
|
-
await this.#onActivity(activity2);
|
|
23895
|
-
};
|
|
23896
|
-
#recordPlanEntries = async (key, entries) => {
|
|
23897
|
-
const identity2 = this.#identity(key);
|
|
23898
|
-
await this.#record(
|
|
23899
|
-
key,
|
|
23900
|
-
new AcpActivity(
|
|
23901
|
-
identity2.id,
|
|
23902
|
-
"plan",
|
|
23903
|
-
"",
|
|
23904
|
-
[],
|
|
23905
|
-
"",
|
|
23906
|
-
formatPlanEntries(entries),
|
|
23907
|
-
identity2.sequence,
|
|
23908
|
-
planStatus(entries),
|
|
23909
|
-
"Plan",
|
|
23910
|
-
""
|
|
23911
|
-
)
|
|
23564
|
+
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
23565
|
+
this.#nextSequence += 1;
|
|
23566
|
+
this.#identities.set(key, identity2);
|
|
23567
|
+
return identity2;
|
|
23568
|
+
};
|
|
23569
|
+
#record = async (key, activity2) => {
|
|
23570
|
+
this.#activities.set(key, activity2);
|
|
23571
|
+
await this.#onActivity(activity2);
|
|
23572
|
+
};
|
|
23573
|
+
#recordPlanEntries = async (key, entries) => {
|
|
23574
|
+
const identity2 = this.#identity(key);
|
|
23575
|
+
await this.#record(
|
|
23576
|
+
key,
|
|
23577
|
+
new AcpActivity(
|
|
23578
|
+
identity2.id,
|
|
23579
|
+
"plan",
|
|
23580
|
+
"",
|
|
23581
|
+
[],
|
|
23582
|
+
"",
|
|
23583
|
+
formatPlanEntries(entries),
|
|
23584
|
+
identity2.sequence,
|
|
23585
|
+
planStatus(entries),
|
|
23586
|
+
"Plan",
|
|
23587
|
+
""
|
|
23588
|
+
)
|
|
23589
|
+
);
|
|
23590
|
+
};
|
|
23591
|
+
};
|
|
23592
|
+
|
|
23593
|
+
// src/acp/agent-turn.ts
|
|
23594
|
+
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
23595
|
+
var AcpTurnState = class {
|
|
23596
|
+
#bufferedText = [];
|
|
23597
|
+
bufferText = (text2, messageId) => {
|
|
23598
|
+
const previous = this.#bufferedText.at(-1);
|
|
23599
|
+
if (previous?.messageId === messageId) {
|
|
23600
|
+
previous.chunks.push(text2);
|
|
23601
|
+
} else {
|
|
23602
|
+
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
23603
|
+
}
|
|
23604
|
+
};
|
|
23605
|
+
flushText = async () => {
|
|
23606
|
+
const buffered = this.#bufferedText;
|
|
23607
|
+
this.#bufferedText = [];
|
|
23608
|
+
for (const message of buffered) {
|
|
23609
|
+
for (const chunk of message.chunks) {
|
|
23610
|
+
await this.onText(chunk, message.messageId);
|
|
23611
|
+
}
|
|
23612
|
+
}
|
|
23613
|
+
};
|
|
23614
|
+
recordTextAsProgress = async () => {
|
|
23615
|
+
const buffered = this.#bufferedText;
|
|
23616
|
+
this.#bufferedText = [];
|
|
23617
|
+
for (const message of buffered) {
|
|
23618
|
+
for (const chunk of message.chunks) {
|
|
23619
|
+
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
23620
|
+
}
|
|
23621
|
+
}
|
|
23622
|
+
};
|
|
23623
|
+
};
|
|
23624
|
+
var IdleAcpTurn = class extends AcpTurnState {
|
|
23625
|
+
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
23626
|
+
running = false;
|
|
23627
|
+
activities = new AcpActivityTracker(
|
|
23628
|
+
() => Promise.resolve(),
|
|
23629
|
+
() => Promise.resolve()
|
|
23630
|
+
);
|
|
23631
|
+
onText = () => Promise.resolve();
|
|
23632
|
+
};
|
|
23633
|
+
var RunningAcpTurn = class extends AcpTurnState {
|
|
23634
|
+
commandId;
|
|
23635
|
+
running = true;
|
|
23636
|
+
activities;
|
|
23637
|
+
onText;
|
|
23638
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
23639
|
+
super();
|
|
23640
|
+
this.commandId = commandId;
|
|
23641
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
23642
|
+
this.onText = onText;
|
|
23643
|
+
}
|
|
23644
|
+
};
|
|
23645
|
+
|
|
23646
|
+
// src/acp/native-session.ts
|
|
23647
|
+
var path = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
23648
|
+
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
23649
|
+
var nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
23650
|
+
var nativeSessionInfoSchema = external_exports.object({
|
|
23651
|
+
sessionId: nativeSessionIdSchema,
|
|
23652
|
+
cwd: path,
|
|
23653
|
+
additionalDirectories: external_exports.array(path).max(16).default([]).readonly(),
|
|
23654
|
+
title: title.nullish(),
|
|
23655
|
+
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
23656
|
+
}).readonly();
|
|
23657
|
+
var nativeSessionPageSchema = external_exports.object({
|
|
23658
|
+
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
23659
|
+
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
23660
|
+
}).readonly();
|
|
23661
|
+
|
|
23662
|
+
// src/acp/agent-update-stream.ts
|
|
23663
|
+
var MAX_PENDING_UPDATES = 100;
|
|
23664
|
+
var MAX_PENDING_BYTES = 1024 * 1024;
|
|
23665
|
+
var AgentUpdateStream = class {
|
|
23666
|
+
#selection = { kind: "awaiting-session", notifications: [], bytes: 0 };
|
|
23667
|
+
#tail = Promise.resolve();
|
|
23668
|
+
#consume;
|
|
23669
|
+
constructor(consume) {
|
|
23670
|
+
this.#consume = consume;
|
|
23671
|
+
}
|
|
23672
|
+
sessionId = () => this.#selection.kind === "selected" ? this.#selection.sessionId : "";
|
|
23673
|
+
drained = () => this.#tail;
|
|
23674
|
+
#enqueue = (notification) => {
|
|
23675
|
+
this.#tail = this.#tail.then(async () => await this.#consume(notification));
|
|
23676
|
+
return this.#tail;
|
|
23677
|
+
};
|
|
23678
|
+
receive = (notification) => {
|
|
23679
|
+
const selection = this.#selection;
|
|
23680
|
+
switch (selection.kind) {
|
|
23681
|
+
case "selected":
|
|
23682
|
+
return this.#enqueue(notification);
|
|
23683
|
+
case "awaiting-session": {
|
|
23684
|
+
const bytes = selection.bytes + Buffer.byteLength(JSON.stringify(notification));
|
|
23685
|
+
if (selection.notifications.length >= MAX_PENDING_UPDATES || bytes > MAX_PENDING_BYTES) {
|
|
23686
|
+
return Promise.reject(
|
|
23687
|
+
new AcpExecutionError(
|
|
23688
|
+
"ACP agent sent too many updates before creating its session",
|
|
23689
|
+
{},
|
|
23690
|
+
"agent_update_limit"
|
|
23691
|
+
)
|
|
23692
|
+
);
|
|
23693
|
+
}
|
|
23694
|
+
this.#selection = {
|
|
23695
|
+
kind: "awaiting-session",
|
|
23696
|
+
notifications: [...selection.notifications, notification],
|
|
23697
|
+
bytes
|
|
23698
|
+
};
|
|
23699
|
+
return Promise.resolve();
|
|
23700
|
+
}
|
|
23701
|
+
}
|
|
23702
|
+
};
|
|
23703
|
+
select = (sessionId) => {
|
|
23704
|
+
const selected = nativeSessionIdSchema.parse(sessionId);
|
|
23705
|
+
const selection = this.#selection;
|
|
23706
|
+
switch (selection.kind) {
|
|
23707
|
+
case "selected":
|
|
23708
|
+
if (selection.sessionId !== selected) {
|
|
23709
|
+
throw new AcpExecutionError(
|
|
23710
|
+
"ACP agent attempted to replace the selected session",
|
|
23711
|
+
{},
|
|
23712
|
+
"invalid_agent_session"
|
|
23713
|
+
);
|
|
23714
|
+
}
|
|
23715
|
+
return;
|
|
23716
|
+
case "awaiting-session":
|
|
23717
|
+
this.#selection = { kind: "selected", sessionId: selected };
|
|
23718
|
+
for (const notification of selection.notifications) {
|
|
23719
|
+
void this.#enqueue(notification);
|
|
23720
|
+
}
|
|
23721
|
+
return;
|
|
23722
|
+
}
|
|
23723
|
+
};
|
|
23724
|
+
};
|
|
23725
|
+
|
|
23726
|
+
// src/acp/session-config/session-config-protocol.ts
|
|
23727
|
+
import { methods as methods2 } from "@agentclientprotocol/sdk";
|
|
23728
|
+
var MAXIMUM_CONFIG_OPTIONS = 100;
|
|
23729
|
+
var SessionConfigProtocolError = class extends Error {
|
|
23730
|
+
code = "invalid_session_configuration_response";
|
|
23731
|
+
constructor(message, options = {}) {
|
|
23732
|
+
super(message, options);
|
|
23733
|
+
this.name = "SessionConfigProtocolError";
|
|
23734
|
+
}
|
|
23735
|
+
};
|
|
23736
|
+
function isRecord5(value) {
|
|
23737
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23738
|
+
}
|
|
23739
|
+
function readString3(value, fallback = "") {
|
|
23740
|
+
return typeof value === "string" ? value : fallback;
|
|
23741
|
+
}
|
|
23742
|
+
function truncate3(value, maximum) {
|
|
23743
|
+
return value.length <= maximum ? value : value.slice(0, maximum);
|
|
23744
|
+
}
|
|
23745
|
+
function readBoolean(value, fallback = false) {
|
|
23746
|
+
return typeof value === "boolean" ? value : fallback;
|
|
23747
|
+
}
|
|
23748
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
23749
|
+
const value = option["value"];
|
|
23750
|
+
if (typeof value !== "string") {
|
|
23751
|
+
return void 0;
|
|
23752
|
+
}
|
|
23753
|
+
return {
|
|
23754
|
+
description: truncate3(readString3(option["description"]), 500),
|
|
23755
|
+
groupId: truncate3(groupId, 128),
|
|
23756
|
+
groupName: truncate3(groupName, 255),
|
|
23757
|
+
name: truncate3(readString3(option["name"], value), 255),
|
|
23758
|
+
value: truncate3(value, 500)
|
|
23759
|
+
};
|
|
23760
|
+
}
|
|
23761
|
+
function normalizeConfigValues(value) {
|
|
23762
|
+
if (!Array.isArray(value)) {
|
|
23763
|
+
return [];
|
|
23764
|
+
}
|
|
23765
|
+
const normalized = [];
|
|
23766
|
+
for (const entry of value) {
|
|
23767
|
+
if (!isRecord5(entry)) {
|
|
23768
|
+
continue;
|
|
23769
|
+
}
|
|
23770
|
+
const groupedOptions = entry["options"];
|
|
23771
|
+
if (Array.isArray(groupedOptions)) {
|
|
23772
|
+
const groupId = readString3(entry["group"]);
|
|
23773
|
+
const groupName = readString3(entry["name"]);
|
|
23774
|
+
for (const groupedOption of groupedOptions) {
|
|
23775
|
+
if (isRecord5(groupedOption)) {
|
|
23776
|
+
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
23777
|
+
if (normalizedValue !== void 0) {
|
|
23778
|
+
normalized.push(normalizedValue);
|
|
23779
|
+
}
|
|
23780
|
+
}
|
|
23781
|
+
}
|
|
23782
|
+
continue;
|
|
23783
|
+
}
|
|
23784
|
+
const normalizedEntry = normalizeConfigValue(entry);
|
|
23785
|
+
if (normalizedEntry !== void 0) {
|
|
23786
|
+
normalized.push(normalizedEntry);
|
|
23787
|
+
}
|
|
23788
|
+
}
|
|
23789
|
+
return normalized.slice(0, 500);
|
|
23790
|
+
}
|
|
23791
|
+
function normalizeConfigOptions(value, modes) {
|
|
23792
|
+
const normalized = [];
|
|
23793
|
+
if (Array.isArray(value)) {
|
|
23794
|
+
for (const option of value) {
|
|
23795
|
+
if (!isRecord5(option)) {
|
|
23796
|
+
continue;
|
|
23797
|
+
}
|
|
23798
|
+
const id = truncate3(readString3(option["id"]), 128);
|
|
23799
|
+
const name = truncate3(readString3(option["name"], id), 255);
|
|
23800
|
+
const category = truncate3(readString3(option["category"]), 128);
|
|
23801
|
+
if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
|
|
23802
|
+
continue;
|
|
23803
|
+
}
|
|
23804
|
+
if (option["type"] === "boolean") {
|
|
23805
|
+
normalized.push({
|
|
23806
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
23807
|
+
category,
|
|
23808
|
+
currentValue: "",
|
|
23809
|
+
description: truncate3(readString3(option["description"]), 500),
|
|
23810
|
+
id,
|
|
23811
|
+
name,
|
|
23812
|
+
type: "boolean",
|
|
23813
|
+
values: []
|
|
23814
|
+
});
|
|
23815
|
+
continue;
|
|
23816
|
+
}
|
|
23817
|
+
if (option["type"] === "select") {
|
|
23818
|
+
const values = normalizeConfigValues(option["options"]);
|
|
23819
|
+
const currentValue = truncate3(readString3(option["currentValue"]), 500);
|
|
23820
|
+
if (values.some((entry) => entry.value === currentValue)) {
|
|
23821
|
+
normalized.push({
|
|
23822
|
+
booleanValue: false,
|
|
23823
|
+
category,
|
|
23824
|
+
currentValue,
|
|
23825
|
+
description: truncate3(readString3(option["description"]), 500),
|
|
23826
|
+
id,
|
|
23827
|
+
name,
|
|
23828
|
+
type: "select",
|
|
23829
|
+
values
|
|
23830
|
+
});
|
|
23831
|
+
}
|
|
23832
|
+
}
|
|
23833
|
+
}
|
|
23834
|
+
}
|
|
23835
|
+
if (isRecord5(modes)) {
|
|
23836
|
+
const values = [];
|
|
23837
|
+
const availableModes = modes["availableModes"];
|
|
23838
|
+
if (Array.isArray(availableModes)) {
|
|
23839
|
+
for (const mode of availableModes) {
|
|
23840
|
+
if (!isRecord5(mode)) {
|
|
23841
|
+
continue;
|
|
23842
|
+
}
|
|
23843
|
+
const id = truncate3(readString3(mode["id"]), 500);
|
|
23844
|
+
if (id.length === 0) {
|
|
23845
|
+
continue;
|
|
23846
|
+
}
|
|
23847
|
+
values.push({
|
|
23848
|
+
description: truncate3(readString3(mode["description"]), 500),
|
|
23849
|
+
groupId: "",
|
|
23850
|
+
groupName: "",
|
|
23851
|
+
name: truncate3(readString3(mode["name"], id), 255),
|
|
23852
|
+
value: id
|
|
23853
|
+
});
|
|
23854
|
+
}
|
|
23855
|
+
}
|
|
23856
|
+
const currentValue = truncate3(readString3(modes["currentModeId"]), 500);
|
|
23857
|
+
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode")) {
|
|
23858
|
+
normalized.unshift({
|
|
23859
|
+
booleanValue: false,
|
|
23860
|
+
category: "mode",
|
|
23861
|
+
currentValue,
|
|
23862
|
+
description: "Agent session mode",
|
|
23863
|
+
id: "mode",
|
|
23864
|
+
name: "Mode",
|
|
23865
|
+
type: "select",
|
|
23866
|
+
values
|
|
23867
|
+
});
|
|
23868
|
+
}
|
|
23869
|
+
}
|
|
23870
|
+
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
23871
|
+
}
|
|
23872
|
+
function normalizeStandardLifecycle(response) {
|
|
23873
|
+
const lifecycle = isRecord5(response) ? response : {};
|
|
23874
|
+
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
23875
|
+
}
|
|
23876
|
+
function replaceStandardConfigOptions(current, value) {
|
|
23877
|
+
const next = normalizeConfigOptions(value, void 0);
|
|
23878
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
23879
|
+
return withMode;
|
|
23880
|
+
}
|
|
23881
|
+
function updateCurrentValue(current, configId, value) {
|
|
23882
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
23883
|
+
}
|
|
23884
|
+
var StandardSessionConfigProtocol = class {
|
|
23885
|
+
configure = async (current, change, nativeSessionId, transport) => {
|
|
23886
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
23887
|
+
if (existing === void 0) {
|
|
23888
|
+
return current;
|
|
23889
|
+
}
|
|
23890
|
+
if (existing.type === "select" && existing.category === "mode") {
|
|
23891
|
+
await transport.request(
|
|
23892
|
+
methods2.agent.session.setMode,
|
|
23893
|
+
{ modeId: change.value, sessionId: nativeSessionId },
|
|
23894
|
+
"ACP agent exited while setting the session mode",
|
|
23895
|
+
change.signal
|
|
23896
|
+
);
|
|
23897
|
+
return updateCurrentValue(current, existing.id, change.value);
|
|
23898
|
+
}
|
|
23899
|
+
const params = existing.type === "boolean" ? {
|
|
23900
|
+
configId: existing.id,
|
|
23901
|
+
sessionId: nativeSessionId,
|
|
23902
|
+
type: "boolean",
|
|
23903
|
+
value: change.booleanValue
|
|
23904
|
+
} : {
|
|
23905
|
+
configId: existing.id,
|
|
23906
|
+
sessionId: nativeSessionId,
|
|
23907
|
+
value: change.value
|
|
23908
|
+
};
|
|
23909
|
+
const response = await transport.request(
|
|
23910
|
+
methods2.agent.session.setConfigOption,
|
|
23911
|
+
params,
|
|
23912
|
+
"ACP agent exited while changing session configuration",
|
|
23913
|
+
change.signal
|
|
23912
23914
|
);
|
|
23915
|
+
if (!isRecord5(response) || !Array.isArray(response["configOptions"])) {
|
|
23916
|
+
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
23917
|
+
}
|
|
23918
|
+
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
23913
23919
|
};
|
|
23920
|
+
normalizeLifecycle = (response) => normalizeStandardLifecycle(response);
|
|
23921
|
+
normalizeUpdate = (current, value) => replaceStandardConfigOptions(current, value);
|
|
23922
|
+
};
|
|
23923
|
+
var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
23924
|
+
|
|
23925
|
+
// src/acp/session-config/session-config-registry.ts
|
|
23926
|
+
function sessionConfigProtocolForAgent(_agentId) {
|
|
23927
|
+
return standardSessionConfigProtocol;
|
|
23928
|
+
}
|
|
23929
|
+
|
|
23930
|
+
// src/acp/session-contracts.ts
|
|
23931
|
+
var NullAcpSessionObserver = class {
|
|
23932
|
+
onCommands = () => Promise.resolve();
|
|
23933
|
+
onConfig = () => Promise.resolve();
|
|
23934
|
+
onContent = () => Promise.resolve();
|
|
23935
|
+
onElicitation = () => Promise.resolve();
|
|
23936
|
+
onElicitationResolved = () => Promise.resolve();
|
|
23937
|
+
onInfo = () => Promise.resolve();
|
|
23938
|
+
onPermission = () => Promise.resolve();
|
|
23939
|
+
onPermissionResolved = () => Promise.resolve();
|
|
23940
|
+
onUsage = () => Promise.resolve();
|
|
23941
|
+
};
|
|
23942
|
+
var AcpPreparedSession = class {
|
|
23943
|
+
agentName;
|
|
23944
|
+
agentVersion;
|
|
23945
|
+
capabilities;
|
|
23946
|
+
commands;
|
|
23947
|
+
configOptions;
|
|
23948
|
+
restored;
|
|
23949
|
+
constructor(agentName, agentVersion, capabilities, commands, configOptions, restored) {
|
|
23950
|
+
this.agentName = agentName;
|
|
23951
|
+
this.agentVersion = agentVersion;
|
|
23952
|
+
this.capabilities = capabilities;
|
|
23953
|
+
this.commands = commands;
|
|
23954
|
+
this.configOptions = configOptions;
|
|
23955
|
+
this.restored = restored;
|
|
23956
|
+
}
|
|
23957
|
+
};
|
|
23958
|
+
var AcpAgentSettingsSnapshot = class {
|
|
23959
|
+
agentName;
|
|
23960
|
+
agentVersion;
|
|
23961
|
+
configOptions;
|
|
23962
|
+
constructor(agentName, agentVersion, configOptions) {
|
|
23963
|
+
this.agentName = agentName;
|
|
23964
|
+
this.agentVersion = agentVersion;
|
|
23965
|
+
this.configOptions = configOptions;
|
|
23966
|
+
}
|
|
23914
23967
|
};
|
|
23915
23968
|
|
|
23916
23969
|
// src/acp/session-history.ts
|
|
@@ -24345,31 +24398,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
24345
24398
|
return validated;
|
|
24346
24399
|
}
|
|
24347
24400
|
|
|
24348
|
-
// src/acp/
|
|
24349
|
-
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
24350
|
-
var AcpTurnState = class {
|
|
24351
|
-
};
|
|
24352
|
-
var IdleAcpTurn = class extends AcpTurnState {
|
|
24353
|
-
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
24354
|
-
running = false;
|
|
24355
|
-
activities = new AcpActivityTracker(
|
|
24356
|
-
() => Promise.resolve(),
|
|
24357
|
-
() => Promise.resolve()
|
|
24358
|
-
);
|
|
24359
|
-
onText = () => Promise.resolve();
|
|
24360
|
-
};
|
|
24361
|
-
var RunningAcpTurn = class extends AcpTurnState {
|
|
24362
|
-
commandId;
|
|
24363
|
-
running = true;
|
|
24364
|
-
activities;
|
|
24365
|
-
onText;
|
|
24366
|
-
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
24367
|
-
super();
|
|
24368
|
-
this.commandId = commandId;
|
|
24369
|
-
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
24370
|
-
this.onText = onText;
|
|
24371
|
-
}
|
|
24372
|
-
};
|
|
24401
|
+
// src/acp/pending-interactions.ts
|
|
24373
24402
|
var PendingPermission = class {
|
|
24374
24403
|
completion = Promise.withResolvers();
|
|
24375
24404
|
interactionId;
|
|
@@ -30320,7 +30349,6 @@ var AgentSession = class _AgentSession {
|
|
|
30320
30349
|
#verifiedAgentVersion;
|
|
30321
30350
|
#agentName = "";
|
|
30322
30351
|
#agentVersion = "";
|
|
30323
|
-
#bufferedAgentText = [];
|
|
30324
30352
|
#capabilities = unsupportedSessionCapabilities();
|
|
30325
30353
|
#commands = [];
|
|
30326
30354
|
#configRevision = 0;
|
|
@@ -30466,35 +30494,6 @@ var AgentSession = class _AgentSession {
|
|
|
30466
30494
|
this.#replay = { kind: "idle" };
|
|
30467
30495
|
}
|
|
30468
30496
|
};
|
|
30469
|
-
emitAgentMessage = async (chunks, messageId) => {
|
|
30470
|
-
for (const chunk of chunks) {
|
|
30471
|
-
await this.#turn.onText(chunk, messageId);
|
|
30472
|
-
}
|
|
30473
|
-
};
|
|
30474
|
-
bufferAgentText = async (text2, messageId) => {
|
|
30475
|
-
const previous = this.#bufferedAgentText.at(-1);
|
|
30476
|
-
if (previous?.messageId === messageId) {
|
|
30477
|
-
previous.chunks.push(text2);
|
|
30478
|
-
return;
|
|
30479
|
-
}
|
|
30480
|
-
this.#bufferedAgentText.push({ chunks: [text2], messageId });
|
|
30481
|
-
};
|
|
30482
|
-
flushAgentText = async () => {
|
|
30483
|
-
const buffered = this.#bufferedAgentText;
|
|
30484
|
-
this.#bufferedAgentText = [];
|
|
30485
|
-
for (const message of buffered) {
|
|
30486
|
-
await this.emitAgentMessage(message.chunks, message.messageId);
|
|
30487
|
-
}
|
|
30488
|
-
};
|
|
30489
|
-
recordBufferedAgentTextAsProgress = async () => {
|
|
30490
|
-
const buffered = this.#bufferedAgentText;
|
|
30491
|
-
this.#bufferedAgentText = [];
|
|
30492
|
-
for (const message of buffered) {
|
|
30493
|
-
for (const chunk of message.chunks) {
|
|
30494
|
-
await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
|
|
30495
|
-
}
|
|
30496
|
-
}
|
|
30497
|
-
};
|
|
30498
30497
|
prepareAgentContent = async (content) => {
|
|
30499
30498
|
if (content.type === "image" && content.uri.length > 0) {
|
|
30500
30499
|
const signal = AbortSignal.timeout(2e4);
|
|
@@ -30992,7 +30991,7 @@ var AgentSession = class _AgentSession {
|
|
|
30992
30991
|
options.signal
|
|
30993
30992
|
);
|
|
30994
30993
|
await this.#updates.drained();
|
|
30995
|
-
await this.
|
|
30994
|
+
await this.#turn.flushText();
|
|
30996
30995
|
await running.activities.finish();
|
|
30997
30996
|
let result;
|
|
30998
30997
|
try {
|
|
@@ -31024,7 +31023,6 @@ var AgentSession = class _AgentSession {
|
|
|
31024
31023
|
cause: error62
|
|
31025
31024
|
});
|
|
31026
31025
|
} finally {
|
|
31027
|
-
this.#bufferedAgentText = [];
|
|
31028
31026
|
this.#turn = new IdleAcpTurn();
|
|
31029
31027
|
}
|
|
31030
31028
|
};
|
|
@@ -31115,11 +31113,11 @@ var AgentSession = class _AgentSession {
|
|
|
31115
31113
|
);
|
|
31116
31114
|
} else {
|
|
31117
31115
|
await this.#turn.activities.finishNarrative();
|
|
31118
|
-
|
|
31116
|
+
this.#turn.bufferText(update.content.text, truncate2(update.messageId ?? "", 255));
|
|
31119
31117
|
}
|
|
31120
31118
|
} else {
|
|
31121
31119
|
await this.#turn.activities.finishNarrative();
|
|
31122
|
-
await this.
|
|
31120
|
+
await this.#turn.flushText();
|
|
31123
31121
|
await this.emitAgentContent(
|
|
31124
31122
|
normalizeContentBlock(update.content),
|
|
31125
31123
|
truncate2(update.messageId ?? "", 255)
|
|
@@ -31138,7 +31136,7 @@ var AgentSession = class _AgentSession {
|
|
|
31138
31136
|
return;
|
|
31139
31137
|
}
|
|
31140
31138
|
if (update.sessionUpdate === "tool_call") {
|
|
31141
|
-
await this.
|
|
31139
|
+
await this.#turn.recordTextAsProgress();
|
|
31142
31140
|
await this.#turn.activities.recordToolCall(update);
|
|
31143
31141
|
return;
|
|
31144
31142
|
}
|
|
@@ -33508,11 +33506,8 @@ function agentMessageMeta(phase) {
|
|
|
33508
33506
|
return { [CODEX_META_KEY]: { phase } };
|
|
33509
33507
|
}
|
|
33510
33508
|
|
|
33511
|
-
// src/acp/codex/
|
|
33512
|
-
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
33509
|
+
// src/acp/codex/settings.ts
|
|
33513
33510
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
33514
|
-
var CODEX_AGENT_VERSION = "0.154.0";
|
|
33515
|
-
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
33516
33511
|
var MODEL_SETTING_ID = "model";
|
|
33517
33512
|
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
33518
33513
|
var MODE_SETTING_ID = "mode";
|
|
@@ -33521,7 +33516,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
|
|
|
33521
33516
|
var MODEL_CATALOG_LIMIT = 1e3;
|
|
33522
33517
|
var FAST_TIER = "fast";
|
|
33523
33518
|
var SERVICE_TIER_FAST = "priority";
|
|
33524
|
-
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
33525
33519
|
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
33526
33520
|
excludeSlashTmp: false,
|
|
33527
33521
|
excludeTmpdirEnvVar: false,
|
|
@@ -33550,108 +33544,20 @@ var FULL_ACCESS_MODE = Object.freeze({
|
|
|
33550
33544
|
approvalsReviewer: "user",
|
|
33551
33545
|
description: "Unrestricted access to the internet and any file on your computer",
|
|
33552
33546
|
id: "agent-full-access",
|
|
33553
|
-
name: "Full access",
|
|
33554
|
-
sandboxPolicy: { type: "dangerFullAccess" }
|
|
33555
|
-
});
|
|
33556
|
-
var AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
|
|
33557
|
-
var DEFAULT_MODE = AGENT_MODE;
|
|
33558
|
-
function initialMode(environment) {
|
|
33559
|
-
const requested = environment["INITIAL_AGENT_MODE"];
|
|
33560
|
-
if (requested === void 0) {
|
|
33561
|
-
return DEFAULT_MODE.id;
|
|
33562
|
-
}
|
|
33563
|
-
return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
|
|
33564
|
-
}
|
|
33565
|
-
function capitalize(value) {
|
|
33566
|
-
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
33567
|
-
}
|
|
33568
|
-
var APPROVAL_OPTIONS = Object.freeze([
|
|
33569
|
-
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
33570
|
-
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
33571
|
-
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
33572
|
-
]);
|
|
33573
|
-
function permissionDecision(optionId) {
|
|
33574
|
-
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
33575
|
-
return optionId;
|
|
33576
|
-
}
|
|
33577
|
-
return "cancel";
|
|
33578
|
-
}
|
|
33579
|
-
function promptInput(prompt) {
|
|
33580
|
-
const input2 = [];
|
|
33581
|
-
for (const block of prompt) {
|
|
33582
|
-
if (block.type === "text") {
|
|
33583
|
-
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
33584
|
-
continue;
|
|
33585
|
-
}
|
|
33586
|
-
if (block.type === "image") {
|
|
33587
|
-
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
33588
|
-
continue;
|
|
33589
|
-
}
|
|
33590
|
-
if (block.type === "resource") {
|
|
33591
|
-
const resource = block.resource;
|
|
33592
|
-
input2.push({
|
|
33593
|
-
text: "text" in resource ? resource.text ?? "" : "",
|
|
33594
|
-
text_elements: [],
|
|
33595
|
-
type: "text"
|
|
33596
|
-
});
|
|
33597
|
-
continue;
|
|
33598
|
-
}
|
|
33599
|
-
if (block.type === "resource_link") {
|
|
33600
|
-
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
33601
|
-
}
|
|
33602
|
-
}
|
|
33603
|
-
return input2;
|
|
33604
|
-
}
|
|
33605
|
-
function isCompactPrompt(prompt) {
|
|
33606
|
-
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
33607
|
-
}
|
|
33608
|
-
function steeringPromptInput(prompt) {
|
|
33609
|
-
const input2 = [];
|
|
33610
|
-
for (const block of prompt) {
|
|
33611
|
-
if (typeof block !== "object" || block === null) {
|
|
33612
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33613
|
-
}
|
|
33614
|
-
const type = Reflect.get(block, "type");
|
|
33615
|
-
if (type === "text") {
|
|
33616
|
-
const text2 = Reflect.get(block, "text");
|
|
33617
|
-
if (typeof text2 !== "string") {
|
|
33618
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33619
|
-
}
|
|
33620
|
-
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
33621
|
-
continue;
|
|
33622
|
-
}
|
|
33623
|
-
if (type === "image") {
|
|
33624
|
-
const data = Reflect.get(block, "data");
|
|
33625
|
-
const mimeType = Reflect.get(block, "mimeType");
|
|
33626
|
-
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
33627
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33628
|
-
}
|
|
33629
|
-
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
33630
|
-
continue;
|
|
33631
|
-
}
|
|
33632
|
-
if (type === "resource") {
|
|
33633
|
-
const resource = Reflect.get(block, "resource");
|
|
33634
|
-
if (typeof resource !== "object" || resource === null) {
|
|
33635
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33636
|
-
}
|
|
33637
|
-
const text2 = Reflect.get(resource, "text");
|
|
33638
|
-
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
33639
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33640
|
-
}
|
|
33641
|
-
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
33642
|
-
continue;
|
|
33643
|
-
}
|
|
33644
|
-
if (type === "resource_link") {
|
|
33645
|
-
const uri = Reflect.get(block, "uri");
|
|
33646
|
-
if (typeof uri !== "string") {
|
|
33647
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33648
|
-
}
|
|
33649
|
-
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
33650
|
-
continue;
|
|
33651
|
-
}
|
|
33652
|
-
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
33547
|
+
name: "Full access",
|
|
33548
|
+
sandboxPolicy: { type: "dangerFullAccess" }
|
|
33549
|
+
});
|
|
33550
|
+
var AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
|
|
33551
|
+
var DEFAULT_MODE = AGENT_MODE;
|
|
33552
|
+
function initialMode(environment) {
|
|
33553
|
+
const requested = environment["INITIAL_AGENT_MODE"];
|
|
33554
|
+
if (requested === void 0) {
|
|
33555
|
+
return DEFAULT_MODE.id;
|
|
33653
33556
|
}
|
|
33654
|
-
return
|
|
33557
|
+
return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
|
|
33558
|
+
}
|
|
33559
|
+
function capitalize(value) {
|
|
33560
|
+
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
33655
33561
|
}
|
|
33656
33562
|
function modelValues(models) {
|
|
33657
33563
|
return models.map((model) => ({
|
|
@@ -33743,19 +33649,352 @@ function effortSetting(model, currentValue) {
|
|
|
33743
33649
|
if (values.length === 0) {
|
|
33744
33650
|
return null;
|
|
33745
33651
|
}
|
|
33746
|
-
const current = values.some((value) => value.value === currentValue) ? currentValue : values[0]?.value ?? "";
|
|
33747
|
-
if (current.length === 0) {
|
|
33748
|
-
return null;
|
|
33652
|
+
const current = values.some((value) => value.value === currentValue) ? currentValue : values[0]?.value ?? "";
|
|
33653
|
+
if (current.length === 0) {
|
|
33654
|
+
return null;
|
|
33655
|
+
}
|
|
33656
|
+
return {
|
|
33657
|
+
category: "thought_level",
|
|
33658
|
+
currentValue: current,
|
|
33659
|
+
description: "How much reasoning effort the model should use",
|
|
33660
|
+
id: REASONING_EFFORT_SETTING_ID,
|
|
33661
|
+
name: "Reasoning effort",
|
|
33662
|
+
options: values,
|
|
33663
|
+
type: "select"
|
|
33664
|
+
};
|
|
33665
|
+
}
|
|
33666
|
+
var CodexSettings = class {
|
|
33667
|
+
#appServer;
|
|
33668
|
+
#models = [];
|
|
33669
|
+
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
33670
|
+
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
33671
|
+
#policySelected = false;
|
|
33672
|
+
// Whether a collaboration mode choice has been made in this session. A restored thread keeps
|
|
33673
|
+
// the mode Codex already persisted, so the first turn does not reset it to Build.
|
|
33674
|
+
#collaborationModeSelected = false;
|
|
33675
|
+
// Whether the app-server accepts collaboration mode on `turn/start`, probed once per
|
|
33676
|
+
// app-server. An older Codex rejects the experimental field, and the setting must disappear
|
|
33677
|
+
// rather than break every turn.
|
|
33678
|
+
#collaborationModeSupported = null;
|
|
33679
|
+
#selection;
|
|
33680
|
+
constructor(appServer, environment) {
|
|
33681
|
+
this.#appServer = appServer;
|
|
33682
|
+
this.#selection = {
|
|
33683
|
+
collaborationMode: "default",
|
|
33684
|
+
effort: "",
|
|
33685
|
+
fastMode: false,
|
|
33686
|
+
mode: initialMode(environment),
|
|
33687
|
+
model: ""
|
|
33688
|
+
};
|
|
33689
|
+
}
|
|
33690
|
+
selectNewThread = (created) => {
|
|
33691
|
+
const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
|
|
33692
|
+
this.#selection = {
|
|
33693
|
+
...this.#selection,
|
|
33694
|
+
collaborationMode: "default",
|
|
33695
|
+
...supported
|
|
33696
|
+
};
|
|
33697
|
+
this.#collaborationModeSelected = false;
|
|
33698
|
+
};
|
|
33699
|
+
observeCollaborationMode = (mode) => {
|
|
33700
|
+
if (mode === void 0 || mode === this.#selection.collaborationMode) {
|
|
33701
|
+
return false;
|
|
33702
|
+
}
|
|
33703
|
+
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
33704
|
+
return true;
|
|
33705
|
+
};
|
|
33706
|
+
turnParameters = () => {
|
|
33707
|
+
const selection = this.#selection;
|
|
33708
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
33709
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
33710
|
+
return {
|
|
33711
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
33712
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
33713
|
+
// inherited rather than overridden.
|
|
33714
|
+
...this.#policySelected ? {
|
|
33715
|
+
approvalPolicy: mode.approvalPolicy,
|
|
33716
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
33717
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
33718
|
+
} : {},
|
|
33719
|
+
// The collaboration mode rides on the turn: Codex applies it to the
|
|
33720
|
+
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
33721
|
+
// mode, so it is only sent once a choice exists to apply.
|
|
33722
|
+
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
33723
|
+
collaborationMode: {
|
|
33724
|
+
mode: selection.collaborationMode,
|
|
33725
|
+
settings: {
|
|
33726
|
+
developer_instructions: null,
|
|
33727
|
+
model: selection.model,
|
|
33728
|
+
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
33729
|
+
}
|
|
33730
|
+
}
|
|
33731
|
+
} : {},
|
|
33732
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
33733
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
33734
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
|
|
33735
|
+
};
|
|
33736
|
+
};
|
|
33737
|
+
loadModels = async (signal) => {
|
|
33738
|
+
const models = [];
|
|
33739
|
+
let cursor = null;
|
|
33740
|
+
try {
|
|
33741
|
+
do {
|
|
33742
|
+
const decoded = modelListResponseSchema.parse(
|
|
33743
|
+
await this.#appServer.request(
|
|
33744
|
+
"model/list",
|
|
33745
|
+
{ cursor, limit: null },
|
|
33746
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
33747
|
+
)
|
|
33748
|
+
);
|
|
33749
|
+
models.push(...decoded.data);
|
|
33750
|
+
cursor = decoded.nextCursor ?? null;
|
|
33751
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
33752
|
+
} catch (error62) {
|
|
33753
|
+
signal.throwIfAborted();
|
|
33754
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
33755
|
+
`);
|
|
33756
|
+
}
|
|
33757
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
33758
|
+
};
|
|
33759
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
33760
|
+
/**
|
|
33761
|
+
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
33762
|
+
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
33763
|
+
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
33764
|
+
*/
|
|
33765
|
+
probeCollaborationMode = async (threadId, signal) => {
|
|
33766
|
+
if (this.#collaborationModeSupported !== null) {
|
|
33767
|
+
return;
|
|
33768
|
+
}
|
|
33769
|
+
try {
|
|
33770
|
+
await this.#appServer.request(
|
|
33771
|
+
"thread/settings/update",
|
|
33772
|
+
{ threadId },
|
|
33773
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
33774
|
+
);
|
|
33775
|
+
this.#collaborationModeSupported = true;
|
|
33776
|
+
} catch {
|
|
33777
|
+
signal.throwIfAborted();
|
|
33778
|
+
this.#collaborationModeSupported = false;
|
|
33779
|
+
}
|
|
33780
|
+
};
|
|
33781
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
33782
|
+
configOptions = () => {
|
|
33783
|
+
const options = [];
|
|
33784
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
33785
|
+
if (model !== null) {
|
|
33786
|
+
options.push(model);
|
|
33787
|
+
}
|
|
33788
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
33789
|
+
if (effort !== null) {
|
|
33790
|
+
options.push(effort);
|
|
33791
|
+
}
|
|
33792
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
33793
|
+
if (fastMode !== null) {
|
|
33794
|
+
options.push(fastMode);
|
|
33795
|
+
}
|
|
33796
|
+
if (this.#collaborationModeSupported === true) {
|
|
33797
|
+
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
33798
|
+
}
|
|
33799
|
+
options.push(modeSetting(this.#selection.mode));
|
|
33800
|
+
return options;
|
|
33801
|
+
};
|
|
33802
|
+
selectRestoredThread = (thread) => {
|
|
33803
|
+
const supported = supportedSelection(
|
|
33804
|
+
this.#models,
|
|
33805
|
+
thread.model ?? this.#selection.model,
|
|
33806
|
+
thread.reasoningEffort ?? this.#selection.effort
|
|
33807
|
+
);
|
|
33808
|
+
this.#selection = {
|
|
33809
|
+
...this.#selection,
|
|
33810
|
+
...supported,
|
|
33811
|
+
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
33812
|
+
};
|
|
33813
|
+
};
|
|
33814
|
+
/**
|
|
33815
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
33816
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
33817
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
33818
|
+
*/
|
|
33819
|
+
applySelection = (configId, value) => {
|
|
33820
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
33821
|
+
if (typeof value !== "boolean") {
|
|
33822
|
+
throw new AcpExecutionError(
|
|
33823
|
+
"The requested Codex setting is invalid",
|
|
33824
|
+
{},
|
|
33825
|
+
"invalid_session_configuration"
|
|
33826
|
+
);
|
|
33827
|
+
}
|
|
33828
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
33829
|
+
throw new AcpExecutionError(
|
|
33830
|
+
"The selected Codex model has no fast mode",
|
|
33831
|
+
{},
|
|
33832
|
+
"invalid_session_configuration"
|
|
33833
|
+
);
|
|
33834
|
+
}
|
|
33835
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
33836
|
+
return;
|
|
33837
|
+
}
|
|
33838
|
+
if (typeof value !== "string") {
|
|
33839
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
33840
|
+
}
|
|
33841
|
+
if (configId === MODE_SETTING_ID) {
|
|
33842
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
33843
|
+
throw new AcpExecutionError(
|
|
33844
|
+
"The requested Codex mode is unavailable",
|
|
33845
|
+
{},
|
|
33846
|
+
"invalid_session_configuration"
|
|
33847
|
+
);
|
|
33848
|
+
}
|
|
33849
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
33850
|
+
this.#policySelected = true;
|
|
33851
|
+
return;
|
|
33852
|
+
}
|
|
33853
|
+
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
33854
|
+
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
33855
|
+
throw new AcpExecutionError(
|
|
33856
|
+
"The requested Codex collaboration mode is unavailable",
|
|
33857
|
+
{},
|
|
33858
|
+
"invalid_session_configuration"
|
|
33859
|
+
);
|
|
33860
|
+
}
|
|
33861
|
+
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
33862
|
+
this.#collaborationModeSelected = true;
|
|
33863
|
+
return;
|
|
33864
|
+
}
|
|
33865
|
+
if (configId === MODEL_SETTING_ID) {
|
|
33866
|
+
if (value === this.#selection.model) {
|
|
33867
|
+
return;
|
|
33868
|
+
}
|
|
33869
|
+
const model = this.#model(value);
|
|
33870
|
+
if (model === void 0) {
|
|
33871
|
+
throw new AcpExecutionError(
|
|
33872
|
+
"The requested Codex model is unavailable",
|
|
33873
|
+
{},
|
|
33874
|
+
"invalid_session_configuration"
|
|
33875
|
+
);
|
|
33876
|
+
}
|
|
33877
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
33878
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
33879
|
+
this.#selection = {
|
|
33880
|
+
...this.#selection,
|
|
33881
|
+
effort,
|
|
33882
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
33883
|
+
model: value
|
|
33884
|
+
};
|
|
33885
|
+
return;
|
|
33886
|
+
}
|
|
33887
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
33888
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
33889
|
+
(option) => option.reasoningEffort
|
|
33890
|
+
);
|
|
33891
|
+
if (!supported.includes(value)) {
|
|
33892
|
+
throw new AcpExecutionError(
|
|
33893
|
+
"The requested Codex reasoning effort is unavailable",
|
|
33894
|
+
{},
|
|
33895
|
+
"invalid_session_configuration"
|
|
33896
|
+
);
|
|
33897
|
+
}
|
|
33898
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
33899
|
+
return;
|
|
33900
|
+
}
|
|
33901
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
33902
|
+
};
|
|
33903
|
+
};
|
|
33904
|
+
|
|
33905
|
+
// src/acp/codex/agent.ts
|
|
33906
|
+
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
33907
|
+
var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
|
|
33908
|
+
var CODEX_AGENT_VERSION = "0.154.0";
|
|
33909
|
+
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
33910
|
+
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
33911
|
+
var APPROVAL_OPTIONS = Object.freeze([
|
|
33912
|
+
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
33913
|
+
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
33914
|
+
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
33915
|
+
]);
|
|
33916
|
+
function permissionDecision(optionId) {
|
|
33917
|
+
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
33918
|
+
return optionId;
|
|
33919
|
+
}
|
|
33920
|
+
return "cancel";
|
|
33921
|
+
}
|
|
33922
|
+
function promptInput(prompt) {
|
|
33923
|
+
const input2 = [];
|
|
33924
|
+
for (const block of prompt) {
|
|
33925
|
+
if (block.type === "text") {
|
|
33926
|
+
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
33927
|
+
continue;
|
|
33928
|
+
}
|
|
33929
|
+
if (block.type === "image") {
|
|
33930
|
+
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
33931
|
+
continue;
|
|
33932
|
+
}
|
|
33933
|
+
if (block.type === "resource") {
|
|
33934
|
+
const resource = block.resource;
|
|
33935
|
+
input2.push({
|
|
33936
|
+
text: "text" in resource ? resource.text ?? "" : "",
|
|
33937
|
+
text_elements: [],
|
|
33938
|
+
type: "text"
|
|
33939
|
+
});
|
|
33940
|
+
continue;
|
|
33941
|
+
}
|
|
33942
|
+
if (block.type === "resource_link") {
|
|
33943
|
+
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
33944
|
+
}
|
|
33945
|
+
}
|
|
33946
|
+
return input2;
|
|
33947
|
+
}
|
|
33948
|
+
function isCompactPrompt(prompt) {
|
|
33949
|
+
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
33950
|
+
}
|
|
33951
|
+
function steeringPromptInput(prompt) {
|
|
33952
|
+
const input2 = [];
|
|
33953
|
+
for (const block of prompt) {
|
|
33954
|
+
if (typeof block !== "object" || block === null) {
|
|
33955
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33956
|
+
}
|
|
33957
|
+
const type = Reflect.get(block, "type");
|
|
33958
|
+
if (type === "text") {
|
|
33959
|
+
const text2 = Reflect.get(block, "text");
|
|
33960
|
+
if (typeof text2 !== "string") {
|
|
33961
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33962
|
+
}
|
|
33963
|
+
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
33964
|
+
continue;
|
|
33965
|
+
}
|
|
33966
|
+
if (type === "image") {
|
|
33967
|
+
const data = Reflect.get(block, "data");
|
|
33968
|
+
const mimeType = Reflect.get(block, "mimeType");
|
|
33969
|
+
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
33970
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33971
|
+
}
|
|
33972
|
+
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
33973
|
+
continue;
|
|
33974
|
+
}
|
|
33975
|
+
if (type === "resource") {
|
|
33976
|
+
const resource = Reflect.get(block, "resource");
|
|
33977
|
+
if (typeof resource !== "object" || resource === null) {
|
|
33978
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33979
|
+
}
|
|
33980
|
+
const text2 = Reflect.get(resource, "text");
|
|
33981
|
+
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
33982
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33983
|
+
}
|
|
33984
|
+
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
33985
|
+
continue;
|
|
33986
|
+
}
|
|
33987
|
+
if (type === "resource_link") {
|
|
33988
|
+
const uri = Reflect.get(block, "uri");
|
|
33989
|
+
if (typeof uri !== "string") {
|
|
33990
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
33991
|
+
}
|
|
33992
|
+
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
33993
|
+
continue;
|
|
33994
|
+
}
|
|
33995
|
+
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
33749
33996
|
}
|
|
33750
|
-
return
|
|
33751
|
-
category: "thought_level",
|
|
33752
|
-
currentValue: current,
|
|
33753
|
-
description: "How much reasoning effort the model should use",
|
|
33754
|
-
id: REASONING_EFFORT_SETTING_ID,
|
|
33755
|
-
name: "Reasoning effort",
|
|
33756
|
-
options: values,
|
|
33757
|
-
type: "select"
|
|
33758
|
-
};
|
|
33997
|
+
return input2;
|
|
33759
33998
|
}
|
|
33760
33999
|
function userInputSchema(questions) {
|
|
33761
34000
|
const properties = {};
|
|
@@ -33783,31 +34022,13 @@ var CodexAcpAgent = class {
|
|
|
33783
34022
|
terminated;
|
|
33784
34023
|
#closePromise = null;
|
|
33785
34024
|
#connection = null;
|
|
33786
|
-
#
|
|
34025
|
+
#settings;
|
|
33787
34026
|
#nativeSessionId = "";
|
|
33788
|
-
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
33789
|
-
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
33790
|
-
#policySelected = false;
|
|
33791
|
-
// Whether a collaboration mode choice has been made in this session. A restored thread keeps
|
|
33792
|
-
// the mode Codex already persisted, so the first turn does not reset it to Build.
|
|
33793
|
-
#collaborationModeSelected = false;
|
|
33794
|
-
// Whether the app-server accepts collaboration mode on `turn/start`, probed once per
|
|
33795
|
-
// app-server. An older Codex rejects the experimental field, and the setting must disappear
|
|
33796
|
-
// rather than break every turn.
|
|
33797
|
-
#collaborationModeSupported = null;
|
|
33798
|
-
#selection;
|
|
33799
34027
|
#streamedReasoningItemIds = /* @__PURE__ */ new Set();
|
|
33800
34028
|
#turn = null;
|
|
33801
34029
|
#nativeTurnId = null;
|
|
33802
34030
|
#updateTail = Promise.resolve();
|
|
33803
34031
|
constructor(options) {
|
|
33804
|
-
this.#selection = {
|
|
33805
|
-
collaborationMode: "default",
|
|
33806
|
-
effort: "",
|
|
33807
|
-
fastMode: false,
|
|
33808
|
-
mode: initialMode(options.environment),
|
|
33809
|
-
model: ""
|
|
33810
|
-
};
|
|
33811
34032
|
this.#appServer = new CodexAppServerClient({
|
|
33812
34033
|
command: options.command,
|
|
33813
34034
|
cwd: options.cwd,
|
|
@@ -33821,6 +34042,7 @@ var CodexAcpAgent = class {
|
|
|
33821
34042
|
}
|
|
33822
34043
|
}
|
|
33823
34044
|
});
|
|
34045
|
+
this.#settings = new CodexSettings(this.#appServer, options.environment);
|
|
33824
34046
|
this.terminated = this.#appServer.terminated;
|
|
33825
34047
|
void this.terminated.then((termination) => {
|
|
33826
34048
|
this.#turn?.completion.reject(acpEndpointTerminationError(termination));
|
|
@@ -33847,39 +34069,34 @@ var CodexAcpAgent = class {
|
|
|
33847
34069
|
await this.#appServer.request(
|
|
33848
34070
|
"thread/start",
|
|
33849
34071
|
{ cwd: context.params.cwd },
|
|
33850
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
34072
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
33851
34073
|
)
|
|
33852
34074
|
);
|
|
33853
34075
|
this.#nativeSessionId = created.thread.id;
|
|
33854
|
-
|
|
33855
|
-
this.#
|
|
33856
|
-
...this.#selection,
|
|
33857
|
-
collaborationMode: "default",
|
|
33858
|
-
...supported
|
|
33859
|
-
};
|
|
33860
|
-
this.#collaborationModeSelected = false;
|
|
33861
|
-
await this.#probeCollaborationMode(context.signal);
|
|
34076
|
+
this.#settings.selectNewThread(created);
|
|
34077
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
33862
34078
|
await this.#emitAvailableCommands();
|
|
33863
|
-
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
34079
|
+
return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
|
|
33864
34080
|
}).onRequest(methods4.agent.session.setConfigOption, async (context) => {
|
|
33865
|
-
this.#applySelection(context.params.configId, context.params.value);
|
|
33866
|
-
return { configOptions: this.#configOptions() };
|
|
34081
|
+
this.#settings.applySelection(context.params.configId, context.params.value);
|
|
34082
|
+
return { configOptions: this.#settings.configOptions() };
|
|
33867
34083
|
}).onRequest(methods4.agent.session.setMode, async (context) => {
|
|
33868
|
-
this.#applySelection(
|
|
34084
|
+
this.#settings.applySelection("mode", context.params.modeId);
|
|
33869
34085
|
return {};
|
|
33870
34086
|
}).onRequest(methods4.agent.session.load, async (context) => {
|
|
33871
34087
|
const resumed = threadResumeResponseSchema.parse(
|
|
33872
34088
|
await this.#appServer.request(
|
|
33873
34089
|
"thread/resume",
|
|
33874
34090
|
{ cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
|
|
33875
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
34091
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
33876
34092
|
)
|
|
33877
34093
|
);
|
|
33878
|
-
this.#
|
|
33879
|
-
|
|
34094
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
34095
|
+
this.#settings.selectRestoredThread(resumed);
|
|
34096
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
33880
34097
|
await this.#replayHistory(resumed.turns);
|
|
33881
34098
|
await this.#emitAvailableCommands();
|
|
33882
|
-
return { configOptions: this.#configOptions() };
|
|
34099
|
+
return { configOptions: this.#settings.configOptions() };
|
|
33883
34100
|
}).onRequest(methods4.agent.session.fork, async (context) => {
|
|
33884
34101
|
const forked = threadForkResponseSchema.parse(
|
|
33885
34102
|
await this.#appServer.request(
|
|
@@ -33889,26 +34106,28 @@ var CodexAcpAgent = class {
|
|
|
33889
34106
|
excludeTurns: false,
|
|
33890
34107
|
threadId: context.params.sessionId
|
|
33891
34108
|
},
|
|
33892
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
34109
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
33893
34110
|
)
|
|
33894
34111
|
);
|
|
33895
|
-
this.#
|
|
33896
|
-
|
|
34112
|
+
this.#nativeSessionId = forked.thread.id;
|
|
34113
|
+
this.#settings.selectRestoredThread(forked);
|
|
34114
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
33897
34115
|
await this.#replayHistory(forked.turns);
|
|
33898
34116
|
await this.#emitAvailableCommands();
|
|
33899
|
-
return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
|
|
34117
|
+
return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
|
|
33900
34118
|
}).onRequest(methods4.agent.session.resume, async (context) => {
|
|
33901
34119
|
const resumed = threadResumeResponseSchema.parse(
|
|
33902
34120
|
await this.#appServer.request(
|
|
33903
34121
|
"thread/resume",
|
|
33904
34122
|
{ cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
|
|
33905
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
34123
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
33906
34124
|
)
|
|
33907
34125
|
);
|
|
33908
|
-
this.#
|
|
33909
|
-
|
|
34126
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
34127
|
+
this.#settings.selectRestoredThread(resumed);
|
|
34128
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
33910
34129
|
await this.#emitAvailableCommands();
|
|
33911
|
-
return { configOptions: this.#configOptions() };
|
|
34130
|
+
return { configOptions: this.#settings.configOptions() };
|
|
33912
34131
|
}).onRequest(methods4.agent.session.prompt, async (context) => {
|
|
33913
34132
|
if (isCompactPrompt(context.params.prompt)) {
|
|
33914
34133
|
return await this.#compact(context.signal);
|
|
@@ -33948,7 +34167,7 @@ var CodexAcpAgent = class {
|
|
|
33948
34167
|
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
33949
34168
|
initialize = async (signal) => {
|
|
33950
34169
|
await this.#appServer.initialize(signal);
|
|
33951
|
-
await this.#loadModels(signal);
|
|
34170
|
+
await this.#settings.loadModels(signal);
|
|
33952
34171
|
};
|
|
33953
34172
|
/**
|
|
33954
34173
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
@@ -33974,84 +34193,6 @@ var CodexAcpAgent = class {
|
|
|
33974
34193
|
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
33975
34194
|
* turn lifecycle continues without settings rather than failing initialization.
|
|
33976
34195
|
*/
|
|
33977
|
-
#loadModels = async (signal) => {
|
|
33978
|
-
const models = [];
|
|
33979
|
-
let cursor = null;
|
|
33980
|
-
try {
|
|
33981
|
-
do {
|
|
33982
|
-
const decoded = modelListResponseSchema.parse(
|
|
33983
|
-
await this.#appServer.request(
|
|
33984
|
-
"model/list",
|
|
33985
|
-
{ cursor, limit: null },
|
|
33986
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
33987
|
-
)
|
|
33988
|
-
);
|
|
33989
|
-
models.push(...decoded.data);
|
|
33990
|
-
cursor = decoded.nextCursor ?? null;
|
|
33991
|
-
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
33992
|
-
} catch (error62) {
|
|
33993
|
-
signal.throwIfAborted();
|
|
33994
|
-
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
33995
|
-
`);
|
|
33996
|
-
}
|
|
33997
|
-
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
33998
|
-
};
|
|
33999
|
-
#model = (id) => this.#models.find((model) => model.id === id);
|
|
34000
|
-
/**
|
|
34001
|
-
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
34002
|
-
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
34003
|
-
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
34004
|
-
*/
|
|
34005
|
-
#probeCollaborationMode = async (signal) => {
|
|
34006
|
-
if (this.#collaborationModeSupported !== null) {
|
|
34007
|
-
return;
|
|
34008
|
-
}
|
|
34009
|
-
try {
|
|
34010
|
-
await this.#appServer.request(
|
|
34011
|
-
"thread/settings/update",
|
|
34012
|
-
{ threadId: this.#nativeSessionId },
|
|
34013
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
34014
|
-
);
|
|
34015
|
-
this.#collaborationModeSupported = true;
|
|
34016
|
-
} catch {
|
|
34017
|
-
signal.throwIfAborted();
|
|
34018
|
-
this.#collaborationModeSupported = false;
|
|
34019
|
-
}
|
|
34020
|
-
};
|
|
34021
|
-
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
34022
|
-
#configOptions = () => {
|
|
34023
|
-
const options = [];
|
|
34024
|
-
const model = modelSetting(this.#models, this.#selection.model);
|
|
34025
|
-
if (model !== null) {
|
|
34026
|
-
options.push(model);
|
|
34027
|
-
}
|
|
34028
|
-
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
34029
|
-
if (effort !== null) {
|
|
34030
|
-
options.push(effort);
|
|
34031
|
-
}
|
|
34032
|
-
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
34033
|
-
if (fastMode !== null) {
|
|
34034
|
-
options.push(fastMode);
|
|
34035
|
-
}
|
|
34036
|
-
if (this.#collaborationModeSupported === true) {
|
|
34037
|
-
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
34038
|
-
}
|
|
34039
|
-
options.push(modeSetting(this.#selection.mode));
|
|
34040
|
-
return options;
|
|
34041
|
-
};
|
|
34042
|
-
#selectRestoredThread = (thread) => {
|
|
34043
|
-
this.#nativeSessionId = thread.thread.id;
|
|
34044
|
-
const supported = supportedSelection(
|
|
34045
|
-
this.#models,
|
|
34046
|
-
thread.model ?? this.#selection.model,
|
|
34047
|
-
thread.reasoningEffort ?? this.#selection.effort
|
|
34048
|
-
);
|
|
34049
|
-
this.#selection = {
|
|
34050
|
-
...this.#selection,
|
|
34051
|
-
...supported,
|
|
34052
|
-
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
34053
|
-
};
|
|
34054
|
-
};
|
|
34055
34196
|
#replayHistory = async (turns) => {
|
|
34056
34197
|
for (const turn of turns ?? []) {
|
|
34057
34198
|
for (const rawItem of turn.items) {
|
|
@@ -34093,95 +34234,6 @@ var CodexAcpAgent = class {
|
|
|
34093
34234
|
}
|
|
34094
34235
|
}
|
|
34095
34236
|
};
|
|
34096
|
-
/**
|
|
34097
|
-
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
34098
|
-
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
34099
|
-
* so the reply never advertises an effort the selected model cannot run.
|
|
34100
|
-
*/
|
|
34101
|
-
#applySelection = (configId, value) => {
|
|
34102
|
-
if (configId === FAST_MODE_SETTING_ID) {
|
|
34103
|
-
if (typeof value !== "boolean") {
|
|
34104
|
-
throw new AcpExecutionError(
|
|
34105
|
-
"The requested Codex setting is invalid",
|
|
34106
|
-
{},
|
|
34107
|
-
"invalid_session_configuration"
|
|
34108
|
-
);
|
|
34109
|
-
}
|
|
34110
|
-
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
34111
|
-
throw new AcpExecutionError(
|
|
34112
|
-
"The selected Codex model has no fast mode",
|
|
34113
|
-
{},
|
|
34114
|
-
"invalid_session_configuration"
|
|
34115
|
-
);
|
|
34116
|
-
}
|
|
34117
|
-
this.#selection = { ...this.#selection, fastMode: value };
|
|
34118
|
-
return;
|
|
34119
|
-
}
|
|
34120
|
-
if (typeof value !== "string") {
|
|
34121
|
-
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
34122
|
-
}
|
|
34123
|
-
if (configId === MODE_SETTING_ID) {
|
|
34124
|
-
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
34125
|
-
throw new AcpExecutionError(
|
|
34126
|
-
"The requested Codex mode is unavailable",
|
|
34127
|
-
{},
|
|
34128
|
-
"invalid_session_configuration"
|
|
34129
|
-
);
|
|
34130
|
-
}
|
|
34131
|
-
this.#selection = { ...this.#selection, mode: value };
|
|
34132
|
-
this.#policySelected = true;
|
|
34133
|
-
return;
|
|
34134
|
-
}
|
|
34135
|
-
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
34136
|
-
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
34137
|
-
throw new AcpExecutionError(
|
|
34138
|
-
"The requested Codex collaboration mode is unavailable",
|
|
34139
|
-
{},
|
|
34140
|
-
"invalid_session_configuration"
|
|
34141
|
-
);
|
|
34142
|
-
}
|
|
34143
|
-
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
34144
|
-
this.#collaborationModeSelected = true;
|
|
34145
|
-
return;
|
|
34146
|
-
}
|
|
34147
|
-
if (configId === MODEL_SETTING_ID) {
|
|
34148
|
-
if (value === this.#selection.model) {
|
|
34149
|
-
return;
|
|
34150
|
-
}
|
|
34151
|
-
const model = this.#model(value);
|
|
34152
|
-
if (model === void 0) {
|
|
34153
|
-
throw new AcpExecutionError(
|
|
34154
|
-
"The requested Codex model is unavailable",
|
|
34155
|
-
{},
|
|
34156
|
-
"invalid_session_configuration"
|
|
34157
|
-
);
|
|
34158
|
-
}
|
|
34159
|
-
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
34160
|
-
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
34161
|
-
this.#selection = {
|
|
34162
|
-
...this.#selection,
|
|
34163
|
-
effort,
|
|
34164
|
-
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
34165
|
-
model: value
|
|
34166
|
-
};
|
|
34167
|
-
return;
|
|
34168
|
-
}
|
|
34169
|
-
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
34170
|
-
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
34171
|
-
(option) => option.reasoningEffort
|
|
34172
|
-
);
|
|
34173
|
-
if (!supported.includes(value)) {
|
|
34174
|
-
throw new AcpExecutionError(
|
|
34175
|
-
"The requested Codex reasoning effort is unavailable",
|
|
34176
|
-
{},
|
|
34177
|
-
"invalid_session_configuration"
|
|
34178
|
-
);
|
|
34179
|
-
}
|
|
34180
|
-
this.#selection = { ...this.#selection, effort: value };
|
|
34181
|
-
return;
|
|
34182
|
-
}
|
|
34183
|
-
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
34184
|
-
};
|
|
34185
34237
|
#emit = async (update) => {
|
|
34186
34238
|
const connection = this.#connection;
|
|
34187
34239
|
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
@@ -34206,7 +34258,7 @@ var CodexAcpAgent = class {
|
|
|
34206
34258
|
}
|
|
34207
34259
|
await connection.client.notify(methods4.client.session.update, {
|
|
34208
34260
|
sessionId: this.#nativeSessionId,
|
|
34209
|
-
update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
|
|
34261
|
+
update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
|
|
34210
34262
|
});
|
|
34211
34263
|
};
|
|
34212
34264
|
// Notifications are serialized so two app-server items cannot interleave into one ACP update
|
|
@@ -34246,8 +34298,7 @@ var CodexAcpAgent = class {
|
|
|
34246
34298
|
const decoded = threadSettingsUpdatedSchema.safeParse(params);
|
|
34247
34299
|
if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
|
|
34248
34300
|
const mode = decoded.data.threadSettings.collaborationMode?.mode;
|
|
34249
|
-
if (
|
|
34250
|
-
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
34301
|
+
if (this.#settings.observeCollaborationMode(mode)) {
|
|
34251
34302
|
await this.#enqueue(async () => {
|
|
34252
34303
|
await this.#emitConfigOptionsUpdate();
|
|
34253
34304
|
});
|
|
@@ -34369,7 +34420,7 @@ var CodexAcpAgent = class {
|
|
|
34369
34420
|
const decision = await this.#askPermission(
|
|
34370
34421
|
title2,
|
|
34371
34422
|
params.itemId,
|
|
34372
|
-
AbortSignal.timeout(
|
|
34423
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
34373
34424
|
);
|
|
34374
34425
|
void turn;
|
|
34375
34426
|
this.#appServer.respond(request.id, { decision });
|
|
@@ -34391,7 +34442,7 @@ var CodexAcpAgent = class {
|
|
|
34391
34442
|
sessionId: this.#nativeSessionId,
|
|
34392
34443
|
...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
|
|
34393
34444
|
},
|
|
34394
|
-
{ cancellationSignal: AbortSignal.timeout(
|
|
34445
|
+
{ cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
|
|
34395
34446
|
);
|
|
34396
34447
|
const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
|
|
34397
34448
|
const answers = {};
|
|
@@ -34409,7 +34460,7 @@ var CodexAcpAgent = class {
|
|
|
34409
34460
|
return;
|
|
34410
34461
|
}
|
|
34411
34462
|
const params = decoded.data;
|
|
34412
|
-
const signal = AbortSignal.timeout(
|
|
34463
|
+
const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
|
|
34413
34464
|
if (params.mode === "url" && params.url !== void 0) {
|
|
34414
34465
|
const response2 = await connection.client.request(
|
|
34415
34466
|
methods4.client.elicitation.create,
|
|
@@ -34458,38 +34509,12 @@ var CodexAcpAgent = class {
|
|
|
34458
34509
|
this.#turn = turn;
|
|
34459
34510
|
this.#nativeTurnId = null;
|
|
34460
34511
|
try {
|
|
34461
|
-
const selection = this.#selection;
|
|
34462
|
-
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
34463
|
-
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
34464
34512
|
const started = turnSchema.parse(
|
|
34465
34513
|
(await this.#appServer.request(
|
|
34466
34514
|
"turn/start",
|
|
34467
34515
|
{
|
|
34468
|
-
|
|
34469
|
-
// policy, and those fields stay off the turn so the host's own setup is
|
|
34470
|
-
// inherited rather than overridden.
|
|
34471
|
-
...this.#policySelected ? {
|
|
34472
|
-
approvalPolicy: mode.approvalPolicy,
|
|
34473
|
-
approvalsReviewer: mode.approvalsReviewer,
|
|
34474
|
-
sandboxPolicy: mode.sandboxPolicy
|
|
34475
|
-
} : {},
|
|
34476
|
-
// The collaboration mode rides on the turn: Codex applies it to the
|
|
34477
|
-
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
34478
|
-
// mode, so it is only sent once a choice exists to apply.
|
|
34479
|
-
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
34480
|
-
collaborationMode: {
|
|
34481
|
-
mode: selection.collaborationMode,
|
|
34482
|
-
settings: {
|
|
34483
|
-
developer_instructions: null,
|
|
34484
|
-
model: selection.model,
|
|
34485
|
-
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
34486
|
-
}
|
|
34487
|
-
}
|
|
34488
|
-
} : {},
|
|
34489
|
-
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
34516
|
+
...this.#settings.turnParameters(),
|
|
34490
34517
|
input: input2,
|
|
34491
|
-
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
34492
|
-
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
34493
34518
|
threadId: this.#nativeSessionId
|
|
34494
34519
|
},
|
|
34495
34520
|
signal
|
|
@@ -34558,7 +34583,7 @@ var CodexAcpAgent = class {
|
|
|
34558
34583
|
await this.#appServer.request(
|
|
34559
34584
|
"turn/steer",
|
|
34560
34585
|
{ expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
|
|
34561
|
-
AbortSignal.any([signal, AbortSignal.timeout(
|
|
34586
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
34562
34587
|
)
|
|
34563
34588
|
);
|
|
34564
34589
|
if (response.turnId !== active.turn.id) {
|
|
@@ -34577,7 +34602,7 @@ var CodexAcpAgent = class {
|
|
|
34577
34602
|
await this.#appServer.request(
|
|
34578
34603
|
"turn/interrupt",
|
|
34579
34604
|
{ threadId: this.#nativeSessionId, turnId: turn.turn.id },
|
|
34580
|
-
AbortSignal.timeout(
|
|
34605
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
34581
34606
|
);
|
|
34582
34607
|
} catch {
|
|
34583
34608
|
}
|