Skip to content

Conversation

@Emt-lin
Copy link
Collaborator

@Emt-lin Emt-lin commented Nov 5, 2025

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.ts with getApiKeyForProvider() and isRequiredChatModel() 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.tsx
  • src/settings/v2/components/ApiKeyDialog.tsx
  • src/settings/v2/components/ModelAddDialog.tsx
  • src/settings/v2/components/ModelEditDialog.tsx
  • src/settings/v2/components/ModelTable.tsx
  • src/utils.ts
CleanShot 2025-11-05 at 20 19 37

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.ts with getApiKeyForProvider() and isRequiredChatModel().
  • 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: Use getApiKeyForProvider() for consistent key retrieval.
  • Core utils:
    • src/utils.ts: Simplify getNeedSetKeyProvider(); update checkModelApiKey() to use centralized key lookup and improved notices.

Written by Cursor Bugbot for commit 1a29fee. This will update automatically on new commits. Configure here.

@Emt-lin Emt-lin requested a review from logancyang November 5, 2025 12:21
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@logancyang
Copy link
Owner

bugbot run

@Emt-lin Emt-lin force-pushed the refactor-model-dispaly branch from 7df7024 to c59b603 Compare November 7, 2025 06:16
Changed REQUIRED_MODELS from a top-level constant to a getter function to avoid circular dependency issues during module initialization. This fixes test failures where ChatModels enum was accessed before being fully initialized.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@logancyang
Copy link
Owner

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants