Skip to content

The agent that grows with you

fix(desktop): unwrap Mistral Voxtral JSON in client-direct STT

HexLab98bc737576ba25
diff --git a/apps/desktop/src/lib/voice-client-direct.ts b/apps/desktop/src/lib/voice-client-direct.ts
index bef4480af7f..ae13747783f 100644
--- a/apps/desktop/src/lib/voice-client-direct.ts
+++ b/apps/desktop/src/lib/voice-client-direct.ts
@@ -140,6 +140,36 @@ async function providerErrorText(response: Response): Promise<string> {
return body.slice(0, 300)
}
+/**
+ * Normalize an OpenAI-compatible transcription HTTP body to spoken text.
+ *
+ * Groq and OpenAI honor `response_format=text` and return a bare string.
+ * Mistral Voxtral ignores that flag and returns JSON
+ * `{ text, model, usage, ... }` — dumping that object into the Desktop
+ * composer is the dictation regression (plain speech becomes raw JSON).
+ */
+export function transcriptFromOpenAiMultipartBody(body: string): string {
+ const trimmed = String(body || '').trim()
+
+ if (!trimmed) {
+ return ''
+ }
+
+ if (trimmed.startsWith('{')) {
+ try {
+ const parsed = JSON.parse(trimmed) as { text?: unknown }
+
+ if (typeof parsed?.text === 'string') {
+ return parsed.text.trim()
+ }
+ } catch {
+ // Not JSON — treat the body as the transcript.
+ }
+ }
+
+ return trimmed
+}
+
/**
* Transcribe provider-direct. Returns the transcript ('' = silence), or null
* when the profile's provider isn't client-callable — the caller relays.
@@ -179,7 +209,7 @@ export async function transcribeAudioClientDirect(audio: Blob): Promise<null | s
throw new Error(`${stt.provider} STT error (HTTP ${response.status}): ${await providerErrorText(response)}`)
}
- return (await response.text()).trim()
+ return transcriptFromOpenAiMultipartBody(await response.text())
}
if (stt.wire === 'xai-stt') {