mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 08:58:09 +08:00
add memory variable
This commit is contained in:
@ -5,8 +5,9 @@ import {
|
||||
RiArrowDownSLine,
|
||||
RiCheckLine,
|
||||
} from '@remixicon/react'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import {
|
||||
useNodes,
|
||||
useStore,
|
||||
} from 'reactflow'
|
||||
import {
|
||||
PortalToFollowElem,
|
||||
@ -14,9 +15,6 @@ import {
|
||||
PortalToFollowElemTrigger,
|
||||
} from '@/app/components/base/portal-to-follow-elem'
|
||||
import BlockIcon from '@/app/components/workflow/block-icon'
|
||||
import type {
|
||||
CommonNodeType,
|
||||
} from '@/app/components/workflow/types'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import cn from '@/utils/classnames'
|
||||
|
||||
@ -32,12 +30,13 @@ const NodeSelector: FC<Props> = ({
|
||||
nodeType = BlockEnum.LLM,
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
const nodes = useNodes<CommonNodeType>()
|
||||
|
||||
const filteredNodes = nodeType ? nodes.filter(node => node.data?.type === nodeType) : nodes
|
||||
const filteredNodes = useStore(useShallow((s) => {
|
||||
const nodes = [...s.nodeInternals.values()]
|
||||
return nodes.filter(node => node.data?.type === nodeType)
|
||||
}))
|
||||
|
||||
const currentNode = useMemo(() => filteredNodes.find(node => node.id === value), [filteredNodes, value])
|
||||
|
||||
return (
|
||||
<PortalToFollowElem
|
||||
open={open}
|
||||
|
||||
@ -29,12 +29,14 @@ import { useDocLink } from '@/context/i18n'
|
||||
import cn from '@/utils/classnames'
|
||||
import useInspectVarsCrud from '../../hooks/use-inspect-vars-crud'
|
||||
import { ChatVarType } from './type'
|
||||
import { useMemoryVariable } from '@/app/components/workflow/hooks'
|
||||
|
||||
const ChatVariablePanel = () => {
|
||||
const { t } = useTranslation()
|
||||
const docLink = useDocLink()
|
||||
const store = useStoreApi()
|
||||
const workflowStore = useWorkflowStore()
|
||||
const { handleAddMemoryVariable, handleUpdateMemoryVariable, handleDeleteMemoryVariable } = useMemoryVariable()
|
||||
const setShowChatVariablePanel = useStore(s => s.setShowChatVariablePanel)
|
||||
const varList = useStore(s => s.conversationVariables) as ConversationVariable[]
|
||||
const memoryVariables = useStore(s => s.memoryVariables) as MemoryVariable[]
|
||||
@ -90,8 +92,8 @@ 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))
|
||||
if (chatVar.value_type === ChatVarType.Memory)
|
||||
handleDeleteMemoryVariable(chatVar as MemoryVariable)
|
||||
setCacheForDelete(undefined)
|
||||
setShowRemoveConfirm(false)
|
||||
handleVarChanged(chatVar.value_type === ChatVarType.Memory)
|
||||
@ -110,8 +112,10 @@ const ChatVariablePanel = () => {
|
||||
|
||||
const handleSave = useCallback(async (chatVar: ConversationVariable | MemoryVariable) => {
|
||||
if (chatVar.value_type === ChatVarType.Memory) {
|
||||
const memoryVarList = workflowStore.getState().memoryVariables
|
||||
setMemoryVariables([chatVar, ...memoryVarList])
|
||||
if (!currentVar)
|
||||
handleAddMemoryVariable(chatVar as MemoryVariable)
|
||||
else
|
||||
handleUpdateMemoryVariable(chatVar as MemoryVariable)
|
||||
handleVarChanged(true)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user