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