fix: replace raw ai_consent_required code with translatable message and consent prompt
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 7m20s
CI / Deploy production (on server) (push) Successful in 24s

- Centralize AI consent 403 responses in server-consent helpers
- Return human-readable message + code + i18n errorKey from all AI APIs
- Update dashboard and AI clients to detect code/errorKey and translate
- Add consent.ai.requiredToast i18n keys (fr/en)
This commit is contained in:
Antigravity
2026-07-18 17:32:00 +00:00
parent 86505659cf
commit 324bf40658
41 changed files with 404 additions and 97 deletions

View File

@@ -6,7 +6,7 @@ import { getChatProvider } from '@/lib/ai/factory'
import { semanticSearchService } from '@/lib/ai/services/semantic-search.service'
import { prisma } from '@/lib/prisma'
import { auth } from '@/auth'
import { hasUserAiConsent } from '@/lib/consent/server-consent'
import { hasUserAiConsent, aiConsentForbiddenResponse } from '@/lib/consent/server-consent'
import { loadTranslations, getTranslationValue, SupportedLanguage } from '@/lib/i18n'
import { toolRegistry } from '@/lib/ai/tools'
import { reserveAiUsageOrThrow, handleQuotaHttpError } from '@/lib/ai-quota'
@@ -65,10 +65,7 @@ export async function POST(req: Request) {
// GDPR AI Consent check
if (!(await hasUserAiConsent())) {
return new Response(JSON.stringify({ error: 'ai_consent_required' }), {
status: 403,
headers: { 'Content-Type': 'application/json' },
})
return aiConsentForbiddenResponse()
}
// 1.5 Quota check (per-provider BYOK bypass — only when BYOK will be used for resolved provider)