mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* feat: add filterFilesByEndpointConfig to filter disabled file processing by provider * chore: explicit define of endpointFileConfig for better debugging * refactor: move `normalizeEndpointName` to data-provider as used app-wide * chore: remove overrideEndpoint from useFileHandling * refactor: improve endpoint file config selection * refactor: update filterFilesByEndpointConfig to accept structured parameters and improve endpoint file config handling * refactor: replace defaultFileConfig with getEndpointFileConfig for improved file configuration handling across components * test: add comprehensive unit tests for getEndpointFileConfig to validate endpoint configuration handling * refactor: streamline agent endpoint assignment and improve file filtering logic * feat: add error handling for disabled file uploads in endpoint configuration * refactor: update encodeAndFormat functions to accept structured parameters for provider and endpoint * refactor: streamline requestFiles handling in initializeAgent function * fix: getEndpointFileConfig partial config merging scenarios * refactor: enhance mergeWithDefault function to support document-supported providers with comprehensive MIME types * refactor: user-configured default file config in getEndpointFileConfig * fix: prevent file handling when endpoint is disabled and file is dragged to chat * refactor: move `getEndpointField` to `data-provider` and update usage across components and hooks * fix: prioritize endpointType based on agent.endpoint in file filtering logic * fix: prioritize agent.endpoint in file filtering logic and remove unnecessary endpointType defaulting
121 lines
3.8 KiB
JavaScript
121 lines
3.8 KiB
JavaScript
const { loadCustomEndpointsConfig } = require('@librechat/api');
|
|
const {
|
|
CacheKeys,
|
|
EModelEndpoint,
|
|
isAgentsEndpoint,
|
|
orderEndpointsConfig,
|
|
defaultAgentCapabilities,
|
|
} = require('librechat-data-provider');
|
|
const loadDefaultEndpointsConfig = require('./loadDefaultEConfig');
|
|
const getLogStores = require('~/cache/getLogStores');
|
|
const { getAppConfig } = require('./app');
|
|
|
|
/**
|
|
*
|
|
* @param {ServerRequest} req
|
|
* @returns {Promise<TEndpointsConfig>}
|
|
*/
|
|
async function getEndpointsConfig(req) {
|
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
|
const cachedEndpointsConfig = await cache.get(CacheKeys.ENDPOINT_CONFIG);
|
|
if (cachedEndpointsConfig) {
|
|
return cachedEndpointsConfig;
|
|
}
|
|
|
|
const appConfig = req.config ?? (await getAppConfig({ role: req.user?.role }));
|
|
const defaultEndpointsConfig = await loadDefaultEndpointsConfig(appConfig);
|
|
const customEndpointsConfig = loadCustomEndpointsConfig(appConfig?.endpoints?.custom);
|
|
|
|
/** @type {TEndpointsConfig} */
|
|
const mergedConfig = {
|
|
...defaultEndpointsConfig,
|
|
...customEndpointsConfig,
|
|
};
|
|
|
|
if (appConfig.endpoints?.[EModelEndpoint.azureOpenAI]) {
|
|
/** @type {Omit<TConfig, 'order'>} */
|
|
mergedConfig[EModelEndpoint.azureOpenAI] = {
|
|
userProvide: false,
|
|
};
|
|
}
|
|
|
|
if (appConfig.endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) {
|
|
/** @type {Omit<TConfig, 'order'>} */
|
|
mergedConfig[EModelEndpoint.azureAssistants] = {
|
|
userProvide: false,
|
|
};
|
|
}
|
|
|
|
if (
|
|
mergedConfig[EModelEndpoint.assistants] &&
|
|
appConfig?.endpoints?.[EModelEndpoint.assistants]
|
|
) {
|
|
const { disableBuilder, retrievalModels, capabilities, version, ..._rest } =
|
|
appConfig.endpoints[EModelEndpoint.assistants];
|
|
|
|
mergedConfig[EModelEndpoint.assistants] = {
|
|
...mergedConfig[EModelEndpoint.assistants],
|
|
version,
|
|
retrievalModels,
|
|
disableBuilder,
|
|
capabilities,
|
|
};
|
|
}
|
|
if (mergedConfig[EModelEndpoint.agents] && appConfig?.endpoints?.[EModelEndpoint.agents]) {
|
|
const { disableBuilder, capabilities, allowedProviders, ..._rest } =
|
|
appConfig.endpoints[EModelEndpoint.agents];
|
|
|
|
mergedConfig[EModelEndpoint.agents] = {
|
|
...mergedConfig[EModelEndpoint.agents],
|
|
allowedProviders,
|
|
disableBuilder,
|
|
capabilities,
|
|
};
|
|
}
|
|
|
|
if (
|
|
mergedConfig[EModelEndpoint.azureAssistants] &&
|
|
appConfig?.endpoints?.[EModelEndpoint.azureAssistants]
|
|
) {
|
|
const { disableBuilder, retrievalModels, capabilities, version, ..._rest } =
|
|
appConfig.endpoints[EModelEndpoint.azureAssistants];
|
|
|
|
mergedConfig[EModelEndpoint.azureAssistants] = {
|
|
...mergedConfig[EModelEndpoint.azureAssistants],
|
|
version,
|
|
retrievalModels,
|
|
disableBuilder,
|
|
capabilities,
|
|
};
|
|
}
|
|
|
|
if (mergedConfig[EModelEndpoint.bedrock] && appConfig?.endpoints?.[EModelEndpoint.bedrock]) {
|
|
const { availableRegions } = appConfig.endpoints[EModelEndpoint.bedrock];
|
|
mergedConfig[EModelEndpoint.bedrock] = {
|
|
...mergedConfig[EModelEndpoint.bedrock],
|
|
availableRegions,
|
|
};
|
|
}
|
|
|
|
const endpointsConfig = orderEndpointsConfig(mergedConfig);
|
|
|
|
await cache.set(CacheKeys.ENDPOINT_CONFIG, endpointsConfig);
|
|
return endpointsConfig;
|
|
}
|
|
|
|
/**
|
|
* @param {ServerRequest} req
|
|
* @param {import('librechat-data-provider').AgentCapabilities} capability
|
|
* @returns {Promise<boolean>}
|
|
*/
|
|
const checkCapability = async (req, capability) => {
|
|
const isAgents = isAgentsEndpoint(req.body?.endpointType || req.body?.endpoint);
|
|
const endpointsConfig = await getEndpointsConfig(req);
|
|
const capabilities =
|
|
isAgents || endpointsConfig?.[EModelEndpoint.agents]?.capabilities != null
|
|
? (endpointsConfig?.[EModelEndpoint.agents]?.capabilities ?? [])
|
|
: defaultAgentCapabilities;
|
|
return capabilities.includes(capability);
|
|
};
|
|
|
|
module.exports = { getEndpointsConfig, checkCapability };
|