Skip to content

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

fix: use getModelProvider() consistently and remove redundant fallbacks

Excelsior632280cc2b90
diff --git a/src/components/ui/PromptStudio.tsx b/src/components/ui/PromptStudio.tsx
index 5c71d4b52..d1ec1fdf2 100644
--- a/src/components/ui/PromptStudio.tsx
+++ b/src/components/ui/PromptStudio.tsx
@@ -18,6 +18,7 @@ import { AlertDialog } from "./dialog";
import { useDialogs } from "../../hooks/useDialogs";
import { useAgentName } from "../../utils/agentName";
import ReasoningService, { DEFAULT_PROMPTS } from "../../services/ReasoningService";
+import { getModelProvider } from "../../models/ModelRegistry";
interface PromptStudioProps {
className?: string;
@@ -102,7 +103,8 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
// Check if reasoning model is enabled and if we have the necessary settings
const useReasoningModel = localStorage.getItem("useReasoningModel") === "true";
const reasoningModel = localStorage.getItem("reasoningModel") || "";
- const reasoningProvider = localStorage.getItem("reasoningProvider") || "openai";
+ // Determine provider from the model name, falling back to openai if needed
+ const reasoningProvider = reasoningModel ? getModelProvider(reasoningModel) : "openai";
if (!useReasoningModel) {
setTestResult(
@@ -129,13 +131,8 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
}
}
- if (providerConfig.apiKeyStorageKey) {
- const apiKey = localStorage.getItem(providerConfig.apiKeyStorageKey);
- if (!apiKey || apiKey.trim() === "") {
- setTestResult(`⚠️ No ${providerLabel} API key found. Add it in AI Models settings.`);
- return;
- }
- }
+ // Note: API key validation is handled by ReasoningService which uses Electron IPC
+ // to fetch keys from the environment. We skip localStorage validation here.
// Save current prompts temporarily so the test uses them
const currentCustomPrompts = localStorage.getItem("customPrompts");
@@ -324,7 +321,7 @@ export default function PromptStudio({ className = "" }: PromptStudioProps) {
const renderTestPlayground = () => {
const useReasoningModel = localStorage.getItem("useReasoningModel") === "true";
const reasoningModel = localStorage.getItem("reasoningModel") || "";
- const reasoningProvider = localStorage.getItem("reasoningProvider") || "openai";
+ const reasoningProvider = reasoningModel ? getModelProvider(reasoningModel) : "openai";
const providerConfig = PROVIDER_CONFIG[reasoningProvider] || {
label: reasoningProvider.charAt(0).toUpperCase() + reasoningProvider.slice(1),
};
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index a0af1480a..b7722501d 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -2,6 +2,7 @@ import { useCallback } from "react";
import { useLocalStorage } from "./useLocalStorage";
import { getModelProvider } from "../models/ModelRegistry";
import { API_ENDPOINTS } from "../config/constants";
+import ReasoningService from "../services/ReasoningService";
export interface TranscriptionSettings {
useLocalWhisper: boolean;
@@ -125,27 +126,64 @@ export function useSettings() {
deserialize: String,
});
- // API keys
- const [openaiApiKey, setOpenaiApiKey] = useLocalStorage("openaiApiKey", "", {
+ // API keys - localStorage for UI, synced to Electron IPC for persistence
+ const [openaiApiKey, setOpenaiApiKeyLocal] = useLocalStorage("openaiApiKey", "", {
serialize: String,
deserialize: String,
});
- const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropicApiKey", "", {
+ const [anthropicApiKey, setAnthropicApiKeyLocal] = useLocalStorage("anthropicApiKey", "", {
serialize: String,
deserialize: String,
});
- const [geminiApiKey, setGeminiApiKey] = useLocalStorage("geminiApiKey", "", {
+ const [geminiApiKey, setGeminiApiKeyLocal] = useLocalStorage("geminiApiKey", "", {
serialize: String,
deserialize: String,
});
- const [groqApiKey, setGroqApiKey] = useLocalStorage("groqApiKey", "", {
+ const [groqApiKey, setGroqApiKeyLocal] = useLocalStorage("groqApiKey", "", {
serialize: String,
deserialize: String,
});
+ // Wrapped setters that sync to Electron IPC and invalidate cache
+ const setOpenaiApiKey = useCallback(
+ (key: string) => {
+ setOpenaiApiKeyLocal(key);
+ window.electronAPI?.saveOpenAIKey?.(key);
+ ReasoningService.clearApiKeyCache("openai");
+ },
+ [setOpenaiApiKeyLocal]
+ );
+
+ const setAnthropicApiKey = useCallback(
+ (key: string) => {
+ setAnthropicApiKeyLocal(key);
+ window.electronAPI?.saveAnthropicKey?.(key);
+ ReasoningService.clearApiKeyCache("anthropic");
+ },
+ [setAnthropicApiKeyLocal]
+ );
+
+ const setGeminiApiKey = useCallback(
+ (key: string) => {
+ setGeminiApiKeyLocal(key);
+ window.electronAPI?.saveGeminiKey?.(key);
+ ReasoningService.clearApiKeyCache("gemini");
+ },
+ [setGeminiApiKeyLocal]
+ );
+
+ const setGroqApiKey = useCallback(
+ (key: string) => {
+ setGroqApiKeyLocal(key);
+ window.electronAPI?.saveGroqKey?.(key);
+ ReasoningService.clearApiKeyCache("groq");
+ },
+ [setGroqApiKeyLocal]
+ );
+
// Hotkey
const [dictationKey, setDictationKey] = useLocalStorage("dictationKey", "", {
serialize: String,
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 82187352d..4df92cd04 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -959,6 +959,20 @@ class ReasoningService extends BaseReasoningService {
}
}
+ /**
+ * Clear cached API key for a specific provider or all providers.
+ * Call this when API keys change to ensure fresh keys are used.
+ */
+ clearApiKeyCache(provider?: "openai" | "anthropic" | "gemini" | "groq"): void {
+ if (provider) {
+ this.apiKeyCache.delete(provider);
+ logger.logReasoning("API_KEY_CACHE_CLEARED", { provider });
+ } else {
+ this.apiKeyCache.clear();
+ logger.logReasoning("API_KEY_CACHE_CLEARED", { provider: "all" });
+ }
+ }
+
destroy(): void {
if (this.cacheCleanupStop) {
this.cacheCleanupStop();