({
startingNodeIds,
reactFlowNodes,
reactFlowEdges,
graph,
depthQueue,
componentNodes,
question,
uploadedFilesContent,
chatHistory,
apiMessageId,
chatId,
sessionId,
chatflowid,
appDataSource,
overrideConfig,
apiOverrideStatus = false,
nodeOverrides = {},
availableVariables = [],
variableOverrides = [],
cachePool,
isUpsert,
stopNodeId,
uploads,
baseURL,
orgId,
workspaceId,
subscriptionId,
usageCacheManager,
updateStorageUsage,
checkStorage
}: BuildFlowParams)
| 514 | * @param {BuildFlowParams} params |
| 515 | */ |
| 516 | export const buildFlow = async ({ |
| 517 | startingNodeIds, |
| 518 | reactFlowNodes, |
| 519 | reactFlowEdges, |
| 520 | graph, |
| 521 | depthQueue, |
| 522 | componentNodes, |
| 523 | question, |
| 524 | uploadedFilesContent, |
| 525 | chatHistory, |
| 526 | apiMessageId, |
| 527 | chatId, |
| 528 | sessionId, |
| 529 | chatflowid, |
| 530 | appDataSource, |
| 531 | overrideConfig, |
| 532 | apiOverrideStatus = false, |
| 533 | nodeOverrides = {}, |
| 534 | availableVariables = [], |
| 535 | variableOverrides = [], |
| 536 | cachePool, |
| 537 | isUpsert, |
| 538 | stopNodeId, |
| 539 | uploads, |
| 540 | baseURL, |
| 541 | orgId, |
| 542 | workspaceId, |
| 543 | subscriptionId, |
| 544 | usageCacheManager, |
| 545 | updateStorageUsage, |
| 546 | checkStorage |
| 547 | }: BuildFlowParams) => { |
| 548 | const flowNodes = cloneDeep(reactFlowNodes) |
| 549 | |
| 550 | let upsertHistory: Record<string, any> = {} |
| 551 | |
| 552 | // Create a Queue and add our initial node in it |
| 553 | const nodeQueue = [] as INodeQueue[] |
| 554 | const exploredNode = {} as IExploredNode |
| 555 | const dynamicVariables = {} as Record<string, unknown> |
| 556 | let ignoreNodeIds: string[] = [] |
| 557 | |
| 558 | // In the case of infinite loop, only max 3 loops will be executed |
| 559 | const maxLoop = 3 |
| 560 | |
| 561 | for (let i = 0; i < startingNodeIds.length; i += 1) { |
| 562 | nodeQueue.push({ nodeId: startingNodeIds[i], depth: 0 }) |
| 563 | exploredNode[startingNodeIds[i]] = { remainingLoop: maxLoop, lastSeenDepth: 0 } |
| 564 | } |
| 565 | |
| 566 | const initializedNodes: Set<string> = new Set() |
| 567 | const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph |
| 568 | |
| 569 | const flowData: ICommonObject = { |
| 570 | chatflowid, |
| 571 | chatflowId: chatflowid, |
| 572 | chatId, |
| 573 | sessionId, |
no test coverage detected