@napuketto/adapter 0.16.1 → 0.16.4
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/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/{core-D5c78lFV.mjs → core-l7TM-aKF.mjs} +23 -2
- package/dist/core-l7TM-aKF.mjs.map +1 -0
- package/dist/{essence-Bxs-aKSC.mjs → essence-CU3kvItK.mjs} +75 -2
- package/dist/essence-CU3kvItK.mjs.map +1 -0
- package/dist/gray-tip-DNo_Mi4E.d.mts.map +1 -1
- package/dist/{index-Dhd-kaUF.d.mts → index-jdSniAj1.d.mts} +13 -3
- package/dist/index-jdSniAj1.d.mts.map +1 -0
- package/dist/kurobot/index.d.mts +12 -5
- package/dist/kurobot/index.d.mts.map +1 -1
- package/dist/kurobot/index.mjs +16 -15
- package/dist/kurobot/index.mjs.map +1 -1
- package/dist/log-AtQxAmbQ.mjs +214 -0
- package/dist/log-AtQxAmbQ.mjs.map +1 -0
- package/dist/milky/index.d.mts +15 -15
- package/dist/milky/index.d.mts.map +1 -1
- package/dist/milky/index.mjs +274 -265
- package/dist/milky/index.mjs.map +1 -1
- package/dist/onebot11/index.d.mts +1 -1
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +294 -276
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/raw-message-D5nMIebz.mjs +130 -0
- package/dist/raw-message-D5nMIebz.mjs.map +1 -0
- package/dist/satori/index.d.mts +116 -116
- package/dist/satori/index.d.mts.map +1 -1
- package/dist/satori/index.mjs +25 -31
- package/dist/satori/index.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/core-D5c78lFV.mjs.map +0 -1
- package/dist/essence-Bxs-aKSC.mjs.map +0 -1
- package/dist/index-Dhd-kaUF.d.mts.map +0 -1
- package/dist/log-BsInJV_y.mjs +0 -123
- package/dist/log-BsInJV_y.mjs.map +0 -1
- package/dist/media-DMMn74TC.mjs +0 -126
- package/dist/media-DMMn74TC.mjs.map +0 -1
- package/dist/raw-message-DE3sdJg8.mjs +0 -45
- package/dist/raw-message-DE3sdJg8.mjs.map +0 -1
package/dist/milky/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as
|
|
5
|
-
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
1
|
+
import { a as runAction, i as ActionRegistry, r as BaseProtocolAdapter } from "../core-l7TM-aKF.mjs";
|
|
2
|
+
import { c as collectGrayTipUids, d as hasGrayTip, l as findRevokeElement, n as sliceRaw, o as fileUriToPath, t as logEventFailure, u as firstUntranslatedGrayTip } from "../log-AtQxAmbQ.mjs";
|
|
3
|
+
import { a as firstNonEmptyString, c as MS_TO_SEC, d as resolveUin, f as toUin, i as toUnixSeconds, l as NUMERIC_RE, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, t as forEachRawMessage, u as numericUin } from "../raw-message-D5nMIebz.mjs";
|
|
4
|
+
import { a as narrowSysMsgBlobs, c as recognizeSysMsg, d as varintOf, f as BuddyReqDedup, h as narrowBuddyReqs, i as OBSERVED_UNNAMED_SYSMSG_KEYS, l as textOf, m as filterBuddyReqs, n as extractEssenceSetSysMsg, o as nodeAt, p as batchUnreadNums, r as narrowEssenceGroupArg, s as processSysMsgBlob, t as EssenceListSync, u as varintAt } from "../essence-CU3kvItK.mjs";
|
|
5
|
+
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, errorMessage, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
+
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
|
|
10
|
-
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
11
|
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
13
12
|
// src/milky/action/base-action.ts
|
|
14
13
|
/** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余取常见 HTTP 语义近似负数)。 */
|
|
@@ -119,7 +118,8 @@ function toFriendEntity(friend, uin, nick) {
|
|
|
119
118
|
/** 群域共入参(群号 / 成员 uin / 可选布尔;群管理 / 通知 / 精华 / 文件域复用)。 */
|
|
120
119
|
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
121
120
|
const userIdField = { user_id: z.number().int().min(10001) };
|
|
122
|
-
const optBool
|
|
121
|
+
const optBool = z.boolean().nullable().optional();
|
|
122
|
+
const optStr = z.string().nullable().optional();
|
|
123
123
|
/** 群查询域动作工厂(群信息 / 成员列表 / 成员单查 / 公告列表)。 */
|
|
124
124
|
function createGroupQueryActions(api) {
|
|
125
125
|
return [
|
|
@@ -127,7 +127,7 @@ function createGroupQueryActions(api) {
|
|
|
127
127
|
name: "get_group_info",
|
|
128
128
|
schema: z.object({
|
|
129
129
|
...groupIdField,
|
|
130
|
-
no_cache: optBool
|
|
130
|
+
no_cache: optBool
|
|
131
131
|
}),
|
|
132
132
|
handle: async (payload) => {
|
|
133
133
|
const groupCode = String(payload.group_id);
|
|
@@ -138,7 +138,7 @@ function createGroupQueryActions(api) {
|
|
|
138
138
|
name: "get_group_member_list",
|
|
139
139
|
schema: z.object({
|
|
140
140
|
...groupIdField,
|
|
141
|
-
no_cache: optBool
|
|
141
|
+
no_cache: optBool
|
|
142
142
|
}),
|
|
143
143
|
handle: async (payload) => {
|
|
144
144
|
return { members: (await membersOf(api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
|
|
@@ -149,7 +149,7 @@ function createGroupQueryActions(api) {
|
|
|
149
149
|
schema: z.object({
|
|
150
150
|
...groupIdField,
|
|
151
151
|
...userIdField,
|
|
152
|
-
no_cache: optBool
|
|
152
|
+
no_cache: optBool
|
|
153
153
|
}),
|
|
154
154
|
handle: async (payload) => {
|
|
155
155
|
return { member: toGroupMemberEntity(await memberOf(api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
|
|
@@ -181,7 +181,7 @@ async function memberOf(api, groupId, userId) {
|
|
|
181
181
|
api.logger?.debug({
|
|
182
182
|
group: groupCode,
|
|
183
183
|
uin,
|
|
184
|
-
error:
|
|
184
|
+
error: errorMessage(err)
|
|
185
185
|
}, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
|
|
186
186
|
return uin;
|
|
187
187
|
});
|
|
@@ -211,7 +211,7 @@ async function senderUinOf(b, api) {
|
|
|
211
211
|
const uins = await api.uidToUin([uid]).catch((err) => {
|
|
212
212
|
api.logger?.debug({
|
|
213
213
|
uid,
|
|
214
|
-
error:
|
|
214
|
+
error: errorMessage(err)
|
|
215
215
|
}, "milky: 公告发送者 uid→uin 失败,兜底 0");
|
|
216
216
|
});
|
|
217
217
|
return Number(uins?.get(uid)) || 0;
|
|
@@ -247,7 +247,7 @@ function createGroupEssenceActions(api) {
|
|
|
247
247
|
schema: z.object({
|
|
248
248
|
...groupIdField,
|
|
249
249
|
message_seq: z.number().int().min(0),
|
|
250
|
-
is_set: optBool
|
|
250
|
+
is_set: optBool
|
|
251
251
|
}),
|
|
252
252
|
handle: async (payload) => {
|
|
253
253
|
const groupCode = String(payload.group_id);
|
|
@@ -328,8 +328,6 @@ function essenceToEntity(item, groupId) {
|
|
|
328
328
|
* - http(s):// → @napuketto/media downloadUrl 落盘 cacheDir/milky/
|
|
329
329
|
* 未配置 mediaDir 时远程 URI 报错(不发静默空消息)。
|
|
330
330
|
*/
|
|
331
|
-
/** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
|
|
332
|
-
const FILE_URI_PREFIX_RE$1 = /^file:\/\//;
|
|
333
331
|
/** 解析远程媒体 URI 为本地绝对路径(base64:// / http(s)://;file:// 走同步面)。 */
|
|
334
332
|
async function resolveMediaUri(uri, mediaDir) {
|
|
335
333
|
if (mediaDir === void 0 || mediaDir === "") throw kernelError("远程媒体发送需要配置 [accounts.milky] cacheDir(下载缓存目录)", "INVALID_PARAM");
|
|
@@ -344,11 +342,7 @@ async function resolveMediaUri(uri, mediaDir) {
|
|
|
344
342
|
* resolveMediaUri 落盘;裸路径(go-cqhttp 惯例)原样。
|
|
345
343
|
*/
|
|
346
344
|
async function resolveUriToPath(uri, mediaDir) {
|
|
347
|
-
if (uri.startsWith("file://"))
|
|
348
|
-
return fileURLToPath(uri);
|
|
349
|
-
} catch {
|
|
350
|
-
return uri.replace(FILE_URI_PREFIX_RE$1, "");
|
|
351
|
-
}
|
|
345
|
+
if (uri.startsWith("file://")) return fileUriToPath(uri);
|
|
352
346
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return await resolveMediaUri(uri, mediaDir);
|
|
353
347
|
return uri;
|
|
354
348
|
}
|
|
@@ -375,7 +369,6 @@ async function writeBase64(payload, mediaDir) {
|
|
|
375
369
|
}
|
|
376
370
|
// src/milky/action/group-file.ts
|
|
377
371
|
const fileIdField = { file_id: z.string().min(1) };
|
|
378
|
-
const optStr$2 = z.string().nullable().optional();
|
|
379
372
|
/** 群文件域动作工厂(列表 / 移动 / 重命名 / 删除 / 转存 / 文件夹 / 闪传上传 / 下载链接)。 */
|
|
380
373
|
function createGroupFileActions(api) {
|
|
381
374
|
return [
|
|
@@ -383,7 +376,7 @@ function createGroupFileActions(api) {
|
|
|
383
376
|
name: "get_group_files",
|
|
384
377
|
schema: z.object({
|
|
385
378
|
...groupIdField,
|
|
386
|
-
parent_folder_id: optStr
|
|
379
|
+
parent_folder_id: optStr
|
|
387
380
|
}),
|
|
388
381
|
handle: async (payload) => {
|
|
389
382
|
const groupCode = String(payload.group_id);
|
|
@@ -404,8 +397,8 @@ function createGroupFileActions(api) {
|
|
|
404
397
|
schema: z.object({
|
|
405
398
|
...groupIdField,
|
|
406
399
|
...fileIdField,
|
|
407
|
-
parent_folder_id: optStr
|
|
408
|
-
target_folder_id: optStr
|
|
400
|
+
parent_folder_id: optStr,
|
|
401
|
+
target_folder_id: optStr
|
|
409
402
|
}),
|
|
410
403
|
handle: async (payload) => {
|
|
411
404
|
await api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
|
|
@@ -417,7 +410,7 @@ function createGroupFileActions(api) {
|
|
|
417
410
|
schema: z.object({
|
|
418
411
|
...groupIdField,
|
|
419
412
|
...fileIdField,
|
|
420
|
-
parent_folder_id: optStr
|
|
413
|
+
parent_folder_id: optStr,
|
|
421
414
|
new_file_name: z.string().min(1)
|
|
422
415
|
}),
|
|
423
416
|
handle: async (payload) => {
|
|
@@ -472,7 +465,7 @@ function createGroupFileActions(api) {
|
|
|
472
465
|
name: "upload_group_file",
|
|
473
466
|
schema: z.object({
|
|
474
467
|
...groupIdField,
|
|
475
|
-
parent_folder_id: optStr
|
|
468
|
+
parent_folder_id: optStr,
|
|
476
469
|
file_uri: z.string().min(1),
|
|
477
470
|
file_name: z.string().min(1)
|
|
478
471
|
}),
|
|
@@ -541,6 +534,152 @@ function folderToEntity(info, groupId) {
|
|
|
541
534
|
file_count: num("totalFileCount")
|
|
542
535
|
};
|
|
543
536
|
}
|
|
537
|
+
// src/milky/api.ts
|
|
538
|
+
var MilkyApi = class {
|
|
539
|
+
msgApi;
|
|
540
|
+
groupApi;
|
|
541
|
+
friendApi;
|
|
542
|
+
profileApi;
|
|
543
|
+
profileLikeApi;
|
|
544
|
+
ticketApi;
|
|
545
|
+
webApi;
|
|
546
|
+
groupNotifyApi;
|
|
547
|
+
richMediaApi;
|
|
548
|
+
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
549
|
+
flashTransferApi;
|
|
550
|
+
recentContactApi;
|
|
551
|
+
self;
|
|
552
|
+
groupCache;
|
|
553
|
+
qqVersion;
|
|
554
|
+
implVersion;
|
|
555
|
+
mediaDir;
|
|
556
|
+
/** 动作层可观测出口(缺省静默)。 */
|
|
557
|
+
logger;
|
|
558
|
+
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
559
|
+
seqIndex;
|
|
560
|
+
constructor(opts, seqIndex) {
|
|
561
|
+
this.msgApi = opts.msgApi;
|
|
562
|
+
this.groupApi = opts.groupApi;
|
|
563
|
+
this.friendApi = opts.friendApi;
|
|
564
|
+
this.profileApi = opts.profileApi;
|
|
565
|
+
this.profileLikeApi = opts.profileLikeApi;
|
|
566
|
+
this.ticketApi = opts.ticketApi;
|
|
567
|
+
this.webApi = opts.webApi;
|
|
568
|
+
this.groupNotifyApi = opts.groupNotifyApi;
|
|
569
|
+
this.richMediaApi = opts.richMediaApi;
|
|
570
|
+
this.flashTransferApi = opts.flashTransferApi;
|
|
571
|
+
this.recentContactApi = opts.recentContactApi;
|
|
572
|
+
this.self = opts.self;
|
|
573
|
+
this.groupCache = opts.groupCache;
|
|
574
|
+
this.qqVersion = opts.qqVersion;
|
|
575
|
+
this.implVersion = opts.implVersion;
|
|
576
|
+
this.mediaDir = opts.mediaDir;
|
|
577
|
+
this.logger = opts.logger;
|
|
578
|
+
this.seqIndex = seqIndex;
|
|
579
|
+
}
|
|
580
|
+
/** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
|
|
581
|
+
uinToUid(uins) {
|
|
582
|
+
return this.groupApi.uinToUid(uins);
|
|
583
|
+
}
|
|
584
|
+
/** uid → uin(事件路径 mention 转换)。 */
|
|
585
|
+
uidToUin(uids) {
|
|
586
|
+
return this.groupApi.uidToUin(uids);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* uin(数字)→ uid(群管动作入参转换);转换失败抛 INVALID_PARAM
|
|
590
|
+
* (Milky 入参 user_id 都是 uin,kernel 群管 API 要 uid)。
|
|
591
|
+
*/
|
|
592
|
+
async resolveUidFromUin(uin) {
|
|
593
|
+
const uinStr = String(uin);
|
|
594
|
+
let cause;
|
|
595
|
+
try {
|
|
596
|
+
const uid = (await this.uinToUid([uinStr])).get(uinStr);
|
|
597
|
+
if (uid !== void 0 && uid !== "") return uid;
|
|
598
|
+
} catch (err) {
|
|
599
|
+
cause = err;
|
|
600
|
+
}
|
|
601
|
+
throw kernelError(`用户 ${uinStr} 不存在或 uin→uid 转换失败`, "INVALID_PARAM", cause === void 0 ? void 0 : { cause });
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* message_scene + 数字 ID → NT Peer。
|
|
605
|
+
* group = 群号直作 peerUid;friend/temp = uin → uid(失败退 uin 原样,交 QQ 端判断)。
|
|
606
|
+
*/
|
|
607
|
+
async resolvePeer(scene, id) {
|
|
608
|
+
if (scene === "group") return {
|
|
609
|
+
chatType: ChatType.GROUP,
|
|
610
|
+
peerUid: String(id)
|
|
611
|
+
};
|
|
612
|
+
const uin = String(id);
|
|
613
|
+
let uid;
|
|
614
|
+
try {
|
|
615
|
+
uid = (await this.uinToUid([uin])).get(uin);
|
|
616
|
+
} catch (err) {
|
|
617
|
+
this.logger?.warn({
|
|
618
|
+
uin,
|
|
619
|
+
error: errorMessage(err)
|
|
620
|
+
}, "milky: uin→uid 转换失败,peer 退用 uin 原样");
|
|
621
|
+
}
|
|
622
|
+
return {
|
|
623
|
+
chatType: scene === "friend" ? ChatType.C2C : ChatType.C2C_TEMP,
|
|
624
|
+
peerUid: uid ?? uin
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* seq → msgId(索引优先,未登记扫描近段历史兜底)。
|
|
629
|
+
* 两层都未命中返回 undefined(调用方抛 NOT_FOUND)。
|
|
630
|
+
*/
|
|
631
|
+
async resolveMsgIdBySeq(peer, seq, chatType) {
|
|
632
|
+
const indexed = this.seqIndex.resolveMsgId(chatType, peer.peerUid, seq);
|
|
633
|
+
if (indexed !== void 0) return indexed;
|
|
634
|
+
const hit = (await this.msgApi.fetchMessages(peer, { count: 60 }).catch((err) => {
|
|
635
|
+
this.logger?.debug({
|
|
636
|
+
peer: peer.peerUid,
|
|
637
|
+
seq,
|
|
638
|
+
error: errorMessage(err)
|
|
639
|
+
}, "milky: msgSeq 反查近段历史失败");
|
|
640
|
+
return [];
|
|
641
|
+
})).find((m) => Number(m.msgSeq) === seq);
|
|
642
|
+
if (hit === void 0) return;
|
|
643
|
+
this.seqIndex.record(hit);
|
|
644
|
+
return hit.msgId;
|
|
645
|
+
}
|
|
646
|
+
/** 发送结果回查:msgId → {message_seq, time}(sendMessage 只回 msgId)。 */
|
|
647
|
+
async resolveSentOutput(peer, msgId) {
|
|
648
|
+
const [sent] = await this.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
649
|
+
if (sent === void 0) throw kernelError("发送结果回查失败(msgId 未命中)", "UNKNOWN");
|
|
650
|
+
this.seqIndex.record(sent);
|
|
651
|
+
return {
|
|
652
|
+
message_seq: Number(sent.msgSeq),
|
|
653
|
+
time: toUnixSeconds(sent.msgTime)
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
/** self.uid 必备(nudge 发送的 callerUid;缺配置报 INVALID_PARAM)。 */
|
|
658
|
+
function requireSelfUid(api) {
|
|
659
|
+
const uid = api.self.uid;
|
|
660
|
+
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
661
|
+
return uid;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* 按通知 seq 查找群通知(先非可疑后可疑两屏依序,OB11 set_group_add_request
|
|
665
|
+
* 同路径)。屏序惰性拉取:前一屏命中则不拉后续屏(群通知规范序)。
|
|
666
|
+
* 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
|
|
667
|
+
* 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
|
|
668
|
+
*/
|
|
669
|
+
async function findGroupNotify(api, seq) {
|
|
670
|
+
const screens = [() => api.groupNotifyApi.getSingleScreenNotifies(false, 100), () => api.groupNotifyApi.getSingleScreenNotifies(true, 100)];
|
|
671
|
+
for (const fetchScreen of screens) {
|
|
672
|
+
const hit = (await fetchScreen()).find((item) => item.seq === seq);
|
|
673
|
+
if (hit !== void 0) return hit;
|
|
674
|
+
}
|
|
675
|
+
throw kernelError(`未找到通知 ${seq}(无效或已过期)`, "NOT_FOUND");
|
|
676
|
+
}
|
|
677
|
+
/** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
|
|
678
|
+
async function findBuddyReq(api, initiatorUid) {
|
|
679
|
+
const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
|
|
680
|
+
if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
|
|
681
|
+
return hit;
|
|
682
|
+
}
|
|
544
683
|
// src/milky/action/group-manage.ts
|
|
545
684
|
/**
|
|
546
685
|
* Milky 群管理域动作:send_group_nudge / set_group_name / set_group_member_card /
|
|
@@ -550,10 +689,6 @@ function folderToEntity(info, groupId) {
|
|
|
550
689
|
* 写操作合:成员类操作 user_id(uin) → uid 转换后进 kernel(resolveUidFromUin);
|
|
551
690
|
* 公告 image_uri / 头像 image_uri 落盘后进 kernel。
|
|
552
691
|
*/
|
|
553
|
-
const optStr$1 = z.string().nullable().optional();
|
|
554
|
-
/** NTGroupMemberRole 数值(ADMIN=3 / MEMBER=2,setMemberRole 入参)。 */
|
|
555
|
-
const NTGroupMemberRoleAdmin = 3;
|
|
556
|
-
const NTGroupMemberRoleMember = 2;
|
|
557
692
|
/** 群管理域动作工厂(群设置 / 成员管理 / 公告 / 戳一戳)。 */
|
|
558
693
|
function createGroupManageActions(api) {
|
|
559
694
|
return [
|
|
@@ -568,7 +703,7 @@ function createGroupManageActions(api) {
|
|
|
568
703
|
const peer = await api.resolvePeer("group", payload.group_id);
|
|
569
704
|
await api.msgApi.sendNudge(peer, {
|
|
570
705
|
receiverUid,
|
|
571
|
-
callerUid: requireSelfUid
|
|
706
|
+
callerUid: requireSelfUid(api)
|
|
572
707
|
});
|
|
573
708
|
return {};
|
|
574
709
|
}
|
|
@@ -602,11 +737,11 @@ function createGroupManageActions(api) {
|
|
|
602
737
|
schema: z.object({
|
|
603
738
|
...groupIdField,
|
|
604
739
|
...userIdField,
|
|
605
|
-
is_set: optBool
|
|
740
|
+
is_set: optBool
|
|
606
741
|
}),
|
|
607
742
|
handle: async (payload) => {
|
|
608
743
|
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
609
|
-
api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ?
|
|
744
|
+
api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ? NTGroupMemberRole.MEMBER : NTGroupMemberRole.ADMIN);
|
|
610
745
|
return {};
|
|
611
746
|
}
|
|
612
747
|
}),
|
|
@@ -630,7 +765,7 @@ function createGroupManageActions(api) {
|
|
|
630
765
|
name: "set_group_whole_mute",
|
|
631
766
|
schema: z.object({
|
|
632
767
|
...groupIdField,
|
|
633
|
-
is_mute: optBool
|
|
768
|
+
is_mute: optBool
|
|
634
769
|
}),
|
|
635
770
|
handle: async (payload) => {
|
|
636
771
|
await api.groupApi.setGroupShutUp(String(payload.group_id), payload.is_mute !== false);
|
|
@@ -642,7 +777,7 @@ function createGroupManageActions(api) {
|
|
|
642
777
|
schema: z.object({
|
|
643
778
|
...groupIdField,
|
|
644
779
|
...userIdField,
|
|
645
|
-
reject_add_request: optBool
|
|
780
|
+
reject_add_request: optBool
|
|
646
781
|
}),
|
|
647
782
|
handle: async (payload) => {
|
|
648
783
|
const uid = await api.resolveUidFromUin(payload.user_id);
|
|
@@ -688,7 +823,7 @@ function createGroupManageActions(api) {
|
|
|
688
823
|
schema: z.object({
|
|
689
824
|
...groupIdField,
|
|
690
825
|
content: z.string().min(1),
|
|
691
|
-
image_uri: optStr
|
|
826
|
+
image_uri: optStr
|
|
692
827
|
}),
|
|
693
828
|
handle: async (payload) => {
|
|
694
829
|
const groupCode = String(payload.group_id);
|
|
@@ -711,158 +846,13 @@ function createGroupManageActions(api) {
|
|
|
711
846
|
})
|
|
712
847
|
];
|
|
713
848
|
}
|
|
714
|
-
|
|
715
|
-
function requireSelfUid$1(api) {
|
|
716
|
-
const uid = api.self.uid;
|
|
717
|
-
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
718
|
-
return uid;
|
|
719
|
-
}
|
|
720
|
-
// src/milky/api.ts
|
|
721
|
-
var MilkyApi = class {
|
|
722
|
-
msgApi;
|
|
723
|
-
groupApi;
|
|
724
|
-
friendApi;
|
|
725
|
-
profileApi;
|
|
726
|
-
profileLikeApi;
|
|
727
|
-
ticketApi;
|
|
728
|
-
webApi;
|
|
729
|
-
groupNotifyApi;
|
|
730
|
-
richMediaApi;
|
|
731
|
-
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
732
|
-
flashTransferApi;
|
|
733
|
-
recentContactApi;
|
|
734
|
-
self;
|
|
735
|
-
groupCache;
|
|
736
|
-
qqVersion;
|
|
737
|
-
implVersion;
|
|
738
|
-
mediaDir;
|
|
739
|
-
/** 动作层可观测出口(缺省静默)。 */
|
|
740
|
-
logger;
|
|
741
|
-
/** message_seq ↔ msgId 双向映射(接收链路 record,动作侧反查)。 */
|
|
742
|
-
seqIndex;
|
|
743
|
-
constructor(opts, seqIndex) {
|
|
744
|
-
this.msgApi = opts.msgApi;
|
|
745
|
-
this.groupApi = opts.groupApi;
|
|
746
|
-
this.friendApi = opts.friendApi;
|
|
747
|
-
this.profileApi = opts.profileApi;
|
|
748
|
-
this.profileLikeApi = opts.profileLikeApi;
|
|
749
|
-
this.ticketApi = opts.ticketApi;
|
|
750
|
-
this.webApi = opts.webApi;
|
|
751
|
-
this.groupNotifyApi = opts.groupNotifyApi;
|
|
752
|
-
this.richMediaApi = opts.richMediaApi;
|
|
753
|
-
this.flashTransferApi = opts.flashTransferApi;
|
|
754
|
-
this.recentContactApi = opts.recentContactApi;
|
|
755
|
-
this.self = opts.self;
|
|
756
|
-
this.groupCache = opts.groupCache;
|
|
757
|
-
this.qqVersion = opts.qqVersion;
|
|
758
|
-
this.implVersion = opts.implVersion;
|
|
759
|
-
this.mediaDir = opts.mediaDir;
|
|
760
|
-
this.logger = opts.logger;
|
|
761
|
-
this.seqIndex = seqIndex;
|
|
762
|
-
}
|
|
763
|
-
/** uin → uid(私聊目标 / at 段发送转换 / 群管动作的 uid 入参)。 */
|
|
764
|
-
uinToUid(uins) {
|
|
765
|
-
return this.groupApi.uinToUid(uins);
|
|
766
|
-
}
|
|
767
|
-
/** uid → uin(事件路径 mention 转换)。 */
|
|
768
|
-
uidToUin(uids) {
|
|
769
|
-
return this.groupApi.uidToUin(uids);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* uin(数字)→ uid(群管动作入参转换);转换失败抛 INVALID_PARAM
|
|
773
|
-
* (Milky 入参 user_id 都是 uin,kernel 群管 API 要 uid)。
|
|
774
|
-
*/
|
|
775
|
-
async resolveUidFromUin(uin) {
|
|
776
|
-
const uinStr = String(uin);
|
|
777
|
-
let cause;
|
|
778
|
-
try {
|
|
779
|
-
const uid = (await this.uinToUid([uinStr])).get(uinStr);
|
|
780
|
-
if (uid !== void 0 && uid !== "") return uid;
|
|
781
|
-
} catch (err) {
|
|
782
|
-
cause = err;
|
|
783
|
-
}
|
|
784
|
-
throw kernelError(`用户 ${uinStr} 不存在或 uin→uid 转换失败`, "INVALID_PARAM", cause === void 0 ? void 0 : { cause });
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* message_scene + 数字 ID → NT Peer。
|
|
788
|
-
* group = 群号直作 peerUid;friend/temp = uin → uid(失败退 uin 原样,交 QQ 端判断)。
|
|
789
|
-
*/
|
|
790
|
-
async resolvePeer(scene, id) {
|
|
791
|
-
if (scene === "group") return {
|
|
792
|
-
chatType: ChatType.GROUP,
|
|
793
|
-
peerUid: String(id)
|
|
794
|
-
};
|
|
795
|
-
const uin = String(id);
|
|
796
|
-
let uid;
|
|
797
|
-
try {
|
|
798
|
-
uid = (await this.uinToUid([uin])).get(uin);
|
|
799
|
-
} catch (err) {
|
|
800
|
-
this.logger?.warn({
|
|
801
|
-
uin,
|
|
802
|
-
error: err instanceof Error ? err.message : String(err)
|
|
803
|
-
}, "milky: uin→uid 转换失败,peer 退用 uin 原样");
|
|
804
|
-
}
|
|
805
|
-
return {
|
|
806
|
-
chatType: scene === "friend" ? ChatType.C2C : ChatType.C2C_TEMP,
|
|
807
|
-
peerUid: uid ?? uin
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* seq → msgId(索引优先,未登记扫描近段历史兜底)。
|
|
812
|
-
* 两层都未命中返回 undefined(调用方抛 NOT_FOUND)。
|
|
813
|
-
*/
|
|
814
|
-
async resolveMsgIdBySeq(peer, seq, chatType) {
|
|
815
|
-
const indexed = this.seqIndex.resolveMsgId(chatType, peer.peerUid, seq);
|
|
816
|
-
if (indexed !== void 0) return indexed;
|
|
817
|
-
const hit = (await this.msgApi.fetchMessages(peer, { count: 60 }).catch((err) => {
|
|
818
|
-
this.logger?.debug({
|
|
819
|
-
peer: peer.peerUid,
|
|
820
|
-
seq,
|
|
821
|
-
error: err instanceof Error ? err.message : String(err)
|
|
822
|
-
}, "milky: msgSeq 反查近段历史失败");
|
|
823
|
-
return [];
|
|
824
|
-
})).find((m) => Number(m.msgSeq) === seq);
|
|
825
|
-
if (hit === void 0) return;
|
|
826
|
-
this.seqIndex.record(hit);
|
|
827
|
-
return hit.msgId;
|
|
828
|
-
}
|
|
829
|
-
/** 发送结果回查:msgId → {message_seq, time}(sendMessage 只回 msgId)。 */
|
|
830
|
-
async resolveSentOutput(peer, msgId) {
|
|
831
|
-
const [sent] = await this.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
832
|
-
if (sent === void 0) throw kernelError("发送结果回查失败(msgId 未命中)", "UNKNOWN");
|
|
833
|
-
this.seqIndex.record(sent);
|
|
834
|
-
return {
|
|
835
|
-
message_seq: Number(sent.msgSeq),
|
|
836
|
-
time: toUnixSeconds(sent.msgTime)
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
/** 通知查找默认搜索数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
841
|
-
const NOTIFY_SEARCH_COUNT$1 = 100;
|
|
849
|
+
// src/milky/helper/event/request.ts
|
|
842
850
|
/**
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
* 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
|
|
846
|
-
* 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
|
|
851
|
+
* BuddyReq → friend_request 事件。
|
|
852
|
+
* comment 取验证留言:QQNT 实际字段是 `extWords`,`words` 为旧口径兜底(都缺省空串)。
|
|
847
853
|
*/
|
|
848
|
-
async function findGroupNotify(api, seq) {
|
|
849
|
-
const screens = [() => api.groupNotifyApi.getSingleScreenNotifies(false, NOTIFY_SEARCH_COUNT$1), () => api.groupNotifyApi.getSingleScreenNotifies(true, NOTIFY_SEARCH_COUNT$1)];
|
|
850
|
-
for (const fetchScreen of screens) {
|
|
851
|
-
const hit = (await fetchScreen()).find((item) => item.seq === seq);
|
|
852
|
-
if (hit !== void 0) return hit;
|
|
853
|
-
}
|
|
854
|
-
throw kernelError(`未找到通知 ${seq}(无效或已过期)`, "NOT_FOUND");
|
|
855
|
-
}
|
|
856
|
-
/** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
|
|
857
|
-
async function findBuddyReq(api, initiatorUid) {
|
|
858
|
-
const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
|
|
859
|
-
if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
|
|
860
|
-
return hit;
|
|
861
|
-
}
|
|
862
|
-
// src/milky/helper/event/request.ts
|
|
863
|
-
/** BuddyReq → friend_request 事件(comment 取 words 字段,形状待校准,缺省空串)。 */
|
|
864
854
|
function toFriendRequestEvent(req, ctx) {
|
|
865
|
-
const
|
|
855
|
+
const comment = firstNonEmptyString(stringOrUndefined(req["extWords"]), stringOrUndefined(req["words"])) ?? "";
|
|
866
856
|
return {
|
|
867
857
|
time: Math.floor(Date.now() / MS_TO_SEC),
|
|
868
858
|
self_id: Number(ctx.selfUin),
|
|
@@ -870,7 +860,7 @@ function toFriendRequestEvent(req, ctx) {
|
|
|
870
860
|
data: {
|
|
871
861
|
initiator_id: toUin(req.friendUid, ctx),
|
|
872
862
|
initiator_uid: req.friendUid,
|
|
873
|
-
comment
|
|
863
|
+
comment,
|
|
874
864
|
via: req.sourceName ?? ""
|
|
875
865
|
}
|
|
876
866
|
};
|
|
@@ -931,9 +921,6 @@ function collectNotifyUids(notifies) {
|
|
|
931
921
|
return [...uids];
|
|
932
922
|
}
|
|
933
923
|
// src/milky/action/group-notice.ts
|
|
934
|
-
const optStr = z.string().nullable().optional();
|
|
935
|
-
/** 通知查找数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
|
|
936
|
-
const NOTIFY_SEARCH_COUNT = 100;
|
|
937
924
|
/** get_group_notifications 默认 limit(规范 default 20)。 */
|
|
938
925
|
const NOTIFICATIONS_DEFAULT_LIMIT = 20;
|
|
939
926
|
/** 群通知域动作工厂(通知列表 + 应答四动作)。 */
|
|
@@ -943,14 +930,14 @@ function createGroupNoticeActions(api) {
|
|
|
943
930
|
name: "get_group_notifications",
|
|
944
931
|
schema: z.object({
|
|
945
932
|
start_notification_seq: z.number().int().min(0).nullable().optional(),
|
|
946
|
-
is_filtered: optBool
|
|
933
|
+
is_filtered: optBool,
|
|
947
934
|
limit: z.number().int().min(0).nullable().optional()
|
|
948
935
|
}),
|
|
949
936
|
handle: async (payload) => {
|
|
950
|
-
const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true,
|
|
937
|
+
const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, 100);
|
|
951
938
|
const start = payload.start_notification_seq;
|
|
952
939
|
const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
|
|
953
|
-
const uidToUin = await
|
|
940
|
+
const uidToUin = await collectNotifyUidToUin(api, filtered);
|
|
954
941
|
const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
|
|
955
942
|
const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
|
|
956
943
|
const page = entities.slice(0, limit);
|
|
@@ -988,14 +975,14 @@ const respondRequestSchema = z.object({
|
|
|
988
975
|
notification_seq: z.number().int().min(0),
|
|
989
976
|
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
990
977
|
...groupIdField,
|
|
991
|
-
is_filtered: optBool
|
|
978
|
+
is_filtered: optBool
|
|
992
979
|
});
|
|
993
980
|
/** reject_group_request 入参(reason 无源)。 */
|
|
994
981
|
const rejectRequestSchema = z.object({
|
|
995
982
|
notification_seq: z.number().int().min(0),
|
|
996
983
|
notification_type: z.enum(["join_request", "invited_join_request"]),
|
|
997
984
|
...groupIdField,
|
|
998
|
-
is_filtered: optBool
|
|
985
|
+
is_filtered: optBool,
|
|
999
986
|
reason: optStr
|
|
1000
987
|
});
|
|
1001
988
|
/** accept/reject_group_invitation 入参。 */
|
|
@@ -1010,13 +997,13 @@ async function respondGroupNotify(api, seq, doubt, approve) {
|
|
|
1010
997
|
return {};
|
|
1011
998
|
}
|
|
1012
999
|
/** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
|
|
1013
|
-
async function
|
|
1000
|
+
async function collectNotifyUidToUin(api, notifies) {
|
|
1014
1001
|
const uids = collectNotifyUids(notifies);
|
|
1015
1002
|
if (uids.length === 0) return /* @__PURE__ */ new Map();
|
|
1016
1003
|
return await api.uidToUin(uids).catch((err) => {
|
|
1017
1004
|
api.logger?.warn({
|
|
1018
1005
|
count: uids.length,
|
|
1019
|
-
error:
|
|
1006
|
+
error: errorMessage(err)
|
|
1020
1007
|
}, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
|
|
1021
1008
|
return /* @__PURE__ */ new Map();
|
|
1022
1009
|
});
|
|
@@ -1089,17 +1076,6 @@ function notifyToEntity(notify, isFiltered, uidToUin) {
|
|
|
1089
1076
|
return entity;
|
|
1090
1077
|
}
|
|
1091
1078
|
// src/milky/helper/message/segments.ts
|
|
1092
|
-
/**
|
|
1093
|
-
* Milky 消息段 ↔ canonical 元素转换(纯函数)
|
|
1094
|
-
*
|
|
1095
|
-
* 接收方向:canonical → IncomingSegment(规范 14 种中映射 12 种;market_face /
|
|
1096
|
-
* markdown 无 canonical 对应(MFACE/MARKDOWN 原始元素形状未探测),unknown 一律
|
|
1097
|
-
* 跳过——规范兼容性要求「数组中未知项跳过」)。forward 接收段不经 canonical:
|
|
1098
|
-
* kernel 无 MULTI_FORWARD 分支,adapter 从 RawMessage 提取 resId 后经
|
|
1099
|
-
* incomingForwardSegment + ctx 注入。
|
|
1100
|
-
* 发送方向:OutgoingSegment → canonical(10 种全映射;forward 顶层段不走本转换器,
|
|
1101
|
-
* 由 sendMilkyMessage 分流到组装链——本转换器内 forward 报错只拦截混发/嵌套)。
|
|
1102
|
-
*/
|
|
1103
1079
|
/** uin 字符串 → Milky user_id(非有限正数 = 转换失败)。 */
|
|
1104
1080
|
function toUserId(uin) {
|
|
1105
1081
|
const n = Number(uin);
|
|
@@ -1357,16 +1333,6 @@ function resolveUriToPathPlaceholder(uri) {
|
|
|
1357
1333
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("base64://")) return uri;
|
|
1358
1334
|
return uri;
|
|
1359
1335
|
}
|
|
1360
|
-
/** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
|
|
1361
|
-
const FILE_URI_PREFIX_RE = /^file:\/\//;
|
|
1362
|
-
/** file:// URI → 平台路径(Windows 盘符兼容)。 */
|
|
1363
|
-
function fileUriToPath(uri) {
|
|
1364
|
-
try {
|
|
1365
|
-
return fileURLToPath(uri);
|
|
1366
|
-
} catch {
|
|
1367
|
-
return uri.replace(FILE_URI_PREFIX_RE, "");
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
1336
|
// src/milky/helper/event/translate.ts
|
|
1371
1337
|
/**
|
|
1372
1338
|
* Milky 事件翻译(RawMessage → Milky 事件,纯函数)
|
|
@@ -1542,7 +1508,7 @@ function createMessageQueryActions(api) {
|
|
|
1542
1508
|
};
|
|
1543
1509
|
const msgs = await api.msgApi.fetchForwardMessage(peer, entry.msgId);
|
|
1544
1510
|
for (const m of msgs) api.seqIndex.record(m);
|
|
1545
|
-
const uidToUin = await
|
|
1511
|
+
const uidToUin = await collectAtUidToUin(api, msgs);
|
|
1546
1512
|
const messages = [];
|
|
1547
1513
|
for (const m of msgs) messages.push({
|
|
1548
1514
|
message_seq: Number(m.msgSeq),
|
|
@@ -1564,13 +1530,13 @@ async function translateWithEntities(api, scene, peer, msg) {
|
|
|
1564
1530
|
const [detail, member] = await Promise.all([api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
|
|
1565
1531
|
api.logger?.warn({
|
|
1566
1532
|
group: peer.peerUid,
|
|
1567
|
-
error:
|
|
1533
|
+
error: errorMessage(err)
|
|
1568
1534
|
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
1569
1535
|
}), api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
|
|
1570
1536
|
api.logger?.debug({
|
|
1571
1537
|
group: peer.peerUid,
|
|
1572
1538
|
member: msg.senderUid,
|
|
1573
|
-
error:
|
|
1539
|
+
error: errorMessage(err)
|
|
1574
1540
|
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
1575
1541
|
})]);
|
|
1576
1542
|
ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
|
|
@@ -1594,12 +1560,12 @@ async function loadGroupData(api, groupCode) {
|
|
|
1594
1560
|
const [detail, members] = await Promise.all([api.groupCache.getGroupDetail(groupCode).catch((err) => {
|
|
1595
1561
|
api.logger?.warn({
|
|
1596
1562
|
group: groupCode,
|
|
1597
|
-
error:
|
|
1563
|
+
error: errorMessage(err)
|
|
1598
1564
|
}, "milky: 群详情缓存读取失败,历史翻译退化");
|
|
1599
1565
|
}), api.groupCache.getMembers(groupCode).catch((err) => {
|
|
1600
1566
|
api.logger?.warn({
|
|
1601
1567
|
group: groupCode,
|
|
1602
|
-
error:
|
|
1568
|
+
error: errorMessage(err)
|
|
1603
1569
|
}, "milky: 群成员表缓存读取失败,历史翻译退化");
|
|
1604
1570
|
return [];
|
|
1605
1571
|
})]);
|
|
@@ -1621,14 +1587,14 @@ function translateHistoryMessage(api, msg, peerUid, groupData) {
|
|
|
1621
1587
|
return toMessageReceiveEvent(msg, ctx).data;
|
|
1622
1588
|
}
|
|
1623
1589
|
/** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
|
|
1624
|
-
async function
|
|
1590
|
+
async function collectAtUidToUin(api, msgs) {
|
|
1625
1591
|
const uids = /* @__PURE__ */ new Set();
|
|
1626
1592
|
for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
|
|
1627
1593
|
if (uids.size === 0) return /* @__PURE__ */ new Map();
|
|
1628
1594
|
return await api.uidToUin([...uids]).catch((err) => {
|
|
1629
1595
|
api.logger?.warn({
|
|
1630
1596
|
count: uids.size,
|
|
1631
|
-
error:
|
|
1597
|
+
error: errorMessage(err)
|
|
1632
1598
|
}, "milky: 历史 at uid→uin 失败,mention 段跳过");
|
|
1633
1599
|
return /* @__PURE__ */ new Map();
|
|
1634
1600
|
});
|
|
@@ -1640,7 +1606,7 @@ async function senderNameOf(api, msg) {
|
|
|
1640
1606
|
api.logger?.debug({
|
|
1641
1607
|
group: msg.peerUid,
|
|
1642
1608
|
member: msg.senderUid,
|
|
1643
|
-
error:
|
|
1609
|
+
error: errorMessage(err)
|
|
1644
1610
|
}, "milky: 发送者成员缓存读取失败,退 uin 字符串");
|
|
1645
1611
|
});
|
|
1646
1612
|
const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
|
|
@@ -1823,7 +1789,7 @@ async function recallTempMessages(peer, msgIds, api) {
|
|
|
1823
1789
|
api.logger?.warn({
|
|
1824
1790
|
peer: peer.peerUid,
|
|
1825
1791
|
count: msgIds.length,
|
|
1826
|
-
error:
|
|
1792
|
+
error: errorMessage(e)
|
|
1827
1793
|
}, "milky: forward 临时消息撤回失败(转发已发出)");
|
|
1828
1794
|
}
|
|
1829
1795
|
}
|
|
@@ -1843,7 +1809,7 @@ async function resolveAtUins(atUins, api) {
|
|
|
1843
1809
|
} catch (err) {
|
|
1844
1810
|
api.logger?.warn({
|
|
1845
1811
|
count: atUins.length,
|
|
1846
|
-
error:
|
|
1812
|
+
error: errorMessage(err)
|
|
1847
1813
|
}, "milky: at uin→uid 失败,at 段原样发送");
|
|
1848
1814
|
return;
|
|
1849
1815
|
}
|
|
@@ -1957,8 +1923,6 @@ function createProfileActions(api) {
|
|
|
1957
1923
|
];
|
|
1958
1924
|
}
|
|
1959
1925
|
// src/milky/action/social.ts
|
|
1960
|
-
/** 可选布尔(nudge / pin 入参共用口径)。 */
|
|
1961
|
-
const optBool = z.boolean().nullable().optional();
|
|
1962
1926
|
/** 社交类动作工厂(好友/群列表、赞、删好友、申请处理、戳一戳、会话置顶)。 */
|
|
1963
1927
|
function createSocialActions(api) {
|
|
1964
1928
|
return [
|
|
@@ -2009,7 +1973,7 @@ function createSocialActions(api) {
|
|
|
2009
1973
|
if (reqs.length > 0) uidToUin = await api.uidToUin(reqs.map((req) => req.friendUid)).catch((err) => {
|
|
2010
1974
|
api.logger?.warn({
|
|
2011
1975
|
count: reqs.length,
|
|
2012
|
-
error:
|
|
1976
|
+
error: errorMessage(err)
|
|
2013
1977
|
}, "milky: 好友申请 uid→uin 失败,initiator_id 兜底 0");
|
|
2014
1978
|
return /* @__PURE__ */ new Map();
|
|
2015
1979
|
});
|
|
@@ -2121,12 +2085,6 @@ async function pinnedGroupEntities(api, groupCodes) {
|
|
|
2121
2085
|
return g !== void 0 ? [groupListToEntity(g)] : [];
|
|
2122
2086
|
});
|
|
2123
2087
|
}
|
|
2124
|
-
/** self.uid 必备(nudge 发送的 callerUid)。 */
|
|
2125
|
-
function requireSelfUid(api) {
|
|
2126
|
-
const uid = api.self.uid;
|
|
2127
|
-
if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
|
|
2128
|
-
return uid;
|
|
2129
|
-
}
|
|
2130
2088
|
// src/milky/action/system.ts
|
|
2131
2089
|
/**
|
|
2132
2090
|
* Milky 系统类动作:get_login_info / get_impl_info
|
|
@@ -2185,22 +2143,51 @@ function createMilkyActionRegistry(opts) {
|
|
|
2185
2143
|
return registry;
|
|
2186
2144
|
}
|
|
2187
2145
|
// src/milky/enrichment.ts
|
|
2146
|
+
/** 资料详情兜底的单批上限(好友申请批通常只有个位数,超限多为历史积压)。 */
|
|
2147
|
+
const MAX_PROFILE_LOOKUPS = 10;
|
|
2188
2148
|
/** Milky 收链路异步回填器。 */
|
|
2189
2149
|
var MilkyEnrichment = class {
|
|
2190
2150
|
api;
|
|
2191
2151
|
constructor(deps) {
|
|
2192
2152
|
this.api = deps.api;
|
|
2193
2153
|
}
|
|
2194
|
-
/**
|
|
2195
|
-
|
|
2154
|
+
/**
|
|
2155
|
+
* uid 批量 → uin(空集/失败返回 undefined 语义:调用方用空 Map)。
|
|
2156
|
+
*
|
|
2157
|
+
* `profileFallback` 时才做资料详情兜底(issue #122):好友申请的申请人通常不在
|
|
2158
|
+
* 任何群里,群口径必然命中不了;而 grayTip 一类高频路径不做兜底——群口径整体失败
|
|
2159
|
+
* 时逐 uid 打 IPC 会把收链路拖垮。
|
|
2160
|
+
*/
|
|
2161
|
+
async resolveUidToUin(uids, options = {}) {
|
|
2196
2162
|
const unique = [...new Set(uids.filter((uid) => uid !== ""))];
|
|
2197
|
-
if (unique.length === 0) return
|
|
2198
|
-
|
|
2163
|
+
if (unique.length === 0) return;
|
|
2164
|
+
const map = await this.api.uidToUin(unique).catch((err) => {
|
|
2199
2165
|
this.api.logger?.warn({
|
|
2200
2166
|
count: unique.length,
|
|
2201
|
-
error:
|
|
2167
|
+
error: errorMessage(err)
|
|
2202
2168
|
}, "milky: uid→uin 批量转换失败,事件退用 uid");
|
|
2169
|
+
return /* @__PURE__ */ new Map();
|
|
2203
2170
|
});
|
|
2171
|
+
if (options.profileFallback === true) await this.fillMissingUins(unique, map);
|
|
2172
|
+
return map;
|
|
2173
|
+
}
|
|
2174
|
+
/**
|
|
2175
|
+
* 群口径未命中的 uid 逐个走 `profileApi.getUinByUid` 兜底(原地补 map)。
|
|
2176
|
+
* fail-soft:单条失败 / 查不到保持未命中(翻译层退 0);条数设上限,防历史积压
|
|
2177
|
+
* 批次把逐条 IPC 打满。
|
|
2178
|
+
*/
|
|
2179
|
+
async fillMissingUins(uids, map) {
|
|
2180
|
+
const missing = uids.filter((uid) => !map.has(uid));
|
|
2181
|
+
for (const uid of missing.slice(0, MAX_PROFILE_LOOKUPS)) try {
|
|
2182
|
+
const uin = await this.api.profileApi.getUinByUid(uid);
|
|
2183
|
+
if (uin !== null) map.set(uid, uin);
|
|
2184
|
+
} catch (err) {
|
|
2185
|
+
this.api.logger?.debug({ error: errorMessage(err) }, "milky: uid→uin 资料兜底失败(该 uid 退 0)");
|
|
2186
|
+
}
|
|
2187
|
+
if (missing.length > MAX_PROFILE_LOOKUPS) this.api.logger?.debug({
|
|
2188
|
+
missing: missing.length,
|
|
2189
|
+
limit: MAX_PROFILE_LOOKUPS
|
|
2190
|
+
}, "milky: 待兜底 uid 超上限,其余保持未命中");
|
|
2204
2191
|
}
|
|
2205
2192
|
/** at uid → uin 批量转换(mention.user_id 用;失败 mention 段跳过)。 */
|
|
2206
2193
|
async fillMentionUids(elements, ctx) {
|
|
@@ -2211,7 +2198,7 @@ var MilkyEnrichment = class {
|
|
|
2211
2198
|
} catch (err) {
|
|
2212
2199
|
this.api.logger?.warn({
|
|
2213
2200
|
count: atUids.length,
|
|
2214
|
-
error:
|
|
2201
|
+
error: errorMessage(err)
|
|
2215
2202
|
}, "milky: at uid→uin 失败,mention 段跳过");
|
|
2216
2203
|
}
|
|
2217
2204
|
}
|
|
@@ -2221,13 +2208,13 @@ var MilkyEnrichment = class {
|
|
|
2221
2208
|
const [detail, member] = await Promise.all([this.api.groupCache.getGroupDetail(msg.peerUid).catch((err) => {
|
|
2222
2209
|
this.api.logger?.warn({
|
|
2223
2210
|
group: msg.peerUid,
|
|
2224
|
-
error:
|
|
2211
|
+
error: errorMessage(err)
|
|
2225
2212
|
}, "milky: 群详情缓存读取失败,实体回填退化");
|
|
2226
2213
|
}), this.api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
|
|
2227
2214
|
this.api.logger?.debug({
|
|
2228
2215
|
group: msg.peerUid,
|
|
2229
2216
|
member: msg.senderUid,
|
|
2230
|
-
error:
|
|
2217
|
+
error: errorMessage(err)
|
|
2231
2218
|
}, "milky: 群成员缓存读取失败,实体回填退化");
|
|
2232
2219
|
})]);
|
|
2233
2220
|
ctx.groupEntity = toGroupEntity(detail, msg.peerUid);
|
|
@@ -2248,10 +2235,11 @@ var MilkyEventPipeline = class {
|
|
|
2248
2235
|
/** 订阅 kernel 事件(消息 + 群 + 好友 + ,幂等;路由到 inbound/)。 */
|
|
2249
2236
|
subscribe() {
|
|
2250
2237
|
if (this.unsubscribes.length > 0) return;
|
|
2238
|
+
this.deps.request.markStartup();
|
|
2251
2239
|
const { msgChannel, groupChannel, buddyChannel, recentContactChannel, loginChannel } = this.deps;
|
|
2252
2240
|
this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) => this.deps.message.handle(msg).catch((err) => {
|
|
2253
2241
|
this.logFailure("message_receive", err);
|
|
2254
|
-
})), msgChannel.on("Msg/onRecvSysMsg", (a) => this.deps.sysMsg.handleRawArg(a)), msgChannel.on("Msg/onRecvOfflineFileMsg", (m) => this.deps.fileNotice.fileMessages(m)), msgChannel.on("Msg/onFileMsgCome", (m) => this.deps.fileNotice.fileMessages(m)));
|
|
2242
|
+
}), { logger: this.deps.logger }), msgChannel.on("Msg/onRecvSysMsg", (a) => this.deps.sysMsg.handleRawArg(a)), msgChannel.on("Msg/onRecvOfflineFileMsg", (m) => this.deps.fileNotice.fileMessages(m)), msgChannel.on("Msg/onFileMsgCome", (m) => this.deps.fileNotice.fileMessages(m)));
|
|
2255
2243
|
if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
|
|
2256
2244
|
this.deps.request.groupNotifies(doubt, notifies).catch((err) => {
|
|
2257
2245
|
this.logFailure("group request", err);
|
|
@@ -2732,8 +2720,6 @@ var MilkyInboundMessage = class {
|
|
|
2732
2720
|
* {chatType, peerUin, topFlag(1/0), topFlagTime(秒级 unix 字符串)},与操作
|
|
2733
2721
|
* 一一对应(milky.md §0.8.6)。
|
|
2734
2722
|
*/
|
|
2735
|
-
/** uin 形判别(peer_id 必须是数字串)。 */
|
|
2736
|
-
const NUMERIC_RE$1 = /^\d+$/;
|
|
2737
2723
|
/** 置顶翻转检测(每适配器实例一份,键 = chatType:peerUin——群号与 uin 数值空间可重叠)。 */
|
|
2738
2724
|
var PinWatch = class {
|
|
2739
2725
|
states = /* @__PURE__ */ new Map();
|
|
@@ -2767,7 +2753,7 @@ function toPeerPinChangeData(entry) {
|
|
|
2767
2753
|
const scene = pinScene(entry.chatType);
|
|
2768
2754
|
if (scene === null || entry.topFlag === void 0) return null;
|
|
2769
2755
|
const peerUin = typeof entry.peerUin === "string" && entry.peerUin !== "" ? entry.peerUin : scene === "group" ? entry.peerUid : "";
|
|
2770
|
-
if (peerUin === "" || !NUMERIC_RE
|
|
2756
|
+
if (peerUin === "" || !NUMERIC_RE.test(peerUin)) return null;
|
|
2771
2757
|
return {
|
|
2772
2758
|
data: {
|
|
2773
2759
|
message_scene: scene,
|
|
@@ -2844,9 +2830,17 @@ function secondsOf(raw) {
|
|
|
2844
2830
|
/** Milky 请求域处理器(群通知 / 好友申请的 uid 回填与广播)。 */
|
|
2845
2831
|
var MilkyInboundRequest = class {
|
|
2846
2832
|
deps;
|
|
2833
|
+
/** 已广播申请的 `${friendUid}:${reqTime}`(实例级,跨 reloadTransports 保留)。 */
|
|
2834
|
+
dedup = new BuddyReqDedup();
|
|
2835
|
+
/** 历史积压基准(订阅时刷新:重连后以此刻为界)。 */
|
|
2836
|
+
baselineSec = startupBaselineSec();
|
|
2847
2837
|
constructor(deps) {
|
|
2848
2838
|
this.deps = deps;
|
|
2849
2839
|
}
|
|
2840
|
+
/** 刷新启动基准(pipeline subscribe 时调用)。 */
|
|
2841
|
+
markStartup() {
|
|
2842
|
+
this.baselineSec = startupBaselineSec();
|
|
2843
|
+
}
|
|
2850
2844
|
/** 群通知通道:入群请求 / 成员邀请 / 邀请自身(uid→uin 批量后翻译)。 */
|
|
2851
2845
|
async groupNotifies(doubt, notifies) {
|
|
2852
2846
|
const ctx = await this.requestCtx(collectNotifyUids(notifies));
|
|
@@ -2860,17 +2854,27 @@ var MilkyInboundRequest = class {
|
|
|
2860
2854
|
this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "milky: friend request 翻译失败(整批丢弃)", err));
|
|
2861
2855
|
}
|
|
2862
2856
|
async broadcastBuddyReqs(arg) {
|
|
2857
|
+
if (batchUnreadNums(arg) === 0) {
|
|
2858
|
+
this.deps.logger?.debug({}, "milky: onBuddyReqChange unreadNums=0(整批跳过)");
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2863
2861
|
const reqs = narrowBuddyReqs(arg);
|
|
2864
2862
|
if (reqs === null) {
|
|
2865
2863
|
this.deps.logger?.warn({ raw: sliceRaw(JSON.stringify(arg)) }, "milky: onBuddyReqChange 未知参数形状");
|
|
2866
2864
|
return;
|
|
2867
2865
|
}
|
|
2868
|
-
const
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2866
|
+
const fresh = filterBuddyReqs(reqs, this.baselineSec).filter((req) => this.dedup.claim(req));
|
|
2867
|
+
if (fresh.length < reqs.length) this.deps.logger?.debug({
|
|
2868
|
+
total: reqs.length,
|
|
2869
|
+
kept: fresh.length
|
|
2870
|
+
}, "milky: 好友申请过滤(历史积压 / 已读 / 已处理 / 重复)");
|
|
2871
|
+
if (fresh.length === 0) return;
|
|
2872
|
+
const ctx = await this.requestCtx(fresh.map((req) => req.friendUid));
|
|
2873
|
+
for (const req of fresh) this.deps.broadcast(toFriendRequestEvent(req, ctx));
|
|
2874
|
+
}
|
|
2875
|
+
/** request 翻译上下文(uid→uin 批量转换 + 资料兜底;失败退空 Map)。 */
|
|
2872
2876
|
async requestCtx(uids) {
|
|
2873
|
-
const uidToUin = await this.deps.enrich.resolveUidToUin(uids);
|
|
2877
|
+
const uidToUin = await this.deps.enrich.resolveUidToUin(uids, { profileFallback: true });
|
|
2874
2878
|
return {
|
|
2875
2879
|
selfUin: this.deps.api.self.uin,
|
|
2876
2880
|
...uidToUin !== void 0 ? { uidToUin } : { uidToUin: /* @__PURE__ */ new Map() }
|
|
@@ -2893,8 +2897,6 @@ var MilkyInboundRequest = class {
|
|
|
2893
2897
|
* (remove 走 onGroupEssenceListChange 列表 diff,shared/essence.ts)。
|
|
2894
2898
|
* - 528:349/381/382 多端设备同步族:不广播。
|
|
2895
2899
|
*/
|
|
2896
|
-
/** 数字串判别(faceId 实证为数字字符串)。 */
|
|
2897
|
-
const NUMERIC_RE = /^\d+$/;
|
|
2898
2900
|
/** 732:16 → group_message_reaction。 */
|
|
2899
2901
|
const REACTION_RULE = {
|
|
2900
2902
|
kind: "group_message_reaction",
|
|
@@ -2957,15 +2959,9 @@ const KIND_TABLE = /* @__PURE__ */ new Map([["732:16", REACTION_RULE], ["732:1",
|
|
|
2957
2959
|
};
|
|
2958
2960
|
}
|
|
2959
2961
|
}]]);
|
|
2960
|
-
/** 已观测但未命名的键(多端设备同步族等,不广播只走校准日志)。 */
|
|
2961
|
-
const OBSERVED_UNNAMED = /* @__PURE__ */ new Set([
|
|
2962
|
-
"528:382",
|
|
2963
|
-
"528:349",
|
|
2964
|
-
"528:381"
|
|
2965
|
-
]);
|
|
2966
2962
|
/** (msgType, subType) → 识别结果(绑定 Milky 表;table 参数供单测注入)。 */
|
|
2967
2963
|
function recognizeMilkySysMsg(msgType, subType, table = KIND_TABLE) {
|
|
2968
|
-
return recognizeSysMsg(msgType, subType, table,
|
|
2964
|
+
return recognizeSysMsg(msgType, subType, table, OBSERVED_UNNAMED_SYSMSG_KEYS);
|
|
2969
2965
|
}
|
|
2970
2966
|
// src/milky/inbound/sysmsg.ts
|
|
2971
2967
|
/**
|
|
@@ -3014,6 +3010,19 @@ var MilkyInboundSysMsg = class {
|
|
|
3014
3010
|
}
|
|
3015
3011
|
};
|
|
3016
3012
|
// src/milky/transport.ts
|
|
3013
|
+
/**
|
|
3014
|
+
* Milky 传输装配(单端口 HTTP:POST /api/:api + GET /event SSE + /event WS 升级
|
|
3015
|
+
* + WebHook 主动推送,docs/protocols/milky.md §4)
|
|
3016
|
+
*
|
|
3017
|
+
* - HTTP API:HttpServer onPathRequest 分发 → 动作注册表 → 规范响应信封
|
|
3018
|
+
* (200 ok / 200 failed(-400/-403/自定) / 401 鉴权 / 404 API 不存在(空 body)/
|
|
3019
|
+
* 415 Content-Type)。
|
|
3020
|
+
* - /event:onRawRequest 承接 SSE(createSseResponse,event: milky_event);
|
|
3021
|
+
* onUpgrade 承接同端口 WS 升级(网络原语 下沉 network)。
|
|
3022
|
+
* - WebHook:HttpClient(fire-and-forget POST,Authorization 头带 token)。
|
|
3023
|
+
*
|
|
3024
|
+
* 事件推送统一经 MilkyEventHub(注册到 EventBroadcaster,send → SSE/WS 客户端)。
|
|
3025
|
+
*/
|
|
3017
3026
|
/** /event 路径(规范固定)。 */
|
|
3018
3027
|
const EVENT_PATH = "/event";
|
|
3019
3028
|
/** /api/ 前缀 + 动作名(小写字母开头,小写/数字/下划线)。 */
|
|
@@ -3152,7 +3161,7 @@ function handleMilkyHttpRequest(ctx, req, respond, registry, logger) {
|
|
|
3152
3161
|
}).catch((err) => {
|
|
3153
3162
|
logger?.warn({
|
|
3154
3163
|
path: ctx.path,
|
|
3155
|
-
error:
|
|
3164
|
+
error: errorMessage(err)
|
|
3156
3165
|
}, "milky: 动作分发异常,已回 -500");
|
|
3157
3166
|
respond({
|
|
3158
3167
|
status: "failed",
|
|
@@ -3175,7 +3184,7 @@ function tokenMatches(ctx, token, logger) {
|
|
|
3175
3184
|
} catch (err) {
|
|
3176
3185
|
logger?.debug({
|
|
3177
3186
|
url: ctx.url,
|
|
3178
|
-
error:
|
|
3187
|
+
error: errorMessage(err)
|
|
3179
3188
|
}, "milky: 鉴权 URL 解析失败,按未授权拒绝");
|
|
3180
3189
|
return false;
|
|
3181
3190
|
}
|