Coverage for src / lilbee / server / routes / crawl.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-04-29 19:16 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-04-29 19:16 +0000
1"""Crawl route handler."""
3from __future__ import annotations
5from litestar import post
6from litestar.exceptions import ValidationException
7from litestar.response import Stream
9from lilbee.server import handlers
10from lilbee.server.models import CrawlRequest
13@post("/api/crawl")
14async def crawl_route(data: CrawlRequest) -> Stream:
15 """Crawl a URL with streaming SSE progress events."""
16 from lilbee.crawler import require_valid_crawl_url
18 try:
19 require_valid_crawl_url(data.url)
20 except ValueError as exc:
21 raise ValidationException(str(exc)) from exc
22 gen = handlers.crawl_stream(url=data.url, depth=data.depth, max_pages=data.max_pages)
23 return Stream(gen, media_type="text/event-stream")