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

38 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-09-27 03:18:22 +08:00
#!/usr/bin/env bun
import { $ } from "bun"
import path from "path"
2025-10-17 03:58:49 +08:00
import { ZenData } from "../src/model"
2025-09-27 03:18:22 +08:00
const stage = process.argv[2]
if (!stage) throw new Error("Stage is required")
const root = path.resolve(process.cwd(), "..", "..", "..")
// read the secret
const ret = await $`bun sst secret list`.cwd(root).text()
2025-11-22 01:50:51 +08:00
const lines = ret.split("\n")
const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
2025-12-12 12:41:04 +08:00
const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1]
2025-12-24 09:36:52 +08:00
const value6 = lines.find((line) => line.startsWith("ZEN_MODELS6"))?.split("=")[1]
2025-11-04 04:43:52 +08:00
if (!value1) throw new Error("ZEN_MODELS1 not found")
if (!value2) throw new Error("ZEN_MODELS2 not found")
2025-11-22 01:50:51 +08:00
if (!value3) throw new Error("ZEN_MODELS3 not found")
if (!value4) throw new Error("ZEN_MODELS4 not found")
2025-12-12 12:41:04 +08:00
if (!value5) throw new Error("ZEN_MODELS5 not found")
2025-12-24 09:36:52 +08:00
if (!value6) throw new Error("ZEN_MODELS6 not found")
2025-09-27 03:18:22 +08:00
// validate value
2025-12-24 09:36:52 +08:00
ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5 + value6))
2025-09-27 03:18:22 +08:00
// update the secret
2025-11-04 04:43:52 +08:00
await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}`
await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}`
2025-11-22 01:50:51 +08:00
await $`bun sst secret set ZEN_MODELS3 ${value3} --stage ${stage}`
await $`bun sst secret set ZEN_MODELS4 ${value4} --stage ${stage}`
2025-12-12 12:41:04 +08:00
await $`bun sst secret set ZEN_MODELS5 ${value5} --stage ${stage}`
2025-12-24 09:36:52 +08:00
await $`bun sst secret set ZEN_MODELS6 ${value6} --stage ${stage}`