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

Function checkBlockIsUnderParent

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

Source from the content-addressed store, hash-verified

410 * Checks if a block with the given agentId is already nested under the specified parent.
411 */
412const checkBlockIsUnderParent = (
413 blocks: ContentBlock[],
414 targetAgentId: string,
415 parentAgentId: string,
416): boolean => {
417 for (const block of blocks) {
418 if (block.type === 'agent' && block.agentId === parentAgentId) {
419 // Found the parent, check if target is anywhere in its children
420 return findBlockInChildren(block.blocks || [], targetAgentId)
421 } else if (block.type === 'agent' && block.blocks) {
422 // Recurse into other agent blocks to find the parent
423 if (checkBlockIsUnderParent(block.blocks, targetAgentId, parentAgentId)) {
424 return true
425 }
426 }
427 }
428 return false
429}
430
431/**
432 * Extracts a block with given agentId from nested blocks structure.

Callers 1

moveSpawnAgentBlockFunction · 0.85

Calls 1

findBlockInChildrenFunction · 0.85

Tested by

no test coverage detected