feat(chat): questions on every new conversation with a refresh icon (BUG-2282); the waiting screen draws the person's chart and plain steps from the run's real events (BUG-2283)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
@@ -30815,3 +30815,30 @@
|
||||
- 防复发:新形状的节名和标签只在 `chat-answer-shape.ts` 里定义,写法、解析和页面都引用它;改标题必须同时过 `chat-answer-shape-2281` 的解析和渲染测试。旧回答渲染由同一测试逐字比对。
|
||||
- 关联记录:BUG-2247(正文说人话、编号和判断依据,本次在它上面改形状和长度)、BUG-2248(加粗配对,新形状照常经过)、BUG-2241(土星压力段覆盖,时间条语气用它)、BUG-2239(运期覆盖行)、BUG-2235(补写只补必看层)、BUG-2229(问答写法)、BUG-1539(推荐问题按回答生成;新形状的回答自带)、BUG-2182(用户要的长度优先,照旧)。
|
||||
- 修复版本:分支 `claude/chat-ux-answer`(本地提交,待父会话推送 staging)。
|
||||
|
||||
## BUG-2282 | 新对话进来不知道问什么:常用问题藏在输入框的小按钮里,三个起步问题只在第一次免费提问前出现
|
||||
|
||||
- 状态:fixed-pending-verify(待负责人看截图、staging 实测)。
|
||||
- 首次发现 / 最近更新:2026-11-24 / 2026-11-24。
|
||||
- 现象:内测用户反馈,进来以后不知道该问什么;「常用问题」藏在输入框左边的小按钮里;首页的三个起步问题只在第一次免费提问还没用掉时出现(BUG-1431、BUG-2144),老用户新开对话只有问候语和输入框。
|
||||
- 触发条件:任何已建档用户新开一个空的问答对话(首问免费已用过)。
|
||||
- 根因:不是代码缺陷。BUG-1431 定的「起步三问只在首问免费未用时显示」;之后常用问题库(12 组,每组 5 条)只从输入框按钮进入。
|
||||
- 修复(负责人 2026-11-24 同意原型「刚进来」,同日改为一次三问 + 刷新图标):`frontend/src/app/(app)/page.tsx` 新增 `starterQuestionsVisible`:首问免费未用时照旧(`newcomerHome`),另外在每个新的空问答对话里也显示(不含合盘对话、已删的人、旧的生时纠正对话)。`StarterQuestions` 改为三张卡,每张前面一个话题词(例如「性格」「工作」「感情」「钱」,`starter-question-topic`,说明文字样式,无提示副标题),点一下就发;标题右边一枚刷新图标(`aria-label` 「换一组」,ghost 图标按钮),点一下三张一起换成下一组,三个不同话题,循环。第一组就是原来的三个起步问题(「我是一个什么样的人?」「未来两年事业有哪些变化」「今年推进重要计划,先看什么?」,第三问仍带 plan-timing 入口,出生时间是估的仍链到生时纠正);之后各组取自常用问题库(`starterLibrarySets`:工作 / 感情 / 钱 / 性格在前,其余话题按库的顺序;只取不用填空就能发的、标题里没有术语的问题;帮别人看时沿用「我」换成对方称呼的规则)。卡片固定高度(电脑 88px,两行问题 + 话题词;手机 68px,话题词在左),换一组时输入框不动;换组淡入 180ms,减少动态时没有动画。标题:首问免费未用时仍是「从这三个问题开始」(BUG-2201),老用户是原型的「想知道什么,点一个就能问」。
|
||||
- 老用户的变化:新开的空对话里,问候语下面多了这一块(标题、刷新图标、三张卡),其他不变:星盘面板照旧按已存的开合状态(只有新手首页默认收起,`useStarterChartFold(newcomerHome)` 未改);输入框的「常用问题」按钮照旧;扣点、首问免费的判断和发送路径(`startSuggestedConsultation`)不变。
|
||||
- 验证:新增 `frontend/tests/starter-arrive-2282.test.tsx`(第一组与话题词、后续各组三个不同话题、无术语、可直接发、不重复、帮别人看换称呼;点一下发送、刷新换组并循环回第一组;每个新空对话显示、新手标题和收起与扣点条件不变;固定卡高与减少动态)。按原值 / 新值 / 原因更新:`onboarding-intake-20261022`、`onboarding-three-screens-2144`、`newcomer-2200-2201`、`starter-plan-entrypoint-2160`。截图(组件渲染,用产品编译后的样式表;登录态的真实页面本机没有起):`/workspace/eval-read-1116/chat-ux-prototype/build/entry-arrive-{phone,desktop}-{light,dark}.png`。
|
||||
- 防复发:上面的测试。
|
||||
- 关联记录:BUG-1431、BUG-2144、BUG-2160、BUG-2199、BUG-2201、BUG-2279(协调窗口的「换一组」,本条在每个新对话上实现同样行为并加话题词)。
|
||||
- 修复版本:分支 `claude/chat-ux-entry-wait`(未推送)。
|
||||
|
||||
## BUG-2283 | 等回答的时候只有一行文字,感觉不到是在看自己的星盘
|
||||
|
||||
- 状态:fixed-pending-verify(待负责人看截图、staging 实测)。
|
||||
- 首次发现 / 最近更新:2026-11-24 / 2026-11-24。
|
||||
- 现象:内测用户反馈,产品不像是在解读她自己的盘;等回答的半分钟到两分钟里只有一行状态(BUG-2048)。
|
||||
- 触发条件:任何问答在回答出字之前。
|
||||
- 根因:不是代码缺陷。BUG-2048 的一行状态只说「正在……」,不画盘。
|
||||
- 修复(负责人 2026-11-24 同意原型「等回答的时候」,盘上不画星):回答出字前,回答位置上显示这次问的那个人的星盘(产品自己的 `ChartBoardSvg`,用户选的南北式,220px,只有格子,不画星、不写星座和宫号),上面一行小字说是哪张盘(默认「本命盘」),下面是白话步骤。全部由路由已经发出的真实事件驱动,没有计时器(`frontend/src/lib/chat-wait-progress.ts`):`skill.started`(对话第一问)→「先看性格的底子」亮「性格」;`tool.started` 带的领域 → 每个领域一行(「再看事业这一块」等),亮这个领域在路由里的宫(`requiredLayers` 里的宫号,经共用表 `frontend/src/lib/chat-chart-areas.ts` 写成白话名);`chart-calculation` 的「第 i/N 项」→ 第 i 个领域成为当前;`tool.completed` 且路由的领域要用 D10 / D9 →「换到专门看事业 / 感情的那张盘」,画面换成那张盘、只亮它对应的一块,标题换成白话名;查卡外资料的 `activity`「正在多看一眼:D10 分盘…」同样换盘(只认 D10、D9 两张有白话名的盘),查大运、行运类 →「(回到本命盘,)对一遍这几年的时间」,查别的 →「再多看一处细节」;`answer-composition`(不是查资料那句)、`phase.started compose`、第一段正文 →「正在整理回答」。亮过的地方一直亮着;换盘那一步结束后回到本命盘,之前的地方仍亮。某一步慢,就一直停在那一步。接着问的回合不显示第一步,列表更短。盘的数据只读页面已经有的星盘缓存(`peekChartPage`,同一个人才用),不发任何请求;没有缓存时只显示步骤;South 式缺那张分盘时不换画面。事件对不上(旧路径、闲聊、出错、接着问还没到领域)时照旧显示原来的一行状态;原来的一行状态一直挂着(隐藏),用时和完成后「分析了 N 步」不变。正文一出字就回到原来的一行「正在写回答」,回答不被推动。亮的格子 0.5s 淡入,减少动态时直接出现;读屏读步骤列表和一条 `aria-live` 的当前步骤,盘是带标签的装饰图。聊天里没有「可以先离开」这类现成的句子,没有新加。
|
||||
- 验证:新增 `frontend/tests/chat-wait-progress-2283.test.tsx`(7 条:共用表与领域取宫、事业 / 钱 / 感情 / 综合 / 两个领域的步骤与亮区、只在事件出现时换盘、退回一行状态的各种情况、组件渲染与隐藏的一行状态、不发请求不画星、缺分盘时南北式的处理),事件序列按 `stream-agent-response.ts` 和 `consultation-tools.ts` 实际发出的顺序录入。截图(组件渲染:真实组件 + 产品编译后的样式表 + 测试用的公开示例盘,未登录真实页面):`/workspace/eval-read-1116/chat-ux-prototype/build/entry-wait-{early,switch,last}-{phone,desktop}-{light,dark}.png`、`entry-wait-switch-south-phone-light.png`。
|
||||
- 防复发:上面的测试;`use-consultation-run.ts` 用同一份事件喂时间线和等待画面。
|
||||
- 关联记录:BUG-2048、BUG-2053、BUG-2241(改成白话那一步已去掉,不出现在步骤里)、BUG-2281(回答里的「从你的星盘里看出来的」用同一张白话表)。
|
||||
- 修复版本:分支 `claude/chat-ux-entry-wait`(未推送)。
|
||||
|
||||
@@ -574,6 +574,11 @@ export default function Home() {
|
||||
const newcomerHome = starterHomeVisible && account?.firstConsultFree === true
|
||||
&& (currentSubjectId === "self" ? selfChartComplete(profile) : Boolean(dailyProfile && selfChartComplete(dailyProfile)));
|
||||
useStarterChartFold(newcomerHome);
|
||||
// BUG-2282: the three questions show on every new, empty conversation (原值:只在首问免费未用时,BUG-1431;
|
||||
// 原因:内测用户进来不知道问什么,负责人 2026-11-24 同意原型「刚进来」). The fold and the first-question billing are unchanged.
|
||||
const starterQuestionsVisible = newcomerHome || (starterHomeVisible
|
||||
&& activeSession?.sessionType === "consultation"
|
||||
&& !synastryChat && !subjectDeleted && !retiredRectificationSession);
|
||||
// BUG-2144: every onboarding screen, the name included, is a card; the composer waits until the chart is made.
|
||||
const onboardingFormActive = !synastryChat && subjectCatalogReady && !profileComplete;
|
||||
const starterHasPriorSessions = sessions.some((session) => session.id !== activeSession?.id);
|
||||
@@ -1066,8 +1071,9 @@ export default function Home() {
|
||||
</div>
|
||||
|
||||
{!onboardingFormActive && <div className={`composer-wrap ${starterHomeVisible ? "composer-wrap-starter" : ""}`}>
|
||||
{newcomerHome ? (
|
||||
{starterQuestionsVisible ? (
|
||||
<StarterQuestions
|
||||
newcomer={newcomerHome}
|
||||
audience={currentSubjectId !== "self" && dailyProfile
|
||||
? { kind: "other", name: dailyProfile.name.trim() || "TA", relationLabel: personRelationLabel(dailyProfile.relation) }
|
||||
: { kind: "self" }}
|
||||
|
||||
@@ -614,13 +614,27 @@ button:disabled:where(:not([data-slot="button"])) { cursor: default; opacity: .4
|
||||
.starter-questions { display: grid; justify-items: center; gap: 8px; width: min(var(--session-column-width), 100%); margin: 0 auto var(--space-3); }
|
||||
/* BUG-2201: the newcomer home is headed by 「从这三个问题开始」 (display serif, the onboarding card heading's size). */
|
||||
.starter-questions-title { margin: 0 0 var(--space-1); color: var(--color-ink); font-family: var(--font-display); font-size: var(--type-title-md); font-weight: 500; letter-spacing: -.3px; line-height: 1.3; text-align: center; }
|
||||
/* BUG-2282: the heading carries the 「换一组」 refresh icon right after it; the heading stays centred. */
|
||||
.starter-questions-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 2px; width: 100%; margin: 0 0 var(--space-1); }
|
||||
.starter-questions-head .starter-questions-title { grid-column: 2; margin: 0; }
|
||||
.starter-questions-head .starter-questions-refresh { grid-column: 3; justify-self: start; color: var(--color-ink-tertiary); }
|
||||
.starter-questions-head .starter-questions-refresh:hover { color: var(--color-ink); }
|
||||
.starter-questions-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
|
||||
.starter-questions-list .starter-question { width: 100%; height: auto; min-height: 56px; padding: 10px 12px; border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--color-canvas-soft); box-shadow: none; color: var(--color-ink-secondary); white-space: normal; align-items: flex-start; justify-content: flex-start; text-align: left; font-size: var(--type-body-sm); font-weight: 400; line-height: 1.45; }
|
||||
/* Only a swap fades in; the first set keeps the onboarding entrance. */
|
||||
.starter-questions-list.is-swapped { animation: starter-set-in 180ms ease-out; }
|
||||
@keyframes starter-set-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
||||
@media (prefers-reduced-motion: reduce) { .starter-questions-list.is-swapped { animation: none; } }
|
||||
/* BUG-2282: one fixed height per card that fits the longest question on two lines plus its topic word, so a swap
|
||||
never moves the composer. The topic word is the quiet caption style above the question (beside it on a phone). */
|
||||
.starter-questions-list .starter-question { display: flex; flex-direction: column; gap: 2px; width: 100%; height: 88px; padding: 10px 12px; border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--color-canvas-soft); box-shadow: none; color: var(--color-ink-secondary); white-space: normal; align-items: flex-start; justify-content: flex-start; text-align: left; font-size: var(--type-body-sm); font-weight: 400; line-height: 1.45; overflow: hidden; }
|
||||
.starter-question-topic { color: var(--color-ink-tertiary); font-size: var(--type-caption); line-height: 1.4; white-space: nowrap; }
|
||||
.starter-question-text { min-width: 0; }
|
||||
/* Owner 2026-11-22: no outline on the starter cards; a soft fill, the selected fill on hover. */
|
||||
.starter-questions-list .starter-question:hover, .starter-questions-list .starter-question:focus-visible { border-color: transparent; background: var(--color-sidebar-selected); color: var(--color-ink); }
|
||||
@media (max-width: 640px) {
|
||||
.starter-questions-list { grid-template-columns: minmax(0, 1fr); }
|
||||
.starter-questions-list .starter-question { min-height: 44px; }
|
||||
.starter-questions-list .starter-question { flex-direction: row; align-items: center; gap: 12px; height: 68px; }
|
||||
.starter-question-topic { flex: none; width: 4em; }
|
||||
}
|
||||
.birth-time-transition-card { position: relative; overflow: visible; }
|
||||
/* Toasts (2026-09-30): the only place action results and errors appear. A
|
||||
@@ -1785,6 +1799,42 @@ button.chat-chart-resize-handle:active { position: absolute; top: 0; left: -3px;
|
||||
.consultation-run-timeline__list {
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
/* BUG-2283 (原型「等回答的时候」): before the answer has text, the person's chart (areas only, the reader's board
|
||||
style, compact) under a one-line caption, then the plain steps. Lit areas get a light wash of the accent and fade
|
||||
in; under reduced motion they simply appear. */
|
||||
.chat-wait { display: grid; justify-items: center; gap: var(--space-3); min-width: 0; padding-top: var(--space-2); padding-bottom: var(--consult-think-answer-gap); }
|
||||
.chat-wait-figure { display: grid; justify-items: center; gap: var(--space-1); margin: 0; }
|
||||
.chat-wait-caption { margin: 0; color: var(--color-ink-tertiary); font-size: var(--type-caption); line-height: 20px; height: 20px; }
|
||||
.chat-wait-board { width: 220px; height: 220px; }
|
||||
/* The board stylesheet loads lazily; these keep the first frame drawn the same before it arrives. */
|
||||
.chat-wait-board svg { display: block; width: 100%; height: 100%; }
|
||||
.chat-wait-board .chart-board-cell polygon,
|
||||
.chat-wait-board .chart-board-cell rect { fill: var(--color-canvas); stroke: var(--color-border-strong); stroke-width: 1; }
|
||||
.chat-wait-board .chart-board-center rect,
|
||||
.chat-wait-board .chart-board-center circle { fill: none; stroke: var(--color-border); }
|
||||
.chat-wait-board .chart-board-cell { cursor: default; }
|
||||
.chat-wait-board .chart-board-cell polygon,
|
||||
.chat-wait-board .chart-board-cell rect { transition: fill .5s ease; }
|
||||
.chat-wait-board .chart-board-cell.is-tinted polygon,
|
||||
.chat-wait-board .chart-board-cell.is-tinted rect { fill: color-mix(in srgb, var(--color-action) 22%, var(--color-canvas)); }
|
||||
.chat-wait-board .chart-board-sign,
|
||||
.chat-wait-board .chart-board-house,
|
||||
.chat-wait-board .chart-board-asc-mark { display: none; }
|
||||
.chat-wait-board .chart-board-note { font-size: 22px; font-weight: 500; fill: var(--color-ink); animation: chat-wait-area-in .5s ease both; }
|
||||
@keyframes chat-wait-area-in { from { opacity: 0; } to { opacity: 1; } }
|
||||
.chat-wait-steps { display: grid; gap: var(--space-2); width: min(100%, 320px); margin: 0; padding: 0; list-style: none; font-size: var(--type-body-sm); line-height: 1.5; }
|
||||
.chat-wait-step { display: flex; align-items: baseline; gap: 10px; color: var(--color-ink-secondary); opacity: .4; transition: opacity .4s ease; }
|
||||
.chat-wait-step.is-done, .chat-wait-step.is-now { opacity: 1; }
|
||||
.chat-wait-step.is-now { color: var(--color-ink); }
|
||||
.chat-wait-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--color-border); transform: translateY(-1px); }
|
||||
.chat-wait-step.is-done .chat-wait-dot { background: var(--color-ink-tertiary); }
|
||||
.chat-wait-step.is-now .chat-wait-dot { background: var(--color-action); }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.chat-wait-board .chart-board-cell polygon,
|
||||
.chat-wait-board .chart-board-cell rect,
|
||||
.chat-wait-step { transition: none; }
|
||||
.chat-wait-board .chart-board-note { animation: none; }
|
||||
}
|
||||
/* BUG-2048: the one-line status (原型 D). Live: spinner, the line, the elapsed time after 10 s. Settled: one
|
||||
line that opens to the steps, indented with no rule beside them (owner 2026-11-20: no left accent bar). */
|
||||
.consultation-run-status-slot { min-width: 0; padding-bottom: var(--consult-think-answer-gap); }
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import { AgentActivityStatus } from "@/components/agent-activity-status";
|
||||
import { prefetchOnIdle } from "@/components/chat-chunk-prefetch";
|
||||
import { ChatMessageContent } from "@/components/chat-message-content";
|
||||
import { ConsultationRunStatus, ConsultationRunTimeline } from "@/components/consultation-run-timeline";
|
||||
import { ConsultationRunTimeline } from "@/components/consultation-run-timeline";
|
||||
import { ChatWaitProgress } from "@/components/chat-wait-progress";
|
||||
import type { ChatMessageView } from "@/lib/chat-message-view";
|
||||
import { consultAnswerBasisRows } from "@/lib/consult-answer-basis";
|
||||
import { memo, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
|
||||
@@ -142,7 +143,8 @@ export const ChatMessageRow = memo(function ChatMessageRow({
|
||||
)
|
||||
: null;
|
||||
const runStatus = oneLineStatus
|
||||
? <ConsultationRunStatus rows={consultTimeline} live={timelineLive} answering={hasAnswer} question={question} />
|
||||
// BUG-2283: before the answer has text, the chart and plain steps (falls back to this same one-line status).
|
||||
? <ChatWaitProgress rows={consultTimeline} live={timelineLive} answering={hasAnswer} question={question} />
|
||||
: null;
|
||||
// Above the answer while the run is live. The slot stays for the fold-away
|
||||
// after it, so the same element carries the transition.
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo } from "react";
|
||||
|
||||
import { ChartBoardSvg, type ChartBoardHouseNote } from "@/components/chart-board/chart-board-svg";
|
||||
import type { BoardFocus } from "@/lib/chart-board-focus";
|
||||
import { boardFromChart, type BoardModel } from "@/lib/chart-board-model";
|
||||
import type { ChartBoardStyle } from "@/lib/chart-board-style";
|
||||
import { CHART_AREA_NAMES } from "@/lib/chat-chart-areas";
|
||||
import type { ChartViewOk } from "@/lib/chart-view-contract";
|
||||
|
||||
const NO_BODIES = new Set<never>();
|
||||
const NO_MARKS = new Map<never, never>();
|
||||
const noop = () => {};
|
||||
|
||||
/** The chart's houses with every body removed (owner 2026-11-24: no planets on the waiting chart). */
|
||||
export function waitBoardModel(chart: ChartViewOk["vedic"]["vargas"][number]["chart"]): BoardModel {
|
||||
const model = boardFromChart(chart);
|
||||
return { ...model, houses: model.houses.map((house) => ({ ...house, bodies: [] })) };
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2283: the product's own board (ChartBoardSvg, the reader's North / South style) at a compact size, areas only.
|
||||
* Lit houses use the board's own wash (`is-tinted`); a lit natal house carries its plain name from the shared table.
|
||||
* Decorative: the caller wraps it in a labelled `role="img"`; the step list is what assistive technology reads.
|
||||
*/
|
||||
export function ChatWaitBoard({
|
||||
chart,
|
||||
style,
|
||||
lit,
|
||||
labeled,
|
||||
}: Readonly<{
|
||||
chart: ChartViewOk["vedic"]["vargas"][number]["chart"];
|
||||
style: ChartBoardStyle;
|
||||
lit: readonly number[];
|
||||
labeled: readonly number[];
|
||||
}>) {
|
||||
useEffect(() => {
|
||||
void import("@/components/chart-board/chart-board-styles").catch(() => undefined);
|
||||
}, []);
|
||||
const model = useMemo(() => waitBoardModel(chart), [chart]);
|
||||
const focus = useMemo<BoardFocus>(() => ({
|
||||
lit: NO_BODIES,
|
||||
dimmed: NO_BODIES,
|
||||
marks: NO_MARKS,
|
||||
houses: new Set(lit),
|
||||
outlined: new Set<number>(),
|
||||
links: [],
|
||||
numberFrom: null,
|
||||
chips: [],
|
||||
}), [lit]);
|
||||
const notes = useMemo<(ChartBoardHouseNote | null)[]>(
|
||||
() => Array.from({ length: 12 }, (_, index) => (labeled.includes(index + 1) ? { text: CHART_AREA_NAMES[index + 1]!, tone: "plain" } : null)),
|
||||
[labeled],
|
||||
);
|
||||
return (
|
||||
<div className="chat-wait-board" aria-hidden="true" inert>
|
||||
<ChartBoardSvg model={model} style={style} selection={null} onSelect={noop} ariaLabel="" focus={focus} houseNotes={notes} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ChatWaitBoard;
|
||||
@@ -0,0 +1,97 @@
|
||||
"use client";
|
||||
|
||||
import { lazy, Suspense, useEffect, useSyncExternalStore } from "react";
|
||||
|
||||
import { ConsultationRunStatus } from "@/components/consultation-run-timeline";
|
||||
import type { ChartViewOk } from "@/lib/chart-view-contract";
|
||||
import type { ConsultationTimelineRow } from "@/lib/consultation-run-timeline";
|
||||
import { readCurrentSubjectId } from "@/lib/current-subject";
|
||||
import { WAIT_CHART_LABEL, waitView, type WaitChart, type WaitView } from "@/lib/chat-wait-progress";
|
||||
import { readChatWait, subscribeChatWait } from "@/lib/chat-wait-store";
|
||||
import { peekChartPage, subscribeChartPageChanges } from "@/lib/secondary-page-data";
|
||||
import { useUiStore } from "@/stores/ui-store";
|
||||
|
||||
const ChatWaitBoard = lazy(() => import("@/components/chat-wait-board"));
|
||||
|
||||
/** The chart the page already holds for the selected person; null when it is not loaded (no request is made). */
|
||||
function readWaitChartView(): ChartViewOk | null {
|
||||
const snapshot = peekChartPage();
|
||||
if (snapshot?.kind !== "view" || snapshot.view.status !== "ok") return null;
|
||||
const view = snapshot.view;
|
||||
if (view.subjectId && view.subjectId !== readCurrentSubjectId()) return null;
|
||||
return view;
|
||||
}
|
||||
|
||||
type Board = Readonly<{ chart: ChartViewOk["vedic"]["vargas"][number]["chart"]; caption: string; lit: readonly number[]; labeled: readonly number[] }>;
|
||||
|
||||
/**
|
||||
* Which drawing to show. A switched chart the page has not loaded keeps its place on the North board (the cells do
|
||||
* not depend on the signs there and no sign is written); on the South board, where the cells are the signs, it
|
||||
* stays on 本命盘 rather than draw a wrong picture.
|
||||
*/
|
||||
export function waitBoard(view: Extract<WaitView, { mappable: true }>, chartView: ChartViewOk | null, style: "north" | "south"): Board | null {
|
||||
if (!chartView) return null;
|
||||
const find = (id: WaitChart) => chartView.vedic.vargas.find((varga) => varga.id === id)?.chart ?? null;
|
||||
const natal = find("D1");
|
||||
if (!natal) return null;
|
||||
if (view.chart === "D1") return { chart: natal, caption: view.caption, lit: view.lit, labeled: view.labeled };
|
||||
const varga = find(view.chart);
|
||||
if (varga) return { chart: varga, caption: view.caption, lit: view.lit, labeled: [] };
|
||||
if (style === "north") return { chart: natal, caption: view.caption, lit: view.lit, labeled: [] };
|
||||
return { chart: natal, caption: "本命盘", lit: view.natal, labeled: view.natal };
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2283 (原型「等回答的时候」): before the answer has text, the person's chart (areas only) and the plain step list,
|
||||
* both driven by the run's real events (chat-wait-progress.ts). When the events do not map, or once the answer is
|
||||
* being written, today's one-line status shows instead; it stays mounted throughout, so its elapsed time and
|
||||
* settled summary are unchanged.
|
||||
*/
|
||||
export function ChatWaitProgress({
|
||||
rows,
|
||||
live,
|
||||
answering,
|
||||
question,
|
||||
}: Readonly<{
|
||||
rows: readonly ConsultationTimelineRow[];
|
||||
live: boolean;
|
||||
answering: boolean;
|
||||
question?: string | null;
|
||||
}>) {
|
||||
const slot = useSyncExternalStore(subscribeChatWait, readChatWait, readChatWait);
|
||||
const chartView = useSyncExternalStore(subscribeChartPageChanges, readWaitChartView, readWaitChartView);
|
||||
const style = useUiStore((state) => state.chartBoardStyle);
|
||||
const hydrated = useUiStore((state) => state.chartBoardStyleHydrated);
|
||||
const hydrate = useUiStore((state) => state.hydrateChartBoardStyle);
|
||||
useEffect(() => {
|
||||
if (!hydrated) hydrate();
|
||||
}, [hydrate, hydrated]);
|
||||
const view = live && !answering ? waitView(slot?.state) : { mappable: false as const };
|
||||
const board = view.mappable ? waitBoard(view, chartView, style) : null;
|
||||
return (
|
||||
<>
|
||||
{view.mappable ? (
|
||||
<div className="chat-wait">
|
||||
{board ? (
|
||||
<div className="chat-wait-figure" role="img" aria-label={`${WAIT_CHART_LABEL}:${board.caption}`}>
|
||||
<div className="chat-wait-caption" aria-hidden="true">{board.caption}</div>
|
||||
<Suspense fallback={<div className="chat-wait-board" aria-hidden="true" />}>
|
||||
<ChatWaitBoard chart={board.chart} style={style} lit={board.lit} labeled={board.labeled} />
|
||||
</Suspense>
|
||||
</div>
|
||||
) : null}
|
||||
<ol className="chat-wait-steps">
|
||||
{view.steps.map((step) => (
|
||||
<li key={step.id} className={`chat-wait-step is-${step.status}`} aria-current={step.status === "now" ? "step" : undefined}>
|
||||
<span className="chat-wait-dot" aria-hidden="true" />
|
||||
{step.text}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
<span className="sr-only" role="status" aria-live="polite">{view.current}</span>
|
||||
</div>
|
||||
) : null}
|
||||
<ConsultationRunStatus rows={rows} live={live} answering={answering} question={question} concealed={view.mappable} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -251,11 +251,14 @@ export function ConsultationRunStatus({
|
||||
live = false,
|
||||
answering = false,
|
||||
question,
|
||||
concealed = false,
|
||||
}: Readonly<{
|
||||
rows: readonly ConsultationTimelineRow[];
|
||||
live?: boolean;
|
||||
answering?: boolean;
|
||||
question?: string | null;
|
||||
/** BUG-2283: the waiting chart stands in for the line; it stays mounted so its elapsed time keeps counting. */
|
||||
concealed?: boolean;
|
||||
}>) {
|
||||
const bodyId = useId();
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -282,7 +285,7 @@ export function ConsultationRunStatus({
|
||||
if (view.kind === "hidden" || (view.kind === "done" && startedAt === null)) return null;
|
||||
if (view.kind === "live") {
|
||||
return (
|
||||
<div className="consultation-run-status-slot">
|
||||
<div className="consultation-run-status-slot" hidden={concealed || undefined}>
|
||||
<div className="consultation-run-status is-live" role="status" aria-live="polite">
|
||||
<InlineSpinner size={12} />
|
||||
<ShimmerText key={view.label} className="consultation-run-status__label" text={view.label} />
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button, buttonVariants } from "@/components/ui/button";
|
||||
import {
|
||||
starterPrompts,
|
||||
starterQuestions,
|
||||
starterFirstSet,
|
||||
starterLibrarySets,
|
||||
starterWatching,
|
||||
type StarterAudience,
|
||||
type StarterCard,
|
||||
type StarterChartSigns,
|
||||
} from "@/lib/starter-questions";
|
||||
import { readConsultPresetDomains, subscribeConsultPresetDomains } from "@/lib/consult-preset-store";
|
||||
// BUG-2161: the third starter tells the server it came from this button (it asks for the plan and deadline first).
|
||||
import { STARTER_PLAN_TIMING_ENTRYPOINT } from "@/lib/plan-timing-clarify";
|
||||
import { STARTER_QUESTIONS_TITLE } from "@/lib/starter-chart-details";
|
||||
@@ -18,11 +21,15 @@ import { AppLink } from "@/components/app-link";
|
||||
import { RECTIFICATION_PAGE_HREF } from "@/lib/chat-session-url";
|
||||
import type { Theme } from "@/lib/home-types";
|
||||
|
||||
/** BUG-2282: the heading of the questions on a returning reader's new conversation (prototype 「刚进来」). */
|
||||
export const STARTER_QUESTIONS_RETURNING_TITLE = "想知道什么,点一个就能问";
|
||||
export const STARTER_REFRESH_LABEL = "换一组";
|
||||
|
||||
/**
|
||||
* The first question (BUG-2144): three equal cards right above the composer,
|
||||
* as wide as its column (three in a row, stacked at 640px and below). All three
|
||||
* send. BUG-2201 (owner 2026-11-22): the group is headed 「从这三个问题开始」,
|
||||
* so a newcomer knows where to begin.
|
||||
* The questions above the composer on every new, empty conversation (BUG-2282; before it, only until the free first
|
||||
* question was used, BUG-1431 / BUG-2144). Three cards, each from a different topic with its topic word, one tap
|
||||
* sends; the refresh icon beside the heading swaps all three for the next three (owner 2026-11-24). Cards have one
|
||||
* fixed height, so a swap never moves the composer. BUG-2201: the newcomer home keeps 「从这三个问题开始」.
|
||||
*/
|
||||
export function StarterQuestions({
|
||||
audience,
|
||||
@@ -30,6 +37,7 @@ export function StarterQuestions({
|
||||
signs,
|
||||
onAsk,
|
||||
rectifyHint = false,
|
||||
newcomer = true,
|
||||
}: {
|
||||
readonly audience: StarterAudience;
|
||||
readonly subjectId: string;
|
||||
@@ -37,14 +45,25 @@ export function StarterQuestions({
|
||||
readonly onAsk: (question: string, theme?: Theme, entrypoint?: typeof STARTER_PLAN_TIMING_ENTRYPOINT) => void;
|
||||
/** The current person's time is an estimate (issue #145; anyone in the list since #160): the third card goes to /rectification. */
|
||||
readonly rectifyHint?: boolean;
|
||||
/** The free first question is still unused (BUG-2201 heading). */
|
||||
readonly newcomer?: boolean;
|
||||
}) {
|
||||
const questions = starterQuestions(audience, signs, { birthTimeUncertain: rectifyHint });
|
||||
const prompts = starterPrompts(audience);
|
||||
const moonKnown = Boolean(signs.moonSign);
|
||||
const domains = useSyncExternalStore(subscribeConsultPresetDomains, readConsultPresetDomains, readConsultPresetDomains);
|
||||
const audienceKey = audience.kind === "other" ? `other:${audience.name}` : "self";
|
||||
const first = starterFirstSet(audience, signs, { birthTimeUncertain: rectifyHint });
|
||||
// The page passes a fresh audience object on every render; the library sets only change with the person.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
const more = useMemo(() => starterLibrarySets(audience, domains), [audienceKey, domains]);
|
||||
const setCount = more.length + 1;
|
||||
// Another person starts again at the first set.
|
||||
const pickedKey = `${subjectId}|${audienceKey}`;
|
||||
const [picked, setPicked] = useState<{ key: string; set: number; swapped: boolean }>({ key: pickedKey, set: 0, swapped: false });
|
||||
const current = picked.key === pickedKey ? picked.set % setCount : 0;
|
||||
const swapped = picked.key === pickedKey && picked.swapped;
|
||||
const cards = current === 0 ? first : more[current - 1]!;
|
||||
|
||||
// The signs come from the chart the engine already computed (BUG-1459). Until
|
||||
// 2026-11-02 today's 今日星语 card carried them and this read was only the
|
||||
// fallback; the card left the home page, so the chart is the source now. Until
|
||||
// it arrives, and on any failure, the first question keeps its no-sign wording.
|
||||
useEffect(() => {
|
||||
if (moonKnown) return;
|
||||
@@ -52,19 +71,64 @@ export function StarterQuestions({
|
||||
.then((module) => module.loadStarterSignsFromChart(subjectId))
|
||||
.catch(() => undefined);
|
||||
}, [moonKnown, subjectId]);
|
||||
|
||||
function card(item: StarterCard, index: number) {
|
||||
const onboarding = current === 0
|
||||
? { "data-onboarding-enter": `starter-${index}`, ...(item.rectify ? {} : { "data-onboarding-follow-source": "" }) }
|
||||
: {};
|
||||
const body = (
|
||||
<>
|
||||
<span className="starter-question-topic">{item.topic}</span>
|
||||
<span className="starter-question-text">{item.label}</span>
|
||||
</>
|
||||
);
|
||||
if (item.rectify) {
|
||||
// Product 2026-11-07: an estimated birth time goes to the time check first.
|
||||
return (
|
||||
<AppLink key={item.label} className={`${buttonVariants({ variant: "outline" })} starter-question`} href={RECTIFICATION_PAGE_HREF} data-onboarding-press="" data-onboarding-index={index} {...onboarding}>
|
||||
{body}
|
||||
</AppLink>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Button
|
||||
key={item.label}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="starter-question"
|
||||
data-onboarding-press=""
|
||||
data-onboarding-index={index}
|
||||
{...onboarding}
|
||||
onClick={() => (item.planTiming
|
||||
? onAsk(item.prompt, "timing", STARTER_PLAN_TIMING_ENTRYPOINT)
|
||||
: onAsk(item.prompt, item.theme ?? undefined))}
|
||||
>
|
||||
{body}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="starter-questions">
|
||||
<h2 className="starter-questions-title">{STARTER_QUESTIONS_TITLE}</h2>
|
||||
<div className="starter-questions-head">
|
||||
<h2 className="starter-questions-title">{newcomer ? STARTER_QUESTIONS_TITLE : STARTER_QUESTIONS_RETURNING_TITLE}</h2>
|
||||
{setCount > 1 ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="starter-questions-refresh"
|
||||
aria-label={STARTER_REFRESH_LABEL}
|
||||
title={STARTER_REFRESH_LABEL}
|
||||
onClick={() => setPicked({ key: pickedKey, set: (current + 1) % setCount, swapped: true })}
|
||||
>
|
||||
<RefreshCw aria-hidden="true" />
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{audience.kind === "other" ? <Badge variant="outline">{starterWatching(audience)}</Badge> : null}
|
||||
<div className="starter-questions-list">
|
||||
<Button type="button" variant="outline" className="starter-question" data-onboarding-press="" data-onboarding-enter="starter-0" data-onboarding-index={0} data-onboarding-follow-source="" onClick={() => onAsk(prompts[0])}>{questions[0]}</Button>
|
||||
<Button type="button" variant="outline" className="starter-question" data-onboarding-press="" data-onboarding-enter="starter-1" data-onboarding-index={1} data-onboarding-follow-source="" onClick={() => onAsk(prompts[1])}>{questions[1]}</Button>
|
||||
{rectifyHint ? (
|
||||
// Product 2026-11-07: an estimated birth time goes to the time check first.
|
||||
<AppLink className={`${buttonVariants({ variant: "outline" })} starter-question`} href={RECTIFICATION_PAGE_HREF} data-onboarding-press="" data-onboarding-enter="starter-2" data-onboarding-index={2}>{questions[2]}</AppLink>
|
||||
) : (
|
||||
<Button type="button" variant="outline" className="starter-question" data-onboarding-press="" data-onboarding-enter="starter-2" data-onboarding-index={2} data-onboarding-follow-source="" onClick={() => onAsk(prompts[2], "timing", STARTER_PLAN_TIMING_ENTRYPOINT)}>{questions[2]}</Button>
|
||||
)}
|
||||
<div key={current} className={swapped ? "starter-questions-list is-swapped" : "starter-questions-list"} data-starter-set={current}>
|
||||
{cards.map(card)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
} from "@/lib/consultation-run-timeline";
|
||||
import { createNdjsonParser, type AgentExecutionReceipt, type ConsultationAgentPublicEvent } from "@/lib/consultation-agent-events";
|
||||
import { createStreamFrameBuffer } from "@/lib/stream-frame-buffer";
|
||||
import { beginChatWait, feedChatWait } from "@/lib/chat-wait-store";
|
||||
import {
|
||||
applyThinkingSectionProgress,
|
||||
upsertThinkingSection,
|
||||
@@ -839,6 +840,8 @@ export function useConsultationRun(params: ConsultationRunParams) {
|
||||
setConsultationPhase("streaming");
|
||||
}
|
||||
setStreamingReply({ sessionId, text: "", timeline: [] });
|
||||
// BUG-2283: the waiting screen follows this run's events; the first question of a conversation starts with 性格.
|
||||
beginChatWait(requestId, sessionId, userSession.messages.filter((message) => message.role === "user").length <= 1);
|
||||
let responseKind: "smalltalk" | undefined;
|
||||
let latestPartialReply = "";
|
||||
let thinkingSections: PublicThinkingSection[] = [];
|
||||
@@ -1018,6 +1021,7 @@ export function useConsultationRun(params: ConsultationRunParams) {
|
||||
if ((response.headers.get("content-type") ?? "").includes("application/x-ndjson")) {
|
||||
const parser = createNdjsonParser((event) => {
|
||||
if (responseKind !== "smalltalk") timelineState = reduceConsultationTimeline(timelineState, event);
|
||||
if (responseKind !== "smalltalk") feedChatWait(requestId, event);
|
||||
frames.touch();
|
||||
if (event.type === "answer.delta") {
|
||||
// A moderated answer arrives as one replacing delta (2026-09-30).
|
||||
|
||||
@@ -32,3 +32,17 @@ export function chartAreaHouses(houses: readonly number[]): number[] {
|
||||
export function chartAreaNames(houses: readonly number[]): string[] {
|
||||
return chartAreaHouses(houses).map((house) => CHART_AREA_NAMES[house]!);
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2283 (waiting screen): the houses a consultation domain reads, taken from the domain's routed layers
|
||||
* (`requiredLayers` in consultation-domain-registry.ts, e.g. 「10th house/lord」, 「2nd/11th/9th/5th houses」).
|
||||
* The caller passes the layers, so this file keeps no imports. A domain whose layers name no house gives [].
|
||||
*/
|
||||
export function domainChartHouses(requiredLayers: readonly string[]): number[] {
|
||||
const houses: number[] = [];
|
||||
for (const layer of requiredLayers) {
|
||||
if (!/\bhouses?\b/iu.test(layer)) continue;
|
||||
for (const match of layer.matchAll(/(\d{1,2})(?:st|nd|rd|th)\b/gu)) houses.push(Number(match[1]));
|
||||
}
|
||||
return chartAreaHouses(houses);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
* BUG-2283 (owner-approved chat prototype 2026-11-24, 「等回答的时候」): while an answer is being prepared the page
|
||||
* draws the person's chart (areas only, no planets) and a short list of plain steps. Every step comes from an event
|
||||
* the consult route really sends; nothing here runs on a timer. A stage that takes long simply stays 「now」 longer.
|
||||
*
|
||||
* skill.started (first turn of a conversation) → 先看性格的底子 lights 性格 (house 1)
|
||||
* tool.started { domains } → one step per routed domain lights the domain's houses
|
||||
* activity chart-calculation 「第 i/N 项」 → domain i becomes the current step
|
||||
* tool.completed, a routed domain reads D10 / D9 → 换到专门看事业 / 感情的那张盘 the picture switches to that chart
|
||||
* activity 「正在多看一眼:D10 分盘…」 (evidence lookup) → the same switch, for D10 / D9 only
|
||||
* activity 「正在多看一眼:全部大运起止…」 and the like → 对一遍这几年的时间 (back on 本命盘)
|
||||
* activity 「正在多看一眼:…」 (any other section) → 再多看一处细节
|
||||
* activity answer-composition, phase compose, answer → 正在整理回答
|
||||
*
|
||||
* The houses per domain come from the domain routing (`requiredLayers`), named through the shared table in
|
||||
* chat-chart-areas.ts. A turn whose events give no area (an older path, a reply without the chart tool, an error)
|
||||
* is `mappable: false`, and the page keeps today's one-line status instead.
|
||||
*/
|
||||
import type { ConsultationAgentPublicEvent } from "./consultation-agent-events.ts";
|
||||
import { evidenceLookupSectionLabel } from "./consultation-activity-labels.ts";
|
||||
import {
|
||||
consultationDomainDefinition,
|
||||
consultationDomainIds,
|
||||
type ConsultationDomain,
|
||||
} from "./consultation-domain-registry.ts";
|
||||
import { chartAreaHouses, domainChartHouses } from "./chat-chart-areas.ts";
|
||||
|
||||
export type WaitChart = "D1" | "D9" | "D10";
|
||||
export type WaitStepKind = "base" | "domain" | "varga" | "timing" | "detail" | "final";
|
||||
export type WaitStepStatus = "pending" | "now" | "done";
|
||||
|
||||
export type WaitStep = Readonly<{
|
||||
id: string;
|
||||
kind: WaitStepKind;
|
||||
text: string;
|
||||
chart: WaitChart;
|
||||
houses: readonly number[];
|
||||
}>;
|
||||
|
||||
export type WaitState = Readonly<{
|
||||
firstTurn: boolean;
|
||||
steps: readonly WaitStep[];
|
||||
/** Index of the current step; -1 until a mapped event arrives. */
|
||||
now: number;
|
||||
domainsSeen: boolean;
|
||||
ended: boolean;
|
||||
}>;
|
||||
|
||||
export const WAIT_FIRST_STEP = "先看性格的底子";
|
||||
export const WAIT_FINAL_STEP = "正在整理回答";
|
||||
export const WAIT_NATAL_CAPTION = "本命盘";
|
||||
export const WAIT_TIMING_STEP = "对一遍这几年的时间";
|
||||
export const WAIT_TIMING_STEP_AFTER_SWITCH = "回到本命盘,对一遍这几年的时间";
|
||||
export const WAIT_DETAIL_STEP = "再多看一处细节";
|
||||
export const WAIT_CHART_LABEL = "正在看的星盘区域";
|
||||
|
||||
/** One plain line per registry domain (no terms, no 「你」, so it reads the same on someone else's chart). */
|
||||
export const WAIT_DOMAIN_STEPS: Readonly<Record<ConsultationDomain, string>> = {
|
||||
career: "再看事业这一块",
|
||||
marriage: "再看感情这一块",
|
||||
wealth: "再看钱这一块",
|
||||
health: "再看身体和精力",
|
||||
education: "再看学习这一块",
|
||||
migration: "再看搬家和远行",
|
||||
family: "再看家里这一块",
|
||||
parents: "再看和父母有关的部分",
|
||||
children: "再看和孩子有关的部分",
|
||||
annual: "再看接下来这一年",
|
||||
timing: "再看问到的这段时间",
|
||||
general: "再把整张盘看一遍",
|
||||
};
|
||||
|
||||
/**
|
||||
* The divisional charts with a plain name (fixed table). A varga without one is never shown as a switch.
|
||||
* `houses`: the area that chart is read for, lit while it is shown.
|
||||
*/
|
||||
export const WAIT_VARGA_CHARTS: Readonly<Record<Exclude<WaitChart, "D1">, Readonly<{ caption: string; houses: readonly number[] }>>> = {
|
||||
D10: { caption: "专门看事业的那张盘", houses: [10] },
|
||||
D9: { caption: "专门看感情的那张盘", houses: [7] },
|
||||
};
|
||||
|
||||
function isNamedVarga(value: string): value is Exclude<WaitChart, "D1"> {
|
||||
return Object.hasOwn(WAIT_VARGA_CHARTS, value);
|
||||
}
|
||||
|
||||
/** Evidence lookups that read time (dashas, transits): their plain labels, as the route writes them. */
|
||||
const TIMING_LOOKUP_LABELS: ReadonlySet<string> = new Set([
|
||||
"vimshottari_mahadashas", "transits", "chara_dasha", "moon_transit", "dasha_sandhi", "dasa_convergence",
|
||||
].map((section) => evidenceLookupSectionLabel(section)));
|
||||
|
||||
const LOOKUP_RE = /^正在多看一眼:(.+?)…?$/u;
|
||||
const CALCULATION_INDEX_RE = /第 (\d+)\/(\d+) 项/u;
|
||||
|
||||
function finalStep(): WaitStep {
|
||||
return { id: "final", kind: "final", text: WAIT_FINAL_STEP, chart: "D1", houses: [] };
|
||||
}
|
||||
|
||||
export function beginWait(firstTurn: boolean): WaitState {
|
||||
const steps: WaitStep[] = firstTurn
|
||||
? [{ id: "base", kind: "base", text: WAIT_FIRST_STEP, chart: "D1", houses: [1] }, finalStep()]
|
||||
: [finalStep()];
|
||||
return { firstTurn, steps, now: -1, domainsSeen: false, ended: false };
|
||||
}
|
||||
|
||||
function advance(state: WaitState, index: number): WaitState {
|
||||
if (index < 0 || index <= state.now) return state;
|
||||
return { ...state, now: index };
|
||||
}
|
||||
|
||||
function finalIndex(state: WaitState): number {
|
||||
return state.steps.findIndex((step) => step.kind === "final");
|
||||
}
|
||||
|
||||
/** Insert steps just before 「正在整理回答」. */
|
||||
function insertBeforeFinal(state: WaitState, added: readonly WaitStep[]): WaitState {
|
||||
const at = finalIndex(state);
|
||||
const steps = [...state.steps.slice(0, at), ...added, ...state.steps.slice(at)];
|
||||
// The current step keeps its place: anything inserted lands after it unless the final step was already reached.
|
||||
return { ...state, steps, now: state.now >= at ? state.now + added.length : state.now };
|
||||
}
|
||||
|
||||
function knownDomains(values: readonly string[] | undefined): ConsultationDomain[] {
|
||||
const ids = consultationDomainIds as readonly string[];
|
||||
return [...new Set((values ?? []).filter((value): value is ConsultationDomain => ids.includes(value)))];
|
||||
}
|
||||
|
||||
/** The first named divisional chart the routed domains read, in routing order. */
|
||||
function routedVarga(domains: readonly ConsultationDomain[]): Exclude<WaitChart, "D1"> | null {
|
||||
for (const domain of domains) {
|
||||
for (const layer of consultationDomainDefinition(domain).requiredLayers) {
|
||||
if (isNamedVarga(layer)) return layer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function vargaStep(varga: Exclude<WaitChart, "D1">, id: string): WaitStep {
|
||||
const chart = WAIT_VARGA_CHARTS[varga];
|
||||
return { id, kind: "varga", text: `换到${chart.caption}`, chart: varga, houses: chart.houses };
|
||||
}
|
||||
|
||||
function onToolStarted(state: WaitState, domains: readonly ConsultationDomain[]): WaitState {
|
||||
if (state.domainsSeen || domains.length === 0) return state;
|
||||
const added: WaitStep[] = domains.map((domain) => ({
|
||||
id: `domain-${domain}`,
|
||||
kind: "domain",
|
||||
text: WAIT_DOMAIN_STEPS[domain],
|
||||
chart: "D1",
|
||||
houses: domainChartHouses(consultationDomainDefinition(domain).requiredLayers),
|
||||
}));
|
||||
const varga = routedVarga(domains);
|
||||
if (varga) added.push(vargaStep(varga, `routed-${varga}`));
|
||||
const next = { ...insertBeforeFinal(state, added), domainsSeen: true };
|
||||
return advance(next, next.steps.findIndex((step) => step.kind === "domain"));
|
||||
}
|
||||
|
||||
function onLookup(state: WaitState, label: string): WaitState {
|
||||
const current = state.steps[state.now];
|
||||
const varga = /^(D\d{1,3}) 分盘$/u.exec(label)?.[1];
|
||||
let step: WaitStep;
|
||||
if (varga && isNamedVarga(varga)) {
|
||||
step = vargaStep(varga, `lookup-${state.steps.length}`);
|
||||
} else if (TIMING_LOOKUP_LABELS.has(label)) {
|
||||
step = {
|
||||
id: `lookup-${state.steps.length}`,
|
||||
kind: "timing",
|
||||
text: current?.kind === "varga" ? WAIT_TIMING_STEP_AFTER_SWITCH : WAIT_TIMING_STEP,
|
||||
chart: "D1",
|
||||
houses: [],
|
||||
};
|
||||
} else {
|
||||
step = { id: `lookup-${state.steps.length}`, kind: "detail", text: WAIT_DETAIL_STEP, chart: "D1", houses: [] };
|
||||
}
|
||||
// The same look twice in a row is one step.
|
||||
if (current && current.kind === step.kind && current.chart === step.chart && current.text === step.text) return state;
|
||||
// A lookup during 「正在整理回答」 is not shown: the answer is already being written.
|
||||
if (state.now >= finalIndex(state)) return state;
|
||||
const next = insertBeforeFinal(state, [step]);
|
||||
return advance(next, finalIndex(next) - 1);
|
||||
}
|
||||
|
||||
export function reduceWait(state: WaitState, event: ConsultationAgentPublicEvent): WaitState {
|
||||
if (state.ended) return state;
|
||||
switch (event.type) {
|
||||
case "skill.started":
|
||||
return state.firstTurn ? advance(state, 0) : state;
|
||||
case "tool.started":
|
||||
return onToolStarted(state, knownDomains(event.domains));
|
||||
case "tool.completed": {
|
||||
const at = state.steps.findIndex((step) => step.id.startsWith("routed-"));
|
||||
return advance(state, at);
|
||||
}
|
||||
case "activity": {
|
||||
if (event.phase === "chart-calculation") {
|
||||
const match = CALCULATION_INDEX_RE.exec(event.label);
|
||||
if (!match) return state;
|
||||
const domainSteps = state.steps.map((step, index) => ({ step, index })).filter((item) => item.step.kind === "domain");
|
||||
return advance(state, domainSteps[Number(match[1]) - 1]?.index ?? -1);
|
||||
}
|
||||
if (event.phase === "answer-composition") {
|
||||
const lookup = LOOKUP_RE.exec(event.label);
|
||||
if (lookup) return onLookup(state, lookup[1]!.trim());
|
||||
return advance(state, finalIndex(state));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
case "phase.started":
|
||||
return event.phase === "compose" ? advance(state, finalIndex(state)) : state;
|
||||
case "answer.delta":
|
||||
return event.text.trim() ? advance(state, finalIndex(state)) : state;
|
||||
case "run.completed":
|
||||
case "run.failed":
|
||||
return { ...state, ended: true };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export type WaitViewStep = Readonly<{ id: string; text: string; status: WaitStepStatus }>;
|
||||
|
||||
export type WaitView =
|
||||
| Readonly<{ mappable: false }>
|
||||
| Readonly<{
|
||||
mappable: true;
|
||||
steps: readonly WaitViewStep[];
|
||||
current: string;
|
||||
/** The chart drawn now, and its caption in plain words. */
|
||||
chart: WaitChart;
|
||||
caption: string;
|
||||
/** Houses washed on the drawn chart. */
|
||||
lit: readonly number[];
|
||||
/** Houses whose plain name is written on the chart (the natal areas; a switched chart only washes). */
|
||||
labeled: readonly number[];
|
||||
/** The natal areas reached so far (what 本命盘 shows again after a switch). */
|
||||
natal: readonly number[];
|
||||
}>;
|
||||
|
||||
export function waitView(state: WaitState | null | undefined): WaitView {
|
||||
if (!state || state.now < 0) return { mappable: false };
|
||||
const reached = state.steps.slice(0, state.now + 1);
|
||||
const natal = chartAreaHouses(reached.filter((step) => step.chart === "D1").flatMap((step) => step.houses));
|
||||
const current = state.steps[state.now]!;
|
||||
// Nothing to light (a follow-up that only reached 「正在整理回答」): keep today's line rather than an empty picture.
|
||||
if (current.chart === "D1" && natal.length === 0) return { mappable: false };
|
||||
const steps = state.steps.map((step, index) => ({
|
||||
id: step.id,
|
||||
text: step.text,
|
||||
status: index < state.now ? "done" as const : index === state.now ? "now" as const : "pending" as const,
|
||||
}));
|
||||
if (current.chart !== "D1") {
|
||||
return {
|
||||
mappable: true,
|
||||
steps,
|
||||
current: current.text,
|
||||
chart: current.chart,
|
||||
caption: WAIT_VARGA_CHARTS[current.chart].caption,
|
||||
lit: chartAreaHouses(current.houses),
|
||||
labeled: [],
|
||||
natal,
|
||||
};
|
||||
}
|
||||
return { mappable: true, steps, current: current.text, chart: "D1", caption: WAIT_NATAL_CAPTION, lit: natal, labeled: natal, natal };
|
||||
}
|
||||
|
||||
export function reduceWaitEvents(events: readonly ConsultationAgentPublicEvent[], firstTurn: boolean): WaitState {
|
||||
return events.reduce(reduceWait, beginWait(firstTurn));
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* BUG-2283: the waiting screen's state for the one consultation that is running on this page. The run hook
|
||||
* (use-consultation-run.ts) writes it from the stream's events; the live answer row reads it. One slot: the page
|
||||
* runs one consultation at a time, and each send starts a new slot.
|
||||
*/
|
||||
import type { ConsultationAgentPublicEvent } from "./consultation-agent-events.ts";
|
||||
import { beginWait, reduceWait, type WaitState } from "./chat-wait-progress.ts";
|
||||
|
||||
type Slot = Readonly<{ requestId: string; sessionId: string; state: WaitState }>;
|
||||
|
||||
let slot: Slot | null = null;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notify() {
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
export function beginChatWait(requestId: string, sessionId: string, firstTurn: boolean): void {
|
||||
slot = { requestId, sessionId, state: beginWait(firstTurn) };
|
||||
notify();
|
||||
}
|
||||
|
||||
export function feedChatWait(requestId: string, event: ConsultationAgentPublicEvent): void {
|
||||
if (!slot || slot.requestId !== requestId) return;
|
||||
const state = reduceWait(slot.state, event);
|
||||
if (state === slot.state) return;
|
||||
slot = { ...slot, state };
|
||||
notify();
|
||||
}
|
||||
|
||||
export function readChatWait(): Slot | null {
|
||||
return slot;
|
||||
}
|
||||
|
||||
export function subscribeChatWait(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => { listeners.delete(listener); };
|
||||
}
|
||||
|
||||
export function resetChatWaitForTests(): void {
|
||||
slot = null;
|
||||
notify();
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { SIGN_ZH, type SignName } from "@/lib/chart-view-labels";
|
||||
import type { ConsultPresetDomain } from "@/lib/consult-preset-prompts";
|
||||
import type { ConsultationDomain } from "@/lib/consultation-domain-registry";
|
||||
|
||||
export type StarterAudience =
|
||||
| { readonly kind: "self" }
|
||||
@@ -143,3 +145,107 @@ export function starterPrompts(audience: StarterAudience): readonly [string, str
|
||||
otherTimingPrompt(name),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* BUG-2282 (owner-approved chat prototype 2026-11-24, 「刚进来」; owner 2026-11-24: three at a time with a refresh
|
||||
* icon, 「这里可以加个刷新标志 点一下换三个问题」): every new, empty conversation shows three questions, each from a
|
||||
* different topic and carrying its topic word. The first set is the three starters above (「我是一个什么样的人?」
|
||||
* first); the refresh swaps to the next three from the 常用问题 library, three different topics again, cycling.
|
||||
*/
|
||||
export type StarterCard = Readonly<{
|
||||
/** The quiet topic word before the question. */
|
||||
topic: string;
|
||||
label: string;
|
||||
/** What one tap sends. */
|
||||
prompt: string;
|
||||
theme: ConsultationDomain | null;
|
||||
/** The third starter: the server asks for the plan and the deadline first (BUG-2161). */
|
||||
planTiming?: boolean;
|
||||
/** The third starter when the birth time is an estimate: opens the time check instead of sending. */
|
||||
rectify?: boolean;
|
||||
}>;
|
||||
|
||||
export type StarterSet = readonly [StarterCard, StarterCard, StarterCard];
|
||||
|
||||
/** The topic word per library group: plain, short, no terms. */
|
||||
export const STARTER_TOPIC_WORDS: Readonly<Record<ConsultationDomain, string>> = {
|
||||
general: "性格",
|
||||
career: "工作",
|
||||
marriage: "感情",
|
||||
wealth: "钱",
|
||||
family: "家庭",
|
||||
parents: "父母",
|
||||
children: "孩子",
|
||||
education: "学习",
|
||||
health: "生活节奏",
|
||||
migration: "居住",
|
||||
annual: "这一年",
|
||||
timing: "时机",
|
||||
};
|
||||
|
||||
/** 工作 / 感情 / 钱 / 性格 lead (prototype); the library's other topics follow in library order. */
|
||||
const STARTER_TOPIC_ORDER: readonly ConsultationDomain[] = ["career", "marriage", "wealth", "general"];
|
||||
|
||||
/** Library questions a newcomer cannot read: chart terms. */
|
||||
const STARTER_TERM_RE = /大运|行运|土星|木星|宫|上升|月亮|星盘|命盘|出生时间/u;
|
||||
|
||||
/** A preset question that sends as it is: no 「(填写)」 blank for the reader to fill in. */
|
||||
function sendsAsIs(prompt: string): boolean {
|
||||
return !prompt.includes("(");
|
||||
}
|
||||
|
||||
function forOther(text: string, name: string): string {
|
||||
return text.replaceAll("我", name);
|
||||
}
|
||||
|
||||
/** The first set: the three starters, unchanged, each with its topic word. */
|
||||
export function starterFirstSet(audience: StarterAudience, signs: StarterChartSigns, options: Readonly<{ birthTimeUncertain?: boolean }> = {}): StarterSet {
|
||||
const labels = starterQuestions(audience, signs, options);
|
||||
const prompts = starterPrompts(audience);
|
||||
return [
|
||||
{ topic: STARTER_TOPIC_WORDS.general, label: labels[0], prompt: prompts[0], theme: null },
|
||||
{ topic: STARTER_TOPIC_WORDS.career, label: labels[1], prompt: prompts[1], theme: null },
|
||||
options.birthTimeUncertain
|
||||
? { topic: "出生时间", label: labels[2], prompt: prompts[2], theme: null, rectify: true }
|
||||
: { topic: STARTER_TOPIC_WORDS.timing, label: labels[2], prompt: prompts[2], theme: "timing", planTiming: true },
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The sets after the first: each takes the next question of three different topics, in topic order, so no question
|
||||
* repeats until every one has been shown. Only questions that send as they are and carry no chart terms are used.
|
||||
*/
|
||||
export function starterLibrarySets(audience: StarterAudience, domains: readonly ConsultPresetDomain[]): StarterSet[] {
|
||||
const name = audience.kind === "other" ? audience.name.trim() || "TA" : null;
|
||||
const shown = new Set<string>([STARTER_SELF_LABEL, STARTER_TIMING_LABEL]);
|
||||
const rank = (id: ConsultationDomain) => {
|
||||
const at = STARTER_TOPIC_ORDER.indexOf(id);
|
||||
return at < 0 ? STARTER_TOPIC_ORDER.length : at;
|
||||
};
|
||||
const queues = [...domains]
|
||||
.map((domain, at) => ({ domain, at }))
|
||||
.sort((a, b) => rank(a.domain.id) - rank(b.domain.id) || a.at - b.at)
|
||||
.map(({ domain }) => ({
|
||||
items: domain.prompts
|
||||
.filter((item) => sendsAsIs(item.prompt) && !STARTER_TERM_RE.test(item.title) && !shown.has(item.title))
|
||||
.map((item): StarterCard => ({
|
||||
topic: STARTER_TOPIC_WORDS[domain.id] ?? domain.label,
|
||||
label: name ? forOther(item.title, name) : item.title,
|
||||
prompt: name ? forOther(item.prompt, name) : item.prompt,
|
||||
theme: domain.id,
|
||||
})),
|
||||
}))
|
||||
.filter((queue) => queue.items.length > 0);
|
||||
const sets: StarterSet[] = [];
|
||||
let start = 0;
|
||||
for (;;) {
|
||||
const open = queues.filter((queue) => queue.items.length > 0);
|
||||
if (open.length < 3) break;
|
||||
const offset = start % open.length;
|
||||
const ordered = [...open.slice(offset), ...open.slice(0, offset)];
|
||||
const picked = ordered.slice(0, 3).map((queue) => queue.items.shift()!);
|
||||
sets.push([picked[0]!, picked[1]!, picked[2]!]);
|
||||
start += 3;
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { CHART_AREA_NAMES, chartAreaNames, domainChartHouses } from "../src/lib/chat-chart-areas.ts";
|
||||
import type { ConsultationAgentPublicEvent } from "../src/lib/consultation-agent-events.ts";
|
||||
import { evidenceLookupActivityLabel } from "../src/lib/consultation-activity-labels.ts";
|
||||
import { consultationDomainDefinition, consultationDomainIds } from "../src/lib/consultation-domain-registry.ts";
|
||||
import {
|
||||
reduceWaitEvents,
|
||||
WAIT_DOMAIN_STEPS,
|
||||
WAIT_FINAL_STEP,
|
||||
WAIT_FIRST_STEP,
|
||||
waitView,
|
||||
} from "../src/lib/chat-wait-progress.ts";
|
||||
import { beginChatWait, feedChatWait, resetChatWaitForTests } from "../src/lib/chat-wait-store.ts";
|
||||
import { ChatWaitProgress } from "../src/components/chat-wait-progress.tsx";
|
||||
|
||||
/**
|
||||
* BUG-2283: recorded real event sequences, in the order the consult route sends them (stream-agent-response.ts
|
||||
* collectAgentPublicEvents / mapChunk, consultation-tools.ts data-jyotish-activity).
|
||||
*/
|
||||
const start: ConsultationAgentPublicEvent[] = [
|
||||
{ type: "run.started", runId: "run-1", requestId: "req-1" },
|
||||
{ type: "skill.started", name: "jyotish-vedic-astrology" },
|
||||
{ type: "skill.completed", name: "jyotish-vedic-astrology" },
|
||||
];
|
||||
const tool = (domains: string[]): ConsultationAgentPublicEvent => ({
|
||||
type: "tool.started", callId: "c1", tool: "run-jyotish-consultation", label: "正在计算个人星盘", domains: domains as never,
|
||||
});
|
||||
const done: ConsultationAgentPublicEvent = { type: "tool.completed", callId: "c1", tool: "run-jyotish-consultation", status: "ready", durationMs: 1500 };
|
||||
const compose: ConsultationAgentPublicEvent = { type: "activity", phase: "answer-composition", label: "正在组织回答" };
|
||||
const lookup = (section: string): ConsultationAgentPublicEvent => ({ type: "activity", phase: "answer-composition", label: evidenceLookupActivityLabel(section) });
|
||||
|
||||
function mapped(events: ConsultationAgentPublicEvent[], firstTurn = true) {
|
||||
const view = waitView(reduceWaitEvents(events, firstTurn));
|
||||
assert.equal(view.mappable, true);
|
||||
if (!view.mappable) throw new Error("unmapped");
|
||||
return view;
|
||||
}
|
||||
|
||||
test("the house → plain name table has twelve plain names; domain houses come from the routing", () => {
|
||||
assert.equal(Object.keys(CHART_AREA_NAMES).length, 12);
|
||||
for (const name of Object.values(CHART_AREA_NAMES)) assert.doesNotMatch(name, /宫|第|\d/u);
|
||||
assert.deepEqual(domainChartHouses(consultationDomainDefinition("career").requiredLayers), [10]);
|
||||
assert.deepEqual(domainChartHouses(consultationDomainDefinition("marriage").requiredLayers), [7]);
|
||||
assert.deepEqual(domainChartHouses(consultationDomainDefinition("wealth").requiredLayers), [2, 11, 9, 5]);
|
||||
assert.deepEqual(domainChartHouses(consultationDomainDefinition("general").requiredLayers), []);
|
||||
assert.deepEqual(chartAreaNames([1, 10]), ["性格", "事业"]);
|
||||
// Every registry domain has a plain step line.
|
||||
for (const id of consultationDomainIds) assert.ok(WAIT_DOMAIN_STEPS[id], id);
|
||||
});
|
||||
|
||||
test("career: 性格 → 事业 → the career chart (on tool.completed) → 正在整理回答, lit areas stay", () => {
|
||||
const steps = (view: ReturnType<typeof mapped>) => view.steps.map((step) => `${step.status}:${step.text}`);
|
||||
let view = mapped([...start]);
|
||||
assert.deepEqual(steps(view), [`now:${WAIT_FIRST_STEP}`, `pending:${WAIT_FINAL_STEP}`]);
|
||||
assert.deepEqual(view.lit, [1]);
|
||||
assert.equal(view.caption, "本命盘");
|
||||
|
||||
view = mapped([...start, tool(["career"])]);
|
||||
assert.deepEqual(steps(view), [`done:${WAIT_FIRST_STEP}`, "now:再看事业这一块", "pending:换到专门看事业的那张盘", `pending:${WAIT_FINAL_STEP}`]);
|
||||
assert.deepEqual(view.lit, [1, 10]);
|
||||
assert.deepEqual(view.labeled, [1, 10]);
|
||||
|
||||
// The switch: the career chart, its own area washed, no names written on it.
|
||||
view = mapped([...start, tool(["career"]), done]);
|
||||
assert.equal(view.chart, "D10");
|
||||
assert.equal(view.caption, "专门看事业的那张盘");
|
||||
assert.deepEqual(view.lit, [10]);
|
||||
assert.deepEqual(view.labeled, []);
|
||||
assert.deepEqual(view.natal, [1, 10]);
|
||||
|
||||
// Back on 本命盘 with the earlier areas lit for the last step.
|
||||
view = mapped([...start, tool(["career"]), done, compose]);
|
||||
assert.equal(view.chart, "D1");
|
||||
assert.deepEqual(view.lit, [1, 10]);
|
||||
assert.equal(view.current, WAIT_FINAL_STEP);
|
||||
assert.deepEqual(steps(view).at(-1), `now:${WAIT_FINAL_STEP}`);
|
||||
});
|
||||
|
||||
test("money, relationship, personality and general map through the routing", () => {
|
||||
const money = mapped([...start, tool(["wealth"]), done]);
|
||||
// Wealth routes D2 / D11; neither has a plain name, so no switch is shown.
|
||||
assert.equal(money.chart, "D1");
|
||||
assert.deepEqual(money.lit, [1, 2, 11, 9, 5]);
|
||||
assert.equal(money.current, "再看钱这一块");
|
||||
|
||||
const love = mapped([...start, tool(["marriage"]), done]);
|
||||
assert.equal(love.chart, "D9");
|
||||
assert.equal(love.caption, "专门看感情的那张盘");
|
||||
assert.deepEqual(love.lit, [7]);
|
||||
|
||||
const general = mapped([...start, tool(["general"])]);
|
||||
assert.equal(general.current, "再把整张盘看一遍");
|
||||
assert.deepEqual(general.lit, [1]);
|
||||
|
||||
// Two routed domains: the second becomes current on its own 「第 2/2 项」 event.
|
||||
const two = mapped([...start, tool(["career", "wealth"]),
|
||||
{ type: "activity", phase: "chart-calculation", label: "正在计算本命盘(第 1/2 项)…" },
|
||||
{ type: "activity", phase: "chart-calculation", label: "正在计算本命盘(第 2/2 项)…" }]);
|
||||
assert.equal(two.current, "再看钱这一块");
|
||||
assert.deepEqual(two.lit, [1, 10, 2, 11, 9, 5]);
|
||||
});
|
||||
|
||||
test("the chart switches only when the events show that layer", () => {
|
||||
// tool.started alone: D10 is planned (pending), the picture stays on 本命盘.
|
||||
assert.equal(mapped([...start, tool(["career"])]).chart, "D1");
|
||||
// No tool event at all: never a switch.
|
||||
assert.equal(mapped([...start, compose]).chart, "D1");
|
||||
// An evidence lookup of D9 during a money question switches; an unnamed varga (D7) is a plain detail step.
|
||||
const looked = mapped([...start, tool(["wealth"]), done, lookup("varga:D9")]);
|
||||
assert.equal(looked.chart, "D9");
|
||||
assert.equal(looked.current, "换到专门看感情的那张盘");
|
||||
const unnamed = mapped([...start, tool(["wealth"]), done, lookup("varga:D7")]);
|
||||
assert.equal(unnamed.chart, "D1");
|
||||
assert.equal(unnamed.current, "再多看一处细节");
|
||||
// After a switch, a dasha lookup returns to 本命盘.
|
||||
const back = mapped([...start, tool(["career"]), done, lookup("vimshottari_mahadashas")]);
|
||||
assert.equal(back.chart, "D1");
|
||||
assert.equal(back.current, "回到本命盘,对一遍这几年的时间");
|
||||
assert.deepEqual(back.lit, [1, 10]);
|
||||
});
|
||||
|
||||
test("fallback: no mapped event, an older path, or a follow-up with nothing to light keeps the one-line status", () => {
|
||||
assert.equal(waitView(reduceWaitEvents([{ type: "run.started", runId: "r", requestId: "q" }], true)).mappable, false);
|
||||
assert.equal(waitView(null).mappable, false);
|
||||
// Follow-up: no 性格 step; until a domain arrives there is nothing to light.
|
||||
assert.equal(waitView(reduceWaitEvents([...start], false)).mappable, false);
|
||||
assert.equal(waitView(reduceWaitEvents([...start, compose], false)).mappable, false);
|
||||
const follow = mapped([...start, tool(["career"]), done, compose], false);
|
||||
assert.deepEqual(follow.steps.map((step) => step.text), ["再看事业这一块", "换到专门看事业的那张盘", WAIT_FINAL_STEP]);
|
||||
// A tool failure maps nothing new and never freezes on an empty chart.
|
||||
const failed = mapped([...start, tool(["career"]), { type: "tool.failed", callId: "c1", tool: "run-jyotish-consultation", code: "timeout" }]);
|
||||
assert.equal(failed.current, "再看事业这一块");
|
||||
});
|
||||
|
||||
test("the row shows the steps (chart only when the page has it), else today's status; no planets, no extra request", () => {
|
||||
resetChatWaitForTests();
|
||||
const rows = [{ id: "calculate", kind: "calculate" as const, status: "live" as const, label: "正在计算个人星盘", domains: ["career"] }];
|
||||
// Nothing mapped yet: today's line.
|
||||
beginChatWait("req-1", "s1", true);
|
||||
let markup = renderToStaticMarkup(<ChatWaitProgress rows={rows} live answering={false} question="我适合做什么样的工作?" />);
|
||||
assert.doesNotMatch(markup, /chat-wait-steps/);
|
||||
assert.match(markup, /consultation-run-status is-live/);
|
||||
// Mapped: the plain steps; the chart is not loaded in this test, so only the list shows, and today's line stays mounted, hidden.
|
||||
for (const event of [...start, tool(["career"])]) feedChatWait("req-1", event);
|
||||
markup = renderToStaticMarkup(<ChatWaitProgress rows={rows} live answering={false} question="我适合做什么样的工作?" />);
|
||||
assert.match(markup, /<ol class="chat-wait-steps">/);
|
||||
assert.match(markup, /class="chat-wait-step is-now" aria-current="step"><span class="chat-wait-dot" aria-hidden="true"><\/span>再看事业这一块/);
|
||||
assert.match(markup, /role="status" aria-live="polite">再看事业这一块</);
|
||||
assert.match(markup, /<div class="consultation-run-status-slot" hidden="">/);
|
||||
assert.doesNotMatch(markup, /chat-wait-figure/);
|
||||
// Once the answer has text, today's line takes over again.
|
||||
markup = renderToStaticMarkup(<ChatWaitProgress rows={rows} live answering question="我适合做什么样的工作?" />);
|
||||
assert.doesNotMatch(markup, /chat-wait-steps/);
|
||||
// A stale request id is ignored.
|
||||
feedChatWait("other", compose);
|
||||
resetChatWaitForTests();
|
||||
|
||||
const board = readFileSync(new URL("../src/components/chat-wait-board.tsx", import.meta.url), "utf8");
|
||||
assert.match(board, /bodies: \[\]/);
|
||||
const component = readFileSync(new URL("../src/components/chat-wait-progress.tsx", import.meta.url), "utf8");
|
||||
assert.match(component, /peekChartPage/);
|
||||
assert.doesNotMatch(component, /fetch|ensureChartPage|requestLayer|useChartPage\(/);
|
||||
const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
|
||||
assert.match(css, /@media \(prefers-reduced-motion: reduce\) \{\n \.chat-wait-board \.chart-board-cell polygon,\n \.chat-wait-board \.chart-board-cell rect,\n \.chat-wait-step \{ transition: none; \}/);
|
||||
// The run hook feeds the store from the same events as the timeline.
|
||||
const hook = readFileSync(new URL("../src/hooks/use-consultation-run.ts", import.meta.url), "utf8");
|
||||
assert.match(hook, /if \(responseKind !== "smalltalk"\) feedChatWait\(requestId, event\);/);
|
||||
});
|
||||
|
||||
test("a switched chart the page has not loaded: North keeps the switch, South stays on 本命盘", async () => {
|
||||
const { waitBoard } = await import("../src/components/chat-wait-progress.tsx");
|
||||
const view = mapped([...start, tool(["career"]), done]);
|
||||
const natal = { houses: [] } as never;
|
||||
const chartView = { vedic: { vargas: [{ id: "D1", chart: natal }] } } as never;
|
||||
assert.equal(waitBoard(view, null, "north"), null);
|
||||
const north = waitBoard(view, chartView, "north")!;
|
||||
assert.equal(north.caption, "专门看事业的那张盘");
|
||||
assert.deepEqual(north.lit, [10]);
|
||||
const south = waitBoard(view, chartView, "south")!;
|
||||
assert.equal(south.caption, "本命盘");
|
||||
assert.deepEqual(south.lit, [1, 10]);
|
||||
});
|
||||
@@ -75,7 +75,8 @@ function NewcomerHome({ newcomer }: { newcomer: boolean }) {
|
||||
|
||||
test("BUG-2201: the newcomer home is headed 「从这三个问题开始」; the panel starts folded and the top-bar button opens it", async () => {
|
||||
const markup = renderToStaticMarkup(<StarterQuestions audience={{ kind: "self" }} subjectId="self" signs={{ ascendantSign: null, moonSign: "Taurus" }} onAsk={noop} />);
|
||||
assert.match(markup, /^<div class="starter-questions"><h2 class="starter-questions-title">从这三个问题开始<\/h2>/);
|
||||
// 原值: 标题直接在 .starter-questions 下;新值: 标题和「换一组」图标按钮同在 .starter-questions-head 一行;原因: BUG-2282 负责人 2026-11-24
|
||||
assert.match(markup, /^<div class="starter-questions"><div class="starter-questions-head"><h2 class="starter-questions-title">从这三个问题开始<\/h2><button[^>]*aria-label="换一组"/);
|
||||
assert.match(css, /\.starter-questions-title \{[^}]*font-family: var\(--font-display\); font-size: var\(--type-title-md\); font-weight: 500;/);
|
||||
|
||||
// Owner 2026-11-22: no separate 「展开星盘详情」 row; the existing top-bar button is the only control.
|
||||
@@ -83,7 +84,10 @@ test("BUG-2201: the newcomer home is headed 「从这三个问题开始」; the
|
||||
assert.doesNotMatch(css, /starter-chart-details/);
|
||||
assert.doesNotMatch(page, /StarterChartDetails|展开星盘详情/);
|
||||
assert.match(page, /const newcomerHome = starterHomeVisible && account\?\.firstConsultFree === true/);
|
||||
assert.match(page, /\{newcomerHome \? \(\n\s*<StarterQuestions/);
|
||||
// 原值: {newcomerHome ? (<StarterQuestions …)},只有首问免费未用时显示;新值: 每个新的空对话都显示,newcomer 只决定标题;
|
||||
// 原因: BUG-2282 负责人 2026-11-24 同意原型「刚进来」。星盘面板收起(useStarterChartFold)仍只看 newcomerHome。
|
||||
assert.match(page, /const starterQuestionsVisible = newcomerHome \|\| \(starterHomeVisible/);
|
||||
assert.match(page, /\{starterQuestionsVisible \? \(\n\s*<StarterQuestions\n\s*newcomer=\{newcomerHome\}/);
|
||||
assert.match(page, /useStarterChartFold\(newcomerHome\);/);
|
||||
assert.match(read("components/chat-chart-frame.tsx"), /export function useStarterChartFold[\s\S]*?useLayoutEffect\(/);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import test from "node:test";
|
||||
import { readOnboardingIntake } from "../src/lib/onboarding-intake.ts";
|
||||
import { missingProfileStep, onboardingCatalogDecision } from "../src/lib/home-profile.ts";
|
||||
import { emptyProfile, type Profile } from "../src/lib/home-types.ts";
|
||||
import { otherSkySubjectLine, STARTER_RECTIFY_FIRST, starterQuestions, type StarterChartSigns } from "../src/lib/starter-questions.ts";
|
||||
import { otherSkySubjectLine, STARTER_PROMPTS, STARTER_RECTIFY_FIRST, starterFirstSet, starterQuestions, type StarterChartSigns } from "../src/lib/starter-questions.ts";
|
||||
|
||||
/** Fictional chart. 1990-01-02 and 杭州 are not a real person's birth data. */
|
||||
function chart(name: string, ready: boolean): Profile {
|
||||
@@ -116,8 +116,15 @@ test("an estimated birth time turns the third starter into the time check (产
|
||||
assert.equal(starterQuestions(self, both, { birthTimeUncertain: true })[2], STARTER_RECTIFY_FIRST);
|
||||
assert.equal(STARTER_RECTIFY_FIRST, "出生时间先核对,再问具体的事");
|
||||
const questions = readFileSync(new URL("../src/components/starter-questions.tsx", import.meta.url), "utf8");
|
||||
assert.match(questions, /starterQuestions\(audience, signs, \{ birthTimeUncertain: rectifyHint \}\)/);
|
||||
assert.match(questions, /href=\{RECTIFICATION_PAGE_HREF\} data-onboarding-press="" data-onboarding-enter="starter-2"/);
|
||||
// 原值: 组件里直接调 starterQuestions(audience, signs, { birthTimeUncertain: rectifyHint }),第三张卡链接写死 data-onboarding-enter="starter-2"
|
||||
// 新值: 组件调 starterFirstSet(...)(同样的三问,多了话题词),rectify 卡仍链到生时纠正,首组仍带 starter-0..2 的入场标记
|
||||
// 原因: BUG-2282,每个新对话都显示三问并可「换一组」,负责人 2026-11-24
|
||||
assert.match(questions, /starterFirstSet\(audience, signs, \{ birthTimeUncertain: rectifyHint \}\)/);
|
||||
assert.match(questions, /href=\{RECTIFICATION_PAGE_HREF\} data-onboarding-press=""/);
|
||||
assert.match(questions, /"data-onboarding-enter": `starter-\$\{index\}`/);
|
||||
const rectifyCard = starterFirstSet(self, both, { birthTimeUncertain: true })[2];
|
||||
assert.equal(rectifyCard.rectify, true);
|
||||
assert.equal(rectifyCard.label, STARTER_RECTIFY_FIRST);
|
||||
});
|
||||
|
||||
test("the third starter question sends like the other two (BUG-2144)", () => {
|
||||
@@ -130,7 +137,13 @@ test("the third starter question sends like the other two (BUG-2144)", () => {
|
||||
// 原值: onClick={() => onAsk(prompts[2], "timing")}
|
||||
// 新值: 第三问另带 entrypoint "starter_plan_timing",服务端据此先追问计划和期限
|
||||
// 原因: BUG-2160 / BUG-2161,占星师 2026-11-22 第 9 节「先确认具体是什么计划、希望什么时候完成」
|
||||
assert.match(questions, /onClick=\{\(\) => onAsk\(prompts\[2\], "timing", STARTER_PLAN_TIMING_ENTRYPOINT\)\}/);
|
||||
// 原值: onClick={() => onAsk(prompts[2], "timing", STARTER_PLAN_TIMING_ENTRYPOINT)}
|
||||
// 新值: 卡片数据里第三问带 planTiming,点击时 onAsk(item.prompt, "timing", STARTER_PLAN_TIMING_ENTRYPOINT),发出的全文不变
|
||||
// 原因: BUG-2282,三问改成按卡片数据渲染(可换一组)
|
||||
assert.match(questions, /onAsk\(item\.prompt, "timing", STARTER_PLAN_TIMING_ENTRYPOINT\)/);
|
||||
const timingCard = starterFirstSet({ kind: "self" }, both)[2];
|
||||
assert.equal(timingCard.planTiming, true);
|
||||
assert.equal(timingCard.prompt, STARTER_PROMPTS[2]);
|
||||
assert.doesNotMatch(questions, /onFill|onNudge/);
|
||||
assert.doesNotMatch(page, /onFill=|onNudge=|function nudgeComposer/);
|
||||
// 首问免费(BUG-1431 的「第一次提问还没用掉」)仍是起步三问出现的条件:firstConsultFree 就是 first_consult_free_used_at 为空。
|
||||
|
||||
@@ -426,12 +426,14 @@ test("the three starters sit right above the composer, as wide as it, and all th
|
||||
const asked: [string, string | undefined][] = [];
|
||||
try {
|
||||
await harness.render(<StarterQuestions audience={{ kind: "self" }} subjectId="self" signs={{ ascendantSign: null, moonSign: "Taurus" }} onAsk={(question, theme) => { asked.push([question, theme]); }} />);
|
||||
const cards = harness.elements().filter((node) => node.tagName === "BUTTON");
|
||||
// 原值: 三个按钮就是全部按钮;新值: 另有一枚「换一组」图标按钮,三张卡不含它;原因: BUG-2282 负责人 2026-11-24「点一下换三个问题」
|
||||
const cards = harness.elements().filter((node) => node.tagName === "BUTTON" && node.getAttribute("aria-label") !== "换一组");
|
||||
assert.equal(cards.length, 3);
|
||||
for (const card of cards) await harness.event(card);
|
||||
assert.deepEqual(asked, [[STARTER_PROMPTS[0], undefined], [STARTER_PROMPTS[1], undefined], [STARTER_PROMPTS[2], "timing"]]);
|
||||
// 原值: 「今年哪段时间适合推进一件事」;新值: 「今年推进重要计划,先看什么?」;原因: BUG-2160 占星师 2026-11-22 第 9 项定稿
|
||||
assert.ok(cards.some((card) => card.text === "今年推进重要计划,先看什么?"));
|
||||
// BUG-2282 原值: 卡片文字就是问题;新值: 问题前有话题词(「时机」);原因: 负责人 2026-11-24 每行带话题词
|
||||
assert.ok(cards.some((card) => card.text === "时机今年推进重要计划,先看什么?"));
|
||||
} finally {
|
||||
await harness.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { StarterQuestions } from "../src/components/starter-questions.tsx";
|
||||
import { CONSULT_PRESET_DOMAINS } from "../src/lib/consult-preset-prompts.ts";
|
||||
import { STARTER_PROMPTS, starterFirstSet, starterLibrarySets } from "../src/lib/starter-questions.ts";
|
||||
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support.ts";
|
||||
|
||||
const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
const self = { kind: "self" as const };
|
||||
const noSigns = { ascendantSign: null, moonSign: "Taurus" };
|
||||
const TERMS = /大运|行运|土星|木星|宫|上升|月亮|星盘|命盘|白羊|金牛|双子|巨蟹|狮子|处女|天秤|天蝎|射手|摩羯|水瓶|双鱼/u;
|
||||
|
||||
test("BUG-2282: first set = the three starters with topic words, 「我是一个什么样的人?」 first", () => {
|
||||
const first = starterFirstSet(self, noSigns);
|
||||
assert.deepEqual(first.map((card) => card.topic), ["性格", "工作", "时机"]);
|
||||
assert.equal(first[0].label, "我是一个什么样的人?");
|
||||
assert.deepEqual(first.map((card) => card.prompt), [...STARTER_PROMPTS]);
|
||||
});
|
||||
|
||||
test("BUG-2282: further sets are three different topics, plain, sendable, no repeats, 工作 / 感情 / 钱 / 性格 first", () => {
|
||||
const sets = starterLibrarySets(self, CONSULT_PRESET_DOMAINS);
|
||||
assert.ok(sets.length >= 5, `sets: ${sets.length}`);
|
||||
assert.deepEqual(sets[0]!.map((card) => card.topic), ["工作", "感情", "钱"]);
|
||||
assert.equal(sets[1]![0]!.topic, "性格");
|
||||
const labels = new Set<string>();
|
||||
for (const set of sets) {
|
||||
assert.equal(new Set(set.map((card) => card.topic)).size, 3);
|
||||
for (const card of set) {
|
||||
assert.doesNotMatch(card.label, TERMS, card.label);
|
||||
assert.ok(!card.prompt.includes("("), card.label);
|
||||
assert.ok(!labels.has(card.label), card.label);
|
||||
labels.add(card.label);
|
||||
}
|
||||
}
|
||||
// Someone else's chart: the existing name rule (「我」 → the name).
|
||||
const other = starterLibrarySets({ kind: "other", name: "小舟", relationLabel: "朋友" }, CONSULT_PRESET_DOMAINS);
|
||||
assert.ok(other.flat().every((card) => !card.label.includes("我") && !card.prompt.includes("我")));
|
||||
assert.ok(other.flat().some((card) => card.label.includes("小舟")));
|
||||
});
|
||||
|
||||
test("BUG-2282: one tap sends; the refresh icon swaps all three and cycles back to the first set", async () => {
|
||||
const harness = createClientLifecycleHarness();
|
||||
const asked: [string, string | undefined, string | undefined][] = [];
|
||||
try {
|
||||
await harness.render(<StarterQuestions newcomer={false} audience={self} subjectId="self" signs={noSigns} onAsk={(question, theme, entrypoint) => { asked.push([question, theme, entrypoint]); }} />);
|
||||
const cards = () => harness.elements().filter((node) => node.tagName === "BUTTON" && node.getAttribute("aria-label") !== "换一组");
|
||||
const refresh = () => harness.elements().find((node) => node.getAttribute("aria-label") === "换一组")!;
|
||||
assert.equal(cards().length, 3);
|
||||
await harness.event(cards()[0]!);
|
||||
assert.deepEqual(asked[0], [STARTER_PROMPTS[0], undefined, undefined]);
|
||||
await harness.event(refresh());
|
||||
const sets = starterLibrarySets(self, CONSULT_PRESET_DOMAINS);
|
||||
assert.deepEqual(cards().map((card) => card.text), sets[0]!.map((card) => `${card.topic}${card.label}`));
|
||||
await harness.event(cards()[1]!);
|
||||
assert.deepEqual(asked[1], [sets[0]![1]!.prompt, "marriage", undefined]);
|
||||
for (let index = 1; index <= sets.length; index += 1) await harness.event(refresh());
|
||||
assert.equal(cards()[0]!.text, "性格我是一个什么样的人?");
|
||||
} finally {
|
||||
await harness.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("BUG-2282: shown on every new empty conversation; heading, fold and billing for newcomers unchanged", () => {
|
||||
const page = read("../src/app/(app)/page.tsx");
|
||||
assert.match(page, /const starterQuestionsVisible = newcomerHome \|\| \(starterHomeVisible\n\s*&& activeSession\?\.sessionType === "consultation"\n\s*&& !synastryChat && !subjectDeleted && !retiredRectificationSession\);/);
|
||||
assert.match(page, /useStarterChartFold\(newcomerHome\);/);
|
||||
assert.match(page, /const newcomerHome = starterHomeVisible && account\?\.firstConsultFree === true/);
|
||||
const newcomer = renderToStaticMarkup(<StarterQuestions audience={self} subjectId="self" signs={noSigns} onAsk={() => {}} />);
|
||||
assert.match(newcomer, />从这三个问题开始</);
|
||||
const returning = renderToStaticMarkup(<StarterQuestions newcomer={false} audience={self} subjectId="self" signs={noSigns} onAsk={() => {}} />);
|
||||
assert.match(returning, />想知道什么,点一个就能问</);
|
||||
assert.match(returning, /aria-label="换一组"/);
|
||||
assert.match(returning, /<span class="starter-question-topic">性格<\/span><span class="starter-question-text">我是一个什么样的人?<\/span>/);
|
||||
// Fixed card height (the composer never moves on a swap); swap motion off under reduced motion.
|
||||
const css = read("../src/app/globals.css");
|
||||
assert.match(css, /\.starter-questions-list \.starter-question \{[^}]*height: 88px;/);
|
||||
assert.match(css, /\.starter-questions-list \.starter-question \{ flex-direction: row; align-items: center; gap: 12px; height: 68px; \}/);
|
||||
assert.match(css, /@media \(prefers-reduced-motion: reduce\) \{ \.starter-questions-list\.is-swapped \{ animation: none; \} \}/);
|
||||
// The composer's 常用问题 pill is still there.
|
||||
assert.match(page, /<ConsultPresetMenu disabled=/);
|
||||
});
|
||||
@@ -3,14 +3,20 @@ import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
import { STARTER_PLAN_TIMING_ENTRYPOINT, isBareStarterPlanTimingQuestion } from "../src/lib/plan-timing-clarify.ts";
|
||||
import { starterPrompts } from "../src/lib/starter-questions.ts";
|
||||
import { CONSULT_PRESET_DOMAINS } from "../src/lib/consult-preset-prompts.ts";
|
||||
import { starterFirstSet, starterLibrarySets, starterPrompts } from "../src/lib/starter-questions.ts";
|
||||
|
||||
const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf8");
|
||||
|
||||
test("BUG-2160: the third starter sends the plan-timing entrypoint and the page passes it on", () => {
|
||||
const starter = read("../src/components/starter-questions.tsx");
|
||||
assert.match(starter, /onAsk\(prompts\[2\], "timing", STARTER_PLAN_TIMING_ENTRYPOINT\)/);
|
||||
assert.doesNotMatch(starter, /onAsk\(prompts\[[01]\][^)]*STARTER_PLAN_TIMING_ENTRYPOINT/);
|
||||
// 原值: onAsk(prompts[2], "timing", STARTER_PLAN_TIMING_ENTRYPOINT),前两问不带 entrypoint
|
||||
// 新值: 只有带 planTiming 的卡(首组第三问)带 entrypoint;其他卡(含换一组的问题)不带
|
||||
// 原因: BUG-2282,三问改成按卡片数据渲染,可换一组
|
||||
assert.match(starter, /item\.planTiming\s*\?\s*onAsk\(item\.prompt, "timing", STARTER_PLAN_TIMING_ENTRYPOINT\)\s*:\s*onAsk\(item\.prompt, item\.theme \?\? undefined\)/);
|
||||
const first = starterFirstSet({ kind: "self" }, { ascendantSign: null, moonSign: null });
|
||||
assert.deepEqual(first.map((card) => Boolean(card.planTiming)), [false, false, true]);
|
||||
assert.ok(starterLibrarySets({ kind: "self" }, CONSULT_PRESET_DOMAINS).flat().every((card) => !card.planTiming));
|
||||
const page = read("../src/app/(app)/page.tsx");
|
||||
assert.match(page, /onAsk=\{\(text, theme, entrypoint\) => void startSuggestedConsultation\(text, theme, entrypoint \?\? null\)\}/);
|
||||
assert.equal(STARTER_PLAN_TIMING_ENTRYPOINT, "starter_plan_timing");
|
||||
|
||||
Reference in New Issue
Block a user