From 7cef0fff890abe19d040b9d8b745ae096e80b4a4 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Wed, 5 Nov 2025 18:28:17 +0800 Subject: [PATCH] fix: --- .../components/base/prompt-editor/index.tsx | 12 +---- .../plugins/memory-popup-plugin/index.tsx | 26 +++++----- .../plugins/workflow-variable-block/node.tsx | 2 + ...kflow-variable-block-replacement-block.tsx | 3 +- .../hooks/use-fetch-workflow-inspect-vars.ts | 2 +- .../hooks/use-inspect-vars-crud-common.ts | 2 +- .../workflow/hooks/use-workflow-variables.ts | 5 +- .../nodes/_base/components/prompt/editor.tsx | 9 ---- .../nodes/_base/components/variable/utils.ts | 52 +++++++++++++------ .../variable/var-reference-vars.tsx | 19 +++++-- .../_base/hooks/use-available-var-list.ts | 21 ++++++-- .../nodes/_base/hooks/use-one-step-run.ts | 3 +- .../workflow/nodes/iteration/use-config.ts | 2 +- .../llm/components/config-prompt-item.tsx | 9 ---- .../nodes/llm/components/config-prompt.tsx | 12 ----- .../components/workflow/nodes/llm/panel.tsx | 6 --- .../workflow/nodes/llm/use-config.ts | 33 ++---------- .../workflow/nodes/loop/use-config.ts | 4 +- .../components/variable-modal.tsx | 3 +- .../hooks/use-form/use-type-schema.ts | 2 +- .../panel/chat-variable-panel/type.ts | 2 +- web/app/components/workflow/types.ts | 4 +- 22 files changed, 104 insertions(+), 129 deletions(-) diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index c5dd9720e5..3e03452651 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -80,9 +80,6 @@ import { UPDATE_HISTORY_EVENT_EMITTER, } from './constants' import { useEventEmitterContextContext } from '@/context/event-emitter' -import type { - MemoryVariable, -} from '@/app/components/workflow/types' import cn from '@/utils/classnames' export type PromptEditorProps = { @@ -109,8 +106,6 @@ export type PromptEditorProps = { lastRunBlock?: LastRunBlockType isSupportFileVar?: boolean isMemorySupported?: boolean - memoryVarInNode?: MemoryVariable[] - memoryVarInApp?: MemoryVariable[] } const PromptEditor: FC = ({ @@ -137,8 +132,6 @@ const PromptEditor: FC = ({ lastRunBlock, isSupportFileVar, isMemorySupported, - memoryVarInNode = [], - memoryVarInApp = [], }) => { const { eventEmitter } = useEventEmitterContextContext() const initialConfig = { @@ -209,11 +202,10 @@ const PromptEditor: FC = ({ } ErrorBoundary={LexicalErrorBoundary} /> - {isMemorySupported && ( + {isMemorySupported && workflowVariableBlock?.show && ( v.nodeId === 'memory_block')?.vars || []} /> )} container ?? (typeof document !== 'undefined' ? document.body : null), [container]) const useContainer = !!containerEl && containerEl !== document.body + const memoryVarInNode = memoryVariables.filter(memoryVariable => memoryVariable.memoryVariableNodeId) + const memoryVarInApp = memoryVariables.filter(memoryVariable => !memoryVariable.memoryVariableNodeId) const { refs, floatingStyles, isPositioned } = useFloating({ placement: 'bottom-start', @@ -213,15 +213,15 @@ export default function MemoryPopupPlugin({
{memoryVarInNode.map(variable => (
handleSelectVariable(['memory_block', variable.id])} + onClick={() => handleSelectVariable(['memory_block', variable.variable])} > -
{variable.name}
+
{variable.memoryVariableName}
))}
@@ -237,15 +237,15 @@ export default function MemoryPopupPlugin({
{memoryVarInApp.map(variable => (
handleSelectVariable(['memory_block', variable.id])} + onClick={() => handleSelectVariable(['memory_block', variable.variable])} > -
{variable.name}
+
{variable.memoryVariableName}
))}
diff --git a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/node.tsx b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/node.tsx index afdf7844ba..fa9207ce25 100644 --- a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/node.tsx +++ b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/node.tsx @@ -13,6 +13,7 @@ export type SerializedNode = SerializedLexicalNode & { getVarType?: GetVarType environmentVariables?: Var[] conversationVariables?: Var[] + memoryVariables?: Var[] ragVariables?: Var[] } @@ -98,6 +99,7 @@ export class WorkflowVariableBlockNode extends DecoratorNode getVarType: this.getVarType(), environmentVariables: this.getEnvironmentVariables(), conversationVariables: this.getConversationVariables(), + memoryVariables: this.getMemoryVariables(), ragVariables: this.getRagVariables(), } } diff --git a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/workflow-variable-block-replacement-block.tsx b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/workflow-variable-block-replacement-block.tsx index 62b9cccb3f..d705060fc9 100644 --- a/web/app/components/base/prompt-editor/plugins/workflow-variable-block/workflow-variable-block-replacement-block.tsx +++ b/web/app/components/base/prompt-editor/plugins/workflow-variable-block/workflow-variable-block-replacement-block.tsx @@ -28,6 +28,7 @@ const WorkflowVariableBlockReplacementBlock = ({ acc.push(...curr.vars.filter(v => v.isRagVariable)) return acc }, []) + const memoryVariables = variables?.find(variable => variable.nodeId === 'memory_block')?.vars || [] useEffect(() => { if (!editor.hasNodes([WorkflowVariableBlockNode])) @@ -39,7 +40,7 @@ const WorkflowVariableBlockReplacementBlock = ({ onInsert() const nodePathString = textNode.getTextContent().slice(3, -3) - return $applyNodeReplacement($createWorkflowVariableBlockNode(nodePathString.split('.'), workflowNodesMap, getVarType, variables?.find(o => o.nodeId === 'env')?.vars || [], variables?.find(o => o.nodeId === 'conversation')?.vars || [], ragVariables)) + return $applyNodeReplacement($createWorkflowVariableBlockNode(nodePathString.split('.'), workflowNodesMap, getVarType, variables?.find(o => o.nodeId === 'env')?.vars || [], variables?.find(o => o.nodeId === 'conversation')?.vars || [], memoryVariables, ragVariables)) }, [onInsert, workflowNodesMap, getVarType, variables]) const getMatch = useCallback((text: string) => { diff --git a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts index 60f839b93d..4d9c3fe0b8 100644 --- a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts @@ -51,7 +51,7 @@ export const useSetWorkflowVarsWithValue = ({ const { getNodes } = store.getState() const nodeArr = getNodes() - const allNodesOutputVars = toNodeOutputVars(nodeArr, false, () => true, [], [], [], passedInAllPluginInfoList || allPluginInfoList, passedInSchemaTypeDefinitions || schemaTypeDefinitions) + const allNodesOutputVars = toNodeOutputVars(nodeArr, false, () => true, [], [], [], [], passedInAllPluginInfoList || allPluginInfoList, passedInSchemaTypeDefinitions || schemaTypeDefinitions) const nodesKeyValue: Record = {} nodeArr.forEach((node) => { diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts index 6b7acd0a85..fc8833d036 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts @@ -132,7 +132,7 @@ export const useInspectVarsCrudCommon = ({ mcpTools: mcpTools || [], dataSourceList: dataSourceList || [], } - const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], allPluginInfoList, schemaTypeDefinitions) + const currentNodeOutputVars = toNodeOutputVars([currentNode], false, () => true, [], [], [], [], allPluginInfoList, schemaTypeDefinitions) const vars = await fetchNodeInspectVars(flowType, flowId, nodeId) const varsWithSchemaType = vars.map((varItem) => { const schemaType = currentNodeOutputVars[0]?.vars.find(v => v.variable === varItem.name)?.schemaType || '' diff --git a/web/app/components/workflow/hooks/use-workflow-variables.ts b/web/app/components/workflow/hooks/use-workflow-variables.ts index 468a0142b3..e0387d6296 100644 --- a/web/app/components/workflow/hooks/use-workflow-variables.ts +++ b/web/app/components/workflow/hooks/use-workflow-variables.ts @@ -37,7 +37,6 @@ export const useWorkflowVariables = () => { hideEnv, hideChatVar, conversationVariablesFirst, - memoryVarSortFn, }: { parentNode?: Node | null beforeNodes: Node[] @@ -46,11 +45,11 @@ export const useWorkflowVariables = () => { hideEnv?: boolean hideChatVar?: boolean conversationVariablesFirst?: boolean - memoryVarSortFn?: (a: string, b: string) => number }): NodeOutPutVar[] => { const { conversationVariables, environmentVariables, + memoryVariables, ragPipelineVariables, dataSourceList, } = workflowStore.getState() @@ -61,6 +60,7 @@ export const useWorkflowVariables = () => { isChatMode, environmentVariables: hideEnv ? [] : environmentVariables, conversationVariables: (isChatMode && !hideChatVar) ? conversationVariables : [], + memoryVariables: isChatMode ? memoryVariables : [], ragVariables: ragPipelineVariables, filterVar, allPluginInfoList: { @@ -72,7 +72,6 @@ export const useWorkflowVariables = () => { }, schemaTypeDefinitions, conversationVariablesFirst, - memoryVarSortFn, }) }, [t, workflowStore, schemaTypeDefinitions, buildInTools, customTools, workflowTools, mcpTools]) diff --git a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx index 5ee8484f58..b6b1544fc3 100644 --- a/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/prompt/editor.tsx @@ -38,9 +38,6 @@ import { useStore } from '@/app/components/workflow/store' import { useWorkflowVariableType } from '@/app/components/workflow/hooks' import AddMemoryButton from './add-memory-button' import { MEMORY_POPUP_SHOW_BY_EVENT_EMITTER } from './type' -import type { - MemoryVariable, -} from '@/app/components/workflow/types' import MemoryCreateButton from '@/app/components/workflow/nodes/llm/components/memory-system/memory-create-button' type Props = { @@ -86,8 +83,6 @@ type Props = { titleClassName?: string required?: boolean isMemorySupported?: boolean - memoryVarInNode?: MemoryVariable[] - memoryVarInApp?: MemoryVariable[] } const Editor: FC = ({ @@ -128,8 +123,6 @@ const Editor: FC = ({ editorContainerClassName, required, isMemorySupported, - memoryVarInNode = [], - memoryVarInApp = [], }) => { const { t } = useTranslation() const { eventEmitter } = useEventEmitterContextContext() @@ -311,8 +304,6 @@ const Editor: FC = ({ editable={!readOnly} isSupportFileVar={isSupportFileVar} isMemorySupported - memoryVarInNode={memoryVarInNode} - memoryVarInApp={memoryVarInApp} /> {/* to patch Editor not support dynamic change editable status */} {readOnly &&
} 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 ddffcff4e7..b93a28e135 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -39,7 +39,7 @@ import type { import type { VariableAssignerNodeType } from '@/app/components/workflow/nodes/variable-assigner/types' import type { Field as StructField } from '@/app/components/workflow/nodes/llm/types' import type { RAGPipelineVariable } from '@/models/pipeline' - +import type { MemoryVariable } from '@/app/components/workflow/types' import { AGENT_OUTPUT_STRUCT, FILE_STRUCT, @@ -82,7 +82,7 @@ export const isRagVariableVar = (valueSelector: ValueSelector) => { } export const isSpecialVar = (prefix: string): boolean => { - return ['sys', 'env', 'conversation', 'rag'].includes(prefix) + return ['sys', 'env', 'conversation', 'memory_block', 'rag'].includes(prefix) } export const hasValidChildren = (children: any): boolean => { @@ -313,7 +313,6 @@ const formatItem = ( allPluginInfoList: Record, ragVars?: Var[], schemaTypeDefinitions: SchemaTypeDefinition[] = [], - memoryVarSortFn?: (a: string, b: string) => number, ): NodeOutPutVar => { const { id, data } = item @@ -629,15 +628,25 @@ const formatItem = ( } case 'conversation': { - if (memoryVarSortFn) - data.chatVarList.sort(memoryVarSortFn) - res.vars = data.chatVarList.map((chatVar: ConversationVariable) => { - return { - variable: `conversation.${chatVar.name}`, - type: chatVar.value_type, - description: chatVar.description, - } - }) as Var[] + res.vars = [ + ...data.memoryVarList.map((memoryVar: MemoryVariable) => { + return { + variable: `memory_block.${memoryVar.node_id ? `${memoryVar.node_id}_` : ''}${memoryVar.id}`, + type: 'memory_block', + description: '', + isMemoryVariable: true, + memoryVariableName: memoryVar.name, + memoryVariableNodeId: memoryVar.node_id, + } + }) as Var[], + ...data.chatVarList.map((chatVar: ConversationVariable) => { + return { + variable: `conversation.${chatVar.name}`, + type: chatVar.value_type, + description: chatVar.description, + } + }) as Var[], + ] break } @@ -680,11 +689,13 @@ const formatItem = ( (() => { const variableArr = v.variable.split('.') const [first] = variableArr + if (isSpecialVar(first)) return variableArr return [...selector, ...variableArr] })(), ) + if (isCurrentMatched) return true const isFile = v.type === VarType.file @@ -759,11 +770,11 @@ export const toNodeOutputVars = ( filterVar = (_payload: Var, _selector: ValueSelector) => true, environmentVariables: EnvironmentVariable[] = [], conversationVariables: ConversationVariable[] = [], + memoryVariables: MemoryVariable[] = [], ragVariables: RAGPipelineVariable[] = [], allPluginInfoList: Record, schemaTypeDefinitions?: SchemaTypeDefinition[], conversationVariablesFirst: boolean = false, - memoryVarSortFn?: (a: string, b: string) => number, ): NodeOutPutVar[] => { // ENV_NODE data format const ENV_NODE = { @@ -780,6 +791,7 @@ export const toNodeOutputVars = ( data: { title: 'CONVERSATION', type: 'conversation', + memoryVarList: memoryVariables, chatVarList: conversationVariables, }, } @@ -802,6 +814,8 @@ export const toNodeOutputVars = ( if (b.data.type === 'env') return -1 if (a.data.type === 'conversation') return 1 if (b.data.type === 'conversation') return -1 + if (a.data.type === 'memory_block') return 1 + if (b.data.type === 'memory_block') return -1 // sort nodes by x position return (b.position?.x || 0) - (a.position?.x || 0) }) @@ -851,7 +865,6 @@ export const toNodeOutputVars = ( } as Var), ), schemaTypeDefinitions, - memoryVarSortFn, ), isStartNode: node.data.type === BlockEnum.Start, } @@ -979,6 +992,7 @@ export const getVarType = ({ isConstant, environmentVariables = [], conversationVariables = [], + memoryVariables = [], ragVariables = [], allPluginInfoList, schemaTypeDefinitions, @@ -993,6 +1007,7 @@ export const getVarType = ({ isConstant?: boolean; environmentVariables?: EnvironmentVariable[]; conversationVariables?: ConversationVariable[]; + memoryVariables?: MemoryVariable[]; ragVariables?: RAGPipelineVariable[]; allPluginInfoList: Record; schemaTypeDefinitions?: SchemaTypeDefinition[]; @@ -1006,6 +1021,7 @@ export const getVarType = ({ undefined, environmentVariables, conversationVariables, + memoryVariables, ragVariables, allPluginInfoList, schemaTypeDefinitions, @@ -1132,12 +1148,12 @@ export const toNodeAvailableVars = ({ isChatMode, environmentVariables, conversationVariables, + memoryVariables, ragVariables, filterVar, allPluginInfoList, schemaTypeDefinitions, conversationVariablesFirst, - memoryVarSortFn, }: { parentNode?: Node | null; t?: any; @@ -1148,13 +1164,14 @@ export const toNodeAvailableVars = ({ environmentVariables?: EnvironmentVariable[]; // chat var conversationVariables?: ConversationVariable[]; + // memory variables + memoryVariables?: MemoryVariable[]; // rag variables ragVariables?: RAGPipelineVariable[]; filterVar: (payload: Var, selector: ValueSelector) => boolean; allPluginInfoList: Record; schemaTypeDefinitions?: SchemaTypeDefinition[]; conversationVariablesFirst?: boolean - memoryVarSortFn?: (a: string, b: string) => number }): NodeOutPutVar[] => { const beforeNodesOutputVars = toNodeOutputVars( beforeNodes, @@ -1162,11 +1179,11 @@ export const toNodeAvailableVars = ({ filterVar, environmentVariables, conversationVariables, + memoryVariables, ragVariables, allPluginInfoList, schemaTypeDefinitions, conversationVariablesFirst, - memoryVarSortFn, ) const isInIteration = parentNode?.data.type === BlockEnum.Iteration if (isInIteration) { @@ -1179,6 +1196,7 @@ export const toNodeAvailableVars = ({ isChatMode, environmentVariables, conversationVariables, + memoryVariables, allPluginInfoList, schemaTypeDefinitions, }) 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 e70cfed97c..25b2d92a72 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 @@ -64,6 +64,7 @@ const Item: FC = ({ const isSys = itemData.variable.startsWith('sys.') const isEnv = itemData.variable.startsWith('env.') const isChatVar = itemData.variable.startsWith('conversation.') + const isMemoryVar = itemData.variable.startsWith('memory_block') const isRagVariable = itemData.isRagVariable const flatVarIcon = useMemo(() => { if (!isFlat) @@ -147,7 +148,7 @@ const Item: FC = ({ if (isFlat) { onChange([itemData.variable], itemData) } - else if (isSys || isEnv || isChatVar || isRagVariable) { // system variable | environment variable | conversation variable + else if (isSys || isEnv || isChatVar || isMemoryVar || isRagVariable) { // system variable | environment variable | conversation variable onChange([...objPath, ...itemData.variable.split('.')], itemData) } else { @@ -157,10 +158,16 @@ const Item: FC = ({ const variableCategory = useMemo(() => { if (isEnv) return 'environment' if (isChatVar) return 'conversation' + if (isMemoryVar) return 'memory_block' if (isLoopVar) return 'loop' if (isRagVariable) return 'rag' return 'system' - }, [isEnv, isChatVar, isSys, isLoopVar, isRagVariable]) + }, [isEnv, isChatVar, isMemoryVar, isSys, isLoopVar, isRagVariable]) + const variableType = useMemo(() => { + if (itemData.type === 'memory_block') + return 'memory' + return itemData.type + }, [itemData.type]) return ( = ({ />} {isFlat && flatVarIcon} - {!isEnv && !isChatVar && !isRagVariable && ( + {!isEnv && !isChatVar && !isMemoryVar && !isRagVariable && (
{varName}
)} {isEnv && ( @@ -196,11 +203,15 @@ const Item: FC = ({ {isChatVar && (
{itemData.variable.replace('conversation.', '')}
)} + {isMemoryVar && ( +
{itemData.memoryVariableName}
+ ) + } {isRagVariable && (
{itemData.variable.split('.').slice(-1)[0]}
)} -
{(preferSchemaType && itemData.schemaType) ? itemData.schemaType : itemData.type}
+
{(preferSchemaType && itemData.schemaType) ? itemData.schemaType : variableType}
{ (isObj || isStructureOutput) && ( diff --git a/web/app/components/workflow/nodes/_base/hooks/use-available-var-list.ts b/web/app/components/workflow/nodes/_base/hooks/use-available-var-list.ts index f0847e5eba..c58b6f8c1c 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-available-var-list.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-available-var-list.ts @@ -16,7 +16,6 @@ type Params = { filterVar: (payload: Var, selector: ValueSelector) => boolean passedInAvailableNodes?: Node[] conversationVariablesFirst?: boolean - memoryVarSortFn?: (a: string, b: string) => number } // TODO: loop type? @@ -27,7 +26,6 @@ const useAvailableVarList = (nodeId: string, { hideChatVar, passedInAvailableNodes, conversationVariablesFirst, - memoryVarSortFn, }: Params = { onlyLeafNodeVar: false, filterVar: () => true, @@ -67,7 +65,7 @@ const useAvailableVarList = (nodeId: string, { }) } } - const availableVars = [...getNodeAvailableVars({ + const nodeAvailableVars = getNodeAvailableVars({ parentNode: iterationNode, beforeNodes: availableNodes, isChatMode, @@ -75,7 +73,22 @@ const useAvailableVarList = (nodeId: string, { hideEnv, hideChatVar, conversationVariablesFirst, - memoryVarSortFn, + }) + + const availableVars = [...nodeAvailableVars.map((availableVar) => { + if (availableVar.nodeId === 'conversation') { + return { + ...availableVar, + vars: availableVar.vars.filter((v) => { + if (!v.memoryVariableNodeId) + return true + + return v.memoryVariableNodeId === nodeId + }), + } + } + + return availableVar }), ...dataSourceRagVars] return { diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 93602f9751..7c7a3eea41 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -131,6 +131,7 @@ const useOneStepRun = ({ const { t } = useTranslation() const { getBeforeNodesInSameBranch, getBeforeNodesInSameBranchIncludeParent } = useWorkflow() as any const conversationVariables = useStore(s => s.conversationVariables) + const memoryVariables = useStore(s => s.memoryVariables) const isChatMode = useIsChatMode() const isIteration = data.type === BlockEnum.Iteration const isLoop = data.type === BlockEnum.Loop @@ -159,7 +160,7 @@ const useOneStepRun = ({ dataSourceList: dataSourceList || [], } - const allOutputVars = toNodeOutputVars(availableNodes, isChatMode, undefined, undefined, conversationVariables, [], allPluginInfoList, schemaTypeDefinitions) + const allOutputVars = toNodeOutputVars(availableNodes, isChatMode, undefined, undefined, conversationVariables, memoryVariables, [], allPluginInfoList, schemaTypeDefinitions) const targetVar = allOutputVars.find(item => isSystem ? !!item.isStartNode : item.nodeId === valueSelector[0]) if (!targetVar) return undefined diff --git a/web/app/components/workflow/nodes/iteration/use-config.ts b/web/app/components/workflow/nodes/iteration/use-config.ts index 2e47bb3740..bdd4020f09 100644 --- a/web/app/components/workflow/nodes/iteration/use-config.ts +++ b/web/app/components/workflow/nodes/iteration/use-config.ts @@ -58,7 +58,7 @@ const useConfig = (id: string, payload: IterationNodeType) => { mcpTools: mcpTools || [], dataSourceList: dataSourceList || [], } - const childrenNodeVars = toNodeOutputVars(iterationChildrenNodes, isChatMode, undefined, [], [], [], allPluginInfoList) + const childrenNodeVars = toNodeOutputVars(iterationChildrenNodes, isChatMode, undefined, [], [], [], [], allPluginInfoList) const handleOutputVarChange = useCallback((output: ValueSelector | string, _varKindType: VarKindType, varInfo?: Var) => { if (isEqual(inputs.output_selector, output as ValueSelector)) diff --git a/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx b/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx index e3c018a558..01157ce9ad 100644 --- a/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx +++ b/web/app/components/workflow/nodes/llm/components/config-prompt-item.tsx @@ -9,9 +9,6 @@ import Editor from '@/app/components/workflow/nodes/_base/components/prompt/edit import TypeSelector from '@/app/components/workflow/nodes/_base/components/selector' import Tooltip from '@/app/components/base/tooltip' import { PromptRole } from '@/models/debug' -import type { - MemoryVariable, -} from '@/app/components/workflow/types' const i18nPrefix = 'workflow.nodes.llm' @@ -42,8 +39,6 @@ type Props = { varList: Variable[] handleAddVariable: (payload: any) => void modelConfig?: ModelConfig - memoryVarInNode?: MemoryVariable[] - memoryVarInApp?: MemoryVariable[] } const roleOptions = [ @@ -86,8 +81,6 @@ const ConfigPromptItem: FC = ({ varList, handleAddVariable, modelConfig, - memoryVarInNode = [], - memoryVarInApp = [], }) => { const { t } = useTranslation() const workflowStore = useWorkflowStore() @@ -164,8 +157,6 @@ const ConfigPromptItem: FC = ({ } isMemorySupported - memoryVarInNode={memoryVarInNode} - memoryVarInApp={memoryVarInApp} /> ) } diff --git a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx index c789e626c1..21a3a81152 100644 --- a/web/app/components/workflow/nodes/llm/components/config-prompt.tsx +++ b/web/app/components/workflow/nodes/llm/components/config-prompt.tsx @@ -14,9 +14,6 @@ import cn from '@/utils/classnames' import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor' import AddButton from '@/app/components/workflow/nodes/_base/components/add-button' import { DragHandle } from '@/app/components/base/icons/src/vender/line/others' -import type { - MemoryVariable, -} from '@/app/components/workflow/types' const i18nPrefix = 'workflow.nodes.llm' @@ -37,9 +34,6 @@ type Props = { varList?: Variable[] handleAddVariable: (payload: any) => void modelConfig: ModelConfig - memoryVarSortFn?: (a: string, b: string) => number - memoryVarInNode?: MemoryVariable[] - memoryVarInApp?: MemoryVariable[] } const ConfigPrompt: FC = ({ @@ -55,9 +49,6 @@ const ConfigPrompt: FC = ({ varList = [], handleAddVariable, modelConfig, - memoryVarSortFn, - memoryVarInNode, - memoryVarInApp, }) => { const { t } = useTranslation() const workflowStore = useWorkflowStore() @@ -83,7 +74,6 @@ const ConfigPrompt: FC = ({ onlyLeafNodeVar: false, filterVar, conversationVariablesFirst: true, - memoryVarSortFn, }) const handleChatModePromptChange = useCallback((index: number) => { @@ -215,8 +205,6 @@ const ConfigPrompt: FC = ({ varList={varList} handleAddVariable={handleAddVariable} modelConfig={modelConfig} - memoryVarInNode={memoryVarInNode} - memoryVarInApp={memoryVarInApp} /> ) diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 647201346e..44648f12dc 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -64,9 +64,6 @@ const Panel: FC> = ({ handleStructureOutputChange, filterJinja2InputVar, handleReasoningFormatChange, - memoryVarSortFn, - memoryVarInNode, - memoryVarInApp, } = useConfig(id, data) const { memoryType } = useMemory(id, data) @@ -158,9 +155,6 @@ const Panel: FC> = ({ varList={inputs.prompt_config?.jinja2_variables || []} handleAddVariable={handleAddVariable} modelConfig={model} - memoryVarSortFn={memoryVarSortFn} - memoryVarInNode={memoryVarInNode} - memoryVarInApp={memoryVarInApp} /> )} diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index a7d3130a80..fd1a276c70 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import produce from 'immer' import { EditionType, VarType } from '../../types' import type { Memory, PromptItem, ValueSelector, Var, Variable } from '../../types' @@ -22,7 +22,6 @@ import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars const useConfig = (id: string, payload: LLMNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() const isChatMode = useIsChatMode() - const memoryVariables = useStore(s => s.memoryVariables) const defaultConfig = useStore(s => s.nodesDefaultConfigs)?.[payload.type] const [defaultRolePrefix, setDefaultRolePrefix] = useState<{ user: string; assistant: string }>({ user: '', assistant: '' }) @@ -308,11 +307,11 @@ const useConfig = (id: string, payload: LLMNodeType) => { }, [setInputs, deleteNodeInspectorVars, id]) const filterInputVar = useCallback((varPayload: Var) => { - return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile].includes(varPayload.type) + return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile, VarType.memory].includes(varPayload.type) }, []) const filterJinja2InputVar = useCallback((varPayload: Var) => { - return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.arrayBoolean, VarType.arrayObject, VarType.object, VarType.array, VarType.boolean].includes(varPayload.type) + return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.arrayBoolean, VarType.arrayObject, VarType.object, VarType.array, VarType.boolean, VarType.memory].includes(varPayload.type) }, []) const filterMemoryPromptVar = useCallback((varPayload: Var) => { @@ -335,29 +334,6 @@ const useConfig = (id: string, payload: LLMNodeType) => { filterVar: filterMemoryPromptVar, }) - const memoryVarSortFn = useCallback((a: string, b: string) => { - const idsInNode = inputs.memory?.block_id || [] - const aInNode = idsInNode.includes(a) - const bInNode = idsInNode.includes(b) - - if (aInNode && !bInNode) return -1 - if (!aInNode && bInNode) return 1 - - return a.localeCompare(b) - }, [inputs.memory?.block_id]) - - const memoryVarInNode = useMemo(() => { - const idsInNode = inputs.memory?.block_id || [] - return memoryVariables - .filter(varItem => idsInNode.includes(varItem.id)) - }, [inputs.memory?.block_id, memoryVariables]) - - const memoryVarInApp = useMemo(() => { - const idsInApp = inputs.memory?.block_id || [] - return memoryVariables - .filter(varItem => !idsInApp.includes(varItem.id)) - }, [inputs.memory?.block_id, memoryVariables]) - return { readOnly, isChatMode, @@ -391,9 +367,6 @@ const useConfig = (id: string, payload: LLMNodeType) => { handleStructureOutputEnableChange, filterJinja2InputVar, handleReasoningFormatChange, - memoryVarSortFn, - memoryVarInNode, - memoryVarInApp, } } diff --git a/web/app/components/workflow/nodes/loop/use-config.ts b/web/app/components/workflow/nodes/loop/use-config.ts index e8504fb5e9..b5c133ead6 100644 --- a/web/app/components/workflow/nodes/loop/use-config.ts +++ b/web/app/components/workflow/nodes/loop/use-config.ts @@ -38,7 +38,7 @@ const useConfig = (id: string, payload: LoopNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() const isChatMode = useIsChatMode() const conversationVariables = useStore(s => s.conversationVariables) - + const memoryVariables = useStore(s => s.memoryVariables) const { inputs, setInputs } = useNodeCrud(id, payload) const inputsRef = useRef(inputs) const handleInputsChange = useCallback((newInputs: LoopNodeType) => { @@ -65,7 +65,7 @@ const useConfig = (id: string, payload: LoopNodeType) => { mcpTools: mcpTools || [], dataSourceList: dataSourceList || [], } - const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode, undefined, [], conversationVariables, [], allPluginInfoList) + const childrenNodeVars = toNodeOutputVars(loopChildrenNodes, isChatMode, undefined, [], conversationVariables, memoryVariables, [], allPluginInfoList) const { getIsVarFileAttribute, diff --git a/web/app/components/workflow/panel/chat-variable-panel/components/variable-modal.tsx b/web/app/components/workflow/panel/chat-variable-panel/components/variable-modal.tsx index 2135b25e0a..17b8faed91 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/components/variable-modal.tsx +++ b/web/app/components/workflow/panel/chat-variable-panel/components/variable-modal.tsx @@ -1,7 +1,6 @@ import React, { useCallback, useRef } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' -import { v4 as uuid4 } from 'uuid' import { useForm as useTanstackForm, useStore as useTanstackStore, @@ -84,7 +83,7 @@ const ChatVariableModal = ({ return notify({ type: 'error', message: 'object key can not be empty' }) onSave({ - id: chatVar ? chatVar.id : uuid4(), + id: chatVar ? chatVar.id : `${Date.now()}`, name, value_type, value: editInJSON ? JSON.parse(value) : value, diff --git a/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-type-schema.ts b/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-type-schema.ts index 9469703b59..2370601ea9 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-type-schema.ts +++ b/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-type-schema.ts @@ -44,7 +44,7 @@ export const useTypeSchema = () => { label: t('workflow.chatVariable.modal.type'), type: 'select', options: typeList.map(type => ({ - label: type, + label: type === ChatVarType.Memory ? 'memory' : type, value: type, })), onChange: handleTypeChange, diff --git a/web/app/components/workflow/panel/chat-variable-panel/type.ts b/web/app/components/workflow/panel/chat-variable-panel/type.ts index d63f4f369d..0c278b2a62 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/type.ts +++ b/web/app/components/workflow/panel/chat-variable-panel/type.ts @@ -7,7 +7,7 @@ export enum ChatVarType { ArrayNumber = 'array[number]', ArrayBoolean = 'array[boolean]', ArrayObject = 'array[object]', - Memory = 'memory', + Memory = 'memory_block', } export type ObjectValueItem = { diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index e517a8edaf..950ab89eac 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -312,7 +312,7 @@ export enum VarType { arrayFile = 'array[file]', any = 'any', arrayAny = 'array[any]', - memory = 'memory', + memory = 'memory_block', } export enum ValueType { @@ -334,6 +334,8 @@ export type Var = { nodeId?: string isRagVariable?: boolean schemaType?: string + memoryVariableName?: string + memoryVariableNodeId?: string } export type NodeOutPutVar = {