Coverage for src / lilbee / providers / local_servers / config_urls.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-06-28 01:01 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-06-28 01:01 +0000
1"""Resolve each local server's configured base URL, with spec-default fallback."""
3from __future__ import annotations
5from collections.abc import Callable
7from lilbee.core.config.model import cfg
8from lilbee.providers.local_servers.lm_studio import LM_STUDIO
9from lilbee.providers.local_servers.ollama import OLLAMA
10from lilbee.providers.local_servers.registry import LOCAL_SERVERS, local_server_for_key
11from lilbee.providers.local_servers.spec import LocalServerSpec
13_URL_ACCESSOR_BY_KEY: dict[str, Callable[[], str]] = {
14 OLLAMA.key: lambda: cfg.ollama_base_url,
15 LM_STUDIO.key: lambda: cfg.lm_studio_base_url,
16}
19def _configured_url(spec: LocalServerSpec) -> str:
20 return _URL_ACCESSOR_BY_KEY[spec.key]().strip() or spec.default_base_url
23def base_url_for(server_key: str) -> str:
24 """Configured URL for a server key, falling back to its spec default."""
25 spec = local_server_for_key(server_key)
26 if spec is None:
27 raise KeyError(f"Unknown local server: {server_key!r}")
28 return _configured_url(spec)
31def configured_local_servers() -> list[tuple[LocalServerSpec, str]]:
32 """Return (spec, resolved-url) for every known local server."""
33 return [(spec, _configured_url(spec)) for spec in LOCAL_SERVERS]