wllama-service 2.0.0 → 2.0.1

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.1",
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,63 @@
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 fixed relative path. This is the part that breaks in
10
+ * yarn workspaces monorepos: @wllama/wllama gets hoisted to the
11
+ * monorepo ROOT node_modules, not nested under wllama-service's own
12
+ * node_modules, so `__dirname + '../node_modules/@wllama/wllama/...'`
13
+ * never finds it. require.resolve walks up node_modules the same way
14
+ * Node itself would, so it finds the package wherever it actually is.
15
+ */
16
+ function resolveWasmSrc() {
17
+ const pkgJsonPath = require.resolve('@wllama/wllama/package.json');
18
+ const pkgRoot = path.dirname(pkgJsonPath);
19
+ return path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm');
20
+ }
15
21
 
16
- const destArg = process.env.WLLAMA_WASM_DEST || 'public/wllama';
17
- const destDir = path.resolve(process.cwd(), destArg);
22
+ /**
23
+ * Find the consuming app's public directory. Tries common monorepo
24
+ * layouts, then falls back to walking up from cwd looking for a
25
+ * package.json + public/ pair.
26
+ */
27
+ function findPublicDir() {
28
+ const candidates = [
29
+ path.resolve(process.cwd(), 'public'),
30
+ path.resolve(process.cwd(), '../../public'),
31
+ path.resolve(process.cwd(), '../../../public'),
32
+ path.resolve(process.cwd(), '../../../../public'),
33
+ ];
34
+ return candidates.find((p) => fs.existsSync(p));
35
+ }
18
36
 
19
- const result = copyWasm(destDir);
37
+ let wasmSrc;
38
+ try {
39
+ wasmSrc = resolveWasmSrc();
40
+ } catch (err) {
41
+ console.warn('[wllama-service] Could not resolve @wllama/wllama:', err.message);
42
+ process.exit(0);
43
+ }
44
+
45
+ if (!fs.existsSync(wasmSrc)) {
46
+ console.warn('[wllama-service] wllama.wasm not found at', wasmSrc);
47
+ process.exit(0);
48
+ }
20
49
 
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.
50
+ const publicDir = findPublicDir();
51
+ if (!publicDir) {
52
+ console.warn(
53
+ '[wllama-service] Could not find a public/ directory near',
54
+ process.cwd(),
55
+ '\n Set WLLAMA_PUBLIC_DIR env var to specify it explicitly.',
56
+ );
25
57
  process.exit(0);
26
- }
58
+ }
59
+
60
+ const dest = path.join(publicDir, 'wllama', 'wllama.wasm');
61
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
62
+ fs.copyFileSync(wasmSrc, dest);
63
+ console.log(`[wllama-service] ✓ Copied wllama.wasm to ${dest}`);