Frank hai 3 meses
pai
achega
0b8050d453

+ 5 - 2
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()

+ 1 - 1
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")

+ 4 - 2
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)

+ 2 - 0
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(),