@moxt-ai/mobius 0.0.55 → 0.0.57

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/runtime.js CHANGED
@@ -22572,6 +22572,9 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
22572
22572
  var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
22573
22573
  var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
22574
22574
  var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
22575
+ var AGENT_CATALOG_REFRESH_KIND = "agent.catalog.refresh";
22576
+ var AGENT_CATALOG_REFRESHED_KIND = "agent.catalog.refreshed";
22577
+ var AGENT_CATALOG_REFRESH_FAILED_KIND = "agent.catalog.refresh.failed";
22575
22578
  var FILE_READ_KIND = "file.read";
22576
22579
  var FILE_BEGIN_KIND = "file.begin";
22577
22580
  var FILE_CHUNK_KIND = "file.chunk";
@@ -22687,6 +22690,20 @@ var agentSettingsDiscoveryFailedEventSchema = external_exports.strictObject({
22687
22690
  message: external_exports.string().min(1).max(500),
22688
22691
  requestId: IDENTIFIER
22689
22692
  }).readonly();
22693
+ var agentCatalogRefreshCommandSchema = external_exports.strictObject({
22694
+ kind: external_exports.literal(AGENT_CATALOG_REFRESH_KIND),
22695
+ requestId: IDENTIFIER
22696
+ }).readonly();
22697
+ var agentCatalogRefreshedEventSchema = external_exports.strictObject({
22698
+ kind: external_exports.literal(AGENT_CATALOG_REFRESHED_KIND),
22699
+ requestId: IDENTIFIER
22700
+ }).readonly();
22701
+ var agentCatalogRefreshFailedEventSchema = external_exports.strictObject({
22702
+ code: IDENTIFIER,
22703
+ kind: external_exports.literal(AGENT_CATALOG_REFRESH_FAILED_KIND),
22704
+ message: external_exports.string().min(1).max(500),
22705
+ requestId: IDENTIFIER
22706
+ }).readonly();
22690
22707
  var sessionConfigurationSelectionSchema = external_exports.strictObject({
22691
22708
  booleanValue: external_exports.boolean(),
22692
22709
  configId: IDENTIFIER,
@@ -23088,6 +23105,9 @@ var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
23088
23105
  var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
23089
23106
  var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
23090
23107
  var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
23108
+ var decodeAgentCatalogRefreshCommand = (encoded) => decode3(encoded, agentCatalogRefreshCommandSchema);
23109
+ var encodeAgentCatalogRefreshedEvent = (message) => encode3(message, agentCatalogRefreshedEventSchema);
23110
+ var encodeAgentCatalogRefreshFailedEvent = (message) => encode3(message, agentCatalogRefreshFailedEventSchema);
23091
23111
  var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
23092
23112
  var encodeFileBeginEvent = (message) => encode3(message, fileBeginEventSchema);
23093
23113
  var encodeFileChunkEvent = (message) => encode3(message, fileChunkEventSchema);
@@ -23879,6 +23899,15 @@ var DaemonLocalContext = class {
23879
23899
  this.environment = Object.freeze({ ...environment, MOBIUS_STATE_DIRECTORY: this.stateDirectory });
23880
23900
  }
23881
23901
  };
23902
+ function withDaemonEnvironment(agent, environment) {
23903
+ const launchEnvironment = {};
23904
+ for (const [name, value] of Object.entries(environment)) {
23905
+ if (typeof value === "string") {
23906
+ launchEnvironment[name] = value;
23907
+ }
23908
+ }
23909
+ return agent.withEnvironment({ ...launchEnvironment, ...agent.environment });
23910
+ }
23882
23911
  var DaemonReconnectTarget = class {
23883
23912
  };
23884
23913
  var OpaqueDaemonReconnectTarget = class extends DaemonReconnectTarget {
@@ -23900,12 +23929,13 @@ var ChannelDaemonReconnectTarget = class extends DaemonReconnectTarget {
23900
23929
  }
23901
23930
  };
23902
23931
  function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = new ChannelDaemonReconnectTarget(connection.channelId)) {
23932
+ const daemonAgents = agents.map((agent) => withDaemonEnvironment(agent, localContext.environment));
23903
23933
  return {
23904
- agents,
23934
+ agents: daemonAgents,
23905
23935
  defaultWorkspace: connection.defaultWorkspace,
23906
23936
  auditDatabasePath: connection.auditDatabasePath,
23907
23937
  bindingId: "workspace",
23908
- catalog: new LocalAgentCatalog(agents, installableAgents),
23938
+ catalog: new LocalAgentCatalog(daemonAgents, installableAgents),
23909
23939
  channelId: connection.channelId,
23910
23940
  installableAgents,
23911
23941
  localContext,
@@ -36087,16 +36117,9 @@ var FixedInstallationExecutor = class {
36087
36117
  };
36088
36118
  const initialInventory = await discoverLocalAgentInventory({
36089
36119
  ...discoveryOptions,
36090
- specifications: this.#specifications
36120
+ specifications: [specification]
36091
36121
  });
36092
- const previous2 = this.#catalog.read();
36093
- this.#catalog.transition(initialInventory.readyAgents(), initialInventory.installable);
36094
- try {
36095
- await this.#publishCatalog(signal);
36096
- } catch (error62) {
36097
- this.#catalog.transition(previous2.agents, previous2.installableAgents);
36098
- throw error62;
36099
- }
36122
+ await this.#publishDiscoveredAgent(agentId, initialInventory, this.#environment, signal);
36100
36123
  const alreadyReady = initialInventory.available.find((candidate) => candidate.specification.id === agentId);
36101
36124
  if (alreadyReady instanceof AvailableAgent) {
36102
36125
  return;
@@ -36149,7 +36172,7 @@ var FixedInstallationExecutor = class {
36149
36172
  defaultWorkspace: this.#defaultWorkspace,
36150
36173
  environment,
36151
36174
  signal,
36152
- specifications: this.#specifications
36175
+ specifications: [specification]
36153
36176
  });
36154
36177
  const verified = inventory.available.find((candidate) => candidate.specification.id === agentId);
36155
36178
  if (verified instanceof AvailableAgent) {
@@ -36157,14 +36180,7 @@ var FixedInstallationExecutor = class {
36157
36180
  adapterVersion: verified.agent.adapterVersion,
36158
36181
  agentVersion: verified.agent.agentVersion
36159
36182
  });
36160
- const previousCatalog = this.#catalog.read();
36161
- this.#catalog.transition(inventory.readyAgents(), inventory.installable);
36162
- try {
36163
- await this.#publishCatalog(signal);
36164
- } catch (error62) {
36165
- this.#catalog.transition(previousCatalog.agents, previousCatalog.installableAgents);
36166
- throw error62;
36167
- }
36183
+ await this.#publishDiscoveredAgent(agentId, inventory, environment, signal);
36168
36184
  return;
36169
36185
  }
36170
36186
  const unavailable = inventory.unavailable.find((candidate) => candidate.specification.id === agentId);
@@ -36192,6 +36208,22 @@ var FixedInstallationExecutor = class {
36192
36208
  throw translateExecutionError(error62);
36193
36209
  }
36194
36210
  };
36211
+ #publishDiscoveredAgent = async (agentId, inventory, environment, signal) => {
36212
+ const previous2 = this.#catalog.read();
36213
+ this.#catalog.transition(
36214
+ [
36215
+ ...previous2.agents.filter((agent) => agent.id !== agentId),
36216
+ ...inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment))
36217
+ ],
36218
+ [...previous2.installableAgents.filter((agent) => agent.id !== agentId), ...inventory.installable]
36219
+ );
36220
+ try {
36221
+ await this.#publishCatalog(signal);
36222
+ } catch (error62) {
36223
+ this.#catalog.transition(previous2.agents, previous2.installableAgents);
36224
+ throw error62;
36225
+ }
36226
+ };
36195
36227
  };
36196
36228
 
36197
36229
  // src/artifacts/local-file-streamer.ts
@@ -39418,8 +39450,19 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, s
39418
39450
  }
39419
39451
  const selectedEffort2 = effortOption(selectedOptions);
39420
39452
  valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
39453
+ return {
39454
+ effortSettingId: selectedEffort2?.id ?? "",
39455
+ modelSettingId: model.id,
39456
+ resolution: "on_model_selection",
39457
+ valuesByModel
39458
+ };
39459
+ }
39460
+ const defaultModel = model.type === "select" ? model.currentValue : "";
39461
+ const reportedEffort = effortOption(selectedOptions);
39462
+ const selectedEffort = defaultModel.length > 0 && reportedEffort === void 0 ? effortOption(await inspectModel(defaultModel)) : reportedEffort;
39463
+ if (defaultModel.length > 0) {
39464
+ valuesByModel[defaultModel] = selectedEffort?.type === "select" ? selectedEffort.values : [];
39421
39465
  }
39422
- const selectedEffort = effortOption(selectedOptions);
39423
39466
  return {
39424
39467
  effortSettingId: selectedEffort?.id ?? "",
39425
39468
  modelSettingId: model.id,
@@ -40028,7 +40071,28 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
40028
40071
  );
40029
40072
  }
40030
40073
  }
40031
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
40074
+ async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
40075
+ signal.throwIfAborted();
40076
+ const environment = await resolveEnvironment(signal);
40077
+ signal.throwIfAborted();
40078
+ const inventory = await discoverLocalAgentInventory({
40079
+ defaultWorkspace: config2.defaultWorkspace,
40080
+ environment,
40081
+ signal
40082
+ });
40083
+ const previousCatalog = config2.catalog.read();
40084
+ config2.catalog.transition(
40085
+ inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment)),
40086
+ inventory.installable
40087
+ );
40088
+ try {
40089
+ await publishAgentCatalog(config2, signal);
40090
+ } catch (error62) {
40091
+ config2.catalog.transition(previousCatalog.agents, previousCatalog.installableAgents);
40092
+ throw error62;
40093
+ }
40094
+ }
40095
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer, resolveAgentCatalogEnvironment) {
40032
40096
  const relayUrl = new URL(config2.relayUrl);
40033
40097
  relayUrl.searchParams.set("deliveryReceipts", "1");
40034
40098
  relayUrl.searchParams.set("liveness", "1");
@@ -40038,6 +40102,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40038
40102
  const connectionController = new AbortController();
40039
40103
  const nativeRequests = /* @__PURE__ */ new Map();
40040
40104
  const agentSettingsDiscoveries = /* @__PURE__ */ new Map();
40105
+ const agentCatalogRefreshes = /* @__PURE__ */ new Map();
40041
40106
  installationObserver.connect(socket);
40042
40107
  onConnected();
40043
40108
  try {
@@ -40489,6 +40554,82 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40489
40554
  });
40490
40555
  return;
40491
40556
  }
40557
+ if (kind === AGENT_CATALOG_REFRESH_KIND) {
40558
+ const command2 = decodeAgentCatalogRefreshCommand(encoded);
40559
+ if (agentCatalogRefreshes.has(command2.requestId) || agentCatalogRefreshes.size > 0) {
40560
+ if (socket.readyState === WebSocket2.OPEN) {
40561
+ send(
40562
+ socket,
40563
+ encodeAgentCatalogRefreshFailedEvent({
40564
+ code: "agent_catalog_refresh_busy",
40565
+ kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
40566
+ message: "Another local Agent catalog refresh is already running",
40567
+ requestId: command2.requestId
40568
+ })
40569
+ );
40570
+ }
40571
+ return;
40572
+ }
40573
+ const controller = new AbortController();
40574
+ const operationSignal = AbortSignal.any([connectionController.signal, controller.signal]);
40575
+ const timeout = timer.schedule(
40576
+ () => controller.abort(
40577
+ new AcpExecutionError(
40578
+ "The local Agent catalog refresh timed out",
40579
+ {},
40580
+ "agent_catalog_refresh_timeout"
40581
+ )
40582
+ ),
40583
+ 9e4
40584
+ );
40585
+ const completion = (async () => {
40586
+ try {
40587
+ await refreshAgentCatalog(config2, resolveAgentCatalogEnvironment, operationSignal);
40588
+ audit.record({
40589
+ commandId: command2.requestId,
40590
+ event: "agent_catalog_refreshed",
40591
+ sessionId: "agent-catalog"
40592
+ });
40593
+ if (socket.readyState === WebSocket2.OPEN) {
40594
+ send(
40595
+ socket,
40596
+ encodeAgentCatalogRefreshedEvent({
40597
+ kind: AGENT_CATALOG_REFRESHED_KIND,
40598
+ requestId: command2.requestId
40599
+ })
40600
+ );
40601
+ }
40602
+ } catch (error62) {
40603
+ const failure2 = operationSignal.aborted ? controller.signal.reason ?? new AcpExecutionError(
40604
+ "The local Agent catalog refresh was cancelled",
40605
+ {},
40606
+ "agent_catalog_refresh_cancelled"
40607
+ ) : error62;
40608
+ audit.record({
40609
+ commandId: command2.requestId,
40610
+ details: { code: operationErrorCode(failure2) },
40611
+ event: "agent_catalog_refresh_failed",
40612
+ sessionId: "agent-catalog"
40613
+ });
40614
+ if (socket.readyState === WebSocket2.OPEN) {
40615
+ send(
40616
+ socket,
40617
+ encodeAgentCatalogRefreshFailedEvent({
40618
+ code: operationErrorCode(failure2),
40619
+ kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
40620
+ message: operationErrorMessage(failure2),
40621
+ requestId: command2.requestId
40622
+ })
40623
+ );
40624
+ }
40625
+ } finally {
40626
+ timeout.cancel();
40627
+ agentCatalogRefreshes.delete(command2.requestId);
40628
+ }
40629
+ })();
40630
+ agentCatalogRefreshes.set(command2.requestId, { completion, controller });
40631
+ return;
40632
+ }
40492
40633
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
40493
40634
  const command2 = decodeNativeSessionCommand(encoded);
40494
40635
  const previous2 = [...nativeRequests.values()].filter(
@@ -40860,11 +41001,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40860
41001
  connectionController.abort();
40861
41002
  await Promise.all([
40862
41003
  ...[...nativeRequests.values()].map((request) => request.completion),
40863
- ...[...agentSettingsDiscoveries.values()].map((request) => request.completion)
41004
+ ...[...agentSettingsDiscoveries.values()].map((request) => request.completion),
41005
+ ...[...agentCatalogRefreshes.values()].map((request) => request.completion)
40864
41006
  ]);
40865
41007
  }
40866
41008
  }
40867
- async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41009
+ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, options = {}) {
40868
41010
  const installationAudit = new AuditInstallationEvents(audit);
40869
41011
  const stateDirectory = config2.localContext.stateDirectory;
40870
41012
  const specifications = supportedLocalAgentSpecifications();
@@ -40906,6 +41048,10 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
40906
41048
  let connectionAnnounced = false;
40907
41049
  let catalogPublished = false;
40908
41050
  let readinessAnnounced = false;
41051
+ const resolveAgentCatalogEnvironment = options.resolveAgentCatalogEnvironment ?? (async (catalogSignal) => {
41052
+ catalogSignal.throwIfAborted();
41053
+ return config2.localContext.environment;
41054
+ });
40909
41055
  const startAutomaticIntegrationProvisioning = () => {
40910
41056
  if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
40911
41057
  return;
@@ -40971,7 +41117,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
40971
41117
  diagnostics,
40972
41118
  announceConnection,
40973
41119
  signal,
40974
- timer
41120
+ timer,
41121
+ resolveAgentCatalogEnvironment
40975
41122
  );
40976
41123
  } catch (error62) {
40977
41124
  if (signal.aborted) {
@@ -41897,10 +42044,12 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
41897
42044
  }
41898
42045
  var MobiusRuntimeEngine = class {
41899
42046
  #config;
42047
+ #options;
41900
42048
  #state = new IdleMobiusRuntimeState();
41901
- constructor(config2) {
42049
+ constructor(config2, options = {}) {
41902
42050
  validateRuntimeConfiguration(config2);
41903
42051
  this.#config = config2;
42052
+ this.#options = options;
41904
42053
  }
41905
42054
  run = async (signal) => {
41906
42055
  if (!(this.#state instanceof IdleMobiusRuntimeState)) {
@@ -41910,7 +42059,9 @@ var MobiusRuntimeEngine = class {
41910
42059
  this.#state = new RunningMobiusRuntimeState();
41911
42060
  const audit = new AuditStore(this.#config.auditDatabasePath);
41912
42061
  try {
41913
- await runDaemon(this.#config, audit, signal);
42062
+ await runDaemon(this.#config, audit, signal, void 0, {
42063
+ ...this.#options.resolveAgentCatalogEnvironment === void 0 ? {} : { resolveAgentCatalogEnvironment: this.#options.resolveAgentCatalogEnvironment }
42064
+ });
41914
42065
  } finally {
41915
42066
  audit.close();
41916
42067
  this.#state = new FinishedMobiusRuntimeState();