@ai-ecoverse/slicc-kernel 1.179.0 → 1.181.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, 14];
830
+ var PROTOCOL = [1, 16];
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,8 @@ 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
+ });
1065
1112
  if (opts.cwdMissing === "error") await since(channel, 14, "cwdMissing: 'error'", async () => {
1066
1113
  });
1067
1114
  const started = Promise.withResolvers();
@@ -1086,6 +1133,19 @@ async function spawnOn(channel, argv, opts) {
1086
1133
  signal: async (name = "SIGTERM") => void await channel.call({ op: "kill", pid: -pgid, signal: name })
1087
1134
  };
1088
1135
  }
1136
+ async function sudoRunOn(channel, replay, { stdout, stderr, tag }) {
1137
+ await since(channel, 16, "sudoRun", async () => {
1138
+ });
1139
+ const started = Promise.withResolvers();
1140
+ let endedBy;
1141
+ const { done } = channel.request(
1142
+ { op: "sudo-run", replay, options: { stdout, stderr, tag } },
1143
+ { started: started.resolve, ended: (signal) => endedBy = signal }
1144
+ );
1145
+ done.catch(started.reject);
1146
+ const pid = await started.promise;
1147
+ return { pid, pgid: pid, ended: endedOf(done, () => endedBy) };
1148
+ }
1089
1149
  function endedOf(done, signal) {
1090
1150
  return quiet(
1091
1151
  done.then((status) => {
@@ -1123,6 +1183,10 @@ async function terminalOn(channel, argv, opts) {
1123
1183
  });
1124
1184
  if (opts.tag !== void 0) await since(channel, 12, "a tag per terminal", async () => {
1125
1185
  });
1186
+ if (Array.isArray(opts.tag)) {
1187
+ await since(channel, 15, "several tags per terminal", async () => {
1188
+ });
1189
+ }
1126
1190
  if (opts.cwdMissing === "error") await since(channel, 14, "cwdMissing: 'error'", async () => {
1127
1191
  });
1128
1192
  let listener = onData ?? null;
@@ -1282,6 +1346,8 @@ async function attachKernel(port, options = {}) {
1282
1346
  channel.traitsListeners.add(listener);
1283
1347
  return () => channel.traitsListeners.delete(listener);
1284
1348
  },
1349
+ trace: (tag, onEvents, options2 = {}) => traceOn(channel, tag, onEvents, options2),
1350
+ sudoRun: (replay, options2 = {}) => sudoRunOn(channel, replay, options2),
1285
1351
  async close(o = {}) {
1286
1352
  if (channel.failure) return;
1287
1353
  await channel.call({ op: "detach", ...o.kill ? { kill: true } : {} }).catch(() => void 0);