Skip to content

Commit 83f2b6f

Browse files
authored
refactor(console): make Zen routes a thin inference proxy (#54563)
1 parent d21b079 commit 83f2b6f

48 files changed

Lines changed: 53 additions & 5120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎bun.lock‎

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎infra/console.ts‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,6 @@ export const auth = new sst.cloudflare.Worker("AuthApi", {
6969
// GATEWAY
7070
////////////////
7171

72-
export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint", {
73-
url: $interpolate`https://${domain}/stripe/webhook`,
74-
enabledEvents: [
75-
"checkout.session.async_payment_failed",
76-
"checkout.session.async_payment_succeeded",
77-
"checkout.session.completed",
78-
"checkout.session.expired",
79-
"charge.refunded",
80-
"invoice.payment_succeeded",
81-
"invoice.payment_failed",
82-
"invoice.payment_action_required",
83-
"customer.created",
84-
"customer.deleted",
85-
"customer.updated",
86-
"customer.discount.created",
87-
"customer.discount.deleted",
88-
"customer.discount.updated",
89-
"customer.source.created",
90-
"customer.source.deleted",
91-
"customer.source.expiring",
92-
"customer.source.updated",
93-
"customer.subscription.created",
94-
"customer.subscription.deleted",
95-
"customer.subscription.paused",
96-
"customer.subscription.pending_update_applied",
97-
"customer.subscription.pending_update_expired",
98-
"customer.subscription.resumed",
99-
"customer.subscription.trial_will_end",
100-
"customer.subscription.updated",
101-
],
102-
})
103-
10472
const zenLiteProduct = new stripe.Product("ZenLite", {
10573
name: "OpenCode Go",
10674
})
@@ -229,9 +197,6 @@ const consoleMigration = new sst.Linkable("ConsoleMigration", {
229197
inferenceUrl: migrationDomain ? `https://${migrationDomain}/inference` : "",
230198
},
231199
})
232-
const STRIPE_WEBHOOK_SECRET = new sst.Linkable("STRIPE_WEBHOOK_SECRET", {
233-
properties: { value: stripeWebhook.secret },
234-
})
235200

236201
////////////////
237202
// CONSOLE
@@ -261,11 +226,8 @@ new sst.cloudflare.x.SolidStart("Console", {
261226
bucket,
262227
bucketNew,
263228
database,
264-
SECRET.UpstashRedisRestUrl,
265-
SECRET.UpstashRedisRestToken,
266229
AUTH_API_URL,
267230
consoleMigration,
268-
STRIPE_WEBHOOK_SECRET,
269231
SECRET.SupportApiKey,
270232
DISCORD_INCIDENT_WEBHOOK_URL,
271233
SECRET.HoneycombWebhookSecret,

‎infra/secret.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ export const SECRET = {
1010
HoneycombApiKey: new sst.Secret("HONEYCOMB_API_KEY"),
1111
HoneycombWebhookSecret: new random.RandomPassword("HoneycombWebhookSecret", { length: 24 }),
1212
SupportApiKey: new sst.Secret("SUPPORT_API_KEY"),
13-
UpstashRedisRestUrl: new sst.Secret("UpstashRedisRestUrl"),
14-
UpstashRedisRestToken: new sst.Secret("UpstashRedisRestToken"),
1513
}

‎packages/console/app/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@solidjs/router": "catalog:",
2727
"@solidjs/start": "catalog:",
2828
"@stripe/stripe-js": "8.6.1",
29-
"@upstash/redis": "1.38.0",
3029
"chart.js": "4.5.1",
3130
"nitro": "3.0.1-alpha.1",
3231
"number-flow": "0.6.2",

‎packages/console/app/src/lib/inference-proxy.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export async function proxyInference(
4444
? request.headers.get("x-goog-api-key")
4545
: request.headers.get("authorization")?.split(" ")[1]
4646
const anonymous = !key || key === "public"
47-
if (anonymous && !generation?.anonymous) return undefined
47+
// The destination answers keyless reads itself; keyless generation is only forwarded for free models.
48+
if (anonymous && request.method !== "GET" && !generation?.anonymous) return undefined
4849

4950
// New Console keys are never in the legacy key table; every legacy key is `sk-`.
5051
const legacy = !anonymous && !key.startsWith("oc_sk_")
Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
1-
const MUSE_SPARK_BLOCKED_COUNTRIES = new Set([
2-
"AF",
3-
"BY",
4-
"CN",
5-
"CU",
6-
"EH",
7-
"ER",
8-
"ET",
9-
"HK",
10-
"HT",
11-
"IQ",
12-
"IR",
13-
"KH",
14-
"KP",
15-
"LY",
16-
"MM",
17-
"MO",
18-
"NI",
19-
"PK",
20-
"RU",
21-
"SO",
22-
"SY",
23-
"VE",
24-
])
25-
261
export function countryFromRequest(request: Request | undefined) {
272
if (!request) return undefined
283
const cloudflareRequest = request as Request & { cf?: { country?: string } }
294
return cloudflareRequest.cf?.country ?? request.headers.get("cf-ipcountry") ?? undefined
305
}
31-
32-
export function isModelCountryRestricted(model: string, country: string | undefined) {
33-
return (
34-
[
35-
"muse-spark-1.3-contributor",
36-
"muse-spark-1.3-contributor-free",
37-
"muse-spark-1.2-contributor",
38-
"muse-spark-1.2-contributor-free",
39-
].includes(model) &&
40-
country !== undefined &&
41-
MUSE_SPARK_BLOCKED_COUNTRIES.has(country.toUpperCase())
42-
)
43-
}

0 commit comments

Comments
 (0)