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.

right.tsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { useTranslation } from 'react-i18next'
  2. import {
  3. RiArrowGoBackLine,
  4. RiCloseLine,
  5. RiMenuLine,
  6. } from '@remixicon/react'
  7. import { useStore } from '../store'
  8. import type { BlockEnum } from '../types'
  9. import useCurrentVars from '../hooks/use-inspect-vars-crud'
  10. import Empty from './empty'
  11. import ValueContent from './value-content'
  12. import ActionButton from '@/app/components/base/action-button'
  13. import Badge from '@/app/components/base/badge'
  14. import CopyFeedback from '@/app/components/base/copy-feedback'
  15. import Tooltip from '@/app/components/base/tooltip'
  16. import BlockIcon from '@/app/components/workflow/block-icon'
  17. import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others'
  18. import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
  19. import Loading from '@/app/components/base/loading'
  20. import type { currentVarType } from './panel'
  21. import { VarInInspectType } from '@/types/workflow'
  22. import cn from '@/utils/classnames'
  23. type Props = {
  24. currentNodeVar?: currentVarType
  25. handleOpenMenu: () => void
  26. isValueFetching?: boolean
  27. }
  28. const Right = ({
  29. currentNodeVar,
  30. handleOpenMenu,
  31. isValueFetching,
  32. }: Props) => {
  33. const { t } = useTranslation()
  34. const bottomPanelWidth = useStore(s => s.bottomPanelWidth)
  35. const setShowVariableInspectPanel = useStore(s => s.setShowVariableInspectPanel)
  36. const setCurrentFocusNodeId = useStore(s => s.setCurrentFocusNodeId)
  37. const {
  38. resetConversationVar,
  39. resetToLastRunVar,
  40. editInspectVarValue,
  41. } = useCurrentVars()
  42. const handleValueChange = (varId: string, value: any) => {
  43. if (!currentNodeVar) return
  44. editInspectVarValue(currentNodeVar.nodeId, varId, value)
  45. }
  46. const resetValue = () => {
  47. if (!currentNodeVar) return
  48. resetToLastRunVar(currentNodeVar.nodeId, currentNodeVar.var.id)
  49. }
  50. const handleClose = () => {
  51. setShowVariableInspectPanel(false)
  52. setCurrentFocusNodeId('')
  53. }
  54. const handleClear = () => {
  55. if (!currentNodeVar) return
  56. resetConversationVar(currentNodeVar.var.id)
  57. }
  58. const getCopyContent = () => {
  59. const value = currentNodeVar?.var.value
  60. if (value === null || value === undefined)
  61. return ''
  62. if (typeof value === 'object')
  63. return JSON.stringify(value)
  64. return String(value)
  65. }
  66. return (
  67. <div className={cn('flex h-full flex-col')}>
  68. {/* header */}
  69. <div className='flex shrink-0 items-center justify-between gap-1 px-2 pt-2'>
  70. {bottomPanelWidth < 488 && (
  71. <ActionButton className='shrink-0' onClick={handleOpenMenu}>
  72. <RiMenuLine className='h-4 w-4' />
  73. </ActionButton>
  74. )}
  75. <div className='flex w-0 grow items-center gap-1'>
  76. {currentNodeVar && (
  77. <>
  78. {currentNodeVar.nodeType === VarInInspectType.environment && (
  79. <Env className='h-4 w-4 shrink-0 text-util-colors-violet-violet-600' />
  80. )}
  81. {currentNodeVar.nodeType === VarInInspectType.conversation && (
  82. <BubbleX className='h-4 w-4 shrink-0 text-util-colors-teal-teal-700' />
  83. )}
  84. {currentNodeVar.nodeType === VarInInspectType.system && (
  85. <Variable02 className='h-4 w-4 shrink-0 text-text-accent' />
  86. )}
  87. {currentNodeVar.nodeType !== VarInInspectType.environment && currentNodeVar.nodeType !== VarInInspectType.conversation && currentNodeVar.nodeType !== VarInInspectType.system && (
  88. <>
  89. <BlockIcon
  90. className='shrink-0'
  91. type={currentNodeVar.nodeType as BlockEnum}
  92. size='xs'
  93. />
  94. <div className='system-sm-regular shrink-0 text-text-secondary'>{currentNodeVar.title}</div>
  95. <div className='system-sm-regular shrink-0 text-text-quaternary'>/</div>
  96. </>
  97. )}
  98. <div title={currentNodeVar.var.name} className='system-sm-semibold truncate text-text-secondary'>{currentNodeVar.var.name}</div>
  99. <div className='system-xs-medium ml-1 shrink-0 text-text-tertiary'>{currentNodeVar.var.value_type}</div>
  100. </>
  101. )}
  102. </div>
  103. <div className='flex shrink-0 items-center gap-1'>
  104. {currentNodeVar && (
  105. <>
  106. {currentNodeVar.var.edited && (
  107. <Badge>
  108. <span className='ml-[2.5px] mr-[4.5px] h-[3px] w-[3px] rounded bg-text-accent-secondary'></span>
  109. <span className='system-2xs-semibold-uupercase'>{t('workflow.debug.variableInspect.edited')}</span>
  110. </Badge>
  111. )}
  112. {currentNodeVar.var.edited && currentNodeVar.var.type !== VarInInspectType.conversation && (
  113. <Tooltip popupContent={t('workflow.debug.variableInspect.reset')}>
  114. <ActionButton onClick={resetValue}>
  115. <RiArrowGoBackLine className='h-4 w-4' />
  116. </ActionButton>
  117. </Tooltip>
  118. )}
  119. {currentNodeVar.var.edited && currentNodeVar.var.type === VarInInspectType.conversation && (
  120. <Tooltip popupContent={t('workflow.debug.variableInspect.resetConversationVar')}>
  121. <ActionButton onClick={handleClear}>
  122. <RiArrowGoBackLine className='h-4 w-4' />
  123. </ActionButton>
  124. </Tooltip>
  125. )}
  126. {currentNodeVar.var.value_type !== 'secret' && (
  127. <CopyFeedback content={getCopyContent()} />
  128. )}
  129. </>
  130. )}
  131. <ActionButton onClick={handleClose}>
  132. <RiCloseLine className='h-4 w-4' />
  133. </ActionButton>
  134. </div>
  135. </div>
  136. {/* content */}
  137. <div className='grow p-2'>
  138. {!currentNodeVar && <Empty />}
  139. {isValueFetching && (
  140. <div className='flex h-full items-center justify-center'>
  141. <Loading />
  142. </div>
  143. )}
  144. {currentNodeVar && !isValueFetching && <ValueContent currentVar={currentNodeVar.var} handleValueChange={handleValueChange} />}
  145. </div>
  146. </div>
  147. )
  148. }
  149. export default Right