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

Function combineNodeInputs

packages/server/src/utils/buildAgentflow.ts:971–1044  ·  view source on GitHub ↗

* Combines inputs from multiple source nodes into a single input object * @param {Map } receivedInputs - Map of inputs received from different nodes * @returns {any} Combined input data * * @example * const inputs = new Map(); * inputs.set('node1', { json: { value: 1 }, text: 'Hell

(receivedInputs: Map<string, any>)

Source from the content-addressed store, hash-verified

969 * }
970 */
971function combineNodeInputs(receivedInputs: Map<string, any>): any {
972 // Filter out null/undefined inputs
973 const validInputs = new Map(Array.from(receivedInputs.entries()).filter(([_, value]) => value !== null && value !== undefined))
974
975 if (validInputs.size === 0) {
976 return null
977 }
978
979 if (validInputs.size === 1) {
980 return Array.from(validInputs.values())[0]
981 }
982
983 // Initialize result object to store combined data
984 const result: {
985 json: any
986 text?: string
987 binary?: any
988 error?: Error
989 } = {
990 json: {}
991 }
992
993 // Sort inputs by source node ID to ensure consistent ordering
994 const sortedInputs = Array.from(validInputs.entries()).sort((a, b) => a[0].localeCompare(b[0]))
995
996 for (const [sourceNodeId, inputData] of sortedInputs) {
997 if (!inputData) continue
998
999 try {
1000 // Handle different types of input data
1001 if (typeof inputData === 'object') {
1002 // Merge JSON data
1003 if (inputData.json) {
1004 result.json = {
1005 ...result.json,
1006 [sourceNodeId]: inputData.json
1007 }
1008 }
1009
1010 // Combine text data if present
1011 if (inputData.text) {
1012 result.text = result.text ? `${result.text}\n${inputData.text}` : inputData.text
1013 }
1014
1015 // Merge binary data if present
1016 if (inputData.binary) {
1017 result.binary = {
1018 ...result.binary,
1019 [sourceNodeId]: inputData.binary
1020 }
1021 }
1022
1023 // Handle error data
1024 if (inputData.error) {
1025 result.error = inputData.error
1026 }
1027 } else {
1028 // Handle primitive data types

Callers 1

processNodeOutputsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected