mirror of https://github.com/langgenius/dify.git
use setMemoryVariables
This commit is contained in:
parent
8a348615bf
commit
1c3ff179f8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ export const useChat = (
|
|||
const { fetchInspectVars } = useSetWorkflowVarsWithValue()
|
||||
const [suggestedQuestions, setSuggestQuestions] = useState<string[]>([])
|
||||
const suggestedQuestionsAbortControllerRef = useRef<AbortController | null>(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)
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue