( state: MakaPiTranscriptState, event: SessionEvent, )
| 509 | } |
| 510 | |
| 511 | export function applyMakaSessionEventToTranscript( |
| 512 | state: MakaPiTranscriptState, |
| 513 | event: SessionEvent, |
| 514 | ): void { |
| 515 | if ( |
| 516 | event.type === 'text_delta' || |
| 517 | event.type === 'text_complete' || |
| 518 | event.type === 'thinking_delta' || |
| 519 | event.type === 'thinking_complete' || |
| 520 | event.type === 'tool_start' || |
| 521 | event.type === 'error' || |
| 522 | event.type === 'abort' || |
| 523 | event.type === 'complete' |
| 524 | ) { |
| 525 | state.providerRetry = undefined; |
| 526 | } |
| 527 | switch (event.type) { |
| 528 | case 'text_delta': |
| 529 | appendAssistantText(state, event.messageId, event.text); |
| 530 | break; |
| 531 | |
| 532 | case 'text_complete': |
| 533 | if (!setAssistantText(state, event.messageId, event.text) && event.text) { |
| 534 | appendAssistantText(state, event.messageId, event.text); |
| 535 | } |
| 536 | break; |
| 537 | |
| 538 | case 'thinking_delta': |
| 539 | appendThinking(state, event.messageId, event.text); |
| 540 | break; |
| 541 | |
| 542 | case 'thinking_complete': |
| 543 | if (event.text) setThinking(state, event.messageId, event.text); |
| 544 | break; |
| 545 | |
| 546 | case 'tool_start': { |
| 547 | // A Read / StopBackgroundTask aimed at a ref a visible Bash card owns is |
| 548 | // internal polling of that run: it never gets a row, so an active polling |
| 549 | // loop cannot flicker cards in and out of the transcript. The result |
| 550 | // folds into the parent at tool_result. A poll is folded only when its |
| 551 | // parent card already carries the run's shell_run result — otherwise it |
| 552 | // renders normally and the tool_result fold below still applies. |
| 553 | if (event.toolName === 'Read' || event.toolName === 'StopBackgroundTask') { |
| 554 | const ref = readArgsRef(event.args); |
| 555 | if (ref && findShellRunParent(state, ref, event.toolUseId)) { |
| 556 | state.pendingShellRunPolls.set(event.toolUseId, { |
| 557 | toolName: event.toolName, |
| 558 | ...(event.displayName ? { title: event.displayName } : {}), |
| 559 | input: projectToolActivityArgs(event.toolName, event.args), |
| 560 | }); |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | state.entries.push({ |
| 565 | kind: 'tool', |
| 566 | turnId: event.turnId, |
| 567 | toolUseId: event.toolUseId, |
| 568 | toolName: event.toolName, |
no test coverage detected