The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli): custom/providers — fold isinstance guards and identity lookup chain
Tekniumdfa6bc0103ed
diff --git a/hermes_cli/providers.py b/hermes_cli/providers.pyindex e394dc8f699..3e91e69f14b 100644--- a/hermes_cli/providers.py+++ b/hermes_cli/providers.py@@ -332,9 +332,7 @@ def _user_pdef(pid: str, name: str, base_url: str, key_env: str, transport: strdef resolve_user_provider(name: str, user_config: Dict[str, Any]) -> Optional[ProviderDef]:"""Resolve a provider from the user's config.yaml ``providers:`` section."""- if not user_config or not isinstance(user_config, dict):- return None- entry = user_config.get(name)+ entry = user_config.get(name) if isinstance(user_config, dict) and user_config else Noneif not isinstance(entry, dict):return Nonereturn _user_pdef(name, entry.get("name", "") or name,@@ -372,10 +370,8 @@ def resolve_custom_provider(name: str, custom_providers: Optional[List[Dict[str,"""Resolve a provider from the user's config.yaml ``custom_providers`` list. A stored bare``"custom"`` (corrupt state from a prior model-switch bug) falls back to the first valid entryso existing configs self-heal."""- if not custom_providers or not isinstance(custom_providers, list):- return Nonerequested = (name or "").strip().lower()- if not requested:+ if not requested or not custom_providers or not isinstance(custom_providers, list):return Nonefirst_valid: Optional[ProviderDef] = Nonefor entry in custom_providers:diff --git a/hermes_cli/runtime_provider_custom.py b/hermes_cli/runtime_provider_custom.pyindex 0e6d31e4f3a..48f9f64428c 100644--- a/hermes_cli/runtime_provider_custom.py+++ b/hermes_cli/runtime_provider_custom.py@@ -153,9 +153,7 @@ def _match_new_style_provider(requested_norm: str, providers: Dict[str, Any]) ->def _match_legacy_custom_provider(requested_norm: str, custom_providers) -> Optional[Dict[str, Any]]:"""Scan the legacy ``custom_providers:`` list for ``requested_norm``."""for entry in custom_providers:- if not isinstance(entry, dict):- continue- name, base_url = entry.get("name"), entry.get("base_url")+ name, base_url = (entry.get("name"), entry.get("base_url")) if isinstance(entry, dict) else (None, None)if not isinstance(name, str) or not isinstance(base_url, str):continueprovider_key = _clean(entry.get("provider_key", ""))@@ -178,10 +176,9 @@ def _get_named_custom_provider(requested_provider: str) -> Optional[Dict[str, Anrp = _rp()config = rp.load_config()providers = config.get("providers")- if isinstance(providers, dict):- found = _match_new_style_provider(requested_norm, providers)- if found:- return found+ found = _match_new_style_provider(requested_norm, providers) if isinstance(providers, dict) else None+ if found:+ return foundif isinstance(config.get("custom_providers"), dict):logger.warning("custom_providers in config.yaml is a dict, not a list. ""Each entry must be prefixed with '-' in YAML. "@@ -221,9 +218,7 @@ def _find_custom_identity(matches: Callable[[Dict[str, Any]], bool]) -> Optionalexcept Exception:custom_providers = Nonefor entry in custom_providers or []:- if not isinstance(entry, dict):- continue- name = entry.get("name")+ name = entry.get("name") if isinstance(entry, dict) else Noneif isinstance(name, str) and name.strip() and matches(entry):return custom_provider_slug(name, str(entry.get("provider_key", "") or ""))return None@@ -258,10 +253,8 @@ def find_custom_provider_identity_by_model(model: str) -> Optional[str]:if isinstance(models, dict):return any(str(mid).strip().lower() == target for mid in models)if isinstance(models, list):- return any(- _model_id_matches(item.get("id") or item.get("name") if isinstance(item, dict) else item, target)- for item in models- )+ return any(_model_id_matches(item.get("id") or item.get("name") if isinstance(item, dict) else item, target)+ for item in models)return Falsereturn _find_custom_identity(_entry_serves_model)@@ -277,14 +270,10 @@ def canonical_custom_identity(*, base_url: Optional[str] = None, config_provider(3) the configured provider (arg, ``model.provider``, ``HERMES_INFERENCE_PROVIDER``) when itnames a real entry."""rp = _rp()- if base_url:- identity = find_custom_provider_identity(base_url)- if identity:- return identity- if model:- identity = find_custom_provider_identity_by_model(model)- if identity:- return identity+ identity = (find_custom_provider_identity(base_url) if base_url else None) or (+ find_custom_provider_identity_by_model(model) if model else None)+ if identity:+ return identitycandidate = str(config_provider or "").strip()if not candidate:try: