diff --git a/packages/components/credentials/OpenAPIAuth.credential.ts b/packages/components/credentials/OpenAPIAuth.credential.ts deleted file mode 100644 index 3f0ef9075..000000000 --- a/packages/components/credentials/OpenAPIAuth.credential.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { INodeParams, INodeCredential } from '../src/Interface' - -class OpenAPIAuth implements INodeCredential { - label: string - name: string - version: number - description: string - inputs: INodeParams[] - - constructor() { - this.label = 'OpenAPI Auth Token' - this.name = 'openAPIAuth' - this.version = 1.0 - this.inputs = [ - { - label: 'OpenAPI Token', - name: 'openAPIToken', - type: 'password', - description: 'Auth Token. For example: Bearer ' - } - ] - } -} - -module.exports = { credClass: OpenAPIAuth } diff --git a/packages/server/src/controllers/chat-messages/index.ts b/packages/server/src/controllers/chat-messages/index.ts index 7f380f47d..670374d30 100644 --- a/packages/server/src/controllers/chat-messages/index.ts +++ b/packages/server/src/controllers/chat-messages/index.ts @@ -4,7 +4,7 @@ import chatflowsService from '../../services/chatflows' import chatMessagesService from '../../services/chat-messages' import { aMonthAgo, clearSessionMemory } from '../../utils' import { getRunningExpressApp } from '../../utils/getRunningExpressApp' -import { Between, DeleteResult, FindOptionsWhere } from 'typeorm' +import { Between, DeleteResult, FindOptionsWhere, In } from 'typeorm' import { ChatMessage } from '../../database/entities/ChatMessage' import { InternalFlowiseError } from '../../errors/internalFlowiseError' import { StatusCodes } from 'http-status-codes' @@ -49,19 +49,17 @@ const createChatMessage = async (req: Request, res: Response, next: NextFunction const getAllChatMessages = async (req: Request, res: Response, next: NextFunction) => { try { - let chatTypeFilter = req.query?.chatType as ChatType | undefined - if (chatTypeFilter) { + const _chatTypes = req.query?.chatType as string | undefined + let chatTypes: ChatType[] | undefined + if (_chatTypes) { try { - const chatTypeFilterArray = JSON.parse(chatTypeFilter) - if (chatTypeFilterArray.includes(ChatType.EXTERNAL) && chatTypeFilterArray.includes(ChatType.INTERNAL)) { - chatTypeFilter = undefined - } else if (chatTypeFilterArray.includes(ChatType.EXTERNAL)) { - chatTypeFilter = ChatType.EXTERNAL - } else if (chatTypeFilterArray.includes(ChatType.INTERNAL)) { - chatTypeFilter = ChatType.INTERNAL + if (Array.isArray(_chatTypes)) { + chatTypes = _chatTypes + } else { + chatTypes = JSON.parse(_chatTypes) } } catch (e) { - return res.status(500).send(e) + chatTypes = [_chatTypes as ChatType] } } const sortOrder = req.query?.order as string | undefined @@ -84,7 +82,7 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio } const apiResponse = await chatMessagesService.getAllChatMessages( req.params.id, - chatTypeFilter, + chatTypes, sortOrder, chatId, memoryType, @@ -118,7 +116,7 @@ const getAllInternalChatMessages = async (req: Request, res: Response, next: Nex } const apiResponse = await chatMessagesService.getAllInternalChatMessages( req.params.id, - ChatType.INTERNAL, + [ChatType.INTERNAL], sortOrder, chatId, memoryType, @@ -155,7 +153,19 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc const chatId = req.query?.chatId as string const memoryType = req.query?.memoryType as string | undefined const sessionId = req.query?.sessionId as string | undefined - const _chatType = req.query?.chatType as string | undefined + const _chatTypes = req.query?.chatType as string | undefined + let chatTypes: ChatType[] | undefined + if (_chatTypes) { + try { + if (Array.isArray(_chatTypes)) { + chatTypes = _chatTypes + } else { + chatTypes = JSON.parse(_chatTypes) + } + } catch (e) { + chatTypes = [_chatTypes as ChatType] + } + } const startDate = req.query?.startDate as string | undefined const endDate = req.query?.endDate as string | undefined const isClearFromViewMessageDialog = req.query?.isClearFromViewMessageDialog as string | undefined @@ -169,7 +179,7 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc const hardDelete = req.query?.hardDelete as boolean | undefined const messages = await utilGetChatMessage({ chatflowid, - chatType: _chatType as ChatType | undefined, + chatTypes, startDate, endDate, feedback: isFeedback, @@ -236,7 +246,9 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc if (chatId) deleteOptions.chatId = chatId if (memoryType) deleteOptions.memoryType = memoryType if (sessionId) deleteOptions.sessionId = sessionId - if (_chatType) deleteOptions.chatType = _chatType + if (chatTypes && chatTypes.length > 0) { + deleteOptions.chatType = In(chatTypes) + } if (startDate && endDate) { const fromDate = new Date(startDate) const toDate = new Date(endDate) diff --git a/packages/server/src/controllers/stats/index.ts b/packages/server/src/controllers/stats/index.ts index 20a0bd7fa..c86bd544a 100644 --- a/packages/server/src/controllers/stats/index.ts +++ b/packages/server/src/controllers/stats/index.ts @@ -3,7 +3,6 @@ import { Request, Response, NextFunction } from 'express' import statsService from '../../services/stats' import { ChatMessageRatingType, ChatType } from '../../Interface' import { InternalFlowiseError } from '../../errors/internalFlowiseError' -import { getErrorMessage } from '../../errors/utils' const getChatflowStats = async (req: Request, res: Response, next: NextFunction) => { try { @@ -11,27 +10,22 @@ const getChatflowStats = async (req: Request, res: Response, next: NextFunction) throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: statsController.getChatflowStats - id not provided!`) } const chatflowid = req.params.id - let chatTypeFilter = req.query?.chatType as ChatType | undefined + const _chatTypes = req.query?.chatType as string | undefined + let chatTypes: ChatType[] | undefined + if (_chatTypes) { + try { + if (Array.isArray(_chatTypes)) { + chatTypes = _chatTypes + } else { + chatTypes = JSON.parse(_chatTypes) + } + } catch (e) { + chatTypes = [_chatTypes as ChatType] + } + } const startDate = req.query?.startDate as string | undefined const endDate = req.query?.endDate as string | undefined let feedbackTypeFilters = req.query?.feedbackType as ChatMessageRatingType[] | undefined - if (chatTypeFilter) { - try { - const chatTypeFilterArray = JSON.parse(chatTypeFilter) - if (chatTypeFilterArray.includes(ChatType.EXTERNAL) && chatTypeFilterArray.includes(ChatType.INTERNAL)) { - chatTypeFilter = undefined - } else if (chatTypeFilterArray.includes(ChatType.EXTERNAL)) { - chatTypeFilter = ChatType.EXTERNAL - } else if (chatTypeFilterArray.includes(ChatType.INTERNAL)) { - chatTypeFilter = ChatType.INTERNAL - } - } catch (e) { - throw new InternalFlowiseError( - StatusCodes.INTERNAL_SERVER_ERROR, - `Error: statsController.getChatflowStats - ${getErrorMessage(e)}` - ) - } - } if (feedbackTypeFilters) { try { const feedbackTypeFilterArray = JSON.parse(JSON.stringify(feedbackTypeFilters)) @@ -51,15 +45,7 @@ const getChatflowStats = async (req: Request, res: Response, next: NextFunction) return res.status(500).send(e) } } - const apiResponse = await statsService.getChatflowStats( - chatflowid, - chatTypeFilter, - startDate, - endDate, - '', - true, - feedbackTypeFilters - ) + const apiResponse = await statsService.getChatflowStats(chatflowid, chatTypes, startDate, endDate, '', true, feedbackTypeFilters) return res.json(apiResponse) } catch (error) { next(error) diff --git a/packages/server/src/services/chat-messages/index.ts b/packages/server/src/services/chat-messages/index.ts index 858d0a77e..298eae4b8 100644 --- a/packages/server/src/services/chat-messages/index.ts +++ b/packages/server/src/services/chat-messages/index.ts @@ -27,7 +27,7 @@ const createChatMessage = async (chatMessage: Partial) => { // Get all chatmessages from chatflowid const getAllChatMessages = async ( chatflowId: string, - chatTypeFilter: ChatType | undefined, + chatTypes: ChatType[] | undefined, sortOrder: string = 'ASC', chatId?: string, memoryType?: string, @@ -41,7 +41,7 @@ const getAllChatMessages = async ( try { const dbResponse = await utilGetChatMessage({ chatflowid: chatflowId, - chatType: chatTypeFilter, + chatTypes, sortOrder, chatId, memoryType, @@ -64,7 +64,7 @@ const getAllChatMessages = async ( // Get internal chatmessages from chatflowid const getAllInternalChatMessages = async ( chatflowId: string, - chatTypeFilter: ChatType | undefined, + chatTypes: ChatType[] | undefined, sortOrder: string = 'ASC', chatId?: string, memoryType?: string, @@ -78,7 +78,7 @@ const getAllInternalChatMessages = async ( try { const dbResponse = await utilGetChatMessage({ chatflowid: chatflowId, - chatType: chatTypeFilter, + chatTypes, sortOrder, chatId, memoryType, diff --git a/packages/server/src/services/stats/index.ts b/packages/server/src/services/stats/index.ts index 7c1f60fc9..8b28c4f95 100644 --- a/packages/server/src/services/stats/index.ts +++ b/packages/server/src/services/stats/index.ts @@ -9,7 +9,7 @@ import { getErrorMessage } from '../../errors/utils' // get stats for showing in chatflow const getChatflowStats = async ( chatflowid: string, - chatTypeFilter: ChatType | undefined, + chatTypes: ChatType[] | undefined, startDate?: string, endDate?: string, messageId?: string, @@ -19,7 +19,7 @@ const getChatflowStats = async ( try { const chatmessages = (await utilGetChatMessage({ chatflowid, - chatType: chatTypeFilter, + chatTypes, startDate, endDate, messageId, diff --git a/packages/server/src/utils/getChatMessage.ts b/packages/server/src/utils/getChatMessage.ts index 3a35b486e..f5244aa60 100644 --- a/packages/server/src/utils/getChatMessage.ts +++ b/packages/server/src/utils/getChatMessage.ts @@ -1,4 +1,4 @@ -import { MoreThanOrEqual, LessThanOrEqual, Between } from 'typeorm' +import { MoreThanOrEqual, LessThanOrEqual, Between, In } from 'typeorm' import { ChatMessageRatingType, ChatType } from '../Interface' import { ChatMessage } from '../database/entities/ChatMessage' import { ChatMessageFeedback } from '../database/entities/ChatMessageFeedback' @@ -8,7 +8,7 @@ import { aMonthAgo } from '.' /** * Method that get chat messages. * @param {string} chatflowid - * @param {ChatType} chatType + * @param {ChatType[]} chatTypes * @param {string} sortOrder * @param {string} chatId * @param {string} memoryType @@ -20,7 +20,7 @@ import { aMonthAgo } from '.' */ interface GetChatMessageParams { chatflowid: string - chatType?: ChatType + chatTypes?: ChatType[] sortOrder?: string chatId?: string memoryType?: string @@ -34,7 +34,7 @@ interface GetChatMessageParams { export const utilGetChatMessage = async ({ chatflowid, - chatType, + chatTypes, sortOrder = 'ASC', chatId, memoryType, @@ -56,8 +56,8 @@ export const utilGetChatMessage = async ({ .where('chat_message.chatflowid = :chatflowid', { chatflowid }) // based on which parameters are available add `andWhere` clauses to the query - if (chatType) { - query.andWhere('chat_message.chatType = :chatType', { chatType }) + if (chatTypes && chatTypes.length > 0) { + query.andWhere('chat_message.chatType IN (:...chatTypes)', { chatTypes }) } if (chatId) { query.andWhere('chat_message.chatId = :chatId', { chatId }) @@ -114,7 +114,7 @@ export const utilGetChatMessage = async ({ return await appServer.AppDataSource.getRepository(ChatMessage).find({ where: { chatflowid, - chatType, + chatType: chatTypes?.length ? In(chatTypes) : undefined, chatId, memoryType: memoryType ?? undefined, sessionId: sessionId ?? undefined,