wip: zen black

This commit is contained in:
Frank
2026-01-22 12:40:42 -05:00
parent bb582416f2
commit a890d51bbc
16 changed files with 130 additions and 42 deletions

View File

@@ -417,6 +417,7 @@ export async function handler(
timeMonthlyUsageUpdated: BillingTable.timeMonthlyUsageUpdated,
reloadTrigger: BillingTable.reloadTrigger,
timeReloadLockedTill: BillingTable.timeReloadLockedTill,
subscription: BillingTable.subscription,
},
user: {
id: UserTable.id,
@@ -488,10 +489,9 @@ export async function handler(
if (modelInfo.allowAnonymous) return
// Validate subscription billing
if (authInfo.subscription) {
const black = BlackData.get()
if (authInfo.billing.subscription && authInfo.subscription) {
const sub = authInfo.subscription
const now = new Date()
const plan = authInfo.billing.subscription.plan
const formatRetryTime = (seconds: number) => {
const days = Math.floor(seconds / 86400)
@@ -505,6 +505,7 @@ export async function handler(
// Check weekly limit
if (sub.fixedUsage && sub.timeFixedUpdated) {
const result = Black.analyzeWeeklyUsage({
plan,
usage: sub.fixedUsage,
timeUpdated: sub.timeFixedUpdated,
})
@@ -518,6 +519,7 @@ export async function handler(
// Check rolling limit
if (sub.rollingUsage && sub.timeRollingUpdated) {
const result = Black.analyzeRollingUsage({
plan,
usage: sub.rollingUsage,
timeUpdated: sub.timeRollingUpdated,
})
@@ -666,7 +668,8 @@ export async function handler(
.where(and(eq(KeyTable.workspaceID, authInfo.workspaceID), eq(KeyTable.id, authInfo.apiKeyId))),
...(authInfo.subscription
? (() => {
const black = BlackData.get()
const plan = authInfo.billing.subscription!.plan
const black = BlackData.get({ plan })
const week = getWeekBounds(new Date())
const rollingWindowSeconds = black.rollingWindow * 3600
return [