Editable analysis prompts on the admin page
The system prompts of the free summary and the paid detailed analysis can be edited per language under /admin/promptok. Every save is a new row in prompt_revisions (NULL = built-in text); new analyses record the revision in prompt_version (v2-r<id>) and the worker uses exactly that text. Existing analyses stay; the cross-user cache only copies results of the same revision. The prompt code moves to the shared analysis-prompt crate so the backend can show the built-in text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { AdminUsers } from "./AdminUsers";
|
||||
@@ -13,6 +14,7 @@ export default async function AdminPage() {
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin" />
|
||||
<div className="page-head">
|
||||
<h1>Felhasználók</h1>
|
||||
<p className="muted">Szerepkörök kezelése és részletes elemzések jóváírása (ajándék, reklamáció). A vásárlások is ide könyvelődnek majd.</p>
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { Tabs } from "@/components/Tabs";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { AdminPrompt, PromptKind } from "@/lib/types";
|
||||
|
||||
const KINDS: { kind: PromptKind; id: string; label: string; about: string }[] = [
|
||||
{
|
||||
kind: "summary",
|
||||
id: "osszefoglalo",
|
||||
label: "Tömör összefoglaló",
|
||||
about: "Ingyenes, a képlet oldalán a „Röviden” blokk: egy cím és 3–4 mondat. Minden új képlethez magától elkészül.",
|
||||
},
|
||||
{
|
||||
kind: "natal",
|
||||
id: "reszletes",
|
||||
label: "Részletes elemzés",
|
||||
about: "Fizetős, hat fejezet, erősségek, kihívások és útravaló. Kérésre készül.",
|
||||
},
|
||||
];
|
||||
|
||||
const LANGUAGES: Record<string, string> = { hu: "Magyar", en: "Angol" };
|
||||
|
||||
export function AdminPrompts() {
|
||||
const [prompts, setPrompts] = useState<AdminPrompt[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api<{ prompts: AdminPrompt[] }>("/admin/prompts")
|
||||
.then((d) => setPrompts(d.prompts))
|
||||
.catch((e) => setError(errorText(e)));
|
||||
}, []);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (!prompts) return <p className="muted">Betöltés…</p>;
|
||||
|
||||
const replace = (next: AdminPrompt) =>
|
||||
setPrompts((all) => all?.map((p) => (p.kind === next.kind && p.language === next.language ? next : p)) ?? null);
|
||||
|
||||
return (
|
||||
<section className="card">
|
||||
<Tabs
|
||||
label="Elemzésfajták"
|
||||
tabs={KINDS.map((k) => ({
|
||||
id: k.id,
|
||||
label: k.label,
|
||||
content: (
|
||||
<KindPrompts about={k.about} prompts={prompts.filter((p) => p.kind === k.kind)} onSaved={replace} />
|
||||
),
|
||||
}))}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function KindPrompts({
|
||||
about,
|
||||
prompts,
|
||||
onSaved,
|
||||
}: {
|
||||
about: string;
|
||||
prompts: AdminPrompt[];
|
||||
onSaved: (p: AdminPrompt) => void;
|
||||
}) {
|
||||
const [language, setLanguage] = useState(prompts[0]?.language ?? "hu");
|
||||
const prompt = prompts.find((p) => p.language === language) ?? prompts[0];
|
||||
if (!prompt) return null;
|
||||
return (
|
||||
<div className="prompt-kind">
|
||||
<div className="prompt-kind-head">
|
||||
<p className="muted">{about}</p>
|
||||
{prompts.length > 1 && (
|
||||
<div className="field prompt-lang">
|
||||
<label htmlFor={`lang-${prompt.kind}`}>Nyelv</label>
|
||||
<select
|
||||
id={`lang-${prompt.kind}`}
|
||||
className="inp"
|
||||
value={language}
|
||||
onChange={(e) => setLanguage(e.target.value)}
|
||||
>
|
||||
{prompts.map((p) => (
|
||||
<option key={p.language} value={p.language}>
|
||||
{LANGUAGES[p.language] ?? p.language}
|
||||
{p.custom ? " (szerkesztett)" : ""}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<PromptEditor key={`${prompt.kind}-${prompt.language}`} prompt={prompt} onSaved={onSaved} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PromptEditor({ prompt, onSaved }: { prompt: AdminPrompt; onSaved: (p: AdminPrompt) => void }) {
|
||||
const [draft, setDraft] = useState(prompt.system);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const dirty = draft.trim() !== prompt.system.trim();
|
||||
const id = `prompt-${prompt.kind}-${prompt.language}`;
|
||||
|
||||
useEffect(() => {
|
||||
if (!dirty) return;
|
||||
const warn = (e: BeforeUnloadEvent) => e.preventDefault();
|
||||
window.addEventListener("beforeunload", warn);
|
||||
return () => window.removeEventListener("beforeunload", warn);
|
||||
}, [dirty]);
|
||||
|
||||
async function save(system: string | null) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setSaved(false);
|
||||
try {
|
||||
const next = await api<AdminPrompt>(`/admin/prompts/${prompt.kind}/${prompt.language}`, {
|
||||
method: "PUT",
|
||||
body: { system },
|
||||
});
|
||||
onSaved(next);
|
||||
setDraft(next.system);
|
||||
setSaved(true);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="prompt-editor">
|
||||
<div className="prompt-status">
|
||||
{prompt.custom ? (
|
||||
<span className="badge badge-gold">Szerkesztett</span>
|
||||
) : (
|
||||
<span className="badge">Alapértelmezett</span>
|
||||
)}
|
||||
{prompt.updated_at && (
|
||||
<span className="hint">
|
||||
Utoljára mentve: {formatDate(prompt.updated_at, true)}
|
||||
{prompt.updated_by ? ` · ${prompt.updated_by}` : ""}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor={id}>Utasítások a modellnek (system prompt)</label>
|
||||
<textarea
|
||||
id={id}
|
||||
className="inp prompt-text"
|
||||
value={draft}
|
||||
onChange={(e) => {
|
||||
setDraft(e.target.value);
|
||||
setSaved(false);
|
||||
}}
|
||||
spellCheck={false}
|
||||
rows={24}
|
||||
/>
|
||||
<span className="hint">
|
||||
{draft.length.toLocaleString("hu-HU")} karakter
|
||||
{dirty ? " · mentetlen változás" : ""}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{saved && !dirty && (
|
||||
<p className="msg msg-ok" role="status">
|
||||
Elmentve. Az ezután kért elemzések már ezzel készülnek.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => save(draft)} disabled={busy || !dirty}>
|
||||
{busy ? "Mentés…" : "Mentés"}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setDraft(prompt.system)} disabled={busy || !dirty}>
|
||||
Változások elvetése
|
||||
</button>
|
||||
{(prompt.custom || draft.trim() !== prompt.default.trim()) && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost"
|
||||
onClick={() => setDraft(prompt.default)}
|
||||
disabled={busy || draft.trim() === prompt.default.trim()}
|
||||
>
|
||||
Alapértelmezett szöveg betöltése
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<details className="details">
|
||||
<summary>Amit a modell ezen felül kap</summary>
|
||||
<div className="prompt-extra">
|
||||
<p className="hint">
|
||||
Ezt a kód állítja össze, nem szerkeszthető. A <code>{"{chart data}"}</code> helyére a képlet pozíciói kerülnek
|
||||
(név, dátum és hely nélkül). A válasz formáját (mezők, fejezetek) egy rögzített JSON-séma írja elő.
|
||||
</p>
|
||||
<pre className="prompt-pre">{prompt.user_template}</pre>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
{prompt.history.length > 0 && (
|
||||
<details className="details">
|
||||
<summary>Korábbi változatok ({prompt.history.length})</summary>
|
||||
<ul className="prompt-history">
|
||||
{prompt.history.map((h, i) => (
|
||||
<li key={h.id}>
|
||||
<span>
|
||||
{formatDate(h.created_at, true)}
|
||||
{h.created_by ? ` · ${h.created_by}` : ""}
|
||||
</span>
|
||||
<span className="hint">
|
||||
{i === 0 ? "érvényben · " : ""}
|
||||
{h.custom ? `${(h.system ?? "").length.toLocaleString("hu-HU")} karakter` : "alapértelmezett"}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm"
|
||||
onClick={() => setDraft(h.system ?? prompt.default)}
|
||||
disabled={busy}
|
||||
>
|
||||
Betöltés
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="hint">A betöltött változat a szerkesztőbe kerül; a mentéssel lesz érvényes.</p>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 { AdminPrompts } from "./AdminPrompts";
|
||||
|
||||
export const metadata: Metadata = { title: "Promptok" };
|
||||
|
||||
export default async function AdminPromptsPage() {
|
||||
const me = await requireMe("/admin/promptok");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/promptok" />
|
||||
<div className="page-head">
|
||||
<h1>Promptok</h1>
|
||||
<p className="muted">
|
||||
Az elemzéseket író modell utasításai. A változás az ezután kért elemzésekre hat; a már elkészültek
|
||||
változatlanok maradnak.
|
||||
</p>
|
||||
</div>
|
||||
<AdminPrompts />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -404,3 +404,40 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.legal a { color: var(--gold); }
|
||||
.legal-table td { vertical-align: top; line-height: 1.5; }
|
||||
.danger-box { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--danger); border-radius: var(--radius); }
|
||||
|
||||
/* Admin */
|
||||
.admin-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-x: auto; }
|
||||
.admin-nav a {
|
||||
padding: 10px 14px; min-height: 44px; display: inline-flex; align-items: center; color: var(--muted);
|
||||
text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
|
||||
}
|
||||
.admin-nav a:hover { color: var(--ink); }
|
||||
.admin-nav a[aria-current="page"] { color: var(--gold); border-bottom-color: var(--gold); }
|
||||
.prompt-kind { display: flex; flex-direction: column; gap: 20px; }
|
||||
.prompt-kind-head { display: flex; gap: 16px 24px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
|
||||
.prompt-kind-head > p { flex: 1 1 360px; margin: 0; }
|
||||
.prompt-lang { width: 200px; }
|
||||
.prompt-editor { display: flex; flex-direction: column; gap: 16px; }
|
||||
.prompt-status { display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap; }
|
||||
.prompt-text {
|
||||
min-height: 420px; padding: 12px 14px; resize: vertical; line-height: 1.55;
|
||||
font: 400 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
.prompt-extra { display: flex; flex-direction: column; gap: 10px; }
|
||||
.prompt-pre {
|
||||
margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
|
||||
white-space: pre-wrap; overflow-wrap: anywhere; font: 400 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
color: var(--ink-2);
|
||||
}
|
||||
.prompt-history { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; }
|
||||
.prompt-history li {
|
||||
display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
|
||||
padding: 8px 0; border-bottom: 1px solid var(--line);
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.prompt-text { min-height: 320px; font-size: 13px; }
|
||||
.prompt-lang { width: 100%; }
|
||||
.prompt-history li { grid-template-columns: 1fr auto; }
|
||||
.prompt-history li .hint { grid-column: 1; }
|
||||
.prompt-history li .btn { grid-column: 2; grid-row: 1 / span 2; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user