From 1e00b01bc30357890bdfe7850598fd2ae965a1a4 Mon Sep 17 00:00:00 2001 From: Antigravity Date: Fri, 29 May 2026 13:17:40 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20quota=20auto=5Ftag=20consomm=C3=A9=201x?= =?UTF-8?q?=20par=20application=20r=C3=A9elle,=20pas=20=C3=A0=20chaque=20f?= =?UTF-8?q?rappe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Route /api/ai/tags: supprime l'incrément sur les suggestions (UI only) → chaque keystroke (debounce 1.5s) ne consommait plus de quota - notes.ts: incrément unique quand des labels IA sont réellement appliqués en background (syncNoteLabels) - PRO limit: 200 → 500 auto_tag/mois (200 était trop bas) Avant: écrire une note 5min = ~20 incréments pour UNE note Après: 1 incrément uniquement si des labels sont effectivement appliqués Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- memento-note/app/actions/notes.ts | 3 +++ memento-note/app/api/ai/tags/route.ts | 3 ++- memento-note/lib/entitlements.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/memento-note/app/actions/notes.ts b/memento-note/app/actions/notes.ts index b65cde0..1af17da 100644 --- a/memento-note/app/actions/notes.ts +++ b/memento-note/app/actions/notes.ts @@ -11,6 +11,7 @@ import { embeddingService } from '@/lib/ai/services/embedding.service' import { syncNoteLinksForNote } from '@/lib/notes/sync-note-links' import { getSystemConfig, getConfigNumber, getConfigBoolean, SEARCH_DEFAULTS } from '@/lib/config' import { contextualAutoTagService } from '@/lib/ai/services/contextual-auto-tag.service' +import { incrementUsageAsync } from '@/lib/entitlements' import { semanticSearchService } from '@/lib/ai/services/semantic-search.service' import { getAISettings } from '@/app/actions/ai-settings' import { @@ -508,6 +509,8 @@ export async function createNote(data: { } const merged = [...new Set([...existingNames, ...appliedLabels])] await syncNoteLabels(noteId, merged, notebookId ?? null, userId) + // Incrémenter le quota une seule fois par sauvegarde où des labels IA sont appliqués + incrementUsageAsync(userId, 'auto_tag') if (!data.skipRevalidation) { revalidatePath('/home') } diff --git a/memento-note/app/api/ai/tags/route.ts b/memento-note/app/api/ai/tags/route.ts index 6e40ef8..70eeeb2 100644 --- a/memento-note/app/api/ai/tags/route.ts +++ b/memento-note/app/api/ai/tags/route.ts @@ -83,7 +83,8 @@ export async function POST(req: NextRequest) { session.user.id, (provider) => provider.generateTags(content, language), ); - if (!usedByok) incrementUsageAsync(session.user.id, 'auto_tag'); + // Ne pas incrémenter ici — ce sont des suggestions UI (déclenchées à chaque keystroke) + // Le quota est compté uniquement lors de l'application réelle des labels (voir notes.ts) return NextResponse.json({ tags }); } catch (err) { console.error('[/api/ai/tags] legacy tagging failed:', err) diff --git a/memento-note/lib/entitlements.ts b/memento-note/lib/entitlements.ts index 7bc896b..352d80f 100644 --- a/memento-note/lib/entitlements.ts +++ b/memento-note/lib/entitlements.ts @@ -84,7 +84,7 @@ const TIER_LIMITS: Record }, PRO: { semantic_search: 100, - auto_tag: 200, + auto_tag: 500, auto_title: 200, reformulate: 50, chat: 50,