@moxt-ai/mobius 0.0.48 → 0.0.49

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.
Files changed (52) hide show
  1. package/dist/acp/session-manager.d.ts +2 -1
  2. package/dist/acp/session-manager.d.ts.map +1 -1
  3. package/dist/acp/session-manager.js +34 -11
  4. package/dist/acp/session-manager.js.map +1 -1
  5. package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
  6. package/dist/agent-catalog/publish-agent-catalog.js +0 -1
  7. package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
  8. package/dist/artifacts/local-file-streamer.d.ts +3 -0
  9. package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
  10. package/dist/artifacts/local-file-streamer.js +82 -0
  11. package/dist/artifacts/local-file-streamer.js.map +1 -0
  12. package/dist/authorization/local-raster.d.ts +4 -3
  13. package/dist/authorization/local-raster.d.ts.map +1 -1
  14. package/dist/authorization/local-raster.js +22 -12
  15. package/dist/authorization/local-raster.js.map +1 -1
  16. package/dist/cli.js +529 -1659
  17. package/dist/cli.js.map +4 -4
  18. package/dist/index.d.ts +0 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +569 -1690
  21. package/dist/index.js.map +4 -4
  22. package/dist/native-sessions/history-images.js +1 -1
  23. package/dist/native-sessions/history-images.js.map +1 -1
  24. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  25. package/dist/pairing/pair-local-machine.js +0 -1
  26. package/dist/pairing/pair-local-machine.js.map +1 -1
  27. package/dist/run-daemon.d.ts.map +1 -1
  28. package/dist/run-daemon.js +26 -270
  29. package/dist/run-daemon.js.map +1 -1
  30. package/dist/runtime.js +396 -1353
  31. package/dist/runtime.js.map +4 -4
  32. package/package.json +1 -1
  33. package/dist/bots/bot-context-applicator.d.ts +0 -14
  34. package/dist/bots/bot-context-applicator.d.ts.map +0 -1
  35. package/dist/bots/bot-context-applicator.js +0 -32
  36. package/dist/bots/bot-context-applicator.js.map +0 -1
  37. package/dist/bots/bot-execution-context.d.ts +0 -19
  38. package/dist/bots/bot-execution-context.d.ts.map +0 -1
  39. package/dist/bots/bot-execution-context.js +0 -75
  40. package/dist/bots/bot-execution-context.js.map +0 -1
  41. package/dist/bots/bot-message-command.d.ts +0 -6
  42. package/dist/bots/bot-message-command.d.ts.map +0 -1
  43. package/dist/bots/bot-message-command.js +0 -140
  44. package/dist/bots/bot-message-command.js.map +0 -1
  45. package/dist/bots/bot-outbound-ipc.d.ts +0 -12
  46. package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
  47. package/dist/bots/bot-outbound-ipc.js +0 -245
  48. package/dist/bots/bot-outbound-ipc.js.map +0 -1
  49. package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
  50. package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
  51. package/dist/bots/local-bot-execution-authorizer.js +0 -62
  52. package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/runtime.js CHANGED
@@ -5,8 +5,8 @@ var __export = (target, all2) => {
5
5
  };
6
6
 
7
7
  // src/runtime.ts
8
- import { mkdir as mkdir5, realpath as realpath9, stat as stat8 } from "node:fs/promises";
9
- import { dirname as dirname8, join as join18, resolve as resolve5 } from "node:path";
8
+ import { mkdir as mkdir4, realpath as realpath10, stat as stat9 } from "node:fs/promises";
9
+ import { dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
10
10
 
11
11
  // src/agent-catalog/local-agent.ts
12
12
  import { realpathSync, statSync } from "node:fs";
@@ -78,12 +78,12 @@ var ExecutableIdentity = class {
78
78
  realPath;
79
79
  requestedPath;
80
80
  size;
81
- constructor(requestedPath, realPath_, device, inode, size, changedAtMilliseconds) {
81
+ constructor(requestedPath2, realPath_, device, inode, size, changedAtMilliseconds) {
82
82
  this.changedAtMilliseconds = changedAtMilliseconds;
83
83
  this.device = device;
84
84
  this.inode = inode;
85
85
  this.realPath = realPath_;
86
- this.requestedPath = requestedPath;
86
+ this.requestedPath = requestedPath2;
87
87
  this.size = size;
88
88
  }
89
89
  matches = (candidate) => this.requestedPath === candidate.requestedPath && this.realPath === candidate.realPath && this.device === candidate.device && this.inode === candidate.inode && this.size === candidate.size && this.changedAtMilliseconds === candidate.changedAtMilliseconds;
@@ -123,8 +123,8 @@ function executableExtensions(executableName, environment, platform) {
123
123
  const extensions = configured.split(";").map((extension2) => extension2.trim()).filter((extension2) => extension2.length > 0).map((extension2) => extension2.startsWith(".") ? extension2 : `.${extension2}`);
124
124
  return extensions.length > 0 ? extensions : [".EXE"];
125
125
  }
126
- async function resolveExecutablePath(requestedPath, platform = process.platform) {
127
- const absoluteRequestedPath = resolve(requestedPath);
126
+ async function resolveExecutablePath(requestedPath2, platform = process.platform) {
127
+ const absoluteRequestedPath = resolve(requestedPath2);
128
128
  try {
129
129
  const resolvedPath = await realpath(absoluteRequestedPath);
130
130
  const metadata = await stat(resolvedPath);
@@ -157,8 +157,8 @@ async function findExecutableOnPath(executableName, environment, platform = proc
157
157
  continue;
158
158
  }
159
159
  for (const extension2 of extensions) {
160
- const requestedPath = resolve(join(entry, `${executableName}${extension2}`));
161
- const executable = await resolveExecutablePath(requestedPath, platform);
160
+ const requestedPath2 = resolve(join(entry, `${executableName}${extension2}`));
161
+ const executable = await resolveExecutablePath(requestedPath2, platform);
162
162
  if (executable !== null) {
163
163
  return executable;
164
164
  }
@@ -20364,6 +20364,11 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
20364
20364
  var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
20365
20365
  var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
20366
20366
  var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
20367
+ var FILE_READ_KIND = "file.read";
20368
+ var FILE_BEGIN_KIND = "file.begin";
20369
+ var FILE_CHUNK_KIND = "file.chunk";
20370
+ var FILE_END_KIND = "file.end";
20371
+ var FILE_FAILED_KIND = "file.failed";
20367
20372
  var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
20368
20373
  var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
20369
20374
  var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
@@ -20374,6 +20379,41 @@ var workspaceEntrySchema = external_exports.strictObject({
20374
20379
  directoryId: DIRECTORY_IDENTIFIER,
20375
20380
  name: external_exports.string().min(1).max(255)
20376
20381
  }).readonly();
20382
+ var fileReadCommandSchema = external_exports.strictObject({
20383
+ kind: external_exports.literal(FILE_READ_KIND),
20384
+ maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
20385
+ requestId: IDENTIFIER,
20386
+ sessionId: IDENTIFIER,
20387
+ path: external_exports.string().min(1).max(4096)
20388
+ }).readonly();
20389
+ var fileBeginEventSchema = external_exports.strictObject({
20390
+ byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
20391
+ kind: external_exports.literal(FILE_BEGIN_KIND),
20392
+ mediaType: external_exports.string().min(1).max(255),
20393
+ modifiedAt: external_exports.iso.datetime({ offset: true }),
20394
+ name: external_exports.string().min(1).max(500),
20395
+ requestId: IDENTIFIER,
20396
+ sessionId: IDENTIFIER
20397
+ }).readonly();
20398
+ var fileChunkEventSchema = external_exports.strictObject({
20399
+ data: external_exports.string().min(1).max(4e5),
20400
+ kind: external_exports.literal(FILE_CHUNK_KIND),
20401
+ requestId: IDENTIFIER,
20402
+ sequence: external_exports.number().int().nonnegative().max(1024),
20403
+ sessionId: IDENTIFIER
20404
+ }).readonly();
20405
+ var fileEndEventSchema = external_exports.strictObject({
20406
+ kind: external_exports.literal(FILE_END_KIND),
20407
+ requestId: IDENTIFIER,
20408
+ sessionId: IDENTIFIER
20409
+ }).readonly();
20410
+ var fileFailedEventSchema = external_exports.strictObject({
20411
+ code: IDENTIFIER,
20412
+ kind: external_exports.literal(FILE_FAILED_KIND),
20413
+ message: external_exports.string().min(1).max(500),
20414
+ requestId: IDENTIFIER,
20415
+ sessionId: IDENTIFIER
20416
+ }).readonly();
20377
20417
  var configValueSchema = external_exports.strictObject({
20378
20418
  description: SHORT_TEXT,
20379
20419
  groupId: external_exports.string().max(128),
@@ -20590,7 +20630,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
20590
20630
  kind: external_exports.literal(SESSION_PREPARE_KIND),
20591
20631
  requestId: IDENTIFIER,
20592
20632
  sessionState: external_exports.literal("provisioned").optional(),
20593
- /** @deprecated Reserved for the legacy Bot Agent-configuration endpoint. */
20633
+ /** Marks an inspection-only Session preparation. */
20594
20634
  transient: external_exports.boolean().optional()
20595
20635
  }).superRefine((command, context) => {
20596
20636
  if (command.transient === true && command.sessionState === "provisioned") {
@@ -20811,11 +20851,15 @@ var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisp
20811
20851
  var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
20812
20852
  var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
20813
20853
  var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
20814
- var decodeAgentExecutionConfiguration = (value) => decodeValue(value, agentExecutionConfigurationSchema);
20815
20854
  var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
20816
20855
  var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
20817
20856
  var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
20818
20857
  var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
20858
+ var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
20859
+ var encodeFileBeginEvent = (message) => encode3(message, fileBeginEventSchema);
20860
+ var encodeFileChunkEvent = (message) => encode3(message, fileChunkEventSchema);
20861
+ var encodeFileEndEvent = (message) => encode3(message, fileEndEventSchema);
20862
+ var encodeFileFailedEvent = (message) => encode3(message, fileFailedEventSchema);
20819
20863
  var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
20820
20864
  var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
20821
20865
  var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
@@ -21295,325 +21339,6 @@ function encodeSessionFailedEvent(message) {
21295
21339
  return JSON.stringify(decodeSessionFailedEvent(JSON.stringify(message)));
21296
21340
  }
21297
21341
 
21298
- // ../protocol/src/bot.ts
21299
- var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
21300
- var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21301
- var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
21302
- var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
21303
- var SHA256_PATTERN = /^[a-f0-9]{64}$/;
21304
- var MAX_INSTRUCTIONS_LENGTH = 1e5;
21305
- var BotDeliveryTargetReference = class {
21306
- alias;
21307
- deliveryTargetId;
21308
- constructor(alias, deliveryTargetId) {
21309
- this.alias = alias;
21310
- this.deliveryTargetId = deliveryTargetId;
21311
- }
21312
- };
21313
- var BotReplyRoute = class {
21314
- };
21315
- var OwnerBotReplyRoute = class extends BotReplyRoute {
21316
- kind = "owner";
21317
- };
21318
- var BotConnectionReplyRoute = class extends BotReplyRoute {
21319
- connectionId;
21320
- deliveryTargetId;
21321
- kind = "connection";
21322
- constructor(connectionId, deliveryTargetId) {
21323
- super();
21324
- this.connectionId = connectionId;
21325
- this.deliveryTargetId = deliveryTargetId;
21326
- }
21327
- };
21328
- var BotSessionPromptCommand = class {
21329
- additionalDirectoryIds;
21330
- agentId;
21331
- allowedDeliveryTargets;
21332
- behaviorDigest;
21333
- behaviorInstructions;
21334
- behaviorRevisionId;
21335
- bindingId;
21336
- bindingRevision;
21337
- botId;
21338
- commandId;
21339
- conversationId;
21340
- directoryId;
21341
- disposition;
21342
- executionCapabilityId;
21343
- executionCapabilitySecret;
21344
- executionDeadlineAt;
21345
- executionId;
21346
- executionConfiguration;
21347
- images;
21348
- kind = BOT_SESSION_PROMPT_KIND;
21349
- prompt;
21350
- replyRoute;
21351
- resources;
21352
- sessionConfigurations;
21353
- sessionId;
21354
- targetCommandId;
21355
- turnId;
21356
- constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, executionConfiguration, sessionConfigurations = [], disposition = SessionPromptDisposition.Reject, targetCommandId = "") {
21357
- this.sessionId = sessionId;
21358
- this.commandId = commandId;
21359
- this.agentId = agentId;
21360
- this.bindingId = bindingId;
21361
- this.directoryId = directoryId2;
21362
- this.disposition = disposition;
21363
- this.additionalDirectoryIds = Object.freeze([...additionalDirectoryIds]);
21364
- this.images = Object.freeze([...images]);
21365
- this.resources = Object.freeze([...resources]);
21366
- this.prompt = prompt;
21367
- this.executionId = executionId;
21368
- this.executionCapabilityId = executionCapabilityId;
21369
- this.executionCapabilitySecret = executionCapabilitySecret;
21370
- this.executionDeadlineAt = executionDeadlineAt;
21371
- this.botId = botId;
21372
- this.conversationId = conversationId;
21373
- this.turnId = turnId;
21374
- this.behaviorRevisionId = behaviorRevisionId;
21375
- this.bindingRevision = bindingRevision;
21376
- this.behaviorInstructions = behaviorInstructions;
21377
- this.behaviorDigest = behaviorDigest;
21378
- this.allowedDeliveryTargets = Object.freeze(
21379
- allowedDeliveryTargets.map(
21380
- (target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
21381
- )
21382
- );
21383
- this.replyRoute = replyRoute;
21384
- this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
21385
- this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
21386
- this.targetCommandId = targetCommandId;
21387
- }
21388
- toJSON() {
21389
- const { disposition, sessionConfigurations, targetCommandId, ...command } = this;
21390
- return {
21391
- ...command,
21392
- ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations },
21393
- ...disposition === SessionPromptDisposition.Reject ? {} : { disposition, targetCommandId }
21394
- };
21395
- }
21396
- };
21397
- function isRecord3(value) {
21398
- return typeof value === "object" && value !== null && !Array.isArray(value);
21399
- }
21400
- function parseJson3(encoded) {
21401
- let value;
21402
- try {
21403
- value = JSON.parse(encoded);
21404
- } catch (cause) {
21405
- throw new ProtocolMessageError("Message is not valid JSON", { cause });
21406
- }
21407
- if (!isRecord3(value)) {
21408
- throw new ProtocolMessageError("Message must be a JSON object");
21409
- }
21410
- return value;
21411
- }
21412
- function assertExactKeys2(value, expected) {
21413
- const keys = Object.keys(value);
21414
- if (keys.length !== expected.length || keys.some((key) => !expected.includes(key))) {
21415
- throw new ProtocolMessageError("Message fields do not match the Bot protocol");
21416
- }
21417
- }
21418
- function assertKeysWithOptional(value, expected, optional2) {
21419
- const keys = Object.keys(value);
21420
- if (keys.length < expected.length || keys.length > expected.length + optional2.length || expected.some((key) => !Object.hasOwn(value, key)) || keys.some((key) => !expected.includes(key) && !optional2.includes(key))) {
21421
- throw new ProtocolMessageError("Message fields do not match the Bot protocol");
21422
- }
21423
- }
21424
- function readText2(value, key, maximumLength, allowEmpty) {
21425
- const field = value[key];
21426
- if (typeof field !== "string" || field.length > maximumLength || !allowEmpty && field.length === 0) {
21427
- throw new ProtocolMessageError(`Invalid Bot protocol field: ${key}`);
21428
- }
21429
- return field;
21430
- }
21431
- function readIdentifier2(value, key) {
21432
- const field = readText2(value, key, 128, false);
21433
- if (!IDENTIFIER_PATTERN3.test(field)) {
21434
- throw new ProtocolMessageError(`Invalid Bot identifier field: ${key}`);
21435
- }
21436
- return field;
21437
- }
21438
- function readDirectoryIdentifier2(value, key) {
21439
- const field = readText2(value, key, 2048, false);
21440
- if (!DIRECTORY_IDENTIFIER_PATTERN3.test(field)) {
21441
- throw new ProtocolMessageError(`Invalid Bot directory field: ${key}`);
21442
- }
21443
- return field;
21444
- }
21445
- function readInteger(value, key) {
21446
- const field = value[key];
21447
- if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 1) {
21448
- throw new ProtocolMessageError(`Invalid Bot integer field: ${key}`);
21449
- }
21450
- return field;
21451
- }
21452
- function readTimestamp(value, key) {
21453
- const field = readText2(value, key, 64, false);
21454
- if (Number.isNaN(Date.parse(field))) {
21455
- throw new ProtocolMessageError(`Invalid Bot timestamp field: ${key}`);
21456
- }
21457
- return field;
21458
- }
21459
- function readDigest(value, key) {
21460
- const field = readText2(value, key, 64, false);
21461
- if (!SHA256_PATTERN.test(field)) {
21462
- throw new ProtocolMessageError(`Invalid Bot digest field: ${key}`);
21463
- }
21464
- return field;
21465
- }
21466
- function readToken(value, key) {
21467
- const field = readText2(value, key, 256, false);
21468
- if (!TOKEN_PATTERN.test(field)) {
21469
- throw new ProtocolMessageError(`Invalid Bot token field: ${key}`);
21470
- }
21471
- return field;
21472
- }
21473
- function readIdentifiers(value, key, maximumCount) {
21474
- const field = value[key];
21475
- if (!Array.isArray(field) || field.length > maximumCount) {
21476
- throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
21477
- }
21478
- const identifiers = [];
21479
- const unique = /* @__PURE__ */ new Set();
21480
- for (const candidate of field) {
21481
- if (typeof candidate !== "string" || !IDENTIFIER_PATTERN3.test(candidate) || unique.has(candidate)) {
21482
- throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
21483
- }
21484
- unique.add(candidate);
21485
- identifiers.push(candidate);
21486
- }
21487
- return Object.freeze(identifiers);
21488
- }
21489
- function readTargets(value, key) {
21490
- const field = value[key];
21491
- if (!Array.isArray(field) || field.length > 64) {
21492
- throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
21493
- }
21494
- const targets = [];
21495
- const identifiers = /* @__PURE__ */ new Set();
21496
- const aliases = /* @__PURE__ */ new Set();
21497
- for (const candidate of field) {
21498
- if (!isRecord3(candidate)) {
21499
- throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
21500
- }
21501
- assertExactKeys2(candidate, ["alias", "deliveryTargetId"]);
21502
- const alias = readIdentifier2(candidate, "alias");
21503
- const deliveryTargetId = readIdentifier2(candidate, "deliveryTargetId");
21504
- if (aliases.has(alias) || identifiers.has(deliveryTargetId)) {
21505
- throw new ProtocolMessageError(`Duplicate Bot delivery target: ${key}`);
21506
- }
21507
- aliases.add(alias);
21508
- identifiers.add(deliveryTargetId);
21509
- targets.push(new BotDeliveryTargetReference(alias, deliveryTargetId));
21510
- }
21511
- return Object.freeze(targets);
21512
- }
21513
- function readSessionConfigurations(value) {
21514
- if (!Object.hasOwn(value, "sessionConfigurations")) {
21515
- return [];
21516
- }
21517
- return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
21518
- }
21519
- function readReplyRoute(value) {
21520
- if (!isRecord3(value)) {
21521
- throw new ProtocolMessageError("Invalid Bot reply route");
21522
- }
21523
- const kind = readText2(value, "kind", 32, false);
21524
- if (kind === "owner") {
21525
- assertExactKeys2(value, ["kind"]);
21526
- return new OwnerBotReplyRoute();
21527
- }
21528
- if (kind === "connection") {
21529
- assertExactKeys2(value, ["connectionId", "deliveryTargetId", "kind"]);
21530
- return new BotConnectionReplyRoute(
21531
- readIdentifier2(value, "connectionId"),
21532
- readIdentifier2(value, "deliveryTargetId")
21533
- );
21534
- }
21535
- throw new ProtocolMessageError("Invalid Bot reply route");
21536
- }
21537
- function decodeBotSessionPromptCommand(encoded) {
21538
- const value = parseJson3(encoded);
21539
- assertKeysWithOptional(
21540
- value,
21541
- [
21542
- "additionalDirectoryIds",
21543
- "agentId",
21544
- "allowedDeliveryTargets",
21545
- "behaviorDigest",
21546
- "behaviorInstructions",
21547
- "behaviorRevisionId",
21548
- "bindingId",
21549
- "bindingRevision",
21550
- "botId",
21551
- "commandId",
21552
- "conversationId",
21553
- "directoryId",
21554
- "executionCapabilityId",
21555
- "executionCapabilitySecret",
21556
- "executionDeadlineAt",
21557
- "executionId",
21558
- "executionConfiguration",
21559
- "images",
21560
- "kind",
21561
- "prompt",
21562
- "replyRoute",
21563
- "resources",
21564
- "sessionId",
21565
- "turnId"
21566
- ],
21567
- ["disposition", "sessionConfigurations", "targetCommandId"]
21568
- );
21569
- if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
21570
- throw new ProtocolMessageError("Invalid Bot Session prompt kind");
21571
- }
21572
- const rawDisposition = value["disposition"];
21573
- let disposition;
21574
- if (rawDisposition === void 0 || rawDisposition === SessionPromptDisposition.Reject) {
21575
- disposition = SessionPromptDisposition.Reject;
21576
- } else if (rawDisposition === SessionPromptDisposition.Queue) {
21577
- disposition = SessionPromptDisposition.Queue;
21578
- } else if (rawDisposition === SessionPromptDisposition.Steer) {
21579
- disposition = SessionPromptDisposition.Steer;
21580
- } else {
21581
- throw new ProtocolMessageError("Invalid Bot Session prompt disposition");
21582
- }
21583
- const targetCommandId = value["targetCommandId"] === void 0 ? "" : readText2(value, "targetCommandId", 128, false);
21584
- if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN3.test(targetCommandId)) {
21585
- throw new ProtocolMessageError("Bot Session prompt disposition has an invalid target command");
21586
- }
21587
- return new BotSessionPromptCommand(
21588
- readIdentifier2(value, "sessionId"),
21589
- readIdentifier2(value, "commandId"),
21590
- readIdentifier2(value, "agentId"),
21591
- readIdentifier2(value, "bindingId"),
21592
- readDirectoryIdentifier2(value, "directoryId"),
21593
- readIdentifiers(value, "additionalDirectoryIds", 16),
21594
- decodePromptImagesValue(value["images"]),
21595
- decodePromptResourcesValue(value["resources"]),
21596
- readText2(value, "prompt", 1e4, false),
21597
- readIdentifier2(value, "executionId"),
21598
- readIdentifier2(value, "executionCapabilityId"),
21599
- readToken(value, "executionCapabilitySecret"),
21600
- readTimestamp(value, "executionDeadlineAt"),
21601
- readIdentifier2(value, "botId"),
21602
- readIdentifier2(value, "conversationId"),
21603
- readIdentifier2(value, "turnId"),
21604
- readIdentifier2(value, "behaviorRevisionId"),
21605
- readInteger(value, "bindingRevision"),
21606
- readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21607
- readDigest(value, "behaviorDigest"),
21608
- readTargets(value, "allowedDeliveryTargets"),
21609
- readReplyRoute(value["replyRoute"]),
21610
- decodeAgentExecutionConfiguration(value["executionConfiguration"]),
21611
- readSessionConfigurations(value),
21612
- disposition,
21613
- targetCommandId
21614
- );
21615
- }
21616
-
21617
21342
  // ../protocol/src/mobius-api.ts
21618
21343
  var MOBIUS_API_PREFIX = "/mobius/api";
21619
21344
  var API_PREFIX_PATTERN = /^\/[a-zA-Z0-9._~-]+(?:\/[a-zA-Z0-9._~-]+)*$/;
@@ -21826,13 +21551,13 @@ var SessionEventRejectionCode = {
21826
21551
  SessionNotFound: "session_not_found",
21827
21552
  SessionRejected: "session_rejected"
21828
21553
  };
21829
- var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21554
+ var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21830
21555
  var CURSOR_PATTERN = /^[A-Za-z0-9_-]{1,512}$/;
21831
21556
  var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
21832
21557
  var DECIMAL_SEQUENCE_PATTERN = /^(?:0|[1-9][0-9]*)$/;
21833
21558
  var eventSourceSchema = external_exports.discriminatedUnion("kind", [
21834
21559
  external_exports.strictObject({
21835
- attemptId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21560
+ attemptId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21836
21561
  kind: external_exports.literal("attempt"),
21837
21562
  sourceSeq: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN)
21838
21563
  }).readonly(),
@@ -21842,41 +21567,41 @@ var eventSourceSchema = external_exports.discriminatedUnion("kind", [
21842
21567
  }).readonly()
21843
21568
  ]);
21844
21569
  var eventEnvelopeSchema = external_exports.strictObject({
21845
- eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21570
+ eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21846
21571
  kind: external_exports.literal(SESSION_EVENT_KIND),
21847
21572
  payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
21848
- sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21573
+ sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21849
21574
  source: eventSourceSchema
21850
21575
  }).readonly();
21851
21576
  var committedEventSchema = external_exports.strictObject({
21852
21577
  cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
21853
- eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21578
+ eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21854
21579
  kind: external_exports.literal(SESSION_EVENT_COMMITTED_KIND),
21855
21580
  payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
21856
21581
  recordedAt: external_exports.string().datetime({ offset: true }),
21857
21582
  sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
21858
- sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21583
+ sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21859
21584
  source: eventSourceSchema
21860
21585
  }).readonly();
21861
21586
  var eventAcknowledgementSchema = external_exports.strictObject({
21862
21587
  cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
21863
21588
  duplicate: external_exports.boolean(),
21864
- eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21589
+ eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21865
21590
  kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
21866
21591
  sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
21867
- sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4)
21592
+ sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
21868
21593
  }).readonly();
21869
21594
  var eventDeferredSchema = external_exports.strictObject({
21870
- eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21595
+ eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21871
21596
  kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
21872
21597
  retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
21873
- sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4)
21598
+ sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
21874
21599
  }).readonly();
21875
21600
  var eventRejectionSchema = external_exports.strictObject({
21876
21601
  code: external_exports.enum(SessionEventRejectionCode),
21877
- eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4),
21602
+ eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
21878
21603
  kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
21879
- sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN4)
21604
+ sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
21880
21605
  }).readonly();
21881
21606
  function decode5(encoded, schema) {
21882
21607
  let value;
@@ -22391,7 +22116,7 @@ var ManagedNpmPackageError = class extends Error {
22391
22116
  this.name = "ManagedNpmPackageError";
22392
22117
  }
22393
22118
  };
22394
- function isRecord4(value) {
22119
+ function isRecord3(value) {
22395
22120
  return typeof value === "object" && value !== null && !Array.isArray(value);
22396
22121
  }
22397
22122
  function packagePath(root, packageName) {
@@ -22413,7 +22138,7 @@ async function readJsonRecord(path2, maximumBytes) {
22413
22138
  );
22414
22139
  }
22415
22140
  const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
22416
- if (!isRecord4(value)) {
22141
+ if (!isRecord3(value)) {
22417
22142
  throw new ManagedNpmPackageError(
22418
22143
  "managed_package_verification_failed",
22419
22144
  "The managed npm package metadata is invalid"
@@ -22439,7 +22164,7 @@ function readBinPath(packageMetadata, executableName) {
22439
22164
  if (typeof bin === "string") {
22440
22165
  return bin;
22441
22166
  }
22442
- if (isRecord4(bin) && typeof bin[executableName] === "string") {
22167
+ if (isRecord3(bin) && typeof bin[executableName] === "string") {
22443
22168
  return bin[executableName];
22444
22169
  }
22445
22170
  throw new ManagedNpmPackageError(
@@ -22455,7 +22180,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
22455
22180
  );
22456
22181
  }
22457
22182
  const packages = lock["packages"];
22458
- if (!isRecord4(packages)) {
22183
+ if (!isRecord3(packages)) {
22459
22184
  throw new ManagedNpmPackageError(
22460
22185
  "managed_package_verification_failed",
22461
22186
  "The managed npm package lockfile is invalid"
@@ -22469,7 +22194,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
22469
22194
  if (verifyDependencyClosure && normalizedKey.length > 0) {
22470
22195
  let resolved;
22471
22196
  try {
22472
- if (!normalizedKey.split("/").includes("node_modules") || !isRecord4(candidate) || typeof candidate["version"] !== "string" || candidate["version"].length === 0 || typeof candidate["integrity"] !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(candidate["integrity"]) || typeof candidate["resolved"] !== "string") {
22197
+ if (!normalizedKey.split("/").includes("node_modules") || !isRecord3(candidate) || typeof candidate["version"] !== "string" || candidate["version"].length === 0 || typeof candidate["integrity"] !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(candidate["integrity"]) || typeof candidate["resolved"] !== "string") {
22473
22198
  throw new Error("Invalid locked dependency");
22474
22199
  }
22475
22200
  resolved = new URL(candidate["resolved"]);
@@ -22492,7 +22217,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
22492
22217
  matches += 1;
22493
22218
  }
22494
22219
  }
22495
- if (matches !== 1 || !isRecord4(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
22220
+ if (matches !== 1 || !isRecord3(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
22496
22221
  throw new ManagedNpmPackageError(
22497
22222
  "managed_package_verification_failed",
22498
22223
  "The managed npm package lockfile does not match the pinned artifact"
@@ -23303,7 +23028,7 @@ var ManagedAgentArchiveError = class extends Error {
23303
23028
  this.name = "ManagedAgentArchiveError";
23304
23029
  }
23305
23030
  };
23306
- function isRecord5(value) {
23031
+ function isRecord4(value) {
23307
23032
  return typeof value === "object" && value !== null && !Array.isArray(value);
23308
23033
  }
23309
23034
  function isContainedPath3(root, candidate) {
@@ -23360,7 +23085,7 @@ async function readManifest(path2) {
23360
23085
  );
23361
23086
  }
23362
23087
  const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
23363
- if (!isRecord5(parsed)) {
23088
+ if (!isRecord4(parsed)) {
23364
23089
  throw new ManagedAgentArchiveError(
23365
23090
  "managed_archive_verification_failed",
23366
23091
  "The managed Agent archive manifest is invalid"
@@ -23673,8 +23398,8 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
23673
23398
  requestedPaths.unshift(join11(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
23674
23399
  }
23675
23400
  const executables = [];
23676
- for (const requestedPath of requestedPaths) {
23677
- const executable = await resolveExecutablePath(requestedPath, "darwin");
23401
+ for (const requestedPath2 of requestedPaths) {
23402
+ const executable = await resolveExecutablePath(requestedPath2, "darwin");
23678
23403
  context.signal.throwIfAborted();
23679
23404
  if (executable !== null) {
23680
23405
  executables.push(executable);
@@ -23762,41 +23487,41 @@ var DiscoveryAcpHandler = class {
23762
23487
  };
23763
23488
  function readableAcpStream(input2) {
23764
23489
  let byteLength = 0;
23765
- let open5 = true;
23490
+ let open6 = true;
23766
23491
  return new ReadableStream({
23767
23492
  start(controller) {
23768
23493
  input2.on("data", (chunk) => {
23769
- if (!open5) {
23494
+ if (!open6) {
23770
23495
  return;
23771
23496
  }
23772
23497
  if (!(chunk instanceof Uint8Array)) {
23773
- open5 = false;
23498
+ open6 = false;
23774
23499
  controller.error(new Error("ACP adapter produced invalid output"));
23775
23500
  return;
23776
23501
  }
23777
23502
  byteLength += chunk.byteLength;
23778
23503
  if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
23779
- open5 = false;
23504
+ open6 = false;
23780
23505
  controller.error(new Error("ACP adapter output limit exceeded"));
23781
23506
  return;
23782
23507
  }
23783
23508
  controller.enqueue(new Uint8Array(chunk));
23784
23509
  });
23785
23510
  input2.once("end", () => {
23786
- if (open5) {
23787
- open5 = false;
23511
+ if (open6) {
23512
+ open6 = false;
23788
23513
  controller.close();
23789
23514
  }
23790
23515
  });
23791
23516
  input2.once("error", (error62) => {
23792
- if (open5) {
23793
- open5 = false;
23517
+ if (open6) {
23518
+ open6 = false;
23794
23519
  controller.error(error62);
23795
23520
  }
23796
23521
  });
23797
23522
  },
23798
23523
  cancel() {
23799
- open5 = false;
23524
+ open6 = false;
23800
23525
  }
23801
23526
  });
23802
23527
  }
@@ -24067,7 +23792,7 @@ async function resolveAdapterExecutable(specification, context) {
24067
23792
  const executables = await resolveAdapterExecutables(specification, context);
24068
23793
  return executables[0] ?? null;
24069
23794
  }
24070
- async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize4 = normalizeVersionOutput) {
23795
+ async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize5 = normalizeVersionOutput) {
24071
23796
  const result = await runBoundedProcess({
24072
23797
  arguments: arguments_,
24073
23798
  command: executable.path,
@@ -24076,7 +23801,7 @@ async function probeVersion(executable, arguments_, environment, defaultWorkspac
24076
23801
  signal,
24077
23802
  timeoutMilliseconds
24078
23803
  });
24079
- const version2 = normalize4(result.stdout || result.stderr);
23804
+ const version2 = normalize5(result.stdout || result.stderr);
24080
23805
  if (version2.length === 0) {
24081
23806
  throw new ProcessExecutionError("process_exit_failed", "The executable did not report a version");
24082
23807
  }
@@ -24335,9 +24060,9 @@ function createDaemonConfig(connection, agents = [], installableAgents = []) {
24335
24060
 
24336
24061
  // src/run-daemon.ts
24337
24062
  import { randomUUID as randomUUID3 } from "node:crypto";
24338
- import { basename as basename5, join as join16 } from "node:path";
24063
+ import { basename as basename6 } from "node:path";
24339
24064
  import { styleText } from "node:util";
24340
- import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
24065
+ import { fetch as fetch5, WebSocket as WebSocket2 } from "undici";
24341
24066
 
24342
24067
  // src/acp/session-manager.ts
24343
24068
  import { spawn as spawn3 } from "node:child_process";
@@ -24349,10 +24074,11 @@ import {
24349
24074
  } from "@agentclientprotocol/sdk";
24350
24075
 
24351
24076
  // src/authorization/local-raster.ts
24352
- import { readFile as readFile2, realpath as realpath6, stat as stat5 } from "node:fs/promises";
24077
+ import { open as open4, readFile as readFile2, realpath as realpath6, stat as stat5 } from "node:fs/promises";
24353
24078
  import { basename, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
24354
24079
  import { fileURLToPath } from "node:url";
24355
- var MAX_LOCAL_RASTER_BYTES = 3e6;
24080
+ var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
24081
+ var MAX_INLINE_RASTER_BYTES = 3e6;
24356
24082
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
24357
24083
  var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
24358
24084
  var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
@@ -24363,12 +24089,17 @@ var LocalRasterImage = class {
24363
24089
  bytes;
24364
24090
  mimeType;
24365
24091
  name;
24366
- constructor(name, mimeType, bytes) {
24092
+ sourceUri;
24093
+ constructor(name, mimeType, bytes, sourceUri = "") {
24367
24094
  this.bytes = bytes;
24368
24095
  this.mimeType = mimeType;
24369
24096
  this.name = name;
24097
+ this.sourceUri = sourceUri;
24370
24098
  }
24371
- base64 = () => Buffer.from(this.bytes).toString("base64");
24099
+ base64 = async () => {
24100
+ const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
24101
+ return Buffer.from(bytes).toString("base64");
24102
+ };
24372
24103
  };
24373
24104
  function startsWith(bytes, signature, offset = 0) {
24374
24105
  if (bytes.byteLength < offset + signature.byteLength) {
@@ -24392,14 +24123,14 @@ function sniffRasterMime(bytes) {
24392
24123
  return null;
24393
24124
  }
24394
24125
  function readInlineRaster(data, name = "Image") {
24395
- if (data.length === 0 || data.length > Math.ceil(MAX_LOCAL_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
24126
+ if (data.length === 0 || data.length > Math.ceil(MAX_INLINE_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
24396
24127
  return null;
24397
24128
  }
24398
24129
  if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
24399
24130
  return null;
24400
24131
  }
24401
24132
  const bytes = new Uint8Array(Buffer.from(data, "base64"));
24402
- if (bytes.byteLength < 1 || bytes.byteLength > MAX_LOCAL_RASTER_BYTES) {
24133
+ if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
24403
24134
  return null;
24404
24135
  }
24405
24136
  const mimeType = sniffRasterMime(bytes);
@@ -24467,16 +24198,19 @@ async function readLocalRaster(uri, signal) {
24467
24198
  if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
24468
24199
  return null;
24469
24200
  }
24470
- const bytes = new Uint8Array(await readFile2(target));
24471
- signal.throwIfAborted();
24472
- if (bytes.byteLength < 1 || bytes.byteLength > MAX_LOCAL_RASTER_BYTES) {
24473
- return null;
24201
+ const handle = await open4(target, "r");
24202
+ const header = new Uint8Array(12);
24203
+ try {
24204
+ await handle.read(header, 0, header.byteLength, 0);
24205
+ } finally {
24206
+ await handle.close();
24474
24207
  }
24475
- const mimeType = sniffRasterMime(bytes);
24208
+ signal.throwIfAborted();
24209
+ const mimeType = sniffRasterMime(header);
24476
24210
  if (mimeType === null) {
24477
24211
  return null;
24478
24212
  }
24479
- return new LocalRasterImage(basename(target) || "Image", mimeType, bytes);
24213
+ return new LocalRasterImage(basename(target) || "Image", mimeType, null, target);
24480
24214
  }
24481
24215
 
24482
24216
  // src/authorization/local-video.ts
@@ -24602,7 +24336,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
24602
24336
  if (local === null) {
24603
24337
  return "[Image unavailable]";
24604
24338
  }
24605
- const data = local.base64();
24339
+ const data = await local.base64();
24606
24340
  if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
24607
24341
  return "[Image unavailable]";
24608
24342
  }
@@ -24638,7 +24372,7 @@ async function replaceImageMarkers(text3, replace) {
24638
24372
 
24639
24373
  // src/acp/activity.ts
24640
24374
  var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
24641
- function isRecord6(value) {
24375
+ function isRecord5(value) {
24642
24376
  return typeof value === "object" && value !== null && !Array.isArray(value);
24643
24377
  }
24644
24378
  var AcpActivity = class _AcpActivity {
@@ -24872,16 +24606,16 @@ async function normalizeToolContent(content3, prepareContent) {
24872
24606
  return normalized;
24873
24607
  }
24874
24608
  function rawMcpToolContent(rawOutput) {
24875
- if (!isRecord6(rawOutput)) {
24609
+ if (!isRecord5(rawOutput)) {
24876
24610
  return [];
24877
24611
  }
24878
- const result = isRecord6(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
24612
+ const result = isRecord5(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
24879
24613
  const content3 = result["content"];
24880
24614
  if (!Array.isArray(content3)) {
24881
24615
  return [];
24882
24616
  }
24883
24617
  return content3.flatMap((item) => {
24884
- if (!isRecord6(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
24618
+ if (!isRecord5(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
24885
24619
  return [];
24886
24620
  }
24887
24621
  const uri = item["uri"];
@@ -24958,7 +24692,7 @@ function contentPhase(content3) {
24958
24692
  return "";
24959
24693
  }
24960
24694
  const codex = metadata["codex"];
24961
- if (!isRecord6(codex)) {
24695
+ if (!isRecord5(codex)) {
24962
24696
  return "";
24963
24697
  }
24964
24698
  const phase = codex["phase"];
@@ -27762,7 +27496,7 @@ var attention = {
27762
27496
  };
27763
27497
  function resolveAllAttention(events, context) {
27764
27498
  let index2 = -1;
27765
- let open5;
27499
+ let open6;
27766
27500
  let group;
27767
27501
  let text3;
27768
27502
  let openingSequence;
@@ -27772,16 +27506,16 @@ function resolveAllAttention(events, context) {
27772
27506
  let offset;
27773
27507
  while (++index2 < events.length) {
27774
27508
  if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
27775
- open5 = index2;
27776
- while (open5--) {
27777
- if (events[open5][0] === "exit" && events[open5][1].type === "attentionSequence" && events[open5][1]._open && // If the markers are the same:
27778
- context.sliceSerialize(events[open5][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
27779
- if ((events[open5][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open5][1].end.offset - events[open5][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
27509
+ open6 = index2;
27510
+ while (open6--) {
27511
+ if (events[open6][0] === "exit" && events[open6][1].type === "attentionSequence" && events[open6][1]._open && // If the markers are the same:
27512
+ context.sliceSerialize(events[open6][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
27513
+ if ((events[open6][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open6][1].end.offset - events[open6][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
27780
27514
  continue;
27781
27515
  }
27782
- use = events[open5][1].end.offset - events[open5][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
27516
+ use = events[open6][1].end.offset - events[open6][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
27783
27517
  const start = {
27784
- ...events[open5][1].end
27518
+ ...events[open6][1].end
27785
27519
  };
27786
27520
  const end = {
27787
27521
  ...events[index2][1].start
@@ -27792,7 +27526,7 @@ function resolveAllAttention(events, context) {
27792
27526
  type: use > 1 ? "strongSequence" : "emphasisSequence",
27793
27527
  start,
27794
27528
  end: {
27795
- ...events[open5][1].end
27529
+ ...events[open6][1].end
27796
27530
  }
27797
27531
  };
27798
27532
  closingSequence = {
@@ -27805,7 +27539,7 @@ function resolveAllAttention(events, context) {
27805
27539
  text3 = {
27806
27540
  type: use > 1 ? "strongText" : "emphasisText",
27807
27541
  start: {
27808
- ...events[open5][1].end
27542
+ ...events[open6][1].end
27809
27543
  },
27810
27544
  end: {
27811
27545
  ...events[index2][1].start
@@ -27820,18 +27554,18 @@ function resolveAllAttention(events, context) {
27820
27554
  ...closingSequence.end
27821
27555
  }
27822
27556
  };
27823
- events[open5][1].end = {
27557
+ events[open6][1].end = {
27824
27558
  ...openingSequence.start
27825
27559
  };
27826
27560
  events[index2][1].start = {
27827
27561
  ...closingSequence.end
27828
27562
  };
27829
27563
  nextEvents = [];
27830
- if (events[open5][1].end.offset - events[open5][1].start.offset) {
27831
- nextEvents = push(nextEvents, [["enter", events[open5][1], context], ["exit", events[open5][1], context]]);
27564
+ if (events[open6][1].end.offset - events[open6][1].start.offset) {
27565
+ nextEvents = push(nextEvents, [["enter", events[open6][1], context], ["exit", events[open6][1], context]]);
27832
27566
  }
27833
27567
  nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
27834
- nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open5 + 1, index2), context));
27568
+ nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + 1, index2), context));
27835
27569
  nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
27836
27570
  if (events[index2][1].end.offset - events[index2][1].start.offset) {
27837
27571
  offset = 2;
@@ -27839,8 +27573,8 @@ function resolveAllAttention(events, context) {
27839
27573
  } else {
27840
27574
  offset = 0;
27841
27575
  }
27842
- splice(events, open5 - 1, index2 - open5 + 3, nextEvents);
27843
- index2 = open5 + nextEvents.length - offset - 2;
27576
+ splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
27577
+ index2 = open6 + nextEvents.length - offset - 2;
27844
27578
  break;
27845
27579
  }
27846
27580
  }
@@ -27872,10 +27606,10 @@ function tokenizeAttention(effects, ok2) {
27872
27606
  }
27873
27607
  const token = effects.exit("attentionSequence");
27874
27608
  const after = classifyCharacter(code);
27875
- const open5 = !after || after === 2 && before || attentionMarkers2.includes(code);
27609
+ const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
27876
27610
  const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
27877
- token._open = Boolean(marker === 42 ? open5 : open5 && (before || !close));
27878
- token._close = Boolean(marker === 42 ? close : close && (after || !open5));
27611
+ token._open = Boolean(marker === 42 ? open6 : open6 && (before || !close));
27612
+ token._close = Boolean(marker === 42 ? close : close && (after || !open6));
27879
27613
  return ok2(code);
27880
27614
  }
27881
27615
  }
@@ -27899,9 +27633,9 @@ function tokenizeAutolink(effects, ok2, nok) {
27899
27633
  effects.consume(code);
27900
27634
  effects.exit("autolinkMarker");
27901
27635
  effects.enter("autolinkProtocol");
27902
- return open5;
27636
+ return open6;
27903
27637
  }
27904
- function open5(code) {
27638
+ function open6(code) {
27905
27639
  if (asciiAlpha(code)) {
27906
27640
  effects.consume(code);
27907
27641
  return schemeOrEmailAtext;
@@ -28101,9 +27835,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
28101
27835
  effects.enter("characterReferenceMarker");
28102
27836
  effects.consume(code);
28103
27837
  effects.exit("characterReferenceMarker");
28104
- return open5;
27838
+ return open6;
28105
27839
  }
28106
- function open5(code) {
27840
+ function open6(code) {
28107
27841
  if (code === 35) {
28108
27842
  effects.enter("characterReferenceMarkerNumeric");
28109
27843
  effects.consume(code);
@@ -29472,9 +29206,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
29472
29206
  effects.enter("htmlFlow");
29473
29207
  effects.enter("htmlFlowData");
29474
29208
  effects.consume(code);
29475
- return open5;
29209
+ return open6;
29476
29210
  }
29477
- function open5(code) {
29211
+ function open6(code) {
29478
29212
  if (code === 33) {
29479
29213
  effects.consume(code);
29480
29214
  return declarationOpen;
@@ -29822,9 +29556,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
29822
29556
  effects.enter("htmlText");
29823
29557
  effects.enter("htmlTextData");
29824
29558
  effects.consume(code);
29825
- return open5;
29559
+ return open6;
29826
29560
  }
29827
- function open5(code) {
29561
+ function open6(code) {
29828
29562
  if (code === 33) {
29829
29563
  effects.consume(code);
29830
29564
  return declarationOpen;
@@ -30150,12 +29884,12 @@ function resolveToLabelEnd(events, context) {
30150
29884
  let index2 = events.length;
30151
29885
  let offset = 0;
30152
29886
  let token;
30153
- let open5;
29887
+ let open6;
30154
29888
  let close;
30155
29889
  let media;
30156
29890
  while (index2--) {
30157
29891
  token = events[index2][1];
30158
- if (open5) {
29892
+ if (open6) {
30159
29893
  if (token.type === "link" || token.type === "labelLink" && token._inactive) {
30160
29894
  break;
30161
29895
  }
@@ -30164,7 +29898,7 @@ function resolveToLabelEnd(events, context) {
30164
29898
  }
30165
29899
  } else if (close) {
30166
29900
  if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
30167
- open5 = index2;
29901
+ open6 = index2;
30168
29902
  if (token.type !== "labelLink") {
30169
29903
  offset = 2;
30170
29904
  break;
@@ -30175,9 +29909,9 @@ function resolveToLabelEnd(events, context) {
30175
29909
  }
30176
29910
  }
30177
29911
  const group = {
30178
- type: events[open5][1].type === "labelLink" ? "link" : "image",
29912
+ type: events[open6][1].type === "labelLink" ? "link" : "image",
30179
29913
  start: {
30180
- ...events[open5][1].start
29914
+ ...events[open6][1].start
30181
29915
  },
30182
29916
  end: {
30183
29917
  ...events[events.length - 1][1].end
@@ -30186,7 +29920,7 @@ function resolveToLabelEnd(events, context) {
30186
29920
  const label = {
30187
29921
  type: "label",
30188
29922
  start: {
30189
- ...events[open5][1].start
29923
+ ...events[open6][1].start
30190
29924
  },
30191
29925
  end: {
30192
29926
  ...events[close][1].end
@@ -30195,20 +29929,20 @@ function resolveToLabelEnd(events, context) {
30195
29929
  const text3 = {
30196
29930
  type: "labelText",
30197
29931
  start: {
30198
- ...events[open5 + offset + 2][1].end
29932
+ ...events[open6 + offset + 2][1].end
30199
29933
  },
30200
29934
  end: {
30201
29935
  ...events[close - 2][1].start
30202
29936
  }
30203
29937
  };
30204
29938
  media = [["enter", group, context], ["enter", label, context]];
30205
- media = push(media, events.slice(open5 + 1, open5 + offset + 3));
29939
+ media = push(media, events.slice(open6 + 1, open6 + offset + 3));
30206
29940
  media = push(media, [["enter", text3, context]]);
30207
- media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open5 + offset + 4, close - 3), context));
29941
+ media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + offset + 4, close - 3), context));
30208
29942
  media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
30209
29943
  media = push(media, events.slice(close + 1));
30210
29944
  media = push(media, [["exit", group, context]]);
30211
- splice(events, open5, events.length, media);
29945
+ splice(events, open6, events.length, media);
30212
29946
  return events;
30213
29947
  }
30214
29948
  function tokenizeLabelEnd(effects, ok2, nok) {
@@ -30353,9 +30087,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
30353
30087
  effects.enter("labelImageMarker");
30354
30088
  effects.consume(code);
30355
30089
  effects.exit("labelImageMarker");
30356
- return open5;
30090
+ return open6;
30357
30091
  }
30358
- function open5(code) {
30092
+ function open6(code) {
30359
30093
  if (code === 91) {
30360
30094
  effects.enter("labelMarker");
30361
30095
  effects.consume(code);
@@ -31659,8 +31393,8 @@ function compiler(options) {
31659
31393
  return length;
31660
31394
  }
31661
31395
  function opener(create, and) {
31662
- return open5;
31663
- function open5(token) {
31396
+ return open6;
31397
+ function open6(token) {
31664
31398
  enter.call(this, create(token), token);
31665
31399
  if (and) and.call(this, token);
31666
31400
  }
@@ -31692,18 +31426,18 @@ function compiler(options) {
31692
31426
  }
31693
31427
  function exit2(token, onExitError) {
31694
31428
  const node3 = this.stack.pop();
31695
- const open5 = this.tokenStack.pop();
31696
- if (!open5) {
31429
+ const open6 = this.tokenStack.pop();
31430
+ if (!open6) {
31697
31431
  throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
31698
31432
  start: token.start,
31699
31433
  end: token.end
31700
31434
  }) + "): it\u2019s not open");
31701
- } else if (open5[0].type !== token.type) {
31435
+ } else if (open6[0].type !== token.type) {
31702
31436
  if (onExitError) {
31703
- onExitError.call(this, token, open5[0]);
31437
+ onExitError.call(this, token, open6[0]);
31704
31438
  } else {
31705
- const handler = open5[1] || defaultOnError;
31706
- handler.call(this, token, open5[0]);
31439
+ const handler = open6[1] || defaultOnError;
31440
+ handler.call(this, token, open6[0]);
31707
31441
  }
31708
31442
  }
31709
31443
  node3.position.end = point2(token.end);
@@ -32387,7 +32121,7 @@ var SessionConfigProtocolError = class extends Error {
32387
32121
  this.name = "SessionConfigProtocolError";
32388
32122
  }
32389
32123
  };
32390
- function isRecord7(value) {
32124
+ function isRecord6(value) {
32391
32125
  return typeof value === "object" && value !== null && !Array.isArray(value);
32392
32126
  }
32393
32127
  function readString2(value, fallback = "") {
@@ -32414,7 +32148,7 @@ function normalizeConfigValues(value) {
32414
32148
  }
32415
32149
  const normalized = [];
32416
32150
  for (const entry of value) {
32417
- if (!isRecord7(entry)) {
32151
+ if (!isRecord6(entry)) {
32418
32152
  continue;
32419
32153
  }
32420
32154
  const groupedOptions = entry["options"];
@@ -32422,7 +32156,7 @@ function normalizeConfigValues(value) {
32422
32156
  const groupId = readString2(entry["group"]);
32423
32157
  const groupName = readString2(entry["name"]);
32424
32158
  for (const groupedOption of groupedOptions) {
32425
- if (isRecord7(groupedOption)) {
32159
+ if (isRecord6(groupedOption)) {
32426
32160
  normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
32427
32161
  }
32428
32162
  }
@@ -32436,7 +32170,7 @@ function normalizeConfigOptions(value, modes) {
32436
32170
  const normalized = [];
32437
32171
  if (Array.isArray(value)) {
32438
32172
  for (const option of value) {
32439
- if (!isRecord7(option)) {
32173
+ if (!isRecord6(option)) {
32440
32174
  continue;
32441
32175
  }
32442
32176
  const id = truncate2(readString2(option["id"]), 128);
@@ -32475,12 +32209,12 @@ function normalizeConfigOptions(value, modes) {
32475
32209
  }
32476
32210
  }
32477
32211
  }
32478
- if (isRecord7(modes)) {
32212
+ if (isRecord6(modes)) {
32479
32213
  const values = [];
32480
32214
  const availableModes = modes["availableModes"];
32481
32215
  if (Array.isArray(availableModes)) {
32482
32216
  for (const mode of availableModes) {
32483
- if (!isRecord7(mode)) {
32217
+ if (!isRecord6(mode)) {
32484
32218
  continue;
32485
32219
  }
32486
32220
  const id = truncate2(readString2(mode["id"]), 500);
@@ -32619,7 +32353,7 @@ function ensureRequiredExecutionOptions(current, permission) {
32619
32353
  return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
32620
32354
  }
32621
32355
  function normalizeStandardLifecycle(response) {
32622
- const lifecycle = isRecord7(response) ? response : {};
32356
+ const lifecycle = isRecord6(response) ? response : {};
32623
32357
  return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
32624
32358
  }
32625
32359
  function replaceStandardConfigOptions(current, value) {
@@ -32661,7 +32395,7 @@ var StandardSessionConfigProtocol = class {
32661
32395
  "ACP agent exited while changing session configuration",
32662
32396
  change.signal
32663
32397
  );
32664
- if (!isRecord7(response) || !Array.isArray(response["configOptions"])) {
32398
+ if (!isRecord6(response) || !Array.isArray(response["configOptions"])) {
32665
32399
  throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
32666
32400
  }
32667
32401
  return replaceStandardConfigOptions(current, response["configOptions"]);
@@ -32675,18 +32409,18 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
32675
32409
  var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
32676
32410
  var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
32677
32411
  function legacyOptions(response) {
32678
- if (!isRecord7(response)) {
32412
+ if (!isRecord6(response)) {
32679
32413
  return [];
32680
32414
  }
32681
32415
  const metadata = response["_meta"];
32682
- if (!isRecord7(metadata)) {
32416
+ if (!isRecord6(metadata)) {
32683
32417
  return [];
32684
32418
  }
32685
32419
  const sessionConfig = metadata["x.ai/sessionConfig"];
32686
- if (!isRecord7(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
32420
+ if (!isRecord6(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
32687
32421
  return [];
32688
32422
  }
32689
- return sessionConfig["options"].slice(0, 500).filter(isRecord7);
32423
+ return sessionConfig["options"].slice(0, 500).filter(isRecord6);
32690
32424
  }
32691
32425
  function legacyValue(option) {
32692
32426
  const value = readString2(option["id"]);
@@ -32699,7 +32433,7 @@ function legacyValue(option) {
32699
32433
  };
32700
32434
  }
32701
32435
  function modelsRecord(response) {
32702
- if (!isRecord7(response) || !isRecord7(response["models"])) {
32436
+ if (!isRecord6(response) || !isRecord6(response["models"])) {
32703
32437
  return {};
32704
32438
  }
32705
32439
  return response["models"];
@@ -32718,7 +32452,7 @@ function legacyModelOptions(response) {
32718
32452
  }
32719
32453
  if (values.length === 0 && Array.isArray(models["availableModels"])) {
32720
32454
  for (const model of models["availableModels"]) {
32721
- if (!isRecord7(model)) {
32455
+ if (!isRecord6(model)) {
32722
32456
  continue;
32723
32457
  }
32724
32458
  const value = readString2(model["modelId"]).slice(0, 500);
@@ -32798,7 +32532,7 @@ function legacyReasoningEffortOptions(response) {
32798
32532
  return [result];
32799
32533
  }
32800
32534
  function normalizeGrokLifecycle(response) {
32801
- const lifecycle = isRecord7(response) ? response : {};
32535
+ const lifecycle = isRecord6(response) ? response : {};
32802
32536
  const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
32803
32537
  const normalized = [...standard];
32804
32538
  if (!normalized.some((option) => option.category === "model")) {
@@ -32817,11 +32551,11 @@ function updateCurrentValue2(current, category, value) {
32817
32551
  return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
32818
32552
  }
32819
32553
  function validateGrokResponse(response, modelId) {
32820
- if (!isRecord7(response) || !isRecord7(response["_meta"])) {
32554
+ if (!isRecord6(response) || !isRecord6(response["_meta"])) {
32821
32555
  throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
32822
32556
  }
32823
32557
  const model = response["_meta"]["model"];
32824
- const appliedModel = isRecord7(model) ? model["Ok"] : model;
32558
+ const appliedModel = isRecord6(model) ? model["Ok"] : model;
32825
32559
  if (appliedModel !== modelId) {
32826
32560
  throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
32827
32561
  }
@@ -33354,7 +33088,7 @@ function createWritableAcpStream(output2) {
33354
33088
  function truncate3(value, maximumLength) {
33355
33089
  return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
33356
33090
  }
33357
- function isRecord8(value) {
33091
+ function isRecord7(value) {
33358
33092
  return typeof value === "object" && value !== null && !Array.isArray(value);
33359
33093
  }
33360
33094
  function readString4(value, fallback = "") {
@@ -33388,7 +33122,7 @@ function normalizeElicitationOptions(schema) {
33388
33122
  const oneOf = schema["oneOf"];
33389
33123
  if (Array.isArray(oneOf)) {
33390
33124
  for (const option of oneOf) {
33391
- if (isRecord8(option) && typeof option["const"] === "string") {
33125
+ if (isRecord7(option) && typeof option["const"] === "string") {
33392
33126
  normalized.push({
33393
33127
  description: truncate3(readString4(option["description"]), 500),
33394
33128
  label: truncate3(readString4(option["title"], option["const"]), 255),
@@ -33408,7 +33142,7 @@ function normalizeElicitationOptions(schema) {
33408
33142
  return normalized.slice(0, 200);
33409
33143
  }
33410
33144
  const items = schema["items"];
33411
- if (!isRecord8(items)) {
33145
+ if (!isRecord7(items)) {
33412
33146
  return normalized;
33413
33147
  }
33414
33148
  const anyOf = items["anyOf"];
@@ -33421,7 +33155,7 @@ function numericString(value) {
33421
33155
  return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
33422
33156
  }
33423
33157
  function normalizeElicitationFields(requestedSchema) {
33424
- if (!isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
33158
+ if (!isRecord7(requestedSchema) || !isRecord7(requestedSchema["properties"])) {
33425
33159
  return [];
33426
33160
  }
33427
33161
  const properties2 = requestedSchema["properties"];
@@ -33431,7 +33165,7 @@ function normalizeElicitationFields(requestedSchema) {
33431
33165
  );
33432
33166
  const normalized = [];
33433
33167
  for (const [name, property] of Object.entries(properties2)) {
33434
- if (!isRecord8(property)) {
33168
+ if (!isRecord7(property)) {
33435
33169
  continue;
33436
33170
  }
33437
33171
  const type = elicitationFieldType(property["type"]);
@@ -33522,7 +33256,7 @@ function validateElicitationContent(encoded, requestedSchema) {
33522
33256
  "invalid_elicitation_response"
33523
33257
  );
33524
33258
  }
33525
- if (!isRecord8(decoded) || !isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
33259
+ if (!isRecord7(decoded) || !isRecord7(requestedSchema) || !isRecord7(requestedSchema["properties"])) {
33526
33260
  throw new AcpExecutionError(
33527
33261
  "Elicitation response does not match the requested form",
33528
33262
  {},
@@ -33542,7 +33276,7 @@ function validateElicitationContent(encoded, requestedSchema) {
33542
33276
  const validated = {};
33543
33277
  for (const [name, value] of Object.entries(decoded)) {
33544
33278
  const property = properties2[name];
33545
- if (!isRecord8(property)) {
33279
+ if (!isRecord7(property)) {
33546
33280
  throw new AcpExecutionError(
33547
33281
  `Elicitation field ${name} was not requested`,
33548
33282
  {},
@@ -33695,6 +33429,7 @@ var AcpProcessSession = class _AcpProcessSession {
33695
33429
  #permissionProfile;
33696
33430
  #sessionConfigProtocol;
33697
33431
  #store;
33432
+ #emittedToolImages = /* @__PURE__ */ new Set();
33698
33433
  #verifiedAgentVersion;
33699
33434
  #preSessionUpdateBytes = 0;
33700
33435
  #agentName = "";
@@ -33915,19 +33650,19 @@ var AcpProcessSession = class _AcpProcessSession {
33915
33650
  }
33916
33651
  };
33917
33652
  prepareAgentContent = async (content3) => {
33918
- if (content3.type === "image" && content3.data.length > 0) {
33919
- const raster = readInlineRaster(content3.data, content3.name);
33920
- if (raster !== null) {
33921
- return await this.importRaster(raster, AbortSignal.timeout(2e4));
33922
- }
33923
- }
33924
- if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
33653
+ if (content3.type === "image" && content3.uri.length > 0) {
33925
33654
  const signal = AbortSignal.timeout(2e4);
33926
33655
  const raster = await readLocalRaster(content3.uri, signal);
33927
33656
  if (raster !== null) {
33928
33657
  return await this.importRaster(raster, signal);
33929
33658
  }
33930
33659
  }
33660
+ if (content3.type === "image" && content3.data.length > 0) {
33661
+ const raster = readInlineRaster(content3.data, content3.name);
33662
+ if (raster !== null) {
33663
+ return await this.importRaster(raster, AbortSignal.timeout(2e4));
33664
+ }
33665
+ }
33931
33666
  if (content3.type === "video" && content3.data.length > 0) {
33932
33667
  const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
33933
33668
  if (video === null) {
@@ -33948,6 +33683,22 @@ var AcpProcessSession = class _AcpProcessSession {
33948
33683
  sessionId: this.#mobiusSessionId
33949
33684
  });
33950
33685
  };
33686
+ emitToolImages = async (update) => {
33687
+ if (update.status !== "completed") {
33688
+ return;
33689
+ }
33690
+ for (const [index2, item] of (update.content ?? []).entries()) {
33691
+ if (item.type !== "content" || item.content.type !== "image") {
33692
+ continue;
33693
+ }
33694
+ const key = `${update.toolCallId}:${index2.toString()}`;
33695
+ if (this.#emittedToolImages.has(key)) {
33696
+ continue;
33697
+ }
33698
+ this.#emittedToolImages.add(key);
33699
+ await this.emitAgentContent(normalizeContentBlock(item.content), `tool-${key}`);
33700
+ }
33701
+ };
33951
33702
  emitRaster = async (raster, messageId, signal) => {
33952
33703
  const content3 = await this.importRaster(raster, signal);
33953
33704
  await this.#getObserver().onContent({
@@ -33959,14 +33710,14 @@ var AcpProcessSession = class _AcpProcessSession {
33959
33710
  sessionId: this.#mobiusSessionId
33960
33711
  });
33961
33712
  };
33962
- importRaster = async (raster, signal) => {
33963
- const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, raster, signal);
33964
- return imageDisplayContent(
33965
- raster.mimeType,
33966
- raster.name,
33967
- artifactId.length > 0 ? "" : raster.base64(),
33968
- artifactId
33969
- );
33713
+ importRaster = async (raster, _signal) => {
33714
+ if (raster.sourceUri.length > 0) {
33715
+ return {
33716
+ ...imageDisplayContent(raster.mimeType, raster.name, "", ""),
33717
+ uri: raster.sourceUri
33718
+ };
33719
+ }
33720
+ return imageDisplayContent(raster.mimeType, raster.name, await raster.base64(), "");
33970
33721
  };
33971
33722
  importVideo = async (video, signal) => {
33972
33723
  const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
@@ -34450,7 +34201,7 @@ var AcpProcessSession = class _AcpProcessSession {
34450
34201
  "ACP agent exited during steering",
34451
34202
  options.signal
34452
34203
  );
34453
- if (!isRecord8(response)) {
34204
+ if (!isRecord7(response)) {
34454
34205
  throw new AcpExecutionError(
34455
34206
  "ACP agent returned an invalid steering response",
34456
34207
  {},
@@ -34746,6 +34497,7 @@ var AcpProcessSession = class _AcpProcessSession {
34746
34497
  }
34747
34498
  if (update.sessionUpdate === "tool_call_update") {
34748
34499
  await this.#turn.activities.recordToolCallUpdate(update);
34500
+ await this.emitToolImages(update);
34749
34501
  return;
34750
34502
  }
34751
34503
  if (update.sessionUpdate === "plan") {
@@ -35424,7 +35176,7 @@ var AcpSessionManager = class {
35424
35176
  async (runtime) => await runtime.close()
35425
35177
  );
35426
35178
  /**
35427
- * @deprecated Retained for the Bot-scoped legacy Agent-configuration API.
35179
+ * Retained for Agents that expose a separate persisted configuration channel.
35428
35180
  * Use inspectAgentSettings for Agent-scoped settings discovery.
35429
35181
  */
35430
35182
  inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
@@ -36018,7 +35770,6 @@ async function publishAgentCatalog(config2, signal) {
36018
35770
  agentPath: agent.agentIdentity.requestedPath,
36019
35771
  agentVersion: agent.agentVersion,
36020
35772
  agentSettingsDiscovery: true,
36021
- botSessionConfiguration: true,
36022
35773
  capabilities: agent.capabilities,
36023
35774
  id: agent.id,
36024
35775
  label: agent.label,
@@ -36505,6 +36256,91 @@ var FixedInstallationExecutor = class {
36505
36256
  };
36506
36257
  };
36507
36258
 
36259
+ // src/artifacts/local-file-streamer.ts
36260
+ import { createReadStream as createReadStream2 } from "node:fs";
36261
+ import { realpath as realpath7, stat as stat6 } from "node:fs/promises";
36262
+ import { basename as basename3, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
36263
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
36264
+ var CHUNK_BYTES = 192 * 1024;
36265
+ function requestedPath(value) {
36266
+ if (value.includes("\0")) {
36267
+ return null;
36268
+ }
36269
+ if (value.startsWith("file:")) {
36270
+ try {
36271
+ const url2 = new URL(value);
36272
+ return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath2(url2) : null;
36273
+ } catch {
36274
+ return null;
36275
+ }
36276
+ }
36277
+ return value;
36278
+ }
36279
+ async function resolveFile(value, signal) {
36280
+ const requested = requestedPath(value);
36281
+ if (requested === null || !isAbsolute9(requested) || normalize3(requested) !== requested) {
36282
+ return null;
36283
+ }
36284
+ try {
36285
+ const target = await realpath7(requested);
36286
+ signal.throwIfAborted();
36287
+ return isAbsolute9(target) && normalize3(target) === target ? target : null;
36288
+ } catch {
36289
+ signal.throwIfAborted();
36290
+ return null;
36291
+ }
36292
+ }
36293
+ async function streamLocalFile(command, send2, signal) {
36294
+ const target = await resolveFile(command.path, signal);
36295
+ if (target === null) {
36296
+ throw new Error("The local file is unavailable");
36297
+ }
36298
+ const before = await stat6(target);
36299
+ signal.throwIfAborted();
36300
+ if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
36301
+ throw new Error("The local file is too large to read");
36302
+ }
36303
+ const raster = await readLocalRaster(target, signal);
36304
+ send2(
36305
+ encodeFileBeginEvent({
36306
+ byteLength: before.size,
36307
+ kind: FILE_BEGIN_KIND,
36308
+ mediaType: raster?.mimeType ?? "application/octet-stream",
36309
+ modifiedAt: before.mtime.toISOString(),
36310
+ name: basename3(target) || "file",
36311
+ requestId: command.requestId,
36312
+ sessionId: command.sessionId
36313
+ })
36314
+ );
36315
+ let sequence = 0;
36316
+ const stream = createReadStream2(target, { highWaterMark: CHUNK_BYTES, signal });
36317
+ for await (const value of stream) {
36318
+ const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
36319
+ send2(
36320
+ encodeFileChunkEvent({
36321
+ data: Buffer.from(bytes).toString("base64"),
36322
+ kind: FILE_CHUNK_KIND,
36323
+ requestId: command.requestId,
36324
+ sequence,
36325
+ sessionId: command.sessionId
36326
+ })
36327
+ );
36328
+ sequence += 1;
36329
+ }
36330
+ const after = await stat6(target);
36331
+ signal.throwIfAborted();
36332
+ if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
36333
+ throw new Error("The local file changed during transfer");
36334
+ }
36335
+ send2(
36336
+ encodeFileEndEvent({
36337
+ kind: FILE_END_KIND,
36338
+ requestId: command.requestId,
36339
+ sessionId: command.sessionId
36340
+ })
36341
+ );
36342
+ }
36343
+
36508
36344
  // src/artifacts/runtime-artifact-uploader.ts
36509
36345
  import { createHash as createHash2 } from "node:crypto";
36510
36346
 
@@ -36531,15 +36367,15 @@ var MobiusValidationError = class extends MobiusError {
36531
36367
  };
36532
36368
 
36533
36369
  // ../mobius-sdk/src/resources.ts
36534
- var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
36370
+ var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
36535
36371
  function invalidResponse(message) {
36536
36372
  return new MobiusProtocolError(message);
36537
36373
  }
36538
- function isRecord9(value) {
36374
+ function isRecord8(value) {
36539
36375
  return typeof value === "object" && value !== null && !Array.isArray(value);
36540
36376
  }
36541
36377
  function record3(value, name) {
36542
- if (!isRecord9(value)) {
36378
+ if (!isRecord8(value)) {
36543
36379
  throw invalidResponse(`The service returned an invalid ${name}`);
36544
36380
  }
36545
36381
  return value;
@@ -36553,7 +36389,7 @@ function stringField(value, field, maximumLength = 85e5) {
36553
36389
  }
36554
36390
  function identifierField(value, field) {
36555
36391
  const candidate = stringField(value, field, 128);
36556
- if (!IDENTIFIER_PATTERN5.test(candidate)) {
36392
+ if (!IDENTIFIER_PATTERN4.test(candidate)) {
36557
36393
  throw invalidResponse(`The service returned an invalid ${field}`);
36558
36394
  }
36559
36395
  return candidate;
@@ -36900,9 +36736,9 @@ var LocalAuthorizationError = class extends Error {
36900
36736
  };
36901
36737
 
36902
36738
  // src/authorization/workspace-directory.ts
36903
- import { readdir as readdir2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
36739
+ import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
36904
36740
  import { homedir as homedir2 } from "node:os";
36905
- import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute9, join as join15, normalize as normalize3, relative as relative4 } from "node:path";
36741
+ import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute10, join as join15, normalize as normalize4, relative as relative4 } from "node:path";
36906
36742
  var WorkspaceDirectoryListing = class {
36907
36743
  directoryId;
36908
36744
  directoryLabel;
@@ -36928,7 +36764,7 @@ function decodePath(value, prefix) {
36928
36764
  throw new LocalAuthorizationError("The directory identifier is invalid");
36929
36765
  }
36930
36766
  const decoded = Buffer.from(encoded, "base64url").toString("utf8");
36931
- if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize3(decoded) !== decoded) {
36767
+ if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize4(decoded) !== decoded) {
36932
36768
  throw new LocalAuthorizationError("The directory identifier is invalid");
36933
36769
  }
36934
36770
  return decoded;
@@ -36954,7 +36790,7 @@ var WorkspaceDirectoryService = class {
36954
36790
  }
36955
36791
  if (id.startsWith("path-")) {
36956
36792
  const path2 = decodePath(id, "path-");
36957
- if (isAbsolute9(path2)) {
36793
+ if (isAbsolute10(path2)) {
36958
36794
  return path2;
36959
36795
  }
36960
36796
  }
@@ -36962,15 +36798,15 @@ var WorkspaceDirectoryService = class {
36962
36798
  };
36963
36799
  resolvePath = async (requested, signal) => {
36964
36800
  signal.throwIfAborted();
36965
- if (!isAbsolute9(requested) || requested.includes("\0") || normalize3(requested) !== requested) {
36801
+ if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
36966
36802
  throw new LocalAuthorizationError("The local directory path is invalid");
36967
36803
  }
36968
36804
  try {
36969
- const target = await realpath7(requested);
36805
+ const target = await realpath8(requested);
36970
36806
  signal.throwIfAborted();
36971
- const metadata = await stat6(target);
36807
+ const metadata = await stat7(target);
36972
36808
  signal.throwIfAborted();
36973
- if (!isAbsolute9(target) || normalize3(target) !== target || !metadata.isDirectory()) {
36809
+ if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
36974
36810
  throw new LocalAuthorizationError("The selected location is not a directory");
36975
36811
  }
36976
36812
  return target;
@@ -36986,15 +36822,15 @@ var WorkspaceDirectoryService = class {
36986
36822
  };
36987
36823
  label = (path2) => {
36988
36824
  const suffix = relative4(homedir2(), path2);
36989
- return suffix === "" ? "~" : !isAbsolute9(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
36825
+ return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
36990
36826
  };
36991
- identify = async (bindingId, requestedPath, signal) => {
36827
+ identify = async (bindingId, requestedPath2, signal) => {
36992
36828
  this.authorizeMachine(bindingId);
36993
- const path2 = await this.resolvePath(requestedPath, signal);
36829
+ const path2 = await this.resolvePath(requestedPath2, signal);
36994
36830
  return {
36995
36831
  path: path2,
36996
36832
  directoryId: encodePath(path2),
36997
- name: basename3(path2) || path2,
36833
+ name: basename4(path2) || path2,
36998
36834
  label: this.label(path2)
36999
36835
  };
37000
36836
  };
@@ -37050,436 +36886,9 @@ var WorkspaceDirectoryService = class {
37050
36886
  };
37051
36887
  };
37052
36888
 
37053
- // src/bots/local-bot-execution-authorizer.ts
37054
- var LocalBotAuthorizationError = class extends Error {
37055
- code;
37056
- constructor(code, message, options = {}) {
37057
- super(message, options);
37058
- this.code = code;
37059
- this.name = "LocalBotAuthorizationError";
37060
- }
37061
- };
37062
- var AuthorizedLocalBotExecution = class {
37063
- agent;
37064
- behaviorDigest;
37065
- behaviorRevisionId;
37066
- bindingId;
37067
- bindingRevision;
37068
- botId;
37069
- executionConfiguration;
37070
- workspacePath;
37071
- workspaceRef;
37072
- constructor(command, agent, workspacePath) {
37073
- this.agent = agent;
37074
- this.behaviorDigest = command.behaviorDigest;
37075
- this.behaviorRevisionId = command.behaviorRevisionId;
37076
- this.bindingId = command.bindingId;
37077
- this.bindingRevision = command.bindingRevision;
37078
- this.botId = command.botId;
37079
- this.executionConfiguration = command.executionConfiguration;
37080
- this.workspacePath = workspacePath;
37081
- this.workspaceRef = command.directoryId;
37082
- }
37083
- };
37084
- var LocalBotExecutionAuthorizer = class {
37085
- authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
37086
- signal.throwIfAborted();
37087
- let agent;
37088
- try {
37089
- agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
37090
- } catch (cause) {
37091
- if (cause instanceof AgentPermissionConfigurationError) {
37092
- throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
37093
- }
37094
- throw cause;
37095
- }
37096
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
37097
- revalidateExecutable(agent.adapterIdentity),
37098
- revalidateExecutable(agent.agentIdentity)
37099
- ]);
37100
- signal.throwIfAborted();
37101
- if (!adapterUnchanged || !agentUnchanged) {
37102
- throw new LocalBotAuthorizationError(
37103
- "binding_incompatible",
37104
- "The local Agent executable changed while the Runtime is active; restart the Runtime"
37105
- );
37106
- }
37107
- if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
37108
- throw new LocalBotAuthorizationError(
37109
- "binding_incompatible",
37110
- "The local Agent cannot apply the Bot behavior"
37111
- );
37112
- }
37113
- const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
37114
- signal.throwIfAborted();
37115
- return new AuthorizedLocalBotExecution(command, agent, workspacePath);
37116
- };
37117
- };
37118
-
37119
- // src/bots/bot-context-applicator.ts
37120
- var AppliedBotContext = class {
37121
- resources;
37122
- constructor(resources) {
37123
- this.resources = Object.freeze([...resources]);
37124
- }
37125
- };
37126
- var EmbeddedBotContextApplicator = class {
37127
- apply = async (command, execution, resources, signal) => {
37128
- signal.throwIfAborted();
37129
- if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
37130
- throw new LocalBotAuthorizationError(
37131
- "binding_incompatible",
37132
- "The Bot behavior does not match the execution target"
37133
- );
37134
- }
37135
- if (command.behaviorInstructions.length === 0) {
37136
- return new AppliedBotContext(resources);
37137
- }
37138
- if (!execution.agent.capabilities.embeddedContextPrompt) {
37139
- throw new LocalBotAuthorizationError(
37140
- "binding_incompatible",
37141
- "The local Agent cannot enforce the Bot behavior context"
37142
- );
37143
- }
37144
- const trustedContext = {
37145
- mimeType: "text/markdown",
37146
- name: "Mobius Bot behavior",
37147
- text: command.behaviorInstructions,
37148
- type: "embedded",
37149
- uri: `mobius://bots/${encodeURIComponent(command.botId)}/behavior-revisions/${encodeURIComponent(command.behaviorRevisionId)}?sha256=${command.behaviorDigest}`
37150
- };
37151
- return new AppliedBotContext([trustedContext, ...resources]);
37152
- };
37153
- };
37154
-
37155
- // src/bots/bot-execution-context.ts
37156
- import { randomBytes } from "node:crypto";
37157
- var ActiveBotExecutionContext = class {
37158
- command;
37159
- contextHandle;
37160
- constructor(contextHandle, command) {
37161
- this.contextHandle = contextHandle;
37162
- this.command = command;
37163
- }
37164
- resolveTarget = (target) => {
37165
- if (target === "current") {
37166
- if (!(this.command.replyRoute instanceof BotConnectionReplyRoute)) {
37167
- throw new LocalBotAuthorizationError(
37168
- "delivery_target_not_allowed",
37169
- "This Bot conversation has no external reply target"
37170
- );
37171
- }
37172
- return this.command.replyRoute.deliveryTargetId;
37173
- }
37174
- const resolved = this.command.allowedDeliveryTargets.find((candidate) => candidate.alias === target);
37175
- if (resolved === void 0) {
37176
- throw new LocalBotAuthorizationError(
37177
- "delivery_target_not_allowed",
37178
- "The named Bot delivery target is not approved"
37179
- );
37180
- }
37181
- return resolved.deliveryTargetId;
37182
- };
37183
- };
37184
- var BotExecutionContextLease = class {
37185
- context;
37186
- #release;
37187
- #released = false;
37188
- constructor(context, release) {
37189
- this.context = context;
37190
- this.#release = release;
37191
- }
37192
- release = () => {
37193
- if (this.#released) {
37194
- return;
37195
- }
37196
- this.#released = true;
37197
- this.#release();
37198
- };
37199
- };
37200
- var BotExecutionContextRegistry = class {
37201
- #activeByHandle = /* @__PURE__ */ new Map();
37202
- #handlesBySession = /* @__PURE__ */ new Map();
37203
- #inactiveHandles = /* @__PURE__ */ new Set();
37204
- activate = (command) => {
37205
- let handle = this.#handlesBySession.get(command.sessionId);
37206
- if (handle === void 0) {
37207
- handle = `ctx_${Buffer.from(randomBytes(32)).toString("base64url")}`;
37208
- this.#handlesBySession.set(command.sessionId, handle);
37209
- }
37210
- if (this.#activeByHandle.has(handle)) {
37211
- throw new LocalBotAuthorizationError("session_busy", "The Bot execution context is already active");
37212
- }
37213
- const context = new ActiveBotExecutionContext(handle, command);
37214
- this.#inactiveHandles.delete(handle);
37215
- this.#activeByHandle.set(handle, context);
37216
- return new BotExecutionContextLease(context, () => {
37217
- if (this.#activeByHandle.get(handle) === context) {
37218
- this.#activeByHandle.delete(handle);
37219
- this.#inactiveHandles.add(handle);
37220
- }
37221
- });
37222
- };
37223
- read = (handle) => {
37224
- const context = this.#activeByHandle.get(handle);
37225
- if (context === void 0) {
37226
- if (this.#inactiveHandles.has(handle)) {
37227
- throw new LocalBotAuthorizationError(
37228
- "execution_capability_expired",
37229
- "The Bot execution capability has expired"
37230
- );
37231
- }
37232
- throw new LocalBotAuthorizationError(
37233
- "execution_context_required",
37234
- "An active Bot execution context is required"
37235
- );
37236
- }
37237
- return context;
37238
- };
37239
- };
37240
-
37241
- // src/bots/bot-outbound-ipc.ts
37242
- import { chmod as chmod2, mkdir as mkdir3, unlink } from "node:fs/promises";
37243
- import { createServer } from "node:net";
37244
- import { dirname as dirname6, isAbsolute as isAbsolute10 } from "node:path";
37245
- import { fetch as fetch4 } from "undici";
37246
- var BOT_IPC_REQUEST_LIMIT = 32 * 1024;
37247
- var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
37248
- var BOT_RELAY_TIMEOUT_MILLISECONDS = 2e4;
37249
- var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
37250
- var WINDOWS_NAMED_PIPE_PREFIX = "\\\\.\\pipe\\";
37251
- var BotOutboundIpcRequest = class {
37252
- contextHandle;
37253
- idempotencyKey;
37254
- target;
37255
- text;
37256
- constructor(contextHandle, idempotencyKey, target, text3) {
37257
- this.contextHandle = contextHandle;
37258
- this.idempotencyKey = idempotencyKey;
37259
- this.target = target;
37260
- this.text = text3;
37261
- }
37262
- };
37263
- function isRecord10(value) {
37264
- return typeof value === "object" && value !== null && !Array.isArray(value);
37265
- }
37266
- function decodeRequest(encoded) {
37267
- let value;
37268
- try {
37269
- value = JSON.parse(encoded);
37270
- } catch (cause) {
37271
- throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid", { cause });
37272
- }
37273
- if (!isRecord10(value)) {
37274
- throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
37275
- }
37276
- const keys = Object.keys(value);
37277
- if (keys.length !== 4 || !keys.every((key) => ["contextHandle", "idempotencyKey", "target", "text"].includes(key))) {
37278
- throw new LocalBotAuthorizationError("invalid_request", "The local Bot request fields are invalid");
37279
- }
37280
- const contextHandle = value["contextHandle"];
37281
- const idempotencyKey = value["idempotencyKey"];
37282
- const target = value["target"];
37283
- const text3 = value["text"];
37284
- if (typeof contextHandle !== "string" || !/^ctx_[a-zA-Z0-9_-]{43}$/.test(contextHandle) || typeof idempotencyKey !== "string" || !IDENTIFIER_PATTERN6.test(idempotencyKey) || typeof target !== "string" || !IDENTIFIER_PATTERN6.test(target) || typeof text3 !== "string" || text3.trim().length === 0 || text3.length > 1e4) {
37285
- throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
37286
- }
37287
- return new BotOutboundIpcRequest(contextHandle, idempotencyKey, target, text3);
37288
- }
37289
- function relayEndpoint(relayUrl, context, target) {
37290
- const endpoint = new URL(relayUrl);
37291
- if (endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") {
37292
- throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay URL is invalid");
37293
- }
37294
- endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
37295
- endpoint.search = "";
37296
- const execution = encodeURIComponent(context.command.executionId);
37297
- if (target === "current") {
37298
- context.resolveTarget(target);
37299
- endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/reply-messages`;
37300
- return endpoint;
37301
- }
37302
- const deliveryTargetId = context.resolveTarget(target);
37303
- endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
37304
- return endpoint;
37305
- }
37306
- function daemonToken(relayUrl) {
37307
- const token = relayUrl.searchParams.get("token") ?? "";
37308
- if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
37309
- throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
37310
- }
37311
- return token;
37312
- }
37313
- async function decodeRelayResponse(response) {
37314
- const encoded = await response.text();
37315
- let value;
37316
- try {
37317
- value = JSON.parse(encoded);
37318
- } catch (cause) {
37319
- throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay returned invalid data", {
37320
- cause
37321
- });
37322
- }
37323
- if (response.status === 202 && isRecord10(value) && typeof value["outboundMessageId"] === "string") {
37324
- return value["outboundMessageId"];
37325
- }
37326
- if (isRecord10(value) && isRecord10(value["error"])) {
37327
- const error62 = value["error"];
37328
- if (typeof error62["code"] === "string" && typeof error62["message"] === "string") {
37329
- throw new LocalBotAuthorizationError(error62["code"], error62["message"]);
37330
- }
37331
- }
37332
- throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay rejected the Bot action");
37333
- }
37334
- var BotOutboundIpcServer = class {
37335
- #registry;
37336
- #relayUrl;
37337
- #server;
37338
- #socketPath;
37339
- #usesFilesystemSocket;
37340
- constructor(socketPath, relayUrl, registry2) {
37341
- const usesFilesystemSocket = !socketPath.startsWith(WINDOWS_NAMED_PIPE_PREFIX);
37342
- if (usesFilesystemSocket && !isAbsolute10(socketPath)) {
37343
- throw new Error("The Bot IPC path must be absolute");
37344
- }
37345
- this.#registry = registry2;
37346
- this.#relayUrl = new URL(relayUrl);
37347
- this.#server = createServer({ allowHalfOpen: true }, (socket) => this.accept(socket));
37348
- this.#socketPath = socketPath;
37349
- this.#usesFilesystemSocket = usesFilesystemSocket;
37350
- }
37351
- get socketPath() {
37352
- return this.#socketPath;
37353
- }
37354
- listen = async (signal) => {
37355
- signal.throwIfAborted();
37356
- if (this.#usesFilesystemSocket) {
37357
- await mkdir3(dirname6(this.#socketPath), { mode: 448, recursive: true });
37358
- await unlink(this.#socketPath).catch((error62) => {
37359
- if (!isRecord10(error62) || error62["code"] !== "ENOENT") {
37360
- throw error62;
37361
- }
37362
- });
37363
- }
37364
- await new Promise((resolve6, reject) => {
37365
- const fail = (error62) => reject(error62);
37366
- this.#server.once("error", fail);
37367
- this.#server.listen(this.#socketPath, () => {
37368
- this.#server.removeListener("error", fail);
37369
- resolve6();
37370
- });
37371
- });
37372
- if (this.#usesFilesystemSocket) {
37373
- await chmod2(this.#socketPath, 384);
37374
- }
37375
- signal.addEventListener("abort", this.abort, { once: true });
37376
- if (signal.aborted) {
37377
- this.abort();
37378
- }
37379
- };
37380
- close = async () => {
37381
- if (this.#server.listening) {
37382
- await new Promise((resolve6, reject) => {
37383
- this.#server.close((error62) => {
37384
- if (error62 === void 0) {
37385
- resolve6();
37386
- return;
37387
- }
37388
- reject(error62);
37389
- });
37390
- });
37391
- }
37392
- if (this.#usesFilesystemSocket) {
37393
- await unlink(this.#socketPath).catch((error62) => {
37394
- if (!isRecord10(error62) || error62["code"] !== "ENOENT") {
37395
- throw error62;
37396
- }
37397
- });
37398
- }
37399
- };
37400
- #abort = () => {
37401
- this.#server.close();
37402
- };
37403
- abort = () => this.#abort();
37404
- accept = (socket) => {
37405
- const chunks = [];
37406
- let length = 0;
37407
- let rejected = false;
37408
- const controller = new AbortController();
37409
- socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS, () => {
37410
- controller.abort(new Error("Bot IPC request timed out"));
37411
- socket.destroy();
37412
- });
37413
- socket.on("data", (chunk) => {
37414
- length += chunk.byteLength;
37415
- if (length > BOT_IPC_REQUEST_LIMIT) {
37416
- rejected = true;
37417
- controller.abort(new Error("Bot IPC request is too large"));
37418
- socket.end(
37419
- JSON.stringify({
37420
- error: { code: "invalid_request", message: "The local Bot request is too large" },
37421
- ok: false
37422
- })
37423
- );
37424
- return;
37425
- }
37426
- chunks.push(chunk);
37427
- });
37428
- socket.once("error", () => controller.abort());
37429
- socket.once("close", () => controller.abort());
37430
- socket.once("end", () => {
37431
- if (rejected) {
37432
- return;
37433
- }
37434
- void this.handle(Buffer.concat(chunks).toString("utf8").trim(), controller.signal).then(
37435
- (outboundMessageId) => {
37436
- if (!socket.destroyed) {
37437
- socket.end(JSON.stringify({ ok: true, outboundMessageId }));
37438
- }
37439
- },
37440
- (error62) => {
37441
- if (socket.destroyed) {
37442
- return;
37443
- }
37444
- const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "bot_service_unavailable";
37445
- const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local Bot action could not be completed";
37446
- socket.end(JSON.stringify({ error: { code, message }, ok: false }));
37447
- }
37448
- );
37449
- });
37450
- };
37451
- handle = async (encoded, signal) => {
37452
- const request = decodeRequest(encoded);
37453
- const context = this.#registry.read(request.contextHandle);
37454
- const timeout = AbortSignal.timeout(BOT_RELAY_TIMEOUT_MILLISECONDS);
37455
- const requestSignal = AbortSignal.any([signal, timeout]);
37456
- let response;
37457
- try {
37458
- response = await fetch4(relayEndpoint(this.#relayUrl, context, request.target), {
37459
- body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
37460
- headers: {
37461
- authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
37462
- "content-type": "application/json",
37463
- "x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
37464
- },
37465
- method: "POST",
37466
- signal: requestSignal
37467
- });
37468
- } catch (cause) {
37469
- signal.throwIfAborted();
37470
- throw new LocalBotAuthorizationError(
37471
- timeout.aborted ? "bot_service_timeout" : "bot_service_unavailable",
37472
- timeout.aborted ? "The Mobius Bot action timed out" : "The Mobius Relay is unavailable",
37473
- { cause }
37474
- );
37475
- }
37476
- return await decodeRelayResponse(response);
37477
- };
37478
- };
37479
-
37480
36889
  // src/native-sessions/service.ts
37481
36890
  import { randomUUID } from "node:crypto";
37482
- import { basename as basename4 } from "node:path";
36891
+ import { basename as basename5 } from "node:path";
37483
36892
 
37484
36893
  // src/native-sessions/codex-history.ts
37485
36894
  import { spawn as spawn4 } from "node:child_process";
@@ -37988,7 +37397,7 @@ var NativeSessionService = class {
37988
37397
  }
37989
37398
  resolvedPaths.add(path2);
37990
37399
  additionalDirectories.push(path2);
37991
- additionalEntries.push({ directoryId: directoryId2, name: basename4(path2) });
37400
+ additionalEntries.push({ directoryId: directoryId2, name: basename5(path2) });
37992
37401
  }
37993
37402
  const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
37994
37403
  const opened = await this.#sessions.forkSessionAtTurn(
@@ -38146,12 +37555,12 @@ var NativeSessionService = class {
38146
37555
 
38147
37556
  // src/prompt-artifact-resolver.ts
38148
37557
  import { createHash as createHash3 } from "node:crypto";
38149
- import { fetch as fetch5 } from "undici";
37558
+ import { fetch as fetch4 } from "undici";
38150
37559
  var ARTIFACT_SCHEME = "mobius-artifact:";
38151
37560
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
38152
37561
  var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
38153
37562
  var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
38154
- var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
37563
+ var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
38155
37564
  var PromptArtifactError = class extends Error {
38156
37565
  code;
38157
37566
  constructor(code, message, options = {}) {
@@ -38194,7 +37603,7 @@ function parseReference(resource) {
38194
37603
  const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
38195
37604
  const sha256 = url2.searchParams.get("sha256") ?? "";
38196
37605
  const byteLength = Number(encodedByteLength2);
38197
- if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN7.test(artifactId) || keys.length !== 2 || keys[0] !== "byteLength" || keys[1] !== "sha256" || !/^[1-9][0-9]*$/.test(encodedByteLength2) || !Number.isSafeInteger(byteLength) || !/^[a-f0-9]{64}$/.test(sha256)) {
37606
+ if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN5.test(artifactId) || keys.length !== 2 || keys[0] !== "byteLength" || keys[1] !== "sha256" || !/^[1-9][0-9]*$/.test(encodedByteLength2) || !Number.isSafeInteger(byteLength) || !/^[a-f0-9]{64}$/.test(sha256)) {
38198
37607
  throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
38199
37608
  }
38200
37609
  return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
@@ -38260,7 +37669,7 @@ async function download(config2, command, reference, signal) {
38260
37669
  const requestSignal = AbortSignal.any([signal, timeoutSignal]);
38261
37670
  let response;
38262
37671
  try {
38263
- response = await fetch5(downloadUrl(config2, command, reference), {
37672
+ response = await fetch4(downloadUrl(config2, command, reference), {
38264
37673
  dispatcher: environmentProxyDispatcher,
38265
37674
  headers: {
38266
37675
  accept: reference.resource.mimeType,
@@ -38698,7 +38107,7 @@ var RelayConnectionLiveness = class {
38698
38107
 
38699
38108
  // src/relay-connection/session-event-outbox.ts
38700
38109
  import { mkdirSync as mkdirSync3 } from "node:fs";
38701
- import { dirname as dirname7 } from "node:path";
38110
+ import { dirname as dirname6 } from "node:path";
38702
38111
  import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
38703
38112
  var DEFAULT_OUTBOX_LIMITS = {
38704
38113
  criticalEventBytes: 136 * 1024 * 1024,
@@ -38764,7 +38173,7 @@ var SessionEventOutbox = class {
38764
38173
  constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
38765
38174
  validateLimits(limits);
38766
38175
  this.#limits = limits;
38767
- mkdirSync3(dirname7(path2), { recursive: true });
38176
+ mkdirSync3(dirname6(path2), { recursive: true });
38768
38177
  this.#database = new DatabaseSync3(path2);
38769
38178
  this.#database.exec(`
38770
38179
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
@@ -39297,12 +38706,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
39297
38706
  var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
39298
38707
  var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
39299
38708
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
39300
- function botIpcSocketPath() {
39301
- if (process.platform === "win32") {
39302
- return `\\\\.\\pipe\\mobius-bot-${randomUUID3()}`;
39303
- }
39304
- return join16("/tmp", `mobius-bot-${randomUUID3()}.sock`);
39305
- }
39306
38709
  var DaemonAcpObserver = class {
39307
38710
  #config;
39308
38711
  #record;
@@ -39520,7 +38923,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
39520
38923
  const requestSignal = AbortSignal.any([signal, timeoutSignal]);
39521
38924
  let response;
39522
38925
  try {
39523
- response = await fetch6(activeTurnReconciliationEndpoint(config2, turn), {
38926
+ response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
39524
38927
  body: JSON.stringify({ outcome: { kind: "running" } }),
39525
38928
  dispatcher: environmentProxyDispatcher,
39526
38929
  headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
@@ -39832,13 +39235,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
39832
39235
  );
39833
39236
  }
39834
39237
  function operationErrorCode(error62) {
39835
- if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof LocalBotAuthorizationError || error62 instanceof PromptArtifactError) {
39238
+ if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
39836
39239
  return error62.code;
39837
39240
  }
39838
39241
  return "session_operation_failed";
39839
39242
  }
39840
39243
  function operationErrorMessage(error62) {
39841
- if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof LocalBotAuthorizationError || error62 instanceof PromptArtifactError) {
39244
+ if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
39842
39245
  return error62.message;
39843
39246
  }
39844
39247
  return "The local agent operation could not be completed";
@@ -39873,7 +39276,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
39873
39276
  additionalDirectories.push(directory);
39874
39277
  additionalDirectoryEntries.push({
39875
39278
  directoryId: additionalDirectoryId,
39876
- name: basename5(directory)
39279
+ name: basename6(directory)
39877
39280
  });
39878
39281
  }
39879
39282
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
@@ -40425,37 +39828,6 @@ async function applyCompleteSessionConfiguration(sessions, audit, initialOptions
40425
39828
  }
40426
39829
  assertAppliedSessionConfiguration(options, selections);
40427
39830
  }
40428
- function botExecutionAgent(agent, contextHandle, socketPath) {
40429
- return new LocalAgentDefinition(
40430
- agent.id,
40431
- agent.label,
40432
- agent.command,
40433
- agent.arguments,
40434
- {
40435
- ...agent.environment,
40436
- MOBIUS_BOT_CONTEXT: contextHandle,
40437
- MOBIUS_BOT_SOCKET: socketPath,
40438
- MOBIUS_RELAY_TOKEN: "",
40439
- MOBIUS_RELAY_URL: ""
40440
- },
40441
- agent.adapterVersion,
40442
- agent.agentVersion,
40443
- agent.adapterIdentity,
40444
- agent.agentIdentity,
40445
- agent.capabilities,
40446
- agent.permissionProfile
40447
- );
40448
- }
40449
- function assertPreparedPermission(configOptions, permissionMode) {
40450
- const permission = configOptions.find((option) => option.id === "permission_mode");
40451
- if (permission === void 0 || permission.type !== "select" || permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode) {
40452
- throw new AcpExecutionError(
40453
- "The required Agent permission mode is unavailable",
40454
- {},
40455
- "invalid_session_configuration"
40456
- );
40457
- }
40458
- }
40459
39831
  function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
40460
39832
  const details = {
40461
39833
  agentId,
@@ -40468,274 +39840,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
40468
39840
  process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
40469
39841
  `);
40470
39842
  }
40471
- async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40472
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40473
- return configOptions;
40474
- }
40475
- const option = configOptions.find((candidate) => candidate.id === selection.configId);
40476
- if (option === void 0) {
40477
- warnIgnoredSetting(
40478
- audit,
40479
- "bot_execution_setting_ignored",
40480
- commandId,
40481
- sessionId,
40482
- agent.id,
40483
- selection,
40484
- category,
40485
- "setting_unavailable"
40486
- );
40487
- return configOptions;
40488
- }
40489
- if (option.type !== "select" || option.category !== category) {
40490
- warnIgnoredSetting(
40491
- audit,
40492
- "bot_execution_setting_ignored",
40493
- commandId,
40494
- sessionId,
40495
- agent.id,
40496
- selection,
40497
- category,
40498
- "setting_schema_mismatch"
40499
- );
40500
- return configOptions;
40501
- }
40502
- if (selection.valueType !== "select" || selection.booleanValue) {
40503
- warnIgnoredSetting(
40504
- audit,
40505
- "bot_execution_setting_ignored",
40506
- commandId,
40507
- sessionId,
40508
- agent.id,
40509
- selection,
40510
- category,
40511
- "selection_schema_mismatch"
40512
- );
40513
- return configOptions;
40514
- }
40515
- if (!option.values.some((value) => value.value === selection.value)) {
40516
- warnIgnoredSetting(
40517
- audit,
40518
- "bot_execution_setting_ignored",
40519
- commandId,
40520
- sessionId,
40521
- agent.id,
40522
- selection,
40523
- category,
40524
- "value_unavailable"
40525
- );
40526
- return configOptions;
40527
- }
40528
- if (option.currentValue === selection.value) {
40529
- return configOptions;
40530
- }
40531
- return await sessions.configureSession({
40532
- additionalDirectories,
40533
- agent,
40534
- booleanValue: false,
40535
- configId: selection.configId,
40536
- cwd,
40537
- requestId: `cfg_${randomUUID3()}`,
40538
- sessionId,
40539
- signal,
40540
- value: selection.value,
40541
- valueType: "select"
40542
- });
40543
- }
40544
- async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
40545
- const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40546
- publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40547
- });
40548
- try {
40549
- const startDeadline = Date.parse(command.executionDeadlineAt);
40550
- if (!Number.isSafeInteger(startDeadline) || startDeadline <= Date.now()) {
40551
- throw new LocalBotAuthorizationError("turn_expired", "The Bot execution start deadline has expired");
40552
- }
40553
- const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
40554
- const resolved = await resolveSessionDirectories(
40555
- directories,
40556
- config2.bindingId,
40557
- command.directoryId,
40558
- command.additionalDirectoryIds,
40559
- signal
40560
- );
40561
- const attachments = await resolvePromptArtifacts(config2, command, signal);
40562
- const applied = await applicator.apply(command, execution, attachments.resources, signal);
40563
- const startExecution = () => {
40564
- audit.record({
40565
- commandId: command.commandId,
40566
- details: {
40567
- behaviorRevisionId: command.behaviorRevisionId,
40568
- bindingId: command.bindingId,
40569
- botId: command.botId,
40570
- executionId: command.executionId
40571
- },
40572
- event: "bot_session_authorized",
40573
- sessionId: command.sessionId
40574
- });
40575
- outbox.transitionExecution(command.commandId, "running");
40576
- publisher.recordAttempt(
40577
- command.sessionId,
40578
- encodeSessionStartedEvent({
40579
- attemptId,
40580
- commandId: command.commandId,
40581
- kind: SESSION_STARTED_KIND,
40582
- sessionId: command.sessionId
40583
- }),
40584
- attemptId
40585
- );
40586
- activateAttempt();
40587
- };
40588
- let stopReason = "steered";
40589
- if (command.disposition === SessionPromptDisposition.Steer) {
40590
- startExecution();
40591
- await sessions.steerPrompt({
40592
- additionalDirectories: resolved.additionalDirectories,
40593
- agent: execution.agent,
40594
- commandId: command.commandId,
40595
- cwd: resolved.cwd,
40596
- images: attachments.images,
40597
- prompt: command.prompt,
40598
- resources: applied.resources,
40599
- sessionId: command.sessionId,
40600
- signal,
40601
- targetCommandId: command.targetCommandId
40602
- });
40603
- } else {
40604
- if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
40605
- throw new AcpExecutionError(
40606
- "The queued Bot prompt target is unavailable",
40607
- {},
40608
- "prompt_queue_target_unavailable"
40609
- );
40610
- }
40611
- const lease = contexts.activate(command);
40612
- try {
40613
- const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
40614
- const prepared = await sessions.prepareExecutionSession({
40615
- additionalDirectories: resolved.additionalDirectories,
40616
- agent,
40617
- cwd: resolved.cwd,
40618
- sessionId: command.sessionId,
40619
- signal
40620
- });
40621
- assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
40622
- let configOptions = await applySupportedExecutionSelection(
40623
- sessions,
40624
- audit,
40625
- prepared.configOptions,
40626
- execution.executionConfiguration.model,
40627
- "model",
40628
- agent,
40629
- resolved.cwd,
40630
- resolved.additionalDirectories,
40631
- command.commandId,
40632
- command.sessionId,
40633
- signal
40634
- );
40635
- configOptions = await applySupportedExecutionSelection(
40636
- sessions,
40637
- audit,
40638
- configOptions,
40639
- execution.executionConfiguration.reasoningEffort,
40640
- "thought_level",
40641
- agent,
40642
- resolved.cwd,
40643
- resolved.additionalDirectories,
40644
- command.commandId,
40645
- command.sessionId,
40646
- signal
40647
- );
40648
- for (const selection of command.sessionConfigurations) {
40649
- await sessions.configureSession({
40650
- additionalDirectories: resolved.additionalDirectories,
40651
- agent,
40652
- booleanValue: selection.booleanValue,
40653
- configId: selection.configId,
40654
- cwd: resolved.cwd,
40655
- requestId: `cfg_${randomUUID3()}`,
40656
- sessionId: command.sessionId,
40657
- signal,
40658
- value: selection.value,
40659
- valueType: selection.valueType
40660
- });
40661
- }
40662
- startExecution();
40663
- const result = await sessions.runPrompt({
40664
- additionalDirectories: resolved.additionalDirectories,
40665
- agent,
40666
- commandId: command.commandId,
40667
- cwd: resolved.cwd,
40668
- disposition: command.disposition,
40669
- images: attachments.images,
40670
- onActivity: activities.record,
40671
- onText: (text3, messageId) => {
40672
- publisher.recordAttempt(
40673
- command.sessionId,
40674
- encodeAgentMessageDeltaEvent({
40675
- commandId: command.commandId,
40676
- kind: AGENT_MESSAGE_DELTA_KIND,
40677
- messageId,
40678
- sessionId: command.sessionId,
40679
- text: text3
40680
- }),
40681
- attemptId
40682
- );
40683
- return Promise.resolve();
40684
- },
40685
- prompt: command.prompt,
40686
- resources: applied.resources,
40687
- sessionId: command.sessionId,
40688
- signal,
40689
- targetCommandId: command.targetCommandId
40690
- });
40691
- stopReason = result.stopReason;
40692
- } finally {
40693
- lease.release();
40694
- }
40695
- }
40696
- activities.flush();
40697
- publisher.recordAttempt(
40698
- command.sessionId,
40699
- encodeSessionCompletedEvent({
40700
- commandId: command.commandId,
40701
- kind: SESSION_COMPLETED_KIND,
40702
- sessionId: command.sessionId,
40703
- stopReason
40704
- }),
40705
- attemptId
40706
- );
40707
- outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
40708
- audit.record({
40709
- commandId: command.commandId,
40710
- details: { botId: command.botId, executionId: command.executionId },
40711
- event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
40712
- sessionId: command.sessionId
40713
- });
40714
- } catch (error62) {
40715
- activities.flush();
40716
- const failure2 = error62;
40717
- audit.record({
40718
- commandId: command.commandId,
40719
- details: {
40720
- botId: command.botId,
40721
- code: operationErrorCode(failure2),
40722
- executionId: command.executionId
40723
- },
40724
- event: "bot_session_failed",
40725
- sessionId: command.sessionId
40726
- });
40727
- const code = operationErrorCode(failure2);
40728
- reportFailure(
40729
- publisher,
40730
- command,
40731
- code === "session_operation_failed" ? "agent_execution_failed" : code,
40732
- code === "session_operation_failed" ? "The local agent could not complete the Bot request" : operationErrorMessage(failure2),
40733
- attemptId
40734
- );
40735
- outbox.transitionExecution(command.commandId, "failed");
40736
- console.error("Mobius daemon Bot command failed", failure2);
40737
- }
40738
- }
40739
39843
  function waitForRelayRetry(signal, timer) {
40740
39844
  if (signal.aborted) {
40741
39845
  return Promise.resolve();
@@ -40788,7 +39892,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
40788
39892
  );
40789
39893
  }
40790
39894
  }
40791
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, authorizer, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
39895
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
40792
39896
  const relayUrl = new URL(config2.relayUrl);
40793
39897
  relayUrl.searchParams.set("deliveryReceipts", "1");
40794
39898
  relayUrl.searchParams.set("liveness", "1");
@@ -40954,32 +40058,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40954
40058
  }
40955
40059
  return;
40956
40060
  }
40957
- if (kind === BOT_SESSION_PROMPT_KIND) {
40958
- const command = decodeBotSessionPromptCommand(delivery.payload);
40959
- await processDeliveredPrompt(
40960
- delivery,
40961
- command,
40962
- command.disposition !== SessionPromptDisposition.Steer,
40963
- (attemptId, activateAttempt, executionSignal) => executeBotPrompt(
40964
- outbox,
40965
- publisher,
40966
- command,
40967
- config2,
40968
- directories,
40969
- audit,
40970
- sessions,
40971
- authorizer,
40972
- contexts,
40973
- applicator,
40974
- ipc,
40975
- attemptId,
40976
- activateAttempt,
40977
- timer,
40978
- executionSignal
40979
- )
40980
- );
40981
- return;
40982
- }
40983
40061
  if (kind === SESSION_PROMPT_KIND) {
40984
40062
  const command = decodeSessionPromptCommand(delivery.payload);
40985
40063
  await processDeliveredPrompt(
@@ -41037,8 +40115,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41037
40115
  payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
41038
40116
  } else if (payloadKind === SESSION_PROMPT_KIND) {
41039
40117
  payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
41040
- } else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
41041
- payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
41042
40118
  } else {
41043
40119
  throw new Error("Runtime delivery contains an unsupported protocol message");
41044
40120
  }
@@ -41431,6 +40507,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41431
40507
  connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
41432
40508
  return;
41433
40509
  }
40510
+ if (kind === FILE_READ_KIND) {
40511
+ const command2 = decodeFileReadCommand(encoded);
40512
+ void streamLocalFile(
40513
+ command2,
40514
+ (message) => send(socket, message),
40515
+ connectionController.signal
40516
+ ).catch((error62) => {
40517
+ if (socket.readyState !== WebSocket2.OPEN || connectionController.signal.aborted) {
40518
+ return;
40519
+ }
40520
+ send(
40521
+ socket,
40522
+ encodeFileFailedEvent({
40523
+ code: "file_unavailable",
40524
+ kind: FILE_FAILED_KIND,
40525
+ message: error62 instanceof Error ? error62.message : "The local file is unavailable",
40526
+ requestId: command2.requestId,
40527
+ sessionId: command2.sessionId
40528
+ })
40529
+ );
40530
+ });
40531
+ return;
40532
+ }
41434
40533
  if (kind === SESSION_CANCEL_KIND) {
41435
40534
  const cancellation = decodeSessionCancelCommand(encoded);
41436
40535
  const turn2 = activeTurns.get(cancellation.commandId);
@@ -41524,48 +40623,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41524
40623
  });
41525
40624
  return;
41526
40625
  }
41527
- if (kind === BOT_SESSION_PROMPT_KIND) {
41528
- const command2 = decodeBotSessionPromptCommand(encoded);
41529
- if (activeTurns.has(command2.commandId)) {
41530
- return;
41531
- }
41532
- const receipt2 = outbox.claimExecution(command2.commandId, command2.sessionId, encoded);
41533
- if (receipt2.kind === "duplicate") {
41534
- return;
41535
- }
41536
- const turn2 = new ActiveDaemonTurn(command2, receipt2.attemptId);
41537
- activeTurns.set(command2.commandId, turn2);
41538
- void executeBotPrompt(
41539
- outbox,
41540
- publisher,
41541
- command2,
41542
- config2,
41543
- directories,
41544
- audit,
41545
- sessions,
41546
- authorizer,
41547
- contexts,
41548
- applicator,
41549
- ipc,
41550
- receipt2.attemptId,
41551
- () => {
41552
- if (command2.disposition !== SessionPromptDisposition.Steer) {
41553
- activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
41554
- }
41555
- },
41556
- timer,
41557
- turn2.signal
41558
- ).catch((error62) => {
41559
- console.error("Mobius daemon Bot turn failed", error62);
41560
- }).finally(() => {
41561
- activeTurns.delete(command2.commandId);
41562
- if (activeAttemptIds.get(command2.sessionId) === receipt2.attemptId) {
41563
- activeAttemptIds.delete(command2.sessionId);
41564
- }
41565
- turn2.finish();
41566
- });
41567
- return;
41568
- }
41569
40626
  if (kind !== SESSION_PROMPT_KIND) {
41570
40627
  throw new Error("Unsupported protocol message");
41571
40628
  }
@@ -41669,10 +40726,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41669
40726
  const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
41670
40727
  const outbox = new SessionEventOutbox(config2.auditDatabasePath);
41671
40728
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
41672
- const authorizer = new LocalBotExecutionAuthorizer();
41673
- const contexts = new BotExecutionContextRegistry();
41674
- const applicator = new EmbeddedBotContextApplicator();
41675
- const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
41676
40729
  const activeTurns = /* @__PURE__ */ new Map();
41677
40730
  const activeAttemptIds = /* @__PURE__ */ new Map();
41678
40731
  const recordSessionEvent = (sessionId, payload) => {
@@ -41746,7 +40799,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41746
40799
  startAutomaticIntegrationProvisioning();
41747
40800
  });
41748
40801
  try {
41749
- await ipc.listen(signal);
41750
40802
  while (!signal.aborted) {
41751
40803
  connectionEpoch += 1;
41752
40804
  try {
@@ -41760,10 +40812,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41760
40812
  nativeSessions,
41761
40813
  outbox,
41762
40814
  publisher,
41763
- authorizer,
41764
- contexts,
41765
- applicator,
41766
- ipc,
41767
40815
  activeTurns,
41768
40816
  activeAttemptIds,
41769
40817
  connectionEpoch,
@@ -41796,19 +40844,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41796
40844
  await installations.close();
41797
40845
  } finally {
41798
40846
  try {
41799
- await ipc.close();
40847
+ await sessions.close();
41800
40848
  } finally {
41801
40849
  try {
41802
- await sessions.close();
40850
+ sessionStore.close();
41803
40851
  } finally {
41804
40852
  try {
41805
- sessionStore.close();
40853
+ publisher.close();
41806
40854
  } finally {
41807
- try {
41808
- publisher.close();
41809
- } finally {
41810
- outbox.close();
41811
- }
40855
+ outbox.close();
41812
40856
  }
41813
40857
  }
41814
40858
  }
@@ -41820,14 +40864,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41820
40864
 
41821
40865
  // src/pairing/pair-local-machine.ts
41822
40866
  import { randomUUID as randomUUID4 } from "node:crypto";
41823
- import { mkdir as mkdir4, open as open4, realpath as realpath8, rename as rename3, stat as stat7, writeFile as writeFile2 } from "node:fs/promises";
40867
+ import { mkdir as mkdir3, open as open5, realpath as realpath9, rename as rename3, stat as stat8, writeFile as writeFile2 } from "node:fs/promises";
41824
40868
  import { hostname as hostname3 } from "node:os";
41825
- import { basename as basename6, join as join17, resolve as resolve4 } from "node:path";
41826
- import { fetch as fetch7 } from "undici";
40869
+ import { basename as basename7, join as join16, resolve as resolve4 } from "node:path";
40870
+ import { fetch as fetch6 } from "undici";
41827
40871
  var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
41828
40872
  var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
41829
- var IDENTIFIER_PATTERN8 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
41830
- var TOKEN_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
40873
+ var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
40874
+ var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
41831
40875
  var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
41832
40876
  var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
41833
40877
  var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
@@ -41841,7 +40885,7 @@ var PairingClientError = class extends Error {
41841
40885
  this.name = "PairingClientError";
41842
40886
  }
41843
40887
  };
41844
- function isRecord11(value) {
40888
+ function isRecord9(value) {
41845
40889
  return typeof value === "object" && value !== null && !Array.isArray(value);
41846
40890
  }
41847
40891
  function hasExactKeys(value, expectedKeys) {
@@ -41880,7 +40924,7 @@ function parsePairingCode(value) {
41880
40924
  return code;
41881
40925
  }
41882
40926
  function validatePairingId(value) {
41883
- if (!IDENTIFIER_PATTERN8.test(value)) {
40927
+ if (!IDENTIFIER_PATTERN6.test(value)) {
41884
40928
  throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
41885
40929
  }
41886
40930
  return value;
@@ -41888,9 +40932,9 @@ function validatePairingId(value) {
41888
40932
  async function resolveDefaultWorkspace2(path2) {
41889
40933
  const requestedWorkspace = resolve4(path2);
41890
40934
  try {
41891
- await mkdir4(requestedWorkspace, { recursive: true, mode: 448 });
41892
- const defaultWorkspace = await realpath8(requestedWorkspace);
41893
- const metadata = await stat7(defaultWorkspace);
40935
+ await mkdir3(requestedWorkspace, { recursive: true, mode: 448 });
40936
+ const defaultWorkspace = await realpath9(requestedWorkspace);
40937
+ const metadata = await stat8(defaultWorkspace);
41894
40938
  if (!metadata.isDirectory()) {
41895
40939
  throw new PairingClientError("invalid_workspace", "The default workspace is not a directory");
41896
40940
  }
@@ -41919,9 +40963,9 @@ async function readJsonResponse(response) {
41919
40963
  }
41920
40964
  }
41921
40965
  function readRelayError(value) {
41922
- if (isRecord11(value)) {
40966
+ if (isRecord9(value)) {
41923
40967
  const error62 = value["error"];
41924
- if (isRecord11(error62)) {
40968
+ if (isRecord9(error62)) {
41925
40969
  const code = error62["code"];
41926
40970
  const message = error62["message"];
41927
40971
  if (typeof code === "string" && typeof message === "string") {
@@ -41932,13 +40976,13 @@ function readRelayError(value) {
41932
40976
  return new PairingClientError("pairing_failed", "The relay could not pair this machine");
41933
40977
  }
41934
40978
  function decodePairingResponse(value, credentialField, expectedKeys) {
41935
- if (!isRecord11(value) || !hasExactKeys(value, expectedKeys)) {
40979
+ if (!isRecord9(value) || !hasExactKeys(value, expectedKeys)) {
41936
40980
  throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
41937
40981
  }
41938
40982
  const channelId = value["channelId"];
41939
40983
  const runtimeCredential2 = value[credentialField];
41940
40984
  const runtimeId = value["runtimeId"];
41941
- if (typeof channelId !== "string" || !IDENTIFIER_PATTERN8.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN2.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN8.test(runtimeId)) {
40985
+ if (typeof channelId !== "string" || !IDENTIFIER_PATTERN6.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN6.test(runtimeId)) {
41942
40986
  throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
41943
40987
  }
41944
40988
  return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
@@ -41948,7 +40992,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
41948
40992
  agentPath: agent.agentIdentity.requestedPath,
41949
40993
  agentVersion: agent.agentVersion,
41950
40994
  agentSettingsDiscovery: true,
41951
- botSessionConfiguration: true,
41952
40995
  capabilities: agent.capabilities,
41953
40996
  id: agent.id,
41954
40997
  label: agent.label,
@@ -41957,13 +41000,13 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
41957
41000
  const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
41958
41001
  let response;
41959
41002
  try {
41960
- response = await fetch7(endpoint, {
41003
+ response = await fetch6(endpoint, {
41961
41004
  body: JSON.stringify({
41962
41005
  agents,
41963
41006
  installableAgents,
41964
41007
  machineName: hostname3(),
41965
41008
  pairingCode: options.code,
41966
- workspaceName: basename6(defaultWorkspace) || "Local workspace"
41009
+ workspaceName: basename7(defaultWorkspace) || "Local workspace"
41967
41010
  }),
41968
41011
  dispatcher: environmentProxyDispatcher,
41969
41012
  headers: { "content-type": "application/json" },
@@ -41980,10 +41023,10 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
41980
41023
  return options.pairingId.length > 0 ? decodePairingResponse(value, "runtimeCredential", REDEEM_RESPONSE_KEYS) : decodePairingResponse(value, "daemonToken", CLAIM_RESPONSE_KEYS);
41981
41024
  }
41982
41025
  async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
41983
- const connectionsDirectory = join17(readStateDirectory(environment), "connections");
41984
- await mkdir4(connectionsDirectory, { mode: 448, recursive: true });
41985
- const connectionPath = join17(connectionsDirectory, `${channelId}.json`);
41986
- const temporaryPath = join17(connectionsDirectory, `.${channelId}.${randomUUID4()}.tmp`);
41026
+ const connectionsDirectory = join16(readStateDirectory(environment), "connections");
41027
+ await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
41028
+ const connectionPath = join16(connectionsDirectory, `${channelId}.json`);
41029
+ const temporaryPath = join16(connectionsDirectory, `.${channelId}.${randomUUID4()}.tmp`);
41987
41030
  await writeFile2(
41988
41031
  temporaryPath,
41989
41032
  `${JSON.stringify(
@@ -42003,14 +41046,14 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
42003
41046
  return connectionPath;
42004
41047
  }
42005
41048
  function decodeSavedConnection(value, expectedChannelId) {
42006
- if (!isRecord11(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
41049
+ if (!isRecord9(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
42007
41050
  throw new PairingClientError("invalid_connection", "The saved connection is invalid");
42008
41051
  }
42009
41052
  const defaultWorkspace = value["defaultWorkspace"];
42010
41053
  const channelId = value["channelId"];
42011
41054
  const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
42012
41055
  const relayOrigin = value["relayOrigin"];
42013
- if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN8.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN2.test(runtimeCredential2) || typeof relayOrigin !== "string") {
41056
+ if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN6.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof relayOrigin !== "string") {
42014
41057
  throw new PairingClientError("invalid_connection", "The saved connection is invalid");
42015
41058
  }
42016
41059
  return {
@@ -42021,9 +41064,9 @@ function decodeSavedConnection(value, expectedChannelId) {
42021
41064
  };
42022
41065
  }
42023
41066
  async function readSavedConnection(channelId, environment) {
42024
- const connectionPath = join17(readStateDirectory(environment), "connections", `${channelId}.json`);
41067
+ const connectionPath = join16(readStateDirectory(environment), "connections", `${channelId}.json`);
42025
41068
  let encoded = "";
42026
- const handle = await open4(connectionPath, "r");
41069
+ const handle = await open5(connectionPath, "r");
42027
41070
  try {
42028
41071
  const metadata = await handle.stat();
42029
41072
  if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
@@ -42057,7 +41100,7 @@ function buildPairedDaemon(connection, connectionPath, inventory, environment) {
42057
41100
  const relayUrl = mobiusApiUrl(connection.relayOrigin, "/v1/runtimes/connect");
42058
41101
  relayUrl.protocol = relayUrl.protocol === "https:" ? "wss:" : "ws:";
42059
41102
  relayUrl.searchParams.set("token", connection.runtimeCredential);
42060
- const auditDatabasePath = join17(readStateDirectory(environment), "audit", `${connection.channelId}.sqlite`);
41103
+ const auditDatabasePath = join16(readStateDirectory(environment), "audit", `${connection.channelId}.sqlite`);
42061
41104
  return {
42062
41105
  channelUrl: new URL(`/channels/${encodeURIComponent(connection.channelId)}`, connection.relayOrigin).toString(),
42063
41106
  config: createDaemonConfig(
@@ -42116,7 +41159,7 @@ async function pairMobiusRuntime(options, signal, environment = process.env) {
42116
41159
  }
42117
41160
  async function resumeMobiusRuntime(channelId, signal, environment = process.env) {
42118
41161
  const normalizedChannelId = validatePairingId(channelId);
42119
- const connectionPath = join17(readStateDirectory(environment), "connections", `${normalizedChannelId}.json`);
41162
+ const connectionPath = join16(readStateDirectory(environment), "connections", `${normalizedChannelId}.json`);
42120
41163
  const connection = await readSavedConnection(normalizedChannelId, environment);
42121
41164
  const inventory = await discoverLocalAgentInventory({
42122
41165
  defaultWorkspace: connection.defaultWorkspace,
@@ -42127,7 +41170,7 @@ async function resumeMobiusRuntime(channelId, signal, environment = process.env)
42127
41170
  }
42128
41171
 
42129
41172
  // src/runtime.ts
42130
- var IDENTIFIER_PATTERN9 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
41173
+ var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
42131
41174
  var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
42132
41175
  var MobiusRuntimeConfigurationError = class extends Error {
42133
41176
  code = "runtime_configuration_invalid";
@@ -42179,11 +41222,11 @@ function relayUrlFromConnection(connection) {
42179
41222
  }
42180
41223
  function loadMobiusRuntimeConnection(environment = process.env) {
42181
41224
  const channelId = requiredEnvironmentValue(environment, "MOBIUS_CHANNEL_ID");
42182
- if (!IDENTIFIER_PATTERN9.test(channelId)) {
41225
+ if (!IDENTIFIER_PATTERN7.test(channelId)) {
42183
41226
  throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
42184
41227
  }
42185
41228
  return Object.freeze({
42186
- auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join18(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
41229
+ auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join17(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
42187
41230
  channelId,
42188
41231
  defaultWorkspace: loadDefaultWorkspace(environment),
42189
41232
  relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
@@ -42193,9 +41236,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
42193
41236
  async function resolveWorkspace(path2) {
42194
41237
  const requested = resolve5(path2);
42195
41238
  try {
42196
- await mkdir5(requested, { recursive: true, mode: 448 });
42197
- const resolved = await realpath9(requested);
42198
- const metadata = await stat8(resolved);
41239
+ await mkdir4(requested, { recursive: true, mode: 448 });
41240
+ const resolved = await realpath10(requested);
41241
+ const metadata = await stat9(resolved);
42199
41242
  if (!metadata.isDirectory()) {
42200
41243
  throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
42201
41244
  }
@@ -42212,7 +41255,7 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
42212
41255
  const relayUrl = relayUrlFromConnection(connection);
42213
41256
  const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
42214
41257
  const auditDatabasePath = resolve5(connection.auditDatabasePath);
42215
- await mkdir5(dirname8(auditDatabasePath), { recursive: true, mode: 448 });
41258
+ await mkdir4(dirname7(auditDatabasePath), { recursive: true, mode: 448 });
42216
41259
  const inventory = await discoverLocalAgentInventory({
42217
41260
  defaultWorkspace,
42218
41261
  environment,