libfx 0.0.7 → 0.0.8-dev.820.g1d9d3b63d6ea
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 +240 -275
- package/browser.js +2 -1
- package/core-output.js +58 -0
- package/fx-core.wasm +0 -0
- package/fx-sdk.js +658 -208
- package/fx-term.wasm +0 -0
- package/libfx.darwin-arm64.node +0 -0
- package/libfx.darwin-x64.node +0 -0
- package/libfx.linux-arm64.node +0 -0
- package/libfx.linux-x64.node +0 -0
- package/mcp.js +118 -0
- package/node.cjs +2542 -0
- package/node.js +331 -88
- package/package.json +13 -4
- package/skills-node.js +29 -0
- package/skills.js +44 -0
- package/wasm-module.js +50 -0
package/wasm-module.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const modulePromisesBySource = new Map();
|
|
2
|
+
const modulePromisesByObject = new WeakMap();
|
|
3
|
+
const moduleFailureSource = Symbol("libfx.moduleFailureSource");
|
|
4
|
+
|
|
5
|
+
export function withModuleFailure(input, onFailure) {
|
|
6
|
+
return { [moduleFailureSource]: { input, onFailure } };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function compileModule(input) {
|
|
10
|
+
const failureSource = input?.[moduleFailureSource];
|
|
11
|
+
if (failureSource) {
|
|
12
|
+
try {
|
|
13
|
+
return await compileModule(failureSource.input);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
failureSource.onFailure();
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (input instanceof WebAssembly.Module) return input;
|
|
20
|
+
if (typeof input === "string") input = fetch(input);
|
|
21
|
+
if (input instanceof Promise) input = await input;
|
|
22
|
+
if (input instanceof WebAssembly.Module) return input;
|
|
23
|
+
if (input instanceof Response) {
|
|
24
|
+
const contentType = input.headers.get("content-type")?.split(";", 1)[0].trim().toLowerCase();
|
|
25
|
+
if (contentType === "application/wasm" && typeof WebAssembly.compileStreaming === "function") {
|
|
26
|
+
return WebAssembly.compileStreaming(input);
|
|
27
|
+
}
|
|
28
|
+
const bytes = await input.arrayBuffer();
|
|
29
|
+
return WebAssembly.compile(bytes);
|
|
30
|
+
}
|
|
31
|
+
if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {
|
|
32
|
+
return WebAssembly.compile(input);
|
|
33
|
+
}
|
|
34
|
+
throw new TypeError("wasm must be a URL, Response, ArrayBuffer, typed array, or WebAssembly.Module");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function loadModule(input) {
|
|
38
|
+
if (input instanceof WebAssembly.Module) return Promise.resolve(input);
|
|
39
|
+
const isString = typeof input === "string";
|
|
40
|
+
if (!isString && (typeof input !== "object" || input === null)) return compileModule(input);
|
|
41
|
+
const cache = isString ? modulePromisesBySource : modulePromisesByObject;
|
|
42
|
+
const cached = cache.get(input);
|
|
43
|
+
if (cached) return cached;
|
|
44
|
+
const pending = compileModule(input);
|
|
45
|
+
cache.set(input, pending);
|
|
46
|
+
pending.catch(() => {
|
|
47
|
+
if (cache.get(input) === pending) cache.delete(input);
|
|
48
|
+
});
|
|
49
|
+
return pending;
|
|
50
|
+
}
|