(
reactFlowNodes: IReactFlowNode[],
componentNodes: IComponentNodes,
chatId: string,
appDataSource: DataSource,
orgId?: string,
sessionId?: string,
memoryType?: string,
isClearFromViewMessageDialog?: string
)
| 766 | * @param {string} isClearFromViewMessageDialog |
| 767 | */ |
| 768 | export 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 | |
| 810 | export const getGlobalVariable = async ( |
| 811 | overrideConfig?: ICommonObject, |
no test coverage detected