MCPcopy
hub / github.com/FlowiseAI/Flowise / getGlobalVariable

Function getGlobalVariable

packages/server/src/utils/index.ts:810–864  ·  view source on GitHub ↗
(
    overrideConfig?: ICommonObject,
    availableVariables: IVariable[] = [],
    variableOverrides: ICommonObject[] = []
)

Source from the content-addressed store, hash-verified

808}
809
810export const getGlobalVariable = async (
811 overrideConfig?: ICommonObject,
812 availableVariables: IVariable[] = [],
813 variableOverrides: ICommonObject[] = []
814) => {
815 // override variables defined in overrideConfig
816 // nodeData.inputs.vars is an Object, check each property and override the variable
817 if (overrideConfig?.vars && variableOverrides) {
818 for (const propertyName of Object.getOwnPropertyNames(overrideConfig.vars)) {
819 // Check if this variable is enabled for override
820 const override = variableOverrides.find((v) => v.name === propertyName)
821 if (!override?.enabled) {
822 continue // Skip this variable if it's not enabled for override
823 }
824
825 const foundVar = availableVariables.find((v) => v.name === propertyName)
826 if (foundVar) {
827 // even if the variable was defined as runtime, we override it with static value
828 foundVar.type = 'static'
829 foundVar.value = overrideConfig.vars[propertyName]
830 } else {
831 // add it the variables, if not found locally in the db
832 availableVariables.push({
833 name: propertyName,
834 type: 'static',
835 value: overrideConfig.vars[propertyName],
836 id: '',
837 updatedDate: new Date(),
838 createdDate: new Date(),
839 workspaceId: ''
840 })
841 }
842 }
843 }
844
845 let vars = {}
846 if (availableVariables.length) {
847 for (const item of availableVariables) {
848 let value = item.value
849
850 // read from .env file
851 if (item.type === 'runtime') {
852 value = process.env[item.name] ?? ''
853 }
854
855 Object.defineProperty(vars, item.name, {
856 enumerable: true,
857 configurable: true,
858 writable: true,
859 value: value
860 })
861 }
862 }
863 return vars
864}
865
866/**
867 * Get variable value from outputResponses.output

Callers 2

resolveNodeReferenceFunction · 0.85
getVariableValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected