mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(onboarding): make AI insights reachable early without a gate
Close the gap between the welcome carousel's AI promise and the payoff: a fresh keyless user used to meet "No AI provider connected" on every AI surface, because the only setup prompt was a skippable card on the final screen. Add an "insights" row to the getting-started checklist, derived from real provider state — any personal key, local model, OAuth sign-in, or the operator's shared key flips it done via /api/user/ai-provider. It persists past onboarding, self-satisfies on connect, and dismisses like the others. Elevate the done-screen AI card into a value-first panel: it leads with a static, clearly-labelled example briefing (no model call, no egress, no consent), then the local-first ladder — local model, bring-your-own-key, subscription sign-in with the training caveat — and the honest line that HealthLog is fully useful without AI. All three exits stay, so the panel gates nothing. On a deployment with a shared provider it says so plainly. Extract the worked example into a shared SampleBriefingCard. Add onboarding.ai.* copy across all six locales and retire the old single-card done-screen keys.
This commit is contained in:
1 parent
89634e20ee
commit
0adba584a9
14 files changed
+546
-55
No files matched your search
@@ -23,6 +23,7 @@ function inputs(overrides: Partial<Parameters<typeof buildChecklist>[0]> = {}) {
|
||||
medicationCount: 0,
|
||||
dataSourceConnected: false,
|
||||
notificationsConfigured: false,
|
||||
insightsConfigured: false,
|
||||
dismissedIds: new Set<ChecklistItemId>(),
|
||||
...overrides,
|
||||
};
|
||||
@@ -43,7 +44,7 @@ describe("isProfileComplete", () => {
|
||||
});
|
||||
|
||||
describe("buildChecklist", () => {
|
||||
it("emits the five canonical items in stable order", () => {
|
||||
it("emits the six canonical items in stable order", () => {
|
||||
const items = buildChecklist(inputs());
|
||||
expect(items.map((i) => i.id)).toEqual([
|
||||
"profile",
|
||||
@@ -51,9 +52,20 @@ describe("buildChecklist", () => {
|
||||
"medication",
|
||||
"dataSource",
|
||||
"notifications",
|
||||
"insights",
|
||||
]);
|
||||
});
|
||||
|
||||
it("flags insights done once any provider can serve the user", () => {
|
||||
const off = buildChecklist(inputs({ insightsConfigured: false }));
|
||||
expect(off.find((i) => i.id === "insights")?.done).toBe(false);
|
||||
// `insightsConfigured` is derived from aiAvailable, which is true for a
|
||||
// personal key, a local model, an OAuth sign-in, OR the operator's
|
||||
// shared key — any one flips the row done.
|
||||
const on = buildChecklist(inputs({ insightsConfigured: true }));
|
||||
expect(on.find((i) => i.id === "insights")?.done).toBe(true);
|
||||
});
|
||||
|
||||
it("marks profile done when all three fields set", () => {
|
||||
const items = buildChecklist(inputs());
|
||||
expect(items.find((i) => i.id === "profile")?.done).toBe(true);
|
||||
@@ -97,6 +109,7 @@ describe("buildChecklist", () => {
|
||||
expect(hrefs.medication).toBe("/medications");
|
||||
expect(hrefs.dataSource).toBe("/settings/integrations");
|
||||
expect(hrefs.notifications).toBe("/settings/notifications");
|
||||
expect(hrefs.insights).toBe("/settings/ai");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,8 +127,12 @@ describe("visibleChecklist + checklistProgress", () => {
|
||||
inputs({
|
||||
measurementCount: 3,
|
||||
medicationCount: 1,
|
||||
// dismiss the only one not done so percent jumps to 100
|
||||
dismissedIds: new Set<ChecklistItemId>(["dataSource", "notifications"]),
|
||||
// dismiss the ones not done so percent jumps to 100
|
||||
dismissedIds: new Set<ChecklistItemId>([
|
||||
"dataSource",
|
||||
"notifications",
|
||||
"insights",
|
||||
]),
|
||||
}),
|
||||
);
|
||||
const progress = checklistProgress(items);
|
||||
@@ -132,6 +149,7 @@ describe("visibleChecklist + checklistProgress", () => {
|
||||
medicationCount: 0,
|
||||
dataSourceConnected: false,
|
||||
notificationsConfigured: false,
|
||||
insightsConfigured: false,
|
||||
dismissedIds: new Set(),
|
||||
});
|
||||
const progress = checklistProgress(items);
|
||||
@@ -196,6 +214,7 @@ describe("shouldShowChecklist", () => {
|
||||
medicationCount: 1,
|
||||
dataSourceConnected: true,
|
||||
notificationsConfigured: true,
|
||||
insightsConfigured: true,
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
|
||||
@@ -12,6 +12,7 @@ export const CHECKLIST_ITEM_IDS = [
|
||||
"medication",
|
||||
"dataSource",
|
||||
"notifications",
|
||||
"insights",
|
||||
] as const;
|
||||
|
||||
export type ChecklistItemId = (typeof CHECKLIST_ITEM_IDS)[number];
|
||||
@@ -52,14 +53,24 @@ export interface ChecklistInputs {
|
||||
* (Telegram, ntfy, or Web Push).
|
||||
*/
|
||||
notificationsConfigured: boolean;
|
||||
/**
|
||||
* True iff any AI provider can serve this user — a personal key,
|
||||
* a local model, an OAuth sign-in, OR the operator's shared key.
|
||||
* Derived from `/api/user/ai-provider`'s `aiAvailable`, so the row
|
||||
* self-satisfies the moment insights become reachable (including on a
|
||||
* deployment that ships a shared operator key). Presence-only — it
|
||||
* never decrypts a credential or probes liveness.
|
||||
*/
|
||||
insightsConfigured: boolean;
|
||||
/** Dismissed item ids (per-item localStorage state). */
|
||||
dismissedIds: ReadonlySet<ChecklistItemId>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the ordered checklist for the dashboard hero. Stable order:
|
||||
* profile → measurement → medication → dataSource → notifications. Each
|
||||
* item carries the deep-link the row's CTA should navigate to.
|
||||
* profile → measurement → medication → dataSource → notifications →
|
||||
* insights. Each item carries the deep-link the row's CTA should
|
||||
* navigate to.
|
||||
*/
|
||||
export function buildChecklist(inputs: ChecklistInputs): ChecklistItem[] {
|
||||
const profileDone = isProfileComplete(inputs.profile);
|
||||
@@ -94,6 +105,12 @@ export function buildChecklist(inputs: ChecklistInputs): ChecklistItem[] {
|
||||
href: "/settings/notifications",
|
||||
dismissed: inputs.dismissedIds.has("notifications"),
|
||||
},
|
||||
{
|
||||
id: "insights",
|
||||
done: inputs.insightsConfigured,
|
||||
href: "/settings/ai",
|
||||
dismissed: inputs.dismissedIds.has("insights"),
|
||||
},
|
||||
];
|
||||
return items;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user