Loading pkgs/by-name/op/opencode/fix-models-macro.patchdeleted 100644 → 0 +0 −8 Original line number Diff line number Diff line --- a/packages/opencode/src/provider/models-macro.ts +++ b/packages/opencode/src/provider/models-macro.ts @@ -1,4 +1,3 @@ export async function data() { - const json = await fetch("https://models.dev/api.json").then((x) => x.text()) - return json + return process.env.MODELS_JSON || '{}'; } pkgs/by-name/op/opencode/local-models-dev.patch 0 → 100644 +20 −0 Original line number Diff line number Diff line diff --git i/packages/opencode/src/provider/models-macro.ts w/packages/opencode/src/provider/models-macro.ts index 91a0348..4f60069 100644 --- i/packages/opencode/src/provider/models-macro.ts +++ w/packages/opencode/src/provider/models-macro.ts @@ -1,4 +1,15 @@ export async function data() { + const localApiJsonPath = process.env.MODELS_DEV_API_JSON + + // Try to read from local file if path is provided + if (localApiJsonPath) { + const localFile = Bun.file(localApiJsonPath) + if (await localFile.exists()) { + return await localFile.text() + } + } + + // Fallback to fetching from remote URL const json = await fetch("https://models.dev/api.json").then((x) => x.text()) return json } pkgs/by-name/op/opencode/package.nix +10 −11 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ buildGoModule, bun, fetchFromGitHub, fetchurl, models-dev, nix-update-script, testers, writableTmpDirAsHomeHook, Loading Loading @@ -106,17 +106,15 @@ stdenvNoCC.mkDerivation (finalAttrs: { outputHashMode = "recursive"; }; models-dev-data = fetchurl { url = "https://models.dev/api.json"; sha256 = "sha256-igxQOC+Hz2FnXIW/S4Px9WhRuBhcIQIHO+7U8jHU1TQ="; }; nativeBuildInputs = [ bun ]; nativeBuildInputs = [ bun models-dev ]; patches = [ # Patch `packages/opencode/src/provider/models-macro.ts` to load the prefetched `models.dev/api.json` # from the `MODELS_JSON` environment variable instead of fetching it at build time. ./fix-models-macro.patch # Patch `packages/opencode/src/provider/models-macro.ts` to get contents of # `api.json` from the file bundled with `bun build`. ./local-models-dev.patch ]; configurePhase = '' Loading @@ -127,10 +125,11 @@ stdenvNoCC.mkDerivation (finalAttrs: { runHook postConfigure ''; env.MODELS_DEV_API_JSON = "${models-dev}/dist/api.json"; buildPhase = '' runHook preBuild export MODELS_JSON="$(cat ${finalAttrs.models-dev-data})" bun build \ --define OPENCODE_VERSION="'${finalAttrs.version}'" \ --compile \ Loading Loading
pkgs/by-name/op/opencode/fix-models-macro.patchdeleted 100644 → 0 +0 −8 Original line number Diff line number Diff line --- a/packages/opencode/src/provider/models-macro.ts +++ b/packages/opencode/src/provider/models-macro.ts @@ -1,4 +1,3 @@ export async function data() { - const json = await fetch("https://models.dev/api.json").then((x) => x.text()) - return json + return process.env.MODELS_JSON || '{}'; }
pkgs/by-name/op/opencode/local-models-dev.patch 0 → 100644 +20 −0 Original line number Diff line number Diff line diff --git i/packages/opencode/src/provider/models-macro.ts w/packages/opencode/src/provider/models-macro.ts index 91a0348..4f60069 100644 --- i/packages/opencode/src/provider/models-macro.ts +++ w/packages/opencode/src/provider/models-macro.ts @@ -1,4 +1,15 @@ export async function data() { + const localApiJsonPath = process.env.MODELS_DEV_API_JSON + + // Try to read from local file if path is provided + if (localApiJsonPath) { + const localFile = Bun.file(localApiJsonPath) + if (await localFile.exists()) { + return await localFile.text() + } + } + + // Fallback to fetching from remote URL const json = await fetch("https://models.dev/api.json").then((x) => x.text()) return json }
pkgs/by-name/op/opencode/package.nix +10 −11 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ buildGoModule, bun, fetchFromGitHub, fetchurl, models-dev, nix-update-script, testers, writableTmpDirAsHomeHook, Loading Loading @@ -106,17 +106,15 @@ stdenvNoCC.mkDerivation (finalAttrs: { outputHashMode = "recursive"; }; models-dev-data = fetchurl { url = "https://models.dev/api.json"; sha256 = "sha256-igxQOC+Hz2FnXIW/S4Px9WhRuBhcIQIHO+7U8jHU1TQ="; }; nativeBuildInputs = [ bun ]; nativeBuildInputs = [ bun models-dev ]; patches = [ # Patch `packages/opencode/src/provider/models-macro.ts` to load the prefetched `models.dev/api.json` # from the `MODELS_JSON` environment variable instead of fetching it at build time. ./fix-models-macro.patch # Patch `packages/opencode/src/provider/models-macro.ts` to get contents of # `api.json` from the file bundled with `bun build`. ./local-models-dev.patch ]; configurePhase = '' Loading @@ -127,10 +125,11 @@ stdenvNoCC.mkDerivation (finalAttrs: { runHook postConfigure ''; env.MODELS_DEV_API_JSON = "${models-dev}/dist/api.json"; buildPhase = '' runHook preBuild export MODELS_JSON="$(cat ${finalAttrs.models-dev-data})" bun build \ --define OPENCODE_VERSION="'${finalAttrs.version}'" \ --compile \ Loading