Repository navigation
fix(speech): show "Saved key kept" hint for equivalent OpenAI-compatible base URLs - #49231
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Low Merge Risk:
|
…ble base URLs The OpenAI-compatible provider dialog compared the raw saved and typed base URLs, so a trailing slash or the full /audio/transcriptions URL hid the "Saved key kept" hint even though the store keeps the key for any URL that resolves to the same transcription endpoint. Move openAiCompatibleTranscriptionUrl to a shared module next to a new isSameOpenAiCompatibleEndpoint, and use it in both the dialog and the store so they apply the same rule. Trailing slashes are trimmed with a linear scan instead of a backtracking regex since the dialog now runs it per keystroke. Fixes stablyai#49201 Co-authored-by: Neil <[email protected]>
4301e40 to
28a6b6c
Compare
ELI5
When an API key is already saved for an OpenAI-compatible voice provider, the settings dialog shows "Saved key kept". That hint disappeared if you only added a trailing
/or pasted the full transcription URL, as if the key would be lost. Saving actually kept it. The hint now matches what saving does.What Changed
saved.baseUrl === baseUrl.trim()), so any change in spelling swapped "Saved key kept" for "Optional for local servers", while the store kept the key for any URL that resolves to the same transcription endpoint.isSameOpenAiCompatibleEndpoint, which compares the transcription endpoints the two URLs resolve to. An invalid or half-typed URL returnsfalseinstead of throwing.openAiCompatibleTranscriptionUrlmoved from the main-process store tosrc/shared/speech/openai-compatible-endpoint.tsso the renderer can use it, next to the newisSameOpenAiCompatibleEndpoint. The trailing-slash trim switched from the/\/+$/regex to a linear scan, because that regex backtracks quadratically on long slash runs and the function now runs on every keystroke.Why
The dialog and the store each had their own rule, and they disagreed. One shared helper keeps them in step without duplicating URL parsing in the renderer. Which keys are kept is unchanged: a different host, scheme, port or path still drops the saved key.
Linked Issue
Fixes #49201
Original fix by @YannVanneth in #49231; final version reworked during the bug bash.
Reported by @Minidoracat
Visual Proof
Saved base URL
https://api.groq.com/openai/v1, then a trailing/typed. Screenshots from the original PR (the dialog change is unchanged):Testing
Repro: Settings → Voice → OpenAI-compatible provider with a saved key, then add a trailing
/to the base URL or paste the full/audio/transcriptionsURL.Verification:
New
src/shared/speech/openai-compatible-endpoint.test.tscovers equivalent forms (whitespace, trailing slashes, full transcriptions URL), a different endpoint, and invalid URLs without throwing.vitest run src/shared/speech src/main/speech: 7/7 passed.A throwaway happy-dom probe (not committed) rendered the real dialog and checked the API key placeholder for 13 typed URLs. Trailing
/, full and slash-terminated transcriptions URLs, padding, uppercase scheme/host and an explicit:443all show "Saved key kept"./v2,http:, another host, embedded credentials, a missing scheme and an empty field all show "Optional for local servers". 13/13 passed.oxfmt, oxlint, the anti-slop and code-quality oxlint configs, ast-grep and the changed-code quality gate are clean on the changed files.
Platforms: macOS (unit and component tests). The change is pure URL logic with no OS, path or shell dependence.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None, because this only runs in the voice provider settings dialog. Measured with Node 24: the per-keystroke check costs about 0.7 µs (before: about 0.01 µs for a string compare). For a URL with 20,000 trailing slashes it takes 25 µs, compared with 162 ms for the old regex in the store. A 100k-character path takes 111 µs. No new I/O, IPC, polling or subprocesses.
Risk
Level: Low
The shared function also builds the URL that receives the key. Apart from the trailing-slash trim, which gives the same result, its logic is unchanged. If the comparison were wrong, the hint would be wrong, or a blank key field would keep or drop the saved key incorrectly. The stored format and IPC contract are unchanged, so a plain revert backs it out.
Review
The store still refuses to reuse the saved key for a different host, scheme or path. UI copy and layout are unchanged.
Agent skill upstream boundary
Notes
No security, cross-platform, SSH/remote, mobile or backwards-compatibility impact: the logic is pure string/URL handling and the IPC contract and stored format are unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)