mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
* chore: assistants, unsupported assistant, better logging * chore: remove unnecessary logger in validateAssistant middleware * fix: resolve initial conversation save/promise before saving response * chore: Import and organize dependencies in Speech component * fix: conversation statefulness - Latest Message (at index 0) should not be reset if existing convo - add debugging context for clearAllLatestMessages - Added logging concerning latest Message updates (dev mode only) - update latest message Set logic, also checks for change in conversation Id - consolidated latest message helpers to client/src/utils/messages.ts
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
const { v4 } = require('uuid');
|
|
const { handleAbortError } = require('~/server/middleware/abortMiddleware');
|
|
|
|
/**
|
|
* Checks if the assistant is supported or excluded
|
|
* @param {object} req - Express Request
|
|
* @param {object} req.body - The request payload.
|
|
* @param {object} res - Express Response
|
|
* @param {function} next - Express next middleware function.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
const validateAssistant = async (req, res, next) => {
|
|
const { endpoint, conversationId, assistant_id, messageId } = req.body;
|
|
|
|
/** @type {Partial<TAssistantEndpoint>} */
|
|
const assistantsConfig = req.app.locals?.[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;
|