* Builds a filie history snapshot chain from the conversation
( fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, conversation: TranscriptMessage[], )
| 2247 | * Builds a filie history snapshot chain from the conversation |
| 2248 | */ |
| 2249 | function buildFileHistorySnapshotChain( |
| 2250 | fileHistorySnapshots: Map<UUID, FileHistorySnapshotMessage>, |
| 2251 | conversation: TranscriptMessage[], |
| 2252 | ): FileHistorySnapshot[] { |
| 2253 | const snapshots: FileHistorySnapshot[] = [] |
| 2254 | // messageId → last index in snapshots[] for O(1) update lookup |
| 2255 | const indexByMessageId = new Map<string, number>() |
| 2256 | for (const message of conversation) { |
| 2257 | const snapshotMessage = fileHistorySnapshots.get(message.uuid) |
| 2258 | if (!snapshotMessage) { |
| 2259 | continue |
| 2260 | } |
| 2261 | const { snapshot, isSnapshotUpdate } = snapshotMessage |
| 2262 | const existingIndex = isSnapshotUpdate |
| 2263 | ? indexByMessageId.get(snapshot.messageId) |
| 2264 | : undefined |
| 2265 | if (existingIndex === undefined) { |
| 2266 | indexByMessageId.set(snapshot.messageId, snapshots.length) |
| 2267 | snapshots.push(snapshot) |
| 2268 | } else { |
| 2269 | snapshots[existingIndex] = snapshot |
| 2270 | } |
| 2271 | } |
| 2272 | return snapshots |
| 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * Builds an attribution snapshot chain from the conversation. |
no test coverage detected