From b8fc8b293432e1150b347545cb92226f22072b6e Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 18 Nov 2026 19:02:57 +0100 Subject: [PATCH 1/2] fix(embeddings): fetch the native ONNX Runtime from NuGet, GitHub's copy is gone github.com/microsoft/onnxruntime answers 404 since 17.11.2026 (repo, API and every release download), so `models download` could not install the native library on Linux and macOS and the models fell back to WebAssembly. The Native runtime CI job failed on every PR. The library now comes from Microsoft's NuGet package Microsoft.ML.OnnxRuntime 1.30.0. One HTTP Range request fetches only the deflated bytes of this system's library out of the 157 MB zip; installFiles checks the slice's size and sha256, fflate inflates it, and the library's own sha256 is checked as before. A published NuGet version never changes, and the package signature nuget.org may replace is the zip's last file, so the pinned offsets hold. - linux-x64, linux-arm64: the same library bytes as the GitHub release. - darwin-arm64: NuGet's own build of 1.30.0, same size and install name (@rpath/libonnxruntime.1.dylib), new sha256. - Windows keeps onnxruntime-node's npm tarball. ModelFile gains an optional `offset`, sent as a Range header. The package's probe-native.mjs takes the same slices. Co-Authored-By: Claude Opus 5.5 --- changes/fix-ort-native-source.md | 8 +++ packages/onnx/README.md | 7 ++- packages/onnx/probe-native.mjs | 93 +++++++++++++++-------------- src/embeddings/onnx-runtime.test.ts | 29 ++++++++- src/embeddings/onnx-runtime.ts | 60 +++++++++++-------- src/speech/install.ts | 9 ++- src/speech/models.ts | 2 + 7 files changed, 131 insertions(+), 77 deletions(-) create mode 100644 changes/fix-ort-native-source.md diff --git a/changes/fix-ort-native-source.md b/changes/fix-ort-native-source.md new file mode 100644 index 000000000..97e2aeeb3 --- /dev/null +++ b/changes/fix-ort-native-source.md @@ -0,0 +1,8 @@ +### Fixed + +- **`models download` installs the native ONNX Runtime again on Linux and macOS.** Microsoft's GitHub repository, and + every release download in it, answers 404 since 17.11.2026, so the download failed and the models ran through + WebAssembly. The library now comes from Microsoft's NuGet package `Microsoft.ML.OnnxRuntime` 1.30.0: one HTTP Range + request fetches only that system's library out of the 157 MB package, 10–12.5 MB. The Linux libraries are byte for + byte the ones from the GitHub release; the macOS one is NuGet's own build of the same version, with a new sha256. + Windows still takes its library from `onnxruntime-node`'s npm tarball. diff --git a/packages/onnx/README.md b/packages/onnx/README.md index 29d77c787..db8afe488 100644 --- a/packages/onnx/README.md +++ b/packages/onnx/README.md @@ -6,9 +6,10 @@ about 15 MB instead of the 145 MB package that also carries every browser build. - **Native**, 2–3× faster, on Linux x64 and arm64 (glibc), macOS arm64 and Windows x64 and arm64: `onnxruntime-node`'s JavaScript and the 0.3–0.4 MB binding of each of those systems, without its libraries. - `@wirecat/cli-core` downloads the library beside a copy of the binding, which loads it from its own folder: from Microsoft's release of - the same version, and on Windows from `onnxruntime-node`'s own npm tarball, because the Windows binding needs the - DirectML build of `onnxruntime.dll` (export ordinal 4) that Microsoft's CPU release does not carry. + `@wirecat/cli-core` downloads the library beside a copy of the binding, which loads it from its own folder: from + Microsoft's NuGet package of the same version, and on Windows from `onnxruntime-node`'s own npm tarball, because the + Windows binding needs the DirectML build of `onnxruntime.dll` (export ordinal 4) that Microsoft's CPU release does + not carry. ```js import { env, InferenceSession, Tensor } from "@wirecat/cli-core-onnx" // WebAssembly diff --git a/packages/onnx/probe-native.mjs b/packages/onnx/probe-native.mjs index 3da49e185..4b5b4cec0 100644 --- a/packages/onnx/probe-native.mjs +++ b/packages/onnx/probe-native.mjs @@ -1,63 +1,64 @@ // Runs the one-node model through the native binding of this system, beside the ONNX Runtime library -// @wirecat/cli-core downloads — from Microsoft's release, or on Windows from onnxruntime-node's npm tarball, whose -// DirectML build of onnxruntime.dll the binding needs: `node probe-native.mjs` and `bun probe-native.mjs`. +// @wirecat/cli-core downloads — from Microsoft's NuGet package, or on Windows from onnxruntime-node's npm tarball, +// whose DirectML build of onnxruntime.dll the binding needs: `node probe-native.mjs` and `bun probe-native.mjs`. import { execFileSync } from "node:child_process" import { createHash } from "node:crypto" import { copyFileSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" +import { inflateRawSync } from "node:zlib" import { nativeBindingFor, ONNX_RUNTIME_VERSION, openNative } from "@wirecat/cli-core-onnx" -const release = `https://github.com/microsoft/onnxruntime/releases/download/v${ONNX_RUNTIME_VERSION}` -const npm = "https://registry.npmjs.org/onnxruntime-node/-" -const archives = { - "linux-x64": [ - "onnxruntime-linux-x64-1.30.0.tgz", - "a5ed5a3cac51fbb2e90da632ae43d19212faaa20e76484e62bcb7c23ddb3b3fd", - "onnxruntime-linux-x64-1.30.0/lib/libonnxruntime.so.1.30.0", - "libonnxruntime.so.1", - ], - "linux-arm64": [ - "onnxruntime-linux-aarch64-1.30.0.tgz", - "e16a27a8ed330bbc698df7330b0cf56e722f354e3bcc92118682c74ef3c3e3da", - "onnxruntime-linux-aarch64-1.30.0/lib/libonnxruntime.so.1.30.0", - "libonnxruntime.so.1", - ], - "darwin-arm64": [ - "onnxruntime-osx-arm64-1.30.0.tgz", - "6ebb5062a934537c352937821f9fe9718e7de1a2db1122a93dd363ffd53a7012", - "./onnxruntime-osx-arm64-1.30.0/lib/libonnxruntime.1.30.0.dylib", - "libonnxruntime.1.dylib", - ], - "win32-x64": [ - "onnxruntime-node-1.30.0.tgz", - "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75", - "package/bin/napi-v6/win32/x64/onnxruntime.dll", - "onnxruntime.dll", - ], - "win32-arm64": [ - "onnxruntime-node-1.30.0.tgz", - "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75", - "package/bin/napi-v6/win32/arm64/onnxruntime.dll", - "onnxruntime.dll", - ], +const nuget = + `https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ONNX_RUNTIME_VERSION}` + + `/microsoft.ml.onnxruntime.${ONNX_RUNTIME_VERSION}.nupkg` +const npm = `https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz` +const npmSha256 = "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75" +// Each library's deflated bytes in the NuGet zip, or its path in the npm tarball, and the name the binding loads. +const sources = { + "linux-x64": { + offset: 121_160_280, + sha256: "6f7d1ee67f9c7d3e5d1b009492aef02d2833ba16a4a896b71438b20abfe4293a", + bytes: 11_061_061, + library: "libonnxruntime.so.1", + }, + "linux-arm64": { + offset: 111_131_974, + sha256: "4e8adcdf8582ff74925989b0e009efa808723b23ec297eae4acaababe0ffad8f", + bytes: 10_026_119, + library: "libonnxruntime.so.1", + }, + "darwin-arm64": { + offset: 132_223_187, + sha256: "d9f60cc9c7af596e5114a0dbb3afdc62eaa93de0236ce6e6aa4500ace7b39c0a", + bytes: 12_536_089, + library: "libonnxruntime.1.dylib", + }, + "win32-x64": { member: "package/bin/napi-v6/win32/x64/onnxruntime.dll", library: "onnxruntime.dll" }, + "win32-arm64": { member: "package/bin/napi-v6/win32/arm64/onnxruntime.dll", library: "onnxruntime.dll" }, } const target = `${process.platform}-${process.arch}` -const [name, sha256, member, library] = archives[target] ?? [] -if (!name) throw new Error(`no ONNX Runtime archive for ${target}`) +const source = sources[target] +if (!source) throw new Error(`no ONNX Runtime library for ${target}`) const binding = nativeBindingFor() if (!binding) throw new Error(`the package carries no binding for ${target}`) -const work = mkdtempSync(join(tmpdir(), "onnx-native-")) -const archive = Buffer.from( - await (await fetch(`${process.platform === "win32" ? npm : release}/${name}`)).arrayBuffer(), -) -const actual = createHash("sha256").update(archive).digest("hex") -if (actual !== sha256) throw new Error(`${name} is not the file expected (sha256 ${actual})`) -writeFileSync(join(work, name), archive) -execFileSync("tar", ["-xf", name, member], { cwd: work }) const folder = mkdtempSync(join(tmpdir(), "onnx-runtime-")) -copyFileSync(join(work, member), join(folder, library)) +if (source.member) { + const archive = Buffer.from(await (await fetch(npm)).arrayBuffer()) + const actual = createHash("sha256").update(archive).digest("hex") + if (actual !== npmSha256) throw new Error(`the npm tarball is not the file expected (sha256 ${actual})`) + const work = mkdtempSync(join(tmpdir(), "onnx-native-")) + writeFileSync(join(work, "npm.tgz"), archive) + execFileSync("tar", ["-xf", "npm.tgz", source.member], { cwd: work }) + copyFileSync(join(work, source.member), join(folder, source.library)) +} else { + const range = `bytes=${source.offset}-${source.offset + source.bytes - 1}` + const slice = Buffer.from(await (await fetch(nuget, { headers: { Range: range } })).arrayBuffer()) + const actual = createHash("sha256").update(slice).digest("hex") + if (actual !== source.sha256) throw new Error(`the NuGet slice is not the one expected (sha256 ${actual})`) + writeFileSync(join(folder, source.library), inflateRawSync(slice)) +} copyFileSync(binding, join(folder, "onnxruntime_binding.node")) const { InferenceSession, Tensor } = openNative(join(folder, "onnxruntime_binding.node")) diff --git a/src/embeddings/onnx-runtime.test.ts b/src/embeddings/onnx-runtime.test.ts index 544e0ce66..fde8b25f2 100644 --- a/src/embeddings/onnx-runtime.test.ts +++ b/src/embeddings/onnx-runtime.test.ts @@ -3,7 +3,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from import { tmpdir } from "node:os" import { join } from "node:path" import { ONNX_RUNTIME_VERSION as PACKAGE_VERSION } from "@wirecat/cli-core-onnx" -import { gzipSync } from "fflate" +import { deflateSync, gzipSync } from "fflate" import { afterEach, describe, expect, it, vi } from "vitest" import { installNativeRuntime, @@ -94,6 +94,33 @@ describe("the native ONNX Runtime", () => { expect(fetch).toHaveBeenCalledTimes(1) }) + it("is installed out of one ranged slice of a zip, the library alone, deflated", async () => { + const slice = deflateSync(library) + const runtime: NativeRuntime = { + target: "test-x64", + archive: { + name: "library.deflate", + url: "https://example.test/p.nupkg", + offset: 1000, + sha256: sha256(slice), + bytes: slice.length, + }, + library: { name: "libonnxruntime.test", sha256: sha256(library), bytes: library.length }, + } + const env = { WIRECAT_STATE_DIR: mkdtempSync(join(tmpdir(), "runtime-")) } + const fetch = fetchOf(slice) + + const folder = await installNativeRuntime({ env, fetch, runtime, binding: binding() }) + + expect(readFileSync(join(folder as string, "libonnxruntime.test"))).toEqual(Buffer.from(library)) + expect(fetch).toHaveBeenCalledWith( + "https://example.test/p.nupkg", + expect.objectContaining({ + headers: { Range: `bytes=1000-${1000 + slice.length - 1}` }, + }), + ) + }) + it("installs nothing when the archive holds another library", async () => { const member = "onnxruntime-linux-x64-1.30.0/lib/libonnxruntime.so.1.30.0" const archive = gzipSync(tarOf([{ name: member, data: new TextEncoder().encode("another library") }])) diff --git a/src/embeddings/onnx-runtime.ts b/src/embeddings/onnx-runtime.ts index 5c4227190..43172233a 100644 --- a/src/embeddings/onnx-runtime.ts +++ b/src/embeddings/onnx-runtime.ts @@ -11,7 +11,7 @@ import { } from "node:fs" import { join } from "node:path" import { CliError } from "@wirecat/cli-base" -import { gunzipSync } from "fflate" +import { gunzipSync, inflateSync } from "fflate" import { type Fetch, installFiles, megabytes, sharedModelsDirectory } from "../speech/install.js" import type { ModelFile } from "../speech/models.js" @@ -21,13 +21,22 @@ export const ONNX_RUNTIME_VERSION = "1.30.0" export interface NativeRuntime { readonly target: string readonly archive: ModelFile - readonly member: string + /** The library's path in a tar archive; absent when `archive` is the library alone, deflated, out of a zip. */ + readonly member?: string readonly library: { name: string; sha256: string; bytes: number } } -const release = (name: string, sha256: string, bytes: number): ModelFile => ({ - name, - url: `https://github.com/microsoft/onnxruntime/releases/download/v${ONNX_RUNTIME_VERSION}/${name}`, +const NUGET = "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime" + +/** + * One library out of Microsoft's NuGet package, fetched alone by where its deflated bytes sit in the 157 MB zip: a + * version on nuget.org never changes, and the package signature, which nuget.org may replace, is its last file. + * Microsoft's GitHub releases went away on 17.11.2026. + */ +const nuget = (target: string, offset: number, sha256: string, bytes: number): ModelFile => ({ + name: `onnxruntime-${ONNX_RUNTIME_VERSION}-${target}.deflate`, + url: `${NUGET}/${ONNX_RUNTIME_VERSION}/microsoft.ml.onnxruntime.${ONNX_RUNTIME_VERSION}.nupkg`, + offset, sha256, bytes, }) @@ -46,12 +55,12 @@ const npmTarball: ModelFile = { /** The systems the native-runtime workflow runs natively; elsewhere, and on musl, the models run through WebAssembly. */ const NATIVE: Record> = { "linux-x64": { - archive: release( - "onnxruntime-linux-x64-1.30.0.tgz", - "a5ed5a3cac51fbb2e90da632ae43d19212faaa20e76484e62bcb7c23ddb3b3fd", - 11_306_877, + archive: nuget( + "linux-x64", + 121_160_280, + "6f7d1ee67f9c7d3e5d1b009492aef02d2833ba16a4a896b71438b20abfe4293a", + 11_061_061, ), - member: "onnxruntime-linux-x64-1.30.0/lib/libonnxruntime.so.1.30.0", library: { name: "libonnxruntime.so.1", sha256: "245a6f8c38127551057a1cd1ffd59f0a186a227ade4f3492dea2494eb565542e", @@ -59,12 +68,12 @@ const NATIVE: Record> = { }, }, "linux-arm64": { - archive: release( - "onnxruntime-linux-aarch64-1.30.0.tgz", - "e16a27a8ed330bbc698df7330b0cf56e722f354e3bcc92118682c74ef3c3e3da", - 10_269_495, + archive: nuget( + "linux-arm64", + 111_131_974, + "4e8adcdf8582ff74925989b0e009efa808723b23ec297eae4acaababe0ffad8f", + 10_026_119, ), - member: "onnxruntime-linux-aarch64-1.30.0/lib/libonnxruntime.so.1.30.0", library: { name: "libonnxruntime.so.1", sha256: "64e903a43a041240fd6bcffe0ac6d4fea47ef87bf24b9d097801bd00a9612a4b", @@ -72,15 +81,15 @@ const NATIVE: Record> = { }, }, "darwin-arm64": { - archive: release( - "onnxruntime-osx-arm64-1.30.0.tgz", - "6ebb5062a934537c352937821f9fe9718e7de1a2db1122a93dd363ffd53a7012", - 42_373_116, + archive: nuget( + "osx-arm64", + 132_223_187, + "d9f60cc9c7af596e5114a0dbb3afdc62eaa93de0236ce6e6aa4500ace7b39c0a", + 12_536_089, ), - member: "onnxruntime-osx-arm64-1.30.0/lib/libonnxruntime.1.30.0.dylib", library: { name: "libonnxruntime.1.dylib", - sha256: "bcc9110f9d638a119de2db7afb3ba9a1da8085f0cb3401e1c48ae1caf450b6fa", + sha256: "bffaa6ef856dba2c26f09c7c0e7018fd1562625f3485292c7ad28b83748c6879", bytes: 43_879_424, }, }, @@ -143,9 +152,9 @@ const isInstalled = (runtime: NativeRuntime, folder: string): boolean => sizeOf(join(folder, runtime.library.name)) === runtime.library.bytes && sizeOf(join(folder, BINDING)) !== undefined /** - * The library this system's binding links to, out of Microsoft's release archive, checked against its own sha256 - * and placed beside a copy of the binding, which loads it from its own folder. Only from `models download`: a search - * never downloads. `undefined` when this system runs models through WebAssembly only. + * The library this system's binding links to, out of Microsoft's NuGet package or onnxruntime-node's npm tarball, + * checked against its own sha256 and placed beside a copy of the binding, which loads it from its own folder. Only + * from `models download`: a search never downloads. `undefined` when this system runs models through WebAssembly only. */ export const installNativeRuntime = async ({ env = process.env, @@ -175,7 +184,8 @@ export const installNativeRuntime = async ({ try { const archive = join(staging, runtime.archive.name) await installFiles([[runtime.archive, archive]], { ...(fetch ? { fetch } : {}), progress }) - const library = tarMember(gunzipSync(readFileSync(archive)), runtime.member) + const bytes = readFileSync(archive) + const library = runtime.member ? tarMember(gunzipSync(bytes), runtime.member) : inflateSync(bytes) rmSync(archive) const sha256 = library && createHash("sha256").update(library).digest("hex") if (!library || library.length !== runtime.library.bytes || sha256 !== runtime.library.sha256) diff --git a/src/speech/install.ts b/src/speech/install.ts index bff653fed..cd6e39b4e 100644 --- a/src/speech/install.ts +++ b/src/speech/install.ts @@ -66,7 +66,10 @@ const sizeOf = (path: string): number | undefined => { export const installedBytes = (model: SpeechModel): number => model.files.reduce((sum, file) => sum + file.bytes, 0) -export type Fetch = (url: string, init?: { signal?: AbortSignal }) => Promise +export type Fetch = ( + url: string, + init?: { signal?: AbortSignal; headers?: Record }, +) => Promise export interface InstallOptions { fetch?: Fetch @@ -142,7 +145,9 @@ const fetchInto = async ( stalled: Watchdog, received: (bytes: number) => void, ): Promise => { - const response = await get(file.url, { signal: stalled.signal }) + const range = + file.offset === undefined ? {} : { headers: { Range: `bytes=${file.offset}-${file.offset + file.bytes - 1}` } } + const response = await get(file.url, { signal: stalled.signal, ...range }) if (!response.ok || !response.body) { await response.body?.cancel() throw new CliError("network_error", `${file.name} could not be downloaded: HTTP ${response.status}`) diff --git a/src/speech/models.ts b/src/speech/models.ts index 751c99a80..b11c1fd94 100644 --- a/src/speech/models.ts +++ b/src/speech/models.ts @@ -15,6 +15,8 @@ export interface ModelFile { url: string sha256: string bytes: number + /** Where the file starts inside the one at `url`, fetched alone by an HTTP Range request. */ + offset?: number } export interface SpeechModel { From 2b5ae7cc94798b2cafd1117459067ebb5cdc82ee Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 18 Nov 2026 19:08:44 +0100 Subject: [PATCH 2/2] fix(embeddings): take the native ONNX Runtime from WireCat's own npm packages The owner wants no run-time dependency on Microsoft's hosting, GitHub or NuGet. The library now comes from @wirecat/onnxruntime- on registry.npmjs.org, one package per platform (linux-x64, linux-arm64, darwin-arm64, win32-x64, win32-arm64), each holding only that library plus Microsoft's LICENSE and ThirdPartyNotices.txt, with os/cpu set. `models download` still fetches on demand into the shared models folder, through the existing tarball path (installFiles, gunzip, tarMember): every NATIVE entry now has the same shape, member `package/`. Tarball and library sha256 are both pinned. The NuGet Range code from the previous commit is reverted: nothing needs it. bin/publish-onnxruntime builds the packages once from the NuGet 1.30.0 nupkg (Linux, macOS) and the onnxruntime-node 1.30.0 tarball (Windows, DirectML build, same DLL sha as today), packs them with npm pack (reproducible here: two runs, same sha256), refuses any tarball that differs from the pin, and with --publish publishes those not yet on npm. Not published: a new npm package needs the owner. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + bin/publish-onnxruntime | 200 ++++++++++++++++++++++++++++ changes/fix-ort-native-source.md | 14 +- packages/onnx/README.md | 6 +- packages/onnx/probe-native.mjs | 68 +++------- src/embeddings/onnx-runtime.test.ts | 29 +--- src/embeddings/onnx-runtime.ts | 131 ++++++++---------- src/speech/install.ts | 9 +- src/speech/models.ts | 2 - 9 files changed, 290 insertions(+), 170 deletions(-) create mode 100755 bin/publish-onnxruntime diff --git a/.gitignore b/.gitignore index 04afbed00..6cf78c31b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ packages/onnx/native/ # Internal working files: kept on the machine, not published. /CLEANUP.md /docs/dev/*-handoff.md +packages/onnxruntime/ diff --git a/bin/publish-onnxruntime b/bin/publish-onnxruntime new file mode 100755 index 000000000..2d660b2fa --- /dev/null +++ b/bin/publish-onnxruntime @@ -0,0 +1,200 @@ +#!/usr/bin/env node +// Builds the five @wirecat/onnxruntime- packages that `models download` takes the native ONNX Runtime from, +// and with --publish publishes the ones npm does not have yet. Microsoft's GitHub releases went away on 17.11.2026, +// so cli-core depends on no Microsoft hosting at run time: the libraries are taken once, here, from Microsoft's NuGet +// package (Linux, macOS) and onnxruntime-node's npm tarball (Windows: its binding needs the DirectML build of +// onnxruntime.dll, export ordinal 4, which the NuGet CPU build lacks). Every input and every packed tarball is +// checked against the sha256 below, which src/embeddings/onnx-runtime.ts pins too: a packed tarball that differs +// (another npm version packs differently) is not published. +// +// bin/publish-onnxruntime build and pack into packages/onnxruntime/ +// bin/publish-onnxruntime --publish the same, then publish; the npm token comes from the keyring +// (secret-tool lookup service npm account leemour) or NPM_TOKEN +import { execFileSync } from "node:child_process" +import { createHash } from "node:crypto" +import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs" +import { dirname, join } from "node:path" +import { fileURLToPath } from "node:url" +import { unzipSync } from "fflate" + +const VERSION = "1.30.0" +const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..") +const OUT = join(ROOT, "packages", "onnxruntime") +const SOURCES = join(OUT, "sources") + +const NUGET = { + url: + `https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${VERSION}` + + `/microsoft.ml.onnxruntime.${VERSION}.nupkg`, + file: join(SOURCES, `microsoft.ml.onnxruntime.${VERSION}.nupkg`), + sha256: "30df119bd9164eaa187666d93147448fdd4a9a1a3caf83f1505daf7af2d1c5d2", +} +const NPM = { + url: `https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-${VERSION}.tgz`, + file: join(SOURCES, `onnxruntime-node-${VERSION}.tgz`), + sha256: "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75", +} + +const TARGETS = [ + { + target: "linux-x64", + os: "linux", + cpu: "x64", + from: NUGET, + member: "runtimes/linux-x64/native/libonnxruntime.so", + library: "libonnxruntime.so.1", + sha256: "245a6f8c38127551057a1cd1ffd59f0a186a227ade4f3492dea2494eb565542e", + tarball: "9c12e88ae495ae04e28802e52c2524a7a9c31aa715a67eeb636c85efcb08e5d9", + }, + { + target: "linux-arm64", + os: "linux", + cpu: "arm64", + from: NUGET, + member: "runtimes/linux-arm64/native/libonnxruntime.so", + library: "libonnxruntime.so.1", + sha256: "64e903a43a041240fd6bcffe0ac6d4fea47ef87bf24b9d097801bd00a9612a4b", + tarball: "4ec23a63f0e7f49edb63590f4bc8b0e8526bff5b3a2b19d768112f37dc50d09c", + }, + { + target: "darwin-arm64", + os: "darwin", + cpu: "arm64", + from: NUGET, + member: "runtimes/osx-arm64/native/libonnxruntime.dylib", + library: "libonnxruntime.1.dylib", + sha256: "bffaa6ef856dba2c26f09c7c0e7018fd1562625f3485292c7ad28b83748c6879", + tarball: "0e543a584a048b301ff96b81af4b001288e048577ce0f0b4a5a9c2df97979615", + }, + { + target: "win32-x64", + os: "win32", + cpu: "x64", + from: NPM, + member: "package/bin/napi-v6/win32/x64/onnxruntime.dll", + library: "onnxruntime.dll", + sha256: "508c362f5673483dd3a086379c392795b2e42d10d5e6f3f90ebd7ac21c97af67", + tarball: "55924c8e4c3f975d131e943712c5fac6e5423fb2b0c356c96230f2ad18dc2792", + }, + { + target: "win32-arm64", + os: "win32", + cpu: "arm64", + from: NPM, + member: "package/bin/napi-v6/win32/arm64/onnxruntime.dll", + library: "onnxruntime.dll", + sha256: "6c3a2abf5c6aca11c48a0d338a91af309f2266f25ce2e4084e6a87bbcb0fbfd0", + tarball: "77e43743e580d6641e49b7cdeed57fd11f21a8cf27a186dd33a3db817b3ff7f2", + }, +] + +const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex") +const fail = (message) => { + console.error(message) + process.exit(1) +} + +const fetched = async ({ url, file, sha256: expected }) => { + if (!existsSync(file)) { + console.log(`downloading ${url}`) + const response = await fetch(url) + if (!response.ok) fail(`${url}: HTTP ${response.status}`) + writeFileSync(file, Buffer.from(await response.arrayBuffer())) + } + const bytes = readFileSync(file) + if (sha256(bytes) !== expected) fail(`${file} is not the file expected (sha256 ${sha256(bytes)}); delete it to retry`) + return bytes +} + +const tarMember = (archive, member) => + execFileSync("tar", ["-xzOf", archive, member], { maxBuffer: 256 * 1024 * 1024 }) + +const readme = ({ target, from, member, library, sha256: expected }) => `# @wirecat/onnxruntime-${target} + +ONNX Runtime ${VERSION}'s native library for ${target}, as \`${library}\`, for +[@wirecat/cli-core](https://www.npmjs.com/package/@wirecat/cli-core): \`models download\` fetches this package's +tarball and checks the library's sha256 before it uses it. Not meant to be installed on its own. + +- Source: ${from.url} +- Source sha256: \`${from.sha256}\` +- Member: \`${member}\` +- Library sha256: \`${expected}\` + +ONNX Runtime is © Microsoft Corporation, under the MIT licence in \`LICENSE\`; \`ThirdPartyNotices.txt\` lists the +code it includes. Both are copied from the NuGet package \`Microsoft.ML.OnnxRuntime\` ${VERSION}. +` + +mkdirSync(SOURCES, { recursive: true }) +const nuget = unzipSync(await fetched(NUGET), { + filter: ({ name }) => name === "LICENSE" || name === "ThirdPartyNotices.txt" || name.startsWith("runtimes/"), +}) +await fetched(NPM) + +const packed = [] +for (const spec of TARGETS) { + const name = `@wirecat/onnxruntime-${spec.target}` + const folder = join(OUT, spec.target) + rmSync(folder, { recursive: true, force: true }) + mkdirSync(folder, { recursive: true }) + const library = spec.from === NUGET ? nuget[spec.member] : tarMember(NPM.file, spec.member) + if (!library || sha256(library) !== spec.sha256) fail(`${spec.member} is not the library expected`) + writeFileSync(join(folder, spec.library), library, { mode: 0o755 }) + writeFileSync(join(folder, "LICENSE"), nuget.LICENSE) + writeFileSync(join(folder, "ThirdPartyNotices.txt"), nuget["ThirdPartyNotices.txt"]) + writeFileSync(join(folder, "README.md"), readme(spec)) + const manifest = { + name, + version: VERSION, + description: `ONNX Runtime ${VERSION}'s native library for ${spec.target}, for @wirecat/cli-core`, + license: "MIT", + repository: { type: "git", url: "git+https://github.com/WireCatLabs/cli-core.git", directory: "bin" }, + os: [spec.os], + cpu: [spec.cpu], + files: [spec.library, "LICENSE", "ThirdPartyNotices.txt", "README.md"], + } + writeFileSync(join(folder, "package.json"), `${JSON.stringify(manifest, null, 2)}\n`) + const [{ filename }] = JSON.parse( + execFileSync("npm", ["pack", "--json", "--pack-destination", OUT], { cwd: folder, encoding: "utf8" }), + ) + const tarball = join(OUT, filename) + const actual = sha256(readFileSync(tarball)) + console.log(`${name}@${VERSION}: ${tarball}, ${readFileSync(tarball).length} bytes, sha256 ${actual}`) + if (spec.tarball && actual !== spec.tarball) fail(`${filename} packed differently from the pinned ${spec.tarball}`) + packed.push({ name, tarball, pinned: Boolean(spec.tarball) }) +} + +if (!process.argv.includes("--publish")) process.exit(0) +if (packed.some(({ pinned }) => !pinned)) fail("pin every tarball's sha256 above before publishing") + +let token = process.env.NPM_TOKEN +if (!token) { + try { + token = execFileSync("secret-tool", ["lookup", "service", "npm", "account", "leemour"], { + encoding: "utf8", + stdio: ["ignore", "pipe", "ignore"], + }).trim() + } catch {} +} +if (!token) fail("no npm token: export NPM_TOKEN, or: secret-tool store --label=npm service npm account leemour") +const npmrc = join(OUT, ".npmrc") +// The config names the variable, not the value: the token stays in this process's environment. +writeFileSync(npmrc, "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n", { mode: 0o600 }) +try { + for (const { name, tarball } of packed) { + let published = false + try { + execFileSync("npm", ["view", `${name}@${VERSION}`, "version"], { stdio: "ignore" }) + published = true + } catch {} + if (published) { + console.log(`${name}@${VERSION} is already on npm`) + continue + } + execFileSync("npm", ["publish", tarball, "--access", "public", "--userconfig", npmrc], { + stdio: "inherit", + env: { ...process.env, NPM_TOKEN: token }, + }) + } +} finally { + rmSync(npmrc, { force: true }) +} diff --git a/changes/fix-ort-native-source.md b/changes/fix-ort-native-source.md index 97e2aeeb3..2c9b6f03a 100644 --- a/changes/fix-ort-native-source.md +++ b/changes/fix-ort-native-source.md @@ -1,8 +1,10 @@ ### Fixed -- **`models download` installs the native ONNX Runtime again on Linux and macOS.** Microsoft's GitHub repository, and - every release download in it, answers 404 since 17.11.2026, so the download failed and the models ran through - WebAssembly. The library now comes from Microsoft's NuGet package `Microsoft.ML.OnnxRuntime` 1.30.0: one HTTP Range - request fetches only that system's library out of the 157 MB package, 10–12.5 MB. The Linux libraries are byte for - byte the ones from the GitHub release; the macOS one is NuGet's own build of the same version, with a new sha256. - Windows still takes its library from `onnxruntime-node`'s npm tarball. +- **`models download` takes the native ONNX Runtime from WireCat's own npm packages.** Microsoft's GitHub repository, + and every release download in it, answers 404 since 17.11.2026, so the download failed on Linux and macOS and the + models ran through WebAssembly. The library now comes from `@wirecat/onnxruntime-` on npm (linux-x64, + linux-arm64, darwin-arm64, win32-x64, win32-arm64), 10–13 MB each, with the same sha256 check of the library. No + download depends on Microsoft's hosting any more. `bin/publish-onnxruntime` builds the packages once from + Microsoft's NuGet package `Microsoft.ML.OnnxRuntime` 1.30.0, and on Windows from `onnxruntime-node`'s npm tarball as + before. The Linux and Windows libraries are byte for byte the ones used so far. The macOS one is NuGet's build of + the same version, with a new sha256. Windows downloads 11 MB instead of the 113 MB `onnxruntime-node` tarball. diff --git a/packages/onnx/README.md b/packages/onnx/README.md index db8afe488..83229bbc5 100644 --- a/packages/onnx/README.md +++ b/packages/onnx/README.md @@ -7,9 +7,9 @@ - **Native**, 2–3× faster, on Linux x64 and arm64 (glibc), macOS arm64 and Windows x64 and arm64: `onnxruntime-node`'s JavaScript and the 0.3–0.4 MB binding of each of those systems, without its libraries. `@wirecat/cli-core` downloads the library beside a copy of the binding, which loads it from its own folder: from - Microsoft's NuGet package of the same version, and on Windows from `onnxruntime-node`'s own npm tarball, because the - Windows binding needs the DirectML build of `onnxruntime.dll` (export ordinal 4) that Microsoft's CPU release does - not carry. + WireCat's `@wirecat/onnxruntime-` package of the same version, built by `bin/publish-onnxruntime` from + Microsoft's NuGet package, and on Windows from `onnxruntime-node`'s own npm tarball, because the Windows binding + needs the DirectML build of `onnxruntime.dll` (export ordinal 4) that Microsoft's CPU build does not carry. ```js import { env, InferenceSession, Tensor } from "@wirecat/cli-core-onnx" // WebAssembly diff --git a/packages/onnx/probe-native.mjs b/packages/onnx/probe-native.mjs index 4b5b4cec0..c6090244d 100644 --- a/packages/onnx/probe-native.mjs +++ b/packages/onnx/probe-native.mjs @@ -1,64 +1,38 @@ // Runs the one-node model through the native binding of this system, beside the ONNX Runtime library -// @wirecat/cli-core downloads — from Microsoft's NuGet package, or on Windows from onnxruntime-node's npm tarball, -// whose DirectML build of onnxruntime.dll the binding needs: `node probe-native.mjs` and `bun probe-native.mjs`. +// @wirecat/cli-core downloads from WireCat's @wirecat/onnxruntime- package on npm (bin/publish-onnxruntime): +// `node probe-native.mjs` and `bun probe-native.mjs`. import { execFileSync } from "node:child_process" import { createHash } from "node:crypto" import { copyFileSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { inflateRawSync } from "node:zlib" import { nativeBindingFor, ONNX_RUNTIME_VERSION, openNative } from "@wirecat/cli-core-onnx" -const nuget = - `https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/${ONNX_RUNTIME_VERSION}` + - `/microsoft.ml.onnxruntime.${ONNX_RUNTIME_VERSION}.nupkg` -const npm = `https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz` -const npmSha256 = "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75" -// Each library's deflated bytes in the NuGet zip, or its path in the npm tarball, and the name the binding loads. -const sources = { - "linux-x64": { - offset: 121_160_280, - sha256: "6f7d1ee67f9c7d3e5d1b009492aef02d2833ba16a4a896b71438b20abfe4293a", - bytes: 11_061_061, - library: "libonnxruntime.so.1", - }, - "linux-arm64": { - offset: 111_131_974, - sha256: "4e8adcdf8582ff74925989b0e009efa808723b23ec297eae4acaababe0ffad8f", - bytes: 10_026_119, - library: "libonnxruntime.so.1", - }, - "darwin-arm64": { - offset: 132_223_187, - sha256: "d9f60cc9c7af596e5114a0dbb3afdc62eaa93de0236ce6e6aa4500ace7b39c0a", - bytes: 12_536_089, - library: "libonnxruntime.1.dylib", - }, - "win32-x64": { member: "package/bin/napi-v6/win32/x64/onnxruntime.dll", library: "onnxruntime.dll" }, - "win32-arm64": { member: "package/bin/napi-v6/win32/arm64/onnxruntime.dll", library: "onnxruntime.dll" }, +const archives = { + "linux-x64": ["9c12e88ae495ae04e28802e52c2524a7a9c31aa715a67eeb636c85efcb08e5d9", "libonnxruntime.so.1"], + "linux-arm64": ["4ec23a63f0e7f49edb63590f4bc8b0e8526bff5b3a2b19d768112f37dc50d09c", "libonnxruntime.so.1"], + "darwin-arm64": ["0e543a584a048b301ff96b81af4b001288e048577ce0f0b4a5a9c2df97979615", "libonnxruntime.1.dylib"], + "win32-x64": ["55924c8e4c3f975d131e943712c5fac6e5423fb2b0c356c96230f2ad18dc2792", "onnxruntime.dll"], + "win32-arm64": ["77e43743e580d6641e49b7cdeed57fd11f21a8cf27a186dd33a3db817b3ff7f2", "onnxruntime.dll"], } const target = `${process.platform}-${process.arch}` -const source = sources[target] -if (!source) throw new Error(`no ONNX Runtime library for ${target}`) +const [sha256, library] = archives[target] ?? [] +if (!sha256) throw new Error(`no ONNX Runtime package for ${target}`) +const name = `onnxruntime-${target}-${ONNX_RUNTIME_VERSION}.tgz` +const member = `package/${library}` const binding = nativeBindingFor() if (!binding) throw new Error(`the package carries no binding for ${target}`) +const work = mkdtempSync(join(tmpdir(), "onnx-native-")) +const archive = Buffer.from( + await (await fetch(`https://registry.npmjs.org/@wirecat/onnxruntime-${target}/-/${name}`)).arrayBuffer(), +) +const actual = createHash("sha256").update(archive).digest("hex") +if (actual !== sha256) throw new Error(`${name} is not the file expected (sha256 ${actual})`) +writeFileSync(join(work, name), archive) +execFileSync("tar", ["-xf", name, member], { cwd: work }) const folder = mkdtempSync(join(tmpdir(), "onnx-runtime-")) -if (source.member) { - const archive = Buffer.from(await (await fetch(npm)).arrayBuffer()) - const actual = createHash("sha256").update(archive).digest("hex") - if (actual !== npmSha256) throw new Error(`the npm tarball is not the file expected (sha256 ${actual})`) - const work = mkdtempSync(join(tmpdir(), "onnx-native-")) - writeFileSync(join(work, "npm.tgz"), archive) - execFileSync("tar", ["-xf", "npm.tgz", source.member], { cwd: work }) - copyFileSync(join(work, source.member), join(folder, source.library)) -} else { - const range = `bytes=${source.offset}-${source.offset + source.bytes - 1}` - const slice = Buffer.from(await (await fetch(nuget, { headers: { Range: range } })).arrayBuffer()) - const actual = createHash("sha256").update(slice).digest("hex") - if (actual !== source.sha256) throw new Error(`the NuGet slice is not the one expected (sha256 ${actual})`) - writeFileSync(join(folder, source.library), inflateRawSync(slice)) -} +copyFileSync(join(work, member), join(folder, library)) copyFileSync(binding, join(folder, "onnxruntime_binding.node")) const { InferenceSession, Tensor } = openNative(join(folder, "onnxruntime_binding.node")) diff --git a/src/embeddings/onnx-runtime.test.ts b/src/embeddings/onnx-runtime.test.ts index fde8b25f2..544e0ce66 100644 --- a/src/embeddings/onnx-runtime.test.ts +++ b/src/embeddings/onnx-runtime.test.ts @@ -3,7 +3,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from import { tmpdir } from "node:os" import { join } from "node:path" import { ONNX_RUNTIME_VERSION as PACKAGE_VERSION } from "@wirecat/cli-core-onnx" -import { deflateSync, gzipSync } from "fflate" +import { gzipSync } from "fflate" import { afterEach, describe, expect, it, vi } from "vitest" import { installNativeRuntime, @@ -94,33 +94,6 @@ describe("the native ONNX Runtime", () => { expect(fetch).toHaveBeenCalledTimes(1) }) - it("is installed out of one ranged slice of a zip, the library alone, deflated", async () => { - const slice = deflateSync(library) - const runtime: NativeRuntime = { - target: "test-x64", - archive: { - name: "library.deflate", - url: "https://example.test/p.nupkg", - offset: 1000, - sha256: sha256(slice), - bytes: slice.length, - }, - library: { name: "libonnxruntime.test", sha256: sha256(library), bytes: library.length }, - } - const env = { WIRECAT_STATE_DIR: mkdtempSync(join(tmpdir(), "runtime-")) } - const fetch = fetchOf(slice) - - const folder = await installNativeRuntime({ env, fetch, runtime, binding: binding() }) - - expect(readFileSync(join(folder as string, "libonnxruntime.test"))).toEqual(Buffer.from(library)) - expect(fetch).toHaveBeenCalledWith( - "https://example.test/p.nupkg", - expect.objectContaining({ - headers: { Range: `bytes=1000-${1000 + slice.length - 1}` }, - }), - ) - }) - it("installs nothing when the archive holds another library", async () => { const member = "onnxruntime-linux-x64-1.30.0/lib/libonnxruntime.so.1.30.0" const archive = gzipSync(tarOf([{ name: member, data: new TextEncoder().encode("another library") }])) diff --git a/src/embeddings/onnx-runtime.ts b/src/embeddings/onnx-runtime.ts index 43172233a..5f0571212 100644 --- a/src/embeddings/onnx-runtime.ts +++ b/src/embeddings/onnx-runtime.ts @@ -11,7 +11,7 @@ import { } from "node:fs" import { join } from "node:path" import { CliError } from "@wirecat/cli-base" -import { gunzipSync, inflateSync } from "fflate" +import { gunzipSync } from "fflate" import { type Fetch, installFiles, megabytes, sharedModelsDirectory } from "../speech/install.js" import type { ModelFile } from "../speech/models.js" @@ -21,96 +21,76 @@ export const ONNX_RUNTIME_VERSION = "1.30.0" export interface NativeRuntime { readonly target: string readonly archive: ModelFile - /** The library's path in a tar archive; absent when `archive` is the library alone, deflated, out of a zip. */ - readonly member?: string + readonly member: string readonly library: { name: string; sha256: string; bytes: number } } -const NUGET = "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime" +const REGISTRY = "https://registry.npmjs.org" /** - * One library out of Microsoft's NuGet package, fetched alone by where its deflated bytes sit in the 157 MB zip: a - * version on nuget.org never changes, and the package signature, which nuget.org may replace, is its last file. - * Microsoft's GitHub releases went away on 17.11.2026. + * WireCat's own package of this system's library, on npm: Microsoft's GitHub releases went away on 17.11.2026, so no + * download depends on Microsoft's hosting. `bin/publish-onnxruntime` builds them from Microsoft's NuGet package, and + * on Windows from onnxruntime-node's npm tarball: its binding imports the DirectML build of onnxruntime.dll by + * ordinal, which Microsoft's CPU build lacks; DirectML.dll is loaded only when used, so the DLL alone runs on CPU. */ -const nuget = (target: string, offset: number, sha256: string, bytes: number): ModelFile => ({ - name: `onnxruntime-${ONNX_RUNTIME_VERSION}-${target}.deflate`, - url: `${NUGET}/${ONNX_RUNTIME_VERSION}/microsoft.ml.onnxruntime.${ONNX_RUNTIME_VERSION}.nupkg`, - offset, - sha256, - bytes, +const wirecat = ( + target: string, + sha256: string, + bytes: number, + library: NativeRuntime["library"], +): Omit => ({ + archive: { + name: `onnxruntime-${target}-${ONNX_RUNTIME_VERSION}.tgz`, + url: `${REGISTRY}/@wirecat/onnxruntime-${target}/-/onnxruntime-${target}-${ONNX_RUNTIME_VERSION}.tgz`, + sha256, + bytes, + }, + member: `package/${library.name}`, + library, }) -/** - * onnxruntime-node's own npm tarball, for Windows: its binding imports the DirectML build of onnxruntime.dll by - * ordinal, which Microsoft's CPU release lacks; DirectML.dll is loaded only when used, so the DLL alone runs on CPU. - */ -const npmTarball: ModelFile = { - name: `onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz`, - url: `https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-${ONNX_RUNTIME_VERSION}.tgz`, - sha256: "6e3390d6b783e7be946fad629292799da28d0b42f84856e50d2c1b0383291e75", - bytes: 113_507_888, -} - /** The systems the native-runtime workflow runs natively; elsewhere, and on musl, the models run through WebAssembly. */ const NATIVE: Record> = { - "linux-x64": { - archive: nuget( - "linux-x64", - 121_160_280, - "6f7d1ee67f9c7d3e5d1b009492aef02d2833ba16a4a896b71438b20abfe4293a", - 11_061_061, - ), - library: { - name: "libonnxruntime.so.1", - sha256: "245a6f8c38127551057a1cd1ffd59f0a186a227ade4f3492dea2494eb565542e", - bytes: 28_985_152, - }, - }, - "linux-arm64": { - archive: nuget( - "linux-arm64", - 111_131_974, - "4e8adcdf8582ff74925989b0e009efa808723b23ec297eae4acaababe0ffad8f", - 10_026_119, - ), - library: { + "linux-x64": wirecat("linux-x64", "9c12e88ae495ae04e28802e52c2524a7a9c31aa715a67eeb636c85efcb08e5d9", 11_305_384, { + name: "libonnxruntime.so.1", + sha256: "245a6f8c38127551057a1cd1ffd59f0a186a227ade4f3492dea2494eb565542e", + bytes: 28_985_152, + }), + "linux-arm64": wirecat( + "linux-arm64", + "4ec23a63f0e7f49edb63590f4bc8b0e8526bff5b3a2b19d768112f37dc50d09c", + 10_386_392, + { name: "libonnxruntime.so.1", sha256: "64e903a43a041240fd6bcffe0ac6d4fea47ef87bf24b9d097801bd00a9612a4b", bytes: 25_135_496, }, - }, - "darwin-arm64": { - archive: nuget( - "osx-arm64", - 132_223_187, - "d9f60cc9c7af596e5114a0dbb3afdc62eaa93de0236ce6e6aa4500ace7b39c0a", - 12_536_089, - ), - library: { + ), + "darwin-arm64": wirecat( + "darwin-arm64", + "0e543a584a048b301ff96b81af4b001288e048577ce0f0b4a5a9c2df97979615", + 12_921_423, + { name: "libonnxruntime.1.dylib", sha256: "bffaa6ef856dba2c26f09c7c0e7018fd1562625f3485292c7ad28b83748c6879", bytes: 43_879_424, }, - }, - "win32-x64": { - archive: npmTarball, - member: "package/bin/napi-v6/win32/x64/onnxruntime.dll", - library: { - name: "onnxruntime.dll", - sha256: "508c362f5673483dd3a086379c392795b2e42d10d5e6f3f90ebd7ac21c97af67", - bytes: 28_754_232, - }, - }, - "win32-arm64": { - archive: npmTarball, - member: "package/bin/napi-v6/win32/arm64/onnxruntime.dll", - library: { + ), + "win32-x64": wirecat("win32-x64", "55924c8e4c3f975d131e943712c5fac6e5423fb2b0c356c96230f2ad18dc2792", 10_652_326, { + name: "onnxruntime.dll", + sha256: "508c362f5673483dd3a086379c392795b2e42d10d5e6f3f90ebd7ac21c97af67", + bytes: 28_754_232, + }), + "win32-arm64": wirecat( + "win32-arm64", + "77e43743e580d6641e49b7cdeed57fd11f21a8cf27a186dd33a3db817b3ff7f2", + 10_778_591, + { name: "onnxruntime.dll", sha256: "6c3a2abf5c6aca11c48a0d338a91af309f2266f25ce2e4084e6a87bbcb0fbfd0", bytes: 29_815_136, }, - }, + ), } const onMusl = (): boolean => { @@ -152,9 +132,9 @@ const isInstalled = (runtime: NativeRuntime, folder: string): boolean => sizeOf(join(folder, runtime.library.name)) === runtime.library.bytes && sizeOf(join(folder, BINDING)) !== undefined /** - * The library this system's binding links to, out of Microsoft's NuGet package or onnxruntime-node's npm tarball, - * checked against its own sha256 and placed beside a copy of the binding, which loads it from its own folder. Only - * from `models download`: a search never downloads. `undefined` when this system runs models through WebAssembly only. + * The library this system's binding links to, out of WireCat's npm package of it, checked against its own sha256 + * and placed beside a copy of the binding, which loads it from its own folder. Only from `models download`: a search + * never downloads. `undefined` when this system runs models through WebAssembly only. */ export const installNativeRuntime = async ({ env = process.env, @@ -175,17 +155,14 @@ export const installNativeRuntime = async ({ const folder = runtimeFolder(runtime, env) if (isInstalled(runtime, folder)) return folder - progress( - `ONNX Runtime ${ONNX_RUNTIME_VERSION} for ${runtime.target}: ${megabytes(runtime.archive.bytes)} from Microsoft`, - ) + progress(`ONNX Runtime ${ONNX_RUNTIME_VERSION} for ${runtime.target}: ${megabytes(runtime.archive.bytes)} from npm`) const parent = sharedModelsDirectory("runtime", env) mkdirSync(parent, { recursive: true, mode: 0o700 }) const staging = mkdtempSync(join(parent, ".onnxruntime-")) try { const archive = join(staging, runtime.archive.name) await installFiles([[runtime.archive, archive]], { ...(fetch ? { fetch } : {}), progress }) - const bytes = readFileSync(archive) - const library = runtime.member ? tarMember(gunzipSync(bytes), runtime.member) : inflateSync(bytes) + const library = tarMember(gunzipSync(readFileSync(archive)), runtime.member) rmSync(archive) const sha256 = library && createHash("sha256").update(library).digest("hex") if (!library || library.length !== runtime.library.bytes || sha256 !== runtime.library.sha256) diff --git a/src/speech/install.ts b/src/speech/install.ts index cd6e39b4e..bff653fed 100644 --- a/src/speech/install.ts +++ b/src/speech/install.ts @@ -66,10 +66,7 @@ const sizeOf = (path: string): number | undefined => { export const installedBytes = (model: SpeechModel): number => model.files.reduce((sum, file) => sum + file.bytes, 0) -export type Fetch = ( - url: string, - init?: { signal?: AbortSignal; headers?: Record }, -) => Promise +export type Fetch = (url: string, init?: { signal?: AbortSignal }) => Promise export interface InstallOptions { fetch?: Fetch @@ -145,9 +142,7 @@ const fetchInto = async ( stalled: Watchdog, received: (bytes: number) => void, ): Promise => { - const range = - file.offset === undefined ? {} : { headers: { Range: `bytes=${file.offset}-${file.offset + file.bytes - 1}` } } - const response = await get(file.url, { signal: stalled.signal, ...range }) + const response = await get(file.url, { signal: stalled.signal }) if (!response.ok || !response.body) { await response.body?.cancel() throw new CliError("network_error", `${file.name} could not be downloaded: HTTP ${response.status}`) diff --git a/src/speech/models.ts b/src/speech/models.ts index b11c1fd94..751c99a80 100644 --- a/src/speech/models.ts +++ b/src/speech/models.ts @@ -15,8 +15,6 @@ export interface ModelFile { url: string sha256: string bytes: number - /** Where the file starts inside the one at `url`, fetched alone by an HTTP Range request. */ - offset?: number } export interface SpeechModel {