"use client"; import { IconAlertTriangle } from "@tabler/icons-react"; import { Progress } from "@kandev/ui/progress"; export type VoiceModelLoadIndicatorProps = { state: "idle" | "loading" | "ready" | "error"; /** 0–1 fraction; clamped before rendering. */ progress: number; modelLabel: string; }; function clampPercent(progress: number): number { if (!Number.isFinite(progress)) return 0; const pct = Math.round(progress * 100); if (pct < 0) return 0; if (pct > 100) return 100; return pct; } export function VoiceModelLoadIndicator({ state, progress, modelLabel, }: VoiceModelLoadIndicatorProps) { if (state === "idle" || state === "ready") return null; const pct = clampPercent(progress); // Single stable role="status" wrapper so AT announces the loading→error // transition (a newly-inserted live region would be silently ignored). // (Radix) already renders its own role="progressbar" — the // wrapper div intentionally has no role to avoid nested progressbar nodes. return (
{state === "error" ? ( <> {modelLabel} failed to load ) : (
Downloading {modelLabel}… {pct}%
)}
); }