From fd50fcfdf2f572d9096a06b7801be34a8a3d90df Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 08:42:56 +0000 Subject: [PATCH] fix(speech): send cloud dictation through the proxy set in Settings (#40236) * fix(speech): send cloud dictation through the proxy set in Settings * fix(speech): keep OpenAI cookies out of the desktop session * refactor(speech): send transcription and the key check through one request helper --- .../speech/openai-api-key-verification.ts | 13 +++++----- .../speech/openai-transcription-client.ts | 26 +++++++++++++------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/speech/openai-api-key-verification.ts b/src/main/speech/openai-api-key-verification.ts index b1b5efc2ea8..d7fe69a1710 100644 --- a/src/main/speech/openai-api-key-verification.ts +++ b/src/main/speech/openai-api-key-verification.ts @@ -1,6 +1,6 @@ import { saveOpenAiSpeechApiKey } from './openai-api-key-store' import { - OPENAI_TRANSCRIPTION_URL, + postOpenAiTranscription, readOpenAiErrorMessage, type OpenAiTranscriptionResponse } from './openai-transcription-client' @@ -20,12 +20,11 @@ async function rejectUnauthorizedOpenAiKey(apiKey: string): Promise { let response: Response try { // An empty form is refused before any transcription, but only after OpenAI checks the key. - response = await fetch(OPENAI_TRANSCRIPTION_URL, { - method: 'POST', - headers: { Authorization: `Bearer ${apiKey}` }, - body: new FormData(), - signal: AbortSignal.timeout(KEY_CHECK_TIMEOUT_MS) - }) + response = await postOpenAiTranscription( + apiKey, + new FormData(), + AbortSignal.timeout(KEY_CHECK_TIMEOUT_MS) + ) } catch { return } diff --git a/src/main/speech/openai-transcription-client.ts b/src/main/speech/openai-transcription-client.ts index dcacc4e4818..b17ba3411cf 100644 --- a/src/main/speech/openai-transcription-client.ts +++ b/src/main/speech/openai-transcription-client.ts @@ -1,3 +1,4 @@ +import { getMainHttpClient } from '../network/http-client' import { resampleToRate } from './stt-audio-resample' import { replaceRetiredSpeechModelId } from './model-catalog' @@ -68,6 +69,22 @@ function encodePcm16Wav(chunks: Float32Array[], sampleRate: number): Buffer { + return getMainHttpClient().fetch(OPENAI_TRANSCRIPTION_URL, { + method: 'POST', + // Bearer auth only: keep OpenAI's cookies out of the shared desktop session. + credentials: 'omit', + signal, + headers: { Authorization: `Bearer ${apiKey}` }, + body: form + }) +} + export function readOpenAiErrorMessage(data: OpenAiTranscriptionResponse): string | undefined { return typeof data.error?.message === 'string' ? sanitizeOpenAiTranscriptionErrorMessage(data.error.message) @@ -151,14 +168,7 @@ export class OpenAiTranscriptionSession { } private async upload(form: FormData, signal: AbortSignal): Promise { - const response = await fetch(OPENAI_TRANSCRIPTION_URL, { - method: 'POST', - signal, - headers: { - Authorization: `Bearer ${this.readApiKey()}` - }, - body: form - }) + const response = await postOpenAiTranscription(this.readApiKey(), form, signal) const data = (await response.json().catch(() => ({}))) as OpenAiTranscriptionResponse if (!response.ok) {