* Finds the parent condition node for a given node, if any
(nodeId: string, edges: IReactFlowEdge[], nodes: IReactFlowNode[])
| 717 | * Finds the parent condition node for a given node, if any |
| 718 | */ |
| 719 | function findConditionParent(nodeId: string, edges: IReactFlowEdge[], nodes: IReactFlowNode[]): string | null { |
| 720 | const currentNode = nodes.find((n) => n.id === nodeId) |
| 721 | if (!currentNode) return null |
| 722 | if ( |
| 723 | currentNode.data.name === 'conditionAgentflow' || |
| 724 | currentNode.data.name === 'conditionAgentAgentflow' || |
| 725 | currentNode.data.name === 'humanInputAgentflow' |
| 726 | ) { |
| 727 | return currentNode.id |
| 728 | } |
| 729 | |
| 730 | let currentId = nodeId |
| 731 | const visited = new Set<string>() |
| 732 | |
| 733 | let shouldContinue = true |
| 734 | while (shouldContinue) { |
| 735 | if (visited.has(currentId)) { |
| 736 | shouldContinue = false |
| 737 | continue |
| 738 | } |
| 739 | visited.add(currentId) |
| 740 | |
| 741 | const parentEdge = edges.find((edge) => edge.target === currentId) |
| 742 | if (!parentEdge) { |
| 743 | shouldContinue = false |
| 744 | continue |
| 745 | } |
| 746 | |
| 747 | const parentNode = nodes.find((n) => n.id === parentEdge.source) |
| 748 | if (!parentNode) { |
| 749 | shouldContinue = false |
| 750 | continue |
| 751 | } |
| 752 | |
| 753 | if ( |
| 754 | parentNode.data.name === 'conditionAgentflow' || |
| 755 | parentNode.data.name === 'conditionAgentAgentflow' || |
| 756 | parentNode.data.name === 'humanInputAgentflow' |
| 757 | ) { |
| 758 | return parentNode.id |
| 759 | } |
| 760 | |
| 761 | currentId = parentNode.id |
| 762 | } |
| 763 | |
| 764 | return null |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Checks if a node has received all required inputs |
no test coverage detected