@moxt-ai/mobius 0.0.334 → 0.0.336

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 (36) hide show
  1. package/dist/cli.js +407 -132
  2. package/dist/cli.js.map +4 -4
  3. package/dist/daemon/control/protocol.d.ts +2 -0
  4. package/dist/daemon/control/protocol.d.ts.map +1 -1
  5. package/dist/daemon/control/protocol.js +25 -0
  6. package/dist/daemon/control/protocol.js.map +1 -1
  7. package/dist/daemon/control/switch-status.d.ts.map +1 -1
  8. package/dist/daemon/control/switch-status.js +3 -3
  9. package/dist/daemon/control/switch-status.js.map +1 -1
  10. package/dist/daemon/lifecycle/manager-client.d.ts.map +1 -1
  11. package/dist/daemon/lifecycle/manager-client.js +12 -12
  12. package/dist/daemon/lifecycle/manager-client.js.map +1 -1
  13. package/dist/daemon/lifecycle/manager.d.ts.map +1 -1
  14. package/dist/daemon/lifecycle/manager.js +4 -9
  15. package/dist/daemon/lifecycle/manager.js.map +1 -1
  16. package/dist/daemon/upgrades/upgrade.d.ts.map +1 -1
  17. package/dist/daemon/upgrades/upgrade.js +4 -4
  18. package/dist/daemon/upgrades/upgrade.js.map +1 -1
  19. package/dist/runtime/relay/run-relay-connection.d.ts.map +1 -1
  20. package/dist/runtime/relay/run-relay-connection.js +5 -57
  21. package/dist/runtime/relay/run-relay-connection.js.map +1 -1
  22. package/dist/runtime.js +263 -102
  23. package/dist/runtime.js.map +4 -4
  24. package/dist/session/live/agent-session.d.ts.map +1 -1
  25. package/dist/session/live/agent-session.js +2 -1
  26. package/dist/session/live/agent-session.js.map +1 -1
  27. package/dist/session/live/session-configurations.d.ts.map +1 -1
  28. package/dist/session/live/session-configurations.js +8 -1
  29. package/dist/session/live/session-configurations.js.map +1 -1
  30. package/dist/session/turn/execution-receipts.d.ts.map +1 -1
  31. package/dist/session/turn/execution-receipts.js +6 -3
  32. package/dist/session/turn/execution-receipts.js.map +1 -1
  33. package/dist/storage/session/execution-receipt-table.d.ts.map +1 -1
  34. package/dist/storage/session/execution-receipt-table.js +5 -2
  35. package/dist/storage/session/execution-receipt-table.js.map +1 -1
  36. package/package.json +2 -2
package/dist/runtime.js CHANGED
@@ -20993,17 +20993,6 @@ var ProtocolMessageError = class extends Error {
20993
20993
  this.name = "ProtocolMessageError";
20994
20994
  }
20995
20995
  };
20996
- var UnsupportedProtocolMessageKindError = class extends Error {
20997
- code = "unsupported_protocol_message_kind";
20998
- direction;
20999
- messageKind;
21000
- constructor(direction, messageKind) {
21001
- super(`Unsupported ${direction} message kind: ${messageKind}`);
21002
- this.name = "UnsupportedProtocolMessageKindError";
21003
- this.direction = direction;
21004
- this.messageKind = messageKind;
21005
- }
21006
- };
21007
20996
  function isRecord2(value) {
21008
20997
  return typeof value === "object" && value !== null && !Array.isArray(value);
21009
20998
  }
@@ -22468,14 +22457,7 @@ var sharedSessionEventFields = {
22468
22457
  sessionId: identifierStringSchema
22469
22458
  };
22470
22459
  var sessionLiveEventFields = { ...sharedSessionEventFields, position: positionSchema };
22471
- var sessionEventSchema = external_exports.discriminatedUnion("type", [
22472
- external_exports.object({ ...sharedSessionEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
22473
- external_exports.object({
22474
- ...sharedSessionEventFields,
22475
- payload: lifecycleMetadataSchema,
22476
- type: external_exports.literal("lifecycle-metadata")
22477
- }).readonly()
22478
- ]);
22460
+ var sessionEventSchema = external_exports.object({ ...sharedSessionEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly();
22479
22461
  var sessionLiveEventSchema = external_exports.discriminatedUnion("type", [
22480
22462
  external_exports.object({ ...sessionLiveEventFields, payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
22481
22463
  external_exports.object({
@@ -22514,7 +22496,129 @@ var sessionWireEventSchema = external_exports.union([
22514
22496
  var sessionWireEnvelopeSchema = external_exports.object({
22515
22497
  kind: external_exports.literal(SESSION_EVENT_KIND),
22516
22498
  events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
22517
- }).readonly();
22499
+ }).passthrough().readonly();
22500
+ var knownContentBlockTypes = /* @__PURE__ */ new Set([
22501
+ "text",
22502
+ "image",
22503
+ "audio",
22504
+ "resource_link",
22505
+ "resource",
22506
+ "external_image",
22507
+ "external_audio",
22508
+ "external_resource"
22509
+ ]);
22510
+ var knownToolCallContentTypes = /* @__PURE__ */ new Set(["content", "diff", "terminal"]);
22511
+ var knownPlanTypes = /* @__PURE__ */ new Set(["items", "file", "markdown"]);
22512
+ var knownConfigOptionTypes = /* @__PURE__ */ new Set(["select", "boolean"]);
22513
+ var knownSessionUpdates = /* @__PURE__ */ new Set([
22514
+ "user_message_chunk",
22515
+ "agent_message_chunk",
22516
+ "agent_thought_chunk",
22517
+ "tool_call",
22518
+ "tool_call_update",
22519
+ "plan",
22520
+ "plan_update",
22521
+ "plan_removed",
22522
+ "available_commands_update",
22523
+ "current_mode_update",
22524
+ "config_option_update",
22525
+ "session_info_update",
22526
+ "usage_update",
22527
+ "compaction_update",
22528
+ "compaction_summary_chunk"
22529
+ ]);
22530
+ var knownLifecycleKinds = /* @__PURE__ */ new Set([
22531
+ "session.queue.changed",
22532
+ "session.permission.requested",
22533
+ "session.permission.resolved",
22534
+ "session.elicitation.requested",
22535
+ "session.elicitation.resolved",
22536
+ "prompt.requested",
22537
+ "prompt.started",
22538
+ "prompt.completed",
22539
+ "prompt.failed-before-start",
22540
+ "prompt.failed"
22541
+ ]);
22542
+ function isRecord3(value) {
22543
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22544
+ }
22545
+ function hasUnknownDiscriminator(value, key, known) {
22546
+ if (!isRecord3(value)) {
22547
+ return false;
22548
+ }
22549
+ const variant = value[key];
22550
+ return typeof variant === "string" && !known.has(variant);
22551
+ }
22552
+ function containsUnknownContentBlock(value) {
22553
+ return hasUnknownDiscriminator(value, "type", knownContentBlockTypes);
22554
+ }
22555
+ function containsUnknownToolCallContent(value) {
22556
+ if (hasUnknownDiscriminator(value, "type", knownToolCallContentTypes)) {
22557
+ return true;
22558
+ }
22559
+ return isRecord3(value) && value["type"] === "content" && containsUnknownContentBlock(value["content"]);
22560
+ }
22561
+ function arrayContainsUnknown(value, predicate) {
22562
+ return Array.isArray(value) && value.some(predicate);
22563
+ }
22564
+ function containsUnknownAcpVariant(payload) {
22565
+ const update = payload["sessionUpdate"];
22566
+ if (typeof update !== "string") {
22567
+ return false;
22568
+ }
22569
+ if (!knownSessionUpdates.has(update)) {
22570
+ return true;
22571
+ }
22572
+ if (["user_message_chunk", "agent_message_chunk", "agent_thought_chunk", "compaction_summary_chunk"].includes(
22573
+ update
22574
+ )) {
22575
+ return containsUnknownContentBlock(payload["content"]);
22576
+ }
22577
+ if (update === "tool_call" || update === "tool_call_update") {
22578
+ return arrayContainsUnknown(payload["content"], containsUnknownToolCallContent);
22579
+ }
22580
+ if (update === "plan_update") {
22581
+ return hasUnknownDiscriminator(payload["plan"], "type", knownPlanTypes);
22582
+ }
22583
+ if (update === "config_option_update") {
22584
+ return arrayContainsUnknown(
22585
+ payload["configOptions"],
22586
+ (option) => hasUnknownDiscriminator(option, "type", knownConfigOptionTypes)
22587
+ );
22588
+ }
22589
+ if (update === "compaction_update") {
22590
+ return arrayContainsUnknown(payload["summary"], containsUnknownContentBlock);
22591
+ }
22592
+ return false;
22593
+ }
22594
+ function isKnownSessionEventVariant(value) {
22595
+ if (!isRecord3(value)) {
22596
+ return true;
22597
+ }
22598
+ const type = value["type"];
22599
+ if (typeof type !== "string") {
22600
+ return true;
22601
+ }
22602
+ if (type === "acp") {
22603
+ const payload = value["payload"];
22604
+ return !isRecord3(payload) || !containsUnknownAcpVariant(payload);
22605
+ }
22606
+ if (type === "lifecycle-metadata") {
22607
+ const payload = value["payload"];
22608
+ if (!isRecord3(payload)) {
22609
+ return true;
22610
+ }
22611
+ const kind = payload["kind"];
22612
+ if (typeof kind === "string" && !knownLifecycleKinds.has(kind)) {
22613
+ return false;
22614
+ }
22615
+ return kind !== "prompt.requested" || !arrayContainsUnknown(payload["content"], containsUnknownContentBlock);
22616
+ }
22617
+ return false;
22618
+ }
22619
+ function filterKnownSessionEventVariants(events) {
22620
+ return Array.isArray(events) ? events.filter(isKnownSessionEventVariant) : events;
22621
+ }
22518
22622
  var sessionEventBatchSchema = external_exports.array(sessionEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
22519
22623
  var sessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
22520
22624
  var sessionExportSchema = external_exports.object({
@@ -22600,10 +22704,28 @@ function decode4(value, schema) {
22600
22704
  function encode3(value, schema) {
22601
22705
  return JSON.stringify(decode4(value, schema));
22602
22706
  }
22707
+ function sanitizeKnownNativeSessionEvents(value) {
22708
+ const input2 = inputValue(value);
22709
+ if (!isRecord3(input2)) {
22710
+ return input2;
22711
+ }
22712
+ const page = input2["events"];
22713
+ const queuedPromptRequests = input2["queuedPromptRequests"];
22714
+ return {
22715
+ ...input2,
22716
+ events: isRecord3(page) ? { ...page, events: filterKnownSessionEventVariants(page["events"]) } : page,
22717
+ queuedPromptRequests: Array.isArray(queuedPromptRequests) ? queuedPromptRequests.filter(
22718
+ (prompt) => !isRecord3(prompt) || !arrayContainsUnknown(prompt["content"], containsUnknownContentBlock)
22719
+ ) : queuedPromptRequests
22720
+ };
22721
+ }
22722
+ var knownSessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
22603
22723
  var decodeSessionEvent = (value) => decode4(value, sessionEventSchema);
22724
+ var decodeKnownSessionEventPayload = (value) => isKnownSessionEventVariant(value) ? decode4(value, sessionEventPayloadSchema) : null;
22604
22725
  var decodeSessionEventEnvelope = (value) => decode4(value, sessionEventEnvelopeSchema);
22605
22726
  var encodeSessionEventEnvelope = (value) => encode3(value, sessionEventEnvelopeSchema);
22606
22727
  var decodeAcpSessionUpdate = (value) => decode4(value, acpSessionUpdateSchema);
22728
+ var decodeKnownNativeSessionEvents = (value) => decode4(sanitizeKnownNativeSessionEvents(value), nativeSessionEventsSchema);
22607
22729
 
22608
22730
  // ../mobius-sdk/src/protocol/session/observability/history.ts
22609
22731
  var SESSION_HISTORY_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
@@ -22634,6 +22756,30 @@ var pageLoadedFields = {
22634
22756
  };
22635
22757
  var sessionHistoryPageLoadedSchema = external_exports.object({ ...pageLoadedFields, kind: external_exports.literal(SESSION_HISTORY_PAGE_LOADED_KIND) }).readonly();
22636
22758
  var sessionPreviewHistoryPageLoadedSchema = external_exports.object({ ...pageLoadedFields, kind: external_exports.literal(SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND) }).readonly();
22759
+ var wireNativeSessionEventsSchema = external_exports.object({
22760
+ events: external_exports.object({
22761
+ events: external_exports.array(external_exports.unknown()).max(1e4).readonly(),
22762
+ nextCursor: external_exports.string().min(1).max(512).nullable(),
22763
+ sessionGenerationId: identifierStringSchema,
22764
+ tailCursor: external_exports.string().max(512),
22765
+ throughPosition: external_exports.string().regex(/^(0|[1-9][0-9]*)$/u).optional(),
22766
+ truncated: external_exports.boolean(),
22767
+ version: external_exports.literal(2)
22768
+ }).passthrough().readonly(),
22769
+ queuedPromptRequests: external_exports.array(external_exports.unknown()).max(1e3).readonly()
22770
+ }).passthrough().readonly();
22771
+ var sessionHistoryWirePageLoadedSchema = external_exports.object({
22772
+ events: wireNativeSessionEventsSchema,
22773
+ kind: external_exports.literal(SESSION_HISTORY_PAGE_LOADED_KIND),
22774
+ requestId: identifierStringSchema,
22775
+ sessionId: identifierStringSchema
22776
+ }).passthrough().readonly();
22777
+ var sessionPreviewHistoryWirePageLoadedSchema = external_exports.object({
22778
+ events: wireNativeSessionEventsSchema,
22779
+ kind: external_exports.literal(SESSION_PREVIEW_HISTORY_PAGE_LOADED_KIND),
22780
+ requestId: identifierStringSchema,
22781
+ sessionId: identifierStringSchema
22782
+ }).passthrough().readonly();
22637
22783
  function decode5(schema, encoded) {
22638
22784
  try {
22639
22785
  const value = JSON.parse(encoded);
@@ -22642,10 +22788,21 @@ function decode5(schema, encoded) {
22642
22788
  throw new ProtocolMessageError("Invalid live Session history message", { cause });
22643
22789
  }
22644
22790
  }
22791
+ function decodeLoaded(schema, encoded) {
22792
+ try {
22793
+ const value = JSON.parse(encoded);
22794
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
22795
+ return schema.parse(value);
22796
+ }
22797
+ return schema.parse({ ...value, events: decodeKnownNativeSessionEvents(Reflect.get(value, "events")) });
22798
+ } catch (cause) {
22799
+ throw new ProtocolMessageError("Invalid live Session history message", { cause });
22800
+ }
22801
+ }
22645
22802
  var decodeSessionHistoryPageLoad = (encoded) => decode5(sessionHistoryPageLoadSchema, encoded);
22646
- var decodeSessionHistoryPageLoaded = (encoded) => decode5(sessionHistoryPageLoadedSchema, encoded);
22803
+ var decodeSessionHistoryPageLoaded = (encoded) => decodeLoaded(sessionHistoryPageLoadedSchema, encoded);
22647
22804
  var decodeSessionPreviewHistoryPageLoad = (encoded) => decode5(sessionPreviewHistoryPageLoadSchema, encoded);
22648
- var decodeSessionPreviewHistoryPageLoaded = (encoded) => decode5(sessionPreviewHistoryPageLoadedSchema, encoded);
22805
+ var decodeSessionPreviewHistoryPageLoaded = (encoded) => decodeLoaded(sessionPreviewHistoryPageLoadedSchema, encoded);
22649
22806
  var encodeSessionHistoryPageLoad = (value) => JSON.stringify(sessionHistoryPageLoadSchema.parse(value));
22650
22807
  var encodeSessionHistoryPageLoaded = (value) => JSON.stringify(sessionHistoryPageLoadedSchema.parse(value));
22651
22808
  var encodeSessionPreviewHistoryPageLoad = (value) => JSON.stringify(sessionPreviewHistoryPageLoadSchema.parse(value));
@@ -22886,13 +23043,28 @@ var serviceToDaemonSignatures = {
22886
23043
  )
22887
23044
  };
22888
23045
  var serviceToDaemonRegistry = serviceToDaemonSignatures;
22889
- function decodeServiceToDaemonMessage(encoded) {
23046
+ var knownNativeActions = /* @__PURE__ */ new Set(["active-turn", "find", "list", "import", "fork"]);
23047
+ function isRecord4(value) {
23048
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23049
+ }
23050
+ function hasUnknownDiscriminator2(value, key, known) {
23051
+ if (!isRecord4(value)) {
23052
+ return false;
23053
+ }
23054
+ const variant = value[key];
23055
+ return typeof variant === "string" && !known.has(variant);
23056
+ }
23057
+ function hasUnknownServiceVariant(kind, value) {
23058
+ return kind === NATIVE_SESSION_REQUEST_KIND && hasUnknownDiscriminator2(value, "action", knownNativeActions);
23059
+ }
23060
+ function decodeKnownServiceToDaemonMessage(encoded) {
22890
23061
  const kind = decodeMessageKind(encoded);
22891
23062
  const signature = serviceToDaemonRegistry[kind];
22892
23063
  if (signature === void 0) {
22893
- throw new UnsupportedProtocolMessageKindError("service-to-daemon", kind);
23064
+ return null;
22894
23065
  }
22895
- return signature.decoder(encoded);
23066
+ const value = parseJson(encoded);
23067
+ return hasUnknownServiceVariant(kind, value) ? null : signature.decoder(encoded);
22896
23068
  }
22897
23069
  var daemonToServiceSignatures = {
22898
23070
  [SESSION_CLOSED_KIND]: defineMessageSignature(
@@ -23108,7 +23280,7 @@ var SessionConfigProtocolError = class extends Error {
23108
23280
  this.name = "SessionConfigProtocolError";
23109
23281
  }
23110
23282
  };
23111
- function isRecord3(value) {
23283
+ function isRecord5(value) {
23112
23284
  return typeof value === "object" && value !== null && !Array.isArray(value);
23113
23285
  }
23114
23286
  function readString3(value, fallback = "") {
@@ -23139,7 +23311,7 @@ function normalizeConfigValues(value) {
23139
23311
  }
23140
23312
  const normalized = [];
23141
23313
  for (const entry of value) {
23142
- if (!isRecord3(entry)) {
23314
+ if (!isRecord5(entry)) {
23143
23315
  continue;
23144
23316
  }
23145
23317
  const groupedOptions = entry["options"];
@@ -23147,7 +23319,7 @@ function normalizeConfigValues(value) {
23147
23319
  const groupId = readString3(entry["group"]);
23148
23320
  const groupName = readString3(entry["name"]);
23149
23321
  for (const groupedOption of groupedOptions) {
23150
- if (isRecord3(groupedOption)) {
23322
+ if (isRecord5(groupedOption)) {
23151
23323
  const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
23152
23324
  if (normalizedValue !== void 0) {
23153
23325
  normalized.push(normalizedValue);
@@ -23172,7 +23344,7 @@ function normalizeConfigOptions(value, modes) {
23172
23344
  const normalized = [];
23173
23345
  if (Array.isArray(value)) {
23174
23346
  for (const option of value) {
23175
- if (!isRecord3(option)) {
23347
+ if (!isRecord5(option)) {
23176
23348
  continue;
23177
23349
  }
23178
23350
  const id = truncate2(readString3(option["id"]), 128);
@@ -23212,12 +23384,12 @@ function normalizeConfigOptions(value, modes) {
23212
23384
  }
23213
23385
  }
23214
23386
  }
23215
- if (isRecord3(modes)) {
23387
+ if (isRecord5(modes)) {
23216
23388
  const values = [];
23217
23389
  const availableModes = modes["availableModes"];
23218
23390
  if (Array.isArray(availableModes)) {
23219
23391
  for (const mode of availableModes) {
23220
- if (!isRecord3(mode)) {
23392
+ if (!isRecord5(mode)) {
23221
23393
  continue;
23222
23394
  }
23223
23395
  const id = truncate2(readString3(mode["id"]), 500);
@@ -23250,7 +23422,7 @@ function normalizeConfigOptions(value, modes) {
23250
23422
  return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
23251
23423
  }
23252
23424
  function normalizeStandardLifecycle(response) {
23253
- const lifecycle = isRecord3(response) ? response : {};
23425
+ const lifecycle = isRecord5(response) ? response : {};
23254
23426
  return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
23255
23427
  }
23256
23428
  function replaceStandardConfigOptions(current, value) {
@@ -23292,7 +23464,7 @@ var StandardSessionConfigProtocol = class {
23292
23464
  "ACP agent exited while changing session configuration",
23293
23465
  change.signal
23294
23466
  );
23295
- if (!isRecord3(response) || !Array.isArray(response["configOptions"])) {
23467
+ if (!isRecord5(response) || !Array.isArray(response["configOptions"])) {
23296
23468
  throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
23297
23469
  }
23298
23470
  return replaceStandardConfigOptions(current, response["configOptions"]);
@@ -32352,7 +32524,7 @@ var toolImageSchema = external_exports.union([
32352
32524
  file: external_exports.object({ base64: external_exports.string(), type: external_exports.string() })
32353
32525
  }).transform(({ file: file2 }) => ({ type: "image", data: file2.base64, mimeType: file2.type }))
32354
32526
  ]);
32355
- function isRecord4(value) {
32527
+ function isRecord6(value) {
32356
32528
  return typeof value === "object" && value !== null && !Array.isArray(value);
32357
32529
  }
32358
32530
  var AcpContentExternalizer = class {
@@ -32459,13 +32631,13 @@ var AcpContentExternalizer = class {
32459
32631
  }
32460
32632
  return result2;
32461
32633
  }
32462
- if (!isRecord4(value)) {
32634
+ if (!isRecord6(value)) {
32463
32635
  return value;
32464
32636
  }
32465
32637
  const image = toolImageSchema.safeParse(value);
32466
32638
  if (image.success && image.data.data.length > 0) {
32467
32639
  const prepared = await this.#content(sessionId, image.data, signal);
32468
- if (isRecord4(prepared.event) && typeof prepared.event["imageKey"] === "string") {
32640
+ if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
32469
32641
  images.set(prepared.event["imageKey"], prepared);
32470
32642
  } else {
32471
32643
  images.set(`unavailable:${images.size}`, prepared);
@@ -32496,7 +32668,7 @@ var AcpContentExternalizer = class {
32496
32668
  const prepared = await this.#content(sessionId, content, signal);
32497
32669
  agentContent.push({ ...item, content: prepared.agent });
32498
32670
  eventContent.push({ ...item, content: prepared.event });
32499
- if (isRecord4(prepared.event) && typeof prepared.event["imageKey"] === "string") {
32671
+ if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
32500
32672
  images.delete(prepared.event["imageKey"]);
32501
32673
  }
32502
32674
  }
@@ -32576,7 +32748,7 @@ import { fetch as fetch3 } from "undici";
32576
32748
  // package.json
32577
32749
  var package_default = {
32578
32750
  name: "@moxt-ai/mobius",
32579
- version: "0.0.334",
32751
+ version: "0.0.336",
32580
32752
  description: "Mobius CLI for pairing and running local AI agent services.",
32581
32753
  type: "module",
32582
32754
  bin: {
@@ -69854,7 +70026,7 @@ var DESTINATIONS = /* @__PURE__ */ new Set([
69854
70026
  ]);
69855
70027
  var BEHAVIORS = /* @__PURE__ */ new Set(["allow", "deny", "ask"]);
69856
70028
  var MODES = /* @__PURE__ */ new Set(["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"]);
69857
- function isRecord5(value) {
70029
+ function isRecord7(value) {
69858
70030
  return !!value && typeof value === "object" && !Array.isArray(value);
69859
70031
  }
69860
70032
  function isDestination(value) {
@@ -69871,13 +70043,13 @@ function safePlainString(value, maxLength) {
69871
70043
  });
69872
70044
  }
69873
70045
  function isRule(value) {
69874
- if (!isRecord5(value) || !safePlainString(value.toolName, MAX_TOOL_NAME_LENGTH)) {
70046
+ if (!isRecord7(value) || !safePlainString(value.toolName, MAX_TOOL_NAME_LENGTH)) {
69875
70047
  return false;
69876
70048
  }
69877
70049
  return value.ruleContent === void 0 || safePlainString(value.ruleContent, MAX_RULE_CONTENT_LENGTH);
69878
70050
  }
69879
70051
  function isKnownUpdate(value) {
69880
- if (!isRecord5(value) || !isDestination(value.destination) || typeof value.type !== "string") {
70052
+ if (!isRecord7(value) || !isDestination(value.destination) || typeof value.type !== "string") {
69881
70053
  return false;
69882
70054
  }
69883
70055
  switch (value.type) {
@@ -82601,7 +82773,7 @@ var AgentCatalogPublishError = class extends Error {
82601
82773
  this.name = "AgentCatalogPublishError";
82602
82774
  }
82603
82775
  };
82604
- function isRecord6(value) {
82776
+ function isRecord8(value) {
82605
82777
  return typeof value === "object" && value !== null && !Array.isArray(value);
82606
82778
  }
82607
82779
  function isSafeRelayErrorMessage(value) {
@@ -82614,7 +82786,7 @@ async function rejectedCatalogError(response) {
82614
82786
  } catch {
82615
82787
  return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
82616
82788
  }
82617
- if (!isRecord6(value) || !isRecord6(value["error"])) {
82789
+ if (!isRecord8(value) || !isRecord8(value["error"])) {
82618
82790
  return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
82619
82791
  }
82620
82792
  const code = value["error"]["code"];
@@ -83036,7 +83208,7 @@ var RuntimeInstallationStoreError = class extends Error {
83036
83208
  this.name = "RuntimeInstallationStoreError";
83037
83209
  }
83038
83210
  };
83039
- function isRecord7(value) {
83211
+ function isRecord9(value) {
83040
83212
  return typeof value === "object" && value !== null && !Array.isArray(value);
83041
83213
  }
83042
83214
  function hasExactKeys(value, expectedKeys) {
@@ -83103,7 +83275,7 @@ function installationId() {
83103
83275
  return `min_${randomUUID13().replaceAll("-", "")}`;
83104
83276
  }
83105
83277
  function decodeInstallationPointer(value) {
83106
- if (!isRecord7(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
83278
+ if (!isRecord9(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
83107
83279
  throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
83108
83280
  }
83109
83281
  const storedInstallationId = value["installationId"];
@@ -83113,7 +83285,7 @@ function decodeInstallationPointer(value) {
83113
83285
  return { installationId: validateInstallationId(storedInstallationId) };
83114
83286
  }
83115
83287
  function decodeChannelIndex(value) {
83116
- if (!isRecord7(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
83288
+ if (!isRecord9(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
83117
83289
  throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
83118
83290
  }
83119
83291
  const applicationId = value["applicationId"];
@@ -83163,7 +83335,7 @@ function decodeVerifiedConnection(value) {
83163
83335
  );
83164
83336
  }
83165
83337
  function decodeConnection(value) {
83166
- if (!isRecord7(value)) {
83338
+ if (!isRecord9(value)) {
83167
83339
  throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
83168
83340
  }
83169
83341
  return decodeVerifiedConnection(value);
@@ -83776,7 +83948,10 @@ function legacyState(receipt) {
83776
83948
  if (receipt.outcome === null) {
83777
83949
  return receipt.started ? "running" : "dispatching";
83778
83950
  }
83779
- const event = sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
83951
+ const event = decodeKnownSessionEventPayload(JSON.parse(receipt.outcome));
83952
+ if (event === null) {
83953
+ return "failed";
83954
+ }
83780
83955
  return event.type === "lifecycle-metadata" && event.payload.kind === "prompt.completed" ? event.payload.stopReason === "cancelled" ? "cancelled" : "succeeded" : "failed";
83781
83956
  }
83782
83957
  var ExecutionReceiptTable = class {
@@ -83925,6 +84100,31 @@ var unmeasuredOperationMetrics = Object.freeze({
83925
84100
  // src/session/live/agent-session.ts
83926
84101
  import { methods as methods14 } from "@agentclientprotocol/sdk";
83927
84102
 
84103
+ // ../mobius-sdk/src/conversation-title.ts
84104
+ var CONVERSATION_TITLE_CHARACTER_LIMIT = 42;
84105
+ function conversationTitleFromText(text2) {
84106
+ let compact = "";
84107
+ for (const line of text2.split(/\r?\n/u)) {
84108
+ const candidate = line.replaceAll(/\s+/g, " ").trim();
84109
+ if (candidate.length === 0 || candidate.startsWith("```") || candidate.startsWith("~~~")) {
84110
+ continue;
84111
+ }
84112
+ const readable = candidate.replace(/^(?:>\s*)+/u, "").replace(/^#{1,6}(?:\s+|$)/u, "").replace(/^(?:[-*+]|\d+[.)])\s+/u, "").trim();
84113
+ if (readable.length > 0) {
84114
+ compact = readable;
84115
+ break;
84116
+ }
84117
+ }
84118
+ if (compact.length === 0) {
84119
+ compact = text2.replaceAll(/\s+/g, " ").trim();
84120
+ }
84121
+ const characters = Array.from(compact);
84122
+ if (characters.length <= CONVERSATION_TITLE_CHARACTER_LIMIT) {
84123
+ return compact;
84124
+ }
84125
+ return `${characters.slice(0, CONVERSATION_TITLE_CHARACTER_LIMIT - 1).join("")}\u2026`;
84126
+ }
84127
+
83928
84128
  // src/session/api/session-api.ts
83929
84129
  var NullSessionObserver = class {
83930
84130
  onBackgroundActivity = (_source, _active) => {
@@ -84560,7 +84760,11 @@ var storedSessionConfigurationsSchema = external_exports.array(
84560
84760
  external_exports.object({ configId: external_exports.string().max(128), type: external_exports.literal("select"), value: external_exports.string().max(500) })
84561
84761
  ])
84562
84762
  ).max(100);
84563
- var decodeStoredSessionConfigurations = (value) => storedSessionConfigurationsSchema.parse(value);
84763
+ var decodeStoredSessionConfigurations = (value) => storedSessionConfigurationsSchema.parse(
84764
+ Array.isArray(value) ? value.filter(
84765
+ (configuration) => typeof configuration !== "object" || configuration === null || !("type" in configuration) || typeof configuration.type !== "string" || configuration.type === "boolean" || configuration.type === "select"
84766
+ ) : value
84767
+ );
84564
84768
  var SessionConfigurations = class {
84565
84769
  #selected = [];
84566
84770
  stored = () => this.#selected;
@@ -85360,7 +85564,7 @@ var AgentSession = class _AgentSession {
85360
85564
  }
85361
85565
  validatePromptContent(options, this.#capabilities);
85362
85566
  if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
85363
- this.#sessionTitle = truncate(options.prompt, 500);
85567
+ this.#sessionTitle = conversationTitleFromText(options.prompt);
85364
85568
  }
85365
85569
  this.#prompted = true;
85366
85570
  this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
@@ -87074,7 +87278,7 @@ var ExecutionReceipts = class {
87074
87278
  };
87075
87279
  outcome = (commandId) => {
87076
87280
  const receipt = this.#executions.get(commandId);
87077
- return receipt?.outcome === null || receipt === void 0 ? void 0 : sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
87281
+ return receipt?.outcome === null || receipt === void 0 ? void 0 : decodeKnownSessionEventPayload(JSON.parse(receipt.outcome)) ?? void 0;
87078
87282
  };
87079
87283
  /** Reserves an unseen command for cancellation before a delayed prompt can claim its identity. */
87080
87284
  recordCancellationBeforeAdmission = (commandId, sessionId) => {
@@ -87137,7 +87341,10 @@ var ExecutionReceipts = class {
87137
87341
  code: "runtime_restarted",
87138
87342
  message: "The local runtime restarted before this request started"
87139
87343
  }
87140
- } : sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
87344
+ } : decodeKnownSessionEventPayload(JSON.parse(receipt.outcome));
87345
+ if (event === null) {
87346
+ continue;
87347
+ }
87141
87348
  const recordedAt = receipt.outcome === null ? (/* @__PURE__ */ new Date()).toISOString() : external_exports.object({ recordedAt: external_exports.string() }).parse(JSON.parse(receipt.outcome)).recordedAt;
87142
87349
  recovered.push({ sessionId: receipt.sessionId, event, recordedAt });
87143
87350
  if (receipt.outcome === null) {
@@ -91216,35 +91423,6 @@ function closeRelaySocket(socket, code, reason) {
91216
91423
  }
91217
91424
  }
91218
91425
  }
91219
- function readCommandCorrelation(encoded) {
91220
- let value;
91221
- try {
91222
- value = JSON.parse(encoded);
91223
- } catch {
91224
- return { requestId: "unsupported", sessionId: "" };
91225
- }
91226
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
91227
- return { requestId: "unsupported", sessionId: "" };
91228
- }
91229
- const requestId = Reflect.get(value, "requestId");
91230
- const sessionId = Reflect.get(value, "sessionId");
91231
- return {
91232
- requestId: typeof requestId === "string" && isIdentifier(requestId) ? requestId : "unsupported",
91233
- sessionId: typeof sessionId === "string" && isIdentifier(sessionId) ? sessionId : ""
91234
- };
91235
- }
91236
- function rejectUnsupportedCommand(socket, correlation, rejection) {
91237
- if (socket.readyState !== WebSocket8.OPEN) {
91238
- return;
91239
- }
91240
- send(socket, {
91241
- code: rejection.code,
91242
- kind: SESSION_OPERATION_FAILED_KIND,
91243
- message: "The Relay sent a command this daemon does not support",
91244
- requestId: correlation.requestId,
91245
- sessionId: correlation.sessionId
91246
- });
91247
- }
91248
91426
  async function runRelayConnection({
91249
91427
  resolveAgent,
91250
91428
  config: config2,
@@ -91397,7 +91575,10 @@ async function runRelayConnection({
91397
91575
  return;
91398
91576
  }
91399
91577
  try {
91400
- const message = decodeServiceToDaemonMessage(encoded);
91578
+ const message = decodeKnownServiceToDaemonMessage(encoded);
91579
+ if (message === null) {
91580
+ return;
91581
+ }
91401
91582
  const kind = message.kind;
91402
91583
  if (kind === RUNTIME_LIVENESS_READY_KIND) {
91403
91584
  if (ready) {
@@ -91415,26 +91596,6 @@ async function runRelayConnection({
91415
91596
  }
91416
91597
  commands.dispatch(message);
91417
91598
  } catch (error62) {
91418
- if (error62 instanceof UnsupportedProtocolMessageKindError) {
91419
- const correlation = readCommandCorrelation(encoded);
91420
- console.warn("Mobius daemon rejected an unsupported Relay command", {
91421
- code: error62.code,
91422
- direction: error62.direction,
91423
- messageKind: error62.messageKind
91424
- });
91425
- diagnostics.daemonDiagnostic(
91426
- "relay_command_unsupported",
91427
- correlation.requestId,
91428
- {
91429
- code: error62.code,
91430
- direction: error62.direction,
91431
- messageKind: error62.messageKind
91432
- },
91433
- error62
91434
- );
91435
- rejectUnsupportedCommand(socket, correlation, error62);
91436
- return;
91437
- }
91438
91599
  console.error("Mobius daemon rejected a message", error62);
91439
91600
  failAndClose(
91440
91601
  new Error("Relay sent an invalid protocol message", { cause: error62 }),