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

Function nestBlockUnderParent

cli/src/utils/message-block-helpers.ts:365–387  ·  view source on GitHub ↗
(
  blocks: ContentBlock[],
  parentAgentId: string,
  blockToNest: ContentBlock,
)

Source from the content-addressed store, hash-verified

363 * Nests a block under a parent agent, or returns it at top level if parent not found.
364 */
365export const nestBlockUnderParent = (
366 blocks: ContentBlock[],
367 parentAgentId: string,
368 blockToNest: ContentBlock,
369): NestBlockResult => {
370 let parentFound = false
371 const updatedBlocks = updateBlocksRecursively(
372 blocks,
373 parentAgentId,
374 (parentBlock) => {
375 if (parentBlock.type !== 'agent') {
376 return parentBlock
377 }
378 parentFound = true
379 return {
380 ...parentBlock,
381 blocks: [...(parentBlock.blocks || []), blockToNest],
382 }
383 },
384 )
385
386 return { blocks: updatedBlocks, parentFound }
387}
388
389/**
390 * Checks if a block with the given targetId exists anywhere in the children of the blocks.

Callers 3

handleSubagentStartFunction · 0.90
moveSpawnAgentBlockFunction · 0.85

Calls 1

updateBlocksRecursivelyFunction · 0.70

Tested by

no test coverage detected