@napuketto/kernel 0.13.0 → 0.13.1
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.d.mts +98 -32
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +382 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -330,6 +330,55 @@ function parseLogConfig(section, env = {}) {
|
|
|
330
330
|
delete draft.fileLevelExplicit;
|
|
331
331
|
return draft;
|
|
332
332
|
}
|
|
333
|
+
// src/utils/type-guards.ts
|
|
334
|
+
/**
|
|
335
|
+
* 通用运行时类型守卫集(全仓复用,零依赖)
|
|
336
|
+
*
|
|
337
|
+
* 目标:把「外部边界进来的 unknown」经**可证明的**运行时检查收窄为业务类型,
|
|
338
|
+
* 取代 `as unknown as T` / `as T` 一类绕过编译器的虚假类型安全。
|
|
339
|
+
*
|
|
340
|
+
* 约定:
|
|
341
|
+
* - 只做形状判定,不做业务语义校验(业务错误仍由调用方抛 KernelError);
|
|
342
|
+
* - 守卫是 `val is T` 型谓词,收窄由编译器自然推导,调用方无需再断言;
|
|
343
|
+
* - 失败路径统一经 kernelError 抛 INVALID_STATE(ADR-009),不抛裸 Error。
|
|
344
|
+
*
|
|
345
|
+
*/
|
|
346
|
+
/** 判断未知值是否为非 null 且非数组的普通对象 Record。 */
|
|
347
|
+
function isRecord(val) {
|
|
348
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
349
|
+
}
|
|
350
|
+
/** 判断对象是否包含指定字段且类型为 string。 */
|
|
351
|
+
function hasStringProp(obj, key) {
|
|
352
|
+
return typeof obj[key] === "string";
|
|
353
|
+
}
|
|
354
|
+
/** 判断对象是否包含指定字段且类型为有限 number。 */
|
|
355
|
+
function hasNumberProp(obj, key) {
|
|
356
|
+
return typeof obj[key] === "number" && Number.isFinite(obj[key]);
|
|
357
|
+
}
|
|
358
|
+
/** 判断对象是否包含指定字段且类型为 boolean。 */
|
|
359
|
+
function hasBooleanProp(obj, key) {
|
|
360
|
+
return typeof obj[key] === "boolean";
|
|
361
|
+
}
|
|
362
|
+
/** 判断对象是否包含指定字段且类型为 function。 */
|
|
363
|
+
function hasFunctionProp(obj, key) {
|
|
364
|
+
return typeof obj[key] === "function";
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* 校验并收窄 Kernel Session 返回的原生 Service 实例。
|
|
368
|
+
*
|
|
369
|
+
* 原生 `get*Service()` 在 session 未 init / 句柄失效时可能返回 null、undefined、
|
|
370
|
+
* 已 `isNull()` 的空句柄或残缺对象——直接 `as unknown as NodeIKernel*Service`
|
|
371
|
+
* 会让调用方在第一次方法调用时炸出裸 TypeError。这里统一在边界拦截:
|
|
372
|
+
* 空 / 非对象 / isNull() === true / 缺失关键方法一律抛 INVALID_STATE。
|
|
373
|
+
*/
|
|
374
|
+
function requireKernelService(raw, serviceName, requiredMethods = []) {
|
|
375
|
+
if (raw === null || raw === void 0 || !isRecord(raw)) throw kernelError(`${serviceName}() 返回空(session 未 init)`, "INVALID_STATE");
|
|
376
|
+
if (hasFunctionProp(raw, "isNull")) {
|
|
377
|
+
if (raw["isNull"]() === true) throw kernelError(`${serviceName}() 返回空句柄(isNull 为 true)`, "INVALID_STATE");
|
|
378
|
+
}
|
|
379
|
+
for (const method of requiredMethods) if (typeof raw[method] !== "function") throw kernelError(`${serviceName}() 返回对象缺失必要方法: ${method}`, "INVALID_STATE");
|
|
380
|
+
return raw;
|
|
381
|
+
}
|
|
333
382
|
// src/infra/log-format.ts
|
|
334
383
|
/**
|
|
335
384
|
* 控制台渲染流(pretty / single-line / json,2026-10-25 日志可配置化;
|
|
@@ -563,14 +612,18 @@ function createConsoleFormatStream(opts) {
|
|
|
563
612
|
};
|
|
564
613
|
const render = opts.format === "pretty" ? renderPrettyLine : opts.format === "json" ? renderJsonLine : renderSingleLine;
|
|
565
614
|
return { write(line) {
|
|
566
|
-
let
|
|
615
|
+
let parsed;
|
|
567
616
|
try {
|
|
568
|
-
|
|
617
|
+
parsed = JSON.parse(line);
|
|
569
618
|
} catch {
|
|
570
619
|
out.write(`${line}\n`);
|
|
571
620
|
return;
|
|
572
621
|
}
|
|
573
|
-
|
|
622
|
+
if (!isRecord(parsed)) {
|
|
623
|
+
out.write(`${line}\n`);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
out.write(render(parsed, ctx));
|
|
574
627
|
} };
|
|
575
628
|
}
|
|
576
629
|
// src/infra/logger.ts
|
|
@@ -877,10 +930,17 @@ function unwrap(label, result, errMsg) {
|
|
|
877
930
|
if (result === 0) return;
|
|
878
931
|
throw kernelError(`${label} 失败: ${errMsg ?? "无错误详情"}`, "UNKNOWN");
|
|
879
932
|
}
|
|
880
|
-
/**
|
|
933
|
+
/**
|
|
934
|
+
* 宽松 result 校验(result 为数字非 0 视为失败;缺失/非对象/非数字视为成功)。
|
|
935
|
+
*
|
|
936
|
+
* 入参故意收为 unknown:原生方法返回形状在探测期不稳定,调用方无需为
|
|
937
|
+
* 「把返回值塞进宽松形状」再写 `as { result?: unknown }` 断言。
|
|
938
|
+
*/
|
|
881
939
|
function checkLooseResult(label, res) {
|
|
882
|
-
if (res
|
|
883
|
-
|
|
940
|
+
if (!isRecord(res)) return;
|
|
941
|
+
const result = res["result"];
|
|
942
|
+
if (typeof result !== "number" || result === 0) return;
|
|
943
|
+
throw kernelError(`${label} 失败: ${String(res["errMsg"] ?? "")}`, "UNKNOWN");
|
|
884
944
|
}
|
|
885
945
|
/** 原生结果解包:result !== 0 抛 KernelError(errMsg 语义映射错误码)。 */
|
|
886
946
|
function unwrapResult(label, raw) {
|
|
@@ -911,9 +971,11 @@ const PATH_SEPARATORS = /[\\/]/;
|
|
|
911
971
|
var FlashTransferApi = class {
|
|
912
972
|
service;
|
|
913
973
|
constructor(session) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
974
|
+
this.service = requireKernelService(session.getFlashTransferService(), "getFlashTransferService", [
|
|
975
|
+
"createFlashTransferUploadTask",
|
|
976
|
+
"addFileSetUploadListener",
|
|
977
|
+
"sendFlashTransferMsg"
|
|
978
|
+
]);
|
|
917
979
|
}
|
|
918
980
|
/**
|
|
919
981
|
* 上传文件集(`createFlashTransferUploadTask`)。所有文件 `onFileDidFinishUpload`
|
|
@@ -1051,9 +1113,7 @@ var FriendApi = class {
|
|
|
1051
1113
|
service;
|
|
1052
1114
|
uidToUin;
|
|
1053
1115
|
constructor(session, opts = {}) {
|
|
1054
|
-
|
|
1055
|
-
if (service === null || service === void 0) throw kernelError("getBuddyService() 返回空(session 未 init)", "INVALID_STATE");
|
|
1056
|
-
this.service = service;
|
|
1116
|
+
this.service = requireKernelService(session.getBuddyService(), "getBuddyService", ["getBuddyListFromCache", "getBuddyNick"]);
|
|
1057
1117
|
this.uidToUin = opts.uidToUin;
|
|
1058
1118
|
}
|
|
1059
1119
|
/** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
|
|
@@ -1617,15 +1677,6 @@ const GroupMemberDataSource = {
|
|
|
1617
1677
|
NETWORK: 1
|
|
1618
1678
|
};
|
|
1619
1679
|
// src/types/wrapper.ts
|
|
1620
|
-
/**
|
|
1621
|
-
* wrapper.node 的 NAPI 接口面(自研描述,非移植)
|
|
1622
|
-
*
|
|
1623
|
-
* 来源:wrapper.node 在 QQ 定制版 Electron 里通过 napi_define_class / napi_set_named_property
|
|
1624
|
-
* 注册的 JS 类(2026-08-05 Ghidra 反编译 FUN_180c6274a / FUN_180c80224 确认类名)。
|
|
1625
|
-
* 这些接口是 wrapper.node 对外暴露的外部系统契约——我们自研描述其形状,未复制任何第三方代码。
|
|
1626
|
-
*
|
|
1627
|
-
* 注意:这里所有对象由 QQ 运行时的 NAPI 层自动构建/转换,业务层禁止触碰 C++ ABI。
|
|
1628
|
-
*/
|
|
1629
1680
|
/** 平台类型(与 wrapper.node 的 platform 字段对应)。 */
|
|
1630
1681
|
const PlatformType = {
|
|
1631
1682
|
KUNKNOWN: 0,
|
|
@@ -1659,12 +1710,12 @@ var GroupApi = class {
|
|
|
1659
1710
|
/** 精华消息需要 msg service(按 msgId 拉消息取 msgSeq/msgRandom)。 */
|
|
1660
1711
|
msgService;
|
|
1661
1712
|
constructor(session) {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
this.msgService =
|
|
1713
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", [
|
|
1714
|
+
"getGroupList",
|
|
1715
|
+
"getGroupDetailInfo",
|
|
1716
|
+
"getAllMemberList"
|
|
1717
|
+
]);
|
|
1718
|
+
this.msgService = requireKernelService(session.getMsgService(), "getMsgService", ["getMsgsByMsgId"]);
|
|
1668
1719
|
}
|
|
1669
1720
|
/**
|
|
1670
1721
|
* 群列表(force=true 触发原生刷新)。
|
|
@@ -1688,40 +1739,42 @@ var GroupApi = class {
|
|
|
1688
1739
|
* 而是提取详情字段;形状异常抛 UNKNOWN 而非静默返回垃圾数据。 */
|
|
1689
1740
|
async getGroupInfo(groupCode) {
|
|
1690
1741
|
const raw = await this.service.getGroupDetailInfo(groupCode, 0);
|
|
1691
|
-
|
|
1742
|
+
if (!isRecord(raw)) throw kernelError("getGroupDetailInfo 返回非对象结果", "INVALID_PARAM");
|
|
1743
|
+
const result = raw["result"];
|
|
1744
|
+
const errMsg = typeof raw["errMsg"] === "string" ? raw["errMsg"] : "未知错误";
|
|
1692
1745
|
if (typeof result === "number" && result !== 0) unwrap("getGroupDetailInfo", result, errMsg);
|
|
1693
1746
|
const detail = extractGroupDetail(result, raw);
|
|
1694
|
-
if (detail === null) throw kernelError(`getGroupDetailInfo
|
|
1747
|
+
if (detail === null) throw kernelError(`getGroupDetailInfo 未返回群详情: ${errMsg}`, "INVALID_PARAM");
|
|
1695
1748
|
return detail;
|
|
1696
1749
|
}
|
|
1697
1750
|
/** 群成员列表(forceFetch=true 强制拉取,默认缓存优先)。 */
|
|
1698
1751
|
async getGroupMemberList(groupCode, forceFetch = false) {
|
|
1699
|
-
|
|
1700
|
-
if (raw.errCode !== 0) throw kernelError(`getAllMemberList 失败: ${raw.errMsg}`, "UNKNOWN");
|
|
1701
|
-
return [...raw.result.infos.values()];
|
|
1752
|
+
return memberListOf(extractMemberInfos(await this.service.getAllMemberList(groupCode, forceFetch)));
|
|
1702
1753
|
}
|
|
1703
1754
|
/** 群成员详情(uids 为空返回空数组)。 */
|
|
1704
1755
|
async getGroupMemberInfo(groupCode, uids) {
|
|
1705
1756
|
if (uids.length === 0) return [];
|
|
1706
1757
|
const raw = await this.service.getMemberInfo(groupCode, uids, true);
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
return [];
|
|
1758
|
+
if (!isRecord(raw)) throw kernelError("getMemberInfo 返回非对象结果", "INVALID_PARAM");
|
|
1759
|
+
unwrap("getMemberInfo", toResultNumber(raw["result"]), toOptionalString(raw["errMsg"]));
|
|
1760
|
+
const infos = raw["infos"];
|
|
1761
|
+
return infos instanceof Map ? memberListOf(infos) : [];
|
|
1711
1762
|
}
|
|
1712
1763
|
/** uin → uid(私聊发送等需要)。 */
|
|
1713
1764
|
async uinToUid(uins) {
|
|
1714
1765
|
if (uins.length === 0) return /* @__PURE__ */ new Map();
|
|
1715
1766
|
const raw = await this.service.getUidByUins(uins);
|
|
1716
|
-
if (raw
|
|
1717
|
-
|
|
1767
|
+
if (!isRecord(raw)) throw kernelError("getUidByUins 返回非对象结果", "INVALID_PARAM");
|
|
1768
|
+
if (toResultNumber(raw["errCode"]) !== 0) throw kernelError(`getUidByUins 失败: ${toOptionalString(raw["errMsg"]) ?? ""}`, "UNKNOWN");
|
|
1769
|
+
return toStringMap(raw["uids"]);
|
|
1718
1770
|
}
|
|
1719
1771
|
/** uid → uin。 */
|
|
1720
1772
|
async uidToUin(uids) {
|
|
1721
1773
|
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
1722
1774
|
const raw = await this.service.getUinByUids(uids);
|
|
1723
|
-
if (raw
|
|
1724
|
-
|
|
1775
|
+
if (!isRecord(raw)) throw kernelError("getUinByUids 返回非对象结果", "INVALID_PARAM");
|
|
1776
|
+
if (toResultNumber(raw["errCode"]) !== 0) throw kernelError(`getUinByUids 失败: ${toOptionalString(raw["errMsg"]) ?? ""}`, "UNKNOWN");
|
|
1777
|
+
return toStringMap(raw["uins"]);
|
|
1725
1778
|
}
|
|
1726
1779
|
/** 群成员角色 → OB11 role 字符串。 */
|
|
1727
1780
|
static roleToString(role) {
|
|
@@ -1835,8 +1888,10 @@ var GroupApi = class {
|
|
|
1835
1888
|
if (isKernelError(e)) throw e;
|
|
1836
1889
|
throw kernelError(`getGroupBulletin 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1837
1890
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1891
|
+
const result = isRecord(raw) ? raw["result"] : void 0;
|
|
1892
|
+
const errMsg = isRecord(raw) ? toOptionalString(raw["errMsg"]) : void 0;
|
|
1893
|
+
unwrap("getGroupBulletin", toResultNumber(result), errMsg);
|
|
1894
|
+
return extractBulletins(result);
|
|
1840
1895
|
}
|
|
1841
1896
|
/**
|
|
1842
1897
|
* 发群公告(send_group_announcement;imagePath 提供时先 uploadGroupBulletinPic
|
|
@@ -1887,16 +1942,21 @@ var GroupApi = class {
|
|
|
1887
1942
|
async uploadBulletinPic(groupCode, imagePath) {
|
|
1888
1943
|
const res = await this.service.uploadGroupBulletinPic(groupCode, imagePath);
|
|
1889
1944
|
checkLooseResult("uploadGroupBulletinPic", res);
|
|
1890
|
-
return typeof res
|
|
1945
|
+
return isRecord(res) && typeof res["picId"] === "string" ? res["picId"] : "";
|
|
1891
1946
|
}
|
|
1892
1947
|
/** @all 剩余次数(get_group_at_all_remain)。 */
|
|
1893
1948
|
async getGroupRemainAtTimes(groupCode) {
|
|
1894
1949
|
const raw = await this.service.getGroupRemainAtTimes(groupCode);
|
|
1895
|
-
if (raw
|
|
1950
|
+
if (!isRecord(raw)) throw kernelError("getGroupRemainAtTimes 返回非对象结果", "INVALID_PARAM");
|
|
1951
|
+
const errCode = raw["errCode"];
|
|
1952
|
+
if (typeof errCode === "number" && errCode !== 0) throw kernelError(`getGroupRemainAtTimes 失败: ${typeof raw["errMsg"] === "string" ? raw["errMsg"] : "未知错误"}`, "UNKNOWN");
|
|
1953
|
+
const atInfo = raw["atInfo"];
|
|
1954
|
+
if (!isRecord(atInfo)) throw kernelError("getGroupRemainAtTimes 未返回 atInfo", "INVALID_PARAM");
|
|
1955
|
+
if (!hasBooleanProp(atInfo, "canAtAll") || !hasNumberProp(atInfo, "remainAtAllCountForUin") || !hasNumberProp(atInfo, "remainAtAllCountForGroup")) throw kernelError("getGroupRemainAtTimes 的 atInfo 字段不完整", "INVALID_PARAM");
|
|
1896
1956
|
return {
|
|
1897
|
-
canAtAll:
|
|
1898
|
-
remainAtAllCountForUin:
|
|
1899
|
-
remainAtAllCountForGroup:
|
|
1957
|
+
canAtAll: atInfo["canAtAll"],
|
|
1958
|
+
remainAtAllCountForUin: atInfo["remainAtAllCountForUin"],
|
|
1959
|
+
remainAtAllCountForGroup: atInfo["remainAtAllCountForGroup"]
|
|
1900
1960
|
};
|
|
1901
1961
|
}
|
|
1902
1962
|
};
|
|
@@ -1904,59 +1964,91 @@ var GroupApi = class {
|
|
|
1904
1964
|
function toResultNumber(result) {
|
|
1905
1965
|
return typeof result === "number" ? result : 0;
|
|
1906
1966
|
}
|
|
1967
|
+
/** 未知值 → string | undefined(非字符串一律丢弃)。 */
|
|
1968
|
+
function toOptionalString(value) {
|
|
1969
|
+
return typeof value === "string" ? value : void 0;
|
|
1970
|
+
}
|
|
1971
|
+
/** 字符串键值 Map 收窄(非 Map / 非 string 项丢弃,不做元素级强转)。 */
|
|
1972
|
+
function toStringMap(value) {
|
|
1973
|
+
const out = /* @__PURE__ */ new Map();
|
|
1974
|
+
if (!(value instanceof Map)) return out;
|
|
1975
|
+
for (const [key, val] of value) if (typeof key === "string" && typeof val === "string") out.set(key, val);
|
|
1976
|
+
return out;
|
|
1977
|
+
}
|
|
1978
|
+
/** 群成员形状判定(infos Map 的 value:uid + uin 齐备才算成员)。 */
|
|
1979
|
+
function isGroupMember$1(val) {
|
|
1980
|
+
return isRecord(val) && hasStringProp(val, "uid") && hasStringProp(val, "uin");
|
|
1981
|
+
}
|
|
1982
|
+
/** infos Map → 成员数组(逐项形状校验,非成员项丢弃)。 */
|
|
1983
|
+
function memberListOf(infos) {
|
|
1984
|
+
const out = [];
|
|
1985
|
+
for (const value of infos.values()) if (isGroupMember$1(value)) out.push(value);
|
|
1986
|
+
return out;
|
|
1987
|
+
}
|
|
1988
|
+
/** 群详情形状判定(标识 / 名称 / 成员数四要素齐备才算详情)。 */
|
|
1989
|
+
function isGroupDetailInfo(val) {
|
|
1990
|
+
return isRecord(val) && hasStringProp(val, "groupCode") && hasStringProp(val, "groupName") && hasNumberProp(val, "memberNum") && hasNumberProp(val, "maxMemberNum");
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* 从 getAllMemberList 返回结构取出 infos Map。
|
|
1994
|
+
* 兼容 `{ infos }` 与 `{ result: { infos } }` 两种形状(探测期二者都出现过);
|
|
1995
|
+
* 错误码非 0 抛 UNKNOWN,缺 infos 抛 INVALID_PARAM。
|
|
1996
|
+
*/
|
|
1997
|
+
function extractMemberInfos(raw) {
|
|
1998
|
+
if (!isRecord(raw)) throw kernelError("getAllMemberList 返回格式无效(非对象)", "INVALID_PARAM");
|
|
1999
|
+
const code = toResultNumber(raw["errCode"]);
|
|
2000
|
+
if (code !== 0) throw kernelError(`getAllMemberList 失败 (code=${code}): ${toOptionalString(raw["errMsg"]) ?? "未知错误"}`, "UNKNOWN");
|
|
2001
|
+
const infos = raw["infos"];
|
|
2002
|
+
if (infos instanceof Map) return infos;
|
|
2003
|
+
const nested = raw["result"];
|
|
2004
|
+
if (isRecord(nested)) {
|
|
2005
|
+
const nestedInfos = nested["infos"];
|
|
2006
|
+
if (nestedInfos instanceof Map) return nestedInfos;
|
|
2007
|
+
}
|
|
2008
|
+
throw kernelError("getAllMemberList 返回结果缺失 infos Map", "INVALID_PARAM");
|
|
2009
|
+
}
|
|
1907
2010
|
/** 公告列表宽松提取(result 数组 / { bulletins } / { result: 数组 } 兼容,形状待校准)。 */
|
|
1908
2011
|
function extractBulletins(result) {
|
|
1909
2012
|
const candidates = [result];
|
|
1910
|
-
if (result
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
]) candidates.push(rec[key]);
|
|
1918
|
-
}
|
|
1919
|
-
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter((item) => item !== null && typeof item === "object");
|
|
2013
|
+
if (isRecord(result)) for (const key of [
|
|
2014
|
+
"bulletins",
|
|
2015
|
+
"announcementList",
|
|
2016
|
+
"result",
|
|
2017
|
+
"list"
|
|
2018
|
+
]) candidates.push(result[key]);
|
|
2019
|
+
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter(isRecord);
|
|
1920
2020
|
return [];
|
|
1921
2021
|
}
|
|
1922
2022
|
/**
|
|
1923
2023
|
* 从 getGroupDetailInfo 返回提取群详情(兼容三种形状):
|
|
1924
|
-
* - result
|
|
2024
|
+
* - result 为详情对象 → 直接返回
|
|
1925
2025
|
* - result 为 0/空 → 从 raw.groupInfo / detailInfo / info 提取
|
|
1926
|
-
*
|
|
2026
|
+
* 提取不到(含数组 / 空对象 / 缺字段)返回 null,由调用方抛 KernelError。导出供单测。
|
|
1927
2027
|
*/
|
|
1928
2028
|
function extractGroupDetail(result, raw) {
|
|
1929
|
-
if (result
|
|
1930
|
-
|
|
1931
|
-
const candidate =
|
|
1932
|
-
|
|
1933
|
-
return null;
|
|
2029
|
+
if (isGroupDetailInfo(result)) return result;
|
|
2030
|
+
if (!isRecord(raw)) return null;
|
|
2031
|
+
const candidate = raw["groupInfo"] ?? raw["detailInfo"] ?? raw["info"];
|
|
2032
|
+
return isGroupDetailInfo(candidate) ? candidate : null;
|
|
1934
2033
|
}
|
|
1935
2034
|
// src/apis/group-notify.ts
|
|
1936
|
-
/**
|
|
1937
|
-
* GroupNotifyApi:群通知/禁言列表语义化 API(ADR-009 统一错误语义,P2-13)
|
|
1938
|
-
*
|
|
1939
|
-
* get_group_system_msg / set_group_add_request / get_group_shut_list 共用。
|
|
1940
|
-
* getSingleScreenNotifies / getGroupShutUpMemberList 的列表可能走 listener 回调,
|
|
1941
|
-
* 直接调用返回形状待探测校准:兼容 result 数组 / 字段 / 直接数组。
|
|
1942
|
-
*/
|
|
1943
2035
|
/** 群通知 API:从 session 拿 group service,包装成语义化方法。 */
|
|
1944
2036
|
var GroupNotifyApi = class {
|
|
1945
2037
|
service;
|
|
1946
2038
|
constructor(session) {
|
|
1947
|
-
|
|
1948
|
-
if (service === null || service === void 0) throw kernelError("getGroupService() 返回空(session 未 init)", "INVALID_STATE");
|
|
1949
|
-
this.service = service;
|
|
2039
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", ["getSingleScreenNotifies", "operateSysNotify"]);
|
|
1950
2040
|
}
|
|
1951
2041
|
/** 单屏通知列表(get_group_system_msg / set_group_add_request 共用)。 */
|
|
1952
2042
|
async getSingleScreenNotifies(doubt, count) {
|
|
1953
|
-
|
|
2043
|
+
const raw = await this.service.getSingleScreenNotifies(doubt, "", count);
|
|
2044
|
+
return extractNotifyList(isRecord(raw) ? raw["result"] : void 0);
|
|
1954
2045
|
}
|
|
1955
2046
|
/** 禁言成员列表(get_group_shut_list)。 */
|
|
1956
2047
|
async getGroupShutUpMemberList(groupCode) {
|
|
1957
2048
|
const raw = await this.service.getGroupShutUpMemberList(groupCode);
|
|
1958
|
-
if (raw
|
|
1959
|
-
|
|
2049
|
+
if (!isRecord(raw)) return [];
|
|
2050
|
+
unwrap("getGroupShutUpMemberList", typeof raw["result"] === "number" ? raw["result"] : 0, typeof raw["errMsg"] === "string" ? raw["errMsg"] : void 0);
|
|
2051
|
+
return extractMemberList(raw["result"]);
|
|
1960
2052
|
}
|
|
1961
2053
|
/** 处理群请求(set_group_add_request 应答;approve=true 同意 / false 拒绝)。 */
|
|
1962
2054
|
async handleGroupRequest(doubt, notify, operateType, reason) {
|
|
@@ -1976,23 +2068,35 @@ var GroupNotifyApi = class {
|
|
|
1976
2068
|
});
|
|
1977
2069
|
}
|
|
1978
2070
|
};
|
|
1979
|
-
/**
|
|
2071
|
+
/** 群通知项形状判定(seq 字符串 + type 数字是 GroupNotify 的必备标识)。 */
|
|
2072
|
+
function isGroupNotify(val) {
|
|
2073
|
+
return isRecord(val) && hasStringProp(val, "seq") && hasNumberProp(val, "type");
|
|
2074
|
+
}
|
|
2075
|
+
/** 群成员项形状判定(uid + uin 齐备才算成员)。 */
|
|
2076
|
+
function isGroupMember(val) {
|
|
2077
|
+
return isRecord(val) && hasStringProp(val, "uid") && hasStringProp(val, "uin");
|
|
2078
|
+
}
|
|
2079
|
+
/** 数组逐项守卫过滤(非数组 = 空数组)。 */
|
|
2080
|
+
function filterList(value, guard) {
|
|
2081
|
+
return Array.isArray(value) ? value.filter(guard) : [];
|
|
2082
|
+
}
|
|
2083
|
+
/** 从 getSingleScreenNotifies 返回提取通知数组(兼容 result 数组 / notifies / groupNotifies)。 */
|
|
1980
2084
|
function extractNotifyList(result) {
|
|
1981
|
-
if (Array.isArray(result)) return result;
|
|
1982
|
-
if (result
|
|
1983
|
-
|
|
1984
|
-
if (Array.isArray(obj.notifies)) return obj.notifies;
|
|
1985
|
-
if (Array.isArray(obj.groupNotifies)) return obj.groupNotifies;
|
|
1986
|
-
}
|
|
1987
|
-
return [];
|
|
2085
|
+
if (Array.isArray(result)) return result.filter(isGroupNotify);
|
|
2086
|
+
if (!isRecord(result)) return [];
|
|
2087
|
+
return [...filterList(result["notifies"], isGroupNotify), ...filterList(result["groupNotifies"], isGroupNotify)];
|
|
1988
2088
|
}
|
|
1989
|
-
/** 从 getGroupShutUpMemberList 返回提取成员数组(兼容 result 数组 / memberList
|
|
2089
|
+
/** 从 getGroupShutUpMemberList 返回提取成员数组(兼容 result 数组 / memberList / list / infos Map)。 */
|
|
1990
2090
|
function extractMemberList(result) {
|
|
1991
|
-
if (Array.isArray(result)) return result;
|
|
1992
|
-
if (result
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2091
|
+
if (Array.isArray(result)) return result.filter(isGroupMember);
|
|
2092
|
+
if (!isRecord(result)) return [];
|
|
2093
|
+
const fromFields = [...filterList(result["memberList"], isGroupMember), ...filterList(result["list"], isGroupMember)];
|
|
2094
|
+
if (fromFields.length > 0) return fromFields;
|
|
2095
|
+
const infos = result["infos"];
|
|
2096
|
+
if (infos instanceof Map) {
|
|
2097
|
+
const out = [];
|
|
2098
|
+
for (const item of infos.values()) if (isGroupMember(item)) out.push(item);
|
|
2099
|
+
return out;
|
|
1996
2100
|
}
|
|
1997
2101
|
return [];
|
|
1998
2102
|
}
|
|
@@ -2143,9 +2247,11 @@ var MsgApi = class {
|
|
|
2143
2247
|
/** 上次生成 msgId 的时间(单调递增,2026-08-07 防同毫秒并发碰撞)。 */
|
|
2144
2248
|
lastMsgTime = 0;
|
|
2145
2249
|
constructor(session, channel, util) {
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2250
|
+
this.service = requireKernelService(session.getMsgService(), "getMsgService", [
|
|
2251
|
+
"sendMsg",
|
|
2252
|
+
"recallMsg",
|
|
2253
|
+
"getMsgs"
|
|
2254
|
+
]);
|
|
2149
2255
|
this.channel = channel ?? null;
|
|
2150
2256
|
this.util = util !== null && util !== void 0 ? util : null;
|
|
2151
2257
|
}
|
|
@@ -2639,9 +2745,7 @@ function mapSex(raw) {
|
|
|
2639
2745
|
var ProfileApi = class {
|
|
2640
2746
|
service;
|
|
2641
2747
|
constructor(session) {
|
|
2642
|
-
|
|
2643
|
-
if (service === null || service === void 0) throw kernelError("getProfileService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2644
|
-
this.service = service;
|
|
2748
|
+
this.service = requireKernelService(session.getProfileService(), "getProfileService", ["getUserDetailInfo", "getUserDetailInfoByUin"]);
|
|
2645
2749
|
}
|
|
2646
2750
|
/** 设置个性签名(set_self_longnick)。 */
|
|
2647
2751
|
async setLongNick(longNick) {
|
|
@@ -2688,9 +2792,7 @@ var ProfileApi = class {
|
|
|
2688
2792
|
var ProfileLikeApi = class {
|
|
2689
2793
|
service;
|
|
2690
2794
|
constructor(session) {
|
|
2691
|
-
|
|
2692
|
-
if (service === null || service === void 0) throw kernelError("getProfileLikeService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2693
|
-
this.service = service;
|
|
2795
|
+
this.service = requireKernelService(session.getProfileLikeService(), "getProfileLikeService", ["setBuddyProfileLike"]);
|
|
2694
2796
|
}
|
|
2695
2797
|
/** 点赞(send_like;uid 为目标 uid,count 次数)。 */
|
|
2696
2798
|
async sendLike(uid, count = 1) {
|
|
@@ -2717,9 +2819,7 @@ const RECENT_CONTACT_FETCH_COUNT = 200;
|
|
|
2717
2819
|
var RecentContactApi = class {
|
|
2718
2820
|
service;
|
|
2719
2821
|
constructor(session) {
|
|
2720
|
-
|
|
2721
|
-
if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2722
|
-
this.service = service;
|
|
2822
|
+
this.service = requireKernelService(session.getRecentContactService(), "getRecentContactService", ["getRecentContactList"]);
|
|
2723
2823
|
}
|
|
2724
2824
|
/** 置顶会话列表(get_peer_pins;getRecentContactList 返回形状待探测校准)。 */
|
|
2725
2825
|
async getPinnedContacts() {
|
|
@@ -2803,9 +2903,7 @@ const SPACE_QUERY_FILE_COUNT = 1;
|
|
|
2803
2903
|
var RichMediaApi = class {
|
|
2804
2904
|
service;
|
|
2805
2905
|
constructor(session) {
|
|
2806
|
-
|
|
2807
|
-
if (service === null || service === void 0) throw kernelError("getRichMediaService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2808
|
-
this.service = service;
|
|
2906
|
+
this.service = requireKernelService(session.getRichMediaService(), "getRichMediaService", ["getGroupFileList"]);
|
|
2809
2907
|
}
|
|
2810
2908
|
/** 英文单词翻译(translate_en2zh)。 */
|
|
2811
2909
|
async translateWords(words) {
|
|
@@ -2852,10 +2950,10 @@ var RichMediaApi = class {
|
|
|
2852
2950
|
/** 创建群文件夹(create_group_file_folder)。 */
|
|
2853
2951
|
async createGroupFolder(groupCode, folderName) {
|
|
2854
2952
|
const raw = await this.service.createGroupFolder(groupCode, folderName);
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
return "";
|
|
2953
|
+
checkLooseResult("createGroupFolder", raw);
|
|
2954
|
+
if (!isRecord(raw)) return "";
|
|
2955
|
+
const result = raw["result"];
|
|
2956
|
+
return typeof result === "string" ? result : "";
|
|
2859
2957
|
}
|
|
2860
2958
|
/** 删除群文件(delete_group_file)。 */
|
|
2861
2959
|
async deleteGroupFile(groupCode, fileIds) {
|
|
@@ -2902,25 +3000,31 @@ var RichMediaApi = class {
|
|
|
2902
3000
|
if (raw.result !== 0) unwrap("transGroupFile", raw.result, raw.errMsg);
|
|
2903
3001
|
}
|
|
2904
3002
|
};
|
|
2905
|
-
/**
|
|
3003
|
+
/** 群文件列表项形状判定(fileInfo / folderInfo 出现时必须带齐标识字段)。 */
|
|
3004
|
+
function isGroupFileListItem(val) {
|
|
3005
|
+
if (!isRecord(val)) return false;
|
|
3006
|
+
const fileInfo = val["fileInfo"];
|
|
3007
|
+
const hasValidFile = fileInfo === void 0 || isRecord(fileInfo) && hasStringProp(fileInfo, "fileId") && hasStringProp(fileInfo, "fileName");
|
|
3008
|
+
const folderInfo = val["folderInfo"];
|
|
3009
|
+
const hasValidFolder = folderInfo === void 0 || isRecord(folderInfo) && hasStringProp(folderInfo, "folderId") && hasStringProp(folderInfo, "folderName");
|
|
3010
|
+
return hasValidFile && hasValidFolder;
|
|
3011
|
+
}
|
|
3012
|
+
/** 从 getGroupFileList 返回提取文件列表(兼容数组 / { items } / { item } / { fileList } / { list })。导出供单测。 */
|
|
2906
3013
|
function extractFileList(result) {
|
|
2907
|
-
if (Array.isArray(result)) return result;
|
|
2908
|
-
if (result
|
|
2909
|
-
const
|
|
2910
|
-
|
|
2911
|
-
"items",
|
|
2912
|
-
"fileList",
|
|
2913
|
-
"list"
|
|
2914
|
-
]
|
|
2915
|
-
|
|
2916
|
-
if (Array.isArray(value)) return value;
|
|
2917
|
-
}
|
|
3014
|
+
if (Array.isArray(result)) return result.filter(isGroupFileListItem);
|
|
3015
|
+
if (!isRecord(result)) return [];
|
|
3016
|
+
const candidates = [
|
|
3017
|
+
result["item"],
|
|
3018
|
+
result["items"],
|
|
3019
|
+
result["fileList"],
|
|
3020
|
+
result["list"]
|
|
3021
|
+
];
|
|
3022
|
+
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter(isGroupFileListItem);
|
|
2918
3023
|
return [];
|
|
2919
3024
|
}
|
|
2920
|
-
/**
|
|
3025
|
+
/** 统计文件数量(fileInfo 条目数,数组 / { items } 兼容)。 */
|
|
2921
3026
|
function countGroupFiles(result) {
|
|
2922
|
-
|
|
2923
|
-
return 0;
|
|
3027
|
+
return extractFileList(result).filter((item) => item.fileInfo !== void 0).length;
|
|
2924
3028
|
}
|
|
2925
3029
|
// src/apis/ticket.ts
|
|
2926
3030
|
/**
|
|
@@ -2936,9 +3040,7 @@ const JUMP_TIMEOUT_MS = 1e4;
|
|
|
2936
3040
|
var TicketApi = class {
|
|
2937
3041
|
service;
|
|
2938
3042
|
constructor(session) {
|
|
2939
|
-
|
|
2940
|
-
if (service === null || service === void 0) throw kernelError("getTicketService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2941
|
-
this.service = service;
|
|
3043
|
+
this.service = requireKernelService(session.getTicketService(), "getTicketService", ["forceFetchClientKey"]);
|
|
2942
3044
|
}
|
|
2943
3045
|
/** 获取 clientKey(get_clientkey)。 */
|
|
2944
3046
|
async getClientKey() {
|
|
@@ -2972,9 +3074,9 @@ function fetchJumpCookies(url) {
|
|
|
2972
3074
|
});
|
|
2973
3075
|
req.setTimeout(JUMP_TIMEOUT_MS, () => {
|
|
2974
3076
|
req.destroy();
|
|
2975
|
-
reject(
|
|
3077
|
+
reject(kernelError("获取 cookies 超时", "TIMEOUT"));
|
|
2976
3078
|
});
|
|
2977
|
-
req.on("error", (err) => reject(err));
|
|
3079
|
+
req.on("error", (err) => reject(kernelError(`获取 cookies 网络请求失败: ${err.message}`, "UNKNOWN", { cause: err })));
|
|
2978
3080
|
});
|
|
2979
3081
|
}
|
|
2980
3082
|
/** 解析 set-cookie 头数组 → { name: value } dict。 */
|
|
@@ -3032,10 +3134,9 @@ var WebApi = class {
|
|
|
3032
3134
|
group_code: groupCode
|
|
3033
3135
|
}).toString(), cookie);
|
|
3034
3136
|
if (ret === null || ret.retcode !== 0) return null;
|
|
3035
|
-
const list = ret.data?.msg_list;
|
|
3036
3137
|
return {
|
|
3037
|
-
items:
|
|
3038
|
-
isEnd: ret.
|
|
3138
|
+
items: extractEssenceItems(ret.msgList),
|
|
3139
|
+
isEnd: ret.isEnd
|
|
3039
3140
|
};
|
|
3040
3141
|
}
|
|
3041
3142
|
/** 获取群精华消息列表(get_essence_msg_list;分页拉取至 is_end)。 */
|
|
@@ -3099,31 +3200,47 @@ function parseHonorList(text, type) {
|
|
|
3099
3200
|
} catch {
|
|
3100
3201
|
return [];
|
|
3101
3202
|
}
|
|
3102
|
-
|
|
3203
|
+
if (!isRecord(state)) return [];
|
|
3204
|
+
const raw = type === WebHonorType.TALKATIVE ? state["talkativeList"] : state["actorList"];
|
|
3103
3205
|
if (!Array.isArray(raw)) return [];
|
|
3104
3206
|
const out = [];
|
|
3105
|
-
for (const item of raw)
|
|
3106
|
-
|
|
3207
|
+
for (const item of raw) {
|
|
3208
|
+
if (!isRecord(item)) continue;
|
|
3107
3209
|
out.push({
|
|
3108
|
-
uin: String(
|
|
3109
|
-
name: String(
|
|
3110
|
-
avatar: String(
|
|
3111
|
-
desc: String(
|
|
3210
|
+
uin: String(item["uin"] ?? ""),
|
|
3211
|
+
name: String(item["name"] ?? ""),
|
|
3212
|
+
avatar: String(item["avatar"] ?? ""),
|
|
3213
|
+
desc: String(item["desc"] ?? "")
|
|
3112
3214
|
});
|
|
3113
3215
|
}
|
|
3114
3216
|
return out;
|
|
3115
3217
|
}
|
|
3116
|
-
/**
|
|
3218
|
+
/** 精华消息项形状判定(msg_content 数组是 EssenceMsgItem 的标识字段)。 */
|
|
3219
|
+
function isEssenceMsgItem(val) {
|
|
3220
|
+
return isRecord(val) && Array.isArray(val["msg_content"]);
|
|
3221
|
+
}
|
|
3222
|
+
/** msg_list → 精华消息数组(逐项守卫,非数组 / 残缺项丢弃)。 */
|
|
3223
|
+
function extractEssenceItems(list) {
|
|
3224
|
+
return Array.isArray(list) ? list.filter(isEssenceMsgItem) : [];
|
|
3225
|
+
}
|
|
3226
|
+
/**
|
|
3227
|
+
* 请求 qun.qq.com JSON 接口(带 Cookie;失败返回 null)。
|
|
3228
|
+
* 响应体先过 `isRecord` 收窄再取字段——非对象 JSON(数组 / 标量)按 INVALID_PARAM 抛出。
|
|
3229
|
+
*/
|
|
3117
3230
|
async function fetchQunJson(url, cookie) {
|
|
3118
3231
|
try {
|
|
3119
3232
|
const res = await fetch(url, { headers: { Cookie: cookieToString(cookie) } });
|
|
3120
3233
|
if (!res.ok) return null;
|
|
3121
3234
|
const json = await res.json();
|
|
3235
|
+
if (!isRecord(json)) throw kernelError("群 WebApi 响应非 JSON 对象", "INVALID_PARAM");
|
|
3236
|
+
const data = json["data"];
|
|
3122
3237
|
return {
|
|
3123
|
-
retcode: json
|
|
3124
|
-
data:
|
|
3238
|
+
retcode: typeof json["retcode"] === "number" ? json["retcode"] : -1,
|
|
3239
|
+
msgList: isRecord(data) ? data["msg_list"] : void 0,
|
|
3240
|
+
isEnd: isRecord(data) && data["is_end"] === true
|
|
3125
3241
|
};
|
|
3126
3242
|
} catch (err) {
|
|
3243
|
+
if (isKernelError(err)) throw err;
|
|
3127
3244
|
throw kernelError(`qun.qq.com 请求失败: ${errorMessage(err)}`, "UNKNOWN");
|
|
3128
3245
|
}
|
|
3129
3246
|
}
|
|
@@ -3176,9 +3293,7 @@ var FriendBridge = class {
|
|
|
3176
3293
|
channel;
|
|
3177
3294
|
listenerId = null;
|
|
3178
3295
|
constructor(session, channel) {
|
|
3179
|
-
|
|
3180
|
-
if (service === null || service === void 0) throw kernelError("getBuddyService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3181
|
-
this.service = service;
|
|
3296
|
+
this.service = requireKernelService(session.getBuddyService(), "getBuddyService", ["addKernelBuddyListener"]);
|
|
3182
3297
|
this.channel = channel;
|
|
3183
3298
|
}
|
|
3184
3299
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3217,9 +3332,7 @@ var GroupBridge = class {
|
|
|
3217
3332
|
channel;
|
|
3218
3333
|
listenerId = null;
|
|
3219
3334
|
constructor(session, channel) {
|
|
3220
|
-
|
|
3221
|
-
if (service === null || service === void 0) throw kernelError("getGroupService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3222
|
-
this.service = service;
|
|
3335
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", ["addKernelGroupListener"]);
|
|
3223
3336
|
this.channel = channel;
|
|
3224
3337
|
}
|
|
3225
3338
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3356,9 +3469,7 @@ var MsgBridge = class {
|
|
|
3356
3469
|
channel;
|
|
3357
3470
|
listenerId = null;
|
|
3358
3471
|
constructor(session, channel) {
|
|
3359
|
-
|
|
3360
|
-
if (service === null || service === void 0) throw kernelError("getMsgService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3361
|
-
this.service = service;
|
|
3472
|
+
this.service = requireKernelService(session.getMsgService(), "getMsgService", ["addKernelMsgListener"]);
|
|
3362
3473
|
this.channel = channel;
|
|
3363
3474
|
}
|
|
3364
3475
|
/**
|
|
@@ -3413,9 +3524,7 @@ var RecentContactBridge = class {
|
|
|
3413
3524
|
channel;
|
|
3414
3525
|
listenerId = null;
|
|
3415
3526
|
constructor(session, channel) {
|
|
3416
|
-
|
|
3417
|
-
if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3418
|
-
this.service = service;
|
|
3527
|
+
this.service = requireKernelService(session.getRecentContactService(), "getRecentContactService", ["addKernelRecentContactListener"]);
|
|
3419
3528
|
this.channel = channel;
|
|
3420
3529
|
}
|
|
3421
3530
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3673,8 +3782,16 @@ var GroupCache = class {
|
|
|
3673
3782
|
groupDetails = /* @__PURE__ */ new Map();
|
|
3674
3783
|
/** 群成员:groupCode → (uid → GroupMember)。 */
|
|
3675
3784
|
members = /* @__PURE__ */ new Map();
|
|
3676
|
-
/**
|
|
3677
|
-
|
|
3785
|
+
/**
|
|
3786
|
+
* 惰性回填 in-flight 去重。
|
|
3787
|
+
*
|
|
3788
|
+
* 按返回类型拆成三个精确容器:同 key 并发只拉一次,且取回的值类型由容器
|
|
3789
|
+
* 声明(Promise<Group[]> / Promise<GroupDetailInfo> / Promise<GroupMember[]>)
|
|
3790
|
+
* 自然推导——不再用 `Promise<unknown>` + `as Promise<T>` 假装泛型。
|
|
3791
|
+
*/
|
|
3792
|
+
inFlightGroupList = null;
|
|
3793
|
+
inFlightDetail = /* @__PURE__ */ new Map();
|
|
3794
|
+
inFlightMembers = /* @__PURE__ */ new Map();
|
|
3678
3795
|
unsubscribes = null;
|
|
3679
3796
|
constructor(opts) {
|
|
3680
3797
|
this.channel = opts.channel;
|
|
@@ -3711,7 +3828,9 @@ var GroupCache = class {
|
|
|
3711
3828
|
this.groupList.clear();
|
|
3712
3829
|
this.groupDetails.clear();
|
|
3713
3830
|
this.members.clear();
|
|
3714
|
-
this.
|
|
3831
|
+
this.inFlightGroupList = null;
|
|
3832
|
+
this.inFlightDetail.clear();
|
|
3833
|
+
this.inFlightMembers.clear();
|
|
3715
3834
|
}
|
|
3716
3835
|
/** 释放(等价 unregister,幂等)。 */
|
|
3717
3836
|
dispose() {
|
|
@@ -3773,7 +3892,7 @@ var GroupCache = class {
|
|
|
3773
3892
|
async getGroupDetail(groupCode) {
|
|
3774
3893
|
const cached = this.groupDetails.get(groupCode);
|
|
3775
3894
|
if (cached !== void 0) return cached;
|
|
3776
|
-
const detail = await this.
|
|
3895
|
+
const detail = await this.dedupeMap(this.inFlightDetail, groupCode, () => this.groupApi.getGroupInfo(groupCode));
|
|
3777
3896
|
this.groupDetails.set(groupCode, detail);
|
|
3778
3897
|
return detail;
|
|
3779
3898
|
}
|
|
@@ -3784,7 +3903,7 @@ var GroupCache = class {
|
|
|
3784
3903
|
async getMembers(groupCode) {
|
|
3785
3904
|
const map = this.members.get(groupCode);
|
|
3786
3905
|
if (map !== void 0 && map.size > 0) return [...map.values()];
|
|
3787
|
-
const members = await this.
|
|
3906
|
+
const members = await this.dedupeMap(this.inFlightMembers, groupCode, () => this.groupApi.getGroupMemberList(groupCode, true));
|
|
3788
3907
|
const merged = /* @__PURE__ */ new Map();
|
|
3789
3908
|
for (const member of members) merged.set(member.uid, member);
|
|
3790
3909
|
this.members.set(groupCode, merged);
|
|
@@ -3797,7 +3916,7 @@ var GroupCache = class {
|
|
|
3797
3916
|
async getMember(groupCode, uid) {
|
|
3798
3917
|
const cached = await this.getCachedMember(groupCode, uid);
|
|
3799
3918
|
if (cached !== void 0) return cached;
|
|
3800
|
-
const [member] = await this.
|
|
3919
|
+
const [member] = await this.dedupeMap(this.inFlightMembers, `member:${groupCode}:${uid}`, () => this.groupApi.getGroupMemberInfo(groupCode, [uid]));
|
|
3801
3920
|
if (member === void 0) return;
|
|
3802
3921
|
const target = this.members.get(groupCode);
|
|
3803
3922
|
if (target !== void 0) target.set(member.uid, member);
|
|
@@ -3812,22 +3931,30 @@ var GroupCache = class {
|
|
|
3812
3931
|
}
|
|
3813
3932
|
return map?.get(uid);
|
|
3814
3933
|
}
|
|
3815
|
-
/** 惰性回填全量群列表(getGroup
|
|
3934
|
+
/** 惰性回填全量群列表(getGroup 缺失时;并发调用共享同一次拉取)。 */
|
|
3816
3935
|
async loadGroupList() {
|
|
3817
|
-
|
|
3818
|
-
|
|
3936
|
+
let inFlight = this.inFlightGroupList;
|
|
3937
|
+
if (inFlight === null) {
|
|
3938
|
+
inFlight = this.groupApi.getGroupList(false).finally(() => {
|
|
3939
|
+
this.inFlightGroupList = null;
|
|
3940
|
+
});
|
|
3941
|
+
this.inFlightGroupList = inFlight;
|
|
3942
|
+
}
|
|
3943
|
+
for (const group of await inFlight) this.groupList.set(group.groupCode, group);
|
|
3819
3944
|
}
|
|
3820
|
-
/**
|
|
3821
|
-
|
|
3822
|
-
|
|
3945
|
+
/**
|
|
3946
|
+
* 惰性回填并发去重(按返回类型分容器):同 map + key 并发只拉一次。
|
|
3947
|
+
* loader 的返回值类型即容器元素类型——取回时由 Promise<T> 自然给出 T,
|
|
3948
|
+
* 不需要 `as Promise<T>` 断言。
|
|
3949
|
+
*/
|
|
3950
|
+
async dedupeMap(map, key, loader) {
|
|
3951
|
+
const existing = map.get(key);
|
|
3823
3952
|
if (existing !== void 0) return await existing;
|
|
3824
|
-
const
|
|
3825
|
-
|
|
3826
|
-
}).finally(() => {
|
|
3827
|
-
this.inFlight.delete(key);
|
|
3953
|
+
const promise = loader().finally(() => {
|
|
3954
|
+
map.delete(key);
|
|
3828
3955
|
});
|
|
3829
|
-
|
|
3830
|
-
return await
|
|
3956
|
+
map.set(key, promise);
|
|
3957
|
+
return await promise;
|
|
3831
3958
|
}
|
|
3832
3959
|
};
|
|
3833
3960
|
// src/context.ts
|
|
@@ -3899,6 +4026,43 @@ function createLoginListener() {
|
|
|
3899
4026
|
* T3 单步超时兜底——底层 promise 永久挂起时按登录失败抛出)
|
|
3900
4027
|
*/
|
|
3901
4028
|
/**
|
|
4029
|
+
* 登录服务形状判定:getLoginList / quickLoginWithUin / getMsfStatus 齐备才算可用。
|
|
4030
|
+
* 判空职责从「调用点各自做两级强转」收拢到这里。
|
|
4031
|
+
*/
|
|
4032
|
+
function isLoginServiceShape(val) {
|
|
4033
|
+
return isRecord(val) && hasFunctionProp(val, "getLoginList") && hasFunctionProp(val, "quickLoginWithUin") && hasFunctionProp(val, "getMsfStatus");
|
|
4034
|
+
}
|
|
4035
|
+
/** 校验并收窄 loginService(失败抛 INVALID_STATE,ADR-009)。 */
|
|
4036
|
+
function requireLoginService(raw) {
|
|
4037
|
+
if (!isLoginServiceShape(raw)) throw kernelError("loginService 无效(缺 getLoginList / quickLoginWithUin / getMsfStatus)", "INVALID_STATE");
|
|
4038
|
+
return raw;
|
|
4039
|
+
}
|
|
4040
|
+
/** 连接方法面判定(connect / add / remove 监听存在时必须是函数)。 */
|
|
4041
|
+
function isLoginConnectionShape(val) {
|
|
4042
|
+
if (!isRecord(val)) return false;
|
|
4043
|
+
const connect = val["connect"];
|
|
4044
|
+
const addListener = val["addKernelLoginListener"];
|
|
4045
|
+
const removeListener = val["removeKernelLoginListener"];
|
|
4046
|
+
return (connect === void 0 || typeof connect === "function") && (addListener === void 0 || typeof addListener === "function") && (removeListener === void 0 || typeof removeListener === "function");
|
|
4047
|
+
}
|
|
4048
|
+
/** 登录列表项形状判定(uin 是唯一必填字段)。 */
|
|
4049
|
+
function isLoginAccountInfo(val) {
|
|
4050
|
+
return isRecord(val) && hasStringProp(val, "uin");
|
|
4051
|
+
}
|
|
4052
|
+
/** getLoginList 返回 → 登录列表(形状异常返回空数组,不抛裸 TypeError)。 */
|
|
4053
|
+
function extractLoginAccounts(list) {
|
|
4054
|
+
if (!isRecord(list)) return [];
|
|
4055
|
+
const items = list["LocalLoginInfoList"];
|
|
4056
|
+
return Array.isArray(items) ? items.filter(isLoginAccountInfo) : [];
|
|
4057
|
+
}
|
|
4058
|
+
/** quickLoginWithUin 返回 → errMsg(结构缺失按「未知登录错误」处理)。 */
|
|
4059
|
+
function extractLoginErrMsg(result) {
|
|
4060
|
+
if (!isRecord(result)) return "未知登录错误";
|
|
4061
|
+
const info = result["loginErrorInfo"];
|
|
4062
|
+
if (isRecord(info) && typeof info["errMsg"] === "string") return info["errMsg"];
|
|
4063
|
+
return "未知登录错误";
|
|
4064
|
+
}
|
|
4065
|
+
/**
|
|
3902
4066
|
* 网络状态(MSF)常量。
|
|
3903
4067
|
* 3 = 已连接(NapCat waitForNetworkConnection 语义,自研描述)。
|
|
3904
4068
|
*/
|
|
@@ -3925,10 +4089,10 @@ const QUICK_LOGIN_TIMEOUT_MESSAGE = "快速登录超时";
|
|
|
3925
4089
|
*/
|
|
3926
4090
|
function waitForNetworkConnection(ctx, opts = {}) {
|
|
3927
4091
|
const raw = ctx.loginService;
|
|
3928
|
-
if (raw
|
|
4092
|
+
if (!isRecord(raw) || !hasFunctionProp(raw, "getMsfStatus")) return Promise.resolve(false);
|
|
3929
4093
|
return waitFor(() => {
|
|
3930
4094
|
try {
|
|
3931
|
-
return raw
|
|
4095
|
+
return raw["getMsfStatus"]() === MSF_STATUS_CONNECTED;
|
|
3932
4096
|
} catch {
|
|
3933
4097
|
return false;
|
|
3934
4098
|
}
|
|
@@ -3936,9 +4100,7 @@ function waitForNetworkConnection(ctx, opts = {}) {
|
|
|
3936
4100
|
}
|
|
3937
4101
|
/** 列出历史登录账号(boot.cjs 启动横幅用,「可用快速登录 of QQ」)。 */
|
|
3938
4102
|
async function listLoginAccounts(ctx) {
|
|
3939
|
-
|
|
3940
|
-
if (raw === null) throw kernelError("loginService 无效(缺 getLoginList)", "INVALID_STATE");
|
|
3941
|
-
return (await raw.getLoginList()).LocalLoginInfoList;
|
|
4103
|
+
return extractLoginAccounts(await requireLoginService(ctx.loginService).getLoginList());
|
|
3942
4104
|
}
|
|
3943
4105
|
/**
|
|
3944
4106
|
* 登录服务连接(自建宿主必需,HANDOVER-V6/V10 p0-kernel-flow 实证顺序):
|
|
@@ -3950,7 +4112,7 @@ async function listLoginAccounts(ctx) {
|
|
|
3950
4112
|
*/
|
|
3951
4113
|
async function ensureLoginConnected(ctx, opts) {
|
|
3952
4114
|
const raw = ctx.loginService;
|
|
3953
|
-
if (raw
|
|
4115
|
+
if (!isLoginConnectionShape(raw) || typeof raw.connect !== "function") return;
|
|
3954
4116
|
await waitLoginConnected(raw, opts.timeoutMs);
|
|
3955
4117
|
await sleep(CONNECTION_SETTLE_MS);
|
|
3956
4118
|
}
|
|
@@ -4062,7 +4224,7 @@ async function loginWithNetworkRetry(ctx, loginService, target, opts, quickTimeo
|
|
|
4062
4224
|
}
|
|
4063
4225
|
/** 单次快速登录尝试(成功带结果,失败带错误消息)。 */
|
|
4064
4226
|
async function attemptQuickLogin(loginService, target) {
|
|
4065
|
-
const
|
|
4227
|
+
const errMsg = extractLoginErrMsg(await loginService.quickLoginWithUin(target.uin));
|
|
4066
4228
|
if (errMsg) return {
|
|
4067
4229
|
ok: false,
|
|
4068
4230
|
errMsg
|
|
@@ -4088,14 +4250,12 @@ function isNetworkError(errMsg) {
|
|
|
4088
4250
|
* 抛出,上层 catch/qrFallback 语义自动生效。
|
|
4089
4251
|
*/
|
|
4090
4252
|
async function quickLogin(ctx, opts = {}) {
|
|
4091
|
-
const
|
|
4092
|
-
if (raw === null) throw kernelError("loginService 无效(缺 getLoginList)", "INVALID_STATE");
|
|
4093
|
-
const loginService = raw;
|
|
4253
|
+
const loginService = requireLoginService(ctx.loginService);
|
|
4094
4254
|
const quickTimeoutMs = opts.quickLoginTimeoutMs ?? 2e4;
|
|
4095
4255
|
await ensureLoginConnected(ctx, { ...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {} });
|
|
4096
|
-
const items = (await raceWithTimeout(loginService.getLoginList(), quickTimeoutMs, () => {
|
|
4256
|
+
const items = extractLoginAccounts(await raceWithTimeout(loginService.getLoginList(), quickTimeoutMs, () => {
|
|
4097
4257
|
throw kernelError(`快速登录失败: ${QUICK_LOGIN_TIMEOUT_MESSAGE}`, "NOT_LOGIN");
|
|
4098
|
-
}))
|
|
4258
|
+
}));
|
|
4099
4259
|
if (items.length === 0) throw kernelError("无历史登录账号", "NOT_LOGIN");
|
|
4100
4260
|
return loginWithNetworkRetry(ctx, loginService, pickLoginTarget(items, opts.uin), opts, quickTimeoutMs);
|
|
4101
4261
|
}
|
|
@@ -5290,14 +5450,14 @@ var NapukettoCore = class NapukettoCore {
|
|
|
5290
5450
|
* QQ 主进程(V1)模式 QQ 自己 initConfig 过正确路径,无需解析。
|
|
5291
5451
|
*/
|
|
5292
5452
|
initLoginConfig(wrapper, appid) {
|
|
5293
|
-
const
|
|
5294
|
-
if (
|
|
5453
|
+
const raw = wrapper.loginService;
|
|
5454
|
+
if (!isRecord(raw) || !hasInitConfig(raw)) {
|
|
5295
5455
|
this.ctx.logger.warn("loginService 不可用,跳过 initConfig");
|
|
5296
5456
|
return;
|
|
5297
5457
|
}
|
|
5298
5458
|
const commonPath = resolveCommonPath(this.ctx, wrapper);
|
|
5299
5459
|
const loginCfg = buildLoginConfig(appid, wrapper.versionInfo.fullVersion, commonPath);
|
|
5300
|
-
|
|
5460
|
+
raw["initConfig"](loginCfg);
|
|
5301
5461
|
this.ctx.logger.info({ commonPath }, "loginService.initConfig OK");
|
|
5302
5462
|
}
|
|
5303
5463
|
/**
|
|
@@ -5356,7 +5516,8 @@ var NapukettoCore = class NapukettoCore {
|
|
|
5356
5516
|
/** QR 状态转发:日志 + onLoginProgress(failed 附 failureReason)。 */
|
|
5357
5517
|
forwardQrState(session, opts, state) {
|
|
5358
5518
|
this.ctx.logger.info({ state }, "QR 登录状态");
|
|
5359
|
-
|
|
5519
|
+
const progress = qrProgressEvent(state, session.selfInfo, session.failureReason);
|
|
5520
|
+
if (progress !== null) opts.onLoginProgress?.(progress);
|
|
5360
5521
|
}
|
|
5361
5522
|
/**
|
|
5362
5523
|
* 停止:幂等清理 QR 会话 + 已装配的运行时服务(桥/缓存/通道)后日志收尾。
|
|
@@ -5410,6 +5571,14 @@ function resolveSessionAccountPath(ctx, wrapper) {
|
|
|
5410
5571
|
const root = resolveQqUserDataRoot(wrapper.exports, { dataRoot: ctx.paths.root });
|
|
5411
5572
|
return root !== null ? resolveQqGlobalPath(root) : ctx.paths.accountDir;
|
|
5412
5573
|
}
|
|
5574
|
+
/**
|
|
5575
|
+
* loginService.initConfig 形状守卫(可带一个配置参数调用)。
|
|
5576
|
+
* `hasFunctionProp` 的函数类型是「零参可调用」(`(...args: never[])`),
|
|
5577
|
+
* 这里需要带参调用,故给一个精确到参数的谓词。
|
|
5578
|
+
*/
|
|
5579
|
+
function hasInitConfig(val) {
|
|
5580
|
+
return typeof val["initConfig"] === "function";
|
|
5581
|
+
}
|
|
5413
5582
|
/** 写二维码 png 到磁盘(base64 解码,供 cli/用户扫码)。 */
|
|
5414
5583
|
function writeQrCodePng(filePath, pngBase64) {
|
|
5415
5584
|
try {
|
|
@@ -5430,13 +5599,29 @@ function requireQrSelfInfo(session) {
|
|
|
5430
5599
|
if (self === null) throw kernelError("QR 登录成功但 selfInfo 为空", "INVALID_STATE");
|
|
5431
5600
|
return self;
|
|
5432
5601
|
}
|
|
5433
|
-
/**
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5602
|
+
/**
|
|
5603
|
+
* QR 进度事件折叠(可辨识联合,判别字段 = state)。
|
|
5604
|
+
*
|
|
5605
|
+
* 返回 null = 该状态不单独上报:
|
|
5606
|
+
* - waiting_scan:二维码数据由 `subscribeQrProgress` 的 onQrCode 回执发出
|
|
5607
|
+
* (那里才拿得到 qr),状态机这次先不带 qr 的事件不再重复发;
|
|
5608
|
+
* - logged_in 且 selfInfo 仍为空:会话已损坏(调用方随后按 INVALID_STATE 拒绝),
|
|
5609
|
+
* 不构造自相矛盾的 logged_in 事件。
|
|
5610
|
+
*/
|
|
5611
|
+
function qrProgressEvent(state, selfInfo, reason) {
|
|
5612
|
+
switch (state) {
|
|
5613
|
+
case "idle": return { state };
|
|
5614
|
+
case "waiting_scan": return null;
|
|
5615
|
+
case "scanned": return { state };
|
|
5616
|
+
case "logged_in": return selfInfo === null ? null : {
|
|
5617
|
+
state,
|
|
5618
|
+
selfInfo
|
|
5619
|
+
};
|
|
5620
|
+
case "failed": return {
|
|
5621
|
+
state,
|
|
5622
|
+
message: reason ?? ""
|
|
5623
|
+
};
|
|
5624
|
+
}
|
|
5440
5625
|
}
|
|
5441
5626
|
/** 等待 QR 登录终态:logged_in resolve,failed reject。 */
|
|
5442
5627
|
function waitQrLoggedIn(session) {
|
|
@@ -6289,6 +6474,6 @@ function listQQVersions(installDir) {
|
|
|
6289
6474
|
return statSync(full).isDirectory() && existsSync(join(full, "resources", "app", "wrapper.node"));
|
|
6290
6475
|
}).sort().reverse();
|
|
6291
6476
|
}
|
|
6292
|
-
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, DependsAdapter, DispatcherAdapter, EXIT_CONFIG_INVALID, ElementType, FlashTransferApi, FriendApi, FriendBridge, GlobalAdapter, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, GroupMemberDataSource, GroupNotifyApi, GroupNotifyMsgStatus, GroupNotifyMsgType, KERNEL_ERROR_CODES, KernelError, LoginBridge, MAIN_CONFIG_FILE, MsgApi, MsgBridge, NTEventChannel, NTGroupMemberRole, NTGroupRequestOperateTypes, NapukettoCore, PathWrapper, ProfileApi, ProfileLikeApi, QrLoginSession, RecentContactApi, RecentContactBridge, RichMediaApi, TicketApi, TipGroupElementType, VIDEO_THUMB_KEY, WebApi, WebHonorType, activateO3MiscService, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createConsoleFormatStream, createCoreContext, createKernelRuntime, createSessionListener as createLifecycleSessionListener, createSessionListener, createLogger, createLoginListener, createRecordingListener, createSession, createWrapper, dlopenWrapper, electronProcessType, errorMessage, getExistingSession, getMainSession, initAndStartSession, initEngine, initSession, isKernelError, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, parseAppidFromMajor, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveWrapperPath, sleep, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitFor, waitForNetworkConnection, waitSessionReady };
|
|
6477
|
+
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, DependsAdapter, DispatcherAdapter, EXIT_CONFIG_INVALID, ElementType, FlashTransferApi, FriendApi, FriendBridge, GlobalAdapter, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, GroupMemberDataSource, GroupNotifyApi, GroupNotifyMsgStatus, GroupNotifyMsgType, KERNEL_ERROR_CODES, KernelError, LoginBridge, MAIN_CONFIG_FILE, MsgApi, MsgBridge, NTEventChannel, NTGroupMemberRole, NTGroupRequestOperateTypes, NapukettoCore, PathWrapper, ProfileApi, ProfileLikeApi, QrLoginSession, RecentContactApi, RecentContactBridge, RichMediaApi, TicketApi, TipGroupElementType, VIDEO_THUMB_KEY, WebApi, WebHonorType, activateO3MiscService, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createConsoleFormatStream, createCoreContext, createKernelRuntime, createSessionListener as createLifecycleSessionListener, createSessionListener, createLogger, createLoginListener, createRecordingListener, createSession, createWrapper, dlopenWrapper, electronProcessType, errorMessage, getExistingSession, getMainSession, hasBooleanProp, hasFunctionProp, hasNumberProp, hasStringProp, initAndStartSession, initEngine, initSession, isKernelError, isRecord, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, parseAppidFromMajor, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, requireKernelService, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveWrapperPath, sleep, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitFor, waitForNetworkConnection, waitSessionReady };
|
|
6293
6478
|
|
|
6294
6479
|
//# sourceMappingURL=index.mjs.map
|