@moxt-ai/mobius 0.0.53 → 0.0.54

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/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";
@@ -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,K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,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(),
@@ -39558,6 +39624,8 @@ var systemDaemonTimer = new SystemDaemonTimer();
39558
39624
  // src/run-daemon.ts
39559
39625
  var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
39560
39626
  var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
39627
+ var AGENT_TEXT_COALESCING_MILLISECONDS = 100;
39628
+ var AGENT_TEXT_MAXIMUM_LENGTH = 1e5;
39561
39629
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
39562
39630
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
39563
39631
  var DaemonAcpObserver = class {
@@ -40458,6 +40526,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40458
40526
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40459
40527
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40460
40528
  });
40529
+ const text3 = new CoalescingTextPublisher(
40530
+ timer,
40531
+ (messageId, delta) => {
40532
+ publisher.recordAttempt(
40533
+ command.sessionId,
40534
+ encodeAgentMessageDeltaEvent({
40535
+ commandId: command.commandId,
40536
+ kind: AGENT_MESSAGE_DELTA_KIND,
40537
+ messageId,
40538
+ sessionId: command.sessionId,
40539
+ text: delta
40540
+ }),
40541
+ attemptId
40542
+ );
40543
+ },
40544
+ AGENT_TEXT_COALESCING_MILLISECONDS,
40545
+ AGENT_TEXT_MAXIMUM_LENGTH
40546
+ );
40461
40547
  try {
40462
40548
  const resolved = await resolveSessionDirectories(
40463
40549
  directories,
@@ -40544,18 +40630,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40544
40630
  disposition: command.disposition,
40545
40631
  images: attachments.images,
40546
40632
  onActivity: activities.record,
40547
- onText: (text3, messageId) => {
40548
- publisher.recordAttempt(
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
- );
40633
+ onText: (delta, messageId) => {
40634
+ text3.record(messageId, delta);
40559
40635
  return Promise.resolve();
40560
40636
  },
40561
40637
  prompt: command.prompt,
@@ -40566,6 +40642,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40566
40642
  });
40567
40643
  stopReason = result.stopReason;
40568
40644
  }
40645
+ text3.flush();
40569
40646
  activities.flush();
40570
40647
  publisher.recordAttempt(
40571
40648
  command.sessionId,
@@ -40584,6 +40661,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40584
40661
  sessionId: command.sessionId
40585
40662
  });
40586
40663
  } catch (error62) {
40664
+ text3.flush();
40587
40665
  activities.flush();
40588
40666
  audit.record({
40589
40667
  commandId: command.commandId,
@@ -41138,6 +41216,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41138
41216
  signal.addEventListener("abort", stop, { once: true });
41139
41217
  const handleClose = (event) => {
41140
41218
  diagnostics.connectionClosed(connectionEpoch, event.code, event.reason, "relay");
41219
+ if (isRuntimeRelayRevocation(event.code, event.reason)) {
41220
+ rejectConnection(new RuntimeRelayRevokedError(event.code, event.reason));
41221
+ return;
41222
+ }
41141
41223
  resolveConnection();
41142
41224
  };
41143
41225
  const handleError = (event) => {
@@ -41792,6 +41874,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41792
41874
  if (signal.aborted) {
41793
41875
  return;
41794
41876
  }
41877
+ if (error62 instanceof RuntimeRelayRevokedError) {
41878
+ throw error62;
41879
+ }
41795
41880
  diagnostics.connectionFailed(connectionEpoch, error62, "connection");
41796
41881
  }
41797
41882
  await waitForRelayRetry(signal, timer);
@@ -41978,6 +42063,7 @@ export {
41978
42063
  PairingClientError,
41979
42064
  RuntimeInstallationStore,
41980
42065
  RuntimeInstallationStoreError,
42066
+ RuntimeRelayRevokedError,
41981
42067
  StoredRuntimeConnection,
41982
42068
  VerifiedRuntimeConnection,
41983
42069
  createAcpClient,