@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/index.js
CHANGED
|
@@ -22456,7 +22456,7 @@ var nativeSessionPageSchema = external_exports.object({
|
|
|
22456
22456
|
|
|
22457
22457
|
// src/native-sessions/chat-agent.ts
|
|
22458
22458
|
function supportsNativeChat(agentId) {
|
|
22459
|
-
return agentId === "codex" || agentId === "claude" || agentId === "opencode";
|
|
22459
|
+
return agentId === "codex" || agentId === "claude" || agentId === "opencode" || agentId === "pi";
|
|
22460
22460
|
}
|
|
22461
22461
|
function isNativeChatSessionId(agentId, sessionId) {
|
|
22462
22462
|
if (!nativeSessionIdSchema.safeParse(sessionId).success) {
|
|
@@ -22465,7 +22465,7 @@ function isNativeChatSessionId(agentId, sessionId) {
|
|
|
22465
22465
|
if (agentId === "opencode") {
|
|
22466
22466
|
return /^ses_[a-zA-Z0-9]+$/.test(sessionId);
|
|
22467
22467
|
}
|
|
22468
|
-
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);
|
|
22468
|
+
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);
|
|
22469
22469
|
}
|
|
22470
22470
|
|
|
22471
22471
|
// src/acp/acp-error.ts
|
|
@@ -31532,7 +31532,7 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
|
31532
31532
|
// src/run-daemon.ts
|
|
31533
31533
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
31534
31534
|
import { styleText } from "node:util";
|
|
31535
|
-
import {
|
|
31535
|
+
import { WebSocket as WebSocket5 } from "undici";
|
|
31536
31536
|
|
|
31537
31537
|
// src/agent-catalog/discover-agent-settings.ts
|
|
31538
31538
|
import { createHash as createHash3 } from "node:crypto";
|
|
@@ -32861,6 +32861,9 @@ var DaemonDiagnosticLog = class {
|
|
|
32861
32861
|
};
|
|
32862
32862
|
};
|
|
32863
32863
|
|
|
32864
|
+
// src/daemon-observers.ts
|
|
32865
|
+
import { WebSocket as WebSocket2 } from "undici";
|
|
32866
|
+
|
|
32864
32867
|
// src/daemon-session-commands.ts
|
|
32865
32868
|
import { basename as basename6 } from "node:path";
|
|
32866
32869
|
import { WebSocket } from "undici";
|
|
@@ -34058,6 +34061,253 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
34058
34061
|
}
|
|
34059
34062
|
}
|
|
34060
34063
|
|
|
34064
|
+
// src/daemon-observers.ts
|
|
34065
|
+
var DaemonAcpObserver = class {
|
|
34066
|
+
#record;
|
|
34067
|
+
constructor(record2) {
|
|
34068
|
+
this.#record = record2;
|
|
34069
|
+
}
|
|
34070
|
+
onCommands = (event) => {
|
|
34071
|
+
this.#record(event.sessionId, event);
|
|
34072
|
+
return Promise.resolve();
|
|
34073
|
+
};
|
|
34074
|
+
onConfig = (event) => {
|
|
34075
|
+
this.#record(event.sessionId, event);
|
|
34076
|
+
return Promise.resolve();
|
|
34077
|
+
};
|
|
34078
|
+
onContent = (event) => {
|
|
34079
|
+
this.#record(event.sessionId, event);
|
|
34080
|
+
return Promise.resolve();
|
|
34081
|
+
};
|
|
34082
|
+
onElicitation = (event) => {
|
|
34083
|
+
this.#record(event.sessionId, event);
|
|
34084
|
+
return Promise.resolve();
|
|
34085
|
+
};
|
|
34086
|
+
onElicitationResolved = (event) => {
|
|
34087
|
+
this.#record(event.sessionId, event);
|
|
34088
|
+
return Promise.resolve();
|
|
34089
|
+
};
|
|
34090
|
+
onInfo = (event) => {
|
|
34091
|
+
this.#record(event.sessionId, event);
|
|
34092
|
+
return Promise.resolve();
|
|
34093
|
+
};
|
|
34094
|
+
onPermission = (event) => {
|
|
34095
|
+
this.#record(event.sessionId, event);
|
|
34096
|
+
return Promise.resolve();
|
|
34097
|
+
};
|
|
34098
|
+
onPermissionResolved = (event) => {
|
|
34099
|
+
this.#record(event.sessionId, event);
|
|
34100
|
+
return Promise.resolve();
|
|
34101
|
+
};
|
|
34102
|
+
onUsage = (event) => {
|
|
34103
|
+
this.#record(event.sessionId, event);
|
|
34104
|
+
return Promise.resolve();
|
|
34105
|
+
};
|
|
34106
|
+
};
|
|
34107
|
+
var AuditInstallationEvents = class {
|
|
34108
|
+
#audit;
|
|
34109
|
+
constructor(audit) {
|
|
34110
|
+
this.#audit = audit;
|
|
34111
|
+
}
|
|
34112
|
+
record = (event, requestId, agentId, details = {}) => {
|
|
34113
|
+
this.#audit.record({
|
|
34114
|
+
commandId: requestId,
|
|
34115
|
+
details,
|
|
34116
|
+
event,
|
|
34117
|
+
sessionId: `agent-installation:${agentId}`
|
|
34118
|
+
});
|
|
34119
|
+
};
|
|
34120
|
+
};
|
|
34121
|
+
var DaemonInstallationObserver = class {
|
|
34122
|
+
#started = /* @__PURE__ */ new Set();
|
|
34123
|
+
#socket = null;
|
|
34124
|
+
connect = (socket) => {
|
|
34125
|
+
this.#socket = socket;
|
|
34126
|
+
};
|
|
34127
|
+
disconnect = (socket) => {
|
|
34128
|
+
if (this.#socket === socket) {
|
|
34129
|
+
this.#socket = null;
|
|
34130
|
+
}
|
|
34131
|
+
};
|
|
34132
|
+
#send = (socket, message) => {
|
|
34133
|
+
try {
|
|
34134
|
+
send(socket, message);
|
|
34135
|
+
} catch {
|
|
34136
|
+
if (this.#socket === socket) {
|
|
34137
|
+
this.#socket = null;
|
|
34138
|
+
}
|
|
34139
|
+
}
|
|
34140
|
+
};
|
|
34141
|
+
onState = (state) => {
|
|
34142
|
+
const socket = this.#socket;
|
|
34143
|
+
if (socket === null || socket.readyState !== WebSocket2.OPEN) {
|
|
34144
|
+
return Promise.resolve();
|
|
34145
|
+
}
|
|
34146
|
+
if (state instanceof RequestedInstallation) {
|
|
34147
|
+
return Promise.resolve();
|
|
34148
|
+
}
|
|
34149
|
+
if (state instanceof RunningInstallation) {
|
|
34150
|
+
if (!this.#started.has(state.requestId)) {
|
|
34151
|
+
this.#started.add(state.requestId);
|
|
34152
|
+
this.#send(socket, {
|
|
34153
|
+
agentId: state.agentId,
|
|
34154
|
+
kind: AGENT_INSTALL_STARTED_KIND,
|
|
34155
|
+
requestId: state.requestId
|
|
34156
|
+
});
|
|
34157
|
+
}
|
|
34158
|
+
this.#send(socket, {
|
|
34159
|
+
agentId: state.agentId,
|
|
34160
|
+
kind: AGENT_INSTALL_PROGRESS_KIND,
|
|
34161
|
+
requestId: state.requestId,
|
|
34162
|
+
stage: state.stage
|
|
34163
|
+
});
|
|
34164
|
+
return Promise.resolve();
|
|
34165
|
+
}
|
|
34166
|
+
if (state instanceof SucceededInstallation) {
|
|
34167
|
+
this.#send(socket, {
|
|
34168
|
+
agentId: state.agentId,
|
|
34169
|
+
authenticationMayBeRequired: state.authenticationMayBeRequired,
|
|
34170
|
+
kind: AGENT_INSTALL_COMPLETED_KIND,
|
|
34171
|
+
requestId: state.requestId
|
|
34172
|
+
});
|
|
34173
|
+
return Promise.resolve();
|
|
34174
|
+
}
|
|
34175
|
+
if (state instanceof FailedInstallation) {
|
|
34176
|
+
this.#send(socket, {
|
|
34177
|
+
agentId: state.agentId,
|
|
34178
|
+
code: state.code,
|
|
34179
|
+
kind: AGENT_INSTALL_FAILED_KIND,
|
|
34180
|
+
message: state.message,
|
|
34181
|
+
requestId: state.requestId
|
|
34182
|
+
});
|
|
34183
|
+
return Promise.resolve();
|
|
34184
|
+
}
|
|
34185
|
+
if (state instanceof CancelledInstallation) {
|
|
34186
|
+
this.#send(socket, {
|
|
34187
|
+
agentId: state.agentId,
|
|
34188
|
+
kind: AGENT_INSTALL_CANCELLED_KIND,
|
|
34189
|
+
requestId: state.requestId
|
|
34190
|
+
});
|
|
34191
|
+
return Promise.resolve();
|
|
34192
|
+
}
|
|
34193
|
+
throw new Error("Unsupported Agent integration installation state");
|
|
34194
|
+
};
|
|
34195
|
+
};
|
|
34196
|
+
|
|
34197
|
+
// src/daemon-turn-reconciliation.ts
|
|
34198
|
+
import { fetch as fetch5 } from "undici";
|
|
34199
|
+
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
34200
|
+
var ActiveDaemonTurn = class {
|
|
34201
|
+
attemptId;
|
|
34202
|
+
command;
|
|
34203
|
+
#controller;
|
|
34204
|
+
#finished = Promise.withResolvers();
|
|
34205
|
+
#cancellationRequested = false;
|
|
34206
|
+
constructor(command, attemptId) {
|
|
34207
|
+
this.attemptId = attemptId;
|
|
34208
|
+
this.command = command;
|
|
34209
|
+
this.#controller = new AbortController();
|
|
34210
|
+
}
|
|
34211
|
+
abortDaemon = () => {
|
|
34212
|
+
this.#controller.abort();
|
|
34213
|
+
};
|
|
34214
|
+
finish = () => this.#finished.resolve();
|
|
34215
|
+
matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
|
|
34216
|
+
requestCancellation = () => {
|
|
34217
|
+
if (this.#cancellationRequested) {
|
|
34218
|
+
return false;
|
|
34219
|
+
}
|
|
34220
|
+
this.#cancellationRequested = true;
|
|
34221
|
+
return true;
|
|
34222
|
+
};
|
|
34223
|
+
get signal() {
|
|
34224
|
+
return this.#controller.signal;
|
|
34225
|
+
}
|
|
34226
|
+
get completion() {
|
|
34227
|
+
return this.#finished.promise;
|
|
34228
|
+
}
|
|
34229
|
+
};
|
|
34230
|
+
var ActiveTurnReconciliationError = class extends Error {
|
|
34231
|
+
code = "active_turn_reconciliation_failed";
|
|
34232
|
+
diagnosticDetails;
|
|
34233
|
+
relayErrorCode;
|
|
34234
|
+
terminal;
|
|
34235
|
+
constructor(message, options = {}) {
|
|
34236
|
+
super(message, options);
|
|
34237
|
+
this.name = "ActiveTurnReconciliationError";
|
|
34238
|
+
this.relayErrorCode = options.relayErrorCode ?? null;
|
|
34239
|
+
this.terminal = options.terminal ?? false;
|
|
34240
|
+
this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
|
|
34241
|
+
}
|
|
34242
|
+
};
|
|
34243
|
+
var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
|
|
34244
|
+
async function relayErrorCode(response) {
|
|
34245
|
+
try {
|
|
34246
|
+
const body = JSON.parse(await response.text());
|
|
34247
|
+
if (typeof body !== "object" || body === null) {
|
|
34248
|
+
return null;
|
|
34249
|
+
}
|
|
34250
|
+
const error62 = Reflect.get(body, "error");
|
|
34251
|
+
if (typeof error62 !== "object" || error62 === null) {
|
|
34252
|
+
return null;
|
|
34253
|
+
}
|
|
34254
|
+
const code = Reflect.get(error62, "code");
|
|
34255
|
+
return typeof code === "string" && code.length > 0 ? code : null;
|
|
34256
|
+
} catch {
|
|
34257
|
+
return null;
|
|
34258
|
+
}
|
|
34259
|
+
}
|
|
34260
|
+
function activeTurnReconciliationEndpoint(config2, turn) {
|
|
34261
|
+
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
34262
|
+
let channelPath = "";
|
|
34263
|
+
if (endpoint.pathname.endsWith("/daemon")) {
|
|
34264
|
+
channelPath = endpoint.pathname.slice(0, -"/daemon".length);
|
|
34265
|
+
} else {
|
|
34266
|
+
const runtimePath = "/v1/runtimes/connect";
|
|
34267
|
+
if (!endpoint.pathname.endsWith(runtimePath)) {
|
|
34268
|
+
throw new ActiveTurnReconciliationError("The Relay URL is invalid");
|
|
34269
|
+
}
|
|
34270
|
+
channelPath = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}`;
|
|
34271
|
+
}
|
|
34272
|
+
endpoint.pathname = `${channelPath}/sessions/${encodeURIComponent(turn.command.sessionId)}/attempts/${encodeURIComponent(turn.attemptId)}/reconciliation`;
|
|
34273
|
+
return endpoint;
|
|
34274
|
+
}
|
|
34275
|
+
async function reconcileActiveTurn(config2, turn, signal) {
|
|
34276
|
+
signal.throwIfAborted();
|
|
34277
|
+
const timeoutSignal = AbortSignal.timeout(ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS);
|
|
34278
|
+
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
34279
|
+
let response;
|
|
34280
|
+
try {
|
|
34281
|
+
response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
|
|
34282
|
+
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
34283
|
+
dispatcher: environmentProxyDispatcher,
|
|
34284
|
+
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
34285
|
+
method: "POST",
|
|
34286
|
+
signal: requestSignal
|
|
34287
|
+
});
|
|
34288
|
+
} catch (error62) {
|
|
34289
|
+
if (signal.aborted) {
|
|
34290
|
+
signal.throwIfAborted();
|
|
34291
|
+
}
|
|
34292
|
+
throw new ActiveTurnReconciliationError(
|
|
34293
|
+
timeoutSignal.aborted ? "The active Agent turn reconciliation timed out" : "The active Agent turn could not be reconciled",
|
|
34294
|
+
{ cause: error62 }
|
|
34295
|
+
);
|
|
34296
|
+
}
|
|
34297
|
+
if (!response.ok) {
|
|
34298
|
+
const errorCode = await relayErrorCode(response);
|
|
34299
|
+
const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
|
|
34300
|
+
throw new ActiveTurnReconciliationError(
|
|
34301
|
+
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()}`,
|
|
34302
|
+
{ relayErrorCode: errorCode, terminal }
|
|
34303
|
+
);
|
|
34304
|
+
}
|
|
34305
|
+
await response.body?.cancel();
|
|
34306
|
+
}
|
|
34307
|
+
async function reconcileActiveTurns(config2, turns, signal) {
|
|
34308
|
+
await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
|
|
34309
|
+
}
|
|
34310
|
+
|
|
34061
34311
|
// src/native-sessions/codex-history.ts
|
|
34062
34312
|
import { spawn as spawn5 } from "node:child_process";
|
|
34063
34313
|
var responseSchema = external_exports.union([
|
|
@@ -34520,8 +34770,8 @@ async function readAcpHistory(sessions, directories, bindingId, options, nativeS
|
|
|
34520
34770
|
throw new AcpExecutionError("The native Session was not found.", {}, "native_session_not_found");
|
|
34521
34771
|
}
|
|
34522
34772
|
|
|
34523
|
-
// src/native-sessions/
|
|
34524
|
-
var
|
|
34773
|
+
// src/native-sessions/acp-adapter.ts
|
|
34774
|
+
var acpSessionAdapter = {
|
|
34525
34775
|
linkedHistory: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
34526
34776
|
history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
34527
34777
|
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
@@ -34549,13 +34799,6 @@ var codexSessionAdapter = {
|
|
|
34549
34799
|
preview: async (context) => await verifiedHistory(context, false)
|
|
34550
34800
|
};
|
|
34551
34801
|
|
|
34552
|
-
// src/native-sessions/opencode-adapter.ts
|
|
34553
|
-
var openCodeSessionAdapter = {
|
|
34554
|
-
linkedHistory: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
34555
|
-
history: async ({ sessions, directories, bindingId, options, nativeSessionId }) => await readAcpHistory(sessions, directories, bindingId, options, nativeSessionId),
|
|
34556
|
-
preview: async ({ sessions, options, nativeSessionId }) => await sessions.previewNativeSession(options, nativeSessionId)
|
|
34557
|
-
};
|
|
34558
|
-
|
|
34559
34802
|
// src/native-sessions/agent-adapter.ts
|
|
34560
34803
|
var genericSessionAdapter = {
|
|
34561
34804
|
linkedHistory: async () => {
|
|
@@ -34570,11 +34813,8 @@ function nativeSessionAdapter(agentId) {
|
|
|
34570
34813
|
if (agentId === "codex") {
|
|
34571
34814
|
return codexSessionAdapter;
|
|
34572
34815
|
}
|
|
34573
|
-
if (agentId === "claude") {
|
|
34574
|
-
return
|
|
34575
|
-
}
|
|
34576
|
-
if (agentId === "opencode") {
|
|
34577
|
-
return openCodeSessionAdapter;
|
|
34816
|
+
if (agentId === "claude" || agentId === "opencode" || agentId === "pi") {
|
|
34817
|
+
return acpSessionAdapter;
|
|
34578
34818
|
}
|
|
34579
34819
|
return genericSessionAdapter;
|
|
34580
34820
|
}
|
|
@@ -35060,7 +35300,7 @@ var NativeSessionService = class {
|
|
|
35060
35300
|
};
|
|
35061
35301
|
|
|
35062
35302
|
// src/relay-connection/connect.ts
|
|
35063
|
-
import { WebSocket as
|
|
35303
|
+
import { WebSocket as WebSocket3 } from "undici";
|
|
35064
35304
|
var CONNECTION_TIMEOUT_MILLISECONDS = 6e4;
|
|
35065
35305
|
var RelayConnectionError = class extends Error {
|
|
35066
35306
|
code;
|
|
@@ -35078,7 +35318,7 @@ function connectRelay(url2, signal) {
|
|
|
35078
35318
|
const endpoint = new URL(url2);
|
|
35079
35319
|
const headers = runtimeAuthorization(endpoint);
|
|
35080
35320
|
endpoint.searchParams.delete("token");
|
|
35081
|
-
const socket = new
|
|
35321
|
+
const socket = new WebSocket3(endpoint, {
|
|
35082
35322
|
dispatcher: environmentProxyDispatcher,
|
|
35083
35323
|
headers
|
|
35084
35324
|
});
|
|
@@ -35442,10 +35682,10 @@ var RelayConnectionLiveness = class {
|
|
|
35442
35682
|
import { createHash as createHash5 } from "node:crypto";
|
|
35443
35683
|
import { DatabaseSync } from "node:sqlite";
|
|
35444
35684
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
35445
|
-
criticalEventBytes:
|
|
35446
|
-
runtimeDeliveryBytes:
|
|
35685
|
+
criticalEventBytes: 40 * 1024 * 1024,
|
|
35686
|
+
runtimeDeliveryBytes: 32 * 1024 * 1024,
|
|
35447
35687
|
runtimeDeliveryCount: 64,
|
|
35448
|
-
standardEventBytes:
|
|
35688
|
+
standardEventBytes: 32 * 1024 * 1024
|
|
35449
35689
|
};
|
|
35450
35690
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
35451
35691
|
var SessionEventOutboxCapacityError = class extends Error {
|
|
@@ -35967,7 +36207,7 @@ function isDaemonExecutionState(value) {
|
|
|
35967
36207
|
}
|
|
35968
36208
|
|
|
35969
36209
|
// src/relay-connection/session-event-publisher.ts
|
|
35970
|
-
import { WebSocket as
|
|
36210
|
+
import { WebSocket as WebSocket4 } from "undici";
|
|
35971
36211
|
var DaemonSessionEventConnectionState = class {
|
|
35972
36212
|
};
|
|
35973
36213
|
var DisconnectedDaemonSessionEventState = class extends DaemonSessionEventConnectionState {
|
|
@@ -35984,7 +36224,7 @@ var ConnectedDaemonSessionEventState = class extends DaemonSessionEventConnectio
|
|
|
35984
36224
|
disconnect = (socket) => socket === this.#socket ? new DisconnectedDaemonSessionEventState() : this;
|
|
35985
36225
|
matches = (socket) => socket === this.#socket;
|
|
35986
36226
|
send = (message) => {
|
|
35987
|
-
if (this.#socket.readyState !==
|
|
36227
|
+
if (this.#socket.readyState !== WebSocket4.OPEN) {
|
|
35988
36228
|
return false;
|
|
35989
36229
|
}
|
|
35990
36230
|
try {
|
|
@@ -36211,249 +36451,7 @@ var systemDaemonTimer = new SystemDaemonTimer();
|
|
|
36211
36451
|
|
|
36212
36452
|
// src/run-daemon.ts
|
|
36213
36453
|
var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
36214
|
-
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
36215
36454
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
36216
|
-
var DaemonAcpObserver = class {
|
|
36217
|
-
#record;
|
|
36218
|
-
constructor(record2) {
|
|
36219
|
-
this.#record = record2;
|
|
36220
|
-
}
|
|
36221
|
-
onCommands = (event) => {
|
|
36222
|
-
this.#record(event.sessionId, event);
|
|
36223
|
-
return Promise.resolve();
|
|
36224
|
-
};
|
|
36225
|
-
onConfig = (event) => {
|
|
36226
|
-
this.#record(event.sessionId, event);
|
|
36227
|
-
return Promise.resolve();
|
|
36228
|
-
};
|
|
36229
|
-
onContent = (event) => {
|
|
36230
|
-
this.#record(event.sessionId, event);
|
|
36231
|
-
return Promise.resolve();
|
|
36232
|
-
};
|
|
36233
|
-
onElicitation = (event) => {
|
|
36234
|
-
this.#record(event.sessionId, event);
|
|
36235
|
-
return Promise.resolve();
|
|
36236
|
-
};
|
|
36237
|
-
onElicitationResolved = (event) => {
|
|
36238
|
-
this.#record(event.sessionId, event);
|
|
36239
|
-
return Promise.resolve();
|
|
36240
|
-
};
|
|
36241
|
-
onInfo = (event) => {
|
|
36242
|
-
this.#record(event.sessionId, event);
|
|
36243
|
-
return Promise.resolve();
|
|
36244
|
-
};
|
|
36245
|
-
onPermission = (event) => {
|
|
36246
|
-
this.#record(event.sessionId, event);
|
|
36247
|
-
return Promise.resolve();
|
|
36248
|
-
};
|
|
36249
|
-
onPermissionResolved = (event) => {
|
|
36250
|
-
this.#record(event.sessionId, event);
|
|
36251
|
-
return Promise.resolve();
|
|
36252
|
-
};
|
|
36253
|
-
onUsage = (event) => {
|
|
36254
|
-
this.#record(event.sessionId, event);
|
|
36255
|
-
return Promise.resolve();
|
|
36256
|
-
};
|
|
36257
|
-
};
|
|
36258
|
-
var AuditInstallationEvents = class {
|
|
36259
|
-
#audit;
|
|
36260
|
-
constructor(audit) {
|
|
36261
|
-
this.#audit = audit;
|
|
36262
|
-
}
|
|
36263
|
-
record = (event, requestId, agentId, details = {}) => {
|
|
36264
|
-
this.#audit.record({
|
|
36265
|
-
commandId: requestId,
|
|
36266
|
-
details,
|
|
36267
|
-
event,
|
|
36268
|
-
sessionId: `agent-installation:${agentId}`
|
|
36269
|
-
});
|
|
36270
|
-
};
|
|
36271
|
-
};
|
|
36272
|
-
var DaemonInstallationObserver = class {
|
|
36273
|
-
#started = /* @__PURE__ */ new Set();
|
|
36274
|
-
#socket = null;
|
|
36275
|
-
connect = (socket) => {
|
|
36276
|
-
this.#socket = socket;
|
|
36277
|
-
};
|
|
36278
|
-
disconnect = (socket) => {
|
|
36279
|
-
if (this.#socket === socket) {
|
|
36280
|
-
this.#socket = null;
|
|
36281
|
-
}
|
|
36282
|
-
};
|
|
36283
|
-
#send = (socket, message) => {
|
|
36284
|
-
try {
|
|
36285
|
-
send(socket, message);
|
|
36286
|
-
} catch {
|
|
36287
|
-
if (this.#socket === socket) {
|
|
36288
|
-
this.#socket = null;
|
|
36289
|
-
}
|
|
36290
|
-
}
|
|
36291
|
-
};
|
|
36292
|
-
onState = (state) => {
|
|
36293
|
-
const socket = this.#socket;
|
|
36294
|
-
if (socket === null || socket.readyState !== WebSocket4.OPEN) {
|
|
36295
|
-
return Promise.resolve();
|
|
36296
|
-
}
|
|
36297
|
-
if (state instanceof RequestedInstallation) {
|
|
36298
|
-
return Promise.resolve();
|
|
36299
|
-
}
|
|
36300
|
-
if (state instanceof RunningInstallation) {
|
|
36301
|
-
if (!this.#started.has(state.requestId)) {
|
|
36302
|
-
this.#started.add(state.requestId);
|
|
36303
|
-
this.#send(socket, {
|
|
36304
|
-
agentId: state.agentId,
|
|
36305
|
-
kind: AGENT_INSTALL_STARTED_KIND,
|
|
36306
|
-
requestId: state.requestId
|
|
36307
|
-
});
|
|
36308
|
-
}
|
|
36309
|
-
this.#send(socket, {
|
|
36310
|
-
agentId: state.agentId,
|
|
36311
|
-
kind: AGENT_INSTALL_PROGRESS_KIND,
|
|
36312
|
-
requestId: state.requestId,
|
|
36313
|
-
stage: state.stage
|
|
36314
|
-
});
|
|
36315
|
-
return Promise.resolve();
|
|
36316
|
-
}
|
|
36317
|
-
if (state instanceof SucceededInstallation) {
|
|
36318
|
-
this.#send(socket, {
|
|
36319
|
-
agentId: state.agentId,
|
|
36320
|
-
authenticationMayBeRequired: state.authenticationMayBeRequired,
|
|
36321
|
-
kind: AGENT_INSTALL_COMPLETED_KIND,
|
|
36322
|
-
requestId: state.requestId
|
|
36323
|
-
});
|
|
36324
|
-
return Promise.resolve();
|
|
36325
|
-
}
|
|
36326
|
-
if (state instanceof FailedInstallation) {
|
|
36327
|
-
this.#send(socket, {
|
|
36328
|
-
agentId: state.agentId,
|
|
36329
|
-
code: state.code,
|
|
36330
|
-
kind: AGENT_INSTALL_FAILED_KIND,
|
|
36331
|
-
message: state.message,
|
|
36332
|
-
requestId: state.requestId
|
|
36333
|
-
});
|
|
36334
|
-
return Promise.resolve();
|
|
36335
|
-
}
|
|
36336
|
-
if (state instanceof CancelledInstallation) {
|
|
36337
|
-
this.#send(socket, {
|
|
36338
|
-
agentId: state.agentId,
|
|
36339
|
-
kind: AGENT_INSTALL_CANCELLED_KIND,
|
|
36340
|
-
requestId: state.requestId
|
|
36341
|
-
});
|
|
36342
|
-
return Promise.resolve();
|
|
36343
|
-
}
|
|
36344
|
-
throw new Error("Unsupported Agent integration installation state");
|
|
36345
|
-
};
|
|
36346
|
-
};
|
|
36347
|
-
var ActiveDaemonTurn = class {
|
|
36348
|
-
attemptId;
|
|
36349
|
-
command;
|
|
36350
|
-
#controller;
|
|
36351
|
-
#finished = Promise.withResolvers();
|
|
36352
|
-
#cancellationRequested = false;
|
|
36353
|
-
constructor(command, attemptId) {
|
|
36354
|
-
this.attemptId = attemptId;
|
|
36355
|
-
this.command = command;
|
|
36356
|
-
this.#controller = new AbortController();
|
|
36357
|
-
}
|
|
36358
|
-
abortDaemon = () => {
|
|
36359
|
-
this.#controller.abort();
|
|
36360
|
-
};
|
|
36361
|
-
finish = () => this.#finished.resolve();
|
|
36362
|
-
matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
|
|
36363
|
-
requestCancellation = () => {
|
|
36364
|
-
if (this.#cancellationRequested) {
|
|
36365
|
-
return false;
|
|
36366
|
-
}
|
|
36367
|
-
this.#cancellationRequested = true;
|
|
36368
|
-
return true;
|
|
36369
|
-
};
|
|
36370
|
-
get signal() {
|
|
36371
|
-
return this.#controller.signal;
|
|
36372
|
-
}
|
|
36373
|
-
get completion() {
|
|
36374
|
-
return this.#finished.promise;
|
|
36375
|
-
}
|
|
36376
|
-
};
|
|
36377
|
-
var ActiveTurnReconciliationError = class extends Error {
|
|
36378
|
-
code = "active_turn_reconciliation_failed";
|
|
36379
|
-
diagnosticDetails;
|
|
36380
|
-
relayErrorCode;
|
|
36381
|
-
terminal;
|
|
36382
|
-
constructor(message, options = {}) {
|
|
36383
|
-
super(message, options);
|
|
36384
|
-
this.name = "ActiveTurnReconciliationError";
|
|
36385
|
-
this.relayErrorCode = options.relayErrorCode ?? null;
|
|
36386
|
-
this.terminal = options.terminal ?? false;
|
|
36387
|
-
this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
|
|
36388
|
-
}
|
|
36389
|
-
};
|
|
36390
|
-
var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
|
|
36391
|
-
async function relayErrorCode(response) {
|
|
36392
|
-
try {
|
|
36393
|
-
const body = JSON.parse(await response.text());
|
|
36394
|
-
if (typeof body !== "object" || body === null) {
|
|
36395
|
-
return null;
|
|
36396
|
-
}
|
|
36397
|
-
const error62 = Reflect.get(body, "error");
|
|
36398
|
-
if (typeof error62 !== "object" || error62 === null) {
|
|
36399
|
-
return null;
|
|
36400
|
-
}
|
|
36401
|
-
const code = Reflect.get(error62, "code");
|
|
36402
|
-
return typeof code === "string" && code.length > 0 ? code : null;
|
|
36403
|
-
} catch {
|
|
36404
|
-
return null;
|
|
36405
|
-
}
|
|
36406
|
-
}
|
|
36407
|
-
function activeTurnReconciliationEndpoint(config2, turn) {
|
|
36408
|
-
const endpoint = relayHttpEndpoint(config2.relayUrl);
|
|
36409
|
-
let channelPath = "";
|
|
36410
|
-
if (endpoint.pathname.endsWith("/daemon")) {
|
|
36411
|
-
channelPath = endpoint.pathname.slice(0, -"/daemon".length);
|
|
36412
|
-
} else {
|
|
36413
|
-
const runtimePath = "/v1/runtimes/connect";
|
|
36414
|
-
if (!endpoint.pathname.endsWith(runtimePath)) {
|
|
36415
|
-
throw new ActiveTurnReconciliationError("The Relay URL is invalid");
|
|
36416
|
-
}
|
|
36417
|
-
channelPath = `${endpoint.pathname.slice(0, -runtimePath.length)}/channels/${encodeURIComponent(config2.channelId)}`;
|
|
36418
|
-
}
|
|
36419
|
-
endpoint.pathname = `${channelPath}/sessions/${encodeURIComponent(turn.command.sessionId)}/attempts/${encodeURIComponent(turn.attemptId)}/reconciliation`;
|
|
36420
|
-
return endpoint;
|
|
36421
|
-
}
|
|
36422
|
-
async function reconcileActiveTurn(config2, turn, signal) {
|
|
36423
|
-
signal.throwIfAborted();
|
|
36424
|
-
const timeoutSignal = AbortSignal.timeout(ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS);
|
|
36425
|
-
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
36426
|
-
let response;
|
|
36427
|
-
try {
|
|
36428
|
-
response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
|
|
36429
|
-
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
36430
|
-
dispatcher: environmentProxyDispatcher,
|
|
36431
|
-
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
36432
|
-
method: "POST",
|
|
36433
|
-
signal: requestSignal
|
|
36434
|
-
});
|
|
36435
|
-
} catch (error62) {
|
|
36436
|
-
if (signal.aborted) {
|
|
36437
|
-
signal.throwIfAborted();
|
|
36438
|
-
}
|
|
36439
|
-
throw new ActiveTurnReconciliationError(
|
|
36440
|
-
timeoutSignal.aborted ? "The active Agent turn reconciliation timed out" : "The active Agent turn could not be reconciled",
|
|
36441
|
-
{ cause: error62 }
|
|
36442
|
-
);
|
|
36443
|
-
}
|
|
36444
|
-
if (!response.ok) {
|
|
36445
|
-
const errorCode = await relayErrorCode(response);
|
|
36446
|
-
const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
|
|
36447
|
-
throw new ActiveTurnReconciliationError(
|
|
36448
|
-
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()}`,
|
|
36449
|
-
{ relayErrorCode: errorCode, terminal }
|
|
36450
|
-
);
|
|
36451
|
-
}
|
|
36452
|
-
await response.body?.cancel();
|
|
36453
|
-
}
|
|
36454
|
-
async function reconcileActiveTurns(config2, turns, signal) {
|
|
36455
|
-
await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
|
|
36456
|
-
}
|
|
36457
36455
|
function closeRelaySocket(socket, code, reason) {
|
|
36458
36456
|
try {
|
|
36459
36457
|
socket.close(code, reason);
|
|
@@ -36821,14 +36819,14 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
36821
36819
|
};
|
|
36822
36820
|
const connectionLiveness = new RelayConnectionLiveness(timer, {
|
|
36823
36821
|
send: (message) => {
|
|
36824
|
-
if (socket.readyState !==
|
|
36822
|
+
if (socket.readyState !== WebSocket5.OPEN) {
|
|
36825
36823
|
return false;
|
|
36826
36824
|
}
|
|
36827
36825
|
try {
|
|
36828
36826
|
send(socket, message);
|
|
36829
36827
|
return true;
|
|
36830
36828
|
} catch (error62) {
|
|
36831
|
-
if (socket.readyState !==
|
|
36829
|
+
if (socket.readyState !== WebSocket5.OPEN) {
|
|
36832
36830
|
return false;
|
|
36833
36831
|
}
|
|
36834
36832
|
throw error62;
|
|
@@ -36954,7 +36952,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
36954
36952
|
(request) => request.agentId === command2.agentId && !request.controller.signal.aborted
|
|
36955
36953
|
);
|
|
36956
36954
|
if (agentSettingsDiscoveries.has(command2.requestId) || existing !== void 0) {
|
|
36957
|
-
if (socket.readyState ===
|
|
36955
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
36958
36956
|
send(socket, {
|
|
36959
36957
|
code: "agent_settings_discovery_busy",
|
|
36960
36958
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -36965,7 +36963,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
36965
36963
|
return;
|
|
36966
36964
|
}
|
|
36967
36965
|
if (agentSettingsDiscoveries.size >= 4) {
|
|
36968
|
-
if (socket.readyState ===
|
|
36966
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
36969
36967
|
send(socket, {
|
|
36970
36968
|
code: "agent_settings_discovery_busy",
|
|
36971
36969
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -37023,7 +37021,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37023
37021
|
event: "agent_settings_discovered",
|
|
37024
37022
|
sessionId: `agent-settings:${command2.agentId}`
|
|
37025
37023
|
});
|
|
37026
|
-
if (socket.readyState ===
|
|
37024
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37027
37025
|
send(socket, result.event);
|
|
37028
37026
|
}
|
|
37029
37027
|
} catch (error62) {
|
|
@@ -37051,7 +37049,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37051
37049
|
`
|
|
37052
37050
|
);
|
|
37053
37051
|
}
|
|
37054
|
-
if (socket.readyState ===
|
|
37052
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37055
37053
|
send(socket, {
|
|
37056
37054
|
code: operationErrorCode(failure2),
|
|
37057
37055
|
kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
|
|
@@ -37074,7 +37072,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37074
37072
|
if (kind === AGENT_CATALOG_REFRESH_KIND) {
|
|
37075
37073
|
const command2 = message;
|
|
37076
37074
|
if (agentCatalogRefreshes.has(command2.requestId) || agentCatalogRefreshes.size > 0) {
|
|
37077
|
-
if (socket.readyState ===
|
|
37075
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37078
37076
|
send(socket, {
|
|
37079
37077
|
code: "agent_catalog_refresh_busy",
|
|
37080
37078
|
kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
|
|
@@ -37104,7 +37102,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37104
37102
|
event: "agent_catalog_refreshed",
|
|
37105
37103
|
sessionId: "agent-catalog"
|
|
37106
37104
|
});
|
|
37107
|
-
if (socket.readyState ===
|
|
37105
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37108
37106
|
send(socket, {
|
|
37109
37107
|
kind: AGENT_CATALOG_REFRESHED_KIND,
|
|
37110
37108
|
requestId: command2.requestId
|
|
@@ -37128,7 +37126,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37128
37126
|
{ code: operationErrorCode(failure2) },
|
|
37129
37127
|
failure2
|
|
37130
37128
|
);
|
|
37131
|
-
if (socket.readyState ===
|
|
37129
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37132
37130
|
send(socket, {
|
|
37133
37131
|
code: operationErrorCode(failure2),
|
|
37134
37132
|
kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
|
|
@@ -37197,7 +37195,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37197
37195
|
}
|
|
37198
37196
|
operationSignal.throwIfAborted();
|
|
37199
37197
|
const result = await nativeSessions.execute(command2, operationSignal);
|
|
37200
|
-
if (socket.readyState ===
|
|
37198
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37201
37199
|
send(socket, result);
|
|
37202
37200
|
}
|
|
37203
37201
|
} catch (error62) {
|
|
@@ -37288,7 +37286,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37288
37286
|
}
|
|
37289
37287
|
operationSignal.throwIfAborted();
|
|
37290
37288
|
const result = await nativeSessions.executeTurnFork(command2, operationSignal);
|
|
37291
|
-
if (socket.readyState ===
|
|
37289
|
+
if (socket.readyState === WebSocket5.OPEN) {
|
|
37292
37290
|
send(socket, result);
|
|
37293
37291
|
}
|
|
37294
37292
|
} catch (error62) {
|
|
@@ -37342,7 +37340,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
37342
37340
|
(message2) => send(socket, message2),
|
|
37343
37341
|
connectionController.signal
|
|
37344
37342
|
).catch((error62) => {
|
|
37345
|
-
if (socket.readyState !==
|
|
37343
|
+
if (socket.readyState !== WebSocket5.OPEN || connectionController.signal.aborted) {
|
|
37346
37344
|
return;
|
|
37347
37345
|
}
|
|
37348
37346
|
send(socket, {
|