pull-models.ts 840 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import path from "path"
  4. import { ZenData } from "../src/model"
  5. const stage = process.argv[2]
  6. if (!stage) throw new Error("Stage is required")
  7. const root = path.resolve(process.cwd(), "..", "..", "..")
  8. const PARTS = 8
  9. // read the secret
  10. const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
  11. const lines = ret.split("\n")
  12. const values = Array.from({ length: PARTS }, (_, i) => {
  13. const value = lines
  14. .find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
  15. ?.split("=")
  16. .slice(1)
  17. .join("=")
  18. if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
  19. return value
  20. })
  21. // validate value
  22. ZenData.validate(JSON.parse(values.join("")))
  23. // update the secret
  24. for (let i = 0; i < PARTS; i++) {
  25. await $`bun sst secret set ZEN_MODELS${i + 1} -- ${values[i]}`
  26. }