mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 13:01:11 +03:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { IActiveChatflows, INodeData, IReactFlowNode } from './Interface'
|
|
|
|
/**
|
|
* This pool is to keep track of active chatflow pools
|
|
* so we can prevent building langchain flow all over again
|
|
*/
|
|
export class ChatflowPool {
|
|
activeChatflows: IActiveChatflows = {}
|
|
|
|
/**
|
|
* Add to the pool
|
|
* @param {string} chatflowid
|
|
* @param {INodeData} endingNodeData
|
|
* @param {IReactFlowNode[]} startingNodes
|
|
*/
|
|
add(chatflowid: string, endingNodeData: INodeData, startingNodes: IReactFlowNode[]) {
|
|
this.activeChatflows[chatflowid] = {
|
|
startingNodes,
|
|
endingNodeData,
|
|
inSync: true
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update to the pool
|
|
* @param {string} chatflowid
|
|
* @param {boolean} inSync
|
|
*/
|
|
updateInSync(chatflowid: string, inSync: boolean) {
|
|
if (Object.prototype.hasOwnProperty.call(this.activeChatflows, chatflowid)) {
|
|
this.activeChatflows[chatflowid].inSync = inSync
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove from the pool
|
|
* @param {string} chatflowid
|
|
*/
|
|
async remove(chatflowid: string) {
|
|
if (Object.prototype.hasOwnProperty.call(this.activeChatflows, chatflowid)) {
|
|
delete this.activeChatflows[chatflowid]
|
|
}
|
|
}
|
|
}
|