Skip to content

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

fix(transcription): honor self-hosted settings on retry (#1154)

Henry Su5a86b63ef516
diff --git a/src/components/ControlPanel.tsx b/src/components/ControlPanel.tsx
index 7d671303b..7a3d4bd9d 100644
--- a/src/components/ControlPanel.tsx
+++ b/src/components/ControlPanel.tsx
@@ -507,6 +507,7 @@ export default function ControlPanel({ initialSettingsSection }: ControlPanelPro
transcriptionMode: s.transcriptionMode,
remoteTranscriptionType: s.remoteTranscriptionType,
remoteTranscriptionUrl: s.remoteTranscriptionUrl,
+ remoteTranscriptionModel: s.remoteTranscriptionModel,
});
if (result.success && result.transcription) {
const rawText = result.transcription.text;
diff --git a/src/components/chat/useChatStreaming.ts b/src/components/chat/useChatStreaming.ts
index 27afbbd24..f3943c3e6 100644
--- a/src/components/chat/useChatStreaming.ts
+++ b/src/components/chat/useChatStreaming.ts
@@ -205,7 +205,10 @@ export function useChatStreaming({
systemPrompt,
lanUrl: isLanAgent ? settings.chatAgentRemoteUrl : undefined,
baseUrl: isCustomAgent ? settings.chatAgentCloudBaseUrl || undefined : undefined,
- customApiKey: isCustomAgent ? settings.chatAgentCustomApiKey || undefined : undefined,
+ customApiKey:
+ isCustomAgent || isLanAgent
+ ? settings.chatAgentCustomApiKey || undefined
+ : undefined,
disableThinking: settings.chatAgentDisableThinking,
},
aiTools
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 360903e5b..42b7d9d9c 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -2192,6 +2192,14 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
const isSelfHosted = isSelfHostedTranscription(s);
const isCustomEndpoint = isSelfHosted || currentProvider === "custom";
+ // Never fall back to the cloud default for self-hosted — fail closed instead.
+ if (isSelfHosted) {
+ const normalizedRemote = normalizeBaseUrl(remoteUrl);
+ if (!normalizedRemote || !isSecureEndpoint(normalizedRemote)) {
+ throw new Error("Self-hosted transcription URL is invalid or unsupported");
+ }
+ }
+
if (
this.cachedTranscriptionEndpoint &&
(this.cachedEndpointProvider !== currentProvider ||
@@ -2338,6 +2346,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
{ error: error.message, stack: error.stack },
"transcription"
);
+ if (isSelfHosted) throw error;
this.cachedTranscriptionEndpoint = API_ENDPOINTS.TRANSCRIPTION;
this.cachedEndpointProvider = currentProvider;
this.cachedEndpointBaseUrl = currentBaseUrl;
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index eeb0d7034..1d18e2763 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -3983,8 +3983,40 @@ class IPCHandlers {
preferredLanguage && preferredLanguage !== "auto"
? preferredLanguage.split("-")[0]
: undefined;
+ const { resolveSelfHostedRetryRoute } = await import("./retryTranscriptionRouting.js");
+ const selfHostedRoute = resolveSelfHostedRetryRoute(settings);
- if (settings?.useLocalWhisper) {
+ if (selfHostedRoute?.kind === "configuration-error") {
+ throw new Error(selfHostedRoute.error);
+ }
+
+ if (selfHostedRoute?.kind === "self-hosted") {
+ const formData = new FormData();
+ formData.append("file", new Blob([buffer], { type: "audio/webm" }), "audio.webm");
+ if (selfHostedRoute.model) {
+ formData.append("model", selfHostedRoute.model);
+ }
+ if (language) {
+ formData.append("language", language);
+ }
+
+ const response = await proxyFetch(selfHostedRoute.endpoint, {
+ method: "POST",
+ body: formData,
+ });
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(`Self-hosted API Error: ${response.status} ${errorText}`);
+ }
+ const data = await response.json();
+ if (data?.text) {
+ result = {
+ text: data.text,
+ source: "self-hosted",
+ model: selfHostedRoute.model,
+ };
+ }
+ } else if (settings?.useLocalWhisper) {
if (settings.localTranscriptionProvider === "nvidia") {
const model =
settings.parakeetModel || process.env.PARAKEET_MODEL || "parakeet-tdt-0.6b-v3";
diff --git a/src/helpers/retryTranscriptionRouting.js b/src/helpers/retryTranscriptionRouting.js
new file mode 100644
index 000000000..8d889b546
--- /dev/null
+++ b/src/helpers/retryTranscriptionRouting.js
@@ -0,0 +1,41 @@
+import { buildApiUrl, normalizeBaseUrl } from "../config/constants.ts";
+import { isSecureEndpoint } from "../utils/urlUtils.ts";
+import { resolveSelfHostedTranscriptionModel } from "./selfHostedTranscription.js";
+
+export function resolveSelfHostedRetryRoute(settings) {
+ const mode =
+ typeof settings?.transcriptionMode === "string" ? settings.transcriptionMode.trim() : "";
+ if (mode !== "self-hosted") return null;
+
+ const configuredUrl =
+ typeof settings?.remoteTranscriptionUrl === "string"
+ ? settings.remoteTranscriptionUrl.trim()
+ : "";
+ if (!configuredUrl) {
+ return {
+ kind: "configuration-error",
+ error: "Self-hosted transcription URL is not configured",
+ };
+ }
+
+ const remoteUrl = configuredUrl.replace(/\/+$/, "");
+ const normalizedBaseUrl = normalizeBaseUrl(remoteUrl);
+ let hasSupportedProtocol = false;
+ try {
+ const protocol = new URL(normalizedBaseUrl).protocol;
+ hasSupportedProtocol = protocol === "http:" || protocol === "https:";
+ } catch {}
+
+ if (!normalizedBaseUrl || !hasSupportedProtocol || !isSecureEndpoint(normalizedBaseUrl)) {
+ return {
+ kind: "configuration-error",
+ error: "Self-hosted transcription URL is invalid or unsupported",
+ };
+ }
+
+ return {
+ kind: "self-hosted",
+ endpoint: buildApiUrl(normalizedBaseUrl, "/audio/transcriptions"),
+ model: resolveSelfHostedTranscriptionModel(settings),
+ };
+}
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index d87adbda7..cc6d6d96a 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -387,6 +387,9 @@ class ReasoningService extends BaseReasoningService {
const rawUrl = lanOverride || settings.cleanupRemoteUrl.trim();
const baseUrl = ensureV1Suffix(rawUrl);
endpoint = buildApiUrl(baseUrl, "/chat/completions");
+ apiKey =
+ config.customApiKey?.trim() ||
+ (lanOverride ? "" : settings.cleanupCustomApiKey?.trim() || "");
} else if (isLocalProvider) {
const serverResult = await window.electronAPI.llamaServerStart(model);
if (!serverResult.success || !serverResult.port) {
@@ -616,6 +619,9 @@ class ReasoningService extends BaseReasoningService {
} else if (isLanCleanup) {
const rawUrl = lanOverride || settings.cleanupRemoteUrl.trim();
baseURL = ensureV1Suffix(rawUrl);
+ apiKey =
+ config.customApiKey?.trim() ||
+ (lanOverride ? "" : settings.cleanupCustomApiKey?.trim() || "");
} else if (isLocalProvider) {
const serverResult = await window.electronAPI.llamaServerStart(model);
if (!serverResult.success || !serverResult.port) {
diff --git a/src/services/ai/providers.ts b/src/services/ai/providers.ts
index 940f18509..ff7831142 100644
--- a/src/services/ai/providers.ts
+++ b/src/services/ai/providers.ts
@@ -56,7 +56,7 @@ export async function getAIModel(
...(opts?.disableThinking ? { fetch: withDisabledReasoning } : {}),
}).chat(model);
case "local":
- return createOpenAI({ apiKey: "no-key", baseURL }).chat(model);
+ return createOpenAI({ apiKey: apiKey || "no-key", baseURL }).chat(model);
default:
throw new Error(`Unsupported AI SDK provider for renderer: ${provider}`);
}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 555e82a2d..55bbaae64 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -569,6 +569,7 @@ declare global {
transcriptionMode?: InferenceMode;
remoteTranscriptionType?: SelfHostedType;
remoteTranscriptionUrl?: string;
+ remoteTranscriptionModel?: string;
}
) => Promise<{
success: boolean;
diff --git a/test/helpers/retryTranscriptionRouting.test.js b/test/helpers/retryTranscriptionRouting.test.js
new file mode 100644
index 000000000..9e53c903d
--- /dev/null
+++ b/test/helpers/retryTranscriptionRouting.test.js
@@ -0,0 +1,100 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const load = () => import("../../src/helpers/retryTranscriptionRouting.js");
+
+test("selects self-hosted retry routing over stale cloud settings", async () => {
+ const { resolveSelfHostedRetryRoute } = await load();
+
+ for (const provider of ["groq", "openai", "mistral", "xai", "tinfoil", "custom"]) {
+ const route = resolveSelfHostedRetryRoute({
+ transcriptionMode: "self-hosted",
+ remoteTranscriptionUrl: "http://localhost:5001/v1",
+ remoteTranscriptionModel: " self-hosted-model ",
+ useLocalWhisper: true,
+ cloudTranscriptionMode: "openwhispr",
+ cloudTranscriptionProvider: provider,
+ cloudTranscriptionModel: "stale-cloud-model",
+ });
+
+ assert.deepEqual(route, {
+ kind: "self-hosted",
+ endpoint: "http://localhost:5001/v1/audio/transcriptions",
+ model: "self-hosted-model",
+ });
+ }
+});
+
+test("normalizes supported self-hosted URLs and allows private HTTP endpoints", async () => {
+ const { resolveSelfHostedRetryRoute } = await load();
+ const cases = [
+ ["http://localhost:5001", "http://localhost:5001/audio/transcriptions"],
+ ["http://localhost:5001/v1", "http://localhost:5001/v1/audio/transcriptions"],
+ ["http://127.0.0.1:5001/v1", "http://127.0.0.1:5001/v1/audio/transcriptions"],
+ ["http://192.168.1.20:5001/v1", "http://192.168.1.20:5001/v1/audio/transcriptions"],
+ [
+ "http://localhost:5001/v1/audio/transcriptions",
+ "http://localhost:5001/v1/audio/transcriptions",
+ ],
+ [
+ " http://localhost:5001/v1/audio/transcriptions/// ",
+ "http://localhost:5001/v1/audio/transcriptions",
+ ],
+ ];
+
+ for (const [remoteTranscriptionUrl, endpoint] of cases) {
+ const route = resolveSelfHostedRetryRoute({
+ transcriptionMode: "self-hosted",
+ remoteTranscriptionUrl,
+ });
+ assert.equal(route.kind, "self-hosted");
+ assert.equal(route.endpoint, endpoint);
+ }
+});
+
+test("fails closed for missing, malformed, or unsupported self-hosted URLs", async () => {
+ const { resolveSelfHostedRetryRoute } = await load();
+ const missingError = "Self-hosted transcription URL is not configured";
+ const invalidError = "Self-hosted transcription URL is invalid or unsupported";
+ const cases = [
+ [undefined, missingError],
+ [null, missingError],
+ ["", missingError],
+ [" ", missingError],
+ [42, missingError],
+ ["not a url", invalidError],
+ ["https://", invalidError],
+ ["ftp://localhost:5001/v1", invalidError],
+ ["http://example.com/v1", invalidError],
+ ];
+
+ for (const [remoteTranscriptionUrl, error] of cases) {
+ assert.deepEqual(
+ resolveSelfHostedRetryRoute({
+ transcriptionMode: "self-hosted",
+ remoteTranscriptionUrl,
+ useLocalWhisper: true,
+ cloudTranscriptionMode: "openwhispr",
+ cloudTranscriptionProvider: "groq",
+ }),
+ {
+ kind: "configuration-error",
+ error,
+ }
+ );
+ }
+});
+
+test("does not intercept non-self-hosted retry modes", async () => {
+ const { resolveSelfHostedRetryRoute } = await load();
+
+ for (const settings of [
+ { transcriptionMode: "local", useLocalWhisper: true },
+ { transcriptionMode: "openwhispr", cloudTranscriptionMode: "openwhispr" },
+ { transcriptionMode: "providers", cloudTranscriptionProvider: "tinfoil" },
+ { transcriptionMode: "providers", cloudTranscriptionProvider: "groq" },
+ {},
+ ]) {
+ assert.equal(resolveSelfHostedRetryRoute(settings), null);
+ }
+});