mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
feat(documents): add per-user automatic AI reading opt-in
Add the documentsAutoAiRead per-user Boolean (migration 0231, default false) that authorises ambient AI reading of uploaded vault documents. OFF by default keeps the vault local-first for every self-hoster. - schema column + migration 0231_documents_auto_ai_read - documentAutoReadEnabled(userId) read helper - GET/PATCH /api/auth/me/documents-auto-ai-read toggle route; the ON write mints an ai_full consent receipt for the audit trail - the document consent gate short-circuits an external pick when the toggle is ON; a local pick stays ungated and OFF still requires a receipt for any external egress
This commit is contained in:
1 parent
168a8ea5c5
commit
813dc2547b
6 files changed
+253
-1
No files matched your search
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Per-user document-vault AI settings.
|
||||
*
|
||||
* `documentAutoReadEnabled(userId)` reads the `documentsAutoAiRead` opt-in — the
|
||||
* single switch that authorises ambient (no-per-document-tap) AI reading of
|
||||
* uploaded documents. OFF by default: the vault stays local-first and every
|
||||
* external egress needs an explicit per-document action + consent receipt.
|
||||
*
|
||||
* Two gates read this flag:
|
||||
* - the document consent gate (`assertDocumentEgressConsent`) short-circuits an
|
||||
* external pick when it is ON (the toggle IS the standing consent);
|
||||
* - the auto-index-on-upload job stays strictly local when it is OFF and uses
|
||||
* the document-order external pick when it is ON.
|
||||
*/
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
/**
|
||||
* True when the user has opted into automatic AI reading of uploaded documents.
|
||||
* A missing row (deleted account raced against a job) resolves to `false` —
|
||||
* fail-closed to the local-first posture, never to external egress.
|
||||
*/
|
||||
export async function documentAutoReadEnabled(userId: string): Promise<boolean> {
|
||||
const row = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { documentsAutoAiRead: true },
|
||||
});
|
||||
return row?.documentsAutoAiRead ?? false;
|
||||
}
|
||||
Reference in new issue
Block a user