Skip to content

Briefing Endpoints

API endpoints and server actions specific to the Briefing Progressivo 4-phase flow.

All briefing mutations use Server Actions defined in src/actions/briefing.ts. Each action:

  • Is marked with 'use server'
  • Uses requireActionAuth() for authentication
  • Returns a BriefingFlowState object (or an extended variant)
ActionSignaturePurpose
updateDiagnosis(sessionId, fields) → BriefingFlowStateUpdate diagnosis fields (situation, area, tema, tese). Advances from Phase 0 → Phase 1 if needed.
chooseSituation(sessionId, situation) → { state, phase2Blocks }Set user situation. Derives delivery mode and generates Phase 2 blocks.
addAdditionalContext(sessionId, text) → BriefingFlowStateStore free-text additional context in briefing state.

Situation → Delivery Mode mapping:

SituationDelivery ModeDescription
pesquisandosinteseUser is researching — gets a concise synthesis
avaliandoparecerUser is evaluating — gets a formal legal opinion
atuandoestrategiaUser is acting — gets a strategic plan
estudandomapaUser is studying — gets a conceptual map
ActionSignaturePurpose
evaluatePrecedent(sessionId, processoId, evaluation) → BriefingFlowStateRate a precedent as 'useful' or 'not_useful'. Advances to Phase 2 if needed.
ActionSignaturePurpose
advanceToPhase3(sessionId) → { state, phase3Blocks }Generate risk blocks (risk_balance + chart) from existing case analysis.
resolveRisk(sessionId, riskId) → BriefingFlowStateMark a risk as handled. Updates the risk_balance block in the database.
ActionSignaturePurpose
generateDelivery(sessionId) → { state, phase4Blocks }Generate delivery blocks based on the selected delivery mode. Requires deliveryMode to be set.
choosePath(sessionId, pathId) → BriefingFlowStateSet chosen strategic path in the estrategia delivery block. Generates next steps.
setFaseProcessual(sessionId, fase) → BriefingFlowStateUpdate faseProcessual field in the estrategia delivery block.
ActionSignaturePurpose
finalizeSession(sessionId) → BriefingFlowStateMark session as finalized. Updates exit_card block to selected: 'concluir'.
handleExitAction(sessionId, action) → { state, action }Handle exit card selection. If action === 'concluir', sets finalized = true.

Generate and download a PDF document for a briefing session.

Source: src/app/api/export/pdf/[sessionId]/route.ts

Auth: auth() session check. Bypassed when ENABLE_DEV_AUTH=true.

Path parameters: sessionId: string

Response 200:

HeaderValue
Content-Typeapplication/pdf
Content-Dispositionattachment; filename="briefing-{sessionId.slice(0,8)}.pdf"

Body: raw PDF bytes generated by generateBriefingPDF() from src/lib/pdf/generator.ts.

Error responses:

  • 401{ error: 'Unauthorized' }
  • 404{ error: 'Session not found' } (no blocks exist for the sessionId)

PDF generation details:

  • Uses jsPDF for PDF creation
  • Extracts blocks by type from the session database
  • Manual Y-position tracking with checkPage() for page overflow
  • Text wrapping via doc.splitTextToSize(text, maxWidth)
  • Output: new Uint8Array(doc.output('arraybuffer'))

These endpoints exist in Juca but are being migrated to Valter. They will be removed in v0.4 after migration is complete:

GroupPathEndpointsMigration Target
Analyzer/api/analyzer/*8Valter /v1/factual/*, /v1/retrieve
Chat/api/chat/*6Valter LLM pipeline
KG/api/kg/*14Valter /v1/graph/*
Reasoning/api/reasoning/*4Valter IRAC extraction
Search/api/search/*2Valter /v1/retrieve
Comparator/api/comparator/*2Valter multi-model comparison