fix: copy ort .mjs file, add COOP/COEP headers, set numThreads=1

The threaded ORT WASM requires ort-wasm-simd-threaded.mjs to be served
alongside the .wasm files, and needs SharedArrayBuffer (COOP/COEP headers).
Add the .mjs to the static copy targets, add the required headers to the
Vite dev server, and set ort.env.wasm.numThreads=1 as a single-threaded
fallback that avoids the SharedArrayBuffer requirement entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mk
2026-03-23 23:41:51 -03:00
parent edd1e1d34e
commit b25cec3aa0
2 changed files with 15 additions and 0 deletions

View File

@@ -50,6 +50,10 @@ export default ({
src: "node_modules/onnxruntime-web/dist/*.wasm",
dest: "vad",
},
{
src: "node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.mjs",
dest: "vad",
},
],
}),
react(),
@@ -118,6 +122,11 @@ export default ({
key: fs.readFileSync("./backend/dev_tls_m.localhost.key"),
cert: fs.readFileSync("./backend/dev_tls_m.localhost.crt"),
},
// Required for SharedArrayBuffer (used by onnxruntime-web threaded WASM)
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
worker: {
format: "es",