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(translation): treat whitespace-only chain results as empty (#1618)
Henry Suf80d8f49a756
diff --git a/src/helpers/translationChain.js b/src/helpers/translationChain.jsindex 1739632a9..869d577b4 100644--- a/src/helpers/translationChain.js+++ b/src/helpers/translationChain.js@@ -34,7 +34,7 @@ export async function executeTranslationChain({if (cleanupReachable) {try {const cleaned = await runCleanup(out);- if (cleaned) out = cleaned;+ if (normalizeComparableText(cleaned)) out = cleaned;// Cloud cleanup counts as cloud reasoning once its call succeeds, even if it// returned empty text.if (cleanupIsCloud) usedCloudReasoning = true;@@ -64,5 +64,5 @@ export async function executeTranslationChain({// Keep the chain result only when it produced text; an empty/missing result// preserves the input so a dictation is never overwritten with nothing.export function resolveTranslatedText(previousText, chainResult) {- return chainResult?.text ? chainResult.text : previousText;+ return normalizeComparableText(chainResult?.text) ? chainResult.text : previousText;}diff --git a/test/helpers/translationChain.test.js b/test/helpers/translationChain.test.jsindex e8b6295e0..46b73b5e8 100644--- a/test/helpers/translationChain.test.js+++ b/test/helpers/translationChain.test.js@@ -81,6 +81,51 @@ test("cleanup throws: onCleanupError fires, translate runs on original text", asassert.equal(result.text, "translated(raw)");});+test("cleanup returns whitespace-only: text unchanged, translate still runs", async () => {+ const { executeTranslationChain } = await load();++ const result = await executeTranslationChain(+ makeOpts({+ runCleanup: async () => " ",+ runTranslate: async (currentText) => `translated(${currentText})`,+ })+ );++ assert.equal(result.text, "translated(raw)");+});++test("translate returns whitespace-only: onEmptyTranslate fires, cleaned text kept", async () => {+ const { executeTranslationChain } = await load();+ let emptyCalled = false;++ const result = await executeTranslationChain(+ makeOpts({+ runCleanup: async () => "cleaned",+ runTranslate: async () => "\u00a0",+ onEmptyTranslate: () => {+ emptyCalled = true;+ },+ })+ );++ assert.equal(emptyCalled, true);+ assert.equal(result.text, "cleaned");+});++test("shouldTranslate false: whitespace-only cleanup keeps the original text", async () => {+ const { executeTranslationChain } = await load();++ const result = await executeTranslationChain(+ makeOpts({+ text: "hello world",+ shouldTranslate: false,+ runCleanup: async () => " ",+ })+ );++ assert.equal(result.text, "hello world");+});+test("cleanup returns empty: text unchanged, translate still runs", async () => {const { executeTranslationChain } = await load();@@ -301,6 +346,8 @@ test("resolveTranslatedText: empty chain result keeps processedText", async () =const { resolveTranslatedText } = await load();assert.equal(resolveTranslatedText("raw dictation", { text: "" }), "raw dictation");+ assert.equal(resolveTranslatedText("raw dictation", { text: " " }), "raw dictation");+ assert.equal(resolveTranslatedText("raw dictation", { text: "\u00a0" }), "raw dictation");assert.equal(resolveTranslatedText("raw dictation", { text: null }), "raw dictation");assert.equal(resolveTranslatedText("raw dictation", {}), "raw dictation");});