@@ -519,7 +519,7 @@ export const buildFlow = async ({
519
519
520
520
// Only override the config if its status is true
521
521
if ( overrideConfig && apiOverrideStatus ) {
522
- flowNodeData = replaceInputsWithConfig ( flowNodeData , overrideConfig , nodeOverrides )
522
+ flowNodeData = replaceInputsWithConfig ( flowNodeData , overrideConfig , nodeOverrides , variableOverrides )
523
523
}
524
524
525
525
if ( isUpsert ) upsertHistory [ 'flowData' ] = saveUpsertFlowData ( flowNodeData , upsertHistory )
@@ -1001,9 +1001,15 @@ export const resolveVariables = async (
1001
1001
* @param {INodeData } flowNodeData
1002
1002
* @param {ICommonObject } overrideConfig
1003
1003
* @param {ICommonObject } nodeOverrides
1004
+ * @param {ICommonObject[] } variableOverrides
1004
1005
* @returns {INodeData }
1005
1006
*/
1006
- export const replaceInputsWithConfig = ( flowNodeData : INodeData , overrideConfig : ICommonObject , nodeOverrides : ICommonObject ) => {
1007
+ export const replaceInputsWithConfig = (
1008
+ flowNodeData : INodeData ,
1009
+ overrideConfig : ICommonObject ,
1010
+ nodeOverrides : ICommonObject ,
1011
+ variableOverrides : ICommonObject [ ]
1012
+ ) => {
1007
1013
const types = 'inputs'
1008
1014
1009
1015
const isParameterEnabled = ( nodeType : string , paramName : string ) : boolean => {
@@ -1014,28 +1020,54 @@ export const replaceInputsWithConfig = (flowNodeData: INodeData, overrideConfig:
1014
1020
1015
1021
const getParamValues = ( inputsObj : ICommonObject ) => {
1016
1022
for ( const config in overrideConfig ) {
1017
- // Always allow analytics config: https://docs.flowiseai.com/using-flowise/analytic#api
1018
- if ( config !== 'analytics' ) {
1019
- // If overrideConfig[key] is object
1020
- if ( overrideConfig [ config ] && typeof overrideConfig [ config ] === 'object' ) {
1021
- const nodeIds = Object . keys ( overrideConfig [ config ] )
1022
- if ( nodeIds . includes ( flowNodeData . id ) ) {
1023
- // Check if this parameter is enabled for this node type
1024
- if ( isParameterEnabled ( flowNodeData . label , config ) ) {
1025
- inputsObj [ config ] = overrideConfig [ config ] [ flowNodeData . id ]
1023
+ /**
1024
+ * Several conditions:
1025
+ * 1. If config is 'analytics', always allow it
1026
+ * 2. If config is 'vars', check its object and filter out the variables that are not enabled for override
1027
+ * 3. If typeof config is an object, check if the node id is in the overrideConfig object and if the parameter (systemMessagePrompt) is enabled
1028
+ * Example:
1029
+ * "systemMessagePrompt": {
1030
+ * "chatPromptTemplate_0": "You are an assistant"
1031
+ * }
1032
+ * 4. If typeof config is a string, check if the parameter is enabled
1033
+ * Example:
1034
+ * "systemMessagePrompt": "You are an assistant"
1035
+ */
1036
+
1037
+ if ( config === 'analytics' ) {
1038
+ // pass
1039
+ } else if ( config === 'vars' ) {
1040
+ if ( typeof overrideConfig [ config ] === 'object' ) {
1041
+ const filteredVars : ICommonObject = { }
1042
+
1043
+ const vars = overrideConfig [ config ]
1044
+ for ( const variable in vars ) {
1045
+ const override = variableOverrides . find ( ( v ) => v . name === variable )
1046
+ if ( ! override ?. enabled ) {
1047
+ continue // Skip this variable if it's not enabled for override
1026
1048
}
1027
- continue
1028
- } else if ( nodeIds . some ( ( nodeId ) => nodeId . includes ( flowNodeData . name ) ) ) {
1029
- /*
1030
- * "systemMessagePrompt": {
1031
- * "chatPromptTemplate_0": "You are an assistant" <---- continue for loop if current node is chatPromptTemplate_1
1032
- * }
1033
- */
1034
- continue
1049
+ filteredVars [ variable ] = vars [ variable ]
1035
1050
}
1051
+ overrideConfig [ config ] = filteredVars
1036
1052
}
1037
-
1038
- // Only proceed if the parameter is enabled for this node type
1053
+ } else if ( overrideConfig [ config ] && typeof overrideConfig [ config ] === 'object' ) {
1054
+ const nodeIds = Object . keys ( overrideConfig [ config ] )
1055
+ if ( nodeIds . includes ( flowNodeData . id ) ) {
1056
+ // Check if this parameter is enabled
1057
+ if ( isParameterEnabled ( flowNodeData . label , config ) ) {
1058
+ inputsObj [ config ] = overrideConfig [ config ] [ flowNodeData . id ]
1059
+ }
1060
+ continue
1061
+ } else if ( nodeIds . some ( ( nodeId ) => nodeId . includes ( flowNodeData . name ) ) ) {
1062
+ /*
1063
+ * "systemMessagePrompt": {
1064
+ * "chatPromptTemplate_0": "You are an assistant" <---- continue for loop if current node is chatPromptTemplate_1
1065
+ * }
1066
+ */
1067
+ continue
1068
+ }
1069
+ } else {
1070
+ // Only proceed if the parameter is enabled
1039
1071
if ( ! isParameterEnabled ( flowNodeData . label , config ) ) {
1040
1072
continue
1041
1073
}
0 commit comments