mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(coach): say how an answer was worked out
The evidence disclosure under a Coach answer now carries one muted
line: which sources and windows the turn read, how many readings, and
how they were aggregated ("Blood pressure, last 90 days: 142 readings,
weekly averages · Sleep, last 30 days: no readings in this window").
The server builds it from the recorded steps and tables in the request
locale; it holds catalog strings and counts only, never a reading, and
a source that turned up nothing says so.
The tool-mode prompt gains a recheck rule: when the person questions a
figure, name the source and window, read it again (or reuse the stored
table), and correct the answer if the two differ.
This commit is contained in:
1 parent
78fc22d0f8
commit
01aba93878
9 files changed
+708
-44
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { CoachMethodLine } from "../method-line";
|
||||
|
||||
function render(node: React.ReactNode, locale: "en" | "de" = "en") {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale={locale}>{node}</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("<CoachMethodLine>", () => {
|
||||
it("renders nothing without a method", () => {
|
||||
expect(render(<CoachMethodLine method={null} />)).toBe("");
|
||||
expect(render(<CoachMethodLine method={{ entries: [], text: "" }} />)).toBe(
|
||||
"",
|
||||
);
|
||||
});
|
||||
|
||||
it("renders the server text as a muted meta line", () => {
|
||||
const html = render(
|
||||
<CoachMethodLine
|
||||
method={{
|
||||
entries: [{ domain: "bp", window: "last90days", count: 142 }],
|
||||
text: "Blood pressure, last 90 days: 142 readings",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('data-slot="coach-method-line"');
|
||||
expect(html).toContain("text-muted-foreground text-xs");
|
||||
expect(html).toContain("How this was worked out:");
|
||||
expect(html).toContain("Blood pressure, last 90 days: 142 readings");
|
||||
});
|
||||
|
||||
it("labels the line in the reader's locale", () => {
|
||||
const html = render(
|
||||
<CoachMethodLine method={{ entries: [], text: "Blutdruck" }} />,
|
||||
"de",
|
||||
);
|
||||
expect(html).toContain("Wie das ermittelt wurde:");
|
||||
});
|
||||
});
|
||||
@@ -3,16 +3,28 @@
|
||||
/**
|
||||
* v1.39.4 — how an answer was worked out, as one muted line inside the
|
||||
* evidence disclosure: sources, windows, counts and aggregation, rendered
|
||||
* on the server. Never a health value.
|
||||
*
|
||||
* Not built yet: renders nothing.
|
||||
* on the server in the request locale. Never a health value, so it sits in
|
||||
* the meta tier beside the key values it explains rather than repeating
|
||||
* them.
|
||||
*/
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { COACH_METHOD_KEYS } from "@/lib/ai/coach/dialog-keys";
|
||||
import type { CoachMethod } from "@/lib/ai/coach/types";
|
||||
|
||||
export interface CoachMethodLineProps {
|
||||
method: CoachMethod | null;
|
||||
}
|
||||
|
||||
export function CoachMethodLine(_props: CoachMethodLineProps) {
|
||||
return null;
|
||||
export function CoachMethodLine({ method }: CoachMethodLineProps) {
|
||||
const { t } = useTranslations();
|
||||
if (!method || !method.text) return null;
|
||||
return (
|
||||
<p
|
||||
data-slot="coach-method-line"
|
||||
className="text-muted-foreground text-xs leading-relaxed"
|
||||
>
|
||||
<span className="font-medium">{t(COACH_METHOD_KEYS.label)}:</span>{" "}
|
||||
{method.text}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user