Error log, retry notice, a waiting counter that keeps counting
- generation_errors: every failed attempt (model, attempt, outcome, duration); admin Hibanapló page and GET /v1/admin/errors; kept 90 days - The waiting page counts from when the text was asked for (requested_at), not from the page load, so a reload no longer restarts it - It says when an attempt failed and is retried, and when a failed text's unit was given back; admins see the error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
"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<string, string> = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" };
|
||||
const KINDS: Record<string, string> = {
|
||||
summary: "összefoglaló",
|
||||
natal: "képletelemzés",
|
||||
synastry: "kapcsolati",
|
||||
forecast: "előrejelzés",
|
||||
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("");
|
||||
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);
|
||||
|
||||
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<Page>(`/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 (
|
||||
<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>
|
||||
<select id="error-source" className="inp" value={source} onChange={(e) => setSource(e.target.value)}>
|
||||
<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>
|
||||
<select id="error-outcome" className="inp" value={outcome} onChange={(e) => setOutcome(e.target.value)}>
|
||||
<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>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => load(0)} disabled={busy}>
|
||||
Frissítés
|
||||
</button>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{errors && errors.length < total && (
|
||||
<button type="button" className="btn btn-sm" onClick={() => load(errors.length)} disabled={busy}>
|
||||
{busy ? "Betöltés…" : "Régebbiek"}
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { ErrorLog } from "./ErrorLog";
|
||||
|
||||
export const metadata: Metadata = { title: "Hibanapló" };
|
||||
|
||||
export default async function AdminErrorsPage() {
|
||||
const me = await requireMe("/admin/hibak");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/hibak" />
|
||||
<div className="page-head">
|
||||
<h1>Hibanapló</h1>
|
||||
<p className="muted">
|
||||
Az elemzések, válaszok és prompt-próbák minden sikertelen próbálkozása, a legújabb elöl. A worker írja; 90 napig
|
||||
őrizzük.
|
||||
</p>
|
||||
</div>
|
||||
<ErrorLog />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -647,3 +647,13 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.job-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
|
||||
.job-row > span:first-child { display: flex; flex-direction: column; min-width: 0; }
|
||||
@media (max-width: 640px) { .job-row { grid-template-columns: minmax(0, 1fr) auto; } .job-row .model-price { grid-column: 1 / -1; align-items: flex-start; } }
|
||||
.retry-notice { display: flex; flex-direction: column; gap: 4px; }
|
||||
.retry-notice p { margin: 0; }
|
||||
|
||||
/* admin: error log */
|
||||
.error-log { width: 100%; border-collapse: collapse; font-size: 14px; }
|
||||
.error-log th, .error-log td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
|
||||
.error-log td > .hint, .error-log td > code { display: block; }
|
||||
.error-log .error-text { overflow-wrap: anywhere; max-width: 460px; }
|
||||
.error-log .outcome { white-space: nowrap; }
|
||||
.error-log .outcome.tone-tense { color: var(--tense); font-weight: 600; }
|
||||
|
||||
Reference in New Issue
Block a user