22 lines
881 B
Python
22 lines
881 B
Python
import json
|
|
import logging
|
|
from fastapi import APIRouter, Depends, HTTPException, Response
|
|
from common.db import fetchone
|
|
from common.deps import verify_api_key
|
|
from integrations.llm.schemas.plan import PlanOutput
|
|
|
|
router = APIRouter(prefix="/api/plans", tags=["plans"], dependencies=[Depends(verify_api_key)])
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get("/{run_id}", response_model=PlanOutput | None)
|
|
async def get_plan(run_id: str):
|
|
logger.info("GET /api/plans/%s", run_id)
|
|
row = await fetchone("SELECT plan_data FROM analysis_runs WHERE analysis_run_id = %s", (run_id,))
|
|
if row is None:
|
|
raise HTTPException(status_code=404, detail="Run not found")
|
|
if row["plan_data"] is None:
|
|
return Response(status_code=204)
|
|
data = json.loads(row["plan_data"]) if isinstance(row["plan_data"], str) else row["plan_data"]
|
|
return PlanOutput(**data)
|