MCPcopy
hub / github.com/FlowiseAI/Flowise / clearSessionMemory

Function clearSessionMemory

packages/server/src/utils/index.ts:768–808  ·  view source on GitHub ↗
(
    reactFlowNodes: IReactFlowNode[],
    componentNodes: IComponentNodes,
    chatId: string,
    appDataSource: DataSource,
    orgId?: string,
    sessionId?: string,
    memoryType?: string,
    isClearFromViewMessageDialog?: string
)

Source from the content-addressed store, hash-verified

766 * @param {string} isClearFromViewMessageDialog
767 */
768export const clearSessionMemory = async (
769 reactFlowNodes: IReactFlowNode[],
770 componentNodes: IComponentNodes,
771 chatId: string,
772 appDataSource: DataSource,
773 orgId?: string,
774 sessionId?: string,
775 memoryType?: string,
776 isClearFromViewMessageDialog?: string
777) => {
778 for (const node of reactFlowNodes) {
779 if (node.data.category !== 'Memory' && node.data.type !== 'OpenAIAssistant') continue
780
781 // Only clear specific session memory from View Message Dialog UI
782 if (isClearFromViewMessageDialog && memoryType && node.data.label !== memoryType) continue
783
784 const nodeInstanceFilePath = componentNodes[node.data.name].filePath as string
785 const nodeModule = await import(nodeInstanceFilePath)
786 const newNodeInstance = new nodeModule.nodeClass()
787 const options: ICommonObject = { orgId, chatId, appDataSource, databaseEntities, logger }
788
789 // SessionId always take priority first because it is the sessionId used for 3rd party memory node
790 if (sessionId && node.data.inputs) {
791 if (node.data.type === 'OpenAIAssistant') {
792 await newNodeInstance.clearChatMessages(node.data, options, { type: 'threadId', id: sessionId })
793 } else {
794 node.data.inputs.sessionId = sessionId
795 const initializedInstance: FlowiseMemory = await newNodeInstance.init(node.data, '', options)
796 await initializedInstance.clearChatMessages(sessionId)
797 }
798 } else if (chatId && node.data.inputs) {
799 if (node.data.type === 'OpenAIAssistant') {
800 await newNodeInstance.clearChatMessages(node.data, options, { type: 'chatId', id: chatId })
801 } else {
802 node.data.inputs.sessionId = chatId
803 const initializedInstance: FlowiseMemory = await newNodeInstance.init(node.data, '', options)
804 await initializedInstance.clearChatMessages(chatId)
805 }
806 }
807 }
808}
809
810export const getGlobalVariable = async (
811 overrideConfig?: ICommonObject,

Callers 2

removeAllChatMessagesFunction · 0.90
buildAgentGraphFunction · 0.90

Calls 2

clearChatMessagesMethod · 0.65
initMethod · 0.65

Tested by

no test coverage detected