use-is-var-file-attribute.ts 1012 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { useMemo } from 'react'
  2. import { useIsChatMode, useWorkflow, useWorkflowVariables } from '../../hooks'
  3. import type { ValueSelector } from '../../types'
  4. import { VarType } from '../../types'
  5. type Params = {
  6. nodeId: string
  7. }
  8. const useIsVarFileAttribute = ({
  9. nodeId,
  10. }: Params) => {
  11. const isChatMode = useIsChatMode()
  12. const { getBeforeNodesInSameBranch } = useWorkflow()
  13. const availableNodes = useMemo(() => {
  14. return getBeforeNodesInSameBranch(nodeId)
  15. }, [getBeforeNodesInSameBranch, nodeId])
  16. const { getCurrentVariableType } = useWorkflowVariables()
  17. const getIsVarFileAttribute = (variable: ValueSelector) => {
  18. if (variable.length !== 3)
  19. return false
  20. const parentVariable = variable.slice(0, 2)
  21. const varType = getCurrentVariableType({
  22. valueSelector: parentVariable,
  23. availableNodes,
  24. isChatMode,
  25. isConstant: false,
  26. })
  27. return varType === VarType.file
  28. }
  29. return {
  30. getIsVarFileAttribute,
  31. }
  32. }
  33. export default useIsVarFileAttribute