2025-09-26 15:18:22 -04:00
|
|
|
#!/usr/bin/env bun
|
|
|
|
|
|
|
|
|
|
import { $ } from "bun"
|
|
|
|
|
import path from "path"
|
|
|
|
|
import os from "os"
|
2025-10-16 15:58:49 -04:00
|
|
|
import { ZenData } from "../src/model"
|
2025-09-26 15:18:22 -04:00
|
|
|
|
|
|
|
|
const root = path.resolve(process.cwd(), "..", "..", "..")
|
2026-03-31 00:07:54 -04:00
|
|
|
const models = await $`bun sst secret list --stage frank`.cwd(root).text()
|
2026-02-17 01:32:57 -05:00
|
|
|
const PARTS = 30
|
2025-09-26 15:18:22 -04:00
|
|
|
|
|
|
|
|
// read the line starting with "ZEN_MODELS"
|
2025-11-21 12:50:51 -05:00
|
|
|
const lines = models.split("\n")
|
2026-01-15 18:21:01 -05:00
|
|
|
const oldValues = Array.from({ length: PARTS }, (_, i) => {
|
|
|
|
|
const value = lines
|
2026-01-30 12:19:36 -05:00
|
|
|
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}=`))
|
2026-01-15 18:21:01 -05:00
|
|
|
?.split("=")
|
|
|
|
|
.slice(1)
|
|
|
|
|
.join("=")
|
2026-02-04 20:56:34 -05:00
|
|
|
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
|
|
|
|
|
return value
|
2026-01-15 18:21:01 -05:00
|
|
|
})
|
2025-09-26 15:18:22 -04:00
|
|
|
|
|
|
|
|
// store the prettified json to a temp file
|
|
|
|
|
const filename = `models-${Date.now()}.json`
|
|
|
|
|
const tempFile = Bun.file(path.join(os.tmpdir(), filename))
|
2026-01-15 18:21:01 -05:00
|
|
|
await tempFile.write(JSON.stringify(JSON.parse(oldValues.join("")), null, 2))
|
2025-09-26 15:18:22 -04:00
|
|
|
console.log("tempFile", tempFile.name)
|
|
|
|
|
|
|
|
|
|
// open temp file in vim and read the file on close
|
|
|
|
|
await $`vim ${tempFile.name}`
|
2025-11-03 15:43:52 -05:00
|
|
|
const newValue = JSON.stringify(JSON.parse(await tempFile.text()))
|
|
|
|
|
ZenData.validate(JSON.parse(newValue))
|
2025-09-26 15:18:22 -04:00
|
|
|
|
|
|
|
|
// update the secret
|
2026-01-15 18:21:01 -05:00
|
|
|
const chunk = Math.ceil(newValue.length / PARTS)
|
|
|
|
|
const newValues = Array.from({ length: PARTS }, (_, i) =>
|
|
|
|
|
newValue.slice(chunk * i, i === PARTS - 1 ? undefined : chunk * (i + 1)),
|
|
|
|
|
)
|
2025-12-11 23:41:04 -05:00
|
|
|
|
2026-01-30 12:19:36 -05:00
|
|
|
const envFile = Bun.file(path.join(os.tmpdir(), `models-${Date.now()}.env`))
|
2026-02-07 13:32:19 -05:00
|
|
|
await envFile.write(newValues.map((v, i) => `ZEN_MODELS${i + 1}="${v.replace(/"/g, '\\"')}"`).join("\n"))
|
2026-03-31 00:07:54 -04:00
|
|
|
await $`bun sst secret load ${envFile.name} --stage frank`.cwd(root)
|