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

+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 } : {}) }),
});