File size: 2,104 Bytes
a31f556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
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))