Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/chrome/vendor/d1/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Isolated d1 Runtime Dependencies

Only the experimental finite-decision d1 provider uses this directory. Existing
chat Transformers 4.2.0 / patched ONNX Runtime 1.27 remain unchanged.
chat Transformers 4.2.0 / patched ONNX Runtime 1.27 use a separate runtime.

- onnxruntime-web 1.31.0-dev.20260914-8d85527a0, commit
8d85527a010e294a26b274749f74294b2a32cec5: five runtime files copied byte-exact.
The WebGPU bundle uses the native `webgpuInit` ABI and its matching asyncify
factory/WASM pair. The original JSEP files are retained for provenance, but
are inactive: their `jsepInit` ABI does not match this WebGPU bundle.
- @huggingface/transformers 4.3.1: tokenizer API. Exactly two bare module imports
are relinked to ./ort.webgpu.bundle.min.mjs; all remaining bytes are unchanged.
This reproduces the previously verified browser import map, including Tensor.
- @huggingface/transformers 4.3.1: tokenizer API. Two bare module imports
are relinked to ./ort.webgpu.bundle.min.mjs, including Tensor. The upstream
CDN fallback is replaced with URLs relative to the packaged browser module,
so the asyncify factory and WASM resolve locally even before the worker
applies its explicit runtime settings.
- ORT MIT and Transformers Apache-2.0 licenses are retained separately. They do
not replace the model's LFM Open License v1.0.

All executable modules/WASM are bundled in the extension, not downloaded remote
code. Model graph/tokenizer bytes are separately checksum-pinned data assets.
Runtime and graph precision is FP32 regardless of legacy config.dtype.
vendor-manifest.json records upstream/copied SHA-256 and the exact linkage edits.
vendor-manifest.json records upstream/copied SHA-256 and the local packaging edits.
16 changes: 5 additions & 11 deletions src/chrome/vendor/d1/transformers.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -8726,18 +8726,12 @@ if (ONNX_ENV) {
ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[severityLevel];
};
if (ONNX_ENV.wasm) {
if (
// @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
!(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
) {
const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
let wasmPathSuffix = ".asyncify";
if (apis.IS_SAFARI_BELOW_26 && !apis.IS_WEBGPU_AVAILABLE) {
wasmPathSuffix = "";
}
// MV3: executable runtime files must come from the extension package.
// Both vendored ONNX Runtime builds use the asyncify factory/WASM pair.
if (!ONNX_ENV.wasm.wasmPaths) {
ONNX_ENV.wasm.wasmPaths = {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded${wasmPathSuffix}.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded${wasmPathSuffix}.wasm`
mjs: new URL("./ort-wasm-simd-threaded.asyncify.mjs", import.meta.url).href,
wasm: new URL("./ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href
};
}
ONNX_ENV.wasm.proxy = false;
Expand Down
12 changes: 8 additions & 4 deletions src/chrome/vendor/d1/vendor-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,25 @@
"bytes": 1156762,
"sha256": "ad44c6e41ff23fd5b01fa3fe08199a0440a35711dc9f80a31132fcce08fbd432"
},
"copied_bytes": 1156776,
"copied_sha256": "539590a6de78977caa3d28a4669df919c909a485388a870d4da67cdea8aa5698",
"copied_bytes": 1156484,
"copied_sha256": "85e66224c31c821cf9f47bf1768f213b01885eb9ebb01f984d7ddf83b9844434",
"byte_exact": false
}
],
"transformers_import_linkage_only_changes": [
"transformers_packaging_patches": [
[
"import * as ONNX_WEB from \"onnxruntime-web/webgpu\";",
"import * as ONNX_WEB from \"./ort.webgpu.bundle.min.mjs\";"
],
[
"import { Tensor } from \"onnxruntime-common\";",
"import { Tensor } from \"./ort.webgpu.bundle.min.mjs\";"
],
[
"Upstream jsDelivr ONNX Runtime default (including the unused Safari variant)",
"Packaged asyncify factory and WASM resolved relative to import.meta.url"
]
],
"old_chat_vendors_modified": false,
"old_chat_vendors_modified": true,
"global_dependency_versions_modified": false
}
8 changes: 7 additions & 1 deletion src/chrome/vendor/transformers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ grep -E '(import|export)[^"]*from\s+"[a-zA-Z@]' \
| grep -v '^\s*//' | grep -v '^\s*\*'
```

Keep the browser bundle's local WASM default: replace the upstream CDN
initializer with URLs for the packaged asyncify factory and binary relative
to `import.meta.url`. This also covers callers that have not yet set
`ort.env.wasm.wasmPaths`. Do not reintroduce a remote runtime fallback.

The LFM2.5-VL ONNX repositories need two compatibility hooks. The 1.6B export
predates the standard ImageTextToText component filenames, so keep the small
`session_file_names` alias hook in
Expand Down Expand Up @@ -191,7 +196,8 @@ cp node_modules/onnxruntime-common/dist/esm/*.js \

Copy the Transformers.js license and the ONNX Runtime license plus
`ThirdPartyNotices.txt` into this directory whenever the runtime is updated.
Reapply the specifier and ImageTextToText session-alias patches, update the
Reapply the import specifiers, local WASM default, and ImageTextToText
session-alias patches, update the
version table above, then verify:

1. `node --check` passes for the provider, host, and worker.
Expand Down
17 changes: 6 additions & 11 deletions src/chrome/vendor/transformers/transformers.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -7781,17 +7781,12 @@ if (ONNX_ENV) {
ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[severityLevel];
};
if (ONNX_ENV.wasm) {
if (
// @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
!(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
) {
const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
ONNX_ENV.wasm.wasmPaths = apis.IS_SAFARI ? {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.wasm`
} : {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.wasm`
// MV3: executable runtime files must come from the extension package.
// Both vendored ONNX Runtime builds use the asyncify factory/WASM pair.
if (!ONNX_ENV.wasm.wasmPaths) {
ONNX_ENV.wasm.wasmPaths = {
mjs: new URL("./ort-wasm-simd-threaded.asyncify.mjs", import.meta.url).href,
wasm: new URL("./ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href
};
}
ONNX_ENV.wasm.proxy = false;
Expand Down
12 changes: 7 additions & 5 deletions src/firefox/vendor/d1/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Isolated d1 Runtime Dependencies

Only the experimental finite-decision d1 provider uses this directory. Existing
chat Transformers 4.2.0 / patched ONNX Runtime 1.27 remain unchanged.
chat Transformers 4.2.0 / patched ONNX Runtime 1.27 use a separate runtime.

- onnxruntime-web 1.31.0-dev.20260914-8d85527a0, commit
8d85527a010e294a26b274749f74294b2a32cec5: five runtime files copied byte-exact.
The WebGPU bundle uses the native `webgpuInit` ABI and its matching asyncify
factory/WASM pair. The original JSEP files are retained for provenance, but
are inactive: their `jsepInit` ABI does not match this WebGPU bundle.
- @huggingface/transformers 4.3.1: tokenizer API. Exactly two bare module imports
are relinked to ./ort.webgpu.bundle.min.mjs; all remaining bytes are unchanged.
This reproduces the previously verified browser import map, including Tensor.
- @huggingface/transformers 4.3.1: tokenizer API. Two bare module imports
are relinked to ./ort.webgpu.bundle.min.mjs, including Tensor. The upstream
CDN fallback is replaced with URLs relative to the packaged browser module,
so the asyncify factory and WASM resolve locally even before the worker
applies its explicit runtime settings.
- ORT MIT and Transformers Apache-2.0 licenses are retained separately. They do
not replace the model's LFM Open License v1.0.

All executable modules/WASM are bundled in the extension, not downloaded remote
code. Model graph/tokenizer bytes are separately checksum-pinned data assets.
Runtime and graph precision is FP32 regardless of legacy config.dtype.
vendor-manifest.json records upstream/copied SHA-256 and the exact linkage edits.
vendor-manifest.json records upstream/copied SHA-256 and the local packaging edits.
16 changes: 5 additions & 11 deletions src/firefox/vendor/d1/transformers.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -8726,18 +8726,12 @@ if (ONNX_ENV) {
ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[severityLevel];
};
if (ONNX_ENV.wasm) {
if (
// @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
!(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
) {
const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
let wasmPathSuffix = ".asyncify";
if (apis.IS_SAFARI_BELOW_26 && !apis.IS_WEBGPU_AVAILABLE) {
wasmPathSuffix = "";
}
// MV3: executable runtime files must come from the extension package.
// Both vendored ONNX Runtime builds use the asyncify factory/WASM pair.
if (!ONNX_ENV.wasm.wasmPaths) {
ONNX_ENV.wasm.wasmPaths = {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded${wasmPathSuffix}.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded${wasmPathSuffix}.wasm`
mjs: new URL("./ort-wasm-simd-threaded.asyncify.mjs", import.meta.url).href,
wasm: new URL("./ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href
};
}
ONNX_ENV.wasm.proxy = false;
Expand Down
12 changes: 8 additions & 4 deletions src/firefox/vendor/d1/vendor-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,25 @@
"bytes": 1156762,
"sha256": "ad44c6e41ff23fd5b01fa3fe08199a0440a35711dc9f80a31132fcce08fbd432"
},
"copied_bytes": 1156776,
"copied_sha256": "539590a6de78977caa3d28a4669df919c909a485388a870d4da67cdea8aa5698",
"copied_bytes": 1156484,
"copied_sha256": "85e66224c31c821cf9f47bf1768f213b01885eb9ebb01f984d7ddf83b9844434",
"byte_exact": false
}
],
"transformers_import_linkage_only_changes": [
"transformers_packaging_patches": [
[
"import * as ONNX_WEB from \"onnxruntime-web/webgpu\";",
"import * as ONNX_WEB from \"./ort.webgpu.bundle.min.mjs\";"
],
[
"import { Tensor } from \"onnxruntime-common\";",
"import { Tensor } from \"./ort.webgpu.bundle.min.mjs\";"
],
[
"Upstream jsDelivr ONNX Runtime default (including the unused Safari variant)",
"Packaged asyncify factory and WASM resolved relative to import.meta.url"
]
],
"old_chat_vendors_modified": false,
"old_chat_vendors_modified": true,
"global_dependency_versions_modified": false
}
5 changes: 3 additions & 2 deletions src/firefox/vendor/transformers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ cache for fully offline use.
| `ThirdPartyNotices.onnxruntime.txt` | ONNX Runtime | Incorporated third-party notices |

The readable browser build is the same patched file used by Chrome: its bare
ONNX Runtime imports point at packaged relative files, and its ImageTextToText
session map accepts filename aliases for Chrome's legacy LFM2.5-VL 1.6B export.
ONNX Runtime imports and default asyncify factory/WASM paths point at packaged
relative files. Its ImageTextToText session map accepts filename aliases for
Chrome's legacy LFM2.5-VL 1.6B export.
It can also opt into nested `processor_config.json` metadata and standalone
chat-template files used by current VL exports. Those hooks are dormant in
Firefox. The WebGPU JSEP binaries are intentionally omitted from Firefox
Expand Down
17 changes: 6 additions & 11 deletions src/firefox/vendor/transformers/transformers.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -7781,17 +7781,12 @@ if (ONNX_ENV) {
ONNX_ENV.logLevel = ONNX_LOG_LEVEL_NAMES[severityLevel];
};
if (ONNX_ENV.wasm) {
if (
// @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304)
!(typeof ServiceWorkerGlobalScope !== "undefined" && self instanceof ServiceWorkerGlobalScope) && ONNX_ENV.versions?.web && !ONNX_ENV.wasm.wasmPaths
) {
const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ONNX_ENV.versions.web}/dist/`;
ONNX_ENV.wasm.wasmPaths = apis.IS_SAFARI ? {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.wasm`
} : {
mjs: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.mjs`,
wasm: `${wasmPathPrefix}ort-wasm-simd-threaded.asyncify.wasm`
// MV3: executable runtime files must come from the extension package.
// Both vendored ONNX Runtime builds use the asyncify factory/WASM pair.
if (!ONNX_ENV.wasm.wasmPaths) {
ONNX_ENV.wasm.wasmPaths = {
mjs: new URL("./ort-wasm-simd-threaded.asyncify.mjs", import.meta.url).href,
wasm: new URL("./ort-wasm-simd-threaded.asyncify.wasm", import.meta.url).href
};
}
ONNX_ENV.wasm.proxy = false;
Expand Down
30 changes: 30 additions & 0 deletions test/d1-decision.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import assert from 'node:assert/strict';
import { test } from 'node:test';
import { readFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';
import { execFile as execFileCallback } from 'node:child_process';
import { promisify } from 'node:util';
import vm from 'node:vm';

// One top-level function of a source file, by name.
Expand Down Expand Up @@ -48,6 +50,34 @@ async function withD1Download(pin, { stored = {}, marker = 'current' } = {}, fn)
}
}

const execFile = promisify(execFileCallback);

test('vendored Transformers imports default to packaged ONNX factory and WASM before worker configuration', async () => {
for (const browser of ['chrome', 'firefox']) {
for (const vendor of ['d1', 'transformers']) {
const url = new URL(`../src/${browser}/vendor/${vendor}/transformers.web.js`, import.meta.url);
// The real browser module must never install a CDN fallback, even if
// today's worker sets local paths immediately after the import.
const source = await readFile(url, 'utf8');
assert.doesNotMatch(source, /https?:\/\/[^\s"'`]*onnxruntime-web/i, url.pathname);
const { stdout } = await execFile(process.execPath, ['--input-type=module', '--eval', `
const url = process.argv[1];
// Select the bundled web ORT backend in a fresh process before import.
globalThis.process = undefined;
const { env } = await import(url);
console.log(JSON.stringify(env.backends.onnx.wasm.wasmPaths));
`, url.href]);
const expected = {
mjs: new URL('ort-wasm-simd-threaded.asyncify.mjs', url),
wasm: new URL('ort-wasm-simd-threaded.asyncify.wasm', url),
};
assert.deepEqual(JSON.parse(stdout), { mjs: expected.mjs.href, wasm: expected.wasm.href }, url.pathname);
assert.match(await readFile(expected.mjs, 'utf8'), /export default/, url.pathname);
assert.deepEqual((await readFile(expected.wasm)).subarray(0, 4), Buffer.from([0, 97, 115, 109]), url.pathname);
}
}
});

for (const build of ['chrome', 'firefox']) {
const config = await import(`../src/${build}/src/agent/decision-config.js`);
const availability = await import(`../src/${build}/src/agent/decision-availability.js`);
Expand Down
Loading