"use client"; import { useCallback, useEffect, useState } from "react"; import { api, errorText } from "@/lib/api"; import { formatDate } from "@/lib/astro"; import type { GenerationError } from "@/lib/types"; const PAGE = 100; const SOURCES: Record = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" }; const KINDS: Record = { summary: "összefoglaló", natal: "képletelemzés", synastry: "kapcsolati", forecast: "előrejelzés", question: "válasz", }; const OUTCOMES: Record = { retry: { label: "újrapróbálva", tone: "neutral" }, fallback: { label: "tartalék modell vette át", tone: "neutral" }, failed: { label: "végleg sikertelen", tone: "tense" }, }; interface Page { errors: GenerationError[]; total: number; last_day: number; } /** The admin error log with filters and paging. */ export function ErrorLog() { const [source, setSource] = useState(""); const [outcome, setOutcome] = useState(""); const [errors, setErrors] = useState(null); const [total, setTotal] = useState(0); const [lastDay, setLastDay] = useState(0); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const load = useCallback( async (offset: number) => { setBusy(true); setError(null); const params = new URLSearchParams({ limit: String(PAGE), offset: String(offset) }); if (source) params.set("source", source); if (outcome) params.set("outcome", outcome); try { const page = await api(`/admin/errors?${params}`); setErrors((all) => (offset === 0 ? page.errors : [...(all ?? []), ...page.errors])); setTotal(page.total); setLastDay(page.last_day); } catch (e) { setError(errorText(e)); } finally { setBusy(false); } }, [source, outcome], ); useEffect(() => { load(0); }, [load]); return (

{total} bejegyzés, ebből {lastDay} az elmúlt 24 órában

{error && (

{error}

)} {errors === null ? (

Betöltés…

) : errors.length === 0 ? (

Nincs hiba. 🎉

) : (
{errors.map((e) => ( ))}
Időpont Mi Modell Kísérlet Következmény Hiba
{formatDate(e.created_at, true)} {SOURCES[e.source] ?? e.source} {e.source !== "question" && ` (${KINDS[e.kind] ?? e.kind})`} {e.user && {e.user}} {e.item_id.slice(0, 8)} {e.model} {e.attempt}.{e.seconds !== null && {e.seconds} mp} {OUTCOMES[e.outcome].label} {e.error}
)} {errors && errors.length < total && ( )}
); }