@moxt-ai/mobius 0.0.94 → 0.0.96
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/elicitation.d.ts +5 -0
- package/dist/acp/elicitation.d.ts.map +1 -0
- package/dist/acp/elicitation.js +186 -0
- package/dist/acp/elicitation.js.map +1 -0
- package/dist/acp/process-capacity.d.ts +12 -0
- package/dist/acp/process-capacity.d.ts.map +1 -0
- package/dist/acp/process-capacity.js +90 -0
- package/dist/acp/process-capacity.js.map +1 -0
- package/dist/acp/process-session.d.ts +166 -0
- package/dist/acp/process-session.d.ts.map +1 -0
- package/dist/acp/process-session.js +1300 -0
- package/dist/acp/process-session.js.map +1 -0
- package/dist/acp/session-config/apply-session-configuration.d.ts +9 -0
- package/dist/acp/session-config/apply-session-configuration.d.ts.map +1 -0
- package/dist/acp/session-config/apply-session-configuration.js +141 -0
- package/dist/acp/session-config/apply-session-configuration.js.map +1 -0
- package/dist/acp/session-manager.d.ts +4 -159
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +8 -1578
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/acp/value-utils.d.ts +4 -0
- package/dist/acp/value-utils.d.ts.map +1 -0
- package/dist/acp/value-utils.js +10 -0
- package/dist/acp/value-utils.js.map +1 -0
- package/dist/agent-catalog/agent-settings-adapter.d.ts +5 -18
- package/dist/agent-catalog/agent-settings-adapter.d.ts.map +1 -1
- package/dist/agent-catalog/agent-settings-adapter.js +7 -161
- package/dist/agent-catalog/agent-settings-adapter.js.map +1 -1
- package/dist/agent-catalog/agent-settings-base.d.ts +26 -0
- package/dist/agent-catalog/agent-settings-base.d.ts.map +1 -0
- package/dist/agent-catalog/agent-settings-base.js +66 -0
- package/dist/agent-catalog/agent-settings-base.js.map +1 -0
- package/dist/agent-catalog/agents/codex-settings-adapter.d.ts +5 -0
- package/dist/agent-catalog/agents/codex-settings-adapter.d.ts.map +1 -0
- package/dist/agent-catalog/agents/codex-settings-adapter.js +6 -0
- package/dist/agent-catalog/agents/codex-settings-adapter.js.map +1 -0
- package/dist/agent-catalog/agents/deepseek-settings-adapter.d.ts +9 -0
- package/dist/agent-catalog/agents/deepseek-settings-adapter.d.ts.map +1 -0
- package/dist/agent-catalog/agents/deepseek-settings-adapter.js +26 -0
- package/dist/agent-catalog/agents/deepseek-settings-adapter.js.map +1 -0
- package/dist/agent-catalog/agents/opencode-settings-adapter.d.ts +9 -0
- package/dist/agent-catalog/agents/opencode-settings-adapter.d.ts.map +1 -0
- package/dist/agent-catalog/agents/opencode-settings-adapter.js +74 -0
- package/dist/agent-catalog/agents/opencode-settings-adapter.js.map +1 -0
- package/dist/agent-catalog/discover-agent-settings.d.ts +10 -0
- package/dist/agent-catalog/discover-agent-settings.d.ts.map +1 -0
- package/dist/agent-catalog/discover-agent-settings.js +252 -0
- package/dist/agent-catalog/discover-agent-settings.js.map +1 -0
- package/dist/cli.js +1236 -1168
- package/dist/cli.js.map +4 -4
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/index.js +2266 -2198
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/agent-adapter.d.ts +17 -0
- package/dist/native-sessions/agent-adapter.d.ts.map +1 -0
- package/dist/native-sessions/agent-adapter.js +22 -0
- package/dist/native-sessions/agent-adapter.js.map +1 -0
- package/dist/native-sessions/chat-agent.d.ts +3 -0
- package/dist/native-sessions/chat-agent.d.ts.map +1 -0
- package/dist/native-sessions/chat-agent.js +5 -0
- package/dist/native-sessions/chat-agent.js.map +1 -0
- package/dist/native-sessions/claude-adapter.d.ts +3 -0
- package/dist/native-sessions/claude-adapter.d.ts.map +1 -0
- package/dist/native-sessions/claude-adapter.js +7 -0
- package/dist/native-sessions/claude-adapter.js.map +1 -0
- package/dist/native-sessions/claude-history.d.ts +6 -0
- package/dist/native-sessions/claude-history.d.ts.map +1 -0
- package/dist/native-sessions/claude-history.js +27 -0
- package/dist/native-sessions/claude-history.js.map +1 -0
- package/dist/native-sessions/codex-adapter.d.ts +3 -0
- package/dist/native-sessions/codex-adapter.d.ts.map +1 -0
- package/dist/native-sessions/codex-adapter.js +21 -0
- package/dist/native-sessions/codex-adapter.js.map +1 -0
- package/dist/native-sessions/service.d.ts +0 -2
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +25 -58
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +4 -387
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +2583 -2515
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.96",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -28520,6 +28520,7 @@ var encodeAgentInstallCancelledEvent = (message) => encode3(message, agentInstal
|
|
|
28520
28520
|
|
|
28521
28521
|
// ../protocol/src/messages.ts
|
|
28522
28522
|
var SESSION_PROMPT_KIND = "session.prompt";
|
|
28523
|
+
var RUNTIME_WORKSPACE_BINDING_ID = "workspace";
|
|
28523
28524
|
var SESSION_CANCEL_KIND = "session.cancel";
|
|
28524
28525
|
var RUNTIME_LIVENESS_READY_KIND = "runtime.liveness.ready";
|
|
28525
28526
|
var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
|
|
@@ -29750,7 +29751,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
29750
29751
|
return {
|
|
29751
29752
|
agents: daemonAgents,
|
|
29752
29753
|
defaultWorkspace: connection.defaultWorkspace,
|
|
29753
|
-
bindingId:
|
|
29754
|
+
bindingId: RUNTIME_WORKSPACE_BINDING_ID,
|
|
29754
29755
|
catalog: new LocalAgentCatalog(daemonAgents, installableAgents),
|
|
29755
29756
|
channelId: connection.channelId,
|
|
29756
29757
|
installableAgents,
|
|
@@ -30724,12 +30725,420 @@ var AuditStore = class {
|
|
|
30724
30725
|
};
|
|
30725
30726
|
|
|
30726
30727
|
// src/run-daemon.ts
|
|
30727
|
-
import {
|
|
30728
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
30728
30729
|
import { basename as basename7 } from "node:path";
|
|
30729
30730
|
import { styleText } from "node:util";
|
|
30730
30731
|
import { fetch as fetch5, WebSocket as WebSocket2 } from "undici";
|
|
30731
30732
|
|
|
30732
|
-
// src/acp/session-
|
|
30733
|
+
// src/acp/session-config/apply-session-configuration.ts
|
|
30734
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
30735
|
+
|
|
30736
|
+
// src/agent-catalog/agent-settings-base.ts
|
|
30737
|
+
var AgentSettingsConfigurationError = class extends Error {
|
|
30738
|
+
code = "invalid_session_configuration";
|
|
30739
|
+
constructor(message, options = {}) {
|
|
30740
|
+
super(message, options);
|
|
30741
|
+
this.name = "AgentSettingsConfigurationError";
|
|
30742
|
+
}
|
|
30743
|
+
};
|
|
30744
|
+
var AgentSettingsLaunchSelectionResult = class {
|
|
30745
|
+
agent;
|
|
30746
|
+
handled;
|
|
30747
|
+
constructor(agent, handled) {
|
|
30748
|
+
this.agent = agent;
|
|
30749
|
+
this.handled = handled;
|
|
30750
|
+
}
|
|
30751
|
+
};
|
|
30752
|
+
var AppliedAgentLaunchSettings = class {
|
|
30753
|
+
agent;
|
|
30754
|
+
sessionConfigurations;
|
|
30755
|
+
constructor(agent, sessionConfigurations) {
|
|
30756
|
+
this.agent = agent;
|
|
30757
|
+
this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
|
|
30758
|
+
}
|
|
30759
|
+
};
|
|
30760
|
+
var AgentSettingsAdapter = class {
|
|
30761
|
+
modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION;
|
|
30762
|
+
applyLaunchSelection = (agent, _selection) => new AgentSettingsLaunchSelectionResult(agent, false);
|
|
30763
|
+
settings = (_agent) => [];
|
|
30764
|
+
};
|
|
30765
|
+
function selectValue(name, value, description) {
|
|
30766
|
+
return {
|
|
30767
|
+
description,
|
|
30768
|
+
groupId: "",
|
|
30769
|
+
groupName: "",
|
|
30770
|
+
name,
|
|
30771
|
+
value
|
|
30772
|
+
};
|
|
30773
|
+
}
|
|
30774
|
+
function selectSetting(id, name, description, currentValue, values) {
|
|
30775
|
+
return {
|
|
30776
|
+
booleanValue: false,
|
|
30777
|
+
category: "execution",
|
|
30778
|
+
currentValue,
|
|
30779
|
+
description,
|
|
30780
|
+
id,
|
|
30781
|
+
name,
|
|
30782
|
+
type: "select",
|
|
30783
|
+
values
|
|
30784
|
+
};
|
|
30785
|
+
}
|
|
30786
|
+
function selectedValue(selection, configId) {
|
|
30787
|
+
if (selection.configId !== configId || selection.valueType !== "select" || selection.booleanValue || selection.value.length === 0) {
|
|
30788
|
+
throw new AgentSettingsConfigurationError("The requested Agent setting is invalid");
|
|
30789
|
+
}
|
|
30790
|
+
return selection.value;
|
|
30791
|
+
}
|
|
30792
|
+
function validValue(values, value) {
|
|
30793
|
+
if (!values.some((candidate) => candidate.value === value)) {
|
|
30794
|
+
throw new AgentSettingsConfigurationError("The requested Agent setting is unavailable");
|
|
30795
|
+
}
|
|
30796
|
+
return value;
|
|
30797
|
+
}
|
|
30798
|
+
|
|
30799
|
+
// src/agent-catalog/agents/codex-settings-adapter.ts
|
|
30800
|
+
var CodexSettingsAdapter = class extends AgentSettingsAdapter {
|
|
30801
|
+
modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE;
|
|
30802
|
+
};
|
|
30803
|
+
|
|
30804
|
+
// src/agent-catalog/agents/deepseek-settings-adapter.ts
|
|
30805
|
+
var READ_ONLY_VALUE = "read-only";
|
|
30806
|
+
var WORKSPACE_WRITE_VALUE = "workspace-write";
|
|
30807
|
+
var DANGER_FULL_ACCESS_VALUE = "danger-full-access";
|
|
30808
|
+
var DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID = "dsh_access_mode";
|
|
30809
|
+
var dshAccessModes = Object.freeze([
|
|
30810
|
+
selectValue("Read only", READ_ONLY_VALUE, "Allow inspection without local writes."),
|
|
30811
|
+
selectValue("Workspace write", WORKSPACE_WRITE_VALUE, "Allow changes in the selected workspace."),
|
|
30812
|
+
selectValue("Full access", DANGER_FULL_ACCESS_VALUE, "Allow unrestricted local execution.")
|
|
30813
|
+
]);
|
|
30814
|
+
var DeepSeekHarnessSettingsAdapter = class extends AgentSettingsAdapter {
|
|
30815
|
+
settings = (agent) => {
|
|
30816
|
+
const configured = agent.environment["DSH_PERMISSION_MODE"] ?? WORKSPACE_WRITE_VALUE;
|
|
30817
|
+
return [
|
|
30818
|
+
selectSetting(
|
|
30819
|
+
DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID,
|
|
30820
|
+
"Access mode",
|
|
30821
|
+
"Controls the local side effects allowed for this DeepSeek Harness session.",
|
|
30822
|
+
validValue(dshAccessModes, configured),
|
|
30823
|
+
dshAccessModes
|
|
30824
|
+
)
|
|
30825
|
+
];
|
|
30826
|
+
};
|
|
30827
|
+
applyLaunchSelection = (agent, selection) => {
|
|
30828
|
+
if (selection.configId !== DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID) {
|
|
30829
|
+
return new AgentSettingsLaunchSelectionResult(agent, false);
|
|
30830
|
+
}
|
|
30831
|
+
const value = validValue(dshAccessModes, selectedValue(selection, DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID));
|
|
30832
|
+
return new AgentSettingsLaunchSelectionResult(
|
|
30833
|
+
agent.withEnvironment({ ...agent.environment, DSH_PERMISSION_MODE: value }),
|
|
30834
|
+
true
|
|
30835
|
+
);
|
|
30836
|
+
};
|
|
30837
|
+
};
|
|
30838
|
+
|
|
30839
|
+
// src/agent-catalog/agents/opencode-settings-adapter.ts
|
|
30840
|
+
var AGENT_DEFAULT_VALUE = "agent_default";
|
|
30841
|
+
var READ_ONLY_VALUE2 = "read-only";
|
|
30842
|
+
var WORKSPACE_WRITE_VALUE2 = "workspace-write";
|
|
30843
|
+
var DANGER_FULL_ACCESS_VALUE2 = "danger-full-access";
|
|
30844
|
+
var OPENCODE_PERMISSION_SETTING_ID = "opencode_permission";
|
|
30845
|
+
var openCodePermissionModes = Object.freeze([
|
|
30846
|
+
selectValue("Agent default", AGENT_DEFAULT_VALUE, "Keep OpenCode's existing permission policy."),
|
|
30847
|
+
selectValue("Read only", READ_ONLY_VALUE2, "Allow inspection without local writes."),
|
|
30848
|
+
selectValue("Workspace write", WORKSPACE_WRITE_VALUE2, "Allow changes in the selected workspace."),
|
|
30849
|
+
selectValue("Full access", DANGER_FULL_ACCESS_VALUE2, "Allow unrestricted local execution.")
|
|
30850
|
+
]);
|
|
30851
|
+
function openCodeConfiguration(environment) {
|
|
30852
|
+
const encoded = environment["OPENCODE_CONFIG_CONTENT"];
|
|
30853
|
+
if (encoded === void 0 || encoded.length === 0) {
|
|
30854
|
+
return {};
|
|
30855
|
+
}
|
|
30856
|
+
let parsed;
|
|
30857
|
+
try {
|
|
30858
|
+
parsed = JSON.parse(encoded);
|
|
30859
|
+
} catch (cause) {
|
|
30860
|
+
throw new AgentSettingsConfigurationError("The OpenCode configuration is invalid", { cause });
|
|
30861
|
+
}
|
|
30862
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
30863
|
+
throw new AgentSettingsConfigurationError("The OpenCode configuration is invalid");
|
|
30864
|
+
}
|
|
30865
|
+
return Object.freeze({ ...parsed });
|
|
30866
|
+
}
|
|
30867
|
+
function openCodePermission(value) {
|
|
30868
|
+
if (value === READ_ONLY_VALUE2) {
|
|
30869
|
+
return {
|
|
30870
|
+
"*": "deny",
|
|
30871
|
+
glob: "allow",
|
|
30872
|
+
grep: "allow",
|
|
30873
|
+
lsp: "allow",
|
|
30874
|
+
read: "allow",
|
|
30875
|
+
skill: "allow"
|
|
30876
|
+
};
|
|
30877
|
+
}
|
|
30878
|
+
if (value === WORKSPACE_WRITE_VALUE2) {
|
|
30879
|
+
return {
|
|
30880
|
+
"*": "allow",
|
|
30881
|
+
external_directory: "ask"
|
|
30882
|
+
};
|
|
30883
|
+
}
|
|
30884
|
+
return "allow";
|
|
30885
|
+
}
|
|
30886
|
+
var OpenCodeSettingsAdapter = class extends AgentSettingsAdapter {
|
|
30887
|
+
settings = (agent) => {
|
|
30888
|
+
const currentValue = agent.environment["MOBIUS_OPENCODE_PERMISSION"] ?? AGENT_DEFAULT_VALUE;
|
|
30889
|
+
return [
|
|
30890
|
+
selectSetting(
|
|
30891
|
+
OPENCODE_PERMISSION_SETTING_ID,
|
|
30892
|
+
"Permissions",
|
|
30893
|
+
"Controls OpenCode's local permission policy.",
|
|
30894
|
+
validValue(openCodePermissionModes, currentValue),
|
|
30895
|
+
openCodePermissionModes
|
|
30896
|
+
)
|
|
30897
|
+
];
|
|
30898
|
+
};
|
|
30899
|
+
applyLaunchSelection = (agent, selection) => {
|
|
30900
|
+
if (selection.configId !== OPENCODE_PERMISSION_SETTING_ID) {
|
|
30901
|
+
return new AgentSettingsLaunchSelectionResult(agent, false);
|
|
30902
|
+
}
|
|
30903
|
+
const value = validValue(openCodePermissionModes, selectedValue(selection, OPENCODE_PERMISSION_SETTING_ID));
|
|
30904
|
+
if (value === AGENT_DEFAULT_VALUE) {
|
|
30905
|
+
return new AgentSettingsLaunchSelectionResult(agent, true);
|
|
30906
|
+
}
|
|
30907
|
+
return new AgentSettingsLaunchSelectionResult(
|
|
30908
|
+
agent.withEnvironment({
|
|
30909
|
+
...agent.environment,
|
|
30910
|
+
MOBIUS_OPENCODE_PERMISSION: value,
|
|
30911
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify({
|
|
30912
|
+
...openCodeConfiguration(agent.environment),
|
|
30913
|
+
permission: openCodePermission(value)
|
|
30914
|
+
})
|
|
30915
|
+
}),
|
|
30916
|
+
true
|
|
30917
|
+
);
|
|
30918
|
+
};
|
|
30919
|
+
};
|
|
30920
|
+
|
|
30921
|
+
// src/agent-catalog/agent-settings-adapter.ts
|
|
30922
|
+
var genericAdapter = new AgentSettingsAdapter();
|
|
30923
|
+
var codexAdapter = new CodexSettingsAdapter();
|
|
30924
|
+
var deepSeekHarnessAdapter = new DeepSeekHarnessSettingsAdapter();
|
|
30925
|
+
var openCodeAdapter = new OpenCodeSettingsAdapter();
|
|
30926
|
+
function agentSettingsAdapterForAgent(agentId) {
|
|
30927
|
+
if (agentId === "codex") {
|
|
30928
|
+
return codexAdapter;
|
|
30929
|
+
}
|
|
30930
|
+
if (agentId === "deepseek-harness") {
|
|
30931
|
+
return deepSeekHarnessAdapter;
|
|
30932
|
+
}
|
|
30933
|
+
if (agentId === "opencode") {
|
|
30934
|
+
return openCodeAdapter;
|
|
30935
|
+
}
|
|
30936
|
+
return genericAdapter;
|
|
30937
|
+
}
|
|
30938
|
+
function applyAgentLaunchSettings(agent, selections) {
|
|
30939
|
+
const adapter = agentSettingsAdapterForAgent(agent.id);
|
|
30940
|
+
let selectedAgent = agent;
|
|
30941
|
+
const sessionConfigurations = [];
|
|
30942
|
+
for (const selection of selections) {
|
|
30943
|
+
const applied = adapter.applyLaunchSelection(selectedAgent, selection);
|
|
30944
|
+
selectedAgent = applied.agent;
|
|
30945
|
+
if (!applied.handled) {
|
|
30946
|
+
sessionConfigurations.push(selection);
|
|
30947
|
+
}
|
|
30948
|
+
}
|
|
30949
|
+
return new AppliedAgentLaunchSettings(selectedAgent, sessionConfigurations);
|
|
30950
|
+
}
|
|
30951
|
+
|
|
30952
|
+
// src/infra/operation-metrics.ts
|
|
30953
|
+
var AccumulatingOperationMetrics = class {
|
|
30954
|
+
#durations = /* @__PURE__ */ new Map();
|
|
30955
|
+
measure = async (name, operation) => {
|
|
30956
|
+
const startedAt = performance.now();
|
|
30957
|
+
try {
|
|
30958
|
+
return await operation();
|
|
30959
|
+
} finally {
|
|
30960
|
+
this.record(name, performance.now() - startedAt);
|
|
30961
|
+
}
|
|
30962
|
+
};
|
|
30963
|
+
measureSync = (name, operation) => {
|
|
30964
|
+
const startedAt = performance.now();
|
|
30965
|
+
try {
|
|
30966
|
+
return operation();
|
|
30967
|
+
} finally {
|
|
30968
|
+
this.record(name, performance.now() - startedAt);
|
|
30969
|
+
}
|
|
30970
|
+
};
|
|
30971
|
+
snapshot = () => Object.freeze(
|
|
30972
|
+
[...this.#durations].map(([name, durationMilliseconds]) => Object.freeze({ durationMilliseconds, name }))
|
|
30973
|
+
);
|
|
30974
|
+
record = (name, durationMilliseconds) => {
|
|
30975
|
+
this.#durations.set(
|
|
30976
|
+
name,
|
|
30977
|
+
Math.min(12e4, (this.#durations.get(name) ?? 0) + Math.max(0, durationMilliseconds))
|
|
30978
|
+
);
|
|
30979
|
+
};
|
|
30980
|
+
};
|
|
30981
|
+
var unmeasuredOperationMetrics = Object.freeze({
|
|
30982
|
+
measure: async (_name, operation) => await operation(),
|
|
30983
|
+
measureSync: (_name, operation) => operation(),
|
|
30984
|
+
snapshot: () => Object.freeze([])
|
|
30985
|
+
});
|
|
30986
|
+
|
|
30987
|
+
// src/native-sessions/chat-agent.ts
|
|
30988
|
+
function supportsNativeChat(agentId) {
|
|
30989
|
+
return agentId === "codex" || agentId === "claude";
|
|
30990
|
+
}
|
|
30991
|
+
|
|
30992
|
+
// src/acp/process-capacity.ts
|
|
30993
|
+
var AcpProcessCapacityLease = class {
|
|
30994
|
+
#releaseCapacity;
|
|
30995
|
+
#released = false;
|
|
30996
|
+
constructor(releaseCapacity) {
|
|
30997
|
+
this.#releaseCapacity = releaseCapacity;
|
|
30998
|
+
}
|
|
30999
|
+
release = () => {
|
|
31000
|
+
if (this.#released) {
|
|
31001
|
+
return;
|
|
31002
|
+
}
|
|
31003
|
+
this.#released = true;
|
|
31004
|
+
this.#releaseCapacity();
|
|
31005
|
+
};
|
|
31006
|
+
};
|
|
31007
|
+
var AcpProcessCapacityWaiter = class {
|
|
31008
|
+
completion = Promise.withResolvers();
|
|
31009
|
+
signal;
|
|
31010
|
+
constructor(signal) {
|
|
31011
|
+
this.signal = signal;
|
|
31012
|
+
}
|
|
31013
|
+
cancel = () => {
|
|
31014
|
+
try {
|
|
31015
|
+
this.signal.throwIfAborted();
|
|
31016
|
+
} catch (error62) {
|
|
31017
|
+
this.completion.reject(error62);
|
|
31018
|
+
}
|
|
31019
|
+
};
|
|
31020
|
+
};
|
|
31021
|
+
var AcpProcessCapacityLock = class {
|
|
31022
|
+
#locked = false;
|
|
31023
|
+
#waiters = [];
|
|
31024
|
+
acquire = async (signal) => {
|
|
31025
|
+
signal.throwIfAborted();
|
|
31026
|
+
if (!this.#locked) {
|
|
31027
|
+
this.#locked = true;
|
|
31028
|
+
return new AcpProcessCapacityLease(this.#release);
|
|
31029
|
+
}
|
|
31030
|
+
const waiter = new AcpProcessCapacityWaiter(signal);
|
|
31031
|
+
this.#waiters.push(waiter);
|
|
31032
|
+
signal.addEventListener("abort", waiter.cancel, { once: true });
|
|
31033
|
+
if (signal.aborted) {
|
|
31034
|
+
waiter.cancel();
|
|
31035
|
+
}
|
|
31036
|
+
try {
|
|
31037
|
+
return await waiter.completion.promise;
|
|
31038
|
+
} finally {
|
|
31039
|
+
signal.removeEventListener("abort", waiter.cancel);
|
|
31040
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
31041
|
+
if (index2 >= 0) {
|
|
31042
|
+
this.#waiters.splice(index2, 1);
|
|
31043
|
+
}
|
|
31044
|
+
}
|
|
31045
|
+
};
|
|
31046
|
+
#release = () => {
|
|
31047
|
+
while (this.#waiters.length > 0) {
|
|
31048
|
+
const waiter = this.#waiters.shift();
|
|
31049
|
+
if (waiter === void 0 || waiter.signal.aborted) {
|
|
31050
|
+
continue;
|
|
31051
|
+
}
|
|
31052
|
+
waiter.completion.resolve(new AcpProcessCapacityLease(this.#release));
|
|
31053
|
+
return;
|
|
31054
|
+
}
|
|
31055
|
+
this.#locked = false;
|
|
31056
|
+
};
|
|
31057
|
+
};
|
|
31058
|
+
async function waitForAcpProcessCapacity(completion, signal) {
|
|
31059
|
+
signal.throwIfAborted();
|
|
31060
|
+
const cancelled = Promise.withResolvers();
|
|
31061
|
+
const cancel = () => {
|
|
31062
|
+
try {
|
|
31063
|
+
signal.throwIfAborted();
|
|
31064
|
+
} catch (error62) {
|
|
31065
|
+
cancelled.reject(error62);
|
|
31066
|
+
}
|
|
31067
|
+
};
|
|
31068
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
31069
|
+
if (signal.aborted) {
|
|
31070
|
+
cancel();
|
|
31071
|
+
}
|
|
31072
|
+
try {
|
|
31073
|
+
await Promise.race([completion, cancelled.promise]);
|
|
31074
|
+
} finally {
|
|
31075
|
+
signal.removeEventListener("abort", cancel);
|
|
31076
|
+
}
|
|
31077
|
+
}
|
|
31078
|
+
|
|
31079
|
+
// src/acp/session-store.ts
|
|
31080
|
+
var AcpStoredSession = class {
|
|
31081
|
+
additionalDirectories;
|
|
31082
|
+
agentId;
|
|
31083
|
+
cwd;
|
|
31084
|
+
nativeSessionId;
|
|
31085
|
+
prompted;
|
|
31086
|
+
sessionId;
|
|
31087
|
+
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted) {
|
|
31088
|
+
this.additionalDirectories = [...additionalDirectories];
|
|
31089
|
+
this.agentId = agentId;
|
|
31090
|
+
this.cwd = cwd;
|
|
31091
|
+
this.nativeSessionId = nativeSessionId;
|
|
31092
|
+
this.prompted = prompted;
|
|
31093
|
+
this.sessionId = sessionId;
|
|
31094
|
+
}
|
|
31095
|
+
};
|
|
31096
|
+
var AcpStoredSessionLookup = class {
|
|
31097
|
+
};
|
|
31098
|
+
var MissingAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
31099
|
+
found = false;
|
|
31100
|
+
};
|
|
31101
|
+
var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
31102
|
+
found = true;
|
|
31103
|
+
session;
|
|
31104
|
+
constructor(session) {
|
|
31105
|
+
super();
|
|
31106
|
+
this.session = session;
|
|
31107
|
+
}
|
|
31108
|
+
};
|
|
31109
|
+
var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
31110
|
+
found = false;
|
|
31111
|
+
};
|
|
31112
|
+
var MemoryAcpSessionStore = class {
|
|
31113
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
31114
|
+
#deleted = /* @__PURE__ */ new Set();
|
|
31115
|
+
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
31116
|
+
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
31117
|
+
);
|
|
31118
|
+
markDeleted = (agentId, nativeSessionId) => {
|
|
31119
|
+
const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
|
|
31120
|
+
for (const id of ids) {
|
|
31121
|
+
this.#sessions.delete(id);
|
|
31122
|
+
this.#deleted.add(id);
|
|
31123
|
+
}
|
|
31124
|
+
return ids;
|
|
31125
|
+
};
|
|
31126
|
+
read = (sessionId) => {
|
|
31127
|
+
if (this.#deleted.has(sessionId)) {
|
|
31128
|
+
return new DeletedAcpStoredSession();
|
|
31129
|
+
}
|
|
31130
|
+
const session = this.#sessions.get(sessionId);
|
|
31131
|
+
return session === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(session);
|
|
31132
|
+
};
|
|
31133
|
+
remove = (sessionId) => {
|
|
31134
|
+
this.#sessions.delete(sessionId);
|
|
31135
|
+
};
|
|
31136
|
+
write = (session) => {
|
|
31137
|
+
this.#sessions.set(session.sessionId, session);
|
|
31138
|
+
};
|
|
31139
|
+
};
|
|
31140
|
+
|
|
31141
|
+
// src/acp/process-session.ts
|
|
30733
31142
|
import { spawn as spawn4 } from "node:child_process";
|
|
30734
31143
|
import {
|
|
30735
31144
|
methods as methods8,
|
|
@@ -30927,41 +31336,6 @@ function readInlineVideo(data, declaredMimeType, name = "Video") {
|
|
|
30927
31336
|
return new LocalVideo(basename3(name) || "Video", mimeType, bytes);
|
|
30928
31337
|
}
|
|
30929
31338
|
|
|
30930
|
-
// src/infra/operation-metrics.ts
|
|
30931
|
-
var AccumulatingOperationMetrics = class {
|
|
30932
|
-
#durations = /* @__PURE__ */ new Map();
|
|
30933
|
-
measure = async (name, operation) => {
|
|
30934
|
-
const startedAt = performance.now();
|
|
30935
|
-
try {
|
|
30936
|
-
return await operation();
|
|
30937
|
-
} finally {
|
|
30938
|
-
this.record(name, performance.now() - startedAt);
|
|
30939
|
-
}
|
|
30940
|
-
};
|
|
30941
|
-
measureSync = (name, operation) => {
|
|
30942
|
-
const startedAt = performance.now();
|
|
30943
|
-
try {
|
|
30944
|
-
return operation();
|
|
30945
|
-
} finally {
|
|
30946
|
-
this.record(name, performance.now() - startedAt);
|
|
30947
|
-
}
|
|
30948
|
-
};
|
|
30949
|
-
snapshot = () => Object.freeze(
|
|
30950
|
-
[...this.#durations].map(([name, durationMilliseconds]) => Object.freeze({ durationMilliseconds, name }))
|
|
30951
|
-
);
|
|
30952
|
-
record = (name, durationMilliseconds) => {
|
|
30953
|
-
this.#durations.set(
|
|
30954
|
-
name,
|
|
30955
|
-
Math.min(12e4, (this.#durations.get(name) ?? 0) + Math.max(0, durationMilliseconds))
|
|
30956
|
-
);
|
|
30957
|
-
};
|
|
30958
|
-
};
|
|
30959
|
-
var unmeasuredOperationMetrics = Object.freeze({
|
|
30960
|
-
measure: async (_name, operation) => await operation(),
|
|
30961
|
-
measureSync: (_name, operation) => operation(),
|
|
30962
|
-
snapshot: () => Object.freeze([])
|
|
30963
|
-
});
|
|
30964
|
-
|
|
30965
31339
|
// src/native-sessions/history-images.ts
|
|
30966
31340
|
var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
|
|
30967
31341
|
async function embedLocalHistoryImages(history, signal) {
|
|
@@ -31621,6 +31995,244 @@ var AcpActivityTracker = class {
|
|
|
31621
31995
|
};
|
|
31622
31996
|
};
|
|
31623
31997
|
|
|
31998
|
+
// src/acp/value-utils.ts
|
|
31999
|
+
function truncate3(value, maximumLength) {
|
|
32000
|
+
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
32001
|
+
}
|
|
32002
|
+
function isRecord8(value) {
|
|
32003
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32004
|
+
}
|
|
32005
|
+
function readString2(value, fallback = "") {
|
|
32006
|
+
return typeof value === "string" ? value : fallback;
|
|
32007
|
+
}
|
|
32008
|
+
|
|
32009
|
+
// src/acp/elicitation.ts
|
|
32010
|
+
function elicitationFieldType(value) {
|
|
32011
|
+
if (value === "boolean") {
|
|
32012
|
+
return "boolean";
|
|
32013
|
+
}
|
|
32014
|
+
if (value === "integer") {
|
|
32015
|
+
return "integer";
|
|
32016
|
+
}
|
|
32017
|
+
if (value === "number") {
|
|
32018
|
+
return "number";
|
|
32019
|
+
}
|
|
32020
|
+
if (value === "array") {
|
|
32021
|
+
return "multiselect";
|
|
32022
|
+
}
|
|
32023
|
+
return "string";
|
|
32024
|
+
}
|
|
32025
|
+
function normalizeElicitationOptions(schema) {
|
|
32026
|
+
const normalized = [];
|
|
32027
|
+
const oneOf = schema["oneOf"];
|
|
32028
|
+
if (Array.isArray(oneOf)) {
|
|
32029
|
+
for (const option of oneOf) {
|
|
32030
|
+
if (isRecord8(option) && typeof option["const"] === "string") {
|
|
32031
|
+
normalized.push({
|
|
32032
|
+
description: truncate3(readString2(option["description"]), 500),
|
|
32033
|
+
label: truncate3(readString2(option["title"], option["const"]), 255),
|
|
32034
|
+
value: truncate3(option["const"], 500)
|
|
32035
|
+
});
|
|
32036
|
+
}
|
|
32037
|
+
}
|
|
32038
|
+
return normalized.slice(0, 200);
|
|
32039
|
+
}
|
|
32040
|
+
const enumValues = schema["enum"];
|
|
32041
|
+
if (Array.isArray(enumValues)) {
|
|
32042
|
+
for (const entry of enumValues) {
|
|
32043
|
+
if (typeof entry === "string") {
|
|
32044
|
+
normalized.push({ description: "", label: entry, value: entry });
|
|
32045
|
+
}
|
|
32046
|
+
}
|
|
32047
|
+
return normalized.slice(0, 200);
|
|
32048
|
+
}
|
|
32049
|
+
const items = schema["items"];
|
|
32050
|
+
if (!isRecord8(items)) {
|
|
32051
|
+
return normalized;
|
|
32052
|
+
}
|
|
32053
|
+
const anyOf = items["anyOf"];
|
|
32054
|
+
if (Array.isArray(anyOf)) {
|
|
32055
|
+
return normalizeElicitationOptions({ oneOf: anyOf });
|
|
32056
|
+
}
|
|
32057
|
+
return normalizeElicitationOptions({ enum: items["enum"] });
|
|
32058
|
+
}
|
|
32059
|
+
function numericString(value) {
|
|
32060
|
+
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
32061
|
+
}
|
|
32062
|
+
function normalizeElicitationFields(requestedSchema) {
|
|
32063
|
+
if (!isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
|
|
32064
|
+
return [];
|
|
32065
|
+
}
|
|
32066
|
+
const properties = requestedSchema["properties"];
|
|
32067
|
+
const requiredValues = requestedSchema["required"];
|
|
32068
|
+
const required2 = new Set(
|
|
32069
|
+
Array.isArray(requiredValues) ? requiredValues.filter((entry) => typeof entry === "string") : []
|
|
32070
|
+
);
|
|
32071
|
+
const normalized = [];
|
|
32072
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
32073
|
+
if (!isRecord8(property)) {
|
|
32074
|
+
continue;
|
|
32075
|
+
}
|
|
32076
|
+
const type = elicitationFieldType(property["type"]);
|
|
32077
|
+
const options = normalizeElicitationOptions(property);
|
|
32078
|
+
const normalizedType = type === "string" && options.length > 0 ? "select" : type;
|
|
32079
|
+
const defaultValue = property["default"];
|
|
32080
|
+
normalized.push({
|
|
32081
|
+
defaultBooleanValue: typeof defaultValue === "boolean" ? defaultValue : false,
|
|
32082
|
+
defaultNumberValue: typeof defaultValue === "number" && Number.isFinite(defaultValue) ? defaultValue : 0,
|
|
32083
|
+
defaultStringValue: typeof defaultValue === "string" ? truncate3(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate3(JSON.stringify(defaultValue), 1e4) : "",
|
|
32084
|
+
description: truncate3(readString2(property["description"]), 500),
|
|
32085
|
+
format: truncate3(readString2(property["format"]), 64),
|
|
32086
|
+
hasDefaultValue: defaultValue !== void 0 && defaultValue !== null,
|
|
32087
|
+
maximum: numericString(property["maximum"]),
|
|
32088
|
+
maximumLength: numericString(property["maxLength"] ?? property["maxItems"]),
|
|
32089
|
+
minimum: numericString(property["minimum"]),
|
|
32090
|
+
minimumLength: numericString(property["minLength"] ?? property["minItems"]),
|
|
32091
|
+
name: truncate3(name, 128),
|
|
32092
|
+
options,
|
|
32093
|
+
pattern: truncate3(readString2(property["pattern"]), 500),
|
|
32094
|
+
required: required2.has(name),
|
|
32095
|
+
title: truncate3(readString2(property["title"], name), 255),
|
|
32096
|
+
type: normalizedType
|
|
32097
|
+
});
|
|
32098
|
+
}
|
|
32099
|
+
return normalized.slice(0, 100);
|
|
32100
|
+
}
|
|
32101
|
+
function validateStringValue(name, value, schema) {
|
|
32102
|
+
const minimum = schema["minLength"];
|
|
32103
|
+
const maximum = schema["maxLength"];
|
|
32104
|
+
if (typeof minimum === "number" && value.length < minimum) {
|
|
32105
|
+
throw new AcpExecutionError(
|
|
32106
|
+
`Elicitation field ${name} is shorter than allowed`,
|
|
32107
|
+
{},
|
|
32108
|
+
"invalid_elicitation_response"
|
|
32109
|
+
);
|
|
32110
|
+
}
|
|
32111
|
+
if (typeof maximum === "number" && value.length > maximum) {
|
|
32112
|
+
throw new AcpExecutionError(
|
|
32113
|
+
`Elicitation field ${name} is longer than allowed`,
|
|
32114
|
+
{},
|
|
32115
|
+
"invalid_elicitation_response"
|
|
32116
|
+
);
|
|
32117
|
+
}
|
|
32118
|
+
const pattern = schema["pattern"];
|
|
32119
|
+
if (typeof pattern === "string" && !new RegExp(pattern, "u").test(value)) {
|
|
32120
|
+
throw new AcpExecutionError(
|
|
32121
|
+
`Elicitation field ${name} does not match the required format`,
|
|
32122
|
+
{},
|
|
32123
|
+
"invalid_elicitation_response"
|
|
32124
|
+
);
|
|
32125
|
+
}
|
|
32126
|
+
const allowed = normalizeElicitationOptions(schema);
|
|
32127
|
+
if (allowed.length > 0 && !allowed.some((entry) => entry.value === value)) {
|
|
32128
|
+
throw new AcpExecutionError(
|
|
32129
|
+
`Elicitation field ${name} is not an allowed value`,
|
|
32130
|
+
{},
|
|
32131
|
+
"invalid_elicitation_response"
|
|
32132
|
+
);
|
|
32133
|
+
}
|
|
32134
|
+
}
|
|
32135
|
+
function validateNumericValue(name, value, schema, integer2) {
|
|
32136
|
+
if (!Number.isFinite(value) || integer2 && !Number.isInteger(value)) {
|
|
32137
|
+
throw new AcpExecutionError(
|
|
32138
|
+
`Elicitation field ${name} is not a valid number`,
|
|
32139
|
+
{},
|
|
32140
|
+
"invalid_elicitation_response"
|
|
32141
|
+
);
|
|
32142
|
+
}
|
|
32143
|
+
const minimum = schema["minimum"];
|
|
32144
|
+
const maximum = schema["maximum"];
|
|
32145
|
+
if (typeof minimum === "number" && value < minimum || typeof maximum === "number" && value > maximum) {
|
|
32146
|
+
throw new AcpExecutionError(
|
|
32147
|
+
`Elicitation field ${name} is outside the allowed range`,
|
|
32148
|
+
{},
|
|
32149
|
+
"invalid_elicitation_response"
|
|
32150
|
+
);
|
|
32151
|
+
}
|
|
32152
|
+
}
|
|
32153
|
+
function validateElicitationContent(encoded, requestedSchema) {
|
|
32154
|
+
let decoded;
|
|
32155
|
+
try {
|
|
32156
|
+
decoded = JSON.parse(encoded);
|
|
32157
|
+
} catch (error62) {
|
|
32158
|
+
throw new AcpExecutionError(
|
|
32159
|
+
"Elicitation response is not valid JSON",
|
|
32160
|
+
{ cause: error62 },
|
|
32161
|
+
"invalid_elicitation_response"
|
|
32162
|
+
);
|
|
32163
|
+
}
|
|
32164
|
+
if (!isRecord8(decoded) || !isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
|
|
32165
|
+
throw new AcpExecutionError(
|
|
32166
|
+
"Elicitation response does not match the requested form",
|
|
32167
|
+
{},
|
|
32168
|
+
"invalid_elicitation_response"
|
|
32169
|
+
);
|
|
32170
|
+
}
|
|
32171
|
+
const properties = requestedSchema["properties"];
|
|
32172
|
+
const requiredValue = requestedSchema["required"];
|
|
32173
|
+
const required2 = new Set(
|
|
32174
|
+
Array.isArray(requiredValue) ? requiredValue.filter((entry) => typeof entry === "string") : []
|
|
32175
|
+
);
|
|
32176
|
+
for (const name of required2) {
|
|
32177
|
+
if (!(name in decoded)) {
|
|
32178
|
+
throw new AcpExecutionError(`Elicitation field ${name} is required`, {}, "invalid_elicitation_response");
|
|
32179
|
+
}
|
|
32180
|
+
}
|
|
32181
|
+
const validated = {};
|
|
32182
|
+
for (const [name, value] of Object.entries(decoded)) {
|
|
32183
|
+
const property = properties[name];
|
|
32184
|
+
if (!isRecord8(property)) {
|
|
32185
|
+
throw new AcpExecutionError(
|
|
32186
|
+
`Elicitation field ${name} was not requested`,
|
|
32187
|
+
{},
|
|
32188
|
+
"invalid_elicitation_response"
|
|
32189
|
+
);
|
|
32190
|
+
}
|
|
32191
|
+
if (property["type"] === "string" && typeof value === "string") {
|
|
32192
|
+
validateStringValue(name, value, property);
|
|
32193
|
+
validated[name] = value;
|
|
32194
|
+
continue;
|
|
32195
|
+
}
|
|
32196
|
+
if (property["type"] === "number" && typeof value === "number") {
|
|
32197
|
+
validateNumericValue(name, value, property, false);
|
|
32198
|
+
validated[name] = value;
|
|
32199
|
+
continue;
|
|
32200
|
+
}
|
|
32201
|
+
if (property["type"] === "integer" && typeof value === "number") {
|
|
32202
|
+
validateNumericValue(name, value, property, true);
|
|
32203
|
+
validated[name] = value;
|
|
32204
|
+
continue;
|
|
32205
|
+
}
|
|
32206
|
+
if (property["type"] === "boolean" && typeof value === "boolean") {
|
|
32207
|
+
validated[name] = value;
|
|
32208
|
+
continue;
|
|
32209
|
+
}
|
|
32210
|
+
if (property["type"] === "array" && Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
32211
|
+
const minimum = property["minItems"];
|
|
32212
|
+
const maximum = property["maxItems"];
|
|
32213
|
+
if (typeof minimum === "number" && value.length < minimum || typeof maximum === "number" && value.length > maximum) {
|
|
32214
|
+
throw new AcpExecutionError(
|
|
32215
|
+
`Elicitation field ${name} has an invalid selection count`,
|
|
32216
|
+
{},
|
|
32217
|
+
"invalid_elicitation_response"
|
|
32218
|
+
);
|
|
32219
|
+
}
|
|
32220
|
+
const allowed = normalizeElicitationOptions(property);
|
|
32221
|
+
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
32222
|
+
throw new AcpExecutionError(
|
|
32223
|
+
`Elicitation field ${name} contains an invalid selection`,
|
|
32224
|
+
{},
|
|
32225
|
+
"invalid_elicitation_response"
|
|
32226
|
+
);
|
|
32227
|
+
}
|
|
32228
|
+
validated[name] = value;
|
|
32229
|
+
continue;
|
|
32230
|
+
}
|
|
32231
|
+
throw new AcpExecutionError(`Elicitation field ${name} has the wrong type`, {}, "invalid_elicitation_response");
|
|
32232
|
+
}
|
|
32233
|
+
return validated;
|
|
32234
|
+
}
|
|
32235
|
+
|
|
31624
32236
|
// ../../node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
|
|
31625
32237
|
var emptyOptions = {};
|
|
31626
32238
|
function toString(value, options) {
|
|
@@ -38832,13 +39444,13 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
38832
39444
|
this.name = "SessionConfigProtocolError";
|
|
38833
39445
|
}
|
|
38834
39446
|
};
|
|
38835
|
-
function
|
|
39447
|
+
function isRecord9(value) {
|
|
38836
39448
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38837
39449
|
}
|
|
38838
|
-
function
|
|
39450
|
+
function readString3(value, fallback = "") {
|
|
38839
39451
|
return typeof value === "string" ? value : fallback;
|
|
38840
39452
|
}
|
|
38841
|
-
function
|
|
39453
|
+
function truncate4(value, maximum) {
|
|
38842
39454
|
return value.length <= maximum ? value : value.slice(0, maximum);
|
|
38843
39455
|
}
|
|
38844
39456
|
function readBoolean(value, fallback = false) {
|
|
@@ -38850,11 +39462,11 @@ function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
|
38850
39462
|
return void 0;
|
|
38851
39463
|
}
|
|
38852
39464
|
return {
|
|
38853
|
-
description:
|
|
38854
|
-
groupId:
|
|
38855
|
-
groupName:
|
|
38856
|
-
name:
|
|
38857
|
-
value:
|
|
39465
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
39466
|
+
groupId: truncate4(groupId, 128),
|
|
39467
|
+
groupName: truncate4(groupName, 255),
|
|
39468
|
+
name: truncate4(readString3(option["name"], value), 255),
|
|
39469
|
+
value: truncate4(value, 500)
|
|
38858
39470
|
};
|
|
38859
39471
|
}
|
|
38860
39472
|
function normalizeConfigValues(value) {
|
|
@@ -38863,15 +39475,15 @@ function normalizeConfigValues(value) {
|
|
|
38863
39475
|
}
|
|
38864
39476
|
const normalized = [];
|
|
38865
39477
|
for (const entry of value) {
|
|
38866
|
-
if (!
|
|
39478
|
+
if (!isRecord9(entry)) {
|
|
38867
39479
|
continue;
|
|
38868
39480
|
}
|
|
38869
39481
|
const groupedOptions = entry["options"];
|
|
38870
39482
|
if (Array.isArray(groupedOptions)) {
|
|
38871
|
-
const groupId =
|
|
38872
|
-
const groupName =
|
|
39483
|
+
const groupId = readString3(entry["group"]);
|
|
39484
|
+
const groupName = readString3(entry["name"]);
|
|
38873
39485
|
for (const groupedOption of groupedOptions) {
|
|
38874
|
-
if (
|
|
39486
|
+
if (isRecord9(groupedOption)) {
|
|
38875
39487
|
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
38876
39488
|
if (normalizedValue !== void 0) {
|
|
38877
39489
|
normalized.push(normalizedValue);
|
|
@@ -38891,12 +39503,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
38891
39503
|
const normalized = [];
|
|
38892
39504
|
if (Array.isArray(value)) {
|
|
38893
39505
|
for (const option of value) {
|
|
38894
|
-
if (!
|
|
39506
|
+
if (!isRecord9(option)) {
|
|
38895
39507
|
continue;
|
|
38896
39508
|
}
|
|
38897
|
-
const id =
|
|
38898
|
-
const name =
|
|
38899
|
-
const category =
|
|
39509
|
+
const id = truncate4(readString3(option["id"]), 128);
|
|
39510
|
+
const name = truncate4(readString3(option["name"], id), 255);
|
|
39511
|
+
const category = truncate4(readString3(option["category"]), 128);
|
|
38900
39512
|
if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
|
|
38901
39513
|
continue;
|
|
38902
39514
|
}
|
|
@@ -38905,7 +39517,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
38905
39517
|
booleanValue: readBoolean(option["currentValue"]),
|
|
38906
39518
|
category,
|
|
38907
39519
|
currentValue: "",
|
|
38908
|
-
description:
|
|
39520
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
38909
39521
|
id,
|
|
38910
39522
|
name,
|
|
38911
39523
|
type: "boolean",
|
|
@@ -38915,13 +39527,13 @@ function normalizeConfigOptions(value, modes) {
|
|
|
38915
39527
|
}
|
|
38916
39528
|
if (option["type"] === "select") {
|
|
38917
39529
|
const values = normalizeConfigValues(option["options"]);
|
|
38918
|
-
const currentValue =
|
|
39530
|
+
const currentValue = truncate4(readString3(option["currentValue"]), 500);
|
|
38919
39531
|
if (values.some((entry) => entry.value === currentValue)) {
|
|
38920
39532
|
normalized.push({
|
|
38921
39533
|
booleanValue: false,
|
|
38922
39534
|
category,
|
|
38923
39535
|
currentValue,
|
|
38924
|
-
description:
|
|
39536
|
+
description: truncate4(readString3(option["description"]), 500),
|
|
38925
39537
|
id,
|
|
38926
39538
|
name,
|
|
38927
39539
|
type: "select",
|
|
@@ -38931,28 +39543,28 @@ function normalizeConfigOptions(value, modes) {
|
|
|
38931
39543
|
}
|
|
38932
39544
|
}
|
|
38933
39545
|
}
|
|
38934
|
-
if (
|
|
39546
|
+
if (isRecord9(modes)) {
|
|
38935
39547
|
const values = [];
|
|
38936
39548
|
const availableModes = modes["availableModes"];
|
|
38937
39549
|
if (Array.isArray(availableModes)) {
|
|
38938
39550
|
for (const mode of availableModes) {
|
|
38939
|
-
if (!
|
|
39551
|
+
if (!isRecord9(mode)) {
|
|
38940
39552
|
continue;
|
|
38941
39553
|
}
|
|
38942
|
-
const id =
|
|
39554
|
+
const id = truncate4(readString3(mode["id"]), 500);
|
|
38943
39555
|
if (id.length === 0) {
|
|
38944
39556
|
continue;
|
|
38945
39557
|
}
|
|
38946
39558
|
values.push({
|
|
38947
|
-
description:
|
|
39559
|
+
description: truncate4(readString3(mode["description"]), 500),
|
|
38948
39560
|
groupId: "",
|
|
38949
39561
|
groupName: "",
|
|
38950
|
-
name:
|
|
39562
|
+
name: truncate4(readString3(mode["name"], id), 255),
|
|
38951
39563
|
value: id
|
|
38952
39564
|
});
|
|
38953
39565
|
}
|
|
38954
39566
|
}
|
|
38955
|
-
const currentValue =
|
|
39567
|
+
const currentValue = truncate4(readString3(modes["currentModeId"]), 500);
|
|
38956
39568
|
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode")) {
|
|
38957
39569
|
normalized.unshift({
|
|
38958
39570
|
booleanValue: false,
|
|
@@ -38969,7 +39581,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
38969
39581
|
return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
38970
39582
|
}
|
|
38971
39583
|
function normalizeStandardLifecycle(response) {
|
|
38972
|
-
const lifecycle =
|
|
39584
|
+
const lifecycle = isRecord9(response) ? response : {};
|
|
38973
39585
|
return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
38974
39586
|
}
|
|
38975
39587
|
function replaceStandardConfigOptions(current, value) {
|
|
@@ -39011,7 +39623,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
39011
39623
|
"ACP agent exited while changing session configuration",
|
|
39012
39624
|
change.signal
|
|
39013
39625
|
);
|
|
39014
|
-
if (!
|
|
39626
|
+
if (!isRecord9(response) || !Array.isArray(response["configOptions"])) {
|
|
39015
39627
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
39016
39628
|
}
|
|
39017
39629
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -39231,75 +39843,11 @@ var AcpHistoryReplay = class {
|
|
|
39231
39843
|
};
|
|
39232
39844
|
};
|
|
39233
39845
|
|
|
39234
|
-
// src/acp/session
|
|
39235
|
-
var AcpStoredSession = class {
|
|
39236
|
-
additionalDirectories;
|
|
39237
|
-
agentId;
|
|
39238
|
-
cwd;
|
|
39239
|
-
nativeSessionId;
|
|
39240
|
-
prompted;
|
|
39241
|
-
sessionId;
|
|
39242
|
-
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted) {
|
|
39243
|
-
this.additionalDirectories = [...additionalDirectories];
|
|
39244
|
-
this.agentId = agentId;
|
|
39245
|
-
this.cwd = cwd;
|
|
39246
|
-
this.nativeSessionId = nativeSessionId;
|
|
39247
|
-
this.prompted = prompted;
|
|
39248
|
-
this.sessionId = sessionId;
|
|
39249
|
-
}
|
|
39250
|
-
};
|
|
39251
|
-
var AcpStoredSessionLookup = class {
|
|
39252
|
-
};
|
|
39253
|
-
var MissingAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
39254
|
-
found = false;
|
|
39255
|
-
};
|
|
39256
|
-
var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
39257
|
-
found = true;
|
|
39258
|
-
session;
|
|
39259
|
-
constructor(session) {
|
|
39260
|
-
super();
|
|
39261
|
-
this.session = session;
|
|
39262
|
-
}
|
|
39263
|
-
};
|
|
39264
|
-
var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
39265
|
-
found = false;
|
|
39266
|
-
};
|
|
39267
|
-
var MemoryAcpSessionStore = class {
|
|
39268
|
-
#sessions = /* @__PURE__ */ new Map();
|
|
39269
|
-
#deleted = /* @__PURE__ */ new Set();
|
|
39270
|
-
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
39271
|
-
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
39272
|
-
);
|
|
39273
|
-
markDeleted = (agentId, nativeSessionId) => {
|
|
39274
|
-
const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
|
|
39275
|
-
for (const id of ids) {
|
|
39276
|
-
this.#sessions.delete(id);
|
|
39277
|
-
this.#deleted.add(id);
|
|
39278
|
-
}
|
|
39279
|
-
return ids;
|
|
39280
|
-
};
|
|
39281
|
-
read = (sessionId) => {
|
|
39282
|
-
if (this.#deleted.has(sessionId)) {
|
|
39283
|
-
return new DeletedAcpStoredSession();
|
|
39284
|
-
}
|
|
39285
|
-
const session = this.#sessions.get(sessionId);
|
|
39286
|
-
return session === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(session);
|
|
39287
|
-
};
|
|
39288
|
-
remove = (sessionId) => {
|
|
39289
|
-
this.#sessions.delete(sessionId);
|
|
39290
|
-
};
|
|
39291
|
-
write = (session) => {
|
|
39292
|
-
this.#sessions.set(session.sessionId, session);
|
|
39293
|
-
};
|
|
39294
|
-
};
|
|
39295
|
-
|
|
39296
|
-
// src/acp/session-manager.ts
|
|
39846
|
+
// src/acp/process-session.ts
|
|
39297
39847
|
var PROCESS_STOP_TIMEOUT_MILLISECONDS = 1e3;
|
|
39298
|
-
var MAX_ACP_PROCESSES = 10;
|
|
39299
39848
|
var MAX_PRE_SESSION_UPDATES = 100;
|
|
39300
39849
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
39301
39850
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
39302
|
-
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
39303
39851
|
function nativeHistoryNotRetained() {
|
|
39304
39852
|
return {
|
|
39305
39853
|
cause: {
|
|
@@ -39352,91 +39900,6 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
39352
39900
|
this.name = "RetryableAcpInitializationError";
|
|
39353
39901
|
}
|
|
39354
39902
|
};
|
|
39355
|
-
var AcpProcessCapacityLease = class {
|
|
39356
|
-
#releaseCapacity;
|
|
39357
|
-
#released = false;
|
|
39358
|
-
constructor(releaseCapacity) {
|
|
39359
|
-
this.#releaseCapacity = releaseCapacity;
|
|
39360
|
-
}
|
|
39361
|
-
release = () => {
|
|
39362
|
-
if (this.#released) {
|
|
39363
|
-
return;
|
|
39364
|
-
}
|
|
39365
|
-
this.#released = true;
|
|
39366
|
-
this.#releaseCapacity();
|
|
39367
|
-
};
|
|
39368
|
-
};
|
|
39369
|
-
var AcpProcessCapacityWaiter = class {
|
|
39370
|
-
completion = Promise.withResolvers();
|
|
39371
|
-
signal;
|
|
39372
|
-
constructor(signal) {
|
|
39373
|
-
this.signal = signal;
|
|
39374
|
-
}
|
|
39375
|
-
cancel = () => {
|
|
39376
|
-
try {
|
|
39377
|
-
this.signal.throwIfAborted();
|
|
39378
|
-
} catch (error62) {
|
|
39379
|
-
this.completion.reject(error62);
|
|
39380
|
-
}
|
|
39381
|
-
};
|
|
39382
|
-
};
|
|
39383
|
-
var AcpProcessCapacityLock = class {
|
|
39384
|
-
#locked = false;
|
|
39385
|
-
#waiters = [];
|
|
39386
|
-
acquire = async (signal) => {
|
|
39387
|
-
signal.throwIfAborted();
|
|
39388
|
-
if (!this.#locked) {
|
|
39389
|
-
this.#locked = true;
|
|
39390
|
-
return new AcpProcessCapacityLease(this.#release);
|
|
39391
|
-
}
|
|
39392
|
-
const waiter = new AcpProcessCapacityWaiter(signal);
|
|
39393
|
-
this.#waiters.push(waiter);
|
|
39394
|
-
signal.addEventListener("abort", waiter.cancel, { once: true });
|
|
39395
|
-
if (signal.aborted) {
|
|
39396
|
-
waiter.cancel();
|
|
39397
|
-
}
|
|
39398
|
-
try {
|
|
39399
|
-
return await waiter.completion.promise;
|
|
39400
|
-
} finally {
|
|
39401
|
-
signal.removeEventListener("abort", waiter.cancel);
|
|
39402
|
-
const index2 = this.#waiters.indexOf(waiter);
|
|
39403
|
-
if (index2 >= 0) {
|
|
39404
|
-
this.#waiters.splice(index2, 1);
|
|
39405
|
-
}
|
|
39406
|
-
}
|
|
39407
|
-
};
|
|
39408
|
-
#release = () => {
|
|
39409
|
-
while (this.#waiters.length > 0) {
|
|
39410
|
-
const waiter = this.#waiters.shift();
|
|
39411
|
-
if (waiter === void 0 || waiter.signal.aborted) {
|
|
39412
|
-
continue;
|
|
39413
|
-
}
|
|
39414
|
-
waiter.completion.resolve(new AcpProcessCapacityLease(this.#release));
|
|
39415
|
-
return;
|
|
39416
|
-
}
|
|
39417
|
-
this.#locked = false;
|
|
39418
|
-
};
|
|
39419
|
-
};
|
|
39420
|
-
async function waitForAcpProcessCapacity(completion, signal) {
|
|
39421
|
-
signal.throwIfAborted();
|
|
39422
|
-
const cancelled = Promise.withResolvers();
|
|
39423
|
-
const cancel = () => {
|
|
39424
|
-
try {
|
|
39425
|
-
signal.throwIfAborted();
|
|
39426
|
-
} catch (error62) {
|
|
39427
|
-
cancelled.reject(error62);
|
|
39428
|
-
}
|
|
39429
|
-
};
|
|
39430
|
-
signal.addEventListener("abort", cancel, { once: true });
|
|
39431
|
-
if (signal.aborted) {
|
|
39432
|
-
cancel();
|
|
39433
|
-
}
|
|
39434
|
-
try {
|
|
39435
|
-
await Promise.race([completion, cancelled.promise]);
|
|
39436
|
-
} finally {
|
|
39437
|
-
signal.removeEventListener("abort", cancel);
|
|
39438
|
-
}
|
|
39439
|
-
}
|
|
39440
39903
|
function readableWebStream(input2) {
|
|
39441
39904
|
let streamOpen = true;
|
|
39442
39905
|
return new ReadableStream({
|
|
@@ -39512,15 +39975,6 @@ function createWritableAcpStream(output2) {
|
|
|
39512
39975
|
}
|
|
39513
39976
|
});
|
|
39514
39977
|
}
|
|
39515
|
-
function truncate4(value, maximumLength) {
|
|
39516
|
-
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
39517
|
-
}
|
|
39518
|
-
function isRecord9(value) {
|
|
39519
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39520
|
-
}
|
|
39521
|
-
function readString3(value, fallback = "") {
|
|
39522
|
-
return typeof value === "string" ? value : fallback;
|
|
39523
|
-
}
|
|
39524
39978
|
function arraysEqual(left, right) {
|
|
39525
39979
|
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
39526
39980
|
}
|
|
@@ -39529,231 +39983,6 @@ function recordsEqual(left, right) {
|
|
|
39529
39983
|
const rightEntries = Object.entries(right);
|
|
39530
39984
|
return leftEntries.length === rightEntries.length && leftEntries.every(([name, value]) => right[name] === value);
|
|
39531
39985
|
}
|
|
39532
|
-
function elicitationFieldType(value) {
|
|
39533
|
-
if (value === "boolean") {
|
|
39534
|
-
return "boolean";
|
|
39535
|
-
}
|
|
39536
|
-
if (value === "integer") {
|
|
39537
|
-
return "integer";
|
|
39538
|
-
}
|
|
39539
|
-
if (value === "number") {
|
|
39540
|
-
return "number";
|
|
39541
|
-
}
|
|
39542
|
-
if (value === "array") {
|
|
39543
|
-
return "multiselect";
|
|
39544
|
-
}
|
|
39545
|
-
return "string";
|
|
39546
|
-
}
|
|
39547
|
-
function normalizeElicitationOptions(schema) {
|
|
39548
|
-
const normalized = [];
|
|
39549
|
-
const oneOf = schema["oneOf"];
|
|
39550
|
-
if (Array.isArray(oneOf)) {
|
|
39551
|
-
for (const option of oneOf) {
|
|
39552
|
-
if (isRecord9(option) && typeof option["const"] === "string") {
|
|
39553
|
-
normalized.push({
|
|
39554
|
-
description: truncate4(readString3(option["description"]), 500),
|
|
39555
|
-
label: truncate4(readString3(option["title"], option["const"]), 255),
|
|
39556
|
-
value: truncate4(option["const"], 500)
|
|
39557
|
-
});
|
|
39558
|
-
}
|
|
39559
|
-
}
|
|
39560
|
-
return normalized.slice(0, 200);
|
|
39561
|
-
}
|
|
39562
|
-
const enumValues = schema["enum"];
|
|
39563
|
-
if (Array.isArray(enumValues)) {
|
|
39564
|
-
for (const entry of enumValues) {
|
|
39565
|
-
if (typeof entry === "string") {
|
|
39566
|
-
normalized.push({ description: "", label: entry, value: entry });
|
|
39567
|
-
}
|
|
39568
|
-
}
|
|
39569
|
-
return normalized.slice(0, 200);
|
|
39570
|
-
}
|
|
39571
|
-
const items = schema["items"];
|
|
39572
|
-
if (!isRecord9(items)) {
|
|
39573
|
-
return normalized;
|
|
39574
|
-
}
|
|
39575
|
-
const anyOf = items["anyOf"];
|
|
39576
|
-
if (Array.isArray(anyOf)) {
|
|
39577
|
-
return normalizeElicitationOptions({ oneOf: anyOf });
|
|
39578
|
-
}
|
|
39579
|
-
return normalizeElicitationOptions({ enum: items["enum"] });
|
|
39580
|
-
}
|
|
39581
|
-
function numericString(value) {
|
|
39582
|
-
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
39583
|
-
}
|
|
39584
|
-
function normalizeElicitationFields(requestedSchema) {
|
|
39585
|
-
if (!isRecord9(requestedSchema) || !isRecord9(requestedSchema["properties"])) {
|
|
39586
|
-
return [];
|
|
39587
|
-
}
|
|
39588
|
-
const properties = requestedSchema["properties"];
|
|
39589
|
-
const requiredValues = requestedSchema["required"];
|
|
39590
|
-
const required2 = new Set(
|
|
39591
|
-
Array.isArray(requiredValues) ? requiredValues.filter((entry) => typeof entry === "string") : []
|
|
39592
|
-
);
|
|
39593
|
-
const normalized = [];
|
|
39594
|
-
for (const [name, property] of Object.entries(properties)) {
|
|
39595
|
-
if (!isRecord9(property)) {
|
|
39596
|
-
continue;
|
|
39597
|
-
}
|
|
39598
|
-
const type = elicitationFieldType(property["type"]);
|
|
39599
|
-
const options = normalizeElicitationOptions(property);
|
|
39600
|
-
const normalizedType = type === "string" && options.length > 0 ? "select" : type;
|
|
39601
|
-
const defaultValue = property["default"];
|
|
39602
|
-
normalized.push({
|
|
39603
|
-
defaultBooleanValue: typeof defaultValue === "boolean" ? defaultValue : false,
|
|
39604
|
-
defaultNumberValue: typeof defaultValue === "number" && Number.isFinite(defaultValue) ? defaultValue : 0,
|
|
39605
|
-
defaultStringValue: typeof defaultValue === "string" ? truncate4(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate4(JSON.stringify(defaultValue), 1e4) : "",
|
|
39606
|
-
description: truncate4(readString3(property["description"]), 500),
|
|
39607
|
-
format: truncate4(readString3(property["format"]), 64),
|
|
39608
|
-
hasDefaultValue: defaultValue !== void 0 && defaultValue !== null,
|
|
39609
|
-
maximum: numericString(property["maximum"]),
|
|
39610
|
-
maximumLength: numericString(property["maxLength"] ?? property["maxItems"]),
|
|
39611
|
-
minimum: numericString(property["minimum"]),
|
|
39612
|
-
minimumLength: numericString(property["minLength"] ?? property["minItems"]),
|
|
39613
|
-
name: truncate4(name, 128),
|
|
39614
|
-
options,
|
|
39615
|
-
pattern: truncate4(readString3(property["pattern"]), 500),
|
|
39616
|
-
required: required2.has(name),
|
|
39617
|
-
title: truncate4(readString3(property["title"], name), 255),
|
|
39618
|
-
type: normalizedType
|
|
39619
|
-
});
|
|
39620
|
-
}
|
|
39621
|
-
return normalized.slice(0, 100);
|
|
39622
|
-
}
|
|
39623
|
-
function validateStringValue(name, value, schema) {
|
|
39624
|
-
const minimum = schema["minLength"];
|
|
39625
|
-
const maximum = schema["maxLength"];
|
|
39626
|
-
if (typeof minimum === "number" && value.length < minimum) {
|
|
39627
|
-
throw new AcpExecutionError(
|
|
39628
|
-
`Elicitation field ${name} is shorter than allowed`,
|
|
39629
|
-
{},
|
|
39630
|
-
"invalid_elicitation_response"
|
|
39631
|
-
);
|
|
39632
|
-
}
|
|
39633
|
-
if (typeof maximum === "number" && value.length > maximum) {
|
|
39634
|
-
throw new AcpExecutionError(
|
|
39635
|
-
`Elicitation field ${name} is longer than allowed`,
|
|
39636
|
-
{},
|
|
39637
|
-
"invalid_elicitation_response"
|
|
39638
|
-
);
|
|
39639
|
-
}
|
|
39640
|
-
const pattern = schema["pattern"];
|
|
39641
|
-
if (typeof pattern === "string" && !new RegExp(pattern, "u").test(value)) {
|
|
39642
|
-
throw new AcpExecutionError(
|
|
39643
|
-
`Elicitation field ${name} does not match the required format`,
|
|
39644
|
-
{},
|
|
39645
|
-
"invalid_elicitation_response"
|
|
39646
|
-
);
|
|
39647
|
-
}
|
|
39648
|
-
const allowed = normalizeElicitationOptions(schema);
|
|
39649
|
-
if (allowed.length > 0 && !allowed.some((entry) => entry.value === value)) {
|
|
39650
|
-
throw new AcpExecutionError(
|
|
39651
|
-
`Elicitation field ${name} is not an allowed value`,
|
|
39652
|
-
{},
|
|
39653
|
-
"invalid_elicitation_response"
|
|
39654
|
-
);
|
|
39655
|
-
}
|
|
39656
|
-
}
|
|
39657
|
-
function validateNumericValue(name, value, schema, integer2) {
|
|
39658
|
-
if (!Number.isFinite(value) || integer2 && !Number.isInteger(value)) {
|
|
39659
|
-
throw new AcpExecutionError(
|
|
39660
|
-
`Elicitation field ${name} is not a valid number`,
|
|
39661
|
-
{},
|
|
39662
|
-
"invalid_elicitation_response"
|
|
39663
|
-
);
|
|
39664
|
-
}
|
|
39665
|
-
const minimum = schema["minimum"];
|
|
39666
|
-
const maximum = schema["maximum"];
|
|
39667
|
-
if (typeof minimum === "number" && value < minimum || typeof maximum === "number" && value > maximum) {
|
|
39668
|
-
throw new AcpExecutionError(
|
|
39669
|
-
`Elicitation field ${name} is outside the allowed range`,
|
|
39670
|
-
{},
|
|
39671
|
-
"invalid_elicitation_response"
|
|
39672
|
-
);
|
|
39673
|
-
}
|
|
39674
|
-
}
|
|
39675
|
-
function validateElicitationContent(encoded, requestedSchema) {
|
|
39676
|
-
let decoded;
|
|
39677
|
-
try {
|
|
39678
|
-
decoded = JSON.parse(encoded);
|
|
39679
|
-
} catch (error62) {
|
|
39680
|
-
throw new AcpExecutionError(
|
|
39681
|
-
"Elicitation response is not valid JSON",
|
|
39682
|
-
{ cause: error62 },
|
|
39683
|
-
"invalid_elicitation_response"
|
|
39684
|
-
);
|
|
39685
|
-
}
|
|
39686
|
-
if (!isRecord9(decoded) || !isRecord9(requestedSchema) || !isRecord9(requestedSchema["properties"])) {
|
|
39687
|
-
throw new AcpExecutionError(
|
|
39688
|
-
"Elicitation response does not match the requested form",
|
|
39689
|
-
{},
|
|
39690
|
-
"invalid_elicitation_response"
|
|
39691
|
-
);
|
|
39692
|
-
}
|
|
39693
|
-
const properties = requestedSchema["properties"];
|
|
39694
|
-
const requiredValue = requestedSchema["required"];
|
|
39695
|
-
const required2 = new Set(
|
|
39696
|
-
Array.isArray(requiredValue) ? requiredValue.filter((entry) => typeof entry === "string") : []
|
|
39697
|
-
);
|
|
39698
|
-
for (const name of required2) {
|
|
39699
|
-
if (!(name in decoded)) {
|
|
39700
|
-
throw new AcpExecutionError(`Elicitation field ${name} is required`, {}, "invalid_elicitation_response");
|
|
39701
|
-
}
|
|
39702
|
-
}
|
|
39703
|
-
const validated = {};
|
|
39704
|
-
for (const [name, value] of Object.entries(decoded)) {
|
|
39705
|
-
const property = properties[name];
|
|
39706
|
-
if (!isRecord9(property)) {
|
|
39707
|
-
throw new AcpExecutionError(
|
|
39708
|
-
`Elicitation field ${name} was not requested`,
|
|
39709
|
-
{},
|
|
39710
|
-
"invalid_elicitation_response"
|
|
39711
|
-
);
|
|
39712
|
-
}
|
|
39713
|
-
if (property["type"] === "string" && typeof value === "string") {
|
|
39714
|
-
validateStringValue(name, value, property);
|
|
39715
|
-
validated[name] = value;
|
|
39716
|
-
continue;
|
|
39717
|
-
}
|
|
39718
|
-
if (property["type"] === "number" && typeof value === "number") {
|
|
39719
|
-
validateNumericValue(name, value, property, false);
|
|
39720
|
-
validated[name] = value;
|
|
39721
|
-
continue;
|
|
39722
|
-
}
|
|
39723
|
-
if (property["type"] === "integer" && typeof value === "number") {
|
|
39724
|
-
validateNumericValue(name, value, property, true);
|
|
39725
|
-
validated[name] = value;
|
|
39726
|
-
continue;
|
|
39727
|
-
}
|
|
39728
|
-
if (property["type"] === "boolean" && typeof value === "boolean") {
|
|
39729
|
-
validated[name] = value;
|
|
39730
|
-
continue;
|
|
39731
|
-
}
|
|
39732
|
-
if (property["type"] === "array" && Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
39733
|
-
const minimum = property["minItems"];
|
|
39734
|
-
const maximum = property["maxItems"];
|
|
39735
|
-
if (typeof minimum === "number" && value.length < minimum || typeof maximum === "number" && value.length > maximum) {
|
|
39736
|
-
throw new AcpExecutionError(
|
|
39737
|
-
`Elicitation field ${name} has an invalid selection count`,
|
|
39738
|
-
{},
|
|
39739
|
-
"invalid_elicitation_response"
|
|
39740
|
-
);
|
|
39741
|
-
}
|
|
39742
|
-
const allowed = normalizeElicitationOptions(property);
|
|
39743
|
-
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
39744
|
-
throw new AcpExecutionError(
|
|
39745
|
-
`Elicitation field ${name} contains an invalid selection`,
|
|
39746
|
-
{},
|
|
39747
|
-
"invalid_elicitation_response"
|
|
39748
|
-
);
|
|
39749
|
-
}
|
|
39750
|
-
validated[name] = value;
|
|
39751
|
-
continue;
|
|
39752
|
-
}
|
|
39753
|
-
throw new AcpExecutionError(`Elicitation field ${name} has the wrong type`, {}, "invalid_elicitation_response");
|
|
39754
|
-
}
|
|
39755
|
-
return validated;
|
|
39756
|
-
}
|
|
39757
39986
|
var AcpTurnState = class {
|
|
39758
39987
|
};
|
|
39759
39988
|
var IdleAcpTurn = class extends AcpTurnState {
|
|
@@ -40220,8 +40449,8 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40220
40449
|
);
|
|
40221
40450
|
}
|
|
40222
40451
|
this.#capabilities = normalizeAcpCapabilities(initialized);
|
|
40223
|
-
this.#agentName =
|
|
40224
|
-
this.#agentVersion =
|
|
40452
|
+
this.#agentName = truncate3(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? this.#agentId, 255);
|
|
40453
|
+
this.#agentVersion = truncate3(
|
|
40225
40454
|
this.#verifiedAgentVersion.length > 0 ? this.#verifiedAgentVersion : initialized.agentInfo?.version ?? "",
|
|
40226
40455
|
128
|
|
40227
40456
|
);
|
|
@@ -40455,7 +40684,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40455
40684
|
nativeSessionId = () => this.#nativeSessionId;
|
|
40456
40685
|
adoptNativeSessionId = (sessionId) => {
|
|
40457
40686
|
if (this.#prompted || this.#nativeSessionId !== sessionId) {
|
|
40458
|
-
throw new AcpExecutionError("The new
|
|
40687
|
+
throw new AcpExecutionError("The new native Session cannot be adopted", {}, "session_identity_mismatch");
|
|
40459
40688
|
}
|
|
40460
40689
|
const previousSessionId = this.#mobiusSessionId;
|
|
40461
40690
|
this.#store.write(
|
|
@@ -40668,7 +40897,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40668
40897
|
"ACP agent exited during steering",
|
|
40669
40898
|
options.signal
|
|
40670
40899
|
);
|
|
40671
|
-
if (!
|
|
40900
|
+
if (!isRecord8(response)) {
|
|
40672
40901
|
throw new AcpExecutionError(
|
|
40673
40902
|
"ACP agent returned an invalid steering response",
|
|
40674
40903
|
{},
|
|
@@ -40785,8 +41014,8 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40785
41014
|
const interactionId = `permission-${crypto.randomUUID()}`;
|
|
40786
41015
|
const options = request.options.slice(0, 20).map((option) => ({
|
|
40787
41016
|
kind: option.kind,
|
|
40788
|
-
name:
|
|
40789
|
-
optionId:
|
|
41017
|
+
name: truncate3(option.name, 255),
|
|
41018
|
+
optionId: truncate3(option.optionId, 255)
|
|
40790
41019
|
}));
|
|
40791
41020
|
if (options.length === 0) {
|
|
40792
41021
|
throw new AcpExecutionError(
|
|
@@ -40808,9 +41037,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40808
41037
|
kind: SESSION_PERMISSION_REQUESTED_KIND,
|
|
40809
41038
|
options,
|
|
40810
41039
|
sessionId: this.#mobiusSessionId,
|
|
40811
|
-
title:
|
|
40812
|
-
toolCallId:
|
|
40813
|
-
toolKind:
|
|
41040
|
+
title: truncate3(request.toolCall.title ?? "Permission required", 500),
|
|
41041
|
+
toolCallId: truncate3(request.toolCall.toolCallId, 255),
|
|
41042
|
+
toolKind: truncate3(request.toolCall.kind ?? "other", 64)
|
|
40814
41043
|
});
|
|
40815
41044
|
return await pending.completion.promise;
|
|
40816
41045
|
} finally {
|
|
@@ -40839,7 +41068,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40839
41068
|
const schemaValue = Reflect.get(request, "requestedSchema");
|
|
40840
41069
|
const requestedSchema = request.mode === "form" ? schemaValue : {};
|
|
40841
41070
|
const elicitationIdValue = Reflect.get(request, "elicitationId");
|
|
40842
|
-
const elicitationId = request.mode === "url" && typeof elicitationIdValue === "string" ?
|
|
41071
|
+
const elicitationId = request.mode === "url" && typeof elicitationIdValue === "string" ? truncate3(elicitationIdValue, 255) : "";
|
|
40843
41072
|
const pending = new PendingElicitation(interactionId, elicitationId, requestedSchema);
|
|
40844
41073
|
this.#pendingElicitations.set(interactionId, pending);
|
|
40845
41074
|
const abort = () => {
|
|
@@ -40854,10 +41083,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40854
41083
|
fields: normalizeElicitationFields(requestedSchema),
|
|
40855
41084
|
interactionId,
|
|
40856
41085
|
kind: SESSION_ELICITATION_REQUESTED_KIND,
|
|
40857
|
-
message:
|
|
41086
|
+
message: truncate3(request.message, 2e3),
|
|
40858
41087
|
mode: request.mode,
|
|
40859
41088
|
sessionId: this.#mobiusSessionId,
|
|
40860
|
-
url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ?
|
|
41089
|
+
url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate3(readString2(Reflect.get(request, "url")), 4096) : ""
|
|
40861
41090
|
});
|
|
40862
41091
|
return await pending.completion.promise;
|
|
40863
41092
|
} finally {
|
|
@@ -40935,14 +41164,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40935
41164
|
);
|
|
40936
41165
|
} else {
|
|
40937
41166
|
await this.#turn.activities.finishNarrative();
|
|
40938
|
-
await this.bufferAgentText(update.content.text,
|
|
41167
|
+
await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
40939
41168
|
}
|
|
40940
41169
|
} else {
|
|
40941
41170
|
await this.#turn.activities.finishNarrative();
|
|
40942
41171
|
await this.flushAgentText();
|
|
40943
41172
|
await this.emitAgentContent(
|
|
40944
41173
|
normalizeContentBlock(update.content),
|
|
40945
|
-
|
|
41174
|
+
truncate3(update.messageId ?? "", 255)
|
|
40946
41175
|
);
|
|
40947
41176
|
}
|
|
40948
41177
|
return;
|
|
@@ -40981,9 +41210,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
40981
41210
|
}
|
|
40982
41211
|
if (update.sessionUpdate === "available_commands_update") {
|
|
40983
41212
|
const commands = update.availableCommands.slice(0, 500).map((command) => ({
|
|
40984
|
-
description:
|
|
40985
|
-
inputHint:
|
|
40986
|
-
name:
|
|
41213
|
+
description: truncate3(command.description, 500),
|
|
41214
|
+
inputHint: truncate3(command.input?.hint ?? "", 255),
|
|
41215
|
+
name: truncate3(command.name, 128)
|
|
40987
41216
|
})).filter((command) => command.name.length > 0);
|
|
40988
41217
|
this.#commands = commands;
|
|
40989
41218
|
await this.#getObserver().onCommands({
|
|
@@ -41012,10 +41241,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
41012
41241
|
}
|
|
41013
41242
|
if (update.sessionUpdate === "session_info_update") {
|
|
41014
41243
|
if (Object.hasOwn(update, "title")) {
|
|
41015
|
-
this.#sessionTitle =
|
|
41244
|
+
this.#sessionTitle = truncate3(update.title ?? "", 500);
|
|
41016
41245
|
}
|
|
41017
41246
|
if (Object.hasOwn(update, "updatedAt")) {
|
|
41018
|
-
this.#sessionUpdatedAt =
|
|
41247
|
+
this.#sessionUpdatedAt = truncate3(update.updatedAt ?? "", 128);
|
|
41019
41248
|
}
|
|
41020
41249
|
await this.#getObserver().onInfo({
|
|
41021
41250
|
kind: SESSION_INFO_UPDATED_KIND,
|
|
@@ -41028,7 +41257,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
41028
41257
|
if (update.sessionUpdate === "usage_update") {
|
|
41029
41258
|
await this.#getObserver().onUsage({
|
|
41030
41259
|
costAmount: update.cost?.amount ?? 0,
|
|
41031
|
-
costCurrency:
|
|
41260
|
+
costCurrency: truncate3(update.cost?.currency ?? "", 16),
|
|
41032
41261
|
hasCost: update.cost !== void 0 && update.cost !== null,
|
|
41033
41262
|
kind: SESSION_USAGE_UPDATED_KIND,
|
|
41034
41263
|
sessionId: this.#mobiusSessionId,
|
|
@@ -41101,7 +41330,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
41101
41330
|
);
|
|
41102
41331
|
}
|
|
41103
41332
|
if (error62 instanceof RequestError3) {
|
|
41104
|
-
throw new AcpExecutionError(
|
|
41333
|
+
throw new AcpExecutionError(truncate3(error62.message, 500), { cause: error62 }, "acp_agent_error");
|
|
41105
41334
|
}
|
|
41106
41335
|
throw error62;
|
|
41107
41336
|
}
|
|
@@ -41170,6 +41399,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
41170
41399
|
}
|
|
41171
41400
|
};
|
|
41172
41401
|
};
|
|
41402
|
+
|
|
41403
|
+
// src/acp/session-manager.ts
|
|
41404
|
+
var MAX_ACP_PROCESSES = 10;
|
|
41405
|
+
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
41173
41406
|
var AcpProcessEvictionCandidate = class {
|
|
41174
41407
|
};
|
|
41175
41408
|
var MissingAcpProcessEvictionCandidate = class extends AcpProcessEvictionCandidate {
|
|
@@ -41489,7 +41722,7 @@ var AcpSessionManager = class {
|
|
|
41489
41722
|
return await this.#startRetainedSessionProcess(
|
|
41490
41723
|
options,
|
|
41491
41724
|
async () => await AcpProcessSession.start(
|
|
41492
|
-
this.#sessionIdentity === "native" && options.agent.id
|
|
41725
|
+
this.#sessionIdentity === "native" && supportsNativeChat(options.agent.id) && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(
|
|
41493
41726
|
options.sessionId
|
|
41494
41727
|
) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId } } : options,
|
|
41495
41728
|
() => this.#observer,
|
|
@@ -41929,7 +42162,7 @@ var AcpSessionManager = class {
|
|
|
41929
42162
|
const nativeSessionId = runtime.nativeSessionId();
|
|
41930
42163
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(nativeSessionId) || this.#sessions.has(nativeSessionId) || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
|
|
41931
42164
|
throw new AcpExecutionError(
|
|
41932
|
-
"
|
|
42165
|
+
"The Agent returned an invalid new Session ID",
|
|
41933
42166
|
{},
|
|
41934
42167
|
"invalid_native_session_response"
|
|
41935
42168
|
);
|
|
@@ -42264,209 +42497,446 @@ var AcpSessionManager = class {
|
|
|
42264
42497
|
};
|
|
42265
42498
|
};
|
|
42266
42499
|
|
|
42267
|
-
// src/
|
|
42268
|
-
|
|
42269
|
-
|
|
42270
|
-
|
|
42271
|
-
|
|
42272
|
-
|
|
42273
|
-
|
|
42274
|
-
|
|
42275
|
-
|
|
42276
|
-
|
|
42277
|
-
|
|
42278
|
-
|
|
42500
|
+
// src/acp/session-config/apply-session-configuration.ts
|
|
42501
|
+
function invalidSessionConfiguration(message) {
|
|
42502
|
+
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
42503
|
+
}
|
|
42504
|
+
function agentForSessionConfiguration(agent, selections) {
|
|
42505
|
+
try {
|
|
42506
|
+
return applyAgentLaunchSettings(agent, selections);
|
|
42507
|
+
} catch (error62) {
|
|
42508
|
+
if (error62 instanceof Error) {
|
|
42509
|
+
throw invalidSessionConfiguration(error62.message);
|
|
42510
|
+
}
|
|
42511
|
+
throw error62;
|
|
42279
42512
|
}
|
|
42280
|
-
}
|
|
42281
|
-
|
|
42282
|
-
|
|
42283
|
-
|
|
42284
|
-
constructor(agent, handled) {
|
|
42285
|
-
this.agent = agent;
|
|
42286
|
-
this.handled = handled;
|
|
42513
|
+
}
|
|
42514
|
+
function validateSessionConfigurationSelection(option, selection) {
|
|
42515
|
+
if (option.type !== selection.valueType) {
|
|
42516
|
+
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
42287
42517
|
}
|
|
42288
|
-
|
|
42289
|
-
|
|
42290
|
-
|
|
42291
|
-
|
|
42292
|
-
|
|
42293
|
-
|
|
42294
|
-
|
|
42518
|
+
if (option.type === "boolean") {
|
|
42519
|
+
if (selection.value.length > 0) {
|
|
42520
|
+
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
42521
|
+
}
|
|
42522
|
+
return;
|
|
42523
|
+
}
|
|
42524
|
+
if (selection.booleanValue) {
|
|
42525
|
+
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
42526
|
+
}
|
|
42527
|
+
if (!option.values.some((value) => value.value === selection.value)) {
|
|
42528
|
+
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
42295
42529
|
}
|
|
42296
|
-
};
|
|
42297
|
-
var AgentSettingsAdapter = class {
|
|
42298
|
-
modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION;
|
|
42299
|
-
applyLaunchSelection = (agent, _selection) => new AgentSettingsLaunchSelectionResult(agent, false);
|
|
42300
|
-
settings = (_agent) => [];
|
|
42301
|
-
};
|
|
42302
|
-
function selectValue(name, value, description) {
|
|
42303
|
-
return {
|
|
42304
|
-
description,
|
|
42305
|
-
groupId: "",
|
|
42306
|
-
groupName: "",
|
|
42307
|
-
name,
|
|
42308
|
-
value
|
|
42309
|
-
};
|
|
42310
|
-
}
|
|
42311
|
-
function selectSetting(id, name, description, currentValue, values) {
|
|
42312
|
-
return {
|
|
42313
|
-
booleanValue: false,
|
|
42314
|
-
category: "execution",
|
|
42315
|
-
currentValue,
|
|
42316
|
-
description,
|
|
42317
|
-
id,
|
|
42318
|
-
name,
|
|
42319
|
-
type: "select",
|
|
42320
|
-
values
|
|
42321
|
-
};
|
|
42322
42530
|
}
|
|
42323
|
-
function
|
|
42324
|
-
if (
|
|
42325
|
-
|
|
42531
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
42532
|
+
if (option.type !== selection.valueType) {
|
|
42533
|
+
return false;
|
|
42326
42534
|
}
|
|
42327
|
-
|
|
42535
|
+
if (option.type === "boolean") {
|
|
42536
|
+
return selection.value.length === 0;
|
|
42537
|
+
}
|
|
42538
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
42328
42539
|
}
|
|
42329
|
-
function
|
|
42330
|
-
|
|
42331
|
-
|
|
42540
|
+
function sessionConfigurationMatches(option, selection) {
|
|
42541
|
+
validateSessionConfigurationSelection(option, selection);
|
|
42542
|
+
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
42543
|
+
}
|
|
42544
|
+
function sessionConfigurationPriority(selection, options) {
|
|
42545
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
42546
|
+
if (selection.configId === "model" || option?.category === "model") {
|
|
42547
|
+
return 0;
|
|
42332
42548
|
}
|
|
42333
|
-
|
|
42549
|
+
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
42550
|
+
return 1;
|
|
42551
|
+
}
|
|
42552
|
+
if (option?.category === "model_config") {
|
|
42553
|
+
return 2;
|
|
42554
|
+
}
|
|
42555
|
+
return 3;
|
|
42334
42556
|
}
|
|
42335
|
-
|
|
42336
|
-
|
|
42337
|
-
|
|
42338
|
-
|
|
42339
|
-
|
|
42340
|
-
|
|
42341
|
-
settings = (agent) => {
|
|
42342
|
-
const configured = agent.environment["DSH_PERMISSION_MODE"] ?? WORKSPACE_WRITE_VALUE;
|
|
42343
|
-
return [
|
|
42344
|
-
selectSetting(
|
|
42345
|
-
DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID,
|
|
42346
|
-
"Access mode",
|
|
42347
|
-
"Controls the local side effects allowed for this DeepSeek Harness session.",
|
|
42348
|
-
validValue(dshAccessModes, configured),
|
|
42349
|
-
dshAccessModes
|
|
42350
|
-
)
|
|
42351
|
-
];
|
|
42352
|
-
};
|
|
42353
|
-
applyLaunchSelection = (agent, selection) => {
|
|
42354
|
-
if (selection.configId !== DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID) {
|
|
42355
|
-
return new AgentSettingsLaunchSelectionResult(agent, false);
|
|
42557
|
+
function assertAppliedSessionConfiguration(options, selections) {
|
|
42558
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
42559
|
+
for (const option of options) {
|
|
42560
|
+
const selection = selectionsById.get(option.id);
|
|
42561
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
42562
|
+
continue;
|
|
42356
42563
|
}
|
|
42357
|
-
|
|
42358
|
-
|
|
42359
|
-
|
|
42360
|
-
|
|
42564
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
42565
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
42566
|
+
}
|
|
42567
|
+
}
|
|
42568
|
+
}
|
|
42569
|
+
function unavailableSessionConfigurationCategory(selection) {
|
|
42570
|
+
if (selection.configId === "model") {
|
|
42571
|
+
return "model";
|
|
42572
|
+
}
|
|
42573
|
+
if (selection.configId === "reasoning_effort") {
|
|
42574
|
+
return "thought_level";
|
|
42575
|
+
}
|
|
42576
|
+
return "unknown";
|
|
42577
|
+
}
|
|
42578
|
+
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
42579
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
42580
|
+
if (option === void 0) {
|
|
42581
|
+
warnIgnoredSetting(
|
|
42582
|
+
audit,
|
|
42583
|
+
"session_configuration_setting_ignored",
|
|
42584
|
+
commandId,
|
|
42585
|
+
sessionId,
|
|
42586
|
+
agent.id,
|
|
42587
|
+
selection,
|
|
42588
|
+
unavailableSessionConfigurationCategory(selection),
|
|
42589
|
+
"setting_unavailable"
|
|
42361
42590
|
);
|
|
42362
|
-
|
|
42363
|
-
};
|
|
42364
|
-
var openCodePermissionModes = Object.freeze([
|
|
42365
|
-
selectValue("Agent default", AGENT_DEFAULT_VALUE, "Keep OpenCode's existing permission policy."),
|
|
42366
|
-
selectValue("Read only", READ_ONLY_VALUE, "Allow inspection without local writes."),
|
|
42367
|
-
selectValue("Workspace write", WORKSPACE_WRITE_VALUE, "Allow changes in the selected workspace."),
|
|
42368
|
-
selectValue("Full access", DANGER_FULL_ACCESS_VALUE, "Allow unrestricted local execution.")
|
|
42369
|
-
]);
|
|
42370
|
-
function openCodeConfiguration(environment) {
|
|
42371
|
-
const encoded = environment["OPENCODE_CONFIG_CONTENT"];
|
|
42372
|
-
if (encoded === void 0 || encoded.length === 0) {
|
|
42373
|
-
return {};
|
|
42591
|
+
return options;
|
|
42374
42592
|
}
|
|
42375
|
-
|
|
42376
|
-
|
|
42377
|
-
|
|
42378
|
-
|
|
42379
|
-
|
|
42593
|
+
if (option.type !== selection.valueType) {
|
|
42594
|
+
warnIgnoredSetting(
|
|
42595
|
+
audit,
|
|
42596
|
+
"session_configuration_setting_ignored",
|
|
42597
|
+
commandId,
|
|
42598
|
+
sessionId,
|
|
42599
|
+
agent.id,
|
|
42600
|
+
selection,
|
|
42601
|
+
option.category,
|
|
42602
|
+
"setting_schema_mismatch"
|
|
42603
|
+
);
|
|
42604
|
+
return options;
|
|
42380
42605
|
}
|
|
42381
|
-
if (
|
|
42382
|
-
|
|
42606
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
42607
|
+
warnIgnoredSetting(
|
|
42608
|
+
audit,
|
|
42609
|
+
"session_configuration_setting_ignored",
|
|
42610
|
+
commandId,
|
|
42611
|
+
sessionId,
|
|
42612
|
+
agent.id,
|
|
42613
|
+
selection,
|
|
42614
|
+
option.category,
|
|
42615
|
+
"selection_schema_mismatch"
|
|
42616
|
+
);
|
|
42617
|
+
return options;
|
|
42383
42618
|
}
|
|
42384
|
-
|
|
42619
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
42620
|
+
warnIgnoredSetting(
|
|
42621
|
+
audit,
|
|
42622
|
+
"session_configuration_setting_ignored",
|
|
42623
|
+
commandId,
|
|
42624
|
+
sessionId,
|
|
42625
|
+
agent.id,
|
|
42626
|
+
selection,
|
|
42627
|
+
option.category,
|
|
42628
|
+
"value_unavailable"
|
|
42629
|
+
);
|
|
42630
|
+
return options;
|
|
42631
|
+
}
|
|
42632
|
+
if (sessionConfigurationMatches(option, selection)) {
|
|
42633
|
+
return options;
|
|
42634
|
+
}
|
|
42635
|
+
return await sessions.configureSession({
|
|
42636
|
+
additionalDirectories,
|
|
42637
|
+
agent,
|
|
42638
|
+
booleanValue: selection.booleanValue,
|
|
42639
|
+
configId: selection.configId,
|
|
42640
|
+
cwd,
|
|
42641
|
+
requestId: `cfg_${randomUUID2()}`,
|
|
42642
|
+
sessionId,
|
|
42643
|
+
signal,
|
|
42644
|
+
value: selection.value,
|
|
42645
|
+
valueType: selection.valueType
|
|
42646
|
+
});
|
|
42385
42647
|
}
|
|
42386
|
-
function
|
|
42387
|
-
|
|
42388
|
-
|
|
42389
|
-
|
|
42390
|
-
|
|
42391
|
-
|
|
42392
|
-
|
|
42393
|
-
|
|
42394
|
-
|
|
42395
|
-
|
|
42648
|
+
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
42649
|
+
let options = initialOptions;
|
|
42650
|
+
const orderedSelections = selections.toSorted((left, right) => {
|
|
42651
|
+
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
42652
|
+
return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
|
|
42653
|
+
});
|
|
42654
|
+
for (const selection of orderedSelections) {
|
|
42655
|
+
options = await applySessionConfigurationSelection(
|
|
42656
|
+
sessions,
|
|
42657
|
+
audit,
|
|
42658
|
+
options,
|
|
42659
|
+
selection,
|
|
42660
|
+
agent,
|
|
42661
|
+
cwd,
|
|
42662
|
+
additionalDirectories,
|
|
42663
|
+
commandId,
|
|
42664
|
+
sessionId,
|
|
42665
|
+
signal
|
|
42666
|
+
);
|
|
42396
42667
|
}
|
|
42397
|
-
|
|
42398
|
-
|
|
42399
|
-
|
|
42400
|
-
|
|
42401
|
-
|
|
42668
|
+
assertAppliedSessionConfiguration(options, selections);
|
|
42669
|
+
}
|
|
42670
|
+
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
42671
|
+
const details = {
|
|
42672
|
+
agentId,
|
|
42673
|
+
category,
|
|
42674
|
+
configId: selection.configId,
|
|
42675
|
+
reason,
|
|
42676
|
+
requestedValue: selection.value
|
|
42677
|
+
};
|
|
42678
|
+
audit.record({ commandId, details, event, sessionId });
|
|
42679
|
+
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
42680
|
+
`);
|
|
42681
|
+
}
|
|
42682
|
+
|
|
42683
|
+
// src/agent-catalog/discover-agent-settings.ts
|
|
42684
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
42685
|
+
function isUnavailableModel(cause, modelSettingId, requestedModel) {
|
|
42686
|
+
return cause instanceof AcpConfigurationValueUnavailableError && cause.configId === modelSettingId && cause.requestedValue === requestedModel;
|
|
42687
|
+
}
|
|
42688
|
+
function unsupportedModelIds(unsupportedModels) {
|
|
42689
|
+
return [...new Set(unsupportedModels.map((item) => item.requestedValue))];
|
|
42690
|
+
}
|
|
42691
|
+
async function discoverAgentSettings(command, config2, directories, sessions, signal) {
|
|
42692
|
+
const agent = config2.catalog.find(command.agentId);
|
|
42693
|
+
const cwd = await directories.resolve(config2.bindingId, "default", signal);
|
|
42694
|
+
const inspectedBaseSnapshot = await sessions.inspectAgentSettings({
|
|
42695
|
+
additionalDirectories: [],
|
|
42696
|
+
agent,
|
|
42697
|
+
cwd,
|
|
42698
|
+
signal
|
|
42699
|
+
});
|
|
42700
|
+
const baseSnapshot = {
|
|
42701
|
+
agentName: inspectedBaseSnapshot.agentName,
|
|
42702
|
+
agentVersion: inspectedBaseSnapshot.agentVersion,
|
|
42703
|
+
configOptions: await discoverOpenCodeModelOptions(agent, cwd, inspectedBaseSnapshot.configOptions, signal)
|
|
42704
|
+
};
|
|
42705
|
+
const baseModel = modelOption(baseSnapshot.configOptions);
|
|
42706
|
+
const unsupportedModels = [];
|
|
42707
|
+
let selectedSnapshot = baseSnapshot;
|
|
42708
|
+
if (command.model !== void 0) {
|
|
42709
|
+
if (baseModel === void 0 || baseModel.type !== "select" || !baseModel.values.some((value) => value.value === command.model)) {
|
|
42710
|
+
unsupportedModels.push(
|
|
42711
|
+
new AcpConfigurationValueUnavailableError(
|
|
42712
|
+
baseModel?.id ?? "model",
|
|
42713
|
+
command.model,
|
|
42714
|
+
baseModel?.values.map((value) => value.value) ?? []
|
|
42715
|
+
)
|
|
42716
|
+
);
|
|
42717
|
+
} else {
|
|
42718
|
+
try {
|
|
42719
|
+
selectedSnapshot = await sessions.inspectAgentSettings({
|
|
42720
|
+
additionalDirectories: [],
|
|
42721
|
+
agent,
|
|
42722
|
+
cwd,
|
|
42723
|
+
model: command.model,
|
|
42724
|
+
signal
|
|
42725
|
+
});
|
|
42726
|
+
} catch (cause) {
|
|
42727
|
+
signal.throwIfAborted();
|
|
42728
|
+
if (!isUnavailableModel(cause, baseModel.id, command.model)) {
|
|
42729
|
+
throw cause;
|
|
42730
|
+
}
|
|
42731
|
+
unsupportedModels.push(cause);
|
|
42732
|
+
}
|
|
42733
|
+
}
|
|
42402
42734
|
}
|
|
42403
|
-
|
|
42735
|
+
const adapter = agentSettingsAdapterForAgent(agent.id);
|
|
42736
|
+
const modelEffort = await discoverModelEffort(
|
|
42737
|
+
command,
|
|
42738
|
+
agent,
|
|
42739
|
+
adapter.modelEffortResolution,
|
|
42740
|
+
baseSnapshot.configOptions,
|
|
42741
|
+
selectedSnapshot.configOptions,
|
|
42742
|
+
unsupportedModels,
|
|
42743
|
+
cwd,
|
|
42744
|
+
sessions,
|
|
42745
|
+
signal
|
|
42746
|
+
);
|
|
42747
|
+
const baseSettings = withoutUnsupportedModels(
|
|
42748
|
+
settingsFromSnapshot(agent, baseSnapshot.configOptions),
|
|
42749
|
+
baseModel?.id ?? "",
|
|
42750
|
+
modelEffort.unsupportedModelIds
|
|
42751
|
+
);
|
|
42752
|
+
const settings = withoutUnsupportedModels(
|
|
42753
|
+
settingsFromSnapshot(agent, selectedSnapshot.configOptions),
|
|
42754
|
+
baseModel?.id ?? "",
|
|
42755
|
+
modelEffort.unsupportedModelIds
|
|
42756
|
+
);
|
|
42757
|
+
return {
|
|
42758
|
+
event: {
|
|
42759
|
+
agentId: command.agentId,
|
|
42760
|
+
agentName: selectedSnapshot.agentName,
|
|
42761
|
+
agentVersion: selectedSnapshot.agentVersion,
|
|
42762
|
+
kind: AGENT_SETTINGS_DISCOVERED_KIND,
|
|
42763
|
+
modelEffort,
|
|
42764
|
+
requestId: command.requestId,
|
|
42765
|
+
settings,
|
|
42766
|
+
settingsRevision: settingsRevision(agent, baseSnapshot.agentVersion, baseSettings, modelEffort)
|
|
42767
|
+
},
|
|
42768
|
+
unsupportedModels
|
|
42769
|
+
};
|
|
42404
42770
|
}
|
|
42405
|
-
|
|
42406
|
-
|
|
42407
|
-
|
|
42408
|
-
|
|
42409
|
-
|
|
42410
|
-
|
|
42411
|
-
|
|
42412
|
-
|
|
42413
|
-
|
|
42414
|
-
|
|
42415
|
-
)
|
|
42416
|
-
];
|
|
42771
|
+
function settingFromOption(option) {
|
|
42772
|
+
return {
|
|
42773
|
+
booleanValue: option.booleanValue,
|
|
42774
|
+
category: option.category,
|
|
42775
|
+
defaultValue: option.type === "boolean" ? "" : option.currentValue,
|
|
42776
|
+
description: option.description,
|
|
42777
|
+
id: option.id,
|
|
42778
|
+
name: option.name,
|
|
42779
|
+
type: option.type,
|
|
42780
|
+
values: option.values
|
|
42417
42781
|
};
|
|
42418
|
-
|
|
42419
|
-
|
|
42420
|
-
|
|
42782
|
+
}
|
|
42783
|
+
function settingsFromSnapshot(agent, configOptions) {
|
|
42784
|
+
const settings = [
|
|
42785
|
+
...agentSettingsAdapterForAgent(agent.id).settings(agent).map(settingFromOption),
|
|
42786
|
+
...configOptions.map(settingFromOption)
|
|
42787
|
+
];
|
|
42788
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
42789
|
+
for (const setting of settings) {
|
|
42790
|
+
if (identifiers.has(setting.id)) {
|
|
42791
|
+
throw new AcpExecutionError(
|
|
42792
|
+
"The Agent returned duplicate setting identifiers",
|
|
42793
|
+
{},
|
|
42794
|
+
"invalid_session_configuration"
|
|
42795
|
+
);
|
|
42421
42796
|
}
|
|
42422
|
-
|
|
42423
|
-
|
|
42424
|
-
|
|
42797
|
+
identifiers.add(setting.id);
|
|
42798
|
+
}
|
|
42799
|
+
if (settings.length > 128) {
|
|
42800
|
+
throw new AcpExecutionError("The Agent returned too many settings", {}, "invalid_session_configuration");
|
|
42801
|
+
}
|
|
42802
|
+
return settings;
|
|
42803
|
+
}
|
|
42804
|
+
function withoutUnsupportedModels(settings, modelSettingId, unsupportedModelIds2) {
|
|
42805
|
+
if (modelSettingId.length === 0 || unsupportedModelIds2.length === 0) {
|
|
42806
|
+
return settings;
|
|
42807
|
+
}
|
|
42808
|
+
const unsupported = new Set(unsupportedModelIds2);
|
|
42809
|
+
return settings.map((setting) => {
|
|
42810
|
+
if (setting.id !== modelSettingId || setting.type !== "select") {
|
|
42811
|
+
return setting;
|
|
42425
42812
|
}
|
|
42426
|
-
return
|
|
42427
|
-
|
|
42428
|
-
|
|
42429
|
-
|
|
42430
|
-
|
|
42431
|
-
|
|
42432
|
-
|
|
42433
|
-
|
|
42434
|
-
|
|
42435
|
-
|
|
42436
|
-
|
|
42813
|
+
return {
|
|
42814
|
+
...setting,
|
|
42815
|
+
defaultValue: unsupported.has(setting.defaultValue) ? "" : setting.defaultValue,
|
|
42816
|
+
values: setting.values.filter((value) => !unsupported.has(value.value))
|
|
42817
|
+
};
|
|
42818
|
+
});
|
|
42819
|
+
}
|
|
42820
|
+
function modelOption(options) {
|
|
42821
|
+
return options.find((option) => option.id === "model" || option.category === "model");
|
|
42822
|
+
}
|
|
42823
|
+
function effortOption(options) {
|
|
42824
|
+
return options.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
42825
|
+
}
|
|
42826
|
+
function unavailableModelEffort() {
|
|
42827
|
+
return {
|
|
42828
|
+
effortSettingId: "",
|
|
42829
|
+
modelSettingId: "",
|
|
42830
|
+
resolution: AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE,
|
|
42831
|
+
unsupportedModelIds: [],
|
|
42832
|
+
valuesByModel: {}
|
|
42437
42833
|
};
|
|
42438
|
-
}
|
|
42439
|
-
|
|
42440
|
-
|
|
42441
|
-
|
|
42442
|
-
|
|
42443
|
-
|
|
42444
|
-
var deepSeekHarnessAdapter = new DeepSeekHarnessSettingsAdapter();
|
|
42445
|
-
var openCodeAdapter = new OpenCodeSettingsAdapter();
|
|
42446
|
-
function agentSettingsAdapterForAgent(agentId) {
|
|
42447
|
-
if (agentId === "codex") {
|
|
42448
|
-
return codexAdapter;
|
|
42834
|
+
}
|
|
42835
|
+
async function discoverModelEffort(command, agent, resolution, initialOptions, selectedOptions, initiallyUnsupportedModels, cwd, sessions, signal) {
|
|
42836
|
+
const model = modelOption(initialOptions);
|
|
42837
|
+
const unsupportedModels = initiallyUnsupportedModels;
|
|
42838
|
+
if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
|
|
42839
|
+
return { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) };
|
|
42449
42840
|
}
|
|
42450
|
-
if (
|
|
42451
|
-
return
|
|
42841
|
+
if (model === void 0 || model.type !== "select" || model.values.length === 0) {
|
|
42842
|
+
return { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) };
|
|
42452
42843
|
}
|
|
42453
|
-
|
|
42454
|
-
|
|
42844
|
+
const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
|
|
42845
|
+
additionalDirectories: [],
|
|
42846
|
+
agent,
|
|
42847
|
+
cwd,
|
|
42848
|
+
model: modelValue,
|
|
42849
|
+
signal
|
|
42850
|
+
})).configOptions;
|
|
42851
|
+
const valuesByModel = {};
|
|
42852
|
+
if (resolution === "complete") {
|
|
42853
|
+
const effort = effortOption(initialOptions);
|
|
42854
|
+
if (effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
|
|
42855
|
+
return {
|
|
42856
|
+
...unavailableModelEffort(),
|
|
42857
|
+
unsupportedModelIds: unsupportedModelIds(unsupportedModels)
|
|
42858
|
+
};
|
|
42859
|
+
}
|
|
42860
|
+
for (const value of model.values) {
|
|
42861
|
+
if (unsupportedModels.some((diagnostic) => diagnostic.requestedValue === value.value)) {
|
|
42862
|
+
continue;
|
|
42863
|
+
}
|
|
42864
|
+
try {
|
|
42865
|
+
const selectedEffort2 = effortOption(await inspectModel(value.value));
|
|
42866
|
+
valuesByModel[value.value] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
42867
|
+
} catch (cause) {
|
|
42868
|
+
signal.throwIfAborted();
|
|
42869
|
+
if (!isUnavailableModel(cause, model.id, value.value)) {
|
|
42870
|
+
throw cause;
|
|
42871
|
+
}
|
|
42872
|
+
unsupportedModels.push(cause);
|
|
42873
|
+
}
|
|
42874
|
+
}
|
|
42875
|
+
return {
|
|
42876
|
+
effortSettingId: effort.id,
|
|
42877
|
+
modelSettingId: model.id,
|
|
42878
|
+
resolution: "complete",
|
|
42879
|
+
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
42880
|
+
valuesByModel
|
|
42881
|
+
};
|
|
42455
42882
|
}
|
|
42456
|
-
|
|
42457
|
-
|
|
42458
|
-
|
|
42459
|
-
|
|
42460
|
-
|
|
42461
|
-
|
|
42462
|
-
|
|
42463
|
-
|
|
42464
|
-
|
|
42465
|
-
|
|
42466
|
-
|
|
42883
|
+
if (command.model !== void 0) {
|
|
42884
|
+
const modelUnsupported = unsupportedModels.some((diagnostic) => diagnostic.requestedValue === command.model);
|
|
42885
|
+
const selectedEffort2 = effortOption(selectedOptions);
|
|
42886
|
+
if (!modelUnsupported) {
|
|
42887
|
+
valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
42888
|
+
}
|
|
42889
|
+
return {
|
|
42890
|
+
effortSettingId: selectedEffort2?.id ?? "",
|
|
42891
|
+
modelSettingId: model.id,
|
|
42892
|
+
resolution: "on_model_selection",
|
|
42893
|
+
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
42894
|
+
valuesByModel
|
|
42895
|
+
};
|
|
42896
|
+
}
|
|
42897
|
+
const defaultModel = model.type === "select" ? model.currentValue : "";
|
|
42898
|
+
const reportedEffort = effortOption(selectedOptions);
|
|
42899
|
+
let selectedEffort = reportedEffort;
|
|
42900
|
+
if (defaultModel.length > 0 && reportedEffort === void 0) {
|
|
42901
|
+
try {
|
|
42902
|
+
selectedEffort = effortOption(await inspectModel(defaultModel));
|
|
42903
|
+
} catch (cause) {
|
|
42904
|
+
signal.throwIfAborted();
|
|
42905
|
+
if (!isUnavailableModel(cause, model.id, defaultModel)) {
|
|
42906
|
+
throw cause;
|
|
42907
|
+
}
|
|
42908
|
+
unsupportedModels.push(cause);
|
|
42467
42909
|
}
|
|
42468
42910
|
}
|
|
42469
|
-
|
|
42911
|
+
if (defaultModel.length > 0 && !unsupportedModels.some((diagnostic) => diagnostic.requestedValue === defaultModel)) {
|
|
42912
|
+
valuesByModel[defaultModel] = selectedEffort?.type === "select" ? selectedEffort.values : [];
|
|
42913
|
+
}
|
|
42914
|
+
return {
|
|
42915
|
+
effortSettingId: selectedEffort?.id ?? "",
|
|
42916
|
+
modelSettingId: model.id,
|
|
42917
|
+
resolution: "on_model_selection",
|
|
42918
|
+
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
42919
|
+
valuesByModel
|
|
42920
|
+
};
|
|
42921
|
+
}
|
|
42922
|
+
function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
|
|
42923
|
+
const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
|
|
42924
|
+
effortSettingId: "",
|
|
42925
|
+
modelSettingId: modelEffort.modelSettingId,
|
|
42926
|
+
resolution: modelEffort.resolution,
|
|
42927
|
+
unsupportedModelIds: modelEffort.unsupportedModelIds,
|
|
42928
|
+
valuesByModel: {}
|
|
42929
|
+
};
|
|
42930
|
+
return createHash3("sha256").update(
|
|
42931
|
+
JSON.stringify({
|
|
42932
|
+
adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
|
|
42933
|
+
agentId: agent.id,
|
|
42934
|
+
agentVersion: agent.agentVersion,
|
|
42935
|
+
modelEffort: revisionModelEffort,
|
|
42936
|
+
reportedAgentVersion,
|
|
42937
|
+
settings
|
|
42938
|
+
})
|
|
42939
|
+
).digest("hex");
|
|
42470
42940
|
}
|
|
42471
42941
|
|
|
42472
42942
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
@@ -43755,8 +44225,91 @@ var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await read
|
|
|
43755
44225
|
var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
|
|
43756
44226
|
|
|
43757
44227
|
// src/native-sessions/service.ts
|
|
43758
|
-
import { randomUUID as
|
|
44228
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
43759
44229
|
import { basename as basename6 } from "node:path";
|
|
44230
|
+
|
|
44231
|
+
// src/native-sessions/claude-history.ts
|
|
44232
|
+
async function readClaudeHistory(sessions, directories, bindingId, options, nativeSessionId) {
|
|
44233
|
+
let cursor = null;
|
|
44234
|
+
let inspected = 0;
|
|
44235
|
+
for (let pageNumber = 0; pageNumber < 500 && inspected < 500; pageNumber += 1) {
|
|
44236
|
+
const page = await sessions.listNativeSessions(options, cursor);
|
|
44237
|
+
inspected += page.sessions.length;
|
|
44238
|
+
const found = page.sessions.find((entry) => entry.sessionId === nativeSessionId);
|
|
44239
|
+
if (found !== void 0) {
|
|
44240
|
+
const primary = await directories.identify(bindingId, found.cwd, options.signal);
|
|
44241
|
+
const additional = await Promise.all(
|
|
44242
|
+
found.additionalDirectories.map(
|
|
44243
|
+
async (directory) => await directories.identify(bindingId, directory, options.signal)
|
|
44244
|
+
)
|
|
44245
|
+
);
|
|
44246
|
+
if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index2) => directory.path !== options.additionalDirectories[index2])) {
|
|
44247
|
+
throw new AcpExecutionError(
|
|
44248
|
+
"The native Session belongs to another workspace.",
|
|
44249
|
+
{},
|
|
44250
|
+
"session_identity_mismatch"
|
|
44251
|
+
);
|
|
44252
|
+
}
|
|
44253
|
+
return await sessions.previewNativeSession(options, nativeSessionId);
|
|
44254
|
+
}
|
|
44255
|
+
if (page.nextCursor === null || page.nextCursor === cursor) {
|
|
44256
|
+
break;
|
|
44257
|
+
}
|
|
44258
|
+
cursor = page.nextCursor ?? null;
|
|
44259
|
+
}
|
|
44260
|
+
throw new AcpExecutionError("The native Session was not found.", {}, "native_session_not_found");
|
|
44261
|
+
}
|
|
44262
|
+
|
|
44263
|
+
// src/native-sessions/claude-adapter.ts
|
|
44264
|
+
var claudeSessionAdapter = {
|
|
44265
|
+
linkedHistory: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readClaudeHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
44266
|
+
history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readClaudeHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
44267
|
+
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
44268
|
+
};
|
|
44269
|
+
|
|
44270
|
+
// src/native-sessions/codex-adapter.ts
|
|
44271
|
+
async function verifiedHistory(context, full) {
|
|
44272
|
+
const { options, nativeSessionId, directories, bindingId } = context;
|
|
44273
|
+
const snapshot = full ? await readCodexFullHistory(options.agent, options.cwd, nativeSessionId, options.signal) : await readCodexHistory(options.agent, options.cwd, nativeSessionId, options.signal);
|
|
44274
|
+
const resolved = await directories.identify(bindingId, snapshot.cwd, options.signal);
|
|
44275
|
+
if (snapshot.nativeSessionId !== nativeSessionId || resolved.path !== options.cwd) {
|
|
44276
|
+
throw new AcpExecutionError(
|
|
44277
|
+
"Codex returned history for a different session or workspace.",
|
|
44278
|
+
{},
|
|
44279
|
+
"invalid_native_session_response"
|
|
44280
|
+
);
|
|
44281
|
+
}
|
|
44282
|
+
return snapshot.history;
|
|
44283
|
+
}
|
|
44284
|
+
var codexSessionAdapter = {
|
|
44285
|
+
linkedHistory: async (context) => await verifiedHistory(context, true),
|
|
44286
|
+
history: async (context) => await verifiedHistory(context, true),
|
|
44287
|
+
// Codex enforces an exclusive writer per thread. Its read-only app-server
|
|
44288
|
+
// history path keeps externally owned conversations previewable.
|
|
44289
|
+
preview: async (context) => await verifiedHistory(context, false)
|
|
44290
|
+
};
|
|
44291
|
+
|
|
44292
|
+
// src/native-sessions/agent-adapter.ts
|
|
44293
|
+
var genericSessionAdapter = {
|
|
44294
|
+
linkedHistory: async () => {
|
|
44295
|
+
throw new AcpExecutionError("This Agent does not support Chat history", {}, "native_session_unsupported");
|
|
44296
|
+
},
|
|
44297
|
+
history: async () => {
|
|
44298
|
+
throw new AcpExecutionError("Native history is unavailable for this Agent", {}, "native_session_unsupported");
|
|
44299
|
+
},
|
|
44300
|
+
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
44301
|
+
};
|
|
44302
|
+
function nativeSessionAdapter(agentId) {
|
|
44303
|
+
if (agentId === "codex") {
|
|
44304
|
+
return codexSessionAdapter;
|
|
44305
|
+
}
|
|
44306
|
+
if (agentId === "claude") {
|
|
44307
|
+
return claudeSessionAdapter;
|
|
44308
|
+
}
|
|
44309
|
+
return genericSessionAdapter;
|
|
44310
|
+
}
|
|
44311
|
+
|
|
44312
|
+
// src/native-sessions/service.ts
|
|
43760
44313
|
var NativeSessionService = class {
|
|
43761
44314
|
#entries = /* @__PURE__ */ new Map();
|
|
43762
44315
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -43787,27 +44340,6 @@ var NativeSessionService = class {
|
|
|
43787
44340
|
signal
|
|
43788
44341
|
};
|
|
43789
44342
|
if (command.action === "linked-history") {
|
|
43790
|
-
if (options.agent.id !== "codex") {
|
|
43791
|
-
const history = await this.#sessions.loadLinkedSessionHistory({
|
|
43792
|
-
...options,
|
|
43793
|
-
sessionId: command.targetSessionId
|
|
43794
|
-
});
|
|
43795
|
-
this.record(command, "native_session_history_read");
|
|
43796
|
-
return history === null ? {
|
|
43797
|
-
action: "unlinked-history",
|
|
43798
|
-
kind: "native.session.result",
|
|
43799
|
-
requestId: command.requestId,
|
|
43800
|
-
sessionId: command.sessionId,
|
|
43801
|
-
targetSessionId: command.targetSessionId
|
|
43802
|
-
} : {
|
|
43803
|
-
action: "linked-history",
|
|
43804
|
-
history,
|
|
43805
|
-
kind: "native.session.result",
|
|
43806
|
-
requestId: command.requestId,
|
|
43807
|
-
sessionId: command.sessionId,
|
|
43808
|
-
targetSessionId: command.targetSessionId
|
|
43809
|
-
};
|
|
43810
|
-
}
|
|
43811
44343
|
const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
|
|
43812
44344
|
if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
|
|
43813
44345
|
this.record(command, "native_session_history_read");
|
|
@@ -43826,19 +44358,17 @@ var NativeSessionService = class {
|
|
|
43826
44358
|
targetSessionId: command.targetSessionId
|
|
43827
44359
|
};
|
|
43828
44360
|
}
|
|
43829
|
-
const
|
|
43830
|
-
|
|
43831
|
-
|
|
43832
|
-
|
|
43833
|
-
|
|
43834
|
-
|
|
43835
|
-
|
|
43836
|
-
);
|
|
43837
|
-
}
|
|
44361
|
+
const history = await nativeSessionAdapter(options.agent.id).linkedHistory({
|
|
44362
|
+
sessions: this.#sessions,
|
|
44363
|
+
directories: this.#directories,
|
|
44364
|
+
bindingId: command.bindingId,
|
|
44365
|
+
options,
|
|
44366
|
+
nativeSessionId
|
|
44367
|
+
});
|
|
43838
44368
|
this.record(command, "native_session_history_read");
|
|
43839
44369
|
return {
|
|
43840
44370
|
action: "linked-history",
|
|
43841
|
-
history
|
|
44371
|
+
history,
|
|
43842
44372
|
kind: "native.session.result",
|
|
43843
44373
|
requestId: command.requestId,
|
|
43844
44374
|
sessionId: command.sessionId,
|
|
@@ -43846,7 +44376,7 @@ var NativeSessionService = class {
|
|
|
43846
44376
|
};
|
|
43847
44377
|
}
|
|
43848
44378
|
if (command.action === "create") {
|
|
43849
|
-
if (options.agent.id
|
|
44379
|
+
if (!supportsNativeChat(options.agent.id)) {
|
|
43850
44380
|
throw new AcpExecutionError(
|
|
43851
44381
|
"Native session creation is unavailable for this Agent",
|
|
43852
44382
|
{},
|
|
@@ -43879,7 +44409,7 @@ var NativeSessionService = class {
|
|
|
43879
44409
|
if (authorized === null) {
|
|
43880
44410
|
return null;
|
|
43881
44411
|
}
|
|
43882
|
-
const entryId =
|
|
44412
|
+
const entryId = randomUUID3();
|
|
43883
44413
|
if (this.#entries.size >= 5e3) {
|
|
43884
44414
|
this.#entries.clear();
|
|
43885
44415
|
}
|
|
@@ -43934,7 +44464,7 @@ var NativeSessionService = class {
|
|
|
43934
44464
|
"invalid_native_session_response"
|
|
43935
44465
|
);
|
|
43936
44466
|
}
|
|
43937
|
-
nextCursor =
|
|
44467
|
+
nextCursor = randomUUID3();
|
|
43938
44468
|
if (this.#cursors.size >= 500) {
|
|
43939
44469
|
this.#cursors.clear();
|
|
43940
44470
|
}
|
|
@@ -43998,7 +44528,13 @@ var NativeSessionService = class {
|
|
|
43998
44528
|
}
|
|
43999
44529
|
const target = await this.resolveTarget(command, options, selected);
|
|
44000
44530
|
if (command.action === "history") {
|
|
44001
|
-
const history = await
|
|
44531
|
+
const history = await nativeSessionAdapter(options.agent.id).history({
|
|
44532
|
+
sessions: this.#sessions,
|
|
44533
|
+
directories: this.#directories,
|
|
44534
|
+
bindingId: command.bindingId,
|
|
44535
|
+
options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
|
|
44536
|
+
nativeSessionId: target.info.sessionId
|
|
44537
|
+
});
|
|
44002
44538
|
signal.throwIfAborted();
|
|
44003
44539
|
this.record(command, "native_session_history_read");
|
|
44004
44540
|
return {
|
|
@@ -44010,7 +44546,13 @@ var NativeSessionService = class {
|
|
|
44010
44546
|
};
|
|
44011
44547
|
}
|
|
44012
44548
|
if (command.action === "preview") {
|
|
44013
|
-
const history = await
|
|
44549
|
+
const history = await nativeSessionAdapter(options.agent.id).preview({
|
|
44550
|
+
sessions: this.#sessions,
|
|
44551
|
+
directories: this.#directories,
|
|
44552
|
+
bindingId: command.bindingId,
|
|
44553
|
+
options: { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
|
|
44554
|
+
nativeSessionId: target.info.sessionId
|
|
44555
|
+
});
|
|
44014
44556
|
signal.throwIfAborted();
|
|
44015
44557
|
this.record(command, "native_session_previewed");
|
|
44016
44558
|
return {
|
|
@@ -44164,43 +44706,6 @@ var NativeSessionService = class {
|
|
|
44164
44706
|
title: command.title
|
|
44165
44707
|
};
|
|
44166
44708
|
};
|
|
44167
|
-
previewHistory = async (command, options, target, signal) => {
|
|
44168
|
-
if (options.agent.id !== "codex") {
|
|
44169
|
-
return await this.#sessions.previewNativeSession(
|
|
44170
|
-
{ ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
|
|
44171
|
-
target.info.sessionId
|
|
44172
|
-
);
|
|
44173
|
-
}
|
|
44174
|
-
const snapshot = await readCodexHistory(options.agent, target.cwd, target.info.sessionId, signal);
|
|
44175
|
-
const resolved = await this.#directories.identify(command.bindingId, snapshot.cwd, signal);
|
|
44176
|
-
if (snapshot.nativeSessionId !== target.info.sessionId || resolved.path !== target.cwd) {
|
|
44177
|
-
throw new AcpExecutionError(
|
|
44178
|
-
"Codex returned history for a different session or workspace.",
|
|
44179
|
-
{},
|
|
44180
|
-
"invalid_native_session_response"
|
|
44181
|
-
);
|
|
44182
|
-
}
|
|
44183
|
-
return snapshot.history;
|
|
44184
|
-
};
|
|
44185
|
-
readHistory = async (command, options, target, signal) => {
|
|
44186
|
-
if (options.agent.id !== "codex") {
|
|
44187
|
-
throw new AcpExecutionError(
|
|
44188
|
-
"Native history is unavailable for this Agent",
|
|
44189
|
-
{},
|
|
44190
|
-
"native_session_unsupported"
|
|
44191
|
-
);
|
|
44192
|
-
}
|
|
44193
|
-
const snapshot = await readCodexFullHistory(options.agent, target.cwd, target.info.sessionId, signal);
|
|
44194
|
-
const resolved = await this.#directories.identify(command.bindingId, snapshot.cwd, signal);
|
|
44195
|
-
if (snapshot.nativeSessionId !== target.info.sessionId || resolved.path !== target.cwd) {
|
|
44196
|
-
throw new AcpExecutionError(
|
|
44197
|
-
"Codex returned history for a different session or workspace.",
|
|
44198
|
-
{},
|
|
44199
|
-
"invalid_native_session_response"
|
|
44200
|
-
);
|
|
44201
|
-
}
|
|
44202
|
-
return snapshot.history;
|
|
44203
|
-
};
|
|
44204
44709
|
authorizeEntry = async (command, options, info) => {
|
|
44205
44710
|
try {
|
|
44206
44711
|
const primary = await this.#directories.identify(command.bindingId, info.cwd, options.signal);
|
|
@@ -44285,7 +44790,7 @@ var NativeSessionService = class {
|
|
|
44285
44790
|
};
|
|
44286
44791
|
|
|
44287
44792
|
// src/prompt-artifact-resolver.ts
|
|
44288
|
-
import { createHash as
|
|
44793
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
44289
44794
|
import { fetch as fetch4 } from "undici";
|
|
44290
44795
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
44291
44796
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
@@ -44424,7 +44929,7 @@ async function download(config2, command, reference, signal) {
|
|
|
44424
44929
|
);
|
|
44425
44930
|
}
|
|
44426
44931
|
const bytes = await responseBytes(response, reference.byteLength, requestSignal);
|
|
44427
|
-
if (
|
|
44932
|
+
if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
|
|
44428
44933
|
throw new PromptArtifactError(
|
|
44429
44934
|
"artifact_integrity_failed",
|
|
44430
44935
|
"The prompt artifact failed integrity validation"
|
|
@@ -44890,7 +45395,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
44890
45395
|
};
|
|
44891
45396
|
|
|
44892
45397
|
// src/relay-connection/liveness.ts
|
|
44893
|
-
import { randomUUID as
|
|
45398
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
44894
45399
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
44895
45400
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
44896
45401
|
var RelayLivenessState = class {
|
|
@@ -44979,7 +45484,7 @@ var RelayConnectionLiveness = class {
|
|
|
44979
45484
|
}
|
|
44980
45485
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
44981
45486
|
}
|
|
44982
|
-
const heartbeatId =
|
|
45487
|
+
const heartbeatId = randomUUID4();
|
|
44983
45488
|
this.#state = new AwaitingHeartbeatAckState(
|
|
44984
45489
|
heartbeatId,
|
|
44985
45490
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -44996,7 +45501,7 @@ var RelayConnectionLiveness = class {
|
|
|
44996
45501
|
};
|
|
44997
45502
|
|
|
44998
45503
|
// src/relay-connection/session-event-outbox.ts
|
|
44999
|
-
import { createHash as
|
|
45504
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
45000
45505
|
import { DatabaseSync } from "node:sqlite";
|
|
45001
45506
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
45002
45507
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -45122,7 +45627,7 @@ var SessionEventOutbox = class {
|
|
|
45122
45627
|
`);
|
|
45123
45628
|
}
|
|
45124
45629
|
claimExecution = (commandId, sessionId, commandJson) => {
|
|
45125
|
-
const commandHash =
|
|
45630
|
+
const commandHash = createHash5("sha256").update(commandJson).digest("hex");
|
|
45126
45631
|
this.#database.exec("BEGIN IMMEDIATE");
|
|
45127
45632
|
try {
|
|
45128
45633
|
const existing = this.#database.prepare(
|
|
@@ -46241,262 +46746,6 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
46241
46746
|
}
|
|
46242
46747
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
46243
46748
|
}
|
|
46244
|
-
function isUnavailableModel(cause, modelSettingId, requestedModel) {
|
|
46245
|
-
return cause instanceof AcpConfigurationValueUnavailableError && cause.configId === modelSettingId && cause.requestedValue === requestedModel;
|
|
46246
|
-
}
|
|
46247
|
-
function unsupportedModelIds(unsupportedModels) {
|
|
46248
|
-
return [...new Set(unsupportedModels.map((item) => item.requestedValue))];
|
|
46249
|
-
}
|
|
46250
|
-
async function discoverAgentSettings(command, config2, directories, sessions, signal) {
|
|
46251
|
-
const agent = config2.catalog.find(command.agentId);
|
|
46252
|
-
const cwd = await directories.resolve(config2.bindingId, "default", signal);
|
|
46253
|
-
const inspectedBaseSnapshot = await sessions.inspectAgentSettings({
|
|
46254
|
-
additionalDirectories: [],
|
|
46255
|
-
agent,
|
|
46256
|
-
cwd,
|
|
46257
|
-
signal
|
|
46258
|
-
});
|
|
46259
|
-
const baseSnapshot = {
|
|
46260
|
-
agentName: inspectedBaseSnapshot.agentName,
|
|
46261
|
-
agentVersion: inspectedBaseSnapshot.agentVersion,
|
|
46262
|
-
configOptions: await discoverOpenCodeModelOptions(agent, cwd, inspectedBaseSnapshot.configOptions, signal)
|
|
46263
|
-
};
|
|
46264
|
-
const baseModel = modelOption(baseSnapshot.configOptions);
|
|
46265
|
-
const unsupportedModels = [];
|
|
46266
|
-
let selectedSnapshot = baseSnapshot;
|
|
46267
|
-
if (command.model !== void 0) {
|
|
46268
|
-
if (baseModel === void 0 || baseModel.type !== "select" || !baseModel.values.some((value) => value.value === command.model)) {
|
|
46269
|
-
unsupportedModels.push(
|
|
46270
|
-
new AcpConfigurationValueUnavailableError(
|
|
46271
|
-
baseModel?.id ?? "model",
|
|
46272
|
-
command.model,
|
|
46273
|
-
baseModel?.values.map((value) => value.value) ?? []
|
|
46274
|
-
)
|
|
46275
|
-
);
|
|
46276
|
-
} else {
|
|
46277
|
-
try {
|
|
46278
|
-
selectedSnapshot = await sessions.inspectAgentSettings({
|
|
46279
|
-
additionalDirectories: [],
|
|
46280
|
-
agent,
|
|
46281
|
-
cwd,
|
|
46282
|
-
model: command.model,
|
|
46283
|
-
signal
|
|
46284
|
-
});
|
|
46285
|
-
} catch (cause) {
|
|
46286
|
-
signal.throwIfAborted();
|
|
46287
|
-
if (!isUnavailableModel(cause, baseModel.id, command.model)) {
|
|
46288
|
-
throw cause;
|
|
46289
|
-
}
|
|
46290
|
-
unsupportedModels.push(cause);
|
|
46291
|
-
}
|
|
46292
|
-
}
|
|
46293
|
-
}
|
|
46294
|
-
const adapter = agentSettingsAdapterForAgent(agent.id);
|
|
46295
|
-
const modelEffort = await discoverModelEffort(
|
|
46296
|
-
command,
|
|
46297
|
-
agent,
|
|
46298
|
-
adapter.modelEffortResolution,
|
|
46299
|
-
baseSnapshot.configOptions,
|
|
46300
|
-
selectedSnapshot.configOptions,
|
|
46301
|
-
unsupportedModels,
|
|
46302
|
-
cwd,
|
|
46303
|
-
sessions,
|
|
46304
|
-
signal
|
|
46305
|
-
);
|
|
46306
|
-
const baseSettings = withoutUnsupportedModels(
|
|
46307
|
-
settingsFromSnapshot(agent, baseSnapshot.configOptions),
|
|
46308
|
-
baseModel?.id ?? "",
|
|
46309
|
-
modelEffort.unsupportedModelIds
|
|
46310
|
-
);
|
|
46311
|
-
const settings = withoutUnsupportedModels(
|
|
46312
|
-
settingsFromSnapshot(agent, selectedSnapshot.configOptions),
|
|
46313
|
-
baseModel?.id ?? "",
|
|
46314
|
-
modelEffort.unsupportedModelIds
|
|
46315
|
-
);
|
|
46316
|
-
return {
|
|
46317
|
-
event: {
|
|
46318
|
-
agentId: command.agentId,
|
|
46319
|
-
agentName: selectedSnapshot.agentName,
|
|
46320
|
-
agentVersion: selectedSnapshot.agentVersion,
|
|
46321
|
-
kind: AGENT_SETTINGS_DISCOVERED_KIND,
|
|
46322
|
-
modelEffort,
|
|
46323
|
-
requestId: command.requestId,
|
|
46324
|
-
settings,
|
|
46325
|
-
settingsRevision: settingsRevision(agent, baseSnapshot.agentVersion, baseSettings, modelEffort)
|
|
46326
|
-
},
|
|
46327
|
-
unsupportedModels
|
|
46328
|
-
};
|
|
46329
|
-
}
|
|
46330
|
-
function settingFromOption(option) {
|
|
46331
|
-
return {
|
|
46332
|
-
booleanValue: option.booleanValue,
|
|
46333
|
-
category: option.category,
|
|
46334
|
-
defaultValue: option.type === "boolean" ? "" : option.currentValue,
|
|
46335
|
-
description: option.description,
|
|
46336
|
-
id: option.id,
|
|
46337
|
-
name: option.name,
|
|
46338
|
-
type: option.type,
|
|
46339
|
-
values: option.values
|
|
46340
|
-
};
|
|
46341
|
-
}
|
|
46342
|
-
function settingsFromSnapshot(agent, configOptions) {
|
|
46343
|
-
const settings = [
|
|
46344
|
-
...agentSettingsAdapterForAgent(agent.id).settings(agent).map(settingFromOption),
|
|
46345
|
-
...configOptions.map(settingFromOption)
|
|
46346
|
-
];
|
|
46347
|
-
const identifiers = /* @__PURE__ */ new Set();
|
|
46348
|
-
for (const setting of settings) {
|
|
46349
|
-
if (identifiers.has(setting.id)) {
|
|
46350
|
-
throw new AcpExecutionError(
|
|
46351
|
-
"The Agent returned duplicate setting identifiers",
|
|
46352
|
-
{},
|
|
46353
|
-
"invalid_session_configuration"
|
|
46354
|
-
);
|
|
46355
|
-
}
|
|
46356
|
-
identifiers.add(setting.id);
|
|
46357
|
-
}
|
|
46358
|
-
if (settings.length > 128) {
|
|
46359
|
-
throw new AcpExecutionError("The Agent returned too many settings", {}, "invalid_session_configuration");
|
|
46360
|
-
}
|
|
46361
|
-
return settings;
|
|
46362
|
-
}
|
|
46363
|
-
function withoutUnsupportedModels(settings, modelSettingId, unsupportedModelIds2) {
|
|
46364
|
-
if (modelSettingId.length === 0 || unsupportedModelIds2.length === 0) {
|
|
46365
|
-
return settings;
|
|
46366
|
-
}
|
|
46367
|
-
const unsupported = new Set(unsupportedModelIds2);
|
|
46368
|
-
return settings.map((setting) => {
|
|
46369
|
-
if (setting.id !== modelSettingId || setting.type !== "select") {
|
|
46370
|
-
return setting;
|
|
46371
|
-
}
|
|
46372
|
-
return {
|
|
46373
|
-
...setting,
|
|
46374
|
-
defaultValue: unsupported.has(setting.defaultValue) ? "" : setting.defaultValue,
|
|
46375
|
-
values: setting.values.filter((value) => !unsupported.has(value.value))
|
|
46376
|
-
};
|
|
46377
|
-
});
|
|
46378
|
-
}
|
|
46379
|
-
function modelOption(options) {
|
|
46380
|
-
return options.find((option) => option.id === "model" || option.category === "model");
|
|
46381
|
-
}
|
|
46382
|
-
function effortOption(options) {
|
|
46383
|
-
return options.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
46384
|
-
}
|
|
46385
|
-
function unavailableModelEffort() {
|
|
46386
|
-
return {
|
|
46387
|
-
effortSettingId: "",
|
|
46388
|
-
modelSettingId: "",
|
|
46389
|
-
resolution: AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE,
|
|
46390
|
-
unsupportedModelIds: [],
|
|
46391
|
-
valuesByModel: {}
|
|
46392
|
-
};
|
|
46393
|
-
}
|
|
46394
|
-
async function discoverModelEffort(command, agent, resolution, initialOptions, selectedOptions, initiallyUnsupportedModels, cwd, sessions, signal) {
|
|
46395
|
-
const model = modelOption(initialOptions);
|
|
46396
|
-
const unsupportedModels = initiallyUnsupportedModels;
|
|
46397
|
-
if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
|
|
46398
|
-
return { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) };
|
|
46399
|
-
}
|
|
46400
|
-
if (model === void 0 || model.type !== "select" || model.values.length === 0) {
|
|
46401
|
-
return { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) };
|
|
46402
|
-
}
|
|
46403
|
-
const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
|
|
46404
|
-
additionalDirectories: [],
|
|
46405
|
-
agent,
|
|
46406
|
-
cwd,
|
|
46407
|
-
model: modelValue,
|
|
46408
|
-
signal
|
|
46409
|
-
})).configOptions;
|
|
46410
|
-
const valuesByModel = {};
|
|
46411
|
-
if (resolution === "complete") {
|
|
46412
|
-
const effort = effortOption(initialOptions);
|
|
46413
|
-
if (effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
|
|
46414
|
-
return {
|
|
46415
|
-
...unavailableModelEffort(),
|
|
46416
|
-
unsupportedModelIds: unsupportedModelIds(unsupportedModels)
|
|
46417
|
-
};
|
|
46418
|
-
}
|
|
46419
|
-
for (const value of model.values) {
|
|
46420
|
-
if (unsupportedModels.some((diagnostic) => diagnostic.requestedValue === value.value)) {
|
|
46421
|
-
continue;
|
|
46422
|
-
}
|
|
46423
|
-
try {
|
|
46424
|
-
const selectedEffort2 = effortOption(await inspectModel(value.value));
|
|
46425
|
-
valuesByModel[value.value] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
46426
|
-
} catch (cause) {
|
|
46427
|
-
signal.throwIfAborted();
|
|
46428
|
-
if (!isUnavailableModel(cause, model.id, value.value)) {
|
|
46429
|
-
throw cause;
|
|
46430
|
-
}
|
|
46431
|
-
unsupportedModels.push(cause);
|
|
46432
|
-
}
|
|
46433
|
-
}
|
|
46434
|
-
return {
|
|
46435
|
-
effortSettingId: effort.id,
|
|
46436
|
-
modelSettingId: model.id,
|
|
46437
|
-
resolution: "complete",
|
|
46438
|
-
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
46439
|
-
valuesByModel
|
|
46440
|
-
};
|
|
46441
|
-
}
|
|
46442
|
-
if (command.model !== void 0) {
|
|
46443
|
-
const modelUnsupported = unsupportedModels.some((diagnostic) => diagnostic.requestedValue === command.model);
|
|
46444
|
-
const selectedEffort2 = effortOption(selectedOptions);
|
|
46445
|
-
if (!modelUnsupported) {
|
|
46446
|
-
valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
46447
|
-
}
|
|
46448
|
-
return {
|
|
46449
|
-
effortSettingId: selectedEffort2?.id ?? "",
|
|
46450
|
-
modelSettingId: model.id,
|
|
46451
|
-
resolution: "on_model_selection",
|
|
46452
|
-
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
46453
|
-
valuesByModel
|
|
46454
|
-
};
|
|
46455
|
-
}
|
|
46456
|
-
const defaultModel = model.type === "select" ? model.currentValue : "";
|
|
46457
|
-
const reportedEffort = effortOption(selectedOptions);
|
|
46458
|
-
let selectedEffort = reportedEffort;
|
|
46459
|
-
if (defaultModel.length > 0 && reportedEffort === void 0) {
|
|
46460
|
-
try {
|
|
46461
|
-
selectedEffort = effortOption(await inspectModel(defaultModel));
|
|
46462
|
-
} catch (cause) {
|
|
46463
|
-
signal.throwIfAborted();
|
|
46464
|
-
if (!isUnavailableModel(cause, model.id, defaultModel)) {
|
|
46465
|
-
throw cause;
|
|
46466
|
-
}
|
|
46467
|
-
unsupportedModels.push(cause);
|
|
46468
|
-
}
|
|
46469
|
-
}
|
|
46470
|
-
if (defaultModel.length > 0 && !unsupportedModels.some((diagnostic) => diagnostic.requestedValue === defaultModel)) {
|
|
46471
|
-
valuesByModel[defaultModel] = selectedEffort?.type === "select" ? selectedEffort.values : [];
|
|
46472
|
-
}
|
|
46473
|
-
return {
|
|
46474
|
-
effortSettingId: selectedEffort?.id ?? "",
|
|
46475
|
-
modelSettingId: model.id,
|
|
46476
|
-
resolution: "on_model_selection",
|
|
46477
|
-
unsupportedModelIds: unsupportedModelIds(unsupportedModels),
|
|
46478
|
-
valuesByModel
|
|
46479
|
-
};
|
|
46480
|
-
}
|
|
46481
|
-
function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
|
|
46482
|
-
const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
|
|
46483
|
-
effortSettingId: "",
|
|
46484
|
-
modelSettingId: modelEffort.modelSettingId,
|
|
46485
|
-
resolution: modelEffort.resolution,
|
|
46486
|
-
unsupportedModelIds: modelEffort.unsupportedModelIds,
|
|
46487
|
-
valuesByModel: {}
|
|
46488
|
-
};
|
|
46489
|
-
return createHash5("sha256").update(
|
|
46490
|
-
JSON.stringify({
|
|
46491
|
-
adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
|
|
46492
|
-
agentId: agent.id,
|
|
46493
|
-
agentVersion: agent.agentVersion,
|
|
46494
|
-
modelEffort: revisionModelEffort,
|
|
46495
|
-
reportedAgentVersion,
|
|
46496
|
-
settings
|
|
46497
|
-
})
|
|
46498
|
-
).digest("hex");
|
|
46499
|
-
}
|
|
46500
46749
|
async function executeWorkspaceList(socket, command, directories, audit, signal) {
|
|
46501
46750
|
try {
|
|
46502
46751
|
const listing = await directories.list(command.bindingId, command.directoryId, signal);
|
|
@@ -47002,187 +47251,6 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
47002
47251
|
console.error("Mobius daemon command failed", error62);
|
|
47003
47252
|
}
|
|
47004
47253
|
}
|
|
47005
|
-
function invalidSessionConfiguration(message) {
|
|
47006
|
-
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
47007
|
-
}
|
|
47008
|
-
function agentForSessionConfiguration(agent, selections) {
|
|
47009
|
-
try {
|
|
47010
|
-
return applyAgentLaunchSettings(agent, selections);
|
|
47011
|
-
} catch (error62) {
|
|
47012
|
-
if (error62 instanceof Error) {
|
|
47013
|
-
throw invalidSessionConfiguration(error62.message);
|
|
47014
|
-
}
|
|
47015
|
-
throw error62;
|
|
47016
|
-
}
|
|
47017
|
-
}
|
|
47018
|
-
function validateSessionConfigurationSelection(option, selection) {
|
|
47019
|
-
if (option.type !== selection.valueType) {
|
|
47020
|
-
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
47021
|
-
}
|
|
47022
|
-
if (option.type === "boolean") {
|
|
47023
|
-
if (selection.value.length > 0) {
|
|
47024
|
-
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
47025
|
-
}
|
|
47026
|
-
return;
|
|
47027
|
-
}
|
|
47028
|
-
if (selection.booleanValue) {
|
|
47029
|
-
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
47030
|
-
}
|
|
47031
|
-
if (!option.values.some((value) => value.value === selection.value)) {
|
|
47032
|
-
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
47033
|
-
}
|
|
47034
|
-
}
|
|
47035
|
-
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
47036
|
-
if (option.type !== selection.valueType) {
|
|
47037
|
-
return false;
|
|
47038
|
-
}
|
|
47039
|
-
if (option.type === "boolean") {
|
|
47040
|
-
return selection.value.length === 0;
|
|
47041
|
-
}
|
|
47042
|
-
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
47043
|
-
}
|
|
47044
|
-
function sessionConfigurationMatches(option, selection) {
|
|
47045
|
-
validateSessionConfigurationSelection(option, selection);
|
|
47046
|
-
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
47047
|
-
}
|
|
47048
|
-
function sessionConfigurationPriority(selection, options) {
|
|
47049
|
-
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
47050
|
-
if (selection.configId === "model" || option?.category === "model") {
|
|
47051
|
-
return 0;
|
|
47052
|
-
}
|
|
47053
|
-
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
47054
|
-
return 1;
|
|
47055
|
-
}
|
|
47056
|
-
if (option?.category === "model_config") {
|
|
47057
|
-
return 2;
|
|
47058
|
-
}
|
|
47059
|
-
return 3;
|
|
47060
|
-
}
|
|
47061
|
-
function assertAppliedSessionConfiguration(options, selections) {
|
|
47062
|
-
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
47063
|
-
for (const option of options) {
|
|
47064
|
-
const selection = selectionsById.get(option.id);
|
|
47065
|
-
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
47066
|
-
continue;
|
|
47067
|
-
}
|
|
47068
|
-
if (!sessionConfigurationMatches(option, selection)) {
|
|
47069
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
47070
|
-
}
|
|
47071
|
-
}
|
|
47072
|
-
}
|
|
47073
|
-
function unavailableSessionConfigurationCategory(selection) {
|
|
47074
|
-
if (selection.configId === "model") {
|
|
47075
|
-
return "model";
|
|
47076
|
-
}
|
|
47077
|
-
if (selection.configId === "reasoning_effort") {
|
|
47078
|
-
return "thought_level";
|
|
47079
|
-
}
|
|
47080
|
-
return "unknown";
|
|
47081
|
-
}
|
|
47082
|
-
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
47083
|
-
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
47084
|
-
if (option === void 0) {
|
|
47085
|
-
warnIgnoredSetting(
|
|
47086
|
-
audit,
|
|
47087
|
-
"session_configuration_setting_ignored",
|
|
47088
|
-
commandId,
|
|
47089
|
-
sessionId,
|
|
47090
|
-
agent.id,
|
|
47091
|
-
selection,
|
|
47092
|
-
unavailableSessionConfigurationCategory(selection),
|
|
47093
|
-
"setting_unavailable"
|
|
47094
|
-
);
|
|
47095
|
-
return options;
|
|
47096
|
-
}
|
|
47097
|
-
if (option.type !== selection.valueType) {
|
|
47098
|
-
warnIgnoredSetting(
|
|
47099
|
-
audit,
|
|
47100
|
-
"session_configuration_setting_ignored",
|
|
47101
|
-
commandId,
|
|
47102
|
-
sessionId,
|
|
47103
|
-
agent.id,
|
|
47104
|
-
selection,
|
|
47105
|
-
option.category,
|
|
47106
|
-
"setting_schema_mismatch"
|
|
47107
|
-
);
|
|
47108
|
-
return options;
|
|
47109
|
-
}
|
|
47110
|
-
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
47111
|
-
warnIgnoredSetting(
|
|
47112
|
-
audit,
|
|
47113
|
-
"session_configuration_setting_ignored",
|
|
47114
|
-
commandId,
|
|
47115
|
-
sessionId,
|
|
47116
|
-
agent.id,
|
|
47117
|
-
selection,
|
|
47118
|
-
option.category,
|
|
47119
|
-
"selection_schema_mismatch"
|
|
47120
|
-
);
|
|
47121
|
-
return options;
|
|
47122
|
-
}
|
|
47123
|
-
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
47124
|
-
warnIgnoredSetting(
|
|
47125
|
-
audit,
|
|
47126
|
-
"session_configuration_setting_ignored",
|
|
47127
|
-
commandId,
|
|
47128
|
-
sessionId,
|
|
47129
|
-
agent.id,
|
|
47130
|
-
selection,
|
|
47131
|
-
option.category,
|
|
47132
|
-
"value_unavailable"
|
|
47133
|
-
);
|
|
47134
|
-
return options;
|
|
47135
|
-
}
|
|
47136
|
-
if (sessionConfigurationMatches(option, selection)) {
|
|
47137
|
-
return options;
|
|
47138
|
-
}
|
|
47139
|
-
return await sessions.configureSession({
|
|
47140
|
-
additionalDirectories,
|
|
47141
|
-
agent,
|
|
47142
|
-
booleanValue: selection.booleanValue,
|
|
47143
|
-
configId: selection.configId,
|
|
47144
|
-
cwd,
|
|
47145
|
-
requestId: `cfg_${randomUUID4()}`,
|
|
47146
|
-
sessionId,
|
|
47147
|
-
signal,
|
|
47148
|
-
value: selection.value,
|
|
47149
|
-
valueType: selection.valueType
|
|
47150
|
-
});
|
|
47151
|
-
}
|
|
47152
|
-
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
47153
|
-
let options = initialOptions;
|
|
47154
|
-
const orderedSelections = selections.toSorted((left, right) => {
|
|
47155
|
-
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
47156
|
-
return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
|
|
47157
|
-
});
|
|
47158
|
-
for (const selection of orderedSelections) {
|
|
47159
|
-
options = await applySessionConfigurationSelection(
|
|
47160
|
-
sessions,
|
|
47161
|
-
audit,
|
|
47162
|
-
options,
|
|
47163
|
-
selection,
|
|
47164
|
-
agent,
|
|
47165
|
-
cwd,
|
|
47166
|
-
additionalDirectories,
|
|
47167
|
-
commandId,
|
|
47168
|
-
sessionId,
|
|
47169
|
-
signal
|
|
47170
|
-
);
|
|
47171
|
-
}
|
|
47172
|
-
assertAppliedSessionConfiguration(options, selections);
|
|
47173
|
-
}
|
|
47174
|
-
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
47175
|
-
const details = {
|
|
47176
|
-
agentId,
|
|
47177
|
-
category,
|
|
47178
|
-
configId: selection.configId,
|
|
47179
|
-
reason,
|
|
47180
|
-
requestedValue: selection.value
|
|
47181
|
-
};
|
|
47182
|
-
audit.record({ commandId, details, event, sessionId });
|
|
47183
|
-
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
47184
|
-
`);
|
|
47185
|
-
}
|
|
47186
47254
|
function waitForRelayRetry(signal, timer) {
|
|
47187
47255
|
if (signal.aborted) {
|
|
47188
47256
|
return Promise.resolve();
|
|
@@ -47229,7 +47297,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
47229
47297
|
{
|
|
47230
47298
|
agentId: agent.id,
|
|
47231
47299
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
47232
|
-
requestId: `automatic-integration-${
|
|
47300
|
+
requestId: `automatic-integration-${randomUUID5()}`
|
|
47233
47301
|
},
|
|
47234
47302
|
signal
|
|
47235
47303
|
);
|