(
reactFlowNodeData: INodeData,
reactFlowNodes: IReactFlowNode[],
question: string,
chatHistory: IMessage[],
flowConfig?: ICommonObject,
uploadedFilesContent?: string,
availableVariables: IVariable[] = [],
variableOverrides: ICommonObject[] = []
)
| 1025 | * @returns {INodeData} |
| 1026 | */ |
| 1027 | export const resolveVariables = async ( |
| 1028 | reactFlowNodeData: INodeData, |
| 1029 | reactFlowNodes: IReactFlowNode[], |
| 1030 | question: string, |
| 1031 | chatHistory: IMessage[], |
| 1032 | flowConfig?: ICommonObject, |
| 1033 | uploadedFilesContent?: string, |
| 1034 | availableVariables: IVariable[] = [], |
| 1035 | variableOverrides: ICommonObject[] = [] |
| 1036 | ): Promise<INodeData> => { |
| 1037 | let flowNodeData = cloneDeep(reactFlowNodeData) |
| 1038 | |
| 1039 | const getParamValues = async (paramsObj: ICommonObject) => { |
| 1040 | for (const key in paramsObj) { |
| 1041 | const paramValue: string = paramsObj[key] |
| 1042 | if (Array.isArray(paramValue)) { |
| 1043 | const resolvedInstances = [] |
| 1044 | for (const param of paramValue) { |
| 1045 | const resolvedInstance = await getVariableValue( |
| 1046 | param, |
| 1047 | reactFlowNodes, |
| 1048 | question, |
| 1049 | chatHistory, |
| 1050 | undefined, |
| 1051 | flowConfig, |
| 1052 | uploadedFilesContent, |
| 1053 | availableVariables, |
| 1054 | variableOverrides |
| 1055 | ) |
| 1056 | resolvedInstances.push(resolvedInstance) |
| 1057 | } |
| 1058 | paramsObj[key] = resolvedInstances |
| 1059 | } else { |
| 1060 | const isAcceptVariable = reactFlowNodeData.inputParams.find((param) => param.name === key)?.acceptVariable ?? false |
| 1061 | const resolvedInstance = await getVariableValue( |
| 1062 | paramValue, |
| 1063 | reactFlowNodes, |
| 1064 | question, |
| 1065 | chatHistory, |
| 1066 | isAcceptVariable, |
| 1067 | flowConfig, |
| 1068 | uploadedFilesContent, |
| 1069 | availableVariables, |
| 1070 | variableOverrides |
| 1071 | ) |
| 1072 | paramsObj[key] = resolvedInstance |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | const paramsObj = flowNodeData['inputs'] ?? {} |
| 1078 | await getParamValues(paramsObj) |
| 1079 | |
| 1080 | return flowNodeData |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * Loop through each inputs and replace their value with override config values |
no test coverage detected