Skip to content

The agent that grows with you

fix(cli): first-time setup resolves plugin catalogs like the /model picker

teknium1e22e33c18998
diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.py
index 7537569ba65..51f6dc1d239 100644
--- a/hermes_cli/model_setup_flows.py
+++ b/hermes_cli/model_setup_flows.py
@@ -867,10 +867,12 @@ _SPECIAL_MODEL_LISTS = {
def _api_key_provider_model_list(provider_id: str, pconfig, existing_key: str, key_env: str, effective_base: str) -> list:
"""Model list for an API-key provider: models.dev registry (cached, agentic/tool-capable filter)
- → curated static list (offline insurance) → provider-owned catalog (generic /models
- probe for unregistered providers). Providers in ``_SPECIAL_MODEL_LISTS`` have their own resolution."""
+ → curated static list (offline insurance) → provider-owned catalog (``ProviderProfile.fetch_models``
+ merged with ``fallback_models`` exactly like the ``/model`` picker's
+ ``models._profile_live_catalog``; generic /models probe for unregistered providers).
+ Providers in ``_SPECIAL_MODEL_LISTS`` have their own resolution."""
from hermes_cli.config import get_env_value
- from hermes_cli.models import _PROVIDER_MODELS, fetch_api_models
+ from hermes_cli.models import _PROVIDER_MODELS, fetch_api_models, merge_profile_catalog
curated = _PROVIDER_MODELS.get(provider_id, [])
api_key_for_probe = existing_key or (get_env_value(key_env) if key_env else "")
@@ -890,11 +892,19 @@ def _api_key_provider_model_list(provider_id: str, pconfig, existing_key: str, k
from providers import get_provider_profile
profile = get_provider_profile(provider_id)
if profile is not None:
- # Provider catalogs can use a different endpoint, auth, or response shape.
- curated = curated or list(profile.fallback_models)
- live_models = profile.fetch_models(api_key=api_key_for_probe, base_url=effective_base)
- else:
- live_models = fetch_api_models(api_key_for_probe, effective_base)
+ # The profile owns endpoint (models_url), headers and response shape; a failing catalog
+ # degrades to fallback_models the same way the picker does.
+ try:
+ live_models = profile.fetch_models(api_key=api_key_for_probe, base_url=effective_base)
+ except Exception:
+ live_models = None
+ model_list = merge_profile_catalog(provider_id, profile, live_models) or []
+ if live_models:
+ _report_live_models(model_list, f"{pconfig.name} API")
+ else:
+ _show_curated(model_list)
+ return model_list
+ live_models = fetch_api_models(api_key_for_probe, effective_base)
if live_models and len(live_models) >= len(curated):
_report_live_models(live_models, f"{pconfig.name} API")
return live_models
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 320ceb33ddf..153356a6b17 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -1536,7 +1536,20 @@ def _profile_live_catalog(normalized: str) -> Optional[list[str]]:
if not (profile.auth_type == "api_key" and profile.base_url):
return list(profile.fallback_models) or None
api_key, base_url = _api_key_credentials(normalized)
- live = profile.fetch_models(api_key=api_key, base_url=base_url or profile.base_url or None) if api_key else None
+ live = None
+ if api_key:
+ # A raising catalog override degrades like a None return: fallback_models, not an empty picker.
+ try:
+ live = profile.fetch_models(api_key=api_key, base_url=base_url or profile.base_url or None)
+ except Exception:
+ live = None
+ return merge_profile_catalog(normalized, profile, live)
+
+
+def merge_profile_catalog(normalized: str, profile, live: Optional[list[str]]) -> Optional[list[str]]:
+ """Combine a profile's live catalog with its curated list the way the ``/model`` picker does, so
+ first-time setup (``model_setup_flows._api_key_provider_model_list``) offers the same rows the
+ picker will later show. Empty live → ``fallback_models`` (None when the profile has none)."""
if live and normalized in _LIVE_FIRST_PICKER_PROVIDERS:
# The relay still LISTS delisted ids it no longer serves; the keyed Zen/Go picker is
# live-first, so it filters them out here (#111749).
diff --git a/tests/agent/test_image_routing.py b/tests/agent/test_image_routing.py
index 69eecf07619..98de113be3e 100644
--- a/tests/agent/test_image_routing.py
+++ b/tests/agent/test_image_routing.py
@@ -693,3 +693,25 @@ class TestCodexContextVariantVisionLookup:
# Ineligible alias: looked up verbatim, no capability gained.
assert image_routing._probe_models_dev("openai-codex", "gpt-5.5-900k", {}) is None
assert seen[-1] == "gpt-5.5-900k"
+
+
+# ─── registered ProviderProfile.supports_vision ──────────────────────────────
+
+
+class TestProviderProfileDeclaration:
+
+ def test_profile_declared_vision_routes_native_only_when_declared(self, monkeypatch):
+ """The routing probe honours the same ``supports_vision`` the tool-result media path reads:
+ a plugin that declares it goes native; an undeclared plugin stays text (#116408)."""
+ import providers
+ from providers.base import ProviderProfile
+
+ for name, declared in (("scout-vision", True), ("scout-novision", False)):
+ monkeypatch.setitem(
+ providers._REGISTRY, name,
+ ProviderProfile(name=name, auth_type="api_key", base_url="https://x.invalid/v1",
+ supports_vision=declared))
+ with patch("agent.image_routing._probe_models_dev", return_value=None), \
+ patch("agent.image_routing._probe_managed_runtime", return_value=None):
+ assert decide_image_input_mode("scout-vision", "any-model", {}) == "native"
+ assert decide_image_input_mode("scout-novision", "any-model", {}) == "text"
diff --git a/tests/hermes_cli/test_setup_provider_catalog.py b/tests/hermes_cli/test_setup_provider_catalog.py
index 0b8973be726..f0d16c00e41 100644
--- a/tests/hermes_cli/test_setup_provider_catalog.py
+++ b/tests/hermes_cli/test_setup_provider_catalog.py
@@ -88,3 +88,30 @@ def test_setup_uses_profile_endpoint_and_headers(tmp_path, monkeypatch):
assert result == ["live-catalog-model"]
assert requests == [("/catalog", "present")]
+
+
+def test_setup_matches_picker_when_catalog_fetch_fails(monkeypatch):
+ """A profile whose catalog is down offers its ``fallback_models`` at setup, exactly what
+ ``/model`` shows via ``models.provider_model_ids`` for the same profile."""
+ from types import SimpleNamespace
+
+ import providers
+ from providers.base import ProviderProfile
+ from hermes_cli import model_setup_flows as flows, models
+
+ class DownProfile(ProviderProfile):
+ def fetch_models(self, *, api_key=None, base_url=None, timeout=8.0):
+ raise ConnectionError("catalog down")
+
+ profile = DownProfile(
+ name="scout-down-catalog", auth_type="api_key", env_vars=("SCOUT_DOWN_TEST_KEY",),
+ base_url="https://down.example.invalid/v1", fallback_models=("declared-a", "declared-b"),
+ )
+ monkeypatch.setitem(providers._REGISTRY, profile.name, profile)
+ monkeypatch.setattr(flows, "_models_dev_merged", lambda *_: [])
+ monkeypatch.setattr(models, "_api_key_credentials", lambda *_: ("synthetic-test-key", ""))
+
+ setup_rows = flows._api_key_provider_model_list(
+ profile.name, SimpleNamespace(name="Down"), "synthetic-test-key", "", profile.base_url)
+
+ assert setup_rows == ["declared-a", "declared-b"] == models.provider_model_ids(profile.name)