@@ -14,6 +14,7 @@ import type { SessionTranscriptUpdate } from "../../sessions/transcript-events.j
|
14 | 14 | import { getRuntimeConfig } from "../io.js"; |
15 | 15 | import type { OpenClawConfig } from "../types.openclaw.js"; |
16 | 16 | import { formatSessionArchiveTimestamp } from "./artifacts.js"; |
| 17 | +import { extractGeneratedTranscriptSessionId } from "./generated-transcript-session-id.js"; |
17 | 18 | import { |
18 | 19 | resolveSessionFilePath, |
19 | 20 | resolveSessionFilePathOptions, |
@@ -915,34 +916,6 @@ function classifyGeneratedTranscriptCandidate(
|
915 | 916 | return transcriptSessionId === sessionId ? "current" : "stale"; |
916 | 917 | } |
917 | 918 | |
918 | | -function extractGeneratedTranscriptSessionId(sessionFile?: string): string | undefined { |
919 | | -const trimmed = sessionFile?.trim(); |
920 | | -if (!trimmed) { |
921 | | -return undefined; |
922 | | -} |
923 | | -const base = path.basename(trimmed); |
924 | | -if (!base.endsWith(".jsonl")) { |
925 | | -return undefined; |
926 | | -} |
927 | | -const withoutExt = base.slice(0, -".jsonl".length); |
928 | | -const topicIndex = withoutExt.indexOf("-topic-"); |
929 | | -if (topicIndex > 0) { |
930 | | -const topicSessionId = withoutExt.slice(0, topicIndex); |
931 | | -return looksLikeGeneratedSessionId(topicSessionId) ? topicSessionId : undefined; |
932 | | -} |
933 | | -const forkMatch = withoutExt.match( |
934 | | -/^(\d{4}-\d{2}-\d{2}T[\w-]+(?:Z|[+-]\d{2}(?:-\d{2})?)?)_(.+)$/, |
935 | | -); |
936 | | -if (forkMatch?.[2]) { |
937 | | -return looksLikeGeneratedSessionId(forkMatch[2]) ? forkMatch[2] : undefined; |
938 | | -} |
939 | | -return looksLikeGeneratedSessionId(withoutExt) ? withoutExt : undefined; |
940 | | -} |
941 | | - |
942 | | -function looksLikeGeneratedSessionId(value: string): boolean { |
943 | | -return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value); |
944 | | -} |
945 | | - |
946 | 919 | /** |
947 | 920 | * Persists one logical transcript turn through the current file-backed writer. |
948 | 921 | * The file implementation resolves/rebinds the transcript file, holds one |
|