feat(4-5/4-6): audit logging + zero-data-retention headers
Some checks failed
CI / Lint, Unit Tests & Build (push) Successful in 5m39s
CI / Deploy production (on server) (push) Failing after 18s

Audit Logging (story 4-6):
- Nouveau modèle AuditLog (userId, action, resource, metadata, ip, createdAt)
- Migration 20260529143000_add_audit_log appliquée
- lib/audit-log.ts : logAuditEvent (fire-and-forget) + logAuditEventAsync + getClientIp
- auth.ts : LOG LOGIN / LOGOUT / USER_CREATED sur chaque event NextAuth
- /api/chat : log AI_REQUEST avec tokens + byok flag dans onFinish
- /api/agents/run-for-note : log AI_REQUEST avec featureKey + noteId

Zero-data-retention (story 4-5):
- OpenAI provider : header OpenAI-No-Training: 1
- Anthropic provider : header Anthropic-No-Train: 1
- DeepSeek provider : header X-No-Train: 1

sprint-status: 4-5 et 4-6 → done

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Antigravity
2026-05-29 14:36:06 +00:00
parent cd54a983c3
commit 5703d5bd49
10 changed files with 141 additions and 3 deletions

View File

@@ -12,7 +12,12 @@ export class AnthropicProvider implements AIProvider {
*/
constructor(apiKey: string, modelName: string = 'claude-sonnet-4-20250514', baseURL?: string) {
const trimmedBase = baseURL?.trim().replace(/\/+$/, '');
const anthropicClient = createAnthropic(trimmedBase ? { apiKey, baseURL: trimmedBase } : { apiKey });
const zdrHeaders = { 'Anthropic-No-Train': '1' };
const anthropicClient = createAnthropic(
trimmedBase
? { apiKey, baseURL: trimmedBase, headers: zdrHeaders }
: { apiKey, headers: zdrHeaders }
);
this.model = anthropicClient.chat(modelName);
}

View File

@@ -13,6 +13,7 @@ export class DeepSeekProvider implements AIProvider {
const deepseek = createOpenAI({
baseURL: 'https://api.deepseek.com/v1',
apiKey: apiKey,
headers: { 'X-No-Train': '1' },
fetch: async (url, options) => {
if (options?.body) {
try {

View File

@@ -12,6 +12,10 @@ export class OpenAIProvider implements AIProvider {
// Use .chat() to force /chat/completions endpoint (avoids Responses API)
const openaiClient = createOpenAI({
apiKey: apiKey,
headers: {
// Zero-data-retention: signal OpenAI not to use data for training
'OpenAI-No-Training': '1',
},
});
this.model = openaiClient.chat(modelName);