Repository navigation
feat: dark/light theme toggle and live provider model list #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Live model listing for providers, used by the HTTP server.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import logging | ||
|
|
||
| from coding_agent.core.config import ProviderName | ||
| from coding_agent.plugins.llm_provider import LLMProviderPlugin | ||
| from coding_agent.providers.openai_compat import OpenAICompatProvider | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Short timeout so a dead provider cannot hang the webui. | ||
| LIST_MODELS_TIMEOUT_SECONDS = 10.0 | ||
|
|
||
|
|
||
| async def list_provider_models( | ||
| provider: ProviderName, | ||
| *, | ||
| timeout: float = LIST_MODELS_TIMEOUT_SECONDS, | ||
| ) -> list[str]: | ||
| """Return model ids for an OpenAI-compatible provider. | ||
|
|
||
| Provider construction reuses ``LLMProviderPlugin.provide_llm`` so base_url | ||
| and env-var API-key resolution stay in one place. A fresh plugin instance | ||
| is created per call, so the constructed provider (and its httpx client) is | ||
| short-lived and is closed here — the plugin-level instance cache is never | ||
| shared across requests. | ||
|
|
||
| Returns an empty list when the provider is not OpenAI-compatible | ||
| (anthropic, codex, kimi-code-anthropic, copilot). Raises on construction | ||
| or network failure; callers decide how to surface that. | ||
| """ | ||
| plugin = LLMProviderPlugin(provider=provider, model="", api_key="") | ||
| instance = plugin.provide_llm() | ||
| if not isinstance(instance, OpenAICompatProvider): | ||
| return [] | ||
| try: | ||
| return await asyncio.wait_for(instance.list_models(), timeout=timeout) | ||
| finally: | ||
| await instance.close() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| """Tests for the GET /providers/{provider}/models endpoint and its helper.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from httpx import ASGITransport, AsyncClient | ||
|
|
||
| import coding_agent.server.http_server as http_server | ||
| from coding_agent.core.config import settings | ||
| from coding_agent.plugins.llm_provider import LLMProviderPlugin | ||
| from coding_agent.providers.openai_compat import OpenAICompatProvider | ||
| from coding_agent.server.http_server import app | ||
| from coding_agent.server.provider_models import list_provider_models | ||
| from coding_agent.server.rate_limit import limiter | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def client(): | ||
| """Create async test client with a fresh rate limiter.""" | ||
| limiter.reset() | ||
| transport = ASGITransport(app=app) | ||
| async with AsyncClient(transport=transport, base_url="http://test") as ac: | ||
| yield ac | ||
|
|
||
|
|
||
| class TestProviderModelsEndpoint: | ||
| """Endpoint-level tests with the provider client mocked out.""" | ||
|
|
||
| async def test_live_listing_returns_model_ids(self, client, monkeypatch): | ||
| async def fake_list_provider_models(provider, *, timeout=10.0): | ||
| assert provider == "kimi-code" | ||
| return ["kimi-for-coding", "kimi-for-coding-highspeed", "k3", "k3-256k"] | ||
|
|
||
| monkeypatch.setattr( | ||
| http_server, "list_provider_models", fake_list_provider_models | ||
| ) | ||
|
|
||
| response = await client.get("/providers/kimi-code/models") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == { | ||
| "provider": "kimi-code", | ||
| "models": [ | ||
| {"id": "kimi-for-coding"}, | ||
| {"id": "kimi-for-coding-highspeed"}, | ||
| {"id": "k3"}, | ||
| {"id": "k3-256k"}, | ||
| ], | ||
| "source": "live", | ||
| } | ||
|
|
||
| async def test_unknown_provider_returns_422(self, client): | ||
| response = await client.get("/providers/not-a-provider/models") | ||
|
|
||
| assert response.status_code == 422 | ||
|
|
||
| async def test_listing_failure_returns_unavailable(self, client, monkeypatch): | ||
| async def failing_list_provider_models(provider, *, timeout=10.0): | ||
| raise RuntimeError("no API key configured") | ||
|
|
||
| monkeypatch.setattr( | ||
| http_server, "list_provider_models", failing_list_provider_models | ||
| ) | ||
|
|
||
| response = await client.get("/providers/deepseek/models") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == { | ||
| "provider": "deepseek", | ||
| "models": [], | ||
| "source": "unavailable", | ||
| } | ||
|
|
||
| async def test_empty_listing_returns_unavailable(self, client, monkeypatch): | ||
| async def empty_list_provider_models(provider, *, timeout=10.0): | ||
| return [] | ||
|
|
||
| monkeypatch.setattr( | ||
| http_server, "list_provider_models", empty_list_provider_models | ||
| ) | ||
|
|
||
| response = await client.get("/providers/anthropic/models") | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == { | ||
| "provider": "anthropic", | ||
| "models": [], | ||
| "source": "unavailable", | ||
| } | ||
|
|
||
| async def test_requires_api_key_when_configured(self, monkeypatch): | ||
| async def fake_list_provider_models(provider, *, timeout=10.0): | ||
| return ["k3"] | ||
|
|
||
| monkeypatch.setattr( | ||
| http_server, "list_provider_models", fake_list_provider_models | ||
| ) | ||
| limiter.reset() | ||
| with patch.object(settings, "http_api_key", "test-secret-key"): | ||
| transport = ASGITransport(app=app) | ||
| async with AsyncClient( | ||
| transport=transport, base_url="http://test" | ||
| ) as authed_client: | ||
| unauthenticated = await authed_client.get("/providers/kimi-code/models") | ||
| authenticated = await authed_client.get( | ||
| "/providers/kimi-code/models", | ||
| headers={"X-API-Key": "test-secret-key"}, | ||
| ) | ||
|
|
||
| assert unauthenticated.status_code == 401 | ||
| assert authenticated.status_code == 200 | ||
| assert authenticated.json()["source"] == "live" | ||
|
|
||
|
|
||
| class TestListProviderModelsHelper: | ||
| """Helper-level tests: provider reuse, filtering, timeout, cleanup.""" | ||
|
|
||
| async def test_openai_compatible_provider_returns_ids_and_closes_client( | ||
| self, monkeypatch | ||
| ): | ||
| captured: dict[str, OpenAICompatProvider] = {} | ||
|
|
||
| real_init = OpenAICompatProvider.__init__ | ||
|
|
||
| def tracking_init(self, *args, **kwargs): | ||
| real_init(self, *args, **kwargs) | ||
| captured["instance"] = self | ||
|
|
||
| async def fake_list_models(self): | ||
| return ["kimi-for-coding", "k3"] | ||
|
|
||
| monkeypatch.setattr(OpenAICompatProvider, "__init__", tracking_init) | ||
| monkeypatch.setattr(OpenAICompatProvider, "list_models", fake_list_models) | ||
|
|
||
| ids = await list_provider_models("kimi-code") | ||
|
|
||
| assert ids == ["kimi-for-coding", "k3"] | ||
| # The short-lived dedicated client is closed after the call. | ||
| assert captured["instance"]._http_client is None | ||
|
|
||
| async def test_non_openai_compatible_provider_returns_empty(self, monkeypatch): | ||
| sentinel = object() | ||
|
|
||
| monkeypatch.setattr( | ||
| LLMProviderPlugin, "provide_llm", lambda self, **kwargs: sentinel | ||
| ) | ||
|
|
||
| assert await list_provider_models("anthropic") == [] | ||
|
|
||
| async def test_listing_hits_timeout(self, monkeypatch): | ||
| async def slow_list_models(self): | ||
| await asyncio.sleep(5) | ||
| return ["never"] | ||
|
|
||
| monkeypatch.setattr(OpenAICompatProvider, "list_models", slow_list_models) | ||
|
|
||
| with pytest.raises(asyncio.TimeoutError): | ||
| await list_provider_models("openai", timeout=0.05) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: delete-cloud/Coding-Agent-Loop
Length of output: 36514
🏁 Script executed:
Repository: delete-cloud/Coding-Agent-Loop
Length of output: 15831
Close non-compatible provider instances before returning an empty list.
provide_llm()constructs instances beforeisinstance(instance, OpenAICompatProvider)checks them, so non-compatible providers bypassfinallyand keep their short-lived cleanup resources alive.coding-agent/src/coding_agent/server/provider_models.py#L35-L42: return the non-compatible provider to cleanup instead of returning early, or skip construction via an explicit OpenAI-compatible provider-only path.coding-agent/tests/ui/test_provider_models.py#L144-L151: replace the sentinel with a non-compatible provider/fake and assert it is closed.📍 Affects 2 files
coding-agent/src/coding_agent/server/provider_models.py#L35-L42(this comment)coding-agent/tests/ui/test_provider_models.py#L144-L151🤖 Prompt for AI Agents