@napuketto/kernel 0.19.2 → 0.19.4

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.
Files changed (3) hide show
  1. package/dist/index.d.mts +788 -881
  2. package/dist/index.mjs +4825 -4652
  3. package/package.json +1 -1
package/dist/index.d.mts CHANGED
@@ -1,5 +1,9 @@
1
1
  /**
2
- * @napuketto/kernel 入口(P0 地基 + P1 前哨)
2
+ * @napuketto/kernel 入口(Flat 5-Tier Runtime)
3
+ *
4
+ * 五段式扁平分层:L0 `types/` + `infra/`(零内部依赖)→ L1 `native/`(原生防腐层)
5
+ * → L2 `apis/`(无状态语义 API)→ L3 `runtime/`(登录 / 缓存 / 内核装配)。
6
+ * 本文件是唯一根出口,逐层汇总公共面;导出符号与目录重构前逐项一致。
3
7
  *
4
8
  * 当前导出:类型化错误(ADR-017)、路径装配(ADR-016)、pino 日志(ADR-007)、
5
9
  * JSON 配置基类(ADR-012)、类型化事件通道(ADR-003)、QQ 版本探测(ADR-018)、
@@ -7,10 +11,6 @@
7
11
  * apis / cache / login / bridge 均已接入(见下方导出)。
8
12
  */
9
13
  import pino from "pino";
10
- /** NT RawMessage → canonical 元素(与 toSendElements 对称,接收方向)。 */
11
- export declare function toCanonicalElements(msg: RawMessage): CanonicalElement[];
12
- /** canonical 元素 → NT 发送元素(text/at/face/image/voice/reply 核心 + json ARK 透传)。 */
13
- export declare function toSendElements(elements: CanonicalElement[]): SendMessageElement[];
14
14
  /**
15
15
  * 实体类型层(运行时探测产物 + 公开资料作说明书,ADR-006)
16
16
  *
@@ -39,11 +39,24 @@ interface Peer {
39
39
  peerUid: string;
40
40
  guildId?: string;
41
41
  }
42
- /** 文本元素(at 用 atType + atUid 表达)。 */
42
+ /** 文本元素(at 用 atType + atNtUid/atUid 表达)。 */
43
43
  interface TextElement {
44
44
  content: string;
45
45
  atType?: number | null;
46
+ /**
47
+ * 单人 at 目标的 **数字 UIN**(QQ 号字符串)。
48
+ *
49
+ * ⚠️ 不是 NT UID:把 `u_...` 写进本字段会被 wrapper 归零成 `"0"`(issue #192)。
50
+ * 客户端原生元素里它是 atNtUid 的冗余镜像;`@全体` 缺省。
51
+ */
46
52
  atUid?: string | null;
53
+ /**
54
+ * 单人 at 目标的 **NT UID**(`u_...`),QQNT 解析真实提及所依赖的字段;
55
+ * 接收方向优先读它。`@全体` 实测为 `"all"`(atType=1)。
56
+ */
57
+ atNtUid?: string | null;
58
+ /** at 目标 tinyId(原生元素可能携带;发送不需要)。 */
59
+ atTinyId?: string | null;
47
60
  }
48
61
  /** 图片元素(发送时 picPath 必须;接收含 url)。 */
49
62
  interface PicElement {
@@ -1265,10 +1278,9 @@ type RecentContactListener = {
1265
1278
  *
1266
1279
  * 描述 QQ 消息的事实结构,是各协议翻译层的公共中间表示。
1267
1280
  *
1268
- * 2026-11:运行时转换函数(picLocalCandidates / toCanonicalElements /
1269
- * toSendElements)已下沉至 `../codec/message-element.ts`——类型层保持纯声明,
1270
- * 不再 import `node:fs` 与 `../infra/**` 运行时值;本文件末行保留桥接重导出,
1271
- * 既有导入坐标(含单测)零破坏。
1281
+ * 本文件只做**类型声明**(无 `node:fs` / `infra` 运行时依赖);运行时转换函数
1282
+ * (`picLocalCandidates` / `toCanonicalElements` / `toSendElements`)在
1283
+ * `native/message-codec.ts`,经 `native/index.ts` 对外。
1272
1284
  */
1273
1285
  /** 协议无关的规范消息元素。 */
1274
1286
  type CanonicalElement = {
@@ -1642,72 +1654,6 @@ export declare class FlashTransferApi {
1642
1654
  /** 注销监听器:失败不影响主流程(原生可能已卸载服务)。 */
1643
1655
  private detachQuietly;
1644
1656
  }
1645
- /** 好友条目(uid + 昵称/备注,昵称由 buddy service 缓存补全)。 */
1646
- interface Friend {
1647
- uid: string;
1648
- /** QQ 号。无法解析时为空,uid 始终单独保留。 */
1649
- uin: string | null;
1650
- nickname: string;
1651
- remark: string;
1652
- }
1653
- /** 带分类的好友列表项(get_friends_with_category 返回)。 */
1654
- interface FriendCategory {
1655
- categoryId: number;
1656
- categorySortId: number;
1657
- categoryName: string;
1658
- categoryMbCount: number;
1659
- onlineCount: number;
1660
- buddyList: Friend[];
1661
- }
1662
- /** 可疑好友申请(OB11 结构,get_doubt_friends_add_request 返回)。 */
1663
- interface DoubtFriendRequestInfo {
1664
- flag: string;
1665
- /**
1666
- * 申请人 QQ 号。uid 无法解析为数字 uin(如 `u_xxx` 且不在任何群)时**缺省**:
1667
- * `Number("u_xxx")` 会产出 NaN,JSON 序列化后静默变成 null(下游 number 契约被
1668
- * 击穿),所以这里宁可不给字段,也不给 NaN / 0 这类假值。
1669
- */
1670
- uin?: number;
1671
- nick?: string;
1672
- source?: string;
1673
- reason?: string;
1674
- msg?: string;
1675
- group_code?: string;
1676
- time?: string;
1677
- type: "doubt";
1678
- }
1679
- /** FriendApi 构造选项。 */
1680
- interface FriendApiOptions {
1681
- /** uid→uin 转换器(通常注入 GroupApi.uidToUin);只补缺少 UIN 的项。 */
1682
- uidToUin?: ((uids: string[]) => Promise<Map<string, string>>) | undefined;
1683
- }
1684
- /** 好友 API:从 session 拿 buddy service,包装成语义化方法。 */
1685
- export declare class FriendApi {
1686
- private readonly service;
1687
- private readonly uidToUin;
1688
- constructor(session: NodeIQQNTWrapperSession, opts?: FriendApiOptions);
1689
- /** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
1690
- getFriendList(): Promise<Friend[]>;
1691
- private friendsFromCategories;
1692
- /** 带分类的好友列表(get_friends_with_category,分类保留)。 */
1693
- getFriendCategories(): Promise<FriendCategory[]>;
1694
- /** 原始分类(getBuddyListV2 / 缓存)。 */
1695
- private getBuddyCategories;
1696
- /** 判断是否好友。 */
1697
- isBuddy(uid: string): boolean;
1698
- /** 好友申请列表(set_friend_add_request 应答前查找匹配项)。 */
1699
- getBuddyReqList(): Promise<BuddyReq[]>;
1700
- /** 应答好友申请(accept=true 同意;remark 由调用方另行 setFriendRemark)。 */
1701
- handleFriendRequest(notify: BuddyReq, accept: boolean): Promise<void>;
1702
- /** 设置好友备注(void 语义乐观处理)。 */
1703
- setFriendRemark(uid: string, remark: string): void;
1704
- /** 删除好友(tempBlock=拉黑,tempBothDel=双向删除)。 */
1705
- deleteFriend(uid: string, tempBlock?: boolean, tempBothDel?: boolean): Promise<void>;
1706
- /** 可疑好友申请列表(get_doubt_friends_add_request;uin 经 uidToUin 转换)。 */
1707
- getDoubtFriendRequest(count: number): Promise<DoubtFriendRequestInfo[]>;
1708
- /** 处理可疑好友申请(set_doubt_friends_add_request;uid=flag)。 */
1709
- handleDoubtFriendRequest(uid: string): void;
1710
- }
1711
1657
  /** 群 API:从 session 拿 group service,包装成语义化方法。 */
1712
1658
  export declare class GroupApi {
1713
1659
  private readonly service;
@@ -1770,26 +1716,16 @@ export declare class GroupApi {
1770
1716
  addGroupEssence(groupCode: string, msgId: string): Promise<void>;
1771
1717
  /** 取消精华消息。 */
1772
1718
  removeGroupEssence(groupCode: string, msgId: string): Promise<void>;
1773
- /** 精华消息公共流程:按 msgId 拉消息 → add/removeGroupEssence。 */
1774
- private setEssence;
1775
- /**
1776
- * 群公告列表(get_group_announcements;getGroupBulletin 返回形状待探测校准,
1777
- * 兼容 result 数组 / result.bulletins 等宽松提取)。
1778
- */
1719
+ /** 群公告列表(get_group_announcements)。 */
1779
1720
  getGroupAnnouncements(groupCode: string): Promise<GroupBulletin[]>;
1780
- /**
1781
- * 发群公告(send_group_announcement;imagePath 提供时先 uploadGroupBulletinPic
1782
- * 再带 picId 发布——两步参数形状均待探测校准)。
1783
- */
1721
+ /** 发群公告(send_group_announcement;imagePath 提供时先上传再带 picId 发布)。 */
1784
1722
  publishGroupAnnouncement(groupCode: string, content: string, imagePath?: string): Promise<void>;
1785
- /** 删群公告(delete_group_announcement;参数待探测校准)。 */
1723
+ /** 删群公告(delete_group_announcement)。 */
1786
1724
  deleteGroupAnnouncement(groupCode: string, announcementId: string): Promise<void>;
1787
1725
  /** 专属头衔(set_group_member_special_title;setIdentityTitleInfo 参数待校准)。 */
1788
1726
  setMemberSpecialTitle(groupCode: string, uid: string, title: string): Promise<void>;
1789
1727
  /** 群头像(set_group_avatar;GroupService.setHeader 参数待校准)。 */
1790
1728
  setGroupAvatar(groupCode: string, imagePath: string): Promise<void>;
1791
- /** 公告图片上传(uploadGroupBulletinPic 返回 picId 待校准,失败原样上抛)。 */
1792
- private uploadBulletinPic;
1793
1729
  /** @all 剩余次数(get_group_at_all_remain)。 */
1794
1730
  getGroupRemainAtTimes(groupCode: string): Promise<{
1795
1731
  canAtAll: boolean;
@@ -1889,7 +1825,7 @@ export declare class NTEventChannel<L extends ListenerShape, Name extends string
1889
1825
  timeout?: number;
1890
1826
  }): Promise<EventArgs<L, Name, E>>;
1891
1827
  /**
1892
- * 类型化派发:wrapper-loader 的原生回调经此推入通道。
1828
+ * 类型化派发:wrapper 生命周期的原生回调经此推入通道。
1893
1829
  * 2026-08-07 修复:原生 EventEmitter.emit 中一个 listener 抛异常会中断后续
1894
1830
  * listener 派发(Node 语义)——改为快照数组逐个 try/catch,保证「单个订阅者
1895
1831
  * 异常不打断派发」(协议翻译层异常不饿死缓存维护等其他订阅者)。
@@ -2025,18 +1961,11 @@ export declare class MsgApi {
2025
1961
  private readonly service;
2026
1962
  /** 消息事件通道(sendMsg 后等 onMsgInfoListUpdate 确认发送结果)。 */
2027
1963
  private readonly channel;
2028
- /** NodeQQNTWrapperUtil(富媒体发送 copyFile 用;session 拿不到时可为 null)。 */
2029
- private readonly util;
2030
- /** 上次生成 msgId 的时间(单调递增,2026-08-07 防同毫秒并发碰撞)。 */
2031
- private lastMsgTime;
1964
+ /** msgId 时间戳生成器(单调递增,防同毫秒并发碰撞)。 */
1965
+ private readonly ids;
1966
+ /** 富媒体元素准备器(md5 / 目标路径 / copyFile 落盘)。 */
1967
+ private readonly media;
2032
1968
  constructor(session: NodeIQQNTWrapperSession, channel?: MsgEventChannel, util?: unknown);
2033
- /**
2034
- * 生成 msgId 时间戳(单调递增)。
2035
- * generateMsgUniqueId(chatType, time) 以 time 区分消息——同毫秒并发发送
2036
- * (机器人群发/多会话同时回复)Date.now() 会碰撞,msgId 相同导致 wrapper
2037
- * 拒绝或覆盖。严格单调递增保证进程内唯一。
2038
- */
2039
- private nextMsgTime;
2040
1969
  /**
2041
1970
  * 发送消息:canonical 元素 → NT 发送元素 → sendMsg(NapCat 式)。
2042
1971
  * 返回 NT msgId(雪花 ID)。
@@ -2055,71 +1984,6 @@ export declare class MsgApi {
2055
1984
  sendMessage(target: Peer, elements: CanonicalElement[]): Promise<{
2056
1985
  msgId: string;
2057
1986
  }>;
2058
- /**
2059
- * canonical 元素 → 发送元素,富媒体(PIC/PTT)做 NapCat 式预处理。
2060
- * 2026-08-11 修复(实测):图片发送必须 elementType=2(PIC)+ 完整 picElement
2061
- * (md5HexStr/fileSize/fileName/sourcePath),且文件须经 getRichMediaFilePathForGuild
2062
- * 计算目标路径 + util.copyFile 放置——缺任一环节 sendMsg 返回 rich media transfer failed。
2063
- * 2026-08-12(语音):PTT 同理——只给 filePath 触发 wrapper 内部
2064
- * "Cannot convert undefined or null to object"(缺字段转换失败)。
2065
- */
2066
- private prepareSendElements;
2067
- /**
2068
- * PIC 元素 NapCat 式预处理:md5 → 目标路径 → copyFile → 完整 picElement。
2069
- *
2070
- * 图片尺寸/MIME 优先取 canonical(adapter 已用 `@napuketto/media` 探测并写入
2071
- * `size` / `mime`);缺任一项时(IPC 直发、第三方直接调 kernel)用本包的
2072
- * 零依赖文件头解析兜底补齐,`picType` 按真实类型映射。硬编码 0/0/1000
2073
- * 会让手机端 QQ 收到的图片消息显示空白(上传本身成功)。
2074
- */
2075
- private prepareImageElement;
2076
- /**
2077
- * PTT 元素预处理:md5 → 目标路径 → copyFile → 完整 pttElement。
2078
- *
2079
- * 2026-08-12(实测依据):只给 filePath 时 wrapper 内部抛
2080
- * "Cannot convert undefined or null to object"(缺 md5HexStr/fileSize 等字段),
2081
- * 且发送后进程崩溃重启(supervisor 自动拉起)。完整字段(NapCat 同款,
2082
- * formatType/voiceType/canConvert2Text/waveAmplitudes 等)消除该错误。
2083
- *
2084
- * ⚠️ silk 格式:QQ 语音协议为 silk v3。非 silk → silk 的转码在协议层
2085
- * (adapter,@napuketto/media 的 encodePcmToSilk,2026-08-12 接线)完成,
2086
- * 此处接收的已是 silk 路径,仅做放置。kernel 不 import media(解耦红线)。
2087
- */
2088
- private preparePttElement;
2089
- /**
2090
- * VIDEO 元素预处理:md5 → 目标路径 → copyFile → 完整 videoElement。
2091
- *
2092
- * 字段依据:2026-10-17 收向实测(历史视频消息 videoElement 全字段快照)+
2093
- * 发送实测(2026-10-17 18:12 自建宿主发送成功,群内可播放):
2094
- * 1. `thumbPath` 必须是真实 `Map<number, string>`(收向实测 `Map<0, path>`)——
2095
- * 经 JSON/IPC 传参会退化成 `{}`,wrapper 转换失败;
2096
- * 2. **缩略图目标路径用视频 md5**(`Video/<YYYY-MM>/Thumb/<videoMd5>_0.png`):
2097
- * 真实消息实测 videoMd5=`3d27…`、thumbMd5=`46da…`,落盘文件名却是
2098
- * `3d27…_0.png`;此前按 thumbMd5 放置 → native 传输按视频 md5 找不到缩略图
2099
- * → `rich media transfer failed`(20+ 组字段变体都无效的真正原因);
2100
- * 3. `thumbMd5` 是缩略图**内容**的 md5,与文件名无关;`fileTime` 为秒。
2101
- */
2102
- private prepareVideoElement;
2103
- /**
2104
- * FILE 元素预处理(P2-2 预留口子,upload_private/group_file 落地):
2105
- * pic/ptt/video 同款 NapCat 式链路——md5 → getRichMediaFilePathForGuild(FILE)
2106
- * → copyFile → 完整 fileElement。链路模式已验证(三类媒体同构);fileElement
2107
- * 字段值(fileSize 字符串形态、fileUuid 空串等)待探测校准。
2108
- */
2109
- private prepareFileElement;
2110
- /**
2111
- * 富媒体文件放置(PIC/PTT/VIDEO 共用):md5 + 文件名 → QQ 内部目标路径
2112
- * (getRichMediaFilePathForGuild)→ util.copyFile 放置 → 返回目标路径。
2113
- *
2114
- * `downloadType`:1 = 原文件(Ori),2 = 缩略图(Thumb,视频缩略图必须)。
2115
- */
2116
- private placeMediaFile;
2117
- /**
2118
- * 注册 onMsgInfoListUpdate 确认监听。
2119
- * resolve 时返回命中的那条消息(sendStatus 成功),发送失败/超时 reject。
2120
- * channel 由调用方传入(sendMessage 已在无通道时提前返回,这里不做空判)。
2121
- */
2122
- private confirmSend;
2123
1987
  /** 撤回消息(群聊管理员 / 私聊 2 分钟内)。 */
2124
1988
  recallMessage(target: Peer, msgIds: string[]): Promise<void>;
2125
1989
  /** 拉取历史消息(msgId 为空从最新拉;count 条,时间倒序)。 */
@@ -2142,24 +2006,12 @@ export declare class MsgApi {
2142
2006
  emojiId: string;
2143
2007
  like: boolean;
2144
2008
  }): Promise<void>;
2145
- /**
2146
- * 语音转文字(fetch_ptt_text)。
2147
- * 流程:按 msgId 拉消息 → 找 PTT 元素 → translatePtt2Text(异步转写)
2148
- * → 再拉一次消息读 pttElement.text。
2149
- */
2009
+ /** 语音转文字(fetch_ptt_text)。 */
2150
2010
  fetchPttText(msgId: string, target: Peer): Promise<string>;
2151
2011
  /** 标记会话已读。 */
2152
2012
  markRead(target: Peer): Promise<void>;
2153
- /**
2154
- * 语音主动下载(get_record 本地未命中兜底,2026-09-08 B1)。
2155
- * downloadRichMedia 返回 void(实测),完成信号 = 重拉消息元素:
2156
- * 轮询(300ms × 34,约 10s)直到 filePath 非空且 transferStatus 进入
2157
- * 已下载态(2/4);超时但 filePath 已有值则尽力返回(磁盘命中判断留给
2158
- * 调用方),完全无路径抛 NOT_FOUND。
2159
- */
2013
+ /** 语音主动下载(get_record 本地未命中兜底,2026-09-08 B1)。 */
2160
2014
  downloadPtt(msgId: string, target: Peer): Promise<PttElement>;
2161
- /** 取消息内语音元素(无则 null;附 elemId 供主动下载)。 */
2162
- private pttElementOf;
2163
2015
  /** 发送输入状态(set_input_status;eventType=1 输入中,0 停止)。 */
2164
2016
  setInputStatus(target: Peer, eventType: number): Promise<void>;
2165
2017
  /** 戳一戳发送(send_friend/group_nudge;参数形状待探测校准,失败抛 UNKNOWN)。 */
@@ -2171,10 +2023,7 @@ export declare class MsgApi {
2171
2023
  setContactTop(target: Peer, isTop: boolean): Promise<void>;
2172
2024
  /** 收藏表情列表(get_custom_face_url_list;queryFavEmojiByDesc 形状待校准)。 */
2173
2025
  queryFavEmojis(): Promise<string[]>;
2174
- /**
2175
- * 发送合并转发(send_group/private_forward_msg)。
2176
- * buildMultiForwardMsg 组装 MULTI_FORWARD 元素 → 直接作 sendMsg 元素发送。
2177
- */
2026
+ /** 发送合并转发(send_group/private_forward_msg)。 */
2178
2027
  sendForwardMessage(target: Peer, sourcePeer: Peer, srcMsgIds: string[]): Promise<{
2179
2028
  msgId: string;
2180
2029
  }>;
@@ -2194,6 +2043,115 @@ export declare class MsgApi {
2194
2043
  };
2195
2044
  }): Promise<void>;
2196
2045
  }
2046
+ /** 群文件列表条目(fileInfo/folderInfo 取其一)。 */
2047
+ interface GroupFileListItem {
2048
+ fileInfo?: GroupFileItemInfo;
2049
+ folderInfo?: GroupFolderInfo;
2050
+ }
2051
+ /** 群文件系统信息。 */
2052
+ interface GroupFileSystemInfo {
2053
+ fileCount: number;
2054
+ limitCount: number;
2055
+ usedSpace: number;
2056
+ totalSpace: number;
2057
+ }
2058
+ /** 富媒体 API:从 session 拿 rich media service,包装成语义化方法。 */
2059
+ export declare class RichMediaApi {
2060
+ private readonly service;
2061
+ constructor(session: NodeIQQNTWrapperSession);
2062
+ /** 英文单词翻译(translate_en2zh)。 */
2063
+ translateWords(words: string[]): Promise<string[]>;
2064
+ /** 群文件列表(get_group_root_files;parent 缺省根目录)。 */
2065
+ getGroupFileList(groupCode: string, parentFolderId?: string, fileCount?: number): Promise<GroupFileListItem[]>;
2066
+ /** 群文件系统信息(get_group_file_system_info;getGroupFileList 的 groupSpaceResult)。 */
2067
+ getGroupFileSystemInfo(groupCode: string): Promise<GroupFileSystemInfo>;
2068
+ /** 创建群文件夹(create_group_file_folder)。 */
2069
+ createGroupFolder(groupCode: string, folderName: string): Promise<string>;
2070
+ /** 删除群文件(delete_group_file)。 */
2071
+ deleteGroupFile(groupCode: string, fileIds: string[]): Promise<void>;
2072
+ /** 删除群文件夹(delete_group_folder)。 */
2073
+ deleteGroupFolder(groupCode: string, folderId: string): Promise<void>;
2074
+ /** 重命名群文件(rename_group_file;参数语义待探测校准)。 */
2075
+ renameGroupFile(groupCode: string, fileId: string, newName: string): Promise<void>;
2076
+ /** 移动群文件(move_group_file;targetFolder 空为根目录)。 */
2077
+ moveGroupFile(groupCode: string, fileIds: string[], targetFolderId: string): Promise<void>;
2078
+ /** 重命名群文件夹(rename_group_folder;形态镜像 renameGroupFile,待校准)。 */
2079
+ renameGroupFolder(groupCode: string, folderId: string, newName: string): Promise<void>;
2080
+ /**
2081
+ * 群文件下载链接(get_group_file_download_url):getGroupFileList 根列表按
2082
+ * fileId 查找取 url 字段(字段待实机确认)。已知差异:仅根目录可达——
2083
+ * 子目录文件需 parentFolderId 逐层定位,暂不支持。
2084
+ */
2085
+ getGroupFileDownloadUrl(groupCode: string, fileId: string): Promise<string>;
2086
+ /** 转存群文件(trans_group_file)。 */
2087
+ transGroupFile(groupCode: string, fileId: string): Promise<void>;
2088
+ }
2089
+ /** 好友条目(uid + 昵称/备注,昵称由 buddy service 缓存补全)。 */
2090
+ interface Friend {
2091
+ uid: string;
2092
+ /** QQ 号。无法解析时为空,uid 始终单独保留。 */
2093
+ uin: string | null;
2094
+ nickname: string;
2095
+ remark: string;
2096
+ }
2097
+ /** 带分类的好友列表项(get_friends_with_category 返回)。 */
2098
+ interface FriendCategory {
2099
+ categoryId: number;
2100
+ categorySortId: number;
2101
+ categoryName: string;
2102
+ categoryMbCount: number;
2103
+ onlineCount: number;
2104
+ buddyList: Friend[];
2105
+ }
2106
+ /** 可疑好友申请(OB11 结构,get_doubt_friends_add_request 返回)。 */
2107
+ interface DoubtFriendRequestInfo {
2108
+ flag: string;
2109
+ /**
2110
+ * 申请人 QQ 号。uid 无法解析为数字 uin(如 `u_xxx` 且不在任何群)时**缺省**:
2111
+ * `Number("u_xxx")` 会产出 NaN,JSON 序列化后静默变成 null(下游 number 契约被
2112
+ * 击穿),所以这里宁可不给字段,也不给 NaN / 0 这类假值。
2113
+ */
2114
+ uin?: number;
2115
+ nick?: string;
2116
+ source?: string;
2117
+ reason?: string;
2118
+ msg?: string;
2119
+ group_code?: string;
2120
+ time?: string;
2121
+ type: "doubt";
2122
+ }
2123
+ /** FriendApi 构造选项。 */
2124
+ interface FriendApiOptions {
2125
+ /** uid→uin 转换器(通常注入 GroupApi.uidToUin);只补缺少 UIN 的项。 */
2126
+ uidToUin?: ((uids: string[]) => Promise<Map<string, string>>) | undefined;
2127
+ }
2128
+ /** 好友 API:从 session 拿 buddy service,包装成语义化方法。 */
2129
+ export declare class FriendApi {
2130
+ private readonly service;
2131
+ private readonly uidToUin;
2132
+ constructor(session: NodeIQQNTWrapperSession, opts?: FriendApiOptions);
2133
+ /** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
2134
+ getFriendList(): Promise<Friend[]>;
2135
+ private friendsFromCategories;
2136
+ /** 带分类的好友列表(get_friends_with_category,分类保留)。 */
2137
+ getFriendCategories(): Promise<FriendCategory[]>;
2138
+ /** 原始分类(getBuddyListV2 / 缓存)。 */
2139
+ private getBuddyCategories;
2140
+ /** 判断是否好友。 */
2141
+ isBuddy(uid: string): boolean;
2142
+ /** 好友申请列表(set_friend_add_request 应答前查找匹配项)。 */
2143
+ getBuddyReqList(): Promise<BuddyReq[]>;
2144
+ /** 应答好友申请(accept=true 同意;remark 由调用方另行 setFriendRemark)。 */
2145
+ handleFriendRequest(notify: BuddyReq, accept: boolean): Promise<void>;
2146
+ /** 设置好友备注(void 语义乐观处理)。 */
2147
+ setFriendRemark(uid: string, remark: string): void;
2148
+ /** 删除好友(tempBlock=拉黑,tempBothDel=双向删除)。 */
2149
+ deleteFriend(uid: string, tempBlock?: boolean, tempBothDel?: boolean): Promise<void>;
2150
+ /** 可疑好友申请列表(get_doubt_friends_add_request;uin 经 uidToUin 转换)。 */
2151
+ getDoubtFriendRequest(count: number): Promise<DoubtFriendRequestInfo[]>;
2152
+ /** 处理可疑好友申请(set_doubt_friends_add_request;uid=flag)。 */
2153
+ handleDoubtFriendRequest(uid: string): void;
2154
+ }
2197
2155
  /** 陌生人信息(get_stranger_info 返回)。 */
2198
2156
  interface StrangerInfo {
2199
2157
  user_id: number;
@@ -2257,51 +2215,8 @@ export declare class RecentContactApi {
2257
2215
  /** 置顶会话列表(get_peer_pins;getRecentContactList 返回形状待探测校准)。 */
2258
2216
  getPinnedContacts(): Promise<PinnedContact[]>;
2259
2217
  }
2260
- /** 群文件列表条目(fileInfo/folderInfo 取其一)。 */
2261
- interface GroupFileListItem {
2262
- fileInfo?: GroupFileItemInfo;
2263
- folderInfo?: GroupFolderInfo;
2264
- }
2265
- /** 群文件系统信息。 */
2266
- interface GroupFileSystemInfo {
2267
- fileCount: number;
2268
- limitCount: number;
2269
- usedSpace: number;
2270
- totalSpace: number;
2271
- }
2272
- /** 富媒体 API:从 session 拿 rich media service,包装成语义化方法。 */
2273
- export declare class RichMediaApi {
2274
- private readonly service;
2275
- constructor(session: NodeIQQNTWrapperSession);
2276
- /** 英文单词翻译(translate_en2zh)。 */
2277
- translateWords(words: string[]): Promise<string[]>;
2278
- /** 群文件列表(get_group_root_files;parent 缺省根目录)。 */
2279
- getGroupFileList(groupCode: string, parentFolderId?: string, fileCount?: number): Promise<GroupFileListItem[]>;
2280
- /** 群文件系统信息(get_group_file_system_info;getGroupFileList 的 groupSpaceResult)。 */
2281
- getGroupFileSystemInfo(groupCode: string): Promise<GroupFileSystemInfo>;
2282
- /** 创建群文件夹(create_group_file_folder)。 */
2283
- createGroupFolder(groupCode: string, folderName: string): Promise<string>;
2284
- /** 删除群文件(delete_group_file)。 */
2285
- deleteGroupFile(groupCode: string, fileIds: string[]): Promise<void>;
2286
- /** 删除群文件夹(delete_group_folder)。 */
2287
- deleteGroupFolder(groupCode: string, folderId: string): Promise<void>;
2288
- /** 重命名群文件(rename_group_file;参数语义待探测校准)。 */
2289
- renameGroupFile(groupCode: string, fileId: string, newName: string): Promise<void>;
2290
- /** 移动群文件(move_group_file;targetFolder 空为根目录)。 */
2291
- moveGroupFile(groupCode: string, fileIds: string[], targetFolderId: string): Promise<void>;
2292
- /** 重命名群文件夹(rename_group_folder;形态镜像 renameGroupFile,待校准)。 */
2293
- renameGroupFolder(groupCode: string, folderId: string, newName: string): Promise<void>;
2294
- /**
2295
- * 群文件下载链接(get_group_file_download_url):getGroupFileList 根列表按
2296
- * fileId 查找取 url 字段(字段待实机确认)。已知差异:仅根目录可达——
2297
- * 子目录文件需 parentFolderId 逐层定位,暂不支持。
2298
- */
2299
- getGroupFileDownloadUrl(groupCode: string, fileId: string): Promise<string>;
2300
- /** 转存群文件(trans_group_file)。 */
2301
- transGroupFile(groupCode: string, fileId: string): Promise<void>;
2302
- }
2303
- /** 票据 API:从 session 拿 ticket service,包装成语义化方法。 */
2304
- export declare class TicketApi {
2218
+ /** 票据 API:从 session 拿 ticket service,包装成语义化方法。 */
2219
+ export declare class TicketApi {
2305
2220
  private readonly service;
2306
2221
  constructor(session: NodeIQQNTWrapperSession);
2307
2222
  /** 获取 clientKey(get_clientkey)。 */
@@ -2370,205 +2285,6 @@ export declare class WebApi {
2370
2285
  /** 拉取单类荣誉列表(honorlist 接口,正则提取 __INITIAL_STATE__)。 */
2371
2286
  private fetchHonorList;
2372
2287
  }
2373
- /** BuddyCache diff 事件 listener(归一化「新增/删除」事件)。 */
2374
- type BuddyCacheListener = {
2375
- onBuddyAdded: (entry: BuddyListEntry) => void;
2376
- onBuddyRemoved: (entry: BuddyListEntry) => void;
2377
- };
2378
- /** BuddyCache diff 事件通道(事件名 BuddyCache/onBuddyAdded 等)。 */
2379
- type BuddyCacheEventChannel = NTEventChannel<BuddyCacheListener, "BuddyCache">;
2380
- /** BuddyCache 构造参数。 */
2381
- interface BuddyCacheOptions {
2382
- /** Buddy 事件通道(FriendBridge 注册原生监听后 emit 到这里)。 */
2383
- channel: BuddyEventChannel;
2384
- /** 校准日志(可选:快照形状异常 raw 记录;缺省静默)。 */
2385
- logger?: {
2386
- warn(obj: unknown, msg?: string): void;
2387
- };
2388
- }
2389
- /**
2390
- * 防御性收窄 onBuddyListChange 载荷 → BuddyCategory[](T10 实证形状;
2391
- * 非数组 / 非对象分类项返回 null,调用方打 raw 日志积累校准数据)。
2392
- * 分类字段逐项做运行时类型校验并安全构造,缺失项取保守默认值。
2393
- */
2394
- export declare function narrowBuddyCategories(arg: unknown): BuddyCategory[] | null;
2395
- /** 好友缓存:快照维护 + diff 归一化事件。 */
2396
- export declare class BuddyCache {
2397
- private readonly channel;
2398
- private readonly logger;
2399
- /** diff 归一化事件通道(协议层订阅 friend_add / IPC 转发消费)。 */
2400
- readonly events: BuddyCacheEventChannel;
2401
- /** 好友快照(uid → entry,onBuddyListChange 全量维护)。 */
2402
- private readonly buddies;
2403
- /** 首帧已建 baseline(此后快照才参与 diff)。 */
2404
- private bootstrapped;
2405
- private unsubscribes;
2406
- constructor(opts: BuddyCacheOptions);
2407
- /** 订阅 Buddy 事件通道(幂等)。 */
2408
- register(): void;
2409
- /** 退订事件通道(幂等)。 */
2410
- unregister(): void;
2411
- /** 释放(等价 unregister,幂等)。 */
2412
- dispose(): void;
2413
- /** `using cache = ...` 自动释放。 */
2414
- [Symbol.dispose](): void;
2415
- /** 应用全量快照:首帧建 baseline,之后 diff 发布归一化事件。 */
2416
- private applySnapshot;
2417
- /** 好友快照(只读拷贝)。 */
2418
- listBuddies(): BuddyListEntry[];
2419
- /** 单个好友(快照;undefined = 不在缓存)。 */
2420
- getBuddy(uid: string): BuddyListEntry | undefined;
2421
- /** 快照是否已建(测试/诊断用)。 */
2422
- get baselineReady(): boolean;
2423
- }
2424
- /** onGroupEssenceListChange 参数 → 群号(录制实证首项字符串;防御收窄)。 */
2425
- export declare function narrowEssenceGroupArg(arg: unknown): string | null;
2426
- /** 列表缓存条目:seq → 操作者/发送者 uin(null = 不可得)。 */
2427
- interface EssenceCacheEntry {
2428
- /** 加精操作者(add_digest_uin;取消场景无值)。 */
2429
- operatorUin: string | null;
2430
- /** 被加精消息发送者(sender_uin;OB11 delete 事件 sender_id 只能从缓存回填)。 */
2431
- senderUin: string | null;
2432
- /** 加精时间(add_digest_time 秒级 unix;非正数 → null = 不可得)。 */
2433
- addDigestTime: number | null;
2434
- }
2435
- /** 列表 diff 结果:cache = 新列表缓存。 */
2436
- interface EssenceDiffResult {
2437
- cache: Map<number, EssenceCacheEntry>;
2438
- /** 新增(is_set=true);operator = add_digest_uin,sender = sender_uin。 */
2439
- added: EssenceAddedItem[];
2440
- /** 移除(is_set=false;移除者不可从列表得知,operator 省略)。 */
2441
- removed: number[];
2442
- }
2443
- /** diff 新增条目。 */
2444
- interface EssenceAddedItem {
2445
- messageSeq: number;
2446
- operatorUin: string | null;
2447
- senderUin: string | null;
2448
- addDigestTime: number | null;
2449
- }
2450
- /**
2451
- * 精华列表 diff:prev 缺省(基线未建立)时只建缓存不产出事件——
2452
- * 首个变更事件只做基线,避免全量首推被误报为「逐条加精」。
2453
- */
2454
- export declare function diffEssenceList(prev: ReadonlyMap<number, EssenceCacheEntry> | undefined, items: readonly EssenceMsgItem[]): EssenceDiffResult;
2455
- /** 精华列表同步依赖(拉取 + 广播回调;事件翻译归协议层)。 */
2456
- interface EssenceListSyncDeps {
2457
- /** 全量精华列表拉取(WebApi.getEssenceMsgList)。 */
2458
- fetchList: (groupCode: string) => Promise<EssenceMsgItem[]>;
2459
- /** diff 新增项广播(协议层做事件翻译 + message_id 反查 / 快路径去重)。 */
2460
- onAdded: (groupCode: string, added: readonly EssenceAddedItem[]) => void | Promise<void>;
2461
- /** diff 移除项广播(prev 供 sender 回填)。 */
2462
- onRemoved: (groupCode: string, removed: readonly number[], prev: ReadonlyMap<number, EssenceCacheEntry>) => void | Promise<void>;
2463
- /** 列表拉取失败(串行链不中断,下个触发器继续;缺省静默)。 */
2464
- onFetchError?: (groupCode: string, err: unknown) => void;
2465
- }
2466
- /**
2467
- * 精华列表串行同步器(OB11 / Milky adapter 共用):
2468
- * - 列表缓存(群号 → seq → 条目)+ 串行链——并发回写乱序会把新列表覆盖成旧列表,
2469
- * 732:1 触发器与列表回调共用一条链,谁先到谁触发,diff 幂等 + 串行天然去重;
2470
- * - 基线未建立只建基线不产出事件(避免全量首推被误报为逐条加精)。
2471
- */
2472
- export declare class EssenceListSync {
2473
- private readonly deps;
2474
- private readonly caches;
2475
- private chain;
2476
- constructor(deps: EssenceListSyncDeps);
2477
- /** 入队单群串行同步(拉取 → diff → 广播 → 更新缓存)。 */
2478
- enqueue(groupCode: string): void;
2479
- /** 单群同步:拉取失败走 onFetchError;基线未建立只建缓存。 */
2480
- private sync;
2481
- }
2482
- /** GroupCache 构造参数。 */
2483
- interface GroupCacheOptions {
2484
- /** 群事件通道(GroupBridge 注册原生监听后 emit 到这里)。 */
2485
- channel: GroupEventChannel;
2486
- /** 群 API(惰性回填用)。 */
2487
- groupApi: GroupApi;
2488
- }
2489
- /**
2490
- * 群/成员缓存:事件主动维护 + 查询惰性回填。
2491
- * 只读接口 getGroupDetail / getMembers / getMember / getGroup(列表项)。
2492
- */
2493
- export declare class GroupCache {
2494
- private readonly channel;
2495
- private readonly groupApi;
2496
- /** 群列表项(onGroupListUpdate / getGroupList 回填)。 */
2497
- private readonly groupList;
2498
- /** 群详情(onGroupDetailInfoChange / getGroupInfo 回填)。 */
2499
- private readonly groupDetails;
2500
- /** 群成员:groupCode → (uid → GroupMember)。 */
2501
- private readonly members;
2502
- /**
2503
- * 惰性回填 in-flight 去重。
2504
- *
2505
- * 按返回类型拆成三个精确容器:同 key 并发只拉一次,且取回的值类型由容器
2506
- * 声明(Promise<Group[]> / Promise<GroupDetailInfo> / Promise<GroupMember[]>)
2507
- * 自然推导——不再用 `Promise<unknown>` + `as Promise<T>` 假装泛型。
2508
- */
2509
- private inFlightGroupList;
2510
- private readonly inFlightDetail;
2511
- private readonly inFlightMembers;
2512
- private unsubscribes;
2513
- constructor(opts: GroupCacheOptions);
2514
- /** 订阅群事件通道(幂等)。 */
2515
- register(): void;
2516
- /** 退订事件通道(幂等)。 */
2517
- unregister(): void;
2518
- /** 释放(等价 unregister,幂等)。 */
2519
- dispose(): void;
2520
- /** `using cache = ...` 自动释放。 */
2521
- [Symbol.dispose](): void;
2522
- /** 合并成员到该群缓存(uid → GroupMember)。 */
2523
- private upsertMembers;
2524
- /** 群列表是否已有缓存(同步判断)。 */
2525
- hasGroup(groupCode: string): boolean;
2526
- /**
2527
- * 群列表快照(只读,缓存由 onGroupListUpdate 事件主动维护)。
2528
- * 群列表数据不走原生 getGroupList 返回值(实测仅 { result, errMsg },
2529
- * 列表经事件推送)——协议/IPC 层消费列表一律经此方法。
2530
- */
2531
- listGroups(): Group[];
2532
- /**
2533
- * 群列表快照(缓存为空时主动触发原生刷新,等待事件回填后返回)。
2534
- *
2535
- * 实测(2026-08-08 端到端联调):onGroupListUpdate 仅在登录后首轮同步
2536
- * 推送(MMKV 已有缓存后不再重复推送)——进程内缓存为空时列表读不到。
2537
- * 触发 getGroupList(true) 会重新拉取并推送事件回填缓存。
2538
- * 返回空数组 = 刷新后仍无数据(超时 5s)。
2539
- */
2540
- listGroupsRefreshed(): Promise<Group[]>;
2541
- /**
2542
- * 群列表项(只读;缺失惰性回填 getGroupList)。
2543
- * 返回 undefined 表示群不存在。
2544
- */
2545
- getGroup(groupCode: string): Promise<Group | undefined>;
2546
- /**
2547
- * 群详情(只读;缺失惰性回填 getGroupInfo)。
2548
- * getGroupInfo 恒返回对象(失败抛 KernelError),直接缓存。
2549
- */
2550
- getGroupDetail(groupCode: string): Promise<GroupDetailInfo>;
2551
- /**
2552
- * 群成员列表(只读;缺失惰性回填 getAllMemberList(forceFetch=true))。
2553
- * 返回空数组表示该群无成员(或拉取失败已由 GroupApi 抛 KernelError)。
2554
- */
2555
- getMembers(groupCode: string): Promise<GroupMember[]>;
2556
- /**
2557
- * 群成员(只读;缺失回填:先整群拉取,再按 uid 取;仍无则 getMemberInfo 单查)。
2558
- * 返回 undefined 表示成员不在群。
2559
- */
2560
- getMember(groupCode: string, uid: string): Promise<GroupMember | undefined>;
2561
- /** 读缓存成员(缺失先整群回填一次)。 */
2562
- private getCachedMember;
2563
- /** 惰性回填全量群列表(getGroup 缺失时;并发调用共享同一次拉取)。 */
2564
- private loadGroupList;
2565
- /**
2566
- * 惰性回填并发去重(按返回类型分容器):同 map + key 并发只拉一次。
2567
- * loader 的返回值类型即容器元素类型——取回时由 Promise<T> 自然给出 T,
2568
- * 不需要 `as Promise<T>` 断言。
2569
- */
2570
- private dedupeMap;
2571
- }
2572
2288
  /** 配置文本格式。 */
2573
2289
  type ConfigFormat = "json" | "toml";
2574
2290
  /**
@@ -2861,6 +2577,56 @@ export declare class PathWrapper {
2861
2577
  */
2862
2578
  clearCache(): void;
2863
2579
  }
2580
+ /** 判断未知值是否为非 null、非数组的普通对象 Record。 */
2581
+ export declare function isRecord(val: unknown): val is Record<string, unknown>;
2582
+ /** 判断未知值是否为可调用的函数。 */
2583
+ export declare function isCallable(val: unknown): val is (...args: unknown[]) => unknown;
2584
+ /**
2585
+ * 安全读取任意值上的属性(支持 plain object 及带有原型链的原生 C++ 包装实例 / 函数对象)。
2586
+ */
2587
+ export declare function getOwnProp(val: unknown, key: string): unknown;
2588
+ /** 判断未知值是否为包含指定 string 属性的对象。 */
2589
+ export declare function hasStringProp<K extends string>(val: unknown, key: K): val is Record<K, string> & Record<string, unknown>;
2590
+ /** 判断未知值是否为包含指定有限 number 属性的对象。 */
2591
+ export declare function hasNumberProp<K extends string>(val: unknown, key: K): val is Record<K, number> & Record<string, unknown>;
2592
+ /** 判断未知值是否为包含指定 boolean 属性的对象。 */
2593
+ export declare function hasBooleanProp<K extends string>(val: unknown, key: K): val is Record<K, boolean> & Record<string, unknown>;
2594
+ /**
2595
+ * 判断未知值(对象或原生构造器函数)是否具备指定名称的可调用方法。
2596
+ * 注意:参数类型收窄为 `...args: unknown[]`,支持直接传参或 `.call(target, ...)` 调用。
2597
+ */
2598
+ export declare function hasFunctionProp<K extends string>(val: unknown, key: K): val is Record<K, (...args: unknown[]) => unknown> & Record<string, unknown>;
2599
+ /** `hasFunctionProp` 的语义别名,专用于反射与原生边界探测。 */
2600
+ export declare const hasCallableProp: typeof hasFunctionProp;
2601
+ /**
2602
+ * 判断目标对象/实例是否同时具备一组方法面(Method Surface)。
2603
+ */
2604
+ export declare function hasMethodSurface<const M extends readonly string[]>(val: unknown, methods: M): val is Record<M[number], (...args: unknown[]) => unknown> & Record<string, unknown>;
2605
+ /** 判断未知值是否为包含静态 `.get()` 工厂方法的原生导出项。 */
2606
+ export declare function hasStaticGetter(val: unknown): val is {
2607
+ get: (...args: unknown[]) => unknown;
2608
+ };
2609
+ /** 判断未知值是否为包含静态 `.create()` 工厂方法的原生导出项。 */
2610
+ export declare function hasStaticCreator(val: unknown): val is {
2611
+ create: (...args: unknown[]) => unknown;
2612
+ };
2613
+ /** 判断未知值是否为 Promise-like(具备 `.then` 与 `.catch` 方法)。 */
2614
+ export declare function isPromiseLike(val: unknown): val is Promise<unknown>;
2615
+ /** 从未知异常中安全提取系统错误码(如 ENOENT / ESRCH / EPERM)。 */
2616
+ export declare function getErrorCode(err: unknown): string | undefined;
2617
+ /** 从未知异常中安全提取错误消息文本。 */
2618
+ export declare function getErrorMessage(err: unknown): string;
2619
+ /** 安全解析 JSON 文本并交由类型守卫验证,校验失败或解析抛错均返回 null。 */
2620
+ export declare function parseJsonWithGuard<T>(raw: string, guard: (val: unknown) => val is T): T | null;
2621
+ /**
2622
+ * 校验原生 Kernel Service 实例是否非空且具备要求的核心方法集合。
2623
+ *
2624
+ * 原生 `get*Service()` 在 session 未 init / 句柄失效时可能返回 null、undefined、
2625
+ * 已 `isNull()` 的空句柄或残缺对象——直接断言成 NodeIKernel*Service
2626
+ * 会让调用方在第一次方法调用时炸出裸 TypeError。这里统一在边界拦截:
2627
+ * 空 / 非对象 / isNull() === true / 缺失关键方法一律抛 INVALID_STATE。
2628
+ */
2629
+ export declare function requireKernelService<T extends object>(service: T | null | undefined, serviceName: string, requiredMethods?: readonly (keyof T & string)[]): T;
2864
2630
  /**
2865
2631
  * 等待/延迟工具(通用底层原语,2026-08-08 克隆合并;2026-11 下沉至 infra)
2866
2632
  *
@@ -2871,6 +2637,28 @@ export declare class PathWrapper {
2871
2637
  export declare function waitFor(predicate: () => boolean, timeoutMs: number, intervalMs?: number): Promise<boolean>;
2872
2638
  /** 短延迟。 */
2873
2639
  export declare function sleep(ms: number): Promise<void>;
2640
+ /** NT RawMessage → canonical 元素(与 toSendElements 对称,接收方向)。 */
2641
+ export declare function toCanonicalElements(msg: RawMessage): CanonicalElement[];
2642
+ /** canonical 元素 → NT 发送元素(text/at/face/image/voice/reply 核心 + json ARK 透传)。 */
2643
+ export declare function toSendElements(elements: CanonicalElement[]): SendMessageElement[];
2644
+ /** startNapuketto 的引导环境(由 loader launcher 注入环境变量,boot.cjs 透传)。 */
2645
+ interface BootEnv {
2646
+ /** QQ 版本(如 "9.9.31-49919")。 */
2647
+ qqVersion?: string | undefined;
2648
+ /** 用户数据目录(cfgDir 的父级,用于 desktopPathConfig)。 */
2649
+ dataDir?: string | undefined;
2650
+ /** 数据根(Linux 和调试沙箱下 QQ 数据存放在 `<dataRoot>/nt_qq`)。 */
2651
+ dataRoot?: string | undefined;
2652
+ /** 账号 uin(可选,提供则一步 init+start)。 */
2653
+ selfUin?: string | undefined;
2654
+ /** 账号 uid(可选)。 */
2655
+ selfUid?: string | undefined;
2656
+ /**
2657
+ * wrapper.node 绝对路径(appid 自动解析用:同目录 major.node)。
2658
+ * 缺省回退 `NAPUKETTO_WRAPPER_PATH` 环境变量。
2659
+ */
2660
+ wrapperPath?: string | undefined;
2661
+ }
2874
2662
  /**
2875
2663
  * Electron 进程类型(Node 的 process 类型无此字段)。
2876
2664
  * - "browser":QQ 主进程(V1 模式)
@@ -2900,6 +2688,16 @@ interface QqDataRootOptions {
2900
2688
  * 其余 Windows 场景走官方 API + 默认位置兜底。
2901
2689
  */
2902
2690
  export declare function resolveQqUserDataRoot(exports: WrapperNodeApi, opts?: QqDataRootOptions): string | null;
2691
+ /**
2692
+ * 加载 wrapper.node 原生模块并校验核心导出(自建宿主引导原语,2026-11 从
2693
+ * loader self-host.ts 下沉:原生 `dlopen` 是 kernel 的唯一原生层职责,loader
2694
+ * 只编排流程)。
2695
+ *
2696
+ * @param wrapperPath wrapper.node 绝对路径(QQ 安装目录 / 缓存文件根)
2697
+ * @returns NAPI exports(含 NodeIKernelLoginService 等构造器)
2698
+ * @throws KernelError exports 缺 NodeIKernelLoginService(stub 环境异常)或 dlopen 失败
2699
+ */
2700
+ export declare function dlopenWrapper(wrapperPath: string): WrapperNodeApi;
2903
2701
  /** QQ 版本信息(登录握手用)。 */
2904
2702
  interface QqVersionContext {
2905
2703
  fullVersion: string;
@@ -2927,6 +2725,21 @@ interface WrapperContext {
2927
2725
  /** wrapper.node 绝对路径(BootEnv.wrapperPath 注入;appid 自动解析用)。 */
2928
2726
  wrapperPath?: string | undefined;
2929
2727
  }
2728
+ /** startNapuketto 选项。 */
2729
+ interface StartNapukettoOptions {
2730
+ /** 截获的 wrapper.node NAPI exports(boot.cjs 传入)。 */
2731
+ wrapperExports: WrapperNodeApi;
2732
+ /** 引导环境(版本/数据目录/账号)。 */
2733
+ env?: BootEnv | undefined;
2734
+ /** 覆盖 engine 配置(联调用)。 */
2735
+ engineConfig?: EnginInitDesktopConfig | undefined;
2736
+ /** 覆盖 session 配置(联调用,提供则自动 init+start)。 */
2737
+ sessionConfig?: WrapperSessionInitConfig | undefined;
2738
+ /** QQ 已 init 的 session(boot.cjs 拦截 new 捕获)。 */
2739
+ qqSession?: NodeIQQNTWrapperSession | null | undefined;
2740
+ /** QQ 的 loginService 实例(boot.cjs 拦截 new 捕获)。 */
2741
+ qqLoginService?: unknown;
2742
+ }
2930
2743
  /**
2931
2744
  * 从 loader 截获的 NAPI exports 创建 wrapper 上下文。
2932
2745
  * 在 QQ 主进程内调用(boot.cjs → kernel 入口)。
@@ -2969,49 +2782,6 @@ export declare function startSession(ctx: WrapperContext): void;
2969
2782
  * 返回 WrapperContext;失败抛 KernelError。
2970
2783
  */
2971
2784
  export declare function startNapuketto(options: StartNapukettoOptions): WrapperContext;
2972
- /** startNapuketto 的引导环境(由 loader launcher 注入环境变量,boot.cjs 透传)。 */
2973
- interface BootEnv {
2974
- /** QQ 版本(如 "9.9.31-49919")。 */
2975
- qqVersion?: string | undefined;
2976
- /** 用户数据目录(cfgDir 的父级,用于 desktopPathConfig)。 */
2977
- dataDir?: string | undefined;
2978
- /** 数据根(Linux 和调试沙箱下 QQ 数据存放在 `<dataRoot>/nt_qq`)。 */
2979
- dataRoot?: string | undefined;
2980
- /** 账号 uin(可选,提供则一步 init+start)。 */
2981
- selfUin?: string | undefined;
2982
- /** 账号 uid(可选)。 */
2983
- selfUid?: string | undefined;
2984
- /**
2985
- * wrapper.node 绝对路径(appid 自动解析用:同目录 major.node)。
2986
- * 缺省回退 `NAPUKETTO_WRAPPER_PATH` 环境变量。
2987
- */
2988
- wrapperPath?: string | undefined;
2989
- }
2990
- /** startNapuketto 选项。 */
2991
- interface StartNapukettoOptions {
2992
- /** 截获的 wrapper.node NAPI exports(boot.cjs 传入)。 */
2993
- wrapperExports: WrapperNodeApi;
2994
- /** 引导环境(版本/数据目录/账号)。 */
2995
- env?: BootEnv | undefined;
2996
- /** 覆盖 engine 配置(联调用)。 */
2997
- engineConfig?: EnginInitDesktopConfig | undefined;
2998
- /** 覆盖 session 配置(联调用,提供则自动 init+start)。 */
2999
- sessionConfig?: WrapperSessionInitConfig | undefined;
3000
- /** QQ 已 init 的 session(boot.cjs 拦截 new 捕获)。 */
3001
- qqSession?: NodeIQQNTWrapperSession | null | undefined;
3002
- /** QQ 的 loginService 实例(boot.cjs 拦截 new 捕获)。 */
3003
- qqLoginService?: unknown;
3004
- }
3005
- /**
3006
- * 加载 wrapper.node 原生模块并校验核心导出(自建宿主引导原语,2026-11 从
3007
- * loader self-host.ts 下沉:原生 `dlopen` 是 kernel 的唯一原生层职责,loader
3008
- * 只编排流程)。
3009
- *
3010
- * @param wrapperPath wrapper.node 绝对路径(QQ 安装目录 / 缓存文件根)
3011
- * @returns NAPI exports(含 NodeIKernelLoginService 等构造器)
3012
- * @throws KernelError exports 缺 NodeIKernelLoginService(stub 环境异常)或 dlopen 失败
3013
- */
3014
- export declare function dlopenWrapper(wrapperPath: string): WrapperNodeApi;
3015
2785
  /**
3016
2786
  * 激活自建宿主 O3MiscService 事件分发(三要素之二,V6 实测决定性):
3017
2787
  * 不激活则 getLoginList 永不 resolve(挂起)。listener 用普通对象
@@ -3023,95 +2793,486 @@ export declare function dlopenWrapper(wrapperPath: string): WrapperNodeApi;
3023
2793
  * @returns 是否成功激活
3024
2794
  */
3025
2795
  export declare function activateO3MiscService(wrapperExports: WrapperNodeApi | Record<string, unknown> | undefined): boolean;
3026
- /** 登录结果(QR 或快速登录)。 */
3027
- interface LoginResult {
3028
- uin: string;
3029
- uid: string;
3030
- nick: string;
2796
+ /**
2797
+ * 探测 wrapper 运行时:dump session 方法与各 service 方法名到 JSON。
2798
+ * 返回探测结果对象;同时写文件(NAPUKETTO_CFG_DIR/<file>,默认 napuketto-probe.json)。
2799
+ * 服务枚举逐项增量落盘(persist)——活 session 上原生崩溃时文件保留断点。
2800
+ */
2801
+ export declare function probeRuntime(ctx: WrapperContext, file?: string): Record<string, unknown>;
2802
+ /** 录制事件(JSONL 一行)。 */
2803
+ interface ListenerRecordEvent {
2804
+ /** ISO 时间戳。 */
2805
+ ts: string;
2806
+ /** 服务简称(Msg / Group / …;LoginService 例外,来自 exports 单例)。 */
2807
+ service: string;
2808
+ /** 回调名;陷阱观测用合成事件 `<get>` / `<has>` / `<ownKeys>` / `<registered>`。 */
2809
+ event: string;
2810
+ /** 回调入参(截断序列化)或注册附加信息。 */
2811
+ args: unknown[];
3031
2812
  }
3032
- /** 登录列表项(getLoginList 返回,说明书参考)。 */
3033
- interface LoginAccountInfo {
3034
- uin: string;
3035
- uid?: string | undefined;
3036
- nickName?: string | undefined;
3037
- isQuickLogin?: boolean | undefined;
2813
+ /** 录制结果摘要(bootstrap 日志用)。 */
2814
+ interface ListenerRecordingResult {
2815
+ /** jsonl 产物绝对路径。 */
2816
+ file: string;
2817
+ /** 逐服务注册结果(ok=listenerId / error / null=服务 getter 返回空)。 */
2818
+ registered: Record<string, {
2819
+ ok: boolean;
2820
+ listenerId?: number;
2821
+ error?: string | null;
2822
+ }>;
3038
2823
  }
3039
2824
  /**
3040
- * 等待网络连接就绪(loginService.getMsfStatus() === 3)。
3041
- * 参考 NapCat waitForNetworkConnection 思路(自研实现):快速登录在 QQ 刚拉起、
3042
- * 网络栈未初始化时报 1006511 网络异常——等待 MSF 连接后再重试。
3043
- * @returns 是否在超时前就绪。
2825
+ * 构造万能监听器:Proxy get 陷阱对任意字符串属性返回记录函数(同时记录原生
2826
+ * 查过的名字,即使从未调用);has / ownKeys 也记录(判定原生按名 Get 还是
2827
+ * 枚举发现回调);非字符串键(Symbol,如 util.inspect 触发)放行默认行为。
3044
2828
  */
3045
- export declare function waitForNetworkConnection(ctx: WrapperContext, opts?: {
3046
- timeoutMs?: number;
3047
- }): Promise<boolean>;
3048
- /** 列出历史登录账号(boot.cjs 启动横幅用,「可用快速登录 of QQ」)。 */
3049
- export declare function listLoginAccounts(ctx: WrapperContext): Promise<LoginAccountInfo[]>;
3050
- /** quickLogin 参数(uin 指定账号;timeoutMs 网络就绪等待;quickLoginTimeoutMs 单步超时)。 */
3051
- interface QuickLoginOptions {
3052
- /** 指定快速登录账号(缺省遍历历史列表,优先 isQuickLogin)。 */
3053
- uin?: string | undefined;
3054
- /** 网络就绪等待超时(毫秒,P2-1 既有语义),默认 15s。 */
3055
- timeoutMs?: number | undefined;
3056
- /** 单步快速登录超时(毫秒,T3 挂起兜底),默认 {@link QUICK_LOGIN_TIMEOUT_MS}。 */
3057
- quickLoginTimeoutMs?: number | undefined;
3058
- }
2829
+ export declare function createRecordingListener(service: string, onEvent: (record: ListenerRecordEvent) => void): object;
3059
2830
  /**
3060
- * 快速登录:遍历历史登录列表尝试。
3061
- * P2-1:失败且错误为网络异常(1006511)时,等网络就绪后重试(最多 NETWORK_RETRY_MAX 次)。
3062
- * T3:getLoginList 与每次 quickLoginWithUin 均包超时竞速(默认 20s)——服务端
3063
- * 已有会话时底层 promise 永久挂起,超时按登录失败(「快速登录失败: 快速登录超时」)
3064
- * 抛出,上层 catch/qrFallback 语义自动生效。
2831
+ * 启动 listener 录制:session 十服务 + LoginService(exports 单例)逐服务注册
2832
+ * 万能监听器,JSONL 逐行追加。返回摘要;文件路径写入结果(bootstrap 日志用)。
2833
+ *
2834
+ * ⚠️ 调用时序约束:必须在任何探测(probeRuntime / getMainSession)之前调用——
2835
+ * resolveMainFromStartup 会把空壳主 session 写回 ctx.session(session-resolver.ts),
2836
+ * 空壳的 service getter 函数仍在但调用返回 null(late probe 61/63 null 的根因)。
3065
2837
  */
3066
- export declare function quickLogin(ctx: WrapperContext, opts?: QuickLoginOptions): Promise<LoginResult>;
2838
+ export declare function startListenerRecording(ctx: WrapperContext, file?: string): ListenerRecordingResult;
3067
2839
  /**
3068
- * 等待 QQ 自己完成 session 初始化(framework 复用模式,2026-08-05 修正)。
2840
+ * QQ 数据根路径解析(P2-1,2026-08-06)
3069
2841
  *
3070
- * 背景:QQ 9.9.31 实测——session 由 QQ 主进程自己创建并 init(登录后)。
3071
- * 我们不自己 init(重复 init 断言 "implementation of IQQNTWrapperSession is not valid"),
3072
- * 也不自己 create(登录前 create() 干扰 QQ,实测 QQ 退出 code=0)。
3073
- * 正确做法:等 QQ 的 session 就绪(getMsgService 非 null = 核心 service 已挂载)。
2842
+ * 从 `getNTUserDataInfoConfig()` 的返回值中提取 QQ 真实数据根路径:
2843
+ * worker(utilityProcess)模式下 loginService 是 new 的,commonPath 必须指向
2844
+ * QQ 真实数据路径才能读到历史账号(cli 的 `.napuketto\default` 读不到,
2845
+ * getLoginList 空,P2-1 实测)。
2846
+ *
2847
+ * 返回值形态可能是 JSON 字符串(对象/数组)或纯路径字符串,此处做宽容解析。
3074
2848
  */
3075
- export declare function waitSessionReady(ctx: WrapperContext, opts?: {
3076
- timeoutMs?: number | undefined;
3077
- }): Promise<void>;
3078
- /** 登录连接 + 快速登录(quickLogin 等)已拆到 login-connect.ts(见文件头 re-export)。 */
3079
- /** session 初始化(4 参全为普通 JS 对象,等 init 完成信号)。 */
3080
- export declare function initAndStartSession(ctx: WrapperContext, config: WrapperSessionInitConfig, listener?: NodeIKernelSessionListener, opts?: {
3081
- timeoutMs?: number | undefined;
3082
- }): Promise<void>;
3083
- /** 登录状态。 */
3084
- type LoginState = "idle" | "waiting_scan" | "scanned" | "logged_in" | "failed";
3085
- /** 二维码数据(png base64 + 解码 url)。 */
3086
- interface QrCodeData {
3087
- pngBase64: string;
3088
- qrcodeUrl: string;
2849
+ /**
2850
+ * QQ 全局数据目录(commonPath / desktopGlobalPath = 数据根/nt_qq/global,
2851
+ * HANDOVER-V6 自建宿主三要素之三,p0-kernel-flow 实证)。
2852
+ *
2853
+ * 防御:已含 nt_qq/global 后缀(worker 环境下 getNTUserDataInfoConfig 可能
2854
+ * 返回完整路径)则不重复拼接,避免 `nt_qq/global/nt_qq/global` 错位。
2855
+ */
2856
+ export declare function resolveQqGlobalPath(root: string): string;
2857
+ /**
2858
+ * 复用 QQ 已有 session(P1-4:QQ 已登录,直接拿单例避免重复 init)。
2859
+ * 优先 `NodeIQQNTWrapperSession.get()`;返回 null 时回退 createSession。
2860
+ *
2861
+ * @internal 仅供 probe 诊断参考,请勿在业务装配中直接调用(会写回 ctx.session)。
2862
+ */
2863
+ export declare function getExistingSession(ctx: WrapperContext): NodeIQQNTWrapperSession | null;
2864
+ /**
2865
+ * 复用 QQ 主 session(P1-4 实测链路):
2866
+ * `NodeIQQNTStartupSessionWrapper.create()` → `start()` → `getSessionIdList()`(Map
2867
+ * {nt:"nt_3", gpro:"gpro_3"})→ `NodeIQQNTWrapperSession.getNTWrapperSession("nt_3")`。
2868
+ * 注:实测这些 session 是空壳(核心 service null),真正可用的是 new + init(lifecycle.ts)。
2869
+ *
2870
+ * @internal 仅供 probe 诊断参考,请勿在业务装配中直接调用(纯查询语义,不改写 ctx.session)。
2871
+ */
2872
+ export declare function getMainSession(ctx: WrapperContext): NodeIQQNTWrapperSession | null;
2873
+ /** NAPI 回调占位(方法存在即可被反射调用,无副作用)。 */
2874
+ declare const noop: () => void;
2875
+ /** NodeIGlobalAdapter 实现(engine.initWithDeskTopConfig 第二参)。 */
2876
+ export declare class GlobalAdapter implements NodeIGlobalAdapter {
2877
+ onLog: typeof noop;
2878
+ onGetSrvCalTime: typeof noop;
2879
+ onShowErrUITips: typeof noop;
2880
+ fixPicImgType: typeof noop;
2881
+ getAppSetting: typeof noop;
2882
+ onInstallFinished: typeof noop;
2883
+ onUpdateGeneralFlag: typeof noop;
2884
+ onGetOfflineMsg: typeof noop;
3089
2885
  }
3090
- /** selfInfo(登录成功后填写)。 */
3091
- interface SelfInfo {
3092
- uin: string;
3093
- uid: string;
3094
- nick: string;
2886
+ /** NodeIDependsAdapter 实现(session.init 第二参)。 */
2887
+ export declare class DependsAdapter implements NodeIDependsAdapter {
2888
+ onMSFStatusChange: typeof noop;
2889
+ onMSFSsoError: typeof noop;
2890
+ getGroupCode: typeof noop;
3095
2891
  }
3096
- /** 快速登录项。 */
3097
- interface LoginListItem {
3098
- uin: string;
3099
- uid?: string;
3100
- nickName?: string;
3101
- isQuickLogin?: boolean;
2892
+ /** NodeIDispatcherAdapter 实现(session.init 第三参)。 */
2893
+ export declare class DispatcherAdapter implements NodeIDispatcherAdapter {
2894
+ dispatchRequest: typeof noop;
2895
+ dispatchCall: typeof noop;
2896
+ dispatchCallWithJson: typeof noop;
3102
2897
  }
3103
- /** QR 登录会话(状态机 + 回调订阅)。 */
3104
- export declare class QrLoginSession {
3105
- private readonly loginService;
3106
- private state;
3107
- private listenerId;
3108
- private self;
3109
- private readonly qrCodeHandlers;
3110
- private readonly stateHandlers;
3111
- /** 超时定时器(refresh 后启动,登录成功/失败/stop 清理)。 */
3112
- private timeoutTimer;
3113
- /** 失败原因(超时等,failed 态透出给上层提示文案)。 */
3114
- private failureReasonValue;
2898
+ /** 会话监听器选项。 */
2899
+ interface SessionListenerOptions {
2900
+ /** 事件日志回调(默认静默——boot 阶段事件对用户是噪音;调试时可传回调观察)。 */
2901
+ onEvent?: ((name: string, ...args: unknown[]) => void) | undefined;
2902
+ }
2903
+ /**
2904
+ * 创建会话监听器(默认静默,boot 阶段默认;login 模块接入后可覆盖)。
2905
+ * 回调方法必须存在(NAPI 按方法名反射),但输出与否由调用方决定——
2906
+ * onNTSessionCreate / onOpentelemetryInit 等对用户无信息量,默认不打 stdout。
2907
+ */
2908
+ export declare function createSessionListener(opts?: SessionListenerOptions): NodeIKernelSessionListener;
2909
+ /** 创建登录监听器(占位,登录器接入时填充)。 */
2910
+ export declare function createLoginListener(): KernelLoginListener;
2911
+ /**
2912
+ * 从 major.node 提取 appid(NapCat parseAppidFromMajorV2 的自研等价实现)。
2913
+ * major.node 含 `QQAppId/` 标记后跟数字(腾讯工具链产物,实测确认)。
2914
+ * 返回 null 表示解析失败(调用方应显式报错,不再回退硬编码 appid)。
2915
+ */
2916
+ export declare function parseAppidFromMajor(majorPath: string): string | null;
2917
+ /**
2918
+ * 解析 appid / qua(自研,参考 NapCat QQBasicInfoWrapper 思路但独立实现):
2919
+ * appid 唯一来源 = major.node 提取(实测 9.9.33-51802 = 537376818)。
2920
+ * majorPath 缺省或解析失败时抛 KernelError——不再静默回退过期 appid。
2921
+ * majorPath 传 wrapper.node 同目录 major.node。
2922
+ */
2923
+ export declare function resolveAppidQua(fullVersion: string, majorPath?: string, platform?: PlatformType): {
2924
+ appid: string;
2925
+ qua: string;
2926
+ };
2927
+ /** 生成 engine 桌面配置(wrapper 契约字段)。majorPath 可选(缺失/解析失败会抛错)。 */
2928
+ export declare function buildEngineConfig(fullVersion: string, dataPathGlobal: string, majorPath?: string, platform?: PlatformType): EnginInitDesktopConfig;
2929
+ /** 生成登录初始化配置(externalVersion: false 与 NapCat 同款,扫码兼容关键)。 */
2930
+ export declare function buildLoginConfig(appid: string, fullVersion: string, commonPath: string): Record<string, unknown>;
2931
+ /** buildSessionConfig 参数。 */
2932
+ interface SessionConfigOptions {
2933
+ appid: string;
2934
+ fullVersion: string;
2935
+ selfUin: string;
2936
+ selfUid: string;
2937
+ accountPath: string;
2938
+ downloadPath: string;
2939
+ /** 设备指纹 guid(来自 loginService.getMachineGuid();缺省空串)。 */
2940
+ machineGuid?: string | undefined;
2941
+ /** 平台(缺省按 process.platform 探测;测试/联调可显式覆盖)。 */
2942
+ platform?: PlatformType | undefined;
2943
+ }
2944
+ /** 生成 session 初始化配置(登录成功后调用)。 */
2945
+ export declare function buildSessionConfig(options: SessionConfigOptions): WrapperSessionInitConfig;
2946
+ /**
2947
+ * 读取设备指纹 guid(wrapper.node 字符串分析实证,2026-08-12):
2948
+ * NodeIKernelLoginService::getMachineGuid(0 参,返回机器 GUID 字符串)。
2949
+ * 无 getMachineId 方法——TODO 里的方法名不存在,等价方法是 getMachineGuid。
2950
+ * 失败(无该方法 / 调用抛错 / 返回值非字符串)兜底空串。
2951
+ */
2952
+ export declare function readMachineGuid(loginService: unknown): string;
2953
+ /**
2954
+ * QQ 安装目录探测(ADR-018)
2955
+ *
2956
+ * wrapper.node 路径随 QQ 版本变化:`<安装目录>/versions/<版本>/resources/app/wrapper.node`。
2957
+ * 加载前必须知道版本(登录握手参数 appid/qua 与版本强相关)。
2958
+ *
2959
+ * 已实测确认(2026-08-05,QQ 9.9.31-49919):
2960
+ * - 目录结构:versions/<9.9.31-49919>/resources/app/wrapper.node
2961
+ * - 版本信息在 versions/<版本>/resources/app/package.json(name=qq-chat / version / buildVersion)
2962
+ * - wrapper.node 是 C++ ABI 模块(非 N-API),导出 INTSessionShell 等符号
2963
+ */
2964
+ /** 解析 wrapper.node 绝对路径(按 ADR-018 目录约定)。 */
2965
+ export declare function resolveWrapperPath(installDir: string, version: string): string;
2966
+ /**
2967
+ * 探测指定版本信息(校验 wrapper.node 存在)。
2968
+ * 版本号不匹配目录时抛 NOT_FOUND(明确失败而非静默)。
2969
+ */
2970
+ export declare function resolveQQVersion(installDir: string, version: string): QQVersionInfo;
2971
+ /** 扫描 versions 目录,取可加载的版本列表(按目录名倒序,最新在前)。 */
2972
+ export declare function listQQVersions(installDir: string): string[];
2973
+ /** QQ 版本信息。 */
2974
+ interface QqVersionInfo {
2975
+ /** 完整版本号,如 "9.9.31-49919"。 */
2976
+ fullVersion: string;
2977
+ /** 构建号,如 "49919"。 */
2978
+ buildVersion: string;
2979
+ /** wrapper.node 绝对路径。 */
2980
+ wrapperPath: string;
2981
+ /** 登录握手参数(P1 探测脚本产出,暂为空串)。 */
2982
+ appid: string;
2983
+ /** 登录握手参数(P1 探测脚本产出,暂为空串)。 */
2984
+ qua: string;
2985
+ }
2986
+ /** @deprecated 使用 `QqVersionInfo`(缩写大小写统一为 `Qq`)。 */
2987
+ type QQVersionInfo = QqVersionInfo;
2988
+ /** BuddyCache diff 事件 listener(归一化「新增/删除」事件)。 */
2989
+ type BuddyCacheListener = {
2990
+ onBuddyAdded: (entry: BuddyListEntry) => void;
2991
+ onBuddyRemoved: (entry: BuddyListEntry) => void;
2992
+ };
2993
+ /** BuddyCache diff 事件通道(事件名 BuddyCache/onBuddyAdded 等)。 */
2994
+ type BuddyCacheEventChannel = NTEventChannel<BuddyCacheListener, "BuddyCache">;
2995
+ /** BuddyCache 构造参数。 */
2996
+ interface BuddyCacheOptions {
2997
+ /** Buddy 事件通道(FriendBridge 注册原生监听后 emit 到这里)。 */
2998
+ channel: BuddyEventChannel;
2999
+ /** 校准日志(可选:快照形状异常 raw 记录;缺省静默)。 */
3000
+ logger?: {
3001
+ warn(obj: unknown, msg?: string): void;
3002
+ };
3003
+ }
3004
+ /**
3005
+ * 防御性收窄 onBuddyListChange 载荷 → BuddyCategory[](T10 实证形状;
3006
+ * 非数组 / 非对象分类项返回 null,调用方打 raw 日志积累校准数据)。
3007
+ * 分类字段逐项做运行时类型校验并安全构造,缺失项取保守默认值。
3008
+ */
3009
+ export declare function narrowBuddyCategories(arg: unknown): BuddyCategory[] | null;
3010
+ /** 好友缓存:快照维护 + diff 归一化事件。 */
3011
+ export declare class BuddyCache {
3012
+ private readonly channel;
3013
+ private readonly logger;
3014
+ /** diff 归一化事件通道(协议层订阅 friend_add / IPC 转发消费)。 */
3015
+ readonly events: BuddyCacheEventChannel;
3016
+ /** 好友快照(uid → entry,onBuddyListChange 全量维护)。 */
3017
+ private readonly buddies;
3018
+ /** 首帧已建 baseline(此后快照才参与 diff)。 */
3019
+ private bootstrapped;
3020
+ private unsubscribes;
3021
+ constructor(opts: BuddyCacheOptions);
3022
+ /** 订阅 Buddy 事件通道(幂等)。 */
3023
+ register(): void;
3024
+ /** 退订事件通道(幂等)。 */
3025
+ unregister(): void;
3026
+ /** 释放(等价 unregister,幂等)。 */
3027
+ dispose(): void;
3028
+ /** `using cache = ...` 自动释放。 */
3029
+ [Symbol.dispose](): void;
3030
+ /** 应用全量快照:首帧建 baseline,之后 diff 发布归一化事件。 */
3031
+ private applySnapshot;
3032
+ /** 好友快照(只读拷贝)。 */
3033
+ listBuddies(): BuddyListEntry[];
3034
+ /** 单个好友(快照;undefined = 不在缓存)。 */
3035
+ getBuddy(uid: string): BuddyListEntry | undefined;
3036
+ /** 快照是否已建(测试/诊断用)。 */
3037
+ get baselineReady(): boolean;
3038
+ }
3039
+ /** onGroupEssenceListChange 参数 → 群号(录制实证首项字符串;防御收窄)。 */
3040
+ export declare function narrowEssenceGroupArg(arg: unknown): string | null;
3041
+ /** 列表缓存条目:seq → 操作者/发送者 uin(null = 不可得)。 */
3042
+ interface EssenceCacheEntry {
3043
+ /** 加精操作者(add_digest_uin;取消场景无值)。 */
3044
+ operatorUin: string | null;
3045
+ /** 被加精消息发送者(sender_uin;OB11 delete 事件 sender_id 只能从缓存回填)。 */
3046
+ senderUin: string | null;
3047
+ /** 加精时间(add_digest_time 秒级 unix;非正数 → null = 不可得)。 */
3048
+ addDigestTime: number | null;
3049
+ }
3050
+ /** 列表 diff 结果:cache = 新列表缓存。 */
3051
+ interface EssenceDiffResult {
3052
+ cache: Map<number, EssenceCacheEntry>;
3053
+ /** 新增(is_set=true);operator = add_digest_uin,sender = sender_uin。 */
3054
+ added: EssenceAddedItem[];
3055
+ /** 移除(is_set=false;移除者不可从列表得知,operator 省略)。 */
3056
+ removed: number[];
3057
+ }
3058
+ /** diff 新增条目。 */
3059
+ interface EssenceAddedItem {
3060
+ messageSeq: number;
3061
+ operatorUin: string | null;
3062
+ senderUin: string | null;
3063
+ addDigestTime: number | null;
3064
+ }
3065
+ /**
3066
+ * 精华列表 diff:prev 缺省(基线未建立)时只建缓存不产出事件——
3067
+ * 首个变更事件只做基线,避免全量首推被误报为「逐条加精」。
3068
+ */
3069
+ export declare function diffEssenceList(prev: ReadonlyMap<number, EssenceCacheEntry> | undefined, items: readonly EssenceMsgItem[]): EssenceDiffResult;
3070
+ /** 精华列表同步依赖(拉取 + 广播回调;事件翻译归协议层)。 */
3071
+ interface EssenceListSyncDeps {
3072
+ /** 全量精华列表拉取(WebApi.getEssenceMsgList)。 */
3073
+ fetchList: (groupCode: string) => Promise<EssenceMsgItem[]>;
3074
+ /** diff 新增项广播(协议层做事件翻译 + message_id 反查 / 快路径去重)。 */
3075
+ onAdded: (groupCode: string, added: readonly EssenceAddedItem[]) => void | Promise<void>;
3076
+ /** diff 移除项广播(prev 供 sender 回填)。 */
3077
+ onRemoved: (groupCode: string, removed: readonly number[], prev: ReadonlyMap<number, EssenceCacheEntry>) => void | Promise<void>;
3078
+ /** 列表拉取失败(串行链不中断,下个触发器继续;缺省静默)。 */
3079
+ onFetchError?: (groupCode: string, err: unknown) => void;
3080
+ }
3081
+ /**
3082
+ * 精华列表串行同步器(OB11 / Milky adapter 共用):
3083
+ * - 列表缓存(群号 → seq → 条目)+ 串行链——并发回写乱序会把新列表覆盖成旧列表,
3084
+ * 732:1 触发器与列表回调共用一条链,谁先到谁触发,diff 幂等 + 串行天然去重;
3085
+ * - 基线未建立只建基线不产出事件(避免全量首推被误报为逐条加精)。
3086
+ */
3087
+ export declare class EssenceListSync {
3088
+ private readonly deps;
3089
+ private readonly caches;
3090
+ private chain;
3091
+ constructor(deps: EssenceListSyncDeps);
3092
+ /** 入队单群串行同步(拉取 → diff → 广播 → 更新缓存)。 */
3093
+ enqueue(groupCode: string): void;
3094
+ /** 单群同步:拉取失败走 onFetchError;基线未建立只建缓存。 */
3095
+ private sync;
3096
+ }
3097
+ /** GroupCache 构造参数。 */
3098
+ interface GroupCacheOptions {
3099
+ /** 群事件通道(GroupBridge 注册原生监听后 emit 到这里)。 */
3100
+ channel: GroupEventChannel;
3101
+ /** 群 API(惰性回填用)。 */
3102
+ groupApi: GroupApi;
3103
+ }
3104
+ /**
3105
+ * 群/成员缓存:事件主动维护 + 查询惰性回填。
3106
+ * 只读接口 getGroupDetail / getMembers / getMember / getGroup(列表项)。
3107
+ */
3108
+ export declare class GroupCache {
3109
+ private readonly channel;
3110
+ private readonly groupApi;
3111
+ /** 群列表项(onGroupListUpdate / getGroupList 回填)。 */
3112
+ private readonly groupList;
3113
+ /** 群详情(onGroupDetailInfoChange / getGroupInfo 回填)。 */
3114
+ private readonly groupDetails;
3115
+ /** 群成员:groupCode → (uid → GroupMember)。 */
3116
+ private readonly members;
3117
+ /**
3118
+ * 惰性回填 in-flight 去重。
3119
+ *
3120
+ * 按返回类型拆成三个精确容器:同 key 并发只拉一次,且取回的值类型由容器
3121
+ * 声明(Promise<Group[]> / Promise<GroupDetailInfo> / Promise<GroupMember[]>)
3122
+ * 自然推导——不再用 `Promise<unknown>` + `as Promise<T>` 假装泛型。
3123
+ */
3124
+ private inFlightGroupList;
3125
+ private readonly inFlightDetail;
3126
+ private readonly inFlightMembers;
3127
+ private unsubscribes;
3128
+ constructor(opts: GroupCacheOptions);
3129
+ /** 订阅群事件通道(幂等)。 */
3130
+ register(): void;
3131
+ /** 退订事件通道(幂等)。 */
3132
+ unregister(): void;
3133
+ /** 释放(等价 unregister,幂等)。 */
3134
+ dispose(): void;
3135
+ /** `using cache = ...` 自动释放。 */
3136
+ [Symbol.dispose](): void;
3137
+ /** 合并成员到该群缓存(uid → GroupMember)。 */
3138
+ private upsertMembers;
3139
+ /** 群列表是否已有缓存(同步判断)。 */
3140
+ hasGroup(groupCode: string): boolean;
3141
+ /**
3142
+ * 群列表快照(只读,缓存由 onGroupListUpdate 事件主动维护)。
3143
+ * 群列表数据不走原生 getGroupList 返回值(实测仅 { result, errMsg },
3144
+ * 列表经事件推送)——协议/IPC 层消费列表一律经此方法。
3145
+ */
3146
+ listGroups(): Group[];
3147
+ /**
3148
+ * 群列表快照(缓存为空时主动触发原生刷新,等待事件回填后返回)。
3149
+ *
3150
+ * 实测(2026-08-08 端到端联调):onGroupListUpdate 仅在登录后首轮同步
3151
+ * 推送(MMKV 已有缓存后不再重复推送)——进程内缓存为空时列表读不到。
3152
+ * 触发 getGroupList(true) 会重新拉取并推送事件回填缓存。
3153
+ * 返回空数组 = 刷新后仍无数据(超时 5s)。
3154
+ */
3155
+ listGroupsRefreshed(): Promise<Group[]>;
3156
+ /**
3157
+ * 群列表项(只读;缺失惰性回填 getGroupList)。
3158
+ * 返回 undefined 表示群不存在。
3159
+ */
3160
+ getGroup(groupCode: string): Promise<Group | undefined>;
3161
+ /**
3162
+ * 群详情(只读;缺失惰性回填 getGroupInfo)。
3163
+ * getGroupInfo 恒返回对象(失败抛 KernelError),直接缓存。
3164
+ */
3165
+ getGroupDetail(groupCode: string): Promise<GroupDetailInfo>;
3166
+ /**
3167
+ * 群成员列表(只读;缺失惰性回填 getAllMemberList(forceFetch=true))。
3168
+ * 返回空数组表示该群无成员(或拉取失败已由 GroupApi 抛 KernelError)。
3169
+ */
3170
+ getMembers(groupCode: string): Promise<GroupMember[]>;
3171
+ /**
3172
+ * 群成员(只读;缺失回填:先整群拉取,再按 uid 取;仍无则 getMemberInfo 单查)。
3173
+ * 返回 undefined 表示成员不在群。
3174
+ */
3175
+ getMember(groupCode: string, uid: string): Promise<GroupMember | undefined>;
3176
+ /** 读缓存成员(缺失先整群回填一次)。 */
3177
+ private getCachedMember;
3178
+ /** 惰性回填全量群列表(getGroup 缺失时;并发调用共享同一次拉取)。 */
3179
+ private loadGroupList;
3180
+ /**
3181
+ * 惰性回填并发去重(按返回类型分容器):同 map + key 并发只拉一次。
3182
+ * loader 的返回值类型即容器元素类型——取回时由 Promise<T> 自然给出 T,
3183
+ * 不需要 `as Promise<T>` 断言。
3184
+ */
3185
+ private dedupeMap;
3186
+ }
3187
+ /**
3188
+ * 等待网络连接就绪(loginService.getMsfStatus() === 3)。
3189
+ * 参考 NapCat waitForNetworkConnection 思路(自研实现):快速登录在 QQ 刚拉起、
3190
+ * 网络栈未初始化时报 1006511 网络异常——等待 MSF 连接后再重试。
3191
+ * @returns 是否在超时前就绪。
3192
+ */
3193
+ export declare function waitForNetworkConnection(ctx: WrapperContext, opts?: {
3194
+ timeoutMs?: number;
3195
+ }): Promise<boolean>;
3196
+ /** 登录结果(QR 或快速登录)。 */
3197
+ interface LoginResult {
3198
+ uin: string;
3199
+ uid: string;
3200
+ nick: string;
3201
+ }
3202
+ /** 登录列表项(getLoginList 返回,说明书参考)。 */
3203
+ interface LoginAccountInfo {
3204
+ uin: string;
3205
+ uid?: string | undefined;
3206
+ nickName?: string | undefined;
3207
+ isQuickLogin?: boolean | undefined;
3208
+ }
3209
+ /** 列出历史登录账号(boot.cjs 启动横幅用,「可用快速登录 of QQ」)。 */
3210
+ export declare function listLoginAccounts(ctx: WrapperContext): Promise<LoginAccountInfo[]>;
3211
+ /** quickLogin 参数(uin 指定账号;timeoutMs 网络就绪等待;quickLoginTimeoutMs 单步超时)。 */
3212
+ interface QuickLoginOptions {
3213
+ /** 指定快速登录账号(缺省遍历历史列表,优先 isQuickLogin)。 */
3214
+ uin?: string | undefined;
3215
+ /** 网络就绪等待超时(毫秒,P2-1 既有语义),默认 15s。 */
3216
+ timeoutMs?: number | undefined;
3217
+ /** 单步快速登录超时(毫秒,T3 挂起兜底),默认 {@link QUICK_LOGIN_TIMEOUT_MS}。 */
3218
+ quickLoginTimeoutMs?: number | undefined;
3219
+ }
3220
+ /**
3221
+ * 快速登录:遍历历史登录列表尝试。
3222
+ * P2-1:失败且错误为网络异常(1006511)时,等网络就绪后重试(最多 NETWORK_RETRY_MAX 次)。
3223
+ * T3:getLoginList 与每次 quickLoginWithUin 均包超时竞速(默认 20s)——服务端
3224
+ * 已有会话时底层 promise 永久挂起,超时按登录失败(「快速登录失败: 快速登录超时」)
3225
+ * 抛出,上层 catch/qrFallback 语义自动生效。
3226
+ */
3227
+ export declare function quickLogin(ctx: WrapperContext, opts?: QuickLoginOptions): Promise<LoginResult>;
3228
+ /**
3229
+ * 等待 QQ 自己完成 session 初始化(framework 复用模式,2026-08-05 修正)。
3230
+ *
3231
+ * 背景:QQ 9.9.31 实测——session 由 QQ 主进程自己创建并 init(登录后)。
3232
+ * 我们不自己 init(重复 init 断言 "implementation of IQQNTWrapperSession is not valid"),
3233
+ * 也不自己 create(登录前 create() 干扰 QQ,实测 QQ 退出 code=0)。
3234
+ * 正确做法:等 QQ 的 session 就绪(getMsgService 非 null = 核心 service 已挂载)。
3235
+ */
3236
+ export declare function waitSessionReady(ctx: WrapperContext, opts?: {
3237
+ timeoutMs?: number | undefined;
3238
+ }): Promise<void>;
3239
+ /** 登录连接 + 快速登录(quickLogin 等)已拆到 msf-connection.ts / quick-login.ts(见文件头 re-export)。 */
3240
+ /** session 初始化(4 参全为普通 JS 对象,等 init 完成信号)。 */
3241
+ export declare function initAndStartSession(ctx: WrapperContext, config: WrapperSessionInitConfig, listener?: NodeIKernelSessionListener, opts?: {
3242
+ timeoutMs?: number | undefined;
3243
+ }): Promise<void>;
3244
+ /** 登录状态。 */
3245
+ type LoginState = "idle" | "waiting_scan" | "scanned" | "logged_in" | "failed";
3246
+ /** 二维码数据(png base64 + 解码 url)。 */
3247
+ interface QrCodeData {
3248
+ pngBase64: string;
3249
+ qrcodeUrl: string;
3250
+ }
3251
+ /** selfInfo(登录成功后填写)。 */
3252
+ interface SelfInfo {
3253
+ uin: string;
3254
+ uid: string;
3255
+ nick: string;
3256
+ }
3257
+ /** 快速登录项。 */
3258
+ interface LoginListItem {
3259
+ uin: string;
3260
+ uid?: string;
3261
+ nickName?: string;
3262
+ isQuickLogin?: boolean;
3263
+ }
3264
+ /** QR 登录会话(状态机 + 回调订阅)。 */
3265
+ export declare class QrLoginSession {
3266
+ private readonly loginService;
3267
+ private state;
3268
+ private listenerId;
3269
+ private self;
3270
+ private readonly qrCodeHandlers;
3271
+ private readonly stateHandlers;
3272
+ /** 超时定时器(refresh 后启动,登录成功/失败/stop 清理)。 */
3273
+ private timeoutTimer;
3274
+ /** 失败原因(超时等,failed 态透出给上层提示文案)。 */
3275
+ private failureReasonValue;
3115
3276
  /** 超时上限(毫秒,默认 QR_LOGIN_TIMEOUT_MS)。 */
3116
3277
  private readonly timeoutMs;
3117
3278
  constructor(loginService: unknown, options?: {
@@ -3169,84 +3330,6 @@ interface CoreContext {
3169
3330
  }
3170
3331
  /** 创建装配根(初始 wrapper/login 为 null)。 */
3171
3332
  export declare function createCoreContext(opts: CoreContextOptions): CoreContext;
3172
- /** 运行时装配参数。 */
3173
- interface KernelRuntimeOptions {
3174
- /** 已 init 的 wrapper session(getMsgService 等非空)。 */
3175
- session: NodeIQQNTWrapperSession;
3176
- /** 登录结果(WebApi getCookies 的 uin 来源;未传时用空串)。 */
3177
- login?: LoginResult | null | undefined;
3178
- /** wrapper.node exports(MsgApi 富媒体 copyFile 用 NodeQQNTWrapperUtil)。 */
3179
- wrapperExports?: WrapperNodeApi | Record<string, unknown> | undefined;
3180
- /** QQ loginService(传入时装配 LoginBridge,提供 Login 事件通道数据)。 */
3181
- loginService?: unknown;
3182
- /** 校准日志出口(在线状态上报失败等;缺省静默)。 */
3183
- logger?: {
3184
- warn(obj: unknown, msg?: string): void;
3185
- } | undefined;
3186
- /** 是否自动注册全部原生事件桥与缓存(默认 true)。 */
3187
- autoRegister?: boolean | undefined;
3188
- /** 是否自动上报在线状态 status=10 以开启服务端实时消息推送(默认 false;自建宿主传 true)。 */
3189
- reportOnlineStatus?: boolean | undefined;
3190
- }
3191
- /** 内核服务聚合(createKernelRuntime 产物)。 */
3192
- interface KernelRuntime {
3193
- readonly msgChannel: MsgEventChannel;
3194
- readonly groupChannel: GroupEventChannel;
3195
- readonly friendChannel: BuddyEventChannel;
3196
- readonly recentContactChannel: RecentContactEventChannel;
3197
- readonly loginChannel: LoginEventChannel;
3198
- readonly msgBridge: MsgBridge;
3199
- readonly groupBridge: GroupBridge;
3200
- readonly friendBridge: FriendBridge;
3201
- /** getRecentContactService 不存在/不可用时为 null(跳过注册)。 */
3202
- readonly recentContactBridge: RecentContactBridge | null;
3203
- /** 未传 loginService 时为 null(跳过注册)。 */
3204
- readonly loginBridge: LoginBridge | null;
3205
- readonly msgApi: MsgApi;
3206
- readonly groupApi: GroupApi;
3207
- readonly friendApi: FriendApi;
3208
- readonly groupNotifyApi: GroupNotifyApi;
3209
- readonly ticketApi: TicketApi;
3210
- readonly richMediaApi: RichMediaApi;
3211
- readonly flashTransferApi: FlashTransferApi;
3212
- readonly recentContactApi: RecentContactApi;
3213
- readonly profileApi: ProfileApi;
3214
- readonly profileLikeApi: ProfileLikeApi;
3215
- readonly webApi: WebApi;
3216
- readonly groupCache: GroupCache;
3217
- readonly buddyCache: BuddyCache;
3218
- /** 一键清理(幂等):桥/缓存 unregister + 通道 dispose。 */
3219
- dispose(): void;
3220
- /** `using runtime = ...` 自动清理。 */
3221
- [Symbol.dispose](): void;
3222
- }
3223
- /**
3224
- * 装配内核运行时(同步;API 构造失败即抛 KernelError)。
3225
- *
3226
- * @param opts 装配参数(session 必填)
3227
- * @returns 聚合了全部通道/桥/API/缓存的服务对象
3228
- */
3229
- export declare function createKernelRuntime(opts: KernelRuntimeOptions): KernelRuntime;
3230
- interface NapukettoCoreOptions {
3231
- /** 数据根 / 账号(透传给 PathWrapper,见 ADR-016)。 */
3232
- paths?: PathOptions | undefined;
3233
- /** 日志级别,默认 info。 */
3234
- logLevel?: LogLevel | undefined;
3235
- /** 文件日志路径;不传则默认 `logs/napuketto.log`(父目录自动创建)。 */
3236
- logFile?: string | undefined;
3237
- /** 文件目的地级别(可低于控制台级别;缺省同 logLevel)。 */
3238
- logFileLevel?: LogLevel | undefined;
3239
- /** 是否输出 console,默认 true。 */
3240
- consoleLog?: boolean | undefined;
3241
- /** 控制台格式(缺省按 TTY 自动:TTY pretty / pipe single-line)。 */
3242
- logFormat?: LogFormat | undefined;
3243
- /** 时间戳渲染模式,默认 local。 */
3244
- logTimestamp?: TimestampMode | undefined;
3245
- /** 控制台颜色(缺省自动)。 */
3246
- logColorize?: boolean | undefined;
3247
- /** 账号标注(记录结构化 account 字段;快速登录目标账号,登录前已知时传入)。 */
3248
- account?: string | undefined;
3249
- }
3250
3333
  /**
3251
3334
  * 登录进度(IPC 子进程模式经 onLoginProgress 转发;koishi 插件展示二维码/状态用)。
3252
3335
  *
@@ -3280,6 +3363,27 @@ type LoginProgress = {
3280
3363
  selfInfo?: undefined;
3281
3364
  message: string;
3282
3365
  };
3366
+ /** 装配选项(paths + logger)。 */
3367
+ interface NapukettoCoreOptions {
3368
+ /** 数据根 / 账号(透传给 PathWrapper,见 ADR-016)。 */
3369
+ paths?: PathOptions | undefined;
3370
+ /** 日志级别,默认 info。 */
3371
+ logLevel?: LogLevel | undefined;
3372
+ /** 文件日志路径;不传则默认 `logs/napuketto.log`(父目录自动创建)。 */
3373
+ logFile?: string | undefined;
3374
+ /** 文件目的地级别(可低于控制台级别;缺省同 logLevel)。 */
3375
+ logFileLevel?: LogLevel | undefined;
3376
+ /** 是否输出 console,默认 true。 */
3377
+ consoleLog?: boolean | undefined;
3378
+ /** 控制台格式(缺省按 TTY 自动:TTY pretty / pipe single-line)。 */
3379
+ logFormat?: LogFormat | undefined;
3380
+ /** 时间戳渲染模式,默认 local。 */
3381
+ logTimestamp?: TimestampMode | undefined;
3382
+ /** 控制台颜色(缺省自动)。 */
3383
+ logColorize?: boolean | undefined;
3384
+ /** 账号标注(记录结构化 account 字段;快速登录目标账号,登录前已知时传入)。 */
3385
+ account?: string | undefined;
3386
+ }
3283
3387
  /** login 参数。 */
3284
3388
  interface CoreLoginOptions {
3285
3389
  /**
@@ -3316,6 +3420,64 @@ interface CoreLoginOptions {
3316
3420
  */
3317
3421
  activateSession?: boolean | undefined;
3318
3422
  }
3423
+ /** 运行时装配参数。 */
3424
+ interface KernelRuntimeOptions {
3425
+ /** 已 init 的 wrapper session(getMsgService 等非空)。 */
3426
+ session: NodeIQQNTWrapperSession;
3427
+ /** 登录结果(WebApi getCookies 的 uin 来源;未传时用空串)。 */
3428
+ login?: LoginResult | null | undefined;
3429
+ /** wrapper.node exports(MsgApi 富媒体 copyFile 用 NodeQQNTWrapperUtil)。 */
3430
+ wrapperExports?: WrapperNodeApi | Record<string, unknown> | undefined;
3431
+ /** QQ loginService(传入时装配 LoginBridge,提供 Login 事件通道数据)。 */
3432
+ loginService?: unknown;
3433
+ /** 校准日志出口(在线状态上报失败等;缺省静默)。 */
3434
+ logger?: {
3435
+ warn(obj: unknown, msg?: string): void;
3436
+ } | undefined;
3437
+ /** 是否自动注册全部原生事件桥与缓存(默认 true)。 */
3438
+ autoRegister?: boolean | undefined;
3439
+ /** 是否自动上报在线状态 status=10 以开启服务端实时消息推送(默认 false;自建宿主传 true)。 */
3440
+ reportOnlineStatus?: boolean | undefined;
3441
+ }
3442
+ /** 内核服务聚合(createKernelRuntime 产物)。 */
3443
+ interface KernelRuntime {
3444
+ readonly msgChannel: MsgEventChannel;
3445
+ readonly groupChannel: GroupEventChannel;
3446
+ readonly friendChannel: BuddyEventChannel;
3447
+ readonly recentContactChannel: RecentContactEventChannel;
3448
+ readonly loginChannel: LoginEventChannel;
3449
+ readonly msgBridge: MsgBridge;
3450
+ readonly groupBridge: GroupBridge;
3451
+ readonly friendBridge: FriendBridge;
3452
+ /** getRecentContactService 不存在/不可用时为 null(跳过注册)。 */
3453
+ readonly recentContactBridge: RecentContactBridge | null;
3454
+ /** 未传 loginService 时为 null(跳过注册)。 */
3455
+ readonly loginBridge: LoginBridge | null;
3456
+ readonly msgApi: MsgApi;
3457
+ readonly groupApi: GroupApi;
3458
+ readonly friendApi: FriendApi;
3459
+ readonly groupNotifyApi: GroupNotifyApi;
3460
+ readonly ticketApi: TicketApi;
3461
+ readonly richMediaApi: RichMediaApi;
3462
+ readonly flashTransferApi: FlashTransferApi;
3463
+ readonly recentContactApi: RecentContactApi;
3464
+ readonly profileApi: ProfileApi;
3465
+ readonly profileLikeApi: ProfileLikeApi;
3466
+ readonly webApi: WebApi;
3467
+ readonly groupCache: GroupCache;
3468
+ readonly buddyCache: BuddyCache;
3469
+ /** 一键清理(幂等):桥/缓存 unregister + 通道 dispose。 */
3470
+ dispose(): void;
3471
+ /** `using runtime = ...` 自动清理。 */
3472
+ [Symbol.dispose](): void;
3473
+ }
3474
+ /**
3475
+ * 装配内核运行时(同步;API 构造失败即抛 KernelError)。
3476
+ *
3477
+ * @param opts 装配参数(session 必填)
3478
+ * @returns 聚合了全部通道/桥/API/缓存的服务对象
3479
+ */
3480
+ export declare function createKernelRuntime(opts: KernelRuntimeOptions): KernelRuntime;
3319
3481
  /**
3320
3482
  * 核心装配器:持有 CoreContext,负责启动/停止编排。
3321
3483
  * 无全局单例(ADR-015 推论)——每账号每进程实例化一份。
@@ -3378,15 +3540,6 @@ export declare class NapukettoCore {
3378
3540
  createRuntime(opts?: Omit<KernelRuntimeOptions, "session" | "login" | "wrapperExports">): KernelRuntime;
3379
3541
  /** 快速登录优先,失败按 qrFallback 决定是否回退 QR(QR 应直接出码,见 loginByQr 注)。 */
3380
3542
  private loginQuickFirst;
3381
- /**
3382
- * loginService.initConfig(worker/自建宿主需指定 QQ 真实数据路径)。
3383
- * worker(utilityProcess)模式 + 自建宿主(标准 node)下 loginService 是
3384
- * new 的,commonPath 必须指向 QQ 真实数据目录(数据根/nt_qq/global,
3385
- * HANDOVER-V6 三要素之三)才能读到历史账号——cli 的 `.napuketto\default`
3386
- * 读不到(getLoginList 空,P2-1 实测 2026-08-06)。
3387
- * QQ 主进程(V1)模式 QQ 自己 initConfig 过正确路径,无需解析。
3388
- */
3389
- private initLoginConfig;
3390
3543
  /**
3391
3544
  * 替换当前 session(登录后 Proxy 捕获的 QQ 新实例替换自己 create 的无效实例)。
3392
3545
  * 在 QQ 主进程内由 boot.cjs 调用(登录成功后)。
@@ -3399,10 +3552,6 @@ export declare class NapukettoCore {
3399
3552
  refreshQr(): boolean;
3400
3553
  /** QR 登录:QrLoginSession 状态机 + 二维码写独占缓存目录(无 UI,cli 可打印路径)。 */
3401
3554
  private loginByQr;
3402
- /** 订阅 QR 进度:二维码写盘 + 状态机经 onLoginProgress 转发。 */
3403
- private subscribeQrProgress;
3404
- /** QR 状态转发:日志 + onLoginProgress(failed 附 failureReason)。 */
3405
- private forwardQrState;
3406
3555
  /**
3407
3556
  * 停止:幂等清理 QR 会话 + 已装配的运行时服务(桥/缓存/通道)后日志收尾。
3408
3557
  * 重复调用直接返回(宿主关停钩子可能同时触发多次)。
@@ -3415,246 +3564,4 @@ export declare class NapukettoCore {
3415
3564
  /** `using core = ...` 自动释放。 */
3416
3565
  [Symbol.dispose](): void;
3417
3566
  }
3418
- /** 判断未知值是否为非 null、非数组的普通对象 Record。 */
3419
- export declare function isRecord(val: unknown): val is Record<string, unknown>;
3420
- /** 判断未知值是否为可调用的函数。 */
3421
- export declare function isCallable(val: unknown): val is (...args: unknown[]) => unknown;
3422
- /**
3423
- * 安全读取任意值上的属性(支持 plain object 及带有原型链的原生 C++ 包装实例 / 函数对象)。
3424
- */
3425
- export declare function getOwnProp(val: unknown, key: string): unknown;
3426
- /** 判断未知值是否为包含指定 string 属性的对象。 */
3427
- export declare function hasStringProp<K extends string>(val: unknown, key: K): val is Record<K, string> & Record<string, unknown>;
3428
- /** 判断未知值是否为包含指定有限 number 属性的对象。 */
3429
- export declare function hasNumberProp<K extends string>(val: unknown, key: K): val is Record<K, number> & Record<string, unknown>;
3430
- /** 判断未知值是否为包含指定 boolean 属性的对象。 */
3431
- export declare function hasBooleanProp<K extends string>(val: unknown, key: K): val is Record<K, boolean> & Record<string, unknown>;
3432
- /**
3433
- * 判断未知值(对象或原生构造器函数)是否具备指定名称的可调用方法。
3434
- * 注意:参数类型收窄为 `...args: unknown[]`,支持直接传参或 `.call(target, ...)` 调用。
3435
- */
3436
- export declare function hasFunctionProp<K extends string>(val: unknown, key: K): val is Record<K, (...args: unknown[]) => unknown> & Record<string, unknown>;
3437
- /** `hasFunctionProp` 的语义别名,专用于反射与原生边界探测。 */
3438
- export declare const hasCallableProp: typeof hasFunctionProp;
3439
- /**
3440
- * 判断目标对象/实例是否同时具备一组方法面(Method Surface)。
3441
- */
3442
- export declare function hasMethodSurface<const M extends readonly string[]>(val: unknown, methods: M): val is Record<M[number], (...args: unknown[]) => unknown> & Record<string, unknown>;
3443
- /** 判断未知值是否为包含静态 `.get()` 工厂方法的原生导出项。 */
3444
- export declare function hasStaticGetter(val: unknown): val is {
3445
- get: (...args: unknown[]) => unknown;
3446
- };
3447
- /** 判断未知值是否为包含静态 `.create()` 工厂方法的原生导出项。 */
3448
- export declare function hasStaticCreator(val: unknown): val is {
3449
- create: (...args: unknown[]) => unknown;
3450
- };
3451
- /** 判断未知值是否为 Promise-like(具备 `.then` 与 `.catch` 方法)。 */
3452
- export declare function isPromiseLike(val: unknown): val is Promise<unknown>;
3453
- /** 从未知异常中安全提取系统错误码(如 ENOENT / ESRCH / EPERM)。 */
3454
- export declare function getErrorCode(err: unknown): string | undefined;
3455
- /** 从未知异常中安全提取错误消息文本。 */
3456
- export declare function getErrorMessage(err: unknown): string;
3457
- /** 安全解析 JSON 文本并交由类型守卫验证,校验失败或解析抛错均返回 null。 */
3458
- export declare function parseJsonWithGuard<T>(raw: string, guard: (val: unknown) => val is T): T | null;
3459
- /**
3460
- * 校验原生 Kernel Service 实例是否非空且具备要求的核心方法集合。
3461
- *
3462
- * 原生 `get*Service()` 在 session 未 init / 句柄失效时可能返回 null、undefined、
3463
- * 已 `isNull()` 的空句柄或残缺对象——直接断言成 NodeIKernel*Service
3464
- * 会让调用方在第一次方法调用时炸出裸 TypeError。这里统一在边界拦截:
3465
- * 空 / 非对象 / isNull() === true / 缺失关键方法一律抛 INVALID_STATE。
3466
- */
3467
- export declare function requireKernelService<T extends object>(service: T | null | undefined, serviceName: string, requiredMethods?: readonly (keyof T & string)[]): T;
3468
- /**
3469
- * 探测 wrapper 运行时:dump session 方法与各 service 方法名到 JSON。
3470
- * 返回探测结果对象;同时写文件(NAPUKETTO_CFG_DIR/<file>,默认 napuketto-probe.json)。
3471
- * 服务枚举逐项增量落盘(persist)——活 session 上原生崩溃时文件保留断点。
3472
- */
3473
- export declare function probeRuntime(ctx: WrapperContext, file?: string): Record<string, unknown>;
3474
- /** 录制事件(JSONL 一行)。 */
3475
- interface ListenerRecordEvent {
3476
- /** ISO 时间戳。 */
3477
- ts: string;
3478
- /** 服务简称(Msg / Group / …;LoginService 例外,来自 exports 单例)。 */
3479
- service: string;
3480
- /** 回调名;陷阱观测用合成事件 `<get>` / `<has>` / `<ownKeys>` / `<registered>`。 */
3481
- event: string;
3482
- /** 回调入参(截断序列化)或注册附加信息。 */
3483
- args: unknown[];
3484
- }
3485
- /** 录制结果摘要(bootstrap 日志用)。 */
3486
- interface ListenerRecordingResult {
3487
- /** jsonl 产物绝对路径。 */
3488
- file: string;
3489
- /** 逐服务注册结果(ok=listenerId / error / null=服务 getter 返回空)。 */
3490
- registered: Record<string, {
3491
- ok: boolean;
3492
- listenerId?: number;
3493
- error?: string | null;
3494
- }>;
3495
- }
3496
- /**
3497
- * 构造万能监听器:Proxy get 陷阱对任意字符串属性返回记录函数(同时记录原生
3498
- * 查过的名字,即使从未调用);has / ownKeys 也记录(判定原生按名 Get 还是
3499
- * 枚举发现回调);非字符串键(Symbol,如 util.inspect 触发)放行默认行为。
3500
- */
3501
- export declare function createRecordingListener(service: string, onEvent: (record: ListenerRecordEvent) => void): object;
3502
- /**
3503
- * 启动 listener 录制:session 十服务 + LoginService(exports 单例)逐服务注册
3504
- * 万能监听器,JSONL 逐行追加。返回摘要;文件路径写入结果(bootstrap 日志用)。
3505
- *
3506
- * ⚠️ 调用时序约束:必须在任何探测(probeRuntime / getMainSession)之前调用——
3507
- * resolveMainFromStartup 会把空壳主 session 写回 ctx.session(session-resolver.ts),
3508
- * 空壳的 service getter 函数仍在但调用返回 null(late probe 61/63 null 的根因)。
3509
- */
3510
- export declare function startListenerRecording(ctx: WrapperContext, file?: string): ListenerRecordingResult;
3511
- /**
3512
- * QQ 数据根路径解析(P2-1,2026-08-06)
3513
- *
3514
- * 从 `getNTUserDataInfoConfig()` 的返回值中提取 QQ 真实数据根路径:
3515
- * worker(utilityProcess)模式下 loginService 是 new 的,commonPath 必须指向
3516
- * QQ 真实数据路径才能读到历史账号(cli 的 `.napuketto\default` 读不到,
3517
- * getLoginList 空,P2-1 实测)。
3518
- *
3519
- * 返回值形态可能是 JSON 字符串(对象/数组)或纯路径字符串,此处做宽容解析。
3520
- */
3521
- /**
3522
- * QQ 全局数据目录(commonPath / desktopGlobalPath = 数据根/nt_qq/global,
3523
- * HANDOVER-V6 自建宿主三要素之三,p0-kernel-flow 实证)。
3524
- *
3525
- * 防御:已含 nt_qq/global 后缀(worker 环境下 getNTUserDataInfoConfig 可能
3526
- * 返回完整路径)则不重复拼接,避免 `nt_qq/global/nt_qq/global` 错位。
3527
- */
3528
- export declare function resolveQqGlobalPath(root: string): string;
3529
- /**
3530
- * 复用 QQ 已有 session(P1-4:QQ 已登录,直接拿单例避免重复 init)。
3531
- * 优先 `NodeIQQNTWrapperSession.get()`;返回 null 时回退 createSession。
3532
- *
3533
- * @internal 仅供 probe 诊断参考,请勿在业务装配中直接调用(会写回 ctx.session)。
3534
- */
3535
- export declare function getExistingSession(ctx: WrapperContext): NodeIQQNTWrapperSession | null;
3536
- /**
3537
- * 复用 QQ 主 session(P1-4 实测链路):
3538
- * `NodeIQQNTStartupSessionWrapper.create()` → `start()` → `getSessionIdList()`(Map
3539
- * {nt:"nt_3", gpro:"gpro_3"})→ `NodeIQQNTWrapperSession.getNTWrapperSession("nt_3")`。
3540
- * 注:实测这些 session 是空壳(核心 service null),真正可用的是 new + init(lifecycle.ts)。
3541
- *
3542
- * @internal 仅供 probe 诊断参考,请勿在业务装配中直接调用(纯查询语义,不改写 ctx.session)。
3543
- */
3544
- export declare function getMainSession(ctx: WrapperContext): NodeIQQNTWrapperSession | null;
3545
- /** NAPI 回调占位(方法存在即可被反射调用,无副作用)。 */
3546
- declare const noop: () => void;
3547
- /** NodeIGlobalAdapter 实现(engine.initWithDeskTopConfig 第二参)。 */
3548
- export declare class GlobalAdapter implements NodeIGlobalAdapter {
3549
- onLog: typeof noop;
3550
- onGetSrvCalTime: typeof noop;
3551
- onShowErrUITips: typeof noop;
3552
- fixPicImgType: typeof noop;
3553
- getAppSetting: typeof noop;
3554
- onInstallFinished: typeof noop;
3555
- onUpdateGeneralFlag: typeof noop;
3556
- onGetOfflineMsg: typeof noop;
3557
- }
3558
- /** NodeIDependsAdapter 实现(session.init 第二参)。 */
3559
- export declare class DependsAdapter implements NodeIDependsAdapter {
3560
- onMSFStatusChange: typeof noop;
3561
- onMSFSsoError: typeof noop;
3562
- getGroupCode: typeof noop;
3563
- }
3564
- /** NodeIDispatcherAdapter 实现(session.init 第三参)。 */
3565
- export declare class DispatcherAdapter implements NodeIDispatcherAdapter {
3566
- dispatchRequest: typeof noop;
3567
- dispatchCall: typeof noop;
3568
- dispatchCallWithJson: typeof noop;
3569
- }
3570
- /** 会话监听器选项。 */
3571
- interface SessionListenerOptions {
3572
- /** 事件日志回调(默认静默——boot 阶段事件对用户是噪音;调试时可传回调观察)。 */
3573
- onEvent?: ((name: string, ...args: unknown[]) => void) | undefined;
3574
- }
3575
- /**
3576
- * 创建会话监听器(默认静默,boot 阶段默认;login 模块接入后可覆盖)。
3577
- * 回调方法必须存在(NAPI 按方法名反射),但输出与否由调用方决定——
3578
- * onNTSessionCreate / onOpentelemetryInit 等对用户无信息量,默认不打 stdout。
3579
- */
3580
- export declare function createSessionListener(opts?: SessionListenerOptions): NodeIKernelSessionListener;
3581
- /** 创建登录监听器(占位,登录器接入时填充)。 */
3582
- export declare function createLoginListener(): KernelLoginListener;
3583
- /**
3584
- * 从 major.node 提取 appid(NapCat parseAppidFromMajorV2 的自研等价实现)。
3585
- * major.node 含 `QQAppId/` 标记后跟数字(腾讯工具链产物,实测确认)。
3586
- * 返回 null 表示解析失败(调用方应显式报错,不再回退硬编码 appid)。
3587
- */
3588
- export declare function parseAppidFromMajor(majorPath: string): string | null;
3589
- /**
3590
- * 解析 appid / qua(自研,参考 NapCat QQBasicInfoWrapper 思路但独立实现):
3591
- * appid 唯一来源 = major.node 提取(实测 9.9.33-51802 = 537376818)。
3592
- * majorPath 缺省或解析失败时抛 KernelError——不再静默回退过期 appid。
3593
- * majorPath 传 wrapper.node 同目录 major.node。
3594
- */
3595
- export declare function resolveAppidQua(fullVersion: string, majorPath?: string, platform?: PlatformType): {
3596
- appid: string;
3597
- qua: string;
3598
- };
3599
- /** 生成 engine 桌面配置(wrapper 契约字段)。majorPath 可选(缺失/解析失败会抛错)。 */
3600
- export declare function buildEngineConfig(fullVersion: string, dataPathGlobal: string, majorPath?: string, platform?: PlatformType): EnginInitDesktopConfig;
3601
- /** 生成登录初始化配置(externalVersion: false 与 NapCat 同款,扫码兼容关键)。 */
3602
- export declare function buildLoginConfig(appid: string, fullVersion: string, commonPath: string): Record<string, unknown>;
3603
- /** buildSessionConfig 参数。 */
3604
- interface SessionConfigOptions {
3605
- appid: string;
3606
- fullVersion: string;
3607
- selfUin: string;
3608
- selfUid: string;
3609
- accountPath: string;
3610
- downloadPath: string;
3611
- /** 设备指纹 guid(来自 loginService.getMachineGuid();缺省空串)。 */
3612
- machineGuid?: string | undefined;
3613
- /** 平台(缺省按 process.platform 探测;测试/联调可显式覆盖)。 */
3614
- platform?: PlatformType | undefined;
3615
- }
3616
- /** 生成 session 初始化配置(登录成功后调用)。 */
3617
- export declare function buildSessionConfig(options: SessionConfigOptions): WrapperSessionInitConfig;
3618
- /**
3619
- * 读取设备指纹 guid(wrapper.node 字符串分析实证,2026-08-12):
3620
- * NodeIKernelLoginService::getMachineGuid(0 参,返回机器 GUID 字符串)。
3621
- * 无 getMachineId 方法——TODO 里的方法名不存在,等价方法是 getMachineGuid。
3622
- * 失败(无该方法 / 调用抛错 / 返回值非字符串)兜底空串。
3623
- */
3624
- export declare function readMachineGuid(loginService: unknown): string;
3625
- /**
3626
- * QQ 安装目录探测(ADR-018)
3627
- *
3628
- * wrapper.node 路径随 QQ 版本变化:`<安装目录>/versions/<版本>/resources/app/wrapper.node`。
3629
- * 加载前必须知道版本(登录握手参数 appid/qua 与版本强相关)。
3630
- *
3631
- * 已实测确认(2026-08-05,QQ 9.9.31-49919):
3632
- * - 目录结构:versions/<9.9.31-49919>/resources/app/wrapper.node
3633
- * - 版本信息在 versions/<版本>/resources/app/package.json(name=qq-chat / version / buildVersion)
3634
- * - wrapper.node 是 C++ ABI 模块(非 N-API),导出 INTSessionShell 等符号
3635
- */
3636
- /** 解析 wrapper.node 绝对路径(按 ADR-018 目录约定)。 */
3637
- export declare function resolveWrapperPath(installDir: string, version: string): string;
3638
- /**
3639
- * 探测指定版本信息(校验 wrapper.node 存在)。
3640
- * 版本号不匹配目录时抛 NOT_FOUND(明确失败而非静默)。
3641
- */
3642
- export declare function resolveQQVersion(installDir: string, version: string): QQVersionInfo;
3643
- /** 扫描 versions 目录,取可加载的版本列表(按目录名倒序,最新在前)。 */
3644
- export declare function listQQVersions(installDir: string): string[];
3645
- /** QQ 版本信息。 */
3646
- interface QqVersionInfo {
3647
- /** 完整版本号,如 "9.9.31-49919"。 */
3648
- fullVersion: string;
3649
- /** 构建号,如 "49919"。 */
3650
- buildVersion: string;
3651
- /** wrapper.node 绝对路径。 */
3652
- wrapperPath: string;
3653
- /** 登录握手参数(P1 探测脚本产出,暂为空串)。 */
3654
- appid: string;
3655
- /** 登录握手参数(P1 探测脚本产出,暂为空串)。 */
3656
- qua: string;
3657
- }
3658
- /** @deprecated 使用 `QqVersionInfo`(缩写大小写统一为 `Qq`)。 */
3659
- type QQVersionInfo = QqVersionInfo;
3660
3567
  export { type BootEnv, type BuddyCacheEventChannel, type BuddyCacheListener, type BuddyCacheOptions, type BuddyCategory, type BuddyCoreInfo, type BuddyEventChannel, type BuddyListEntry, type BuddyListener, type BuddyProfileLikeResult, type BuddyReq, type CanonicalElement, type ConfigFormat, type ConfigOptions, type ConfigPathOptions, type ConfigSchema, type ConsoleFormatStreamOptions, type CoreContext, type CoreContextOptions, type CoreLoginOptions, type DesktopPathConfig, type DeviceInfo, type DoubtBuddyReq, type DoubtFriendRequestInfo, type EnginInitDesktopConfig, type EssenceAddedItem, type EssenceCacheEntry, type EssenceDiffResult, type EssenceListSyncDeps, type EssenceMsgItem, type FaceElement, type FileElement, type FlashTransferFileSet, type FlashTransferFileStatus, type FlashTransferPermission, type FlashTransferTarget, type FlashTransferTaskInfo, type FlashTransferUploadListener, type FlashTransferUploadOptions, type FlashTransferUploadResult, type ForceFetchClientKeyRetType, type Friend, type FriendApiOptions, type FriendCategory, type GeneralCallResult, type GetFileListParam, type GrayTipElement, type GrayTipRevokeElement, type Group, type GroupBulletin, type GroupCacheOptions, type GroupDetailInfo, type GroupEventChannel, type GroupFileItemInfo, type GroupFileListItem, type GroupFileSystemInfo, type GroupFolderInfo, type GroupHonorWebInfo, type GroupListener, type GroupMember, type GroupMemberListChange, type GroupNotify, type GroupRemainAtTimes, type GroupRequestKind, type GroupRequestRef, type GroupSpaceInfo, type HonorListItem, type IKernelLoginListener, type KernelErrorCode, type KernelLoginListener, type KernelRuntime, type KernelRuntimeOptions, type KickMemberInfo, type KickMemberV2Req, type ListenerEvents, type ListenerRecordEvent, type ListenerRecordingResult, type LogConfig, type LogEnvSource, type LogFileConfig, type LogFormat, type LogLevel, type LogModuleName, type LoggerOptions, type LoginAccountInfo, type LoginEventChannel, type LoginListItem, type LoginListener, type LoginProgress, type LoginResult, type LoginState, type MsgEventChannel, type MsgListener, type MsgReadReportItem, type MsgReceipt, type NapukettoCoreOptions, type NodeIDependsAdapter, type NodeIDispatcherAdapter, type NodeIGlobalAdapter, type NodeIKernelBuddyService, type NodeIKernelGroupService, type NodeIKernelLoginService, type NodeIKernelMsgService, type NodeIKernelProfileLikeService, type NodeIKernelProfileService, type NodeIKernelRecentContactService, type NodeIKernelRichMediaService, type NodeIKernelSessionListener, type NodeIKernelTicketService, type NodeIQQNTStartupSessionWrapper, type NodeIQQNTWrapperEngine, type NodeIQQNTWrapperSession, type NodeQQNTWrapperUtil, type NudgeParam, type PathOptions, type Peer, type PendingGroupRequest, type PicElement, type PinnedContact, type PlatformType, type PttElement, type QQVersionContext, type QQVersionInfo, type QqDataRootOptions, type QqVersionContext, type QqVersionInfo, type QrCodeData, type QuickLoginOptions, type RDeliveryConfig, type RawElement, type RawMessage, type RecentContact, type RecentContactEventChannel, type RecentContactFetchParam, type RecentContactListChanged, type RecentContactListener, type ReplyElement, type SelfInfo, type SendMessageElement, type SessionConfigOptions, type SessionListenerOptions, type ShutUpGroupMember, type StartNapukettoOptions, type StrangerInfo, type TextElement, type TimestampMode, type TipAioOpGrayTipElement, type TipGroupElement, type UserDetailInfoByUin, type VendorType, type VideoElement, type WrapperContext, type WrapperNodeApi, type WrapperSessionInitConfig, createSessionListener as createLifecycleSessionListener };