@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.
@@ -0,0 +1,27 @@
1
+ import type { DaemonTimer } from "./timer.ts";
2
+ /**
3
+ * Coalesces streaming assistant text into a bounded, ordered event stream.
4
+ *
5
+ * Token-level Agents (Claude Code enables `includePartialMessages`) emit one
6
+ * update per streamed token, so a single final answer can arrive as hundreds or
7
+ * thousands of chunks. Forwarding each chunk as its own durable Session event
8
+ * floods the owning Attempt's replay window and stalls the turn's text behind
9
+ * the relay round trip. Buffering the text and flushing on a short timer bounds
10
+ * the event rate without splitting or reordering the answer.
11
+ *
12
+ * Chunks are buffered in a single slot rather than keyed by message id: the
13
+ * deltas of one turn are sequential, and a per-id map would reorder text that
14
+ * interleaves across ids when the slots flush.
15
+ */
16
+ export declare class CoalescingTextPublisher {
17
+ #private;
18
+ constructor(timer: DaemonTimer, publish: (messageId: string, text: string) => void, coalescingMilliseconds: number, maximumTextLength: number);
19
+ /** Emit any buffered text now, cancelling the pending flush. */
20
+ readonly flush: () => void;
21
+ /**
22
+ * Buffer a chunk, emitting the buffered text when the message changes or the
23
+ * buffer would exceed the protocol's per-event text limit.
24
+ */
25
+ readonly record: (messageId: string, text: string) => void;
26
+ }
27
+ //# sourceMappingURL=coalescing-text-publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coalescing-text-publisher.d.ts","sourceRoot":"","sources":["../../src/relay-connection/coalescing-text-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;;;;;;;;;;GAaG;AACH,qBAAa,uBAAuB;;IAShC,YACI,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,EAClD,sBAAsB,EAAE,MAAM,EAC9B,iBAAiB,EAAE,MAAM,EAM5B;IAED,gEAAgE;IAChE,QAAQ,CAAC,KAAK,QAAO,IAAI,CAUvB;IAEF;;;OAGG;IACH,QAAQ,CAAC,MAAM,cAAe,MAAM,QAAQ,MAAM,KAAG,IAAI,CAavD;CACL"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Coalesces streaming assistant text into a bounded, ordered event stream.
3
+ *
4
+ * Token-level Agents (Claude Code enables `includePartialMessages`) emit one
5
+ * update per streamed token, so a single final answer can arrive as hundreds or
6
+ * thousands of chunks. Forwarding each chunk as its own durable Session event
7
+ * floods the owning Attempt's replay window and stalls the turn's text behind
8
+ * the relay round trip. Buffering the text and flushing on a short timer bounds
9
+ * the event rate without splitting or reordering the answer.
10
+ *
11
+ * Chunks are buffered in a single slot rather than keyed by message id: the
12
+ * deltas of one turn are sequential, and a per-id map would reorder text that
13
+ * interleaves across ids when the slots flush.
14
+ */
15
+ export class CoalescingTextPublisher {
16
+ #coalescingMilliseconds;
17
+ #maximumTextLength;
18
+ #publish;
19
+ #timer;
20
+ #messageId = "";
21
+ #scheduled = null;
22
+ #text = "";
23
+ constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
24
+ this.#publish = publish;
25
+ this.#timer = timer;
26
+ this.#coalescingMilliseconds = coalescingMilliseconds;
27
+ this.#maximumTextLength = maximumTextLength;
28
+ }
29
+ /** Emit any buffered text now, cancelling the pending flush. */
30
+ flush = () => {
31
+ this.#scheduled?.cancel();
32
+ this.#scheduled = null;
33
+ const messageId = this.#messageId;
34
+ const text = this.#text;
35
+ this.#messageId = "";
36
+ this.#text = "";
37
+ if (text.length > 0) {
38
+ this.#publish(messageId, text);
39
+ }
40
+ };
41
+ /**
42
+ * Buffer a chunk, emitting the buffered text when the message changes or the
43
+ * buffer would exceed the protocol's per-event text limit.
44
+ */
45
+ record = (messageId, text) => {
46
+ if (text.length === 0) {
47
+ return;
48
+ }
49
+ if (this.#text.length > 0 &&
50
+ (this.#messageId !== messageId || this.#text.length + text.length > this.#maximumTextLength)) {
51
+ this.flush();
52
+ }
53
+ this.#messageId = messageId;
54
+ this.#text = `${this.#text}${text}`;
55
+ this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
56
+ };
57
+ }
58
+ //# sourceMappingURL=coalescing-text-publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coalescing-text-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/coalescing-text-publisher.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,uBAAuB;IACvB,uBAAuB,CAAS;IAChC,kBAAkB,CAAS;IAC3B,QAAQ,CAA4C;IACpD,MAAM,CAAc;IAC7B,UAAU,GAAG,EAAE,CAAC;IAChB,UAAU,GAA+B,IAAI,CAAC;IAC9C,KAAK,GAAG,EAAE,CAAC;IAEX,YACI,KAAkB,EAClB,OAAkD,EAClD,sBAA8B,EAC9B,iBAAyB;QAEzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,uBAAuB,GAAG,sBAAsB,CAAC;QACtD,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChD,CAAC;IAED,gEAAgE;IACvD,KAAK,GAAG,GAAS,EAAE;QACxB,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;IACL,CAAC,CAAC;IAEF;;;OAGG;IACM,MAAM,GAAG,CAAC,SAAiB,EAAE,IAAY,EAAQ,EAAE;QACxD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO;QACX,CAAC;QACD,IACI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACrB,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,EAC9F,CAAC;YACC,IAAI,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvF,CAAC,CAAC;CACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/relay-connection/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAwBnC,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAsF9E"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/relay-connection/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAyBnC,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CA0F9E"}
@@ -1,6 +1,7 @@
1
1
  import { WebSocket } from "undici";
2
2
  import { environmentProxyDispatcher } from "../network/environment-proxy.js";
3
3
  import { runtimeAuthorization } from "./runtime-authentication.js";
4
+ import { isRuntimeRelayRevocation, RuntimeRelayRevokedError } from "./runtime-revocation.js";
4
5
  const CONNECTION_TIMEOUT_MILLISECONDS = 15_000;
5
6
  class RelayConnectionError extends Error {
6
7
  code;
@@ -46,6 +47,10 @@ export function connectRelay(url, signal) {
46
47
  }, { cause: signal.reason }));
47
48
  };
48
49
  const onClose = (event) => {
50
+ if (isRuntimeRelayRevocation(event.code, event.reason)) {
51
+ fail(new RuntimeRelayRevokedError(event.code, event.reason));
52
+ return;
53
+ }
49
54
  fail(new RelayConnectionError("relay_connection_closed", "Relay connection closed before it was ready", {
50
55
  closeCode: event.code.toString(),
51
56
  closeReason: event.reason,
@@ -1 +1 @@
1
- {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/relay-connection/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,+BAA+B,GAAG,MAAM,CAAC;AAE/C,MAAM,oBAAqB,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,iBAAiB,CAAmC;IAE7D,YACI,IAAY,EACZ,OAAe,EACf,iBAAiB,GAAqC,EAAE,EACxD,OAAO,GAAiB,EAAE;QAE1B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACvC,CAAC;CACJ;AAED,MAAM,UAAU,YAAY,CAAC,GAAQ,EAAE,MAAmB;IACtD,MAAM,CAAC,cAAc,EAAE,CAAC;IAExB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;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AAC,CAAC;QAExD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A Runtime relay revocation is terminal for this local Runtime. It is normalized from the
3
+ * deployed Relay close record so callers never need to branch on transport text.
4
+ */
5
+ export declare class RuntimeRelayRevokedError extends Error {
6
+ readonly code = "runtime_relay_revoked";
7
+ readonly closeCode: number;
8
+ readonly closeReason: string;
9
+ constructor(closeCode: number, closeReason: string, options?: ErrorOptions);
10
+ }
11
+ export declare function isRuntimeRelayRevocation(closeCode: number, closeReason: string): boolean;
12
+ //# sourceMappingURL=runtime-revocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-revocation.d.ts","sourceRoot":"","sources":["../../src/relay-connection/runtime-revocation.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,2BAA2B;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,YAAY,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,EAK7E;CACJ;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAExF"}
@@ -0,0 +1,21 @@
1
+ const runtimeRevocationCloseCode = 1008;
2
+ const runtimeRevocationCloseReason = "Runtime revoked";
3
+ /**
4
+ * A Runtime relay revocation is terminal for this local Runtime. It is normalized from the
5
+ * deployed Relay close record so callers never need to branch on transport text.
6
+ */
7
+ export class RuntimeRelayRevokedError extends Error {
8
+ code = "runtime_relay_revoked";
9
+ closeCode;
10
+ closeReason;
11
+ constructor(closeCode, closeReason, options = {}) {
12
+ super("The Runtime was revoked by the Relay", options);
13
+ this.closeCode = closeCode;
14
+ this.closeReason = closeReason;
15
+ this.name = "RuntimeRelayRevokedError";
16
+ }
17
+ }
18
+ export function isRuntimeRelayRevocation(closeCode, closeReason) {
19
+ return closeCode === runtimeRevocationCloseCode && closeReason === runtimeRevocationCloseReason;
20
+ }
21
+ //# sourceMappingURL=runtime-revocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-revocation.js","sourceRoot":"","sources":["../../src/relay-connection/runtime-revocation.ts"],"names":[],"mappings":"AAAA,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAEvD;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACtC,IAAI,GAAG,uBAAuB,CAAC;IAC/B,SAAS,CAAS;IAClB,WAAW,CAAS;IAE7B,YAAY,SAAiB,EAAE,WAAmB,EAAE,OAAO,GAAiB,EAAE;QAC1E,KAAK,CAAC,sCAAsC,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IAC3C,CAAC;CACJ;AAED,MAAM,UAAU,wBAAwB,CAAC,SAAiB,EAAE,WAAmB;IAC3E,OAAO,SAAS,KAAK,0BAA0B,IAAI,WAAW,KAAK,4BAA4B,CAAC;AACpG,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"AAgJA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAUhD,OAAO,EAA4B,KAAK,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AA4/E5G,wBAAsB,SAAS,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE,WAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CAoJf"}
1
+ {"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"AAgJA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD,OAAO,EAA4B,KAAK,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AA8gF5G,wBAAsB,SAAS,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE,WAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CAuJf"}
@@ -19,14 +19,20 @@ import { AccumulatingOperationMetrics } from "./infra/operation-metrics.js";
19
19
  import { NativeSessionService } from "./native-sessions/service.js";
20
20
  import { environmentProxyDispatcher } from "./network/environment-proxy.js";
21
21
  import { PromptArtifactError, resolvePromptArtifacts } from "./prompt-artifact-resolver.js";
22
+ import { CoalescingTextPublisher } from "./relay-connection/coalescing-text-publisher.js";
22
23
  import { connectRelay } from "./relay-connection/connect.js";
23
24
  import { RelayConnectionDiagnostics } from "./relay-connection/diagnostics.js";
24
25
  import { RelayConnectionLiveness } from "./relay-connection/liveness.js";
25
26
  import { relayHttpEndpoint, runtimeAuthorization } from "./relay-connection/runtime-authentication.js";
27
+ import { isRuntimeRelayRevocation, RuntimeRelayRevokedError } from "./relay-connection/runtime-revocation.js";
26
28
  import { RuntimeDeliveryInboxCapacityError, SessionEventOutbox } from "./relay-connection/session-event-outbox.js";
27
29
  import { systemDaemonTimer } from "./relay-connection/timer.js";
28
30
  const RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
29
31
  const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
32
+ const AGENT_TEXT_COALESCING_MILLISECONDS = 100;
33
+ // Mirrors the protocol's per-event text limit; a delta larger than this is
34
+ // rejected by the Session event codec rather than truncated.
35
+ const AGENT_TEXT_MAXIMUM_LENGTH = 100_000;
30
36
  const ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 20_000;
31
37
  const ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
32
38
  class DaemonAcpObserver {
@@ -876,6 +882,15 @@ async function executePrompt(outbox, publisher, command, config, directories, au
876
882
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
877
883
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
878
884
  });
885
+ const text = new CoalescingTextPublisher(timer, (messageId, delta) => {
886
+ publisher.recordAttempt(command.sessionId, encodeAgentMessageDeltaEvent({
887
+ commandId: command.commandId,
888
+ kind: AGENT_MESSAGE_DELTA_KIND,
889
+ messageId,
890
+ sessionId: command.sessionId,
891
+ text: delta,
892
+ }), attemptId);
893
+ }, AGENT_TEXT_COALESCING_MILLISECONDS, AGENT_TEXT_MAXIMUM_LENGTH);
879
894
  try {
880
895
  const resolved = await resolveSessionDirectories(directories, config.bindingId, command.directoryId, command.additionalDirectoryIds, signal);
881
896
  const agent = config.catalog.find(command.agentId);
@@ -942,14 +957,8 @@ async function executePrompt(outbox, publisher, command, config, directories, au
942
957
  disposition: command.disposition,
943
958
  images: attachments.images,
944
959
  onActivity: activities.record,
945
- onText: (text, messageId) => {
946
- publisher.recordAttempt(command.sessionId, encodeAgentMessageDeltaEvent({
947
- commandId: command.commandId,
948
- kind: AGENT_MESSAGE_DELTA_KIND,
949
- messageId,
950
- sessionId: command.sessionId,
951
- text,
952
- }), attemptId);
960
+ onText: (delta, messageId) => {
961
+ text.record(messageId, delta);
953
962
  return Promise.resolve();
954
963
  },
955
964
  prompt: command.prompt,
@@ -960,6 +969,7 @@ async function executePrompt(outbox, publisher, command, config, directories, au
960
969
  });
961
970
  stopReason = result.stopReason;
962
971
  }
972
+ text.flush();
963
973
  activities.flush();
964
974
  publisher.recordAttempt(command.sessionId, encodeSessionCompletedEvent({
965
975
  commandId: command.commandId,
@@ -975,6 +985,7 @@ async function executePrompt(outbox, publisher, command, config, directories, au
975
985
  });
976
986
  }
977
987
  catch (error) {
988
+ text.flush();
978
989
  activities.flush();
979
990
  audit.record({
980
991
  commandId: command.commandId,
@@ -1446,6 +1457,10 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1446
1457
  signal.addEventListener("abort", stop, { once: true });
1447
1458
  const handleClose = (event) => {
1448
1459
  diagnostics.connectionClosed(connectionEpoch, event.code, event.reason, "relay");
1460
+ if (isRuntimeRelayRevocation(event.code, event.reason)) {
1461
+ rejectConnection(new RuntimeRelayRevokedError(event.code, event.reason));
1462
+ return;
1463
+ }
1449
1464
  resolveConnection();
1450
1465
  };
1451
1466
  const handleError = (event) => {
@@ -1962,6 +1977,9 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
1962
1977
  if (signal.aborted) {
1963
1978
  return;
1964
1979
  }
1980
+ if (error instanceof RuntimeRelayRevokedError) {
1981
+ throw error;
1982
+ }
1965
1983
  diagnostics.connectionFailed(connectionEpoch, error, "connection");
1966
1984
  }
1967
1985
  await waitForRelayRetry(signal, timer);