( state: MakaPiTranscriptState, turnId: string, messages: readonly StoredMessage[], )
| 342 | * live events without applying session-switch reset semantics. |
| 343 | */ |
| 344 | export function reconcileToolsWithStoredMessages( |
| 345 | state: MakaPiTranscriptState, |
| 346 | turnId: string, |
| 347 | messages: readonly StoredMessage[], |
| 348 | ): boolean { |
| 349 | const turnMessages = messages.filter((message) => message.turnId === turnId); |
| 350 | const durableTools = new Map( |
| 351 | foldStoredShellRunChildren( |
| 352 | materializeSession(turnMessages).items.flatMap(chatItemToTranscriptEntries), |
| 353 | ) |
| 354 | .filter( |
| 355 | (entry): entry is Extract<MakaPiTranscriptEntry, { kind: 'tool' }> => entry.kind === 'tool', |
| 356 | ) |
| 357 | .map((entry) => [entry.toolUseId, entry]), |
| 358 | ); |
| 359 | let changed = false; |
| 360 | const reconciled: MakaPiTranscriptEntry[] = []; |
| 361 | for (const entry of state.entries) { |
| 362 | if (entry.kind !== 'tool' || entry.turnId !== turnId) { |
| 363 | reconciled.push(entry); |
| 364 | continue; |
| 365 | } |
| 366 | const durable = durableTools.get(entry.toolUseId); |
| 367 | if (!durable) { |
| 368 | if (!entryInLiveViewport(state, entry)) { |
| 369 | entry.hidden = true; |
| 370 | reconciled.push(entry); |
| 371 | } |
| 372 | changed = true; |
| 373 | continue; |
| 374 | } |
| 375 | entry.toolName = durable.toolName; |
| 376 | entry.title = durable.title; |
| 377 | entry.input = structuredClone(durable.input); |
| 378 | entry.result = durable.result ? structuredClone(durable.result) : undefined; |
| 379 | entry.output = durable.output; |
| 380 | entry.durationMs = durable.durationMs; |
| 381 | entry.status = durable.status; |
| 382 | entry.hidden = durable.hidden; |
| 383 | entry.resultVersion += 1; |
| 384 | changed = true; |
| 385 | reconciled.push(entry); |
| 386 | } |
| 387 | state.entries = reconciled; |
| 388 | return changed; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * True when the entry will render inside the live viewport, or has not been |
no test coverage detected