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