You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data-source.ts 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import type {
  2. InputVar,
  3. ToolWithProvider,
  4. } from '../types'
  5. import type { DataSourceNodeType } from '../nodes/data-source/types'
  6. import { CollectionType } from '@/app/components/tools/types'
  7. import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
  8. export const getDataSourceCheckParams = (
  9. toolData: DataSourceNodeType,
  10. dataSourceList: ToolWithProvider[],
  11. language: string,
  12. ) => {
  13. const { plugin_id, provider_type, datasource_name } = toolData
  14. const isBuiltIn = provider_type === CollectionType.builtIn
  15. const currentDataSource = dataSourceList.find(item => item.plugin_id === plugin_id)
  16. const currentDataSourceItem = currentDataSource?.tools.find(tool => tool.name === datasource_name)
  17. const formSchemas = currentDataSourceItem ? toolParametersToFormSchemas(currentDataSourceItem.parameters) : []
  18. return {
  19. dataSourceInputsSchema: (() => {
  20. const formInputs: InputVar[] = []
  21. formSchemas.forEach((item: any) => {
  22. formInputs.push({
  23. label: item.label[language] || item.label.en_US,
  24. variable: item.variable,
  25. type: item.type,
  26. required: item.required,
  27. hide: item.hide,
  28. })
  29. })
  30. return formInputs
  31. })(),
  32. notAuthed: isBuiltIn && !!currentDataSource?.allow_delete && !currentDataSource?.is_authorized,
  33. language,
  34. }
  35. }