2025-11-10 19:05:30 -05:00
|
|
|
import { EModelEndpoint, extractEnvVariable, normalizeEndpointName } from 'librechat-data-provider';
|
2025-08-26 12:10:18 -04:00
|
|
|
import type { TCustomEndpoints, TEndpoint, TConfig } from 'librechat-data-provider';
|
|
|
|
|
import type { TCustomEndpointsConfig } from '~/types/endpoints';
|
2025-11-10 19:05:30 -05:00
|
|
|
import { isUserProvided } from '~/utils';
|
2025-08-26 12:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load config endpoints from the cached configuration object
|
|
|
|
|
* @param customEndpointsConfig - The configuration object
|
|
|
|
|
*/
|
|
|
|
|
export function loadCustomEndpointsConfig(
|
|
|
|
|
customEndpoints?: TCustomEndpoints,
|
|
|
|
|
): TCustomEndpointsConfig | undefined {
|
|
|
|
|
if (!customEndpoints) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const customEndpointsConfig: TCustomEndpointsConfig = {};
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(customEndpoints)) {
|
|
|
|
|
const filteredEndpoints = customEndpoints.filter(
|
|
|
|
|
(endpoint) =>
|
|
|
|
|
endpoint.baseURL &&
|
|
|
|
|
endpoint.apiKey &&
|
|
|
|
|
endpoint.name &&
|
|
|
|
|
endpoint.models &&
|
|
|
|
|
(endpoint.models.fetch || endpoint.models.default),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < filteredEndpoints.length; i++) {
|
|
|
|
|
const endpoint = filteredEndpoints[i] as TEndpoint;
|
|
|
|
|
const {
|
|
|
|
|
baseURL,
|
|
|
|
|
apiKey,
|
|
|
|
|
name: configName,
|
|
|
|
|
iconURL,
|
|
|
|
|
modelDisplayLabel,
|
|
|
|
|
customParams,
|
|
|
|
|
} = endpoint;
|
|
|
|
|
const name = normalizeEndpointName(configName);
|
|
|
|
|
|
|
|
|
|
const resolvedApiKey = extractEnvVariable(apiKey ?? '');
|
|
|
|
|
const resolvedBaseURL = extractEnvVariable(baseURL ?? '');
|
|
|
|
|
|
|
|
|
|
customEndpointsConfig[name] = {
|
|
|
|
|
type: EModelEndpoint.custom,
|
|
|
|
|
userProvide: isUserProvided(resolvedApiKey),
|
|
|
|
|
userProvideURL: isUserProvided(resolvedBaseURL),
|
|
|
|
|
customParams: customParams as TConfig['customParams'],
|
|
|
|
|
modelDisplayLabel,
|
|
|
|
|
iconURL,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return customEndpointsConfig;
|
|
|
|
|
}
|