From f82f06bdd078ab98cf95d659ba8b11c8ce6e06e7 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 21 Aug 2025 16:11:32 +0800 Subject: [PATCH] feat: support filter file vars --- .../workflow/nodes/_base/components/variable/utils.ts | 10 ++++++++++ .../_base/components/variable/var-reference-picker.tsx | 8 +++++--- .../components/workflow/nodes/knowledge-base/panel.tsx | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) 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 c2a29c8620..36bf0890da 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -639,6 +639,16 @@ const formatItem = ( return res } + +export const removeFileVars = (nodeWithVars: NodeOutPutVar[]) => { + return nodeWithVars.map((item) => { + return { + ...item, + vars: item.vars.filter(v => v.type !== VarType.file && v.type !== VarType.arrayFile), + } + }).filter(item => item.vars.length > 0) +} + export const toNodeOutputVars = ( nodes: any[], isChatMode: boolean, diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index 5a6bd77af3..0816da164a 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -18,7 +18,7 @@ import { import RemoveButton from '../remove-button' import useAvailableVarList from '../../hooks/use-available-var-list' import VarReferencePopup from './var-reference-popup' -import { getNodeInfoById, isConversationVar, isENV, isRagVariableVar, isSystemVar, varTypeToStructType } from './utils' +import { getNodeInfoById, isConversationVar, isENV, isRagVariableVar, isSystemVar, removeFileVars, varTypeToStructType } from './utils' import ConstantField from './constant-field' import cn from '@/utils/classnames' import type { CommonNodeType, Node, NodeOutPutVar, ToolWithProvider, ValueSelector, Var } from '@/app/components/workflow/types' @@ -63,6 +63,7 @@ type Props = { defaultVarKindType?: VarKindType onlyLeafNodeVar?: boolean filterVar?: (payload: Var, valueSelector: ValueSelector) => boolean + isFilterFileVar?: boolean availableNodes?: Node[] availableVars?: NodeOutPutVar[] isAddBtnTrigger?: boolean @@ -94,6 +95,7 @@ const VarReferencePicker: FC = ({ defaultVarKindType = VarKindType.constant, onlyLeafNodeVar, filterVar = () => true, + isFilterFileVar, availableNodes: passedInAvailableNodes, availableVars: passedInAvailableVars, isAddBtnTrigger, @@ -146,8 +148,8 @@ const VarReferencePicker: FC = ({ const outputVars = useMemo(() => { const results = passedInAvailableVars || availableVars - return results - }, [passedInAvailableVars, availableVars]) + return isFilterFileVar ? removeFileVars(results) : results + }, [passedInAvailableVars, availableVars, isFilterFileVar]) const [open, setOpen] = useState(false) useEffect(() => { diff --git a/web/app/components/workflow/nodes/knowledge-base/panel.tsx b/web/app/components/workflow/nodes/knowledge-base/panel.tsx index 94de0bd70a..0a5bda5d1b 100644 --- a/web/app/components/workflow/nodes/knowledge-base/panel.tsx +++ b/web/app/components/workflow/nodes/knowledge-base/panel.tsx @@ -76,6 +76,7 @@ const Panel: FC> = ({ onChange={handleInputVariableChange} readonly={nodesReadOnly} filterVar={filterVar} + isFilterFileVar isSupportFileVar={false} />