zen: wip · argszero/opencode@05232ea · GitHub
Skip to content

Commit 05232ea

Browse files
author
Frank
committed
zen: wip
1 parent 7652a96 commit 05232ea

14 files changed

Lines changed: 285 additions & 29 deletions

File tree

infra/console.ts

Lines changed: 11 additions & 3 deletions

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ export async function handler(
239239
.filter((provider) => !provider.disabled)
240240
.flatMap((provider) => Array<typeof provider>(provider.weight ?? 1).fill(provider))
241241

242-
// Use last character of IP address to select a provider
243-
const lastChar = ip.charCodeAt(ip.length - 1) || 0
244-
const index = lastChar % providers.length
245-
const provider = providers[index]
242+
// Use the last 2 characters of IP address to select a provider
243+
const lastChars = ip.slice(-2)
244+
const index = parseInt(lastChars, 16) % providers.length
245+
const provider = providers[index || 0]
246246

247247
if (!(provider.id in zenData.providers)) {
248248
throw new ModelError(`Provider ${provider.id} not supported`)

packages/console/core/script/promote-models.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ const root = path.resolve(process.cwd(), "..", "..", "..")
1111

1212
// read the secret
1313
const ret = await $`bun sst secret list`.cwd(root).text()
14-
const value = ret
14+
const value1 = ret
1515
.split("\n")
16-
.find((line) => line.startsWith("ZEN_MODELS"))
16+
.find((line) => line.startsWith("ZEN_MODELS1"))
1717
?.split("=")[1]
18-
if (!value) throw new Error("ZEN_MODELS not found")
18+
const value2 = ret
19+
.split("\n")
20+
.find((line) => line.startsWith("ZEN_MODELS2"))
21+
?.split("=")[1]
22+
if (!value1) throw new Error("ZEN_MODELS1 not found")
23+
if (!value2) throw new Error("ZEN_MODELS2 not found")
1924

2025
// validate value
21-
ZenData.validate(JSON.parse(value))
26+
ZenData.validate(JSON.parse(value1 + value2))
2227

2328
// update the secret
24-
await $`bun sst secret set ZEN_MODELS ${value} --stage ${stage}`
29+
await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}`
30+
await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}`

packages/console/core/script/update-models.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@ const models = await $`bun sst secret list`.cwd(root).text()
1010
console.log("models", models)
1111

1212
// read the line starting with "ZEN_MODELS"
13-
const oldValue = models
13+
const oldValue1 = models
1414
.split("\n")
15-
.find((line) => line.startsWith("ZEN_MODELS"))
15+
.find((line) => line.startsWith("ZEN_MODELS1"))
1616
?.split("=")[1]
17-
if (!oldValue) throw new Error("ZEN_MODELS not found")
18-
console.log("oldValue", oldValue)
17+
const oldValue2 = models
18+
.split("\n")
19+
.find((line) => line.startsWith("ZEN_MODELS2"))
20+
?.split("=")[1]
21+
if (!oldValue1) throw new Error("ZEN_MODELS1 not found")
22+
if (!oldValue2) throw new Error("ZEN_MODELS2 not found")
1923

2024
// store the prettified json to a temp file
2125
const filename = `models-${Date.now()}.json`
2226
const tempFile = Bun.file(path.join(os.tmpdir(), filename))
23-
await tempFile.write(JSON.stringify(JSON.parse(oldValue), null, 2))
27+
await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2), null, 2))
2428
console.log("tempFile", tempFile.name)
2529

2630
// open temp file in vim and read the file on close
2731
await $`vim ${tempFile.name}`
28-
const newValue = JSON.parse(await tempFile.text())
29-
ZenData.validate(newValue)
32+
const newValue = JSON.stringify(JSON.parse(await tempFile.text()))
33+
ZenData.validate(JSON.parse(newValue))
3034

3135
// update the secret
32-
await $`bun sst secret set ZEN_MODELS ${JSON.stringify(newValue)}`
36+
const mid = Math.floor(newValue.length / 2)
37+
await $`bun sst secret set ZEN_MODELS1 ${newValue.slice(0, mid)}`
38+
await $`bun sst secret set ZEN_MODELS2 ${newValue.slice(mid)}`

packages/console/core/src/model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export namespace ZenData {
4747
})
4848

4949
export const list = fn(z.void(), () => {
50-
const json = JSON.parse(Resource.ZEN_MODELS.value)
50+
const json = JSON.parse(Resource.ZEN_MODELS1.value + Resource.ZEN_MODELS2.value)
5151
return ModelsSchema.parse(json)
5252
})
5353
}
@@ -56,7 +56,9 @@ export namespace Model {
5656
export const enable = fn(z.object({ model: z.string() }), ({ model }) => {
5757
Actor.assertAdmin()
5858
return Database.use((db) =>
59-
db.delete(ModelTable).where(and(eq(ModelTable.workspaceID, Actor.workspace()), eq(ModelTable.model, model))),
59+
db
60+
.delete(ModelTable)
61+
.where(and(eq(ModelTable.workspaceID, Actor.workspace()), eq(ModelTable.model, model))),
6062
)
6163
})
6264

packages/console/core/sst-env.d.ts

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,102 @@
33
/* eslint-disable */
44
/* deno-fmt-ignore-file */
55

6-
/// <reference path="../../../sst-env.d.ts" />
6+
import "sst"
7+
declare module "sst" {
8+
export interface Resource {
9+
"ADMIN_SECRET": {
10+
"type": "sst.sst.Secret"
11+
"value": string
12+
}
13+
"AUTH_API_URL": {
14+
"type": "sst.sst.Linkable"
15+
"value": string
16+
}
17+
"AWS_SES_ACCESS_KEY_ID": {
18+
"type": "sst.sst.Secret"
19+
"value": string
20+
}
21+
"AWS_SES_SECRET_ACCESS_KEY": {
22+
"type": "sst.sst.Secret"
23+
"value": string
24+
}
25+
"Console": {
26+
"type": "sst.cloudflare.SolidStart"
27+
"url": string
28+
}
29+
"Database": {
30+
"database": string
31+
"host": string
32+
"password": string
33+
"port": number
34+
"type": "sst.sst.Linkable"
35+
"username": string
36+
}
37+
"Desktop": {
38+
"type": "sst.cloudflare.StaticSite"
39+
"url": string
40+
}
41+
"EMAILOCTOPUS_API_KEY": {
42+
"type": "sst.sst.Secret"
43+
"value": string
44+
}
45+
"GITHUB_APP_ID": {
46+
"type": "sst.sst.Secret"
47+
"value": string
48+
}
49+
"GITHUB_APP_PRIVATE_KEY": {
50+
"type": "sst.sst.Secret"
51+
"value": string
52+
}
53+
"GITHUB_CLIENT_ID_CONSOLE": {
54+
"type": "sst.sst.Secret"
55+
"value": string
56+
}
57+
"GITHUB_CLIENT_SECRET_CONSOLE": {
58+
"type": "sst.sst.Secret"
59+
"value": string
60+
}
61+
"GOOGLE_CLIENT_ID": {
62+
"type": "sst.sst.Secret"
63+
"value": string
64+
}
65+
"HONEYCOMB_API_KEY": {
66+
"type": "sst.sst.Secret"
67+
"value": string
68+
}
69+
"STRIPE_SECRET_KEY": {
70+
"type": "sst.sst.Secret"
71+
"value": string
72+
}
73+
"STRIPE_WEBHOOK_SECRET": {
74+
"type": "sst.sst.Linkable"
75+
"value": string
76+
}
77+
"Web": {
78+
"type": "sst.cloudflare.Astro"
79+
"url": string
80+
}
81+
"ZEN_MODELS1": {
82+
"type": "sst.sst.Secret"
83+
"value": string
84+
}
85+
"ZEN_MODELS2": {
86+
"type": "sst.sst.Secret"
87+
"value": string
88+
}
89+
}
90+
}
91+
// cloudflare
92+
import * as cloudflare from "@cloudflare/workers-types";
93+
declare module "sst" {
94+
export interface Resource {
95+
"Api": cloudflare.Service
96+
"AuthApi": cloudflare.Service
97+
"AuthStorage": cloudflare.KVNamespace
98+
"Bucket": cloudflare.R2Bucket
99+
"LogProcessor": cloudflare.Service
100+
}
101+
}
7102

8103
import "sst"
9104
export {}

packages/console/function/sst-env.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import "sst"
77
declare module "sst" {
88
export interface Resource {
9+
"ADMIN_SECRET": {
10+
"type": "sst.sst.Secret"
11+
"value": string
12+
}
913
"AUTH_API_URL": {
1014
"type": "sst.sst.Linkable"
1115
"value": string
@@ -74,7 +78,11 @@ declare module "sst" {
7478
"type": "sst.cloudflare.Astro"
7579
"url": string
7680
}
77-
"ZEN_MODELS": {
81+
"ZEN_MODELS1": {
82+
"type": "sst.sst.Secret"
83+
"value": string
84+
}
85+
"ZEN_MODELS2": {
7886
"type": "sst.sst.Secret"
7987
"value": string
8088
}

packages/console/resource/sst-env.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import "sst"
77
declare module "sst" {
88
export interface Resource {
9+
"ADMIN_SECRET": {
10+
"type": "sst.sst.Secret"
11+
"value": string
12+
}
913
"AUTH_API_URL": {
1014
"type": "sst.sst.Linkable"
1115
"value": string
@@ -74,7 +78,11 @@ declare module "sst" {
7478
"type": "sst.cloudflare.Astro"
7579
"url": string
7680
}
77-
"ZEN_MODELS": {
81+
"ZEN_MODELS1": {
82+
"type": "sst.sst.Secret"
83+
"value": string
84+
}
85+
"ZEN_MODELS2": {
7886
"type": "sst.sst.Secret"
7987
"value": string
8088
}

packages/function/sst-env.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import "sst"
77
declare module "sst" {
88
export interface Resource {
9+
"ADMIN_SECRET": {
10+
"type": "sst.sst.Secret"
11+
"value": string
12+
}
913
"AUTH_API_URL": {
1014
"type": "sst.sst.Linkable"
1115
"value": string
@@ -74,7 +78,11 @@ declare module "sst" {
7478
"type": "sst.cloudflare.Astro"
7579
"url": string
7680
}
77-
"ZEN_MODELS": {
81+
"ZEN_MODELS1": {
82+
"type": "sst.sst.Secret"
83+
"value": string
84+
}
85+
"ZEN_MODELS2": {
7886
"type": "sst.sst.Secret"
7987
"value": string
8088
}

packages/script/sst-env.d.ts

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)