diff --git a/packages/server/src/services/export-import/index.ts b/packages/server/src/services/export-import/index.ts index 0f60796a5..0fb86e00d 100644 --- a/packages/server/src/services/export-import/index.ts +++ b/packages/server/src/services/export-import/index.ts @@ -25,6 +25,7 @@ import executionService, { ExecutionFilters } from '../executions' import marketplacesService from '../marketplaces' import toolsService from '../tools' import variableService from '../variables' +import { Platform } from '../../Interface' type ExportInput = { agentflow: boolean @@ -547,6 +548,8 @@ async function replaceDuplicateIdsForVariable(queryRunner: QueryRunner, original const records = await queryRunner.manager.find(Variable, { where: { id: In(ids) } }) + if (getRunningExpressApp().identityManager.getPlatformType() === Platform.CLOUD) + originalData.Variable = originalData.Variable.filter((variable) => variable.type !== 'runtime') if (records.length < 0) return originalData for (let record of records) { const oldId = record.id diff --git a/packages/server/src/services/variables/index.ts b/packages/server/src/services/variables/index.ts index 0a0099842..b2ecc31c5 100644 --- a/packages/server/src/services/variables/index.ts +++ b/packages/server/src/services/variables/index.ts @@ -6,11 +6,13 @@ import { getErrorMessage } from '../../errors/utils' import { getAppVersion } from '../../utils' import { QueryRunner } from 'typeorm' import { validate } from 'uuid' +import { Platform } from '../../Interface' const createVariable = async (newVariable: Variable, orgId: string) => { + const appServer = getRunningExpressApp() + if (appServer.identityManager.getPlatformType() === Platform.CLOUD && newVariable.type === 'runtime') + throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Cloud platform does not support runtime variables!') try { - const appServer = getRunningExpressApp() - const variable = await appServer.AppDataSource.getRepository(Variable).create(newVariable) const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(variable) await appServer.telemetry.sendTelemetry( @@ -87,8 +89,10 @@ const getVariableById = async (variableId: string) => { } const updateVariable = async (variable: Variable, updatedVariable: Variable) => { + const appServer = getRunningExpressApp() + if (appServer.identityManager.getPlatformType() === Platform.CLOUD && updatedVariable.type === 'runtime') + throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Cloud platform does not support runtime variables!') try { - const appServer = getRunningExpressApp() const tmpUpdatedVariable = await appServer.AppDataSource.getRepository(Variable).merge(variable, updatedVariable) const dbResponse = await appServer.AppDataSource.getRepository(Variable).save(tmpUpdatedVariable) return dbResponse @@ -131,7 +135,7 @@ const importVariables = async (newVariables: Partial[], queryRunner?: }) // step 3 - remove ids that are only duplicate - const prepVariables: Partial[] = newVariables.map((newVariable) => { + let prepVariables: Partial[] = newVariables.map((newVariable) => { let id: string = '' if (newVariable.id) id = newVariable.id if (foundIds.includes(id)) { @@ -141,6 +145,10 @@ const importVariables = async (newVariables: Partial[], queryRunner?: return newVariable }) + // Filter out variables with type "runtime" + if (appServer.identityManager.getPlatformType() === Platform.CLOUD) + prepVariables = prepVariables.filter((variable) => variable.type !== 'runtime') + // step 4 - transactional insert array of entities const insertResponse = await repository.insert(prepVariables) diff --git a/packages/ui/src/views/variables/AddEditVariableDialog.jsx b/packages/ui/src/views/variables/AddEditVariableDialog.jsx index 9647ffc04..dd82c7560 100644 --- a/packages/ui/src/views/variables/AddEditVariableDialog.jsx +++ b/packages/ui/src/views/variables/AddEditVariableDialog.jsx @@ -114,7 +114,7 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro if (setError) setError(err) enqueueSnackbar({ message: `Failed to add new Variable: ${ - typeof error.response.data === 'object' ? error.response.data.message : error.response.data + typeof err.response.data === 'object' ? err.response.data.message : err.response.data }`, options: { key: new Date().getTime() + Math.random(), @@ -155,11 +155,11 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro }) onConfirm(saveResp.data.id) } - } catch (error) { + } catch (err) { if (setError) setError(err) enqueueSnackbar({ message: `Failed to save Variable: ${ - typeof error.response.data === 'object' ? error.response.data.message : error.response.data + typeof err.response.data === 'object' ? err.response.data.message : err.response.data }`, options: { key: new Date().getTime() + Math.random(),