wllama-service 2.0.1 → 2.0.3
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 +2 -1
- package/scripts/postinstall.js +29 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wllama-service",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Framework-agnostic browser LLM service wrapper with WebGPU and WebAssembly support",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
+
"postinstall": "node scripts/postinstall.js",
|
|
23
24
|
"build": "tsup",
|
|
24
25
|
"dev": "tsup --watch",
|
|
25
26
|
"typecheck": "tsc --noEmit",
|
package/scripts/postinstall.js
CHANGED
|
@@ -6,58 +6,48 @@ const path = require('path');
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Resolve @wllama/wllama's wasm file using Node's real module resolution
|
|
9
|
-
* instead of a
|
|
10
|
-
* yarn workspaces
|
|
11
|
-
* monorepo
|
|
12
|
-
*
|
|
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.
|
|
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.
|
|
15
13
|
*/
|
|
16
14
|
function resolveWasmSrc() {
|
|
17
|
-
const pkgJsonPath = require.resolve('@wllama/wllama/package.json'
|
|
15
|
+
const pkgJsonPath = require.resolve('@wllama/wllama/package.json', {
|
|
16
|
+
paths: [process.cwd()],
|
|
17
|
+
});
|
|
18
18
|
const pkgRoot = path.dirname(pkgJsonPath);
|
|
19
|
-
return path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm');
|
|
20
|
-
}
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* package.json + public/ pair.
|
|
26
|
-
*/
|
|
27
|
-
function findPublicDir() {
|
|
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)
|
|
28
23
|
const candidates = [
|
|
29
|
-
path.
|
|
30
|
-
path.
|
|
31
|
-
path.resolve(process.cwd(), '../../../public'),
|
|
32
|
-
path.resolve(process.cwd(), '../../../../public'),
|
|
24
|
+
path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm'),
|
|
25
|
+
path.join(pkgRoot, 'esm', 'single-thread', 'wllama.wasm'),
|
|
33
26
|
];
|
|
34
|
-
|
|
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
35
|
}
|
|
36
36
|
|
|
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');
|
|
41
|
+
|
|
37
42
|
let wasmSrc;
|
|
38
43
|
try {
|
|
39
44
|
wasmSrc = resolveWasmSrc();
|
|
40
45
|
} catch (err) {
|
|
41
|
-
console.warn('[wllama-
|
|
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
|
-
}
|
|
49
|
-
|
|
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
|
-
);
|
|
46
|
+
console.warn('[copy-wllama-wasm] ' + err.message);
|
|
57
47
|
process.exit(0);
|
|
58
48
|
}
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
51
|
+
const dest = path.join(destDir, 'wllama.wasm');
|
|
62
52
|
fs.copyFileSync(wasmSrc, dest);
|
|
63
|
-
console.log(`[wllama-
|
|
53
|
+
console.log(`[copy-wllama-wasm] ✓ Copied ${wasmSrc} -> ${dest}`);
|