@napuketto/kernel 0.12.0 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +502 -458
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +171 -148
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -41,6 +41,10 @@ function kernelError(message, code = "UNKNOWN", options) {
|
|
|
41
41
|
function isKernelError(err) {
|
|
42
42
|
return err instanceof KernelError;
|
|
43
43
|
}
|
|
44
|
+
/** 提取未知异常的文本消息(Error 取 message,其余转字符串)。 */
|
|
45
|
+
function errorMessage(err) {
|
|
46
|
+
return err instanceof Error ? err.message : String(err);
|
|
47
|
+
}
|
|
44
48
|
/**
|
|
45
49
|
* 配置校验失败(INVALID_PARAM 子型,2026-10-25 嵌入式宿主契约):仅用于
|
|
46
50
|
* 「配置未就绪」一族——主配置校验/反序列化、内联配置、协议段 seed 校验。
|
|
@@ -124,7 +128,7 @@ var ConfigBase = class {
|
|
|
124
128
|
await this.save(this.defaults);
|
|
125
129
|
return this.value;
|
|
126
130
|
}
|
|
127
|
-
throw
|
|
131
|
+
throw configError(`读取配置文件失败: ${this.path}`, { cause: err });
|
|
128
132
|
}
|
|
129
133
|
this.value = this.parse(raw);
|
|
130
134
|
return this.value;
|
|
@@ -162,12 +166,12 @@ var ConfigBase = class {
|
|
|
162
166
|
try {
|
|
163
167
|
input = this.deserialize(raw);
|
|
164
168
|
} catch (err) {
|
|
165
|
-
throw
|
|
169
|
+
throw configError(`配置文件 ${this.format.toUpperCase()} 解析失败: ${this.path}`, { cause: err });
|
|
166
170
|
}
|
|
167
171
|
try {
|
|
168
172
|
return this.schema.parse(input);
|
|
169
173
|
} catch (err) {
|
|
170
|
-
throw
|
|
174
|
+
throw configError(`配置文件校验失败: ${this.path}`, { cause: err });
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
};
|
|
@@ -611,7 +615,7 @@ function wallMs() {
|
|
|
611
615
|
}
|
|
612
616
|
function toSingle(streams) {
|
|
613
617
|
const [only] = streams;
|
|
614
|
-
if (only === void 0) throw
|
|
618
|
+
if (only === void 0) throw kernelError("logger 内部错误:目的地列表为空", "UNKNOWN");
|
|
615
619
|
return only.stream;
|
|
616
620
|
}
|
|
617
621
|
/** 控制台目的地(console=false 返回 null)。 */
|
|
@@ -665,7 +669,7 @@ function createLogger(opts = {}) {
|
|
|
665
669
|
timestamp: opts.timestamp ?? "local",
|
|
666
670
|
colorize: opts.colorize ?? (format === "pretty" && isTty)
|
|
667
671
|
}, destination), buildFileTarget(opts, opts.fileLevel ?? consoleLevel)].filter((target) => target !== null);
|
|
668
|
-
if (targets.length === 0) throw
|
|
672
|
+
if (targets.length === 0) throw kernelError("logger 至少需要一个输出目标:console 或 file", "INVALID_PARAM");
|
|
669
673
|
const pinoOptions = {
|
|
670
674
|
level: gateLevel(targets),
|
|
671
675
|
redact: [...DEFAULT_REDACT_PATHS, ...opts.redact ?? []],
|
|
@@ -720,7 +724,7 @@ function resolveProjectRoot() {
|
|
|
720
724
|
* 返回绝对路径。独立导出便于 cli / 探测脚本复用。
|
|
721
725
|
*/
|
|
722
726
|
function resolveDataRoot(dataRoot) {
|
|
723
|
-
const explicit = dataRoot ?? process.env["NAPKETTO_DATA"];
|
|
727
|
+
const explicit = dataRoot ?? process.env["NAPUKETTO_DATA"] ?? process.env["NAPKETTO_DATA"];
|
|
724
728
|
if (explicit !== void 0 && explicit !== "") return resolve(expandTilde(explicit));
|
|
725
729
|
const projectRoot = resolveProjectRoot();
|
|
726
730
|
if (projectRoot !== void 0) return join(projectRoot, DEFAULT_DATA_ROOT_NAME);
|
|
@@ -748,7 +752,7 @@ function findProjectRoot(startDir, marker) {
|
|
|
748
752
|
* 返回绝对路径。独立导出便于 cli / loader 装配链复用。
|
|
749
753
|
*/
|
|
750
754
|
function resolveConfigPath(opts = {}) {
|
|
751
|
-
const explicit = process.env["NAPKETTO_CONFIG"];
|
|
755
|
+
const explicit = process.env["NAPUKETTO_CONFIG"] ?? process.env["NAPKETTO_CONFIG"];
|
|
752
756
|
if (explicit !== void 0 && explicit !== "") return resolve(explicit);
|
|
753
757
|
const projectRoot = resolveProjectRoot();
|
|
754
758
|
if (projectRoot !== void 0) return join(projectRoot, MAIN_CONFIG_FILE);
|
|
@@ -807,6 +811,37 @@ var PathWrapper = class {
|
|
|
807
811
|
});
|
|
808
812
|
}
|
|
809
813
|
};
|
|
814
|
+
// src/infra/wait.ts
|
|
815
|
+
/**
|
|
816
|
+
* 等待/延迟工具(通用底层原语,2026-08-08 克隆合并;2026-11 下沉至 infra)
|
|
817
|
+
*
|
|
818
|
+
* 纯 promise 工具,无任何业务依赖——login / cache 等上层模块经
|
|
819
|
+
* `infra/index.js` 复用,杜绝 cache -> login 的跨领域依赖。
|
|
820
|
+
*/
|
|
821
|
+
/** 等待条件满足(轮询,带超时)。 */
|
|
822
|
+
function waitFor(predicate, timeoutMs, intervalMs = 500) {
|
|
823
|
+
return new Promise((resolve) => {
|
|
824
|
+
const started = Date.now();
|
|
825
|
+
const tick = () => {
|
|
826
|
+
if (predicate()) {
|
|
827
|
+
resolve(true);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (Date.now() - started > timeoutMs) {
|
|
831
|
+
resolve(false);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
setTimeout(tick, intervalMs);
|
|
835
|
+
};
|
|
836
|
+
tick();
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
/** 短延迟。 */
|
|
840
|
+
function sleep(ms) {
|
|
841
|
+
return new Promise((resolve) => {
|
|
842
|
+
setTimeout(resolve, ms);
|
|
843
|
+
});
|
|
844
|
+
}
|
|
810
845
|
// src/apis/result.ts
|
|
811
846
|
/**
|
|
812
847
|
* 原生调用结果解包(ADR-009 统一错误语义)
|
|
@@ -913,7 +948,7 @@ var FlashTransferApi = class {
|
|
|
913
948
|
} catch (e) {
|
|
914
949
|
clearTimer(state.timer);
|
|
915
950
|
this.detachQuietly(listener);
|
|
916
|
-
throw kernelError(`createFlashTransferUploadTask 失败: ${
|
|
951
|
+
throw kernelError(`createFlashTransferUploadTask 失败: ${errorMessage(e)}`, "UNKNOWN", { cause: e });
|
|
917
952
|
}
|
|
918
953
|
try {
|
|
919
954
|
await done;
|
|
@@ -1186,13 +1221,49 @@ const TipGroupElementType = {
|
|
|
1186
1221
|
UNBLOCK: 7,
|
|
1187
1222
|
SHUT_UP: 8
|
|
1188
1223
|
};
|
|
1189
|
-
// src/types/
|
|
1190
|
-
/**
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1224
|
+
// src/types/services/group-service.ts
|
|
1225
|
+
/** 群成员角色(QQ wrapper 契约)。 */
|
|
1226
|
+
const NTGroupMemberRole = {
|
|
1227
|
+
UNSPECIFIED: 0,
|
|
1228
|
+
STRANGER: 1,
|
|
1229
|
+
MEMBER: 2,
|
|
1230
|
+
ADMIN: 3,
|
|
1231
|
+
OWNER: 4
|
|
1232
|
+
};
|
|
1233
|
+
/** 群通知类型(GroupNotifyMsgType,说明书参考)。 */
|
|
1234
|
+
const GroupNotifyMsgType = {
|
|
1235
|
+
UN_SPECIFIED: 0,
|
|
1236
|
+
INVITED_BY_MEMBER: 1,
|
|
1237
|
+
REFUSE_INVITED: 2,
|
|
1238
|
+
REFUSED_BY_ADMINI_STRATOR: 3,
|
|
1239
|
+
AGREED_TOJOIN_DIRECT: 4,
|
|
1240
|
+
INVITED_NEED_ADMINI_STRATOR_PASS: 5,
|
|
1241
|
+
AGREED_TO_JOIN_BY_ADMINI_STRATOR: 6,
|
|
1242
|
+
REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS: 7,
|
|
1243
|
+
SET_ADMIN: 8,
|
|
1244
|
+
KICK_MEMBER_NOTIFY_ADMIN: 9,
|
|
1245
|
+
KICK_MEMBER_NOTIFY_KICKED: 10,
|
|
1246
|
+
MEMBER_LEAVE_NOTIFY_ADMIN: 11,
|
|
1247
|
+
CANCEL_ADMIN_NOTIFY_CANCELED: 12,
|
|
1248
|
+
CANCEL_ADMIN_NOTIFY_ADMIN: 13,
|
|
1249
|
+
TRANSFER_GROUP_NOTIFY_OLDOWNER: 14,
|
|
1250
|
+
TRANSFER_GROUP_NOTIFY_ADMIN: 15
|
|
1251
|
+
};
|
|
1252
|
+
/** 群通知处理状态(GroupNotifyMsgStatus,说明书参考)。 */
|
|
1253
|
+
const GroupNotifyMsgStatus = {
|
|
1254
|
+
KINIT: 0,
|
|
1255
|
+
KUNHANDLE: 1,
|
|
1256
|
+
KAGREED: 2,
|
|
1257
|
+
KREFUSED: 3,
|
|
1258
|
+
KIGNORED: 4
|
|
1259
|
+
};
|
|
1260
|
+
/** 群请求操作类型(NTGroupRequestOperateTypes,说明书参考)。 */
|
|
1261
|
+
const NTGroupRequestOperateTypes = {
|
|
1262
|
+
KUNSPECIFIED: 0,
|
|
1263
|
+
KAGREE: 1,
|
|
1264
|
+
KREFUSE: 2,
|
|
1265
|
+
KIGNORE: 3,
|
|
1266
|
+
KDELETE: 4
|
|
1196
1267
|
};
|
|
1197
1268
|
// src/types/services/msg-service.ts
|
|
1198
1269
|
/** 消息元素类型枚举(QQ wrapper 外部契约,自研描述)。 */
|
|
@@ -1218,13 +1289,15 @@ const ElementType = {
|
|
|
1218
1289
|
INTEXT_GIFT: 18,
|
|
1219
1290
|
CALENDAR: 19
|
|
1220
1291
|
};
|
|
1221
|
-
// src/
|
|
1292
|
+
// src/codec/message-element.ts
|
|
1222
1293
|
/**
|
|
1223
|
-
* canonical
|
|
1294
|
+
* canonical 消息元素双向转换(NT wrapper ↔ 协议无关中间表示)
|
|
1295
|
+
*
|
|
1296
|
+
* 2026-11 从 `types/message-element.ts` 下沉:类型层保持纯声明(无 node:fs /
|
|
1297
|
+
* infra 运行时依赖),本文件承担全部运行时转换与本地路径存在性校验。
|
|
1224
1298
|
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
* 各协议(onebot11/satori)只写薄映射 canonical ↔ 协议格式。
|
|
1299
|
+
* kernel 只做一次 NT ↔ canonical 转换,各协议(onebot11/satori)只写薄映射
|
|
1300
|
+
* canonical ↔ 协议格式。
|
|
1228
1301
|
*/
|
|
1229
1302
|
/** 文本 at 类型(QQ wrapper 契约,自研描述)。 */
|
|
1230
1303
|
const AtType = {
|
|
@@ -1233,12 +1306,6 @@ const AtType = {
|
|
|
1233
1306
|
ME: 4
|
|
1234
1307
|
};
|
|
1235
1308
|
/**
|
|
1236
|
-
* 视频缩略图在 thumbPath 中的 key(收向实测 Map<0, path>;平面对象形态下
|
|
1237
|
-
* 数字 key 经序列化变字符串 "0"。apis/msg.ts 发送侧有同名常量,types 层
|
|
1238
|
-
* 不能反向 import apis(依赖方向),此处独立定义)。
|
|
1239
|
-
*/
|
|
1240
|
-
const VIDEO_THUMB_KEY$1 = 0;
|
|
1241
|
-
/**
|
|
1242
1309
|
* 读视频缩略图路径(接收方向形态不唯一,防御读取):
|
|
1243
1310
|
* - 进程内为 `Map<0, path>`(收向实测);
|
|
1244
1311
|
* - 跨进程/JSON 序列化后退化为平面对象 `{"0": path}`(`JSON.stringify(Map)`
|
|
@@ -1252,10 +1319,10 @@ function readVideoThumbPath(thumb) {
|
|
|
1252
1319
|
if (thumb === void 0 || thumb === "") return;
|
|
1253
1320
|
if (typeof thumb === "string") return thumb;
|
|
1254
1321
|
if (thumb instanceof Map) {
|
|
1255
|
-
const value = thumb.get(
|
|
1322
|
+
const value = thumb.get(0);
|
|
1256
1323
|
return value === "" ? void 0 : value;
|
|
1257
1324
|
}
|
|
1258
|
-
const value = thumb[String(
|
|
1325
|
+
const value = thumb[String(0)];
|
|
1259
1326
|
return value === "" ? void 0 : value;
|
|
1260
1327
|
}
|
|
1261
1328
|
/** TEXT 元素 → canonical(at 或纯文本)。 */
|
|
@@ -1460,7 +1527,7 @@ function jsonToArkBytes(raw) {
|
|
|
1460
1527
|
try {
|
|
1461
1528
|
return JSON.stringify(raw) ?? "";
|
|
1462
1529
|
} catch (err) {
|
|
1463
|
-
throw kernelError(`json 元素序列化失败: ${
|
|
1530
|
+
throw kernelError(`json 元素序列化失败: ${errorMessage(err)}`, "INVALID_PARAM");
|
|
1464
1531
|
}
|
|
1465
1532
|
}
|
|
1466
1533
|
/** canonical 元素 → NT 发送元素(text/at/face/image/voice/reply 核心 + json ARK 透传)。 */
|
|
@@ -1532,49 +1599,13 @@ function toSendElements(elements) {
|
|
|
1532
1599
|
}
|
|
1533
1600
|
return out;
|
|
1534
1601
|
}
|
|
1535
|
-
// src/types/
|
|
1536
|
-
/**
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
OWNER: 4
|
|
1543
|
-
};
|
|
1544
|
-
/** 群通知类型(GroupNotifyMsgType,说明书参考)。 */
|
|
1545
|
-
const GroupNotifyMsgType = {
|
|
1546
|
-
UN_SPECIFIED: 0,
|
|
1547
|
-
INVITED_BY_MEMBER: 1,
|
|
1548
|
-
REFUSE_INVITED: 2,
|
|
1549
|
-
REFUSED_BY_ADMINI_STRATOR: 3,
|
|
1550
|
-
AGREED_TOJOIN_DIRECT: 4,
|
|
1551
|
-
INVITED_NEED_ADMINI_STRATOR_PASS: 5,
|
|
1552
|
-
AGREED_TO_JOIN_BY_ADMINI_STRATOR: 6,
|
|
1553
|
-
REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS: 7,
|
|
1554
|
-
SET_ADMIN: 8,
|
|
1555
|
-
KICK_MEMBER_NOTIFY_ADMIN: 9,
|
|
1556
|
-
KICK_MEMBER_NOTIFY_KICKED: 10,
|
|
1557
|
-
MEMBER_LEAVE_NOTIFY_ADMIN: 11,
|
|
1558
|
-
CANCEL_ADMIN_NOTIFY_CANCELED: 12,
|
|
1559
|
-
CANCEL_ADMIN_NOTIFY_ADMIN: 13,
|
|
1560
|
-
TRANSFER_GROUP_NOTIFY_OLDOWNER: 14,
|
|
1561
|
-
TRANSFER_GROUP_NOTIFY_ADMIN: 15
|
|
1562
|
-
};
|
|
1563
|
-
/** 群通知处理状态(GroupNotifyMsgStatus,说明书参考)。 */
|
|
1564
|
-
const GroupNotifyMsgStatus = {
|
|
1565
|
-
KINIT: 0,
|
|
1566
|
-
KUNHANDLE: 1,
|
|
1567
|
-
KAGREED: 2,
|
|
1568
|
-
KREFUSED: 3,
|
|
1569
|
-
KIGNORED: 4
|
|
1570
|
-
};
|
|
1571
|
-
/** 群请求操作类型(NTGroupRequestOperateTypes,说明书参考)。 */
|
|
1572
|
-
const NTGroupRequestOperateTypes = {
|
|
1573
|
-
KUNSPECIFIED: 0,
|
|
1574
|
-
KAGREE: 1,
|
|
1575
|
-
KREFUSE: 2,
|
|
1576
|
-
KIGNORE: 3,
|
|
1577
|
-
KDELETE: 4
|
|
1602
|
+
// src/types/listeners/group.ts
|
|
1603
|
+
/** 群列表更新类型(说明书参考,值待探测校准)。 */
|
|
1604
|
+
const GroupListUpdateType = {
|
|
1605
|
+
/** 全量更新(groupList 为完整列表)。 */
|
|
1606
|
+
ALL: 0,
|
|
1607
|
+
/** 增量更新(合并到现有缓存)。 */
|
|
1608
|
+
PARTIAL: 1
|
|
1578
1609
|
};
|
|
1579
1610
|
// src/types/wrapper.ts
|
|
1580
1611
|
/**
|
|
@@ -1786,7 +1817,7 @@ var GroupApi = class {
|
|
|
1786
1817
|
raw = await this.service.getGroupBulletin(groupCode);
|
|
1787
1818
|
} catch (e) {
|
|
1788
1819
|
if (isKernelError(e)) throw e;
|
|
1789
|
-
throw kernelError(`getGroupBulletin 调用失败: ${
|
|
1820
|
+
throw kernelError(`getGroupBulletin 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1790
1821
|
}
|
|
1791
1822
|
unwrap("getGroupBulletin", toResultNumber(raw.result), raw.errMsg);
|
|
1792
1823
|
return extractBulletins(raw.result);
|
|
@@ -1806,7 +1837,7 @@ var GroupApi = class {
|
|
|
1806
1837
|
}));
|
|
1807
1838
|
} catch (e) {
|
|
1808
1839
|
if (isKernelError(e)) throw e;
|
|
1809
|
-
throw kernelError(`publishGroupBulletin 调用失败: ${
|
|
1840
|
+
throw kernelError(`publishGroupBulletin 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1810
1841
|
}
|
|
1811
1842
|
}
|
|
1812
1843
|
/** 删群公告(delete_group_announcement;参数待探测校准)。 */
|
|
@@ -1815,7 +1846,7 @@ var GroupApi = class {
|
|
|
1815
1846
|
checkLooseResult("deleteGroupBulletin", await this.service.deleteGroupBulletin(groupCode, announcementId));
|
|
1816
1847
|
} catch (e) {
|
|
1817
1848
|
if (isKernelError(e)) throw e;
|
|
1818
|
-
throw kernelError(`deleteGroupBulletin 调用失败: ${
|
|
1849
|
+
throw kernelError(`deleteGroupBulletin 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1819
1850
|
}
|
|
1820
1851
|
}
|
|
1821
1852
|
/** 专属头衔(set_group_member_special_title;setIdentityTitleInfo 参数待校准)。 */
|
|
@@ -1824,7 +1855,7 @@ var GroupApi = class {
|
|
|
1824
1855
|
checkLooseResult("setIdentityTitleInfo", await this.service.setIdentityTitleInfo(groupCode, uid, title));
|
|
1825
1856
|
} catch (e) {
|
|
1826
1857
|
if (isKernelError(e)) throw e;
|
|
1827
|
-
throw kernelError(`setIdentityTitleInfo 调用失败: ${
|
|
1858
|
+
throw kernelError(`setIdentityTitleInfo 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1828
1859
|
}
|
|
1829
1860
|
}
|
|
1830
1861
|
/** 群头像(set_group_avatar;GroupService.setHeader 参数待校准)。 */
|
|
@@ -1833,7 +1864,7 @@ var GroupApi = class {
|
|
|
1833
1864
|
checkLooseResult("setHeader", await this.service.setHeader(groupCode, imagePath));
|
|
1834
1865
|
} catch (e) {
|
|
1835
1866
|
if (isKernelError(e)) throw e;
|
|
1836
|
-
throw kernelError(`setHeader(group) 调用失败: ${
|
|
1867
|
+
throw kernelError(`setHeader(group) 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1837
1868
|
}
|
|
1838
1869
|
}
|
|
1839
1870
|
/** 公告图片上传(uploadGroupBulletinPic 返回 picId 待校准,失败原样上抛)。 */
|
|
@@ -1872,10 +1903,6 @@ function extractBulletins(result) {
|
|
|
1872
1903
|
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter((item) => item !== null && typeof item === "object");
|
|
1873
1904
|
return [];
|
|
1874
1905
|
}
|
|
1875
|
-
/** 未知异常 → 消息字符串。 */
|
|
1876
|
-
function errMsgString$3(e) {
|
|
1877
|
-
return e instanceof Error ? e.message : String(e);
|
|
1878
|
-
}
|
|
1879
1906
|
/**
|
|
1880
1907
|
* 从 getGroupDetailInfo 返回提取群详情(兼容三种形状):
|
|
1881
1908
|
* - result 为对象 → 详情直接在其中(最常见)
|
|
@@ -2030,8 +2057,6 @@ const VIDEO_STORE_ID = 1;
|
|
|
2030
2057
|
const VIDEO_ORIGINAL = true;
|
|
2031
2058
|
const VIDEO_FROM = 0;
|
|
2032
2059
|
const VIDEO_SOURCE_CODEC_FORMAT = 0;
|
|
2033
|
-
/** 视频缩略图在 thumbPath Map 中的 key(收向实测 Map<0, path>)。 */
|
|
2034
|
-
const VIDEO_THUMB_KEY = 0;
|
|
2035
2060
|
/** getRichMediaFilePathForGuild 的 downloadType:1 = 原文件,2 = 缩略图。 */
|
|
2036
2061
|
const RICH_MEDIA_DOWNLOAD_TYPE_ORIGIN = 1;
|
|
2037
2062
|
const RICH_MEDIA_DOWNLOAD_TYPE_THUMB = 2;
|
|
@@ -2041,16 +2066,6 @@ const THUMB_SIZE_NONE = 0;
|
|
|
2041
2066
|
/** 语音下载轮询参数(300ms × 34 ≈ 10s;返回 void 只能经重拉元素观察完成)。 */
|
|
2042
2067
|
const PTT_POLL_INTERVAL_MS = 300;
|
|
2043
2068
|
const PTT_POLL_TIMES = 34;
|
|
2044
|
-
/** sleep(下载轮询间隔)。 */
|
|
2045
|
-
function sleep$1(ms) {
|
|
2046
|
-
return new Promise((resolve) => {
|
|
2047
|
-
setTimeout(resolve, ms);
|
|
2048
|
-
});
|
|
2049
|
-
}
|
|
2050
|
-
/** 未知异常 → 消息字符串。 */
|
|
2051
|
-
function errMsgString$2(e) {
|
|
2052
|
-
return e instanceof Error ? e.message : String(e);
|
|
2053
|
-
}
|
|
2054
2069
|
/** 语音下载完成判定:有路径且(传输完成或末次轮询)才返回元素,否则 null。 */
|
|
2055
2070
|
function pttDownloadResult(latest, isLastPoll) {
|
|
2056
2071
|
if (latest === void 0) return null;
|
|
@@ -2296,7 +2311,7 @@ var MsgApi = class {
|
|
|
2296
2311
|
videoElement.thumbSize = thumbSize.size;
|
|
2297
2312
|
videoElement.thumbWidth = el.width ?? 0;
|
|
2298
2313
|
videoElement.thumbHeight = el.height ?? 0;
|
|
2299
|
-
videoElement.thumbPath = /* @__PURE__ */ new Map([[
|
|
2314
|
+
videoElement.thumbPath = /* @__PURE__ */ new Map([[0, thumbRelPath]]);
|
|
2300
2315
|
}
|
|
2301
2316
|
return {
|
|
2302
2317
|
elementType: ElementType.VIDEO,
|
|
@@ -2432,7 +2447,7 @@ var MsgApi = class {
|
|
|
2432
2447
|
thumbSize: THUMB_SIZE_NONE
|
|
2433
2448
|
});
|
|
2434
2449
|
for (let i = 0; i < PTT_POLL_TIMES; i++) {
|
|
2435
|
-
await sleep
|
|
2450
|
+
await sleep(PTT_POLL_INTERVAL_MS);
|
|
2436
2451
|
const result = pttDownloadResult(findPttElement(await this.fetchMsgsByMsgId(target, [msgId]))?.pttElement, i === 33);
|
|
2437
2452
|
if (result !== null) return result;
|
|
2438
2453
|
}
|
|
@@ -2463,7 +2478,7 @@ var MsgApi = class {
|
|
|
2463
2478
|
checkLooseResult("sendNudge", await this.service.sendNudge(param));
|
|
2464
2479
|
} catch (e) {
|
|
2465
2480
|
if (isKernelError(e)) throw e;
|
|
2466
|
-
throw kernelError(`sendNudge 调用失败: ${
|
|
2481
|
+
throw kernelError(`sendNudge 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
2467
2482
|
}
|
|
2468
2483
|
}
|
|
2469
2484
|
/** 会话置顶(set_peer_pin;setContactLocalTop 参数待探测校准)。 */
|
|
@@ -2472,7 +2487,7 @@ var MsgApi = class {
|
|
|
2472
2487
|
checkLooseResult("setContactLocalTop", await this.service.setContactLocalTop(target, isTop));
|
|
2473
2488
|
} catch (e) {
|
|
2474
2489
|
if (isKernelError(e)) throw e;
|
|
2475
|
-
throw kernelError(`setContactLocalTop 调用失败: ${
|
|
2490
|
+
throw kernelError(`setContactLocalTop 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
2476
2491
|
}
|
|
2477
2492
|
}
|
|
2478
2493
|
/** 收藏表情列表(get_custom_face_url_list;queryFavEmojiByDesc 形状待校准)。 */
|
|
@@ -2481,7 +2496,7 @@ var MsgApi = class {
|
|
|
2481
2496
|
try {
|
|
2482
2497
|
raw = await this.service.queryFavEmojiByDesc("");
|
|
2483
2498
|
} catch (e) {
|
|
2484
|
-
throw kernelError(`queryFavEmojiByDesc 调用失败: ${
|
|
2499
|
+
throw kernelError(`queryFavEmojiByDesc 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
2485
2500
|
}
|
|
2486
2501
|
checkLooseResult("queryFavEmojiByDesc", raw);
|
|
2487
2502
|
const list = raw.emojiInfoList;
|
|
@@ -2593,6 +2608,7 @@ function mapSex(raw) {
|
|
|
2593
2608
|
* - setNickName:set_qq_profile
|
|
2594
2609
|
* - setHeader:set_qq_avatar
|
|
2595
2610
|
* - getStrangerInfo:get_stranger_info(uin → uid → 详情扁平化)
|
|
2611
|
+
* - getUinByUid:uid → uin 弱身份兜底(好友申请等「不在群里」的 uid)
|
|
2596
2612
|
*/
|
|
2597
2613
|
/** 资料 API:从 session 拿 profile service,包装成语义化方法。 */
|
|
2598
2614
|
var ProfileApi = class {
|
|
@@ -2624,6 +2640,18 @@ var ProfileApi = class {
|
|
|
2624
2640
|
const info = await this.service.getUserDetailInfo(uid);
|
|
2625
2641
|
return flattenStrangerInfo(uin, uid, byUin, info);
|
|
2626
2642
|
}
|
|
2643
|
+
/**
|
|
2644
|
+
* uid → uin(弱身份兜底;issue #122)。
|
|
2645
|
+
*
|
|
2646
|
+
* `GroupApi.uidToUin` 走群成员口径(getUinByUids),好友申请 / 陌生人这类不在任何群
|
|
2647
|
+
* 的 uid 必然解析失败,此处用资料详情反查 `detail.uin`。查不到返回 `null`(不抛错:
|
|
2648
|
+
* 「可能没有值」的读操作,调用方 fail-soft);`detail.uin` 未经真实样本确认,见
|
|
2649
|
+
* docs/design.md「已知边界」。
|
|
2650
|
+
*/
|
|
2651
|
+
async getUinByUid(uid) {
|
|
2652
|
+
const uin = (await this.service.getUserDetailInfo(uid)).detail?.uin;
|
|
2653
|
+
return typeof uin === "string" && uin !== "" ? uin : null;
|
|
2654
|
+
}
|
|
2627
2655
|
};
|
|
2628
2656
|
// src/apis/profile-like.ts
|
|
2629
2657
|
/**
|
|
@@ -2675,7 +2703,7 @@ var RecentContactApi = class {
|
|
|
2675
2703
|
raw = await this.service.getRecentContactList({ count: RECENT_CONTACT_FETCH_COUNT });
|
|
2676
2704
|
} catch (e) {
|
|
2677
2705
|
if (isKernelError(e)) throw e;
|
|
2678
|
-
throw kernelError(`getRecentContactList 调用失败: ${
|
|
2706
|
+
throw kernelError(`getRecentContactList 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
2679
2707
|
}
|
|
2680
2708
|
checkLooseResult("getRecentContactList", raw);
|
|
2681
2709
|
return extractPinnedContacts(raw);
|
|
@@ -2725,10 +2753,6 @@ function pinnedItem(contact, scene) {
|
|
|
2725
2753
|
scene
|
|
2726
2754
|
}];
|
|
2727
2755
|
}
|
|
2728
|
-
/** 未知异常 → 消息字符串。 */
|
|
2729
|
-
function errMsgString$1(e) {
|
|
2730
|
-
return e instanceof Error ? e.message : String(e);
|
|
2731
|
-
}
|
|
2732
2756
|
// src/apis/richmedia.ts
|
|
2733
2757
|
/**
|
|
2734
2758
|
* RichMediaApi:富媒体语义化 API(ADR-009 统一错误语义,P2-14)
|
|
@@ -3075,7 +3099,7 @@ async function fetchQunJson(url, cookie) {
|
|
|
3075
3099
|
data: json.data
|
|
3076
3100
|
};
|
|
3077
3101
|
} catch (err) {
|
|
3078
|
-
throw kernelError(`qun.qq.com 请求失败: ${
|
|
3102
|
+
throw kernelError(`qun.qq.com 请求失败: ${errorMessage(err)}`, "UNKNOWN");
|
|
3079
3103
|
}
|
|
3080
3104
|
}
|
|
3081
3105
|
/** 请求 qun.qq.com 文本接口(带 Cookie;失败返回 null)。 */
|
|
@@ -3085,7 +3109,7 @@ async function fetchQunText(url, cookie) {
|
|
|
3085
3109
|
if (!res.ok) return null;
|
|
3086
3110
|
return await res.text();
|
|
3087
3111
|
} catch (err) {
|
|
3088
|
-
throw kernelError(`qun.qq.com 请求失败: ${
|
|
3112
|
+
throw kernelError(`qun.qq.com 请求失败: ${errorMessage(err)}`, "UNKNOWN");
|
|
3089
3113
|
}
|
|
3090
3114
|
}
|
|
3091
3115
|
/** Cookie dict → 头字符串。 */
|
|
@@ -3410,7 +3434,7 @@ var NTEventChannel = class {
|
|
|
3410
3434
|
};
|
|
3411
3435
|
const timer = setTimeout(() => {
|
|
3412
3436
|
cleanup();
|
|
3413
|
-
reject(
|
|
3437
|
+
reject(kernelError(`等待事件超时: ${event}`, "TIMEOUT"));
|
|
3414
3438
|
}, timeoutMs);
|
|
3415
3439
|
const cleanup = () => {
|
|
3416
3440
|
clearTimeout(timer);
|
|
@@ -3538,34 +3562,6 @@ var BuddyCache = class {
|
|
|
3538
3562
|
return this.bootstrapped;
|
|
3539
3563
|
}
|
|
3540
3564
|
};
|
|
3541
|
-
// src/login/wait.ts
|
|
3542
|
-
/**
|
|
3543
|
-
* 等待/延迟工具(login 模块共享,2026-08-08 克隆合并)
|
|
3544
|
-
*/
|
|
3545
|
-
/** 等待条件满足(轮询,带超时)。 */
|
|
3546
|
-
function waitFor(predicate, timeoutMs, intervalMs = 500) {
|
|
3547
|
-
return new Promise((resolve) => {
|
|
3548
|
-
const started = Date.now();
|
|
3549
|
-
const tick = () => {
|
|
3550
|
-
if (predicate()) {
|
|
3551
|
-
resolve(true);
|
|
3552
|
-
return;
|
|
3553
|
-
}
|
|
3554
|
-
if (Date.now() - started > timeoutMs) {
|
|
3555
|
-
resolve(false);
|
|
3556
|
-
return;
|
|
3557
|
-
}
|
|
3558
|
-
setTimeout(tick, intervalMs);
|
|
3559
|
-
};
|
|
3560
|
-
tick();
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
/** 短延迟。 */
|
|
3564
|
-
function sleep(ms) {
|
|
3565
|
-
return new Promise((resolve) => {
|
|
3566
|
-
setTimeout(resolve, ms);
|
|
3567
|
-
});
|
|
3568
|
-
}
|
|
3569
3565
|
// src/cache/group-cache.ts
|
|
3570
3566
|
/**
|
|
3571
3567
|
* 群/成员缓存:事件主动维护 + 查询惰性回填。
|
|
@@ -4583,7 +4579,7 @@ function readMachineGuid(loginService) {
|
|
|
4583
4579
|
function defaultEngineConfig(env, qqDataPath) {
|
|
4584
4580
|
const platform = detectPlatformType();
|
|
4585
4581
|
const fullVersion = env.qqVersion ?? "";
|
|
4586
|
-
const wrapperPath = process.env["NAPUTO_WRAPPER_PATH"] ?? "";
|
|
4582
|
+
const wrapperPath = process.env["NAPUKETTO_WRAPPER_PATH"] ?? process.env["NAPUTO_WRAPPER_PATH"] ?? "";
|
|
4587
4583
|
const majorPath = wrapperPath !== "" ? join(dirname(wrapperPath), "major.node") : "";
|
|
4588
4584
|
const qua = (majorPath !== "" ? parseQuaFromMajor(majorPath) : null) ?? (fullVersion !== "" ? buildQua(fullVersion, platform) : "");
|
|
4589
4585
|
return {
|
|
@@ -4627,7 +4623,7 @@ function electronProcessType() {
|
|
|
4627
4623
|
*/
|
|
4628
4624
|
function resolveQqUserDataRoot(exports, opts = {}) {
|
|
4629
4625
|
if ((opts.platform ?? detectPlatformType()) === PlatformType.KLINUX) {
|
|
4630
|
-
const dataRoot = opts.dataRoot ?? process.env["NAPUTO_DATA_ROOT"] ?? "";
|
|
4626
|
+
const dataRoot = opts.dataRoot ?? process.env["NAPUKETTO_DATA_ROOT"] ?? process.env["NAPUTO_DATA_ROOT"] ?? process.env["NAPUKETTO_DATA"] ?? process.env["NAPKETTO_DATA"] ?? "";
|
|
4631
4627
|
if (dataRoot !== "") return dataRoot;
|
|
4632
4628
|
}
|
|
4633
4629
|
return extractUserDataRoot(exports) ?? join(homedir(), "Documents", "Tencent Files");
|
|
@@ -4813,6 +4809,37 @@ function getOrCreateLoginService(exports) {
|
|
|
4813
4809
|
return null;
|
|
4814
4810
|
}
|
|
4815
4811
|
}
|
|
4812
|
+
/**
|
|
4813
|
+
* 加载 wrapper.node 原生模块并校验核心导出(自建宿主引导原语,2026-11 从
|
|
4814
|
+
* loader self-host.ts 下沉:原生 `dlopen` 是 kernel 的唯一原生层职责,loader
|
|
4815
|
+
* 只编排流程)。
|
|
4816
|
+
*
|
|
4817
|
+
* @param wrapperPath wrapper.node 绝对路径(QQ 安装目录 / 缓存文件根)
|
|
4818
|
+
* @returns NAPI exports(含 NodeIKernelLoginService 等构造器)
|
|
4819
|
+
* @throws KernelError exports 缺 NodeIKernelLoginService(stub 环境异常)或 dlopen 失败
|
|
4820
|
+
*/
|
|
4821
|
+
function dlopenWrapper(wrapperPath) {
|
|
4822
|
+
const m = { exports: {} };
|
|
4823
|
+
process.dlopen(m, wrapperPath);
|
|
4824
|
+
if (!Object.keys(m.exports ?? {}).includes("NodeIKernelLoginService")) throw kernelError("exports 无 NodeIKernelLoginService(stub 环境异常?)", "INVALID_STATE");
|
|
4825
|
+
return m.exports;
|
|
4826
|
+
}
|
|
4827
|
+
/**
|
|
4828
|
+
* 激活自建宿主 O3MiscService 事件分发(三要素之二,V6 实测决定性):
|
|
4829
|
+
* 不激活则 getLoginList 永不 resolve(挂起)。listener 用普通对象
|
|
4830
|
+
* (getOnAmgomDataPiece 空实现,wrapper 契约回调)。
|
|
4831
|
+
*
|
|
4832
|
+
* @param wrapperExports dlopen 产出的 exports(缺失/版本变化时返回 false)
|
|
4833
|
+
* @returns 是否成功激活
|
|
4834
|
+
*/
|
|
4835
|
+
function activateO3MiscService(wrapperExports) {
|
|
4836
|
+
const O3 = wrapperExports?.["NodeIO3MiscService"];
|
|
4837
|
+
if (O3 && typeof O3.get === "function") {
|
|
4838
|
+
O3.get().addO3MiscListener({ getOnAmgomDataPiece() {} });
|
|
4839
|
+
return true;
|
|
4840
|
+
}
|
|
4841
|
+
return false;
|
|
4842
|
+
}
|
|
4816
4843
|
// src/core.ts
|
|
4817
4844
|
/**
|
|
4818
4845
|
* NapukettoCore:装配 + 启动(§9 第 6 项,2026-08-05 实现)
|
|
@@ -5420,7 +5447,7 @@ function tryMsgService(rec, thisCtx) {
|
|
|
5420
5447
|
} catch (e) {
|
|
5421
5448
|
return {
|
|
5422
5449
|
service: null,
|
|
5423
|
-
error:
|
|
5450
|
+
error: errorMessage(e)
|
|
5424
5451
|
};
|
|
5425
5452
|
}
|
|
5426
5453
|
}
|
|
@@ -5455,10 +5482,6 @@ function sessionFace(session) {
|
|
|
5455
5482
|
ownKeys: Object.getOwnPropertyNames(session)
|
|
5456
5483
|
} : null;
|
|
5457
5484
|
}
|
|
5458
|
-
/** 未知异常 → 错误消息字符串。 */
|
|
5459
|
-
function errMsgString(e) {
|
|
5460
|
-
return e instanceof Error ? e.message : String(e);
|
|
5461
|
-
}
|
|
5462
5485
|
/** try getNTWrapperSession(id) → session 方法面(fn 缺失记 null,失败记 error)。 */
|
|
5463
5486
|
function trySessionFace(ctx, id) {
|
|
5464
5487
|
const fn = getNTWrapperSessionFn(ctx);
|
|
@@ -5466,7 +5489,7 @@ function trySessionFace(ctx, id) {
|
|
|
5466
5489
|
try {
|
|
5467
5490
|
return sessionFace(fn.call(ctx.exports.NodeIQQNTWrapperSession, id));
|
|
5468
5491
|
} catch (e) {
|
|
5469
|
-
return { error:
|
|
5492
|
+
return { error: errorMessage(e) };
|
|
5470
5493
|
}
|
|
5471
5494
|
}
|
|
5472
5495
|
/** 用真实 sessionId 取主 session(getNTWrapperSession(nt_x))并记录方法面。 */
|
|
@@ -5631,13 +5654,13 @@ function probeRuntime(ctx, file = "napuketto-probe.json") {
|
|
|
5631
5654
|
/** 探测结果落盘(增量与最终共用;最终写入后记 probeFile 路径)。 */
|
|
5632
5655
|
function writeProbeFile(result, file) {
|
|
5633
5656
|
try {
|
|
5634
|
-
const dir = process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
|
|
5657
|
+
const dir = process.env["NAPUKETTO_CFG_DIR"] ?? process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
|
|
5635
5658
|
mkdirSync(dir, { recursive: true });
|
|
5636
5659
|
const full = join(dir, file);
|
|
5637
5660
|
writeFileSync(full, JSON.stringify(result, null, 2), "utf8");
|
|
5638
5661
|
result["probeFile"] = full;
|
|
5639
5662
|
} catch (e) {
|
|
5640
|
-
result["probeFileError"] =
|
|
5663
|
+
result["probeFileError"] = errorMessage(e);
|
|
5641
5664
|
}
|
|
5642
5665
|
}
|
|
5643
5666
|
// src/wrapper/probe/probe-listener.ts
|
|
@@ -5740,7 +5763,7 @@ function createRecordingListener(service, onEvent) {
|
|
|
5740
5763
|
* 空壳的 service getter 函数仍在但调用返回 null(late probe 61/63 null 的根因)。
|
|
5741
5764
|
*/
|
|
5742
5765
|
function startListenerRecording(ctx, file = "napuketto-listener-record.jsonl") {
|
|
5743
|
-
const dir = process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
|
|
5766
|
+
const dir = process.env["NAPUKETTO_CFG_DIR"] ?? process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
|
|
5744
5767
|
mkdirSync(dir, { recursive: true });
|
|
5745
5768
|
const full = join(dir, file);
|
|
5746
5769
|
writeFileSync(full, "", "utf8");
|
|
@@ -5776,7 +5799,7 @@ function recordService(session, getter, emit) {
|
|
|
5776
5799
|
} catch (e) {
|
|
5777
5800
|
return {
|
|
5778
5801
|
ok: false,
|
|
5779
|
-
error:
|
|
5802
|
+
error: errorMessage(e)
|
|
5780
5803
|
};
|
|
5781
5804
|
}
|
|
5782
5805
|
}
|
|
@@ -5797,7 +5820,7 @@ function recordLoginService(ctx, emit) {
|
|
|
5797
5820
|
} catch (e) {
|
|
5798
5821
|
return {
|
|
5799
5822
|
ok: false,
|
|
5800
|
-
error:
|
|
5823
|
+
error: errorMessage(e)
|
|
5801
5824
|
};
|
|
5802
5825
|
}
|
|
5803
5826
|
}
|
|
@@ -5886,6 +5909,6 @@ function listQQVersions(installDir) {
|
|
|
5886
5909
|
return statSync(full).isDirectory() && existsSync(join(full, "resources", "app", "wrapper.node"));
|
|
5887
5910
|
}).sort().reverse();
|
|
5888
5911
|
}
|
|
5889
|
-
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, EXIT_CONFIG_INVALID, ElementType, FlashTransferApi, FriendApi, FriendBridge, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, 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, WebApi, WebHonorType, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createCoreContext, createSessionListener as createLifecycleSessionListener, createSessionListener, createLogger, createLoginListener, createRecordingListener, createSession, createWrapper, electronProcessType, getExistingSession, getMainSession, initAndStartSession, initEngine, initSession, isKernelError, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, parseAppidFromMajor, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveWrapperPath, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitForNetworkConnection, waitSessionReady };
|
|
5912
|
+
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, EXIT_CONFIG_INVALID, ElementType, FlashTransferApi, FriendApi, FriendBridge, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, 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, WebApi, WebHonorType, activateO3MiscService, buildEngineConfig, buildLoginConfig, buildSessionConfig, configError, createCoreContext, 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, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitForNetworkConnection, waitSessionReady };
|
|
5890
5913
|
|
|
5891
5914
|
//# sourceMappingURL=index.mjs.map
|