( blocks: ContentBlock[], targetAgentId: string, )
| 433 | * Returns the remaining blocks and the extracted block (if found). |
| 434 | */ |
| 435 | export const extractBlockById = ( |
| 436 | blocks: ContentBlock[], |
| 437 | targetAgentId: string, |
| 438 | ): { remainingBlocks: ContentBlock[]; extractedBlock: ContentBlock | null } => { |
| 439 | let extractedBlock: ContentBlock | null = null |
| 440 | |
| 441 | const extractRecursively = (blocks: ContentBlock[]): ContentBlock[] => { |
| 442 | const result: ContentBlock[] = [] |
| 443 | for (const block of blocks) { |
| 444 | if (block.type === 'agent' && block.agentId === targetAgentId) { |
| 445 | extractedBlock = block |
| 446 | // Don't add to result - we're extracting it |
| 447 | } else if (block.type === 'agent' && block.blocks) { |
| 448 | result.push({ |
| 449 | ...block, |
| 450 | blocks: extractRecursively(block.blocks), |
| 451 | }) |
| 452 | } else { |
| 453 | result.push(block) |
| 454 | } |
| 455 | } |
| 456 | return result |
| 457 | } |
| 458 | |
| 459 | const remainingBlocks = extractRecursively(blocks) |
| 460 | return { remainingBlocks, extractedBlock } |
| 461 | } |
| 462 | |
| 463 | export const moveSpawnAgentBlock = ( |
| 464 | blocks: ContentBlock[], |
no test coverage detected