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
fix(dictation): warn when cleanup is on but no model can run (#2634)
Henry Su9434865bad33
diff --git a/src/components/CleanupFailureToastListener.tsx b/src/components/CleanupFailureToastListener.tsxindex 6b0a751a0..bf599ad87 100644--- a/src/components/CleanupFailureToastListener.tsx+++ b/src/components/CleanupFailureToastListener.tsx@@ -3,9 +3,9 @@ import { useTranslation } from "react-i18next";import { useToast } from "./ui/useToast";import { consumeCleanupFailures, useCleanupFailureStore } from "../stores/cleanupFailureStore";import { isDictationPanelWindow } from "../utils/windowContext";-import { providerErrorToastProps } from "../utils/describeProviderError";+import { providerErrorActions, providerErrorToastProps } from "../utils/describeProviderError";-/** Tells the user their dictation was pasted raw because AI cleanup failed. */+/** Tells the user their dictation went out raw because AI cleanup failed or can't run. */export default function CleanupFailureToastListener() {const { t } = useTranslation();const { toast } = useToast();@@ -18,6 +18,9 @@ export default function CleanupFailureToastListener() {const failure = state.lastFailure ?? { message: state.lastMessage };// Draining first keeps a re-run of this effect from toasting the same failure twice.if (consumeCleanupFailures() === 0) return;+ // Says the raw text was pasted only when it was: a held-back paste keeps its pill.+ const pasted = failure.pasted !== false;+ const pastedLine = pasted ? t("app.toasts.cleanupFailed.description") : "";// The panel may already be hidden after dictation; surface it so the toast is seen.if (isDictationPanelWindow()) {window.electronAPI?.showDictationPanel?.();@@ -28,12 +31,12 @@ export default function CleanupFailureToastListener() {toast({title: t("app.toasts.cleanupFailed.title"),// A line break, not a space, so CJK sentences don't get one after "。".- description: `${description}\n${t("app.toasts.cleanupFailed.description")}`,+ description: pastedLine ? `${description}\n${pastedLine}` : description,...(actions ? { actions } : {}),variant: "destructive",// The dictation has already pasted, so the card can take the pill's place// like a transcription failure does.- ...(isDictationPanelWindow() ? { presentation: "dictation-error" as const } : {}),+ ...(pasted && isDictationPanelWindow() ? { presentation: "dictation-error" as const } : {}),duration: 10000,});return;@@ -42,10 +45,13 @@ export default function CleanupFailureToastListener() {? t(failure.messageKey, failure.messageParams): failure.message || t("app.toasts.cleanupFailed.title");const description = failure.actionKey ? t(failure.actionKey) : failure.action;+ // Technical details carry their own copy button, so only the Settings link is added.+ const actions = providerErrorActions({ settingsTarget: failure.settingsTarget }, t);toast({title,...(description ? { description } : {}),- secondaryDescription: t("app.toasts.cleanupFailed.description"),+ ...(pastedLine ? { secondaryDescription: pastedLine } : {}),+ ...(actions.length ? { actions } : {}),...(failure.copyCommand ? { copyCommand: failure.copyCommand } : {}),technicalDetails: failure.technicalDetails,variant: "destructive",diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 79e82a6d9..2ba039ec3 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -65,6 +65,7 @@ import { usePolicyStore } from "../stores/policyStore";import {getBatchTranscriptionModel,getCloudModel,+ getProviderDisplayName,getTranscriptionProvider,getTranscriptionProviders,isOnlineParakeetModel,@@ -95,7 +96,13 @@ import {} from "./transcriptionFallback";import { transcriptionFailureOutcome } from "./transcriptionFailureOutcome";import { IPC_ERROR_FIELDS, errorFromIpcResult } from "./ipcErrorFields";-import { asProviderError, providerHttpError, redactProviderBody } from "./providerHttpErrors";+import {+ PROVIDER_ERROR_CODES,+ asProviderError,+ providerError,+ providerHttpError,+ redactProviderBody,+} from "./providerHttpErrors";import {executeTranslationChain,hasTextContent,@@ -108,6 +115,7 @@ import {stripAgentAddressPreservingFormatting,} from "../config/agentDetection";import {+ cleanupUnconfiguredNotice,resolveDictationRouteKind,resolveAgentImageTarget,resolveWakeWordLanguage,@@ -352,6 +360,7 @@ function resolveReasoningRoute(return {kind: "agent",+ cleanupReachable,model: target.model,config: {...target.config,@@ -374,9 +383,9 @@ function resolveReasoningRoute(};}if (kind === "cleanup") {- return { kind: "cleanup", config: cleanupConfig };+ return { kind: "cleanup", cleanupReachable, config: cleanupConfig };}- return { kind: "skip" };+ return { kind: "skip", cleanupReachable };}const PLACEHOLDER_KEYS = {@@ -688,6 +697,7 @@ class AudioManager {this.pendingSelectionEdit = null;this.pendingAssistantConversation = null;this.pendingCleanupFailure = null;+ this._shownCleanupSetupKey = null;this._processingCancellationGeneration = 0;this._activeProcessingPipeline = null;this.assistantSelectionContext = null;@@ -3208,6 +3218,38 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);}}+ // Runs wherever a dictation's route is decided, with the reachability that+ // decision used. The notice reaches the user through the result extras.+ _noteCleanupRoute(settings, { kind, cleanupReachable }) {+ const { forget, notice } = cleanupUnconfiguredNotice(this._shownCleanupSetupKey, {+ skipped: kind === "skip",+ cleanupReachable,+ settings,+ });+ if (forget) this._shownCleanupSetupKey = null;+ if (notice && !this.pendingCleanupFailure) this.pendingCleanupFailure = notice;+ }++ // A BYOK cleanup model is selected, but the availability check found no API key+ // for any provider, so this one has none either. Reports the failure the cleanup+ // route raises when it runs, as the Cloud and streaming paths already do.+ _noteMissingCleanupKey(settings) {+ const cleanup = selectResolvedLLMConfig(settings, "dictationCleanup");+ if (cleanup.mode !== "providers" || cleanup.provider === "custom") return;+ this.pendingCleanupFailure = cleanupFailureFromError(+ providerError(PROVIDER_ERROR_CODES.KEY_MISSING, {+ provider: getProviderDisplayName(cleanup.provider),+ surface: "llm",+ })+ );+ }++ // The renderer confirms an unconfigured-cleanup notice once it is on screen, so+ // a dictation cancelled or discarded before then never uses up the warning.+ markCleanupNoticeShown(failure) {+ if (failure?.setupKey) this._shownCleanupSetupKey = failure.setupKey;+ }+async processTranscription(text, source, wasCancelled = neverCancelled) {const result = await this.processTranscriptionCore(text, source, wasCancelled);if (wasCancelled()) return result;@@ -3252,6 +3294,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);logger.logReasoning("REASONING_SKIPPED", {reason: "No cleanup or dictation-agent model available",});+ this._noteCleanupRoute(settings, { kind: "skip", cleanupReachable });return normalizedText;}@@ -3264,6 +3307,11 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);cleanupProvider,agentName,});+ // Nothing can run cleanup although the assistant could, so no route is decided.+ if (!useReasoning) {+ this._noteCleanupRoute(settings, { kind: "skip", cleanupReachable });+ if (cleanupReachable) this._noteMissingCleanupKey(settings);+ }if (useReasoning) {let route;@@ -3280,6 +3328,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (this.translationRequested && route.kind !== "translation") {this.notifyTranslationFallback("unreachable");}+ this._noteCleanupRoute(settings, route);if (route.kind === "skip") return normalizedText;if (route.kind === "translation") {@@ -3606,6 +3655,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (this.translationRequested && route.kind !== "translation") {this.notifyTranslationFallback("unreachable");}+ this._noteCleanupRoute(settings, route);try {if (route.kind === "agent") {const reasoned = await this.processAgentCommand(@@ -5815,6 +5865,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (this.translationRequested && route.kind !== "translation") {this.notifyTranslationFallback("unreachable");}+ this._noteCleanupRoute(stSettings, route);const isCloudCleanup = isCloudCleanupMode();try {diff --git a/src/helpers/dictationRouting.js b/src/helpers/dictationRouting.jsindex 35f2c9659..5cb32d1b8 100644--- a/src/helpers/dictationRouting.js+++ b/src/helpers/dictationRouting.js@@ -203,3 +203,43 @@ export function resolveDictationRouteKind({}return "skip";}++// A dictation skipped while cleanup is switched on goes out raw, which looks like+// a cleanup that changed nothing, so it carries a notice. `shownKey` names the+// broken setup the user was last warned about: the same one warns once, while a+// different mode or provider, or signing out, warns again. Once cleanup is off or+// reachable the warning is forgotten (`forget`), so the next broken setup warns.+// Signed out of OpenWhispr Cloud gets its own message, since the fix is signing in.+// The "llm" surface gives it the same friendly cleanup toast as a provider failure.+export function cleanupUnconfiguredNotice(shownKey, { skipped, cleanupReachable, settings }) {+ if (!settings.useCleanupModel || cleanupReachable) return { forget: true, notice: null };+ if (!skipped) return { forget: false, notice: null };+ const signedOut =+ settings.cleanupMode === "openwhispr" &&+ settings.cleanupCloudMode === "openwhispr" &&+ !settings.isSignedIn;+ const setupKey = [+ signedOut ? "signedOut" : "unconfigured",+ settings.cleanupMode || "",+ settings.cleanupProvider || "",+ ].join("\0");+ if (setupKey === shownKey) return { forget: false, notice: null };+ return {+ forget: false,+ notice: signedOut+ ? {+ message: "AI cleanup uses OpenWhispr Cloud, but you're signed out.",+ messageKey: "hooks.audioRecording.cleanupSignedOut",+ surface: "llm",+ settingsTarget: "llms",+ setupKey,+ }+ : {+ message: "AI cleanup is on, but no cleanup model is set up.",+ messageKey: "hooks.audioRecording.cleanupUnconfigured",+ surface: "llm",+ settingsTarget: "llms",+ setupKey,+ },+ };+}diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.jsindex f0bf7083c..efcb7f7dd 100644--- a/src/hooks/useAudioRecording.js+++ b/src/hooks/useAudioRecording.js@@ -789,6 +789,7 @@ export const useAudioRecording = (toast, options = {}) => {// generation when the attempt began: if the next dictation started while// it waited, that recording owns the pill (and would dismiss this one at// once) and its live preview, so the transcript only stays on the clipboard.+ let heldBehindNewerDictation = false;const reportHeldBackPaste = async (delivery,{ title, description, descriptionClipboardFailed, onRetry },@@ -801,6 +802,7 @@ export const useAudioRecording = (toast, options = {}) => {{ delivery, keptInClipboard },"clipboard");+ heldBehindNewerDictation = true;return;}window.electronAPI?.hideDictationPreview?.();@@ -856,6 +858,7 @@ export const useAudioRecording = (toast, options = {}) => {return pasteOutcome.pasted;};+ let pasted = false;if (pushForceStoppedRef.current && autoPasteEnabled && !result.assistantConversation) {// The push hit its safety ceiling while the trigger keys were still// down. Injecting the paste shortcut into those held modifiers is@@ -928,12 +931,26 @@ export const useAudioRecording = (toast, options = {}) => {// visible somewhere.if (pasteSucceeded) {window.electronAPI?.hideDictationPreview?.();- if (result.cleanupFailure) recordCleanupFailure(result.cleanupFailure);}+ pasted = pasteSucceeded;} else if (keepTranscriptionInClipboard && !result.assistantConversation) {await keepInClipboard("clipboard-only");}+ // Cleanup can be missing or can fail whether or not the paste landed+ // (#2631, #1003), so the toast is told which. The onboarding demo's+ // paste is a no-op into its own text box, so it reports nothing there.+ // A paste held back behind a newer dictation stays quiet too: that+ // recording owns the pill, and an unconfigured warning stays unspent.+ if (+ result.cleanupFailure &&+ !heldBehindNewerDictation &&+ localStorage.getItem("onboardingCompleted") === "true"+ ) {+ recordCleanupFailure({ ...result.cleanupFailure, pasted });+ audioManagerRef.current.markCleanupNoticeShown(result.cleanupFailure);+ }+if (result.source === "openai" && getSettings().useLocalWhisper) {toast({title: t("hooks.audioRecording.fallback.title"),diff --git a/src/locales/ar/translation.json b/src/locales/ar/translation.jsonindex 5dacbb14f..b75c586a3 100644--- a/src/locales/ar/translation.json+++ b/src/locales/ar/translation.json@@ -1,6 +1,8 @@{"hooks": {"audioRecording": {+ "cleanupSignedOut": "يستخدم تنظيف الذكاء الاصطناعي OpenWhispr Cloud، لكنك لم تسجّل الدخول.",+ "cleanupUnconfigured": "تنظيف الذكاء الاصطناعي مفعّل، ولكن لم يُضبط نموذج للتنظيف.","errorTitles": {"sessionExpired": "انتهت الجلسة","offline": "أنت غير متصل بالإنترنت",diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex 3e3f1f960..baeccfb13 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "Die KI-Bereinigung nutzt OpenWhispr Cloud, aber Sie sind abgemeldet.",+ "cleanupUnconfigured": "Die KI-Bereinigung ist aktiv, aber es ist kein Bereinigungsmodell eingerichtet.","errorTitles": {"sessionExpired": "Sitzung abgelaufen","offline": "Sie sind offline",diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex b96f5cf8b..7bdcf9d5d 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "AI cleanup uses OpenWhispr Cloud, but you're signed out.",+ "cleanupUnconfigured": "AI cleanup is on, but no cleanup model is set up.","errorTitles": {"sessionExpired": "Session Expired","offline": "You're Offline",diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex 5920a7eb9..f26488965 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "La limpieza con IA usa OpenWhispr Cloud, pero no has iniciado sesión.",+ "cleanupUnconfigured": "La limpieza con IA está activada, pero no hay un modelo de limpieza configurado.","errorTitles": {"sessionExpired": "Sesión expirada","offline": "Sin conexión",diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex d50da811c..8f1b462ff 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "Le nettoyage IA utilise OpenWhispr Cloud, mais vous n'êtes pas connecté.",+ "cleanupUnconfigured": "Le nettoyage IA est activé, mais aucun modèle de nettoyage n'est configuré.","errorTitles": {"sessionExpired": "Session expirée","offline": "Vous êtes hors ligne",diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex 433623af0..879e00412 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "La pulizia IA usa OpenWhispr Cloud, ma non hai effettuato l'accesso.",+ "cleanupUnconfigured": "La pulizia IA è attiva, ma non è configurato alcun modello di pulizia.","errorTitles": {"sessionExpired": "Sessione scaduta","offline": "Sei offline",diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex 6897a778a..ec56883a9 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "AIクリーンアップはOpenWhispr Cloudを使用しますが、サインインしていません。",+ "cleanupUnconfigured": "AIクリーンアップはオンですが、クリーンアップモデルが設定されていません。","errorTitles": {"sessionExpired": "セッション期限切れ","offline": "オフラインです",diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex e4d479390..6ef3e20f4 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -877,6 +877,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "A limpeza por IA usa o OpenWhispr Cloud, mas você não está conectado.",+ "cleanupUnconfigured": "A limpeza por IA está ativada, mas nenhum modelo de limpeza foi configurado.","errorTitles": {"sessionExpired": "Sessão expirada","offline": "Sem conexão",diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex a78dad848..e799e95a7 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "ИИ-очистка использует OpenWhispr Cloud, но вы не вошли в аккаунт.",+ "cleanupUnconfigured": "ИИ-очистка включена, но модель очистки не настроена.","errorTitles": {"sessionExpired": "Сессия истекла","offline": "Нет подключения к интернету",diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex e67b2d057..fd4392085 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "AI 清理使用 OpenWhispr Cloud,但你尚未登录。",+ "cleanupUnconfigured": "已开启 AI 清理,但尚未设置清理模型。","errorTitles": {"sessionExpired": "会话已过期","offline": "你已离线",diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex c018353d6..8a16b7486 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -898,6 +898,8 @@},"hooks": {"audioRecording": {+ "cleanupSignedOut": "AI 清理使用 OpenWhispr Cloud,但你尚未登入。",+ "cleanupUnconfigured": "已開啟 AI 清理,但尚未設定清理模型。","errorTitles": {"sessionExpired": "工作階段已過期","offline": "你目前離線",diff --git a/src/stores/cleanupFailureStore.ts b/src/stores/cleanupFailureStore.tsindex e7330f9dd..e9907422b 100644--- a/src/stores/cleanupFailureStore.ts+++ b/src/stores/cleanupFailureStore.ts@@ -11,6 +11,10 @@ export interface CleanupFailure {actionKey?: string;copyCommand?: string;technicalDetails?: TechnicalErrorDetailsData;+ /** False when the raw dictation never reached the cursor (held back, clipboard only). */+ pasted?: boolean;+ /** Names the broken setup an unconfigured-cleanup notice warns about. */+ setupKey?: string;}interface CleanupFailureState {diff --git a/test/helpers/audioManagerCleanupUnconfigured.test.js b/test/helpers/audioManagerCleanupUnconfigured.test.jsnew file mode 100644index 000000000..a94497b96--- /dev/null+++ b/test/helpers/audioManagerCleanupUnconfigured.test.js@@ -0,0 +1,145 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const { createRendererServer, installBrowserGlobals } = require("../lib/rendererTestHarness");++const UNCONFIGURED = "hooks.audioRecording.cleanupUnconfigured";+const SIGNED_OUT = "hooks.audioRecording.cleanupSignedOut";++async function loadRealAudioManager(t) {+ const { window } = installBrowserGlobals(t, { window: { dispatchEvent() {} } });+ Object.defineProperty(navigator, "onLine", { configurable: true, value: true });+ t.after(() => delete navigator.onLine);+ const vite = await createRendererServer(t, {+ cachePrefix: "openwhispr-audio-cleanup-unconfigured-",+ mockModules: {+ "/utils/logger":+ "export default { debug() {}, info() {}, warn() {}, error() {}, logReasoning() {} };",+ },+ });+ const AudioManager = (await vite.ssrLoadModule("/helpers/audioManager.js")).default;+ const service = (await vite.ssrLoadModule("/services/ReasoningService.ts")).default;+ t.after(() => service.destroy());+ const { useSettingsStore } = await vite.ssrLoadModule("/stores/settingsStore.ts");+ const { usePolicyStore } = await vite.ssrLoadModule("/stores/policyStore.ts");+ usePolicyStore.setState({ status: "unmanaged", policy: null });+ useSettingsStore.setState({+ isSignedIn: false,+ useCleanupModel: true,+ cleanupMode: "providers",+ cleanupProvider: "openai",+ cleanupModel: "",+ useDictationAgent: false,+ useDictationTranslation: false,+ customPrompts: { cleanup: "" },+ preferredLanguage: "en",+ });+ const manager = Object.assign(Object.create(AudioManager.prototype), {+ voiceAgentRequested: false,+ translationRequested: false,+ pendingCleanupFailure: null,+ _shownCleanupSetupKey: null,+ getEffectiveSttLanguage: () => "en",+ getWhisperPrompt: () => null,+ isDictionaryEcho: () => false,+ isReasoningAvailable: async () => true,+ finalizeChineseScript: async (text) => text,+ });+ return { window, manager, setSettings: (next) => useSettingsStore.setState(next) };+}++async function dictate(manager, text) {+ assert.equal(await manager.processTranscriptionCore(text, "local"), text);+ return manager._takePendingResultExtras().cleanupFailure;+}++test("cleanup on with no model warns once it is shown, and again after a fix breaks", async (t) => {+ const { window, manager, setSettings } = await loadRealAudioManager(t);++ const first = await dictate(manager, "hello there");+ assert.equal(first.messageKey, UNCONFIGURED);+ assert.equal(first.settingsTarget, "llms");++ // A notice that never reached the screen (a cancelled dictation) is not used up.+ assert.equal((await dictate(manager, "hello again")).messageKey, UNCONFIGURED);+ manager.markCleanupNoticeShown(first);+ assert.equal(await dictate(manager, "and again"), undefined);++ // A reachable model runs cleanup and forgets the warning, so the same broken+ // setup warns again once the model is gone.+ setSettings({ cleanupMode: "local", cleanupProvider: "local", cleanupModel: "test-model" });+ window.electronAPI.processLocalReasoning = async () => ({ success: true, text: "Cleaned." });+ assert.equal(await manager.processTranscriptionCore("fixed now", "local"), "Cleaned.");+ assert.equal(manager._takePendingResultExtras().cleanupFailure, undefined);+ setSettings({ cleanupMode: "providers", cleanupProvider: "openai", cleanupModel: "" });+ assert.equal((await dictate(manager, "broken again")).messageKey, UNCONFIGURED);++ setSettings({ useCleanupModel: false });+ assert.equal(await dictate(manager, "cleanup off"), undefined);++ setSettings({ useCleanupModel: true, cleanupMode: "openwhispr", cleanupCloudMode: "openwhispr" });+ assert.equal((await dictate(manager, "signed out")).messageKey, SIGNED_OUT);+});++test("cleanup with nothing to run on warns even when the assistant is reachable", async (t) => {+ const { manager, setSettings } = await loadRealAudioManager(t);+ // The Cloud assistant skips the early "no model" return; cleanup still can't run.+ setSettings({+ isSignedIn: true,+ useDictationAgent: true,+ dictationAgentMode: "openwhispr",+ dictationAgentCloudMode: "openwhispr",+ });+ manager.isReasoningAvailable = async () => false;+ assert.equal((await dictate(manager, "local words")).messageKey, UNCONFIGURED);+});++test("a BYOK cleanup model with no API key reports the missing key", async (t) => {+ const { manager, setSettings } = await loadRealAudioManager(t);+ // A model is selected, but no provider has a key, so the availability check fails.+ setSettings({ cleanupModel: "gpt-5-mini" });+ manager.isReasoningAvailable = async () => false;++ const failure = await dictate(manager, "no key words");+ assert.equal(failure.messageKey, "providerErrors.keyMissing");+ assert.deepEqual(failure.messageParams, { provider: "OpenAI" });+ assert.equal(failure.surface, "llm");+ assert.equal(failure.settingsTarget, "llms");++ // A local model needs no key, so it is never reported as one missing.+ setSettings({ cleanupMode: "local", cleanupProvider: "local", cleanupModel: "test-model" });+ assert.equal(await dictate(manager, "local model words"), undefined);+});++test("the Cloud batch and streaming paths warn when they skip an unreachable cleanup", async (t) => {+ const { window, manager, setSettings } = await loadRealAudioManager(t);+ // Signed in for Cloud transcription, with cleanup set to providers and no model.+ setSettings({ isSignedIn: true, cleanupCloudMode: "openwhispr" });+ window.electronAPI.cloudTranscribe = async () => ({ success: true, text: "cloud words" });+ window.electronAPI.cloudStreamingUsage = async () => ({ success: true });++ const batch = await manager.processWithOpenWhisprCloud(new Blob(["synthetic audio"]));+ assert.equal(batch.text, "cloud words");+ assert.equal(manager._takePendingResultExtras().cleanupFailure?.messageKey, UNCONFIGURED);++ let streamed;+ Object.assign(manager, {+ streamingFinalText: "streamed words",+ streamingCleanupFns: [],+ micRecovery: { stop() {} },+ finishStreamingFallbackSegment: async () => {},+ mergeRecordedSegments: async () => null,+ awaitStreamingTextSettled: async () => {},+ getStreamingProvider: () => ({+ awaitsFinalTranscript: true,+ stop: async () => ({ success: true }),+ }),+ getStreamingProviderName: () => "openwhispr",+ shouldUseStreaming: () => false,+ onTranscriptionComplete: (value) => {+ streamed = value;+ },+ });+ await manager._finalizeStreamingRecording(null);+ assert.equal(streamed.text, "streamed words");+ assert.equal(streamed.cleanupFailure?.messageKey, UNCONFIGURED);+});diff --git a/test/helpers/cleanupFailureToast.test.js b/test/helpers/cleanupFailureToast.test.jsindex dff5dcb68..ec7eafd6e 100644--- a/test/helpers/cleanupFailureToast.test.js+++ b/test/helpers/cleanupFailureToast.test.js@@ -103,7 +103,16 @@ test("technical AWS details use the selected UI language", async (t) => {assert.match(markup, /aria-label="Copiar detalles técnicos"/);});-async function recordClassifiedCleanupFailure(t, { dictationWindow }) {+const CLASSIFIED_FAILURE = {+ message: "OpenAI rejected your API key.",+ surface: "llm",+ messageKey: "providerErrors.authFailed",+ messageParams: { provider: "OpenAI" },+ settingsTarget: "llms",+ technicalDetails: { provider: "OpenAI", status: 401 },+};++async function recordCleanupFailureToast(t, { dictationWindow, failure = CLASSIFIED_FAILURE }) {let root = null;t.after(async () => {if (root) await React.act(async () => root.unmount());@@ -138,21 +147,12 @@ async function recordClassifiedCleanupFailure(t, { dictationWindow }) {root = createRoot(container);await React.act(async () => root.render(React.createElement(CleanupFailureToastListener)));- await React.act(async () =>- recordCleanupFailure({- message: "OpenAI rejected your API key.",- surface: "llm",- messageKey: "providerErrors.authFailed",- messageParams: { provider: "OpenAI" },- settingsTarget: "llms",- technicalDetails: { provider: "OpenAI", status: 401 },- })- );+ await React.act(async () => recordCleanupFailure(failure));return globalThis.__cleanupFailureToasts.at(-1);}test("a classified cleanup failure says why, then that the dictation went in raw, with Open Settings and Copy details", async (t) => {- const toastProps = await recordClassifiedCleanupFailure(t, { dictationWindow: false });+ const toastProps = await recordCleanupFailureToast(t, { dictationWindow: false });assert.equal(toastProps.title, "Cleanup failed");assert.equal(toastProps.description,@@ -171,8 +171,80 @@ test("a classified cleanup failure says why, then that the dictation went in raw});test("in the dictation window a classified cleanup failure uses the pill's error card", async (t) => {- const toastProps = await recordClassifiedCleanupFailure(t, { dictationWindow: true });+ const toastProps = await recordCleanupFailureToast(t, { dictationWindow: true });assert.equal(toastProps.presentation, "dictation-error");assert.equal(toastProps.duration, 10_000);assert.equal(toastProps.actions.length, 2);});++test("a classified failure whose paste was held back leaves the pill alone and claims no paste", async (t) => {+ const toastProps = await recordCleanupFailureToast(t, {+ dictationWindow: true,+ failure: { ...CLASSIFIED_FAILURE, pasted: false },+ });+ assert.equal(toastProps.title, "Cleanup failed");+ assert.equal(toastProps.description, "OpenAI rejected your API key.");+ assert.equal(toastProps.presentation, undefined, "the held-back paste keeps its pill");+});++// The shape cleanupUnconfiguredNotice returns (pinned in dictationRouting.test.js).+const UNCONFIGURED_NOTICE = {+ message: "AI cleanup is on, but no cleanup model is set up.",+ messageKey: "hooks.audioRecording.cleanupUnconfigured",+ surface: "llm",+ settingsTarget: "llms",+ setupKey: "unconfigured\0providers\0",+};++test("an unconfigured-cleanup notice takes the pill's error card with Open Settings", async (t) => {+ const toastProps = await recordCleanupFailureToast(t, {+ dictationWindow: true,+ failure: { ...UNCONFIGURED_NOTICE, pasted: true },+ });+ assert.equal(toastProps.title, "Cleanup failed");+ assert.equal(+ toastProps.description,+ "AI cleanup is on, but no cleanup model is set up.\nOriginal dictation pasted without AI cleanup."+ );+ assert.deepEqual(+ toastProps.actions.map(({ label }) => label),+ ["Open Settings"]+ );+ assert.equal(toastProps.presentation, "dictation-error");+});++test("an unconfigured-cleanup notice for a dictation that was not pasted claims no paste", async (t) => {+ const toastProps = await recordCleanupFailureToast(t, {+ dictationWindow: true,+ failure: { ...UNCONFIGURED_NOTICE, pasted: false },+ });+ assert.equal(toastProps.description, "AI cleanup is on, but no cleanup model is set up.");+ assert.deepEqual(+ toastProps.actions.map(({ label }) => label),+ ["Open Settings"]+ );+ assert.equal(toastProps.presentation, undefined, "the held-back paste keeps its pill");+});++test("a signed-out Cloud cleanup notice says the fix is signing in", async (t) => {+ const toastProps = await recordCleanupFailureToast(t, {+ dictationWindow: false,+ failure: {+ message: "AI cleanup uses OpenWhispr Cloud, but you're signed out.",+ messageKey: "hooks.audioRecording.cleanupSignedOut",+ surface: "llm",+ settingsTarget: "llms",+ setupKey: "signedOut\0openwhispr\0",+ pasted: true,+ },+ });+ assert.equal(toastProps.title, "Cleanup failed");+ assert.equal(+ toastProps.description,+ "AI cleanup uses OpenWhispr Cloud, but you're signed out.\nOriginal dictation pasted without AI cleanup."+ );+ assert.deepEqual(+ toastProps.actions.map(({ label }) => label),+ ["Open Settings"]+ );+});diff --git a/test/helpers/dictationRouting.test.js b/test/helpers/dictationRouting.test.jsindex 7af0b40c8..a42be7f95 100644--- a/test/helpers/dictationRouting.test.js+++ b/test/helpers/dictationRouting.test.js@@ -790,3 +790,66 @@ test("lifecycle input kind prefers assistant, then translation, then dictation",);assert.equal(resolveLifecycleInputKind({}), "dictation");});++test("an unconfigured cleanup warns once per broken setup, and again once it was fixed", async () => {+ const { cleanupUnconfiguredNotice } = await load();+ const settings = {+ useCleanupModel: true,+ cleanupMode: "providers",+ cleanupProvider: "openai",+ isSignedIn: false,+ };+ const skipped = { skipped: true, cleanupReachable: false, settings };++ const first = cleanupUnconfiguredNotice(null, skipped);+ assert.equal(first.forget, false);+ assert.equal(first.notice.messageKey, "hooks.audioRecording.cleanupUnconfigured");+ assert.equal(first.notice.settingsTarget, "llms");+ assert.equal(first.notice.surface, "llm", "it gets the friendly cleanup toast");++ const shownKey = first.notice.setupKey;+ assert.equal(cleanupUnconfiguredNotice(shownKey, skipped).notice, null);+ const otherProvider = cleanupUnconfiguredNotice(shownKey, {+ ...skipped,+ settings: { ...settings, cleanupProvider: "anthropic" },+ });+ assert.notEqual(otherProvider.notice, null, "a different broken setup warns again");++ // Only a skipped dictation warns; a wake-word command was handled by the agent.+ assert.deepEqual(cleanupUnconfiguredNotice(null, { ...skipped, skipped: false }), {+ forget: false,+ notice: null,+ });++ for (const fixed of [+ { ...skipped, cleanupReachable: true },+ { ...skipped, settings: { ...settings, useCleanupModel: false } },+ ]) {+ assert.deepEqual(cleanupUnconfiguredNotice(shownKey, fixed), { forget: true, notice: null });+ }+});++test("signed out of OpenWhispr Cloud, the cleanup notice says so", async () => {+ const { cleanupUnconfiguredNotice } = await load();+ const cloud = {+ useCleanupModel: true,+ cleanupMode: "openwhispr",+ cleanupCloudMode: "openwhispr",+ isSignedIn: false,+ };+ const { notice } = cleanupUnconfiguredNotice(null, {+ skipped: true,+ cleanupReachable: false,+ settings: cloud,+ });+ assert.equal(notice.messageKey, "hooks.audioRecording.cleanupSignedOut");+ assert.equal(notice.settingsTarget, "llms");+ assert.equal(notice.surface, "llm");++ const byok = cleanupUnconfiguredNotice(null, {+ skipped: true,+ cleanupReachable: false,+ settings: { ...cloud, cleanupCloudMode: "byok" },+ });+ assert.equal(byok.notice.messageKey, "hooks.audioRecording.cleanupUnconfigured");+});diff --git a/test/helpers/useAudioRecordingCleanupFallback.test.js b/test/helpers/useAudioRecordingCleanupFallback.test.jsindex dc66fc70b..6b00b1828 100644--- a/test/helpers/useAudioRecordingCleanupFallback.test.js+++ b/test/helpers/useAudioRecordingCleanupFallback.test.js@@ -15,6 +15,7 @@ export default class FakeAudioManager {this.translationRequested = false;this.sttConfig = { success: true };this.pasteCalls = 0;+ this.shownNotices = [];globalThis.__cleanupFallbackManager = this;}setCallbacks(callbacks) { this.callbacks = callbacks; }@@ -22,14 +23,16 @@ export default class FakeAudioManager {shouldUseStreaming() { return false; }async safePaste() {this.pasteCalls += 1;- return { pasted: globalThis.__cleanupFallbackPasteOutcome?.pasted === true };+ const outcome = globalThis.__cleanupFallbackPasteOutcome || {};+ return { pasted: outcome.pasted === true, ...(outcome.reason ? { reason: outcome.reason } : {}) };}+ markCleanupNoticeShown(failure) { this.shownNotices.push(failure); }async saveTranscription() { return true; }cleanup() {}}`;-test("raw cleanup fallback is reported only after the original dictation is pasted", async (t) => {+test("a raw cleanup fallback is reported with whether the dictation was pasted", async (t) => {let root = null;t.after(async () => {if (root) await React.act(async () => root.unmount());@@ -49,12 +52,14 @@ test("raw cleanup fallback is reported only after the original dictation is pastonCancelDictationPreparation: noopDispose,onStopDictation: noopDispose,completeDictationPreview: async () => {},+ writeClipboard: async () => ({ success: true }),hideDictationPreview: async () => {},dictationLifecycleStateChanged: () => {},},},});const container = installHookDom(t);+ localStorage.setItem("onboardingCompleted", "true");const vite = await createRendererServer(t, {cachePrefix: "openwhispr-cleanup-fallback-hook-",mockModules: {@@ -94,19 +99,41 @@ test("raw cleanup fallback is reported only after the original dictation is pastcleanupFailure,};- globalThis.__cleanupFallbackPasteOutcome = { success: true, pasted: true };- await React.act(async () => manager.callbacks.onTranscriptionComplete({ ...result }));+ const recorded = async (pasteOutcome) => {+ useCleanupFailureStore.setState({ pending: 0, lastFailure: null });+ manager.shownNotices = [];+ globalThis.__cleanupFallbackPasteOutcome = pasteOutcome;+ await React.act(async () => manager.callbacks.onTranscriptionComplete({ ...result }));+ const { pending, lastFailure } = useCleanupFailureStore.getState();+ return { pending, lastFailure, shown: manager.shownNotices };+ };++ let report = await recorded({ success: true, pasted: true });assert.equal(manager.pasteCalls, 1);- assert.equal(useCleanupFailureStore.getState().pending, 1);- assert.deepEqual(useCleanupFailureStore.getState().lastFailure, cleanupFailure);+ assert.equal(report.pending, 1);+ assert.deepEqual(report.lastFailure, { ...cleanupFailure, pasted: true });+ assert.deepEqual(report.shown, [cleanupFailure]);- useCleanupFailureStore.setState({ pending: 0, lastFailure: null });- globalThis.__cleanupFallbackPasteOutcome = { success: true, pasted: false };- await React.act(async () => manager.callbacks.onTranscriptionComplete({ ...result }));- assert.equal(useCleanupFailureStore.getState().pending, 0);+ // A paste that did not land still reports the cause, without claiming the paste.+ report = await recorded({ success: true, pasted: false });+ assert.equal(report.pending, 1);+ assert.equal(report.lastFailure.pasted, false);++ // Held back for still-held modifiers: the pill shows and the cause is reported too.+ report = await recorded({ success: true, pasted: false, reason: "modifiers-held" });+ assert.equal(report.pending, 1);+ assert.equal(report.lastFailure.pasted, false);useSettingsStore.setState({ autoPasteEnabled: false, keepTranscriptionInClipboard: false });- globalThis.__cleanupFallbackPasteOutcome = { success: true, pasted: true };- await React.act(async () => manager.callbacks.onTranscriptionComplete({ ...result }));- assert.equal(useCleanupFailureStore.getState().pending, 0);+ report = await recorded({ success: true, pasted: true });+ assert.equal(report.pending, 1);+ assert.equal(report.lastFailure.pasted, false);++ // The onboarding demo's paste is a no-op into its own text box: nothing is+ // reported, and an unconfigured-cleanup warning is not used up.+ useSettingsStore.setState({ autoPasteEnabled: true });+ localStorage.setItem("onboardingCompleted", "false");+ report = await recorded({ success: true, pasted: false });+ assert.equal(report.pending, 0);+ assert.deepEqual(report.shown, []);});diff --git a/test/helpers/useAudioRecordingForceStop.test.js b/test/helpers/useAudioRecordingForceStop.test.jsindex 0734b00ab..b2c07968d 100644--- a/test/helpers/useAudioRecordingForceStop.test.js+++ b/test/helpers/useAudioRecordingForceStop.test.js@@ -36,6 +36,9 @@ export default class FakeAudioManager {globalThis.__forceStopPastes.push({ text, options });return globalThis.__forceStopPasteOutcome;}+ markCleanupNoticeShown(failure) {+ globalThis.__forceStopShownNotices.push(failure);+ }saveTranscription() {return Promise.resolve(true);}@@ -149,6 +152,7 @@ async function mountHarness(globalThis.__forceStopPastes = [];globalThis.__forceStopPasteOutcome = pasteOutcome;globalThis.__forceStopStarts = 0;+ globalThis.__forceStopShownNotices = [];const vite = await createRendererServer(t, {cachePrefix: "openwhispr-audio-recording-force-stop-",@@ -162,6 +166,8 @@ async function mountHarness(},});const { useAudioRecording } = await vite.ssrLoadModule("/hooks/useAudioRecording.js");+ const { useCleanupFailureStore } = await vite.ssrLoadModule("/stores/cleanupFailureStore.ts");+ useCleanupFailureStore.setState({ pending: 0, lastFailure: null });const api = {};// Stable like the app's ToastProvider callback: a new identity per render@@ -188,6 +194,8 @@ async function mountHarness(dismissals,previewHides: () => previewHides,recordingStarts: () => globalThis.__forceStopStarts,+ cleanupReports: () => useCleanupFailureStore.getState().pending,+ shownNotices: () => globalThis.__forceStopShownNotices,setRecording: async (isRecording) => {await React.act(async () =>globalThis.__forceStopAudioManager.callbacks.onStateChange({@@ -446,6 +454,27 @@ test("a paste held back after the next recording started keeps the transcript quassert.equal(harness.lifecycle.at(-1), "recording");});+test("a paste held back behind the next recording reports no cleanup failure", async (t) => {+ const paste = deferredPaste();+ const harness = await mountHarness(t, { pasteOutcome: paste.outcome });+ localStorage.setItem("onboardingCompleted", "true");+ const cleanupFailure = {+ message: "AI cleanup is on, but no cleanup model is set up.",+ messageKey: "hooks.audioRecording.cleanupUnconfigured",+ settingsTarget: "llms",+ setupKey: "unconfigured",+ };+ await harness.complete({ cleanupFailure }, { detach: true });++ await harness.startRecording();+ await harness.setRecording(true);+ await paste.settle({ pasted: false, reason: "modifiers-held" });+ await harness.flush();++ assert.equal(harness.cleanupReports(), 0, "the new recording owns the window");+ assert.deepEqual(harness.shownNotices(), [], "the warning stays unspent");+});+// Retry shows no progress while the paste waits on held keys, so a second click// is likely; it must not queue a second paste of the same text.test("a double-clicked Retry pastes once", async (t) => {