Skip to content

Commit a51a1c0

Browse files
fwangColin4k1024
authored andcommitted
wip: zen (anomalyco#11343)
1 parent c5c3376 commit a51a1c0

11 files changed

Lines changed: 74 additions & 18 deletions

File tree

infra/console.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ const ZEN_MODELS = [
133133
new sst.Secret("ZEN_MODELS6"),
134134
new sst.Secret("ZEN_MODELS7"),
135135
new sst.Secret("ZEN_MODELS8"),
136+
new sst.Secret("ZEN_MODELS9"),
137+
new sst.Secret("ZEN_MODELS10"),
136138
]
137139
const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
138140
const STRIPE_PUBLISHABLE_KEY = new sst.Secret("STRIPE_PUBLISHABLE_KEY")

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import { $ } from "bun"
44
import path from "path"
5+
import os from "os"
56
import { ZenData } from "../src/model"
67

78
const stage = process.argv[2]
89
if (!stage) throw new Error("Stage is required")
910

1011
const root = path.resolve(process.cwd(), "..", "..", "..")
11-
const PARTS = 8
12+
const PARTS = 10
1213

1314
// read the secret
1415
const ret = await $`bun sst secret list`.cwd(root).text()
1516
const lines = ret.split("\n")
1617
const values = Array.from({ length: PARTS }, (_, i) => {
1718
const value = lines
18-
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
19+
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}=`))
1920
?.split("=")
2021
.slice(1)
2122
.join("=")
@@ -27,6 +28,6 @@ const values = Array.from({ length: PARTS }, (_, i) => {
2728
ZenData.validate(JSON.parse(values.join("")))
2829

2930
// update the secret
30-
for (let i = 0; i < PARTS; i++) {
31-
await $`bun sst secret set ZEN_MODELS${i + 1} --stage ${stage} -- ${values[i]}`
32-
}
31+
const envFile = Bun.file(path.join(os.tmpdir(), `models-${Date.now()}.env`))
32+
await envFile.write(values.map((v, i) => `ZEN_MODELS${i + 1}=${v}`).join("\n"))
33+
await $`bun sst secret load ${envFile.name} --stage ${stage}`.cwd(root)

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import { $ } from "bun"
44
import path from "path"
5+
import os from "os"
56
import { ZenData } from "../src/model"
67

78
const stage = process.argv[2]
89
if (!stage) throw new Error("Stage is required")
910

1011
const root = path.resolve(process.cwd(), "..", "..", "..")
11-
const PARTS = 8
12+
const PARTS = 10
1213

1314
// read the secret
1415
const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
1516
const lines = ret.split("\n")
1617
const values = Array.from({ length: PARTS }, (_, i) => {
1718
const value = lines
18-
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
19+
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}=`))
1920
?.split("=")
2021
.slice(1)
2122
.join("=")
@@ -27,6 +28,6 @@ const values = Array.from({ length: PARTS }, (_, i) => {
2728
ZenData.validate(JSON.parse(values.join("")))
2829

2930
// update the secret
30-
for (let i = 0; i < PARTS; i++) {
31-
await $`bun sst secret set ZEN_MODELS${i + 1} -- ${values[i]}`
32-
}
31+
const envFile = Bun.file(path.join(os.tmpdir(), `models-${Date.now()}.env`))
32+
await envFile.write(values.map((v, i) => `ZEN_MODELS${i + 1}=${v}`).join("\n"))
33+
await $`bun sst secret load ${envFile.name}`.cwd(root)

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import { ZenData } from "../src/model"
77

88
const root = path.resolve(process.cwd(), "..", "..", "..")
99
const models = await $`bun sst secret list`.cwd(root).text()
10-
const PARTS = 8
10+
const PARTS = 10
1111

1212
// read the line starting with "ZEN_MODELS"
1313
const lines = models.split("\n")
1414
const oldValues = Array.from({ length: PARTS }, (_, i) => {
1515
const value = lines
16-
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
16+
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}=`))
1717
?.split("=")
1818
.slice(1)
1919
.join("=")
20-
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
21-
return value
20+
// TODO
21+
//if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
22+
//return value
23+
return value ?? ""
2224
})
2325

2426
// store the prettified json to a temp file
@@ -38,6 +40,6 @@ const newValues = Array.from({ length: PARTS }, (_, i) =>
3840
newValue.slice(chunk * i, i === PARTS - 1 ? undefined : chunk * (i + 1)),
3941
)
4042

41-
for (let i = 0; i < PARTS; i++) {
42-
await $`bun sst secret set ZEN_MODELS${i + 1} -- ${newValues[i]}`
43-
}
43+
const envFile = Bun.file(path.join(os.tmpdir(), `models-${Date.now()}.env`))
44+
await envFile.write(newValues.map((v, i) => `ZEN_MODELS${i + 1}=${v}`).join("\n"))
45+
await $`bun sst secret load ${envFile.name}`.cwd(root)

packages/console/core/src/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export namespace ZenData {
7575
Resource.ZEN_MODELS5.value +
7676
Resource.ZEN_MODELS6.value +
7777
Resource.ZEN_MODELS7.value +
78-
Resource.ZEN_MODELS8.value,
78+
Resource.ZEN_MODELS8.value +
79+
Resource.ZEN_MODELS9.value +
80+
Resource.ZEN_MODELS10.value,
7981
)
8082
return ModelsSchema.parse(json)
8183
})

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ declare module "sst" {
133133
"type": "sst.sst.Secret"
134134
"value": string
135135
}
136+
"ZEN_MODELS10": {
137+
"type": "sst.sst.Secret"
138+
"value": string
139+
}
136140
"ZEN_MODELS2": {
137141
"type": "sst.sst.Secret"
138142
"value": string
@@ -161,6 +165,10 @@ declare module "sst" {
161165
"type": "sst.sst.Secret"
162166
"value": string
163167
}
168+
"ZEN_MODELS9": {
169+
"type": "sst.sst.Secret"
170+
"value": string
171+
}
164172
"ZEN_SESSION_SECRET": {
165173
"type": "sst.sst.Secret"
166174
"value": string

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ declare module "sst" {
133133
"type": "sst.sst.Secret"
134134
"value": string
135135
}
136+
"ZEN_MODELS10": {
137+
"type": "sst.sst.Secret"
138+
"value": string
139+
}
136140
"ZEN_MODELS2": {
137141
"type": "sst.sst.Secret"
138142
"value": string
@@ -161,6 +165,10 @@ declare module "sst" {
161165
"type": "sst.sst.Secret"
162166
"value": string
163167
}
168+
"ZEN_MODELS9": {
169+
"type": "sst.sst.Secret"
170+
"value": string
171+
}
164172
"ZEN_SESSION_SECRET": {
165173
"type": "sst.sst.Secret"
166174
"value": string

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ declare module "sst" {
133133
"type": "sst.sst.Secret"
134134
"value": string
135135
}
136+
"ZEN_MODELS10": {
137+
"type": "sst.sst.Secret"
138+
"value": string
139+
}
136140
"ZEN_MODELS2": {
137141
"type": "sst.sst.Secret"
138142
"value": string
@@ -161,6 +165,10 @@ declare module "sst" {
161165
"type": "sst.sst.Secret"
162166
"value": string
163167
}
168+
"ZEN_MODELS9": {
169+
"type": "sst.sst.Secret"
170+
"value": string
171+
}
164172
"ZEN_SESSION_SECRET": {
165173
"type": "sst.sst.Secret"
166174
"value": string

packages/enterprise/sst-env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ declare module "sst" {
133133
"type": "sst.sst.Secret"
134134
"value": string
135135
}
136+
"ZEN_MODELS10": {
137+
"type": "sst.sst.Secret"
138+
"value": string
139+
}
136140
"ZEN_MODELS2": {
137141
"type": "sst.sst.Secret"
138142
"value": string
@@ -161,6 +165,10 @@ declare module "sst" {
161165
"type": "sst.sst.Secret"
162166
"value": string
163167
}
168+
"ZEN_MODELS9": {
169+
"type": "sst.sst.Secret"
170+
"value": string
171+
}
164172
"ZEN_SESSION_SECRET": {
165173
"type": "sst.sst.Secret"
166174
"value": string

packages/function/sst-env.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ declare module "sst" {
133133
"type": "sst.sst.Secret"
134134
"value": string
135135
}
136+
"ZEN_MODELS10": {
137+
"type": "sst.sst.Secret"
138+
"value": string
139+
}
136140
"ZEN_MODELS2": {
137141
"type": "sst.sst.Secret"
138142
"value": string
@@ -161,6 +165,10 @@ declare module "sst" {
161165
"type": "sst.sst.Secret"
162166
"value": string
163167
}
168+
"ZEN_MODELS9": {
169+
"type": "sst.sst.Secret"
170+
"value": string
171+
}
164172
"ZEN_SESSION_SECRET": {
165173
"type": "sst.sst.Secret"
166174
"value": string

0 commit comments

Comments
 (0)