fix(quotas): unifier le décompte IA (BYOK, rollback) et combler les fuites
Centralise la réserve via ai-quota, corrige admin unavailable (-1), brancher les routes sans quota et le host-pays brainstorm, avec usage-meter élargi, noms de clusters, MCP et ajustements dashboard/insights. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { VALID_FEATURES, getCurrentPeriodKey } from '@/lib/quota-utils'
|
||||
import {
|
||||
getAllEntitlementsForAdmin,
|
||||
invalidateEntitlementCache,
|
||||
ENTITLEMENT_UNAVAILABLE,
|
||||
type SubscriptionTier as TierType,
|
||||
} from '@/lib/plan-entitlements'
|
||||
import { logAuditEventAsync } from '@/lib/audit-log'
|
||||
@@ -73,9 +74,20 @@ export async function updatePlanEntitlement(
|
||||
}
|
||||
|
||||
if (mode === 'unavailable') {
|
||||
await prisma.planEntitlement.deleteMany({
|
||||
where: { tier: tier as SubscriptionTier, feature },
|
||||
})
|
||||
await prisma.planEntitlement.upsert({
|
||||
where: {
|
||||
tier_feature: {
|
||||
tier: tier as SubscriptionTier,
|
||||
feature,
|
||||
},
|
||||
},
|
||||
update: { limitValue: ENTITLEMENT_UNAVAILABLE },
|
||||
create: {
|
||||
tier: tier as SubscriptionTier,
|
||||
feature,
|
||||
limitValue: ENTITLEMENT_UNAVAILABLE,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await prisma.planEntitlement.upsert({
|
||||
where: {
|
||||
@@ -158,7 +170,7 @@ export async function updateBillingConfig(data: Record<string, string>) {
|
||||
|
||||
async function getUsageOverviewInternal() {
|
||||
const period = getCurrentPeriodKey()
|
||||
const periodStart = new Date(`${period}-01`)
|
||||
const periodStart = new Date(`${period}-01T00:00:00.000Z`)
|
||||
|
||||
const aggregated = await prisma.usageLog.groupBy({
|
||||
by: ['feature'],
|
||||
|
||||
Reference in New Issue
Block a user