(
chatflowId: string,
orgId: string,
workspaceId: string,
userPermittedTypes: EnumChatflowType[]
)
| 120 | } |
| 121 | |
| 122 | const 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 | |
| 173 | const getAllChatflows = async (type?: ChatflowType, workspaceId?: string, page: number = -1, limit: number = -1) => { |
| 174 | try { |
nothing calls this directly
no test coverage detected