您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import type { EndNodeType } from './types'
  4. import type { NodeProps, Variable } from '@/app/components/workflow/types'
  5. import {
  6. useIsChatMode,
  7. useWorkflow,
  8. useWorkflowVariables,
  9. } from '@/app/components/workflow/hooks'
  10. import { BlockEnum } from '@/app/components/workflow/types'
  11. import {
  12. VariableLabelInNode,
  13. } from '@/app/components/workflow/nodes/_base/components/variable/variable-label'
  14. const Node: FC<NodeProps<EndNodeType>> = ({
  15. id,
  16. data,
  17. }) => {
  18. const { getBeforeNodesInSameBranch } = useWorkflow()
  19. const availableNodes = getBeforeNodesInSameBranch(id)
  20. const { getCurrentVariableType } = useWorkflowVariables()
  21. const isChatMode = useIsChatMode()
  22. const startNode = availableNodes.find((node: any) => {
  23. return node.data.type === BlockEnum.Start
  24. })
  25. const getNode = (id: string) => {
  26. return availableNodes.find(node => node.id === id) || startNode
  27. }
  28. const { outputs } = data
  29. const filteredOutputs = (outputs as Variable[]).filter(({ value_selector }) => value_selector.length > 0)
  30. if (!filteredOutputs.length)
  31. return null
  32. return (
  33. <div className='mb-1 space-y-0.5 px-3 py-1'>
  34. {filteredOutputs.map(({ value_selector }, index) => {
  35. const node = getNode(value_selector[0])
  36. const varType = getCurrentVariableType({
  37. valueSelector: value_selector,
  38. availableNodes,
  39. isChatMode,
  40. })
  41. return (
  42. <VariableLabelInNode
  43. key={index}
  44. variables={value_selector}
  45. nodeType={node?.data.type}
  46. nodeTitle={node?.data.title}
  47. variableType={varType}
  48. />
  49. )
  50. })}
  51. </div>
  52. )
  53. }
  54. export default React.memo(Node)