S6-1: /api/exam analyse endpoint — structure → ghost-region suggestions (async)

The canvas "Auto-detect" path (spec R3.1/R3.3/R3.5/R5.4). Async because extraction on
an image-only paper takes ~15-60s (Card-12 grounding):

  POST /api/exam/templates/{id}/analyse -> {job_id}   (BackgroundTasks)
  GET  /api/exam/jobs/{id}              -> {status, counts, suggestions}

suggestions = questions + response_areas + boundaries, each source:'ai',confirmed:false
with confidence + page-fraction bounds + deterministic uuids — rendered as ghosts the
teacher confirms/dismisses; never overwrites manual shapes; persistence stays PUT /templates/{id}.

Access is as-the-user (E1/E2): the template is read under RLS (unseen -> 404, IDOR-safe)
and a job is only visible to the user who started it.

The heavy pipeline stays OUT of the API behind modules/services/exam_extract.py — an HTTP
client (aiohttp) to the exam-structure extraction service (the docling-exam-spike pipeline,
GPU-attached, deterministic), mirroring how the app calls Docling Serve/Ollama. Configured
via EXAM_EXTRACT_URL; unset -> the job fails cleanly as 'extraction unavailable'.

Follow-on (S6-1b): stand up that extraction service (POST /api/extract: source -> suggestions)
wrapping scripts/structure.py + scripts/analyse.py.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
CC Worker
2026-07-02 19:45:26 +00:00
co-authored by Claude Opus 4.8
parent e269e67f27
commit c0458f5528
4 changed files with 178 additions and 0 deletions
+4
View File
@@ -181,3 +181,7 @@ GOOGLE_CLIENT_SECRETS_FILE=
# Node Filesystem (for document storage)
# =============================================================================
NODE_FILESYSTEM_PATH=/tmp/cc-nodes
# Exam-structure extraction service (docling-exam-spike pipeline) for /api/exam analyse (S6-1)
EXAM_EXTRACT_URL=
EXAM_EXTRACT_TIMEOUT=180