mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-09-21 23:55:23 +00:00
* chore: remove all bing code * chore: remove bing code and auto-focus effects * chore: add back escapeRegExp helper function for regex special character handling * chore: remove deprecated fields from settings and conversation schema * fix: ensure default endpoint is set correctly in conversation setup * feat: add disableFocus option to newConversation for improved search behavior
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import type {
|
|
TPreset,
|
|
TConversation,
|
|
EModelEndpoint,
|
|
TEndpointsConfig,
|
|
} from 'librechat-data-provider';
|
|
import { getLocalStorageItems } from './localStorage';
|
|
import { mapEndpoints } from './endpoints';
|
|
|
|
type TConvoSetup = Partial<TPreset> | Partial<TConversation>;
|
|
|
|
type TDefaultEndpoint = { convoSetup: TConvoSetup; endpointsConfig: TEndpointsConfig };
|
|
|
|
const getEndpointFromSetup = (
|
|
convoSetup: TConvoSetup | null,
|
|
endpointsConfig: TEndpointsConfig,
|
|
): EModelEndpoint | null => {
|
|
let { endpoint: targetEndpoint = '' } = convoSetup || {};
|
|
targetEndpoint = targetEndpoint ?? '';
|
|
if (targetEndpoint && endpointsConfig?.[targetEndpoint]) {
|
|
return targetEndpoint as EModelEndpoint;
|
|
} else if (targetEndpoint) {
|
|
console.warn(`Illegal target endpoint ${targetEndpoint} ${endpointsConfig}`);
|
|
}
|
|
return null;
|
|
};
|
|
|
|
const getEndpointFromLocalStorage = (endpointsConfig: TEndpointsConfig) => {
|
|
try {
|
|
const { lastConversationSetup } = getLocalStorageItems();
|
|
const { endpoint } = lastConversationSetup ?? { endpoint: null };
|
|
const isDefaultConfig = Object.values(endpointsConfig ?? {}).every((value) => !value);
|
|
|
|
if (isDefaultConfig && endpoint) {
|
|
return endpoint;
|
|
}
|
|
|
|
if (isDefaultConfig && endpoint) {
|
|
return endpoint;
|
|
}
|
|
|
|
return endpoint && endpointsConfig?.[endpoint] != null ? endpoint : null;
|
|
} catch (error) {
|
|
console.error(error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
const getDefinedEndpoint = (endpointsConfig: TEndpointsConfig) => {
|
|
const endpoints = mapEndpoints(endpointsConfig);
|
|
return endpoints.find((e) => Object.hasOwn(endpointsConfig ?? {}, e));
|
|
};
|
|
|
|
const getDefaultEndpoint = ({
|
|
convoSetup,
|
|
endpointsConfig,
|
|
}: TDefaultEndpoint): EModelEndpoint | undefined => {
|
|
return (
|
|
getEndpointFromSetup(convoSetup, endpointsConfig) ||
|
|
getEndpointFromLocalStorage(endpointsConfig) ||
|
|
getDefinedEndpoint(endpointsConfig)
|
|
);
|
|
};
|
|
|
|
export default getDefaultEndpoint;
|