Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
refactor(reasoning): share httpError and window-context helpers
Gabriel Stein8140e87ac718
diff --git a/src/components/CleanupFailureToastListener.tsx b/src/components/CleanupFailureToastListener.tsxindex 3ba3852a6..32d0d8f0e 100644--- a/src/components/CleanupFailureToastListener.tsx+++ b/src/components/CleanupFailureToastListener.tsx@@ -2,11 +2,7 @@ import { useEffect } from "react";import { useTranslation } from "react-i18next";import { useToast } from "./ui/useToast";import { consumeCleanupFailures, useCleanupFailureStore } from "../stores/cleanupFailureStore";--const isDictationPanelWindow = () => {- const { search, pathname } = window.location;- return !pathname.includes("control") && !search.includes("panel=true");-};+import { isDictationPanelWindow } from "../utils/windowContext";/** Tells the user their dictation was pasted raw because AI cleanup failed. */export default function CleanupFailureToastListener() {diff --git a/src/components/TinfoilModelSwitchToastListener.tsx b/src/components/TinfoilModelSwitchToastListener.tsxindex 1e4f893bf..ef3ef7b25 100644--- a/src/components/TinfoilModelSwitchToastListener.tsx+++ b/src/components/TinfoilModelSwitchToastListener.tsx@@ -5,11 +5,7 @@ import {consumeTinfoilModelSwitches,useTinfoilModelSwitchStore,} from "../stores/tinfoilModelSwitchStore";--const isDictationPanelWindow = () => {- const { search, pathname } = window.location;- return !pathname.includes("control") && !search.includes("panel=true");-};+import { isDictationPanelWindow } from "../utils/windowContext";/** Alerts the user when a retired Tinfoil model was switched out from under them. */export default function TinfoilModelSwitchToastListener() {diff --git a/src/components/notes/MeetingRecordingPill.tsx b/src/components/notes/MeetingRecordingPill.tsxindex 52a72d6bb..3a01b2307 100644--- a/src/components/notes/MeetingRecordingPill.tsx+++ b/src/components/notes/MeetingRecordingPill.tsx@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";import { Square } from "lucide-react";import { stopRecording, useMeetingRecordingStore } from "../../stores/meetingRecordingStore";import { cn } from "../lib/utils";+import { isControlPanelWindow } from "../../utils/windowContext";interface MeetingRecordingPillProps {activeView: string;@@ -14,12 +15,6 @@ interface MeetingRecordingPillProps {const BAR_COUNT = 4;const BAR_FLOOR = 12;-const isControlPanelWindow = () => {- if (typeof window === "undefined") return false;- const { search, pathname } = window.location;- return pathname.includes("control") || search.includes("panel=true");-};-const truncateTitle = (title: string) =>title.length > 20 ? `${title.slice(0, 19).trimEnd()}…` : title;diff --git a/src/components/ui/Toast.tsx b/src/components/ui/Toast.tsxindex f0715c013..eacadcfca 100644--- a/src/components/ui/Toast.tsx+++ b/src/components/ui/Toast.tsx@@ -2,6 +2,7 @@ import * as React from "react";import { X, Copy, Check } from "lucide-react";import { cn } from "../lib/utils";import { ToastContext, type ToastProps } from "./useToast";+import { isDictationPanelWindow } from "../../utils/windowContext";interface ToastState extends ToastProps {id: string;@@ -111,12 +112,7 @@ const ToastViewport: React.FC<{onPauseTimer: (id: string) => void;onResumeTimer: (id: string, remainingTime: number) => void;}> = ({ toasts, onDismiss, onPauseTimer, onResumeTimer }) => {- const isDictationPanel = React.useMemo(() => {- return (- window.location.pathname.indexOf("control") === -1 &&- window.location.search.indexOf("panel=true") === -1- );- }, []);+ const isDictationPanel = React.useMemo(isDictationPanelWindow, []);if (toasts.length === 0) return null;diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 95a6e570c..676641de5 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -1399,7 +1399,6 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);fallbackToCleanup: true,});logger.warn("Reasoning failed", { source, error: error.message }, "notes");- // Retries are already spent here: the raw transcript is what the user gets.if (route?.kind === "cleanup") recordCleanupFailure();}}@@ -1676,7 +1675,6 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);{ error: reasonError.message },"transcription");- // Retries are already spent here: the raw transcript is what the user gets.if (route.kind === "cleanup") recordCleanupFailure();}timings.reasoningProcessingDurationMs = Math.round(performance.now() - reasoningStart);@@ -3181,7 +3179,6 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);{ error: reasonError.message },"streaming");- // Retries are already spent here: the raw transcript is what the user gets.if (route.kind === "cleanup") recordCleanupFailure();}}diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex 20e0c1d3d..7fdac8862 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -8,7 +8,7 @@ import {} from "../models/ModelRegistry";import { BaseReasoningService, ReasoningConfig } from "./BaseReasoningService";import { SecureCache } from "../utils/SecureCache";-import { withRetry, createApiRetryStrategy } from "../utils/retry";+import { withRetry, createApiRetryStrategy, httpError } from "../utils/retry";import { API_ENDPOINTS, TOKEN_LIMITS, buildApiUrl, ensureV1Suffix } from "../config/constants";import logger from "../utils/logger";import { getSettings, isCloudCleanupMode } from "../stores/settingsStore";@@ -264,10 +264,7 @@ class ReasoningService extends BaseReasoningService {errorData.message ||errorData.error ||`${providerName} API error: ${res.status}`;- // Carry the status so the retry layer can tell a rejection from a network fault.- const apiError = new Error(errorMessage) as Error & { status?: number };- apiError.status = res.status;- throw apiError;+ throw httpError(errorMessage, res.status);}const jsonResponse = await res.json();diff --git a/src/services/ai/inferenceProviders/gemini.ts b/src/services/ai/inferenceProviders/gemini.tsindex f644c8920..ee5152186 100644--- a/src/services/ai/inferenceProviders/gemini.ts+++ b/src/services/ai/inferenceProviders/gemini.ts@@ -1,6 +1,6 @@import type { InferenceProvider } from "./types";import { getCloudModel } from "../../../models/ModelRegistry";-import { withRetry, createApiRetryStrategy } from "../../../utils/retry";+import { withRetry, createApiRetryStrategy, httpError } from "../../../utils/retry";import { API_ENDPOINTS, TOKEN_LIMITS } from "../../../config/constants";import { wrapCleanupTranscript } from "../../../config/prompts";import logger from "../../../utils/logger";@@ -97,10 +97,7 @@ export const geminiProvider: InferenceProvider = {errorData.message ||(typeof errorData.error === "string" ? errorData.error : null) ||`Gemini API error: ${res.status}`;- // Carry the status so the retry layer can tell a rejection from a network fault.- const apiError = new Error(errMsg) as Error & { status?: number };- apiError.status = res.status;- throw apiError;+ throw httpError(errMsg, res.status);}const jsonResponse = (await res.json()) as GeminiResponse;diff --git a/src/services/ai/inferenceProviders/openai.ts b/src/services/ai/inferenceProviders/openai.tsindex b769e5ec9..769b000bb 100644--- a/src/services/ai/inferenceProviders/openai.ts+++ b/src/services/ai/inferenceProviders/openai.ts@@ -2,7 +2,7 @@ import type { InferenceProvider } from "./types";import { API_ENDPOINTS, TOKEN_LIMITS, buildApiUrl } from "../../../config/constants";import { getOpenAiApiConfig } from "../../../models/ModelRegistry";import { getSettings } from "../../../stores/settingsStore";-import { withRetry, createApiRetryStrategy } from "../../../utils/retry";+import { withRetry, createApiRetryStrategy, httpError } from "../../../utils/retry";import logger from "../../../utils/logger";import { getConfiguredOpenAIBase } from "../openaiBase";import { applyThinkingSuppression } from "../thinkingSuppression";@@ -237,7 +237,7 @@ export const openaiProvider: InferenceProvider = {(res.status === 404 || res.status === 405) && type === "responses";if (isUnsupportedEndpoint) {- lastError = new Error(errorMessage);+ lastError = httpError(errorMessage, res.status);rememberPreference(openAiBase, "chat");logger.logReasoning("OPENAI_ENDPOINT_FALLBACK", {attemptedEndpoint: endpoint,@@ -246,10 +246,7 @@ export const openaiProvider: InferenceProvider = {continue;}- // Carry the status so the retry layer can tell a rejection from a network fault.- const apiError = new Error(errorMessage) as Error & { status?: number };- apiError.status = res.status;- throw apiError;+ throw httpError(errorMessage, res.status);}rememberPreference(openAiBase, type);diff --git a/src/utils/retry.ts b/src/utils/retry.tsindex a92089d8a..c82d9995f 100644--- a/src/utils/retry.ts+++ b/src/utils/retry.ts@@ -39,6 +39,11 @@ export async function withRetry<T>(fn: () => Promise<T>, options: RetryOptions =throw lastError;}+// Status lets createApiRetryStrategy tell an HTTP rejection from a network fault.+export function httpError(message: string, status: number): Error & { status: number } {+ return Object.assign(new Error(message), { status });+}+// Specific retry strategy for API callsexport function createApiRetryStrategy() {return {diff --git a/src/utils/windowContext.ts b/src/utils/windowContext.tsnew file mode 100644index 000000000..79cbd090f--- /dev/null+++ b/src/utils/windowContext.ts@@ -0,0 +1,10 @@+// The control panel loads with "control" in the path (packaged) or ?panel=true+// (dev server); the dictation panel is the plain URL.+export const isControlPanelWindow = (): boolean => {+ if (typeof window === "undefined") return false;+ const { search, pathname } = window.location;+ return pathname.includes("control") || search.includes("panel=true");+};++export const isDictationPanelWindow = (): boolean =>+ typeof window !== "undefined" && !isControlPanelWindow();