@napuketto/kernel 0.15.4 → 0.16.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/index.mjs CHANGED
@@ -1345,6 +1345,13 @@ function toDoubtFriendRequestInfo(item, uinMap) {
1345
1345
  *
1346
1346
  * ⚠️ 部分字段按公开资料(wrapper 外部契约)自研描述,待下一次进程内
1347
1347
  * 探测(probe.ts)校准——接口签名是外部系统事实,自研描述其形状。
1348
+ *
1349
+ * ⚠️ 跨平台空值契约(2026-11 Linux 3.2.x 线上事故):Windows 原生对象省略
1350
+ * 未命中的变体字段(`undefined`),Linux 原生对象则把未命中的变体字段**显式
1351
+ * 置 `null`**(纯文本元素的 `picElement: null` / `grayTipElement: null` 等),
1352
+ * 元素子字段同样可能是 null。因此本文件所有可选字段都声明为 `T | null`
1353
+ * (而非仅 `T`):读取方必须用 `== null` / `!= null`(同时覆盖 null 与
1354
+ * undefined),禁止只判 `=== undefined`。这样编译器会持续拦截新的漏网读取。
1348
1355
  */
1349
1356
  /** 会话类型(QQ wrapper 外部契约)。 */
1350
1357
  const ChatType = {
@@ -1475,18 +1482,18 @@ const AtType = {
1475
1482
  * 直接 `.get(0)` 抛 TypeError,整条视频消息事件分派失败。
1476
1483
  */
1477
1484
  function readVideoThumbPath(thumb) {
1478
- if (thumb === void 0 || thumb === "") return;
1485
+ if (thumb == null || thumb === "") return;
1479
1486
  if (typeof thumb === "string") return thumb;
1480
1487
  if (thumb instanceof Map) {
1481
1488
  const value = thumb.get(0);
1482
- return value === "" ? void 0 : value;
1489
+ return value == null || value === "" ? void 0 : value;
1483
1490
  }
1484
1491
  const value = thumb[String(0)];
1485
- return value === "" ? void 0 : value;
1492
+ return value == null || value === "" ? void 0 : value;
1486
1493
  }
1487
1494
  /** TEXT 元素 → canonical(at 或纯文本)。 */
1488
1495
  function textToCanonical(textEl) {
1489
- if (textEl === void 0) return {
1496
+ if (textEl == null) return {
1490
1497
  type: "text",
1491
1498
  text: ""
1492
1499
  };
@@ -1512,9 +1519,15 @@ function textToCanonical(textEl) {
1512
1519
  text: content
1513
1520
  };
1514
1521
  }
1515
- /** 空串视为缺失(Linux 原生对象常给 "" 而不是省略字段)。 */
1522
+ /**
1523
+ * 空值视为缺失(跨平台原生对象形态差异):
1524
+ * - Windows 省略未命中的字段 → undefined;
1525
+ * - Linux 3.2.x 显式置 null;
1526
+ * - Linux 原生对象也常给 "" 而不是省略字段。
1527
+ * 三者统一归为 undefined,避免 null 被当成有效值继续下传。
1528
+ */
1516
1529
  function emptyToUndefined(value) {
1517
- return value === void 0 || value === "" ? void 0 : value;
1530
+ return value == null || value === "" ? void 0 : value;
1518
1531
  }
1519
1532
  /** 取第一个非空字符串(跨平台字段名不一致时的兜底链)。 */
1520
1533
  function firstNonEmpty(...values) {
@@ -1537,7 +1550,7 @@ function isLocalPathCandidate(value) {
1537
1550
  * pic-path-grace(桥层等待落盘)与 picToCanonical 共用同一候选序。
1538
1551
  */
1539
1552
  function picLocalCandidates(pic) {
1540
- if (pic === void 0) return [];
1553
+ if (pic == null) return [];
1541
1554
  const seen = /* @__PURE__ */ new Set();
1542
1555
  const out = [];
1543
1556
  for (const raw of [pic.picPath, pic.sourcePath]) {
@@ -1551,7 +1564,7 @@ function picLocalCandidates(pic) {
1551
1564
  }
1552
1565
  /** PIC 元素 → canonical image。 */
1553
1566
  function picToCanonical(pic) {
1554
- if (pic === void 0) return {
1567
+ if (pic == null) return {
1555
1568
  type: "image",
1556
1569
  path: ""
1557
1570
  };
@@ -1570,7 +1583,7 @@ function picToCanonical(pic) {
1570
1583
  }
1571
1584
  /** FACE 元素 → canonical face。 */
1572
1585
  function faceToCanonical(face) {
1573
- if (face === void 0) return {
1586
+ if (face == null) return {
1574
1587
  type: "face",
1575
1588
  id: "0"
1576
1589
  };
@@ -1581,7 +1594,7 @@ function faceToCanonical(face) {
1581
1594
  }
1582
1595
  /** PTT 元素 → canonical voice。 */
1583
1596
  function pttToCanonical(ptt) {
1584
- if (ptt === void 0) return {
1597
+ if (ptt == null) return {
1585
1598
  type: "voice",
1586
1599
  path: ""
1587
1600
  };
@@ -1592,7 +1605,7 @@ function pttToCanonical(ptt) {
1592
1605
  }
1593
1606
  /** VIDEO 元素 → canonical video。 */
1594
1607
  function videoToCanonical(video) {
1595
- if (video === void 0) return {
1608
+ if (video == null) return {
1596
1609
  type: "video",
1597
1610
  path: ""
1598
1611
  };
@@ -1600,23 +1613,23 @@ function videoToCanonical(video) {
1600
1613
  type: "video",
1601
1614
  path: video.filePath ?? video.videoUrl ?? ""
1602
1615
  };
1603
- if (video.videoUrl !== void 0) base.url = video.videoUrl;
1616
+ if (video.videoUrl != null) base.url = video.videoUrl;
1604
1617
  const thumb = readVideoThumbPath(video.thumbPath);
1605
1618
  if (thumb !== void 0) base.thumbPath = thumb;
1606
- if (video.thumbWidth !== void 0 && video.thumbWidth > 0) base.width = video.thumbWidth;
1607
- if (video.thumbHeight !== void 0 && video.thumbHeight > 0) base.height = video.thumbHeight;
1608
- if (video.fileTime !== void 0 && video.fileTime > 0) base.durationSec = video.fileTime;
1619
+ if (video.thumbWidth != null && video.thumbWidth > 0) base.width = video.thumbWidth;
1620
+ if (video.thumbHeight != null && video.thumbHeight > 0) base.height = video.thumbHeight;
1621
+ if (video.fileTime != null && video.fileTime > 0) base.durationSec = video.fileTime;
1609
1622
  return base;
1610
1623
  }
1611
1624
  /** FILE 元素 → canonical file。 */
1612
1625
  function fileToCanonical(file) {
1613
- if (file === void 0) return {
1626
+ if (file == null) return {
1614
1627
  type: "file",
1615
1628
  path: ""
1616
1629
  };
1617
1630
  const path = file.filePath ?? "";
1618
1631
  const name = file.fileName;
1619
- if (name === void 0) return {
1632
+ if (name == null) return {
1620
1633
  type: "file",
1621
1634
  path
1622
1635
  };
@@ -1628,13 +1641,13 @@ function fileToCanonical(file) {
1628
1641
  }
1629
1642
  /** REPLY 元素 → canonical reply。 */
1630
1643
  function replyToCanonical(reply) {
1631
- if (reply === void 0) return {
1644
+ if (reply == null) return {
1632
1645
  type: "reply",
1633
1646
  messageId: ""
1634
1647
  };
1635
1648
  return {
1636
1649
  type: "reply",
1637
- messageId: reply.replayMsgId
1650
+ messageId: reply.replayMsgId ?? ""
1638
1651
  };
1639
1652
  }
1640
1653
  /**
@@ -1646,7 +1659,7 @@ function replyToCanonical(reply) {
1646
1659
  */
1647
1660
  function arkToCanonical(ark, el) {
1648
1661
  const bytes = ark?.bytesData;
1649
- if (bytes === void 0 || bytes === "") return {
1662
+ if (bytes == null || bytes === "") return {
1650
1663
  type: "unknown",
1651
1664
  raw: el
1652
1665
  };
@@ -2305,8 +2318,8 @@ const PTT_POLL_INTERVAL_MS = 300;
2305
2318
  const PTT_POLL_TIMES = 34;
2306
2319
  /** 语音下载完成判定:有路径且(传输完成或末次轮询)才返回元素,否则 null。 */
2307
2320
  function pttDownloadResult(latest, isLastPoll) {
2308
- if (latest === void 0) return null;
2309
- const hasPath = latest.filePath !== void 0 && latest.filePath !== "";
2321
+ if (latest == null) return null;
2322
+ const hasPath = latest.filePath != null && latest.filePath !== "";
2310
2323
  const done = latest.transferStatus === 2 || latest.transferStatus === 4;
2311
2324
  return hasPath && (done || isLastPoll) ? latest : null;
2312
2325
  }
@@ -2670,7 +2683,7 @@ var MsgApi = class {
2670
2683
  if (ptt === null) throw kernelError("消息中不包含语音", "NOT_FOUND");
2671
2684
  unwrapResult("translatePtt2Text", await this.service.translatePtt2Text(msgId, target, ptt));
2672
2685
  const text = findPttElement(await this.fetchMsgsByMsgId(target, [msgId]))?.pttElement?.text;
2673
- if (text === void 0 || text === "") throw kernelError("获取语音转文字结果失败", "UNKNOWN");
2686
+ if (text == null || text === "") throw kernelError("获取语音转文字结果失败", "UNKNOWN");
2674
2687
  return text;
2675
2688
  }
2676
2689
  /** 标记会话已读。 */
@@ -2705,7 +2718,7 @@ var MsgApi = class {
2705
2718
  async pttElementOf(msgId, target) {
2706
2719
  const el = findPttElement(await this.fetchMsgsByMsgId(target, [msgId]));
2707
2720
  const ptt = el?.pttElement;
2708
- if (el === null || ptt === void 0) return null;
2721
+ if (el === null || ptt == null) return null;
2709
2722
  return {
2710
2723
  elemId: el.elementId ?? "",
2711
2724
  ptt
@@ -2764,7 +2777,7 @@ var MsgApi = class {
2764
2777
  });
2765
2778
  unwrapResult("buildMultiForwardMsg", built);
2766
2779
  const elements = built.rspInfo?.elements;
2767
- if (elements === void 0 || elements.length === 0) throw kernelError("合并转发组装失败:无元素", "UNKNOWN");
2780
+ if (elements == null || elements.length === 0) throw kernelError("合并转发组装失败:无元素", "UNKNOWN");
2768
2781
  const msgId = this.service.generateMsgUniqueId(target.chatType, String(Date.now()));
2769
2782
  unwrapResult("sendMsg", await this.service.sendMsg(msgId, target, elements, /* @__PURE__ */ new Map()));
2770
2783
  return { msgId };
@@ -2772,7 +2785,7 @@ var MsgApi = class {
2772
2785
  /** 获取合并转发内容(get_forward_msg;resId 取自 multiForwardMsgElement)。 */
2773
2786
  async fetchForwardMessage(peer, msgId) {
2774
2787
  const forward = findForwardElement(await this.fetchMsgsByMsgId(peer, [msgId]));
2775
- if (forward === null || forward.resId === "") throw kernelError("消息不包含合并转发内容", "NOT_FOUND");
2788
+ if (forward === null || forward.resId == null || forward.resId === "") throw kernelError("消息不包含合并转发内容", "NOT_FOUND");
2776
2789
  const raw = await this.service.getMultiMsg(peer, msgId, forward.resId);
2777
2790
  unwrapResult("getMultiMsg", raw);
2778
2791
  return raw.msgList ?? [];
@@ -2787,17 +2800,26 @@ var MsgApi = class {
2787
2800
  unwrapResult("setStatus", await this.service.setStatus(opts));
2788
2801
  }
2789
2802
  };
2790
- /** 在消息列表中找含 pttElement 的元素(找不到返回 null)。 */
2803
+ /**
2804
+ * 在消息列表中找含 pttElement 的元素(找不到返回 null)。
2805
+ *
2806
+ * ⚠️ `!= null` 而非 `!== undefined`(Linux 原生宿主):Windows 省略未命中的
2807
+ * 变体字段,Linux 3.2.x 把所有变体字段显式置 null。用 `!== undefined` 会让
2808
+ * 首个元素(哪怕是文本消息)被误判成语音元素,进而把 null 传给原生下载接口。
2809
+ */
2791
2810
  function findPttElement(msgs) {
2792
2811
  const [first] = msgs;
2793
2812
  if (first === void 0) return null;
2794
- return first.elements.find((el) => el.pttElement !== void 0) ?? null;
2813
+ return first.elements.find((el) => el.pttElement != null) ?? null;
2795
2814
  }
2796
- /** 在消息列表中找含 multiForwardMsgElement 的元素(找不到返回 null)。 */
2815
+ /**
2816
+ * 在消息列表中找含 multiForwardMsgElement 的元素(找不到返回 null)。
2817
+ * 同 findPttElement:`!= null` 兼容 Linux 的显式 null 变体字段。
2818
+ */
2797
2819
  function findForwardElement(msgs) {
2798
2820
  const [first] = msgs;
2799
2821
  if (first === void 0) return null;
2800
- return first.elements.find((el) => el.multiForwardMsgElement !== void 0)?.multiForwardMsgElement ?? null;
2822
+ return first.elements.find((el) => el.multiForwardMsgElement != null)?.multiForwardMsgElement ?? null;
2801
2823
  }
2802
2824
  // src/apis/stranger-info.ts
2803
2825
  /** 宽松取值:undefined 时给默认值(null 也归默认)。 */
@@ -3565,9 +3587,12 @@ const DEFAULT_INTERVAL_MS = 250;
3565
3587
  function collectCandidates(msgs) {
3566
3588
  const seen = /* @__PURE__ */ new Set();
3567
3589
  const out = [];
3568
- for (const msg of msgs) for (const element of msg.elements ?? []) for (const candidate of picLocalCandidates(element.picElement)) if (!seen.has(candidate)) {
3569
- seen.add(candidate);
3570
- out.push(candidate);
3590
+ for (const msg of msgs) for (const element of msg.elements ?? []) {
3591
+ if (element.elementType !== ElementType.PIC || element.picElement == null) continue;
3592
+ for (const candidate of picLocalCandidates(element.picElement)) if (!seen.has(candidate)) {
3593
+ seen.add(candidate);
3594
+ out.push(candidate);
3595
+ }
3571
3596
  }
3572
3597
  return out;
3573
3598
  }
@@ -3613,7 +3638,13 @@ var MsgBridge = class {
3613
3638
  * 超时后原样放行(canonical 层置空裁决)。
3614
3639
  */
3615
3640
  emitPicAware(event, msgs) {
3616
- if (!hasPendingPicPaths(msgs)) {
3641
+ let pending;
3642
+ try {
3643
+ pending = hasPendingPicPaths(msgs);
3644
+ } catch {
3645
+ pending = false;
3646
+ }
3647
+ if (!pending) {
3617
3648
  this.channel.emit(event, msgs);
3618
3649
  return;
3619
3650
  }