(
candidates: StartBlockCandidate<T>[],
edges?: Array<{ source: string; target: string }>
)
| 313 | * If multiple disjoint paths exist, returns one trigger per path |
| 314 | */ |
| 315 | export function selectBestTrigger<T extends { type: string; subBlocks?: Record<string, unknown> }>( |
| 316 | candidates: StartBlockCandidate<T>[], |
| 317 | edges?: Array<{ source: string; target: string }> |
| 318 | ): StartBlockCandidate<T>[] { |
| 319 | if (candidates.length === 0) { |
| 320 | throw new Error('No trigger candidates provided') |
| 321 | } |
| 322 | |
| 323 | // If edges provided, group by path and select best from each group |
| 324 | if (edges) { |
| 325 | const groups = groupTriggersByPath(candidates, edges) |
| 326 | return groups.map((group) => selectBestFromGroup(group)) |
| 327 | } |
| 328 | |
| 329 | // Otherwise just select the single best trigger |
| 330 | return [selectBestFromGroup(candidates)] |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Selects the best trigger from a group based on priority |
no test coverage detected