Skip to content

Add @wllama/wllama-compat for Safari compatibility#223

Merged
ngxson merged 11 commits into
masterfrom
xsn/compat_safari
May 23, 2026
Merged

Add @wllama/wllama-compat for Safari compatibility#223
ngxson merged 11 commits into
masterfrom
xsn/compat_safari

Conversation

@ngxson

@ngxson ngxson commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added a compatibility API (setCompat) and runtime detection for Memory64/compat needs; published a new compat package.
  • Documentation

    • Updated README and added compat package docs with usage, hosting, and WebGPU guidance.
  • Chores

    • Version bumped to 3.2.2; build/publish pipeline updated to produce and publish compat WASM artifacts and CDN exports.
  • Examples

    • Demos auto-select local or CDN compat assets when running on localhost.
  • Tests

    • Tests updated to control/disable compat mode during runs.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR adds a compat build and runtime mode: a new @wllama/wllama-compat package and CDN mapping, build changes to produce asyncify-based WASM, feature detection (Memory64/JSPI), a Wllama.setCompat API, worker resource abstraction, worker-runtime compat handling, example wiring, and test updates.

Changes

Compat mode for JSPI/Memory64-less browsers

Layer / File(s) Summary
Build configuration for compat variant
CMakeLists.txt, scripts/docker-compose.yml, .gitignore, .prettierignore, package.json
Introduces WLLAMA_COMPILE_OPTIONS/WLLAMA_LINK_OPTIONS and conditional WLLAMA_COMPAT flags, adds a second Docker build pass to emit compat WASM into compat/wasm/, updates ignore/prettier rules, and bumps package version to 3.2.2.
Compat package definition and automation
compat/package.json, compat/README.md, compat/index.js, scripts/generate_wasm_from_cdn.js, scripts/post_build.sh
Adds @wllama/wllama-compat manifest and README; generate script emits WasmCompatFromCDN; post-build step syncs root version into compat/package.json; upload script now publishes compat package.
Environment and compat mode detection
src/utils.ts, src/wasm-from-cdn.ts
Decouples WebGPU detection from JSPI, adds isSupportMem64() and needCompat() helpers, updates CDN URLs to v3.2.2, and adds WasmCompatFromCDN.
Wllama setCompat API and model loading orchestration
src/wllama.ts
Adds WllamaCompat type and setCompat() API, initializes compat to 'default', evaluates needCompat() in loadModel, builds workerResources with compat overrides, and emits warnings when CDN compat is used or when Firefox-specific conditions occur.
Worker resource abstraction and JS code loading
src/worker.ts
Refactors ProxyToWorker to accept WllamaWorkerResources (wasmPath, optional jsPath, compat), adds getModuleCode() to resolve inline/fallback/fetched worker JS, and composes runOptions from resources.
Worker-level compat pointer and memory handling
src/workers-code/llama-cpp.js
Introduces isCompat flag and toSizeT() helper to switch numeric representation (Number vs BigInt) for memory sizing, pointer arithmetic, allocations, async read sizes, and cwrap pointer types.
Example demos with compat configuration
examples/basic/index.html, examples/embeddings/index.html, examples/multimodal/index.html, examples/tools/index.html, examples/main/...
Examples detect localhost to use local compat assets or default CDN; examples/main imports a virtual compat config, exports WLLAMA_COMPAT_CONFIG, and Vite plugin provides a virtual module for local compat artifacts; instance creation centralized to apply compat.
Test infrastructure updates for compat mode
src/mjs.test.ts, src/wllama.test.ts, src/wllama.wgpu.test.ts
Test helpers created to centralize Wllama construction and call setCompat(null) so tests run with compat disabled; tests updated to use helpers.
Documentation updates
compat/README.md, README.md
Adds compat README with self-hosting/Vite guidance and setCompat examples; README updated to point to compat docs and shows WebGPU compat usage.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • ngxson/wllama#217: Related to the CDN wasm export pipeline; shares generated-module changes for wasm CDN exports.
  • ngxson/wllama#215: Overlaps on JSPI/WebGPU detection and conditional compat vs non-compat build/runtime handling.
  • ngxson/wllama#192: Also updates wasm CDN URL mappings and the llama.cpp submodule/version pinning area.

"🐰
A compat layer hops into place,
Asyncify bridges a fragile space.
Old browsers hum, new paths align,
Wllama loads — small and fine.
🥕"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective: adding a new compat package for Safari compatibility. It directly reflects the primary purpose evident across the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch xsn/compat_safari

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ngxson

ngxson commented May 23, 2026

Copy link
Copy Markdown
Owner Author

CC @reeselevine , we are now distributing an optional package @wllama/wllama-compat

This is to avoid bloating user's node_modules. By default, the compat module is pulled from CDN. User can npm install it to serve it locally.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/workers-code/llama-cpp.js (1)

252-275: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize Memory64 read offsets before crossing into DOM APIs.

Line 261 forwards raw offset/req_size, and Line 273 uses raw out_ptr. In the non-compat Memory64 build those can be BigInt, but Blob.slice() in src/worker.ts and typed-array offsets only accept number, so async file reads can throw during model load. Convert them once at this JS boundary. The in-file 2GB cap makes that cast safe here.

Proposed fix
 const _wllama_js_file_read = async (path, offset, req_size, out_ptr) => {
   const name = _stripModelsPrefix(path);
+  const offsetNum = Number(offset);
+  const reqSizeNum = Number(req_size);
+  const outPtrNum = Number(out_ptr);
 
   pendingReadPromise = new Promise((res, rej) => {
     pendingReadResolve = res;
     pendingReadReject = rej;
   });
   isAwaitReading = true;
 
-  postMessage({ verb: 'fs.read_req', args: [name, offset, req_size] });
+  postMessage({ verb: 'fs.read_req', args: [name, offsetNum, reqSizeNum] });
 
   let data;
   try {
     data = await pendingReadPromise;
   } finally {
@@
 
   const bytes = new Uint8Array(data);
-  getHeapU8().set(bytes, out_ptr);
+  getHeapU8().set(bytes, outPtrNum);
   return toSizeT(bytes.length);
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workers-code/llama-cpp.js` around lines 252 - 275, _wllama_js_file_read
forwards Memory64 BigInt offsets into DOM APIs and typed-array ops; normalize
offset, req_size and out_ptr to JS Numbers before use. Inside
_wllama_js_file_read (and before postMessage/getHeapU8().set), coerce each of
offset, req_size, out_ptr from BigInt to Number (e.g. const off = typeof offset
=== 'bigint' ? Number(offset) : offset), then apply the existing in-file 2GB cap
(e.g. cappedOff = Math.min(off, 0x7fffffff)) for safety, use these capped
numeric values in postMessage({... args: [name, cappedOff, cappedReqSize] }) and
in getHeapU8().set(bytes, cappedOutPtr); leave
pendingReadPromise/pendingReadResolve/pendingReadReject, _stripModelsPrefix,
toSizeT unchanged.
🧹 Nitpick comments (1)
examples/embeddings/index.html (1)

39-43: 💤 Low value

Inconsistent compat configuration compared to other examples.

Other examples (basic, multimodal, tools) include the 'exclude_firefox' argument when calling setCompat() for localhost, but this example omits it. For consistency across all examples, consider adding it.

♻️ Proposed change for consistency
       wllama.setCompat({
         wasm: '../../compat/wasm/wllama.wasm',
         worker: '../../compat/wasm/wllama.js',
-      });
+      }, 'exclude_firefox');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/embeddings/index.html` around lines 39 - 43, The localhost compat
block for wllama is missing the exclude_firefox option; update the call to
wllama.setCompat(...) in the examples/embeddings/index.html file to include the
same 'exclude_firefox' argument used in other examples so the call to
wllama.setCompat({ wasm: ..., worker: ..., exclude_firefox: true }) matches the
basic/multimodal/tools examples and keeps behavior consistent across examples.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@compat/package.json`:
- Around line 5-6: The package sets "main": "index.js" but no compat/index.js
exists so importing the package root fails; fix by either adding a minimal
compat/index.js (and optional compat/index.d.ts) that re-exports the wasm
entrypoints, or by updating compat/package.json to remove or change "main" and
add appropriate "exports" entries that point only to the existing wasm files
(e.g., export "./wasm/*" and/or "./package.json" as needed); edit the
package.json "main" value or the "exports" map and/or create the minimal
compat/index.js file and ensure the release scripts (scripts/post_build.sh,
scripts/docker-compose.yml) will include it so root imports like import
'`@wllama/wllama-compat`' resolve.

In `@compat/README.md`:
- Around line 73-77: Summary: The README text incorrectly says "import it as
`?raw`" which conflicts with the example that uses `?url` for the .wasm file and
`?raw` for the worker JS. Fix: update the sentence to explicitly state that the
.wasm asset should be imported with `?url` and the worker JS with `?raw`
(referencing compatWasm and compatWorker in the example), or reword to: ".wasm
-> ?url; worker JS -> ?raw" so the guidance matches the import lines for
compatWasm and compatWorker.

In `@examples/basic/index.html`:
- Around line 91-97: The snippet only sets compat for localhost; add an else
branch to handle non-localhost by calling wllama.setCompat('default') so the app
uses the default compatibility on deployments—locate the window.location.href
check and the existing wllama.setCompat({...}, 'exclude_firefox') block and
append an else that invokes wllama.setCompat('default') for all other hosts.

In `@examples/main/src/config.ts`:
- Around line 3-4: The import in examples/main/src/config.ts references a
missing asset wllama.wasm (import lines compatWasm and compatWorker); fix by
either adding the missing file compat/wasm/wllama.wasm into the compat package
so `@wllama/wllama-compat/wasm/wllama.wasm`?url resolves, or update the example to
point compatWasm to a valid source (e.g., a CDN or the actual generated wasm
path used in your build) and keep the compatWorker import as-is.

In `@src/wllama.ts`:
- Line 153: The field this.compat is being initialized to WasmCompatFromCDN
which lets needCompat() trigger compat behavior by default; change
initialization so this.compat starts as null (or an explicit opt-out) and only
assign WasmCompatFromCDN inside setCompat()/when mode: 'firefox_safari' is
selected so compat becomes opt-in; update any places that rely on this.compat
(references around lines with WasmCompatFromCDN and methods needCompat(),
setCompat()) to handle a null compat value safely and ensure Firefox/Safari
compat is only enabled when setCompat(mode: 'firefox_safari') is called.
- Around line 493-501: The Firefox branch currently assumes missing JSPI when
workerResources.compat is false and emits an incorrect message (and the text has
a typo "compat more"); update the logic in the isFirefox() handling to
explicitly detect JSPI support (e.g., check an existing flag like
workerResources.jspiAvailable or add one) instead of inferring from
workerResources.compat, and emit one warning when JSPI is actually unavailable
and a different, accurate guidance when compat is simply off; also fix the typo
by replacing "compat more" with clearer wording such as "enable compat mode" in
the logger().warn calls.

In `@src/worker.ts`:
- Around line 78-83: The WllamaWorkerResources interface and init logic must
prevent using the default WLLAMA_EMSCRIPTEN_CODE JS when compat is true: update
the code that currently falls back to WLLAMA_EMSCRIPTEN_CODE to instead throw an
error (or require a compat-specific js payload) when resources.compat === true
and resources.jsPath is missing; specifically, change the logic that reads
jsPath/uses WLLAMA_EMSCRIPTEN_CODE (referencing WllamaWorkerResources, jsPath,
compat and the WLLAMA_EMSCRIPTEN_CODE constant) so it validates if (compat &&
!jsPath) { throw new Error("compat mode requires an explicit jsPath/compat JS
bundle"); } and remove the implicit fallback in that branch or provide a
dedicated compat JS constant.

---

Outside diff comments:
In `@src/workers-code/llama-cpp.js`:
- Around line 252-275: _wllama_js_file_read forwards Memory64 BigInt offsets
into DOM APIs and typed-array ops; normalize offset, req_size and out_ptr to JS
Numbers before use. Inside _wllama_js_file_read (and before
postMessage/getHeapU8().set), coerce each of offset, req_size, out_ptr from
BigInt to Number (e.g. const off = typeof offset === 'bigint' ? Number(offset) :
offset), then apply the existing in-file 2GB cap (e.g. cappedOff = Math.min(off,
0x7fffffff)) for safety, use these capped numeric values in postMessage({...
args: [name, cappedOff, cappedReqSize] }) and in getHeapU8().set(bytes,
cappedOutPtr); leave pendingReadPromise/pendingReadResolve/pendingReadReject,
_stripModelsPrefix, toSizeT unchanged.

---

Nitpick comments:
In `@examples/embeddings/index.html`:
- Around line 39-43: The localhost compat block for wllama is missing the
exclude_firefox option; update the call to wllama.setCompat(...) in the
examples/embeddings/index.html file to include the same 'exclude_firefox'
argument used in other examples so the call to wllama.setCompat({ wasm: ...,
worker: ..., exclude_firefox: true }) matches the basic/multimodal/tools
examples and keeps behavior consistent across examples.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07bcd36d-2e32-4ee4-88fd-685653b59353

📥 Commits

Reviewing files that changed from the base of the PR and between e8e134f and b1a4296.

⛔ Files ignored due to path filters (2)
  • examples/main/package-lock.json is excluded by !**/package-lock.json
  • src/wasm/wllama.wasm is excluded by !**/*.wasm
📒 Files selected for processing (27)
  • .gitignore
  • .prettierignore
  • CMakeLists.txt
  • README.md
  • compat/README.md
  • compat/index.ts
  • compat/package.json
  • compat/wasm/wllama.js
  • examples/basic/index.html
  • examples/embeddings/index.html
  • examples/main/package.json
  • examples/main/src/config.ts
  • examples/main/src/utils/wllama.context.tsx
  • examples/multimodal/index.html
  • examples/tools/index.html
  • llama.cpp
  • package.json
  • scripts/docker-compose.yml
  • scripts/generate_wasm_from_cdn.js
  • scripts/post_build.sh
  • src/utils.ts
  • src/wasm-from-cdn.ts
  • src/wasm/wllama.js
  • src/wllama.ts
  • src/worker.ts
  • src/workers-code/generated.ts
  • src/workers-code/llama-cpp.js

Comment thread compat/package.json
Comment thread compat/README.md Outdated
Comment thread examples/basic/index.html
Comment thread examples/main/src/config.ts Outdated
Comment thread src/wllama.ts Outdated
Comment thread src/wllama.ts
Comment thread src/worker.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/wllama.ts (1)

499-502: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix inverted JSPI check and typo in Firefox warning.

Line 499 currently warns about missing JSPI only when isSupportJSPI() is true, so guidance is inverted. Line 501 also still says “compat more”.

Proposed fix
-      } else if (isSupportJSPI()) {
+      } else if (!isSupportJSPI()) {
         this.logger().warn(
-          'WebGPU is disabled on Firefox due to missing JSPI support. Please consider enabling compat more, or enabling "javascript.options.wasm_js_promise_integration" in "about:config".'
+          'WebGPU is disabled on Firefox due to missing JSPI support. Please consider enabling compat mode, or enabling "javascript.options.wasm_js_promise_integration" in "about:config".'
         );
       }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/wllama.ts` around lines 499 - 502, The condition and message are
inverted: change the branch that logs the Firefox JSPI warning to trigger when
JSPI is NOT supported (use !isSupportJSPI()), and update the logger().warn text
in the block to fix the typo and clarify guidance (e.g., "WebGPU is disabled on
Firefox due to missing JSPI support. Please consider enabling compatibility
mode, or enable \"javascript.options.wasm_js_promise_integration\" in
about:config."). Ensure you modify the isSupportJSPI() check and the string
passed to logger().warn accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/main/vite.config.ts`:
- Around line 3-4: The build fails because vite.config.ts imports Node built-ins
(import { existsSync } from 'fs'; import { resolve } from 'path';) but
examples/main lacks Node type coverage; add "`@types/node`" to
examples/main/package.json devDependencies and update
examples/main/tsconfig.node.json to include Node types (e.g., add "types":
["node"] under "compilerOptions") so tsc can resolve fs/path typings for
vite.config.ts.

---

Duplicate comments:
In `@src/wllama.ts`:
- Around line 499-502: The condition and message are inverted: change the branch
that logs the Firefox JSPI warning to trigger when JSPI is NOT supported (use
!isSupportJSPI()), and update the logger().warn text in the block to fix the
typo and clarify guidance (e.g., "WebGPU is disabled on Firefox due to missing
JSPI support. Please consider enabling compatibility mode, or enable
\"javascript.options.wasm_js_promise_integration\" in about:config."). Ensure
you modify the isSupportJSPI() check and the string passed to logger().warn
accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c9068f8-e28c-42b1-a6f5-df502651f7e5

📥 Commits

Reviewing files that changed from the base of the PR and between b1a4296 and 955499f.

⛔ Files ignored due to path filters (1)
  • src/wasm/wllama.wasm is excluded by !**/*.wasm
📒 Files selected for processing (15)
  • CMakeLists.txt
  • compat/README.md
  • compat/index.js
  • compat/wasm/wllama.js
  • examples/basic/index.html
  • examples/main/src/config.ts
  • examples/main/src/vite-env.d.ts
  • examples/main/vite.config.ts
  • src/mjs.test.ts
  • src/wasm/wllama.js
  • src/wllama.test.ts
  • src/wllama.ts
  • src/wllama.wgpu.test.ts
  • src/worker.ts
  • src/workers-code/generated.ts
💤 Files with no reviewable changes (1)
  • compat/index.js
✅ Files skipped from review due to trivial changes (1)
  • compat/README.md

Comment thread examples/main/vite.config.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/main/vite.config.ts (1)

10-18: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize + JSON-encode Windows paths when embedding them into the virtual module import specifiers.

COMPAT_WASM / COMPAT_JS are built with Node resolve() and injected into the generated code as '${COMPAT_WASM}?url' / '${COMPAT_JS}?raw'. On Windows this can yield backslash-containing specifiers (including escape sequences like \n) and break the virtual module; use normalizePath and JSON.stringify when generating the import strings. (https://vite.dev/guide/api-plugin)

🪟 Suggested change
- import { defineConfig } from 'vite';
+ import { defineConfig, normalizePath } from 'vite';
@@
-const COMPAT_WASM = resolve(
+const COMPAT_WASM = normalizePath(resolve(
   __dirname,
   'node_modules/@wllama/wllama-compat/wasm/wllama.wasm'
-);
-const COMPAT_JS = resolve(
+));
+const COMPAT_JS = normalizePath(resolve(
   __dirname,
   'node_modules/@wllama/wllama-compat/wasm/wllama.js'
-);
+));
@@
-          return `
-import wasm from '${COMPAT_WASM}?url';
-import worker from '${COMPAT_JS}?raw';
+          return `
+import wasm from ${JSON.stringify(`${COMPAT_WASM}?url`)};
+import worker from ${JSON.stringify(`${COMPAT_JS}?raw`)};
 export default { wasm, worker: { code: worker } };
 `;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/main/vite.config.ts` around lines 10 - 18, When embedding
COMPAT_WASM and COMPAT_JS into the virtual module import specifiers, normalize
their paths and JSON-encode the resulting strings to avoid backslashes/escape
sequences on Windows; specifically, call normalizePath(resolve(...)) for
COMPAT_WASM and COMPAT_JS and then wrap the normalized string with
JSON.stringify before injecting as "'...'?url" / "'...'?raw" in the generated
code so the import specifiers are safe across platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 23: The "upload" npm script currently publishes the main package before
the companion "compat" package, risking the main release going live if the
compat publish fails; update the "upload" script so it runs the compat publish
first (ensure the "(cd compat && npm publish --access public)" step executes
before publishing the main package), keep the format and build steps intact, and
use && chaining so the main package publish only runs if the compat publish
succeeds; modify the "upload" script entry in package.json accordingly.

---

Outside diff comments:
In `@examples/main/vite.config.ts`:
- Around line 10-18: When embedding COMPAT_WASM and COMPAT_JS into the virtual
module import specifiers, normalize their paths and JSON-encode the resulting
strings to avoid backslashes/escape sequences on Windows; specifically, call
normalizePath(resolve(...)) for COMPAT_WASM and COMPAT_JS and then wrap the
normalized string with JSON.stringify before injecting as "'...'?url" /
"'...'?raw" in the generated code so the import specifiers are safe across
platforms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a7afe29b-5a60-4d6a-8d9a-a94bbfdc9fd0

📥 Commits

Reviewing files that changed from the base of the PR and between 955499f and 57fef54.

⛔ Files ignored due to path filters (2)
  • examples/main/package-lock.json is excluded by !**/package-lock.json
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • examples/main/package.json
  • examples/main/vite.config.ts
  • package.json
  • src/wllama.ts

Comment thread package.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
package.json (1)

23-23: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Publishing order issue remains unaddressed.

The main package is still published before the compat package. If the compat publish fails, @wllama/wllama@3.2.2 will already be live on npm with CDN URLs pointing to a non-existent @wllama/wllama-compat@3.2.2, breaking Safari compatibility for all users who install this version.

🔁 Apply the previously suggested fix
-    "upload": "npm run format && npm run build && npm publish --access public && (cd compat && npm publish --access public)",
+    "upload": "npm run format && npm run build && (cd compat && npm publish --access public) && npm publish --access public",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 23, The "upload" npm script currently publishes the
main package before the compat package; change the script so the compat package
is published first (run the compat publish step before publishing the main
package) and ensure the build/format steps still run before both publishes;
specifically update the "upload" script entry so it runs format and build, then
publishes the compat package (cd compat && npm publish --access public) and only
after that publishes the main package (npm publish --access public) to prevent
releasing the main package that references a missing compat release.
🧹 Nitpick comments (1)
scripts/generate_wasm_from_cdn.js (1)

7-19: 🏗️ Heavy lift

Version-sync concern is not a current blocker; consider guarding against future drift.

The generator’s use of the main packageJson.version for @wllama/wllama-compat URLs is consistent in this repo (compat and main versions both equal 3.2.2), so the generated CDN URLs should exist. Add a build-time check to fail fast if compat/package.json ever diverges from the main version.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/generate_wasm_from_cdn.js` around lines 7 - 19, Add a build-time
guard in scripts/generate_wasm_from_cdn.js that reads and compares the main
packageJson.version (variable "version") with the compat package version (read
from compat/package.json, call it "compatVersion"); if they differ, fail fast
(throw or process.exit with an error) and include both versions in the error
message, and then use "compatVersion" when constructing the WasmCompatFromCDN
URLs rather than reusing "version" so the generated CDN links reflect the actual
compat package version; place this check before building the outputContent
constant.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@package.json`:
- Line 23: The "upload" npm script currently publishes the main package before
the compat package; change the script so the compat package is published first
(run the compat publish step before publishing the main package) and ensure the
build/format steps still run before both publishes; specifically update the
"upload" script entry so it runs format and build, then publishes the compat
package (cd compat && npm publish --access public) and only after that publishes
the main package (npm publish --access public) to prevent releasing the main
package that references a missing compat release.

---

Nitpick comments:
In `@scripts/generate_wasm_from_cdn.js`:
- Around line 7-19: Add a build-time guard in scripts/generate_wasm_from_cdn.js
that reads and compares the main packageJson.version (variable "version") with
the compat package version (read from compat/package.json, call it
"compatVersion"); if they differ, fail fast (throw or process.exit with an
error) and include both versions in the error message, and then use
"compatVersion" when constructing the WasmCompatFromCDN URLs rather than reusing
"version" so the generated CDN links reflect the actual compat package version;
place this check before building the outputContent constant.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 634e7485-5c94-4559-a521-738063bf31a3

📥 Commits

Reviewing files that changed from the base of the PR and between 57fef54 and b031520.

📒 Files selected for processing (4)
  • compat/package.json
  • package.json
  • scripts/generate_wasm_from_cdn.js
  • src/wasm-from-cdn.ts
✅ Files skipped from review due to trivial changes (2)
  • src/wasm-from-cdn.ts
  • compat/package.json

@ngxson ngxson merged commit 2592cfe into master May 23, 2026
6 checks passed
@ngxson ngxson linked an issue Jun 1, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Call for contributors] Add guide for compiling Safari-compatible version

1 participant