Document Superadmin API for AI Skill Retrieval Profiles and Update Access Layer
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Has been cancelled
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Has been cancelled
- Added documentation for the new Superadmin CRUD endpoints for managing AI Skill Retrieval Profiles (`/api/admin/ai-skill-retrieval-profiles*`). - Updated the ACCESS_LAYER_ENDPOINT_AUDIT.md to include the new Superadmin API and its exempt status. - Registered the ai_skill_retrieval_admin router in the backend and updated versioning to reflect the changes. - Enhanced the frontend with a new Admin page for AI Skill Retrieval, including navigation and API integration for profile management.
This commit is contained in:
1 parent
294b09a5d9
commit
286c36e9d7
11 files changed
+871
-10
No files matched your search
@@ -54,6 +54,7 @@ const AdminUsersPage = lazy(() => import('./pages/AdminUsersPage'))
|
||||
const MediaLibraryPage = lazy(() => import('./pages/MediaLibraryPage'))
|
||||
const LegalPage = lazy(() => import('./pages/LegalPage'))
|
||||
const AdminLegalDocumentsPage = lazy(() => import('./pages/AdminLegalDocumentsPage'))
|
||||
const AdminAiSkillRetrievalPage = lazy(() => import('./pages/AdminAiSkillRetrievalPage'))
|
||||
const SettingsLegalPage = lazy(() => import('./pages/SettingsLegalPage'))
|
||||
|
||||
/** Shield „Admin“: nur Super-Admin (global). Vereinsorga: Vereine → Mitglieder. */
|
||||
@@ -300,6 +301,14 @@ const appRouter = createBrowserRouter([
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/ai-skill-retrieval',
|
||||
element: (
|
||||
<PlatformAdminRoute>
|
||||
<AdminAiSkillRetrievalPage />
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{ path: 'trainer-contexts', element: <TrainerContextsPage /> },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale } from 'lucide-react'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale, Brain } from 'lucide-react'
|
||||
|
||||
/**
|
||||
* Admin-Seiten-Navigation (horizontal) — nur für Super-Admins (globaler Portal-Mandant).
|
||||
@@ -12,6 +12,7 @@ export default function AdminPageNav() {
|
||||
{ to: '/admin/catalogs', label: 'Kataloge', icon: FolderTree },
|
||||
{ to: '/admin/mediawiki-import', label: 'Wiki-Import', icon: Download },
|
||||
{ to: '/admin/legal-documents', label: 'Rechtstexte', icon: Scale },
|
||||
{ to: '/admin/ai-skill-retrieval', label: 'KI Retrieval', icon: Brain },
|
||||
]
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,435 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
import AdminPageNav from '../components/AdminPageNav'
|
||||
|
||||
/** Startvorlage — alle Schlüssel optional; Fehlwerte nutzen Fallbacks in exercise_ai (siehe Spec). */
|
||||
const DEFAULT_CONFIG_JSON = `{
|
||||
"version": 1,
|
||||
"importance_multiplier": 1,
|
||||
"text_overlap_bonus": 2,
|
||||
"main_slug_weights": { "karate": 1, "allgemeine": 1 },
|
||||
"category_slug_weights": {},
|
||||
"category_max_share": {},
|
||||
"main_min_share": {},
|
||||
"description_plain_max_len": 160,
|
||||
"karate_relevance_max_len": 72,
|
||||
"keyword_overrides": []
|
||||
}`
|
||||
|
||||
function parseConfigObject(text) {
|
||||
const t = text.trim()
|
||||
if (!t) return {}
|
||||
const parsed = JSON.parse(t)
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
throw new Error('Config muss ein JSON-Objekt sein.')
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
function formatDt(iso) {
|
||||
if (!iso) return ''
|
||||
try {
|
||||
const d = new Date(iso)
|
||||
if (Number.isNaN(d.getTime())) return String(iso)
|
||||
return d.toLocaleString('de-DE', { dateStyle: 'short', timeStyle: 'short' })
|
||||
} catch {
|
||||
return String(iso)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pflege von ai_skill_retrieval_profiles (KI Skill-Katalog Gewichte/Quoten).
|
||||
* Nur Superadmin — Routen-Spiegel: PlatformAdminRoute.
|
||||
*/
|
||||
export default function AdminAiSkillRetrievalPage() {
|
||||
const { user } = useAuth()
|
||||
const isSuperadmin = user?.role === 'superadmin'
|
||||
|
||||
const [profiles, setProfiles] = useState([])
|
||||
const [focusAreas, setFocusAreas] = useState([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const [editor, setEditor] = useState(null)
|
||||
|
||||
const loadAll = useCallback(async () => {
|
||||
const [p, faRaw] = await Promise.all([
|
||||
api.listAiSkillRetrievalProfiles(),
|
||||
api.listFocusAreas(),
|
||||
])
|
||||
setProfiles(Array.isArray(p) ? p : [])
|
||||
const fa = Array.isArray(faRaw) ? faRaw : []
|
||||
setFocusAreas(fa.filter((a) => !a.status || String(a.status).toLowerCase() === 'active'))
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSuperadmin) return
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e.message || String(e))
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [isSuperadmin, loadAll])
|
||||
|
||||
const openNew = () => {
|
||||
setEditor({
|
||||
mode: 'new',
|
||||
isDefault: false,
|
||||
focusAreaId: '',
|
||||
name: '',
|
||||
description: '',
|
||||
active: true,
|
||||
configJson: DEFAULT_CONFIG_JSON,
|
||||
})
|
||||
}
|
||||
|
||||
const openEdit = (row) => {
|
||||
setEditor({
|
||||
mode: 'edit',
|
||||
id: row.id,
|
||||
originalIsDefault: !!row.is_default,
|
||||
isDefault: !!row.is_default,
|
||||
promoteToDefault: false,
|
||||
focusAreaId: row.focus_area_id != null ? String(row.focus_area_id) : '',
|
||||
name: row.name || '',
|
||||
description: row.description || '',
|
||||
active: !!row.active,
|
||||
configJson: JSON.stringify(row.config && typeof row.config === 'object' ? row.config : {}, null, 2),
|
||||
})
|
||||
}
|
||||
|
||||
const closeEditor = () => setEditor(null)
|
||||
|
||||
const save = async () => {
|
||||
if (!editor) return
|
||||
let cfg
|
||||
try {
|
||||
cfg = parseConfigObject(editor.configJson)
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
return
|
||||
}
|
||||
|
||||
const name = editor.name.trim()
|
||||
if (name.length < 2) {
|
||||
alert('Name mindestens 2 Zeichen.')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (editor.mode === 'new') {
|
||||
const body = {
|
||||
name,
|
||||
description: (editor.description || '').trim(),
|
||||
active: editor.active,
|
||||
is_default: editor.isDefault,
|
||||
config: cfg,
|
||||
}
|
||||
if (!editor.isDefault) {
|
||||
const fid = parseInt(editor.focusAreaId, 10)
|
||||
if (!fid) {
|
||||
alert('Fokusbereich wählen (oder „Standardprofil“ aktivieren).')
|
||||
return
|
||||
}
|
||||
body.focus_area_id = fid
|
||||
}
|
||||
await api.createAiSkillRetrievalProfile(body)
|
||||
} else {
|
||||
const body = {
|
||||
name,
|
||||
description: (editor.description || '').trim(),
|
||||
active: editor.active,
|
||||
config: cfg,
|
||||
}
|
||||
if (editor.originalIsDefault) {
|
||||
await api.updateAiSkillRetrievalProfile(editor.id, body)
|
||||
} else {
|
||||
if (editor.promoteToDefault) {
|
||||
body.is_default = true
|
||||
} else {
|
||||
const fid = parseInt(editor.focusAreaId, 10)
|
||||
if (!fid) {
|
||||
alert('Fokusbereich wählen oder „Als Standardprofil setzen“ aktivieren.')
|
||||
return
|
||||
}
|
||||
body.focus_area_id = fid
|
||||
}
|
||||
await api.updateAiSkillRetrievalProfile(editor.id, body)
|
||||
}
|
||||
}
|
||||
closeEditor()
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
const remove = async (row) => {
|
||||
if (row.is_default) return
|
||||
if (!confirm(`Profil „${row.name}“ wirklich löschen?`)) return
|
||||
try {
|
||||
await api.deleteAiSkillRetrievalProfile(row.id)
|
||||
await loadAll()
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuperadmin) return <Navigate to="/" replace />
|
||||
|
||||
return (
|
||||
<div className="app-page">
|
||||
<AdminPageNav />
|
||||
|
||||
<h1 style={{ marginTop: 0 }}>KI Skill-Retrieval-Profile</h1>
|
||||
<p style={{ color: 'var(--text2)', maxWidth: '52rem', lineHeight: 1.55, marginBottom: '1rem' }}>
|
||||
Konfiguration für den Skill-Katalog-Kontext bei <strong>Übungs-KI</strong> (OpenRouter).
|
||||
Standardprofil ohne Fokusbereich; weitere Zeilen je <strong>aktivem</strong> Fokusbereich.
|
||||
JSON-Feld <code>config</code> siehe{' '}
|
||||
<code style={{ fontSize: '0.88em' }}>.claude/docs/working/AI_SKILL_RETRIEVAL_PROFILES_SPEC.md</code>.
|
||||
</p>
|
||||
|
||||
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap', marginBottom: '1rem' }}>
|
||||
<button type="button" className="btn btn-primary" onClick={openNew}>
|
||||
Neues Profil
|
||||
</button>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => loadAll().catch((e) => setError(e.message))}>
|
||||
Aktualisieren
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="card" style={{ padding: '12px 16px', marginBottom: '1rem', borderColor: 'var(--danger)' }}>
|
||||
<strong style={{ color: 'var(--danger)' }}>Fehler</strong>
|
||||
<div style={{ marginTop: '0.35rem', whiteSpace: 'pre-wrap' }}>{error}</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="spinner" style={{ margin: '2rem auto' }} />
|
||||
) : (
|
||||
<div className="card" style={{ padding: 0, overflow: 'auto' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: '0.92rem' }}>
|
||||
<thead>
|
||||
<tr style={{ textAlign: 'left', borderBottom: '1px solid var(--border)' }}>
|
||||
<th style={{ padding: '10px 12px' }}>Name</th>
|
||||
<th style={{ padding: '10px 12px' }}>Typ</th>
|
||||
<th style={{ padding: '10px 12px' }}>Fokusbereich</th>
|
||||
<th style={{ padding: '10px 12px' }}>Aktiv</th>
|
||||
<th style={{ padding: '10px 12px' }}>Geändert</th>
|
||||
<th style={{ padding: '10px 12px', width: '1%' }} />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{profiles.map((row) => (
|
||||
<tr key={row.id} style={{ borderBottom: '1px solid var(--border)' }}>
|
||||
<td style={{ padding: '10px 12px', fontWeight: 600 }}>{row.name}</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.is_default ? 'Standard' : 'Fokus'}</td>
|
||||
<td style={{ padding: '10px 12px', color: 'var(--text2)' }}>
|
||||
{row.is_default ? '—' : row.focus_area_name || `(ID ${row.focus_area_id})`}
|
||||
</td>
|
||||
<td style={{ padding: '10px 12px' }}>{row.active ? 'ja' : 'nein'}</td>
|
||||
<td style={{ padding: '10px 12px', color: 'var(--text3)' }}>{formatDt(row.updated_at)}</td>
|
||||
<td style={{ padding: '10px 12px', whiteSpace: 'nowrap' }}>
|
||||
<button type="button" className="btn btn-secondary" style={{ marginRight: 6 }} onClick={() => openEdit(row)}>
|
||||
Bearbeiten
|
||||
</button>
|
||||
{!row.is_default ? (
|
||||
<button type="button" className="btn btn-secondary" onClick={() => remove(row)}>
|
||||
Löschen
|
||||
</button>
|
||||
) : null}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{profiles.length === 0 ? (
|
||||
<div style={{ padding: '1.25rem', color: 'var(--text3)' }}>Keine Einträge (oder Tabelle/Migration 068 fehlt).</div>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{editor && (
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
inset: 0,
|
||||
background: 'rgba(0,0,0,0.5)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
zIndex: 1200,
|
||||
padding: '1rem',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
maxWidth: '640px',
|
||||
width: '100%',
|
||||
maxHeight: '90vh',
|
||||
overflow: 'auto',
|
||||
padding: '1.25rem 1.5rem',
|
||||
}}
|
||||
>
|
||||
<h2 style={{ marginTop: 0 }}>{editor.mode === 'new' ? 'Neues Profil' : 'Profil bearbeiten'}</h2>
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor="arp-name">
|
||||
Name
|
||||
</label>
|
||||
<input
|
||||
id="arp-name"
|
||||
className="form-input"
|
||||
value={editor.name}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, name: e.target.value } : ed))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor="arp-desc">
|
||||
Beschreibung
|
||||
</label>
|
||||
<textarea
|
||||
id="arp-desc"
|
||||
className="form-input"
|
||||
rows={3}
|
||||
value={editor.description}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, description: e.target.value } : ed))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{editor.mode === 'new' ? (
|
||||
<div className="form-row">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={editor.isDefault}
|
||||
onChange={(e) =>
|
||||
setEditor((ed) =>
|
||||
ed ? { ...ed, isDefault: e.target.checked, focusAreaId: e.target.checked ? '' : ed.focusAreaId } : ed
|
||||
)
|
||||
}
|
||||
/>
|
||||
Standardprofil (ohne Fokusbereich)
|
||||
</label>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{editor.mode === 'edit' && editor.originalIsDefault ? (
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>
|
||||
Standardprofil: Fokusbereich ist immer leer; Deaktivieren ist nicht erlaubt.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{editor.mode === 'edit' && !editor.originalIsDefault ? (
|
||||
<div className="form-row">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!editor.promoteToDefault}
|
||||
onChange={(e) =>
|
||||
setEditor((ed) =>
|
||||
ed ? { ...ed, promoteToDefault: e.target.checked, focusAreaId: e.target.checked ? '' : ed.focusAreaId } : ed
|
||||
)
|
||||
}
|
||||
/>
|
||||
Als Standardprofil setzen (andere Standard-Markierung wird entfernt)
|
||||
</label>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{!editor.isDefault && editor.mode === 'new' ? (
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor="arp-focus">
|
||||
Fokusbereich
|
||||
</label>
|
||||
<select
|
||||
id="arp-focus"
|
||||
className="form-input"
|
||||
value={editor.focusAreaId}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, focusAreaId: e.target.value } : ed))}
|
||||
>
|
||||
<option value="">— wählen —</option>
|
||||
{focusAreas.map((fa) => (
|
||||
<option key={fa.id} value={String(fa.id)}>
|
||||
{fa.name || `Fokus ${fa.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{editor.mode === 'edit' && !editor.originalIsDefault && !editor.promoteToDefault ? (
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor="arp-focus-e">
|
||||
Fokusbereich
|
||||
</label>
|
||||
<select
|
||||
id="arp-focus-e"
|
||||
className="form-input"
|
||||
value={editor.focusAreaId}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, focusAreaId: e.target.value } : ed))}
|
||||
>
|
||||
<option value="">— wählen —</option>
|
||||
{focusAreas.map((fa) => (
|
||||
<option key={fa.id} value={String(fa.id)}>
|
||||
{fa.name || `Fokus ${fa.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="form-row">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', cursor: 'pointer' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={editor.active}
|
||||
disabled={editor.mode === 'edit' && editor.originalIsDefault}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, active: e.target.checked } : ed))}
|
||||
/>
|
||||
Aktiv
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor="arp-config">
|
||||
Config (JSON)
|
||||
</label>
|
||||
<textarea
|
||||
id="arp-config"
|
||||
className="form-input"
|
||||
style={{ fontFamily: 'ui-monospace, monospace', fontSize: '0.82rem', minHeight: '220px' }}
|
||||
value={editor.configJson}
|
||||
onChange={(e) => setEditor((ed) => (ed ? { ...ed, configJson: e.target.value } : ed))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: '0.5rem', marginTop: '1rem', flexWrap: 'wrap' }}>
|
||||
<button type="button" className="btn btn-primary" style={{ flex: '1 1 120px' }} onClick={save}>
|
||||
Speichern
|
||||
</button>
|
||||
<button type="button" className="btn btn-secondary" onClick={closeEditor}>
|
||||
Abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -361,6 +361,33 @@ export async function getAdminHierarchy() {
|
||||
return request('/api/admin/hierarchy')
|
||||
}
|
||||
|
||||
// Superadmin: KI Skill-Retrieval-Profile (Migration 068, exercise_ai)
|
||||
export async function listAiSkillRetrievalProfiles() {
|
||||
return request('/api/admin/ai-skill-retrieval-profiles')
|
||||
}
|
||||
|
||||
export async function getAiSkillRetrievalProfile(profileId) {
|
||||
return request(`/api/admin/ai-skill-retrieval-profiles/${profileId}`)
|
||||
}
|
||||
|
||||
export async function createAiSkillRetrievalProfile(data) {
|
||||
return request('/api/admin/ai-skill-retrieval-profiles', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateAiSkillRetrievalProfile(profileId, data) {
|
||||
return request(`/api/admin/ai-skill-retrieval-profiles/${profileId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteAiSkillRetrievalProfile(profileId) {
|
||||
return request(`/api/admin/ai-skill-retrieval-profiles/${profileId}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Reifegradmodelle / Fähigkeitsmatrix
|
||||
// ============================================================================
|
||||
@@ -764,6 +791,11 @@ export const api = {
|
||||
updateFocusArea,
|
||||
deleteFocusArea,
|
||||
getAdminHierarchy,
|
||||
listAiSkillRetrievalProfiles,
|
||||
getAiSkillRetrievalProfile,
|
||||
createAiSkillRetrievalProfile,
|
||||
updateAiSkillRetrievalProfile,
|
||||
deleteAiSkillRetrievalProfile,
|
||||
listStyleDirections,
|
||||
listTrainingStyles,
|
||||
createStyleDirection,
|
||||
|
||||
Reference in new issue
Block a user