from typing import Optional from fastapi import APIRouter, Query from app.core.security import UserContext from app.core.data_store import DataStore from app.agent.proactive_detector import ProactiveIssueDetector router = APIRouter(prefix="/api/proactive", tags=["Proactive Intelligence"]) data_store_instance: Optional[DataStore] = None @router.get("/insights") async def get_proactive_insights( account_id: Optional[str] = Query(None), is_internal: bool = Query(True), role: str = Query("operations_lead") ): """Returns proactive alerts, SLA breaches, ticket clusters, and carrier delays.""" ctx = UserContext(account_id=account_id, is_internal=is_internal, role=role) detector = ProactiveIssueDetector(data_store_instance) return detector.detect_all_issues(ctx)