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

33 lines
840 B
TypeScript
Raw Normal View History

2025-11-25 04:24:43 +08:00
#!/usr/bin/env bun
import { $ } from "bun"
import path from "path"
import { ZenData } from "../src/model"
const stage = process.argv[2]
if (!stage) throw new Error("Stage is required")
const root = path.resolve(process.cwd(), "..", "..", "..")
2026-01-16 07:21:01 +08:00
const PARTS = 8
2025-11-25 04:24:43 +08:00
// read the secret
const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
const lines = ret.split("\n")
2026-01-16 07:21:01 +08:00
const values = Array.from({ length: PARTS }, (_, i) => {
const value = lines
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
?.split("=")
.slice(1)
.join("=")
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
return value
})
2025-11-25 04:24:43 +08:00
// validate value
2026-01-16 07:21:01 +08:00
ZenData.validate(JSON.parse(values.join("")))
2025-11-25 04:24:43 +08:00
// update the secret
2026-01-16 07:21:01 +08:00
for (let i = 0; i < PARTS; i++) {
await $`bun sst secret set ZEN_MODELS${i + 1} -- ${values[i]}`
}