返回 DeepSeek-Reasonix
transcriptRecordBytes.ts
根目录 / desktop / frontend / src / lib / transcriptRecordBytes.ts
1 import type { HistoryMessage } from "./types";
2
3 // recordBytes approximates the retained UTF-16 size of a record's inline text
4 // (the same fields the Go side counts for its slice byte budget).
5 export function recordBytes(m: HistoryMessage): number {
6 let chars =
7 (m.content?.length ?? 0) +
8 (m.reasoning?.length ?? 0) +
9 (m.submitText?.length ?? 0) +
10 (m.detail?.length ?? 0) +
11 (m.code?.length ?? 0) +
12 (m.summary?.length ?? 0) +
13 (m.archive?.length ?? 0) +
14 (m.toolResultError?.length ?? 0) +
15 (m.toolCallId?.length ?? 0) +
16 (m.toolName?.length ?? 0) +
17 (m.role?.length ?? 0);
18 if (m.completionReceipt) chars += JSON.stringify(m.completionReceipt).length;
19 if (m.completionSummary) chars += JSON.stringify(m.completionSummary).length;
20 for (const tc of m.toolCalls ?? []) {
21 if (tc.resultObservation) chars += JSON.stringify(tc.resultObservation).length;
22 chars +=
23 (tc.arguments?.length ?? 0) +
24 (tc.subject?.length ?? 0) +
25 (tc.summary?.length ?? 0) +
26 (tc.diff?.length ?? 0) +
27 (tc.id?.length ?? 0) +
28 (tc.name?.length ?? 0);
29 }
30 return chars * 2;
31 }
32
32 lines TYPESCRIPT