From 05232ead938b7cc7dcf75afa9470effef0ed4251 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 3 Nov 2025 15:43:52 -0500 Subject: zen: wip --- packages/console/core/script/promote-models.ts | 16 +++-- packages/console/core/script/update-models.ts | 22 +++--- packages/console/core/src/model.ts | 6 +- packages/console/core/sst-env.d.ts | 97 +++++++++++++++++++++++++- 4 files changed, 125 insertions(+), 16 deletions(-) (limited to 'packages/console/core') diff --git a/packages/console/core/script/promote-models.ts b/packages/console/core/script/promote-models.ts index 67c2b6f3e..717813e40 100755 --- a/packages/console/core/script/promote-models.ts +++ b/packages/console/core/script/promote-models.ts @@ -11,14 +11,20 @@ const root = path.resolve(process.cwd(), "..", "..", "..") // read the secret const ret = await $`bun sst secret list`.cwd(root).text() -const value = ret +const value1 = ret .split("\n") - .find((line) => line.startsWith("ZEN_MODELS")) + .find((line) => line.startsWith("ZEN_MODELS1")) ?.split("=")[1] -if (!value) throw new Error("ZEN_MODELS not found") +const value2 = ret + .split("\n") + .find((line) => line.startsWith("ZEN_MODELS2")) + ?.split("=")[1] +if (!value1) throw new Error("ZEN_MODELS1 not found") +if (!value2) throw new Error("ZEN_MODELS2 not found") // validate value -ZenData.validate(JSON.parse(value)) +ZenData.validate(JSON.parse(value1 + value2)) // update the secret -await $`bun sst secret set ZEN_MODELS ${value} --stage ${stage}` +await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}` +await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}` diff --git a/packages/console/core/script/update-models.ts b/packages/console/core/script/update-models.ts index 939af616e..e7a245515 100755 --- a/packages/console/core/script/update-models.ts +++ b/packages/console/core/script/update-models.ts @@ -10,23 +10,29 @@ const models = await $`bun sst secret list`.cwd(root).text() console.log("models", models) // read the line starting with "ZEN_MODELS" -const oldValue = models +const oldValue1 = models .split("\n") - .find((line) => line.startsWith("ZEN_MODELS")) + .find((line) => line.startsWith("ZEN_MODELS1")) ?.split("=")[1] -if (!oldValue) throw new Error("ZEN_MODELS not found") -console.log("oldValue", oldValue) +const oldValue2 = models + .split("\n") + .find((line) => line.startsWith("ZEN_MODELS2")) + ?.split("=")[1] +if (!oldValue1) throw new Error("ZEN_MODELS1 not found") +if (!oldValue2) throw new Error("ZEN_MODELS2 not found") // 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)) +await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2), 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()) -ZenData.validate(newValue) +const newValue = JSON.stringify(JSON.parse(await tempFile.text())) +ZenData.validate(JSON.parse(newValue)) // update the secret -await $`bun sst secret set ZEN_MODELS ${JSON.stringify(newValue)}` +const mid = Math.floor(newValue.length / 2) +await $`bun sst secret set ZEN_MODELS1 ${newValue.slice(0, mid)}` +await $`bun sst secret set ZEN_MODELS2 ${newValue.slice(mid)}` diff --git a/packages/console/core/src/model.ts b/packages/console/core/src/model.ts index 300f92ed0..118f7401d 100644 --- a/packages/console/core/src/model.ts +++ b/packages/console/core/src/model.ts @@ -47,7 +47,7 @@ export namespace ZenData { }) export const list = fn(z.void(), () => { - const json = JSON.parse(Resource.ZEN_MODELS.value) + const json = JSON.parse(Resource.ZEN_MODELS1.value + Resource.ZEN_MODELS2.value) return ModelsSchema.parse(json) }) } @@ -56,7 +56,9 @@ export namespace Model { export const enable = fn(z.object({ model: z.string() }), ({ model }) => { Actor.assertAdmin() return Database.use((db) => - db.delete(ModelTable).where(and(eq(ModelTable.workspaceID, Actor.workspace()), eq(ModelTable.model, model))), + db + .delete(ModelTable) + .where(and(eq(ModelTable.workspaceID, Actor.workspace()), eq(ModelTable.model, model))), ) }) diff --git a/packages/console/core/sst-env.d.ts b/packages/console/core/sst-env.d.ts index 9b9de7327..01407434e 100644 --- a/packages/console/core/sst-env.d.ts +++ b/packages/console/core/sst-env.d.ts @@ -3,7 +3,102 @@ /* eslint-disable */ /* deno-fmt-ignore-file */ -/// +import "sst" +declare module "sst" { + export interface Resource { + "ADMIN_SECRET": { + "type": "sst.sst.Secret" + "value": string + } + "AUTH_API_URL": { + "type": "sst.sst.Linkable" + "value": string + } + "AWS_SES_ACCESS_KEY_ID": { + "type": "sst.sst.Secret" + "value": string + } + "AWS_SES_SECRET_ACCESS_KEY": { + "type": "sst.sst.Secret" + "value": string + } + "Console": { + "type": "sst.cloudflare.SolidStart" + "url": string + } + "Database": { + "database": string + "host": string + "password": string + "port": number + "type": "sst.sst.Linkable" + "username": string + } + "Desktop": { + "type": "sst.cloudflare.StaticSite" + "url": string + } + "EMAILOCTOPUS_API_KEY": { + "type": "sst.sst.Secret" + "value": string + } + "GITHUB_APP_ID": { + "type": "sst.sst.Secret" + "value": string + } + "GITHUB_APP_PRIVATE_KEY": { + "type": "sst.sst.Secret" + "value": string + } + "GITHUB_CLIENT_ID_CONSOLE": { + "type": "sst.sst.Secret" + "value": string + } + "GITHUB_CLIENT_SECRET_CONSOLE": { + "type": "sst.sst.Secret" + "value": string + } + "GOOGLE_CLIENT_ID": { + "type": "sst.sst.Secret" + "value": string + } + "HONEYCOMB_API_KEY": { + "type": "sst.sst.Secret" + "value": string + } + "STRIPE_SECRET_KEY": { + "type": "sst.sst.Secret" + "value": string + } + "STRIPE_WEBHOOK_SECRET": { + "type": "sst.sst.Linkable" + "value": string + } + "Web": { + "type": "sst.cloudflare.Astro" + "url": string + } + "ZEN_MODELS1": { + "type": "sst.sst.Secret" + "value": string + } + "ZEN_MODELS2": { + "type": "sst.sst.Secret" + "value": string + } + } +} +// cloudflare +import * as cloudflare from "@cloudflare/workers-types"; +declare module "sst" { + export interface Resource { + "Api": cloudflare.Service + "AuthApi": cloudflare.Service + "AuthStorage": cloudflare.KVNamespace + "Bucket": cloudflare.R2Bucket + "LogProcessor": cloudflare.Service + } +} import "sst" export {} \ No newline at end of file -- cgit v1.2.3