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:
Marc-André Bombeck committed 2026-07-09 10:32:59 +02:00
1 parent 168a8ea5c5
commit 813dc2547b
6 files changed
+253 -1

No files matched your search

@@ -0,0 +1,17 @@
-- Automatic AI reading of uploaded vault documents (per-user opt-in).
--
-- One additive, defaulted column on `users`. OFF by default: the document vault
-- stays local-first — a freshly uploaded document is only read by an external AI
-- provider when the user explicitly taps a per-document action (which still
-- requires an active consent receipt). When `true`, the auto-index-on-upload job
-- may read a new document through the user's configured external provider with
-- no per-document tap; flipping the toggle on is itself the standing consent
-- (the write that sets it also mints an `ai_full` consent receipt for the audit
-- trail).
--
-- The default `false` backfills every existing row onto the current behaviour
-- (local-first, per-document-explicit, consent-required), so this is a no-op for
-- anyone who never opts in.
ALTER TABLE "users"
ADD COLUMN "documents_auto_ai_read" BOOLEAN NOT NULL DEFAULT false;
+12
View File
@@ -302,6 +302,18 @@ model User {
aiOcrBaseUrl String? @map("ai_ocr_base_url") // LOCAL OCR provider only
aiOcrKeyEncrypted String? @map("ai_ocr_key_encrypted")
// Automatic AI reading of uploaded vault documents. OFF by default: the vault
// stays local-first — a newly stored document is only read externally when the
// user explicitly taps a per-document AI action (which still needs an active
// consent receipt). When `true`, the auto-index job may read a freshly
// uploaded document through the user's configured external provider with no
// per-document tap: the toggle IS the standing consent (the write that flips
// it on also mints an `ai_full` receipt for the audit trail). Mirrors
// `labsLocalOcrEnabled`; all AI provider config is per-user, so the operator
// flips it for their own account. Default `false` is the entire privacy
// contract for every other self-hoster.
documentsAutoAiRead Boolean @default(false) @map("documents_auto_ai_read")
// Onboarding
onboardingCompletedAt DateTime? @map("onboarding_completed_at")
// v1.4.25 W14b — last persisted onboarding wizard step.