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

Function updateChatflow

packages/server/src/services/chatflows/index.ts:454–554  ·  view source on GitHub ↗
(
    chatflow: ChatFlow,
    updateChatFlow: ChatFlow,
    orgId: string,
    workspaceId: string,
    subscriptionId: string
)

Source from the content-addressed store, hash-verified

452}
453
454const updateChatflow = async (
455 chatflow: ChatFlow,
456 updateChatFlow: ChatFlow,
457 orgId: string,
458 workspaceId: string,
459 subscriptionId: string
460): Promise<any> => {
461 const appServer = getRunningExpressApp()
462 if (updateChatFlow.flowData && containsBase64File(updateChatFlow)) {
463 updateChatFlow.flowData = await updateFlowDataWithFilePaths(
464 chatflow.id,
465 updateChatFlow.flowData,
466 orgId,
467 workspaceId,
468 subscriptionId,
469 appServer.usageCacheManager
470 )
471 }
472 if (updateChatFlow.type || updateChatFlow.type === '') {
473 validateChatflowType(updateChatFlow.type)
474 } else {
475 updateChatFlow.type = chatflow.type
476 }
477 if (updateChatFlow.chatbotConfig) {
478 try {
479 const parsed = JSON.parse(updateChatFlow.chatbotConfig) as ICommonObject
480 if (parsed?.fullFileUpload?.allowedUploadFileTypes !== undefined) {
481 const current = parsed.fullFileUpload.allowedUploadFileTypes
482 const sanitized = sanitizeAllowedUploadMimeTypesFromConfig(typeof current === 'string' ? current : String(current ?? ''))
483 parsed.fullFileUpload.allowedUploadFileTypes = sanitized
484 updateChatFlow.chatbotConfig = JSON.stringify(parsed)
485 }
486 } catch (error) {
487 const message = getErrorMessage(error)
488 logger.error(`[server]: Invalid chatbotConfig JSON in updateChatflow: ${message}`)
489 throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, `Invalid chatbotConfig: ${message}`)
490 }
491 }
492 const newDbChatflow = appServer.AppDataSource.getRepository(ChatFlow).merge(chatflow, updateChatFlow)
493 newDbChatflow.workspaceId = workspaceId // defense-in-depth: use trusted param, not chatflow.workspaceId (merge mutates in-place)
494 await _checkAndUpdateDocumentStoreUsage(newDbChatflow, workspaceId)
495 const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).save(newDbChatflow)
496
497 // Check if the flow is agentflow and if it has a schedule node, if yes then notify the beat to sync the schedule
498 if (dbResponse.type === EnumChatflowType.AGENTFLOW) {
499 const flowData = dbResponse.flowData
500 const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
501 const nodes = (parsedFlowData.nodes || []).filter((node) => node.data.name !== 'stickyNoteAgentflow')
502 const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
503 const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
504 if (startInputType === 'scheduleInput') {
505 const scheduleInputMode = startNode?.data?.inputs?.scheduleInputMode as ScheduleInputMode | undefined
506 if (!scheduleInputMode) {
507 throw new InternalFlowiseError(
508 StatusCodes.BAD_REQUEST,
509 'Schedule Input Mode is required on the Start node when Start Input Type is Schedule.'
510 )
511 }

Callers

nothing calls this directly

Calls 11

getRunningExpressAppFunction · 0.90
containsBase64FileFunction · 0.90
getErrorMessageFunction · 0.90
validateChatflowTypeFunction · 0.85
stringifyMethod · 0.80
onScheduleChangedMethod · 0.80
parseMethod · 0.65
getInstanceMethod · 0.45

Tested by

no test coverage detected