@nodetool-ai/kernels 0.0.0-bootstrap.0 → 0.8.14
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/README.md +44 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/backend.d.ts +34 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +9 -0
- package/dist/backend.js.map +1 -0
- package/dist/generated/kernels-wasm.d.ts +3 -0
- package/dist/generated/kernels-wasm.d.ts.map +1 -0
- package/dist/generated/kernels-wasm.js +887 -0
- package/dist/generated/kernels-wasm.js.map +1 -0
- package/dist/index.d.ts +254 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +605 -0
- package/dist/index.js.map +1 -0
- package/dist/wasm.d.ts +10 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +101 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +48 -3
package/dist/wasm.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebAssembly backend: instantiates the embedded module and runs a kernel
|
|
3
|
+
* call by copying each buffer argument into the module's linear memory.
|
|
4
|
+
*/
|
|
5
|
+
import type { KernelBackend } from "./backend.js";
|
|
6
|
+
/** Decodes standard base64, without depending on atob or Buffer. */
|
|
7
|
+
export declare function decodeBase64(text: string): Uint8Array<ArrayBuffer>;
|
|
8
|
+
/** Instantiates the kernel module from its bytes. */
|
|
9
|
+
export declare function instantiateWasmKernels(bytes: Uint8Array<ArrayBuffer>): Promise<KernelBackend>;
|
|
10
|
+
//# sourceMappingURL=wasm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAa,aAAa,EAAE,MAAM,cAAc,CAAC;AA+B7D,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAiBlE;AAMD,qDAAqD;AACrD,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAC7B,OAAO,CAAC,aAAa,CAAC,CAoDxB"}
|
package/dist/wasm.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** errno ENOSYS: the module's abort path may try to print, and cannot. */
|
|
2
|
+
const ENOSYS = 52;
|
|
3
|
+
/**
|
|
4
|
+
* The imports the standalone module declares. They serve only libc++'s abort
|
|
5
|
+
* path, which a kernel never takes for valid arguments.
|
|
6
|
+
*/
|
|
7
|
+
const IMPORTS = {
|
|
8
|
+
env: {
|
|
9
|
+
emscripten_notify_memory_growth: () => undefined
|
|
10
|
+
},
|
|
11
|
+
wasi_snapshot_preview1: {
|
|
12
|
+
fd_close: () => ENOSYS,
|
|
13
|
+
fd_write: () => ENOSYS,
|
|
14
|
+
fd_seek: () => ENOSYS
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
18
|
+
/** Decodes standard base64, without depending on atob or Buffer. */
|
|
19
|
+
export function decodeBase64(text) {
|
|
20
|
+
const table = new Uint8Array(128);
|
|
21
|
+
for (let i = 0; i < BASE64.length; i++)
|
|
22
|
+
table[BASE64.charCodeAt(i)] = i;
|
|
23
|
+
const clean = text.replace(/=+$/, "");
|
|
24
|
+
const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
|
|
25
|
+
let bits = 0;
|
|
26
|
+
let value = 0;
|
|
27
|
+
let o = 0;
|
|
28
|
+
for (let i = 0; i < clean.length; i++) {
|
|
29
|
+
value = (value << 6) | table[clean.charCodeAt(i)];
|
|
30
|
+
bits += 6;
|
|
31
|
+
if (bits >= 8) {
|
|
32
|
+
bits -= 8;
|
|
33
|
+
out[o++] = (value >> bits) & 0xff;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function bytesOf(array) {
|
|
39
|
+
return new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
40
|
+
}
|
|
41
|
+
/** Instantiates the kernel module from its bytes. */
|
|
42
|
+
export async function instantiateWasmKernels(bytes) {
|
|
43
|
+
const module = await WebAssembly.compile(bytes);
|
|
44
|
+
const instance = await WebAssembly.instantiate(module, IMPORTS);
|
|
45
|
+
const exports = instance.exports;
|
|
46
|
+
exports._initialize?.();
|
|
47
|
+
return {
|
|
48
|
+
kind: "wasm",
|
|
49
|
+
call(name, args) {
|
|
50
|
+
const fn = exports[name];
|
|
51
|
+
if (typeof fn !== "function") {
|
|
52
|
+
throw new Error(`The kernel module has no function ${name}`);
|
|
53
|
+
}
|
|
54
|
+
const allocations = [];
|
|
55
|
+
try {
|
|
56
|
+
const params = [];
|
|
57
|
+
const buffers = [];
|
|
58
|
+
for (const arg of args) {
|
|
59
|
+
if (typeof arg === "number") {
|
|
60
|
+
params.push(arg);
|
|
61
|
+
}
|
|
62
|
+
else if (arg === null) {
|
|
63
|
+
params.push(0);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const array = "in" in arg ? arg.in : "out" in arg ? arg.out : arg.inout;
|
|
67
|
+
const ptr = exports.malloc(Math.max(1, array.byteLength));
|
|
68
|
+
if (ptr === 0) {
|
|
69
|
+
throw new Error(`The kernel module is out of memory (${array.byteLength} bytes)`);
|
|
70
|
+
}
|
|
71
|
+
allocations.push(ptr);
|
|
72
|
+
params.push(ptr);
|
|
73
|
+
buffers.push({ ptr, arg });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// malloc may grow the memory, which replaces its buffer, so the
|
|
77
|
+
// view is taken after the last allocation.
|
|
78
|
+
const heap = new Uint8Array(exports.memory.buffer);
|
|
79
|
+
for (const { ptr, arg } of buffers) {
|
|
80
|
+
if ("in" in arg)
|
|
81
|
+
heap.set(bytesOf(arg.in), ptr);
|
|
82
|
+
else if ("inout" in arg)
|
|
83
|
+
heap.set(bytesOf(arg.inout), ptr);
|
|
84
|
+
}
|
|
85
|
+
const result = fn(...params);
|
|
86
|
+
const after = new Uint8Array(exports.memory.buffer);
|
|
87
|
+
for (const { ptr, arg } of buffers) {
|
|
88
|
+
const target = "out" in arg ? arg.out : "inout" in arg ? arg.inout : null;
|
|
89
|
+
if (target)
|
|
90
|
+
bytesOf(target).set(after.subarray(ptr, ptr + target.byteLength));
|
|
91
|
+
}
|
|
92
|
+
return result ?? 0;
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
for (const ptr of allocations)
|
|
96
|
+
exports.free(ptr);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=wasm.js.map
|
package/dist/wasm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAcA,0EAA0E;AAC1E,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB;;;GAGG;AACH,MAAM,OAAO,GAAwB;IACnC,GAAG,EAAE;QACH,+BAA+B,EAAE,GAAG,EAAE,CAAC,SAAS;KACjD;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM;KACtB;CACF,CAAC;AAEF,MAAM,MAAM,GACV,kEAAkE,CAAC;AAErE,oEAAoE;AACpE,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,MAAM,CAA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AC;gBACT,KAAK,MAAM,GAAG,IAAI,WAAW;oBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodetool-ai/kernels",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.14",
|
|
4
|
+
"description": "The NodeTool C++ kernel library (native/kernels) as WebAssembly, with a typed API for batch and streaming nodes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.0.0"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "node ../../scripts/build-typescript-workspace.mjs",
|
|
13
|
+
"test": "node ../../scripts/run-vitest.mjs run",
|
|
14
|
+
"test:watch": "node ../../scripts/run-vitest.mjs",
|
|
15
|
+
"lint": "node ../../scripts/run-tsc.mjs --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.0.0",
|
|
19
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
20
|
+
"vitest": "^5.0.1"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"nodetool-dev": "./src/index.ts",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
5
30
|
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/nodetool-ai/nodetool.git",
|
|
34
|
+
"directory": "packages/kernels"
|
|
35
|
+
},
|
|
6
36
|
"publishConfig": {
|
|
7
37
|
"access": "public"
|
|
8
|
-
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"homepage": "https://nodetool.ai",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/nodetool-ai/nodetool/issues"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"nodetool",
|
|
49
|
+
"dsp",
|
|
50
|
+
"webassembly",
|
|
51
|
+
"image-processing",
|
|
52
|
+
"audio"
|
|
53
|
+
]
|
|
9
54
|
}
|