返回 DeepSeek-Reasonix
transcriptHistoryFetch.ts
根目录 / desktop / frontend / src / lib / transcriptHistoryFetch.ts
1 import { asArray } from "./array";
2 import { loadPreparedHistory, type HistoryPreparationWait } from "./historyPreparation";
3 import { recordBytes } from "./transcriptRecordBytes";
4 import { noteHistoryPage } from "./sessionDiagnostics";
5 import type { HistoryEntry, HistorySlice } from "./types";
6
7 // Keep preparation pending while preserving the existing content-free metrics.
8 export async function fetchPreparedHistorySlice(load: () => Promise<HistorySlice>, current: () => boolean, wait?: HistoryPreparationWait): Promise<HistorySlice | undefined> {
9 const startedAt = performance.now();
10 const slice = await loadPreparedHistory(load, current, wait);
11 if (!slice) return undefined;
12 if (slice.error?.trim()) throw new Error(slice.error.trim());
13 const entries = asArray<HistoryEntry>(slice.entries);
14 noteHistoryPage({ entries: entries.length, inlineBytes: entries.reduce((bytes, entry) => bytes + recordBytes(entry.message), 0),
15 durationMs: Math.max(0, performance.now() - startedAt), stale: Boolean(slice.stale), source: slice.source ?? "" });
16 return slice;
17 }
18
18 lines TYPESCRIPT