feat: make birth-time rectification conversational

This commit is contained in:
Jesse_Chen
2026-07-23 13:12:09 +08:00
parent 200c39d22b
commit f9010c8797
34 changed files with 1720 additions and 177 deletions
@@ -21,7 +21,10 @@ import {
type DeclaredBirthInput,
type LifeEventEvidence,
} from "../../../lib/conversational-rectification/persistence-contracts.ts";
import type { RectificationNarrativeGenerator } from "../../../lib/conversational-rectification/narrative-agent.ts";
import {
rectificationNarrativeOutputSchema,
type RectificationNarrativeGenerator,
} from "../../../lib/conversational-rectification/narrative-agent.ts";
import type { BirthTimeJourneyEngine, RectificationQuestionnaire } from "../../../lib/birth-time-journey-service.ts";
import type { CandidateResult, LifeEvent } from "../../../lib/birth-time-evidence.ts";
import type { CandidateDifferenceBuild } from "../../../lib/birth-time-dynamic-choice-internal.ts";
@@ -353,6 +356,7 @@ function scoreableLifeEvents(
domain: item.domain,
precision: item.datePrecision as "day" | "month" | "year",
date: item.dateValue,
summary: item.eventSummary,
} as LifeEvent];
}).slice(-MAXIMUM_SCOREABLE_EVENTS);
}
@@ -671,13 +675,21 @@ async function productionNarrativeGenerator(): Promise<RectificationNarrativeGen
name: "Conversational Rectification Narrator",
model: model.model,
skills: [jyotishSkillPath],
instructions: "Return only the exact JSON object requested by the user prompt. Use the Jyotish Skill only to choose a natural, one-question-at-a-time evidence strategy and wording. Treat supplied packet facts as the exclusive source of candidate times, status, dates, layers, scores, references, and confirmation permissions. Never invent, recalculate, or confirm candidate data.",
instructions: "Return only the exact JSON object requested by the user prompt. Load the Jyotish Skill to choose a natural, one-question-at-a-time evidence strategy and to explain the supplied expert workflow. Treat supplied packet facts as the exclusive source of candidate times, status, dates, layers, scores, technique states, references, and confirmation permissions. Never invent, recalculate, or confirm candidate data. A blocked or not_evaluated technique must never be described as used. On final turns, include a concise user-readable Technique Audit Table from packet.expertWorkflow; on collecting turns, keep the reply conversational and ask exactly one next question.",
});
return {
modelId: model.id,
async generate(prompt) {
const result = await agent.generate([{ role: "user", content: prompt }]);
return { text: result.text };
const result = await agent.generate(
[{ role: "user", content: prompt }],
{
structuredOutput: {
schema: rectificationNarrativeOutputSchema,
jsonPromptInjection: "inline",
},
},
);
return { text: JSON.stringify(rectificationNarrativeOutputSchema.parse(result.object)) };
},
};
}