Skip to content

Commit e7553a1

Browse files
authored
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.
1 parent 9efb70e commit e7553a1

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/server/src/utils/index.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,33 @@ export const replaceInputsWithConfig = (
11491149
if (nodeIds.includes(flowNodeData.id)) {
11501150
// Check if this parameter is enabled
11511151
if (isParameterEnabled(flowNodeData.label, config)) {
1152-
inputsObj[config] = overrideConfig[config][flowNodeData.id]
1152+
const existingValue = inputsObj[config]
1153+
const overrideValue = overrideConfig[config][flowNodeData.id]
1154+
1155+
// Merge objects instead of completely overriding
1156+
if (
1157+
typeof existingValue === 'object' &&
1158+
typeof overrideValue === 'object' &&
1159+
!Array.isArray(existingValue) &&
1160+
!Array.isArray(overrideValue) &&
1161+
existingValue !== null &&
1162+
overrideValue !== null
1163+
) {
1164+
inputsObj[config] = Object.assign({}, existingValue, overrideValue)
1165+
} else if (typeof existingValue === 'string' && existingValue.startsWith('{') && existingValue.endsWith('}')) {
1166+
try {
1167+
const parsedExisting = JSON.parse(existingValue)
1168+
if (typeof overrideValue === 'object' && !Array.isArray(overrideValue)) {
1169+
inputsObj[config] = Object.assign({}, parsedExisting, overrideValue)
1170+
} else {
1171+
inputsObj[config] = overrideValue
1172+
}
1173+
} catch (e) {
1174+
inputsObj[config] = overrideValue
1175+
}
1176+
} else {
1177+
inputsObj[config] = overrideValue
1178+
}
11531179
}
11541180
continue
11551181
} else if (nodeIds.some((nodeId) => nodeId.includes(flowNodeData.name))) {

0 commit comments

Comments
 (0)