* Builds a filie history snapshot chain from the conversation
( fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, conversation: TranscriptMessage[], )
| 2406 | * Builds a filie history snapshot chain from the conversation |
| 2407 | */ |
| 2408 | function buildFileHistorySnapshotChain( |
| 2409 | fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, |
| 2410 | conversation: TranscriptMessage[], |
| 2411 | ): FileHistorySnapshot[] { |
| 2412 | const snapshots: FileHistorySnapshot[] = [] |
| 2413 | // messageId → last index in snapshots[] for O(1) update lookup |
| 2414 | const indexByMessageId = new Map<string, number>() |
| 2415 | for (const message of conversation) { |
| 2416 | const snapshotMessage = fileHistorySnapshots.get(message.uuid) |
| 2417 | if (!snapshotMessage) { |
| 2418 | continue |
| 2419 | } |
| 2420 | const { snapshot, isSnapshotUpdate } = snapshotMessage |
| 2421 | const existingIndex = isSnapshotUpdate |
| 2422 | ? indexByMessageId.get(snapshot.messageId) |
| 2423 | : undefined |
| 2424 | if (existingIndex === undefined) { |
| 2425 | indexByMessageId.set(snapshot.messageId, snapshots.length) |
| 2426 | snapshots.push(snapshot) |
| 2427 | } else { |
| 2428 | snapshots[existingIndex] = snapshot |
| 2429 | } |
| 2430 | } |
| 2431 | return snapshots |
| 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * Builds an attribution snapshot chain from the conversation. |
no test coverage detected