
























@@ -15,7 +15,6 @@ import {
1515import { jsonUtf8Bytes } from "../infra/json-utf8-bytes.js";
1616import { hasInterSessionUserProvenance } from "../sessions/input-provenance.js";
1717import { extractAssistantVisibleText } from "../shared/chat-message-content.js";
18-import { escapeRegExp } from "../shared/regexp.js";
1918import { estimateStringChars, estimateTokensFromChars } from "../utils/cjk-chars.js";
2019import { stripInlineDirectiveTagsForDisplay } from "../utils/directive-tags.js";
2120import { extractToolCallNames, hasToolCall } from "../utils/transcript-tools.js";
@@ -28,6 +27,11 @@ import {
2827readSessionTranscriptIndex,
2928type IndexedTranscriptEntry,
3029} from "./session-transcript-index.fs.js";
30+import {
31+extractJsonNullableStringFieldPrefix,
32+extractJsonNumberFieldPrefix,
33+extractJsonStringFieldPrefix,
34+} from "./session-transcript-json.js";
3135import type { SessionPreviewItem } from "./session-utils.types.js";
32363337type SessionTitleFields = {
@@ -297,40 +301,6 @@ function isOversizedTranscriptLine(line: string): boolean {
297301return Buffer.byteLength(line, "utf8") > MAX_TRANSCRIPT_PARSE_LINE_BYTES;
298302}
299303300-function extractJsonStringFieldPrefix(prefix: string, field: string): string | undefined {
301-const match = new RegExp(`"${escapeRegExp(field)}"\\s*:\\s*"((?:\\\\.|[^"\\\\])*)"`).exec(prefix);
302-if (!match) {
303-return undefined;
304-}
305-try {
306-const decoded = JSON.parse(`"${match[1]}"`) as unknown;
307-return normalizeTailEntryString(decoded);
308-} catch {
309-return undefined;
310-}
311-}
312-313-function extractJsonNullableStringFieldPrefix(
314-prefix: string,
315-field: string,
316-): string | null | undefined {
317-if (new RegExp(`"${escapeRegExp(field)}"\\s*:\\s*null`).test(prefix)) {
318-return null;
319-}
320-return extractJsonStringFieldPrefix(prefix, field);
321-}
322-323-function extractJsonNumberFieldPrefix(prefix: string, field: string): number | undefined {
324-const match = new RegExp(
325-`"${escapeRegExp(field)}"\\s*:\\s*(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)`,
326-).exec(prefix);
327-if (!match) {
328-return undefined;
329-}
330-const decoded = Number(match[1]);
331-return Number.isFinite(decoded) ? decoded : undefined;
332-}
333-334304function buildOversizedTranscriptRecord(line: string): TailTranscriptRecord {
335305const prefix = line.slice(0, OVERSIZED_TRANSCRIPT_METADATA_PREFIX_CHARS);
336306const messageMatch = /"message"\s*:/.exec(prefix);
@@ -356,10 +326,6 @@ function buildOversizedTranscriptRecord(line: string): TailTranscriptRecord {
356326return { record };
357327}
358328359-function normalizeTailEntryString(value: unknown): string | undefined {
360-return typeof value === "string" && value.trim().length > 0 ? value : undefined;
361-}
362-363329function parseTailTranscriptRecord(line: string): TailTranscriptRecord | null {
364330if (isOversizedTranscriptLine(line)) {
365331return buildOversizedTranscriptRecord(line);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。