@cfasim-ui/pyodide 0.1.7 → 0.1.8

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.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "Pyodide (Python-in-browser) integration for cfasim-ui",
6
6
  "license": "Apache-2.0",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "pyodide": "^0.29.3",
24
- "@cfasim-ui/shared": "0.1.7"
24
+ "@cfasim-ui/shared": "0.1.8"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "vue": "^3.5.0"
@@ -122,6 +122,13 @@ function convertModelOutputs(jsResult: any): ModelOutputsWire | null {
122
122
  if ((buf as any).destroy) (buf as any).destroy();
123
123
  } else if (buf instanceof ArrayBuffer) {
124
124
  buffers.push(buf);
125
+ } else if (ArrayBuffer.isView(buf)) {
126
+ buffers.push(
127
+ buf.buffer.slice(
128
+ buf.byteOffset,
129
+ buf.byteOffset + buf.byteLength,
130
+ ) as ArrayBuffer,
131
+ );
125
132
  }
126
133
  }
127
134
 
package/src/useModel.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ref, toValue, watch } from "vue";
1
+ import { ref, toRaw, toValue, watch } from "vue";
2
2
  import type { MaybeRef } from "vue";
3
3
  import type { ModelOutput } from "@cfasim-ui/shared";
4
4
  import { asyncRunPython, loadModule } from "./pyodideWorkerApi.js";
@@ -20,9 +20,14 @@ export function useModel<T = unknown>(moduleName: string) {
20
20
  await loaded;
21
21
  const argNames = context ? Object.keys(context) : [];
22
22
  const callArgs = argNames.join(", ");
23
+ const plainContext = context
24
+ ? Object.fromEntries(
25
+ Object.entries(context).map(([k, v]) => [k, toRaw(v)]),
26
+ )
27
+ : undefined;
23
28
  const response = await asyncRunPython(
24
29
  `import ${moduleName}\n${moduleName}.${fn}(${callArgs})`,
25
- context,
30
+ plainContext,
26
31
  );
27
32
  if (response.error) {
28
33
  error.value = response.error;
@@ -51,11 +56,14 @@ export function useModel<T = unknown>(moduleName: string) {
51
56
  outputsError.value = undefined;
52
57
  try {
53
58
  await loaded;
54
- const argNames = Object.keys(p);
59
+ const plain = Object.fromEntries(
60
+ Object.entries(p).map(([k, v]) => [k, toRaw(v)]),
61
+ );
62
+ const argNames = Object.keys(plain);
55
63
  const callArgs = argNames.join(", ");
56
64
  const response = await asyncRunPython(
57
65
  `import ${moduleName}\n${moduleName}.${fn}(${callArgs})`,
58
- p,
66
+ plain,
59
67
  );
60
68
  if (response.error) {
61
69
  outputsError.value = response.error;