Coverage for src / lilbee / server / handlers / __init__.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-06-28 01:01 +0000

1"""Framework-agnostic route handlers for the lilbee HTTP server. 

2 

3Every public function is a plain async callable; no framework imports. 

4Return types are dicts (JSON responses), lists, or async generators of SSE strings. 

5 

6Handlers are grouped by concern (sse, rag, models, ingest, config, documents, 

7crawl) under sibling submodules. The names re-exported below are the public 

8API consumed by ``server/routes/*.py``. 

9""" 

10 

11from __future__ import annotations 

12 

13from lilbee.app.status import gather_status 

14from lilbee.app.version import get_version 

15from lilbee.server.handlers.config import ( 

16 get_config, 

17 get_config_defaults, 

18 update_config, 

19) 

20from lilbee.server.handlers.crawl import crawl_stream 

21from lilbee.server.handlers.documents import ( 

22 delete_documents, 

23 get_source_content, 

24 list_documents, 

25) 

26from lilbee.server.handlers.ingest import ( 

27 MAX_ADD_FILES, 

28 add_files_stream, 

29 import_stream, 

30 sync_stream, 

31 validate_add_paths, 

32) 

33from lilbee.server.handlers.models import ( 

34 TASK_ENDPOINT_PATH, 

35 ModelCatalogSection, 

36 ModelsResponse, 

37 format_task_mismatch, 

38 list_external_models, 

39 list_models, 

40 models_catalog, 

41 models_delete, 

42 models_installed, 

43 models_pull, 

44 models_show, 

45 set_chat_model, 

46 set_embedding_model, 

47 set_reranker_model, 

48 set_vision_model, 

49) 

50from lilbee.server.handlers.rag import ( 

51 ask, 

52 ask_stream, 

53 chat, 

54 chat_stream, 

55 search, 

56) 

57from lilbee.server.handlers.sse import ( 

58 SseStream, 

59 classify_load_error, 

60 sse_done, 

61 sse_error, 

62 sse_event, 

63) 

64from lilbee.server.models import HealthResponse, StatusResponse 

65 

66 

67async def health() -> HealthResponse: 

68 """Return service health and version.""" 

69 return HealthResponse(status="ok", version=get_version()) 

70 

71 

72async def status() -> StatusResponse: 

73 """Return config, sources, and chunk counts.""" 

74 raw = gather_status() 

75 return StatusResponse(**raw.model_dump(exclude_none=True)) 

76 

77 

78__all__ = [ 

79 "MAX_ADD_FILES", 

80 "TASK_ENDPOINT_PATH", 

81 "ModelCatalogSection", 

82 "ModelsResponse", 

83 "SseStream", 

84 "add_files_stream", 

85 "ask", 

86 "ask_stream", 

87 "chat", 

88 "chat_stream", 

89 "classify_load_error", 

90 "crawl_stream", 

91 "delete_documents", 

92 "format_task_mismatch", 

93 "get_config", 

94 "get_config_defaults", 

95 "get_source_content", 

96 "health", 

97 "import_stream", 

98 "list_documents", 

99 "list_external_models", 

100 "list_models", 

101 "models_catalog", 

102 "models_delete", 

103 "models_installed", 

104 "models_pull", 

105 "models_show", 

106 "search", 

107 "set_chat_model", 

108 "set_embedding_model", 

109 "set_reranker_model", 

110 "set_vision_model", 

111 "sse_done", 

112 "sse_error", 

113 "sse_event", 

114 "status", 

115 "sync_stream", 

116 "update_config", 

117 "validate_add_paths", 

118]