feat: New tab structure — Discovery Scan, Doc-Check, Banner, Impressum
Removed Schnellanalyse tab. New 4-tab structure: 1. Website-Scan (Discovery): Finds legal documents + services, shows "Jetzt pruefen" buttons that navigate to specialized tabs with pre-filled URLs. 2. Dokumenten-Pruefung: DSI, AGB, Cookie, Widerruf checks (existing) 3. Banner-Check: Cookie banner 46-check deep verification (existing) 4. Impressum-Check (NEW): §5 TMG / §18 MStV with 16 checks, own tab with URL input, history, email report. Uses existing impressum_checks.py via doc-check endpoint. Tab cross-navigation: Scan → "Jetzt pruefen" → opens target tab with URL pre-filled via localStorage handoff. Removed: Mode selector (pre/post launch), Schnellanalyse, useAgentAnalysis hook import, AnalysisResult/FollowUpQuestions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,168 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
import { ChecklistView } from './ChecklistView'
|
||||||
|
|
||||||
|
interface CheckItem {
|
||||||
|
id: string; label: string; passed: boolean; severity: string
|
||||||
|
matched_text: string; level?: number; parent?: string | null
|
||||||
|
skipped?: boolean; hint?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ImpressumCheckTab() {
|
||||||
|
const [url, setUrl] = useState(() =>
|
||||||
|
typeof window !== 'undefined' ? localStorage.getItem('impressum-check-url') || '' : ''
|
||||||
|
)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [progress, setProgress] = useState('')
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [results, setResults] = useState<any>(() => {
|
||||||
|
if (typeof window === 'undefined') return null
|
||||||
|
try { const s = localStorage.getItem('impressum-check-results'); return s ? JSON.parse(s) : null } catch { return null }
|
||||||
|
})
|
||||||
|
const [history, setHistory] = useState<{ url: string; date: string; findings: number; pct: number; resultKey: string }[]>(() => {
|
||||||
|
if (typeof window === 'undefined') return []
|
||||||
|
try { return JSON.parse(localStorage.getItem('impressum-check-history') || '[]') } catch { return [] }
|
||||||
|
})
|
||||||
|
|
||||||
|
React.useEffect(() => { localStorage.setItem('impressum-check-url', url) }, [url])
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!url.trim()) return
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
setError(null)
|
||||||
|
setResults(null)
|
||||||
|
setProgress('Impressum wird geprueft...')
|
||||||
|
|
||||||
|
try {
|
||||||
|
const startRes = await fetch('/api/sdk/v1/agent/doc-check', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
entries: [{ doc_type: 'impressum', label: 'Impressum', url: url.trim() }],
|
||||||
|
recipient: 'dsb@breakpilot.local',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
if (!startRes.ok) throw new Error(`Fehler: ${startRes.status}`)
|
||||||
|
const { check_id } = await startRes.json()
|
||||||
|
if (!check_id) throw new Error('Keine Check-ID erhalten')
|
||||||
|
|
||||||
|
let attempts = 0
|
||||||
|
while (attempts < 120) {
|
||||||
|
await new Promise(r => setTimeout(r, 3000))
|
||||||
|
const pollRes = await fetch(`/api/sdk/v1/agent/doc-check?check_id=${check_id}`)
|
||||||
|
if (!pollRes.ok) { attempts++; continue }
|
||||||
|
const pollData = await pollRes.json()
|
||||||
|
if (pollData.progress) setProgress(pollData.progress)
|
||||||
|
if (pollData.status === 'completed' && pollData.result) {
|
||||||
|
setResults(pollData.result)
|
||||||
|
setProgress('')
|
||||||
|
localStorage.setItem('impressum-check-results', JSON.stringify(pollData.result))
|
||||||
|
const resultKey = `impressum-result-${Date.now()}`
|
||||||
|
try { localStorage.setItem(resultKey, JSON.stringify(pollData.result)) } catch {}
|
||||||
|
const total = pollData.result.total_findings || 0
|
||||||
|
const pct = pollData.result.results?.[0]?.completeness_pct || 0
|
||||||
|
const entry = { url: url.trim(), date: new Date().toISOString(), findings: total, pct, resultKey }
|
||||||
|
const updated = [entry, ...history].slice(0, 30)
|
||||||
|
setHistory(updated)
|
||||||
|
localStorage.setItem('impressum-check-history', JSON.stringify(updated))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (pollData.status === 'failed') throw new Error(pollData.error || 'Pruefung fehlgeschlagen')
|
||||||
|
attempts++
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : 'Unbekannter Fehler')
|
||||||
|
setProgress('')
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="bg-amber-50 border border-amber-200 rounded-lg p-4">
|
||||||
|
<h3 className="text-sm font-semibold text-amber-900">Impressum-Check (§5 TMG / §18 MStV)</h3>
|
||||||
|
<p className="text-xs text-amber-700 mt-1">
|
||||||
|
Prueft 16 Pflichtangaben: Anbietername, Anschrift, Kontaktdaten, Handelsregister,
|
||||||
|
USt-IdNr., Vertretungsberechtigte, V.i.S.d.P., Streitbeilegung.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className="flex gap-3">
|
||||||
|
<input type="url" value={url} onChange={e => setUrl(e.target.value)}
|
||||||
|
placeholder="https://www.example.com/impressum"
|
||||||
|
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={loading} required />
|
||||||
|
<button type="submit" disabled={loading || !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 whitespace-nowrap">
|
||||||
|
{loading ? (
|
||||||
|
<><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>Pruefe...</>
|
||||||
|
) : 'Impressum pruefen'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{progress && (
|
||||||
|
<div className="bg-purple-50 border border-purple-200 rounded-lg p-4 text-sm text-purple-700 flex items-center gap-3">
|
||||||
|
<svg className="animate-spin w-5 h-5 text-purple-500 shrink-0" 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>
|
||||||
|
{progress}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && <div className="bg-red-50 border border-red-200 rounded-lg p-4 text-sm text-red-700">{error}</div>}
|
||||||
|
|
||||||
|
{results?.results && (
|
||||||
|
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
||||||
|
<ChecklistView results={results.results} />
|
||||||
|
{results.email_status && (
|
||||||
|
<div className="mt-3 text-xs text-gray-500 flex items-center gap-2">
|
||||||
|
<span className={`w-2 h-2 rounded-full ${results.email_status === 'sent' ? 'bg-green-400' : 'bg-gray-300'}`} />
|
||||||
|
E-Mail: {results.email_status === 'sent' ? 'Gesendet' : results.email_status}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{history.length > 0 && (
|
||||||
|
<div className="border border-gray-200 rounded-xl p-4">
|
||||||
|
<h4 className="text-sm font-medium text-gray-700 mb-2">Letzte Impressum-Checks</h4>
|
||||||
|
<div className="space-y-1">
|
||||||
|
{history.map((h, i) => (
|
||||||
|
<button key={i} onClick={() => {
|
||||||
|
setUrl(h.url)
|
||||||
|
if (h.resultKey) {
|
||||||
|
try { const s = localStorage.getItem(h.resultKey); if (s) { setResults(JSON.parse(s)); return } } catch {}
|
||||||
|
}
|
||||||
|
try { const l = localStorage.getItem('impressum-check-results'); if (l) setResults(JSON.parse(l)) } catch {}
|
||||||
|
}}
|
||||||
|
className="w-full flex items-center justify-between p-2.5 rounded-lg border border-gray-100 hover:border-purple-200 hover:bg-purple-50/30 transition-all text-left">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="text-sm font-medium text-gray-900 truncate">{h.url}</div>
|
||||||
|
<div className="text-xs text-gray-500">
|
||||||
|
{new Date(h.date).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' })}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3 shrink-0 ml-3">
|
||||||
|
<span className={`text-xs font-medium ${h.findings > 0 ? 'text-red-600' : 'text-green-600'}`}>
|
||||||
|
{h.findings} Findings
|
||||||
|
</span>
|
||||||
|
<span className={`text-xs font-medium ${h.pct === 100 ? 'text-green-700' : h.pct >= 50 ? 'text-yellow-700' : 'text-red-700'}`}>
|
||||||
|
{h.pct}%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,35 +1,24 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useState } from 'react'
|
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 { ScanResult } from './_components/ScanResult'
|
||||||
import { DocCheckTab } from './_components/DocCheckTab'
|
import { DocCheckTab } from './_components/DocCheckTab'
|
||||||
import { BannerCheckTab } from './_components/BannerCheckTab'
|
import { BannerCheckTab } from './_components/BannerCheckTab'
|
||||||
|
import { ImpressumCheckTab } from './_components/ImpressumCheckTab'
|
||||||
import { ComplianceFAQ } from './_components/ComplianceFAQ'
|
import { ComplianceFAQ } from './_components/ComplianceFAQ'
|
||||||
|
|
||||||
type AnalysisMode = 'pre_launch' | 'post_launch'
|
type AnalysisTab = 'scan' | 'doc-check' | 'banner-check' | 'impressum-check'
|
||||||
type AnalysisTab = 'quick' | 'scan' | 'doc-check' | 'banner-check'
|
|
||||||
|
|
||||||
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 }[] = [
|
const TABS: { id: AnalysisTab; label: string; desc: string }[] = [
|
||||||
{ id: 'quick', label: 'Schnellanalyse', desc: 'Einzelne Seite klassifizieren + bewerten' },
|
{ id: 'scan', label: 'Website-Scan', desc: 'Rechtliche Dokumente finden + Dienstleister erkennen' },
|
||||||
{ id: 'scan', label: 'Website-Scan', desc: 'Mehrere Seiten scannen + Dienstleister abgleichen' },
|
{ id: 'doc-check', label: 'Dokumenten-Pruefung', desc: 'DSI, AGB, Cookie-Richtlinie inhaltlich pruefen' },
|
||||||
{ id: 'doc-check', label: 'Dokumenten-Pruefung', desc: 'Einzelne Dokumente gezielt pruefen' },
|
|
||||||
{ id: 'banner-check', label: 'Banner-Check', desc: 'Cookie-Banner auf DSGVO-Konformitaet testen' },
|
{ id: 'banner-check', label: 'Banner-Check', desc: 'Cookie-Banner auf DSGVO-Konformitaet testen' },
|
||||||
|
{ id: 'impressum-check', label: 'Impressum-Check', desc: 'Impressum auf §5 TMG Pflichtangaben pruefen' },
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function AgentPage() {
|
export default function AgentPage() {
|
||||||
// Restore state from localStorage on mount
|
|
||||||
const [url, setUrl] = useState(() => typeof window !== 'undefined' ? localStorage.getItem('agent-scan-url') || '' : '')
|
const [url, setUrl] = useState(() => typeof window !== 'undefined' ? localStorage.getItem('agent-scan-url') || '' : '')
|
||||||
const [mode, setMode] = useState<AnalysisMode>(() => (typeof window !== 'undefined' ? localStorage.getItem('agent-scan-mode') as AnalysisMode : null) || 'post_launch')
|
const [tab, setTab] = useState<AnalysisTab>(() => (typeof window !== 'undefined' ? localStorage.getItem('agent-scan-tab') as AnalysisTab : null) || 'scan')
|
||||||
const [tab, setTab] = useState<AnalysisTab>(() => (typeof window !== 'undefined' ? localStorage.getItem('agent-scan-tab') as AnalysisTab : null) || 'quick')
|
|
||||||
const [scanLoading, setScanLoading] = useState(false)
|
const [scanLoading, setScanLoading] = useState(false)
|
||||||
const [scanError, setScanError] = useState<string | null>(null)
|
const [scanError, setScanError] = useState<string | null>(null)
|
||||||
const [scanData, setScanData] = useState<any>(() => {
|
const [scanData, setScanData] = useState<any>(() => {
|
||||||
@@ -38,19 +27,15 @@ export default function AgentPage() {
|
|||||||
})
|
})
|
||||||
const [scanProgress, setScanProgress] = useState<string>('')
|
const [scanProgress, setScanProgress] = useState<string>('')
|
||||||
const [activeScanId, setActiveScanId] = useState<string>(() => typeof window !== 'undefined' ? localStorage.getItem('agent-scan-id') || '' : '')
|
const [activeScanId, setActiveScanId] = useState<string>(() => typeof window !== 'undefined' ? localStorage.getItem('agent-scan-id') || '' : '')
|
||||||
const [scanHistory, setScanHistory] = useState<{ url: string; date: string; findings: number; docs: number }[]>(() => {
|
const [scanHistory, setScanHistory] = useState<{ url: string; date: string; findings: number; docs: number; resultKey: string }[]>(() => {
|
||||||
if (typeof window === 'undefined') return []
|
if (typeof window === 'undefined') return []
|
||||||
try { return JSON.parse(localStorage.getItem('agent-scan-history') || '[]') } catch { return [] }
|
try { return JSON.parse(localStorage.getItem('agent-scan-history') || '[]') } catch { return [] }
|
||||||
})
|
})
|
||||||
const { analyze, answerFollowUp, loading, error, result, history } = useAgentAnalysis()
|
|
||||||
|
|
||||||
// Persist state to localStorage
|
|
||||||
React.useEffect(() => { localStorage.setItem('agent-scan-url', url) }, [url])
|
React.useEffect(() => { localStorage.setItem('agent-scan-url', url) }, [url])
|
||||||
React.useEffect(() => { localStorage.setItem('agent-scan-mode', mode) }, [mode])
|
|
||||||
React.useEffect(() => { localStorage.setItem('agent-scan-tab', tab) }, [tab])
|
React.useEffect(() => { localStorage.setItem('agent-scan-tab', tab) }, [tab])
|
||||||
React.useEffect(() => { if (scanData?.services) localStorage.setItem('agent-scan-result', JSON.stringify(scanData)) }, [scanData])
|
|
||||||
|
|
||||||
// Resume polling if scan was in progress when page was left
|
// Resume polling if scan was in progress
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!activeScanId || scanData?.services) return
|
if (!activeScanId || scanData?.services) return
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
@@ -74,15 +59,8 @@ export default function AgentPage() {
|
|||||||
_addToHistory(data.result)
|
_addToHistory(data.result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (data.status === 'failed') {
|
if (data.status === 'failed' || data.status === 'not_found') {
|
||||||
setScanError(data.error || 'Scan fehlgeschlagen')
|
if (data.status === 'failed') setScanError(data.error || 'Scan fehlgeschlagen')
|
||||||
setScanProgress('')
|
|
||||||
setScanLoading(false)
|
|
||||||
localStorage.removeItem('agent-scan-id')
|
|
||||||
setActiveScanId('')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (data.status === 'not_found') {
|
|
||||||
setScanProgress('')
|
setScanProgress('')
|
||||||
setScanLoading(false)
|
setScanLoading(false)
|
||||||
localStorage.removeItem('agent-scan-id')
|
localStorage.removeItem('agent-scan-id')
|
||||||
@@ -97,125 +75,97 @@ export default function AgentPage() {
|
|||||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const _addToHistory = (result: any) => {
|
const _addToHistory = (result: any) => {
|
||||||
|
const resultKey = `scan-result-${Date.now()}`
|
||||||
|
try { localStorage.setItem(resultKey, JSON.stringify(result)) } catch {}
|
||||||
const entry = {
|
const entry = {
|
||||||
url: url || result.url || '',
|
url: url || result.url || '',
|
||||||
date: new Date().toISOString(),
|
date: new Date().toISOString(),
|
||||||
findings: result.findings?.length || 0,
|
findings: result.findings?.length || 0,
|
||||||
docs: result.discovered_documents?.length || 0,
|
docs: result.discovered_documents?.length || 0,
|
||||||
|
resultKey,
|
||||||
}
|
}
|
||||||
const updated = [entry, ...scanHistory].slice(0, 50)
|
const updated = [entry, ...scanHistory].slice(0, 30)
|
||||||
setScanHistory(updated)
|
setScanHistory(updated)
|
||||||
localStorage.setItem('agent-scan-history', JSON.stringify(updated))
|
localStorage.setItem('agent-scan-history', JSON.stringify(updated))
|
||||||
}
|
}
|
||||||
|
|
||||||
const _loadFromHistory = (entry: { url: string }) => {
|
const handleScan = async (e: React.FormEvent) => {
|
||||||
setUrl(entry.url)
|
|
||||||
setTab('scan')
|
|
||||||
// Load saved result if same URL
|
|
||||||
try {
|
|
||||||
const saved = localStorage.getItem('agent-scan-result')
|
|
||||||
if (saved) {
|
|
||||||
const parsed = JSON.parse(saved)
|
|
||||||
if (parsed.url === entry.url) {
|
|
||||||
setScanData(parsed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!url.trim()) return
|
if (!url.trim()) return
|
||||||
|
setScanLoading(true)
|
||||||
|
setScanError(null)
|
||||||
|
setScanData(null)
|
||||||
|
setScanProgress('Scan wird gestartet...')
|
||||||
|
try {
|
||||||
|
const startRes = await fetch('/api/sdk/v1/agent/scan', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ url: url.trim(), mode: 'post_launch' }),
|
||||||
|
})
|
||||||
|
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')
|
||||||
|
setActiveScanId(scan_id)
|
||||||
|
localStorage.setItem('agent-scan-id', scan_id)
|
||||||
|
|
||||||
if (tab === 'quick') {
|
let attempts = 0
|
||||||
analyze(url.trim(), mode)
|
while (attempts < 120) {
|
||||||
} else {
|
await new Promise(r => setTimeout(r, 5000))
|
||||||
setScanLoading(true)
|
const pollRes = await fetch(`/api/sdk/v1/agent/scan?scan_id=${scan_id}`)
|
||||||
setScanError(null)
|
if (!pollRes.ok) { attempts++; continue }
|
||||||
setScanData(null)
|
const pollData = await pollRes.json()
|
||||||
setScanProgress('Scan wird gestartet...')
|
if (pollData.progress) setScanProgress(pollData.progress)
|
||||||
try {
|
if (pollData.status === 'completed' && pollData.result) {
|
||||||
// Step 1: Start async scan
|
setScanData(pollData.result)
|
||||||
const startRes = await fetch('/api/sdk/v1/agent/scan', {
|
setScanProgress('')
|
||||||
method: 'POST',
|
localStorage.setItem('agent-scan-result', JSON.stringify(pollData.result))
|
||||||
headers: { 'Content-Type': 'application/json' },
|
localStorage.removeItem('agent-scan-id')
|
||||||
body: JSON.stringify({ url: url.trim(), mode }),
|
setActiveScanId('')
|
||||||
})
|
_addToHistory(pollData.result)
|
||||||
if (!startRes.ok) throw new Error(`Scan konnte nicht gestartet werden: ${startRes.status}`)
|
break
|
||||||
const { scan_id } = await startRes.json()
|
|
||||||
if (!scan_id) throw new Error('Keine Scan-ID erhalten')
|
|
||||||
setActiveScanId(scan_id)
|
|
||||||
localStorage.setItem('agent-scan-id', scan_id)
|
|
||||||
|
|
||||||
// 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 pollData = await pollRes.json()
|
|
||||||
|
|
||||||
if (pollData.progress) {
|
|
||||||
setScanProgress(pollData.progress)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pollData.status === 'completed' && pollData.result) {
|
|
||||||
setScanData(pollData.result)
|
|
||||||
setScanProgress('')
|
|
||||||
localStorage.setItem('agent-scan-result', JSON.stringify(pollData.result))
|
|
||||||
localStorage.removeItem('agent-scan-id')
|
|
||||||
setActiveScanId('')
|
|
||||||
_addToHistory(pollData.result)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (pollData.status === 'failed') {
|
|
||||||
throw new Error(pollData.error || 'Scan fehlgeschlagen')
|
|
||||||
}
|
|
||||||
attempts++
|
|
||||||
}
|
}
|
||||||
if (attempts >= maxAttempts) throw new Error('Scan-Timeout (10 Minuten)')
|
if (pollData.status === 'failed') throw new Error(pollData.error || 'Scan fehlgeschlagen')
|
||||||
} catch (e) {
|
attempts++
|
||||||
setScanError(e instanceof Error ? e.message : 'Unbekannter Fehler')
|
|
||||||
setScanProgress('')
|
|
||||||
} finally {
|
|
||||||
setScanLoading(false)
|
|
||||||
}
|
}
|
||||||
|
if (attempts >= 120) throw new Error('Scan-Timeout (10 Minuten)')
|
||||||
|
} catch (e) {
|
||||||
|
setScanError(e instanceof Error ? e.message : 'Unbekannter Fehler')
|
||||||
|
setScanProgress('')
|
||||||
|
} finally {
|
||||||
|
setScanLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLoading = tab === 'quick' ? loading : scanLoading
|
// Navigate to a specialized tab with a pre-filled URL
|
||||||
const currentError = tab === 'quick' ? error : scanError
|
const navigateToCheck = (targetTab: AnalysisTab, checkUrl: string) => {
|
||||||
|
// Store the URL in the target tab's localStorage key
|
||||||
|
const keyMap: Record<string, string> = {
|
||||||
|
'doc-check': 'doc-check-prefill-url',
|
||||||
|
'banner-check': 'banner-check-url',
|
||||||
|
'impressum-check': 'impressum-check-url',
|
||||||
|
}
|
||||||
|
if (keyMap[targetTab]) {
|
||||||
|
localStorage.setItem(keyMap[targetTab], checkUrl)
|
||||||
|
}
|
||||||
|
setTab(targetTab)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract discovered documents for quick-action buttons
|
||||||
|
const discoveredDocs = scanData?.discovered_documents || []
|
||||||
|
const scannedUrl = scanData?.url || url
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 max-w-4xl">
|
<div className="space-y-6 max-w-4xl">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-bold text-gray-900">Compliance Agent</h1>
|
<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>
|
<p className="text-gray-500 mt-1">Analysiere Webseiten und Dokumente 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>
|
</div>
|
||||||
|
|
||||||
{/* Tab Selection */}
|
{/* Tab Selection */}
|
||||||
<div className="flex border-b border-gray-200">
|
<div className="flex border-b border-gray-200 overflow-x-auto">
|
||||||
{TABS.map(t => (
|
{TABS.map(t => (
|
||||||
<button key={t.id} onClick={() => setTab(t.id)}
|
<button key={t.id} onClick={() => setTab(t.id)}
|
||||||
className={`px-4 py-2.5 text-sm font-medium border-b-2 transition-colors ${
|
className={`px-4 py-2.5 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${
|
||||||
tab === t.id
|
tab === t.id
|
||||||
? 'border-purple-500 text-purple-700'
|
? 'border-purple-500 text-purple-700'
|
||||||
: 'border-transparent text-gray-500 hover:text-gray-700'}`}>
|
: 'border-transparent text-gray-500 hover:text-gray-700'}`}>
|
||||||
@@ -224,94 +174,122 @@ export default function AgentPage() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Doc Check Tab — own component */}
|
{/* Website-Scan Tab */}
|
||||||
{tab === 'doc-check' && <DocCheckTab />}
|
{tab === 'scan' && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="bg-indigo-50 border border-indigo-200 rounded-lg p-4">
|
||||||
|
<h3 className="text-sm font-semibold text-indigo-900">Website-Scan (Discovery)</h3>
|
||||||
|
<p className="text-xs text-indigo-700 mt-1">
|
||||||
|
Findet alle rechtlichen Dokumente (DSI, AGB, Impressum, Cookie, Widerruf),
|
||||||
|
erkennt eingesetzte Drittdienste und prueft ob sie in der DSE dokumentiert sind.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Banner Check Tab — own component */}
|
<form onSubmit={handleScan} className="flex gap-3">
|
||||||
{tab === 'banner-check' && <BannerCheckTab />}
|
<input type="url" value={url} onChange={e => setUrl(e.target.value)}
|
||||||
|
placeholder="https://www.example.com/"
|
||||||
|
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={scanLoading} required />
|
||||||
|
<button type="submit" disabled={scanLoading || !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 whitespace-nowrap">
|
||||||
|
{scanLoading ? (
|
||||||
|
<><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>Scanne...</>
|
||||||
|
) : 'Website scannen'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
{/* URL Input (quick + scan only) */}
|
{scanProgress && (
|
||||||
{(tab === 'quick' || tab === 'scan') && <form onSubmit={handleSubmit} className="flex gap-3">
|
<div className="bg-purple-50 border border-purple-200 rounded-lg p-4 text-sm text-purple-700 flex items-center gap-3">
|
||||||
<input type="url" value={url} onChange={e => setUrl(e.target.value)}
|
<svg className="animate-spin w-5 h-5 text-purple-500 shrink-0" fill="none" viewBox="0 0 24 24">
|
||||||
placeholder={tab === 'scan' ? 'https://www.example.com/' : 'https://example.com/datenschutz'}
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
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"
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||||
disabled={isLoading} required />
|
</svg>
|
||||||
<button type="submit" disabled={isLoading || !url.trim()}
|
{scanProgress}
|
||||||
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">
|
</div>
|
||||||
{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 === 'scan' ? 'Scanne...' : 'Analysiere...'}</>
|
|
||||||
) : tab === 'scan' ? 'Website scannen' : 'Analysieren'}
|
|
||||||
</button>
|
|
||||||
</form>}
|
|
||||||
|
|
||||||
{/* Scan Progress */}
|
{scanError && (
|
||||||
{scanProgress && tab === 'scan' && (
|
<div className="bg-red-50 border border-red-200 rounded-lg p-4 text-sm text-red-700">{scanError}</div>
|
||||||
<div className="bg-purple-50 border border-purple-200 rounded-lg p-4 text-sm text-purple-700 flex items-center gap-3">
|
)}
|
||||||
<svg className="animate-spin w-5 h-5 text-purple-500 shrink-0" 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>
|
|
||||||
{scanProgress}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Error */}
|
{/* Quick Action Buttons — navigate to specialized tabs */}
|
||||||
{currentError && (
|
{scanData && (
|
||||||
<div className="bg-red-50 border border-red-200 rounded-lg p-4 text-sm text-red-700">{currentError}</div>
|
<div className="bg-white border border-gray-200 rounded-xl p-4 shadow-sm">
|
||||||
)}
|
<h4 className="text-sm font-semibold text-gray-800 mb-3">Jetzt pruefen</h4>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<button onClick={() => navigateToCheck('banner-check', scannedUrl)}
|
||||||
|
className="p-3 rounded-lg border border-gray-200 hover:border-purple-300 hover:bg-purple-50 transition-all text-left">
|
||||||
|
<div className="text-sm font-medium text-gray-900">Cookie-Banner pruefen</div>
|
||||||
|
<div className="text-xs text-gray-500 mt-0.5">3-Phasen Dark-Pattern-Analyse</div>
|
||||||
|
</button>
|
||||||
|
<button onClick={() => navigateToCheck('impressum-check', scannedUrl + '/impressum')}
|
||||||
|
className="p-3 rounded-lg border border-gray-200 hover:border-purple-300 hover:bg-purple-50 transition-all text-left">
|
||||||
|
<div className="text-sm font-medium text-gray-900">Impressum pruefen</div>
|
||||||
|
<div className="text-xs text-gray-500 mt-0.5">§5 TMG Pflichtangaben</div>
|
||||||
|
</button>
|
||||||
|
{discoveredDocs.map((doc: any, i: number) => (
|
||||||
|
<button key={i} onClick={() => navigateToCheck('doc-check', doc.url)}
|
||||||
|
className="p-3 rounded-lg border border-gray-200 hover:border-purple-300 hover:bg-purple-50 transition-all text-left">
|
||||||
|
<div className="text-sm font-medium text-gray-900 truncate">{doc.title || doc.url}</div>
|
||||||
|
<div className="text-xs text-gray-500 mt-0.5">
|
||||||
|
{doc.doc_type?.toUpperCase()} · {doc.word_count || '?'} Woerter
|
||||||
|
{doc.completeness_pct != null && ` · ${doc.completeness_pct}%`}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Quick Analysis Result */}
|
{/* Full Scan Result */}
|
||||||
{tab === 'quick' && result && (
|
{scanData?.services && (
|
||||||
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm space-y-6">
|
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
||||||
<AnalysisResult result={result} />
|
<ScanResult data={scanData} />
|
||||||
{result.follow_up_questions.length > 0 && (
|
</div>
|
||||||
<div className="border-t pt-4">
|
)}
|
||||||
<FollowUpQuestions questions={result.follow_up_questions} answers={result.follow_up_answers} onAnswer={answerFollowUp} />
|
|
||||||
|
{/* Scan History */}
|
||||||
|
{scanHistory.length > 0 && (
|
||||||
|
<div className="border border-gray-200 rounded-xl p-4">
|
||||||
|
<h4 className="text-sm font-medium text-gray-700 mb-3">Letzte Scans</h4>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{scanHistory.map((h, i) => (
|
||||||
|
<button key={i} onClick={() => {
|
||||||
|
setUrl(h.url)
|
||||||
|
if (h.resultKey) {
|
||||||
|
try { const s = localStorage.getItem(h.resultKey); if (s) { setScanData(JSON.parse(s)); return } } catch {}
|
||||||
|
}
|
||||||
|
try { const l = localStorage.getItem('agent-scan-result'); if (l) setScanData(JSON.parse(l)) } catch {}
|
||||||
|
}}
|
||||||
|
className="w-full flex items-center justify-between p-3 rounded-lg border border-gray-100 hover:border-purple-200 hover:bg-purple-50/30 transition-all text-left">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="text-sm font-medium text-gray-900 truncate">{h.url}</div>
|
||||||
|
<div className="text-xs text-gray-500">
|
||||||
|
{new Date(h.date).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' })}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-3 shrink-0 ml-3">
|
||||||
|
{h.docs > 0 && <span className="text-xs text-purple-600">{h.docs} Dok.</span>}
|
||||||
|
<span className={`text-xs font-medium ${h.findings > 0 ? 'text-red-600' : 'text-green-600'}`}>
|
||||||
|
{h.findings} Findings
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Scan Result — only render when we have a complete response with services */}
|
{/* Specialized Tabs */}
|
||||||
{tab === 'scan' && scanData && scanData.services && (
|
{tab === 'doc-check' && <DocCheckTab />}
|
||||||
<div className="bg-white border border-gray-200 rounded-xl p-6 shadow-sm">
|
{tab === 'banner-check' && <BannerCheckTab />}
|
||||||
<ScanResult data={scanData} />
|
{tab === 'impressum-check' && <ImpressumCheckTab />}
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* History (quick only) */}
|
|
||||||
{tab === 'quick' && (
|
|
||||||
<AnalysisHistory history={history} onSelect={r => { setUrl(r.url); analyze(r.url, mode) }} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Scan History */}
|
|
||||||
{tab === 'scan' && scanHistory.length > 0 && (
|
|
||||||
<div className="border border-gray-200 rounded-xl p-4">
|
|
||||||
<h4 className="text-sm font-medium text-gray-700 mb-3">Letzte Scans</h4>
|
|
||||||
<div className="space-y-2">
|
|
||||||
{scanHistory.map((h, i) => (
|
|
||||||
<button key={i} onClick={() => _loadFromHistory(h)}
|
|
||||||
className="w-full flex items-center justify-between p-3 rounded-lg border border-gray-100 hover:border-purple-200 hover:bg-purple-50/30 transition-all text-left">
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<div className="text-sm font-medium text-gray-900 truncate">{h.url}</div>
|
|
||||||
<div className="text-xs text-gray-500">
|
|
||||||
{new Date(h.date).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' })}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-3 shrink-0 ml-3">
|
|
||||||
{h.docs > 0 && <span className="text-xs text-purple-600">{h.docs} Dok.</span>}
|
|
||||||
<span className={`text-xs font-medium ${h.findings > 0 ? 'text-red-600' : 'text-green-600'}`}>
|
|
||||||
{h.findings} Findings
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* FAQ */}
|
{/* FAQ */}
|
||||||
<ComplianceFAQ />
|
<ComplianceFAQ />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user