Refactor model API key handling and improve model filtering.
Summary
- Extract API key handling logic into reusable utility functions
- Add model filtering in ModelSelector to show only models with valid API keys or required models
- Prevent disabling required models (Copilot Plus Flash, OpenRouter Gemini)
Key Changes
- New utility file:
src/utils/modelUtils.tswithgetApiKeyForProvider()andisRequiredChatModel()helpers - ModelSelector: Now filters models by API key availability
- Consistent API key retrieval: Unified across ApiKeyDialog, ModelAddDialog, and ModelEditDialog
- Required models protection: Cannot be disabled in ModelTable
Files Changed
src/utils/modelUtils.ts(new file, 54 lines)src/components/ui/ModelSelector.tsxsrc/settings/v2/components/ApiKeyDialog.tsxsrc/settings/v2/components/ModelAddDialog.tsxsrc/settings/v2/components/ModelEditDialog.tsxsrc/settings/v2/components/ModelTable.tsxsrc/utils.ts
[!NOTE] Centralizes API key logic in
utils/modelUtils, filters selectable models by API key or required status, and disables toggling of required models, updating dialogs and utils accordingly.
- Utilities:
- Add
src/utils/modelUtils.tswithgetApiKeyForProvider()andisRequiredChatModel().- UI:
src/components/ui/ModelSelector.tsx: Show only models with valid API keys or required models; use filtered list for selection/restore.src/settings/v2/components/ModelTable.tsx: Disable enable toggle for required chat models.- Settings dialogs:
src/settings/v2/components/ApiKeyDialog.tsx,ModelAddDialog.tsx,ModelEditDialog.tsx: UsegetApiKeyForProvider()for consistent key retrieval.- Core utils:
src/utils.ts: SimplifygetNeedSetKeyProvider(); updatecheckModelApiKey()to use centralized key lookup and improved notices.Written by Cursor Bugbot for commit 1a29fee054780454e68834814dfb0280c36cdb28. This will update automatically on new commits. Configure here.
bugbot run
@Emt-lin I've removed the popups complaining about no API key during onboarding #2015. As byproduct, I removed the logic that forbids the user to switch to a default model without API key. Now every "no API key" error should show as AI response errorblock. As for the model picker in chat input, we should simply hide those models with no API key.
Does this PR get affected by this design above? And could you please resolve conflict and rebase? thanks!