@senguoyun/dsh-arkme 3.0.72 → 3.0.73

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.
@@ -186,7 +186,7 @@ function objectValue$3(value) {
186
186
  function stringValue$3(value) {
187
187
  return typeof value === "string" ? value : "";
188
188
  }
189
- function numberValue$33(value) {
189
+ function numberValue$34(value) {
190
190
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
191
191
  }
192
192
  function stableRecordUid(namespace, key) {
@@ -249,13 +249,13 @@ function registerDSHAgentInputRecordSync(ctx, service, options = {}) {
249
249
  if (disposed) return;
250
250
  const event = objectValue$3(rawEvent);
251
251
  const sessionId = stringValue$3(objectValue$3(rawSession).id).trim();
252
- const eventSeq = Math.trunc(numberValue$33(event.seq));
252
+ const eventSeq = Math.trunc(numberValue$34(event.seq));
253
253
  if (sessionId === "" || eventSeq < 0) return;
254
254
  const text = dshAgentInputTextFromEvent(event);
255
255
  if (text === void 0) return;
256
256
  const key = `${sessionId}\0${String(eventSeq)}`;
257
257
  if (inFlight.has(key) || synced.has(key)) return;
258
- sync(key, dshAgentInputRecordUid(sessionId, eventSeq), text, numberValue$33(event.time), 1);
258
+ sync(key, dshAgentInputRecordUid(sessionId, eventSeq), text, numberValue$34(event.time), 1);
259
259
  };
260
260
  ctx.effect(() => {
261
261
  const source = sessionEventSource(ctx);
@@ -13106,7 +13106,7 @@ function projectRecordingSummaryModelConfig(value) {
13106
13106
  const nestedItem = objectValue$2(root.item);
13107
13107
  const item = Object.keys(nestedItem).length > 0 ? nestedItem : root;
13108
13108
  const seen = /* @__PURE__ */ new Set();
13109
- const options = listValue$29(item.allowed_route_options ?? item.allowedRouteOptions).flatMap((raw) => {
13109
+ const options = listValue$30(item.allowed_route_options ?? item.allowedRouteOptions).flatMap((raw) => {
13110
13110
  const option = objectValue$2(raw);
13111
13111
  const routeKey = stringValue$2(option.route_key ?? option.routeKey).trim();
13112
13112
  if (routeKey === "" || seen.has(routeKey)) return [];
@@ -13132,7 +13132,7 @@ function projectRecordingSummaryModelConfig(value) {
13132
13132
  function objectValue$2(value) {
13133
13133
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
13134
13134
  }
13135
- function listValue$29(value) {
13135
+ function listValue$30(value) {
13136
13136
  return Array.isArray(value) ? value : [];
13137
13137
  }
13138
13138
  function stringValue$2(value) {
@@ -13140,7 +13140,7 @@ function stringValue$2(value) {
13140
13140
  if (typeof value === "number" && Number.isFinite(value)) return String(value);
13141
13141
  return "";
13142
13142
  }
13143
- function numberValue$32(value) {
13143
+ function numberValue$33(value) {
13144
13144
  if (typeof value === "number" && Number.isFinite(value)) return value;
13145
13145
  if (typeof value === "string" && value.trim() !== "") {
13146
13146
  const parsed = Number(value);
@@ -13166,18 +13166,18 @@ function displayVersionTimestamp(value) {
13166
13166
  }
13167
13167
  function normalizeStructuredTimeline(value) {
13168
13168
  const root = objectValue$2(value);
13169
- return (Array.isArray(value) ? value : listValue$29(root.timelines ?? root.timeline ?? root.items)).map((raw, index) => {
13169
+ return (Array.isArray(value) ? value : listValue$30(root.timelines ?? root.timeline ?? root.items)).map((raw, index) => {
13170
13170
  const row = objectValue$2(raw);
13171
13171
  const rawRange = stringValue$2(row.time_range).trim();
13172
13172
  const rangeMatch = TIMELINE_HEADER.exec(rawRange);
13173
13173
  const startAt = stringValue$2(row.start_at ?? row.startAt ?? row.start_time).trim() || rangeMatch?.[1] || "";
13174
13174
  const endAt = stringValue$2(row.end_at ?? row.endAt ?? row.end_time).trim() || rangeMatch?.[2] || "";
13175
- const dialoguePoints = listValue$29(row.dialogue_points ?? row.dialogues).map(objectValue$2).map(normalizeTimelineDialoguePoint).filter((point) => point.speakerName !== "" || point.summary !== "" || point.quote !== "" || point.roleDescription !== "");
13176
- const participantValues = [...listValue$29(row.participants ?? row.roles).map((item) => {
13175
+ const dialoguePoints = listValue$30(row.dialogue_points ?? row.dialogues).map(objectValue$2).map(normalizeTimelineDialoguePoint).filter((point) => point.speakerName !== "" || point.summary !== "" || point.quote !== "" || point.roleDescription !== "");
13176
+ const participantValues = [...listValue$30(row.participants ?? row.roles).map((item) => {
13177
13177
  const participant = objectValue$2(item);
13178
13178
  return Object.keys(participant).length === 0 ? item : participant.name ?? participant.spk_name;
13179
13179
  }), ...dialoguePoints.map((item) => item.speakerName)];
13180
- const tags = listValue$29(row.event_tags ?? row.tags);
13180
+ const tags = listValue$30(row.event_tags ?? row.tags);
13181
13181
  const otherInfo = normalizeTimelineDetailItems(row.other_info ?? row.otherInfo);
13182
13182
  const positionNote = stringValue$2(row.position_note ?? row.positionNote).trim();
13183
13183
  const environmentNote = stringValue$2(row.environment_note ?? row.environmentNote).trim();
@@ -13210,7 +13210,7 @@ function normalizeStructuredTimeline(value) {
13210
13210
  }).filter((item) => item.startAt !== "" || item.endAt !== "" || item.title !== "" || item.description !== "");
13211
13211
  }
13212
13212
  function normalizeTimelineDialoguePoint(row) {
13213
- const rawData = listValue$29(row.raw_data_ls ?? row.rawData).map(objectValue$2);
13213
+ const rawData = listValue$30(row.raw_data_ls ?? row.rawData).map(objectValue$2);
13214
13214
  const quote = rawData.map((item) => stringValue$2(item.text ?? item.content).trim()).filter((value) => value !== "").join("\n");
13215
13215
  return {
13216
13216
  speakerName: stringValue$2(row.spk_name ?? row.speaker_name ?? row.speakerName).trim(),
@@ -13221,7 +13221,7 @@ function normalizeTimelineDialoguePoint(row) {
13221
13221
  };
13222
13222
  }
13223
13223
  function normalizeTimelineDetailItems(value) {
13224
- return listValue$29(value).map(objectValue$2).flatMap((item) => {
13224
+ return listValue$30(value).map(objectValue$2).flatMap((item) => {
13225
13225
  const label = stringValue$2(item.label ?? item.name).trim();
13226
13226
  const detail = stringValue$2(item.value ?? item.content ?? item.text).trim();
13227
13227
  return label !== "" && detail !== "" ? [{
@@ -13381,10 +13381,10 @@ function projectRecordingVersions(response, kind) {
13381
13381
  const expectedKind = kind === "timeline" ? 1 : 2;
13382
13382
  const versions = [];
13383
13383
  let sourceIndex = 0;
13384
- for (const rawVersion of listValue$29(root.audio_summary_ls ?? root.items ?? root.versions)) {
13384
+ for (const rawVersion of listValue$30(root.audio_summary_ls ?? root.items ?? root.versions)) {
13385
13385
  const version = objectValue$2(rawVersion);
13386
- if (numberValue$32(version.kind) !== expectedKind) continue;
13387
- const rawStatus = numberValue$32(version.status);
13386
+ if (numberValue$33(version.kind) !== expectedKind) continue;
13387
+ const rawStatus = numberValue$33(version.status);
13388
13388
  const content = stringValue$2(version.answer ?? version.content).trim();
13389
13389
  const snapshotValid = version.timeline_snapshot_valid !== false;
13390
13390
  let status = rawStatus === 1 ? "processing" : rawStatus === 2 ? "done" : "failed";
@@ -13398,7 +13398,7 @@ function projectRecordingVersions(response, kind) {
13398
13398
  status,
13399
13399
  selectable,
13400
13400
  ...version.continuation_available === true ? { continuationAvailable: true } : {},
13401
- generationStage: numberValue$32(version.generation_stage ?? version.stage),
13401
+ generationStage: numberValue$33(version.generation_stage ?? version.stage),
13402
13402
  generatedAtMillis: displayVersionTimestamp(version.update_at) ?? displayVersionTimestamp(version.create_at) ?? 0,
13403
13403
  modelDisplayName: stringValue$2(version.model_display_name ?? version.model_name).trim(),
13404
13404
  content,
@@ -13607,7 +13607,7 @@ var RecordingWorkflowService = class {
13607
13607
  };
13608
13608
  //#endregion
13609
13609
  //#region src/mention-metadata.ts
13610
- function listValue$28(value) {
13610
+ function listValue$29(value) {
13611
13611
  return Array.isArray(value) ? value : [];
13612
13612
  }
13613
13613
  function integerLikeValue$4(value) {
@@ -13628,12 +13628,12 @@ function arkmeMentionMetadataFromRecord(record, payload) {
13628
13628
  function arkmeMentionMetadataMentionsViewer(record, payload, viewerUserId, delegatedTeamId) {
13629
13629
  if (viewerUserId <= 0) return false;
13630
13630
  const metadata = arkmeMentionMetadataFromRecord(record, payload);
13631
- for (const rawMention of listValue$28(metadata.human_mentions ?? metadata.humanMentions)) {
13631
+ for (const rawMention of listValue$29(metadata.human_mentions ?? metadata.humanMentions)) {
13632
13632
  const mention = objectValue$4(rawMention);
13633
13633
  const mentionedUserId = integerLikeValue$4(mention.user_id ?? mention.userId);
13634
13634
  if (mentionedUserId === 0 || mentionedUserId === viewerUserId) return true;
13635
13635
  }
13636
- if (delegatedTeamId && listValue$28(metadata.team_mentions).some((raw) => objectValue$4(raw).team_id === delegatedTeamId)) return true;
13636
+ if (delegatedTeamId && listValue$29(metadata.team_mentions).some((raw) => objectValue$4(raw).team_id === delegatedTeamId)) return true;
13637
13637
  return false;
13638
13638
  }
13639
13639
  //#endregion
@@ -15720,13 +15720,13 @@ const GROUP_AVATAR_NEGATIVE_CACHE_TTL_MS = 6e4;
15720
15720
  const TOPIC_DISSOLVE_RECORD_CONCURRENCY = 6;
15721
15721
  const PRIVATE_REMARK_PAGE_LIMIT = 50;
15722
15722
  const PRIVATE_REMARK_MAX_PAGES = 20;
15723
- function numberValue$31(value) {
15723
+ function numberValue$32(value) {
15724
15724
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
15725
15725
  }
15726
15726
  function booleanValue$15(value) {
15727
15727
  return value === true;
15728
15728
  }
15729
- function listValue$27(value) {
15729
+ function listValue$28(value) {
15730
15730
  return Array.isArray(value) ? value : [];
15731
15731
  }
15732
15732
  function integerLikeValue$2(value) {
@@ -15767,12 +15767,12 @@ function arkmeChatDirectoryMetadataFromBundle(bundle, fallbackSubjectUid = "") {
15767
15767
  return {
15768
15768
  ...subjectUid === "" ? {} : { subjectUid },
15769
15769
  activityAtMillis: arkmeChatSortActiveAt(bundle, chatSession),
15770
- latestSequence: Math.max(0, numberValue$31(unread.session_last_seq ?? chatSession.last_seq))
15770
+ latestSequence: Math.max(0, numberValue$32(unread.session_last_seq ?? chatSession.last_seq))
15771
15771
  };
15772
15772
  }
15773
15773
  function arkmeChatSortActiveAt(bundle, chatSession) {
15774
- const projected = numberValue$31(bundle.sort_active_at);
15775
- return Math.max(0, projected > 0 ? projected : numberValue$31(bundle.last_active_at ?? chatSession.last_active_at));
15774
+ const projected = numberValue$32(bundle.sort_active_at);
15775
+ return Math.max(0, projected > 0 ? projected : numberValue$32(bundle.last_active_at ?? chatSession.last_active_at));
15776
15776
  }
15777
15777
  function backendBooleanValue(value) {
15778
15778
  if (value === null || value === void 0) return void 0;
@@ -15865,13 +15865,13 @@ function normalizedConversationText(values) {
15865
15865
  return "";
15866
15866
  }
15867
15867
  function conversationMediaMarker(values) {
15868
- const displayItems = values.flatMap((value) => [...listValue$27(value.media_display_items), ...listValue$27(value.mediaDisplayItems)]).map(objectValue$4);
15868
+ const displayItems = values.flatMap((value) => [...listValue$28(value.media_display_items), ...listValue$28(value.mediaDisplayItems)]).map(objectValue$4);
15869
15869
  const displayByAsset = /* @__PURE__ */ new Map();
15870
15870
  for (const item of displayItems) {
15871
15871
  const fileAssetUid = stringValue$4(item.file_asset_uid ?? item.fileAssetUid).trim();
15872
15872
  if (fileAssetUid !== "") displayByAsset.set(fileAssetUid, item);
15873
15873
  }
15874
- const mediaRefs = values.flatMap((value) => [...listValue$27(value.media_refs), ...listValue$27(value.mediaRefs)]).map(objectValue$4);
15874
+ const mediaRefs = values.flatMap((value) => [...listValue$28(value.media_refs), ...listValue$28(value.mediaRefs)]).map(objectValue$4);
15875
15875
  const attachments = (mediaRefs.length > 0 ? mediaRefs.map((ref) => ({
15876
15876
  ...displayByAsset.get(stringValue$4(ref.file_asset_uid ?? ref.fileAssetUid).trim()) ?? {},
15877
15877
  ...ref
@@ -16206,11 +16206,11 @@ var SourceService = class {
16206
16206
  lane: "background-read",
16207
16207
  key: `private-chat-viewer-labels:${pageCursor === void 0 ? "first" : String(page)}`
16208
16208
  });
16209
- for (const raw of listValue$27(data.items)) {
16209
+ for (const raw of listValue$28(data.items)) {
16210
16210
  const bundle = objectValue$4(raw);
16211
- const sessionKind = numberValue$31(objectValue$4(bundle.session).session_kind);
16211
+ const sessionKind = numberValue$32(objectValue$4(bundle.session).session_kind);
16212
16212
  if (sessionKind !== 1 && sessionKind !== 3) continue;
16213
- const targetUserId = numberValue$31(objectValue$4(bundle.private_counterpart).user_id);
16213
+ const targetUserId = numberValue$32(objectValue$4(bundle.private_counterpart).user_id);
16214
16214
  if (!remaining.has(targetUserId)) continue;
16215
16215
  const supplement = objectValue$4(bundle.private_supplement);
16216
16216
  const counterpart = objectValue$4(bundle.private_counterpart);
@@ -16248,7 +16248,7 @@ var SourceService = class {
16248
16248
  key: `private-remarks:${String(offset)}`,
16249
16249
  failureCooldownMs: 2e3
16250
16250
  });
16251
- const rawItems = listValue$27(data.items);
16251
+ const rawItems = listValue$28(data.items);
16252
16252
  for (const value of rawItems) {
16253
16253
  const raw = objectValue$4(value);
16254
16254
  const targetUserId = recordOwnerId(raw.user_id);
@@ -16273,9 +16273,9 @@ var SourceService = class {
16273
16273
  key: `private-remarks:direct:${pageCursor === void 0 ? "first" : String(page)}`,
16274
16274
  failureCooldownMs: 2e3
16275
16275
  });
16276
- for (const value of listValue$27(data.items)) {
16276
+ for (const value of listValue$28(data.items)) {
16277
16277
  const bundle = objectValue$4(value);
16278
- const sessionKind = numberValue$31(objectValue$4(bundle.session).session_kind);
16278
+ const sessionKind = numberValue$32(objectValue$4(bundle.session).session_kind);
16279
16279
  if (sessionKind !== 1 && sessionKind !== 3) continue;
16280
16280
  const targetUserId = recordOwnerId(objectValue$4(bundle.private_counterpart).user_id);
16281
16281
  if (!remaining.has(targetUserId)) continue;
@@ -16325,11 +16325,11 @@ var SourceService = class {
16325
16325
  this.invalidateSourceListCache(session.userId, "send_to_self");
16326
16326
  });
16327
16327
  const topicUid = stringValue$4(created.topic_uid).trim();
16328
- if (topicUid === "" || numberValue$31(created.status) !== 1) throw new ArkmePluginError("topic-create-contract-invalid", "主题创建响应不完整", true, 502);
16328
+ if (topicUid === "" || numberValue$32(created.status) !== 1) throw new ArkmePluginError("topic-create-contract-invalid", "主题创建响应不完整", true, 502);
16329
16329
  const sourceRef = await this.sealSourceRef(session.userId, "topic", topicUid, title);
16330
16330
  const topicHierarchyKey = await this.topicHierarchyKey(session.userId, topicUid);
16331
16331
  if (parentTopicUid !== void 0) try {
16332
- if (numberValue$31(objectValue$4((await this.runtime.authenticatedPost("/api/v1/topics/hierarchy/bind", {
16332
+ if (numberValue$32(objectValue$4((await this.runtime.authenticatedPost("/api/v1/topics/hierarchy/bind", {
16333
16333
  parent_topic_uid: parentTopicUid,
16334
16334
  child_topic_uid: topicUid
16335
16335
  }, session)).relation).status) !== 1) throw new ArkmePluginError("topic-hierarchy-bind-contract-invalid", "子主题层级响应不完整", true, 502);
@@ -16630,7 +16630,7 @@ var SourceService = class {
16630
16630
  parent_topic_uid: nextParentTopicUid ?? "",
16631
16631
  insert_before_topic_uid: ""
16632
16632
  }, session);
16633
- return stringValue$4(moved.topic_uid).trim() === topicUid && stringValue$4(moved.parent_topic_uid).trim() === (nextParentTopicUid ?? "") && numberValue$31(moved.sibling_order) > 0;
16633
+ return stringValue$4(moved.topic_uid).trim() === topicUid && stringValue$4(moved.parent_topic_uid).trim() === (nextParentTopicUid ?? "") && numberValue$32(moved.sibling_order) > 0;
16634
16634
  }
16635
16635
  async rollbackDissolvedTopicChildren(children, topicUid, parentTopicUid, session) {
16636
16636
  for (const child of [...children].reverse()) await this.moveTopicHierarchyForDissolve(child.topic.ownerRef, parentTopicUid ?? "", topicUid, session).catch(() => false);
@@ -16659,7 +16659,7 @@ var SourceService = class {
16659
16659
  }, session);
16660
16660
  const movedTopicUid = stringValue$4(moved.topic_uid).trim();
16661
16661
  const movedParentUid = stringValue$4(moved.parent_topic_uid).trim();
16662
- const siblingOrder = numberValue$31(moved.sibling_order);
16662
+ const siblingOrder = numberValue$32(moved.sibling_order);
16663
16663
  if (movedTopicUid !== topic.ownerRef || movedParentUid !== (nextParentUid ?? "") || siblingOrder <= 0) throw new ArkmePluginError("topic-hierarchy-move-contract-invalid", "主题移动响应不完整,请刷新后重试", true, 502);
16664
16664
  this.invalidateSourceListCache(session.userId, "send_to_self");
16665
16665
  return {
@@ -16682,11 +16682,11 @@ var SourceService = class {
16682
16682
  signal?.throwIfAborted();
16683
16683
  const items = [];
16684
16684
  const seen = /* @__PURE__ */ new Set();
16685
- for (const raw of listValue$27(data.items)) {
16685
+ for (const raw of listValue$28(data.items)) {
16686
16686
  const entry = objectValue$4(raw);
16687
16687
  const core = objectValue$4(entry.topic_core);
16688
16688
  if (arkmePrivacyLockedTopic(entry) || core.status !== 1) continue;
16689
- const topicKind = numberValue$31(core.kind) || 1;
16689
+ const topicKind = numberValue$32(core.kind) || 1;
16690
16690
  if (!arkmeSourceAllowsUserWrite({
16691
16691
  kind: "topic",
16692
16692
  topicKind
@@ -16700,7 +16700,7 @@ var SourceService = class {
16700
16700
  kind: "topic",
16701
16701
  topicKind,
16702
16702
  displayName: title,
16703
- activeAtMillis: numberValue$31(core.update_at),
16703
+ activeAtMillis: numberValue$32(core.update_at),
16704
16704
  unreadCount: 0,
16705
16705
  ...typeof recordCount === "number" && Number.isSafeInteger(recordCount) && recordCount >= 0 ? { recordCount } : {},
16706
16706
  sourceRef: await this.sealSourceRef(session.userId, "topic", topicUid, title),
@@ -16708,7 +16708,7 @@ var SourceService = class {
16708
16708
  });
16709
16709
  }
16710
16710
  const pageCursor = objectValue$4(data.next_page_cursor ?? data.next_cursor);
16711
- const offset = numberValue$31(data.next_offset);
16711
+ const offset = numberValue$32(data.next_offset);
16712
16712
  const hasCursor = Object.keys(pageCursor).length > 0;
16713
16713
  if (data.has_more === true && !hasCursor && offset <= 0) throw new ArkmePluginError("topic-candidates-incomplete", "主题列表加载不完整,请重试", true, 502);
16714
16714
  return {
@@ -16936,7 +16936,7 @@ var SourceService = class {
16936
16936
  options.signal?.throwIfAborted();
16937
16937
  const cached = summaryResult.status === "rejected" || latestRecordsResult.status === "rejected" ? await this.runtime.stateStore.cachedSnapshot(session.userId).catch(() => void 0) : void 0;
16938
16938
  const defaultRecordCount = summaryResult.status === "fulfilled" ? summaryResult.value.recordCount : cached?.summary?.recordCount;
16939
- const defaultLatestRecord = latestRecordsResult.status === "fulfilled" ? listValue$27(latestRecordsResult.value.items).map((raw) => this.recordReader.isDSHAgentInput?.(raw) === true || this.recordReader.isPrivacyLocked?.(raw) === true || arkmePrivacyLockedRecord(raw) || lockedRecordUids.has(stringValue$4(objectValue$4(raw).record_uid ?? objectValue$4(objectValue$4(raw).record_core).record_uid).trim()) ? void 0 : this.recordReader.recordItem(raw)).find((item) => item !== void 0) : cached?.items.reduce((latest, item) => item.creationSource === 3 ? latest : latest === void 0 || item.sendAtMillis > latest.sendAtMillis ? item : latest, void 0);
16939
+ const defaultLatestRecord = latestRecordsResult.status === "fulfilled" ? listValue$28(latestRecordsResult.value.items).map((raw) => this.recordReader.isDSHAgentInput?.(raw) === true || this.recordReader.isPrivacyLocked?.(raw) === true || arkmePrivacyLockedRecord(raw) || lockedRecordUids.has(stringValue$4(objectValue$4(raw).record_uid ?? objectValue$4(objectValue$4(raw).record_core).record_uid).trim()) ? void 0 : this.recordReader.recordItem(raw)).find((item) => item !== void 0) : cached?.items.reduce((latest, item) => item.creationSource === 3 ? latest : latest === void 0 || item.sendAtMillis > latest.sendAtMillis ? item : latest, void 0);
16940
16940
  const defaultLatestPreview = defaultLatestRecord === void 0 ? "" : arkmeTimelineConversationPreview(defaultLatestRecord, "");
16941
16941
  const defaultCategory = {
16942
16942
  sourceRef: await this.sealSourceRef(session.userId, "default_category", "uncategorized", "未分类"),
@@ -16952,25 +16952,25 @@ var SourceService = class {
16952
16952
  const parentTopicUidByChild = /* @__PURE__ */ new Map();
16953
16953
  const siblingOrderByChild = /* @__PURE__ */ new Map();
16954
16954
  const childTopicUidsByParent = /* @__PURE__ */ new Map();
16955
- for (const raw of listValue$27(hierarchyData?.relations)) {
16955
+ for (const raw of listValue$28(hierarchyData?.relations)) {
16956
16956
  const relation = objectValue$4(raw);
16957
- if (numberValue$31(relation.rel_kind) !== 1 || numberValue$31(relation.status) !== 1) continue;
16957
+ if (numberValue$32(relation.rel_kind) !== 1 || numberValue$32(relation.status) !== 1) continue;
16958
16958
  const parentTopicUid = stringValue$4(relation.parent_topic_uid).trim();
16959
16959
  const childTopicUid = stringValue$4(relation.child_topic_uid).trim();
16960
16960
  if (parentTopicUid === "" || childTopicUid === "" || parentTopicUid === childTopicUid) continue;
16961
16961
  parentTopicUidByChild.set(childTopicUid, parentTopicUid);
16962
- siblingOrderByChild.set(childTopicUid, numberValue$31(relation.sibling_order));
16962
+ siblingOrderByChild.set(childTopicUid, numberValue$32(relation.sibling_order));
16963
16963
  const children = childTopicUidsByParent.get(parentTopicUid) ?? /* @__PURE__ */ new Set();
16964
16964
  children.add(childTopicUid);
16965
16965
  childTopicUidsByParent.set(parentTopicUid, children);
16966
16966
  }
16967
- for (const raw of listValue$27(data.items)) {
16967
+ for (const raw of listValue$28(data.items)) {
16968
16968
  const item = objectValue$4(raw);
16969
16969
  if (arkmePrivacyLockedTopic(item)) continue;
16970
16970
  const core = objectValue$4(item.topic_core);
16971
- if (numberValue$31(core.kind) === 3) continue;
16971
+ if (numberValue$32(core.kind) === 3) continue;
16972
16972
  const status = core.status ?? item.status;
16973
- if (status !== void 0 && numberValue$31(status) !== 1) continue;
16973
+ if (status !== void 0 && numberValue$32(status) !== 1) continue;
16974
16974
  const summary = objectValue$4(item.summary);
16975
16975
  const latest = objectValue$4(item.latest_record_core);
16976
16976
  const parent = objectValue$4(core.parent_topic_core ?? core.parent_topic ?? item.parent_topic_core ?? item.parent_topic);
@@ -16981,14 +16981,14 @@ var SourceService = class {
16981
16981
  const parentTopicUid = stringValue$4(parentTopicUidByChild.get(topicUid) ?? core.parent_topic_uid ?? core.parent_uid ?? item.parent_topic_uid ?? item.parent_uid ?? parent.topic_uid ?? parent.uid).trim();
16982
16982
  topicDescriptors.push({
16983
16983
  topicUid,
16984
- topicKind: numberValue$31(core.kind) || 1,
16984
+ topicKind: numberValue$32(core.kind) || 1,
16985
16985
  ...parentTopicUid === "" || parentTopicUid === topicUid ? {} : { parentTopicUid },
16986
- siblingOrder: numberValue$31(siblingOrderByChild.get(topicUid) ?? core.sibling_order ?? item.sibling_order),
16986
+ siblingOrder: numberValue$32(siblingOrderByChild.get(topicUid) ?? core.sibling_order ?? item.sibling_order),
16987
16987
  title,
16988
16988
  latestPreview: arkmeChatConversationPreview(latest, session.userId),
16989
- latestMessageAtMillis: numberValue$31(latest.send_at ?? summary.latest_send_at),
16990
- activeAtMillis: numberValue$31(latest.send_at ?? summary.latest_send_at ?? core.update_at),
16991
- recordCount: numberValue$31(summary.record_count)
16989
+ latestMessageAtMillis: numberValue$32(latest.send_at ?? summary.latest_send_at),
16990
+ activeAtMillis: numberValue$32(latest.send_at ?? summary.latest_send_at ?? core.update_at),
16991
+ recordCount: numberValue$32(summary.record_count)
16992
16992
  });
16993
16993
  }
16994
16994
  const sourceRefByTopicUid = /* @__PURE__ */ new Map();
@@ -17029,12 +17029,12 @@ var SourceService = class {
17029
17029
  unreadCount: 0
17030
17030
  };
17031
17031
  const nextPageCursor = objectValue$4(data.next_page_cursor ?? data.next_cursor);
17032
- const nextOffset = numberValue$31(data.next_offset);
17032
+ const nextOffset = numberValue$32(data.next_offset);
17033
17033
  const preferredPageCursor = Object.keys(nextPageCursor).length > 0 ? nextPageCursor : void 0;
17034
17034
  const preferredOffset = preferredPageCursor === void 0 && nextOffset > 0 ? nextOffset : void 0;
17035
17035
  const hasMore = data.has_more === true && (preferredPageCursor !== void 0 || preferredOffset !== void 0);
17036
17036
  const totalValue = data.total ?? data.total_count;
17037
- const total = totalValue === void 0 ? void 0 : Math.max(0, numberValue$31(totalValue));
17037
+ const total = totalValue === void 0 ? void 0 : Math.max(0, numberValue$32(totalValue));
17038
17038
  return {
17039
17039
  directory,
17040
17040
  items: [
@@ -17066,7 +17066,7 @@ var SourceService = class {
17066
17066
  const chatSessionUidByIndex = /* @__PURE__ */ new Map();
17067
17067
  const privateUserIdByIndex = /* @__PURE__ */ new Map();
17068
17068
  const groupSessionUidByIndex = /* @__PURE__ */ new Map();
17069
- for (const raw of listValue$27(data.items)) {
17069
+ for (const raw of listValue$28(data.items)) {
17070
17070
  const bundle = objectValue$4(raw);
17071
17071
  const chatSession = objectValue$4(bundle.session);
17072
17072
  const counterpart = objectValue$4(bundle.private_counterpart);
@@ -17077,9 +17077,9 @@ var SourceService = class {
17077
17077
  const unread = objectValue$4(bundle.unread_snapshot);
17078
17078
  const currentPolicy = objectValue$4(bundle.current_policy);
17079
17079
  const attention = projectArkmeChatAttention(unread.unread_count, currentPolicy);
17080
- const isPinned = numberValue$31(currentPolicy.pin_state) === 2;
17080
+ const isPinned = numberValue$32(currentPolicy.pin_state) === 2;
17081
17081
  const uid = stringValue$4(chatSession.chat_session_uid).trim();
17082
- const sessionKind = numberValue$31(chatSession.session_kind);
17082
+ const sessionKind = numberValue$32(chatSession.session_kind);
17083
17083
  const kind = sessionKind === 2 ? "group_chat" : sessionKind === 1 || sessionKind === 3 ? "private_chat" : void 0;
17084
17084
  if (uid === "" || kind === void 0) continue;
17085
17085
  const cached = this.chatSourceCache.get(`${String(session.userId)}:${uid}`);
@@ -17088,7 +17088,7 @@ var SourceService = class {
17088
17088
  const activity = kind === "group_chat" ? arkmeChatActivityPreview(bundle, session.userId) : {};
17089
17089
  const previewUnavailable = latestRecord.status === 3 || latestRecord.status === "unavailable";
17090
17090
  const previewMissing = latestRecord.status === 2 || latestRecord.status === 4 || latestRecord.status === "missing";
17091
- const latestSequence = numberValue$31(unread.session_last_seq ?? chatSession.last_seq);
17091
+ const latestSequence = numberValue$32(unread.session_last_seq ?? chatSession.last_seq);
17092
17092
  const preview = activity.latestPreview ?? (previewUnavailable ? cached?.latestSequence === latestSequence ? cached.latestPreview ?? "" : "" : previewMissing ? "" : arkmeChatConversationPreview(latestRecord, session.userId));
17093
17093
  const unreadCount = attention.unreadCount;
17094
17094
  const latestRelation = objectValue$4(latestPreview.relation);
@@ -17109,7 +17109,7 @@ var SourceService = class {
17109
17109
  }),
17110
17110
  sourceKey: await this.chatDirectorySourceKey(session.userId, uid),
17111
17111
  kind,
17112
- directMessageAdmissionApplicable: sessionKind === 1 && numberValue$31(counterpart.user_id) > 0,
17112
+ directMessageAdmissionApplicable: sessionKind === 1 && numberValue$32(counterpart.user_id) > 0,
17113
17113
  displayName,
17114
17114
  ...kind === "private_chat" && privateNickname !== "" ? { privateNickname } : {},
17115
17115
  ...kind === "private_chat" && cached?.avatarRef !== void 0 ? { avatarRef: cached.avatarRef } : {},
@@ -17121,16 +17121,16 @@ var SourceService = class {
17121
17121
  activeAtMillis: arkmeChatSortActiveAt(bundle, chatSession),
17122
17122
  ...attention,
17123
17123
  ...hasUnreadMention === void 0 ? {} : { hasUnreadMention },
17124
- readSequence: numberValue$31(unread.read_seq),
17124
+ readSequence: numberValue$32(unread.read_seq),
17125
17125
  isPinned,
17126
- chatPolicyUpdatedAtMillis: numberValue$31(currentPolicy.update_at),
17127
- chatNotificationPolicyUpdatedAtMillis: numberValue$31(currentPolicy.update_at),
17128
- ...numberValue$31(unread.session_last_seq ?? chatSession.last_seq) > 0 ? { latestSequence: numberValue$31(unread.session_last_seq ?? chatSession.last_seq) } : {}
17126
+ chatPolicyUpdatedAtMillis: numberValue$32(currentPolicy.update_at),
17127
+ chatNotificationPolicyUpdatedAtMillis: numberValue$32(currentPolicy.update_at),
17128
+ ...numberValue$32(unread.session_last_seq ?? chatSession.last_seq) > 0 ? { latestSequence: numberValue$32(unread.session_last_seq ?? chatSession.last_seq) } : {}
17129
17129
  }));
17130
17130
  const itemIndex = items.push(item) - 1;
17131
17131
  chatSessionUidByIndex.set(itemIndex, uid);
17132
17132
  if (kind === "private_chat") {
17133
- const counterpartUserId = numberValue$31(counterpart.user_id);
17133
+ const counterpartUserId = numberValue$32(counterpart.user_id);
17134
17134
  if (Number.isSafeInteger(counterpartUserId) && counterpartUserId > 0) {
17135
17135
  item.peerUserId = counterpartUserId;
17136
17136
  item.peerMemberType = arkmePeerMemberType(counterpart.member_type);
@@ -17149,7 +17149,7 @@ var SourceService = class {
17149
17149
  }
17150
17150
  const hasMore = data.has_more === true;
17151
17151
  const totalValue = data.total ?? data.total_count;
17152
- const total = totalValue === void 0 ? void 0 : Math.max(0, numberValue$31(totalValue));
17152
+ const total = totalValue === void 0 ? void 0 : Math.max(0, numberValue$32(totalValue));
17153
17153
  const nextPageCursor = objectValue$4(data.next_page_cursor);
17154
17154
  return {
17155
17155
  directory,
@@ -17229,16 +17229,16 @@ var SourceService = class {
17229
17229
  if (index !== void 0) authoritativeGroupIndices.add(index);
17230
17230
  }
17231
17231
  const snapshotsByUid = /* @__PURE__ */ new Map();
17232
- for (const raw of listValue$27(data.items)) {
17232
+ for (const raw of listValue$28(data.items)) {
17233
17233
  const snapshot = objectValue$4(raw);
17234
17234
  const uid = stringValue$4(snapshot.chat_session_uid).trim();
17235
17235
  const index = indexByGroupUid.get(uid);
17236
17236
  if (index === void 0 || !groupUids.includes(uid)) continue;
17237
- const memberIds = listValue$27(snapshot.members).map((member) => numberValue$31(objectValue$4(member).user_id)).filter((userId) => Number.isSafeInteger(userId) && userId > 0).slice(0, 5);
17237
+ const memberIds = listValue$28(snapshot.members).map((member) => numberValue$32(objectValue$4(member).user_id)).filter((userId) => Number.isSafeInteger(userId) && userId > 0).slice(0, 5);
17238
17238
  const projection = {
17239
- memberCount: Math.max(0, Math.trunc(numberValue$31(snapshot.member_count))),
17239
+ memberCount: Math.max(0, Math.trunc(numberValue$32(snapshot.member_count))),
17240
17240
  strategy: stringValue$4(snapshot.strategy).trim(),
17241
- computedAtMillis: numberValue$31(snapshot.computed_at),
17241
+ computedAtMillis: numberValue$32(snapshot.computed_at),
17242
17242
  memberIds
17243
17243
  };
17244
17244
  snapshotsByUid.set(uid, projection);
@@ -17406,7 +17406,7 @@ var SourceService = class {
17406
17406
  const kind = parsed.kind;
17407
17407
  const result = {
17408
17408
  version: 1,
17409
- userId: numberValue$31(parsed.userId),
17409
+ userId: numberValue$32(parsed.userId),
17410
17410
  kind: isSourceKind(kind) ? kind : "default_category",
17411
17411
  ownerRef: stringValue$4(parsed.ownerRef).trim(),
17412
17412
  displayName: isSourceKind(kind) && kind === "default_category" ? "未分类" : stringValue$4(parsed.displayName).trim(),
@@ -17418,8 +17418,8 @@ var SourceService = class {
17418
17418
  const sidebarSubjectUid = stringValue$4(parsed.sidebarSubjectUid).trim();
17419
17419
  return {
17420
17420
  ...sidebarSubjectUid === "" ? {} : { sidebarSubjectUid },
17421
- conversationListActivityAtMillis: Math.max(0, numberValue$31(parsed.conversationListActivityAtMillis)),
17422
- conversationListLatestSequence: Math.max(0, numberValue$31(parsed.conversationListLatestSequence))
17421
+ conversationListActivityAtMillis: Math.max(0, numberValue$32(parsed.conversationListActivityAtMillis)),
17422
+ conversationListLatestSequence: Math.max(0, numberValue$32(parsed.conversationListLatestSequence))
17423
17423
  };
17424
17424
  })() : {}
17425
17425
  };
@@ -17496,16 +17496,16 @@ var SourceService = class {
17496
17496
  const unread = objectValue$4(bundle.unread_snapshot);
17497
17497
  const currentPolicy = objectValue$4(bundle.current_policy);
17498
17498
  const attention = projectArkmeChatAttention(unread.unread_count, currentPolicy, cached?.isMuted ?? false);
17499
- const isPinned = numberValue$31(currentPolicy.pin_state) === 2;
17499
+ const isPinned = numberValue$32(currentPolicy.pin_state) === 2;
17500
17500
  const uid = stringValue$4(chatSession.chat_session_uid).trim();
17501
- const sessionKind = numberValue$31(chatSession.session_kind);
17502
- const peerUserId = numberValue$31(counterpart.user_id);
17501
+ const sessionKind = numberValue$32(chatSession.session_kind);
17502
+ const peerUserId = numberValue$32(counterpart.user_id);
17503
17503
  const kind = sessionKind === 2 ? "group_chat" : sessionKind === 1 || sessionKind === 3 ? "private_chat" : void 0;
17504
17504
  if (uid === "" || kind === void 0) throw new Error("invalid chat display snapshot");
17505
17505
  const privateNickname = stringValue$4(supplement.counterpart_name_snapshot).trim() || stringValue$4(counterpart.display_name_snapshot).trim();
17506
17506
  const displayName = (kind === "private_chat" ? stringValue$4(supplement.remark).trim() || privateNickname || (sessionKind === 3 ? stringValue$4(supplement.pending_name).trim() : "") || cached?.displayName || stringValue$4(counterpart.visible_phone).trim() : stringValue$4(chatSession.title)).trim() || cached?.displayName || "未命名会话";
17507
17507
  const latestItem = [...timelineItems].sort((left, right) => (right.sequence ?? 0) - (left.sequence ?? 0))[0];
17508
- const snapshotSequence = numberValue$31(unread.session_last_seq ?? chatSession.last_seq);
17508
+ const snapshotSequence = numberValue$32(unread.session_last_seq ?? chatSession.last_seq);
17509
17509
  const previewSnapshot = options.previewSnapshot === true && snapshotSequence >= Math.max(cached?.latestSequence ?? 0, latestItem?.sequence ?? 0);
17510
17510
  let latestPreview = latestItem === void 0 ? cached?.latestPreview : arkmeTimelineConversationPreview(latestItem);
17511
17511
  if (previewSnapshot) {
@@ -17520,7 +17520,7 @@ var SourceService = class {
17520
17520
  activity.latestActivityKind = "record";
17521
17521
  latestPreview = arkmeTimelineConversationPreview(latestItem);
17522
17522
  }
17523
- const latestSequence = Math.max(numberValue$31(unread.session_last_seq ?? chatSession.last_seq), latestItem?.sequence ?? 0, cached?.latestSequence ?? 0);
17523
+ const latestSequence = Math.max(numberValue$32(unread.session_last_seq ?? chatSession.last_seq), latestItem?.sequence ?? 0, cached?.latestSequence ?? 0);
17524
17524
  const unreadCount = attention.unreadCount;
17525
17525
  const latestMentionsViewer = latestItem?.isMe === false && latestItem.mentionsViewer === true;
17526
17526
  const backendMentionState = chatUnreadMentionState(unread);
@@ -17539,7 +17539,7 @@ var SourceService = class {
17539
17539
  }),
17540
17540
  sourceKey: await this.chatDirectorySourceKey(session.userId, uid),
17541
17541
  kind,
17542
- directMessageAdmissionApplicable: sessionKind === 1 && numberValue$31(counterpart.user_id) > 0,
17542
+ directMessageAdmissionApplicable: sessionKind === 1 && numberValue$32(counterpart.user_id) > 0,
17543
17543
  displayName,
17544
17544
  ...kind === "private_chat" && privateNickname !== "" ? { privateNickname } : {},
17545
17545
  ...kind === "private_chat" && Number.isSafeInteger(peerUserId) && peerUserId > 0 ? { peerUserId } : {},
@@ -17555,8 +17555,8 @@ var SourceService = class {
17555
17555
  ...Number.isSafeInteger(unread.read_seq) && Number(unread.read_seq) >= 0 ? { readSequence: Number(unread.read_seq) } : {},
17556
17556
  ...hasUnreadMention === void 0 ? {} : { hasUnreadMention },
17557
17557
  isPinned,
17558
- chatPolicyUpdatedAtMillis: numberValue$31(currentPolicy.update_at),
17559
- chatNotificationPolicyUpdatedAtMillis: numberValue$31(currentPolicy.update_at),
17558
+ chatPolicyUpdatedAtMillis: numberValue$32(currentPolicy.update_at),
17559
+ chatNotificationPolicyUpdatedAtMillis: numberValue$32(currentPolicy.update_at),
17560
17560
  ...latestSequence > 0 ? { latestSequence } : {}
17561
17561
  }));
17562
17562
  }
@@ -17584,7 +17584,7 @@ var SourceService = class {
17584
17584
  const value = this.decodeCursor(cursor);
17585
17585
  if (value.directory !== "send_to_self") throw new ArkmePluginError("source-cursor-invalid", "发给自己的主题分页游标无效", false);
17586
17586
  const pageCursor = objectValue$4(value.pageCursor);
17587
- const offset = numberValue$31(value.offset);
17587
+ const offset = numberValue$32(value.offset);
17588
17588
  if (Object.keys(pageCursor).length === 0 && offset <= 0) throw new ArkmePluginError("source-cursor-invalid", "发给自己的主题分页游标无效", false);
17589
17589
  return {
17590
17590
  ...Object.keys(pageCursor).length === 0 ? {} : { pageCursor },
@@ -17609,22 +17609,22 @@ function notificationRetryDelay(attempts) {
17609
17609
  if (attempts <= 4) return 200;
17610
17610
  return Math.min(5e3, 500 * 2 ** Math.min(4, attempts - 5));
17611
17611
  }
17612
- function numberValue$30(value) {
17612
+ function numberValue$31(value) {
17613
17613
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
17614
17614
  }
17615
- function listValue$26(value) {
17615
+ function listValue$27(value) {
17616
17616
  return Array.isArray(value) ? value : [];
17617
17617
  }
17618
17618
  function timelineNotificationIdentities(data) {
17619
- return listValue$26(data.items).flatMap((raw) => {
17619
+ return listValue$27(data.items).flatMap((raw) => {
17620
17620
  const item = objectValue$4(raw);
17621
17621
  const relation = objectValue$4(item.relation);
17622
17622
  const payload = objectValue$4(objectValue$4(item.record).payload);
17623
17623
  const identity = {
17624
17624
  relationUid: stringValue$4(relation.rel_uid ?? relation.relUid).trim(),
17625
17625
  itemUid: stringValue$4(relation.record_uid ?? relation.recordUid ?? payload.record_uid ?? payload.recordUid).trim(),
17626
- sequence: numberValue$30(relation.seq ?? relation.sequence),
17627
- senderUserId: numberValue$30(relation.sender_user_id ?? relation.senderUserId)
17626
+ sequence: numberValue$31(relation.seq ?? relation.sequence),
17627
+ senderUserId: numberValue$31(relation.sender_user_id ?? relation.senderUserId)
17628
17628
  };
17629
17629
  return identity.itemUid !== "" && Number.isSafeInteger(identity.sequence) && identity.sequence > 0 && Number.isSafeInteger(identity.senderUserId) && identity.senderUserId > 0 ? [identity] : [];
17630
17630
  });
@@ -17634,13 +17634,13 @@ function groupInteractionPeers(data, viewerUserId, afterSequence, throughSequenc
17634
17634
  if (throughSequence <= afterSequence) return void 0;
17635
17635
  const covered = /* @__PURE__ */ new Set();
17636
17636
  const peers = /* @__PURE__ */ new Set();
17637
- for (const raw of listValue$26(data.items)) {
17637
+ for (const raw of listValue$27(data.items)) {
17638
17638
  const item = objectValue$4(raw);
17639
17639
  const relation = objectValue$4(item.relation);
17640
- const sequence = numberValue$30(relation.seq ?? relation.sequence);
17640
+ const sequence = numberValue$31(relation.seq ?? relation.sequence);
17641
17641
  if (!Number.isSafeInteger(sequence) || sequence <= 0) return void 0;
17642
17642
  if (sequence <= afterSequence || sequence > throughSequence) continue;
17643
- const sender = numberValue$30(relation.sender_user_id);
17643
+ const sender = numberValue$31(relation.sender_user_id);
17644
17644
  const record = objectValue$4(item.record);
17645
17645
  const payload = objectValue$4(record.payload);
17646
17646
  if (!Number.isSafeInteger(sender) || sender <= 0 || record.status !== 1 || Object.keys(payload).length === 0) return void 0;
@@ -17648,7 +17648,7 @@ function groupInteractionPeers(data, viewerUserId, afterSequence, throughSequenc
17648
17648
  const metadata = arkmeMentionMetadataFromRecord(record, payload);
17649
17649
  const mentions = metadata.human_mentions ?? metadata.humanMentions;
17650
17650
  if (mentions !== void 0 && !Array.isArray(mentions)) return void 0;
17651
- for (const rawMention of listValue$26(mentions)) {
17651
+ for (const rawMention of listValue$27(mentions)) {
17652
17652
  const mention = objectValue$4(rawMention);
17653
17653
  const target = mention.user_id ?? mention.userId;
17654
17654
  if (typeof target !== "number" || !Number.isSafeInteger(target) || target < 0) return void 0;
@@ -18833,7 +18833,7 @@ var ChatRealtimeService = class {
18833
18833
  key: `projection:display:${projectionBatchKey}`,
18834
18834
  traffic: "message-sync"
18835
18835
  });
18836
- for (const raw of listValue$26(displayData.items)) {
18836
+ for (const raw of listValue$27(displayData.items)) {
18837
18837
  const bundle = objectValue$4(raw);
18838
18838
  const uid = stringValue$4(objectValue$4(bundle.session).chat_session_uid).trim();
18839
18839
  if (uid !== "") bundles.set(uid, bundle);
@@ -18959,7 +18959,7 @@ var ChatRealtimeService = class {
18959
18959
  const projectStartedAt = Date.now();
18960
18960
  if (bundles === void 0 && previewBundle === void 0 && projection.refreshSource !== false) throw new Error("Chat display projection failed");
18961
18961
  const bundle = previewBundle ?? bundles?.get(uid);
18962
- const sessionKind = numberValue$30(objectValue$4(bundle).session_kind ?? objectValue$4(objectValue$4(bundle).session).session_kind);
18962
+ const sessionKind = numberValue$31(objectValue$4(bundle).session_kind ?? objectValue$4(objectValue$4(bundle).session).session_kind);
18963
18963
  const sourceKind = sessionKind === 2 ? "group_chat" : sessionKind === 1 || sessionKind === 3 ? "private_chat" : cached?.kind === "group_chat" || cached?.kind === "private_chat" ? cached.kind : void 0;
18964
18964
  if (sourceKind === "group_chat" && groupInteractionTraceEnabled()) {
18965
18965
  const group = groupInteractionTraceKey(await this.source.chatDirectorySourceKey(session.userId, uid));
@@ -25084,7 +25084,7 @@ async function teamHistoryChunk(adapter, resultRef, cursor) {
25084
25084
  const stringValue$1 = (v) => typeof v === "string" ? v : "";
25085
25085
  const objectValue$1 = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
25086
25086
  const finiteNumberValue$1 = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
25087
- const numberValue$29 = (v) => finiteNumberValue$1(v) ?? 0;
25087
+ const numberValue$30 = (v) => finiteNumberValue$1(v) ?? 0;
25088
25088
  const firstSnapshotText$1 = (...values) => values.map((v) => stringValue$1(v).trim()).find(Boolean);
25089
25089
  function snapshotDateLabel(value) {
25090
25090
  if (value === void 0) return void 0;
@@ -25098,7 +25098,7 @@ function snapshotDateLabel(value) {
25098
25098
  }
25099
25099
  function snapshotMovement(value) {
25100
25100
  const rawSpeed = value.speed ?? value.speed_mps ?? value.speedMetersPerSecond;
25101
- const speed = numberValue$29(rawSpeed);
25101
+ const speed = numberValue$30(rawSpeed);
25102
25102
  if (typeof rawSpeed === "number" && Number.isFinite(rawSpeed)) {
25103
25103
  const kmh = Math.round(speed * 3.6);
25104
25104
  return kmh <= 2 ? "静止" : kmh <= 5 ? `缓慢移动(${String(kmh)}km/h)` : kmh <= 60 ? `移动(${String(kmh)}km/h)` : `高速移动(${String(kmh)}km/h)`;
@@ -25950,10 +25950,10 @@ function projectRecordRecordingForward(raw) {
25950
25950
  }
25951
25951
  //#endregion
25952
25952
  //#region src/forward-records-presentation.ts
25953
- function numberValue$28(value) {
25953
+ function numberValue$29(value) {
25954
25954
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
25955
25955
  }
25956
- function listValue$25(value) {
25956
+ function listValue$26(value) {
25957
25957
  return Array.isArray(value) ? value : [];
25958
25958
  }
25959
25959
  async function projectForwardRecordsWithAvatars(contentPayload, viewerUserId, fallbackCreatedAtMillis, media, profile, source) {
@@ -25981,19 +25981,19 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
25981
25981
  let remainingItems = 100;
25982
25982
  let remainingSegments = 2e3;
25983
25983
  const epochMillis = (value) => {
25984
- const time = numberValue$28(value);
25984
+ const time = numberValue$29(value);
25985
25985
  return Number.isFinite(time) && time > 0 && time < 864e13 ? Math.trunc(time < 0xe8d4a51000 ? time * 1e3 : time) : 0;
25986
25986
  };
25987
25987
  const projectCard = (node, depth, fallbackAt, fallbackTitle = "转发快记", teamSnapshot = false) => {
25988
25988
  const projectedItems = [];
25989
- const values = listValue$25(node.items);
25989
+ const values = listValue$26(node.items);
25990
25990
  let truncated = values.length > 100 || depth > 4;
25991
25991
  const createdAtMillis = epochMillis(node.created_at ?? node.createdAt) || epochMillis(fallbackAt);
25992
25992
  const ownerBlind = teamSnapshot || (node.source_type ?? node.sourceType) === "team_message";
25993
25993
  const sorted = (depth <= 4 ? values.slice(0, 100) : []).map((value, index) => ({
25994
25994
  value,
25995
25995
  index,
25996
- order: numberValue$28(objectValue$4(value).item_order)
25996
+ order: numberValue$29(objectValue$4(value).item_order)
25997
25997
  })).sort((left, right) => (left.order || left.index) - (right.order || right.index));
25998
25998
  for (const entry of sorted) {
25999
25999
  if (remainingItems === 0) {
@@ -26007,9 +26007,9 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26007
26007
  const sourceTypeValue = stringValue$4(item.source_type ?? item.sourceType ?? node.source_type ?? node.sourceType ?? payload.source_type ?? payload.sourceType);
26008
26008
  const rawType = sourceTypeValue === "quick_records" ? stringValue$4(item.source_chat_session_uid ?? item.sourceChatSessionUid).trim() ? "chat_record" : "record" : sourceTypeValue;
26009
26009
  const sourceSender = item.source_sender_user_id ?? item.sourceSenderUserId;
26010
- const isDeepSeekReply = rawType === "agent" && numberValue$28(sourceSender) === 0 && stringValue$4(item.source_avatar_kind ?? item.sourceAvatarKind) === "deepseek";
26011
- const isCodexReply = rawType === "codex" && numberValue$28(sourceSender) === 0;
26012
- const senderUserId = ownerBlind || rawType === "team_message" || isDeepSeekReply || isCodexReply ? 0 : numberValue$28(sourceSender ?? item.owner_id ?? item.ownerId);
26010
+ const isDeepSeekReply = rawType === "agent" && numberValue$29(sourceSender) === 0 && stringValue$4(item.source_avatar_kind ?? item.sourceAvatarKind) === "deepseek";
26011
+ const isCodexReply = rawType === "codex" && numberValue$29(sourceSender) === 0;
26012
+ const senderUserId = ownerBlind || rawType === "team_message" || isDeepSeekReply || isCodexReply ? 0 : numberValue$29(sourceSender ?? item.owner_id ?? item.ownerId);
26013
26013
  const senderName = isCodexReply ? "Codex" : isDeepSeekReply ? "DeepSeek Harness" : stringValue$4(item.owner_name ?? item.ownerName ?? item.source_display_name ?? item.sourceDisplayName).trim() || "Arkme用户";
26014
26014
  const title = stringValue$4(item.title).trim();
26015
26015
  const sendAtMillis = epochMillis(item.send_at ?? item.sendAt);
@@ -26028,9 +26028,9 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26028
26028
  const textFormat = (rawType === "agent" || rawType === "codex") && stringValue$4(item.render_format ?? item.renderFormat) === "markdown" ? "markdown" : arkmeRecordTextFormat(item);
26029
26029
  const rawText = stringValue$4(item.text ?? item.text_preview ?? item.textPreview);
26030
26030
  let textContent = textFormat === "markdown" ? rawText : rawText.trim();
26031
- const displayKind = numberValue$28(item.display_kind ?? item.displayKind);
26031
+ const displayKind = numberValue$29(item.display_kind ?? item.displayKind);
26032
26032
  const sourceType = rawType === "record" || rawType === "chat_record" || rawType === "long_recording_segments" || rawType === "agent" || rawType === "codex" || rawType === "ai_letter" ? rawType : "unknown";
26033
- const files = listValue$25(item.files);
26033
+ const files = listValue$26(item.files);
26034
26034
  const longArticle = displayKind === 1;
26035
26035
  const contentBlocks = media.forwardContentBlocks(files, viewerUserId, {
26036
26036
  longArticle,
@@ -26041,14 +26041,14 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26041
26041
  textContent = remapLongArticleAssets(textContent, aliases);
26042
26042
  }
26043
26043
  const call = objectValue$4(item.call_record_snapshot ?? item.callRecordSnapshot);
26044
- const recordingSegments = listValue$25(item.long_recording_segments ?? item.longRecordingSegments);
26045
- const rawSegments = recordingSegments.length > 0 ? recordingSegments : listValue$25(call.transcript_segments ?? call.transcriptSegments);
26044
+ const recordingSegments = listValue$26(item.long_recording_segments ?? item.longRecordingSegments);
26045
+ const rawSegments = recordingSegments.length > 0 ? recordingSegments : listValue$26(call.transcript_segments ?? call.transcriptSegments);
26046
26046
  const segmentValues = rawSegments.slice(0, Math.min(500, remainingSegments));
26047
26047
  remainingSegments -= segmentValues.length;
26048
26048
  const segments = segmentValues.map((value) => {
26049
26049
  if (recordingSegments.length > 0) return projectForwardRecordingSegment(value, senderName);
26050
26050
  const segment = objectValue$4(value);
26051
- const offset = (value) => Math.max(0, Math.trunc(numberValue$28(value)));
26051
+ const offset = (value) => Math.max(0, Math.trunc(numberValue$29(value)));
26052
26052
  const startMillis = offset(segment.start_millis ?? segment.startMillis ?? segment.start_ms ?? segment.startMs);
26053
26053
  const endMillis = Math.max(startMillis, offset(segment.end_millis ?? segment.endMillis ?? segment.end_ms ?? segment.endMs));
26054
26054
  const speakerNumber = offset(segment.speaker_number ?? segment.speakerNumber);
@@ -26070,10 +26070,10 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26070
26070
  ...audioUrl !== "" && segmentMedia.length === 0 ? { mediaUnavailable: true } : {}
26071
26071
  };
26072
26072
  });
26073
- const imageCount = Math.max(0, Math.trunc(numberValue$28(item.image_count ?? item.imageCount)));
26074
- const voiceCount = Math.max(0, Math.trunc(numberValue$28(item.voice_count ?? item.voiceCount)));
26075
- const fileCount = Math.max(0, Math.trunc(numberValue$28(item.file_count ?? item.fileCount)));
26076
- const fileName = listValue$25(item.file_names ?? item.fileNames).map((value) => stringValue$4(value).trim()).find((value) => value !== "");
26073
+ const imageCount = Math.max(0, Math.trunc(numberValue$29(item.image_count ?? item.imageCount)));
26074
+ const voiceCount = Math.max(0, Math.trunc(numberValue$29(item.voice_count ?? item.voiceCount)));
26075
+ const fileCount = Math.max(0, Math.trunc(numberValue$29(item.file_count ?? item.fileCount)));
26076
+ const fileName = listValue$26(item.file_names ?? item.fileNames).map((value) => stringValue$4(value).trim()).find((value) => value !== "");
26077
26077
  const contentLabel = imageCount > 0 ? imageCount > 1 ? `[${String(imageCount)}张图片]` : "[图片]" : voiceCount > 0 ? "[语音]" : fileCount > 0 ? fileName === void 0 ? "[文件]" : `[文件] ${fileName}` : stringValue$4(item.availability).trim() !== "" ? "原快记暂不可查看" : void 0;
26078
26078
  const sourceTeam = objectValue$4(item.source_representation), originTeam = objectValue$4(item.origin_representation);
26079
26079
  projectedItems.push({
@@ -26088,13 +26088,13 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26088
26088
  } } : {},
26089
26089
  ...isDeepSeekReply ? { avatarKind: "deepseek" } : {},
26090
26090
  ...senderUserId > 0 && senderUserId !== viewerUserId ? { senderUserId } : {},
26091
- sendAtMillis: recordingSegments.length > 0 ? numberValue$28(item.send_at ?? item.sendAt) : sendAtMillis,
26091
+ sendAtMillis: recordingSegments.length > 0 ? numberValue$29(item.send_at ?? item.sendAt) : sendAtMillis,
26092
26092
  title,
26093
26093
  textContent,
26094
26094
  textFormat,
26095
26095
  displayKind,
26096
26096
  sourceType,
26097
- templateKind: numberValue$28(item.template_kind ?? item.templateKind),
26097
+ templateKind: numberValue$29(item.template_kind ?? item.templateKind),
26098
26098
  ...contentBlocks.length === 0 ? {} : { contentBlocks },
26099
26099
  ...files.length > contentBlocks.length ? { mediaUnavailable: true } : {},
26100
26100
  ...segments.length === 0 ? {} : { segments },
@@ -26107,7 +26107,7 @@ function projectForwardRecordsPreview(contentPayload, viewerUserId, fallbackCrea
26107
26107
  return {
26108
26108
  title: stringValue$4(node.title).trim() || fallbackTitle,
26109
26109
  createdAtMillis,
26110
- summaryLines: listValue$25(node.summary_lines ?? node.summaryLines).map((value) => stringValue$4(value).trim()).filter(Boolean),
26110
+ summaryLines: listValue$26(node.summary_lines ?? node.summaryLines).map((value) => stringValue$4(value).trim()).filter(Boolean),
26111
26111
  items: projectedItems,
26112
26112
  ...truncated ? { truncated: true } : {}
26113
26113
  };
@@ -46181,13 +46181,13 @@ function bestMatchingCategory(text) {
46181
46181
  }
46182
46182
  //#endregion
46183
46183
  //#region src/services/ai-video-service.ts
46184
- function numberValue$27(value) {
46184
+ function numberValue$28(value) {
46185
46185
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
46186
46186
  }
46187
46187
  function booleanValue$14(value) {
46188
46188
  return value === true;
46189
46189
  }
46190
- function listValue$24(value) {
46190
+ function listValue$25(value) {
46191
46191
  return Array.isArray(value) ? value : [];
46192
46192
  }
46193
46193
  var AiVideoService = class {
@@ -46200,7 +46200,7 @@ var AiVideoService = class {
46200
46200
  const data = await this.runtime.authenticatedAudioPost("/api/v1/audio/get-session-detail-by-id", { session_id: recordingUid }, session, signal, { bypassCache: true });
46201
46201
  const recording = objectValue$4(data.session);
46202
46202
  if (recording.session_id !== recordingUid || recording.source !== 1 || !Number.isSafeInteger(recording.start_at)) throw new ArkmePluginError("recording-selection-invalid", "录音素材详情无效", false);
46203
- const rows = [...listValue$24(data.doubao_transcript_item_ls), ...listValue$24(data.transcript_item_ls)].map(objectValue$4);
46203
+ const rows = [...listValue$25(data.doubao_transcript_item_ls), ...listValue$25(data.transcript_item_ls)].map(objectValue$4);
46204
46204
  return utterances.map((utterance) => {
46205
46205
  const matches = rows.filter((item) => Number.isSafeInteger(item.start_at) && Number.isSafeInteger(item.end_at) && Number(item.start_at) - Number(recording.start_at) === utterance.startOffsetMillis && Number(item.end_at) - Number(recording.start_at) === utterance.endOffsetMillis && item.text === utterance.text);
46206
46206
  const selected = matches.filter((item) => item.transcript_source !== "system" || !matches.some((other) => other.child_id === item.child_id && other.transcript_source === "doubao"));
@@ -46219,9 +46219,9 @@ var AiVideoService = class {
46219
46219
  return {
46220
46220
  allowed: booleanValue$14(data.allowed),
46221
46221
  message: stringValue$4(data.message).trim() || "AI 视频内容检查已完成",
46222
- selectedDurationMillis: Math.max(0, numberValue$27(data.selected_duration_millis)),
46223
- minimumDurationMillis: Math.max(0, numberValue$27(data.minimum_duration_millis)),
46224
- selectedSegmentCount: Math.max(0, numberValue$27(data.selected_segment_count)),
46222
+ selectedDurationMillis: Math.max(0, numberValue$28(data.selected_duration_millis)),
46223
+ minimumDurationMillis: Math.max(0, numberValue$28(data.minimum_duration_millis)),
46224
+ selectedSegmentCount: Math.max(0, numberValue$28(data.selected_segment_count)),
46225
46225
  retryable: booleanValue$14(data.retryable),
46226
46226
  ...stringValue$4(data.reason_code).trim() === "" ? {} : { reasonCode: stringValue$4(data.reason_code).trim() },
46227
46227
  ...stringValue$4(data.proof).trim() === "" ? {} : { proof: stringValue$4(data.proof).trim() }
@@ -46257,7 +46257,7 @@ var AiVideoService = class {
46257
46257
  ...options.statuses === void 0 || options.statuses.length === 0 ? {} : { statuses: options.statuses }
46258
46258
  }, session, options.signal);
46259
46259
  return {
46260
- items: listValue$24(data.items).map((raw) => this.aiVideoListItem(raw)).filter((item) => item !== void 0),
46260
+ items: listValue$25(data.items).map((raw) => this.aiVideoListItem(raw)).filter((item) => item !== void 0),
46261
46261
  hasMore: booleanValue$14(data.has_more),
46262
46262
  ...stringValue$4(data.next_cursor).trim() === "" ? {} : { nextCursor: stringValue$4(data.next_cursor).trim() }
46263
46263
  };
@@ -46271,10 +46271,10 @@ var AiVideoService = class {
46271
46271
  return {
46272
46272
  allowed: booleanValue$14(data.allowed),
46273
46273
  message: stringValue$4(data.message).trim() || "AI 视频内容检查已完成",
46274
- selectedDurationMillis: Math.max(0, numberValue$27(data.selected_duration_millis)),
46275
- minimumDurationMillis: Math.max(0, numberValue$27(data.minimum_duration_millis)),
46276
- selectedSegmentCount: Math.max(0, numberValue$27(data.selected_segment_count)),
46277
- selectedTextCount: Math.max(0, numberValue$27(data.selected_text_count)),
46274
+ selectedDurationMillis: Math.max(0, numberValue$28(data.selected_duration_millis)),
46275
+ minimumDurationMillis: Math.max(0, numberValue$28(data.minimum_duration_millis)),
46276
+ selectedSegmentCount: Math.max(0, numberValue$28(data.selected_segment_count)),
46277
+ selectedTextCount: Math.max(0, numberValue$28(data.selected_text_count)),
46278
46278
  retryable: booleanValue$14(data.retryable),
46279
46279
  ...stringValue$4(data.reason_code).trim() === "" ? {} : { reasonCode: stringValue$4(data.reason_code).trim() },
46280
46280
  ...stringValue$4(data.proof).trim() === "" ? {} : { proof: stringValue$4(data.proof).trim() }
@@ -46314,19 +46314,19 @@ var AiVideoService = class {
46314
46314
  "canceled"
46315
46315
  ])).has(status)) throw new ArkmePluginError("ai-video-contract-invalid", "AI 视频服务返回了无效任务信息", true, 502);
46316
46316
  const selection = objectValue$4(data.selection);
46317
- const segmentCount = listValue$24(selection.segments).length;
46318
- const textCount = listValue$24(selection.texts).length;
46317
+ const segmentCount = listValue$25(selection.segments).length;
46318
+ const textCount = listValue$25(selection.texts).length;
46319
46319
  return {
46320
46320
  jobId,
46321
46321
  status,
46322
46322
  stage: stringValue$4(data.stage).trim() || status,
46323
- progress: Math.min(100, Math.max(0, Math.trunc(numberValue$27(data.progress)))),
46323
+ progress: Math.min(100, Math.max(0, Math.trunc(numberValue$28(data.progress)))),
46324
46324
  selectedSegmentCount: segmentCount,
46325
46325
  ...textCount === 0 ? {} : { selectedTextCount: textCount },
46326
46326
  retryable: booleanValue$14(data.retryable),
46327
46327
  ...stringValue$4(data.video_asset_uid).trim() === "" ? {} : { videoAssetUid: stringValue$4(data.video_asset_uid).trim() },
46328
46328
  ...stringValue$4(data.cover_asset_uid).trim() === "" ? {} : { coverAssetUid: stringValue$4(data.cover_asset_uid).trim() },
46329
- ...numberValue$27(data.video_duration_millis) <= 0 ? {} : { videoDurationMillis: numberValue$27(data.video_duration_millis) },
46329
+ ...numberValue$28(data.video_duration_millis) <= 0 ? {} : { videoDurationMillis: numberValue$28(data.video_duration_millis) },
46330
46330
  ...stringValue$4(data.error_code).trim() === "" ? {} : { errorCode: stringValue$4(data.error_code).trim() },
46331
46331
  ...stringValue$4(data.error_message).trim() === "" ? {} : { errorMessage: stringValue$4(data.error_message).trim() },
46332
46332
  ...stringValue$4(data.failure_stage).trim() === "" ? {} : { failureStage: stringValue$4(data.failure_stage).trim() }
@@ -46349,17 +46349,17 @@ var AiVideoService = class {
46349
46349
  sessionId: stringValue$4(item.session_id).trim(),
46350
46350
  status,
46351
46351
  stage: stringValue$4(item.stage).trim() || status,
46352
- progress: Math.min(100, Math.max(0, Math.trunc(numberValue$27(item.progress)))),
46352
+ progress: Math.min(100, Math.max(0, Math.trunc(numberValue$28(item.progress)))),
46353
46353
  title: stringValue$4(source.title).trim() || "长录音 AI 视频",
46354
- sourceStartedAtMillis: numberValue$27(source.started_at),
46355
- selectedDurationMillis: Math.max(0, numberValue$27(source.selected_duration_millis)),
46356
- selectedSegmentCount: Math.max(0, Math.trunc(numberValue$27(item.selected_segment_count))),
46354
+ sourceStartedAtMillis: numberValue$28(source.started_at),
46355
+ selectedDurationMillis: Math.max(0, numberValue$28(source.selected_duration_millis)),
46356
+ selectedSegmentCount: Math.max(0, Math.trunc(numberValue$28(item.selected_segment_count))),
46357
46357
  retryable: booleanValue$14(item.retryable),
46358
- createdAtMillis: numberValue$27(item.created_at),
46359
- updatedAtMillis: numberValue$27(item.updated_at),
46358
+ createdAtMillis: numberValue$28(item.created_at),
46359
+ updatedAtMillis: numberValue$28(item.updated_at),
46360
46360
  ...stringValue$4(item.cover_asset_uid).trim() === "" ? {} : { coverAssetUid: stringValue$4(item.cover_asset_uid).trim() },
46361
46361
  ...stringValue$4(item.video_asset_uid).trim() === "" ? {} : { videoAssetUid: stringValue$4(item.video_asset_uid).trim() },
46362
- ...numberValue$27(item.video_duration_millis) <= 0 ? {} : { videoDurationMillis: numberValue$27(item.video_duration_millis) },
46362
+ ...numberValue$28(item.video_duration_millis) <= 0 ? {} : { videoDurationMillis: numberValue$28(item.video_duration_millis) },
46363
46363
  ...stringValue$4(item.error_code).trim() === "" ? {} : { errorCode: stringValue$4(item.error_code).trim() },
46364
46364
  ...stringValue$4(item.error_message).trim() === "" ? {} : { errorMessage: clippedText(item.error_message, 500) }
46365
46365
  };
@@ -46367,14 +46367,14 @@ var AiVideoService = class {
46367
46367
  };
46368
46368
  //#endregion
46369
46369
  //#region src/services/ai-letter-service.ts
46370
- function listValue$23(value) {
46370
+ function listValue$24(value) {
46371
46371
  return Array.isArray(value) ? value : [];
46372
46372
  }
46373
- function numberValue$26(value) {
46373
+ function numberValue$27(value) {
46374
46374
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
46375
46375
  }
46376
46376
  function millisValue$1(value) {
46377
- const numeric = Math.trunc(numberValue$26(value));
46377
+ const numeric = Math.trunc(numberValue$27(value));
46378
46378
  if (numeric <= 0) return 0;
46379
46379
  return numeric < 0xe8d4a51000 ? numeric * 1e3 : numeric;
46380
46380
  }
@@ -46382,7 +46382,7 @@ function letterItem(raw) {
46382
46382
  const item = objectValue$4(raw);
46383
46383
  const letterId = stringValue$4(item.letter_id ?? item.letterId).trim();
46384
46384
  if (letterId === "") return void 0;
46385
- const readStatus = Math.trunc(numberValue$26(item.read_status ?? item.readStatus));
46385
+ const readStatus = Math.trunc(numberValue$27(item.read_status ?? item.readStatus));
46386
46386
  return {
46387
46387
  letterId,
46388
46388
  title: stringValue$4(item.title).trim() || "AI 来信",
@@ -46404,8 +46404,8 @@ var AiLetterService = class {
46404
46404
  limit: Math.min(50, Math.max(1, Math.trunc(options.limit ?? 20)))
46405
46405
  }, session, options.signal);
46406
46406
  return {
46407
- items: listValue$23(data.items).map(letterItem).filter((item) => item !== void 0),
46408
- nextCursor: Math.max(0, Math.trunc(numberValue$26(data.next_cursor ?? data.nextCursor)))
46407
+ items: listValue$24(data.items).map(letterItem).filter((item) => item !== void 0),
46408
+ nextCursor: Math.max(0, Math.trunc(numberValue$27(data.next_cursor ?? data.nextCursor)))
46409
46409
  };
46410
46410
  }
46411
46411
  async unread(signal) {
@@ -46413,7 +46413,7 @@ var AiLetterService = class {
46413
46413
  const data = await this.runtime.authenticatedIntelligentPost("/api/v1/ai-letter/unread-count", {}, session, signal);
46414
46414
  const latestUnread = letterItem(data.latest_unread ?? data.latestUnread);
46415
46415
  return {
46416
- unreadCount: Math.max(0, Math.trunc(numberValue$26(data.unread_count ?? data.unreadCount))),
46416
+ unreadCount: Math.max(0, Math.trunc(numberValue$27(data.unread_count ?? data.unreadCount))),
46417
46417
  ...latestUnread === void 0 ? {} : { latestUnread }
46418
46418
  };
46419
46419
  }
@@ -46422,7 +46422,7 @@ var AiLetterService = class {
46422
46422
  const ids = [...new Set(letterIds.map((value) => value.trim()).filter((value) => value !== ""))].slice(0, 50);
46423
46423
  if (ids.length === 0) return await this.unread(signal);
46424
46424
  const data = await this.runtime.authenticatedIntelligentPost("/api/v1/ai-letter/mark-read", { letter_ids: ids }, session, signal);
46425
- return { unreadCount: Math.max(0, Math.trunc(numberValue$26(data.unread_count ?? data.unreadCount))) };
46425
+ return { unreadCount: Math.max(0, Math.trunc(numberValue$27(data.unread_count ?? data.unreadCount))) };
46426
46426
  }
46427
46427
  };
46428
46428
  /** Cache is disposable presentation, never pending-send evidence or an authority. */
@@ -47155,6 +47155,8 @@ var ArkoLocalMarks = class {
47155
47155
  //#region src/services/arko-service.ts
47156
47156
  const ARKO_AGENT_DIRECT_SESSION_TYPE = 2;
47157
47157
  const ARKO_DEFAULT_SESSION_NAME = "Arko";
47158
+ const ARKO_DELEGATED_SESSION_NAME = "本机协同";
47159
+ const ARKO_DELEGATED_SESSION_CACHE_LIMIT = 200;
47158
47160
  const ARKO_COMPLETED_STATUS = "completed";
47159
47161
  const ARKO_STREAM_TIMEOUT_STATUS = "stream_timeout";
47160
47162
  const ARKO_HISTORY_PAGE_LIMIT = 50;
@@ -47171,16 +47173,16 @@ const ARKO_RUN_STATUSES = /* @__PURE__ */ new Set([
47171
47173
  "expired"
47172
47174
  ]);
47173
47175
  const ARKO_PROFILE_DISPLAY_NAME_CACHE_TTL_MS = 10 * 6e4;
47174
- function numberValue$25(value) {
47176
+ function numberValue$26(value) {
47175
47177
  return typeof value === "number" && Number.isFinite(value) ? value : 0;
47176
47178
  }
47177
47179
  function booleanValue$13(value) {
47178
47180
  return value === true;
47179
47181
  }
47180
- function listValue$22(value) {
47182
+ function listValue$23(value) {
47181
47183
  return Array.isArray(value) ? value : [];
47182
47184
  }
47183
- function optionalString$3(value) {
47185
+ function optionalString$4(value) {
47184
47186
  const text = stringValue$4(value).trim();
47185
47187
  return text === "" ? void 0 : text;
47186
47188
  }
@@ -47206,7 +47208,7 @@ function joinUrlWithQuery(baseUrl, path, query) {
47206
47208
  }
47207
47209
  function arkoProfileFromData(data) {
47208
47210
  const displayName = stringValue$4(data.display_name).trim();
47209
- const version = numberValue$25(data.version);
47211
+ const version = numberValue$26(data.version);
47210
47212
  if (displayName === "" || !Number.isSafeInteger(version) || version < 0) throw new ArkmePluginError("arko-profile-contract-invalid", "Arko 资料响应不完整", true, 502);
47211
47213
  return {
47212
47214
  displayName,
@@ -47245,7 +47247,7 @@ function arkoModelCatalogFromData(data) {
47245
47247
  const defaultRouteKey = arkoModelRouteKey(data.default_route_key);
47246
47248
  const effectiveRouteKey = arkoModelRouteKey(data.effective_route_key);
47247
47249
  const selectionSource = stringValue$4(data.selection_source);
47248
- const options = listValue$22(data.items).map(arkoModelOptionFromData);
47250
+ const options = listValue$23(data.items).map(arkoModelOptionFromData);
47249
47251
  const routeKeys = new Set(options.map((option) => option.routeKey));
47250
47252
  const selected = options.filter((option) => option.selected);
47251
47253
  if (selectionSource !== "default" && selectionSource !== "personal" && selectionSource !== "unavailable" || options.length === 0 || options.length > 256 || routeKeys.size !== options.length || !routeKeys.has(defaultRouteKey) || (selectionSource === "unavailable" ? routeKeys.has(effectiveRouteKey) || selected.length !== 0 : !routeKeys.has(effectiveRouteKey) || selected.length !== 1 || selected[0]?.routeKey !== effectiveRouteKey)) throw new ArkmePluginError("arko-model-contract-invalid", "Arko 模型目录响应无效", true, 502);
@@ -47266,9 +47268,9 @@ function parsedJsonRecord(value) {
47266
47268
  }
47267
47269
  function arkoHistoryItemFromData(value) {
47268
47270
  const data = objectValue$4(value);
47269
- const messageId = numberValue$25(data.id ?? data.msg_id ?? data.msgId);
47270
- const sessionId = numberValue$25(data.session_id ?? data.sessionId);
47271
- const roleCode = numberValue$25(data.role ?? data.sender_role ?? data.senderRole);
47271
+ const messageId = numberValue$26(data.id ?? data.msg_id ?? data.msgId);
47272
+ const sessionId = numberValue$26(data.session_id ?? data.sessionId);
47273
+ const roleCode = numberValue$26(data.role ?? data.sender_role ?? data.senderRole);
47272
47274
  if (!Number.isSafeInteger(messageId) || messageId <= 0 || !Number.isSafeInteger(sessionId) || sessionId <= 0 || roleCode !== 2 && roleCode !== 3) return void 0;
47273
47275
  const extra = parsedJsonRecord(data.extra ?? data.metadata ?? data.meta);
47274
47276
  const extraData = parsedJsonRecord(extra.data);
@@ -47290,22 +47292,22 @@ function arkoHistoryItemFromData(value) {
47290
47292
  extraData.updateAt,
47291
47293
  data.updated_at,
47292
47294
  data.updatedAt
47293
- ].map(numberValue$25).find((candidate) => candidate > 0) ?? 0;
47294
- const runUid = optionalString$3(extra.agent_run_uid);
47295
- const runStatus = optionalString$3(extra.agent_run_status);
47295
+ ].map(numberValue$26).find((candidate) => candidate > 0) ?? 0;
47296
+ const runUid = optionalString$4(extra.agent_run_uid);
47297
+ const runStatus = optionalString$4(extra.agent_run_status);
47296
47298
  const retryable = optionalBooleanValue$1(extra.agent_run_retryable);
47297
- const errorCode = optionalString$3(extra.agent_run_error_code);
47298
- const retryOfRunUid = optionalString$3(extra.retry_of_run_uid);
47299
- const entryRecordUid = optionalString$3(extra.entry_record_uid ?? extraData.entry_record_uid);
47299
+ const errorCode = optionalString$4(extra.agent_run_error_code);
47300
+ const retryOfRunUid = optionalString$4(extra.retry_of_run_uid);
47301
+ const entryRecordUid = optionalString$4(extra.entry_record_uid ?? extraData.entry_record_uid);
47300
47302
  return {
47301
47303
  messageId,
47302
47304
  sessionId,
47303
- lifecycleVersion: numberValue$25(data.lifecycle_version),
47305
+ lifecycleVersion: numberValue$26(data.lifecycle_version),
47304
47306
  role: roleCode === 2 ? "user" : "assistant",
47305
47307
  text: stringValue$4(data.content ?? data.text_content ?? data.textContent),
47306
47308
  reasoning: stringValue$4(data.reason_content ?? data.reason_text ?? data.reasonText),
47307
47309
  createdAtMillis: activityAt === data.created_at_ms ? activityAt : activityAt > 0 && activityAt < 1e11 ? activityAt * 1e3 : activityAt,
47308
- status: numberValue$25(data.status ?? data.msg_status),
47310
+ status: numberValue$26(data.status ?? data.msg_status),
47309
47311
  ...runUid === void 0 ? {} : { runUid },
47310
47312
  ...runStatus === void 0 ? {} : { runStatus },
47311
47313
  ...retryable === void 0 ? {} : { retryable },
@@ -47332,7 +47334,7 @@ function arkoRunProjectionFromData(data) {
47332
47334
  };
47333
47335
  }
47334
47336
  function arkoCreatedRecordUids(value) {
47335
- return listValue$22(value).map((item) => stringValue$4(item).trim()).filter((item) => item !== "");
47337
+ return listValue$23(value).map((item) => stringValue$4(item).trim()).filter((item) => item !== "");
47336
47338
  }
47337
47339
  function arkoStreamFrame(raw) {
47338
47340
  try {
@@ -47351,6 +47353,7 @@ var ArkoService = class {
47351
47353
  lifecycle;
47352
47354
  localMarks;
47353
47355
  arkoProfileDisplayNameCache = /* @__PURE__ */ new Map();
47356
+ delegatedSessions = /* @__PURE__ */ new Map();
47354
47357
  constructor(runtime, profile, messageActions, images) {
47355
47358
  this.runtime = runtime;
47356
47359
  this.profile = profile;
@@ -47367,6 +47370,7 @@ var ArkoService = class {
47367
47370
  }
47368
47371
  dispose() {
47369
47372
  this.arkoProfileDisplayNameCache.clear();
47373
+ this.delegatedSessions.clear();
47370
47374
  }
47371
47375
  async arkoProfile(signal) {
47372
47376
  const session = await this.runtime.requireSession();
@@ -47389,7 +47393,7 @@ var ArkoService = class {
47389
47393
  async arkoEnsureSession(signal) {
47390
47394
  const session = await this.runtime.requireSession();
47391
47395
  const latest = await this.runtime.authenticatedIntelligentPost("/api/v1/qa/latest-session", { type: ARKO_AGENT_DIRECT_SESSION_TYPE }, session, signal);
47392
- const latestSessionId = numberValue$25(latest.id);
47396
+ const latestSessionId = numberValue$26(latest.id);
47393
47397
  if (Number.isSafeInteger(latestSessionId) && latestSessionId > 0) return {
47394
47398
  sessionId: latestSessionId,
47395
47399
  created: false,
@@ -47399,7 +47403,7 @@ var ArkoService = class {
47399
47403
  }
47400
47404
  async arkoCreateSession(signal) {
47401
47405
  const session = await this.runtime.requireSession();
47402
- const createdSessionId = numberValue$25((await this.runtime.authenticatedIntelligentPost("/api/v1/qa/new-session", {
47406
+ const createdSessionId = numberValue$26((await this.runtime.authenticatedIntelligentPost("/api/v1/qa/new-session", {
47403
47407
  name: ARKO_DEFAULT_SESSION_NAME,
47404
47408
  type: ARKO_AGENT_DIRECT_SESSION_TYPE
47405
47409
  }, session, signal)).session_id);
@@ -47410,6 +47414,40 @@ var ArkoService = class {
47410
47414
  name: ARKO_DEFAULT_SESSION_NAME
47411
47415
  };
47412
47416
  }
47417
+ /**
47418
+ * Opens or reuses an isolated thread session (`lane: "thread"`) for desktop
47419
+ * agent delegations so `arkme_arko_ask` never pollutes the user's main Arko
47420
+ * conversation or pulls its 128K main history.
47421
+ */
47422
+ async arkoEnsureDelegatedSession(session, scope, name, signal) {
47423
+ const normalizedScope = scope?.trim();
47424
+ const cacheKey = normalizedScope ? `${session.userId}:${normalizedScope}` : void 0;
47425
+ if (cacheKey !== void 0) {
47426
+ const cached = this.delegatedSessions.get(cacheKey);
47427
+ if (cached !== void 0) {
47428
+ this.delegatedSessions.delete(cacheKey);
47429
+ this.delegatedSessions.set(cacheKey, cached);
47430
+ return cached;
47431
+ }
47432
+ }
47433
+ const sessionName = name?.trim() || ARKO_DELEGATED_SESSION_NAME;
47434
+ const createdSessionId = numberValue$26((await this.runtime.authenticatedIntelligentPost("/api/v1/qa/new-session", {
47435
+ name: sessionName,
47436
+ type: ARKO_AGENT_DIRECT_SESSION_TYPE,
47437
+ lane: "thread"
47438
+ }, session, signal)).session_id);
47439
+ if (!Number.isSafeInteger(createdSessionId) || createdSessionId <= 0) throw new ArkmePluginError("arko-session-contract-invalid", "Arko 会话响应不完整", true, 502);
47440
+ if (cacheKey !== void 0) {
47441
+ if ((await this.runtime.requireSession().catch(() => void 0))?.userId === session.userId) {
47442
+ if (this.delegatedSessions.size >= ARKO_DELEGATED_SESSION_CACHE_LIMIT) {
47443
+ const oldest = this.delegatedSessions.keys().next().value;
47444
+ if (oldest !== void 0) this.delegatedSessions.delete(oldest);
47445
+ }
47446
+ this.delegatedSessions.set(cacheKey, createdSessionId);
47447
+ }
47448
+ }
47449
+ return createdSessionId;
47450
+ }
47413
47451
  async arkoModelCatalog(signal) {
47414
47452
  const session = await this.runtime.requireSession();
47415
47453
  return arkoModelCatalogFromData(await this.runtime.authenticatedIntelligentPost("/api/v1/agent/model/list", {}, session, signal));
@@ -47420,16 +47458,18 @@ var ArkoService = class {
47420
47458
  const session = await this.runtime.requireSession();
47421
47459
  return arkoModelCatalogFromData(await this.runtime.authenticatedIntelligentPost("/api/v1/agent/model/activate", { route_key: normalized }, session, signal));
47422
47460
  }
47423
- async arkoHistoryPage(limit = ARKO_HISTORY_PAGE_LIMIT, offset = 0, signal) {
47461
+ async arkoHistoryPage(limit = ARKO_HISTORY_PAGE_LIMIT, offset = 0, signal, sessionId) {
47424
47462
  const normalizedLimit = Math.min(ARKO_HISTORY_PAGE_LIMIT, Math.max(1, Math.trunc(limit)));
47425
47463
  const normalizedOffset = Math.max(0, Math.trunc(offset));
47426
47464
  const session = await this.runtime.requireSession();
47427
- const rawItems = listValue$22((await this.runtime.authenticatedIntelligentPost("/api/v1/qa/message-list", {
47465
+ const payload = {
47428
47466
  limit: normalizedLimit,
47429
47467
  offset: normalizedOffset,
47430
47468
  session_type: ARKO_AGENT_DIRECT_SESSION_TYPE,
47431
47469
  client_capabilities: ["dsh.arko.images.v1"]
47432
- }, session, signal, {
47470
+ };
47471
+ if (sessionId !== void 0 && Number.isSafeInteger(sessionId) && sessionId > 0) payload.session_id = sessionId;
47472
+ const rawItems = listValue$23((await this.runtime.authenticatedIntelligentPost("/api/v1/qa/message-list", payload, session, signal, {
47433
47473
  lane: "interactive-read",
47434
47474
  bypassCache: true,
47435
47475
  cacheMs: 0
@@ -47452,23 +47492,23 @@ var ArkoService = class {
47452
47492
  }
47453
47493
  if (strict) {
47454
47494
  const wire = objectValue$4(raw);
47455
- if (![1, 2].includes(numberValue$25(wire.source_type)) || ![
47495
+ if (![1, 2].includes(numberValue$26(wire.source_type)) || ![
47456
47496
  1,
47457
47497
  2,
47458
47498
  3
47459
- ].includes(numberValue$25(wire.type)) || ![
47499
+ ].includes(numberValue$26(wire.type)) || ![
47460
47500
  1,
47461
47501
  2,
47462
47502
  3,
47463
47503
  5
47464
47504
  ].includes(item.status) || !Number.isSafeInteger(wire.created_at_ms) || !Number.isSafeInteger(wire.order_at_ms)) throw new ArkmePluginError("arko-history-contract-invalid", "历史消息字段不完整", true, 502);
47465
47505
  item.reasoning = "";
47466
- item.createdAtMillis = numberValue$25(wire.created_at_ms);
47467
- item.sourceType = numberValue$25(wire.source_type);
47468
- item.messageType = numberValue$25(wire.type);
47469
- item.orderAtMillis = numberValue$25(wire.order_at_ms);
47506
+ item.createdAtMillis = numberValue$26(wire.created_at_ms);
47507
+ item.sourceType = numberValue$26(wire.source_type);
47508
+ item.messageType = numberValue$26(wire.type);
47509
+ item.orderAtMillis = numberValue$26(wire.order_at_ms);
47470
47510
  }
47471
- const attachments = listValue$22(objectValue$4(raw).attachments).map(objectValue$4).filter((attachment) => stringValue$4(attachment.file_asset_uid) !== "" && ARKO_IMAGE_MIME_TYPES.some((mime) => mime === attachment.mime_type));
47511
+ const attachments = listValue$23(objectValue$4(raw).attachments).map(objectValue$4).filter((attachment) => stringValue$4(attachment.file_asset_uid) !== "" && ARKO_IMAGE_MIME_TYPES.some((mime) => mime === attachment.mime_type));
47472
47512
  if (attachments.length === 0) return item;
47473
47513
  const blocks = this.images?.project({ media_display_items: attachments.map((attachment) => ({
47474
47514
  ...attachment,
@@ -47485,7 +47525,7 @@ var ArkoService = class {
47485
47525
  fileAssetUid: stringValue$4(attachment.file_asset_uid),
47486
47526
  fileName: stringValue$4(attachment.file_name) || "图片",
47487
47527
  mimeType: stringValue$4(attachment.mime_type),
47488
- size: numberValue$25(attachment.size),
47528
+ size: numberValue$26(attachment.size),
47489
47529
  sortOrder
47490
47530
  };
47491
47531
  });
@@ -47541,12 +47581,12 @@ var ArkoService = class {
47541
47581
  });
47542
47582
  }
47543
47583
  historyContinuation(data) {
47544
- const hasMore = data.has_more === true, nextCursor = optionalString$3(data.next_cursor);
47545
- if (typeof data.has_more !== "boolean" || hasMore && !nextCursor || !Number.isSafeInteger(data.scanned) || numberValue$25(data.scanned) < 0 || numberValue$25(data.scanned) > 500 || data.consistency !== "live") throw new ArkmePluginError("arko-history-contract-invalid", "历史分页响应不完整", true, 502);
47584
+ const hasMore = data.has_more === true, nextCursor = optionalString$4(data.next_cursor);
47585
+ if (typeof data.has_more !== "boolean" || hasMore && !nextCursor || !Number.isSafeInteger(data.scanned) || numberValue$26(data.scanned) < 0 || numberValue$26(data.scanned) > 500 || data.consistency !== "live") throw new ArkmePluginError("arko-history-contract-invalid", "历史分页响应不完整", true, 502);
47546
47586
  return {
47547
47587
  hasMore,
47548
47588
  ...hasMore ? { nextCursor } : {},
47549
- scanned: numberValue$25(data.scanned),
47589
+ scanned: numberValue$26(data.scanned),
47550
47590
  consistency: "live"
47551
47591
  };
47552
47592
  }
@@ -47576,10 +47616,10 @@ var ArkoService = class {
47576
47616
  cacheMs: 0
47577
47617
  });
47578
47618
  return {
47579
- items: await this.projectHistory(listValue$22(data.items), session, true),
47619
+ items: await this.projectHistory(listValue$23(data.items), session, true),
47580
47620
  ...this.historyContinuation(data),
47581
- ...optionalString$3(data.before_cursor) ? { beforeCursor: stringValue$4(data.before_cursor) } : {},
47582
- ...optionalString$3(data.after_cursor) ? { afterCursor: stringValue$4(data.after_cursor) } : {}
47621
+ ...optionalString$4(data.before_cursor) ? { beforeCursor: stringValue$4(data.before_cursor) } : {},
47622
+ ...optionalString$4(data.after_cursor) ? { afterCursor: stringValue$4(data.after_cursor) } : {}
47583
47623
  };
47584
47624
  }
47585
47625
  async readSearch(query, signal) {
@@ -47597,20 +47637,20 @@ var ArkoService = class {
47597
47637
  return {
47598
47638
  items: await Promise.all(data.items.map(async (raw) => {
47599
47639
  const item = objectValue$4(raw);
47600
- if (!Number.isSafeInteger(item.id) || numberValue$25(item.id) < 1 || !Number.isSafeInteger(item.session_id) || numberValue$25(item.session_id) < 1 || ![2, 3].includes(numberValue$25(item.role)) || ![
47640
+ if (!Number.isSafeInteger(item.id) || numberValue$26(item.id) < 1 || !Number.isSafeInteger(item.session_id) || numberValue$26(item.session_id) < 1 || ![2, 3].includes(numberValue$26(item.role)) || ![
47601
47641
  1,
47602
47642
  2,
47603
47643
  3,
47604
47644
  5
47605
- ].includes(numberValue$25(item.status)) || typeof item.snippet !== "string" || item.snippet.length > 1024 || typeof item.created_at_ms !== "number" || typeof item.order_at_ms !== "number") throw new ArkmePluginError("arko-history-contract-invalid", "搜索响应无效", true, 502);
47645
+ ].includes(numberValue$26(item.status)) || typeof item.snippet !== "string" || item.snippet.length > 1024 || typeof item.created_at_ms !== "number" || typeof item.order_at_ms !== "number") throw new ArkmePluginError("arko-history-contract-invalid", "搜索响应无效", true, 502);
47606
47646
  return {
47607
- messageKey: `${numberValue$25(item.session_id)}:${numberValue$25(item.id)}`,
47608
- messageRef: await this.messageRef(session.userId, numberValue$25(item.session_id), numberValue$25(item.id)),
47647
+ messageKey: `${numberValue$26(item.session_id)}:${numberValue$26(item.id)}`,
47648
+ messageRef: await this.messageRef(session.userId, numberValue$26(item.session_id), numberValue$26(item.id)),
47609
47649
  role: item.role === 2 ? "user" : "assistant",
47610
47650
  snippet: item.snippet,
47611
47651
  createdAtMillis: item.created_at_ms,
47612
47652
  orderAtMillis: item.order_at_ms,
47613
- status: numberValue$25(item.status)
47653
+ status: numberValue$26(item.status)
47614
47654
  };
47615
47655
  })),
47616
47656
  ...this.historyContinuation(data)
@@ -47620,7 +47660,7 @@ var ArkoService = class {
47620
47660
  const before = query.before ?? 20, after = query.after ?? 20;
47621
47661
  if (!Number.isInteger(before) || !Number.isInteger(after) || before < 0 || after < 0 || before + after > 49 || typeof query.messageRef !== "string") throw new ArkmePluginError("arko-history-invalid", "上下文窗口参数无效", false, 400);
47622
47662
  const session = await this.runtime.requireSession(), ref = await this.historyCodec.open("arkme-arko-message-v1", query.messageRef);
47623
- if (ref.userId !== session.userId || numberValue$25(ref.expiresAtMillis) <= Date.now() || !Number.isSafeInteger(ref.messageId) || !Number.isSafeInteger(ref.sessionId)) throw new ArkmePluginError("arko-message-unavailable", "消息已不可查看,请重新搜索", false, 404);
47663
+ if (ref.userId !== session.userId || numberValue$26(ref.expiresAtMillis) <= Date.now() || !Number.isSafeInteger(ref.messageId) || !Number.isSafeInteger(ref.sessionId)) throw new ArkmePluginError("arko-message-unavailable", "消息已不可查看,请重新搜索", false, 404);
47624
47664
  const data = await this.runtime.authenticatedIntelligentPost("/api/v1/arko/messages/context", {
47625
47665
  session_id: ref.sessionId,
47626
47666
  message_id: ref.messageId,
@@ -47631,8 +47671,8 @@ var ArkoService = class {
47631
47671
  bypassCache: true,
47632
47672
  cacheMs: 0
47633
47673
  });
47634
- const items = await this.projectHistory(listValue$22(data.items), session, true);
47635
- if (typeof data.has_before !== "boolean" || typeof data.has_after !== "boolean" || data.has_before && !optionalString$3(data.before_cursor) || data.has_after && !optionalString$3(data.after_cursor) || !items.some((item) => item.sessionId === ref.sessionId && item.messageId === ref.messageId)) throw new ArkmePluginError("arko-history-contract-invalid", "上下文响应不完整", true, 502);
47674
+ const items = await this.projectHistory(listValue$23(data.items), session, true);
47675
+ if (typeof data.has_before !== "boolean" || typeof data.has_after !== "boolean" || data.has_before && !optionalString$4(data.before_cursor) || data.has_after && !optionalString$4(data.after_cursor) || !items.some((item) => item.sessionId === ref.sessionId && item.messageId === ref.messageId)) throw new ArkmePluginError("arko-history-contract-invalid", "上下文响应不完整", true, 502);
47636
47676
  const anchor = items.find((item) => item.sessionId === ref.sessionId && item.messageId === ref.messageId);
47637
47677
  anchor.messageRef = query.messageRef;
47638
47678
  return {
@@ -47695,7 +47735,7 @@ var ArkoService = class {
47695
47735
  if (turn.text !== text || options.sessionId !== void 0 && turn.sessionId !== options.sessionId || JSON.stringify(turn.images?.map((file) => file.fileRef) ?? []) !== JSON.stringify(options.imageFileRefs ?? []) || turn.replyToRunUid !== (options.replyToRunUid?.trim() || void 0) || turn.replyToAssistantMsgId !== options.replyToAssistantMsgId || options.modelRouteKey !== void 0 && turn.modelRouteKey !== options.modelRouteKey) throw new ArkmePluginError("arko-turn-conflict", "本轮发送内容已冻结,请确认原请求结果", false);
47696
47736
  if (previous.request !== void 0) return this.postArkoTurn(session, previous, options.waitMillis, options.signal);
47697
47737
  }
47698
- const sessionId = previous?.turn.sessionId ?? options.sessionId ?? (await this.arkoEnsureSession(options.signal)).sessionId;
47738
+ const sessionId = previous?.turn.sessionId ?? options.sessionId ?? (options.delegated !== void 0 ? await this.arkoEnsureDelegatedSession(session, options.delegated.scope, options.delegated.name, options.signal) : (await this.arkoEnsureSession(options.signal)).sessionId);
47699
47739
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
47700
47740
  const replyToRunUid = options.replyToRunUid?.trim() ?? "";
47701
47741
  const replyToAssistantMsgId = options.replyToAssistantMsgId;
@@ -47733,11 +47773,15 @@ var ArkoService = class {
47733
47773
  if (attachments.length !== imageFileRefs.length) throw new ArkmePluginError("arko-image-upload-incomplete", "图片上传未完成,请重试", true);
47734
47774
  if ((await this.runtime.requireSession()).userId !== session.userId) throw new ArkmePluginError("arko-account-changed", "账号已切换,本次发送已取消", false);
47735
47775
  }
47776
+ const delegatedScope = options.delegated?.scope?.trim();
47736
47777
  const body = {
47737
47778
  model: 2,
47738
47779
  session_id: sessionId,
47739
47780
  content: text,
47740
- extra: "{}",
47781
+ extra: options.delegated === void 0 ? "{}" : JSON.stringify({
47782
+ source: "dsh_agent",
47783
+ ...delegatedScope ? { dsh_session_id: delegatedScope } : {}
47784
+ }),
47741
47785
  ...timezone === void 0 || timezone.trim() === "" ? {} : { tz_inna: timezone.trim() },
47742
47786
  client_turn_uid: clientTurnUid,
47743
47787
  ...hasContinuationRun ? {
@@ -47813,9 +47857,9 @@ var ArkoService = class {
47813
47857
  if (error.code === "arkme-code-1108") throw new ArkmePluginError("arko-history-changed", "对话历史已更改,本次未发送;请刷新后重新发送", false, 409);
47814
47858
  throw new ArkmePluginError(error.code, error.message, false);
47815
47859
  });
47816
- const userMsgId = numberValue$25(accepted.user_msg_id);
47817
- const assistantMsgId = numberValue$25(accepted.assistant_msg_id);
47818
- const acceptedSessionId = numberValue$25(accepted.session_id) || sessionId;
47860
+ const userMsgId = numberValue$26(accepted.user_msg_id);
47861
+ const assistantMsgId = numberValue$26(accepted.assistant_msg_id);
47862
+ const acceptedSessionId = numberValue$26(accepted.session_id) || sessionId;
47819
47863
  if (!Number.isSafeInteger(acceptedSessionId) || acceptedSessionId <= 0 || !Number.isSafeInteger(userMsgId) || userMsgId <= 0 || !Number.isSafeInteger(assistantMsgId) || assistantMsgId <= 0) throw new ArkmePluginError("arko-ask-contract-invalid", "Arko 消息响应不完整", true, 502);
47820
47864
  const runUid = stringValue$4(accepted.run_uid).trim();
47821
47865
  if (runUid === "") throw new ArkmePluginError("arko-ask-contract-invalid", "Arko 消息响应缺少运行标识", true, 502);
@@ -47854,8 +47898,8 @@ var ArkoService = class {
47854
47898
  }, session, signal);
47855
47899
  const status = stringValue$4(data.status).trim();
47856
47900
  const normalizedRunUid = stringValue$4(data.run_uid).trim() || runUid.trim();
47857
- const sequence = numberValue$25(data.sequence);
47858
- const surfaceAssistantMsgId = numberValue$25(data.surface_assistant_msg_id);
47901
+ const sequence = numberValue$26(data.sequence);
47902
+ const surfaceAssistantMsgId = numberValue$26(data.surface_assistant_msg_id);
47859
47903
  const clientAction = optionalRecord$1(data.client_action);
47860
47904
  if (normalizedRunUid !== runUid.trim() || !ARKO_RUN_STATUSES.has(status) || !Number.isSafeInteger(sequence) || sequence < 0 || !Number.isSafeInteger(surfaceAssistantMsgId) || surfaceAssistantMsgId <= 0) throw new ArkmePluginError("arko-run-status-contract-invalid", "Arko 运行状态响应不完整", true, 502);
47861
47905
  return {
@@ -48089,6 +48133,225 @@ var ArkoService = class {
48089
48133
  }
48090
48134
  };
48091
48135
  //#endregion
48136
+ //#region src/services/memory-service.ts
48137
+ const MEMORY_SEARCH_MAX_QUERY_CHARS = 500;
48138
+ const MEMORY_SEARCH_DEFAULT_TOP_K = 8;
48139
+ const MEMORY_SEARCH_MAX_TOP_K = 8;
48140
+ const MEMORY_WRITE_MAX_FACTS = 5;
48141
+ const MEMORY_WRITE_MAX_FACT_CHARS = 200;
48142
+ const MEMORY_SUMMARY_LIST_LIMIT = 12;
48143
+ const MEMORY_SUMMARY_MAX_FACTS = 8;
48144
+ function numberValue$25(value) {
48145
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
48146
+ }
48147
+ function optionalString$3(value) {
48148
+ const trimmed = stringValue$4(value).trim();
48149
+ return trimmed === "" ? void 0 : trimmed;
48150
+ }
48151
+ function listValue$22(value) {
48152
+ return Array.isArray(value) ? value : [];
48153
+ }
48154
+ function cleanFactText(value) {
48155
+ return stringValue$4(value).replace(/[\u0000-\u001F\u007F\u2028\u2029]/g, " ").replace(/\s+/g, " ").trim();
48156
+ }
48157
+ function searchItemFromData(raw) {
48158
+ const item = objectValue$4(raw);
48159
+ const memoryId = stringValue$4(item.memory_id).trim();
48160
+ const fact = cleanFactText(item.fact);
48161
+ if (memoryId === "" || fact === "") return void 0;
48162
+ const layer = stringValue$4(item.layer).trim() || "long_term";
48163
+ const confidence = numberValue$25(item.confidence);
48164
+ const snapshotTs = numberValue$25(item.snapshot_ts);
48165
+ const sourceType = optionalString$3(item.source_type);
48166
+ const scope = optionalString$3(item.scope);
48167
+ const score = typeof item.score === "number" && Number.isFinite(item.score) ? item.score : void 0;
48168
+ const scoreReason = optionalString$3(item.score_reason);
48169
+ return {
48170
+ memoryId,
48171
+ layer,
48172
+ fact,
48173
+ confidence,
48174
+ snapshotTs,
48175
+ ...sourceType === void 0 ? {} : { sourceType },
48176
+ ...scope === void 0 ? {} : { scope },
48177
+ ...score === void 0 ? {} : { score },
48178
+ ...scoreReason === void 0 ? {} : { scoreReason }
48179
+ };
48180
+ }
48181
+ function extractOverviewFromV3Home(raw) {
48182
+ const snapshot = objectValue$4(raw.snapshot);
48183
+ const candidates = [
48184
+ snapshot.summary,
48185
+ snapshot.overview,
48186
+ snapshot.headline,
48187
+ raw.summary,
48188
+ raw.overview
48189
+ ];
48190
+ for (const candidate of candidates) {
48191
+ const cleaned = cleanFactText(candidate);
48192
+ if (cleaned !== "") return cleaned;
48193
+ }
48194
+ const sections = listValue$22(snapshot.sections ?? raw.sections);
48195
+ const highlights = [];
48196
+ for (const rawSection of sections) {
48197
+ const section = objectValue$4(rawSection);
48198
+ const direct = cleanFactText(section.summary ?? section.preview ?? section.headline);
48199
+ if (direct !== "") {
48200
+ highlights.push(direct);
48201
+ if (highlights.length >= 4) break;
48202
+ continue;
48203
+ }
48204
+ const previewItems = listValue$22(section.preview_items);
48205
+ for (const rawItem of previewItems) {
48206
+ const item = objectValue$4(rawItem);
48207
+ const state = stringValue$4(item.state).trim().toLowerCase();
48208
+ if (state === "deleted" || state === "retracted" || state === "pending_confirm") continue;
48209
+ const value = cleanFactText(item.value);
48210
+ if (value === "") continue;
48211
+ const label = cleanFactText(item.predicate_label);
48212
+ highlights.push(label !== "" && label !== "长期记忆" ? `${label}:${value}` : value);
48213
+ if (highlights.length >= 4) break;
48214
+ }
48215
+ if (highlights.length >= 4) break;
48216
+ }
48217
+ return highlights.length > 0 ? highlights.join(";") : void 0;
48218
+ }
48219
+ var MemoryService = class {
48220
+ runtime;
48221
+ constructor(runtime) {
48222
+ this.runtime = runtime;
48223
+ }
48224
+ async memorySearch(query, options = {}) {
48225
+ const normalizedQuery = query.trim();
48226
+ if (normalizedQuery === "" || [...normalizedQuery].length > MEMORY_SEARCH_MAX_QUERY_CHARS) throw new ArkmePluginError("memory-search-invalid", "长期记忆检索问题不能为空或超过 500 字", false, 400);
48227
+ const rawTopK = options.topK ?? MEMORY_SEARCH_DEFAULT_TOP_K;
48228
+ if (!Number.isSafeInteger(rawTopK) || rawTopK < 1 || rawTopK > MEMORY_SEARCH_MAX_TOP_K) throw new ArkmePluginError("memory-search-invalid", "top_k 必须在 1 到 8 之间", false, 400);
48229
+ const layer = options.layer?.trim();
48230
+ const scope = options.scope?.trim();
48231
+ const session = await this.runtime.requireSession();
48232
+ const payload = {
48233
+ query: normalizedQuery,
48234
+ top_k: rawTopK,
48235
+ intent: "agent_grounding",
48236
+ ...layer ? { layer } : {},
48237
+ ...scope ? { scope } : {}
48238
+ };
48239
+ const data = await this.runtime.authenticatedMemoryCorePost("/api/v1/memory/search", payload, session, options.signal, false);
48240
+ return {
48241
+ items: listValue$22(data.items).map(searchItemFromData).filter((item) => item !== void 0).slice(0, rawTopK),
48242
+ searchMode: stringValue$4(data.search_mode).trim() || "hybrid"
48243
+ };
48244
+ }
48245
+ async memoryWriteFacts(rawFacts, options = {}) {
48246
+ if (!Array.isArray(rawFacts) || rawFacts.length === 0 || rawFacts.length > MEMORY_WRITE_MAX_FACTS) throw new ArkmePluginError("memory-write-invalid", "请提供 1 到 5 条有效长期记忆事实", false, 400);
48247
+ const layer = (options.layer ?? "long_term").trim();
48248
+ if (layer !== "long_term" && layer !== "life_phase") throw new ArkmePluginError("memory-write-invalid", "layer 仅支持 long_term 或 life_phase", false, 400);
48249
+ const seen = /* @__PURE__ */ new Set();
48250
+ const facts = [];
48251
+ for (const raw of rawFacts) {
48252
+ if (typeof raw !== "string") throw new ArkmePluginError("memory-write-invalid", "长期记忆事实必须是字符串", false, 400);
48253
+ const cleaned = cleanFactText(raw);
48254
+ if (cleaned === "" || [...cleaned].length > MEMORY_WRITE_MAX_FACT_CHARS) throw new ArkmePluginError("memory-write-invalid", "每条长期记忆事实不能为空且不超过 200 字", false, 400);
48255
+ const key = cleaned.toLowerCase();
48256
+ if (seen.has(key)) continue;
48257
+ seen.add(key);
48258
+ facts.push(cleaned);
48259
+ }
48260
+ if (facts.length === 0) throw new ArkmePluginError("memory-write-invalid", "请提供至少 1 条有效长期记忆事实", false, 400);
48261
+ const session = await this.runtime.requireSession();
48262
+ const baseEventId = options.sourceEventId?.trim() ?? "";
48263
+ const snapshotTs = Date.now();
48264
+ const payload = {
48265
+ scope: "user",
48266
+ layer,
48267
+ facts: facts.map((fact, index) => ({
48268
+ fact,
48269
+ confidence: .85,
48270
+ snapshot_ts: snapshotTs,
48271
+ from_self: true,
48272
+ ...baseEventId === "" ? {} : { source_event_id: facts.length > 1 ? `${baseEventId}:${index + 1}` : baseEventId }
48273
+ }))
48274
+ };
48275
+ const data = await this.runtime.authenticatedMemoryCorePost("/api/v1/memory/write-facts", payload, session, options.signal, true);
48276
+ const items = listValue$22(data.items).map(searchItemFromData).filter((item) => item !== void 0);
48277
+ return {
48278
+ created: numberValue$25(data.created),
48279
+ updated: numberValue$25(data.updated),
48280
+ items
48281
+ };
48282
+ }
48283
+ async memoryDelete(memoryId, signal) {
48284
+ const normalizedId = memoryId.trim();
48285
+ if (normalizedId === "" || [...normalizedId].length > 128) throw new ArkmePluginError("memory-forget-invalid", "请提供有效的 memory_id", false, 400);
48286
+ const session = await this.runtime.requireSession();
48287
+ const data = await this.runtime.authenticatedMemoryCorePost("/api/v1/memory/delete", { memory_id: normalizedId }, session, signal, true);
48288
+ return {
48289
+ memoryId: stringValue$4(data.memory_id).trim() || normalizedId,
48290
+ status: stringValue$4(data.status).trim() || "deleted"
48291
+ };
48292
+ }
48293
+ async memoryCorrect(memoryId, reason, signal) {
48294
+ const normalizedId = memoryId.trim();
48295
+ if (normalizedId === "" || [...normalizedId].length > 128) throw new ArkmePluginError("memory-forget-invalid", "请提供有效的 memory_id", false, 400);
48296
+ const normalizedReason = cleanFactText(reason);
48297
+ if (normalizedReason === "" || [...normalizedReason].length > 200) throw new ArkmePluginError("memory-forget-invalid", "标记纠正时请提供 1 到 200 字的 reason", false, 400);
48298
+ const session = await this.runtime.requireSession();
48299
+ const data = await this.runtime.authenticatedMemoryCorePost("/api/v1/memory/correct", {
48300
+ memory_id: normalizedId,
48301
+ reason: normalizedReason
48302
+ }, session, signal, true);
48303
+ return {
48304
+ memoryId: stringValue$4(data.memory_id).trim() || normalizedId,
48305
+ status: stringValue$4(data.status).trim() || "corrected"
48306
+ };
48307
+ }
48308
+ /**
48309
+ * Builds a compact, cache-friendly summary of the signed-in user's long-term
48310
+ * memory facts (and V3 profile overview when published) for system prompt
48311
+ * injection. Fails soft per source so missing snapshots never break startup,
48312
+ * while rethrowing when every source fails so callers keep their last known
48313
+ * summary during transient outages.
48314
+ */
48315
+ async memorySummarySnapshot(signal) {
48316
+ const session = await this.runtime.requireSession();
48317
+ const [factsResult, overviewResult] = await Promise.allSettled([this.readTopDurableFacts(session, signal), this.readProfileV3Overview(session, signal)]);
48318
+ if (factsResult.status === "rejected" && overviewResult.status === "rejected") throw factsResult.reason;
48319
+ const facts = factsResult.status === "fulfilled" ? factsResult.value : [];
48320
+ const profileOverview = overviewResult.status === "fulfilled" ? overviewResult.value : void 0;
48321
+ return {
48322
+ facts,
48323
+ ...profileOverview === void 0 ? {} : { profileOverview }
48324
+ };
48325
+ }
48326
+ async readTopDurableFacts(session, signal) {
48327
+ const rows = listValue$22((await this.runtime.authenticatedMemoryCorePost("/api/v1/memory/list", { limit: MEMORY_SUMMARY_LIST_LIMIT }, session, signal, false)).items).map((raw) => objectValue$4(raw)).filter((item) => {
48328
+ const status = stringValue$4(item.status).trim().toLowerCase();
48329
+ if (status === "deleted" || status === "retracted") return false;
48330
+ if (item.from_self === false) return false;
48331
+ return cleanFactText(item.fact) !== "";
48332
+ }).sort((a, b) => {
48333
+ const confDiff = numberValue$25(b.confidence) - numberValue$25(a.confidence);
48334
+ if (Math.abs(confDiff) > .001) return confDiff;
48335
+ const timeA = Math.max(numberValue$25(a.last_seen_at), numberValue$25(a.snapshot_ts));
48336
+ return Math.max(numberValue$25(b.last_seen_at), numberValue$25(b.snapshot_ts)) - timeA;
48337
+ });
48338
+ const seen = /* @__PURE__ */ new Set();
48339
+ const facts = [];
48340
+ for (const row of rows) {
48341
+ const fact = cleanFactText(row.fact);
48342
+ const dedupeKey = fact.toLowerCase();
48343
+ if (seen.has(dedupeKey)) continue;
48344
+ seen.add(dedupeKey);
48345
+ facts.push(fact);
48346
+ if (facts.length >= MEMORY_SUMMARY_MAX_FACTS) break;
48347
+ }
48348
+ return facts;
48349
+ }
48350
+ async readProfileV3Overview(session, signal) {
48351
+ return extractOverviewFromV3Home(await this.runtime.authenticatedMemoryCorePost("/api/v1/personal-profile/v3/experience/home", {}, session, signal, false));
48352
+ }
48353
+ };
48354
+ //#endregion
48092
48355
  //#region src/services/arrangement-source-service.ts
48093
48356
  /** Resolves saved arrangement evidence against the current source owner's access rules. */
48094
48357
  var ArrangementSourceService = class {
@@ -115351,6 +115614,7 @@ var ArkmeService = class {
115351
115614
  recordExport;
115352
115615
  arkoTimeline;
115353
115616
  arko;
115617
+ memory;
115354
115618
  group;
115355
115619
  publicSocial;
115356
115620
  privateGroupCreate;
@@ -115953,6 +116217,7 @@ var ArkmeService = class {
115953
116217
  upload: (refs, signal) => this.filesOwner().uploadRefs(refs, signal),
115954
116218
  project: (raw, userId) => this.media.richContentBlocks(raw, userId)
115955
116219
  });
116220
+ this.memory = new MemoryService(this.runtime);
115956
116221
  this.commonGroups = new CommonGroupService(this.runtime, this.source);
115957
116222
  this.group = new GroupService(this.runtime, this.source, this.profile, { sendPrivateText: async (sourceRef, chatSessionUid, text, recordUid, relationUid, session, signal) => {
115958
116223
  await this.chat.sendChatSourceTextRaw(sourceRef, chatSessionUid, text, recordUid, relationUid, session, void 0, void 0, signal);
@@ -117362,10 +117627,10 @@ var ArkmeService = class {
117362
117627
  async arkoExport(signal, onProgress) {
117363
117628
  return this.arko.arkoExport(signal, onProgress);
117364
117629
  }
117365
- async arkoHistoryPage(limit = 50, offset = 0, signal) {
117630
+ async arkoHistoryPage(limit = 50, offset = 0, signal, sessionId) {
117366
117631
  const { userId } = await this.runtime.requireSession();
117367
- const page = await this.arko.arkoHistoryPage(limit, offset, signal);
117368
- if (offset === 0) {
117632
+ const page = await this.arko.arkoHistoryPage(limit, offset, signal, sessionId);
117633
+ if (offset === 0 && sessionId === void 0) {
117369
117634
  const latest = [...page.items].filter((item) => item.text.trim() !== "" || item.contentBlocks?.length).sort((a, b) => b.createdAtMillis - a.createdAtMillis || b.messageId - a.messageId)[0];
117370
117635
  if (latest !== void 0) this.directory.rememberSpecial({ arkoPreview: {
117371
117636
  text: latest.text.trim() || "[图片]",
@@ -117395,6 +117660,37 @@ var ArkmeService = class {
117395
117660
  async arkoCancel(sessionId, assistantMsgId, runUid, signal) {
117396
117661
  return await this.arko.arkoCancel(sessionId, assistantMsgId, runUid, signal);
117397
117662
  }
117663
+ memoryChangedListeners = /* @__PURE__ */ new Set();
117664
+ onMemoryChanged(listener) {
117665
+ this.memoryChangedListeners.add(listener);
117666
+ return () => {
117667
+ this.memoryChangedListeners.delete(listener);
117668
+ };
117669
+ }
117670
+ async memorySearch(query, options = {}) {
117671
+ return await this.memory.memorySearch(query, options);
117672
+ }
117673
+ async memoryWriteFacts(facts, options = {}) {
117674
+ const { userId } = await this.runtime.requireSession();
117675
+ const result = await this.memory.memoryWriteFacts(facts, options);
117676
+ if (result.created > 0 || result.updated > 0) for (const listener of this.memoryChangedListeners) listener(userId);
117677
+ return result;
117678
+ }
117679
+ async memoryDelete(memoryId, signal) {
117680
+ const { userId } = await this.runtime.requireSession();
117681
+ const result = await this.memory.memoryDelete(memoryId, signal);
117682
+ for (const listener of this.memoryChangedListeners) listener(userId);
117683
+ return result;
117684
+ }
117685
+ async memoryCorrect(memoryId, reason, signal) {
117686
+ const { userId } = await this.runtime.requireSession();
117687
+ const result = await this.memory.memoryCorrect(memoryId, reason, signal);
117688
+ for (const listener of this.memoryChangedListeners) listener(userId);
117689
+ return result;
117690
+ }
117691
+ async memorySummarySnapshot(signal) {
117692
+ return await this.memory.memorySummarySnapshot(signal);
117693
+ }
117398
117694
  async aiVideoResolveSelection(recordingUid, utterances, signal) {
117399
117695
  return await this.aiVideo.aiVideoResolveSelection(recordingUid, utterances, signal);
117400
117696
  }