panel.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import RemoveEffectVarConfirm from '../_base/components/remove-effect-var-confirm'
  5. import VarList from './components/var-list'
  6. import VarItem from './components/var-item'
  7. import useConfig from './use-config'
  8. import type { StartNodeType } from './types'
  9. import Split from '@/app/components/workflow/nodes/_base/components/split'
  10. import Field from '@/app/components/workflow/nodes/_base/components/field'
  11. import AddButton from '@/app/components/base/button/add-button'
  12. import ConfigVarModal from '@/app/components/app/configuration/config-var/config-modal'
  13. import type { InputVar, NodePanelProps } from '@/app/components/workflow/types'
  14. const i18nPrefix = 'workflow.nodes.start'
  15. const Panel: FC<NodePanelProps<StartNodeType>> = ({
  16. id,
  17. data,
  18. }) => {
  19. const { t } = useTranslation()
  20. const {
  21. readOnly,
  22. isChatMode,
  23. inputs,
  24. isShowAddVarModal,
  25. showAddVarModal,
  26. handleAddVariable,
  27. hideAddVarModal,
  28. handleVarListChange,
  29. isShowRemoveVarConfirm,
  30. hideRemoveVarConfirm,
  31. onRemoveVarConfirm,
  32. } = useConfig(id, data)
  33. const handleAddVarConfirm = (payload: InputVar) => {
  34. handleAddVariable(payload)
  35. hideAddVarModal()
  36. }
  37. return (
  38. <div className='mt-2'>
  39. <div className='px-4 pb-2 space-y-4'>
  40. <Field
  41. title={t(`${i18nPrefix}.inputField`)}
  42. operations={
  43. !readOnly ? <AddButton onClick={showAddVarModal} /> : undefined
  44. }
  45. >
  46. <>
  47. <VarList
  48. readonly={readOnly}
  49. list={inputs.variables || []}
  50. onChange={handleVarListChange}
  51. />
  52. <div className='mt-1 space-y-1'>
  53. <Split className='my-2' />
  54. {
  55. isChatMode && (
  56. <VarItem
  57. readonly
  58. payload={{
  59. variable: 'sys.query',
  60. } as any}
  61. rightContent={
  62. <div className='text-xs font-normal text-gray-500'>
  63. String
  64. </div>
  65. }
  66. />)
  67. }
  68. <VarItem
  69. readonly
  70. showLegacyBadge={!isChatMode}
  71. payload={{
  72. variable: 'sys.files',
  73. } as any}
  74. rightContent={
  75. <div className='text-xs font-normal text-gray-500'>
  76. Array[File]
  77. </div>
  78. }
  79. />
  80. {
  81. isChatMode && (
  82. <>
  83. <VarItem
  84. readonly
  85. payload={{
  86. variable: 'sys.dialogue_count',
  87. } as any}
  88. rightContent={
  89. <div className='text-xs font-normal text-gray-500'>
  90. Number
  91. </div>
  92. }
  93. />
  94. <VarItem
  95. readonly
  96. payload={{
  97. variable: 'sys.conversation_id',
  98. } as any}
  99. rightContent={
  100. <div className='text-xs font-normal text-gray-500'>
  101. String
  102. </div>
  103. }
  104. />
  105. </>
  106. )
  107. }
  108. <VarItem
  109. readonly
  110. payload={{
  111. variable: 'sys.user_id',
  112. } as any}
  113. rightContent={
  114. <div className='text-xs font-normal text-gray-500'>
  115. String
  116. </div>
  117. }
  118. />
  119. <VarItem
  120. readonly
  121. payload={{
  122. variable: 'sys.app_id',
  123. } as any}
  124. rightContent={
  125. <div className='text-xs font-normal text-gray-500'>
  126. String
  127. </div>
  128. }
  129. />
  130. <VarItem
  131. readonly
  132. payload={{
  133. variable: 'sys.workflow_id',
  134. } as any}
  135. rightContent={
  136. <div className='text-xs font-normal text-gray-500'>
  137. String
  138. </div>
  139. }
  140. />
  141. <VarItem
  142. readonly
  143. payload={{
  144. variable: 'sys.workflow_run_id',
  145. } as any}
  146. rightContent={
  147. <div className='text-xs font-normal text-gray-500'>
  148. String
  149. </div>
  150. }
  151. />
  152. </div>
  153. </>
  154. </Field>
  155. </div>
  156. {isShowAddVarModal && (
  157. <ConfigVarModal
  158. isCreate
  159. supportFile
  160. isShow={isShowAddVarModal}
  161. onClose={hideAddVarModal}
  162. onConfirm={handleAddVarConfirm}
  163. varKeys={inputs.variables.map(v => v.variable)}
  164. />
  165. )}
  166. <RemoveEffectVarConfirm
  167. isShow={isShowRemoveVarConfirm}
  168. onCancel={hideRemoveVarConfirm}
  169. onConfirm={onRemoveVarConfirm}
  170. />
  171. </div>
  172. )
  173. }
  174. export default React.memo(Panel)