( blocks: ContentBlock[], parentAgentId: string, blockToNest: ContentBlock, )
| 363 | * Nests a block under a parent agent, or returns it at top level if parent not found. |
| 364 | */ |
| 365 | export 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. |
no test coverage detected