mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-27 12:46:13 +01:00
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
|
|
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);
|
||
|
|
}
|