Tarot readings have a topic: general, relationship, work, self-knowledge
The new reading form starts with the topic; it steers how the model reads the cards (with the topic's own limits, e.g. no break-up predictions for relationships) and shows on the reading and in the list. Readings from before count as general. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -117,6 +117,67 @@ pub fn spread(id: &str) -> Option<&'static Spread> {
|
||||
SPREADS.iter().find(|s| s.id == id)
|
||||
}
|
||||
|
||||
/// What the reading is about: it steers how the cards are read.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Topic {
|
||||
pub id: &'static str,
|
||||
pub name: &'static str,
|
||||
/// The instruction for the model (Hungarian, English).
|
||||
pub focus: (&'static str, &'static str),
|
||||
}
|
||||
|
||||
pub const TOPICS: [Topic; 4] = [
|
||||
Topic {
|
||||
id: "general",
|
||||
name: "Általános",
|
||||
focus: (
|
||||
"Általános jóslás: az olvasó élete egészére vonatkoztasd a lapokat.",
|
||||
"A general reading: relate the cards to the reader's life as a whole.",
|
||||
),
|
||||
},
|
||||
Topic {
|
||||
id: "love",
|
||||
name: "Párkapcsolat",
|
||||
focus: (
|
||||
"Párkapcsolati jóslás: minden lapot a szerelem, a vonzalom, a közelség, a bizalom és a kommunikáció \
|
||||
szemszögéből olvass, akár van kapcsolata az olvasónak, akár keres. Ne feltételezd a partner nemét, és ne \
|
||||
jósolj szakítást, hűtlenséget vagy azt, hogy valaki biztosan visszatér.",
|
||||
"A relationship reading: read every card through love, attraction, closeness, trust and communication, \
|
||||
whether the reader is in a relationship or looking for one. Do not assume the partner's gender, and do \
|
||||
not predict a break-up, infidelity or that someone will surely come back.",
|
||||
),
|
||||
},
|
||||
Topic {
|
||||
id: "work",
|
||||
name: "Munka és hivatás",
|
||||
focus: (
|
||||
"Munka és hivatás: a lapokat a munka, a hivatás, a tanulás, a munkahelyi kapcsolatok és a fejlődés \
|
||||
szemszögéből olvasd. Ne adj pénzügyi vagy jogi tanácsot, és ne jósolj elbocsátást vagy anyagi \
|
||||
nyereséget, veszteséget.",
|
||||
"Work and calling: read the cards through work, vocation, learning, relationships at work and growth. \
|
||||
Give no financial or legal advice, and do not predict dismissal or financial gains or losses.",
|
||||
),
|
||||
},
|
||||
Topic {
|
||||
id: "self",
|
||||
name: "Önismeret",
|
||||
focus: (
|
||||
"Önismeret: a lapokat a belső világ, az érzelmek, a minták és a lelki fejlődés szemszögéből olvasd; a \
|
||||
külső események helyett arra figyelj, mit tanulhat az olvasó önmagáról.",
|
||||
"Self-knowledge: read the cards through the inner world, feelings, patterns and inner growth; rather \
|
||||
than outer events, focus on what the reader can learn about themselves.",
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
/// A topic by id (`None`, and readings from before topics: general).
|
||||
pub fn topic(id: Option<&str>) -> Option<&'static Topic> {
|
||||
match id {
|
||||
None => TOPICS.first(),
|
||||
Some(id) => TOPICS.iter().find(|t| t.id == id),
|
||||
}
|
||||
}
|
||||
|
||||
/// The Hungarian name of a zodiac sign as the charts store it ("cancer").
|
||||
pub fn sign_hu(sign: &str) -> &'static str {
|
||||
match sign.to_ascii_lowercase().as_str() {
|
||||
@@ -142,6 +203,7 @@ pub fn sign_hu(sign: &str) -> &'static str {
|
||||
/// The cards are in the order of the spread's positions.
|
||||
pub struct Reading<'a> {
|
||||
pub spread: &'static Spread,
|
||||
pub topic: &'static Topic,
|
||||
pub question: Option<&'a str>,
|
||||
/// (card, reversed) per position.
|
||||
pub cards: Vec<(&'static Card, bool)>,
|
||||
@@ -171,6 +233,7 @@ impl<'a> Reading<'a> {
|
||||
let text = |k: &str| value[k].as_str().map(str::trim).filter(|s| !s.is_empty());
|
||||
Ok(Self {
|
||||
spread,
|
||||
topic: topic(text("topic")).ok_or("unknown topic")?,
|
||||
question: text("question"),
|
||||
cards,
|
||||
sun: text("sun"),
|
||||
@@ -284,12 +347,18 @@ pub fn build_tarot(language: &str, reading: &Reading) -> Prompt {
|
||||
let hu = language == "hu";
|
||||
let mut user = String::new();
|
||||
let none = if hu { "nincs megadva" } else { "not given" };
|
||||
user.push_str(&format!(
|
||||
"{}: {}. {}\n\n",
|
||||
if hu { "Téma" } else { "Topic" },
|
||||
reading.topic.name,
|
||||
if hu { reading.topic.focus.0 } else { reading.topic.focus.1 },
|
||||
));
|
||||
match reading.question {
|
||||
Some(q) => user.push_str(&format!("{}: {}\n\n", if hu { "A kérdés" } else { "The question" }, q.trim())),
|
||||
None => user.push_str(if hu {
|
||||
"Nincs konkrét kérdés: az olvasó a jelenlegi életszakaszára kér útmutatást.\n\n"
|
||||
"Nincs konkrét kérdés: az olvasó a témában a jelenlegi életszakaszára kér útmutatást.\n\n"
|
||||
} else {
|
||||
"No specific question: the reader asks for guidance about their present phase of life.\n\n"
|
||||
"No specific question: the reader asks for guidance on the topic in their present phase of life.\n\n"
|
||||
}),
|
||||
}
|
||||
let sign = |s: Option<&str>| {
|
||||
@@ -369,6 +438,8 @@ mod tests {
|
||||
"sun": "cancer", "moon": "pisces", "ascendant": null});
|
||||
let reading = Reading::parse(&value).unwrap();
|
||||
let prompt = build_tarot("hu", &reading);
|
||||
// Readings without a topic (the first ones) are general.
|
||||
assert!(prompt.user.starts_with("Téma: Általános."));
|
||||
assert!(prompt.user.contains("A kérdés: Merre induljak tovább?"));
|
||||
assert!(prompt.user.contains("Nap: Rák, Hold: Halak, Aszcendens: nincs megadva"));
|
||||
assert!(prompt.user.contains("2. Jelenlegi fókusz"));
|
||||
@@ -380,6 +451,15 @@ mod tests {
|
||||
let english = build_tarot("en", &reading);
|
||||
assert!(english.user.contains("Sun: Cancer") && english.system.contains("English"));
|
||||
|
||||
let mut love = value.clone();
|
||||
love["topic"] = json!("love");
|
||||
let prompt = build_tarot("hu", &Reading::parse(&love).unwrap());
|
||||
assert!(
|
||||
prompt.user.starts_with("Téma: Párkapcsolat.") && prompt.user.contains("Ne feltételezd a partner nemét")
|
||||
);
|
||||
love["topic"] = json!("pénz");
|
||||
assert!(Reading::parse(&love).is_err());
|
||||
|
||||
let wrong = json!({"spread": "daily", "cards": [{"card": "major-0"}, {"card": "major-1"}]});
|
||||
assert!(Reading::parse(&wrong).is_err());
|
||||
assert!(Reading::parse(&json!({"spread": "daily", "cards": [{"card": "nincs"}]})).is_err());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Kártyajóslás
|
||||
|
||||
A `/kartyajoslas` oldalon a felhasználó kirakást választ, opcionálisan kérdést ír (legfeljebb 300 karakter), és a legyezőbe terített, lefordított pakliból kiválasztja a lapokat. Ezután a lapok sorban felfordulnak, és elkészül a személyre szabott jóslás. A korábbi jóslások ugyanitt listázódnak, egyenként a `/kartyajoslas/{id}` oldalon nyithatók meg. A nyilvános példaoldal (`/kartyajoslas/pelda`) két előre megírt jóslást mutat fülekkel, egy munkáról (3 lap) és egy párkapcsolatról (Képlet-kereszt, 5 lap). Mindkettőnél animáció játssza le a húzást: lapválasztás a legyezőből, kirakás, felfordítás, végül megjelenik a szöveg (`src/components/tarot/TarotDemo.tsx`, a szövegek: `src/content/tarot-pelda.json`). Mozgáscsökkentő beállításnál rögtön a végállapot látszik.
|
||||
A `/kartyajoslas` oldalon a felhasználó témát (Általános, Párkapcsolat, Munka és hivatás, Önismeret; a téma szerinti olvasási szempont a promptba kerül, `TOPICS`) és kirakást választ, opcionálisan kérdést ír (legfeljebb 300 karakter), és a legyezőbe terített, lefordított pakliból kiválasztja a lapokat. Ezután a lapok sorban felfordulnak, és elkészül a személyre szabott jóslás. A korábbi jóslások ugyanitt listázódnak, egyenként a `/kartyajoslas/{id}` oldalon nyithatók meg. A nyilvános példaoldal (`/kartyajoslas/pelda`) két előre megírt jóslást mutat fülekkel, egy munkáról (3 lap) és egy párkapcsolatról (Képlet-kereszt, 5 lap). Mindkettőnél animáció játssza le a húzást: lapválasztás a legyezőből, kirakás, felfordítás, végül megjelenik a szöveg (`src/components/tarot/TarotDemo.tsx`, a szövegek: `src/content/tarot-pelda.json`). Mozgáscsökkentő beállításnál rögtön a végállapot látszik.
|
||||
|
||||
## Működés
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@ impl ReadingRow {
|
||||
"status": self.status,
|
||||
"spread": self.tarot["spread"],
|
||||
"spread_name": spread.map(|s| s.name),
|
||||
"topic": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.id),
|
||||
"topic_name": tarot::topic(self.tarot["topic"].as_str()).map(|t| t.name),
|
||||
"question": self.tarot["question"],
|
||||
"cards": cards,
|
||||
"content": self.content,
|
||||
@@ -147,6 +149,8 @@ pub async fn get_one(State(state): St, auth: AuthUser, WithRejection(Path(id), _
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NewReading {
|
||||
spread: String,
|
||||
/// `general` (the default), `love`, `work` or `self`.
|
||||
topic: Option<String>,
|
||||
question: Option<String>,
|
||||
}
|
||||
|
||||
@@ -157,6 +161,7 @@ pub async fn create(
|
||||
WithRejection(Json(req), _): Body<NewReading>,
|
||||
) -> ApiResult<(StatusCode, Json<Value>)> {
|
||||
let spread = tarot::spread(&req.spread).ok_or_else(|| ApiError::BadRequest("unknown spread".into()))?;
|
||||
let topic = tarot::topic(req.topic.as_deref()).ok_or_else(|| ApiError::BadRequest("unknown topic".into()))?;
|
||||
let question = req.question.map(|q| q.trim().replace("\r\n", "\n")).filter(|q| !q.is_empty());
|
||||
if question.as_ref().is_some_and(|q| q.chars().count() > TAROT_QUESTION_MAX_CHARS) {
|
||||
return Err(ApiError::BadRequest(format!(
|
||||
@@ -179,6 +184,7 @@ pub async fn create(
|
||||
let (sun, moon, ascendant) = big_three(&state, auth.id()).await?;
|
||||
let reading = json!({
|
||||
"spread": spread.id,
|
||||
"topic": topic.id,
|
||||
"question": question,
|
||||
"cards": draw(spread),
|
||||
"sun": sun,
|
||||
|
||||
@@ -2593,7 +2593,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
app.chart(&anna, "Saját", true, "1990-07-01").await;
|
||||
let body = json!({"spread": "trinity", "question": "Merre induljak tovább?"});
|
||||
let body = json!({"spread": "trinity", "topic": "love", "question": "Merre induljak tovább?"});
|
||||
// No units: a package or the addon is needed.
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), body.clone()).await;
|
||||
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED, "{}", r.body);
|
||||
@@ -2610,6 +2610,8 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "nincs"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "topic": "pénz"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let long = "x".repeat(analysis_prompt::TAROT_QUESTION_MAX_CHARS + 1);
|
||||
let r = app.post("/v1/tarot/readings", Some(&anna), json!({"spread": "daily", "question": long})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
@@ -2618,6 +2620,7 @@ async fn tarot_readings_draw_on_the_server_and_use_tarot_units(pool: PgPool) {
|
||||
assert_eq!(r.status, StatusCode::ACCEPTED, "{}", r.body);
|
||||
assert_eq!(r.body["status"], "pending");
|
||||
assert_eq!(r.body["spread_name"], "Sorsfonalak hármas");
|
||||
assert_eq!((&r.body["topic"], &r.body["topic_name"]), (&json!("love"), &json!("Párkapcsolat")));
|
||||
assert_eq!(r.body["question"], "Merre induljak tovább?");
|
||||
let cards = r.body["cards"].as_array().unwrap();
|
||||
assert_eq!(cards.len(), 3);
|
||||
|
||||
@@ -981,6 +981,15 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.tarot-spread:hover { border-color: #5a6790; }
|
||||
.tarot-spread.is-active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
|
||||
.tarot-spread:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.tarot-topics { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.tarot-topics legend { margin-bottom: 8px; }
|
||||
.tarot-topic {
|
||||
display: inline-flex; align-items: center; min-height: 38px; padding: 0 16px; cursor: pointer; font-size: 14px;
|
||||
border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel-2); color: var(--ink-2);
|
||||
}
|
||||
.tarot-topic:hover { border-color: #5a6790; }
|
||||
.tarot-topic.is-active { border-color: var(--gold); color: var(--gold); background: rgba(217, 180, 106, 0.08); }
|
||||
.tarot-topic:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.tarot-spread-name { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
|
||||
|
||||
.tarot-stage { align-items: stretch; }
|
||||
|
||||
@@ -24,6 +24,7 @@ export default async function TarotReadingPage({ params }: { params: Promise<{ i
|
||||
← Kártyajóslás
|
||||
</Link>
|
||||
<span className="eyebrow">
|
||||
{reading.topic_name ? `${reading.topic_name} · ` : ""}
|
||||
{reading.spread_name} · {day(reading.created_at)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,15 @@ import Link from "next/link";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { api, ApiError, errorText } from "@/lib/api";
|
||||
import { SPREADS, TAROT_QUESTION_MAX, tarotCard, type SpreadId, type TarotReading } from "@/lib/tarot";
|
||||
import {
|
||||
SPREADS,
|
||||
TAROT_QUESTION_MAX,
|
||||
TOPICS,
|
||||
tarotCard,
|
||||
type SpreadId,
|
||||
type TarotReading,
|
||||
type TopicId,
|
||||
} from "@/lib/tarot";
|
||||
import type { PayMethod, UnitBalance } from "@/lib/types";
|
||||
|
||||
import { PackageChooser } from "../PackageCards";
|
||||
@@ -40,6 +48,7 @@ export function TarotTable({
|
||||
const [readings, setReadings] = useState(initialReadings);
|
||||
const [left, setLeft] = useState(initialLeft);
|
||||
const [spread, setSpread] = useState<SpreadId>("trinity");
|
||||
const [topic, setTopic] = useState<TopicId>("general");
|
||||
const [question, setQuestion] = useState("");
|
||||
const [phase, setPhase] = useState<Phase>("setup");
|
||||
const [picked, setPicked] = useState<number[]>([]);
|
||||
@@ -68,7 +77,7 @@ export function TarotTable({
|
||||
setError(null);
|
||||
try {
|
||||
const reading = await api<TarotReading>("/tarot/readings", {
|
||||
body: { spread, question: question.trim() || null },
|
||||
body: { spread, topic, question: question.trim() || null },
|
||||
});
|
||||
setCurrent(reading);
|
||||
setReadings((all) => [reading, ...all]);
|
||||
@@ -86,7 +95,7 @@ export function TarotTable({
|
||||
}
|
||||
}
|
||||
},
|
||||
[spread, question],
|
||||
[spread, topic, question],
|
||||
);
|
||||
|
||||
function pick(i: number) {
|
||||
@@ -151,6 +160,22 @@ export function TarotTable({
|
||||
</div>
|
||||
) : (
|
||||
<form className="field" style={{ gap: 18 }} onSubmit={start}>
|
||||
<fieldset className="tarot-topics">
|
||||
<legend className="label">Téma</legend>
|
||||
{TOPICS.map((t) => (
|
||||
<label key={t.id} className={t.id === topic ? "tarot-topic is-active" : "tarot-topic"}>
|
||||
<input
|
||||
type="radio"
|
||||
name="topic"
|
||||
value={t.id}
|
||||
checked={t.id === topic}
|
||||
onChange={() => setTopic(t.id)}
|
||||
className="sr-only"
|
||||
/>
|
||||
{t.name}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
<fieldset className="tarot-spreads">
|
||||
<legend className="label">Kirakás</legend>
|
||||
{SPREADS.map((s) => (
|
||||
@@ -176,7 +201,7 @@ export function TarotTable({
|
||||
rows={2}
|
||||
maxLength={TAROT_QUESTION_MAX}
|
||||
value={question}
|
||||
placeholder="Pl. Mire figyeljek, ha munkahelyet váltanék? Kérdés nélkül általános útmutatást kapsz."
|
||||
placeholder={`${TOPICS.find((x) => x.id === topic)?.example ?? ""} Kérdés nélkül a témában kapsz útmutatást.`}
|
||||
onChange={(e) => setQuestion(e.target.value)}
|
||||
/>
|
||||
<span className="hint">
|
||||
@@ -208,7 +233,9 @@ export function TarotTable({
|
||||
{phase !== "setup" && (
|
||||
<section className="card tarot-stage" aria-labelledby="tarot-stage-title">
|
||||
<div className="tarot-stage-head">
|
||||
<span className="eyebrow">{current?.spread_name ?? chosen.name}</span>
|
||||
<span className="eyebrow">
|
||||
{current?.spread_name ?? chosen.name} · {current?.topic_name ?? TOPICS.find((x) => x.id === topic)?.name}
|
||||
</span>
|
||||
<h2 id="tarot-stage-title">
|
||||
{phase === "picking"
|
||||
? `Válassz ${chosen.cards} lapot a pakliból`
|
||||
@@ -266,7 +293,8 @@ export function TarotTable({
|
||||
<span className="tarot-history-text">
|
||||
<strong>{r.content?.title ?? r.question ?? r.spread_name}</strong>
|
||||
<span className="hint">
|
||||
{day(r.created_at)} · {r.spread_name}
|
||||
{day(r.created_at)} · {r.topic_name ? `${r.topic_name} · ` : ""}
|
||||
{r.spread_name}
|
||||
{r.question && r.content ? ` · „${r.question}”` : ""}
|
||||
{r.status === "pending" || r.status === "running" ? " · készül" : ""}
|
||||
{r.status === "failed" ? " · nem sikerült" : ""}
|
||||
|
||||
@@ -43,6 +43,16 @@ export const SPREADS: { id: SpreadId; name: string; cards: number; about: string
|
||||
},
|
||||
];
|
||||
|
||||
export type TopicId = "general" | "love" | "work" | "self";
|
||||
|
||||
/** What a reading is about (the backend's `TOPICS`), with an example question. */
|
||||
export const TOPICS: { id: TopicId; name: string; example: string }[] = [
|
||||
{ id: "general", name: "Általános", example: "Pl. Mire figyeljek a következő hetekben?" },
|
||||
{ id: "love", name: "Párkapcsolat", example: "Pl. Mit tehetek azért, hogy közelebb kerüljünk egymáshoz?" },
|
||||
{ id: "work", name: "Munka és hivatás", example: "Pl. Mire figyeljek, ha munkahelyet váltanék?" },
|
||||
{ id: "self", name: "Önismeret", example: "Pl. Mit tanulhatok most önmagamról?" },
|
||||
];
|
||||
|
||||
/** Longest question (the backend's `TAROT_QUESTION_MAX_CHARS`). */
|
||||
export const TAROT_QUESTION_MAX = 300;
|
||||
|
||||
@@ -60,6 +70,8 @@ export interface TarotReading {
|
||||
status: "pending" | "running" | "done" | "failed";
|
||||
spread: SpreadId;
|
||||
spread_name: string | null;
|
||||
topic: TopicId | null;
|
||||
topic_name: string | null;
|
||||
question: string | null;
|
||||
cards: { card: string; reversed: boolean; position: string | null; about: string | null }[];
|
||||
content: TarotContent | null;
|
||||
|
||||
Reference in New Issue
Block a user