diff --git a/web/app/components/rag-pipeline/store/index.ts b/web/app/components/rag-pipeline/store/index.ts index e39fdaa0f3..c430f1fee0 100644 --- a/web/app/components/rag-pipeline/store/index.ts +++ b/web/app/components/rag-pipeline/store/index.ts @@ -3,6 +3,8 @@ import type { StateCreator } from 'zustand' import type { ToolWithProvider, } from '@/app/components/workflow/types' +import type { DataSourceItem } from '@/app/components/workflow/block-selector/types' +import { transformDataSourceToTool } from '@/app/components/workflow/block-selector/utils' export type RagPipelineSliceShape = { pipelineId: string @@ -13,7 +15,7 @@ export type RagPipelineSliceShape = { ragPipelineVariables: RAGPipelineVariables setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => void dataSourceList: ToolWithProvider[] - setDataSourceList: (dataSourceList: ToolWithProvider[]) => void + setDataSourceList: (dataSourceList: DataSourceItem[]) => void } export type CreateRagPipelineSliceSlice = StateCreator @@ -26,5 +28,8 @@ export const createRagPipelineSliceSlice: StateCreator = ragPipelineVariables: [], setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => set(() => ({ ragPipelineVariables })), dataSourceList: [], - setDataSourceList: (dataSourceList: ToolWithProvider[]) => set(() => ({ dataSourceList })), + setDataSourceList: (dataSourceList: DataSourceItem[]) => { + const formatedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item)) + set(() => ({ dataSourceList: formatedDataSourceList })) + }, }) diff --git a/web/app/components/workflow/block-selector/data-sources.tsx b/web/app/components/workflow/block-selector/data-sources.tsx index e27bd11cc5..795adf5cc0 100644 --- a/web/app/components/workflow/block-selector/data-sources.tsx +++ b/web/app/components/workflow/block-selector/data-sources.tsx @@ -30,7 +30,6 @@ const DataSources = ({ }: AllToolsProps) => { const pluginRef = useRef(null) const wrapElemRef = useRef(null) - const formatedDataSources = dataSources.map(item => ({ ...item, tools: item.datasources || [] })) const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => { onSelect(BlockEnum.DataSource, toolDefaultValue && { provider_id: toolDefaultValue?.provider_id, @@ -52,7 +51,7 @@ const DataSources = ({ tool.label[language][0]) const treeViewToolsData = useMemo(() => { const result: Record = {} diff --git a/web/app/components/workflow/block-selector/types.ts b/web/app/components/workflow/block-selector/types.ts index 1558fd4be6..4e1abf4f47 100644 --- a/web/app/components/workflow/block-selector/types.ts +++ b/web/app/components/workflow/block-selector/types.ts @@ -1,3 +1,5 @@ +import type { TypeWithI18N } from '@/app/components/header/account-setting/model-provider-page/declarations' + export enum TabsEnum { Blocks = 'blocks', Tools = 'tools', @@ -51,3 +53,32 @@ export type ToolValue = { enabled?: boolean extra?: Record } + +export type DataSourceItem = { + plugin_id: string + plugin_unique_identifier: string + provider: string + declaration: { + credentials_schema: any[] + provider_type: string + identity: { + author: string + description: TypeWithI18N + icon: string | { background: string; content: string } + label: TypeWithI18N + name: string + tags: string[] + } + datasources: { + description: TypeWithI18N + identity: { + author: string + icon?: string | { background: string; content: string } + label: TypeWithI18N + name: string + provider: string + } + parameters: any[] + }[] + } +} diff --git a/web/app/components/workflow/block-selector/utils.ts b/web/app/components/workflow/block-selector/utils.ts new file mode 100644 index 0000000000..0ebefa2e01 --- /dev/null +++ b/web/app/components/workflow/block-selector/utils.ts @@ -0,0 +1,31 @@ +import { CollectionType } from '@/app/components/tools/types' +import type { Tool } from '@/app/components/tools/types' +import type { DataSourceItem } from './types' + +export const transformDataSourceToTool = (dataSourceItem: DataSourceItem) => { + return { + id: dataSourceItem.plugin_unique_identifier, + name: dataSourceItem.declaration.identity.name, + author: dataSourceItem.declaration.identity.author, + description: dataSourceItem.declaration.identity.description, + icon: dataSourceItem.declaration.identity.icon, + label: dataSourceItem.declaration.identity.label, + type: CollectionType.datasource, + team_credentials: {}, + is_team_authorization: false, + allow_delete: true, + labels: dataSourceItem.declaration.identity.tags || [], + plugin_id: dataSourceItem.plugin_id, + tools: dataSourceItem.declaration.datasources.map((datasource) => { + return { + name: datasource.identity.name, + author: datasource.identity.author, + label: datasource.identity.label, + description: datasource.description, + parameters: datasource.parameters, + labels: [], + output_schema: {}, + } as Tool + }), + } +} diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index b897ae7b4f..8c2c7811a4 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -519,8 +519,6 @@ const formatItem = ( const isFile = v.type === VarType.file const children = (() => { if (isFile) { - if (v.children) - return v.children return OUTPUT_FILE_SUB_VARIABLES.map((key) => { return { variable: key, @@ -539,8 +537,6 @@ const formatItem = ( const isFile = v.type === VarType.file const { children } = (() => { if (isFile) { - if (v.children) - return { children: v.children } return { children: OUTPUT_FILE_SUB_VARIABLES.map((key) => { return { diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index 4db027da6c..513c811d9a 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -57,7 +57,6 @@ const Panel: FC> = ({ id, data }) => { name={OUTPUT_VARIABLES_MAP.file.name} type={OUTPUT_VARIABLES_MAP.file.type} description={OUTPUT_VARIABLES_MAP.file.description} - subItems={OUTPUT_VARIABLES_MAP.file.subItems} /> ) } diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index cf3a55f895..235f60a9a8 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -417,7 +417,6 @@ export type MoreInfo = { export type ToolWithProvider = Collection & { tools: Tool[] - datasources?: Tool[] } export enum SupportUploadFileTypes {