Repository: FlowiseAI/Flowise
File: packages/server/src/ChildProcess.ts (TypeScript)

Code before:

            const endingNodeData = nodes.find((nd) => nd.id === endingNodeId)?.data
            if (!endingNodeData) {
                await sendToParentProcess('error', `Ending node must be either a Chain or Agent`)
                return
            }

            if (
                endingNodeData.outputs &&
                Object.keys(endingNodeData.outputs).length &&
                !Object.values(endingNodeData.outputs).includes(endingNodeData.name)
            ) {
                await sendToParentProcess(
                    'error',
                    `Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
                )
                return
            }

            /*** Get Starting Nodes with Non-Directed Graph ***/
            const constructedObj = constructGraphs(nodes, edges, true)
            const nonDirectedGraph = constructedObj.graph
            const { startingNodeIds, depthQueue } = getStartingNodes(nonDirectedGraph, endingNodeId)

            /*** BFS to traverse from Starting Nodes to Ending Node ***/
            const chatId = await getChatId(chatflow.id)
            const reactFlowNodes = await buildLangchain(
                startingNodeIds,
                nodes,
                graph,
                depthQueue,
                componentNodes,
                incomingInput.question,
                chatId,
                incomingInput?.overrideConfig
            )

            const nodeToExecute = reactFlowNodes.find((node: IReactFlowNode) => node.id === endingNodeId)
            if (!nodeToExecute) {
                await sendToParentProcess('error', `Node ${endingNodeId} not found`)
                return
            }

            const reactFlowNodeData: INodeData = resolveVariables(nodeToExecute.data, reactFlowNodes, incomingInput.question)
            nodeToExecuteData = reactFlowNodeData

            const startingNodes = nodes.filter((nd) => startingNodeIds.includes(nd.id))
            addToChatFlowPool = {
                chatflowid: chatflow.id,
                nodeToExecuteData,
                startingNodes,

Review comment (suggestion):
this will not work because child processes dont have access to `DataSource`. You'll have to get the chatid in `startChildProcess()` and pass it in the `IRunChatflowMessageValue` - https://github.com/FlowiseAI/Flowise/blob/main/packages/server/src/index.ts#L449. Then retrieve it here - https://github.com/FlowiseAI/Flowise/blob/main/packages/server/src/ChildProcess.ts#L26

Code after:
            const endingNodeData = nodes.find((nd) => nd.id === endingNodeId)?.data
            if (!endingNodeData) {
                await sendToParentProcess('error', `Ending node must be either a Chain or Agent`)
                return
            }

            if (
                endingNodeData.outputs &&
                Object.keys(endingNodeData.outputs).length &&
                !Object.values(endingNodeData.outputs).includes(endingNodeData.name)
            ) {
                await sendToParentProcess(
                    'error',
                    `Output of ${endingNodeData.label} (${endingNodeData.id}) must be ${endingNodeData.label}, can't be an Output Prediction`
                )
                return
            }

            /*** Get Starting Nodes with Non-Directed Graph ***/
            const constructedObj = constructGraphs(nodes, edges, true)
            const nonDirectedGraph = constructedObj.graph
            const { startingNodeIds, depthQueue } = getStartingNodes(nonDirectedGraph, endingNodeId)

            /*** BFS to traverse from Starting Nodes to Ending Node ***/
            const reactFlowNodes = await buildLangchain(
                startingNodeIds,
                nodes,
                graph,
                depthQueue,
                componentNodes,
                incomingInput.question,
                chatId,
                incomingInput?.overrideConfig
            )

            const nodeToExecute = reactFlowNodes.find((node: IReactFlowNode) => node.id === endingNodeId)
            if (!nodeToExecute) {
                await sendToParentProcess('error', `Node ${endingNodeId} not found`)
                return
            }

            const reactFlowNodeData: INodeData = resolveVariables(nodeToExecute.data, reactFlowNodes, incomingInput.question)
            nodeToExecuteData = reactFlowNodeData

            const startingNodes = nodes.filter((nd) => startingNodeIds.includes(nd.id))
            addToChatFlowPool = {
                chatflowid: chatflow.id,
                nodeToExecuteData,
                startingNodes,
                overrideConfig: incomingInput?.overrideConfig
            }