@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/runtime.js
CHANGED
|
@@ -23465,11 +23465,8 @@ function agentMessageMeta(phase) {
|
|
|
23465
23465
|
return { [CODEX_META_KEY]: { phase } };
|
|
23466
23466
|
}
|
|
23467
23467
|
|
|
23468
|
-
// src/acp/codex/
|
|
23469
|
-
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
23468
|
+
// src/acp/codex/settings.ts
|
|
23470
23469
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
23471
|
-
var CODEX_AGENT_VERSION = "0.154.0";
|
|
23472
|
-
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
23473
23470
|
var MODEL_SETTING_ID = "model";
|
|
23474
23471
|
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
23475
23472
|
var MODE_SETTING_ID = "mode";
|
|
@@ -23478,7 +23475,6 @@ var COLLABORATION_MODE_SETTING_ID = "collaboration_mode";
|
|
|
23478
23475
|
var MODEL_CATALOG_LIMIT = 1e3;
|
|
23479
23476
|
var FAST_TIER = "fast";
|
|
23480
23477
|
var SERVICE_TIER_FAST = "priority";
|
|
23481
|
-
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
23482
23478
|
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
23483
23479
|
excludeSlashTmp: false,
|
|
23484
23480
|
excludeTmpdirEnvVar: false,
|
|
@@ -23522,94 +23518,6 @@ function initialMode(environment) {
|
|
|
23522
23518
|
function capitalize(value) {
|
|
23523
23519
|
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
23524
23520
|
}
|
|
23525
|
-
var APPROVAL_OPTIONS = Object.freeze([
|
|
23526
|
-
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
23527
|
-
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
23528
|
-
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
23529
|
-
]);
|
|
23530
|
-
function permissionDecision(optionId) {
|
|
23531
|
-
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
23532
|
-
return optionId;
|
|
23533
|
-
}
|
|
23534
|
-
return "cancel";
|
|
23535
|
-
}
|
|
23536
|
-
function promptInput(prompt) {
|
|
23537
|
-
const input2 = [];
|
|
23538
|
-
for (const block of prompt) {
|
|
23539
|
-
if (block.type === "text") {
|
|
23540
|
-
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
23541
|
-
continue;
|
|
23542
|
-
}
|
|
23543
|
-
if (block.type === "image") {
|
|
23544
|
-
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
23545
|
-
continue;
|
|
23546
|
-
}
|
|
23547
|
-
if (block.type === "resource") {
|
|
23548
|
-
const resource = block.resource;
|
|
23549
|
-
input2.push({
|
|
23550
|
-
text: "text" in resource ? resource.text ?? "" : "",
|
|
23551
|
-
text_elements: [],
|
|
23552
|
-
type: "text"
|
|
23553
|
-
});
|
|
23554
|
-
continue;
|
|
23555
|
-
}
|
|
23556
|
-
if (block.type === "resource_link") {
|
|
23557
|
-
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
23558
|
-
}
|
|
23559
|
-
}
|
|
23560
|
-
return input2;
|
|
23561
|
-
}
|
|
23562
|
-
function isCompactPrompt(prompt) {
|
|
23563
|
-
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
23564
|
-
}
|
|
23565
|
-
function steeringPromptInput(prompt) {
|
|
23566
|
-
const input2 = [];
|
|
23567
|
-
for (const block of prompt) {
|
|
23568
|
-
if (typeof block !== "object" || block === null) {
|
|
23569
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23570
|
-
}
|
|
23571
|
-
const type = Reflect.get(block, "type");
|
|
23572
|
-
if (type === "text") {
|
|
23573
|
-
const text2 = Reflect.get(block, "text");
|
|
23574
|
-
if (typeof text2 !== "string") {
|
|
23575
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23576
|
-
}
|
|
23577
|
-
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
23578
|
-
continue;
|
|
23579
|
-
}
|
|
23580
|
-
if (type === "image") {
|
|
23581
|
-
const data = Reflect.get(block, "data");
|
|
23582
|
-
const mimeType = Reflect.get(block, "mimeType");
|
|
23583
|
-
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
23584
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23585
|
-
}
|
|
23586
|
-
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
23587
|
-
continue;
|
|
23588
|
-
}
|
|
23589
|
-
if (type === "resource") {
|
|
23590
|
-
const resource = Reflect.get(block, "resource");
|
|
23591
|
-
if (typeof resource !== "object" || resource === null) {
|
|
23592
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23593
|
-
}
|
|
23594
|
-
const text2 = Reflect.get(resource, "text");
|
|
23595
|
-
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
23596
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23597
|
-
}
|
|
23598
|
-
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
23599
|
-
continue;
|
|
23600
|
-
}
|
|
23601
|
-
if (type === "resource_link") {
|
|
23602
|
-
const uri = Reflect.get(block, "uri");
|
|
23603
|
-
if (typeof uri !== "string") {
|
|
23604
|
-
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23605
|
-
}
|
|
23606
|
-
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
23607
|
-
continue;
|
|
23608
|
-
}
|
|
23609
|
-
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
23610
|
-
}
|
|
23611
|
-
return input2;
|
|
23612
|
-
}
|
|
23613
23521
|
function modelValues(models) {
|
|
23614
23522
|
return models.map((model) => ({
|
|
23615
23523
|
description: model.description ?? "",
|
|
@@ -23714,34 +23622,9 @@ function effortSetting(model, currentValue) {
|
|
|
23714
23622
|
type: "select"
|
|
23715
23623
|
};
|
|
23716
23624
|
}
|
|
23717
|
-
|
|
23718
|
-
const properties = {};
|
|
23719
|
-
const required2 = [];
|
|
23720
|
-
for (const question of questions) {
|
|
23721
|
-
required2.push(question.id);
|
|
23722
|
-
properties[question.id] = {
|
|
23723
|
-
description: question.question,
|
|
23724
|
-
title: question.header,
|
|
23725
|
-
type: "string",
|
|
23726
|
-
...question.options == null || question.options.length === 0 ? {} : {
|
|
23727
|
-
oneOf: question.options.map((option) => ({
|
|
23728
|
-
const: option.label,
|
|
23729
|
-
description: option.description,
|
|
23730
|
-
title: option.label
|
|
23731
|
-
}))
|
|
23732
|
-
}
|
|
23733
|
-
};
|
|
23734
|
-
}
|
|
23735
|
-
return { properties, required: required2, type: "object" };
|
|
23736
|
-
}
|
|
23737
|
-
var CodexAcpAgent = class {
|
|
23738
|
-
#app;
|
|
23625
|
+
var CodexSettings = class {
|
|
23739
23626
|
#appServer;
|
|
23740
|
-
terminated;
|
|
23741
|
-
#closePromise = null;
|
|
23742
|
-
#connection = null;
|
|
23743
23627
|
#models = [];
|
|
23744
|
-
#nativeSessionId = "";
|
|
23745
23628
|
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
23746
23629
|
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
23747
23630
|
#policySelected = false;
|
|
@@ -23753,48 +23636,389 @@ var CodexAcpAgent = class {
|
|
|
23753
23636
|
// rather than break every turn.
|
|
23754
23637
|
#collaborationModeSupported = null;
|
|
23755
23638
|
#selection;
|
|
23756
|
-
|
|
23757
|
-
|
|
23758
|
-
#nativeTurnId = null;
|
|
23759
|
-
#updateTail = Promise.resolve();
|
|
23760
|
-
constructor(options) {
|
|
23639
|
+
constructor(appServer, environment) {
|
|
23640
|
+
this.#appServer = appServer;
|
|
23761
23641
|
this.#selection = {
|
|
23762
23642
|
collaborationMode: "default",
|
|
23763
23643
|
effort: "",
|
|
23764
23644
|
fastMode: false,
|
|
23765
|
-
mode: initialMode(
|
|
23645
|
+
mode: initialMode(environment),
|
|
23766
23646
|
model: ""
|
|
23767
23647
|
};
|
|
23768
|
-
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
|
|
23772
|
-
|
|
23773
|
-
|
|
23774
|
-
|
|
23775
|
-
|
|
23776
|
-
|
|
23777
|
-
|
|
23648
|
+
}
|
|
23649
|
+
selectNewThread = (created) => {
|
|
23650
|
+
const supported = supportedSelection(this.#models, created.model ?? "", created.reasoningEffort ?? "");
|
|
23651
|
+
this.#selection = {
|
|
23652
|
+
...this.#selection,
|
|
23653
|
+
collaborationMode: "default",
|
|
23654
|
+
...supported
|
|
23655
|
+
};
|
|
23656
|
+
this.#collaborationModeSelected = false;
|
|
23657
|
+
};
|
|
23658
|
+
observeCollaborationMode = (mode) => {
|
|
23659
|
+
if (mode === void 0 || mode === this.#selection.collaborationMode) {
|
|
23660
|
+
return false;
|
|
23661
|
+
}
|
|
23662
|
+
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
23663
|
+
return true;
|
|
23664
|
+
};
|
|
23665
|
+
turnParameters = () => {
|
|
23666
|
+
const selection = this.#selection;
|
|
23667
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
23668
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
23669
|
+
return {
|
|
23670
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
23671
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
23672
|
+
// inherited rather than overridden.
|
|
23673
|
+
...this.#policySelected ? {
|
|
23674
|
+
approvalPolicy: mode.approvalPolicy,
|
|
23675
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
23676
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
23677
|
+
} : {},
|
|
23678
|
+
// The collaboration mode rides on the turn: Codex applies it to the
|
|
23679
|
+
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
23680
|
+
// mode, so it is only sent once a choice exists to apply.
|
|
23681
|
+
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
23682
|
+
collaborationMode: {
|
|
23683
|
+
mode: selection.collaborationMode,
|
|
23684
|
+
settings: {
|
|
23685
|
+
developer_instructions: null,
|
|
23686
|
+
model: selection.model,
|
|
23687
|
+
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
23688
|
+
}
|
|
23778
23689
|
}
|
|
23690
|
+
} : {},
|
|
23691
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
23692
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
23693
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {}
|
|
23694
|
+
};
|
|
23695
|
+
};
|
|
23696
|
+
loadModels = async (signal) => {
|
|
23697
|
+
const models = [];
|
|
23698
|
+
let cursor = null;
|
|
23699
|
+
try {
|
|
23700
|
+
do {
|
|
23701
|
+
const decoded = modelListResponseSchema.parse(
|
|
23702
|
+
await this.#appServer.request(
|
|
23703
|
+
"model/list",
|
|
23704
|
+
{ cursor, limit: null },
|
|
23705
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
23706
|
+
)
|
|
23707
|
+
);
|
|
23708
|
+
models.push(...decoded.data);
|
|
23709
|
+
cursor = decoded.nextCursor ?? null;
|
|
23710
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
23711
|
+
} catch (error62) {
|
|
23712
|
+
signal.throwIfAborted();
|
|
23713
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
23714
|
+
`);
|
|
23715
|
+
}
|
|
23716
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
23717
|
+
};
|
|
23718
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
23719
|
+
/**
|
|
23720
|
+
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
23721
|
+
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
23722
|
+
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
23723
|
+
*/
|
|
23724
|
+
probeCollaborationMode = async (threadId, signal) => {
|
|
23725
|
+
if (this.#collaborationModeSupported !== null) {
|
|
23726
|
+
return;
|
|
23727
|
+
}
|
|
23728
|
+
try {
|
|
23729
|
+
await this.#appServer.request(
|
|
23730
|
+
"thread/settings/update",
|
|
23731
|
+
{ threadId },
|
|
23732
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
23733
|
+
);
|
|
23734
|
+
this.#collaborationModeSupported = true;
|
|
23735
|
+
} catch {
|
|
23736
|
+
signal.throwIfAborted();
|
|
23737
|
+
this.#collaborationModeSupported = false;
|
|
23738
|
+
}
|
|
23739
|
+
};
|
|
23740
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
23741
|
+
configOptions = () => {
|
|
23742
|
+
const options = [];
|
|
23743
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
23744
|
+
if (model !== null) {
|
|
23745
|
+
options.push(model);
|
|
23746
|
+
}
|
|
23747
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
23748
|
+
if (effort !== null) {
|
|
23749
|
+
options.push(effort);
|
|
23750
|
+
}
|
|
23751
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
23752
|
+
if (fastMode !== null) {
|
|
23753
|
+
options.push(fastMode);
|
|
23754
|
+
}
|
|
23755
|
+
if (this.#collaborationModeSupported === true) {
|
|
23756
|
+
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
23757
|
+
}
|
|
23758
|
+
options.push(modeSetting(this.#selection.mode));
|
|
23759
|
+
return options;
|
|
23760
|
+
};
|
|
23761
|
+
selectRestoredThread = (thread) => {
|
|
23762
|
+
const supported = supportedSelection(
|
|
23763
|
+
this.#models,
|
|
23764
|
+
thread.model ?? this.#selection.model,
|
|
23765
|
+
thread.reasoningEffort ?? this.#selection.effort
|
|
23766
|
+
);
|
|
23767
|
+
this.#selection = {
|
|
23768
|
+
...this.#selection,
|
|
23769
|
+
...supported,
|
|
23770
|
+
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
23771
|
+
};
|
|
23772
|
+
};
|
|
23773
|
+
/**
|
|
23774
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
23775
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
23776
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
23777
|
+
*/
|
|
23778
|
+
applySelection = (configId, value) => {
|
|
23779
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
23780
|
+
if (typeof value !== "boolean") {
|
|
23781
|
+
throw new AcpExecutionError(
|
|
23782
|
+
"The requested Codex setting is invalid",
|
|
23783
|
+
{},
|
|
23784
|
+
"invalid_session_configuration"
|
|
23785
|
+
);
|
|
23779
23786
|
}
|
|
23780
|
-
|
|
23781
|
-
|
|
23782
|
-
|
|
23783
|
-
|
|
23784
|
-
|
|
23785
|
-
|
|
23786
|
-
console.error("The failed Codex endpoint could not release its process tree", cause);
|
|
23787
|
-
});
|
|
23787
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
23788
|
+
throw new AcpExecutionError(
|
|
23789
|
+
"The selected Codex model has no fast mode",
|
|
23790
|
+
{},
|
|
23791
|
+
"invalid_session_configuration"
|
|
23792
|
+
);
|
|
23788
23793
|
}
|
|
23789
|
-
|
|
23790
|
-
|
|
23791
|
-
|
|
23792
|
-
|
|
23793
|
-
|
|
23794
|
-
|
|
23795
|
-
|
|
23796
|
-
|
|
23797
|
-
|
|
23794
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
23795
|
+
return;
|
|
23796
|
+
}
|
|
23797
|
+
if (typeof value !== "string") {
|
|
23798
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
23799
|
+
}
|
|
23800
|
+
if (configId === MODE_SETTING_ID) {
|
|
23801
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
23802
|
+
throw new AcpExecutionError(
|
|
23803
|
+
"The requested Codex mode is unavailable",
|
|
23804
|
+
{},
|
|
23805
|
+
"invalid_session_configuration"
|
|
23806
|
+
);
|
|
23807
|
+
}
|
|
23808
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
23809
|
+
this.#policySelected = true;
|
|
23810
|
+
return;
|
|
23811
|
+
}
|
|
23812
|
+
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
23813
|
+
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
23814
|
+
throw new AcpExecutionError(
|
|
23815
|
+
"The requested Codex collaboration mode is unavailable",
|
|
23816
|
+
{},
|
|
23817
|
+
"invalid_session_configuration"
|
|
23818
|
+
);
|
|
23819
|
+
}
|
|
23820
|
+
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
23821
|
+
this.#collaborationModeSelected = true;
|
|
23822
|
+
return;
|
|
23823
|
+
}
|
|
23824
|
+
if (configId === MODEL_SETTING_ID) {
|
|
23825
|
+
if (value === this.#selection.model) {
|
|
23826
|
+
return;
|
|
23827
|
+
}
|
|
23828
|
+
const model = this.#model(value);
|
|
23829
|
+
if (model === void 0) {
|
|
23830
|
+
throw new AcpExecutionError(
|
|
23831
|
+
"The requested Codex model is unavailable",
|
|
23832
|
+
{},
|
|
23833
|
+
"invalid_session_configuration"
|
|
23834
|
+
);
|
|
23835
|
+
}
|
|
23836
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
23837
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
23838
|
+
this.#selection = {
|
|
23839
|
+
...this.#selection,
|
|
23840
|
+
effort,
|
|
23841
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
23842
|
+
model: value
|
|
23843
|
+
};
|
|
23844
|
+
return;
|
|
23845
|
+
}
|
|
23846
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
23847
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
23848
|
+
(option) => option.reasoningEffort
|
|
23849
|
+
);
|
|
23850
|
+
if (!supported.includes(value)) {
|
|
23851
|
+
throw new AcpExecutionError(
|
|
23852
|
+
"The requested Codex reasoning effort is unavailable",
|
|
23853
|
+
{},
|
|
23854
|
+
"invalid_session_configuration"
|
|
23855
|
+
);
|
|
23856
|
+
}
|
|
23857
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
23858
|
+
return;
|
|
23859
|
+
}
|
|
23860
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
23861
|
+
};
|
|
23862
|
+
};
|
|
23863
|
+
|
|
23864
|
+
// src/acp/codex/agent.ts
|
|
23865
|
+
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
23866
|
+
var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
|
|
23867
|
+
var CODEX_AGENT_VERSION = "0.154.0";
|
|
23868
|
+
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
23869
|
+
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
23870
|
+
var APPROVAL_OPTIONS = Object.freeze([
|
|
23871
|
+
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
23872
|
+
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
23873
|
+
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
23874
|
+
]);
|
|
23875
|
+
function permissionDecision(optionId) {
|
|
23876
|
+
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
23877
|
+
return optionId;
|
|
23878
|
+
}
|
|
23879
|
+
return "cancel";
|
|
23880
|
+
}
|
|
23881
|
+
function promptInput(prompt) {
|
|
23882
|
+
const input2 = [];
|
|
23883
|
+
for (const block of prompt) {
|
|
23884
|
+
if (block.type === "text") {
|
|
23885
|
+
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
23886
|
+
continue;
|
|
23887
|
+
}
|
|
23888
|
+
if (block.type === "image") {
|
|
23889
|
+
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
23890
|
+
continue;
|
|
23891
|
+
}
|
|
23892
|
+
if (block.type === "resource") {
|
|
23893
|
+
const resource = block.resource;
|
|
23894
|
+
input2.push({
|
|
23895
|
+
text: "text" in resource ? resource.text ?? "" : "",
|
|
23896
|
+
text_elements: [],
|
|
23897
|
+
type: "text"
|
|
23898
|
+
});
|
|
23899
|
+
continue;
|
|
23900
|
+
}
|
|
23901
|
+
if (block.type === "resource_link") {
|
|
23902
|
+
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
23903
|
+
}
|
|
23904
|
+
}
|
|
23905
|
+
return input2;
|
|
23906
|
+
}
|
|
23907
|
+
function isCompactPrompt(prompt) {
|
|
23908
|
+
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
23909
|
+
}
|
|
23910
|
+
function steeringPromptInput(prompt) {
|
|
23911
|
+
const input2 = [];
|
|
23912
|
+
for (const block of prompt) {
|
|
23913
|
+
if (typeof block !== "object" || block === null) {
|
|
23914
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23915
|
+
}
|
|
23916
|
+
const type = Reflect.get(block, "type");
|
|
23917
|
+
if (type === "text") {
|
|
23918
|
+
const text2 = Reflect.get(block, "text");
|
|
23919
|
+
if (typeof text2 !== "string") {
|
|
23920
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23921
|
+
}
|
|
23922
|
+
input2.push({ text: text2, text_elements: [], type: "text" });
|
|
23923
|
+
continue;
|
|
23924
|
+
}
|
|
23925
|
+
if (type === "image") {
|
|
23926
|
+
const data = Reflect.get(block, "data");
|
|
23927
|
+
const mimeType = Reflect.get(block, "mimeType");
|
|
23928
|
+
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
23929
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23930
|
+
}
|
|
23931
|
+
input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
|
|
23932
|
+
continue;
|
|
23933
|
+
}
|
|
23934
|
+
if (type === "resource") {
|
|
23935
|
+
const resource = Reflect.get(block, "resource");
|
|
23936
|
+
if (typeof resource !== "object" || resource === null) {
|
|
23937
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23938
|
+
}
|
|
23939
|
+
const text2 = Reflect.get(resource, "text");
|
|
23940
|
+
if (text2 !== void 0 && typeof text2 !== "string") {
|
|
23941
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23942
|
+
}
|
|
23943
|
+
input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
|
|
23944
|
+
continue;
|
|
23945
|
+
}
|
|
23946
|
+
if (type === "resource_link") {
|
|
23947
|
+
const uri = Reflect.get(block, "uri");
|
|
23948
|
+
if (typeof uri !== "string") {
|
|
23949
|
+
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
23950
|
+
}
|
|
23951
|
+
input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
|
|
23952
|
+
continue;
|
|
23953
|
+
}
|
|
23954
|
+
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
23955
|
+
}
|
|
23956
|
+
return input2;
|
|
23957
|
+
}
|
|
23958
|
+
function userInputSchema(questions) {
|
|
23959
|
+
const properties = {};
|
|
23960
|
+
const required2 = [];
|
|
23961
|
+
for (const question of questions) {
|
|
23962
|
+
required2.push(question.id);
|
|
23963
|
+
properties[question.id] = {
|
|
23964
|
+
description: question.question,
|
|
23965
|
+
title: question.header,
|
|
23966
|
+
type: "string",
|
|
23967
|
+
...question.options == null || question.options.length === 0 ? {} : {
|
|
23968
|
+
oneOf: question.options.map((option) => ({
|
|
23969
|
+
const: option.label,
|
|
23970
|
+
description: option.description,
|
|
23971
|
+
title: option.label
|
|
23972
|
+
}))
|
|
23973
|
+
}
|
|
23974
|
+
};
|
|
23975
|
+
}
|
|
23976
|
+
return { properties, required: required2, type: "object" };
|
|
23977
|
+
}
|
|
23978
|
+
var CodexAcpAgent = class {
|
|
23979
|
+
#app;
|
|
23980
|
+
#appServer;
|
|
23981
|
+
terminated;
|
|
23982
|
+
#closePromise = null;
|
|
23983
|
+
#connection = null;
|
|
23984
|
+
#settings;
|
|
23985
|
+
#nativeSessionId = "";
|
|
23986
|
+
#streamedReasoningItemIds = /* @__PURE__ */ new Set();
|
|
23987
|
+
#turn = null;
|
|
23988
|
+
#nativeTurnId = null;
|
|
23989
|
+
#updateTail = Promise.resolve();
|
|
23990
|
+
constructor(options) {
|
|
23991
|
+
this.#appServer = new CodexAppServerClient({
|
|
23992
|
+
command: options.command,
|
|
23993
|
+
cwd: options.cwd,
|
|
23994
|
+
environment: options.environment,
|
|
23995
|
+
handlers: {
|
|
23996
|
+
onNotification: async (method, params) => {
|
|
23997
|
+
await this.#onNotification(method, params);
|
|
23998
|
+
},
|
|
23999
|
+
onServerRequest: async (request) => {
|
|
24000
|
+
await this.#onServerRequest(request);
|
|
24001
|
+
}
|
|
24002
|
+
}
|
|
24003
|
+
});
|
|
24004
|
+
this.#settings = new CodexSettings(this.#appServer, options.environment);
|
|
24005
|
+
this.terminated = this.#appServer.terminated;
|
|
24006
|
+
void this.terminated.then((termination) => {
|
|
24007
|
+
this.#turn?.completion.reject(acpEndpointTerminationError(termination));
|
|
24008
|
+
if (termination.kind === "failed") {
|
|
24009
|
+
void this.close().catch((cause) => {
|
|
24010
|
+
console.error("The failed Codex endpoint could not release its process tree", cause);
|
|
24011
|
+
});
|
|
24012
|
+
}
|
|
24013
|
+
});
|
|
24014
|
+
this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
|
|
24015
|
+
this.#connection = connection;
|
|
24016
|
+
}).onRequest(methods.agent.initialize, async () => ({
|
|
24017
|
+
_meta: { steering: { supported: true } },
|
|
24018
|
+
agentCapabilities: {
|
|
24019
|
+
loadSession: true,
|
|
24020
|
+
promptCapabilities: { embeddedContext: true, image: true },
|
|
24021
|
+
sessionCapabilities: { close: {}, fork: {}, list: {} }
|
|
23798
24022
|
},
|
|
23799
24023
|
agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
|
|
23800
24024
|
authMethods: [],
|
|
@@ -23804,39 +24028,34 @@ var CodexAcpAgent = class {
|
|
|
23804
24028
|
await this.#appServer.request(
|
|
23805
24029
|
"thread/start",
|
|
23806
24030
|
{ cwd: context.params.cwd },
|
|
23807
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
24031
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
23808
24032
|
)
|
|
23809
24033
|
);
|
|
23810
24034
|
this.#nativeSessionId = created.thread.id;
|
|
23811
|
-
|
|
23812
|
-
this.#
|
|
23813
|
-
...this.#selection,
|
|
23814
|
-
collaborationMode: "default",
|
|
23815
|
-
...supported
|
|
23816
|
-
};
|
|
23817
|
-
this.#collaborationModeSelected = false;
|
|
23818
|
-
await this.#probeCollaborationMode(context.signal);
|
|
24035
|
+
this.#settings.selectNewThread(created);
|
|
24036
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
23819
24037
|
await this.#emitAvailableCommands();
|
|
23820
|
-
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
24038
|
+
return { configOptions: this.#settings.configOptions(), sessionId: created.thread.id };
|
|
23821
24039
|
}).onRequest(methods.agent.session.setConfigOption, async (context) => {
|
|
23822
|
-
this.#applySelection(context.params.configId, context.params.value);
|
|
23823
|
-
return { configOptions: this.#configOptions() };
|
|
24040
|
+
this.#settings.applySelection(context.params.configId, context.params.value);
|
|
24041
|
+
return { configOptions: this.#settings.configOptions() };
|
|
23824
24042
|
}).onRequest(methods.agent.session.setMode, async (context) => {
|
|
23825
|
-
this.#applySelection(
|
|
24043
|
+
this.#settings.applySelection("mode", context.params.modeId);
|
|
23826
24044
|
return {};
|
|
23827
24045
|
}).onRequest(methods.agent.session.load, async (context) => {
|
|
23828
24046
|
const resumed = threadResumeResponseSchema.parse(
|
|
23829
24047
|
await this.#appServer.request(
|
|
23830
24048
|
"thread/resume",
|
|
23831
24049
|
{ cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
|
|
23832
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
24050
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
23833
24051
|
)
|
|
23834
24052
|
);
|
|
23835
|
-
this.#
|
|
23836
|
-
|
|
24053
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
24054
|
+
this.#settings.selectRestoredThread(resumed);
|
|
24055
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
23837
24056
|
await this.#replayHistory(resumed.turns);
|
|
23838
24057
|
await this.#emitAvailableCommands();
|
|
23839
|
-
return { configOptions: this.#configOptions() };
|
|
24058
|
+
return { configOptions: this.#settings.configOptions() };
|
|
23840
24059
|
}).onRequest(methods.agent.session.fork, async (context) => {
|
|
23841
24060
|
const forked = threadForkResponseSchema.parse(
|
|
23842
24061
|
await this.#appServer.request(
|
|
@@ -23846,26 +24065,28 @@ var CodexAcpAgent = class {
|
|
|
23846
24065
|
excludeTurns: false,
|
|
23847
24066
|
threadId: context.params.sessionId
|
|
23848
24067
|
},
|
|
23849
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
24068
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
23850
24069
|
)
|
|
23851
24070
|
);
|
|
23852
|
-
this.#
|
|
23853
|
-
|
|
24071
|
+
this.#nativeSessionId = forked.thread.id;
|
|
24072
|
+
this.#settings.selectRestoredThread(forked);
|
|
24073
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
23854
24074
|
await this.#replayHistory(forked.turns);
|
|
23855
24075
|
await this.#emitAvailableCommands();
|
|
23856
|
-
return { configOptions: this.#configOptions(), sessionId: forked.thread.id };
|
|
24076
|
+
return { configOptions: this.#settings.configOptions(), sessionId: forked.thread.id };
|
|
23857
24077
|
}).onRequest(methods.agent.session.resume, async (context) => {
|
|
23858
24078
|
const resumed = threadResumeResponseSchema.parse(
|
|
23859
24079
|
await this.#appServer.request(
|
|
23860
24080
|
"thread/resume",
|
|
23861
24081
|
{ cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
|
|
23862
|
-
AbortSignal.any([context.signal, AbortSignal.timeout(
|
|
24082
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
23863
24083
|
)
|
|
23864
24084
|
);
|
|
23865
|
-
this.#
|
|
23866
|
-
|
|
24085
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
24086
|
+
this.#settings.selectRestoredThread(resumed);
|
|
24087
|
+
await this.#settings.probeCollaborationMode(this.#nativeSessionId, context.signal);
|
|
23867
24088
|
await this.#emitAvailableCommands();
|
|
23868
|
-
return { configOptions: this.#configOptions() };
|
|
24089
|
+
return { configOptions: this.#settings.configOptions() };
|
|
23869
24090
|
}).onRequest(methods.agent.session.prompt, async (context) => {
|
|
23870
24091
|
if (isCompactPrompt(context.params.prompt)) {
|
|
23871
24092
|
return await this.#compact(context.signal);
|
|
@@ -23905,7 +24126,7 @@ var CodexAcpAgent = class {
|
|
|
23905
24126
|
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
23906
24127
|
initialize = async (signal) => {
|
|
23907
24128
|
await this.#appServer.initialize(signal);
|
|
23908
|
-
await this.#loadModels(signal);
|
|
24129
|
+
await this.#settings.loadModels(signal);
|
|
23909
24130
|
};
|
|
23910
24131
|
/**
|
|
23911
24132
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
@@ -23931,84 +24152,6 @@ var CodexAcpAgent = class {
|
|
|
23931
24152
|
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
23932
24153
|
* turn lifecycle continues without settings rather than failing initialization.
|
|
23933
24154
|
*/
|
|
23934
|
-
#loadModels = async (signal) => {
|
|
23935
|
-
const models = [];
|
|
23936
|
-
let cursor = null;
|
|
23937
|
-
try {
|
|
23938
|
-
do {
|
|
23939
|
-
const decoded = modelListResponseSchema.parse(
|
|
23940
|
-
await this.#appServer.request(
|
|
23941
|
-
"model/list",
|
|
23942
|
-
{ cursor, limit: null },
|
|
23943
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
23944
|
-
)
|
|
23945
|
-
);
|
|
23946
|
-
models.push(...decoded.data);
|
|
23947
|
-
cursor = decoded.nextCursor ?? null;
|
|
23948
|
-
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
23949
|
-
} catch (error62) {
|
|
23950
|
-
signal.throwIfAborted();
|
|
23951
|
-
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
23952
|
-
`);
|
|
23953
|
-
}
|
|
23954
|
-
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
23955
|
-
};
|
|
23956
|
-
#model = (id) => this.#models.find((model) => model.id === id);
|
|
23957
|
-
/**
|
|
23958
|
-
* Learns, once per app-server, whether collaboration mode can be applied. An empty settings
|
|
23959
|
-
* update is a no-op on a supporting Codex; an older Codex answers an error, which costs the
|
|
23960
|
-
* Build/Plan selector alone without changing a restored thread's persisted mode.
|
|
23961
|
-
*/
|
|
23962
|
-
#probeCollaborationMode = async (signal) => {
|
|
23963
|
-
if (this.#collaborationModeSupported !== null) {
|
|
23964
|
-
return;
|
|
23965
|
-
}
|
|
23966
|
-
try {
|
|
23967
|
-
await this.#appServer.request(
|
|
23968
|
-
"thread/settings/update",
|
|
23969
|
-
{ threadId: this.#nativeSessionId },
|
|
23970
|
-
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
23971
|
-
);
|
|
23972
|
-
this.#collaborationModeSupported = true;
|
|
23973
|
-
} catch {
|
|
23974
|
-
signal.throwIfAborted();
|
|
23975
|
-
this.#collaborationModeSupported = false;
|
|
23976
|
-
}
|
|
23977
|
-
};
|
|
23978
|
-
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
23979
|
-
#configOptions = () => {
|
|
23980
|
-
const options = [];
|
|
23981
|
-
const model = modelSetting(this.#models, this.#selection.model);
|
|
23982
|
-
if (model !== null) {
|
|
23983
|
-
options.push(model);
|
|
23984
|
-
}
|
|
23985
|
-
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
23986
|
-
if (effort !== null) {
|
|
23987
|
-
options.push(effort);
|
|
23988
|
-
}
|
|
23989
|
-
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
23990
|
-
if (fastMode !== null) {
|
|
23991
|
-
options.push(fastMode);
|
|
23992
|
-
}
|
|
23993
|
-
if (this.#collaborationModeSupported === true) {
|
|
23994
|
-
options.push(collaborationModeSetting(this.#selection.collaborationMode));
|
|
23995
|
-
}
|
|
23996
|
-
options.push(modeSetting(this.#selection.mode));
|
|
23997
|
-
return options;
|
|
23998
|
-
};
|
|
23999
|
-
#selectRestoredThread = (thread) => {
|
|
24000
|
-
this.#nativeSessionId = thread.thread.id;
|
|
24001
|
-
const supported = supportedSelection(
|
|
24002
|
-
this.#models,
|
|
24003
|
-
thread.model ?? this.#selection.model,
|
|
24004
|
-
thread.reasoningEffort ?? this.#selection.effort
|
|
24005
|
-
);
|
|
24006
|
-
this.#selection = {
|
|
24007
|
-
...this.#selection,
|
|
24008
|
-
...supported,
|
|
24009
|
-
fastMode: thread.serviceTier === SERVICE_TIER_FAST
|
|
24010
|
-
};
|
|
24011
|
-
};
|
|
24012
24155
|
#replayHistory = async (turns) => {
|
|
24013
24156
|
for (const turn of turns ?? []) {
|
|
24014
24157
|
for (const rawItem of turn.items) {
|
|
@@ -24050,95 +24193,6 @@ var CodexAcpAgent = class {
|
|
|
24050
24193
|
}
|
|
24051
24194
|
}
|
|
24052
24195
|
};
|
|
24053
|
-
/**
|
|
24054
|
-
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
24055
|
-
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
24056
|
-
* so the reply never advertises an effort the selected model cannot run.
|
|
24057
|
-
*/
|
|
24058
|
-
#applySelection = (configId, value) => {
|
|
24059
|
-
if (configId === FAST_MODE_SETTING_ID) {
|
|
24060
|
-
if (typeof value !== "boolean") {
|
|
24061
|
-
throw new AcpExecutionError(
|
|
24062
|
-
"The requested Codex setting is invalid",
|
|
24063
|
-
{},
|
|
24064
|
-
"invalid_session_configuration"
|
|
24065
|
-
);
|
|
24066
|
-
}
|
|
24067
|
-
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
24068
|
-
throw new AcpExecutionError(
|
|
24069
|
-
"The selected Codex model has no fast mode",
|
|
24070
|
-
{},
|
|
24071
|
-
"invalid_session_configuration"
|
|
24072
|
-
);
|
|
24073
|
-
}
|
|
24074
|
-
this.#selection = { ...this.#selection, fastMode: value };
|
|
24075
|
-
return;
|
|
24076
|
-
}
|
|
24077
|
-
if (typeof value !== "string") {
|
|
24078
|
-
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
24079
|
-
}
|
|
24080
|
-
if (configId === MODE_SETTING_ID) {
|
|
24081
|
-
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
24082
|
-
throw new AcpExecutionError(
|
|
24083
|
-
"The requested Codex mode is unavailable",
|
|
24084
|
-
{},
|
|
24085
|
-
"invalid_session_configuration"
|
|
24086
|
-
);
|
|
24087
|
-
}
|
|
24088
|
-
this.#selection = { ...this.#selection, mode: value };
|
|
24089
|
-
this.#policySelected = true;
|
|
24090
|
-
return;
|
|
24091
|
-
}
|
|
24092
|
-
if (configId === COLLABORATION_MODE_SETTING_ID) {
|
|
24093
|
-
if (!COLLABORATION_MODES.some((mode) => mode.value === value)) {
|
|
24094
|
-
throw new AcpExecutionError(
|
|
24095
|
-
"The requested Codex collaboration mode is unavailable",
|
|
24096
|
-
{},
|
|
24097
|
-
"invalid_session_configuration"
|
|
24098
|
-
);
|
|
24099
|
-
}
|
|
24100
|
-
this.#selection = { ...this.#selection, collaborationMode: value };
|
|
24101
|
-
this.#collaborationModeSelected = true;
|
|
24102
|
-
return;
|
|
24103
|
-
}
|
|
24104
|
-
if (configId === MODEL_SETTING_ID) {
|
|
24105
|
-
if (value === this.#selection.model) {
|
|
24106
|
-
return;
|
|
24107
|
-
}
|
|
24108
|
-
const model = this.#model(value);
|
|
24109
|
-
if (model === void 0) {
|
|
24110
|
-
throw new AcpExecutionError(
|
|
24111
|
-
"The requested Codex model is unavailable",
|
|
24112
|
-
{},
|
|
24113
|
-
"invalid_session_configuration"
|
|
24114
|
-
);
|
|
24115
|
-
}
|
|
24116
|
-
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
24117
|
-
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
24118
|
-
this.#selection = {
|
|
24119
|
-
...this.#selection,
|
|
24120
|
-
effort,
|
|
24121
|
-
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
24122
|
-
model: value
|
|
24123
|
-
};
|
|
24124
|
-
return;
|
|
24125
|
-
}
|
|
24126
|
-
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
24127
|
-
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
24128
|
-
(option) => option.reasoningEffort
|
|
24129
|
-
);
|
|
24130
|
-
if (!supported.includes(value)) {
|
|
24131
|
-
throw new AcpExecutionError(
|
|
24132
|
-
"The requested Codex reasoning effort is unavailable",
|
|
24133
|
-
{},
|
|
24134
|
-
"invalid_session_configuration"
|
|
24135
|
-
);
|
|
24136
|
-
}
|
|
24137
|
-
this.#selection = { ...this.#selection, effort: value };
|
|
24138
|
-
return;
|
|
24139
|
-
}
|
|
24140
|
-
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
24141
|
-
};
|
|
24142
24196
|
#emit = async (update) => {
|
|
24143
24197
|
const connection = this.#connection;
|
|
24144
24198
|
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
@@ -24163,7 +24217,7 @@ var CodexAcpAgent = class {
|
|
|
24163
24217
|
}
|
|
24164
24218
|
await connection.client.notify(methods.client.session.update, {
|
|
24165
24219
|
sessionId: this.#nativeSessionId,
|
|
24166
|
-
update: { configOptions: this.#configOptions(), sessionUpdate: "config_option_update" }
|
|
24220
|
+
update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
|
|
24167
24221
|
});
|
|
24168
24222
|
};
|
|
24169
24223
|
// Notifications are serialized so two app-server items cannot interleave into one ACP update
|
|
@@ -24203,8 +24257,7 @@ var CodexAcpAgent = class {
|
|
|
24203
24257
|
const decoded = threadSettingsUpdatedSchema.safeParse(params);
|
|
24204
24258
|
if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
|
|
24205
24259
|
const mode = decoded.data.threadSettings.collaborationMode?.mode;
|
|
24206
|
-
if (
|
|
24207
|
-
this.#selection = { ...this.#selection, collaborationMode: mode };
|
|
24260
|
+
if (this.#settings.observeCollaborationMode(mode)) {
|
|
24208
24261
|
await this.#enqueue(async () => {
|
|
24209
24262
|
await this.#emitConfigOptionsUpdate();
|
|
24210
24263
|
});
|
|
@@ -24326,7 +24379,7 @@ var CodexAcpAgent = class {
|
|
|
24326
24379
|
const decision = await this.#askPermission(
|
|
24327
24380
|
title2,
|
|
24328
24381
|
params.itemId,
|
|
24329
|
-
AbortSignal.timeout(
|
|
24382
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
24330
24383
|
);
|
|
24331
24384
|
void turn;
|
|
24332
24385
|
this.#appServer.respond(request.id, { decision });
|
|
@@ -24348,7 +24401,7 @@ var CodexAcpAgent = class {
|
|
|
24348
24401
|
sessionId: this.#nativeSessionId,
|
|
24349
24402
|
...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
|
|
24350
24403
|
},
|
|
24351
|
-
{ cancellationSignal: AbortSignal.timeout(
|
|
24404
|
+
{ cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2) }
|
|
24352
24405
|
);
|
|
24353
24406
|
const content = response.action === "accept" ? Reflect.get(response, "content") : void 0;
|
|
24354
24407
|
const answers = {};
|
|
@@ -24366,7 +24419,7 @@ var CodexAcpAgent = class {
|
|
|
24366
24419
|
return;
|
|
24367
24420
|
}
|
|
24368
24421
|
const params = decoded.data;
|
|
24369
|
-
const signal = AbortSignal.timeout(
|
|
24422
|
+
const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2);
|
|
24370
24423
|
if (params.mode === "url" && params.url !== void 0) {
|
|
24371
24424
|
const response2 = await connection.client.request(
|
|
24372
24425
|
methods.client.elicitation.create,
|
|
@@ -24415,38 +24468,12 @@ var CodexAcpAgent = class {
|
|
|
24415
24468
|
this.#turn = turn;
|
|
24416
24469
|
this.#nativeTurnId = null;
|
|
24417
24470
|
try {
|
|
24418
|
-
const selection = this.#selection;
|
|
24419
|
-
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
24420
|
-
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
24421
24471
|
const started = turnSchema.parse(
|
|
24422
24472
|
(await this.#appServer.request(
|
|
24423
24473
|
"turn/start",
|
|
24424
24474
|
{
|
|
24425
|
-
|
|
24426
|
-
// policy, and those fields stay off the turn so the host's own setup is
|
|
24427
|
-
// inherited rather than overridden.
|
|
24428
|
-
...this.#policySelected ? {
|
|
24429
|
-
approvalPolicy: mode.approvalPolicy,
|
|
24430
|
-
approvalsReviewer: mode.approvalsReviewer,
|
|
24431
|
-
sandboxPolicy: mode.sandboxPolicy
|
|
24432
|
-
} : {},
|
|
24433
|
-
// The collaboration mode rides on the turn: Codex applies it to the
|
|
24434
|
-
// thread, where it persists until changed. "Build" is Codex's `default`
|
|
24435
|
-
// mode, so it is only sent once a choice exists to apply.
|
|
24436
|
-
...this.#collaborationModeSupported && (selection.collaborationMode !== "default" || this.#collaborationModeSelected) ? {
|
|
24437
|
-
collaborationMode: {
|
|
24438
|
-
mode: selection.collaborationMode,
|
|
24439
|
-
settings: {
|
|
24440
|
-
developer_instructions: null,
|
|
24441
|
-
model: selection.model,
|
|
24442
|
-
reasoning_effort: selection.effort.length === 0 ? null : selection.effort
|
|
24443
|
-
}
|
|
24444
|
-
}
|
|
24445
|
-
} : {},
|
|
24446
|
-
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
24475
|
+
...this.#settings.turnParameters(),
|
|
24447
24476
|
input: input2,
|
|
24448
|
-
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
24449
|
-
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
24450
24477
|
threadId: this.#nativeSessionId
|
|
24451
24478
|
},
|
|
24452
24479
|
signal
|
|
@@ -24515,7 +24542,7 @@ var CodexAcpAgent = class {
|
|
|
24515
24542
|
await this.#appServer.request(
|
|
24516
24543
|
"turn/steer",
|
|
24517
24544
|
{ expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
|
|
24518
|
-
AbortSignal.any([signal, AbortSignal.timeout(
|
|
24545
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
24519
24546
|
)
|
|
24520
24547
|
);
|
|
24521
24548
|
if (response.turnId !== active.turn.id) {
|
|
@@ -24534,7 +24561,7 @@ var CodexAcpAgent = class {
|
|
|
24534
24561
|
await this.#appServer.request(
|
|
24535
24562
|
"turn/interrupt",
|
|
24536
24563
|
{ threadId: this.#nativeSessionId, turnId: turn.turn.id },
|
|
24537
|
-
AbortSignal.timeout(
|
|
24564
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)
|
|
24538
24565
|
);
|
|
24539
24566
|
} catch {
|
|
24540
24567
|
}
|
|
@@ -27323,340 +27350,17 @@ var AgentConnection = class {
|
|
|
27323
27350
|
};
|
|
27324
27351
|
};
|
|
27325
27352
|
|
|
27326
|
-
// src/acp/
|
|
27327
|
-
var
|
|
27328
|
-
|
|
27329
|
-
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
|
|
27337
|
-
var nativeSessionPageSchema = external_exports.object({
|
|
27338
|
-
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
27339
|
-
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
27340
|
-
}).readonly();
|
|
27341
|
-
|
|
27342
|
-
// src/acp/agent-update-stream.ts
|
|
27343
|
-
var MAX_PENDING_UPDATES = 100;
|
|
27344
|
-
var MAX_PENDING_BYTES = 1024 * 1024;
|
|
27345
|
-
var AgentUpdateStream = class {
|
|
27346
|
-
#selection = { kind: "awaiting-session", notifications: [], bytes: 0 };
|
|
27347
|
-
#tail = Promise.resolve();
|
|
27348
|
-
#consume;
|
|
27349
|
-
constructor(consume) {
|
|
27350
|
-
this.#consume = consume;
|
|
27351
|
-
}
|
|
27352
|
-
sessionId = () => this.#selection.kind === "selected" ? this.#selection.sessionId : "";
|
|
27353
|
-
drained = () => this.#tail;
|
|
27354
|
-
#enqueue = (notification) => {
|
|
27355
|
-
this.#tail = this.#tail.then(async () => await this.#consume(notification));
|
|
27356
|
-
return this.#tail;
|
|
27357
|
-
};
|
|
27358
|
-
receive = (notification) => {
|
|
27359
|
-
const selection = this.#selection;
|
|
27360
|
-
switch (selection.kind) {
|
|
27361
|
-
case "selected":
|
|
27362
|
-
return this.#enqueue(notification);
|
|
27363
|
-
case "awaiting-session": {
|
|
27364
|
-
const bytes = selection.bytes + Buffer.byteLength(JSON.stringify(notification));
|
|
27365
|
-
if (selection.notifications.length >= MAX_PENDING_UPDATES || bytes > MAX_PENDING_BYTES) {
|
|
27366
|
-
return Promise.reject(
|
|
27367
|
-
new AcpExecutionError(
|
|
27368
|
-
"ACP agent sent too many updates before creating its session",
|
|
27369
|
-
{},
|
|
27370
|
-
"agent_update_limit"
|
|
27371
|
-
)
|
|
27372
|
-
);
|
|
27373
|
-
}
|
|
27374
|
-
this.#selection = {
|
|
27375
|
-
kind: "awaiting-session",
|
|
27376
|
-
notifications: [...selection.notifications, notification],
|
|
27377
|
-
bytes
|
|
27378
|
-
};
|
|
27379
|
-
return Promise.resolve();
|
|
27380
|
-
}
|
|
27381
|
-
}
|
|
27382
|
-
};
|
|
27383
|
-
select = (sessionId) => {
|
|
27384
|
-
const selected = nativeSessionIdSchema.parse(sessionId);
|
|
27385
|
-
const selection = this.#selection;
|
|
27386
|
-
switch (selection.kind) {
|
|
27387
|
-
case "selected":
|
|
27388
|
-
if (selection.sessionId !== selected) {
|
|
27389
|
-
throw new AcpExecutionError(
|
|
27390
|
-
"ACP agent attempted to replace the selected session",
|
|
27391
|
-
{},
|
|
27392
|
-
"invalid_agent_session"
|
|
27393
|
-
);
|
|
27394
|
-
}
|
|
27395
|
-
return;
|
|
27396
|
-
case "awaiting-session":
|
|
27397
|
-
this.#selection = { kind: "selected", sessionId: selected };
|
|
27398
|
-
for (const notification of selection.notifications) {
|
|
27399
|
-
void this.#enqueue(notification);
|
|
27400
|
-
}
|
|
27401
|
-
return;
|
|
27402
|
-
}
|
|
27403
|
-
};
|
|
27404
|
-
};
|
|
27405
|
-
|
|
27406
|
-
// src/acp/session-config/session-config-protocol.ts
|
|
27407
|
-
import { methods as methods7 } from "@agentclientprotocol/sdk";
|
|
27408
|
-
var MAXIMUM_CONFIG_OPTIONS = 100;
|
|
27409
|
-
var SessionConfigProtocolError = class extends Error {
|
|
27410
|
-
code = "invalid_session_configuration_response";
|
|
27411
|
-
constructor(message, options = {}) {
|
|
27412
|
-
super(message, options);
|
|
27413
|
-
this.name = "SessionConfigProtocolError";
|
|
27414
|
-
}
|
|
27415
|
-
};
|
|
27416
|
-
function isRecord7(value) {
|
|
27417
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27418
|
-
}
|
|
27419
|
-
function readString3(value, fallback = "") {
|
|
27420
|
-
return typeof value === "string" ? value : fallback;
|
|
27421
|
-
}
|
|
27422
|
-
function truncate4(value, maximum) {
|
|
27423
|
-
return value.length <= maximum ? value : value.slice(0, maximum);
|
|
27424
|
-
}
|
|
27425
|
-
function readBoolean(value, fallback = false) {
|
|
27426
|
-
return typeof value === "boolean" ? value : fallback;
|
|
27427
|
-
}
|
|
27428
|
-
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
27429
|
-
const value = option["value"];
|
|
27430
|
-
if (typeof value !== "string") {
|
|
27431
|
-
return void 0;
|
|
27432
|
-
}
|
|
27433
|
-
return {
|
|
27434
|
-
description: truncate4(readString3(option["description"]), 500),
|
|
27435
|
-
groupId: truncate4(groupId, 128),
|
|
27436
|
-
groupName: truncate4(groupName, 255),
|
|
27437
|
-
name: truncate4(readString3(option["name"], value), 255),
|
|
27438
|
-
value: truncate4(value, 500)
|
|
27439
|
-
};
|
|
27440
|
-
}
|
|
27441
|
-
function normalizeConfigValues(value) {
|
|
27442
|
-
if (!Array.isArray(value)) {
|
|
27443
|
-
return [];
|
|
27444
|
-
}
|
|
27445
|
-
const normalized = [];
|
|
27446
|
-
for (const entry of value) {
|
|
27447
|
-
if (!isRecord7(entry)) {
|
|
27448
|
-
continue;
|
|
27449
|
-
}
|
|
27450
|
-
const groupedOptions = entry["options"];
|
|
27451
|
-
if (Array.isArray(groupedOptions)) {
|
|
27452
|
-
const groupId = readString3(entry["group"]);
|
|
27453
|
-
const groupName = readString3(entry["name"]);
|
|
27454
|
-
for (const groupedOption of groupedOptions) {
|
|
27455
|
-
if (isRecord7(groupedOption)) {
|
|
27456
|
-
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
27457
|
-
if (normalizedValue !== void 0) {
|
|
27458
|
-
normalized.push(normalizedValue);
|
|
27459
|
-
}
|
|
27460
|
-
}
|
|
27461
|
-
}
|
|
27462
|
-
continue;
|
|
27463
|
-
}
|
|
27464
|
-
const normalizedEntry = normalizeConfigValue(entry);
|
|
27465
|
-
if (normalizedEntry !== void 0) {
|
|
27466
|
-
normalized.push(normalizedEntry);
|
|
27467
|
-
}
|
|
27468
|
-
}
|
|
27469
|
-
return normalized.slice(0, 500);
|
|
27470
|
-
}
|
|
27471
|
-
function normalizeConfigOptions(value, modes) {
|
|
27472
|
-
const normalized = [];
|
|
27473
|
-
if (Array.isArray(value)) {
|
|
27474
|
-
for (const option of value) {
|
|
27475
|
-
if (!isRecord7(option)) {
|
|
27476
|
-
continue;
|
|
27477
|
-
}
|
|
27478
|
-
const id = truncate4(readString3(option["id"]), 128);
|
|
27479
|
-
const name = truncate4(readString3(option["name"], id), 255);
|
|
27480
|
-
const category = truncate4(readString3(option["category"]), 128);
|
|
27481
|
-
if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
|
|
27482
|
-
continue;
|
|
27483
|
-
}
|
|
27484
|
-
if (option["type"] === "boolean") {
|
|
27485
|
-
normalized.push({
|
|
27486
|
-
booleanValue: readBoolean(option["currentValue"]),
|
|
27487
|
-
category,
|
|
27488
|
-
currentValue: "",
|
|
27489
|
-
description: truncate4(readString3(option["description"]), 500),
|
|
27490
|
-
id,
|
|
27491
|
-
name,
|
|
27492
|
-
type: "boolean",
|
|
27493
|
-
values: []
|
|
27494
|
-
});
|
|
27495
|
-
continue;
|
|
27496
|
-
}
|
|
27497
|
-
if (option["type"] === "select") {
|
|
27498
|
-
const values = normalizeConfigValues(option["options"]);
|
|
27499
|
-
const currentValue = truncate4(readString3(option["currentValue"]), 500);
|
|
27500
|
-
if (values.some((entry) => entry.value === currentValue)) {
|
|
27501
|
-
normalized.push({
|
|
27502
|
-
booleanValue: false,
|
|
27503
|
-
category,
|
|
27504
|
-
currentValue,
|
|
27505
|
-
description: truncate4(readString3(option["description"]), 500),
|
|
27506
|
-
id,
|
|
27507
|
-
name,
|
|
27508
|
-
type: "select",
|
|
27509
|
-
values
|
|
27510
|
-
});
|
|
27511
|
-
}
|
|
27512
|
-
}
|
|
27513
|
-
}
|
|
27514
|
-
}
|
|
27515
|
-
if (isRecord7(modes)) {
|
|
27516
|
-
const values = [];
|
|
27517
|
-
const availableModes = modes["availableModes"];
|
|
27518
|
-
if (Array.isArray(availableModes)) {
|
|
27519
|
-
for (const mode of availableModes) {
|
|
27520
|
-
if (!isRecord7(mode)) {
|
|
27521
|
-
continue;
|
|
27522
|
-
}
|
|
27523
|
-
const id = truncate4(readString3(mode["id"]), 500);
|
|
27524
|
-
if (id.length === 0) {
|
|
27525
|
-
continue;
|
|
27526
|
-
}
|
|
27527
|
-
values.push({
|
|
27528
|
-
description: truncate4(readString3(mode["description"]), 500),
|
|
27529
|
-
groupId: "",
|
|
27530
|
-
groupName: "",
|
|
27531
|
-
name: truncate4(readString3(mode["name"], id), 255),
|
|
27532
|
-
value: id
|
|
27533
|
-
});
|
|
27534
|
-
}
|
|
27535
|
-
}
|
|
27536
|
-
const currentValue = truncate4(readString3(modes["currentModeId"]), 500);
|
|
27537
|
-
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode")) {
|
|
27538
|
-
normalized.unshift({
|
|
27539
|
-
booleanValue: false,
|
|
27540
|
-
category: "mode",
|
|
27541
|
-
currentValue,
|
|
27542
|
-
description: "Agent session mode",
|
|
27543
|
-
id: "mode",
|
|
27544
|
-
name: "Mode",
|
|
27545
|
-
type: "select",
|
|
27546
|
-
values
|
|
27547
|
-
});
|
|
27548
|
-
}
|
|
27549
|
-
}
|
|
27550
|
-
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
27551
|
-
}
|
|
27552
|
-
function normalizeStandardLifecycle(response) {
|
|
27553
|
-
const lifecycle = isRecord7(response) ? response : {};
|
|
27554
|
-
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
27555
|
-
}
|
|
27556
|
-
function replaceStandardConfigOptions(current, value) {
|
|
27557
|
-
const next = normalizeConfigOptions(value, void 0);
|
|
27558
|
-
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
27559
|
-
return withMode;
|
|
27560
|
-
}
|
|
27561
|
-
function updateCurrentValue(current, configId, value) {
|
|
27562
|
-
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
27563
|
-
}
|
|
27564
|
-
var StandardSessionConfigProtocol = class {
|
|
27565
|
-
configure = async (current, change, nativeSessionId, transport) => {
|
|
27566
|
-
const existing = current.find((option) => option.id === change.configId);
|
|
27567
|
-
if (existing === void 0) {
|
|
27568
|
-
return current;
|
|
27569
|
-
}
|
|
27570
|
-
if (existing.type === "select" && existing.category === "mode") {
|
|
27571
|
-
await transport.request(
|
|
27572
|
-
methods7.agent.session.setMode,
|
|
27573
|
-
{ modeId: change.value, sessionId: nativeSessionId },
|
|
27574
|
-
"ACP agent exited while setting the session mode",
|
|
27575
|
-
change.signal
|
|
27576
|
-
);
|
|
27577
|
-
return updateCurrentValue(current, existing.id, change.value);
|
|
27578
|
-
}
|
|
27579
|
-
const params = existing.type === "boolean" ? {
|
|
27580
|
-
configId: existing.id,
|
|
27581
|
-
sessionId: nativeSessionId,
|
|
27582
|
-
type: "boolean",
|
|
27583
|
-
value: change.booleanValue
|
|
27584
|
-
} : {
|
|
27585
|
-
configId: existing.id,
|
|
27586
|
-
sessionId: nativeSessionId,
|
|
27587
|
-
value: change.value
|
|
27588
|
-
};
|
|
27589
|
-
const response = await transport.request(
|
|
27590
|
-
methods7.agent.session.setConfigOption,
|
|
27591
|
-
params,
|
|
27592
|
-
"ACP agent exited while changing session configuration",
|
|
27593
|
-
change.signal
|
|
27594
|
-
);
|
|
27595
|
-
if (!isRecord7(response) || !Array.isArray(response["configOptions"])) {
|
|
27596
|
-
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
27597
|
-
}
|
|
27598
|
-
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
27599
|
-
};
|
|
27600
|
-
normalizeLifecycle = (response) => normalizeStandardLifecycle(response);
|
|
27601
|
-
normalizeUpdate = (current, value) => replaceStandardConfigOptions(current, value);
|
|
27602
|
-
};
|
|
27603
|
-
var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
27604
|
-
|
|
27605
|
-
// src/acp/session-config/session-config-registry.ts
|
|
27606
|
-
function sessionConfigProtocolForAgent(_agentId) {
|
|
27607
|
-
return standardSessionConfigProtocol;
|
|
27608
|
-
}
|
|
27609
|
-
|
|
27610
|
-
// src/acp/session-contracts.ts
|
|
27611
|
-
var NullAcpSessionObserver = class {
|
|
27612
|
-
onCommands = () => Promise.resolve();
|
|
27613
|
-
onConfig = () => Promise.resolve();
|
|
27614
|
-
onContent = () => Promise.resolve();
|
|
27615
|
-
onElicitation = () => Promise.resolve();
|
|
27616
|
-
onElicitationResolved = () => Promise.resolve();
|
|
27617
|
-
onInfo = () => Promise.resolve();
|
|
27618
|
-
onPermission = () => Promise.resolve();
|
|
27619
|
-
onPermissionResolved = () => Promise.resolve();
|
|
27620
|
-
onUsage = () => Promise.resolve();
|
|
27621
|
-
};
|
|
27622
|
-
var AcpPreparedSession = class {
|
|
27623
|
-
agentName;
|
|
27624
|
-
agentVersion;
|
|
27625
|
-
capabilities;
|
|
27626
|
-
commands;
|
|
27627
|
-
configOptions;
|
|
27628
|
-
restored;
|
|
27629
|
-
constructor(agentName, agentVersion, capabilities, commands, configOptions, restored) {
|
|
27630
|
-
this.agentName = agentName;
|
|
27631
|
-
this.agentVersion = agentVersion;
|
|
27632
|
-
this.capabilities = capabilities;
|
|
27633
|
-
this.commands = commands;
|
|
27634
|
-
this.configOptions = configOptions;
|
|
27635
|
-
this.restored = restored;
|
|
27636
|
-
}
|
|
27637
|
-
};
|
|
27638
|
-
var AcpAgentSettingsSnapshot = class {
|
|
27639
|
-
agentName;
|
|
27640
|
-
agentVersion;
|
|
27641
|
-
configOptions;
|
|
27642
|
-
constructor(agentName, agentVersion, configOptions) {
|
|
27643
|
-
this.agentName = agentName;
|
|
27644
|
-
this.agentVersion = agentVersion;
|
|
27645
|
-
this.configOptions = configOptions;
|
|
27646
|
-
}
|
|
27647
|
-
};
|
|
27648
|
-
|
|
27649
|
-
// src/acp/activity.ts
|
|
27650
|
-
var AcpActivityNarration = class {
|
|
27651
|
-
activityId;
|
|
27652
|
-
activityType;
|
|
27653
|
-
sequence;
|
|
27654
|
-
text;
|
|
27655
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
27656
|
-
this.activityId = activityId;
|
|
27657
|
-
this.activityType = activityType;
|
|
27658
|
-
this.sequence = sequence;
|
|
27659
|
-
this.text = text2;
|
|
27353
|
+
// src/acp/activity.ts
|
|
27354
|
+
var AcpActivityNarration = class {
|
|
27355
|
+
activityId;
|
|
27356
|
+
activityType;
|
|
27357
|
+
sequence;
|
|
27358
|
+
text;
|
|
27359
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
27360
|
+
this.activityId = activityId;
|
|
27361
|
+
this.activityType = activityType;
|
|
27362
|
+
this.sequence = sequence;
|
|
27363
|
+
this.text = text2;
|
|
27660
27364
|
}
|
|
27661
27365
|
};
|
|
27662
27366
|
var AcpActivity = class _AcpActivity {
|
|
@@ -27886,79 +27590,455 @@ var AcpActivityTracker = class {
|
|
|
27886
27590
|
for (const key of this.#narrations.keys()) {
|
|
27887
27591
|
await this.#completeNarrative(key);
|
|
27888
27592
|
}
|
|
27889
|
-
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
27890
|
-
for (const [key, activity2] of entries) {
|
|
27891
|
-
const completed = activity2.complete();
|
|
27892
|
-
if (completed !== activity2) {
|
|
27893
|
-
await this.#record(key, completed);
|
|
27593
|
+
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
27594
|
+
for (const [key, activity2] of entries) {
|
|
27595
|
+
const completed = activity2.complete();
|
|
27596
|
+
if (completed !== activity2) {
|
|
27597
|
+
await this.#record(key, completed);
|
|
27598
|
+
}
|
|
27599
|
+
}
|
|
27600
|
+
};
|
|
27601
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
27602
|
+
// incremental events carried the text; this final event gives consumers the
|
|
27603
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
27604
|
+
#completeNarrative = async (key) => {
|
|
27605
|
+
const narration = this.#narrations.get(key);
|
|
27606
|
+
if (narration === void 0) {
|
|
27607
|
+
return;
|
|
27608
|
+
}
|
|
27609
|
+
this.#narrations.delete(key);
|
|
27610
|
+
const previous = this.#activities.get(key);
|
|
27611
|
+
const detail = narration.truncated ? {
|
|
27612
|
+
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
27613
|
+
kind: "truncated",
|
|
27614
|
+
originalBytes: narration.originalBytes
|
|
27615
|
+
} : captureActivityDetail([], "", narration.output);
|
|
27616
|
+
await this.#record(
|
|
27617
|
+
key,
|
|
27618
|
+
new AcpActivity(
|
|
27619
|
+
narration.activityId,
|
|
27620
|
+
narration.activityType,
|
|
27621
|
+
"",
|
|
27622
|
+
[],
|
|
27623
|
+
"",
|
|
27624
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27625
|
+
narration.sequence,
|
|
27626
|
+
"completed",
|
|
27627
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27628
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
27629
|
+
previous?.content ?? [],
|
|
27630
|
+
detail
|
|
27631
|
+
)
|
|
27632
|
+
);
|
|
27633
|
+
};
|
|
27634
|
+
#identity = (key) => {
|
|
27635
|
+
const existing = this.#identities.get(key);
|
|
27636
|
+
if (existing !== void 0) {
|
|
27637
|
+
return existing;
|
|
27638
|
+
}
|
|
27639
|
+
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
27640
|
+
this.#nextSequence += 1;
|
|
27641
|
+
this.#identities.set(key, identity2);
|
|
27642
|
+
return identity2;
|
|
27643
|
+
};
|
|
27644
|
+
#record = async (key, activity2) => {
|
|
27645
|
+
this.#activities.set(key, activity2);
|
|
27646
|
+
await this.#onActivity(activity2);
|
|
27647
|
+
};
|
|
27648
|
+
#recordPlanEntries = async (key, entries) => {
|
|
27649
|
+
const identity2 = this.#identity(key);
|
|
27650
|
+
await this.#record(
|
|
27651
|
+
key,
|
|
27652
|
+
new AcpActivity(
|
|
27653
|
+
identity2.id,
|
|
27654
|
+
"plan",
|
|
27655
|
+
"",
|
|
27656
|
+
[],
|
|
27657
|
+
"",
|
|
27658
|
+
formatPlanEntries(entries),
|
|
27659
|
+
identity2.sequence,
|
|
27660
|
+
planStatus(entries),
|
|
27661
|
+
"Plan",
|
|
27662
|
+
""
|
|
27663
|
+
)
|
|
27664
|
+
);
|
|
27665
|
+
};
|
|
27666
|
+
};
|
|
27667
|
+
|
|
27668
|
+
// src/acp/agent-turn.ts
|
|
27669
|
+
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
27670
|
+
var AcpTurnState = class {
|
|
27671
|
+
#bufferedText = [];
|
|
27672
|
+
bufferText = (text2, messageId) => {
|
|
27673
|
+
const previous = this.#bufferedText.at(-1);
|
|
27674
|
+
if (previous?.messageId === messageId) {
|
|
27675
|
+
previous.chunks.push(text2);
|
|
27676
|
+
} else {
|
|
27677
|
+
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
27678
|
+
}
|
|
27679
|
+
};
|
|
27680
|
+
flushText = async () => {
|
|
27681
|
+
const buffered = this.#bufferedText;
|
|
27682
|
+
this.#bufferedText = [];
|
|
27683
|
+
for (const message of buffered) {
|
|
27684
|
+
for (const chunk of message.chunks) {
|
|
27685
|
+
await this.onText(chunk, message.messageId);
|
|
27686
|
+
}
|
|
27687
|
+
}
|
|
27688
|
+
};
|
|
27689
|
+
recordTextAsProgress = async () => {
|
|
27690
|
+
const buffered = this.#bufferedText;
|
|
27691
|
+
this.#bufferedText = [];
|
|
27692
|
+
for (const message of buffered) {
|
|
27693
|
+
for (const chunk of message.chunks) {
|
|
27694
|
+
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
27695
|
+
}
|
|
27696
|
+
}
|
|
27697
|
+
};
|
|
27698
|
+
};
|
|
27699
|
+
var IdleAcpTurn = class extends AcpTurnState {
|
|
27700
|
+
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
27701
|
+
running = false;
|
|
27702
|
+
activities = new AcpActivityTracker(
|
|
27703
|
+
() => Promise.resolve(),
|
|
27704
|
+
() => Promise.resolve()
|
|
27705
|
+
);
|
|
27706
|
+
onText = () => Promise.resolve();
|
|
27707
|
+
};
|
|
27708
|
+
var RunningAcpTurn = class extends AcpTurnState {
|
|
27709
|
+
commandId;
|
|
27710
|
+
running = true;
|
|
27711
|
+
activities;
|
|
27712
|
+
onText;
|
|
27713
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
27714
|
+
super();
|
|
27715
|
+
this.commandId = commandId;
|
|
27716
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
27717
|
+
this.onText = onText;
|
|
27718
|
+
}
|
|
27719
|
+
};
|
|
27720
|
+
|
|
27721
|
+
// src/acp/native-session.ts
|
|
27722
|
+
var path = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
27723
|
+
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
27724
|
+
var nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
27725
|
+
var nativeSessionInfoSchema = external_exports.object({
|
|
27726
|
+
sessionId: nativeSessionIdSchema,
|
|
27727
|
+
cwd: path,
|
|
27728
|
+
additionalDirectories: external_exports.array(path).max(16).default([]).readonly(),
|
|
27729
|
+
title: title.nullish(),
|
|
27730
|
+
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
27731
|
+
}).readonly();
|
|
27732
|
+
var nativeSessionPageSchema = external_exports.object({
|
|
27733
|
+
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
27734
|
+
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
27735
|
+
}).readonly();
|
|
27736
|
+
|
|
27737
|
+
// src/acp/agent-update-stream.ts
|
|
27738
|
+
var MAX_PENDING_UPDATES = 100;
|
|
27739
|
+
var MAX_PENDING_BYTES = 1024 * 1024;
|
|
27740
|
+
var AgentUpdateStream = class {
|
|
27741
|
+
#selection = { kind: "awaiting-session", notifications: [], bytes: 0 };
|
|
27742
|
+
#tail = Promise.resolve();
|
|
27743
|
+
#consume;
|
|
27744
|
+
constructor(consume) {
|
|
27745
|
+
this.#consume = consume;
|
|
27746
|
+
}
|
|
27747
|
+
sessionId = () => this.#selection.kind === "selected" ? this.#selection.sessionId : "";
|
|
27748
|
+
drained = () => this.#tail;
|
|
27749
|
+
#enqueue = (notification) => {
|
|
27750
|
+
this.#tail = this.#tail.then(async () => await this.#consume(notification));
|
|
27751
|
+
return this.#tail;
|
|
27752
|
+
};
|
|
27753
|
+
receive = (notification) => {
|
|
27754
|
+
const selection = this.#selection;
|
|
27755
|
+
switch (selection.kind) {
|
|
27756
|
+
case "selected":
|
|
27757
|
+
return this.#enqueue(notification);
|
|
27758
|
+
case "awaiting-session": {
|
|
27759
|
+
const bytes = selection.bytes + Buffer.byteLength(JSON.stringify(notification));
|
|
27760
|
+
if (selection.notifications.length >= MAX_PENDING_UPDATES || bytes > MAX_PENDING_BYTES) {
|
|
27761
|
+
return Promise.reject(
|
|
27762
|
+
new AcpExecutionError(
|
|
27763
|
+
"ACP agent sent too many updates before creating its session",
|
|
27764
|
+
{},
|
|
27765
|
+
"agent_update_limit"
|
|
27766
|
+
)
|
|
27767
|
+
);
|
|
27768
|
+
}
|
|
27769
|
+
this.#selection = {
|
|
27770
|
+
kind: "awaiting-session",
|
|
27771
|
+
notifications: [...selection.notifications, notification],
|
|
27772
|
+
bytes
|
|
27773
|
+
};
|
|
27774
|
+
return Promise.resolve();
|
|
27775
|
+
}
|
|
27776
|
+
}
|
|
27777
|
+
};
|
|
27778
|
+
select = (sessionId) => {
|
|
27779
|
+
const selected = nativeSessionIdSchema.parse(sessionId);
|
|
27780
|
+
const selection = this.#selection;
|
|
27781
|
+
switch (selection.kind) {
|
|
27782
|
+
case "selected":
|
|
27783
|
+
if (selection.sessionId !== selected) {
|
|
27784
|
+
throw new AcpExecutionError(
|
|
27785
|
+
"ACP agent attempted to replace the selected session",
|
|
27786
|
+
{},
|
|
27787
|
+
"invalid_agent_session"
|
|
27788
|
+
);
|
|
27789
|
+
}
|
|
27790
|
+
return;
|
|
27791
|
+
case "awaiting-session":
|
|
27792
|
+
this.#selection = { kind: "selected", sessionId: selected };
|
|
27793
|
+
for (const notification of selection.notifications) {
|
|
27794
|
+
void this.#enqueue(notification);
|
|
27795
|
+
}
|
|
27796
|
+
return;
|
|
27797
|
+
}
|
|
27798
|
+
};
|
|
27799
|
+
};
|
|
27800
|
+
|
|
27801
|
+
// src/acp/session-config/session-config-protocol.ts
|
|
27802
|
+
import { methods as methods7 } from "@agentclientprotocol/sdk";
|
|
27803
|
+
var MAXIMUM_CONFIG_OPTIONS = 100;
|
|
27804
|
+
var SessionConfigProtocolError = class extends Error {
|
|
27805
|
+
code = "invalid_session_configuration_response";
|
|
27806
|
+
constructor(message, options = {}) {
|
|
27807
|
+
super(message, options);
|
|
27808
|
+
this.name = "SessionConfigProtocolError";
|
|
27809
|
+
}
|
|
27810
|
+
};
|
|
27811
|
+
function isRecord7(value) {
|
|
27812
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27813
|
+
}
|
|
27814
|
+
function readString3(value, fallback = "") {
|
|
27815
|
+
return typeof value === "string" ? value : fallback;
|
|
27816
|
+
}
|
|
27817
|
+
function truncate4(value, maximum) {
|
|
27818
|
+
return value.length <= maximum ? value : value.slice(0, maximum);
|
|
27819
|
+
}
|
|
27820
|
+
function readBoolean(value, fallback = false) {
|
|
27821
|
+
return typeof value === "boolean" ? value : fallback;
|
|
27822
|
+
}
|
|
27823
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
27824
|
+
const value = option["value"];
|
|
27825
|
+
if (typeof value !== "string") {
|
|
27826
|
+
return void 0;
|
|
27827
|
+
}
|
|
27828
|
+
return {
|
|
27829
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
27830
|
+
groupId: truncate4(groupId, 128),
|
|
27831
|
+
groupName: truncate4(groupName, 255),
|
|
27832
|
+
name: truncate4(readString3(option["name"], value), 255),
|
|
27833
|
+
value: truncate4(value, 500)
|
|
27834
|
+
};
|
|
27835
|
+
}
|
|
27836
|
+
function normalizeConfigValues(value) {
|
|
27837
|
+
if (!Array.isArray(value)) {
|
|
27838
|
+
return [];
|
|
27839
|
+
}
|
|
27840
|
+
const normalized = [];
|
|
27841
|
+
for (const entry of value) {
|
|
27842
|
+
if (!isRecord7(entry)) {
|
|
27843
|
+
continue;
|
|
27844
|
+
}
|
|
27845
|
+
const groupedOptions = entry["options"];
|
|
27846
|
+
if (Array.isArray(groupedOptions)) {
|
|
27847
|
+
const groupId = readString3(entry["group"]);
|
|
27848
|
+
const groupName = readString3(entry["name"]);
|
|
27849
|
+
for (const groupedOption of groupedOptions) {
|
|
27850
|
+
if (isRecord7(groupedOption)) {
|
|
27851
|
+
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
27852
|
+
if (normalizedValue !== void 0) {
|
|
27853
|
+
normalized.push(normalizedValue);
|
|
27854
|
+
}
|
|
27855
|
+
}
|
|
27856
|
+
}
|
|
27857
|
+
continue;
|
|
27858
|
+
}
|
|
27859
|
+
const normalizedEntry = normalizeConfigValue(entry);
|
|
27860
|
+
if (normalizedEntry !== void 0) {
|
|
27861
|
+
normalized.push(normalizedEntry);
|
|
27862
|
+
}
|
|
27863
|
+
}
|
|
27864
|
+
return normalized.slice(0, 500);
|
|
27865
|
+
}
|
|
27866
|
+
function normalizeConfigOptions(value, modes) {
|
|
27867
|
+
const normalized = [];
|
|
27868
|
+
if (Array.isArray(value)) {
|
|
27869
|
+
for (const option of value) {
|
|
27870
|
+
if (!isRecord7(option)) {
|
|
27871
|
+
continue;
|
|
27872
|
+
}
|
|
27873
|
+
const id = truncate4(readString3(option["id"]), 128);
|
|
27874
|
+
const name = truncate4(readString3(option["name"], id), 255);
|
|
27875
|
+
const category = truncate4(readString3(option["category"]), 128);
|
|
27876
|
+
if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
|
|
27877
|
+
continue;
|
|
27878
|
+
}
|
|
27879
|
+
if (option["type"] === "boolean") {
|
|
27880
|
+
normalized.push({
|
|
27881
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
27882
|
+
category,
|
|
27883
|
+
currentValue: "",
|
|
27884
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
27885
|
+
id,
|
|
27886
|
+
name,
|
|
27887
|
+
type: "boolean",
|
|
27888
|
+
values: []
|
|
27889
|
+
});
|
|
27890
|
+
continue;
|
|
27891
|
+
}
|
|
27892
|
+
if (option["type"] === "select") {
|
|
27893
|
+
const values = normalizeConfigValues(option["options"]);
|
|
27894
|
+
const currentValue = truncate4(readString3(option["currentValue"]), 500);
|
|
27895
|
+
if (values.some((entry) => entry.value === currentValue)) {
|
|
27896
|
+
normalized.push({
|
|
27897
|
+
booleanValue: false,
|
|
27898
|
+
category,
|
|
27899
|
+
currentValue,
|
|
27900
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
27901
|
+
id,
|
|
27902
|
+
name,
|
|
27903
|
+
type: "select",
|
|
27904
|
+
values
|
|
27905
|
+
});
|
|
27906
|
+
}
|
|
27907
|
+
}
|
|
27908
|
+
}
|
|
27909
|
+
}
|
|
27910
|
+
if (isRecord7(modes)) {
|
|
27911
|
+
const values = [];
|
|
27912
|
+
const availableModes = modes["availableModes"];
|
|
27913
|
+
if (Array.isArray(availableModes)) {
|
|
27914
|
+
for (const mode of availableModes) {
|
|
27915
|
+
if (!isRecord7(mode)) {
|
|
27916
|
+
continue;
|
|
27917
|
+
}
|
|
27918
|
+
const id = truncate4(readString3(mode["id"]), 500);
|
|
27919
|
+
if (id.length === 0) {
|
|
27920
|
+
continue;
|
|
27921
|
+
}
|
|
27922
|
+
values.push({
|
|
27923
|
+
description: truncate4(readString3(mode["description"]), 500),
|
|
27924
|
+
groupId: "",
|
|
27925
|
+
groupName: "",
|
|
27926
|
+
name: truncate4(readString3(mode["name"], id), 255),
|
|
27927
|
+
value: id
|
|
27928
|
+
});
|
|
27894
27929
|
}
|
|
27895
27930
|
}
|
|
27896
|
-
|
|
27897
|
-
|
|
27898
|
-
|
|
27899
|
-
|
|
27900
|
-
|
|
27901
|
-
|
|
27902
|
-
|
|
27903
|
-
|
|
27931
|
+
const currentValue = truncate4(readString3(modes["currentModeId"]), 500);
|
|
27932
|
+
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode")) {
|
|
27933
|
+
normalized.unshift({
|
|
27934
|
+
booleanValue: false,
|
|
27935
|
+
category: "mode",
|
|
27936
|
+
currentValue,
|
|
27937
|
+
description: "Agent session mode",
|
|
27938
|
+
id: "mode",
|
|
27939
|
+
name: "Mode",
|
|
27940
|
+
type: "select",
|
|
27941
|
+
values
|
|
27942
|
+
});
|
|
27904
27943
|
}
|
|
27905
|
-
|
|
27906
|
-
|
|
27907
|
-
|
|
27908
|
-
|
|
27909
|
-
|
|
27910
|
-
|
|
27911
|
-
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
|
|
27915
|
-
|
|
27916
|
-
|
|
27917
|
-
|
|
27918
|
-
|
|
27919
|
-
|
|
27920
|
-
|
|
27921
|
-
|
|
27922
|
-
|
|
27923
|
-
|
|
27924
|
-
|
|
27925
|
-
previous?.content ?? [],
|
|
27926
|
-
detail
|
|
27927
|
-
)
|
|
27928
|
-
);
|
|
27929
|
-
};
|
|
27930
|
-
#identity = (key) => {
|
|
27931
|
-
const existing = this.#identities.get(key);
|
|
27932
|
-
if (existing !== void 0) {
|
|
27933
|
-
return existing;
|
|
27944
|
+
}
|
|
27945
|
+
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
27946
|
+
}
|
|
27947
|
+
function normalizeStandardLifecycle(response) {
|
|
27948
|
+
const lifecycle = isRecord7(response) ? response : {};
|
|
27949
|
+
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
27950
|
+
}
|
|
27951
|
+
function replaceStandardConfigOptions(current, value) {
|
|
27952
|
+
const next = normalizeConfigOptions(value, void 0);
|
|
27953
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
27954
|
+
return withMode;
|
|
27955
|
+
}
|
|
27956
|
+
function updateCurrentValue(current, configId, value) {
|
|
27957
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
27958
|
+
}
|
|
27959
|
+
var StandardSessionConfigProtocol = class {
|
|
27960
|
+
configure = async (current, change, nativeSessionId, transport) => {
|
|
27961
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
27962
|
+
if (existing === void 0) {
|
|
27963
|
+
return current;
|
|
27934
27964
|
}
|
|
27935
|
-
|
|
27936
|
-
|
|
27937
|
-
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
27943
|
-
|
|
27944
|
-
|
|
27945
|
-
|
|
27946
|
-
|
|
27947
|
-
|
|
27948
|
-
|
|
27949
|
-
|
|
27950
|
-
|
|
27951
|
-
|
|
27952
|
-
|
|
27953
|
-
|
|
27954
|
-
|
|
27955
|
-
|
|
27956
|
-
|
|
27957
|
-
|
|
27958
|
-
|
|
27959
|
-
)
|
|
27965
|
+
if (existing.type === "select" && existing.category === "mode") {
|
|
27966
|
+
await transport.request(
|
|
27967
|
+
methods7.agent.session.setMode,
|
|
27968
|
+
{ modeId: change.value, sessionId: nativeSessionId },
|
|
27969
|
+
"ACP agent exited while setting the session mode",
|
|
27970
|
+
change.signal
|
|
27971
|
+
);
|
|
27972
|
+
return updateCurrentValue(current, existing.id, change.value);
|
|
27973
|
+
}
|
|
27974
|
+
const params = existing.type === "boolean" ? {
|
|
27975
|
+
configId: existing.id,
|
|
27976
|
+
sessionId: nativeSessionId,
|
|
27977
|
+
type: "boolean",
|
|
27978
|
+
value: change.booleanValue
|
|
27979
|
+
} : {
|
|
27980
|
+
configId: existing.id,
|
|
27981
|
+
sessionId: nativeSessionId,
|
|
27982
|
+
value: change.value
|
|
27983
|
+
};
|
|
27984
|
+
const response = await transport.request(
|
|
27985
|
+
methods7.agent.session.setConfigOption,
|
|
27986
|
+
params,
|
|
27987
|
+
"ACP agent exited while changing session configuration",
|
|
27988
|
+
change.signal
|
|
27960
27989
|
);
|
|
27990
|
+
if (!isRecord7(response) || !Array.isArray(response["configOptions"])) {
|
|
27991
|
+
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
27992
|
+
}
|
|
27993
|
+
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
27961
27994
|
};
|
|
27995
|
+
normalizeLifecycle = (response) => normalizeStandardLifecycle(response);
|
|
27996
|
+
normalizeUpdate = (current, value) => replaceStandardConfigOptions(current, value);
|
|
27997
|
+
};
|
|
27998
|
+
var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
27999
|
+
|
|
28000
|
+
// src/acp/session-config/session-config-registry.ts
|
|
28001
|
+
function sessionConfigProtocolForAgent(_agentId) {
|
|
28002
|
+
return standardSessionConfigProtocol;
|
|
28003
|
+
}
|
|
28004
|
+
|
|
28005
|
+
// src/acp/session-contracts.ts
|
|
28006
|
+
var NullAcpSessionObserver = class {
|
|
28007
|
+
onCommands = () => Promise.resolve();
|
|
28008
|
+
onConfig = () => Promise.resolve();
|
|
28009
|
+
onContent = () => Promise.resolve();
|
|
28010
|
+
onElicitation = () => Promise.resolve();
|
|
28011
|
+
onElicitationResolved = () => Promise.resolve();
|
|
28012
|
+
onInfo = () => Promise.resolve();
|
|
28013
|
+
onPermission = () => Promise.resolve();
|
|
28014
|
+
onPermissionResolved = () => Promise.resolve();
|
|
28015
|
+
onUsage = () => Promise.resolve();
|
|
28016
|
+
};
|
|
28017
|
+
var AcpPreparedSession = class {
|
|
28018
|
+
agentName;
|
|
28019
|
+
agentVersion;
|
|
28020
|
+
capabilities;
|
|
28021
|
+
commands;
|
|
28022
|
+
configOptions;
|
|
28023
|
+
restored;
|
|
28024
|
+
constructor(agentName, agentVersion, capabilities, commands, configOptions, restored) {
|
|
28025
|
+
this.agentName = agentName;
|
|
28026
|
+
this.agentVersion = agentVersion;
|
|
28027
|
+
this.capabilities = capabilities;
|
|
28028
|
+
this.commands = commands;
|
|
28029
|
+
this.configOptions = configOptions;
|
|
28030
|
+
this.restored = restored;
|
|
28031
|
+
}
|
|
28032
|
+
};
|
|
28033
|
+
var AcpAgentSettingsSnapshot = class {
|
|
28034
|
+
agentName;
|
|
28035
|
+
agentVersion;
|
|
28036
|
+
configOptions;
|
|
28037
|
+
constructor(agentName, agentVersion, configOptions) {
|
|
28038
|
+
this.agentName = agentName;
|
|
28039
|
+
this.agentVersion = agentVersion;
|
|
28040
|
+
this.configOptions = configOptions;
|
|
28041
|
+
}
|
|
27962
28042
|
};
|
|
27963
28043
|
|
|
27964
28044
|
// src/acp/session-history.ts
|
|
@@ -28393,31 +28473,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
28393
28473
|
return validated;
|
|
28394
28474
|
}
|
|
28395
28475
|
|
|
28396
|
-
// src/acp/
|
|
28397
|
-
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
28398
|
-
var AcpTurnState = class {
|
|
28399
|
-
};
|
|
28400
|
-
var IdleAcpTurn = class extends AcpTurnState {
|
|
28401
|
-
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
28402
|
-
running = false;
|
|
28403
|
-
activities = new AcpActivityTracker(
|
|
28404
|
-
() => Promise.resolve(),
|
|
28405
|
-
() => Promise.resolve()
|
|
28406
|
-
);
|
|
28407
|
-
onText = () => Promise.resolve();
|
|
28408
|
-
};
|
|
28409
|
-
var RunningAcpTurn = class extends AcpTurnState {
|
|
28410
|
-
commandId;
|
|
28411
|
-
running = true;
|
|
28412
|
-
activities;
|
|
28413
|
-
onText;
|
|
28414
|
-
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
28415
|
-
super();
|
|
28416
|
-
this.commandId = commandId;
|
|
28417
|
-
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
28418
|
-
this.onText = onText;
|
|
28419
|
-
}
|
|
28420
|
-
};
|
|
28476
|
+
// src/acp/pending-interactions.ts
|
|
28421
28477
|
var PendingPermission = class {
|
|
28422
28478
|
completion = Promise.withResolvers();
|
|
28423
28479
|
interactionId;
|
|
@@ -34368,7 +34424,6 @@ var AgentSession = class _AgentSession {
|
|
|
34368
34424
|
#verifiedAgentVersion;
|
|
34369
34425
|
#agentName = "";
|
|
34370
34426
|
#agentVersion = "";
|
|
34371
|
-
#bufferedAgentText = [];
|
|
34372
34427
|
#capabilities = unsupportedSessionCapabilities();
|
|
34373
34428
|
#commands = [];
|
|
34374
34429
|
#configRevision = 0;
|
|
@@ -34514,35 +34569,6 @@ var AgentSession = class _AgentSession {
|
|
|
34514
34569
|
this.#replay = { kind: "idle" };
|
|
34515
34570
|
}
|
|
34516
34571
|
};
|
|
34517
|
-
emitAgentMessage = async (chunks, messageId) => {
|
|
34518
|
-
for (const chunk of chunks) {
|
|
34519
|
-
await this.#turn.onText(chunk, messageId);
|
|
34520
|
-
}
|
|
34521
|
-
};
|
|
34522
|
-
bufferAgentText = async (text2, messageId) => {
|
|
34523
|
-
const previous = this.#bufferedAgentText.at(-1);
|
|
34524
|
-
if (previous?.messageId === messageId) {
|
|
34525
|
-
previous.chunks.push(text2);
|
|
34526
|
-
return;
|
|
34527
|
-
}
|
|
34528
|
-
this.#bufferedAgentText.push({ chunks: [text2], messageId });
|
|
34529
|
-
};
|
|
34530
|
-
flushAgentText = async () => {
|
|
34531
|
-
const buffered = this.#bufferedAgentText;
|
|
34532
|
-
this.#bufferedAgentText = [];
|
|
34533
|
-
for (const message of buffered) {
|
|
34534
|
-
await this.emitAgentMessage(message.chunks, message.messageId);
|
|
34535
|
-
}
|
|
34536
|
-
};
|
|
34537
|
-
recordBufferedAgentTextAsProgress = async () => {
|
|
34538
|
-
const buffered = this.#bufferedAgentText;
|
|
34539
|
-
this.#bufferedAgentText = [];
|
|
34540
|
-
for (const message of buffered) {
|
|
34541
|
-
for (const chunk of message.chunks) {
|
|
34542
|
-
await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
|
|
34543
|
-
}
|
|
34544
|
-
}
|
|
34545
|
-
};
|
|
34546
34572
|
prepareAgentContent = async (content) => {
|
|
34547
34573
|
if (content.type === "image" && content.uri.length > 0) {
|
|
34548
34574
|
const signal = AbortSignal.timeout(2e4);
|
|
@@ -35040,7 +35066,7 @@ var AgentSession = class _AgentSession {
|
|
|
35040
35066
|
options.signal
|
|
35041
35067
|
);
|
|
35042
35068
|
await this.#updates.drained();
|
|
35043
|
-
await this.
|
|
35069
|
+
await this.#turn.flushText();
|
|
35044
35070
|
await running.activities.finish();
|
|
35045
35071
|
let result;
|
|
35046
35072
|
try {
|
|
@@ -35072,7 +35098,6 @@ var AgentSession = class _AgentSession {
|
|
|
35072
35098
|
cause: error62
|
|
35073
35099
|
});
|
|
35074
35100
|
} finally {
|
|
35075
|
-
this.#bufferedAgentText = [];
|
|
35076
35101
|
this.#turn = new IdleAcpTurn();
|
|
35077
35102
|
}
|
|
35078
35103
|
};
|
|
@@ -35163,11 +35188,11 @@ var AgentSession = class _AgentSession {
|
|
|
35163
35188
|
);
|
|
35164
35189
|
} else {
|
|
35165
35190
|
await this.#turn.activities.finishNarrative();
|
|
35166
|
-
|
|
35191
|
+
this.#turn.bufferText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
35167
35192
|
}
|
|
35168
35193
|
} else {
|
|
35169
35194
|
await this.#turn.activities.finishNarrative();
|
|
35170
|
-
await this.
|
|
35195
|
+
await this.#turn.flushText();
|
|
35171
35196
|
await this.emitAgentContent(
|
|
35172
35197
|
normalizeContentBlock(update.content),
|
|
35173
35198
|
truncate3(update.messageId ?? "", 255)
|
|
@@ -35186,7 +35211,7 @@ var AgentSession = class _AgentSession {
|
|
|
35186
35211
|
return;
|
|
35187
35212
|
}
|
|
35188
35213
|
if (update.sessionUpdate === "tool_call") {
|
|
35189
|
-
await this.
|
|
35214
|
+
await this.#turn.recordTextAsProgress();
|
|
35190
35215
|
await this.#turn.activities.recordToolCall(update);
|
|
35191
35216
|
return;
|
|
35192
35217
|
}
|