diff --git a/src/lib/insights/memory.ts b/src/lib/insights/memory.ts index b9277dd69..450c74df4 100644 --- a/src/lib/insights/memory.ts +++ b/src/lib/insights/memory.ts @@ -33,6 +33,16 @@ export type InsightScope = | "medication-compliance-status" | "mood-status"; +/** + * v1.8.7.1 — the generic per-HealthKit-metric assessments key their + * previous-context rows under `insights.metric:-status.`, the + * same `-status` action shape the seven specialised scopes use. Accept + * that scope form alongside the seven so the generic generator can read + * its comparison row without an `as never` cast that would silently + * disable type checking on the argument. + */ +export type PreviousContextScope = InsightScope | `metric:${string}-status`; + export interface PreviousInsightContext { /** ISO timestamp the previous analysis was rendered. */ generatedAt: string; @@ -59,7 +69,7 @@ export interface PreviousInsightContext { */ export async function getPreviousInsightContext( userId: string, - scope: InsightScope, + scope: PreviousContextScope, locale: "de" | "en", minAgeHours: number = 12, ): Promise { diff --git a/src/lib/insights/metric-status.ts b/src/lib/insights/metric-status.ts index 88a8d30dc..855d4a18c 100644 --- a/src/lib/insights/metric-status.ts +++ b/src/lib/insights/metric-status.ts @@ -280,8 +280,10 @@ export async function generateMetricStatus(args: { args.userId, // memory.ts keys previous context by the `insights..` // action; the generic scope (`metric:-status`) carries the same - // `-status` suffix so the comparison row reads back correctly. - `${scope}-status` as never, + // `-status` suffix so the comparison row reads back correctly. The + // `getPreviousInsightContext` param is typed to accept this scope form + // (`PreviousContextScope`), so the argument type-checks honestly. + `${scope}-status`, locale, 12, );