| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import { useStoreApi } from 'reactflow' | 
					
						
							|  |  |  | import { useMemo } from 'react' | 
					
						
							|  |  |  | import { useIsChatMode, useWorkflow, useWorkflowVariables } from '../../hooks' | 
					
						
							|  |  |  | import type { ValueSelector } from '../../types' | 
					
						
							|  |  |  | import { VarType } from '../../types' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Params = { | 
					
						
							|  |  |  |   nodeId: string | 
					
						
							|  |  |  |   isInIteration: boolean | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   isInLoop: boolean | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | const useIsVarFileAttribute = ({ | 
					
						
							|  |  |  |   nodeId, | 
					
						
							|  |  |  |   isInIteration, | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   isInLoop, | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | }: Params) => { | 
					
						
							|  |  |  |   const isChatMode = useIsChatMode() | 
					
						
							|  |  |  |   const store = useStoreApi() | 
					
						
							|  |  |  |   const { getBeforeNodesInSameBranch } = useWorkflow() | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     getNodes, | 
					
						
							|  |  |  |   } = store.getState() | 
					
						
							|  |  |  |   const currentNode = getNodes().find(n => n.id === nodeId) | 
					
						
							|  |  |  |   const iterationNode = isInIteration ? getNodes().find(n => n.id === currentNode!.parentId) : null | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   const loopNode = isInLoop ? getNodes().find(n => n.id === currentNode!.parentId) : null | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   const availableNodes = useMemo(() => { | 
					
						
							|  |  |  |     return getBeforeNodesInSameBranch(nodeId) | 
					
						
							|  |  |  |   }, [getBeforeNodesInSameBranch, nodeId]) | 
					
						
							|  |  |  |   const { getCurrentVariableType } = useWorkflowVariables() | 
					
						
							|  |  |  |   const getIsVarFileAttribute = (variable: ValueSelector) => { | 
					
						
							|  |  |  |     if (variable.length !== 3) | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     const parentVariable = variable.slice(0, 2) | 
					
						
							|  |  |  |     const varType = getCurrentVariableType({ | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |       parentNode: isInIteration ? iterationNode : loopNode, | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |       valueSelector: parentVariable, | 
					
						
							|  |  |  |       availableNodes, | 
					
						
							|  |  |  |       isChatMode, | 
					
						
							|  |  |  |       isConstant: false, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     return varType === VarType.file | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     getIsVarFileAttribute, | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default useIsVarFileAttribute |