Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Add Bonsai 2 text and vision WebGPU presets
Barack Sokullubf2c982a0102
diff --git a/docs/providers-and-models.md b/docs/providers-and-models.mdindex 3c123b3f9..1ce140ffd 100644--- a/docs/providers-and-models.md+++ b/docs/providers-and-models.md@@ -273,7 +273,7 @@ class BaseLLMProvider {| `gpt4all` | `openai` | local | (loaded model) | Yes (default on) || `local_openai_proxy` | `openai` | local | (required) | Off / manual toggle || `unsloth` | `openai` | local | (required) | Off / manual toggle |-| `webgpu` (Chromium) | `webgpu` | local | Compass Tiny v2.1 (only preset); experimental custom HF ONNX repos | No |+| `webgpu` (Chromium) | `webgpu` | local | Compass Tiny v2.1; Ternary Bonsai 2 2B / 4B, text or vision | Bonsai Vision presets only || `azure_openai` | `azure_openai` | cloud | (deployment) | Manual toggle || `aws_bedrock` | `aws_bedrock` | cloud | (model id) | No || `openai` | `openai` | cloud | `gpt-5.6-terra` | Model-name regex |@@ -417,8 +417,21 @@ duplicate request.### Local Providers-On Chromium, **WebGPU (In-browser)** is an endpoint-free local provider. Its-Apocalypse text picker offers a single shipped preset:+On Chromium, **WebGPU (In-browser)** is an endpoint-free local provider.+Settings and Apocalypse Mode offer the same five presets, in this order:++| Model | Download | Images | Browser context |+| --- | --- | --- | --- |+| [Compass Tiny v2.1](https://huggingface.co/webbrain-one/webbrain-compass-tiny-v2.1) (default) | 1.87 GB, Q4/FP16 | No | 32k |+| [Ternary Bonsai 2 2B](https://huggingface.co/danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU) | 787 MB, Q2/FP16 | No | 16k |+| [Ternary Bonsai 2 4B](https://huggingface.co/Mike0021/Ternary-Bonsai-2-4B-text-ONNX) | 1.50 GB, Q2/FP16 | No | 16k |+| [Ternary Bonsai 2 2B Vision](https://huggingface.co/webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision) | 1.45 GB, Q2/FP16 | Yes | 16k |+| [Ternary Bonsai 2 4B Vision](https://huggingface.co/webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision) | 2.15 GB, Q2/FP16 | Yes | 16k |++Download sizes are approximate and exclude GPU working memory. Bonsai's native+context is larger; the browser defaults limit cache growth. Each model has its+own download and readiness state. Changing models preserves already downloaded+files, and switching back can reuse them.- [`webbrain-one/webbrain-compass-tiny-v2.1`](https://huggingface.co/webbrain-one/webbrain-compass-tiny-v2.1)(`q4f16`, about 1.87 GB across two external-data shards), WebBrain's Compass@@ -427,24 +440,55 @@ Apocalypse text picker offers a single shipped preset:Runtime Web GPU worker, and emits MiniCPM5 XML-style tool calls(`<function name="..."><param name="...">...</param></function>`, CDATA-wrappedwhen values contain `<`, `&`, or newlines), which the local fallback parser- accepts. Enabling Apocalypse Mode starts this download automatically.+ accepts. Enabling Apocalypse Mode downloads the selected preset; Compass is+ the default for a new installation.++Bonsai uses the packaged Qwen3.5 runtime and Q2 weight storage with FP16+activations. Its text presets reject image attachments. The Vision variants+retain Prism ML's original image tower and add its processor and image graph+to the ternary language export. They accept screenshots directly as the main+provider and also work for text-only turns. They do not enable or replace the+separate 450M assistive vision fallback. Browser image processing is bounded to+approximately one megapixel per image. Build sources, tensor mapping checks,+and the hardware browser verification command are documented in+[`scripts/models/bonsai/README.md`](../scripts/models/bonsai/README.md).++To verify the published text presets through the packaged production worker,+run these commands from the repository root with its Playwright Chromium+installed:++```powershell+node scripts/check-bonsai-webgpu.mjs --model danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU --profile .build/bonsai/text-2b-profile --output .build/bonsai/text-2b-result.json+node scripts/check-bonsai-webgpu.mjs --model Mike0021/Ternary-Bonsai-2-4B-text-ONNX --profile .build/bonsai/text-4b-profile --output .build/bonsai/text-4b-result.json+```++These commands download model files, run text and tool-call/result checks on+hardware WebGPU, and save JSON evidence. `--probe-only` checks the adapter and+packaged runtime without downloading weights. `--offline` repeats inference+using an existing profile and port (default 8769), requiring cached readiness+and rejecting Hugging Face fetches. Vision builds also require `--vision`;+the build README gives exact commands for local export folders, image history,+cache refresh after rebuilding, and recording browser evidence. The separate+`node test/quality/webgpu-presets-mv3.mjs` check exercises the installed extension's+five model choices and saved settings with mocked cache readiness; it does not+establish model inference quality.Custom Hugging Face repositories have not been tested and are likely not towork. They must be compatible with Transformers.js text generation, provide a`q4f16` ONNX variant, and use a chat template that accepts `tools`; WebBrainvalidates the template after loading and rejects incompatible repositories.-The provider is text-only and defaults to the Compact prompt tier with a-32k context window. Budget roughly 4 GB of GPU headroom (about 1.87 GB of+The provider defaults to the Compact prompt tier. For Compass, budget roughly+4 GB of GPU headroom (about 1.87 GB ofweights plus KV cache that grows with context length); on constrained GPUs,lower the context window on the WebGPU card in Settings → Providers (16384 isa safe fallback) and retry with a short prompt. Each repository is cachedseparately in Chrome.-After downloading Compass in Apocalypse Mode, the WebGPU card in+After downloading a preset in Apocalypse Mode, the WebGPU card in**Settings -> Providers** can be configured, tested, and selected as the normalchat provider. The nuclear standalone-chat control remains available as aper-run override that does not change the global selection. Once its files are-cached, Compass works without Apocalypse Mode enabled.+cached, the selected model works without Apocalypse Mode enabled.**Test Connection** checks only the packaged runtime and hardware WebGPUadapter, so it does not trigger a model download. There is no API key, baseURL, localhost server, or OpenAI-compatible endpoint. Firefox does not exposediff --git a/scripts/check-bonsai-webgpu.mjs b/scripts/check-bonsai-webgpu.mjsnew file mode 100644index 000000000..8bfb2b11c--- /dev/null+++ b/scripts/check-bonsai-webgpu.mjs@@ -0,0 +1,255 @@+import assert from 'node:assert/strict';+import fs from 'node:fs/promises';+import { createReadStream } from 'node:fs';+import http from 'node:http';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { chromium } from 'playwright';++// Runs the packaged production inference worker on hardware WebGPU. Local repo+// mappings serve unpublished artifacts without changing model code or metadata.+const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const args = process.argv.slice(2);+const option = (name, fallback) => {+ const index = args.indexOf(name);+ return index < 0 ? fallback : args[index + 1];+};+if (args.includes('--help')) {+ console.log(`Usage: node scripts/check-bonsai-webgpu.mjs --model owner/repo [--vision]+ --local-repo owner/repo=directory Serve local artifacts (repeatable)+ --profile directory Reuse browser cache (default .build/bonsai/browser-profile)+ --output file JSON evidence (default .build/bonsai/browser-result.json)+ --probe-only Check hardware/runtime without downloading+ --offline Require cached files; reject HF network fetches+ --clear-model-cache Delete only the selected model's cached files+ --adapter-luid high,low Select a Windows GPU without changing OS settings+ --skip-tools Skip the tool-template round trip+ --vision Verify two independent image-only facts+ --ocr Check exact image-only codes instead of color/shape+ --image-history Also verify a turn with two differently sized images+ --compact-images Use low-resolution OCR fixtures (196/216 image tokens)+ --timeout-ms N Per-operation deadline (default 1800000)+ --port N Stable origin for cache reuse (default 8769)`);+ process.exit(0);+}+const model = option('--model', 'danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU');+const vision = args.includes('--vision');+const ocr = args.includes('--ocr');+assert(!ocr || vision, '--ocr requires --vision');+const dtype = vision+ ? { embed_tokens: 'q2f16', vision_encoder: 'fp16', decoder_model_merged: 'q2f16' }+ : 'q2f16';+const localRepos = {};+for (let index = 0; index < args.length; index++) {+ if (args[index] !== '--local-repo') continue;+ const entry = args[++index] || '';+ const separator = entry.indexOf('=');+ assert(separator > 0, '--local-repo requires owner/repo=directory');+ localRepos[entry.slice(0, separator)] = path.resolve(entry.slice(separator + 1));+}+const output = path.resolve(option('--output', '.build/bonsai/browser-result.json'));+const profile = path.resolve(option('--profile', '.build/bonsai/browser-profile'));+const timeout = Number(option('--timeout-ms', 30 * 60_000));+const result = { model, dtype, vision, ocr, compactImages: !ocr || args.includes('--compact-images'), startedAt: new Date().toISOString(), checks: [], errors: [] };+const workerBootstrap = `+const nativeFetch = globalThis.fetch.bind(globalThis);+const mapped = ${JSON.stringify(Object.keys(localRepos))};+globalThis.fetch = (input, init) => {+ const source = typeof input === 'string' ? input : input.url || String(input);+ const url = new URL(source, self.location.href);+ if (url.hostname === 'huggingface.co') {+ if (${args.includes('--offline')}) throw new Error('Offline verification blocked a Hugging Face fetch: ' + url.pathname);+ const match = url.pathname.match(/^\\/([^/]+\\/[^/]+)\\/resolve\\/[^/]+\\/(.+)$/);+ if (match && mapped.includes(match[1])) {+ return nativeFetch('/models/' + match[1] + '/' + match[2], init);+ }+ }+ return nativeFetch(input, init);+};+await import('/extension/src/offscreen/inference-worker.js');+self.postMessage({ type: 'harness-ready' });+`;+const mime = file => ({ '.mjs': 'text/javascript', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm', '.html': 'text/html' }[path.extname(file)] || 'application/octet-stream');+const server = http.createServer(async (request, response) => {+ response.setHeader('Cross-Origin-Opener-Policy', 'same-origin');+ response.setHeader('Cross-Origin-Embedder-Policy', 'credentialless');+ response.setHeader('Access-Control-Allow-Origin', '*');+ try {+ const pathname = decodeURIComponent(new URL(request.url, 'http://localhost').pathname);+ if (pathname === '/favicon.ico') { response.writeHead(204); response.end(); return; }+ if (pathname === '/') {+ response.setHeader('Content-Type', 'text/html');+ response.end('<!doctype html><title>Bonsai WebGPU verification</title>Production WebGPU worker verification');+ return;+ }+ if (pathname === '/worker.mjs') {+ response.setHeader('Content-Type', 'text/javascript'); response.end(workerBootstrap); return;+ }+ let base, relative;+ if (pathname.startsWith('/extension/')) {+ base = path.join(root, 'src/chrome'); relative = pathname.slice('/extension/'.length);+ } else if (pathname.startsWith('/models/')) {+ const match = pathname.match(/^\/models\/([^/]+\/[^/]+)\/(.+)$/);+ base = match && localRepos[match[1]]; relative = match?.[2];+ }+ if (!base || !relative) { response.writeHead(404); response.end(); return; }+ const file = path.resolve(base, relative);+ if (!file.startsWith(path.resolve(base) + path.sep)) { response.writeHead(403); response.end(); return; }+ const stat = await fs.stat(file);+ response.setHeader('Content-Type', mime(file));+ response.setHeader('Content-Length', stat.size);+ if (request.method === 'HEAD') response.end();+ else createReadStream(file).on('error', () => response.destroy()).pipe(response);+ } catch (error) {+ response.writeHead(error.code === 'ENOENT' ? 404 : 500); response.end(error.code || 'file error');+ }+});+await fs.mkdir(path.dirname(output), { recursive: true });+await fs.mkdir(profile, { recursive: true });+await new Promise((resolve, reject) => { server.once('error', reject); server.listen(Number(option('--port', 8769)), '127.0.0.1', resolve); });+let context;+try {+ context = await chromium.launchPersistentContext(profile, {+ headless: true,+ channel: 'chromium',+ args: ['--enable-unsafe-webgpu', '--force-high-performance-gpu',+ ...(option('--adapter-luid', '') ? [`--use-adapter-luid=${option('--adapter-luid')}`] : [])],+ });+ const page = await context.newPage();+ page.on('console', message => {+ if (message.type() === 'error') result.errors.push(message.text().slice(0, 2000));+ console.log(`[browser:${message.type()}] ${message.text().slice(0, 1000)}`);+ });+ page.on('pageerror', error => result.errors.push(error.message));+ await page.goto(`http://127.0.0.1:${server.address().port}`);+ await page.evaluate(() => new Promise((ready, failed) => {+ const pending = new Map(); let id = 0, progressAt = 0;+ const worker = new Worker('/worker.mjs', { type: 'module' });+ worker.onmessage = ({ data }) => {+ if (data.type === 'harness-ready') { ready(); }+ else if (data.id && pending.has(data.id)) {+ const { resolve, reject, timer } = pending.get(data.id);+ clearTimeout(timer); pending.delete(data.id);+ if (data.ok === false) reject(new Error(data.error)); else resolve(data);+ } else if (data.type === 'text-download-state' && Date.now() - progressAt > 10_000) {+ progressAt = Date.now(); console.log(JSON.stringify(data.state));+ }+ };+ worker.onerror = event => {+ failed(new Error(event.message));+ for (const { reject, timer } of pending.values()) { clearTimeout(timer); reject(new Error(event.message)); }+ pending.clear();+ };+ window.workerCall = (type, payload, timeout) => new Promise((resolve, reject) => {+ const requestId = ++id;+ const timer = setTimeout(() => { pending.delete(requestId); reject(new Error(`Timeout: ${type}`)); }, timeout);+ pending.set(requestId, { resolve, reject, timer });+ worker.postMessage({ id: requestId, type, payload });+ });+ }));+ const call = (type, payload = {}) => page.evaluate(({ type, payload, timeout }) => window.workerCall(type, payload, timeout), { type, payload, timeout });+ const origin = new URL(page.url()).origin;+ await call('init', {+ transformersUrl: `${origin}/extension/vendor/transformers/transformers.web.js`,+ wasmMjsUrl: `${origin}/extension/vendor/transformers/ort-wasm-simd-threaded.asyncify.mjs`,+ wasmUrl: `${origin}/extension/vendor/transformers/ort-wasm-simd-threaded.asyncify.wasm`,+ });+ result.probe = await call('probe');+ console.log(JSON.stringify({ probe: result.probe }));+ assert(result.probe.hasWebGPU, 'Hardware WebGPU required');+ assert(!result.probe.isFallbackAdapter, 'Software WebGPU cannot validate this model');+ result.adapter = await page.evaluate(async () => {+ const adapter = await navigator.gpu.requestAdapter({ powerPreference: 'high-performance' });+ return { vendor: adapter?.info.vendor, architecture: adapter?.info.architecture, description: adapter?.info.description, device: adapter?.info.device };+ });+ if (!args.includes('--probe-only')) {+ if (args.includes('--clear-model-cache')) {+ assert(!args.includes('--offline'), '--clear-model-cache cannot be used with --offline');+ await call('stop-text-download', { modelId: model, dtype });+ }+ const loadStarted = Date.now();+ result.offline = args.includes('--offline');+ result.download = await call(result.offline ? 'text-download-status' : 'download-text', { modelId: model, dtype, device: 'webgpu' });+ result.loadSeconds = (Date.now() - loadStarted) / 1000;+ assert(result.download.ready, 'Download did not become ready');+ const chat = async (name, messages, options = {}) => {+ const started = Date.now();+ const response = await call(vision ? 'multimodal-text-chat' : 'text-chat', { modelId: model, dtype, device: 'webgpu', messages, options: { maxTokens: 160, ...options } });+ result.checks.push({ name, seconds: (Date.now() - started) / 1000, ...response });+ console.log(JSON.stringify(result.checks.at(-1)));+ return response;+ };+ const reply = await chat('text', [{ role: 'user', content: 'What is 17 plus 26? Reply with only the number.' }]);+ assert.match(reply.content, /^\s*43[.!]?\s*$/, 'Text answer must be correct and terminate at the end of its turn');+ if (!args.includes('--skip-tools')) {+ const tools = [{ type: 'function', function: { name: 'get_weather', description: 'Look up the current weather for a city.', parameters: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] } } }];+ const toolReply = await chat('tool-call', [{ role: 'system', content: 'Use the provided tool for weather requests.' }, { role: 'user', content: 'What is the weather in Istanbul? Call the weather tool.' }], { tools, maxTokens: 300 });+ assert.match(JSON.stringify(toolReply), /get_weather/);+ assert.match(JSON.stringify(toolReply), /Istanbul/i);+ assert.equal((toolReply.content.match(/<tool_call>/g) || []).length, 1, 'Expected one complete tool call');+ assert.match(toolReply.content, /<\/tool_call>/, 'Truncated tool call');+ const followup = await chat('tool-result', [+ { role: 'user', content: 'What is the weather in Istanbul?' },+ { role: 'assistant', content: '', tool_calls: [{ id: 'weather-1', type: 'function', function: { name: 'get_weather', arguments: '{"city":"Istanbul"}' } }] },+ { role: 'tool', tool_call_id: 'weather-1', content: '{"city":"Istanbul","temperature_celsius":19,"condition":"sunny"}' },+ ], { tools });+ assert.match(followup.content, /19/);+ }+ if (vision) {+ const history = [];+ const imageFailures = [];+ for (const [color, code, shape] of [['red', 'K7M2', 'rectangle'], ['blue', 'R4X9', 'circle']]) {+ // Prism recommends at least 1024 visual tokens for OCR. Use ~1MP+ // fixtures by default; compact mode preserves the earlier low-resolution+ // quality check without changing the application's image processor.+ const image = await page.evaluate(({ color, code, shape, compact, ocr }) => {+ const width = color === 'red' ? 448 : 576;+ const height = color === 'red' ? 448 : 384;+ const canvas = document.createElement('canvas');+ canvas.width = compact ? width : color === 'red' ? 1024 : 1248;+ canvas.height = compact ? height : color === 'red' ? 1024 : 832;+ const ctx = canvas.getContext('2d'); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height);+ ctx.scale(canvas.width / width, canvas.height / height);+ ctx.fillStyle = color;+ if (ocr || shape === 'rectangle') ctx.fillRect(64, 40, width - 128, 180);+ else { ctx.beginPath(); ctx.arc(width / 2, 130, 90, 0, 2 * Math.PI); ctx.fill(); }+ if (ocr) { ctx.font = 'bold 76px Arial'; ctx.fillStyle = 'black'; ctx.textAlign = 'center'; ctx.fillText(code, width / 2, 340); }+ return canvas.toDataURL('image/png');+ }, { color, code, shape, compact: result.compactImages, ocr });+ await fs.writeFile(output.replace(/\.json$/, '') + `-${color}.png`, Buffer.from(image.split(',')[1], 'base64'));+ const message = { role: 'user', content: [+ { type: 'image_url', image_url: { url: image } },+ { type: 'text', text: ocr+ ? 'What color is the rectangle, and what four-character code is printed below it? Reply with the color and code.'+ : 'What color is the large shape, and what is its shape? Reply with the color and shape.' },+ ] };+ const answer = await chat(`image-${color}`, [message]);+ if (!new RegExp(color, 'i').test(answer.content)) imageFailures.push(`${color}: wrong image color`);+ if (ocr && !answer.content.replace(/\s/g, '').includes(code)) imageFailures.push(`${color}: wrong image-only code (expected ${code})`);+ if (!ocr && !new RegExp(shape, 'i').test(answer.content)) imageFailures.push(`${color}: wrong image shape (expected ${shape})`);+ history.push(message, { role: 'assistant', content: answer.content });+ }+ if (args.includes('--image-history')) {+ const answer = await chat('image-history', [...history, { role: 'user', content: ocr+ ? 'Repeat only the color and four-character code from the SECOND image.'+ : 'Repeat only the color and shape from the SECOND image.' }]);+ if (!/blue/i.test(answer.content)) imageFailures.push('history: wrong image selected');+ if (ocr && !answer.content.replace(/\s/g, '').includes('R4X9')) imageFailures.push('history: wrong image-only code');+ if (!ocr && !/circle/i.test(answer.content)) imageFailures.push('history: wrong image shape');+ }+ assert.deepEqual(imageFailures, [], 'Image checks failed');+ }+ await call('dispose-all');+ result.cacheAfterDispose = await call('text-download-status', { modelId: model, dtype });+ assert(result.cacheAfterDispose.ready, 'Disposing GPU allocations lost download readiness');+ }+ result.passed = true;+} catch (error) {+ result.passed = false; result.failure = error.stack; console.error(error); process.exitCode = 1;+} finally {+ result.finishedAt = new Date().toISOString();+ await fs.writeFile(output, JSON.stringify(result, null, 2) + '\n');+ await context?.close();+ await new Promise(resolve => server.close(resolve));+ console.log(`Evidence: ${output}`);+}diff --git a/scripts/models/bonsai/README.md b/scripts/models/bonsai/README.mdnew file mode 100644index 000000000..6f280eb06--- /dev/null+++ b/scripts/models/bonsai/README.md@@ -0,0 +1,155 @@+# Bonsai 2 vision ONNX builds++`build_vision.py` creates the 2B and 4B image-capable WebBrain model bundles.+It runs independently of the extension and has no effect on packaged JavaScript+dependencies. Generated files stay in the ignored `.build/bonsai` directory.++```powershell+uv venv --python 3.12 .build/bonsai/venv+uv pip install --python .build/bonsai/venv/Scripts/python.exe -r scripts/models/bonsai/requirements.txt+.build/bonsai/venv/Scripts/python.exe scripts/models/bonsai/build_vision.py+```++The default builds both sizes. `--size 2B` or `--size 4B` selects one. Use+`--offline` after all pinned source files have been downloaded. The sources are+public and the build explicitly downloads without credentials; do not put a+Hugging Face token in this directory, a command-line argument, or a model card.+The optional `--skip-inference` only skips the CPU vision graph smoke check and+records it as unverified; it does not bypass tensor and ONNX graph checks.+Rebuilding removes previously attached successful browser/native reports from+the export folder so new artifacts cannot inherit stale validation evidence.+Keep raw reports outside that folder and rerun validation after a rebuild.++The downloads total approximately 5.4 GB. Allow additional room for generated+vision graphs and browser caches. Unchanged language graphs are hardlinked into+the export directory on supported filesystems. The build does not upload files.++## Source and conversion contract++Each size has three revision-pinned inputs in the script:++- `prism-ml/Ternary-Bonsai-2-{2B,4B}-mlx-2bit`: original vision weights and license.+- `danyalmalik/Ternary-Bonsai-2-{2B,4B}-ONNX-WebGPU`: exact ternary language graphs,+ tokenizer and model configuration, including the required Hadamard transforms.+- `onnx-community/Qwen3.5-{2B,4B}-ONNX`: compatible vision graph topology and+ processor/tokenizer sidecars.++Every learned vision initializer is replaced from the matching Prism pack.+The export checks both directions of the tensor mapping: no unexported source+weights and no unmatched learned ONNX initializers. MLX Conv3D weights use+`[out,time,height,width,channels]`; ONNX flattened patches use+`[channels,time,height,width]`. Linear kernels are transposed. FP16 source values+are preserved exactly, with FP32 widening where the graph uses FP32 norms and+position embeddings. Generated constants and rotary frequencies remain in the+pinned topology.++The existing text embedding graph already applies the inverse Hadamard transform+and returns embeddings in the original residual basis. The restored vision+embeddings therefore need no extra Hadamard rotation. The decoder already accepts+Qwen's three-axis position IDs and hybrid attention caches.++## Runtime contract++Load `AutoProcessor` and `AutoModelForImageTextToText` with:++```javascript+{+ device: 'webgpu',+ dtype: {+ embed_tokens: 'q2f16',+ decoder_model_merged: 'q2f16',+ vision_encoder: 'fp16',+ },+}+```++The three ONNX graphs each have one external `.onnx_data` file. The exported+configuration adds the missing `q2f16: float16` cache dtype. The runtime must+support `MatMulNBits(bits=2)` and `GatherBlockQuantized`, Qwen3.5 recurrent state,+FP16 WebGPU shaders, and the Qwen image processor/chat template. Vision graph+inputs are `pixel_values: float32[num_patches,1536]` and+`image_grid_thw: int64[num_images,3]`. Output `image_features` is+`float32[num_patches/4,2048]` for 2B and `float32[num_patches/4,2560]` for 4B.++## Validation and publishing++Each bundle includes a model card, upstream LICENSE and NOTICE, SHA-256 manifest,+and `export-validation.json`. Validation checks full tensor coverage, serialized+tensor hashes, ONNX structural validity, finite outputs for square and rectangular+image grids, and different embeddings for different image pixels. These CPU graph+checks do not establish language answer quality or browser compatibility.++Before uploading, run `scripts/check-bonsai-webgpu.mjs` through the production+browser worker for text generation and independent image-only facts. It uses the+repository's Playwright dependency and installed Chromium; if Chromium is missing,+run `npx playwright install chromium`. Run one hardware verification at a time.+From the repository root in PowerShell:++```powershell+$bonsaiSize = '2B'+$bonsaiRepo = "webbrain-one/Ternary-Bonsai-2-$bonsaiSize-ONNX-WebGPU-Vision"+$bonsaiBundle = ".build/bonsai/exports/Ternary-Bonsai-2-$bonsaiSize-ONNX-WebGPU-Vision"+$bonsaiProfile = ".build/bonsai/vision-$bonsaiSize-profile"+node scripts/check-bonsai-webgpu.mjs --model $bonsaiRepo --vision --image-history --local-repo "$bonsaiRepo=$bonsaiBundle" --profile $bonsaiProfile --clear-model-cache --output ".build/bonsai/vision-$bonsaiSize-result.json"+node scripts/check-bonsai-webgpu.mjs --model $bonsaiRepo --vision --image-history --profile $bonsaiProfile --offline --output ".build/bonsai/vision-$bonsaiSize-offline-result.json"+```++Repeat with `$bonsaiSize = '4B'` and recalculate the three variables. The first+command serves the unpublished export locally under its intended repository ID+and clears only that model's old cached files before loading. Use it again after+rebuilding model artifacts so an earlier cached graph cannot mask a changed+export. The second command uses the same browser profile and origin (default+port 8769), rejects Hugging Face fetches, and requires the first run's cached+readiness marker. Do not combine `--offline` with `--clear-model-cache`.++The checks cover text, tool-call/result turns, separate color/shape image fixtures,+and, with `--image-history`, differently sized screenshots in one conversation.+`--ocr` runs strict exact-code OCR checks; it is a separate quality check and its+failure reports must be preserved. The 2B model has omitted/confused characters+in these fixtures even when using 1,024 visual tokens. `--compact-images` selects+lower-resolution image fixtures; the JSON evidence+records that choice. `--probe-only` checks hardware/runtime without loading+weights. `--adapter-luid high,low` can select a specific Windows GPU without+changing system settings. See `--help` for operation deadlines and output paths.+These checks establish the recorded synthetic cases on the tested browser/GPU,+not broad OCR or model-quality performance.++Record a successful result alongside the export validation and reseal the+SHA-256 manifest:++```powershell+.build/bonsai/venv/Scripts/python.exe scripts/models/bonsai/record_browser_validation.py --bundle $bonsaiBundle --evidence ".build/bonsai/vision-$bonsaiSize-result.json"+```++The recorder requires a passing hardware WebGPU run for the matching model with+text, tool round trips, and both image color/shape fixtures. It preserves the full+evidence and its practical limitation to the tested browser/GPU and synthetic+images. Publish only the export folder contents;+the source packs, environment, download caches, and browser profile are local+build inputs. Intended repository IDs are+`webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision` and+`webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision`.++## Native vision parity++`validate_vision_reference.py` independently loads the original Prism tower into+the native Transformers Qwen3.5 eager implementation, using FP32 calculations,+and compares it with the FP16 ONNX export. It covers square, rectangular,+multiple-image, and realistic 28×28 patch grids (448-pixel image). The report+records relative error, cosine similarity, software versions and tested graph+hashes. This checks encoder math; browser tests still cover image integration+with the language model.++It additionally needs `transformers==5.20.1` and a compatible PyTorch runtime.+The recorded run used PyTorch 2.9.1+cu128 on the RTX5090. An existing compatible+Python environment's Torch can be reused with `--torch-site-packages` without+upgrading that environment. Otherwise use a dedicated environment with Torch+already installed. For example:++```powershell+.build/bonsai/venv/Scripts/python.exe scripts/models/bonsai/validate_vision_reference.py --size 2B --device cuda:0 --grid-size 28 --output .build/bonsai/vision-native-parity-2b.json+```++Repeat with `--size 4B` and a separate output filename. The native reference+checks original source-pack hashes before loading and uses no model repository+Python code. Include its JSON evidence in the bundle before resealing the manifest.diff --git a/scripts/models/bonsai/build_vision.py b/scripts/models/bonsai/build_vision.pynew file mode 100644index 000000000..e9124b9d7--- /dev/null+++ b/scripts/models/bonsai/build_vision.py@@ -0,0 +1,342 @@+"""Build WebBrain's Bonsai vision ONNX bundles from revision-pinned sources.++The language graphs are already lossless ternary exports. Re-exporting them+through dense weights would lose that property. The official vision weights+are plain FP16, so insert every original tower tensor into the compatible+Qwen3.5 ONNX topology, accounting for MLX's Conv3D layout.+"""++import argparse+import hashlib+import json+import os+import re+import shutil+from pathlib import Path++import numpy as np+import onnx+import onnxruntime as ort+from huggingface_hub import snapshot_download+from onnx import numpy_helper+from safetensors import safe_open+++SOURCES = {+ "2B": {+ "prism": ("prism-ml/Ternary-Bonsai-2-2B-mlx-2bit", "1c6cbae21f8c38830ce337972b46fdae7b18eaaa"),+ "text": ("danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU", "a3c26c4d363186f744b20e08d585ce43e2ce7e8d"),+ "vision": ("onnx-community/Qwen3.5-2B-ONNX", "315216e893038beefcc6eba41ac168913dd0d879"),+ },+ "4B": {+ "prism": ("prism-ml/Ternary-Bonsai-2-4B-mlx-2bit", "dff2caaa23fa8706164c44c10f1b58feb405f76a"),+ "text": ("danyalmalik/Ternary-Bonsai-2-4B-ONNX-WebGPU", "3e0b805e22baf98858057b80cfa637c2b6c77521"),+ "vision": ("onnx-community/Qwen3.5-4B-ONNX", "23ac3352f288351eddcdf141b32f4f66587f7e2d"),+ },+}+PATTERNS = {+ "prism": ["model.safetensors", "config.json", "LICENSE", "NOTICE.txt"],+ "text": ["onnx/*", "config.json", "tokenizer.json", "LICENSE", "NOTICE.txt"],+ "vision": ["onnx/vision_encoder_fp16.onnx", "tokenizer_config.json", "preprocessor_config.json",+ "processor_config.json", "generation_config.json", "chat_template.jinja"],+}+VISION_PACK_SHA256 = {+ "2B": "da5095b9f34d7f0d5094090afeeadf124eef821c75136dc28957ce586ae7ac0c",+ "4B": "432f48d0edcb8da2e6a4e0c96078588362397e2603e7fdea99957babfe968259",+}+++def read_json(path):+ return json.loads(path.read_text(encoding="utf-8"))+++def write_json(path, value):+ path.write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8")+++def digest(path):+ with path.open("rb") as stream:+ return hashlib.file_digest(stream, "sha256").hexdigest()+++def link_or_copy(source, target):+ """Keep immutable large source graphs shared with the distributable bundle."""+ if target.exists():+ if os.path.samefile(source, target):+ return+ target.unlink()+ try:+ target.hardlink_to(source)+ except OSError:+ shutil.copy2(source, target)+++def seal_manifest(output):+ files = [{"path": str(path.relative_to(output)).replace("\\", "/"), "size": path.stat().st_size,+ "sha256": digest(path)} for path in sorted(output.rglob("*"))+ if path.is_file() and path.name != "manifest.json" and ".cache" not in path.parts]+ total = sum(file["size"] for file in files)+ write_json(output / "manifest.json", {"format": "webbrain-bonsai-vision-v1", "files": files,+ "total_bytes": total})+ return total+++def source_tensor_name(name):+ """Map pinned ONNX names to the original Prism MLX namespace, fail closed."""+ if name == "model.embeddings.patch_embed.weight":+ return "vision_tower.patch_embed.proj.weight", "mlx-conv3d"+ if name == "model.embeddings.patch_embed.Add.bias":+ return "vision_tower.patch_embed.proj.bias", "identity"+ if name == "model.pos_embed.weight":+ return "vision_tower.pos_embed.weight", "identity"+ name = name.replace("model.layers.merger.merger_norm_layernorm.", "vision_tower.merger.norm.")+ name = name.replace("model.merger.linear1.", "vision_tower.merger.linear_fc1.")+ name = name.replace("model.merger.linear2.", "vision_tower.merger.linear_fc2.")+ name = re.sub(r"^model\.layers\.(\d+)\.", r"vision_tower.blocks.\1.", name)+ name = name.replace("norm1_layernorm", "norm1").replace("norm2_layernorm", "norm2")+ transpose = ".MatMul.weight" in name+ name = name.replace(".MatMul.weight", ".weight").replace(".Add.bias", ".bias")+ if not name.startswith("vision_tower."):+ raise ValueError(f"Unmapped learned ONNX tensor: {name}")+ return name, "transpose" if transpose else "identity"+++def export_vision(prism, template, output):+ # All nonlearned constants are inline in this pinned topology. Loading its+ # large external weights would waste bandwidth: every one is replaced below.+ graph = onnx.load(template, load_external_data=False)+ records = []+ seen = set()+ with safe_open(prism / "model.safetensors", framework="np") as weights:+ source_names = {name for name in weights.keys() if name.startswith("vision_tower.")}+ for initializer in graph.graph.initializer:+ if initializer.name.startswith("/") or initializer.name == "model.vision.inv_freq":+ continue # Positional frequencies and graph shape constants are not learned.+ source_name, transform = source_tensor_name(initializer.name)+ if source_name in seen:+ raise ValueError(f"Source tensor mapped twice: {source_name}")+ seen.add(source_name)+ original = weights.get_tensor(source_name)+ if transform == "mlx-conv3d":+ # MLX stores [out, time, height, width, channels]. The graph's+ # patch rows use [channels, time, height, width].+ original = original.transpose(0, 4, 1, 2, 3).reshape(original.shape[0], -1).T+ elif transform == "transpose":+ original = original.T+ target_dtype = onnx.helper.tensor_dtype_to_np_dtype(initializer.data_type)+ converted = np.ascontiguousarray(original.astype(target_dtype))+ if converted.shape != tuple(initializer.dims) or not np.isfinite(converted).all():+ raise ValueError(f"Invalid tensor shape/value: {source_name}")+ records.append({+ "source": source_name,+ "target": initializer.name,+ "transform": transform,+ "shape": list(converted.shape),+ "dtype": str(converted.dtype),+ "sha256": hashlib.sha256(converted.tobytes()).hexdigest(),+ })+ initializer.CopyFrom(numpy_helper.from_array(converted, name=initializer.name))+ if seen != source_names:+ raise ValueError(f"Incomplete vision export: missing={source_names - seen}, extra={seen - source_names}")+ graph.doc_string = (+ "Modified by WebBrain: all learned vision tensors restored from the original "+ "Prism ML Ternary Bonsai 2 MLX pack. MLX Conv3D axes and linear kernels were "+ "transposed for this ONNX topology. Created using Bonsai by Prism ML. "+ "See export-validation.json for pinned source revisions and tensor hashes."+ )+ output.parent.mkdir(parents=True, exist_ok=True)+ # ONNX appends to existing external data files. Only these exact build+ # outputs are replaced, never source files or arbitrary directories.+ output.with_name(output.name + "_data").unlink(missing_ok=True)+ onnx.save_model(graph, output, save_as_external_data=True, all_tensors_to_one_file=True,+ location=output.name + "_data", size_threshold=1024)+ onnx.checker.check_model(str(output))+ saved = onnx.load(output)+ expected = {record["target"]: record for record in records}+ for tensor in saved.graph.initializer:+ if tensor.name in expected:+ actual = hashlib.sha256(numpy_helper.to_array(tensor).tobytes()).hexdigest()+ if actual != expected[tensor.name]["sha256"]:+ raise ValueError(f"Serialized tensor mismatch: {tensor.name}")+ return records+++def validate_vision(output, hidden_size):+ """Exercise dynamic rectangular grids and ensure pixels affect embeddings.++ This validates the vision graph only. Meaningful image answers are checked+ separately through the packaged browser worker before publication.+ """+ options = ort.SessionOptions()+ options.intra_op_num_threads = 8+ session = ort.InferenceSession(str(output), sess_options=options, providers=["CPUExecutionProvider"])+ results = []+ features = []+ pixel_inputs = []+ for rows, columns, channel in [(4, 4, 0), (4, 4, 2), (4, 6, 1)]:+ pixels = np.full((rows * columns, 3, 2, 16, 16), -1, dtype=np.float32)+ pixels[:, channel] = 1+ value = session.run(None, {+ "pixel_values": pixels.reshape(rows * columns, -1),+ "image_grid_thw": np.array([[1, rows, columns]], dtype=np.int64),+ })[0]+ expected = (rows * columns // 4, hidden_size)+ if value.shape != expected or not np.isfinite(value).all():+ raise ValueError(f"Vision inference failed for grid {rows}x{columns}")+ features.append(value)+ pixel_inputs.append(pixels.reshape(rows * columns, -1))+ results.append({"grid": [1, rows, columns], "output_shape": list(value.shape), "finite": True})+ difference = float(np.max(np.abs(features[0] - features[1])))+ if difference <= 0.001:+ raise ValueError("Vision output does not respond to different pixel inputs")+ # Conversation history can contain differently sized screenshots. Their+ # patches share one call but must not attend across the image boundary.+ multiple = session.run(None, {+ "pixel_values": np.concatenate([pixel_inputs[0], pixel_inputs[2]]),+ "image_grid_thw": np.array([[1, 4, 4], [1, 4, 6]], dtype=np.int64),+ })[0]+ separate = np.concatenate([features[0], features[2]])+ if not np.allclose(multiple, separate, rtol=0.02, atol=0.003):+ raise ValueError("Batched image features differ from independent image encoding")+ return {"provider": "CPUExecutionProvider", "fixtures": results,+ "red_blue_max_absolute_difference": difference,+ "multiple_image_max_absolute_difference": float(np.max(np.abs(multiple - separate)))}+++def build(size, workspace, offline=False, skip_inference=False):+ roots = {}+ for kind, (repo, revision) in SOURCES[size].items():+ roots[kind] = workspace / "sources" / size / kind+ if not offline:+ snapshot_download(repo, revision=revision, local_dir=roots[kind], allow_patterns=PATTERNS[kind],+ max_workers=3, token=False)+ prism, text, vision = (roots[name] for name in ("prism", "text", "vision"))+ source_pack_hash = digest(prism / "model.safetensors")+ if source_pack_hash != VISION_PACK_SHA256[size]:+ raise ValueError("Original vision pack SHA-256 differs from the pinned Hugging Face LFS object")+ print(f"{size}: original Prism vision pack SHA-256 verified", flush=True)+ output = workspace / "exports" / f"Ternary-Bonsai-2-{size}-ONNX-WebGPU-Vision"+ (output / "onnx").mkdir(parents=True, exist_ok=True)+ # A rebuilt package needs fresh external validation. Keep the original+ # reports outside this directory, but never seal a stale success report+ # into newly generated model artifacts.+ for filename in ("browser-validation.json", "native-vision-validation.json"):+ (output / filename).unlink(missing_ok=True)+ original_config = read_json(prism / "config.json")+ config = read_json(text / "config.json")+ if config["vision_config"] != original_config["vision_config"]:+ raise ValueError("Vision graph and original model architectures differ")+ if config["text_config"]["hidden_size"] != config["vision_config"]["out_hidden_size"]:+ raise ValueError("Vision and language embedding dimensions differ")+ for filename in ("decoder_model_merged_q2f16.onnx", "decoder_model_merged_q2f16.onnx_data",+ "embed_tokens_q2f16.onnx", "embed_tokens_q2f16.onnx_data"):+ source = text / "onnx" / filename+ link_or_copy(source, output / "onnx" / filename)+ shutil.copy2(text / "tokenizer.json", output / "tokenizer.json")+ for filename in ("tokenizer_config.json", "preprocessor_config.json", "processor_config.json",+ "generation_config.json", "chat_template.jinja"):+ shutil.copy2(vision / filename, output / filename)+ tokenizer_config = read_json(output / "tokenizer_config.json")+ tokenizer_config["tokenizer_class"] = "Qwen2Tokenizer"+ write_json(output / "tokenizer_config.json", tokenizer_config)+ # The upstream 16-megapixel ceiling is unsuitable for an interactive browser+ # worker. This is a processor default, not a change to the vision weights.+ preprocessor_config = read_json(output / "preprocessor_config.json")+ preprocessor_config["size"]["longest_edge"] = 1048576+ write_json(output / "preprocessor_config.json", preprocessor_config)+ processor_config = read_json(output / "processor_config.json")+ processor_config["image_processor"]["size"]["longest_edge"] = 1048576+ write_json(output / "processor_config.json", processor_config)+ config["transformers.js_config"] = {+ "use_external_data_format": {"vision_encoder_fp16.onnx": 1, "embed_tokens_q2f16.onnx": 1,+ "decoder_model_merged_q2f16.onnx": 1},+ "kv_cache_dtype": {"q2f16": "float16", "fp16": "float16"},+ }+ write_json(output / "config.json", config)+ shutil.copy2(prism / "LICENSE", output / "LICENSE")+ (output / "NOTICE.txt").write_text(+ (prism / "NOTICE.txt").read_text(encoding="utf-8") + "\n\n"+ + (text / "NOTICE.txt").read_text(encoding="utf-8") + "\n\n"+ + "Modified by WebBrain: restored the original Prism ML vision tower to the ONNX package; "+ + "adapted processor/runtime configuration. Created using Bonsai by Prism ML.\n",+ encoding="utf-8",+ )+ vision_output = output / "onnx" / "vision_encoder_fp16.onnx"+ records = export_vision(prism, vision / "onnx" / "vision_encoder_fp16.onnx", vision_output)+ print(f"{size}: exported and checked all {len(records)} vision tensors", flush=True)+ validation = None if skip_inference else validate_vision(vision_output, config["vision_config"]["out_hidden_size"])+ report = {+ "size": size,+ "sources": {kind: {"repo_id": repo, "revision": revision} for kind, (repo, revision) in SOURCES[size].items()},+ "source_vision_pack_sha256": source_pack_hash,+ "vision_tensor_count": len(records),+ "onnx_checker": "passed",+ "vision_inference": validation,+ "browser_image_inference": "Run scripts/check-bonsai-webgpu.mjs; this build check does not verify browser answers.",+ "tensor_mapping": records,+ }+ write_json(output / "export-validation.json", report)+ ocr_limit = (+ f"The {size} model omitted or confused characters in four-character OCR fixtures, "+ "including at a 1,024-visual-token budget. Failed OCR reports are retained "+ "alongside successful pipeline checks when publishing validation evidence."+ )+ (output / "README.md").write_text(f"""---+license: apache-2.0+library_name: transformers.js+pipeline_tag: image-text-to-text+base_model:+- prism-ml/Ternary-Bonsai-2-{size}-mlx-2bit+tags: [onnx, webgpu, ternary, bonsai, vision, qwen3_5]+---++# Ternary Bonsai 2 {size} — WebGPU with images++Created using Bonsai by Prism ML. This is a modified ONNX packaging of Prism's+Ternary Bonsai 2 {size}, for local text and image inference in WebBrain.++The ternary language graphs and Hadamard transforms come unchanged from+`danyalmalik/Ternary-Bonsai-2-{size}-ONNX-WebGPU`. The original Prism FP16 vision+tower is exported into the compatible `onnx-community/Qwen3.5-{size}-ONNX`+topology. All original vision tensors are mapped and checked after serialization;+the MLX patch projection is transposed from its channel-last layout. Normalization+and position tensors are widened to FP32 as required by the ONNX graph.+No training or additional language quantization is performed.+Processor sidecars select the compatible Qwen2 tokenizer class and a 1,048,576+pixel image ceiling for browser memory use.++Use Transformers.js `AutoProcessor` and `AutoModelForImageTextToText`, with+`device: 'webgpu'` and+`dtype: {{embed_tokens: 'q2f16', decoder_model_merged: 'q2f16', vision_encoder: 'fp16'}}`.+The runtime must support Qwen3.5 hybrid linear/full attention, `MatMulNBits` with+2-bit weights, `GatherBlockQuantized`, and FP16 WebGPU shaders. Vision pixels and+image embeddings enter the graph as FP32. KV and recurrent states are FP16.++Reproduce with `scripts/models/bonsai/build_vision.py` in the WebBrain repository.+`export-validation.json` records pinned upstream revisions, complete vision+tensor mappings, serialization hashes, and CPU graph checks. `manifest.json`+records distributable file sizes and SHA-256 hashes. Browser and model-answer+validation must be run separately; graph checks alone do not establish answer+quality or support on every browser/GPU.++Color/shape fixtures check independent visual facts. Exact OCR is a separate+optional check. {ocr_limit}++Apache 2.0; see LICENSE and NOTICE.txt. Original context capacity is 262,144 tokens;+WebBrain applies a smaller browser context budget. Model weights and processor+files are downloaded once; inference runs locally.+""", encoding="utf-8")+ total = seal_manifest(output)+ print(json.dumps({"output": str(output.resolve()), "vision_tensors": len(records),+ "total_bytes": total, "vision_inference": validation}), flush=True)+++if __name__ == "__main__":+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--size", choices=["2B", "4B", "all"], default="all")+ parser.add_argument("--workspace", type=Path, default=Path(".build/bonsai"))+ parser.add_argument("--offline", action="store_true", help="Use already downloaded, revision-pinned sources")+ parser.add_argument("--skip-inference", action="store_true", help="Only serialize/check weights; report inference as unverified")+ args = parser.parse_args()+ for model_size in (["2B", "4B"] if args.size == "all" else [args.size]):+ build(model_size, args.workspace.resolve(), args.offline, args.skip_inference)diff --git a/scripts/models/bonsai/record_browser_validation.py b/scripts/models/bonsai/record_browser_validation.pynew file mode 100644index 000000000..38af297a1--- /dev/null+++ b/scripts/models/bonsai/record_browser_validation.py@@ -0,0 +1,48 @@+"""Attach successful text/tool and image color/shape evidence to a vision bundle."""++import argparse++from build_vision import digest, read_json, seal_manifest, write_json+++def record(bundle, evidence):+ result = read_json(evidence)+ if result.get("passed") is not True or result.get("vision") is not True:+ raise ValueError("Only a successful vision run can be recorded as browser validation")+ if result.get("model") != f"webbrain-one/{bundle.name}":+ raise ValueError("Browser evidence belongs to a different model")+ probe = result.get("probe", {})+ if not probe.get("hasWebGPU") or probe.get("isFallbackAdapter") is not False:+ raise ValueError("Hardware WebGPU evidence is required")+ checks = {check["name"]: check for check in result.get("checks", [])}+ required = {"text", "tool-call", "tool-result", "image-red", "image-blue"}+ if not required.issubset(checks) or not all(checks[name].get("ok") is True for name in required):+ raise ValueError("Evidence must include successful text, tool, and both image checks")+ # Refuse to attach evidence after model artifacts changed since the testable+ # build was sealed. The browser test uses this exact export directory.+ manifest = read_json(bundle / "manifest.json")+ for entry in manifest["files"]:+ if digest(bundle / entry["path"]) != entry["sha256"]:+ raise ValueError(f"Bundle changed after build: {entry['path']}")+ write_json(bundle / "browser-validation.json", result)+ validation = read_json(bundle / "export-validation.json")+ validation["browser_image_inference"] = {+ "status": "passed",+ "evidence": "browser-validation.json",+ "finished_at": result.get("finishedAt"),+ "adapter": result.get("adapter"),+ "checks": sorted(checks),+ "limitations": "Synthetic fixtures on this recorded browser/GPU; not a general model-quality benchmark.",+ }+ write_json(bundle / "export-validation.json", validation)+ total = seal_manifest(bundle)+ print(f"Recorded verified browser evidence; distributable files total {total} bytes")+++if __name__ == "__main__":+ from pathlib import Path+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--bundle", type=Path, required=True)+ parser.add_argument("--evidence", type=Path, required=True)+ args = parser.parse_args()+ record(args.bundle.resolve(), args.evidence.resolve())diff --git a/scripts/models/bonsai/requirements.txt b/scripts/models/bonsai/requirements.txtnew file mode 100644index 000000000..51df64d30--- /dev/null+++ b/scripts/models/bonsai/requirements.txt@@ -0,0 +1,5 @@+huggingface-hub==2.2.0+numpy==2.5.4+onnx==1.23.2+onnxruntime==1.31.0+safetensors==0.8.0diff --git a/scripts/models/bonsai/validate_vision_reference.py b/scripts/models/bonsai/validate_vision_reference.pynew file mode 100644index 000000000..945c7aedb--- /dev/null+++ b/scripts/models/bonsai/validate_vision_reference.py@@ -0,0 +1,113 @@+"""Compare exported vision features with native Qwen3.5 eager PyTorch.++This optional check needs PyTorch and Transformers in addition to the build+requirements. --torch-site-packages can reuse an existing compatible Python+environment without changing its packages. It never executes repository code.+"""++import argparse+import json+import sys+from pathlib import Path+++def validate(args):+ if args.grid_size < 0 or args.grid_size % 2:+ raise ValueError("The extra image grid must be zero or a positive even number")+ if args.torch_site_packages:+ # Import only the native runtime and its ordinary dependencies. Leaving+ # the other environment on sys.path would expose unrelated old SciPy /+ # scikit-learn wheels to this environment's NumPy ABI.+ runtime_path = str(args.torch_site_packages.resolve())+ sys.path.append(runtime_path)+ try:+ import torch, torchvision, sympy, networkx, jinja2 # noqa: F401+ finally:+ sys.path.remove(runtime_path)+ import numpy as np+ import onnxruntime as ort+ import torch+ import transformers+ from safetensors import safe_open+ from transformers.initialization import no_init_weights+ from transformers.models.qwen3_5.configuration_qwen3_5 import Qwen3_5VisionConfig+ from transformers.models.qwen3_5.modeling_qwen3_5 import Qwen3_5VisionModel+ from build_vision import VISION_PACK_SHA256, digest, read_json, write_json++ source = args.workspace / "sources" / args.size / "prism"+ bundle = args.workspace / "exports" / f"Ternary-Bonsai-2-{args.size}-ONNX-WebGPU-Vision"+ if digest(source / "model.safetensors") != VISION_PACK_SHA256[args.size]:+ raise ValueError("Native reference source hash mismatch")+ config = Qwen3_5VisionConfig(**read_json(source / "config.json")["vision_config"])+ config._attn_implementation = "eager"+ torch.set_num_threads(8)+ torch.set_float32_matmul_precision("highest")+ torch.backends.cuda.matmul.allow_tf32 = False+ torch.backends.cudnn.allow_tf32 = False+ with no_init_weights():+ model = Qwen3_5VisionModel(config)+ state = {}+ with safe_open(source / "model.safetensors", framework="np") as weights:+ for key in weights.keys():+ if not key.startswith("vision_tower."):+ continue+ array = weights.get_tensor(key)+ name = key.removeprefix("vision_tower.")+ if name == "patch_embed.proj.weight":+ # Native Conv3D takes [out,channels,time,height,width]. This+ # reference does not use the ONNX MatMul reshape/transposition.+ array = array.transpose(0, 4, 1, 2, 3)+ state[name] = torch.from_numpy(array.copy()).float()+ model.load_state_dict(state, strict=True)+ del state+ model = model.to(args.device).eval()+ print(f"Native {args.size} Qwen3.5 vision loaded on {args.device}", flush=True)+ options = ort.SessionOptions()+ options.intra_op_num_threads = 8+ graph = bundle / "onnx" / "vision_encoder_fp16.onnx"+ session = ort.InferenceSession(str(graph), sess_options=options, providers=["CPUExecutionProvider"])+ random = np.random.default_rng(1987)+ records = []+ fixtures = [[[1, 4, 4]], [[1, 4, 6]], [[1, 4, 4], [1, 4, 6]]]+ if args.grid_size:+ fixtures.append([[1, args.grid_size, args.grid_size]])+ for grids in fixtures:+ grid = np.array(grids, dtype=np.int64)+ patches = int(np.prod(grid, axis=1).sum())+ pixels = random.uniform(-1, 1, size=(patches, 1536)).astype(np.float32)+ exported = session.run(None, {"pixel_values": pixels, "image_grid_thw": grid})[0]+ with torch.inference_mode():+ eager = model(torch.from_numpy(pixels).to(args.device),+ grid_thw=torch.from_numpy(grid).to(args.device)).pooler_output.float().cpu().numpy()+ if exported.shape != eager.shape or not np.isfinite(exported).all() or not np.isfinite(eager).all():+ raise ValueError("Reference and exported features must have matching shapes and finite values")+ difference = exported.astype(np.float64) - eager.astype(np.float64)+ relative_l2 = float(np.linalg.norm(difference) / max(np.linalg.norm(eager), 1e-12))+ cosine = float(np.dot(exported.ravel(), eager.ravel()) /+ (np.linalg.norm(exported) * np.linalg.norm(eager)))+ record = {"image_grid_thw": grids, "shape": list(eager.shape),+ "cosine_similarity": cosine, "relative_l2_error": relative_l2,+ "max_absolute_error": float(np.max(np.abs(difference)))}+ records.append(record)+ print(json.dumps(record), flush=True)+ if not np.isfinite(cosine) or not np.isfinite(relative_l2) or cosine < 0.9999 or relative_l2 > 0.02:+ raise ValueError(f"Native eager vision parity failed: {record}")+ report = {"passed": True, "size": args.size, "reference": "Native Qwen3.5 eager FP32 with original Prism weights",+ "device": args.device, "torch": torch.__version__, "transformers": transformers.__version__,+ "onnxruntime": ort.__version__, "exported_graph_sha256": digest(graph),+ "exported_weights_sha256": digest(graph.with_name(graph.name + "_data")), "fixtures": records}+ args.output.parent.mkdir(parents=True, exist_ok=True)+ write_json(args.output, report)+ print(f"Native vision parity evidence: {args.output}", flush=True)+++if __name__ == "__main__":+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--size", choices=["2B", "4B"], default="2B")+ parser.add_argument("--workspace", type=Path, default=Path(".build/bonsai"))+ parser.add_argument("--device", default="cuda:0")+ parser.add_argument("--grid-size", type=int, default=28,+ help="Also check this square grid (28 matches a 448-pixel image); 0 skips it")+ parser.add_argument("--torch-site-packages", type=Path)+ parser.add_argument("--output", type=Path, default=Path(".build/bonsai/vision-native-parity.json"))+ validate(parser.parse_args())diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex 2d1cd7193..05f286459 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -4480,7 +4480,6 @@ async function handleMessage(msg, sender) {case 'get_providers': {const providers = providerManager.getAll({ includeSidepanelOnly: msg.includeSidepanelOnly === true });- delete providers.webgpu;return { providers, active: providerManager.activeProviderId };}diff --git a/src/chrome/src/offscreen/inference-worker.js b/src/chrome/src/offscreen/inference-worker.jsindex 008753f78..c53f9a42b 100644--- a/src/chrome/src/offscreen/inference-worker.js+++ b/src/chrome/src/offscreen/inference-worker.js@@ -7,6 +7,8 @@* request/response messages to it.*/+import { BONSAI2_TOKENIZER_CONFIG } from '../../vendor/bonsai2/tokenizer-config.js';+let libraryPromise = null;let libraryVersion = null;let workerConfig = null;@@ -33,6 +35,30 @@ const WEBGPU_LFM25_VL_3B_MODEL_ID = 'LiquidAI/LFM2.5-VL-3B-ONNX';const WEBGPU_NANBEIGE42_3B_MODEL_ID = 'Michionlion/Nanbeige4.2-3B-ONNX-WebGPU';const WEBGPU_MINICPM5_2B_MODEL_ID = 'RASMUS/MiniCPM5-2B-ONNX';const WEBGPU_BONSAI27_MODEL_ID = 'prism-ml/Bonsai-27B-gguf';+const WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS = new Set([+ 'danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU',+ 'danyalmalik/Ternary-Bonsai-2-4B-ONNX-WebGPU',+]);+const WEBGPU_BONSAI2_VISION_MODEL_IDS = new Set([+ 'webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision',+ 'webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision',+]);+const WEBGPU_BONSAI2_MODEL_IDS = new Set([+ ...WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS,+ ...WEBGPU_BONSAI2_VISION_MODEL_IDS,+ 'Mike0021/Ternary-Bonsai-2-4B-text-ONNX',+]);+// The Qwen3.5 generation_config sidecar omitted by Danyal's split exports.+// Per-request decoding still controls do_sample and the output token budget.+const BONSAI2_GENERATION_CONFIG = {+ bos_token_id: 248044,+ eos_token_id: [248046, 248044],+ pad_token_id: 248044,+ do_sample: true,+ temperature: 0.6,+ top_k: 20,+ top_p: 0.95,+};const WEBGPU_LFM25_MAX_NEW_TOKENS = 2048;const WEBGPU_LFM25_TEXT_MODEL_IDS = new Set([WEBGPU_LFM25_MODEL_ID,@@ -61,6 +87,7 @@ const WEBGPU_LONG_OUTPUT_MODEL_IDS = new Set([...WEBGPU_LFM25_TEXT_MODEL_IDS,WEBGPU_NANBEIGE42_3B_MODEL_ID,WEBGPU_MINICPM5_2B_MODEL_ID,+ ...WEBGPU_BONSAI2_MODEL_IDS,]);// Publisher-recommended decoding for the shipped reasoning presets. Custom// repositories keep Transformers.js greedy defaults.@@ -148,6 +175,88 @@ function isLfm25VlModel(modelId) {return WEBGPU_LFM25_VL_MODEL_IDS.has(String(modelId || '').trim());}+function isMultimodalTextModel(modelId) {+ return isLfm25VlModel(modelId) || WEBGPU_BONSAI2_VISION_MODEL_IDS.has(modelId);+}++export function bonsai2CompatibilityMetadata(input) {+ // Supply missing sidecars from packaged metadata without borrowing a tokenizer+ // from another remote model or changing any unrecognized repository.+ try {+ const url = new URL(typeof input === 'string' || input instanceof URL ? String(input) : input?.url);+ const match = /^\/([^/]+\/[^/]+)\/resolve\/[^/]+\/(tokenizer_config|generation_config)\.json$/.exec(url.pathname);+ if (url.origin !== 'https://huggingface.co' || !WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS.has(match?.[1])) return null;+ return match[2] === 'tokenizer_config' ? BONSAI2_TOKENIZER_CONFIG : BONSAI2_GENERATION_CONFIG;+ } catch {+ return null;+ }+}++function packagedMetadataResponse(metadata, head = false) {+ const body = JSON.stringify(metadata);+ return new Response(head ? null : body, {+ headers: { 'content-type': 'application/json', 'content-length': String(new TextEncoder().encode(body).length) },+ });+}++async function cacheBonsai2CompatibilityMetadata(modelId) {+ if (!WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS.has(modelId) || typeof caches === 'undefined') return;+ const cache = await caches.open(TRANSFORMERS_CACHE_NAME);+ for (const file of ['tokenizer_config.json', 'generation_config.json']) {+ const url = `https://huggingface.co/${modelId}/resolve/main/${file}`;+ if (!await cache.match(url)) await cache.put(url, packagedMetadataResponse(bonsai2CompatibilityMetadata(url)));+ }+}++export function normalizeBonsai2Config(config) {+ return {+ ...config,+ // The source export omits generation_config.json. Its base-model EOS is+ // only <|endoftext|>; chat must also stop at <|im_end|> or it generates+ // subsequent assistant turns after an otherwise complete answer.+ text_config: {+ ...config.text_config,+ eos_token_id: [248046, 248044],+ pad_token_id: 248044,+ },+ // Danyal's metadata still describes the original Qwen q4/fp16 shards;+ // both Bonsai q2f16 components have exactly one external data file.+ 'transformers.js_config': {+ ...(config['transformers.js_config'] || {}),+ use_external_data_format: {+ 'embed_tokens_q2f16.onnx': 1,+ 'decoder_model_merged_q2f16.onnx': 1,+ },+ kv_cache_dtype: { q2f16: 'float16' },+ },+ };+}++export function applyBonsai2RotaryCompatibility(modelId, model) {+ if ((!WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS.has(modelId) && !WEBGPU_BONSAI2_VISION_MODEL_IDS.has(modelId))+ || typeof model?._get_text_only_rope_index !== 'function') return;+ const original = model._get_text_only_rope_index;+ model._get_text_only_rope_index = function (inputIds, attentionMask) {+ const [positions, deltas] = original.call(this, inputIds, attentionMask);+ if (attentionMask) {+ // Transformers.js 4.2 adds the prompt length to the pure-text MRoPE+ // delta instead of subtracting it. Cached decoding then jumps from+ // position N-1 to 3N. Recompute the delta from the actual positions;+ // image prompts use a separate, correct method and remain untouched.+ const [batchSize, sequenceLength] = attentionMask.dims;+ for (let batch = 0; batch < batchSize; batch++) {+ let maximum = -1n;+ const offset = batch * sequenceLength;+ for (let i = 0; i < sequenceLength; i++) {+ if (positions.data[offset + i] > maximum) maximum = positions.data[offset + i];+ }+ deltas.data[batch] = maximum + 1n - BigInt(sequenceLength);+ }+ }+ return [positions, deltas];+ };+}+function lfm25VlProcessorOptions(modelId) {if (!isLfm25VlModel(modelId)) return {};return {@@ -237,6 +346,8 @@ async function markVisionModelReady(modelId) {}async function controlledFetch(input, init = {}) {+ const metadata = bonsai2CompatibilityMetadata(input);+ if (metadata) return packagedMetadataResponse(metadata, init.method === 'HEAD');if (!nativeFetch) throw new Error('Fetch is unavailable in the WebGPU worker.');if (textDownloadAbortController && fetchTargetsActiveTextModel(input)) {return nativeFetch(input, { ...init, signal: textDownloadAbortController.signal });@@ -453,17 +564,32 @@ function noteWebgpuExecutionSuccess() {webgpuExecutionFailureStreak = 0;}+export function perFileProgressEvents(event) {+ if (event?.status !== 'progress_total') return [event];+ // Transformers.js emits an aggregate snapshot immediately before the same+ // file's progress event. Account for its known files, never for its model+ // total as an additional file (which doubles every downloaded byte).+ return Object.entries(event?.files || {}).map(([file, progress]) => ({+ status: 'progress', file,+ loaded: Number(progress?.loaded || 0),+ total: Number(progress?.total || 0),+ }));+}+function postProgress(modelId, event) {+ const fileEvents = perFileProgressEvents(event);if (modelId === activeTextDownloadModelId && !textDownloadCancelMode) {- const file = String(event?.file || event?.name || '');- if (file) {+ const file = String(event?.file || (event?.status === 'progress_total' ? textDownloadState.file : event?.name) || '');+ for (const fileEvent of fileEvents) {+ const file = String(fileEvent?.file || '');+ if (!file) continue;const previous = textDownloadFiles.get(file) || { loaded: 0, total: 0, status: '' };- const total = Number(event?.total || previous.total || 0);- const loaded = event?.status === 'done' && total > 0+ const total = Number(fileEvent?.total || previous.total || 0);+ const loaded = fileEvent?.status === 'done' && total > 0? total- : Number(event?.loaded ?? previous.loaded ?? 0);+ : Number(fileEvent?.loaded ?? previous.loaded ?? 0);textDownloadFiles.set(file, {- status: event?.status || previous.status,+ status: fileEvent?.status || previous.status,loaded: Math.max(0, loaded),total: Math.max(0, total),});@@ -487,15 +613,17 @@ function postProgress(modelId, event) {};postTextDownloadState({ force: event?.status === 'done' });}- self.postMessage({- type: 'progress',- modelId,- status: event?.status || '',- file: event?.file || event?.name || '',- loaded: Number(event?.loaded || 0),- total: Number(event?.total || 0),- progress: Number(event?.progress || 0),- });+ for (const fileEvent of fileEvents) {+ self.postMessage({+ type: 'progress',+ modelId,+ status: fileEvent?.status || '',+ file: fileEvent?.file || '',+ loaded: Number(fileEvent?.loaded || 0),+ total: Number(fileEvent?.total || 0),+ progress: Number(fileEvent?.progress || 0),+ });+ }}async function disposeRuntime(runtime) {@@ -599,7 +727,9 @@ async function getVisionRuntime(modelId, dtype, device, {await disposeVisionRuntime();const progress_callback = event => postProgress(modelId, event);const config = await legacyLfm25VlConfig(library, modelId, progress_callback, localFilesOnly);- const processorOptions = lfm25VlProcessorOptions(modelId);+ const processorOptions = WEBGPU_BONSAI2_VISION_MODEL_IDS.has(modelId)+ ? { image_processor_config_file: 'processor_config.json', chat_template_file: 'chat_template.jinja' }+ : lfm25VlProcessorOptions(modelId);const previousAllowLocalModels = library.env?.allowLocalModels;if (localFilesOnly && library.env) library.env.allowLocalModels = true;let processorResult;@@ -646,6 +776,12 @@ async function getVisionRuntime(modelId, dtype, device, {}const processor = processorResult.value;const model = modelResult.value;+ applyBonsai2RotaryCompatibility(modelId, model);+ if (WEBGPU_BONSAI2_VISION_MODEL_IDS.has(modelId) && processor.image_processor) {+ // Bound the visual token count for browser screenshots. Upstream Qwen's+ // 16M-pixel ceiling is intended for server GPUs and can exhaust WebGPU.+ processor.image_processor.max_pixels = 1024 * 1024;+ }bindWebGpuDeviceDiagnostics(library);visionRuntime = { library, processor, model };visionRuntimeKey = key;@@ -778,9 +914,19 @@ async function getTextRuntime(modelId, dtype, device, { localFilesOnly = false }if (localFilesOnly && library.env) library.env.allowLocalModels = true;let pipeline;try {+ // Seed omitted metadata before local_files_only loading, including older+ // browser caches created before these compatibility sidecars were added.+ await cacheBonsai2CompatibilityMetadata(modelId);+ const config = WEBGPU_BONSAI2_SPLIT_TEXT_MODEL_IDS.has(modelId)+ ? normalizeBonsai2Config(await library.AutoConfig.from_pretrained(modelId, {+ local_files_only: localFilesOnly,+ progress_callback: event => postProgress(modelId, event),+ }))+ : null;pipeline = await library.pipeline('text-generation', modelId, {device,dtype,+ ...(config ? { config } : {}),...(WEBGPU_TEXT_MODEL_FILE_NAMES.has(modelId)? { model_file_name: WEBGPU_TEXT_MODEL_FILE_NAMES.get(modelId) }: {}),@@ -802,6 +948,7 @@ async function getTextRuntime(modelId, dtype, device, { localFilesOnly = false }if (localFilesOnly && library.env) library.env.allowLocalModels = previousAllowLocalModels;}bindWebGpuDeviceDiagnostics(library);+ applyBonsai2RotaryCompatibility(modelId, pipeline.model);textRuntime = {library,pipeline,@@ -825,7 +972,7 @@ async function getTextRuntime(modelId, dtype, device, { localFilesOnly = false }}async function getDownloadedTextRuntime(modelId, dtype, device, { localFilesOnly = false } = {}) {- if (isLfm25VlModel(modelId)) {+ if (isMultimodalTextModel(modelId)) {return getVisionRuntime(modelId, dtype, device, {localFilesOnly,owner: 'text',@@ -836,8 +983,8 @@ async function getDownloadedTextRuntime(modelId, dtype, device, { localFilesOnly}async function disposeDownloadedTextRuntime(modelId = '') {- if (!modelId || isLfm25VlModel(modelId)) await disposeVisionRuntime('text');- if (!modelId || !isLfm25VlModel(modelId)) await disposeTextRuntime();+ if (!modelId || isMultimodalTextModel(modelId)) await disposeVisionRuntime('text');+ if (!modelId || !isMultimodalTextModel(modelId)) await disposeTextRuntime();}function chatTemplateText(value) {@@ -853,7 +1000,7 @@ export function tokenizerSupportsTools(tokenizer) {}function assertToolCapableTextRuntime(runtime, modelId) {- if (tokenizerSupportsTools(runtime?.tokenizer)) return;+ if (tokenizerSupportsTools(runtime?.tokenizer ?? runtime?.processor?.tokenizer)) return;throw new Error(`${modelId} is not compatible with WebBrain: custom repositories must provide a chat template that accepts tools.`);}@@ -1134,6 +1281,40 @@ export function prepareMultimodalMessages(messages) {return { messages: prepared, imageUrls };}+export async function processMultimodalInputs(runtime, modelId, images, prompt) {+ // Qwen's processor takes (text, images), while LFM takes (images, text).+ // Keep this distinction at the runtime boundary so screenshot messages and+ // their untrusted-content framing stay identical throughout the agent.+ if (!WEBGPU_BONSAI2_VISION_MODEL_IDS.has(modelId)) {+ return runtime.processor(images, prompt, { add_special_tokens: false });+ }+ if (!Array.isArray(images) || images.length < 2) {+ return runtime.processor(prompt, images, { add_special_tokens: false });+ }+ // The bundled Qwen image processor treats a batch as video frames. Screenshot+ // history consists of independent images, potentially with different shapes.+ // Process each separately, then join patches and one grid row per image.+ const marker = '<|image_pad|>';+ const chunks = prompt.split(marker);+ if (chunks.length !== images.length + 1) {+ throw new Error('The screenshot count does not match the image placeholders in the prompt.');+ }+ const imageInputs = [];+ for (const image of images) imageInputs.push(await runtime.processor.image_processor(image));+ const mergeArea = runtime.processor.image_processor.config.merge_size ** 2;+ let expanded = chunks[0];+ for (let i = 0; i < imageInputs.length; i++) {+ const grid = imageInputs[i].image_grid_thw.tolist()[0];+ const tokens = Number(grid.reduce((product, dimension) => product * dimension, 1n)) / mergeArea;+ expanded += marker.repeat(tokens) + chunks[i + 1];+ }+ return {+ ...runtime.processor.tokenizer(expanded, { add_special_tokens: false }),+ pixel_values: runtime.library.cat(imageInputs.map(input => input.pixel_values), 0),+ image_grid_thw: runtime.library.cat(imageInputs.map(input => input.image_grid_thw), 0),+ };+}+function createVisionProbeImage(RawImage) {if (!RawImage) throw new Error('The packaged runtime does not expose RawImage.');// LFM2.5-VL-450M is much more dependable at coarse visual classification@@ -1188,15 +1369,16 @@ async function runVision(payload, requestId) {});const { messages, imageUrls } = prepareMultimodalMessages(payload?.messages);if (imageUrls.length !== 1) {- throw new Error(`LFM2.5-VL requires exactly one screenshot; received ${imageUrls.length}.`);+ throw new Error(`${modelId} requires exactly one screenshot; received ${imageUrls.length}.`);}const prompt = runtime.processor.apply_chat_template(messages, {add_generation_prompt: true,+ ...(WEBGPU_BONSAI2_MODEL_IDS.has(modelId) ? { enable_thinking: false } : {}),});const image = payload?.options?.visionProbe === true? createVisionProbeImage(runtime.library.RawImage): await runtime.library.load_image(imageUrls[0]);- const inputs = await runtime.processor(image, prompt, { add_special_tokens: false });+ const inputs = await processMultimodalInputs(runtime, modelId, image, prompt);const requestedTokens = Number(payload?.options?.maxTokens);const maxNewTokens = Number.isFinite(requestedTokens)? Math.max(1, Math.min(1600, Math.round(requestedTokens)))@@ -1327,7 +1509,7 @@ function addLegacyVlTools(messages, tools) {async function runMultimodalText(payload) {const modelId = assertOnnxTextModel(payload?.modelId);- if (!isLfm25VlModel(modelId)) {+ if (!isMultimodalTextModel(modelId)) {throw new Error(`${modelId} is not a shipped WebGPU multimodal model.`);}const device = payload?.device || 'webgpu';@@ -1344,19 +1526,19 @@ async function runMultimodalText(payload) {owner: 'text',readiness: 'text',});+ if (payload?.requireTools === true) assertToolCapableTextRuntime(runtime, modelId);const tools = Array.isArray(payload?.options?.tools) ? payload.options.tools : [];let { messages, imageUrls } = prepareMultimodalMessages(payload?.messages);if (modelId === WEBGPU_LFM25_VL_16B_MODEL_ID) messages = addLegacyVlTools(messages, tools);const prompt = runtime.processor.apply_chat_template(messages, {add_generation_prompt: true,tools: tools.length ? tools : undefined,+ ...(WEBGPU_BONSAI2_MODEL_IDS.has(modelId) ? { enable_thinking: false } : {}),});let inputs;if (imageUrls.length) {const images = await Promise.all(imageUrls.map(url => runtime.library.load_image(url)));- inputs = await runtime.processor(images.length === 1 ? images[0] : images, prompt, {- add_special_tokens: false,- });+ inputs = await processMultimodalInputs(runtime, modelId, images.length === 1 ? images[0] : images, prompt);} else {inputs = runtime.processor.tokenizer(prompt, { add_special_tokens: false });}diff --git a/src/chrome/src/providers/manager.js b/src/chrome/src/providers/manager.jsindex d8fd91106..747105fc0 100644--- a/src/chrome/src/providers/manager.js+++ b/src/chrome/src/providers/manager.js@@ -1881,7 +1881,7 @@ export class ProviderManager {return this._webgpuProvider().downloadStatus(msg);}- /** Configure a shipped Apocalypse text preset and start Compass cache fill. */+ /** Start the selected shipped Apocalypse chat model, defaulting to Compass. */async enableAndStartWebgpuTextDownload() {try {const currentModel = this.getAll().webgpu?.model;@@ -1891,8 +1891,6 @@ export class ProviderManager {await this.updateProvider('webgpu', {model,dtype,- contextWindow: preset?.contextWindow || 32768,- promptTier: 'compact',});const provider = this._webgpuProvider();const probe = await provider.testConnection();@@ -2010,14 +2008,15 @@ export class ProviderManager {if (id === 'webgpu' && Object.hasOwn(updates, 'model')) {merged.model = normalizeWebgpuModelId(merged.model);const preset = webgpuModelPreset(merged.model);- if (preset?.contextWindow && !Object.hasOwn(updates, 'contextWindow')) {+ const modelChanged = merged.model !== normalizeWebgpuModelId(current.model);+ if (modelChanged && preset?.contextWindow && !Object.hasOwn(updates, 'contextWindow')) {merged.contextWindow = preset.contextWindow;}// A retained Bonsai dtype ('q1') must not leak into a new target: a// custom ONNX repository would otherwise request model_q1.onnx instead// of the documented q4f16 graph. Reset to the preset (or ONNX default)// whenever the model changes unless the update explicitly supplies one.- if (!Object.hasOwn(updates, 'dtype')) {+ if (modelChanged && !Object.hasOwn(updates, 'dtype')) {merged.dtype = preset?.dtype || WEBGPU_DTYPE;}}diff --git a/src/chrome/src/providers/webgpu.js b/src/chrome/src/providers/webgpu.jsindex dcb988864..2fecec279 100644--- a/src/chrome/src/providers/webgpu.js+++ b/src/chrome/src/providers/webgpu.js@@ -13,8 +13,18 @@ export const WEBGPU_LFM25_VL_3B_MODEL_ID = 'LiquidAI/LFM2.5-VL-3B-ONNX';export const WEBGPU_NANBEIGE42_3B_MODEL_ID = 'Michionlion/Nanbeige4.2-3B-ONNX-WebGPU';export const WEBGPU_MINICPM5_2B_MODEL_ID = 'RASMUS/MiniCPM5-2B-ONNX';export const WEBGPU_COMPASS_TINY_V2_MODEL_ID = 'webbrain-one/webbrain-compass-tiny-v2.1';+export const WEBGPU_BONSAI2_2B_MODEL_ID = 'danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU';+export const WEBGPU_BONSAI2_4B_MODEL_ID = 'Mike0021/Ternary-Bonsai-2-4B-text-ONNX';+export const WEBGPU_BONSAI2_VL_2B_MODEL_ID = 'webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision';+export const WEBGPU_BONSAI2_VL_4B_MODEL_ID = 'webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision';export const WEBGPU_BONSAI27_MODEL_ID = 'prism-ml/Bonsai-27B-gguf';export const WEBGPU_DTYPE = 'q4f16';+export const WEBGPU_BONSAI2_DTYPE = 'q2f16';+export const WEBGPU_BONSAI2_VL_DTYPE = Object.freeze({+ embed_tokens: 'q2f16',+ vision_encoder: 'fp16',+ decoder_model_merged: 'q2f16',+});export const WEBGPU_BONSAI27_DTYPE = 'q1';export const WEBGPU_RUNTIME_ONNX = 'onnx';export const WEBGPU_RUNTIME_ONNX_VL = 'onnx-vl';@@ -118,6 +128,48 @@ export const WEBGPU_MODEL_PRESETS = Object.freeze([contextWindow: 32768,supportsVision: false,}),+ Object.freeze({+ id: WEBGPU_BONSAI2_2B_MODEL_ID,+ runtime: WEBGPU_RUNTIME_ONNX,+ label: 'Ternary Bonsai 2 2B',+ size: '787 MB',+ dtype: WEBGPU_BONSAI2_DTYPE,+ dtypeLabel: WEBGPU_BONSAI2_DTYPE,+ // Bound the native 262k context for browser GPU memory. Full-attention+ // KV slots cost about 12 KB/token at 2B and 32 KB/token at 4B in FP16.+ contextWindow: 16384,+ supportsVision: false,+ }),+ Object.freeze({+ id: WEBGPU_BONSAI2_4B_MODEL_ID,+ runtime: WEBGPU_RUNTIME_ONNX,+ label: 'Ternary Bonsai 2 4B',+ size: '1.50 GB',+ dtype: WEBGPU_BONSAI2_DTYPE,+ dtypeLabel: WEBGPU_BONSAI2_DTYPE,+ contextWindow: 16384,+ supportsVision: false,+ }),+ Object.freeze({+ id: WEBGPU_BONSAI2_VL_2B_MODEL_ID,+ runtime: WEBGPU_RUNTIME_ONNX_VL,+ label: 'Ternary Bonsai 2 2B Vision',+ size: '1.45 GB',+ dtype: WEBGPU_BONSAI2_VL_DTYPE,+ dtypeLabel: 'Q2/FP16',+ contextWindow: 16384,+ supportsVision: true,+ }),+ Object.freeze({+ id: WEBGPU_BONSAI2_VL_4B_MODEL_ID,+ runtime: WEBGPU_RUNTIME_ONNX_VL,+ label: 'Ternary Bonsai 2 4B Vision',+ size: '2.15 GB',+ dtype: WEBGPU_BONSAI2_VL_DTYPE,+ dtypeLabel: 'Q2/FP16',+ contextWindow: 16384,+ supportsVision: true,+ }),Object.freeze({id: WEBGPU_BONSAI27_MODEL_ID,runtime: WEBGPU_RUNTIME_BITGPU,@@ -129,6 +181,15 @@ export const WEBGPU_MODEL_PRESETS = Object.freeze([supportsVision: false,}),]);+// Keep legacy presets loadable without offering them for new selections.+// Both Chrome pickers use this order; Firefox has no offscreen chat runtime.+export const WEBGPU_SELECTABLE_MODEL_PRESETS = Object.freeze([+ WEBGPU_COMPASS_TINY_V2_MODEL_ID,+ WEBGPU_BONSAI2_2B_MODEL_ID,+ WEBGPU_BONSAI2_4B_MODEL_ID,+ WEBGPU_BONSAI2_VL_2B_MODEL_ID,+ WEBGPU_BONSAI2_VL_4B_MODEL_ID,+].map(id => WEBGPU_MODEL_PRESETS.find(preset => preset.id === id)));export const WEBGPU_MODEL_NOT_READY_ERROR = `${WEBGPU_COMPASS_TINY_V2_MODEL_ID} is not downloaded. Open Settings > Providers > WebGPU or Apocalypse Mode > WebGPU to download it before chatting.`;// Chrome-only selection state. Keep this separate from the synced// `visionModel` endpoint so enabling the fallback never overwrites a user's@@ -217,6 +278,12 @@ export function isShippedWebgpuPreset(modelId) {return webgpuModelPreset(modelId) != null;}+export function isSelectableWebgpuPreset(modelId) {+ if (!String(modelId || '').trim()) return false;+ const preset = webgpuModelPreset(modelId);+ return !!preset && WEBGPU_SELECTABLE_MODEL_PRESETS.includes(preset);+}+export function webgpuModelRuntime(modelId) {return webgpuModelPreset(modelId)?.runtime || WEBGPU_RUNTIME_ONNX;}diff --git a/src/chrome/src/ui/apocalypse-mode.html b/src/chrome/src/ui/apocalypse-mode.htmlindex bdd9a318c..103eda86c 100644--- a/src/chrome/src/ui/apocalypse-mode.html+++ b/src/chrome/src/ui/apocalypse-mode.html@@ -140,11 +140,27 @@<strong data-i18n="ap.models.text.title"></strong><span class="meta" data-webgpu-text-size>1.87 GB · WebGPU</span></div>- <div class="webgpu-text-presets" role="radiogroup" aria-label="Local text model">+ <div class="webgpu-text-presets" role="radiogroup" aria-label="Local chat model"><label class="webgpu-text-preset"><input type="radio" name="webgpu-text-preset" value="webbrain-one/webbrain-compass-tiny-v2.1" data-webgpu-text-preset checked><span>Compass Tiny v2.1</span></label>+ <label class="webgpu-text-preset">+ <input type="radio" name="webgpu-text-preset" value="danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU" data-webgpu-text-preset>+ <span>Ternary Bonsai 2 2B</span>+ </label>+ <label class="webgpu-text-preset">+ <input type="radio" name="webgpu-text-preset" value="Mike0021/Ternary-Bonsai-2-4B-text-ONNX" data-webgpu-text-preset>+ <span>Ternary Bonsai 2 4B</span>+ </label>+ <label class="webgpu-text-preset">+ <input type="radio" name="webgpu-text-preset" value="webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision" data-webgpu-text-preset>+ <span>Ternary Bonsai 2 2B Vision</span>+ </label>+ <label class="webgpu-text-preset">+ <input type="radio" name="webgpu-text-preset" value="webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision" data-webgpu-text-preset>+ <span>Ternary Bonsai 2 4B Vision</span>+ </label></div><p class="meta" data-webgpu-text-warning hidden data-i18n="ap.models.text.bonsai_warning"></p><p class="meta" data-webgpu-text-copy data-i18n="ap.webgpu.rag"></p>diff --git a/src/chrome/src/ui/apocalypse-mode.js b/src/chrome/src/ui/apocalypse-mode.jsindex a24832ba9..ccbb843cb 100644--- a/src/chrome/src/ui/apocalypse-mode.js+++ b/src/chrome/src/ui/apocalypse-mode.js@@ -23,10 +23,12 @@ import { createOfflineRagReadinessController } from './offline-rag-readiness.js'import {WEBGPU_COMPASS_TINY_V2_MODEL_ID,WEBGPU_DTYPE,+ WEBGPU_SELECTABLE_MODEL_PRESETS,WEBGPU_VISION_CONSENT_VERSION,WEBGPU_VISION_CONSENT_VERSION_KEY,WEBGPU_VISION_ENABLED_KEY,isShippedWebgpuPreset,+ isSelectableWebgpuPreset,webgpuModelDtype,webgpuModelPreset,} from '../providers/webgpu.js';@@ -82,7 +84,7 @@ let visionDownloadState = null;let visionFallbackExplicitlyEnabled = false;let fixedWebgpuProviderConfigured = false;let fixedWebgpuProviderMarkedReady = false;-let webgpuPresetHydrated = false;+let webgpuPresetChangePending = false;let visionTestRunning = false;let webgpuDownloadStatusRequest = 0;let webgpuDownloadState = {@@ -430,7 +432,8 @@ function updateWebgpuTextPresetUi() {const copy = document.querySelector('[data-webgpu-text-copy]');if (copy) {copy.dataset.i18n = 'ap.webgpu.rag';- copy.textContent = t('ap.webgpu.rag');+ copy.dataset.i18nParams = JSON.stringify({ model: preset.label });+ copy.textContent = t('ap.webgpu.rag', { model: preset.label });}for (const input of document.querySelectorAll('[data-webgpu-text-preset]')) {input.checked = input.value === (preset?.id || WEBGPU_COMPASS_TINY_V2_MODEL_ID);@@ -454,8 +457,8 @@ function anyOtherWebgpuTextPaused() {}function webgpuDownloadActionState() {- // The Compass preset remains selected, but controls must follow a retained- // Settings transfer, including when Compass itself is already cached.+ // Controls follow a retained Settings transfer even when the selected+ // preset is already cached.const transfers = [webgpuDownloadState, ...otherWebgpuTextStates()].filter(state => WEBGPU_TEXT_BUSY_STATUSES.has(state.status));return transfers.find(state => state.status !== 'paused') || transfers[0] || webgpuDownloadState;@@ -528,7 +531,7 @@ async function runVisionDownloadAction(action) {}}-async function ensureFixedWebgpuProvider({ markConfigured = false, force = false } = {}) {+async function ensureFixedWebgpuProvider({ markConfigured = false, force = false, preserveConfig = false } = {}) {const preset = selectedWebgpuPreset();const model = preset?.id || WEBGPU_COMPASS_TINY_V2_MODEL_ID;const dtype = preset?.dtype || webgpuModelDtype(model, WEBGPU_DTYPE);@@ -538,12 +541,9 @@ async function ensureFixedWebgpuProvider({ markConfigured = false, force = false}await providerCommand('update_provider', {providerId: 'webgpu',- config: {- model,- dtype,- contextWindow: preset?.contextWindow || 32768,- promptTier: 'compact',- },+ // A readiness check must not replace a saved context budget or prompt tier.+ // The manager applies the new preset's context default when its model changes.+ config: preserveConfig ? {} : { model, dtype },markConfigured,});fixedWebgpuProviderConfigured = true;@@ -551,51 +551,65 @@ async function ensureFixedWebgpuProvider({ markConfigured = false, force = false}async function refreshWebgpuDownloadStatus({ probeSibling = false } = {}) {- if (!supportsWebgpuVision) return;+ if (!supportsWebgpuVision || webgpuPresetChangePending) return;const requestId = ++webgpuDownloadStatusRequest;try {let state = await providerCommand('get_webgpu_download_status');if (requestId !== webgpuDownloadStatusRequest) return;let preset = webgpuModelPreset(state?.modelId);- if (!preset || preset.id !== WEBGPU_COMPASS_TINY_V2_MODEL_ID) {- // Only Compass Tiny v2.1 is offered. Retain an active transfer in the- // aggregate tracker, then switch the provider to Compass before- // rendering its controls.+ if (!isSelectableWebgpuPreset(preset?.id)) {+ // Retain any legacy/custom transfer in the aggregate tracker before+ // switching the provider to a model offered by this picker.setWebgpuDownloadState(state, { syncActiveTransfer: true });await ensureFixedWebgpuProvider({ force: true });if (requestId !== webgpuDownloadStatusRequest) return;state = await providerCommand('get_webgpu_download_status');if (requestId !== webgpuDownloadStatusRequest) return;preset = webgpuModelPreset(state?.modelId);- if (!preset) throw new Error('Unable to select a shipped WebGPU text preset.');+ if (!isSelectableWebgpuPreset(preset?.id)) throw new Error('Unable to select a shipped WebGPU chat preset.');}if (preset) {const selectedId = selectedWebgpuModelId();- if (!webgpuPresetHydrated || selectedId === preset.id) {- const input = document.querySelector(`[data-webgpu-text-preset][value="${CSS.escape(preset.id)}"]`);- if (input) input.checked = true;- webgpuPresetHydrated = true;+ if (selectedId !== preset.id) {+ fixedWebgpuProviderConfigured = false;+ fixedWebgpuProviderMarkedReady = false;}+ const input = document.querySelector(`[data-webgpu-text-preset][value="${CSS.escape(preset.id)}"]`);+ if (input) input.checked = true;}updateWebgpuTextPresetUi();setWebgpuDownloadState(state, { syncActiveTransfer: true });if (probeSibling) await refreshSiblingWebgpuTextStatus(state?.modelId, requestId);if (requestId !== webgpuDownloadStatusRequest) return;- if (state?.ready === true) await ensureFixedWebgpuProvider({ markConfigured: true });+ if (state?.ready === true) await ensureFixedWebgpuProvider({ markConfigured: true, preserveConfig: true });} catch (error) {- if (requestId === webgpuDownloadStatusRequest) setWebgpuDownloadState({ status: 'error', error: error.message });+ if (requestId === webgpuDownloadStatusRequest) setWebgpuDownloadState({+ ...webgpuDownloadState, status: 'error', ready: false, error: error.message,+ });}}async function refreshSiblingWebgpuTextStatus(currentModelId, requestId = webgpuDownloadStatusRequest) {- // Only Compass Tiny v2.1 is offered, so there are no unselected shipped- // text models to probe.- return;+ await Promise.all(WEBGPU_SELECTABLE_MODEL_PRESETS+ .filter(preset => preset.id !== currentModelId)+ .map(async (preset) => {+ try {+ const state = await providerCommand('get_webgpu_download_status', { model: preset.id, dtype: preset.dtype });+ if (requestId !== webgpuDownloadStatusRequest) return;+ recordWebgpuTextState(state);+ } catch {+ // A failed sibling probe must not hide controls for the selected model.+ }+ }));+ if (requestId === webgpuDownloadStatusRequest) updateOverallModelsReadiness();}async function onWebgpuTextPresetChange() {+ if (webgpuPresetChangePending) return;+ webgpuPresetChangePending = true;+ ++webgpuDownloadStatusRequest;+ for (const input of document.querySelectorAll('[data-webgpu-text-preset]')) input.disabled = true;recordWebgpuTextState(webgpuDownloadState);- webgpuPresetHydrated = true;fixedWebgpuProviderConfigured = false;fixedWebgpuProviderMarkedReady = false;updateWebgpuTextPresetUi();@@ -611,9 +625,13 @@ async function onWebgpuTextPresetChange() {updateOverallModelsReadiness();try {await ensureFixedWebgpuProvider();+ webgpuPresetChangePending = false;await refreshWebgpuDownloadStatus({ probeSibling: true });} catch (error) {- setWebgpuDownloadState({ status: 'error', error: error.message });+ setWebgpuDownloadState({ ...webgpuDownloadState, status: 'error', ready: false, error: error.message });+ } finally {+ webgpuPresetChangePending = false;+ for (const input of document.querySelectorAll('[data-webgpu-text-preset]')) input.disabled = false;}}diff --git a/src/chrome/src/ui/locales/emergency-copy.mjs b/src/chrome/src/ui/locales/emergency-copy.mjsindex 9755aafb7..41295add7 100644--- a/src/chrome/src/ui/locales/emergency-copy.mjs+++ b/src/chrome/src/ui/locales/emergency-copy.mjs@@ -5,7 +5,7 @@ const emergencyCopy = {'ap.emergency.desc': 'Choose another Wikipedia language or an edition with images, then add OpenStax textbooks and trusted emergency PDFs.','ap.emergency.open': 'Open Emergency Box','ap.emergency.gate': 'Complete the three basic downloads above first. Emergency Box stays locked so the core offline chat, vision, and knowledge setup is ready before you add optional resources.',- 'ap.webgpu.rag': 'Runs LFM2.5 2.6B on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.',+ 'ap.webgpu.rag': 'Runs {model} on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.','ap.webgpu.rag.pro': 'Runs Bonsai 27B on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.','ap.reader.open': 'Read','ar.page_title': 'WebBrain — Offline Wikipedia Reader',diff --git a/src/chrome/src/ui/locales/emergency-translations.mjs b/src/chrome/src/ui/locales/emergency-translations.mjsindex e56f06508..10aee923c 100644--- a/src/chrome/src/ui/locales/emergency-translations.mjs+++ b/src/chrome/src/ui/locales/emergency-translations.mjs@@ -4,7 +4,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Elige otro idioma de Wikipedia o una edición con imágenes y, después, añade libros de texto de OpenStax y PDF de emergencia de confianza.","ap.emergency.open": "Abrir la Caja de Emergencia","ap.emergency.gate": "Completa primero las tres descargas básicas de arriba. La Caja de Emergencia permanece bloqueada para que el chat, la visión y el conocimiento esenciales sin conexión estén listos antes de que añadas recursos opcionales.",- "ap.webgpu.rag": "Ejecuta LiquidAI/LFM2.5-2.6B-ONNX en tu GPU y los chats permanecen en este dispositivo. Cuando hay un archivo de Wikipedia instalado, el chat local recupera los pasajes coincidentes y cita la fecha del archivo.",+ "ap.webgpu.rag": "Ejecuta {model} en tu GPU y los chats permanecen en este dispositivo. Cuando hay un archivo de Wikipedia instalado, el chat local recupera los pasajes coincidentes y cita la fecha del archivo.","ap.reader.open": "Leer","ar.page_title": "WebBrain — Lector de Wikipedia sin conexión","ar.back": "Volver al Modo Apocalipsis",@@ -142,7 +142,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Choisissez une autre langue Wikipédia ou une édition avec images, puis ajoutez des manuels OpenStax et des PDF d'urgence fiables.","ap.emergency.open": "Ouvrir la Boîte d'urgence","ap.emergency.gate": "Terminez d'abord les trois téléchargements de base ci-dessus. La Boîte d'urgence reste verrouillée afin que la configuration essentielle hors ligne du chat, de la vision et des connaissances soit prête avant d'ajouter des ressources facultatives.",- "ap.webgpu.rag": "Exécute LiquidAI/LFM2.5-2.6B-ONNX sur votre GPU, les conversations restant sur cet appareil. Lorsqu'une archive Wikipédia est installée, le chat local récupère les passages correspondants et cite la date de l'archive.",+ "ap.webgpu.rag": "Exécute {model} sur votre GPU, les conversations restant sur cet appareil. Lorsqu'une archive Wikipédia est installée, le chat local récupère les passages correspondants et cite la date de l'archive.","ap.reader.open": "Lire","ar.page_title": "WebBrain — Lecteur Wikipédia hors ligne","ar.back": "Retour au mode Apocalypse",@@ -280,7 +280,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Başka bir Wikipedia dilini veya görselli bir sürümü seçin, ardından OpenStax ders kitapları ve güvenilir acil durum PDF'leri ekleyin.","ap.emergency.open": "Acil Durum Kutusu'nu aç","ap.emergency.gate": "Önce yukarıdaki üç temel indirmeyi tamamlayın. Acil Durum Kutusu kilitli kalır; böylece isteğe bağlı kaynakları eklemeden önce temel çevrimdışı sohbet, görüntü ve bilgi kurulumu hazır olur.",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX'i GPU'nuzda çalıştırır ve sohbetler bu cihazda kalır. Bir Wikipedia arşivi kurulduğunda, yerel sohbet eşleşen bölümleri getirir ve arşiv tarihini belirtir.",+ "ap.webgpu.rag": "{model}'i GPU'nuzda çalıştırır ve sohbetler bu cihazda kalır. Bir Wikipedia arşivi kurulduğunda, yerel sohbet eşleşen bölümleri getirir ve arşiv tarihini belirtir.","ap.reader.open": "Oku","ar.page_title": "WebBrain — Çevrimdışı Wikipedia Okuyucu","ar.back": "Kıyamet Modu'na dön",@@ -418,7 +418,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "选择另一种 Wikipedia 语言或含图片的版本,然后添加 OpenStax 教科书和可信的应急 PDF。","ap.emergency.open": "打开应急箱","ap.emergency.gate": "请先完成上面的三项必要下载。应急箱保持锁定,这样在添加可选资源之前,核心的离线聊天、视觉和知识设置就已经就绪。",- "ap.webgpu.rag": "在 GPU 上运行 LiquidAI/LFM2.5-2.6B-ONNX,聊天数据保存在本设备上。当安装了 Wikipedia 存档后,本地聊天会检索匹配的段落并注明存档日期。",+ "ap.webgpu.rag": "在 GPU 上运行 {model},聊天数据保存在本设备上。当安装了 Wikipedia 存档后,本地聊天会检索匹配的段落并注明存档日期。","ap.reader.open": "阅读","ar.page_title": "WebBrain — 离线 Wikipedia 阅读器","ar.back": "返回末日模式",@@ -556,7 +556,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Выберите другой язык Википедии или версию с изображениями, затем добавьте учебники OpenStax и доверенные аварийные PDF.","ap.emergency.open": "Открыть аварийный ящик","ap.emergency.gate": "Сначала завершите три базовые загрузки выше. Аварийный ящик остаётся заблокированным, чтобы базовая настройка офлайн-чата, зрения и знаний была готова, прежде чем вы добавите дополнительные ресурсы.",- "ap.webgpu.rag": "Запускает LiquidAI/LFM2.5-2.6B-ONNX на вашем GPU, а переписка остаётся на этом устройстве. Когда установлен архив Википедии, локальный чат находит подходящие фрагменты и указывает дату архива.",+ "ap.webgpu.rag": "Запускает {model} на вашем GPU, а переписка остаётся на этом устройстве. Когда установлен архив Википедии, локальный чат находит подходящие фрагменты и указывает дату архива.","ap.reader.open": "Читать","ar.page_title": "WebBrain — Офлайн-читалка Википедии","ar.back": "Назад в режим апокалипсиса",@@ -694,7 +694,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Виберіть іншу мову Вікіпедії або версію з зображеннями, потім додайте підручники OpenStax і надійні аварійні PDF.","ap.emergency.open": "Відкрити аварійну скриньку","ap.emergency.gate": "Спершу завершіть три базові завантаження вище. Аварійна скринька залишається заблокованою, щоб базова офлайн-настройка чату, зору та знань була готова, перш ніж ви додасте додаткові ресурси.",- "ap.webgpu.rag": "Запускає LiquidAI/LFM2.5-2.6B-ONNX на вашому GPU, а переписка залишається на цьому пристрої. Коли встановлено архів Вікіпедії, локальний чат знаходить відповідні фрагменти та вказує дату архіву.",+ "ap.webgpu.rag": "Запускає {model} на вашому GPU, а переписка залишається на цьому пристрої. Коли встановлено архів Вікіпедії, локальний чат знаходить відповідні фрагменти та вказує дату архіву.","ap.reader.open": "Читати","ar.page_title": "WebBrain — Офлайн-читач Вікіпедії","ar.back": "Назад до режиму апокаліпсису",@@ -832,7 +832,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "اختر لغة أخرى لويكيبيديا أو إصدارًا بالصور، ثم أضف كتب OpenStax المدرسية وملفات PDF موثوقة للطوارئ.","ap.emergency.open": "فتح صندوق الطوارئ","ap.emergency.gate": "أكمل التنزيلات الأساسية الثلاثة أعلاه أولًا. يظل صندوق الطوارئ مقفلًا حتى تكون إعدادات الدردشة والرؤية والمعرفة الأساسية دون اتصال جاهزة قبل إضافة الموارد الاختيارية.",- "ap.webgpu.rag": "يشغّل LiquidAI/LFM2.5-2.6B-ONNX على وحدة معالجة الرسومات لديك، وتبقى المحادثات على هذا الجهاز. عند تثبيت أرشيف ويكيبيديا، يبحث الدردشة المحلي عن المقاطع المطابقة ويذكر تاريخ الأرشيف.",+ "ap.webgpu.rag": "يشغّل {model} على وحدة معالجة الرسومات لديك، وتبقى المحادثات على هذا الجهاز. عند تثبيت أرشيف ويكيبيديا، يبحث الدردشة المحلي عن المقاطع المطابقة ويذكر تاريخ الأرشيف.","ap.reader.open": "اقرأ","ar.page_title": "WebBrain — قارئ ويكيبيديا دون اتصال","ar.back": "العودة إلى وضع نهاية العالم",@@ -970,7 +970,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "別のウィキペディア言語か、画像付きの版を選んでから、OpenStax の教科書と信頼できる緊急用 PDF を追加します。","ap.emergency.open": "緊急ボックスを開く","ap.emergency.gate": "まず上記の必須ダウンロード3つを完了してください。任意のリソースを追加する前に、基本のオフライン会話・視覚・知識のセットアップが整うまで、緊急ボックスはロックされたままです。",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX を GPU 上で実行し、会話はこのデバイスに留まります。ウィキペディアのアーカイブをインストールすると、ローカル会話が一致する節を取得し、アーカイブの日付を記載します。",+ "ap.webgpu.rag": "{model} を GPU 上で実行し、会話はこのデバイスに留まります。ウィキペディアのアーカイブをインストールすると、ローカル会話が一致する節を取得し、アーカイブの日付を記載します。","ap.reader.open": "読む","ar.page_title": "WebBrain — オフラインのウィキペディア リーダー","ar.back": "黙示録モードに戻る",@@ -1108,7 +1108,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "다른 위키백과 언어 또는 이미지 포함 버전을 선택한 다음 OpenStax 교과서와 신뢰할 수 있는 비상용 PDF를 추가하세요.","ap.emergency.open": "비상 상자 열기","ap.emergency.gate": "먼저 위의 필수 다운로드 3개를 완료하세요. 선택 리소스를 추가하기 전에 기본 오프라인 대화·시각·지식 설정이 갖춰질 때까지 비상 상자는 잠겨 있습니다.",- "ap.webgpu.rag": "GPU에서 LiquidAI/LFM2.5-2.6B-ONNX를 실행하며 대화는 이 기기에 남습니다. 위키백과 아카이브를 설치하면 로컬 대화가 일치하는 절을 가져오고 아카이브 날짜를 표시합니다.",+ "ap.webgpu.rag": "GPU에서 {model}를 실행하며 대화는 이 기기에 남습니다. 위키백과 아카이브를 설치하면 로컬 대화가 일치하는 절을 가져오고 아카이브 날짜를 표시합니다.","ap.reader.open": "읽기","ar.page_title": "WebBrain — 오프라인 위키백과 리더","ar.back": "묵시록 모드로 돌아가기",@@ -1246,7 +1246,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pilih bahasa Wikipedia lain atau edisi bergambar, lalu tambahkan buku teks OpenStax dan PDF darurat tepercaya.","ap.emergency.open": "Buka Kotak Darurat","ap.emergency.gate": "Selesaikan dulu tiga unduhan wajib di atas. Kotak Darurat tetap terkunci sehingga pengaturan dasar obrolan, penglihatan, dan pengetahuan offline sudah siap sebelum Anda menambahkan sumber opsional.",- "ap.webgpu.rag": "Menjalankan LiquidAI/LFM2.5-2.6B-ONNX di GPU Anda, dan percakapan tetap di perangkat ini. Saat arsip Wikipedia terpasang, obrolan lokal mengambil bagian yang cocok dan menyebutkan tanggal arsip.",+ "ap.webgpu.rag": "Menjalankan {model} di GPU Anda, dan percakapan tetap di perangkat ini. Saat arsip Wikipedia terpasang, obrolan lokal mengambil bagian yang cocok dan menyebutkan tanggal arsip.","ap.reader.open": "Baca","ar.page_title": "WebBrain — Pembaca Wikipedia Offline","ar.back": "Kembali ke Mode Kiamat",@@ -1384,7 +1384,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "เลือกภาษาอื่นของวิกิพีเดียหรือรุ่นที่มีรูปภาพ จากนั้นเพิ่มหนังสือเรียนของ OpenStax และไฟล์ PDF ฉุกเฉินที่เชื่อถือได้","ap.emergency.open": "เปิดกล่องฉุกเฉิน","ap.emergency.gate": "ดาวน์โหลดสามรายการที่จำเป็นข้างต้นให้เสร็จก่อน กล่องฉุกเฉินจะถูกล็อกไว้จนกว่าการตั้งค่าพื้นฐานแบบออฟไลน์สำหรับแชท การมองเห็น และความรู้จะพร้อม ก่อนที่คุณจะเพิ่มทรัพยากรเพิ่มเติม",- "ap.webgpu.rag": "รัน LiquidAI/LFM2.5-2.6B-ONNX บน GPU ของคุณ และการสนทนายังคงอยู่ในอุปกรณ์นี้ เมื่อติดตั้งคลังวิกิพีเดียแล้ว แชทในเครื่องจะดึงส่วนที่ตรงกันและระบุวันที่ของคลัง",+ "ap.webgpu.rag": "รัน {model} บน GPU ของคุณ และการสนทนายังคงอยู่ในอุปกรณ์นี้ เมื่อติดตั้งคลังวิกิพีเดียแล้ว แชทในเครื่องจะดึงส่วนที่ตรงกันและระบุวันที่ของคลัง","ap.reader.open": "อ่าน","ar.page_title": "WebBrain — โปรแกรมอ่านวิกิพีเดียแบบออฟไลน์","ar.back": "กลับไปที่โหมดวันสิ้นโลก",@@ -1522,7 +1522,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pilih bahasa Wikipedia lain atau edisi bergambar, kemudian tambahkan buku teks OpenStax dan PDF kecemasan yang dipercayai.","ap.emergency.open": "Buka Kotak Kecemasan","ap.emergency.gate": "Selesaikan dahulu tiga muat turun wajib di atas. Kotak Kecemasan kekal terkunci supaya persediaan asas untuk sembang, penglihatan dan pengetahuan luar talian sedia sebelum anda menambah sumber pilihan.",- "ap.webgpu.rag": "Menjalankan LiquidAI/LFM2.5-2.6B-ONNX pada GPU anda, dan perbualan kekal pada peranti ini. Apabila arkib Wikipedia dipasang, sembang setempat mengambil bahagian yang sepadan dan menyatakan tarikh arkib.",+ "ap.webgpu.rag": "Menjalankan {model} pada GPU anda, dan perbualan kekal pada peranti ini. Apabila arkib Wikipedia dipasang, sembang setempat mengambil bahagian yang sepadan dan menyatakan tarikh arkib.","ap.reader.open": "Baca","ar.page_title": "WebBrain — Pembaca Wikipedia Luar Talian","ar.back": "Kembali ke Mod Kiamat",@@ -1660,7 +1660,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pumili ng ibang wika ng Wikipedia o bersyong may mga larawan, pagkatapos ay magdagdag ng mga aklat-aralin ng OpenStax at mga pinagkakatiwalaang emergency PDF.","ap.emergency.open": "Buksan ang Kahon ng Emergency","ap.emergency.gate": "Kumpletuhin muna ang tatlong kinakailangang download sa itaas. Nakatakda ang Kahon ng Emergency hanggang sa maging handa ang pangunahing setup para sa offline na chat, paningin, at kaalaman bago ka magdagdag ng mga opsyonal na mapagkukunan.",- "ap.webgpu.rag": "Pinapatakbo ang LiquidAI/LFM2.5-2.6B-ONNX sa iyong GPU, at nananatili sa device na ito ang mga pag-uusap. Kapag naka-install ang isang archive ng Wikipedia, kinukuha ng lokal na chat ang mga tugmang seksyon at binabanggit ang petsa ng archive.",+ "ap.webgpu.rag": "Pinapatakbo ang {model} sa iyong GPU, at nananatili sa device na ito ang mga pag-uusap. Kapag naka-install ang isang archive ng Wikipedia, kinukuha ng lokal na chat ang mga tugmang seksyon at binabanggit ang petsa ng archive.","ap.reader.open": "Basahin","ar.page_title": "WebBrain — Offline Reader ng Wikipedia","ar.back": "Bumalik sa Apocalypse Mode",@@ -1798,7 +1798,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Wybierz inny język Wikipedii lub wersję z obrazkami, a następnie dodaj podręczniki OpenStax i zaufane pliki PDF na wypadek awarii.","ap.emergency.open": "Otwórz skrzynkę awaryjną","ap.emergency.gate": "Najpierw ukończ trzy obowiązkowe pobrania powyżej. Skrzynka awaryjna pozostaje zablokowana, aby podstawowa konfiguracja offline czatu, widzenia i wiedzy była gotowa, zanim dodasz opcjonalne zasoby.",- "ap.webgpu.rag": "Uruchamia LiquidAI/LFM2.5-2.6B-ONNX na Twoim GPU, a rozmowy pozostają na tym urządzeniu. Po zainstalowaniu archiwum Wikipedii lokalny czat pobiera pasujące sekcje i podaje datę archiwum.",+ "ap.webgpu.rag": "Uruchamia {model} na Twoim GPU, a rozmowy pozostają na tym urządzeniu. Po zainstalowaniu archiwum Wikipedii lokalny czat pobiera pasujące sekcje i podaje datę archiwum.","ap.reader.open": "Czytaj","ar.page_title": "WebBrain — Czytnik Wikipedii offline","ar.back": "Wróć do trybu Apokalipsy",@@ -1936,7 +1936,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "בחרו שפה אחרת של ויקיפדיה או מהדורה עם תמונות, ואז הוסיפו ספרי לימוד של OpenStax ו-PDF אמינים לחירום.","ap.emergency.open": "פתיחת קופסת החירום","ap.emergency.gate": "השלימו תחילה את שלושת ההורדות החובה למעלה. קופסת החירום נשארת נעולה כך שההתקנה הבסיסית של צ׳אט, ראייה וידע במצב לא מקוון מוכנה לפני שתוסיפו משאבים אופציונליים.",- "ap.webgpu.rag": "מריץ את LiquidAI/LFM2.5-2.6B-ONNX על ה-GPU שלכם, והשיחות נשארות במכשיר זה. כשמותקן ארכיון ויקיפדיה, הצ׳אט המקומי שולף קטעים תואמים ומציין את תאריך הארכיון.",+ "ap.webgpu.rag": "מריץ את {model} על ה-GPU שלכם, והשיחות נשארות במכשיר זה. כשמותקן ארכיון ויקיפדיה, הצ׳אט המקומי שולף קטעים תואמים ומציין את תאריך הארכיון.","ap.reader.open": "קריאה","ar.page_title": "WebBrain — קורא ויקיפדיה לא מקוון","ar.back": "חזרה למצב אפוקליפסה",@@ -2074,7 +2074,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "विकिपीडिया की कोई दूसरी भाषा या चित्रों वाला संस्करण चुनें, फिर OpenStax पाठ्यपुस्तकें और भरोसेमंद आपातकालीन PDF जोड़ें।","ap.emergency.open": "आपातकालीन बॉक्स खोलें","ap.emergency.gate": "पहले ऊपर दिए गए तीन अनिवार्य डाउनलोड पूरे करें। आपातकालीन बॉक्स तब तक लॉक रहता है, जब तक ऑफ़लाइन चैट, विज़न और ज्ञान की बुनियादी सेटअप आपके वैकल्पिक संसाधन जोड़ने से पहले तैयार न हो।",- "ap.webgpu.rag": "आपके GPU पर LiquidAI/LFM2.5-2.6B-ONNX चलाता है, और बातचीत इसी डिवाइस पर रहती है। जब विकिपीडिया का आर्काइव इंस्टॉल होता है, तो लोकल चैट मेल खाते अनुभाग खींचता है और आर्काइव की तारीख़ बताता है।",+ "ap.webgpu.rag": "आपके GPU पर {model} चलाता है, और बातचीत इसी डिवाइस पर रहती है। जब विकिपीडिया का आर्काइव इंस्टॉल होता है, तो लोकल चैट मेल खाते अनुभाग खींचता है और आर्काइव की तारीख़ बताता है।","ap.reader.open": "पढ़ें","ar.page_title": "WebBrain — ऑफ़लाइन विकिपीडिया रीडर","ar.back": "प्रलय मोड पर लौटें",@@ -2212,7 +2212,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Escolha outro idioma da Wikipédia ou uma edição com imagens e adicione livros didáticos do OpenStax e PDFs de emergência confiáveis.","ap.emergency.open": "Abrir a Caixa de Emergência","ap.emergency.gate": "Conclua primeiro os três downloads obrigatórios acima. A Caixa de Emergência permanece bloqueada para que a configuração básica offline de bate-papo, visão e conhecimento esteja pronta antes de você adicionar recursos opcionais.",- "ap.webgpu.rag": "Executa o LiquidAI/LFM2.5-2.6B-ONNX na sua GPU, e as conversas permanecem neste dispositivo. Quando um arquivo da Wikipédia está instalado, o bate-papo local busca as seções correspondentes e menciona a data do arquivo.",+ "ap.webgpu.rag": "Executa o {model} na sua GPU, e as conversas permanecem neste dispositivo. Quando um arquivo da Wikipédia está instalado, o bate-papo local busca as seções correspondentes e menciona a data do arquivo.","ap.reader.open": "Ler","ar.page_title": "WebBrain — Leitor offline da Wikipédia","ar.back": "Voltar ao Modo Apocalipse",@@ -2350,7 +2350,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Chọn ngôn ngữ Wikipedia khác hoặc bản có hình ảnh, rồi thêm sách giáo khoa OpenStax và các PDF khẩn cấp đáng tin cậy.","ap.emergency.open": "Mở Hộp Khẩn Cấp","ap.emergency.gate": "Trước tiên hãy hoàn tất ba bản tải xuống bắt buộc ở trên. Hộp Khẩn Cấp vẫn bị khóa để phần thiết lập cơ bản ngoại tuyến cho trò chuyện, thị giác và kiến thức sẵn sàng trước khi bạn thêm các tài nguyên tùy chọn.",- "ap.webgpu.rag": "Chạy LiquidAI/LFM2.5-2.6B-ONNX trên GPU của bạn và cuộc trò chuyện vẫn nằm trên thiết bị này. Khi kho lưu trữ Wikipedia được cài đặt, trò chuyện cục bộ sẽ truy xuất các mục phù hợp và ghi rõ ngày của kho lưu trữ.",+ "ap.webgpu.rag": "Chạy {model} trên GPU của bạn và cuộc trò chuyện vẫn nằm trên thiết bị này. Khi kho lưu trữ Wikipedia được cài đặt, trò chuyện cục bộ sẽ truy xuất các mục phù hợp và ghi rõ ngày của kho lưu trữ.","ap.reader.open": "Đọc","ar.page_title": "WebBrain — Trình đọc Wikipedia ngoại tuyến","ar.back": "Quay lại Chế độ Ngày tận thế",@@ -2488,7 +2488,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "উইকিপিডিয়ার অন্য একটি ভাষা বা ছবিসহ সংস্করণ বেছে নিন, তারপর OpenStax পাঠ্যবই এবং বিশ্বস্ত জরুরি PDF যোগ করুন।","ap.emergency.open": "জরুরি বাক্স খুলুন","ap.emergency.gate": "প্রথমে উপরের তিনটি বাধ্যতামূলক ডাউনলোড সম্পূর্ণ করুন। জরুরি বাক্সটি লক থাকবে যতক্ষণ না আপনি ঐচ্ছিক সম্পদ যোগ করার আগে অফলাইন চ্যাট, দৃষ্টি এবং জ্ঞানের মৌলিক সেটআপ প্রস্তুত হয়।",- "ap.webgpu.rag": "আপনার GPU-তে LiquidAI/LFM2.5-2.6B-ONNX চালায় এবং কথোপকথন এই ডিভাইসেই থাকে। উইকিপিডিয়া আর্কাইভ ইনস্টল হলে, লোকাল চ্যাট মিলে যাওয়া অংশগুলো টেনে আনে এবং আর্কাইভের তারিখ উল্লেখ করে।",+ "ap.webgpu.rag": "আপনার GPU-তে {model} চালায় এবং কথোপকথন এই ডিভাইসেই থাকে। উইকিপিডিয়া আর্কাইভ ইনস্টল হলে, লোকাল চ্যাট মিলে যাওয়া অংশগুলো টেনে আনে এবং আর্কাইভের তারিখ উল্লেখ করে।","ap.reader.open": "পড়ুন","ar.page_title": "WebBrain — অফলাইন উইকিপিডিয়া পাঠক","ar.back": "অ্যাপোক্যালিপস মোডে ফিরুন",@@ -2626,7 +2626,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "زبان دیگری از ویکیپدیا یا نسخهٔ تصویردار را انتخاب کنید، سپس کتابهای درسی OpenStax و PDFهای اضطراری قابلاعتماد را اضافه کنید.","ap.emergency.open": "باز کردن جعبهٔ اضطراری","ap.emergency.gate": "ابتدا سه دانلود اجباری بالا را کامل کنید. جعبهٔ اضطراری قفل میماند تا راهاندازی پایهٔ چت، بینایی و دانش بهصورت آفلاین آماده شود، پیش از آنکه منابع اختیاری را اضافه کنید.",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX را روی GPU شما اجرا میکند و گفتوگوها در همین دستگاه میمانند. وقتی بایگانی ویکیپدیا نصب میشود، چت محلی بخشهای منطبق را بازیابی و تاریخ بایگانی را ذکر میکند.",+ "ap.webgpu.rag": "{model} را روی GPU شما اجرا میکند و گفتوگوها در همین دستگاه میمانند. وقتی بایگانی ویکیپدیا نصب میشود، چت محلی بخشهای منطبق را بازیابی و تاریخ بایگانی را ذکر میکند.","ap.reader.open": "خواندن","ar.page_title": "WebBrain — خوانندهٔ ویکیپدیا بهصورت آفلاین","ar.back": "بازگشت به حالت آخرالزمان",@@ -2764,7 +2764,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Kies een andere Wikipedia-taal of een versie met afbeeldingen, en voeg dan OpenStax-studieboeken en vertrouwde nood-PDF's toe.","ap.emergency.open": "Noodbox openen","ap.emergency.gate": "Voltooi eerst de drie verplichte downloads hierboven. De Noodbox blijft vergrendeld zodat de basissetup voor offline chatten, zien en kennis klaar is voordat je optionele bronnen toevoegt.",- "ap.webgpu.rag": "Draait LiquidAI/LFM2.5-2.6B-ONNX op je GPU, en gesprekken blijven op dit apparaat. Wanneer een Wikipedia-archief is geïnstalleerd, haalt de lokale chat overeenkomende secties op en noemt de archiefdatum.",+ "ap.webgpu.rag": "Draait {model} op je GPU, en gesprekken blijven op dit apparaat. Wanneer een Wikipedia-archief is geïnstalleerd, haalt de lokale chat overeenkomende secties op en noemt de archiefdatum.","ap.reader.open": "Lezen","ar.page_title": "WebBrain — Offline Wikipedia-lezer","ar.back": "Terug naar Apocalypse-modus",@@ -2902,7 +2902,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Wähle eine andere Wikipedia-Sprache oder eine Ausgabe mit Bildern und füge dann OpenStax-Lehrbücher und vertrauenswürdige Notfall-PDFs hinzu.","ap.emergency.open": "Notfallbox öffnen","ap.emergency.gate": "Schließe zuerst die drei Pflicht-Downloads oben ab. Die Notfallbox bleibt gesperrt, damit das grundlegende Offline-Setup für Chat, Sehen und Wissen fertig ist, bevor du optionale Ressourcen hinzufügst.",- "ap.webgpu.rag": "Führt LiquidAI/LFM2.5-2.6B-ONNX auf deiner GPU aus, und Gespräche bleiben auf diesem Gerät. Wenn ein Wikipedia-Archiv installiert ist, ruft der lokale Chat passende Abschnitte ab und nennt das Archivdatum.",+ "ap.webgpu.rag": "Führt {model} auf deiner GPU aus, und Gespräche bleiben auf diesem Gerät. Wenn ein Wikipedia-Archiv installiert ist, ruft der lokale Chat passende Abschnitte ab und nennt das Archivdatum.","ap.reader.open": "Lesen","ar.page_title": "WebBrain — Offline-Wikipedia-Reader","ar.back": "Zurück zum Apokalypse-Modus",diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.jsindex e2f74ec87..5a07641dd 100644--- a/src/chrome/src/ui/settings.js+++ b/src/chrome/src/ui/settings.js@@ -72,6 +72,7 @@ import { canonicalizeOllamaBaseUrl } from '../providers/context-windows.js';import {WEBGPU_COMPASS_TINY_V2_MODEL_ID,WEBGPU_MODEL_PRESETS,+ WEBGPU_SELECTABLE_MODEL_PRESETS,WEBGPU_VISION_AUTO_SELECTED_KEY,WEBGPU_VISION_CONSENT_VERSION,WEBGPU_VISION_CONSENT_VERSION_KEY,@@ -3287,8 +3288,8 @@ function renderProviders() {labelKey: 'st.provider.field.model',type: 'text',placeholder: 'owner/repository',- suggestions: [WEBGPU_COMPASS_TINY_V2_MODEL_ID],- suggestionLabels: Object.fromEntries(WEBGPU_MODEL_PRESETS.filter(option => option.id === WEBGPU_COMPASS_TINY_V2_MODEL_ID).map(option => [+ suggestions: WEBGPU_SELECTABLE_MODEL_PRESETS.map(option => option.id),+ suggestionLabels: Object.fromEntries(WEBGPU_SELECTABLE_MODEL_PRESETS.map(option => [option.id,`${option.label} — ${option.id}${option.supportsVision ? ` — ${t('st.provider.field.supports_vision')}` : ''}`,])),diff --git a/src/chrome/vendor/bonsai2/LICENSE b/src/chrome/vendor/bonsai2/LICENSEnew file mode 100644index 000000000..d9a10c0d8--- /dev/null+++ b/src/chrome/vendor/bonsai2/LICENSE@@ -0,0 +1,176 @@+ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONSdiff --git a/src/chrome/vendor/bonsai2/NOTICE.txt b/src/chrome/vendor/bonsai2/NOTICE.txtnew file mode 100644index 000000000..5341ed98e--- /dev/null+++ b/src/chrome/vendor/bonsai2/NOTICE.txt@@ -0,0 +1,9 @@+This software is copyright 2026-present Prism ML, Inc. It is available under the Apache 2.0 license.+If you publicly deploy or redistribute this software, we would appreciate attribution such as: "Created using Bonsai by Prism ML."++This software is built from Qwen3.5-4B, Copyright 2026 Alibaba Cloud, which is available under the Apache 2.0 License: https://huggingface.co/Qwen/Qwen3.5-4B/blob/main/LICENSE+++WebBrain packages tokenizer_config.json from Mike0021/Ternary-Bonsai-2-4B-text-ONNX+revision f82021c254bc8044aa77cc4cbd3af181ba538afa as a JavaScript data export.+Used only to restore missing tokenizer metadata for danyalmalik's Ternary Bonsai 2 ONNX exports.diff --git a/src/chrome/vendor/bonsai2/tokenizer-config.js b/src/chrome/vendor/bonsai2/tokenizer-config.jsnew file mode 100644index 000000000..41ae6a9c6--- /dev/null+++ b/src/chrome/vendor/bonsai2/tokenizer-config.js@@ -0,0 +1,306 @@+// Apache-2.0; source and attribution in NOTICE.txt.+export const BONSAI2_TOKENIZER_CONFIG = {+ "add_prefix_space": false,+ "added_tokens_decoder": {+ "248044": {+ "content": "<|endoftext|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248045": {+ "content": "<|im_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248046": {+ "content": "<|im_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248047": {+ "content": "<|object_ref_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248048": {+ "content": "<|object_ref_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248049": {+ "content": "<|box_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248050": {+ "content": "<|box_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248051": {+ "content": "<|quad_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248052": {+ "content": "<|quad_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248053": {+ "content": "<|vision_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248054": {+ "content": "<|vision_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248055": {+ "content": "<|vision_pad|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248056": {+ "content": "<|image_pad|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248057": {+ "content": "<|video_pad|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248058": {+ "content": "<tool_call>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248059": {+ "content": "</tool_call>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248060": {+ "content": "<|fim_prefix|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248061": {+ "content": "<|fim_middle|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248062": {+ "content": "<|fim_suffix|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248063": {+ "content": "<|fim_pad|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248064": {+ "content": "<|repo_name|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248065": {+ "content": "<|file_sep|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248066": {+ "content": "<tool_response>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248067": {+ "content": "</tool_response>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248068": {+ "content": "<think>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248069": {+ "content": "</think>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": false+ },+ "248070": {+ "content": "<|audio_start|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248071": {+ "content": "<|audio_end|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248072": {+ "content": "<tts_pad>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248073": {+ "content": "<tts_text_bos>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248074": {+ "content": "<tts_text_eod>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248075": {+ "content": "<tts_text_bos_single>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ },+ "248076": {+ "content": "<|audio_pad|>",+ "lstrip": false,+ "normalized": false,+ "rstrip": false,+ "single_word": false,+ "special": true+ }+ },+ "additional_special_tokens": [+ "<|im_start|>",+ "<|im_end|>",+ "<|object_ref_start|>",+ "<|object_ref_end|>",+ "<|box_start|>",+ "<|box_end|>",+ "<|quad_start|>",+ "<|quad_end|>",+ "<|vision_start|>",+ "<|vision_end|>",+ "<|vision_pad|>",+ "<|image_pad|>",+ "<|video_pad|>"+ ],+ "bos_token": null,+ "chat_template": "{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or item.type == 'video' %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n{%- if tools and tools is iterable and tools is not mapping %}\n {{- '<|im_start|>system\\n' }}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\" }}\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" %}\n {%- set content = render_content(message.content, false)|trim %}\n {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if ns.multi_step_tool %}\n {{- raise_exception('No user query found in messages.') }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = render_content(message.content, true)|trim %}\n {%- if message.role == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n {%- if loop.index0 > ns.last_query_index %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\\n\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- else %}\n {{- '<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- else %}\n {{- '\\n<tool_call>\\n<function=' + tool_call.name + '>\\n' }}\n {%- endif %}\n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}\n {{- args_value }}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if not loop.last and loop.nextitem.role != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- elif loop.last %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- else %}\n {{- raise_exception('Unexpected message role.') }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- else %}\n {{- '<think>\\n' }}\n {%- endif %}\n{%- endif %}",+ "clean_up_tokenization_spaces": false,+ "eos_token": "<|im_end|>",+ "errors": "replace",+ "model_max_length": 262144,+ "pad_token": "<|endoftext|>",+ "split_special_tokens": false,+ "tokenizer_class": "Qwen2Tokenizer",+ "unk_token": null,+ "add_bos_token": false,+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",+ "extra_special_tokens": {+ "audio_bos_token": "<|audio_start|>",+ "audio_eos_token": "<|audio_end|>",+ "audio_token": "<|audio_pad|>",+ "image_token": "<|image_pad|>",+ "video_token": "<|video_pad|>",+ "vision_bos_token": "<|vision_start|>",+ "vision_eos_token": "<|vision_end|>"+ }+};diff --git a/src/chrome/vendor/transformers/README.md b/src/chrome/vendor/transformers/README.mdindex 77657d097..632e630c6 100644--- a/src/chrome/vendor/transformers/README.md+++ b/src/chrome/vendor/transformers/README.md@@ -3,10 +3,10 @@This directory packages the JavaScript and WASM runtime used by two localWebGPU paths in Chrome and by offline RAG's CPU/WASM semantic reranker:-- **Apocalypse Mode / Settings -> local WebGPU chat** downloads Compass Tiny- v2.1 (`webbrain-one/webbrain-compass-tiny-v2.1`, ~1.87 GB), the sole text- preset exposed in the UI, used by the standalone-chat nuclear control and- selectable as a normal chat provider. The underlying runtime also supports+- **Apocalypse Mode / Settings -> local WebGPU chat** offers Compass Tiny+ v2.1 (`webbrain-one/webbrain-compass-tiny-v2.1`, ~1.87 GB) and Ternary Bonsai 2+ 2B / 4B in text and vision variants, used by the standalone-chat nuclear+ control and selectable as a normal chat provider. The underlying runtime also supportsLFM2.5 and Nanbeige exports. An opt-in Bonsai 27B preset uses a separatevendored bitgpu worker, not this Transformers.js runtime; see`src/chrome/vendor/bitgpu/README.webbrain.md`.@@ -16,9 +16,9 @@ WebGPU paths in Chrome and by offline RAG's CPU/WASM semantic reranker:`Xenova/multilingual-e5-small` q8 model in a separate CPU/WASM worker. Modelweights remain optional and are never bundled or downloaded by a question.-Model weights are not bundled. Transformers.js downloads the WebGPU model on-first use and stores it in the browser cache. The exposed UI text preset is-Compass Tiny v2.1 (~1.87 GB), with underlying runtime support for LFM2.5+Model weights are not bundled. Explicit download controls fetch the selected+WebGPU model and store it in the browser cache; inference only uses cached+models. The default preset is Compass Tiny v2.1 (~1.87 GB), with underlying runtime support for LFM2.5(2.6B, 1.2B Instruct, 1.2B Thinking, VL 1.6B, VL 3B) and Nanbeige4.2-3B.Compass Tiny v2.1 is available through the nuclear control in standalone chatand can also be configured, downloaded, and selected directly in Settings ->@@ -29,6 +29,23 @@ thinking out of visible answers. Current LFM2.5-VL layouts use:- `vision_encoder`: FP16- `decoder_model_merged`: Q4+Ternary Bonsai 2 uses Q2/FP16 language graphs, the existing Qwen3.5 hybrid+attention runtime, and (for the Vision presets) an FP16 vision encoder. Its+reproducible export is in `scripts/models/bonsai/`. Danyalmalik's 2B/4B split ports+omit tokenizer and generation sidecars; the worker seeds the licensed, packaged+Qwen3.5 metadata from `vendor/bonsai2/` for those exact repositories. It also+corrects their external-data declarations, chat stop tokens, and Q2 cache+precision. The 4B text preset uses Mike0021's+single causal graph with its own complete metadata. The Vision presets use+`webbrain-one/Ternary-Bonsai-2-{2B,4B}-ONNX-WebGPU-Vision`, the Qwen processor's+text-first image API, and a bounded image resolution.++For the split Bonsai text and Vision models, the worker corrects Transformers.js+4.2's text-only rotary cache offset; image turns keep the native three-axis+positions. Independent screenshots are processed separately before concatenating+their patches and grids, because the bundled image processor treats an image+array as video frames. These adaptations are scoped to the named Bonsai models.+`Michionlion/Nanbeige4.2-3B-ONNX-WebGPU` needs no bundle patch, but it doesneed two things from this runtime. It publishes one WebGPU-fused graph named`onnx/model_webgpu_mlp_q4f16.onnx` instead of the default `model_q4f16.onnx`,diff --git a/src/firefox/src/ui/locales/emergency-copy.mjs b/src/firefox/src/ui/locales/emergency-copy.mjsindex 9755aafb7..41295add7 100644--- a/src/firefox/src/ui/locales/emergency-copy.mjs+++ b/src/firefox/src/ui/locales/emergency-copy.mjs@@ -5,7 +5,7 @@ const emergencyCopy = {'ap.emergency.desc': 'Choose another Wikipedia language or an edition with images, then add OpenStax textbooks and trusted emergency PDFs.','ap.emergency.open': 'Open Emergency Box','ap.emergency.gate': 'Complete the three basic downloads above first. Emergency Box stays locked so the core offline chat, vision, and knowledge setup is ready before you add optional resources.',- 'ap.webgpu.rag': 'Runs LFM2.5 2.6B on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.',+ 'ap.webgpu.rag': 'Runs {model} on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.','ap.webgpu.rag.pro': 'Runs Bonsai 27B on your GPU, with chats staying on this device. When a Wikipedia archive is installed, local chat retrieves matching passages and cites the archive date.','ap.reader.open': 'Read','ar.page_title': 'WebBrain — Offline Wikipedia Reader',diff --git a/src/firefox/src/ui/locales/emergency-translations.mjs b/src/firefox/src/ui/locales/emergency-translations.mjsindex e56f06508..10aee923c 100644--- a/src/firefox/src/ui/locales/emergency-translations.mjs+++ b/src/firefox/src/ui/locales/emergency-translations.mjs@@ -4,7 +4,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Elige otro idioma de Wikipedia o una edición con imágenes y, después, añade libros de texto de OpenStax y PDF de emergencia de confianza.","ap.emergency.open": "Abrir la Caja de Emergencia","ap.emergency.gate": "Completa primero las tres descargas básicas de arriba. La Caja de Emergencia permanece bloqueada para que el chat, la visión y el conocimiento esenciales sin conexión estén listos antes de que añadas recursos opcionales.",- "ap.webgpu.rag": "Ejecuta LiquidAI/LFM2.5-2.6B-ONNX en tu GPU y los chats permanecen en este dispositivo. Cuando hay un archivo de Wikipedia instalado, el chat local recupera los pasajes coincidentes y cita la fecha del archivo.",+ "ap.webgpu.rag": "Ejecuta {model} en tu GPU y los chats permanecen en este dispositivo. Cuando hay un archivo de Wikipedia instalado, el chat local recupera los pasajes coincidentes y cita la fecha del archivo.","ap.reader.open": "Leer","ar.page_title": "WebBrain — Lector de Wikipedia sin conexión","ar.back": "Volver al Modo Apocalipsis",@@ -142,7 +142,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Choisissez une autre langue Wikipédia ou une édition avec images, puis ajoutez des manuels OpenStax et des PDF d'urgence fiables.","ap.emergency.open": "Ouvrir la Boîte d'urgence","ap.emergency.gate": "Terminez d'abord les trois téléchargements de base ci-dessus. La Boîte d'urgence reste verrouillée afin que la configuration essentielle hors ligne du chat, de la vision et des connaissances soit prête avant d'ajouter des ressources facultatives.",- "ap.webgpu.rag": "Exécute LiquidAI/LFM2.5-2.6B-ONNX sur votre GPU, les conversations restant sur cet appareil. Lorsqu'une archive Wikipédia est installée, le chat local récupère les passages correspondants et cite la date de l'archive.",+ "ap.webgpu.rag": "Exécute {model} sur votre GPU, les conversations restant sur cet appareil. Lorsqu'une archive Wikipédia est installée, le chat local récupère les passages correspondants et cite la date de l'archive.","ap.reader.open": "Lire","ar.page_title": "WebBrain — Lecteur Wikipédia hors ligne","ar.back": "Retour au mode Apocalypse",@@ -280,7 +280,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Başka bir Wikipedia dilini veya görselli bir sürümü seçin, ardından OpenStax ders kitapları ve güvenilir acil durum PDF'leri ekleyin.","ap.emergency.open": "Acil Durum Kutusu'nu aç","ap.emergency.gate": "Önce yukarıdaki üç temel indirmeyi tamamlayın. Acil Durum Kutusu kilitli kalır; böylece isteğe bağlı kaynakları eklemeden önce temel çevrimdışı sohbet, görüntü ve bilgi kurulumu hazır olur.",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX'i GPU'nuzda çalıştırır ve sohbetler bu cihazda kalır. Bir Wikipedia arşivi kurulduğunda, yerel sohbet eşleşen bölümleri getirir ve arşiv tarihini belirtir.",+ "ap.webgpu.rag": "{model}'i GPU'nuzda çalıştırır ve sohbetler bu cihazda kalır. Bir Wikipedia arşivi kurulduğunda, yerel sohbet eşleşen bölümleri getirir ve arşiv tarihini belirtir.","ap.reader.open": "Oku","ar.page_title": "WebBrain — Çevrimdışı Wikipedia Okuyucu","ar.back": "Kıyamet Modu'na dön",@@ -418,7 +418,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "选择另一种 Wikipedia 语言或含图片的版本,然后添加 OpenStax 教科书和可信的应急 PDF。","ap.emergency.open": "打开应急箱","ap.emergency.gate": "请先完成上面的三项必要下载。应急箱保持锁定,这样在添加可选资源之前,核心的离线聊天、视觉和知识设置就已经就绪。",- "ap.webgpu.rag": "在 GPU 上运行 LiquidAI/LFM2.5-2.6B-ONNX,聊天数据保存在本设备上。当安装了 Wikipedia 存档后,本地聊天会检索匹配的段落并注明存档日期。",+ "ap.webgpu.rag": "在 GPU 上运行 {model},聊天数据保存在本设备上。当安装了 Wikipedia 存档后,本地聊天会检索匹配的段落并注明存档日期。","ap.reader.open": "阅读","ar.page_title": "WebBrain — 离线 Wikipedia 阅读器","ar.back": "返回末日模式",@@ -556,7 +556,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Выберите другой язык Википедии или версию с изображениями, затем добавьте учебники OpenStax и доверенные аварийные PDF.","ap.emergency.open": "Открыть аварийный ящик","ap.emergency.gate": "Сначала завершите три базовые загрузки выше. Аварийный ящик остаётся заблокированным, чтобы базовая настройка офлайн-чата, зрения и знаний была готова, прежде чем вы добавите дополнительные ресурсы.",- "ap.webgpu.rag": "Запускает LiquidAI/LFM2.5-2.6B-ONNX на вашем GPU, а переписка остаётся на этом устройстве. Когда установлен архив Википедии, локальный чат находит подходящие фрагменты и указывает дату архива.",+ "ap.webgpu.rag": "Запускает {model} на вашем GPU, а переписка остаётся на этом устройстве. Когда установлен архив Википедии, локальный чат находит подходящие фрагменты и указывает дату архива.","ap.reader.open": "Читать","ar.page_title": "WebBrain — Офлайн-читалка Википедии","ar.back": "Назад в режим апокалипсиса",@@ -694,7 +694,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Виберіть іншу мову Вікіпедії або версію з зображеннями, потім додайте підручники OpenStax і надійні аварійні PDF.","ap.emergency.open": "Відкрити аварійну скриньку","ap.emergency.gate": "Спершу завершіть три базові завантаження вище. Аварійна скринька залишається заблокованою, щоб базова офлайн-настройка чату, зору та знань була готова, перш ніж ви додасте додаткові ресурси.",- "ap.webgpu.rag": "Запускає LiquidAI/LFM2.5-2.6B-ONNX на вашому GPU, а переписка залишається на цьому пристрої. Коли встановлено архів Вікіпедії, локальний чат знаходить відповідні фрагменти та вказує дату архіву.",+ "ap.webgpu.rag": "Запускає {model} на вашому GPU, а переписка залишається на цьому пристрої. Коли встановлено архів Вікіпедії, локальний чат знаходить відповідні фрагменти та вказує дату архіву.","ap.reader.open": "Читати","ar.page_title": "WebBrain — Офлайн-читач Вікіпедії","ar.back": "Назад до режиму апокаліпсису",@@ -832,7 +832,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "اختر لغة أخرى لويكيبيديا أو إصدارًا بالصور، ثم أضف كتب OpenStax المدرسية وملفات PDF موثوقة للطوارئ.","ap.emergency.open": "فتح صندوق الطوارئ","ap.emergency.gate": "أكمل التنزيلات الأساسية الثلاثة أعلاه أولًا. يظل صندوق الطوارئ مقفلًا حتى تكون إعدادات الدردشة والرؤية والمعرفة الأساسية دون اتصال جاهزة قبل إضافة الموارد الاختيارية.",- "ap.webgpu.rag": "يشغّل LiquidAI/LFM2.5-2.6B-ONNX على وحدة معالجة الرسومات لديك، وتبقى المحادثات على هذا الجهاز. عند تثبيت أرشيف ويكيبيديا، يبحث الدردشة المحلي عن المقاطع المطابقة ويذكر تاريخ الأرشيف.",+ "ap.webgpu.rag": "يشغّل {model} على وحدة معالجة الرسومات لديك، وتبقى المحادثات على هذا الجهاز. عند تثبيت أرشيف ويكيبيديا، يبحث الدردشة المحلي عن المقاطع المطابقة ويذكر تاريخ الأرشيف.","ap.reader.open": "اقرأ","ar.page_title": "WebBrain — قارئ ويكيبيديا دون اتصال","ar.back": "العودة إلى وضع نهاية العالم",@@ -970,7 +970,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "別のウィキペディア言語か、画像付きの版を選んでから、OpenStax の教科書と信頼できる緊急用 PDF を追加します。","ap.emergency.open": "緊急ボックスを開く","ap.emergency.gate": "まず上記の必須ダウンロード3つを完了してください。任意のリソースを追加する前に、基本のオフライン会話・視覚・知識のセットアップが整うまで、緊急ボックスはロックされたままです。",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX を GPU 上で実行し、会話はこのデバイスに留まります。ウィキペディアのアーカイブをインストールすると、ローカル会話が一致する節を取得し、アーカイブの日付を記載します。",+ "ap.webgpu.rag": "{model} を GPU 上で実行し、会話はこのデバイスに留まります。ウィキペディアのアーカイブをインストールすると、ローカル会話が一致する節を取得し、アーカイブの日付を記載します。","ap.reader.open": "読む","ar.page_title": "WebBrain — オフラインのウィキペディア リーダー","ar.back": "黙示録モードに戻る",@@ -1108,7 +1108,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "다른 위키백과 언어 또는 이미지 포함 버전을 선택한 다음 OpenStax 교과서와 신뢰할 수 있는 비상용 PDF를 추가하세요.","ap.emergency.open": "비상 상자 열기","ap.emergency.gate": "먼저 위의 필수 다운로드 3개를 완료하세요. 선택 리소스를 추가하기 전에 기본 오프라인 대화·시각·지식 설정이 갖춰질 때까지 비상 상자는 잠겨 있습니다.",- "ap.webgpu.rag": "GPU에서 LiquidAI/LFM2.5-2.6B-ONNX를 실행하며 대화는 이 기기에 남습니다. 위키백과 아카이브를 설치하면 로컬 대화가 일치하는 절을 가져오고 아카이브 날짜를 표시합니다.",+ "ap.webgpu.rag": "GPU에서 {model}를 실행하며 대화는 이 기기에 남습니다. 위키백과 아카이브를 설치하면 로컬 대화가 일치하는 절을 가져오고 아카이브 날짜를 표시합니다.","ap.reader.open": "읽기","ar.page_title": "WebBrain — 오프라인 위키백과 리더","ar.back": "묵시록 모드로 돌아가기",@@ -1246,7 +1246,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pilih bahasa Wikipedia lain atau edisi bergambar, lalu tambahkan buku teks OpenStax dan PDF darurat tepercaya.","ap.emergency.open": "Buka Kotak Darurat","ap.emergency.gate": "Selesaikan dulu tiga unduhan wajib di atas. Kotak Darurat tetap terkunci sehingga pengaturan dasar obrolan, penglihatan, dan pengetahuan offline sudah siap sebelum Anda menambahkan sumber opsional.",- "ap.webgpu.rag": "Menjalankan LiquidAI/LFM2.5-2.6B-ONNX di GPU Anda, dan percakapan tetap di perangkat ini. Saat arsip Wikipedia terpasang, obrolan lokal mengambil bagian yang cocok dan menyebutkan tanggal arsip.",+ "ap.webgpu.rag": "Menjalankan {model} di GPU Anda, dan percakapan tetap di perangkat ini. Saat arsip Wikipedia terpasang, obrolan lokal mengambil bagian yang cocok dan menyebutkan tanggal arsip.","ap.reader.open": "Baca","ar.page_title": "WebBrain — Pembaca Wikipedia Offline","ar.back": "Kembali ke Mode Kiamat",@@ -1384,7 +1384,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "เลือกภาษาอื่นของวิกิพีเดียหรือรุ่นที่มีรูปภาพ จากนั้นเพิ่มหนังสือเรียนของ OpenStax และไฟล์ PDF ฉุกเฉินที่เชื่อถือได้","ap.emergency.open": "เปิดกล่องฉุกเฉิน","ap.emergency.gate": "ดาวน์โหลดสามรายการที่จำเป็นข้างต้นให้เสร็จก่อน กล่องฉุกเฉินจะถูกล็อกไว้จนกว่าการตั้งค่าพื้นฐานแบบออฟไลน์สำหรับแชท การมองเห็น และความรู้จะพร้อม ก่อนที่คุณจะเพิ่มทรัพยากรเพิ่มเติม",- "ap.webgpu.rag": "รัน LiquidAI/LFM2.5-2.6B-ONNX บน GPU ของคุณ และการสนทนายังคงอยู่ในอุปกรณ์นี้ เมื่อติดตั้งคลังวิกิพีเดียแล้ว แชทในเครื่องจะดึงส่วนที่ตรงกันและระบุวันที่ของคลัง",+ "ap.webgpu.rag": "รัน {model} บน GPU ของคุณ และการสนทนายังคงอยู่ในอุปกรณ์นี้ เมื่อติดตั้งคลังวิกิพีเดียแล้ว แชทในเครื่องจะดึงส่วนที่ตรงกันและระบุวันที่ของคลัง","ap.reader.open": "อ่าน","ar.page_title": "WebBrain — โปรแกรมอ่านวิกิพีเดียแบบออฟไลน์","ar.back": "กลับไปที่โหมดวันสิ้นโลก",@@ -1522,7 +1522,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pilih bahasa Wikipedia lain atau edisi bergambar, kemudian tambahkan buku teks OpenStax dan PDF kecemasan yang dipercayai.","ap.emergency.open": "Buka Kotak Kecemasan","ap.emergency.gate": "Selesaikan dahulu tiga muat turun wajib di atas. Kotak Kecemasan kekal terkunci supaya persediaan asas untuk sembang, penglihatan dan pengetahuan luar talian sedia sebelum anda menambah sumber pilihan.",- "ap.webgpu.rag": "Menjalankan LiquidAI/LFM2.5-2.6B-ONNX pada GPU anda, dan perbualan kekal pada peranti ini. Apabila arkib Wikipedia dipasang, sembang setempat mengambil bahagian yang sepadan dan menyatakan tarikh arkib.",+ "ap.webgpu.rag": "Menjalankan {model} pada GPU anda, dan perbualan kekal pada peranti ini. Apabila arkib Wikipedia dipasang, sembang setempat mengambil bahagian yang sepadan dan menyatakan tarikh arkib.","ap.reader.open": "Baca","ar.page_title": "WebBrain — Pembaca Wikipedia Luar Talian","ar.back": "Kembali ke Mod Kiamat",@@ -1660,7 +1660,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Pumili ng ibang wika ng Wikipedia o bersyong may mga larawan, pagkatapos ay magdagdag ng mga aklat-aralin ng OpenStax at mga pinagkakatiwalaang emergency PDF.","ap.emergency.open": "Buksan ang Kahon ng Emergency","ap.emergency.gate": "Kumpletuhin muna ang tatlong kinakailangang download sa itaas. Nakatakda ang Kahon ng Emergency hanggang sa maging handa ang pangunahing setup para sa offline na chat, paningin, at kaalaman bago ka magdagdag ng mga opsyonal na mapagkukunan.",- "ap.webgpu.rag": "Pinapatakbo ang LiquidAI/LFM2.5-2.6B-ONNX sa iyong GPU, at nananatili sa device na ito ang mga pag-uusap. Kapag naka-install ang isang archive ng Wikipedia, kinukuha ng lokal na chat ang mga tugmang seksyon at binabanggit ang petsa ng archive.",+ "ap.webgpu.rag": "Pinapatakbo ang {model} sa iyong GPU, at nananatili sa device na ito ang mga pag-uusap. Kapag naka-install ang isang archive ng Wikipedia, kinukuha ng lokal na chat ang mga tugmang seksyon at binabanggit ang petsa ng archive.","ap.reader.open": "Basahin","ar.page_title": "WebBrain — Offline Reader ng Wikipedia","ar.back": "Bumalik sa Apocalypse Mode",@@ -1798,7 +1798,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Wybierz inny język Wikipedii lub wersję z obrazkami, a następnie dodaj podręczniki OpenStax i zaufane pliki PDF na wypadek awarii.","ap.emergency.open": "Otwórz skrzynkę awaryjną","ap.emergency.gate": "Najpierw ukończ trzy obowiązkowe pobrania powyżej. Skrzynka awaryjna pozostaje zablokowana, aby podstawowa konfiguracja offline czatu, widzenia i wiedzy była gotowa, zanim dodasz opcjonalne zasoby.",- "ap.webgpu.rag": "Uruchamia LiquidAI/LFM2.5-2.6B-ONNX na Twoim GPU, a rozmowy pozostają na tym urządzeniu. Po zainstalowaniu archiwum Wikipedii lokalny czat pobiera pasujące sekcje i podaje datę archiwum.",+ "ap.webgpu.rag": "Uruchamia {model} na Twoim GPU, a rozmowy pozostają na tym urządzeniu. Po zainstalowaniu archiwum Wikipedii lokalny czat pobiera pasujące sekcje i podaje datę archiwum.","ap.reader.open": "Czytaj","ar.page_title": "WebBrain — Czytnik Wikipedii offline","ar.back": "Wróć do trybu Apokalipsy",@@ -1936,7 +1936,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "בחרו שפה אחרת של ויקיפדיה או מהדורה עם תמונות, ואז הוסיפו ספרי לימוד של OpenStax ו-PDF אמינים לחירום.","ap.emergency.open": "פתיחת קופסת החירום","ap.emergency.gate": "השלימו תחילה את שלושת ההורדות החובה למעלה. קופסת החירום נשארת נעולה כך שההתקנה הבסיסית של צ׳אט, ראייה וידע במצב לא מקוון מוכנה לפני שתוסיפו משאבים אופציונליים.",- "ap.webgpu.rag": "מריץ את LiquidAI/LFM2.5-2.6B-ONNX על ה-GPU שלכם, והשיחות נשארות במכשיר זה. כשמותקן ארכיון ויקיפדיה, הצ׳אט המקומי שולף קטעים תואמים ומציין את תאריך הארכיון.",+ "ap.webgpu.rag": "מריץ את {model} על ה-GPU שלכם, והשיחות נשארות במכשיר זה. כשמותקן ארכיון ויקיפדיה, הצ׳אט המקומי שולף קטעים תואמים ומציין את תאריך הארכיון.","ap.reader.open": "קריאה","ar.page_title": "WebBrain — קורא ויקיפדיה לא מקוון","ar.back": "חזרה למצב אפוקליפסה",@@ -2074,7 +2074,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "विकिपीडिया की कोई दूसरी भाषा या चित्रों वाला संस्करण चुनें, फिर OpenStax पाठ्यपुस्तकें और भरोसेमंद आपातकालीन PDF जोड़ें।","ap.emergency.open": "आपातकालीन बॉक्स खोलें","ap.emergency.gate": "पहले ऊपर दिए गए तीन अनिवार्य डाउनलोड पूरे करें। आपातकालीन बॉक्स तब तक लॉक रहता है, जब तक ऑफ़लाइन चैट, विज़न और ज्ञान की बुनियादी सेटअप आपके वैकल्पिक संसाधन जोड़ने से पहले तैयार न हो।",- "ap.webgpu.rag": "आपके GPU पर LiquidAI/LFM2.5-2.6B-ONNX चलाता है, और बातचीत इसी डिवाइस पर रहती है। जब विकिपीडिया का आर्काइव इंस्टॉल होता है, तो लोकल चैट मेल खाते अनुभाग खींचता है और आर्काइव की तारीख़ बताता है।",+ "ap.webgpu.rag": "आपके GPU पर {model} चलाता है, और बातचीत इसी डिवाइस पर रहती है। जब विकिपीडिया का आर्काइव इंस्टॉल होता है, तो लोकल चैट मेल खाते अनुभाग खींचता है और आर्काइव की तारीख़ बताता है।","ap.reader.open": "पढ़ें","ar.page_title": "WebBrain — ऑफ़लाइन विकिपीडिया रीडर","ar.back": "प्रलय मोड पर लौटें",@@ -2212,7 +2212,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Escolha outro idioma da Wikipédia ou uma edição com imagens e adicione livros didáticos do OpenStax e PDFs de emergência confiáveis.","ap.emergency.open": "Abrir a Caixa de Emergência","ap.emergency.gate": "Conclua primeiro os três downloads obrigatórios acima. A Caixa de Emergência permanece bloqueada para que a configuração básica offline de bate-papo, visão e conhecimento esteja pronta antes de você adicionar recursos opcionais.",- "ap.webgpu.rag": "Executa o LiquidAI/LFM2.5-2.6B-ONNX na sua GPU, e as conversas permanecem neste dispositivo. Quando um arquivo da Wikipédia está instalado, o bate-papo local busca as seções correspondentes e menciona a data do arquivo.",+ "ap.webgpu.rag": "Executa o {model} na sua GPU, e as conversas permanecem neste dispositivo. Quando um arquivo da Wikipédia está instalado, o bate-papo local busca as seções correspondentes e menciona a data do arquivo.","ap.reader.open": "Ler","ar.page_title": "WebBrain — Leitor offline da Wikipédia","ar.back": "Voltar ao Modo Apocalipse",@@ -2350,7 +2350,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Chọn ngôn ngữ Wikipedia khác hoặc bản có hình ảnh, rồi thêm sách giáo khoa OpenStax và các PDF khẩn cấp đáng tin cậy.","ap.emergency.open": "Mở Hộp Khẩn Cấp","ap.emergency.gate": "Trước tiên hãy hoàn tất ba bản tải xuống bắt buộc ở trên. Hộp Khẩn Cấp vẫn bị khóa để phần thiết lập cơ bản ngoại tuyến cho trò chuyện, thị giác và kiến thức sẵn sàng trước khi bạn thêm các tài nguyên tùy chọn.",- "ap.webgpu.rag": "Chạy LiquidAI/LFM2.5-2.6B-ONNX trên GPU của bạn và cuộc trò chuyện vẫn nằm trên thiết bị này. Khi kho lưu trữ Wikipedia được cài đặt, trò chuyện cục bộ sẽ truy xuất các mục phù hợp và ghi rõ ngày của kho lưu trữ.",+ "ap.webgpu.rag": "Chạy {model} trên GPU của bạn và cuộc trò chuyện vẫn nằm trên thiết bị này. Khi kho lưu trữ Wikipedia được cài đặt, trò chuyện cục bộ sẽ truy xuất các mục phù hợp và ghi rõ ngày của kho lưu trữ.","ap.reader.open": "Đọc","ar.page_title": "WebBrain — Trình đọc Wikipedia ngoại tuyến","ar.back": "Quay lại Chế độ Ngày tận thế",@@ -2488,7 +2488,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "উইকিপিডিয়ার অন্য একটি ভাষা বা ছবিসহ সংস্করণ বেছে নিন, তারপর OpenStax পাঠ্যবই এবং বিশ্বস্ত জরুরি PDF যোগ করুন।","ap.emergency.open": "জরুরি বাক্স খুলুন","ap.emergency.gate": "প্রথমে উপরের তিনটি বাধ্যতামূলক ডাউনলোড সম্পূর্ণ করুন। জরুরি বাক্সটি লক থাকবে যতক্ষণ না আপনি ঐচ্ছিক সম্পদ যোগ করার আগে অফলাইন চ্যাট, দৃষ্টি এবং জ্ঞানের মৌলিক সেটআপ প্রস্তুত হয়।",- "ap.webgpu.rag": "আপনার GPU-তে LiquidAI/LFM2.5-2.6B-ONNX চালায় এবং কথোপকথন এই ডিভাইসেই থাকে। উইকিপিডিয়া আর্কাইভ ইনস্টল হলে, লোকাল চ্যাট মিলে যাওয়া অংশগুলো টেনে আনে এবং আর্কাইভের তারিখ উল্লেখ করে।",+ "ap.webgpu.rag": "আপনার GPU-তে {model} চালায় এবং কথোপকথন এই ডিভাইসেই থাকে। উইকিপিডিয়া আর্কাইভ ইনস্টল হলে, লোকাল চ্যাট মিলে যাওয়া অংশগুলো টেনে আনে এবং আর্কাইভের তারিখ উল্লেখ করে।","ap.reader.open": "পড়ুন","ar.page_title": "WebBrain — অফলাইন উইকিপিডিয়া পাঠক","ar.back": "অ্যাপোক্যালিপস মোডে ফিরুন",@@ -2626,7 +2626,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "زبان دیگری از ویکیپدیا یا نسخهٔ تصویردار را انتخاب کنید، سپس کتابهای درسی OpenStax و PDFهای اضطراری قابلاعتماد را اضافه کنید.","ap.emergency.open": "باز کردن جعبهٔ اضطراری","ap.emergency.gate": "ابتدا سه دانلود اجباری بالا را کامل کنید. جعبهٔ اضطراری قفل میماند تا راهاندازی پایهٔ چت، بینایی و دانش بهصورت آفلاین آماده شود، پیش از آنکه منابع اختیاری را اضافه کنید.",- "ap.webgpu.rag": "LiquidAI/LFM2.5-2.6B-ONNX را روی GPU شما اجرا میکند و گفتوگوها در همین دستگاه میمانند. وقتی بایگانی ویکیپدیا نصب میشود، چت محلی بخشهای منطبق را بازیابی و تاریخ بایگانی را ذکر میکند.",+ "ap.webgpu.rag": "{model} را روی GPU شما اجرا میکند و گفتوگوها در همین دستگاه میمانند. وقتی بایگانی ویکیپدیا نصب میشود، چت محلی بخشهای منطبق را بازیابی و تاریخ بایگانی را ذکر میکند.","ap.reader.open": "خواندن","ar.page_title": "WebBrain — خوانندهٔ ویکیپدیا بهصورت آفلاین","ar.back": "بازگشت به حالت آخرالزمان",@@ -2764,7 +2764,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Kies een andere Wikipedia-taal of een versie met afbeeldingen, en voeg dan OpenStax-studieboeken en vertrouwde nood-PDF's toe.","ap.emergency.open": "Noodbox openen","ap.emergency.gate": "Voltooi eerst de drie verplichte downloads hierboven. De Noodbox blijft vergrendeld zodat de basissetup voor offline chatten, zien en kennis klaar is voordat je optionele bronnen toevoegt.",- "ap.webgpu.rag": "Draait LiquidAI/LFM2.5-2.6B-ONNX op je GPU, en gesprekken blijven op dit apparaat. Wanneer een Wikipedia-archief is geïnstalleerd, haalt de lokale chat overeenkomende secties op en noemt de archiefdatum.",+ "ap.webgpu.rag": "Draait {model} op je GPU, en gesprekken blijven op dit apparaat. Wanneer een Wikipedia-archief is geïnstalleerd, haalt de lokale chat overeenkomende secties op en noemt de archiefdatum.","ap.reader.open": "Lezen","ar.page_title": "WebBrain — Offline Wikipedia-lezer","ar.back": "Terug naar Apocalypse-modus",@@ -2902,7 +2902,7 @@ const emergencyModeTranslations = {"ap.emergency.desc": "Wähle eine andere Wikipedia-Sprache oder eine Ausgabe mit Bildern und füge dann OpenStax-Lehrbücher und vertrauenswürdige Notfall-PDFs hinzu.","ap.emergency.open": "Notfallbox öffnen","ap.emergency.gate": "Schließe zuerst die drei Pflicht-Downloads oben ab. Die Notfallbox bleibt gesperrt, damit das grundlegende Offline-Setup für Chat, Sehen und Wissen fertig ist, bevor du optionale Ressourcen hinzufügst.",- "ap.webgpu.rag": "Führt LiquidAI/LFM2.5-2.6B-ONNX auf deiner GPU aus, und Gespräche bleiben auf diesem Gerät. Wenn ein Wikipedia-Archiv installiert ist, ruft der lokale Chat passende Abschnitte ab und nennt das Archivdatum.",+ "ap.webgpu.rag": "Führt {model} auf deiner GPU aus, und Gespräche bleiben auf diesem Gerät. Wenn ein Wikipedia-Archiv installiert ist, ruft der lokale Chat passende Abschnitte ab und nennt das Archivdatum.","ap.reader.open": "Lesen","ar.page_title": "WebBrain — Offline-Wikipedia-Reader","ar.back": "Zurück zum Apokalypse-Modus",diff --git a/test/quality/webgpu-presets-mv3.mjs b/test/quality/webgpu-presets-mv3.mjsnew file mode 100644index 000000000..504c2a1f2--- /dev/null+++ b/test/quality/webgpu-presets-mv3.mjs@@ -0,0 +1,92 @@+import assert from 'node:assert/strict';+import fs from 'node:fs/promises';+import os from 'node:os';+import path from 'node:path';+import { chromium } from 'playwright';+import { WEBGPU_SELECTABLE_MODEL_PRESETS } from '../../src/chrome/src/providers/webgpu.js';++// Exercise installed Settings, Apocalypse and provider-menu wiring. Only cache+// readiness is a fixture; this test neither downloads nor runs model weights.+const temporaryRoot = path.resolve(os.tmpdir());+const profile = await fs.mkdtemp(path.join(temporaryRoot, 'webbrain-bonsai-ui-'));+const extension = path.resolve('src/chrome');+let context;+try {+ context = await chromium.launchPersistentContext(profile, {+ headless: true,+ channel: 'chromium',+ viewport: { width: 1280, height: 1000 },+ args: [`--disable-extensions-except=${extension}`, `--load-extension=${extension}`],+ });+ const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30000 });+ const origin = `chrome-extension://${new URL(worker.url()).host}`;+ await worker.evaluate(async () => {+ await chrome.storage.local.set({ onboardingComplete: true, wbLocale: 'en', helpImproveWebBrain: false });+ const send = chrome.runtime.sendMessage.bind(chrome.runtime);+ chrome.runtime.sendMessage = (message, callback) => {+ if (message?.type !== 'webgpu-download-status') return send(message, callback);+ const state = { modelId: message.model, dtype: message.dtype, status: 'ready', ready: true };+ callback?.(state);+ return Promise.resolve(state);+ };+ });+ const page = await context.newPage();+ const errors = [];+ page.on('pageerror', error => errors.push(error.message));+ await page.goto(`${origin}/src/ui/settings.html#providers`);+ await page.locator('.provider-card[data-provider-id="webgpu"] .provider-header').click();+ const picker = page.locator('.model-select[data-model-for="webgpu"]');+ await picker.waitFor({ state: 'attached' });+ const ids = WEBGPU_SELECTABLE_MODEL_PRESETS.map(preset => preset.id);+ assert.deepEqual(await picker.locator('option').evaluateAll(options => options.map(option => option.value).filter(value => value !== '__custom__')), ids);+ const message = (action, data = {}) => page.evaluate(({ action, data }) => chrome.runtime.sendMessage({ target: 'background', action, ...data }), { action, data });+ for (const preset of WEBGPU_SELECTABLE_MODEL_PRESETS) {+ await picker.selectOption(preset.id, { force: true });+ assert.equal(await page.locator('input[data-provider="webgpu"][data-key="contextWindow"]').inputValue(), String(preset.contextWindow));+ await page.locator('.btn-save[data-provider="webgpu"]').click({ force: true });+ await page.waitForFunction(async id => {+ const state = await chrome.runtime.sendMessage({ target: 'background', action: 'get_providers' });+ return state.providers?.webgpu?.model === id;+ }, preset.id);+ const state = await message('get_providers');+ assert.equal(state.providers.webgpu.supportsVision, preset.supportsVision);+ assert.deepEqual(state.providers.webgpu.dtype, preset.dtype);+ }+ assert.equal((await message('set_active_provider', { providerId: 'webgpu' })).ok, true);+ const panel = await context.newPage();+ await panel.goto(`${origin}/src/ui/sidepanel.html`);+ await panel.waitForFunction(() => document.querySelector('#provider-select')?.value === 'webgpu');+ assert.ok((await panel.locator('#provider-select option[value="webgpu"]').textContent()).includes('WebGPU'));++ await message('update_provider', { providerId: 'webgpu', config: { contextWindow: 8192, promptTier: 'mid' } });+ await page.goto(`${origin}/src/ui/apocalypse-mode.html`);+ await page.waitForFunction(id => document.querySelector('[data-webgpu-text-preset]:checked')?.value === id, ids.at(-1));+ await page.waitForFunction(() => document.querySelector('[data-webgpu-download-panel]')?.dataset.state === 'ready');+ const hydrated = await message('get_providers');+ assert.equal(hydrated.providers.webgpu.contextWindow, 8192, 'opening Apocalypse must preserve a saved context budget');+ assert.equal(hydrated.providers.webgpu.promptTier, 'mid', 'opening Apocalypse must preserve a saved prompt tier');+ assert.deepEqual(await page.locator('[data-webgpu-text-preset]').evaluateAll(inputs => inputs.map(input => input.value)), ids);+ for (const preset of WEBGPU_SELECTABLE_MODEL_PRESETS) {+ await page.locator(`[data-webgpu-text-preset][value="${preset.id}"]`).check();+ await page.waitForFunction(async id => {+ const state = await chrome.runtime.sendMessage({ target: 'background', action: 'get_providers' });+ return state.providers?.webgpu?.model === id;+ }, preset.id);+ assert.ok((await page.locator('[data-webgpu-text-copy]').textContent()).includes(preset.label));+ }+ await message('update_provider', { providerId: 'webgpu', config: { model: ids[1], contextWindow: 4096 } });+ await page.waitForFunction(id => document.querySelector('[data-webgpu-text-preset]:checked')?.value === id, ids[1]);+ assert.equal((await message('get_providers')).providers.webgpu.contextWindow, 4096,+ 'polling must adopt an external Settings selection without overwriting its context budget');+ await page.setViewportSize({ width: 390, height: 900 });+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false);+ assert.deepEqual(errors, []);+ console.log('PASS: installed MV3 Settings and Apocalypse offer five presets; saved capabilities/context/tier, external selection changes, normal provider selection, and mobile layout verified. Cache readiness was mocked; no inference performed.');+} finally {+ await context?.close();+ const resolvedProfile = path.resolve(profile);+ if (path.dirname(resolvedProfile) !== temporaryRoot || !path.basename(resolvedProfile).startsWith('webbrain-bonsai-ui-')) {+ throw new Error('Refusing to remove a profile outside the test temporary directory.');+ }+ await fs.rm(resolvedProfile, { recursive: true, force: true });+}diff --git a/test/run.js b/test/run.jsindex d3919999b..ed43d5fd3 100644--- a/test/run.js+++ b/test/run.js@@ -1037,9 +1037,16 @@ const {WEBGPU_NANBEIGE42_3B_MODEL_ID,WEBGPU_MINICPM5_2B_MODEL_ID,WEBGPU_COMPASS_TINY_V2_MODEL_ID,+ WEBGPU_BONSAI2_2B_MODEL_ID,+ WEBGPU_BONSAI2_4B_MODEL_ID,+ WEBGPU_BONSAI2_VL_2B_MODEL_ID,+ WEBGPU_BONSAI2_VL_4B_MODEL_ID,+ WEBGPU_BONSAI2_DTYPE,+ WEBGPU_BONSAI2_VL_DTYPE,WEBGPU_BONSAI27_MODEL_ID,WEBGPU_MODEL_ID,WEBGPU_MODEL_PRESETS,+ WEBGPU_SELECTABLE_MODEL_PRESETS,WEBGPU_VISION_DTYPE,WEBGPU_VISION_AUTO_SELECTED_KEY,WEBGPU_VISION_CONSENT_VERSION,@@ -1051,6 +1058,7 @@ const {WEBGPU_VISION_READY_MARKER_VERSION,normalizeWebgpuModelId,isShippedWebgpuPreset,+ isSelectableWebgpuPreset,webgpuModelDtype,webgpuModelPreset,webgpuVisionReadyMarkerUrl,@@ -37920,10 +37928,10 @@ test('Apocalypse Mode keeps summary stats in its header and optional Wikipedia i'chrome: Emergency Box must render locked until basic setup is ready');assert.match(pageScript, /function updateEmergencyBoxGate\(readinessKind\)[\s\S]*?const locked = readinessKind !== 'ready'/,'chrome: Emergency Box is not gated by aggregate readiness');- assert.match(pageScript, /update_provider[\s\S]*?providerId: 'webgpu'[\s\S]*?model,[\s\S]*?contextWindow: preset\?\.contextWindow/, 'chrome: Apocalypse Mode does not configure the selected WebGPU download');+ assert.match(pageScript, /update_provider[\s\S]*?providerId: 'webgpu'[\s\S]*?config: preserveConfig \? \{\} : \{ model, dtype \}/, 'chrome: Apocalypse Mode must configure the selected download without replacing saved context settings');assert.match(pageHtml, /data-webgpu-text-preset/, 'chrome: the local text model picker is missing');assert.match(pageHtml, /value="webbrain-one\/webbrain-compass-tiny-v2\.1"/, 'chrome: the Compass Tiny v2.1 preset is missing');- assert.doesNotMatch(pageHtml, /value="prism-ml\/Bonsai-27B-gguf"/, 'chrome: only Compass Tiny v2.1 should be offered');+ assert.doesNotMatch(pageHtml, /value="prism-ml\/Bonsai-27B-gguf"/, 'chrome: the legacy 27B model should not be offered');assert.doesNotMatch(pageScript, /testWebgpuTextModel|providerCommand\('test_provider', \{ providerId: 'webgpu' \}\)/,'chrome: the removed local text Test action is still wired');assert.match(pageScript, /testWebgpuVisionModel[\s\S]*?providerCommand\('test_vision_provider'\)/,@@ -65310,6 +65318,159 @@ test('failed sensitive field-tool readbacks are annotated and redacted', () => {console.log('\nprovider categorization');+test('Bonsai WebGPU presets preserve ordered selection and model-specific image capabilities', async () => {+ const expectedIds = [WEBGPU_COMPASS_TINY_V2_MODEL_ID, WEBGPU_BONSAI2_2B_MODEL_ID, WEBGPU_BONSAI2_4B_MODEL_ID,+ WEBGPU_BONSAI2_VL_2B_MODEL_ID, WEBGPU_BONSAI2_VL_4B_MODEL_ID];+ assert.deepEqual(WEBGPU_SELECTABLE_MODEL_PRESETS.map(preset => preset.id), expectedIds);+ const html = fs.readFileSync(path.join(ROOT, 'src/chrome/src/ui/apocalypse-mode.html'), 'utf8');+ assert.deepEqual([...html.matchAll(/<input[^>]+value="([^"]+)"[^>]*data-webgpu-text-preset/g)].map(match => match[1]), expectedIds,+ 'the Apocalypse radio choices must stay in the same order as the Settings suggestions');+ assert.equal(isSelectableWebgpuPreset(''), false);+ assert.equal(isSelectableWebgpuPreset(WEBGPU_BONSAI27_MODEL_ID), false);+ assert.equal(isShippedWebgpuPreset(WEBGPU_BONSAI27_MODEL_ID), true, 'saved legacy presets must remain loadable');++ const manager = new ProviderManagerCh();+ manager.save = async () => {};+ manager.providers.set('webgpu', new WebGPUProvider(manager._defaultConfigs().webgpu));+ const messages = [{ role: 'user', content: [{ type: 'image_url', image_url: { url: 'data:image/png;base64,AA==' } }] }];+ for (const preset of WEBGPU_SELECTABLE_MODEL_PRESETS) {+ await manager.updateProvider('webgpu', { model: preset.id });+ const provider = manager.providers.get('webgpu');+ assert.equal(manager.getAll().webgpu.contextWindow, preset.contextWindow);+ assert.deepEqual(manager.getAll().webgpu.dtype, preset.dtype);+ assert.equal(provider.supportsVision, preset.supportsVision);+ assert.equal(provider.config.supportsVision, preset.supportsVision);+ assert.equal(provider.requiresToolTemplate, false);+ const sent = [];+ provider._dispatch = async message => {+ sent.push(message);+ return message.type === 'webgpu-download-status'+ ? { ready: true }+ : { ok: true, content: 'Local answer.', toolCalls: null };+ };+ if (preset.supportsVision) {+ await provider.chat(messages, { maxTokens: 32 });+ assert.equal(sent.at(-1).runtime, 'onnx-vl');+ assert.deepEqual(sent.at(-1).dtype, WEBGPU_BONSAI2_VL_DTYPE);+ assert.deepEqual(sent.at(-1).messages, messages);+ } else {+ await assert.rejects(provider.chat(messages), /text-only/);+ assert.equal(sent.length, 0, 'text-only rejection must happen before downloading or dispatching image data');+ if (preset.id !== WEBGPU_COMPASS_TINY_V2_MODEL_ID) assert.equal(provider.dtype, WEBGPU_BONSAI2_DTYPE);+ }+ }+ await manager.updateProvider('webgpu', { model: WEBGPU_COMPASS_TINY_V2_MODEL_ID });+ assert.equal(manager.getAll().webgpu.contextWindow, 32768);+ assert.equal(manager.getAll().webgpu.dtype, WEBGPU_DTYPE);+ assert.equal(manager.getAll().webgpu.supportsVision, false, 'switching back from vision must clear image capability');+ await manager.updateProvider('webgpu', { model: WEBGPU_BONSAI2_VL_4B_MODEL_ID, contextWindow: 4096, promptTier: 'mid' });+ await manager.updateProvider('webgpu', { model: WEBGPU_BONSAI2_VL_4B_MODEL_ID });+ assert.equal(manager.getAll().webgpu.contextWindow, 4096, 'saving the same preset must preserve a lowered context budget');+ assert.equal(manager.getAll().webgpu.promptTier, 'mid');+});++test('Apocalypse hydrates every selectable Bonsai preset and inspects sibling cache state without changing selection', async () => {+ const source = fs.readFileSync(path.join(ROOT, 'src/chrome/src/ui/apocalypse-mode.js'), 'utf8');+ const functions = source.slice(source.indexOf('async function refreshWebgpuDownloadStatus('), source.indexOf('async function onWebgpuTextPresetChange('));+ for (const preset of WEBGPU_SELECTABLE_MODEL_PRESETS) {+ const queried = [];+ const recorded = [];+ let selectedId = WEBGPU_COMPASS_TINY_V2_MODEL_ID;+ const context = vm.createContext({+ WEBGPU_SELECTABLE_MODEL_PRESETS, webgpuModelPreset, isSelectableWebgpuPreset,+ supportsWebgpuVision: true, webgpuDownloadStatusRequest: 0,+ webgpuPresetChangePending: false, fixedWebgpuProviderConfigured: false, fixedWebgpuProviderMarkedReady: false,+ CSS: { escape: value => value },+ selectedWebgpuModelId: () => selectedId,+ document: { querySelector: () => ({ set checked(value) { if (value) selectedId = preset.id; } }) },+ providerCommand: async (action, query) => {+ assert.equal(action, 'get_webgpu_download_status');+ const modelId = query?.model || preset.id;+ queried.push(modelId);+ if (query) assert.deepEqual(query.dtype, webgpuModelPreset(modelId).dtype);+ return { modelId, status: 'not-downloaded', ready: false };+ },+ ensureFixedWebgpuProvider: async () => { throw new Error('Unexpected model change'); },+ updateWebgpuTextPresetUi() {}, updateOverallModelsReadiness() {},+ recordWebgpuTextState: state => recorded.push(state),+ setWebgpuDownloadState: state => { assert.equal(state.status, 'not-downloaded'); },+ });+ vm.runInContext(functions, context);+ await vm.runInContext('refreshWebgpuDownloadStatus({ probeSibling: true })', context);+ assert.equal(selectedId, preset.id, 'opening Apocalypse must preserve the selected Bonsai variant');+ assert.equal(queried.length, 5);+ assert.deepEqual(new Set(queried), new Set(WEBGPU_SELECTABLE_MODEL_PRESETS.map(option => option.id)));+ assert.equal(recorded.length, 4);+ }+});++test('Apocalypse ignores stale preset status while saving and retains the selected model after a failed download', async () => {+ const source = fs.readFileSync(path.join(ROOT, 'src/chrome/src/ui/apocalypse-mode.js'), 'utf8');+ const functions = source.slice(source.indexOf('async function ensureFixedWebgpuProvider('), source.indexOf('async function runWebgpuDownloadAction('));+ const target = WEBGPU_BONSAI2_VL_4B_MODEL_ID;+ let selected = WEBGPU_COMPASS_TINY_V2_MODEL_ID;+ let saved = selected;+ let releaseOldStatus;+ let releaseSave;+ let statusCount = 0;+ const commands = [];+ const radios = WEBGPU_SELECTABLE_MODEL_PRESETS.map(preset => ({+ value: preset.id, disabled: false,+ set checked(value) { if (value) selected = preset.id; },+ }));+ const context = vm.createContext({+ WEBGPU_COMPASS_TINY_V2_MODEL_ID, WEBGPU_DTYPE, WEBGPU_SELECTABLE_MODEL_PRESETS,+ webgpuModelPreset, webgpuModelDtype, isSelectableWebgpuPreset,+ supportsWebgpuVision: true, webgpuDownloadStatusRequest: 0,+ webgpuPresetChangePending: false,+ fixedWebgpuProviderConfigured: false, fixedWebgpuProviderMarkedReady: false,+ webgpuDownloadState: { modelId: selected, dtype: WEBGPU_DTYPE, status: 'not-downloaded', ready: false },+ selectedWebgpuModelId: () => selected,+ selectedWebgpuPreset: () => webgpuModelPreset(selected),+ CSS: { escape: value => value },+ document: {+ querySelectorAll: () => radios,+ querySelector: selector => radios.find(radio => selector.includes(radio.value)),+ },+ updateWebgpuTextPresetUi() {}, updateWebgpuDownloadPanel() {}, updateOverallModelsReadiness() {}, recordWebgpuTextState() {},+ setWebgpuDownloadState: state => { context.webgpuDownloadState = state; },+ providerCommand: async (action, payload = {}) => {+ commands.push({ action, payload: structuredClone(payload) });+ if (action === 'update_provider') {+ await new Promise(resolve => { releaseSave = resolve; });+ saved = payload.config.model || saved;+ return { ok: true };+ }+ assert.equal(action, 'get_webgpu_download_status', 'selection must not start a model download');+ statusCount += 1;+ if (statusCount === 1) return new Promise(resolve => { releaseOldStatus = resolve; });+ return { modelId: payload.model || saved, dtype: webgpuModelPreset(payload.model || saved).dtype,+ status: 'error', ready: false, error: 'Download failed.' };+ },+ });+ vm.runInContext(functions, context);+ const staleRefresh = context.refreshWebgpuDownloadStatus();+ selected = target;+ const selection = context.onWebgpuTextPresetChange();+ assert.equal(radios.every(radio => radio.disabled), true);+ releaseOldStatus({ modelId: WEBGPU_COMPASS_TINY_V2_MODEL_ID, status: 'ready', ready: true });+ await staleRefresh;+ await context.refreshWebgpuDownloadStatus();+ assert.equal(statusCount, 1, 'polling must wait for the selected preset to finish saving');+ assert.equal(selected, target, 'an older ready response must not restore Compass');+ releaseSave();+ await selection;+ assert.equal(saved, target);+ assert.equal(selected, target);+ assert.equal(context.webgpuDownloadState.status, 'error');+ assert.equal(context.webgpuDownloadState.ready, false);+ assert.deepEqual(context.webgpuDownloadState.dtype, WEBGPU_BONSAI2_VL_DTYPE);+ assert.equal(radios.some(radio => radio.disabled), false, 'failed downloads must leave model selection available');+ assert.equal(commands.filter(command => command.action === 'update_provider').length, 1);+ assert.deepEqual(commands.find(command => command.action === 'update_provider').payload.config,+ { model: target, dtype: WEBGPU_BONSAI2_VL_DTYPE });+});+test('Chrome exposes separate endpoint-free WebGPU text and vision providers', async () => {const previousChrome = globalThis.chrome;const sentMessages = [];@@ -65397,6 +65558,10 @@ test('Chrome exposes separate endpoint-free WebGPU text and vision providers', a{ id: WEBGPU_NANBEIGE42_3B_MODEL_ID, label: 'Nanbeige4.2-3B', runtime: 'onnx', contextWindow: 4096, supportsVision: false },{ id: WEBGPU_MINICPM5_2B_MODEL_ID, label: 'MiniCPM5-2B', runtime: 'onnx', contextWindow: 16384, supportsVision: false },{ id: WEBGPU_COMPASS_TINY_V2_MODEL_ID, label: 'Compass Tiny v2.1', runtime: 'onnx', contextWindow: 32768, supportsVision: false },+ { id: WEBGPU_BONSAI2_2B_MODEL_ID, label: 'Ternary Bonsai 2 2B', runtime: 'onnx', contextWindow: 16384, supportsVision: false },+ { id: WEBGPU_BONSAI2_4B_MODEL_ID, label: 'Ternary Bonsai 2 4B', runtime: 'onnx', contextWindow: 16384, supportsVision: false },+ { id: WEBGPU_BONSAI2_VL_2B_MODEL_ID, label: 'Ternary Bonsai 2 2B Vision', runtime: 'onnx-vl', contextWindow: 16384, supportsVision: true },+ { id: WEBGPU_BONSAI2_VL_4B_MODEL_ID, label: 'Ternary Bonsai 2 4B Vision', runtime: 'onnx-vl', contextWindow: 16384, supportsVision: true },{ id: WEBGPU_BONSAI27_MODEL_ID, label: 'Basic text model', runtime: 'bitgpu', contextWindow: 4096, supportsVision: false },]);assert.equal(new WebGPUProvider({ model: WEBGPU_BONSAI27_MODEL_ID }).dtype, 'q1');@@ -66141,6 +66306,16 @@ test('Apocalypse text download fixes the Compass preset and avoids duplicate sta'webgpu-download-status',], 'an in-progress Compass download must not be queued twice');+ await manager.updateProvider('webgpu', { model: WEBGPU_BONSAI2_VL_4B_MODEL_ID, contextWindow: 8192, promptTier: 'mid' });+ downloadState = { modelId: WEBGPU_BONSAI2_VL_4B_MODEL_ID, dtype: WEBGPU_BONSAI2_VL_DTYPE, status: 'ready', ready: true };+ sentMessages.length = 0;+ const cachedBonsai = await manager.enableAndStartWebgpuTextDownload();+ assert.equal(cachedBonsai.ready, true);+ assert.equal(cachedBonsai.started, false);+ assert.equal(manager.getAll().webgpu.contextWindow, 8192, 'enabling Apocalypse must preserve a saved Bonsai context budget');+ assert.equal(manager.getAll().webgpu.promptTier, 'mid');+ assert.deepEqual(sentMessages.map(message => message.type), ['webgpu-probe', 'webgpu-download-status']);+sentMessages.length = 0;hasWebGPU = false;downloadState = {@@ -66229,8 +66404,9 @@ test('Apocalypse controls retain Settings transfers while the preset stays on Coconst radio = { value: WEBGPU_COMPASS_TINY_V2_MODEL_ID, checked: true };const context = vm.createContext({WEBGPU_COMPASS_TINY_V2_MODEL_ID, WEBGPU_DTYPE, webgpuModelPreset, webgpuModelDtype, isShippedWebgpuPreset,+ isSelectableWebgpuPreset, WEBGPU_SELECTABLE_MODEL_PRESETS,supportsWebgpuVision: true, fixedWebgpuProviderConfigured: false, fixedWebgpuProviderMarkedReady: false,- webgpuPresetHydrated: false, webgpuDownloadStatusRequest: 0, webgpuDownloadState: { status: 'checking' },+ webgpuPresetChangePending: false, webgpuDownloadStatusRequest: 0, webgpuDownloadState: { status: 'checking' },snapshot: { enabled: false }, elements: {}, CSS: { escape: value => value },t: key => key, confirm: () => true,document: {@@ -66241,7 +66417,7 @@ test('Apocalypse controls retain Settings transfers while the preset stays on CoproviderCommand: async (action, payload = {}) => {commands.push({ action, payload: structuredClone(payload) });if (action === 'update_provider') {- configuredModel = payload.config.model;+ configuredModel = payload.config.model || configuredModel;return { ok: true };}if (action === 'get_webgpu_download_status') {@@ -66343,6 +66519,7 @@ test('Apocalypse enable keeps a selected Bonsai preset and does not auto-downloa...manager._defaultConfigs().webgpu,model: WEBGPU_BONSAI27_MODEL_ID,dtype: 'q1',+ contextWindow: 4096,configured: false,}));const result = await manager.enableAndStartWebgpuTextDownload();@@ -66427,8 +66604,8 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contracassert.doesNotMatch(apocalypseHtml, new RegExp(retiredId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')),`${retiredId} should no longer be offered in the Apocalypse WebGPU picker`);}- assert.equal((apocalypseHtml.match(/class="webgpu-capability"/g) || []).length, 0,- 'only the text-only Compass preset is offered, so no multimodal badge should remain');+ assert.equal((apocalypseHtml.match(/<span>Ternary Bonsai 2 [24]B Vision<\/span>/g) || []).length, 2,+ 'the two image-capable Bonsai options must identify their vision support');assert.match(worker, /decoder_model_merged:\s*'q4'/);assert.match(worker, /const blocks = \[\.\.\.imageBlocks, \.\.\.textBlocks\]/);assert.match(worker, /createVisionProbeImage\(runtime\.library\.RawImage\)/);@@ -66740,7 +66917,7 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contracsettingsScript.indexOf(' webgpu: {'),settingsScript.indexOf(' azure_openai: {'),);- assert.match(webgpuSettingsBlock, /WEBGPU_MODEL_PRESETS/);+ assert.match(webgpuSettingsBlock, /WEBGPU_SELECTABLE_MODEL_PRESETS/);assert.match(webgpuSettingsBlock, /CONTEXT_WINDOW_FIELD/);assert.match(webgpuSettingsBlock, /PROMPT_TIER_FIELD/);assert.match(apocalypseHtml, /data-i18n="ap\.models\.text\.title"/);@@ -66761,11 +66938,11 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contracassert.doesNotMatch(apocalypseHtml, />Basic text model<\/span>/);assert.doesNotMatch(apocalypseHtml, /· LFM2\.5 2\.6B/);assert.doesNotMatch(apocalypseHtml, /· Bonsai 27B/);- assert.match(emergencyCopy, /Runs LFM2\.5 2\.6B on your GPU/);+ assert.match(emergencyCopy, /Runs \{model\} on your GPU/);assert.match(emergencyCopy, /'ap\.webgpu\.rag\.pro': 'Runs Bonsai 27B on your GPU/);assert.match(apocalypseScript, /function onWebgpuTextPresetChange/);assert.match(apocalypseScript, /webgpuModelPreset/);- assert.match(apocalypseScript, /webgpuPresetHydrated/);+ assert.match(apocalypseScript, /webgpuPresetChangePending/);assert.match(apocalypseScript, /normalized\.modelId !== selectedWebgpuModelId\(\)/);assert.match(apocalypseScript, /function anyOtherWebgpuTextBusy/);assert.match(background, /getWebgpuDownloadStatus\(msg\)/,@@ -66779,7 +66956,7 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contracassert.doesNotMatch(apocalypseScript, /normalizeWebgpuModelId|set_active_provider/);assert.doesNotMatch(apocalypseScript, /providerCommand\('test_provider', \{ providerId: 'webgpu' \}\)/);assert.match(apocalypseScript, /providerCommand\('test_vision_provider'\)/);- assert.match(apocalypseScript, /update_provider[\s\S]*?providerId: 'webgpu'[\s\S]*?model,[\s\S]*?contextWindow: preset\?\.contextWindow [\s\S]*?promptTier: 'compact'/);+ assert.match(apocalypseScript, /update_provider[\s\S]*?providerId: 'webgpu'[\s\S]*?config: preserveConfig \? \{\} : \{ model, dtype \}/);assert.doesNotMatch(profileSync, /webgpuVisionEnabled/, 'Chrome-only vision selection must not profile-sync to Firefox');assert.doesNotMatch(profileSync, /webgpuVisionAutoSelected/, 'automatic local-vision provenance must not profile-sync to Firefox');assert.match(englishLocale, /Selecting “Use local fallback” checks WebGPU, records your consent,[\s\S]*Tasks report its status and never wait for it; keep Chrome open/);@@ -66830,7 +67007,7 @@ test('WebGPU worker follows local text-generation and WebBrain VL vision contracassert.match(bonsaiWorker, /return \{ content, reasoningContent, toolCalls \}/);assert.match(bonsaiWorker, /if \(queuedTextDownload === request\) queuedTextDownload = null/,'a completed download request must not clear a newer queued resume for the same model');- assert.match(apocalypseScript, /if \(!preset \|\| preset\.id !== WEBGPU_COMPASS_TINY_V2_MODEL_ID\)[\s\S]*?setWebgpuDownloadState\(state, \{ syncActiveTransfer: true \}\)[\s\S]*?ensureFixedWebgpuProvider\(\{ force: true \}\)[\s\S]*?get_webgpu_download_status/,+ assert.match(apocalypseScript, /if \(!isSelectableWebgpuPreset\(preset\?\.id\)\)[\s\S]*?setWebgpuDownloadState\(state, \{ syncActiveTransfer: true \}\)[\s\S]*?ensureFixedWebgpuProvider\(\{ force: true \}\)[\s\S]*?get_webgpu_download_status/,'Apocalypse Mode must replace a persisted custom WebGPU model with the checked shipped preset');const resumeHelpersStart = bonsaiWorker.indexOf('function parseContentRange');const resumeHelpersEnd = bonsaiWorker.indexOf('\n\nasync function fetchGgufForStorage', resumeHelpersStart);@@ -67373,6 +67550,260 @@ test('Vision Model removal deletes only its cache entries', async () => {}});+test('Bonsai 2 worker keeps native rotary positions continuous for text and images', async () => {+ const previousSelf = globalThis.self;+ const ortSymbol = Symbol.for('onnxruntime');+ const previousOrt = globalThis[ortSymbol];+ try {+ globalThis.self = {addEventListener() {}, postMessage() {}};+ globalThis[ortSymbol] = await import(pathToFileURL(path.join(ROOT, 'src/chrome/vendor/transformers/onnxruntime-common/index.js')).href);+ const {applyBonsai2RotaryCompatibility} = await import(`${pathToFileURL(path.join(ROOT, 'src/chrome/src/offscreen/inference-worker.js')).href}?bonsai2-rope-test`);+ const {Qwen3_5ForConditionalGeneration,Tensor} = await import(pathToFileURL(path.join(ROOT, 'src/chrome/vendor/transformers/transformers.web.js')).href);+ const makeModel = () => Object.assign(Object.create(Qwen3_5ForConditionalGeneration.prototype), {+ config:{image_token_id:248056,vision_start_token_id:248053,vision_config:{spatial_merge_size:2}},+ sessions:{decoder_model_merged:{inputNames:['position_ids']}},+ });+ const ids = new Tensor('int64',[1n,2n,3n],[1,3]);+ const mask = new Tensor('int64',[1n,1n,1n],[1,3]);+ for (const modelId of [+ 'danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU',+ 'danyalmalik/Ternary-Bonsai-2-4B-ONNX-WebGPU',+ 'webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision',+ 'webbrain-one/Ternary-Bonsai-2-4B-ONNX-WebGPU-Vision',+ ]) {+ const model = makeModel();+ applyBonsai2RotaryCompatibility(modelId,model);+ const prefill = model.prepare_inputs_for_generation(null,{input_ids:ids,attention_mask:mask},{});+ assert.deepEqual(prefill.position_ids.tolist(),Array.from({length:3},()=>[[0n,1n,2n]]));+ assert.deepEqual(prefill.rope_deltas.tolist(),[[0n]],'pure text must have no MRoPE offset');+ const next = model.prepare_inputs_for_generation(null,{+ input_ids:new Tensor('int64',[4n],[1,1]),+ attention_mask:new Tensor('int64',[1n,1n,1n,1n],[1,4]),+ rope_deltas:prefill.rope_deltas,past_key_values:{get_seq_length:()=>3},+ },{});+ assert.deepEqual(next.position_ids.tolist(),Array.from({length:3},()=>[[3n]]),'cached decoding must continue at position 3, not 9');+ const [,paddedDeltas] = model.get_rope_index(new Tensor('int64',[0n,2n,3n],[1,3]),null,null,new Tensor('int64',[0n,1n,1n],[1,3]));+ assert.deepEqual(paddedDeltas.tolist(),[[-1n]],'padding must not advance the next token position');+ const [imagePositions,imageDeltas] = model.get_rope_index(+ new Tensor('int64',[248053n,248056n,248056n,248056n,248056n,248054n],[1,6]),+ new Tensor('int64',[1n,4n,4n],[1,3]),null,new Tensor('int64',[1n,1n,1n,1n,1n,1n],[1,6]),+ );+ assert.deepEqual(imagePositions.tolist(),[[[0n,1n,1n,1n,1n,3n]],[[0n,1n,1n,2n,2n,3n]],[[0n,1n,2n,1n,2n,3n]]]);+ assert.deepEqual(imageDeltas.tolist(),[[-2n]],'image rotary compression must remain intact');+ }+ for(const modelId of ['custom/qwen3.5','Mike0021/Ternary-Bonsai-2-4B-text-ONNX']) {+ const model=makeModel(),original=model._get_text_only_rope_index;+ applyBonsai2RotaryCompatibility(modelId,model);+ assert.equal(model._get_text_only_rope_index,original,'unrelated runtime classes must remain unchanged');+ }+ } finally {+ if(previousSelf === undefined) delete globalThis.self; else globalThis.self=previousSelf;+ if(previousOrt === undefined) delete globalThis[ortSymbol]; else globalThis[ortSymbol]=previousOrt;+ }+});++test('Bonsai 2 worker loads split text exports and preserves Qwen vision/tool contracts', async () => {+ const previousSelf = globalThis.self;+ const previousCapture = globalThis.__bonsai2Capture;+ const previousFetch = globalThis.fetch;+ const previousCaches = globalThis.caches;+ let listener;+ const posted = [];+ const cacheEntries = new Map();+ let networkRequests = 0;+ try {+ globalThis.fetch = async () => { networkRequests++; throw new Error('Unexpected network request'); };+ const cache = {+ match: async url => cacheEntries.get(typeof url === 'string' ? url : url.url)?.clone(),+ put: async (url, response) => { cacheEntries.set(url, response.clone()); },+ keys: async () => [...cacheEntries.keys()].map(url => ({url})),+ delete: async url => cacheEntries.delete(typeof url === 'string' ? url : url.url),+ };+ globalThis.caches = {open:async () => cache, keys:async () => ['transformers-cache']};+ globalThis.self = {+ addEventListener: (type, callback) => { if (type === 'message') listener = callback; },+ postMessage: value => posted.push(value),+ };+ const worker = await import(`${pathToFileURL(path.join(ROOT, 'src/chrome/src/offscreen/inference-worker.js')).href}?bonsai2-test`);+ const textModel = 'danyalmalik/Ternary-Bonsai-2-2B-ONNX-WebGPU';+ const visionModel = 'webbrain-one/Ternary-Bonsai-2-2B-ONNX-WebGPU-Vision';+ const metadata = worker.bonsai2CompatibilityMetadata(`https://huggingface.co/${textModel}/resolve/main/tokenizer_config.json`);+ assert.equal(metadata.eos_token, '<|im_end|>');+ assert.equal(worker.tokenizerSupportsTools({ chat_template: metadata.chat_template }), true);+ assert.equal(worker.bonsai2CompatibilityMetadata(`https://example.com/${textModel}/resolve/main/tokenizer_config.json`), null);+ assert.equal(worker.bonsai2CompatibilityMetadata('https://huggingface.co/custom/model/resolve/main/tokenizer_config.json'), null);+ assert.equal(worker.bonsai2CompatibilityMetadata(`https://huggingface.co/${textModel}/resolve/main/tokenizer.json`), null);+ const generationUrl = `https://huggingface.co/${textModel}/resolve/main/generation_config.json`;+ assert.deepEqual(worker.bonsai2CompatibilityMetadata(generationUrl).eos_token_id, [248046,248044]);+ assert.equal(worker.bonsai2CompatibilityMetadata('https://huggingface.co/custom/model/resolve/main/generation_config.json'), null);+ const { PreTrainedTokenizer, PreTrainedModel } = await import(pathToFileURL(path.join(ROOT, 'src/chrome/vendor/transformers/transformers.web.js')).href);+ const tokenizer = new PreTrainedTokenizer({+ model: {type:'BPE',vocab:{a:0},merges:[]}, decoder:{type:'ByteLevel'},+ post_processor:null,pre_tokenizer:null,normalizer:null,added_tokens:[],+ }, metadata);+ const wrappedPage = '<untrusted_page_content id="abc">Page text</untrusted_page_content>';+ const rendered = tokenizer.apply_chat_template(worker.prepareTextMessages([+ {role:'user',content:'Read the page.'},+ {role:'assistant',tool_calls:[{type:'function',function:{name:'read_page',arguments:'{}'}}]},+ {role:'tool',content:wrappedPage},+ ]), {tokenize:false,add_generation_prompt:true,enable_thinking:false,+ tools:[{type:'function',function:{name:'read_page',parameters:{type:'object',properties:{}}}}]});+ assert.ok(rendered.includes(wrappedPage), 'the real template must retain the complete untrusted boundary');+ assert.ok(rendered.includes('<function=read_page>'), 'the real template must replay normalized tool calls');+ assert.match(rendered, /<think>\s*<\/think>\s*$/, 'thinking must be closed in the generation prefix');+ const imageShapes = [[1,4,6], [1,6,8]];+ const imageProcessor = Object.assign(async image => ({+ pixel_values: {dims:[image.rows * image.columns,3]},+ image_grid_thw: {tolist:() => [[1n,BigInt(image.rows),BigInt(image.columns)]]},+ }), {config:{merge_size:2}});+ const cat = (tensors, axis) => {+ assert.equal(axis, 0);+ return tensors[0].tolist+ ? {tolist:() => tensors.flatMap(tensor => tensor.tolist())}+ : {dims:[tensors.reduce((total, tensor) => total + tensor.dims[0], 0),3]};+ };+ const batchInputs = await worker.processMultimodalInputs({+ library:{cat}, processor:{image_processor:imageProcessor, tokenizer:prompt => ({prompt})},+ }, visionModel, [{rows:4,columns:6},{rows:6,columns:8}], 'First <|image_pad|> then <|image_pad|> compare.');+ assert.deepEqual(batchInputs.image_grid_thw.tolist(), imageShapes.map(grid => grid.map(BigInt)), 'each screenshot needs its own image grid');+ assert.deepEqual(batchInputs.pixel_values.dims, [72,3], 'different screenshot shapes must concatenate along the patch axis');+ assert.equal(batchInputs.prompt, `First ${'<|image_pad|>'.repeat(6)} then ${'<|image_pad|>'.repeat(12)} compare.`);+ const sourceConfig = {+ model_type: 'qwen3_5', architectures: ['Qwen3_5ForConditionalGeneration'],+ text_config: { hidden_size: 2048 },+ 'transformers.js_config': { use_external_data_format: { 'decoder_model_merged_q4f16.onnx': 2 } },+ };+ const module = `+ export const env = { version: 'test', backends: { onnx: { wasm: {} } } };+ const capture = globalThis.__bonsai2Capture;+ export const AutoConfig = { from_pretrained: async () => (${JSON.stringify(sourceConfig)}) };+ export async function pipeline(task, modelId, options) {+ capture.textLoads.push({modelId, options});+ options.progress_callback({status:'progress_total',name:modelId,loaded:150,total:300,progress:50,+ files:{'config.json':{loaded:100,total:100},'onnx/model.onnx_data':{loaded:50,total:200}}});+ options.progress_callback({status:'progress',name:modelId,file:'onnx/model.onnx_data',loaded:50,total:200,progress:25});+ options.progress_callback({status:'progress_total',name:modelId,loaded:300,total:300,progress:100,+ files:{'config.json':{loaded:100,total:100},'onnx/model.onnx_data':{loaded:200,total:200}}});+ options.progress_callback({status:'progress',name:modelId,file:'onnx/model.onnx_data',loaded:200,total:200,progress:100});+ options.progress_callback({status:'done',name:modelId,file:'onnx/model.onnx_data'});+ const root = 'https://huggingface.co/' + modelId + '/resolve/main/';+ const metadataResponse = options.local_files_only+ ? await (await caches.open('transformers-cache')).match(root + 'tokenizer_config.json')+ : await env.fetch(root + 'tokenizer_config.json');+ const metadata = await metadataResponse.json();+ const generationResponse = options.local_files_only+ ? await (await caches.open('transformers-cache')).match(root + 'generation_config.json')+ : await env.fetch(root + 'generation_config.json');+ capture.generationMetadata = await generationResponse.json();+ const fn = async (messages, generation) => {+ capture.generation = generation;+ capture.messages = messages;+ return [{generated_text: [{role:'assistant', content:'Text answer'}]}];+ };+ fn.tokenizer = { chat_template: metadata.chat_template };+ fn.model = {};+ fn.dispose = async () => {};+ return fn;+ }+ export const AutoProcessor = { from_pretrained: async (modelId, options) => {+ capture.processorOptions = options;+ const processor = async (prompt, images) => {+ if (typeof prompt !== 'string') throw new Error('Qwen requires text before images');+ capture.imageInputs = {prompt, images};+ return {input_ids:{dims:[1,3]}};+ };+ processor.image_processor = {max_pixels:16777216};+ processor.tokenizer = Object.assign(() => ({input_ids:{dims:[1,3]}}), {chat_template:'{% if tools %}{{ tools }}{% endif %}'});+ processor.apply_chat_template = (messages, options) => {+ capture.template = {messages, options};+ return 'Rendered Qwen prompt';+ };+ processor.batch_decode = () => ['Vision answer'];+ capture.processor = processor;+ return processor;+ }};+ export const AutoModelForImageTextToText = { from_pretrained: async (modelId, options) => {+ capture.visionLoads.push({modelId, options});+ return {generate: async (inputs) => {+ capture.visionGeneration = inputs;+ return {slice: () => ({})};+ }, dispose: async () => {}};+ }};+ export const load_image = async url => ({url});+ `;+ globalThis.__bonsai2Capture = { textLoads: [], visionLoads: [] };+ const capture = globalThis.__bonsai2Capture;+ let id = 0;+ const dispatch = async (type, payload = {}) => {+ const requestId = ++id;+ await listener({data:{id:requestId, type, payload}});+ const response = posted.find(value => value.id === requestId);+ assert.equal(response?.ok, true, response?.error || `No response to ${type}`);+ return response;+ };+ await dispatch('init', {transformersUrl:`data:text/javascript,${encodeURIComponent(module)}`});+ const tools = [{type:'function', function:{name:'read_page', parameters:{type:'object',properties:{}}}}];+ const textPayload = {modelId:textModel, dtype:'q2f16', requireTools:true,+ messages:[{role:'user',content:'<untrusted_page_content id="abc">Page text</untrusted_page_content>'}],+ options:{tools,maxTokens:1024}};+ const textDownload = await dispatch('download-text', textPayload);+ assert.equal(textDownload.loaded, 300, 'aggregate and file events must count downloaded bytes once');+ assert.equal(textDownload.total, 300, 'aggregate model totals must not be stored as another file');+ const visionProgressEvents = posted.filter(value => value.type === 'progress');+ assert.equal(visionProgressEvents.some(event => event.status === 'progress_total' || event.file === textModel), false,+ 'the vision host must receive only normalized file progress, avoiding the same double count');+ const visionFiles = new Map();+ for (const event of visionProgressEvents) if (event.total > 0) visionFiles.set(event.file, event);+ assert.equal([...visionFiles.values()].reduce((total, item) => total + item.total, 0), 300);+ assert.equal(capture.visionLoads.length, 0, 'text-only download must not load a missing vision graph');+ assert.deepEqual(capture.textLoads[0].options.config['transformers.js_config'].use_external_data_format, {+ 'embed_tokens_q2f16.onnx':1, 'decoder_model_merged_q2f16.onnx':1,+ });+ assert.deepEqual(capture.textLoads[0].options.config['transformers.js_config'].kv_cache_dtype, {q2f16:'float16'});+ assert.deepEqual(capture.textLoads[0].options.config.text_config.eos_token_id, [248046,248044], 'both chat turn end and end-of-text must stop generation');+ assert.equal(capture.textLoads[0].options.config.text_config.pad_token_id, 248044);+ const modelForStopping = {config:capture.textLoads[0].options.config, generation_config:{}};+ const generationConfig = PreTrainedModel.prototype._prepare_generation_config.call(modelForStopping, null, {});+ const stopping = PreTrainedModel.prototype._get_stopping_criteria.call(modelForStopping, generationConfig);+ assert.deepEqual(stopping([[43n,248046n]], []), [true], 'the real generation runtime must stop at the chat end token');+ assert.deepEqual(stopping([[43n,248044n]], []), [true], 'end-of-text must also terminate');+ assert.deepEqual(stopping([[43n,248045n]], []), [false], 'ordinary non-EOS tokens must not terminate');+ cacheEntries.delete(generationUrl); // Upgrade a cache created before the metadata fix.+ await dispatch('dispose-text');+ const textResult = await dispatch('text-chat', textPayload);+ assert.equal(textResult.content, 'Text answer');+ assert.equal(capture.textLoads.at(-1).options.local_files_only, true);+ assert.deepEqual(capture.generationMetadata.eos_token_id, [248046,248044]);+ assert.ok(cacheEntries.has(generationUrl), 'missing sidecars must be restored even during cached offline loading');+ assert.deepEqual(capture.generation.tokenizer_encode_kwargs, {enable_thinking:false});+ assert.equal(capture.generation.max_new_tokens, 1024);+ assert.deepEqual(capture.messages, textPayload.messages, 'page-content boundary must survive prompt preparation');+ const visionPayload = {...textPayload, modelId:visionModel,+ dtype:{embed_tokens:'q2f16',decoder_model_merged:'q2f16',vision_encoder:'fp16'},+ messages:[{role:'user',content:[{type:'image_url',image_url:{url:'data:image/png;base64,AA=='}},{type:'text',text:'Describe.'}]}]};+ await dispatch('download-text', visionPayload);+ assert.equal(capture.visionLoads.length, 1);+ assert.equal(capture.processorOptions.image_processor_config_file, 'processor_config.json');+ assert.equal(capture.processorOptions.chat_template_file, 'chat_template.jinja');+ assert.equal(capture.processor.image_processor.max_pixels, 1048576);+ const visionResult = await dispatch('multimodal-text-chat', visionPayload);+ assert.equal(visionResult.content, 'Vision answer');+ assert.deepEqual(capture.template.options.tools, tools);+ assert.equal(capture.template.options.enable_thinking, false);+ assert.equal(capture.imageInputs.images.url, 'data:image/png;base64,AA==');+ assert.equal(capture.imageInputs.prompt, 'Rendered Qwen prompt');+ await dispatch('stop-text-download', visionPayload);+ assert.equal((await dispatch('text-download-status', visionPayload)).ready, false);+ assert.equal((await dispatch('text-download-status', textPayload)).ready, true, 'removing vision must preserve text readiness');+ assert.equal(networkRequests, 0, 'packaged sidecars must never attempt a remote fetch');+ } finally {+ if (previousSelf === undefined) delete globalThis.self; else globalThis.self = previousSelf;+ if (previousCapture === undefined) delete globalThis.__bonsai2Capture; else globalThis.__bonsai2Capture = previousCapture;+ if (previousFetch === undefined) delete globalThis.fetch; else globalThis.fetch = previousFetch;+ if (previousCaches === undefined) delete globalThis.caches; else globalThis.caches = previousCaches;+ }+});+test('WebGPU worker replays text tool history and applies model-specific generation contracts', async () => {const previousSelf = globalThis.self;const previousCounts = globalThis.__webgpuRuntimeCounts;