The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge remote-tracking branch 'origin/main' into austin/fix/121347-base-url-resolution
Austin Pickett46618927522d
diff --cc hermes_cli/models.pyindex 62892c1c2ec,74c4189fe03..eeeeebb1813--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@@ -1596,66 -1596,32 +1596,72 @@@ def _drop_delisted_opencode_models(normreturn rows+ def _chat_catalog_rows(models):+ """Drop generation ids from a chat-catalog list, keeping its list subclass."""+ from hermes_cli.chat_catalog import without_generation_models+ return without_generation_models(models)++-def provider_model_ids(provider: Optional[str], *, force_refresh: bool = False) -> list[str]:- """Best known model catalog for a provider: per-provider live fetchers, then the generic profile- fetch, then the static list (merged with models.dev for ``_MODELS_DEV_PREFERRED`` providers)."""- requested = str(provider or "").strip().lower()- if requested == "ollama":- return _ollama_local_catalog(force_refresh)+def _configured_relay_base_url(provider: str) -> str:+ """``model.base_url`` when it points the *configured* provider at a relay/proxy, else "".- normalized = normalize_provider(provider)- fetcher = _PROVIDER_CATALOG_FETCHERS.get(normalized)- if fetcher is not None:- models = fetcher(normalized, force_refresh)- if models is not None:- return _chat_catalog_rows(models)+ Discovery must probe the same endpoint inference uses (#121387): with ``model.base_url``+ set for the configured provider, the vendor's canonical host is NOT the catalog to list.+ Mirrors the ``$OPENAI_BASE_URL`` -> ``model.base_url`` -> canonical precedence of+ ``_openai_discovery_base_url`` for every built-in provider, not just OpenAI.+ """try:- models = _profile_live_catalog(normalized)+ model_cfg = _get_model_config_dict()except Exception:- models = None- if models is not None:- return _chat_catalog_rows(models)+ return ""+ cfg_provider = str(model_cfg.get("provider") or "").strip().lower()+ if not cfg_provider or not provider:+ return ""+ try:+ if normalize_provider(provider) != normalize_provider(cfg_provider):+ return ""+ except Exception:+ return ""+ return str(model_cfg.get("base_url") or "").strip().rstrip("/")+++def _relay_model_catalog(normalized: str, relay: str) -> Optional[list[str]]:+ """Live catalog probed at a configured ``model.base_url`` relay, or None to fall through.++ Returns only the relay's live ids (no curated merge): a relay user must see the relay's+ catalog, and a failed/empty probe degrades to the canonical fetchers untouched.+ """+ try:+ from providers import get_provider_profile++ profile = get_provider_profile(normalized)+ if profile is None or getattr(profile, "auth_type", "") != "api_key":+ return None+ api_key, _ = _api_key_credentials(normalized)+ live = profile.fetch_models(api_key=api_key, base_url=relay)+ return [str(m) for m in (live or []) if m] or None+ except Exception:+ return None+++# Canonical fetchers that already resolve `model.base_url` themselves for the configured+# provider AND degrade to their curated list when that relay fails — `_anthropic_catalog`,+# `_custom_catalog`, `_openai_catalog` (via `_openai_discovery_base_url`) and the simple+# api-key fetchers (via `resolve_api_key_provider_credentials`). They already satisfy the+# "no vendor egress when a relay is configured" invariant, so intercepting them would only+# override correct, better-merged behaviour. Everything else is vendor-pinned (#121387).+_RELAY_AWARE_CATALOG_FETCHERS = frozenset(+ {"anthropic", "custom", "openai", "openai-api", "stepfun", "gmi"}+)+++def _static_catalog(normalized: str, fetcher: Any) -> list[str]:+ """The local, no-egress catalog tail: curated static list (+ models.dev merge where preferred).++ Shared by the normal path's final fallback and by the configured-relay degrade path, which+ must never reach a live vendor fetcher (#121387).+ """# Merge static curated list with live API results so models that the live endpoint omits (stale cache,# partial rollout) still appear in the picker. Single providers (kimi, zai) use curated-first (commit# 658ac1d86) to surface newest models even when live API lags (#46309). OpenCode Zen / Go are different:@@@ -1668,46 -1634,12 +1674,46 @@@# source is serving its authoritative catalog.curated_static = (CuratedFallbackModels if fetcher is not None else list)(_PROVIDER_MODELS.get(normalized, []))if normalized not in _MODELS_DEV_PREFERRED:- return _drop_delisted_opencode_models(normalized, curated_static)+ return _chat_catalog_rows(_drop_delisted_opencode_models(normalized, curated_static))# models.dev keeps listing retired Zen ids too: filter after the merge, not before.merged = _drop_delisted_opencode_models(normalized, _merge_with_models_dev(normalized, curated_static))- return _xai_finalize_catalog(merged) if normalized in {"xai", "xai-oauth"} else merged+ return _chat_catalog_rows(_xai_finalize_catalog(merged) if normalized in {"xai", "xai-oauth"} else merged)+def provider_model_ids(provider: Optional[str], *, force_refresh: bool = False) -> list[str]:+ """Best known model catalog for a provider: per-provider live fetchers, then the generic profile+ fetch, then the static list (merged with models.dev for ``_MODELS_DEV_PREFERRED`` providers)."""+ requested = str(provider or "").strip().lower()+ if requested == "ollama":+ return _ollama_local_catalog(force_refresh)++ normalized = normalize_provider(provider)+ # A configured `model.base_url` relay is TERMINAL for live catalog egress: the picker must+ # list what the configured endpoint serves and must never touch the vendor host (#121387).+ # A failed or empty probe degrades to the local curated list — falling through to the+ # canonical fetchers would send the provider credential to exactly the host the user+ # deliberately routed away from, recreating the bug on the failure path.- relay = _configured_relay_base_url(provider)++ relay = _configured_relay_base_url(provider or "")+ if relay and normalized not in _RELAY_AWARE_CATALOG_FETCHERS:+ relayed = _relay_model_catalog(normalized, relay)+ if relayed:- return relayed++ return _chat_catalog_rows(relayed)+ return _static_catalog(normalized, _PROVIDER_CATALOG_FETCHERS.get(normalized))+ fetcher = _PROVIDER_CATALOG_FETCHERS.get(normalized)+ if fetcher is not None:+ models = fetcher(normalized, force_refresh)+ if models is not None:- return models++ return _chat_catalog_rows(models)+ try:+ models = _profile_live_catalog(normalized)+ except Exception:+ models = None+ if models is not None:- return models++ return _chat_catalog_rows(models)++ return _static_catalog(normalized, fetcher)++# ---------------------------------------------------------------------------# Disk cache for provider_model_ids() — keeps /model picker fast (otherwise every open re-fetches# every authed provider's /v1/models). One JSON file at $HERMES_HOME/provider_models_cache.json;