From 466f3a11de47b50a65230cfb019265603a5adb01 Mon Sep 17 00:00:00 2001 From: helix4u <4317663+helix4u@users.noreply.github.com> Date: Tue, 5 May 2026 20:54:20 -0600 Subject: [PATCH] fix(gateway): preserve model picker current context --- hermes_cli/model_switch.py | 4 ++ .../hermes_cli/test_list_picker_providers.py | 49 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py index ec3ca6aed2..dfaae1448a 100644 --- a/hermes_cli/model_switch.py +++ b/hermes_cli/model_switch.py @@ -1687,9 +1687,11 @@ def list_authenticated_providers( def list_picker_providers( current_provider: str = "", + current_base_url: str = "", user_providers: dict = None, custom_providers: list | None = None, max_models: int = 8, + current_model: str = "", ) -> List[dict]: """Interactive-picker variant of :func:`list_authenticated_providers`. @@ -1714,9 +1716,11 @@ def list_picker_providers( providers = list_authenticated_providers( current_provider=current_provider, + current_base_url=current_base_url, user_providers=user_providers, custom_providers=custom_providers, max_models=max_models, + current_model=current_model, ) filtered: List[dict] = [] diff --git a/tests/hermes_cli/test_list_picker_providers.py b/tests/hermes_cli/test_list_picker_providers.py index e424a104fd..1d3e75e036 100644 --- a/tests/hermes_cli/test_list_picker_providers.py +++ b/tests/hermes_cli/test_list_picker_providers.py @@ -190,8 +190,11 @@ def test_max_models_caps_openrouter_live_output(monkeypatch): def test_passthrough_kwargs_to_base(monkeypatch): - """All kwargs (current_provider, user_providers, custom_providers, max_models) - must be forwarded to ``list_authenticated_providers`` unchanged. + """All kwargs must be forwarded to ``list_authenticated_providers`` unchanged. + + The gateway /model picker passes ``current_base_url`` and ``current_model`` + so custom endpoint grouping can mark the current row. Dropping those kwargs + regressed Telegram/Discord into the text-list fallback. """ captured = {} @@ -205,12 +208,54 @@ def test_passthrough_kwargs_to_base(monkeypatch): model_switch.list_picker_providers( current_provider="openrouter", + current_base_url="http://x", + current_model="openai/gpt-5.4", user_providers={"foo": {"api": "http://x"}}, custom_providers=[{"name": "bar", "base_url": "http://y"}], max_models=12, ) assert captured["current_provider"] == "openrouter" + assert captured["current_base_url"] == "http://x" + assert captured["current_model"] == "openai/gpt-5.4" assert captured["user_providers"] == {"foo": {"api": "http://x"}} assert captured["custom_providers"] == [{"name": "bar", "base_url": "http://y"}] assert captured["max_models"] == 12 + + +def test_current_custom_endpoint_passthrough_marks_current_row(monkeypatch): + """Interactive picker should preserve current custom endpoint semantics.""" + monkeypatch.setattr("agent.models_dev.fetch_models_dev", lambda: {}) + monkeypatch.setattr("agent.models_dev.PROVIDER_TO_MODELS_DEV", {}) + monkeypatch.setattr("hermes_cli.providers.HERMES_OVERLAYS", {}) + monkeypatch.setattr("hermes_cli.models.fetch_openrouter_models", + lambda *a, **kw: []) + + result = model_switch.list_picker_providers( + current_provider="custom:ollama", + current_base_url="http://localhost:11434/v1", + current_model="glm-5.1", + user_providers={}, + custom_providers=[ + { + "name": "Ollama — GLM 5.1", + "base_url": "http://localhost:11434/v1", + "api_key": "ollama", + "model": "glm-5.1", + }, + { + "name": "Ollama — Qwen3", + "base_url": "http://localhost:11434/v1", + "api_key": "ollama", + "model": "qwen3", + }, + ], + max_models=50, + ) + + custom_rows = [p for p in result if p.get("is_user_defined")] + assert len(custom_rows) == 1 + row = custom_rows[0] + assert row["slug"] == "custom:ollama" + assert row["is_current"] is True + assert row["models"] == ["glm-5.1", "qwen3"]