mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Largest feature delta in the v1.4.x line. Insights expands into seven dedicated metric sub-pages; GLP-1 medication tracking lands end-to-end (drug-level chart with Research Mode acknowledgment, EMA titration ladder, cadence + compliance, side-effect taxonomy, pen/vial inventory); cross-source priority becomes a two-axis resolver; per-user timezone threads through ten analytics surfaces; Withings activity + sleep v2 sync; onboarding rebuilt as a nested-route wizard; Personal Records ship end-to-end; Health Score provenance accordion; Coach runs native first-party prompts across six locales with a 1800-assertion refusal-probe matrix; OpenAPI drift gate hard-fails; multi-arch GHCR image. Migrations 0043 through 0060 are additive and forward-only. PROMPT_VERSION 4.24.0 → 4.25.0 with GROUND RULE 9 (refuses dose recommendations) and GROUND RULE 15 (refuses drug-level estimates with MDR + MDCG 2021-24 cites). See CHANGELOG.md for the full per-section delta.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { AsyncLocalStorage } from "node:async_hooks";
|
|
import type { WideEvent } from "./types";
|
|
import { WideEventBuilder } from "./event-builder";
|
|
import { registerSourcePriorityParseObserver } from "@/lib/validations/source-priority";
|
|
|
|
/** AsyncLocalStorage fuer den aktuellen Request-Kontext */
|
|
export const eventStorage = new AsyncLocalStorage<WideEventBuilder>();
|
|
|
|
/** Aktuellen EventBuilder abrufen (null falls ausserhalb eines Kontexts) */
|
|
export function getEvent(): WideEventBuilder | null {
|
|
return eventStorage.getStore() ?? null;
|
|
}
|
|
|
|
/**
|
|
* Convenience: Felder im aktuellen Event annotieren.
|
|
* Safe to call anywhere — no-op wenn kein Kontext aktiv.
|
|
*/
|
|
export function annotate(fields: {
|
|
action?: WideEvent["action"];
|
|
meta?: Record<string, unknown>;
|
|
}): void {
|
|
const evt = getEvent();
|
|
if (!evt) return;
|
|
if (fields.action) evt.setAction(fields.action);
|
|
if (fields.meta) {
|
|
for (const [key, value] of Object.entries(fields.meta)) {
|
|
evt.addMeta(key, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
// v1.4.25 Fix-G — wire the schema-parser breadcrumb into the
|
|
// AsyncLocalStorage-backed `annotate()` only on the server. The
|
|
// validations module stays bundle-safe for client imports; this side
|
|
// effect runs the first time any server module imports the logging
|
|
// context.
|
|
registerSourcePriorityParseObserver((fields) => {
|
|
annotate(fields);
|
|
});
|