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
This commit is contained in:
Kelvin Amoaba
2026-11-09 08:42:56 +00:00
committed by GitHub
parent 8abac5357e
commit fd50fcfdf2
2 changed files with 24 additions and 15 deletions
@@ -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<void> {
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
}
+18 -8
View File
@@ -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<Arra
return buffer
}
/** The one request both transcription and the key check send; the main HTTP client follows the app's proxy. */
export function postOpenAiTranscription(
apiKey: string,
form: FormData,
signal: AbortSignal
): Promise<Response> {
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<string> {
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) {