Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 6, 2025

Summary

Add a cloud icon toggle for routing models through Mux Gateway, with a cleaner API design and reactive state management.

Key Changes

  • Gateway toggle UI: Cloud icon button next to supported models (anthropic, openai, google, xai) to enable/disable gateway routing per-model
  • Global enable/disable: Toggle switch in Providers → Mux Gateway settings to disable gateway without removing coupon code (useful for testing)
  • Custom gateway icon: Circle with M logo, outer glow ring when active
  • Reactive state: useGateway() hook with clean interface:
    • isActive: gateway configured AND enabled
    • canToggleModel(id): whether to show toggle
    • isModelRoutingThroughGateway(id): for display badge
    • toggleModelGateway(id): toggle per-model
  • Migration: Legacy mux-gateway:provider/model format auto-migrates to canonical form with gateway enabled

Bug Fixes

  • Gateway toggle now reliably affects message sending (reactive useSendMessageOptions)
  • Synchronous localStorage writes prevent race conditions

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@ammar-agent ammar-agent force-pushed the fix-mux-gateway-models branch from f4390cd to 5dbda60 Compare December 6, 2025 22:09
- Add whitespace-nowrap to ProviderWithIcon to prevent line breaks
- Create useGatewayModels hook for managing gateway preferences
- Add cloud icon toggle to ModelRow in settings
- Add cloud icon toggle to ModelSelector dropdown
- Transform model to gateway format when sending messages

Users can now click the cloud icon on any model to route it through
Mux Gateway. The preference is stored per-model and the transformation
happens transparently when sending messages.

_Generated with mux_
- Track gateway availability (couponCodeSet) in localStorage
- Only transform to gateway format when gateway is both enabled AND available
- Hide cloud icon toggle when gateway provider is not configured
- Cloud icon only shows in model selector when gateway is actually active
- Filter out mux-gateway provider from custom models list in settings
- Filter out mux-gateway models from model LRU list
- Only show cloud icon for providers that gateway supports (anthropic, openai, google)
- Add isGatewaySupported() check in toGatewayModel for extra robustness
Add forward compatibility for users who have directly specified
mux-gateway models in their config:

- migrateGatewayModel(): converts 'mux-gateway:provider/model' to
  'provider:model' and auto-enables gateway toggle for that model
- Applied in useSendMessageOptions, getSendOptionsFromStorage
- useModelLRU: migrates LRU list and default model on load
- Malformed gateway entries are filtered out

Example: 'mux-gateway:anthropic/claude-opus-4-5' becomes
'anthropic:claude-opus-4-5' with gateway toggle enabled
Add xai and bedrock to supported providers list. The Vercel AI Gateway
supports OpenAI, Anthropic, Google, xAI, Amazon Bedrock, and others.

Excluded providers:
- ollama: Local-only, not routable through cloud gateway
- openrouter: Already a gateway/aggregator
Remove bedrock from supported gateway providers due to its complex
AWS credential-based authentication, which doesn't fit the simple
API key routing model of the gateway.
@ammar-agent ammar-agent force-pushed the fix-mux-gateway-models branch from 5cbc854 to c655e18 Compare December 7, 2025 16:56
Replace generic Cloud icon with a dedicated gateway icon showing
data flowing through a central hub (hexagon with arrows).
More distinctive and semantically meaningful for the gateway feature.
@ammar-agent ammar-agent force-pushed the fix-mux-gateway-models branch from 6cd7b1c to d75244f Compare December 7, 2025 17:01
- Add global gateway enabled state to localStorage (defaults to true)
- Add toggle switch in Mux Gateway provider section when coupon is set
- Respect global enabled state across all gateway UI elements
- Simplify GatewayIcon to diamond relay symbol

This allows users to disable gateway routing without removing
their coupon code, useful for testing or debugging.
Rename useGatewayModels → useGateway with cleaner interface:
- isActive: gateway configured AND enabled (ready to use)
- isConfigured: coupon code set
- isEnabled: global master switch on
- canToggleModel(id): whether to show gateway toggle for model
- modelUsesGateway(id): model is toggled for gateway
- isModelRoutingThroughGateway(id): active + uses (for display)
- toggleEnabled(): toggle global switch
- toggleModelGateway(id): toggle per-model

Consolidates scattered checks like:
  gatewayGloballyEnabled && gatewayAvailable && isGatewaySupported(model)
Into single semantic calls:
  gateway.canToggleModel(model)

Also renames isGatewaySupported → isProviderSupported for clarity.
@ammar-agent ammar-agent force-pushed the fix-mux-gateway-models branch from d4af5fa to 9392cad Compare December 7, 2025 17:11
Use a circle (portal) with an arrow passing through instead of
a diamond relay. More visually balanced at small sizes.
Concentric rings with a sparkle/cross at center for a more
magical portal appearance.
- Circle with M logo for clear Mux branding
- Active state shows outer glow ring instead of fill
- Cleaner visual distinction between enabled/disabled
usePersistedState batches localStorage writes in microtask, which can
cause race conditions when toggling gateway and immediately sending
a message. Now we also call updatePersistedState directly to ensure
toGatewayModel() sees the change immediately.
The hook now subscribes to useGateway() so it re-renders when
the user toggles gateway on/off for a model. This fixes the bug
where disabling gateway in the model selector didn't take effect
immediately when sending a message.
@ammar-agent ammar-agent changed the title 🤖 feat: add cloud icon toggle for Mux Gateway models 🤖 feat: add Mux Gateway toggle with cleaner API Dec 7, 2025
The thinking policy regex patterns expect canonical model format
(e.g., 'gpt-5-pro'), not gateway format ('openai/gpt-5-pro').
Run enforceThinkingPolicy before gateway transform to ensure
correct policy detection.
useSendMessageOptions now returns both:
- model: gateway-transformed for API calls
- baseModel: canonical format for UI/policy (e.g., codex-max reasoning levels)

This ensures ThinkingSlider shows correct options (xhigh for codex-max)
even when model is routed through gateway.
@ammario ammario merged commit 17f9181 into main Dec 7, 2025
19 checks passed
@ammario ammario deleted the fix-mux-gateway-models branch December 7, 2025 17:53
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.

2 participants