Let superadmins choose the OpenRouter model from the live catalog.
Deploy Development / deploy (push) Successful in 1m0s
Test Suite / pytest-backend (push) Successful in 50s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 20s
Test Suite / k6 /health Baseline (push) Successful in 36s
Test Suite / playwright-tests (push) Failing after 7m52s
Deploy Development / deploy (push) Successful in 1m0s
Test Suite / pytest-backend (push) Successful in 50s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 20s
Test Suite / k6 /health Baseline (push) Successful in 36s
Test Suite / playwright-tests (push) Failing after 7m52s
The platform default can be replaced in the admin UI when a model is no longer available, without editing OPENROUTER_MODEL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1bdb039a91
commit
f49de9c971
21 files changed
+1246
-35
No files matched your search
@@ -64,6 +64,7 @@ const LegalPage = lazy(() => import('./pages/LegalPage'))
|
||||
const AdminLegalDocumentsPage = lazy(() => import('./pages/AdminLegalDocumentsPage'))
|
||||
const AdminAiSkillRetrievalPage = lazy(() => import('./pages/AdminAiSkillRetrievalPage'))
|
||||
const AdminAiPromptsPage = lazy(() => import('./pages/AdminAiPromptsPage'))
|
||||
const AdminOpenRouterPage = lazy(() => import('./pages/AdminOpenRouterPage'))
|
||||
const AdminExerciseEnrichmentPage = lazy(() => import('./pages/AdminExerciseEnrichmentPage'))
|
||||
const AdminUserContentPage = lazy(() => import('./pages/AdminUserContentPage'))
|
||||
const SettingsLegalPage = lazy(() => import('./pages/SettingsLegalPage'))
|
||||
@@ -387,6 +388,14 @@ const appRouter = createBrowserRouter([
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/openrouter',
|
||||
element: (
|
||||
<PlatformAdminRoute>
|
||||
<AdminOpenRouterPage />
|
||||
</PlatformAdminRoute>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'admin/exercise-enrichment',
|
||||
element: (
|
||||
|
||||
@@ -10075,3 +10075,134 @@ button.combo-coach-cand-link:hover {
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Superadmin: OpenRouter-Modellkatalog */
|
||||
.or-settings {
|
||||
padding: 16px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.or-settings__line {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 16px;
|
||||
margin: 0 0 8px;
|
||||
align-items: baseline;
|
||||
}
|
||||
.or-settings__line span {
|
||||
min-width: 6.5rem;
|
||||
color: var(--text3);
|
||||
font-size: 13px;
|
||||
}
|
||||
.or-settings__line code,
|
||||
.or-picker__id {
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.or-settings__notice {
|
||||
margin: 8px 0 0;
|
||||
color: var(--accent-dark);
|
||||
}
|
||||
.or-settings__actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.or-picker__toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.or-picker__count {
|
||||
margin: 0;
|
||||
color: var(--text2);
|
||||
font-size: 13px;
|
||||
}
|
||||
.or-picker__filters {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 10px 12px;
|
||||
}
|
||||
.or-picker__filters .form-row {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.or-picker__note,
|
||||
.or-picker__error,
|
||||
.or-picker__empty {
|
||||
margin: 8px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.or-picker__error {
|
||||
color: var(--danger);
|
||||
}
|
||||
.or-picker__note,
|
||||
.or-picker__empty {
|
||||
color: var(--text2);
|
||||
}
|
||||
.or-picker__clear {
|
||||
margin: 12px 0;
|
||||
}
|
||||
.or-picker__list {
|
||||
list-style: none;
|
||||
margin: 12px 0 0;
|
||||
padding: 0;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
}
|
||||
.or-picker__option {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
text-align: left;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: transparent;
|
||||
color: var(--text1);
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
}
|
||||
.or-picker__list li:last-child .or-picker__option {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.or-picker__option:hover {
|
||||
background: var(--surface2);
|
||||
}
|
||||
.or-picker__option--selected {
|
||||
background: var(--surface2);
|
||||
box-shadow: inset 3px 0 0 var(--accent);
|
||||
}
|
||||
.or-picker__option:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.or-picker__name {
|
||||
font-weight: 600;
|
||||
}
|
||||
.or-picker__meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 12px;
|
||||
color: var(--text3);
|
||||
font-size: 12px;
|
||||
}
|
||||
.or-model-embed {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
background: var(--surface);
|
||||
}
|
||||
.or-model-embed summary {
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
}
|
||||
.or-model-embed .or-picker {
|
||||
margin-top: 12px;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale, Sparkles, Wand2, Activity, Building2, Shield } from 'lucide-react'
|
||||
import { TreePine, FolderTree, Download, Grid3x3, Users, Scale, Sparkles, Bot, Wand2, Activity, Building2, Shield } from 'lucide-react'
|
||||
|
||||
/**
|
||||
* Admin-Seiten-Navigation (horizontal) — nur für Super-Admins (globaler Portal-Mandant).
|
||||
@@ -16,6 +16,7 @@ export default function AdminPageNav() {
|
||||
{ to: '/admin/mediawiki-import', label: 'Wiki-Import', icon: Download },
|
||||
{ to: '/admin/legal-documents', label: 'Rechtstexte', icon: Scale },
|
||||
{ to: '/admin/ai-prompts', label: 'KI Prompts', icon: Sparkles },
|
||||
{ to: '/admin/openrouter', label: 'KI-Modell', icon: Bot },
|
||||
{ to: '/admin/exercise-enrichment', label: 'Übungs-Anreicherung', icon: Wand2 },
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
import { useEffect, useId, useMemo, useState } from 'react'
|
||||
import api from '../utils/api'
|
||||
|
||||
function formatContext(value) {
|
||||
const n = Number(value)
|
||||
if (!Number.isFinite(n) || n <= 0) return '—'
|
||||
if (n >= 1000) {
|
||||
const k = n / 1000
|
||||
return Number.isInteger(k) ? `${k}k` : `${k.toFixed(1)}k`
|
||||
}
|
||||
return String(n)
|
||||
}
|
||||
|
||||
function tokenUsd(raw) {
|
||||
if (raw == null || raw === '') return null
|
||||
const n = Number(raw)
|
||||
return Number.isFinite(n) ? n : null
|
||||
}
|
||||
|
||||
function usdPerMillion(raw) {
|
||||
const n = tokenUsd(raw)
|
||||
if (n == null) return null
|
||||
const perM = n * 1_000_000
|
||||
if (perM === 0) return '0'
|
||||
if (perM < 0.01) return perM.toFixed(4)
|
||||
if (perM < 1) return perM.toFixed(3)
|
||||
return perM.toFixed(2)
|
||||
}
|
||||
|
||||
function priceLabel(model) {
|
||||
const prompt = usdPerMillion(model.prompt_usd_per_token)
|
||||
const completion = usdPerMillion(model.completion_usd_per_token)
|
||||
if (prompt == null && completion == null) return 'Preis unbekannt'
|
||||
return `${prompt ?? '—'} / ${completion ?? '—'} USD je 1 Mio. Tokens`
|
||||
}
|
||||
|
||||
function matchesFilters(model, filters) {
|
||||
const query = filters.query.trim().toLowerCase()
|
||||
if (query) {
|
||||
const hay = `${model.name || ''} ${model.id || ''} ${model.description || ''}`.toLowerCase()
|
||||
if (!hay.includes(query)) return false
|
||||
}
|
||||
if (filters.provider && model.provider !== filters.provider) return false
|
||||
const inputs = Array.isArray(model.input_modalities) ? model.input_modalities : []
|
||||
if (filters.modality === 'text' && !(inputs.length === 1 && inputs[0] === 'text')) return false
|
||||
if (filters.modality === 'image' && !inputs.includes('image')) return false
|
||||
if (filters.modality === 'audio' && !inputs.includes('audio')) return false
|
||||
if (filters.contextMin && (Number(model.context_length) || 0) < filters.contextMin) return false
|
||||
if (filters.price === 'free' && !model.is_free) return false
|
||||
if (filters.price === 'paid' && model.is_free) return false
|
||||
return true
|
||||
}
|
||||
|
||||
function compareModels(sort, a, b) {
|
||||
if (sort === 'context') {
|
||||
const diff = (Number(b.context_length) || 0) - (Number(a.context_length) || 0)
|
||||
if (diff) return diff
|
||||
}
|
||||
if (sort === 'price') {
|
||||
const ap = tokenUsd(a.prompt_usd_per_token)
|
||||
const bp = tokenUsd(b.prompt_usd_per_token)
|
||||
const aMissing = ap == null
|
||||
const bMissing = bp == null
|
||||
if (aMissing !== bMissing) return aMissing ? 1 : -1
|
||||
if (!aMissing && ap !== bp) return ap - bp
|
||||
}
|
||||
return String(a.name || a.id).localeCompare(String(b.name || b.id), 'de')
|
||||
}
|
||||
|
||||
/**
|
||||
* Durchsuchbare OpenRouter-Modellliste. value ist die Modell-ID oder leer.
|
||||
*/
|
||||
export default function OpenRouterModelPicker({
|
||||
value,
|
||||
onChange,
|
||||
allowClear = false,
|
||||
clearLabel = 'Plattformstandard verwenden',
|
||||
listMaxHeight = '22rem',
|
||||
}) {
|
||||
const [models, setModels] = useState([])
|
||||
const [meta, setMeta] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
const [query, setQuery] = useState('')
|
||||
const [provider, setProvider] = useState('')
|
||||
const [modality, setModality] = useState('')
|
||||
const [contextMin, setContextMin] = useState(0)
|
||||
const [price, setPrice] = useState('')
|
||||
const [sort, setSort] = useState('name')
|
||||
const uid = useId()
|
||||
|
||||
async function load(refresh = false) {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const data = await api.listAdminOpenRouterModels(refresh)
|
||||
setModels(Array.isArray(data?.models) ? data.models : [])
|
||||
setMeta(data)
|
||||
} catch (e) {
|
||||
setError(e.message || 'Modellliste konnte nicht geladen werden.')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
setLoading(true)
|
||||
api
|
||||
.listAdminOpenRouterModels(false)
|
||||
.then((data) => {
|
||||
if (cancelled) return
|
||||
setModels(Array.isArray(data?.models) ? data.models : [])
|
||||
setMeta(data)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (!cancelled) setError(e.message || 'Modellliste konnte nicht geladen werden.')
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
const providers = useMemo(() => {
|
||||
const names = new Set(models.map((model) => model.provider).filter(Boolean))
|
||||
return Array.from(names).sort((a, b) => a.localeCompare(b, 'de'))
|
||||
}, [models])
|
||||
|
||||
const visible = useMemo(() => {
|
||||
const filters = { query, provider, modality, contextMin, price }
|
||||
return models
|
||||
.filter((model) => matchesFilters(model, filters))
|
||||
.sort((a, b) => compareModels(sort, a, b))
|
||||
}, [models, query, provider, modality, contextMin, price, sort])
|
||||
|
||||
const selected = models.find((model) => model.id === value) || null
|
||||
const selectedHidden = Boolean(value) && !visible.some((model) => model.id === value)
|
||||
|
||||
return (
|
||||
<div className="or-picker">
|
||||
<div className="or-picker__toolbar">
|
||||
<p className="or-picker__count">
|
||||
{loading
|
||||
? 'Modelle werden geladen …'
|
||||
: `${visible.length} von ${models.length} Modellen`}
|
||||
</p>
|
||||
<button type="button" className="btn btn-secondary" disabled={loading} onClick={() => load(true)}>
|
||||
Liste aktualisieren
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{meta?.stale ? (
|
||||
<p className="or-picker__note">
|
||||
OpenRouter ist gerade nicht erreichbar. Angezeigt wird die zuletzt geladene Liste.
|
||||
</p>
|
||||
) : null}
|
||||
{error ? <p className="or-picker__error">{error}</p> : null}
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-search`}>
|
||||
Suche
|
||||
</label>
|
||||
<input
|
||||
id={`${uid}-search`}
|
||||
className="form-input"
|
||||
type="search"
|
||||
value={query}
|
||||
placeholder="Name oder Modell-ID"
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="or-picker__filters">
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-provider`}>
|
||||
Anbieter
|
||||
</label>
|
||||
<select
|
||||
id={`${uid}-provider`}
|
||||
className="form-input"
|
||||
value={provider}
|
||||
onChange={(e) => setProvider(e.target.value)}
|
||||
>
|
||||
<option value="">Alle</option>
|
||||
{providers.map((name) => (
|
||||
<option key={name} value={name}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-modality`}>
|
||||
Eingabe
|
||||
</label>
|
||||
<select
|
||||
id={`${uid}-modality`}
|
||||
className="form-input"
|
||||
value={modality}
|
||||
onChange={(e) => setModality(e.target.value)}
|
||||
>
|
||||
<option value="">Alle</option>
|
||||
<option value="text">Nur Text</option>
|
||||
<option value="image">Mit Bild</option>
|
||||
<option value="audio">Mit Audio</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-context`}>
|
||||
Kontext
|
||||
</label>
|
||||
<select
|
||||
id={`${uid}-context`}
|
||||
className="form-input"
|
||||
value={String(contextMin)}
|
||||
onChange={(e) => setContextMin(Number(e.target.value) || 0)}
|
||||
>
|
||||
<option value="0">Alle</option>
|
||||
<option value="32000">mindestens 32k</option>
|
||||
<option value="128000">mindestens 128k</option>
|
||||
<option value="200000">mindestens 200k</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-price`}>
|
||||
Preis
|
||||
</label>
|
||||
<select
|
||||
id={`${uid}-price`}
|
||||
className="form-input"
|
||||
value={price}
|
||||
onChange={(e) => setPrice(e.target.value)}
|
||||
>
|
||||
<option value="">Alle</option>
|
||||
<option value="free">Kostenlos</option>
|
||||
<option value="paid">Kostenpflichtig</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label" htmlFor={`${uid}-sort`}>
|
||||
Sortierung
|
||||
</label>
|
||||
<select
|
||||
id={`${uid}-sort`}
|
||||
className="form-input"
|
||||
value={sort}
|
||||
onChange={(e) => setSort(e.target.value)}
|
||||
>
|
||||
<option value="name">Name</option>
|
||||
<option value="context">Kontext, größter zuerst</option>
|
||||
<option value="price">Eingabepreis, niedrigster zuerst</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{allowClear ? (
|
||||
<div className="or-picker__clear">
|
||||
<button
|
||||
type="button"
|
||||
className={`btn ${value ? 'btn-secondary' : 'btn-primary'}`}
|
||||
onClick={() => onChange('')}
|
||||
>
|
||||
{clearLabel}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{value && !selected && !loading ? (
|
||||
<p className="or-picker__note">
|
||||
Gespeichert ist <code>{value}</code>. Diese ID steht in der aktuellen OpenRouter-Liste nicht.
|
||||
</p>
|
||||
) : null}
|
||||
{selectedHidden && selected ? (
|
||||
<p className="or-picker__note">
|
||||
Die aktuelle Auswahl <code>{selected.id}</code> passt nicht zu Suche oder Filtern.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<ul className="or-picker__list" role="listbox" aria-label="OpenRouter-Modelle" style={{ maxHeight: listMaxHeight }}>
|
||||
{!loading && visible.length === 0 ? (
|
||||
<li className="or-picker__empty">Kein Modell passt zu Suche und Filtern.</li>
|
||||
) : null}
|
||||
{visible.map((model) => {
|
||||
const isSelected = model.id === value
|
||||
return (
|
||||
<li key={model.id}>
|
||||
<button
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={isSelected}
|
||||
className={`or-picker__option${isSelected ? ' or-picker__option--selected' : ''}`}
|
||||
onClick={() => onChange(model.id)}
|
||||
>
|
||||
<span className="or-picker__name">{model.name}</span>
|
||||
<code className="or-picker__id">{model.id}</code>
|
||||
<span className="or-picker__meta">
|
||||
<span>Kontext {formatContext(model.context_length)}</span>
|
||||
<span>{priceLabel(model)}</span>
|
||||
{model.is_free ? <span>kostenlos</span> : null}
|
||||
{(model.input_modalities || []).length ? (
|
||||
<span>{model.input_modalities.join(', ')}</span>
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { Link, Navigate } from 'react-router-dom'
|
||||
import { Sparkles } from 'lucide-react'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
import AdminPageNav from '../components/AdminPageNav'
|
||||
import OpenRouterModelPicker from '../components/OpenRouterModelPicker'
|
||||
|
||||
/**
|
||||
* Pflege von ai_prompts (OpenRouter-Vorlagen) — nur Superadmin.
|
||||
@@ -25,6 +26,7 @@ export default function AdminAiPromptsPage() {
|
||||
const [draftTemplate, setDraftTemplate] = useState('')
|
||||
const [draftOpenrouterModel, setDraftOpenrouterModel] = useState('')
|
||||
const [draftActive, setDraftActive] = useState(true)
|
||||
const [modelListOpen, setModelListOpen] = useState(false)
|
||||
|
||||
const [pvTitle, setPvTitle] = useState('Testübung')
|
||||
const [pvGoal, setPvGoal] = useState('<p>Ziel hier</p>')
|
||||
@@ -80,6 +82,7 @@ export default function AdminAiPromptsPage() {
|
||||
setDetail(null)
|
||||
return
|
||||
}
|
||||
setModelListOpen(false)
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
try {
|
||||
@@ -264,15 +267,35 @@ export default function AdminAiPromptsPage() {
|
||||
/>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">OpenRouter-Modell (optional)</label>
|
||||
<input
|
||||
className="form-input"
|
||||
placeholder="Leer = Server-OPENROUTER_MODEL · z.B. anthropic/claude-3.5-haiku"
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
value={draftOpenrouterModel}
|
||||
onChange={(e) => setDraftOpenrouterModel(e.target.value)}
|
||||
/>
|
||||
<label className="form-label">OpenRouter-Modell für diesen Prompt</label>
|
||||
<p style={{ margin: '0 0 8px', color: 'var(--text2)', fontSize: 13 }}>
|
||||
{draftOpenrouterModel ? (
|
||||
<>
|
||||
Gewählt: <code>{draftOpenrouterModel}</code>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
Plattformstandard.{' '}
|
||||
<Link to="/admin/openrouter">KI-Modell festlegen</Link>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
<div className="or-model-embed">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={() => setModelListOpen((open) => !open)}
|
||||
>
|
||||
{modelListOpen ? 'Liste schließen' : 'Modell aus der OpenRouter-Liste wählen'}
|
||||
</button>
|
||||
{modelListOpen ? (
|
||||
<OpenRouterModelPicker
|
||||
value={draftOpenrouterModel}
|
||||
onChange={setDraftOpenrouterModel}
|
||||
allowClear
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 12 }}>
|
||||
<input type="checkbox" checked={draftActive} onChange={(e) => setDraftActive(e.target.checked)} />
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { Bot } from 'lucide-react'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
import AdminPageNav from '../components/AdminPageNav'
|
||||
import OpenRouterModelPicker from '../components/OpenRouterModelPicker'
|
||||
|
||||
/**
|
||||
* Plattform-Standardmodell bei OpenRouter — nur Superadmin.
|
||||
*/
|
||||
export default function AdminOpenRouterPage() {
|
||||
const { user } = useAuth()
|
||||
const isSuperadmin = user?.role === 'superadmin'
|
||||
|
||||
const [settings, setSettings] = useState(null)
|
||||
const [draft, setDraft] = useState('')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
const [notice, setNotice] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSuperadmin) return undefined
|
||||
let cancelled = false
|
||||
setLoading(true)
|
||||
api
|
||||
.getAdminOpenRouterSettings()
|
||||
.then((data) => {
|
||||
if (cancelled) return
|
||||
setSettings(data)
|
||||
setDraft(data?.openrouter_model || '')
|
||||
})
|
||||
.catch((e) => {
|
||||
if (!cancelled) setError(e.message || 'Einstellung konnte nicht geladen werden.')
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [isSuperadmin])
|
||||
|
||||
async function save(nextModel) {
|
||||
setSaving(true)
|
||||
setError('')
|
||||
setNotice('')
|
||||
try {
|
||||
const data = await api.updateAdminOpenRouterSettings(nextModel)
|
||||
setSettings(data)
|
||||
setDraft(data?.openrouter_model || '')
|
||||
setNotice(nextModel ? 'Standardmodell gespeichert.' : 'Es gilt wieder der Umgebungswert.')
|
||||
} catch (e) {
|
||||
setError(e.message || 'Speichern fehlgeschlagen.')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuperadmin) return <Navigate to="/" replace />
|
||||
|
||||
const stored = settings?.openrouter_model || ''
|
||||
const dirty = draft !== stored
|
||||
const sourceLabel = settings?.source === 'database' ? 'Datenbank' : 'Umgebung'
|
||||
|
||||
return (
|
||||
<div className="admin-page" style={{ maxWidth: 1100, margin: '0 auto', padding: '16px', paddingBottom: 96 }}>
|
||||
<AdminPageNav />
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 8 }}>
|
||||
<Bot size={22} aria-hidden />
|
||||
<h1 style={{ margin: 0, fontSize: '1.25rem' }}>KI-Modell</h1>
|
||||
</div>
|
||||
<p style={{ fontSize: 13, color: 'var(--text3)', marginTop: 0, maxWidth: '42rem' }}>
|
||||
Dieses Modell nutzt Shinkan für alle KI-Aufrufe, bei denen am einzelnen Prompt kein eigenes Modell
|
||||
hinterlegt ist. Die Liste kommt live von OpenRouter.
|
||||
</p>
|
||||
|
||||
{loading ? (
|
||||
<div className="card" style={{ padding: 24, textAlign: 'center' }}>
|
||||
<div className="spinner" />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="card or-settings">
|
||||
<p className="or-settings__line">
|
||||
<span>Aktiv</span>
|
||||
<code>{settings?.effective_model || '—'}</code>
|
||||
</p>
|
||||
<p className="or-settings__line">
|
||||
<span>Quelle</span>
|
||||
<strong>{sourceLabel}</strong>
|
||||
</p>
|
||||
<p className="or-settings__line">
|
||||
<span>Umgebung</span>
|
||||
<code>{settings?.env_model || '—'}</code>
|
||||
</p>
|
||||
{dirty ? <p className="or-picker__note">Die Auswahl ist noch nicht gespeichert.</p> : null}
|
||||
{notice ? <p className="or-settings__notice">{notice}</p> : null}
|
||||
{error ? <p className="or-picker__error">{error}</p> : null}
|
||||
<div className="or-settings__actions">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
disabled={saving || !draft || !dirty}
|
||||
onClick={() => save(draft)}
|
||||
>
|
||||
Als Standard speichern
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={saving || !stored}
|
||||
onClick={() => save('')}
|
||||
>
|
||||
Umgebungswert verwenden
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<OpenRouterModelPicker value={draft} onChange={setDraft} listMaxHeight="min(62vh, 640px)" />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -674,6 +674,22 @@ export async function getAdminAiPromptPlaceholdersCatalog() {
|
||||
return request('/api/admin/ai-prompts/catalog/placeholders')
|
||||
}
|
||||
|
||||
/** Superadmin: OpenRouter-Standardmodell und live Modellkatalog */
|
||||
export async function getAdminOpenRouterSettings() {
|
||||
return request('/api/admin/openrouter/settings')
|
||||
}
|
||||
|
||||
export async function updateAdminOpenRouterSettings(openrouterModel) {
|
||||
return request('/api/admin/openrouter/settings', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ openrouter_model: openrouterModel || '' }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function listAdminOpenRouterModels(refresh = false) {
|
||||
return request(`/api/admin/openrouter/models${refresh ? '?refresh=true' : ''}`)
|
||||
}
|
||||
|
||||
export async function listCatalogPromptSlotTypes() {
|
||||
return request('/api/catalog-prompt-slot-types')
|
||||
}
|
||||
@@ -1160,6 +1176,9 @@ export const api = {
|
||||
previewAdminAiPrompt,
|
||||
resetAdminAiPromptTemplate,
|
||||
getAdminAiPromptPlaceholdersCatalog,
|
||||
getAdminOpenRouterSettings,
|
||||
updateAdminOpenRouterSettings,
|
||||
listAdminOpenRouterModels,
|
||||
listCatalogPromptSlotTypes,
|
||||
getCatalogPromptSlots,
|
||||
updateCatalogPromptSlots,
|
||||
|
||||
Reference in new issue
Block a user