Download packages/console/core/script/update-limits.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/4bbfe8b25e2b3fcaec1aee78c50a8a29306735ca/packages/console/core/script/update-limits.ts
- Command line
-
hf download hf://SaylorTwift/opencode@4bbfe8b25e2b3fcaec1aee78c50a8a29306735ca/packages/console/core/script/update-limits.ts
-
curl -L -o update-limits.ts https://huggingface.co/SaylorTwift/opencode/resolve/4bbfe8b25e2b3fcaec1aee78c50a8a29306735ca/packages/console/core/script/update-limits.ts
1.15 kB
| import { $ } from "bun" | |
| import path from "path" | |
| import os from "os" | |
| import { Subscription } from "../src/subscription" | |
| const root = path.resolve(process.cwd(), "..", "..", "..") | |
| const secrets = await $`bun sst secret list --fallback`.cwd(root).text() | |
| // read value | |
| const lines = secrets.split("\n") | |
| const oldValue = lines.find((line) => line.startsWith("ZEN_LIMITS"))?.split("=")[1] ?? "{}" | |
| if (!oldValue) throw new Error("ZEN_LIMITS not found") | |
| // store the prettified json to a temp file | |
| const filename = `limits-${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.stringify(JSON.parse(await tempFile.text())) | |
| Subscription.validate(JSON.parse(newValue)) | |
| // update the secret | |
| const envFile = Bun.file(path.join(os.tmpdir(), `limits-${Date.now()}.env`)) | |
| await envFile.write(`ZEN_LIMITS="${newValue.replace(/"/g, '\\"')}"`) | |
| await $`bun sst secret load ${envFile.name} --fallback`.cwd(root) | |