Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: reuse model picker for transcription models, consolidate a lot of reusbale code between provider and model picking

Gabriel Steinf483ed463479
diff --git a/src/assets/icons/providers/nvidia.svg b/src/assets/icons/providers/nvidia.svg
new file mode 100644
index 000000000..130a7bcaa
--- /dev/null
+++ b/src/assets/icons/providers/nvidia.svg
@@ -0,0 +1,22 @@
+<svg version="1.1" id="Layer_1" xmlns:x="ns_extend;" xmlns:i="ns_ai;" xmlns:graph="ns_graphs;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 163.3 108" style="enable-background:new 0 0 163.3 108;" xml:space="preserve">
+ <style type="text/css">
+ .st0{fill:#76B900;}
+ </style>
+ <metadata>
+ <sfw xmlns="ns_sfw;">
+ <slices>
+ </slices>
+ <sliceSourceBounds bottomLeftOrigin="true" height="108" width="163.3" x="-331" y="-210.3">
+ </sliceSourceBounds>
+ </sfw>
+ </metadata>
+ <g>
+ <path class="st0" d="M60.9,32.2v-9.7c1-0.1,1.9-0.1,2.9-0.1c26.7-0.8,44.2,23,44.2,23S89.1,71.5,68.8,71.5c-2.7,0-5.3-0.4-7.9-1.3
+ V40.7c10.4,1.3,12.5,5.8,18.7,16.2l13.9-11.7c0,0-10.2-13.3-27.2-13.3C64.5,31.9,62.7,32,60.9,32.2 M60.9,0v14.5l2.9-0.2
+ c37.1-1.3,61.3,30.4,61.3,30.4S97.3,78.6,68.4,78.6c-2.5,0-5-0.2-7.5-0.7v9c2,0.2,4.1,0.4,6.2,0.4c26.9,0,46.4-13.8,65.3-30
+ c3.1,2.5,15.9,8.6,18.6,11.2c-17.9,15-59.7,27.1-83.4,27.1c-2.3,0-4.4-0.1-6.6-0.4V108h102.3V0C163.3,0,60.9,0,60.9,0z M60.9,70.3
+ v7.7C36,73.5,29.1,47.6,29.1,47.6s12-13.2,31.8-15.4v8.4h-0.1c-10.4-1.3-18.6,8.5-18.6,8.5S46.9,65.5,60.9,70.3 M16.7,46.5
+ c0,0,14.7-21.8,44.2-24v-7.9C28.2,17.2,0,44.8,0,44.8s16,46.3,60.9,50.5v-8.4C27.9,82.8,16.7,46.5,16.7,46.5z">
+ </path>
+ </g>
+</svg>
\ No newline at end of file
diff --git a/src/components/LocalModelPicker.tsx b/src/components/LocalModelPicker.tsx
new file mode 100644
index 000000000..ccccb0ac5
--- /dev/null
+++ b/src/components/LocalModelPicker.tsx
@@ -0,0 +1,264 @@
+import { useState, useEffect, useCallback, useMemo } from 'react';
+import { Button } from './ui/button';
+import { RefreshCw, Download, Trash2, Check } from 'lucide-react';
+import { ProviderIcon } from './ui/ProviderIcon';
+import { ProviderTabs } from './ui/ProviderTabs';
+import DownloadProgressBar from './ui/DownloadProgressBar';
+import { useDialogs } from '../hooks/useDialogs';
+import { useModelDownload, type ModelType } from '../hooks/useModelDownload';
+import { MODEL_PICKER_COLORS } from '../utils/modelPickerStyles';
+
+type PickerColorScheme = 'purple' | 'indigo';
+
+export interface LocalModel {
+ id: string;
+ name: string;
+ size: string;
+ sizeBytes?: number;
+ description: string;
+ isDownloaded?: boolean;
+ downloaded?: boolean;
+ recommended?: boolean;
+}
+
+export interface LocalProvider {
+ id: string;
+ name: string;
+ models: LocalModel[];
+}
+
+interface LocalModelPickerProps {
+ providers: LocalProvider[];
+ selectedModel: string;
+ selectedProvider: string;
+ onModelSelect: (modelId: string) => void;
+ onProviderSelect: (providerId: string) => void;
+ modelType: ModelType;
+ colorScheme?: PickerColorScheme;
+ className?: string;
+ onDownloadComplete?: () => void;
+}
+
+export default function LocalModelPicker({
+ providers,
+ selectedModel,
+ selectedProvider,
+ onModelSelect,
+ onProviderSelect,
+ modelType,
+ colorScheme = 'purple',
+ className = '',
+ onDownloadComplete,
+}: LocalModelPickerProps) {
+ const [downloadedModels, setDownloadedModels] = useState<Set<string>>(new Set());
+ const [loadingModels, setLoadingModels] = useState(false);
+
+ const { showConfirmDialog } = useDialogs();
+ const styles = useMemo(() => MODEL_PICKER_COLORS[colorScheme], [colorScheme]);
+
+ const loadDownloadedModels = useCallback(async () => {
+ setLoadingModels(true);
+ try {
+ let downloaded = new Set<string>();
+ if (modelType === 'whisper') {
+ const result = await window.electronAPI?.listWhisperModels();
+ if (result?.success) {
+ downloaded = new Set(
+ result.models.filter((m: { downloaded?: boolean }) => m.downloaded).map((m: { model: string }) => m.model)
+ );
+ }
+ } else {
+ const result = await window.electronAPI?.modelGetAll?.();
+ if (result && Array.isArray(result)) {
+ downloaded = new Set(
+ result.filter((m: { isDownloaded?: boolean }) => m.isDownloaded).map((m: { id: string }) => m.id)
+ );
+ }
+ }
+ setDownloadedModels(downloaded);
+ return downloaded;
+ } catch (error) {
+ console.error('Failed to load downloaded models:', error);
+ return new Set<string>();
+ } finally {
+ setLoadingModels(false);
+ }
+ }, [modelType]);
+
+ useEffect(() => {
+ const initAndValidate = async () => {
+ const downloaded = await loadDownloadedModels();
+ if (selectedModel && !downloaded.has(selectedModel)) {
+ onModelSelect('');
+ }
+ };
+ initAndValidate();
+ }, [loadDownloadedModels, selectedModel, onModelSelect]);
+
+ const handleDownloadComplete = useCallback(() => {
+ loadDownloadedModels();
+ onDownloadComplete?.();
+ }, [loadDownloadedModels, onDownloadComplete]);
+
+ const {
+ downloadingModel,
+ downloadProgress,
+ downloadModel,
+ deleteModel,
+ isDownloadingModel,
+ } = useModelDownload({
+ modelType,
+ onDownloadComplete: handleDownloadComplete,
+ onModelsCleared: loadDownloadedModels,
+ });
+
+ const handleDownload = useCallback((modelId: string) => {
+ downloadModel(modelId, onModelSelect);
+ }, [downloadModel, onModelSelect]);
+
+ const handleDelete = useCallback((modelId: string) => {
+ showConfirmDialog({
+ title: 'Delete Model',
+ description: "Are you sure you want to delete this model? You'll need to re-download it if you want to use it again.",
+ onConfirm: () => deleteModel(modelId, loadDownloadedModels),
+ variant: 'destructive',
+ });
+ }, [showConfirmDialog, deleteModel, loadDownloadedModels]);
+
+ const currentProvider = providers.find(p => p.id === selectedProvider);
+ const models = currentProvider?.models || [];
+
+ const progressDisplay = useMemo(() => {
+ if (!downloadingModel) return null;
+
+ const modelName = models.find(m => m.id === downloadingModel)?.name || downloadingModel;
+
+ return (
+ <DownloadProgressBar
+ modelName={modelName}
+ progress={downloadProgress}
+ styles={styles}
+ />
+ );
+ }, [downloadingModel, downloadProgress, models, styles]);
+
+ return (
+ <div className={`${styles.container} ${className}`}>
+ <ProviderTabs
+ providers={providers}
+ selectedId={selectedProvider}
+ onSelect={onProviderSelect}
+ colorScheme={colorScheme}
+ scrollable
+ />
+
+ {progressDisplay}
+
+ <div className="p-4">
+ <div className="flex items-center justify-between mb-3">
+ <h5 className={styles.header}>Available Models</h5>
+ <Button
+ onClick={loadDownloadedModels}
+ variant="outline"
+ size="sm"
+ disabled={loadingModels}
+ className={styles.buttons.refresh}
+ >
+ <RefreshCw size={14} className={loadingModels ? 'animate-spin' : ''} />
+ <span className="ml-1">{loadingModels ? 'Checking...' : 'Refresh'}</span>
+ </Button>
+ </div>
+
+ <div className="space-y-2">
+ {models.length === 0 ? (
+ <p className="text-sm text-gray-500">No models available for this provider</p>
+ ) : (
+ models.map((model) => {
+ const isSelected = model.id === selectedModel;
+ const isDownloading = isDownloadingModel(model.id);
+ const isDownloaded = downloadedModels.has(model.id) || model.isDownloaded || model.downloaded;
+
+ return (
+ <div
+ key={model.id}
+ className={`p-3 rounded-lg border-2 transition-all ${
+ isSelected ? styles.modelCard.selected : styles.modelCard.default
+ }`}
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex-1">
+ <div className="flex items-center gap-2">
+ <ProviderIcon provider={selectedProvider} className="w-4 h-4" />
+ <span className="font-medium text-gray-900">{model.name}</span>
+ {isSelected && (
+ <span className={styles.badges.selected}>✓ Selected</span>
+ )}
+ {model.recommended && (
+ <span className={styles.badges.recommended}>
+ Recommended
+ </span>
+ )}
+ </div>
+ <div className="text-xs text-gray-600 mt-1">{model.description}</div>
+ <div className="flex items-center gap-2 mt-1">
+ <span className="text-xs text-gray-500">Size: {model.size}</span>
+ {isDownloaded && (
+ <span className={styles.badges.downloaded}>
+ <Check className="inline w-3 h-3 mr-1" />
+ Downloaded
+ </span>
+ )}
+ </div>
+ </div>
+
+ <div className="flex gap-2">
+ {isDownloaded ? (
+ <>
+ {!isSelected && (
+ <Button
+ onClick={() => onModelSelect(model.id)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.select}
+ >
+ Select
+ </Button>
+ )}
+ <Button
+ onClick={() => handleDelete(model.id)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.delete}
+ >
+ <Trash2 size={14} />
+ <span className="ml-1">Delete</span>
+ </Button>
+ </>
+ ) : (
+ <Button
+ onClick={() => handleDownload(model.id)}
+ size="sm"
+ disabled={isDownloading}
+ className={styles.buttons.download}
+ >
+ {isDownloading ? (
+ `${Math.round(downloadProgress.percentage)}%`
+ ) : (
+ <>
+ <Download size={14} />
+ <span className="ml-1">Download</span>
+ </>
+ )}
+ </Button>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+ })
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/src/components/LocalWhisperPicker.tsx b/src/components/LocalWhisperPicker.tsx
new file mode 100644
index 000000000..135875c11
--- /dev/null
+++ b/src/components/LocalWhisperPicker.tsx
@@ -0,0 +1,201 @@
+import { useState, useEffect, useCallback, useMemo } from 'react';
+import { Button } from './ui/button';
+import { RefreshCw, Download, Trash2, Check } from 'lucide-react';
+import { ProviderIcon } from './ui/ProviderIcon';
+import DownloadProgressBar from './ui/DownloadProgressBar';
+import { useDialogs } from '../hooks/useDialogs';
+import { useModelDownload } from '../hooks/useModelDownload';
+import { WHISPER_MODEL_INFO } from '../models/ModelRegistry';
+import { MODEL_PICKER_COLORS, type ColorScheme } from '../utils/modelPickerStyles';
+
+interface WhisperModel {
+ model: string;
+ size_mb?: number;
+ downloaded?: boolean;
+}
+
+interface LocalWhisperPickerProps {
+ selectedModel: string;
+ onModelSelect: (modelId: string) => void;
+ className?: string;
+ variant?: 'onboarding' | 'settings';
+}
+
+export default function LocalWhisperPicker({
+ selectedModel,
+ onModelSelect,
+ className = '',
+ variant = 'settings',
+}: LocalWhisperPickerProps) {
+ const [models, setModels] = useState<WhisperModel[]>([]);
+ const [loadingModels, setLoadingModels] = useState(false);
+
+ const { showConfirmDialog } = useDialogs();
+ const colorScheme: ColorScheme = variant === 'settings' ? 'purple' : 'blue';
+ const styles = useMemo(() => MODEL_PICKER_COLORS[colorScheme], [colorScheme]);
+
+ const loadModels = useCallback(async () => {
+ try {
+ setLoadingModels(true);
+ const result = await window.electronAPI?.listWhisperModels();
+ if (result?.success) {
+ setModels(result.models);
+ }
+ } catch (error) {
+ console.error('[LocalWhisperPicker] Failed to load models:', error);
+ setModels([]);
+ } finally {
+ setLoadingModels(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ loadModels();
+ }, [loadModels]);
+
+ const {
+ downloadingModel,
+ downloadProgress,
+ downloadModel,
+ deleteModel,
+ isDownloadingModel,
+ } = useModelDownload({
+ modelType: 'whisper',
+ onDownloadComplete: loadModels,
+ onModelsCleared: loadModels,
+ });
+
+ const handleDelete = useCallback((modelId: string) => {
+ showConfirmDialog({
+ title: 'Delete Model',
+ description: "Are you sure you want to delete this model? You'll need to re-download it if you want to use it again.",
+ onConfirm: () => deleteModel(modelId, loadModels),
+ variant: 'destructive',
+ });
+ }, [showConfirmDialog, deleteModel, loadModels]);
+
+ const progressDisplay = useMemo(() => {
+ if (!downloadingModel) return null;
+
+ const modelInfo = WHISPER_MODEL_INFO[downloadingModel];
+ const modelName = modelInfo?.name || downloadingModel;
+
+ return (
+ <DownloadProgressBar
+ modelName={modelName}
+ progress={downloadProgress}
+ styles={styles}
+ />
+ );
+ }, [downloadingModel, downloadProgress, styles]);
+
+ return (
+ <div className={`${styles.container} ${className}`}>
+ {progressDisplay}
+
+ <div className="p-4">
+ <div className="flex items-center justify-between mb-3">
+ <h5 className={styles.header}>Whisper Models</h5>
+ <Button
+ onClick={loadModels}
+ variant="outline"
+ size="sm"
+ disabled={loadingModels}
+ className={styles.buttons.refresh}
+ >
+ <RefreshCw size={14} className={loadingModels ? 'animate-spin' : ''} />
+ <span className="ml-1">{loadingModels ? 'Checking...' : 'Refresh'}</span>
+ </Button>
+ </div>
+
+ <div className="space-y-2">
+ {models.map((model) => {
+ const modelId = model.model;
+ const info = WHISPER_MODEL_INFO[modelId] || { name: modelId, description: 'Model', size: 'Unknown' };
+ const isSelected = modelId === selectedModel;
+ const isDownloading = isDownloadingModel(modelId);
+ const isDownloaded = model.downloaded;
+
+ return (
+ <div
+ key={modelId}
+ className={`p-3 rounded-lg border-2 transition-all ${
+ isSelected ? styles.modelCard.selected : styles.modelCard.default
+ }`}
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex-1">
+ <div className="flex items-center gap-2">
+ <ProviderIcon provider="whisper" className="w-4 h-4" />
+ <span className="font-medium text-gray-900">{info.name}</span>
+ {isSelected && (
+ <span className={styles.badges.selected}>✓ Selected</span>
+ )}
+ {info.recommended && (
+ <span className={styles.badges.recommended}>
+ Recommended
+ </span>
+ )}
+ </div>
+ <div className="flex items-center gap-2 mt-1">
+ <span className="text-xs text-gray-600">{info.description}</span>
+ <span className="text-xs text-gray-500">• {model.size_mb ? `${model.size_mb}MB` : info.size}</span>
+ {isDownloaded && (
+ <span className={styles.badges.downloaded}>
+ <Check className="inline w-3 h-3 mr-1" />
+ Downloaded
+ </span>
+ )}
+ </div>
+ </div>
+
+ <div className="flex gap-2">
+ {isDownloaded ? (
+ <>
+ {!isSelected && (
+ <Button
+ onClick={() => onModelSelect(modelId)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.select}
+ >
+ Select
+ </Button>
+ )}
+ <Button
+ onClick={() => handleDelete(modelId)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.delete}
+ >
+ <Trash2 size={14} />
+ <span className="ml-1">Delete</span>
+ </Button>
+ </>
+ ) : (
+ <Button
+ onClick={() => downloadModel(modelId, onModelSelect)}
+ size="sm"
+ disabled={isDownloading}
+ className={styles.buttons.download}
+ >
+ {isDownloading ? (
+ `${Math.round(downloadProgress.percentage)}%`
+ ) : (
+ <>
+ <Download size={14} />
+ <span className="ml-1">Download</span>
+ </>
+ )}
+ </Button>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index 5cb136b97..c52ea7403 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -20,7 +20,7 @@ import {
User,
} from "lucide-react";
import TitleBar from "./TitleBar";
-import WhisperModelPicker from "./WhisperModelPicker";
+import LocalWhisperPicker from "./LocalWhisperPicker";
import ProcessingModeSelector from "./ui/ProcessingModeSelector";
import ApiKeyInput from "./ui/ApiKeyInput";
import PermissionCard from "./ui/PermissionCard";
@@ -36,7 +36,7 @@ import { useSettings } from "../hooks/useSettings";
import { getLanguageLabel } from "../utils/languages";
import { REASONING_PROVIDERS } from "../models/ModelRegistry";
import LanguageSelector from "./ui/LanguageSelector";
-import { UnifiedModelPickerCompact } from "./UnifiedModelPicker";
+import ModelCardList from "./ui/ModelCardList";
const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
import { setAgentName as saveAgentName } from "../utils/agentName";
import { formatHotkeyLabel } from "../utils/hotkeys";
@@ -701,7 +701,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
</p>
</div>
- <WhisperModelPicker
+ <LocalWhisperPicker
selectedModel={whisperModel}
onModelSelect={setWhisperModel}
variant="onboarding"
@@ -791,7 +791,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
Using OpenAI defaults from <code>{reasoningModelsEndpoint}</code>.
</p>
)}
- <UnifiedModelPickerCompact
+ <ModelCardList
models={displayedReasoningModels}
selectedModel={reasoningModel}
onModelSelect={(modelId) =>
diff --git a/src/components/AIModelSelectorEnhanced.tsx b/src/components/ReasoningModelSelector.tsx
similarity index 62%
rename from src/components/AIModelSelectorEnhanced.tsx
rename to src/components/ReasoningModelSelector.tsx
index 20b04ce18..32fd5828b 100644
--- a/src/components/AIModelSelectorEnhanced.tsx
+++ b/src/components/ReasoningModelSelector.tsx
@@ -1,10 +1,10 @@
-import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
+import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import { Button } from './ui/button';
import { Input } from './ui/input';
-import { Cloud, Lock, Download, Check } from 'lucide-react';
+import { Cloud, Lock } from 'lucide-react';
import ApiKeyInput from './ui/ApiKeyInput';
-import { UnifiedModelPickerCompact } from './UnifiedModelPicker';
-import { ProviderIcon } from './ui/ProviderIcon';
+import ModelCardList from './ui/ModelCardList';
+import LocalModelPicker, { type LocalProvider } from './LocalModelPicker';
import { ProviderTabs } from './ui/ProviderTabs';
import { API_ENDPOINTS, buildApiUrl, normalizeBaseUrl } from '../config/constants';
import { REASONING_PROVIDERS } from '../models/ModelRegistry';
@@ -57,7 +57,7 @@ const resolveOwnedByIcon = (ownedBy?: string): string | undefined => {
return undefined;
};
-interface AIModelSelectorEnhancedProps {
+interface ReasoningModelSelectorProps {
useReasoningModel: boolean;
setUseReasoningModel: (value: boolean) => void;
reasoningModel: string;
@@ -74,11 +74,10 @@ interface AIModelSelectorEnhancedProps {
setGeminiApiKey: (key: string) => void;
groqApiKey: string;
setGroqApiKey: (key: string) => void;
- pasteFromClipboard: (setter: (value: string) => void) => void;
showAlertDialog: (dialog: { title: string; description: string }) => void;
}
-export default function AIModelSelectorEnhanced({
+export default function ReasoningModelSelector({
useReasoningModel,
setUseReasoningModel,
reasoningModel,
@@ -95,14 +94,10 @@ export default function AIModelSelectorEnhanced({
setGeminiApiKey,
groqApiKey,
setGroqApiKey,
- pasteFromClipboard,
- showAlertDialog,
-}: AIModelSelectorEnhancedProps) {
+}: ReasoningModelSelectorProps) {
const [selectedMode, setSelectedMode] = useState<'cloud' | 'local'>('cloud');
const [selectedCloudProvider, setSelectedCloudProvider] = useState('openai');
const [selectedLocalProvider, setSelectedLocalProvider] = useState('qwen');
- const [downloadedModels, setDownloadedModels] = useState<Set<string>>(new Set());
- const [downloadingModel, setDownloadingModel] = useState<string | null>(null);
const [customModelOptions, setCustomModelOptions] = useState<CloudModelOption[]>([]);
const [customModelsLoading, setCustomModelsLoading] = useState(false);
const [customModelsError, setCustomModelsError] = useState<string | null>(null);
@@ -116,6 +111,7 @@ export default function AIModelSelectorEnhanced({
isMountedRef.current = false;
};
}, []);
+
useEffect(() => {
setCustomBaseInput(cloudReasoningBaseUrl);
}, [cloudReasoningBaseUrl]);
@@ -126,6 +122,7 @@ export default function AIModelSelectorEnhanced({
[cloudReasoningBaseUrl]
);
const latestReasoningBaseRef = useRef(normalizedCustomReasoningBase);
+
useEffect(() => {
latestReasoningBaseRef.current = normalizedCustomReasoningBase;
}, [normalizedCustomReasoningBase]);
@@ -149,13 +146,8 @@ export default function AIModelSelectorEnhanced({
return;
}
- if (!force && lastLoadedBaseRef.current === normalizedBase) {
- return;
- }
-
- if (!force && pendingBaseRef.current === normalizedBase) {
- return;
- }
+ if (!force && lastLoadedBaseRef.current === normalizedBase) return;
+ if (!force && pendingBaseRef.current === normalizedBase) return;
if (baseOverride !== undefined) {
latestReasoningBaseRef.current = normalizedBase;
@@ -186,7 +178,6 @@ export default function AIModelSelectorEnhanced({
return;
}
- // Security: Only allow HTTPS endpoints (except localhost for development)
const isLocalhost = normalizedBase.includes('://localhost') || normalizedBase.includes('://127.0.0.1');
if (!normalizedBase.startsWith('https://') && !isLocalhost) {
if (isMountedRef.current && latestReasoningBaseRef.current === normalizedBase) {
@@ -202,11 +193,7 @@ export default function AIModelSelectorEnhanced({
}
const modelsUrl = buildApiUrl(normalizedBase, '/models');
-
- const response = await fetch(modelsUrl, {
- method: 'GET',
- headers,
- });
+ const response = await fetch(modelsUrl, { method: 'GET', headers });
if (!response.ok) {
const errorText = await response.text().catch(() => '');
@@ -217,26 +204,22 @@ export default function AIModelSelectorEnhanced({
}
const payload = await response.json().catch(() => ({}));
-
const rawModels = Array.isArray(payload?.data)
? payload.data
: Array.isArray(payload?.models)
? payload.models
: [];
- const mappedModels = (rawModels as Array<any>)
+ const mappedModels = (rawModels as Array<Record<string, unknown>>)
.map((item) => {
- const value = item?.id || item?.name;
- if (!value) {
- return null;
- }
+ const value = (item?.id || item?.name) as string | undefined;
+ if (!value) return null;
const ownedBy = typeof item?.owned_by === 'string' ? item.owned_by : undefined;
const icon = resolveOwnedByIcon(ownedBy);
return {
value,
- label: item?.id || item?.name || value,
- description:
- item?.description || (ownedBy ? `Owner: ${ownedBy}` : undefined),
+ label: (item?.id || item?.name || value) as string,
+ description: (item?.description as string) || (ownedBy ? `Owner: ${ownedBy}` : undefined),
icon,
ownedBy,
} as CloudModelOption;
@@ -250,15 +233,14 @@ export default function AIModelSelectorEnhanced({
mappedModels.length > 0 &&
!mappedModels.some((model) => model.value === reasoningModel)
) {
- setReasoningModel("");
+ setReasoningModel('');
}
setCustomModelsError(null);
lastLoadedBaseRef.current = normalizedBase;
}
} catch (error) {
if (isMountedRef.current && latestReasoningBaseRef.current === normalizedBase) {
- const message =
- (error as Error).message || 'Unable to load models from endpoint.';
+ const message = (error as Error).message || 'Unable to load models from endpoint.';
const unauthorized = /\b(401|403)\b/.test(message);
if (unauthorized && !apiKey) {
setCustomModelsError(
@@ -280,14 +262,13 @@ export default function AIModelSelectorEnhanced({
},
[cloudReasoningBaseUrl, openaiApiKey, reasoningModel, setReasoningModel]
);
+
const trimmedCustomBase = customBaseInput.trim();
const hasSavedCustomBase = Boolean((cloudReasoningBaseUrl || '').trim());
- const isCustomBaseDirty =
- trimmedCustomBase !== (cloudReasoningBaseUrl || '').trim();
+ const isCustomBaseDirty = trimmedCustomBase !== (cloudReasoningBaseUrl || '').trim();
+
const displayedCustomModels = useMemo<CloudModelOption[]>(() => {
- if (isCustomBaseDirty) {
- return [];
- }
+ if (isCustomBaseDirty) return [];
return customModelOptions;
}, [isCustomBaseDirty, customModelOptions]);
@@ -296,11 +277,21 @@ export default function AIModelSelectorEnhanced({
id,
name: id === 'custom' ? 'Custom' : REASONING_PROVIDERS[id as keyof typeof REASONING_PROVIDERS]?.name || id,
}));
- const localProviderIds = modelRegistry.getAllProviders().map((p) => p.id);
- const localProviders = localProviderIds.map(id => {
- const provider = modelRegistry.getProvider(id);
- return { id, name: provider?.name || id };
- });
+
+ const localProviders = useMemo<LocalProvider[]>(() => {
+ return modelRegistry.getAllProviders().map((provider) => ({
+ id: provider.id,
+ name: provider.name,
+ models: provider.models.map((model) => ({
+ id: model.id,
+ name: model.name,
+ size: model.size,
+ sizeBytes: model.sizeBytes,
+ description: model.description,
+ recommended: model.recommended,
+ })),
+ }));
+ }, []);
const openaiModelOptions = useMemo<CloudModelOption[]>(() => {
const iconPath = getProviderIconPath('openai');
@@ -311,25 +302,18 @@ export default function AIModelSelectorEnhanced({
}, []);
const selectedCloudModels = useMemo<CloudModelOption[]>(() => {
- if (selectedCloudProvider === 'openai') {
- return openaiModelOptions;
- }
-
- if (selectedCloudProvider === 'custom') {
- return displayedCustomModels;
- }
+ if (selectedCloudProvider === 'openai') return openaiModelOptions;
+ if (selectedCloudProvider === 'custom') return displayedCustomModels;
const provider = REASONING_PROVIDERS[selectedCloudProvider as keyof typeof REASONING_PROVIDERS];
- if (!provider?.models) {
- return [];
- }
+ if (!provider?.models) return [];
const iconPath = getProviderIconPath(selectedCloudProvider);
return provider.models.map((model) => ({
...model,
icon: iconPath,
}));
- }, [selectedCloudProvider, openaiModelOptions, customModelOptions]);
+ }, [selectedCloudProvider, openaiModelOptions, displayedCustomModels]);
const handleApplyCustomBase = useCallback(() => {
const trimmedBase = customBaseInput.trim();
@@ -337,7 +321,7 @@ export default function AIModelSelectorEnhanced({
setCloudReasoningBaseUrl(trimmedBase);
lastLoadedBaseRef.current = null;
loadRemoteModels(trimmedBase, true);
- }, [customBaseInput, setCustomBaseInput, setCloudReasoningBaseUrl, loadRemoteModels]);
+ }, [customBaseInput, setCloudReasoningBaseUrl, loadRemoteModels]);
const handleResetCustomBase = useCallback(() => {
const defaultBase = API_ENDPOINTS.OPENAI_BASE;
@@ -345,40 +329,30 @@ export default function AIModelSelectorEnhanced({
setCloudReasoningBaseUrl(defaultBase);
lastLoadedBaseRef.current = null;
loadRemoteModels(defaultBase, true);
- }, [setCustomBaseInput, setCloudReasoningBaseUrl, loadRemoteModels]);
+ }, [setCloudReasoningBaseUrl, loadRemoteModels]);
const handleRefreshCustomModels = useCallback(() => {
if (isCustomBaseDirty) {
handleApplyCustomBase();
return;
}
-
- if (!trimmedCustomBase) {
- return;
- }
-
+ if (!trimmedCustomBase) return;
loadRemoteModels(undefined, true);
}, [handleApplyCustomBase, isCustomBaseDirty, trimmedCustomBase, loadRemoteModels]);
- // Initialize based on current provider
useEffect(() => {
- if (localProviders.includes(localReasoningProvider)) {
+ const localProviderIds = localProviders.map(p => p.id);
+ if (localProviderIds.includes(localReasoningProvider)) {
setSelectedMode('local');
setSelectedLocalProvider(localReasoningProvider);
- } else if (cloudProviders.includes(localReasoningProvider)) {
+ } else if (cloudProviderIds.includes(localReasoningProvider)) {
setSelectedMode('cloud');
setSelectedCloudProvider(localReasoningProvider);
}
-
- // Check downloaded models
- checkDownloadedModels();
- }, []);
-
- useEffect(() => {
- if (selectedCloudProvider !== 'custom') {
- return;
- }
+ }, [localProviders, localReasoningProvider]);
+ useEffect(() => {
+ if (selectedCloudProvider !== 'custom') return;
if (!hasCustomBase) {
setCustomModelsError(null);
setCustomModelOptions([]);
@@ -388,49 +362,38 @@ export default function AIModelSelectorEnhanced({
}
const normalizedBase = normalizedCustomReasoningBase;
- if (!normalizedBase) {
- return;
- }
-
- if (pendingBaseRef.current === normalizedBase || lastLoadedBaseRef.current === normalizedBase) {
- return;
- }
+ if (!normalizedBase) return;
+ if (pendingBaseRef.current === normalizedBase || lastLoadedBaseRef.current === normalizedBase) return;
loadRemoteModels();
}, [selectedCloudProvider, hasCustomBase, normalizedCustomReasoningBase, loadRemoteModels]);
- // Check which models are downloaded
- const checkDownloadedModels = async () => {
+ const [downloadedModels, setDownloadedModels] = useState<Set<string>>(new Set());
+
+ const loadDownloadedModels = useCallback(async () => {
try {
const result = await window.electronAPI?.modelGetAll?.();
if (result && Array.isArray(result)) {
- const downloaded = new Set(result.filter(m => m.isDownloaded).map(m => m.id));
+ const downloaded = new Set(
+ result.filter((m: { isDownloaded?: boolean }) => m.isDownloaded).map((m: { id: string }) => m.id)
+ );
setDownloadedModels(downloaded);
+ return downloaded;
}
} catch (error) {
- console.error('Failed to check downloaded models:', error);
+ console.error('Failed to load downloaded models:', error);
}
- };
-
- // Handle model download with minimal code
- const downloadModel = async (modelId: string) => {
- setDownloadingModel(modelId);
- try {
- await window.electronAPI?.modelDownload?.(modelId);
- setDownloadedModels(prev => new Set([...prev, modelId]));
- if (!reasoningModel) setReasoningModel(modelId);
- } catch (error) {
- console.error('Download failed:', error);
- } finally {
- setDownloadingModel(null);
- }
- };
+ return new Set<string>();
+ }, []);
+
+ useEffect(() => {
+ loadDownloadedModels();
+ }, [loadDownloadedModels]);
const handleModeChange = async (newMode: 'cloud' | 'local') => {
setSelectedMode(newMode);
-
+
if (newMode === 'cloud') {
- // Switch to cloud mode
setLocalReasoningProvider(selectedCloudProvider);
if (selectedCloudProvider === 'custom') {
@@ -451,11 +414,17 @@ export default function AIModelSelectorEnhanced({
setReasoningModel(provider.models[0].value);
}
} else {
- // Switch to local mode
setLocalReasoningProvider(selectedLocalProvider);
- const provider = modelRegistry.getProvider(selectedLocalProvider);
- if (provider?.models?.length > 0) {
- setReasoningModel(provider.models[0].id);
+ const downloaded = await loadDownloadedModels();
+ const provider = localProviders.find(p => p.id === selectedLocalProvider);
+ const models = provider?.models ?? [];
+ if (models.length > 0) {
+ const firstDownloaded = models.find(m => downloaded.has(m.id));
+ if (firstDownloaded) {
+ setReasoningModel(firstDownloaded.id);
+ } else {
+ setReasoningModel('');
+ }
}
}
};
@@ -463,8 +432,7 @@ export default function AIModelSelectorEnhanced({
const handleCloudProviderChange = (provider: string) => {
setSelectedCloudProvider(provider);
setLocalReasoningProvider(provider);
-
- // Update model to first available
+
if (provider === 'custom') {
setCustomBaseInput(cloudReasoningBaseUrl);
lastLoadedBaseRef.current = null;
@@ -484,34 +452,24 @@ export default function AIModelSelectorEnhanced({
}
};
- const handleLocalProviderChange = (provider: string) => {
- setSelectedLocalProvider(provider);
- setLocalReasoningProvider(provider);
- // Update model to first available
- const providerData = modelRegistry.getProvider(provider);
- if (providerData?.models?.length > 0) {
- setReasoningModel(providerData.models[0].id);
+ const handleLocalProviderChange = async (providerId: string) => {
+ setSelectedLocalProvider(providerId);
+ setLocalReasoningProvider(providerId);
+ const downloaded = await loadDownloadedModels();
+ const provider = localProviders.find(p => p.id === providerId);
+ const models = provider?.models ?? [];
+ if (models.length > 0) {
+ const firstDownloaded = models.find(m => downloaded.has(m.id));
+ if (firstDownloaded) {
+ setReasoningModel(firstDownloaded.id);
+ } else {
+ setReasoningModel('');
+ }
}
};
- const getProviderColor = (provider: string) => {
- const colors: Record<string, string> = {
- 'openai': 'green',
- 'anthropic': 'purple',
- 'gemini': 'blue',
- 'groq': 'orange', // Fast and fiery like Groq
- 'qwen': 'indigo',
- 'mistral': 'orange',
- 'llama': 'blue',
- 'openai-oss': 'teal',
- 'custom': 'cyan'
- };
- return colors[provider] || 'gray';
- };
-
return (
<div className="space-y-6">
- {/* Enable/Disable Toggle */}
<div className="flex items-center justify-between p-4 bg-green-50 border border-green-200 rounded-xl">
<div>
<label className="text-sm font-medium text-green-800">
@@ -529,10 +487,10 @@ export default function AIModelSelectorEnhanced({
onChange={(e) => setUseReasoningModel(e.target.checked)}
/>
<div className={`w-11 h-6 bg-gray-200 rounded-full transition-colors duration-200 ${
- useReasoningModel ? "bg-green-600" : "bg-gray-300"
+ useReasoningModel ? 'bg-green-600' : 'bg-gray-300'
}`}>
<div className={`absolute top-0.5 left-0.5 bg-white border border-gray-300 rounded-full h-5 w-5 transition-transform duration-200 ${
- useReasoningModel ? "translate-x-5" : "translate-x-0"
+ useReasoningModel ? 'translate-x-5' : 'translate-x-0'
}`} />
</div>
</label>
@@ -540,14 +498,13 @@ export default function AIModelSelectorEnhanced({
{useReasoningModel && (
<>
- {/* Cloud vs Local Selection */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
<button
onClick={() => handleModeChange('cloud')}
className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
selectedMode === 'cloud'
- ? "border-indigo-500 bg-indigo-50"
- : "border-neutral-200 bg-white hover:border-neutral-300"
+ ? 'border-indigo-500 bg-indigo-50'
+ : 'border-neutral-200 bg-white hover:border-neutral-300'
}`}
>
<div className="flex items-center justify-between mb-2">
@@ -568,8 +525,8 @@ export default function AIModelSelectorEnhanced({
onClick={() => handleModeChange('local')}
className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
selectedMode === 'local'
- ? "border-indigo-500 bg-indigo-50"
- : "border-neutral-200 bg-white hover:border-neutral-300"
+ ? 'border-indigo-500 bg-indigo-50'
+ : 'border-neutral-200 bg-white hover:border-neutral-300'
}`}
>
<div className="flex items-center justify-between mb-2">
@@ -587,10 +544,8 @@ export default function AIModelSelectorEnhanced({
</button>
</div>
- {/* Provider Content */}
{selectedMode === 'cloud' ? (
<div className="space-y-4">
- {/* Cloud Provider Tabs */}
<div className="border border-gray-200 rounded-xl overflow-hidden">
<ProviderTabs
providers={cloudProviders}
@@ -600,7 +555,6 @@ export default function AIModelSelectorEnhanced({
/>
<div className="p-4">
- {/* Use UnifiedModelPickerCompact for cloud models */}
{selectedCloudProvider === 'custom' ? (
<>
<div className="space-y-3">
@@ -650,9 +604,7 @@ export default function AIModelSelectorEnhanced({
<div className="space-y-3 pt-4 border-t border-gray-200">
<h4 className="text-sm font-medium text-gray-700">Available Models</h4>
{!hasCustomBase && (
- <p className="text-xs text-amber-600">
- Enter a base URL to load models.
- </p>
+ <p className="text-xs text-amber-600">Enter a base URL to load models.</p>
)}
{hasCustomBase && (
<>
@@ -663,13 +615,11 @@ export default function AIModelSelectorEnhanced({
<p className="text-xs text-red-600">{customModelsError}</p>
)}
{!customModelsLoading && !customModelsError && customModelOptions.length === 0 && (
- <p className="text-xs text-amber-600">
- No models returned by this endpoint.
- </p>
+ <p className="text-xs text-amber-600">No models returned by this endpoint.</p>
)}
</>
)}
- <UnifiedModelPickerCompact
+ <ModelCardList
models={selectedCloudModels}
selectedModel={reasoningModel}
onModelSelect={setReasoningModel}
@@ -680,14 +630,13 @@ export default function AIModelSelectorEnhanced({
<>
<div className="space-y-3">
<h4 className="text-sm font-medium text-gray-700">Select Model</h4>
- <UnifiedModelPickerCompact
+ <ModelCardList
models={selectedCloudModels}
selectedModel={reasoningModel}
onModelSelect={setReasoningModel}
/>
</div>
- {/* API Key Configuration */}
<div className="mt-4 pt-4 border-t border-gray-200">
{selectedCloudProvider === 'openai' && (
<div className="space-y-3">
@@ -697,7 +646,7 @@ export default function AIModelSelectorEnhanced({
setApiKey={setOpenaiApiKey}
helpText={
<>
- Need an API key?{" "}
+ Need an API key?{' '}
<a
href="https://platform.openai.com"
target="_blank"
@@ -715,75 +664,72 @@ export default function AIModelSelectorEnhanced({
{selectedCloudProvider === 'anthropic' && (
<div className="space-y-3">
<h4 className="font-medium text-gray-900">API Configuration</h4>
- <div className="flex gap-2">
- <Input
- type="password"
- placeholder="sk-ant-..."
- value={anthropicApiKey}
- onChange={(e) => setAnthropicApiKey(e.target.value)}
- className="flex-1 text-sm"
- />
- <Button
- variant="outline"
- size="sm"
- onClick={() => pasteFromClipboard(setAnthropicApiKey)}
- >
- Paste
- </Button>
- </div>
- <p className="text-xs text-gray-600">
- Get your API key from console.anthropic.com
- </p>
+ <ApiKeyInput
+ apiKey={anthropicApiKey}
+ setApiKey={setAnthropicApiKey}
+ placeholder="sk-ant-..."
+ helpText={
+ <>
+ Need an API key?{' '}
+ <a
+ href="https://console.anthropic.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ console.anthropic.com
+ </a>
+ </>
+ }
+ />
</div>
)}
{selectedCloudProvider === 'gemini' && (
<div className="space-y-3">
<h4 className="font-medium text-gray-900">API Configuration</h4>
- <div className="flex gap-2">
- <Input
- type="password"
- placeholder="AIza..."
- value={geminiApiKey}
- onChange={(e) => setGeminiApiKey(e.target.value)}
- className="flex-1 text-sm"
- />
- <Button
- variant="outline"
- size="sm"
- onClick={() => pasteFromClipboard(setGeminiApiKey)}
- >
- Paste
- </Button>
- </div>
- <p className="text-xs text-gray-600">
- Get your API key from makersuite.google.com/app/apikey
- </p>
+ <ApiKeyInput
+ apiKey={geminiApiKey}
+ setApiKey={setGeminiApiKey}
+ placeholder="AIza..."
+ helpText={
+ <>
+ Need an API key?{' '}
+ <a
+ href="https://makersuite.google.com/app/apikey"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ makersuite.google.com
+ </a>
+ </>
+ }
+ />
</div>
)}
{selectedCloudProvider === 'groq' && (
<div className="space-y-3">
<h4 className="font-medium text-gray-900">API Configuration</h4>
- <div className="flex gap-2">
- <Input
- type="password"
- placeholder="gsk_..."
- value={groqApiKey}
- onChange={(e) => setGroqApiKey(e.target.value)}
- className="flex-1 text-sm"
- />
- <Button
- variant="outline"
- size="sm"
- onClick={() => pasteFromClipboard(setGroqApiKey)}
- >
- Paste
- </Button>
- </div>
- <p className="text-xs text-gray-600">
- Get your API key from console.groq.com
- </p>
+ <ApiKeyInput
+ apiKey={groqApiKey}
+ setApiKey={setGroqApiKey}
+ placeholder="gsk_..."
+ helpText={
+ <>
+ Need an API key?{' '}
+ <a
+ href="https://console.groq.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ console.groq.com
+ </a>
+ </>
+ }
+ />
</div>
)}
</div>
@@ -793,105 +739,16 @@ export default function AIModelSelectorEnhanced({
</div>
</div>
) : (
- <div className="space-y-4">
- {/* Local Provider Tabs */}
- <div className="border border-gray-200 rounded-xl overflow-hidden">
- <ProviderTabs
- providers={localProviders}
- selectedId={selectedLocalProvider}
- onSelect={handleLocalProviderChange}
- colorScheme="purple"
- scrollable
- />
-
- {/* Local Model List with Download */}
- <div className="p-4">
- <div className="space-y-3">
- <h4 className="text-sm font-medium text-gray-700">Available Models</h4>
- {(() => {
- const provider = modelRegistry.getProvider(selectedLocalProvider);
- if (!provider || !provider.models) {
- return <p className="text-sm text-gray-500">No models available for this provider</p>;
- }
-
- return (
- <div className="space-y-2">
- {provider.models.map((model) => {
- const isDownloaded = downloadedModels.has(model.id);
- const isDownloading = downloadingModel === model.id;
- const isSelected = reasoningModel === model.id;
-
- return (
- <div
- key={model.id}
- className={`p-3 rounded-lg border-2 transition-all ${
- isSelected
- ? 'border-purple-500 bg-purple-50'
- : 'border-gray-200 bg-white hover:border-gray-300'
- }`}
- >
- <div className="flex items-center justify-between">
- <div className="flex-1">
- <div className="flex items-center gap-2">
- <ProviderIcon provider={selectedLocalProvider} className="w-4 h-4" />
- <span className="font-medium text-gray-900">{model.name}</span>
- </div>
- <div className="text-xs text-gray-600 mt-1">{model.description}</div>
- <div className="flex items-center gap-2 mt-1">
- <span className="text-xs text-gray-500">Size: {model.size}</span>
- {isDownloaded && (
- <span className="text-xs text-green-600 bg-green-100 px-2 py-0.5 rounded">
- <Check className="inline w-3 h-3 mr-1" />
- Downloaded
- </span>
- )}
- {model.recommended && (
- <span className="text-xs text-blue-600 bg-blue-100 px-2 py-0.5 rounded">
- Recommended
- </span>
- )}
- </div>
- </div>
- <div className="flex gap-2">
- {isDownloaded ? (
- !isSelected && (
- <Button
- size="sm"
- variant="outline"
- onClick={() => setReasoningModel(model.id)}
- >
- Select
- </Button>
- )
- ) : (
- <Button
- size="sm"
- variant="default"
- disabled={isDownloading}
- onClick={() => downloadModel(model.id)}
- >
- {isDownloading ? (
- <>Downloading...</>
- ) : (
- <>
- <Download className="w-3 h-3 mr-1" />
- Download
- </>
- )}
- </Button>
- )}
- </div>
- </div>
- </div>
- );
- })}
- </div>
- );
- })()}
- </div>
- </div>
- </div>
- </div>
+ <LocalModelPicker
+ providers={localProviders}
+ selectedModel={reasoningModel}
+ selectedProvider={selectedLocalProvider}
+ onModelSelect={setReasoningModel}
+ onProviderSelect={handleLocalProviderChange}
+ modelType="llm"
+ colorScheme="purple"
+ onDownloadComplete={loadDownloadedModels}
+ />
)}
</>
)}
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 0292ec671..dce4eec9c 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -2,35 +2,23 @@ import React, { useState, useCallback, useEffect, useRef } from "react";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { RefreshCw, Download, Keyboard, Mic, Shield } from "lucide-react";
-import { ProviderIcon } from "./ui/ProviderIcon";
-import WhisperModelPicker from "./WhisperModelPicker";
-import ProcessingModeSelector from "./ui/ProcessingModeSelector";
-import ApiKeyInput from "./ui/ApiKeyInput";
+import TranscriptionModelPicker from "./TranscriptionModelPicker";
import { ConfirmDialog, AlertDialog } from "./ui/dialog";
-import { ProviderTabs } from "./ui/ProviderTabs";
import { useSettings } from "../hooks/useSettings";
import { useDialogs } from "../hooks/useDialogs";
import { useAgentName } from "../utils/agentName";
import { useWhisper } from "../hooks/useWhisper";
import { usePermissions } from "../hooks/usePermissions";
import { useClipboard } from "../hooks/useClipboard";
-import { REASONING_PROVIDERS, getTranscriptionProviders, getTranscriptionModels } from "../models/ModelRegistry";
+import { REASONING_PROVIDERS, getTranscriptionProviders } from "../models/ModelRegistry";
import { formatHotkeyLabel } from "../utils/hotkeys";
import LanguageSelector from "./ui/LanguageSelector";
import PromptStudio from "./ui/PromptStudio";
import { API_ENDPOINTS } from "../config/constants";
-import AIModelSelectorEnhanced from "./AIModelSelectorEnhanced";
+import ReasoningModelSelector from "./ReasoningModelSelector";
import type { UpdateInfoResult } from "../types/electron";
const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
-// Custom transcription provider constant
-const CUSTOM_TRANSCRIPTION_PROVIDER = {
- id: 'custom',
- name: 'Custom',
- baseUrl: '',
- models: []
-} as const;
-
export type SettingsSectionType =
| "general"
| "transcription"
@@ -45,7 +33,6 @@ interface SettingsPageProps {
export default function SettingsPage({
activeSection = "general",
}: SettingsPageProps) {
- // Use custom hooks
const {
confirmDialog,
alertDialog,
@@ -97,7 +84,6 @@ export default function SettingsPage({
updateApiKeys,
} = useSettings();
- // Update state
const [currentVersion, setCurrentVersion] = useState<string>("");
const [updateStatus, setUpdateStatus] = useState<{
updateAvailable: boolean;
@@ -125,7 +111,7 @@ export default function SettingsPage({
const whisperHook = useWhisper(showAlertDialog);
const permissionsHook = usePermissions(showAlertDialog);
- const { pasteFromClipboardWithFallback } = useClipboard(showAlertDialog);
+ useClipboard(showAlertDialog);
const { agentName, setAgentName } = useAgentName();
const installTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -217,17 +203,14 @@ export default function SettingsPage({
};
}, [showAlertDialog]);
- // Local state for provider selection (overrides computed value)
const [localReasoningProvider, setLocalReasoningProvider] = useState(() => {
return localStorage.getItem("reasoningProvider") || reasoningProvider;
});
- // Defer heavy operations for better performance
useEffect(() => {
let mounted = true;
let unsubscribeUpdates;
- // Defer version and update checks to improve initial render
const timer = setTimeout(async () => {
if (!mounted) return;
@@ -256,7 +239,6 @@ export default function SettingsPage({
unsubscribeUpdates = subscribeToUpdates();
- // Check whisper after initial render
if (mounted) {
whisperHook.checkWhisperInstallation();
}
@@ -265,7 +247,6 @@ export default function SettingsPage({
return () => {
mounted = false;
clearTimeout(timer);
- // Always clean up update listeners if they exist
unsubscribeUpdates?.();
};
}, [whisperHook, subscribeToUpdates]);
@@ -300,14 +281,12 @@ export default function SettingsPage({
const normalizedReasoningBase = (cloudReasoningBaseUrl || '').trim();
setCloudReasoningBaseUrl(normalizedReasoningBase);
- // Update reasoning settings including the base URL
updateReasoningSettings({
useReasoningModel,
reasoningModel,
cloudReasoningBaseUrl: normalizedReasoningBase
});
- // Save API keys to backend based on provider (including custom)
if ((localReasoningProvider === "openai" || localReasoningProvider === "custom") && openaiApiKey) {
await window.electronAPI?.saveOpenAIKey(openaiApiKey);
}
@@ -321,7 +300,6 @@ export default function SettingsPage({
await window.electronAPI?.saveGroqKey(groqApiKey);
}
- // Update API keys in state (for custom provider, save the API key used)
const keysToSave: Partial<{openaiApiKey: string; anthropicApiKey: string; geminiApiKey: string; groqApiKey: string}> = {};
if ((localReasoningProvider === "openai" || localReasoningProvider === "custom") && openaiApiKey.trim()) {
keysToSave.openaiApiKey = openaiApiKey;
@@ -337,7 +315,6 @@ export default function SettingsPage({
}
updateApiKeys(keysToSave);
- // Save the provider separately since it's computed from the model
localStorage.setItem("reasoningProvider", localReasoningProvider);
const providerLabel =
@@ -372,7 +349,6 @@ export default function SettingsPage({
const saveApiKey = useCallback(async () => {
try {
- // Save all API keys to backend
if (openaiApiKey) {
await window.electronAPI?.saveOpenAIKey(openaiApiKey);
}
@@ -528,7 +504,6 @@ export default function SettingsPage({
case "general":
return (
<div className="space-y-8">
- {/* App Updates Section */}
<div className="space-y-6">
<div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
@@ -741,7 +716,6 @@ export default function SettingsPage({
</div>
</div>
- {/* Hotkey Section */}
<div className="border-t pt-8">
<div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
@@ -793,7 +767,6 @@ export default function SettingsPage({
</div>
</div>
- {/* Permissions Section */}
<div className="border-t pt-8">
<div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
@@ -832,7 +805,6 @@ export default function SettingsPage({
</div>
</div>
- {/* About Section */}
<div className="border-t pt-8">
<div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
@@ -874,7 +846,6 @@ export default function SettingsPage({
</div>
</div>
- {/* System Actions */}
<div className="space-y-3">
<Button
onClick={() => {
@@ -957,177 +928,38 @@ export default function SettingsPage({
return (
<div className="space-y-6">
<div>
- <h3 className="text-lg font-semibold text-gray-900 mb-4">
+ <h3 className="text-lg font-semibold text-gray-900 mb-2">
Speech to Text Processing
</h3>
- <ProcessingModeSelector
- useLocalWhisper={useLocalWhisper}
- setUseLocalWhisper={(value) => {
- setUseLocalWhisper(value);
- updateTranscriptionSettings({ useLocalWhisper: value });
- }}
- />
+ <p className="text-sm text-gray-600 mb-4">
+ Choose a cloud provider for fast transcription or use local Whisper models for complete privacy.
+ </p>
</div>
- {!useLocalWhisper && (
- <div className="space-y-4">
- <h4 className="font-medium text-gray-900">Cloud Transcription Provider</h4>
-
- {/* Provider Tabs */}
- <div className="border border-gray-200 rounded-xl overflow-hidden">
- <ProviderTabs
- providers={[...getTranscriptionProviders(), CUSTOM_TRANSCRIPTION_PROVIDER]}
- selectedId={cloudTranscriptionProvider}
- onSelect={(providerId) => {
- setCloudTranscriptionProvider(providerId);
- if (providerId !== 'custom') {
- const provider = getTranscriptionProviders().find(p => p.id === providerId);
- const models = getTranscriptionModels(providerId);
- setCloudTranscriptionModel(models[0]?.id || '');
- if (provider) {
- setCloudTranscriptionBaseUrl(provider.baseUrl);
- }
- }
- }}
- colorScheme="indigo"
- />
-
- <div className="p-4">
- {cloudTranscriptionProvider === 'custom' ? (
- <>
- {/* Custom Endpoint Settings */}
- <div className="space-y-3">
- <h4 className="font-medium text-gray-900">Endpoint Settings</h4>
- <Input
- value={cloudTranscriptionBaseUrl}
- onChange={(event) => setCloudTranscriptionBaseUrl(event.target.value)}
- placeholder="https://api.openai.com/v1"
- className="text-sm"
- />
- <div className="flex flex-wrap gap-2">
- <Button
- type="button"
- size="sm"
- variant="outline"
- onClick={() => {
- setCloudTranscriptionBaseUrl(API_ENDPOINTS.TRANSCRIPTION_BASE);
- }}
- >
- Reset to Default
- </Button>
- </div>
- <p className="text-xs text-gray-600">
- Use a custom OpenAI-compatible endpoint for transcription.
- </p>
- </div>
-
- <div className="space-y-3 pt-4 border-t border-gray-200">
- <h4 className="font-medium text-gray-900">Authentication</h4>
- <ApiKeyInput
- apiKey={openaiApiKey}
- setApiKey={setOpenaiApiKey}
- helpText="Optional. Added as a Bearer token for your custom endpoint."
- />
- </div>
-
- <div className="space-y-3 pt-4 border-t border-gray-200">
- <h4 className="font-medium text-gray-900">Model Name</h4>
- <Input
- value={cloudTranscriptionModel}
- onChange={(event) => setCloudTranscriptionModel(event.target.value)}
- placeholder="whisper-1"
- className="text-sm"
- />
- <p className="text-xs text-gray-600">
- Enter the model name supported by your custom endpoint.
- </p>
- </div>
- </>
- ) : (
- <>
- {/* Model Selection */}
- <div className="space-y-3">
- <h4 className="text-sm font-medium text-gray-700">Select Model</h4>
- <div className="space-y-2">
- {getTranscriptionModels(cloudTranscriptionProvider).map((model) => {
- const isSelected = cloudTranscriptionModel === model.id;
- return (
- <button
- key={model.id}
- onClick={() => setCloudTranscriptionModel(model.id)}
- className={`w-full p-3 rounded-lg border-2 transition-all text-left ${
- isSelected
- ? 'border-indigo-500 bg-indigo-50'
- : 'border-gray-200 bg-white hover:border-gray-300'
- }`}
- >
- <div className="flex items-center gap-2">
- <ProviderIcon provider={cloudTranscriptionProvider} className="w-4 h-4" />
- <span className="font-medium text-gray-900">{model.name}</span>
- </div>
- <div className="text-xs text-gray-600 mt-1">{model.description}</div>
- </button>
- );
- })}
- </div>
- </div>
-
- {/* API Key Configuration */}
- <div className="mt-4 pt-4 border-t border-gray-200">
- <div className="space-y-3">
- <h4 className="font-medium text-gray-900">API Configuration</h4>
- <ApiKeyInput
- apiKey={cloudTranscriptionProvider === "groq" ? groqApiKey : openaiApiKey}
- setApiKey={cloudTranscriptionProvider === "groq" ? setGroqApiKey : setOpenaiApiKey}
- helpText={
- cloudTranscriptionProvider === "groq" ? (
- <>
- Need an API key?{" "}
- <a
- href="https://console.groq.com"
- target="_blank"
- rel="noopener noreferrer"
- className="text-blue-600 underline"
- >
- console.groq.com
- </a>
- </>
- ) : (
- <>
- Need an API key?{" "}
- <a
- href="https://platform.openai.com"
- target="_blank"
- rel="noopener noreferrer"
- className="text-blue-600 underline"
- >
- platform.openai.com
- </a>
- </>
- )
- }
- />
- </div>
- </div>
- </>
- )}
- </div>
- </div>
- </div>
- )}
-
- {useLocalWhisper && whisperHook.whisperInstalled && (
- <div className="space-y-4 p-4 bg-purple-50 border border-purple-200 rounded-xl">
- <h4 className="font-medium text-purple-900">
- Local Whisper Model
- </h4>
- <WhisperModelPicker
- selectedModel={whisperModel}
- onModelSelect={setWhisperModel}
- variant="settings"
- />
- </div>
- )}
+ <TranscriptionModelPicker
+ selectedCloudProvider={cloudTranscriptionProvider}
+ onCloudProviderSelect={(providerId) => {
+ setCloudTranscriptionProvider(providerId);
+ const provider = getTranscriptionProviders().find(p => p.id === providerId);
+ if (provider) {
+ setCloudTranscriptionBaseUrl(provider.baseUrl);
+ }
+ }}
+ selectedCloudModel={cloudTranscriptionModel}
+ onCloudModelSelect={setCloudTranscriptionModel}
+ selectedLocalModel={whisperModel}
+ onLocalModelSelect={setWhisperModel}
+ useLocalWhisper={useLocalWhisper}
+ onModeChange={(isLocal) => {
+ setUseLocalWhisper(isLocal);
+ updateTranscriptionSettings({ useLocalWhisper: isLocal });
+ }}
+ openaiApiKey={openaiApiKey}
+ setOpenaiApiKey={setOpenaiApiKey}
+ groqApiKey={groqApiKey}
+ setGroqApiKey={setGroqApiKey}
+ variant="settings"
+ />
<div className="space-y-4 p-4 bg-gray-50 border border-gray-200 rounded-xl">
<h4 className="font-medium text-gray-900">Preferred Language</h4>
@@ -1193,7 +1025,7 @@ export default function SettingsPage({
</p>
</div>
- <AIModelSelectorEnhanced
+ <ReasoningModelSelector
useReasoningModel={useReasoningModel}
setUseReasoningModel={(value) => {
setUseReasoningModel(value);
@@ -1213,7 +1045,6 @@ export default function SettingsPage({
setGeminiApiKey={setGeminiApiKey}
groqApiKey={groqApiKey}
setGroqApiKey={setGroqApiKey}
- pasteFromClipboard={pasteFromClipboardWithFallback}
showAlertDialog={showAlertDialog}
/>
diff --git a/src/components/TranscriptionModelPicker.tsx b/src/components/TranscriptionModelPicker.tsx
new file mode 100644
index 000000000..d1b369558
--- /dev/null
+++ b/src/components/TranscriptionModelPicker.tsx
@@ -0,0 +1,467 @@
+import { useState, useEffect, useCallback, useMemo } from 'react';
+import { Button } from './ui/button';
+import { RefreshCw, Download, Trash2, Check, Cloud, Lock } from 'lucide-react';
+import { ProviderIcon } from './ui/ProviderIcon';
+import { ProviderTabs } from './ui/ProviderTabs';
+import ModelCardList from './ui/ModelCardList';
+import DownloadProgressBar from './ui/DownloadProgressBar';
+import ApiKeyInput from './ui/ApiKeyInput';
+import { useDialogs } from '../hooks/useDialogs';
+import { useModelDownload } from '../hooks/useModelDownload';
+import { getTranscriptionProviders, TranscriptionProviderData, WHISPER_MODEL_INFO } from '../models/ModelRegistry';
+import { MODEL_PICKER_COLORS, type ColorScheme } from '../utils/modelPickerStyles';
+
+interface WhisperModel {
+ model: string;
+ size_mb?: number;
+ downloaded?: boolean;
+}
+
+interface TranscriptionModelPickerProps {
+ selectedCloudProvider: string;
+ onCloudProviderSelect: (providerId: string) => void;
+ selectedCloudModel: string;
+ onCloudModelSelect: (modelId: string) => void;
+ selectedLocalModel: string;
+ onLocalModelSelect: (modelId: string) => void;
+ selectedLocalProvider?: string;
+ onLocalProviderSelect?: (providerId: string) => void;
+ useLocalWhisper: boolean;
+ onModeChange: (useLocal: boolean) => void;
+ openaiApiKey: string;
+ setOpenaiApiKey: (key: string) => void;
+ groqApiKey: string;
+ setGroqApiKey: (key: string) => void;
+ className?: string;
+ variant?: 'onboarding' | 'settings';
+}
+
+const CLOUD_PROVIDER_TABS = [
+ { id: 'openai', name: 'OpenAI' },
+ { id: 'groq', name: 'Groq' },
+];
+
+const VALID_CLOUD_PROVIDER_IDS = CLOUD_PROVIDER_TABS.map(p => p.id);
+
+const LOCAL_PROVIDER_TABS = [
+ { id: 'whisper', name: 'OpenAI Whisper' },
+ { id: 'nvidia', name: 'Nvidia', disabled: true, badge: 'Coming Soon' },
+];
+
+export default function TranscriptionModelPicker({
+ selectedCloudProvider,
+ onCloudProviderSelect,
+ selectedCloudModel,
+ onCloudModelSelect,
+ selectedLocalModel,
+ onLocalModelSelect,
+ selectedLocalProvider = 'whisper',
+ onLocalProviderSelect,
+ useLocalWhisper,
+ onModeChange,
+ openaiApiKey,
+ setOpenaiApiKey,
+ groqApiKey,
+ setGroqApiKey,
+ className = '',
+ variant = 'settings',
+}: TranscriptionModelPickerProps) {
+ const [localModels, setLocalModels] = useState<WhisperModel[]>([]);
+ const [loadingModels, setLoadingModels] = useState(false);
+ const [internalLocalProvider, setInternalLocalProvider] = useState(selectedLocalProvider);
+
+ const { showConfirmDialog } = useDialogs();
+ const colorScheme: ColorScheme = variant === 'settings' ? 'purple' : 'blue';
+ const styles = useMemo(() => MODEL_PICKER_COLORS[colorScheme], [colorScheme]);
+
+ const cloudProviders = useMemo(() => getTranscriptionProviders(), []);
+
+ const loadLocalModels = useCallback(async () => {
+ try {
+ setLoadingModels(true);
+ const result = await window.electronAPI?.listWhisperModels();
+ if (result?.success) {
+ setLocalModels(result.models);
+ }
+ } catch (error) {
+ console.error('[TranscriptionModelPicker] Failed to load models:', error);
+ setLocalModels([]);
+ } finally {
+ setLoadingModels(false);
+ }
+ }, []);
+
+ const ensureValidCloudSelection = useCallback(() => {
+ const isValidProvider = VALID_CLOUD_PROVIDER_IDS.includes(selectedCloudProvider);
+
+ if (!isValidProvider) {
+ const firstProvider = cloudProviders[0];
+ if (firstProvider) {
+ onCloudProviderSelect(firstProvider.id);
+ if (firstProvider.models?.length) {
+ onCloudModelSelect(firstProvider.models[0].id);
+ }
+ }
+ } else if (!selectedCloudModel) {
+ const provider = cloudProviders.find(p => p.id === selectedCloudProvider);
+ if (provider?.models?.length) {
+ onCloudModelSelect(provider.models[0].id);
+ }
+ }
+ }, [cloudProviders, selectedCloudProvider, selectedCloudModel, onCloudProviderSelect, onCloudModelSelect]);
+
+ useEffect(() => {
+ if (useLocalWhisper) {
+ loadLocalModels();
+ } else {
+ ensureValidCloudSelection();
+ }
+ }, [useLocalWhisper, loadLocalModels, ensureValidCloudSelection]);
+
+ useEffect(() => {
+ const handleModelsCleared = () => loadLocalModels();
+ window.addEventListener('openwhispr-models-cleared', handleModelsCleared);
+ return () => window.removeEventListener('openwhispr-models-cleared', handleModelsCleared);
+ }, [loadLocalModels]);
+
+ const {
+ downloadingModel,
+ downloadProgress,
+ downloadModel,
+ deleteModel,
+ isDownloadingModel,
+ } = useModelDownload({
+ modelType: 'whisper',
+ onDownloadComplete: loadLocalModels,
+ });
+
+ const handleModeChange = useCallback((isLocal: boolean) => {
+ onModeChange(isLocal);
+ if (!isLocal) {
+ ensureValidCloudSelection();
+ }
+ }, [onModeChange, ensureValidCloudSelection]);
+
+ const handleCloudProviderChange = useCallback((providerId: string) => {
+ onCloudProviderSelect(providerId);
+ const provider = cloudProviders.find(p => p.id === providerId);
+ if (provider?.models?.length) {
+ onCloudModelSelect(provider.models[0].id);
+ }
+ }, [cloudProviders, onCloudProviderSelect, onCloudModelSelect]);
+
+ const handleLocalProviderChange = useCallback((providerId: string) => {
+ const tab = LOCAL_PROVIDER_TABS.find(t => t.id === providerId);
+ if (tab?.disabled) return;
+
+ setInternalLocalProvider(providerId);
+ onLocalProviderSelect?.(providerId);
+ }, [onLocalProviderSelect]);
+
+ const handleDelete = useCallback((modelId: string) => {
+ showConfirmDialog({
+ title: 'Delete Model',
+ description: "Are you sure you want to delete this model? You'll need to re-download it if you want to use it again.",
+ onConfirm: () => deleteModel(modelId, loadLocalModels),
+ variant: 'destructive',
+ });
+ }, [showConfirmDialog, deleteModel, loadLocalModels]);
+
+ const currentCloudProvider = useMemo<TranscriptionProviderData | undefined>(() => {
+ return cloudProviders.find(p => p.id === selectedCloudProvider);
+ }, [cloudProviders, selectedCloudProvider]);
+
+ const cloudModelOptions = useMemo(() => {
+ if (!currentCloudProvider) return [];
+ return currentCloudProvider.models.map(m => ({
+ value: m.id,
+ label: m.name,
+ description: m.description,
+ icon: `/assets/icons/providers/${selectedCloudProvider}.svg`,
+ }));
+ }, [currentCloudProvider, selectedCloudProvider]);
+
+ const progressDisplay = useMemo(() => {
+ if (!downloadingModel || !useLocalWhisper) return null;
+
+ const modelInfo = WHISPER_MODEL_INFO[downloadingModel];
+ const modelName = modelInfo?.name || downloadingModel;
+
+ return (
+ <DownloadProgressBar
+ modelName={modelName}
+ progress={downloadProgress}
+ styles={styles}
+ />
+ );
+ }, [downloadingModel, downloadProgress, useLocalWhisper, styles]);
+
+ const renderLocalModels = () => {
+ return (
+ <div className="space-y-2">
+ {localModels.map((model) => {
+ const modelId = model.model;
+ const info = WHISPER_MODEL_INFO[modelId] || { name: modelId, description: 'Model', size: 'Unknown' };
+ const isSelected = modelId === selectedLocalModel;
+ const isDownloading = isDownloadingModel(modelId);
+ const isDownloaded = model.downloaded;
+
+ return (
+ <div
+ key={modelId}
+ className={`p-3 rounded-lg border-2 transition-all ${
+ isSelected ? styles.modelCard.selected : styles.modelCard.default
+ }`}
+ >
+ <div className="flex items-center justify-between">
+ <div className="flex-1">
+ <div className="flex items-center gap-2">
+ <ProviderIcon provider="whisper" className="w-4 h-4" />
+ <span className="font-medium text-gray-900">{info.name}</span>
+ {isSelected && (
+ <span className={styles.badges.selected}>✓ Selected</span>
+ )}
+ {info.recommended && (
+ <span className={styles.badges.recommended}>
+ Recommended
+ </span>
+ )}
+ </div>
+ <div className="flex items-center gap-2 mt-1">
+ <span className="text-xs text-gray-600">{info.description}</span>
+ <span className="text-xs text-gray-500">• {model.size_mb ? `${model.size_mb}MB` : info.size}</span>
+ {isDownloaded && (
+ <span className={styles.badges.downloaded}>
+ <Check className="inline w-3 h-3 mr-1" />
+ Downloaded
+ </span>
+ )}
+ </div>
+ </div>
+
+ <div className="flex gap-2">
+ {isDownloaded ? (
+ <>
+ {!isSelected && (
+ <Button
+ onClick={() => onLocalModelSelect(modelId)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.select}
+ >
+ Select
+ </Button>
+ )}
+ <Button
+ onClick={() => handleDelete(modelId)}
+ size="sm"
+ variant="outline"
+ className={styles.buttons.delete}
+ >
+ <Trash2 size={14} />
+ <span className="ml-1">Delete</span>
+ </Button>
+ </>
+ ) : (
+ <Button
+ onClick={() => downloadModel(modelId, onLocalModelSelect)}
+ size="sm"
+ disabled={isDownloading}
+ className={styles.buttons.download}
+ >
+ {isDownloading ? (
+ `${Math.round(downloadProgress.percentage)}%`
+ ) : (
+ <>
+ <Download size={14} />
+ <span className="ml-1">Download</span>
+ </>
+ )}
+ </Button>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ );
+ };
+
+ const renderLocalProviderTab = (provider: typeof LOCAL_PROVIDER_TABS[0], isSelected: boolean) => {
+ const isDisabled = provider.disabled;
+ const tabColorScheme = colorScheme === 'purple' ? 'purple' : 'indigo';
+ const colors = {
+ purple: { text: 'text-purple-700', border: 'rgb(147 51 234)', bg: 'rgb(250 245 255)' },
+ indigo: { text: 'text-indigo-700', border: 'rgb(99 102 241)', bg: 'rgb(238 242 255)' },
+ };
+ const tabColors = colors[tabColorScheme];
+
+ return (
+ <button
+ key={provider.id}
+ onClick={() => !isDisabled && handleLocalProviderChange(provider.id)}
+ className={`flex-1 flex items-center justify-center gap-2 px-4 py-3 font-medium transition-all whitespace-nowrap ${
+ isDisabled
+ ? 'text-gray-600 cursor-default'
+ : isSelected
+ ? `${tabColors.text} border-b-2`
+ : 'text-gray-600 hover:bg-gray-100'
+ }`}
+ style={isSelected && !isDisabled ? { borderBottomColor: tabColors.border, backgroundColor: tabColors.bg } : undefined}
+ >
+ <ProviderIcon provider={provider.id} className="w-5 h-5" />
+ <span>{provider.name}</span>
+ {provider.badge && (
+ <span className="text-xs text-gray-500 bg-gray-100 px-2 py-0.5 rounded-full">
+ {provider.badge}
+ </span>
+ )}
+ </button>
+ );
+ };
+
+ return (
+ <div className={`space-y-4 ${className}`}>
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-3">
+ <button
+ onClick={() => handleModeChange(false)}
+ className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
+ !useLocalWhisper
+ ? 'border-purple-500 bg-purple-50'
+ : 'border-neutral-200 bg-white hover:border-neutral-300'
+ }`}
+ >
+ <div className="flex items-center justify-between mb-2">
+ <div className="flex items-center gap-3">
+ <Cloud className="w-6 h-6 text-blue-600" />
+ <h4 className="font-medium text-neutral-900">Cloud</h4>
+ </div>
+ <span className="text-xs text-green-600 bg-green-100 px-2 py-1 rounded-full">
+ Fast
+ </span>
+ </div>
+ <p className="text-sm text-neutral-600">
+ Transcription via API. Fast and accurate, requires internet.
+ </p>
+ </button>
+
+ <button
+ onClick={() => handleModeChange(true)}
+ className={`p-4 border-2 rounded-xl text-left transition-all cursor-pointer ${
+ useLocalWhisper
+ ? 'border-purple-500 bg-purple-50'
+ : 'border-neutral-200 bg-white hover:border-neutral-300'
+ }`}
+ >
+ <div className="flex items-center justify-between mb-2">
+ <div className="flex items-center gap-3">
+ <Lock className="w-6 h-6 text-purple-600" />
+ <h4 className="font-medium text-neutral-900">Local</h4>
+ </div>
+ <span className="text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full">
+ Private
+ </span>
+ </div>
+ <p className="text-sm text-neutral-600">
+ Runs on your device. Complete privacy, works offline.
+ </p>
+ </button>
+ </div>
+
+ {!useLocalWhisper ? (
+ <div className="space-y-4">
+ <div className={styles.container}>
+ <ProviderTabs
+ providers={CLOUD_PROVIDER_TABS}
+ selectedId={selectedCloudProvider}
+ onSelect={handleCloudProviderChange}
+ colorScheme={colorScheme === 'purple' ? 'purple' : 'indigo'}
+ scrollable
+ />
+
+ <div className="p-4">
+ <div className="space-y-3">
+ <h4 className="text-sm font-medium text-gray-700">Select Model</h4>
+ <ModelCardList
+ models={cloudModelOptions}
+ selectedModel={selectedCloudModel}
+ onModelSelect={onCloudModelSelect}
+ colorScheme={colorScheme === 'purple' ? 'purple' : 'indigo'}
+ />
+ </div>
+
+ <div className="mt-4 pt-4 border-t border-gray-200">
+ <div className="space-y-3">
+ <h4 className="font-medium text-gray-900">API Configuration</h4>
+ <ApiKeyInput
+ apiKey={selectedCloudProvider === 'groq' ? groqApiKey : openaiApiKey}
+ setApiKey={selectedCloudProvider === 'groq' ? setGroqApiKey : setOpenaiApiKey}
+ helpText={
+ selectedCloudProvider === 'groq' ? (
+ <>
+ Need an API key?{' '}
+ <a
+ href="https://console.groq.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ console.groq.com
+ </a>
+ </>
+ ) : (
+ <>
+ Need an API key?{' '}
+ <a
+ href="https://platform.openai.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ platform.openai.com
+ </a>
+ </>
+ )
+ }
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ ) : (
+ <div className={styles.container}>
+ <div className="flex bg-gray-50 border-b border-gray-200">
+ {LOCAL_PROVIDER_TABS.map(provider =>
+ renderLocalProviderTab(provider, internalLocalProvider === provider.id)
+ )}
+ </div>
+
+ {progressDisplay}
+
+ <div className="p-4">
+ <div className="flex items-center justify-between mb-3">
+ <h5 className={styles.header}>Available Models</h5>
+ <Button
+ onClick={loadLocalModels}
+ variant="outline"
+ size="sm"
+ disabled={loadingModels}
+ className={styles.buttons.refresh}
+ >
+ <RefreshCw size={14} className={loadingModels ? 'animate-spin' : ''} />
+ <span className="ml-1">{loadingModels ? 'Checking...' : 'Refresh'}</span>
+ </Button>
+ </div>
+
+ {internalLocalProvider === 'whisper' && renderLocalModels()}
+ {internalLocalProvider === 'nvidia' && (
+ <p className="text-sm text-gray-500">Nvidia GPU acceleration coming soon.</p>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/src/components/UnifiedModelPicker.tsx b/src/components/UnifiedModelPicker.tsx
deleted file mode 100644
index a7d1ac917..000000000
--- a/src/components/UnifiedModelPicker.tsx
+++ /dev/null
@@ -1,562 +0,0 @@
-import { useState, useEffect, useCallback, useMemo } from "react";
-import { Button } from "./ui/button";
-import { Progress } from "./ui/progress";
-import { Alert, AlertDescription } from "./ui/alert";
-import {
- RefreshCw,
- Download,
- Trash2,
- AlertCircle,
- ExternalLink,
- Globe
-} from "lucide-react";
-import { useDialogs } from "../hooks/useDialogs";
-import { useToast } from "./ui/Toast";
-import { formatBytes } from "../utils/formatBytes";
-import "../types/electron";
-
-interface Model {
- id: string;
- name: string;
- model?: string; // For Whisper compatibility
- size: string;
- size_mb?: number;
- sizeBytes?: number;
- description: string;
- downloaded?: boolean;
- isDownloaded?: boolean;
- recommended?: boolean;
- type: 'whisper' | 'llm';
-}
-
-interface DownloadProgress {
- percentage: number;
- downloadedBytes: number;
- totalBytes: number;
- speed?: number;
- eta?: number;
-}
-
-interface UnifiedModelPickerProps {
- selectedModel: string;
- onModelSelect: (modelId: string) => void;
- modelType: 'whisper' | 'llm';
- className?: string;
- variant?: "onboarding" | "settings";
-}
-
-const VARIANT_STYLES = {
- onboarding: {
- container: "bg-gray-50 p-4 rounded-lg",
- progress: "bg-blue-50 border-b border-blue-200",
- progressText: "text-blue-900",
- progressBar: "bg-blue-200",
- progressFill: "bg-gradient-to-r from-blue-500 to-blue-600",
- header: "font-medium text-gray-900 mb-3",
- modelCard: {
- selected: "border-blue-500 bg-blue-50",
- default: "border-gray-200 bg-white hover:border-gray-300",
- },
- badges: {
- selected: "text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full font-medium",
- downloaded: "text-xs text-green-600 bg-green-100 px-2 py-1 rounded",
- },
- buttons: {
- download: "bg-blue-600 hover:bg-blue-700",
- select: "border-gray-300 text-gray-700 hover:bg-gray-50",
- delete: "text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",
- refresh: "border-gray-300 text-gray-700 hover:bg-gray-50",
- },
- },
- settings: {
- container: "bg-white border border-purple-200 rounded-lg overflow-hidden",
- progress: "bg-purple-50 border-b border-purple-200",
- progressText: "text-purple-900",
- progressBar: "bg-purple-200",
- progressFill: "bg-gradient-to-r from-purple-500 to-purple-600",
- header: "font-medium text-purple-900",
- modelCard: {
- selected: "border-purple-500 bg-purple-50",
- default: "border-purple-200 bg-white hover:border-purple-300",
- },
- badges: {
- selected: "text-xs text-purple-600 bg-purple-100 px-2 py-1 rounded-full font-medium",
- downloaded: "text-xs text-emerald-600 bg-emerald-100 px-2 py-1 rounded-md",
- },
- buttons: {
- download: "bg-purple-600 hover:bg-purple-700",
- select: "border-purple-300 text-purple-700 hover:bg-purple-50",
- delete: "text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200",
- refresh: "border-purple-300 text-purple-700 hover:bg-purple-50",
- },
- },
-};
-
-function formatETA(seconds: number): string {
- if (seconds < 60) return `${Math.round(seconds)}s`;
- const minutes = Math.floor(seconds / 60);
- const remainingSeconds = Math.round(seconds % 60);
- return `${minutes}m ${remainingSeconds}s`;
-}
-
-// Export the compact variant for cloud models
-export function UnifiedModelPickerCompact({
- selectedModel,
- onModelSelect,
- models,
- className = "",
-}: {
- selectedModel: string;
- onModelSelect: (modelId: string) => void;
- models: Array<{ value: string; label: string; description?: string; icon?: string }>;
- className?: string;
-}) {
- return (
- <div className={`space-y-2 ${className}`}>
- {models.map((model) => (
- <button
- key={model.value}
- onClick={() => onModelSelect(model.value)}
- className={`w-full p-3 rounded-lg border-2 text-left transition-all ${
- selectedModel === model.value
- ? 'border-indigo-500 bg-indigo-50'
- : 'border-gray-200 bg-white hover:border-gray-300'
- }`}
- >
- <div className="flex items-center justify-between">
- <div>
- <div className="flex items-center gap-2">
- {model.icon ? (
- <img src={model.icon} alt="" className="w-4 h-4" aria-hidden="true" />
- ) : (
- <Globe className="w-4 h-4 text-gray-400" aria-hidden="true" />
- )}
- <span className="font-medium text-gray-900">{model.label}</span>
- </div>
- {model.description && (
- <div className="text-xs text-gray-600 mt-1">{model.description}</div>
- )}
- </div>
- {selectedModel === model.value && (
- <span className="text-xs text-indigo-600 bg-indigo-100 px-2 py-1 rounded-full font-medium">
- ✓ Selected
- </span>
- )}
- </div>
- </button>
- ))}
- </div>
- );
-}
-
-export default function UnifiedModelPicker({
- selectedModel,
- onModelSelect,
- modelType,
- className = "",
- variant = "settings",
-}: UnifiedModelPickerProps) {
- const [models, setModels] = useState<Model[]>([]);
- const [downloadingModel, setDownloadingModel] = useState<string | null>(null);
- const [downloadProgress, setDownloadProgress] = useState<DownloadProgress>({
- percentage: 0,
- downloadedBytes: 0,
- totalBytes: 0,
- });
- const [loadingModels, setLoadingModels] = useState(false);
- const [llamaCppStatus, setLlamaCppStatus] = useState<{
- isInstalled: boolean;
- version?: string;
- checking: boolean;
- }>({ isInstalled: true, checking: false }); // Default to true for now
-
- const {
- showConfirmDialog,
- showAlertDialog,
- } = useDialogs();
- const { toast } = useToast();
- const styles = useMemo(() => VARIANT_STYLES[variant], [variant]);
-
- // Check llama.cpp installation for LLM models
- // Commented out for now - defaulting to installed
- /*
- useEffect(() => {
- if (modelType === 'llm') {
- const checkLlamaCpp = async () => {
- try {
- const result = await window.electronAPI?.llamaCppCheck();
- setLlamaCppStatus({
- isInstalled: result?.isInstalled || false,
- version: result?.version,
- checking: false,
- });
- } catch {
- setLlamaCppStatus({ isInstalled: false, checking: false });
- }
- };
- checkLlamaCpp();
- }
- }, [modelType]);
- */
-
- const loadModels = useCallback(async () => {
- try {
- setLoadingModels(true);
-
- if (modelType === 'whisper') {
- const result = await window.electronAPI.listWhisperModels();
- if (result.success) {
- const whisperModels: Model[] = result.models.map((m: any) => ({
- ...m,
- id: m.model,
- name: m.model.charAt(0).toUpperCase() + m.model.slice(1),
- size: m.size_mb ? `${m.size_mb}MB` : 'Unknown',
- description: {
- tiny: "Fastest, lower quality",
- base: "Good balance (recommended)",
- small: "Better quality, slower",
- medium: "High quality",
- large: "Best quality, slowest",
- turbo: "Fast with good quality"
- }[m.model] || "Model",
- type: 'whisper' as const,
- isDownloaded: m.downloaded,
- recommended: m.model === 'base'
- }));
- setModels(whisperModels);
- }
- } else {
- console.log('[UnifiedModelPicker] Loading LLM models...');
- const result = await window.electronAPI.modelGetAll();
- console.log('[UnifiedModelPicker] Got result:', result);
-
- if (!result || !Array.isArray(result)) {
- console.error('[UnifiedModelPicker] Invalid result format:', result);
- setModels([]);
- return;
- }
-
- const llmModels: Model[] = result.map((m: any) => ({
- ...m,
- type: 'llm' as const,
- downloaded: m.isDownloaded
- }));
- console.log('[UnifiedModelPicker] Mapped models:', llmModels);
- setModels(llmModels);
- }
- } catch (error) {
- console.error("[UnifiedModelPicker] Failed to load models:", error);
- setModels([]);
- } finally {
- setLoadingModels(false);
- }
- }, [modelType]);
-
- useEffect(() => {
- loadModels();
- }, [loadModels]);
-
- useEffect(() => {
- const handleModelsCleared = () => {
- loadModels();
- };
-
- window.addEventListener("openwhispr-models-cleared", handleModelsCleared);
- return () => {
- window.removeEventListener("openwhispr-models-cleared", handleModelsCleared);
- };
- }, [loadModels]);
-
- const handleDownloadProgress = useCallback((_event: any, data: any) => {
- if (modelType === 'whisper') {
- // Whisper progress format
- if (data.type === "progress") {
- const progress: DownloadProgress = {
- percentage: data.percentage || 0,
- downloadedBytes: data.downloaded_bytes || 0,
- totalBytes: data.total_bytes || 0,
- };
-
- if (data.speed_mbps && data.speed_mbps > 0) {
- const remainingBytes = progress.totalBytes - progress.downloadedBytes;
- progress.eta = (remainingBytes * 8) / (data.speed_mbps * 1_000_000);
- progress.speed = data.speed_mbps;
- }
-
- setDownloadProgress(progress);
- } else if (data.type === "complete" || data.type === "error") {
- setDownloadingModel(null);
- setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
- loadModels();
- }
- } else {
- // LLM progress format
- setDownloadProgress({
- percentage: data.progress || 0,
- downloadedBytes: data.downloadedSize || 0,
- totalBytes: data.totalSize || 0,
- });
- }
- }, [modelType, loadModels]);
-
- useEffect(() => {
- const dispose =
- modelType === 'whisper'
- ? window.electronAPI.onWhisperDownloadProgress(handleDownloadProgress)
- : window.electronAPI.onModelDownloadProgress(handleDownloadProgress);
-
- return () => {
- dispose?.();
- };
- }, [handleDownloadProgress, modelType]);
-
- const downloadModel = useCallback(async (modelId: string) => {
- try {
- setDownloadingModel(modelId);
- setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
- onModelSelect(modelId);
-
- if (modelType === 'whisper') {
- const result = await window.electronAPI.downloadWhisperModel(modelId);
- if (!result.success && !result.error?.includes("interrupted by user")) {
- showAlertDialog({
- title: "Download Failed",
- description: `Failed to download model: ${result.error}`,
- });
- }
- } else {
- await window.electronAPI.modelDownload(modelId);
- }
-
- await loadModels();
- } catch (error: any) {
- if (!error.toString().includes("interrupted by user")) {
- showAlertDialog({
- title: "Download Failed",
- description: `Failed to download model: ${error}`,
- });
- }
- } finally {
- setDownloadingModel(null);
- setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
- }
- }, [modelType, onModelSelect, loadModels, showAlertDialog]);
-
- const deleteModel = useCallback(async (modelId: string) => {
- showConfirmDialog({
- title: "Delete Model",
- description: `Are you sure you want to delete this model? You'll need to re-download it if you want to use it again.`,
- onConfirm: async () => {
- try {
- if (modelType === 'whisper') {
- const result = await window.electronAPI.deleteWhisperModel(modelId);
- if (result.success) {
- toast({
- title: "Model Deleted",
- description: `Model deleted successfully! Freed ${result.freed_mb}MB of disk space.`,
- });
- }
- } else {
- await window.electronAPI.modelDelete(modelId);
- toast({
- title: "Model Deleted",
- description: "Model deleted successfully!",
- });
- }
- loadModels();
- } catch (error) {
- showAlertDialog({
- title: "Delete Failed",
- description: `Failed to delete model: ${error}`,
- });
- }
- },
- variant: "destructive",
- });
- }, [modelType, loadModels, showConfirmDialog, showAlertDialog, toast]);
-
- const handleInstallLlamaCpp = async () => {
- try {
- const result = await window.electronAPI?.llamaCppInstall();
- if (result?.success) {
- const status = await window.electronAPI?.llamaCppCheck();
- setLlamaCppStatus({
- isInstalled: status?.isInstalled || false,
- version: status?.version,
- checking: false,
- });
- loadModels();
- }
- } catch (error) {
- console.error("Installation error:", error);
- }
- };
-
- // Show llama.cpp installation prompt for LLM models
- if (modelType === 'llm' && !llamaCppStatus.isInstalled && !llamaCppStatus.checking) {
- return (
- <div className={`${styles.container} ${className}`}>
- <div className="p-4">
- <h3 className="text-lg font-semibold mb-4">Local AI Models</h3>
- <Alert>
- <AlertCircle className="h-4 w-4" />
- <AlertDescription className="space-y-3">
- <p>llama.cpp is required to run local AI models.</p>
- <div className="flex items-center gap-3">
- <Button onClick={handleInstallLlamaCpp} size="sm">
- Install llama.cpp
- </Button>
- <Button
- variant="link"
- className="p-0 h-auto text-primary"
- onClick={() => window.electronAPI?.openExternal("https://github.com/ggerganov/llama.cpp#installation")}
- >
- Manual installation
- <ExternalLink className="ml-1 h-3 w-3" />
- </Button>
- </div>
- </AlertDescription>
- </Alert>
- </div>
- </div>
- );
- }
-
- const progressDisplay = useMemo(() => {
- if (!downloadingModel) return null;
-
- const { percentage, speed, eta } = downloadProgress;
- const progressText = `${Math.round(percentage)}%`;
- const speedText = speed ? ` • ${speed.toFixed(1)} MB/s` : "";
- const etaText = eta ? ` • ETA: ${formatETA(eta)}` : "";
-
- return (
- <div className={`${styles.progress} p-3`}>
- <div className="flex items-center justify-between mb-2">
- <span className={`text-sm font-medium ${styles.progressText}`}>
- Downloading {models.find(m => m.id === downloadingModel)?.name || downloadingModel}...
- </span>
- <span className={`text-xs ${styles.progressText}`}>
- {progressText}{speedText}{etaText}
- </span>
- </div>
- <div className={`w-full ${styles.progressBar} rounded-full h-2`}>
- <div
- className={`${styles.progressFill} h-2 rounded-full transition-all duration-300 ease-out`}
- style={{ width: `${Math.min(percentage, 100)}%` }}
- />
- </div>
- </div>
- );
- }, [downloadingModel, downloadProgress, models, styles]);
-
- return (
- <div className={`${styles.container} ${className}`}>
- {progressDisplay}
-
- <div className="p-4">
- <div className="flex items-center justify-between mb-3">
- <h5 className={styles.header}>
- {modelType === 'whisper' ? 'Whisper Models' : 'Local AI Models'}
- </h5>
- <Button
- onClick={loadModels}
- variant="outline"
- size="sm"
- disabled={loadingModels}
- className={styles.buttons.refresh}
- >
- <RefreshCw size={14} className={loadingModels ? "animate-spin" : ""} />
- <span className="ml-1">{loadingModels ? "Checking..." : "Refresh"}</span>
- </Button>
- </div>
-
- <div className="space-y-2">
- {models.map((model) => {
- const modelId = model.id || model.model || '';
- const isSelected = modelId === selectedModel;
- const isDownloading = downloadingModel === modelId;
- const isDownloaded = model.downloaded || model.isDownloaded;
-
- return (
- <div
- key={modelId}
- className={`flex items-center justify-between p-3 rounded-lg border-2 transition-all ${
- isSelected ? styles.modelCard.selected : styles.modelCard.default
- }`}
- >
- <div className="flex-1">
- <div className="flex items-center gap-2">
- <span className="font-medium">{model.name}</span>
- {isSelected && (
- <span className={styles.badges.selected}>✓ Selected</span>
- )}
- {model.recommended && (
- <span className="text-xs bg-primary/10 text-primary px-2 py-1 rounded">
- Recommended
- </span>
- )}
- </div>
- <div className="flex items-center gap-2 mt-1">
- <p className="text-xs text-gray-600">{model.description}</p>
- <span className="text-xs text-gray-500">• {model.size}</span>
- {isDownloaded && (
- <span className={styles.badges.downloaded}>✓ Downloaded</span>
- )}
- </div>
- </div>
-
- <div className="flex gap-2">
- {isDownloaded && (
- <>
- {!isSelected && (
- <Button
- onClick={() => onModelSelect(modelId)}
- size="sm"
- variant="outline"
- className={styles.buttons.select}
- >
- Select
- </Button>
- )}
- <Button
- onClick={() => deleteModel(modelId)}
- size="sm"
- variant="outline"
- className={styles.buttons.delete}
- >
- <Trash2 size={14} />
- <span className="ml-1">Delete</span>
- </Button>
- </>
- )}
- {!isDownloaded && !isDownloading && (
- <Button
- onClick={() => downloadModel(modelId)}
- size="sm"
- className={styles.buttons.download}
- >
- <Download size={14} />
- <span className="ml-1">Download</span>
- </Button>
- )}
- {isDownloading && (
- <Button disabled size="sm" className={styles.buttons.download}>
- {`${Math.round(downloadProgress.percentage)}%`}
- </Button>
- )}
- </div>
- </div>
- );
- })}
- </div>
-
- {modelType === 'llm' && (
- <div className="mt-6 text-xs text-muted-foreground">
- <p>Models are stored in: ~/.cache/openwhispr/models/</p>
- </div>
- )}
- </div>
- </div>
- );
-}
diff --git a/src/components/WhisperModelPicker.tsx b/src/components/WhisperModelPicker.tsx
deleted file mode 100644
index aadac47d8..000000000
--- a/src/components/WhisperModelPicker.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import React from "react";
-import UnifiedModelPicker from "./UnifiedModelPicker";
-
-interface WhisperModelPickerProps {
- selectedModel: string;
- onModelSelect: (model: string) => void;
- className?: string;
- variant?: "onboarding" | "settings";
-}
-
-export default function WhisperModelPicker({
- selectedModel,
- onModelSelect,
- className = "",
- variant = "settings",
-}: WhisperModelPickerProps) {
- return (
- <UnifiedModelPicker
- selectedModel={selectedModel}
- onModelSelect={onModelSelect}
- modelType="whisper"
- className={className}
- variant={variant}
- />
- );
-}
\ No newline at end of file
diff --git a/src/components/ui/DownloadProgressBar.tsx b/src/components/ui/DownloadProgressBar.tsx
new file mode 100644
index 000000000..4979d910e
--- /dev/null
+++ b/src/components/ui/DownloadProgressBar.tsx
@@ -0,0 +1,36 @@
+import { formatETA, type DownloadProgress } from '../../hooks/useModelDownload';
+import { type ModelPickerStyles } from '../../utils/modelPickerStyles';
+
+interface DownloadProgressBarProps {
+ modelName: string;
+ progress: DownloadProgress;
+ styles: ModelPickerStyles;
+}
+
+export function DownloadProgressBar({ modelName, progress, styles }: DownloadProgressBarProps) {
+ const { percentage, speed, eta } = progress;
+ const progressText = `${Math.round(percentage)}%`;
+ const speedText = speed ? ` • ${speed.toFixed(1)} MB/s` : '';
+ const etaText = eta ? ` • ETA: ${formatETA(eta)}` : '';
+
+ return (
+ <div className={`${styles.progress} p-3`}>
+ <div className="flex items-center justify-between mb-2">
+ <span className={`text-sm font-medium ${styles.progressText}`}>
+ Downloading {modelName}...
+ </span>
+ <span className={`text-xs ${styles.progressText}`}>
+ {progressText}{speedText}{etaText}
+ </span>
+ </div>
+ <div className={`w-full ${styles.progressBar} rounded-full h-2`}>
+ <div
+ className={`${styles.progressFill} h-2 rounded-full transition-all duration-300 ease-out`}
+ style={{ width: `${Math.min(percentage, 100)}%` }}
+ />
+ </div>
+ </div>
+ );
+}
+
+export default DownloadProgressBar;
diff --git a/src/components/ui/ModelCardList.tsx b/src/components/ui/ModelCardList.tsx
new file mode 100644
index 000000000..0db408c2d
--- /dev/null
+++ b/src/components/ui/ModelCardList.tsx
@@ -0,0 +1,82 @@
+import { Globe } from 'lucide-react';
+
+export interface ModelCardOption {
+ value: string;
+ label: string;
+ description?: string;
+ icon?: string;
+}
+
+type ColorScheme = 'indigo' | 'purple';
+
+interface ModelCardListProps {
+ models: ModelCardOption[];
+ selectedModel: string;
+ onModelSelect: (modelId: string) => void;
+ colorScheme?: ColorScheme;
+ className?: string;
+}
+
+const COLOR_CONFIG: Record<ColorScheme, {
+ selected: string;
+ default: string;
+ badge: string;
+}> = {
+ indigo: {
+ selected: 'border-indigo-500 bg-indigo-50',
+ default: 'border-gray-200 bg-white hover:border-gray-300',
+ badge: 'text-xs text-indigo-600 bg-indigo-100 px-2 py-1 rounded-full font-medium',
+ },
+ purple: {
+ selected: 'border-purple-500 bg-purple-50',
+ default: 'border-gray-200 bg-white hover:border-gray-300',
+ badge: 'text-xs text-purple-600 bg-purple-100 px-2 py-1 rounded-full font-medium',
+ },
+};
+
+export default function ModelCardList({
+ models,
+ selectedModel,
+ onModelSelect,
+ colorScheme = 'indigo',
+ className = '',
+}: ModelCardListProps) {
+ const styles = COLOR_CONFIG[colorScheme];
+
+ return (
+ <div className={`space-y-2 ${className}`}>
+ {models.map((model) => {
+ const isSelected = selectedModel === model.value;
+
+ return (
+ <button
+ key={model.value}
+ onClick={() => onModelSelect(model.value)}
+ className={`w-full p-3 rounded-lg border-2 text-left transition-all ${
+ isSelected ? styles.selected : styles.default
+ }`}
+ >
+ <div className="flex items-center justify-between">
+ <div>
+ <div className="flex items-center gap-2">
+ {model.icon ? (
+ <img src={model.icon} alt="" className="w-4 h-4" aria-hidden="true" />
+ ) : (
+ <Globe className="w-4 h-4 text-gray-400" aria-hidden="true" />
+ )}
+ <span className="font-medium text-gray-900">{model.label}</span>
+ </div>
+ {model.description && (
+ <div className="text-xs text-gray-600 mt-1">{model.description}</div>
+ )}
+ </div>
+ {isSelected && (
+ <span className={styles.badge}>✓ Selected</span>
+ )}
+ </div>
+ </button>
+ );
+ })}
+ </div>
+ );
+}
diff --git a/src/components/ui/ProviderIcon.tsx b/src/components/ui/ProviderIcon.tsx
index bb4201506..2944f1033 100644
--- a/src/components/ui/ProviderIcon.tsx
+++ b/src/components/ui/ProviderIcon.tsx
@@ -1,5 +1,5 @@
-import React, { useState } from 'react';
-import { Brain, Zap, Globe, Cpu, Wrench } from 'lucide-react';
+import { useState } from 'react';
+import { Brain, Wrench, HardDrive } from 'lucide-react';
interface ProviderIconProps {
provider: string;
@@ -13,29 +13,21 @@ export function ProviderIcon({ provider, className = "w-5 h-5" }: ProviderIconPr
return <Wrench className={className} />;
}
- const getFallbackIcon = () => {
- switch (provider) {
- // Cloud providers
- case 'openai': return <Brain className={className} />;
- case 'anthropic': return <Zap className={className} />;
- case 'gemini': return <Globe className={className} />;
- case 'groq': return <Zap className={className} />;
- // Local providers
- case 'qwen': return <Brain className={className} />;
- case 'mistral': return <Zap className={className} />;
- case 'llama': return <Cpu className={className} />;
- case 'openai-oss': return <Globe className={className} />;
- default: return <Brain className={className} />;
- }
- };
+ if (provider === 'local') {
+ return <HardDrive className={className} />;
+ }
+
+ const iconPath = provider === 'whisper'
+ ? '/assets/icons/providers/openai.svg'
+ : `/assets/icons/providers/${provider}.svg`;
if (svgError) {
- return getFallbackIcon();
+ return <Brain className={className} />;
}
return (
<img
- src={`/assets/icons/providers/${provider}.svg`}
+ src={iconPath}
alt={`${provider} icon`}
className={className}
onError={() => setSvgError(true)}
diff --git a/src/hooks/useModelDownload.ts b/src/hooks/useModelDownload.ts
new file mode 100644
index 000000000..eac059ccf
--- /dev/null
+++ b/src/hooks/useModelDownload.ts
@@ -0,0 +1,185 @@
+import { useState, useCallback, useEffect, useRef } from 'react';
+import { useDialogs } from './useDialogs';
+import { useToast } from '../components/ui/Toast';
+import type { WhisperDownloadProgressData } from '../types/electron';
+import '../types/electron';
+
+export interface DownloadProgress {
+ percentage: number;
+ downloadedBytes: number;
+ totalBytes: number;
+ speed?: number;
+ eta?: number;
+}
+
+export type ModelType = 'whisper' | 'llm';
+
+interface UseModelDownloadOptions {
+ modelType: ModelType;
+ onDownloadComplete?: () => void;
+ onModelsCleared?: () => void;
+}
+
+interface LLMDownloadProgressData {
+ modelId: string;
+ progress: number;
+ downloadedSize: number;
+ totalSize: number;
+}
+
+export function formatETA(seconds: number): string {
+ if (seconds < 60) return `${Math.round(seconds)}s`;
+ const minutes = Math.floor(seconds / 60);
+ const remainingSeconds = Math.round(seconds % 60);
+ return `${minutes}m ${remainingSeconds}s`;
+}
+
+export function useModelDownload({ modelType, onDownloadComplete, onModelsCleared }: UseModelDownloadOptions) {
+ const [downloadingModel, setDownloadingModel] = useState<string | null>(null);
+ const [downloadProgress, setDownloadProgress] = useState<DownloadProgress>({
+ percentage: 0,
+ downloadedBytes: 0,
+ totalBytes: 0,
+ });
+
+ const { showAlertDialog } = useDialogs();
+ const { toast } = useToast();
+ const onDownloadCompleteRef = useRef(onDownloadComplete);
+ const onModelsClearedRef = useRef(onModelsCleared);
+
+ useEffect(() => {
+ onDownloadCompleteRef.current = onDownloadComplete;
+ }, [onDownloadComplete]);
+
+ useEffect(() => {
+ onModelsClearedRef.current = onModelsCleared;
+ }, [onModelsCleared]);
+
+ useEffect(() => {
+ const handleModelsCleared = () => onModelsClearedRef.current?.();
+ window.addEventListener('openwhispr-models-cleared', handleModelsCleared);
+ return () => window.removeEventListener('openwhispr-models-cleared', handleModelsCleared);
+ }, []);
+
+ const handleWhisperProgress = useCallback((_event: unknown, data: WhisperDownloadProgressData) => {
+ if (data.type === 'progress') {
+ const progress: DownloadProgress = {
+ percentage: data.percentage || 0,
+ downloadedBytes: data.downloaded_bytes || 0,
+ totalBytes: data.total_bytes || 0,
+ };
+
+ setDownloadProgress(progress);
+ } else if (data.type === 'complete' || data.type === 'error') {
+ setDownloadingModel(null);
+ setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
+ onDownloadCompleteRef.current?.();
+ }
+ }, []);
+
+ const handleLLMProgress = useCallback((_event: unknown, data: LLMDownloadProgressData) => {
+ setDownloadProgress({
+ percentage: data.progress || 0,
+ downloadedBytes: data.downloadedSize || 0,
+ totalBytes: data.totalSize || 0,
+ });
+ }, []);
+
+ useEffect(() => {
+ const dispose = modelType === 'whisper'
+ ? window.electronAPI?.onWhisperDownloadProgress(handleWhisperProgress)
+ : window.electronAPI?.onModelDownloadProgress(handleLLMProgress);
+
+ return () => {
+ dispose?.();
+ };
+ }, [handleWhisperProgress, handleLLMProgress, modelType]);
+
+ const downloadModel = useCallback(async (modelId: string, onSelectAfterDownload?: (id: string) => void) => {
+ try {
+ setDownloadingModel(modelId);
+ setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
+
+ let success = false;
+
+ if (modelType === 'whisper') {
+ const result = await window.electronAPI?.downloadWhisperModel(modelId);
+ if (!result?.success && !result?.error?.includes('interrupted by user')) {
+ showAlertDialog({
+ title: 'Download Failed',
+ description: `Failed to download model: ${result?.error}`,
+ });
+ } else {
+ success = result?.success ?? false;
+ }
+ } else {
+ const result = await window.electronAPI?.modelDownload?.(modelId) as { success: boolean; error?: string } | undefined;
+ if (result && !result.success && result.error) {
+ showAlertDialog({
+ title: 'Download Failed',
+ description: `Failed to download model: ${result.error}`,
+ });
+ } else {
+ success = result?.success ?? false;
+ }
+ }
+
+ if (success) {
+ onSelectAfterDownload?.(modelId);
+ }
+
+ onDownloadCompleteRef.current?.();
+ } catch (error: unknown) {
+ const errorMessage = error instanceof Error ? error.message : String(error);
+ if (!errorMessage.includes('interrupted by user')) {
+ showAlertDialog({
+ title: 'Download Failed',
+ description: `Failed to download model: ${errorMessage}`,
+ });
+ }
+ } finally {
+ setDownloadingModel(null);
+ setDownloadProgress({ percentage: 0, downloadedBytes: 0, totalBytes: 0 });
+ }
+ }, [modelType, showAlertDialog]);
+
+ const deleteModel = useCallback(async (modelId: string, onComplete?: () => void) => {
+ try {
+ if (modelType === 'whisper') {
+ const result = await window.electronAPI?.deleteWhisperModel(modelId);
+ if (result?.success) {
+ toast({
+ title: 'Model Deleted',
+ description: `Model deleted successfully! Freed ${result.freed_mb}MB of disk space.`,
+ });
+ }
+ } else {
+ await window.electronAPI?.modelDelete?.(modelId);
+ toast({
+ title: 'Model Deleted',
+ description: 'Model deleted successfully!',
+ });
+ }
+ onComplete?.();
+ } catch (error: unknown) {
+ const errorMessage = error instanceof Error ? error.message : String(error);
+ showAlertDialog({
+ title: 'Delete Failed',
+ description: `Failed to delete model: ${errorMessage}`,
+ });
+ }
+ }, [modelType, toast, showAlertDialog]);
+
+ const isDownloading = downloadingModel !== null;
+ const isDownloadingModel = useCallback((modelId: string) => downloadingModel === modelId, [downloadingModel]);
+
+ return {
+ downloadingModel,
+ downloadProgress,
+ isDownloading,
+ isDownloadingModel,
+ downloadModel,
+ deleteModel,
+ formatETA,
+ };
+}
diff --git a/src/models/ModelRegistry.ts b/src/models/ModelRegistry.ts
index 670d44270..13792166b 100644
--- a/src/models/ModelRegistry.ts
+++ b/src/models/ModelRegistry.ts
@@ -1,6 +1,5 @@
import modelDataRaw from './modelRegistryData.json';
-// Types for local models (downloadable GGUF files)
export interface ModelDefinition {
id: string;
name: string;
@@ -31,7 +30,6 @@ export interface ModelProvider {
getDownloadUrl(model: ModelDefinition): string;
}
-// Types for cloud models (API-based)
export interface CloudModelDefinition {
id: string;
name: string;
@@ -44,7 +42,6 @@ export interface CloudProviderData {
models: CloudModelDefinition[];
}
-// Types for transcription providers (speech-to-text)
export interface TranscriptionModelDefinition {
id: string;
name: string;
@@ -58,8 +55,18 @@ export interface TranscriptionProviderData {
models: TranscriptionModelDefinition[];
}
-// Type-safe model registry data structure
+export interface WhisperModelInfo {
+ name: string;
+ description: string;
+ size: string;
+ sizeMb: number;
+ recommended?: boolean;
+}
+
+export type WhisperModelsMap = Record<string, WhisperModelInfo>;
+
interface ModelRegistryData {
+ whisperModels: WhisperModelsMap;
transcriptionProviders: TranscriptionProviderData[];
cloudProviders: CloudProviderData[];
localProviders: LocalProviderData[];
@@ -150,7 +157,6 @@ class ModelRegistry {
export const modelRegistry = ModelRegistry.getInstance();
-// Reasoning providers (flat structure for UI dropdowns)
export interface ReasoningModel {
value: string;
label: string;
@@ -216,18 +222,12 @@ export function getModelProvider(modelId: string): string {
const model = getAllReasoningModels().find((m) => m.value === modelId);
if (!model) {
- // Infer provider from model name pattern
if (modelId.includes("claude")) return "anthropic";
- // Check for gemini but exclude gemma (which could be Groq or local)
if (modelId.includes("gemini") && !modelId.includes("gemma")) return "gemini";
- // OpenAI cloud models (gpt-4.x, gpt-5.x but NOT gpt-oss which could be Groq)
if ((modelId.includes("gpt-4") || modelId.includes("gpt-5")) && !modelId.includes("gpt-oss")) return "openai";
- // Groq-specific model patterns (these run on Groq cloud, not local)
- // Groq models have patterns like "qwen/", "openai/gpt-oss-", "llama-3.1-8b-instant", "llama-3.3-", "mixtral-", "gemma2-"
if (modelId.includes("qwen/") || modelId.includes("openai/") ||
modelId.includes("llama-3.1-8b-instant") || modelId.includes("llama-3.3-") ||
modelId.includes("mixtral-") || modelId.includes("gemma2-")) return "groq";
- // Local models have patterns like "qwen2.5-", "qwen3-", "llama-3.2-", "mistral-", "gpt-oss-20b-mxfp4"
if (modelId.includes("qwen") || modelId.includes("llama") ||
modelId.includes("mistral") || modelId.includes("gpt-oss-20b-mxfp4")) return "local";
}
@@ -235,7 +235,6 @@ export function getModelProvider(modelId: string): string {
return model?.provider || "openai";
}
-// Transcription provider helpers
export function getTranscriptionProviders(): TranscriptionProviderData[] {
return modelRegistry.getTranscriptionProviders();
}
@@ -253,3 +252,13 @@ export function getDefaultTranscriptionModel(providerId: string): string {
const models = getTranscriptionModels(providerId);
return models[0]?.id || 'gpt-4o-mini-transcribe';
}
+
+export function getWhisperModels(): WhisperModelsMap {
+ return modelData.whisperModels;
+}
+
+export function getWhisperModelInfo(modelId: string): WhisperModelInfo | undefined {
+ return modelData.whisperModels[modelId];
+}
+
+export const WHISPER_MODEL_INFO = modelData.whisperModels;
diff --git a/src/models/modelRegistryData.json b/src/models/modelRegistryData.json
index 42a7d3cdc..fb08f7593 100644
--- a/src/models/modelRegistryData.json
+++ b/src/models/modelRegistryData.json
@@ -1,4 +1,12 @@
{
+ "whisperModels": {
+ "tiny": { "name": "Tiny", "description": "Fastest, lower quality", "size": "39MB", "sizeMb": 39 },
+ "base": { "name": "Base", "description": "Good balance", "size": "74MB", "sizeMb": 74, "recommended": true },
+ "small": { "name": "Small", "description": "Better quality, slower", "size": "244MB", "sizeMb": 244 },
+ "medium": { "name": "Medium", "description": "High quality", "size": "769MB", "sizeMb": 769 },
+ "large": { "name": "Large", "description": "Best quality, slowest", "size": "1.5GB", "sizeMb": 1550 },
+ "turbo": { "name": "Turbo", "description": "Fast with good quality", "size": "809MB", "sizeMb": 809 }
+ },
"transcriptionProviders": [
{
"id": "openai",
@@ -172,9 +180,9 @@
"id": "qwen3-8b-q4_k_m",
"name": "Qwen3 8B",
"size": "5.0GB",
- "sizeBytes": 5368709120,
+ "sizeBytes": 5402263552,
"description": "Latest Qwen3 with thinking mode support",
- "fileName": "qwen3-8b-q4_k_m.gguf",
+ "fileName": "Qwen3-8B-Q4_K_M.gguf",
"quantization": "q4_k_m",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-8B-GGUF",
@@ -184,9 +192,9 @@
"id": "qwen3-8b-q5_k_m",
"name": "Qwen3 8B (Q5)",
"size": "5.9GB",
- "sizeBytes": 6333399654,
+ "sizeBytes": 6281625600,
"description": "Higher quality Qwen3 with thinking mode",
- "fileName": "qwen3-8b-q5_k_m.gguf",
+ "fileName": "Qwen3-8B-Q5_K_M.gguf",
"quantization": "q5_k_m",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-8B-GGUF"
@@ -197,7 +205,7 @@
"size": "2.5GB",
"sizeBytes": 2684354560,
"description": "Compact Qwen3 with reasoning capabilities",
- "fileName": "qwen3-4b-q4_k_m.gguf",
+ "fileName": "Qwen3-4B-Q4_K_M.gguf",
"quantization": "q4_k_m",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-4B-GGUF"
@@ -206,9 +214,9 @@
"id": "qwen3-1.7b-q8_0",
"name": "Qwen3 1.7B",
"size": "1.8GB",
- "sizeBytes": 1932735283,
+ "sizeBytes": 1965555712,
"description": "Small but capable Qwen3 model",
- "fileName": "qwen3-1.7b-q8_0.gguf",
+ "fileName": "Qwen3-1.7B-Q8_0.gguf",
"quantization": "q8_0",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-1.7B-GGUF"
@@ -217,9 +225,9 @@
"id": "qwen3-0.6b-q8_0",
"name": "Qwen3 0.6B",
"size": "0.6GB",
- "sizeBytes": 644245094,
+ "sizeBytes": 686817280,
"description": "Tiny Qwen3 for edge devices",
- "fileName": "qwen3-0.6b-q8_0.gguf",
+ "fileName": "Qwen3-0.6B-Q8_0.gguf",
"quantization": "q8_0",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-0.6B-GGUF"
@@ -230,7 +238,7 @@
"size": "19.8GB",
"sizeBytes": 21260251955,
"description": "Most powerful local Qwen3 with deep reasoning",
- "fileName": "qwen3-32b-q4_k_m.gguf",
+ "fileName": "Qwen3-32B-Q4_K_M.gguf",
"quantization": "q4_k_m",
"contextLength": 131072,
"hfRepo": "Qwen/Qwen3-32B-GGUF"
@@ -238,8 +246,8 @@
{
"id": "qwen2.5-0.5b-instruct-q5_k_m",
"name": "Qwen2.5 0.5B",
- "size": "0.4GB",
- "sizeBytes": 429496729,
+ "size": "0.5GB",
+ "sizeBytes": 548405248,
"description": "Smallest model, fast but limited capabilities",
"fileName": "qwen2.5-0.5b-instruct-q5_k_m.gguf",
"quantization": "q5_k_m",
@@ -260,8 +268,8 @@
{
"id": "qwen2.5-3b-instruct-q5_k_m",
"name": "Qwen2.5 3B",
- "size": "2.3GB",
- "sizeBytes": 2469606195,
+ "size": "2.4GB",
+ "sizeBytes": 2620055552,
"description": "Balanced model for general use",
"fileName": "qwen2.5-3b-instruct-q5_k_m.gguf",
"quantization": "q5_k_m",
@@ -272,23 +280,23 @@
"id": "qwen2.5-7b-instruct-q4_k_m",
"name": "Qwen2.5 7B",
"size": "4.7GB",
- "sizeBytes": 5046586241,
+ "sizeBytes": 5025128858,
"description": "Large model with high quality (Q4_K_M)",
- "fileName": "qwen2.5-7b-instruct-q4_k_m.gguf",
+ "fileName": "Qwen2.5-7B-Instruct-Q4_K_M.gguf",
"quantization": "q4_k_m",
"contextLength": 128000,
- "hfRepo": "Qwen/Qwen2.5-7B-Instruct-GGUF"
+ "hfRepo": "bartowski/Qwen2.5-7B-Instruct-GGUF"
},
{
"id": "qwen2.5-7b-instruct-q5_k_m",
"name": "Qwen2.5 7B (Q5)",
"size": "5.4GB",
- "sizeBytes": 5798205849,
+ "sizeBytes": 5841530470,
"description": "Large model, high quality reasoning (Q5_K_M)",
- "fileName": "qwen2.5-7b-instruct-q5_k_m.gguf",
+ "fileName": "Qwen2.5-7B-Instruct-Q5_K_M.gguf",
"quantization": "q5_k_m",
"contextLength": 128000,
- "hfRepo": "Qwen/Qwen2.5-7B-Instruct-GGUF"
+ "hfRepo": "bartowski/Qwen2.5-7B-Instruct-GGUF"
}
]
},
@@ -302,7 +310,7 @@
"id": "mistral-7b-instruct-v0.3-q4_k_m",
"name": "Mistral 7B Instruct v0.3",
"size": "4.4GB",
- "sizeBytes": 4724956928,
+ "sizeBytes": 4692635648,
"description": "Fast and efficient instruction model",
"fileName": "Mistral-7B-Instruct-v0.3-Q4_K_M.gguf",
"quantization": "q4_k_m",
@@ -314,7 +322,7 @@
"id": "mistral-7b-instruct-v0.3-q5_k_m",
"name": "Mistral 7B Instruct v0.3 (Q5)",
"size": "5.1GB",
- "sizeBytes": 5477387264,
+ "sizeBytes": 5519900672,
"description": "Higher quality instruction model",
"fileName": "Mistral-7B-Instruct-v0.3-Q5_K_M.gguf",
"quantization": "q5_k_m",
@@ -332,8 +340,8 @@
{
"id": "llama-3.2-1b-instruct-q4_k_m",
"name": "Llama 3.2 1B",
- "size": "0.9GB",
- "sizeBytes": 966367642,
+ "size": "0.8GB",
+ "sizeBytes": 847249408,
"description": "Tiny model for edge devices",
"fileName": "Llama-3.2-1B-Instruct-Q4_K_M.gguf",
"quantization": "q4_k_m",
@@ -344,7 +352,7 @@
"id": "llama-3.2-3b-instruct-q4_k_m",
"name": "Llama 3.2 3B",
"size": "2.0GB",
- "sizeBytes": 2147483648,
+ "sizeBytes": 2168958976,
"description": "Small but capable multilingual model",
"fileName": "Llama-3.2-3B-Instruct-Q4_K_M.gguf",
"quantization": "q4_k_m",
@@ -356,7 +364,7 @@
"id": "llama-3.1-8b-instruct-q4_k_m",
"name": "Llama 3.1 8B",
"size": "4.9GB",
- "sizeBytes": 5260091802,
+ "sizeBytes": 5282717696,
"description": "Powerful model with great performance",
"fileName": "Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
"quantization": "q4_k_m",
diff --git a/src/utils/modelPickerStyles.ts b/src/utils/modelPickerStyles.ts
new file mode 100644
index 000000000..3896e9a3d
--- /dev/null
+++ b/src/utils/modelPickerStyles.ts
@@ -0,0 +1,89 @@
+export type ColorScheme = 'purple' | 'indigo' | 'blue';
+
+export interface ModelPickerStyles {
+ container: string;
+ progress: string;
+ progressText: string;
+ progressBar: string;
+ progressFill: string;
+ header: string;
+ modelCard: { selected: string; default: string };
+ badges: { selected: string; downloaded: string; recommended: string };
+ buttons: { download: string; select: string; delete: string; refresh: string };
+}
+
+export const MODEL_PICKER_COLORS: Record<ColorScheme, ModelPickerStyles> = {
+ purple: {
+ container: 'border border-gray-200 rounded-xl overflow-hidden',
+ progress: 'bg-purple-50 border-b border-purple-200',
+ progressText: 'text-purple-900',
+ progressBar: 'bg-purple-200',
+ progressFill: 'bg-gradient-to-r from-purple-500 to-purple-600',
+ header: 'font-medium text-purple-900',
+ modelCard: {
+ selected: 'border-purple-500 bg-purple-50',
+ default: 'border-gray-200 bg-white hover:border-gray-300',
+ },
+ badges: {
+ selected: 'text-xs text-purple-600 bg-purple-100 px-2 py-1 rounded-full font-medium',
+ downloaded: 'text-xs text-green-600 bg-green-100 px-2 py-0.5 rounded',
+ recommended: 'text-xs text-blue-600 bg-blue-100 px-2 py-0.5 rounded',
+ },
+ buttons: {
+ download: 'bg-purple-600 hover:bg-purple-700',
+ select: 'border-purple-300 text-purple-700 hover:bg-purple-50',
+ delete: 'text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200',
+ refresh: 'border-purple-300 text-purple-700 hover:bg-purple-50',
+ },
+ },
+ indigo: {
+ container: 'border border-gray-200 rounded-xl overflow-hidden',
+ progress: 'bg-indigo-50 border-b border-indigo-200',
+ progressText: 'text-indigo-900',
+ progressBar: 'bg-indigo-200',
+ progressFill: 'bg-gradient-to-r from-indigo-500 to-indigo-600',
+ header: 'font-medium text-indigo-900',
+ modelCard: {
+ selected: 'border-indigo-500 bg-indigo-50',
+ default: 'border-gray-200 bg-white hover:border-gray-300',
+ },
+ badges: {
+ selected: 'text-xs text-indigo-600 bg-indigo-100 px-2 py-1 rounded-full font-medium',
+ downloaded: 'text-xs text-green-600 bg-green-100 px-2 py-0.5 rounded',
+ recommended: 'text-xs text-blue-600 bg-blue-100 px-2 py-0.5 rounded',
+ },
+ buttons: {
+ download: 'bg-indigo-600 hover:bg-indigo-700',
+ select: 'border-indigo-300 text-indigo-700 hover:bg-indigo-50',
+ delete: 'text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200',
+ refresh: 'border-indigo-300 text-indigo-700 hover:bg-indigo-50',
+ },
+ },
+ blue: {
+ container: 'bg-gray-50 rounded-lg overflow-hidden border border-gray-200',
+ progress: 'bg-blue-50 border-b border-blue-200',
+ progressText: 'text-blue-900',
+ progressBar: 'bg-blue-200',
+ progressFill: 'bg-gradient-to-r from-blue-500 to-blue-600',
+ header: 'font-medium text-gray-900',
+ modelCard: {
+ selected: 'border-blue-500 bg-blue-50',
+ default: 'border-gray-200 bg-white hover:border-gray-300',
+ },
+ badges: {
+ selected: 'text-xs text-blue-600 bg-blue-100 px-2 py-1 rounded-full font-medium',
+ downloaded: 'text-xs text-green-600 bg-green-100 px-2 py-1 rounded',
+ recommended: 'text-xs bg-primary/10 text-primary px-2 py-1 rounded',
+ },
+ buttons: {
+ download: 'bg-blue-600 hover:bg-blue-700',
+ select: 'border-gray-300 text-gray-700 hover:bg-gray-50',
+ delete: 'text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200',
+ refresh: 'border-gray-300 text-gray-700 hover:bg-gray-50',
+ },
+ },
+};
+
+export function getModelPickerStyles(colorScheme: ColorScheme): ModelPickerStyles {
+ return MODEL_PICKER_COLORS[colorScheme];
+}