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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { useStore } from '../store'
  4. import Button from '@/app/components/base/button'
  5. // import ActionButton from '@/app/components/base/action-button'
  6. // import Tooltip from '@/app/components/base/tooltip'
  7. import Group from './group'
  8. import useCurrentVars from '../hooks/use-inspect-vars-crud'
  9. import { useNodesInteractions } from '../hooks/use-nodes-interactions'
  10. import type { currentVarType } from './panel'
  11. import type { VarInInspect } from '@/types/workflow'
  12. import { VarInInspectType } from '@/types/workflow'
  13. import cn from '@/utils/classnames'
  14. type Props = {
  15. currentNodeVar?: currentVarType
  16. handleVarSelect: (state: any) => void
  17. }
  18. const Left = ({
  19. currentNodeVar,
  20. handleVarSelect,
  21. }: Props) => {
  22. const { t } = useTranslation()
  23. const environmentVariables = useStore(s => s.environmentVariables)
  24. const setCurrentFocusNodeId = useStore(s => s.setCurrentFocusNodeId)
  25. const {
  26. conversationVars,
  27. systemVars,
  28. nodesWithInspectVars,
  29. deleteAllInspectorVars,
  30. deleteNodeInspectorVars,
  31. } = useCurrentVars()
  32. const { handleNodeSelect } = useNodesInteractions()
  33. const showDivider = environmentVariables.length > 0 || conversationVars.length > 0 || systemVars.length > 0
  34. const handleClearAll = () => {
  35. deleteAllInspectorVars()
  36. setCurrentFocusNodeId('')
  37. }
  38. const handleClearNode = (nodeId: string) => {
  39. deleteNodeInspectorVars(nodeId)
  40. setCurrentFocusNodeId('')
  41. }
  42. return (
  43. <div className={cn('flex h-full flex-col')}>
  44. {/* header */}
  45. <div className='flex shrink-0 items-center justify-between gap-1 pl-4 pr-1 pt-2'>
  46. <div className='system-sm-semibold-uppercase truncate text-text-primary'>{t('workflow.debug.variableInspect.title')}</div>
  47. <Button variant='ghost' size='small' className='shrink-0' onClick={handleClearAll}>{t('workflow.debug.variableInspect.clearAll')}</Button>
  48. </div>
  49. {/* content */}
  50. <div className='grow overflow-y-auto py-1'>
  51. {/* group ENV */}
  52. {environmentVariables.length > 0 && (
  53. <Group
  54. varType={VarInInspectType.environment}
  55. varList={environmentVariables as VarInInspect[]}
  56. currentVar={currentNodeVar}
  57. handleSelect={handleVarSelect}
  58. />
  59. )}
  60. {/* group CHAT VAR */}
  61. {conversationVars.length > 0 && (
  62. <Group
  63. varType={VarInInspectType.conversation}
  64. varList={conversationVars}
  65. currentVar={currentNodeVar}
  66. handleSelect={handleVarSelect}
  67. />
  68. )}
  69. {/* group SYSTEM VAR */}
  70. {systemVars.length > 0 && (
  71. <Group
  72. varType={VarInInspectType.system}
  73. varList={systemVars}
  74. currentVar={currentNodeVar}
  75. handleSelect={handleVarSelect}
  76. />
  77. )}
  78. {/* divider */}
  79. {showDivider && (
  80. <div className='px-4 py-1'>
  81. <div className='h-px bg-divider-subtle'></div>
  82. </div>
  83. )}
  84. {/* group nodes */}
  85. {nodesWithInspectVars.length > 0 && nodesWithInspectVars.map(group => (
  86. <Group
  87. key={group.nodeId}
  88. varType={VarInInspectType.node}
  89. varList={group.vars}
  90. nodeData={group}
  91. currentVar={currentNodeVar}
  92. handleSelect={handleVarSelect}
  93. handleView={() => handleNodeSelect(group.nodeId, false, true)}
  94. handleClear={() => handleClearNode(group.nodeId)}
  95. />
  96. ))}
  97. </div>
  98. </div>
  99. )
  100. }
  101. export default Left