@ai-ecoverse/slicc-kernel 1.186.1 → 1.187.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.
@@ -4673,7 +4673,7 @@ function satisfies(version, range2) {
4673
4673
  }
4674
4674
 
4675
4675
  // src/version.ts
4676
- var KERNEL_VERSION = true ? "1.186.1" : "0.0.0-dev";
4676
+ var KERNEL_VERSION = true ? "1.187.0" : "0.0.0-dev";
4677
4677
  var OS_RELEASE = "6.0.0-slicc";
4678
4678
  function procVersion() {
4679
4679
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -29388,7 +29388,7 @@ function replayingHops(inner, heldMs = HELD_MS) {
29388
29388
  clearTimeout(entry.timer);
29389
29389
  void entry.final.cancel().catch(() => void 0);
29390
29390
  };
29391
- const keyOf3 = (owner, method, url) => `${owner} ${method} ${url}`;
29391
+ const keyOf4 = (owner, method, url) => `${owner} ${method} ${url}`;
29392
29392
  const hold = (key, chain2) => {
29393
29393
  drop(key);
29394
29394
  const mine = [...held.keys()].filter((k) => held.get(k)?.owner === chain2.owner);
@@ -29407,7 +29407,7 @@ function replayingHops(inner, heldMs = HELD_MS) {
29407
29407
  const method = followedWith(hop.status, chain2.method);
29408
29408
  const away = target.origin !== new URL(hop.url).origin;
29409
29409
  const print = away ? unauthorized(chain2.fingerprint) : chain2.fingerprint;
29410
- hold(keyOf3(chain2.owner, method, target.href), {
29410
+ hold(keyOf4(chain2.owner, method, target.href), {
29411
29411
  ...chain2,
29412
29412
  method,
29413
29413
  fingerprint: print,
@@ -29424,7 +29424,7 @@ function replayingHops(inner, heldMs = HELD_MS) {
29424
29424
  if (unfollowed2(request.redirect)) return inner.fetch(request, ...rest2);
29425
29425
  const [caller] = rest2;
29426
29426
  const owner = caller ?? KERNEL;
29427
- const key = keyOf3(owner, request.method, request.url);
29427
+ const key = keyOf4(owner, request.method, request.url);
29428
29428
  const waiting2 = held.get(key);
29429
29429
  if (waiting2 && waiting2.fingerprint === fingerprint(request.headers)) {
29430
29430
  held.delete(key);
@@ -39373,6 +39373,7 @@ var DEPTH_RESERVE = 2;
39373
39373
  function shardId(base, index) {
39374
39374
  return index === 0 ? base : `${base}~${index}`;
39375
39375
  }
39376
+ var ofBase = (id2, base) => id2 === base || id2.startsWith(`${base}~`);
39376
39377
  var Placement = class {
39377
39378
  shards = /* @__PURE__ */ new Map();
39378
39379
  waiters = /* @__PURE__ */ new Set();
@@ -39421,7 +39422,7 @@ var Placement = class {
39421
39422
  expected(size) {
39422
39423
  let largest = size.initial;
39423
39424
  for (const shard of this.shards.values()) {
39424
- if (!shard.id.startsWith(size.base)) continue;
39425
+ if (!ofBase(shard.id, size.base)) continue;
39425
39426
  for (const seat of shard.seats) largest = Math.max(largest, seat.bytes);
39426
39427
  }
39427
39428
  return largest;
@@ -39440,7 +39441,7 @@ var Placement = class {
39440
39441
  let spare = 0;
39441
39442
  let shards = 0;
39442
39443
  for (const shard of this.shards.values()) {
39443
- if (shard.seats.size === 0 || !shard.id.startsWith(size.base)) continue;
39444
+ if (shard.seats.size === 0 || !ofBase(shard.id, size.base)) continue;
39444
39445
  shards++;
39445
39446
  const used = this.used(shard.id) + this.pending(shard.id);
39446
39447
  const room = this.budget - size.module * MODULE_ALLOWANCE_FACTOR - used;
@@ -39578,6 +39579,16 @@ function imageOfInit(init) {
39578
39579
  if (!program) return void 0;
39579
39580
  return imageOf(program.module) ?? (typeof program.image === "string" ? program.image : void 0);
39580
39581
  }
39582
+ function importsOfInit(init) {
39583
+ const imports = init?.program?.imports;
39584
+ return typeof imports === "string" ? imports : void 0;
39585
+ }
39586
+ var NO_IMPORTS_MODULE = "export {};\n";
39587
+ async function programRef(image, source) {
39588
+ if (source === void 0) return { image };
39589
+ return { image, imports: { source, digest: await digest(source) } };
39590
+ }
39591
+ var keyOf3 = (ref) => ref.imports ? `${ref.image}+${ref.imports.digest}` : ref.image;
39581
39592
  function forkNeed(init) {
39582
39593
  const total = init.fork?.snapshot?.total;
39583
39594
  if (typeof total === "number" && total > 0) return total;
@@ -39592,12 +39603,17 @@ function parentOf10(init) {
39592
39603
  function cloudflareProcesses(loader, images, gate, code, memory = {}) {
39593
39604
  let hostDigest;
39594
39605
  let loads = 0;
39595
- const workerId = async (image) => {
39606
+ const idOf3 = async (ref) => {
39596
39607
  hostDigest ??= digest(`${code.host}\0${code.process}\0${code.localForks !== false}`);
39597
- return `slicc-${(await hostDigest).slice(0, 16)}-${image.slice(0, 40)}`;
39608
+ const imports = ref.imports ? `-${ref.imports.digest.slice(0, 16)}` : "";
39609
+ return `slicc-${(await hostDigest).slice(0, 16)}-${ref.image.slice(0, 40)}${imports}`;
39598
39610
  };
39599
- const workerCode = (image) => {
39611
+ const workerCode = (ref) => {
39600
39612
  loads++;
39613
+ const env = {
39614
+ ...code.localForks === false ? { SLICC_LOCAL_FORKS: "off" } : {},
39615
+ ...ref.imports ? { SLICC_IMPORTS: ref.imports.digest } : {}
39616
+ };
39601
39617
  return {
39602
39618
  compatibilityDate: code.compatibilityDate ?? PROCESS_COMPATIBILITY_DATE,
39603
39619
  ...code.compatibilityFlags ? { compatibilityFlags: code.compatibilityFlags } : {},
@@ -39605,25 +39621,30 @@ function cloudflareProcesses(loader, images, gate, code, memory = {}) {
39605
39621
  modules: {
39606
39622
  "host.js": code.host,
39607
39623
  "process.js": code.process,
39608
- "program.wasm": { wasm: images.get(image) }
39624
+ "program.wasm": { wasm: images.get(ref.image) },
39625
+ "imports.js": ref.imports?.source ?? NO_IMPORTS_MODULE
39609
39626
  },
39610
39627
  globalOutbound: null,
39611
- ...code.localForks === false ? { env: { SLICC_LOCAL_FORKS: "off" } } : {}
39628
+ ...Object.keys(env).length > 0 ? { env } : {}
39612
39629
  };
39613
39630
  };
39614
39631
  const forks = new ForkTokens();
39615
39632
  const placement = new Placement(gate, { ...memory, waitMs: gate.waitMs });
39616
39633
  const reservations = /* @__PURE__ */ new Map();
39617
39634
  const seated = /* @__PURE__ */ new Map();
39618
- const sizeOf2 = async (image) => ({
39619
- image,
39620
- base: await workerId(image),
39621
- ...images.sizeOf(image)
39622
- });
39623
- const reservedFor = (image) => {
39624
- const list = reservations.get(image);
39635
+ const sizeOf2 = async (ref) => {
39636
+ const { initial: initial3, module } = images.sizeOf(ref.image);
39637
+ return {
39638
+ image: keyOf3(ref),
39639
+ base: await idOf3(ref),
39640
+ initial: initial3,
39641
+ module: module + (ref.imports?.source.length ?? 0)
39642
+ };
39643
+ };
39644
+ const reservedFor = (key) => {
39645
+ const list = reservations.get(key);
39625
39646
  const seat = list?.shift();
39626
- if (list?.length === 0) reservations.delete(image);
39647
+ if (list?.length === 0) reservations.delete(key);
39627
39648
  return seat;
39628
39649
  };
39629
39650
  const depthOf = (ppid) => {
@@ -39642,41 +39663,39 @@ function cloudflareProcesses(loader, images, gate, code, memory = {}) {
39642
39663
  return {
39643
39664
  forks,
39644
39665
  placement,
39645
- workerId,
39666
+ workerId: async (image, imports) => idOf3(await programRef(image, imports)),
39646
39667
  get loads() {
39647
39668
  return loads;
39648
39669
  },
39649
- async admit(module, from = {}) {
39670
+ async admit(module, from = {}, imports) {
39650
39671
  const image = imageOf(module);
39651
39672
  if (image === void 0 || !images.has(image)) return () => {
39652
39673
  };
39674
+ const ref = await programRef(image, imports);
39675
+ const key = keyOf3(ref);
39653
39676
  const parent = from.ppid === void 0 ? void 0 : seated.get(from.ppid);
39654
- const seat = await placement.place(
39655
- await sizeOf2(image),
39656
- void 0,
39657
- depthOf(from.ppid),
39658
- parent
39659
- );
39660
- const list = reservations.get(image) ?? [];
39677
+ const seat = await placement.place(await sizeOf2(ref), void 0, depthOf(from.ppid), parent);
39678
+ const list = reservations.get(key) ?? [];
39661
39679
  list.push(seat);
39662
- reservations.set(image, list);
39680
+ reservations.set(key, list);
39663
39681
  return () => {
39664
39682
  const at = list.indexOf(seat);
39665
39683
  if (at < 0) return;
39666
39684
  list.splice(at, 1);
39667
- if (list.length === 0 && reservations.get(image) === list) reservations.delete(image);
39685
+ if (list.length === 0 && reservations.get(key) === list) reservations.delete(key);
39668
39686
  seat.release();
39669
39687
  };
39670
39688
  },
39671
39689
  async open(init) {
39672
39690
  const image = imageOfInit(init);
39673
39691
  if (image === void 0) throw new Error("this host runs only wasm programs with an image");
39674
- const reserved2 = reservedFor(image);
39692
+ const ref = await programRef(image, importsOfInit(init));
39693
+ const reserved2 = reservedFor(keyOf3(ref));
39675
39694
  if (!images.has(image)) {
39676
39695
  reserved2?.release();
39677
39696
  throw new Error(`no program image ${image}`);
39678
39697
  }
39679
- const size = await sizeOf2(image);
39698
+ const size = await sizeOf2(ref);
39680
39699
  const forkInit = init;
39681
39700
  const need2 = forkNeed(forkInit);
39682
39701
  const seat = nearParent(size, forkInit, reserved2) ?? await placement.place(size, need2);
@@ -39688,7 +39707,7 @@ function cloudflareProcesses(loader, images, gate, code, memory = {}) {
39688
39707
  seat.release();
39689
39708
  };
39690
39709
  try {
39691
- const host = loader.get(seat.id, () => workerCode(image)).getEntrypoint();
39710
+ const host = loader.get(seat.id, () => workerCode(ref)).getEntrypoint();
39692
39711
  return await openLink(host, release, {
39693
39712
  forks,
39694
39713
  sized: (bytes) => seat.memory(bytes),
@@ -42872,7 +42891,7 @@ async function createCloudflareKernel(options) {
42872
42891
  ...options.sql ? { durable: flush } : {},
42873
42892
  ports: localPorts,
42874
42893
  emscripten: "kernel",
42875
- admit: (program, from) => processes2.admit(program.abi === "js" ? void 0 : program.module, from),
42894
+ admit: (program, from) => program.abi === "js" ? processes2.admit(void 0, from) : processes2.admit(program.module, from, program.imports),
42876
42895
  createWorker: () => trackedWorker(processes2, live2, terminated),
42877
42896
  ...options.modules ? { modules: options.modules } : {},
42878
42897
  ...options.commands ? { commands: options.commands } : {},