Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adclaw/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "1.0.30"
__version__ = "1.0.31"
10 changes: 9 additions & 1 deletion src/adclaw/app/routers/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)

router = APIRouter(prefix="/models", tags=["models"])
HOST_AI_PROVIDER_ID = "adclaw-host-ai"


class ProviderConfigRequest(BaseModel):
Expand Down Expand Up @@ -116,14 +117,21 @@ def _build_provider_info(
)


def _provider_info_sort_key(provider: ProviderInfo) -> tuple[int, str]:
if provider.id == HOST_AI_PROVIDER_ID:
return (0, "")
return (1, provider.name.lower())


@router.get(
"",
response_model=List[ProviderInfo],
summary="List all providers",
)
async def list_all_providers() -> List[ProviderInfo]:
data = load_providers_json()
return [_build_provider_info(p, data) for p in list_providers()]
providers = [_build_provider_info(p, data) for p in list_providers()]
return sorted(providers, key=_provider_info_sort_key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve registry provider priority after Host AI

When the custom Host AI provider is present (or even absent), this second sort reorders every non-Host provider alphabetically, discarding the priority order already returned by list_providers() via _PROVIDER_ORDER (and asserted by test_xiaomi_provider_sorted_first). In the normal built-in provider list this moves Xiaomi from the configured first position behind alphabetically earlier providers, so the Models UI no longer reflects the registry’s intended/default provider priority; only Host AI should be lifted while preserving the existing order for the rest.

Useful? React with 👍 / 👎.



@router.put(
Expand Down
37 changes: 36 additions & 1 deletion tests/test_adclaw_ai_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from fastapi import HTTPException

from adclaw.app.routers import providers as provider_routes
from adclaw.providers.models import CustomProviderData, ModelInfo, ProvidersData
from adclaw.providers.models import (
CustomProviderData,
ModelInfo,
ProviderDefinition,
ProvidersData,
)
from adclaw.providers.store import (
ProviderUsageRequestError,
fetch_provider_usage,
Expand Down Expand Up @@ -214,3 +219,33 @@ def test_provider_usage_route_is_threadpool_safe_and_validation_guarded():
assert "def get_provider_usage(" in source
assert "async def get_provider_usage(" not in source
assert "except (ValueError, ValidationError)" in source


@pytest.mark.asyncio
async def test_list_all_providers_prioritizes_adclaw_ai(monkeypatch):
data = _host_ai_data()
xiaomi = ProviderDefinition(
id="xiaomi-codingplan",
name="Xiaomi Coding Plan",
models=[ModelInfo(id="mimo-v2.5", name="MiMo v2.5")],
)
host_ai = ProviderDefinition(
id="adclaw-host-ai",
name="AdClaw AI",
models=data.custom_providers["adclaw-host-ai"].models,
is_custom=True,
)

monkeypatch.setattr(provider_routes, "load_providers_json", lambda: data)
monkeypatch.setattr(
provider_routes,
"list_providers",
lambda: [xiaomi, host_ai],
)

providers = await provider_routes.list_all_providers()

assert [provider.id for provider in providers[:2]] == [
"adclaw-host-ai",
"xiaomi-codingplan",
]
Loading