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

Function deleteChatflow

packages/server/src/services/chatflows/index.ts:122–171  ·  view source on GitHub ↗
(
    chatflowId: string,
    orgId: string,
    workspaceId: string,
    userPermittedTypes: EnumChatflowType[]
)

Source from the content-addressed store, hash-verified

120}
121
122const deleteChatflow = async (
123 chatflowId: string,
124 orgId: string,
125 workspaceId: string,
126 userPermittedTypes: EnumChatflowType[]
127): Promise<any> => {
128 try {
129 const appServer = getRunningExpressApp()
130
131 const chatflow = await getChatflowById(chatflowId, workspaceId)
132 if (!userPermittedTypes.includes(chatflow.type as EnumChatflowType))
133 throw new InternalFlowiseError(StatusCodes.FORBIDDEN, `You do not have permission to delete this chatflow type`)
134
135 const dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).delete({ id: chatflowId })
136
137 // Update document store usage
138 await documentStoreService.updateDocumentStoreUsage(chatflowId, undefined, workspaceId)
139
140 // Delete all chat messages
141 await appServer.AppDataSource.getRepository(ChatMessage).delete({ chatflowid: chatflowId })
142
143 // Delete all chat feedback
144 await appServer.AppDataSource.getRepository(ChatMessageFeedback).delete({ chatflowid: chatflowId })
145
146 // Delete all upsert history
147 await appServer.AppDataSource.getRepository(UpsertHistory).delete({ chatflowid: chatflowId })
148
149 // delete schedules related to the chatflow if it's an agentflow
150 if (chatflow.type === EnumChatflowType.AGENTFLOW) {
151 const existingRecord = await scheduleService.deleteScheduleForTarget(chatflow.id, ScheduleTriggerType.AGENTFLOW, workspaceId)
152 if (existingRecord) {
153 await ScheduleBeat.getInstance().onScheduleChanged(existingRecord.id, 'delete')
154 }
155 }
156
157 try {
158 // Delete all uploads corresponding to this chatflow
159 const { totalSize } = await removeFolderFromStorage(orgId, chatflowId)
160 await updateStorageUsage(orgId, workspaceId, totalSize, appServer.usageCacheManager)
161 } catch (e) {
162 logger.error(`[server]: Error deleting file storage for chatflow ${chatflowId}`)
163 }
164 return dbResponse
165 } catch (error) {
166 throw new InternalFlowiseError(
167 StatusCodes.INTERNAL_SERVER_ERROR,
168 `Error: chatflowsService.deleteChatflow - ${getErrorMessage(error)}`
169 )
170 }
171}
172
173const getAllChatflows = async (type?: ChatflowType, workspaceId?: string, page: number = -1, limit: number = -1) => {
174 try {

Callers

nothing calls this directly

Calls 8

getRunningExpressAppFunction · 0.90
updateStorageUsageFunction · 0.90
getErrorMessageFunction · 0.90
removeFolderFromStorageFunction · 0.85
onScheduleChangedMethod · 0.80
getChatflowByIdFunction · 0.70
deleteMethod · 0.45
getInstanceMethod · 0.45

Tested by

no test coverage detected