@moxt-ai/mobius 0.0.44 → 0.0.45

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
@@ -21071,6 +21071,7 @@ function decodeMessageKind(encoded) {
21071
21071
  }
21072
21072
  function decodeSessionPromptCommand(encoded) {
21073
21073
  const value = parseJson2(encoded);
21074
+ const hasSessionConfigurations = Object.hasOwn(value, "sessionConfigurations");
21074
21075
  assertExactKeys(value, [
21075
21076
  "additionalDirectoryIds",
21076
21077
  "agentId",
@@ -21082,6 +21083,7 @@ function decodeSessionPromptCommand(encoded) {
21082
21083
  "kind",
21083
21084
  "prompt",
21084
21085
  "resources",
21086
+ ...hasSessionConfigurations ? ["sessionConfigurations"] : [],
21085
21087
  "sessionId",
21086
21088
  "targetCommandId"
21087
21089
  ]);
@@ -21102,6 +21104,10 @@ function decodeSessionPromptCommand(encoded) {
21102
21104
  if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN2.test(targetCommandId)) {
21103
21105
  throw new ProtocolMessageError("Prompt disposition has an invalid target command");
21104
21106
  }
21107
+ const sessionConfigurations = hasSessionConfigurations ? decodeSessionConfigurationSelections(value["sessionConfigurations"]) : [];
21108
+ if (new Set(sessionConfigurations.map((selection) => selection.configId)).size !== sessionConfigurations.length) {
21109
+ throw new ProtocolMessageError("Session configuration identifiers must be unique");
21110
+ }
21105
21111
  return {
21106
21112
  additionalDirectoryIds: readDirectoryIdentifiers(value, "additionalDirectoryIds", 16),
21107
21113
  agentId: readIdentifier(value, "agentId"),
@@ -21113,6 +21119,7 @@ function decodeSessionPromptCommand(encoded) {
21113
21119
  kind: SESSION_PROMPT_KIND,
21114
21120
  prompt,
21115
21121
  resources,
21122
+ ...hasSessionConfigurations ? { sessionConfigurations } : {},
21116
21123
  sessionId: readIdentifier(value, "sessionId"),
21117
21124
  targetCommandId
21118
21125
  };
@@ -36026,7 +36033,8 @@ async function publishAgentCatalog(config2, signal) {
36026
36033
  botSessionConfiguration: true,
36027
36034
  capabilities: agent.capabilities,
36028
36035
  id: agent.id,
36029
- label: agent.label
36036
+ label: agent.label,
36037
+ sessionTurnConfiguration: true
36030
36038
  })),
36031
36039
  installableAgents: catalog.installableAgents
36032
36040
  }),
@@ -36752,13 +36760,6 @@ var UploadedRuntimeArtifact = class {
36752
36760
  this.sha256 = sha256;
36753
36761
  }
36754
36762
  };
36755
- function daemonToken(config2) {
36756
- const token = config2.relayUrl.searchParams.get("token");
36757
- if (token === null || token.length < 32) {
36758
- throw new RuntimeArtifactUploadError("artifact_endpoint_invalid", "The Relay daemon token is missing");
36759
- }
36760
- return token;
36761
- }
36762
36763
  function channelOrigin(config2) {
36763
36764
  const url2 = new URL(config2.relayUrl);
36764
36765
  url2.protocol = url2.protocol === "wss:" ? "https:" : "http:";
@@ -36803,24 +36804,23 @@ async function readAuthorization(response) {
36803
36804
  translateSdkError(cause);
36804
36805
  }
36805
36806
  }
36806
- function sessionArtifactUrl(origin, sessionId, resourcePath, token) {
36807
- const url2 = new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
36808
- url2.searchParams.set("token", token);
36809
- return url2;
36807
+ function sessionArtifactUrl(origin, sessionId, resourcePath) {
36808
+ return new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
36810
36809
  }
36811
- async function postLease(url2, request, signal) {
36810
+ async function postLease(url2, headers, request, signal) {
36812
36811
  return await fetch3(url2, {
36813
36812
  dispatcher: environmentProxyDispatcher,
36814
- headers: { "content-type": "application/json" },
36813
+ headers: { ...headers, "content-type": "application/json" },
36815
36814
  method: "POST",
36816
36815
  body: JSON.stringify(request),
36817
36816
  signal
36818
36817
  });
36819
36818
  }
36820
- async function putContent(url2, authorization, bytes, signal) {
36819
+ async function putContent(url2, headers, authorization, bytes, signal) {
36821
36820
  return await fetch3(url2, {
36822
36821
  dispatcher: environmentProxyDispatcher,
36823
36822
  headers: {
36823
+ ...headers,
36824
36824
  "content-type": authorization.mediaType,
36825
36825
  "x-mobius-upload-token": authorization.uploadToken
36826
36826
  },
@@ -36845,11 +36845,12 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
36845
36845
  const timeoutSignal = AbortSignal.timeout(UPLOAD_TIMEOUT_MILLISECONDS);
36846
36846
  const requestSignal = AbortSignal.any([signal, timeoutSignal]);
36847
36847
  const origin = channelOrigin(config2);
36848
- const token = daemonToken(config2);
36848
+ const headers = runtimeAuthorization(config2.relayUrl);
36849
36849
  let created;
36850
36850
  try {
36851
36851
  created = await postLease(
36852
- sessionArtifactUrl(origin, sessionId, "artifacts/uploads", token),
36852
+ sessionArtifactUrl(origin, sessionId, "artifacts/uploads"),
36853
+ headers,
36853
36854
  request,
36854
36855
  requestSignal
36855
36856
  );
@@ -36869,12 +36870,8 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
36869
36870
  let uploaded;
36870
36871
  try {
36871
36872
  uploaded = await putContent(
36872
- sessionArtifactUrl(
36873
- origin,
36874
- sessionId,
36875
- `artifacts/${encodeURIComponent(authorization.artifactId)}/content`,
36876
- token
36877
- ),
36873
+ sessionArtifactUrl(origin, sessionId, `artifacts/${encodeURIComponent(authorization.artifactId)}/content`),
36874
+ headers,
36878
36875
  authorization,
36879
36876
  artifact.bytes,
36880
36877
  requestSignal
@@ -37328,7 +37325,7 @@ function relayEndpoint(relayUrl, context, target) {
37328
37325
  endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
37329
37326
  return endpoint;
37330
37327
  }
37331
- function daemonToken2(relayUrl) {
37328
+ function daemonToken(relayUrl) {
37332
37329
  const token = relayUrl.searchParams.get("token") ?? "";
37333
37330
  if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
37334
37331
  throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
@@ -37483,7 +37480,7 @@ var BotOutboundIpcServer = class {
37483
37480
  response = await fetch4(relayEndpoint(this.#relayUrl, context, request.target), {
37484
37481
  body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
37485
37482
  headers: {
37486
- authorization: `Bearer ${daemonToken2(this.#relayUrl)}`,
37483
+ authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
37487
37484
  "content-type": "application/json",
37488
37485
  "x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
37489
37486
  },
@@ -40118,6 +40115,36 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40118
40115
  signal
40119
40116
  );
40120
40117
  const agent = config2.catalog.find(command.agentId);
40118
+ if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
40119
+ throw new AcpExecutionError(
40120
+ "The queued prompt target is unavailable",
40121
+ {},
40122
+ "prompt_queue_target_unavailable"
40123
+ );
40124
+ }
40125
+ if (command.sessionConfigurations !== void 0) {
40126
+ const prepared = await sessions.prepareExecutionSession({
40127
+ additionalDirectories: resolved.additionalDirectories,
40128
+ agent,
40129
+ cwd: resolved.cwd,
40130
+ sessionId: command.sessionId,
40131
+ signal
40132
+ });
40133
+ if (command.disposition === SessionPromptDisposition.Steer) {
40134
+ assertCompleteSessionConfiguration(prepared.configOptions, command.sessionConfigurations);
40135
+ } else {
40136
+ await applyCompleteSessionConfiguration(
40137
+ sessions,
40138
+ prepared.configOptions,
40139
+ command.sessionConfigurations,
40140
+ agent,
40141
+ resolved.cwd,
40142
+ resolved.additionalDirectories,
40143
+ command.sessionId,
40144
+ signal
40145
+ );
40146
+ }
40147
+ }
40121
40148
  audit.record({
40122
40149
  commandId: command.commandId,
40123
40150
  event: "session_authorized",
@@ -40152,13 +40179,6 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40152
40179
  });
40153
40180
  stopReason = "steered";
40154
40181
  } else {
40155
- if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
40156
- throw new AcpExecutionError(
40157
- "The queued prompt target is unavailable",
40158
- {},
40159
- "prompt_queue_target_unavailable"
40160
- );
40161
- }
40162
40182
  const result = await sessions.runPrompt({
40163
40183
  additionalDirectories: resolved.additionalDirectories,
40164
40184
  agent,
@@ -40225,6 +40245,113 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40225
40245
  console.error("Mobius daemon command failed", error62);
40226
40246
  }
40227
40247
  }
40248
+ function invalidSessionConfiguration(message) {
40249
+ return new AcpExecutionError(message, {}, "invalid_session_configuration");
40250
+ }
40251
+ function validateSessionConfigurationSelection(option, selection) {
40252
+ if (option.type !== selection.valueType) {
40253
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
40254
+ }
40255
+ if (option.type === "boolean") {
40256
+ if (selection.value.length > 0) {
40257
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40258
+ }
40259
+ return;
40260
+ }
40261
+ if (selection.booleanValue) {
40262
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40263
+ }
40264
+ if (!option.values.some((value) => value.value === selection.value)) {
40265
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
40266
+ }
40267
+ }
40268
+ function assertSessionConfigurationSchema(options, selections) {
40269
+ if (options.length !== selections.length) {
40270
+ throw invalidSessionConfiguration("The Turn configuration does not match the Agent settings schema");
40271
+ }
40272
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40273
+ if (selectionsById.size !== selections.length) {
40274
+ throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
40275
+ }
40276
+ for (const option of options) {
40277
+ const selection = selectionsById.get(option.id);
40278
+ if (selection === void 0 || selection.valueType !== option.type || option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
40279
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
40280
+ }
40281
+ }
40282
+ }
40283
+ function sessionConfigurationMatches(option, selection) {
40284
+ validateSessionConfigurationSelection(option, selection);
40285
+ return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
40286
+ }
40287
+ function sessionConfigurationPriority(selection, options) {
40288
+ if (selection.configId === "permission_mode") {
40289
+ return 0;
40290
+ }
40291
+ const option = options.find((candidate) => candidate.id === selection.configId);
40292
+ if (selection.configId === "model" || option?.category === "model") {
40293
+ return 1;
40294
+ }
40295
+ if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
40296
+ return 2;
40297
+ }
40298
+ if (option?.category === "model_config") {
40299
+ return 3;
40300
+ }
40301
+ return 4;
40302
+ }
40303
+ function assertCompleteSessionConfiguration(options, selections) {
40304
+ assertSessionConfigurationSchema(options, selections);
40305
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40306
+ for (const option of options) {
40307
+ const selection = selectionsById.get(option.id);
40308
+ if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
40309
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
40310
+ }
40311
+ }
40312
+ }
40313
+ async function applySessionConfigurationSelection(sessions, options, selection, agent, cwd, additionalDirectories, sessionId, signal) {
40314
+ const option = options.find((candidate) => candidate.id === selection.configId);
40315
+ if (option === void 0) {
40316
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
40317
+ }
40318
+ if (sessionConfigurationMatches(option, selection)) {
40319
+ return options;
40320
+ }
40321
+ return await sessions.configureSession({
40322
+ additionalDirectories,
40323
+ agent,
40324
+ booleanValue: selection.booleanValue,
40325
+ configId: selection.configId,
40326
+ cwd,
40327
+ requestId: `cfg_${randomUUID3()}`,
40328
+ sessionId,
40329
+ signal,
40330
+ value: selection.value,
40331
+ valueType: selection.valueType
40332
+ });
40333
+ }
40334
+ async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
40335
+ assertSessionConfigurationSchema(initialOptions, selections);
40336
+ let options = initialOptions;
40337
+ const orderedSelections = selections.toSorted((left, right) => {
40338
+ const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
40339
+ return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
40340
+ });
40341
+ for (const selection of orderedSelections) {
40342
+ options = await applySessionConfigurationSelection(
40343
+ sessions,
40344
+ options,
40345
+ selection,
40346
+ agent,
40347
+ cwd,
40348
+ additionalDirectories,
40349
+ sessionId,
40350
+ signal
40351
+ );
40352
+ }
40353
+ assertCompleteSessionConfiguration(options, selections);
40354
+ }
40228
40355
  function botExecutionAgent(agent, contextHandle, socketPath) {
40229
40356
  return new LocalAgentDefinition(
40230
40357
  agent.id,
@@ -41703,7 +41830,8 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
41703
41830
  botSessionConfiguration: true,
41704
41831
  capabilities: agent.capabilities,
41705
41832
  id: agent.id,
41706
- label: agent.label
41833
+ label: agent.label,
41834
+ sessionTurnConfiguration: true
41707
41835
  }));
41708
41836
  const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
41709
41837
  let response;