@tensor-cad/engine 0.1.1 → 0.1.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/node.d.ts +15 -2
- package/node.js +13 -5
- package/package.json +1 -1
- package/tensorcad.wasm +0 -0
package/node.d.ts
CHANGED
|
@@ -6,15 +6,28 @@
|
|
|
6
6
|
* singleton the way the editor does: one engine per process, loaded before the
|
|
7
7
|
* first command runs.
|
|
8
8
|
*/
|
|
9
|
-
import { type Engine } from "./index.js";
|
|
9
|
+
import { type Engine, type LoadOptions } from "./index.js";
|
|
10
10
|
import "../vendor/wasm_exec.js";
|
|
11
11
|
/**
|
|
12
12
|
* Loads the engine, once per process.
|
|
13
13
|
*
|
|
14
14
|
* A missing module is the one failure worth naming precisely: it means the
|
|
15
15
|
* repository was cloned but not built, and the fix is one command.
|
|
16
|
+
*
|
|
17
|
+
* ## Being handed the module instead of finding it
|
|
18
|
+
*
|
|
19
|
+
* `options.wasm` skips the search. That is not a convenience — it is the only
|
|
20
|
+
* way this entry point works in a Worker, where there is no filesystem to read
|
|
21
|
+
* and the module arrives already compiled from the bundler.
|
|
22
|
+
*
|
|
23
|
+
* It matters because of what else lives here: the free functions below share
|
|
24
|
+
* *this* singleton, and the MCP tools are written against them. A host that
|
|
25
|
+
* loaded its own engine through `createEngine` would have two, and the tools
|
|
26
|
+
* would find the one nobody filled — "the engine is not loaded yet", moments
|
|
27
|
+
* after loading it. So a host with its own module gives it to this loader
|
|
28
|
+
* rather than keeping it.
|
|
16
29
|
*/
|
|
17
|
-
export declare function loadEngine(): Promise<Engine>;
|
|
30
|
+
export declare function loadEngine(options?: LoadOptions): Promise<Engine>;
|
|
18
31
|
/** The engine. Throws if something asked before the load finished. */
|
|
19
32
|
export declare function engine(): Engine;
|
|
20
33
|
export * from "./index.js";
|
package/node.js
CHANGED
|
@@ -1371,9 +1371,14 @@ function modulePaths() {
|
|
|
1371
1371
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
1372
1372
|
return [join(here, "tensorcad.wasm"), join(here, "..", "wasm", "tensorcad.wasm")];
|
|
1373
1373
|
}
|
|
1374
|
-
async function loadEngine() {
|
|
1374
|
+
async function loadEngine(options) {
|
|
1375
1375
|
if (loaded)
|
|
1376
1376
|
return loaded;
|
|
1377
|
+
if (options?.wasm !== undefined) {
|
|
1378
|
+
loaded = await createEngine(options);
|
|
1379
|
+
publish(loaded);
|
|
1380
|
+
return loaded;
|
|
1381
|
+
}
|
|
1377
1382
|
const paths = modulePaths();
|
|
1378
1383
|
let bytes = null;
|
|
1379
1384
|
for (const path of paths) {
|
|
@@ -1387,12 +1392,15 @@ async function loadEngine() {
|
|
|
1387
1392
|
throw new EngineError(`The analysis engine is not built (looked in ${paths.join(" and ")}). Run: bun run build:wasm`);
|
|
1388
1393
|
}
|
|
1389
1394
|
loaded = await createEngine({ wasm: bytes });
|
|
1390
|
-
|
|
1391
|
-
HARDWARE.push(...loaded.hardware());
|
|
1392
|
-
for (const entry of loaded.blocks.builtInEntries)
|
|
1393
|
-
CATALOG[entry.type] = entry;
|
|
1395
|
+
publish(loaded);
|
|
1394
1396
|
return loaded;
|
|
1395
1397
|
}
|
|
1398
|
+
function publish(engine) {
|
|
1399
|
+
PRESET_NAMES.push(...engine.presets());
|
|
1400
|
+
HARDWARE.push(...engine.hardware());
|
|
1401
|
+
for (const entry of engine.blocks.builtInEntries)
|
|
1402
|
+
CATALOG[entry.type] = entry;
|
|
1403
|
+
}
|
|
1396
1404
|
function engine() {
|
|
1397
1405
|
if (!loaded)
|
|
1398
1406
|
throw new EngineError("The engine is not loaded yet; await loadEngine() first.");
|
package/package.json
CHANGED
package/tensorcad.wasm
CHANGED
|
Binary file
|