b7f9099ad9
Third tab "Cookie-Test" in Compliance Agent: - Phase A: Before consent (tracking without permission) - Phase B: After rejection (CRITICAL if tracking persists) - Phase C: After acceptance (undocumented services) - CMP badge (Didomi, OneTrust, etc.) - Violation cards with severity badges and legal references Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
204 lines
9.1 KiB
TypeScript
204 lines
9.1 KiB
TypeScript
'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'
|
|
import { ConsentTestResult } from './_components/ConsentTestResult'
|
|
|
|
type AnalysisMode = 'pre_launch' | 'post_launch'
|
|
type AnalysisTab = 'quick' | 'scan' | 'consent'
|
|
|
|
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 und gleicht erkannte Dienste mit der Datenschutzerklaerung ab.' },
|
|
{ id: 'consent', label: 'Cookie-Test', info: 'Testet mit echtem Browser was VOR und NACH Cookie-Einwilligung geladen wird. Erkennt Verstoesse gegen §25 TDDDG.' },
|
|
]
|
|
|
|
export default function AgentPage() {
|
|
const [url, setUrl] = useState('')
|
|
const [mode, setMode] = useState<AnalysisMode>('post_launch')
|
|
const [tab, setTab] = useState<AnalysisTab>('quick')
|
|
const [scanLoading, setScanLoading] = useState(false)
|
|
const [scanError, setScanError] = useState<string | null>(null)
|
|
const [scanData, setScanData] = useState<any>(null)
|
|
const [scanHistory, setScanHistory] = useState<any[]>([])
|
|
const [consentLoading, setConsentLoading] = useState(false)
|
|
const [consentError, setConsentError] = useState<string | null>(null)
|
|
const [consentData, setConsentData] = useState<any>(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 if (tab === 'scan') {
|
|
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)
|
|
}
|
|
} else {
|
|
setConsentLoading(true)
|
|
setConsentError(null)
|
|
setConsentData(null)
|
|
try {
|
|
const res = await fetch('/api/sdk/v1/agent/consent-test', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ url: url.trim() }),
|
|
})
|
|
if (!res.ok) throw new Error(`Cookie-Test fehlgeschlagen: ${res.status}`)
|
|
setConsentData(await res.json())
|
|
} catch (e) {
|
|
setConsentError(e instanceof Error ? e.message : 'Unbekannter Fehler')
|
|
} finally {
|
|
setConsentLoading(false)
|
|
}
|
|
}
|
|
}
|
|
|
|
const isLoading = tab === 'quick' ? loading : tab === 'scan' ? scanLoading : consentLoading
|
|
const currentError = tab === 'quick' ? error : tab === 'scan' ? scanError : consentError
|
|
const currentTab = TABS.find(t => t.id === tab)!
|
|
|
|
return (
|
|
<div className="space-y-6 max-w-4xl">
|
|
<div>
|
|
<h1 className="text-2xl font-bold text-gray-900">Compliance Agent</h1>
|
|
<p className="text-gray-500 mt-1">Analysiere Dokumente und Webseiten auf DSGVO-Konformitaet.</p>
|
|
</div>
|
|
|
|
{/* Mode Selection */}
|
|
<div className="grid grid-cols-2 gap-3">
|
|
{MODES.map(m => (
|
|
<button key={m.id} onClick={() => setMode(m.id)}
|
|
className={`p-3 rounded-xl border-2 text-left transition-all ${
|
|
mode === m.id ? 'border-purple-500 bg-purple-50' : 'border-gray-200 hover:border-gray-300'}`}>
|
|
<div className="flex items-center gap-3">
|
|
<span className="text-xl">{m.icon}</span>
|
|
<div>
|
|
<p className={`text-sm font-semibold ${mode === m.id ? 'text-purple-900' : 'text-gray-900'}`}>{m.label}</p>
|
|
<p className="text-xs text-gray-500">{m.desc}</p>
|
|
</div>
|
|
</div>
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
{/* Tab Selection + Info */}
|
|
<div>
|
|
<div className="flex border-b border-gray-200">
|
|
{TABS.map(t => (
|
|
<button key={t.id} onClick={() => setTab(t.id)}
|
|
className={`px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ${
|
|
tab === t.id
|
|
? 'border-purple-500 text-purple-700'
|
|
: 'border-transparent text-gray-500 hover:text-gray-700'}`}>
|
|
{t.label}
|
|
</button>
|
|
))}
|
|
</div>
|
|
<p className="text-xs text-gray-400 mt-2 px-1">{currentTab.info}</p>
|
|
</div>
|
|
|
|
{/* URL Input */}
|
|
<form onSubmit={handleSubmit} className="flex gap-3">
|
|
<input type="url" value={url} onChange={e => setUrl(e.target.value)}
|
|
placeholder={tab === 'consent' ? 'https://www.example.com/' : 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 />
|
|
<button type="submit" disabled={isLoading || !url.trim()}
|
|
className="px-6 py-3 bg-purple-600 text-white rounded-lg hover:bg-purple-700 disabled:opacity-50 transition-colors flex items-center gap-2 text-sm font-medium">
|
|
{isLoading ? (
|
|
<><svg className="animate-spin w-4 h-4" fill="none" viewBox="0 0 24 24">
|
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
|
</svg>{tab === 'consent' ? 'Teste Cookies...' : tab === 'scan' ? 'Scanne...' : 'Analysiere...'}</>
|
|
) : tab === 'consent' ? 'Cookie-Test starten' : tab === 'scan' ? 'Website scannen' : 'Analysieren'}
|
|
</button>
|
|
</form>
|
|
|
|
{/* Error */}
|
|
{currentError && (
|
|
<div className="bg-red-50 border border-red-200 rounded-lg p-4 text-sm text-red-700">{currentError}</div>
|
|
)}
|
|
|
|
{/* Quick Analysis Result */}
|
|
{tab === 'quick' && result && (
|
|
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm space-y-6">
|
|
<AnalysisResult result={result} />
|
|
{result.follow_up_questions.length > 0 && (
|
|
<div className="border-t pt-4">
|
|
<FollowUpQuestions questions={result.follow_up_questions} answers={result.follow_up_answers} onAnswer={answerFollowUp} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Scan Result */}
|
|
{tab === 'scan' && scanData && (
|
|
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
|
<ScanResult data={scanData} />
|
|
</div>
|
|
)}
|
|
|
|
{/* Consent Test Result */}
|
|
{tab === 'consent' && consentData && (
|
|
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
|
<ConsentTestResult data={consentData} />
|
|
</div>
|
|
)}
|
|
|
|
{/* History */}
|
|
{tab === 'quick' && (
|
|
<AnalysisHistory history={history} onSelect={r => { setUrl(r.url); analyze(r.url, mode) }} />
|
|
)}
|
|
{tab === 'scan' && scanHistory.length > 0 && (
|
|
<div>
|
|
<h3 className="text-sm font-medium text-gray-700 mb-3">Letzte Scans</h3>
|
|
<div className="space-y-2">
|
|
{scanHistory.map((item, i) => (
|
|
<button key={i} onClick={() => setUrl(item.url)}
|
|
className="w-full text-left p-3 bg-white border border-gray-200 rounded-lg hover:border-purple-300 hover:bg-purple-50 transition-colors">
|
|
<div className="flex items-center gap-3">
|
|
<span className="text-xs font-medium text-gray-500 w-8">{item.pages_scanned}p</span>
|
|
<span className="text-sm text-gray-700 truncate flex-1">{item.url}</span>
|
|
<span className={`text-xs px-2 py-0.5 rounded ${item.findings?.length > 0 ? 'bg-red-100 text-red-700' : 'bg-green-100 text-green-700'}`}>
|
|
{item.findings?.length || 0} Findings
|
|
</span>
|
|
<span className="text-xs text-gray-400">
|
|
{new Date(item.scanned_at).toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })}
|
|
</span>
|
|
</div>
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|