@metaharness/kernel 0.1.0 → 0.1.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/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -27
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/pkg/package.json +21 -0
- package/pkg/ruflo_kernel_wasm.d.ts +17 -0
- package/pkg/ruflo_kernel_wasm.js +218 -0
- package/pkg/ruflo_kernel_wasm_bg.wasm +0 -0
- package/pkg/ruflo_kernel_wasm_bg.wasm.d.ts +10 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,5 +14,22 @@ interface KernelBackend {
|
|
|
14
14
|
* Load the kernel. native > wasm > pure-JS. The JS backend is the floor, so
|
|
15
15
|
* this never rejects with a missing-module error. Cached.
|
|
16
16
|
*/
|
|
17
|
+
/** Test-only: clear the cached backend + recorded errors so a subsequent
|
|
18
|
+
* loadKernel() re-resolves (e.g. after changing METAHARNESS_KERNEL_BACKEND). */
|
|
19
|
+
export declare function _resetKernelCacheForTests(): void;
|
|
17
20
|
export declare function loadKernel(): Promise<KernelBackend>;
|
|
21
|
+
/**
|
|
22
|
+
* GH #20/#22: backend diagnostics for `doctor` and honest capability reporting.
|
|
23
|
+
* Returns the resolved backend, the requested backend (if any), and the reason
|
|
24
|
+
* each higher-tier backend was unavailable. Triggers resolution if needed.
|
|
25
|
+
*/
|
|
26
|
+
export interface KernelDiagnostics {
|
|
27
|
+
resolved: 'native' | 'wasm' | 'js';
|
|
28
|
+
requested: string | null;
|
|
29
|
+
reasons: {
|
|
30
|
+
native?: string;
|
|
31
|
+
wasm?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export declare function kernelDiagnostics(): Promise<KernelDiagnostics>;
|
|
18
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzG,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,aAAa;IACrB,UAAU,IAAI,UAAU,CAAC;IACzB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC7C,OAAO,IAAI,MAAM,CAAC;IAClB,OAAO,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;CACnC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzG,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,aAAa;IACrB,UAAU,IAAI,UAAU,CAAC;IACzB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC7C,OAAO,IAAI,MAAM,CAAC;IAClB,OAAO,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;CACnC;AAuHD;;;GAGG;AACH;gFACgF;AAChF,wBAAgB,yBAAyB,IAAI,IAAI,CAIhD;AAED,wBAAsB,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAwCzD;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAIpE"}
|
package/dist/index.js
CHANGED
|
@@ -10,19 +10,25 @@
|
|
|
10
10
|
// but js is the floor — the kernel is always loadable. (ADR-002a §fallback.)
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
let _cached = null;
|
|
13
|
+
// GH #20/#22: remember WHY a higher-tier backend was unavailable so `doctor`
|
|
14
|
+
// and a requested-but-missing backend can report the actual reason instead of
|
|
15
|
+
// silently using js.
|
|
16
|
+
const _backendErrors = {};
|
|
13
17
|
async function loadNative() {
|
|
18
|
+
const plat = `${process.platform}-${process.arch}`;
|
|
19
|
+
const map = {
|
|
20
|
+
'darwin-arm64': '@metaharness/kernel-darwin-arm64',
|
|
21
|
+
'darwin-x64': '@metaharness/kernel-darwin-x64',
|
|
22
|
+
'linux-x64': '@metaharness/kernel-linux-x64-gnu',
|
|
23
|
+
'linux-arm64': '@metaharness/kernel-linux-arm64-gnu',
|
|
24
|
+
'win32-x64': '@metaharness/kernel-win32-x64-msvc',
|
|
25
|
+
};
|
|
26
|
+
const pkg = map[plat];
|
|
27
|
+
if (!pkg) {
|
|
28
|
+
_backendErrors.native = `no native package mapping for platform "${plat}"`;
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
14
31
|
try {
|
|
15
|
-
const plat = `${process.platform}-${process.arch}`;
|
|
16
|
-
const map = {
|
|
17
|
-
'darwin-arm64': '@metaharness/kernel-darwin-arm64',
|
|
18
|
-
'darwin-x64': '@metaharness/kernel-darwin-x64',
|
|
19
|
-
'linux-x64': '@metaharness/kernel-linux-x64-gnu',
|
|
20
|
-
'linux-arm64': '@metaharness/kernel-linux-arm64-gnu',
|
|
21
|
-
'win32-x64': '@metaharness/kernel-win32-x64-msvc',
|
|
22
|
-
};
|
|
23
|
-
const pkg = map[plat];
|
|
24
|
-
if (!pkg)
|
|
25
|
-
return null;
|
|
26
32
|
const mod = await import(pkg);
|
|
27
33
|
return {
|
|
28
34
|
kernelInfo: () => mod.kernelInfo(),
|
|
@@ -31,27 +37,32 @@ async function loadNative() {
|
|
|
31
37
|
backend: 'native',
|
|
32
38
|
};
|
|
33
39
|
}
|
|
34
|
-
catch {
|
|
40
|
+
catch (e) {
|
|
41
|
+
_backendErrors.native = `optional dependency "${pkg}" not installed (${e.message})`;
|
|
35
42
|
return null;
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
async function loadWasm() {
|
|
39
46
|
try {
|
|
40
|
-
// @ts-ignore — generated by `wasm-pack build` into ../pkg
|
|
41
|
-
//
|
|
42
|
-
//
|
|
47
|
+
// @ts-ignore — generated by `wasm-pack build --target nodejs` into ../pkg/.
|
|
48
|
+
// The nodejs target is CommonJS and auto-initializes the wasm on require
|
|
49
|
+
// (no init() call). pkg/package.json carries {"type":"commonjs"} (GH #21)
|
|
50
|
+
// so this ESM module loads the CJS shim correctly; ESM interop puts the
|
|
51
|
+
// exports on `.default` (and, via cjs-module-lexer, as named exports too).
|
|
43
52
|
const mod = await import('../pkg/ruflo_kernel_wasm.js');
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
const api = typeof mod.kernelInfo === 'function' ? mod : (mod.default ?? mod);
|
|
54
|
+
if (typeof api.kernelInfo !== 'function') {
|
|
55
|
+
throw new Error('wasm shim loaded but kernelInfo() is missing');
|
|
46
56
|
}
|
|
47
57
|
return {
|
|
48
|
-
kernelInfo: () =>
|
|
49
|
-
mcpValidate: (s) =>
|
|
50
|
-
version: () =>
|
|
58
|
+
kernelInfo: () => api.kernelInfo(),
|
|
59
|
+
mcpValidate: (s) => api.mcpValidate(s) ?? null,
|
|
60
|
+
version: () => api.version(),
|
|
51
61
|
backend: 'wasm',
|
|
52
62
|
};
|
|
53
63
|
}
|
|
54
|
-
catch {
|
|
64
|
+
catch (e) {
|
|
65
|
+
_backendErrors.wasm = `wasm artifact (pkg/ruflo_kernel_wasm.js) not present in @metaharness/kernel (${e.message})`;
|
|
55
66
|
return null;
|
|
56
67
|
}
|
|
57
68
|
}
|
|
@@ -98,16 +109,19 @@ function loadJs() {
|
|
|
98
109
|
// Mirror the NAPI binding, which throws on unparseable spec JSON.
|
|
99
110
|
throw new Error(`invalid spec json: ${e.message}`);
|
|
100
111
|
}
|
|
101
|
-
// Rules, byte-for-byte from crates/kernel/src/mcp.rs::validate.
|
|
112
|
+
// Rules, byte-for-byte from crates/kernel/src/mcp.rs::validate. The real
|
|
113
|
+
// kernel surfaces these through `Error::Mcp(..)`, whose Display prefixes
|
|
114
|
+
// "mcp: " — so native + wasm return "mcp: <reason>". The js floor must
|
|
115
|
+
// match exactly (GH #20: drift surfaced once wasm became loadable).
|
|
102
116
|
if (typeof spec.name !== 'string' || spec.name.length === 0) {
|
|
103
|
-
return 'server name is empty';
|
|
117
|
+
return 'mcp: server name is empty';
|
|
104
118
|
}
|
|
105
119
|
const hasCommand = Array.isArray(spec.command) && spec.command.length > 0;
|
|
106
120
|
const hasUrl = typeof spec.url === 'string' && spec.url.length > 0;
|
|
107
121
|
if (hasCommand && hasUrl)
|
|
108
|
-
return 'command and url are mutually exclusive';
|
|
122
|
+
return 'mcp: command and url are mutually exclusive';
|
|
109
123
|
if (!hasCommand && !hasUrl)
|
|
110
|
-
return 'either command or url must be set';
|
|
124
|
+
return 'mcp: either command or url must be set';
|
|
111
125
|
return null;
|
|
112
126
|
},
|
|
113
127
|
backend: 'js',
|
|
@@ -117,11 +131,52 @@ function loadJs() {
|
|
|
117
131
|
* Load the kernel. native > wasm > pure-JS. The JS backend is the floor, so
|
|
118
132
|
* this never rejects with a missing-module error. Cached.
|
|
119
133
|
*/
|
|
134
|
+
/** Test-only: clear the cached backend + recorded errors so a subsequent
|
|
135
|
+
* loadKernel() re-resolves (e.g. after changing METAHARNESS_KERNEL_BACKEND). */
|
|
136
|
+
export function _resetKernelCacheForTests() {
|
|
137
|
+
_cached = null;
|
|
138
|
+
delete _backendErrors.native;
|
|
139
|
+
delete _backendErrors.wasm;
|
|
140
|
+
}
|
|
120
141
|
export async function loadKernel() {
|
|
121
142
|
if (_cached)
|
|
122
143
|
return _cached;
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
// GH #22: honor METAHARNESS_KERNEL_BACKEND=native|wasm|js. When a specific
|
|
145
|
+
// backend is requested but cannot load, FAIL LOUDLY with the reason instead
|
|
146
|
+
// of silently using js.
|
|
147
|
+
const requested = (process.env.METAHARNESS_KERNEL_BACKEND || '').trim().toLowerCase();
|
|
148
|
+
if (requested && !['native', 'wasm', 'js'].includes(requested)) {
|
|
149
|
+
throw new Error(`METAHARNESS_KERNEL_BACKEND="${requested}" is invalid; choose one of: native, wasm, js`);
|
|
150
|
+
}
|
|
151
|
+
if (requested === 'js') {
|
|
152
|
+
_cached = loadJs();
|
|
153
|
+
return _cached;
|
|
154
|
+
}
|
|
155
|
+
if (requested === 'native') {
|
|
156
|
+
const n = await loadNative();
|
|
157
|
+
if (!n) {
|
|
158
|
+
throw new Error(`kernel backend "native" was requested but is unavailable: ${_backendErrors.native ?? 'unknown reason'}. ` +
|
|
159
|
+
`Unset METAHARNESS_KERNEL_BACKEND to fall back to js.`);
|
|
160
|
+
}
|
|
161
|
+
_cached = n;
|
|
162
|
+
return _cached;
|
|
163
|
+
}
|
|
164
|
+
if (requested === 'wasm') {
|
|
165
|
+
const w = await loadWasm();
|
|
166
|
+
if (!w) {
|
|
167
|
+
throw new Error(`kernel backend "wasm" was requested but is unavailable: ${_backendErrors.wasm ?? 'unknown reason'}. ` +
|
|
168
|
+
`Unset METAHARNESS_KERNEL_BACKEND to fall back to js.`);
|
|
169
|
+
}
|
|
170
|
+
_cached = w;
|
|
171
|
+
return _cached;
|
|
172
|
+
}
|
|
173
|
+
// Auto: native > wasm > pure-JS (the floor).
|
|
174
|
+
_cached = (await loadNative()) ?? (await loadWasm()) ?? loadJs();
|
|
125
175
|
return _cached;
|
|
126
176
|
}
|
|
177
|
+
export async function kernelDiagnostics() {
|
|
178
|
+
const k = await loadKernel();
|
|
179
|
+
const requested = (process.env.METAHARNESS_KERNEL_BACKEND || '').trim().toLowerCase() || null;
|
|
180
|
+
return { resolved: k.backend, requested, reasons: { ..._backendErrors } };
|
|
181
|
+
}
|
|
127
182
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,+EAA+E;AAC/E,6EAA6E;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAiB5C,IAAI,OAAO,GAAyB,IAAI,CAAC;AAEzC,KAAK,UAAU,UAAU;IACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,+EAA+E;AAC/E,6EAA6E;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAiB5C,IAAI,OAAO,GAAyB,IAAI,CAAC;AAEzC,6EAA6E;AAC7E,8EAA8E;AAC9E,qBAAqB;AACrB,MAAM,cAAc,GAAuC,EAAE,CAAC;AAE9D,KAAK,UAAU,UAAU;IACvB,MAAM,IAAI,GAAG,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IACnD,MAAM,GAAG,GAA2B;QAClC,cAAc,EAAE,kCAAkC;QAClD,YAAY,EAAE,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AAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC;IAC9F,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;AAC5E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metaharness/kernel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Cross-platform kernel for the agent-harness-generator — wasm primary, NAPI-RS native fallback",
|
|
5
5
|
"homepage": "https://github.com/ruvnet/agent-harness-generator",
|
|
6
6
|
"repository": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc",
|
|
42
42
|
"test": "vitest run",
|
|
43
|
-
"lint": "tsc --noEmit"
|
|
43
|
+
"lint": "tsc --noEmit",
|
|
44
|
+
"build:wasm": "RUSTFLAGS= wasm-pack build ../../crates/kernel-wasm --target nodejs --release --out-dir ../../packages/kernel-js/pkg && rm -f pkg/.gitignore && node -e \"const f=require('fs');const j=require('./pkg/package.json');j.type='commonjs';f.writeFileSync('./pkg/package.json',JSON.stringify(j,null,2)+'\\n')\""
|
|
44
45
|
},
|
|
45
46
|
"keywords": [
|
|
46
47
|
"agent-harness",
|
package/pkg/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ruflo-kernel-wasm",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"rUv <ruv@ruv.net>"
|
|
5
|
+
],
|
|
6
|
+
"description": "WebAssembly bindings for ruflo-kernel",
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ruvnet/agent-harness-generator"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"ruflo_kernel_wasm_bg.wasm",
|
|
15
|
+
"ruflo_kernel_wasm.js",
|
|
16
|
+
"ruflo_kernel_wasm.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"main": "ruflo_kernel_wasm.js",
|
|
19
|
+
"types": "ruflo_kernel_wasm.d.ts",
|
|
20
|
+
"type": "commonjs"
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return kernel build metadata as a JS object.
|
|
6
|
+
*/
|
|
7
|
+
export function kernelInfo(): any;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Validate an MCP server spec (returns `null` on success, error string otherwise).
|
|
11
|
+
*/
|
|
12
|
+
export function mcpValidate(spec_json: string): any;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns the package version.
|
|
16
|
+
*/
|
|
17
|
+
export function version(): string;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* @ts-self-types="./ruflo_kernel_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return kernel build metadata as a JS object.
|
|
5
|
+
* @returns {any}
|
|
6
|
+
*/
|
|
7
|
+
function kernelInfo() {
|
|
8
|
+
try {
|
|
9
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
10
|
+
wasm.kernelInfo(retptr);
|
|
11
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
12
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
13
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
14
|
+
if (r2) {
|
|
15
|
+
throw takeObject(r1);
|
|
16
|
+
}
|
|
17
|
+
return takeObject(r0);
|
|
18
|
+
} finally {
|
|
19
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.kernelInfo = kernelInfo;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Validate an MCP server spec (returns `null` on success, error string otherwise).
|
|
26
|
+
* @param {string} spec_json
|
|
27
|
+
* @returns {any}
|
|
28
|
+
*/
|
|
29
|
+
function mcpValidate(spec_json) {
|
|
30
|
+
try {
|
|
31
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
32
|
+
const ptr0 = passStringToWasm0(spec_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
33
|
+
const len0 = WASM_VECTOR_LEN;
|
|
34
|
+
wasm.mcpValidate(retptr, ptr0, len0);
|
|
35
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
36
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
37
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
38
|
+
if (r2) {
|
|
39
|
+
throw takeObject(r1);
|
|
40
|
+
}
|
|
41
|
+
return takeObject(r0);
|
|
42
|
+
} finally {
|
|
43
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.mcpValidate = mcpValidate;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the package version.
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
function version() {
|
|
53
|
+
let deferred1_0;
|
|
54
|
+
let deferred1_1;
|
|
55
|
+
try {
|
|
56
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
57
|
+
wasm.version(retptr);
|
|
58
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
59
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
60
|
+
deferred1_0 = r0;
|
|
61
|
+
deferred1_1 = r1;
|
|
62
|
+
return getStringFromWasm0(r0, r1);
|
|
63
|
+
} finally {
|
|
64
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
65
|
+
wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.version = version;
|
|
69
|
+
function __wbg_get_imports() {
|
|
70
|
+
const import0 = {
|
|
71
|
+
__proto__: null,
|
|
72
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
73
|
+
const ret = String(getObject(arg1));
|
|
74
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
75
|
+
const len1 = WASM_VECTOR_LEN;
|
|
76
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
77
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
78
|
+
},
|
|
79
|
+
__wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
|
|
80
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
81
|
+
},
|
|
82
|
+
__wbg_new_2e117a478906f062: function() {
|
|
83
|
+
const ret = new Object();
|
|
84
|
+
return addHeapObject(ret);
|
|
85
|
+
},
|
|
86
|
+
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
87
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
88
|
+
},
|
|
89
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
90
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
91
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
92
|
+
return addHeapObject(ret);
|
|
93
|
+
},
|
|
94
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
95
|
+
const ret = getObject(arg0);
|
|
96
|
+
return addHeapObject(ret);
|
|
97
|
+
},
|
|
98
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
99
|
+
takeObject(arg0);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
__proto__: null,
|
|
104
|
+
"./ruflo_kernel_wasm_bg.js": import0,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function addHeapObject(obj) {
|
|
109
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
110
|
+
const idx = heap_next;
|
|
111
|
+
heap_next = heap[idx];
|
|
112
|
+
|
|
113
|
+
heap[idx] = obj;
|
|
114
|
+
return idx;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function dropObject(idx) {
|
|
118
|
+
if (idx < 1028) return;
|
|
119
|
+
heap[idx] = heap_next;
|
|
120
|
+
heap_next = idx;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let cachedDataViewMemory0 = null;
|
|
124
|
+
function getDataViewMemory0() {
|
|
125
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
126
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
127
|
+
}
|
|
128
|
+
return cachedDataViewMemory0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getStringFromWasm0(ptr, len) {
|
|
132
|
+
return decodeText(ptr >>> 0, len);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let cachedUint8ArrayMemory0 = null;
|
|
136
|
+
function getUint8ArrayMemory0() {
|
|
137
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
138
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
139
|
+
}
|
|
140
|
+
return cachedUint8ArrayMemory0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getObject(idx) { return heap[idx]; }
|
|
144
|
+
|
|
145
|
+
let heap = new Array(1024).fill(undefined);
|
|
146
|
+
heap.push(undefined, null, true, false);
|
|
147
|
+
|
|
148
|
+
let heap_next = heap.length;
|
|
149
|
+
|
|
150
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
151
|
+
if (realloc === undefined) {
|
|
152
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
153
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
154
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
155
|
+
WASM_VECTOR_LEN = buf.length;
|
|
156
|
+
return ptr;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let len = arg.length;
|
|
160
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
161
|
+
|
|
162
|
+
const mem = getUint8ArrayMemory0();
|
|
163
|
+
|
|
164
|
+
let offset = 0;
|
|
165
|
+
|
|
166
|
+
for (; offset < len; offset++) {
|
|
167
|
+
const code = arg.charCodeAt(offset);
|
|
168
|
+
if (code > 0x7F) break;
|
|
169
|
+
mem[ptr + offset] = code;
|
|
170
|
+
}
|
|
171
|
+
if (offset !== len) {
|
|
172
|
+
if (offset !== 0) {
|
|
173
|
+
arg = arg.slice(offset);
|
|
174
|
+
}
|
|
175
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
176
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
177
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
178
|
+
|
|
179
|
+
offset += ret.written;
|
|
180
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
WASM_VECTOR_LEN = offset;
|
|
184
|
+
return ptr;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function takeObject(idx) {
|
|
188
|
+
const ret = getObject(idx);
|
|
189
|
+
dropObject(idx);
|
|
190
|
+
return ret;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
194
|
+
cachedTextDecoder.decode();
|
|
195
|
+
function decodeText(ptr, len) {
|
|
196
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const cachedTextEncoder = new TextEncoder();
|
|
200
|
+
|
|
201
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
202
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
203
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
204
|
+
view.set(buf);
|
|
205
|
+
return {
|
|
206
|
+
read: arg.length,
|
|
207
|
+
written: buf.length
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let WASM_VECTOR_LEN = 0;
|
|
213
|
+
|
|
214
|
+
const wasmPath = `${__dirname}/ruflo_kernel_wasm_bg.wasm`;
|
|
215
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
216
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
217
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
218
|
+
let wasm = wasmInstance.exports;
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const kernelInfo: (a: number) => void;
|
|
5
|
+
export const mcpValidate: (a: number, b: number, c: number) => void;
|
|
6
|
+
export const version: (a: number) => void;
|
|
7
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
8
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
9
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
10
|
+
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|