@moxt-ai/mobius 0.0.53 → 0.0.55
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 +119 -15
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +117 -14
- package/dist/index.js.map +4 -4
- package/dist/relay-connection/coalescing-text-publisher.d.ts +27 -0
- package/dist/relay-connection/coalescing-text-publisher.d.ts.map +1 -0
- package/dist/relay-connection/coalescing-text-publisher.js +58 -0
- package/dist/relay-connection/coalescing-text-publisher.js.map +1 -0
- package/dist/relay-connection/connect.d.ts.map +1 -1
- package/dist/relay-connection/connect.js +5 -0
- package/dist/relay-connection/connect.js.map +1 -1
- package/dist/relay-connection/liveness.d.ts +1 -1
- package/dist/relay-connection/liveness.d.ts.map +1 -1
- package/dist/relay-connection/liveness.js +5 -1
- package/dist/relay-connection/liveness.js.map +1 -1
- package/dist/relay-connection/runtime-revocation.d.ts +12 -0
- package/dist/relay-connection/runtime-revocation.d.ts.map +1 -0
- package/dist/relay-connection/runtime-revocation.js +21 -0
- package/dist/relay-connection/runtime-revocation.js.map +1 -0
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +41 -9
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +118 -14
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { AuditStore } from "./audit/audit-store.ts";
|
|
|
4
4
|
export { LocalAuthorizationError } from "./authorization/local-authorization-error.ts";
|
|
5
5
|
export { ChannelDaemonReconnectTarget, DaemonLocalContext, DaemonReconnectTarget, loadDaemonConfig, OpaqueDaemonReconnectTarget, } from "./config.ts";
|
|
6
6
|
export { type MobiusRuntimePairingOptions, type PairedDaemon, PairingClientError, pairLocalMachine, pairMobiusRuntime, resumeLocalMachine, resumeMobiusRuntime, } from "./pairing/pair-local-machine.ts";
|
|
7
|
+
export { RuntimeRelayRevokedError } from "./relay-connection/runtime-revocation.ts";
|
|
7
8
|
export { runDaemon } from "./run-daemon.ts";
|
|
8
9
|
export { createMobiusRuntimeEngine, loadMobiusRuntimeConnection, MobiusRuntimeConfigurationError, MobiusRuntimeEngine, } from "./runtime.ts";
|
|
9
10
|
export { ImportedLegacyRuntimeConnection, openRuntimeInstallationStore, type RuntimeConnectionInput, RuntimeInstallationStore, RuntimeInstallationStoreError, type RuntimeInstallationStoreOptions, StoredRuntimeConnection, VerifiedRuntimeConnection, } from "./storage/runtime-installation-store.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EACH,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,2BAA2B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,KAAK,2BAA2B,EAChC,KAAK,YAAY,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACH,yBAAyB,EACzB,2BAA2B,EAC3B,+BAA+B,EAC/B,mBAAmB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,+BAA+B,EAC/B,4BAA4B,EAC5B,KAAK,sBAAsB,EAC3B,wBAAwB,EACxB,6BAA6B,EAC7B,KAAK,+BAA+B,EACpC,uBAAuB,EACvB,yBAAyB,GAC5B,MAAM,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EACH,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,2BAA2B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,KAAK,2BAA2B,EAChC,KAAK,YAAY,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACH,yBAAyB,EACzB,2BAA2B,EAC3B,+BAA+B,EAC/B,mBAAmB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,+BAA+B,EAC/B,4BAA4B,EAC5B,KAAK,sBAAsB,EAC3B,wBAAwB,EACxB,6BAA6B,EAC7B,KAAK,+BAA+B,EACpC,uBAAuB,EACvB,yBAAyB,GAC5B,MAAM,yCAAyC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -36369,6 +36369,24 @@ async function resumeLocalMachine(arguments_, signal = new AbortController().sig
|
|
|
36369
36369
|
return await target.resume(installation, signal, process.env);
|
|
36370
36370
|
}
|
|
36371
36371
|
|
|
36372
|
+
// src/relay-connection/runtime-revocation.ts
|
|
36373
|
+
var runtimeRevocationCloseCode = 1008;
|
|
36374
|
+
var runtimeRevocationCloseReason = "Runtime revoked";
|
|
36375
|
+
var RuntimeRelayRevokedError = class extends Error {
|
|
36376
|
+
code = "runtime_relay_revoked";
|
|
36377
|
+
closeCode;
|
|
36378
|
+
closeReason;
|
|
36379
|
+
constructor(closeCode, closeReason, options = {}) {
|
|
36380
|
+
super("The Runtime was revoked by the Relay", options);
|
|
36381
|
+
this.closeCode = closeCode;
|
|
36382
|
+
this.closeReason = closeReason;
|
|
36383
|
+
this.name = "RuntimeRelayRevokedError";
|
|
36384
|
+
}
|
|
36385
|
+
};
|
|
36386
|
+
function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
36387
|
+
return closeCode === runtimeRevocationCloseCode && closeReason === runtimeRevocationCloseReason;
|
|
36388
|
+
}
|
|
36389
|
+
|
|
36372
36390
|
// src/run-daemon.ts
|
|
36373
36391
|
import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
|
|
36374
36392
|
import { basename as basename7 } from "node:path";
|
|
@@ -38622,6 +38640,50 @@ async function resolvePromptArtifacts(config2, command, signal) {
|
|
|
38622
38640
|
return new ResolvedPromptArtifacts(images, resources);
|
|
38623
38641
|
}
|
|
38624
38642
|
|
|
38643
|
+
// src/relay-connection/coalescing-text-publisher.ts
|
|
38644
|
+
var CoalescingTextPublisher = class {
|
|
38645
|
+
#coalescingMilliseconds;
|
|
38646
|
+
#maximumTextLength;
|
|
38647
|
+
#publish;
|
|
38648
|
+
#timer;
|
|
38649
|
+
#messageId = "";
|
|
38650
|
+
#scheduled = null;
|
|
38651
|
+
#text = "";
|
|
38652
|
+
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
38653
|
+
this.#publish = publish;
|
|
38654
|
+
this.#timer = timer;
|
|
38655
|
+
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
38656
|
+
this.#maximumTextLength = maximumTextLength;
|
|
38657
|
+
}
|
|
38658
|
+
/** Emit any buffered text now, cancelling the pending flush. */
|
|
38659
|
+
flush = () => {
|
|
38660
|
+
this.#scheduled?.cancel();
|
|
38661
|
+
this.#scheduled = null;
|
|
38662
|
+
const messageId = this.#messageId;
|
|
38663
|
+
const text3 = this.#text;
|
|
38664
|
+
this.#messageId = "";
|
|
38665
|
+
this.#text = "";
|
|
38666
|
+
if (text3.length > 0) {
|
|
38667
|
+
this.#publish(messageId, text3);
|
|
38668
|
+
}
|
|
38669
|
+
};
|
|
38670
|
+
/**
|
|
38671
|
+
* Buffer a chunk, emitting the buffered text when the message changes or the
|
|
38672
|
+
* buffer would exceed the protocol's per-event text limit.
|
|
38673
|
+
*/
|
|
38674
|
+
record = (messageId, text3) => {
|
|
38675
|
+
if (text3.length === 0) {
|
|
38676
|
+
return;
|
|
38677
|
+
}
|
|
38678
|
+
if (this.#text.length > 0 && (this.#messageId !== messageId || this.#text.length + text3.length > this.#maximumTextLength)) {
|
|
38679
|
+
this.flush();
|
|
38680
|
+
}
|
|
38681
|
+
this.#messageId = messageId;
|
|
38682
|
+
this.#text = `${this.#text}${text3}`;
|
|
38683
|
+
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
38684
|
+
};
|
|
38685
|
+
};
|
|
38686
|
+
|
|
38625
38687
|
// src/relay-connection/connect.ts
|
|
38626
38688
|
import { WebSocket } from "undici";
|
|
38627
38689
|
var CONNECTION_TIMEOUT_MILLISECONDS = 15e3;
|
|
@@ -38676,6 +38738,10 @@ function connectRelay(url2, signal) {
|
|
|
38676
38738
|
);
|
|
38677
38739
|
};
|
|
38678
38740
|
const onClose = (event) => {
|
|
38741
|
+
if (isRuntimeRelayRevocation(event.code, event.reason)) {
|
|
38742
|
+
fail(new RuntimeRelayRevokedError(event.code, event.reason));
|
|
38743
|
+
return;
|
|
38744
|
+
}
|
|
38679
38745
|
fail(
|
|
38680
38746
|
new RelayConnectionError("relay_connection_closed", "Relay connection closed before it was ready", {
|
|
38681
38747
|
closeCode: event.code.toString(),
|
|
@@ -38950,12 +39016,16 @@ var RelayConnectionLiveness = class {
|
|
|
38950
39016
|
heartbeatId,
|
|
38951
39017
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
38952
39018
|
);
|
|
38953
|
-
this.#transport.send(
|
|
39019
|
+
const sent = this.#transport.send(
|
|
38954
39020
|
encodeRuntimeHeartbeatEvent({
|
|
38955
39021
|
heartbeatId,
|
|
38956
39022
|
kind: RUNTIME_HEARTBEAT_KIND
|
|
38957
39023
|
})
|
|
38958
39024
|
);
|
|
39025
|
+
if (!sent && this.#state instanceof AwaitingHeartbeatAckState && this.#state.heartbeatId === heartbeatId) {
|
|
39026
|
+
this.#state.timeout.cancel();
|
|
39027
|
+
this.#state = new FinishedRelayLivenessState();
|
|
39028
|
+
}
|
|
38959
39029
|
};
|
|
38960
39030
|
};
|
|
38961
39031
|
|
|
@@ -39558,6 +39628,8 @@ var systemDaemonTimer = new SystemDaemonTimer();
|
|
|
39558
39628
|
// src/run-daemon.ts
|
|
39559
39629
|
var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
39560
39630
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39631
|
+
var AGENT_TEXT_COALESCING_MILLISECONDS = 100;
|
|
39632
|
+
var AGENT_TEXT_MAXIMUM_LENGTH = 1e5;
|
|
39561
39633
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39562
39634
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39563
39635
|
var DaemonAcpObserver = class {
|
|
@@ -40458,6 +40530,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40458
40530
|
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
40459
40531
|
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
40460
40532
|
});
|
|
40533
|
+
const text3 = new CoalescingTextPublisher(
|
|
40534
|
+
timer,
|
|
40535
|
+
(messageId, delta) => {
|
|
40536
|
+
publisher.recordAttempt(
|
|
40537
|
+
command.sessionId,
|
|
40538
|
+
encodeAgentMessageDeltaEvent({
|
|
40539
|
+
commandId: command.commandId,
|
|
40540
|
+
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
40541
|
+
messageId,
|
|
40542
|
+
sessionId: command.sessionId,
|
|
40543
|
+
text: delta
|
|
40544
|
+
}),
|
|
40545
|
+
attemptId
|
|
40546
|
+
);
|
|
40547
|
+
},
|
|
40548
|
+
AGENT_TEXT_COALESCING_MILLISECONDS,
|
|
40549
|
+
AGENT_TEXT_MAXIMUM_LENGTH
|
|
40550
|
+
);
|
|
40461
40551
|
try {
|
|
40462
40552
|
const resolved = await resolveSessionDirectories(
|
|
40463
40553
|
directories,
|
|
@@ -40544,18 +40634,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40544
40634
|
disposition: command.disposition,
|
|
40545
40635
|
images: attachments.images,
|
|
40546
40636
|
onActivity: activities.record,
|
|
40547
|
-
onText: (
|
|
40548
|
-
|
|
40549
|
-
command.sessionId,
|
|
40550
|
-
encodeAgentMessageDeltaEvent({
|
|
40551
|
-
commandId: command.commandId,
|
|
40552
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
40553
|
-
messageId,
|
|
40554
|
-
sessionId: command.sessionId,
|
|
40555
|
-
text: text3
|
|
40556
|
-
}),
|
|
40557
|
-
attemptId
|
|
40558
|
-
);
|
|
40637
|
+
onText: (delta, messageId) => {
|
|
40638
|
+
text3.record(messageId, delta);
|
|
40559
40639
|
return Promise.resolve();
|
|
40560
40640
|
},
|
|
40561
40641
|
prompt: command.prompt,
|
|
@@ -40566,6 +40646,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40566
40646
|
});
|
|
40567
40647
|
stopReason = result.stopReason;
|
|
40568
40648
|
}
|
|
40649
|
+
text3.flush();
|
|
40569
40650
|
activities.flush();
|
|
40570
40651
|
publisher.recordAttempt(
|
|
40571
40652
|
command.sessionId,
|
|
@@ -40584,6 +40665,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40584
40665
|
sessionId: command.sessionId
|
|
40585
40666
|
});
|
|
40586
40667
|
} catch (error62) {
|
|
40668
|
+
text3.flush();
|
|
40587
40669
|
activities.flush();
|
|
40588
40670
|
audit.record({
|
|
40589
40671
|
commandId: command.commandId,
|
|
@@ -41122,7 +41204,20 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41122
41204
|
}
|
|
41123
41205
|
};
|
|
41124
41206
|
const connectionLiveness = new RelayConnectionLiveness(timer, {
|
|
41125
|
-
send: (message) =>
|
|
41207
|
+
send: (message) => {
|
|
41208
|
+
if (socket.readyState !== WebSocket2.OPEN) {
|
|
41209
|
+
return false;
|
|
41210
|
+
}
|
|
41211
|
+
try {
|
|
41212
|
+
send(socket, message);
|
|
41213
|
+
return true;
|
|
41214
|
+
} catch (error62) {
|
|
41215
|
+
if (socket.readyState !== WebSocket2.OPEN) {
|
|
41216
|
+
return false;
|
|
41217
|
+
}
|
|
41218
|
+
throw error62;
|
|
41219
|
+
}
|
|
41220
|
+
},
|
|
41126
41221
|
unresponsive: (heartbeatId, timeoutMilliseconds) => {
|
|
41127
41222
|
diagnostics.heartbeatTimedOut(connectionEpoch, heartbeatId, timeoutMilliseconds);
|
|
41128
41223
|
diagnostics.connectionClosed(
|
|
@@ -41138,6 +41233,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41138
41233
|
signal.addEventListener("abort", stop, { once: true });
|
|
41139
41234
|
const handleClose = (event) => {
|
|
41140
41235
|
diagnostics.connectionClosed(connectionEpoch, event.code, event.reason, "relay");
|
|
41236
|
+
if (isRuntimeRelayRevocation(event.code, event.reason)) {
|
|
41237
|
+
rejectConnection(new RuntimeRelayRevokedError(event.code, event.reason));
|
|
41238
|
+
return;
|
|
41239
|
+
}
|
|
41141
41240
|
resolveConnection();
|
|
41142
41241
|
};
|
|
41143
41242
|
const handleError = (event) => {
|
|
@@ -41792,6 +41891,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41792
41891
|
if (signal.aborted) {
|
|
41793
41892
|
return;
|
|
41794
41893
|
}
|
|
41894
|
+
if (error62 instanceof RuntimeRelayRevokedError) {
|
|
41895
|
+
throw error62;
|
|
41896
|
+
}
|
|
41795
41897
|
diagnostics.connectionFailed(connectionEpoch, error62, "connection");
|
|
41796
41898
|
}
|
|
41797
41899
|
await waitForRelayRetry(signal, timer);
|
|
@@ -41978,6 +42080,7 @@ export {
|
|
|
41978
42080
|
PairingClientError,
|
|
41979
42081
|
RuntimeInstallationStore,
|
|
41980
42082
|
RuntimeInstallationStoreError,
|
|
42083
|
+
RuntimeRelayRevokedError,
|
|
41981
42084
|
StoredRuntimeConnection,
|
|
41982
42085
|
VerifiedRuntimeConnection,
|
|
41983
42086
|
createAcpClient,
|