(
flowNodeData: INodeData,
overrideConfig: ICommonObject,
nodeOverrides: INodeOverrides,
variableOverrides: IVariableOverride[]
)
| 1089 | * @returns {INodeData} |
| 1090 | */ |
| 1091 | export const replaceInputsWithConfig = ( |
| 1092 | flowNodeData: INodeData, |
| 1093 | overrideConfig: ICommonObject, |
| 1094 | nodeOverrides: INodeOverrides, |
| 1095 | variableOverrides: IVariableOverride[] |
| 1096 | ) => { |
| 1097 | const types = 'inputs' |
| 1098 | |
| 1099 | const isParameterEnabled = (nodeType: string, paramName: string): boolean => { |
| 1100 | if (!nodeOverrides[nodeType]) return false |
| 1101 | const parameter = nodeOverrides[nodeType].find((param: any) => param.name === paramName) |
| 1102 | return parameter?.enabled ?? false |
| 1103 | } |
| 1104 | |
| 1105 | const getParamValues = (inputsObj: ICommonObject) => { |
| 1106 | for (const config in overrideConfig) { |
| 1107 | /** |
| 1108 | * Several conditions: |
| 1109 | * 1. If config is 'analytics', always allow it |
| 1110 | * 2. If config is 'vars', check its object and filter out the variables that are not enabled for override |
| 1111 | * 3. If typeof config's value is an array, check if the parameter is enabled and apply directly |
| 1112 | * 4. If typeof config's value is an object, check if the node id is in the overrideConfig object and if the parameter (systemMessagePrompt) is enabled |
| 1113 | * Example: |
| 1114 | * "systemMessagePrompt": { |
| 1115 | * "chatPromptTemplate_0": "You are an assistant" |
| 1116 | * } |
| 1117 | * 5. If typeof config's value is a string, check if the parameter is enabled |
| 1118 | * Example: |
| 1119 | * "systemMessagePrompt": "You are an assistant" |
| 1120 | */ |
| 1121 | |
| 1122 | if (config === 'analytics') { |
| 1123 | // pass |
| 1124 | } else if (config === 'vars') { |
| 1125 | if (typeof overrideConfig[config] === 'object') { |
| 1126 | const filteredVars: ICommonObject = {} |
| 1127 | |
| 1128 | const vars = overrideConfig[config] |
| 1129 | for (const variable in vars) { |
| 1130 | const override = variableOverrides.find((v) => v.name === variable) |
| 1131 | if (!override?.enabled) { |
| 1132 | continue // Skip this variable if it's not enabled for override |
| 1133 | } |
| 1134 | filteredVars[variable] = vars[variable] |
| 1135 | } |
| 1136 | overrideConfig[config] = filteredVars |
| 1137 | } |
| 1138 | } else if (Array.isArray(overrideConfig[config])) { |
| 1139 | // Handle arrays as direct parameter values |
| 1140 | if (isParameterEnabled(flowNodeData.label, config)) { |
| 1141 | // If existing value is also an array, concatenate; otherwise replace |
| 1142 | const existingValue = inputsObj[config] |
| 1143 | if (Array.isArray(existingValue)) { |
| 1144 | inputsObj[config] = [...new Set([...existingValue, ...overrideConfig[config]])] |
| 1145 | } else { |
| 1146 | inputsObj[config] = overrideConfig[config] |
| 1147 | } |
| 1148 | } |
no test coverage detected