fix(ui): harden provider preset/icon typing

- replace unsafe provider asset/color index lookups with typed helpers

- explicitly type UI preset override map to satisfy ProviderPresetId indexing

- resolves TS7053 failures seen in validate CI after dev merges
This commit is contained in:
Tam Nhu Tran committed 2026-02-20 23:24:11 +07:00
1 parent 14242b5681
commit b3177179b1
2 files changed
+11 -9

No files matched your search

+5 -4
View File
@@ -5,7 +5,7 @@
*/ */
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { PROVIDER_ASSETS, PROVIDER_COLORS } from '@/lib/provider-config'; import { getProviderLogoAsset, PROVIDER_COLORS } from '@/lib/provider-config';
interface ProviderIconProps { interface ProviderIconProps {
provider: string; provider: string;
@@ -22,7 +22,8 @@ export function ProviderIcon({
withBackground = false, withBackground = false,
}: ProviderIconProps) { }: ProviderIconProps) {
const normalized = provider.toLowerCase(); const normalized = provider.toLowerCase();
const assetPath = PROVIDER_ASSETS[normalized]; const assetPath = getProviderLogoAsset(provider);
const providerColor = PROVIDER_COLORS[normalized as keyof typeof PROVIDER_COLORS] || '#6b7280';
// Icon size is smaller when inside background circle // Icon size is smaller when inside background circle
const iconSize = withBackground ? Math.floor(size * 0.65) : size; const iconSize = withBackground ? Math.floor(size * 0.65) : size;
@@ -40,7 +41,7 @@ export function ProviderIcon({
<span <span
className="font-bold" className="font-bold"
style={{ style={{
color: PROVIDER_COLORS[normalized] || '#6b7280', color: providerColor,
fontSize: iconSize * 0.6, fontSize: iconSize * 0.6,
}} }}
> >
@@ -75,7 +76,7 @@ export function ProviderIcon({
); );
} }
const bgColor = PROVIDER_COLORS[normalized] || '#6b7280'; const bgColor = providerColor;
return ( return (
<div <div
className={cn( className={cn(
+6 -5
View File
@@ -23,11 +23,12 @@ export type ProviderPreset = ProviderPresetDefinition;
*/ */
type UiPresetOverride = Pick<ProviderPreset, 'apiKeyPlaceholder'>; type UiPresetOverride = Pick<ProviderPreset, 'apiKeyPlaceholder'>;
const UI_PRESET_OVERRIDES = Object.freeze({ const UI_PRESET_OVERRIDES: Readonly<Partial<Record<ProviderPresetId, UiPresetOverride>>> =
ollama: { Object.freeze({
apiKeyPlaceholder: '', ollama: {
}, apiKeyPlaceholder: '',
}) satisfies Readonly<Partial<Record<ProviderPresetId, UiPresetOverride>>>; },
});
function withUiOverrides(preset: ProviderPresetDefinition): ProviderPreset { function withUiOverrides(preset: ProviderPresetDefinition): ProviderPreset {
const overrides = UI_PRESET_OVERRIDES[preset.id]; const overrides = UI_PRESET_OVERRIDES[preset.id];