core: fix models snapshot loading to prevent caching issues
This commit is contained in:
@@ -9,9 +9,6 @@ import { lazy } from "@/util/lazy"
|
|||||||
// Try to import bundled snapshot (generated at build time)
|
// Try to import bundled snapshot (generated at build time)
|
||||||
// Falls back to undefined in dev mode when snapshot doesn't exist
|
// Falls back to undefined in dev mode when snapshot doesn't exist
|
||||||
/* @ts-ignore */
|
/* @ts-ignore */
|
||||||
const SNAPSHOT = await import("./models-snapshot")
|
|
||||||
.then((m) => m.snapshot as Record<string, unknown>)
|
|
||||||
.catch(() => undefined)
|
|
||||||
|
|
||||||
export namespace ModelsDev {
|
export namespace ModelsDev {
|
||||||
const log = Log.create({ service: "models.dev" })
|
const log = Log.create({ service: "models.dev" })
|
||||||
@@ -91,14 +88,16 @@ export namespace ModelsDev {
|
|||||||
const file = Bun.file(filepath)
|
const file = Bun.file(filepath)
|
||||||
const result = await file.json().catch(() => {})
|
const result = await file.json().catch(() => {})
|
||||||
if (result) return result
|
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 {}
|
if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return {}
|
||||||
const json = await fetch(`${url()}/api.json`).then((x) => x.text())
|
const json = await fetch(`${url()}/api.json`).then((x) => x.text())
|
||||||
return JSON.parse(json)
|
return JSON.parse(json)
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function get() {
|
export async function get() {
|
||||||
refresh()
|
|
||||||
const result = await Data()
|
const result = await Data()
|
||||||
return result as Record<string, Provider>
|
return result as Record<string, Provider>
|
||||||
}
|
}
|
||||||
@@ -127,6 +126,7 @@ export namespace ModelsDev {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Flag.OPENCODE_DISABLE_MODELS_FETCH) {
|
if (!Flag.OPENCODE_DISABLE_MODELS_FETCH) {
|
||||||
|
ModelsDev.refresh()
|
||||||
setInterval(
|
setInterval(
|
||||||
async () => {
|
async () => {
|
||||||
await ModelsDev.refresh()
|
await ModelsDev.refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user