feat: Make the models.dev domain configurable for offline environments (#9258)

This commit is contained in:
Bart Broere
2026-01-21 18:23:07 +01:00
committed by GitHub
parent 95b17bcf5e
commit 8df09abb1b
5 changed files with 18 additions and 6 deletions

View File

@@ -22,6 +22,10 @@ export namespace Global {
cache,
config,
state,
// Allow overriding models.dev URL for offline deployments
get modelsDevUrl() {
return process.env.OPENCODE_MODELS_URL || "https://models.dev"
},
}
}

View File

@@ -1,3 +1,5 @@
import { Global } from "../global"
export async function data() {
const path = Bun.env.MODELS_DEV_API_JSON
if (path) {
@@ -6,6 +8,7 @@ export async function data() {
return await file.text()
}
}
const json = await fetch("https://models.dev/api.json").then((x) => x.text())
const url = Global.Path.modelsDevUrl
const json = await fetch(`${url}/api.json`).then((x) => x.text())
return json
}

View File

@@ -85,7 +85,8 @@ export namespace ModelsDev {
const json = await data()
return JSON.parse(json) as Record<string, Provider>
}
const json = await fetch("https://models.dev/api.json").then((x) => x.text())
const url = Global.Path.modelsDevUrl
const json = await fetch(`${url}/api.json`).then((x) => x.text())
return JSON.parse(json) as Record<string, Provider>
}
@@ -95,7 +96,8 @@ export namespace ModelsDev {
log.info("refreshing", {
file,
})
const result = await fetch("https://models.dev/api.json", {
const url = Global.Path.modelsDevUrl
const result = await fetch(`${url}/api.json`, {
headers: {
"User-Agent": Installation.USER_AGENT,
},