From 0b8050d4535b51c53a8f4006fb1b4b7acd84286c Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 17 May 2026 01:59:17 -0400 Subject: [PATCH] sync --- packages/console/app/src/routes/zen/util/ipRateLimiter.ts | 7 +++++-- packages/console/core/script/promote-limits.ts | 2 +- packages/console/core/script/update-limits.ts | 6 ++++-- packages/console/core/src/subscription.ts | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/console/app/src/routes/zen/util/ipRateLimiter.ts b/packages/console/app/src/routes/zen/util/ipRateLimiter.ts index d22ab4ae2f..814a3c0d67 100644 --- a/packages/console/app/src/routes/zen/util/ipRateLimiter.ts +++ b/packages/console/app/src/routes/zen/util/ipRateLimiter.ts @@ -10,8 +10,11 @@ export function createRateLimiter(modelId: string, rateLimit: number | undefined const dict = i18n(localeFromRequest(request)) const limits = Subscription.getFreeLimits() - const dailyLimit = rateLimit ?? limits.dailyRequests - const isDefaultModel = !rateLimit + const headersExist = Object.entries(limits.checkHeaders).every( + ([name, value]) => request.headers.get(name)?.includes(value) ?? false, + ) + const dailyLimit = !headersExist ? limits.dailyRequestsFallback : (rateLimit ?? limits.dailyRequests) + const isDefaultModel = headersExist && !rateLimit const ip = !rawIp.length ? "unknown" : rawIp const now = Date.now() diff --git a/packages/console/core/script/promote-limits.ts b/packages/console/core/script/promote-limits.ts index a54fcd0afc..55dabdb0f3 100755 --- a/packages/console/core/script/promote-limits.ts +++ b/packages/console/core/script/promote-limits.ts @@ -10,7 +10,7 @@ if (!stage) throw new Error("Stage is required") const root = path.resolve(process.cwd(), "..", "..", "..") // read the secret -const ret = await $`bun sst secret list --stage frank`.cwd(root).text() +const ret = await $`bun sst secret list --fallback`.cwd(root).text() const lines = ret.split("\n") const value = lines.find((line) => line.startsWith("ZEN_LIMITS"))?.split("=")[1] if (!value) throw new Error("ZEN_LIMITS not found") diff --git a/packages/console/core/script/update-limits.ts b/packages/console/core/script/update-limits.ts index 29794f5bec..f69a274a0c 100755 --- a/packages/console/core/script/update-limits.ts +++ b/packages/console/core/script/update-limits.ts @@ -6,7 +6,7 @@ import os from "os" import { Subscription } from "../src/subscription" const root = path.resolve(process.cwd(), "..", "..", "..") -const secrets = await $`bun sst secret list --stage frank`.cwd(root).text() +const secrets = await $`bun sst secret list --fallback`.cwd(root).text() // read value const lines = secrets.split("\n") @@ -25,4 +25,6 @@ const newValue = JSON.stringify(JSON.parse(await tempFile.text())) Subscription.validate(JSON.parse(newValue)) // update the secret -await $`bun sst secret set ZEN_LIMITS ${newValue} --stage frank`.cwd(root) +const envFile = Bun.file(path.join(os.tmpdir(), `limits-${Date.now()}.env`)) +await envFile.write(`ZEN_LIMITS="${newValue.replace(/"/g, '\\"')}"`) +await $`bun sst secret load ${envFile.name} --fallback`.cwd(root) diff --git a/packages/console/core/src/subscription.ts b/packages/console/core/src/subscription.ts index bee5818458..adbb0a55bc 100644 --- a/packages/console/core/src/subscription.ts +++ b/packages/console/core/src/subscription.ts @@ -9,6 +9,8 @@ export namespace Subscription { free: z.object({ promoTokens: z.number().int(), dailyRequests: z.number().int(), + dailyRequestsFallback: z.number().int(), + checkHeaders: z.record(z.string(), z.string()), }), lite: z.object({ rollingLimit: z.number().int(),