mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(ai): replace the Correlations switch with Reading documents
The operator switches become master, Coach, Daily Briefing, Status notes and Reading documents. Correlations goes: it gated statistics, not anything a model writes. Reading documents covers the document vault, lab scans and medication extraction. The Coach module's operator availability now follows the Coach switch, so there is one place to turn the Coach off server-wide. The migration folds a stored Coach availability of false into the switch, and gives everyone who hid the Coach the AI analysis opt-out, since hiding the Coach no longer stops nightly briefing and status notes. A switch read that fails now fails closed. The insights module is described as AI analysis in every locale, and the switch guard now keeps both retired switches out and freezes the callers of the old operator-only gate.
This commit is contained in:
1 parent
c8a01ac3ed
commit
a7888a9011
46 files changed
+758
-422
No files matched your search
@@ -12,10 +12,12 @@ import { SettingsToggle } from "./_shared";
|
||||
import { apiGet, apiPut } from "@/lib/api/api-fetch";
|
||||
|
||||
/**
|
||||
* v1.4.31 — operator-side panel for the five assistant feature
|
||||
* flags. The master toggle gates the whole assistant; four
|
||||
* sub-toggles carve specific surfaces (Coach, Daily Briefing,
|
||||
* per-metric status cards, correlation narration).
|
||||
* Operator-side panel for the five assistant switches. The master stops
|
||||
* every AI feature; four sub-switches each stop one cost or egress profile:
|
||||
* the Coach, the daily briefing, status notes (per-reading notes, workout
|
||||
* notes, reaction lines) and reading documents (the vault, lab scans,
|
||||
* medication extraction). A switch stops AI work and hides AI text; data,
|
||||
* charts and scores keep loading either way.
|
||||
*
|
||||
* UX:
|
||||
* - Master toggle at the top. When off, the sub-toggles are
|
||||
@@ -33,14 +35,14 @@ interface AssistantFlagsResponse {
|
||||
assistantCoachEnabled: boolean;
|
||||
assistantBriefingEnabled: boolean;
|
||||
assistantInsightStatusEnabled: boolean;
|
||||
assistantCorrelationsEnabled: boolean;
|
||||
assistantDocumentAiEnabled: boolean;
|
||||
};
|
||||
resolved: {
|
||||
enabled: boolean;
|
||||
coach: boolean;
|
||||
briefing: boolean;
|
||||
insightStatus: boolean;
|
||||
correlations: boolean;
|
||||
documentAi: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,8 +71,10 @@ function useUpdateAssistantFlags() {
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
client.setQueryData(queryKeys.adminAssistantFlags(), data);
|
||||
// Bust the runtime `/api/feature-flags` cache so the operator
|
||||
// sees the toggled surface react within the same session.
|
||||
// Every record's resolved AI capabilities ride the account payload,
|
||||
// and the deprecated switch projection is still read on the web;
|
||||
// bust both so the operator sees the change within the session.
|
||||
client.invalidateQueries({ queryKey: queryKeys.authMe() });
|
||||
client.invalidateQueries({ queryKey: queryKeys.featureFlags() });
|
||||
toast.success(t("common.saved"));
|
||||
},
|
||||
@@ -143,11 +147,11 @@ export function AssistantSection() {
|
||||
disabled={disabledSubs}
|
||||
/>
|
||||
<SettingsToggle
|
||||
label={t("admin.assistant.correlations.title")}
|
||||
description={t("admin.assistant.correlations.description")}
|
||||
checked={raw?.assistantCorrelationsEnabled ?? true}
|
||||
label={t("admin.assistant.documentAi.title")}
|
||||
description={t("admin.assistant.documentAi.description")}
|
||||
checked={raw?.assistantDocumentAiEnabled ?? true}
|
||||
onCheckedChange={(checked) =>
|
||||
mutation.mutate({ assistantCorrelationsEnabled: checked })
|
||||
mutation.mutate({ assistantDocumentAiEnabled: checked })
|
||||
}
|
||||
disabled={disabledSubs}
|
||||
/>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { ToggleLeft } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
@@ -11,6 +12,7 @@ import { queryKeys } from "@/lib/query-keys";
|
||||
import {
|
||||
MODULE_KEYS,
|
||||
MODULE_REGISTRY,
|
||||
SWITCH_OWNED_MODULE_KEYS,
|
||||
isCodeDisabledModule,
|
||||
} from "@/lib/modules/registry";
|
||||
import type { ModuleKey } from "@/lib/modules/registry";
|
||||
@@ -106,6 +108,32 @@ export function ModuleAvailabilitySection() {
|
||||
// Default-available until the read resolves; an explicit `false`
|
||||
// from the operator layer is the only thing that turns it off.
|
||||
const available = availability?.[key] ?? true;
|
||||
// The Coach has one operator switch, on the assistant panel. The
|
||||
// row stays so the operator sees its state here, read-only, with
|
||||
// the way to the switch that decides it.
|
||||
if (SWITCH_OWNED_MODULE_KEYS.includes(key)) {
|
||||
return (
|
||||
<div
|
||||
key={key}
|
||||
className="space-y-1"
|
||||
data-slot="module-availability-switch-owned"
|
||||
>
|
||||
<SettingsToggle
|
||||
label={t(def.labelKey)}
|
||||
description={t("admin.modules.coachFollowsSwitch")}
|
||||
checked={available}
|
||||
onCheckedChange={() => {}}
|
||||
disabled
|
||||
/>
|
||||
<Link
|
||||
href="/admin/coach"
|
||||
className="text-primary text-xs underline-offset-4 hover:underline"
|
||||
>
|
||||
{t("admin.assistant.title")}
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<SettingsToggle
|
||||
key={key}
|
||||
|
||||
Reference in new issue
Block a user