Hospital records and adopted rectification times were still fed to the model as not_auto_rectified because the chart request omitted declared_accuracy/time_source and mastra hardcoded the boundary. Map profile truth into the engine request, keep rectified for accepted/confirmed active times only, and leave window/general guards unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.9 KiB
TypeScript
88 lines
2.9 KiB
TypeScript
import { z } from "zod";
|
|
import {
|
|
guardGeneralNoBirthTimeOutput,
|
|
guardPreciseTimingOutput,
|
|
} from "./timing-output-guard.ts";
|
|
|
|
export const consultationBirthTimeModeSchema = z.enum([
|
|
"verified_chart",
|
|
"unverified_birth_time",
|
|
"declared_birth_window",
|
|
"general_no_birth_time",
|
|
]);
|
|
|
|
export type ConsultationBirthTimeMode = z.infer<typeof consultationBirthTimeModeSchema>;
|
|
export type NatalMinuteConsultationMode = Extract<
|
|
ConsultationBirthTimeMode,
|
|
"verified_chart" | "unverified_birth_time"
|
|
>;
|
|
|
|
export const UNVERIFIED_BIRTH_TIME_NOTICE = "使用未校正填报时间;分钟敏感结论的置信度已降低。";
|
|
export const HOSPITAL_REPORTED_BIRTH_TIME_NOTICE = "使用你填报的出生时间(医院记录)排盘";
|
|
export const FAMILY_EXACT_REPORTED_BIRTH_TIME_NOTICE = "使用你填报的出生时间排盘;分钟敏感结论的置信度已降低。";
|
|
|
|
export function unverifiedBirthTimeNotice(source: string | null | undefined): string {
|
|
if (source === "hospital_record") return HOSPITAL_REPORTED_BIRTH_TIME_NOTICE;
|
|
if (source === "family_exact") return FAMILY_EXACT_REPORTED_BIRTH_TIME_NOTICE;
|
|
return UNVERIFIED_BIRTH_TIME_NOTICE;
|
|
}
|
|
|
|
export function isNatalMinuteConsultationMode(
|
|
mode: ConsultationBirthTimeMode,
|
|
): mode is NatalMinuteConsultationMode {
|
|
return mode === "verified_chart" || mode === "unverified_birth_time";
|
|
}
|
|
|
|
export function shouldRunBirthChartWorkflow(mode: ConsultationBirthTimeMode): boolean {
|
|
return isNatalMinuteConsultationMode(mode);
|
|
}
|
|
|
|
export function shouldRunDeclaredWindowWorkflow(mode: ConsultationBirthTimeMode): boolean {
|
|
return mode === "declared_birth_window";
|
|
}
|
|
|
|
export function applyBirthTimeModeToWorkflowContext<
|
|
T extends {
|
|
consumer_context: {
|
|
answer_policy: Record<string, unknown>;
|
|
[key: string]: unknown;
|
|
};
|
|
[key: string]: unknown;
|
|
},
|
|
>(
|
|
context: T,
|
|
mode: ConsultationBirthTimeMode,
|
|
options?: { birthTimeSource?: string | null },
|
|
): T {
|
|
if (mode !== "unverified_birth_time") return context;
|
|
return {
|
|
...context,
|
|
consumer_context: {
|
|
...context.consumer_context,
|
|
birth_time_notice: unverifiedBirthTimeNotice(options?.birthTimeSource),
|
|
answer_policy: {
|
|
...context.consumer_context.answer_policy,
|
|
birth_time_confidence: "unverified_reported_time",
|
|
candidate_is_confirmed: false,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Server-side output boundary. Timing and guarantee filtering remains active
|
|
* without inserting a rectification warning into every answer.
|
|
*/
|
|
export function createBirthTimeModeOutputGuard(
|
|
mode: ConsultationBirthTimeMode,
|
|
canAnswerPreciseTiming: boolean,
|
|
): (text: string) => string {
|
|
return (text) => {
|
|
if (mode === "general_no_birth_time") return guardGeneralNoBirthTimeOutput(text);
|
|
if (mode === "declared_birth_window" || !canAnswerPreciseTiming) {
|
|
return guardPreciseTimingOutput(text);
|
|
}
|
|
return text;
|
|
};
|
|
}
|