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

Function extractRecursively

cli/src/utils/message-block-helpers.ts:441–457  ·  view source on GitHub ↗
(blocks: ContentBlock[])

Source from the content-addressed store, hash-verified

439 let extractedBlock: ContentBlock | null = null
440
441 const extractRecursively = (blocks: ContentBlock[]): ContentBlock[] => {
442 const result: ContentBlock[] = []
443 for (const block of blocks) {
444 if (block.type === 'agent' && block.agentId === targetAgentId) {
445 extractedBlock = block
446 // Don't add to result - we're extracting it
447 } else if (block.type === 'agent' && block.blocks) {
448 result.push({
449 ...block,
450 blocks: extractRecursively(block.blocks),
451 })
452 } else {
453 result.push(block)
454 }
455 }
456 return result
457 }
458
459 const remainingBlocks = extractRecursively(blocks)
460 return { remainingBlocks, extractedBlock }

Callers 1

extractBlockByIdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected