feat: load available models. - #149
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
It currently performs unnecessary model-catalog network requests when no key is present and has a robustness issue in free-model detection that can misclassify pricing responses.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a live model catalog flow to the chat drawer so the model <select> can be populated from OpenRouter’s /models endpoint (with fallback to the existing static list), and refactors the picker logic into a dedicated module.
Changes:
- Introduces
createChatModelPicker()to manage model option rendering, grouping (Free/Paid), and catalog caching. - Adds
fetchChatModelOptions()to query and normalize the OpenRouter models catalog (tool-capable models only). - Wires the drawer to refresh model options on open and on key changes.
File summaries
| File | Description |
|---|---|
| src/modules/chat/model-picker.js | New module encapsulating model select state, option rendering, and catalog loading/caching. |
| src/modules/chat/drawer.js | Refactors drawer to delegate model selection and catalog refresh behavior to the new picker. |
| src/modules/chat/api/models.js | New OpenRouter models catalog fetch + normalization logic (tools-capable filtering, free-first sorting). |
| src/modules/chat/api/constants.js | Adds the /models endpoint constant. |
| src/modules/chat/api/completions.js | Re-exports model-catalog helpers alongside existing completions API exports. |
Review details
Suppressed comments (1)
src/modules/chat/drawer.js:238
- Opening the drawer currently attempts to load the model catalog even when no key is present (the composer/select are disabled). Guarding this avoids an unnecessary network request.
if (open) {
void modelPicker.loadModelOptionsFromCatalog()
}
- Files reviewed: 5/5 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return false | ||
| } | ||
|
|
||
| return pricing.prompt === '0' && pricing.completion === '0' |
Comment on lines
+185
to
+187
| if (open) { | ||
| void modelPicker.loadModelOptionsFromCatalog({ force: true }) | ||
| } |
Comment on lines
+92
to
+93
| const token = getChatKey() | ||
| const normalizedToken = typeof token === 'string' ? token.trim() : '' |
Comment on lines
+454
to
+458
| export { | ||
| chatModelOptions, | ||
| defaultChatModel, | ||
| fetchChatModelOptions, | ||
| isFreeChatModel, |
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.
No description provided.