| | const { v4 } = require('uuid'); |
| | const { handleAbortError } = require('~/server/middleware/abortMiddleware'); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const validateAssistant = async (req, res, next) => { |
| | const { endpoint, conversationId, assistant_id, messageId } = req.body; |
| |
|
| | const appConfig = req.config; |
| | |
| | const assistantsConfig = appConfig.endpoints?.[endpoint]; |
| | if (!assistantsConfig) { |
| | return next(); |
| | } |
| |
|
| | const { supportedIds, excludedIds } = assistantsConfig; |
| | const error = { message: 'validateAssistant: Assistant not supported' }; |
| |
|
| | if (supportedIds?.length && !supportedIds.includes(assistant_id)) { |
| | return await handleAbortError(res, req, error, { |
| | sender: 'System', |
| | conversationId, |
| | messageId: v4(), |
| | parentMessageId: messageId, |
| | error, |
| | }); |
| | } else if (excludedIds?.length && excludedIds.includes(assistant_id)) { |
| | return await handleAbortError(res, req, error, { |
| | sender: 'System', |
| | conversationId, |
| | messageId: v4(), |
| | parentMessageId: messageId, |
| | }); |
| | } |
| |
|
| | return next(); |
| | }; |
| |
|
| | module.exports = validateAssistant; |
| |
|