update-models.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import path from "path"
  4. import os from "os"
  5. import { ZenData } from "../src/model"
  6. const root = path.resolve(process.cwd(), "..", "..", "..")
  7. const models = await $`bun sst secret list`.cwd(root).text()
  8. console.log("models", models)
  9. // read the line starting with "ZEN_MODELS"
  10. const oldValue = models
  11. .split("\n")
  12. .find((line) => line.startsWith("ZEN_MODELS"))
  13. ?.split("=")[1]
  14. if (!oldValue) throw new Error("ZEN_MODELS not found")
  15. console.log("oldValue", oldValue)
  16. // store the prettified json to a temp file
  17. const filename = `models-${Date.now()}.json`
  18. const tempFile = Bun.file(path.join(os.tmpdir(), filename))
  19. await tempFile.write(JSON.stringify(JSON.parse(oldValue), null, 2))
  20. console.log("tempFile", tempFile.name)
  21. // open temp file in vim and read the file on close
  22. await $`vim ${tempFile.name}`
  23. const newValue = JSON.parse(await tempFile.text())
  24. ZenData.validate(newValue)
  25. // update the secret
  26. await $`bun sst secret set ZEN_MODELS ${JSON.stringify(newValue)}`