Skip to content

The agent that grows with you

fix(providers): a plugin alias names the same provider whether or not models.dev loads

Teknium72bb27236bc3
diff --git a/hermes_cli/providers.py b/hermes_cli/providers.py
index d87a6fff2a1..157c2c4c669 100644
--- a/hermes_cli/providers.py
+++ b/hermes_cli/providers.py
@@ -256,10 +256,28 @@ def _overlay_pdef(canonical, ov: HermesOverlay, name, env_vars, base_url, doc, s
source=source)
+def _plugin_alias_owner(canonical: str) -> str:
+ """The plugin profile's id when *canonical* is only one of its ``aliases``, else *canonical*.
+
+ A plugin alias that is also a models.dev provider id (``meta`` -> ``meta-ai``, ``azure`` ->
+ ``azure-foundry``) otherwise resolved to the bare models.dev entry whenever the catalog
+ loaded and to the plugin when it did not, so ``--provider meta`` persisted a different
+ provider depending on the network. ``hermes_cli.auth.resolve_provider`` already answers the
+ plugin id. Built-in ids and overlay profiles keep what ``normalize_provider`` gave them."""
+ if not canonical or _is_static_canonical(canonical):
+ return canonical
+ from providers import list_providers
+ profiles = list_providers()
+ if any(prof.name == canonical for prof in profiles):
+ return canonical
+ owner = next((prof for prof in profiles if canonical in prof.aliases), None)
+ return owner.name if owner is not None and not owner.provider_overlay else canonical
+
+
def get_provider(name: str, *, allow_network: bool = True) -> Optional[ProviderDef]:
"""Look up a built-in provider by id or alias: models.dev catalog merged with the Hermes overlay;
Hermes-only overlay (nous, openai-codex, …); plugin provider profiles with a concrete endpoint."""
- canonical = normalize_provider(name)
+ canonical = _plugin_alias_owner(normalize_provider(name))
from hermes_cli.left_core_migration import provider_left_core
if provider_left_core(canonical): # its plugin is not loaded: models.dev must not stand in for it
return None
diff --git a/tests/hermes_cli/test_model_switch_openai_api_mode.py b/tests/hermes_cli/test_model_switch_openai_api_mode.py
index fe61b03b897..cd578d4b6c3 100644
--- a/tests/hermes_cli/test_model_switch_openai_api_mode.py
+++ b/tests/hermes_cli/test_model_switch_openai_api_mode.py
@@ -17,6 +17,8 @@ reasoning_effort into a live one that OpenAI 400s on the chat_completions path.
from unittest.mock import patch
+import pytest
+
from hermes_cli.model_switch import switch_model
from hermes_cli.providers import host_mandated_api_mode
@@ -27,6 +29,14 @@ _MOCK_VALIDATION = {
"message": None,
}
+# models.dev as the live catalog serves it: Meta's Model API is keyed ``meta``, the id the
+# bundled ``meta-ai`` plugin also claims as an alias. Tests seed the registry instead of
+# fetching it, so provider resolution never depends on the network or today's catalog.
+_MODELS_DEV_WITH_META = {
+ "meta": {"id": "meta", "name": "Meta", "env": ["META_MODEL_API_KEY"],
+ "api": "https://api.meta.ai/v1", "models": {}},
+}
+
def _run_openai_switch(
raw_input: str,
@@ -35,9 +45,12 @@ def _run_openai_switch(
explicit_provider: str = "openai-api",
runtime_api_mode: str = "chat_completions",
runtime_base_url: str = "https://api.openai.com/v1",
+ models_dev_registry: dict | None = None,
):
"""Run switch_model with OpenAI-direct mocks and return the result."""
+ registry = _MODELS_DEV_WITH_META if models_dev_registry is None else models_dev_registry
with (
+ patch("agent.models_dev.fetch_models_dev", lambda *a, **k: registry),
patch("hermes_cli.model_switch.resolve_alias", return_value=None),
patch("hermes_cli.model_switch.list_provider_models", return_value=[]),
patch(
@@ -100,13 +113,17 @@ def test_generic_endpoint_keeps_explicit_api_mode():
assert host_mandated_api_mode("https://api.openai.com/v1") == "codex_responses"
assert host_mandated_api_mode("https://api.anthropic.com") == "anthropic_messages"
-def test_stale_chat_overridden_on_meta_direct():
[email protected]("models_dev_registry", [_MODELS_DEV_WITH_META, {}], ids=["catalog", "offline"])
+def test_stale_chat_overridden_on_meta_direct(models_dev_registry):
"""Stale chat_completions on api.meta.ai → codex_responses (like openai direct).
Switching from openrouter/chat_completions to muse-spark on meta's
- endpoint must flip to Responses API for caching (0% vs 93-99%).
+ endpoint must flip to Responses API for caching (0% vs 93-99%). ``meta`` is an
+ alias of the bundled ``meta-ai`` plugin, so the switch lands on ``meta-ai``
+ whether or not models.dev (which keys the same API ``meta``) is reachable.
"""
result = _run_openai_switch(
+ models_dev_registry=models_dev_registry,
raw_input="muse-spark-1.2",
current_provider="openrouter",
current_model="anthropic/claude-opus-4.8",
@@ -115,7 +132,7 @@ def test_stale_chat_overridden_on_meta_direct():
runtime_base_url="https://api.meta.ai/v1",
)
assert result.success, f"switch_model failed: {result.error_message}"
- assert result.target_provider == "meta"
+ assert result.target_provider == "meta-ai"
assert result.new_model == "muse-spark-1.2"
assert result.api_mode == "codex_responses"
diff --git a/tests/hermes_cli/test_provider_plugin_alias_identity.py b/tests/hermes_cli/test_provider_plugin_alias_identity.py
new file mode 100644
index 00000000000..54242fbbb3e
--- /dev/null
+++ b/tests/hermes_cli/test_provider_plugin_alias_identity.py
@@ -0,0 +1,53 @@
+"""A provider plugin's alias names the same provider whether or not models.dev is reachable.
+
+Some bundled plugins claim an alias that models.dev also uses as a provider id (``meta`` for
+``meta-ai``, ``azure`` for ``azure-foundry``, ``google`` for ``gemini``, ``google-vertex`` for
+``vertex``). ``resolve_provider_full`` used to answer the bare models.dev id when the catalog
+loaded and the plugin id when it did not, so ``/model ... --provider meta`` persisted a
+different provider depending on the network, and disagreed with the credential resolver.
+"""
+
+import pytest
+
+from hermes_cli.auth import resolve_provider
+from hermes_cli.providers import resolve_provider_full
+
+
+def _entry(key: str, api: str) -> dict:
+ return {"id": key, "name": key.title(), "env": [f"{key.upper().replace('-', '_')}_API_KEY"],
+ "api": api, "models": {}}
+
+
+# Each alias as models.dev lists it, so the catalog leg has the colliding entry to resolve to.
+_CATALOG = {
+ "meta": _entry("meta", "https://api.meta.ai/v1"),
+ "azure": _entry("azure", "https://example.openai.azure.com/openai"),
+ "google": _entry("google", "https://generativelanguage.googleapis.com/v1beta"),
+ "google-vertex": _entry("google-vertex", "https://aiplatform.googleapis.com/v1"),
+}
+
+_ALIASES = {"meta": "meta-ai", "azure": "azure-foundry", "google": "gemini", "google-vertex": "vertex"}
+
+
[email protected]("registry", [_CATALOG, {}], ids=["catalog", "offline"])
[email protected]("alias", sorted(_ALIASES))
+def test_plugin_alias_resolves_to_the_plugin_id(monkeypatch, alias, registry):
+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda *a, **k: registry)
+
+ pdef = resolve_provider_full(alias)
+
+ assert pdef is not None
+ assert pdef.id == _ALIASES[alias]
+ assert pdef.id == resolve_provider(alias)
+
+
+def test_user_provider_named_like_the_alias_still_wins(monkeypatch):
+ """A configured ``providers.meta`` pointing elsewhere keeps its own identity."""
+ monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda *a, **k: _CATALOG)
+ user = {"meta": {"base_url": "https://relay.example.com/v1", "api_key": "sk-test"}}
+
+ pdef = resolve_provider_full("meta", user_providers=user)
+
+ assert pdef is not None
+ assert pdef.base_url == "https://relay.example.com/v1"
+ assert pdef.id != "meta-ai"