fix(translation): check active provider's token in translateAsync AI gate - #460
Merged
LeanBitLab merged 1 commit intoAug 29, 2026
Merged
Conversation
…gate
translateAsync() gated the built-in-AI fallback on
ProofreadService.getApiKey(), which reads only the Gemini key
(KEY_API_KEY = "gemini_api_key"). With provider OPENAI (custom
OpenAI-compatible endpoint) or GROQ, that check returned false even
when the provider was fully configured, so every AI-fallback branch
short-circuited to Result.failure("Translation plugin not available")
with a misleading "Offline model not downloaded" toast - before any
network request was made.
Proofreading was unaffected because performAsyncOperation() performs a
provider-aware token check, and GGUF translation on the offline flavor
checks getModelPath() instead.
Fix: check the active provider's token (Gemini key / Groq token /
HuggingFace token) the same way.
Fixes LeanBitLab#459
Ref LeanBitLab#456
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #459, refs #456.
translateAsync()gated the built-in-AI translation fallback onProofreadService.getApiKey(), which reads only the Gemini key (KEY_API_KEY = "gemini_api_key",ProofreadService.kt:645). With providerOPENAI(custom OpenAI-compatible endpoint) orGROQ, that key is empty even when the provider is fully configured, sohasAiConfiguredwasfalseand every AI-fallback branch (lines ~414/436/449/462) short-circuited toResult.failure("Translation plugin not available")with a misleading "Offline model not downloaded" toast — before any network request was made.Proofreading was unaffected because
performAsyncOperation()performs a provider-aware check (getGroqToken()for GROQ,getHuggingFaceToken()for OPENAI). GGUF translation on the Offline flavor checks the local model path instead. The gate looks like a leftover from when Gemini was the only cloud provider.This PR changes the gate in
translateAsync()to check the active provider's token, mirroring the pattern already used byperformAsyncOperation():Verification
/v1/chat/completionsformat), where the same provider+model works for proofreading:master(≈v4.1.7):ProofreadHelper.kt:386+ProofreadService.kt:79/645.getGroqToken()andgetHuggingFaceToken()are already public methods onProofreadServiceused byperformAsyncOperation().Notes
Two related cosmetic issues observed on this path (not addressed here to keep the PR minimal):
translation_plugin_fallback_to_ai, "Plugin unavailable, switching to AI") shows on every translation when the plugin isn't installed, even when the user is already in AI mode.Happy to follow up on those separately if useful.
Fixes #459
Refs #456