( blocks: ContentBlock[], )
| 489 | * Also closes any open native reasoning blocks so they don't appear "streaming". |
| 490 | */ |
| 491 | export const markRunningAgentsAsCancelled = ( |
| 492 | blocks: ContentBlock[], |
| 493 | ): ContentBlock[] => { |
| 494 | return blocks.map((block) => { |
| 495 | if (block.type !== 'agent') { |
| 496 | return block |
| 497 | } |
| 498 | |
| 499 | // First recursively process nested agents, then close any reasoning blocks |
| 500 | let updatedBlocks = block.blocks |
| 501 | ? markRunningAgentsAsCancelled(block.blocks) |
| 502 | : undefined |
| 503 | |
| 504 | // Close any open native reasoning blocks in this agent |
| 505 | if (updatedBlocks) { |
| 506 | updatedBlocks = closeNativeReasoningBlock(updatedBlocks) |
| 507 | } |
| 508 | |
| 509 | if (block.status === 'running') { |
| 510 | return { |
| 511 | ...block, |
| 512 | status: 'cancelled' as const, |
| 513 | ...(updatedBlocks && { blocks: updatedBlocks }), |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if (updatedBlocks && updatedBlocks !== block.blocks) { |
| 518 | return { ...block, blocks: updatedBlocks } |
| 519 | } |
| 520 | |
| 521 | return block |
| 522 | }) |
| 523 | } |
no test coverage detected