feat: add manual feedback AI summaries and secure leaderboard scoring

This commit is contained in:
Lago committed 2026-10-15 19:06:10 +02:00
1 parent 34a3a88376
commit 6bad96ca03
37 files changed
+1640 -77

No files matched your search

+7 -2
View File
@@ -11,6 +11,8 @@ import { Activity } from './views/Activity';
import { Events } from './views/Events';
import { Interfaces } from './views/Interfaces';
import { Reports } from './views/Reports';
import { Settings } from './views/Settings';
import { Settings as SettingsIcon } from 'lucide-react';
import { Spinner } from './components/ui';
export type View =
@@ -22,7 +24,8 @@ export type View =
| 'activity'
| 'events'
| 'interfaces'
| 'reports';
| 'reports'
| 'settings';
const NAV: { id: View; label: string; ico: string }[] = [
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
@@ -34,6 +37,7 @@ const NAV: { id: View; label: string; ico: string }[] = [
{ id: 'events', label: 'Events', ico: '📅' },
{ id: 'interfaces', label: 'Interfaces', ico: '🔌' },
{ id: 'reports', label: 'Reports', ico: '📤' },
{ id: 'settings', label: 'Settings', ico: '' },
];
function Shell() {
@@ -67,7 +71,7 @@ function Shell() {
className={`nav-item ${view === n.id ? 'active' : ''}`}
onClick={() => setView(n.id)}
>
<span className="ico">{n.ico}</span>
<span className="ico">{n.id === 'settings' ? <SettingsIcon size={19} aria-hidden="true" /> : n.ico}</span>
{n.label}
</button>
))}
@@ -103,6 +107,7 @@ function Shell() {
{view === 'events' && <Events />}
{view === 'interfaces' && <Interfaces />}
{view === 'reports' && <Reports />}
{view === 'settings' && <Settings />}
</main>
</div>
);
@@ -0,0 +1,48 @@
import { useRef, useState } from 'react';
import { Sparkles } from 'lucide-react';
import { generateFeedbackSummary } from '../lib/api';
import type { FeedbackSummary } from '../lib/types';
export function FeedbackSummaryPanel({ eventId, sessionId, title, count, configured, summary, onGenerated }: {
eventId: string;
sessionId?: string;
title: string;
count: number;
configured: boolean;
summary?: FeedbackSummary;
onGenerated: (summary: FeedbackSummary) => void;
}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const running = useRef(false);
async function generate() {
if (running.current) return;
running.current = true;
setBusy(true);
setError(null);
try { onGenerated(await generateFeedbackSummary(eventId, sessionId)); }
catch (cause) { setError(cause instanceof Error ? cause.message : 'Summary generation failed'); }
finally { running.current = false; setBusy(false); }
}
return (
<section className="feedback-summary" aria-label={`AI summary: ${title}`} aria-busy={busy}>
<div className="feedback-summary-head">
<div><h2 className="h2">{title}</h2><span className="muted small">{count} responses</span></div>
<button className="btn small" disabled={busy || count === 0 || !configured} onClick={generate}
title={!configured ? 'LLM endpoint not configured' : count === 0 ? 'No feedback available' : undefined}>
<Sparkles size={16} aria-hidden="true" />{busy ? 'Generating...' : 'Generate AI Summary'}
</button>
</div>
{!configured && <p className="muted small">LLM endpoint not configured</p>}
{error && <p className="feedback-error" role="alert">{error}</p>}
{busy && <p className="muted small" role="status">Generating summary...</p>}
{summary && <>
<div className="feedback-summary-text">{summary.summary}</div>
<p className="muted small">AI-generated · {summary.response_count} responses · {summary.model} · {new Date(summary.generated_at).toLocaleString()}</p>
{summary.response_count !== count && <p className="muted small">Response count has changed since this summary.</p>}
</>}
</section>
);
}
+38 -4
View File
@@ -8,6 +8,8 @@ import type {
EventFeedback,
ExcelSyncResult,
Feedback,
FeedbackSummary,
LlmSettings,
LeaderboardRow,
PointsLogRow,
PretixOptions,
@@ -67,6 +69,18 @@ export const getAllConnections = () => all<Connection>('connections', { col: 'cr
export const getAllCheckins = () => all<Checkin>('checkins', { col: 'created_at', asc: false });
export const getAllFeedback = () => all<Feedback>('feedback', { col: 'created_at', asc: false });
export const getAllEventFeedback = () => all<EventFeedback>('event_feedback', { col: 'created_at', asc: false });
async function eventFeedbackRows<T>(table: 'feedback' | 'event_feedback', eventId: string): Promise<T[]> {
const rows: T[] = [];
for (let offset = 0; ; offset += 500) {
const { data, error } = await supabase.from(table).select('*').eq('event_id', eventId)
.order('created_at', { ascending: false }).order('id', { ascending: false }).range(offset, offset + 499);
if (error) throw new ApiError(error.message);
rows.push(...data as T[]);
if (data.length < 500) return rows;
}
}
export const getEventSessionFeedback = (eventId: string) => eventFeedbackRows<Feedback>('feedback', eventId);
export const getEventFeedback = (eventId: string) => eventFeedbackRows<EventFeedback>('event_feedback', eventId);
export const getAllPointsLog = () => all<PointsLogRow>('points_log', { col: 'created_at', asc: false });
export const getLeaderboard = () => all<LeaderboardRow>('leaderboard', { col: 'points', asc: false });
@@ -383,8 +397,28 @@ export function sessionMaterialUrl(path: string): string {
return data.publicUrl;
}
/** Trigger the (stub) AI feedback evaluation for a session. */
export async function evaluateSessionFeedback(sessionId: string): Promise<Session> {
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
return await rpc<Session>('evaluate_session_feedback', { p_session_id: sessionId });
async function feedbackSidecarFetch<T>(path: string, init?: RequestInit): Promise<T> {
const { data, error } = await supabase.auth.getSession();
if (error || !data.session) throw new ApiError('Sign in as an administrator');
return sidecarFetch<T>(path, {
...init,
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${data.session.access_token}` },
});
}
export const getLlmSettings = () => feedbackSidecarFetch<LlmSettings>('/llm-settings');
export const saveLlmSettings = (input: { endpoint: string; model: string; api_key?: string }) =>
feedbackSidecarFetch<LlmSettings>('/llm-settings', { method: 'PUT', body: JSON.stringify(input) });
export async function getFeedbackSummaries(eventId: string): Promise<FeedbackSummary[]> {
const { data, error } = await supabase.from('feedback_summaries').select('*').eq('event_id', eventId);
if (error) throw new ApiError(error.message);
return data as FeedbackSummary[];
}
export const generateFeedbackSummary = (eventId: string, sessionId?: string) =>
feedbackSidecarFetch<FeedbackSummary>('/feedback-summary', {
method: 'POST',
body: JSON.stringify({ event_id: eventId, scope: sessionId ? 'session' : 'event', ...(sessionId ? { session_id: sessionId } : {}) }),
});
+18
View File
@@ -1,3 +1,21 @@
export interface LlmSettings {
endpoint: string;
model: string;
has_api_key: boolean;
updated_at: string | null;
}
export interface FeedbackSummary {
scope: 'event' | 'session';
target_id: string;
event_id: string;
session_id: string | null;
summary: string;
response_count: number;
source_fingerprint: string;
model: string;
generated_at: string;
}
export type RegistrationType = 'attendee' | 'speaker' | 'staff' | 'sponsor';
export type SponsorType =
+14
View File
@@ -1,3 +1,17 @@
.llm-settings { display: grid; gap: 18px; max-width: 640px; padding: 20px 0; border-top: 1px solid var(--line); }
.feedback-summary { width: 100%; min-width: 0; padding: 16px 0; border-bottom: 1px solid var(--line); }
.feedback-summary-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.feedback-summary-head > div { min-width: 0; flex: 1 1 220px; overflow-wrap: anywhere; }
.feedback-summary-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; margin: 12px 0; }
.feedback-summary p { overflow-wrap: anywhere; }
.feedback-error { color: var(--red); overflow-wrap: anywhere; margin: 8px 0; }
.feedback-table { overflow-x: auto; }
.feedback-table table { min-width: 680px; }
.seg.activity-tabs { max-width: 100%; }
.seg.activity-tabs button { min-width: 0; white-space: normal; }
@media (max-width: 760px) {
.seg.activity-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
--bg: #f0f2f6; --surface: #ffffff; --surface-2: #f4f5f9;
+30 -11
View File
@@ -3,13 +3,16 @@ import {
getAllCheckins,
getAllConnections,
getAllContacts,
getAllEventFeedback,
getAllFeedback,
getEventFeedback,
getEventSessionFeedback,
getActiveEvent,
getSessions,
getFeedbackSummaries,
getLlmSettings,
} from '../lib/api';
import type { Checkin, Connection, Contact, Event, EventFeedback, Feedback, Session } from '../lib/types';
import type { Checkin, Connection, Contact, Event, EventFeedback, Feedback, FeedbackSummary, Session } from '../lib/types';
import { Avatar, Empty, Spinner } from '../components/ui';
import { FeedbackSummaryPanel } from '../components/FeedbackSummaryPanel';
type Tab = 'checkins' | 'connections' | 'feedback' | 'event_feedback';
@@ -24,6 +27,13 @@ export function Activity() {
const [feedback, setFeedback] = useState<Feedback[]>([]);
const [eventFeedback, setEventFeedback] = useState<EventFeedback[]>([]);
const [error, setError] = useState<string | null>(null);
const [summaries, setSummaries] = useState<FeedbackSummary[]>([]);
const [llmConfigured, setLlmConfigured] = useState(false);
const [summaryError, setSummaryError] = useState<string | null>(null);
function updateSummary(summary: FeedbackSummary) {
setSummaries(current => [...current.filter(item => item.scope !== summary.scope || item.target_id !== summary.target_id), summary]);
}
async function load() {
try {
@@ -33,8 +43,8 @@ export function Activity() {
getAllContacts(),
getAllCheckins(),
getAllConnections(),
getAllFeedback(),
getAllEventFeedback(),
ev ? getEventSessionFeedback(ev.id) : Promise.resolve([]),
ev ? getEventFeedback(ev.id) : Promise.resolve([]),
]);
setContacts(c);
if (ev) {
@@ -44,6 +54,11 @@ export function Activity() {
setConnections(cn.filter((x) => x.event_id === ev.id));
setFeedback(fb.filter((x) => x.event_id === ev.id));
setEventFeedback(efb.filter((x) => x.event_id === ev.id));
try {
const [saved, settings] = await Promise.all([getFeedbackSummaries(ev.id), getLlmSettings()]);
setSummaries(saved);
setLlmConfigured(Boolean(settings.endpoint && settings.model));
} catch (cause) { setSummaryError(cause instanceof Error ? cause.message : 'Failed to load AI settings'); }
}
setLoaded(true);
} catch (e) {
@@ -120,7 +135,7 @@ export function Activity() {
</div>
</div>
<div className="seg" style={{ marginBottom: 16 }}>
<div className="seg activity-tabs" style={{ marginBottom: 16 }}>
<button className={tab === 'checkins' ? 'active' : ''} onClick={() => setTab('checkins')}>
Check-ins
</button>
@@ -209,6 +224,7 @@ export function Activity() {
{tab === 'feedback' && (
<div className="card">
{summaryError && <p className="feedback-error" role="alert">{summaryError}</p>}
{feedback.length === 0 ? (
<Empty icon="⭐" text="No feedback yet." />
) : (
@@ -220,16 +236,16 @@ export function Activity() {
</div>
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
{sessionFeedbackSummary.map((s) => (
<span key={s.session_id} className="pill amber" title={s.title}>
{s.title} · {s.avg.toFixed(1)}★ · {s.count}
</span>
<FeedbackSummaryPanel key={s.session_id} eventId={event.id} sessionId={s.session_id}
title={`${s.title} · ${s.avg.toFixed(1)}★`} count={s.count} configured={llmConfigured}
summary={summaries.find(item => item.scope === 'session' && item.session_id === s.session_id)} onGenerated={updateSummary} />
))}
</div>
</div>
</>
)}
{feedback.length > 0 && (
<div className="table-wrap">
<div className="table-wrap feedback-table">
<table className="data">
<thead>
<tr>
@@ -263,10 +279,13 @@ export function Activity() {
{tab === 'event_feedback' && (
<div className="card">
{summaryError && <p className="feedback-error" role="alert">{summaryError}</p>}
<FeedbackSummaryPanel eventId={event.id} title={event.name} count={eventFeedback.length} configured={llmConfigured}
summary={summaries.find(item => item.scope === 'event')} onGenerated={updateSummary} />
{eventFeedback.length === 0 ? (
<Empty icon="⭐" text="No event-level feedback yet." />
) : (
<div className="table-wrap">
<div className="table-wrap feedback-table">
<table className="data">
<thead>
<tr>
-22
View File
@@ -2,7 +2,6 @@ import { useEffect, useMemo, useRef, useState } from 'react';
import { supabase } from '../lib/supabase';
import {
deleteEventSchedule,
evaluateSessionFeedback,
getAllContacts,
getAllSessionSpeakers,
getActiveEvent,
@@ -129,19 +128,6 @@ export function Schedule() {
}
}
async function doEvaluate(sess: Session) {
setBusy(true);
try {
await evaluateSessionFeedback(sess.id);
await load();
push('success', `AI feedback evaluated for ${sess.title}`);
} catch (e) {
push('error', e instanceof Error ? e.message : 'Evaluation failed');
} finally {
setBusy(false);
}
}
async function deleteCurrentSchedule() {
const target = deleteModal;
if (!target || deleting) return;
@@ -277,17 +263,9 @@ export function Schedule() {
<div className="muted small" style={{ marginTop: 4 }}>
{s.average_feedback != null && <span>⭐ {s.average_feedback.toFixed(1)}</span>}
<span> · {s.material_path ? '📎 material submitted' : '⬜ material not submitted'}</span>
{s.ai_generated_feedback && (
<span className="ai-state"> · 🤖 {s.ai_generated_feedback}</span>
)}
</div>
</div>
<div className="row-actions">
{s.ai_generated_feedback === 'Pending AI Evaluation' && (
<button className="btn small" disabled={mutating} onClick={() => doEvaluate(s)}>
Evaluate
</button>
)}
<button className="btn small" disabled={mutating} onClick={() => setSessModal({ session: s, slotId: slot.id })}>
Edit
</button>
+72
View File
@@ -0,0 +1,72 @@
import { useEffect, useState, type FormEvent } from 'react';
import { Save } from 'lucide-react';
import { getLlmSettings, saveLlmSettings } from '../lib/api';
import { Spinner } from '../components/ui';
export function Settings() {
const [endpoint, setEndpoint] = useState('');
const [model, setModel] = useState('');
const [apiKey, setApiKey] = useState('');
const [hasKey, setHasKey] = useState(false);
const [clearKey, setClearKey] = useState(false);
const [loaded, setLoaded] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [saved, setSaved] = useState(false);
useEffect(() => {
let active = true;
getLlmSettings().then(settings => {
if (!active) return;
setEndpoint(settings.endpoint);
setModel(settings.model);
setHasKey(settings.has_api_key);
setLoaded(true);
}).catch(cause => { if (active) setError(cause instanceof Error ? cause.message : 'Failed to load settings'); });
return () => { active = false; };
}, []);
async function save(event: FormEvent) {
event.preventDefault();
setBusy(true);
setSaved(false);
setError(null);
try {
const settings = await saveLlmSettings({ endpoint: endpoint.trim(), model: model.trim(), ...(clearKey ? { api_key: '' } : apiKey ? { api_key: apiKey } : {}) });
setEndpoint(settings.endpoint);
setHasKey(settings.has_api_key);
setApiKey('');
setClearKey(false);
setSaved(true);
} catch (cause) { setError(cause instanceof Error ? cause.message : 'Failed to save settings'); }
finally { setBusy(false); }
}
return (
<div>
<div className="page-head"><h1>Settings</h1></div>
{error && <p className="feedback-error" role="alert">{error}</p>}
{!loaded && !error && <Spinner />}
{loaded && <form className="llm-settings" onSubmit={save} onChange={() => setSaved(false)}>
<h2 className="h2">Feedback AI</h2>
<div className="field">
<label htmlFor="llm-endpoint">LLM endpoint (OpenAI-compatible)</label>
<input id="llm-endpoint" className="input" type="url" placeholder="https://api.example.com/v1/chat/completions" required value={endpoint} disabled={busy} onChange={event => setEndpoint(event.target.value)} />
</div>
<div className="field">
<label htmlFor="llm-model">Model</label>
<input id="llm-model" className="input" required maxLength={200} value={model} disabled={busy} onChange={event => setModel(event.target.value)} />
</div>
<div className="field">
<label htmlFor="llm-key">API key (optional)</label>
<input id="llm-key" className="input" type="password" autoComplete="new-password" maxLength={4096} value={apiKey} disabled={busy || clearKey} placeholder={hasKey ? 'Key configured' : ''} onChange={event => setApiKey(event.target.value)} />
</div>
{hasKey && <label className="row"><input type="checkbox" checked={clearKey} disabled={busy} onChange={event => setClearKey(event.target.checked)} />Remove stored API key</label>}
<div className="row">
<button className="btn primary" type="submit" disabled={busy}><Save size={16} aria-hidden="true" />{busy ? 'Saving...' : 'Save'}</button>
{saved && <span role="status">Settings saved</span>}
</div>
</form>}
</div>
);
}