panel.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import Split from '../_base/components/split'
  5. import type { ToolNodeType } from './types'
  6. import useConfig from './use-config'
  7. import InputVarList from './components/input-var-list'
  8. import Button from '@/app/components/base/button'
  9. import Field from '@/app/components/workflow/nodes/_base/components/field'
  10. import type { NodePanelProps } from '@/app/components/workflow/types'
  11. import Form from '@/app/components/header/account-setting/model-provider-page/model-modal/Form'
  12. import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials'
  13. import Loading from '@/app/components/base/loading'
  14. import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
  15. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  16. import ResultPanel from '@/app/components/workflow/run/result-panel'
  17. import { useRetryDetailShowInSingleRun } from '@/app/components/workflow/nodes/_base/components/retry/hooks'
  18. import { useToolIcon } from '@/app/components/workflow/hooks'
  19. const i18nPrefix = 'workflow.nodes.tool'
  20. const Panel: FC<NodePanelProps<ToolNodeType>> = ({
  21. id,
  22. data,
  23. }) => {
  24. const { t } = useTranslation()
  25. const {
  26. readOnly,
  27. inputs,
  28. toolInputVarSchema,
  29. setInputVar,
  30. handleOnVarOpen,
  31. filterVar,
  32. toolSettingSchema,
  33. toolSettingValue,
  34. setToolSettingValue,
  35. currCollection,
  36. isShowAuthBtn,
  37. showSetAuth,
  38. showSetAuthModal,
  39. hideSetAuthModal,
  40. handleSaveAuth,
  41. isLoading,
  42. isShowSingleRun,
  43. hideSingleRun,
  44. singleRunForms,
  45. runningStatus,
  46. handleRun,
  47. handleStop,
  48. runResult,
  49. } = useConfig(id, data)
  50. const toolIcon = useToolIcon(data)
  51. const {
  52. retryDetails,
  53. handleRetryDetailsChange,
  54. } = useRetryDetailShowInSingleRun()
  55. if (isLoading) {
  56. return <div className='flex h-[200px] items-center justify-center'>
  57. <Loading />
  58. </div>
  59. }
  60. return (
  61. <div className='pt-2'>
  62. {!readOnly && isShowAuthBtn && (
  63. <>
  64. <div className='px-4'>
  65. <Button
  66. variant='primary'
  67. className='w-full'
  68. onClick={showSetAuthModal}
  69. >
  70. {t(`${i18nPrefix}.toAuthorize`)}
  71. </Button>
  72. </div>
  73. </>
  74. )}
  75. {!isShowAuthBtn && <>
  76. <div className='px-4 space-y-4'>
  77. {toolInputVarSchema.length > 0 && (
  78. <Field
  79. title={t(`${i18nPrefix}.inputVars`)}
  80. >
  81. <InputVarList
  82. readOnly={readOnly}
  83. nodeId={id}
  84. schema={toolInputVarSchema as any}
  85. value={inputs.tool_parameters}
  86. onChange={setInputVar}
  87. filterVar={filterVar}
  88. isSupportConstantValue
  89. onOpen={handleOnVarOpen}
  90. />
  91. </Field>
  92. )}
  93. {toolInputVarSchema.length > 0 && toolSettingSchema.length > 0 && (
  94. <Split />
  95. )}
  96. <Form
  97. className='space-y-4'
  98. itemClassName='!py-0'
  99. fieldLabelClassName='!text-[13px] !font-semibold !text-gray-700 uppercase'
  100. value={toolSettingValue}
  101. onChange={setToolSettingValue}
  102. formSchemas={toolSettingSchema as any}
  103. isEditMode={false}
  104. showOnVariableMap={{}}
  105. validating={false}
  106. inputClassName='!bg-gray-50'
  107. readonly={readOnly}
  108. />
  109. </div>
  110. </>}
  111. {showSetAuth && (
  112. <ConfigCredential
  113. collection={currCollection!}
  114. onCancel={hideSetAuthModal}
  115. onSaved={handleSaveAuth}
  116. isHideRemoveBtn
  117. />
  118. )}
  119. <div>
  120. <OutputVars>
  121. <>
  122. <VarItem
  123. name='text'
  124. type='String'
  125. description={t(`${i18nPrefix}.outputVars.text`)}
  126. />
  127. <VarItem
  128. name='files'
  129. type='Array[File]'
  130. description={t(`${i18nPrefix}.outputVars.files.title`)}
  131. />
  132. <VarItem
  133. name='json'
  134. type='Array[Object]'
  135. description={t(`${i18nPrefix}.outputVars.json`)}
  136. />
  137. </>
  138. </OutputVars>
  139. </div>
  140. {isShowSingleRun && (
  141. <BeforeRunForm
  142. nodeName={inputs.title}
  143. nodeType={inputs.type}
  144. toolIcon={toolIcon}
  145. onHide={hideSingleRun}
  146. forms={singleRunForms}
  147. runningStatus={runningStatus}
  148. onRun={handleRun}
  149. onStop={handleStop}
  150. retryDetails={retryDetails}
  151. onRetryDetailBack={handleRetryDetailsChange}
  152. result={<ResultPanel {...runResult} showSteps={false} onShowRetryDetail={handleRetryDetailsChange} />}
  153. />
  154. )}
  155. </div>
  156. )
  157. }
  158. export default React.memo(Panel)