feat: agent platform initial commit
- FastAPI + HTMX UI: dashboard, agents CRUD, chat, audit, tools - SQLite schema: agents, conversations, messages, audit, sessions - Code-agent sync (agents/*.py -> DB on startup) - MCP client with health check - Token auth (Bearer + session) - LiteLLM integration via llm.py - Docker Compose: agent-platform + mcp-tools services - Smoke tests pass: /health 200, /api/agents 200, / 401
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Audit-Helper: strukturiertes Logging aller Aktionen."""
|
||||
import logging
|
||||
import json
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, Any
|
||||
import aiosqlite
|
||||
|
||||
from config import settings
|
||||
from db import log_audit, get_db
|
||||
|
||||
|
||||
logger = logging.getLogger("audit")
|
||||
|
||||
|
||||
async def record(
|
||||
db: aiosqlite.Connection,
|
||||
agent_id: Optional[str],
|
||||
user_id: str,
|
||||
action: str,
|
||||
target: Optional[str] = None,
|
||||
args: Optional[Dict[str, Any]] = None,
|
||||
result: Optional[Dict[str, Any]] = None,
|
||||
duration_ms: Optional[int] = None,
|
||||
) -> None:
|
||||
"""Schreibt einen Audit-Eintrag in DB + Logger."""
|
||||
await log_audit(
|
||||
db=db,
|
||||
agent_id=agent_id,
|
||||
user_id=user_id,
|
||||
action=action,
|
||||
target=target,
|
||||
args=args,
|
||||
result=result,
|
||||
duration_ms=duration_ms,
|
||||
)
|
||||
|
||||
log_entry = {
|
||||
"ts": datetime.utcnow().isoformat(),
|
||||
"agent_id": agent_id,
|
||||
"user_id": user_id,
|
||||
"action": action,
|
||||
"target": target,
|
||||
"args": args,
|
||||
"result": result,
|
||||
"duration_ms": duration_ms,
|
||||
}
|
||||
logger.info(json.dumps(log_entry, default=str))
|
||||
|
||||
|
||||
async def get_recent(db: aiosqlite.Connection, limit: int = 100, agent_id: Optional[str] = None):
|
||||
"""Holt die letzten Audit-Einträge."""
|
||||
from db import list_audit
|
||||
return await list_audit(db, agent_id=agent_id, limit=limit)
|
||||
Reference in New Issue
Block a user