11import asyncio
22from typing import AsyncGenerator , List , Optional
33
4+ from fastapi .routing import APIRoute
45import requests
56import structlog
67from fastapi import APIRouter , Depends , FastAPI
1617
1718logger = structlog .get_logger ("codegate" )
1819
19- dashboard_router = APIRouter (tags = [ "Dashboard" ] )
20+ dashboard_router = APIRouter ()
2021db_reader = None
2122
23+ def uniq_name (route : APIRoute ):
24+ return f"v1_{ route .name } "
25+
2226def get_db_reader ():
2327 global db_reader
2428 if db_reader is None :
@@ -36,7 +40,7 @@ def fetch_latest_version() -> str:
3640 data = response .json ()
3741 return data .get ("tag_name" , "unknown" )
3842
39- @dashboard_router .get ("/dashboard/messages" )
43+ @dashboard_router .get ("/dashboard/messages" , tags = [ "Dashboard" ], generate_unique_id_function = uniq_name )
4044def get_messages (db_reader : DbReader = Depends (get_db_reader )) -> List [Conversation ]:
4145 """
4246 Get all the messages from the database and return them as a list of conversations.
@@ -46,7 +50,7 @@ def get_messages(db_reader: DbReader = Depends(get_db_reader)) -> List[Conversat
4650 return asyncio .run (parse_messages_in_conversations (prompts_outputs ))
4751
4852
49- @dashboard_router .get ("/dashboard/alerts" )
53+ @dashboard_router .get ("/dashboard/alerts" , tags = [ "Dashboard" ], generate_unique_id_function = uniq_name )
5054def get_alerts (db_reader : DbReader = Depends (get_db_reader )) -> List [Optional [AlertConversation ]]:
5155 """
5256 Get all the messages from the database and return them as a list of conversations.
@@ -64,14 +68,14 @@ async def generate_sse_events() -> AsyncGenerator[str, None]:
6468 yield f"data: { message } \n \n "
6569
6670
67- @dashboard_router .get ("/dashboard/alerts_notification" )
71+ @dashboard_router .get ("/dashboard/alerts_notification" , tags = [ "Dashboard" ], generate_unique_id_function = uniq_name )
6872async def stream_sse ():
6973 """
7074 Send alerts event
7175 """
7276 return StreamingResponse (generate_sse_events (), media_type = "text/event-stream" )
7377
74- @dashboard_router .get ("/dashboard/version" )
78+ @dashboard_router .get ("/dashboard/version" , tags = [ "Dashboard" ], generate_unique_id_function = uniq_name )
7579def version_check ():
7680 try :
7781 latest_version = fetch_latest_version ()
0 commit comments