Free chart summaries; password login off by default
- New analysis kind 'summary' (migration 0005): saving a chart queues a
free 3-4 sentence summary written by SUMMARY_MODEL (default Sonnet
5.5, about 1 cent; Haiku was tested too but chose weaker highlights).
POST /v1/charts/{id}/summary returns it and re-queues a failed one.
- The chart page shows it in a "Röviden" card and polls until ready.
- PASSWORD_LOGIN (default false): register, login and password reset
answer 403; only Google (later Apple, Facebook) logins remain.
- Prompt v2: Hungarian names for elements and modalities (an English
"Fire" slipped into a summary); worker compare-models --summary.
- The worker also reads a lower-case openrouter_api_key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -148,6 +148,16 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.gsi-slot { min-height: 44px; display: flex; justify-content: center; }
|
||||
|
||||
/* Chart page */
|
||||
.summary-card { gap: 10px; border-color: rgba(217, 180, 106, 0.35); }
|
||||
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); }
|
||||
.summary-title { font-size: 26px; }
|
||||
.summary-text { font-size: 16px; line-height: 1.65; color: var(--ink-2); }
|
||||
.summary-text strong { color: var(--ink); font-weight: 600; }
|
||||
.skeleton { display: flex; flex-direction: column; gap: 8px; }
|
||||
.skeleton span { height: 12px; border-radius: 6px; background: var(--line); animation: pulse 1.4s ease-in-out infinite; }
|
||||
.skeleton span:last-child { width: 60%; }
|
||||
@keyframes pulse { 50% { opacity: 0.45; } }
|
||||
@media (prefers-reduced-motion: reduce) { .skeleton span { animation: none; } }
|
||||
.chart-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, 1fr); gap: 24px; align-items: start; }
|
||||
.chart-wheel-card { padding: 16px; gap: 10px; }
|
||||
.chart-wheel { width: 100%; height: auto; display: block; max-width: 680px; margin: 0 auto; }
|
||||
|
||||
@@ -3,10 +3,11 @@ import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { BigThree, ChartTables } from "@/components/ChartTables";
|
||||
import { ChartSummary } from "@/components/ChartSummary";
|
||||
import { ChartWheel } from "@/components/ChartWheel";
|
||||
import { ELEMENTS, MODALITIES, MOON_PHASES, countryName, formatBirthDate, pointName } from "@/lib/astro";
|
||||
import { backendGet, requireMe } from "@/lib/server";
|
||||
import type { Chart } from "@/lib/types";
|
||||
import type { Analysis, Chart } from "@/lib/types";
|
||||
|
||||
export const metadata: Metadata = { title: "Képlet" };
|
||||
|
||||
@@ -17,8 +18,12 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
const { id } = await params;
|
||||
await requireMe(`/kepletek/${id}`);
|
||||
if (!UUID.test(id)) notFound();
|
||||
const chart = await backendGet<Chart>(`/v1/charts/${id}`);
|
||||
const [chart, analyses] = await Promise.all([
|
||||
backendGet<Chart>(`/v1/charts/${id}`),
|
||||
backendGet<{ analyses: Analysis[] }>(`/v1/charts/${id}/analyses`),
|
||||
]);
|
||||
if (!chart) notFound();
|
||||
const summary = analyses?.analyses.find((a) => a.kind === "summary" && a.status !== "failed") ?? null;
|
||||
|
||||
const result = chart.chart;
|
||||
const timeKnown = chart.highlights.time_known;
|
||||
@@ -56,6 +61,7 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
</p>
|
||||
</div>
|
||||
<div className="field" style={{ gap: 16 }}>
|
||||
<ChartSummary chartId={chart.id} initial={summary} />
|
||||
<BigThree chart={chart} />
|
||||
{(elements || modalities || phase) && (
|
||||
<div className="card" style={{ gap: 12 }}>
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import type { Analysis } from "@/lib/types";
|
||||
|
||||
const POLL_MS = 3000;
|
||||
const MAX_POLLS = 60;
|
||||
|
||||
/** `**bold**` → <strong>; the rest is plain text. */
|
||||
function Rich({ text }: { text: string }) {
|
||||
return (
|
||||
<>
|
||||
{text.split(/(\*\*[^*]+\*\*)/g).map((part, i) =>
|
||||
part.startsWith("**") && part.endsWith("**") ? <strong key={i}>{part.slice(2, -2)}</strong> : part,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The free short summary of a chart. The backend queues it when the chart is
|
||||
* saved; this asks for it (queueing it again if it failed) and polls until the
|
||||
* worker has written it.
|
||||
*/
|
||||
export function ChartSummary({ chartId, initial }: { chartId: string; initial: Analysis | null }) {
|
||||
const [summary, setSummary] = useState<Analysis | null>(initial);
|
||||
const [gaveUp, setGaveUp] = useState(false);
|
||||
const done = summary?.status === "done";
|
||||
|
||||
useEffect(() => {
|
||||
if (done) return;
|
||||
let polls = 0;
|
||||
let stopped = false;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const tick = async () => {
|
||||
try {
|
||||
const next = await api<Analysis>(`/charts/${chartId}/summary`, { method: "POST" });
|
||||
if (stopped) return;
|
||||
setSummary(next);
|
||||
if (next.status === "done") return;
|
||||
} catch {
|
||||
// try again on the next tick
|
||||
}
|
||||
if (++polls >= MAX_POLLS) return setGaveUp(true);
|
||||
timer = setTimeout(tick, POLL_MS);
|
||||
};
|
||||
tick();
|
||||
return () => {
|
||||
stopped = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [chartId, done]);
|
||||
|
||||
const content = done ? summary?.content : null;
|
||||
return (
|
||||
<section className="card summary-card" aria-labelledby="summary-title" aria-busy={!done}>
|
||||
<span className="eyebrow">Röviden</span>
|
||||
{content ? (
|
||||
<>
|
||||
<h2 id="summary-title" className="summary-title">
|
||||
{content.title}
|
||||
</h2>
|
||||
<p className="summary-text">
|
||||
<Rich text={content.summary ?? ""} />
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<h2 id="summary-title" className="sr-only">
|
||||
Rövid összefoglaló
|
||||
</h2>
|
||||
<p className="muted" role="status">
|
||||
{gaveUp || summary?.status === "failed"
|
||||
? "Az összefoglaló most nem készült el. Töltsd újra az oldalt egy kicsit később."
|
||||
: "Az összefoglalód készül, ez néhány másodperc…"}
|
||||
</p>
|
||||
{!gaveUp && summary?.status !== "failed" && (
|
||||
<div className="skeleton" aria-hidden="true">
|
||||
<span />
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -82,6 +82,18 @@ export interface Chart {
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Analysis {
|
||||
id: string;
|
||||
kind: "natal" | "synastry" | "summary";
|
||||
status: "pending" | "running" | "done" | "failed";
|
||||
model: string;
|
||||
language: string;
|
||||
content: { title?: string; summary?: string } & Record<string, unknown> | null;
|
||||
credits_charged: number;
|
||||
created_at: string;
|
||||
completed_at: string | null;
|
||||
}
|
||||
|
||||
export interface AdminUser {
|
||||
id: string;
|
||||
email: string;
|
||||
|
||||
Reference in New Issue
Block a user