"""Liefert die im Mac-Worker verfügbaren Verarbeitungs-Profile aus. Cached die Liste 60 s, damit der Mac nicht bei jedem Reload getroffen wird. """ from __future__ import annotations import logging import time from fastapi import APIRouter, Depends from app.core.auth import current_user from app.core.mac_client import MacClient from app.models.user import User router = APIRouter(prefix="/api", tags=["profiles"]) log = logging.getLogger("voice-agent.profiles") _CACHE: dict = {"profiles": None, "ts": 0.0} _TTL = 60.0 _FALLBACK = [{"name": "meeting", "display_name": "Sitzungsprotokoll", "language": "de"}] @router.get("/profiles") async def list_profiles(_: User = Depends(current_user)): now = time.time() if _CACHE["profiles"] is not None and now - _CACHE["ts"] < _TTL: return {"profiles": _CACHE["profiles"]} try: profiles = await MacClient().list_profiles() if not profiles: profiles = _FALLBACK except Exception as e: # noqa: BLE001 log.warning("Konnte Profile vom Mac nicht laden: %s — Fallback wird genutzt", e) profiles = _FALLBACK _CACHE["profiles"] = profiles _CACHE["ts"] = now return {"profiles": profiles}