From 8585f7a62db9c17c6daa00eb406674675be01e71 Mon Sep 17 00:00:00 2001 From: admin-valentin Date: Sat, 1 Aug 2026 12:32:07 +0000 Subject: [PATCH] feat(CC-054): add Legislation page (vector search + AnythingLLM AI agent) --- src/app/dashboard/legislation/page.tsx | 182 +++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/app/dashboard/legislation/page.tsx diff --git a/src/app/dashboard/legislation/page.tsx b/src/app/dashboard/legislation/page.tsx new file mode 100644 index 0000000..6a223d8 --- /dev/null +++ b/src/app/dashboard/legislation/page.tsx @@ -0,0 +1,182 @@ +'use client'; +import { useState } from 'react'; +import { useSession } from '../../../lib/session'; +import { apiFetch } from '../../../lib/api'; + +interface LegResult { + country?: string; + section?: string; + text?: string; + source_id?: string; + [key: string]: unknown; +} + +interface ApiSearchResponse { + scenario?: string; + country_filter?: string; + results?: LegResult[]; +} + +type Mode = 'search' | 'ask'; + +export default function LegislationPage() { + const { session } = useSession(); + const [mode, setMode] = useState('ask'); + const [input, setInput] = useState(''); + const [country, setCountry] = useState('DE'); + const [results, setResults] = useState([]); + const [aiAnswer, setAiAnswer] = useState(null); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const [searched, setSearched] = useState(false); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + if (!input.trim() || !session) return; + setLoading(true); setError(null); setResults([]); setAiAnswer(null); + + try { + const headers = { + Authorization: `Bearer ${session.access_token}`, + 'x-tenant-id': session.tenant_id, + 'Content-Type': 'application/json', + }; + + if (mode === 'search') { + const data: ApiSearchResponse = await apiFetch('/v1/external/legislation/search', { + method: 'POST', headers, + body: JSON.stringify({ scenario: input.trim(), country, topK: 10 }), + }); + setResults(data.results ?? []); + } else { + const data = await apiFetch('/v1/external/legislation/ask', { + method: 'POST', headers, + body: JSON.stringify({ + message: `${input.trim()} (context juridic: ${country})`, + sessionId: 'ceo-legislation-' + Date.now(), + }), + }) as Record; + const text = (data?.textResponse ?? data?.response ?? data?.message ?? '') as string; + setAiAnswer(text); + } + setSearched(true); + } catch { + setError(mode === 'ask' + ? 'Agentul de legislație nu e disponibil momentan. Încearcă modul Căutare.' + : 'Serviciul de căutare nu e disponibil momentan.' + ); + } finally { + setLoading(false); + } + } + + return ( +
+
+

Căutare Legislație

+

+ Corpus DE · RO · EU — căutare vectorială sau răspuns AI prin agent AnythingLLM +

+
+ + {/* Mode toggle */} +
+ {(['ask', 'search'] as Mode[]).map((m) => ( + + ))} +
+ +
+