@moxt-ai/mobius 0.0.98 → 0.0.100
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/cli.js +277 -279
- package/dist/cli.js.map +4 -4
- package/dist/daemon-observers.d.ts +30 -0
- package/dist/daemon-observers.d.ts.map +1 -0
- package/dist/daemon-observers.js +137 -0
- package/dist/daemon-observers.js.map +1 -0
- package/dist/daemon-turn-reconciliation.d.ts +27 -0
- package/dist/daemon-turn-reconciliation.d.ts.map +1 -0
- package/dist/daemon-turn-reconciliation.js +121 -0
- package/dist/daemon-turn-reconciliation.js.map +1 -0
- package/dist/index.js +276 -278
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/acp-adapter.d.ts +3 -0
- package/dist/native-sessions/acp-adapter.d.ts.map +1 -0
- package/dist/native-sessions/{claude-adapter.js → acp-adapter.js} +2 -2
- package/dist/native-sessions/acp-adapter.js.map +1 -0
- package/dist/native-sessions/agent-adapter.d.ts.map +1 -1
- package/dist/native-sessions/agent-adapter.js +3 -7
- package/dist/native-sessions/agent-adapter.js.map +1 -1
- package/dist/native-sessions/chat-agent.js +2 -2
- package/dist/native-sessions/chat-agent.js.map +1 -1
- package/dist/relay-connection/session-event-outbox.js +3 -3
- package/dist/relay-connection/session-event-outbox.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +6 -255
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +276 -278
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/native-sessions/claude-adapter.d.ts +0 -3
- package/dist/native-sessions/claude-adapter.d.ts.map +0 -1
- package/dist/native-sessions/claude-adapter.js.map +0 -1
- package/dist/native-sessions/opencode-adapter.d.ts +0 -3
- package/dist/native-sessions/opencode-adapter.d.ts.map +0 -1
- package/dist/native-sessions/opencode-adapter.js +0 -7
- package/dist/native-sessions/opencode-adapter.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.100",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -30613,7 +30613,7 @@ var AuditStore = class {
|
|
|
30613
30613
|
// src/run-daemon.ts
|
|
30614
30614
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
30615
30615
|
import { styleText } from "node:util";
|
|
30616
|
-
import {
|
|
30616
|
+
import { WebSocket as WebSocket5 } from "undici";
|
|
30617
30617
|
|
|
30618
30618
|
// src/infra/operation-metrics.ts
|
|
30619
30619
|
var AccumulatingOperationMetrics = class {
|
|
@@ -30668,7 +30668,7 @@ var nativeSessionPageSchema = external_exports.object({
|
|
|
30668
30668
|
|
|
30669
30669
|
// src/native-sessions/chat-agent.ts
|
|
30670
30670
|
function supportsNativeChat(agentId) {
|
|
30671
|
-
return agentId === "codex" || agentId === "claude" || agentId === "opencode";
|
|
30671
|
+
return agentId === "codex" || agentId === "claude" || agentId === "opencode" || agentId === "pi";
|
|
30672
30672
|
}
|
|
30673
30673
|
function isNativeChatSessionId(agentId, sessionId) {
|
|
30674
30674
|
if (!nativeSessionIdSchema.safeParse(sessionId).success) {
|
|
@@ -30677,7 +30677,7 @@ function isNativeChatSessionId(agentId, sessionId) {
|
|
|
30677
30677
|
if (agentId === "opencode") {
|
|
30678
30678
|
return /^ses_[a-zA-Z0-9]+$/.test(sessionId);
|
|
30679
30679
|
}
|
|
30680
|
-
return (agentId === "codex" || agentId === "claude") && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(sessionId);
|
|
30680
|
+
return (agentId === "codex" || agentId === "claude" || agentId === "pi") && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(sessionId);
|
|
30681
30681
|
}
|
|
30682
30682
|
|
|
30683
30683
|
// src/acp/process-capacity.ts
|
|
@@ -36301,6 +36301,9 @@ var DaemonDiagnosticLog = class {
|
|
|
36301
36301
|
};
|
|
36302
36302
|
};
|
|
36303
36303
|
|
|
36304
|
+
// src/daemon-observers.ts
|
|
36305
|
+
import { WebSocket as WebSocket2 } from "undici";
|
|
36306
|
+
|
|
36304
36307
|
// src/daemon-session-commands.ts
|
|
36305
36308
|
import { basename as basename6 } from "node:path";
|
|
36306
36309
|
import { WebSocket } from "undici";
|
|
@@ -37498,6 +37501,253 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
37498
37501
|
}
|
|
37499
37502
|
}
|
|
37500
37503
|
|
|
37504
|
+
// src/daemon-observers.ts
|
|
37505
|
+
var DaemonAcpObserver = class {
|
|
37506
|
+
#record;
|
|
37507
|
+
constructor(record2) {
|
|
37508
|
+
this.#record = record2;
|
|
37509
|
+
}
|
|
37510
|
+
onCommands = (event) => {
|
|
37511
|
+
this.#record(event.sessionId, event);
|
|
37512
|
+
return Promise.resolve();
|
|
37513
|
+
};
|
|
37514
|
+
onConfig = (event) => {
|
|
37515
|
+
this.#record(event.sessionId, event);
|
|
37516
|
+
return Promise.resolve();
|
|
37517
|
+
};
|
|
37518
|
+
onContent = (event) => {
|
|
37519
|
+
this.#record(event.sessionId, event);
|
|
37520
|
+
return Promise.resolve();
|
|
37521
|
+
};
|
|
37522
|
+
onElicitation = (event) => {
|
|
37523
|
+
this.#record(event.sessionId, event);
|
|
37524
|
+
return Promise.resolve();
|
|
37525
|
+
};
|
|
37526
|
+
onElicitationResolved = (event) => {
|
|
37527
|
+
this.#record(event.sessionId, event);
|
|
37528
|
+
return Promise.resolve();
|
|
37529
|
+
};
|
|
37530
|
+
onInfo = (event) => {
|
|
37531
|
+
this.#record(event.sessionId, event);
|
|
37532
|
+
return Promise.resolve();
|
|
37533
|
+
};
|
|
37534
|
+
onPermission = (event) => {
|
|
37535
|
+
this.#record(event.sessionId, event);
|
|
37536
|
+
return Promise.resolve();
|
|
37537
|
+
};
|
|
37538
|
+
onPermissionResolved = (event) => {
|
|
37539
|
+
this.#record(event.sessionId, event);
|
|
37540
|
+
return Promise.resolve();
|
|
37541
|
+
};
|
|
37542
|
+
onUsage = (event) => {
|
|
37543
|
+
this.#record(event.sessionId, event);
|
|
37544
|
+
return Promise.resolve();
|
|
37545
|
+
};
|
|
37546
|
+
};
|
|
37547
|
+
var AuditInstallationEvents = class {
|
|
37548
|
+
#audit;
|
|
37549
|
+
constructor(audit) {
|
|
37550
|
+
this.#audit = audit;
|
|
37551
|
+
}
|
|
37552
|
+
record = (event, requestId, agentId, details = {}) => {
|
|
37553
|
+
this.#audit.record({
|
|
37554
|
+
commandId: requestId,
|
|
37555
|
+
details,
|
|
37556
|
+
event,
|
|
37557
|
+
sessionId: `agent-installation:${agentId}`
|
|
37558
|
+
});
|
|
37559
|
+
};
|
|
37560
|
+
};
|
|
37561
|
+
var DaemonInstallationObserver = class {
|
|
37562
|
+
#started = /* @__PURE__ */ new Set();
|
|
37563
|
+
#socket = null;
|
|
37564
|
+
connect = (socket) => {
|
|
37565
|
+
this.#socket = socket;
|
|
37566
|
+
};
|
|
37567
|
+
disconnect = (socket) => {
|
|
37568
|
+
if (this.#socket === socket) {
|
|
37569
|
+
this.#socket = null;
|
|
37570
|
+
}
|
|
37571
|
+
};
|
|
37572
|
+
#send = (socket, message) => {
|
|
37573
|
+
try {
|
|
37574
|
+
send(socket, message);
|
|
37575
|
+
} catch {
|
|
37576
|
+
if (this.#socket === socket) {
|
|
37577
|
+
this.#socket = null;
|
|
37578
|
+
}
|
|
37579
|
+
}
|
|
37580
|
+
};
|
|
37581
|
+
onState = (state) => {
|
|
37582
|
+
const socket = this.#socket;
|
|
37583
|
+
if (socket === null || socket.readyState !== WebSocket2.OPEN) {
|
|
37584
|
+
return Promise.resolve();
|
|
37585
|
+
}
|
|
37586
|
+
if (state instanceof RequestedInstallation) {
|
|
37587
|
+
return Promise.resolve();
|
|
37588
|
+
}
|
|
37589
|
+
if (state instanceof RunningInstallation) {
|
|
37590
|
+
if (!this.#started.has(state.requestId)) {
|
|
37591
|
+
this.#started.add(state.requestId);
|
|
37592
|
+
this.#send(socket, {
|
|
37593
|
+
agentId: state.agentId,
|
|
37594
|
+
kind: AGENT_INSTALL_STARTED_KIND,
|
|
37595
|
+
requestId: state.requestId
|
|
37596
|
+
});
|
|
37597
|
+
}
|
|
37598
|
+
this.#send(socket, {
|
|
37599
|
+
agentId: state.agentId,
|
|
37600
|
+
kind: AGENT_INSTALL_PROGRESS_KIND,
|
|
37601
|
+
requestId: state.requestId,
|
|
37602
|
+
stage: state.stage
|
|
37603
|
+
});
|
|
37604
|
+
return Promise.resolve();
|
|
37605
|
+
}
|
|
37606
|
+
if (state instanceof SucceededInstallation) {
|
|
37607
|
+
this.#send(socket, {
|
|
37608
|
+
agentId: state.agentId,
|
|
37609
|
+
authenticationMayBeRequired: state.authenticationMayBeRequired,
|
|
37610
|
+
kind: AGENT_INSTALL_COMPLETED_KIND,
|
|
37611
|
+
requestId: state.requestId
|
|
37612
|
+
});
|
|
37613
|
+
return Promise.resolve();
|
|
37614
|
+
}
|
|
37615
|
+
if (state instanceof FailedInstallation) {
|
|
37616
|
+
this.#send(socket, {
|
|
37617
|
+
agentId: state.agentId,
|
|
37618
|
+
code: state.code,
|
|
37619
|
+
kind: AGENT_INSTALL_FAILED_KIND,
|
|
37620
|
+
message: state.message,
|
|
37621
|
+
requestId: state.requestId
|
|
37622
|
+
});
|
|
37623
|
+
return Promise.resolve();
|
|
37624
|
+
}
|
|
37625
|
+
if (state instanceof CancelledInstallation) {
|
|
37626
|
+
this.#send(socket, {
|
|
37627
|
+
agentId: state.agentId,
|
|
37628
|
+
kind: AGENT_INSTALL_CANCELLED_KIND,
|
|
37629
|
+
requestId: state.requestId
|
|
37630
|
+
});
|
|
37631
|
+
return Promise.resolve();
|
|
37632
|
+
}
|
|
37633
|
+
throw new Error("Unsupported Agent integration installation state");
|
|
37634
|
+
};
|
|
37635
|
+
};
|
|
37636
|
+
|
|
37637
|
+
// src/daemon-turn-reconciliation.ts
|
|
37638
|
+
import { fetch as fetch5 } from "undici";
|
|
37639
|
+
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
37640
|
+
var ActiveDaemonTurn = class {
|
|
37641
|
+
attemptId;
|
|
37642
|
+
command;
|
|
37643
|
+
#controller;
|
|
37644
|
+
#finished = Promise.withResolvers();
|
|
37645
|
+
#cancellationRequested = false;
|
|
37646
|
+
constructor(command, attemptId) {
|
|
37647
|
+
this.attemptId = attemptId;
|
|
37648
|
+
this.command = command;
|
|
37649
|
+
this.#controller = new AbortController();
|
|
37650
|
+
}
|
|
37651
|
+
abortDaemon = () => {
|
|
37652
|
+
this.#controller.abort();
|
|
37653
|
+
};
|
|
37654
|
+
finish = () => this.#finished.resolve();
|
|
37655
|
+
matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
|
|
37656
|
+
requestCancellation = () => {
|
|
37657
|
+
if (this.#cancellationRequested) {
|
|
37658
|
+
return false;
|
|
37659
|
+
}
|
|
37660
|
+
this.#cancellationRequested = true;
|
|
37661
|
+
return true;
|
|
37662
|
+
};
|
|
37663
|
+
get signal() {
|
|
37664
|
+
return this.#controller.signal;
|
|
37665
|
+
}
|
|
37666
|
+
get completion() {
|
|
37667
|
+
return this.#finished.promise;
|
|
37668
|
+
}
|
|
37669
|
+
};
|
|
37670
|
+
var ActiveTurnReconciliationError = class extends Error {
|
|
37671
|
+
code = "active_turn_reconciliation_failed";
|
|
37672
|
+
diagnosticDetails;
|
|
37673
|
+
relayErrorCode;
|
|
37674
|
+
terminal;
|
|
37675
|
+
constructor(message, options = {}) {
|
|
37676
|
+
super(message, options);
|
|
37677
|
+
this.name = "ActiveTurnReconciliationError";
|
|
37678
|
+
this.relayErrorCode = options.relayErrorCode ?? null;
|
|
37679
|
+
this.terminal = options.terminal ?? false;
|
|
37680
|
+
this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
|
|
37681
|
+
}
|
|
37682
|
+
};
|
|
37683
|
+
var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
|
|
37684
|
+
async function relayErrorCode(response) {
|
|
37685
|
+
try {
|
|
37686
|
+
const body = JSON.parse(await response.text());
|
|
37687
|
+
if (typeof body !== "object" || body === null) {
|
|
37688
|
+
return null;
|
|
37689
|
+
}
|
|
37690
|
+
const error62 = Reflect.get(body, "error");
|
|
37691
|
+
if (typeof error62 !== "object" || error62 === null) {
|
|
37692
|
+
return null;
|
|
37693
|
+
}
|
|
37694
|
+
const code = Reflect.get(error62, "code");
|
|
37695
|
+
return typeof code === "string" && code.length > 0 ? code : null;
|
|
37696
|
+
} catch {
|
|
37697
|
+
return null;
|
|
37698
|
+
}
|
|
37699
|
+
}
|
|
37700
|
+
function activeTurnReconciliationEndpoint(config2, turn) {
|
|
37701
|
+
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
37702
|
+
let channelPath = "";
|
|
37703
|
+
if (endpoint.pathname.endsWith("/daemon")) {
|
|
37704
|
+
channelPath = endpoint.pathname.slice(0, -"/daemon".length);
|
|
37705
|
+
} else {
|
|
37706
|
+
const runtimePath = "/v1/runtimes/connect";
|
|
37707
|
+
if (!endpoint.pathname.endsWith(runtimePath)) {
|
|
37708
|
+
throw new ActiveTurnReconciliationError("The Relay URL is invalid");
|
|
37709
|
+
}
|
|
37710
|
+
channelPath = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}`;
|
|
37711
|
+
}
|
|
37712
|
+
endpoint.pathname = `${channelPath}/sessions/${encodeURIComponent(turn.command.sessionId)}/attempts/${encodeURIComponent(turn.attemptId)}/reconciliation`;
|
|
37713
|
+
return endpoint;
|
|
37714
|
+
}
|
|
37715
|
+
async function reconcileActiveTurn(config2, turn, signal) {
|
|
37716
|
+
signal.throwIfAborted();
|
|
37717
|
+
const timeoutSignal = AbortSignal.timeout(ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS);
|
|
37718
|
+
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
37719
|
+
let response;
|
|
37720
|
+
try {
|
|
37721
|
+
response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
|
|
37722
|
+
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
37723
|
+
dispatcher: environmentProxyDispatcher,
|
|
37724
|
+
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
37725
|
+
method: "POST",
|
|
37726
|
+
signal: requestSignal
|
|
37727
|
+
});
|
|
37728
|
+
} catch (error62) {
|
|
37729
|
+
if (signal.aborted) {
|
|
37730
|
+
signal.throwIfAborted();
|
|
37731
|
+
}
|
|
37732
|
+
throw new ActiveTurnReconciliationError(
|
|
37733
|
+
timeoutSignal.aborted ? "The active Agent turn reconciliation timed out" : "The active Agent turn could not be reconciled",
|
|
37734
|
+
{ cause: error62 }
|
|
37735
|
+
);
|
|
37736
|
+
}
|
|
37737
|
+
if (!response.ok) {
|
|
37738
|
+
const errorCode = await relayErrorCode(response);
|
|
37739
|
+
const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
|
|
37740
|
+
throw new ActiveTurnReconciliationError(
|
|
37741
|
+
terminal ? `The Relay reported that the active Agent turn can no longer be reconciled (${errorCode})` : `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`,
|
|
37742
|
+
{ relayErrorCode: errorCode, terminal }
|
|
37743
|
+
);
|
|
37744
|
+
}
|
|
37745
|
+
await response.body?.cancel();
|
|
37746
|
+
}
|
|
37747
|
+
async function reconcileActiveTurns(config2, turns, signal) {
|
|
37748
|
+
await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
|
|
37749
|
+
}
|
|
37750
|
+
|
|
37501
37751
|
// src/native-sessions/codex-history.ts
|
|
37502
37752
|
import { spawn as spawn5 } from "node:child_process";
|
|
37503
37753
|
var responseSchema = external_exports.union([
|
|
@@ -37960,8 +38210,8 @@ async function readAcpHistory(sessions, directories, bindingId, options, nativeS
|
|
|
37960
38210
|
throw new AcpExecutionError("The native Session was not found.", {}, "native_session_not_found");
|
|
37961
38211
|
}
|
|
37962
38212
|
|
|
37963
|
-
// src/native-sessions/
|
|
37964
|
-
var
|
|
38213
|
+
// src/native-sessions/acp-adapter.ts
|
|
38214
|
+
var acpSessionAdapter = {
|
|
37965
38215
|
linkedHistory: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
37966
38216
|
history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
37967
38217
|
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
@@ -37989,13 +38239,6 @@ var codexSessionAdapter = {
|
|
|
37989
38239
|
preview: async (context) => await verifiedHistory(context, false)
|
|
37990
38240
|
};
|
|
37991
38241
|
|
|
37992
|
-
// src/native-sessions/opencode-adapter.ts
|
|
37993
|
-
var openCodeSessionAdapter = {
|
|
37994
|
-
linkedHistory: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
37995
|
-
history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
37996
|
-
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
37997
|
-
};
|
|
37998
|
-
|
|
37999
38242
|
// src/native-sessions/agent-adapter.ts
|
|
38000
38243
|
var genericSessionAdapter = {
|
|
38001
38244
|
linkedHistory: async () => {
|
|
@@ -38010,11 +38253,8 @@ function nativeSessionAdapter(agentId) {
|
|
|
38010
38253
|
if (agentId === "codex") {
|
|
38011
38254
|
return codexSessionAdapter;
|
|
38012
38255
|
}
|
|
38013
|
-
if (agentId === "claude") {
|
|
38014
|
-
return
|
|
38015
|
-
}
|
|
38016
|
-
if (agentId === "opencode") {
|
|
38017
|
-
return openCodeSessionAdapter;
|
|
38256
|
+
if (agentId === "claude" || agentId === "opencode" || agentId === "pi") {
|
|
38257
|
+
return acpSessionAdapter;
|
|
38018
38258
|
}
|
|
38019
38259
|
return genericSessionAdapter;
|
|
38020
38260
|
}
|
|
@@ -38500,7 +38740,7 @@ var NativeSessionService = class {
|
|
|
38500
38740
|
};
|
|
38501
38741
|
|
|
38502
38742
|
// src/relay-connection/connect.ts
|
|
38503
|
-
import { WebSocket as
|
|
38743
|
+
import { WebSocket as WebSocket3 } from "undici";
|
|
38504
38744
|
|
|
38505
38745
|
// src/relay-connection/runtime-revocation.ts
|
|
38506
38746
|
var runtimeRevocationCloseCode = 1008;
|
|
@@ -38538,7 +38778,7 @@ function connectRelay(url2, signal) {
|
|
|
38538
38778
|
const endpoint = new URL(url2);
|
|
38539
38779
|
const headers = runtimeAuthorization(endpoint);
|
|
38540
38780
|
endpoint.searchParams.delete("token");
|
|
38541
|
-
const socket = new
|
|
38781
|
+
const socket = new WebSocket3(endpoint, {
|
|
38542
38782
|
dispatcher: environmentProxyDispatcher,
|
|
38543
38783
|
headers
|
|
38544
38784
|
});
|
|
@@ -38902,10 +39142,10 @@ var RelayConnectionLiveness = class {
|
|
|
38902
39142
|
import { createHash as createHash5 } from "node:crypto";
|
|
38903
39143
|
import { DatabaseSync } from "node:sqlite";
|
|
38904
39144
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
38905
|
-
criticalEventBytes:
|
|
38906
|
-
runtimeDeliveryBytes:
|
|
39145
|
+
criticalEventBytes: 40 * 1024 * 1024,
|
|
39146
|
+
runtimeDeliveryBytes: 32 * 1024 * 1024,
|
|
38907
39147
|
runtimeDeliveryCount: 64,
|
|
38908
|
-
standardEventBytes:
|
|
39148
|
+
standardEventBytes: 32 * 1024 * 1024
|
|
38909
39149
|
};
|
|
38910
39150
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
38911
39151
|
var SessionEventOutboxCapacityError = class extends Error {
|
|
@@ -39427,7 +39667,7 @@ function isDaemonExecutionState(value) {
|
|
|
39427
39667
|
}
|
|
39428
39668
|
|
|
39429
39669
|
// src/relay-connection/session-event-publisher.ts
|
|
39430
|
-
import { WebSocket as
|
|
39670
|
+
import { WebSocket as WebSocket4 } from "undici";
|
|
39431
39671
|
var DaemonSessionEventConnectionState = class {
|
|
39432
39672
|
};
|
|
39433
39673
|
var DisconnectedDaemonSessionEventState = class extends DaemonSessionEventConnectionState {
|
|
@@ -39444,7 +39684,7 @@ var ConnectedDaemonSessionEventState = class extends DaemonSessionEventConnectio
|
|
|
39444
39684
|
disconnect = (socket) => socket === this.#socket ? new DisconnectedDaemonSessionEventState() : this;
|
|
39445
39685
|
matches = (socket) => socket === this.#socket;
|
|
39446
39686
|
send = (message) => {
|
|
39447
|
-
if (this.#socket.readyState !==
|
|
39687
|
+
if (this.#socket.readyState !== WebSocket4.OPEN) {
|
|
39448
39688
|
return false;
|
|
39449
39689
|
}
|
|
39450
39690
|
try {
|
|
@@ -39671,249 +39911,7 @@ var systemDaemonTimer = new SystemDaemonTimer();
|
|
|
39671
39911
|
|
|
39672
39912
|
// src/run-daemon.ts
|
|
39673
39913
|
var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
39674
|
-
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39675
39914
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39676
|
-
var DaemonAcpObserver = class {
|
|
39677
|
-
#record;
|
|
39678
|
-
constructor(record2) {
|
|
39679
|
-
this.#record = record2;
|
|
39680
|
-
}
|
|
39681
|
-
onCommands = (event) => {
|
|
39682
|
-
this.#record(event.sessionId, event);
|
|
39683
|
-
return Promise.resolve();
|
|
39684
|
-
};
|
|
39685
|
-
onConfig = (event) => {
|
|
39686
|
-
this.#record(event.sessionId, event);
|
|
39687
|
-
return Promise.resolve();
|
|
39688
|
-
};
|
|
39689
|
-
onContent = (event) => {
|
|
39690
|
-
this.#record(event.sessionId, event);
|
|
39691
|
-
return Promise.resolve();
|
|
39692
|
-
};
|
|
39693
|
-
onElicitation = (event) => {
|
|
39694
|
-
this.#record(event.sessionId, event);
|
|
39695
|
-
return Promise.resolve();
|
|
39696
|
-
};
|
|
39697
|
-
onElicitationResolved = (event) => {
|
|
39698
|
-
this.#record(event.sessionId, event);
|
|
39699
|
-
return Promise.resolve();
|
|
39700
|
-
};
|
|
39701
|
-
onInfo = (event) => {
|
|
39702
|
-
this.#record(event.sessionId, event);
|
|
39703
|
-
return Promise.resolve();
|
|
39704
|
-
};
|
|
39705
|
-
onPermission = (event) => {
|
|
39706
|
-
this.#record(event.sessionId, event);
|
|
39707
|
-
return Promise.resolve();
|
|
39708
|
-
};
|
|
39709
|
-
onPermissionResolved = (event) => {
|
|
39710
|
-
this.#record(event.sessionId, event);
|
|
39711
|
-
return Promise.resolve();
|
|
39712
|
-
};
|
|
39713
|
-
onUsage = (event) => {
|
|
39714
|
-
this.#record(event.sessionId, event);
|
|
39715
|
-
return Promise.resolve();
|
|
39716
|
-
};
|
|
39717
|
-
};
|
|
39718
|
-
var AuditInstallationEvents = class {
|
|
39719
|
-
#audit;
|
|
39720
|
-
constructor(audit) {
|
|
39721
|
-
this.#audit = audit;
|
|
39722
|
-
}
|
|
39723
|
-
record = (event, requestId, agentId, details = {}) => {
|
|
39724
|
-
this.#audit.record({
|
|
39725
|
-
commandId: requestId,
|
|
39726
|
-
details,
|
|
39727
|
-
event,
|
|
39728
|
-
sessionId: `agent-installation:${agentId}`
|
|
39729
|
-
});
|
|
39730
|
-
};
|
|
39731
|
-
};
|
|
39732
|
-
var DaemonInstallationObserver = class {
|
|
39733
|
-
#started = /* @__PURE__ */ new Set();
|
|
39734
|
-
#socket = null;
|
|
39735
|
-
connect = (socket) => {
|
|
39736
|
-
this.#socket = socket;
|
|
39737
|
-
};
|
|
39738
|
-
disconnect = (socket) => {
|
|
39739
|
-
if (this.#socket === socket) {
|
|
39740
|
-
this.#socket = null;
|
|
39741
|
-
}
|
|
39742
|
-
};
|
|
39743
|
-
#send = (socket, message) => {
|
|
39744
|
-
try {
|
|
39745
|
-
send(socket, message);
|
|
39746
|
-
} catch {
|
|
39747
|
-
if (this.#socket === socket) {
|
|
39748
|
-
this.#socket = null;
|
|
39749
|
-
}
|
|
39750
|
-
}
|
|
39751
|
-
};
|
|
39752
|
-
onState = (state) => {
|
|
39753
|
-
const socket = this.#socket;
|
|
39754
|
-
if (socket === null || socket.readyState !== WebSocket4.OPEN) {
|
|
39755
|
-
return Promise.resolve();
|
|
39756
|
-
}
|
|
39757
|
-
if (state instanceof RequestedInstallation) {
|
|
39758
|
-
return Promise.resolve();
|
|
39759
|
-
}
|
|
39760
|
-
if (state instanceof RunningInstallation) {
|
|
39761
|
-
if (!this.#started.has(state.requestId)) {
|
|
39762
|
-
this.#started.add(state.requestId);
|
|
39763
|
-
this.#send(socket, {
|
|
39764
|
-
agentId: state.agentId,
|
|
39765
|
-
kind: AGENT_INSTALL_STARTED_KIND,
|
|
39766
|
-
requestId: state.requestId
|
|
39767
|
-
});
|
|
39768
|
-
}
|
|
39769
|
-
this.#send(socket, {
|
|
39770
|
-
agentId: state.agentId,
|
|
39771
|
-
kind: AGENT_INSTALL_PROGRESS_KIND,
|
|
39772
|
-
requestId: state.requestId,
|
|
39773
|
-
stage: state.stage
|
|
39774
|
-
});
|
|
39775
|
-
return Promise.resolve();
|
|
39776
|
-
}
|
|
39777
|
-
if (state instanceof SucceededInstallation) {
|
|
39778
|
-
this.#send(socket, {
|
|
39779
|
-
agentId: state.agentId,
|
|
39780
|
-
authenticationMayBeRequired: state.authenticationMayBeRequired,
|
|
39781
|
-
kind: AGENT_INSTALL_COMPLETED_KIND,
|
|
39782
|
-
requestId: state.requestId
|
|
39783
|
-
});
|
|
39784
|
-
return Promise.resolve();
|
|
39785
|
-
}
|
|
39786
|
-
if (state instanceof FailedInstallation) {
|
|
39787
|
-
this.#send(socket, {
|
|
39788
|
-
agentId: state.agentId,
|
|
39789
|
-
code: state.code,
|
|
39790
|
-
kind: AGENT_INSTALL_FAILED_KIND,
|
|
39791
|
-
message: state.message,
|
|
39792
|
-
requestId: state.requestId
|
|
39793
|
-
});
|
|
39794
|
-
return Promise.resolve();
|
|
39795
|
-
}
|
|
39796
|
-
if (state instanceof CancelledInstallation) {
|
|
39797
|
-
this.#send(socket, {
|
|
39798
|
-
agentId: state.agentId,
|
|
39799
|
-
kind: AGENT_INSTALL_CANCELLED_KIND,
|
|
39800
|
-
requestId: state.requestId
|
|
39801
|
-
});
|
|
39802
|
-
return Promise.resolve();
|
|
39803
|
-
}
|
|
39804
|
-
throw new Error("Unsupported Agent integration installation state");
|
|
39805
|
-
};
|
|
39806
|
-
};
|
|
39807
|
-
var ActiveDaemonTurn = class {
|
|
39808
|
-
attemptId;
|
|
39809
|
-
command;
|
|
39810
|
-
#controller;
|
|
39811
|
-
#finished = Promise.withResolvers();
|
|
39812
|
-
#cancellationRequested = false;
|
|
39813
|
-
constructor(command, attemptId) {
|
|
39814
|
-
this.attemptId = attemptId;
|
|
39815
|
-
this.command = command;
|
|
39816
|
-
this.#controller = new AbortController();
|
|
39817
|
-
}
|
|
39818
|
-
abortDaemon = () => {
|
|
39819
|
-
this.#controller.abort();
|
|
39820
|
-
};
|
|
39821
|
-
finish = () => this.#finished.resolve();
|
|
39822
|
-
matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
|
|
39823
|
-
requestCancellation = () => {
|
|
39824
|
-
if (this.#cancellationRequested) {
|
|
39825
|
-
return false;
|
|
39826
|
-
}
|
|
39827
|
-
this.#cancellationRequested = true;
|
|
39828
|
-
return true;
|
|
39829
|
-
};
|
|
39830
|
-
get signal() {
|
|
39831
|
-
return this.#controller.signal;
|
|
39832
|
-
}
|
|
39833
|
-
get completion() {
|
|
39834
|
-
return this.#finished.promise;
|
|
39835
|
-
}
|
|
39836
|
-
};
|
|
39837
|
-
var ActiveTurnReconciliationError = class extends Error {
|
|
39838
|
-
code = "active_turn_reconciliation_failed";
|
|
39839
|
-
diagnosticDetails;
|
|
39840
|
-
relayErrorCode;
|
|
39841
|
-
terminal;
|
|
39842
|
-
constructor(message, options = {}) {
|
|
39843
|
-
super(message, options);
|
|
39844
|
-
this.name = "ActiveTurnReconciliationError";
|
|
39845
|
-
this.relayErrorCode = options.relayErrorCode ?? null;
|
|
39846
|
-
this.terminal = options.terminal ?? false;
|
|
39847
|
-
this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
|
|
39848
|
-
}
|
|
39849
|
-
};
|
|
39850
|
-
var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
|
|
39851
|
-
async function relayErrorCode(response) {
|
|
39852
|
-
try {
|
|
39853
|
-
const body = JSON.parse(await response.text());
|
|
39854
|
-
if (typeof body !== "object" || body === null) {
|
|
39855
|
-
return null;
|
|
39856
|
-
}
|
|
39857
|
-
const error62 = Reflect.get(body, "error");
|
|
39858
|
-
if (typeof error62 !== "object" || error62 === null) {
|
|
39859
|
-
return null;
|
|
39860
|
-
}
|
|
39861
|
-
const code = Reflect.get(error62, "code");
|
|
39862
|
-
return typeof code === "string" && code.length > 0 ? code : null;
|
|
39863
|
-
} catch {
|
|
39864
|
-
return null;
|
|
39865
|
-
}
|
|
39866
|
-
}
|
|
39867
|
-
function activeTurnReconciliationEndpoint(config2, turn) {
|
|
39868
|
-
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
39869
|
-
let channelPath = "";
|
|
39870
|
-
if (endpoint.pathname.endsWith("/daemon")) {
|
|
39871
|
-
channelPath = endpoint.pathname.slice(0, -"/daemon".length);
|
|
39872
|
-
} else {
|
|
39873
|
-
const runtimePath = "/v1/runtimes/connect";
|
|
39874
|
-
if (!endpoint.pathname.endsWith(runtimePath)) {
|
|
39875
|
-
throw new ActiveTurnReconciliationError("The Relay URL is invalid");
|
|
39876
|
-
}
|
|
39877
|
-
channelPath = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}`;
|
|
39878
|
-
}
|
|
39879
|
-
endpoint.pathname = `${channelPath}/sessions/${encodeURIComponent(turn.command.sessionId)}/attempts/${encodeURIComponent(turn.attemptId)}/reconciliation`;
|
|
39880
|
-
return endpoint;
|
|
39881
|
-
}
|
|
39882
|
-
async function reconcileActiveTurn(config2, turn, signal) {
|
|
39883
|
-
signal.throwIfAborted();
|
|
39884
|
-
const timeoutSignal = AbortSignal.timeout(ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS);
|
|
39885
|
-
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
39886
|
-
let response;
|
|
39887
|
-
try {
|
|
39888
|
-
response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
|
|
39889
|
-
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
39890
|
-
dispatcher: environmentProxyDispatcher,
|
|
39891
|
-
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
39892
|
-
method: "POST",
|
|
39893
|
-
signal: requestSignal
|
|
39894
|
-
});
|
|
39895
|
-
} catch (error62) {
|
|
39896
|
-
if (signal.aborted) {
|
|
39897
|
-
signal.throwIfAborted();
|
|
39898
|
-
}
|
|
39899
|
-
throw new ActiveTurnReconciliationError(
|
|
39900
|
-
timeoutSignal.aborted ? "The active Agent turn reconciliation timed out" : "The active Agent turn could not be reconciled",
|
|
39901
|
-
{ cause: error62 }
|
|
39902
|
-
);
|
|
39903
|
-
}
|
|
39904
|
-
if (!response.ok) {
|
|
39905
|
-
const errorCode = await relayErrorCode(response);
|
|
39906
|
-
const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
|
|
39907
|
-
throw new ActiveTurnReconciliationError(
|
|
39908
|
-
terminal ? `The Relay reported that the active Agent turn can no longer be reconciled (${errorCode})` : `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`,
|
|
39909
|
-
{ relayErrorCode: errorCode, terminal }
|
|
39910
|
-
);
|
|
39911
|
-
}
|
|
39912
|
-
await response.body?.cancel();
|
|
39913
|
-
}
|
|
39914
|
-
async function reconcileActiveTurns(config2, turns, signal) {
|
|
39915
|
-
await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
|
|
39916
|
-
}
|
|
39917
39915
|
function closeRelaySocket(socket, code, reason) {
|
|
39918
39916
|
try {
|
|
39919
39917
|
socket.close(code, reason);
|
|
@@ -40281,14 +40279,14 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40281
40279
|
};
|
|
40282
40280
|
const connectionLiveness = new RelayConnectionLiveness(timer, {
|
|
40283
40281
|
send: (message) => {
|
|
40284
|
-
if (socket.readyState !==
|
|
40282
|
+
if (socket.readyState !== WebSocket5.OPEN) {
|
|
40285
40283
|
return false;
|
|
40286
40284
|
}
|
|
40287
40285
|
try {
|
|
40288
40286
|
send(socket, message);
|
|
40289
40287
|
return true;
|
|
40290
40288
|
} catch (error62) {
|
|
40291
|
-
if (socket.readyState !==
|
|
40289
|
+
if (socket.readyState !== WebSocket5.OPEN) {
|
|
40292
40290
|
return false;
|
|
40293
40291
|
}
|
|
40294
40292
|
throw error62;
|
|
@@ -40414,7 +40412,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40414
40412
|
(request) => request.agentId === command2.agentId && !request.controller.signal.aborted
|
|
40415
40413
|
);
|
|
40416
40414
|
if (agentSettingsDiscoveries.has(command2.requestId) || existing !== void 0) {
|
|
40417
|
-
if (socket.readyState ===
|
|
40415
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40418
40416
|
send(socket, {
|
|
40419
40417
|
code: "agent_settings_discovery_busy",
|
|
40420
40418
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -40425,7 +40423,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40425
40423
|
return;
|
|
40426
40424
|
}
|
|
40427
40425
|
if (agentSettingsDiscoveries.size >= 4) {
|
|
40428
|
-
if (socket.readyState ===
|
|
40426
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40429
40427
|
send(socket, {
|
|
40430
40428
|
code: "agent_settings_discovery_busy",
|
|
40431
40429
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -40483,7 +40481,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40483
40481
|
event: "agent_settings_discovered",
|
|
40484
40482
|
sessionId: `agent-settings:${command2.agentId}`
|
|
40485
40483
|
});
|
|
40486
|
-
if (socket.readyState ===
|
|
40484
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40487
40485
|
send(socket, result.event);
|
|
40488
40486
|
}
|
|
40489
40487
|
} catch (error62) {
|
|
@@ -40511,7 +40509,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40511
40509
|
`
|
|
40512
40510
|
);
|
|
40513
40511
|
}
|
|
40514
|
-
if (socket.readyState ===
|
|
40512
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40515
40513
|
send(socket, {
|
|
40516
40514
|
code: operationErrorCode(failure2),
|
|
40517
40515
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -40534,7 +40532,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40534
40532
|
if (kind === AGENT_CATALOG_REFRESH_KIND) {
|
|
40535
40533
|
const command2 = message;
|
|
40536
40534
|
if (agentCatalogRefreshes.has(command2.requestId) || agentCatalogRefreshes.size > 0) {
|
|
40537
|
-
if (socket.readyState ===
|
|
40535
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40538
40536
|
send(socket, {
|
|
40539
40537
|
code: "agent_catalog_refresh_busy",
|
|
40540
40538
|
kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
|
|
@@ -40564,7 +40562,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40564
40562
|
event: "agent_catalog_refreshed",
|
|
40565
40563
|
sessionId: "agent-catalog"
|
|
40566
40564
|
});
|
|
40567
|
-
if (socket.readyState ===
|
|
40565
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40568
40566
|
send(socket, {
|
|
40569
40567
|
kind: AGENT_CATALOG_REFRESHED_KIND,
|
|
40570
40568
|
requestId: command2.requestId
|
|
@@ -40588,7 +40586,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40588
40586
|
{ code: operationErrorCode(failure2) },
|
|
40589
40587
|
failure2
|
|
40590
40588
|
);
|
|
40591
|
-
if (socket.readyState ===
|
|
40589
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40592
40590
|
send(socket, {
|
|
40593
40591
|
code: operationErrorCode(failure2),
|
|
40594
40592
|
kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
|
|
@@ -40657,7 +40655,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40657
40655
|
}
|
|
40658
40656
|
operationSignal.throwIfAborted();
|
|
40659
40657
|
const result = await nativeSessions.execute(command2, operationSignal);
|
|
40660
|
-
if (socket.readyState ===
|
|
40658
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40661
40659
|
send(socket, result);
|
|
40662
40660
|
}
|
|
40663
40661
|
} catch (error62) {
|
|
@@ -40748,7 +40746,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40748
40746
|
}
|
|
40749
40747
|
operationSignal.throwIfAborted();
|
|
40750
40748
|
const result = await nativeSessions.executeTurnFork(command2, operationSignal);
|
|
40751
|
-
if (socket.readyState ===
|
|
40749
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
40752
40750
|
send(socket, result);
|
|
40753
40751
|
}
|
|
40754
40752
|
} catch (error62) {
|
|
@@ -40802,7 +40800,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40802
40800
|
(message2) => send(socket, message2),
|
|
40803
40801
|
connectionController.signal
|
|
40804
40802
|
).catch((error62) => {
|
|
40805
|
-
if (socket.readyState !==
|
|
40803
|
+
if (socket.readyState !== WebSocket5.OPEN || connectionController.signal.aborted) {
|
|
40806
40804
|
return;
|
|
40807
40805
|
}
|
|
40808
40806
|
send(socket, {
|