From e60a4ccbf4a291a387fcd71f063f78fc98c0ff0b Mon Sep 17 00:00:00 2001 From: Austin Pickett Date: Wed, 22 Jul 2026 00:19:35 -0400 Subject: [PATCH] refactor: tidy dynamic schema-options merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup pass on the per-request provider-options merge — behavior unchanged: - collapse the duplicated entry-validation shared by merge() and its callers into a single guard inside merge() - read the configured memory provider in readable steps instead of a nested ternary - build the merged mapping as one {**base, **overlay} expression - space out logical blocks --- hermes_cli/web_server.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py index cf0ceaaf7ef9..bfe31468aca0 100644 --- a/hermes_cli/web_server.py +++ b/hermes_cli/web_server.py @@ -1145,11 +1145,14 @@ def _memory_provider_schema_options(cfg: Dict[str, Any]) -> List[str]: disk — never silently vanishes from the dropdown. """ options = _memory_provider_options() - current = _normalize_memory_provider_name( - cfg.get("memory", {}).get("provider") if isinstance(cfg.get("memory"), dict) else None - ) + + memory = cfg.get("memory") + configured = memory.get("provider") if isinstance(memory, dict) else None + current = _normalize_memory_provider_name(configured) + if current and current not in options: options = [*options, current] + return options @@ -1173,27 +1176,28 @@ def _schema_with_dynamic_provider_options() -> Dict[str, Dict[str, Any]]: cfg = load_config() except Exception: # pragma: no cover - schema must survive config errors return CONFIG_SCHEMA + overlay: Dict[str, Dict[str, Any]] = {} - def _merge(key: str, merged: List[str]) -> None: + def merge(key: str, options: List[str]) -> None: entry = CONFIG_SCHEMA.get(key) - if not isinstance(entry, dict) or not isinstance(entry.get("options"), list): - return - if merged != entry["options"]: - overlay[key] = {**entry, "options": merged} + + if isinstance(entry, dict) and isinstance(entry.get("options"), list) and options != entry["options"]: + overlay[key] = {**entry, "options": options} for kind in ("tts", "stt"): entry = CONFIG_SCHEMA.get(f"{kind}.provider") - if isinstance(entry, dict) and isinstance(entry.get("options"), list): - _merge(f"{kind}.provider", _custom_provider_options(kind, list(entry["options"]), cfg)) + existing = entry.get("options") if isinstance(entry, dict) else None - _merge("memory.provider", _memory_provider_schema_options(cfg)) + if isinstance(existing, list): + merge(f"{kind}.provider", _custom_provider_options(kind, list(existing), cfg)) + + merge("memory.provider", _memory_provider_schema_options(cfg)) if not overlay: return CONFIG_SCHEMA - fields = dict(CONFIG_SCHEMA) - fields.update(overlay) - return fields + + return {**CONFIG_SCHEMA, **overlay} class ConfigUpdate(BaseModel):