@napuketto/kernel 0.7.1 → 0.7.3

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/index.cjs CHANGED
@@ -4714,13 +4714,22 @@ function resolveMainFromStartup(ctx) {
4714
4714
  *
4715
4715
  * - serialize:深度受限序列化(BigInt 转字符串,Map/Set/Promise 展开,循环引用防护)
4716
4716
  * - tryShape:解析 service getter 返回形状
4717
+ *
4718
+ * 字节串保真(2026-11-01 首录教训):onRecvSysMsg 的 wire bytes 与 grayTip 的
4719
+ * jsonGrayTipElement 是批次三(sysmsg 识别表 / reaction)的样本来源——TypedArray
4720
+ * 与字节形态普通数组转 base64 全量保留(截断上限放宽),数字数组/深对象不再
4721
+ * 20 项 / 4 层截断(上限提至 64 / 8)。
4717
4722
  */
4718
4723
  /** 序列化深度上限(循环引用/深层对象防护)。 */
4719
- const MAX_SERIALIZE_DEPTH = 4;
4724
+ const MAX_SERIALIZE_DEPTH = 8;
4720
4725
  /** 数组序列化条数上限。 */
4721
- const MAX_ARRAY_ITEMS = 20;
4726
+ const MAX_ARRAY_ITEMS = 64;
4722
4727
  /** 对象键序列化条数上限。 */
4723
4728
  const MAX_OBJECT_KEYS = 50;
4729
+ /** 字节串保留上限(超过截断 + truncated 标注)。 */
4730
+ const MAX_BYTES = 8192;
4731
+ /** 字节形态普通数组的最短长度(短数字数组按普通数组序列化)。 */
4732
+ const BYTES_ARRAY_MIN = 16;
4724
4733
  /** 序列化一个值(BigInt 转字符串,Map/Set/Promise 展开,循环引用防护)。 */
4725
4734
  function serialize(value, depth = 0) {
4726
4735
  if (value === null || value === void 0) return value;
@@ -4734,14 +4743,33 @@ function serialize(value, depth = 0) {
4734
4743
  return "[unserializable]";
4735
4744
  }
4736
4745
  }
4737
- /** 序列化容器对象(数组 / Map / Set / Promise / 普通对象)。 */
4746
+ /** 序列化容器对象(TypedArray / 数组 / Map / Set / Promise / 普通对象)。 */
4738
4747
  function serializeContainer(value, depth) {
4739
- if (Array.isArray(value)) return serializeArray(value, depth);
4748
+ if (ArrayBuffer.isView(value)) return serializeBytes(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
4749
+ if (Array.isArray(value)) {
4750
+ if (value.length >= BYTES_ARRAY_MIN && looksLikeBytes(value)) return serializeBytes(Uint8Array.from(value, (b) => b & 255));
4751
+ return serializeArray(value, depth);
4752
+ }
4740
4753
  if (value instanceof Map) return serializeMap(value, depth);
4741
4754
  if (value instanceof Set) return serializeSet(value, depth);
4742
4755
  if (typeof value.then === "function") return "[Promise]";
4743
4756
  return serializeObject(value, depth);
4744
4757
  }
4758
+ /** 普通数组是否字节形态(全部元素为整数且落 [-128, 255]——原生把字节块转成带符号字节数组)。 */
4759
+ function looksLikeBytes(value) {
4760
+ return value.every((x) => typeof x === "number" && Number.isInteger(x) && x >= -128 && x <= 255);
4761
+ }
4762
+ /** 字节块 → { kind: "bytes", size, data(base64), truncated? }。 */
4763
+ function serializeBytes(bytes) {
4764
+ const capped = bytes.length > MAX_BYTES ? bytes.subarray(0, MAX_BYTES) : bytes;
4765
+ const out = {
4766
+ kind: "bytes",
4767
+ size: bytes.length,
4768
+ data: Buffer.from(capped).toString("base64")
4769
+ };
4770
+ if (capped.length < bytes.length) out["truncated"] = bytes.length - capped.length;
4771
+ return out;
4772
+ }
4745
4773
  /** 数组序列化(条数截断)。 */
4746
4774
  function serializeArray(value, depth) {
4747
4775
  return value.slice(0, MAX_ARRAY_ITEMS).map((v) => serialize(v, depth + 1));
package/dist/index.mjs CHANGED
@@ -4688,13 +4688,22 @@ function resolveMainFromStartup(ctx) {
4688
4688
  *
4689
4689
  * - serialize:深度受限序列化(BigInt 转字符串,Map/Set/Promise 展开,循环引用防护)
4690
4690
  * - tryShape:解析 service getter 返回形状
4691
+ *
4692
+ * 字节串保真(2026-11-01 首录教训):onRecvSysMsg 的 wire bytes 与 grayTip 的
4693
+ * jsonGrayTipElement 是批次三(sysmsg 识别表 / reaction)的样本来源——TypedArray
4694
+ * 与字节形态普通数组转 base64 全量保留(截断上限放宽),数字数组/深对象不再
4695
+ * 20 项 / 4 层截断(上限提至 64 / 8)。
4691
4696
  */
4692
4697
  /** 序列化深度上限(循环引用/深层对象防护)。 */
4693
- const MAX_SERIALIZE_DEPTH = 4;
4698
+ const MAX_SERIALIZE_DEPTH = 8;
4694
4699
  /** 数组序列化条数上限。 */
4695
- const MAX_ARRAY_ITEMS = 20;
4700
+ const MAX_ARRAY_ITEMS = 64;
4696
4701
  /** 对象键序列化条数上限。 */
4697
4702
  const MAX_OBJECT_KEYS = 50;
4703
+ /** 字节串保留上限(超过截断 + truncated 标注)。 */
4704
+ const MAX_BYTES = 8192;
4705
+ /** 字节形态普通数组的最短长度(短数字数组按普通数组序列化)。 */
4706
+ const BYTES_ARRAY_MIN = 16;
4698
4707
  /** 序列化一个值(BigInt 转字符串,Map/Set/Promise 展开,循环引用防护)。 */
4699
4708
  function serialize(value, depth = 0) {
4700
4709
  if (value === null || value === void 0) return value;
@@ -4708,14 +4717,33 @@ function serialize(value, depth = 0) {
4708
4717
  return "[unserializable]";
4709
4718
  }
4710
4719
  }
4711
- /** 序列化容器对象(数组 / Map / Set / Promise / 普通对象)。 */
4720
+ /** 序列化容器对象(TypedArray / 数组 / Map / Set / Promise / 普通对象)。 */
4712
4721
  function serializeContainer(value, depth) {
4713
- if (Array.isArray(value)) return serializeArray(value, depth);
4722
+ if (ArrayBuffer.isView(value)) return serializeBytes(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
4723
+ if (Array.isArray(value)) {
4724
+ if (value.length >= BYTES_ARRAY_MIN && looksLikeBytes(value)) return serializeBytes(Uint8Array.from(value, (b) => b & 255));
4725
+ return serializeArray(value, depth);
4726
+ }
4714
4727
  if (value instanceof Map) return serializeMap(value, depth);
4715
4728
  if (value instanceof Set) return serializeSet(value, depth);
4716
4729
  if (typeof value.then === "function") return "[Promise]";
4717
4730
  return serializeObject(value, depth);
4718
4731
  }
4732
+ /** 普通数组是否字节形态(全部元素为整数且落 [-128, 255]——原生把字节块转成带符号字节数组)。 */
4733
+ function looksLikeBytes(value) {
4734
+ return value.every((x) => typeof x === "number" && Number.isInteger(x) && x >= -128 && x <= 255);
4735
+ }
4736
+ /** 字节块 → { kind: "bytes", size, data(base64), truncated? }。 */
4737
+ function serializeBytes(bytes) {
4738
+ const capped = bytes.length > MAX_BYTES ? bytes.subarray(0, MAX_BYTES) : bytes;
4739
+ const out = {
4740
+ kind: "bytes",
4741
+ size: bytes.length,
4742
+ data: Buffer.from(capped).toString("base64")
4743
+ };
4744
+ if (capped.length < bytes.length) out["truncated"] = bytes.length - capped.length;
4745
+ return out;
4746
+ }
4719
4747
  /** 数组序列化(条数截断)。 */
4720
4748
  function serializeArray(value, depth) {
4721
4749
  return value.slice(0, MAX_ARRAY_ITEMS).map((v) => serialize(v, depth + 1));