refactor: streamline endpoint configuration and enhance appConfig usage across services

This commit is contained in:
Danny Avila 2025-08-19 00:40:26 -04:00
parent 647b1bbac6
commit 71a14517cd
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
10 changed files with 103 additions and 107 deletions

View file

@ -0,0 +1,43 @@
import { EModelEndpoint, removeNullishValues } from 'librechat-data-provider';
import type { TCustomConfig, TEndpoint } from 'librechat-data-provider';
import type { AppConfig } from '~/types';
import { isEnabled, normalizeEndpointName } from '~/utils';
/**
* Retrieves the balance configuration object
* */
export function getBalanceConfig(appConfig?: AppConfig): Partial<TCustomConfig['balance']> | null {
const isLegacyEnabled = isEnabled(process.env.CHECK_BALANCE);
const startBalance = process.env.START_BALANCE;
/** @type {} */
const config: Partial<TCustomConfig['balance']> = removeNullishValues({
enabled: isLegacyEnabled,
startBalance: startBalance != null && startBalance ? parseInt(startBalance, 10) : undefined,
});
if (!appConfig) {
return config;
}
return { ...config, ...(appConfig?.['balance'] ?? {}) };
}
export const getCustomEndpointConfig = ({
endpoint,
appConfig,
}: {
endpoint: string | EModelEndpoint;
appConfig?: AppConfig;
}): Partial<TEndpoint> | undefined => {
if (!appConfig) {
throw new Error(`Config not found for the ${endpoint} custom endpoint.`);
}
const customEndpoints = appConfig.endpoints?.[EModelEndpoint.custom] ?? [];
return customEndpoints.find(
(endpointConfig) => normalizeEndpointName(endpointConfig.name) === endpoint,
);
};
export function hasCustomUserVars(appConfig?: AppConfig): boolean {
const mcpServers = appConfig?.mcpConfig;
return Object.values(mcpServers ?? {}).some((server) => server.customUserVars);
}

View file

@ -0,0 +1 @@
export * from './config';

View file

@ -1,3 +1,4 @@
export * from './app';
/* MCP */
export * from './mcp/MCPManager';
export * from './mcp/oauth';