From e7553a1c4e78380202195ae62227b16062b2ae14 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Thu, 26 Jun 2025 14:55:26 +0100 Subject: [PATCH] Bugfix/Allow OverrideConfig For Multiple Nodes In AgentflowV2 (#4734) Bugfix/Enhance input configuration merging logic in replaceInputsWithConfig Improve the handling of input configurations by merging existing values with overrides instead of complete replacement. This includes support for merging objects and parsing JSON strings when necessary. --- packages/server/src/utils/index.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 67d2ee37..89aa4e3b 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -1149,7 +1149,33 @@ export const replaceInputsWithConfig = ( if (nodeIds.includes(flowNodeData.id)) { // Check if this parameter is enabled if (isParameterEnabled(flowNodeData.label, config)) { - inputsObj[config] = overrideConfig[config][flowNodeData.id] + const existingValue = inputsObj[config] + const overrideValue = overrideConfig[config][flowNodeData.id] + + // Merge objects instead of completely overriding + if ( + typeof existingValue === 'object' && + typeof overrideValue === 'object' && + !Array.isArray(existingValue) && + !Array.isArray(overrideValue) && + existingValue !== null && + overrideValue !== null + ) { + inputsObj[config] = Object.assign({}, existingValue, overrideValue) + } else if (typeof existingValue === 'string' && existingValue.startsWith('{') && existingValue.endsWith('}')) { + try { + const parsedExisting = JSON.parse(existingValue) + if (typeof overrideValue === 'object' && !Array.isArray(overrideValue)) { + inputsObj[config] = Object.assign({}, parsedExisting, overrideValue) + } else { + inputsObj[config] = overrideValue + } + } catch (e) { + inputsObj[config] = overrideValue + } + } else { + inputsObj[config] = overrideValue + } } continue } else if (nodeIds.some((nodeId) => nodeId.includes(flowNodeData.name))) {