@moxt-ai/mobius 0.0.131 → 0.0.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/agent-query-processes.d.ts.map +1 -1
- package/dist/acp/agent-query-processes.js +2 -1
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +57 -52
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/runtime-operations.d.ts +11 -0
- package/dist/acp/runtime-operations.d.ts.map +1 -0
- package/dist/acp/runtime-operations.js +45 -0
- package/dist/acp/runtime-operations.js.map +1 -0
- package/dist/cli.js +203 -147
- package/dist/cli.js.map +4 -4
- package/dist/index.js +202 -146
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +202 -146
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -35443,6 +35443,48 @@ var RetainedAgentProcesses = class {
|
|
|
35443
35443
|
};
|
|
35444
35444
|
};
|
|
35445
35445
|
|
|
35446
|
+
// src/acp/runtime-operations.ts
|
|
35447
|
+
var RuntimeOperations = class {
|
|
35448
|
+
#shutdown = new AbortController();
|
|
35449
|
+
#pending = /* @__PURE__ */ new Set();
|
|
35450
|
+
#closing = null;
|
|
35451
|
+
run = async (options, operation) => {
|
|
35452
|
+
const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
|
|
35453
|
+
signal.throwIfAborted();
|
|
35454
|
+
const pending = Promise.resolve().then(() => operation({ ...options, signal }));
|
|
35455
|
+
this.#pending.add(pending);
|
|
35456
|
+
try {
|
|
35457
|
+
const result = await pending;
|
|
35458
|
+
signal.throwIfAborted();
|
|
35459
|
+
return result;
|
|
35460
|
+
} finally {
|
|
35461
|
+
this.#pending.delete(pending);
|
|
35462
|
+
}
|
|
35463
|
+
};
|
|
35464
|
+
close = (release) => {
|
|
35465
|
+
if (this.#closing !== null) {
|
|
35466
|
+
return this.#closing;
|
|
35467
|
+
}
|
|
35468
|
+
this.#shutdown.abort();
|
|
35469
|
+
this.#closing = (async () => {
|
|
35470
|
+
await Promise.allSettled([...this.#pending]);
|
|
35471
|
+
await release();
|
|
35472
|
+
})();
|
|
35473
|
+
return this.#closing;
|
|
35474
|
+
};
|
|
35475
|
+
};
|
|
35476
|
+
async function waitForPreparation(pending, signal) {
|
|
35477
|
+
signal.throwIfAborted();
|
|
35478
|
+
const cancelled = Promise.withResolvers();
|
|
35479
|
+
const abort = () => cancelled.reject(signal.reason);
|
|
35480
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
35481
|
+
try {
|
|
35482
|
+
return await Promise.race([pending, cancelled.promise]);
|
|
35483
|
+
} finally {
|
|
35484
|
+
signal.removeEventListener("abort", abort);
|
|
35485
|
+
}
|
|
35486
|
+
}
|
|
35487
|
+
|
|
35446
35488
|
// src/acp/agent-query-processes.ts
|
|
35447
35489
|
var AgentQueryProcesses = class {
|
|
35448
35490
|
#processesByQuery;
|
|
@@ -35489,7 +35531,7 @@ var AgentQueryProcesses = class {
|
|
|
35489
35531
|
prepare = async (options) => {
|
|
35490
35532
|
const pending = this.#processesByQuery.pending(options.sessionId);
|
|
35491
35533
|
if (pending !== void 0) {
|
|
35492
|
-
const runtime2 = await pending;
|
|
35534
|
+
const runtime2 = await waitForPreparation(pending, options.signal);
|
|
35493
35535
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
35494
35536
|
this.#processesByQuery.touch(options.sessionId, runtime2);
|
|
35495
35537
|
return runtime2.prepared();
|
|
@@ -35768,6 +35810,7 @@ var AgentProcessPool = class {
|
|
|
35768
35810
|
// src/acp/agent-runtime-manager.ts
|
|
35769
35811
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
35770
35812
|
var AgentRuntimeManager = class {
|
|
35813
|
+
#operations = new RuntimeOperations();
|
|
35771
35814
|
#processes = new AgentProcessPool();
|
|
35772
35815
|
#executionProcesses = new RetainedAgentProcesses({
|
|
35773
35816
|
touch: this.#processes.touch,
|
|
@@ -35890,8 +35933,8 @@ var AgentRuntimeManager = class {
|
|
|
35890
35933
|
return runtime;
|
|
35891
35934
|
});
|
|
35892
35935
|
}
|
|
35893
|
-
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
35894
|
-
const stored = metrics.measureSync("session-state-read", () => this.#store.read(
|
|
35936
|
+
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
35937
|
+
const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
|
|
35895
35938
|
if (stored instanceof DeletedAcpStoredSession) {
|
|
35896
35939
|
throw new AcpExecutionError(
|
|
35897
35940
|
"The native Agent session was deleted. Start a new chat.",
|
|
@@ -35902,19 +35945,22 @@ var AgentRuntimeManager = class {
|
|
|
35902
35945
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
35903
35946
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
35904
35947
|
}
|
|
35905
|
-
const pending = this.#executionProcesses.pending(
|
|
35948
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
35906
35949
|
if (pending !== void 0) {
|
|
35907
|
-
const runtime2 = await metrics.measure(
|
|
35908
|
-
|
|
35909
|
-
|
|
35950
|
+
const runtime2 = await metrics.measure(
|
|
35951
|
+
"session-preparation-wait",
|
|
35952
|
+
async () => await waitForPreparation(pending, options2.signal)
|
|
35953
|
+
);
|
|
35954
|
+
if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
35955
|
+
this.#executionProcesses.touch(options2.sessionId, runtime2);
|
|
35910
35956
|
return runtime2.prepared();
|
|
35911
35957
|
}
|
|
35912
|
-
return await this.prepareSession(
|
|
35958
|
+
return await this.prepareSession(options2, metrics);
|
|
35913
35959
|
}
|
|
35914
|
-
const existing = this.#executionProcesses.get(
|
|
35960
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
35915
35961
|
if (existing !== void 0) {
|
|
35916
|
-
if (existing.belongsTo(
|
|
35917
|
-
this.#executionProcesses.touch(
|
|
35962
|
+
if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
35963
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
35918
35964
|
return existing.prepared();
|
|
35919
35965
|
}
|
|
35920
35966
|
if (!existing.canRebind()) {
|
|
@@ -35924,85 +35970,91 @@ var AgentRuntimeManager = class {
|
|
|
35924
35970
|
"session_identity_mismatch"
|
|
35925
35971
|
);
|
|
35926
35972
|
}
|
|
35927
|
-
const runtime2 = await this.#replacePreparation(existing,
|
|
35973
|
+
const runtime2 = await this.#replacePreparation(existing, options2, metrics);
|
|
35928
35974
|
return runtime2.prepared();
|
|
35929
35975
|
}
|
|
35930
|
-
const runtime = await this.#startPreparation(
|
|
35976
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
35931
35977
|
return runtime.prepared();
|
|
35932
|
-
};
|
|
35978
|
+
});
|
|
35933
35979
|
/**
|
|
35934
35980
|
* Opens a short-lived native ACP session only to read the local Agent's
|
|
35935
35981
|
* authoritative settings. Its identity and store are private to this
|
|
35936
35982
|
* operation and never become a Mobius Session.
|
|
35937
35983
|
*/
|
|
35938
|
-
inspectAgentSettings = async (options) =>
|
|
35939
|
-
|
|
35940
|
-
|
|
35941
|
-
|
|
35942
|
-
|
|
35943
|
-
|
|
35984
|
+
inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
|
|
35985
|
+
return await this.#processes.runTransient(
|
|
35986
|
+
options2.signal,
|
|
35987
|
+
async () => await AgentSession.start(
|
|
35988
|
+
{
|
|
35989
|
+
...options2,
|
|
35990
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`
|
|
35991
|
+
},
|
|
35992
|
+
() => this.#agentSettingsObserver,
|
|
35993
|
+
new MemoryAcpSessionStore()
|
|
35994
|
+
),
|
|
35995
|
+
async (runtime) => {
|
|
35996
|
+
const prepared = runtime.prepared();
|
|
35997
|
+
const model = options2.model;
|
|
35998
|
+
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
35999
|
+
...options2,
|
|
36000
|
+
booleanValue: false,
|
|
36001
|
+
configId: prepared.configOptions.find(
|
|
36002
|
+
(option) => option.id === "model" || option.category === "model"
|
|
36003
|
+
)?.id ?? "model",
|
|
36004
|
+
requestId: "agent-settings-model",
|
|
36005
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
36006
|
+
value: model,
|
|
36007
|
+
valueType: "select"
|
|
36008
|
+
});
|
|
36009
|
+
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
35944
36010
|
},
|
|
35945
|
-
() =>
|
|
35946
|
-
|
|
35947
|
-
|
|
35948
|
-
async (runtime) => {
|
|
35949
|
-
const prepared = runtime.prepared();
|
|
35950
|
-
const model = options.model;
|
|
35951
|
-
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
35952
|
-
...options,
|
|
35953
|
-
booleanValue: false,
|
|
35954
|
-
configId: prepared.configOptions.find(
|
|
35955
|
-
(option) => option.id === "model" || option.category === "model"
|
|
35956
|
-
)?.id ?? "model",
|
|
35957
|
-
requestId: "agent-settings-model",
|
|
35958
|
-
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
35959
|
-
value: model,
|
|
35960
|
-
valueType: "select"
|
|
35961
|
-
});
|
|
35962
|
-
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
35963
|
-
},
|
|
35964
|
-
async (runtime) => await runtime.close()
|
|
35965
|
-
);
|
|
36011
|
+
async (runtime) => await runtime.close()
|
|
36012
|
+
);
|
|
36013
|
+
});
|
|
35966
36014
|
/**
|
|
35967
36015
|
* Retained for Agents that expose a separate persisted configuration channel.
|
|
35968
36016
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
35969
36017
|
*/
|
|
35970
|
-
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
35971
|
-
if (this.#executionProcesses.pending(
|
|
35972
|
-
throw new AcpExecutionError(
|
|
36018
|
+
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
36019
|
+
if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
|
|
36020
|
+
throw new AcpExecutionError(
|
|
36021
|
+
"The configuration inspection session is already in use",
|
|
36022
|
+
{},
|
|
36023
|
+
"session_busy"
|
|
36024
|
+
);
|
|
35973
36025
|
}
|
|
35974
|
-
return await this.#executionProcesses.use(
|
|
35975
|
-
const runtime = await this.#startPreparation(
|
|
36026
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
36027
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
35976
36028
|
try {
|
|
35977
36029
|
return runtime.prepared();
|
|
35978
36030
|
} finally {
|
|
35979
36031
|
try {
|
|
35980
|
-
await this.#retireSessionProcess(
|
|
36032
|
+
await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
|
|
35981
36033
|
} finally {
|
|
35982
|
-
this.#store.remove(
|
|
36034
|
+
this.#store.remove(options2.sessionId);
|
|
35983
36035
|
}
|
|
35984
36036
|
}
|
|
35985
36037
|
});
|
|
35986
|
-
};
|
|
35987
|
-
prepareExecutionSession = async (options) => {
|
|
35988
|
-
const pending = this.#executionProcesses.pending(
|
|
36038
|
+
});
|
|
36039
|
+
prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
36040
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
35989
36041
|
if (pending !== void 0) {
|
|
35990
|
-
await pending;
|
|
35991
|
-
return await this.prepareExecutionSession(
|
|
36042
|
+
await waitForPreparation(pending, options2.signal);
|
|
36043
|
+
return await this.prepareExecutionSession(options2);
|
|
35992
36044
|
}
|
|
35993
|
-
const existing = this.#executionProcesses.get(
|
|
36045
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
35994
36046
|
if (existing === void 0) {
|
|
35995
|
-
return (await this.#startPreparation(
|
|
36047
|
+
return (await this.#startPreparation(options2)).prepared();
|
|
35996
36048
|
}
|
|
35997
|
-
if (!existing.belongsTo(
|
|
36049
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
35998
36050
|
throw new AcpExecutionError(
|
|
35999
36051
|
"The agent or workspace cannot change after a conversation has started",
|
|
36000
36052
|
{},
|
|
36001
36053
|
"session_identity_mismatch"
|
|
36002
36054
|
);
|
|
36003
36055
|
}
|
|
36004
|
-
if (existing.usesEnvironment(
|
|
36005
|
-
this.#executionProcesses.touch(
|
|
36056
|
+
if (existing.usesEnvironment(options2.agent.environment)) {
|
|
36057
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
36006
36058
|
return existing.prepared();
|
|
36007
36059
|
}
|
|
36008
36060
|
if (existing.hasRunningTurn()) {
|
|
@@ -36012,15 +36064,15 @@ var AgentRuntimeManager = class {
|
|
|
36012
36064
|
"session_busy"
|
|
36013
36065
|
);
|
|
36014
36066
|
}
|
|
36015
|
-
return (await this.#replaceExecutionPreparation(existing,
|
|
36016
|
-
};
|
|
36017
|
-
prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(
|
|
36018
|
-
configureSession = async (options) => {
|
|
36019
|
-
return await this.#executionProcesses.use(
|
|
36020
|
-
const runtime = await this.ensureSession(
|
|
36021
|
-
return await runtime.configure(
|
|
36067
|
+
return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
|
|
36068
|
+
});
|
|
36069
|
+
prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
|
|
36070
|
+
configureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
36071
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
36072
|
+
const runtime = await this.ensureSession(options2);
|
|
36073
|
+
return await runtime.configure(options2);
|
|
36022
36074
|
});
|
|
36023
|
-
};
|
|
36075
|
+
});
|
|
36024
36076
|
cancelPrompt = async (sessionId) => {
|
|
36025
36077
|
await this.#executions.cancel(sessionId, async () => {
|
|
36026
36078
|
const runtime = this.#executionProcesses.get(sessionId);
|
|
@@ -36035,19 +36087,19 @@ var AgentRuntimeManager = class {
|
|
|
36035
36087
|
}
|
|
36036
36088
|
});
|
|
36037
36089
|
};
|
|
36038
|
-
steerPrompt = async (options) => {
|
|
36039
|
-
if (this.#executions.command(
|
|
36090
|
+
steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
36091
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
36040
36092
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
36041
36093
|
}
|
|
36042
|
-
const pending = this.#executionProcesses.pending(
|
|
36094
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
36043
36095
|
if (pending !== void 0) {
|
|
36044
|
-
await pending;
|
|
36096
|
+
await waitForPreparation(pending, options2.signal);
|
|
36045
36097
|
}
|
|
36046
|
-
if (this.#executions.command(
|
|
36098
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
36047
36099
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
36048
36100
|
}
|
|
36049
|
-
const runtime = this.#executionProcesses.get(
|
|
36050
|
-
if (runtime === void 0 || !runtime.belongsTo(
|
|
36101
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
36102
|
+
if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
36051
36103
|
throw new AcpExecutionError(
|
|
36052
36104
|
"The target turn execution context is unavailable",
|
|
36053
36105
|
{},
|
|
@@ -36064,8 +36116,8 @@ var AgentRuntimeManager = class {
|
|
|
36064
36116
|
deadline.unref();
|
|
36065
36117
|
try {
|
|
36066
36118
|
return await runtime.steer({
|
|
36067
|
-
...
|
|
36068
|
-
signal: AbortSignal.any([
|
|
36119
|
+
...options2,
|
|
36120
|
+
signal: AbortSignal.any([options2.signal, deadlineController.signal])
|
|
36069
36121
|
});
|
|
36070
36122
|
} catch (error62) {
|
|
36071
36123
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -36075,44 +36127,44 @@ var AgentRuntimeManager = class {
|
|
|
36075
36127
|
} finally {
|
|
36076
36128
|
clearTimeout(deadline);
|
|
36077
36129
|
}
|
|
36078
|
-
};
|
|
36079
|
-
runPrompt = async (options) => {
|
|
36080
|
-
const stored = this.#store.read(
|
|
36130
|
+
});
|
|
36131
|
+
runPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
36132
|
+
const stored = this.#store.read(options2.sessionId);
|
|
36081
36133
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
36082
36134
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
36083
36135
|
}
|
|
36084
|
-
this.#executions.begin(
|
|
36136
|
+
this.#executions.begin(options2.sessionId, options2.commandId);
|
|
36085
36137
|
try {
|
|
36086
|
-
if (this.#executions.cancellation(
|
|
36138
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
36087
36139
|
return { stopReason: "cancelled" };
|
|
36088
36140
|
}
|
|
36089
|
-
const runtime = await this.ensureSession(
|
|
36090
|
-
if (this.#nativeOperations.has(`${
|
|
36141
|
+
const runtime = await this.ensureSession(options2);
|
|
36142
|
+
if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
|
|
36091
36143
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
36092
36144
|
}
|
|
36093
|
-
if (this.#executions.cancellation(
|
|
36145
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
36094
36146
|
return { stopReason: "cancelled" };
|
|
36095
36147
|
}
|
|
36096
36148
|
try {
|
|
36097
|
-
const result = await runtime.prompt(
|
|
36098
|
-
return this.#executions.cancellation(
|
|
36149
|
+
const result = await runtime.prompt(options2);
|
|
36150
|
+
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
36099
36151
|
} catch (error62) {
|
|
36100
|
-
if (this.#executions.cancellation(
|
|
36101
|
-
await this.#executions.cancellation(
|
|
36152
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
36153
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
36102
36154
|
return { stopReason: "cancelled" };
|
|
36103
36155
|
}
|
|
36104
36156
|
throw error62;
|
|
36105
36157
|
}
|
|
36106
36158
|
} catch (error62) {
|
|
36107
|
-
const failedRuntime = this.#executionProcesses.get(
|
|
36159
|
+
const failedRuntime = this.#executionProcesses.get(options2.sessionId);
|
|
36108
36160
|
if (failedRuntime !== void 0) {
|
|
36109
36161
|
await this.#retireSessionProcess(
|
|
36110
|
-
|
|
36162
|
+
options2.sessionId,
|
|
36111
36163
|
failedRuntime,
|
|
36112
36164
|
async () => await failedRuntime.close()
|
|
36113
36165
|
);
|
|
36114
36166
|
}
|
|
36115
|
-
if (this.#executions.cancellation(
|
|
36167
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
36116
36168
|
return { stopReason: "cancelled" };
|
|
36117
36169
|
}
|
|
36118
36170
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -36123,14 +36175,14 @@ var AgentRuntimeManager = class {
|
|
|
36123
36175
|
});
|
|
36124
36176
|
} finally {
|
|
36125
36177
|
try {
|
|
36126
|
-
await this.#executions.cancellation(
|
|
36178
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
36127
36179
|
} finally {
|
|
36128
|
-
this.#executions.finish(
|
|
36129
|
-
this.#executionProcesses.touch(
|
|
36180
|
+
this.#executions.finish(options2.sessionId, options2.commandId);
|
|
36181
|
+
this.#executionProcesses.touch(options2.sessionId);
|
|
36130
36182
|
this.#processes.notifyChanged();
|
|
36131
36183
|
}
|
|
36132
36184
|
}
|
|
36133
|
-
};
|
|
36185
|
+
});
|
|
36134
36186
|
respondPermission = async (options) => {
|
|
36135
36187
|
const runtime = this.#executionProcesses.get(options.sessionId);
|
|
36136
36188
|
if (runtime === void 0) {
|
|
@@ -36145,7 +36197,7 @@ var AgentRuntimeManager = class {
|
|
|
36145
36197
|
}
|
|
36146
36198
|
await runtime.respondElicitation(options);
|
|
36147
36199
|
};
|
|
36148
|
-
close = async () => {
|
|
36200
|
+
close = async () => this.#operations.close(async () => {
|
|
36149
36201
|
const sessions = [...this.#executionProcesses.entries()];
|
|
36150
36202
|
await Promise.all([
|
|
36151
36203
|
...sessions.map(
|
|
@@ -36153,23 +36205,23 @@ var AgentRuntimeManager = class {
|
|
|
36153
36205
|
),
|
|
36154
36206
|
this.#queryProcesses.close()
|
|
36155
36207
|
]);
|
|
36156
|
-
};
|
|
36208
|
+
});
|
|
36157
36209
|
findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
|
|
36158
36210
|
const stored = this.#store.read(sessionId);
|
|
36159
36211
|
return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
|
|
36160
36212
|
});
|
|
36161
36213
|
findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
|
|
36162
36214
|
hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
|
|
36163
|
-
createNativeSession = async (options) => {
|
|
36215
|
+
createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
36164
36216
|
const temporarySessionId = `new-${crypto.randomUUID()}`;
|
|
36165
|
-
const temporaryOptions = { ...
|
|
36217
|
+
const temporaryOptions = { ...options2, sessionId: temporarySessionId };
|
|
36166
36218
|
return await this.#executionProcesses.use(temporarySessionId, async () => {
|
|
36167
36219
|
try {
|
|
36168
36220
|
const runtime = await this.#startPreparation(temporaryOptions);
|
|
36169
36221
|
let adopted = false;
|
|
36170
36222
|
try {
|
|
36171
36223
|
const nativeSessionId = runtime.nativeSessionId();
|
|
36172
|
-
if (!isNativeChatSessionId(
|
|
36224
|
+
if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
|
|
36173
36225
|
throw new AcpExecutionError(
|
|
36174
36226
|
"The Agent returned an invalid new Session ID",
|
|
36175
36227
|
{},
|
|
@@ -36195,36 +36247,36 @@ var AgentRuntimeManager = class {
|
|
|
36195
36247
|
this.#store.remove(temporarySessionId);
|
|
36196
36248
|
}
|
|
36197
36249
|
});
|
|
36198
|
-
};
|
|
36199
|
-
ensureSession = async (options) => {
|
|
36200
|
-
const existing = this.#executionProcesses.get(
|
|
36250
|
+
});
|
|
36251
|
+
ensureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
36252
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
36201
36253
|
if (existing !== void 0) {
|
|
36202
|
-
if (!existing.belongsTo(
|
|
36254
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
36203
36255
|
throw new AcpExecutionError(
|
|
36204
36256
|
"The agent or workspace cannot change after a conversation has started",
|
|
36205
36257
|
{},
|
|
36206
36258
|
"session_identity_mismatch"
|
|
36207
36259
|
);
|
|
36208
36260
|
}
|
|
36209
|
-
this.#executionProcesses.touch(
|
|
36261
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
36210
36262
|
return existing;
|
|
36211
36263
|
}
|
|
36212
|
-
await this.prepareSession(
|
|
36213
|
-
const started = this.#executionProcesses.get(
|
|
36264
|
+
await this.prepareSession(options2);
|
|
36265
|
+
const started = this.#executionProcesses.get(options2.sessionId);
|
|
36214
36266
|
if (started === void 0) {
|
|
36215
36267
|
throw new AcpExecutionError("ACP session did not start");
|
|
36216
36268
|
}
|
|
36217
36269
|
return started;
|
|
36218
|
-
};
|
|
36219
|
-
listNativeSessions = async (options, cursor) => {
|
|
36270
|
+
});
|
|
36271
|
+
listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
|
|
36220
36272
|
return await this.#queryProcesses.use(
|
|
36221
|
-
|
|
36222
|
-
async (runtime) => await runtime.listNativeSessions(cursor,
|
|
36273
|
+
options2,
|
|
36274
|
+
async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
|
|
36223
36275
|
);
|
|
36224
|
-
};
|
|
36225
|
-
previewNativeSession = async (options, nativeSessionId) => {
|
|
36226
|
-
const key = `${
|
|
36227
|
-
const linked = this.#store.findNative(
|
|
36276
|
+
});
|
|
36277
|
+
previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
36278
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
36279
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
36228
36280
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
36229
36281
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
36230
36282
|
)) {
|
|
@@ -36236,18 +36288,18 @@ var AgentRuntimeManager = class {
|
|
|
36236
36288
|
}
|
|
36237
36289
|
this.#nativeOperations.add(key);
|
|
36238
36290
|
try {
|
|
36239
|
-
return await this.#queryProcesses.preview(
|
|
36291
|
+
return await this.#queryProcesses.preview(options2, nativeSessionId);
|
|
36240
36292
|
} finally {
|
|
36241
36293
|
this.#nativeOperations.delete(key);
|
|
36242
36294
|
}
|
|
36243
|
-
};
|
|
36244
|
-
loadSessionHistory = async (options) => {
|
|
36245
|
-
return await this.#executionProcesses.use(
|
|
36246
|
-
const runtime = await this.ensureSession(
|
|
36247
|
-
const stored = this.#store.read(
|
|
36295
|
+
});
|
|
36296
|
+
loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
|
|
36297
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
36298
|
+
const runtime = await this.ensureSession(options2);
|
|
36299
|
+
const stored = this.#store.read(options2.sessionId);
|
|
36248
36300
|
if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
|
|
36249
36301
|
const history = await this.#nativeHistoryReader.read(
|
|
36250
|
-
|
|
36302
|
+
options2,
|
|
36251
36303
|
stored.session.nativeSessionId,
|
|
36252
36304
|
runtime.nativeHistoryTurn
|
|
36253
36305
|
);
|
|
@@ -36255,15 +36307,15 @@ var AgentRuntimeManager = class {
|
|
|
36255
36307
|
return history;
|
|
36256
36308
|
}
|
|
36257
36309
|
}
|
|
36258
|
-
return await runtime.loadHistory(
|
|
36310
|
+
return await runtime.loadHistory(options2.signal);
|
|
36259
36311
|
});
|
|
36260
|
-
};
|
|
36261
|
-
openNativeSession = async (options, origin) => {
|
|
36262
|
-
const key = `${
|
|
36312
|
+
});
|
|
36313
|
+
openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
|
|
36314
|
+
const key = `${options2.agent.id}:${origin.nativeSessionId}`;
|
|
36263
36315
|
if (this.#nativeOperations.has(key)) {
|
|
36264
36316
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
36265
36317
|
}
|
|
36266
|
-
const linked = this.#store.findNative(
|
|
36318
|
+
const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
|
|
36267
36319
|
if (linked.some(
|
|
36268
36320
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
36269
36321
|
)) {
|
|
@@ -36277,7 +36329,7 @@ var AgentRuntimeManager = class {
|
|
|
36277
36329
|
if (origin.kind === "import" && existing !== void 0) {
|
|
36278
36330
|
return await this.#executionProcesses.use(existing.sessionId, async () => {
|
|
36279
36331
|
const runtime = await this.ensureSession({
|
|
36280
|
-
...
|
|
36332
|
+
...options2,
|
|
36281
36333
|
sessionId: existing.sessionId
|
|
36282
36334
|
});
|
|
36283
36335
|
if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
|
|
@@ -36299,18 +36351,22 @@ var AgentRuntimeManager = class {
|
|
|
36299
36351
|
}
|
|
36300
36352
|
});
|
|
36301
36353
|
}
|
|
36302
|
-
if (this.#executionProcesses.get(
|
|
36303
|
-
throw new AcpExecutionError(
|
|
36354
|
+
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options2.sessionId) instanceof DeletedAcpStoredSession) {
|
|
36355
|
+
throw new AcpExecutionError(
|
|
36356
|
+
"The destination conversation already exists",
|
|
36357
|
+
{},
|
|
36358
|
+
"session_identity_mismatch"
|
|
36359
|
+
);
|
|
36304
36360
|
}
|
|
36305
|
-
return await this.#executionProcesses.use(
|
|
36361
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
36306
36362
|
this.#nativeOperations.add(key);
|
|
36307
36363
|
try {
|
|
36308
|
-
const runtime = await this.#startPreparation({ ...
|
|
36309
|
-
const openedKey = `${
|
|
36364
|
+
const runtime = await this.#startPreparation({ ...options2, origin });
|
|
36365
|
+
const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
|
|
36310
36366
|
this.#nativeOperations.add(openedKey);
|
|
36311
36367
|
try {
|
|
36312
36368
|
return {
|
|
36313
|
-
sessionId:
|
|
36369
|
+
sessionId: options2.sessionId,
|
|
36314
36370
|
prepared: runtime.prepared()
|
|
36315
36371
|
};
|
|
36316
36372
|
} finally {
|
|
@@ -36318,11 +36374,11 @@ var AgentRuntimeManager = class {
|
|
|
36318
36374
|
this.#processes.notifyChanged();
|
|
36319
36375
|
}
|
|
36320
36376
|
} catch (error62) {
|
|
36321
|
-
this.#store.remove(
|
|
36322
|
-
const runtime = this.#executionProcesses.get(
|
|
36377
|
+
this.#store.remove(options2.sessionId);
|
|
36378
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
36323
36379
|
if (runtime !== void 0) {
|
|
36324
36380
|
await this.#retireSessionProcess(
|
|
36325
|
-
|
|
36381
|
+
options2.sessionId,
|
|
36326
36382
|
runtime,
|
|
36327
36383
|
async () => await runtime.closeProcess()
|
|
36328
36384
|
);
|
|
@@ -36332,11 +36388,11 @@ var AgentRuntimeManager = class {
|
|
|
36332
36388
|
this.#nativeOperations.delete(key);
|
|
36333
36389
|
}
|
|
36334
36390
|
});
|
|
36335
|
-
};
|
|
36336
|
-
deleteNativeSession = async (options, nativeSessionId) => {
|
|
36337
|
-
return await this.#queryProcesses.use(
|
|
36338
|
-
const key = `${
|
|
36339
|
-
const linked = this.#store.findNative(
|
|
36391
|
+
});
|
|
36392
|
+
deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
36393
|
+
return await this.#queryProcesses.use(options2, async (runtime) => {
|
|
36394
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
36395
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
36340
36396
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
36341
36397
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
36342
36398
|
)) {
|
|
@@ -36354,11 +36410,11 @@ var AgentRuntimeManager = class {
|
|
|
36354
36410
|
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
36355
36411
|
}
|
|
36356
36412
|
}
|
|
36357
|
-
|
|
36358
|
-
await runtime.deleteNativeSession(nativeSessionId,
|
|
36359
|
-
const deleted = this.#store.markDeleted(
|
|
36413
|
+
options2.signal.throwIfAborted();
|
|
36414
|
+
await runtime.deleteNativeSession(nativeSessionId, options2.signal);
|
|
36415
|
+
const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
|
|
36360
36416
|
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
36361
|
-
await this.#queryProcesses.retire(
|
|
36417
|
+
await this.#queryProcesses.retire(options2.sessionId, runtime);
|
|
36362
36418
|
}
|
|
36363
36419
|
return deleted;
|
|
36364
36420
|
} finally {
|
|
@@ -36366,7 +36422,7 @@ var AgentRuntimeManager = class {
|
|
|
36366
36422
|
this.#processes.notifyChanged();
|
|
36367
36423
|
}
|
|
36368
36424
|
});
|
|
36369
|
-
};
|
|
36425
|
+
});
|
|
36370
36426
|
};
|
|
36371
36427
|
|
|
36372
36428
|
// src/agent-catalog/publish-agent-catalog.ts
|