Coverage for src / local_deep_research / web / routes / route_registry.py: 82%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:55 +0000

1""" 

2Route Registry - Central documentation of all application routes 

3This file provides a single place to see all available routes across blueprints 

4 

5NOTE: This is primarily for documentation and reference purposes. 

6The actual routes are defined in their respective blueprint files. 

7To keep this in sync: 

81. Update this file when adding/removing routes 

92. Run tests to ensure URLs in tests match actual routes 

103. Consider using get_all_routes() in tests to validate against actual Flask routes 

11""" 

12 

13# Route patterns by blueprint 

14from typing import Any # noqa: E402 

15 

16ROUTE_REGISTRY: dict[str, Any] = { 

17 "research": { 

18 "blueprint": "research_bp", 

19 "url_prefix": None, # Routes at root level 

20 "routes": [ 

21 ("GET", "/", "index", "Home/Research page"), 

22 ( 

23 "POST", 

24 "/api/start_research", 

25 "start_research", 

26 "Start new research", 

27 ), 

28 ( 

29 "GET", 

30 "/api/research/<string:research_id>", 

31 "get_research_details", 

32 "Get research details", 

33 ), 

34 ( 

35 "GET", 

36 "/api/research/<string:research_id>/logs", 

37 "get_research_logs", 

38 "Get research logs", 

39 ), 

40 ( 

41 "GET", 

42 "/api/research/<research_id>/status", 

43 "get_research_status", 

44 "Get research status", 

45 ), 

46 ( 

47 "GET", 

48 "/api/report/<string:research_id>", 

49 "get_research_report", 

50 "Get research report", 

51 ), 

52 ( 

53 "POST", 

54 "/api/terminate/<string:research_id>", 

55 "terminate_research", 

56 "Stop research", 

57 ), 

58 ( 

59 "DELETE", 

60 "/api/delete/<string:research_id>", 

61 "delete_research", 

62 "Delete research", 

63 ), 

64 ("GET", "/api/history", "get_history", "Get research history"), 

65 ( 

66 "POST", 

67 "/api/clear_history", 

68 "clear_history", 

69 "Clear all history", 

70 ), 

71 ( 

72 "GET", 

73 "/progress/<string:research_id>", 

74 "progress_page", 

75 "Research progress page", 

76 ), 

77 ( 

78 "GET", 

79 "/results/<string:research_id>", 

80 "results_page", 

81 "Research results page", 

82 ), 

83 ( 

84 "GET", 

85 "/details/<string:research_id>", 

86 "research_details_page", 

87 "Research details page", 

88 ), 

89 ], 

90 }, 

91 "api_v1": { 

92 "blueprint": "api_blueprint", 

93 "url_prefix": "/api/v1", 

94 "routes": [ 

95 ("GET", "/", "api_documentation", "API documentation"), 

96 ("GET", "/health", "health_check", "Health check"), 

97 ( 

98 "POST", 

99 "/quick_summary", 

100 "api_quick_summary", 

101 "Quick LLM summary", 

102 ), 

103 ( 

104 "POST", 

105 "/quick_summary_test", 

106 "api_quick_summary_test", 

107 "Test quick summary", 

108 ), 

109 ( 

110 "POST", 

111 "/generate_report", 

112 "api_generate_report", 

113 "Generate research report", 

114 ), 

115 ( 

116 "POST", 

117 "/analyze_documents", 

118 "api_analyze_documents", 

119 "Analyze documents", 

120 ), 

121 ], 

122 }, 

123 "history": { 

124 "blueprint": "history_bp", 

125 "url_prefix": "/history", 

126 "routes": [ 

127 ("GET", "/", "history_page", "History page"), 

128 ("GET", "/api", "get_history", "Get history data"), 

129 ( 

130 "GET", 

131 "/status/<string:research_id>", 

132 "get_research_status", 

133 "Get research status", 

134 ), 

135 ( 

136 "GET", 

137 "/details/<string:research_id>", 

138 "get_research_details", 

139 "Get research details", 

140 ), 

141 ( 

142 "GET", 

143 "/logs/<string:research_id>", 

144 "get_research_logs", 

145 "Get research logs", 

146 ), 

147 ( 

148 "GET", 

149 "/log_count/<string:research_id>", 

150 "get_log_count", 

151 "Get log count", 

152 ), 

153 ( 

154 "GET", 

155 "/history/report/<string:research_id>", 

156 "get_report", 

157 "Get research report", 

158 ), 

159 ( 

160 "GET", 

161 "/markdown/<string:research_id>", 

162 "get_markdown", 

163 "Get markdown report", 

164 ), 

165 ], 

166 }, 

167 "settings": { 

168 "blueprint": "settings_bp", 

169 "url_prefix": "/settings", 

170 "routes": [ 

171 ("GET", "/", "settings_page", "Settings page"), 

172 ( 

173 "POST", 

174 "/save_all_settings", 

175 "save_all_settings", 

176 "Save all settings", 

177 ), 

178 ( 

179 "POST", 

180 "/reset_to_defaults", 

181 "reset_to_defaults", 

182 "Reset to defaults", 

183 ), 

184 ("GET", "/api", "api_get_all_settings", "Get all settings"), 

185 ( 

186 "GET", 

187 "/api/<path:key>", 

188 "api_get_setting", 

189 "Get specific setting", 

190 ), 

191 ("POST", "/api/<path:key>", "api_update_setting", "Update setting"), 

192 ( 

193 "DELETE", 

194 "/api/<path:key>", 

195 "api_delete_setting", 

196 "Delete setting", 

197 ), 

198 ("POST", "/api/import", "api_import_settings", "Import settings"), 

199 ( 

200 "GET", 

201 "/api/categories", 

202 "api_get_categories", 

203 "Get setting categories", 

204 ), 

205 ("GET", "/api/types", "api_get_types", "Get setting types"), 

206 ( 

207 "GET", 

208 "/api/ui_elements", 

209 "api_get_ui_elements", 

210 "Get UI elements", 

211 ), 

212 ( 

213 "GET", 

214 "/api/available-models", 

215 "api_get_available_models", 

216 "Get available models", 

217 ), 

218 ( 

219 "GET", 

220 "/api/available-search-engines", 

221 "api_get_available_search_engines", 

222 "Get search engines", 

223 ), 

224 ( 

225 "GET", 

226 "/api/warnings", 

227 "api_get_warnings", 

228 "Get settings warnings", 

229 ), 

230 ( 

231 "GET", 

232 "/api/ollama-status", 

233 "check_ollama_status", 

234 "Check Ollama status", 

235 ), 

236 ], 

237 }, 

238 "metrics": { 

239 "blueprint": "metrics_bp", 

240 "url_prefix": "/metrics", 

241 "routes": [ 

242 ("GET", "/", "metrics_dashboard", "Metrics dashboard"), 

243 ("GET", "/costs", "costs_page", "Costs page"), 

244 ("GET", "/star-reviews", "star_reviews_page", "Star reviews page"), 

245 ("GET", "/api/metrics", "api_metrics", "Get metrics data"), 

246 ( 

247 "GET", 

248 "/api/cost-analytics", 

249 "api_cost_analytics", 

250 "Get cost analytics", 

251 ), 

252 ("GET", "/api/pricing", "api_pricing", "Get pricing data"), 

253 ( 

254 "GET", 

255 "/api/metrics/research/<string:research_id>", 

256 "api_research_metrics", 

257 "Research metrics", 

258 ), 

259 ( 

260 "GET", 

261 "/api/metrics/research/<string:research_id>/timeline", 

262 "api_research_timeline_metrics", 

263 "Timeline metrics", 

264 ), 

265 ( 

266 "GET", 

267 "/api/metrics/research/<string:research_id>/search", 

268 "api_research_search_metrics", 

269 "Search metrics", 

270 ), 

271 ( 

272 "GET", 

273 "/api/ratings/<string:research_id>", 

274 "api_get_research_rating", 

275 "Get research rating", 

276 ), 

277 ( 

278 "POST", 

279 "/api/ratings/<string:research_id>", 

280 "api_save_research_rating", 

281 "Save research rating", 

282 ), 

283 ( 

284 "GET", 

285 "/api/research-costs/<string:research_id>", 

286 "api_research_costs", 

287 "Get research costs", 

288 ), 

289 ], 

290 }, 

291} 

292 

293 

294def get_all_routes(): 

295 """Get a flat list of all routes across blueprints""" 

296 all_routes = [] 

297 for blueprint_name, blueprint_info in ROUTE_REGISTRY.items(): 

298 prefix = blueprint_info["url_prefix"] or "" 

299 for method, path, endpoint, description in blueprint_info["routes"]: 

300 full_path = f"{prefix}{path}" if prefix else path 

301 all_routes.append( 

302 { 

303 "method": method, 

304 "path": full_path, 

305 "endpoint": f"{blueprint_name}.{endpoint}", 

306 "description": description, 

307 "blueprint": blueprint_name, 

308 } 

309 ) 

310 return all_routes 

311 

312 

313def get_routes_by_blueprint(blueprint_name): 

314 """Get routes for a specific blueprint""" 

315 if blueprint_name not in ROUTE_REGISTRY: 

316 return [] 

317 

318 blueprint_info = ROUTE_REGISTRY[blueprint_name] 

319 prefix = blueprint_info["url_prefix"] or "" 

320 routes = [] 

321 

322 for method, path, endpoint, description in blueprint_info["routes"]: 

323 full_path = f"{prefix}{path}" if prefix else path 

324 routes.append( 

325 { 

326 "method": method, 

327 "path": full_path, 

328 "endpoint": endpoint, 

329 "description": description, 

330 } 

331 ) 

332 return routes 

333 

334 

335def find_route(path_pattern): 

336 """Find routes matching a path pattern""" 

337 all_routes = get_all_routes() 

338 matching_routes = [] 

339 

340 for route in all_routes: 

341 if path_pattern.lower() in route["path"].lower(): 

342 matching_routes.append(route) 

343 

344 return matching_routes 

345 

346 

347if __name__ == "__main__": 347 ↛ 349line 347 didn't jump to line 349 because the condition on line 347 was never true

348 # Example usage 

349 print("All API routes:") 

350 for route in get_all_routes(): 

351 if "/api" in route["path"]: 

352 print( 

353 f"{route['method']:6} {route['path']:40} - {route['description']}" 

354 )