1+ /**
2+ * Strictly no getRepository, appServer here, must be passed as parameter
3+ */
4+
15import path from 'path'
26import fs from 'fs'
37import logger from './logger'
@@ -17,6 +21,7 @@ import {
1721 IOverrideConfig ,
1822 IReactFlowEdge ,
1923 IReactFlowNode ,
24+ IVariable ,
2025 IVariableDict ,
2126 IVariableOverride ,
2227 IncomingInput
@@ -439,6 +444,7 @@ type BuildFlowParams = {
439444 overrideConfig ?: ICommonObject
440445 apiOverrideStatus ?: boolean
441446 nodeOverrides ?: INodeOverrides
447+ availableVariables ?: IVariable [ ]
442448 variableOverrides ?: IVariableOverride [ ]
443449 cachePool ?: CachePool
444450 isUpsert ?: boolean
@@ -470,6 +476,7 @@ export const buildFlow = async ({
470476 overrideConfig,
471477 apiOverrideStatus = false ,
472478 nodeOverrides = { } ,
479+ availableVariables = [ ] ,
473480 variableOverrides = [ ] ,
474481 cachePool,
475482 isUpsert,
@@ -534,6 +541,7 @@ export const buildFlow = async ({
534541 chatHistory ,
535542 flowData ,
536543 uploadedFilesContent ,
544+ availableVariables ,
537545 variableOverrides
538546 )
539547
@@ -727,9 +735,12 @@ export const clearSessionMemory = async (
727735 }
728736}
729737
730- const getGlobalVariable = async ( appDataSource : DataSource , overrideConfig ?: ICommonObject , variableOverrides ?: ICommonObject [ ] ) => {
731- const variables = await appDataSource . getRepository ( Variable ) . find ( )
732-
738+ const getGlobalVariable = async (
739+ appDataSource : DataSource ,
740+ overrideConfig ?: ICommonObject ,
741+ availableVariables : IVariable [ ] = [ ] ,
742+ variableOverrides ?: ICommonObject [ ]
743+ ) => {
733744 // override variables defined in overrideConfig
734745 // nodeData.inputs.vars is an Object, check each property and override the variable
735746 if ( overrideConfig ?. vars && variableOverrides ) {
@@ -740,14 +751,14 @@ const getGlobalVariable = async (appDataSource: DataSource, overrideConfig?: ICo
740751 continue // Skip this variable if it's not enabled for override
741752 }
742753
743- const foundVar = variables . find ( ( v ) => v . name === propertyName )
754+ const foundVar = availableVariables . find ( ( v ) => v . name === propertyName )
744755 if ( foundVar ) {
745756 // even if the variable was defined as runtime, we override it with static value
746757 foundVar . type = 'static'
747758 foundVar . value = overrideConfig . vars [ propertyName ]
748759 } else {
749760 // add it the variables, if not found locally in the db
750- variables . push ( {
761+ availableVariables . push ( {
751762 name : propertyName ,
752763 type : 'static' ,
753764 value : overrideConfig . vars [ propertyName ] ,
@@ -760,8 +771,8 @@ const getGlobalVariable = async (appDataSource: DataSource, overrideConfig?: ICo
760771 }
761772
762773 let vars = { }
763- if ( variables . length ) {
764- for ( const item of variables ) {
774+ if ( availableVariables . length ) {
775+ for ( const item of availableVariables ) {
765776 let value = item . value
766777
767778 // read from .env file
@@ -797,6 +808,7 @@ export const getVariableValue = async (
797808 isAcceptVariable = false ,
798809 flowData ?: ICommonObject ,
799810 uploadedFilesContent ?: string ,
811+ availableVariables : IVariable [ ] = [ ] ,
800812 variableOverrides : ICommonObject [ ] = [ ]
801813) => {
802814 const isObject = typeof paramValue === 'object'
@@ -839,7 +851,7 @@ export const getVariableValue = async (
839851 }
840852
841853 if ( variableFullPath . startsWith ( '$vars.' ) ) {
842- const vars = await getGlobalVariable ( appDataSource , flowData , variableOverrides )
854+ const vars = await getGlobalVariable ( appDataSource , flowData , availableVariables , variableOverrides )
843855 const variableValue = get ( vars , variableFullPath . replace ( '$vars.' , '' ) )
844856 if ( variableValue ) {
845857 variableDict [ `{{${ variableFullPath } }}` ] = variableValue
@@ -949,6 +961,7 @@ export const resolveVariables = async (
949961 chatHistory : IMessage [ ] ,
950962 flowData ?: ICommonObject ,
951963 uploadedFilesContent ?: string ,
964+ availableVariables : IVariable [ ] = [ ] ,
952965 variableOverrides : ICommonObject [ ] = [ ]
953966) : Promise < INodeData > => {
954967 let flowNodeData = cloneDeep ( reactFlowNodeData )
@@ -969,6 +982,7 @@ export const resolveVariables = async (
969982 undefined ,
970983 flowData ,
971984 uploadedFilesContent ,
985+ availableVariables ,
972986 variableOverrides
973987 )
974988 resolvedInstances . push ( resolvedInstance )
@@ -985,6 +999,7 @@ export const resolveVariables = async (
985999 isAcceptVariable ,
9861000 flowData ,
9871001 uploadedFilesContent ,
1002+ availableVariables ,
9881003 variableOverrides
9891004 )
9901005 paramsObj [ key ] = resolvedInstance
0 commit comments