""" backend/routes/persona_routes.py §2.17 — Persona Switch REST endpoints """ from fastapi import HTTPException, APIRouter from pydantic import BaseModel router = APIRouter() class PersonaSwitchRequest(BaseModel): persona: str # "jarvis" | "friday" class PersonaStateResponse(BaseModel): active: str voice_id: str wake_word: str @router.post("/switch") async def switch_persona(req: PersonaSwitchRequest): """Switch active persona and broadcast to all connected clients.""" if req.persona not in ("jarvis", "friday"): raise HTTPException(status_code=400, detail="persona must be 'jarvis' or 'friday'") try: from modules.assistant_identity import set_mode set_mode(req.persona) from backend.ws.agent_ws import ws_manager await ws_manager.broadcast({ "event": "agent:switched_persona", "payload": {"persona": req.persona} }) return {"status": "ok", "active": req.persona} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) @router.get("/current") async def get_persona(): """Return the currently active persona with voice and wake-word metadata.""" try: from modules.assistant_identity import get_mode, get_voice_id_for_mode, get_wake_words_for_mode active = get_mode() return { "active": active, "voice_id": get_voice_id_for_mode(active), "wake_words": get_wake_words_for_mode(active), } except Exception as e: raise HTTPException(status_code=500, detail=str(e)) @router.get("/prompts") async def get_persona_prompts(): """Return the full system prompts for both personas (sanitised for UI display).""" try: from modules.assistant_identity import JARVIS_PERSONALITY_PROMPT, FRIDAY_PERSONALITY_PROMPT return { "jarvis": JARVIS_PERSONALITY_PROMPT[:500] + "...", "friday": FRIDAY_PERSONALITY_PROMPT[:500] + "...", } except Exception as e: raise HTTPException(status_code=500, detail=str(e))