2026-11-18 21:47:37 +00:00
|
|
|
|
"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";
|
2026-11-27 00:34:59 +00:00
|
|
|
|
import { confirmDialog } from "@/components/Dialogs";
|
2026-11-18 21:47:37 +00:00
|
|
|
|
|
2026-11-23 09:33:00 +00:00
|
|
|
|
const PAGE = 50;
|
2026-11-18 21:47:37 +00:00
|
|
|
|
|
|
|
|
|
|
const SOURCES: Record<string, string> = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" };
|
|
|
|
|
|
const KINDS: Record<string, string> = {
|
|
|
|
|
|
summary: "összefoglaló",
|
2026-11-27 09:40:09 +00:00
|
|
|
|
weekly: "heti horoszkóp",
|
2026-11-18 21:47:37 +00:00
|
|
|
|
natal: "képletelemzés",
|
|
|
|
|
|
synastry: "kapcsolati",
|
|
|
|
|
|
forecast: "előrejelzés",
|
2026-11-22 16:08:35 +00:00
|
|
|
|
celebrity: "híres ember",
|
2026-11-18 21:47:37 +00:00
|
|
|
|
question: "válasz",
|
|
|
|
|
|
};
|
|
|
|
|
|
const OUTCOMES: Record<GenerationError["outcome"], { label: string; tone: string }> = {
|
|
|
|
|
|
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("");
|
2026-11-23 09:33:00 +00:00
|
|
|
|
const [page, setPage] = useState(0);
|
2026-11-18 21:47:37 +00:00
|
|
|
|
const [errors, setErrors] = useState<GenerationError[] | null>(null);
|
|
|
|
|
|
const [total, setTotal] = useState(0);
|
|
|
|
|
|
const [lastDay, setLastDay] = useState(0);
|
|
|
|
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
|
|
2026-11-23 09:33:00 +00:00
|
|
|
|
const filter = useCallback(() => {
|
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
|
if (source) params.set("source", source);
|
|
|
|
|
|
if (outcome) params.set("outcome", outcome);
|
|
|
|
|
|
return params;
|
|
|
|
|
|
}, [source, outcome]);
|
|
|
|
|
|
|
|
|
|
|
|
const load = useCallback(async () => {
|
|
|
|
|
|
setBusy(true);
|
|
|
|
|
|
setError(null);
|
|
|
|
|
|
const params = filter();
|
|
|
|
|
|
params.set("limit", String(PAGE));
|
|
|
|
|
|
params.set("offset", String(page * PAGE));
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await api<Page>(`/admin/errors?${params}`);
|
|
|
|
|
|
// The last page emptied by deleting: one page back.
|
|
|
|
|
|
if (res.errors.length === 0 && page > 0) return setPage(Math.max(0, Math.ceil(res.total / PAGE) - 1));
|
|
|
|
|
|
setErrors(res.errors);
|
|
|
|
|
|
setTotal(res.total);
|
|
|
|
|
|
setLastDay(res.last_day);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
setError(errorText(e));
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setBusy(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [filter, page]);
|
2026-11-18 21:47:37 +00:00
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-23 09:33:00 +00:00
|
|
|
|
load();
|
2026-11-18 21:47:37 +00:00
|
|
|
|
}, [load]);
|
|
|
|
|
|
|
2026-11-23 09:33:00 +00:00
|
|
|
|
async function removeOne(id: number) {
|
|
|
|
|
|
setError(null);
|
|
|
|
|
|
try {
|
|
|
|
|
|
await api(`/admin/errors/${id}`, { method: "DELETE" });
|
|
|
|
|
|
await load();
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
setError(errorText(e));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function removeMatching() {
|
|
|
|
|
|
const what = source || outcome ? `a szűrésnek megfelelő ${total} bejegyzést` : `mind a ${total} bejegyzést`;
|
2026-11-27 00:34:59 +00:00
|
|
|
|
const ok = await confirmDialog({
|
|
|
|
|
|
title: `Törlöd ${what}?`,
|
|
|
|
|
|
text: "Nem vonható vissza.",
|
|
|
|
|
|
confirm: "Törlés",
|
|
|
|
|
|
danger: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!ok) return;
|
2026-11-23 09:33:00 +00:00
|
|
|
|
setBusy(true);
|
|
|
|
|
|
setError(null);
|
|
|
|
|
|
try {
|
|
|
|
|
|
await api(`/admin/errors?${filter()}`, { method: "DELETE" });
|
|
|
|
|
|
setPage(0);
|
|
|
|
|
|
await load();
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
setError(errorText(e));
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setBusy(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const pages = Math.max(1, Math.ceil(total / PAGE));
|
|
|
|
|
|
|
2026-11-18 21:47:37 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<section className="card" style={{ gap: 12 }}>
|
|
|
|
|
|
<div className="row" style={{ gap: 12, flexWrap: "wrap", alignItems: "flex-end" }}>
|
|
|
|
|
|
<div className="field">
|
|
|
|
|
|
<label htmlFor="error-source">Mi</label>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
<select id="error-source" className="inp" value={source} onChange={(e) => {
|
|
|
|
|
|
setSource(e.target.value);
|
|
|
|
|
|
setPage(0);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
<option value="">mind</option>
|
|
|
|
|
|
{Object.entries(SOURCES).map(([v, l]) => (
|
|
|
|
|
|
<option key={v} value={v}>
|
|
|
|
|
|
{l}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="field">
|
|
|
|
|
|
<label htmlFor="error-outcome">Következmény</label>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
<select id="error-outcome" className="inp" value={outcome} onChange={(e) => {
|
|
|
|
|
|
setOutcome(e.target.value);
|
|
|
|
|
|
setPage(0);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
<option value="">mind</option>
|
|
|
|
|
|
{Object.entries(OUTCOMES).map(([v, o]) => (
|
|
|
|
|
|
<option key={v} value={v}>
|
|
|
|
|
|
{o.label}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="hint" style={{ margin: 0 }}>
|
|
|
|
|
|
{total} bejegyzés, ebből {lastDay} az elmúlt 24 órában
|
|
|
|
|
|
</p>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
<button type="button" className="btn btn-sm btn-ghost" onClick={load} disabled={busy}>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
Frissítés
|
|
|
|
|
|
</button>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
{total > 0 && (
|
|
|
|
|
|
<button type="button" className="btn btn-sm btn-danger" onClick={removeMatching} disabled={busy}>
|
|
|
|
|
|
{source || outcome ? `A szűrt ${total} törlése` : `Mind a ${total} törlése`}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
2026-11-18 21:47:37 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<p className="msg msg-error" role="alert">
|
|
|
|
|
|
{error}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{errors === null ? (
|
|
|
|
|
|
<p className="muted">Betöltés…</p>
|
|
|
|
|
|
) : errors.length === 0 ? (
|
|
|
|
|
|
<p className="muted">Nincs hiba. 🎉</p>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="table-wrap">
|
|
|
|
|
|
<table className="error-log">
|
|
|
|
|
|
<thead>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th>Időpont</th>
|
|
|
|
|
|
<th>Mi</th>
|
|
|
|
|
|
<th>Modell</th>
|
|
|
|
|
|
<th>Kísérlet</th>
|
|
|
|
|
|
<th>Következmény</th>
|
|
|
|
|
|
<th>Hiba</th>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
<th>
|
|
|
|
|
|
<span className="sr-only">Törlés</span>
|
|
|
|
|
|
</th>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
{errors.map((e) => (
|
|
|
|
|
|
<tr key={e.id}>
|
|
|
|
|
|
<td className="num">{formatDate(e.created_at, true)}</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
{SOURCES[e.source] ?? e.source}
|
|
|
|
|
|
{e.source !== "question" && ` (${KINDS[e.kind] ?? e.kind})`}
|
|
|
|
|
|
{e.user && <span className="hint">{e.user}</span>}
|
|
|
|
|
|
<code className="hint" title={e.item_id}>
|
|
|
|
|
|
{e.item_id.slice(0, 8)}
|
|
|
|
|
|
</code>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<code>{e.model}</code>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="num">
|
|
|
|
|
|
{e.attempt}.{e.seconds !== null && <span className="hint">{e.seconds} mp</span>}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<span className={`outcome tone-${OUTCOMES[e.outcome].tone}`}>{OUTCOMES[e.outcome].label}</span>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="error-text">{e.error}</td>
|
2026-11-23 09:33:00 +00:00
|
|
|
|
<td>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className="btn btn-sm btn-ghost"
|
|
|
|
|
|
onClick={() => removeOne(e.id)}
|
|
|
|
|
|
aria-label="Bejegyzés törlése"
|
|
|
|
|
|
title="Bejegyzés törlése"
|
|
|
|
|
|
>
|
|
|
|
|
|
✕
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</td>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
</tr>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-11-23 09:33:00 +00:00
|
|
|
|
{total > PAGE && (
|
|
|
|
|
|
<nav className="pager" aria-label="Lapozás">
|
|
|
|
|
|
<button type="button" className="btn btn-sm" disabled={busy || page === 0} onClick={() => setPage(page - 1)}>
|
|
|
|
|
|
‹ Újabbak
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<span className="num">
|
|
|
|
|
|
{page * PAGE + 1}–{Math.min(total, (page + 1) * PAGE)} / {total} · {page + 1}/{pages}. oldal
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
className="btn btn-sm"
|
|
|
|
|
|
disabled={busy || page + 1 >= pages}
|
|
|
|
|
|
onClick={() => setPage(page + 1)}
|
|
|
|
|
|
>
|
|
|
|
|
|
Régebbiek ›
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</nav>
|
2026-11-18 21:47:37 +00:00
|
|
|
|
)}
|
|
|
|
|
|
</section>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|