( filePath: string, )
| 2293 | * @throws Error if file doesn't exist or contains invalid data |
| 2294 | */ |
| 2295 | export async function loadTranscriptFromFile( |
| 2296 | filePath: string, |
| 2297 | ): Promise<LogOption> { |
| 2298 | if (filePath.endsWith('.jsonl')) { |
| 2299 | const { |
| 2300 | messages, |
| 2301 | summaries, |
| 2302 | customTitles, |
| 2303 | tags, |
| 2304 | fileHistorySnapshots, |
| 2305 | attributionSnapshots, |
| 2306 | contextCollapseCommits, |
| 2307 | contextCollapseSnapshot, |
| 2308 | leafUuids, |
| 2309 | contentReplacements, |
| 2310 | worktreeStates, |
| 2311 | } = await loadTranscriptFile(filePath) |
| 2312 | |
| 2313 | if (messages.size === 0) { |
| 2314 | throw new Error('No messages found in JSONL file') |
| 2315 | } |
| 2316 | |
| 2317 | // Find the most recent leaf message using pre-computed leaf UUIDs |
| 2318 | const leafMessage = findLatestMessage(messages.values(), msg => |
| 2319 | leafUuids.has(msg.uuid), |
| 2320 | ) |
| 2321 | |
| 2322 | if (!leafMessage) { |
| 2323 | throw new Error('No valid conversation chain found in JSONL file') |
| 2324 | } |
| 2325 | |
| 2326 | // Build the conversation chain backwards from leaf to root |
| 2327 | const transcript = buildConversationChain(messages, leafMessage) |
| 2328 | |
| 2329 | const summary = summaries.get(leafMessage.uuid) |
| 2330 | const customTitle = customTitles.get(leafMessage.sessionId as UUID) |
| 2331 | const tag = tags.get(leafMessage.sessionId as UUID) |
| 2332 | const sessionId = leafMessage.sessionId as UUID |
| 2333 | return { |
| 2334 | ...convertToLogOption( |
| 2335 | transcript, |
| 2336 | 0, |
| 2337 | summary, |
| 2338 | customTitle, |
| 2339 | buildFileHistorySnapshotChain(fileHistorySnapshots, transcript), |
| 2340 | tag, |
| 2341 | filePath, |
| 2342 | buildAttributionSnapshotChain(attributionSnapshots, transcript), |
| 2343 | undefined, |
| 2344 | contentReplacements.get(sessionId) ?? [], |
| 2345 | ), |
| 2346 | contextCollapseCommits: contextCollapseCommits.filter( |
| 2347 | e => e.sessionId === sessionId, |
| 2348 | ), |
| 2349 | contextCollapseSnapshot: |
| 2350 | contextCollapseSnapshot?.sessionId === sessionId |
| 2351 | ? contextCollapseSnapshot |
| 2352 | : undefined, |
no test coverage detected