@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/cli.js CHANGED
@@ -11,7 +11,7 @@ import { mkdir as mkdir5 } from "node:fs/promises";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@moxt-ai/mobius",
14
- version: "0.0.53",
14
+ version: "0.0.54",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -38705,8 +38705,72 @@ async function resolvePromptArtifacts(config2, command, signal) {
38705
38705
  return new ResolvedPromptArtifacts(images, resources);
38706
38706
  }
38707
38707
 
38708
+ // src/relay-connection/coalescing-text-publisher.ts
38709
+ var CoalescingTextPublisher = class {
38710
+ #coalescingMilliseconds;
38711
+ #maximumTextLength;
38712
+ #publish;
38713
+ #timer;
38714
+ #messageId = "";
38715
+ #scheduled = null;
38716
+ #text = "";
38717
+ constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
38718
+ this.#publish = publish;
38719
+ this.#timer = timer;
38720
+ this.#coalescingMilliseconds = coalescingMilliseconds;
38721
+ this.#maximumTextLength = maximumTextLength;
38722
+ }
38723
+ /** Emit any buffered text now, cancelling the pending flush. */
38724
+ flush = () => {
38725
+ this.#scheduled?.cancel();
38726
+ this.#scheduled = null;
38727
+ const messageId = this.#messageId;
38728
+ const text3 = this.#text;
38729
+ this.#messageId = "";
38730
+ this.#text = "";
38731
+ if (text3.length > 0) {
38732
+ this.#publish(messageId, text3);
38733
+ }
38734
+ };
38735
+ /**
38736
+ * Buffer a chunk, emitting the buffered text when the message changes or the
38737
+ * buffer would exceed the protocol's per-event text limit.
38738
+ */
38739
+ record = (messageId, text3) => {
38740
+ if (text3.length === 0) {
38741
+ return;
38742
+ }
38743
+ if (this.#text.length > 0 && (this.#messageId !== messageId || this.#text.length + text3.length > this.#maximumTextLength)) {
38744
+ this.flush();
38745
+ }
38746
+ this.#messageId = messageId;
38747
+ this.#text = `${this.#text}${text3}`;
38748
+ this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
38749
+ };
38750
+ };
38751
+
38708
38752
  // src/relay-connection/connect.ts
38709
38753
  import { WebSocket } from "undici";
38754
+
38755
+ // src/relay-connection/runtime-revocation.ts
38756
+ var runtimeRevocationCloseCode = 1008;
38757
+ var runtimeRevocationCloseReason = "Runtime revoked";
38758
+ var RuntimeRelayRevokedError = class extends Error {
38759
+ code = "runtime_relay_revoked";
38760
+ closeCode;
38761
+ closeReason;
38762
+ constructor(closeCode, closeReason, options = {}) {
38763
+ super("The Runtime was revoked by the Relay", options);
38764
+ this.closeCode = closeCode;
38765
+ this.closeReason = closeReason;
38766
+ this.name = "RuntimeRelayRevokedError";
38767
+ }
38768
+ };
38769
+ function isRuntimeRelayRevocation(closeCode, closeReason) {
38770
+ return closeCode === runtimeRevocationCloseCode && closeReason === runtimeRevocationCloseReason;
38771
+ }
38772
+
38773
+ // src/relay-connection/connect.ts
38710
38774
  var CONNECTION_TIMEOUT_MILLISECONDS = 15e3;
38711
38775
  var RelayConnectionError = class extends Error {
38712
38776
  code;
@@ -38759,6 +38823,10 @@ function connectRelay(url2, signal) {
38759
38823
  );
38760
38824
  };
38761
38825
  const onClose = (event) => {
38826
+ if (isRuntimeRelayRevocation(event.code, event.reason)) {
38827
+ fail(new RuntimeRelayRevokedError(event.code, event.reason));
38828
+ return;
38829
+ }
38762
38830
  fail(
38763
38831
  new RelayConnectionError("relay_connection_closed", "Relay connection closed before it was ready", {
38764
38832
  closeCode: event.code.toString(),
@@ -39641,6 +39709,8 @@ var systemDaemonTimer = new SystemDaemonTimer();
39641
39709
  // src/run-daemon.ts
39642
39710
  var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
39643
39711
  var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
39712
+ var AGENT_TEXT_COALESCING_MILLISECONDS = 100;
39713
+ var AGENT_TEXT_MAXIMUM_LENGTH = 1e5;
39644
39714
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
39645
39715
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
39646
39716
  var DaemonAcpObserver = class {
@@ -40541,6 +40611,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40541
40611
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40542
40612
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40543
40613
  });
40614
+ const text3 = new CoalescingTextPublisher(
40615
+ timer,
40616
+ (messageId, delta) => {
40617
+ publisher.recordAttempt(
40618
+ command.sessionId,
40619
+ encodeAgentMessageDeltaEvent({
40620
+ commandId: command.commandId,
40621
+ kind: AGENT_MESSAGE_DELTA_KIND,
40622
+ messageId,
40623
+ sessionId: command.sessionId,
40624
+ text: delta
40625
+ }),
40626
+ attemptId
40627
+ );
40628
+ },
40629
+ AGENT_TEXT_COALESCING_MILLISECONDS,
40630
+ AGENT_TEXT_MAXIMUM_LENGTH
40631
+ );
40544
40632
  try {
40545
40633
  const resolved = await resolveSessionDirectories(
40546
40634
  directories,
@@ -40627,18 +40715,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40627
40715
  disposition: command.disposition,
40628
40716
  images: attachments.images,
40629
40717
  onActivity: activities.record,
40630
- onText: (text3, messageId) => {
40631
- publisher.recordAttempt(
40632
- command.sessionId,
40633
- encodeAgentMessageDeltaEvent({
40634
- commandId: command.commandId,
40635
- kind: AGENT_MESSAGE_DELTA_KIND,
40636
- messageId,
40637
- sessionId: command.sessionId,
40638
- text: text3
40639
- }),
40640
- attemptId
40641
- );
40718
+ onText: (delta, messageId) => {
40719
+ text3.record(messageId, delta);
40642
40720
  return Promise.resolve();
40643
40721
  },
40644
40722
  prompt: command.prompt,
@@ -40649,6 +40727,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40649
40727
  });
40650
40728
  stopReason = result.stopReason;
40651
40729
  }
40730
+ text3.flush();
40652
40731
  activities.flush();
40653
40732
  publisher.recordAttempt(
40654
40733
  command.sessionId,
@@ -40667,6 +40746,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40667
40746
  sessionId: command.sessionId
40668
40747
  });
40669
40748
  } catch (error62) {
40749
+ text3.flush();
40670
40750
  activities.flush();
40671
40751
  audit.record({
40672
40752
  commandId: command.commandId,
@@ -41221,6 +41301,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41221
41301
  signal.addEventListener("abort", stop, { once: true });
41222
41302
  const handleClose = (event) => {
41223
41303
  diagnostics.connectionClosed(connectionEpoch, event.code, event.reason, "relay");
41304
+ if (isRuntimeRelayRevocation(event.code, event.reason)) {
41305
+ rejectConnection(new RuntimeRelayRevokedError(event.code, event.reason));
41306
+ return;
41307
+ }
41224
41308
  resolveConnection();
41225
41309
  };
41226
41310
  const handleError = (event) => {
@@ -41875,6 +41959,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41875
41959
  if (signal.aborted) {
41876
41960
  return;
41877
41961
  }
41962
+ if (error62 instanceof RuntimeRelayRevokedError) {
41963
+ throw error62;
41964
+ }
41878
41965
  diagnostics.connectionFailed(connectionEpoch, error62, "connection");
41879
41966
  }
41880
41967
  await waitForRelayRetry(signal, timer);