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>
This commit is contained in:
Benjamin Admin
2026-07-01 11:31:28 +02:00
parent 591cae5ebc
commit f9b7ba2424
20 changed files with 671 additions and 453 deletions
@@ -1,7 +1,7 @@
'use client'
import { FileText, Hash, Image as ImageIcon, Library } from 'lucide-react'
import type { AdvisorEvidenceMeta } from '@/lib/sdk/advisor/evidence'
import type { AdvisorResponse } from '@/lib/sdk/advisor/contract'
import { resolveRegulation } from '@/lib/sdk/advisor/regulation-display'
function Card({
@@ -31,12 +31,13 @@ function Card({
}
/**
* "Antwort basiert auf" — honest, meaningful counts (not bare badges). Regelwerke = distinct
* document FAMILIES (via resolveRegulation), so multi-part works like the DSK SDM count once.
* No fabricated trust score — a real trust signal needs a defined basis (bindingness/coverage).
* "Antwort basiert auf" — objective counts only (no fabricated trust score). Regelwerke = distinct
* document families. Leitlinien deliberately omitted until bindingness exists in the Legal-KG.
*/
export function EvidenceSummary({ meta }: { meta: AdvisorEvidenceMeta }) {
const families = new Set(meta.sources.map((s) => resolveRegulation(s.regulation).familyKey)).size
export function EvidenceSummary({ response }: { response: AdvisorResponse }) {
const families = new Set(
response.evidence.map((e) => resolveRegulation({ code: e.document, short: e.document }).familyKey),
).size
const cls = 'h-4 w-4'
return (
<div>
@@ -45,9 +46,9 @@ export function EvidenceSummary({ meta }: { meta: AdvisorEvidenceMeta }) {
</div>
<div className="grid grid-cols-2 gap-1.5">
<Card icon={<Library className={cls} />} value={families} label="Regelwerke" />
<Card icon={<FileText className={cls} />} value={meta.sources.length} label="Evidence Units" />
<Card icon={<ImageIcon className={cls} />} value={meta.figures.length} label="Abbildungen" dim={meta.figures.length === 0} />
<Card icon={<Hash className={cls} />} value={meta.footnotes.length} label="Fußnoten" dim={meta.footnotes.length === 0} />
<Card icon={<FileText className={cls} />} value={response.evidence.length} label="Evidence Units" />
<Card icon={<ImageIcon className={cls} />} value={response.visual_evidence.length} label="Diagramme" dim={response.visual_evidence.length === 0} />
<Card icon={<Hash className={cls} />} value={response.footnotes.length} label="Fußnoten" dim={response.footnotes.length === 0} />
</div>
</div>
)