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
7 changes: 6 additions & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cmake = "latest"
dprint = "latest"
editorconfig-checker = "latest"
"github:block/goose" = "latest"
"github:wasm-bindgen/wasm-bindgen" = "0.2.114"
ollama = "latest"
osv-scanner = "latest"
pipx = "latest"
Expand Down Expand Up @@ -68,7 +69,11 @@ run = "cargo run"
[tasks.build-ws-wasm-agent]
description = "Build the WebSocket WASM client"
dir = "services/ws-wasm-agent"
run = "wasm-pack build --target web"
run = "wasm-pack build . --target web -- -Z build-std=std,panic_abort"

[tasks.build-ws-wasm-agent.env]
RUSTFLAGS = "-C target-cpu=mvp -C target-feature=+mutable-globals,+sign-ext,+nontrapping-fptoint"
RUSTUP_TOOLCHAIN = "nightly"

[tasks.test-ws-wasm-agent-firefox]
description = "Run headless Firefox tests for the WebSocket WASM client"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mise run build-ws-wasm-agent
mise run ws-server
```

The WASM build disables WebAssembly reference types so it can still load on older browsers such as Chrome 95.

Find the IP address of your laptop in the local network,
which will normally be something like 192.168.1.x.

Expand Down
29 changes: 29 additions & 0 deletions services/ws-server/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@ const formatNumber = (value, digits = 3) => (
Number.isFinite(value) ? value.toFixed(digits) : "n/a"
);

const configureOnnxRuntimeWasm = () => {
if (!window.ort?.env?.wasm) {
throw new Error("onnxruntime-web environment is unavailable.");
}

const ortVersion = window.ort.env.versions?.web;
if (typeof ortVersion !== "string" || ortVersion.length === 0) {
throw new Error("onnxruntime-web version is unavailable.");
}

const distBaseUrl = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ortVersion}/dist`;
const supportsWasmThreads = window.crossOriginIsolated === true
&& typeof SharedArrayBuffer !== "undefined";

window.ort.env.wasm.numThreads = supportsWasmThreads ? 0 : 1;
window.ort.env.wasm.wasmPaths = {
mjs: `${distBaseUrl}/ort-wasm-simd-threaded.mjs`,
wasm: `${distBaseUrl}/ort-wasm-simd-threaded.wasm`,
};

append(
`onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=${
window.ort.env.wasm.numThreads === 1 ? "disabled" : "auto"
}`,
);
};

const degreesToRadians = (value) => (
Number.isFinite(value) ? (value * Math.PI) / 180 : 0
);
Expand Down Expand Up @@ -797,6 +824,8 @@ try {
throw new Error("onnxruntime-web did not load.");
}

configureOnnxRuntimeWasm();

harButton.disabled = true;
harButton.textContent = "Loading HAR...";
updateHarStatus(["loading model..."]);
Expand Down
Loading