@hermespilot/link 0.8.1-beta.3 → 0.8.1

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.
@@ -4,7 +4,7 @@ import Router from "@koa/router";
4
4
 
5
5
  // src/conversations/conversation-service.ts
6
6
  import { EventEmitter } from "events";
7
- import { createHash as createHash9, randomUUID as randomUUID12 } from "crypto";
7
+ import { createHash as createHash9, randomUUID as randomUUID13 } from "crypto";
8
8
  import path27 from "path";
9
9
 
10
10
  // src/database/link-database.ts
@@ -6008,6 +6008,13 @@ function readProfileReasoningEffort(config) {
6008
6008
  function writeProfileReasoningEffort(config, reasoningEffort) {
6009
6009
  const agent = ensureRecord(config, "agent");
6010
6010
  agent.reasoning_effort = reasoningEffort;
6011
+ writeProfileShowReasoning(config, reasoningEffort !== "none");
6012
+ }
6013
+ function writeProfileShowReasoning(config, showReasoning) {
6014
+ const display = ensureRecord(config, "display");
6015
+ const sections = ensureRecord(display, "sections");
6016
+ display.show_reasoning = showReasoning;
6017
+ sections.thinking = showReasoning ? "expanded" : "hidden";
6011
6018
  }
6012
6019
  function normalizeReasoningEffort(value) {
6013
6020
  if (typeof value !== "string") {
@@ -7714,7 +7721,7 @@ function isConversationMissingError(error) {
7714
7721
  }
7715
7722
 
7716
7723
  // src/constants.ts
7717
- var LINK_VERSION = "0.8.1-beta.3";
7724
+ var LINK_VERSION = "0.8.1";
7718
7725
  var LINK_COMMAND = "hermeslink";
7719
7726
  var LINK_DEFAULT_PORT = 52379;
7720
7727
  var LINK_RUNTIME_DIR_NAME = ".hermeslink";
@@ -8221,9 +8228,6 @@ function shouldThrottleLiveActivityEvent(activity, event, options) {
8221
8228
  if (!Number.isFinite(lastVisibleAt)) {
8222
8229
  return false;
8223
8230
  }
8224
- if (isAssistantProgressEvent(event) && isToolPhase(activity.lastPhase)) {
8225
- return false;
8226
- }
8227
8231
  return liveActivityEventTimeMs(event) - lastVisibleAt < MIN_LIVE_ACTIVITY_PUSH_INTERVAL_MS;
8228
8232
  }
8229
8233
  function liveActivityEventTimeMs(event) {
@@ -8246,9 +8250,6 @@ function liveActivityReportQueueKey(event) {
8246
8250
  event.targetId
8247
8251
  ].join(":");
8248
8252
  }
8249
- function isAssistantProgressEvent(event) {
8250
- return event.eventKind === "reasoning_available";
8251
- }
8252
8253
  function isLiveActivityTitleUpdateEvent(event) {
8253
8254
  return event.eventKind === "conversation_updated" && Boolean(event.conversationTitle?.trim());
8254
8255
  }
@@ -10783,6 +10784,15 @@ async function streamTuiGatewayRun(input) {
10783
10784
  reasoning_effort: input.reasoningEffort ?? null
10784
10785
  });
10785
10786
  await client.waitForSessionDrain(started.runtimeSessionId, input.signal);
10787
+ if (input.reasoningEffort?.trim()) {
10788
+ await setTuiGatewayReasoningDisplay(client, {
10789
+ profileName,
10790
+ sessionId: started.runtimeSessionId,
10791
+ storedSessionId: started.storedSessionId,
10792
+ reasoningEffort: input.reasoningEffort,
10793
+ logger: input.logger
10794
+ });
10795
+ }
10786
10796
  const usageBaseline = await client.readSessionUsage(started.runtimeSessionId).catch((error) => {
10787
10797
  void input.logger?.debug("tui_gateway_usage_baseline_read_failed", {
10788
10798
  profile: profileName,
@@ -10802,6 +10812,37 @@ async function streamTuiGatewayRun(input) {
10802
10812
  events: normalizeTuiGatewayRunUsageDeltas(events, usageBaseline)
10803
10813
  };
10804
10814
  }
10815
+ async function setTuiGatewayReasoningDisplay(client, input) {
10816
+ const effort = input.reasoningEffort.trim();
10817
+ if (!effort) {
10818
+ return;
10819
+ }
10820
+ await withSessionBusyRetry(
10821
+ () => client.request(
10822
+ "config.set",
10823
+ {
10824
+ session_id: input.sessionId,
10825
+ key: "reasoning",
10826
+ value: effort === "none" ? "hide" : "show"
10827
+ },
10828
+ REQUEST_TIMEOUT_MS
10829
+ )
10830
+ ).catch((error) => {
10831
+ throw withBusyContext(error, {
10832
+ profileName: input.profileName,
10833
+ runtimeSessionId: input.sessionId,
10834
+ storedSessionId: input.storedSessionId,
10835
+ method: "config.set:reasoning-display"
10836
+ });
10837
+ });
10838
+ void input.logger?.debug("tui_gateway_reasoning_display_applied", {
10839
+ profile: input.profileName,
10840
+ runtime_session_id: input.sessionId,
10841
+ stored_session_id: input.storedSessionId ?? null,
10842
+ reasoning_effort: effort,
10843
+ display: effort === "none" ? "hide" : "show"
10844
+ });
10845
+ }
10805
10846
  function buildTuiGatewayPromptText(input) {
10806
10847
  return input.input;
10807
10848
  }
@@ -11094,6 +11135,7 @@ async function setTuiGatewaySessionModelConfig(input) {
11094
11135
  hermes_session_id: input.hermesSessionId ?? null,
11095
11136
  model: model ?? null,
11096
11137
  provider: input.provider ?? null,
11138
+ force_model: input.forceModel === true,
11097
11139
  reasoning_effort: reasoningEffort ?? null
11098
11140
  });
11099
11141
  const client = await getTuiGatewayClient({
@@ -11134,7 +11176,14 @@ async function setTuiGatewaySessionModelConfig(input) {
11134
11176
  });
11135
11177
  }
11136
11178
  const raw = [];
11137
- if (model) {
11179
+ const currentModelMatches = model === void 0 ? false : await currentTuiGatewaySessionModelMatches(client, {
11180
+ profileName,
11181
+ runtimeSessionId: started.runtimeSessionId,
11182
+ model,
11183
+ logger: input.logger
11184
+ });
11185
+ const shouldSetModel = model !== void 0 && (input.forceModel === true || !currentModelMatches);
11186
+ if (shouldSetModel && model) {
11138
11187
  const result = await withSessionBusyRetry(
11139
11188
  () => client.request(
11140
11189
  "config.set",
@@ -11159,6 +11208,15 @@ async function setTuiGatewaySessionModelConfig(input) {
11159
11208
  });
11160
11209
  });
11161
11210
  raw.push(result);
11211
+ } else if (model) {
11212
+ void input.logger?.debug("tui_gateway_session_model_config_model_skipped", {
11213
+ profile: profileName,
11214
+ runtime_session_id: started.runtimeSessionId,
11215
+ stored_session_id: started.storedSessionId,
11216
+ model,
11217
+ provider: input.provider ?? null,
11218
+ native_session_model_config: hasNativeSessionModelConfig
11219
+ });
11162
11220
  }
11163
11221
  if (reasoningEffort) {
11164
11222
  const result = await withSessionBusyRetry(
@@ -11180,6 +11238,25 @@ async function setTuiGatewaySessionModelConfig(input) {
11180
11238
  });
11181
11239
  });
11182
11240
  raw.push(result);
11241
+ const displayResult = await withSessionBusyRetry(
11242
+ () => client.request(
11243
+ "config.set",
11244
+ {
11245
+ session_id: started.runtimeSessionId,
11246
+ key: "reasoning",
11247
+ value: reasoningEffort === "none" ? "hide" : "show"
11248
+ },
11249
+ REQUEST_TIMEOUT_MS
11250
+ )
11251
+ ).catch((error) => {
11252
+ throw withBusyContext(error, {
11253
+ profileName,
11254
+ runtimeSessionId: started.runtimeSessionId,
11255
+ storedSessionId: started.storedSessionId,
11256
+ method: "config.set:reasoning-display"
11257
+ });
11258
+ });
11259
+ raw.push(displayResult);
11183
11260
  }
11184
11261
  rememberSessionRef(profileName, input.hermesSessionId, started);
11185
11262
  rememberSessionRef(profileName, started.storedSessionId, started);
@@ -11191,6 +11268,9 @@ async function setTuiGatewaySessionModelConfig(input) {
11191
11268
  native_session_model_config: hasNativeSessionModelConfig,
11192
11269
  model: model ?? null,
11193
11270
  provider: input.provider ?? null,
11271
+ force_model: input.forceModel === true,
11272
+ current_model_matches: currentModelMatches,
11273
+ model_config_set: shouldSetModel,
11194
11274
  reasoning_effort: reasoningEffort ?? null
11195
11275
  });
11196
11276
  return {
@@ -11201,6 +11281,34 @@ async function setTuiGatewaySessionModelConfig(input) {
11201
11281
  raw
11202
11282
  };
11203
11283
  }
11284
+ async function currentTuiGatewaySessionModelMatches(client, input) {
11285
+ try {
11286
+ const result = await client.request(
11287
+ "session.active_list",
11288
+ { current_session_id: input.runtimeSessionId },
11289
+ 1e4
11290
+ );
11291
+ const sessions = Array.isArray(result.sessions) ? result.sessions : [];
11292
+ for (const item of sessions) {
11293
+ const liveSession = normalizeTuiGatewayLiveSessionRecord(item);
11294
+ if (!liveSession || liveSession.runtimeSessionId !== input.runtimeSessionId) {
11295
+ continue;
11296
+ }
11297
+ return liveSession.model?.trim() === input.model.trim();
11298
+ }
11299
+ } catch (error) {
11300
+ void input.logger?.debug(
11301
+ "tui_gateway_session_model_config_current_model_read_failed",
11302
+ {
11303
+ profile: input.profileName,
11304
+ runtime_session_id: input.runtimeSessionId,
11305
+ model: input.model,
11306
+ error: error instanceof Error ? error.message : String(error)
11307
+ }
11308
+ );
11309
+ }
11310
+ return false;
11311
+ }
11204
11312
  async function restartTuiGatewayBackend(input) {
11205
11313
  const profileName = normalizeProfileName2(input.profileName);
11206
11314
  const client = clients.get(profileName);
@@ -12354,6 +12462,15 @@ function normalizeGatewayEvent(event) {
12354
12462
  payload: { type: "message.delta", delta }
12355
12463
  } : null;
12356
12464
  }
12465
+ case "reasoning.delta":
12466
+ case "thinking.delta": {
12467
+ const text = readText(payload, "text") ?? readText(payload, "delta") ?? readText(payload, "preview") ?? readText(payload, "content");
12468
+ return text !== null ? {
12469
+ ...base,
12470
+ payloadType: event.type,
12471
+ payload: { ...payload, type: event.type, text }
12472
+ } : null;
12473
+ }
12357
12474
  case "message.complete": {
12358
12475
  const text = readText(payload, "text") ?? readText(payload, "rendered") ?? readText(payload, "content");
12359
12476
  const status = readString5(payload, "status")?.toLowerCase();
@@ -12394,6 +12511,14 @@ function normalizeGatewayEvent(event) {
12394
12511
  }
12395
12512
  };
12396
12513
  }
12514
+ case "reasoning.available": {
12515
+ const text = readText(payload, "text") ?? readText(payload, "delta") ?? readText(payload, "preview") ?? readText(payload, "content");
12516
+ return text !== null ? {
12517
+ ...base,
12518
+ payloadType: "reasoning.available",
12519
+ payload: { ...payload, type: "reasoning.available", text }
12520
+ } : null;
12521
+ }
12397
12522
  case "session.info": {
12398
12523
  const sessionKey = readString5(payload, "session_key") ?? readString5(payload, "sessionKey") ?? readString5(payload, "stored_session_id") ?? readString5(payload, "storedSessionId") ?? readString5(payload, "session_id") ?? readString5(payload, "sessionId");
12399
12524
  return {
@@ -12423,6 +12548,14 @@ function normalizeGatewayEvent(event) {
12423
12548
  case "tool.start":
12424
12549
  case "tool.progress": {
12425
12550
  const toolName = readString5(payload, "name") ?? readString5(payload, "tool") ?? "tool";
12551
+ if (event.type === "tool.progress" && toolName === "_thinking") {
12552
+ const text = readText(payload, "delta") ?? readText(payload, "text") ?? readText(payload, "preview") ?? readText(payload, "content") ?? readText(payload, "label");
12553
+ return text !== null ? {
12554
+ ...base,
12555
+ payloadType: "reasoning.available",
12556
+ payload: { ...payload, type: "reasoning.available", text }
12557
+ } : null;
12558
+ }
12426
12559
  const toolId = readString5(payload, "tool_id") ?? readString5(payload, "tool_call_id") ?? readString5(payload, "call_id") ?? readString5(payload, "id");
12427
12560
  const context = readString5(payload, "context");
12428
12561
  const argsText = readString5(payload, "args_text");
@@ -14370,6 +14503,206 @@ function isNodeError8(error, code) {
14370
14503
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
14371
14504
  }
14372
14505
 
14506
+ // src/conversations/message-visibility.ts
14507
+ var VISIBLE_SYSTEM_LIFECYCLE_KINDS = /* @__PURE__ */ new Set([
14508
+ "context_compression",
14509
+ "goal_completion",
14510
+ "model_switch"
14511
+ ]);
14512
+ var HERMES_IMPORTED_MESSAGE_FORMATS = /* @__PURE__ */ new Set([
14513
+ "hermes-message",
14514
+ "hermes-message-group"
14515
+ ]);
14516
+ function withAppMessageVisibility(message) {
14517
+ return applyAppMessagePresentation(message);
14518
+ }
14519
+ function toAppVisibleLinkMessage(message) {
14520
+ const projected = applyAppMessagePresentation(message);
14521
+ return projected.visibility === "internal" ? null : projected;
14522
+ }
14523
+ function isAppVisibleConversationEvent(event) {
14524
+ return toAppVisibleConversationEvent(event) !== null;
14525
+ }
14526
+ function toAppVisibleConversationEvent(event) {
14527
+ const message = readEventMessage(event);
14528
+ if (!message) {
14529
+ return event;
14530
+ }
14531
+ const projected = toAppVisibleLinkMessage(message);
14532
+ if (!projected) {
14533
+ return null;
14534
+ }
14535
+ return {
14536
+ ...event,
14537
+ payload: {
14538
+ ...event.payload ?? {},
14539
+ message: projected
14540
+ }
14541
+ };
14542
+ }
14543
+ function applyAppMessagePresentation(message) {
14544
+ if (message.visibility === "internal") {
14545
+ return message;
14546
+ }
14547
+ if (isHermesImportedMessage(message) && message.presentation?.kind === "model_switch") {
14548
+ return { ...message, visibility: "internal" };
14549
+ }
14550
+ if (message.visibility === "visible" && message.presentation) {
14551
+ return message;
14552
+ }
14553
+ if (message.raw?.format === "hermes-link-slash-command-result") {
14554
+ return withVisibleMessage(message);
14555
+ }
14556
+ const text = messageText(message);
14557
+ if (isHermesImportedMessage(message)) {
14558
+ const strippedText = stripLeadingHermesInternalNote(text);
14559
+ if (strippedText !== text) {
14560
+ return strippedText ? withText(message, strippedText) : { ...message, visibility: "internal" };
14561
+ }
14562
+ const presentation2 = parseHermesSystemMarker(text);
14563
+ if (presentation2) {
14564
+ return withPresentation(message, presentation2);
14565
+ }
14566
+ if (isHermesInternalSystemStyleMarker(text)) {
14567
+ return { ...message, visibility: "internal" };
14568
+ }
14569
+ }
14570
+ const presentation = linkLifecycleMarkerPresentation(message);
14571
+ if (presentation) {
14572
+ return withPresentation(message, presentation);
14573
+ }
14574
+ if (message.role === "system") {
14575
+ return { ...message, visibility: "internal" };
14576
+ }
14577
+ return withVisibleMessage(message);
14578
+ }
14579
+ function linkLifecycleMarkerPresentation(message) {
14580
+ if (message.raw?.format === "hermes-link-lifecycle-marker") {
14581
+ const payload = toRecord7(message.raw?.payload);
14582
+ const kind = readString9(payload, "kind");
14583
+ if (!VISIBLE_SYSTEM_LIFECYCLE_KINDS.has(kind ?? "")) {
14584
+ return null;
14585
+ }
14586
+ if (kind === "model_switch") {
14587
+ const model = readString9(payload, "model");
14588
+ const provider = readString9(payload, "provider");
14589
+ return {
14590
+ type: "lifecycle_marker",
14591
+ kind,
14592
+ ...model ? { model } : {},
14593
+ ...provider ? { provider } : {}
14594
+ };
14595
+ }
14596
+ return { type: "lifecycle_marker" };
14597
+ }
14598
+ return null;
14599
+ }
14600
+ function isHermesImportedMessage(message) {
14601
+ return message.hermes?.imported_from === "hermes" || HERMES_IMPORTED_MESSAGE_FORMATS.has(message.raw?.format ?? "");
14602
+ }
14603
+ function isHermesInternalSystemStyleMarker(text) {
14604
+ const normalized = text.trim();
14605
+ return normalized.startsWith(
14606
+ "[System: The active model for this chat has changed to "
14607
+ ) || normalized.startsWith(
14608
+ "[System: The user has changed the assistant's personality. "
14609
+ ) || normalized.startsWith(
14610
+ "[System: The user has cleared the personality overlay. "
14611
+ ) || normalized.startsWith("[System: Your previous tool call ") || normalized.startsWith(
14612
+ "[System: The previous response was cut off by a "
14613
+ ) || normalized.startsWith(
14614
+ "[System: Your previous response was truncated by the output "
14615
+ ) || normalized.startsWith(
14616
+ "[System: Continue now. Execute the required tool calls and only "
14617
+ ) || normalized.startsWith(
14618
+ "[Note: model was just switched from "
14619
+ );
14620
+ }
14621
+ function parseHermesSystemMarker(text) {
14622
+ const normalized = text.trim();
14623
+ if (normalized.startsWith(
14624
+ "[System: The user has changed the assistant's personality. "
14625
+ )) {
14626
+ return { type: "lifecycle_marker", kind: "personality_changed" };
14627
+ }
14628
+ if (normalized.startsWith(
14629
+ "[System: The user has cleared the personality overlay. "
14630
+ )) {
14631
+ return { type: "lifecycle_marker", kind: "personality_cleared" };
14632
+ }
14633
+ return null;
14634
+ }
14635
+ function stripLeadingHermesInternalNote(text) {
14636
+ return text.replace(
14637
+ /^\[Note: model was just switched from [^\]]+\]\s*/u,
14638
+ ""
14639
+ );
14640
+ }
14641
+ function withPresentation(message, presentation) {
14642
+ const text = presentationText(presentation) ?? messageText(message);
14643
+ return {
14644
+ ...message,
14645
+ visibility: "visible",
14646
+ presentation,
14647
+ parts: replaceTextParts(message.parts, text)
14648
+ };
14649
+ }
14650
+ function withVisibleMessage(message) {
14651
+ return {
14652
+ ...message,
14653
+ visibility: message.visibility ?? "visible"
14654
+ };
14655
+ }
14656
+ function presentationText(presentation) {
14657
+ switch (presentation.kind) {
14658
+ case "model_switch":
14659
+ return presentation.model ? `Model switched to ${presentation.model}` : "Model switched";
14660
+ case "personality_changed":
14661
+ return "Personality updated";
14662
+ case "personality_cleared":
14663
+ return "Personality cleared";
14664
+ default:
14665
+ return null;
14666
+ }
14667
+ }
14668
+ function withText(message, text) {
14669
+ const parts = replaceTextParts(message.parts, text);
14670
+ return {
14671
+ ...message,
14672
+ visibility: "visible",
14673
+ parts
14674
+ };
14675
+ }
14676
+ function replaceTextParts(parts, text) {
14677
+ let replaced = false;
14678
+ const next = parts.map((part) => {
14679
+ if (part.type !== "text" || replaced) {
14680
+ return part;
14681
+ }
14682
+ replaced = true;
14683
+ return { ...part, text };
14684
+ });
14685
+ return replaced ? next : [{ type: "text", text }, ...parts];
14686
+ }
14687
+ function readEventMessage(event) {
14688
+ const payload = toRecord7(event.payload);
14689
+ const message = toRecord7(payload.message);
14690
+ return readString9(message, "id") ? message : null;
14691
+ }
14692
+ function messageText(message) {
14693
+ return message.parts.filter(isTextPart).map((part) => part.text).join("").trim();
14694
+ }
14695
+ function isTextPart(part) {
14696
+ return part.type === "text" && typeof part.text === "string";
14697
+ }
14698
+ function toRecord7(value) {
14699
+ return typeof value === "object" && value !== null ? value : {};
14700
+ }
14701
+ function readString9(record, key) {
14702
+ const value = record[key];
14703
+ return typeof value === "string" ? value : void 0;
14704
+ }
14705
+
14373
14706
  // src/conversations/conversation-view.ts
14374
14707
  var DEFAULT_MESSAGES_PAGE_SIZE = 40;
14375
14708
  var MAX_MESSAGES_PAGE_SIZE = 100;
@@ -14444,14 +14777,14 @@ function buildConversationEventStreamState(snapshot) {
14444
14777
  };
14445
14778
  }
14446
14779
  function isActiveContextCompressionMarker(message) {
14447
- const payload = toRecord7(message.raw?.payload);
14780
+ const payload = toRecord8(message.raw?.payload);
14448
14781
  return message.raw?.format === "hermes-link-lifecycle-marker" && payload.kind === "context_compression" && payload.status === "compressing";
14449
14782
  }
14450
- function toRecord7(value) {
14783
+ function toRecord8(value) {
14451
14784
  return typeof value === "object" && value !== null ? value : {};
14452
14785
  }
14453
14786
  function isRetryableUserMessage(message) {
14454
- return message.role === "user" && message.raw?.format !== "hermes-link-slash-command" && (messageText(message).length > 0 || message.parts.some((part) => Boolean(part.blob)));
14787
+ return message.role === "user" && message.raw?.format !== "hermes-link-slash-command" && (messageText2(message).length > 0 || message.parts.some((part) => Boolean(part.blob)));
14455
14788
  }
14456
14789
  function normalizeMessagesPageLimit(value) {
14457
14790
  if (value === void 0 || !Number.isFinite(value)) {
@@ -14461,8 +14794,10 @@ function normalizeMessagesPageLimit(value) {
14461
14794
  }
14462
14795
  function toSummary(manifest, snapshot, profile) {
14463
14796
  const stats = buildConversationStats(manifest, snapshot);
14464
- const lastMessage = [...snapshot.messages].reverse().find(
14465
- (message) => message.parts.some((part) => part.type === "text" && part.text)
14797
+ const lastMessage = [...snapshot.messages].reverse().map(toAppVisibleLinkMessage).find(
14798
+ (message) => Boolean(
14799
+ message?.parts.some((part) => part.type === "text" && part.text)
14800
+ )
14466
14801
  );
14467
14802
  return {
14468
14803
  id: manifest.id,
@@ -14501,9 +14836,9 @@ function temporaryTitleFromUserMessage(content) {
14501
14836
  return chars.length <= TEMPORARY_TITLE_MAX_CHARS ? normalized : `${chars.slice(0, TEMPORARY_TITLE_MAX_CHARS).join("")}\u2026`;
14502
14837
  }
14503
14838
  function previewText(message) {
14504
- return messageText(message).slice(0, 160);
14839
+ return messageText2(message).slice(0, 160);
14505
14840
  }
14506
- function messageText(message) {
14841
+ function messageText2(message) {
14507
14842
  return message.parts.filter((part) => part.type === "text" && part.text).map((part) => part.text).join("").trim();
14508
14843
  }
14509
14844
  function toEventStreamRunSummary(run, requiresUserAction) {
@@ -16718,7 +17053,7 @@ function normalizeConversationTitle(value) {
16718
17053
  return Array.from(normalized).slice(0, SESSION_TITLE_MAX_LENGTH).join("");
16719
17054
  }
16720
17055
  function visibleTitleSourceText(message) {
16721
- return cleanHermesDisplayText(messageText(message)).replace(/\s+/gu, " ").trim();
17056
+ return cleanHermesDisplayText(messageText2(message)).replace(/\s+/gu, " ").trim();
16722
17057
  }
16723
17058
  function truncateTitleSourceText(value, maxLength) {
16724
17059
  return Array.from(value).slice(0, maxLength).join("");
@@ -17056,7 +17391,7 @@ function buildLinkSnapshotHistory(snapshot, run) {
17056
17391
  return false;
17057
17392
  }
17058
17393
  return message.run_id !== run.id;
17059
- }).map((message) => normalizeHistoryMessage(message.role, messageText(message))).filter(
17394
+ }).map((message) => normalizeHistoryMessage(message.role, messageText2(message))).filter(
17060
17395
  (message) => Boolean(message)
17061
17396
  );
17062
17397
  }
@@ -17780,7 +18115,7 @@ var ConversationOrchestrationCoordinator = class {
17780
18115
  conversationId,
17781
18116
  runId: run.id,
17782
18117
  input: this.buildHermesInput(
17783
- messageText(user),
18118
+ messageText2(user),
17784
18119
  user.parts.filter((part) => Boolean(part.blob))
17785
18120
  )
17786
18121
  };
@@ -18785,7 +19120,7 @@ var ConversationOrchestrationCoordinator = class {
18785
19120
  input.manifest.id,
18786
19121
  run.id,
18787
19122
  this.buildHermesInput(
18788
- messageText(previousUser),
19123
+ messageText2(previousUser),
18789
19124
  previousUser.parts.filter((part) => Boolean(part.blob))
18790
19125
  )
18791
19126
  );
@@ -18989,19 +19324,19 @@ function projectConversationAgentEvent(event, language = readLanguage(event.payl
18989
19324
  });
18990
19325
  }
18991
19326
  function projectAgentEvent(input) {
18992
- const type = readString9(input.payload, "type") ?? readString9(input.payload, "event") ?? input.type;
19327
+ const type = readString10(input.payload, "type") ?? readString10(input.payload, "event") ?? input.type;
18993
19328
  if (!isAgentActivityEvent(type)) {
18994
19329
  return null;
18995
19330
  }
18996
- const createdAt = readString9(input.payload, "started_at") ?? readString9(input.payload, "created_at") ?? input.createdAt;
18997
- const tool = toRecord8(input.payload.tool);
18998
- const call = toRecord8(input.payload.tool_call ?? input.payload.toolCall);
18999
- const fn = toRecord8(call.function ?? input.payload.function);
19000
- const name = readString9(input.payload, "tool_name") ?? readString9(input.payload, "toolName") ?? readString9(input.payload, "name") ?? readString9(input.payload, "tool") ?? readString9(tool, "name") ?? readString9(call, "name") ?? readString9(fn, "name") ?? "tool";
19001
- const id = readString9(input.payload, "tool_call_id") ?? readString9(input.payload, "toolCallId") ?? readString9(input.payload, "tool_id") ?? readString9(input.payload, "call_id") ?? readString9(input.payload, "id") ?? readString9(tool, "id") ?? readString9(call, "id") ?? readString9(fn, "id") ?? `tool_${hashAgentEventKey(`${type}:${input.fallbackKey}:${stableStringify(input.payload)}`)}`;
19331
+ const createdAt = readString10(input.payload, "started_at") ?? readString10(input.payload, "created_at") ?? input.createdAt;
19332
+ const tool = toRecord9(input.payload.tool);
19333
+ const call = toRecord9(input.payload.tool_call ?? input.payload.toolCall);
19334
+ const fn = toRecord9(call.function ?? input.payload.function);
19335
+ const name = readString10(input.payload, "tool_name") ?? readString10(input.payload, "toolName") ?? readString10(input.payload, "name") ?? readString10(input.payload, "tool") ?? readString10(tool, "name") ?? readString10(call, "name") ?? readString10(fn, "name") ?? "tool";
19336
+ const id = readString10(input.payload, "tool_call_id") ?? readString10(input.payload, "toolCallId") ?? readString10(input.payload, "tool_id") ?? readString10(input.payload, "call_id") ?? readString10(input.payload, "id") ?? readString10(tool, "id") ?? readString10(call, "id") ?? readString10(fn, "id") ?? `tool_${hashAgentEventKey(`${type}:${input.fallbackKey}:${stableStringify(input.payload)}`)}`;
19002
19337
  const rawArguments = input.payload.arguments ?? input.payload.args ?? input.payload.args_text ?? input.payload.argsText ?? input.payload.input ?? tool.arguments ?? tool.args ?? tool.input ?? call.arguments ?? call.args ?? call.input ?? fn.arguments;
19003
19338
  const args = stringifyAgentValue(rawArguments);
19004
- const summary = readString9(input.payload, "summary") ?? readString9(input.payload, "description") ?? readText2(input.payload, "preview") ?? readText2(input.payload, "context") ?? readText2(input.payload, "args_text") ?? readString9(tool, "summary") ?? readString9(tool, "description") ?? readString9(call, "summary") ?? void 0;
19339
+ const summary = readString10(input.payload, "summary") ?? readString10(input.payload, "description") ?? readText2(input.payload, "preview") ?? readText2(input.payload, "context") ?? readText2(input.payload, "args_text") ?? readString10(tool, "summary") ?? readString10(tool, "description") ?? readString10(call, "summary") ?? void 0;
19005
19340
  const status = input.payload.error === true ? "failed" : agentStatusForEventType(type);
19006
19341
  const actionSummary = summarizeAgentArguments({
19007
19342
  toolName: name,
@@ -19019,7 +19354,7 @@ function projectAgentEvent(input) {
19019
19354
  status,
19020
19355
  created_at: createdAt,
19021
19356
  ...status === "running" ? {} : {
19022
- completed_at: readString9(input.payload, "completed_at") ?? input.createdAt
19357
+ completed_at: readString10(input.payload, "completed_at") ?? input.createdAt
19023
19358
  }
19024
19359
  };
19025
19360
  }
@@ -19172,7 +19507,7 @@ function sanitizeAppConversationEventValue(value, input) {
19172
19507
  return value;
19173
19508
  }
19174
19509
  const next = {};
19175
- for (const [key, child] of Object.entries(toRecord8(value))) {
19510
+ for (const [key, child] of Object.entries(toRecord9(value))) {
19176
19511
  if (key === "raw") {
19177
19512
  const raw = retainAppVisibleRaw(child);
19178
19513
  if (raw) {
@@ -19191,11 +19526,11 @@ function sanitizeAppConversationEventValue(value, input) {
19191
19526
  return next;
19192
19527
  }
19193
19528
  function retainAppVisibleRaw(value) {
19194
- const raw = toRecord8(value);
19529
+ const raw = toRecord9(value);
19195
19530
  if (raw.format !== LIFECYCLE_MARKER_FORMAT) {
19196
19531
  return null;
19197
19532
  }
19198
- const payload = toRecord8(raw.payload);
19533
+ const payload = toRecord9(raw.payload);
19199
19534
  if (typeof payload.kind !== "string" || !APP_VISIBLE_LIFECYCLE_MARKER_KINDS.has(payload.kind)) {
19200
19535
  return null;
19201
19536
  }
@@ -19291,8 +19626,8 @@ function summarizeSkillViewArguments(toolName, rawArguments, args) {
19291
19626
  return void 0;
19292
19627
  }
19293
19628
  const argumentObject = readToolArgumentsObject(rawArguments, args);
19294
- const skillName = readString9(argumentObject, "name")?.trim();
19295
- const filePath = readString9(argumentObject, "file_path")?.trim() ?? readString9(argumentObject, "filePath")?.trim();
19629
+ const skillName = readString10(argumentObject, "name")?.trim();
19630
+ const filePath = readString10(argumentObject, "file_path")?.trim() ?? readString10(argumentObject, "filePath")?.trim();
19296
19631
  if (!skillName) {
19297
19632
  return filePath || void 0;
19298
19633
  }
@@ -19300,7 +19635,7 @@ function summarizeSkillViewArguments(toolName, rawArguments, args) {
19300
19635
  }
19301
19636
  function readToolArgumentsObject(rawArguments, args) {
19302
19637
  if (typeof rawArguments === "object" && rawArguments !== null && !Array.isArray(rawArguments)) {
19303
- return toRecord8(rawArguments);
19638
+ return toRecord9(rawArguments);
19304
19639
  }
19305
19640
  if (typeof rawArguments === "string") {
19306
19641
  const decoded = decodeJsonObject(rawArguments);
@@ -19319,7 +19654,7 @@ function decodeJsonObject(value) {
19319
19654
  if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
19320
19655
  return void 0;
19321
19656
  }
19322
- return toRecord8(decoded);
19657
+ return toRecord9(decoded);
19323
19658
  } catch {
19324
19659
  return void 0;
19325
19660
  }
@@ -19357,10 +19692,10 @@ function readErrorMessage3(payload) {
19357
19692
  if (typeof payload.error === "string" && payload.error.trim()) {
19358
19693
  return payload.error.trim();
19359
19694
  }
19360
- const error = toRecord8(payload.error);
19361
- return readString9(error, "message") ?? readString9(payload, "message");
19695
+ const error = toRecord9(payload.error);
19696
+ return readString10(error, "message") ?? readString10(payload, "message");
19362
19697
  }
19363
- function readString9(payload, key) {
19698
+ function readString10(payload, key) {
19364
19699
  const value = payload[key];
19365
19700
  return typeof value === "string" && value.trim() ? value.trim() : null;
19366
19701
  }
@@ -19368,7 +19703,7 @@ function readText2(payload, key) {
19368
19703
  const value = payload[key];
19369
19704
  return typeof value === "string" && value.length > 0 ? value : null;
19370
19705
  }
19371
- function toRecord8(value) {
19706
+ function toRecord9(value) {
19372
19707
  return typeof value === "object" && value !== null ? value : {};
19373
19708
  }
19374
19709
 
@@ -19550,8 +19885,9 @@ var ConversationQueryCoordinator = class {
19550
19885
  const manifest = await this.deps.store.readActiveManifest(conversationId);
19551
19886
  const snapshot = await this.deps.store.readSnapshot(conversationId);
19552
19887
  const limit = normalizeMessagesPageLimit(options.limit);
19553
- const total = snapshot.messages.length;
19554
- const endIndex = options.beforeMessageId ? snapshot.messages.findIndex(
19888
+ const visibleMessages = snapshot.messages.map(toAppVisibleLinkMessage).filter((message) => message !== null);
19889
+ const total = visibleMessages.length;
19890
+ const endIndex = options.beforeMessageId ? visibleMessages.findIndex(
19555
19891
  (message) => message.id === options.beforeMessageId
19556
19892
  ) : total;
19557
19893
  if (endIndex < 0) {
@@ -19565,7 +19901,7 @@ var ConversationQueryCoordinator = class {
19565
19901
  const events = await this.listEvents(conversationId, 0).catch(() => []);
19566
19902
  const messages2 = await this.hydrateAgentEventsForMessages(
19567
19903
  conversationId,
19568
- snapshot.messages.slice(startIndex, endIndex),
19904
+ visibleMessages.slice(startIndex, endIndex),
19569
19905
  snapshot,
19570
19906
  events
19571
19907
  );
@@ -20465,10 +20801,10 @@ function isControlMessage(message) {
20465
20801
  return message.raw?.format === "hermes-link-slash-command" || message.raw?.format === "hermes-link-slash-command-result";
20466
20802
  }
20467
20803
  function isContextCompressionMarker(message) {
20468
- return message.raw?.format === CONTEXT_COMPRESSION_MARKER_FORMAT && toRecord9(message.raw?.payload).kind === CONTEXT_COMPRESSION_MARKER_KIND;
20804
+ return message.raw?.format === CONTEXT_COMPRESSION_MARKER_FORMAT && toRecord10(message.raw?.payload).kind === CONTEXT_COMPRESSION_MARKER_KIND;
20469
20805
  }
20470
20806
  function readCompressionStatus(message) {
20471
- const status = toRecord9(message.raw?.payload).status;
20807
+ const status = toRecord10(message.raw?.payload).status;
20472
20808
  return typeof status === "string" ? status : void 0;
20473
20809
  }
20474
20810
  function unsupportedCompressionError(language) {
@@ -20506,7 +20842,7 @@ function normalizeProfileName5(value) {
20506
20842
  function localizedText(language, zh, en) {
20507
20843
  return language === "en" ? en : zh;
20508
20844
  }
20509
- function toRecord9(value) {
20845
+ function toRecord10(value) {
20510
20846
  return typeof value === "object" && value !== null ? value : {};
20511
20847
  }
20512
20848
  function createContextCompressionOperationId() {
@@ -20887,7 +21223,7 @@ async function importMediaReferencesForMessage(deps, input) {
20887
21223
  };
20888
21224
  }
20889
21225
  assistant.hermes = {
20890
- ...toRecord10(assistant.hermes),
21226
+ ...toRecord11(assistant.hermes),
20891
21227
  imported_media_source_keys: [...importedSourceKeys],
20892
21228
  media_import_failed_source_keys: [...failedSourceKeys],
20893
21229
  media_import_failures: [...failureRecordsByKey.values()].slice(
@@ -20919,16 +21255,16 @@ async function importMediaReferencesForMessage(deps, input) {
20919
21255
  };
20920
21256
  }
20921
21257
  function readMediaImportFailures(message) {
20922
- const hermes = toRecord10(message.hermes);
21258
+ const hermes = toRecord11(message.hermes);
20923
21259
  const failures = hermes.media_import_failures;
20924
21260
  if (!Array.isArray(failures)) {
20925
21261
  return [];
20926
21262
  }
20927
21263
  return failures.flatMap((item) => {
20928
- const record = toRecord10(item);
20929
- const key = readString10(record, "key");
20930
- const filename = readString10(record, "filename");
20931
- const reason = readString10(record, "reason");
21264
+ const record = toRecord11(item);
21265
+ const key = readString11(record, "key");
21266
+ const filename = readString11(record, "filename");
21267
+ const reason = readString11(record, "reason");
20932
21268
  if (!key || !filename || !reason) {
20933
21269
  return [];
20934
21270
  }
@@ -20937,13 +21273,13 @@ function readMediaImportFailures(message) {
20937
21273
  key,
20938
21274
  filename,
20939
21275
  reason,
20940
- ...readString10(record, "code") ? { code: readString10(record, "code") } : {}
21276
+ ...readString11(record, "code") ? { code: readString11(record, "code") } : {}
20941
21277
  }
20942
21278
  ];
20943
21279
  });
20944
21280
  }
20945
21281
  function readFailedMediaSourceKeys(message) {
20946
- const hermes = toRecord10(message.hermes);
21282
+ const hermes = toRecord11(message.hermes);
20947
21283
  const keys = hermes.media_import_failed_source_keys;
20948
21284
  if (!Array.isArray(keys)) {
20949
21285
  return /* @__PURE__ */ new Set();
@@ -21009,11 +21345,11 @@ function describeMediaImportFailure(reference, sourceKey, error) {
21009
21345
  function isSupportedDeliveryFilename(filename) {
21010
21346
  return SUPPORTED_DELIVERY_EXTENSIONS.has(path20.extname(filename).toLowerCase());
21011
21347
  }
21012
- function readString10(payload, key) {
21348
+ function readString11(payload, key) {
21013
21349
  const value = payload[key];
21014
21350
  return typeof value === "string" && value.trim() ? value.trim() : null;
21015
21351
  }
21016
- function toRecord10(value) {
21352
+ function toRecord11(value) {
21017
21353
  return typeof value === "object" && value !== null ? value : {};
21018
21354
  }
21019
21355
  function isNodeError12(error, code) {
@@ -21476,6 +21812,12 @@ async function mergeExistingHermesConversation(input) {
21476
21812
  input.store,
21477
21813
  input.conversationIds
21478
21814
  );
21815
+ if (await softDeleteActiveDuplicatesForArchivedHermesConversation({
21816
+ ...input,
21817
+ conversations
21818
+ })) {
21819
+ return true;
21820
+ }
21479
21821
  const active = conversations.filter((item) => item.manifest.status === "active");
21480
21822
  const canonical = selectCanonicalHermesConversation(active);
21481
21823
  if (!canonical) {
@@ -21518,6 +21860,26 @@ async function mergeExistingHermesConversation(input) {
21518
21860
  }
21519
21861
  return changed;
21520
21862
  }
21863
+ async function softDeleteActiveDuplicatesForArchivedHermesConversation(input) {
21864
+ const active = input.conversations.filter(
21865
+ (item) => item.manifest.status === "active"
21866
+ );
21867
+ const hasArchived = input.conversations.some(
21868
+ (item) => item.manifest.status === "archived"
21869
+ );
21870
+ if (!hasArchived || active.length === 0 || !active.every(isSafeHermesImportConversation)) {
21871
+ return false;
21872
+ }
21873
+ for (const duplicate of active) {
21874
+ await softDeleteMergedHermesDuplicate({
21875
+ paths: input.paths,
21876
+ store: input.store,
21877
+ duplicate,
21878
+ candidate: input.candidate
21879
+ });
21880
+ }
21881
+ return true;
21882
+ }
21521
21883
  async function mergeHermesCandidateIntoConversation(input) {
21522
21884
  const { candidate, existing } = input;
21523
21885
  const profile = await resolveConversationProfileTarget(
@@ -21662,8 +22024,8 @@ function collectMessageHermesRowKeys(message) {
21662
22024
  readHermesRawMessageRows(message.raw).forEach((row, index) => {
21663
22025
  keys.push(hermesRowKey(row, index));
21664
22026
  });
21665
- const hermes = toRecord11(message.hermes);
21666
- const sessionId = readString11(hermes, "session_id") ?? "";
22027
+ const hermes = toRecord12(message.hermes);
22028
+ const sessionId = readString12(hermes, "session_id") ?? "";
21667
22029
  const messageIds = Array.isArray(hermes.message_ids) ? hermes.message_ids : hermes.message_id === void 0 || hermes.message_id === null ? [] : [hermes.message_id];
21668
22030
  for (const messageId of messageIds) {
21669
22031
  if (messageId === void 0 || messageId === null) {
@@ -21701,7 +22063,7 @@ function consumeRepresentedMessageSignature(counts, message) {
21701
22063
  return true;
21702
22064
  }
21703
22065
  function representedMessageSignature(message) {
21704
- const text = messageText(message);
22066
+ const text = messageText2(message);
21705
22067
  if (!text) {
21706
22068
  return null;
21707
22069
  }
@@ -21733,11 +22095,11 @@ function lineageTitle(candidate) {
21733
22095
  if (explicitLineageTitle) {
21734
22096
  return explicitLineageTitle;
21735
22097
  }
21736
- const sessionTitle = readString11(candidate.session, "title") ?? "";
22098
+ const sessionTitle = readString12(candidate.session, "title") ?? "";
21737
22099
  return isDefaultConversationTitle(sessionTitle) ? void 0 : stripCompressionTitleSuffix2(sessionTitle);
21738
22100
  }
21739
22101
  function deriveHermesConversationTitle(candidate, snapshot) {
21740
- return lineageTitle(candidate) ?? normalizeHermesSourceTitle(readString11(candidate.session, "title")) ?? firstUserText(snapshot);
22102
+ return lineageTitle(candidate) ?? normalizeHermesSourceTitle(readString12(candidate.session, "title")) ?? firstUserText(snapshot);
21741
22103
  }
21742
22104
  function lineageManifestPatch(candidate) {
21743
22105
  const sessionIds = lineageSessionIds(candidate);
@@ -21841,7 +22203,7 @@ function isSafeHermesImportConversation(item) {
21841
22203
  if (item.manifest.title_source === "manual" || item.manifest.title_source === "generated") {
21842
22204
  return false;
21843
22205
  }
21844
- return snapshot.messages.length === 0 || snapshot.messages.every((message) => isHermesImportedMessage(message));
22206
+ return snapshot.messages.length === 0 || snapshot.messages.every((message) => isHermesImportedMessage2(message));
21845
22207
  }
21846
22208
  function isEmptyHermesImportPlaceholder(item) {
21847
22209
  return item.manifest.status === "active" && item.snapshot.messages.length === 0 && item.snapshot.runs.length === 0 && item.manifest.title_source === "default" && isDefaultConversationTitle(item.manifest.title) && item.manifest.hermes_session_id !== void 0 && !item.manifest.hermes_session_id.startsWith("hp_");
@@ -21943,7 +22305,7 @@ function collectImportedHermesPrefix(snapshot) {
21943
22305
  let endIndex = 0;
21944
22306
  for (; endIndex < snapshot.messages.length; endIndex += 1) {
21945
22307
  const message = snapshot.messages[endIndex];
21946
- if (!isHermesImportedMessage(message)) {
22308
+ if (!isHermesImportedMessage2(message)) {
21947
22309
  break;
21948
22310
  }
21949
22311
  if (message.hermes?.import_projection !== HERMES_IMPORT_PROJECTION_VERSION) {
@@ -21982,20 +22344,20 @@ function collectImportedHermesPrefix(snapshot) {
21982
22344
  needsUpgrade: needsProjectionVersion && (hasToolMetadata || hasMediaDeliveryMarkup)
21983
22345
  };
21984
22346
  }
21985
- function isHermesImportedMessage(message) {
22347
+ function isHermesImportedMessage2(message) {
21986
22348
  return message.hermes?.imported_from === "hermes" || message.raw?.format === "hermes-message" || message.raw?.format === "hermes-message-group";
21987
22349
  }
21988
22350
  function readHermesRowsFromAgentEvent(event) {
21989
22351
  if (event.raw?.format !== "hermes-message" && event.raw?.format !== "hermes-message-group") {
21990
22352
  return [];
21991
22353
  }
21992
- const payload = toRecord11(event.raw.payload);
21993
- const message = toRecord11(payload.message);
21994
- if (normalizeMessageRole(readString11(message, "role") ?? void 0) === "tool") {
22354
+ const payload = toRecord12(event.raw.payload);
22355
+ const message = toRecord12(payload.message);
22356
+ if (normalizeMessageRole(readString12(message, "role") ?? void 0) === "tool") {
21995
22357
  return [message];
21996
22358
  }
21997
22359
  return readHermesRawMessageRows(event.raw).filter(
21998
- (row) => Boolean(readString11(row, "role"))
22360
+ (row) => Boolean(readString12(row, "role"))
21999
22361
  );
22000
22362
  }
22001
22363
  function appendHermesRowOnce(rows, seen, row) {
@@ -22008,15 +22370,15 @@ function appendHermesRowOnce(rows, seen, row) {
22008
22370
  }
22009
22371
  function hermesRowKey(row, fallbackIndex) {
22010
22372
  if (row.id !== void 0 && row.id !== null) {
22011
- return hermesMessageIdKey(readString11(row, "session_id") ?? "", row.id);
22373
+ return hermesMessageIdKey(readString12(row, "session_id") ?? "", row.id);
22012
22374
  }
22013
- return `fallback:${readString11(row, "session_id") ?? ""}:${fallbackIndex}:${row.role ?? ""}:${row.timestamp ?? ""}:${normalizeContent2(row.content)}`;
22375
+ return `fallback:${readString12(row, "session_id") ?? ""}:${fallbackIndex}:${row.role ?? ""}:${row.timestamp ?? ""}:${normalizeContent2(row.content)}`;
22014
22376
  }
22015
22377
  function hermesMessageIdKey(sessionId, messageId) {
22016
22378
  return `id:${sessionId}:${String(messageId)}`;
22017
22379
  }
22018
22380
  function hasHermesToolMetadata(row) {
22019
- return normalizeMessageRole(row.role) === "tool" || readHermesToolCalls(row).length > 0 || Boolean(readString11(row, "tool_call_id")) || Boolean(readString11(row, "tool_name"));
22381
+ return normalizeMessageRole(row.role) === "tool" || readHermesToolCalls(row).length > 0 || Boolean(readString12(row, "tool_call_id")) || Boolean(readString12(row, "tool_name"));
22020
22382
  }
22021
22383
  function toLinkMessages(input) {
22022
22384
  const linkMessages = [];
@@ -22134,8 +22496,8 @@ function toLinkMessages(input) {
22134
22496
  return linkMessages;
22135
22497
  }
22136
22498
  function consumePendingToolCall(input) {
22137
- const toolCallId = readString11(input.toolMessage, "tool_call_id");
22138
- const toolName = readString11(input.toolMessage, "tool_name");
22499
+ const toolCallId = readString12(input.toolMessage, "tool_call_id");
22500
+ const toolName = readString12(input.toolMessage, "tool_name");
22139
22501
  let pending = toolCallId ? input.toolCallsById.get(toolCallId) : void 0;
22140
22502
  if (!pending && toolName) {
22141
22503
  pending = input.pendingToolCalls.find(
@@ -22185,13 +22547,13 @@ function readHermesToolCalls(message) {
22185
22547
  );
22186
22548
  }
22187
22549
  function normalizeHermesToolCall(value) {
22188
- const record = toRecord11(value);
22550
+ const record = toRecord12(value);
22189
22551
  if (Object.keys(record).length === 0) {
22190
22552
  return null;
22191
22553
  }
22192
- const fn = toRecord11(record.function);
22193
- const id = readString11(record, "id") ?? readString11(record, "call_id") ?? readString11(record, "tool_call_id") ?? readString11(fn, "id") ?? void 0;
22194
- const name = readString11(fn, "name") ?? readString11(record, "name") ?? readString11(record, "tool_name") ?? readString11(record, "tool") ?? "tool";
22554
+ const fn = toRecord12(record.function);
22555
+ const id = readString12(record, "id") ?? readString12(record, "call_id") ?? readString12(record, "tool_call_id") ?? readString12(fn, "id") ?? void 0;
22556
+ const name = readString12(fn, "name") ?? readString12(record, "name") ?? readString12(record, "tool_name") ?? readString12(record, "tool") ?? "tool";
22195
22557
  const rawArguments = fn.arguments ?? record.arguments ?? record.args ?? record.input;
22196
22558
  return {
22197
22559
  ...id ? { id } : {},
@@ -22230,8 +22592,8 @@ function projectHermesToolCompletedEvent(input) {
22230
22592
  const createdAt = isoFromHermesTime(input.sourceMessage.timestamp) ?? new Date(Date.now() + input.index).toISOString();
22231
22593
  const output = normalizeContent2(input.sourceMessage.content);
22232
22594
  const parsedOutput = parseJsonValue(output);
22233
- const toolCallId = readString11(input.sourceMessage, "tool_call_id") ?? input.pending?.toolCall.id;
22234
- const toolName = readString11(input.sourceMessage, "tool_name") ?? input.pending?.toolCall.name ?? "tool";
22595
+ const toolCallId = readString12(input.sourceMessage, "tool_call_id") ?? input.pending?.toolCall.id;
22596
+ const toolName = readString12(input.sourceMessage, "tool_name") ?? input.pending?.toolCall.name ?? "tool";
22235
22597
  return projectHermesAgentEvent({
22236
22598
  conversationId: input.conversationId,
22237
22599
  messageId: input.messageId,
@@ -22416,23 +22778,10 @@ async function readKnownHermesSessions(store) {
22416
22778
  if (!manifest) {
22417
22779
  continue;
22418
22780
  }
22419
- if (manifest.hermes_session_id) {
22420
- sessionIds.add(manifest.hermes_session_id);
22421
- rememberKnownHermesConversation(
22422
- conversationIdsBySessionId,
22423
- manifest.hermes_session_id,
22424
- conversationId
22425
- );
22426
- }
22427
- for (const sessionId of manifest.hermes_session_ids ?? []) {
22428
- sessionIds.add(sessionId);
22429
- rememberKnownHermesConversation(
22430
- conversationIdsBySessionId,
22431
- sessionId,
22432
- conversationId
22433
- );
22434
- }
22435
22781
  for (const sessionId of [
22782
+ manifest.hermes_session_id,
22783
+ ...manifest.hermes_session_ids ?? [],
22784
+ ...Object.values(manifest.profile_session_ids ?? {}),
22436
22785
  manifest.hermes_lineage?.root_session_id,
22437
22786
  manifest.hermes_lineage?.current_session_id,
22438
22787
  ...manifest.hermes_lineage?.session_ids ?? []
@@ -22579,7 +22928,7 @@ function readHermesRawMessageRows(raw) {
22579
22928
  return [];
22580
22929
  }
22581
22930
  if (raw.format === "hermes-message-group") {
22582
- const payload = toRecord11(raw.payload);
22931
+ const payload = toRecord12(raw.payload);
22583
22932
  return Array.isArray(payload.messages) ? payload.messages.filter(
22584
22933
  (item) => typeof item === "object" && item !== null
22585
22934
  ) : [];
@@ -22617,11 +22966,11 @@ ${right}`;
22617
22966
  function projectCompressionTips(rows) {
22618
22967
  const childrenByParent = /* @__PURE__ */ new Map();
22619
22968
  for (const row of rows) {
22620
- const id = readString11(row, "id");
22969
+ const id = readString12(row, "id");
22621
22970
  if (!id) {
22622
22971
  continue;
22623
22972
  }
22624
- const parentId = readString11(row, "parent_session_id");
22973
+ const parentId = readString12(row, "parent_session_id");
22625
22974
  if (parentId) {
22626
22975
  const children = childrenByParent.get(parentId) ?? [];
22627
22976
  children.push(row);
@@ -22630,22 +22979,22 @@ function projectCompressionTips(rows) {
22630
22979
  }
22631
22980
  const projected = [];
22632
22981
  for (const row of rows) {
22633
- const id = readString11(row, "id");
22634
- if (!id || readString11(row, "parent_session_id")) {
22982
+ const id = readString12(row, "id");
22983
+ if (!id || readString12(row, "parent_session_id")) {
22635
22984
  continue;
22636
22985
  }
22637
22986
  let tip = row;
22638
22987
  const visited = /* @__PURE__ */ new Set([id]);
22639
22988
  const chain = [row];
22640
- while (readString11(tip, "end_reason") === "compression") {
22641
- const tipId2 = readString11(tip, "id");
22989
+ while (readString12(tip, "end_reason") === "compression") {
22990
+ const tipId2 = readString12(tip, "id");
22642
22991
  if (!tipId2) {
22643
22992
  break;
22644
22993
  }
22645
22994
  const next = (childrenByParent.get(tipId2) ?? []).filter((child) => isCompressionContinuation(tip, child)).sort(
22646
22995
  (left, right) => (readNumber3(right.started_at) ?? 0) - (readNumber3(left.started_at) ?? 0) || (readNumber3(right.last_active) ?? 0) - (readNumber3(left.last_active) ?? 0)
22647
22996
  )[0];
22648
- const nextId = next ? readString11(next, "id") : null;
22997
+ const nextId = next ? readString12(next, "id") : null;
22649
22998
  if (!next || !nextId || visited.has(nextId)) {
22650
22999
  break;
22651
23000
  }
@@ -22653,15 +23002,15 @@ function projectCompressionTips(rows) {
22653
23002
  visited.add(nextId);
22654
23003
  chain.push(next);
22655
23004
  }
22656
- const tipId = readString11(tip, "id");
23005
+ const tipId = readString12(tip, "id");
22657
23006
  if (tipId) {
22658
- const sessionIds = chain.map((item) => readString11(item, "id")).filter((item) => Boolean(item));
23007
+ const sessionIds = chain.map((item) => readString12(item, "id")).filter((item) => Boolean(item));
22659
23008
  projected.push({
22660
23009
  ...tip,
22661
23010
  id: tipId,
22662
23011
  _lineage_root_id: id,
22663
23012
  _lineage_session_ids: sessionIds,
22664
- _lineage_title: readString11(row, "title") ?? stripCompressionTitleSuffix2(readString11(tip, "title") ?? ""),
23013
+ _lineage_title: readString12(row, "title") ?? stripCompressionTitleSuffix2(readString12(tip, "title") ?? ""),
22665
23014
  _lineage_usage: aggregateHermesSessionUsage(chain),
22666
23015
  started_at: readNumber3(row.started_at) ?? readNumber3(tip.started_at)
22667
23016
  });
@@ -22670,10 +23019,10 @@ function projectCompressionTips(rows) {
22670
23019
  return projected;
22671
23020
  }
22672
23021
  function isCompressionContinuation(parent, child) {
22673
- const childId = readString11(child, "id");
23022
+ const childId = readString12(child, "id");
22674
23023
  const parentEndedAt = readNumber3(parent.ended_at);
22675
23024
  const childStartedAt = readNumber3(child.started_at);
22676
- return Boolean(childId) && readString11(parent, "end_reason") === "compression" && parentEndedAt !== null && childStartedAt !== null && childStartedAt >= parentEndedAt;
23025
+ return Boolean(childId) && readString12(parent, "end_reason") === "compression" && parentEndedAt !== null && childStartedAt !== null && childStartedAt >= parentEndedAt;
22677
23026
  }
22678
23027
  function aggregateHermesSessionUsage(rows) {
22679
23028
  let inputTokens = 0;
@@ -22685,8 +23034,8 @@ function aggregateHermesSessionUsage(rows) {
22685
23034
  inputTokens += readNumber3(row.input_tokens) ?? 0;
22686
23035
  outputTokens += readNumber3(row.output_tokens) ?? 0;
22687
23036
  apiCallCount += readNumber3(row.api_call_count) ?? 0;
22688
- model = readString11(row, "model") ?? model;
22689
- provider = readString11(row, "billing_provider") ?? readString11(row, "provider") ?? provider;
23037
+ model = readString12(row, "model") ?? model;
23038
+ provider = readString12(row, "billing_provider") ?? readString12(row, "provider") ?? provider;
22690
23039
  }
22691
23040
  return {
22692
23041
  input_tokens: inputTokens,
@@ -22718,7 +23067,7 @@ async function readHermesSessionMessages(candidate) {
22718
23067
  ]);
22719
23068
  const selected = jsonlMessages.length > dbMessages.length ? jsonlMessages : dbMessages;
22720
23069
  return selected.map(
22721
- (message) => readString11(message, "session_id") ? message : { ...message, session_id: candidate.session.id }
23070
+ (message) => readString12(message, "session_id") ? message : { ...message, session_id: candidate.session.id }
22722
23071
  );
22723
23072
  }
22724
23073
  async function readStateDbMessages(dbPath, sessionId) {
@@ -22786,7 +23135,7 @@ async function readJsonlMessages(profileName, sessionId) {
22786
23135
  return rows;
22787
23136
  }
22788
23137
  function normalizeJsonlMessage(row) {
22789
- const role = readString11(row, "role");
23138
+ const role = readString12(row, "role");
22790
23139
  if (!role) {
22791
23140
  return null;
22792
23141
  }
@@ -22867,7 +23216,7 @@ function collectMessageMediaReferences(message) {
22867
23216
  );
22868
23217
  }
22869
23218
  function appendImportedMediaImportFailureNotice(message) {
22870
- const hermes = toRecord11(message.hermes);
23219
+ const hermes = toRecord12(message.hermes);
22871
23220
  if (hermes.media_import_failure_notice_appended === true) {
22872
23221
  return false;
22873
23222
  }
@@ -22910,9 +23259,9 @@ function formatImportedFilenameList(filenames) {
22910
23259
  function toLinkMessage(input) {
22911
23260
  const role = normalizeMessageRole(input.message.role);
22912
23261
  const text = normalizeContent2(input.message.content);
22913
- const sessionId = readString11(input.message, "session_id") ?? input.sessionId;
23262
+ const sessionId = readString12(input.message, "session_id") ?? input.sessionId;
22914
23263
  const createdAt = isoFromHermesTime(input.message.timestamp) ?? new Date(Date.now() + input.index).toISOString();
22915
- return {
23264
+ return withAppMessageVisibility({
22916
23265
  id: `msg_${randomUUID11().replaceAll("-", "")}`,
22917
23266
  schema_version: 1,
22918
23267
  conversation_id: input.conversationId,
@@ -22938,7 +23287,7 @@ function toLinkMessage(input) {
22938
23287
  format: "hermes-message",
22939
23288
  payload: input.message
22940
23289
  }
22941
- };
23290
+ });
22942
23291
  }
22943
23292
  function senderForRole(input) {
22944
23293
  switch (input.role) {
@@ -23041,7 +23390,7 @@ function normalizeContent2(value) {
23041
23390
  return item;
23042
23391
  }
23043
23392
  if (typeof item === "object" && item !== null) {
23044
- return readString11(item, "text") ?? "";
23393
+ return readString12(item, "text") ?? "";
23045
23394
  }
23046
23395
  return "";
23047
23396
  }).filter(Boolean).join("");
@@ -23062,17 +23411,17 @@ function parseJsonValue(value) {
23062
23411
  return void 0;
23063
23412
  }
23064
23413
  }
23065
- function toRecord11(value) {
23414
+ function toRecord12(value) {
23066
23415
  return typeof value === "object" && value !== null ? value : {};
23067
23416
  }
23068
23417
  function isDeletedSession(session) {
23069
- return readBoolean2(session.deleted) || readBoolean2(session.is_deleted) || Boolean(readString11(session, "deleted_at")) || ["deleted", "removed"].includes(readString11(session, "status") ?? "");
23418
+ return readBoolean2(session.deleted) || readBoolean2(session.is_deleted) || Boolean(readString12(session, "deleted_at")) || ["deleted", "removed"].includes(readString12(session, "status") ?? "");
23070
23419
  }
23071
23420
  function isHiddenSession(session) {
23072
- const source = readString11(session, "source")?.toLowerCase();
23073
- const status = readString11(session, "status")?.toLowerCase();
23074
- const visibility = readString11(session, "visibility")?.toLowerCase();
23075
- return Boolean(source && HIDDEN_SESSION_SOURCES.has(source)) || readBoolean2(session.hidden) || readBoolean2(session.archived) || Boolean(readString11(session, "archived_at")) || status === "hidden" || status === "archived" || visibility === "hidden" || visibility === "hide";
23421
+ const source = readString12(session, "source")?.toLowerCase();
23422
+ const status = readString12(session, "status")?.toLowerCase();
23423
+ const visibility = readString12(session, "visibility")?.toLowerCase();
23424
+ return Boolean(source && HIDDEN_SESSION_SOURCES.has(source)) || readBoolean2(session.hidden) || readBoolean2(session.archived) || Boolean(readString12(session, "archived_at")) || status === "hidden" || status === "archived" || visibility === "hidden" || visibility === "hide";
23076
23425
  }
23077
23426
  function readTableColumns2(db, tableName) {
23078
23427
  try {
@@ -23106,7 +23455,7 @@ function isoFromHermesTime(value) {
23106
23455
  const millis = numeric > 1e10 ? numeric : numeric * 1e3;
23107
23456
  return new Date(millis).toISOString();
23108
23457
  }
23109
- function readString11(payload, key) {
23458
+ function readString12(payload, key) {
23110
23459
  const value = payload[key];
23111
23460
  return typeof value === "string" && value.trim() ? value.trim() : null;
23112
23461
  }
@@ -23263,11 +23612,11 @@ function normalizeDeliveryFileInputs(value) {
23263
23612
  }
23264
23613
  if (typeof value === "object" && value !== null && !Array.isArray(value)) {
23265
23614
  const record = value;
23266
- const filePath = readString12(record, "path") ?? readString12(record, "file");
23615
+ const filePath = readString13(record, "path") ?? readString13(record, "file");
23267
23616
  if (!filePath) {
23268
23617
  return [];
23269
23618
  }
23270
- const caption = readString12(record, "caption") ?? void 0;
23619
+ const caption = readString13(record, "caption") ?? void 0;
23271
23620
  return [{ path: filePath, ...caption ? { caption } : {} }];
23272
23621
  }
23273
23622
  if (!Array.isArray(value)) {
@@ -23281,11 +23630,11 @@ function normalizeDeliveryFileInputs(value) {
23281
23630
  return [];
23282
23631
  }
23283
23632
  const record = item;
23284
- const filePath = readString12(record, "path") ?? readString12(record, "file");
23633
+ const filePath = readString13(record, "path") ?? readString13(record, "file");
23285
23634
  if (!filePath) {
23286
23635
  return [];
23287
23636
  }
23288
- const caption = readString12(record, "caption") ?? void 0;
23637
+ const caption = readString13(record, "caption") ?? void 0;
23289
23638
  return [{ path: filePath, ...caption ? { caption } : {} }];
23290
23639
  });
23291
23640
  }
@@ -23322,7 +23671,7 @@ function pruneExpiredDeliveryContexts(now = Date.now()) {
23322
23671
  }
23323
23672
  }
23324
23673
  }
23325
- function readString12(payload, key) {
23674
+ function readString13(payload, key) {
23326
23675
  const value = payload[key];
23327
23676
  return typeof value === "string" && value.trim() ? value.trim() : null;
23328
23677
  }
@@ -23330,6 +23679,47 @@ function isNodeError14(error, code) {
23330
23679
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
23331
23680
  }
23332
23681
 
23682
+ // src/conversations/model-lifecycle-marker.ts
23683
+ import { randomUUID as randomUUID12 } from "crypto";
23684
+ var MODEL_SWITCH_MARKER_FORMAT = "hermes-link-lifecycle-marker";
23685
+ var MODEL_SWITCH_MARKER_KIND = "model_switch";
23686
+ function createModelSwitchMarker(input) {
23687
+ const text = `Model switched to ${input.model}`;
23688
+ return {
23689
+ id: `msg_model_switch_${randomUUID12().replaceAll("-", "")}`,
23690
+ schema_version: 1,
23691
+ conversation_id: input.conversationId,
23692
+ role: "system",
23693
+ status: "completed",
23694
+ visibility: "visible",
23695
+ presentation: {
23696
+ type: "lifecycle_marker",
23697
+ kind: MODEL_SWITCH_MARKER_KIND,
23698
+ model: input.model,
23699
+ ...input.provider ? { provider: input.provider } : {}
23700
+ },
23701
+ created_at: input.createdAt,
23702
+ updated_at: input.createdAt,
23703
+ sender: {
23704
+ id: "hermes_link",
23705
+ type: "system",
23706
+ display_name: "Hermes Link"
23707
+ },
23708
+ parts: [{ type: "text", text }],
23709
+ attachments: [],
23710
+ raw: {
23711
+ format: MODEL_SWITCH_MARKER_FORMAT,
23712
+ payload: {
23713
+ kind: MODEL_SWITCH_MARKER_KIND,
23714
+ model: input.model,
23715
+ ...input.provider ? { provider: input.provider } : {},
23716
+ created_at: input.createdAt,
23717
+ text
23718
+ }
23719
+ }
23720
+ };
23721
+ }
23722
+
23333
23723
  // src/conversations/run-lifecycle.ts
23334
23724
  import { createHash as createHash8 } from "crypto";
23335
23725
  import { readdir as readdir9 } from "fs/promises";
@@ -23503,7 +23893,7 @@ async function createHermesRun(input, options = {}) {
23503
23893
  );
23504
23894
  }
23505
23895
  const payload = await readJsonResponse(response);
23506
- const runId = readString13(payload, "run_id") ?? readString13(payload, "runId") ?? readString13(payload, "id");
23896
+ const runId = readString14(payload, "run_id") ?? readString14(payload, "runId") ?? readString14(payload, "id");
23507
23897
  if (!runId) {
23508
23898
  throw new LinkHttpError(
23509
23899
  502,
@@ -23540,8 +23930,8 @@ async function readHermesRunStatus(runId, options = {}) {
23540
23930
  options.language
23541
23931
  );
23542
23932
  const payload = await readJsonResponse(response);
23543
- const status = readString13(payload, "status");
23544
- const resolvedRunId = readString13(payload, "run_id") ?? readString13(payload, "runId") ?? runId;
23933
+ const status = readString14(payload, "status");
23934
+ const resolvedRunId = readString14(payload, "run_id") ?? readString14(payload, "runId") ?? runId;
23545
23935
  if (!status) {
23546
23936
  throw new LinkHttpError(
23547
23937
  502,
@@ -23550,15 +23940,15 @@ async function readHermesRunStatus(runId, options = {}) {
23550
23940
  );
23551
23941
  }
23552
23942
  return {
23553
- object: readString13(payload, "object") ?? void 0,
23943
+ object: readString14(payload, "object") ?? void 0,
23554
23944
  run_id: resolvedRunId,
23555
23945
  status,
23556
23946
  output: payload.output,
23557
23947
  usage: payload.usage,
23558
23948
  error: payload.error,
23559
- last_event: readString13(payload, "last_event") ?? void 0,
23560
- session_id: readString13(payload, "session_id") ?? void 0,
23561
- model: readString13(payload, "model") ?? void 0,
23949
+ last_event: readString14(payload, "last_event") ?? void 0,
23950
+ session_id: readString14(payload, "session_id") ?? void 0,
23951
+ model: readString14(payload, "model") ?? void 0,
23562
23952
  created_at: payload.created_at,
23563
23953
  updated_at: payload.updated_at,
23564
23954
  raw: payload
@@ -23783,12 +24173,12 @@ function parseHermesApiCapabilities(payload) {
23783
24173
  source: "reported",
23784
24174
  authRequired: readBoolean3(auth, "required"),
23785
24175
  responsesStreaming: readBoolean3(features, "responses_streaming"),
23786
- runStopPath: readBoolean3(features, "run_stop") === false ? null : readString13(runStop, "path"),
23787
- sessionContinuityHeader: readString13(
24176
+ runStopPath: readBoolean3(features, "run_stop") === false ? null : readString14(runStop, "path"),
24177
+ sessionContinuityHeader: readString14(
23788
24178
  features,
23789
24179
  "session_continuity_header"
23790
24180
  ),
23791
- sessionKeyHeader: readString13(features, "session_key_header")
24181
+ sessionKeyHeader: readString14(features, "session_key_header")
23792
24182
  };
23793
24183
  }
23794
24184
  async function callHermesApi(path38, init, options) {
@@ -24014,14 +24404,14 @@ function isRecord2(value) {
24014
24404
  }
24015
24405
  function readUpstreamMessage(payload, raw) {
24016
24406
  const error = typeof payload?.error === "object" && payload.error !== null ? payload.error : null;
24017
- const message = readString13(error ?? {}, "message") ?? readString13(payload ?? {}, "message");
24407
+ const message = readString14(error ?? {}, "message") ?? readString14(payload ?? {}, "message");
24018
24408
  if (message) {
24019
24409
  return message;
24020
24410
  }
24021
24411
  const body = raw.trim().replace(/\s+/gu, " ").slice(0, 500);
24022
24412
  return body || "empty response body";
24023
24413
  }
24024
- function readString13(payload, key) {
24414
+ function readString14(payload, key) {
24025
24415
  const value = payload[key];
24026
24416
  return typeof value === "string" && value.trim() ? value.trim() : null;
24027
24417
  }
@@ -24785,14 +25175,14 @@ async function countConfiguredTools(profileName) {
24785
25175
  if (!raw.trim()) {
24786
25176
  return 0;
24787
25177
  }
24788
- const config = toRecord12(YAML2.parse(raw));
25178
+ const config = toRecord13(YAML2.parse(raw));
24789
25179
  const toolsets = /* @__PURE__ */ new Set();
24790
25180
  collectToolsetValues(config.toolsets, toolsets);
24791
- const platformToolsets = toRecord12(config.platform_toolsets);
25181
+ const platformToolsets = toRecord13(config.platform_toolsets);
24792
25182
  for (const value of Object.values(platformToolsets)) {
24793
25183
  collectToolsetValues(value, toolsets);
24794
25184
  }
24795
- const mcpServers = Object.keys(toRecord12(config.mcp_servers)).length;
25185
+ const mcpServers = Object.keys(toRecord13(config.mcp_servers)).length;
24796
25186
  return toolsets.size + mcpServers;
24797
25187
  }
24798
25188
  function collectToolsetValues(value, target) {
@@ -24806,7 +25196,7 @@ function collectToolsetValues(value, target) {
24806
25196
  target.add(value.trim());
24807
25197
  }
24808
25198
  }
24809
- function toRecord12(value) {
25199
+ function toRecord13(value) {
24810
25200
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
24811
25201
  }
24812
25202
 
@@ -25226,7 +25616,7 @@ async function readUsageProbeConfigStatus(input) {
25226
25616
  changed: false
25227
25617
  };
25228
25618
  }
25229
- const plugins = toRecord13(config.plugins);
25619
+ const plugins = toRecord14(config.plugins);
25230
25620
  if (plugins.enabled !== void 0 && !Array.isArray(plugins.enabled)) {
25231
25621
  return {
25232
25622
  enabled: false,
@@ -25459,7 +25849,7 @@ async function readHermesConfigDocument2(configPath, language) {
25459
25849
  }
25460
25850
  return {
25461
25851
  document,
25462
- config: toRecord13(document.toJSON()),
25852
+ config: toRecord14(document.toJSON()),
25463
25853
  existingRaw
25464
25854
  };
25465
25855
  }
@@ -25501,7 +25891,7 @@ function parseUsageProbeEvent(line) {
25501
25891
  if (payload.event !== "post_api_request") {
25502
25892
  return null;
25503
25893
  }
25504
- const profile = readString14(payload.profile);
25894
+ const profile = readString15(payload.profile);
25505
25895
  const promptTokens = readInteger2(payload.prompt_tokens) ?? readInteger2(payload.input_tokens);
25506
25896
  if (!profile || promptTokens === void 0) {
25507
25897
  return null;
@@ -25509,17 +25899,17 @@ function parseUsageProbeEvent(line) {
25509
25899
  const completionTokens = readInteger2(payload.completion_tokens) ?? readInteger2(payload.output_tokens) ?? 0;
25510
25900
  return {
25511
25901
  profile,
25512
- sessionId: readString14(payload.session_id),
25513
- taskId: readString14(payload.task_id),
25902
+ sessionId: readString15(payload.session_id),
25903
+ taskId: readString15(payload.task_id),
25514
25904
  apiCallCount: readInteger2(payload.api_call_count) ?? 0,
25515
25905
  promptTokens,
25516
25906
  completionTokens,
25517
25907
  totalTokens: readInteger2(payload.total_tokens) ?? promptTokens + completionTokens,
25518
- model: readString14(payload.model),
25519
- provider: readString14(payload.provider),
25520
- apiMode: readString14(payload.api_mode),
25521
- finishReason: readString14(payload.finish_reason),
25522
- createdAt: readString14(payload.created_at) ?? (/* @__PURE__ */ new Date(0)).toISOString()
25908
+ model: readString15(payload.model),
25909
+ provider: readString15(payload.provider),
25910
+ apiMode: readString15(payload.api_mode),
25911
+ finishReason: readString15(payload.finish_reason),
25912
+ createdAt: readString15(payload.created_at) ?? (/* @__PURE__ */ new Date(0)).toISOString()
25523
25913
  };
25524
25914
  } catch {
25525
25915
  return null;
@@ -25884,7 +26274,7 @@ function uniqueStrings2(entries) {
25884
26274
  function sameStringList(left, right) {
25885
26275
  return left.length === right.length && left.every((entry, index) => entry === right[index]);
25886
26276
  }
25887
- function readString14(value) {
26277
+ function readString15(value) {
25888
26278
  return typeof value === "string" && value.trim() ? value.trim() : null;
25889
26279
  }
25890
26280
  function readInteger2(value) {
@@ -25897,7 +26287,7 @@ function readInteger2(value) {
25897
26287
  }
25898
26288
  return void 0;
25899
26289
  }
25900
- function toRecord13(value) {
26290
+ function toRecord14(value) {
25901
26291
  return isRecord3(value) ? value : {};
25902
26292
  }
25903
26293
  function isRecord3(value) {
@@ -25982,8 +26372,8 @@ function parseSseBlock(block) {
25982
26372
  if (decoded === null) {
25983
26373
  return null;
25984
26374
  }
25985
- const payload = toRecord14(decoded);
25986
- const payloadType = (readString15(payload, "type") ?? readString15(payload, "event") ?? readString15(payload, "object") ?? eventName) || "message";
26375
+ const payload = toRecord15(decoded);
26376
+ const payloadType = (readString16(payload, "type") ?? readString16(payload, "event") ?? readString16(payload, "object") ?? eventName) || "message";
25987
26377
  return { eventName, payloadType, payload, rawPayload: decoded ?? raw };
25988
26378
  }
25989
26379
  function decodeJson(value) {
@@ -25999,11 +26389,11 @@ function decodeJson(value) {
25999
26389
  return { type: "message.delta", delta: value };
26000
26390
  }
26001
26391
  }
26002
- function readString15(body, key) {
26392
+ function readString16(body, key) {
26003
26393
  const value = body[key];
26004
26394
  return typeof value === "string" && value.trim() ? value.trim() : null;
26005
26395
  }
26006
- function toRecord14(value) {
26396
+ function toRecord15(value) {
26007
26397
  return typeof value === "object" && value !== null ? value : {};
26008
26398
  }
26009
26399
 
@@ -26166,7 +26556,7 @@ async function readJsonlMessages2(sessionsDir, sessionId) {
26166
26556
  }
26167
26557
  try {
26168
26558
  const parsed = JSON.parse(line);
26169
- const role = readString16(parsed, "role");
26559
+ const role = readString17(parsed, "role");
26170
26560
  if (!role) {
26171
26561
  continue;
26172
26562
  }
@@ -26190,13 +26580,13 @@ function readHermesToolCalls2(row) {
26190
26580
  );
26191
26581
  }
26192
26582
  function normalizeHermesToolCall2(value) {
26193
- const record = toRecord15(value);
26583
+ const record = toRecord16(value);
26194
26584
  if (Object.keys(record).length === 0) {
26195
26585
  return null;
26196
26586
  }
26197
- const fn = toRecord15(record.function);
26198
- const id = readString16(record, "id") ?? readString16(record, "call_id") ?? readString16(record, "tool_call_id") ?? readString16(fn, "id") ?? void 0;
26199
- const name = readString16(fn, "name") ?? readString16(record, "name") ?? readString16(record, "tool_name") ?? readString16(record, "tool") ?? "tool";
26587
+ const fn = toRecord16(record.function);
26588
+ const id = readString17(record, "id") ?? readString17(record, "call_id") ?? readString17(record, "tool_call_id") ?? readString17(fn, "id") ?? void 0;
26589
+ const name = readString17(fn, "name") ?? readString17(record, "name") ?? readString17(record, "tool_name") ?? readString17(record, "tool") ?? "tool";
26200
26590
  const rawArguments = fn.arguments ?? record.arguments ?? record.args ?? record.input;
26201
26591
  return {
26202
26592
  ...id ? { id } : {},
@@ -26206,8 +26596,8 @@ function normalizeHermesToolCall2(value) {
26206
26596
  };
26207
26597
  }
26208
26598
  function consumePendingToolCall2(input) {
26209
- const toolCallId = readString16(input.toolMessage, "tool_call_id");
26210
- const toolName = readString16(input.toolMessage, "tool_name");
26599
+ const toolCallId = readString17(input.toolMessage, "tool_call_id");
26600
+ const toolName = readString17(input.toolMessage, "tool_name");
26211
26601
  let pending = toolCallId ? input.toolCallsById.get(toolCallId) : void 0;
26212
26602
  if (!pending && toolName) {
26213
26603
  pending = input.pendingToolCalls.find(
@@ -26230,8 +26620,8 @@ function consumePendingToolCall2(input) {
26230
26620
  function toolCompletedEvent(row, pending, existingEventId) {
26231
26621
  const output = normalizeContent3(row.content);
26232
26622
  const parsedOutput = parseJsonValue2(output);
26233
- const toolCallId = readString16(row, "tool_call_id") ?? pending?.toolCall.id;
26234
- const toolName = readString16(row, "tool_name") ?? pending?.toolCall.name ?? "tool";
26623
+ const toolCallId = readString17(row, "tool_call_id") ?? pending?.toolCall.id;
26624
+ const toolName = readString17(row, "tool_name") ?? pending?.toolCall.name ?? "tool";
26235
26625
  const payload = {
26236
26626
  type: "tool.completed",
26237
26627
  event: "tool.completed",
@@ -26275,7 +26665,7 @@ function groupReusableToolEventIds(events) {
26275
26665
  return grouped;
26276
26666
  }
26277
26667
  function consumeReusableToolEventId(grouped, pending, row) {
26278
- const toolName = pending?.toolCall.name ?? readString16(row, "tool_name") ?? "tool";
26668
+ const toolName = pending?.toolCall.name ?? readString17(row, "tool_name") ?? "tool";
26279
26669
  const key = normalizeToolTitle(humanizeToolName2(toolName));
26280
26670
  const ids = grouped.get(key);
26281
26671
  const id = ids?.shift();
@@ -26330,7 +26720,7 @@ function normalizeContent3(value) {
26330
26720
  return item;
26331
26721
  }
26332
26722
  if (typeof item === "object" && item !== null) {
26333
- return readString16(item, "text") ?? "";
26723
+ return readString17(item, "text") ?? "";
26334
26724
  }
26335
26725
  return "";
26336
26726
  }).filter(Boolean).join("");
@@ -26375,7 +26765,7 @@ async function isFile2(filePath) {
26375
26765
  function isValidProfileName3(value) {
26376
26766
  return typeof value === "string" && /^[a-zA-Z0-9._-]{1,64}$/u.test(value);
26377
26767
  }
26378
- function readString16(payload, key) {
26768
+ function readString17(payload, key) {
26379
26769
  const value = payload[key];
26380
26770
  return typeof value === "string" && value.trim() ? value.trim() : null;
26381
26771
  }
@@ -26393,7 +26783,7 @@ function readNumber4(value) {
26393
26783
  const millis = Date.parse(value);
26394
26784
  return Number.isNaN(millis) ? null : millis;
26395
26785
  }
26396
- function toRecord15(value) {
26786
+ function toRecord16(value) {
26397
26787
  return typeof value === "object" && value !== null ? value : {};
26398
26788
  }
26399
26789
  function isNodeError17(error, code) {
@@ -26493,25 +26883,25 @@ var RunToolEventIdCoalescer = class {
26493
26883
  }
26494
26884
  };
26495
26885
  function readToolEventType(event) {
26496
- const type = readString17(event.payload, "type") ?? readString17(event.payload, "event") ?? event.payloadType;
26886
+ const type = readString18(event.payload, "type") ?? readString18(event.payload, "event") ?? event.payloadType;
26497
26887
  return type.startsWith("tool.") ? type : null;
26498
26888
  }
26499
26889
  function isTerminalToolEvent(type) {
26500
26890
  return type === "tool.completed" || type === "tool.failed" || type === "tool.error";
26501
26891
  }
26502
26892
  function hasStableToolEventId(payload) {
26503
- const tool = toRecord16(payload.tool);
26504
- const call = toRecord16(payload.tool_call ?? payload.toolCall);
26505
- const fn = toRecord16(call.function ?? payload.function);
26893
+ const tool = toRecord17(payload.tool);
26894
+ const call = toRecord17(payload.tool_call ?? payload.toolCall);
26895
+ const fn = toRecord17(call.function ?? payload.function);
26506
26896
  return Boolean(
26507
- readString17(payload, "tool_call_id") ?? readString17(payload, "toolCallId") ?? readString17(payload, "tool_id") ?? readString17(payload, "call_id") ?? readString17(payload, "id") ?? readString17(tool, "id") ?? readString17(call, "id") ?? readString17(fn, "id")
26897
+ readString18(payload, "tool_call_id") ?? readString18(payload, "toolCallId") ?? readString18(payload, "tool_id") ?? readString18(payload, "call_id") ?? readString18(payload, "id") ?? readString18(tool, "id") ?? readString18(call, "id") ?? readString18(fn, "id")
26508
26898
  );
26509
26899
  }
26510
26900
  function readToolName2(payload) {
26511
- const tool = toRecord16(payload.tool);
26512
- const call = toRecord16(payload.tool_call ?? payload.toolCall);
26513
- const fn = toRecord16(call.function ?? payload.function);
26514
- return readString17(payload, "tool_name") ?? readString17(payload, "toolName") ?? readString17(payload, "name") ?? readString17(payload, "tool") ?? readString17(tool, "name") ?? readString17(call, "name") ?? readString17(fn, "name") ?? "tool";
26901
+ const tool = toRecord17(payload.tool);
26902
+ const call = toRecord17(payload.tool_call ?? payload.toolCall);
26903
+ const fn = toRecord17(call.function ?? payload.function);
26904
+ return readString18(payload, "tool_name") ?? readString18(payload, "toolName") ?? readString18(payload, "name") ?? readString18(payload, "tool") ?? readString18(tool, "name") ?? readString18(call, "name") ?? readString18(fn, "name") ?? "tool";
26515
26905
  }
26516
26906
  function withGeneratedToolEventId(event, id) {
26517
26907
  return {
@@ -26568,16 +26958,20 @@ function stableStringify2(value) {
26568
26958
  function hashStableValue(value) {
26569
26959
  return createHash7("sha256").update(value).digest("hex").slice(0, 16);
26570
26960
  }
26571
- function readString17(payload, key) {
26961
+ function readString18(payload, key) {
26572
26962
  const value = payload[key];
26573
26963
  return typeof value === "string" && value.trim() ? value.trim() : null;
26574
26964
  }
26575
- function toRecord16(value) {
26965
+ function toRecord17(value) {
26576
26966
  return typeof value === "object" && value !== null ? value : {};
26577
26967
  }
26578
26968
 
26579
26969
  // src/conversations/stream-events.ts
26580
26970
  function normalizeHermesStreamEvent(event) {
26971
+ const reasoningEvent = normalizeReasoningEvent(event);
26972
+ if (reasoningEvent) {
26973
+ return reasoningEvent;
26974
+ }
26581
26975
  const responseEvent = normalizeHermesResponseEvent(event);
26582
26976
  if (responseEvent || isHermesResponseEvent(event)) {
26583
26977
  return responseEvent;
@@ -26596,8 +26990,8 @@ function normalizeHermesStreamEvent(event) {
26596
26990
  };
26597
26991
  }
26598
26992
  if (event.eventName === "hermes.tool.progress") {
26599
- const toolName = readString18(event.payload, "tool") ?? readString18(event.payload, "name") ?? "tool";
26600
- const preview = readString18(event.payload, "label") ?? readString18(event.payload, "preview") ?? toolName;
26993
+ const toolName = readString19(event.payload, "tool") ?? readString19(event.payload, "name") ?? "tool";
26994
+ const preview = readString19(event.payload, "label") ?? readString19(event.payload, "preview") ?? toolName;
26601
26995
  return {
26602
26996
  ...event,
26603
26997
  payloadType: "tool.started",
@@ -26636,6 +27030,33 @@ function normalizeHermesStreamEvent(event) {
26636
27030
  }
26637
27031
  return null;
26638
27032
  }
27033
+ function normalizeReasoningEvent(event) {
27034
+ const type = event.payloadType || event.eventName;
27035
+ if (type === "reasoning.available" || type === "reasoning.delta" || type === "thinking.delta") {
27036
+ const text2 = readReasoningText(event.payload);
27037
+ return text2 ? {
27038
+ ...event,
27039
+ payloadType: type,
27040
+ payload: { ...event.payload, type, text: text2 }
27041
+ } : null;
27042
+ }
27043
+ if (type !== "tool.progress" && event.eventName !== "hermes.tool.progress") {
27044
+ return null;
27045
+ }
27046
+ const toolName = readString19(event.payload, "tool_name") ?? readString19(event.payload, "tool") ?? readString19(event.payload, "name");
27047
+ if (toolName !== "_thinking") {
27048
+ return null;
27049
+ }
27050
+ const text = readReasoningText(event.payload);
27051
+ return text ? {
27052
+ ...event,
27053
+ payloadType: "reasoning.available",
27054
+ payload: { ...event.payload, type: "reasoning.available", text }
27055
+ } : null;
27056
+ }
27057
+ function readReasoningText(payload) {
27058
+ return readText3(payload, "text") ?? readText3(payload, "delta") ?? readText3(payload, "preview") ?? readText3(payload, "content") ?? readText3(payload, "label");
27059
+ }
26639
27060
  function isHermesResponseEvent(event) {
26640
27061
  return event.payloadType.startsWith("response.") || event.eventName.startsWith("response.");
26641
27062
  }
@@ -26672,8 +27093,8 @@ function normalizeHermesResponseEvent(event) {
26672
27093
  }
26673
27094
  }
26674
27095
  function normalizeResponseCreated(event) {
26675
- const response = toRecord17(event.payload.response ?? event.payload);
26676
- const responseId = readString18(response, "id") ?? readString18(event.payload, "id");
27096
+ const response = toRecord18(event.payload.response ?? event.payload);
27097
+ const responseId = readString19(response, "id") ?? readString19(event.payload, "id");
26677
27098
  return responseId ? {
26678
27099
  ...event,
26679
27100
  payloadType: "response.created",
@@ -26685,11 +27106,11 @@ function normalizeResponseCreated(event) {
26685
27106
  } : null;
26686
27107
  }
26687
27108
  function normalizeResponseOutputItemAdded(event) {
26688
- const item = toRecord17(event.payload.item);
26689
- if (readString18(item, "type") !== "function_call") {
27109
+ const item = toRecord18(event.payload.item);
27110
+ if (readString19(item, "type") !== "function_call") {
26690
27111
  return null;
26691
27112
  }
26692
- const toolName = readString18(item, "name") ?? "tool";
27113
+ const toolName = readString19(item, "name") ?? "tool";
26693
27114
  const argumentsValue = parseJsonValue3(item.arguments) ?? item.arguments;
26694
27115
  return {
26695
27116
  ...event,
@@ -26699,16 +27120,16 @@ function normalizeResponseOutputItemAdded(event) {
26699
27120
  tool: toolName,
26700
27121
  tool_name: toolName,
26701
27122
  name: toolName,
26702
- tool_call_id: readString18(item, "call_id") ?? readString18(item, "id"),
27123
+ tool_call_id: readString19(item, "call_id") ?? readString19(item, "id"),
26703
27124
  arguments: argumentsValue,
26704
27125
  preview: toolName,
26705
- response_item_id: readString18(item, "id") ?? void 0
27126
+ response_item_id: readString19(item, "id") ?? void 0
26706
27127
  }
26707
27128
  };
26708
27129
  }
26709
27130
  function normalizeResponseOutputItemDone(event) {
26710
- const item = toRecord17(event.payload.item);
26711
- if (readString18(item, "type") === "message") {
27131
+ const item = toRecord18(event.payload.item);
27132
+ if (readString19(item, "type") === "message") {
26712
27133
  const delta = extractResponseAssistantText({ output: [item] });
26713
27134
  return delta ? {
26714
27135
  ...event,
@@ -26716,7 +27137,7 @@ function normalizeResponseOutputItemDone(event) {
26716
27137
  payload: { type: "message.delta", delta }
26717
27138
  } : null;
26718
27139
  }
26719
- if (readString18(item, "type") !== "function_call_output") {
27140
+ if (readString19(item, "type") !== "function_call_output") {
26720
27141
  return null;
26721
27142
  }
26722
27143
  const output = readResponseItemOutput(item.output);
@@ -26726,41 +27147,41 @@ function normalizeResponseOutputItemDone(event) {
26726
27147
  payloadType: "tool.completed",
26727
27148
  payload: {
26728
27149
  type: "tool.completed",
26729
- tool_call_id: readString18(item, "call_id") ?? readString18(item, "id"),
26730
- status: readString18(item, "status") ?? "completed",
27150
+ tool_call_id: readString19(item, "call_id") ?? readString19(item, "id"),
27151
+ status: readString19(item, "status") ?? "completed",
26731
27152
  output,
26732
27153
  content: output,
26733
27154
  result: parsedOutput ?? output,
26734
- response_item_id: readString18(item, "id") ?? void 0
27155
+ response_item_id: readString19(item, "id") ?? void 0
26735
27156
  }
26736
27157
  };
26737
27158
  }
26738
27159
  function normalizeResponseCompleted(event) {
26739
- const response = toRecord17(event.payload.response);
27160
+ const response = toRecord18(event.payload.response);
26740
27161
  return {
26741
27162
  ...event,
26742
27163
  payloadType: "run.completed",
26743
27164
  payload: {
26744
27165
  type: "run.completed",
26745
- response_id: readString18(response, "id") ?? readString18(event.payload, "id"),
26746
- usage: toRecord17(response.usage),
27166
+ response_id: readString19(response, "id") ?? readString19(event.payload, "id"),
27167
+ usage: toRecord18(response.usage),
26747
27168
  response
26748
27169
  }
26749
27170
  };
26750
27171
  }
26751
27172
  function normalizeResponseFailed(event) {
26752
- const response = toRecord17(event.payload.response);
26753
- const error = toRecord17(response.error);
27173
+ const response = toRecord18(event.payload.response);
27174
+ const error = toRecord18(response.error);
26754
27175
  return {
26755
27176
  ...event,
26756
27177
  payloadType: "run.failed",
26757
27178
  payload: {
26758
27179
  type: "run.failed",
26759
- response_id: readString18(response, "id") ?? readString18(event.payload, "id"),
27180
+ response_id: readString19(response, "id") ?? readString19(event.payload, "id"),
26760
27181
  error: {
26761
- message: readString18(error, "message") ?? readString18(event.payload, "message") ?? "Hermes run failed"
27182
+ message: readString19(error, "message") ?? readString19(event.payload, "message") ?? "Hermes run failed"
26762
27183
  },
26763
- usage: toRecord17(response.usage),
27184
+ usage: toRecord18(response.usage),
26764
27185
  response
26765
27186
  }
26766
27187
  };
@@ -26784,8 +27205,8 @@ function readErrorMessage4(payload) {
26784
27205
  if (typeof payload.error === "string" && payload.error.trim()) {
26785
27206
  return payload.error.trim();
26786
27207
  }
26787
- const error = toRecord17(payload.error);
26788
- return readString18(error, "message") ?? readString18(payload, "message");
27208
+ const error = toRecord18(payload.error);
27209
+ return readString19(error, "message") ?? readString19(payload, "message");
26789
27210
  }
26790
27211
  function readDelta(payload) {
26791
27212
  return readText3(payload, "delta") ?? readText3(payload, "text") ?? readText3(payload, "content");
@@ -26794,8 +27215,8 @@ function extractResponseAssistantText(value) {
26794
27215
  if (typeof value === "string") {
26795
27216
  return value.trim().length > 0 ? value : null;
26796
27217
  }
26797
- const payload = toRecord17(value);
26798
- const response = toRecord17(payload.response ?? value);
27218
+ const payload = toRecord18(value);
27219
+ const response = toRecord18(payload.response ?? value);
26799
27220
  const directOutput = readText3(response, "output");
26800
27221
  if (directOutput?.trim()) {
26801
27222
  return directOutput;
@@ -26827,15 +27248,15 @@ function isTopLevelErrorEvent(event) {
26827
27248
  }
26828
27249
  function readChatCompletionDelta(payload) {
26829
27250
  const choice = readFirstChoice(payload);
26830
- const delta = toRecord17(choice.delta);
27251
+ const delta = toRecord18(choice.delta);
26831
27252
  return readText3(delta, "content");
26832
27253
  }
26833
27254
  function readChatCompletionFinishReason(payload) {
26834
27255
  const choice = readFirstChoice(payload);
26835
- return readString18(choice, "finish_reason") ?? readString18(choice, "finishReason");
27256
+ return readString19(choice, "finish_reason") ?? readString19(choice, "finishReason");
26836
27257
  }
26837
27258
  function readChatCompletionUsage(payload) {
26838
- const usage = toRecord17(payload.usage);
27259
+ const usage = toRecord18(payload.usage);
26839
27260
  const input = readInteger3(usage, "prompt_tokens") ?? readInteger3(usage, "input_tokens");
26840
27261
  const output = readInteger3(usage, "completion_tokens") ?? readInteger3(usage, "output_tokens");
26841
27262
  const total = readInteger3(usage, "total_tokens");
@@ -26864,15 +27285,15 @@ function readFirstChoice(payload) {
26864
27285
  if (!Array.isArray(choices)) {
26865
27286
  return {};
26866
27287
  }
26867
- return toRecord17(choices[0]);
27288
+ return toRecord18(choices[0]);
26868
27289
  }
26869
27290
  function readAssistantTextFromChoices(payload) {
26870
27291
  const choices = payload.choices;
26871
27292
  if (!Array.isArray(choices)) {
26872
27293
  return null;
26873
27294
  }
26874
- const messages2 = choices.map(toRecord17).map((choice) => toRecord17(choice.message ?? choice.delta)).filter((message) => {
26875
- const role = readString18(message, "role");
27295
+ const messages2 = choices.map(toRecord18).map((choice) => toRecord18(choice.message ?? choice.delta)).filter((message) => {
27296
+ const role = readString19(message, "role");
26876
27297
  return !role || role === "assistant";
26877
27298
  }).map(readResponseMessageText).filter((text) => Boolean(text?.trim()));
26878
27299
  return messages2.length > 0 ? messages2.join("\n\n") : null;
@@ -26888,7 +27309,7 @@ function readInteger3(payload, key) {
26888
27309
  }
26889
27310
  return void 0;
26890
27311
  }
26891
- function readString18(payload, key) {
27312
+ function readString19(payload, key) {
26892
27313
  const value = payload[key];
26893
27314
  return typeof value === "string" && value.trim() ? value.trim() : null;
26894
27315
  }
@@ -26900,9 +27321,9 @@ function readResponseOutputItemText(value) {
26900
27321
  if (typeof value === "string") {
26901
27322
  return value;
26902
27323
  }
26903
- const item = toRecord17(value);
26904
- const type = readString18(item, "type");
26905
- const role = readString18(item, "role");
27324
+ const item = toRecord18(value);
27325
+ const type = readString19(item, "type");
27326
+ const role = readString19(item, "role");
26906
27327
  if (type && type !== "message" && type !== "output_text" && type !== "text") {
26907
27328
  return null;
26908
27329
  }
@@ -26920,15 +27341,15 @@ function readResponseContentText(value) {
26920
27341
  return value;
26921
27342
  }
26922
27343
  if (!Array.isArray(value)) {
26923
- const record = toRecord17(value);
27344
+ const record = toRecord18(value);
26924
27345
  return readText3(record, "text") ?? readText3(record, "content") ?? readText3(record, "output_text") ?? readText3(record, "refusal");
26925
27346
  }
26926
27347
  const chunks = value.map((partValue) => {
26927
27348
  if (typeof partValue === "string") {
26928
27349
  return partValue;
26929
27350
  }
26930
- const part = toRecord17(partValue);
26931
- const type = readString18(part, "type");
27351
+ const part = toRecord18(partValue);
27352
+ const type = readString19(part, "type");
26932
27353
  if (type && !isVisibleResponseTextPart(type)) {
26933
27354
  return null;
26934
27355
  }
@@ -26947,7 +27368,7 @@ function readResponseItemOutput(value) {
26947
27368
  if (!Array.isArray(value)) {
26948
27369
  return stringifyJsonValue(value);
26949
27370
  }
26950
- const text = value.map(toRecord17).map((part) => readText3(part, "text") ?? readText3(part, "content") ?? "").join("");
27371
+ const text = value.map(toRecord18).map((part) => readText3(part, "text") ?? readText3(part, "content") ?? "").join("");
26951
27372
  return text || stringifyJsonValue(value);
26952
27373
  }
26953
27374
  function parseJsonValue3(value) {
@@ -26973,7 +27394,7 @@ function stringifyJsonValue(value) {
26973
27394
  return String(value);
26974
27395
  }
26975
27396
  }
26976
- function toRecord17(value) {
27397
+ function toRecord18(value) {
26977
27398
  return typeof value === "object" && value !== null ? value : {};
26978
27399
  }
26979
27400
 
@@ -28305,7 +28726,7 @@ var ConversationRunLifecycle = class {
28305
28726
 
28306
28727
  ${input.fallbackInput}` : input.fallbackInput;
28307
28728
  }
28308
- const content = messageText(userMessage);
28729
+ const content = messageText2(userMessage);
28309
28730
  const voiceLines = [];
28310
28731
  for (const part of userMessage.parts.filter(isVoicePart)) {
28311
28732
  const audioPath = part.local_path ?? (part.blob ? blobPath(this.deps.paths, part.blob) : "");
@@ -28622,7 +29043,7 @@ ${resolved}` : resolved;
28622
29043
  if (!assistant) {
28623
29044
  return false;
28624
29045
  }
28625
- return messageText(assistant).length > 0 || (assistant.agent_events?.length ?? 0) > 0 || (assistant.approvals?.length ?? 0) > 0 || assistant.parts.some((part) => part.type !== "text");
29046
+ return messageText2(assistant).length > 0 || (assistant.agent_events?.length ?? 0) > 0 || (assistant.approvals?.length ?? 0) > 0 || assistant.parts.some((part) => part.type !== "text");
28626
29047
  }
28627
29048
  async appendAssistantTextFromCompletedResponse(conversationId, runId, event) {
28628
29049
  const terminalText = extractResponseAssistantText(event.payload);
@@ -28738,6 +29159,7 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
28738
29159
  }
28739
29160
  return null;
28740
29161
  }
29162
+ const isReasoningEvent = isReasoningStreamEvent(event.payloadType);
28741
29163
  let goalStatus = null;
28742
29164
  if (event.payloadType === "status.update") {
28743
29165
  goalStatus = await this.persistGoalStatusUpdate(
@@ -28763,32 +29185,36 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
28763
29185
  raw: { format: "hermes-run-event", payload: event.rawPayload }
28764
29186
  });
28765
29187
  if (messageId) {
28766
- await this.persistAgentEventProjection(
28767
- conversationId,
28768
- messageId,
28769
- conversationEvent
28770
- );
28771
- await this.persistApprovalRequest(
28772
- conversationId,
28773
- runId,
28774
- messageId,
28775
- conversationEvent,
28776
- event
28777
- );
28778
- await this.importMediaReferences(
28779
- conversationId,
28780
- runId,
28781
- messageId,
28782
- mediaReferences
28783
- );
29188
+ if (isReasoningEvent) {
29189
+ await this.appendThinkingDelta(conversationId, runId, messageId, event);
29190
+ } else {
29191
+ await this.persistAgentEventProjection(
29192
+ conversationId,
29193
+ messageId,
29194
+ conversationEvent
29195
+ );
29196
+ await this.persistApprovalRequest(
29197
+ conversationId,
29198
+ runId,
29199
+ messageId,
29200
+ conversationEvent,
29201
+ event
29202
+ );
29203
+ await this.importMediaReferences(
29204
+ conversationId,
29205
+ runId,
29206
+ messageId,
29207
+ mediaReferences
29208
+ );
29209
+ }
28784
29210
  }
28785
29211
  return goalStatus;
28786
29212
  }
28787
29213
  async persistGoalStatusUpdate(conversationId, runId, event) {
28788
- if (readString19(event.payload, "kind") !== "goal") {
29214
+ if (readString20(event.payload, "kind") !== "goal") {
28789
29215
  return null;
28790
29216
  }
28791
- const text = readString19(event.payload, "text") ?? readString19(event.payload, "message") ?? readString19(event.payload, "status") ?? "";
29217
+ const text = readString20(event.payload, "text") ?? readString20(event.payload, "message") ?? readString20(event.payload, "status") ?? "";
28792
29218
  const manifest = await this.deps.readRunnableManifest(conversationId);
28793
29219
  const snapshot = await this.deps.readSnapshot(conversationId);
28794
29220
  const run = snapshot.runs.find((item) => item.id === runId);
@@ -28975,8 +29401,8 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
28975
29401
  }
28976
29402
  const textPart = assistant.parts.find((part) => part.type === "text");
28977
29403
  const currentText = textPart?.text ?? "";
28978
- const pendingDeliveryText = readString19(
28979
- toRecord18(assistant.hermes),
29404
+ const pendingDeliveryText = readString20(
29405
+ toRecord19(assistant.hermes),
28980
29406
  "pending_media_delivery_text"
28981
29407
  );
28982
29408
  const normalizedDelta = normalizeStreamingTextDelta(
@@ -28991,7 +29417,7 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
28991
29417
  pendingDeliveryText ?? ""
28992
29418
  );
28993
29419
  const nextHermes = {
28994
- ...toRecord18(assistant.hermes),
29420
+ ...toRecord19(assistant.hermes),
28995
29421
  ...extracted.pendingText ? { pending_media_delivery_text: extracted.pendingText } : {}
28996
29422
  };
28997
29423
  if (!extracted.pendingText) {
@@ -29026,13 +29452,47 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
29026
29452
  extracted.references
29027
29453
  );
29028
29454
  }
29455
+ async appendThinkingDelta(conversationId, runId, messageId, event) {
29456
+ const delta = readDelta(event.payload);
29457
+ if (!delta) {
29458
+ return;
29459
+ }
29460
+ const snapshot = await this.deps.readSnapshot(conversationId);
29461
+ const assistant = snapshot.messages.find(
29462
+ (message) => message.id === messageId
29463
+ );
29464
+ const hasAssistantText = assistant != null && messageText2(assistant).trim().length > 0;
29465
+ const run = snapshot.runs.find((item) => item.id === runId);
29466
+ if (!assistant || hasAssistantText || run?.status !== "running") {
29467
+ return;
29468
+ }
29469
+ await this.deps.appendEvent(conversationId, {
29470
+ type: "message.delta",
29471
+ message_id: messageId,
29472
+ run_id: runId,
29473
+ payload: {
29474
+ phase: "thinking",
29475
+ delta,
29476
+ source: event.payloadType,
29477
+ segment_id: this.thinkingSegmentId(runId, event)
29478
+ },
29479
+ raw: {
29480
+ format: "hermes-run-event",
29481
+ payload: event.rawPayload
29482
+ }
29483
+ });
29484
+ }
29485
+ thinkingSegmentId(runId, event) {
29486
+ const payload = event.payload;
29487
+ return readString20(payload, "segment_id") ?? readString20(payload, "segmentId") ?? readString20(payload, "id") ?? readString20(payload, "tool_call_id") ?? readString20(payload, "tool_id") ?? `${event.payloadType}:${runId}`;
29488
+ }
29029
29489
  async runRequestsAppDelivery(conversationId, runId) {
29030
29490
  const snapshot = await this.deps.readSnapshot(conversationId).catch(() => null);
29031
29491
  const run = snapshot?.runs.find((item) => item.id === runId);
29032
29492
  const user = snapshot?.messages.find(
29033
29493
  (message) => message.id === run?.trigger_message_id
29034
29494
  );
29035
- return user ? messageRequestsAppDelivery(messageText(user)) : false;
29495
+ return user ? messageRequestsAppDelivery(messageText2(user)) : false;
29036
29496
  }
29037
29497
  async completeRun(conversationId, runId, source) {
29038
29498
  await this.refreshRunHermesCompressionTip(conversationId, runId);
@@ -29090,7 +29550,7 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
29090
29550
  conversationId,
29091
29551
  runId,
29092
29552
  assistant.id,
29093
- collectMediaTags(messageText(assistant))
29553
+ collectMediaTags(messageText2(assistant))
29094
29554
  );
29095
29555
  snapshot = await this.deps.readSnapshot(conversationId);
29096
29556
  const refreshedRun = snapshot.runs.find((item) => item.id === runId);
@@ -29651,7 +30111,7 @@ ${details.join("\n")}` : localizedEmptyHermesResponseMessage(language);
29651
30111
  includeDisabled: true
29652
30112
  });
29653
30113
  return new Set(
29654
- jobs.map((job) => readString19(job, "id") ?? readString19(job, "job_id")).filter((id) => Boolean(id))
30114
+ jobs.map((job) => readString20(job, "id") ?? readString20(job, "job_id")).filter((id) => Boolean(id))
29655
30115
  );
29656
30116
  }
29657
30117
  async bindNewCronJobsCreatedByRun(input) {
@@ -29694,7 +30154,7 @@ function guidedInterruptNote() {
29694
30154
  ].join("\n");
29695
30155
  }
29696
30156
  function appendMediaImportFailureNotice(message) {
29697
- const hermes = toRecord18(message.hermes);
30157
+ const hermes = toRecord19(message.hermes);
29698
30158
  if (hermes.media_import_failure_notice_appended === true) {
29699
30159
  return;
29700
30160
  }
@@ -29751,11 +30211,11 @@ async function readdirWithDirs(directory) {
29751
30211
  throw error;
29752
30212
  });
29753
30213
  }
29754
- function readString19(payload, key) {
30214
+ function readString20(payload, key) {
29755
30215
  const value = payload[key];
29756
30216
  return typeof value === "string" && value.trim() ? value.trim() : null;
29757
30217
  }
29758
- function toRecord18(value) {
30218
+ function toRecord19(value) {
29759
30219
  return typeof value === "object" && value !== null ? value : {};
29760
30220
  }
29761
30221
  function insertLifecycleMarkerBeforeAssistant(snapshot, marker, run) {
@@ -29813,13 +30273,13 @@ function timestampBeforeAssistantForRun(snapshot, run, fallback) {
29813
30273
  }
29814
30274
  function findContextCompressionMarker(snapshot, operationId) {
29815
30275
  return snapshot.messages.find((message) => {
29816
- const payload = toRecord18(message.raw?.payload);
30276
+ const payload = toRecord19(message.raw?.payload);
29817
30277
  return message.raw?.format === CONTEXT_COMPRESSION_MARKER_FORMAT && payload.kind === CONTEXT_COMPRESSION_MARKER_KIND && payload.operation_id === operationId;
29818
30278
  });
29819
30279
  }
29820
30280
  function findGoalCompletionMarker(snapshot, runId) {
29821
30281
  return snapshot.messages.find((message) => {
29822
- const payload = toRecord18(message.raw?.payload);
30282
+ const payload = toRecord19(message.raw?.payload);
29823
30283
  return message.raw?.format === GOAL_LIFECYCLE_MARKER_FORMAT && payload.kind === GOAL_COMPLETION_MARKER_KIND && payload.run_id === runId;
29824
30284
  });
29825
30285
  }
@@ -29834,7 +30294,7 @@ function nextContextCompressionGeneration(snapshot) {
29834
30294
  return maxGeneration + 1;
29835
30295
  }
29836
30296
  function contextCompressionGeneration(message) {
29837
- const payload = toRecord18(message.raw?.payload);
30297
+ const payload = toRecord19(message.raw?.payload);
29838
30298
  if (message.raw?.format !== CONTEXT_COMPRESSION_MARKER_FORMAT || payload.kind !== CONTEXT_COMPRESSION_MARKER_KIND) {
29839
30299
  return null;
29840
30300
  }
@@ -29842,11 +30302,11 @@ function contextCompressionGeneration(message) {
29842
30302
  return typeof generation === "number" && Number.isFinite(generation) ? Math.max(0, Math.floor(generation)) : null;
29843
30303
  }
29844
30304
  function readPreviousSessionId(payload) {
29845
- return readString19(payload, "old_session_id") ?? readString19(payload, "oldSessionId") ?? readString19(payload, "previous_session_id") ?? readString19(payload, "previousSessionId");
30305
+ return readString20(payload, "old_session_id") ?? readString20(payload, "oldSessionId") ?? readString20(payload, "previous_session_id") ?? readString20(payload, "previousSessionId");
29846
30306
  }
29847
30307
  function readNextSessionId(payload) {
29848
- const info = toRecord18(payload.info);
29849
- return readString19(payload, "session_key") ?? readString19(payload, "sessionKey") ?? readString19(payload, "stored_session_id") ?? readString19(payload, "storedSessionId") ?? readString19(payload, "session_id") ?? readString19(payload, "sessionId") ?? readString19(info, "session_key") ?? readString19(info, "sessionKey");
30308
+ const info = toRecord19(payload.info);
30309
+ return readString20(payload, "session_key") ?? readString20(payload, "sessionKey") ?? readString20(payload, "stored_session_id") ?? readString20(payload, "storedSessionId") ?? readString20(payload, "session_id") ?? readString20(payload, "sessionId") ?? readString20(info, "session_key") ?? readString20(info, "sessionKey");
29850
30310
  }
29851
30311
  function eventPayloadWithLanguage(payload, language) {
29852
30312
  return { ...payload, language };
@@ -29934,17 +30394,17 @@ function isFileSearchCompletion(payloadType, payload) {
29934
30394
  if (payloadType !== "tool.completed") {
29935
30395
  return false;
29936
30396
  }
29937
- const tool = toRecord18(payload.tool);
29938
- const toolCall = toRecord18(payload.tool_call ?? payload.toolCall);
29939
- const fn = toRecord18(toolCall.function ?? payload.function);
30397
+ const tool = toRecord19(payload.tool);
30398
+ const toolCall = toRecord19(payload.tool_call ?? payload.toolCall);
30399
+ const fn = toRecord19(toolCall.function ?? payload.function);
29940
30400
  const candidates = [
29941
- readString19(payload, "tool_name"),
29942
- readString19(payload, "toolName"),
29943
- readString19(payload, "name"),
29944
- readString19(payload, "tool"),
29945
- readString19(tool, "name"),
29946
- readString19(toolCall, "name"),
29947
- readString19(fn, "name")
30401
+ readString20(payload, "tool_name"),
30402
+ readString20(payload, "toolName"),
30403
+ readString20(payload, "name"),
30404
+ readString20(payload, "tool"),
30405
+ readString20(tool, "name"),
30406
+ readString20(toolCall, "name"),
30407
+ readString20(fn, "name")
29948
30408
  ].filter((value) => Boolean(value)).map(normalizeToolName);
29949
30409
  return candidates.some(
29950
30410
  (name) => [
@@ -30116,6 +30576,9 @@ function reasoningEffortForRun(run) {
30116
30576
  }
30117
30577
  return effort;
30118
30578
  }
30579
+ function isReasoningStreamEvent(payloadType) {
30580
+ return payloadType === "reasoning.available" || payloadType === "reasoning.delta" || payloadType === "thinking.delta";
30581
+ }
30119
30582
  function mergeRunUsage(previous, next) {
30120
30583
  const nextContextWindow = next.context_window ?? previous?.context_window;
30121
30584
  const nextContextTokens = next.context_tokens ?? refineEstimatedContextTokens(previous, next.input_tokens, nextContextWindow);
@@ -30212,14 +30675,14 @@ function readResponseId(payload) {
30212
30675
  if (!payload) {
30213
30676
  return null;
30214
30677
  }
30215
- const response = toRecord18(payload.response);
30216
- return readString19(payload, "response_id") ?? readString19(response, "id");
30678
+ const response = toRecord19(payload.response);
30679
+ return readString20(payload, "response_id") ?? readString20(response, "id");
30217
30680
  }
30218
30681
  function readRunId(payload) {
30219
30682
  if (!payload) {
30220
30683
  return null;
30221
30684
  }
30222
- return readString19(payload, "run_id") ?? readString19(payload, "runId");
30685
+ return readString20(payload, "run_id") ?? readString20(payload, "runId");
30223
30686
  }
30224
30687
  function isCompletedRunStatus(status) {
30225
30688
  return status === "completed" || status === "complete" || status === "succeeded" || status === "success" || status === "done";
@@ -30237,8 +30700,8 @@ function readStatusErrorMessage(value) {
30237
30700
  if (typeof value === "string" && value.trim()) {
30238
30701
  return value.trim();
30239
30702
  }
30240
- const record = toRecord18(value);
30241
- return readString19(record, "message") ?? readString19(record, "error");
30703
+ const record = toRecord19(value);
30704
+ return readString20(record, "message") ?? readString20(record, "error");
30242
30705
  }
30243
30706
  function formatUnknownErrorMessage(error) {
30244
30707
  return error instanceof Error ? error.message : String(error);
@@ -30281,7 +30744,7 @@ function previewText2(message) {
30281
30744
  if (!message) {
30282
30745
  return null;
30283
30746
  }
30284
- const text = messageText(message).replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
30747
+ const text = messageText2(message).replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
30285
30748
  return text ? text.slice(0, 512) : null;
30286
30749
  }
30287
30750
  function runNotificationSourceEventId(conversationId, runId, eventKind) {
@@ -30328,6 +30791,12 @@ function isNodeError18(error, code) {
30328
30791
  // src/conversations/conversation-service.ts
30329
30792
  var ALL_CONVERSATION_EVENTS = "conversation:*";
30330
30793
  var HERMES_ARCHIVE_STATE_SYNC_ID = "hermes-agent-archive-state-v1";
30794
+ function runtimeMatchesConfiguredModel(runtime, model) {
30795
+ return runtime.model.id === model.id && (runtime.model.provider_key ?? runtime.model.provider ?? "") === model.provider && normalizeModelEndpoint(runtime.model.base_url) === normalizeModelEndpoint(model.baseUrl) && (runtime.model.api_mode ?? "") === (model.apiMode ?? "");
30796
+ }
30797
+ function normalizeModelEndpoint(value) {
30798
+ return value?.trim().replace(/\/+$/u, "") ?? "";
30799
+ }
30331
30800
  function isConversationNotificationEvent(event) {
30332
30801
  const type = event.type.toLowerCase();
30333
30802
  return type === "conversation.created" || type === "conversation.updated" || type === "conversation.goal.updated" || isAlwaysPublishedNotificationEvent(type) || type === "message.created" || type === "message.completed" || type === "message.failed" || type === "run.started" || type === "run.queued" || type === "run.completed" || type === "run.failed" || type === "run.cancelled" || type === "run.canceled" || type === "approval.requested" || type === "input_request.created" || readPayloadBool(event.payload, "requires_action") || readPayloadBool(event.payload, "requires_user_action") || readPayloadBool(event.payload, "requires_approval");
@@ -30535,7 +31004,7 @@ var ConversationService = class {
30535
31004
  async createConversation(input = {}) {
30536
31005
  await this.store.ensureConversationsDir();
30537
31006
  const now = (/* @__PURE__ */ new Date()).toISOString();
30538
- const id = `conv_${randomUUID12().replaceAll("-", "")}`;
31007
+ const id = `conv_${randomUUID13().replaceAll("-", "")}`;
30539
31008
  const title = input.title?.trim() || DEFAULT_CONVERSATION_TITLE;
30540
31009
  const profile = await resolveConversationProfileTarget(
30541
31010
  this.paths,
@@ -30778,7 +31247,7 @@ var ConversationService = class {
30778
31247
  updated_at: now
30779
31248
  } : manifest;
30780
31249
  const message = {
30781
- id: `msg_${randomUUID12().replaceAll("-", "")}`,
31250
+ id: `msg_${randomUUID13().replaceAll("-", "")}`,
30782
31251
  schema_version: 1,
30783
31252
  conversation_id: manifest.id,
30784
31253
  role: "assistant",
@@ -31119,17 +31588,20 @@ var ConversationService = class {
31119
31588
  `model "${normalizedModelId}" is not configured for profile "${currentRuntime.profile.name}"`
31120
31589
  );
31121
31590
  }
31591
+ const shouldApplyModelConfig = configuredModel != null && !runtimeMatchesConfiguredModel(currentRuntime, configuredModel);
31592
+ const modelConfigToApply = shouldApplyModelConfig ? configuredModel : void 0;
31122
31593
  const sessionConfig = await setTuiGatewaySessionModelConfig({
31123
31594
  hermesSessionId: manifest.hermes_session_id,
31124
31595
  profileName: currentRuntime.profile.name,
31125
31596
  title: manifest.title,
31126
31597
  conversationHistory: snapshot.messages.length > 0 ? snapshot.messages.map((message) => ({
31127
31598
  role: message.role,
31128
- content: messageText(message)
31599
+ content: messageText2(message)
31129
31600
  })) : void 0,
31130
- ...configuredModel ? {
31131
- model: configuredModel.id,
31132
- provider: configuredModel.provider
31601
+ ...modelConfigToApply ? {
31602
+ model: modelConfigToApply.id,
31603
+ provider: modelConfigToApply.provider,
31604
+ forceModel: true
31133
31605
  } : {},
31134
31606
  ...reasoningEffort ? { reasoningEffort } : {},
31135
31607
  logger: this.logger,
@@ -31177,6 +31649,24 @@ var ConversationService = class {
31177
31649
  runtime
31178
31650
  }
31179
31651
  });
31652
+ let markerMessage;
31653
+ let markerEventSeq;
31654
+ if (configuredModel && shouldApplyModelConfig) {
31655
+ markerMessage = createModelSwitchMarker({
31656
+ conversationId,
31657
+ model: configuredModel.id,
31658
+ provider: configuredModel.provider,
31659
+ createdAt: updatedAt
31660
+ });
31661
+ snapshot.messages.push(markerMessage);
31662
+ await this.store.writeSnapshot(conversationId, snapshot);
31663
+ const markerEvent = await this.appendEvent(conversationId, {
31664
+ type: "message.created",
31665
+ message_id: markerMessage.id,
31666
+ payload: { message: markerMessage }
31667
+ });
31668
+ markerEventSeq = markerEvent.seq;
31669
+ }
31180
31670
  return {
31181
31671
  conversation_id: conversationId,
31182
31672
  default_model: runtime.model.id,
@@ -31187,7 +31677,9 @@ var ConversationService = class {
31187
31677
  } : {},
31188
31678
  scope: "conversation",
31189
31679
  runtime,
31190
- last_event_seq: event.seq
31680
+ last_event_seq: markerEventSeq ?? event.seq,
31681
+ ...markerMessage ? { marker_message: markerMessage } : {},
31682
+ ...markerEventSeq ? { marker_event_seq: markerEventSeq } : {}
31191
31683
  };
31192
31684
  });
31193
31685
  }
@@ -31348,18 +31840,33 @@ var ConversationService = class {
31348
31840
  };
31349
31841
  }
31350
31842
  async listEvents(conversationId, after = 0) {
31351
- return this.queries.listEvents(conversationId, after);
31843
+ return (await this.queries.listEvents(conversationId, after)).map(toAppVisibleConversationEvent).filter((event) => event !== null);
31352
31844
  }
31353
31845
  subscribe(conversationId, listener) {
31354
31846
  const eventName = this.liveEventName(conversationId);
31355
- this.emitter.on(eventName, listener);
31356
- return () => this.emitter.off(eventName, listener);
31847
+ const visibleListener = (event) => {
31848
+ const visibleEvent = toAppVisibleConversationEvent(event);
31849
+ if (visibleEvent) {
31850
+ listener(visibleEvent);
31851
+ }
31852
+ };
31853
+ this.emitter.on(eventName, visibleListener);
31854
+ return () => this.emitter.off(eventName, visibleListener);
31357
31855
  }
31358
31856
  subscribeAll(listener) {
31359
- this.emitter.on(ALL_CONVERSATION_EVENTS, listener);
31360
- return () => this.emitter.off(ALL_CONVERSATION_EVENTS, listener);
31857
+ const visibleListener = (event) => {
31858
+ const visibleEvent = toAppVisibleConversationEvent(event);
31859
+ if (visibleEvent) {
31860
+ listener(visibleEvent);
31861
+ }
31862
+ };
31863
+ this.emitter.on(ALL_CONVERSATION_EVENTS, visibleListener);
31864
+ return () => this.emitter.off(ALL_CONVERSATION_EVENTS, visibleListener);
31361
31865
  }
31362
31866
  async shouldPublishNotificationEvent(event) {
31867
+ if (!isAppVisibleConversationEvent(event)) {
31868
+ return false;
31869
+ }
31363
31870
  if (!isConversationNotificationEvent(event)) {
31364
31871
  return false;
31365
31872
  }
@@ -32179,7 +32686,7 @@ function selectCronNotificationMessage(snapshot, runAt) {
32179
32686
  })[0] ?? null;
32180
32687
  }
32181
32688
  function notificationPreviewText(message) {
32182
- const text = messageText(message).replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
32689
+ const text = messageText2(message).replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
32183
32690
  return text ? text.slice(0, 512) : null;
32184
32691
  }
32185
32692
  function buildLiveActivityEvent(input) {
@@ -32239,7 +32746,7 @@ function liveActivityTodoProgressForEvent(event) {
32239
32746
  if (todos) {
32240
32747
  const totalCount2 = todos.length;
32241
32748
  const doneCount2 = todos.filter((item) => {
32242
- const status = readString20(item, "status")?.toLowerCase();
32749
+ const status = readString21(item, "status")?.toLowerCase();
32243
32750
  return status === "completed" || status === "cancelled" || status === "canceled";
32244
32751
  }).length;
32245
32752
  return {
@@ -32288,11 +32795,11 @@ function liveActivityTitleFromConversationUpdate(event) {
32288
32795
  if (event.type.toLowerCase() !== "conversation.updated") {
32289
32796
  return void 0;
32290
32797
  }
32291
- const titleSource = readString20(event.payload, "title_source");
32798
+ const titleSource = readString21(event.payload, "title_source");
32292
32799
  if (titleSource === "default" || titleSource === "temporary_fallback") {
32293
32800
  return null;
32294
32801
  }
32295
- const title = readString20(event.payload, "title");
32802
+ const title = readString21(event.payload, "title");
32296
32803
  return title ? truncateLiveActivityTitle(title, 24) : null;
32297
32804
  }
32298
32805
  function liveActivityTitleFromManifest(manifest) {
@@ -32332,7 +32839,7 @@ function isConversationTitleUpdateEvent(event) {
32332
32839
  if (event.type.toLowerCase() !== "conversation.updated") {
32333
32840
  return false;
32334
32841
  }
32335
- return Boolean(readString20(event.payload, "title")?.trim());
32842
+ return Boolean(readString21(event.payload, "title")?.trim());
32336
32843
  }
32337
32844
  function resolveLiveActivityTarget(input) {
32338
32845
  if (input.run?.kind === "compression") {
@@ -32354,7 +32861,7 @@ function liveActivityPhaseForEvent(event, run, contextOperation) {
32354
32861
  }
32355
32862
  if (type === "conversation.goal.updated") {
32356
32863
  const goal = readRecord2(event.payload).goal;
32357
- const status = readString20(goal, "status");
32864
+ const status = readString21(goal, "status");
32358
32865
  return status === "paused" ? "goal_paused" : "goal_running";
32359
32866
  }
32360
32867
  if (isConversationTitleUpdateEvent(event)) {
@@ -32372,9 +32879,6 @@ function liveActivityPhaseForEvent(event, run, contextOperation) {
32372
32879
  if (type === "approval.requested") {
32373
32880
  return "needs_approval";
32374
32881
  }
32375
- if (type === "reasoning.available") {
32376
- return run?.mode === "goal" ? "goal_running" : "running";
32377
- }
32378
32882
  if (type === "context_compression.started") {
32379
32883
  return "context_compressing";
32380
32884
  }
@@ -32401,7 +32905,7 @@ function liveActivityPhaseForEvent(event, run, contextOperation) {
32401
32905
  function liveActivityTextForEvent(input) {
32402
32906
  const toolName = readToolName3(input.event.payload);
32403
32907
  const assistantText = input.event.message_id ? input.snapshot.messages.find((message) => message.id === input.event.message_id) : null;
32404
- const preview = input.event.type.toLowerCase() === "reasoning.available" ? liveActivityReasoningPreview(input.event.payload) : isLiveActivityTerminalEvent(input.phase, input.run?.kind === "compression" ? "context_compression" : "run") && assistantText ? notificationPreviewText(assistantText) : null;
32908
+ const preview = isLiveActivityTerminalEvent(input.phase, input.run?.kind === "compression" ? "context_compression" : "run") && assistantText ? notificationPreviewText(assistantText) : null;
32405
32909
  if (input.language === "en") {
32406
32910
  return liveActivityTextEn(input.phase, toolName, preview, input.contextOperation);
32407
32911
  }
@@ -32479,23 +32983,6 @@ function liveActivityTextEn(phase, toolName, preview, contextOperation) {
32479
32983
  return { statusLabel: "Running", progressText: "Working on your request", detailText: preview ?? void 0 };
32480
32984
  }
32481
32985
  }
32482
- function liveActivityReasoningPreview(payload) {
32483
- const text = readString20(payload, "text")?.replace(/<[^>]+>/gu, " ").replace(/\s+/gu, " ").trim();
32484
- return liveActivityCleanAssistantPreview(text);
32485
- }
32486
- function liveActivityCleanAssistantPreview(text) {
32487
- const normalized = text?.replace(/\s+/gu, " ").trim();
32488
- if (!normalized || normalized.length < 4) {
32489
- return null;
32490
- }
32491
- if (looksUnsafeForLockScreen(normalized)) {
32492
- return null;
32493
- }
32494
- return normalized.length > 90 ? `${normalized.slice(0, 90)}...` : normalized;
32495
- }
32496
- function looksUnsafeForLockScreen(text) {
32497
- return /(?:^|\s)(?:https?:\/\/|\/[A-Za-z0-9_.-]+\/|[A-Za-z]:\\|[A-Z_]{8,}=)/u.test(text) || /(?:```|<\?xml|BEGIN [A-Z ]+KEY|token|api[_ -]?key|password|secret)/iu.test(text);
32498
- }
32499
32986
  function isLiveActivityTerminalEvent(phase, targetKind) {
32500
32987
  if (phase === "completed" || phase === "failed" || phase === "cancelled") {
32501
32988
  return true;
@@ -32507,7 +32994,7 @@ function readContextCompressionOperation(payload) {
32507
32994
  if (!operation || typeof operation !== "object") {
32508
32995
  return null;
32509
32996
  }
32510
- const operationId = readString20(operation, "operation_id");
32997
+ const operationId = readString21(operation, "operation_id");
32511
32998
  if (!operationId) {
32512
32999
  return null;
32513
33000
  }
@@ -32515,19 +33002,19 @@ function readContextCompressionOperation(payload) {
32515
33002
  return {
32516
33003
  operation_id: operationId,
32517
33004
  generation: typeof record.generation === "number" ? record.generation : 0,
32518
- status: readString20(record, "status") === "completed" ? "completed" : readString20(record, "status") === "failed" ? "failed" : readString20(record, "status") === "timed_out" ? "timed_out" : readString20(record, "status") === "cancelled" ? "cancelled" : "compressing",
32519
- started_at: readString20(record, "started_at") ?? (/* @__PURE__ */ new Date()).toISOString(),
32520
- source: readString20(record, "source") === "manual" ? "manual" : "auto"
33005
+ status: readString21(record, "status") === "completed" ? "completed" : readString21(record, "status") === "failed" ? "failed" : readString21(record, "status") === "timed_out" ? "timed_out" : readString21(record, "status") === "cancelled" ? "cancelled" : "compressing",
33006
+ started_at: readString21(record, "started_at") ?? (/* @__PURE__ */ new Date()).toISOString(),
33007
+ source: readString21(record, "source") === "manual" ? "manual" : "auto"
32521
33008
  };
32522
33009
  }
32523
33010
  function readToolName3(payload) {
32524
33011
  const record = readRecord2(payload);
32525
- return readString20(record, "tool_name") ?? readString20(record, "tool") ?? readString20(record, "name") ?? readString20(readRecord2(record.tool), "name");
33012
+ return readString21(record, "tool_name") ?? readString21(record, "tool") ?? readString21(record, "name") ?? readString21(readRecord2(record.tool), "name");
32526
33013
  }
32527
33014
  function readRecord2(value) {
32528
33015
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
32529
33016
  }
32530
- function readString20(value, key) {
33017
+ function readString21(value, key) {
32531
33018
  const raw = readRecord2(value)[key];
32532
33019
  return typeof raw === "string" && raw.trim() ? raw.trim() : null;
32533
33020
  }
@@ -32544,7 +33031,7 @@ function approvalRestartText(language, zh, en) {
32544
33031
  }
32545
33032
 
32546
33033
  // src/security/devices.ts
32547
- import { randomBytes as randomBytes3, randomUUID as randomUUID13, timingSafeEqual, createHash as createHash10 } from "crypto";
33034
+ import { randomBytes as randomBytes3, randomUUID as randomUUID14, timingSafeEqual, createHash as createHash10 } from "crypto";
32548
33035
  var ACCESS_TOKEN_TTL_MS = 15 * 60 * 1e3;
32549
33036
  var REFRESH_TOKEN_TTL_MS = 90 * 24 * 60 * 60 * 1e3;
32550
33037
  var DEVICE_SEEN_WRITE_INTERVAL_MS = 60 * 60 * 1e3;
@@ -32562,7 +33049,7 @@ async function createDeviceSession(input, paths = resolveRuntimePaths()) {
32562
33049
  }
32563
33050
  }
32564
33051
  const device = {
32565
- id: `dev_${randomUUID13().replaceAll("-", "")}`,
33052
+ id: `dev_${randomUUID14().replaceAll("-", "")}`,
32566
33053
  label: normalizeDeviceLabel(input.label),
32567
33054
  platform: normalizeDevicePlatform(input.platform),
32568
33055
  model: normalizeDeviceModel(input.model),
@@ -33047,7 +33534,7 @@ async function readRawBody(request, maxBytes) {
33047
33534
  }
33048
33535
  return Buffer.concat(chunks);
33049
33536
  }
33050
- function readString21(body, key) {
33537
+ function readString22(body, key) {
33051
33538
  const value = body[key];
33052
33539
  return typeof value === "string" && value.trim() ? value.trim() : null;
33053
33540
  }
@@ -33082,7 +33569,7 @@ function readSupportedLanguage(value) {
33082
33569
  return null;
33083
33570
  }
33084
33571
  function readOptionalProfileName(body) {
33085
- return readString21(body, "profile") ?? readString21(body, "profile_name") ?? readString21(body, "profileName") ?? void 0;
33572
+ return readString22(body, "profile") ?? readString22(body, "profile_name") ?? readString22(body, "profileName") ?? void 0;
33086
33573
  }
33087
33574
  function readStringArray(body, ...keys) {
33088
33575
  for (const key of keys) {
@@ -33502,7 +33989,7 @@ function registerConversationRoutes(router, options) {
33502
33989
  const language = readPreferredLanguage(ctx);
33503
33990
  const body = await readJsonBody(ctx.req);
33504
33991
  ctx.status = 201;
33505
- const rawReasoningEffort = readString21(body, "reasoning_effort") ?? readString21(body, "reasoningEffort") ?? readString21(body, "default_reasoning_effort") ?? readString21(body, "defaultReasoningEffort");
33992
+ const rawReasoningEffort = readString22(body, "reasoning_effort") ?? readString22(body, "reasoningEffort") ?? readString22(body, "default_reasoning_effort") ?? readString22(body, "defaultReasoningEffort");
33506
33993
  const reasoningEffort = normalizeReasoningEffort(rawReasoningEffort);
33507
33994
  if (rawReasoningEffort && !reasoningEffort) {
33508
33995
  throw new LinkHttpError(
@@ -33515,15 +34002,15 @@ function registerConversationRoutes(router, options) {
33515
34002
  ok: true,
33516
34003
  conversation: localizeConversationSummary(
33517
34004
  await conversations.createConversation({
33518
- title: readString21(body, "title") ?? void 0,
34005
+ title: readString22(body, "title") ?? void 0,
33519
34006
  profileName: readOptionalProfileName(body),
33520
34007
  accountId: auth.accountId,
33521
34008
  appInstanceId: auth.appInstanceId,
33522
34009
  workspaceId: readConversationWorkspaceId(body),
33523
- modelId: readString21(body, "model_id") ?? readString21(body, "modelId") ?? readString21(body, "model") ?? void 0,
33524
- modelProvider: readString21(body, "model_provider") ?? readString21(body, "modelProvider") ?? readString21(body, "provider") ?? void 0,
33525
- modelBaseUrl: readString21(body, "model_base_url") ?? readString21(body, "modelBaseUrl") ?? readString21(body, "base_url") ?? readString21(body, "baseUrl") ?? void 0,
33526
- modelApiMode: readString21(body, "model_api_mode") ?? readString21(body, "modelApiMode") ?? readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? void 0,
34010
+ modelId: readString22(body, "model_id") ?? readString22(body, "modelId") ?? readString22(body, "model") ?? void 0,
34011
+ modelProvider: readString22(body, "model_provider") ?? readString22(body, "modelProvider") ?? readString22(body, "provider") ?? void 0,
34012
+ modelBaseUrl: readString22(body, "model_base_url") ?? readString22(body, "modelBaseUrl") ?? readString22(body, "base_url") ?? readString22(body, "baseUrl") ?? void 0,
34013
+ modelApiMode: readString22(body, "model_api_mode") ?? readString22(body, "modelApiMode") ?? readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? void 0,
33527
34014
  reasoningEffort
33528
34015
  }),
33529
34016
  language
@@ -33601,9 +34088,9 @@ function registerConversationRoutes(router, options) {
33601
34088
  const auth = await authenticateRequest(ctx, paths);
33602
34089
  const language = readPreferredLanguage(ctx);
33603
34090
  const body = await readJsonBody(ctx.req);
33604
- const content = readString21(body, "content") ?? readString21(body, "text") ?? readString21(body, "input") ?? "";
34091
+ const content = readString22(body, "content") ?? readString22(body, "text") ?? readString22(body, "input") ?? "";
33605
34092
  const attachments = readMessageAttachments(body.attachments ?? body.blobs);
33606
- const mode = readString21(body, "mode") ?? readString21(body, "send_mode");
34093
+ const mode = readString22(body, "mode") ?? readString22(body, "send_mode");
33607
34094
  if (mode && mode !== "message" && mode !== "goal") {
33608
34095
  throw new LinkHttpError(
33609
34096
  400,
@@ -33626,7 +34113,7 @@ function registerConversationRoutes(router, options) {
33626
34113
  conversationId: ctx.params.conversationId,
33627
34114
  content,
33628
34115
  attachments,
33629
- clientMessageId: readString21(body, "client_message_id") ?? readString21(body, "clientMessageId") ?? void 0,
34116
+ clientMessageId: readString22(body, "client_message_id") ?? readString22(body, "clientMessageId") ?? void 0,
33630
34117
  idempotencyKey: readHeader(ctx, "idempotency-key") ?? void 0,
33631
34118
  profileName: readOptionalProfileName(body),
33632
34119
  mode: mode === "goal" ? "goal" : "message",
@@ -33693,8 +34180,8 @@ function registerConversationRoutes(router, options) {
33693
34180
  ...localizeConversationResult(
33694
34181
  await conversations.startContextCompression({
33695
34182
  conversationId: ctx.params.conversationId,
33696
- focus: readString21(body, "focus") ?? readString21(body, "focus_topic") ?? readString21(body, "focusTopic") ?? void 0,
33697
- clientOperationId: readString21(body, "client_operation_id") ?? readString21(body, "clientOperationId") ?? readHeader(ctx, "idempotency-key") ?? void 0,
34183
+ focus: readString22(body, "focus") ?? readString22(body, "focus_topic") ?? readString22(body, "focusTopic") ?? void 0,
34184
+ clientOperationId: readString22(body, "client_operation_id") ?? readString22(body, "clientOperationId") ?? readHeader(ctx, "idempotency-key") ?? void 0,
33698
34185
  createUserMessage: false,
33699
34186
  accountId: auth.accountId,
33700
34187
  appInstanceId: auth.appInstanceId,
@@ -33708,11 +34195,11 @@ function registerConversationRoutes(router, options) {
33708
34195
  router.patch("/api/v1/conversations/:conversationId/model", async (ctx) => {
33709
34196
  await authenticateRequest(ctx, paths);
33710
34197
  const body = await readJsonBody(ctx.req);
33711
- const modelId = readString21(body, "model_id") ?? readString21(body, "modelId") ?? readString21(body, "model");
33712
- const modelProvider = readString21(body, "model_provider") ?? readString21(body, "modelProvider") ?? readString21(body, "provider") ?? void 0;
33713
- const modelBaseUrl = readString21(body, "model_base_url") ?? readString21(body, "modelBaseUrl") ?? readString21(body, "base_url") ?? readString21(body, "baseUrl") ?? void 0;
33714
- const modelApiMode = readString21(body, "model_api_mode") ?? readString21(body, "modelApiMode") ?? readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? void 0;
33715
- const rawReasoningEffort = readString21(body, "reasoning_effort") ?? readString21(body, "reasoningEffort") ?? readString21(body, "default_reasoning_effort") ?? readString21(body, "defaultReasoningEffort");
34198
+ const modelId = readString22(body, "model_id") ?? readString22(body, "modelId") ?? readString22(body, "model");
34199
+ const modelProvider = readString22(body, "model_provider") ?? readString22(body, "modelProvider") ?? readString22(body, "provider") ?? void 0;
34200
+ const modelBaseUrl = readString22(body, "model_base_url") ?? readString22(body, "modelBaseUrl") ?? readString22(body, "base_url") ?? readString22(body, "baseUrl") ?? void 0;
34201
+ const modelApiMode = readString22(body, "model_api_mode") ?? readString22(body, "modelApiMode") ?? readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? void 0;
34202
+ const rawReasoningEffort = readString22(body, "reasoning_effort") ?? readString22(body, "reasoningEffort") ?? readString22(body, "default_reasoning_effort") ?? readString22(body, "defaultReasoningEffort");
33716
34203
  const reasoningEffort = normalizeReasoningEffort(rawReasoningEffort);
33717
34204
  if (rawReasoningEffort && !reasoningEffort) {
33718
34205
  throw new LinkHttpError(
@@ -33762,7 +34249,7 @@ function registerConversationRoutes(router, options) {
33762
34249
  await authenticateRequest(ctx, paths);
33763
34250
  const language = readPreferredLanguage(ctx);
33764
34251
  const body = await readJsonBody(ctx.req);
33765
- const title = readString21(body, "title") ?? readString21(body, "name") ?? readString21(body, "display_name");
34252
+ const title = readString22(body, "title") ?? readString22(body, "name") ?? readString22(body, "display_name");
33766
34253
  if (!title) {
33767
34254
  throw new LinkHttpError(400, "title_required", "title is required");
33768
34255
  }
@@ -33954,7 +34441,7 @@ function registerConversationRoutes(router, options) {
33954
34441
  async (ctx) => {
33955
34442
  await authenticateRequest(ctx, paths);
33956
34443
  const body = await readJsonBody(ctx.req);
33957
- const scope = readString21(body, "scope") ?? "always";
34444
+ const scope = readString22(body, "scope") ?? "always";
33958
34445
  ctx.body = {
33959
34446
  ok: true,
33960
34447
  ...await conversations.resolveApproval({
@@ -34004,7 +34491,7 @@ function registerConversationRoutes(router, options) {
34004
34491
  conversationId: ctx.params.conversationId,
34005
34492
  requestId: ctx.params.requestId,
34006
34493
  kind,
34007
- answer: readString21(body, "answer") ?? void 0,
34494
+ answer: readString22(body, "answer") ?? void 0,
34008
34495
  password: readRawString(body, "password"),
34009
34496
  value: readRawString(body, "value")
34010
34497
  })
@@ -34173,10 +34660,10 @@ function readConversationWorkspaceFilter(query) {
34173
34660
  }
34174
34661
  function readConversationWorkspaceId(body) {
34175
34662
  if (Object.prototype.hasOwnProperty.call(body, "workspace_id") || Object.prototype.hasOwnProperty.call(body, "workspaceId")) {
34176
- return readString21(body, "workspace_id") ?? readString21(body, "workspaceId");
34663
+ return readString22(body, "workspace_id") ?? readString22(body, "workspaceId");
34177
34664
  }
34178
34665
  if (Object.prototype.hasOwnProperty.call(body, "workspace")) {
34179
- return readString21(body, "workspace");
34666
+ return readString22(body, "workspace");
34180
34667
  }
34181
34668
  return void 0;
34182
34669
  }
@@ -34270,7 +34757,7 @@ function resolveConversationEventCursor(input) {
34270
34757
  return Math.max(queryAfter, headerAfter);
34271
34758
  }
34272
34759
  function readConversationClearPlanTargetStatus(body) {
34273
- const raw = readString21(body, "target_status") ?? readString21(body, "targetStatus") ?? "active";
34760
+ const raw = readString22(body, "target_status") ?? readString22(body, "targetStatus") ?? "active";
34274
34761
  if (raw === "active" || raw === "archived") {
34275
34762
  return raw;
34276
34763
  }
@@ -34281,7 +34768,7 @@ function readConversationClearPlanTargetStatus(body) {
34281
34768
  );
34282
34769
  }
34283
34770
  function readInputRequestKind2(body) {
34284
- const kind = readString21(body, "kind") ?? readString21(body, "type");
34771
+ const kind = readString22(body, "kind") ?? readString22(body, "type");
34285
34772
  if (kind === "clarify" || kind === "sudo" || kind === "secret") {
34286
34773
  return kind;
34287
34774
  }
@@ -34679,7 +35166,7 @@ function toHermesCronJobInput(input) {
34679
35166
  };
34680
35167
  }
34681
35168
  async function bindAndDecorateCronJobForHermesLink(input) {
34682
- const jobId = readString21(input.job, "id") ?? readString21(input.job, "job_id");
35169
+ const jobId = readString22(input.job, "id") ?? readString22(input.job, "job_id");
34683
35170
  if (!jobId) {
34684
35171
  return input.job;
34685
35172
  }
@@ -34698,9 +35185,9 @@ async function bindAndDecorateCronJobForHermesLink(input) {
34698
35185
  }
34699
35186
  function readCronJobCreateInput(body) {
34700
35187
  const input = {};
34701
- const name = readString21(body, "name") ?? readString21(body, "title");
34702
- const prompt = readString21(body, "prompt") ?? readString21(body, "description") ?? readString21(body, "task");
34703
- const schedule = readString21(body, "schedule");
35188
+ const name = readString22(body, "name") ?? readString22(body, "title");
35189
+ const prompt = readString22(body, "prompt") ?? readString22(body, "description") ?? readString22(body, "task");
35190
+ const schedule = readString22(body, "schedule");
34704
35191
  if (!name) {
34705
35192
  throw new LinkHttpError(400, "cron_job_name_required", "name is required");
34706
35193
  }
@@ -34721,7 +35208,7 @@ function readCronJobCreateInput(body) {
34721
35208
  input.name = name;
34722
35209
  input.prompt = prompt;
34723
35210
  input.schedule = schedule;
34724
- input.deliver = readString21(body, "deliver") ?? HERMES_LINK_CRON_DELIVER;
35211
+ input.deliver = readString22(body, "deliver") ?? HERMES_LINK_CRON_DELIVER;
34725
35212
  const skills = readOptionalCronSkills(body);
34726
35213
  if (skills) {
34727
35214
  input.skills = skills;
@@ -35085,7 +35572,7 @@ function normalizeModelCapabilityCatalog(value) {
35085
35572
  const models = rawModels.map(normalizeModelCapabilityEntry).filter((entry) => entry !== null);
35086
35573
  return {
35087
35574
  schemaVersion: readPositiveInteger3(record.schemaVersion) ?? 1,
35088
- updatedAt: readString22(record.updatedAt),
35575
+ updatedAt: readString23(record.updatedAt),
35089
35576
  models
35090
35577
  };
35091
35578
  }
@@ -35094,7 +35581,7 @@ function normalizeModelCapabilityEntry(value) {
35094
35581
  return null;
35095
35582
  }
35096
35583
  const record = value;
35097
- const canonicalId = readString22(record.canonicalId) ?? readString22(record.canonical_id) ?? readString22(record.id);
35584
+ const canonicalId = readString23(record.canonicalId) ?? readString23(record.canonical_id) ?? readString23(record.id);
35098
35585
  if (!canonicalId) {
35099
35586
  return null;
35100
35587
  }
@@ -35122,12 +35609,12 @@ function normalizeModelCapabilityEntry(value) {
35122
35609
  outputModalities: readStringArray2(
35123
35610
  record.outputModalities ?? record.output_modalities
35124
35611
  ),
35125
- source: readString22(record.source),
35126
- updatedAt: readString22(record.updatedAt ?? record.updated_at),
35127
- notes: readString22(record.notes)
35612
+ source: readString23(record.source),
35613
+ updatedAt: readString23(record.updatedAt ?? record.updated_at),
35614
+ notes: readString23(record.notes)
35128
35615
  };
35129
35616
  }
35130
- function readString22(value) {
35617
+ function readString23(value) {
35131
35618
  return typeof value === "string" && value.trim() ? value.trim() : null;
35132
35619
  }
35133
35620
  function readStringArray2(value) {
@@ -35137,7 +35624,7 @@ function readStringArray2(value) {
35137
35624
  const seen = /* @__PURE__ */ new Set();
35138
35625
  const values = [];
35139
35626
  for (const item of value) {
35140
- const text = readString22(item);
35627
+ const text = readString23(item);
35141
35628
  if (!text || seen.has(text)) {
35142
35629
  continue;
35143
35630
  }
@@ -35154,7 +35641,7 @@ function readPositiveInteger3(value) {
35154
35641
  return Math.floor(number);
35155
35642
  }
35156
35643
  function readReasoningSupportPolicy(value) {
35157
- const normalized = readString22(value)?.toLowerCase();
35644
+ const normalized = readString23(value)?.toLowerCase();
35158
35645
  if (!normalized || normalized === "unknown" || normalized === "auto") {
35159
35646
  return null;
35160
35647
  }
@@ -35185,7 +35672,7 @@ function readNullableBoolean(value) {
35185
35672
  if (typeof value === "boolean") {
35186
35673
  return value;
35187
35674
  }
35188
- const normalized = readString22(value)?.toLowerCase();
35675
+ const normalized = readString23(value)?.toLowerCase();
35189
35676
  if (!normalized) {
35190
35677
  return null;
35191
35678
  }
@@ -36334,8 +36821,8 @@ function normalizeUrlForIdentity(value) {
36334
36821
  return value.trim().replace(/\/+$/u, "").toLowerCase();
36335
36822
  }
36336
36823
  function readModelProviderConfigInput(body) {
36337
- const providerName = readString21(body, "display_name") ?? readString21(body, "displayName") ?? readString21(body, "provider_name") ?? readString21(body, "providerName") ?? readString21(body, "name");
36338
- const baseUrl = readString21(body, "base_url") ?? readString21(body, "baseUrl");
36824
+ const providerName = readString22(body, "display_name") ?? readString22(body, "displayName") ?? readString22(body, "provider_name") ?? readString22(body, "providerName") ?? readString22(body, "name");
36825
+ const baseUrl = readString22(body, "base_url") ?? readString22(body, "baseUrl");
36339
36826
  if (!providerName || !baseUrl) {
36340
36827
  throw new LinkHttpError(
36341
36828
  400,
@@ -36346,15 +36833,15 @@ function readModelProviderConfigInput(body) {
36346
36833
  return {
36347
36834
  providerName,
36348
36835
  baseUrl,
36349
- apiMode: readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? readString21(body, "transport") ?? void 0,
36350
- keyEnv: readString21(body, "key_env") ?? readString21(body, "keyEnv") ?? void 0,
36351
- apiKey: readString21(body, "api_key") ?? readString21(body, "apiKey") ?? void 0
36836
+ apiMode: readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? readString22(body, "transport") ?? void 0,
36837
+ keyEnv: readString22(body, "key_env") ?? readString22(body, "keyEnv") ?? void 0,
36838
+ apiKey: readString22(body, "api_key") ?? readString22(body, "apiKey") ?? void 0
36352
36839
  };
36353
36840
  }
36354
36841
  function readModelConfigInput(body) {
36355
- const id = readString21(body, "id") ?? readString21(body, "model_id") ?? readString21(body, "modelId");
36356
- const provider = readString21(body, "provider") ?? readString21(body, "provider_key") ?? readString21(body, "providerKey");
36357
- const baseUrl = readString21(body, "base_url") ?? readString21(body, "baseUrl");
36842
+ const id = readString22(body, "id") ?? readString22(body, "model_id") ?? readString22(body, "modelId");
36843
+ const provider = readString22(body, "provider") ?? readString22(body, "provider_key") ?? readString22(body, "providerKey");
36844
+ const baseUrl = readString22(body, "base_url") ?? readString22(body, "baseUrl");
36358
36845
  if (!id || !provider || !baseUrl) {
36359
36846
  throw new LinkHttpError(
36360
36847
  400,
@@ -36364,22 +36851,22 @@ function readModelConfigInput(body) {
36364
36851
  }
36365
36852
  return {
36366
36853
  id,
36367
- originalModelId: readString21(body, "original_model_id") ?? readString21(body, "originalModelId") ?? readString21(body, "original_id") ?? void 0,
36368
- originalProvider: readString21(body, "original_provider") ?? readString21(body, "originalProvider") ?? readString21(body, "original_provider_key") ?? readString21(body, "originalProviderKey") ?? void 0,
36369
- originalBaseUrl: readString21(body, "original_base_url") ?? readString21(body, "originalBaseUrl") ?? void 0,
36370
- originalApiMode: readString21(body, "original_api_mode") ?? readString21(body, "originalApiMode") ?? void 0,
36854
+ originalModelId: readString22(body, "original_model_id") ?? readString22(body, "originalModelId") ?? readString22(body, "original_id") ?? void 0,
36855
+ originalProvider: readString22(body, "original_provider") ?? readString22(body, "originalProvider") ?? readString22(body, "original_provider_key") ?? readString22(body, "originalProviderKey") ?? void 0,
36856
+ originalBaseUrl: readString22(body, "original_base_url") ?? readString22(body, "originalBaseUrl") ?? void 0,
36857
+ originalApiMode: readString22(body, "original_api_mode") ?? readString22(body, "originalApiMode") ?? void 0,
36371
36858
  provider,
36372
- providerName: readString21(body, "provider_name") ?? readString21(body, "providerName") ?? void 0,
36859
+ providerName: readString22(body, "provider_name") ?? readString22(body, "providerName") ?? void 0,
36373
36860
  baseUrl,
36374
- apiKey: readString21(body, "api_key") ?? readString21(body, "apiKey") ?? void 0,
36375
- apiMode: readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? void 0,
36861
+ apiKey: readString22(body, "api_key") ?? readString22(body, "apiKey") ?? void 0,
36862
+ apiMode: readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? void 0,
36376
36863
  contextLength: readPositiveInteger2(
36377
36864
  body.context_length ?? body.contextLength
36378
36865
  ),
36379
- keyEnv: readString21(body, "key_env") ?? readString21(body, "keyEnv") ?? void 0,
36866
+ keyEnv: readString22(body, "key_env") ?? readString22(body, "keyEnv") ?? void 0,
36380
36867
  setDefault: readBoolean4(body.set_default ?? body.setDefault),
36381
- reasoningEffort: readString21(body, "reasoning_effort") ?? readString21(body, "reasoningEffort") ?? void 0,
36382
- reasoningSupportPolicy: readString21(body, "reasoning_support_policy") ?? readString21(body, "reasoningSupportPolicy") ?? readString21(body, "reasoning_support") ?? readString21(body, "reasoningSupport") ?? void 0,
36868
+ reasoningEffort: readString22(body, "reasoning_effort") ?? readString22(body, "reasoningEffort") ?? void 0,
36869
+ reasoningSupportPolicy: readString22(body, "reasoning_support_policy") ?? readString22(body, "reasoningSupportPolicy") ?? readString22(body, "reasoning_support") ?? readString22(body, "reasoningSupport") ?? void 0,
36383
36870
  supportsVision: readNullableBoolean2(
36384
36871
  body.supports_vision ?? body.supportsVision
36385
36872
  )
@@ -36387,28 +36874,28 @@ function readModelConfigInput(body) {
36387
36874
  }
36388
36875
  function readModelDefaultsInput(body) {
36389
36876
  return {
36390
- taskModelId: readString21(body, "task_model_id") ?? readString21(body, "taskModelId") ?? readString21(body, "default_model_id") ?? readString21(body, "defaultModelId") ?? void 0,
36391
- taskModelProvider: readString21(body, "task_model_provider") ?? readString21(body, "taskModelProvider") ?? readString21(body, "default_model_provider") ?? readString21(body, "defaultModelProvider") ?? void 0,
36392
- taskModelBaseUrl: readString21(body, "task_model_base_url") ?? readString21(body, "taskModelBaseUrl") ?? readString21(body, "default_model_base_url") ?? readString21(body, "defaultModelBaseUrl") ?? void 0,
36393
- taskModelApiMode: readString21(body, "task_model_api_mode") ?? readString21(body, "taskModelApiMode") ?? readString21(body, "default_model_api_mode") ?? readString21(body, "defaultModelApiMode") ?? void 0,
36394
- compressionModelId: readString21(body, "compression_model_id") ?? readString21(body, "compressionModelId") ?? void 0,
36395
- compressionModelProvider: readString21(body, "compression_model_provider") ?? readString21(body, "compressionModelProvider") ?? void 0,
36396
- compressionModelBaseUrl: readString21(body, "compression_model_base_url") ?? readString21(body, "compressionModelBaseUrl") ?? void 0,
36397
- compressionModelApiMode: readString21(body, "compression_model_api_mode") ?? readString21(body, "compressionModelApiMode") ?? void 0,
36398
- reasoningEffort: readString21(body, "reasoning_effort") ?? readString21(body, "reasoningEffort") ?? readString21(body, "default_reasoning_effort") ?? readString21(body, "defaultReasoningEffort") ?? void 0,
36399
- imageInputMode: readString21(body, "image_input_mode") ?? readString21(body, "imageInputMode") ?? void 0
36877
+ taskModelId: readString22(body, "task_model_id") ?? readString22(body, "taskModelId") ?? readString22(body, "default_model_id") ?? readString22(body, "defaultModelId") ?? void 0,
36878
+ taskModelProvider: readString22(body, "task_model_provider") ?? readString22(body, "taskModelProvider") ?? readString22(body, "default_model_provider") ?? readString22(body, "defaultModelProvider") ?? void 0,
36879
+ taskModelBaseUrl: readString22(body, "task_model_base_url") ?? readString22(body, "taskModelBaseUrl") ?? readString22(body, "default_model_base_url") ?? readString22(body, "defaultModelBaseUrl") ?? void 0,
36880
+ taskModelApiMode: readString22(body, "task_model_api_mode") ?? readString22(body, "taskModelApiMode") ?? readString22(body, "default_model_api_mode") ?? readString22(body, "defaultModelApiMode") ?? void 0,
36881
+ compressionModelId: readString22(body, "compression_model_id") ?? readString22(body, "compressionModelId") ?? void 0,
36882
+ compressionModelProvider: readString22(body, "compression_model_provider") ?? readString22(body, "compressionModelProvider") ?? void 0,
36883
+ compressionModelBaseUrl: readString22(body, "compression_model_base_url") ?? readString22(body, "compressionModelBaseUrl") ?? void 0,
36884
+ compressionModelApiMode: readString22(body, "compression_model_api_mode") ?? readString22(body, "compressionModelApiMode") ?? void 0,
36885
+ reasoningEffort: readString22(body, "reasoning_effort") ?? readString22(body, "reasoningEffort") ?? readString22(body, "default_reasoning_effort") ?? readString22(body, "defaultReasoningEffort") ?? void 0,
36886
+ imageInputMode: readString22(body, "image_input_mode") ?? readString22(body, "imageInputMode") ?? void 0
36400
36887
  };
36401
36888
  }
36402
36889
  function readModelDeleteInput(body) {
36403
- const id = readString21(body, "model_id") ?? readString21(body, "modelId");
36890
+ const id = readString22(body, "model_id") ?? readString22(body, "modelId");
36404
36891
  if (!id) {
36405
36892
  throw new LinkHttpError(400, "model_id_required", "model_id is required");
36406
36893
  }
36407
36894
  return {
36408
36895
  id,
36409
- provider: readString21(body, "provider") ?? readString21(body, "provider_key") ?? readString21(body, "providerKey") ?? void 0,
36410
- baseUrl: readString21(body, "base_url") ?? readString21(body, "baseUrl") ?? void 0,
36411
- apiMode: readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? void 0
36896
+ provider: readString22(body, "provider") ?? readString22(body, "provider_key") ?? readString22(body, "providerKey") ?? void 0,
36897
+ baseUrl: readString22(body, "base_url") ?? readString22(body, "baseUrl") ?? void 0,
36898
+ apiMode: readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? void 0
36412
36899
  };
36413
36900
  }
36414
36901
  function readNullableBoolean2(value) {
@@ -36431,8 +36918,8 @@ function readNullableBoolean2(value) {
36431
36918
  return void 0;
36432
36919
  }
36433
36920
  function readModelConfigImportInput(body) {
36434
- const sourceProfileName = readString21(body, "source_profile") ?? readString21(body, "sourceProfile") ?? readString21(body, "source_profile_name") ?? readString21(body, "sourceProfileName");
36435
- const modelId = readString21(body, "model_id") ?? readString21(body, "modelId") ?? readString21(body, "id");
36921
+ const sourceProfileName = readString22(body, "source_profile") ?? readString22(body, "sourceProfile") ?? readString22(body, "source_profile_name") ?? readString22(body, "sourceProfileName");
36922
+ const modelId = readString22(body, "model_id") ?? readString22(body, "modelId") ?? readString22(body, "id");
36436
36923
  if (!sourceProfileName || !modelId) {
36437
36924
  throw new LinkHttpError(
36438
36925
  400,
@@ -36443,9 +36930,9 @@ function readModelConfigImportInput(body) {
36443
36930
  return {
36444
36931
  sourceProfileName,
36445
36932
  modelId,
36446
- provider: readString21(body, "provider") ?? readString21(body, "provider_key") ?? readString21(body, "providerKey") ?? void 0,
36447
- baseUrl: readString21(body, "base_url") ?? readString21(body, "baseUrl") ?? void 0,
36448
- apiMode: readString21(body, "api_mode") ?? readString21(body, "apiMode") ?? void 0,
36933
+ provider: readString22(body, "provider") ?? readString22(body, "provider_key") ?? readString22(body, "providerKey") ?? void 0,
36934
+ baseUrl: readString22(body, "base_url") ?? readString22(body, "baseUrl") ?? void 0,
36935
+ apiMode: readString22(body, "api_mode") ?? readString22(body, "apiMode") ?? void 0,
36449
36936
  setDefault: readBoolean4(body.set_default ?? body.setDefault)
36450
36937
  };
36451
36938
  }
@@ -36883,7 +37370,7 @@ async function readHermesConfigDocument3(configPath) {
36883
37370
  const document = existingRaw ? YAML4.parseDocument(existingRaw) : new YAML4.Document({});
36884
37371
  return {
36885
37372
  document,
36886
- config: toRecord19(document.toJSON()),
37373
+ config: toRecord20(document.toJSON()),
36887
37374
  existingRaw
36888
37375
  };
36889
37376
  }
@@ -36955,7 +37442,7 @@ function ensureRecord3(target, key) {
36955
37442
  target[key] = next;
36956
37443
  return next;
36957
37444
  }
36958
- function toRecord19(value) {
37445
+ function toRecord20(value) {
36959
37446
  return isRecord4(value) ? value : {};
36960
37447
  }
36961
37448
  function isRecord4(value) {
@@ -37419,7 +37906,7 @@ function copyModelConfig(source, target) {
37419
37906
  copied[key] = cloneJson(source[key]);
37420
37907
  }
37421
37908
  }
37422
- const sourceAuxiliary = toRecord20(source.auxiliary);
37909
+ const sourceAuxiliary = toRecord21(source.auxiliary);
37423
37910
  if (Object.prototype.hasOwnProperty.call(sourceAuxiliary, "compression")) {
37424
37911
  const targetAuxiliary = ensureRecord4(target, "auxiliary");
37425
37912
  targetAuxiliary.compression = cloneJson(sourceAuxiliary.compression);
@@ -37428,12 +37915,12 @@ function copyModelConfig(source, target) {
37428
37915
  return copied;
37429
37916
  }
37430
37917
  function copyToolPermissionsConfig(source, target) {
37431
- const sourcePlatformToolsets = toRecord20(source.platform_toolsets);
37918
+ const sourcePlatformToolsets = toRecord21(source.platform_toolsets);
37432
37919
  if (Object.prototype.hasOwnProperty.call(sourcePlatformToolsets, "api_server")) {
37433
37920
  const targetPlatformToolsets = ensureRecord4(target, "platform_toolsets");
37434
37921
  targetPlatformToolsets.api_server = cloneJson(sourcePlatformToolsets.api_server);
37435
37922
  }
37436
- const sourceStt = toRecord20(source.stt);
37923
+ const sourceStt = toRecord21(source.stt);
37437
37924
  if (Object.prototype.hasOwnProperty.call(sourceStt, "enabled")) {
37438
37925
  const targetStt = ensureRecord4(target, "stt");
37439
37926
  targetStt.enabled = cloneJson(sourceStt.enabled);
@@ -37550,7 +38037,7 @@ async function readYamlConfig(configPath) {
37550
38037
  }
37551
38038
  );
37552
38039
  return {
37553
- config: toRecord20(existingRaw ? YAML5.parse(existingRaw) : {}),
38040
+ config: toRecord21(existingRaw ? YAML5.parse(existingRaw) : {}),
37554
38041
  existingRaw
37555
38042
  };
37556
38043
  }
@@ -37662,7 +38149,7 @@ function ensureRecord4(target, key) {
37662
38149
  target[key] = next;
37663
38150
  return next;
37664
38151
  }
37665
- function toRecord20(value) {
38152
+ function toRecord21(value) {
37666
38153
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
37667
38154
  }
37668
38155
  function cloneJson(value) {
@@ -37762,16 +38249,16 @@ function readProfilePermissionsInput(body) {
37762
38249
  const approvals = readOptionalObject(body, "approvals");
37763
38250
  if (approvals) {
37764
38251
  input.approvals = {
37765
- mode: readString21(approvals, "mode") ?? readString21(approvals, "approval_mode") ?? readString21(approvals, "approvalMode") ?? void 0,
38252
+ mode: readString22(approvals, "mode") ?? readString22(approvals, "approval_mode") ?? readString22(approvals, "approvalMode") ?? void 0,
37766
38253
  timeout: readPositiveInteger2(approvals.timeout),
37767
- cronMode: readString21(approvals, "cron_mode") ?? readString21(approvals, "cronMode") ?? void 0
38254
+ cronMode: readString22(approvals, "cron_mode") ?? readString22(approvals, "cronMode") ?? void 0
37768
38255
  };
37769
38256
  }
37770
38257
  const terminal = readOptionalObject(body, "terminal");
37771
38258
  if (terminal) {
37772
38259
  input.terminal = {
37773
- backend: readString21(terminal, "backend") ?? void 0,
37774
- cwd: readString21(terminal, "cwd") ?? void 0,
38260
+ backend: readString22(terminal, "backend") ?? void 0,
38261
+ cwd: readString22(terminal, "cwd") ?? void 0,
37775
38262
  containerCpu: readPositiveInteger2(
37776
38263
  terminal.container_cpu ?? terminal.containerCpu
37777
38264
  ),
@@ -38102,9 +38589,9 @@ async function testHindsightProviderSettings(profileName, patch) {
38102
38589
  const mode = normalizeHindsightMode(
38103
38590
  patch.mode ?? config.mode ?? env.HINDSIGHT_MODE
38104
38591
  );
38105
- const apiUrl = readString23(patch.apiUrl) ?? readString23(config.api_url) ?? env.HINDSIGHT_API_URL ?? (mode === "cloud" ? HINDSIGHT_DEFAULT_API_URL : HINDSIGHT_DEFAULT_LOCAL_URL);
38106
- const bankId = readString23(patch.bankId) ?? readString23(config.bank_id) ?? "hermes";
38107
- const apiKey = readString23(patch.apiKey) ?? env.HINDSIGHT_API_KEY ?? readString23(config.apiKey) ?? readString23(config.api_key);
38592
+ const apiUrl = readString24(patch.apiUrl) ?? readString24(config.api_url) ?? env.HINDSIGHT_API_URL ?? (mode === "cloud" ? HINDSIGHT_DEFAULT_API_URL : HINDSIGHT_DEFAULT_LOCAL_URL);
38593
+ const bankId = readString24(patch.bankId) ?? readString24(config.bank_id) ?? "hermes";
38594
+ const apiKey = readString24(patch.apiKey) ?? env.HINDSIGHT_API_KEY ?? readString24(config.apiKey) ?? readString24(config.api_key);
38108
38595
  const baseUrl = normalizeHttpUrl2(apiUrl);
38109
38596
  if (!baseUrl) {
38110
38597
  return {
@@ -38293,7 +38780,7 @@ async function patchCustomProviderConfig(profileName, provider, patch) {
38293
38780
  "\u81EA\u5B9A\u4E49 memory provider \u914D\u7F6E\u5FC5\u987B\u662F\u6709\u6548\u7684 JSON object\u3002"
38294
38781
  );
38295
38782
  }
38296
- const config = toRecord21(parsed);
38783
+ const config = toRecord22(parsed);
38297
38784
  if (Object.keys(config).length === 0 && parsed !== null) {
38298
38785
  throw new HermesMemoryError(
38299
38786
  "memory_provider_config_invalid",
@@ -38393,8 +38880,8 @@ async function patchHermesMemoryProvider(profileName, provider) {
38393
38880
  }
38394
38881
  );
38395
38882
  const document = existingRaw ? YAML6.parseDocument(existingRaw) : new YAML6.Document({});
38396
- const config = toRecord21(document.toJSON());
38397
- const memory = toRecord21(config.memory);
38883
+ const config = toRecord22(document.toJSON());
38884
+ const memory = toRecord22(config.memory);
38398
38885
  memory.provider = provider === "built-in" ? "" : provider;
38399
38886
  config.memory = memory;
38400
38887
  const backupPath = existingRaw ? `${configPath}.bak.${Date.now()}` : null;
@@ -38417,8 +38904,8 @@ async function patchHermesMemoryLimits(profileName, patch) {
38417
38904
  }
38418
38905
  );
38419
38906
  const document = existingRaw ? YAML6.parseDocument(existingRaw) : new YAML6.Document({});
38420
- const config = toRecord21(document.toJSON());
38421
- const memory = toRecord21(config.memory);
38907
+ const config = toRecord22(document.toJSON());
38908
+ const memory = toRecord22(config.memory);
38422
38909
  if (patch.memoryCharLimit !== void 0) {
38423
38910
  memory.memory_char_limit = patch.memoryCharLimit;
38424
38911
  }
@@ -38638,7 +39125,7 @@ async function readProviderConfigurationStatus(profileName, provider) {
38638
39125
  const config2 = await readJsonObject(
38639
39126
  memoryProviderConfigPath(profileName, "honcho") ?? ""
38640
39127
  );
38641
- return isConfiguredEnvValue(env.HONCHO_API_KEY) || isConfiguredEnvValue(readString23(config2.apiKey)) || isConfiguredEnvValue(readString23(config2.api_key)) || isConfiguredEnvValue(readString23(config2.baseUrl)) ? { configured: true, issue: null } : {
39128
+ return isConfiguredEnvValue(env.HONCHO_API_KEY) || isConfiguredEnvValue(readString24(config2.apiKey)) || isConfiguredEnvValue(readString24(config2.api_key)) || isConfiguredEnvValue(readString24(config2.baseUrl)) ? { configured: true, issue: null } : {
38642
39129
  configured: false,
38643
39130
  issue: "Honcho \u9700\u8981\u5148\u586B\u5199 API Key\uFF0C\u6216\u5728 honcho.json \u914D\u7F6E self-hosted baseUrl\u3002"
38644
39131
  };
@@ -38647,7 +39134,7 @@ async function readProviderConfigurationStatus(profileName, provider) {
38647
39134
  const config2 = await readJsonObject(
38648
39135
  memoryProviderConfigPath(profileName, "mem0") ?? ""
38649
39136
  );
38650
- return isConfiguredEnvValue(env.MEM0_API_KEY) || isConfiguredEnvValue(readString23(config2.api_key)) ? { configured: true, issue: null } : {
39137
+ return isConfiguredEnvValue(env.MEM0_API_KEY) || isConfiguredEnvValue(readString24(config2.api_key)) ? { configured: true, issue: null } : {
38651
39138
  configured: false,
38652
39139
  issue: "Mem0 \u9700\u8981\u5148\u5728\u672C\u9875\u586B\u5199 API Key\uFF0CLink \u4F1A\u5199\u5165\u5F53\u524D Profile \u7684 .env\u3002"
38653
39140
  };
@@ -38689,7 +39176,7 @@ async function readProviderConfigurationStatus(profileName, provider) {
38689
39176
  memoryProviderConfigPath(profileName, provider) ?? ""
38690
39177
  );
38691
39178
  const mode = normalizeHindsightMode(config.mode ?? env.HINDSIGHT_MODE);
38692
- const apiKey = readString23(config.apiKey) ?? readString23(config.api_key) ?? env.HINDSIGHT_API_KEY;
39179
+ const apiKey = readString24(config.apiKey) ?? readString24(config.api_key) ?? env.HINDSIGHT_API_KEY;
38693
39180
  if (mode === "cloud") {
38694
39181
  return isConfiguredEnvValue(apiKey) ? { configured: true, issue: null } : {
38695
39182
  configured: false,
@@ -38697,15 +39184,15 @@ async function readProviderConfigurationStatus(profileName, provider) {
38697
39184
  };
38698
39185
  }
38699
39186
  if (mode === "local_external") {
38700
- const apiUrl = readString23(config.api_url) ?? env.HINDSIGHT_API_URL ?? HINDSIGHT_DEFAULT_LOCAL_URL;
39187
+ const apiUrl = readString24(config.api_url) ?? env.HINDSIGHT_API_URL ?? HINDSIGHT_DEFAULT_LOCAL_URL;
38701
39188
  return isConfiguredEnvValue(apiUrl) ? { configured: true, issue: null } : {
38702
39189
  configured: false,
38703
39190
  issue: "Hindsight local_external \u9700\u8981\u914D\u7F6E\u53EF\u8BBF\u95EE\u7684 API URL\u3002"
38704
39191
  };
38705
39192
  }
38706
39193
  if (mode === "local_embedded") {
38707
- const llmProvider = readString23(config.llm_provider) ?? "openai";
38708
- const llmModel = readString23(config.llm_model);
39194
+ const llmProvider = readString24(config.llm_provider) ?? "openai";
39195
+ const llmModel = readString24(config.llm_model);
38709
39196
  if (!llmModel) {
38710
39197
  return {
38711
39198
  configured: false,
@@ -38713,7 +39200,7 @@ async function readProviderConfigurationStatus(profileName, provider) {
38713
39200
  };
38714
39201
  }
38715
39202
  if (llmProvider === "openai_compatible" && !isConfiguredEnvValue(
38716
- readString23(config.llm_base_url) ?? env.HINDSIGHT_API_LLM_BASE_URL
39203
+ readString24(config.llm_base_url) ?? env.HINDSIGHT_API_LLM_BASE_URL
38717
39204
  )) {
38718
39205
  return {
38719
39206
  configured: false,
@@ -38721,7 +39208,7 @@ async function readProviderConfigurationStatus(profileName, provider) {
38721
39208
  };
38722
39209
  }
38723
39210
  if (!["ollama", "lmstudio", "openai_compatible"].includes(llmProvider) && !isConfiguredEnvValue(
38724
- readString23(config.llmApiKey) ?? readString23(config.llm_api_key) ?? env.HINDSIGHT_LLM_API_KEY
39211
+ readString24(config.llmApiKey) ?? readString24(config.llm_api_key) ?? env.HINDSIGHT_LLM_API_KEY
38725
39212
  )) {
38726
39213
  return {
38727
39214
  configured: false,
@@ -38777,8 +39264,8 @@ async function readProviderSettings(profileName, provider) {
38777
39264
  secretSetting(
38778
39265
  "apiKey",
38779
39266
  "API Key",
38780
- env.HONCHO_API_KEY ?? readString23(config.apiKey) ?? readString23(config.api_key),
38781
- isConfiguredEnvValue(env.HONCHO_API_KEY) || isConfiguredEnvValue(readString23(config.apiKey)) || isConfiguredEnvValue(readString23(config.api_key))
39267
+ env.HONCHO_API_KEY ?? readString24(config.apiKey) ?? readString24(config.api_key),
39268
+ isConfiguredEnvValue(env.HONCHO_API_KEY) || isConfiguredEnvValue(readString24(config.apiKey)) || isConfiguredEnvValue(readString24(config.api_key))
38782
39269
  ),
38783
39270
  stringSetting("workspace", "Workspace", config.workspace ?? "hermes"),
38784
39271
  stringSetting("peerName", "\u7528\u6237 Peer", config.peerName ?? ""),
@@ -38820,8 +39307,8 @@ async function readProviderSettings(profileName, provider) {
38820
39307
  secretSetting(
38821
39308
  "apiKey",
38822
39309
  "API Key",
38823
- env.MEM0_API_KEY ?? readString23(config.apiKey) ?? readString23(config.api_key),
38824
- isConfiguredEnvValue(env.MEM0_API_KEY) || isConfiguredEnvValue(readString23(config.apiKey)) || isConfiguredEnvValue(readString23(config.api_key))
39310
+ env.MEM0_API_KEY ?? readString24(config.apiKey) ?? readString24(config.api_key),
39311
+ isConfiguredEnvValue(env.MEM0_API_KEY) || isConfiguredEnvValue(readString24(config.apiKey)) || isConfiguredEnvValue(readString24(config.api_key))
38825
39312
  ),
38826
39313
  stringSetting("userId", "User ID", config.user_id ?? "hermes-user"),
38827
39314
  stringSetting("agentId", "Agent ID", config.agent_id ?? "hermes"),
@@ -38889,8 +39376,8 @@ async function readProviderSettings(profileName, provider) {
38889
39376
  memoryProviderConfigPath(profileName, provider) ?? ""
38890
39377
  );
38891
39378
  const env = await readHermesMemoryEnv(profileName);
38892
- const banks = toRecord21(config.banks);
38893
- const hermesBank = toRecord21(banks.hermes);
39379
+ const banks = toRecord22(config.banks);
39380
+ const hermesBank = toRecord22(banks.hermes);
38894
39381
  const mode = normalizeHindsightMode(config.mode);
38895
39382
  return [
38896
39383
  selectSetting("mode", "\u8FDE\u63A5\u6A21\u5F0F", mode, [
@@ -38906,8 +39393,8 @@ async function readProviderSettings(profileName, provider) {
38906
39393
  secretSetting(
38907
39394
  "apiKey",
38908
39395
  "Hindsight API Key",
38909
- env.HINDSIGHT_API_KEY ?? readString23(config.apiKey) ?? readString23(config.api_key),
38910
- isConfiguredEnvValue(env.HINDSIGHT_API_KEY) || isConfiguredEnvValue(readString23(config.apiKey)) || isConfiguredEnvValue(readString23(config.api_key))
39396
+ env.HINDSIGHT_API_KEY ?? readString24(config.apiKey) ?? readString24(config.api_key),
39397
+ isConfiguredEnvValue(env.HINDSIGHT_API_KEY) || isConfiguredEnvValue(readString24(config.apiKey)) || isConfiguredEnvValue(readString24(config.api_key))
38911
39398
  ),
38912
39399
  stringSetting(
38913
39400
  "bankId",
@@ -38929,8 +39416,8 @@ async function readProviderSettings(profileName, provider) {
38929
39416
  secretSetting(
38930
39417
  "llmApiKey",
38931
39418
  "LLM API Key",
38932
- env.HINDSIGHT_LLM_API_KEY ?? readString23(config.llmApiKey) ?? readString23(config.llm_api_key),
38933
- isConfiguredEnvValue(env.HINDSIGHT_LLM_API_KEY) || isConfiguredEnvValue(readString23(config.llmApiKey)) || isConfiguredEnvValue(readString23(config.llm_api_key))
39419
+ env.HINDSIGHT_LLM_API_KEY ?? readString24(config.llmApiKey) ?? readString24(config.llm_api_key),
39420
+ isConfiguredEnvValue(env.HINDSIGHT_LLM_API_KEY) || isConfiguredEnvValue(readString24(config.llmApiKey)) || isConfiguredEnvValue(readString24(config.llm_api_key))
38934
39421
  ),
38935
39422
  booleanSetting("autoRecall", "\u81EA\u52A8\u56DE\u5FC6", config.auto_recall ?? true),
38936
39423
  booleanSetting("autoRetain", "\u81EA\u52A8\u6C89\u6DC0", config.auto_retain ?? true),
@@ -39042,18 +39529,18 @@ async function readCustomProviderRegistry(profileName) {
39042
39529
  }
39043
39530
  try {
39044
39531
  const parsed = JSON.parse(raw);
39045
- const providers = Array.isArray(parsed) ? parsed : Array.isArray(toRecord21(parsed).providers) ? toRecord21(parsed).providers : [];
39532
+ const providers = Array.isArray(parsed) ? parsed : Array.isArray(toRecord22(parsed).providers) ? toRecord22(parsed).providers : [];
39046
39533
  return providers.map((item) => {
39047
39534
  if (typeof item === "string") {
39048
39535
  const id2 = normalizeCustomProviderId(item);
39049
39536
  return { id: id2, label: id2, description: "\u81EA\u5B9A\u4E49 memory provider\u3002" };
39050
39537
  }
39051
- const record = toRecord21(item);
39052
- const id = normalizeCustomProviderId(readString23(record.id) ?? "");
39538
+ const record = toRecord22(item);
39539
+ const id = normalizeCustomProviderId(readString24(record.id) ?? "");
39053
39540
  return {
39054
39541
  id,
39055
- label: readString23(record.label) ?? id,
39056
- description: readString23(record.description) ?? "\u81EA\u5B9A\u4E49 memory provider\u3002"
39542
+ label: readString24(record.label) ?? id,
39543
+ description: readString24(record.description) ?? "\u81EA\u5B9A\u4E49 memory provider\u3002"
39057
39544
  };
39058
39545
  }).filter((item) => item.id);
39059
39546
  } catch {
@@ -39102,8 +39589,8 @@ async function discoverUserMemoryProviderDescriptors(profileName) {
39102
39589
  const meta = await readPluginMetadata(providerDir);
39103
39590
  descriptors.push({
39104
39591
  id: providerId,
39105
- label: readString23(meta.name) ?? providerId,
39106
- description: readString23(meta.description) ?? "\u81EA\u5B9A\u4E49 memory provider\u3002"
39592
+ label: readString24(meta.name) ?? providerId,
39593
+ description: readString24(meta.description) ?? "\u81EA\u5B9A\u4E49 memory provider\u3002"
39107
39594
  });
39108
39595
  }
39109
39596
  return descriptors;
@@ -39137,7 +39624,7 @@ async function readPluginMetadata(providerDir) {
39137
39624
  throw error;
39138
39625
  }
39139
39626
  );
39140
- return raw ? toRecord21(YAML6.parse(raw)) : {};
39627
+ return raw ? toRecord22(YAML6.parse(raw)) : {};
39141
39628
  }
39142
39629
  async function resolveByteRoverCli() {
39143
39630
  const candidates = [
@@ -39163,9 +39650,9 @@ async function readHolographicProviderConfig(profileName) {
39163
39650
  throw error;
39164
39651
  }
39165
39652
  );
39166
- const config = raw ? toRecord21(YAML6.parse(raw)) : {};
39167
- const plugins = toRecord21(config.plugins);
39168
- return toRecord21(plugins["hermes-memory-store"]);
39653
+ const config = raw ? toRecord22(YAML6.parse(raw)) : {};
39654
+ const plugins = toRecord22(config.plugins);
39655
+ return toRecord22(plugins["hermes-memory-store"]);
39169
39656
  }
39170
39657
  async function patchHolographicProviderConfig(profileName, patch) {
39171
39658
  const configPath = resolveHermesConfigPath(profileName);
@@ -39178,9 +39665,9 @@ async function patchHolographicProviderConfig(profileName, patch) {
39178
39665
  }
39179
39666
  );
39180
39667
  const document = existingRaw ? YAML6.parseDocument(existingRaw) : new YAML6.Document({});
39181
- const config = toRecord21(document.toJSON());
39182
- const plugins = toRecord21(config.plugins);
39183
- const memoryStore = toRecord21(plugins["hermes-memory-store"]);
39668
+ const config = toRecord22(document.toJSON());
39669
+ const plugins = toRecord22(config.plugins);
39670
+ const memoryStore = toRecord22(plugins["hermes-memory-store"]);
39184
39671
  for (const [key, value] of Object.entries(patch)) {
39185
39672
  if (value !== void 0) {
39186
39673
  memoryStore[key] = value;
@@ -39265,7 +39752,7 @@ function isMemoryEnvKeyWritable(key) {
39265
39752
  ].includes(key);
39266
39753
  }
39267
39754
  function normalizeHindsightMode(value) {
39268
- const mode = readString23(value) ?? "cloud";
39755
+ const mode = readString24(value) ?? "cloud";
39269
39756
  return mode === "local" ? "local_embedded" : mode;
39270
39757
  }
39271
39758
  function normalizeHttpUrl2(value) {
@@ -39328,33 +39815,33 @@ function joinHindsightUrl(baseUrl, pathName) {
39328
39815
  }
39329
39816
  function parseJsonObject2(text) {
39330
39817
  try {
39331
- return toRecord21(JSON.parse(text));
39818
+ return toRecord22(JSON.parse(text));
39332
39819
  } catch {
39333
39820
  return {};
39334
39821
  }
39335
39822
  }
39336
39823
  function readHindsightError(json) {
39337
- const detail = readString23(json.detail) ?? readString23(json.error);
39824
+ const detail = readString24(json.detail) ?? readString24(json.error);
39338
39825
  return detail ? `\uFF1A${detail}` : "";
39339
39826
  }
39340
39827
  function hindsightSemanticIssue(pathName, json) {
39341
39828
  if (pathName === "/health") {
39342
- const status = readString23(json.status);
39829
+ const status = readString24(json.status);
39343
39830
  return status && ["healthy", "ok"].includes(status.toLowerCase()) ? null : `\u5065\u5EB7\u72B6\u6001\u5F02\u5E38\uFF1A${status ?? "unknown"}`;
39344
39831
  }
39345
39832
  return null;
39346
39833
  }
39347
39834
  function summarizeHindsightProbe(pathName, json) {
39348
39835
  if (pathName === "/health") {
39349
- const status = readString23(json.status) ?? "ok";
39350
- const database = readString23(json.database);
39836
+ const status = readString24(json.status) ?? "ok";
39837
+ const database = readString24(json.database);
39351
39838
  return database ? `${status}, database ${database}` : status;
39352
39839
  }
39353
39840
  if (pathName === "/version") {
39354
- const version = readString23(json.api_version);
39841
+ const version = readString24(json.api_version);
39355
39842
  return version ? `API ${version}` : "version endpoint reachable";
39356
39843
  }
39357
- const bankId = readString23(json.bank_id);
39844
+ const bankId = readString24(json.bank_id);
39358
39845
  return bankId ? `bank ${bankId} reachable` : "bank config reachable";
39359
39846
  }
39360
39847
  async function readActiveMemoryProvider(profileName) {
@@ -39367,9 +39854,9 @@ async function readActiveMemoryProvider(profileName) {
39367
39854
  }
39368
39855
  throw error;
39369
39856
  });
39370
- const config = raw ? toRecord21(YAML6.parse(raw)) : {};
39371
- const memory = toRecord21(config.memory);
39372
- const provider = readString23(memory.provider);
39857
+ const config = raw ? toRecord22(YAML6.parse(raw)) : {};
39858
+ const memory = toRecord22(config.memory);
39859
+ const provider = readString24(memory.provider);
39373
39860
  if (!provider || provider === "built-in" || provider === "builtin" || provider === "built_in") {
39374
39861
  return null;
39375
39862
  }
@@ -39401,7 +39888,7 @@ async function readJsonObject(filePath) {
39401
39888
  throw error;
39402
39889
  });
39403
39890
  try {
39404
- return toRecord21(JSON.parse(raw || "{}"));
39891
+ return toRecord22(JSON.parse(raw || "{}"));
39405
39892
  } catch {
39406
39893
  throw new HermesMemoryError(
39407
39894
  "memory_provider_config_invalid",
@@ -39426,7 +39913,7 @@ function stringSetting(key, label, value, editable = true) {
39426
39913
  return {
39427
39914
  key,
39428
39915
  label,
39429
- value: readString23(value) ?? "",
39916
+ value: readString24(value) ?? "",
39430
39917
  editable,
39431
39918
  kind: "string"
39432
39919
  };
@@ -39438,7 +39925,7 @@ function secretSetting(key, label, value, configured) {
39438
39925
  value: "",
39439
39926
  editable: true,
39440
39927
  kind: "secret",
39441
- configured: configured || isConfiguredEnvValue(readString23(value))
39928
+ configured: configured || isConfiguredEnvValue(readString24(value))
39442
39929
  };
39443
39930
  }
39444
39931
  function textSetting(key, label, value, editable = true) {
@@ -39451,7 +39938,7 @@ function textSetting(key, label, value, editable = true) {
39451
39938
  };
39452
39939
  }
39453
39940
  function selectSetting(key, label, value, options, editable = true) {
39454
- const stringValue = readString23(value) ?? options[0] ?? null;
39941
+ const stringValue = readString24(value) ?? options[0] ?? null;
39455
39942
  return { key, label, value: stringValue, editable, kind: "select", options };
39456
39943
  }
39457
39944
  async function readMemoryLimits(profileName) {
@@ -39464,8 +39951,8 @@ async function readMemoryLimits(profileName) {
39464
39951
  }
39465
39952
  throw error;
39466
39953
  });
39467
- const config = raw ? toRecord21(YAML6.parse(raw)) : {};
39468
- const memory = toRecord21(config.memory);
39954
+ const config = raw ? toRecord22(YAML6.parse(raw)) : {};
39955
+ const memory = toRecord22(config.memory);
39469
39956
  return {
39470
39957
  memory: readPositiveInteger4(memory.memory_char_limit) ?? DEFAULT_MEMORY_LIMIT,
39471
39958
  user: readPositiveInteger4(memory.user_char_limit) ?? DEFAULT_USER_LIMIT
@@ -39521,10 +40008,10 @@ function hashString(value) {
39521
40008
  }
39522
40009
  return hash.toString(16);
39523
40010
  }
39524
- function toRecord21(value) {
40011
+ function toRecord22(value) {
39525
40012
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
39526
40013
  }
39527
- function readString23(value) {
40014
+ function readString24(value) {
39528
40015
  return typeof value === "string" && value.trim() ? value.trim() : null;
39529
40016
  }
39530
40017
  function readPositiveInteger4(value) {
@@ -39683,7 +40170,7 @@ function registerProfileMemoryRoutes(router, options) {
39683
40170
  );
39684
40171
  }
39685
40172
  function readMemoryTarget(body) {
39686
- const raw = readString21(body, "target");
40173
+ const raw = readString22(body, "target");
39687
40174
  if (raw === "memory" || raw === "user") {
39688
40175
  return raw;
39689
40176
  }
@@ -39694,7 +40181,7 @@ function readMemoryTarget(body) {
39694
40181
  );
39695
40182
  }
39696
40183
  function readMemoryResetTarget(body) {
39697
- const raw = readString21(body, "target") ?? "all";
40184
+ const raw = readString22(body, "target") ?? "all";
39698
40185
  if (raw === "all" || raw === "memory" || raw === "user") {
39699
40186
  return raw;
39700
40187
  }
@@ -39705,7 +40192,7 @@ function readMemoryResetTarget(body) {
39705
40192
  );
39706
40193
  }
39707
40194
  function readRequiredMemoryContent(body) {
39708
- const content = readString21(body, "content") ?? readString21(body, "text");
40195
+ const content = readString22(body, "content") ?? readString22(body, "text");
39709
40196
  if (!content) {
39710
40197
  throw new LinkHttpError(
39711
40198
  400,
@@ -39716,7 +40203,7 @@ function readRequiredMemoryContent(body) {
39716
40203
  return content;
39717
40204
  }
39718
40205
  function readRequiredMemoryMatch(body) {
39719
- const oldText = readString21(body, "old_text") ?? readString21(body, "oldText") ?? readString21(body, "match");
40206
+ const oldText = readString22(body, "old_text") ?? readString22(body, "oldText") ?? readString22(body, "match");
39720
40207
  if (!oldText) {
39721
40208
  throw new LinkHttpError(
39722
40209
  400,
@@ -39727,7 +40214,7 @@ function readRequiredMemoryMatch(body) {
39727
40214
  return oldText;
39728
40215
  }
39729
40216
  function readRequiredMemoryProvider(body) {
39730
- const provider = readString21(body, "provider") ?? readString21(body, "provider_id") ?? readString21(body, "providerId");
40217
+ const provider = readString22(body, "provider") ?? readString22(body, "provider_id") ?? readString22(body, "providerId");
39731
40218
  if (!provider) {
39732
40219
  throw new LinkHttpError(
39733
40220
  400,
@@ -39757,7 +40244,7 @@ function readMemorySettingsPatch(body, options = {}) {
39757
40244
  input.userCharLimit = userCharLimit;
39758
40245
  }
39759
40246
  }
39760
- const mode = readString21(body, "mode");
40247
+ const mode = readString22(body, "mode");
39761
40248
  if (mode) {
39762
40249
  input.mode = mode;
39763
40250
  }
@@ -39773,7 +40260,7 @@ function readMemorySettingsPatch(body, options = {}) {
39773
40260
  if (bankId !== void 0) {
39774
40261
  input.bankId = bankId;
39775
40262
  }
39776
- const llmProvider = readString21(body, "llm_provider") ?? readString21(body, "llmProvider");
40263
+ const llmProvider = readString22(body, "llm_provider") ?? readString22(body, "llmProvider");
39777
40264
  if (llmProvider) {
39778
40265
  input.llmProvider = llmProvider;
39779
40266
  }
@@ -39809,11 +40296,11 @@ function readMemorySettingsPatch(body, options = {}) {
39809
40296
  if (autoRetain !== void 0) {
39810
40297
  input.autoRetain = autoRetain;
39811
40298
  }
39812
- const memoryMode = readString21(body, "memory_mode") ?? readString21(body, "memoryMode");
40299
+ const memoryMode = readString22(body, "memory_mode") ?? readString22(body, "memoryMode");
39813
40300
  if (memoryMode) {
39814
40301
  input.memoryMode = memoryMode;
39815
40302
  }
39816
- const recallBudget = readString21(body, "recall_budget") ?? readString21(body, "recallBudget");
40303
+ const recallBudget = readString22(body, "recall_budget") ?? readString22(body, "recallBudget");
39817
40304
  if (recallBudget) {
39818
40305
  input.recallBudget = recallBudget;
39819
40306
  }
@@ -39829,11 +40316,11 @@ function readMemorySettingsPatch(body, options = {}) {
39829
40316
  if (profileFrequency !== void 0) {
39830
40317
  input.profileFrequency = profileFrequency;
39831
40318
  }
39832
- const captureMode = readString21(body, "capture_mode") ?? readString21(body, "captureMode");
40319
+ const captureMode = readString22(body, "capture_mode") ?? readString22(body, "captureMode");
39833
40320
  if (captureMode) {
39834
40321
  input.captureMode = captureMode;
39835
40322
  }
39836
- const searchMode = readString21(body, "search_mode") ?? readString21(body, "searchMode");
40323
+ const searchMode = readString22(body, "search_mode") ?? readString22(body, "searchMode");
39837
40324
  if (searchMode) {
39838
40325
  input.searchMode = searchMode;
39839
40326
  }
@@ -39867,11 +40354,11 @@ function readMemorySettingsPatch(body, options = {}) {
39867
40354
  if (aiPeer !== void 0) {
39868
40355
  input.aiPeer = aiPeer;
39869
40356
  }
39870
- const recallMode = readString21(body, "recall_mode") ?? readString21(body, "recallMode");
40357
+ const recallMode = readString22(body, "recall_mode") ?? readString22(body, "recallMode");
39871
40358
  if (recallMode) {
39872
40359
  input.recallMode = recallMode;
39873
40360
  }
39874
- const writeFrequency = readString21(body, "write_frequency") ?? readString21(body, "writeFrequency");
40361
+ const writeFrequency = readString22(body, "write_frequency") ?? readString22(body, "writeFrequency");
39875
40362
  if (writeFrequency) {
39876
40363
  input.writeFrequency = writeFrequency;
39877
40364
  }
@@ -39879,7 +40366,7 @@ function readMemorySettingsPatch(body, options = {}) {
39879
40366
  if (saveMessages !== void 0) {
39880
40367
  input.saveMessages = saveMessages;
39881
40368
  }
39882
- const sessionStrategy = readString21(body, "session_strategy") ?? readString21(body, "sessionStrategy");
40369
+ const sessionStrategy = readString22(body, "session_strategy") ?? readString22(body, "sessionStrategy");
39883
40370
  if (sessionStrategy) {
39884
40371
  input.sessionStrategy = sessionStrategy;
39885
40372
  }
@@ -40159,13 +40646,13 @@ async function readSkillMetadata(input) {
40159
40646
  const skillDir = path33.dirname(input.skillFile);
40160
40647
  const { frontmatter, body } = parseSkillDocument(raw.slice(0, 4e3));
40161
40648
  const name = normalizeSkillName(
40162
- readString24(frontmatter.name) ?? path33.basename(skillDir)
40649
+ readString25(frontmatter.name) ?? path33.basename(skillDir)
40163
40650
  );
40164
40651
  if (!name) {
40165
40652
  return null;
40166
40653
  }
40167
40654
  const description = normalizeDescription(
40168
- readString24(frontmatter.description) ?? firstBodyDescription(body)
40655
+ readString25(frontmatter.description) ?? firstBodyDescription(body)
40169
40656
  );
40170
40657
  const provenance = input.provenance.get(name) ?? {
40171
40658
  source: "local",
@@ -40191,7 +40678,7 @@ function parseSkillDocument(raw) {
40191
40678
  }
40192
40679
  try {
40193
40680
  return {
40194
- frontmatter: toRecord22(YAML7.parse(match[1] ?? "")),
40681
+ frontmatter: toRecord23(YAML7.parse(match[1] ?? "")),
40195
40682
  body: content.slice(match[0].length)
40196
40683
  };
40197
40684
  } catch {
@@ -40232,8 +40719,8 @@ async function readDisabledSkillNames(configPath) {
40232
40719
  if (!raw.trim()) {
40233
40720
  return /* @__PURE__ */ new Set();
40234
40721
  }
40235
- const config = toRecord22(YAML7.parse(raw));
40236
- const skills = toRecord22(config.skills);
40722
+ const config = toRecord23(YAML7.parse(raw));
40723
+ const skills = toRecord23(config.skills);
40237
40724
  return new Set(readStringList6(skills.disabled));
40238
40725
  }
40239
40726
  async function readSkillProvenance(root) {
@@ -40283,17 +40770,17 @@ async function readHubInstalledSkills(root) {
40283
40770
  }
40284
40771
  let lock;
40285
40772
  try {
40286
- lock = toRecord22(JSON.parse(raw));
40773
+ lock = toRecord23(JSON.parse(raw));
40287
40774
  } catch {
40288
40775
  return /* @__PURE__ */ new Map();
40289
40776
  }
40290
- const installed2 = toRecord22(lock.installed);
40777
+ const installed2 = toRecord23(lock.installed);
40291
40778
  const result = /* @__PURE__ */ new Map();
40292
40779
  for (const [name, rawEntry] of Object.entries(installed2)) {
40293
- const entry = toRecord22(rawEntry);
40780
+ const entry = toRecord23(rawEntry);
40294
40781
  result.set(normalizeSkillName(name), {
40295
- source: readString24(entry.source) ?? "hub",
40296
- trust: readString24(entry.trust_level) ?? null
40782
+ source: readString25(entry.source) ?? "hub",
40783
+ trust: readString25(entry.trust_level) ?? null
40297
40784
  });
40298
40785
  }
40299
40786
  return result;
@@ -40353,7 +40840,7 @@ async function readHermesConfigDocument4(configPath) {
40353
40840
  const document = existingRaw ? YAML7.parseDocument(existingRaw) : new YAML7.Document({});
40354
40841
  return {
40355
40842
  document,
40356
- config: toRecord22(document.toJSON()),
40843
+ config: toRecord23(document.toJSON()),
40357
40844
  existingRaw
40358
40845
  };
40359
40846
  }
@@ -40377,14 +40864,14 @@ function readStringList6(value) {
40377
40864
  }
40378
40865
  return value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean);
40379
40866
  }
40380
- function readString24(value) {
40867
+ function readString25(value) {
40381
40868
  return typeof value === "string" && value.trim() ? value.trim() : null;
40382
40869
  }
40383
- function toRecord22(value) {
40870
+ function toRecord23(value) {
40384
40871
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
40385
40872
  }
40386
40873
  function ensureRecord5(target, key) {
40387
- const current = toRecord22(target[key]);
40874
+ const current = toRecord23(target[key]);
40388
40875
  if (current === target[key]) {
40389
40876
  return current;
40390
40877
  }
@@ -40603,11 +41090,11 @@ function readProfileCreationInput(body) {
40603
41090
  };
40604
41091
  }
40605
41092
  function readProfileCreationIdentityTemplateId(body) {
40606
- const identity = toRecord23(body.identity);
41093
+ const identity = toRecord24(body.identity);
40607
41094
  return readOptionalProfileText(body, "identityTemplateId", "identity_template_id").value ?? readOptionalProfileText(identity, "templateId", "template_id").value;
40608
41095
  }
40609
41096
  function readProfileCreationSoulMd(body) {
40610
- const identity = toRecord23(body.identity);
41097
+ const identity = toRecord24(body.identity);
40611
41098
  return readOptionalProfileText(body, "soulMd", "soul_md").value ?? readOptionalProfileText(identity, "soulMd", "soul_md").value;
40612
41099
  }
40613
41100
  function readProfileSoulMd(body) {
@@ -40617,7 +41104,7 @@ function readProfileSoulMd(body) {
40617
41104
  }
40618
41105
  return value;
40619
41106
  }
40620
- function toRecord23(value) {
41107
+ function toRecord24(value) {
40621
41108
  return value && typeof value === "object" ? value : {};
40622
41109
  }
40623
41110
  function readProfileCreationAvatarType(body) {
@@ -40749,7 +41236,7 @@ function registerRunRoutes(router, options) {
40749
41236
  await authenticateRequest(ctx, paths);
40750
41237
  const language = readPreferredLanguage(ctx);
40751
41238
  const body = await readJsonBody(ctx.req);
40752
- const input = readString21(body, "input");
41239
+ const input = readString22(body, "input");
40753
41240
  if (!input) {
40754
41241
  throw new LinkHttpError(400, "run_input_required", "input is required");
40755
41242
  }
@@ -40757,12 +41244,12 @@ function registerRunRoutes(router, options) {
40757
41244
  ctx.body = await createHermesRun(
40758
41245
  {
40759
41246
  input,
40760
- instructions: readString21(body, "instructions") ?? void 0,
41247
+ instructions: readString22(body, "instructions") ?? void 0,
40761
41248
  conversation_history: readConversationHistory(
40762
41249
  body.conversation_history ?? body.conversationHistory
40763
41250
  ),
40764
- session_id: readString21(body, "session_id") ?? readString21(body, "sessionId") ?? void 0,
40765
- session_key: readString21(body, "session_key") ?? readString21(body, "sessionKey") ?? void 0
41251
+ session_id: readString22(body, "session_id") ?? readString22(body, "sessionId") ?? void 0,
41252
+ session_key: readString22(body, "session_key") ?? readString22(body, "sessionKey") ?? void 0
40766
41253
  },
40767
41254
  { logger, profileName: readOptionalProfileName(body), language }
40768
41255
  );
@@ -41171,24 +41658,24 @@ async function readRemoteRelease(options, now) {
41171
41658
  }
41172
41659
  }
41173
41660
  function normalizeServerReleaseSnapshot(payload) {
41174
- const snapshot = toRecord24(payload);
41661
+ const snapshot = toRecord25(payload);
41175
41662
  const remote = toNullableRecord(snapshot.remote);
41176
41663
  return {
41177
41664
  remote: remote ? normalizeServerRelease(remote) : null,
41178
- cacheState: readString25(snapshot, "cache_state") ?? readString25(snapshot, "cacheState"),
41179
- issue: readString25(snapshot, "issue")
41665
+ cacheState: readString26(snapshot, "cache_state") ?? readString26(snapshot, "cacheState"),
41666
+ issue: readString26(snapshot, "issue")
41180
41667
  };
41181
41668
  }
41182
41669
  function normalizeServerRelease(payload) {
41183
- const tag = readString25(payload, "tag");
41184
- const name = readString25(payload, "name");
41670
+ const tag = readString26(payload, "tag");
41671
+ const name = readString26(payload, "name");
41185
41672
  return {
41186
- version: readString25(payload, "version") ?? extractSemver(name) ?? extractTagSemver(tag),
41673
+ version: readString26(payload, "version") ?? extractSemver(name) ?? extractTagSemver(tag),
41187
41674
  tag,
41188
41675
  name,
41189
- releaseUrl: readString25(payload, "releaseUrl") ?? readString25(payload, "release_url"),
41190
- publishedAt: readString25(payload, "publishedAt") ?? readString25(payload, "published_at"),
41191
- fetchedAt: readString25(payload, "fetchedAt") ?? readString25(payload, "fetched_at") ?? (/* @__PURE__ */ new Date()).toISOString()
41676
+ releaseUrl: readString26(payload, "releaseUrl") ?? readString26(payload, "release_url"),
41677
+ publishedAt: readString26(payload, "publishedAt") ?? readString26(payload, "published_at"),
41678
+ fetchedAt: readString26(payload, "fetchedAt") ?? readString26(payload, "fetched_at") ?? (/* @__PURE__ */ new Date()).toISOString()
41192
41679
  };
41193
41680
  }
41194
41681
  async function readReleaseCache(paths) {
@@ -41260,7 +41747,7 @@ function compareSemver2(left, right) {
41260
41747
  }
41261
41748
  return 0;
41262
41749
  }
41263
- function toRecord24(value) {
41750
+ function toRecord25(value) {
41264
41751
  return typeof value === "object" && value !== null ? value : {};
41265
41752
  }
41266
41753
  function toNullableRecord(value) {
@@ -41314,7 +41801,7 @@ function isRecentRunningState2(state) {
41314
41801
  const startedAt = Date.parse(state.started_at);
41315
41802
  return Number.isFinite(startedAt) && Date.now() - startedAt < 3e4;
41316
41803
  }
41317
- function readString25(payload, key) {
41804
+ function readString26(payload, key) {
41318
41805
  const value = payload[key];
41319
41806
  return typeof value === "string" && value.trim() ? value.trim() : null;
41320
41807
  }
@@ -44130,21 +44617,21 @@ async function readRemoteLinkPolicy(options) {
44130
44617
  }
44131
44618
  }
44132
44619
  function normalizeServerSnapshot(payload) {
44133
- const snapshot = toRecord25(payload);
44620
+ const snapshot = toRecord26(payload);
44134
44621
  const policy = toNullableRecord2(snapshot.policy);
44135
44622
  if (!policy) {
44136
44623
  return {
44137
44624
  remote: null,
44138
- issue: readString26(snapshot, "issue")
44625
+ issue: readString27(snapshot, "issue")
44139
44626
  };
44140
44627
  }
44141
44628
  const release = toNullableRecord2(snapshot.release);
44142
- const currentVersion = readString26(policy, "current_version") ?? readString26(policy, "currentVersion");
44143
- const minSafeVersion = readString26(policy, "min_safe_version") ?? readString26(policy, "minSafeVersion");
44629
+ const currentVersion = readString27(policy, "current_version") ?? readString27(policy, "currentVersion");
44630
+ const minSafeVersion = readString27(policy, "min_safe_version") ?? readString27(policy, "minSafeVersion");
44144
44631
  if (!currentVersion) {
44145
44632
  return {
44146
44633
  remote: null,
44147
- issue: readString26(snapshot, "issue")
44634
+ issue: readString27(snapshot, "issue")
44148
44635
  };
44149
44636
  }
44150
44637
  return {
@@ -44152,10 +44639,10 @@ function normalizeServerSnapshot(payload) {
44152
44639
  current_version: currentVersion,
44153
44640
  min_safe_version: minSafeVersion,
44154
44641
  target_version: currentVersion,
44155
- release_url: release ? readString26(release, "release_url") ?? readString26(release, "releaseUrl") : null,
44156
- published_at: release ? readString26(release, "published_at") ?? readString26(release, "publishedAt") : null
44642
+ release_url: release ? readString27(release, "release_url") ?? readString27(release, "releaseUrl") : null,
44643
+ published_at: release ? readString27(release, "published_at") ?? readString27(release, "publishedAt") : null
44157
44644
  },
44158
- issue: readString26(snapshot, "issue")
44645
+ issue: readString27(snapshot, "issue")
44159
44646
  };
44160
44647
  }
44161
44648
  async function fetchCurrentLinkReleaseFromServer(options, fetcher, channel) {
@@ -44563,13 +45050,13 @@ function isProcessAlive5(pid) {
44563
45050
  return false;
44564
45051
  }
44565
45052
  }
44566
- function toRecord25(value) {
45053
+ function toRecord26(value) {
44567
45054
  return typeof value === "object" && value !== null ? value : {};
44568
45055
  }
44569
45056
  function toNullableRecord2(value) {
44570
45057
  return typeof value === "object" && value !== null ? value : null;
44571
45058
  }
44572
- function readString26(payload, key) {
45059
+ function readString27(payload, key) {
44573
45060
  const value = payload[key];
44574
45061
  return typeof value === "string" && value.trim() ? value.trim() : null;
44575
45062
  }
@@ -45085,6 +45572,7 @@ function registerSystemRoutes(router, options) {
45085
45572
  statistics: true,
45086
45573
  conversations: true,
45087
45574
  conversation_events: true,
45575
+ conversation_thinking_stream: true,
45088
45576
  conversation_archive: true,
45089
45577
  conversation_unarchive: true,
45090
45578
  conversation_archive_plan: true,
@@ -45122,8 +45610,8 @@ function registerSystemRoutes(router, options) {
45122
45610
  });
45123
45611
  router.post("/api/v1/pairing/claim", async (ctx) => {
45124
45612
  const body = await readJsonBody(ctx.req);
45125
- const sessionId = readString21(body, "session_id") ?? readString21(body, "sessionId");
45126
- const claimToken = readString21(body, "claim_token") ?? readString21(body, "claimToken");
45613
+ const sessionId = readString22(body, "session_id") ?? readString22(body, "sessionId");
45614
+ const claimToken = readString22(body, "claim_token") ?? readString22(body, "claimToken");
45127
45615
  if (!sessionId || !claimToken) {
45128
45616
  throw new LinkHttpError(
45129
45617
  400,
@@ -45134,10 +45622,10 @@ function registerSystemRoutes(router, options) {
45134
45622
  const claimed = await claimPairing({
45135
45623
  sessionId,
45136
45624
  claimToken,
45137
- deviceLabel: readString21(body, "device_label") ?? readString21(body, "deviceLabel") ?? "HermesPilot App",
45138
- devicePlatform: readString21(body, "device_platform") ?? readString21(body, "devicePlatform") ?? "unknown",
45139
- deviceModel: readString21(body, "device_model") ?? readString21(body, "deviceModel"),
45140
- appInstanceId: readString21(body, "app_instance_id") ?? readString21(body, "appInstanceId"),
45625
+ deviceLabel: readString22(body, "device_label") ?? readString22(body, "deviceLabel") ?? "HermesPilot App",
45626
+ devicePlatform: readString22(body, "device_platform") ?? readString22(body, "devicePlatform") ?? "unknown",
45627
+ deviceModel: readString22(body, "device_model") ?? readString22(body, "deviceModel"),
45628
+ appInstanceId: readString22(body, "app_instance_id") ?? readString22(body, "appInstanceId"),
45141
45629
  paths
45142
45630
  });
45143
45631
  ctx.body = claimed;
@@ -45217,9 +45705,9 @@ function registerSystemRoutes(router, options) {
45217
45705
  const body = await readJsonBody(ctx.req);
45218
45706
  const session = await createDeviceSession(
45219
45707
  {
45220
- label: readString21(body, "device_label") ?? readString21(body, "deviceLabel") ?? "HermesPilot App",
45221
- platform: readString21(body, "device_platform") ?? readString21(body, "devicePlatform") ?? "unknown",
45222
- model: readString21(body, "device_model") ?? readString21(body, "deviceModel"),
45708
+ label: readString22(body, "device_label") ?? readString22(body, "deviceLabel") ?? "HermesPilot App",
45709
+ platform: readString22(body, "device_platform") ?? readString22(body, "devicePlatform") ?? "unknown",
45710
+ model: readString22(body, "device_model") ?? readString22(body, "deviceModel"),
45223
45711
  appInstanceId: auth.appInstanceId
45224
45712
  },
45225
45713
  paths
@@ -45248,7 +45736,7 @@ function registerSystemRoutes(router, options) {
45248
45736
  });
45249
45737
  router.post("/api/v1/auth/refresh", async (ctx) => {
45250
45738
  const body = await readJsonBody(ctx.req);
45251
- const refreshToken = readString21(body, "refresh_token") ?? readString21(body, "refreshToken");
45739
+ const refreshToken = readString22(body, "refresh_token") ?? readString22(body, "refreshToken");
45252
45740
  if (!refreshToken) {
45253
45741
  throw new LinkHttpError(
45254
45742
  400,
@@ -45259,10 +45747,10 @@ function registerSystemRoutes(router, options) {
45259
45747
  const session = await refreshDeviceSession(
45260
45748
  refreshToken,
45261
45749
  {
45262
- appInstanceId: readString21(body, "app_instance_id") ?? readString21(body, "appInstanceId"),
45263
- label: readString21(body, "device_label") ?? readString21(body, "deviceLabel"),
45264
- platform: readString21(body, "device_platform") ?? readString21(body, "devicePlatform"),
45265
- model: readString21(body, "device_model") ?? readString21(body, "deviceModel")
45750
+ appInstanceId: readString22(body, "app_instance_id") ?? readString22(body, "appInstanceId"),
45751
+ label: readString22(body, "device_label") ?? readString22(body, "deviceLabel"),
45752
+ platform: readString22(body, "device_platform") ?? readString22(body, "devicePlatform"),
45753
+ model: readString22(body, "device_model") ?? readString22(body, "deviceModel")
45266
45754
  },
45267
45755
  paths
45268
45756
  );
@@ -45281,7 +45769,7 @@ function registerSystemRoutes(router, options) {
45281
45769
  });
45282
45770
  router.post("/api/v1/auth/logout", async (ctx) => {
45283
45771
  const body = await readJsonBody(ctx.req);
45284
- const refreshToken = readString21(body, "refresh_token") ?? readString21(body, "refreshToken");
45772
+ const refreshToken = readString22(body, "refresh_token") ?? readString22(body, "refreshToken");
45285
45773
  if (refreshToken) {
45286
45774
  await revokeDeviceRefreshToken(refreshToken, paths);
45287
45775
  }
@@ -45522,7 +46010,7 @@ function registerSystemRoutes(router, options) {
45522
46010
  router.patch("/api/v1/devices/:deviceId", async (ctx) => {
45523
46011
  const auth = await authenticateRequest(ctx, paths);
45524
46012
  const body = await readJsonBody(ctx.req);
45525
- const label = readString21(body, "label") ?? readString21(body, "device_label");
46013
+ const label = readString22(body, "label") ?? readString22(body, "device_label");
45526
46014
  if (!label) {
45527
46015
  throw new LinkHttpError(
45528
46016
  400,
@@ -45566,7 +46054,7 @@ function isActiveCronJob(job) {
45566
46054
  if (!enabled) {
45567
46055
  return false;
45568
46056
  }
45569
- const state = readString21(job, "state")?.toLowerCase();
46057
+ const state = readString22(job, "state")?.toLowerCase();
45570
46058
  return !["paused", "disabled", "completed", "deleted"].includes(state ?? "");
45571
46059
  }
45572
46060
  function filterLogsWithinHours(logs, hours, now = Date.now()) {
@@ -45610,8 +46098,8 @@ function registerWorkspaceRoutes(router, options) {
45610
46098
  ctx.body = {
45611
46099
  ok: true,
45612
46100
  workspace: await conversations.createWorkspace({
45613
- name: readString21(body, "name") ?? "",
45614
- icon: readString21(body, "icon") ?? void 0
46101
+ name: readString22(body, "name") ?? "",
46102
+ icon: readString22(body, "icon") ?? void 0
45615
46103
  })
45616
46104
  };
45617
46105
  });
@@ -45621,8 +46109,8 @@ function registerWorkspaceRoutes(router, options) {
45621
46109
  ctx.body = {
45622
46110
  ok: true,
45623
46111
  workspace: await conversations.renameWorkspace(ctx.params.workspaceId, {
45624
- name: readString21(body, "name") ?? "",
45625
- icon: readString21(body, "icon") ?? void 0
46112
+ name: readString22(body, "name") ?? "",
46113
+ icon: readString22(body, "icon") ?? void 0
45626
46114
  })
45627
46115
  };
45628
46116
  });
@@ -45705,8 +46193,8 @@ function registerLinkUpdateRoutes(router, options) {
45705
46193
  ctx.body = await startLinkUpdate({
45706
46194
  paths,
45707
46195
  logger,
45708
- channel: readString21(body, "channel"),
45709
- targetVersion: readString21(body, "target_version") ?? readString21(body, "targetVersion")
46196
+ channel: readString22(body, "channel"),
46197
+ targetVersion: readString22(body, "target_version") ?? readString22(body, "targetVersion")
45710
46198
  });
45711
46199
  });
45712
46200
  router.get("/api/v1/link/update/events", async (ctx) => {
@@ -45736,7 +46224,7 @@ import QRCode from "qrcode";
45736
46224
  function registerPairingRoutes(router, options) {
45737
46225
  const { paths } = options;
45738
46226
  router.get("/pair", async (ctx) => {
45739
- const sessionId = readString21(ctx.query, "session_id");
46227
+ const sessionId = readString22(ctx.query, "session_id");
45740
46228
  if (!sessionId) {
45741
46229
  throw new LinkHttpError(400, "pairing_session_required", "session_id is required");
45742
46230
  }
@@ -45761,7 +46249,7 @@ function registerPairingRoutes(router, options) {
45761
46249
  ctx.body = page;
45762
46250
  });
45763
46251
  router.get("/api/v1/pairing/session", async (ctx) => {
45764
- const sessionId = readString21(ctx.query, "session_id");
46252
+ const sessionId = readString22(ctx.query, "session_id");
45765
46253
  if (!sessionId) {
45766
46254
  throw new LinkHttpError(400, "pairing_session_required", "session_id is required");
45767
46255
  }
@@ -46231,7 +46719,7 @@ function registerInternalRoutes(router, options) {
46231
46719
  router.post("/internal/deliver", async (ctx) => {
46232
46720
  assertLoopbackRequest(ctx.req);
46233
46721
  const body = await readJsonBody(ctx.req);
46234
- const stagingDir = readString21(body, "staging_dir") ?? readString21(body, "stagingDir");
46722
+ const stagingDir = readString22(body, "staging_dir") ?? readString22(body, "stagingDir");
46235
46723
  if (!stagingDir) {
46236
46724
  throw new LinkHttpError(
46237
46725
  400,
@@ -46250,9 +46738,9 @@ function registerInternalRoutes(router, options) {
46250
46738
  ctx.body = {
46251
46739
  ok: true,
46252
46740
  ...await options.conversations.deliverFilesFromTool({
46253
- profile: readString21(body, "profile") ?? readString21(body, "profile_name") ?? readString21(body, "profileName") ?? void 0,
46254
- taskId: readString21(body, "task_id") ?? readString21(body, "taskId") ?? void 0,
46255
- sessionId: readString21(body, "session_id") ?? readString21(body, "sessionId") ?? void 0,
46741
+ profile: readString22(body, "profile") ?? readString22(body, "profile_name") ?? readString22(body, "profileName") ?? void 0,
46742
+ taskId: readString22(body, "task_id") ?? readString22(body, "taskId") ?? void 0,
46743
+ sessionId: readString22(body, "session_id") ?? readString22(body, "sessionId") ?? void 0,
46256
46744
  files: body.files ?? body.file ?? body.path
46257
46745
  })
46258
46746
  };
@@ -46313,9 +46801,9 @@ function registerLiveActivityRoutes(router, options) {
46313
46801
  const auth = await authenticateRequest(ctx, paths);
46314
46802
  const body = await readJsonBody(ctx.req);
46315
46803
  const targetKind = readTargetKind(body);
46316
- const runId = normalizePattern(readString21(body, "run_id") ?? readString21(body, "runId"), RUN_ID_PATTERN);
46804
+ const runId = normalizePattern(readString22(body, "run_id") ?? readString22(body, "runId"), RUN_ID_PATTERN);
46317
46805
  const operationId = normalizePattern(
46318
- readString21(body, "operation_id") ?? readString21(body, "operationId"),
46806
+ readString22(body, "operation_id") ?? readString22(body, "operationId"),
46319
46807
  OPERATION_ID_PATTERN
46320
46808
  );
46321
46809
  if (targetKind === "run" && !runId) {
@@ -46361,7 +46849,7 @@ function registerLiveActivityRoutes(router, options) {
46361
46849
  });
46362
46850
  }
46363
46851
  function readTargetKind(body) {
46364
- const value = readString21(body, "target_kind") ?? readString21(body, "targetKind");
46852
+ const value = readString22(body, "target_kind") ?? readString22(body, "targetKind");
46365
46853
  return readTargetKindValue(value);
46366
46854
  }
46367
46855
  function readTargetKindValue(value) {
@@ -46383,21 +46871,21 @@ function readQueryValue(query, key) {
46383
46871
  return readQueryString(query[key]) ?? null;
46384
46872
  }
46385
46873
  function readApnsEnvironment(body) {
46386
- const value = readString21(body, "apns_environment") ?? readString21(body, "apnsEnvironment");
46874
+ const value = readString22(body, "apns_environment") ?? readString22(body, "apnsEnvironment");
46387
46875
  if (value === "sandbox" || value === "production") {
46388
46876
  return value;
46389
46877
  }
46390
46878
  throw new LinkHttpError(400, "apns_environment_invalid", "apns_environment must be sandbox or production");
46391
46879
  }
46392
46880
  function readLanguage2(body) {
46393
- const value = readString21(body, "language") ?? readString21(body, "preferred_language") ?? readString21(body, "preferredLanguage");
46881
+ const value = readString22(body, "language") ?? readString22(body, "preferred_language") ?? readString22(body, "preferredLanguage");
46394
46882
  if (!value) {
46395
46883
  return null;
46396
46884
  }
46397
46885
  return value.toLowerCase().startsWith("zh") ? "zh" : "en";
46398
46886
  }
46399
46887
  function readPrivacyLevel(body) {
46400
- const value = readString21(body, "privacy_level") ?? readString21(body, "privacyLevel");
46888
+ const value = readString22(body, "privacy_level") ?? readString22(body, "privacyLevel");
46401
46889
  if (value === "minimal" || value === "detailed") {
46402
46890
  return value;
46403
46891
  }
@@ -46405,7 +46893,7 @@ function readPrivacyLevel(body) {
46405
46893
  }
46406
46894
  function readRequiredString(body, keys, code) {
46407
46895
  for (const key of keys) {
46408
- const value = readString21(body, key);
46896
+ const value = readString22(body, key);
46409
46897
  if (value) {
46410
46898
  return value;
46411
46899
  }
@@ -46421,7 +46909,7 @@ function readRequiredPattern(body, keys, pattern, code) {
46421
46909
  }
46422
46910
  function readOptionalString2(body, keys, maxLength) {
46423
46911
  for (const key of keys) {
46424
- const value = readString21(body, key);
46912
+ const value = readString22(body, key);
46425
46913
  if (value) {
46426
46914
  return value.slice(0, maxLength);
46427
46915
  }
@@ -46433,7 +46921,7 @@ function normalizePattern(value, pattern) {
46433
46921
  }
46434
46922
  function readIso(body, keys) {
46435
46923
  for (const key of keys) {
46436
- const value = readString21(body, key);
46924
+ const value = readString22(body, key);
46437
46925
  if (!value) {
46438
46926
  continue;
46439
46927
  }