@moxt-ai/mobius 0.0.52 → 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 {
@@ -40138,32 +40206,41 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
40138
40206
  async function discoverAgentSettings(command, config2, directories, sessions, signal) {
40139
40207
  const agent = config2.catalog.find(command.agentId);
40140
40208
  const cwd = await directories.resolve(config2.bindingId, "default", signal);
40141
- const snapshot = await sessions.inspectAgentSettings({
40209
+ const baseSnapshot = await sessions.inspectAgentSettings({
40142
40210
  additionalDirectories: [],
40143
40211
  agent,
40144
40212
  cwd,
40145
40213
  signal
40146
40214
  });
40215
+ const selectedSnapshot = command.model === void 0 ? baseSnapshot : await sessions.inspectAgentSettings({
40216
+ additionalDirectories: [],
40217
+ agent,
40218
+ cwd,
40219
+ model: command.model,
40220
+ signal
40221
+ });
40147
40222
  const adapter = agentSettingsAdapterForAgent(agent.id);
40148
- const settings = settingsFromSnapshot(agent, snapshot.configOptions);
40223
+ const baseSettings = settingsFromSnapshot(agent, baseSnapshot.configOptions);
40224
+ const settings = settingsFromSnapshot(agent, selectedSnapshot.configOptions);
40149
40225
  const modelEffort = await discoverModelEffort(
40150
40226
  command,
40151
40227
  agent,
40152
40228
  adapter.modelEffortResolution,
40153
- snapshot.configOptions,
40229
+ baseSnapshot.configOptions,
40230
+ selectedSnapshot.configOptions,
40154
40231
  cwd,
40155
40232
  sessions,
40156
40233
  signal
40157
40234
  );
40158
40235
  return {
40159
40236
  agentId: command.agentId,
40160
- agentName: snapshot.agentName,
40161
- agentVersion: snapshot.agentVersion,
40237
+ agentName: selectedSnapshot.agentName,
40238
+ agentVersion: selectedSnapshot.agentVersion,
40162
40239
  kind: AGENT_SETTINGS_DISCOVERED_KIND,
40163
40240
  modelEffort,
40164
40241
  requestId: command.requestId,
40165
40242
  settings,
40166
- settingsRevision: settingsRevision(agent, snapshot.agentVersion, settings, modelEffort)
40243
+ settingsRevision: settingsRevision(agent, baseSnapshot.agentVersion, baseSettings, modelEffort)
40167
40244
  };
40168
40245
  }
40169
40246
  function settingFromOption(option) {
@@ -40213,13 +40290,12 @@ function unavailableModelEffort() {
40213
40290
  valuesByModel: {}
40214
40291
  };
40215
40292
  }
40216
- async function discoverModelEffort(command, agent, resolution, initialOptions, cwd, sessions, signal) {
40293
+ async function discoverModelEffort(command, agent, resolution, initialOptions, selectedOptions, cwd, sessions, signal) {
40217
40294
  const model = modelOption(initialOptions);
40218
- const effort = effortOption(initialOptions);
40219
40295
  if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
40220
40296
  return unavailableModelEffort();
40221
40297
  }
40222
- if (model === void 0 || model.type !== "select" || model.values.length === 0 || effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
40298
+ if (model === void 0 || model.type !== "select" || model.values.length === 0) {
40223
40299
  return unavailableModelEffort();
40224
40300
  }
40225
40301
  const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
@@ -40231,9 +40307,13 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
40231
40307
  })).configOptions;
40232
40308
  const valuesByModel = {};
40233
40309
  if (resolution === "complete") {
40310
+ const effort = effortOption(initialOptions);
40311
+ if (effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
40312
+ return unavailableModelEffort();
40313
+ }
40234
40314
  for (const value of model.values) {
40235
- const selectedEffort = effortOption(await inspectModel(value.value));
40236
- valuesByModel[value.value] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40315
+ const selectedEffort2 = effortOption(await inspectModel(value.value));
40316
+ valuesByModel[value.value] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
40237
40317
  }
40238
40318
  return {
40239
40319
  effortSettingId: effort.id,
@@ -40246,18 +40326,24 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
40246
40326
  if (!model.values.some((value) => value.value === command.model)) {
40247
40327
  throw new AcpExecutionError("The selected Agent model is unavailable", {}, "invalid_session_configuration");
40248
40328
  }
40249
- const selectedEffort = effortOption(await inspectModel(command.model));
40250
- valuesByModel[command.model] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40329
+ const selectedEffort2 = effortOption(selectedOptions);
40330
+ valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
40251
40331
  }
40332
+ const selectedEffort = effortOption(selectedOptions);
40252
40333
  return {
40253
- effortSettingId: effort.id,
40334
+ effortSettingId: selectedEffort?.id ?? "",
40254
40335
  modelSettingId: model.id,
40255
40336
  resolution: "on_model_selection",
40256
40337
  valuesByModel
40257
40338
  };
40258
40339
  }
40259
40340
  function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
40260
- const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : { ...modelEffort, valuesByModel: {} };
40341
+ const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
40342
+ effortSettingId: "",
40343
+ modelSettingId: modelEffort.modelSettingId,
40344
+ resolution: modelEffort.resolution,
40345
+ valuesByModel: {}
40346
+ };
40261
40347
  return createHash5("sha256").update(
40262
40348
  JSON.stringify({
40263
40349
  adapterVersion: agent.adapterVersion,
@@ -40440,6 +40526,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40440
40526
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40441
40527
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40442
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
+ );
40443
40547
  try {
40444
40548
  const resolved = await resolveSessionDirectories(
40445
40549
  directories,
@@ -40526,18 +40630,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40526
40630
  disposition: command.disposition,
40527
40631
  images: attachments.images,
40528
40632
  onActivity: activities.record,
40529
- onText: (text3, messageId) => {
40530
- publisher.recordAttempt(
40531
- command.sessionId,
40532
- encodeAgentMessageDeltaEvent({
40533
- commandId: command.commandId,
40534
- kind: AGENT_MESSAGE_DELTA_KIND,
40535
- messageId,
40536
- sessionId: command.sessionId,
40537
- text: text3
40538
- }),
40539
- attemptId
40540
- );
40633
+ onText: (delta, messageId) => {
40634
+ text3.record(messageId, delta);
40541
40635
  return Promise.resolve();
40542
40636
  },
40543
40637
  prompt: command.prompt,
@@ -40548,6 +40642,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40548
40642
  });
40549
40643
  stopReason = result.stopReason;
40550
40644
  }
40645
+ text3.flush();
40551
40646
  activities.flush();
40552
40647
  publisher.recordAttempt(
40553
40648
  command.sessionId,
@@ -40566,6 +40661,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40566
40661
  sessionId: command.sessionId
40567
40662
  });
40568
40663
  } catch (error62) {
40664
+ text3.flush();
40569
40665
  activities.flush();
40570
40666
  audit.record({
40571
40667
  commandId: command.commandId,
@@ -40629,17 +40725,6 @@ function assertSessionConfigurationSchema(options, selections) {
40629
40725
  }
40630
40726
  }
40631
40727
  }
40632
- function assertSessionConfigurationCoverage(options, selections) {
40633
- const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40634
- if (selectionsById.size !== selections.length) {
40635
- throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
40636
- }
40637
- for (const option of options) {
40638
- if (!selectionsById.has(option.id)) {
40639
- throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
40640
- }
40641
- }
40642
- }
40643
40728
  function sessionConfigurationSelectionIsAvailable(option, selection) {
40644
40729
  if (option.type !== selection.valueType) {
40645
40730
  return false;
@@ -40768,7 +40853,6 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
40768
40853
  });
40769
40854
  }
40770
40855
  async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40771
- assertSessionConfigurationCoverage(initialOptions, selections);
40772
40856
  let options = initialOptions;
40773
40857
  const orderedSelections = selections.toSorted((left, right) => {
40774
40858
  const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
@@ -41132,6 +41216,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41132
41216
  signal.addEventListener("abort", stop, { once: true });
41133
41217
  const handleClose = (event) => {
41134
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
+ }
41135
41223
  resolveConnection();
41136
41224
  };
41137
41225
  const handleError = (event) => {
@@ -41786,6 +41874,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41786
41874
  if (signal.aborted) {
41787
41875
  return;
41788
41876
  }
41877
+ if (error62 instanceof RuntimeRelayRevokedError) {
41878
+ throw error62;
41879
+ }
41789
41880
  diagnostics.connectionFailed(connectionEpoch, error62, "connection");
41790
41881
  }
41791
41882
  await waitForRelayRetry(signal, timer);
@@ -41972,6 +42063,7 @@ export {
41972
42063
  PairingClientError,
41973
42064
  RuntimeInstallationStore,
41974
42065
  RuntimeInstallationStoreError,
42066
+ RuntimeRelayRevokedError,
41975
42067
  StoredRuntimeConnection,
41976
42068
  VerifiedRuntimeConnection,
41977
42069
  createAcpClient,