MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / updateToolBlockWithOutput

Function updateToolBlockWithOutput

cli/src/utils/message-block-helpers.ts:592–622  ·  view source on GitHub ↗
(
  blocks: ContentBlock[],
  options: UpdateToolBlockOptions,
)

Source from the content-addressed store, hash-verified

590 * Recursively processes nested agent blocks.
591 */
592export const updateToolBlockWithOutput = (
593 blocks: ContentBlock[],
594 options: UpdateToolBlockOptions,
595): ContentBlock[] => {
596 const { toolCallId, toolOutput } = options
597
598 return blocks.map((block) => {
599 if (block.type === 'tool' && block.toolCallId === toolCallId) {
600 let output: string
601 if (block.toolName === 'run_terminal_command') {
602 const parsed = (toolOutput?.[0] as any)?.value
603 if (parsed?.stdout || parsed?.stderr) {
604 output = (parsed.stdout || '') + (parsed.stderr || '')
605 } else {
606 output = formatToolOutput(toolOutput)
607 }
608 } else {
609 output = formatToolOutput(toolOutput)
610 }
611 return { ...block, output }
612 } else if (block.type === 'agent' && block.blocks) {
613 const updatedBlocks = updateToolBlockWithOutput(block.blocks, options)
614 // Avoid creating new block if nested blocks didn't change
615 if (isEqual(block.blocks, updatedBlocks)) {
616 return block
617 }
618 return { ...block, blocks: updatedBlocks }
619 }
620 return block
621 })
622}

Callers 3

handleToolResultFunction · 0.90

Calls 1

formatToolOutputFunction · 0.90

Tested by

no test coverage detected