e115934061
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
const { logger, SystemCapabilities } = require('@librechat/data-schemas');
|
|
const { hasCapability } = require('~/server/middleware/roles/capabilities');
|
|
const { getAssistant } = require('~/models');
|
|
|
|
/**
|
|
* Checks if the assistant is supported or excluded
|
|
* @param {object} params
|
|
* @param {object} params.req - Express Request
|
|
* @param {object} params.req.body - The request payload.
|
|
* @param {string} params.overrideEndpoint - The override endpoint
|
|
* @param {string} params.overrideAssistantId - The override assistant ID
|
|
* @param {OpenAIClient} params.openai - OpenAI API Client
|
|
* @returns {Promise<void>}
|
|
*/
|
|
const validateAuthor = async ({ req, openai, overrideEndpoint, overrideAssistantId }) => {
|
|
const endpoint = overrideEndpoint ?? req.body.endpoint ?? req.query.endpoint;
|
|
const assistant_id =
|
|
overrideAssistantId ?? req.params.id ?? req.body.assistant_id ?? req.query.assistant_id;
|
|
|
|
const appConfig = req.config;
|
|
/** @type {Partial<TAssistantEndpoint>} */
|
|
const assistantsConfig = appConfig.endpoints?.[endpoint];
|
|
if (!assistantsConfig) {
|
|
return;
|
|
}
|
|
|
|
if (!assistantsConfig.privateAssistants) {
|
|
return;
|
|
}
|
|
|
|
let canManageAssistants = false;
|
|
try {
|
|
canManageAssistants = await hasCapability(req.user, SystemCapabilities.MANAGE_ASSISTANTS);
|
|
} catch (err) {
|
|
logger.warn(`[validateAuthor] capability check failed, denying bypass: ${err.message}`);
|
|
}
|
|
|
|
if (canManageAssistants) {
|
|
logger.debug(`[validateAuthor] MANAGE_ASSISTANTS bypass for user ${req.user.id}`);
|
|
return;
|
|
}
|
|
|
|
const assistantDoc = await getAssistant({ assistant_id, user: req.user.id });
|
|
if (assistantDoc) {
|
|
return;
|
|
}
|
|
const assistant = await openai.beta.assistants.retrieve(assistant_id);
|
|
if (req.user.id !== assistant?.metadata?.author) {
|
|
throw new Error(`Assistant ${assistant_id} is not authored by the user.`);
|
|
}
|
|
};
|
|
|
|
module.exports = validateAuthor;
|