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

34 lines
1010 B
TypeScript
Raw Permalink Normal View History

2025-09-27 03:18:22 +08:00
#!/usr/bin/env bun
import { $ } from "bun"
import path from "path"
2026-01-31 01:19:36 +08:00
import os from "os"
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(), "..", "..", "..")
2026-02-17 14:32:57 +08:00
const PARTS = 30
2025-09-27 03:18:22 +08:00
// read the secret
2026-03-31 12:07:54 +08:00
const ret = await $`bun sst secret list --stage frank`.cwd(root).text()
2025-11-22 01:50:51 +08:00
const lines = ret.split("\n")
2026-01-16 07:21:01 +08:00
const values = Array.from({ length: PARTS }, (_, i) => {
const value = lines
2026-01-31 01:19:36 +08:00
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}=`))
2026-01-16 07:21:01 +08:00
?.split("=")
.slice(1)
.join("=")
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
return value
})
2025-09-27 03:18:22 +08:00
// validate value
2026-01-16 07:21:01 +08:00
ZenData.validate(JSON.parse(values.join("")))
2025-09-27 03:18:22 +08:00
// update the secret
2026-01-31 01:19:36 +08:00
const envFile = Bun.file(path.join(os.tmpdir(), `models-${Date.now()}.env`))
2026-02-08 02:32:19 +08:00
await envFile.write(values.map((v, i) => `ZEN_MODELS${i + 1}="${v.replace(/"/g, '\\"')}"`).join("\n"))
2026-01-31 01:19:36 +08:00
await $`bun sst secret load ${envFile.name} --stage ${stage}`.cwd(root)