File size: 889 Bytes
95810d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from services.supabase_service import supabase
from typing import Dict, Any, Optional
import logging

logger = logging.getLogger("uvicorn")

class AuditService:
    @staticmethod
    async def log_action(
        user_id: Optional[str],
        action: str,
        agent_id: Optional[str] = None,
        task_id: Optional[str] = None,
        metadata: Optional[Dict[str, Any]] = None
    ):
        """
        Records an action in the audit_logs table.
        """
        try:
            data = {
                "user_id": user_id,
                "action": action,
                "agent_id": agent_id,
                "task_id": task_id,
                "metadata": metadata or {}
            }
            supabase.table("audit_logs").insert(data).execute()
        except Exception as e:
            logger.error(f"AuditService error: {str(e)}")

audit_service = AuditService()