@@ -746,6 +746,38 @@ async def get_alerts_by_workspace(
746
746
)
747
747
return prompts
748
748
749
+ async def get_alerts_summary_by_workspace (self , workspace_id : str ) -> dict :
750
+ """Get aggregated alert summary counts for a given workspace_id."""
751
+ sql = text (
752
+ """
753
+ SELECT
754
+ COUNT(*) AS total_alerts,
755
+ SUM(CASE WHEN a.trigger_type = 'codegate-secrets' THEN 1 ELSE 0 END)
756
+ AS codegate_secrets_count,
757
+ SUM(CASE WHEN a.trigger_type = 'codegate-context-retriever' THEN 1 ELSE 0 END)
758
+ AS codegate_context_retriever_count,
759
+ SUM(CASE WHEN a.trigger_type = 'codegate-pii' THEN 1 ELSE 0 END)
760
+ AS codegate_pii_count
761
+ FROM alerts a
762
+ INNER JOIN prompts p ON p.id = a.prompt_id
763
+ WHERE p.workspace_id = :workspace_id
764
+ """
765
+ )
766
+ conditions = {"workspace_id" : workspace_id }
767
+
768
+ async with self ._async_db_engine .begin () as conn :
769
+ result = await conn .execute (sql , conditions )
770
+ row = result .fetchone ()
771
+
772
+ # Return a dictionary with counts (handling None values safely)
773
+ return {
774
+ "codegate_secrets_count" : row .codegate_secrets_count or 0 if row else 0 ,
775
+ "codegate_context_retriever_count" : (
776
+ row .codegate_context_retriever_count or 0 if row else 0
777
+ ),
778
+ "codegate_pii_count" : row .codegate_pii_count or 0 if row else 0 ,
779
+ }
780
+
749
781
async def get_workspaces (self ) -> List [WorkspaceWithSessionInfo ]:
750
782
sql = text (
751
783
"""
0 commit comments