@ai-ecoverse/slicc-kernel 1.178.4 → 1.180.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.
@@ -827,7 +827,7 @@ async function loopbackFetch(dial, input, options) {
827
827
  }
828
828
 
829
829
  // src/client/protocol.ts
830
- var PROTOCOL = [1, 13];
830
+ var PROTOCOL = [1, 15];
831
831
  function locksOf(scope = globalThis) {
832
832
  const locks = scope.navigator?.locks;
833
833
  return typeof locks?.request === "function" ? locks : void 0;
@@ -892,6 +892,7 @@ var Channel = class {
892
892
  failure;
893
893
  pending = /* @__PURE__ */ new Map();
894
894
  watching = /* @__PURE__ */ new Map();
895
+ tracing = /* @__PURE__ */ new Map();
895
896
  cdpHooks = /* @__PURE__ */ new Map();
896
897
  cdpOpen = /* @__PURE__ */ new Set();
897
898
  facadeHooks = /* @__PURE__ */ new Map();
@@ -959,6 +960,10 @@ var Channel = class {
959
960
  this.watching.get(data.watch)?.(data.change);
960
961
  return;
961
962
  }
963
+ if (data.trace !== void 0 && data.id === void 0) {
964
+ this.traced(data.trace, data.events ?? [], data.dropped ?? 0);
965
+ return;
966
+ }
962
967
  if (data.bye !== void 0) {
963
968
  this.end(new KernelGoneError(data.bye));
964
969
  return;
@@ -987,6 +992,23 @@ var Channel = class {
987
992
  if (reply.error !== void 0) call.reject(new KernelCallError(reply.error, reply.code));
988
993
  else call.resolve(reply.result);
989
994
  }
995
+ traced(trace, events, dropped) {
996
+ const listener = this.tracing.get(trace);
997
+ if (!listener) return;
998
+ const ack = () => {
999
+ if (this.tracing.has(trace)) this.post({ traceAck: trace });
1000
+ };
1001
+ let consumed;
1002
+ try {
1003
+ consumed = listener({ events, dropped });
1004
+ } finally {
1005
+ if (typeof consumed?.then === "function") {
1006
+ void Promise.resolve(consumed).then(ack, ack);
1007
+ } else {
1008
+ ack();
1009
+ }
1010
+ }
1011
+ }
990
1012
  openCdp({ cdpOpen: { registration, ...request }, port }) {
991
1013
  const hook = registration === void 0 ? void 0 : this.cdpHooks.get(registration);
992
1014
  if (!hook || this.failure) {
@@ -1049,6 +1071,29 @@ async function serveCdpOn(channel, hook, options) {
1049
1071
  }
1050
1072
  };
1051
1073
  }
1074
+ async function traceOn(channel, tag, onEvents, options) {
1075
+ if (typeof onEvents !== "function") throw new TypeError("trace: onEvents must be a function");
1076
+ await since(channel, 15, "trace", async () => {
1077
+ });
1078
+ const { id, done } = channel.request({
1079
+ op: "trace",
1080
+ tag,
1081
+ ...options.limit !== void 0 ? { limit: options.limit } : {}
1082
+ });
1083
+ channel.tracing.set(id, onEvents);
1084
+ try {
1085
+ await done;
1086
+ } catch (error) {
1087
+ channel.tracing.delete(id);
1088
+ throw error;
1089
+ }
1090
+ return {
1091
+ close: () => {
1092
+ if (!channel.tracing.delete(id)) return;
1093
+ void channel.call({ op: "untrace", trace: id }).catch(() => void 0);
1094
+ }
1095
+ };
1096
+ }
1052
1097
  async function dialOn(channel, { port, host }) {
1053
1098
  const req = { op: "dial", port, ...host ? { host } : {} };
1054
1099
  return dialStream(await since(channel, 4, "dial", () => channel.call(req)));
@@ -1062,6 +1107,10 @@ async function spawnOn(channel, argv, opts) {
1062
1107
  });
1063
1108
  if (opts.tag !== void 0) await since(channel, 12, "a tag per spawn", async () => {
1064
1109
  });
1110
+ if (Array.isArray(opts.tag)) await since(channel, 15, "several tags per spawn", async () => {
1111
+ });
1112
+ if (opts.cwdMissing === "error") await since(channel, 14, "cwdMissing: 'error'", async () => {
1113
+ });
1065
1114
  const started = Promise.withResolvers();
1066
1115
  let endedBy;
1067
1116
  const options = { ...rest, ...stdin !== void 0 ? { stdin: bytesOf2(stdin) } : {} };
@@ -1121,6 +1170,12 @@ async function terminalOn(channel, argv, opts) {
1121
1170
  });
1122
1171
  if (opts.tag !== void 0) await since(channel, 12, "a tag per terminal", async () => {
1123
1172
  });
1173
+ if (Array.isArray(opts.tag)) {
1174
+ await since(channel, 15, "several tags per terminal", async () => {
1175
+ });
1176
+ }
1177
+ if (opts.cwdMissing === "error") await since(channel, 14, "cwdMissing: 'error'", async () => {
1178
+ });
1124
1179
  let listener = onData ?? null;
1125
1180
  const backlog = [];
1126
1181
  const started = Promise.withResolvers();
@@ -1278,6 +1333,7 @@ async function attachKernel(port, options = {}) {
1278
1333
  channel.traitsListeners.add(listener);
1279
1334
  return () => channel.traitsListeners.delete(listener);
1280
1335
  },
1336
+ trace: (tag, onEvents, options2 = {}) => traceOn(channel, tag, onEvents, options2),
1281
1337
  async close(o = {}) {
1282
1338
  if (channel.failure) return;
1283
1339
  await channel.call({ op: "detach", ...o.kill ? { kill: true } : {} }).catch(() => void 0);