MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / getAvailableNodesForVariable

Function getAvailableNodesForVariable

packages/ui/src/utils/genericHelper.js:638–706  ·  view source on GitHub ↗
(nodes, edges, target, targetHandle, includesStart = false)

Source from the content-addressed store, hash-verified

636}
637
638export const getAvailableNodesForVariable = (nodes, edges, target, targetHandle, includesStart = false) => {
639 // example edge id = "llmChain_0-llmChain_0-output-outputPrediction-string|json-llmChain_1-llmChain_1-input-promptValues-string"
640 // {source} -{sourceHandle} -{target} -{targetHandle}
641 const parentNodes = []
642
643 const isAgentFlowV2 = nodes.find((nd) => nd.id === target)?.data?.category === 'Agent Flows'
644
645 const isSeqAgent = nodes.find((nd) => nd.id === target)?.data?.category === 'Sequential Agents'
646
647 function collectParentNodes(targetNodeId, nodes, edges) {
648 const inputEdges = edges.filter(
649 (edg) => edg.target === targetNodeId && edg.targetHandle.includes(`${targetNodeId}-input-sequentialNode`)
650 )
651
652 // Traverse each edge found
653 inputEdges.forEach((edge) => {
654 const parentNode = nodes.find((nd) => nd.id === edge.source)
655 if (!parentNode) return
656
657 // Recursive call to explore further up the tree
658 collectParentNodes(parentNode.id, nodes, edges)
659
660 // Check and add the parent node to the list if it does not include specific names
661 const excludeNodeNames = ['seqAgent', 'seqLLMNode', 'seqToolNode', 'seqCustomFunction', 'seqExecuteFlow']
662 if (excludeNodeNames.includes(parentNode.data.name)) {
663 parentNodes.push(parentNode)
664 }
665 })
666 }
667 function collectAgentFlowV2ParentNodes(targetNodeId, nodes, edges) {
668 const inputEdges = edges.filter((edg) => edg.target === targetNodeId && edg.targetHandle === targetNodeId)
669
670 // Traverse each edge found
671 inputEdges.forEach((edge) => {
672 const parentNode = nodes.find((nd) => nd.id === edge.source)
673 if (!parentNode) return
674
675 // Recursive call to explore further up the tree
676 collectAgentFlowV2ParentNodes(parentNode.id, nodes, edges)
677
678 // Check and add the parent node to the list if it does not include specific names
679 const excludeNodeNames = ['startAgentflow']
680 if (!excludeNodeNames.includes(parentNode.data.name) || includesStart) {
681 parentNodes.push(parentNode)
682 }
683 })
684 }
685
686 if (isSeqAgent) {
687 collectParentNodes(target, nodes, edges)
688 return uniq(parentNodes)
689 } else if (isAgentFlowV2) {
690 collectAgentFlowV2ParentNodes(target, nodes, edges)
691 const parentNodeId = nodes.find((nd) => nd.id === target)?.parentNode
692 if (parentNodeId) {
693 collectAgentFlowV2ParentNodes(parentNodeId, nodes, edges)
694 }
695 return uniq(parentNodes)

Callers 7

getDataGridColDefFunction · 0.90
getDropdownOptionsFunction · 0.90
JsonEditorInputFunction · 0.90
InputFunction · 0.90
RichInputFunction · 0.90
ExpandRichInputDialogFunction · 0.90
fetchDataFunction · 0.90

Calls 2

collectParentNodesFunction · 0.85

Tested by

no test coverage detected