The open source coding agent.
TypeScript
core: fix models snapshot loading to prevent caching issues
Dax Raad68bd16df696d
diff --git a/packages/opencode/src/provider/models.ts b/packages/opencode/src/provider/models.tsindex 68eac37f2c4..1db2e589e45 100644--- a/packages/opencode/src/provider/models.ts+++ b/packages/opencode/src/provider/models.ts@@ -9,9 +9,6 @@ import { lazy } from "@/util/lazy"// Try to import bundled snapshot (generated at build time)// Falls back to undefined in dev mode when snapshot doesn't exist/* @ts-ignore */-const SNAPSHOT = await import("./models-snapshot")- .then((m) => m.snapshot as Record<string, unknown>)- .catch(() => undefined)export namespace ModelsDev {const log = Log.create({ service: "models.dev" })@@ -91,14 +88,16 @@ export namespace ModelsDev {const file = Bun.file(filepath)const result = await file.json().catch(() => {})if (result) return result- if (SNAPSHOT) return SNAPSHOT+ const snapshot = await import("./models-snapshot")+ .then((m) => m.snapshot as Record<string, unknown>)+ .catch(() => undefined)+ if (snapshot) return snapshotif (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}const json = await fetch(`${url()}/api.json`).then((x) => x.text())return JSON.parse(json)})export async function get() {- refresh()const result = await Data()return result as Record<string, Provider>}@@ -127,6 +126,7 @@ export namespace ModelsDev {}if (!Flag.OPENCODE_DISABLE_MODELS_FETCH) {+ ModelsDev.refresh()setInterval(async () => {await ModelsDev.refresh()