@cfasim-ui/wasm 0.6.4 → 0.7.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/wasm",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "WebAssembly integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "./vite": "./src/vitePlugin.js"
21
21
  },
22
22
  "dependencies": {
23
- "@cfasim-ui/shared": "0.6.4"
23
+ "@cfasim-ui/shared": "0.7.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vue": "^3.5.0"
@@ -0,0 +1,6 @@
1
+ export interface WorkerMessage {
2
+ id: number;
3
+ model: string;
4
+ fn: string;
5
+ args: string[];
6
+ }
@@ -3,13 +3,7 @@ import {
3
3
  postModelOutputsWithTransfer,
4
4
  postErrorWithTransfer,
5
5
  } from "@cfasim-ui/shared/transfer";
6
-
7
- interface WorkerMessage {
8
- id: number;
9
- model: string;
10
- fn: string;
11
- args: string[];
12
- }
6
+ import type { WorkerMessage } from "./messages.js";
13
7
 
14
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
9
  const modulePromises = new Map<string, Promise<Record<string, any>>>();
@@ -1,30 +1,13 @@
1
1
  import type { TransferableResponse } from "@cfasim-ui/shared";
2
- import { unwrapResponse } from "@cfasim-ui/shared";
3
-
4
- interface WorkerMessage {
5
- id: number;
6
- model: string;
7
- fn: string;
8
- args: string[];
9
- }
2
+ import {
3
+ unwrapResponse,
4
+ describeWorkerError,
5
+ MESSAGEERROR_TEXT,
6
+ } from "@cfasim-ui/shared";
7
+ import type { WorkerMessage } from "./messages.js";
10
8
 
11
9
  let lastId = 0;
12
10
 
13
- /**
14
- * Convert a worker `ErrorEvent` into a human-readable message. Cross-origin
15
- * worker failures sanitize the event so every field is null/empty (e.g.
16
- * the worker's module fails to evaluate); fall back to a hint rather than
17
- * an empty string.
18
- */
19
- function describeWorkerError(e: ErrorEvent): string {
20
- const msg = e.message || e.error?.message || "";
21
- if (msg) {
22
- if (e.filename) return `${msg} (${e.filename}:${e.lineno})`;
23
- return msg;
24
- }
25
- return "Worker failed to load (no error details available — most often a cross-origin script load failure or a syntax error in the worker module)";
26
- }
27
-
28
11
  // Rejects keyed by request id so `cancelWasm` can fail in-flight promises
29
12
  // when we terminate the worker mid-run, and so worker-level errors can drain
30
13
  // every pending call at once.
@@ -40,6 +23,7 @@ function newWorker(): Worker {
40
23
  type: "module",
41
24
  });
42
25
  function failAll(message: string) {
26
+ if (workerDeadError) return;
43
27
  workerDeadError = new Error(message);
44
28
  const rejects = Array.from(pendingRejects.values());
45
29
  pendingRejects.clear();
@@ -49,9 +33,7 @@ function newWorker(): Worker {
49
33
  failAll(describeWorkerError(e));
50
34
  });
51
35
  w.addEventListener("messageerror", () => {
52
- failAll(
53
- "Worker received a message it could not deserialize (messageerror)",
54
- );
36
+ failAll(MESSAGEERROR_TEXT);
55
37
  });
56
38
  return w;
57
39
  }