@napuketto/kernel 0.7.3 → 0.9.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.d.mts +211 -218
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +175 -118
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -17
- package/dist/index.cjs +0 -5551
- package/dist/index.d.cts +0 -2987
- package/dist/index.d.cts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
3
4
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
4
5
|
import { parse, stringify } from "smol-toml";
|
|
5
6
|
import process from "node:process";
|
|
6
7
|
import pino from "pino";
|
|
7
|
-
import pinoPretty from "pino-pretty";
|
|
8
8
|
import { homedir, hostname, platform, release, type, version } from "node:os";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
11
|
import { get } from "node:https";
|
|
12
12
|
import { EventEmitter } from "node:events";
|
|
13
|
-
|
|
13
|
+
// src/infra/errors.ts
|
|
14
14
|
/**
|
|
15
15
|
* 全部错误码集合。协议层映射表可据此推导:
|
|
16
16
|
* `Record<(typeof KERNEL_ERROR_CODES)[number], number>`。
|
|
@@ -61,8 +61,7 @@ function configError(message, options) {
|
|
|
61
61
|
}
|
|
62
62
|
/** 配置校验失败的进程退出码(UNIX sysexits EX_CONFIG 惯例)。 */
|
|
63
63
|
const EXIT_CONFIG_INVALID = 78;
|
|
64
|
-
|
|
65
|
-
//#region src/infra/config.ts
|
|
64
|
+
// src/infra/config.ts
|
|
66
65
|
/**
|
|
67
66
|
* 配置基类(ADR-012)
|
|
68
67
|
*
|
|
@@ -181,8 +180,7 @@ function parseToml(text) {
|
|
|
181
180
|
function stringifyToml(value) {
|
|
182
181
|
return stringify(value);
|
|
183
182
|
}
|
|
184
|
-
|
|
185
|
-
//#region src/infra/log-config.ts
|
|
183
|
+
// src/infra/log-config.ts
|
|
186
184
|
/**
|
|
187
185
|
* [log] 配置段解析(napuketto.toml 全局段,2026-10-25 日志可配置化)。
|
|
188
186
|
*
|
|
@@ -329,8 +327,7 @@ function parseLogConfig(section, env = {}) {
|
|
|
329
327
|
delete draft.fileLevelExplicit;
|
|
330
328
|
return draft;
|
|
331
329
|
}
|
|
332
|
-
|
|
333
|
-
//#region src/infra/log-format.ts
|
|
330
|
+
// src/infra/log-format.ts
|
|
334
331
|
/**
|
|
335
332
|
* 结构化控制台流(single-line / json 格式,2026-10-25 日志可配置化)。
|
|
336
333
|
*
|
|
@@ -474,8 +471,7 @@ function createConsoleFormatStream(opts) {
|
|
|
474
471
|
out.write(render(record, ctx));
|
|
475
472
|
} };
|
|
476
473
|
}
|
|
477
|
-
|
|
478
|
-
//#region src/infra/logger.ts
|
|
474
|
+
// src/infra/logger.ts
|
|
479
475
|
/**
|
|
480
476
|
* pino 日志封装(ADR-007)
|
|
481
477
|
*
|
|
@@ -496,6 +492,33 @@ const DEFAULT_REDACT_PATHS = [
|
|
|
496
492
|
"password",
|
|
497
493
|
"secret"
|
|
498
494
|
];
|
|
495
|
+
/** 从本模块位置解析 optional peer(dist/index.mjs 与 src/infra 深度不同,但都归 createRequire 处理)。 */
|
|
496
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
497
|
+
/** undefined = 尚未探测;null = 未安装(降级 single-line 结构化输出)。 */
|
|
498
|
+
let prettyFactory;
|
|
499
|
+
/**
|
|
500
|
+
* 懒加载 pino-pretty(optional peerDependency,2026-11-03 依赖审计整改)。
|
|
501
|
+
*
|
|
502
|
+
* 为什么不用顶层 `import pinoPretty from "pino-pretty"`:kernel 被 koishi 适配器
|
|
503
|
+
* 或嵌入式宿主当库引用时不需要彩色终端渲染,但静态 import 会让「没装
|
|
504
|
+
* pino-pretty」直接变成模块加载期的 ERR_MODULE_NOT_FOUND。改为运行时 require +
|
|
505
|
+
* try/catch:宿主没装(或 pnpm 严格隔离下解析不到)就退化为 single-line 结构化
|
|
506
|
+
* 输出,CLI 侧因为自己依赖 pino-pretty,终端体验不变。
|
|
507
|
+
*
|
|
508
|
+
* 用 createRequire 而非动态 import():解析结果需要同步(createLogger 是同步
|
|
509
|
+
* API),且 pino-pretty 13 是 CJS 包,同步 require 最直接。
|
|
510
|
+
*/
|
|
511
|
+
function loadPrettyFactory() {
|
|
512
|
+
if (prettyFactory !== void 0) return prettyFactory;
|
|
513
|
+
try {
|
|
514
|
+
const mod = requireFromHere("pino-pretty");
|
|
515
|
+
const factory = typeof mod === "function" ? mod : mod.default;
|
|
516
|
+
prettyFactory = typeof factory === "function" ? factory : null;
|
|
517
|
+
} catch {
|
|
518
|
+
prettyFactory = null;
|
|
519
|
+
}
|
|
520
|
+
return prettyFactory;
|
|
521
|
+
}
|
|
499
522
|
/** 级别数值序(求多目的地最低级别用)。 */
|
|
500
523
|
const LEVEL_ORDER = [
|
|
501
524
|
"trace",
|
|
@@ -523,29 +546,34 @@ function toSingle(streams) {
|
|
|
523
546
|
if (only === void 0) throw new KernelError("logger 内部错误:目的地列表为空", "UNKNOWN");
|
|
524
547
|
return only.stream;
|
|
525
548
|
}
|
|
526
|
-
/** 构造控制台流:pretty 走 pino-pretty
|
|
549
|
+
/** 构造控制台流:pretty 走 pino-pretty(未安装则降级),其余走结构化渲染流。 */
|
|
527
550
|
function buildConsoleStream(params) {
|
|
528
551
|
const { format, timestampMode, colorize, destination } = params;
|
|
529
|
-
if (format
|
|
530
|
-
|
|
552
|
+
if (format === "pretty") {
|
|
553
|
+
const pretty = loadPrettyFactory();
|
|
554
|
+
if (pretty !== null) return pretty({
|
|
555
|
+
colorize,
|
|
556
|
+
...timestampMode === "local" ? { translateTime: "SYS:HH:MM:ss.l" } : {},
|
|
557
|
+
...timestampMode === "iso8601" ? { translateTime: "SYS:yyyy-mm-dd'T'HH:MM:ss.l Z" } : {},
|
|
558
|
+
singleLine: false,
|
|
559
|
+
destination
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
return createConsoleFormatStream({
|
|
563
|
+
format: format === "pretty" ? "single-line" : format,
|
|
531
564
|
timestamp: timestampMode,
|
|
532
565
|
colorize,
|
|
533
566
|
destination
|
|
534
567
|
});
|
|
535
|
-
return pinoPretty({
|
|
536
|
-
colorize,
|
|
537
|
-
...timestampMode === "local" ? { translateTime: "SYS:HH:MM:ss.l" } : {},
|
|
538
|
-
...timestampMode === "iso8601" ? { translateTime: "SYS:yyyy-mm-dd'T'HH:MM:ss.l Z" } : {},
|
|
539
|
-
singleLine: false,
|
|
540
|
-
destination
|
|
541
|
-
});
|
|
542
568
|
}
|
|
543
569
|
/** 折叠 LoggerOptions 的渲染缺省:格式按 TTY 自动(TTY pretty / pipe single-line)、
|
|
544
|
-
* 颜色仅在 pretty 且 TTY 时开。
|
|
570
|
+
* 颜色仅在 pretty 且 TTY 时开。pretty 需要 pino-pretty,未安装时同样降级为
|
|
571
|
+
* single-line(与时间戳渲染方式的决策保持一致,避免 elapsed 字符串时间进错流)。 */
|
|
545
572
|
function resolveRenderParams(opts) {
|
|
546
573
|
const destination = opts.destination ?? process.stdout;
|
|
547
574
|
const isTty = destination.isTTY === true;
|
|
548
|
-
const
|
|
575
|
+
const requested = opts.format ?? (isTty ? "pretty" : "single-line");
|
|
576
|
+
const format = requested === "pretty" && loadPrettyFactory() === null ? "single-line" : requested;
|
|
549
577
|
return {
|
|
550
578
|
format,
|
|
551
579
|
timestampMode: opts.timestamp ?? "local",
|
|
@@ -591,8 +619,7 @@ function createLogger(opts = {}) {
|
|
|
591
619
|
else stream = pino.multistream(streams);
|
|
592
620
|
return pino(pinoOptions, stream);
|
|
593
621
|
}
|
|
594
|
-
|
|
595
|
-
//#region src/infra/paths.ts
|
|
622
|
+
// src/infra/paths.ts
|
|
596
623
|
/**
|
|
597
624
|
* 数据目录布局(ADR-016,2026-08-08 修订:数据根默认放项目根)
|
|
598
625
|
*
|
|
@@ -722,8 +749,7 @@ var PathWrapper = class {
|
|
|
722
749
|
});
|
|
723
750
|
}
|
|
724
751
|
};
|
|
725
|
-
|
|
726
|
-
//#region src/apis/result.ts
|
|
752
|
+
// src/apis/result.ts
|
|
727
753
|
/**
|
|
728
754
|
* 原生调用结果解包(ADR-009 统一错误语义)
|
|
729
755
|
*
|
|
@@ -771,8 +797,7 @@ function unwrapResult(label, raw) {
|
|
|
771
797
|
if (code === "UNKNOWN" && label === "sendMsg") code = "SEND_FAILED";
|
|
772
798
|
throw kernelError(`${label} 失败: ${msg}`, code);
|
|
773
799
|
}
|
|
774
|
-
|
|
775
|
-
//#region src/apis/friend.ts
|
|
800
|
+
// src/apis/friend.ts
|
|
776
801
|
/**
|
|
777
802
|
* FriendApi:好友语义化 API(ADR-009 统一错误语义)
|
|
778
803
|
*
|
|
@@ -917,8 +942,7 @@ function toDoubtFriendRequestInfo(item, uinMap) {
|
|
|
917
942
|
assignOptional(info, "time", item.reqTime);
|
|
918
943
|
return info;
|
|
919
944
|
}
|
|
920
|
-
|
|
921
|
-
//#region src/types/entities.ts
|
|
945
|
+
// src/types/entities.ts
|
|
922
946
|
/**
|
|
923
947
|
* 实体类型层(运行时探测产物 + 公开资料作说明书,ADR-006)
|
|
924
948
|
*
|
|
@@ -957,8 +981,7 @@ const TipGroupElementType = {
|
|
|
957
981
|
UNBLOCK: 7,
|
|
958
982
|
SHUT_UP: 8
|
|
959
983
|
};
|
|
960
|
-
|
|
961
|
-
//#region src/types/listeners/group.ts
|
|
984
|
+
// src/types/listeners/group.ts
|
|
962
985
|
/** 群列表更新类型(说明书参考,值待探测校准)。 */
|
|
963
986
|
const GroupListUpdateType = {
|
|
964
987
|
/** 全量更新(groupList 为完整列表)。 */
|
|
@@ -966,8 +989,7 @@ const GroupListUpdateType = {
|
|
|
966
989
|
/** 增量更新(合并到现有缓存)。 */
|
|
967
990
|
PARTIAL: 1
|
|
968
991
|
};
|
|
969
|
-
|
|
970
|
-
//#region src/types/services/msg-service.ts
|
|
992
|
+
// src/types/services/msg-service.ts
|
|
971
993
|
/** 消息元素类型枚举(QQ wrapper 外部契约,自研描述)。 */
|
|
972
994
|
const ElementType = {
|
|
973
995
|
UNKNOWN: 0,
|
|
@@ -991,8 +1013,7 @@ const ElementType = {
|
|
|
991
1013
|
INTEXT_GIFT: 18,
|
|
992
1014
|
CALENDAR: 19
|
|
993
1015
|
};
|
|
994
|
-
|
|
995
|
-
//#region src/types/message-element.ts
|
|
1016
|
+
// src/types/message-element.ts
|
|
996
1017
|
/**
|
|
997
1018
|
* canonical 消息元素模型(协议无关,ADR-008 延伸)
|
|
998
1019
|
*
|
|
@@ -1268,8 +1289,7 @@ function toSendElements(elements) {
|
|
|
1268
1289
|
}
|
|
1269
1290
|
return out;
|
|
1270
1291
|
}
|
|
1271
|
-
|
|
1272
|
-
//#region src/types/services/group-service.ts
|
|
1292
|
+
// src/types/services/group-service.ts
|
|
1273
1293
|
/** 群成员角色(QQ wrapper 契约)。 */
|
|
1274
1294
|
const NTGroupMemberRole = {
|
|
1275
1295
|
UNSPECIFIED: 0,
|
|
@@ -1313,8 +1333,7 @@ const NTGroupRequestOperateTypes = {
|
|
|
1313
1333
|
KIGNORE: 3,
|
|
1314
1334
|
KDELETE: 4
|
|
1315
1335
|
};
|
|
1316
|
-
|
|
1317
|
-
//#region src/types/wrapper.ts
|
|
1336
|
+
// src/types/wrapper.ts
|
|
1318
1337
|
/**
|
|
1319
1338
|
* wrapper.node 的 NAPI 接口面(自研描述,非移植)
|
|
1320
1339
|
*
|
|
@@ -1343,8 +1362,7 @@ const VendorType = {
|
|
|
1343
1362
|
KSUPPORTVIVOPUSH: 5,
|
|
1344
1363
|
KSUPPORTGOOGLEPUSH: 99
|
|
1345
1364
|
};
|
|
1346
|
-
|
|
1347
|
-
//#region src/apis/group.ts
|
|
1365
|
+
// src/apis/group.ts
|
|
1348
1366
|
/**
|
|
1349
1367
|
* GroupApi:群语义化 API(ADR-009 统一错误语义)
|
|
1350
1368
|
*
|
|
@@ -1628,8 +1646,7 @@ function extractGroupDetail(result, raw) {
|
|
|
1628
1646
|
if (candidate !== void 0 && candidate !== null && typeof candidate === "object") return candidate;
|
|
1629
1647
|
return null;
|
|
1630
1648
|
}
|
|
1631
|
-
|
|
1632
|
-
//#region src/apis/group-notify.ts
|
|
1649
|
+
// src/apis/group-notify.ts
|
|
1633
1650
|
/**
|
|
1634
1651
|
* GroupNotifyApi:群通知/禁言列表语义化 API(ADR-009 统一错误语义,P2-13)
|
|
1635
1652
|
*
|
|
@@ -1693,8 +1710,7 @@ function extractMemberList(result) {
|
|
|
1693
1710
|
}
|
|
1694
1711
|
return [];
|
|
1695
1712
|
}
|
|
1696
|
-
|
|
1697
|
-
//#region src/apis/msg.ts
|
|
1713
|
+
// src/apis/msg.ts
|
|
1698
1714
|
/**
|
|
1699
1715
|
* MsgApi:消息语义化 API(ADR-009 统一错误语义)
|
|
1700
1716
|
*
|
|
@@ -2270,8 +2286,7 @@ function findForwardElement(msgs) {
|
|
|
2270
2286
|
if (first === void 0) return null;
|
|
2271
2287
|
return first.elements.find((el) => el.multiForwardMsgElement !== void 0)?.multiForwardMsgElement ?? null;
|
|
2272
2288
|
}
|
|
2273
|
-
|
|
2274
|
-
//#region src/apis/stranger-info.ts
|
|
2289
|
+
// src/apis/stranger-info.ts
|
|
2275
2290
|
/** 宽松取值:undefined 时给默认值(null 也归默认)。 */
|
|
2276
2291
|
function orDefault(value, fallback) {
|
|
2277
2292
|
return value ?? fallback;
|
|
@@ -2321,8 +2336,7 @@ function mapSex(raw) {
|
|
|
2321
2336
|
if (raw === 2) return "female";
|
|
2322
2337
|
return "unknown";
|
|
2323
2338
|
}
|
|
2324
|
-
|
|
2325
|
-
//#region src/apis/profile.ts
|
|
2339
|
+
// src/apis/profile.ts
|
|
2326
2340
|
/**
|
|
2327
2341
|
* ProfileApi:资料语义化 API(ADR-009 统一错误语义,P2-14/P2-15)
|
|
2328
2342
|
*
|
|
@@ -2362,8 +2376,7 @@ var ProfileApi = class {
|
|
|
2362
2376
|
return flattenStrangerInfo(uin, uid, byUin, info);
|
|
2363
2377
|
}
|
|
2364
2378
|
};
|
|
2365
|
-
|
|
2366
|
-
//#region src/apis/profile-like.ts
|
|
2379
|
+
// src/apis/profile-like.ts
|
|
2367
2380
|
/**
|
|
2368
2381
|
* ProfileLikeApi:资料点赞语义化 API(ADR-009 统一错误语义,P2-14)
|
|
2369
2382
|
*
|
|
@@ -2388,8 +2401,7 @@ var ProfileLikeApi = class {
|
|
|
2388
2401
|
if (raw.result !== 0) throw kernelError(`点赞失败: ${raw.errMsg}`, "UNKNOWN");
|
|
2389
2402
|
}
|
|
2390
2403
|
};
|
|
2391
|
-
|
|
2392
|
-
//#region src/apis/recent-contact.ts
|
|
2404
|
+
// src/apis/recent-contact.ts
|
|
2393
2405
|
/**
|
|
2394
2406
|
* RecentContactApi:会话列表语义化 API(P2 批次二,get_peer_pins 数据源)
|
|
2395
2407
|
*
|
|
@@ -2442,24 +2454,33 @@ function extractPinnedContacts(raw) {
|
|
|
2442
2454
|
/** 单条会话 → 置顶项(置顶标记为真且场景可判定才产出)。 */
|
|
2443
2455
|
function pinnedOf(item) {
|
|
2444
2456
|
if (item === null || typeof item !== "object") return [];
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
if (contact.chatType === ChatType.C2C) return
|
|
2457
|
+
return pinnedContactOf(item);
|
|
2458
|
+
}
|
|
2459
|
+
/** 置顶判据(topFlag 实测字段名 + isTop 兼容形态)且 peerUid 可用才产出。 */
|
|
2460
|
+
function pinnedContactOf(contact) {
|
|
2461
|
+
if (!isPinned(contact) || typeof contact.peerUid !== "string") return [];
|
|
2462
|
+
if (contact.chatType === ChatType.GROUP) return pinnedItem(contact, "group");
|
|
2463
|
+
if (contact.chatType === ChatType.C2C) return pinnedItem(contact, "friend");
|
|
2464
|
+
return [];
|
|
2465
|
+
}
|
|
2466
|
+
/** 置顶字段实测为 topFlag(1 = 置顶,listener 载荷 2026-11-01 实录);isTop 为兼容形态。 */
|
|
2467
|
+
function isPinned(contact) {
|
|
2468
|
+
return contact.isTop === true || contact.topFlag === 1;
|
|
2469
|
+
}
|
|
2470
|
+
/** 单条置顶项组装(peerUin 为 peer_pin_change 播种键,可能缺省)。 */
|
|
2471
|
+
function pinnedItem(contact, scene) {
|
|
2472
|
+
const peerUin = typeof contact.peerUin === "string" && contact.peerUin !== "" ? { peerUin: contact.peerUin } : {};
|
|
2473
|
+
return [{
|
|
2452
2474
|
peerUid: contact.peerUid,
|
|
2453
|
-
|
|
2475
|
+
...peerUin,
|
|
2476
|
+
scene
|
|
2454
2477
|
}];
|
|
2455
|
-
return [];
|
|
2456
2478
|
}
|
|
2457
2479
|
/** 未知异常 → 消息字符串。 */
|
|
2458
2480
|
function errMsgString$1(e) {
|
|
2459
2481
|
return e instanceof Error ? e.message : String(e);
|
|
2460
2482
|
}
|
|
2461
|
-
|
|
2462
|
-
//#region src/apis/richmedia.ts
|
|
2483
|
+
// src/apis/richmedia.ts
|
|
2463
2484
|
/**
|
|
2464
2485
|
* RichMediaApi:富媒体语义化 API(ADR-009 统一错误语义,P2-14)
|
|
2465
2486
|
*
|
|
@@ -2603,8 +2624,7 @@ function countGroupFiles(result) {
|
|
|
2603
2624
|
if (Array.isArray(result)) return result.filter((item) => item.fileInfo !== void 0).length;
|
|
2604
2625
|
return 0;
|
|
2605
2626
|
}
|
|
2606
|
-
|
|
2607
|
-
//#region src/apis/ticket.ts
|
|
2627
|
+
// src/apis/ticket.ts
|
|
2608
2628
|
/**
|
|
2609
2629
|
* TicketApi:票据语义化 API(ADR-009 统一错误语义,P2-13)
|
|
2610
2630
|
*
|
|
@@ -2676,8 +2696,7 @@ function parseSetCookieHeaders(raw) {
|
|
|
2676
2696
|
}
|
|
2677
2697
|
return cookies;
|
|
2678
2698
|
}
|
|
2679
|
-
|
|
2680
|
-
//#region src/apis/webapi.ts
|
|
2699
|
+
// src/apis/webapi.ts
|
|
2681
2700
|
/**
|
|
2682
2701
|
* WebApi:群空间 web 接口(P2-15)
|
|
2683
2702
|
*
|
|
@@ -2849,8 +2868,7 @@ function honorTargets(type) {
|
|
|
2849
2868
|
if (type === WebHonorType.ALL) return [...all];
|
|
2850
2869
|
return all.filter((target) => target.kind === type);
|
|
2851
2870
|
}
|
|
2852
|
-
|
|
2853
|
-
//#region src/bridge/friend-bridge.ts
|
|
2871
|
+
// src/bridge/friend-bridge.ts
|
|
2854
2872
|
/**
|
|
2855
2873
|
* 好友事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
2856
2874
|
* 无全局单例(ADR-015 推论)——每进程每 session 实例化一份。
|
|
@@ -2883,8 +2901,7 @@ var FriendBridge = class {
|
|
|
2883
2901
|
this.listenerId = null;
|
|
2884
2902
|
}
|
|
2885
2903
|
};
|
|
2886
|
-
|
|
2887
|
-
//#region src/bridge/group-bridge.ts
|
|
2904
|
+
// src/bridge/group-bridge.ts
|
|
2888
2905
|
/**
|
|
2889
2906
|
* 群事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
2890
2907
|
* 无全局单例(ADR-015 推论)——每进程每 session 实例化一份。
|
|
@@ -2922,8 +2939,37 @@ var GroupBridge = class {
|
|
|
2922
2939
|
this.listenerId = null;
|
|
2923
2940
|
}
|
|
2924
2941
|
};
|
|
2925
|
-
|
|
2926
|
-
|
|
2942
|
+
// src/bridge/login-bridge.ts
|
|
2943
|
+
/**
|
|
2944
|
+
* 登录事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
2945
|
+
* 无全局单例(ADR-015 推论)——每进程一份。
|
|
2946
|
+
*/
|
|
2947
|
+
var LoginBridge = class {
|
|
2948
|
+
service;
|
|
2949
|
+
channel;
|
|
2950
|
+
listenerId = null;
|
|
2951
|
+
constructor(loginService, channel) {
|
|
2952
|
+
if (loginService === null || loginService === void 0 || typeof loginService.addKernelLoginListener !== "function") throw kernelError("loginService 无效(缺 addKernelLoginListener)", "INVALID_STATE");
|
|
2953
|
+
this.service = loginService;
|
|
2954
|
+
this.channel = channel;
|
|
2955
|
+
}
|
|
2956
|
+
/** 注册原生监听(幂等)。 */
|
|
2957
|
+
register() {
|
|
2958
|
+
if (this.listenerId !== null) return;
|
|
2959
|
+
const listener = {
|
|
2960
|
+
onLoginDisConnected: (...args) => this.channel.emit("Login/onLoginDisConnected", ...args),
|
|
2961
|
+
onLogoutSucceed: (...args) => this.channel.emit("Login/onLogoutSucceed", ...args)
|
|
2962
|
+
};
|
|
2963
|
+
this.listenerId = this.service.addKernelLoginListener(listener);
|
|
2964
|
+
}
|
|
2965
|
+
/** 注销原生监听(幂等)。 */
|
|
2966
|
+
unregister() {
|
|
2967
|
+
if (this.listenerId === null) return;
|
|
2968
|
+
this.service.removeKernelLoginListener(this.listenerId);
|
|
2969
|
+
this.listenerId = null;
|
|
2970
|
+
}
|
|
2971
|
+
};
|
|
2972
|
+
// src/bridge/msg-bridge.ts
|
|
2927
2973
|
/**
|
|
2928
2974
|
* 消息事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
2929
2975
|
* 无全局单例(ADR-015 推论)——每进程每 session 实例化一份。
|
|
@@ -2946,7 +2992,8 @@ var MsgBridge = class {
|
|
|
2946
2992
|
onRecvMsgReadReport: (reports) => this.channel.emit("Msg/onRecvMsgReadReport", reports),
|
|
2947
2993
|
onRecvMsgReceipt: (receipts) => this.channel.emit("Msg/onRecvMsgReceipt", receipts),
|
|
2948
2994
|
onMsgInfoListUpdate: (msgs) => this.channel.emit("Msg/onMsgInfoListUpdate", msgs),
|
|
2949
|
-
onRecvOfflineFileMsg: (
|
|
2995
|
+
onRecvOfflineFileMsg: (msgs) => this.channel.emit("Msg/onRecvOfflineFileMsg", msgs),
|
|
2996
|
+
onFileMsgCome: (msgs) => this.channel.emit("Msg/onFileMsgCome", msgs),
|
|
2950
2997
|
onRecvOnlineFileMsg: (arg) => this.channel.emit("Msg/onRecvOnlineFileMsg", arg),
|
|
2951
2998
|
onRecvSysMsg: (arg) => this.channel.emit("Msg/onRecvSysMsg", arg)
|
|
2952
2999
|
};
|
|
@@ -2959,8 +3006,38 @@ var MsgBridge = class {
|
|
|
2959
3006
|
this.listenerId = null;
|
|
2960
3007
|
}
|
|
2961
3008
|
};
|
|
2962
|
-
|
|
2963
|
-
|
|
3009
|
+
// src/bridge/recent-contact-bridge.ts
|
|
3010
|
+
/**
|
|
3011
|
+
* 会话列表事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
3012
|
+
* 无全局单例(ADR-015 推论)——每进程每 session 实例化一份。
|
|
3013
|
+
*/
|
|
3014
|
+
var RecentContactBridge = class {
|
|
3015
|
+
service;
|
|
3016
|
+
channel;
|
|
3017
|
+
listenerId = null;
|
|
3018
|
+
constructor(session, channel) {
|
|
3019
|
+
const service = session.getRecentContactService();
|
|
3020
|
+
if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3021
|
+
this.service = service;
|
|
3022
|
+
this.channel = channel;
|
|
3023
|
+
}
|
|
3024
|
+
/** 注册原生监听(幂等)。 */
|
|
3025
|
+
register() {
|
|
3026
|
+
if (this.listenerId !== null) return;
|
|
3027
|
+
const listener = {
|
|
3028
|
+
onRecentContactListChangedVer2: (lists) => this.channel.emit("RecentContact/onRecentContactListChangedVer2", lists),
|
|
3029
|
+
onRecentContactNotification: (contacts) => this.channel.emit("RecentContact/onRecentContactNotification", contacts)
|
|
3030
|
+
};
|
|
3031
|
+
this.listenerId = this.service.addKernelRecentContactListener(listener);
|
|
3032
|
+
}
|
|
3033
|
+
/** 注销原生监听(幂等)。 */
|
|
3034
|
+
unregister() {
|
|
3035
|
+
if (this.listenerId === null) return;
|
|
3036
|
+
this.service.removeKernelRecentContactListener(this.listenerId);
|
|
3037
|
+
this.listenerId = null;
|
|
3038
|
+
}
|
|
3039
|
+
};
|
|
3040
|
+
// src/event-channel.ts
|
|
2964
3041
|
/**
|
|
2965
3042
|
* 类型化事件通道(ADR-003)
|
|
2966
3043
|
*
|
|
@@ -3067,8 +3144,7 @@ var NTEventChannel = class {
|
|
|
3067
3144
|
};
|
|
3068
3145
|
}
|
|
3069
3146
|
};
|
|
3070
|
-
|
|
3071
|
-
//#region src/cache/buddy-cache.ts
|
|
3147
|
+
// src/cache/buddy-cache.ts
|
|
3072
3148
|
/**
|
|
3073
3149
|
* 防御性收窄 onBuddyListChange 载荷 → BuddyCategory[](T10 实证形状;
|
|
3074
3150
|
* 非数组返回 null,调用方打 raw 日志积累校准数据)。
|
|
@@ -3146,8 +3222,7 @@ var BuddyCache = class {
|
|
|
3146
3222
|
return this.bootstrapped;
|
|
3147
3223
|
}
|
|
3148
3224
|
};
|
|
3149
|
-
|
|
3150
|
-
//#region src/login/wait.ts
|
|
3225
|
+
// src/login/wait.ts
|
|
3151
3226
|
/**
|
|
3152
3227
|
* 等待/延迟工具(login 模块共享,2026-08-08 克隆合并)
|
|
3153
3228
|
*/
|
|
@@ -3175,8 +3250,7 @@ function sleep(ms) {
|
|
|
3175
3250
|
setTimeout(resolve, ms);
|
|
3176
3251
|
});
|
|
3177
3252
|
}
|
|
3178
|
-
|
|
3179
|
-
//#region src/cache/group-cache.ts
|
|
3253
|
+
// src/cache/group-cache.ts
|
|
3180
3254
|
/**
|
|
3181
3255
|
* 群/成员缓存:事件主动维护 + 查询惰性回填。
|
|
3182
3256
|
* 只读接口 getGroupDetail / getMembers / getMember / getGroup(列表项)。
|
|
@@ -3339,8 +3413,7 @@ var GroupCache = class {
|
|
|
3339
3413
|
return await task;
|
|
3340
3414
|
}
|
|
3341
3415
|
};
|
|
3342
|
-
|
|
3343
|
-
//#region src/context.ts
|
|
3416
|
+
// src/context.ts
|
|
3344
3417
|
/** 创建装配根(初始 wrapper/login 为 null)。 */
|
|
3345
3418
|
function createCoreContext(opts) {
|
|
3346
3419
|
return {
|
|
@@ -3350,8 +3423,7 @@ function createCoreContext(opts) {
|
|
|
3350
3423
|
login: null
|
|
3351
3424
|
};
|
|
3352
3425
|
}
|
|
3353
|
-
|
|
3354
|
-
//#region src/wrapper/wrapper-adapters.ts
|
|
3426
|
+
// src/wrapper/wrapper-adapters.ts
|
|
3355
3427
|
/** NAPI 回调占位(方法存在即可被反射调用,无副作用)。 */
|
|
3356
3428
|
const noop = () => void 0;
|
|
3357
3429
|
/** NodeIGlobalAdapter 实现(engine.initWithDeskTopConfig 第二参)。 */
|
|
@@ -3400,8 +3472,7 @@ function createSessionListener(opts = {}) {
|
|
|
3400
3472
|
function createLoginListener() {
|
|
3401
3473
|
return {};
|
|
3402
3474
|
}
|
|
3403
|
-
|
|
3404
|
-
//#region src/login/login-connect.ts
|
|
3475
|
+
// src/login/login-connect.ts
|
|
3405
3476
|
/**
|
|
3406
3477
|
* 登录连接与快速登录(从 lifecycle.ts 拆分,2026-08-08 FTA 优化)
|
|
3407
3478
|
*
|
|
@@ -3590,8 +3661,7 @@ async function quickLogin(ctx, opts = {}) {
|
|
|
3590
3661
|
if (items.length === 0) throw kernelError("无历史登录账号", "NOT_LOGIN");
|
|
3591
3662
|
return loginWithNetworkRetry(ctx, loginService, pickLoginTarget(items, opts.uin), opts, quickTimeoutMs);
|
|
3592
3663
|
}
|
|
3593
|
-
|
|
3594
|
-
//#region src/login/lifecycle.ts
|
|
3664
|
+
// src/login/lifecycle.ts
|
|
3595
3665
|
/**
|
|
3596
3666
|
* 完整启动生命周期(wrapper.node 契约流程,2026-08-05 实测确认,自研实现)
|
|
3597
3667
|
*
|
|
@@ -3694,8 +3764,7 @@ function startupSessionStart(ctx) {
|
|
|
3694
3764
|
} catch {}
|
|
3695
3765
|
return true;
|
|
3696
3766
|
}
|
|
3697
|
-
|
|
3698
|
-
//#region src/login/login.ts
|
|
3767
|
+
// src/login/login.ts
|
|
3699
3768
|
/**
|
|
3700
3769
|
* login.ts:QR 登录流程编排 + 状态机 + selfInfo(ADR-010,2026-08-05)
|
|
3701
3770
|
*
|
|
@@ -3861,8 +3930,7 @@ var QrLoginSession = class {
|
|
|
3861
3930
|
for (const cb of this.qrCodeHandlers) cb(qr);
|
|
3862
3931
|
}
|
|
3863
3932
|
};
|
|
3864
|
-
|
|
3865
|
-
//#region src/wrapper/qq-data-path.ts
|
|
3933
|
+
// src/wrapper/qq-data-path.ts
|
|
3866
3934
|
/**
|
|
3867
3935
|
* QQ 数据根路径解析(P2-1,2026-08-06)
|
|
3868
3936
|
*
|
|
@@ -3922,8 +3990,7 @@ function findInObject(value) {
|
|
|
3922
3990
|
}
|
|
3923
3991
|
return null;
|
|
3924
3992
|
}
|
|
3925
|
-
|
|
3926
|
-
//#region src/wrapper/wrapper-config.ts
|
|
3993
|
+
// src/wrapper/wrapper-config.ts
|
|
3927
3994
|
/**
|
|
3928
3995
|
* wrapper 交互配置装配(纯函数,无状态)
|
|
3929
3996
|
*
|
|
@@ -4132,8 +4199,7 @@ function readMachineGuid(loginService) {
|
|
|
4132
4199
|
return "";
|
|
4133
4200
|
}
|
|
4134
4201
|
}
|
|
4135
|
-
|
|
4136
|
-
//#region src/wrapper/wrapper-loader.ts
|
|
4202
|
+
// src/wrapper/wrapper-loader.ts
|
|
4137
4203
|
/**
|
|
4138
4204
|
* wrapper 引导(NAPI 范式,2026-08-05 重构,替代旧 koffi 方案)
|
|
4139
4205
|
*
|
|
@@ -4362,8 +4428,7 @@ function getOrCreateLoginService(exports) {
|
|
|
4362
4428
|
return null;
|
|
4363
4429
|
}
|
|
4364
4430
|
}
|
|
4365
|
-
|
|
4366
|
-
//#region src/core.ts
|
|
4431
|
+
// src/core.ts
|
|
4367
4432
|
/**
|
|
4368
4433
|
* NapukettoCore:装配 + 启动(§9 第 6 项,2026-08-05 实现)
|
|
4369
4434
|
*
|
|
@@ -4609,8 +4674,7 @@ function resolveCommonPath(ctx, wrapper) {
|
|
|
4609
4674
|
}
|
|
4610
4675
|
return ctx.paths.accountDir;
|
|
4611
4676
|
}
|
|
4612
|
-
|
|
4613
|
-
//#region src/wrapper/session-resolver.ts
|
|
4677
|
+
// src/wrapper/session-resolver.ts
|
|
4614
4678
|
/** 从 getSessionIdList 的 Map 提取主 sessionId(nt_ 前缀优先)。 */
|
|
4615
4679
|
function findMainSessionId(ids) {
|
|
4616
4680
|
return firstStringId(ids, (s) => s.startsWith("nt_")) ?? firstStringId(ids, () => true);
|
|
@@ -4681,8 +4745,7 @@ function resolveMainFromStartup(ctx) {
|
|
|
4681
4745
|
if (session !== null) ctx.session = session;
|
|
4682
4746
|
return session;
|
|
4683
4747
|
}
|
|
4684
|
-
|
|
4685
|
-
//#region src/wrapper/probe/probe-serialize.ts
|
|
4748
|
+
// src/wrapper/probe/probe-serialize.ts
|
|
4686
4749
|
/**
|
|
4687
4750
|
* 运行时反射探测的序列化工具(从 probe.ts 拆分,2026-08-08 FTA 优化)
|
|
4688
4751
|
*
|
|
@@ -4789,8 +4852,7 @@ function tryShape(session, getter) {
|
|
|
4789
4852
|
return "[error]";
|
|
4790
4853
|
}
|
|
4791
4854
|
}
|
|
4792
|
-
|
|
4793
|
-
//#region src/wrapper/probe/probe-utils.ts
|
|
4855
|
+
// src/wrapper/probe/probe-utils.ts
|
|
4794
4856
|
/**
|
|
4795
4857
|
* 运行时反射探测基础工具(从 probe.ts 拆分,2026-08-08 FTA 优化)
|
|
4796
4858
|
*
|
|
@@ -4846,8 +4908,7 @@ function tryCall(obj, name) {
|
|
|
4846
4908
|
function isServiceGetter(name) {
|
|
4847
4909
|
return name.startsWith("get") && name.endsWith("Service");
|
|
4848
4910
|
}
|
|
4849
|
-
|
|
4850
|
-
//#region src/wrapper/probe/probe-services.ts
|
|
4911
|
+
// src/wrapper/probe/probe-services.ts
|
|
4851
4912
|
/** 探测关键 export 构造器方法(get/create/getNTWrapperSession 等)。 */
|
|
4852
4913
|
function probeExportCtors(ctx) {
|
|
4853
4914
|
const keys = [
|
|
@@ -4916,8 +4977,7 @@ const LOGIN_GETTER_PROBES = [
|
|
|
4916
4977
|
"getUid",
|
|
4917
4978
|
"getSelfUin"
|
|
4918
4979
|
];
|
|
4919
|
-
|
|
4920
|
-
//#region src/wrapper/probe/probe.ts
|
|
4980
|
+
// src/wrapper/probe/probe.ts
|
|
4921
4981
|
/**
|
|
4922
4982
|
* 运行时反射探测(ADR-006 落地,P1-4)
|
|
4923
4983
|
*
|
|
@@ -5194,8 +5254,7 @@ function writeProbeFile(result, file) {
|
|
|
5194
5254
|
result["probeFileError"] = errMsgString(e);
|
|
5195
5255
|
}
|
|
5196
5256
|
}
|
|
5197
|
-
|
|
5198
|
-
//#region src/wrapper/probe/probe-listener.ts
|
|
5257
|
+
// src/wrapper/probe/probe-listener.ts
|
|
5199
5258
|
/**
|
|
5200
5259
|
* listener 录制器(批次三前置探测,docs/protocols/milky.md §0.8.1、本包 design.md §10)
|
|
5201
5260
|
*
|
|
@@ -5385,8 +5444,7 @@ function attachRecordingListener(name, service, emit) {
|
|
|
5385
5444
|
...typeof listenerId === "number" ? { listenerId } : {}
|
|
5386
5445
|
};
|
|
5387
5446
|
}
|
|
5388
|
-
|
|
5389
|
-
//#region src/wrapper/wrapper-version.ts
|
|
5447
|
+
// src/wrapper/wrapper-version.ts
|
|
5390
5448
|
/**
|
|
5391
5449
|
* QQ 安装目录探测(ADR-018)
|
|
5392
5450
|
*
|
|
@@ -5442,7 +5500,6 @@ function listQQVersions(installDir) {
|
|
|
5442
5500
|
return statSync(full).isDirectory() && existsSync(join(full, "resources", "app", "wrapper.node"));
|
|
5443
5501
|
}).sort().reverse();
|
|
5444
5502
|
}
|
|
5445
|
-
|
|
5446
|
-
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, EXIT_CONFIG_INVALID, ElementType, FriendApi, FriendBridge, GrayTipSubType, GroupApi, GroupBridge, GroupCache, GroupListUpdateType, GroupNotifyApi, GroupNotifyMsgStatus, GroupNotifyMsgType, KERNEL_ERROR_CODES, KernelError, MAIN_CONFIG_FILE, MsgApi, MsgBridge, NTEventChannel, NTGroupMemberRole, NTGroupRequestOperateTypes, NapukettoCore, PathWrapper, ProfileApi, ProfileLikeApi, QrLoginSession, RecentContactApi, 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 };
|
|
5503
|
+
export { BuddyCache, ChatType, ConfigBase, ConfigError, DEFAULT_DATA_ROOT_NAME, EXIT_CONFIG_INVALID, ElementType, 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 };
|
|
5447
5504
|
|
|
5448
5505
|
//# sourceMappingURL=index.mjs.map
|