refactor: remove getCustomConfig usage and use app config in file citations

This commit is contained in:
Danny Avila 2025-08-18 13:17:31 -04:00
parent 46f9c90223
commit 8525c8df36
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
4 changed files with 29 additions and 30 deletions

View file

@ -1,7 +1,6 @@
const appConfig = require('./app');
const { config } = require('./EndpointService');
const getCachedTools = require('./getCachedTools');
const getCustomConfig = require('./getCustomConfig');
const loadCustomConfig = require('./loadCustomConfig');
const loadConfigModels = require('./loadConfigModels');
const loadDefaultModels = require('./loadDefaultModels');
@ -18,6 +17,5 @@ module.exports = {
loadAsyncEndpoints,
...appConfig,
...getCachedTools,
...getCustomConfig,
...getEndpointsConfig,
};

View file

@ -1,6 +1,5 @@
const { isUserProvided, normalizeEndpointName } = require('@librechat/api');
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
const { getCustomConfig } = require('./getCustomConfig');
const { getAppConfig } = require('./app');
/**
@ -9,19 +8,15 @@ const { getAppConfig } = require('./app');
* @returns {Promise<TEndpointsConfig>} A promise that resolves to an object containing the endpoints configuration
*/
async function loadConfigEndpoints(req) {
const customConfig = await getCustomConfig();
if (!customConfig) {
const appConfig = await getAppConfig({ role: req.user?.role });
if (!appConfig) {
return {};
}
const appConfig = await getAppConfig({ role: req.user?.role });
const { endpoints = {} } = customConfig ?? {};
const endpointsConfig = {};
if (Array.isArray(endpoints[EModelEndpoint.custom])) {
const customEndpoints = endpoints[EModelEndpoint.custom].filter(
if (Array.isArray(appConfig[EModelEndpoint.custom])) {
const customEndpoints = appConfig[EModelEndpoint.custom].filter(
(endpoint) =>
endpoint.baseURL &&
endpoint.apiKey &&

View file

@ -1,9 +1,15 @@
const { nanoid } = require('nanoid');
const { checkAccess } = require('@librechat/api');
const { Tools, PermissionTypes, Permissions } = require('librechat-data-provider');
const { getCustomConfig } = require('~/server/services/Config/getCustomConfig');
const { logger } = require('@librechat/data-schemas');
const {
Tools,
Permissions,
FileSources,
EModelEndpoint,
PermissionTypes,
} = require('librechat-data-provider');
const { getAppConfig } = require('~/server/services/Config/app');
const { getRoleByName } = require('~/models/Role');
const { logger } = require('~/config');
const { Files } = require('~/models');
/**
@ -44,10 +50,10 @@ async function processFileCitations({ user, toolArtifact, toolCallId, metadata }
}
}
const customConfig = await getCustomConfig();
const maxCitations = customConfig?.endpoints?.agents?.maxCitations ?? 30;
const maxCitationsPerFile = customConfig?.endpoints?.agents?.maxCitationsPerFile ?? 5;
const minRelevanceScore = customConfig?.endpoints?.agents?.minRelevanceScore ?? 0.45;
const appConfig = await getAppConfig({ role: user?.role });
const maxCitations = appConfig?.[EModelEndpoint.agents]?.maxCitations ?? 30;
const maxCitationsPerFile = appConfig?.[EModelEndpoint.agents]?.maxCitationsPerFile ?? 5;
const minRelevanceScore = appConfig?.[EModelEndpoint.agents]?.minRelevanceScore ?? 0.45;
const sources = toolArtifact[Tools.file_search].sources || [];
const filteredSources = sources.filter((source) => source.relevance >= minRelevanceScore);
@ -59,7 +65,7 @@ async function processFileCitations({ user, toolArtifact, toolCallId, metadata }
}
const selectedSources = applyCitationLimits(filteredSources, maxCitations, maxCitationsPerFile);
const enhancedSources = await enhanceSourcesWithMetadata(selectedSources, customConfig);
const enhancedSources = await enhanceSourcesWithMetadata(selectedSources, appConfig);
if (enhancedSources.length > 0) {
const fileSearchAttachment = {
@ -110,10 +116,10 @@ function applyCitationLimits(sources, maxCitations, maxCitationsPerFile) {
/**
* Enhance sources with file metadata from database
* @param {Array} sources - Selected sources
* @param {Object} customConfig - Custom configuration
* @param {AppConfig} appConfig - Custom configuration
* @returns {Promise<Array>} Enhanced sources
*/
async function enhanceSourcesWithMetadata(sources, customConfig) {
async function enhanceSourcesWithMetadata(sources, appConfig) {
const fileIds = [...new Set(sources.map((source) => source.fileId))];
let fileMetadataMap = {};
@ -129,7 +135,7 @@ async function enhanceSourcesWithMetadata(sources, customConfig) {
return sources.map((source) => {
const fileRecord = fileMetadataMap[source.fileId] || {};
const configuredStorageType = fileRecord.source || customConfig?.fileStrategy || 'local';
const configuredStorageType = fileRecord.source || appConfig?.fileStrategy || FileSources.local;
return {
...source,

View file

@ -20,17 +20,17 @@ jest.mock('@librechat/api', () => ({
checkAccess: jest.fn().mockResolvedValue(true),
}));
jest.mock('~/server/services/Config/getCustomConfig', () => ({
getCustomConfig: jest.fn().mockResolvedValue({
endpoints: {
agents: {
maxCitations: 30,
maxCitationsPerFile: 5,
minRelevanceScore: 0.45,
},
jest.mock('~/cache/getLogStores', () => () => ({
get: jest.fn().mockResolvedValue({
agents: {
maxCitations: 30,
maxCitationsPerFile: 5,
minRelevanceScore: 0.45,
},
fileStrategy: 'local',
}),
set: jest.fn(),
delete: jest.fn(),
}));
jest.mock('~/config', () => ({