fix(home): serve today's starlanguage from daily guidance
The homepage was waiting on a full chart plus four extra engines, so the card timed out and showed the failure copy on every visit. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,8 +4,8 @@ import {
|
||||
composeDailyStarlanguageCard,
|
||||
dailyStarlanguageCacheKey,
|
||||
dailyStarlanguageCardSchema,
|
||||
dailyStarlanguageEvidence,
|
||||
dailyStarlanguagePrompt,
|
||||
evidenceFromDailyGuidance,
|
||||
parseDailyStarlanguageText,
|
||||
type DailyStarlanguageCard,
|
||||
type DailyStarlanguageEvidence,
|
||||
@@ -19,7 +19,7 @@ import { createServerSupabaseClient } from "@/lib/supabase/server";
|
||||
import { getDailyStarlanguageAgent } from "@/mastra";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 30;
|
||||
export const maxDuration = 20;
|
||||
|
||||
type Profile = GlobalBirthProfile & { birthTimeStatus?: string; timezoneId?: string };
|
||||
type BirthPayload = NonNullable<Awaited<ReturnType<typeof dailyProfilePayload>>>;
|
||||
@@ -35,7 +35,7 @@ type Generated =
|
||||
| { readonly kind: "failed"; readonly reason: "chart_unavailable" };
|
||||
|
||||
const jyotishApiBase = process.env.JYOTISH_API_BASE ?? "http://127.0.0.1:5200";
|
||||
const engineTimeoutMs = 20_000;
|
||||
const engineTimeoutMs = 8_000;
|
||||
const agentTimeoutMs = 45_000;
|
||||
const cacheLimit = 500;
|
||||
|
||||
@@ -89,37 +89,17 @@ async function fetchEngine(path: string, body: Record<string, unknown>) {
|
||||
return await response.json() as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function chartPoints(chart: Record<string, unknown>) {
|
||||
const modules = chart.modules && typeof chart.modules === "object" ? chart.modules as Record<string, unknown> : {};
|
||||
const chartModule = modules.chart && typeof modules.chart === "object" ? modules.chart as Record<string, unknown> : chart;
|
||||
const planets = chartModule.planets && typeof chartModule.planets === "object" ? chartModule.planets : undefined;
|
||||
const ascendant = chartModule.ascendant && typeof chartModule.ascendant === "object" ? chartModule.ascendant : undefined;
|
||||
return planets && ascendant ? { planets, ascendant } : null;
|
||||
}
|
||||
|
||||
async function collectLayers(payload: BirthPayload, today: string) {
|
||||
const chart = await fetchEngine("/api/chart", payload).catch((error: unknown) => {
|
||||
console.warn("daily_starlanguage_chart_unavailable", error);
|
||||
async function loadDailyGuidance(payload: BirthPayload, today: string) {
|
||||
const packet = await fetchEngine("/api/daily_guidance", {
|
||||
...payload,
|
||||
date: today,
|
||||
reference_date: today,
|
||||
}).catch((error: unknown) => {
|
||||
console.warn("daily_starlanguage_guidance_unavailable", error);
|
||||
return null;
|
||||
});
|
||||
const points = chart === null ? null : chartPoints(chart);
|
||||
if (chart === null || !points) return null;
|
||||
const tomorrow = new Date(`${today}T00:00:00.000Z`);
|
||||
tomorrow.setUTCDate(tomorrow.getUTCDate() + 1);
|
||||
const withPoints = { ...payload, planets: points.planets, ascendant: points.ascendant };
|
||||
const [vimshottari, narayana, varga, transit] = await Promise.all([
|
||||
fetchEngine("/api/dasha", { ...withPoints, dasha: "vimshottari", today }).catch(() => null),
|
||||
fetchEngine("/api/dasha", { ...withPoints, dasha: "narayana", today }).catch(() => null),
|
||||
fetchEngine("/api/varga_full", { ...withPoints, divisions: ["D9", "D10"] }).catch(() => null),
|
||||
fetchEngine("/api/transit", {
|
||||
natal_planets: points.planets,
|
||||
ascendant: points.ascendant,
|
||||
start: today,
|
||||
end: tomorrow.toISOString().slice(0, 10),
|
||||
planets_to_check: ["Saturn", "Jupiter", "Rahu", "Ketu", "Mars", "Sun"],
|
||||
}).catch(() => null),
|
||||
]);
|
||||
return { chart, vimshottari, narayana, varga, transit };
|
||||
if (!packet || packet.success !== true) return null;
|
||||
return packet;
|
||||
}
|
||||
|
||||
async function polishWithAgent(evidence: DailyStarlanguageEvidence): Promise<DailyStarlanguageCard | null> {
|
||||
@@ -158,9 +138,10 @@ function scheduleAgentPolish(key: string, today: string, evidence: DailyStarlang
|
||||
}
|
||||
|
||||
async function generateCard(payload: BirthPayload, profile: Profile, today: string): Promise<Generated> {
|
||||
const layers = await collectLayers(payload, today);
|
||||
if (!layers) return { kind: "failed", reason: "chart_unavailable" };
|
||||
const evidence = dailyStarlanguageEvidence(layers, today, profile.birthTimeStatus === "confirmed");
|
||||
const packet = await loadDailyGuidance(payload, today);
|
||||
if (!packet) return { kind: "failed", reason: "chart_unavailable" };
|
||||
const evidence = evidenceFromDailyGuidance(packet, today, profile.birthTimeStatus === "confirmed");
|
||||
if (!evidence) return { kind: "failed", reason: "chart_unavailable" };
|
||||
return {
|
||||
kind: "card",
|
||||
card: composeDailyStarlanguageCard(evidence),
|
||||
|
||||
Reference in New Issue
Block a user