update memory by SSE in preview

This commit is contained in:
JzoNg
2025-09-12 14:35:07 +08:00
parent 27d6fee1ed
commit df502e0d79
3 changed files with 33 additions and 1 deletions

View File

@ -13,7 +13,7 @@ import {
useWorkflowRun,
} from '../../hooks'
import { NodeRunningStatus, WorkflowRunningStatus } from '../../types'
import { useWorkflowStore } from '../../store'
import { useStore, useWorkflowStore } from '../../store'
import { DEFAULT_ITER_TIMES, DEFAULT_LOOP_TIMES } from '../../constants'
import type {
ChatItem,
@ -63,6 +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 {
setIterTimes,
setLoopTimes,
@ -499,6 +501,18 @@ export const useChat = (
})
}
},
onMemoryUpdate: ({ data }) => {
const currentMemoryIndex = conversationVariables.findIndex(item => item.id === data.memory_id)
const newList = produce(conversationVariables, (draft) => {
if (currentMemoryIndex > -1) {
draft[currentMemoryIndex] = {
...draft[currentMemoryIndex],
...data,
}
}
})
setConversationVariables(newList)
},
},
)
}, [threadMessages, chatTree.length, updateCurrentQAOnTree, handleResponding, formSettings?.inputsForm, handleRun, notify, t, config?.suggested_questions_after_answer?.enabled, fetchInspectVars, invalidAllLastRun])