'use client' import React, { useState } from 'react' import { useAgentAnalysis } from './_hooks/useAgentAnalysis' import { AnalysisResult } from './_components/AnalysisResult' import { AnalysisHistory } from './_components/AnalysisHistory' import { FollowUpQuestions } from './_components/FollowUpQuestions' import { ScanResult } from './_components/ScanResult' type AnalysisMode = 'pre_launch' | 'post_launch' type AnalysisTab = 'quick' | 'scan' const MODES: { id: AnalysisMode; label: string; desc: string; icon: string }[] = [ { id: 'pre_launch', label: 'Internes Dokument', desc: 'Vor Veroeffentlichung pruefen', icon: '📋' }, { id: 'post_launch', label: 'Live-Website', desc: 'Bereits online analysieren', icon: '🌐' }, ] const TABS: { id: AnalysisTab; label: string; info: string }[] = [ { id: 'quick', label: 'Schnellanalyse', info: 'Analysiert nur die eingegebene URL. Fuer einen umfassenden Check nutzen Sie den Website-Scan.' }, { id: 'scan', label: 'Website-Scan', info: 'Scannt automatisch 5-10 Unterseiten (Startseite, Datenschutz, Impressum, AGB, Cookies) und gleicht erkannte Dienste mit der Datenschutzerklaerung ab.' }, ] export default function AgentPage() { const [url, setUrl] = useState('') const [mode, setMode] = useState('post_launch') const [tab, setTab] = useState('quick') const [scanLoading, setScanLoading] = useState(false) const [scanError, setScanError] = useState(null) const [scanData, setScanData] = useState(null) const [scanHistory, setScanHistory] = useState([]) const { analyze, answerFollowUp, loading, error, result, history } = useAgentAnalysis() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!url.trim()) return if (tab === 'quick') { analyze(url.trim(), mode) } else { setScanLoading(true) setScanError(null) setScanData(null) try { const res = await fetch('/api/sdk/v1/agent/scan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url.trim(), mode }), }) if (!res.ok) throw new Error(`Scan fehlgeschlagen: ${res.status}`) const data = await res.json() setScanData(data) setScanHistory(prev => [{ url: url.trim(), ...data, scanned_at: new Date().toISOString() }, ...prev].slice(0, 20)) } catch (e) { setScanError(e instanceof Error ? e.message : 'Unbekannter Fehler') } finally { setScanLoading(false) } } } const isLoading = tab === 'quick' ? loading : scanLoading const currentError = tab === 'quick' ? error : scanError const currentTab = TABS.find(t => t.id === tab)! return (

Compliance Agent

Analysiere Dokumente und Webseiten auf DSGVO-Konformitaet.

{/* Mode Selection */}
{MODES.map(m => ( ))}
{/* Tab Selection + Info */}
{TABS.map(t => ( ))}

{currentTab.info}

{/* URL Input */}
setUrl(e.target.value)} placeholder={tab === 'scan' ? 'https://www.example.com/' : 'https://example.com/datenschutz'} className="flex-1 px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent text-sm" disabled={isLoading} required />
{/* Error */} {currentError && (
{currentError}
)} {/* Quick Analysis Result */} {tab === 'quick' && result && (
{result.follow_up_questions.length > 0 && (
)}
)} {/* Scan Result */} {tab === 'scan' && scanData && (
)} {/* History */} {tab === 'quick' && ( { setUrl(r.url); analyze(r.url, mode) }} /> )} {tab === 'scan' && scanHistory.length > 0 && (

Letzte Scans

{scanHistory.map((item, i) => ( ))}
)}
) }