panel.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. const i18nPrefix = 'workflow.nodes.tool'
  18. const Panel: FC<NodePanelProps<ToolNodeType>> = ({
  19. id,
  20. data,
  21. }) => {
  22. const { t } = useTranslation()
  23. const {
  24. readOnly,
  25. inputs,
  26. toolInputVarSchema,
  27. setInputVar,
  28. handleOnVarOpen,
  29. filterVar,
  30. toolSettingSchema,
  31. toolSettingValue,
  32. setToolSettingValue,
  33. currCollection,
  34. isShowAuthBtn,
  35. showSetAuth,
  36. showSetAuthModal,
  37. hideSetAuthModal,
  38. handleSaveAuth,
  39. isLoading,
  40. isShowSingleRun,
  41. hideSingleRun,
  42. singleRunForms,
  43. runningStatus,
  44. handleRun,
  45. handleStop,
  46. runResult,
  47. } = useConfig(id, data)
  48. if (isLoading) {
  49. return <div className='flex h-[200px] items-center justify-center'>
  50. <Loading />
  51. </div>
  52. }
  53. return (
  54. <div className='mt-2'>
  55. {!readOnly && isShowAuthBtn && (
  56. <>
  57. <div className='px-4 pb-3'>
  58. <Button
  59. variant='primary'
  60. className='w-full'
  61. onClick={showSetAuthModal}
  62. >
  63. {t(`${i18nPrefix}.toAuthorize`)}
  64. </Button>
  65. </div>
  66. </>
  67. )}
  68. {!isShowAuthBtn && <>
  69. <div className='px-4 pb-4 space-y-4'>
  70. {toolInputVarSchema.length > 0 && (
  71. <Field
  72. title={t(`${i18nPrefix}.inputVars`)}
  73. >
  74. <InputVarList
  75. readOnly={readOnly}
  76. nodeId={id}
  77. schema={toolInputVarSchema as any}
  78. value={inputs.tool_parameters}
  79. onChange={setInputVar}
  80. filterVar={filterVar}
  81. isSupportConstantValue
  82. onOpen={handleOnVarOpen}
  83. />
  84. </Field>
  85. )}
  86. {toolInputVarSchema.length > 0 && toolSettingSchema.length > 0 && (
  87. <Split />
  88. )}
  89. <Form
  90. className='space-y-4'
  91. itemClassName='!py-0'
  92. fieldLabelClassName='!text-[13px] !font-semibold !text-gray-700 uppercase'
  93. value={toolSettingValue}
  94. onChange={setToolSettingValue}
  95. formSchemas={toolSettingSchema as any}
  96. isEditMode={false}
  97. showOnVariableMap={{}}
  98. validating={false}
  99. inputClassName='!bg-gray-50'
  100. readonly={readOnly}
  101. />
  102. </div>
  103. </>}
  104. {showSetAuth && (
  105. <ConfigCredential
  106. collection={currCollection!}
  107. onCancel={hideSetAuthModal}
  108. onSaved={handleSaveAuth}
  109. isHideRemoveBtn
  110. />
  111. )}
  112. <div className='px-4 pt-4 pb-2'>
  113. <OutputVars>
  114. <>
  115. <VarItem
  116. name='text'
  117. type='String'
  118. description={t(`${i18nPrefix}.outputVars.text`)}
  119. />
  120. <VarItem
  121. name='files'
  122. type='Array[File]'
  123. description={t(`${i18nPrefix}.outputVars.files.title`)}
  124. />
  125. <VarItem
  126. name='json'
  127. type='Array[Object]'
  128. description={t(`${i18nPrefix}.outputVars.json`)}
  129. />
  130. </>
  131. </OutputVars>
  132. </div>
  133. {isShowSingleRun && (
  134. <BeforeRunForm
  135. nodeName={inputs.title}
  136. onHide={hideSingleRun}
  137. forms={singleRunForms}
  138. runningStatus={runningStatus}
  139. onRun={handleRun}
  140. onStop={handleStop}
  141. result={<ResultPanel {...runResult} showSteps={false} />}
  142. />
  143. )}
  144. </div>
  145. )
  146. }
  147. export default React.memo(Panel)