Files
breakpilot-compliance/admin-compliance/lib/sdk/advisor/contract.ts
T
Benjamin Admin f9b7ba2424 feat(advisor): v3 Clarity Gate — Case model + clarify/answer contract, [n] citations
Builds the FE against the SDK<->FE Clarity-Gate contract (board 2026-07-01 /
advisor-clarity-gate-contract). The advisor is now a CASE, not a chat:
- Request {question, context?}; response {mode: clarify|answer, clarity, general_answer,
  answer, evidence, citations, visual_evidence, footnotes}.
- clarify mode: short L1 general answer (marked "allgemeine Definition, ohne Rechtsquelle")
  + domain context chips; picking a chip re-runs the case scoped (-> answer).
- answer mode: markdown answer with clickable [n] citation markers coupled to evidence
  cards (highlight + scroll), evidence grouped by document family, visual_evidence
  (visual_type), footnotes, honest summary counts (no trust score).
- FE never parses the answer for structure — only the deliberate [n] markers, mapped via
  citations[]. New: contract.ts, useAdvisorCase, useCitationHighlight, ClarifyView,
  EvidenceUnitCard, VisualEvidencePane, CaseView. Removed the v2 stream/chat components.

NOT deployed: FE shape-switch (JSON modes) must deploy TOGETHER with the SDK endpoint
delivering the contract (board deploy-coupling). Proxy/route.ts unchanged (SDK-owned).
tsc clean, 16 vitest (incl. clarify+answer fixtures), check-loc 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-01 11:31:28 +02:00

77 lines
2.0 KiB
TypeScript

// FE-facing contract for the Compliance Advisor "Case" (Clarity Gate).
// Matches the SDK<->FE contract (board 2026-07-01 / memory advisor-clarity-gate-contract).
// The FE renders ONLY these structured fields; it never extracts structure from the answer text.
// The only exception is rendering the deliberate [n] citation markers, mapped via `citations`.
export interface SuggestedContext {
id: string // e.g. "datenschutz"
label: string // e.g. "Datenschutz"
}
export interface ClarityInfo {
is_underspecified: boolean
concentration: number
suggested_contexts?: SuggestedContext[] // clarify mode
dominant_context?: string // answer mode
}
/** A retrieved evidence unit. (`evidence[]` item shape — confirm with SDK; see board rückfrage.) */
export interface EvidenceUnit {
evidence_id: string
document: string
section?: string
paragraph?: string
snippet?: string
url?: string
}
/** Numbered [n] <-> evidence coupling, produced by the SDK (not parsed from the answer). */
export interface Citation {
citation_id: string
evidence_id: string
document: string
section?: string | null
paragraph?: string | null
footnote?: string | null
figure?: string | null
}
/** C8 / visual evidence — `visual_type` generalizes beyond figures (flowchart/bpmn/state_machine/...). */
export interface VisualEvidence {
visual_id: string
visual_type: string
caption?: string
document: string
context?: string
image_ref?: string
vision_summary?: string
}
export interface Footnote {
footnote_id?: string
ref?: string
document?: string
section?: string
text?: string
}
export type AdvisorMode = 'clarify' | 'answer'
export interface AdvisorResponse {
mode: AdvisorMode
question: string
clarity: ClarityInfo
general_answer?: string | null // L1 (clarify mode)
answer?: string | null // L2 (answer mode)
scoped_query?: string | null
evidence: EvidenceUnit[]
citations: Citation[]
visual_evidence: VisualEvidence[]
footnotes: Footnote[]
}
export interface AdvisorRequest {
question: string
context?: string | null
}