GeezerVison is showing github.com — Zen: sync · toastdriven/opencode@57120e6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: infra/console.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,6 +102,7 @@ const ZEN_MODELS = [ | 102 | 102 | new sst.Secret("ZEN_MODELS2"), | 103 | 103 | new sst.Secret("ZEN_MODELS3"), | 104 | 104 | new sst.Secret("ZEN_MODELS4"), | | 105 | + new sst.Secret("ZEN_MODELS5"), | 105 | 106 | ] | 106 | 107 | const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY") | 107 | 108 | const AUTH_API_URL = new sst.Linkable("AUTH_API_URL", { | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/workspace/[id]/model-section.tsx +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,9 +43,12 @@ const getModelsInfo = query(async (workspaceID: string) => { | 43 | 43 | const pA = getPriority(idA) | 44 | 44 | const pB = getPriority(idB) | 45 | 45 | if (pA !== pB) return pA - pB | 46 | | - return modelA.name.localeCompare(modelB.name) | | 46 | + | | 47 | + const modelAName = Array.isArray(modelA) ? modelA[0].name : modelA.name | | 48 | + const modelBName = Array.isArray(modelB) ? modelB[0].name : modelB.name | | 49 | + return modelAName.localeCompare(modelBName) | 47 | 50 | }) | 48 | | - .map(([id, model]) => ({ id, name: model.name })), | | 51 | + .map(([id, model]) => ({ id, name: Array.isArray(model) ? model[0].name : model.name })), | 49 | 52 | disabled: await Model.listDisabled(), | 50 | 53 | } | 51 | 54 | }, workspaceID) | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/zen/util/handler.ts +10-5Lines changed: 10 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,15 +57,17 @@ export async function handler( | 57 | 57 | const sessionId = input.request.headers.get("x-opencode-session") ?? "" | 58 | 58 | const requestId = input.request.headers.get("x-opencode-request") ?? "" | 59 | 59 | const projectId = input.request.headers.get("x-opencode-project") ?? "" | | 60 | + const ocClient = input.request.headers.get("x-opencode-client") ?? "" | 60 | 61 | logger.metric({ | 61 | 62 | is_tream: isStream, | 62 | 63 | session: sessionId, | 63 | 64 | request: requestId, | | 65 | + client: ocClient, | 64 | 66 | }) | 65 | 67 | const zenData = ZenData.list() | 66 | 68 | const modelInfo = validateModel(zenData, model) | 67 | 69 | const dataDumper = createDataDumper(sessionId, requestId, projectId) | 68 | | - const trialLimiter = createTrialLimiter(modelInfo.trial?.limit, ip) | | 70 | + const trialLimiter = createTrialLimiter(modelInfo.trial, ip, ocClient) | 69 | 71 | const isTrial = await trialLimiter?.isTrial() | 70 | 72 | const rateLimiter = createRateLimiter(modelInfo.id, modelInfo.rateLimit, ip) | 71 | 73 | await rateLimiter?.check() | @@ -286,11 +288,14 @@ export async function handler( | 286 | 288 | } | 287 | 289 |
| 288 | 290 | function validateModel(zenData: ZenData, reqModel: string) { | 289 | | - if (!(reqModel in zenData.models)) { | 290 | | - throw new ModelError(`Model ${reqModel} not supported`) | 291 | | - } | | 291 | + if (!(reqModel in zenData.models)) throw new ModelError(`Model ${reqModel} not supported`) | | 292 | + | 292 | 293 | const modelId = reqModel as keyof typeof zenData.models | 293 | | - const modelData = zenData.models[modelId] | | 294 | + const modelData = Array.isArray(zenData.models[modelId]) | | 295 | + ? zenData.models[modelId].find((model) => opts.format === model.formatFilter) | | 296 | + : zenData.models[modelId] | | 297 | + | | 298 | + if (!modelData) throw new ModelError(`Model ${reqModel} not supported for format ${opts.format}`) | 294 | 299 |
| 295 | 300 | logger.metric({ model: modelId }) | 296 | 301 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/zen/util/trialLimiter.ts +12-6Lines changed: 12 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Database, eq, sql } from "@opencode-ai/console-core/drizzle/index.js" | 2 | 2 | import { IpTable } from "@opencode-ai/console-core/schema/ip.sql.js" | 3 | 3 | import { UsageInfo } from "./provider/provider" | | 4 | +import { ZenData } from "@opencode-ai/console-core/model.js" | 4 | 5 |
| 5 | | -export function createTrialLimiter(limit: number | undefined, ip: string) { | 6 | | - if (!limit) return | | 6 | +export function createTrialLimiter(trial: ZenData.Trial | undefined, ip: string, client: string) { | | 7 | + if (!trial) return | 7 | 8 | if (!ip) return | 8 | 9 |
| 9 | | - let trial: boolean | | 10 | + const limit = | | 11 | + trial.limits.find((limit) => limit.client === client)?.limit ?? | | 12 | + trial.limits.find((limit) => limit.client === undefined)?.limit | | 13 | + if (!limit) return | | 14 | + | | 15 | + let _isTrial: boolean | 10 | 16 |
| 11 | 17 | return { | 12 | 18 | isTrial: async () => { | @@ -20,11 +26,11 @@ export function createTrialLimiter(limit: number | undefined, ip: string) { | 20 | 26 | .then((rows) => rows[0]), | 21 | 27 | ) | 22 | 28 |
| 23 | | - trial = (data?.usage ?? 0) < limit | 24 | | - return trial | | 29 | + _isTrial = (data?.usage ?? 0) < limit | | 30 | + return _isTrial | 25 | 31 | }, | 26 | 32 | track: async (usageInfo: UsageInfo) => { | 27 | | - if (!trial) return | | 33 | + if (!_isTrial) return | 28 | 34 | const usage = | 29 | 35 | usageInfo.inputTokens + | 30 | 36 | usageInfo.outputTokens + | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/script/promote-models.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,16 +16,19 @@ const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[ | 16 | 16 | const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1] | 17 | 17 | const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1] | 18 | 18 | const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1] | | 19 | +const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1] | 19 | 20 | if (!value1) throw new Error("ZEN_MODELS1 not found") | 20 | 21 | if (!value2) throw new Error("ZEN_MODELS2 not found") | 21 | 22 | if (!value3) throw new Error("ZEN_MODELS3 not found") | 22 | 23 | if (!value4) throw new Error("ZEN_MODELS4 not found") | | 24 | +if (!value5) throw new Error("ZEN_MODELS5 not found") | 23 | 25 |
| 24 | 26 | // validate value | 25 | | -ZenData.validate(JSON.parse(value1 + value2 + value3 + value4)) | | 27 | +ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5)) | 26 | 28 |
| 27 | 29 | // update the secret | 28 | 30 | await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}` | 29 | 31 | await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}` | 30 | 32 | await $`bun sst secret set ZEN_MODELS3 ${value3} --stage ${stage}` | 31 | 33 | await $`bun sst secret set ZEN_MODELS4 ${value4} --stage ${stage}` | | 34 | +await $`bun sst secret set ZEN_MODELS5 ${value5} --stage ${stage}` |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/script/pull-models.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,16 +16,19 @@ const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[ | 16 | 16 | const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1] | 17 | 17 | const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1] | 18 | 18 | const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1] | | 19 | +const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1] | 19 | 20 | if (!value1) throw new Error("ZEN_MODELS1 not found") | 20 | 21 | if (!value2) throw new Error("ZEN_MODELS2 not found") | 21 | 22 | if (!value3) throw new Error("ZEN_MODELS3 not found") | 22 | 23 | if (!value4) throw new Error("ZEN_MODELS4 not found") | | 24 | +if (!value5) throw new Error("ZEN_MODELS5 not found") | 23 | 25 |
| 24 | 26 | // validate value | 25 | | -ZenData.validate(JSON.parse(value1 + value2 + value3 + value4)) | | 27 | +ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5)) | 26 | 28 |
| 27 | 29 | // update the secret | 28 | 30 | await $`bun sst secret set ZEN_MODELS1 ${value1}` | 29 | 31 | await $`bun sst secret set ZEN_MODELS2 ${value2}` | 30 | 32 | await $`bun sst secret set ZEN_MODELS3 ${value3}` | 31 | 33 | await $`bun sst secret set ZEN_MODELS4 ${value4}` | | 34 | +await $`bun sst secret set ZEN_MODELS5 ${value5}` |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/script/update-models.ts +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,15 +14,17 @@ const oldValue1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("= | 14 | 14 | const oldValue2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1] | 15 | 15 | const oldValue3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1] | 16 | 16 | const oldValue4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1] | | 17 | +const oldValue5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1] | 17 | 18 | if (!oldValue1) throw new Error("ZEN_MODELS1 not found") | 18 | 19 | if (!oldValue2) throw new Error("ZEN_MODELS2 not found") | 19 | 20 | if (!oldValue3) throw new Error("ZEN_MODELS3 not found") | 20 | 21 | if (!oldValue4) throw new Error("ZEN_MODELS4 not found") | | 22 | +if (!oldValue5) throw new Error("ZEN_MODELS5 not found") | 21 | 23 |
| 22 | 24 | // store the prettified json to a temp file | 23 | 25 | const filename = `models-${Date.now()}.json` | 24 | 26 | const tempFile = Bun.file(path.join(os.tmpdir(), filename)) | 25 | | -await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2 + oldValue3 + oldValue4), null, 2)) | | 27 | +await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2 + oldValue3 + oldValue4 + oldValue5), null, 2)) | 26 | 28 | console.log("tempFile", tempFile.name) | 27 | 29 |
| 28 | 30 | // open temp file in vim and read the file on close | @@ -31,12 +33,15 @@ const newValue = JSON.stringify(JSON.parse(await tempFile.text())) | 31 | 33 | ZenData.validate(JSON.parse(newValue)) | 32 | 34 |
| 33 | 35 | // update the secret | 34 | | -const chunk = Math.ceil(newValue.length / 4) | | 36 | +const chunk = Math.ceil(newValue.length / 5) | 35 | 37 | const newValue1 = newValue.slice(0, chunk) | 36 | 38 | const newValue2 = newValue.slice(chunk, chunk * 2) | 37 | 39 | const newValue3 = newValue.slice(chunk * 2, chunk * 3) | 38 | | -const newValue4 = newValue.slice(chunk * 3) | | 40 | +const newValue4 = newValue.slice(chunk * 3, chunk * 4) | | 41 | +const newValue5 = newValue.slice(chunk * 4) | | 42 | + | 39 | 43 | await $`bun sst secret set ZEN_MODELS1 ${newValue1}` | 40 | 44 | await $`bun sst secret set ZEN_MODELS2 ${newValue2}` | 41 | 45 | await $`bun sst secret set ZEN_MODELS3 ${newValue3}` | 42 | 46 | await $`bun sst secret set ZEN_MODELS4 ${newValue4}` | | 47 | +await $`bun sst secret set ZEN_MODELS5 ${newValue5}` |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/src/model.ts +17-8Lines changed: 17 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,17 @@ import { Resource } from "@opencode-ai/console-resource" | 9 | 9 |
| 10 | 10 | export namespace ZenData { | 11 | 11 | const FormatSchema = z.enum(["anthropic", "google", "openai", "oa-compat"]) | | 12 | + const TrialSchema = z.object({ | | 13 | + provider: z.string(), | | 14 | + limits: z.array( | | 15 | + z.object({ | | 16 | + limit: z.number(), | | 17 | + client: z.enum(["cli", "desktop"]).optional(), | | 18 | + }), | | 19 | + ), | | 20 | + }) | 12 | 21 | export type Format = z.infer<typeof FormatSchema> | | 22 | + export type Trial = z.infer<typeof TrialSchema> | 13 | 23 |
| 14 | 24 | const ModelCostSchema = z.object({ | 15 | 25 | input: z.number(), | @@ -26,12 +36,7 @@ export namespace ZenData { | 26 | 36 | allowAnonymous: z.boolean().optional(), | 27 | 37 | byokProvider: z.enum(["openai", "anthropic", "google"]).optional(), | 28 | 38 | stickyProvider: z.boolean().optional(), | 29 | | - trial: z | 30 | | - .object({ | 31 | | - limit: z.number(), | 32 | | - provider: z.string(), | 33 | | - }) | 34 | | - .optional(), | | 39 | + trial: TrialSchema.optional(), | 35 | 40 | rateLimit: z.number().optional(), | 36 | 41 | fallbackProvider: z.string().optional(), | 37 | 42 | providers: z.array( | @@ -53,7 +58,7 @@ export namespace ZenData { | 53 | 58 | }) | 54 | 59 |
| 55 | 60 | const ModelsSchema = z.object({ | 56 | | - models: z.record(z.string(), ModelSchema), | | 61 | + models: z.record(z.string(), z.union([ModelSchema, z.array(ModelSchema.extend({ formatFilter: FormatSchema }))])), | 57 | 62 | providers: z.record(z.string(), ProviderSchema), | 58 | 63 | }) | 59 | 64 |
| @@ -63,7 +68,11 @@ export namespace ZenData { | 63 | 68 |
| 64 | 69 | export const list = fn(z.void(), () => { | 65 | 70 | const json = JSON.parse( | 66 | | - Resource.ZEN_MODELS1.value + Resource.ZEN_MODELS2.value + Resource.ZEN_MODELS3.value + Resource.ZEN_MODELS4.value, | | 71 | + Resource.ZEN_MODELS1.value + | | 72 | + Resource.ZEN_MODELS2.value + | | 73 | + Resource.ZEN_MODELS3.value + | | 74 | + Resource.ZEN_MODELS4.value + | | 75 | + Resource.ZEN_MODELS5.value, | 67 | 76 | ) | 68 | 77 | return ModelsSchema.parse(json) | 69 | 78 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/sst-env.d.ts +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,10 +50,6 @@ declare module "sst" { | 50 | 50 | "type": "sst.sst.Secret" | 51 | 51 | "value": string | 52 | 52 | } | 53 | | - "Enterprise": { | 54 | | - "type": "sst.cloudflare.SolidStart" | 55 | | - "url": string | 56 | | - } | 57 | 53 | "GITHUB_APP_ID": { | 58 | 54 | "type": "sst.sst.Secret" | 59 | 55 | "value": string | @@ -94,6 +90,10 @@ declare module "sst" { | 94 | 90 | "type": "sst.sst.Linkable" | 95 | 91 | "value": string | 96 | 92 | } | | 93 | + "Teams": { | | 94 | + "type": "sst.cloudflare.SolidStart" | | 95 | + "url": string | | 96 | + } | 97 | 97 | "Web": { | 98 | 98 | "type": "sst.cloudflare.Astro" | 99 | 99 | "url": string | @@ -114,6 +114,10 @@ declare module "sst" { | 114 | 114 | "type": "sst.sst.Secret" | 115 | 115 | "value": string | 116 | 116 | } | | 117 | + "ZEN_MODELS5": { | | 118 | + "type": "sst.sst.Secret" | | 119 | + "value": string | | 120 | + } | 117 | 121 | } | 118 | 122 | } | 119 | 123 | // cloudflare | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/function/sst-env.d.ts +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,10 +50,6 @@ declare module "sst" { | 50 | 50 | "type": "sst.sst.Secret" | 51 | 51 | "value": string | 52 | 52 | } | 53 | | - "Enterprise": { | 54 | | - "type": "sst.cloudflare.SolidStart" | 55 | | - "url": string | 56 | | - } | 57 | 53 | "GITHUB_APP_ID": { | 58 | 54 | "type": "sst.sst.Secret" | 59 | 55 | "value": string | @@ -94,6 +90,10 @@ declare module "sst" { | 94 | 90 | "type": "sst.sst.Linkable" | 95 | 91 | "value": string | 96 | 92 | } | | 93 | + "Teams": { | | 94 | + "type": "sst.cloudflare.SolidStart" | | 95 | + "url": string | | 96 | + } | 97 | 97 | "Web": { | 98 | 98 | "type": "sst.cloudflare.Astro" | 99 | 99 | "url": string | @@ -114,6 +114,10 @@ declare module "sst" { | 114 | 114 | "type": "sst.sst.Secret" | 115 | 115 | "value": string | 116 | 116 | } | | 117 | + "ZEN_MODELS5": { | | 118 | + "type": "sst.sst.Secret" | | 119 | + "value": string | | 120 | + } | 117 | 121 | } | 118 | 122 | } | 119 | 123 | // cloudflare | |
|