File size: 1,620 Bytes
1397957
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Question API routes."""
from typing import List
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, Field

from ..tool import (
    reply_to_question, 
    reject_question, 
    get_pending_questions,
    QuestionReply,
)


router = APIRouter(prefix="/question", tags=["question"])


class QuestionAnswerRequest(BaseModel):
    """Request to answer a question."""
    answers: List[List[str]] = Field(..., description="Answers in order (each is array of selected labels)")


@router.get("")
@router.get("/")
async def list_pending_questions(session_id: str = None):
    """List all pending questions."""
    pending = get_pending_questions(session_id)
    return {"pending": pending}


@router.post("/{request_id}/reply")
async def answer_question(request_id: str, request: QuestionAnswerRequest):
    """Submit answers to a pending question."""
    success = await reply_to_question(request_id, request.answers)
    
    if not success:
        raise HTTPException(
            status_code=404, 
            detail=f"Question request '{request_id}' not found or already answered"
        )
    
    return {"status": "answered", "request_id": request_id}


@router.post("/{request_id}/reject")
async def dismiss_question(request_id: str):
    """Dismiss/reject a pending question without answering."""
    success = await reject_question(request_id)
    
    if not success:
        raise HTTPException(
            status_code=404,
            detail=f"Question request '{request_id}' not found or already handled"
        )
    
    return {"status": "rejected", "request_id": request_id}