From e7370766bd7ad58ed15627c35bfce4247b36654f Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Fri, 23 May 2025 18:19:01 +0800 Subject: [PATCH] datasource --- .../workflow/block-selector/data-sources.tsx | 1 + .../nodes/_base/components/variable/utils.ts | 11 +++- .../workflow/nodes/data-source/constants.ts | 46 +++++++++++++++++ .../workflow/nodes/data-source/default.ts | 33 +++++++++++- .../workflow/nodes/data-source/panel.tsx | 51 +++---------------- web/app/components/workflow/types.ts | 1 + 6 files changed, 98 insertions(+), 45 deletions(-) create mode 100644 web/app/components/workflow/nodes/data-source/constants.ts diff --git a/web/app/components/workflow/block-selector/data-sources.tsx b/web/app/components/workflow/block-selector/data-sources.tsx index 467ddaa9e7..e27bd11cc5 100644 --- a/web/app/components/workflow/block-selector/data-sources.tsx +++ b/web/app/components/workflow/block-selector/data-sources.tsx @@ -38,6 +38,7 @@ const DataSources = ({ provider_name: toolDefaultValue?.provider_name, datasource_name: toolDefaultValue?.tool_name, datasource_label: toolDefaultValue?.tool_label, + title: toolDefaultValue?.title, }) }, [onSelect]) 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 428c204dd3..b897ae7b4f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -33,6 +33,7 @@ import { TEMPLATE_TRANSFORM_OUTPUT_STRUCT, TOOL_OUTPUT_STRUCT, } from '@/app/components/workflow/constants' +import DataSourceNodeDefault from '@/app/components/workflow/nodes/data-source/default' import type { PromptItem } from '@/models/debug' import { VAR_REGEX } from '@/config' import type { AgentNodeType } from '../../../agent/types' @@ -457,6 +458,11 @@ const formatItem = ( break } + case BlockEnum.DataSource: { + res.vars = DataSourceNodeDefault.getOutputVars?.(data as any) || [] + break + } + case 'env': { res.vars = data.envList.map((env: EnvironmentVariable) => { return { @@ -513,6 +519,8 @@ 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, @@ -529,9 +537,10 @@ const formatItem = ( return obj?.children && ((obj?.children as Var[]).length > 0 || Object.keys((obj?.children as StructuredOutput)?.schema?.properties || {}).length > 0) }).map((v) => { 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/constants.ts b/web/app/components/workflow/nodes/data-source/constants.ts new file mode 100644 index 0000000000..777f4689a8 --- /dev/null +++ b/web/app/components/workflow/nodes/data-source/constants.ts @@ -0,0 +1,46 @@ +import { VarType } from '@/app/components/workflow/types' + +export const OUTPUT_VARIABLES_MAP = { + datasource_type: { + name: 'datasource_type', + type: VarType.string, + description: 'local_file, online_document, website_crawl', + }, + file: { + name: 'file', + type: VarType.file, + description: 'file', + subItems: [ + { + name: 'type', + type: VarType.string, + description: '', + }, + { + name: 'upload_file_id', + type: VarType.string, + description: '', + }, + { + name: 'name', + type: VarType.string, + description: '', + }, + { + name: 'size', + type: VarType.number, + description: '', + }, + { + name: 'extension', + type: VarType.string, + description: '', + }, + { + name: 'mime_type', + type: VarType.string, + description: '', + }, + ], + }, +} diff --git a/web/app/components/workflow/nodes/data-source/default.ts b/web/app/components/workflow/nodes/data-source/default.ts index 6236ed927a..23ad741998 100644 --- a/web/app/components/workflow/nodes/data-source/default.ts +++ b/web/app/components/workflow/nodes/data-source/default.ts @@ -2,6 +2,8 @@ import type { NodeDefault } from '../../types' import type { DataSourceNodeType } from './types' import { genNodeMetaData } from '@/app/components/workflow/utils' import { BlockEnum } from '@/app/components/workflow/types' +import { CollectionType } from '@/app/components/tools/types' +import { OUTPUT_VARIABLES_MAP } from './constants' const metaData = genNodeMetaData({ sort: -1, @@ -9,13 +11,42 @@ const metaData = genNodeMetaData({ }) const nodeDefault: NodeDefault = { metaData, - defaultValue: {}, + defaultValue: { + datasource_parameters: {}, + datasource_configurations: {}, + }, checkValid() { return { isValid: true, errorMessage: '', } }, + getOutputVars(payload) { + const { provider_id, provider_type } = payload + const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource + return [ + { + variable: OUTPUT_VARIABLES_MAP.datasource_type.name, + type: OUTPUT_VARIABLES_MAP.datasource_type.type, + }, + ...( + isLocalFile + ? [ + { + variable: OUTPUT_VARIABLES_MAP.file.name, + type: OUTPUT_VARIABLES_MAP.file.type, + children: OUTPUT_VARIABLES_MAP.file.subItems.map((item) => { + return { + variable: item.name, + type: item.type, + } + }), + }, + ] + : [] + ), + ] + }, } export default nodeDefault diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index a9a303e616..4db027da6c 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -8,6 +8,7 @@ import { BoxGroupField } from '@/app/components/workflow/nodes/_base/components/ import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import TagInput from '@/app/components/base/tag-input' import { useConfig } from './hooks/use-config' +import { OUTPUT_VARIABLES_MAP } from './constants' const Panel: FC> = ({ id, data }) => { const { t } = useTranslation() @@ -46,53 +47,17 @@ const Panel: FC> = ({ id, data }) => { } { isLocalFile && ( ) } diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 0519a6dddb..cfe98c6f2a 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -313,6 +313,7 @@ export type NodeDefault = { } defaultValue: Partial checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string } + getOutputVars?: (payload: T) => Var[] } export type OnSelectBlock = (type: BlockEnum, toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue) => void