Repository navigation
Add a web engine for wasm32-unknown-unknown - #50
Conversation
On wasm32-unknown-unknown, ChatEngine is now a real engine instead of the stub. It runs GGUF Qwen2.5 and Qwen3 models on the CPU through candle, single-threaded, with the tokenizer loaded from tok_model_id. The public signatures match the native engine, so ed-agent compiles unchanged. Tool calling reports Unsupported. Other wasm and unknown targets keep the stub. Model files come from Hugging Face and are kept in Cache Storage (onde-models-v1), which works from a window and from a worker. web_store::download_model mirrors hf_cache::download_model with a progress callback, and is_cached and delete_model manage the cache. Generation builds a ChatML prompt, samples from SamplingConfig, and yields to the event loop between tokens, so cancels and dropped streams are seen. build.rs gains the onde_web cfg. The qwen25 and qwen3 presets set tok_model_id on web as they do on Android. tests/web_smoke.rs downloads Qwen 2.5 0.5B in headless Chrome and checks a streamed reply. It runs only with ONDE_WEB_SMOKE set, so CI compiles it and does not run it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si> Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
There was a problem hiding this comment.
This PR turns the wasm32-unknown-unknown target from the stub into a real browser engine. build.rs adds the onde_web cfg (wasm32 + unknown OS only), Cargo.toml adds candle/tokenizers/web-sys under that target, and engine.rs re-exports super::web::ChatEngine in its place, with the qwen25/qwen3 presets now setting tok_model_id on web as they already did on Android. New text.rs holds the host-testable ChatML prompt builder and logit penalties; new web/mod.rs implements the full ChatEngine surface (prefill chunked with event-loop yields, token streaming with cancel-on-drop via a tokio channel, <think> splitting for history, tool calling reporting Unsupported); new web_store.rs mirrors hf_cache over Cache Storage with streamed download progress. CI compiles (but does not run) the gated web_smoke browser test.
Reviewers should look first at web/mod.rs's generation loop and web_store.rs's download path. Two things worth knowing: the whole GGUF is buffered into wasm memory at load time (see finding), and the smoke test only exercises the Qwen2.5 path — the Qwen3 weights, the <think> handling, and the penalties are untested in a browser.
Automated review by siGit Code Review · commit 731c53a · see the review dashboard
send_message returned the model's raw text while history and complete() both split off Qwen3's <think> block, so a thinking model gave callers the reasoning mixed into the reply. It now returns the reply alone, trimmed like the native engine. load_file now documents its peak memory (about three times the file size), and the prepare_turn comment says the busy guard runs first. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si> Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
…eplies build.sh now appends +simd128 to an exported RUSTFLAGS instead of dropping it. The worker answers a message that arrives before Ed has started with an error instead of ignoring it. A reply that fails after some tokens streamed keeps its text and gets the error appended. The onde comment in Cargo.toml now says the dependency waits on ondeinference/onde#50 rather than on a version number. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: siGit Code v1.7.10 <noreply@sigit.si> Co-Authored-By: OndeCode v1.1.2 <noreply@ondeinference.com>
There was a problem hiding this comment.
Re-review of the follow-up commit 731c53a. Both earlier findings on src/inference/web/mod.rs are addressed: send_message now returns split_think(&out.text).0 so callers get the same text that commit_turn stores in history, and the prepare_turn doc comment now correctly says it runs after the busy guard. The web_store.rs memory finding was resolved by documenting the ~3x peak-wasm-memory behaviour on load_file rather than changing the code, which is a reasonable call given the constraints; the thread stays settled. No new issues in the diff.
Automated review by siGit Code Review · commit dfe2641 · changes since 731c53a · see the review dashboard
On
wasm32-unknown-unknown,ChatEngineis now a real engine instead of the stub. It runs GGUF Qwen2.5 and Qwen3 models on the CPU through candle, single threaded, with the tokenizer loaded fromtok_model_id. The public signatures match the native engine, soed-agentcompiles against it unchanged. Tool calling reportsUnsupported. Other wasm and unknown targets keep the stub.Model files come from Hugging Face and are kept in Cache Storage (
onde-models-v1), which works from a window and from a worker.web_store::download_modelmirrorshf_cache::download_modelwith a progress callback, andis_cachedanddelete_modelmanage the cache.Generation builds a ChatML prompt, samples from
SamplingConfig, and yields to the event loop between tokens, so a cancel or a dropped stream is seen.build.rsgains theonde_webcfg, and the qwen25 and qwen3 presets settok_model_idon web as they do on Android.This has no version bump. The release is separate.
Testing
tests/web_smoke.rsdownloads Qwen 2.5 0.5B in headless Chrome and checks a streamed reply. It only runs withONDE_WEB_SMOKEset, so CI compiles it and does not run it, because of the 380 MB download.I also ran the engine through the Ed web example in ondeinference/ed#62: the model downloads with progress, two turns stream with the second using the first as context, and a reload loads from the cache without downloading again. It runs at roughly 1 to 2.5 tokens/s on an Apple Silicon Mac.