( blocks: ContentBlock[], targetAgentId: string, updateFn: (block: ContentBlock) => ContentBlock, )
| 321 | * Helper function to recursively update blocks by target agent ID. |
| 322 | */ |
| 323 | export 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. |
no outgoing calls
no test coverage detected