5a513181cc
Completes the advisor stack (FE + orchestration; /retrieve is SDK/RAG-owned). The route
now returns the FE contract instead of a text stream:
- retrieveFull() calls /retrieve with {query, context}; consumes clarity/evidence/
visual_evidence/footnotes (exact shape per board 2026-07-01 12:25).
- mode-routing (resolveMode): clarify unless a context was chosen and /retrieve's
clarity.mode says so. clarify -> L1 general answer (completeAdvisorAnswer, ungrounded,
no sources). answer -> L2 answer over numbered evidence with [n] markers.
- citations generated here ([n] -> nth evidence unit); footnotes remapped; evidence /
visual_evidence passed through.
- advisor-llm: non-streaming completeAdvisorAnswer(). Pure mappings in retrieve-mapping.ts
(+ tests). Removed the dead v2 evidence.ts/evidence-adapter (RegulationRef moved to
regulation-display). controls-augmentation kept (tested; re-integrable later).
NOT deployed: joint deploy with the SDK /retrieve endpoint (deploy-coupling). tsc clean,
25 vitest (mapping/clarify/answer/markdown/registry/rag), check-loc 0.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
resolveMode,
|
|
mapClarity,
|
|
mapFootnotes,
|
|
buildCitations,
|
|
numberedEvidenceForPrompt,
|
|
} from '../advisor/retrieve-mapping'
|
|
import type { EvidenceUnit } from '../advisor/contract'
|
|
|
|
describe('resolveMode', () => {
|
|
it('a chosen context always forces answer', () => expect(resolveMode('clarify', true)).toBe('answer'))
|
|
it('clarify + no context -> clarify', () => expect(resolveMode('clarify', false)).toBe('clarify'))
|
|
it('answer -> answer', () => expect(resolveMode('answer', false)).toBe('answer'))
|
|
it('unknown/undefined -> answer', () => expect(resolveMode(undefined, false)).toBe('answer'))
|
|
})
|
|
|
|
describe('mapClarity', () => {
|
|
it('clarify maps candidate_contexts -> suggested_contexts', () => {
|
|
const c = mapClarity(
|
|
{ mode: 'clarify', concentration: 0.3, candidate_contexts: [{ id: 'ds', label: 'Datenschutz', hits: 5 }] },
|
|
'clarify',
|
|
)
|
|
expect(c.is_underspecified).toBe(true)
|
|
expect(c.suggested_contexts).toEqual([{ id: 'ds', label: 'Datenschutz' }])
|
|
})
|
|
it('answer keeps dominant_context, drops suggestions', () => {
|
|
const c = mapClarity({ mode: 'answer', concentration: 0.88, dominant_context: 'ds' }, 'answer')
|
|
expect(c.is_underspecified).toBe(false)
|
|
expect(c.dominant_context).toBe('ds')
|
|
expect(c.suggested_contexts).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
const ev: EvidenceUnit[] = [
|
|
{ evidence_id: 'e1', document: 'DSGVO', section: 'Art. 30', paragraph: 'Abs. 1', snippet: 'x' },
|
|
{ evidence_id: 'e2', document: 'BDSG', section: '§ 38' },
|
|
]
|
|
|
|
describe('buildCitations', () => {
|
|
it('numbers citations 1..n mapped to evidence', () => {
|
|
const cs = buildCitations(ev)
|
|
expect(cs).toHaveLength(2)
|
|
expect(cs[0]).toMatchObject({ citation_id: 'c1', number: 1, evidence_id: 'e1' })
|
|
expect(cs[1].number).toBe(2)
|
|
})
|
|
})
|
|
|
|
describe('numberedEvidenceForPrompt', () => {
|
|
it('prefixes each unit with [n] + its location', () => {
|
|
const s = numberedEvidenceForPrompt(ev)
|
|
expect(s).toContain('[1] DSGVO Art. 30 Abs. 1')
|
|
expect(s).toContain('[2] BDSG § 38')
|
|
})
|
|
})
|
|
|
|
describe('mapFootnotes', () => {
|
|
it('remaps a /retrieve footnote to the contract footnote', () => {
|
|
const fns = mapFootnotes([
|
|
{ id: 'f1', number: 17, regulation_short: 'EDPB WP248', section: 'Kap III', text: 't' },
|
|
])
|
|
expect(fns[0]).toMatchObject({
|
|
footnote_id: 'f1',
|
|
ref: 'Fußnote 17',
|
|
document: 'EDPB WP248',
|
|
section: 'Kap III',
|
|
text: 't',
|
|
})
|
|
})
|
|
})
|