@ai-ecoverse/slicc-kernel 1.26.0 → 1.26.2

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/dist/node.js CHANGED
@@ -2454,6 +2454,7 @@ Sec-WebSocket-Accept: ${accept2}\r
2454
2454
  // src/cdp/facade.ts
2455
2455
  var MAX_HEAD = 64 * 1024;
2456
2456
  var LIST_TIMEOUT = 1e4;
2457
+ var CLOSE_WAIT_MS = 1e3;
2457
2458
  function respond(status, body, type = "text/plain; charset=utf-8") {
2458
2459
  const bytes = new TextEncoder().encode(body);
2459
2460
  const head = latin1Bytes(
@@ -2599,7 +2600,11 @@ var CdpFacade = class {
2599
2600
  async upgrade(conn, incoming, req, runtime) {
2600
2601
  const accept2 = await acceptKey(req.headers);
2601
2602
  const host = await this.host(runtime);
2602
- await new Relay(conn, incoming, host, this.options.maxMessage ?? MAX_MESSAGE, this.stop.signal).start(switchingHead(accept2)).finally(() => host.close());
2603
+ const limits = {
2604
+ max: this.options.maxMessage ?? MAX_MESSAGE,
2605
+ closeWaitMs: this.options.closeWaitMs ?? CLOSE_WAIT_MS
2606
+ };
2607
+ await new Relay(conn, incoming, host, limits, this.stop.signal).start(switchingHead(accept2)).finally(() => host.close());
2603
2608
  }
2604
2609
  };
2605
2610
  var Relay = class {
@@ -2609,12 +2614,14 @@ var Relay = class {
2609
2614
  incoming;
2610
2615
  host;
2611
2616
  max;
2617
+ closeWaitMs;
2612
2618
  stop;
2613
- constructor(conn, incoming, host, max, stop) {
2619
+ constructor(conn, incoming, host, limits, stop) {
2614
2620
  this.conn = conn;
2615
2621
  this.incoming = incoming;
2616
2622
  this.host = host;
2617
- this.max = max;
2623
+ this.max = limits.max;
2624
+ this.closeWaitMs = limits.closeWaitMs;
2618
2625
  this.stop = stop;
2619
2626
  }
2620
2627
  send(bytes) {
@@ -2640,8 +2647,15 @@ var Relay = class {
2640
2647
  void this.end(CLOSE.tooBig, `a message is over ${this.max} bytes`);
2641
2648
  else void this.send(frame(OP_TEXT, bytes));
2642
2649
  };
2643
- await Promise.race([this.pump(), hostGone]);
2650
+ const pumping = this.pump();
2651
+ await Promise.race([pumping, hostGone]);
2644
2652
  await this.writes;
2653
+ let timer;
2654
+ const waited = new Promise((resolve) => {
2655
+ timer = setTimeout(resolve, this.closeWaitMs);
2656
+ });
2657
+ await Promise.race([pumping, waited]);
2658
+ clearTimeout(timer);
2645
2659
  }
2646
2660
  async pump() {
2647
2661
  const reader = new WsReader(this.incoming, this.max);
@@ -3794,6 +3808,9 @@ var MountFs = class {
3794
3808
  truncate: false,
3795
3809
  exclusive: false,
3796
3810
  ...version !== void 0 ? { ifMatch: version } : {}
3811
+ }).catch((err) => {
3812
+ const gone = version !== void 0 && err.code === "ENOENT";
3813
+ throw gone ? errnoError("ESTALE", `${real} is gone from the host`) : err;
3797
3814
  });
3798
3815
  const chunk2 = mount.caps.maxIo ?? DEFAULT_IO;
3799
3816
  const chunks2 = [];
@@ -6479,6 +6496,7 @@ function within3(path, root) {
6479
6496
  var VfsNode = class {
6480
6497
  data;
6481
6498
  ranged;
6499
+ pin;
6482
6500
  length = 0;
6483
6501
  dirty = false;
6484
6502
  queue = Promise.resolve();
@@ -6490,8 +6508,9 @@ var VfsNode = class {
6490
6508
  fs;
6491
6509
  path;
6492
6510
  orphaned;
6493
- constructor(fs, path, contents2, orphaned = false, dirty = false) {
6511
+ constructor(fs, path, contents2, orphaned = false, dirty = false, pin) {
6494
6512
  this.fs = fs;
6513
+ this.pin = pin;
6495
6514
  this.path = path;
6496
6515
  this.orphaned = orphaned;
6497
6516
  if (contents2 !== void 0) this.data = new Uint8Array(contents2);
@@ -6515,6 +6534,10 @@ var VfsNode = class {
6515
6534
  if (this.revoked) throw new KernelError("EIO");
6516
6535
  if (this.ranged || this.data) return this.ranged;
6517
6536
  const io = rangedOps(this.fs);
6537
+ if (io && this.pin && !this.orphaned) {
6538
+ this.ranged = new AsyncRangedFile(io, this.path, this.pin.size, this.pin.version);
6539
+ return this.ranged;
6540
+ }
6518
6541
  const st = io && !this.orphaned ? await this.fs.stat?.(this.path).catch(() => void 0) : void 0;
6519
6542
  if (io && st?.ranged) {
6520
6543
  this.ranged = new AsyncRangedFile(io, this.path, st.size ?? 0, st.version);
@@ -6654,10 +6677,10 @@ var VfsNodes = class {
6654
6677
  constructor(fs) {
6655
6678
  this.fs = fs;
6656
6679
  }
6657
- open(path) {
6680
+ open(path, pin) {
6658
6681
  let node = this.byPath.get(path);
6659
6682
  if (!node) {
6660
- node = new VfsNode(this.fs, path);
6683
+ node = new VfsNode(this.fs, path, void 0, false, false, pin);
6661
6684
  this.byPath.set(path, node);
6662
6685
  }
6663
6686
  node.opens++;
@@ -6778,7 +6801,7 @@ function vfsFile(fs, opts, nodes) {
6778
6801
  const access = opts.flags & O_ACCMODE;
6779
6802
  const readable = access !== O_WRONLY;
6780
6803
  const writable = access === O_WRONLY || access === O_RDWR;
6781
- const node = !nodes || opts.orphan ? new VfsNode(fs, opts.path, opts.contents, opts.orphan === true, opts.dirty === true) : opts.contents !== void 0 ? nodes.adopt(opts.path, opts.contents, opts.dirty === true) : nodes.open(opts.path);
6804
+ const node = !nodes || opts.orphan ? new VfsNode(fs, opts.path, opts.contents, opts.orphan === true, opts.dirty === true) : opts.contents !== void 0 ? nodes.adopt(opts.path, opts.contents, opts.dirty === true) : nodes.open(opts.path, opts.pin);
6782
6805
  let openError;
6783
6806
  const atOpen = (op) => {
6784
6807
  void node.serial(op).catch((err) => {
@@ -7096,7 +7119,8 @@ var WasmProcess = class {
7096
7119
  ...req.contents !== void 0 ? { contents: req.contents } : {},
7097
7120
  ...req.orphan ? { orphan: true } : {},
7098
7121
  ...req.truncate ? { truncate: true } : {},
7099
- ...req.create ? { create: true } : {}
7122
+ ...req.create ? { create: true } : {},
7123
+ ...req.pin ? { pin: req.pin } : {}
7100
7124
  },
7101
7125
  this.nodes
7102
7126
  );
@@ -7228,7 +7252,8 @@ var WasmProcess = class {
7228
7252
  position: req.position ?? 0,
7229
7253
  ...req.contents !== void 0 ? { contents: req.contents } : {},
7230
7254
  ...req.orphan ? { orphan: true } : {},
7231
- ...req.dirty ? { dirty: true } : {}
7255
+ ...req.dirty ? { dirty: true } : {},
7256
+ ...req.pin ? { pin: req.pin } : {}
7232
7257
  },
7233
7258
  this.nodes
7234
7259
  );
@@ -10631,6 +10656,7 @@ async function createNodeKernel(options = {}) {
10631
10656
  ...transport ? { transport } : {},
10632
10657
  ...options.processMounts !== void 0 ? { processMounts: options.processMounts } : {},
10633
10658
  ...options.fstabRetries ? { fstabRetries: options.fstabRetries } : {},
10659
+ ...options.hostfs ? { hostfs: options.hostfs } : {},
10634
10660
  ...options.cdp ? { cdp: options.cdp } : {}
10635
10661
  });
10636
10662
  await launcher.prepare();