Add login gate, calculation history, and AI markdown download.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import RegionSelect, {
|
||||
} from "@/components/shared/region-select";
|
||||
import { calculateBazi, type BaziChart } from "@/lib/calc/bazi";
|
||||
import { streamAiCompletion } from "@/lib/ai/client-stream";
|
||||
import { saveHistoryEntry } from "@/lib/history/storage";
|
||||
|
||||
export default function BaziForm() {
|
||||
const [date, setDate] = useState(todaySolarYmd());
|
||||
@@ -80,7 +81,7 @@ export default function BaziForm() {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
await streamAiCompletion(
|
||||
const text = await streamAiCompletion(
|
||||
{
|
||||
mode: "bazi",
|
||||
payload: {
|
||||
@@ -91,6 +92,18 @@ export default function BaziForm() {
|
||||
},
|
||||
setCompletion,
|
||||
);
|
||||
saveHistoryEntry({
|
||||
mode: "bazi",
|
||||
title: "生辰八字解读",
|
||||
question,
|
||||
summary: activeChart.lunarDate,
|
||||
completion: text,
|
||||
meta: {
|
||||
出生地域: location!.name,
|
||||
阳历生日: `${input.date} ${input.time}`,
|
||||
农历: activeChart.lunarDate,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
@@ -98,6 +111,12 @@ export default function BaziForm() {
|
||||
}
|
||||
}
|
||||
|
||||
const activeChartPreview = chart;
|
||||
const downloadPreamble =
|
||||
completion && location
|
||||
? `# 生辰八字 AI 解读\n\n- 问事:${question}\n- 出生地域:${location.name}\n- 阳历:${date} ${unknownHour ? "时辰不详" : time}\n${activeChartPreview ? `- 农历:${activeChartPreview.lunarDate}\n` : ""}`
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<ModeWorkspace
|
||||
aiPanel={
|
||||
@@ -108,6 +127,8 @@ export default function BaziForm() {
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
emptyHint="排盘后点击「AI 测算」获取解读"
|
||||
downloadFilename={completion ? "生辰八字解读.md" : undefined}
|
||||
downloadPreamble={downloadPreamble}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -23,6 +23,7 @@ import RegionSelect, {
|
||||
import { calculateBazi, type BaziChart } from "@/lib/calc/bazi";
|
||||
import type { GuaResult } from "@/lib/calc/hexagram";
|
||||
import { streamAiCompletion } from "@/lib/ai/client-stream";
|
||||
import { saveHistoryEntry } from "@/lib/history/storage";
|
||||
|
||||
export default function CombinedForm() {
|
||||
const [birthDate, setBirthDate] = useState(todaySolarYmd());
|
||||
@@ -114,8 +115,18 @@ export default function CombinedForm() {
|
||||
setCompletion("");
|
||||
setIsLoading(true);
|
||||
|
||||
const activeChart =
|
||||
chart ??
|
||||
calculateBazi({
|
||||
date: birthDate,
|
||||
time: unknownHour ? "12:00" : birthTime,
|
||||
gender,
|
||||
longitude: birthLocation!.longitude,
|
||||
unknownHour,
|
||||
});
|
||||
|
||||
try {
|
||||
await streamAiCompletion(
|
||||
const text = await streamAiCompletion(
|
||||
{
|
||||
mode: "combined",
|
||||
payload: {
|
||||
@@ -144,6 +155,19 @@ export default function CombinedForm() {
|
||||
},
|
||||
setCompletion,
|
||||
);
|
||||
saveHistoryEntry({
|
||||
mode: "combined",
|
||||
title: "综合测算解读",
|
||||
question,
|
||||
summary: activeChart.lunarDate,
|
||||
completion: text,
|
||||
meta: {
|
||||
出生地域: birthLocation!.name,
|
||||
当前地域: currentLocation!.name,
|
||||
测算时间: `${calcDate} ${calcTime}`,
|
||||
六爻: withHexagram && guaData ? guaData.result.guaTitle : "无",
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e));
|
||||
} finally {
|
||||
@@ -151,6 +175,11 @@ export default function CombinedForm() {
|
||||
}
|
||||
}
|
||||
|
||||
const downloadPreamble =
|
||||
completion && birthLocation && currentLocation
|
||||
? `# 综合测算 AI 解读\n\n- 问事:${question}\n- 出生地域:${birthLocation.name}\n- 当前地域:${currentLocation.name}\n- 测算时间:${calcDate} ${calcTime}\n${chart ? `- 农历:${chart.lunarDate}\n` : ""}${withHexagram && guaData ? `- 六爻:${guaData.result.guaTitle}\n` : ""}`
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<ModeWorkspace
|
||||
aiTitle="综合解读"
|
||||
@@ -162,6 +191,8 @@ export default function CombinedForm() {
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
emptyHint="填写完整信息后,点击「综合测算」"
|
||||
downloadFilename={completion ? "综合测算解读.md" : undefined}
|
||||
downloadPreamble={downloadPreamble}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -17,6 +17,7 @@ import RegionSelect, {
|
||||
useRegionLocation,
|
||||
} from "@/components/shared/region-select";
|
||||
import { streamAiCompletion } from "@/lib/ai/client-stream";
|
||||
import { saveHistoryEntry } from "@/lib/history/storage";
|
||||
import type { GuaResult } from "@/lib/calc/hexagram";
|
||||
import todayJson from "@/lib/data/today.json";
|
||||
|
||||
@@ -68,7 +69,7 @@ export default function LiuyaoForm() {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
await streamAiCompletion(
|
||||
const text = await streamAiCompletion(
|
||||
{
|
||||
mode: "liuyao",
|
||||
payload: {
|
||||
@@ -85,6 +86,18 @@ export default function LiuyaoForm() {
|
||||
},
|
||||
setCompletion,
|
||||
);
|
||||
saveHistoryEntry({
|
||||
mode: "liuyao",
|
||||
title: guaData!.result.guaTitle,
|
||||
question,
|
||||
summary: guaData!.result.guaResult,
|
||||
completion: text,
|
||||
meta: {
|
||||
地域: location!.name,
|
||||
起卦时间: `${calcDate} ${calcTime}`,
|
||||
卦象: guaData!.result.guaTitle,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e));
|
||||
} finally {
|
||||
@@ -112,6 +125,11 @@ export default function LiuyaoForm() {
|
||||
setError("");
|
||||
}
|
||||
|
||||
const downloadPreamble =
|
||||
guaData && location
|
||||
? `# 六爻算卦 AI 解读\n\n- 问事:${question}\n- 地域:${location.name}\n- 时间:${calcDate} ${calcTime}\n- 卦象:${guaData.result.guaTitle}\n`
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<ModeWorkspace
|
||||
aiPanel={
|
||||
@@ -122,6 +140,12 @@ export default function LiuyaoForm() {
|
||||
onCompletion={handleAnalyze}
|
||||
error={error}
|
||||
emptyHint="完成起卦后,点击「AI 解读」"
|
||||
downloadFilename={
|
||||
completion && guaData
|
||||
? `六爻-${guaData.result.guaTitle.replace(/[/\\?%*:|"<>]/g, "-")}.md`
|
||||
: undefined
|
||||
}
|
||||
downloadPreamble={downloadPreamble}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user