@remix_labs/machine-starter 2.13056.0-dev → 2.13058.0-dev

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/common.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ // Types for @remix_labs/machine-starter: starts groovebox VMs in web workers.
2
+ import type { Channel } from "@remix_labs/hub-client";
3
+
4
+ type Hub = { newChannel(clientName?: string): Promise<Channel> };
5
+
6
+ export type StartConfig = {
7
+ vmID: string;
8
+ baseURL?: string;
9
+ org?: string;
10
+ workspace?: string;
11
+ topicPrefix?: string;
12
+ user?: string;
13
+ token?: string;
14
+ noOutputViaMQTT?: boolean;
15
+ machType?: string;
16
+ localFFIs?: Record<string, any>;
17
+ mixcore?: any;
18
+ // base64 string, Uint8Array, or a URL (http, https, data, remix://)
19
+ mixrtCode?: any;
20
+ interceptFFI?: any;
21
+ interceptDynloadFFI?: any;
22
+ [key: string]: any;
23
+ };
24
+
25
+ export function StartWASM2(hub: Hub, config: StartConfig, getWorker: () => Worker | Promise<Worker>): Promise<Worker>;
26
+ export function StartWASM(
27
+ hub: Hub,
28
+ baseURL: string,
29
+ org: string,
30
+ workspace: string,
31
+ vmID: string,
32
+ user: string,
33
+ token: string,
34
+ noOutputViaMQTT: boolean,
35
+ getWorker: () => Worker | Promise<Worker>,
36
+ ): Promise<Worker>;
37
+ export function terminateVM(vmID: string): Promise<void>;
38
+ export const Token: any;
39
+ export const Case: any;
40
+ export const Opaque: any;
package/common.js CHANGED
@@ -77,14 +77,9 @@ async function terminateVM(vmID) {
77
77
  let topic = worker_topics[vmID];
78
78
  let payload = { _rmx_type:"msg_vm_register", id: vmID, alive: false };
79
79
  let msg = channel.newJSONMessage("msg_vm_register", "vm", payload);
80
- try {
81
- await channel.publish(topic + "/announce", msg, true);
82
- // NB. This msg is a leak - it will never be removed.
83
- await channel.disconnect("vm_" + vmID);
84
- } finally {
85
- // this channel is only used here: release the hub's end of it
86
- closeChannel(channel);
87
- }
80
+ await channel.publish(topic + "/announce", msg, true);
81
+ // NB. This msg is a leak - it will never be removed.
82
+ await channel.disconnect("vm_" + vmID);
88
83
  // now the VM is isolated and cannot communicate with the
89
84
  // hub anymore
90
85
  let worker = workers[vmID];
@@ -123,16 +118,6 @@ async function terminateVM(vmID) {
123
118
  }
124
119
  }
125
120
 
126
- // A hub channel has no explicit close: drop its MessagePort so the hub worker can release it.
127
- function closeChannel(channel) {
128
- try {
129
- if (typeof channel.close === "function") channel.close();
130
- else channel.port && channel.port.close && channel.port.close();
131
- // a message sent just before close() may not arrive: ask via the hub itself as well
132
- if (last_hub && last_hub.closeChannelById) last_hub.closeChannelById(channel.chanId);
133
- } catch (_) {}
134
- }
135
-
136
121
  if (globalThis.Process) {
137
122
  Process.on("exit", () => {
138
123
  terminateAllOnExit()
@@ -290,7 +275,6 @@ async function ffi_vm_start(conn, args, getWorker) {
290
275
  let vmChildren = children[conn.config.vmID];
291
276
  if (!vmChildren) vmChildren = [];
292
277
  vmChildren.push(vm_id);
293
- children[conn.config.vmID] = vmChildren; // was never stored: embedded VMs were not stopped with their parent
294
278
  let arg_config = args[0];
295
279
  if (arg_config.interceptFFI !== undefined)
296
280
  config["interceptFFI"] = arg_config.interceptFFI;
@@ -304,10 +288,6 @@ async function ffi_vm_stop(conn, args) {
304
288
  let vm_id = args[0];
305
289
  let worker = workers[vm_id];
306
290
  if (!worker) throw new Error("no such VM: " + vm_id);
307
- for (let parent of Object.keys(children)) {
308
- let i = children[parent].indexOf(vm_id);
309
- if (i >= 0) children[parent].splice(i, 1);
310
- }
311
291
  terminateVM(vm_id);
312
292
  return null;
313
293
  }
@@ -450,10 +430,6 @@ async function starterFFIsMessageLoop(hub, config, starterFFIs, terminate) {
450
430
  ]);
451
431
  if (terminated || msg.eof) {
452
432
  // console.log("[machine-starter] terminate FFI loop", vmID);
453
- // Release the hub subscription and channel; without this each VM (one per build in the
454
- // builder) left both behind for the lifetime of the page.
455
- await sub.unsubscribe().catch(() => {});
456
- closeChannel(channel);
457
433
  return;
458
434
  }
459
435
  let name = msg.payload.name;
@@ -514,8 +490,6 @@ async function blobsMessageLoop(hub, config, terminate) {
514
490
  ]);
515
491
  if (terminated || msg.eof) {
516
492
  // console.log("[machine-starter] terminate blobs loop", vmID);
517
- await sub.unsubscribe().catch(() => {});
518
- closeChannel(channel);
519
493
  return;
520
494
  }
521
495
  let name = msg.payload.name;
@@ -583,20 +557,7 @@ class FFIComm {
583
557
  }
584
558
  }
585
559
 
586
- // Stops every VM that `parentVmID` started (through $vm_start) and has not stopped itself, including
587
- // ones that are still starting. Returns how many were stopped. A parent that outlives its children
588
- // (the L2 session agent starts one embedded VM per session) can leave one running when its owner
589
- // goes away before the session finished starting; the caller decides when that has happened.
590
- function terminateChildren(parentVmID) {
591
- let list = children[parentVmID];
592
- if (!list || list.length === 0) return 0;
593
- let ids = list.slice();
594
- children[parentVmID] = [];
595
- for (let id of ids) terminateVM(id);
596
- return ids.length;
597
- }
598
-
599
560
  // use terminateVM to shut a worker down!
600
- export { StartWASM, StartWASM2, terminateVM, terminateChildren,
561
+ export { StartWASM, StartWASM2, terminateVM,
601
562
  Token, Case, Opaque
602
563
  }
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "13056";
1
+ var GROOVEBOX_BUILD = "13058";
2
2
  export { GROOVEBOX_BUILD }
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./common.js";
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@remix_labs/machine-starter",
3
- "version": "2.13056.0-dev",
3
+ "version": "2.13058.0-dev",
4
4
  "description": "start the groove",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",
7
+ "types": "index.d.ts",
7
8
  "type": "module",
8
9
  "scripts": {
9
10
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,7 +12,7 @@
11
12
  "author": "Remixlabs staff",
12
13
  "license": "ISC",
13
14
  "dependencies": {
14
- "@remix_labs/hub-client": "2.13056.0-dev",
15
+ "@remix_labs/hub-client": "2.13058.0-dev",
15
16
  "nanoid": "^5.0.2",
16
17
  "web-worker": "^1.2.0"
17
18
  },
package/package_pub.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "description": "start the groove",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",
7
+ "types": "index.d.ts",
7
8
  "type": "module",
8
9
  "scripts": {
9
10
  "test": "echo \"Error: no test specified\" && exit 1"