mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-09 12:08:50 +01:00
🧹 chore: Remove Deprecated BingAI Code & Address Mobile Focus (#5565)
* 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
This commit is contained in:
parent
1226f56d0c
commit
19fa4d9f54
52 changed files with 52 additions and 1384 deletions
|
|
@ -256,18 +256,12 @@ export function storeEndpointSettings(conversation: TConversation | null) {
|
|||
if (!conversation) {
|
||||
return;
|
||||
}
|
||||
const { endpoint, model, agentOptions, jailbreak, toneStyle } = conversation;
|
||||
const { endpoint, model, agentOptions } = conversation;
|
||||
|
||||
if (!endpoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (endpoint === EModelEndpoint.bingAI) {
|
||||
const settings = { jailbreak, toneStyle };
|
||||
localStorage.setItem(LocalStorageKeys.LAST_BING, JSON.stringify(settings));
|
||||
return;
|
||||
}
|
||||
|
||||
const lastModel = JSON.parse(localStorage.getItem(LocalStorageKeys.LAST_MODEL) ?? '{}');
|
||||
lastModel[endpoint] = model;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,10 +26,6 @@ describe('getEndpointField', () => {
|
|||
expect(getEndpointField(mockEndpointsConfig, undefined, 'type')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined if the endpoint does not exist in endpointsConfig', () => {
|
||||
expect(getEndpointField(mockEndpointsConfig, EModelEndpoint.bingAI, 'type')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns the correct value for a valid endpoint and property', () => {
|
||||
expect(getEndpointField(mockEndpointsConfig, EModelEndpoint.openAI, 'order')).toEqual(0);
|
||||
expect(getEndpointField(mockEndpointsConfig, EModelEndpoint.google, 'iconURL')).toEqual(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import type {
|
||||
TConversation,
|
||||
TPreset,
|
||||
TEndpointsConfig,
|
||||
TConversation,
|
||||
EModelEndpoint,
|
||||
TEndpointsConfig,
|
||||
} from 'librechat-data-provider';
|
||||
import { getLocalStorageItems } from './localStorage';
|
||||
import { mapEndpoints } from './endpoints';
|
||||
|
|
@ -14,11 +14,11 @@ type TDefaultEndpoint = { convoSetup: TConvoSetup; endpointsConfig: TEndpointsCo
|
|||
const getEndpointFromSetup = (
|
||||
convoSetup: TConvoSetup | null,
|
||||
endpointsConfig: TEndpointsConfig,
|
||||
) => {
|
||||
): EModelEndpoint | null => {
|
||||
let { endpoint: targetEndpoint = '' } = convoSetup || {};
|
||||
targetEndpoint = targetEndpoint ?? '';
|
||||
if (targetEndpoint && endpointsConfig?.[targetEndpoint]) {
|
||||
return targetEndpoint;
|
||||
return targetEndpoint as EModelEndpoint;
|
||||
} else if (targetEndpoint) {
|
||||
console.warn(`Illegal target endpoint ${targetEndpoint} ${endpointsConfig}`);
|
||||
}
|
||||
|
|
@ -54,9 +54,9 @@ const getDefinedEndpoint = (endpointsConfig: TEndpointsConfig) => {
|
|||
const getDefaultEndpoint = ({
|
||||
convoSetup,
|
||||
endpointsConfig,
|
||||
}: TDefaultEndpoint): EModelEndpoint | string | undefined => {
|
||||
}: TDefaultEndpoint): EModelEndpoint | undefined => {
|
||||
return (
|
||||
(getEndpointFromSetup(convoSetup, endpointsConfig) ?? '') ||
|
||||
getEndpointFromSetup(convoSetup, endpointsConfig) ||
|
||||
getEndpointFromLocalStorage(endpointsConfig) ||
|
||||
getDefinedEndpoint(endpointsConfig)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ export { default as logger } from './logger';
|
|||
export { default as buildTree } from './buildTree';
|
||||
export { default as getLoginError } from './getLoginError';
|
||||
export { default as cleanupPreset } from './cleanupPreset';
|
||||
export { default as validateIframe } from './validateIframe';
|
||||
export { default as buildDefaultConvo } from './buildDefaultConvo';
|
||||
export { default as getDefaultEndpoint } from './getDefaultEndpoint';
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,9 @@ export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|||
promptPrefix,
|
||||
chatGptLabel,
|
||||
modelLabel,
|
||||
jailbreak,
|
||||
toneStyle,
|
||||
} = preset;
|
||||
const modelInfo = model ?? '';
|
||||
let title = '';
|
||||
let modelInfo = model ?? '';
|
||||
let label = '';
|
||||
|
||||
const usesChatGPTLabel: TEndpoints = [
|
||||
|
|
@ -30,11 +28,7 @@ export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
|
|||
label = chatGptLabel ?? '';
|
||||
} else if (endpoint != null && endpoint && usesModelLabel.includes(endpoint)) {
|
||||
label = modelLabel ?? '';
|
||||
} else if (endpoint === EModelEndpoint.bingAI) {
|
||||
modelInfo = jailbreak === true ? 'Sydney' : modelInfo;
|
||||
label = toneStyle != null && toneStyle ? `: ${toneStyle}` : '';
|
||||
}
|
||||
|
||||
if (
|
||||
label &&
|
||||
presetTitle != null &&
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
export default function validateIframe(content: string): boolean {
|
||||
const hasValidIframe =
|
||||
content.includes('<iframe role="presentation" style="') &&
|
||||
content.includes('src="https://www.bing.com/images/create');
|
||||
|
||||
if (!hasValidIframe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const iframeRegex = /<iframe\s[^>]*?>/g;
|
||||
const iframeMatches = content.match(iframeRegex);
|
||||
|
||||
if (!iframeMatches || iframeMatches.length > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const parser = new DOMParser();
|
||||
const parsedHtml = parser.parseFromString(content, 'text/html');
|
||||
|
||||
const potentiallyHarmfulTags = ['script', 'img', 'style', 'div', 'a', 'input', 'button', 'form'];
|
||||
for (const tag of potentiallyHarmfulTags) {
|
||||
const elements = parsedHtml.getElementsByTagName(tag);
|
||||
|
||||
if (elements.length > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const iframes = parsedHtml.getElementsByTagName('iframe');
|
||||
|
||||
if (iframes.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const iframe = iframes[0];
|
||||
|
||||
// Verify role and src attributes
|
||||
const role = iframe.getAttribute('role');
|
||||
const src = iframe.getAttribute('src');
|
||||
|
||||
return (
|
||||
role === 'presentation' && src != null && src.startsWith('https://www.bing.com/images/create')
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue