Skip to content

fix: sync validNames with ProviderName type + handle provider-prefixed model IDs (OpenRouter)#91

Open
nalepy wants to merge 3 commits into
cosmicstack-labs:mainfrom
nalepy:fix/provider-toggle-and-openrouter-models
Open

fix: sync validNames with ProviderName type + handle provider-prefixed model IDs (OpenRouter)#91
nalepy wants to merge 3 commits into
cosmicstack-labs:mainfrom
nalepy:fix/provider-toggle-and-openrouter-models

Conversation

@nalepy

@nalepy nalepy commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Two small fixes for provider management in the web dashboard.

Fix 1 — ValidNames array out of sync with ProviderName type

File: src/web/api/providers.ts

The validNames whitelist in the POST /api/providers/:name handler was missing 5 provider types that exist in the ProviderName union type: openaiCompat, mimo, mimoTokenPlan, chatgptWeb, githubCopilot. Toggling any of these providers from the web UI returned 400 Unknown provider.

Fix: Added the 5 missing names to the validNames array. Now matches ProviderName exactly.

Fix 2 — isOpenAIChatModel rejects provider-prefixed model IDs

File: src/utils/provider-models.ts

isOpenAIChatModel() filtered models by checking id.startsWith("gpt-"). OpenRouter (and similar API proxies) return model IDs with a provider prefix: openai/gpt-4o-mini, anthropic/claude-sonnet-4, etc. The prefix caused ALL models to be filtered out, producing the error "Mercury could not find any supported chat models for this provider."

Fix: Split the model ID on / and check only the last segment. This handles both formats:

  • OpenRouter: openai/gpt-4o-minigpt-4o-mini
  • Direct OpenAI: gpt-4o-minigpt-4o-mini
  • OpenAI o-series: o3-minio3-mini

Non-OpenAI models from proxy services (e.g. anthropic/claude-sonnet-4) are still correctly excluded because claude-sonnet-4 doesn't match the gpt-* or /^o\d/ filters.

Testing

  • mercury doctor → toggle MiMo provider no longer returns 400
  • mercury doctor → Test Connection with OpenRouter's OpenAI endpoint now returns models
  • Direct OpenAI API still works (backward compatible)
  • Non-OpenAI proxy models still correctly excluded

Files changed

File Change
src/web/api/providers.ts Add 5 missing provider names to validNames
src/utils/provider-models.ts Split model ID on / before prefix check

nalepy added 3 commits July 6, 2026 13:53
…efixed model IDs

Fix 1 (providers.ts): validNames array was missing 5 provider types
(openaiCompat, mimo, mimoTokenPlan, chatgptWeb, githubCopilot) that
exist in the ProviderName union type. This caused 'Unknown provider'
errors when toggling/disabling any of these providers from the web UI.

Fix 2 (provider-models.ts): isOpenAIChatModel() rejected model IDs with
provider prefixes (e.g. OpenRouter's 'openai/gpt-4o-mini') because it
checked the full ID for the 'gpt-' prefix. Split on '/' and check the
last segment instead — backward-compatible with direct API model names.
The openai provider (and others falling through to the else branch in
ProviderRegistry) defaulted to OpenAI Responses API via
createOpenAI(model) instead of Chat Completions API via
createOpenAI.chat(model). OpenRouter and most proxy services only
support Chat Completions endpoint, causing HTTP 400 'Invalid Responses
API request' on every call — agent retries endlessly burning tokens.

Changed the else branch to pass { useChatApi: true }, matching the
existing openaiCompat and deepseek providers.
The web UI lacks a permissions mode toggle in Settings, so users
cannot switch from 'Ask Me' to 'Allow All' mode. Permission prompts
render as raw JSON in the chat stream instead of interactive dialogs,
blocking all tool execution.

Change bypassPermissions default from false to true so the web
channel starts in Allow All mode. Users who want Ask Me can
still toggle it programmatically via PUT /api/chat/settings.
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.

1 participant