wllama-service 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wllama-service",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Framework-agnostic browser LLM service wrapper with WebGPU and WebAssembly support",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
@@ -1,26 +1,53 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ const fs = require('fs');
4
5
  const path = require('path');
5
- const { copyWasm } = require('./copyWllamaWasm');
6
6
 
7
- // This file is wired up as the "postinstall" script in the CONSUMING
8
- // APP's package.json (see setup below) npm runs it automatically
9
- // right after `npm install` finishes. No command to type, no step
10
- // to remember.
11
- //
12
- // Destination defaults to <app>/public/wllama, but can be overridden
13
- // with an env var if the app's public folder lives somewhere else:
14
- // WLLAMA_WASM_DEST=./static/wllama npm install
7
+ /**
8
+ * Resolve @wllama/wllama's wasm file using Node's real module resolution
9
+ * instead of a guessed relative path. This works correctly regardless of
10
+ * where in the yarn workspaces hoisting tree @wllama/wllama actually
11
+ * landed (monorepo root, nested under wllama-service, etc) — Node's own
12
+ * require.resolve algorithm finds it the same way `require()` would.
13
+ */
14
+ function resolveWasmSrc() {
15
+ const pkgJsonPath = require.resolve('@wllama/wllama/package.json', {
16
+ paths: [process.cwd()],
17
+ });
18
+ const pkgRoot = path.dirname(pkgJsonPath);
15
19
 
16
- const destArg = process.env.WLLAMA_WASM_DEST || 'public/wllama';
17
- const destDir = path.resolve(process.cwd(), destArg);
20
+ // Different @wllama/wllama versions ship different layouts:
21
+ // older: esm/wasm/wllama.wasm
22
+ // newer: esm/single-thread/wllama.wasm (+ esm/multi-thread/wllama.wasm)
23
+ const candidates = [
24
+ path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm'),
25
+ path.join(pkgRoot, 'esm', 'single-thread', 'wllama.wasm'),
26
+ ];
27
+ const found = candidates.find((p) => fs.existsSync(p));
28
+ if (!found) {
29
+ throw new Error(
30
+ `wllama.wasm not found in any known location under ${pkgRoot}\n` +
31
+ `Checked: ${candidates.join(', ')}`,
32
+ );
33
+ }
34
+ return found;
35
+ }
18
36
 
19
- const result = copyWasm(destDir);
37
+ // Destination: this app's own public folder. Adjust this path if your
38
+ // app's public folder lives somewhere other than apps/<this-app>/public
39
+ // relative to where this script sits.
40
+ const destDir = path.resolve(__dirname, '..', 'public', 'wllama');
20
41
 
21
- if (!result) {
22
- // Non-fatal: don't break `npm install` for the app if something's
23
- // off. Worst case, loadModel() fails clearly at runtime with a 404,
24
- // which is easier to debug than a broken install.
42
+ let wasmSrc;
43
+ try {
44
+ wasmSrc = resolveWasmSrc();
45
+ } catch (err) {
46
+ console.warn('[copy-wllama-wasm] ' + err.message);
25
47
  process.exit(0);
26
- }
48
+ }
49
+
50
+ fs.mkdirSync(destDir, { recursive: true });
51
+ const dest = path.join(destDir, 'wllama.wasm');
52
+ fs.copyFileSync(wasmSrc, dest);
53
+ console.log(`[copy-wllama-wasm] ✓ Copied ${wasmSrc} -> ${dest}`);