* Builds a filie history snapshot chain from the conversation
( fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, conversation: TranscriptMessage[], )
| 2292 | * Builds a filie history snapshot chain from the conversation |
| 2293 | */ |
| 2294 | function buildFileHistorySnapshotChain( |
| 2295 | fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, |
| 2296 | conversation: TranscriptMessage[], |
| 2297 | ): FileHistorySnapshot[] { |
| 2298 | const snapshots: FileHistorySnapshot[] = [] |
| 2299 | // messageId → last index in snapshots[] for O(1) update lookup |
| 2300 | const indexByMessageId = new Map<string, number>() |
| 2301 | for (const message of conversation) { |
| 2302 | const snapshotMessage = fileHistorySnapshots.get(message.uuid) |
| 2303 | if (!snapshotMessage) { |
| 2304 | continue |
| 2305 | } |
| 2306 | const { snapshot, isSnapshotUpdate } = snapshotMessage |
| 2307 | const existingIndex = isSnapshotUpdate |
| 2308 | ? indexByMessageId.get(snapshot.messageId) |
| 2309 | : undefined |
| 2310 | if (existingIndex === undefined) { |
| 2311 | indexByMessageId.set(snapshot.messageId, snapshots.length) |
| 2312 | snapshots.push(snapshot) |
| 2313 | } else { |
| 2314 | snapshots[existingIndex] = snapshot |
| 2315 | } |
| 2316 | } |
| 2317 | return snapshots |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * Builds an attribution snapshot chain from the conversation. |
no test coverage detected