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

Function updateBlocksRecursively

cli/src/utils/message-block-helpers.ts:323–352  ·  view source on GitHub ↗
(
  blocks: ContentBlock[],
  targetAgentId: string,
  updateFn: (block: ContentBlock) => ContentBlock,
)

Source from the content-addressed store, hash-verified

321 * Helper function to recursively update blocks by target agent ID.
322 */
323export const updateBlocksRecursively = (
324 blocks: ContentBlock[],
325 targetAgentId: string,
326 updateFn: (block: ContentBlock) => ContentBlock,
327): ContentBlock[] => {
328 let foundTarget = false
329 const result = blocks.map((block) => {
330 if (block.type === 'agent' && block.agentId === targetAgentId) {
331 foundTarget = true
332 return updateFn(block)
333 }
334 if (block.type === 'agent' && block.blocks) {
335 const updatedBlocks = updateBlocksRecursively(
336 block.blocks,
337 targetAgentId,
338 updateFn,
339 )
340 if (updatedBlocks !== block.blocks) {
341 foundTarget = true
342 return {
343 ...block,
344 blocks: updatedBlocks,
345 }
346 }
347 }
348 return block
349 })
350
351 return foundTarget ? result : blocks
352}
353
354/**
355 * Result from nestBlockUnderParent indicating whether the parent was found.

Callers 8

updateAgentTextFunction · 0.90
appendToolToAgentBlockFunction · 0.90
markAgentCompleteFunction · 0.90
nestBlockUnderParentFunction · 0.70
moveSpawnAgentBlockFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected