@ai-ecoverse/slicc-kernel 1.45.0 → 1.46.0

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
@@ -735,6 +735,9 @@ var KernelSocket = class _KernelSocket {
735
735
  get listening() {
736
736
  return this.state === "listening";
737
737
  }
738
+ get unconnected() {
739
+ return this.state === "open" || this.state === "listening";
740
+ }
738
741
  connection() {
739
742
  if (!this.link || this.state !== "connected") throw new KernelError("ENOTCONN");
740
743
  return this.link;
@@ -1399,6 +1402,7 @@ function fetchTransport(options = {}) {
1399
1402
  });
1400
1403
  const body = chunks(response.body, options.bodyIdleMs ?? BODY_IDLE_MS);
1401
1404
  return {
1405
+ ...response.redirected ? { url: response.url, redirected: true } : {},
1402
1406
  status: response.status,
1403
1407
  statusText: response.statusText,
1404
1408
  headers: headers2,
@@ -1444,6 +1448,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1444
1448
  peer.postMessage({
1445
1449
  net: "head",
1446
1450
  nid: call.nid,
1451
+ ...response.redirected ? { url: response.url, redirected: true } : {},
1447
1452
  status: response.status,
1448
1453
  statusText: response.statusText,
1449
1454
  headers: response.headers
@@ -7377,6 +7382,8 @@ var WsHandles = class {
7377
7382
  // src/kernel/net/http-syscalls.ts
7378
7383
  var HTTP_OPS = [
7379
7384
  "net-request",
7385
+ "net-open",
7386
+ "net-head",
7380
7387
  "net-read",
7381
7388
  "net-close",
7382
7389
  "net-traits",
@@ -7401,6 +7408,8 @@ var HttpHandles = class {
7401
7408
  syscall(req) {
7402
7409
  if (req.op.startsWith("net-ws-")) return this.ws.syscall(req);
7403
7410
  if (req.op === "net-request") return this.request(req);
7411
+ if (req.op === "net-open") return Promise.resolve(this.opened(req));
7412
+ if (req.op === "net-head") return this.head(req.handle);
7404
7413
  if (req.op === "net-read") return this.read(req.handle, req.max);
7405
7414
  if (req.op === "net-traits") return Promise.resolve(this.traits());
7406
7415
  return this.close(req.handle);
@@ -7410,56 +7419,70 @@ var HttpHandles = class {
7410
7419
  if (unavailable) return { ok: false, errno: "ENETUNREACH", message: NO_TRANSPORT };
7411
7420
  return { ok: true, kind: "json", json: { ...rest2, crossOrigin } };
7412
7421
  }
7413
- add(abort, body, cancel) {
7422
+ async request(req) {
7423
+ const { handle, head } = this.start(req);
7424
+ const result = await head;
7425
+ if (!result.ok) this.open.delete(handle);
7426
+ return result;
7427
+ }
7428
+ opened(req) {
7429
+ return { ok: true, kind: "json", json: this.start(req).handle };
7430
+ }
7431
+ start(req) {
7414
7432
  const handle = ++this.nextHandle;
7415
- this.open.set(handle, {
7433
+ const abort = new AbortController();
7434
+ const entry = {
7416
7435
  abort,
7417
- body: body[Symbol.asyncIterator](),
7436
+ head: Promise.resolve({ ok: true, kind: "void" }),
7437
+ body: once(EMPTY),
7418
7438
  left: EMPTY,
7419
7439
  done: false,
7420
7440
  reading: Promise.resolve(),
7421
- cancel
7422
- });
7423
- return handle;
7441
+ cancel: async () => void 0
7442
+ };
7443
+ this.open.set(handle, entry);
7444
+ entry.head = this.respond(handle, req, entry);
7445
+ return { handle, head: entry.head };
7424
7446
  }
7425
- async request(req) {
7426
- const abort = new AbortController();
7447
+ async respond(handle, req, entry) {
7427
7448
  try {
7428
7449
  const response = await this.transport.fetch({
7429
7450
  url: req.url,
7430
7451
  method: req.method,
7431
7452
  headers: req.headers,
7432
7453
  ...req.body ? { body: req.body } : {},
7433
- signal: abort.signal
7454
+ signal: entry.abort.signal
7434
7455
  });
7435
- const handle = this.add(abort, response.body, () => response.cancel());
7436
- const head = {
7437
- handle,
7438
- status: response.status,
7439
- statusText: response.statusText,
7440
- url: req.url,
7441
- headers: response.headers
7442
- };
7443
- return { ok: true, kind: "json", json: head };
7456
+ entry.body = response.body[Symbol.asyncIterator]();
7457
+ entry.cancel = () => response.cancel();
7458
+ if (!this.open.has(handle)) await entry.cancel().catch(() => void 0);
7459
+ const head = this.headOf(handle, response.url ?? req.url, response);
7460
+ return response.redirected ? { ...head, json: { ...head.json, redirected: true } } : head;
7444
7461
  } catch (e) {
7445
7462
  const text = message2(e);
7446
- if (text === NO_TRANSPORT) return { ok: false, errno: "ENETUNREACH", message: text };
7447
7463
  const status = e.status;
7448
- if (typeof status !== "number" || status === 502) {
7449
- return { ok: false, errno: "ECONNREFUSED", message: text };
7464
+ if (text === NO_TRANSPORT || typeof status !== "number" || status === 502) {
7465
+ const errno = text === NO_TRANSPORT ? "ENETUNREACH" : "ECONNREFUSED";
7466
+ return { ok: false, errno, message: text };
7450
7467
  }
7451
- const body = new TextEncoder().encode(text);
7452
- const handle = this.add(abort, once(body), async () => void 0);
7453
- const head = {
7454
- handle,
7468
+ entry.body = once(new TextEncoder().encode(text))[Symbol.asyncIterator]();
7469
+ return this.headOf(handle, req.url, {
7455
7470
  status,
7456
7471
  statusText: "",
7457
- url: req.url,
7458
7472
  headers: [["content-type", "text/plain; charset=utf-8"]]
7459
- };
7460
- return { ok: true, kind: "json", json: head };
7473
+ });
7461
7474
  }
7462
7475
  }
7476
+ headOf(handle, url, response) {
7477
+ const { status, statusText, headers } = response;
7478
+ return { ok: true, kind: "json", json: { handle, status, statusText, url, headers } };
7479
+ }
7480
+ head(handle) {
7481
+ const entry = this.open.get(handle);
7482
+ if (!entry)
7483
+ return Promise.resolve({ ok: false, errno: "EBADF", message: `no request ${handle}` });
7484
+ return entry.head;
7485
+ }
7463
7486
  async read(handle, max) {
7464
7487
  const entry = this.open.get(handle);
7465
7488
  if (!entry) return { ok: false, errno: "EBADF", message: `no request ${handle}` };
@@ -9342,6 +9365,9 @@ var WasmProcess = class {
9342
9365
  throw e;
9343
9366
  }
9344
9367
  }
9368
+ refuseIfPending(restart) {
9369
+ if (restart && this.options.hasPending?.()) throw new KernelError("EINTR");
9370
+ }
9345
9371
  blockingSignal() {
9346
9372
  if (this.options.hasPending?.()) throw new KernelError("EINTR");
9347
9373
  return this.interrupt.signal;
@@ -9352,6 +9378,7 @@ var WasmProcess = class {
9352
9378
  if (!read) throw new KernelError(req.peek && file.read ? "EOPNOTSUPP" : "EBADF");
9353
9379
  if (file.tty) this.checkForeground(file.tty);
9354
9380
  if (req.max <= 0) return new Uint8Array(0);
9381
+ if (file instanceof KernelSocket && file.unconnected) throw new KernelError("ENOTCONN");
9355
9382
  const ready2 = pollFile(file).readable;
9356
9383
  if (!ready2 && req.nonblock) throw new KernelError("EAGAIN");
9357
9384
  const signal = ready2 ? this.interrupt.signal : this.blockingSignal();
@@ -9674,8 +9701,10 @@ var WasmProcess = class {
9674
9701
  async procSyscall(req) {
9675
9702
  switch (req.op) {
9676
9703
  case "proc-fork":
9704
+ this.refuseIfPending(req.restart);
9677
9705
  return { ok: true, kind: "json", json: await this.children.fork(req.state) };
9678
9706
  case "proc-spawn":
9707
+ this.refuseIfPending(req.restart);
9679
9708
  return { ok: true, kind: "json", json: await this.spawn(req) };
9680
9709
  case "proc-wait": {
9681
9710
  const signal = req.nohang ? this.interrupt.signal : this.blockingSignal();
@@ -12712,7 +12741,7 @@ var RemoteTransport = class {
12712
12741
  finish();
12713
12742
  throw e;
12714
12743
  }
12715
- const { status, statusText, headers } = head;
12744
+ const { status, statusText, headers, url, redirected } = head;
12716
12745
  const read = async () => {
12717
12746
  if (finished) return void 0;
12718
12747
  const reply = await this.ask({ net: "read", nid }).catch((e) => {
@@ -12729,6 +12758,7 @@ var RemoteTransport = class {
12729
12758
  this.cancel(nid);
12730
12759
  };
12731
12760
  return {
12761
+ ...redirected ? { url, redirected } : {},
12732
12762
  status,
12733
12763
  statusText,
12734
12764
  headers,