'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; desc: string }[] = [ { id: 'quick', label: 'Schnellanalyse', desc: 'Einzelne Seite klassifizieren + bewerten' }, { id: 'scan', label: 'Website-Scan', desc: 'Mehrere Seiten scannen + Dienstleister abgleichen' }, ] 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 { 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 { // Step 1: Start async scan const startRes = await fetch('/api/sdk/v1/agent/scan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: url.trim(), mode }), }) if (!startRes.ok) throw new Error(`Scan konnte nicht gestartet werden: ${startRes.status}`) const { scan_id } = await startRes.json() if (!scan_id) throw new Error('Keine Scan-ID erhalten') // Step 2: Poll for results let attempts = 0 const maxAttempts = 120 // 10 min at 5s intervals while (attempts < maxAttempts) { await new Promise(r => setTimeout(r, 5000)) const pollRes = await fetch(`/api/sdk/v1/agent/scan?scan_id=${scan_id}`) if (!pollRes.ok) { attempts++; continue } const status = await pollRes.json() // Update progress message if (status.progress) { setScanError(null) // Show progress as temporary "error" (will be cleared when done) setScanData({ _progress: status.progress } as any) } if (status.status === 'completed' && status.result) { setScanData(status.result) break } if (status.status === 'failed') { throw new Error(status.error || 'Scan fehlgeschlagen') } attempts++ } if (attempts >= maxAttempts) throw new Error('Scan-Timeout (10 Minuten)') } 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 return (

Compliance Agent

Analysiere Dokumente und Webseiten auf DSGVO-Konformitaet.

{/* Mode Selection */}
{MODES.map(m => ( ))}
{/* Tab Selection */}
{TABS.map(t => ( ))}
{/* 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 (quick only) */} {tab === 'quick' && ( { setUrl(r.url); analyze(r.url, mode) }} /> )}
) }