|
|
@@ -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 snapshot
|
|
|
if (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()
|