@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/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.52",
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 {
@@ -40221,32 +40291,41 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
40221
40291
  async function discoverAgentSettings(command, config2, directories, sessions, signal) {
40222
40292
  const agent = config2.catalog.find(command.agentId);
40223
40293
  const cwd = await directories.resolve(config2.bindingId, "default", signal);
40224
- const snapshot = await sessions.inspectAgentSettings({
40294
+ const baseSnapshot = await sessions.inspectAgentSettings({
40225
40295
  additionalDirectories: [],
40226
40296
  agent,
40227
40297
  cwd,
40228
40298
  signal
40229
40299
  });
40300
+ const selectedSnapshot = command.model === void 0 ? baseSnapshot : await sessions.inspectAgentSettings({
40301
+ additionalDirectories: [],
40302
+ agent,
40303
+ cwd,
40304
+ model: command.model,
40305
+ signal
40306
+ });
40230
40307
  const adapter = agentSettingsAdapterForAgent(agent.id);
40231
- const settings = settingsFromSnapshot(agent, snapshot.configOptions);
40308
+ const baseSettings = settingsFromSnapshot(agent, baseSnapshot.configOptions);
40309
+ const settings = settingsFromSnapshot(agent, selectedSnapshot.configOptions);
40232
40310
  const modelEffort = await discoverModelEffort(
40233
40311
  command,
40234
40312
  agent,
40235
40313
  adapter.modelEffortResolution,
40236
- snapshot.configOptions,
40314
+ baseSnapshot.configOptions,
40315
+ selectedSnapshot.configOptions,
40237
40316
  cwd,
40238
40317
  sessions,
40239
40318
  signal
40240
40319
  );
40241
40320
  return {
40242
40321
  agentId: command.agentId,
40243
- agentName: snapshot.agentName,
40244
- agentVersion: snapshot.agentVersion,
40322
+ agentName: selectedSnapshot.agentName,
40323
+ agentVersion: selectedSnapshot.agentVersion,
40245
40324
  kind: AGENT_SETTINGS_DISCOVERED_KIND,
40246
40325
  modelEffort,
40247
40326
  requestId: command.requestId,
40248
40327
  settings,
40249
- settingsRevision: settingsRevision(agent, snapshot.agentVersion, settings, modelEffort)
40328
+ settingsRevision: settingsRevision(agent, baseSnapshot.agentVersion, baseSettings, modelEffort)
40250
40329
  };
40251
40330
  }
40252
40331
  function settingFromOption(option) {
@@ -40296,13 +40375,12 @@ function unavailableModelEffort() {
40296
40375
  valuesByModel: {}
40297
40376
  };
40298
40377
  }
40299
- async function discoverModelEffort(command, agent, resolution, initialOptions, cwd, sessions, signal) {
40378
+ async function discoverModelEffort(command, agent, resolution, initialOptions, selectedOptions, cwd, sessions, signal) {
40300
40379
  const model = modelOption(initialOptions);
40301
- const effort = effortOption(initialOptions);
40302
40380
  if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
40303
40381
  return unavailableModelEffort();
40304
40382
  }
40305
- if (model === void 0 || model.type !== "select" || model.values.length === 0 || effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
40383
+ if (model === void 0 || model.type !== "select" || model.values.length === 0) {
40306
40384
  return unavailableModelEffort();
40307
40385
  }
40308
40386
  const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
@@ -40314,9 +40392,13 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
40314
40392
  })).configOptions;
40315
40393
  const valuesByModel = {};
40316
40394
  if (resolution === "complete") {
40395
+ const effort = effortOption(initialOptions);
40396
+ if (effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
40397
+ return unavailableModelEffort();
40398
+ }
40317
40399
  for (const value of model.values) {
40318
- const selectedEffort = effortOption(await inspectModel(value.value));
40319
- valuesByModel[value.value] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40400
+ const selectedEffort2 = effortOption(await inspectModel(value.value));
40401
+ valuesByModel[value.value] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
40320
40402
  }
40321
40403
  return {
40322
40404
  effortSettingId: effort.id,
@@ -40329,18 +40411,24 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
40329
40411
  if (!model.values.some((value) => value.value === command.model)) {
40330
40412
  throw new AcpExecutionError("The selected Agent model is unavailable", {}, "invalid_session_configuration");
40331
40413
  }
40332
- const selectedEffort = effortOption(await inspectModel(command.model));
40333
- valuesByModel[command.model] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40414
+ const selectedEffort2 = effortOption(selectedOptions);
40415
+ valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
40334
40416
  }
40417
+ const selectedEffort = effortOption(selectedOptions);
40335
40418
  return {
40336
- effortSettingId: effort.id,
40419
+ effortSettingId: selectedEffort?.id ?? "",
40337
40420
  modelSettingId: model.id,
40338
40421
  resolution: "on_model_selection",
40339
40422
  valuesByModel
40340
40423
  };
40341
40424
  }
40342
40425
  function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
40343
- const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : { ...modelEffort, valuesByModel: {} };
40426
+ const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
40427
+ effortSettingId: "",
40428
+ modelSettingId: modelEffort.modelSettingId,
40429
+ resolution: modelEffort.resolution,
40430
+ valuesByModel: {}
40431
+ };
40344
40432
  return createHash5("sha256").update(
40345
40433
  JSON.stringify({
40346
40434
  adapterVersion: agent.adapterVersion,
@@ -40523,6 +40611,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40523
40611
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40524
40612
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40525
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
+ );
40526
40632
  try {
40527
40633
  const resolved = await resolveSessionDirectories(
40528
40634
  directories,
@@ -40609,18 +40715,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40609
40715
  disposition: command.disposition,
40610
40716
  images: attachments.images,
40611
40717
  onActivity: activities.record,
40612
- onText: (text3, messageId) => {
40613
- publisher.recordAttempt(
40614
- command.sessionId,
40615
- encodeAgentMessageDeltaEvent({
40616
- commandId: command.commandId,
40617
- kind: AGENT_MESSAGE_DELTA_KIND,
40618
- messageId,
40619
- sessionId: command.sessionId,
40620
- text: text3
40621
- }),
40622
- attemptId
40623
- );
40718
+ onText: (delta, messageId) => {
40719
+ text3.record(messageId, delta);
40624
40720
  return Promise.resolve();
40625
40721
  },
40626
40722
  prompt: command.prompt,
@@ -40631,6 +40727,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40631
40727
  });
40632
40728
  stopReason = result.stopReason;
40633
40729
  }
40730
+ text3.flush();
40634
40731
  activities.flush();
40635
40732
  publisher.recordAttempt(
40636
40733
  command.sessionId,
@@ -40649,6 +40746,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40649
40746
  sessionId: command.sessionId
40650
40747
  });
40651
40748
  } catch (error62) {
40749
+ text3.flush();
40652
40750
  activities.flush();
40653
40751
  audit.record({
40654
40752
  commandId: command.commandId,
@@ -40712,17 +40810,6 @@ function assertSessionConfigurationSchema(options, selections) {
40712
40810
  }
40713
40811
  }
40714
40812
  }
40715
- function assertSessionConfigurationCoverage(options, selections) {
40716
- const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40717
- if (selectionsById.size !== selections.length) {
40718
- throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
40719
- }
40720
- for (const option of options) {
40721
- if (!selectionsById.has(option.id)) {
40722
- throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
40723
- }
40724
- }
40725
- }
40726
40813
  function sessionConfigurationSelectionIsAvailable(option, selection) {
40727
40814
  if (option.type !== selection.valueType) {
40728
40815
  return false;
@@ -40851,7 +40938,6 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
40851
40938
  });
40852
40939
  }
40853
40940
  async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40854
- assertSessionConfigurationCoverage(initialOptions, selections);
40855
40941
  let options = initialOptions;
40856
40942
  const orderedSelections = selections.toSorted((left, right) => {
40857
40943
  const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
@@ -41215,6 +41301,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41215
41301
  signal.addEventListener("abort", stop, { once: true });
41216
41302
  const handleClose = (event) => {
41217
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
+ }
41218
41308
  resolveConnection();
41219
41309
  };
41220
41310
  const handleError = (event) => {
@@ -41869,6 +41959,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41869
41959
  if (signal.aborted) {
41870
41960
  return;
41871
41961
  }
41962
+ if (error62 instanceof RuntimeRelayRevokedError) {
41963
+ throw error62;
41964
+ }
41872
41965
  diagnostics.connectionFailed(connectionEpoch, error62, "connection");
41873
41966
  }
41874
41967
  await waitForRelayRetry(signal, timer);