LibreChat/client/src/utils/presets.ts
Danny Avila b45ff8e4ed
🏷️ refactor: EditPresetDialog UI and Remove chatGptLabel from Presets (#7543)
* fix: add necessary dep., remove unnecessary dep from useMentions memoization

* fix: Migrate deprecated chatGptLabel to modelLabel in cleanupPreset and simplify getPresetTitle logic

* fix: Enhance cleanupPreset to remove empty chatGptLabel and add comprehensive tests for label migration and preset handling

* chore: Update endpointType prop in PopoverButtons to allow null values for better flexibility

* refactor: Replace Dialog with OGDialog in EditPresetDialog for improved UI consistency and structure

* style: Update EditPresetDialog layout and styling for improved responsiveness and consistency
2025-05-24 19:24:42 -04:00

84 lines
2 KiB
TypeScript

import type { TPreset, TPlugin } from 'librechat-data-provider';
import { EModelEndpoint } from 'librechat-data-provider';
type TEndpoints = Array<string | EModelEndpoint>;
export const getPresetTitle = (preset: TPreset, mention?: boolean) => {
const {
endpoint,
title: presetTitle,
model,
tools,
promptPrefix,
chatGptLabel,
modelLabel,
} = preset;
const modelInfo = model ?? '';
let title = '';
let label = '';
if (modelLabel) {
label = modelLabel;
}
if (
label &&
presetTitle != null &&
presetTitle &&
label.toLowerCase().includes(presetTitle.toLowerCase())
) {
title = label + ': ';
label = '';
} else if (presetTitle != null && presetTitle && presetTitle.trim() !== 'New Chat') {
title = presetTitle + ': ';
}
if (mention === true) {
return `${modelInfo}${label ? ` | ${label}` : ''}${
promptPrefix != null && promptPrefix ? ` | ${promptPrefix}` : ''
}${
tools
? ` | ${tools
.map((tool: TPlugin | string) => {
if (typeof tool === 'string') {
return tool;
}
return tool.pluginKey;
})
.join(', ')}`
: ''
}`;
}
return `${title}${modelInfo}${label ? ` (${label})` : ''}`.trim();
};
/** Remove unavailable tools from the preset */
export const removeUnavailableTools = (
preset: TPreset,
availableTools: Record<string, TPlugin | undefined>,
) => {
const newPreset = { ...preset };
if (newPreset.tools && newPreset.tools.length > 0) {
newPreset.tools = newPreset.tools
.filter((tool) => {
let pluginKey: string;
if (typeof tool === 'string') {
pluginKey = tool;
} else {
({ pluginKey } = tool);
}
return !!availableTools[pluginKey];
})
.map((tool) => {
if (typeof tool === 'string') {
return tool;
}
return tool.pluginKey;
});
}
return newPreset;
};