mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
feat: Make the models.dev domain configurable for offline environments (#9258)
This commit is contained in:
@@ -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"
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import fsSync from "fs"
|
||||
import { afterAll } from "bun:test"
|
||||
const { Global } = await import("../src/global")
|
||||
|
||||
const dir = path.join(os.tmpdir(), "opencode-test-data-" + process.pid)
|
||||
await fs.mkdir(dir, { recursive: true })
|
||||
@@ -27,7 +28,8 @@ process.env["XDG_STATE_HOME"] = path.join(dir, "state")
|
||||
const cacheDir = path.join(dir, "cache", "opencode")
|
||||
await fs.mkdir(cacheDir, { recursive: true })
|
||||
await fs.writeFile(path.join(cacheDir, "version"), "14")
|
||||
const response = await fetch("https://models.dev/api.json")
|
||||
const url = Global.Path.modelsDevUrl
|
||||
const response = await fetch(`${url}/api.json`)
|
||||
if (response.ok) {
|
||||
await fs.writeFile(path.join(cacheDir, "models.json"), await response.text())
|
||||
}
|
||||
|
||||
@@ -45,12 +45,13 @@ function providerIconsPlugin() {
|
||||
}
|
||||
|
||||
async function fetchProviderIcons() {
|
||||
const providers = await fetch("https://models.dev/api.json")
|
||||
const url = process.env.OPENCODE_MODELS_URL || "https://models.dev"
|
||||
const providers = await fetch(`${url}/api.json`)
|
||||
.then((res) => res.json())
|
||||
.then((json) => Object.keys(json))
|
||||
await Promise.all(
|
||||
providers.map((provider) =>
|
||||
fetch(`https://models.dev/logos/${provider}.svg`)
|
||||
fetch(`${url}/logos/${provider}.svg`)
|
||||
.then((res) => res.text())
|
||||
.then((svg) => fs.writeFileSync(`./src/assets/icons/provider/${provider}.svg`, svg)),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user