@napuketto/kernel 0.5.2 → 0.6.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.cjs CHANGED
@@ -1541,6 +1541,72 @@ var GroupApi = class {
1541
1541
  } else res = await this.service.removeGroupEssence(param);
1542
1542
  checkLooseResult(label, res);
1543
1543
  }
1544
+ /**
1545
+ * 群公告列表(get_group_announcements;getGroupBulletin 返回形状待探测校准,
1546
+ * 兼容 result 数组 / result.bulletins 等宽松提取)。
1547
+ */
1548
+ async getGroupAnnouncements(groupCode) {
1549
+ let raw;
1550
+ try {
1551
+ raw = await this.service.getGroupBulletin(groupCode);
1552
+ } catch (e) {
1553
+ if (isKernelError(e)) throw e;
1554
+ throw kernelError(`getGroupBulletin 调用失败: ${errMsgString$3(e)}`, "UNKNOWN");
1555
+ }
1556
+ unwrap("getGroupBulletin", toResultNumber(raw.result), raw.errMsg);
1557
+ return extractBulletins(raw.result);
1558
+ }
1559
+ /**
1560
+ * 发群公告(send_group_announcement;imagePath 提供时先 uploadGroupBulletinPic
1561
+ * 再带 picId 发布——两步参数形状均待探测校准)。
1562
+ */
1563
+ async publishGroupAnnouncement(groupCode, content, imagePath) {
1564
+ let picId;
1565
+ if (imagePath !== void 0 && imagePath !== "") picId = await this.uploadBulletinPic(groupCode, imagePath);
1566
+ try {
1567
+ checkLooseResult("publishGroupBulletin", await this.service.publishGroupBulletin({
1568
+ groupCode,
1569
+ content,
1570
+ ...picId !== void 0 ? { picId } : {}
1571
+ }));
1572
+ } catch (e) {
1573
+ if (isKernelError(e)) throw e;
1574
+ throw kernelError(`publishGroupBulletin 调用失败: ${errMsgString$3(e)}`, "UNKNOWN");
1575
+ }
1576
+ }
1577
+ /** 删群公告(delete_group_announcement;参数待探测校准)。 */
1578
+ async deleteGroupAnnouncement(groupCode, announcementId) {
1579
+ try {
1580
+ checkLooseResult("deleteGroupBulletin", await this.service.deleteGroupBulletin(groupCode, announcementId));
1581
+ } catch (e) {
1582
+ if (isKernelError(e)) throw e;
1583
+ throw kernelError(`deleteGroupBulletin 调用失败: ${errMsgString$3(e)}`, "UNKNOWN");
1584
+ }
1585
+ }
1586
+ /** 专属头衔(set_group_member_special_title;setIdentityTitleInfo 参数待校准)。 */
1587
+ async setMemberSpecialTitle(groupCode, uid, title) {
1588
+ try {
1589
+ checkLooseResult("setIdentityTitleInfo", await this.service.setIdentityTitleInfo(groupCode, uid, title));
1590
+ } catch (e) {
1591
+ if (isKernelError(e)) throw e;
1592
+ throw kernelError(`setIdentityTitleInfo 调用失败: ${errMsgString$3(e)}`, "UNKNOWN");
1593
+ }
1594
+ }
1595
+ /** 群头像(set_group_avatar;GroupService.setHeader 参数待校准)。 */
1596
+ async setGroupAvatar(groupCode, imagePath) {
1597
+ try {
1598
+ checkLooseResult("setHeader", await this.service.setHeader(groupCode, imagePath));
1599
+ } catch (e) {
1600
+ if (isKernelError(e)) throw e;
1601
+ throw kernelError(`setHeader(group) 调用失败: ${errMsgString$3(e)}`, "UNKNOWN");
1602
+ }
1603
+ }
1604
+ /** 公告图片上传(uploadGroupBulletinPic 返回 picId 待校准,失败原样上抛)。 */
1605
+ async uploadBulletinPic(groupCode, imagePath) {
1606
+ const res = await this.service.uploadGroupBulletinPic(groupCode, imagePath);
1607
+ checkLooseResult("uploadGroupBulletinPic", res);
1608
+ return typeof res?.picId === "string" ? res.picId : "";
1609
+ }
1544
1610
  /** @all 剩余次数(get_group_at_all_remain)。 */
1545
1611
  async getGroupRemainAtTimes(groupCode) {
1546
1612
  const raw = await this.service.getGroupRemainAtTimes(groupCode);
@@ -1552,6 +1618,29 @@ var GroupApi = class {
1552
1618
  };
1553
1619
  }
1554
1620
  };
1621
+ /** result 字段宽松取数(数字直接用,缺省 0 = 成功语义)。 */
1622
+ function toResultNumber(result) {
1623
+ return typeof result === "number" ? result : 0;
1624
+ }
1625
+ /** 公告列表宽松提取(result 数组 / { bulletins } / { result: 数组 } 兼容,形状待校准)。 */
1626
+ function extractBulletins(result) {
1627
+ const candidates = [result];
1628
+ if (result !== null && typeof result === "object") {
1629
+ const rec = result;
1630
+ for (const key of [
1631
+ "bulletins",
1632
+ "announcementList",
1633
+ "result",
1634
+ "list"
1635
+ ]) candidates.push(rec[key]);
1636
+ }
1637
+ for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter((item) => item !== null && typeof item === "object");
1638
+ return [];
1639
+ }
1640
+ /** 未知异常 → 消息字符串。 */
1641
+ function errMsgString$3(e) {
1642
+ return e instanceof Error ? e.message : String(e);
1643
+ }
1555
1644
  /**
1556
1645
  * 从 getGroupDetailInfo 返回提取群详情(兼容三种形状):
1557
1646
  * - result 为对象 → 详情直接在其中(最常见)
@@ -1725,6 +1814,28 @@ function sleep$1(ms) {
1725
1814
  setTimeout(resolve, ms);
1726
1815
  });
1727
1816
  }
1817
+ /** 未知异常 → 消息字符串。 */
1818
+ function errMsgString$2(e) {
1819
+ return e instanceof Error ? e.message : String(e);
1820
+ }
1821
+ /** 语音下载完成判定:有路径且(传输完成或末次轮询)才返回元素,否则 null。 */
1822
+ function pttDownloadResult(latest, isLastPoll) {
1823
+ if (latest === void 0) return null;
1824
+ const hasPath = latest.filePath !== void 0 && latest.filePath !== "";
1825
+ const done = latest.transferStatus === 2 || latest.transferStatus === 4;
1826
+ return hasPath && (done || isLastPoll) ? latest : null;
1827
+ }
1828
+ /** 收藏表情项 → url(字段名待校准,url/imageUrl/emojiUrl 逐个兜底)。 */
1829
+ function extractFavEmojiUrls(list) {
1830
+ const out = [];
1831
+ for (const item of list) {
1832
+ if (item === null || typeof item !== "object") continue;
1833
+ const rec = item;
1834
+ const url = rec["url"] ?? rec["imageUrl"] ?? rec["emojiUrl"];
1835
+ if (typeof url === "string" && url !== "") out.push(url);
1836
+ }
1837
+ return out;
1838
+ }
1728
1839
  /** 读文件 stat(富媒体发送预处理;文件不存在抛 INVALID_PARAM)。 */
1729
1840
  async function statFile(path, label = "图片") {
1730
1841
  try {
@@ -1834,6 +1945,9 @@ var MsgApi = class {
1834
1945
  case "video":
1835
1946
  out.push(await this.prepareVideoElement(el));
1836
1947
  break;
1948
+ case "file":
1949
+ out.push(await this.prepareFileElement(el));
1950
+ break;
1837
1951
  default: out.push(...toSendElements([el]));
1838
1952
  }
1839
1953
  return out;
@@ -1954,6 +2068,28 @@ var MsgApi = class {
1954
2068
  };
1955
2069
  }
1956
2070
  /**
2071
+ * FILE 元素预处理(P2-2 预留口子,upload_private/group_file 落地):
2072
+ * pic/ptt/video 同款 NapCat 式链路——md5 → getRichMediaFilePathForGuild(FILE)
2073
+ * → copyFile → 完整 fileElement。链路模式已验证(三类媒体同构);fileElement
2074
+ * 字段值(fileSize 字符串形态、fileUuid 空串等)待探测校准。
2075
+ */
2076
+ async prepareFileElement(el) {
2077
+ const file = await statFile(el.path, "文件");
2078
+ const md5 = await hashFile(el.path, "文件");
2079
+ const fileName = el.name !== void 0 && el.name !== "" ? el.name : (0, node_path.basename)(el.path);
2080
+ const relPath = await this.placeMediaFile(el.path, ElementType.FILE, md5, fileName);
2081
+ return {
2082
+ elementType: ElementType.FILE,
2083
+ elementId: "",
2084
+ fileElement: {
2085
+ fileName,
2086
+ filePath: relPath,
2087
+ fileSize: String(file.size),
2088
+ fileUuid: ""
2089
+ }
2090
+ };
2091
+ }
2092
+ /**
1957
2093
  * 富媒体文件放置(PIC/PTT/VIDEO 共用):md5 + 文件名 → QQ 内部目标路径
1958
2094
  * (getRichMediaFilePathForGuild)→ util.copyFile 放置 → 返回目标路径。
1959
2095
  *
@@ -2047,31 +2183,72 @@ var MsgApi = class {
2047
2183
  * 调用方),完全无路径抛 NOT_FOUND。
2048
2184
  */
2049
2185
  async downloadPtt(msgId, target) {
2050
- const el = findPttElement(await this.fetchMsgsByMsgId(target, [msgId]));
2051
- const ptt = el?.pttElement;
2052
- if (el === null || ptt === void 0) throw kernelError("消息中不包含语音", "NOT_FOUND");
2053
- const elemId = el.elementId ?? "";
2186
+ const found = await this.pttElementOf(msgId, target);
2187
+ if (found === null) throw kernelError("消息中不包含语音", "NOT_FOUND");
2054
2188
  await this.service.downloadRichMedia({
2055
2189
  msgId,
2056
- elemId,
2190
+ elemId: found.elemId,
2057
2191
  chatType: target.chatType,
2058
2192
  downloadType: DOWNLOAD_TYPE_COMMON,
2059
2193
  thumbSize: THUMB_SIZE_NONE
2060
2194
  });
2061
2195
  for (let i = 0; i < PTT_POLL_TIMES; i++) {
2062
2196
  await sleep$1(PTT_POLL_INTERVAL_MS);
2063
- const latest = findPttElement(await this.fetchMsgsByMsgId(target, [msgId]))?.pttElement;
2064
- if (latest === void 0) continue;
2065
- const done = latest.transferStatus === 2 || latest.transferStatus === 4;
2066
- if (latest.filePath !== void 0 && latest.filePath !== "" && done) return latest;
2067
- if (i === 33 && latest.filePath !== void 0 && latest.filePath !== "") return latest;
2197
+ const result = pttDownloadResult(findPttElement(await this.fetchMsgsByMsgId(target, [msgId]))?.pttElement, i === 33);
2198
+ if (result !== null) return result;
2068
2199
  }
2069
2200
  throw kernelError("语音下载未完成(超时)", "TIMEOUT");
2070
2201
  }
2202
+ /** 取消息内语音元素(无则 null;附 elemId 供主动下载)。 */
2203
+ async pttElementOf(msgId, target) {
2204
+ const el = findPttElement(await this.fetchMsgsByMsgId(target, [msgId]));
2205
+ const ptt = el?.pttElement;
2206
+ if (el === null || ptt === void 0) return null;
2207
+ return {
2208
+ elemId: el.elementId ?? "",
2209
+ ptt
2210
+ };
2211
+ }
2071
2212
  /** 发送输入状态(set_input_status;eventType=1 输入中,0 停止)。 */
2072
2213
  async setInputStatus(target, eventType) {
2073
2214
  await this.service.sendShowInputStatusReq(target.chatType, eventType, target.peerUid);
2074
2215
  }
2216
+ /** 戳一戳发送(send_friend/group_nudge;参数形状待探测校准,失败抛 UNKNOWN)。 */
2217
+ async sendNudge(target, opts) {
2218
+ const param = {
2219
+ receiverUid: opts.receiverUid,
2220
+ callerUid: opts.callerUid,
2221
+ ...target.chatType === ChatType.GROUP ? { confId: target.peerUid } : {}
2222
+ };
2223
+ try {
2224
+ checkLooseResult("sendNudge", await this.service.sendNudge(param));
2225
+ } catch (e) {
2226
+ if (isKernelError(e)) throw e;
2227
+ throw kernelError(`sendNudge 调用失败: ${errMsgString$2(e)}`, "UNKNOWN");
2228
+ }
2229
+ }
2230
+ /** 会话置顶(set_peer_pin;setContactLocalTop 参数待探测校准)。 */
2231
+ async setContactTop(target, isTop) {
2232
+ try {
2233
+ checkLooseResult("setContactLocalTop", await this.service.setContactLocalTop(target, isTop));
2234
+ } catch (e) {
2235
+ if (isKernelError(e)) throw e;
2236
+ throw kernelError(`setContactLocalTop 调用失败: ${errMsgString$2(e)}`, "UNKNOWN");
2237
+ }
2238
+ }
2239
+ /** 收藏表情列表(get_custom_face_url_list;queryFavEmojiByDesc 形状待校准)。 */
2240
+ async queryFavEmojis() {
2241
+ let raw;
2242
+ try {
2243
+ raw = await this.service.queryFavEmojiByDesc("");
2244
+ } catch (e) {
2245
+ throw kernelError(`queryFavEmojiByDesc 调用失败: ${errMsgString$2(e)}`, "UNKNOWN");
2246
+ }
2247
+ checkLooseResult("queryFavEmojiByDesc", raw);
2248
+ const list = raw.emojiInfoList;
2249
+ if (!Array.isArray(list)) return [];
2250
+ return extractFavEmojiUrls(list);
2251
+ }
2075
2252
  /**
2076
2253
  * 发送合并转发(send_group/private_forward_msg)。
2077
2254
  * buildMultiForwardMsg 组装 MULTI_FORWARD 元素 → 直接作 sendMsg 元素发送。
@@ -2238,6 +2415,76 @@ var ProfileLikeApi = class {
2238
2415
  }
2239
2416
  };
2240
2417
  //#endregion
2418
+ //#region src/apis/recent-contact.ts
2419
+ /**
2420
+ * RecentContactApi:会话列表语义化 API(P2 批次二,get_peer_pins 数据源)
2421
+ *
2422
+ * 2026-10-31 实机探测确认 getRecentContactService 有 getRecentContactList /
2423
+ * setContactListTop 等方法;返回形状待探测校准(宽松提取)。
2424
+ * 置顶数据源:isTop 过滤(ChatType 区分 friend/group 场景)。
2425
+ */
2426
+ /** 会话列表拉取条数(覆盖置顶集合足够大;参数值待探测校准)。 */
2427
+ const RECENT_CONTACT_FETCH_COUNT = 200;
2428
+ /** 会话列表 API:从 session 拿 recent contact service,包装成语义化方法。 */
2429
+ var RecentContactApi = class {
2430
+ service;
2431
+ constructor(session) {
2432
+ const service = session.getRecentContactService();
2433
+ if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
2434
+ this.service = service;
2435
+ }
2436
+ /** 置顶会话列表(get_peer_pins;getRecentContactList 返回形状待探测校准)。 */
2437
+ async getPinnedContacts() {
2438
+ let raw;
2439
+ try {
2440
+ raw = await this.service.getRecentContactList({ count: RECENT_CONTACT_FETCH_COUNT });
2441
+ } catch (e) {
2442
+ if (isKernelError(e)) throw e;
2443
+ throw kernelError(`getRecentContactList 调用失败: ${errMsgString$1(e)}`, "UNKNOWN");
2444
+ }
2445
+ checkLooseResult("getRecentContactList", raw);
2446
+ return extractPinnedContacts(raw);
2447
+ }
2448
+ };
2449
+ /** 从返回形状提取置顶会话(result 数组 / 顶层 contacts / 嵌套容器兼容,待校准)。 */
2450
+ function extractPinnedContacts(raw) {
2451
+ const candidates = [raw.result, raw];
2452
+ for (const container of [raw.result, raw]) {
2453
+ if (container === null || typeof container !== "object") continue;
2454
+ const rec = container;
2455
+ for (const key of [
2456
+ "contacts",
2457
+ "data",
2458
+ "result",
2459
+ "list"
2460
+ ]) candidates.push(rec[key]);
2461
+ }
2462
+ for (const candidate of candidates) {
2463
+ if (!Array.isArray(candidate)) continue;
2464
+ return candidate.flatMap((item) => pinnedOf(item));
2465
+ }
2466
+ return [];
2467
+ }
2468
+ /** 单条会话 → 置顶项(isTop 为真且场景可判定才产出)。 */
2469
+ function pinnedOf(item) {
2470
+ if (item === null || typeof item !== "object") return [];
2471
+ const contact = item;
2472
+ if (contact.isTop !== true || typeof contact.peerUid !== "string") return [];
2473
+ if (contact.chatType === ChatType.GROUP) return [{
2474
+ peerUid: contact.peerUid,
2475
+ scene: "group"
2476
+ }];
2477
+ if (contact.chatType === ChatType.C2C) return [{
2478
+ peerUid: contact.peerUid,
2479
+ scene: "friend"
2480
+ }];
2481
+ return [];
2482
+ }
2483
+ /** 未知异常 → 消息字符串。 */
2484
+ function errMsgString$1(e) {
2485
+ return e instanceof Error ? e.message : String(e);
2486
+ }
2487
+ //#endregion
2241
2488
  //#region src/apis/richmedia.ts
2242
2489
  /**
2243
2490
  * RichMediaApi:富媒体语义化 API(ADR-009 统一错误语义,P2-14)
@@ -2283,10 +2530,11 @@ var RichMediaApi = class {
2283
2530
  showOnlinedocFolder: HIDE_ONLINEDOC_FOLDER
2284
2531
  };
2285
2532
  const raw = await this.service.getGroupFileList(groupCode, params);
2286
- if (raw.result !== 0) unwrap("getGroupFileList", raw.result, raw.errMsg);
2533
+ checkLooseResult("getGroupFileList", raw);
2287
2534
  const list = extractFileList(raw.result);
2288
- if (parentFolderId === "") return list;
2289
- return list.filter((item) => item.fileInfo !== void 0 && item.fileInfo.parent === parentFolderId || item.folderInfo !== void 0 && item.folderInfo.folderUid === parentFolderId);
2535
+ const items = list.length > 0 ? list : extractFileList(raw);
2536
+ if (parentFolderId === "") return items;
2537
+ return items.filter((item) => item.fileInfo !== void 0 && item.fileInfo.parent === parentFolderId || item.folderInfo !== void 0 && item.folderInfo.folderUid === parentFolderId);
2290
2538
  }
2291
2539
  /** 群文件系统信息(get_group_file_system_info;getGroupFileList 的 groupSpaceResult)。 */
2292
2540
  async getGroupFileSystemInfo(groupCode) {
@@ -2335,6 +2583,26 @@ var RichMediaApi = class {
2335
2583
  const raw = await this.service.moveGroupFile(groupCode, [GROUP_FILE_BIZ_TYPE], fileIds, "", targetFolderId);
2336
2584
  if (raw.result !== 0) unwrap("moveGroupFile", raw.result, raw.errMsg);
2337
2585
  }
2586
+ /** 重命名群文件夹(rename_group_folder;形态镜像 renameGroupFile,待校准)。 */
2587
+ async renameGroupFolder(groupCode, folderId, newName) {
2588
+ await this.service.renameGroupFolder(groupCode, GROUP_FILE_BIZ_TYPE, folderId, newName, "");
2589
+ }
2590
+ /**
2591
+ * 群文件下载链接(get_group_file_download_url):getGroupFileList 根列表按
2592
+ * fileId 查找取 url 字段(字段待实机确认)。已知差异:仅根目录可达——
2593
+ * 子目录文件需 parentFolderId 逐层定位,暂不支持。
2594
+ */
2595
+ async getGroupFileDownloadUrl(groupCode, fileId) {
2596
+ const items = await this.getGroupFileList(groupCode);
2597
+ for (const item of items) {
2598
+ const info = item.fileInfo;
2599
+ if (info !== void 0 && info.fileId === fileId) {
2600
+ if (typeof info.url === "string" && info.url !== "") return info.url;
2601
+ throw kernelError(`群文件 ${fileId} 无下载链接(url 字段缺失,待实机校准)`, "NOT_FOUND");
2602
+ }
2603
+ }
2604
+ throw kernelError(`群文件 ${fileId} 不在根目录或不存在(仅支持根目录查找)`, "NOT_FOUND");
2605
+ }
2338
2606
  /** 转存群文件(trans_group_file)。 */
2339
2607
  async transGroupFile(groupCode, fileId) {
2340
2608
  const raw = await this.service.transGroupFile(groupCode, fileId);
@@ -4446,7 +4714,6 @@ function resolveMainFromStartup(ctx) {
4446
4714
  *
4447
4715
  * - serialize:深度受限序列化(BigInt 转字符串,Map/Set/Promise 展开,循环引用防护)
4448
4716
  * - tryShape:解析 service getter 返回形状
4449
- * - shapeKeyGetters:探测 service 关键数据 getter 返回形状
4450
4717
  */
4451
4718
  /** 序列化深度上限(循环引用/深层对象防护)。 */
4452
4719
  const MAX_SERIALIZE_DEPTH = 4;
@@ -4520,15 +4787,6 @@ function tryShape(session, getter) {
4520
4787
  return "[error]";
4521
4788
  }
4522
4789
  }
4523
- /** 数据 getter 方法名模式(探测返回形状用)。 */
4524
- const DATA_GETTER_RE = /^(get|query|fetch|load)/i;
4525
- /** 探测 service 的关键数据 getter 返回形状(取前几个无参调用)。 */
4526
- function shapeKeyGetters(session, serviceMethods) {
4527
- const out = {};
4528
- const candidates = serviceMethods.filter((m) => DATA_GETTER_RE.test(m) && !m.endsWith("Listener"));
4529
- for (const m of candidates.slice(0, 8)) out[m] = tryShape(session, m);
4530
- return out;
4531
- }
4532
4790
  //#endregion
4533
4791
  //#region src/wrapper/probe/probe-utils.ts
4534
4792
  /**
@@ -4586,29 +4844,6 @@ function tryCall(obj, name) {
4586
4844
  function isServiceGetter(name) {
4587
4845
  return name.startsWith("get") && name.endsWith("Service");
4588
4846
  }
4589
- /** 非空服务实例计数(逐个调用 get*Service 数非空返回;候选可用度评分)。
4590
- * 自建宿主下 QQ 主 session 未被 init,get*Service 恒 null(2026-10-31 实测
4591
- * napuketto-probe-late.json),kernel 自建 session 服务可用——主目标按此评分选取。 */
4592
- function countNonNullServices(session) {
4593
- if (session === null || session === void 0) return 0;
4594
- let count = 0;
4595
- for (const name of listMethods(session)) {
4596
- if (!isServiceGetter(name)) continue;
4597
- const call = tryCall(session, name);
4598
- if (call.ok && call.value !== null && call.value !== void 0) count += 1;
4599
- }
4600
- return count;
4601
- }
4602
- /** 主探测目标选取:服务实例最多者优先,评分并列保持候选顺序(主 session 在前)。 */
4603
- function pickPrimaryCandidate(candidates) {
4604
- let best = candidates[0];
4605
- for (const candidate of candidates.slice(1)) if (best !== void 0 && candidate.serviceNonNull > best.serviceNonNull) best = candidate;
4606
- return best ?? {
4607
- source: "own-create",
4608
- session: null,
4609
- serviceNonNull: 0
4610
- };
4611
- }
4612
4847
  //#endregion
4613
4848
  //#region src/wrapper/probe/probe-services.ts
4614
4849
  /** 探测关键 export 构造器方法(get/create/getNTWrapperSession 等)。 */
@@ -4859,89 +5094,76 @@ function probeCreatedChain(ctx, created) {
4859
5094
  function findMainProbeId(sessionIds) {
4860
5095
  return sessionIds.find((id) => id.startsWith("nt_")) ?? sessionIds[0];
4861
5096
  }
4862
- /** 探测 session 与 service 方法(候选中选服务实例最多者为主目标)。
4863
- * 自建宿主下 QQ 主 session 未被 init(get*Service 恒 null,2026-10-31 实测
4864
- * napuketto-probe-late.json 全服务空),kernel 自建 session 已带 adapter init
4865
- * 服务可用——主目标按 countNonNullServices 评分选取,并列保持主 session 优先。 */
4866
- function probeSession(ctx) {
4867
- const out = {};
4868
- const candidates = collectProbeCandidates(ctx).map(scoreCandidate);
4869
- const primary = pickPrimaryCandidate(candidates);
4870
- out["sessionSource"] = primary.source;
4871
- out["session"] = sessionFace(primary.session);
4872
- if (primary.session !== null && primary.session !== void 0) out["services"] = collectServiceGetters(primary.session);
4873
- if (candidates.length > 1) out["sessionAlternates"] = alternateFaces(candidates, primary);
4874
- return out;
4875
- }
4876
- /** 候选评分(非空服务实例数)。 */
4877
- function scoreCandidate(candidate) {
4878
- return {
4879
- ...candidate,
4880
- serviceNonNull: countNonNullServices(candidate.session)
4881
- };
4882
- }
4883
- /** 落选候选的概要面(方法数 + 评分,诊断用)。 */
4884
- function alternateFaces(candidates, primary) {
4885
- return candidates.filter((candidate) => candidate !== primary).map((candidate) => ({
4886
- source: candidate.source,
4887
- methodCount: listMethods(candidate.session).length,
4888
- serviceNonNull: candidate.serviceNonNull
4889
- }));
4890
- }
4891
- /** 收集候选 session:kernel 自建 session + QQ 主 session(若可得)。
5097
+ /** 探测 session 与 service 方法名面。
5098
+ * 主目标 = ctx.session 快照(kernel 自建就绪 session),缺省回退 QQ 主 session;
5099
+ * 自建宿主下主 session 未被 init(get*Service 恒 null,2026-10-31 实测)。
4892
5100
  * ⚠️ 先快照 ctx.session 再枚举主 session——getMainSession 有 P1-4 遗留副作用
4893
- * (resolveMainFromStartup 把空壳主 session 写回 ctx.session,session-resolver.ts),
4894
- * 后读会把就绪的自建 session 读成空壳(2026-10-31 实测:候选退化为单主 session)。 */
4895
- function collectProbeCandidates(ctx) {
5101
+ * (resolveMainFromStartup 把空壳主 session 写回 ctx.session,session-resolver.ts)。
5102
+ * ⚠️ names-only:不对服务实例做无参 shape 调用——活 session 上无参调原生方法
5103
+ * = 访问违例 0xC0000005(2026-10-31 实测崩溃,tryShape 捕不住原生段错误)。 */
5104
+ /** 非空判定(null / undefined 均视为缺省)。 */
5105
+ function hasValue(value) {
5106
+ return value !== null && value !== void 0;
5107
+ }
5108
+ function probeSession(ctx, persist) {
5109
+ const out = {};
4896
5110
  const own = ctx.session;
4897
- const candidates = [];
4898
- pushMainCandidate(ctx, candidates);
4899
- pushOwnCandidate(own, candidates);
4900
- return candidates;
5111
+ const main = tryMainSession(ctx);
5112
+ const primary = hasValue(own) ? own : main;
5113
+ out["sessionSource"] = hasValue(own) ? "own-create" : "mainSession";
5114
+ out["session"] = sessionFace(primary);
5115
+ assignServices(out, primary, persist);
5116
+ assignAlternates(out, own, main);
5117
+ return out;
4901
5118
  }
4902
- /** 并入 QQ 主 session 候选(枚举失败静默跳过)。 */
4903
- function pushMainCandidate(ctx, out) {
5119
+ /** 并入主目标的服务方法名面(主目标缺省时跳过)。 */
5120
+ function assignServices(out, primary, persist) {
5121
+ if (!hasValue(primary)) return;
5122
+ out["services"] = collectServiceGetters(primary, persist);
5123
+ }
5124
+ /** 并入落选候选概要(仅主目标为自建 session 时记录主 session 方法数,诊断用)。 */
5125
+ function assignAlternates(out, own, main) {
5126
+ if (!hasValue(own) || !hasValue(main)) return;
5127
+ out["sessionAlternates"] = [{
5128
+ source: "mainSession(getNTWrapperSession)",
5129
+ methodCount: listMethods(main).length
5130
+ }];
5131
+ }
5132
+ /** QQ 主 session(getMainSession 有写回 ctx.session 的副作用——调用前须已快照)。 */
5133
+ function tryMainSession(ctx) {
4904
5134
  try {
4905
- const main = getMainSession(ctx);
4906
- if (main !== null) out.push({
4907
- source: "mainSession(getNTWrapperSession)",
4908
- session: main
4909
- });
4910
- } catch {}
4911
- }
4912
- /** 并入 kernel 自建 session 候选(与已有候选同一实例时去重)。 */
4913
- function pushOwnCandidate(own, out) {
4914
- if (own === null || own === void 0) return;
4915
- if (out.some((candidate) => candidate.session === own)) return;
4916
- out.push({
4917
- source: "own-create",
4918
- session: own
4919
- });
5135
+ return getMainSession(ctx);
5136
+ } catch {
5137
+ return null;
5138
+ }
4920
5139
  }
4921
- /** 收集 session 的 get*Service getter 方法面与返回形状。 */
4922
- function collectServiceGetters(session) {
4923
- const getters = listMethods(session).filter((m) => m.startsWith("get") && m.endsWith("Service"));
5140
+ /** 收集 session 的 get*Service 方法名面(names-only,不做 shape 无参调用)。
5141
+ * 每个服务完成即 persist 一次——活 session 上个别 getter 若触发原生崩溃,
5142
+ * 文件里留下最后一个成功项,精确定位肇事 getter。 */
5143
+ function collectServiceGetters(session, persist) {
4924
5144
  const services = {};
4925
- for (const getter of getters) services[getter] = probeServiceGetter(session, getter);
5145
+ for (const getter of listMethods(session).filter(isServiceGetter)) {
5146
+ services[getter] = probeServiceGetter(session, getter);
5147
+ persist?.();
5148
+ }
4926
5149
  return services;
4927
5150
  }
4928
- /** 探测单个 getter:成功记录方法面/形状,失败记录错误。 */
5151
+ /** 探测单个 getter:成功记录方法名面(不调用服务方法),失败记录错误。 */
4929
5152
  function probeServiceGetter(session, getter) {
4930
5153
  const call = tryCall(session, getter);
4931
5154
  if (!(call.ok && call.value)) return {
4932
5155
  error: call.error ?? "null/undefined",
4933
5156
  ok: call.ok
4934
5157
  };
4935
- const methods = listMethods(call.value);
4936
5158
  return {
4937
- methods,
4938
- ownKeys: Object.getOwnPropertyNames(call.value).slice(0, 20),
4939
- shapes: shapeKeyGetters(call.value, methods)
5159
+ methods: listMethods(call.value),
5160
+ ownKeys: Object.getOwnPropertyNames(call.value).slice(0, 20)
4940
5161
  };
4941
5162
  }
4942
5163
  /**
4943
- * 探测 wrapper 运行时:dump session 方法与各 service 方法到 JSON。
5164
+ * 探测 wrapper 运行时:dump session 方法与各 service 方法名到 JSON。
4944
5165
  * 返回探测结果对象;同时写文件(NAPUTO_CFG_DIR/<file>,默认 napuketto-probe.json)。
5166
+ * 服务枚举逐项增量落盘(persist)——活 session 上原生崩溃时文件保留断点。
4945
5167
  */
4946
5168
  function probeRuntime(ctx, file = "napuketto-probe.json") {
4947
5169
  const result = {
@@ -4951,9 +5173,15 @@ function probeRuntime(ctx, file = "napuketto-probe.json") {
4951
5173
  exportCtors: probeExportCtors(ctx),
4952
5174
  engineCalls: probeEngineCalls(ctx),
4953
5175
  loginService: probeLoginService(ctx),
4954
- startup: probeStartup(ctx),
4955
- ...probeSession(ctx)
5176
+ startup: probeStartup(ctx)
4956
5177
  };
5178
+ const persist = () => writeProbeFile(result, file);
5179
+ Object.assign(result, probeSession(ctx, persist));
5180
+ writeProbeFile(result, file);
5181
+ return result;
5182
+ }
5183
+ /** 探测结果落盘(增量与最终共用;最终写入后记 probeFile 路径)。 */
5184
+ function writeProbeFile(result, file) {
4957
5185
  try {
4958
5186
  const dir = node_process.default.env["NAPUTO_CFG_DIR"] ?? node_process.default.cwd();
4959
5187
  (0, node_fs.mkdirSync)(dir, { recursive: true });
@@ -4961,9 +5189,8 @@ function probeRuntime(ctx, file = "napuketto-probe.json") {
4961
5189
  (0, node_fs.writeFileSync)(full, JSON.stringify(result, null, 2), "utf8");
4962
5190
  result["probeFile"] = full;
4963
5191
  } catch (e) {
4964
- result["probeFileError"] = e instanceof Error ? e.message : String(e);
5192
+ result["probeFileError"] = errMsgString(e);
4965
5193
  }
4966
- return result;
4967
5194
  }
4968
5195
  //#endregion
4969
5196
  //#region src/wrapper/wrapper-version.ts
@@ -5053,6 +5280,7 @@ exports.PathWrapper = PathWrapper;
5053
5280
  exports.ProfileApi = ProfileApi;
5054
5281
  exports.ProfileLikeApi = ProfileLikeApi;
5055
5282
  exports.QrLoginSession = QrLoginSession;
5283
+ exports.RecentContactApi = RecentContactApi;
5056
5284
  exports.RichMediaApi = RichMediaApi;
5057
5285
  exports.TicketApi = TicketApi;
5058
5286
  exports.TipGroupElementType = TipGroupElementType;