From 612112c9192548c5b08b80561466ff1384149fe6 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 12 Sep 2025 16:27:20 +0800 Subject: [PATCH] add memory variable in llm node --- .../llm/components/memory-system/index.tsx | 6 ++ .../memory-system/memory-create-button.tsx | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 web/app/components/workflow/nodes/llm/components/memory-system/memory-create-button.tsx diff --git a/web/app/components/workflow/nodes/llm/components/memory-system/index.tsx b/web/app/components/workflow/nodes/llm/components/memory-system/index.tsx index e7bead9ff8..3ab14758a5 100644 --- a/web/app/components/workflow/nodes/llm/components/memory-system/index.tsx +++ b/web/app/components/workflow/nodes/llm/components/memory-system/index.tsx @@ -6,7 +6,9 @@ import Collapse from '@/app/components/workflow/nodes/_base/components/collapse' import type { Node, } from '@/app/components/workflow/types' +import Divider from '@/app/components/base/divider' import Tooltip from '@/app/components/base/tooltip' +import MemoryCreateButton from './memory-create-button' import MemorySelector from './memory-selector' import LinearMemory from './linear-memory' import type { Memory } from '@/app/components/workflow/types' @@ -54,6 +56,10 @@ const MemorySystem = ({ triggerClassName='w-4 h-4' /> {collapseIcon} + +
e.stopPropagation()}> + +
{ + const [open, setOpen] = useState(false) + const varList = useStore(s => s.conversationVariables) as ConversationVariable[] + const updateChatVarList = useStore(s => s.setConversationVariables) + const { doSyncWorkflowDraft } = useNodesSyncDraft() + const { + invalidateConversationVarValues, + } = useInspectVarsCrud() + + const handleVarChanged = useCallback(() => { + doSyncWorkflowDraft(false, { + onSuccess() { + invalidateConversationVarValues() + }, + }) + }, [doSyncWorkflowDraft, invalidateConversationVarValues]) + + const handleSave = useCallback(async (newChatVar: ConversationVariable) => { + const newList = [newChatVar, ...varList] + updateChatVarList(newList) + handleVarChanged() + setOpen(false) + }, [varList, updateChatVarList, handleVarChanged, setOpen]) + + return ( + <> + + setOpen(v => !v)}> + + + + + + { + setOpen(false) + }} + /> + + + + ) +} + +export default MemoryCreateButton