From 1c3ff179f875a985dde731177883e1cad2d187ce Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 15 Oct 2025 16:44:15 +0800 Subject: [PATCH] use setMemoryVariables --- .../memory-system/memory-create-button.tsx | 16 ++++++++-------- .../workflow/panel/chat-variable-panel/index.tsx | 4 +++- .../workflow/panel/debug-and-preview/hooks.ts | 10 +++++----- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/web/app/components/workflow/nodes/llm/components/memory-system/memory-create-button.tsx b/web/app/components/workflow/nodes/llm/components/memory-system/memory-create-button.tsx index 1a6125f7cc..ce5ee64c6e 100644 --- a/web/app/components/workflow/nodes/llm/components/memory-system/memory-create-button.tsx +++ b/web/app/components/workflow/nodes/llm/components/memory-system/memory-create-button.tsx @@ -8,7 +8,7 @@ import { PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import ActionButton from '@/app/components/base/action-button' -import type { ConversationVariable } from '@/app/components/workflow/types' +import type { MemoryVariable } from '@/app/components/workflow/types' import { useStore } from '@/app/components/workflow/store' import { useNodesSyncDraft } from '@/app/components/workflow/hooks/use-nodes-sync-draft' import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars-crud' @@ -30,8 +30,8 @@ const MemoryCreateButton = ({ }: Props) => { const { eventEmitter } = useEventEmitterContextContext() const [open, setOpen] = useState(false) - const varList = useStore(s => s.conversationVariables) as ConversationVariable[] - const updateChatVarList = useStore(s => s.setConversationVariables) + const varList = useStore(s => s.memoryVariables) as MemoryVariable[] + const updateMemoryVarList = useStore(s => s.setMemoryVariables) const { doSyncWorkflowDraft } = useNodesSyncDraft() const { invalidateConversationVarValues, @@ -45,14 +45,14 @@ const MemoryCreateButton = ({ }) }, [doSyncWorkflowDraft, invalidateConversationVarValues]) - const handleSave = useCallback(async (newChatVar: ConversationVariable) => { - const newList = [newChatVar, ...varList] - updateChatVarList(newList) + const handleSave = useCallback((newMemoryVar: MemoryVariable) => { + const newList = [newMemoryVar, ...varList] + updateMemoryVarList(newList) handleVarChanged() setOpen(false) if (instanceId) - eventEmitter?.emit({ type: MEMORY_VAR_CREATED_BY_MODAL_BY_EVENT_EMITTER, instanceId, variable: ['conversation', newChatVar.name] } as any) - }, [varList, updateChatVarList, handleVarChanged, setOpen, eventEmitter, instanceId]) + eventEmitter?.emit({ type: MEMORY_VAR_CREATED_BY_MODAL_BY_EVENT_EMITTER, instanceId, variable: ['memory', newMemoryVar.name] } as any) + }, [varList, updateMemoryVarList, handleVarChanged, setOpen, eventEmitter, instanceId]) eventEmitter?.useSubscription((v: any) => { if (v.type === MEMORY_VAR_MODAL_SHOW_BY_EVENT_EMITTER && v.instanceId === instanceId) diff --git a/web/app/components/workflow/panel/chat-variable-panel/index.tsx b/web/app/components/workflow/panel/chat-variable-panel/index.tsx index 093a799d8c..eb593a488d 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/index.tsx +++ b/web/app/components/workflow/panel/chat-variable-panel/index.tsx @@ -90,10 +90,12 @@ const ChatVariablePanel = () => { removeUsedVarInNodes(chatVar) const varList = workflowStore.getState().conversationVariables updateChatVarList(varList.filter(v => v.id !== chatVar.id)) + const memoryList = workflowStore.getState().memoryVariables + setMemoryVariables(memoryList.filter(v => v.id !== chatVar.id)) setCacheForDelete(undefined) setShowRemoveConfirm(false) handleVarChanged(chatVar.value_type === ChatVarType.Memory) - }, [handleVarChanged, removeUsedVarInNodes, updateChatVarList]) + }, [handleVarChanged, removeUsedVarInNodes, updateChatVarList, setMemoryVariables]) const deleteCheck = useCallback((chatVar: ConversationVariable | MemoryVariable) => { const effectedNodes = getEffectedNodes(chatVar) diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks.ts b/web/app/components/workflow/panel/debug-and-preview/hooks.ts index be34570153..75e6dbbe7b 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts @@ -63,8 +63,8 @@ export const useChat = ( const { fetchInspectVars } = useSetWorkflowVarsWithValue() const [suggestedQuestions, setSuggestQuestions] = useState([]) const suggestedQuestionsAbortControllerRef = useRef(null) - const conversationVariables = useStore(s => s.conversationVariables) - const setConversationVariables = useStore(s => s.setConversationVariables) + const memoryVariables = useStore(s => s.memoryVariables) + const setMemoryVariables = useStore(s => s.setMemoryVariables) const { setIterTimes, setLoopTimes, @@ -502,8 +502,8 @@ export const useChat = ( } }, onMemoryUpdate: ({ data }) => { - const currentMemoryIndex = conversationVariables.findIndex(item => item.id === data.memory_id) - const newList = produce(conversationVariables, (draft) => { + const currentMemoryIndex = memoryVariables.findIndex(item => item.id === data.memory_id) + const newList = produce(memoryVariables, (draft) => { if (currentMemoryIndex > -1) { draft[currentMemoryIndex] = { ...draft[currentMemoryIndex], @@ -511,7 +511,7 @@ export const useChat = ( } } }) - setConversationVariables(newList) + setMemoryVariables(newList) }, }, )