@napuketto/kernel 0.13.0 → 0.14.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 +188 -59
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +785 -341
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -64,6 +64,112 @@ function configError(message, options) {
|
|
|
64
64
|
}
|
|
65
65
|
/** 配置校验失败的进程退出码(UNIX sysexits EX_CONFIG 惯例)。 */
|
|
66
66
|
const EXIT_CONFIG_INVALID = 78;
|
|
67
|
+
// src/utils/type-guards.ts
|
|
68
|
+
/**
|
|
69
|
+
* 通用运行时类型守卫集(全仓复用,零依赖)
|
|
70
|
+
*
|
|
71
|
+
* 目标:把「外部边界进来的 unknown」经**可证明的**运行时检查收窄为业务类型,
|
|
72
|
+
* 取代双重断言 / 单重断言一类绕过编译器的虚假类型安全。
|
|
73
|
+
*
|
|
74
|
+
* 约定:
|
|
75
|
+
* - 只做形状判定,不做业务语义校验(业务错误仍由调用方抛 KernelError);
|
|
76
|
+
* - 守卫是 `val is T` 型谓词,收窄由编译器自然推导,调用方无需再断言;
|
|
77
|
+
* - 失败路径统一经 kernelError 抛 INVALID_STATE(ADR-009),不抛裸 Error。
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
/** 判断未知值是否为非 null、非数组的普通对象 Record。 */
|
|
81
|
+
function isRecord(val) {
|
|
82
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
83
|
+
}
|
|
84
|
+
/** 判断未知值是否为可调用的函数。 */
|
|
85
|
+
function isCallable(val) {
|
|
86
|
+
return typeof val === "function";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 安全读取任意值上的属性(支持 plain object 及带有原型链的原生 C++ 包装实例 / 函数对象)。
|
|
90
|
+
*/
|
|
91
|
+
function getOwnProp(val, key) {
|
|
92
|
+
if (typeof val !== "object" && typeof val !== "function" || val === null) return;
|
|
93
|
+
return Reflect.get(val, key);
|
|
94
|
+
}
|
|
95
|
+
/** 判断未知值是否为包含指定 string 属性的对象。 */
|
|
96
|
+
function hasStringProp(val, key) {
|
|
97
|
+
return isRecord(val) && typeof val[key] === "string";
|
|
98
|
+
}
|
|
99
|
+
/** 判断未知值是否为包含指定有限 number 属性的对象。 */
|
|
100
|
+
function hasNumberProp(val, key) {
|
|
101
|
+
return isRecord(val) && typeof val[key] === "number" && Number.isFinite(val[key]);
|
|
102
|
+
}
|
|
103
|
+
/** 判断未知值是否为包含指定 boolean 属性的对象。 */
|
|
104
|
+
function hasBooleanProp(val, key) {
|
|
105
|
+
return isRecord(val) && typeof val[key] === "boolean";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 判断未知值(对象或原生构造器函数)是否具备指定名称的可调用方法。
|
|
109
|
+
* 注意:参数类型收窄为 `...args: unknown[]`,支持直接传参或 `.call(target, ...)` 调用。
|
|
110
|
+
*/
|
|
111
|
+
function hasFunctionProp(val, key) {
|
|
112
|
+
if (typeof val !== "object" && typeof val !== "function" || val === null) return false;
|
|
113
|
+
return typeof Reflect.get(val, key) === "function";
|
|
114
|
+
}
|
|
115
|
+
/** `hasFunctionProp` 的语义别名,专用于反射与原生边界探测。 */
|
|
116
|
+
const hasCallableProp = hasFunctionProp;
|
|
117
|
+
/**
|
|
118
|
+
* 判断目标对象/实例是否同时具备一组方法面(Method Surface)。
|
|
119
|
+
*/
|
|
120
|
+
function hasMethodSurface(val, methods) {
|
|
121
|
+
if (typeof val !== "object" && typeof val !== "function" || val === null) return false;
|
|
122
|
+
for (const m of methods) if (typeof Reflect.get(val, m) !== "function") return false;
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
/** 判断未知值是否为包含静态 `.get()` 工厂方法的原生导出项。 */
|
|
126
|
+
function hasStaticGetter(val) {
|
|
127
|
+
return hasFunctionProp(val, "get");
|
|
128
|
+
}
|
|
129
|
+
/** 判断未知值是否为包含静态 `.create()` 工厂方法的原生导出项。 */
|
|
130
|
+
function hasStaticCreator(val) {
|
|
131
|
+
return hasFunctionProp(val, "create");
|
|
132
|
+
}
|
|
133
|
+
/** 判断未知值是否为 Promise-like(具备 `.then` 与 `.catch` 方法)。 */
|
|
134
|
+
function isPromiseLike(val) {
|
|
135
|
+
return hasFunctionProp(val, "then") && hasFunctionProp(val, "catch");
|
|
136
|
+
}
|
|
137
|
+
/** 从未知异常中安全提取系统错误码(如 ENOENT / ESRCH / EPERM)。 */
|
|
138
|
+
function getErrorCode(err) {
|
|
139
|
+
if (!isRecord(err)) return void 0;
|
|
140
|
+
return typeof err["code"] === "string" ? err["code"] : void 0;
|
|
141
|
+
}
|
|
142
|
+
/** 从未知异常中安全提取错误消息文本。 */
|
|
143
|
+
function getErrorMessage(err) {
|
|
144
|
+
if (err instanceof Error) return err.message;
|
|
145
|
+
if (isRecord(err) && typeof err["message"] === "string") return err["message"];
|
|
146
|
+
return String(err);
|
|
147
|
+
}
|
|
148
|
+
/** 安全解析 JSON 文本并交由类型守卫验证,校验失败或解析抛错均返回 null。 */
|
|
149
|
+
function parseJsonWithGuard(raw, guard) {
|
|
150
|
+
try {
|
|
151
|
+
const parsed = JSON.parse(raw);
|
|
152
|
+
return guard(parsed) ? parsed : null;
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 校验原生 Kernel Service 实例是否非空且具备要求的核心方法集合。
|
|
159
|
+
*
|
|
160
|
+
* 原生 `get*Service()` 在 session 未 init / 句柄失效时可能返回 null、undefined、
|
|
161
|
+
* 已 `isNull()` 的空句柄或残缺对象——直接断言成 NodeIKernel*Service
|
|
162
|
+
* 会让调用方在第一次方法调用时炸出裸 TypeError。这里统一在边界拦截:
|
|
163
|
+
* 空 / 非对象 / isNull() === true / 缺失关键方法一律抛 INVALID_STATE。
|
|
164
|
+
*/
|
|
165
|
+
function requireKernelService(service, serviceName, requiredMethods = []) {
|
|
166
|
+
if (service === null || service === void 0 || typeof service !== "object") throw kernelError(`${serviceName}() 返回空(session 未 init)`, "INVALID_STATE");
|
|
167
|
+
if (hasFunctionProp(service, "isNull")) {
|
|
168
|
+
if (service["isNull"]() === true) throw kernelError(`${serviceName}() 返回空句柄(isNull 为 true)`, "INVALID_STATE");
|
|
169
|
+
}
|
|
170
|
+
for (const method of requiredMethods) if (typeof Reflect.get(service, method) !== "function") throw kernelError(`${serviceName}() 返回对象缺失必要方法: ${method}`, "INVALID_STATE");
|
|
171
|
+
return service;
|
|
172
|
+
}
|
|
67
173
|
// src/infra/config.ts
|
|
68
174
|
/**
|
|
69
175
|
* 配置基类(ADR-012)
|
|
@@ -81,7 +187,7 @@ function inferFormat(path) {
|
|
|
81
187
|
return "json";
|
|
82
188
|
}
|
|
83
189
|
function isMissingFileError(err) {
|
|
84
|
-
if (err instanceof Error) return err
|
|
190
|
+
if (err instanceof Error) return getErrorCode(err) === "ENOENT";
|
|
85
191
|
return false;
|
|
86
192
|
}
|
|
87
193
|
/**
|
|
@@ -152,7 +258,10 @@ var ConfigBase = class {
|
|
|
152
258
|
}
|
|
153
259
|
/** 对象 → 文本(TOML/JSON)。 */
|
|
154
260
|
serialize(value) {
|
|
155
|
-
if (this.format === "toml")
|
|
261
|
+
if (this.format === "toml") {
|
|
262
|
+
if (!isRecord(value)) throw configError(`TOML 配置根必须是对象: ${this.path}`);
|
|
263
|
+
return stringify(value);
|
|
264
|
+
}
|
|
156
265
|
return JSON.stringify(value, null, 4);
|
|
157
266
|
}
|
|
158
267
|
/** 文本 → 对象(TOML/JSON)。 */
|
|
@@ -224,20 +333,34 @@ const MODULE_NAME_VALUES = [
|
|
|
224
333
|
"loader",
|
|
225
334
|
"ob11"
|
|
226
335
|
];
|
|
336
|
+
/** 运行时判定是否为日志级别。 */
|
|
337
|
+
function isLogLevel(value) {
|
|
338
|
+
return typeof value === "string" && LOG_LEVEL_VALUES.some((v) => v === value);
|
|
339
|
+
}
|
|
340
|
+
/** 运行时判定是否为控制台输出格式。 */
|
|
341
|
+
function isLogFormat(value) {
|
|
342
|
+
return typeof value === "string" && LOG_FORMAT_VALUES.some((v) => v === value);
|
|
343
|
+
}
|
|
344
|
+
/** 运行时判定是否为时间戳模式。 */
|
|
345
|
+
function isTimestampMode(value) {
|
|
346
|
+
return typeof value === "string" && TIMESTAMP_MODE_VALUES.some((v) => v === value);
|
|
347
|
+
}
|
|
348
|
+
/** 运行时判定是否为可覆盖级别的模块名。 */
|
|
349
|
+
function isLogModuleName(value) {
|
|
350
|
+
return MODULE_NAME_VALUES.some((v) => v === value);
|
|
351
|
+
}
|
|
227
352
|
/** 校验级别字面量;非法值抛 INVALID_PARAM。 */
|
|
228
353
|
function requireLevel(value, key) {
|
|
229
|
-
if (
|
|
354
|
+
if (!isLogLevel(value)) throw kernelError(`主配置 ${key} 必须是日志级别(${LOG_LEVEL_VALUES.join(" / ")})`, "INVALID_PARAM");
|
|
230
355
|
return value;
|
|
231
356
|
}
|
|
232
357
|
/** 宽松级别解析(env 覆盖用;非法/缺失返回 undefined 不生效)。 */
|
|
233
358
|
function optionalLevel(value) {
|
|
234
|
-
|
|
235
|
-
return LOG_LEVEL_VALUES.includes(value) ? value : void 0;
|
|
359
|
+
return isLogLevel(value) ? value : void 0;
|
|
236
360
|
}
|
|
237
361
|
/** 宽松格式解析(env 覆盖用)。 */
|
|
238
362
|
function optionalFormat(value) {
|
|
239
|
-
|
|
240
|
-
return LOG_FORMAT_VALUES.includes(value) ? value : void 0;
|
|
363
|
+
return isLogFormat(value) ? value : void 0;
|
|
241
364
|
}
|
|
242
365
|
/** 宽松布尔解析(env 用:仅识别 1/true/0/false,其余忽略)。 */
|
|
243
366
|
function optionalBool(value) {
|
|
@@ -247,41 +370,44 @@ function optionalBool(value) {
|
|
|
247
370
|
/** 解析 [log.levels] 按模块覆盖表(未知模块名报错,键集封闭防拼写错误)。 */
|
|
248
371
|
function parseModuleLevels(raw) {
|
|
249
372
|
if (raw === void 0) return {};
|
|
250
|
-
if (
|
|
373
|
+
if (!isRecord(raw)) throw kernelError("主配置 log.levels 必须是对象", "INVALID_PARAM");
|
|
251
374
|
const out = {};
|
|
252
375
|
for (const [key, value] of Object.entries(raw)) {
|
|
253
|
-
if (!
|
|
376
|
+
if (!isLogModuleName(key)) throw kernelError(`主配置 log.levels 未知模块 "${key}"(合法模块:${MODULE_NAME_VALUES.join(" / ")})`, "INVALID_PARAM");
|
|
254
377
|
out[key] = requireLevel(value, `log.levels.${key}`);
|
|
255
378
|
}
|
|
256
379
|
return out;
|
|
257
380
|
}
|
|
258
381
|
/** 解析 [log.file] 独立文件 sink。 */
|
|
259
382
|
function parseLogFile(raw, fallbackLevel) {
|
|
260
|
-
if (
|
|
261
|
-
const
|
|
262
|
-
const path = record["path"];
|
|
383
|
+
if (!isRecord(raw)) throw kernelError("主配置 log.file 必须是对象", "INVALID_PARAM");
|
|
384
|
+
const path = raw["path"];
|
|
263
385
|
if (typeof path !== "string" || path === "") throw kernelError("主配置 log.file.path 必须是非空字符串", "INVALID_PARAM");
|
|
264
386
|
return {
|
|
265
387
|
path,
|
|
266
|
-
level:
|
|
388
|
+
level: raw["level"] === void 0 ? fallbackLevel : requireLevel(raw["level"], "log.file.level")
|
|
267
389
|
};
|
|
268
390
|
}
|
|
269
|
-
/** 校验字面量枚举值(非法抛 INVALID_PARAM,报错文案带键名与合法值集)。 */
|
|
270
|
-
function requireEnum(value, key, values) {
|
|
271
|
-
if (typeof value !== "string" || !values.includes(value)) throw kernelError(`主配置 ${key} 必须是(${values.join(" / ")})`, "INVALID_PARAM");
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
391
|
/** 校验布尔字段(undefined 保留原值)。 */
|
|
275
392
|
function applyBoolean(draft, raw, key) {
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
|
|
393
|
+
const value = raw[key];
|
|
394
|
+
if (value === void 0) return;
|
|
395
|
+
if (typeof value !== "boolean") throw kernelError(`主配置 log.${key} 必须是布尔值`, "INVALID_PARAM");
|
|
396
|
+
draft[key] = value;
|
|
279
397
|
}
|
|
280
398
|
/** toml [log] 段字段填充(level/format/timestamp/banner/unboundReceive)。 */
|
|
281
399
|
function applySectionFields(draft, raw) {
|
|
282
400
|
if (raw["level"] !== void 0) draft.level = requireLevel(raw["level"], "log.level");
|
|
283
|
-
|
|
284
|
-
if (
|
|
401
|
+
const format = raw["format"];
|
|
402
|
+
if (format !== void 0) {
|
|
403
|
+
if (!isLogFormat(format)) throw kernelError(`主配置 log.format 必须是(${LOG_FORMAT_VALUES.join(" / ")})`, "INVALID_PARAM");
|
|
404
|
+
draft.format = format;
|
|
405
|
+
}
|
|
406
|
+
const timestamp = raw["timestamp"];
|
|
407
|
+
if (timestamp !== void 0) {
|
|
408
|
+
if (!isTimestampMode(timestamp)) throw kernelError(`主配置 log.timestamp 必须是(${TIMESTAMP_MODE_VALUES.join(" / ")})`, "INVALID_PARAM");
|
|
409
|
+
draft.timestamp = timestamp;
|
|
410
|
+
}
|
|
285
411
|
applyBoolean(draft, raw, "banner");
|
|
286
412
|
applyBoolean(draft, raw, "unboundReceive");
|
|
287
413
|
}
|
|
@@ -317,13 +443,13 @@ function parseLogConfig(section, env = {}) {
|
|
|
317
443
|
levels: {}
|
|
318
444
|
};
|
|
319
445
|
if (section !== void 0) {
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
draft.file = parseLogFile(
|
|
326
|
-
draft.fileLevelExplicit =
|
|
446
|
+
if (!isRecord(section)) throw kernelError("主配置 log 段必须是对象", "INVALID_PARAM");
|
|
447
|
+
applySectionFields(draft, section);
|
|
448
|
+
draft.levels = parseModuleLevels(section["levels"]);
|
|
449
|
+
const file = section["file"];
|
|
450
|
+
if (file !== void 0) {
|
|
451
|
+
draft.file = parseLogFile(file, draft.level);
|
|
452
|
+
draft.fileLevelExplicit = isRecord(file) && file["level"] !== void 0;
|
|
327
453
|
}
|
|
328
454
|
}
|
|
329
455
|
applyEnvOverrides(draft, env);
|
|
@@ -437,8 +563,8 @@ function renderJsonLine(record, ctx) {
|
|
|
437
563
|
const jsonLine = {
|
|
438
564
|
time: renderTime(time, ctx.timestamp, true, ctx.timeOriginMs),
|
|
439
565
|
level: levelLabel(level).toLowerCase(),
|
|
440
|
-
...module
|
|
441
|
-
...account
|
|
566
|
+
...typeof module === "string" ? { module } : typeof name === "string" ? { module: name } : {},
|
|
567
|
+
...typeof account === "string" ? { account } : {},
|
|
442
568
|
...typeof pid === "number" ? { pid } : {},
|
|
443
569
|
msg,
|
|
444
570
|
...fields
|
|
@@ -532,7 +658,7 @@ function renderMultilineStringLines(value, depth) {
|
|
|
532
658
|
*/
|
|
533
659
|
function renderValueLines(value, depth) {
|
|
534
660
|
if (Array.isArray(value)) return renderArrayLines(value, depth);
|
|
535
|
-
if (
|
|
661
|
+
if (isRecord(value)) return renderObjectLines(value, depth);
|
|
536
662
|
if (typeof value === "string" && value.includes("\n")) return renderMultilineStringLines(value, depth);
|
|
537
663
|
return [`${NESTED_INDENT.repeat(depth)}${renderScalar(value)}`];
|
|
538
664
|
}
|
|
@@ -563,14 +689,18 @@ function createConsoleFormatStream(opts) {
|
|
|
563
689
|
};
|
|
564
690
|
const render = opts.format === "pretty" ? renderPrettyLine : opts.format === "json" ? renderJsonLine : renderSingleLine;
|
|
565
691
|
return { write(line) {
|
|
566
|
-
let
|
|
692
|
+
let parsed;
|
|
567
693
|
try {
|
|
568
|
-
|
|
694
|
+
parsed = JSON.parse(line);
|
|
569
695
|
} catch {
|
|
570
696
|
out.write(`${line}\n`);
|
|
571
697
|
return;
|
|
572
698
|
}
|
|
573
|
-
|
|
699
|
+
if (!isRecord(parsed)) {
|
|
700
|
+
out.write(`${line}\n`);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
out.write(render(parsed, ctx));
|
|
574
704
|
} };
|
|
575
705
|
}
|
|
576
706
|
// src/infra/logger.ts
|
|
@@ -877,10 +1007,17 @@ function unwrap(label, result, errMsg) {
|
|
|
877
1007
|
if (result === 0) return;
|
|
878
1008
|
throw kernelError(`${label} 失败: ${errMsg ?? "无错误详情"}`, "UNKNOWN");
|
|
879
1009
|
}
|
|
880
|
-
/**
|
|
1010
|
+
/**
|
|
1011
|
+
* 宽松 result 校验(result 为数字非 0 视为失败;缺失/非对象/非数字视为成功)。
|
|
1012
|
+
*
|
|
1013
|
+
* 入参故意收为 unknown:原生方法返回形状在探测期不稳定,调用方无需为
|
|
1014
|
+
* 「把返回值塞进宽松形状」再写 `as { result?: unknown }` 断言。
|
|
1015
|
+
*/
|
|
881
1016
|
function checkLooseResult(label, res) {
|
|
882
|
-
if (res
|
|
883
|
-
|
|
1017
|
+
if (!isRecord(res)) return;
|
|
1018
|
+
const result = res["result"];
|
|
1019
|
+
if (typeof result !== "number" || result === 0) return;
|
|
1020
|
+
throw kernelError(`${label} 失败: ${String(res["errMsg"] ?? "")}`, "UNKNOWN");
|
|
884
1021
|
}
|
|
885
1022
|
/** 原生结果解包:result !== 0 抛 KernelError(errMsg 语义映射错误码)。 */
|
|
886
1023
|
function unwrapResult(label, raw) {
|
|
@@ -911,9 +1048,11 @@ const PATH_SEPARATORS = /[\\/]/;
|
|
|
911
1048
|
var FlashTransferApi = class {
|
|
912
1049
|
service;
|
|
913
1050
|
constructor(session) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1051
|
+
this.service = requireKernelService(session.getFlashTransferService(), "getFlashTransferService", [
|
|
1052
|
+
"createFlashTransferUploadTask",
|
|
1053
|
+
"addFileSetUploadListener",
|
|
1054
|
+
"sendFlashTransferMsg"
|
|
1055
|
+
]);
|
|
917
1056
|
}
|
|
918
1057
|
/**
|
|
919
1058
|
* 上传文件集(`createFlashTransferUploadTask`)。所有文件 `onFileDidFinishUpload`
|
|
@@ -1051,9 +1190,7 @@ var FriendApi = class {
|
|
|
1051
1190
|
service;
|
|
1052
1191
|
uidToUin;
|
|
1053
1192
|
constructor(session, opts = {}) {
|
|
1054
|
-
|
|
1055
|
-
if (service === null || service === void 0) throw kernelError("getBuddyService() 返回空(session 未 init)", "INVALID_STATE");
|
|
1056
|
-
this.service = service;
|
|
1193
|
+
this.service = requireKernelService(session.getBuddyService(), "getBuddyService", ["getBuddyListFromCache", "getBuddyNick"]);
|
|
1057
1194
|
this.uidToUin = opts.uidToUin;
|
|
1058
1195
|
}
|
|
1059
1196
|
/** 好友列表(分类拍平为 Friend[];昵称/备注从 service 缓存读取)。 */
|
|
@@ -1617,15 +1754,6 @@ const GroupMemberDataSource = {
|
|
|
1617
1754
|
NETWORK: 1
|
|
1618
1755
|
};
|
|
1619
1756
|
// 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
1757
|
/** 平台类型(与 wrapper.node 的 platform 字段对应)。 */
|
|
1630
1758
|
const PlatformType = {
|
|
1631
1759
|
KUNKNOWN: 0,
|
|
@@ -1659,12 +1787,12 @@ var GroupApi = class {
|
|
|
1659
1787
|
/** 精华消息需要 msg service(按 msgId 拉消息取 msgSeq/msgRandom)。 */
|
|
1660
1788
|
msgService;
|
|
1661
1789
|
constructor(session) {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
this.msgService =
|
|
1790
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", [
|
|
1791
|
+
"getGroupList",
|
|
1792
|
+
"getGroupDetailInfo",
|
|
1793
|
+
"getAllMemberList"
|
|
1794
|
+
]);
|
|
1795
|
+
this.msgService = requireKernelService(session.getMsgService(), "getMsgService", ["getMsgsByMsgId"]);
|
|
1668
1796
|
}
|
|
1669
1797
|
/**
|
|
1670
1798
|
* 群列表(force=true 触发原生刷新)。
|
|
@@ -1688,40 +1816,42 @@ var GroupApi = class {
|
|
|
1688
1816
|
* 而是提取详情字段;形状异常抛 UNKNOWN 而非静默返回垃圾数据。 */
|
|
1689
1817
|
async getGroupInfo(groupCode) {
|
|
1690
1818
|
const raw = await this.service.getGroupDetailInfo(groupCode, 0);
|
|
1691
|
-
|
|
1819
|
+
if (!isRecord(raw)) throw kernelError("getGroupDetailInfo 返回非对象结果", "INVALID_PARAM");
|
|
1820
|
+
const result = raw["result"];
|
|
1821
|
+
const errMsg = typeof raw["errMsg"] === "string" ? raw["errMsg"] : "未知错误";
|
|
1692
1822
|
if (typeof result === "number" && result !== 0) unwrap("getGroupDetailInfo", result, errMsg);
|
|
1693
1823
|
const detail = extractGroupDetail(result, raw);
|
|
1694
|
-
if (detail === null) throw kernelError(`getGroupDetailInfo
|
|
1824
|
+
if (detail === null) throw kernelError(`getGroupDetailInfo 未返回群详情: ${errMsg}`, "INVALID_PARAM");
|
|
1695
1825
|
return detail;
|
|
1696
1826
|
}
|
|
1697
1827
|
/** 群成员列表(forceFetch=true 强制拉取,默认缓存优先)。 */
|
|
1698
1828
|
async getGroupMemberList(groupCode, forceFetch = false) {
|
|
1699
|
-
|
|
1700
|
-
if (raw.errCode !== 0) throw kernelError(`getAllMemberList 失败: ${raw.errMsg}`, "UNKNOWN");
|
|
1701
|
-
return [...raw.result.infos.values()];
|
|
1829
|
+
return memberListOf(extractMemberInfos(await this.service.getAllMemberList(groupCode, forceFetch)));
|
|
1702
1830
|
}
|
|
1703
1831
|
/** 群成员详情(uids 为空返回空数组)。 */
|
|
1704
1832
|
async getGroupMemberInfo(groupCode, uids) {
|
|
1705
1833
|
if (uids.length === 0) return [];
|
|
1706
1834
|
const raw = await this.service.getMemberInfo(groupCode, uids, true);
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
return [];
|
|
1835
|
+
if (!isRecord(raw)) throw kernelError("getMemberInfo 返回非对象结果", "INVALID_PARAM");
|
|
1836
|
+
unwrap("getMemberInfo", toResultNumber(raw["result"]), toOptionalString(raw["errMsg"]));
|
|
1837
|
+
const infos = raw["infos"];
|
|
1838
|
+
return infos instanceof Map ? memberListOf(infos) : [];
|
|
1711
1839
|
}
|
|
1712
1840
|
/** uin → uid(私聊发送等需要)。 */
|
|
1713
1841
|
async uinToUid(uins) {
|
|
1714
1842
|
if (uins.length === 0) return /* @__PURE__ */ new Map();
|
|
1715
1843
|
const raw = await this.service.getUidByUins(uins);
|
|
1716
|
-
if (raw
|
|
1717
|
-
|
|
1844
|
+
if (!isRecord(raw)) throw kernelError("getUidByUins 返回非对象结果", "INVALID_PARAM");
|
|
1845
|
+
if (toResultNumber(raw["errCode"]) !== 0) throw kernelError(`getUidByUins 失败: ${toOptionalString(raw["errMsg"]) ?? ""}`, "UNKNOWN");
|
|
1846
|
+
return toStringMap(raw["uids"]);
|
|
1718
1847
|
}
|
|
1719
1848
|
/** uid → uin。 */
|
|
1720
1849
|
async uidToUin(uids) {
|
|
1721
1850
|
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
1722
1851
|
const raw = await this.service.getUinByUids(uids);
|
|
1723
|
-
if (raw
|
|
1724
|
-
|
|
1852
|
+
if (!isRecord(raw)) throw kernelError("getUinByUids 返回非对象结果", "INVALID_PARAM");
|
|
1853
|
+
if (toResultNumber(raw["errCode"]) !== 0) throw kernelError(`getUinByUids 失败: ${toOptionalString(raw["errMsg"]) ?? ""}`, "UNKNOWN");
|
|
1854
|
+
return toStringMap(raw["uins"]);
|
|
1725
1855
|
}
|
|
1726
1856
|
/** 群成员角色 → OB11 role 字符串。 */
|
|
1727
1857
|
static roleToString(role) {
|
|
@@ -1835,8 +1965,10 @@ var GroupApi = class {
|
|
|
1835
1965
|
if (isKernelError(e)) throw e;
|
|
1836
1966
|
throw kernelError(`getGroupBulletin 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
1837
1967
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1968
|
+
const result = isRecord(raw) ? raw["result"] : void 0;
|
|
1969
|
+
const errMsg = isRecord(raw) ? toOptionalString(raw["errMsg"]) : void 0;
|
|
1970
|
+
unwrap("getGroupBulletin", toResultNumber(result), errMsg);
|
|
1971
|
+
return extractBulletins(result);
|
|
1840
1972
|
}
|
|
1841
1973
|
/**
|
|
1842
1974
|
* 发群公告(send_group_announcement;imagePath 提供时先 uploadGroupBulletinPic
|
|
@@ -1887,16 +2019,21 @@ var GroupApi = class {
|
|
|
1887
2019
|
async uploadBulletinPic(groupCode, imagePath) {
|
|
1888
2020
|
const res = await this.service.uploadGroupBulletinPic(groupCode, imagePath);
|
|
1889
2021
|
checkLooseResult("uploadGroupBulletinPic", res);
|
|
1890
|
-
return typeof res
|
|
2022
|
+
return isRecord(res) && typeof res["picId"] === "string" ? res["picId"] : "";
|
|
1891
2023
|
}
|
|
1892
2024
|
/** @all 剩余次数(get_group_at_all_remain)。 */
|
|
1893
2025
|
async getGroupRemainAtTimes(groupCode) {
|
|
1894
2026
|
const raw = await this.service.getGroupRemainAtTimes(groupCode);
|
|
1895
|
-
if (raw
|
|
2027
|
+
if (!isRecord(raw)) throw kernelError("getGroupRemainAtTimes 返回非对象结果", "INVALID_PARAM");
|
|
2028
|
+
const errCode = raw["errCode"];
|
|
2029
|
+
if (typeof errCode === "number" && errCode !== 0) throw kernelError(`getGroupRemainAtTimes 失败: ${typeof raw["errMsg"] === "string" ? raw["errMsg"] : "未知错误"}`, "UNKNOWN");
|
|
2030
|
+
const atInfo = raw["atInfo"];
|
|
2031
|
+
if (!isRecord(atInfo)) throw kernelError("getGroupRemainAtTimes 未返回 atInfo", "INVALID_PARAM");
|
|
2032
|
+
if (!hasBooleanProp(atInfo, "canAtAll") || !hasNumberProp(atInfo, "remainAtAllCountForUin") || !hasNumberProp(atInfo, "remainAtAllCountForGroup")) throw kernelError("getGroupRemainAtTimes 的 atInfo 字段不完整", "INVALID_PARAM");
|
|
1896
2033
|
return {
|
|
1897
|
-
canAtAll:
|
|
1898
|
-
remainAtAllCountForUin:
|
|
1899
|
-
remainAtAllCountForGroup:
|
|
2034
|
+
canAtAll: atInfo["canAtAll"],
|
|
2035
|
+
remainAtAllCountForUin: atInfo["remainAtAllCountForUin"],
|
|
2036
|
+
remainAtAllCountForGroup: atInfo["remainAtAllCountForGroup"]
|
|
1900
2037
|
};
|
|
1901
2038
|
}
|
|
1902
2039
|
};
|
|
@@ -1904,59 +2041,101 @@ var GroupApi = class {
|
|
|
1904
2041
|
function toResultNumber(result) {
|
|
1905
2042
|
return typeof result === "number" ? result : 0;
|
|
1906
2043
|
}
|
|
2044
|
+
/** 未知值 → string | undefined(非字符串一律丢弃)。 */
|
|
2045
|
+
function toOptionalString(value) {
|
|
2046
|
+
return typeof value === "string" ? value : void 0;
|
|
2047
|
+
}
|
|
2048
|
+
/** 字符串键值 Map 收窄(非 Map / 非 string 项丢弃,不做元素级强转)。 */
|
|
2049
|
+
function toStringMap(value) {
|
|
2050
|
+
const out = /* @__PURE__ */ new Map();
|
|
2051
|
+
if (!(value instanceof Map)) return out;
|
|
2052
|
+
for (const [key, val] of value) if (typeof key === "string" && typeof val === "string") out.set(key, val);
|
|
2053
|
+
return out;
|
|
2054
|
+
}
|
|
2055
|
+
/** 可选字段:缺失(undefined/null)放行,存在时必须是 string。 */
|
|
2056
|
+
function isOptionalString$2(rec, key) {
|
|
2057
|
+
const v = rec[key];
|
|
2058
|
+
return v === void 0 || v === null || typeof v === "string";
|
|
2059
|
+
}
|
|
2060
|
+
/** 可选字段:缺失(undefined/null)放行,存在时必须是有限 number。 */
|
|
2061
|
+
function isOptionalNumber$2(rec, key) {
|
|
2062
|
+
const v = rec[key];
|
|
2063
|
+
return v === void 0 || v === null || typeof v === "number" && Number.isFinite(v);
|
|
2064
|
+
}
|
|
2065
|
+
/** 群成员形状判定(uid + uin 必备;展示 / 角色字段缺失即合法,存在则须类型正确)。 */
|
|
2066
|
+
function isGroupMember$1(val) {
|
|
2067
|
+
return isRecord(val) && hasStringProp(val, "uid") && hasStringProp(val, "uin") && isOptionalString$2(val, "nick") && isOptionalString$2(val, "cardName") && isOptionalString$2(val, "remark") && isOptionalString$2(val, "joinTime") && isOptionalString$2(val, "lastSpeakTime") && isOptionalNumber$2(val, "role") && isOptionalNumber$2(val, "shutUpTime") && isOptionalNumber$2(val, "sex") && isOptionalNumber$2(val, "age");
|
|
2068
|
+
}
|
|
2069
|
+
/** infos Map → 成员数组(逐项形状校验,非成员项丢弃)。 */
|
|
2070
|
+
function memberListOf(infos) {
|
|
2071
|
+
const out = [];
|
|
2072
|
+
for (const value of infos.values()) if (isGroupMember$1(value)) out.push(value);
|
|
2073
|
+
return out;
|
|
2074
|
+
}
|
|
2075
|
+
/** 群详情形状判定(标识 / 名称 / 成员数四要素齐备;群号标识字段可选校验)。 */
|
|
2076
|
+
function isGroupDetailInfo(val) {
|
|
2077
|
+
return isRecord(val) && hasStringProp(val, "groupCode") && hasStringProp(val, "groupName") && hasNumberProp(val, "memberNum") && hasNumberProp(val, "maxMemberNum") && isOptionalString$2(val, "groupUin") && isOptionalString$2(val, "ownerUin");
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* 从 getAllMemberList 返回结构取出 infos Map。
|
|
2081
|
+
* 兼容 `{ infos }` 与 `{ result: { infos } }` 两种形状(探测期二者都出现过);
|
|
2082
|
+
* 错误码非 0 抛 UNKNOWN,缺 infos 抛 INVALID_PARAM。
|
|
2083
|
+
*/
|
|
2084
|
+
function extractMemberInfos(raw) {
|
|
2085
|
+
if (!isRecord(raw)) throw kernelError("getAllMemberList 返回格式无效(非对象)", "INVALID_PARAM");
|
|
2086
|
+
const code = toResultNumber(raw["errCode"]);
|
|
2087
|
+
if (code !== 0) throw kernelError(`getAllMemberList 失败 (code=${code}): ${toOptionalString(raw["errMsg"]) ?? "未知错误"}`, "UNKNOWN");
|
|
2088
|
+
const infos = raw["infos"];
|
|
2089
|
+
if (infos instanceof Map) return infos;
|
|
2090
|
+
const nested = raw["result"];
|
|
2091
|
+
if (isRecord(nested)) {
|
|
2092
|
+
const nestedInfos = nested["infos"];
|
|
2093
|
+
if (nestedInfos instanceof Map) return nestedInfos;
|
|
2094
|
+
}
|
|
2095
|
+
throw kernelError("getAllMemberList 返回结果缺失 infos Map", "INVALID_PARAM");
|
|
2096
|
+
}
|
|
1907
2097
|
/** 公告列表宽松提取(result 数组 / { bulletins } / { result: 数组 } 兼容,形状待校准)。 */
|
|
1908
2098
|
function extractBulletins(result) {
|
|
1909
2099
|
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");
|
|
2100
|
+
if (isRecord(result)) for (const key of [
|
|
2101
|
+
"bulletins",
|
|
2102
|
+
"announcementList",
|
|
2103
|
+
"result",
|
|
2104
|
+
"list"
|
|
2105
|
+
]) candidates.push(result[key]);
|
|
2106
|
+
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter(isRecord);
|
|
1920
2107
|
return [];
|
|
1921
2108
|
}
|
|
1922
2109
|
/**
|
|
1923
2110
|
* 从 getGroupDetailInfo 返回提取群详情(兼容三种形状):
|
|
1924
|
-
* - result
|
|
2111
|
+
* - result 为详情对象 → 直接返回
|
|
1925
2112
|
* - result 为 0/空 → 从 raw.groupInfo / detailInfo / info 提取
|
|
1926
|
-
*
|
|
2113
|
+
* 提取不到(含数组 / 空对象 / 缺字段)返回 null,由调用方抛 KernelError。导出供单测。
|
|
1927
2114
|
*/
|
|
1928
2115
|
function extractGroupDetail(result, raw) {
|
|
1929
|
-
if (result
|
|
1930
|
-
|
|
1931
|
-
const candidate =
|
|
1932
|
-
|
|
1933
|
-
return null;
|
|
2116
|
+
if (isGroupDetailInfo(result)) return result;
|
|
2117
|
+
if (!isRecord(raw)) return null;
|
|
2118
|
+
const candidate = raw["groupInfo"] ?? raw["detailInfo"] ?? raw["info"];
|
|
2119
|
+
return isGroupDetailInfo(candidate) ? candidate : null;
|
|
1934
2120
|
}
|
|
1935
2121
|
// 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
2122
|
/** 群通知 API:从 session 拿 group service,包装成语义化方法。 */
|
|
1944
2123
|
var GroupNotifyApi = class {
|
|
1945
2124
|
service;
|
|
1946
2125
|
constructor(session) {
|
|
1947
|
-
|
|
1948
|
-
if (service === null || service === void 0) throw kernelError("getGroupService() 返回空(session 未 init)", "INVALID_STATE");
|
|
1949
|
-
this.service = service;
|
|
2126
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", ["getSingleScreenNotifies", "operateSysNotify"]);
|
|
1950
2127
|
}
|
|
1951
2128
|
/** 单屏通知列表(get_group_system_msg / set_group_add_request 共用)。 */
|
|
1952
2129
|
async getSingleScreenNotifies(doubt, count) {
|
|
1953
|
-
|
|
2130
|
+
const raw = await this.service.getSingleScreenNotifies(doubt, "", count);
|
|
2131
|
+
return extractNotifyList(isRecord(raw) ? raw["result"] : void 0);
|
|
1954
2132
|
}
|
|
1955
2133
|
/** 禁言成员列表(get_group_shut_list)。 */
|
|
1956
2134
|
async getGroupShutUpMemberList(groupCode) {
|
|
1957
2135
|
const raw = await this.service.getGroupShutUpMemberList(groupCode);
|
|
1958
|
-
if (raw
|
|
1959
|
-
|
|
2136
|
+
if (!isRecord(raw)) return [];
|
|
2137
|
+
unwrap("getGroupShutUpMemberList", typeof raw["result"] === "number" ? raw["result"] : 0, typeof raw["errMsg"] === "string" ? raw["errMsg"] : void 0);
|
|
2138
|
+
return extractMemberList(raw["result"]);
|
|
1960
2139
|
}
|
|
1961
2140
|
/** 处理群请求(set_group_add_request 应答;approve=true 同意 / false 拒绝)。 */
|
|
1962
2141
|
async handleGroupRequest(doubt, notify, operateType, reason) {
|
|
@@ -1976,23 +2155,45 @@ var GroupNotifyApi = class {
|
|
|
1976
2155
|
});
|
|
1977
2156
|
}
|
|
1978
2157
|
};
|
|
1979
|
-
/**
|
|
2158
|
+
/** 群通知项形状判定(seq 字符串 + type 数字是 GroupNotify 的必备标识)。 */
|
|
2159
|
+
function isGroupNotify(val) {
|
|
2160
|
+
return isRecord(val) && hasStringProp(val, "seq") && hasNumberProp(val, "type");
|
|
2161
|
+
}
|
|
2162
|
+
/** 可选字段:缺失(undefined/null)放行,存在时必须是 string。 */
|
|
2163
|
+
function isOptionalString$1(rec, key) {
|
|
2164
|
+
const v = rec[key];
|
|
2165
|
+
return v === void 0 || v === null || typeof v === "string";
|
|
2166
|
+
}
|
|
2167
|
+
/** 可选字段:缺失放行,存在时必须是有限 number。 */
|
|
2168
|
+
function isOptionalNumber$1(rec, key) {
|
|
2169
|
+
const v = rec[key];
|
|
2170
|
+
return v === void 0 || v === null || typeof v === "number" && Number.isFinite(v);
|
|
2171
|
+
}
|
|
2172
|
+
/** 群成员项形状判定(uid + uin 必备;展示 / 角色字段缺失即合法,存在则须类型正确)。 */
|
|
2173
|
+
function isGroupMember(val) {
|
|
2174
|
+
return isRecord(val) && hasStringProp(val, "uid") && hasStringProp(val, "uin") && isOptionalString$1(val, "nick") && isOptionalString$1(val, "cardName") && isOptionalString$1(val, "remark") && isOptionalString$1(val, "joinTime") && isOptionalString$1(val, "lastSpeakTime") && isOptionalNumber$1(val, "role") && isOptionalNumber$1(val, "shutUpTime");
|
|
2175
|
+
}
|
|
2176
|
+
/** 数组逐项守卫过滤(非数组 = 空数组)。 */
|
|
2177
|
+
function filterList(value, guard) {
|
|
2178
|
+
return Array.isArray(value) ? value.filter(guard) : [];
|
|
2179
|
+
}
|
|
2180
|
+
/** 从 getSingleScreenNotifies 返回提取通知数组(兼容 result 数组 / notifies / groupNotifies)。 */
|
|
1980
2181
|
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 [];
|
|
2182
|
+
if (Array.isArray(result)) return result.filter(isGroupNotify);
|
|
2183
|
+
if (!isRecord(result)) return [];
|
|
2184
|
+
return [...filterList(result["notifies"], isGroupNotify), ...filterList(result["groupNotifies"], isGroupNotify)];
|
|
1988
2185
|
}
|
|
1989
|
-
/** 从 getGroupShutUpMemberList 返回提取成员数组(兼容 result 数组 / memberList
|
|
2186
|
+
/** 从 getGroupShutUpMemberList 返回提取成员数组(兼容 result 数组 / memberList / list / infos Map)。 */
|
|
1990
2187
|
function extractMemberList(result) {
|
|
1991
|
-
if (Array.isArray(result)) return result;
|
|
1992
|
-
if (result
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2188
|
+
if (Array.isArray(result)) return result.filter(isGroupMember);
|
|
2189
|
+
if (!isRecord(result)) return [];
|
|
2190
|
+
const fromFields = [...filterList(result["memberList"], isGroupMember), ...filterList(result["list"], isGroupMember)];
|
|
2191
|
+
if (fromFields.length > 0) return fromFields;
|
|
2192
|
+
const infos = result["infos"];
|
|
2193
|
+
if (infos instanceof Map) {
|
|
2194
|
+
const out = [];
|
|
2195
|
+
for (const item of infos.values()) if (isGroupMember(item)) out.push(item);
|
|
2196
|
+
return out;
|
|
1996
2197
|
}
|
|
1997
2198
|
return [];
|
|
1998
2199
|
}
|
|
@@ -2093,9 +2294,8 @@ function pttDownloadResult(latest, isLastPoll) {
|
|
|
2093
2294
|
function extractFavEmojiUrls(list) {
|
|
2094
2295
|
const out = [];
|
|
2095
2296
|
for (const item of list) {
|
|
2096
|
-
if (item
|
|
2097
|
-
const
|
|
2098
|
-
const url = rec["url"] ?? rec["imageUrl"] ?? rec["emojiUrl"];
|
|
2297
|
+
if (!isRecord(item)) continue;
|
|
2298
|
+
const url = item["url"] ?? item["imageUrl"] ?? item["emojiUrl"];
|
|
2099
2299
|
if (typeof url === "string" && url !== "") out.push(url);
|
|
2100
2300
|
}
|
|
2101
2301
|
return out;
|
|
@@ -2143,11 +2343,13 @@ var MsgApi = class {
|
|
|
2143
2343
|
/** 上次生成 msgId 的时间(单调递增,2026-08-07 防同毫秒并发碰撞)。 */
|
|
2144
2344
|
lastMsgTime = 0;
|
|
2145
2345
|
constructor(session, channel, util) {
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2346
|
+
this.service = requireKernelService(session.getMsgService(), "getMsgService", [
|
|
2347
|
+
"sendMsg",
|
|
2348
|
+
"recallMsg",
|
|
2349
|
+
"getMsgs"
|
|
2350
|
+
]);
|
|
2149
2351
|
this.channel = channel ?? null;
|
|
2150
|
-
this.util = util
|
|
2352
|
+
this.util = util ?? null;
|
|
2151
2353
|
}
|
|
2152
2354
|
/**
|
|
2153
2355
|
* 生成 msgId 时间戳(单调递增)。
|
|
@@ -2376,10 +2578,11 @@ var MsgApi = class {
|
|
|
2376
2578
|
downloadType,
|
|
2377
2579
|
file_uuid: ""
|
|
2378
2580
|
});
|
|
2379
|
-
if (util !== null) {
|
|
2380
|
-
const instance =
|
|
2381
|
-
|
|
2382
|
-
|
|
2581
|
+
if (util !== null && util !== void 0) {
|
|
2582
|
+
const instance = hasCallableProp(util, "get") ? util.get() : util;
|
|
2583
|
+
if (hasCallableProp(instance, "copyFile")) try {
|
|
2584
|
+
await instance.copyFile(path, relPath);
|
|
2585
|
+
} catch {}
|
|
2383
2586
|
}
|
|
2384
2587
|
return relPath;
|
|
2385
2588
|
}
|
|
@@ -2524,7 +2727,8 @@ var MsgApi = class {
|
|
|
2524
2727
|
throw kernelError(`queryFavEmojiByDesc 调用失败: ${errorMessage(e)}`, "UNKNOWN");
|
|
2525
2728
|
}
|
|
2526
2729
|
checkLooseResult("queryFavEmojiByDesc", raw);
|
|
2527
|
-
|
|
2730
|
+
if (!isRecord(raw)) return [];
|
|
2731
|
+
const list = raw["emojiInfoList"];
|
|
2528
2732
|
if (!Array.isArray(list)) return [];
|
|
2529
2733
|
return extractFavEmojiUrls(list);
|
|
2530
2734
|
}
|
|
@@ -2639,9 +2843,7 @@ function mapSex(raw) {
|
|
|
2639
2843
|
var ProfileApi = class {
|
|
2640
2844
|
service;
|
|
2641
2845
|
constructor(session) {
|
|
2642
|
-
|
|
2643
|
-
if (service === null || service === void 0) throw kernelError("getProfileService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2644
|
-
this.service = service;
|
|
2846
|
+
this.service = requireKernelService(session.getProfileService(), "getProfileService", ["getUserDetailInfo", "getUserDetailInfoByUin"]);
|
|
2645
2847
|
}
|
|
2646
2848
|
/** 设置个性签名(set_self_longnick)。 */
|
|
2647
2849
|
async setLongNick(longNick) {
|
|
@@ -2688,9 +2890,7 @@ var ProfileApi = class {
|
|
|
2688
2890
|
var ProfileLikeApi = class {
|
|
2689
2891
|
service;
|
|
2690
2892
|
constructor(session) {
|
|
2691
|
-
|
|
2692
|
-
if (service === null || service === void 0) throw kernelError("getProfileLikeService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2693
|
-
this.service = service;
|
|
2893
|
+
this.service = requireKernelService(session.getProfileLikeService(), "getProfileLikeService", ["setBuddyProfileLike"]);
|
|
2694
2894
|
}
|
|
2695
2895
|
/** 点赞(send_like;uid 为目标 uid,count 次数)。 */
|
|
2696
2896
|
async sendLike(uid, count = 1) {
|
|
@@ -2717,9 +2917,7 @@ const RECENT_CONTACT_FETCH_COUNT = 200;
|
|
|
2717
2917
|
var RecentContactApi = class {
|
|
2718
2918
|
service;
|
|
2719
2919
|
constructor(session) {
|
|
2720
|
-
|
|
2721
|
-
if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2722
|
-
this.service = service;
|
|
2920
|
+
this.service = requireKernelService(session.getRecentContactService(), "getRecentContactService", ["getRecentContactList"]);
|
|
2723
2921
|
}
|
|
2724
2922
|
/** 置顶会话列表(get_peer_pins;getRecentContactList 返回形状待探测校准)。 */
|
|
2725
2923
|
async getPinnedContacts() {
|
|
@@ -2736,16 +2934,16 @@ var RecentContactApi = class {
|
|
|
2736
2934
|
};
|
|
2737
2935
|
/** 从返回形状提取置顶会话(result 数组 / 顶层 contacts / 嵌套容器兼容,待校准)。 */
|
|
2738
2936
|
function extractPinnedContacts(raw) {
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2937
|
+
const resultField = getOwnProp(raw, "result");
|
|
2938
|
+
const candidates = [resultField, raw];
|
|
2939
|
+
for (const container of [resultField, raw]) {
|
|
2940
|
+
if (!isRecord(container)) continue;
|
|
2743
2941
|
for (const key of [
|
|
2744
2942
|
"contacts",
|
|
2745
2943
|
"data",
|
|
2746
2944
|
"result",
|
|
2747
2945
|
"list"
|
|
2748
|
-
]) candidates.push(
|
|
2946
|
+
]) candidates.push(container[key]);
|
|
2749
2947
|
}
|
|
2750
2948
|
for (const candidate of candidates) {
|
|
2751
2949
|
if (!Array.isArray(candidate)) continue;
|
|
@@ -2753,10 +2951,13 @@ function extractPinnedContacts(raw) {
|
|
|
2753
2951
|
}
|
|
2754
2952
|
return [];
|
|
2755
2953
|
}
|
|
2954
|
+
/** 会话项形状判定(peerUid + chatType 是 RecentContact 的必备标识)。 */
|
|
2955
|
+
function isRecentContact(val) {
|
|
2956
|
+
return isRecord(val) && typeof val["peerUid"] === "string" && typeof val["chatType"] === "number";
|
|
2957
|
+
}
|
|
2756
2958
|
/** 单条会话 → 置顶项(置顶标记为真且场景可判定才产出)。 */
|
|
2757
2959
|
function pinnedOf(item) {
|
|
2758
|
-
|
|
2759
|
-
return pinnedContactOf(item);
|
|
2960
|
+
return isRecentContact(item) ? pinnedContactOf(item) : [];
|
|
2760
2961
|
}
|
|
2761
2962
|
/** 置顶判据(topFlag 实测字段名 + isTop 兼容形态)且 peerUid 可用才产出。 */
|
|
2762
2963
|
function pinnedContactOf(contact) {
|
|
@@ -2803,9 +3004,7 @@ const SPACE_QUERY_FILE_COUNT = 1;
|
|
|
2803
3004
|
var RichMediaApi = class {
|
|
2804
3005
|
service;
|
|
2805
3006
|
constructor(session) {
|
|
2806
|
-
|
|
2807
|
-
if (service === null || service === void 0) throw kernelError("getRichMediaService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2808
|
-
this.service = service;
|
|
3007
|
+
this.service = requireKernelService(session.getRichMediaService(), "getRichMediaService", ["getGroupFileList"]);
|
|
2809
3008
|
}
|
|
2810
3009
|
/** 英文单词翻译(translate_en2zh)。 */
|
|
2811
3010
|
async translateWords(words) {
|
|
@@ -2852,10 +3051,10 @@ var RichMediaApi = class {
|
|
|
2852
3051
|
/** 创建群文件夹(create_group_file_folder)。 */
|
|
2853
3052
|
async createGroupFolder(groupCode, folderName) {
|
|
2854
3053
|
const raw = await this.service.createGroupFolder(groupCode, folderName);
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
return "";
|
|
3054
|
+
checkLooseResult("createGroupFolder", raw);
|
|
3055
|
+
if (!isRecord(raw)) return "";
|
|
3056
|
+
const result = raw["result"];
|
|
3057
|
+
return typeof result === "string" ? result : "";
|
|
2859
3058
|
}
|
|
2860
3059
|
/** 删除群文件(delete_group_file)。 */
|
|
2861
3060
|
async deleteGroupFile(groupCode, fileIds) {
|
|
@@ -2902,25 +3101,31 @@ var RichMediaApi = class {
|
|
|
2902
3101
|
if (raw.result !== 0) unwrap("transGroupFile", raw.result, raw.errMsg);
|
|
2903
3102
|
}
|
|
2904
3103
|
};
|
|
2905
|
-
/**
|
|
3104
|
+
/** 群文件列表项形状判定(fileInfo / folderInfo 出现时必须带齐标识字段)。 */
|
|
3105
|
+
function isGroupFileListItem(val) {
|
|
3106
|
+
if (!isRecord(val)) return false;
|
|
3107
|
+
const fileInfo = val["fileInfo"];
|
|
3108
|
+
const hasValidFile = fileInfo === void 0 || isRecord(fileInfo) && hasStringProp(fileInfo, "fileId") && hasStringProp(fileInfo, "fileName");
|
|
3109
|
+
const folderInfo = val["folderInfo"];
|
|
3110
|
+
const hasValidFolder = folderInfo === void 0 || isRecord(folderInfo) && hasStringProp(folderInfo, "folderId") && hasStringProp(folderInfo, "folderName");
|
|
3111
|
+
return hasValidFile && hasValidFolder;
|
|
3112
|
+
}
|
|
3113
|
+
/** 从 getGroupFileList 返回提取文件列表(兼容数组 / { items } / { item } / { fileList } / { list })。导出供单测。 */
|
|
2906
3114
|
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
|
-
}
|
|
3115
|
+
if (Array.isArray(result)) return result.filter(isGroupFileListItem);
|
|
3116
|
+
if (!isRecord(result)) return [];
|
|
3117
|
+
const candidates = [
|
|
3118
|
+
result["item"],
|
|
3119
|
+
result["items"],
|
|
3120
|
+
result["fileList"],
|
|
3121
|
+
result["list"]
|
|
3122
|
+
];
|
|
3123
|
+
for (const candidate of candidates) if (Array.isArray(candidate)) return candidate.filter(isGroupFileListItem);
|
|
2918
3124
|
return [];
|
|
2919
3125
|
}
|
|
2920
|
-
/**
|
|
3126
|
+
/** 统计文件数量(fileInfo 条目数,数组 / { items } 兼容)。 */
|
|
2921
3127
|
function countGroupFiles(result) {
|
|
2922
|
-
|
|
2923
|
-
return 0;
|
|
3128
|
+
return extractFileList(result).filter((item) => item.fileInfo !== void 0).length;
|
|
2924
3129
|
}
|
|
2925
3130
|
// src/apis/ticket.ts
|
|
2926
3131
|
/**
|
|
@@ -2936,9 +3141,7 @@ const JUMP_TIMEOUT_MS = 1e4;
|
|
|
2936
3141
|
var TicketApi = class {
|
|
2937
3142
|
service;
|
|
2938
3143
|
constructor(session) {
|
|
2939
|
-
|
|
2940
|
-
if (service === null || service === void 0) throw kernelError("getTicketService() 返回空(session 未 init)", "INVALID_STATE");
|
|
2941
|
-
this.service = service;
|
|
3144
|
+
this.service = requireKernelService(session.getTicketService(), "getTicketService", ["forceFetchClientKey"]);
|
|
2942
3145
|
}
|
|
2943
3146
|
/** 获取 clientKey(get_clientkey)。 */
|
|
2944
3147
|
async getClientKey() {
|
|
@@ -2972,9 +3175,9 @@ function fetchJumpCookies(url) {
|
|
|
2972
3175
|
});
|
|
2973
3176
|
req.setTimeout(JUMP_TIMEOUT_MS, () => {
|
|
2974
3177
|
req.destroy();
|
|
2975
|
-
reject(
|
|
3178
|
+
reject(kernelError("获取 cookies 超时", "TIMEOUT"));
|
|
2976
3179
|
});
|
|
2977
|
-
req.on("error", (err) => reject(err));
|
|
3180
|
+
req.on("error", (err) => reject(kernelError(`获取 cookies 网络请求失败: ${err.message}`, "UNKNOWN", { cause: err })));
|
|
2978
3181
|
});
|
|
2979
3182
|
}
|
|
2980
3183
|
/** 解析 set-cookie 头数组 → { name: value } dict。 */
|
|
@@ -3032,10 +3235,9 @@ var WebApi = class {
|
|
|
3032
3235
|
group_code: groupCode
|
|
3033
3236
|
}).toString(), cookie);
|
|
3034
3237
|
if (ret === null || ret.retcode !== 0) return null;
|
|
3035
|
-
const list = ret.data?.msg_list;
|
|
3036
3238
|
return {
|
|
3037
|
-
items:
|
|
3038
|
-
isEnd: ret.
|
|
3239
|
+
items: extractEssenceItems(ret.msgList),
|
|
3240
|
+
isEnd: ret.isEnd
|
|
3039
3241
|
};
|
|
3040
3242
|
}
|
|
3041
3243
|
/** 获取群精华消息列表(get_essence_msg_list;分页拉取至 is_end)。 */
|
|
@@ -3099,31 +3301,57 @@ function parseHonorList(text, type) {
|
|
|
3099
3301
|
} catch {
|
|
3100
3302
|
return [];
|
|
3101
3303
|
}
|
|
3102
|
-
|
|
3304
|
+
if (!isRecord(state)) return [];
|
|
3305
|
+
const raw = type === WebHonorType.TALKATIVE ? state["talkativeList"] : state["actorList"];
|
|
3103
3306
|
if (!Array.isArray(raw)) return [];
|
|
3104
3307
|
const out = [];
|
|
3105
|
-
for (const item of raw)
|
|
3106
|
-
|
|
3308
|
+
for (const item of raw) {
|
|
3309
|
+
if (!isRecord(item)) continue;
|
|
3107
3310
|
out.push({
|
|
3108
|
-
uin: String(
|
|
3109
|
-
name: String(
|
|
3110
|
-
avatar: String(
|
|
3111
|
-
desc: String(
|
|
3311
|
+
uin: String(item["uin"] ?? ""),
|
|
3312
|
+
name: String(item["name"] ?? ""),
|
|
3313
|
+
avatar: String(item["avatar"] ?? ""),
|
|
3314
|
+
desc: String(item["desc"] ?? "")
|
|
3112
3315
|
});
|
|
3113
3316
|
}
|
|
3114
3317
|
return out;
|
|
3115
3318
|
}
|
|
3116
|
-
/**
|
|
3319
|
+
/** 可选字段:缺失放行,存在时类型必须正确。 */
|
|
3320
|
+
function isOptionalString(rec, key) {
|
|
3321
|
+
const v = rec[key];
|
|
3322
|
+
return v === void 0 || v === null || typeof v === "string";
|
|
3323
|
+
}
|
|
3324
|
+
/** 可选字段:缺失放行,存在时必须是有限 number。 */
|
|
3325
|
+
function isOptionalNumber(rec, key) {
|
|
3326
|
+
const v = rec[key];
|
|
3327
|
+
return v === void 0 || v === null || typeof v === "number" && Number.isFinite(v);
|
|
3328
|
+
}
|
|
3329
|
+
/** 精华消息项形状判定(msg_content 数组必备;其余字段存在时逐一校验类型)。 */
|
|
3330
|
+
function isEssenceMsgItem(val) {
|
|
3331
|
+
return isRecord(val) && Array.isArray(val["msg_content"]) && isOptionalString(val, "sender_uin") && isOptionalString(val, "sender_nick") && isOptionalString(val, "add_digest_uin") && isOptionalString(val, "add_digest_nick") && isOptionalNumber(val, "msg_seq") && isOptionalNumber(val, "msg_random") && isOptionalNumber(val, "add_digest_time");
|
|
3332
|
+
}
|
|
3333
|
+
/** msg_list → 精华消息数组(逐项守卫,非数组 / 残缺项丢弃)。 */
|
|
3334
|
+
function extractEssenceItems(list) {
|
|
3335
|
+
return Array.isArray(list) ? list.filter(isEssenceMsgItem) : [];
|
|
3336
|
+
}
|
|
3337
|
+
/**
|
|
3338
|
+
* 请求 qun.qq.com JSON 接口(带 Cookie;失败返回 null)。
|
|
3339
|
+
* 响应体先过 `isRecord` 收窄再取字段——非对象 JSON(数组 / 标量)按 INVALID_PARAM 抛出。
|
|
3340
|
+
*/
|
|
3117
3341
|
async function fetchQunJson(url, cookie) {
|
|
3118
3342
|
try {
|
|
3119
3343
|
const res = await fetch(url, { headers: { Cookie: cookieToString(cookie) } });
|
|
3120
3344
|
if (!res.ok) return null;
|
|
3121
3345
|
const json = await res.json();
|
|
3346
|
+
if (!isRecord(json)) throw kernelError("群 WebApi 响应非 JSON 对象", "INVALID_PARAM");
|
|
3347
|
+
const data = json["data"];
|
|
3122
3348
|
return {
|
|
3123
|
-
retcode: json
|
|
3124
|
-
data:
|
|
3349
|
+
retcode: typeof json["retcode"] === "number" ? json["retcode"] : -1,
|
|
3350
|
+
msgList: isRecord(data) ? data["msg_list"] : void 0,
|
|
3351
|
+
isEnd: isRecord(data) && data["is_end"] === true
|
|
3125
3352
|
};
|
|
3126
3353
|
} catch (err) {
|
|
3354
|
+
if (isKernelError(err)) throw err;
|
|
3127
3355
|
throw kernelError(`qun.qq.com 请求失败: ${errorMessage(err)}`, "UNKNOWN");
|
|
3128
3356
|
}
|
|
3129
3357
|
}
|
|
@@ -3176,9 +3404,7 @@ var FriendBridge = class {
|
|
|
3176
3404
|
channel;
|
|
3177
3405
|
listenerId = null;
|
|
3178
3406
|
constructor(session, channel) {
|
|
3179
|
-
|
|
3180
|
-
if (service === null || service === void 0) throw kernelError("getBuddyService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3181
|
-
this.service = service;
|
|
3407
|
+
this.service = requireKernelService(session.getBuddyService(), "getBuddyService", ["addKernelBuddyListener"]);
|
|
3182
3408
|
this.channel = channel;
|
|
3183
3409
|
}
|
|
3184
3410
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3217,9 +3443,7 @@ var GroupBridge = class {
|
|
|
3217
3443
|
channel;
|
|
3218
3444
|
listenerId = null;
|
|
3219
3445
|
constructor(session, channel) {
|
|
3220
|
-
|
|
3221
|
-
if (service === null || service === void 0) throw kernelError("getGroupService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3222
|
-
this.service = service;
|
|
3446
|
+
this.service = requireKernelService(session.getGroupService(), "getGroupService", ["addKernelGroupListener"]);
|
|
3223
3447
|
this.channel = channel;
|
|
3224
3448
|
}
|
|
3225
3449
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3254,17 +3478,21 @@ var GroupBridge = class {
|
|
|
3254
3478
|
}
|
|
3255
3479
|
};
|
|
3256
3480
|
// src/bridge/login-bridge.ts
|
|
3481
|
+
/** 运行时判定 loginService 是否具备监听注册方法面。 */
|
|
3482
|
+
function isBoundLoginService(val) {
|
|
3483
|
+
return hasCallableProp(val, "addKernelLoginListener");
|
|
3484
|
+
}
|
|
3257
3485
|
/**
|
|
3258
3486
|
* 登录事件桥:注册原生监听 → 回调 emit 到 channel。
|
|
3259
3487
|
* 无全局单例(ADR-015 推论)——每进程一份。
|
|
3260
3488
|
*/
|
|
3261
3489
|
var LoginBridge = class {
|
|
3262
|
-
|
|
3490
|
+
boundService;
|
|
3263
3491
|
channel;
|
|
3264
3492
|
listenerId = null;
|
|
3265
3493
|
constructor(loginService, channel) {
|
|
3266
|
-
if (loginService
|
|
3267
|
-
this.
|
|
3494
|
+
if (!isBoundLoginService(loginService)) throw kernelError("loginService 无效(缺 addKernelLoginListener)", "INVALID_STATE");
|
|
3495
|
+
this.boundService = loginService;
|
|
3268
3496
|
this.channel = channel;
|
|
3269
3497
|
}
|
|
3270
3498
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3274,12 +3502,12 @@ var LoginBridge = class {
|
|
|
3274
3502
|
onLoginDisConnected: (...args) => this.channel.emit("Login/onLoginDisConnected", ...args),
|
|
3275
3503
|
onLogoutSucceed: (...args) => this.channel.emit("Login/onLogoutSucceed", ...args)
|
|
3276
3504
|
};
|
|
3277
|
-
this.listenerId = this.
|
|
3505
|
+
this.listenerId = this.boundService.addKernelLoginListener(listener);
|
|
3278
3506
|
}
|
|
3279
3507
|
/** 注销原生监听(幂等)。 */
|
|
3280
3508
|
unregister() {
|
|
3281
3509
|
if (this.listenerId === null) return;
|
|
3282
|
-
this.
|
|
3510
|
+
this.boundService.removeKernelLoginListener?.(this.listenerId);
|
|
3283
3511
|
this.listenerId = null;
|
|
3284
3512
|
}
|
|
3285
3513
|
/** 释放(等价 unregister,幂等)。 */
|
|
@@ -3356,9 +3584,7 @@ var MsgBridge = class {
|
|
|
3356
3584
|
channel;
|
|
3357
3585
|
listenerId = null;
|
|
3358
3586
|
constructor(session, channel) {
|
|
3359
|
-
|
|
3360
|
-
if (service === null || service === void 0) throw kernelError("getMsgService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3361
|
-
this.service = service;
|
|
3587
|
+
this.service = requireKernelService(session.getMsgService(), "getMsgService", ["addKernelMsgListener"]);
|
|
3362
3588
|
this.channel = channel;
|
|
3363
3589
|
}
|
|
3364
3590
|
/**
|
|
@@ -3413,9 +3639,7 @@ var RecentContactBridge = class {
|
|
|
3413
3639
|
channel;
|
|
3414
3640
|
listenerId = null;
|
|
3415
3641
|
constructor(session, channel) {
|
|
3416
|
-
|
|
3417
|
-
if (service === null || service === void 0) throw kernelError("getRecentContactService() 返回空(session 未 init)", "INVALID_STATE");
|
|
3418
|
-
this.service = service;
|
|
3642
|
+
this.service = requireKernelService(session.getRecentContactService(), "getRecentContactService", ["addKernelRecentContactListener"]);
|
|
3419
3643
|
this.channel = channel;
|
|
3420
3644
|
}
|
|
3421
3645
|
/** 注册原生监听(幂等)。 */
|
|
@@ -3480,9 +3704,10 @@ var NTEventChannel = class {
|
|
|
3480
3704
|
* 每个 Service 只注册一次原生监听,缓存维护与协议翻译都订阅这里。
|
|
3481
3705
|
*/
|
|
3482
3706
|
on(event, handler) {
|
|
3483
|
-
|
|
3707
|
+
const erased = (...args) => Reflect.apply(handler, void 0, args);
|
|
3708
|
+
this.emitter.addListener(String(event), erased);
|
|
3484
3709
|
return () => {
|
|
3485
|
-
this.emitter.removeListener(event,
|
|
3710
|
+
this.emitter.removeListener(String(event), erased);
|
|
3486
3711
|
};
|
|
3487
3712
|
}
|
|
3488
3713
|
/**
|
|
@@ -3497,16 +3722,19 @@ var NTEventChannel = class {
|
|
|
3497
3722
|
cleanup();
|
|
3498
3723
|
resolve(args);
|
|
3499
3724
|
};
|
|
3725
|
+
const erased = (...args) => {
|
|
3726
|
+
Reflect.apply(handler, void 0, args);
|
|
3727
|
+
};
|
|
3500
3728
|
const timer = setTimeout(() => {
|
|
3501
3729
|
cleanup();
|
|
3502
|
-
reject(kernelError(`等待事件超时: ${event}`, "TIMEOUT"));
|
|
3730
|
+
reject(kernelError(`等待事件超时: ${String(event)}`, "TIMEOUT"));
|
|
3503
3731
|
}, timeoutMs);
|
|
3504
3732
|
timer.unref?.();
|
|
3505
3733
|
const cleanup = () => {
|
|
3506
3734
|
clearTimeout(timer);
|
|
3507
|
-
this.emitter.removeListener(event,
|
|
3735
|
+
this.emitter.removeListener(String(event), erased);
|
|
3508
3736
|
};
|
|
3509
|
-
this.emitter.addListener(event,
|
|
3737
|
+
this.emitter.addListener(String(event), erased);
|
|
3510
3738
|
});
|
|
3511
3739
|
}
|
|
3512
3740
|
/**
|
|
@@ -3527,14 +3755,14 @@ var NTEventChannel = class {
|
|
|
3527
3755
|
}
|
|
3528
3756
|
emit(event, ...args) {
|
|
3529
3757
|
for (const anyHandler of this.anyHandlers) try {
|
|
3530
|
-
const ret = anyHandler(event, ...args);
|
|
3758
|
+
const ret = anyHandler(String(event), ...args);
|
|
3531
3759
|
this.catchAsyncListenerError(ret);
|
|
3532
3760
|
} catch (err) {
|
|
3533
3761
|
this.notifyError(err);
|
|
3534
3762
|
}
|
|
3535
|
-
const listeners = this.emitter.listeners(event);
|
|
3763
|
+
const listeners = this.emitter.listeners(String(event));
|
|
3536
3764
|
for (const listener of listeners) try {
|
|
3537
|
-
const ret = listener
|
|
3765
|
+
const ret = Reflect.apply(listener, void 0, args);
|
|
3538
3766
|
this.catchAsyncListenerError(ret);
|
|
3539
3767
|
} catch (err) {
|
|
3540
3768
|
this.notifyError(err);
|
|
@@ -3545,7 +3773,7 @@ var NTEventChannel = class {
|
|
|
3545
3773
|
* UnhandledRejection)——这里统一挂 catch 转发到 onError 兜底。
|
|
3546
3774
|
*/
|
|
3547
3775
|
catchAsyncListenerError(ret) {
|
|
3548
|
-
if (ret
|
|
3776
|
+
if (isPromiseLike(ret)) ret.catch((err) => {
|
|
3549
3777
|
this.notifyError(err);
|
|
3550
3778
|
});
|
|
3551
3779
|
}
|
|
@@ -3574,14 +3802,97 @@ var NTEventChannel = class {
|
|
|
3574
3802
|
}
|
|
3575
3803
|
};
|
|
3576
3804
|
// src/cache/buddy-cache.ts
|
|
3805
|
+
/** 可选展示字段:存在且类型正确才拷贝(未知值丢弃)。 */
|
|
3806
|
+
const MEMBER_STRING_KEYS = [
|
|
3807
|
+
"nick",
|
|
3808
|
+
"remark",
|
|
3809
|
+
"longNick",
|
|
3810
|
+
"avatarUrl",
|
|
3811
|
+
"topTime"
|
|
3812
|
+
];
|
|
3813
|
+
const MEMBER_NUMBER_KEYS = [
|
|
3814
|
+
"categoryId",
|
|
3815
|
+
"birthday_year",
|
|
3816
|
+
"birthday_month",
|
|
3817
|
+
"birthday_day",
|
|
3818
|
+
"sex"
|
|
3819
|
+
];
|
|
3820
|
+
/** 拷贝成员可选字段(类型正确才写入)。 */
|
|
3821
|
+
function copyMemberExtras(entry, raw) {
|
|
3822
|
+
for (const key of MEMBER_STRING_KEYS) {
|
|
3823
|
+
const value = raw[key];
|
|
3824
|
+
if (typeof value === "string") entry[key] = value;
|
|
3825
|
+
}
|
|
3826
|
+
for (const key of MEMBER_NUMBER_KEYS) {
|
|
3827
|
+
const value = raw[key];
|
|
3828
|
+
if (typeof value === "number") entry[key] = value;
|
|
3829
|
+
}
|
|
3830
|
+
const isBlocked = raw["isBlocked"];
|
|
3831
|
+
if (typeof isBlocked === "boolean") entry["isBlocked"] = isBlocked;
|
|
3832
|
+
}
|
|
3833
|
+
/** coreInfo 安全构造(uid/uin 必备)。 */
|
|
3834
|
+
function parseCoreInfo(raw) {
|
|
3835
|
+
if (!isRecord(raw) || typeof raw["uid"] !== "string" || typeof raw["uin"] !== "string") return null;
|
|
3836
|
+
const out = {
|
|
3837
|
+
uid: raw["uid"],
|
|
3838
|
+
uin: raw["uin"]
|
|
3839
|
+
};
|
|
3840
|
+
const nick = raw["nick"];
|
|
3841
|
+
const remark = raw["remark"];
|
|
3842
|
+
return {
|
|
3843
|
+
...out,
|
|
3844
|
+
...typeof nick === "string" ? { nick } : {},
|
|
3845
|
+
...typeof remark === "string" ? { remark } : {}
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
/**
|
|
3849
|
+
* 解析单个好友明细(T10 实测形状:uid/uin 齐备;其余展示字段按类型安全拷贝)。
|
|
3850
|
+
* 返回真实构造的新对象——不把原生载荷直接断言成 `BuddyListEntry`。
|
|
3851
|
+
*/
|
|
3852
|
+
function parseBuddyMember(raw) {
|
|
3853
|
+
if (!isRecord(raw) || typeof raw["uid"] !== "string" || typeof raw["uin"] !== "string") return null;
|
|
3854
|
+
const entry = {
|
|
3855
|
+
uid: raw["uid"],
|
|
3856
|
+
uin: raw["uin"]
|
|
3857
|
+
};
|
|
3858
|
+
copyMemberExtras(entry, raw);
|
|
3859
|
+
const coreInfo = parseCoreInfo(raw["coreInfo"]);
|
|
3860
|
+
if (coreInfo !== null) entry.coreInfo = coreInfo;
|
|
3861
|
+
if (isRecord(raw["baseInfo"])) entry.baseInfo = raw["baseInfo"];
|
|
3862
|
+
return entry;
|
|
3863
|
+
}
|
|
3864
|
+
/** 单个分类项 → BuddyCategory(非对象返回 null)。 */
|
|
3865
|
+
function parseBuddyCategory(item) {
|
|
3866
|
+
if (!isRecord(item)) return null;
|
|
3867
|
+
const buddyListRaw = Array.isArray(item["buddyList"]) ? item["buddyList"] : [];
|
|
3868
|
+
const buddyList = [];
|
|
3869
|
+
for (const b of buddyListRaw) {
|
|
3870
|
+
const parsed = parseBuddyMember(b);
|
|
3871
|
+
if (parsed !== null) buddyList.push(parsed);
|
|
3872
|
+
}
|
|
3873
|
+
return {
|
|
3874
|
+
categoryId: typeof item["categoryId"] === "number" ? item["categoryId"] : 0,
|
|
3875
|
+
categorySortId: typeof item["categorySortId"] === "number" ? item["categorySortId"] : 0,
|
|
3876
|
+
categroyName: typeof item["categroyName"] === "string" ? item["categroyName"] : "",
|
|
3877
|
+
categroyMbCount: typeof item["categroyMbCount"] === "number" ? item["categroyMbCount"] : buddyList.length,
|
|
3878
|
+
onlineCount: typeof item["onlineCount"] === "number" ? item["onlineCount"] : 0,
|
|
3879
|
+
buddyList
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3577
3882
|
/**
|
|
3578
3883
|
* 防御性收窄 onBuddyListChange 载荷 → BuddyCategory[](T10 实证形状;
|
|
3579
|
-
*
|
|
3884
|
+
* 非数组 / 非对象分类项返回 null,调用方打 raw 日志积累校准数据)。
|
|
3885
|
+
* 分类字段逐项做运行时类型校验并安全构造,缺失项取保守默认值。
|
|
3580
3886
|
*/
|
|
3581
3887
|
function narrowBuddyCategories(arg) {
|
|
3582
3888
|
if (!Array.isArray(arg)) return null;
|
|
3583
|
-
|
|
3584
|
-
|
|
3889
|
+
const categories = [];
|
|
3890
|
+
for (const item of arg) {
|
|
3891
|
+
const category = parseBuddyCategory(item);
|
|
3892
|
+
if (category === null) return null;
|
|
3893
|
+
categories.push(category);
|
|
3894
|
+
}
|
|
3895
|
+
return categories;
|
|
3585
3896
|
}
|
|
3586
3897
|
/** 从快照分类拍平好友明细(buddyList 缺失的分类跳过)。 */
|
|
3587
3898
|
function flattenEntries(categories) {
|
|
@@ -3673,8 +3984,16 @@ var GroupCache = class {
|
|
|
3673
3984
|
groupDetails = /* @__PURE__ */ new Map();
|
|
3674
3985
|
/** 群成员:groupCode → (uid → GroupMember)。 */
|
|
3675
3986
|
members = /* @__PURE__ */ new Map();
|
|
3676
|
-
/**
|
|
3677
|
-
|
|
3987
|
+
/**
|
|
3988
|
+
* 惰性回填 in-flight 去重。
|
|
3989
|
+
*
|
|
3990
|
+
* 按返回类型拆成三个精确容器:同 key 并发只拉一次,且取回的值类型由容器
|
|
3991
|
+
* 声明(Promise<Group[]> / Promise<GroupDetailInfo> / Promise<GroupMember[]>)
|
|
3992
|
+
* 自然推导——不再用 `Promise<unknown>` + `as Promise<T>` 假装泛型。
|
|
3993
|
+
*/
|
|
3994
|
+
inFlightGroupList = null;
|
|
3995
|
+
inFlightDetail = /* @__PURE__ */ new Map();
|
|
3996
|
+
inFlightMembers = /* @__PURE__ */ new Map();
|
|
3678
3997
|
unsubscribes = null;
|
|
3679
3998
|
constructor(opts) {
|
|
3680
3999
|
this.channel = opts.channel;
|
|
@@ -3711,7 +4030,9 @@ var GroupCache = class {
|
|
|
3711
4030
|
this.groupList.clear();
|
|
3712
4031
|
this.groupDetails.clear();
|
|
3713
4032
|
this.members.clear();
|
|
3714
|
-
this.
|
|
4033
|
+
this.inFlightGroupList = null;
|
|
4034
|
+
this.inFlightDetail.clear();
|
|
4035
|
+
this.inFlightMembers.clear();
|
|
3715
4036
|
}
|
|
3716
4037
|
/** 释放(等价 unregister,幂等)。 */
|
|
3717
4038
|
dispose() {
|
|
@@ -3773,7 +4094,7 @@ var GroupCache = class {
|
|
|
3773
4094
|
async getGroupDetail(groupCode) {
|
|
3774
4095
|
const cached = this.groupDetails.get(groupCode);
|
|
3775
4096
|
if (cached !== void 0) return cached;
|
|
3776
|
-
const detail = await this.
|
|
4097
|
+
const detail = await this.dedupeMap(this.inFlightDetail, groupCode, () => this.groupApi.getGroupInfo(groupCode));
|
|
3777
4098
|
this.groupDetails.set(groupCode, detail);
|
|
3778
4099
|
return detail;
|
|
3779
4100
|
}
|
|
@@ -3784,7 +4105,7 @@ var GroupCache = class {
|
|
|
3784
4105
|
async getMembers(groupCode) {
|
|
3785
4106
|
const map = this.members.get(groupCode);
|
|
3786
4107
|
if (map !== void 0 && map.size > 0) return [...map.values()];
|
|
3787
|
-
const members = await this.
|
|
4108
|
+
const members = await this.dedupeMap(this.inFlightMembers, groupCode, () => this.groupApi.getGroupMemberList(groupCode, true));
|
|
3788
4109
|
const merged = /* @__PURE__ */ new Map();
|
|
3789
4110
|
for (const member of members) merged.set(member.uid, member);
|
|
3790
4111
|
this.members.set(groupCode, merged);
|
|
@@ -3797,7 +4118,7 @@ var GroupCache = class {
|
|
|
3797
4118
|
async getMember(groupCode, uid) {
|
|
3798
4119
|
const cached = await this.getCachedMember(groupCode, uid);
|
|
3799
4120
|
if (cached !== void 0) return cached;
|
|
3800
|
-
const [member] = await this.
|
|
4121
|
+
const [member] = await this.dedupeMap(this.inFlightMembers, `member:${groupCode}:${uid}`, () => this.groupApi.getGroupMemberInfo(groupCode, [uid]));
|
|
3801
4122
|
if (member === void 0) return;
|
|
3802
4123
|
const target = this.members.get(groupCode);
|
|
3803
4124
|
if (target !== void 0) target.set(member.uid, member);
|
|
@@ -3812,22 +4133,30 @@ var GroupCache = class {
|
|
|
3812
4133
|
}
|
|
3813
4134
|
return map?.get(uid);
|
|
3814
4135
|
}
|
|
3815
|
-
/** 惰性回填全量群列表(getGroup
|
|
4136
|
+
/** 惰性回填全量群列表(getGroup 缺失时;并发调用共享同一次拉取)。 */
|
|
3816
4137
|
async loadGroupList() {
|
|
3817
|
-
|
|
3818
|
-
|
|
4138
|
+
let inFlight = this.inFlightGroupList;
|
|
4139
|
+
if (inFlight === null) {
|
|
4140
|
+
inFlight = this.groupApi.getGroupList(false).finally(() => {
|
|
4141
|
+
this.inFlightGroupList = null;
|
|
4142
|
+
});
|
|
4143
|
+
this.inFlightGroupList = inFlight;
|
|
4144
|
+
}
|
|
4145
|
+
for (const group of await inFlight) this.groupList.set(group.groupCode, group);
|
|
3819
4146
|
}
|
|
3820
|
-
/**
|
|
3821
|
-
|
|
3822
|
-
|
|
4147
|
+
/**
|
|
4148
|
+
* 惰性回填并发去重(按返回类型分容器):同 map + key 并发只拉一次。
|
|
4149
|
+
* loader 的返回值类型即容器元素类型——取回时由 Promise<T> 自然给出 T,
|
|
4150
|
+
* 不需要 `as Promise<T>` 断言。
|
|
4151
|
+
*/
|
|
4152
|
+
async dedupeMap(map, key, loader) {
|
|
4153
|
+
const existing = map.get(key);
|
|
3823
4154
|
if (existing !== void 0) return await existing;
|
|
3824
|
-
const
|
|
3825
|
-
|
|
3826
|
-
}).finally(() => {
|
|
3827
|
-
this.inFlight.delete(key);
|
|
4155
|
+
const promise = loader().finally(() => {
|
|
4156
|
+
map.delete(key);
|
|
3828
4157
|
});
|
|
3829
|
-
|
|
3830
|
-
return await
|
|
4158
|
+
map.set(key, promise);
|
|
4159
|
+
return await promise;
|
|
3831
4160
|
}
|
|
3832
4161
|
};
|
|
3833
4162
|
// src/context.ts
|
|
@@ -3899,6 +4228,43 @@ function createLoginListener() {
|
|
|
3899
4228
|
* T3 单步超时兜底——底层 promise 永久挂起时按登录失败抛出)
|
|
3900
4229
|
*/
|
|
3901
4230
|
/**
|
|
4231
|
+
* 登录服务形状判定:getLoginList / quickLoginWithUin / getMsfStatus 齐备才算可用。
|
|
4232
|
+
* 判空职责从「调用点各自做两级强转」收拢到这里。
|
|
4233
|
+
*/
|
|
4234
|
+
function isLoginServiceShape(val) {
|
|
4235
|
+
return isRecord(val) && hasFunctionProp(val, "getLoginList") && hasFunctionProp(val, "quickLoginWithUin") && hasFunctionProp(val, "getMsfStatus");
|
|
4236
|
+
}
|
|
4237
|
+
/** 校验并收窄 loginService(失败抛 INVALID_STATE,ADR-009)。 */
|
|
4238
|
+
function requireLoginService(raw) {
|
|
4239
|
+
if (!isLoginServiceShape(raw)) throw kernelError("loginService 无效(缺 getLoginList / quickLoginWithUin / getMsfStatus)", "INVALID_STATE");
|
|
4240
|
+
return raw;
|
|
4241
|
+
}
|
|
4242
|
+
/** 连接方法面判定(connect / add / remove 监听存在时必须是函数)。 */
|
|
4243
|
+
function isLoginConnectionShape(val) {
|
|
4244
|
+
if (!isRecord(val)) return false;
|
|
4245
|
+
const connect = val["connect"];
|
|
4246
|
+
const addListener = val["addKernelLoginListener"];
|
|
4247
|
+
const removeListener = val["removeKernelLoginListener"];
|
|
4248
|
+
return (connect === void 0 || typeof connect === "function") && (addListener === void 0 || typeof addListener === "function") && (removeListener === void 0 || typeof removeListener === "function");
|
|
4249
|
+
}
|
|
4250
|
+
/** 登录列表项形状判定(uin 是唯一必填字段)。 */
|
|
4251
|
+
function isLoginAccountInfo(val) {
|
|
4252
|
+
return isRecord(val) && hasStringProp(val, "uin");
|
|
4253
|
+
}
|
|
4254
|
+
/** getLoginList 返回 → 登录列表(形状异常返回空数组,不抛裸 TypeError)。 */
|
|
4255
|
+
function extractLoginAccounts(list) {
|
|
4256
|
+
if (!isRecord(list)) return [];
|
|
4257
|
+
const items = list["LocalLoginInfoList"];
|
|
4258
|
+
return Array.isArray(items) ? items.filter(isLoginAccountInfo) : [];
|
|
4259
|
+
}
|
|
4260
|
+
/** quickLoginWithUin 返回 → errMsg(结构缺失按「未知登录错误」处理)。 */
|
|
4261
|
+
function extractLoginErrMsg(result) {
|
|
4262
|
+
if (!isRecord(result)) return "未知登录错误";
|
|
4263
|
+
const info = result["loginErrorInfo"];
|
|
4264
|
+
if (isRecord(info) && typeof info["errMsg"] === "string") return info["errMsg"];
|
|
4265
|
+
return "未知登录错误";
|
|
4266
|
+
}
|
|
4267
|
+
/**
|
|
3902
4268
|
* 网络状态(MSF)常量。
|
|
3903
4269
|
* 3 = 已连接(NapCat waitForNetworkConnection 语义,自研描述)。
|
|
3904
4270
|
*/
|
|
@@ -3925,10 +4291,10 @@ const QUICK_LOGIN_TIMEOUT_MESSAGE = "快速登录超时";
|
|
|
3925
4291
|
*/
|
|
3926
4292
|
function waitForNetworkConnection(ctx, opts = {}) {
|
|
3927
4293
|
const raw = ctx.loginService;
|
|
3928
|
-
if (raw
|
|
4294
|
+
if (!isRecord(raw) || !hasFunctionProp(raw, "getMsfStatus")) return Promise.resolve(false);
|
|
3929
4295
|
return waitFor(() => {
|
|
3930
4296
|
try {
|
|
3931
|
-
return raw
|
|
4297
|
+
return raw["getMsfStatus"]() === MSF_STATUS_CONNECTED;
|
|
3932
4298
|
} catch {
|
|
3933
4299
|
return false;
|
|
3934
4300
|
}
|
|
@@ -3936,9 +4302,7 @@ function waitForNetworkConnection(ctx, opts = {}) {
|
|
|
3936
4302
|
}
|
|
3937
4303
|
/** 列出历史登录账号(boot.cjs 启动横幅用,「可用快速登录 of QQ」)。 */
|
|
3938
4304
|
async function listLoginAccounts(ctx) {
|
|
3939
|
-
|
|
3940
|
-
if (raw === null) throw kernelError("loginService 无效(缺 getLoginList)", "INVALID_STATE");
|
|
3941
|
-
return (await raw.getLoginList()).LocalLoginInfoList;
|
|
4305
|
+
return extractLoginAccounts(await requireLoginService(ctx.loginService).getLoginList());
|
|
3942
4306
|
}
|
|
3943
4307
|
/**
|
|
3944
4308
|
* 登录服务连接(自建宿主必需,HANDOVER-V6/V10 p0-kernel-flow 实证顺序):
|
|
@@ -3950,7 +4314,7 @@ async function listLoginAccounts(ctx) {
|
|
|
3950
4314
|
*/
|
|
3951
4315
|
async function ensureLoginConnected(ctx, opts) {
|
|
3952
4316
|
const raw = ctx.loginService;
|
|
3953
|
-
if (raw
|
|
4317
|
+
if (!isLoginConnectionShape(raw) || typeof raw.connect !== "function") return;
|
|
3954
4318
|
await waitLoginConnected(raw, opts.timeoutMs);
|
|
3955
4319
|
await sleep(CONNECTION_SETTLE_MS);
|
|
3956
4320
|
}
|
|
@@ -4062,7 +4426,7 @@ async function loginWithNetworkRetry(ctx, loginService, target, opts, quickTimeo
|
|
|
4062
4426
|
}
|
|
4063
4427
|
/** 单次快速登录尝试(成功带结果,失败带错误消息)。 */
|
|
4064
4428
|
async function attemptQuickLogin(loginService, target) {
|
|
4065
|
-
const
|
|
4429
|
+
const errMsg = extractLoginErrMsg(await loginService.quickLoginWithUin(target.uin));
|
|
4066
4430
|
if (errMsg) return {
|
|
4067
4431
|
ok: false,
|
|
4068
4432
|
errMsg
|
|
@@ -4088,14 +4452,12 @@ function isNetworkError(errMsg) {
|
|
|
4088
4452
|
* 抛出,上层 catch/qrFallback 语义自动生效。
|
|
4089
4453
|
*/
|
|
4090
4454
|
async function quickLogin(ctx, opts = {}) {
|
|
4091
|
-
const
|
|
4092
|
-
if (raw === null) throw kernelError("loginService 无效(缺 getLoginList)", "INVALID_STATE");
|
|
4093
|
-
const loginService = raw;
|
|
4455
|
+
const loginService = requireLoginService(ctx.loginService);
|
|
4094
4456
|
const quickTimeoutMs = opts.quickLoginTimeoutMs ?? 2e4;
|
|
4095
4457
|
await ensureLoginConnected(ctx, { ...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {} });
|
|
4096
|
-
const items = (await raceWithTimeout(loginService.getLoginList(), quickTimeoutMs, () => {
|
|
4458
|
+
const items = extractLoginAccounts(await raceWithTimeout(loginService.getLoginList(), quickTimeoutMs, () => {
|
|
4097
4459
|
throw kernelError(`快速登录失败: ${QUICK_LOGIN_TIMEOUT_MESSAGE}`, "NOT_LOGIN");
|
|
4098
|
-
}))
|
|
4460
|
+
}));
|
|
4099
4461
|
if (items.length === 0) throw kernelError("无历史登录账号", "NOT_LOGIN");
|
|
4100
4462
|
return loginWithNetworkRetry(ctx, loginService, pickLoginTarget(items, opts.uin), opts, quickTimeoutMs);
|
|
4101
4463
|
}
|
|
@@ -4214,6 +4576,17 @@ function startupSessionStart(ctx) {
|
|
|
4214
4576
|
*
|
|
4215
4577
|
* 不含 UI 渲染(cli 只做二维码渲染/URL 打印)。
|
|
4216
4578
|
*/
|
|
4579
|
+
/** 运行时判定 loginService 是否具备 QrLoginSession 依赖的方法面。 */
|
|
4580
|
+
function isLoginServiceLike(val) {
|
|
4581
|
+
return hasMethodSurface(val, [
|
|
4582
|
+
"addKernelLoginListener",
|
|
4583
|
+
"removeKernelLoginListener",
|
|
4584
|
+
"connect",
|
|
4585
|
+
"getLoginList",
|
|
4586
|
+
"quickLoginWithUin",
|
|
4587
|
+
"getQRCodePicture"
|
|
4588
|
+
]);
|
|
4589
|
+
}
|
|
4217
4590
|
/** 二维码过期错误码(errType=1 errCode=3,实测)。 */
|
|
4218
4591
|
const QR_EXPIRED_ERR_TYPE = 1;
|
|
4219
4592
|
const QR_EXPIRED_ERR_CODE = 3;
|
|
@@ -4240,9 +4613,8 @@ var QrLoginSession = class {
|
|
|
4240
4613
|
/** 超时上限(毫秒,默认 QR_LOGIN_TIMEOUT_MS)。 */
|
|
4241
4614
|
timeoutMs;
|
|
4242
4615
|
constructor(loginService, options = {}) {
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
this.loginService = svc;
|
|
4616
|
+
if (!isLoginServiceLike(loginService)) throw kernelError("loginService 无效(缺 addKernelLoginListener)", "INVALID_STATE");
|
|
4617
|
+
this.loginService = loginService;
|
|
4246
4618
|
this.timeoutMs = options.timeoutMs ?? 12e4;
|
|
4247
4619
|
}
|
|
4248
4620
|
/** 当前状态。 */
|
|
@@ -4275,7 +4647,7 @@ var QrLoginSession = class {
|
|
|
4275
4647
|
if (opts.quickUin !== void 0 && opts.quickUin !== "") {
|
|
4276
4648
|
this.restartTimeout();
|
|
4277
4649
|
this.loginService.quickLoginWithUin(opts.quickUin).then((result) => {
|
|
4278
|
-
if (result
|
|
4650
|
+
if (extractLoginErrMsg(result) !== "") this.refreshAfterQuickLogin();
|
|
4279
4651
|
}).catch(() => {
|
|
4280
4652
|
this.refreshAfterQuickLogin();
|
|
4281
4653
|
});
|
|
@@ -4479,7 +4851,7 @@ function createKernelRuntime(opts) {
|
|
|
4479
4851
|
/** wrapper exports → util(支持直接传 exports 或 NodeQQNTWrapperUtil 本身)。 */
|
|
4480
4852
|
function wrapperUtilOf(wrapperExports) {
|
|
4481
4853
|
if (wrapperExports === void 0) return;
|
|
4482
|
-
return wrapperExports
|
|
4854
|
+
return getOwnProp(wrapperExports, "NodeQQNTWrapperUtil") ?? wrapperExports;
|
|
4483
4855
|
}
|
|
4484
4856
|
/** RecentContact 桥:老版本 wrapper 无 getRecentContactService 时跳过。 */
|
|
4485
4857
|
function createRecentContactBridge(session, channel) {
|
|
@@ -4822,13 +5194,37 @@ function buildSessionConfig(options) {
|
|
|
4822
5194
|
*/
|
|
4823
5195
|
function readMachineGuid(loginService) {
|
|
4824
5196
|
try {
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
5197
|
+
if (hasCallableProp(loginService, "getMachineGuid")) {
|
|
5198
|
+
const value = loginService.getMachineGuid();
|
|
5199
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
5200
|
+
}
|
|
4829
5201
|
} catch {
|
|
4830
5202
|
return "";
|
|
4831
5203
|
}
|
|
5204
|
+
return "";
|
|
5205
|
+
}
|
|
5206
|
+
// src/wrapper/wrapper-guards.ts
|
|
5207
|
+
/** wrapper.node 顶层导出至少含一个已知符号(dlopen 后立即校验,细节由下游守卫补足)。 */
|
|
5208
|
+
function isWrapperNodeApi(val) {
|
|
5209
|
+
if (!isRecord(val)) return false;
|
|
5210
|
+
return "NodeIQQNTWrapperSession" in val || "NodeIQQNTWrapperEngine" in val || "NodeIKernelLoginService" in val || "NodeQQNTWrapperUtil" in val;
|
|
5211
|
+
}
|
|
5212
|
+
/** engine 实例最小可用面:`initWithDeskTopConfig`(`readyToShow` 为可选增强)。 */
|
|
5213
|
+
function isWrapperEngine(val) {
|
|
5214
|
+
return hasMethodSurface(val, ["initWithDeskTopConfig"]);
|
|
5215
|
+
}
|
|
5216
|
+
/** StartupSessionWrapper 实例可用面:`start()`。 */
|
|
5217
|
+
function isStartupSessionWrapper(val) {
|
|
5218
|
+
return hasCallableProp(val, "start");
|
|
5219
|
+
}
|
|
5220
|
+
/** session 实例最小可用面:`getMsgService()`(service 挂载即 session 可用)。 */
|
|
5221
|
+
function isWrapperSession(val) {
|
|
5222
|
+
return hasCallableProp(val, "getMsgService");
|
|
5223
|
+
}
|
|
5224
|
+
/** Electron 进程类型(Node 的 process 类型无此字段;"browser" / "utility"。 */
|
|
5225
|
+
function getElectronProcessType(proc) {
|
|
5226
|
+
const t = getOwnProp(proc, "type");
|
|
5227
|
+
return typeof t === "string" ? t : void 0;
|
|
4832
5228
|
}
|
|
4833
5229
|
// src/wrapper/wrapper-loader.ts
|
|
4834
5230
|
/**
|
|
@@ -4878,7 +5274,7 @@ function defaultEngineConfig(env, qqDataPath) {
|
|
|
4878
5274
|
* - "utility":utilityProcess Worker(路线 B,2026-08-06)
|
|
4879
5275
|
*/
|
|
4880
5276
|
function electronProcessType() {
|
|
4881
|
-
return process
|
|
5277
|
+
return getElectronProcessType(process);
|
|
4882
5278
|
}
|
|
4883
5279
|
/**
|
|
4884
5280
|
* 解析 QQ 用户数据根(登录数据目录,如 `C:\Users\<user>\Documents\Tencent Files`)。
|
|
@@ -4904,8 +5300,14 @@ function resolveQqUserDataRoot(exports, opts = {}) {
|
|
|
4904
5300
|
/** 从 QQ 官方 API 提取数据根(不可用返回 null,调用方回退默认)。 */
|
|
4905
5301
|
function extractUserDataRoot(exports) {
|
|
4906
5302
|
try {
|
|
4907
|
-
const
|
|
4908
|
-
if (
|
|
5303
|
+
const utilCtor = exports.NodeQQNTWrapperUtil;
|
|
5304
|
+
if (hasCallableProp(utilCtor, "get")) {
|
|
5305
|
+
const inst = utilCtor.get();
|
|
5306
|
+
if (hasCallableProp(inst, "getNTUserDataInfoConfig")) {
|
|
5307
|
+
const raw = inst.getNTUserDataInfoConfig();
|
|
5308
|
+
if (typeof raw === "string" && raw.trim() !== "") return extractDataRoot(raw.trim());
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
4909
5311
|
} catch {}
|
|
4910
5312
|
return null;
|
|
4911
5313
|
}
|
|
@@ -4914,13 +5316,13 @@ function extractUserDataRoot(exports) {
|
|
|
4914
5316
|
* 在 QQ 主进程内调用(boot.cjs → kernel 入口)。
|
|
4915
5317
|
*/
|
|
4916
5318
|
function createWrapper(exports, versionInfo) {
|
|
4917
|
-
const
|
|
4918
|
-
if (
|
|
4919
|
-
const
|
|
4920
|
-
if (!
|
|
5319
|
+
const engineCtor = exports.NodeIQQNTWrapperEngine;
|
|
5320
|
+
if (!hasCallableProp(engineCtor, "get")) throw kernelError("wrapper.node exports 无效(缺少 NodeIQQNTWrapperEngine)", "INVALID_PARAM");
|
|
5321
|
+
const rawEngine = engineCtor.get();
|
|
5322
|
+
if (!isWrapperEngine(rawEngine)) throw kernelError("NodeIQQNTWrapperEngine.get() 返回对象无效", "INVALID_PARAM");
|
|
4921
5323
|
return {
|
|
4922
5324
|
exports,
|
|
4923
|
-
engine,
|
|
5325
|
+
engine: rawEngine,
|
|
4924
5326
|
versionInfo,
|
|
4925
5327
|
session: null,
|
|
4926
5328
|
startupSession: null,
|
|
@@ -4950,18 +5352,20 @@ function createSession(ctx) {
|
|
|
4950
5352
|
}
|
|
4951
5353
|
/** 步骤 1:StartupSessionWrapper.create()(建立启动 session,失败忽略)。 */
|
|
4952
5354
|
function createStartupSession(ctx) {
|
|
4953
|
-
const
|
|
4954
|
-
if (
|
|
5355
|
+
const sswCtor = ctx.exports.NodeIQQNTStartupSessionWrapper;
|
|
5356
|
+
if (!hasCallableProp(sswCtor, "create")) return null;
|
|
4955
5357
|
try {
|
|
4956
|
-
|
|
5358
|
+
const inst = sswCtor.create();
|
|
5359
|
+
if (isStartupSessionWrapper(inst)) ctx.startupSession = inst;
|
|
4957
5360
|
} catch {}
|
|
4958
5361
|
return null;
|
|
4959
5362
|
}
|
|
4960
5363
|
/** 步骤 2:getNTWrapperSession("nt_1")(QQ 主 session,带 cpp_impl)。 */
|
|
4961
5364
|
function getNTWrapperSession(S) {
|
|
4962
|
-
if (
|
|
5365
|
+
if (!hasCallableProp(S, "getNTWrapperSession")) return null;
|
|
4963
5366
|
try {
|
|
4964
|
-
|
|
5367
|
+
const got = S.getNTWrapperSession("nt_1");
|
|
5368
|
+
return isWrapperSession(got) ? got : null;
|
|
4965
5369
|
} catch {
|
|
4966
5370
|
return null;
|
|
4967
5371
|
}
|
|
@@ -5078,7 +5482,7 @@ function resolveLoginService(ctx, qqLoginService) {
|
|
|
5078
5482
|
function getOrCreateLoginService(exports) {
|
|
5079
5483
|
try {
|
|
5080
5484
|
const loginSvcCtor = exports.NodeIKernelLoginService;
|
|
5081
|
-
if (loginSvcCtor
|
|
5485
|
+
if (hasCallableProp(loginSvcCtor, "get")) return loginSvcCtor.get();
|
|
5082
5486
|
return new exports.NodeIKernelLoginService();
|
|
5083
5487
|
} catch {
|
|
5084
5488
|
return null;
|
|
@@ -5096,7 +5500,8 @@ function getOrCreateLoginService(exports) {
|
|
|
5096
5500
|
function dlopenWrapper(wrapperPath) {
|
|
5097
5501
|
const m = { exports: {} };
|
|
5098
5502
|
process.dlopen(m, wrapperPath);
|
|
5099
|
-
if (!Object.keys(m.exports
|
|
5503
|
+
if (!Object.keys(m.exports).includes("NodeIKernelLoginService")) throw kernelError("exports 无 NodeIKernelLoginService(stub 环境异常?)", "INVALID_STATE");
|
|
5504
|
+
if (!isWrapperNodeApi(m.exports)) throw kernelError(`wrapper.node at ${wrapperPath} did not export expected QQNT symbols`, "INVALID_STATE");
|
|
5100
5505
|
return m.exports;
|
|
5101
5506
|
}
|
|
5102
5507
|
/** 已激活 O3MiscService 的 exports(幂等标记,避免重复挂监听)。 */
|
|
@@ -5114,13 +5519,13 @@ const ACTIVATED_O3_EXPORTS = /* @__PURE__ */ new WeakSet();
|
|
|
5114
5519
|
function activateO3MiscService(wrapperExports) {
|
|
5115
5520
|
if (wrapperExports === void 0 || wrapperExports === null) return false;
|
|
5116
5521
|
if (ACTIVATED_O3_EXPORTS.has(wrapperExports)) return true;
|
|
5117
|
-
const
|
|
5118
|
-
if (
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
return
|
|
5522
|
+
const o3Ctor = wrapperExports["NodeIO3MiscService"];
|
|
5523
|
+
if (!hasCallableProp(o3Ctor, "get")) return false;
|
|
5524
|
+
const svc = o3Ctor.get();
|
|
5525
|
+
if (!hasCallableProp(svc, "addO3MiscListener")) return false;
|
|
5526
|
+
svc.addO3MiscListener({ getOnAmgomDataPiece() {} });
|
|
5527
|
+
ACTIVATED_O3_EXPORTS.add(wrapperExports);
|
|
5528
|
+
return true;
|
|
5124
5529
|
}
|
|
5125
5530
|
// src/core.ts
|
|
5126
5531
|
/**
|
|
@@ -5290,14 +5695,14 @@ var NapukettoCore = class NapukettoCore {
|
|
|
5290
5695
|
* QQ 主进程(V1)模式 QQ 自己 initConfig 过正确路径,无需解析。
|
|
5291
5696
|
*/
|
|
5292
5697
|
initLoginConfig(wrapper, appid) {
|
|
5293
|
-
const
|
|
5294
|
-
if (
|
|
5698
|
+
const raw = wrapper.loginService;
|
|
5699
|
+
if (!isRecord(raw) || !hasInitConfig(raw)) {
|
|
5295
5700
|
this.ctx.logger.warn("loginService 不可用,跳过 initConfig");
|
|
5296
5701
|
return;
|
|
5297
5702
|
}
|
|
5298
5703
|
const commonPath = resolveCommonPath(this.ctx, wrapper);
|
|
5299
5704
|
const loginCfg = buildLoginConfig(appid, wrapper.versionInfo.fullVersion, commonPath);
|
|
5300
|
-
|
|
5705
|
+
raw["initConfig"](loginCfg);
|
|
5301
5706
|
this.ctx.logger.info({ commonPath }, "loginService.initConfig OK");
|
|
5302
5707
|
}
|
|
5303
5708
|
/**
|
|
@@ -5356,7 +5761,8 @@ var NapukettoCore = class NapukettoCore {
|
|
|
5356
5761
|
/** QR 状态转发:日志 + onLoginProgress(failed 附 failureReason)。 */
|
|
5357
5762
|
forwardQrState(session, opts, state) {
|
|
5358
5763
|
this.ctx.logger.info({ state }, "QR 登录状态");
|
|
5359
|
-
|
|
5764
|
+
const progress = qrProgressEvent(state, session.selfInfo, session.failureReason);
|
|
5765
|
+
if (progress !== null) opts.onLoginProgress?.(progress);
|
|
5360
5766
|
}
|
|
5361
5767
|
/**
|
|
5362
5768
|
* 停止:幂等清理 QR 会话 + 已装配的运行时服务(桥/缓存/通道)后日志收尾。
|
|
@@ -5410,6 +5816,14 @@ function resolveSessionAccountPath(ctx, wrapper) {
|
|
|
5410
5816
|
const root = resolveQqUserDataRoot(wrapper.exports, { dataRoot: ctx.paths.root });
|
|
5411
5817
|
return root !== null ? resolveQqGlobalPath(root) : ctx.paths.accountDir;
|
|
5412
5818
|
}
|
|
5819
|
+
/**
|
|
5820
|
+
* loginService.initConfig 形状守卫(可带一个配置参数调用)。
|
|
5821
|
+
* `hasFunctionProp` 的函数类型是「零参可调用」(`(...args: never[])`),
|
|
5822
|
+
* 这里需要带参调用,故给一个精确到参数的谓词。
|
|
5823
|
+
*/
|
|
5824
|
+
function hasInitConfig(val) {
|
|
5825
|
+
return typeof val["initConfig"] === "function";
|
|
5826
|
+
}
|
|
5413
5827
|
/** 写二维码 png 到磁盘(base64 解码,供 cli/用户扫码)。 */
|
|
5414
5828
|
function writeQrCodePng(filePath, pngBase64) {
|
|
5415
5829
|
try {
|
|
@@ -5430,13 +5844,29 @@ function requireQrSelfInfo(session) {
|
|
|
5430
5844
|
if (self === null) throw kernelError("QR 登录成功但 selfInfo 为空", "INVALID_STATE");
|
|
5431
5845
|
return self;
|
|
5432
5846
|
}
|
|
5433
|
-
/**
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5847
|
+
/**
|
|
5848
|
+
* QR 进度事件折叠(可辨识联合,判别字段 = state)。
|
|
5849
|
+
*
|
|
5850
|
+
* 返回 null = 该状态不单独上报:
|
|
5851
|
+
* - waiting_scan:二维码数据由 `subscribeQrProgress` 的 onQrCode 回执发出
|
|
5852
|
+
* (那里才拿得到 qr),状态机这次先不带 qr 的事件不再重复发;
|
|
5853
|
+
* - logged_in 且 selfInfo 仍为空:会话已损坏(调用方随后按 INVALID_STATE 拒绝),
|
|
5854
|
+
* 不构造自相矛盾的 logged_in 事件。
|
|
5855
|
+
*/
|
|
5856
|
+
function qrProgressEvent(state, selfInfo, reason) {
|
|
5857
|
+
switch (state) {
|
|
5858
|
+
case "idle": return { state };
|
|
5859
|
+
case "waiting_scan": return null;
|
|
5860
|
+
case "scanned": return { state };
|
|
5861
|
+
case "logged_in": return selfInfo === null ? null : {
|
|
5862
|
+
state,
|
|
5863
|
+
selfInfo
|
|
5864
|
+
};
|
|
5865
|
+
case "failed": return {
|
|
5866
|
+
state,
|
|
5867
|
+
message: reason ?? ""
|
|
5868
|
+
};
|
|
5869
|
+
}
|
|
5440
5870
|
}
|
|
5441
5871
|
/** 等待 QR 登录终态:logged_in resolve,failed reject。 */
|
|
5442
5872
|
function waitQrLoggedIn(session) {
|
|
@@ -5480,13 +5910,13 @@ function firstStringId(ids, pred) {
|
|
|
5480
5910
|
}
|
|
5481
5911
|
/** 通过 getNTWrapperSession 拿主 session(内部辅助)。 */
|
|
5482
5912
|
function resolveMainSession(created, getNTWrapperSession) {
|
|
5483
|
-
created.start
|
|
5484
|
-
const ids =
|
|
5913
|
+
if (hasCallableProp(created, "start")) created.start();
|
|
5914
|
+
const ids = hasCallableProp(created, "getSessionIdList") ? created.getSessionIdList() : null;
|
|
5485
5915
|
if (!(ids instanceof Map)) return null;
|
|
5486
5916
|
const mainId = findMainSessionId(ids);
|
|
5487
5917
|
if (mainId === null) return null;
|
|
5488
5918
|
const maybe = getNTWrapperSession(mainId);
|
|
5489
|
-
return maybe
|
|
5919
|
+
return isWrapperSession(maybe) ? maybe : null;
|
|
5490
5920
|
}
|
|
5491
5921
|
/**
|
|
5492
5922
|
* 复用 QQ 已有 session(P1-4:QQ 已登录,直接拿单例避免重复 init)。
|
|
@@ -5505,10 +5935,10 @@ function getExistingSession(ctx) {
|
|
|
5505
5935
|
/** NodeIQQNTWrapperSession.get() 单例(无效/异常返回 null)。 */
|
|
5506
5936
|
function trySessionGet(ctx) {
|
|
5507
5937
|
try {
|
|
5508
|
-
const
|
|
5509
|
-
if (
|
|
5510
|
-
const got =
|
|
5511
|
-
return got
|
|
5938
|
+
const sessionCtor = ctx.exports.NodeIQQNTWrapperSession;
|
|
5939
|
+
if (!hasCallableProp(sessionCtor, "get")) return null;
|
|
5940
|
+
const got = sessionCtor.get();
|
|
5941
|
+
return isWrapperSession(got) ? got : null;
|
|
5512
5942
|
} catch {
|
|
5513
5943
|
return null;
|
|
5514
5944
|
}
|
|
@@ -5523,20 +5953,19 @@ function trySessionGet(ctx) {
|
|
|
5523
5953
|
*/
|
|
5524
5954
|
function getMainSession(ctx) {
|
|
5525
5955
|
try {
|
|
5526
|
-
return resolveMainFromStartup(ctx)
|
|
5956
|
+
return resolveMainFromStartup(ctx);
|
|
5527
5957
|
} catch {
|
|
5528
5958
|
return null;
|
|
5529
5959
|
}
|
|
5530
5960
|
}
|
|
5531
5961
|
/** startup.create → start → getSessionIdList → getNTWrapperSession 链路。 */
|
|
5532
5962
|
function resolveMainFromStartup(ctx) {
|
|
5533
|
-
const
|
|
5963
|
+
const startupCtor = ctx.exports.NodeIQQNTStartupSessionWrapper;
|
|
5534
5964
|
const sessionCtor = ctx.exports.NodeIQQNTWrapperSession;
|
|
5535
|
-
if (
|
|
5536
|
-
const created =
|
|
5537
|
-
if (
|
|
5538
|
-
|
|
5539
|
-
return resolveMainSession(created, getSession);
|
|
5965
|
+
if (!hasCallableProp(startupCtor, "create") || !hasCallableProp(sessionCtor, "getNTWrapperSession")) return null;
|
|
5966
|
+
const created = startupCtor.create();
|
|
5967
|
+
if (created === null || created === void 0) return null;
|
|
5968
|
+
return resolveMainSession(created, (id) => sessionCtor.getNTWrapperSession(id));
|
|
5540
5969
|
}
|
|
5541
5970
|
// src/wrapper/probe/probe-serialize.ts
|
|
5542
5971
|
/**
|
|
@@ -5577,12 +6006,13 @@ function serialize(value, depth = 0) {
|
|
|
5577
6006
|
function serializeContainer(value, depth) {
|
|
5578
6007
|
if (ArrayBuffer.isView(value)) return serializeBytes(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
5579
6008
|
if (Array.isArray(value)) {
|
|
5580
|
-
if (value.length >= BYTES_ARRAY_MIN && looksLikeBytes(value)) return serializeBytes(Uint8Array.from(value, (b) => b & 255));
|
|
6009
|
+
if (value.length >= BYTES_ARRAY_MIN && looksLikeBytes(value)) return serializeBytes(Uint8Array.from(value, (b) => typeof b === "number" ? b & 255 : 0));
|
|
5581
6010
|
return serializeArray(value, depth);
|
|
5582
6011
|
}
|
|
5583
6012
|
if (value instanceof Map) return serializeMap(value, depth);
|
|
5584
6013
|
if (value instanceof Set) return serializeSet(value, depth);
|
|
5585
|
-
if (
|
|
6014
|
+
if (hasCallableProp(value, "then")) return "[Promise]";
|
|
6015
|
+
if (!isRecord(value)) return String(value);
|
|
5586
6016
|
return serializeObject(value, depth);
|
|
5587
6017
|
}
|
|
5588
6018
|
/** 普通数组是否字节形态(全部元素为整数且落 [-128, 255]——原生把字节块转成带符号字节数组)。 */
|
|
@@ -5636,8 +6066,8 @@ function serializeObject(value, depth) {
|
|
|
5636
6066
|
/** 尝试解析一个 service getter 的返回值形状(深度受限)。 */
|
|
5637
6067
|
function tryShape(session, getter) {
|
|
5638
6068
|
try {
|
|
5639
|
-
const fn = session
|
|
5640
|
-
if (
|
|
6069
|
+
const fn = getOwnProp(session, getter);
|
|
6070
|
+
if (!isCallable(fn)) return null;
|
|
5641
6071
|
const value = fn.call(session);
|
|
5642
6072
|
if (value === null || value === void 0) return null;
|
|
5643
6073
|
return serialize(value);
|
|
@@ -5679,8 +6109,8 @@ function collectOwnNames(obj, names) {
|
|
|
5679
6109
|
/** 安全调用:尝试调用方法拿返回值,失败记录错误(不中断探测)。 */
|
|
5680
6110
|
function tryCall(obj, name) {
|
|
5681
6111
|
try {
|
|
5682
|
-
const fn = obj
|
|
5683
|
-
if (
|
|
6112
|
+
const fn = getOwnProp(obj, name);
|
|
6113
|
+
if (!isCallable(fn)) return {
|
|
5684
6114
|
ok: false,
|
|
5685
6115
|
error: `not a function (typeof=${typeof fn})`
|
|
5686
6116
|
};
|
|
@@ -5702,6 +6132,13 @@ function isServiceGetter(name) {
|
|
|
5702
6132
|
return name.startsWith("get") && name.endsWith("Service");
|
|
5703
6133
|
}
|
|
5704
6134
|
// src/wrapper/probe/probe-services.ts
|
|
6135
|
+
/**
|
|
6136
|
+
* wrapper exports 探测(从 probe.ts 拆分,2026-08-08 FTA 优化)
|
|
6137
|
+
*
|
|
6138
|
+
* - probeExportCtors:关键 export 构造器方法面
|
|
6139
|
+
* - probeEngineCalls:engine 关键调用
|
|
6140
|
+
* - probeLoginService:LoginService 实例(QQ 已登录凭据入口)
|
|
6141
|
+
*/
|
|
5705
6142
|
/** 探测关键 export 构造器方法(get/create/getNTWrapperSession 等)。 */
|
|
5706
6143
|
function probeExportCtors(ctx) {
|
|
5707
6144
|
const keys = [
|
|
@@ -5713,7 +6150,7 @@ function probeExportCtors(ctx) {
|
|
|
5713
6150
|
];
|
|
5714
6151
|
const out = {};
|
|
5715
6152
|
for (const key of keys) {
|
|
5716
|
-
const ctor = ctx.exports
|
|
6153
|
+
const ctor = getOwnProp(ctx.exports, key);
|
|
5717
6154
|
if (ctor !== null && ctor !== void 0) out[key] = {
|
|
5718
6155
|
methods: listMethods(ctor),
|
|
5719
6156
|
ownKeys: Object.getOwnPropertyNames(ctor)
|
|
@@ -5745,7 +6182,7 @@ const ENGINE_CALL_PROBES = [
|
|
|
5745
6182
|
/** 探测 LoginService 实例(QQ 已登录凭据入口)。 */
|
|
5746
6183
|
function probeLoginService(ctx) {
|
|
5747
6184
|
const ctor = ctx.exports.NodeIKernelLoginService;
|
|
5748
|
-
if (ctor
|
|
6185
|
+
if (!hasCallableProp(ctor, "get")) return null;
|
|
5749
6186
|
const inst = tryCall(ctor, "get");
|
|
5750
6187
|
if (!(inst.ok && inst.value)) return { get: inst.error ?? "null/undefined" };
|
|
5751
6188
|
return {
|
|
@@ -5757,7 +6194,7 @@ function probeLoginService(ctx) {
|
|
|
5757
6194
|
/** 尝试关键登录信息 getter(无参调用,探测形状)。 */
|
|
5758
6195
|
function probeLoginGetters(inst) {
|
|
5759
6196
|
const out = {};
|
|
5760
|
-
for (const m of LOGIN_GETTER_PROBES) if (
|
|
6197
|
+
for (const m of LOGIN_GETTER_PROBES) if (hasCallableProp(inst, m)) out[m] = tryShape(inst, m);
|
|
5761
6198
|
return out;
|
|
5762
6199
|
}
|
|
5763
6200
|
/** 登录信息 getter 候选(无参调用,探测形状)。 */
|
|
@@ -5807,10 +6244,9 @@ function probeSessionId(enumFn, thisCtx, id, out) {
|
|
|
5807
6244
|
}
|
|
5808
6245
|
/** 探测单个 session 记录(getter 存在性 + msgService 调用结果 + 方法面)。 */
|
|
5809
6246
|
function probeSessionRecord(value) {
|
|
5810
|
-
const
|
|
5811
|
-
const msg = tryMsgService(rec, value);
|
|
6247
|
+
const msg = tryMsgService(value);
|
|
5812
6248
|
return {
|
|
5813
|
-
hasMsgServiceGetter:
|
|
6249
|
+
hasMsgServiceGetter: hasCallableProp(value, "getMsgService"),
|
|
5814
6250
|
msgServiceOk: msg.service !== null,
|
|
5815
6251
|
msgServiceMethods: msg.service ? listMethods(msg.service).length : 0,
|
|
5816
6252
|
msgError: msg.error,
|
|
@@ -5818,10 +6254,14 @@ function probeSessionRecord(value) {
|
|
|
5818
6254
|
};
|
|
5819
6255
|
}
|
|
5820
6256
|
/** 尝试调用 getMsgService(失败记录错误,成功返回实例)。 */
|
|
5821
|
-
function tryMsgService(
|
|
6257
|
+
function tryMsgService(thisCtx) {
|
|
5822
6258
|
try {
|
|
6259
|
+
if (!hasCallableProp(thisCtx, "getMsgService")) return {
|
|
6260
|
+
service: null,
|
|
6261
|
+
error: "missing getMsgService"
|
|
6262
|
+
};
|
|
5823
6263
|
return {
|
|
5824
|
-
service:
|
|
6264
|
+
service: thisCtx.getMsgService.call(thisCtx) ?? null,
|
|
5825
6265
|
error: null
|
|
5826
6266
|
};
|
|
5827
6267
|
} catch (e) {
|
|
@@ -5833,8 +6273,9 @@ function tryMsgService(rec, thisCtx) {
|
|
|
5833
6273
|
}
|
|
5834
6274
|
/** 取 NodeIQQNTWrapperSession.getNTWrapperSession 函数(无则 null)。 */
|
|
5835
6275
|
function getNTWrapperSessionFn(ctx) {
|
|
5836
|
-
const
|
|
5837
|
-
|
|
6276
|
+
const ctor = ctx.exports.NodeIQQNTWrapperSession;
|
|
6277
|
+
if (hasCallableProp(ctor, "getNTWrapperSession")) return ctor.getNTWrapperSession;
|
|
6278
|
+
return null;
|
|
5838
6279
|
}
|
|
5839
6280
|
/** 探测 startup 实例:start() + getSessionIdList(),提取 sessionIds(Map 值或键)。 */
|
|
5840
6281
|
function probeStartupChain(created) {
|
|
@@ -5896,7 +6337,7 @@ function probeSessionByName(ctx, name) {
|
|
|
5896
6337
|
/** StartupSessionWrapper 可用性判定(缺 create 方法视为不可用)。 */
|
|
5897
6338
|
function startupWrapper(ctx) {
|
|
5898
6339
|
const startup = ctx.exports.NodeIQQNTStartupSessionWrapper;
|
|
5899
|
-
return startup
|
|
6340
|
+
return hasCallableProp(startup, "create") ? startup : null;
|
|
5900
6341
|
}
|
|
5901
6342
|
/** create() 调用结果面(成功记实例方法面 + 序列化值,失败记 error)。 */
|
|
5902
6343
|
function createFace(created) {
|
|
@@ -6154,7 +6595,7 @@ function startListenerRecording(ctx, file = "napuketto-listener-record.jsonl") {
|
|
|
6154
6595
|
};
|
|
6155
6596
|
const registered = {};
|
|
6156
6597
|
const session = ctx.session;
|
|
6157
|
-
if (session
|
|
6598
|
+
if (isRecord(session)) for (const getter of INSTRUMENTED_SERVICE_GETTERS) registered[serviceShortName(getter)] = recordService(session, getter, emit);
|
|
6158
6599
|
registered["Login"] = recordLoginService(ctx, emit);
|
|
6159
6600
|
return {
|
|
6160
6601
|
file: full,
|
|
@@ -6165,12 +6606,12 @@ function startListenerRecording(ctx, file = "napuketto-listener-record.jsonl") {
|
|
|
6165
6606
|
function recordService(session, getter, emit) {
|
|
6166
6607
|
const name = serviceShortName(getter);
|
|
6167
6608
|
try {
|
|
6168
|
-
const
|
|
6169
|
-
if (
|
|
6609
|
+
const getterFn = session[getter];
|
|
6610
|
+
if (!isCallable(getterFn)) return {
|
|
6170
6611
|
ok: false,
|
|
6171
|
-
error: `getter 缺失(typeof=${typeof
|
|
6612
|
+
error: `getter 缺失(typeof=${typeof getterFn})`
|
|
6172
6613
|
};
|
|
6173
|
-
const service =
|
|
6614
|
+
const service = getterFn.call(session);
|
|
6174
6615
|
if (service === null || service === void 0) return {
|
|
6175
6616
|
ok: false,
|
|
6176
6617
|
error: "null/undefined"
|
|
@@ -6185,9 +6626,9 @@ function recordService(session, getter, emit) {
|
|
|
6185
6626
|
}
|
|
6186
6627
|
/** LoginService 单例录制(NodeIKernelLoginService.get(),bot_offline 候选源)。 */
|
|
6187
6628
|
function recordLoginService(ctx, emit) {
|
|
6188
|
-
const ctor = ctx.exports
|
|
6629
|
+
const ctor = getOwnProp(ctx.exports, "NodeIKernelLoginService");
|
|
6189
6630
|
try {
|
|
6190
|
-
if (ctor
|
|
6631
|
+
if (!hasCallableProp(ctor, "get")) return {
|
|
6191
6632
|
ok: false,
|
|
6192
6633
|
error: "NodeIKernelLoginService.get 缺失"
|
|
6193
6634
|
};
|
|
@@ -6211,13 +6652,14 @@ function attachRecordingListener(name, service, emit) {
|
|
|
6211
6652
|
ok: false,
|
|
6212
6653
|
error: "无 add*Listener 方法"
|
|
6213
6654
|
};
|
|
6214
|
-
const add = service
|
|
6215
|
-
if (
|
|
6655
|
+
const add = getOwnProp(service, addMethod);
|
|
6656
|
+
if (!isCallable(add)) return {
|
|
6216
6657
|
ok: false,
|
|
6217
6658
|
error: `${addMethod} 非函数`
|
|
6218
6659
|
};
|
|
6219
6660
|
const listener = createRecordingListener(name, emit);
|
|
6220
|
-
const
|
|
6661
|
+
const rawId = add.call(service, listener);
|
|
6662
|
+
const listenerId = typeof rawId === "number" ? rawId : void 0;
|
|
6221
6663
|
emit({
|
|
6222
6664
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6223
6665
|
service: name,
|
|
@@ -6249,16 +6691,18 @@ function attachRecordingListener(name, service, emit) {
|
|
|
6249
6691
|
function readVersionPackage(installDir, version) {
|
|
6250
6692
|
const pkgPath = join(installDir, "versions", version, "resources", "app", "package.json");
|
|
6251
6693
|
if (!existsSync(pkgPath)) throw kernelError(`QQ 版本目录缺少 package.json: ${pkgPath}`, "NOT_FOUND");
|
|
6694
|
+
let raw;
|
|
6252
6695
|
try {
|
|
6253
|
-
|
|
6254
|
-
return {
|
|
6255
|
-
name: raw.name ?? "",
|
|
6256
|
-
version: raw.version ?? "",
|
|
6257
|
-
...raw.buildVersion !== void 0 ? { buildVersion: raw.buildVersion } : {}
|
|
6258
|
-
};
|
|
6696
|
+
raw = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
6259
6697
|
} catch (cause) {
|
|
6260
6698
|
throw kernelError(`QQ 版本 package.json 解析失败: ${pkgPath}`, "INVALID_PARAM", { cause });
|
|
6261
6699
|
}
|
|
6700
|
+
if (!isRecord(raw) || typeof raw["version"] !== "string" || raw["version"].length === 0) throw kernelError(`QQ 版本 package.json 缺少有效 version: ${pkgPath}`, "INVALID_PARAM");
|
|
6701
|
+
return {
|
|
6702
|
+
name: typeof raw["name"] === "string" ? raw["name"] : "",
|
|
6703
|
+
version: raw["version"],
|
|
6704
|
+
...typeof raw["buildVersion"] === "string" ? { buildVersion: raw["buildVersion"] } : {}
|
|
6705
|
+
};
|
|
6262
6706
|
}
|
|
6263
6707
|
/** 解析 wrapper.node 绝对路径(按 ADR-018 目录约定)。 */
|
|
6264
6708
|
function resolveWrapperPath(installDir, version) {
|
|
@@ -6289,6 +6733,6 @@ function listQQVersions(installDir) {
|
|
|
6289
6733
|
return statSync(full).isDirectory() && existsSync(join(full, "resources", "app", "wrapper.node"));
|
|
6290
6734
|
}).sort().reverse();
|
|
6291
6735
|
}
|
|
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 };
|
|
6736
|
+
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, getErrorCode, getErrorMessage, getExistingSession, getMainSession, getOwnProp, hasBooleanProp, hasCallableProp, hasFunctionProp, hasMethodSurface, hasNumberProp, hasStaticCreator, hasStaticGetter, hasStringProp, initAndStartSession, initEngine, initSession, isCallable, isKernelError, isPromiseLike, isRecord, kernelError, listLoginAccounts, listQQVersions, narrowBuddyCategories, parseAppidFromMajor, parseJsonWithGuard, parseLogConfig, parseToml, probeRuntime, quickLogin, readMachineGuid, requireKernelService, resolveAppidQua, resolveConfigPath, resolveDataRoot, resolveQQVersion, resolveQqGlobalPath, resolveQqUserDataRoot, resolveWrapperPath, sleep, startListenerRecording, startNapuketto, startSession, stringifyToml, toCanonicalElements, toSendElements, waitFor, waitForNetworkConnection, waitSessionReady };
|
|
6293
6737
|
|
|
6294
6738
|
//# sourceMappingURL=index.mjs.map
|