mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 19:30:15 +01:00
refactor: streamline endpoint configuration and enhance appConfig usage across services
This commit is contained in:
parent
647b1bbac6
commit
71a14517cd
10 changed files with 103 additions and 107 deletions
43
packages/api/src/app/config.ts
Normal file
43
packages/api/src/app/config.ts
Normal 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);
|
||||
}
|
||||
1
packages/api/src/app/index.ts
Normal file
1
packages/api/src/app/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './config';
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export * from './app';
|
||||
/* MCP */
|
||||
export * from './mcp/MCPManager';
|
||||
export * from './mcp/oauth';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue