Spaces:
Sleeping
Sleeping
File size: 1,718 Bytes
f37bf1d | 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 | # api/routes/sessions.py
from fastapi import APIRouter, HTTPException
from api.models import ApprovalRequest
from api.services import ChatService
router = APIRouter(prefix="/sessions", tags=["Sessions"])
@router.post("/{session_id}/approve")
async def approve_assistance(session_id: str, request: ApprovalRequest):
"""Approve or reject assistance request"""
try:
return await ChatService.approve_request(
session_id=session_id,
decision=request.decision,
reason=request.reason
)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/{session_id}/status")
async def get_session_status(session_id: str):
"""Get session status including interrupt state"""
try:
return await ChatService.get_session_status(session_id)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/{session_id}/history")
async def get_history(session_id: str):
"""Get conversation history"""
try:
return await ChatService.get_history(session_id)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("")
async def list_sessions():
"""List all active sessions with their status"""
try:
return await ChatService.list_sessions()
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.delete("/{session_id}")
async def clear_session(session_id: str):
"""Clear a session (useful for testing)"""
try:
return await ChatService.clear_session(session_id)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
|