Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

group.tsx 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import {
  4. RiArrowRightSLine,
  5. RiDeleteBinLine,
  6. RiFileList3Line,
  7. RiLoader2Line,
  8. // RiErrorWarningFill,
  9. } from '@remixicon/react'
  10. // import Button from '@/app/components/base/button'
  11. import ActionButton from '@/app/components/base/action-button'
  12. import Tooltip from '@/app/components/base/tooltip'
  13. import BlockIcon from '@/app/components/workflow/block-icon'
  14. import type { currentVarType } from './panel'
  15. import { VarInInspectType } from '@/types/workflow'
  16. import type { NodeWithVar, VarInInspect } from '@/types/workflow'
  17. import cn from '@/utils/classnames'
  18. import { useToolIcon } from '../hooks'
  19. import { VariableIconWithColor } from '@/app/components/workflow/nodes/_base/components/variable/variable-label'
  20. type Props = {
  21. nodeData?: NodeWithVar
  22. currentVar?: currentVarType
  23. varType: VarInInspectType
  24. varList: VarInInspect[]
  25. handleSelect: (state: any) => void
  26. handleView?: () => void
  27. handleClear?: () => void
  28. }
  29. const Group = ({
  30. nodeData,
  31. currentVar,
  32. varType,
  33. varList,
  34. handleSelect,
  35. handleView,
  36. handleClear,
  37. }: Props) => {
  38. const { t } = useTranslation()
  39. const [isCollapsed, setIsCollapsed] = useState(false)
  40. const toolIcon = useToolIcon(nodeData?.nodePayload as any)
  41. const isEnv = varType === VarInInspectType.environment
  42. const isChatVar = varType === VarInInspectType.conversation
  43. const isSystem = varType === VarInInspectType.system
  44. const visibleVarList = isEnv ? varList : varList.filter(v => v.visible)
  45. const handleSelectVar = (varItem: any, type?: string) => {
  46. if (type === VarInInspectType.environment) {
  47. handleSelect({
  48. nodeId: VarInInspectType.environment,
  49. title: VarInInspectType.environment,
  50. nodeType: VarInInspectType.environment,
  51. var: {
  52. ...varItem,
  53. type: VarInInspectType.environment,
  54. ...(varItem.value_type === 'secret' ? { value: '******************' } : {}),
  55. },
  56. })
  57. return
  58. }
  59. if (type === VarInInspectType.conversation) {
  60. handleSelect({
  61. nodeId: VarInInspectType.conversation,
  62. nodeType: VarInInspectType.conversation,
  63. title: VarInInspectType.conversation,
  64. var: {
  65. ...varItem,
  66. type: VarInInspectType.conversation,
  67. },
  68. })
  69. return
  70. }
  71. if (type === VarInInspectType.system) {
  72. handleSelect({
  73. nodeId: VarInInspectType.system,
  74. nodeType: VarInInspectType.system,
  75. title: VarInInspectType.system,
  76. var: {
  77. ...varItem,
  78. type: VarInInspectType.system,
  79. },
  80. })
  81. return
  82. }
  83. if (!nodeData) return
  84. handleSelect({
  85. nodeId: nodeData.nodeId,
  86. nodeType: nodeData.nodeType,
  87. title: nodeData.title,
  88. var: varItem,
  89. })
  90. }
  91. return (
  92. <div className='p-0.5'>
  93. {/* node item */}
  94. <div className='group flex h-6 items-center gap-0.5'>
  95. <div className='h-3 w-3 shrink-0'>
  96. {nodeData?.isSingRunRunning && (
  97. <RiLoader2Line className='h-3 w-3 animate-spin text-text-accent' />
  98. )}
  99. {(!nodeData || !nodeData.isSingRunRunning) && visibleVarList.length > 0 && (
  100. <RiArrowRightSLine className={cn('h-3 w-3 text-text-tertiary', !isCollapsed && 'rotate-90')} onClick={() => setIsCollapsed(!isCollapsed)} />
  101. )}
  102. </div>
  103. <div className='flex grow cursor-pointer items-center gap-1' onClick={() => setIsCollapsed(!isCollapsed)}>
  104. {nodeData && (
  105. <>
  106. <BlockIcon
  107. className='shrink-0'
  108. type={nodeData.nodeType}
  109. toolIcon={toolIcon || ''}
  110. size='xs'
  111. />
  112. <div className='system-xs-medium-uppercase truncate text-text-tertiary'>{nodeData.title}</div>
  113. </>
  114. )}
  115. {!nodeData && (
  116. <div className='system-xs-medium-uppercase truncate text-text-tertiary'>
  117. {isEnv && t('workflow.debug.variableInspect.envNode')}
  118. {isChatVar && t('workflow.debug.variableInspect.chatNode')}
  119. {isSystem && t('workflow.debug.variableInspect.systemNode')}
  120. </div>
  121. )}
  122. </div>
  123. {nodeData && !nodeData.isSingRunRunning && (
  124. <div className='hidden shrink-0 items-center group-hover:flex'>
  125. <Tooltip popupContent={t('workflow.debug.variableInspect.view')}>
  126. <ActionButton onClick={handleView}>
  127. <RiFileList3Line className='h-4 w-4' />
  128. </ActionButton>
  129. </Tooltip>
  130. <Tooltip popupContent={t('workflow.debug.variableInspect.clearNode')}>
  131. <ActionButton onClick={handleClear}>
  132. <RiDeleteBinLine className='h-4 w-4' />
  133. </ActionButton>
  134. </Tooltip>
  135. </div>
  136. )}
  137. </div>
  138. {/* var item list */}
  139. {!isCollapsed && !nodeData?.isSingRunRunning && (
  140. <div className='px-0.5'>
  141. {visibleVarList.length > 0 && visibleVarList.map(varItem => (
  142. <div
  143. key={varItem.id}
  144. className={cn(
  145. 'relative flex cursor-pointer items-center gap-1 rounded-md px-3 py-1 hover:bg-state-base-hover',
  146. varItem.id === currentVar?.var?.id && 'bg-state-base-hover-alt hover:bg-state-base-hover-alt',
  147. )}
  148. onClick={() => handleSelectVar(varItem, varType)}
  149. >
  150. <VariableIconWithColor
  151. variableCategory={varType}
  152. isExceptionVariable={['error_type', 'error_message'].includes(varItem.name)}
  153. className='size-4'
  154. />
  155. <div className='system-sm-medium grow truncate text-text-secondary'>{varItem.name}</div>
  156. <div className='system-xs-regular shrink-0 text-text-tertiary'>{varItem.value_type}</div>
  157. </div>
  158. ))}
  159. </div>
  160. )}
  161. </div>
  162. )
  163. }
  164. export default Group