chore:variable (#4946)
This commit is contained in:
parent
8562d4a563
commit
caffad0fb0
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
try {
|
||||
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 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) => {
|
||||
try {
|
||||
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 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<Variable>[], queryRunner?:
|
|||
})
|
||||
|
||||
// step 3 - remove ids that are only duplicate
|
||||
const prepVariables: Partial<Variable>[] = newVariables.map((newVariable) => {
|
||||
let prepVariables: Partial<Variable>[] = 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<Variable>[], 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue