diff options
| author | Frank <[email protected]> | 2026-03-03 00:25:03 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-03-03 00:25:03 -0500 |
| commit | 6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9 (patch) | |
| tree | d0267534d1bd2e3331fc70ca177be4eef5d85530 /packages/console/core/src | |
| parent | 9f150b07764c44ab5265d7cc2a3fa4e5909094b2 (diff) | |
| download | opencode-6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9.tar.gz opencode-6aa4928e9e9430f8d1e9b009fd4a64f400fe0da9.zip | |
wip: zen
Diffstat (limited to 'packages/console/core/src')
| -rw-r--r-- | packages/console/core/src/black.ts | 26 | ||||
| -rw-r--r-- | packages/console/core/src/lite.ts | 15 | ||||
| -rw-r--r-- | packages/console/core/src/model.ts | 36 | ||||
| -rw-r--r-- | packages/console/core/src/subscription.ts | 46 |
4 files changed, 53 insertions, 70 deletions
diff --git a/packages/console/core/src/black.ts b/packages/console/core/src/black.ts index a18c5258d..1908403a2 100644 --- a/packages/console/core/src/black.ts +++ b/packages/console/core/src/black.ts @@ -2,37 +2,15 @@ import { z } from "zod" import { fn } from "./util/fn" import { Resource } from "@opencode-ai/console-resource" import { BlackPlans } from "./schema/billing.sql" +import { Subscription } from "./subscription" export namespace BlackData { - const Schema = z.object({ - "200": z.object({ - fixedLimit: z.number().int(), - rollingLimit: z.number().int(), - rollingWindow: z.number().int(), - }), - "100": z.object({ - fixedLimit: z.number().int(), - rollingLimit: z.number().int(), - rollingWindow: z.number().int(), - }), - "20": z.object({ - fixedLimit: z.number().int(), - rollingLimit: z.number().int(), - rollingWindow: z.number().int(), - }), - }) - - export const validate = fn(Schema, (input) => { - return input - }) - export const getLimits = fn( z.object({ plan: z.enum(BlackPlans), }), ({ plan }) => { - const json = JSON.parse(Resource.ZEN_BLACK_LIMITS.value) - return Schema.parse(json)[plan] + return Subscription.getLimits()["black"][plan] }, ) diff --git a/packages/console/core/src/lite.ts b/packages/console/core/src/lite.ts index 49d23e59e..c6f7d5a3e 100644 --- a/packages/console/core/src/lite.ts +++ b/packages/console/core/src/lite.ts @@ -1,22 +1,11 @@ import { z } from "zod" import { fn } from "./util/fn" import { Resource } from "@opencode-ai/console-resource" +import { Subscription } from "./subscription" export namespace LiteData { - const Schema = z.object({ - rollingLimit: z.number().int(), - rollingWindow: z.number().int(), - weeklyLimit: z.number().int(), - monthlyLimit: z.number().int(), - }) - - export const validate = fn(Schema, (input) => { - return input - }) - export const getLimits = fn(z.void(), () => { - const json = JSON.parse(Resource.ZEN_LITE_LIMITS.value) - return Schema.parse(json) + return Subscription.getLimits()["lite"] }) export const productID = fn(z.void(), () => Resource.ZEN_LITE_PRICE.product) diff --git a/packages/console/core/src/model.ts b/packages/console/core/src/model.ts index e868b176e..e4fa02249 100644 --- a/packages/console/core/src/model.ts +++ b/packages/console/core/src/model.ts @@ -9,24 +9,7 @@ import { Resource } from "@opencode-ai/console-resource" export namespace ZenData { const FormatSchema = z.enum(["anthropic", "google", "openai", "oa-compat"]) - const TrialSchema = z.object({ - provider: z.string(), - limits: z.array( - z.object({ - limit: z.number(), - client: z.enum(["cli", "desktop"]).optional(), - }), - ), - }) - const RateLimitSchema = z.object({ - period: z.enum(["day", "rolling"]), - value: z.number().int(), - checkHeader: z.string().optional(), - fallbackValue: z.number().int().optional(), - }) export type Format = z.infer<typeof FormatSchema> - export type Trial = z.infer<typeof TrialSchema> - export type RateLimit = z.infer<typeof RateLimitSchema> const ModelCostSchema = z.object({ input: z.number(), @@ -43,8 +26,7 @@ export namespace ZenData { allowAnonymous: z.boolean().optional(), byokProvider: z.enum(["openai", "anthropic", "google"]).optional(), stickyProvider: z.enum(["strict", "prefer"]).optional(), - trial: TrialSchema.optional(), - rateLimit: RateLimitSchema.optional(), + trialProvider: z.string().optional(), fallbackProvider: z.string().optional(), providers: z.array( z.object({ @@ -63,19 +45,12 @@ export namespace ZenData { format: FormatSchema.optional(), headerMappings: z.record(z.string(), z.string()).optional(), payloadModifier: z.record(z.string(), z.any()).optional(), - family: z.string().optional(), - }) - - const ProviderFamilySchema = z.object({ - headers: z.record(z.string(), z.string()).optional(), - responseModifier: z.record(z.string(), z.string()).optional(), }) const ModelsSchema = z.object({ models: z.record(z.string(), z.union([ModelSchema, z.array(ModelSchema.extend({ formatFilter: FormatSchema }))])), liteModels: z.record(z.string(), ModelSchema), providers: z.record(z.string(), ProviderSchema), - providerFamilies: z.record(z.string(), ProviderFamilySchema), }) export const validate = fn(ModelsSchema, (input) => { @@ -115,15 +90,10 @@ export namespace ZenData { Resource.ZEN_MODELS29.value + Resource.ZEN_MODELS30.value, ) - const { models, liteModels, providers, providerFamilies } = ModelsSchema.parse(json) + const { models, liteModels, providers } = ModelsSchema.parse(json) return { models: modelList === "lite" ? liteModels : models, - providers: Object.fromEntries( - Object.entries(providers).map(([id, provider]) => [ - id, - { ...provider, ...(provider.family ? providerFamilies[provider.family] : {}) }, - ]), - ), + providers, } }) } diff --git a/packages/console/core/src/subscription.ts b/packages/console/core/src/subscription.ts index 879f940e0..9d6c3ce2b 100644 --- a/packages/console/core/src/subscription.ts +++ b/packages/console/core/src/subscription.ts @@ -2,8 +2,54 @@ import { z } from "zod" import { fn } from "./util/fn" import { centsToMicroCents } from "./util/price" import { getWeekBounds, getMonthlyBounds } from "./util/date" +import { Resource } from "@opencode-ai/console-resource" export namespace Subscription { + const LimitsSchema = z.object({ + free: z.object({ + promoTokens: z.number().int(), + dailyRequests: z.number().int(), + checkHeader: z.string(), + fallbackValue: z.number().int(), + }), + lite: z.object({ + rollingLimit: z.number().int(), + rollingWindow: z.number().int(), + weeklyLimit: z.number().int(), + monthlyLimit: z.number().int(), + }), + black: z.object({ + "20": z.object({ + fixedLimit: z.number().int(), + rollingLimit: z.number().int(), + rollingWindow: z.number().int(), + }), + "100": z.object({ + fixedLimit: z.number().int(), + rollingLimit: z.number().int(), + rollingWindow: z.number().int(), + }), + "200": z.object({ + fixedLimit: z.number().int(), + rollingLimit: z.number().int(), + rollingWindow: z.number().int(), + }), + }), + }) + + export const validate = fn(LimitsSchema, (input) => { + return input + }) + + export const getLimits = fn(z.void(), () => { + const json = JSON.parse(Resource.ZEN_LIMITS.value) + return LimitsSchema.parse(json) + }) + + export const getFreeLimits = fn(z.void(), () => { + return getLimits()["free"] + }) + export const analyzeRollingUsage = fn( z.object({ limit: z.number().int(), |
