Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

panel.tsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  15. import StructureOutputItem from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show'
  16. import { Type } from '../llm/types'
  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. outputSchema,
  41. hasObjectOutput,
  42. } = useConfig(id, data)
  43. if (isLoading) {
  44. return <div className='flex h-[200px] items-center justify-center'>
  45. <Loading />
  46. </div>
  47. }
  48. return (
  49. <div className='pt-2'>
  50. {!readOnly && isShowAuthBtn && (
  51. <>
  52. <div className='px-4'>
  53. <Button
  54. variant='primary'
  55. className='w-full'
  56. onClick={showSetAuthModal}
  57. >
  58. {t(`${i18nPrefix}.authorize`)}
  59. </Button>
  60. </div>
  61. </>
  62. )}
  63. {!isShowAuthBtn && <>
  64. <div className='space-y-4 px-4'>
  65. {toolInputVarSchema.length > 0 && (
  66. <Field
  67. title={t(`${i18nPrefix}.inputVars`)}
  68. >
  69. <InputVarList
  70. readOnly={readOnly}
  71. nodeId={id}
  72. schema={toolInputVarSchema as any}
  73. value={inputs.tool_parameters}
  74. onChange={setInputVar}
  75. filterVar={filterVar}
  76. isSupportConstantValue
  77. onOpen={handleOnVarOpen}
  78. />
  79. </Field>
  80. )}
  81. {toolInputVarSchema.length > 0 && toolSettingSchema.length > 0 && (
  82. <Split />
  83. )}
  84. <Form
  85. className='space-y-4'
  86. itemClassName='!py-0'
  87. fieldLabelClassName='!text-[13px] !font-semibold !text-text-secondary uppercase'
  88. value={toolSettingValue}
  89. onChange={setToolSettingValue}
  90. formSchemas={toolSettingSchema as any}
  91. isEditMode={false}
  92. showOnVariableMap={{}}
  93. validating={false}
  94. // inputClassName='!bg-gray-50'
  95. readonly={readOnly}
  96. />
  97. </div>
  98. </>}
  99. {showSetAuth && (
  100. <ConfigCredential
  101. collection={currCollection!}
  102. onCancel={hideSetAuthModal}
  103. onSaved={handleSaveAuth}
  104. isHideRemoveBtn
  105. />
  106. )}
  107. <div>
  108. <OutputVars>
  109. <>
  110. <VarItem
  111. name='text'
  112. type='string'
  113. description={t(`${i18nPrefix}.outputVars.text`)}
  114. isIndent={hasObjectOutput}
  115. />
  116. <VarItem
  117. name='files'
  118. type='array[file]'
  119. description={t(`${i18nPrefix}.outputVars.files.title`)}
  120. isIndent={hasObjectOutput}
  121. />
  122. <VarItem
  123. name='json'
  124. type='array[object]'
  125. description={t(`${i18nPrefix}.outputVars.json`)}
  126. isIndent={hasObjectOutput}
  127. />
  128. {outputSchema.map(outputItem => (
  129. <div key={outputItem.name}>
  130. {outputItem.value?.type === 'object' ? (
  131. <StructureOutputItem
  132. rootClassName='code-sm-semibold text-text-secondary'
  133. payload={{
  134. schema: {
  135. type: Type.object,
  136. properties: {
  137. [outputItem.name]: outputItem.value,
  138. },
  139. additionalProperties: false,
  140. },
  141. }} />
  142. ) : (
  143. <VarItem
  144. name={outputItem.name}
  145. type={outputItem.type.toLocaleLowerCase()}
  146. description={outputItem.description}
  147. isIndent={hasObjectOutput}
  148. />
  149. )}
  150. </div>
  151. ))}
  152. </>
  153. </OutputVars>
  154. </div>
  155. </div>
  156. )
  157. }
  158. export default React.memo(Panel)