SAAHMATHWORKS
ready for hugging face space
f37bf1d
# 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))