Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Added openrouter#25

Merged
geelen merged 12 commits intomainfrom
openrouter-pkce
Jul 11, 2025
Merged

Added openrouter#25
geelen merged 12 commits intomainfrom
openrouter-pkce

Conversation

@geelen
Copy link
Copy Markdown
Collaborator

@geelen geelen commented Jul 11, 2025

Using the PKCE popup: https://openrouter.ai/docs/use-cases/oauth-pkce

Also refactored the way the model selector, works. Looking great!

image

geelen and others added 12 commits July 10, 2025 13:07
- Created scripts/update-models.ts to fetch and filter models from models.dev API
- Added pnpm update-models command to package.json
- Generated initial models.json with 39 models from 3 providers
- Filtered to only include anthropic, groq, and openrouter providers
- Added tsx as dev dependency for TypeScript execution

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- Refactored types/models.ts with new Provider and Model interfaces
- Added support for OAuth authentication alongside API keys
- Created useModels hook for favorites management and model data loading
- Added comprehensive auth utils with OAuth PKCE flow implementation
- Updated apiKeys.ts to use new auth system for backward compatibility
- Created OAuthCallback component for OAuth flow completion
- Added support for OpenRouter OAuth configuration

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
…th support

- Refactored ModelSelector to use new favorites-based system with search and filtering
- Added star ratings for favorite models with local storage persistence
- Added search functionality to filter models by name/provider
- Added "Tools Only" and "Favorites" filter toggles
- Updated authentication to support OAuth PKCE flow alongside API keys
- Added OpenRouter OAuth support with proper error handling
- Updated ConversationThread, ModelSelectionModal, and ApiKeyModal to use new Provider type
- Added OAuth success message handling in ChatApp
- Updated useStreamResponse to support OpenRouter via @ai-sdk/openai
- Fixed all TypeScript compilation errors for new model system
- Added proper auth headers for all three providers (Groq, Anthropic, OpenRouter)

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- Fixed unused import in useStreamResponse.ts
- Added .env.example for OpenRouter OAuth configuration
- Created comprehensive MODEL_SELECTOR_GUIDE.md with usage instructions
- Documented all features including favorites, search, filtering, and OAuth
- Added setup instructions for OpenRouter OAuth
- Included troubleshooting guide and local storage details

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- Refactored ModelSelector to show providers first, then starred models
- Created ProviderModelsModal for provider-specific model selection and starring
- Removed search/filter complexity from main dropdown
- Added handleProviderSelect to route between OAuth/API key flows
- OAuth providers show model selection after successful authentication
- API key providers show model selection after key entry
- Starred models appear grayed out when provider not configured
- Clicking unconfigured starred model redirects to provider setup
- Added OAuth success message handling to auto-open provider models
- Clean two-step workflow: configure provider → select/star models

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- Replaced the old flat model list in ModelSelectionModal with provider-first design
- Shows 3 provider cards (Anthropic, Groq, OpenRouter) with auth status
- Added starred models section below providers (empty initially)
- OAuth flow for OpenRouter, API key modals for Anthropic/Groq
- Provider selection leads to ProviderModelsModal for browsing and starring
- Grayed out starred models when provider not configured
- Click unconfigured starred model redirects to provider setup
- OAuth success automatically opens provider models modal
- Clean, intuitive workflow: Select Provider → Configure Auth → Browse Models → Star Favorites

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- Updated authorization URL from /oauth/authorize to /auth
- Changed token URL to /api/v1/auth/keys
- Removed client_id requirement (OpenRouter doesn't use it)
- Removed scopes (OpenRouter doesn't use them)
- Updated OAuth flow to use callback_url instead of redirect_uri
- Changed token exchange to use JSON body instead of form data
- Handle OpenRouter's response format {key: "..."} instead of {access_token: "..."}
- Made state parameter optional for OpenRouter (they don't use it)
- Updated sessionStorage handling for providers without state parameter
- Simplified .env.example to remove client_id requirement

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- **Fixed multiple useModels hook instances**: Removed duplicate hook from ModelSelectionModal and consolidated all model state management in ChatApp
- **Fixed auto-starring**: Models are now automatically starred when selected from any UI (provider modal or favorites list)
- **Fixed favorites persistence**: Starred models now properly persist in localStorage and are restored on page refresh
- **Fixed selected model highlighting**: Currently selected model is now highlighted in the starred models list with blue border, ring effect, and checkmark
- **Improved prop passing**: Pass all model-related functions (addToFavorites, toggleFavorite, isFavorite, getFavoriteModels) down through ChatApp → ConversationThread → ModelSelectionModal
- **Removed debug logs**: Cleaned up console.log statements added during debugging

The root cause was multiple instances of the useModels hook running simultaneously, causing state conflicts where one instance would load favorites correctly but another would reset them to an empty array. Now there's a single source of truth for all model state in ChatApp.

This fixes the specific issues where:
1. Selected models weren't being auto-starred
2. Starred models list was forgotten on page refresh
3. Selected model highlighting wasn't working in the modal

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- **Improved UX**: Replaced stacked modals with a single modal that switches between views
- **Added back navigation**: Provider models view now has a back button in the top left to return to main view
- **Unified modal structure**: Single modal container with conditional rendering for main vs provider views
- **Added search functionality**: Provider models view includes a search bar to filter models
- **Better visual hierarchy**: Provider view shows provider logo and name in header
- **Removed ProviderModelsModal**: Consolidated functionality into ModelSelectionModal
- **Enhanced interaction**: Cleaner navigation flow without modal stacking

Main view shows:
- List of providers with authentication status
- Starred models section

Provider view shows:
- Back button + provider logo/name in header
- Search bar for filtering models
- List of provider's models with star/select actions
- Model count at bottom

This creates a much more intuitive navigation experience similar to mobile app patterns, avoiding the confusing nested modal behavior.

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- **Fixed height constraints**: Modal now uses flexbox layout with proper height management
- **Added flex-shrink-0 to header**: Prevents header from shrinking and maintains fixed height
- **Added flex-1 min-h-0 to content**: Allows content area to take remaining space and scroll properly
- **Improved responsive behavior**: Modal content now scrolls vertically when overflowing on smaller screens

Key changes:
- Modal container: Added `flex flex-col` for vertical layout
- Header: Added `flex-shrink-0` to maintain fixed height
- Content area: Added `flex-1 min-h-0` to fill remaining space and enable scrolling

This ensures that:
1. Header stays fixed at top
2. Content area takes remaining vertical space
3. Content scrolls independently when overflowing
4. Works properly on all screen sizes, including small screens with many models

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
- **Improved UX consistency**: Provider model rows now behave like starred model rows
- **Full row clickable**: Click anywhere in the row to select and star the model
- **Event handling**: Star button uses stopPropagation to prevent row click when toggling favorites
- **Visual clarity**: Replaced "Select" button with subtle "Click to select" hint
- **Added cursor pointer**: Clear visual indication that rows are clickable

Changes:
- Added `cursor-pointer` and `onClick` to model rows in provider view
- Star button now stops event propagation to allow independent toggling
- Removed separate "Select" button for cleaner, more consistent interface
- Added "Click to select" text hint on the right side

This creates a consistent interaction pattern across both:
- Main view starred models (click row to select)
- Provider view models (click row to select and star)

Users can now efficiently browse and select models with single clicks, while still having granular control over favorites via the star button.

Amp-Thread: https://ampcode.com/threads/T-918d21db-3d47-4c6f-a3d8-96a60b59674a
Co-authored-by: Amp <amp@ampcode.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jul 11, 2025

Open in StackBlitz

npx https://pkg.pr.new/modelcontextprotocol/use-mcp@25

commit: f35261d

@geelen geelen merged commit c260e97 into main Jul 11, 2025
8 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant