const { Constants, FileSources, EModelEndpoint, defaultSocialLogins, validateAzureGroups, mapModelToAzureConfig, deprecatedAzureVariables, conflictingAzureVariables, } = require('librechat-data-provider'); const { initializeFirebase } = require('./Files/Firebase/initialize'); const loadCustomConfig = require('./Config/loadCustomConfig'); const handleRateLimits = require('./Config/handleRateLimits'); const { loadAndFormatTools } = require('./ToolService'); const paths = require('~/config/paths'); const { logger } = require('~/config'); /** * * Loads custom config and initializes app-wide variables. * @function AppService * @param {Express.Application} app - The Express application object. */ const AppService = async (app) => { /** @type {TCustomConfig}*/ const config = (await loadCustomConfig()) ?? {}; const fileStrategy = config.fileStrategy ?? FileSources.local; process.env.CDN_PROVIDER = fileStrategy; if (fileStrategy === FileSources.firebase) { initializeFirebase(); } /** @type {Record { if (process.env[key]) { logger.warn( `The \`${key}\` environment variable (related to ${description}) should not be used in combination with the \`azureOpenAI\` endpoint configuration, as you will experience conflicts and errors.`, ); } }); conflictingAzureVariables.forEach(({ key }) => { if (process.env[key]) { logger.warn( `The \`${key}\` environment variable should not be used in combination with the \`azureOpenAI\` endpoint configuration, as you may experience with the defined placeholders for mapping to the current model grouping using the same name.`, ); } }); } if (config?.endpoints?.[EModelEndpoint.assistants]) { const { disableBuilder, pollIntervalMs, timeoutMs, supportedIds, excludedIds } = config.endpoints[EModelEndpoint.assistants]; if (supportedIds?.length && excludedIds?.length) { logger.warn( `Both \`supportedIds\` and \`excludedIds\` are defined for the ${EModelEndpoint.assistants} endpoint; \`excludedIds\` field will be ignored.`, ); } /** @type {Partial} */ endpointLocals[EModelEndpoint.assistants] = { disableBuilder, pollIntervalMs, timeoutMs, supportedIds, excludedIds, }; } app.locals = { socialLogins, availableTools, fileStrategy, fileConfig: config?.fileConfig, paths, ...endpointLocals, }; }; module.exports = AppService;