fix: improve fallback model names
Shows readable model names when provider data is still loading Centralizes model display fallback logic Covers fallback formatting with tests
This commit is contained in:
@@ -22,6 +22,7 @@ import { isDesktopShell } from '@/lib/desktop';
|
||||
import { getAgentColor } from '@/lib/agentColors';
|
||||
import { useDeviceInfo } from '@/lib/device';
|
||||
import { mergeModelMetadataWithLiveModel } from '@/lib/modelMetadata';
|
||||
import { getModelDisplayName as getSharedModelDisplayName } from '@/lib/modelDisplay';
|
||||
import { getEditModeColors } from '@/lib/permissions/editModeColors';
|
||||
import { cn, fuzzyMatch } from '@/lib/utils';
|
||||
import { useContextStore } from '@/stores/contextStore';
|
||||
@@ -1258,12 +1259,8 @@ export const ModelControls: React.FC<ModelControlsProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const getModelDisplayName = (model: ProviderModel | undefined) => {
|
||||
const name = (typeof model?.name === 'string' ? model.name : (typeof model?.id === 'string' ? model.id : ''));
|
||||
if (name.length > 40) {
|
||||
return name.substring(0, 37) + '...';
|
||||
}
|
||||
return name;
|
||||
const getModelDisplayName = (model: ProviderModel | undefined, fallbackModelId?: string) => {
|
||||
return getSharedModelDisplayName(model, fallbackModelId, { maxLength: 40 });
|
||||
};
|
||||
|
||||
const getProviderDisplayName = () => {
|
||||
@@ -1272,10 +1269,9 @@ export const ModelControls: React.FC<ModelControlsProps> = ({
|
||||
};
|
||||
|
||||
const getCurrentModelDisplayName = () => {
|
||||
if (!currentProviderId || !currentModelId) return 'Not selected';
|
||||
if (models.length === 0) return 'Not selected';
|
||||
if (!currentModelId) return t('chat.modelControls.selectModel');
|
||||
const currentModel = models.find((m: ProviderModel) => m.id === currentModelId);
|
||||
return getModelDisplayName(currentModel);
|
||||
return getModelDisplayName(currentModel, currentModelId) || t('chat.modelControls.selectModel');
|
||||
};
|
||||
|
||||
const currentModelDisplayName = getCurrentModelDisplayName();
|
||||
|
||||
Reference in New Issue
Block a user