panel.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import MemoryConfig from '../_base/components/memory-config'
  5. import VarReferencePicker from '../_base/components/variable/var-reference-picker'
  6. import Editor from '../_base/components/prompt/editor'
  7. import ResultPanel from '../../run/result-panel'
  8. import ConfigVision from '../_base/components/config-vision'
  9. import useConfig from './use-config'
  10. import type { ParameterExtractorNodeType } from './types'
  11. import ExtractParameter from './components/extract-parameter/list'
  12. import ImportFromTool from './components/extract-parameter/import-from-tool'
  13. import AddExtractParameter from './components/extract-parameter/update'
  14. import ReasoningModePicker from './components/reasoning-mode-picker'
  15. import Field from '@/app/components/workflow/nodes/_base/components/field'
  16. import Split from '@/app/components/workflow/nodes/_base/components/split'
  17. import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal'
  18. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  19. import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
  20. import Tooltip from '@/app/components/base/tooltip'
  21. import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
  22. import { VarType } from '@/app/components/workflow/types'
  23. const i18nPrefix = 'workflow.nodes.parameterExtractor'
  24. const i18nCommonPrefix = 'workflow.common'
  25. const Panel: FC<NodePanelProps<ParameterExtractorNodeType>> = ({
  26. id,
  27. data,
  28. }) => {
  29. const { t } = useTranslation()
  30. const {
  31. readOnly,
  32. inputs,
  33. handleInputVarChange,
  34. filterVar,
  35. isChatModel,
  36. isChatMode,
  37. isCompletionModel,
  38. handleModelChanged,
  39. handleImportFromTool,
  40. handleCompletionParamsChange,
  41. addExtractParameter,
  42. handleExactParamsChange,
  43. handleInstructionChange,
  44. hasSetBlockStatus,
  45. handleMemoryChange,
  46. isSupportFunctionCall,
  47. handleReasoningModeChange,
  48. availableVars,
  49. availableNodesWithParent,
  50. inputVarValues,
  51. varInputs,
  52. isVisionModel,
  53. handleVisionResolutionChange,
  54. handleVisionResolutionEnabledChange,
  55. isShowSingleRun,
  56. hideSingleRun,
  57. runningStatus,
  58. handleRun,
  59. handleStop,
  60. runResult,
  61. setInputVarValues,
  62. } = useConfig(id, data)
  63. const model = inputs.model
  64. return (
  65. <div className='mt-2'>
  66. <div className='px-4 pb-4 space-y-4'>
  67. <Field
  68. title={t(`${i18nCommonPrefix}.model`)}
  69. >
  70. <ModelParameterModal
  71. popupClassName='!w-[387px]'
  72. isInWorkflow
  73. isAdvancedMode={true}
  74. mode={model?.mode}
  75. provider={model?.provider}
  76. completionParams={model?.completion_params}
  77. modelId={model?.name}
  78. setModel={handleModelChanged}
  79. onCompletionParamsChange={handleCompletionParamsChange}
  80. hideDebugWithMultipleModel
  81. debugWithMultipleModel={false}
  82. readonly={readOnly}
  83. />
  84. </Field>
  85. <Field
  86. title={t(`${i18nPrefix}.inputVar`)}
  87. >
  88. <>
  89. <VarReferencePicker
  90. readonly={readOnly}
  91. nodeId={id}
  92. isShowNodeName
  93. value={inputs.query || []}
  94. onChange={handleInputVarChange}
  95. filterVar={filterVar}
  96. />
  97. </>
  98. </Field>
  99. <Split />
  100. <ConfigVision
  101. nodeId={id}
  102. readOnly={readOnly}
  103. isVisionModel={isVisionModel}
  104. enabled={inputs.vision?.enabled}
  105. onEnabledChange={handleVisionResolutionEnabledChange}
  106. config={inputs.vision?.configs}
  107. onConfigChange={handleVisionResolutionChange}
  108. />
  109. <Field
  110. title={t(`${i18nPrefix}.extractParameters`)}
  111. operations={
  112. !readOnly
  113. ? (
  114. <div className='flex items-center space-x-1'>
  115. {!readOnly && (
  116. <ImportFromTool onImport={handleImportFromTool} />
  117. )}
  118. {!readOnly && (<div className='w-px h-3 bg-gray-200'></div>)}
  119. <AddExtractParameter type='add' onSave={addExtractParameter} />
  120. </div>
  121. )
  122. : undefined
  123. }
  124. >
  125. <ExtractParameter
  126. readonly={readOnly}
  127. list={inputs.parameters || []}
  128. onChange={handleExactParamsChange}
  129. />
  130. </Field>
  131. <Editor
  132. title={
  133. <div className='flex items-center space-x-1'>
  134. <span className='uppercase'>{t(`${i18nPrefix}.instruction`)}</span>
  135. <Tooltip
  136. popupContent={
  137. <div className='w-[120px]'>
  138. {t(`${i18nPrefix}.instructionTip`)}
  139. </div>
  140. }
  141. triggerClassName='w-3.5 h-3.5 ml-0.5'
  142. />
  143. </div>
  144. }
  145. value={inputs.instruction}
  146. onChange={handleInstructionChange}
  147. readOnly={readOnly}
  148. isChatModel={isChatModel}
  149. isChatApp={isChatMode}
  150. isShowContext={false}
  151. hasSetBlockStatus={hasSetBlockStatus}
  152. nodesOutputVars={availableVars}
  153. availableNodes={availableNodesWithParent}
  154. />
  155. <Field
  156. title={t(`${i18nPrefix}.advancedSetting`)}
  157. supportFold
  158. >
  159. <>
  160. {/* Memory */}
  161. {isChatMode && (
  162. <div className='mt-4'>
  163. <MemoryConfig
  164. readonly={readOnly}
  165. config={{ data: inputs.memory }}
  166. onChange={handleMemoryChange}
  167. canSetRoleName={isCompletionModel}
  168. />
  169. </div>
  170. )}
  171. {isSupportFunctionCall && (
  172. <div className='mt-2'>
  173. <ReasoningModePicker
  174. type={inputs.reasoning_mode}
  175. onChange={handleReasoningModeChange}
  176. />
  177. </div>
  178. )}
  179. </>
  180. </Field>
  181. </div>
  182. {inputs.parameters?.length > 0 && (<>
  183. <Split />
  184. <div className='px-4 pt-4 pb-2'>
  185. <OutputVars>
  186. <>
  187. {inputs.parameters.map((param, index) => (
  188. <VarItem
  189. key={index}
  190. name={param.name}
  191. type={param.type}
  192. description={param.description}
  193. />
  194. ))}
  195. <VarItem
  196. name='__is_success'
  197. type={VarType.number}
  198. description={t(`${i18nPrefix}.isSuccess`)}
  199. />
  200. <VarItem
  201. name='__reason'
  202. type={VarType.string}
  203. description={t(`${i18nPrefix}.errorReason`)}
  204. />
  205. </>
  206. </OutputVars>
  207. </div>
  208. </>)}
  209. {isShowSingleRun && (
  210. <BeforeRunForm
  211. nodeName={inputs.title}
  212. onHide={hideSingleRun}
  213. forms={[
  214. {
  215. inputs: [{
  216. label: t(`${i18nPrefix}.inputVar`)!,
  217. variable: 'query',
  218. type: InputVarType.paragraph,
  219. required: true,
  220. }, ...varInputs],
  221. values: inputVarValues,
  222. onChange: setInputVarValues,
  223. },
  224. ]}
  225. runningStatus={runningStatus}
  226. onRun={handleRun}
  227. onStop={handleStop}
  228. result={<ResultPanel {...runResult} showSteps={false} />}
  229. />
  230. )}
  231. </div>
  232. )
  233. }
  234. export default React.memo(Panel)