-
Notifications
You must be signed in to change notification settings - Fork 1
Bug #90: AI buttons visible when consent off #17
Description
Bug #90: AI buttons visible when consent is off
Severity: Medium
Repro
- Open Settings → AI → toggle "Allow AI data sharing" OFF (revoke consent)
- Open any book in the reader
- Observe the toolbar
Expected
AI buttons (sparkles icon) should be hidden or show a consent prompt when tapped.
Actual
AI buttons remain visible in the toolbar. Tapping them opens the AI panel, which then fails at request time with a consent error.
Root Cause
AIReaderAvailability.isAvailable() only checks two gates:
- Feature flag:
featureFlags.aiAssistant - API key presence:
KeychainService.readString(forAccount: AIService.apiKeyAccount)
It does not check AIConsentManager.hasConsent. Consent is only checked at request time inside AIService.sendRequest()/streamRequest(), which throws AIError.consentRequired.
This means the button appears even when the user has explicitly revoked consent. The user sees the panel, tries an action, and only then gets the consent prompt — a confusing UX.
Proper Fix
Add consent check to AIReaderAvailability.isAvailable():
static func isAvailable(...) -> Bool {
featureFlags.aiAssistant
&& hasAPIKey(keychainService: keychainService)
&& AIConsentManager().hasConsent // ← add this
}Or: keep buttons visible but show consent prompt immediately on panel open (before any tab action).
Files
vreader/Services/AI/AIReaderAvailability.swift— availability check (missing consent gate)vreader/Services/AI/AIConsentManager.swift— consent state in UserDefaultsvreader/Views/Reader/ReaderAICoordinator.swift—isAIAvailablecomputed propertyvreader/Views/Reader/ReaderChromeBar.swift— conditional button rendering
Refs #6