* Determines which nodes should be ignored based on condition results * @param currentNode - The node being processed * @param result - The execution result from the node * @param edges - All edges in the workflow * @param nodeId - Current node ID * @returns Array of node IDs that should be ign
(
currentNode: IReactFlowNode,
result: any,
edges: IReactFlowEdge[],
nodeId: string
)
| 797 | * @returns Array of node IDs that should be ignored |
| 798 | */ |
| 799 | async function determineNodesToIgnore( |
| 800 | currentNode: IReactFlowNode, |
| 801 | result: any, |
| 802 | edges: IReactFlowEdge[], |
| 803 | nodeId: string |
| 804 | ): Promise<string[]> { |
| 805 | const ignoreNodeIds: string[] = [] |
| 806 | |
| 807 | // Check if this is a decision node |
| 808 | const isDecisionNode = |
| 809 | currentNode.data.name === 'conditionAgentflow' || |
| 810 | currentNode.data.name === 'conditionAgentAgentflow' || |
| 811 | currentNode.data.name === 'humanInputAgentflow' |
| 812 | |
| 813 | if (isDecisionNode && result.output?.conditions) { |
| 814 | const outputConditions: ICondition[] = result.output.conditions |
| 815 | |
| 816 | // safety net: if no conditions were fulfilled, don't ignore ALL children |
| 817 | // treat the last condition as an else/default fallback |
| 818 | const anyFulfilled = outputConditions.some((c) => c.isFulfilled === true) |
| 819 | if (!anyFulfilled && outputConditions.length > 0) { |
| 820 | // mark the last condition as fulfilled so at least one branch executes |
| 821 | outputConditions[outputConditions.length - 1].isFulfilled = true |
| 822 | } |
| 823 | |
| 824 | // Find indexes of unfulfilled conditions |
| 825 | const unfulfilledIndexes = outputConditions |
| 826 | .map((condition, index) => |
| 827 | condition.isFulfilled === false || !Object.prototype.hasOwnProperty.call(condition, 'isFulfilled') ? index : -1 |
| 828 | ) |
| 829 | .filter((index) => index !== -1) |
| 830 | |
| 831 | // Find nodes to ignore based on unfulfilled conditions |
| 832 | for (const index of unfulfilledIndexes) { |
| 833 | const ignoreEdge = edges.find((edge) => edge.source === nodeId && edge.sourceHandle === `${nodeId}-output-${index}`) |
| 834 | |
| 835 | if (ignoreEdge) { |
| 836 | ignoreNodeIds.push(ignoreEdge.target) |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | return ignoreNodeIds |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Process node outputs and handle branching logic |
no test coverage detected