[split-required] Split remaining 500-680 LOC files (final batch)
website (17 pages + 3 components): - multiplayer/wizard, middleware/wizard+test-wizard, communication - builds/wizard, staff-search, voice, sbom/wizard - foerderantrag, mail/tasks, tools/communication, sbom - compliance/evidence, uni-crawler, brandbook (already done) - CollectionsTab, IngestionTab, RiskHeatmap backend-lehrer (5 files): - letters_api (641 → 2), certificates_api (636 → 2) - alerts_agent/db/models (636 → 3) - llm_gateway/communication_service (614 → 2) - game/database already done in prior batch klausur-service (2 files): - hybrid_vocab_extractor (664 → 2) - klausur-service/frontend: api.ts (620 → 3), EHUploadWizard (591 → 2) voice-service (3 files): - bqas/rag_judge (618 → 3), runner (529 → 2) - enhanced_task_orchestrator (519 → 2) studio-v2 (6 files): - korrektur/[klausurId] (578 → 4), fairness (569 → 2) - AlertsWizard (552 → 2), OnboardingWizard (513 → 2) - korrektur/api.ts (506 → 3), geo-lernwelt (501 → 2) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
246
website/app/admin/rag/components/CollectionCard.tsx
Normal file
246
website/app/admin/rag/components/CollectionCard.tsx
Normal file
@@ -0,0 +1,246 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import type { Collection } from '../types'
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_KLAUSUR_SERVICE_URL || 'http://localhost:8086'
|
||||
|
||||
const statusColors = {
|
||||
ready: 'bg-green-100 text-green-800',
|
||||
indexing: 'bg-yellow-100 text-yellow-800',
|
||||
empty: 'bg-slate-100 text-slate-800',
|
||||
}
|
||||
|
||||
const statusLabels = {
|
||||
ready: 'Bereit',
|
||||
indexing: 'Indexierung...',
|
||||
empty: 'Leer',
|
||||
}
|
||||
|
||||
const useCaseLabels: Record<string, string> = {
|
||||
klausur: 'Klausurkorrektur',
|
||||
zeugnis: 'Zeugniserstellung',
|
||||
material: 'Unterrichtsmaterial',
|
||||
curriculum: 'Lehrplan',
|
||||
other: 'Sonstiges',
|
||||
unknown: 'Unbekannt',
|
||||
}
|
||||
|
||||
export function CollectionCard({ collection }: { collection: Collection }) {
|
||||
const [ingesting, setIngesting] = useState(false)
|
||||
const [reindexing, setReindexing] = useState(false)
|
||||
const [ingestMessage, setIngestMessage] = useState<string | null>(null)
|
||||
const [showReindexConfirm, setShowReindexConfirm] = useState(false)
|
||||
const [chunkingStrategy, setChunkingStrategy] = useState<'semantic' | 'recursive'>('semantic')
|
||||
|
||||
const handleIngest = async () => {
|
||||
setIngesting(true)
|
||||
setIngestMessage(null)
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/rag/collections/${collection.name}/ingest?incremental=true`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setIngestMessage(data.message || 'Indexierung gestartet')
|
||||
} else {
|
||||
const error = await res.json()
|
||||
setIngestMessage(error.detail || 'Fehler beim Starten')
|
||||
}
|
||||
} catch (err) {
|
||||
setIngestMessage('Netzwerkfehler')
|
||||
} finally {
|
||||
setIngesting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleReindex = async () => {
|
||||
setShowReindexConfirm(false)
|
||||
setReindexing(true)
|
||||
setIngestMessage('Starte Re-Indexierung...')
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${API_BASE}/api/v1/admin/rag/collections/${collection.name}/reindex?chunking_strategy=${chunkingStrategy}`,
|
||||
{ method: 'POST' }
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json()
|
||||
setIngestMessage(error.detail || 'Fehler beim Starten')
|
||||
setReindexing(false)
|
||||
return
|
||||
}
|
||||
|
||||
const pollProgress = async () => {
|
||||
try {
|
||||
const progressRes = await fetch(`${API_BASE}/api/v1/admin/rag/reindex/progress`)
|
||||
if (progressRes.ok) {
|
||||
const progress = await progressRes.json()
|
||||
|
||||
if (progress.phase === 'deleting') {
|
||||
setIngestMessage('Loesche alte Chunks...')
|
||||
} else if (progress.phase === 'indexing') {
|
||||
const pct = progress.total_docs > 0
|
||||
? Math.round((progress.current_doc / progress.total_docs) * 100)
|
||||
: 0
|
||||
setIngestMessage(
|
||||
`Indexiere: ${progress.current_doc}/${progress.total_docs} (${pct}%) - ${progress.current_filename}`
|
||||
)
|
||||
} else if (progress.phase === 'complete') {
|
||||
setIngestMessage(
|
||||
`Fertig: ${progress.documents_processed} Dokumente, ` +
|
||||
`${progress.chunks_created} neue Chunks (${progress.old_chunks_deleted} alte geloescht)`
|
||||
)
|
||||
setReindexing(false)
|
||||
return
|
||||
} else if (progress.phase === 'failed') {
|
||||
setIngestMessage(`Fehler: ${progress.error || 'Unbekannter Fehler'}`)
|
||||
setReindexing(false)
|
||||
return
|
||||
}
|
||||
|
||||
if (progress.running) {
|
||||
setTimeout(pollProgress, 1000)
|
||||
} else {
|
||||
setReindexing(false)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setTimeout(pollProgress, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(pollProgress, 500)
|
||||
} catch (err) {
|
||||
setIngestMessage('Netzwerkfehler bei Re-Indexierung')
|
||||
setReindexing(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg border border-slate-200 p-6 hover:shadow-md transition-shadow">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-12 h-12 bg-primary-100 rounded-lg flex items-center justify-center">
|
||||
<svg className="w-6 h-6 text-primary-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-slate-900">{collection.displayName}</h3>
|
||||
<p className="text-sm text-slate-500 font-mono">{collection.name}</p>
|
||||
{collection.description && (
|
||||
<p className="text-sm text-slate-600 mt-1">{collection.description}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2">
|
||||
<span className={`px-3 py-1 rounded-full text-xs font-medium ${statusColors[collection.status]}`}>
|
||||
{statusLabels[collection.status]}
|
||||
</span>
|
||||
<span className="px-2 py-1 bg-slate-100 text-slate-600 text-xs rounded">
|
||||
{useCaseLabels[collection.useCase] || collection.useCase}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Chunks</p>
|
||||
<p className="text-lg font-semibold text-slate-900">{collection.chunkCount.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Jahre</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.years?.length > 0
|
||||
? `${Math.min(...collection.years)}-${Math.max(...collection.years)}`
|
||||
: '-'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Faecher</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.subjects?.length > 0 ? collection.subjects.length : '-'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Bundesland</p>
|
||||
<p className="text-lg font-semibold text-slate-900">{collection.bundesland}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{collection.subjects.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{collection.subjects.slice(0, 8).map((subject) => (
|
||||
<span key={subject} className="px-2 py-1 bg-slate-100 text-slate-700 text-xs rounded-md">{subject}</span>
|
||||
))}
|
||||
{collection.subjects.length > 8 && (
|
||||
<span className="px-2 py-1 bg-slate-100 text-slate-500 text-xs rounded-md">+{collection.subjects.length - 8} weitere</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Ingestion Buttons */}
|
||||
<div className="mt-4 pt-4 border-t border-slate-200">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<button
|
||||
onClick={handleIngest}
|
||||
disabled={ingesting || reindexing}
|
||||
className="px-4 py-2 text-sm font-medium text-primary-700 bg-primary-50 border border-primary-200 rounded-lg hover:bg-primary-100 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
>
|
||||
{ingesting ? (
|
||||
<><div className="animate-spin rounded-full h-4 w-4 border-b-2 border-primary-600"></div>Wird gestartet...</>
|
||||
) : (
|
||||
<><svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" /></svg>Neue indexieren</>
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowReindexConfirm(true)}
|
||||
disabled={ingesting || reindexing || collection.chunkCount === 0}
|
||||
className="px-4 py-2 text-sm font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-lg hover:bg-amber-100 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
title="Alle Dokumente mit neuem Chunking-Algorithmus neu indexieren"
|
||||
>
|
||||
{reindexing ? (
|
||||
<><div className="animate-spin rounded-full h-4 w-4 border-b-2 border-amber-600"></div>Re-Indexierung...</>
|
||||
) : (
|
||||
<><svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" /></svg>Neu-Chunking</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
{ingestMessage && <p className="mt-2 text-sm text-slate-600">{ingestMessage}</p>}
|
||||
</div>
|
||||
|
||||
{/* Re-Index Confirmation Modal */}
|
||||
{showReindexConfirm && (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-xl p-6 max-w-md w-full mx-4 shadow-xl">
|
||||
<h3 className="text-lg font-semibold text-slate-900 mb-4">Collection neu indexieren?</h3>
|
||||
<p className="text-slate-600 mb-4">
|
||||
Dies loescht alle {collection.chunkCount.toLocaleString()} bestehenden Chunks
|
||||
und erstellt sie mit dem gewaehlten Chunking-Algorithmus neu.
|
||||
</p>
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm font-medium text-slate-700 mb-2">Chunking-Strategie</label>
|
||||
<div className="flex gap-4">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input type="radio" name="chunkingStrategy" value="semantic" checked={chunkingStrategy === 'semantic'} onChange={() => setChunkingStrategy('semantic')} className="text-primary-600" />
|
||||
<span className="text-sm"><strong>Semantisch</strong><span className="text-slate-500 ml-1">(empfohlen)</span></span>
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input type="radio" name="chunkingStrategy" value="recursive" checked={chunkingStrategy === 'recursive'} onChange={() => setChunkingStrategy('recursive')} className="text-primary-600" />
|
||||
<span className="text-sm">Rekursiv (legacy)</span>
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-slate-500 mt-2">Semantisches Chunking respektiert Satzgrenzen und verbessert die Suchqualitaet.</p>
|
||||
</div>
|
||||
<div className="flex justify-end gap-3">
|
||||
<button onClick={() => setShowReindexConfirm(false)} className="px-4 py-2 text-sm font-medium text-slate-700 bg-slate-100 rounded-lg hover:bg-slate-200">Abbrechen</button>
|
||||
<button onClick={handleReindex} className="px-4 py-2 text-sm font-medium text-white bg-amber-600 rounded-lg hover:bg-amber-700">Neu indexieren</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import type { Collection, CreateCollectionData } from '../types'
|
||||
import { CollectionCard } from './CollectionCard'
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_KLAUSUR_SERVICE_URL || 'http://localhost:8086'
|
||||
|
||||
@@ -11,11 +12,24 @@ interface CollectionsTabProps {
|
||||
onRefresh: () => void
|
||||
}
|
||||
|
||||
function CollectionsTab({
|
||||
collections,
|
||||
loading,
|
||||
onRefresh
|
||||
}: CollectionsTabProps) {
|
||||
const useCaseOptions = [
|
||||
{ value: 'klausur', label: 'Klausurkorrektur' },
|
||||
{ value: 'zeugnis', label: 'Zeugniserstellung' },
|
||||
{ value: 'material', label: 'Unterrichtsmaterial' },
|
||||
{ value: 'curriculum', label: 'Lehrplan' },
|
||||
{ value: 'other', label: 'Sonstiges' },
|
||||
]
|
||||
|
||||
const bundeslandOptions = [
|
||||
{ value: 'NI', label: 'Niedersachsen' },
|
||||
{ value: 'NW', label: 'Nordrhein-Westfalen' },
|
||||
{ value: 'BY', label: 'Bayern' },
|
||||
{ value: 'BW', label: 'Baden-Wuerttemberg' },
|
||||
{ value: 'HE', label: 'Hessen' },
|
||||
{ value: 'DE', label: 'Bundesweit' },
|
||||
]
|
||||
|
||||
function CollectionsTab({ collections, loading, onRefresh }: CollectionsTabProps) {
|
||||
const [showCreateModal, setShowCreateModal] = useState(false)
|
||||
const [creating, setCreating] = useState(false)
|
||||
const [createError, setCreateError] = useState<string | null>(null)
|
||||
@@ -30,23 +44,15 @@ function CollectionsTab({
|
||||
const handleCreate = async () => {
|
||||
setCreating(true)
|
||||
setCreateError(null)
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/rag/collections`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(formData),
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
setShowCreateModal(false)
|
||||
setFormData({
|
||||
name: 'bp_',
|
||||
display_name: '',
|
||||
bundesland: 'NI',
|
||||
use_case: '',
|
||||
description: '',
|
||||
})
|
||||
setFormData({ name: 'bp_', display_name: '', bundesland: 'NI', use_case: '', description: '' })
|
||||
onRefresh()
|
||||
} else {
|
||||
const error = await res.json()
|
||||
@@ -59,23 +65,6 @@ function CollectionsTab({
|
||||
}
|
||||
}
|
||||
|
||||
const useCaseOptions = [
|
||||
{ value: 'klausur', label: 'Klausurkorrektur' },
|
||||
{ value: 'zeugnis', label: 'Zeugniserstellung' },
|
||||
{ value: 'material', label: 'Unterrichtsmaterial' },
|
||||
{ value: 'curriculum', label: 'Lehrplan' },
|
||||
{ value: 'other', label: 'Sonstiges' },
|
||||
]
|
||||
|
||||
const bundeslandOptions = [
|
||||
{ value: 'NI', label: 'Niedersachsen' },
|
||||
{ value: 'NW', label: 'Nordrhein-Westfalen' },
|
||||
{ value: 'BY', label: 'Bayern' },
|
||||
{ value: 'BW', label: 'Baden-Württemberg' },
|
||||
{ value: 'HE', label: 'Hessen' },
|
||||
{ value: 'DE', label: 'Bundesweit' },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
@@ -85,32 +74,20 @@ function CollectionsTab({
|
||||
<p className="text-sm text-slate-500">Verwaltung der indexierten Dokumentensammlungen</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={onRefresh}
|
||||
className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50"
|
||||
>
|
||||
Aktualisieren
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowCreateModal(true)}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 flex items-center gap-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
||||
</svg>
|
||||
<button onClick={onRefresh} className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50">Aktualisieren</button>
|
||||
<button onClick={() => setShowCreateModal(true)} className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 flex items-center gap-2">
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" /></svg>
|
||||
Neue Sammlung
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Loading State */}
|
||||
{loading && (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"></div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Collections Grid */}
|
||||
{!loading && (
|
||||
<div className="grid gap-4">
|
||||
{collections.length === 0 ? (
|
||||
@@ -120,28 +97,14 @@ function CollectionsTab({
|
||||
</svg>
|
||||
<h3 className="text-lg font-medium text-slate-900 mb-2">Keine Sammlungen vorhanden</h3>
|
||||
<p className="text-slate-500 mb-4">Erstellen Sie eine neue Sammlung, um Dokumente zu indexieren.</p>
|
||||
<button
|
||||
onClick={() => setShowCreateModal(true)}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700"
|
||||
>
|
||||
Erste Sammlung erstellen
|
||||
</button>
|
||||
<button onClick={() => setShowCreateModal(true)} className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700">Erste Sammlung erstellen</button>
|
||||
</div>
|
||||
) : (
|
||||
collections.map((col) => (
|
||||
<CollectionCard key={col.name} collection={col} />
|
||||
))
|
||||
collections.map((col) => <CollectionCard key={col.name} collection={col} />)
|
||||
)}
|
||||
|
||||
{/* Add new collection card */}
|
||||
{collections.length > 0 && (
|
||||
<button
|
||||
onClick={() => setShowCreateModal(true)}
|
||||
className="border-2 border-dashed border-slate-300 rounded-lg p-6 text-center hover:border-primary-400 hover:bg-primary-50 transition-colors cursor-pointer"
|
||||
>
|
||||
<svg className="w-8 h-8 text-slate-400 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
||||
</svg>
|
||||
<button onClick={() => setShowCreateModal(true)} className="border-2 border-dashed border-slate-300 rounded-lg p-6 text-center hover:border-primary-400 hover:bg-primary-50 transition-colors cursor-pointer">
|
||||
<svg className="w-8 h-8 text-slate-400 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" /></svg>
|
||||
<span className="text-sm font-medium text-slate-600">Neue Sammlung erstellen</span>
|
||||
</button>
|
||||
)}
|
||||
@@ -154,115 +117,43 @@ function CollectionsTab({
|
||||
<div className="bg-white rounded-xl shadow-xl w-full max-w-lg mx-4">
|
||||
<div className="p-6 border-b border-slate-200">
|
||||
<h3 className="text-lg font-semibold text-slate-900">Neue RAG-Sammlung erstellen</h3>
|
||||
<p className="text-sm text-slate-500 mt-1">
|
||||
Erstellen Sie eine neue Sammlung für einen spezifischen Anwendungsfall
|
||||
</p>
|
||||
<p className="text-sm text-slate-500 mt-1">Erstellen Sie eine neue Sammlung fuer einen spezifischen Anwendungsfall</p>
|
||||
</div>
|
||||
|
||||
<div className="p-6 space-y-4">
|
||||
{createError && (
|
||||
<div className="p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">
|
||||
{createError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{createError && <div className="p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">{createError}</div>}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">
|
||||
Anzeigename *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.display_name}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, display_name: e.target.value }))}
|
||||
placeholder="z.B. Niedersachsen - Zeugniserstellung"
|
||||
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
|
||||
/>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">Anzeigename *</label>
|
||||
<input type="text" value={formData.display_name} onChange={(e) => setFormData(prev => ({ ...prev, display_name: e.target.value }))} placeholder="z.B. Niedersachsen - Zeugniserstellung" className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-primary-500" />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">
|
||||
Bundesland
|
||||
</label>
|
||||
<select
|
||||
value={formData.bundesland}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, bundesland: e.target.value }))}
|
||||
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500"
|
||||
>
|
||||
{bundeslandOptions.map(opt => (
|
||||
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
||||
))}
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">Bundesland</label>
|
||||
<select value={formData.bundesland} onChange={(e) => setFormData(prev => ({ ...prev, bundesland: e.target.value }))} className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500">
|
||||
{bundeslandOptions.map(opt => <option key={opt.value} value={opt.value}>{opt.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">
|
||||
Anwendungsfall *
|
||||
</label>
|
||||
<select
|
||||
value={formData.use_case}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, use_case: e.target.value }))}
|
||||
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500"
|
||||
>
|
||||
<option value="">Auswählen...</option>
|
||||
{useCaseOptions.map(opt => (
|
||||
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
||||
))}
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">Anwendungsfall *</label>
|
||||
<select value={formData.use_case} onChange={(e) => setFormData(prev => ({ ...prev, use_case: e.target.value }))} className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500">
|
||||
<option value="">Auswaehlen...</option>
|
||||
{useCaseOptions.map(opt => <option key={opt.value} value={opt.value}>{opt.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">
|
||||
Technischer Name *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.name}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, name: e.target.value }))}
|
||||
placeholder="bp_ni_zeugnis"
|
||||
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500 font-mono text-sm"
|
||||
/>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">Technischer Name *</label>
|
||||
<input type="text" value={formData.name} onChange={(e) => setFormData(prev => ({ ...prev, name: e.target.value }))} placeholder="bp_ni_zeugnis" className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500 font-mono text-sm" />
|
||||
<p className="text-xs text-slate-500 mt-1">Muss mit "bp_" beginnen. Nur Kleinbuchstaben und Unterstriche.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">
|
||||
Beschreibung
|
||||
</label>
|
||||
<textarea
|
||||
value={formData.description}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, description: e.target.value }))}
|
||||
placeholder="Wofür wird diese Sammlung verwendet?"
|
||||
rows={3}
|
||||
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500"
|
||||
/>
|
||||
<label className="block text-sm font-medium text-slate-700 mb-1">Beschreibung</label>
|
||||
<textarea value={formData.description} onChange={(e) => setFormData(prev => ({ ...prev, description: e.target.value }))} placeholder="Wofuer wird diese Sammlung verwendet?" rows={3} className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-primary-500" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6 border-t border-slate-200 flex justify-end gap-3">
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowCreateModal(false)
|
||||
setCreateError(null)
|
||||
}}
|
||||
className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50"
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
onClick={handleCreate}
|
||||
disabled={creating || !formData.name || !formData.display_name || !formData.use_case}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
>
|
||||
{creating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Wird erstellt...
|
||||
</>
|
||||
) : (
|
||||
'Sammlung erstellen'
|
||||
)}
|
||||
<button onClick={() => { setShowCreateModal(false); setCreateError(null) }} className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50">Abbrechen</button>
|
||||
<button onClick={handleCreate} disabled={creating || !formData.name || !formData.display_name || !formData.use_case} className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2">
|
||||
{creating ? (<><div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>Wird erstellt...</>) : 'Sammlung erstellen'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -272,322 +163,4 @@ function CollectionsTab({
|
||||
)
|
||||
}
|
||||
|
||||
function CollectionCard({ collection }: { collection: Collection }) {
|
||||
const [ingesting, setIngesting] = useState(false)
|
||||
const [reindexing, setReindexing] = useState(false)
|
||||
const [ingestMessage, setIngestMessage] = useState<string | null>(null)
|
||||
const [showReindexConfirm, setShowReindexConfirm] = useState(false)
|
||||
const [chunkingStrategy, setChunkingStrategy] = useState<'semantic' | 'recursive'>('semantic')
|
||||
|
||||
const statusColors = {
|
||||
ready: 'bg-green-100 text-green-800',
|
||||
indexing: 'bg-yellow-100 text-yellow-800',
|
||||
empty: 'bg-slate-100 text-slate-800',
|
||||
}
|
||||
|
||||
const statusLabels = {
|
||||
ready: 'Bereit',
|
||||
indexing: 'Indexierung...',
|
||||
empty: 'Leer',
|
||||
}
|
||||
|
||||
const useCaseLabels: Record<string, string> = {
|
||||
klausur: 'Klausurkorrektur',
|
||||
zeugnis: 'Zeugniserstellung',
|
||||
material: 'Unterrichtsmaterial',
|
||||
curriculum: 'Lehrplan',
|
||||
other: 'Sonstiges',
|
||||
unknown: 'Unbekannt',
|
||||
}
|
||||
|
||||
const handleIngest = async () => {
|
||||
setIngesting(true)
|
||||
setIngestMessage(null)
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/rag/collections/${collection.name}/ingest?incremental=true`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setIngestMessage(data.message || 'Indexierung gestartet')
|
||||
} else {
|
||||
const error = await res.json()
|
||||
setIngestMessage(error.detail || 'Fehler beim Starten')
|
||||
}
|
||||
} catch (err) {
|
||||
setIngestMessage('Netzwerkfehler')
|
||||
} finally {
|
||||
setIngesting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleReindex = async () => {
|
||||
setShowReindexConfirm(false)
|
||||
setReindexing(true)
|
||||
setIngestMessage('Starte Re-Indexierung...')
|
||||
|
||||
try {
|
||||
// Start the reindex
|
||||
const res = await fetch(
|
||||
`${API_BASE}/api/v1/admin/rag/collections/${collection.name}/reindex?chunking_strategy=${chunkingStrategy}`,
|
||||
{ method: 'POST' }
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json()
|
||||
setIngestMessage(error.detail || 'Fehler beim Starten')
|
||||
setReindexing(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Poll for progress
|
||||
const pollProgress = async () => {
|
||||
try {
|
||||
const progressRes = await fetch(`${API_BASE}/api/v1/admin/rag/reindex/progress`)
|
||||
if (progressRes.ok) {
|
||||
const progress = await progressRes.json()
|
||||
|
||||
if (progress.phase === 'deleting') {
|
||||
setIngestMessage('Lösche alte Chunks...')
|
||||
} else if (progress.phase === 'indexing') {
|
||||
const pct = progress.total_docs > 0
|
||||
? Math.round((progress.current_doc / progress.total_docs) * 100)
|
||||
: 0
|
||||
setIngestMessage(
|
||||
`Indexiere: ${progress.current_doc}/${progress.total_docs} (${pct}%) - ${progress.current_filename}`
|
||||
)
|
||||
} else if (progress.phase === 'complete') {
|
||||
setIngestMessage(
|
||||
`Fertig: ${progress.documents_processed} Dokumente, ` +
|
||||
`${progress.chunks_created} neue Chunks (${progress.old_chunks_deleted} alte gelöscht)`
|
||||
)
|
||||
setReindexing(false)
|
||||
return // Stop polling
|
||||
} else if (progress.phase === 'failed') {
|
||||
setIngestMessage(`Fehler: ${progress.error || 'Unbekannter Fehler'}`)
|
||||
setReindexing(false)
|
||||
return // Stop polling
|
||||
}
|
||||
|
||||
// Continue polling if still running
|
||||
if (progress.running) {
|
||||
setTimeout(pollProgress, 1000)
|
||||
} else {
|
||||
setReindexing(false)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// Ignore polling errors, will retry
|
||||
setTimeout(pollProgress, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
// Start polling after a short delay
|
||||
setTimeout(pollProgress, 500)
|
||||
|
||||
} catch (err) {
|
||||
setIngestMessage('Netzwerkfehler bei Re-Indexierung')
|
||||
setReindexing(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg border border-slate-200 p-6 hover:shadow-md transition-shadow">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-12 h-12 bg-primary-100 rounded-lg flex items-center justify-center">
|
||||
<svg className="w-6 h-6 text-primary-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-slate-900">{collection.displayName}</h3>
|
||||
<p className="text-sm text-slate-500 font-mono">{collection.name}</p>
|
||||
{collection.description && (
|
||||
<p className="text-sm text-slate-600 mt-1">{collection.description}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col items-end gap-2">
|
||||
<span className={`px-3 py-1 rounded-full text-xs font-medium ${statusColors[collection.status]}`}>
|
||||
{statusLabels[collection.status]}
|
||||
</span>
|
||||
<span className="px-2 py-1 bg-slate-100 text-slate-600 text-xs rounded">
|
||||
{useCaseLabels[collection.useCase] || collection.useCase}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Chunks</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.chunkCount.toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Jahre</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.years?.length > 0
|
||||
? `${Math.min(...collection.years)}-${Math.max(...collection.years)}`
|
||||
: '-'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Fächer</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.subjects?.length > 0 ? collection.subjects.length : '-'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Bundesland</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{collection.bundesland}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{collection.subjects.length > 0 && (
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{collection.subjects.slice(0, 8).map((subject) => (
|
||||
<span
|
||||
key={subject}
|
||||
className="px-2 py-1 bg-slate-100 text-slate-700 text-xs rounded-md"
|
||||
>
|
||||
{subject}
|
||||
</span>
|
||||
))}
|
||||
{collection.subjects.length > 8 && (
|
||||
<span className="px-2 py-1 bg-slate-100 text-slate-500 text-xs rounded-md">
|
||||
+{collection.subjects.length - 8} weitere
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Ingestion Buttons */}
|
||||
<div className="mt-4 pt-4 border-t border-slate-200">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<button
|
||||
onClick={handleIngest}
|
||||
disabled={ingesting || reindexing}
|
||||
className="px-4 py-2 text-sm font-medium text-primary-700 bg-primary-50 border border-primary-200 rounded-lg hover:bg-primary-100 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
>
|
||||
{ingesting ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-primary-600"></div>
|
||||
Wird gestartet...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
|
||||
</svg>
|
||||
Neue indexieren
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setShowReindexConfirm(true)}
|
||||
disabled={ingesting || reindexing || collection.chunkCount === 0}
|
||||
className="px-4 py-2 text-sm font-medium text-amber-700 bg-amber-50 border border-amber-200 rounded-lg hover:bg-amber-100 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||
title="Alle Dokumente mit neuem Chunking-Algorithmus neu indexieren"
|
||||
>
|
||||
{reindexing ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-amber-600"></div>
|
||||
Re-Indexierung...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
Neu-Chunking
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{ingestMessage && (
|
||||
<p className="mt-2 text-sm text-slate-600">{ingestMessage}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Re-Index Confirmation Modal */}
|
||||
{showReindexConfirm && (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-xl p-6 max-w-md w-full mx-4 shadow-xl">
|
||||
<h3 className="text-lg font-semibold text-slate-900 mb-4">
|
||||
Collection neu indexieren?
|
||||
</h3>
|
||||
<p className="text-slate-600 mb-4">
|
||||
Dies löscht alle {collection.chunkCount.toLocaleString()} bestehenden Chunks
|
||||
und erstellt sie mit dem gewählten Chunking-Algorithmus neu.
|
||||
</p>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm font-medium text-slate-700 mb-2">
|
||||
Chunking-Strategie
|
||||
</label>
|
||||
<div className="flex gap-4">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="chunkingStrategy"
|
||||
value="semantic"
|
||||
checked={chunkingStrategy === 'semantic'}
|
||||
onChange={() => setChunkingStrategy('semantic')}
|
||||
className="text-primary-600"
|
||||
/>
|
||||
<span className="text-sm">
|
||||
<strong>Semantisch</strong>
|
||||
<span className="text-slate-500 ml-1">(empfohlen)</span>
|
||||
</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="chunkingStrategy"
|
||||
value="recursive"
|
||||
checked={chunkingStrategy === 'recursive'}
|
||||
onChange={() => setChunkingStrategy('recursive')}
|
||||
className="text-primary-600"
|
||||
/>
|
||||
<span className="text-sm">Rekursiv (legacy)</span>
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-slate-500 mt-2">
|
||||
Semantisches Chunking respektiert Satzgrenzen und verbessert die Suchqualität.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-3">
|
||||
<button
|
||||
onClick={() => setShowReindexConfirm(false)}
|
||||
className="px-4 py-2 text-sm font-medium text-slate-700 bg-slate-100 rounded-lg hover:bg-slate-200"
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
onClick={handleReindex}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-amber-600 rounded-lg hover:bg-amber-700"
|
||||
>
|
||||
Neu indexieren
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Upload Tab
|
||||
// ============================================================================
|
||||
|
||||
|
||||
export { CollectionsTab, CollectionCard }
|
||||
|
||||
106
website/app/admin/rag/components/IngestionHistory.tsx
Normal file
106
website/app/admin/rag/components/IngestionHistory.tsx
Normal file
@@ -0,0 +1,106 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import type { IngestionHistoryEntry } from '../types'
|
||||
|
||||
interface IngestionHistoryProps {
|
||||
history: IngestionHistoryEntry[]
|
||||
}
|
||||
|
||||
export function IngestionHistory({ history }: IngestionHistoryProps) {
|
||||
const [showHistory, setShowHistory] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg border border-slate-200 p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold text-slate-900">Indexierungs-Historie</h3>
|
||||
<button
|
||||
onClick={() => setShowHistory(!showHistory)}
|
||||
className="text-sm text-slate-600 hover:text-slate-900 font-medium"
|
||||
>
|
||||
{showHistory ? 'Ausblenden' : `Alle anzeigen (${history.length})`}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{history.length === 0 ? (
|
||||
<p className="text-slate-500 text-sm">Noch keine Indexierungslaeufe durchgefuehrt.</p>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{(showHistory ? history : history.slice(0, 3)).map((entry) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
className={`rounded-lg p-4 ${
|
||||
entry.status === 'success'
|
||||
? 'bg-green-50 border border-green-200'
|
||||
: 'bg-red-50 border border-red-200'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{entry.status === 'success' ? (
|
||||
<svg className="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
)}
|
||||
<span className="font-medium text-slate-900">
|
||||
{new Date(entry.started_at || entry.startedAt).toLocaleString('de-DE')}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-xs text-slate-500 font-mono">{entry.collection}</span>
|
||||
</div>
|
||||
|
||||
{entry.stats && (
|
||||
<div className="grid grid-cols-4 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-slate-500">Gefunden:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.documents_found}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Indexiert:</span>{' '}
|
||||
<span className="font-medium text-green-700">{entry.stats.documents_indexed}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Uebersprungen:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.documents_skipped}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Chunks:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.chunks_created}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{entry.filters && (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{entry.filters.year && (
|
||||
<span className="px-2 py-0.5 bg-slate-200 text-slate-700 text-xs rounded">
|
||||
Jahr: {entry.filters.year}
|
||||
</span>
|
||||
)}
|
||||
{entry.filters.subject && (
|
||||
<span className="px-2 py-0.5 bg-slate-200 text-slate-700 text-xs rounded">
|
||||
Fach: {entry.filters.subject}
|
||||
</span>
|
||||
)}
|
||||
{entry.filters.incremental && (
|
||||
<span className="px-2 py-0.5 bg-blue-100 text-blue-700 text-xs rounded">
|
||||
Inkrementell
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{entry.error && (
|
||||
<p className="mt-2 text-sm text-red-700">{entry.error}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import type {
|
||||
Collection,
|
||||
IngestionStatus,
|
||||
LiveProgress,
|
||||
IndexedStats,
|
||||
PendingFile,
|
||||
PendingFilesData,
|
||||
IngestionHistoryEntry
|
||||
} from '../types'
|
||||
import { IngestionHistory } from './IngestionHistory'
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_KLAUSUR_SERVICE_URL || 'http://localhost:8086'
|
||||
|
||||
@@ -18,117 +17,66 @@ interface IngestionTabProps {
|
||||
onRefresh: () => void
|
||||
}
|
||||
|
||||
function IngestionTab({
|
||||
status,
|
||||
onRefresh
|
||||
}: IngestionTabProps) {
|
||||
function IngestionTab({ status, onRefresh }: IngestionTabProps) {
|
||||
const [starting, setStarting] = useState(false)
|
||||
const [liveProgress, setLiveProgress] = useState<LiveProgress | null>(null)
|
||||
const [indexedStats, setIndexedStats] = useState<IndexedStats | null>(null)
|
||||
const [pendingFiles, setPendingFiles] = useState<PendingFilesData | null>(null)
|
||||
const [ingestionHistory, setIngestionHistory] = useState<IngestionHistoryEntry[]>([])
|
||||
const [showHistory, setShowHistory] = useState(false)
|
||||
const [showPending, setShowPending] = useState(false)
|
||||
|
||||
// Fetch indexed stats, pending files, and history on mount
|
||||
useEffect(() => {
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/nibis/stats`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setIndexedStats(data)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch stats:', err)
|
||||
}
|
||||
try { const res = await fetch(`${API_BASE}/api/v1/admin/nibis/stats`); if (res.ok) setIndexedStats(await res.json()) }
|
||||
catch (err) { console.error('Failed to fetch stats:', err) }
|
||||
}
|
||||
|
||||
const fetchPending = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/rag/files/pending`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setPendingFiles(data)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch pending files:', err)
|
||||
}
|
||||
try { const res = await fetch(`${API_BASE}/api/v1/admin/rag/files/pending`); if (res.ok) setPendingFiles(await res.json()) }
|
||||
catch (err) { console.error('Failed to fetch pending files:', err) }
|
||||
}
|
||||
|
||||
const fetchHistory = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/rag/ingestion/history?limit=20`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setIngestionHistory(data.history || [])
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch history:', err)
|
||||
}
|
||||
try { const res = await fetch(`${API_BASE}/api/v1/admin/rag/ingestion/history?limit=20`); if (res.ok) { const data = await res.json(); setIngestionHistory(data.history || []) } }
|
||||
catch (err) { console.error('Failed to fetch history:', err) }
|
||||
}
|
||||
|
||||
fetchStats()
|
||||
fetchPending()
|
||||
fetchHistory()
|
||||
fetchStats(); fetchPending(); fetchHistory()
|
||||
}, [])
|
||||
|
||||
// Poll for live progress when running
|
||||
useEffect(() => {
|
||||
let interval: NodeJS.Timeout | null = null
|
||||
|
||||
const fetchProgress = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/v1/admin/nibis/progress`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
setLiveProgress(data)
|
||||
// Refresh stats when complete
|
||||
if (!data.running && data.phase === 'complete') {
|
||||
onRefresh()
|
||||
// Also refresh indexed stats
|
||||
const statsRes = await fetch(`${API_BASE}/api/v1/admin/nibis/stats`)
|
||||
if (statsRes.ok) {
|
||||
setIndexedStats(await statsRes.json())
|
||||
}
|
||||
if (statsRes.ok) setIndexedStats(await statsRes.json())
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch progress:', err)
|
||||
}
|
||||
} catch (err) { console.error('Failed to fetch progress:', err) }
|
||||
}
|
||||
|
||||
// Start polling immediately and every 1.5 seconds
|
||||
fetchProgress()
|
||||
interval = setInterval(fetchProgress, 1500)
|
||||
|
||||
return () => {
|
||||
if (interval) clearInterval(interval)
|
||||
}
|
||||
return () => { if (interval) clearInterval(interval) }
|
||||
}, [onRefresh])
|
||||
|
||||
const startIngestion = async () => {
|
||||
setStarting(true)
|
||||
try {
|
||||
await fetch(`${API_BASE}/api/v1/admin/nibis/ingest`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ewh_only: true, incremental: true }),
|
||||
})
|
||||
onRefresh()
|
||||
} catch (err) {
|
||||
console.error('Failed to start ingestion:', err)
|
||||
} finally {
|
||||
setStarting(false)
|
||||
}
|
||||
} catch (err) { console.error('Failed to start ingestion:', err) }
|
||||
finally { setStarting(false) }
|
||||
}
|
||||
|
||||
const phaseLabels: Record<string, string> = {
|
||||
idle: 'Bereit',
|
||||
extracting: 'Entpacke ZIP-Dateien...',
|
||||
discovering: 'Suche Dokumente...',
|
||||
indexing: 'Indexiere Dokumente...',
|
||||
complete: 'Abgeschlossen',
|
||||
idle: 'Bereit', extracting: 'Entpacke ZIP-Dateien...', discovering: 'Suche Dokumente...',
|
||||
indexing: 'Indexiere Dokumente...', complete: 'Abgeschlossen',
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -136,131 +84,58 @@ function IngestionTab({
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-slate-900">Ingestion Status</h2>
|
||||
<p className="text-sm text-slate-500">
|
||||
Übersicht über laufende und vergangene Indexierungsvorgänge
|
||||
</p>
|
||||
<p className="text-sm text-slate-500">Uebersicht ueber laufende und vergangene Indexierungsvorgaenge</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={onRefresh}
|
||||
className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50"
|
||||
>
|
||||
Aktualisieren
|
||||
</button>
|
||||
<button
|
||||
onClick={startIngestion}
|
||||
disabled={status?.running || starting}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<button onClick={onRefresh} className="px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50">Aktualisieren</button>
|
||||
<button onClick={startIngestion} disabled={status?.running || starting} className="px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
{starting ? 'Startet...' : 'Ingestion starten'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Live Progress (when running) */}
|
||||
{/* Live Progress */}
|
||||
{liveProgress?.running && (
|
||||
<div className="bg-primary-50 rounded-lg border border-primary-200 p-6">
|
||||
<div className="flex items-center gap-4 mb-4">
|
||||
<div className="w-3 h-3 bg-primary-500 rounded-full animate-pulse"></div>
|
||||
<span className="text-lg font-medium text-primary-900">
|
||||
{liveProgress.phase ? (phaseLabels[liveProgress.phase] || liveProgress.phase) : 'Läuft...'}
|
||||
</span>
|
||||
<span className="ml-auto text-sm text-primary-700 font-mono">
|
||||
{(liveProgress.percent ?? 0).toFixed(1)}%
|
||||
</span>
|
||||
<span className="text-lg font-medium text-primary-900">{liveProgress.phase ? (phaseLabels[liveProgress.phase] || liveProgress.phase) : 'Laeuft...'}</span>
|
||||
<span className="ml-auto text-sm text-primary-700 font-mono">{(liveProgress.percent ?? 0).toFixed(1)}%</span>
|
||||
</div>
|
||||
|
||||
{/* Progress Bar */}
|
||||
<div className="h-3 bg-primary-200 rounded-full overflow-hidden mb-4">
|
||||
<div
|
||||
className="h-full bg-primary-600 transition-all duration-300"
|
||||
style={{ width: `${liveProgress.percent ?? 0}%` }}
|
||||
/>
|
||||
<div className="h-full bg-primary-600 transition-all duration-300" style={{ width: `${liveProgress.percent ?? 0}%` }} />
|
||||
</div>
|
||||
|
||||
{/* Current File */}
|
||||
{liveProgress.current_filename && (
|
||||
<p className="text-sm text-primary-700 mb-4 truncate">
|
||||
<span className="font-medium">[{liveProgress.current_doc}/{liveProgress.total_docs}]</span>{' '}
|
||||
{liveProgress.current_filename}
|
||||
<span className="font-medium">[{liveProgress.current_doc}/{liveProgress.total_docs}]</span> {liveProgress.current_filename}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Live Stats */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
|
||||
<div className="bg-white/50 rounded p-2">
|
||||
<p className="text-primary-600 text-xs uppercase">Indexiert</p>
|
||||
<p className="text-lg font-semibold text-primary-900">{liveProgress.documents_indexed}</p>
|
||||
</div>
|
||||
<div className="bg-white/50 rounded p-2">
|
||||
<p className="text-primary-600 text-xs uppercase">Übersprungen</p>
|
||||
<p className="text-lg font-semibold text-primary-900">{liveProgress.documents_skipped}</p>
|
||||
</div>
|
||||
<div className="bg-white/50 rounded p-2">
|
||||
<p className="text-primary-600 text-xs uppercase">Chunks</p>
|
||||
<p className="text-lg font-semibold text-primary-900">{liveProgress.chunks_created}</p>
|
||||
</div>
|
||||
<div className="bg-white/50 rounded p-2">
|
||||
<p className="text-primary-600 text-xs uppercase">Fehler</p>
|
||||
<p className={`text-lg font-semibold ${(liveProgress.errors_count ?? 0) > 0 ? 'text-red-600' : 'text-primary-900'}`}>
|
||||
{liveProgress.errors_count ?? 0}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-white/50 rounded p-2"><p className="text-primary-600 text-xs uppercase">Indexiert</p><p className="text-lg font-semibold text-primary-900">{liveProgress.documents_indexed}</p></div>
|
||||
<div className="bg-white/50 rounded p-2"><p className="text-primary-600 text-xs uppercase">Uebersprungen</p><p className="text-lg font-semibold text-primary-900">{liveProgress.documents_skipped}</p></div>
|
||||
<div className="bg-white/50 rounded p-2"><p className="text-primary-600 text-xs uppercase">Chunks</p><p className="text-lg font-semibold text-primary-900">{liveProgress.chunks_created}</p></div>
|
||||
<div className="bg-white/50 rounded p-2"><p className="text-primary-600 text-xs uppercase">Fehler</p><p className={`text-lg font-semibold ${(liveProgress.errors_count ?? 0) > 0 ? 'text-red-600' : 'text-primary-900'}`}>{liveProgress.errors_count ?? 0}</p></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Indexed Data Overview - Always visible */}
|
||||
{/* Indexed Data Overview */}
|
||||
{indexedStats?.indexed && (
|
||||
<div className="bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border border-green-200 p-6">
|
||||
<h3 className="text-lg font-semibold text-green-900 mb-4 flex items-center gap-2">
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>
|
||||
Indexierte Daten (Gesamt)
|
||||
</h3>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-6 mb-4">
|
||||
<div className="bg-white/60 rounded-lg p-3">
|
||||
<p className="text-xs text-green-700 uppercase tracking-wider">Chunks gesamt</p>
|
||||
<p className="text-2xl font-bold text-green-900">
|
||||
{(indexedStats.total_chunks ?? 0).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-white/60 rounded-lg p-3">
|
||||
<p className="text-xs text-green-700 uppercase tracking-wider">Jahre</p>
|
||||
<p className="text-2xl font-bold text-green-900">
|
||||
{indexedStats.years?.length ?? 0}
|
||||
</p>
|
||||
<p className="text-xs text-green-600 mt-1">
|
||||
{(indexedStats.years?.length ?? 0) > 0
|
||||
? `${Math.min(...indexedStats.years!)} - ${Math.max(...indexedStats.years!)}`
|
||||
: '-'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-white/60 rounded-lg p-3">
|
||||
<p className="text-xs text-green-700 uppercase tracking-wider">Fächer</p>
|
||||
<p className="text-2xl font-bold text-green-900">
|
||||
{indexedStats.subjects?.length || 0}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-white/60 rounded-lg p-3">
|
||||
<p className="text-xs text-green-700 uppercase tracking-wider">Status</p>
|
||||
<p className="text-lg font-bold text-green-600">Bereit</p>
|
||||
</div>
|
||||
<div className="bg-white/60 rounded-lg p-3"><p className="text-xs text-green-700 uppercase tracking-wider">Chunks gesamt</p><p className="text-2xl font-bold text-green-900">{(indexedStats.total_chunks ?? 0).toLocaleString()}</p></div>
|
||||
<div className="bg-white/60 rounded-lg p-3"><p className="text-xs text-green-700 uppercase tracking-wider">Jahre</p><p className="text-2xl font-bold text-green-900">{indexedStats.years?.length ?? 0}</p><p className="text-xs text-green-600 mt-1">{(indexedStats.years?.length ?? 0) > 0 ? `${Math.min(...indexedStats.years!)} - ${Math.max(...indexedStats.years!)}` : '-'}</p></div>
|
||||
<div className="bg-white/60 rounded-lg p-3"><p className="text-xs text-green-700 uppercase tracking-wider">Faecher</p><p className="text-2xl font-bold text-green-900">{indexedStats.subjects?.length || 0}</p></div>
|
||||
<div className="bg-white/60 rounded-lg p-3"><p className="text-xs text-green-700 uppercase tracking-wider">Status</p><p className="text-lg font-bold text-green-600">Bereit</p></div>
|
||||
</div>
|
||||
|
||||
{/* Years breakdown */}
|
||||
{indexedStats.years && indexedStats.years.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{indexedStats.years.sort((a, b) => a - b).map((year) => (
|
||||
<span
|
||||
key={year}
|
||||
className="px-3 py-1 bg-white/80 text-green-800 text-sm rounded-full font-medium"
|
||||
>
|
||||
{year}
|
||||
</span>
|
||||
<span key={year} className="px-3 py-1 bg-white/80 text-green-800 text-sm rounded-full font-medium">{year}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
@@ -271,63 +146,27 @@ function IngestionTab({
|
||||
{!liveProgress?.running && (
|
||||
<div className="bg-white rounded-lg border border-slate-200 p-6">
|
||||
<h3 className="text-sm font-medium text-slate-700 mb-4">Letzter Indexierungslauf</h3>
|
||||
|
||||
<div className="flex items-center gap-4 mb-4">
|
||||
<div className="w-3 h-3 bg-green-500 rounded-full"></div>
|
||||
<span className="text-lg font-medium text-slate-900">
|
||||
{liveProgress?.phase === 'complete' ? 'Abgeschlossen' : 'Bereit'}
|
||||
</span>
|
||||
<span className="text-lg font-medium text-slate-900">{liveProgress?.phase === 'complete' ? 'Abgeschlossen' : 'Bereit'}</span>
|
||||
</div>
|
||||
|
||||
{status && (
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-6">
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Zeitpunkt</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{status.lastRun
|
||||
? new Date(status.lastRun).toLocaleString('de-DE')
|
||||
: 'Noch nie'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Neu indexiert</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{status.documentsIndexed ?? '-'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Neue Chunks</p>
|
||||
<p className="text-lg font-semibold text-slate-900">
|
||||
{status.chunksCreated ?? '-'}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-slate-500 uppercase tracking-wider">Fehler</p>
|
||||
<p className={`text-lg font-semibold ${status.errors.length > 0 ? 'text-red-600' : 'text-slate-900'}`}>
|
||||
{status.errors.length}
|
||||
</p>
|
||||
</div>
|
||||
<div><p className="text-xs text-slate-500 uppercase tracking-wider">Zeitpunkt</p><p className="text-lg font-semibold text-slate-900">{status.lastRun ? new Date(status.lastRun).toLocaleString('de-DE') : 'Noch nie'}</p></div>
|
||||
<div><p className="text-xs text-slate-500 uppercase tracking-wider">Neu indexiert</p><p className="text-lg font-semibold text-slate-900">{status.documentsIndexed ?? '-'}</p></div>
|
||||
<div><p className="text-xs text-slate-500 uppercase tracking-wider">Neue Chunks</p><p className="text-lg font-semibold text-slate-900">{status.chunksCreated ?? '-'}</p></div>
|
||||
<div><p className="text-xs text-slate-500 uppercase tracking-wider">Fehler</p><p className={`text-lg font-semibold ${status.errors.length > 0 ? 'text-red-600' : 'text-slate-900'}`}>{status.errors.length}</p></div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Show skipped info from live progress */}
|
||||
{liveProgress && (liveProgress.documents_skipped ?? 0) > 0 && (
|
||||
<p className="mt-3 text-sm text-slate-500">
|
||||
{liveProgress.documents_skipped} Dokumente übersprungen (bereits indexiert)
|
||||
</p>
|
||||
<p className="mt-3 text-sm text-slate-500">{liveProgress.documents_skipped} Dokumente uebersprungen (bereits indexiert)</p>
|
||||
)}
|
||||
|
||||
{status?.errors && status.errors.length > 0 && (
|
||||
<div className="mt-4 p-4 bg-red-50 rounded-lg">
|
||||
<h4 className="text-sm font-medium text-red-800 mb-2">Fehler</h4>
|
||||
<ul className="text-sm text-red-700 space-y-1">
|
||||
{status.errors.slice(0, 5).map((error, i) => (
|
||||
<li key={i}>{error}</li>
|
||||
))}
|
||||
{status.errors.length > 5 && (
|
||||
<li className="text-red-500">... und {status.errors.length - 5} weitere</li>
|
||||
)}
|
||||
{status.errors.slice(0, 5).map((error, i) => <li key={i}>{error}</li>)}
|
||||
{status.errors.length > 5 && <li className="text-red-500">... und {status.errors.length - 5} weitere</li>}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
@@ -339,174 +178,40 @@ function IngestionTab({
|
||||
<div className="bg-amber-50 rounded-lg border border-amber-200 p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<svg className="w-6 h-6 text-amber-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
</svg>
|
||||
<svg className="w-6 h-6 text-amber-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-amber-900">
|
||||
{pendingFiles.pending_count} Dateien warten auf Indexierung
|
||||
</h3>
|
||||
<p className="text-sm text-amber-700">
|
||||
{pendingFiles.indexed_count} von {pendingFiles.total_files} Dateien sind indexiert
|
||||
</p>
|
||||
<h3 className="text-lg font-semibold text-amber-900">{pendingFiles.pending_count} Dateien warten auf Indexierung</h3>
|
||||
<p className="text-sm text-amber-700">{pendingFiles.indexed_count} von {pendingFiles.total_files} Dateien sind indexiert</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShowPending(!showPending)}
|
||||
className="text-sm text-amber-700 hover:text-amber-900 font-medium"
|
||||
>
|
||||
{showPending ? 'Ausblenden' : 'Details anzeigen'}
|
||||
</button>
|
||||
<button onClick={() => setShowPending(!showPending)} className="text-sm text-amber-700 hover:text-amber-900 font-medium">{showPending ? 'Ausblenden' : 'Details anzeigen'}</button>
|
||||
</div>
|
||||
|
||||
{/* Pending by year summary */}
|
||||
{pendingFiles.by_year && Object.keys(pendingFiles.by_year).length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
{Object.entries(pendingFiles.by_year)
|
||||
.sort(([a], [b]) => Number(b) - Number(a))
|
||||
.map(([year, count]) => (
|
||||
<span
|
||||
key={year}
|
||||
className="px-3 py-1 bg-amber-100 text-amber-800 text-sm rounded-full font-medium"
|
||||
>
|
||||
{year}: {count} Dateien
|
||||
</span>
|
||||
))}
|
||||
{Object.entries(pendingFiles.by_year).sort(([a], [b]) => Number(b) - Number(a)).map(([year, count]) => (
|
||||
<span key={year} className="px-3 py-1 bg-amber-100 text-amber-800 text-sm rounded-full font-medium">{year}: {count} Dateien</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pending files list */}
|
||||
{showPending && pendingFiles.pending_files && (
|
||||
<div className="mt-4 max-h-64 overflow-y-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="text-left text-amber-700 border-b border-amber-200">
|
||||
<tr>
|
||||
<th className="pb-2">Dateiname</th>
|
||||
<th className="pb-2">Jahr</th>
|
||||
<th className="pb-2">Fach</th>
|
||||
<th className="pb-2">Niveau</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<thead className="text-left text-amber-700 border-b border-amber-200"><tr><th className="pb-2">Dateiname</th><th className="pb-2">Jahr</th><th className="pb-2">Fach</th><th className="pb-2">Niveau</th></tr></thead>
|
||||
<tbody className="divide-y divide-amber-100">
|
||||
{pendingFiles.pending_files.map((file) => (
|
||||
<tr key={file.id} className="text-amber-900">
|
||||
<td className="py-2 font-mono text-xs">{file.filename}</td>
|
||||
<td className="py-2">{file.year}</td>
|
||||
<td className="py-2">{file.subject}</td>
|
||||
<td className="py-2">{file.niveau}</td>
|
||||
</tr>
|
||||
<tr key={file.id} className="text-amber-900"><td className="py-2 font-mono text-xs">{file.filename}</td><td className="py-2">{file.year}</td><td className="py-2">{file.subject}</td><td className="py-2">{file.niveau}</td></tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{(pendingFiles.pending_count ?? 0) > 100 && (
|
||||
<p className="mt-2 text-xs text-amber-600">
|
||||
Zeige 100 von {pendingFiles.pending_count} Dateien
|
||||
</p>
|
||||
)}
|
||||
{(pendingFiles.pending_count ?? 0) > 100 && <p className="mt-2 text-xs text-amber-600">Zeige 100 von {pendingFiles.pending_count} Dateien</p>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Ingestion History Section */}
|
||||
<div className="bg-white rounded-lg border border-slate-200 p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold text-slate-900">Indexierungs-Historie</h3>
|
||||
<button
|
||||
onClick={() => setShowHistory(!showHistory)}
|
||||
className="text-sm text-slate-600 hover:text-slate-900 font-medium"
|
||||
>
|
||||
{showHistory ? 'Ausblenden' : `Alle anzeigen (${ingestionHistory.length})`}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{ingestionHistory.length === 0 ? (
|
||||
<p className="text-slate-500 text-sm">Noch keine Indexierungsläufe durchgeführt.</p>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{(showHistory ? ingestionHistory : ingestionHistory.slice(0, 3)).map((entry) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
className={`rounded-lg p-4 ${
|
||||
entry.status === 'success'
|
||||
? 'bg-green-50 border border-green-200'
|
||||
: 'bg-red-50 border border-red-200'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
{entry.status === 'success' ? (
|
||||
<svg className="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
)}
|
||||
<span className="font-medium text-slate-900">
|
||||
{new Date(entry.started_at || entry.startedAt).toLocaleString('de-DE')}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-xs text-slate-500 font-mono">{entry.collection}</span>
|
||||
</div>
|
||||
|
||||
{entry.stats && (
|
||||
<div className="grid grid-cols-4 gap-4 text-sm">
|
||||
<div>
|
||||
<span className="text-slate-500">Gefunden:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.documents_found}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Indexiert:</span>{' '}
|
||||
<span className="font-medium text-green-700">{entry.stats.documents_indexed}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Übersprungen:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.documents_skipped}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Chunks:</span>{' '}
|
||||
<span className="font-medium">{entry.stats.chunks_created}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{entry.filters && (
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{entry.filters.year && (
|
||||
<span className="px-2 py-0.5 bg-slate-200 text-slate-700 text-xs rounded">
|
||||
Jahr: {entry.filters.year}
|
||||
</span>
|
||||
)}
|
||||
{entry.filters.subject && (
|
||||
<span className="px-2 py-0.5 bg-slate-200 text-slate-700 text-xs rounded">
|
||||
Fach: {entry.filters.subject}
|
||||
</span>
|
||||
)}
|
||||
{entry.filters.incremental && (
|
||||
<span className="px-2 py-0.5 bg-blue-100 text-blue-700 text-xs rounded">
|
||||
Inkrementell
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{entry.error && (
|
||||
<p className="mt-2 text-sm text-red-700">{entry.error}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<IngestionHistory history={ingestionHistory} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Documents Tab
|
||||
// ============================================================================
|
||||
|
||||
|
||||
export { IngestionTab }
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
* RAG Admin Page Components
|
||||
*/
|
||||
|
||||
export { CollectionsTab, CollectionCard } from './CollectionsTab'
|
||||
export { CollectionsTab } from './CollectionsTab'
|
||||
export { CollectionCard } from './CollectionCard'
|
||||
export { UploadTab } from './UploadTab'
|
||||
export { IngestionTab } from './IngestionTab'
|
||||
export { DocumentsTab } from './DocumentsTab'
|
||||
|
||||
Reference in New Issue
Block a user