@moxt-ai/mobius 0.0.131 → 0.0.133
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/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +1 -4
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/agent-turn.d.ts +0 -4
- package/dist/acp/agent-turn.d.ts.map +1 -1
- package/dist/acp/agent-turn.js +0 -28
- package/dist/acp/agent-turn.js.map +1 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +22 -1
- package/dist/acp/codex/agent.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 +222 -179
- package/dist/cli.js.map +4 -4
- package/dist/index.js +221 -178
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +221 -178
- 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.133",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -25624,6 +25624,7 @@ var CodexAcpAgent = class {
|
|
|
25624
25624
|
#settings;
|
|
25625
25625
|
#nativeSessionId = "";
|
|
25626
25626
|
#streamedReasoningItemIds = /* @__PURE__ */ new Set();
|
|
25627
|
+
#streamedAgentMessageItemIds = /* @__PURE__ */ new Set();
|
|
25627
25628
|
#turn = null;
|
|
25628
25629
|
#nativeTurnId = null;
|
|
25629
25630
|
#updateTail = Promise.resolve();
|
|
@@ -25933,6 +25934,20 @@ var CodexAcpAgent = class {
|
|
|
25933
25934
|
}
|
|
25934
25935
|
return;
|
|
25935
25936
|
}
|
|
25937
|
+
if (method === "item/agentMessage/delta") {
|
|
25938
|
+
const decoded = reasoningTextDeltaParamsSchema.safeParse(params);
|
|
25939
|
+
if (decoded.success && decoded.data.threadId === this.#nativeSessionId && this.#turn !== null && decoded.data.turnId === this.#turn.turn.id && decoded.data.delta.length > 0) {
|
|
25940
|
+
this.#streamedAgentMessageItemIds.add(decoded.data.itemId);
|
|
25941
|
+
await this.#enqueue(async () => {
|
|
25942
|
+
await this.#emit({
|
|
25943
|
+
content: { text: decoded.data.delta, type: "text" },
|
|
25944
|
+
messageId: decoded.data.itemId,
|
|
25945
|
+
sessionUpdate: "agent_message_chunk"
|
|
25946
|
+
});
|
|
25947
|
+
});
|
|
25948
|
+
}
|
|
25949
|
+
return;
|
|
25950
|
+
}
|
|
25936
25951
|
if (method !== "item/started" && method !== "item/completed") {
|
|
25937
25952
|
return;
|
|
25938
25953
|
}
|
|
@@ -25941,7 +25956,7 @@ var CodexAcpAgent = class {
|
|
|
25941
25956
|
return;
|
|
25942
25957
|
}
|
|
25943
25958
|
if (item.type === "agentMessage") {
|
|
25944
|
-
if (method === "item/started") {
|
|
25959
|
+
if (method === "item/started" || this.#streamedAgentMessageItemIds.delete(item.id)) {
|
|
25945
25960
|
return;
|
|
25946
25961
|
}
|
|
25947
25962
|
await this.#enqueue(async () => {
|
|
@@ -26104,6 +26119,7 @@ var CodexAcpAgent = class {
|
|
|
26104
26119
|
};
|
|
26105
26120
|
signal.addEventListener("abort", aborted2, { once: true });
|
|
26106
26121
|
const turn = { completion, turn: { id: "" } };
|
|
26122
|
+
this.#streamedAgentMessageItemIds.clear();
|
|
26107
26123
|
this.#streamedReasoningItemIds.clear();
|
|
26108
26124
|
this.#turn = turn;
|
|
26109
26125
|
this.#nativeTurnId = null;
|
|
@@ -26128,6 +26144,7 @@ var CodexAcpAgent = class {
|
|
|
26128
26144
|
signal.removeEventListener("abort", aborted2);
|
|
26129
26145
|
if (this.#turn === turn) {
|
|
26130
26146
|
this.#turn = null;
|
|
26147
|
+
this.#streamedAgentMessageItemIds.clear();
|
|
26131
26148
|
this.#streamedReasoningItemIds.clear();
|
|
26132
26149
|
}
|
|
26133
26150
|
}
|
|
@@ -31987,33 +32004,6 @@ var AcpActivityTracker = class {
|
|
|
31987
32004
|
// src/acp/agent-turn.ts
|
|
31988
32005
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31989
32006
|
var AcpTurnState = class {
|
|
31990
|
-
#bufferedText = [];
|
|
31991
|
-
bufferText = (text2, messageId) => {
|
|
31992
|
-
const previous = this.#bufferedText.at(-1);
|
|
31993
|
-
if (previous?.messageId === messageId) {
|
|
31994
|
-
previous.chunks.push(text2);
|
|
31995
|
-
} else {
|
|
31996
|
-
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
31997
|
-
}
|
|
31998
|
-
};
|
|
31999
|
-
flushText = async () => {
|
|
32000
|
-
const buffered = this.#bufferedText;
|
|
32001
|
-
this.#bufferedText = [];
|
|
32002
|
-
for (const message of buffered) {
|
|
32003
|
-
for (const chunk of message.chunks) {
|
|
32004
|
-
await this.onText(chunk, message.messageId);
|
|
32005
|
-
}
|
|
32006
|
-
}
|
|
32007
|
-
};
|
|
32008
|
-
recordTextAsProgress = async () => {
|
|
32009
|
-
const buffered = this.#bufferedText;
|
|
32010
|
-
this.#bufferedText = [];
|
|
32011
|
-
for (const message of buffered) {
|
|
32012
|
-
for (const chunk of message.chunks) {
|
|
32013
|
-
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
32014
|
-
}
|
|
32015
|
-
}
|
|
32016
|
-
};
|
|
32017
32007
|
};
|
|
32018
32008
|
var IdleAcpTurn = class extends AcpTurnState {
|
|
32019
32009
|
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
@@ -39385,7 +39375,6 @@ var AgentSession = class _AgentSession {
|
|
|
39385
39375
|
options.signal
|
|
39386
39376
|
);
|
|
39387
39377
|
await this.#updates.drained();
|
|
39388
|
-
await this.#turn.flushText();
|
|
39389
39378
|
await running.activities.finish();
|
|
39390
39379
|
let result;
|
|
39391
39380
|
try {
|
|
@@ -39507,11 +39496,10 @@ var AgentSession = class _AgentSession {
|
|
|
39507
39496
|
);
|
|
39508
39497
|
} else {
|
|
39509
39498
|
await this.#turn.activities.finishNarrative();
|
|
39510
|
-
this.#turn.
|
|
39499
|
+
await this.#turn.onText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
39511
39500
|
}
|
|
39512
39501
|
} else {
|
|
39513
39502
|
await this.#turn.activities.finishNarrative();
|
|
39514
|
-
await this.#turn.flushText();
|
|
39515
39503
|
await this.emitAgentContent(
|
|
39516
39504
|
normalizeContentBlock(update.content),
|
|
39517
39505
|
truncate3(update.messageId ?? "", 255)
|
|
@@ -39530,7 +39518,6 @@ var AgentSession = class _AgentSession {
|
|
|
39530
39518
|
return;
|
|
39531
39519
|
}
|
|
39532
39520
|
if (update.sessionUpdate === "tool_call") {
|
|
39533
|
-
await this.#turn.recordTextAsProgress();
|
|
39534
39521
|
await this.#turn.activities.recordToolCall(update);
|
|
39535
39522
|
return;
|
|
39536
39523
|
}
|
|
@@ -39762,6 +39749,48 @@ var RetainedAgentProcesses = class {
|
|
|
39762
39749
|
};
|
|
39763
39750
|
};
|
|
39764
39751
|
|
|
39752
|
+
// src/acp/runtime-operations.ts
|
|
39753
|
+
var RuntimeOperations = class {
|
|
39754
|
+
#shutdown = new AbortController();
|
|
39755
|
+
#pending = /* @__PURE__ */ new Set();
|
|
39756
|
+
#closing = null;
|
|
39757
|
+
run = async (options, operation) => {
|
|
39758
|
+
const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
|
|
39759
|
+
signal.throwIfAborted();
|
|
39760
|
+
const pending = Promise.resolve().then(() => operation({ ...options, signal }));
|
|
39761
|
+
this.#pending.add(pending);
|
|
39762
|
+
try {
|
|
39763
|
+
const result = await pending;
|
|
39764
|
+
signal.throwIfAborted();
|
|
39765
|
+
return result;
|
|
39766
|
+
} finally {
|
|
39767
|
+
this.#pending.delete(pending);
|
|
39768
|
+
}
|
|
39769
|
+
};
|
|
39770
|
+
close = (release) => {
|
|
39771
|
+
if (this.#closing !== null) {
|
|
39772
|
+
return this.#closing;
|
|
39773
|
+
}
|
|
39774
|
+
this.#shutdown.abort();
|
|
39775
|
+
this.#closing = (async () => {
|
|
39776
|
+
await Promise.allSettled([...this.#pending]);
|
|
39777
|
+
await release();
|
|
39778
|
+
})();
|
|
39779
|
+
return this.#closing;
|
|
39780
|
+
};
|
|
39781
|
+
};
|
|
39782
|
+
async function waitForPreparation(pending, signal) {
|
|
39783
|
+
signal.throwIfAborted();
|
|
39784
|
+
const cancelled = Promise.withResolvers();
|
|
39785
|
+
const abort = () => cancelled.reject(signal.reason);
|
|
39786
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
39787
|
+
try {
|
|
39788
|
+
return await Promise.race([pending, cancelled.promise]);
|
|
39789
|
+
} finally {
|
|
39790
|
+
signal.removeEventListener("abort", abort);
|
|
39791
|
+
}
|
|
39792
|
+
}
|
|
39793
|
+
|
|
39765
39794
|
// src/acp/agent-query-processes.ts
|
|
39766
39795
|
var AgentQueryProcesses = class {
|
|
39767
39796
|
#processesByQuery;
|
|
@@ -39808,7 +39837,7 @@ var AgentQueryProcesses = class {
|
|
|
39808
39837
|
prepare = async (options) => {
|
|
39809
39838
|
const pending = this.#processesByQuery.pending(options.sessionId);
|
|
39810
39839
|
if (pending !== void 0) {
|
|
39811
|
-
const runtime2 = await pending;
|
|
39840
|
+
const runtime2 = await waitForPreparation(pending, options.signal);
|
|
39812
39841
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
39813
39842
|
this.#processesByQuery.touch(options.sessionId, runtime2);
|
|
39814
39843
|
return runtime2.prepared();
|
|
@@ -40087,6 +40116,7 @@ var AgentProcessPool = class {
|
|
|
40087
40116
|
// src/acp/agent-runtime-manager.ts
|
|
40088
40117
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
40089
40118
|
var AgentRuntimeManager = class {
|
|
40119
|
+
#operations = new RuntimeOperations();
|
|
40090
40120
|
#processes = new AgentProcessPool();
|
|
40091
40121
|
#executionProcesses = new RetainedAgentProcesses({
|
|
40092
40122
|
touch: this.#processes.touch,
|
|
@@ -40209,8 +40239,8 @@ var AgentRuntimeManager = class {
|
|
|
40209
40239
|
return runtime;
|
|
40210
40240
|
});
|
|
40211
40241
|
}
|
|
40212
|
-
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
40213
|
-
const stored = metrics.measureSync("session-state-read", () => this.#store.read(
|
|
40242
|
+
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
40243
|
+
const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
|
|
40214
40244
|
if (stored instanceof DeletedAcpStoredSession) {
|
|
40215
40245
|
throw new AcpExecutionError(
|
|
40216
40246
|
"The native Agent session was deleted. Start a new chat.",
|
|
@@ -40221,19 +40251,22 @@ var AgentRuntimeManager = class {
|
|
|
40221
40251
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
40222
40252
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40223
40253
|
}
|
|
40224
|
-
const pending = this.#executionProcesses.pending(
|
|
40254
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40225
40255
|
if (pending !== void 0) {
|
|
40226
|
-
const runtime2 = await metrics.measure(
|
|
40227
|
-
|
|
40228
|
-
|
|
40256
|
+
const runtime2 = await metrics.measure(
|
|
40257
|
+
"session-preparation-wait",
|
|
40258
|
+
async () => await waitForPreparation(pending, options2.signal)
|
|
40259
|
+
);
|
|
40260
|
+
if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40261
|
+
this.#executionProcesses.touch(options2.sessionId, runtime2);
|
|
40229
40262
|
return runtime2.prepared();
|
|
40230
40263
|
}
|
|
40231
|
-
return await this.prepareSession(
|
|
40264
|
+
return await this.prepareSession(options2, metrics);
|
|
40232
40265
|
}
|
|
40233
|
-
const existing = this.#executionProcesses.get(
|
|
40266
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40234
40267
|
if (existing !== void 0) {
|
|
40235
|
-
if (existing.belongsTo(
|
|
40236
|
-
this.#executionProcesses.touch(
|
|
40268
|
+
if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40269
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40237
40270
|
return existing.prepared();
|
|
40238
40271
|
}
|
|
40239
40272
|
if (!existing.canRebind()) {
|
|
@@ -40243,85 +40276,91 @@ var AgentRuntimeManager = class {
|
|
|
40243
40276
|
"session_identity_mismatch"
|
|
40244
40277
|
);
|
|
40245
40278
|
}
|
|
40246
|
-
const runtime2 = await this.#replacePreparation(existing,
|
|
40279
|
+
const runtime2 = await this.#replacePreparation(existing, options2, metrics);
|
|
40247
40280
|
return runtime2.prepared();
|
|
40248
40281
|
}
|
|
40249
|
-
const runtime = await this.#startPreparation(
|
|
40282
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
40250
40283
|
return runtime.prepared();
|
|
40251
|
-
};
|
|
40284
|
+
});
|
|
40252
40285
|
/**
|
|
40253
40286
|
* Opens a short-lived native ACP session only to read the local Agent's
|
|
40254
40287
|
* authoritative settings. Its identity and store are private to this
|
|
40255
40288
|
* operation and never become a Mobius Session.
|
|
40256
40289
|
*/
|
|
40257
|
-
inspectAgentSettings = async (options) =>
|
|
40258
|
-
|
|
40259
|
-
|
|
40260
|
-
|
|
40261
|
-
|
|
40262
|
-
|
|
40290
|
+
inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
|
|
40291
|
+
return await this.#processes.runTransient(
|
|
40292
|
+
options2.signal,
|
|
40293
|
+
async () => await AgentSession.start(
|
|
40294
|
+
{
|
|
40295
|
+
...options2,
|
|
40296
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`
|
|
40297
|
+
},
|
|
40298
|
+
() => this.#agentSettingsObserver,
|
|
40299
|
+
new MemoryAcpSessionStore()
|
|
40300
|
+
),
|
|
40301
|
+
async (runtime) => {
|
|
40302
|
+
const prepared = runtime.prepared();
|
|
40303
|
+
const model = options2.model;
|
|
40304
|
+
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
40305
|
+
...options2,
|
|
40306
|
+
booleanValue: false,
|
|
40307
|
+
configId: prepared.configOptions.find(
|
|
40308
|
+
(option) => option.id === "model" || option.category === "model"
|
|
40309
|
+
)?.id ?? "model",
|
|
40310
|
+
requestId: "agent-settings-model",
|
|
40311
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
40312
|
+
value: model,
|
|
40313
|
+
valueType: "select"
|
|
40314
|
+
});
|
|
40315
|
+
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
40263
40316
|
},
|
|
40264
|
-
() =>
|
|
40265
|
-
|
|
40266
|
-
|
|
40267
|
-
async (runtime) => {
|
|
40268
|
-
const prepared = runtime.prepared();
|
|
40269
|
-
const model = options.model;
|
|
40270
|
-
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
40271
|
-
...options,
|
|
40272
|
-
booleanValue: false,
|
|
40273
|
-
configId: prepared.configOptions.find(
|
|
40274
|
-
(option) => option.id === "model" || option.category === "model"
|
|
40275
|
-
)?.id ?? "model",
|
|
40276
|
-
requestId: "agent-settings-model",
|
|
40277
|
-
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
40278
|
-
value: model,
|
|
40279
|
-
valueType: "select"
|
|
40280
|
-
});
|
|
40281
|
-
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
40282
|
-
},
|
|
40283
|
-
async (runtime) => await runtime.close()
|
|
40284
|
-
);
|
|
40317
|
+
async (runtime) => await runtime.close()
|
|
40318
|
+
);
|
|
40319
|
+
});
|
|
40285
40320
|
/**
|
|
40286
40321
|
* Retained for Agents that expose a separate persisted configuration channel.
|
|
40287
40322
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
40288
40323
|
*/
|
|
40289
|
-
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
40290
|
-
if (this.#executionProcesses.pending(
|
|
40291
|
-
throw new AcpExecutionError(
|
|
40324
|
+
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
40325
|
+
if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
|
|
40326
|
+
throw new AcpExecutionError(
|
|
40327
|
+
"The configuration inspection session is already in use",
|
|
40328
|
+
{},
|
|
40329
|
+
"session_busy"
|
|
40330
|
+
);
|
|
40292
40331
|
}
|
|
40293
|
-
return await this.#executionProcesses.use(
|
|
40294
|
-
const runtime = await this.#startPreparation(
|
|
40332
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40333
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
40295
40334
|
try {
|
|
40296
40335
|
return runtime.prepared();
|
|
40297
40336
|
} finally {
|
|
40298
40337
|
try {
|
|
40299
|
-
await this.#retireSessionProcess(
|
|
40338
|
+
await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
|
|
40300
40339
|
} finally {
|
|
40301
|
-
this.#store.remove(
|
|
40340
|
+
this.#store.remove(options2.sessionId);
|
|
40302
40341
|
}
|
|
40303
40342
|
}
|
|
40304
40343
|
});
|
|
40305
|
-
};
|
|
40306
|
-
prepareExecutionSession = async (options) => {
|
|
40307
|
-
const pending = this.#executionProcesses.pending(
|
|
40344
|
+
});
|
|
40345
|
+
prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40346
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40308
40347
|
if (pending !== void 0) {
|
|
40309
|
-
await pending;
|
|
40310
|
-
return await this.prepareExecutionSession(
|
|
40348
|
+
await waitForPreparation(pending, options2.signal);
|
|
40349
|
+
return await this.prepareExecutionSession(options2);
|
|
40311
40350
|
}
|
|
40312
|
-
const existing = this.#executionProcesses.get(
|
|
40351
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40313
40352
|
if (existing === void 0) {
|
|
40314
|
-
return (await this.#startPreparation(
|
|
40353
|
+
return (await this.#startPreparation(options2)).prepared();
|
|
40315
40354
|
}
|
|
40316
|
-
if (!existing.belongsTo(
|
|
40355
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40317
40356
|
throw new AcpExecutionError(
|
|
40318
40357
|
"The agent or workspace cannot change after a conversation has started",
|
|
40319
40358
|
{},
|
|
40320
40359
|
"session_identity_mismatch"
|
|
40321
40360
|
);
|
|
40322
40361
|
}
|
|
40323
|
-
if (existing.usesEnvironment(
|
|
40324
|
-
this.#executionProcesses.touch(
|
|
40362
|
+
if (existing.usesEnvironment(options2.agent.environment)) {
|
|
40363
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40325
40364
|
return existing.prepared();
|
|
40326
40365
|
}
|
|
40327
40366
|
if (existing.hasRunningTurn()) {
|
|
@@ -40331,15 +40370,15 @@ var AgentRuntimeManager = class {
|
|
|
40331
40370
|
"session_busy"
|
|
40332
40371
|
);
|
|
40333
40372
|
}
|
|
40334
|
-
return (await this.#replaceExecutionPreparation(existing,
|
|
40335
|
-
};
|
|
40336
|
-
prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(
|
|
40337
|
-
configureSession = async (options) => {
|
|
40338
|
-
return await this.#executionProcesses.use(
|
|
40339
|
-
const runtime = await this.ensureSession(
|
|
40340
|
-
return await runtime.configure(
|
|
40373
|
+
return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
|
|
40374
|
+
});
|
|
40375
|
+
prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
|
|
40376
|
+
configureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40377
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40378
|
+
const runtime = await this.ensureSession(options2);
|
|
40379
|
+
return await runtime.configure(options2);
|
|
40341
40380
|
});
|
|
40342
|
-
};
|
|
40381
|
+
});
|
|
40343
40382
|
cancelPrompt = async (sessionId) => {
|
|
40344
40383
|
await this.#executions.cancel(sessionId, async () => {
|
|
40345
40384
|
const runtime = this.#executionProcesses.get(sessionId);
|
|
@@ -40354,19 +40393,19 @@ var AgentRuntimeManager = class {
|
|
|
40354
40393
|
}
|
|
40355
40394
|
});
|
|
40356
40395
|
};
|
|
40357
|
-
steerPrompt = async (options) => {
|
|
40358
|
-
if (this.#executions.command(
|
|
40396
|
+
steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
40397
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
40359
40398
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
40360
40399
|
}
|
|
40361
|
-
const pending = this.#executionProcesses.pending(
|
|
40400
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40362
40401
|
if (pending !== void 0) {
|
|
40363
|
-
await pending;
|
|
40402
|
+
await waitForPreparation(pending, options2.signal);
|
|
40364
40403
|
}
|
|
40365
|
-
if (this.#executions.command(
|
|
40404
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
40366
40405
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
40367
40406
|
}
|
|
40368
|
-
const runtime = this.#executionProcesses.get(
|
|
40369
|
-
if (runtime === void 0 || !runtime.belongsTo(
|
|
40407
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
40408
|
+
if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40370
40409
|
throw new AcpExecutionError(
|
|
40371
40410
|
"The target turn execution context is unavailable",
|
|
40372
40411
|
{},
|
|
@@ -40383,8 +40422,8 @@ var AgentRuntimeManager = class {
|
|
|
40383
40422
|
deadline.unref();
|
|
40384
40423
|
try {
|
|
40385
40424
|
return await runtime.steer({
|
|
40386
|
-
...
|
|
40387
|
-
signal: AbortSignal.any([
|
|
40425
|
+
...options2,
|
|
40426
|
+
signal: AbortSignal.any([options2.signal, deadlineController.signal])
|
|
40388
40427
|
});
|
|
40389
40428
|
} catch (error62) {
|
|
40390
40429
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -40394,44 +40433,44 @@ var AgentRuntimeManager = class {
|
|
|
40394
40433
|
} finally {
|
|
40395
40434
|
clearTimeout(deadline);
|
|
40396
40435
|
}
|
|
40397
|
-
};
|
|
40398
|
-
runPrompt = async (options) => {
|
|
40399
|
-
const stored = this.#store.read(
|
|
40436
|
+
});
|
|
40437
|
+
runPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
40438
|
+
const stored = this.#store.read(options2.sessionId);
|
|
40400
40439
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
40401
40440
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40402
40441
|
}
|
|
40403
|
-
this.#executions.begin(
|
|
40442
|
+
this.#executions.begin(options2.sessionId, options2.commandId);
|
|
40404
40443
|
try {
|
|
40405
|
-
if (this.#executions.cancellation(
|
|
40444
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40406
40445
|
return { stopReason: "cancelled" };
|
|
40407
40446
|
}
|
|
40408
|
-
const runtime = await this.ensureSession(
|
|
40409
|
-
if (this.#nativeOperations.has(`${
|
|
40447
|
+
const runtime = await this.ensureSession(options2);
|
|
40448
|
+
if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
|
|
40410
40449
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40411
40450
|
}
|
|
40412
|
-
if (this.#executions.cancellation(
|
|
40451
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40413
40452
|
return { stopReason: "cancelled" };
|
|
40414
40453
|
}
|
|
40415
40454
|
try {
|
|
40416
|
-
const result = await runtime.prompt(
|
|
40417
|
-
return this.#executions.cancellation(
|
|
40455
|
+
const result = await runtime.prompt(options2);
|
|
40456
|
+
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
40418
40457
|
} catch (error62) {
|
|
40419
|
-
if (this.#executions.cancellation(
|
|
40420
|
-
await this.#executions.cancellation(
|
|
40458
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40459
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
40421
40460
|
return { stopReason: "cancelled" };
|
|
40422
40461
|
}
|
|
40423
40462
|
throw error62;
|
|
40424
40463
|
}
|
|
40425
40464
|
} catch (error62) {
|
|
40426
|
-
const failedRuntime = this.#executionProcesses.get(
|
|
40465
|
+
const failedRuntime = this.#executionProcesses.get(options2.sessionId);
|
|
40427
40466
|
if (failedRuntime !== void 0) {
|
|
40428
40467
|
await this.#retireSessionProcess(
|
|
40429
|
-
|
|
40468
|
+
options2.sessionId,
|
|
40430
40469
|
failedRuntime,
|
|
40431
40470
|
async () => await failedRuntime.close()
|
|
40432
40471
|
);
|
|
40433
40472
|
}
|
|
40434
|
-
if (this.#executions.cancellation(
|
|
40473
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40435
40474
|
return { stopReason: "cancelled" };
|
|
40436
40475
|
}
|
|
40437
40476
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -40442,14 +40481,14 @@ var AgentRuntimeManager = class {
|
|
|
40442
40481
|
});
|
|
40443
40482
|
} finally {
|
|
40444
40483
|
try {
|
|
40445
|
-
await this.#executions.cancellation(
|
|
40484
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
40446
40485
|
} finally {
|
|
40447
|
-
this.#executions.finish(
|
|
40448
|
-
this.#executionProcesses.touch(
|
|
40486
|
+
this.#executions.finish(options2.sessionId, options2.commandId);
|
|
40487
|
+
this.#executionProcesses.touch(options2.sessionId);
|
|
40449
40488
|
this.#processes.notifyChanged();
|
|
40450
40489
|
}
|
|
40451
40490
|
}
|
|
40452
|
-
};
|
|
40491
|
+
});
|
|
40453
40492
|
respondPermission = async (options) => {
|
|
40454
40493
|
const runtime = this.#executionProcesses.get(options.sessionId);
|
|
40455
40494
|
if (runtime === void 0) {
|
|
@@ -40464,7 +40503,7 @@ var AgentRuntimeManager = class {
|
|
|
40464
40503
|
}
|
|
40465
40504
|
await runtime.respondElicitation(options);
|
|
40466
40505
|
};
|
|
40467
|
-
close = async () => {
|
|
40506
|
+
close = async () => this.#operations.close(async () => {
|
|
40468
40507
|
const sessions = [...this.#executionProcesses.entries()];
|
|
40469
40508
|
await Promise.all([
|
|
40470
40509
|
...sessions.map(
|
|
@@ -40472,23 +40511,23 @@ var AgentRuntimeManager = class {
|
|
|
40472
40511
|
),
|
|
40473
40512
|
this.#queryProcesses.close()
|
|
40474
40513
|
]);
|
|
40475
|
-
};
|
|
40514
|
+
});
|
|
40476
40515
|
findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
|
|
40477
40516
|
const stored = this.#store.read(sessionId);
|
|
40478
40517
|
return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
|
|
40479
40518
|
});
|
|
40480
40519
|
findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
|
|
40481
40520
|
hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
|
|
40482
|
-
createNativeSession = async (options) => {
|
|
40521
|
+
createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40483
40522
|
const temporarySessionId = `new-${crypto.randomUUID()}`;
|
|
40484
|
-
const temporaryOptions = { ...
|
|
40523
|
+
const temporaryOptions = { ...options2, sessionId: temporarySessionId };
|
|
40485
40524
|
return await this.#executionProcesses.use(temporarySessionId, async () => {
|
|
40486
40525
|
try {
|
|
40487
40526
|
const runtime = await this.#startPreparation(temporaryOptions);
|
|
40488
40527
|
let adopted = false;
|
|
40489
40528
|
try {
|
|
40490
40529
|
const nativeSessionId = runtime.nativeSessionId();
|
|
40491
|
-
if (!isNativeChatSessionId(
|
|
40530
|
+
if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
|
|
40492
40531
|
throw new AcpExecutionError(
|
|
40493
40532
|
"The Agent returned an invalid new Session ID",
|
|
40494
40533
|
{},
|
|
@@ -40514,36 +40553,36 @@ var AgentRuntimeManager = class {
|
|
|
40514
40553
|
this.#store.remove(temporarySessionId);
|
|
40515
40554
|
}
|
|
40516
40555
|
});
|
|
40517
|
-
};
|
|
40518
|
-
ensureSession = async (options) => {
|
|
40519
|
-
const existing = this.#executionProcesses.get(
|
|
40556
|
+
});
|
|
40557
|
+
ensureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40558
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40520
40559
|
if (existing !== void 0) {
|
|
40521
|
-
if (!existing.belongsTo(
|
|
40560
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40522
40561
|
throw new AcpExecutionError(
|
|
40523
40562
|
"The agent or workspace cannot change after a conversation has started",
|
|
40524
40563
|
{},
|
|
40525
40564
|
"session_identity_mismatch"
|
|
40526
40565
|
);
|
|
40527
40566
|
}
|
|
40528
|
-
this.#executionProcesses.touch(
|
|
40567
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40529
40568
|
return existing;
|
|
40530
40569
|
}
|
|
40531
|
-
await this.prepareSession(
|
|
40532
|
-
const started = this.#executionProcesses.get(
|
|
40570
|
+
await this.prepareSession(options2);
|
|
40571
|
+
const started = this.#executionProcesses.get(options2.sessionId);
|
|
40533
40572
|
if (started === void 0) {
|
|
40534
40573
|
throw new AcpExecutionError("ACP session did not start");
|
|
40535
40574
|
}
|
|
40536
40575
|
return started;
|
|
40537
|
-
};
|
|
40538
|
-
listNativeSessions = async (options, cursor) => {
|
|
40576
|
+
});
|
|
40577
|
+
listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
|
|
40539
40578
|
return await this.#queryProcesses.use(
|
|
40540
|
-
|
|
40541
|
-
async (runtime) => await runtime.listNativeSessions(cursor,
|
|
40579
|
+
options2,
|
|
40580
|
+
async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
|
|
40542
40581
|
);
|
|
40543
|
-
};
|
|
40544
|
-
previewNativeSession = async (options, nativeSessionId) => {
|
|
40545
|
-
const key = `${
|
|
40546
|
-
const linked = this.#store.findNative(
|
|
40582
|
+
});
|
|
40583
|
+
previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
40584
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
40585
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
40547
40586
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
40548
40587
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40549
40588
|
)) {
|
|
@@ -40555,18 +40594,18 @@ var AgentRuntimeManager = class {
|
|
|
40555
40594
|
}
|
|
40556
40595
|
this.#nativeOperations.add(key);
|
|
40557
40596
|
try {
|
|
40558
|
-
return await this.#queryProcesses.preview(
|
|
40597
|
+
return await this.#queryProcesses.preview(options2, nativeSessionId);
|
|
40559
40598
|
} finally {
|
|
40560
40599
|
this.#nativeOperations.delete(key);
|
|
40561
40600
|
}
|
|
40562
|
-
};
|
|
40563
|
-
loadSessionHistory = async (options) => {
|
|
40564
|
-
return await this.#executionProcesses.use(
|
|
40565
|
-
const runtime = await this.ensureSession(
|
|
40566
|
-
const stored = this.#store.read(
|
|
40601
|
+
});
|
|
40602
|
+
loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
|
|
40603
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40604
|
+
const runtime = await this.ensureSession(options2);
|
|
40605
|
+
const stored = this.#store.read(options2.sessionId);
|
|
40567
40606
|
if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
|
|
40568
40607
|
const history = await this.#nativeHistoryReader.read(
|
|
40569
|
-
|
|
40608
|
+
options2,
|
|
40570
40609
|
stored.session.nativeSessionId,
|
|
40571
40610
|
runtime.nativeHistoryTurn
|
|
40572
40611
|
);
|
|
@@ -40574,15 +40613,15 @@ var AgentRuntimeManager = class {
|
|
|
40574
40613
|
return history;
|
|
40575
40614
|
}
|
|
40576
40615
|
}
|
|
40577
|
-
return await runtime.loadHistory(
|
|
40616
|
+
return await runtime.loadHistory(options2.signal);
|
|
40578
40617
|
});
|
|
40579
|
-
};
|
|
40580
|
-
openNativeSession = async (options, origin) => {
|
|
40581
|
-
const key = `${
|
|
40618
|
+
});
|
|
40619
|
+
openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
|
|
40620
|
+
const key = `${options2.agent.id}:${origin.nativeSessionId}`;
|
|
40582
40621
|
if (this.#nativeOperations.has(key)) {
|
|
40583
40622
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40584
40623
|
}
|
|
40585
|
-
const linked = this.#store.findNative(
|
|
40624
|
+
const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
|
|
40586
40625
|
if (linked.some(
|
|
40587
40626
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40588
40627
|
)) {
|
|
@@ -40596,7 +40635,7 @@ var AgentRuntimeManager = class {
|
|
|
40596
40635
|
if (origin.kind === "import" && existing !== void 0) {
|
|
40597
40636
|
return await this.#executionProcesses.use(existing.sessionId, async () => {
|
|
40598
40637
|
const runtime = await this.ensureSession({
|
|
40599
|
-
...
|
|
40638
|
+
...options2,
|
|
40600
40639
|
sessionId: existing.sessionId
|
|
40601
40640
|
});
|
|
40602
40641
|
if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
|
|
@@ -40618,18 +40657,22 @@ var AgentRuntimeManager = class {
|
|
|
40618
40657
|
}
|
|
40619
40658
|
});
|
|
40620
40659
|
}
|
|
40621
|
-
if (this.#executionProcesses.get(
|
|
40622
|
-
throw new AcpExecutionError(
|
|
40660
|
+
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) {
|
|
40661
|
+
throw new AcpExecutionError(
|
|
40662
|
+
"The destination conversation already exists",
|
|
40663
|
+
{},
|
|
40664
|
+
"session_identity_mismatch"
|
|
40665
|
+
);
|
|
40623
40666
|
}
|
|
40624
|
-
return await this.#executionProcesses.use(
|
|
40667
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40625
40668
|
this.#nativeOperations.add(key);
|
|
40626
40669
|
try {
|
|
40627
|
-
const runtime = await this.#startPreparation({ ...
|
|
40628
|
-
const openedKey = `${
|
|
40670
|
+
const runtime = await this.#startPreparation({ ...options2, origin });
|
|
40671
|
+
const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
|
|
40629
40672
|
this.#nativeOperations.add(openedKey);
|
|
40630
40673
|
try {
|
|
40631
40674
|
return {
|
|
40632
|
-
sessionId:
|
|
40675
|
+
sessionId: options2.sessionId,
|
|
40633
40676
|
prepared: runtime.prepared()
|
|
40634
40677
|
};
|
|
40635
40678
|
} finally {
|
|
@@ -40637,11 +40680,11 @@ var AgentRuntimeManager = class {
|
|
|
40637
40680
|
this.#processes.notifyChanged();
|
|
40638
40681
|
}
|
|
40639
40682
|
} catch (error62) {
|
|
40640
|
-
this.#store.remove(
|
|
40641
|
-
const runtime = this.#executionProcesses.get(
|
|
40683
|
+
this.#store.remove(options2.sessionId);
|
|
40684
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
40642
40685
|
if (runtime !== void 0) {
|
|
40643
40686
|
await this.#retireSessionProcess(
|
|
40644
|
-
|
|
40687
|
+
options2.sessionId,
|
|
40645
40688
|
runtime,
|
|
40646
40689
|
async () => await runtime.closeProcess()
|
|
40647
40690
|
);
|
|
@@ -40651,11 +40694,11 @@ var AgentRuntimeManager = class {
|
|
|
40651
40694
|
this.#nativeOperations.delete(key);
|
|
40652
40695
|
}
|
|
40653
40696
|
});
|
|
40654
|
-
};
|
|
40655
|
-
deleteNativeSession = async (options, nativeSessionId) => {
|
|
40656
|
-
return await this.#queryProcesses.use(
|
|
40657
|
-
const key = `${
|
|
40658
|
-
const linked = this.#store.findNative(
|
|
40697
|
+
});
|
|
40698
|
+
deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
40699
|
+
return await this.#queryProcesses.use(options2, async (runtime) => {
|
|
40700
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
40701
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
40659
40702
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
40660
40703
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40661
40704
|
)) {
|
|
@@ -40673,11 +40716,11 @@ var AgentRuntimeManager = class {
|
|
|
40673
40716
|
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
40674
40717
|
}
|
|
40675
40718
|
}
|
|
40676
|
-
|
|
40677
|
-
await runtime.deleteNativeSession(nativeSessionId,
|
|
40678
|
-
const deleted = this.#store.markDeleted(
|
|
40719
|
+
options2.signal.throwIfAborted();
|
|
40720
|
+
await runtime.deleteNativeSession(nativeSessionId, options2.signal);
|
|
40721
|
+
const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
|
|
40679
40722
|
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
40680
|
-
await this.#queryProcesses.retire(
|
|
40723
|
+
await this.#queryProcesses.retire(options2.sessionId, runtime);
|
|
40681
40724
|
}
|
|
40682
40725
|
return deleted;
|
|
40683
40726
|
} finally {
|
|
@@ -40685,7 +40728,7 @@ var AgentRuntimeManager = class {
|
|
|
40685
40728
|
this.#processes.notifyChanged();
|
|
40686
40729
|
}
|
|
40687
40730
|
});
|
|
40688
|
-
};
|
|
40731
|
+
});
|
|
40689
40732
|
};
|
|
40690
40733
|
|
|
40691
40734
|
// src/agent-catalog/publish-agent-catalog.ts
|