選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

right.tsx 5.9KB

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