mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +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
@@ -43,11 +43,12 @@ import {
|
||||
import { auditLog } from "@/lib/auth/audit";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import { getAssistantFlags } from "@/lib/feature-flags";
|
||||
import {
|
||||
mergeAvailabilityPatch,
|
||||
resolveOperatorAvailability,
|
||||
} from "@/lib/modules/operator-availability";
|
||||
import { MODULE_KEYS } from "@/lib/modules/registry";
|
||||
import { MODULE_KEYS, SWITCH_OWNED_MODULE_KEYS } from "@/lib/modules/registry";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -55,11 +56,17 @@ export const dynamic = "force-dynamic";
|
||||
* Strict per-module boolean patch. Building the shape from `MODULE_KEYS`
|
||||
* keeps the schema exhaustive and rejects any non-module key (including
|
||||
* the four core domains) at the validation boundary.
|
||||
*
|
||||
* The Coach is left out and therefore refused: its operator layer is the
|
||||
* Coach switch on the assistant panel, and a second place to turn it off
|
||||
* would be a second answer to one question.
|
||||
*/
|
||||
const moduleAvailabilitySchema = z
|
||||
.object(
|
||||
Object.fromEntries(
|
||||
MODULE_KEYS.map((key) => [key, z.boolean().optional()]),
|
||||
MODULE_KEYS.filter((key) => !SWITCH_OWNED_MODULE_KEYS.includes(key)).map(
|
||||
(key) => [key, z.boolean().optional()],
|
||||
),
|
||||
) as Record<(typeof MODULE_KEYS)[number], z.ZodOptional<z.ZodBoolean>>,
|
||||
)
|
||||
.strict();
|
||||
@@ -68,13 +75,19 @@ export const GET = apiHandler(async () => {
|
||||
await requireAdmin();
|
||||
annotate({ action: { name: "admin.settings.module-availability.get" } });
|
||||
|
||||
const settings = await prisma.appSettings.findUnique({
|
||||
where: { id: "singleton" },
|
||||
select: { moduleAvailabilityJson: true },
|
||||
});
|
||||
const [settings, switches] = await Promise.all([
|
||||
prisma.appSettings.findUnique({
|
||||
where: { id: "singleton" },
|
||||
select: { moduleAvailabilityJson: true },
|
||||
}),
|
||||
getAssistantFlags(),
|
||||
]);
|
||||
|
||||
return apiSuccess({
|
||||
availability: resolveOperatorAvailability(settings?.moduleAvailabilityJson),
|
||||
availability: resolveOperatorAvailability(
|
||||
settings?.moduleAvailabilityJson,
|
||||
switches.coach,
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,6 +141,9 @@ export const PATCH = apiHandler(async (request: NextRequest) => {
|
||||
});
|
||||
|
||||
return apiSuccess({
|
||||
availability: resolveOperatorAvailability(settings.moduleAvailabilityJson),
|
||||
availability: resolveOperatorAvailability(
|
||||
settings.moduleAvailabilityJson,
|
||||
(await getAssistantFlags()).coach,
|
||||
),
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user