Files
breakpilot-compliance/admin-compliance/app/(sdk)/sdk/rag/page.tsx
Benjamin Boenisch 4435e7ea0a Initial commit: breakpilot-compliance - Compliance SDK Platform
Services: Admin-Compliance, Backend-Compliance,
AI-Compliance-SDK, Consent-SDK, Developer-Portal,
PCA-Platform, DSMS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 23:47:28 +01:00

277 lines
11 KiB
TypeScript

'use client'
import React, { useState } from 'react'
import { useSDK } from '@/lib/sdk'
// =============================================================================
// TYPES
// =============================================================================
interface ChatMessage {
id: string
role: 'user' | 'assistant'
content: string
sources?: Source[]
timestamp: Date
}
interface Source {
title: string
reference: string
relevance: number
}
// =============================================================================
// MOCK DATA
// =============================================================================
const mockHistory: ChatMessage[] = [
{
id: 'msg-1',
role: 'user',
content: 'Wann ist eine Datenschutz-Folgenabschaetzung nach DSGVO erforderlich?',
timestamp: new Date('2024-01-22T10:30:00'),
},
{
id: 'msg-2',
role: 'assistant',
content: `Nach Art. 35 DSGVO ist eine Datenschutz-Folgenabschaetzung (DSFA) erforderlich, wenn eine Verarbeitung voraussichtlich ein hohes Risiko fuer die Rechte und Freiheiten natuerlicher Personen zur Folge hat.
Dies ist insbesondere der Fall bei:
1. **Systematischer und umfassender Bewertung** persoenlicher Aspekte natuerlicher Personen, einschliesslich Profiling, auf deren Grundlage Entscheidungen getroffen werden
2. **Umfangreicher Verarbeitung besonderer Kategorien** personenbezogener Daten (Art. 9) oder von Daten ueber strafrechtliche Verurteilungen (Art. 10)
3. **Systematischer umfangreicher Ueberwachung** oeffentlich zugaenglicher Bereiche
Die Aufsichtsbehoerden haben zudem sogenannte "Blacklists" veroeffentlicht, die weitere Verarbeitungstaetigkeiten benennen, fuer die eine DSFA durchzufuehren ist.`,
sources: [
{ title: 'Art. 35 DSGVO', reference: 'DSGVO Art. 35 Abs. 1, 3', relevance: 0.95 },
{ title: 'Erwaegungsgrund 91', reference: 'DSGVO EG 91', relevance: 0.85 },
{ title: 'DSFA-Blacklist DSK', reference: 'DSK Beschluss 2018', relevance: 0.75 },
],
timestamp: new Date('2024-01-22T10:30:05'),
},
]
const suggestedQuestions = [
'Was sind die Rechte der Betroffenen nach DSGVO?',
'Wie lange betraegt die Meldefrist bei einer Datenpanne?',
'Welche Anforderungen stellt der AI Act an Hochrisiko-KI?',
'Wann brauche ich einen Auftragsverarbeitungsvertrag?',
'Was muss in einer Datenschutzerklaerung stehen?',
]
// =============================================================================
// COMPONENTS
// =============================================================================
function MessageBubble({ message }: { message: ChatMessage }) {
const isUser = message.role === 'user'
return (
<div className={`flex ${isUser ? 'justify-end' : 'justify-start'}`}>
<div className={`max-w-3xl ${isUser ? 'order-2' : 'order-1'}`}>
<div
className={`rounded-2xl px-4 py-3 ${
isUser
? 'bg-purple-600 text-white'
: 'bg-white border border-gray-200'
}`}
>
<div className={`text-sm whitespace-pre-wrap ${isUser ? 'text-white' : 'text-gray-700'}`}>
{message.content}
</div>
</div>
{message.sources && message.sources.length > 0 && (
<div className="mt-2 space-y-1">
<p className="text-xs text-gray-500 ml-1">Quellen:</p>
<div className="flex flex-wrap gap-2">
{message.sources.map((source, i) => (
<span
key={i}
className="inline-flex items-center gap-1 px-2 py-1 bg-blue-50 text-blue-700 text-xs rounded-lg hover:bg-blue-100 cursor-pointer"
>
<svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
{source.title}
</span>
))}
</div>
</div>
)}
<p className={`text-xs text-gray-400 mt-1 ${isUser ? 'text-right' : 'text-left'}`}>
{message.timestamp.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })}
</p>
</div>
</div>
)
}
// =============================================================================
// MAIN PAGE
// =============================================================================
export default function RAGPage() {
const { state } = useSDK()
const [messages, setMessages] = useState<ChatMessage[]>(mockHistory)
const [inputValue, setInputValue] = useState('')
const [isLoading, setIsLoading] = useState(false)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
if (!inputValue.trim() || isLoading) return
const userMessage: ChatMessage = {
id: `msg-${Date.now()}`,
role: 'user',
content: inputValue,
timestamp: new Date(),
}
setMessages(prev => [...prev, userMessage])
setInputValue('')
setIsLoading(true)
// Simulate AI response
setTimeout(() => {
const assistantMessage: ChatMessage = {
id: `msg-${Date.now() + 1}`,
role: 'assistant',
content: 'Dies ist eine Platzhalter-Antwort. In der produktiven Version wird hier die Antwort des Legal RAG Systems angezeigt, das Ihre Frage auf Basis der integrierten Rechtsdokumente beantwortet.',
sources: [
{ title: 'DSGVO', reference: 'Art. 5', relevance: 0.9 },
{ title: 'AI Act', reference: 'Art. 6', relevance: 0.8 },
],
timestamp: new Date(),
}
setMessages(prev => [...prev, assistantMessage])
setIsLoading(false)
}, 1500)
}
const handleSuggestedQuestion = (question: string) => {
setInputValue(question)
}
return (
<div className="flex flex-col h-[calc(100vh-200px)]">
{/* Header */}
<div className="flex-shrink-0 mb-6">
<h1 className="text-2xl font-bold text-gray-900">Legal RAG</h1>
<p className="mt-1 text-gray-500">
Stellen Sie rechtliche Fragen zu DSGVO, AI Act und anderen Regelwerken
</p>
</div>
{/* Info Box */}
<div className="flex-shrink-0 bg-blue-50 border border-blue-200 rounded-xl p-4 mb-6">
<div className="flex items-start gap-3">
<svg className="w-5 h-5 text-blue-600 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<div>
<h4 className="font-medium text-blue-800">KI-gestuetzte Rechtsauskunft</h4>
<p className="text-sm text-blue-600 mt-1">
Das System durchsucht DSGVO, AI Act, BDSG und weitere Regelwerke, um Ihre Fragen zu beantworten.
Die Antworten ersetzen keine Rechtsberatung.
</p>
</div>
</div>
</div>
{/* Chat Area */}
<div className="flex-1 overflow-y-auto bg-gray-50 rounded-xl border border-gray-200 p-6 space-y-6">
{messages.length === 0 ? (
<div className="text-center py-12">
<div className="w-16 h-16 mx-auto bg-purple-100 rounded-full flex items-center justify-center mb-4">
<svg className="w-8 h-8 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z" />
</svg>
</div>
<h3 className="text-lg font-semibold text-gray-900">Stellen Sie eine Frage</h3>
<p className="mt-2 text-gray-500 max-w-md mx-auto">
Fragen Sie zu DSGVO, AI Act, Datenschutz oder Compliance-Themen.
</p>
</div>
) : (
messages.map(message => (
<MessageBubble key={message.id} message={message} />
))
)}
{isLoading && (
<div className="flex justify-start">
<div className="bg-white border border-gray-200 rounded-2xl px-4 py-3">
<div className="flex items-center gap-2">
<div className="w-2 h-2 bg-purple-600 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} />
<div className="w-2 h-2 bg-purple-600 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
<div className="w-2 h-2 bg-purple-600 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
</div>
</div>
</div>
)}
</div>
{/* Suggested Questions */}
{messages.length === 0 && (
<div className="flex-shrink-0 mt-4">
<p className="text-sm text-gray-500 mb-2">Vorgeschlagene Fragen:</p>
<div className="flex flex-wrap gap-2">
{suggestedQuestions.map((question, i) => (
<button
key={i}
onClick={() => handleSuggestedQuestion(question)}
className="px-3 py-2 text-sm bg-white border border-gray-200 rounded-lg hover:border-purple-300 hover:bg-purple-50 transition-colors"
>
{question}
</button>
))}
</div>
</div>
)}
{/* Input Area */}
<form onSubmit={handleSubmit} className="flex-shrink-0 mt-4">
<div className="flex items-end gap-4">
<div className="flex-1 relative">
<textarea
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
handleSubmit(e)
}
}}
placeholder="Stellen Sie eine rechtliche Frage..."
rows={2}
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-transparent resize-none"
/>
</div>
<button
type="submit"
disabled={!inputValue.trim() || isLoading}
className={`px-6 py-3 rounded-xl font-medium transition-colors ${
inputValue.trim() && !isLoading
? 'bg-purple-600 text-white hover:bg-purple-700'
: 'bg-gray-200 text-gray-400 cursor-not-allowed'
}`}
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />
</svg>
</button>
</div>
<p className="text-xs text-gray-400 mt-2">
Enter zum Senden, Shift+Enter fuer neue Zeile
</p>
</form>
</div>
)
}