MCPcopy Create free account
hub / github.com/apache/maka / applyMakaSessionEventToTranscript

Function applyMakaSessionEventToTranscript

packages/cli/src/pi-transcript.ts:511–805  ·  view source on GitHub ↗
(
  state: MakaPiTranscriptState,
  event: SessionEvent,
)

Source from the content-addressed store, hash-verified

509}
510
511export 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,

Callers 4

runAgentTurnFunction · 0.85
resumeSessionFunction · 0.85

Calls 15

projectToolActivityArgsFunction · 0.90
appendAssistantTextFunction · 0.85
setAssistantTextFunction · 0.85
appendThinkingFunction · 0.85
setThinkingFunction · 0.85
readArgsRefFunction · 0.85
findShellRunParentFunction · 0.85
createProgressBufferFunction · 0.85
createOutputBufferFunction · 0.85
formatToolResultContentFunction · 0.85
applyOwnShellRunResultFunction · 0.85

Tested by

no test coverage detected