@moxt-ai/mobius 0.0.128 → 0.0.130
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/activity-content.d.ts +29 -0
- package/dist/acp/activity-content.d.ts.map +1 -0
- package/dist/acp/activity-content.js +301 -0
- package/dist/acp/activity-content.js.map +1 -0
- package/dist/acp/activity.d.ts +3 -9
- package/dist/acp/activity.d.ts.map +1 -1
- package/dist/acp/activity.js +2 -300
- package/dist/acp/activity.js.map +1 -1
- package/dist/acp/agent-session.d.ts +0 -4
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +6 -37
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/{session-state.d.ts → agent-turn.d.ts} +5 -22
- package/dist/acp/agent-turn.d.ts.map +1 -0
- package/dist/acp/agent-turn.js +51 -0
- package/dist/acp/agent-turn.js.map +1 -0
- package/dist/acp/pending-interactions.d.ts +22 -0
- package/dist/acp/pending-interactions.d.ts.map +1 -0
- package/dist/acp/{session-state.js → pending-interactions.js} +1 -23
- package/dist/acp/pending-interactions.js.map +1 -0
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +2 -1
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-interactions.d.ts.map +1 -1
- package/dist/acp/session-interactions.js +1 -1
- package/dist/acp/session-interactions.js.map +1 -1
- package/dist/cli.js +312 -312
- package/dist/cli.js.map +4 -4
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/index.js +398 -398
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +384 -384
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/acp/session-state.d.ts.map +0 -1
- package/dist/acp/session-state.js.map +0 -1
package/dist/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.130",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -31162,73 +31162,11 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
31162
31162
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
31163
31163
|
}
|
|
31164
31164
|
|
|
31165
|
-
// src/acp/activity.ts
|
|
31165
|
+
// src/acp/activity-content.ts
|
|
31166
31166
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
31167
|
-
var AcpActivityNarration = class {
|
|
31168
|
-
activityId;
|
|
31169
|
-
activityType;
|
|
31170
|
-
sequence;
|
|
31171
|
-
text;
|
|
31172
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
31173
|
-
this.activityId = activityId;
|
|
31174
|
-
this.activityType = activityType;
|
|
31175
|
-
this.sequence = sequence;
|
|
31176
|
-
this.text = text2;
|
|
31177
|
-
}
|
|
31178
|
-
};
|
|
31179
31167
|
function isRecord7(value) {
|
|
31180
31168
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31181
31169
|
}
|
|
31182
|
-
var AcpActivity = class _AcpActivity {
|
|
31183
|
-
activityId;
|
|
31184
|
-
activityType;
|
|
31185
|
-
input;
|
|
31186
|
-
locations;
|
|
31187
|
-
name;
|
|
31188
|
-
output;
|
|
31189
|
-
sequence;
|
|
31190
|
-
status;
|
|
31191
|
-
title;
|
|
31192
|
-
toolKind;
|
|
31193
|
-
content;
|
|
31194
|
-
detail;
|
|
31195
|
-
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31196
|
-
this.activityId = activityId;
|
|
31197
|
-
this.activityType = activityType;
|
|
31198
|
-
this.input = input2;
|
|
31199
|
-
this.locations = locations;
|
|
31200
|
-
this.name = name;
|
|
31201
|
-
this.output = output2;
|
|
31202
|
-
this.sequence = sequence;
|
|
31203
|
-
this.status = status;
|
|
31204
|
-
this.title = title2;
|
|
31205
|
-
this.toolKind = toolKind;
|
|
31206
|
-
this.content = content;
|
|
31207
|
-
this.detail = detail;
|
|
31208
|
-
}
|
|
31209
|
-
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
31210
|
-
this.activityId,
|
|
31211
|
-
this.activityType,
|
|
31212
|
-
this.input,
|
|
31213
|
-
this.locations,
|
|
31214
|
-
this.name,
|
|
31215
|
-
this.output,
|
|
31216
|
-
this.sequence,
|
|
31217
|
-
"completed",
|
|
31218
|
-
this.title,
|
|
31219
|
-
this.toolKind,
|
|
31220
|
-
this.content,
|
|
31221
|
-
this.detail
|
|
31222
|
-
) : this;
|
|
31223
|
-
};
|
|
31224
|
-
var ActivityIdentity = class {
|
|
31225
|
-
id;
|
|
31226
|
-
sequence;
|
|
31227
|
-
constructor(id, sequence) {
|
|
31228
|
-
this.id = id;
|
|
31229
|
-
this.sequence = sequence;
|
|
31230
|
-
}
|
|
31231
|
-
};
|
|
31232
31170
|
function truncate2(value, maximumLength) {
|
|
31233
31171
|
if (value.length <= maximumLength) {
|
|
31234
31172
|
return value;
|
|
@@ -31505,6 +31443,268 @@ function contentPhase(content) {
|
|
|
31505
31443
|
function isProgressMessage(content) {
|
|
31506
31444
|
return contentPhase(content) === "commentary";
|
|
31507
31445
|
}
|
|
31446
|
+
|
|
31447
|
+
// src/acp/agent-connection.ts
|
|
31448
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
31449
|
+
import { ndJsonStream as ndJsonStream2, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
|
|
31450
|
+
|
|
31451
|
+
// src/acp/value-utils.ts
|
|
31452
|
+
function truncate3(value, maximumLength) {
|
|
31453
|
+
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
31454
|
+
}
|
|
31455
|
+
function isRecord8(value) {
|
|
31456
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31457
|
+
}
|
|
31458
|
+
function readString2(value, fallback = "") {
|
|
31459
|
+
return typeof value === "string" ? value : fallback;
|
|
31460
|
+
}
|
|
31461
|
+
|
|
31462
|
+
// src/acp/agent-connection.ts
|
|
31463
|
+
function readableWebStream(input2) {
|
|
31464
|
+
let streamOpen = true;
|
|
31465
|
+
return new ReadableStream({
|
|
31466
|
+
start(controller) {
|
|
31467
|
+
input2.on("data", (chunk) => {
|
|
31468
|
+
if (!streamOpen) {
|
|
31469
|
+
return;
|
|
31470
|
+
}
|
|
31471
|
+
if (chunk instanceof Uint8Array) {
|
|
31472
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
31473
|
+
return;
|
|
31474
|
+
}
|
|
31475
|
+
streamOpen = false;
|
|
31476
|
+
controller.error(new Error("ACP process produced a non-binary chunk"));
|
|
31477
|
+
});
|
|
31478
|
+
input2.once("end", () => {
|
|
31479
|
+
if (!streamOpen) {
|
|
31480
|
+
return;
|
|
31481
|
+
}
|
|
31482
|
+
streamOpen = false;
|
|
31483
|
+
controller.close();
|
|
31484
|
+
});
|
|
31485
|
+
input2.once("error", (error62) => {
|
|
31486
|
+
if (!streamOpen) {
|
|
31487
|
+
return;
|
|
31488
|
+
}
|
|
31489
|
+
streamOpen = false;
|
|
31490
|
+
controller.error(error62);
|
|
31491
|
+
});
|
|
31492
|
+
},
|
|
31493
|
+
cancel() {
|
|
31494
|
+
streamOpen = false;
|
|
31495
|
+
}
|
|
31496
|
+
});
|
|
31497
|
+
}
|
|
31498
|
+
function createWritableAcpStream(output2) {
|
|
31499
|
+
let outputFailure;
|
|
31500
|
+
const pendingWriteFailures = /* @__PURE__ */ new Set();
|
|
31501
|
+
const fail = (error62) => {
|
|
31502
|
+
outputFailure = error62;
|
|
31503
|
+
for (const reject of pendingWriteFailures) {
|
|
31504
|
+
reject(error62);
|
|
31505
|
+
}
|
|
31506
|
+
pendingWriteFailures.clear();
|
|
31507
|
+
};
|
|
31508
|
+
output2.on("error", fail);
|
|
31509
|
+
output2.once("close", () => {
|
|
31510
|
+
if (outputFailure === void 0) {
|
|
31511
|
+
fail(new Error("ACP process input closed"));
|
|
31512
|
+
}
|
|
31513
|
+
});
|
|
31514
|
+
return new WritableStream({
|
|
31515
|
+
write(chunk) {
|
|
31516
|
+
if (outputFailure !== void 0) {
|
|
31517
|
+
return Promise.reject(outputFailure);
|
|
31518
|
+
}
|
|
31519
|
+
return new Promise((resolve9, reject) => {
|
|
31520
|
+
pendingWriteFailures.add(reject);
|
|
31521
|
+
output2.write(chunk, (error62) => {
|
|
31522
|
+
pendingWriteFailures.delete(reject);
|
|
31523
|
+
if (error62) {
|
|
31524
|
+
outputFailure = error62;
|
|
31525
|
+
reject(error62);
|
|
31526
|
+
return;
|
|
31527
|
+
}
|
|
31528
|
+
if (outputFailure !== void 0) {
|
|
31529
|
+
reject(outputFailure);
|
|
31530
|
+
return;
|
|
31531
|
+
}
|
|
31532
|
+
resolve9();
|
|
31533
|
+
});
|
|
31534
|
+
});
|
|
31535
|
+
}
|
|
31536
|
+
});
|
|
31537
|
+
}
|
|
31538
|
+
var AgentConnection = class {
|
|
31539
|
+
connection;
|
|
31540
|
+
termination;
|
|
31541
|
+
#process;
|
|
31542
|
+
constructor(agent, cwd, client2) {
|
|
31543
|
+
if (agent.kind === "in-process-acp") {
|
|
31544
|
+
const inProcess = agent.createEndpoint({
|
|
31545
|
+
command: agent.command,
|
|
31546
|
+
cwd,
|
|
31547
|
+
environment: agent.environment
|
|
31548
|
+
});
|
|
31549
|
+
this.#process = { kind: "in-process", endpoint: inProcess };
|
|
31550
|
+
this.termination = inProcess.terminated;
|
|
31551
|
+
this.connection = createAcpClient(client2).connect(inProcess.app());
|
|
31552
|
+
return;
|
|
31553
|
+
}
|
|
31554
|
+
const child = spawn4(agent.adapterPath, [...agent.arguments], {
|
|
31555
|
+
cwd,
|
|
31556
|
+
detached: process.platform !== "win32",
|
|
31557
|
+
env: { ...process.env, ...agent.environment },
|
|
31558
|
+
shell: false,
|
|
31559
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
31560
|
+
});
|
|
31561
|
+
this.#process = { kind: "child", child };
|
|
31562
|
+
const stdin = child.stdin;
|
|
31563
|
+
const stdout = child.stdout;
|
|
31564
|
+
const stderr = child.stderr;
|
|
31565
|
+
if (stdin === null || stdout === null || stderr === null) {
|
|
31566
|
+
child.kill("SIGKILL");
|
|
31567
|
+
throw new AcpExecutionError("ACP process streams are unavailable");
|
|
31568
|
+
}
|
|
31569
|
+
stderr.setEncoding("utf8");
|
|
31570
|
+
stderr.on("data", (chunk) => {
|
|
31571
|
+
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
31572
|
+
});
|
|
31573
|
+
this.termination = new Promise((resolve9) => {
|
|
31574
|
+
child.once("error", (cause) => {
|
|
31575
|
+
resolve9({ kind: "failed", error: new AcpExecutionError("The ACP process could not run", { cause }) });
|
|
31576
|
+
});
|
|
31577
|
+
child.once("exit", (code, signal) => {
|
|
31578
|
+
resolve9({
|
|
31579
|
+
kind: "failed",
|
|
31580
|
+
error: new AcpExecutionError("The ACP process stopped", { cause: { code, signal } })
|
|
31581
|
+
});
|
|
31582
|
+
});
|
|
31583
|
+
});
|
|
31584
|
+
const stream = ndJsonStream2(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
31585
|
+
this.connection = createAcpClient(client2).connect(stream);
|
|
31586
|
+
}
|
|
31587
|
+
get inProcessAgent() {
|
|
31588
|
+
return this.#process.kind === "in-process" ? this.#process.endpoint : null;
|
|
31589
|
+
}
|
|
31590
|
+
captureProcessTree = async () => this.#process.kind === "child" ? await captureProcessTree(this.#process.child) : [];
|
|
31591
|
+
closeProcess = async (capturedProcesses = []) => {
|
|
31592
|
+
try {
|
|
31593
|
+
if (this.#process.kind === "in-process") {
|
|
31594
|
+
await this.#process.endpoint.close();
|
|
31595
|
+
return;
|
|
31596
|
+
}
|
|
31597
|
+
await stopProcessTree(this.#process.child, capturedProcesses);
|
|
31598
|
+
} finally {
|
|
31599
|
+
this.connection.close();
|
|
31600
|
+
}
|
|
31601
|
+
};
|
|
31602
|
+
race = async (operation, exitMessage, signal) => {
|
|
31603
|
+
signal.throwIfAborted();
|
|
31604
|
+
let removeAbortListener = () => {
|
|
31605
|
+
};
|
|
31606
|
+
const aborted2 = new Promise((_resolve, reject) => {
|
|
31607
|
+
const rejectAbort = () => {
|
|
31608
|
+
reject(signal.reason ?? new Error("ACP request was cancelled"));
|
|
31609
|
+
};
|
|
31610
|
+
signal.addEventListener("abort", rejectAbort, { once: true });
|
|
31611
|
+
removeAbortListener = () => {
|
|
31612
|
+
signal.removeEventListener("abort", rejectAbort);
|
|
31613
|
+
};
|
|
31614
|
+
});
|
|
31615
|
+
try {
|
|
31616
|
+
try {
|
|
31617
|
+
return await Promise.race([
|
|
31618
|
+
operation,
|
|
31619
|
+
this.termination.then((termination) => {
|
|
31620
|
+
const cause = acpEndpointTerminationError(termination);
|
|
31621
|
+
throw new AcpExecutionError(exitMessage, { cause }, cause.code);
|
|
31622
|
+
}),
|
|
31623
|
+
aborted2
|
|
31624
|
+
]);
|
|
31625
|
+
} catch (error62) {
|
|
31626
|
+
signal.throwIfAborted();
|
|
31627
|
+
if (error62 instanceof RequestError3 && error62.code === -32e3) {
|
|
31628
|
+
throw new AcpExecutionError(
|
|
31629
|
+
"Agent authentication is required",
|
|
31630
|
+
{ cause: error62 },
|
|
31631
|
+
"authentication_required"
|
|
31632
|
+
);
|
|
31633
|
+
}
|
|
31634
|
+
if (error62 instanceof RequestError3) {
|
|
31635
|
+
throw new AcpExecutionError(truncate3(error62.message, 500), { cause: error62 }, "acp_agent_error");
|
|
31636
|
+
}
|
|
31637
|
+
throw error62;
|
|
31638
|
+
}
|
|
31639
|
+
} finally {
|
|
31640
|
+
removeAbortListener();
|
|
31641
|
+
}
|
|
31642
|
+
};
|
|
31643
|
+
};
|
|
31644
|
+
|
|
31645
|
+
// src/acp/activity.ts
|
|
31646
|
+
var AcpActivityNarration = class {
|
|
31647
|
+
activityId;
|
|
31648
|
+
activityType;
|
|
31649
|
+
sequence;
|
|
31650
|
+
text;
|
|
31651
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
31652
|
+
this.activityId = activityId;
|
|
31653
|
+
this.activityType = activityType;
|
|
31654
|
+
this.sequence = sequence;
|
|
31655
|
+
this.text = text2;
|
|
31656
|
+
}
|
|
31657
|
+
};
|
|
31658
|
+
var AcpActivity = class _AcpActivity {
|
|
31659
|
+
activityId;
|
|
31660
|
+
activityType;
|
|
31661
|
+
input;
|
|
31662
|
+
locations;
|
|
31663
|
+
name;
|
|
31664
|
+
output;
|
|
31665
|
+
sequence;
|
|
31666
|
+
status;
|
|
31667
|
+
title;
|
|
31668
|
+
toolKind;
|
|
31669
|
+
content;
|
|
31670
|
+
detail;
|
|
31671
|
+
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
31672
|
+
this.activityId = activityId;
|
|
31673
|
+
this.activityType = activityType;
|
|
31674
|
+
this.input = input2;
|
|
31675
|
+
this.locations = locations;
|
|
31676
|
+
this.name = name;
|
|
31677
|
+
this.output = output2;
|
|
31678
|
+
this.sequence = sequence;
|
|
31679
|
+
this.status = status;
|
|
31680
|
+
this.title = title2;
|
|
31681
|
+
this.toolKind = toolKind;
|
|
31682
|
+
this.content = content;
|
|
31683
|
+
this.detail = detail;
|
|
31684
|
+
}
|
|
31685
|
+
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
31686
|
+
this.activityId,
|
|
31687
|
+
this.activityType,
|
|
31688
|
+
this.input,
|
|
31689
|
+
this.locations,
|
|
31690
|
+
this.name,
|
|
31691
|
+
this.output,
|
|
31692
|
+
this.sequence,
|
|
31693
|
+
"completed",
|
|
31694
|
+
this.title,
|
|
31695
|
+
this.toolKind,
|
|
31696
|
+
this.content,
|
|
31697
|
+
this.detail
|
|
31698
|
+
) : this;
|
|
31699
|
+
};
|
|
31700
|
+
var ActivityIdentity = class {
|
|
31701
|
+
id;
|
|
31702
|
+
sequence;
|
|
31703
|
+
constructor(id, sequence) {
|
|
31704
|
+
this.id = id;
|
|
31705
|
+
this.sequence = sequence;
|
|
31706
|
+
}
|
|
31707
|
+
};
|
|
31508
31708
|
var AcpActivityTracker = class {
|
|
31509
31709
|
#activities = /* @__PURE__ */ new Map();
|
|
31510
31710
|
#identities = /* @__PURE__ */ new Map();
|
|
@@ -31757,203 +31957,58 @@ var AcpActivityTracker = class {
|
|
|
31757
31957
|
};
|
|
31758
31958
|
};
|
|
31759
31959
|
|
|
31760
|
-
// src/acp/agent-
|
|
31761
|
-
|
|
31762
|
-
|
|
31763
|
-
|
|
31764
|
-
|
|
31765
|
-
|
|
31766
|
-
|
|
31767
|
-
|
|
31768
|
-
|
|
31769
|
-
|
|
31770
|
-
}
|
|
31771
|
-
function readString2(value, fallback = "") {
|
|
31772
|
-
return typeof value === "string" ? value : fallback;
|
|
31773
|
-
}
|
|
31774
|
-
|
|
31775
|
-
// src/acp/agent-connection.ts
|
|
31776
|
-
function readableWebStream(input2) {
|
|
31777
|
-
let streamOpen = true;
|
|
31778
|
-
return new ReadableStream({
|
|
31779
|
-
start(controller) {
|
|
31780
|
-
input2.on("data", (chunk) => {
|
|
31781
|
-
if (!streamOpen) {
|
|
31782
|
-
return;
|
|
31783
|
-
}
|
|
31784
|
-
if (chunk instanceof Uint8Array) {
|
|
31785
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
31786
|
-
return;
|
|
31787
|
-
}
|
|
31788
|
-
streamOpen = false;
|
|
31789
|
-
controller.error(new Error("ACP process produced a non-binary chunk"));
|
|
31790
|
-
});
|
|
31791
|
-
input2.once("end", () => {
|
|
31792
|
-
if (!streamOpen) {
|
|
31793
|
-
return;
|
|
31794
|
-
}
|
|
31795
|
-
streamOpen = false;
|
|
31796
|
-
controller.close();
|
|
31797
|
-
});
|
|
31798
|
-
input2.once("error", (error62) => {
|
|
31799
|
-
if (!streamOpen) {
|
|
31800
|
-
return;
|
|
31801
|
-
}
|
|
31802
|
-
streamOpen = false;
|
|
31803
|
-
controller.error(error62);
|
|
31804
|
-
});
|
|
31805
|
-
},
|
|
31806
|
-
cancel() {
|
|
31807
|
-
streamOpen = false;
|
|
31808
|
-
}
|
|
31809
|
-
});
|
|
31810
|
-
}
|
|
31811
|
-
function createWritableAcpStream(output2) {
|
|
31812
|
-
let outputFailure;
|
|
31813
|
-
const pendingWriteFailures = /* @__PURE__ */ new Set();
|
|
31814
|
-
const fail = (error62) => {
|
|
31815
|
-
outputFailure = error62;
|
|
31816
|
-
for (const reject of pendingWriteFailures) {
|
|
31817
|
-
reject(error62);
|
|
31960
|
+
// src/acp/agent-turn.ts
|
|
31961
|
+
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31962
|
+
var AcpTurnState = class {
|
|
31963
|
+
#bufferedText = [];
|
|
31964
|
+
bufferText = (text2, messageId) => {
|
|
31965
|
+
const previous = this.#bufferedText.at(-1);
|
|
31966
|
+
if (previous?.messageId === messageId) {
|
|
31967
|
+
previous.chunks.push(text2);
|
|
31968
|
+
} else {
|
|
31969
|
+
this.#bufferedText.push({ chunks: [text2], messageId });
|
|
31818
31970
|
}
|
|
31819
|
-
pendingWriteFailures.clear();
|
|
31820
31971
|
};
|
|
31821
|
-
|
|
31822
|
-
|
|
31823
|
-
|
|
31824
|
-
|
|
31825
|
-
|
|
31826
|
-
|
|
31827
|
-
return new WritableStream({
|
|
31828
|
-
write(chunk) {
|
|
31829
|
-
if (outputFailure !== void 0) {
|
|
31830
|
-
return Promise.reject(outputFailure);
|
|
31831
|
-
}
|
|
31832
|
-
return new Promise((resolve9, reject) => {
|
|
31833
|
-
pendingWriteFailures.add(reject);
|
|
31834
|
-
output2.write(chunk, (error62) => {
|
|
31835
|
-
pendingWriteFailures.delete(reject);
|
|
31836
|
-
if (error62) {
|
|
31837
|
-
outputFailure = error62;
|
|
31838
|
-
reject(error62);
|
|
31839
|
-
return;
|
|
31840
|
-
}
|
|
31841
|
-
if (outputFailure !== void 0) {
|
|
31842
|
-
reject(outputFailure);
|
|
31843
|
-
return;
|
|
31844
|
-
}
|
|
31845
|
-
resolve9();
|
|
31846
|
-
});
|
|
31847
|
-
});
|
|
31848
|
-
}
|
|
31849
|
-
});
|
|
31850
|
-
}
|
|
31851
|
-
var AgentConnection = class {
|
|
31852
|
-
connection;
|
|
31853
|
-
termination;
|
|
31854
|
-
#process;
|
|
31855
|
-
constructor(agent, cwd, client2) {
|
|
31856
|
-
if (agent.kind === "in-process-acp") {
|
|
31857
|
-
const inProcess = agent.createEndpoint({
|
|
31858
|
-
command: agent.command,
|
|
31859
|
-
cwd,
|
|
31860
|
-
environment: agent.environment
|
|
31861
|
-
});
|
|
31862
|
-
this.#process = { kind: "in-process", endpoint: inProcess };
|
|
31863
|
-
this.termination = inProcess.terminated;
|
|
31864
|
-
this.connection = createAcpClient(client2).connect(inProcess.app());
|
|
31865
|
-
return;
|
|
31866
|
-
}
|
|
31867
|
-
const child = spawn4(agent.adapterPath, [...agent.arguments], {
|
|
31868
|
-
cwd,
|
|
31869
|
-
detached: process.platform !== "win32",
|
|
31870
|
-
env: { ...process.env, ...agent.environment },
|
|
31871
|
-
shell: false,
|
|
31872
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
31873
|
-
});
|
|
31874
|
-
this.#process = { kind: "child", child };
|
|
31875
|
-
const stdin = child.stdin;
|
|
31876
|
-
const stdout = child.stdout;
|
|
31877
|
-
const stderr = child.stderr;
|
|
31878
|
-
if (stdin === null || stdout === null || stderr === null) {
|
|
31879
|
-
child.kill("SIGKILL");
|
|
31880
|
-
throw new AcpExecutionError("ACP process streams are unavailable");
|
|
31881
|
-
}
|
|
31882
|
-
stderr.setEncoding("utf8");
|
|
31883
|
-
stderr.on("data", (chunk) => {
|
|
31884
|
-
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
31885
|
-
});
|
|
31886
|
-
this.termination = new Promise((resolve9) => {
|
|
31887
|
-
child.once("error", (cause) => {
|
|
31888
|
-
resolve9({ kind: "failed", error: new AcpExecutionError("The ACP process could not run", { cause }) });
|
|
31889
|
-
});
|
|
31890
|
-
child.once("exit", (code, signal) => {
|
|
31891
|
-
resolve9({
|
|
31892
|
-
kind: "failed",
|
|
31893
|
-
error: new AcpExecutionError("The ACP process stopped", { cause: { code, signal } })
|
|
31894
|
-
});
|
|
31895
|
-
});
|
|
31896
|
-
});
|
|
31897
|
-
const stream = ndJsonStream2(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
31898
|
-
this.connection = createAcpClient(client2).connect(stream);
|
|
31899
|
-
}
|
|
31900
|
-
get inProcessAgent() {
|
|
31901
|
-
return this.#process.kind === "in-process" ? this.#process.endpoint : null;
|
|
31902
|
-
}
|
|
31903
|
-
captureProcessTree = async () => this.#process.kind === "child" ? await captureProcessTree(this.#process.child) : [];
|
|
31904
|
-
closeProcess = async (capturedProcesses = []) => {
|
|
31905
|
-
try {
|
|
31906
|
-
if (this.#process.kind === "in-process") {
|
|
31907
|
-
await this.#process.endpoint.close();
|
|
31908
|
-
return;
|
|
31972
|
+
flushText = async () => {
|
|
31973
|
+
const buffered = this.#bufferedText;
|
|
31974
|
+
this.#bufferedText = [];
|
|
31975
|
+
for (const message of buffered) {
|
|
31976
|
+
for (const chunk of message.chunks) {
|
|
31977
|
+
await this.onText(chunk, message.messageId);
|
|
31909
31978
|
}
|
|
31910
|
-
await stopProcessTree(this.#process.child, capturedProcesses);
|
|
31911
|
-
} finally {
|
|
31912
|
-
this.connection.close();
|
|
31913
31979
|
}
|
|
31914
31980
|
};
|
|
31915
|
-
|
|
31916
|
-
|
|
31917
|
-
|
|
31918
|
-
|
|
31919
|
-
|
|
31920
|
-
|
|
31921
|
-
reject(signal.reason ?? new Error("ACP request was cancelled"));
|
|
31922
|
-
};
|
|
31923
|
-
signal.addEventListener("abort", rejectAbort, { once: true });
|
|
31924
|
-
removeAbortListener = () => {
|
|
31925
|
-
signal.removeEventListener("abort", rejectAbort);
|
|
31926
|
-
};
|
|
31927
|
-
});
|
|
31928
|
-
try {
|
|
31929
|
-
try {
|
|
31930
|
-
return await Promise.race([
|
|
31931
|
-
operation,
|
|
31932
|
-
this.termination.then((termination) => {
|
|
31933
|
-
const cause = acpEndpointTerminationError(termination);
|
|
31934
|
-
throw new AcpExecutionError(exitMessage, { cause }, cause.code);
|
|
31935
|
-
}),
|
|
31936
|
-
aborted2
|
|
31937
|
-
]);
|
|
31938
|
-
} catch (error62) {
|
|
31939
|
-
signal.throwIfAborted();
|
|
31940
|
-
if (error62 instanceof RequestError3 && error62.code === -32e3) {
|
|
31941
|
-
throw new AcpExecutionError(
|
|
31942
|
-
"Agent authentication is required",
|
|
31943
|
-
{ cause: error62 },
|
|
31944
|
-
"authentication_required"
|
|
31945
|
-
);
|
|
31946
|
-
}
|
|
31947
|
-
if (error62 instanceof RequestError3) {
|
|
31948
|
-
throw new AcpExecutionError(truncate3(error62.message, 500), { cause: error62 }, "acp_agent_error");
|
|
31949
|
-
}
|
|
31950
|
-
throw error62;
|
|
31981
|
+
recordTextAsProgress = async () => {
|
|
31982
|
+
const buffered = this.#bufferedText;
|
|
31983
|
+
this.#bufferedText = [];
|
|
31984
|
+
for (const message of buffered) {
|
|
31985
|
+
for (const chunk of message.chunks) {
|
|
31986
|
+
await this.activities.recordNarrative("progress", message.messageId, chunk);
|
|
31951
31987
|
}
|
|
31952
|
-
} finally {
|
|
31953
|
-
removeAbortListener();
|
|
31954
31988
|
}
|
|
31955
31989
|
};
|
|
31956
31990
|
};
|
|
31991
|
+
var IdleAcpTurn = class extends AcpTurnState {
|
|
31992
|
+
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
31993
|
+
running = false;
|
|
31994
|
+
activities = new AcpActivityTracker(
|
|
31995
|
+
() => Promise.resolve(),
|
|
31996
|
+
() => Promise.resolve()
|
|
31997
|
+
);
|
|
31998
|
+
onText = () => Promise.resolve();
|
|
31999
|
+
};
|
|
32000
|
+
var RunningAcpTurn = class extends AcpTurnState {
|
|
32001
|
+
commandId;
|
|
32002
|
+
running = true;
|
|
32003
|
+
activities;
|
|
32004
|
+
onText;
|
|
32005
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32006
|
+
super();
|
|
32007
|
+
this.commandId = commandId;
|
|
32008
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32009
|
+
this.onText = onText;
|
|
32010
|
+
}
|
|
32011
|
+
};
|
|
31957
32012
|
|
|
31958
32013
|
// src/acp/native-session.ts
|
|
31959
32014
|
var path2 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
@@ -32710,31 +32765,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
32710
32765
|
return validated;
|
|
32711
32766
|
}
|
|
32712
32767
|
|
|
32713
|
-
// src/acp/
|
|
32714
|
-
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
32715
|
-
var AcpTurnState = class {
|
|
32716
|
-
};
|
|
32717
|
-
var IdleAcpTurn = class extends AcpTurnState {
|
|
32718
|
-
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
32719
|
-
running = false;
|
|
32720
|
-
activities = new AcpActivityTracker(
|
|
32721
|
-
() => Promise.resolve(),
|
|
32722
|
-
() => Promise.resolve()
|
|
32723
|
-
);
|
|
32724
|
-
onText = () => Promise.resolve();
|
|
32725
|
-
};
|
|
32726
|
-
var RunningAcpTurn = class extends AcpTurnState {
|
|
32727
|
-
commandId;
|
|
32728
|
-
running = true;
|
|
32729
|
-
activities;
|
|
32730
|
-
onText;
|
|
32731
|
-
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
32732
|
-
super();
|
|
32733
|
-
this.commandId = commandId;
|
|
32734
|
-
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
32735
|
-
this.onText = onText;
|
|
32736
|
-
}
|
|
32737
|
-
};
|
|
32768
|
+
// src/acp/pending-interactions.ts
|
|
32738
32769
|
var PendingPermission = class {
|
|
32739
32770
|
completion = Promise.withResolvers();
|
|
32740
32771
|
interactionId;
|
|
@@ -38685,7 +38716,6 @@ var AgentSession = class _AgentSession {
|
|
|
38685
38716
|
#verifiedAgentVersion;
|
|
38686
38717
|
#agentName = "";
|
|
38687
38718
|
#agentVersion = "";
|
|
38688
|
-
#bufferedAgentText = [];
|
|
38689
38719
|
#capabilities = unsupportedSessionCapabilities();
|
|
38690
38720
|
#commands = [];
|
|
38691
38721
|
#configRevision = 0;
|
|
@@ -38831,35 +38861,6 @@ var AgentSession = class _AgentSession {
|
|
|
38831
38861
|
this.#replay = { kind: "idle" };
|
|
38832
38862
|
}
|
|
38833
38863
|
};
|
|
38834
|
-
emitAgentMessage = async (chunks, messageId) => {
|
|
38835
|
-
for (const chunk of chunks) {
|
|
38836
|
-
await this.#turn.onText(chunk, messageId);
|
|
38837
|
-
}
|
|
38838
|
-
};
|
|
38839
|
-
bufferAgentText = async (text2, messageId) => {
|
|
38840
|
-
const previous = this.#bufferedAgentText.at(-1);
|
|
38841
|
-
if (previous?.messageId === messageId) {
|
|
38842
|
-
previous.chunks.push(text2);
|
|
38843
|
-
return;
|
|
38844
|
-
}
|
|
38845
|
-
this.#bufferedAgentText.push({ chunks: [text2], messageId });
|
|
38846
|
-
};
|
|
38847
|
-
flushAgentText = async () => {
|
|
38848
|
-
const buffered = this.#bufferedAgentText;
|
|
38849
|
-
this.#bufferedAgentText = [];
|
|
38850
|
-
for (const message of buffered) {
|
|
38851
|
-
await this.emitAgentMessage(message.chunks, message.messageId);
|
|
38852
|
-
}
|
|
38853
|
-
};
|
|
38854
|
-
recordBufferedAgentTextAsProgress = async () => {
|
|
38855
|
-
const buffered = this.#bufferedAgentText;
|
|
38856
|
-
this.#bufferedAgentText = [];
|
|
38857
|
-
for (const message of buffered) {
|
|
38858
|
-
for (const chunk of message.chunks) {
|
|
38859
|
-
await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
|
|
38860
|
-
}
|
|
38861
|
-
}
|
|
38862
|
-
};
|
|
38863
38864
|
prepareAgentContent = async (content) => {
|
|
38864
38865
|
if (content.type === "image" && content.uri.length > 0) {
|
|
38865
38866
|
const signal = AbortSignal.timeout(2e4);
|
|
@@ -39357,7 +39358,7 @@ var AgentSession = class _AgentSession {
|
|
|
39357
39358
|
options.signal
|
|
39358
39359
|
);
|
|
39359
39360
|
await this.#updates.drained();
|
|
39360
|
-
await this.
|
|
39361
|
+
await this.#turn.flushText();
|
|
39361
39362
|
await running.activities.finish();
|
|
39362
39363
|
let result;
|
|
39363
39364
|
try {
|
|
@@ -39389,7 +39390,6 @@ var AgentSession = class _AgentSession {
|
|
|
39389
39390
|
cause: error62
|
|
39390
39391
|
});
|
|
39391
39392
|
} finally {
|
|
39392
|
-
this.#bufferedAgentText = [];
|
|
39393
39393
|
this.#turn = new IdleAcpTurn();
|
|
39394
39394
|
}
|
|
39395
39395
|
};
|
|
@@ -39480,11 +39480,11 @@ var AgentSession = class _AgentSession {
|
|
|
39480
39480
|
);
|
|
39481
39481
|
} else {
|
|
39482
39482
|
await this.#turn.activities.finishNarrative();
|
|
39483
|
-
|
|
39483
|
+
this.#turn.bufferText(update.content.text, truncate3(update.messageId ?? "", 255));
|
|
39484
39484
|
}
|
|
39485
39485
|
} else {
|
|
39486
39486
|
await this.#turn.activities.finishNarrative();
|
|
39487
|
-
await this.
|
|
39487
|
+
await this.#turn.flushText();
|
|
39488
39488
|
await this.emitAgentContent(
|
|
39489
39489
|
normalizeContentBlock(update.content),
|
|
39490
39490
|
truncate3(update.messageId ?? "", 255)
|
|
@@ -39503,7 +39503,7 @@ var AgentSession = class _AgentSession {
|
|
|
39503
39503
|
return;
|
|
39504
39504
|
}
|
|
39505
39505
|
if (update.sessionUpdate === "tool_call") {
|
|
39506
|
-
await this.
|
|
39506
|
+
await this.#turn.recordTextAsProgress();
|
|
39507
39507
|
await this.#turn.activities.recordToolCall(update);
|
|
39508
39508
|
return;
|
|
39509
39509
|
}
|