Coverage for src/lilbee/server/routes/agent_config.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""Agent-client config routes: which clients are installed, and their live config.""" 

2 

3from __future__ import annotations 

4 

5from litestar import Request, get 

6from litestar.exceptions import NotFoundException 

7from litestar.params import FromPath 

8 

9from lilbee.app.agent_configs.document import parse_agent_client 

10from lilbee.server import handlers 

11from lilbee.server.models import AgentConfigIndexResponse, AgentConfigResponse 

12 

13 

14def _base_url(request: Request) -> str: 

15 """The origin this request arrived on, so the config points back at this server.""" 

16 return str(request.base_url).rstrip("/") 

17 

18 

19@get("/api/agent-config") 

20async def agent_config_index_route() -> AgentConfigIndexResponse: 

21 """Supported AI clients, with whether each one's CLI is installed on this machine.""" 

22 return await handlers.agent_config_index() 

23 

24 

25@get("/api/agent-config/{client:str}") 

26async def agent_config_route(client: FromPath[str], request: Request) -> AgentConfigResponse: 

27 """One client's paste-ready config, carrying this server's URL and current token.""" 

28 try: 

29 parsed = parse_agent_client(client) 

30 except ValueError as exc: 

31 raise NotFoundException(str(exc)) from exc 

32 return await handlers.agent_config(parsed, _base_url(request))