@ai-ecoverse/slicc-kernel 1.79.0 → 1.81.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
@@ -570,6 +570,7 @@ function id(value) {
570
570
  return value;
571
571
  }
572
572
  function changeCred(cur, change) {
573
+ if (typeof change !== "object" || change === null) throw fsError("EINVAL", "not a change");
573
574
  const privileged = cur.euid === 0;
574
575
  const next2 = copyCred(cur);
575
576
  for (const keys of [UIDS, GIDS]) {
@@ -2479,7 +2480,7 @@ var UserDb = class {
2479
2480
  };
2480
2481
 
2481
2482
  // src/client/protocol.ts
2482
- var PROTOCOL = [1, 9];
2483
+ var PROTOCOL = [1, 10];
2483
2484
  var FS_METHODS = [
2484
2485
  "readFile",
2485
2486
  "writeFile",
@@ -2729,6 +2730,10 @@ async function watchOp(l, req, watches, send, g) {
2729
2730
  watches.set(req.id, unwatch);
2730
2731
  return { result: req.id };
2731
2732
  }
2733
+ var TRAITS_WATCH = -1;
2734
+ function traitsWatch(launcher, transport, send) {
2735
+ return launcher.onTraits(() => send({ traits: transport.traits }));
2736
+ }
2732
2737
  function serveClient(port, host) {
2733
2738
  let state = "new";
2734
2739
  let self;
@@ -2780,6 +2785,7 @@ function serveClient(port, host) {
2780
2785
  ...host.lock ? { lock: host.lock } : {}
2781
2786
  }
2782
2787
  });
2788
+ watches.set(TRAITS_WATCH, traitsWatch(launcher, transport, send));
2783
2789
  }
2784
2790
  async function terminal(req, l) {
2785
2791
  const session = await l.openTerminal(req.argv, {
@@ -13840,7 +13846,9 @@ function replayingHops(inner, heldMs = HELD_MS) {
13840
13846
  return bodiless(hop);
13841
13847
  };
13842
13848
  return {
13843
- traits: { ...inner.traits, manualRedirects: true },
13849
+ get traits() {
13850
+ return { ...inner.traits, manualRedirects: true };
13851
+ },
13844
13852
  ...inner.websocket ? { websocket: inner.websocket.bind(inner) } : {},
13845
13853
  async fetch(request, owner = KERNEL) {
13846
13854
  const key = keyOf2(owner, request.method, request.url);
@@ -16382,6 +16390,7 @@ var Launcher = class {
16382
16390
  this.env = { ...networkEnv(hostname), SLICC_CDP_URL: this.cdp.url, ...options.env };
16383
16391
  this.ca = kernelCa(options.caStore ?? memoryCaStore());
16384
16392
  this.transport = replayingHops(options.transport ?? missingTransport());
16393
+ this.announcedTraits = JSON.stringify(this.transport.traits);
16385
16394
  this.uplink = options.uplink;
16386
16395
  this.routes = new Routes(options.uplink?.traits.ipv6 === true);
16387
16396
  if (options.uplink?.routes) this.routes.set(options.uplink.routes);
@@ -16453,6 +16462,19 @@ var Launcher = class {
16453
16462
  setRoutes(table) {
16454
16463
  this.routes.set(table);
16455
16464
  }
16465
+ traitsListeners = /* @__PURE__ */ new Set();
16466
+ announcedTraits = "";
16467
+ onTraits(listener) {
16468
+ this.traitsListeners.add(listener);
16469
+ return () => this.traitsListeners.delete(listener);
16470
+ }
16471
+ updateTransportTraits() {
16472
+ const now = JSON.stringify(this.transport.traits);
16473
+ if (now === this.announcedTraits) return false;
16474
+ this.announcedTraits = now;
16475
+ for (const listener of [...this.traitsListeners]) listener();
16476
+ return true;
16477
+ }
16456
16478
  commands(scope = "") {
16457
16479
  let found = this.catalogs.get(scope);
16458
16480
  if (!found) {
@@ -17875,6 +17897,9 @@ function diagnosing(transport, check = diagnose) {
17875
17897
  if (!open) return transport;
17876
17898
  return {
17877
17899
  ...transport,
17900
+ get traits() {
17901
+ return transport.traits;
17902
+ },
17878
17903
  websocket: async (request) => {
17879
17904
  try {
17880
17905
  return await open(request);
@@ -18352,6 +18377,7 @@ var Channel = class {
18352
18377
  greeted = Promise.withResolvers();
18353
18378
  ended = Promise.withResolvers();
18354
18379
  remote;
18380
+ traitsListeners = /* @__PURE__ */ new Set();
18355
18381
  failure;
18356
18382
  pending = /* @__PURE__ */ new Map();
18357
18383
  watching = /* @__PURE__ */ new Map();
@@ -18399,6 +18425,11 @@ var Channel = class {
18399
18425
  return this.request(call).done;
18400
18426
  }
18401
18427
  receive(data) {
18428
+ if (data.traits && data.id === void 0) {
18429
+ if (this.remote) this.remote.traits = data.traits;
18430
+ for (const listener of [...this.traitsListeners]) listener(data.traits);
18431
+ return;
18432
+ }
18402
18433
  if (data.cdpOpen && data.port) {
18403
18434
  this.openCdp(data);
18404
18435
  return;
@@ -18679,6 +18710,10 @@ async function attachKernel(port, options = {}) {
18679
18710
  loopbackFetch: (input, options2) => loopbackFetch((o) => dialOn(channel, o), input, options2),
18680
18711
  fs: fsOn(channel),
18681
18712
  serveCdp: (hook, options2 = {}) => serveCdpOn(channel, hook, options2),
18713
+ onTraits(listener) {
18714
+ channel.traitsListeners.add(listener);
18715
+ return () => channel.traitsListeners.delete(listener);
18716
+ },
18682
18717
  async close(o = {}) {
18683
18718
  if (channel.failure) return;
18684
18719
  await channel.call({ op: "detach", ...o.kill ? { kill: true } : {} }).catch(() => void 0);
@@ -18864,6 +18899,7 @@ async function createNodeKernel(options = {}) {
18864
18899
  umount: (target) => guard2(async () => launcher.umount(target)),
18865
18900
  mounts: async () => launcher.mounts.list(),
18866
18901
  setRoutes: (routes) => guard2(async () => launcher.setRoutes(routes)),
18902
+ updateTransportTraits: () => guard2(async () => launcher.updateTransportTraits()),
18867
18903
  users: {
18868
18904
  mode: launcher.usersMode,
18869
18905
  add: (user) => guard2(() => launcher.users.add(user)),