@cfasim-ui/pyodide 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/pyodide",
3
- "version": "0.6.4",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "Pyodide (Python-in-browser) integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -20,8 +20,7 @@
20
20
  "./vite": "./src/vitePlugin.js"
21
21
  },
22
22
  "dependencies": {
23
- "pyodide": "^0.29.3",
24
- "@cfasim-ui/shared": "0.6.4"
23
+ "@cfasim-ui/shared": "0.7.1"
25
24
  },
26
25
  "peerDependencies": {
27
26
  "vue": "^3.5.0"
@@ -0,0 +1,23 @@
1
+ export interface RunMessage {
2
+ id: number;
3
+ type?: "run";
4
+ python: string;
5
+ context?: Record<string, unknown>;
6
+ }
7
+ export interface CallMessage {
8
+ id: number;
9
+ type: "call";
10
+ module: string;
11
+ fn: string;
12
+ kwargs?: Record<string, unknown>;
13
+ }
14
+ export interface LoadModuleMessage {
15
+ id: number;
16
+ type: "loadModule";
17
+ module: string;
18
+ }
19
+ export type WorkerMessage = RunMessage | CallMessage | LoadModuleMessage;
20
+ export type OutgoingMessage =
21
+ | Omit<RunMessage, "id">
22
+ | Omit<CallMessage, "id">
23
+ | Omit<LoadModuleMessage, "id">;
@@ -4,26 +4,7 @@ import {
4
4
  postErrorWithTransfer,
5
5
  } from "@cfasim-ui/shared/transfer";
6
6
  import type { ColumnDescriptor, ModelOutputsWire } from "@cfasim-ui/shared";
7
-
8
- interface RunMessage {
9
- id: number;
10
- type?: "run";
11
- python: string;
12
- context?: Record<string, unknown>;
13
- }
14
- interface CallMessage {
15
- id: number;
16
- type: "call";
17
- module: string;
18
- fn: string;
19
- kwargs?: Record<string, unknown>;
20
- }
21
- interface LoadModuleMessage {
22
- id: number;
23
- type: "loadModule";
24
- module: string;
25
- }
26
- type WorkerMessage = RunMessage | CallMessage | LoadModuleMessage;
7
+ import type { WorkerMessage } from "./messages.js";
27
8
 
28
9
  let wheelMap: Record<string, string> = {};
29
10
 
@@ -63,8 +44,8 @@ async function fetchPyodidePackages(): Promise<string[]> {
63
44
 
64
45
  const pyodideReadyPromise = (async () => {
65
46
  const [pyodideModule, packages] = await Promise.all([
66
- // @ts-expect-error - Pyodide types from CDN
67
47
  import(
48
+ // @ts-expect-error - Pyodide types from CDN
68
49
  /* @vite-ignore */ "https://cdn.jsdelivr.net/pyodide/v0.29.3/full/pyodide.mjs"
69
50
  ),
70
51
  fetchPyodidePackages(),
@@ -1,53 +1,18 @@
1
1
  import type { TransferableResponse } from "@cfasim-ui/shared";
2
- import { unwrapResponse } from "@cfasim-ui/shared";
2
+ import {
3
+ unwrapResponse,
4
+ describeWorkerError,
5
+ MESSAGEERROR_TEXT,
6
+ } from "@cfasim-ui/shared";
7
+ import type { WorkerMessage, OutgoingMessage } from "./messages.js";
3
8
 
4
9
  let lastId = 0;
5
10
  function getId(): number {
6
11
  return ++lastId;
7
12
  }
8
13
 
9
- interface RunMessage {
10
- id: number;
11
- type?: "run";
12
- python: string;
13
- context?: Record<string, unknown>;
14
- }
15
- interface CallMessage {
16
- id: number;
17
- type: "call";
18
- module: string;
19
- fn: string;
20
- kwargs?: Record<string, unknown>;
21
- }
22
- interface LoadModuleMessage {
23
- id: number;
24
- type: "loadModule";
25
- module: string;
26
- }
27
- type WorkerMessage = RunMessage | CallMessage | LoadModuleMessage;
28
- type OutgoingMessage =
29
- | Omit<RunMessage, "id">
30
- | Omit<CallMessage, "id">
31
- | Omit<LoadModuleMessage, "id">;
32
-
33
14
  export type PyodideResponse = { result?: unknown; error?: string };
34
15
 
35
- /**
36
- * Convert a worker `ErrorEvent` into a human-readable message. Cross-origin
37
- * worker failures sanitize the event so every field is null/empty (e.g. a
38
- * dynamic `import("https://cdn…")` that fails at module evaluation): in
39
- * that case we fall back to a hint about likely causes instead of an
40
- * empty string, which would otherwise surface as a blank error.
41
- */
42
- function describeWorkerError(e: ErrorEvent): string {
43
- const msg = e.message || e.error?.message || "";
44
- if (msg) {
45
- if (e.filename) return `${msg} (${e.filename}:${e.lineno})`;
46
- return msg;
47
- }
48
- 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)";
49
- }
50
-
51
16
  /**
52
17
  * Worker names are arbitrary string keys. Workers are spawned lazily on first
53
18
  * use; each one is an independent Pyodide interpreter. Use distinct names when
@@ -96,9 +61,7 @@ function getWorker(name: string): WorkerEntry {
96
61
  failAll(describeWorkerError(e));
97
62
  });
98
63
  worker.addEventListener("messageerror", () => {
99
- failAll(
100
- "Worker received a message it could not deserialize (messageerror)",
101
- );
64
+ failAll(MESSAGEERROR_TEXT);
102
65
  });
103
66
  entry = newEntry;
104
67
  workers.set(name, entry);