mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 22:26:13 +00:00
fix(ai): keep setup invitations away from people who opted out
A person who switched both the Coach and AI analysis off under Settings, Modules still got invited to set AI up: the Insights hint, its copy in Settings, AI, the checklist row and the onboarding panel all keyed on `provider.canConfigure`, which only knows the record kind and the operator switch. The flag itself stays as it is, because the AI usage card and the consent request read it too and still serve document reading, lab photos and medication extraction. The three invitation readers now also check the module map through `hasOptedOutOfAi`.
This commit is contained in:
1 parent
aae029d94e
commit
de8eadbf2f
8 files changed
+108
-19
No files matched your search
@@ -189,6 +189,22 @@ export const AI_OPT_OUT_MODULES: ReadonlySet<ModuleKey> = new Set<ModuleKey>([
|
||||
"insights",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Whether the record has every opt-out module switched off, read from the
|
||||
* module map on `/api/auth/me` (a key the map does not carry counts as on).
|
||||
* An invitation to set AI up has nothing left to offer then. It does not gate
|
||||
* the AI settings themselves: document reading, lab photos and medication
|
||||
* extraction belong to other modules and still need a provider and consent.
|
||||
*/
|
||||
export function hasOptedOutOfAi(
|
||||
modules: Partial<Record<ModuleKey, boolean>> | null | undefined,
|
||||
): boolean {
|
||||
for (const key of AI_OPT_OUT_MODULES) {
|
||||
if (modules?.[key] !== false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const COACH_KINDS: readonly AiConsentKind[] = ["ai_coach", "ai_full"];
|
||||
const INSIGHTS_KINDS: readonly AiConsentKind[] = [
|
||||
"ai_insights_only",
|
||||
|
||||
@@ -83,11 +83,12 @@ export interface ChecklistInputs {
|
||||
*/
|
||||
insightsConfigured: boolean;
|
||||
/**
|
||||
* Whether AI can be set up from here at all (`ai.provider.canConfigure`):
|
||||
* false while the operator has AI switched off and inside a record
|
||||
* somebody else owns. The AI row exists only when true. HealthLog is
|
||||
* complete without AI, so the list never carries a to-do nobody on this
|
||||
* screen can finish.
|
||||
* Whether AI can be set up from here at all (`ai.provider.canConfigure`)
|
||||
* and is still wanted: false while the operator has AI switched off, inside
|
||||
* a record somebody else owns, and once the person switched the Coach and
|
||||
* AI analysis off. The AI row exists only when true. HealthLog is complete
|
||||
* without AI, so the list never carries a to-do nobody on this screen can
|
||||
* finish or that was declined.
|
||||
*/
|
||||
aiConfigurable: boolean;
|
||||
/** Dismissed item ids (per-item localStorage state). */
|
||||
|
||||
Reference in new issue
Block a user