""" Agent Notification Routes — endpoint for the ZeroClaw compliance agent to send notification emails via SMTP. POST /api/compliance/agent/notify """ import logging from datetime import datetime, timezone from fastapi import APIRouter from pydantic import BaseModel from compliance.services.smtp_sender import send_email logger = logging.getLogger(__name__) router = APIRouter(prefix="/compliance/agent", tags=["agent"]) class NotifyRequest(BaseModel): recipient: str subject: str body_html: str role: str escalation_id: str | None = None class NotifyResponse(BaseModel): status: str recipient: str subject: str role: str sent_at: str error: str | None = None @router.post("/notify", response_model=NotifyResponse) async def send_agent_notification(req: NotifyRequest): """Send a compliance notification email on behalf of the agent.""" result = send_email( recipient=req.recipient, subject=req.subject, body_html=_build_email_body(req), ) return NotifyResponse( status=result["status"], recipient=req.recipient, subject=req.subject, role=req.role, sent_at=datetime.now(timezone.utc).isoformat(), error=result.get("error"), ) def _build_email_body(req: NotifyRequest) -> str: """Wrap the agent's HTML body with a standard email frame.""" return f"""
Zugewiesen an: {req.role} {f' | Eskalation: {req.escalation_id}' if req.escalation_id else ''}
{req.body_html}Automatisch generiert vom BreakPilot Compliance Agent (ZeroClaw + Qwen)