From 522210bad67ef84c9e2a8038e85a12170f9f1836 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Tue, 5 Aug 2025 11:39:17 +0800 Subject: [PATCH 1/2] fix: rag variable --- .../plugins/workflow-variable-block/component.tsx | 5 ++++- .../workflow/nodes/_base/components/variable-tag.tsx | 6 +++--- .../components/variable/var-reference-picker.tsx | 3 ++- .../_base/components/variable/var-reference-vars.tsx | 5 +++-- .../_base/components/variable/variable-label/hooks.ts | 11 ++++++++++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx index dffeeb7a1b..1e4bc5b8a9 100644 --- a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx +++ b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/component.tsx @@ -62,7 +62,7 @@ const WorkflowVariableBlockComponent = ({ } )() const [localWorkflowNodesMap, setLocalWorkflowNodesMap] = useState(workflowNodesMap) - const node = localWorkflowNodesMap![variables[0]] + const node = localWorkflowNodesMap![variables[isRagVar ? 1 : 0]] const isEnv = isENV(variables) const isChatVar = isConversationVar(variables) const isException = isExceptionVariable(varName, node?.type) @@ -76,6 +76,9 @@ const WorkflowVariableBlockComponent = ({ if (conversationVariables) variableValid = conversationVariables.some(v => v.variable === `${variables?.[0] ?? ''}.${variables?.[1] ?? ''}`) } + else if (isRagVar) { + variableValid = !!node || (variables[0] === 'rag' && variables[1] === 'shared') + } else { variableValid = !!node } diff --git a/web/app/components/workflow/nodes/_base/components/variable-tag.tsx b/web/app/components/workflow/nodes/_base/components/variable-tag.tsx index 4896d485d7..4d3dfe217c 100644 --- a/web/app/components/workflow/nodes/_base/components/variable-tag.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable-tag.tsx @@ -27,18 +27,18 @@ const VariableTag = ({ availableNodes, }: VariableTagProps) => { const nodes = useNodes() + const isRagVar = isRagVariableVar(valueSelector) const node = useMemo(() => { if (isSystemVar(valueSelector)) { const startNode = availableNodes?.find(n => n.data.type === BlockEnum.Start) if (startNode) return startNode } - return getNodeInfoById(availableNodes || nodes, valueSelector[0]) - }, [nodes, valueSelector, availableNodes]) + return getNodeInfoById(availableNodes || nodes, isRagVar ? valueSelector[1] : valueSelector[0]) + }, [nodes, valueSelector, availableNodes, isRagVar]) const isEnv = isENV(valueSelector) const isChatVar = isConversationVar(valueSelector) - const isRagVar = isRagVariableVar(valueSelector) const isValid = Boolean(node) || isEnv || isChatVar || isRagVar const variableName = isSystemVar(valueSelector) ? valueSelector.slice(0).join('.') : valueSelector.slice(1).join('.') 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 5210ff6a71..d57f09ea0d 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 @@ -390,8 +390,9 @@ const VarReferencePicker: FC = ({ if (isEnv) return 'environment' if (isChatVar) return 'conversation' if (isLoopVar) return 'loop' + if (isRagVar) return 'rag' return 'system' - }, [isEnv, isChatVar, isLoopVar]) + }, [isEnv, isChatVar, isLoopVar, isRagVar]) return (
diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx index 4008bdb2e6..3ea397a440 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx @@ -135,8 +135,9 @@ const Item: FC = ({ if (isEnv) return 'environment' if (isChatVar) return 'conversation' if (isLoopVar) return 'loop' + if (isRagVariable) return 'rag' return 'system' - }, [isEnv, isChatVar, isSys, isLoopVar]) + }, [isEnv, isChatVar, isSys, isLoopVar, isRagVariable]) return ( = ({ variableCategory={variableCategory} isExceptionVariable={isException} /> - {!isEnv && !isChatVar && ( + {!isEnv && !isChatVar && !isRagVariable && (
{itemData.variable}
)} {isEnv && ( diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts index 14ca87903b..d30522f11f 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts @@ -2,9 +2,11 @@ import { useMemo } from 'react' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' import { Loop } from '@/app/components/base/icons/src/vender/workflow' +import { InputField } from '@/app/components/base/icons/src/vender/pipeline' import { isConversationVar, isENV, + isRagVariableVar, isSystemVar, } from '../utils' import { VarInInspectType } from '@/types/workflow' @@ -13,6 +15,9 @@ export const useVarIcon = (variables: string[], variableCategory?: VarInInspectT if (variableCategory === 'loop') return Loop + if (variableCategory === 'rag' || isRagVariableVar(variables)) + return InputField + if (isENV(variables) || variableCategory === VarInInspectType.environment || variableCategory === 'environment') return Env @@ -41,7 +46,11 @@ export const useVarColor = (variables: string[], isExceptionVariable?: boolean, } export const useVarName = (variables: string[], notShowFullPath?: boolean) => { - const variableFullPathName = variables.slice(1).join('.') + let variableFullPathName = variables.slice(1).join('.') + + if (isRagVariableVar(variables) && variables[1] === 'shared') + variableFullPathName = variables.slice(2).join('.') + const variablesLength = variables.length const varName = useMemo(() => { const isSystem = isSystemVar(variables) From 09b5cacbad7feb5cd9f7ea6d43d87721dd7fcc09 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Tue, 5 Aug 2025 13:02:51 +0800 Subject: [PATCH 2/2] fix: rag variable --- .../nodes/_base/components/variable/variable-label/hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts index d30522f11f..19690edcba 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/variable-label/hooks.ts @@ -48,7 +48,7 @@ export const useVarColor = (variables: string[], isExceptionVariable?: boolean, export const useVarName = (variables: string[], notShowFullPath?: boolean) => { let variableFullPathName = variables.slice(1).join('.') - if (isRagVariableVar(variables) && variables[1] === 'shared') + if (isRagVariableVar(variables)) variableFullPathName = variables.slice(2).join('.') const variablesLength = variables.length