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

31 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-25 01:07 +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 

14ROUTE_REGISTRY = { 

15 "research": { 

16 "blueprint": "research_bp", 

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

18 "routes": [ 

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

20 ( 

21 "POST", 

22 "/api/start_research", 

23 "start_research", 

24 "Start new research", 

25 ), 

26 ( 

27 "GET", 

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

29 "get_research_details", 

30 "Get research details", 

31 ), 

32 ( 

33 "GET", 

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

35 "get_research_logs", 

36 "Get research logs", 

37 ), 

38 ( 

39 "GET", 

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

41 "get_research_status", 

42 "Get research status", 

43 ), 

44 ( 

45 "GET", 

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

47 "get_research_report", 

48 "Get research report", 

49 ), 

50 ( 

51 "POST", 

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

53 "terminate_research", 

54 "Stop research", 

55 ), 

56 ( 

57 "DELETE", 

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

59 "delete_research", 

60 "Delete research", 

61 ), 

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

63 ( 

64 "POST", 

65 "/api/clear_history", 

66 "clear_history", 

67 "Clear all history", 

68 ), 

69 ( 

70 "GET", 

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

72 "progress_page", 

73 "Research progress page", 

74 ), 

75 ( 

76 "GET", 

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

78 "results_page", 

79 "Research results page", 

80 ), 

81 ( 

82 "GET", 

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

84 "research_details_page", 

85 "Research details page", 

86 ), 

87 ], 

88 }, 

89 "api_v1": { 

90 "blueprint": "api_blueprint", 

91 "url_prefix": "/api/v1", 

92 "routes": [ 

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

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

95 ( 

96 "POST", 

97 "/quick_summary", 

98 "api_quick_summary", 

99 "Quick LLM summary", 

100 ), 

101 ( 

102 "POST", 

103 "/quick_summary_test", 

104 "api_quick_summary_test", 

105 "Test quick summary", 

106 ), 

107 ( 

108 "POST", 

109 "/generate_report", 

110 "api_generate_report", 

111 "Generate research report", 

112 ), 

113 ( 

114 "POST", 

115 "/analyze_documents", 

116 "api_analyze_documents", 

117 "Analyze documents", 

118 ), 

119 ], 

120 }, 

121 "history": { 

122 "blueprint": "history_bp", 

123 "url_prefix": "/history", 

124 "routes": [ 

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

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

127 ( 

128 "GET", 

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

130 "get_research_status", 

131 "Get research status", 

132 ), 

133 ( 

134 "GET", 

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

136 "get_research_details", 

137 "Get research details", 

138 ), 

139 ( 

140 "GET", 

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

142 "get_research_logs", 

143 "Get research logs", 

144 ), 

145 ( 

146 "GET", 

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

148 "get_log_count", 

149 "Get log count", 

150 ), 

151 ( 

152 "GET", 

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

154 "get_report", 

155 "Get research report", 

156 ), 

157 ( 

158 "GET", 

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

160 "get_markdown", 

161 "Get markdown report", 

162 ), 

163 ], 

164 }, 

165 "settings": { 

166 "blueprint": "settings_bp", 

167 "url_prefix": "/settings", 

168 "routes": [ 

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

170 ( 

171 "POST", 

172 "/save_all_settings", 

173 "save_all_settings", 

174 "Save all settings", 

175 ), 

176 ( 

177 "POST", 

178 "/reset_to_defaults", 

179 "reset_to_defaults", 

180 "Reset to defaults", 

181 ), 

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

183 ( 

184 "GET", 

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

186 "api_get_setting", 

187 "Get specific setting", 

188 ), 

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

190 ( 

191 "DELETE", 

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

193 "api_delete_setting", 

194 "Delete setting", 

195 ), 

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

197 ( 

198 "GET", 

199 "/api/categories", 

200 "api_get_categories", 

201 "Get setting categories", 

202 ), 

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

204 ( 

205 "GET", 

206 "/api/ui_elements", 

207 "api_get_ui_elements", 

208 "Get UI elements", 

209 ), 

210 ( 

211 "GET", 

212 "/api/available-models", 

213 "api_get_available_models", 

214 "Get available models", 

215 ), 

216 ( 

217 "GET", 

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

219 "api_get_available_search_engines", 

220 "Get search engines", 

221 ), 

222 ( 

223 "GET", 

224 "/api/warnings", 

225 "api_get_warnings", 

226 "Get settings warnings", 

227 ), 

228 ( 

229 "GET", 

230 "/api/ollama-status", 

231 "check_ollama_status", 

232 "Check Ollama status", 

233 ), 

234 ], 

235 }, 

236 "metrics": { 

237 "blueprint": "metrics_bp", 

238 "url_prefix": "/metrics", 

239 "routes": [ 

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

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

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

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

244 ( 

245 "GET", 

246 "/api/cost-analytics", 

247 "api_cost_analytics", 

248 "Get cost analytics", 

249 ), 

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

251 ( 

252 "GET", 

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

254 "api_research_metrics", 

255 "Research metrics", 

256 ), 

257 ( 

258 "GET", 

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

260 "api_research_timeline_metrics", 

261 "Timeline metrics", 

262 ), 

263 ( 

264 "GET", 

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

266 "api_research_search_metrics", 

267 "Search metrics", 

268 ), 

269 ( 

270 "GET", 

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

272 "api_get_research_rating", 

273 "Get research rating", 

274 ), 

275 ( 

276 "POST", 

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

278 "api_save_research_rating", 

279 "Save research rating", 

280 ), 

281 ( 

282 "GET", 

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

284 "api_research_costs", 

285 "Get research costs", 

286 ), 

287 ], 

288 }, 

289} 

290 

291 

292def get_all_routes(): 

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

294 all_routes = [] 

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

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

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

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

299 all_routes.append( 

300 { 

301 "method": method, 

302 "path": full_path, 

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

304 "description": description, 

305 "blueprint": blueprint_name, 

306 } 

307 ) 

308 return all_routes 

309 

310 

311def get_routes_by_blueprint(blueprint_name): 

312 """Get routes for a specific blueprint""" 

313 if blueprint_name not in ROUTE_REGISTRY: 

314 return [] 

315 

316 blueprint_info = ROUTE_REGISTRY[blueprint_name] 

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

318 routes = [] 

319 

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

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

322 routes.append( 

323 { 

324 "method": method, 

325 "path": full_path, 

326 "endpoint": endpoint, 

327 "description": description, 

328 } 

329 ) 

330 return routes 

331 

332 

333def find_route(path_pattern): 

334 """Find routes matching a path pattern""" 

335 all_routes = get_all_routes() 

336 matching_routes = [] 

337 

338 for route in all_routes: 

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

340 matching_routes.append(route) 

341 

342 return matching_routes 

343 

344 

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

346 # Example usage 

347 print("All API routes:") 

348 for route in get_all_routes(): 

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

350 print( 

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

352 )