diff --git a/web/app/components/workflow/block-selector/constants.tsx b/web/app/components/workflow/block-selector/constants.tsx index f10035bcfd..ab0c9586dc 100644 --- a/web/app/components/workflow/block-selector/constants.tsx +++ b/web/app/components/workflow/block-selector/constants.tsx @@ -7,3 +7,25 @@ export const BLOCK_CLASSIFICATIONS: string[] = [ BlockClassificationEnum.Transform, BlockClassificationEnum.Utilities, ] + +export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [ + 'txt', + 'markdown', + 'mdx', + 'pdf', + 'html', + 'xlsx', + 'xls', + 'vtt', + 'properties', + 'doc', + 'docx', + 'csv', + 'eml', + 'msg', + 'pptx', + 'xml', + 'epub', + 'ppt', + 'md', +] diff --git a/web/app/components/workflow/block-selector/data-sources.tsx b/web/app/components/workflow/block-selector/data-sources.tsx index 6b2293afa5..294c7c1c79 100644 --- a/web/app/components/workflow/block-selector/data-sources.tsx +++ b/web/app/components/workflow/block-selector/data-sources.tsx @@ -10,13 +10,14 @@ import type { OnSelectBlock, ToolWithProvider, } from '../types' -import type { ToolDefaultValue } from './types' +import type { DataSourceDefaultValue, ToolDefaultValue } from './types' import Tools from './tools' import { ViewType } from './view-type-select' import cn from '@/utils/classnames' import type { ListRef } from '@/app/components/workflow/block-selector/market-place-plugin/list' import { getMarketplaceUrl } from '@/utils/var' import { useGlobalPublicStore } from '@/context/global-public-context' +import { DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE } from './constants' type AllToolsProps = { className?: string @@ -37,14 +38,22 @@ const DataSources = ({ const pluginRef = useRef(null) const wrapElemRef = useRef(null) const handleSelect = useCallback((_: any, toolDefaultValue: ToolDefaultValue) => { - onSelect(BlockEnum.DataSource, toolDefaultValue && { + let defaultValue: DataSourceDefaultValue = { plugin_id: toolDefaultValue?.provider_id, provider_type: toolDefaultValue?.provider_type, provider_name: toolDefaultValue?.provider_name, datasource_name: toolDefaultValue?.tool_name, datasource_label: toolDefaultValue?.tool_label, title: toolDefaultValue?.title, - }) + } + // Update defaultValue with fileExtensions if this is the local file data source + if (toolDefaultValue?.provider_id === 'langgenius/file' && toolDefaultValue?.provider_name === 'file') { + defaultValue = { + ...defaultValue, + fileExtensions: DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE, + } + } + onSelect(BlockEnum.DataSource, toolDefaultValue && defaultValue) }, [onSelect]) const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) diff --git a/web/app/components/workflow/block-selector/types.ts b/web/app/components/workflow/block-selector/types.ts index a5eefe7095..be960b1246 100644 --- a/web/app/components/workflow/block-selector/types.ts +++ b/web/app/components/workflow/block-selector/types.ts @@ -46,6 +46,7 @@ export type DataSourceDefaultValue = { datasource_name: string datasource_label: string title: string + fileExtensions?: string[] } export type ToolValue = { diff --git a/web/app/components/workflow/nodes/data-source/constants.ts b/web/app/components/workflow/nodes/data-source/constants.ts index 6c576df25d..1ff9f722e2 100644 --- a/web/app/components/workflow/nodes/data-source/constants.ts +++ b/web/app/components/workflow/nodes/data-source/constants.ts @@ -1,27 +1,5 @@ import { VarType } from '@/app/components/workflow/types' -export const DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE = [ - 'txt', - 'markdown', - 'mdx', - 'pdf', - 'html', - 'xlsx', - 'xls', - 'vtt', - 'properties', - 'doc', - 'docx', - 'csv', - 'eml', - 'msg', - 'pptx', - 'xml', - 'epub', - 'ppt', - 'md', -] - export const COMMON_OUTPUT = [ { name: 'datasource_type', diff --git a/web/app/components/workflow/nodes/data-source/hooks/use-config.ts b/web/app/components/workflow/nodes/data-source/hooks/use-config.ts index 8624bb98f5..98683e70e7 100644 --- a/web/app/components/workflow/nodes/data-source/hooks/use-config.ts +++ b/web/app/components/workflow/nodes/data-source/hooks/use-config.ts @@ -9,7 +9,6 @@ import type { DataSourceNodeType, ToolVarInputs, } from '../types' -import { DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE } from '../constants' export const useConfig = (id: string, dataSourceList?: any[]) => { const store = useStoreApi() @@ -36,7 +35,6 @@ export const useConfig = (id: string, dataSourceList?: any[]) => { handleNodeDataUpdate({ ...nodeData.data, _dataSourceStartToAdd: false, - fileExtensions: DEFAULT_FILE_EXTENSIONS_IN_LOCAL_FILE_DATA_SOURCE, }) } }, [getNodeData, handleNodeDataUpdate])