panel.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. payload={{
  71. variable: 'sys.files',
  72. } as any}
  73. rightContent={
  74. <div className='text-xs font-normal text-gray-500'>
  75. Array[File]
  76. </div>
  77. }
  78. />
  79. {
  80. isChatMode && (
  81. <>
  82. <VarItem
  83. readonly
  84. payload={{
  85. variable: 'sys.dialogue_count',
  86. } as any}
  87. rightContent={
  88. <div className='text-xs font-normal text-gray-500'>
  89. Number
  90. </div>
  91. }
  92. />
  93. <VarItem
  94. readonly
  95. payload={{
  96. variable: 'sys.conversation_id',
  97. } as any}
  98. rightContent={
  99. <div className='text-xs font-normal text-gray-500'>
  100. String
  101. </div>
  102. }
  103. />
  104. </>
  105. )
  106. }
  107. <VarItem
  108. readonly
  109. payload={{
  110. variable: 'sys.user_id',
  111. } as any}
  112. rightContent={
  113. <div className='text-xs font-normal text-gray-500'>
  114. String
  115. </div>
  116. }
  117. />
  118. </div>
  119. </>
  120. </Field>
  121. </div>
  122. {isShowAddVarModal && (
  123. <ConfigVarModal
  124. isCreate
  125. isShow={isShowAddVarModal}
  126. onClose={hideAddVarModal}
  127. onConfirm={handleAddVarConfirm}
  128. varKeys={inputs.variables.map(v => v.variable)}
  129. />
  130. )}
  131. <RemoveEffectVarConfirm
  132. isShow={isShowRemoveVarConfirm}
  133. onCancel={hideRemoveVarConfirm}
  134. onConfirm={onRemoveVarConfirm}
  135. />
  136. </div>
  137. )
  138. }
  139. export default React.memo(Panel)