diff options
Diffstat (limited to 'packages/console/core/script')
| -rwxr-xr-x | packages/console/core/script/promote-models.ts | 24 | ||||
| -rwxr-xr-x | packages/console/core/script/update-models.ts | 32 |
2 files changed, 56 insertions, 0 deletions
diff --git a/packages/console/core/script/promote-models.ts b/packages/console/core/script/promote-models.ts new file mode 100755 index 000000000..1a5cf2fde --- /dev/null +++ b/packages/console/core/script/promote-models.ts @@ -0,0 +1,24 @@ +#!/usr/bin/env bun + +import { $ } from "bun" +import path from "path" +import { ZenModel } from "../src/model" + +const stage = process.argv[2] +if (!stage) throw new Error("Stage is required") + +const root = path.resolve(process.cwd(), "..", "..", "..") + +// read the secret +const ret = await $`bun sst secret list`.cwd(root).text() +const value = ret + .split("\n") + .find((line) => line.startsWith("ZEN_MODELS")) + ?.split("=")[1] +if (!value) throw new Error("ZEN_MODELS not found") + +// validate value +ZenModel.ModelsSchema.parse(JSON.parse(value)) + +// update the secret +await $`bun sst secret set ZEN_MODELS ${value} --stage ${stage}` diff --git a/packages/console/core/script/update-models.ts b/packages/console/core/script/update-models.ts new file mode 100755 index 000000000..7740fdcf8 --- /dev/null +++ b/packages/console/core/script/update-models.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env bun + +import { $ } from "bun" +import path from "path" +import os from "os" +import { ZenModel } from "../src/model" + +const root = path.resolve(process.cwd(), "..", "..", "..") +const models = await $`bun sst secret list`.cwd(root).text() +console.log("models", models) + +// read the line starting with "ZEN_MODELS" +const oldValue = models + .split("\n") + .find((line) => line.startsWith("ZEN_MODELS")) + ?.split("=")[1] +if (!oldValue) throw new Error("ZEN_MODELS not found") +console.log("oldValue", oldValue) + +// store the prettified json to a temp file +const filename = `models-${Date.now()}.json` +const tempFile = Bun.file(path.join(os.tmpdir(), filename)) +await tempFile.write(JSON.stringify(JSON.parse(oldValue), null, 2)) +console.log("tempFile", tempFile.name) + +// open temp file in vim and read the file on close +await $`vim ${tempFile.name}` +const newValue = JSON.parse(await tempFile.text()) +ZenModel.ModelsSchema.parse(newValue) + +// update the secret +await $`bun sst secret set ZEN_MODELS ${JSON.stringify(newValue)}` |
