( currentAgent: AgentContentBlock, siblingBlocks: ContentBlock[], )
| 88 | * Returns the 0-based index among all implementor agents of the same type. |
| 89 | */ |
| 90 | export const getImplementorIndex = ( |
| 91 | currentAgent: AgentContentBlock, |
| 92 | siblingBlocks: ContentBlock[], |
| 93 | ): number | undefined => { |
| 94 | if (!isImplementorAgent(currentAgent)) return undefined |
| 95 | |
| 96 | // Filter to only implementor agents of the same type |
| 97 | const implementorSiblings = siblingBlocks.filter( |
| 98 | (block): block is AgentContentBlock => |
| 99 | block.type === 'agent' && |
| 100 | isImplementorAgent(block) && |
| 101 | block.agentType === currentAgent.agentType, |
| 102 | ) |
| 103 | |
| 104 | // If there's only one, don't show an index |
| 105 | if (implementorSiblings.length <= 1) { |
| 106 | return undefined |
| 107 | } |
| 108 | |
| 109 | // Find the index of the current agent |
| 110 | return implementorSiblings.findIndex( |
| 111 | (block) => block.agentId === currentAgent.agentId, |
| 112 | ) |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Group consecutive blocks from a blocks array that match the predicate. |
no test coverage detected