feat(ai): add personal summary models and retire Q&A
Add an admin-managed provider model catalog with per-user summary selection, migration backfill, and generation snapshots. Retire report creation and messaging while preserving owner-scoped history. Refs #15 #16 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
80
frontend/src/components/AIModelCatalog.tsx
Normal file
80
frontend/src/components/AIModelCatalog.tsx
Normal file
@ -0,0 +1,80 @@
|
||||
import { useEffect, useState, useCallback, type FormEvent } from 'react'
|
||||
import { adminApi, type AIProvider, type AIModelCatalogEntry } from '@/api/admin'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select } from '@/components/ui/select'
|
||||
|
||||
export function AIModelCatalog({ providers }: { providers: AIProvider[] }) {
|
||||
const [entries, setEntries] = useState<AIModelCatalogEntry[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
const [notice, setNotice] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [providerId, setProviderId] = useState('')
|
||||
const [model, setModel] = useState('')
|
||||
const load = useCallback(() => adminApi.listAIModelCatalog().then(data => { setEntries(data ?? []); return true })
|
||||
.catch(() => { setError('Impossible de charger le catalogue de modèles.'); return false })
|
||||
.finally(() => setLoading(false)), [])
|
||||
useEffect(() => { void load() }, [load])
|
||||
|
||||
async function save(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
if (busy || !providerId || !model.trim()) return
|
||||
setBusy(true); setError(''); setNotice('')
|
||||
try {
|
||||
await adminApi.createAIModelCatalogEntry({ provider_id: providerId, model: model.trim() })
|
||||
setModel(''); setProviderId('')
|
||||
if (await load()) setNotice('Catalogue enregistré. Chaque compte choisit son modèle dans Mes préférences.')
|
||||
} catch { setError('Impossible d’enregistrer ce modèle. Vos saisies sont conservées.') }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
|
||||
async function change(entry: AIModelCatalogEntry, remove: boolean) {
|
||||
if (busy) return
|
||||
setBusy(true); setError(''); setNotice('')
|
||||
try {
|
||||
if (remove) await adminApi.deleteAIModelCatalogEntry(entry.id)
|
||||
else await adminApi.updateAIModelCatalogEntry(entry.id, { enabled: !entry.enabled })
|
||||
if (await load()) setNotice(remove ? 'Modèle supprimé du catalogue.' : 'Disponibilité du modèle mise à jour.')
|
||||
} catch (error) {
|
||||
setError(error && typeof error === 'object' && 'status' in error && error.status === 409
|
||||
? 'Ce modèle est encore sélectionné par un compte et ne peut pas être supprimé.'
|
||||
: 'Impossible de modifier le catalogue. Le modèle est conservé.')
|
||||
} finally { setBusy(false) }
|
||||
}
|
||||
|
||||
return <Card>
|
||||
<CardHeader><CardTitle>Catalogue des modèles de synthèse</CardTitle></CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<p>Les modèles activés sont proposés à tous les comptes. Chaque utilisateur choisit sa configuration personnelle ; aucun choix global ne remplace cette sélection.</p>
|
||||
{loading && <p role="status">Chargement du catalogue…</p>}
|
||||
{error && <div><p role="alert">{error}</p><Button disabled={busy} variant="outline" onClick={() => { setError(''); void load() }}>Recharger le catalogue</Button></div>}
|
||||
{notice && <p role="status">{notice}</p>}
|
||||
{!loading && <>
|
||||
{entries.length === 0 && <p>Aucun modèle configuré.</p>}
|
||||
<ul className="space-y-3">{entries.map(entry => <li key={entry.id} className="rounded-md border p-3 space-y-2 break-words">
|
||||
<p>{entry.provider ?? providers.find(provider => provider.id === entry.provider_id)?.name ?? 'Fournisseur indisponible'} · {entry.model}</p>
|
||||
<p>{entry.enabled ? 'Proposé aux comptes' : 'Désactivé'}</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button variant="outline" disabled={busy} onClick={() => void change(entry, false)}>{entry.enabled ? 'Désactiver' : 'Activer'}</Button>
|
||||
<Button variant="outline" disabled={busy} onClick={() => void change(entry, true)}>Supprimer le modèle</Button>
|
||||
</div>
|
||||
</li>)}</ul>
|
||||
<form aria-label="Ajouter un modèle" onSubmit={save} className="space-y-3">
|
||||
<Label htmlFor="catalog-provider">Connexion fournisseur</Label>
|
||||
<Select id="catalog-provider" required disabled={busy} value={providerId} onChange={event => setProviderId(event.target.value)}>
|
||||
<option value="">Choisir une connexion</option>
|
||||
{providers.map(provider => <option key={provider.id} value={provider.id}>{provider.name}</option>)}
|
||||
</Select>
|
||||
<Label htmlFor="catalog-model">Identifiant du modèle</Label>
|
||||
<Input id="catalog-model" required maxLength={256} value={model} disabled={busy} onChange={event => setModel(event.target.value)} />
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" disabled={busy || !providerId || !model.trim()}>{busy ? 'Enregistrement…' : 'Ajouter au catalogue'}</Button>
|
||||
</div>
|
||||
</form>
|
||||
</>}
|
||||
</CardContent>
|
||||
</Card>
|
||||
}
|
||||
Reference in New Issue
Block a user