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

Function transformAskUserBlocks

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

Source from the content-addressed store, hash-verified

537 * Recursively processes nested agent blocks.
538 */
539export const transformAskUserBlocks = (
540 blocks: ContentBlock[],
541 options: TransformAskUserOptions,
542): ContentBlock[] => {
543 const { toolCallId, resultValue } = options
544
545 return blocks.map((block) => {
546 if (
547 block.type === 'tool' &&
548 block.toolCallId === toolCallId &&
549 block.toolName === 'ask_user'
550 ) {
551 const skipped = (resultValue as any)?.skipped
552 const answers = (resultValue as any)?.answers
553 const questions = block.input.questions
554
555 if (!answers && !skipped) {
556 // If no result data, keep as tool block (fallback)
557 return block
558 }
559
560 return {
561 type: 'ask-user',
562 toolCallId,
563 questions,
564 answers,
565 skipped,
566 } as AskUserContentBlock
567 }
568
569 if (block.type === 'agent' && block.blocks) {
570 const updatedBlocks = transformAskUserBlocks(block.blocks, options)
571 if (updatedBlocks !== block.blocks) {
572 return { ...block, blocks: updatedBlocks }
573 }
574 }
575 return block
576 })
577}
578
579/**
580 * Options for updating tool blocks with output.

Callers 3

handleToolResultFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected