@moxt-ai/mobius 0.0.80 → 0.0.81

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
@@ -23235,6 +23235,97 @@ function openCodeManagedArchive(platform, architecture) {
23235
23235
  }
23236
23236
 
23237
23237
  // src/agent-catalog/agents/opencode-agent.ts
23238
+ var MODEL_DISCOVERY_TIMEOUT_MILLISECONDS = 3e3;
23239
+ var MODEL_DISCOVERY_OUTPUT_LIMIT_BYTES = 1024 * 1024;
23240
+ var MAXIMUM_MODEL_VALUES = 500;
23241
+ function containsControlCharacter(value) {
23242
+ return Array.from(value).some((character) => {
23243
+ const codePoint = character.codePointAt(0) ?? 0;
23244
+ return codePoint <= 31 || codePoint >= 127 && codePoint <= 159;
23245
+ });
23246
+ }
23247
+ async function discoverModelValues(agent, cwd, signal) {
23248
+ if (!await revalidateExecutable(agent.agentIdentity)) {
23249
+ throw new AcpExecutionError(
23250
+ "The local Agent runtime changed; restart Mobius before discovering settings",
23251
+ {},
23252
+ "agent_runtime_changed"
23253
+ );
23254
+ }
23255
+ const acpArgumentIndex = agent.arguments.indexOf("acp");
23256
+ if (acpArgumentIndex < 0) {
23257
+ throw new AcpExecutionError(
23258
+ "OpenCode does not expose its model discovery command",
23259
+ {},
23260
+ "invalid_session_configuration"
23261
+ );
23262
+ }
23263
+ const result = await runBoundedProcess({
23264
+ arguments: [
23265
+ ...agent.arguments.slice(0, acpArgumentIndex),
23266
+ "models",
23267
+ ...agent.arguments.slice(acpArgumentIndex + 1)
23268
+ ],
23269
+ command: agent.command,
23270
+ cwd,
23271
+ environment: { ...process.env, ...agent.environment },
23272
+ outputLimitBytes: MODEL_DISCOVERY_OUTPUT_LIMIT_BYTES,
23273
+ signal,
23274
+ timeoutMilliseconds: MODEL_DISCOVERY_TIMEOUT_MILLISECONDS
23275
+ });
23276
+ const values = [];
23277
+ const identifiers = /* @__PURE__ */ new Set();
23278
+ for (const rawLine of result.stdout.split(/\r?\n/)) {
23279
+ const value = rawLine.trim();
23280
+ if (value.length === 0) {
23281
+ continue;
23282
+ }
23283
+ if (value.length > 512 || !/^[^\s/]+\/\S+$/.test(value) || containsControlCharacter(value)) {
23284
+ throw new AcpExecutionError(
23285
+ "OpenCode returned an invalid model catalog",
23286
+ {},
23287
+ "invalid_session_configuration"
23288
+ );
23289
+ }
23290
+ if (!identifiers.has(value)) {
23291
+ identifiers.add(value);
23292
+ values.push({ description: "", groupId: "", groupName: "", name: value, value });
23293
+ }
23294
+ if (values.length > MAXIMUM_MODEL_VALUES) {
23295
+ throw new AcpExecutionError("OpenCode returned too many models", {}, "invalid_session_configuration");
23296
+ }
23297
+ }
23298
+ return values;
23299
+ }
23300
+ function mergeModelValues(options, discovered) {
23301
+ if (discovered.length === 0) {
23302
+ return options;
23303
+ }
23304
+ return options.map((option) => {
23305
+ if (option.id !== "model" && option.category !== "model" || option.type !== "select") {
23306
+ return option;
23307
+ }
23308
+ const known = new Map(option.values.map((value) => [value.value, value]));
23309
+ const values = discovered.map((value) => known.get(value.value) ?? value);
23310
+ const identifiers = new Set(values.map((value) => value.value));
23311
+ for (const value of option.values) {
23312
+ if (values.length >= MAXIMUM_MODEL_VALUES) {
23313
+ break;
23314
+ }
23315
+ if (!identifiers.has(value.value)) {
23316
+ identifiers.add(value.value);
23317
+ values.push(value);
23318
+ }
23319
+ }
23320
+ return { ...option, values };
23321
+ });
23322
+ }
23323
+ async function discoverOpenCodeModelOptions(agent, cwd, options, signal) {
23324
+ if (agent.id !== "opencode" || agent.kind !== "acp-adapter-process") {
23325
+ return options;
23326
+ }
23327
+ return mergeModelValues(options, await discoverModelValues(agent, cwd, signal));
23328
+ }
23238
23329
  var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
23239
23330
  versionProbeTimeoutMilliseconds = 15e3;
23240
23331
  adapterVersion = OPENCODE_MANAGED_VERSION;
@@ -41790,39 +41881,26 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
41790
41881
  }
41791
41882
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
41792
41883
  }
41793
- var OPENCODE_PROVIDER_SETTLEMENT_MILLISECONDS = 1e3;
41794
- async function waitForAgentSettingsReadiness(agentId, signal, timer) {
41795
- if (agentId !== "opencode") {
41796
- return;
41797
- }
41798
- signal.throwIfAborted();
41799
- await new Promise((resolve8) => {
41800
- const readiness = timer.schedule(finish, OPENCODE_PROVIDER_SETTLEMENT_MILLISECONDS);
41801
- function finish() {
41802
- readiness.cancel();
41803
- signal.removeEventListener("abort", finish);
41804
- resolve8();
41805
- }
41806
- signal.addEventListener("abort", finish, { once: true });
41807
- });
41808
- signal.throwIfAborted();
41809
- }
41810
41884
  function isUnavailableModel(cause, modelSettingId, requestedModel) {
41811
41885
  return cause instanceof AcpConfigurationValueUnavailableError && cause.configId === modelSettingId && cause.requestedValue === requestedModel;
41812
41886
  }
41813
41887
  function unsupportedModelIds(unsupportedModels) {
41814
41888
  return [...new Set(unsupportedModels.map((item) => item.requestedValue))];
41815
41889
  }
41816
- async function discoverAgentSettings(command, config2, directories, sessions, signal, timer) {
41890
+ async function discoverAgentSettings(command, config2, directories, sessions, signal) {
41817
41891
  const agent = config2.catalog.find(command.agentId);
41818
41892
  const cwd = await directories.resolve(config2.bindingId, "default", signal);
41819
- await waitForAgentSettingsReadiness(agent.id, signal, timer);
41820
- const baseSnapshot = await sessions.inspectAgentSettings({
41893
+ const inspectedBaseSnapshot = await sessions.inspectAgentSettings({
41821
41894
  additionalDirectories: [],
41822
41895
  agent,
41823
41896
  cwd,
41824
41897
  signal
41825
41898
  });
41899
+ const baseSnapshot = {
41900
+ agentName: inspectedBaseSnapshot.agentName,
41901
+ agentVersion: inspectedBaseSnapshot.agentVersion,
41902
+ configOptions: await discoverOpenCodeModelOptions(agent, cwd, inspectedBaseSnapshot.configOptions, signal)
41903
+ };
41826
41904
  const baseModel = modelOption(baseSnapshot.configOptions);
41827
41905
  const unsupportedModels = [];
41828
41906
  let selectedSnapshot = baseSnapshot;
@@ -43273,8 +43351,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
43273
43351
  config2,
43274
43352
  directories,
43275
43353
  sessions,
43276
- operationSignal,
43277
- timer
43354
+ operationSignal
43278
43355
  );
43279
43356
  for (const diagnostic of result.unsupportedModels) {
43280
43357
  const details = agentSettingsFailureDetails(command2.agentId, diagnostic);