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:
Bohdan Triapitsyn
2026-06-09 00:01:38 +03:00
parent e6338e5c71
commit 25da8493fe
8 changed files with 341 additions and 42 deletions
@@ -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();