@napuketto/adapter 0.15.4 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/core/index.d.mts +8 -3
  3. package/dist/core/index.mjs +1 -1
  4. package/dist/core-D5c78lFV.mjs +144 -0
  5. package/dist/core-D5c78lFV.mjs.map +1 -0
  6. package/dist/{core-DOyFBFOW.mjs → essence-Bxs-aKSC.mjs} +140 -269
  7. package/dist/essence-Bxs-aKSC.mjs.map +1 -0
  8. package/dist/gray-tip-DNo_Mi4E.d.mts +10 -0
  9. package/dist/gray-tip-DNo_Mi4E.d.mts.map +1 -0
  10. package/dist/index-Dhd-kaUF.d.mts +100 -0
  11. package/dist/index-Dhd-kaUF.d.mts.map +1 -0
  12. package/dist/kurobot/index.d.mts +6 -6
  13. package/dist/kurobot/index.d.mts.map +1 -1
  14. package/dist/kurobot/index.mjs +22 -11
  15. package/dist/kurobot/index.mjs.map +1 -1
  16. package/dist/{gray-tip-C0pnbB__.mjs → log-BsInJV_y.mjs} +47 -14
  17. package/dist/log-BsInJV_y.mjs.map +1 -0
  18. package/dist/media-DMMn74TC.mjs +126 -0
  19. package/dist/media-DMMn74TC.mjs.map +1 -0
  20. package/dist/milky/index.d.mts +19 -22
  21. package/dist/milky/index.d.mts.map +1 -1
  22. package/dist/milky/index.mjs +1386 -1507
  23. package/dist/milky/index.mjs.map +1 -1
  24. package/dist/onebot11/index.d.mts +40 -23
  25. package/dist/onebot11/index.d.mts.map +1 -1
  26. package/dist/onebot11/index.mjs +1297 -1920
  27. package/dist/onebot11/index.mjs.map +1 -1
  28. package/dist/{raw-message-D2vA27kj.mjs → raw-message-DE3sdJg8.mjs} +18 -4
  29. package/dist/raw-message-DE3sdJg8.mjs.map +1 -0
  30. package/dist/satori/index.d.mts +28 -38
  31. package/dist/satori/index.d.mts.map +1 -1
  32. package/dist/satori/index.mjs +411 -573
  33. package/dist/satori/index.mjs.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/core-DOyFBFOW.mjs.map +0 -1
  36. package/dist/gray-tip-C0pnbB__.mjs.map +0 -1
  37. package/dist/gray-tip-CcpfI1Og.d.mts +0 -1
  38. package/dist/index-BbHwULNm.d.mts +0 -269
  39. package/dist/index-BbHwULNm.d.mts.map +0 -1
  40. package/dist/log-DYEB3Eto.mjs +0 -176
  41. package/dist/log-DYEB3Eto.mjs.map +0 -1
  42. package/dist/lookup-Dw0W04Ng.mjs +0 -22
  43. package/dist/lookup-Dw0W04Ng.mjs.map +0 -1
  44. package/dist/raw-message-D2vA27kj.mjs.map +0 -1
  45. package/dist/transport-schema-BEzr06W3.mjs +0 -29
  46. package/dist/transport-schema-BEzr06W3.mjs.map +0 -1
@@ -1,17 +1,17 @@
1
- import { C as runAction, S as ActionRegistry, b as BaseProtocolAdapter, c as narrowSysMsgBlobs, d as recognizeSysMsg, f as textOf, h as varintOf, l as nodeAt, m as varintAt, u as processSysMsgBlob } from "../core-DOyFBFOW.mjs";
2
- import { t as findFirstMatch } from "../lookup-Dw0W04Ng.mjs";
3
- import { a as MS_TO_SEC$2, c as toUin, i as hasGrayTip, n as findRevokeElement, o as numericUin, r as firstUntranslatedGrayTip, s as resolveUin, t as collectGrayTipUids } from "../gray-tip-C0pnbB__.mjs";
4
- import { r as subscribeRawMessages, t as forEachRawMessage } from "../raw-message-D2vA27kj.mjs";
5
- import { a as narrowEssenceGroupArg, i as extractEssenceSetSysMsg, o as narrowBuddyReqs, r as EssenceListSync, t as sliceRaw } from "../log-DYEB3Eto.mjs";
1
+ import { i as runAction, n as BaseProtocolAdapter, r as ActionRegistry } from "../core-D5c78lFV.mjs";
2
+ import { i as toUnixSeconds, r as subscribeRawMessages, t as forEachRawMessage } from "../raw-message-DE3sdJg8.mjs";
3
+ import { a as findRevokeElement, c as MS_TO_SEC, d as toUin, i as collectGrayTipUids, l as numericUin, n as sliceRaw, o as firstUntranslatedGrayTip, s as hasGrayTip, t as logEventFailure, u as resolveUin } from "../log-BsInJV_y.mjs";
4
+ import { a as nodeAt, c as textOf, d as narrowBuddyReqs, i as narrowSysMsgBlobs, l as varintAt, n as extractEssenceSetSysMsg, o as processSysMsgBlob, r as narrowEssenceGroupArg, s as recognizeSysMsg, t as EssenceListSync, u as varintOf } from "../essence-Bxs-aKSC.mjs";
6
5
  import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, kernelError, toCanonicalElements } from "@napuketto/kernel";
7
- import { mkdir, rename, writeFile } from "node:fs/promises";
8
- import { join } from "node:path";
9
- import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
10
6
  import { z } from "zod";
11
7
  import { randomUUID } from "node:crypto";
8
+ import { join } from "node:path";
9
+ import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
10
+ import { mkdir, rename, writeFile } from "node:fs/promises";
12
11
  import { fileURLToPath } from "node:url";
13
12
  import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
14
- // src/milky/action/error-map.ts
13
+ // src/milky/action/base-action.ts
14
+ /** KernelErrorCode → Milky retcode 映射表(-400/-403 规范语义,其余取常见 HTTP 语义近似负数)。 */
15
15
  const milkyErrorCodeMap = {
16
16
  SEND_FAILED: -500,
17
17
  PERMISSION_DENIED: -405,
@@ -22,118 +22,271 @@ const milkyErrorCodeMap = {
22
22
  INVALID_STATE: -409,
23
23
  UNKNOWN: -500
24
24
  };
25
- // src/milky/action/base-action.ts
26
25
  /** zod 错误摘要(单行,issues 取前 3 条)。 */
27
26
  function zodSummary(error) {
28
27
  const parts = [];
29
28
  for (const issue of error.issues.slice(0, 3)) parts.push(`${issue.path.map(String).join(".")}: ${issue.message}`);
30
29
  return parts.join("; ");
31
30
  }
32
- var MilkyAction = class {
33
- /** 校验并执行(HTTP /api 入口;WS /event 不承载动作)。 */
34
- async handle(payload) {
35
- const outcome = await runAction({
36
- schema: this.schema,
37
- handle: (parsed) => this._handle(parsed),
38
- errorCodeMap: this.errorCodeMap,
39
- invalidRetcode: -400,
40
- invalidMessage: (error) => `参数解析失败: ${zodSummary(error)}`
41
- }, payload);
42
- return outcome.ok ? {
43
- status: "ok",
44
- retcode: 0,
45
- data: outcome.data,
46
- message: ""
47
- } : {
48
- status: "failed",
49
- retcode: outcome.retcode,
50
- data: null,
51
- message: outcome.message
52
- };
53
- }
54
- };
55
- /**
56
- * 持 MilkyApi 的动作基类:api 注入 + 统一错误映射表(milkyErrorCodeMap)收拢,
57
- * 动作子类只写 name / schema / _handle。
58
- */
59
- var MilkyApiAction = class extends MilkyAction {
60
- errorCodeMap = milkyErrorCodeMap;
61
- api;
62
- constructor(api) {
63
- super();
64
- this.api = api;
65
- }
66
- };
67
- // src/milky/action/group-essence.ts
68
- const groupIdField$4 = { group_id: z.number().int().min(10001) };
69
- const optBool$3 = z.boolean().nullable().optional();
70
- /**
71
- * get_group_essence_messages:获取精华消息列表。
72
- * WebApi.getEssenceMsgList 全量拉取后按 page_index/page_size 客户端分页
73
- * (kernel 无分页参数);message_time 无源取 operation_time 兜底。
74
- */
75
- var GetGroupEssenceMessagesAction = class extends MilkyApiAction {
76
- name = "get_group_essence_messages";
77
- schema = z.object({
78
- ...groupIdField$4,
79
- page_index: z.number().int().min(0),
80
- page_size: z.number().int().min(0)
81
- });
82
- async _handle(payload) {
83
- const items = await this.api.webApi.getEssenceMsgList(String(payload.group_id));
84
- const start = payload.page_index * payload.page_size;
85
- const page = items.slice(start, start + payload.page_size);
86
- return {
87
- messages: page.map((item) => essenceToEntity(item, payload.group_id)),
88
- is_end: start + page.length >= items.length
89
- };
90
- }
91
- };
92
- /** set_group_essence_message:设置/取消精华(seq → msgId 反查)。 */
93
- var SetGroupEssenceMessageAction = class extends MilkyApiAction {
94
- name = "set_group_essence_message";
95
- schema = z.object({
96
- ...groupIdField$4,
97
- message_seq: z.number().int().min(0),
98
- is_set: optBool$3
99
- });
100
- async _handle(payload) {
101
- const groupCode = String(payload.group_id);
102
- const peer = {
103
- chatType: ChatType.GROUP,
104
- peerUid: groupCode
105
- };
106
- const msgId = await this.api.resolveMsgIdBySeq(peer, payload.message_seq, ChatType.GROUP);
107
- if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
108
- if (payload.is_set === false) await this.api.groupApi.removeGroupEssence(groupCode, msgId);
109
- else await this.api.groupApi.addGroupEssence(groupCode, msgId);
110
- return {};
111
- }
112
- };
113
- /** send_group_message_reaction:消息表情表态(reaction_type face→"1" / emoji→"2")。 */
114
- var SendGroupMessageReactionAction = class extends MilkyApiAction {
115
- name = "send_group_message_reaction";
116
- schema = z.object({
117
- ...groupIdField$4,
118
- message_seq: z.number().int().min(0),
119
- reaction: z.string().min(1),
120
- reaction_type: z.enum(["face", "emoji"]).nullable().optional(),
121
- is_add: z.boolean().nullable().optional()
122
- });
123
- async _handle(payload) {
124
- const peer = {
125
- chatType: ChatType.GROUP,
126
- peerUid: String(payload.group_id)
127
- };
128
- await this.api.msgApi.setMsgEmojiLike(peer, {
129
- msgSeq: String(payload.message_seq),
130
- emojiId: payload.reaction,
131
- emojiType: payload.reaction_type === "emoji" ? "2" : "1",
132
- like: payload.is_add !== false
31
+ /** 声明式动作工厂:闭包依赖 + 统一信封与错误映射。 */
32
+ function defineMilkyAction(spec) {
33
+ return {
34
+ name: spec.name,
35
+ schema: spec.schema,
36
+ handle: async (payload) => {
37
+ const outcome = await runAction({
38
+ schema: spec.schema,
39
+ handle: spec.handle,
40
+ errorCodeMap: milkyErrorCodeMap,
41
+ invalidRetcode: -400,
42
+ invalidMessage: (error) => `参数解析失败: ${zodSummary(error)}`
43
+ }, payload);
44
+ return outcome.ok ? {
45
+ status: "ok",
46
+ retcode: 0,
47
+ data: outcome.data,
48
+ message: ""
49
+ } : {
50
+ status: "failed",
51
+ retcode: outcome.retcode,
52
+ data: null,
53
+ message: outcome.message
54
+ };
55
+ }
56
+ };
57
+ }
58
+ // src/milky/helper/message/entities.ts
59
+ /** GroupDetailInfo / Group → GroupEntity(detail 缺失时全兜底)。 */
60
+ function toGroupEntity(detail, groupCode) {
61
+ return {
62
+ group_id: Number(groupCode),
63
+ group_name: detail?.groupName ?? "",
64
+ member_count: detail?.memberNum ?? 0,
65
+ max_member_count: detail?.maxMemberNum ?? 0,
66
+ remark: detail?.remarkName ?? "",
67
+ created_time: detail?.groupCreateTime ?? 0,
68
+ description: "",
69
+ question: "",
70
+ announcement: ""
71
+ };
72
+ }
73
+ /** 群列表项(GroupCache Group)→ GroupEntity。 */
74
+ function groupListToEntity(group) {
75
+ return {
76
+ group_id: Number(group.groupCode),
77
+ group_name: group.groupName,
78
+ member_count: group.memberCount,
79
+ max_member_count: group.maxMember,
80
+ remark: "",
81
+ created_time: 0,
82
+ description: "",
83
+ question: "",
84
+ announcement: ""
85
+ };
86
+ }
87
+ /** GroupMember → GroupMemberEntity(member 缺失时按 uin 兜底最小实体)。 */
88
+ function toGroupMemberEntity(member, groupCode, uin) {
89
+ const shutUpSeconds = member?.shutUpTime ?? 0;
90
+ return {
91
+ user_id: Number(member?.uin !== void 0 && member.uin !== "" ? member.uin : uin),
92
+ nickname: member?.nick ?? "",
93
+ sex: "unknown",
94
+ group_id: Number(groupCode),
95
+ card: member?.cardName ?? "",
96
+ title: member?.memberSpecialTitle ?? "",
97
+ level: 0,
98
+ role: GroupApi.roleToString(member?.role ?? 2),
99
+ join_time: Number(member?.joinTime) || 0,
100
+ last_sent_time: Number(member?.lastSpeakTime) || 0,
101
+ shut_up_end_time: shutUpSeconds > 0 ? Math.floor(Date.now() / 1e3) + shutUpSeconds : null
102
+ };
103
+ }
104
+ /** Friend → FriendEntity(kernel 无 qid/分类挂载,按最小实体兜底)。 */
105
+ function toFriendEntity(friend, uin, nick) {
106
+ return {
107
+ user_id: Number(friend?.uin !== void 0 && friend.uin !== "" ? friend.uin : uin),
108
+ nickname: friend?.nickname ?? nick,
109
+ sex: "unknown",
110
+ qid: "",
111
+ remark: friend?.remark ?? "",
112
+ category: {
113
+ category_id: 0,
114
+ category_name: ""
115
+ }
116
+ };
117
+ }
118
+ // src/milky/action/group-query.ts
119
+ /** 群域共入参(群号 / 成员 uin / 可选布尔;群管理 / 通知 / 精华 / 文件域复用)。 */
120
+ const groupIdField = { group_id: z.number().int().min(10001) };
121
+ const userIdField = { user_id: z.number().int().min(10001) };
122
+ const optBool$1 = z.boolean().nullable().optional();
123
+ /** 群查询域动作工厂(群信息 / 成员列表 / 成员单查 / 公告列表)。 */
124
+ function createGroupQueryActions(api) {
125
+ return [
126
+ defineMilkyAction({
127
+ name: "get_group_info",
128
+ schema: z.object({
129
+ ...groupIdField,
130
+ no_cache: optBool$1
131
+ }),
132
+ handle: async (payload) => {
133
+ const groupCode = String(payload.group_id);
134
+ return { group: toGroupEntity(api.groupCache !== void 0 ? await api.groupCache.getGroupDetail(groupCode) : await api.groupApi.getGroupInfo(groupCode), groupCode) };
135
+ }
136
+ }),
137
+ defineMilkyAction({
138
+ name: "get_group_member_list",
139
+ schema: z.object({
140
+ ...groupIdField,
141
+ no_cache: optBool$1
142
+ }),
143
+ handle: async (payload) => {
144
+ return { members: (await membersOf(api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
145
+ }
146
+ }),
147
+ defineMilkyAction({
148
+ name: "get_group_member_info",
149
+ schema: z.object({
150
+ ...groupIdField,
151
+ ...userIdField,
152
+ no_cache: optBool$1
153
+ }),
154
+ handle: async (payload) => {
155
+ return { member: toGroupMemberEntity(await memberOf(api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
156
+ }
157
+ }),
158
+ defineMilkyAction({
159
+ name: "get_group_announcements",
160
+ schema: z.object({ ...groupIdField }),
161
+ handle: async (payload) => {
162
+ const groupCode = String(payload.group_id);
163
+ const bulletins = await api.groupApi.getGroupAnnouncements(groupCode);
164
+ return { announcements: await Promise.all(bulletins.map((b) => bulletinToEntity(b, payload.group_id, api))) };
165
+ }
166
+ })
167
+ ];
168
+ }
169
+ /** ---------- 内部辅助 ---------- */
170
+ /** 成员列表(GroupCache 优先,未装配直查)。 */
171
+ async function membersOf(api, groupCode) {
172
+ if (api.groupCache !== void 0) return await api.groupCache.getMembers(groupCode);
173
+ return await api.groupApi.getGroupMemberList(groupCode, true);
174
+ }
175
+ /** 成员单查(user_id = uin;缓存路径经 uid,直查路径按 uin 匹配)。 */
176
+ async function memberOf(api, groupId, userId) {
177
+ const groupCode = String(groupId);
178
+ const uin = String(userId);
179
+ if (api.groupCache !== void 0) {
180
+ const uid = await api.resolveUidFromUin(userId).catch((err) => {
181
+ api.logger?.debug({
182
+ group: groupCode,
183
+ uin,
184
+ error: err instanceof Error ? err.message : String(err)
185
+ }, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
186
+ return uin;
133
187
  });
134
- return {};
188
+ const member = await api.groupCache.getMember(groupCode, uid);
189
+ if (member === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
190
+ return member;
135
191
  }
136
- };
192
+ const hit = (await api.groupApi.getGroupMemberList(groupCode, true)).find((m) => m.uin === uin);
193
+ if (hit === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
194
+ return hit;
195
+ }
196
+ /** GroupBulletin → 群公告实体(senderUid → uin 反查;无源字段兜底,待校准)。 */
197
+ async function bulletinToEntity(b, groupId, api) {
198
+ return {
199
+ group_id: groupId,
200
+ announcement_id: b.announcementId ?? "",
201
+ user_id: await senderUinOf(b, api),
202
+ time: Number(b.publishTime) || 0,
203
+ content: b.content ?? "",
204
+ image_url: picUrlOf(b)
205
+ };
206
+ }
207
+ /** 公告发送者 uid → uin(缺省/转换失败 0 兜底)。 */
208
+ async function senderUinOf(b, api) {
209
+ const uid = b.senderUid;
210
+ if (typeof uid !== "string" || uid === "") return 0;
211
+ const uins = await api.uidToUin([uid]).catch((err) => {
212
+ api.logger?.debug({
213
+ uid,
214
+ error: err instanceof Error ? err.message : String(err)
215
+ }, "milky: 公告发送者 uid→uin 失败,兜底 0");
216
+ });
217
+ return Number(uins?.get(uid)) || 0;
218
+ }
219
+ /** 公告图片 url(缺省 null)。 */
220
+ function picUrlOf(b) {
221
+ const url = b.pic?.url;
222
+ return typeof url === "string" && url !== "" ? url : null;
223
+ }
224
+ // src/milky/action/group-essence.ts
225
+ /** 群精华与表态域动作工厂。 */
226
+ function createGroupEssenceActions(api) {
227
+ return [
228
+ defineMilkyAction({
229
+ name: "get_group_essence_messages",
230
+ schema: z.object({
231
+ ...groupIdField,
232
+ page_index: z.number().int().min(0),
233
+ page_size: z.number().int().min(0)
234
+ }),
235
+ handle: async (payload) => {
236
+ const items = await api.webApi.getEssenceMsgList(String(payload.group_id));
237
+ const start = payload.page_index * payload.page_size;
238
+ const page = items.slice(start, start + payload.page_size);
239
+ return {
240
+ messages: page.map((item) => essenceToEntity(item, payload.group_id)),
241
+ is_end: start + page.length >= items.length
242
+ };
243
+ }
244
+ }),
245
+ defineMilkyAction({
246
+ name: "set_group_essence_message",
247
+ schema: z.object({
248
+ ...groupIdField,
249
+ message_seq: z.number().int().min(0),
250
+ is_set: optBool$1
251
+ }),
252
+ handle: async (payload) => {
253
+ const groupCode = String(payload.group_id);
254
+ const peer = {
255
+ chatType: ChatType.GROUP,
256
+ peerUid: groupCode
257
+ };
258
+ const msgId = await api.resolveMsgIdBySeq(peer, payload.message_seq, ChatType.GROUP);
259
+ if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
260
+ if (payload.is_set === false) await api.groupApi.removeGroupEssence(groupCode, msgId);
261
+ else await api.groupApi.addGroupEssence(groupCode, msgId);
262
+ return {};
263
+ }
264
+ }),
265
+ defineMilkyAction({
266
+ name: "send_group_message_reaction",
267
+ schema: z.object({
268
+ ...groupIdField,
269
+ message_seq: z.number().int().min(0),
270
+ reaction: z.string().min(1),
271
+ reaction_type: z.enum(["face", "emoji"]).nullable().optional(),
272
+ is_add: z.boolean().nullable().optional()
273
+ }),
274
+ handle: async (payload) => {
275
+ const peer = {
276
+ chatType: ChatType.GROUP,
277
+ peerUid: String(payload.group_id)
278
+ };
279
+ await api.msgApi.setMsgEmojiLike(peer, {
280
+ msgSeq: String(payload.message_seq),
281
+ emojiId: payload.reaction,
282
+ emojiType: payload.reaction_type === "emoji" ? "2" : "1",
283
+ like: payload.is_add !== false
284
+ });
285
+ return {};
286
+ }
287
+ })
288
+ ];
289
+ }
137
290
  /** ---------- 内部辅助 ---------- */
138
291
  /** 精华项 → GroupEssenceMessage(msg_content 近似翻译:text / image)。 */
139
292
  function essenceToEntity(item, groupId) {
@@ -221,107 +374,142 @@ async function writeBase64(payload, mediaDir) {
221
374
  }
222
375
  }
223
376
  // src/milky/action/group-file.ts
224
- const groupIdField$3 = { group_id: z.number().int().min(10001) };
225
377
  const fileIdField = { file_id: z.string().min(1) };
226
378
  const optStr$2 = z.string().nullable().optional();
227
- /** get_group_files:获取群文件列表(根目录或指定文件夹;过滤 parent 匹配项)。 */
228
- var GetGroupFilesAction = class extends MilkyApiAction {
229
- name = "get_group_files";
230
- schema = z.object({
231
- ...groupIdField$3,
232
- parent_folder_id: optStr$2
233
- });
234
- async _handle(payload) {
235
- const groupCode = String(payload.group_id);
236
- const parent = payload.parent_folder_id ?? "";
237
- const items = await this.api.richMediaApi.getGroupFileList(groupCode, parent);
238
- const files = [];
239
- const folders = [];
240
- for (const item of items) if (item.fileInfo !== void 0) files.push(fileToEntity(item.fileInfo, payload.group_id));
241
- else if (item.folderInfo !== void 0) folders.push(folderToEntity(item.folderInfo, payload.group_id));
242
- return {
243
- files,
244
- folders
245
- };
246
- }
247
- };
248
- /** move_group_file:移动文件(target_folder_id 空 = 移到根目录;parent 入参仅 schema 兼容)。 */
249
- var MoveGroupFileAction = class extends MilkyApiAction {
250
- name = "move_group_file";
251
- schema = z.object({
252
- ...groupIdField$3,
253
- ...fileIdField,
254
- parent_folder_id: optStr$2,
255
- target_folder_id: optStr$2
256
- });
257
- async _handle(payload) {
258
- await this.api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
259
- return {};
260
- }
261
- };
262
- /** rename_group_file:重命名文件。 */
263
- var RenameGroupFileAction = class extends MilkyApiAction {
264
- name = "rename_group_file";
265
- schema = z.object({
266
- ...groupIdField$3,
267
- ...fileIdField,
268
- parent_folder_id: optStr$2,
269
- new_file_name: z.string().min(1)
270
- });
271
- async _handle(payload) {
272
- await this.api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_file_name);
273
- return {};
274
- }
275
- };
276
- /** delete_group_file:删除文件。 */
277
- var DeleteGroupFileAction = class extends MilkyApiAction {
278
- name = "delete_group_file";
279
- schema = z.object({
280
- ...groupIdField$3,
281
- ...fileIdField
282
- });
283
- async _handle(payload) {
284
- await this.api.richMediaApi.deleteGroupFile(String(payload.group_id), [payload.file_id]);
285
- return {};
286
- }
287
- };
288
- /**
289
- * persist_group_file:转存文件(RichMediaApi.transGroupFile,转存语义待对齐)。
290
- */
291
- var PersistGroupFileAction = class extends MilkyApiAction {
292
- name = "persist_group_file";
293
- schema = z.object({
294
- ...groupIdField$3,
295
- ...fileIdField
296
- });
297
- async _handle(payload) {
298
- await this.api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
299
- return {};
300
- }
301
- };
302
- /** create_group_folder:创建文件夹(返回 folder_id)。 */
303
- var CreateGroupFolderAction = class extends MilkyApiAction {
304
- name = "create_group_folder";
305
- schema = z.object({
306
- ...groupIdField$3,
307
- folder_name: z.string().min(1)
308
- });
309
- async _handle(payload) {
310
- return { folder_id: await this.api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
311
- }
312
- };
313
- /** delete_group_folder:删除文件夹。 */
314
- var DeleteGroupFolderAction = class extends MilkyApiAction {
315
- name = "delete_group_folder";
316
- schema = z.object({
317
- ...groupIdField$3,
318
- folder_id: z.string().min(1)
319
- });
320
- async _handle(payload) {
321
- await this.api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
322
- return {};
323
- }
324
- };
379
+ /** 群文件域动作工厂(列表 / 移动 / 重命名 / 删除 / 转存 / 文件夹 / 闪传上传 / 下载链接)。 */
380
+ function createGroupFileActions(api) {
381
+ return [
382
+ defineMilkyAction({
383
+ name: "get_group_files",
384
+ schema: z.object({
385
+ ...groupIdField,
386
+ parent_folder_id: optStr$2
387
+ }),
388
+ handle: async (payload) => {
389
+ const groupCode = String(payload.group_id);
390
+ const parent = payload.parent_folder_id ?? "";
391
+ const items = await api.richMediaApi.getGroupFileList(groupCode, parent);
392
+ const files = [];
393
+ const folders = [];
394
+ for (const item of items) if (item.fileInfo !== void 0) files.push(fileToEntity(item.fileInfo, payload.group_id));
395
+ else if (item.folderInfo !== void 0) folders.push(folderToEntity(item.folderInfo, payload.group_id));
396
+ return {
397
+ files,
398
+ folders
399
+ };
400
+ }
401
+ }),
402
+ defineMilkyAction({
403
+ name: "move_group_file",
404
+ schema: z.object({
405
+ ...groupIdField,
406
+ ...fileIdField,
407
+ parent_folder_id: optStr$2,
408
+ target_folder_id: optStr$2
409
+ }),
410
+ handle: async (payload) => {
411
+ await api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
412
+ return {};
413
+ }
414
+ }),
415
+ defineMilkyAction({
416
+ name: "rename_group_file",
417
+ schema: z.object({
418
+ ...groupIdField,
419
+ ...fileIdField,
420
+ parent_folder_id: optStr$2,
421
+ new_file_name: z.string().min(1)
422
+ }),
423
+ handle: async (payload) => {
424
+ await api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_file_name);
425
+ return {};
426
+ }
427
+ }),
428
+ defineMilkyAction({
429
+ name: "delete_group_file",
430
+ schema: z.object({
431
+ ...groupIdField,
432
+ ...fileIdField
433
+ }),
434
+ handle: async (payload) => {
435
+ await api.richMediaApi.deleteGroupFile(String(payload.group_id), [payload.file_id]);
436
+ return {};
437
+ }
438
+ }),
439
+ defineMilkyAction({
440
+ name: "persist_group_file",
441
+ schema: z.object({
442
+ ...groupIdField,
443
+ ...fileIdField
444
+ }),
445
+ handle: async (payload) => {
446
+ await api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
447
+ return {};
448
+ }
449
+ }),
450
+ defineMilkyAction({
451
+ name: "create_group_folder",
452
+ schema: z.object({
453
+ ...groupIdField,
454
+ folder_name: z.string().min(1)
455
+ }),
456
+ handle: async (payload) => {
457
+ return { folder_id: await api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
458
+ }
459
+ }),
460
+ defineMilkyAction({
461
+ name: "delete_group_folder",
462
+ schema: z.object({
463
+ ...groupIdField,
464
+ folder_id: z.string().min(1)
465
+ }),
466
+ handle: async (payload) => {
467
+ await api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
468
+ return {};
469
+ }
470
+ }),
471
+ defineMilkyAction({
472
+ name: "upload_group_file",
473
+ schema: z.object({
474
+ ...groupIdField,
475
+ parent_folder_id: optStr$2,
476
+ file_uri: z.string().min(1),
477
+ file_name: z.string().min(1)
478
+ }),
479
+ handle: async (payload) => {
480
+ const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
481
+ const peer = {
482
+ chatType: ChatType.GROUP,
483
+ peerUid: String(payload.group_id)
484
+ };
485
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
486
+ }
487
+ }),
488
+ defineMilkyAction({
489
+ name: "get_group_file_download_url",
490
+ schema: z.object({
491
+ ...groupIdField,
492
+ ...fileIdField
493
+ }),
494
+ handle: async (payload) => {
495
+ return { download_url: await api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
496
+ }
497
+ }),
498
+ defineMilkyAction({
499
+ name: "rename_group_folder",
500
+ schema: z.object({
501
+ ...groupIdField,
502
+ folder_id: z.string().min(1),
503
+ new_folder_name: z.string().min(1)
504
+ }),
505
+ handle: async (payload) => {
506
+ await api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
507
+ return {};
508
+ }
509
+ })
510
+ ];
511
+ }
512
+ /** ---------- 内部辅助 ---------- */
325
513
  /** GroupFileItemInfo → GroupFileEntity(fileSize 原生为字符串;无源字段兜底)。 */
326
514
  function fileToEntity(info, groupId) {
327
515
  return {
@@ -353,231 +541,176 @@ function folderToEntity(info, groupId) {
353
541
  file_count: num("totalFileCount")
354
542
  };
355
543
  }
356
- /**
357
- * upload_group_file:上传并投递文件(**闪传通道**:分享链接卡片,见文件头语义说明)。
358
- * file_id 返回闪传文件集 id(非群文件 fileId)。
359
- */
360
- var UploadGroupFileAction = class extends MilkyApiAction {
361
- name = "upload_group_file";
362
- schema = z.object({
363
- ...groupIdField$3,
364
- parent_folder_id: optStr$2,
365
- file_uri: z.string().min(1),
366
- file_name: z.string().min(1)
367
- });
368
- async _handle(payload) {
369
- const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
370
- const peer = {
371
- chatType: ChatType.GROUP,
372
- peerUid: String(payload.group_id)
373
- };
374
- return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
375
- }
376
- };
377
- /** get_group_file_download_url:群文件下载链接(url 字段待实机确认,仅根目录)。 */
378
- var GetGroupFileDownloadUrlAction = class extends MilkyApiAction {
379
- name = "get_group_file_download_url";
380
- schema = z.object({
381
- ...groupIdField$3,
382
- ...fileIdField
383
- });
384
- async _handle(payload) {
385
- return { download_url: await this.api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
386
- }
387
- };
388
- /** rename_group_folder:重命名群文件夹(renameGroupFile 同款形态,待校准)。 */
389
- var RenameGroupFolderAction = class extends MilkyApiAction {
390
- name = "rename_group_folder";
391
- schema = z.object({
392
- ...groupIdField$3,
393
- folder_id: z.string().min(1),
394
- new_folder_name: z.string().min(1)
395
- });
396
- async _handle(payload) {
397
- await this.api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
398
- return {};
399
- }
400
- };
401
544
  // src/milky/action/group-manage.ts
402
545
  /**
403
- * Milky 群管理域动作(2026-11-14 自 group.ts 拆分,结构重构会话 4/5)
404
- *
405
- * 写操作合:群名/名片/管理员/禁言/踢出/退群 + 群头像/专属头衔/公告发布与
406
- * 删除/群戳一戳(P2 批次二)。成员类操作 user_id(uin) → uid 转换后进 kernel
407
- * (resolveUidFromUin);公告 image_uri / 头像 image_uri 落盘后进 kernel。
546
+ * Milky 群管理域动作:send_group_nudge / set_group_name / set_group_member_card /
547
+ * set_group_member_admin / set_group_member_mute / set_group_whole_mute /
548
+ * kick_group_member / quit_group / set_group_avatar /
549
+ * set_group_member_special_title / send_group_announcement / delete_group_announcement。
550
+ * 写操作合:成员类操作 user_id(uin) → uid 转换后进 kernel(resolveUidFromUin);
551
+ * 公告 image_uri / 头像 image_uri 落盘后进 kernel。
408
552
  */
409
- const groupIdField$2 = { group_id: z.number().int().min(10001) };
410
- const userIdField$1 = { user_id: z.number().int().min(10001) };
411
- const optBool$2 = z.boolean().nullable().optional();
412
553
  const optStr$1 = z.string().nullable().optional();
413
554
  /** NTGroupMemberRole 数值(ADMIN=3 / MEMBER=2,setMemberRole 入参)。 */
414
555
  const NTGroupMemberRoleAdmin = 3;
415
556
  const NTGroupMemberRoleMember = 2;
416
- /** send_group_nudge:发送群戳一戳(self.uid 缺失报 INVALID_PARAM)。 */
417
- var SendGroupNudgeAction = class extends MilkyApiAction {
418
- name = "send_group_nudge";
419
- schema = z.object({
420
- ...groupIdField$2,
421
- ...userIdField$1
422
- });
423
- async _handle(payload) {
424
- const receiverUid = await this.api.resolveUidFromUin(payload.user_id);
425
- const peer = await this.api.resolvePeer("group", payload.group_id);
426
- await this.api.msgApi.sendNudge(peer, {
427
- receiverUid,
428
- callerUid: requireSelfUid$1(this.api)
429
- });
430
- return {};
431
- }
432
- };
433
- /** set_group_name:设置群名。 */
434
- var SetGroupNameAction = class extends MilkyApiAction {
435
- name = "set_group_name";
436
- schema = z.object({
437
- ...groupIdField$2,
438
- new_group_name: z.string()
439
- });
440
- async _handle(payload) {
441
- await this.api.groupApi.modifyGroupName(String(payload.group_id), payload.new_group_name);
442
- return {};
443
- }
444
- };
445
- /** set_group_member_card:设置群名片。 */
446
- var SetGroupMemberCardAction = class extends MilkyApiAction {
447
- name = "set_group_member_card";
448
- schema = z.object({
449
- ...groupIdField$2,
450
- ...userIdField$1,
451
- card: z.string()
452
- });
453
- async _handle(payload) {
454
- const uid = await this.api.resolveUidFromUin(payload.user_id);
455
- this.api.groupApi.setMemberCardName(String(payload.group_id), uid, payload.card);
456
- return {};
457
- }
458
- };
459
- /** set_group_member_admin:设置/取消管理员(is_set 缺省 true)。 */
460
- var SetGroupMemberAdminAction = class extends MilkyApiAction {
461
- name = "set_group_member_admin";
462
- schema = z.object({
463
- ...groupIdField$2,
464
- ...userIdField$1,
465
- is_set: optBool$2
466
- });
467
- async _handle(payload) {
468
- const uid = await this.api.resolveUidFromUin(payload.user_id);
469
- this.api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ? NTGroupMemberRoleMember : NTGroupMemberRoleAdmin);
470
- return {};
471
- }
472
- };
473
- /** set_group_member_mute:禁言成员(duration 秒,0 解除)。 */
474
- var SetGroupMemberMuteAction = class extends MilkyApiAction {
475
- name = "set_group_member_mute";
476
- schema = z.object({
477
- ...groupIdField$2,
478
- ...userIdField$1,
479
- duration: z.number().int().min(0).nullable().optional()
480
- });
481
- async _handle(payload) {
482
- const uid = await this.api.resolveUidFromUin(payload.user_id);
483
- await this.api.groupApi.setMemberShutUp(String(payload.group_id), [{
484
- uid,
485
- duration: payload.duration ?? 0
486
- }]);
487
- return {};
488
- }
489
- };
490
- /** set_group_whole_mute:全员禁言开关(is_mute 缺省 true)。 */
491
- var SetGroupWholeMuteAction = class extends MilkyApiAction {
492
- name = "set_group_whole_mute";
493
- schema = z.object({
494
- ...groupIdField$2,
495
- is_mute: optBool$2
496
- });
497
- async _handle(payload) {
498
- await this.api.groupApi.setGroupShutUp(String(payload.group_id), payload.is_mute !== false);
499
- return {};
500
- }
501
- };
502
- /** kick_group_member:移除成员(reject_add_request 默认 false)。 */
503
- var KickGroupMemberAction = class extends MilkyApiAction {
504
- name = "kick_group_member";
505
- schema = z.object({
506
- ...groupIdField$2,
507
- ...userIdField$1,
508
- reject_add_request: optBool$2
509
- });
510
- async _handle(payload) {
511
- const uid = await this.api.resolveUidFromUin(payload.user_id);
512
- await this.api.groupApi.kickMember(String(payload.group_id), [uid], payload.reject_add_request === true);
513
- return {};
514
- }
515
- };
516
- /** quit_group:退出群聊。 */
517
- var QuitGroupAction = class extends MilkyApiAction {
518
- name = "quit_group";
519
- schema = z.object({ ...groupIdField$2 });
520
- async _handle(payload) {
521
- await this.api.groupApi.quitGroup(String(payload.group_id));
522
- return {};
523
- }
524
- };
525
- /** set_group_avatar:设置群头像(image_uri → 本地路径)。 */
526
- var SetGroupAvatarAction = class extends MilkyApiAction {
527
- name = "set_group_avatar";
528
- schema = z.object({
529
- ...groupIdField$2,
530
- image_uri: z.string().min(1)
531
- });
532
- async _handle(payload) {
533
- const imagePath = await resolveUriToPath(payload.image_uri, this.api.mediaDir);
534
- await this.api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
535
- return {};
536
- }
537
- };
538
- /** set_group_member_special_title:设置专属头衔(uin → uid)。 */
539
- var SetGroupMemberSpecialTitleAction = class extends MilkyApiAction {
540
- name = "set_group_member_special_title";
541
- schema = z.object({
542
- ...groupIdField$2,
543
- ...userIdField$1,
544
- special_title: z.string()
545
- });
546
- async _handle(payload) {
547
- const uid = await this.api.resolveUidFromUin(payload.user_id);
548
- await this.api.groupApi.setMemberSpecialTitle(String(payload.group_id), uid, payload.special_title);
549
- return {};
550
- }
551
- };
552
- /** send_group_announcement:发群公告(image_uri 落盘后经上传+发布两步)。 */
553
- var SendGroupAnnouncementAction = class extends MilkyApiAction {
554
- name = "send_group_announcement";
555
- schema = z.object({
556
- ...groupIdField$2,
557
- content: z.string().min(1),
558
- image_uri: optStr$1
559
- });
560
- async _handle(payload) {
561
- const groupCode = String(payload.group_id);
562
- let imagePath;
563
- if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, this.api.mediaDir);
564
- await this.api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
565
- return {};
566
- }
567
- };
568
- /** delete_group_announcement:删除群公告。 */
569
- var DeleteGroupAnnouncementAction = class extends MilkyApiAction {
570
- name = "delete_group_announcement";
571
- schema = z.object({
572
- ...groupIdField$2,
573
- announcement_id: z.string().min(1)
574
- });
575
- async _handle(payload) {
576
- await this.api.groupApi.deleteGroupAnnouncement(String(payload.group_id), payload.announcement_id);
577
- return {};
578
- }
579
- };
580
- /** ---------- 内部辅助 ---------- */
557
+ /** 群管理域动作工厂(群设置 / 成员管理 / 公告 / 戳一戳)。 */
558
+ function createGroupManageActions(api) {
559
+ return [
560
+ defineMilkyAction({
561
+ name: "send_group_nudge",
562
+ schema: z.object({
563
+ ...groupIdField,
564
+ ...userIdField
565
+ }),
566
+ handle: async (payload) => {
567
+ const receiverUid = await api.resolveUidFromUin(payload.user_id);
568
+ const peer = await api.resolvePeer("group", payload.group_id);
569
+ await api.msgApi.sendNudge(peer, {
570
+ receiverUid,
571
+ callerUid: requireSelfUid$1(api)
572
+ });
573
+ return {};
574
+ }
575
+ }),
576
+ defineMilkyAction({
577
+ name: "set_group_name",
578
+ schema: z.object({
579
+ ...groupIdField,
580
+ new_group_name: z.string()
581
+ }),
582
+ handle: async (payload) => {
583
+ await api.groupApi.modifyGroupName(String(payload.group_id), payload.new_group_name);
584
+ return {};
585
+ }
586
+ }),
587
+ defineMilkyAction({
588
+ name: "set_group_member_card",
589
+ schema: z.object({
590
+ ...groupIdField,
591
+ ...userIdField,
592
+ card: z.string()
593
+ }),
594
+ handle: async (payload) => {
595
+ const uid = await api.resolveUidFromUin(payload.user_id);
596
+ api.groupApi.setMemberCardName(String(payload.group_id), uid, payload.card);
597
+ return {};
598
+ }
599
+ }),
600
+ defineMilkyAction({
601
+ name: "set_group_member_admin",
602
+ schema: z.object({
603
+ ...groupIdField,
604
+ ...userIdField,
605
+ is_set: optBool$1
606
+ }),
607
+ handle: async (payload) => {
608
+ const uid = await api.resolveUidFromUin(payload.user_id);
609
+ api.groupApi.setMemberRole(String(payload.group_id), uid, payload.is_set === false ? NTGroupMemberRoleMember : NTGroupMemberRoleAdmin);
610
+ return {};
611
+ }
612
+ }),
613
+ defineMilkyAction({
614
+ name: "set_group_member_mute",
615
+ schema: z.object({
616
+ ...groupIdField,
617
+ ...userIdField,
618
+ duration: z.number().int().min(0).nullable().optional()
619
+ }),
620
+ handle: async (payload) => {
621
+ const uid = await api.resolveUidFromUin(payload.user_id);
622
+ await api.groupApi.setMemberShutUp(String(payload.group_id), [{
623
+ uid,
624
+ duration: payload.duration ?? 0
625
+ }]);
626
+ return {};
627
+ }
628
+ }),
629
+ defineMilkyAction({
630
+ name: "set_group_whole_mute",
631
+ schema: z.object({
632
+ ...groupIdField,
633
+ is_mute: optBool$1
634
+ }),
635
+ handle: async (payload) => {
636
+ await api.groupApi.setGroupShutUp(String(payload.group_id), payload.is_mute !== false);
637
+ return {};
638
+ }
639
+ }),
640
+ defineMilkyAction({
641
+ name: "kick_group_member",
642
+ schema: z.object({
643
+ ...groupIdField,
644
+ ...userIdField,
645
+ reject_add_request: optBool$1
646
+ }),
647
+ handle: async (payload) => {
648
+ const uid = await api.resolveUidFromUin(payload.user_id);
649
+ await api.groupApi.kickMember(String(payload.group_id), [uid], payload.reject_add_request === true);
650
+ return {};
651
+ }
652
+ }),
653
+ defineMilkyAction({
654
+ name: "quit_group",
655
+ schema: z.object({ ...groupIdField }),
656
+ handle: async (payload) => {
657
+ await api.groupApi.quitGroup(String(payload.group_id));
658
+ return {};
659
+ }
660
+ }),
661
+ defineMilkyAction({
662
+ name: "set_group_avatar",
663
+ schema: z.object({
664
+ ...groupIdField,
665
+ image_uri: z.string().min(1)
666
+ }),
667
+ handle: async (payload) => {
668
+ const imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
669
+ await api.groupApi.setGroupAvatar(String(payload.group_id), imagePath);
670
+ return {};
671
+ }
672
+ }),
673
+ defineMilkyAction({
674
+ name: "set_group_member_special_title",
675
+ schema: z.object({
676
+ ...groupIdField,
677
+ ...userIdField,
678
+ special_title: z.string()
679
+ }),
680
+ handle: async (payload) => {
681
+ const uid = await api.resolveUidFromUin(payload.user_id);
682
+ await api.groupApi.setMemberSpecialTitle(String(payload.group_id), uid, payload.special_title);
683
+ return {};
684
+ }
685
+ }),
686
+ defineMilkyAction({
687
+ name: "send_group_announcement",
688
+ schema: z.object({
689
+ ...groupIdField,
690
+ content: z.string().min(1),
691
+ image_uri: optStr$1
692
+ }),
693
+ handle: async (payload) => {
694
+ const groupCode = String(payload.group_id);
695
+ let imagePath;
696
+ if (payload.image_uri !== void 0 && payload.image_uri !== null && payload.image_uri !== "") imagePath = await resolveUriToPath(payload.image_uri, api.mediaDir);
697
+ await api.groupApi.publishGroupAnnouncement(groupCode, payload.content, imagePath);
698
+ return {};
699
+ }
700
+ }),
701
+ defineMilkyAction({
702
+ name: "delete_group_announcement",
703
+ schema: z.object({
704
+ ...groupIdField,
705
+ announcement_id: z.string().min(1)
706
+ }),
707
+ handle: async (payload) => {
708
+ await api.groupApi.deleteGroupAnnouncement(String(payload.group_id), payload.announcement_id);
709
+ return {};
710
+ }
711
+ })
712
+ ];
713
+ }
581
714
  /** self.uid 必备(nudge 发送的 callerUid;缺配置报 INVALID_PARAM)。 */
582
715
  function requireSelfUid$1(api) {
583
716
  const uid = api.self.uid;
@@ -700,26 +833,29 @@ var MilkyApi = class {
700
833
  this.seqIndex.record(sent);
701
834
  return {
702
835
  message_seq: Number(sent.msgSeq),
703
- time: Math.floor(Number(sent.msgTime) / 1e3)
836
+ time: toUnixSeconds(sent.msgTime)
704
837
  };
705
838
  }
706
839
  };
707
840
  /** 通知查找默认搜索数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
708
841
  const NOTIFY_SEARCH_COUNT$1 = 100;
709
842
  /**
710
- * 按通知 seq 查找群通知(先非可疑后可疑,OB11 set_group_add_request 同路径;
711
- * 屏序骨架走 core findFirstMatch)。
843
+ * 按通知 seq 查找群通知(先非可疑后可疑两屏依序,OB11 set_group_add_request
844
+ * 同路径)。屏序惰性拉取:前一屏命中则不拉后续屏(群通知规范序)。
712
845
  * 未找到抛 NOT_FOUND(应答动作的 seq 无效或已过期)。
713
846
  * 模块级函数(非类成员):应答动作的公共入口,OB11 同路径。
714
847
  */
715
848
  async function findGroupNotify(api, seq) {
716
- const hit = await findFirstMatch([() => api.groupNotifyApi.getSingleScreenNotifies(false, NOTIFY_SEARCH_COUNT$1), () => api.groupNotifyApi.getSingleScreenNotifies(true, NOTIFY_SEARCH_COUNT$1)], (item) => item.seq === seq);
717
- if (hit === void 0) throw kernelError(`未找到通知 ${seq}(无效或已过期)`, "NOT_FOUND");
718
- return hit;
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");
719
855
  }
720
856
  /** 按发起者 uid 查找好友申请(getBuddyReqList 匹配 friendUid);未找到抛 NOT_FOUND。 */
721
857
  async function findBuddyReq(api, initiatorUid) {
722
- const hit = await findFirstMatch([() => api.friendApi.getBuddyReqList()], (req) => req.friendUid === initiatorUid);
858
+ const hit = (await api.friendApi.getBuddyReqList()).find((req) => req.friendUid === initiatorUid);
723
859
  if (hit === void 0) throw kernelError(`未找到来自 ${initiatorUid} 的好友申请`, "NOT_FOUND");
724
860
  return hit;
725
861
  }
@@ -728,7 +864,7 @@ async function findBuddyReq(api, initiatorUid) {
728
864
  function toFriendRequestEvent(req, ctx) {
729
865
  const words = req["words"];
730
866
  return {
731
- time: Math.floor(Date.now() / MS_TO_SEC$2),
867
+ time: Math.floor(Date.now() / MS_TO_SEC),
732
868
  self_id: Number(ctx.selfUin),
733
869
  event_type: "friend_request",
734
870
  data: {
@@ -744,7 +880,7 @@ function toGroupRequestEvent(notify, doubt, ctx) {
744
880
  if (notify.status !== GroupNotifyMsgStatus.KUNHANDLE) return null;
745
881
  const groupId = Number(notify.group?.groupCode ?? 0);
746
882
  const seq = Number(notify.seq);
747
- const time = Math.floor(Date.now() / MS_TO_SEC$2);
883
+ const time = Math.floor(Date.now() / MS_TO_SEC);
748
884
  const selfId = Number(ctx.selfUin);
749
885
  switch (notify.type) {
750
886
  case GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS: return {
@@ -795,348 +931,166 @@ function collectNotifyUids(notifies) {
795
931
  return [...uids];
796
932
  }
797
933
  // src/milky/action/group-notice.ts
798
- const groupIdField$1 = { group_id: z.number().int().min(10001) };
799
- const optBool$1 = z.boolean().nullable().optional();
800
934
  const optStr = z.string().nullable().optional();
801
- /**
802
- * get_group_notifications:获取群通知列表。
803
- * kernel getSingleScreenNotifies 为单屏快照(无翻页)——start_notification_seq
804
- * 作客户端过滤(取 seq 更小的记录);next = 本页最小 seq(仍有余量时)。
805
- */
806
- var GetGroupNotificationsAction = class extends MilkyApiAction {
807
- name = "get_group_notifications";
808
- schema = z.object({
809
- start_notification_seq: z.number().int().min(0).nullable().optional(),
810
- is_filtered: optBool$1,
811
- limit: z.number().int().min(0).nullable().optional()
812
- });
813
- async _handle(payload) {
814
- const notifies = await this.api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, NOTIFY_SEARCH_COUNT);
815
- const start = payload.start_notification_seq;
816
- const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
817
- const uidToUin = await this.collectUidToUin(filtered);
818
- const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
819
- const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
820
- const page = entities.slice(0, limit);
821
- const minSeq = page.reduce((acc, e) => acc === null ? e.notification_seq : Math.min(acc, e.notification_seq), null);
822
- return {
823
- notifications: page,
824
- next_notification_seq: entities.length > page.length && minSeq !== null ? minSeq : null
825
- };
826
- }
827
- /** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
828
- async collectUidToUin(notifies) {
829
- const uids = collectNotifyUids(notifies);
830
- if (uids.length === 0) return /* @__PURE__ */ new Map();
831
- return await this.api.uidToUin(uids).catch((err) => {
832
- this.api.logger?.warn({
833
- count: uids.length,
834
- error: err instanceof Error ? err.message : String(err)
835
- }, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
836
- return /* @__PURE__ */ new Map();
837
- });
838
- }
839
- };
840
- /** accept/reject 群请求 / 群邀请公共基类:seq → 通知匹配 → handleGroupRequest。 */
841
- var HandleGroupNotifyBase = class extends MilkyApiAction {
842
- async respond(seq, doubt) {
843
- const notify = await findGroupNotify(this.api, String(seq));
844
- await this.api.groupNotifyApi.handleGroupRequest(doubt, notify, this.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE, " ");
845
- return {};
846
- }
847
- };
848
- /** accept_group_request:同意入群请求(notification_type/group_id 仅 schema 校验)。 */
849
- var AcceptGroupRequestAction = class extends HandleGroupNotifyBase {
850
- name = "accept_group_request";
851
- schema = z.object({
852
- notification_seq: z.number().int().min(0),
853
- notification_type: z.enum(["join_request", "invited_join_request"]),
854
- ...groupIdField$1,
855
- is_filtered: optBool$1
856
- });
857
- approve = true;
858
- async _handle(payload) {
859
- return await this.respond(payload.notification_seq, payload.is_filtered === true);
860
- }
861
- };
862
- /** reject_group_request:拒绝入群请求(reason 无源,kernel postscript 占位空格)。 */
863
- var RejectGroupRequestAction = class extends HandleGroupNotifyBase {
864
- name = "reject_group_request";
865
- schema = z.object({
866
- notification_seq: z.number().int().min(0),
867
- notification_type: z.enum(["join_request", "invited_join_request"]),
868
- ...groupIdField$1,
869
- is_filtered: optBool$1,
870
- reason: optStr
871
- });
872
- approve = false;
873
- async _handle(payload) {
874
- return await this.respond(payload.notification_seq, payload.is_filtered === true);
875
- }
876
- };
877
- /** accept_group_invitation:接受入群邀请(按 invitation_seq 匹配)。 */
878
- var AcceptGroupInvitationAction = class extends HandleGroupNotifyBase {
879
- name = "accept_group_invitation";
880
- schema = z.object({
881
- ...groupIdField$1,
882
- invitation_seq: z.number().int().min(0)
883
- });
884
- approve = true;
885
- async _handle(payload) {
886
- return await this.respond(payload.invitation_seq, false);
887
- }
888
- };
889
- /** reject_group_invitation:拒绝入群邀请。 */
890
- var RejectGroupInvitationAction = class extends HandleGroupNotifyBase {
891
- name = "reject_group_invitation";
892
- schema = z.object({
893
- ...groupIdField$1,
894
- invitation_seq: z.number().int().min(0)
895
- });
896
- approve = false;
897
- async _handle(payload) {
898
- return await this.respond(payload.invitation_seq, false);
899
- }
900
- };
901
- /** ---------- 内部辅助 ---------- */
902
935
  /** 通知查找数量(单屏全量,OB11 DEFAULT_COUNT 同值)。 */
903
936
  const NOTIFY_SEARCH_COUNT = 100;
904
937
  /** get_group_notifications 默认 limit(规范 default 20)。 */
905
938
  const NOTIFICATIONS_DEFAULT_LIMIT = 20;
906
- /**
907
- * GroupNotify → GroupNotificationEntity(uidToUin 已由调用方批量转换)。
908
- * 类型→构造器表:7=入群申请 / 5=成员邀请他人 / 8=设管理 / 12,13=取消管理 /
909
- * 9,10=踢出 / 11=退群;1=邀请自身无实体变体(事件层表达),其余 null。
910
- */
911
- const NOTIFY_ENTITY_BUILDERS = {
912
- 7: (n, uinOf) => ({
913
- type: "join_request",
914
- group_id: Number(n.group?.groupCode ?? 0),
915
- notification_seq: Number(n.seq),
916
- is_filtered: false,
917
- initiator_id: uinOf(n.user1?.uid),
918
- state: "pending",
919
- operator_id: null,
920
- comment: n.postscript ?? ""
921
- }),
922
- 5: (n, uinOf) => ({
923
- type: "invited_join_request",
924
- group_id: Number(n.group?.groupCode ?? 0),
925
- notification_seq: Number(n.seq),
926
- initiator_id: uinOf(n.user1?.uid),
927
- target_user_id: uinOf(n.user2?.uid),
928
- state: "pending",
929
- operator_id: null
930
- }),
931
- 8: (n, uinOf) => adminChangeEntity(n, uinOf, true),
932
- 12: (n, uinOf) => adminChangeEntity(n, uinOf, false),
933
- 13: (n, uinOf) => adminChangeEntity(n, uinOf, false),
934
- 9: (n, uinOf) => kickEntity(n, uinOf),
935
- 10: (n, uinOf) => kickEntity(n, uinOf),
936
- 11: (n, uinOf) => ({
937
- type: "quit",
938
- group_id: Number(n.group?.groupCode ?? 0),
939
- notification_seq: Number(n.seq),
940
- target_user_id: uinOf(n.user1?.uid)
941
- })
942
- };
943
- /** admin_change 实体(8/12/13 共用)。 */
944
- function adminChangeEntity(n, uinOf, isSet) {
945
- return {
946
- type: "admin_change",
947
- group_id: Number(n.group?.groupCode ?? 0),
948
- notification_seq: Number(n.seq),
949
- target_user_id: uinOf(n.user1?.uid),
950
- is_set: isSet,
951
- operator_id: uinOf(n.user2?.uid)
952
- };
953
- }
954
- /** kick 实体(9/10 共用)。 */
955
- function kickEntity(n, uinOf) {
956
- return {
957
- type: "kick",
958
- group_id: Number(n.group?.groupCode ?? 0),
959
- notification_seq: Number(n.seq),
960
- target_user_id: uinOf(n.user1?.uid),
961
- operator_id: uinOf(n.user2?.uid)
962
- };
963
- }
964
- /** GroupNotify → 实体(isFiltered 透传给 join_request;未识别类型 null)。 */
965
- function notifyToEntity(notify, isFiltered, uidToUin) {
966
- const uinOf = (uid) => uid === void 0 || uid === "" ? 0 : Number(uidToUin.get(uid) ?? 0) || 0;
967
- const builder = NOTIFY_ENTITY_BUILDERS[notify.type];
968
- if (builder === void 0) return null;
969
- const entity = builder(notify, uinOf);
970
- if (entity.type === "join_request") entity.is_filtered = isFiltered;
971
- return entity;
972
- }
973
- // src/milky/helper/message/entities.ts
974
- /** GroupDetailInfo / Group → GroupEntity(detail 缺失时全兜底)。 */
975
- function toGroupEntity(detail, groupCode) {
976
- return {
977
- group_id: Number(groupCode),
978
- group_name: detail?.groupName ?? "",
979
- member_count: detail?.memberNum ?? 0,
980
- max_member_count: detail?.maxMemberNum ?? 0,
981
- remark: detail?.remarkName ?? "",
982
- created_time: detail?.groupCreateTime ?? 0,
983
- description: "",
984
- question: "",
985
- announcement: ""
986
- };
987
- }
988
- /** 群列表项(GroupCache Group)→ GroupEntity。 */
989
- function groupListToEntity(group) {
990
- return {
991
- group_id: Number(group.groupCode),
992
- group_name: group.groupName,
993
- member_count: group.memberCount,
994
- max_member_count: group.maxMember,
995
- remark: "",
996
- created_time: 0,
997
- description: "",
998
- question: "",
999
- announcement: ""
1000
- };
1001
- }
1002
- /** GroupMember → GroupMemberEntity(member 缺失时按 uin 兜底最小实体)。 */
1003
- function toGroupMemberEntity(member, groupCode, uin) {
1004
- const shutUpSeconds = member?.shutUpTime ?? 0;
1005
- return {
1006
- user_id: Number(member?.uin !== void 0 && member.uin !== "" ? member.uin : uin),
1007
- nickname: member?.nick ?? "",
1008
- sex: "unknown",
1009
- group_id: Number(groupCode),
1010
- card: member?.cardName ?? "",
1011
- title: member?.memberSpecialTitle ?? "",
1012
- level: 0,
1013
- role: GroupApi.roleToString(member?.role ?? 2),
1014
- join_time: Number(member?.joinTime) || 0,
1015
- last_sent_time: Number(member?.lastSpeakTime) || 0,
1016
- shut_up_end_time: shutUpSeconds > 0 ? Math.floor(Date.now() / 1e3) + shutUpSeconds : null
1017
- };
1018
- }
1019
- /** Friend → FriendEntity(kernel 无 qid/分类挂载,按最小实体兜底)。 */
1020
- function toFriendEntity(friend, uin, nick) {
1021
- return {
1022
- user_id: Number(friend?.uin !== void 0 && friend.uin !== "" ? friend.uin : uin),
1023
- nickname: friend?.nickname ?? nick,
1024
- sex: "unknown",
1025
- qid: "",
1026
- remark: friend?.remark ?? "",
1027
- category: {
1028
- category_id: 0,
1029
- category_name: ""
1030
- }
1031
- };
1032
- }
1033
- // src/milky/action/group-query.ts
1034
- const groupIdField = { group_id: z.number().int().min(10001) };
1035
- const userIdField = { user_id: z.number().int().min(10001) };
1036
- const optBool = z.boolean().nullable().optional();
1037
- /** get_group_info:获取群信息(GroupCache 详情缓存优先)。 */
1038
- var GetGroupInfoAction = class extends MilkyApiAction {
1039
- name = "get_group_info";
1040
- schema = z.object({
1041
- ...groupIdField,
1042
- no_cache: optBool
1043
- });
1044
- async _handle(payload) {
1045
- const groupCode = String(payload.group_id);
1046
- return { group: toGroupEntity(this.api.groupCache !== void 0 ? await this.api.groupCache.getGroupDetail(groupCode) : await this.api.groupApi.getGroupInfo(groupCode), groupCode) };
1047
- }
1048
- };
1049
- /** get_group_member_list:获取群成员列表(GroupCache 惰性回填)。 */
1050
- var GetGroupMemberListAction = class extends MilkyApiAction {
1051
- name = "get_group_member_list";
1052
- schema = z.object({
1053
- ...groupIdField,
1054
- no_cache: optBool
1055
- });
1056
- async _handle(payload) {
1057
- return { members: (await membersOf(this.api, String(payload.group_id))).map((m) => toGroupMemberEntity(m, String(payload.group_id), m.uin)) };
1058
- }
1059
- };
1060
- /** get_group_member_info:获取群成员信息(user_id = uin → 成员单查)。 */
1061
- var GetGroupMemberInfoAction = class extends MilkyApiAction {
1062
- name = "get_group_member_info";
1063
- schema = z.object({
1064
- ...groupIdField,
1065
- ...userIdField,
1066
- no_cache: optBool
1067
- });
1068
- async _handle(payload) {
1069
- return { member: toGroupMemberEntity(await memberOf(this.api, payload.group_id, payload.user_id), String(payload.group_id), String(payload.user_id)) };
1070
- }
1071
- };
1072
- /** get_group_announcements:获取群公告列表(bulletin 形状待校准,宽松映射)。 */
1073
- var GetGroupAnnouncementsAction = class extends MilkyApiAction {
1074
- name = "get_group_announcements";
1075
- schema = z.object({ ...groupIdField });
1076
- async _handle(payload) {
1077
- const groupCode = String(payload.group_id);
1078
- const bulletins = await this.api.groupApi.getGroupAnnouncements(groupCode);
1079
- return { announcements: await Promise.all(bulletins.map((b) => bulletinToEntity(b, payload.group_id, this.api))) };
1080
- }
1081
- };
1082
- /** ---------- 内部辅助 ---------- */
1083
- /** 成员列表(GroupCache 优先,未装配直查)。 */
1084
- async function membersOf(api, groupCode) {
1085
- if (api.groupCache !== void 0) return await api.groupCache.getMembers(groupCode);
1086
- return await api.groupApi.getGroupMemberList(groupCode, true);
1087
- }
1088
- /** 成员单查(user_id = uin;缓存路径经 uid,直查路径按 uin 匹配)。 */
1089
- async function memberOf(api, groupId, userId) {
1090
- const groupCode = String(groupId);
1091
- const uin = String(userId);
1092
- if (api.groupCache !== void 0) {
1093
- const uid = await api.resolveUidFromUin(userId).catch((err) => {
1094
- api.logger?.debug({
1095
- group: groupCode,
1096
- uin,
1097
- error: err instanceof Error ? err.message : String(err)
1098
- }, "milky: 成员 uin→uid 失败,退用 uin 查缓存");
1099
- return uin;
1100
- });
1101
- const member = await api.groupCache.getMember(groupCode, uid);
1102
- if (member === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
1103
- return member;
1104
- }
1105
- const hit = (await api.groupApi.getGroupMemberList(groupCode, true)).find((m) => m.uin === uin);
1106
- if (hit === void 0) throw kernelError(`成员 ${uin} 不在群 ${groupCode}`, "NOT_FOUND");
1107
- return hit;
939
+ /** 群通知域动作工厂(通知列表 + 应答四动作)。 */
940
+ function createGroupNoticeActions(api) {
941
+ return [
942
+ defineMilkyAction({
943
+ name: "get_group_notifications",
944
+ schema: z.object({
945
+ start_notification_seq: z.number().int().min(0).nullable().optional(),
946
+ is_filtered: optBool$1,
947
+ limit: z.number().int().min(0).nullable().optional()
948
+ }),
949
+ handle: async (payload) => {
950
+ const notifies = await api.groupNotifyApi.getSingleScreenNotifies(payload.is_filtered === true, NOTIFY_SEARCH_COUNT);
951
+ const start = payload.start_notification_seq;
952
+ const filtered = notifies.filter((n) => start === void 0 || start === null || Number(n.seq) < start);
953
+ const uidToUin = await collectUidToUin$1(api, filtered);
954
+ const entities = filtered.map((n) => notifyToEntity(n, payload.is_filtered === true, uidToUin)).filter((e) => e !== null);
955
+ const limit = payload.limit ?? NOTIFICATIONS_DEFAULT_LIMIT;
956
+ const page = entities.slice(0, limit);
957
+ const minSeq = page.reduce((acc, e) => acc === null ? e.notification_seq : Math.min(acc, e.notification_seq), null);
958
+ return {
959
+ notifications: page,
960
+ next_notification_seq: entities.length > page.length && minSeq !== null ? minSeq : null
961
+ };
962
+ }
963
+ }),
964
+ defineMilkyAction({
965
+ name: "accept_group_request",
966
+ schema: respondRequestSchema,
967
+ handle: async (payload) => respondGroupNotify(api, payload.notification_seq, payload.is_filtered === true, true)
968
+ }),
969
+ defineMilkyAction({
970
+ name: "reject_group_request",
971
+ schema: rejectRequestSchema,
972
+ handle: async (payload) => respondGroupNotify(api, payload.notification_seq, payload.is_filtered === true, false)
973
+ }),
974
+ defineMilkyAction({
975
+ name: "accept_group_invitation",
976
+ schema: invitationSchema,
977
+ handle: async (payload) => respondGroupNotify(api, payload.invitation_seq, false, true)
978
+ }),
979
+ defineMilkyAction({
980
+ name: "reject_group_invitation",
981
+ schema: invitationSchema,
982
+ handle: async (payload) => respondGroupNotify(api, payload.invitation_seq, false, false)
983
+ })
984
+ ];
985
+ }
986
+ /** accept_group_request 入参(notification_type 仅 schema 校验)。 */
987
+ const respondRequestSchema = z.object({
988
+ notification_seq: z.number().int().min(0),
989
+ notification_type: z.enum(["join_request", "invited_join_request"]),
990
+ ...groupIdField,
991
+ is_filtered: optBool$1
992
+ });
993
+ /** reject_group_request 入参(reason 无源)。 */
994
+ const rejectRequestSchema = z.object({
995
+ notification_seq: z.number().int().min(0),
996
+ notification_type: z.enum(["join_request", "invited_join_request"]),
997
+ ...groupIdField,
998
+ is_filtered: optBool$1,
999
+ reason: optStr
1000
+ });
1001
+ /** accept/reject_group_invitation 入参。 */
1002
+ const invitationSchema = z.object({
1003
+ ...groupIdField,
1004
+ invitation_seq: z.number().int().min(0)
1005
+ });
1006
+ /** 应答公共路径:seq → 通知匹配 → handleGroupRequest。 */
1007
+ async function respondGroupNotify(api, seq, doubt, approve) {
1008
+ const notify = await findGroupNotify(api, String(seq));
1009
+ await api.groupNotifyApi.handleGroupRequest(doubt, notify, approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE, " ");
1010
+ return {};
1011
+ }
1012
+ /** 通知 user1/user2 uid → uin 批量转换(失败退空 Map,实体 id 兜底 0)。 */
1013
+ async function collectUidToUin$1(api, notifies) {
1014
+ const uids = collectNotifyUids(notifies);
1015
+ if (uids.length === 0) return /* @__PURE__ */ new Map();
1016
+ return await api.uidToUin(uids).catch((err) => {
1017
+ api.logger?.warn({
1018
+ count: uids.length,
1019
+ error: err instanceof Error ? err.message : String(err)
1020
+ }, "milky: 通知 uid→uin 失败,实体 id 兜底 0");
1021
+ return /* @__PURE__ */ new Map();
1022
+ });
1108
1023
  }
1109
- /** GroupBulletin → 群公告实体(senderUid → uin 反查;无源字段兜底,待校准)。 */
1110
- async function bulletinToEntity(b, groupId, api) {
1024
+ /**
1025
+ * GroupNotify → GroupNotificationEntity(uidToUin 已由调用方批量转换)。
1026
+ * 类型→构造器表:7=入群申请 / 5=成员邀请他人 / 8=设管理 / 12,13=取消管理 /
1027
+ * 9,10=踢出 / 11=退群;1=邀请自身无实体变体(事件层表达),其余 null。
1028
+ */
1029
+ const NOTIFY_ENTITY_BUILDERS = {
1030
+ 7: (n, uinOf) => ({
1031
+ type: "join_request",
1032
+ group_id: Number(n.group?.groupCode ?? 0),
1033
+ notification_seq: Number(n.seq),
1034
+ is_filtered: false,
1035
+ initiator_id: uinOf(n.user1?.uid),
1036
+ state: "pending",
1037
+ operator_id: null,
1038
+ comment: n.postscript ?? ""
1039
+ }),
1040
+ 5: (n, uinOf) => ({
1041
+ type: "invited_join_request",
1042
+ group_id: Number(n.group?.groupCode ?? 0),
1043
+ notification_seq: Number(n.seq),
1044
+ initiator_id: uinOf(n.user1?.uid),
1045
+ target_user_id: uinOf(n.user2?.uid),
1046
+ state: "pending",
1047
+ operator_id: null
1048
+ }),
1049
+ 8: (n, uinOf) => adminChangeEntity(n, uinOf, true),
1050
+ 12: (n, uinOf) => adminChangeEntity(n, uinOf, false),
1051
+ 13: (n, uinOf) => adminChangeEntity(n, uinOf, false),
1052
+ 9: (n, uinOf) => kickEntity(n, uinOf),
1053
+ 10: (n, uinOf) => kickEntity(n, uinOf),
1054
+ 11: (n, uinOf) => ({
1055
+ type: "quit",
1056
+ group_id: Number(n.group?.groupCode ?? 0),
1057
+ notification_seq: Number(n.seq),
1058
+ target_user_id: uinOf(n.user1?.uid)
1059
+ })
1060
+ };
1061
+ /** admin_change 实体(8/12/13 共用)。 */
1062
+ function adminChangeEntity(n, uinOf, isSet) {
1111
1063
  return {
1112
- group_id: groupId,
1113
- announcement_id: b.announcementId ?? "",
1114
- user_id: await senderUinOf(b, api),
1115
- time: Number(b.publishTime) || 0,
1116
- content: b.content ?? "",
1117
- image_url: picUrlOf(b)
1064
+ type: "admin_change",
1065
+ group_id: Number(n.group?.groupCode ?? 0),
1066
+ notification_seq: Number(n.seq),
1067
+ target_user_id: uinOf(n.user1?.uid),
1068
+ is_set: isSet,
1069
+ operator_id: uinOf(n.user2?.uid)
1118
1070
  };
1119
1071
  }
1120
- /** 公告发送者 uid → uin(缺省/转换失败 0 兜底)。 */
1121
- async function senderUinOf(b, api) {
1122
- const uid = b.senderUid;
1123
- if (typeof uid !== "string" || uid === "") return 0;
1124
- const uins = await api.uidToUin([uid]).catch((err) => {
1125
- api.logger?.debug({
1126
- uid,
1127
- error: err instanceof Error ? err.message : String(err)
1128
- }, "milky: 公告发送者 uid→uin 失败,兜底 0");
1129
- });
1130
- return Number(uins?.get(uid)) || 0;
1072
+ /** kick 实体(9/10 共用)。 */
1073
+ function kickEntity(n, uinOf) {
1074
+ return {
1075
+ type: "kick",
1076
+ group_id: Number(n.group?.groupCode ?? 0),
1077
+ notification_seq: Number(n.seq),
1078
+ target_user_id: uinOf(n.user1?.uid),
1079
+ operator_id: uinOf(n.user2?.uid)
1080
+ };
1131
1081
  }
1132
- /** 公告图片 url(缺省 null)。 */
1133
- function picUrlOf(b) {
1134
- const url = b.pic?.url;
1135
- return typeof url === "string" && url !== "" ? url : null;
1082
+ /** GroupNotify → 实体(isFiltered 透传给 join_request;未识别类型 null)。 */
1083
+ function notifyToEntity(notify, isFiltered, uidToUin) {
1084
+ const uinOf = (uid) => uid === void 0 || uid === "" ? 0 : Number(uidToUin.get(uid) ?? 0) || 0;
1085
+ const builder = NOTIFY_ENTITY_BUILDERS[notify.type];
1086
+ if (builder === void 0) return null;
1087
+ const entity = builder(notify, uinOf);
1088
+ if (entity.type === "join_request") entity.is_filtered = isFiltered;
1089
+ return entity;
1136
1090
  }
1137
1091
  // src/milky/helper/message/segments.ts
1138
1092
  /**
1139
- * Milky 消息段 ↔ canonical 元素转换(纯函数,ADR-008)
1093
+ * Milky 消息段 ↔ canonical 元素转换(纯函数)
1140
1094
  *
1141
1095
  * 接收方向:canonical → IncomingSegment(规范 14 种中映射 12 种;market_face /
1142
1096
  * markdown 无 canonical 对应(MFACE/MARKDOWN 原始元素形状未探测),unknown 一律
@@ -1278,7 +1232,7 @@ function fileToIncoming(el) {
1278
1232
  };
1279
1233
  }
1280
1234
  /**
1281
- * 合并转发 → forward 段(P1)。
1235
+ * 合并转发 → forward 段。
1282
1236
  * 接收方向 canonical 不承载 MULTI_FORWARD(kernel toCanonicalElement 无此分支),
1283
1237
  * 由 adapter 从 RawMessage 提取 resId 后调用本函数经 ctx 注入(翻译保持纯函数)。
1284
1238
  * title 取 NT fileName(转发卡片标题语义)。
@@ -1319,7 +1273,7 @@ function rawToPayload(raw) {
1319
1273
  * OutgoingSegment 数组 → canonical 元素(同步映射;媒体 URI 解析与 at uin→uid
1320
1274
  * 由调用方在返回值上继续处理)。
1321
1275
  * forward 在此报错:顶层 forward 已由 sendMilkyMessage 分流到组装链(message.ts,
1322
- * P2 批次一),命中本分支 = forward 与其他段混发漏网或嵌套 forward(组装链内逐项
1276
+ *),命中本分支 = forward 与其他段混发漏网或嵌套 forward(组装链内逐项
1323
1277
  * 转换经过此处)——均显式拒绝。
1324
1278
  */
1325
1279
  function outgoingSegmentsToCanonical(segments) {
@@ -1415,15 +1369,13 @@ function fileUriToPath(uri) {
1415
1369
  }
1416
1370
  // src/milky/helper/event/translate.ts
1417
1371
  /**
1418
- * Milky 事件翻译(RawMessage → Milky 事件,纯函数,ADR-008)
1372
+ * Milky 事件翻译(RawMessage → Milky 事件,纯函数)
1419
1373
  *
1420
- * P0 事件两种:message_receive(onRecvMsg)/ message_recall(grayTip REVOKE)。
1374
+ * 事件两种:message_receive(onRecvMsg)/ message_recall(grayTip REVOKE)。
1421
1375
  * 实体与 reply 回填在广播路径异步取得后经 ctx 注入(翻译保持纯函数);
1422
1376
  * 撤回事件的 sender_id 取 RawMessage.senderUin(grayTip 系统消息的 sender
1423
1377
  * 即被撤回原消息的发送者,口径待真实事件校准)。
1424
1378
  */
1425
- /** 毫秒 → 秒(Unix 时间戳)。 */
1426
- const MS_TO_SEC$1 = 1e3;
1427
1379
  /** chatType → message_scene。 */
1428
1380
  function chatTypeToScene(chatType) {
1429
1381
  if (chatType === ChatType.GROUP) return "group";
@@ -1443,7 +1395,7 @@ function toMessageReceiveEvent(msg, ctx) {
1443
1395
  });
1444
1396
  if (ctx.forwardSegments !== void 0) segments.push(...ctx.forwardSegments);
1445
1397
  const scene = chatTypeToScene(msg.chatType);
1446
- const time = Math.floor(Number(msg.msgTime) / MS_TO_SEC$1);
1398
+ const time = toUnixSeconds(msg.msgTime);
1447
1399
  let data;
1448
1400
  if (scene === "group") data = {
1449
1401
  message_scene: "group",
@@ -1483,11 +1435,11 @@ function toMessageReceiveEvent(msg, ctx) {
1483
1435
  /** 撤回 grayTip → message_recall 事件(非撤回 grayTip 返回 null)。 */
1484
1436
  function toMessageRecallEvent(msg, ctx) {
1485
1437
  const revoke = (msg.elements.find((el) => el.grayTipElement != null)?.grayTipElement)?.revokeElement;
1486
- if (revoke === void 0) return null;
1438
+ if (revoke == null) return null;
1487
1439
  const scene = chatTypeToScene(msg.chatType);
1488
1440
  const operatorUin = ctx.uidToUin?.get(revoke.operatorUid) ?? revoke.operatorUid;
1489
1441
  return {
1490
- time: Math.floor(Number(msg.msgTime) / MS_TO_SEC$1),
1442
+ time: toUnixSeconds(msg.msgTime),
1491
1443
  self_id: Number(ctx.selfUin),
1492
1444
  event_type: "message_recall",
1493
1445
  data: {
@@ -1504,9 +1456,9 @@ function toMessageRecallEvent(msg, ctx) {
1504
1456
  function toGroupFileUploadEvent(msg, selfUin) {
1505
1457
  if (msg.chatType !== ChatType.GROUP) return null;
1506
1458
  const file = msg.elements.find((el) => el.fileElement != null)?.fileElement;
1507
- if (file === void 0) return null;
1459
+ if (file == null) return null;
1508
1460
  return {
1509
- time: Math.floor(Number(msg.msgTime) / MS_TO_SEC$1),
1461
+ time: toUnixSeconds(msg.msgTime),
1510
1462
  self_id: Number(selfUin),
1511
1463
  event_type: "group_file_upload",
1512
1464
  data: {
@@ -1529,171 +1481,173 @@ const peerMessageFields = {
1529
1481
  peer_id: z.number().int().min(10001),
1530
1482
  message_seq: z.number().int().min(0)
1531
1483
  };
1532
- /** get_message:获取单条消息(seq → msgId 反查 + 实体回填)。 */
1533
- var GetMessageAction = class extends MilkyApiAction {
1534
- name = "get_message";
1535
- schema = z.object({ ...peerMessageFields });
1536
- async _handle(payload) {
1537
- const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
1538
- const msgId = await this.api.resolveMsgIdBySeq(peer, payload.message_seq, peer.chatType);
1539
- if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
1540
- const [msg] = await this.api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
1541
- if (msg === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
1542
- return { message: await this.translateWithEntities(payload.message_scene, peer, msg) };
1543
- }
1544
- /** 实体回填(group 场景 schema 要求完整实体)→ IncomingMessage。 */
1545
- async translateWithEntities(scene, peer, msg) {
1546
- const ctx = { selfUin: this.api.self.uin };
1547
- if (scene === "group") {
1548
- const [detail, member] = await Promise.all([this.api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
1549
- this.api.logger?.warn({
1550
- group: peer.peerUid,
1551
- error: err instanceof Error ? err.message : String(err)
1552
- }, "milky: 群详情缓存读取失败,实体回填退化");
1553
- }), this.api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
1554
- this.api.logger?.debug({
1555
- group: peer.peerUid,
1556
- member: msg.senderUid,
1557
- error: err instanceof Error ? err.message : String(err)
1558
- }, "milky: 群成员缓存读取失败,实体回填退化");
1559
- })]);
1560
- ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
1561
- ctx.groupMemberEntity = toGroupMemberEntity(member, peer.peerUid, msg.senderUin);
1562
- }
1563
- return toMessageReceiveEvent(msg, ctx).data;
1564
- }
1565
- };
1566
1484
  /** 历史消息默认条数(规范 default 20)。 */
1567
1485
  const HISTORY_DEFAULT_LIMIT = 20;
1568
- /** get_history_messages:获取历史消息(start seq 锚点 → 原生翻页 → 升序输出)。 */
1569
- var GetHistoryMessagesAction = class extends MilkyApiAction {
1570
- name = "get_history_messages";
1571
- schema = z.object({
1572
- message_scene: z.enum([
1573
- "friend",
1574
- "group",
1575
- "temp"
1576
- ]),
1577
- peer_id: z.number().int().min(10001),
1578
- start_message_seq: z.number().int().min(0).nullable().optional(),
1579
- limit: z.number().int().min(0).nullable().optional()
1580
- });
1581
- async _handle(payload) {
1582
- const limit = payload.limit ?? HISTORY_DEFAULT_LIMIT;
1583
- const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
1584
- const anchor = await this.resolveAnchor(peer, payload.start_message_seq);
1585
- const msgs = await this.api.msgApi.fetchMessages(peer, {
1586
- count: limit,
1587
- ...anchor !== void 0 ? { msgId: anchor } : {}
1588
- });
1589
- for (const m of msgs) this.api.seqIndex.record(m);
1590
- const groupData = payload.message_scene === "group" ? await this.loadGroupData(peer.peerUid) : null;
1591
- const ordered = [...msgs].reverse();
1592
- const messages = ordered.map((m) => this.translateHistoryMessage(m, peer.peerUid, groupData));
1593
- const hasMore = msgs.length >= limit;
1594
- const oldest = ordered[0];
1595
- return {
1596
- messages,
1597
- next_message_seq: hasMore && oldest !== void 0 ? Number(oldest.msgSeq) : null
1598
- };
1599
- }
1600
- /** start_message_seq → 锚点 msgId(给了 seq 却反查不到 = NOT_FOUND)。 */
1601
- async resolveAnchor(peer, startSeq) {
1602
- if (startSeq === void 0 || startSeq === null) return;
1603
- const msgId = await this.api.resolveMsgIdBySeq(peer, startSeq, peer.chatType);
1604
- if (msgId === void 0) throw kernelError(`起始消息 ${startSeq} 不存在`, "NOT_FOUND");
1605
- return msgId;
1606
- }
1607
- /** 群场景回填数据(详情 + 成员表;缓存未装配返回空数据)。 */
1608
- async loadGroupData(groupCode) {
1609
- if (this.api.groupCache === void 0) return {
1610
- detail: void 0,
1611
- members: /* @__PURE__ */ new Map()
1612
- };
1613
- const [detail, members] = await Promise.all([this.api.groupCache.getGroupDetail(groupCode).catch((err) => {
1614
- this.api.logger?.warn({
1615
- group: groupCode,
1486
+ /** 消息查询域动作工厂(get_message / get_history_messages / get_forwarded_messages)。 */
1487
+ function createMessageQueryActions(api) {
1488
+ return [
1489
+ defineMilkyAction({
1490
+ name: "get_message",
1491
+ schema: z.object({ ...peerMessageFields }),
1492
+ handle: async (payload) => {
1493
+ const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
1494
+ const msgId = await api.resolveMsgIdBySeq(peer, payload.message_seq, peer.chatType);
1495
+ if (msgId === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
1496
+ const [msg] = await api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
1497
+ if (msg === void 0) throw kernelError(`消息 ${payload.message_seq} 不存在`, "NOT_FOUND");
1498
+ return { message: await translateWithEntities(api, payload.message_scene, peer, msg) };
1499
+ }
1500
+ }),
1501
+ defineMilkyAction({
1502
+ name: "get_history_messages",
1503
+ schema: z.object({
1504
+ message_scene: z.enum([
1505
+ "friend",
1506
+ "group",
1507
+ "temp"
1508
+ ]),
1509
+ peer_id: z.number().int().min(10001),
1510
+ start_message_seq: z.number().int().min(0).nullable().optional(),
1511
+ limit: z.number().int().min(0).nullable().optional()
1512
+ }),
1513
+ handle: async (payload) => {
1514
+ const limit = payload.limit ?? HISTORY_DEFAULT_LIMIT;
1515
+ const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
1516
+ const anchor = await resolveAnchor(api, peer, payload.start_message_seq);
1517
+ const msgs = await api.msgApi.fetchMessages(peer, {
1518
+ count: limit,
1519
+ ...anchor !== void 0 ? { msgId: anchor } : {}
1520
+ });
1521
+ for (const m of msgs) api.seqIndex.record(m);
1522
+ const groupData = payload.message_scene === "group" ? await loadGroupData(api, peer.peerUid) : null;
1523
+ const ordered = [...msgs].reverse();
1524
+ const messages = ordered.map((m) => translateHistoryMessage(api, m, peer.peerUid, groupData));
1525
+ const hasMore = msgs.length >= limit;
1526
+ const oldest = ordered[0];
1527
+ return {
1528
+ messages,
1529
+ next_message_seq: hasMore && oldest !== void 0 ? Number(oldest.msgSeq) : null
1530
+ };
1531
+ }
1532
+ }),
1533
+ defineMilkyAction({
1534
+ name: "get_forwarded_messages",
1535
+ schema: z.object({ forward_id: z.string().min(1) }),
1536
+ handle: async (payload) => {
1537
+ const entry = api.seqIndex.resolveForward(payload.forward_id);
1538
+ if (entry === void 0) throw kernelError(`转发消息 ${payload.forward_id} 不存在(未登记)`, "NOT_FOUND");
1539
+ const peer = {
1540
+ chatType: entry.chatType,
1541
+ peerUid: entry.peerUid
1542
+ };
1543
+ const msgs = await api.msgApi.fetchForwardMessage(peer, entry.msgId);
1544
+ for (const m of msgs) api.seqIndex.record(m);
1545
+ const uidToUin = await collectUidToUin(api, msgs);
1546
+ const messages = [];
1547
+ for (const m of msgs) messages.push({
1548
+ message_seq: Number(m.msgSeq),
1549
+ sender_name: await senderNameOf(api, m),
1550
+ avatar_url: avatarUrlOf(m.senderUin),
1551
+ time: toUnixSeconds(m.msgTime),
1552
+ segments: receiveSegmentsOf(m, uidToUin)
1553
+ });
1554
+ return { messages };
1555
+ }
1556
+ })
1557
+ ];
1558
+ }
1559
+ /** ---------- 内部辅助 ---------- */
1560
+ /** 实体回填(group 场景 schema 要求完整实体)→ IncomingMessage。 */
1561
+ async function translateWithEntities(api, scene, peer, msg) {
1562
+ const ctx = { selfUin: api.self.uin };
1563
+ if (scene === "group") {
1564
+ const [detail, member] = await Promise.all([api.groupCache?.getGroupDetail(peer.peerUid).catch((err) => {
1565
+ api.logger?.warn({
1566
+ group: peer.peerUid,
1616
1567
  error: err instanceof Error ? err.message : String(err)
1617
- }, "milky: 群详情缓存读取失败,历史翻译退化");
1618
- }), this.api.groupCache.getMembers(groupCode).catch((err) => {
1619
- this.api.logger?.warn({
1620
- group: groupCode,
1568
+ }, "milky: 群详情缓存读取失败,实体回填退化");
1569
+ }), api.groupCache?.getMember(peer.peerUid, msg.senderUid).catch((err) => {
1570
+ api.logger?.debug({
1571
+ group: peer.peerUid,
1572
+ member: msg.senderUid,
1621
1573
  error: err instanceof Error ? err.message : String(err)
1622
- }, "milky: 群成员表缓存读取失败,历史翻译退化");
1623
- return [];
1574
+ }, "milky: 群成员缓存读取失败,实体回填退化");
1624
1575
  })]);
1625
- const memberByUid = /* @__PURE__ */ new Map();
1626
- for (const m of members) memberByUid.set(m.uid, m);
1627
- return {
1628
- detail,
1629
- members: memberByUid
1630
- };
1631
- }
1632
- /** 单条历史消息 → IncomingMessage(群场景注入实体,fail-soft)。 */
1633
- translateHistoryMessage(msg, peerUid, groupData) {
1634
- const ctx = { selfUin: this.api.self.uin };
1635
- if (groupData !== null) {
1636
- if (groupData.detail !== void 0) ctx.groupEntity = toGroupEntity(groupData.detail, peerUid);
1637
- const member = groupData.members.get(msg.senderUid);
1638
- if (member !== void 0) ctx.groupMemberEntity = toGroupMemberEntity(member, peerUid, msg.senderUin);
1639
- }
1640
- return toMessageReceiveEvent(msg, ctx).data;
1576
+ ctx.groupEntity = toGroupEntity(detail, peer.peerUid);
1577
+ ctx.groupMemberEntity = toGroupMemberEntity(member, peer.peerUid, msg.senderUin);
1578
+ }
1579
+ return toMessageReceiveEvent(msg, ctx).data;
1580
+ }
1581
+ /** start_message_seq → 锚点 msgId(给了 seq 却反查不到 = NOT_FOUND)。 */
1582
+ async function resolveAnchor(api, peer, startSeq) {
1583
+ if (startSeq === void 0 || startSeq === null) return;
1584
+ const msgId = await api.resolveMsgIdBySeq(peer, startSeq, peer.chatType);
1585
+ if (msgId === void 0) throw kernelError(`起始消息 ${startSeq} 不存在`, "NOT_FOUND");
1586
+ return msgId;
1587
+ }
1588
+ /** 群场景回填数据(详情 + 成员表;缓存未装配返回空数据)。 */
1589
+ async function loadGroupData(api, groupCode) {
1590
+ if (api.groupCache === void 0) return {
1591
+ detail: void 0,
1592
+ members: /* @__PURE__ */ new Map()
1593
+ };
1594
+ const [detail, members] = await Promise.all([api.groupCache.getGroupDetail(groupCode).catch((err) => {
1595
+ api.logger?.warn({
1596
+ group: groupCode,
1597
+ error: err instanceof Error ? err.message : String(err)
1598
+ }, "milky: 群详情缓存读取失败,历史翻译退化");
1599
+ }), api.groupCache.getMembers(groupCode).catch((err) => {
1600
+ api.logger?.warn({
1601
+ group: groupCode,
1602
+ error: err instanceof Error ? err.message : String(err)
1603
+ }, "milky: 群成员表缓存读取失败,历史翻译退化");
1604
+ return [];
1605
+ })]);
1606
+ const memberByUid = /* @__PURE__ */ new Map();
1607
+ for (const m of members) memberByUid.set(m.uid, m);
1608
+ return {
1609
+ detail,
1610
+ members: memberByUid
1611
+ };
1612
+ }
1613
+ /** 单条历史消息 → IncomingMessage(群场景注入实体,fail-soft)。 */
1614
+ function translateHistoryMessage(api, msg, peerUid, groupData) {
1615
+ const ctx = { selfUin: api.self.uin };
1616
+ if (groupData !== null) {
1617
+ if (groupData.detail !== void 0) ctx.groupEntity = toGroupEntity(groupData.detail, peerUid);
1618
+ const member = groupData.members.get(msg.senderUid);
1619
+ if (member !== void 0) ctx.groupMemberEntity = toGroupMemberEntity(member, peerUid, msg.senderUin);
1641
1620
  }
1642
- };
1643
- /** get_forwarded_messages:获取合并转发内容(resId → 转发索引 → fetchForwardMessage)。 */
1644
- var GetForwardedMessagesAction = class extends MilkyApiAction {
1645
- name = "get_forwarded_messages";
1646
- schema = z.object({ forward_id: z.string().min(1) });
1647
- async _handle(payload) {
1648
- const entry = this.api.seqIndex.resolveForward(payload.forward_id);
1649
- if (entry === void 0) throw kernelError(`转发消息 ${payload.forward_id} 不存在(未登记)`, "NOT_FOUND");
1650
- const peer = {
1651
- chatType: entry.chatType,
1652
- peerUid: entry.peerUid
1653
- };
1654
- const msgs = await this.api.msgApi.fetchForwardMessage(peer, entry.msgId);
1655
- for (const m of msgs) this.api.seqIndex.record(m);
1656
- const uidToUin = await this.collectUidToUin(msgs);
1657
- const messages = [];
1658
- for (const m of msgs) messages.push({
1659
- message_seq: Number(m.msgSeq),
1660
- sender_name: await this.senderNameOf(m),
1661
- avatar_url: avatarUrlOf(m.senderUin),
1662
- time: Math.floor(Number(m.msgTime) / 1e3),
1663
- segments: receiveSegmentsOf(m, uidToUin)
1664
- });
1665
- return { messages };
1666
- }
1667
- /** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
1668
- async collectUidToUin(msgs) {
1669
- const uids = /* @__PURE__ */ new Set();
1670
- for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
1671
- if (uids.size === 0) return /* @__PURE__ */ new Map();
1672
- return await this.api.uidToUin([...uids]).catch((err) => {
1673
- this.api.logger?.warn({
1674
- count: uids.size,
1621
+ return toMessageReceiveEvent(msg, ctx).data;
1622
+ }
1623
+ /** at 段 uid → uin 批量转换(mention 翻译;失败退空 Map)。 */
1624
+ async function collectUidToUin(api, msgs) {
1625
+ const uids = /* @__PURE__ */ new Set();
1626
+ for (const m of msgs) for (const el of toCanonicalElements(m)) if (el.type === "at" && el.target !== "all") uids.add(el.target);
1627
+ if (uids.size === 0) return /* @__PURE__ */ new Map();
1628
+ return await api.uidToUin([...uids]).catch((err) => {
1629
+ api.logger?.warn({
1630
+ count: uids.size,
1631
+ error: err instanceof Error ? err.message : String(err)
1632
+ }, "milky: 历史 at uid→uin 失败,mention 段跳过");
1633
+ return /* @__PURE__ */ new Map();
1634
+ });
1635
+ }
1636
+ /** 发送者名(群场景成员缓存昵称/名片,失败退 uin 字符串)。 */
1637
+ async function senderNameOf(api, msg) {
1638
+ if (api.groupCache !== void 0 && msg.chatType === ChatType.GROUP) {
1639
+ const member = await api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
1640
+ api.logger?.debug({
1641
+ group: msg.peerUid,
1642
+ member: msg.senderUid,
1675
1643
  error: err instanceof Error ? err.message : String(err)
1676
- }, "milky: 历史 at uid→uin 失败,mention 段跳过");
1677
- return /* @__PURE__ */ new Map();
1644
+ }, "milky: 发送者成员缓存读取失败,退 uin 字符串");
1678
1645
  });
1646
+ const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
1647
+ if (name !== void 0 && name !== "") return name;
1679
1648
  }
1680
- /** 发送者名(群场景成员缓存昵称/名片,失败退 uin 字符串)。 */
1681
- async senderNameOf(msg) {
1682
- if (this.api.groupCache !== void 0 && msg.chatType === ChatType.GROUP) {
1683
- const member = await this.api.groupCache.getMember(msg.peerUid, msg.senderUid).catch((err) => {
1684
- this.api.logger?.debug({
1685
- group: msg.peerUid,
1686
- member: msg.senderUid,
1687
- error: err instanceof Error ? err.message : String(err)
1688
- }, "milky: 发送者成员缓存读取失败,退 uin 字符串");
1689
- });
1690
- const name = member?.cardName !== void 0 && member.cardName !== "" ? member.cardName : member?.nick;
1691
- if (name !== void 0 && name !== "") return name;
1692
- }
1693
- return msg.senderUin;
1694
- }
1695
- };
1696
- /** ---------- 内部辅助 ---------- */
1649
+ return msg.senderUin;
1650
+ }
1697
1651
  /** 单条消息 → 接收段(canonical 映射 + forward 段注入,forward 不经 canonical)。 */
1698
1652
  function receiveSegmentsOf(msg, uidToUin) {
1699
1653
  const segments = canonicalToIncomingSegments(toCanonicalElements(msg), { ...uidToUin.size > 0 ? { uidToUin } : {} });
@@ -1707,86 +1661,75 @@ function avatarUrlOf(uin) {
1707
1661
  }
1708
1662
  // src/milky/action/message-ops.ts
1709
1663
  const recallFields = { message_seq: z.number().int().min(0) };
1710
- /** recall_private_message:撤回私聊消息。 */
1711
- var RecallPrivateMessageAction = class extends MilkyApiAction {
1712
- name = "recall_private_message";
1713
- schema = z.object({
1714
- user_id: z.number().int().min(10001),
1715
- ...recallFields
1716
- });
1717
- async _handle(payload) {
1718
- await recallBySeq(await this.api.resolvePeer("friend", payload.user_id), payload.message_seq, this.api);
1719
- return {};
1720
- }
1721
- };
1722
- /** recall_group_message:撤回群消息。 */
1723
- var RecallGroupMessageAction = class extends MilkyApiAction {
1724
- name = "recall_group_message";
1725
- schema = z.object({
1726
- group_id: z.number().int().min(10001),
1727
- ...recallFields
1728
- });
1729
- async _handle(payload) {
1730
- await recallBySeq(await this.api.resolvePeer("group", payload.group_id), payload.message_seq, this.api);
1731
- return {};
1732
- }
1733
- };
1664
+ /** 消息操作域动作工厂(recall×2 / mark_read / 收藏表情 / 资源反查 / 私聊文件上传)。 */
1665
+ function createMessageOpsActions(api) {
1666
+ return [
1667
+ defineMilkyAction({
1668
+ name: "recall_private_message",
1669
+ schema: z.object({
1670
+ user_id: z.number().int().min(10001),
1671
+ ...recallFields
1672
+ }),
1673
+ handle: async (payload) => {
1674
+ await recallBySeq(await api.resolvePeer("friend", payload.user_id), payload.message_seq, api);
1675
+ return {};
1676
+ }
1677
+ }),
1678
+ defineMilkyAction({
1679
+ name: "recall_group_message",
1680
+ schema: z.object({
1681
+ group_id: z.number().int().min(10001),
1682
+ ...recallFields
1683
+ }),
1684
+ handle: async (payload) => {
1685
+ await recallBySeq(await api.resolvePeer("group", payload.group_id), payload.message_seq, api);
1686
+ return {};
1687
+ }
1688
+ }),
1689
+ defineMilkyAction({
1690
+ name: "mark_message_as_read",
1691
+ schema: z.object({ ...peerMessageFields }),
1692
+ handle: async (payload) => {
1693
+ const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
1694
+ await api.msgApi.markRead(peer);
1695
+ return {};
1696
+ }
1697
+ }),
1698
+ defineMilkyAction({
1699
+ name: "get_custom_face_url_list",
1700
+ schema: z.object({}),
1701
+ handle: async () => ({ urls: await api.msgApi.queryFavEmojis() })
1702
+ }),
1703
+ defineMilkyAction({
1704
+ name: "get_resource_temp_url",
1705
+ schema: z.object({ resource_id: z.string().min(1) }),
1706
+ handle: async (payload) => {
1707
+ const id = payload.resource_id;
1708
+ if (id.startsWith("http://") || id.startsWith("https://") || id.startsWith("base64://")) return { url: id };
1709
+ throw kernelError(`资源 ${id} 无临时链接(resource_id 非链接形态)`, "NOT_FOUND");
1710
+ }
1711
+ }),
1712
+ defineMilkyAction({
1713
+ name: "upload_private_file",
1714
+ schema: z.object({
1715
+ user_id: z.number().int().min(10001),
1716
+ file_uri: z.string().min(1),
1717
+ file_name: z.string().min(1)
1718
+ }),
1719
+ handle: async (payload) => {
1720
+ const path = await resolveUriToPath(payload.file_uri, api.mediaDir);
1721
+ const peer = await api.resolvePeer("friend", payload.user_id);
1722
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
1723
+ }
1724
+ })
1725
+ ];
1726
+ }
1734
1727
  /** seq → msgId(反查)→ recallMessage。 */
1735
1728
  async function recallBySeq(peer, seq, api) {
1736
1729
  const msgId = await api.resolveMsgIdBySeq(peer, seq, peer.chatType);
1737
1730
  if (msgId === void 0) throw kernelError(`消息 ${seq} 不存在`, "NOT_FOUND");
1738
1731
  await api.msgApi.recallMessage(peer, [msgId]);
1739
1732
  }
1740
- /** mark_message_as_read:标记会话已读(NT setMsgRead 以会话为粒度,seq 入参仅兼容 schema)。 */
1741
- var MarkMessageAsReadAction = class extends MilkyApiAction {
1742
- name = "mark_message_as_read";
1743
- schema = z.object({ ...peerMessageFields });
1744
- async _handle(payload) {
1745
- const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
1746
- await this.api.msgApi.markRead(peer);
1747
- return {};
1748
- }
1749
- };
1750
- /** get_custom_face_url_list:收藏表情链接(queryFavEmojiByDesc 形状待校准)。 */
1751
- var GetCustomFaceUrlListAction = class extends MilkyApiAction {
1752
- name = "get_custom_face_url_list";
1753
- schema = z.object({});
1754
- async _handle() {
1755
- return { urls: await this.api.msgApi.queryFavEmojis() };
1756
- }
1757
- };
1758
- /**
1759
- * get_resource_temp_url:资源临时链接。
1760
- * 已知差异(P0 模型):接收段 resource_id 即临时链接(本地路径优先 url 兜底),
1761
- * 无独立资源索引——http(s)/base64 形态原样返回,其余 NOT_FOUND。
1762
- */
1763
- var GetResourceTempUrlAction = class extends MilkyApiAction {
1764
- name = "get_resource_temp_url";
1765
- schema = z.object({ resource_id: z.string().min(1) });
1766
- async _handle(payload) {
1767
- const id = payload.resource_id;
1768
- if (id.startsWith("http://") || id.startsWith("https://") || id.startsWith("base64://")) return { url: id };
1769
- throw kernelError(`资源 ${id} 无临时链接(resource_id 非链接形态)`, "NOT_FOUND");
1770
- }
1771
- };
1772
- /**
1773
- * upload_private_file:上传并投递私聊文件(**闪传通道**:分享链接卡片)。
1774
- * file_id 返回闪传文件集 id(非文件消息 fileUuid)。语义降级同 upload_group_file:
1775
- * 对端收到的是分享链接卡片而不是 fileElement 文件消息(kernel design §15)。
1776
- */
1777
- var UploadPrivateFileAction = class extends MilkyApiAction {
1778
- name = "upload_private_file";
1779
- schema = z.object({
1780
- user_id: z.number().int().min(10001),
1781
- file_uri: z.string().min(1),
1782
- file_name: z.string().min(1)
1783
- });
1784
- async _handle(payload) {
1785
- const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
1786
- const peer = await this.api.resolvePeer("friend", payload.user_id);
1787
- return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
1788
- }
1789
- };
1790
1733
  // src/milky/action/message-send.ts
1791
1734
  /**
1792
1735
  * OutgoingSegment 宽松校验:入口只保证「{type, data}」形状,字段级转换在
@@ -1797,31 +1740,31 @@ const outgoingSegmentSchema = z.object({
1797
1740
  data: z.record(z.string(), z.unknown())
1798
1741
  }).loose();
1799
1742
  const sendMessageFields = { message: z.array(outgoingSegmentSchema).min(1).max(200) };
1800
- /** send_private_message:发送私聊消息。 */
1801
- var SendPrivateMessageAction = class extends MilkyApiAction {
1802
- name = "send_private_message";
1803
- schema = z.object({
1804
- user_id: z.number().int().min(10001),
1805
- ...sendMessageFields
1806
- });
1807
- async _handle(payload) {
1808
- return await sendMilkyMessage(await this.api.resolvePeer("friend", payload.user_id), payload.message, this.api);
1809
- }
1810
- };
1811
- /** send_group_message:发送群聊消息。 */
1812
- var SendGroupMessageAction = class extends MilkyApiAction {
1813
- name = "send_group_message";
1814
- schema = z.object({
1815
- group_id: z.number().int().min(10001),
1816
- ...sendMessageFields
1817
- });
1818
- async _handle(payload) {
1819
- return await sendMilkyMessage(await this.api.resolvePeer("group", payload.group_id), payload.message, this.api);
1820
- }
1821
- };
1743
+ /** 消息发送域动作工厂(send_private_message / send_group_message)。 */
1744
+ function createMessageSendActions(api) {
1745
+ return [defineMilkyAction({
1746
+ name: "send_private_message",
1747
+ schema: z.object({
1748
+ user_id: z.number().int().min(10001),
1749
+ ...sendMessageFields
1750
+ }),
1751
+ handle: async (payload) => {
1752
+ return await sendMilkyMessage(await api.resolvePeer("friend", payload.user_id), payload.message, api);
1753
+ }
1754
+ }), defineMilkyAction({
1755
+ name: "send_group_message",
1756
+ schema: z.object({
1757
+ group_id: z.number().int().min(10001),
1758
+ ...sendMessageFields
1759
+ }),
1760
+ handle: async (payload) => {
1761
+ return await sendMilkyMessage(await api.resolvePeer("group", payload.group_id), payload.message, api);
1762
+ }
1763
+ })];
1764
+ }
1822
1765
  /** ---------- 发送核心与组装链 ---------- */
1823
1766
  /** 发送核心:segments → canonical(URI/ID 转换)→ sendMessage → 回查输出。
1824
- * forward 段分流到组装链(P2 批次一,临时消息法)。 */
1767
+ * forward 段分流到组装链(临时消息法)。 */
1825
1768
  async function sendMilkyMessage(peer, segments, api) {
1826
1769
  if (segments.some((s) => s.type === "forward")) return await sendForwardComposition(peer, segments, api);
1827
1770
  const { elements, atUins } = outgoingSegmentsToCanonical(segments);
@@ -1831,7 +1774,7 @@ async function sendMilkyMessage(peer, segments, api) {
1831
1774
  return await api.resolveSentOutput(peer, msgId);
1832
1775
  }
1833
1776
  /**
1834
- * forward 段组装链(P2 批次一,milky.md §0.6):仅支持单 forward 单独发。
1777
+ * forward 段组装链(milky.md §0.6):仅支持单 forward 单独发。
1835
1778
  * 临时消息法:逐条发送 messages[i].segments → sendForwardMessage(buildMultiForwardMsg
1836
1779
  * 以目标 peer 的真实消息组装 → sendMsg)→ best-effort 撤回临时消息 → 回查输出。
1837
1780
  *
@@ -1926,8 +1869,8 @@ function isRemoteMediaUri(el) {
1926
1869
  }
1927
1870
  // src/milky/action/profile.ts
1928
1871
  /**
1929
- * Milky 资料类动作(P1):get_user_profile / get_friend_info / set_avatar /
1930
- * set_nickname / set_bio / get_cookies / get_csrf_token
1872
+ * Milky 资料类动作:get_user_profile / get_friend_info / set_avatar /
1873
+ * set_nickname / set_bio / get_cookies / get_csrf_token。
1931
1874
  *
1932
1875
  * set_avatar 的 uri 经 media-uri 解析(本地路径 / file:// 直用,http(s)/base64
1933
1876
  * 落盘 mediaDir);get_cookies 输出规范为单字符串(k=v 分号拼接);
@@ -1935,242 +1878,229 @@ function isRemoteMediaUri(el) {
1935
1878
  */
1936
1879
  /** CSRF 计算域名(bkn 口径,OB11 get_csrf_token 同源)。 */
1937
1880
  const CSRF_DOMAIN = "qun.qq.com";
1938
- /** get_user_profile:获取用户个人信息(陌生人信息 API;country/city/school 无源空兜底)。 */
1939
- var GetUserProfileAction = class extends MilkyApiAction {
1940
- name = "get_user_profile";
1941
- schema = z.object({ user_id: z.number().int().min(10001) });
1942
- async _handle(payload) {
1943
- const info = await this.api.profileApi.getStrangerInfo(String(payload.user_id));
1944
- return {
1945
- nickname: info.nickname,
1946
- qid: info.qid,
1947
- age: info.age,
1948
- sex: info.sex,
1949
- remark: info.remark,
1950
- bio: info.long_nick,
1951
- level: info.qq_level,
1952
- country: "",
1953
- city: "",
1954
- school: ""
1955
- };
1956
- }
1957
- };
1958
- /** get_friend_info:获取好友信息(好友列表单查)。 */
1959
- var GetFriendInfoAction = class extends MilkyApiAction {
1960
- name = "get_friend_info";
1961
- schema = z.object({
1962
- user_id: z.number().int().min(10001),
1963
- no_cache: z.boolean().nullable().optional()
1964
- });
1965
- async _handle(payload) {
1966
- const uin = String(payload.user_id);
1967
- const friend = (await this.api.friendApi.getFriendList()).find((f) => f.uin === uin);
1968
- if (friend === void 0) throw kernelError(`好友 ${uin} 不存在`, "NOT_FOUND");
1969
- return { friend: toFriendEntity(friend, friend.uin, friend.nickname) };
1970
- }
1971
- };
1972
- /** set_avatar:设置头像(uri → 本地路径)。 */
1973
- var SetAvatarAction = class extends MilkyApiAction {
1974
- name = "set_avatar";
1975
- schema = z.object({ uri: z.string().min(1) });
1976
- async _handle(payload) {
1977
- const path = await resolveMediaUri(payload.uri, this.api.mediaDir);
1978
- await this.api.profileApi.setHeader(path);
1979
- return {};
1980
- }
1981
- };
1982
- /** set_nickname:设置昵称。 */
1983
- var SetNicknameAction = class extends MilkyApiAction {
1984
- name = "set_nickname";
1985
- schema = z.object({ new_nickname: z.string() });
1986
- async _handle(payload) {
1987
- await this.api.profileApi.setNickName(payload.new_nickname);
1988
- return {};
1989
- }
1990
- };
1991
- /** set_bio:设置个性签名。 */
1992
- var SetBioAction = class extends MilkyApiAction {
1993
- name = "set_bio";
1994
- schema = z.object({ new_bio: z.string() });
1995
- async _handle(payload) {
1996
- await this.api.profileApi.setLongNick(payload.new_bio);
1997
- return {};
1998
- }
1999
- };
2000
- /** get_cookies:获取 cookies(规范输出为 k=v 分号拼接字符串)。 */
2001
- var GetCookiesAction = class extends MilkyApiAction {
2002
- name = "get_cookies";
2003
- schema = z.object({ domain: z.string().min(1) });
2004
- async _handle(payload) {
2005
- const cookies = await this.api.ticketApi.getCookies(payload.domain, this.api.self.uin);
2006
- return { cookies: Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; ") };
2007
- }
2008
- };
2009
- /** get_csrf_token:bkn(qun.qq.com skey 派生,OB11 get_csrf_token 同口径)。 */
2010
- var GetCSRFTokenAction = class extends MilkyApiAction {
2011
- name = "get_csrf_token";
2012
- schema = z.object({}).strict();
2013
- async _handle() {
2014
- const cookies = await this.api.ticketApi.getCookies(CSRF_DOMAIN, this.api.self.uin);
2015
- return { csrf_token: TicketApi.getBkn(cookies["skey"] ?? "") };
2016
- }
2017
- };
1881
+ /** 资料类动作工厂(资料读取 / 头像昵称签名设置 / cookies 与 bkn)。 */
1882
+ function createProfileActions(api) {
1883
+ return [
1884
+ defineMilkyAction({
1885
+ name: "get_user_profile",
1886
+ schema: z.object({ user_id: z.number().int().min(10001) }),
1887
+ handle: async (payload) => {
1888
+ const info = await api.profileApi.getStrangerInfo(String(payload.user_id));
1889
+ return {
1890
+ nickname: info.nickname,
1891
+ qid: info.qid,
1892
+ age: info.age,
1893
+ sex: info.sex,
1894
+ remark: info.remark,
1895
+ bio: info.long_nick,
1896
+ level: info.qq_level,
1897
+ country: "",
1898
+ city: "",
1899
+ school: ""
1900
+ };
1901
+ }
1902
+ }),
1903
+ defineMilkyAction({
1904
+ name: "get_friend_info",
1905
+ schema: z.object({
1906
+ user_id: z.number().int().min(10001),
1907
+ no_cache: z.boolean().nullable().optional()
1908
+ }),
1909
+ handle: async (payload) => {
1910
+ const uin = String(payload.user_id);
1911
+ const friend = (await api.friendApi.getFriendList()).find((f) => f.uin === uin);
1912
+ if (friend === void 0) throw kernelError(`好友 ${uin} 不存在`, "NOT_FOUND");
1913
+ return { friend: toFriendEntity(friend, friend.uin, friend.nickname) };
1914
+ }
1915
+ }),
1916
+ defineMilkyAction({
1917
+ name: "set_avatar",
1918
+ schema: z.object({ uri: z.string().min(1) }),
1919
+ handle: async (payload) => {
1920
+ const path = await resolveMediaUri(payload.uri, api.mediaDir);
1921
+ await api.profileApi.setHeader(path);
1922
+ return {};
1923
+ }
1924
+ }),
1925
+ defineMilkyAction({
1926
+ name: "set_nickname",
1927
+ schema: z.object({ new_nickname: z.string() }),
1928
+ handle: async (payload) => {
1929
+ await api.profileApi.setNickName(payload.new_nickname);
1930
+ return {};
1931
+ }
1932
+ }),
1933
+ defineMilkyAction({
1934
+ name: "set_bio",
1935
+ schema: z.object({ new_bio: z.string() }),
1936
+ handle: async (payload) => {
1937
+ await api.profileApi.setLongNick(payload.new_bio);
1938
+ return {};
1939
+ }
1940
+ }),
1941
+ defineMilkyAction({
1942
+ name: "get_cookies",
1943
+ schema: z.object({ domain: z.string().min(1) }),
1944
+ handle: async (payload) => {
1945
+ const cookies = await api.ticketApi.getCookies(payload.domain, api.self.uin);
1946
+ return { cookies: Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; ") };
1947
+ }
1948
+ }),
1949
+ defineMilkyAction({
1950
+ name: "get_csrf_token",
1951
+ schema: z.object({}).strict(),
1952
+ handle: async () => {
1953
+ const cookies = await api.ticketApi.getCookies(CSRF_DOMAIN, api.self.uin);
1954
+ return { csrf_token: TicketApi.getBkn(cookies["skey"] ?? "") };
1955
+ }
1956
+ })
1957
+ ];
1958
+ }
2018
1959
  // src/milky/action/social.ts
2019
- const emptySchema$1 = z.object({}).strict();
2020
- /** get_friend_list:获取好友列表。 */
2021
- var GetFriendListAction = class extends MilkyApiAction {
2022
- name = "get_friend_list";
2023
- schema = emptySchema$1;
2024
- async _handle() {
2025
- return { friends: (await this.api.friendApi.getFriendList()).map((f) => toFriendEntity(f, f.uin, f.nickname)) };
2026
- }
2027
- };
2028
- /** get_group_list:获取群列表。
2029
- * 实测校准(2026-08-08,OB11 同款):原生 getGroupList 返回值无数据,列表经
2030
- * onGroupListUpdate 事件进 GroupCache——缓存优先,为空触发刷新回填。
2031
- */
2032
- var GetGroupListAction = class extends MilkyApiAction {
2033
- name = "get_group_list";
2034
- schema = emptySchema$1;
2035
- async _handle() {
2036
- return { groups: (this.api.groupCache !== void 0 ? await this.api.groupCache.listGroupsRefreshed() : await this.api.groupApi.getGroupList(true)).map(groupListToEntity) };
2037
- }
2038
- };
2039
- /** send_profile_like:发送好友赞(count 缺省 1,规范 default 同值)。 */
2040
- var SendProfileLikeAction = class extends MilkyApiAction {
2041
- name = "send_profile_like";
2042
- schema = z.object({
2043
- user_id: z.number().int().min(10001),
2044
- count: z.number().int().min(0).nullable().optional()
2045
- });
2046
- async _handle(payload) {
2047
- const uid = await this.api.resolveUidFromUin(payload.user_id);
2048
- await this.api.profileLikeApi.sendLike(uid, payload.count ?? 1);
2049
- return {};
2050
- }
2051
- };
2052
- /** delete_friend:删除好友。 */
2053
- var DeleteFriendAction = class extends MilkyApiAction {
2054
- name = "delete_friend";
2055
- schema = z.object({ user_id: z.number().int().min(10001) });
2056
- async _handle(payload) {
2057
- const uid = await this.api.resolveUidFromUin(payload.user_id);
2058
- await this.api.friendApi.deleteFriend(uid);
2059
- return {};
2060
- }
2061
- };
2062
- /**
2063
- * get_friend_requests:获取好友请求列表。
2064
- * kernel getBuddyReqList 无过滤/数量参数——is_filtered 入参仅作 schema 兼容
2065
- * (全量返回);state 无源字段恒 pending(真实状态待探测校准)。
2066
- */
2067
- var GetFriendRequestsAction = class extends MilkyApiAction {
2068
- name = "get_friend_requests";
2069
- schema = z.object({
2070
- limit: z.number().int().min(0).nullable().optional(),
2071
- is_filtered: z.boolean().nullable().optional()
2072
- });
2073
- async _handle(payload) {
2074
- const reqs = await this.api.friendApi.getBuddyReqList();
2075
- let uidToUin = /* @__PURE__ */ new Map();
2076
- if (reqs.length > 0) uidToUin = await this.api.uidToUin(reqs.map((req) => req.friendUid)).catch((err) => {
2077
- this.api.logger?.warn({
2078
- count: reqs.length,
2079
- error: err instanceof Error ? err.message : String(err)
2080
- }, "milky: 好友申请 uid→uin 失败,initiator_id 兜底 0");
2081
- return /* @__PURE__ */ new Map();
2082
- });
2083
- const requests = reqs.map((req) => ({
2084
- time: Number(req.reqTime) || 0,
2085
- initiator_id: Number(uidToUin.get(req.friendUid)) || 0,
2086
- initiator_uid: req.friendUid,
2087
- target_user_id: Number(this.api.self.uin),
2088
- target_user_uid: this.api.self.uid ?? "",
2089
- state: "pending",
2090
- comment: typeof req["words"] === "string" ? req["words"] : "",
2091
- via: req.sourceName ?? "",
2092
- is_filtered: false
2093
- }));
2094
- const limit = payload.limit ?? requests.length;
2095
- return { requests: requests.slice(0, limit) };
2096
- }
2097
- };
2098
- /**
2099
- * accept/reject_friend_request 公共基类:initiator_uid → 查申请 → 应答。
2100
- * kernel handleFriendRequest 无 reason 参数(拒绝理由无源,入参仅 schema 兼容)。
2101
- */
2102
- var HandleFriendRequestBase = class extends MilkyApiAction {
2103
- schema = z.object({
2104
- initiator_uid: z.string().min(1),
2105
- is_filtered: z.boolean().nullable().optional(),
2106
- reason: z.string().nullable().optional()
2107
- });
2108
- async _handle(payload) {
2109
- const notify = await findBuddyReq(this.api, payload.initiator_uid);
2110
- await this.api.friendApi.handleFriendRequest(notify, this.accept);
2111
- return {};
2112
- }
2113
- };
2114
- /** accept_friend_request:同意好友申请。 */
2115
- var AcceptFriendRequestAction = class extends HandleFriendRequestBase {
2116
- name = "accept_friend_request";
2117
- accept = true;
2118
- };
2119
- /** reject_friend_request:拒绝好友申请。 */
2120
- var RejectFriendRequestAction = class extends HandleFriendRequestBase {
2121
- name = "reject_friend_request";
2122
- accept = false;
2123
- };
2124
- /** send_friend_nudge:发送好友戳一戳(is_self=true 戳自己)。 */
2125
- var SendFriendNudgeAction = class extends MilkyApiAction {
2126
- name = "send_friend_nudge";
2127
- schema = z.object({
2128
- user_id: z.number().int().min(10001),
2129
- is_self: optBoolNudge
2130
- });
2131
- async _handle(payload) {
2132
- const callerUid = requireSelfUid(this.api);
2133
- const receiverUid = payload.is_self === true ? callerUid : await this.api.resolveUidFromUin(payload.user_id);
2134
- const peer = await this.api.resolvePeer("friend", payload.user_id);
2135
- await this.api.msgApi.sendNudge(peer, {
2136
- receiverUid,
2137
- callerUid
2138
- });
2139
- return {};
2140
- }
2141
- };
2142
- /** get_peer_pins:获取置顶会话(RecentContactApi isTop 过滤,实体经现有翻译)。 */
2143
- var GetPeerPinsAction = class extends MilkyApiAction {
2144
- name = "get_peer_pins";
2145
- schema = z.object({});
2146
- async _handle() {
2147
- const pinned = await this.api.recentContactApi.getPinnedContacts();
2148
- const friendUids = pinned.filter((p) => p.scene === "friend").map((p) => p.peerUid);
2149
- const groupCodes = pinned.filter((p) => p.scene === "group").map((p) => p.peerUid);
2150
- return {
2151
- friends: await pinnedFriendEntities(this.api, friendUids),
2152
- groups: await pinnedGroupEntities(this.api, groupCodes)
2153
- };
2154
- }
2155
- };
2156
- /** set_peer_pin:设置/取消会话置顶(is_pinned 缺省 true)。 */
2157
- var SetPeerPinAction = class extends MilkyApiAction {
2158
- name = "set_peer_pin";
2159
- schema = z.object({
2160
- message_scene: z.enum([
2161
- "friend",
2162
- "group",
2163
- "temp"
2164
- ]),
2165
- peer_id: z.number().int().min(10001),
2166
- is_pinned: optBoolNudge
2167
- });
2168
- async _handle(payload) {
2169
- const peer = await this.api.resolvePeer(payload.message_scene, payload.peer_id);
2170
- await this.api.msgApi.setContactTop(peer, payload.is_pinned ?? true);
2171
- return {};
2172
- }
2173
- };
1960
+ /** 可选布尔(nudge / pin 入参共用口径)。 */
1961
+ const optBool = z.boolean().nullable().optional();
1962
+ /** 社交类动作工厂(好友/群列表、赞、删好友、申请处理、戳一戳、会话置顶)。 */
1963
+ function createSocialActions(api) {
1964
+ return [
1965
+ defineMilkyAction({
1966
+ name: "get_friend_list",
1967
+ schema: z.object({}).strict(),
1968
+ handle: async () => {
1969
+ return { friends: (await api.friendApi.getFriendList()).map((f) => toFriendEntity(f, f.uin, f.nickname)) };
1970
+ }
1971
+ }),
1972
+ defineMilkyAction({
1973
+ name: "get_group_list",
1974
+ schema: z.object({}).strict(),
1975
+ handle: async () => {
1976
+ return { groups: (api.groupCache !== void 0 ? await api.groupCache.listGroupsRefreshed() : await api.groupApi.getGroupList(true)).map(groupListToEntity) };
1977
+ }
1978
+ }),
1979
+ defineMilkyAction({
1980
+ name: "send_profile_like",
1981
+ schema: z.object({
1982
+ user_id: z.number().int().min(10001),
1983
+ count: z.number().int().min(0).nullable().optional()
1984
+ }),
1985
+ handle: async (payload) => {
1986
+ const uid = await api.resolveUidFromUin(payload.user_id);
1987
+ await api.profileLikeApi.sendLike(uid, payload.count ?? 1);
1988
+ return {};
1989
+ }
1990
+ }),
1991
+ defineMilkyAction({
1992
+ name: "delete_friend",
1993
+ schema: z.object({ user_id: z.number().int().min(10001) }),
1994
+ handle: async (payload) => {
1995
+ const uid = await api.resolveUidFromUin(payload.user_id);
1996
+ await api.friendApi.deleteFriend(uid);
1997
+ return {};
1998
+ }
1999
+ }),
2000
+ defineMilkyAction({
2001
+ name: "get_friend_requests",
2002
+ schema: z.object({
2003
+ limit: z.number().int().min(0).nullable().optional(),
2004
+ is_filtered: z.boolean().nullable().optional()
2005
+ }),
2006
+ handle: async (payload) => {
2007
+ const reqs = await api.friendApi.getBuddyReqList();
2008
+ let uidToUin = /* @__PURE__ */ new Map();
2009
+ if (reqs.length > 0) uidToUin = await api.uidToUin(reqs.map((req) => req.friendUid)).catch((err) => {
2010
+ api.logger?.warn({
2011
+ count: reqs.length,
2012
+ error: err instanceof Error ? err.message : String(err)
2013
+ }, "milky: 好友申请 uid→uin 失败,initiator_id 兜底 0");
2014
+ return /* @__PURE__ */ new Map();
2015
+ });
2016
+ const requests = reqs.map((req) => ({
2017
+ time: Number(req.reqTime) || 0,
2018
+ initiator_id: Number(uidToUin.get(req.friendUid)) || 0,
2019
+ initiator_uid: req.friendUid,
2020
+ target_user_id: Number(api.self.uin),
2021
+ target_user_uid: api.self.uid ?? "",
2022
+ state: "pending",
2023
+ comment: typeof req["words"] === "string" ? req["words"] : "",
2024
+ via: req.sourceName ?? "",
2025
+ is_filtered: false
2026
+ }));
2027
+ const limit = payload.limit ?? requests.length;
2028
+ return { requests: requests.slice(0, limit) };
2029
+ }
2030
+ }),
2031
+ defineMilkyAction({
2032
+ name: "accept_friend_request",
2033
+ schema: friendRequestRespondSchema,
2034
+ handle: async (payload) => {
2035
+ const notify = await findBuddyReq(api, payload.initiator_uid);
2036
+ await api.friendApi.handleFriendRequest(notify, true);
2037
+ return {};
2038
+ }
2039
+ }),
2040
+ defineMilkyAction({
2041
+ name: "reject_friend_request",
2042
+ schema: friendRequestRespondSchema,
2043
+ handle: async (payload) => {
2044
+ const notify = await findBuddyReq(api, payload.initiator_uid);
2045
+ await api.friendApi.handleFriendRequest(notify, false);
2046
+ return {};
2047
+ }
2048
+ }),
2049
+ defineMilkyAction({
2050
+ name: "send_friend_nudge",
2051
+ schema: z.object({
2052
+ user_id: z.number().int().min(10001),
2053
+ is_self: optBool
2054
+ }),
2055
+ handle: async (payload) => {
2056
+ const callerUid = requireSelfUid(api);
2057
+ const receiverUid = payload.is_self === true ? callerUid : await api.resolveUidFromUin(payload.user_id);
2058
+ const peer = await api.resolvePeer("friend", payload.user_id);
2059
+ await api.msgApi.sendNudge(peer, {
2060
+ receiverUid,
2061
+ callerUid
2062
+ });
2063
+ return {};
2064
+ }
2065
+ }),
2066
+ defineMilkyAction({
2067
+ name: "get_peer_pins",
2068
+ schema: z.object({}),
2069
+ handle: async () => {
2070
+ const pinned = await api.recentContactApi.getPinnedContacts();
2071
+ const friendUids = pinned.filter((p) => p.scene === "friend").map((p) => p.peerUid);
2072
+ const groupCodes = pinned.filter((p) => p.scene === "group").map((p) => p.peerUid);
2073
+ return {
2074
+ friends: await pinnedFriendEntities(api, friendUids),
2075
+ groups: await pinnedGroupEntities(api, groupCodes)
2076
+ };
2077
+ }
2078
+ }),
2079
+ defineMilkyAction({
2080
+ name: "set_peer_pin",
2081
+ schema: z.object({
2082
+ message_scene: z.enum([
2083
+ "friend",
2084
+ "group",
2085
+ "temp"
2086
+ ]),
2087
+ peer_id: z.number().int().min(10001),
2088
+ is_pinned: optBool
2089
+ }),
2090
+ handle: async (payload) => {
2091
+ const peer = await api.resolvePeer(payload.message_scene, payload.peer_id);
2092
+ await api.msgApi.setContactTop(peer, payload.is_pinned ?? true);
2093
+ return {};
2094
+ }
2095
+ })
2096
+ ];
2097
+ }
2098
+ /** accept/reject_friend_request 共入参(is_filtered / reason 仅 schema 兼容)。 */
2099
+ const friendRequestRespondSchema = z.object({
2100
+ initiator_uid: z.string().min(1),
2101
+ is_filtered: z.boolean().nullable().optional(),
2102
+ reason: z.string().nullable().optional()
2103
+ });
2174
2104
  /** 置顶好友实体(uid 匹配全量好友列表;未命中跳过)。 */
2175
2105
  async function pinnedFriendEntities(api, uids) {
2176
2106
  if (uids.length === 0) return [];
@@ -2197,119 +2127,61 @@ function requireSelfUid(api) {
2197
2127
  if (uid === void 0 || uid === "") throw kernelError("登录身份缺 uid(无法发起戳一戳)", "INVALID_PARAM");
2198
2128
  return uid;
2199
2129
  }
2200
- /** 可选布尔(social.ts 本文件原无 optBool,本地定义避免全局重名)。 */
2201
- const optBoolNudge = z.boolean().nullable().optional();
2202
2130
  // src/milky/action/system.ts
2203
2131
  /**
2204
- * Milky 系统类动作(P0):get_login_info / get_impl_info
2132
+ * Milky 系统类动作:get_login_info / get_impl_info
2205
2133
  *
2206
2134
  * get_impl_info 是 Milky 的版本协商面(规范 §compatibility):milky_version
2207
2135
  * 固定 "1.3"(目标协议版本 1.3.0),qq_protocol_type 固定 windows(自建宿主)。
2208
2136
  */
2209
2137
  /** Milky 协议版本(docs/protocols/milky.md:目标 1.3.0)。 */
2210
2138
  const MILKY_VERSION = "1.3";
2211
- const emptySchema = z.object({}).strict();
2212
- /** get_login_info:获取登录信息。 */
2213
- var GetLoginInfoAction = class extends MilkyApiAction {
2214
- name = "get_login_info";
2215
- schema = emptySchema;
2216
- async _handle() {
2217
- return {
2218
- uin: Number(this.api.self.uin),
2219
- nickname: this.api.self.nickname
2220
- };
2221
- }
2222
- };
2223
- /** get_impl_info:获取协议端信息(版本协商)。 */
2224
- var GetImplInfoAction = class extends MilkyApiAction {
2225
- name = "get_impl_info";
2226
- schema = emptySchema;
2227
- async _handle() {
2228
- return {
2139
+ /** 系统类动作工厂(login_info / impl_info)。 */
2140
+ function createSystemActions(api) {
2141
+ return [defineMilkyAction({
2142
+ name: "get_login_info",
2143
+ schema: z.object({}).strict(),
2144
+ handle: async () => ({
2145
+ uin: Number(api.self.uin),
2146
+ nickname: api.self.nickname
2147
+ })
2148
+ }), defineMilkyAction({
2149
+ name: "get_impl_info",
2150
+ schema: z.object({}).strict(),
2151
+ handle: async () => ({
2229
2152
  impl_name: "napukettoqq",
2230
- impl_version: this.api.implVersion,
2231
- qq_protocol_version: this.api.qqVersion,
2153
+ impl_version: api.implVersion,
2154
+ qq_protocol_version: api.qqVersion,
2232
2155
  qq_protocol_type: "windows",
2233
2156
  milky_version: MILKY_VERSION
2234
- };
2235
- }
2236
- };
2157
+ })
2158
+ })];
2159
+ }
2237
2160
  // src/milky/action/index.ts
2238
2161
  /**
2239
- * Milky 动作注册表(P0 9 + P1 40 + P2 批次二 15 = 64 个)
2162
+ * Milky 动作注册表:动作按领域文件组织(每文件一个 create*Actions 工厂),
2163
+ * 本入口按固定顺序遍历注册——新增动作在领域文件的工厂里登记即可。
2240
2164
  *
2241
- * P0/P1 面 = docs/protocols/milky.md §9 清单;批次二 = §0.7(nudge / 公告 /
2242
- * 头衔 / 群头像 / peer_pins / 上传 / download_url / rename_folder / 收藏表情 /
2243
- * resource 反查)。
2165
+ * 64 动作 = docs/protocols/milky.md §9 清单全量。
2244
2166
  */
2245
- /** Milky 动作注册表(P0+P1 49 动作)。 */
2167
+ /** Milky 动作域工厂(注册顺序即列表顺序:system → message → social/profile → group)。 */
2168
+ const ACTION_FACTORIES = [
2169
+ createSystemActions,
2170
+ createMessageSendActions,
2171
+ createMessageQueryActions,
2172
+ createMessageOpsActions,
2173
+ createSocialActions,
2174
+ createProfileActions,
2175
+ createGroupQueryActions,
2176
+ createGroupManageActions,
2177
+ createGroupEssenceActions,
2178
+ createGroupNoticeActions,
2179
+ createGroupFileActions
2180
+ ];
2181
+ /** 构建 Milky 动作注册表(64 个动作,领域工厂遍历注册)。 */
2246
2182
  function createMilkyActionRegistry(opts) {
2247
2183
  const registry = new ActionRegistry();
2248
- const { api } = opts;
2249
- registry.register(new GetLoginInfoAction(api));
2250
- registry.register(new GetImplInfoAction(api));
2251
- registry.register(new SendPrivateMessageAction(api));
2252
- registry.register(new SendGroupMessageAction(api));
2253
- registry.register(new GetMessageAction(api));
2254
- registry.register(new RecallPrivateMessageAction(api));
2255
- registry.register(new RecallGroupMessageAction(api));
2256
- registry.register(new GetFriendListAction(api));
2257
- registry.register(new GetGroupListAction(api));
2258
- registry.register(new GetUserProfileAction(api));
2259
- registry.register(new GetFriendInfoAction(api));
2260
- registry.register(new SetAvatarAction(api));
2261
- registry.register(new SetNicknameAction(api));
2262
- registry.register(new SetBioAction(api));
2263
- registry.register(new GetCookiesAction(api));
2264
- registry.register(new GetCSRFTokenAction(api));
2265
- registry.register(new SendProfileLikeAction(api));
2266
- registry.register(new DeleteFriendAction(api));
2267
- registry.register(new GetFriendRequestsAction(api));
2268
- registry.register(new AcceptFriendRequestAction(api));
2269
- registry.register(new RejectFriendRequestAction(api));
2270
- registry.register(new GetHistoryMessagesAction(api));
2271
- registry.register(new GetForwardedMessagesAction(api));
2272
- registry.register(new MarkMessageAsReadAction(api));
2273
- registry.register(new GetGroupInfoAction(api));
2274
- registry.register(new GetGroupMemberListAction(api));
2275
- registry.register(new GetGroupMemberInfoAction(api));
2276
- registry.register(new SetGroupNameAction(api));
2277
- registry.register(new SetGroupMemberCardAction(api));
2278
- registry.register(new SetGroupMemberAdminAction(api));
2279
- registry.register(new SetGroupMemberMuteAction(api));
2280
- registry.register(new SetGroupWholeMuteAction(api));
2281
- registry.register(new KickGroupMemberAction(api));
2282
- registry.register(new QuitGroupAction(api));
2283
- registry.register(new GetGroupEssenceMessagesAction(api));
2284
- registry.register(new SetGroupEssenceMessageAction(api));
2285
- registry.register(new SendGroupMessageReactionAction(api));
2286
- registry.register(new GetGroupNotificationsAction(api));
2287
- registry.register(new AcceptGroupRequestAction(api));
2288
- registry.register(new RejectGroupRequestAction(api));
2289
- registry.register(new AcceptGroupInvitationAction(api));
2290
- registry.register(new RejectGroupInvitationAction(api));
2291
- registry.register(new GetGroupFilesAction(api));
2292
- registry.register(new MoveGroupFileAction(api));
2293
- registry.register(new RenameGroupFileAction(api));
2294
- registry.register(new DeleteGroupFileAction(api));
2295
- registry.register(new PersistGroupFileAction(api));
2296
- registry.register(new CreateGroupFolderAction(api));
2297
- registry.register(new DeleteGroupFolderAction(api));
2298
- registry.register(new SendFriendNudgeAction(api));
2299
- registry.register(new GetPeerPinsAction(api));
2300
- registry.register(new SetPeerPinAction(api));
2301
- registry.register(new SendGroupNudgeAction(api));
2302
- registry.register(new GetGroupAnnouncementsAction(api));
2303
- registry.register(new SendGroupAnnouncementAction(api));
2304
- registry.register(new DeleteGroupAnnouncementAction(api));
2305
- registry.register(new SetGroupAvatarAction(api));
2306
- registry.register(new SetGroupMemberSpecialTitleAction(api));
2307
- registry.register(new GetCustomFaceUrlListAction(api));
2308
- registry.register(new GetResourceTempUrlAction(api));
2309
- registry.register(new UploadPrivateFileAction(api));
2310
- registry.register(new UploadGroupFileAction(api));
2311
- registry.register(new GetGroupFileDownloadUrlAction(api));
2312
- registry.register(new RenameGroupFolderAction(api));
2184
+ for (const factory of ACTION_FACTORIES) for (const action of factory(opts.api)) registry.register(action);
2313
2185
  return registry;
2314
2186
  }
2315
2187
  // src/milky/enrichment.ts
@@ -2369,13 +2241,21 @@ var MilkyEventPipeline = class {
2369
2241
  constructor(deps) {
2370
2242
  this.deps = deps;
2371
2243
  }
2372
- /** 订阅 kernel 事件(消息 + 群 + 好友 + 批次三,幂等;路由到 inbound/)。 */
2244
+ /** 事件链异步失败兜底(单条/整批丢弃,warn 留痕不打断订阅)。 */
2245
+ logFailure(kind, err) {
2246
+ logEventFailure(this.deps.logger, `milky: ${kind} 翻译失败(丢弃)`, err);
2247
+ }
2248
+ /** 订阅 kernel 事件(消息 + 群 + 好友 + ,幂等;路由到 inbound/)。 */
2373
2249
  subscribe() {
2374
2250
  if (this.unsubscribes.length > 0) return;
2375
2251
  const { msgChannel, groupChannel, buddyChannel, recentContactChannel, loginChannel } = this.deps;
2376
- this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) => void this.deps.message.handle(msg)), 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)));
2252
+ this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) => this.deps.message.handle(msg).catch((err) => {
2253
+ 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)));
2377
2255
  if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
2378
- this.deps.request.groupNotifies(doubt, notifies);
2256
+ this.deps.request.groupNotifies(doubt, notifies).catch((err) => {
2257
+ this.logFailure("group request", err);
2258
+ });
2379
2259
  }), groupChannel.on("Group/onGroupEssenceListChange", (a) => this.deps.essence.change(a)));
2380
2260
  if (buddyChannel !== void 0) this.unsubscribes.push(buddyChannel.on("Buddy/onBuddyReqChange", (a) => this.deps.request.buddyReqs(a)));
2381
2261
  if (recentContactChannel !== void 0) {
@@ -2404,7 +2284,7 @@ var MessageSeqIndex = class {
2404
2284
  seqToMsg = /* @__PURE__ */ new Map();
2405
2285
  /** msgId → seq 元信息。 */
2406
2286
  msgToMeta = /* @__PURE__ */ new Map();
2407
- /** 合并转发 resId → 定位信息(P1:get_forwarded_messages)。 */
2287
+ /** 合并转发 resId → 定位信息(get_forwarded_messages)。 */
2408
2288
  forwards = /* @__PURE__ */ new Map();
2409
2289
  /** 接收链路登记(一条消息双向写入;重复 msgId 覆盖)。 */
2410
2290
  record(msg) {
@@ -2414,7 +2294,7 @@ var MessageSeqIndex = class {
2414
2294
  this.msgToMeta.set(msg.msgId, {
2415
2295
  seq,
2416
2296
  senderUin: msg.senderUin,
2417
- timeSec: Math.floor(Number(msg.msgTime) / 1e3)
2297
+ timeSec: toUnixSeconds(msg.msgTime)
2418
2298
  });
2419
2299
  this.evict();
2420
2300
  }
@@ -2475,7 +2355,7 @@ var MessageSeqIndex = class {
2475
2355
  };
2476
2356
  // src/milky/helper/state/recent-keys.ts
2477
2357
  /**
2478
- * 带过期去重键缓存(Milky 批次三)
2358
+ * 带过期去重键缓存(Milky)
2479
2359
  *
2480
2360
  * 两个场景共用:friend_file_upload 双回调(onRecvOfflineFileMsg / onFileMsgCome
2481
2361
  * 同载荷,按 msgId 去重)与 group_essence_message_change 双路径(732:1 快路径
@@ -2564,7 +2444,7 @@ var MilkyInboundEssence = class {
2564
2444
  };
2565
2445
  // src/milky/helper/event/file-upload.ts
2566
2446
  /**
2567
- * friend_file_upload 翻译(Milky 批次三,2026-11-01 录制定型)
2447
+ * friend_file_upload 翻译(Milky ,录制定型)
2568
2448
  *
2569
2449
  * 源:Msg/onRecvOfflineFileMsg 与 Msg/onFileMsgCome(同载荷 RawMessage 数组,
2570
2450
  * 双回调按 msgId 在适配器去重);fileElement{fileName, fileSize 字符串,
@@ -2590,126 +2470,6 @@ function toFriendFileUploadData(msg, selfUin, uidToUin) {
2590
2470
  is_self: isSelf
2591
2471
  };
2592
2472
  }
2593
- // src/milky/helper/event/peer-pin.ts
2594
- /**
2595
- * peer_pin_change 翻译(Milky 批次三,RecentContact/onRecentContactListChangedVer2)
2596
- *
2597
- * 回调随消息活动高频快照(含 topFlag 的全量条目 + chatType=7 影子条目),
2598
- * 不能见条目就广播——按「同会话 topFlag 前后值翻转」检测(PinWatch)。
2599
- * 启动期以 getPinnedContacts 播种基线(重启后首个取消置顶也能观测到)。
2600
- *
2601
- * 证据:2026-11-01 set_peer_pin 自触发翻转实验——changedList 条目
2602
- * {chatType, peerUin, topFlag(1/0), topFlagTime(秒级 unix 字符串)},与操作
2603
- * 一一对应(milky.md §0.8.6)。
2604
- */
2605
- /** uin 形判别(peer_id 必须是数字串)。 */
2606
- const NUMERIC_RE$1 = /^\d+$/;
2607
- /** 置顶翻转检测(每适配器实例一份,键 = chatType:peerUin——群号与 uin 数值空间可重叠)。 */
2608
- var PinWatch = class {
2609
- states = /* @__PURE__ */ new Map();
2610
- /** 启动基线:置顶会话播种(只记状态,不产生事件)。 */
2611
- seed(pins) {
2612
- for (const pin of pins) {
2613
- if (pin.peerUin === void 0 || pin.peerUin === "") continue;
2614
- const chatType = pin.scene === "group" ? ChatType.GROUP : ChatType.C2C;
2615
- this.states.set(`${chatType}:${pin.peerUin}`, 1);
2616
- }
2617
- }
2618
- /**
2619
- * 观测一个变更条目:topFlag 相对上次观测翻转 → true(应广播);
2620
- * 首见(基线未建立)或未变 → false。
2621
- */
2622
- observe(chatType, peerUin, topFlag) {
2623
- const key = `${chatType}:${peerUin}`;
2624
- const prev = this.states.get(key);
2625
- this.states.set(key, topFlag);
2626
- return prev !== void 0 && prev !== topFlag;
2627
- }
2628
- };
2629
- /** 场景映射(changedList 条目 chatType → Milky message_scene;影子/其他类型丢弃)。 */
2630
- function pinScene(chatType) {
2631
- if (chatType === ChatType.GROUP) return "group";
2632
- if (chatType === ChatType.C2C) return "friend";
2633
- return null;
2634
- }
2635
- /** 变更条目 → 事件载荷(null = 条目不含置顶字段/场景不支持,跳过不广播)。 */
2636
- function toPeerPinChangeData(entry) {
2637
- const scene = pinScene(entry.chatType);
2638
- if (scene === null || entry.topFlag === void 0) return null;
2639
- const peerUin = typeof entry.peerUin === "string" && entry.peerUin !== "" ? entry.peerUin : scene === "group" ? entry.peerUid : "";
2640
- if (peerUin === "" || !NUMERIC_RE$1.test(peerUin)) return null;
2641
- return {
2642
- data: {
2643
- message_scene: scene,
2644
- peer_id: Number(peerUin),
2645
- is_pinned: entry.topFlag === 1
2646
- },
2647
- topFlagTime: typeof entry.topFlagTime === "string" ? entry.topFlagTime : void 0,
2648
- peerUin
2649
- };
2650
- }
2651
- // src/milky/inbound/pin.ts
2652
- /** Milky 置顶域处理器(翻转检测 + 播种基线 + peer_pin_change 广播)。 */
2653
- var MilkyInboundPin = class {
2654
- deps;
2655
- /** peer_pin 翻转检测(批次三;启动期 getPinnedContacts 播种)。 */
2656
- pinWatch = new PinWatch();
2657
- constructor(deps) {
2658
- this.deps = deps;
2659
- }
2660
- /** 会话列表变更 → 翻转检测逐条处理(首见/未变/不支持场景静默跳过)。 */
2661
- handleChanges(lists) {
2662
- const arr = Array.isArray(lists) ? lists : [lists];
2663
- for (const list of arr) for (const entry of changedListOf(list)) this.handleEntry(entry);
2664
- }
2665
- /** 启动基线:置顶会话播种(2026-11-14 起失败补 debug 日志,不再静默)。 */
2666
- seed() {
2667
- this.deps.api.recentContactApi.getPinnedContacts().then((pins) => {
2668
- this.pinWatch.seed(pins);
2669
- }).catch((err) => {
2670
- this.deps.logger?.debug({ err: String(err) }, "milky: 置顶基线播种失败(跳过)");
2671
- });
2672
- }
2673
- /** 单个变更条目:翻译 + 翻转检测 + 广播。 */
2674
- handleEntry(entry) {
2675
- const payload = pinPayloadOf(entry);
2676
- if (payload === null) return;
2677
- if (!this.pinWatch.observe(payload.chatType, payload.peerUin, payload.topFlag)) return;
2678
- this.deps.broadcast({
2679
- time: secondsOf(payload.topFlagTime),
2680
- self_id: Number(this.deps.api.self.uin),
2681
- event_type: "peer_pin_change",
2682
- data: payload.data
2683
- });
2684
- }
2685
- };
2686
- /** 变更列表 → changedList 条目数组(形状不符 → 空)。 */
2687
- function changedListOf(list) {
2688
- if (list === null || typeof list !== "object") return [];
2689
- const changed = list.changedList;
2690
- return Array.isArray(changed) ? changed : [];
2691
- }
2692
- /** 变更条目 → 翻转检测输入(null = 条目不支持/缺置顶字段)。 */
2693
- function pinPayloadOf(entry) {
2694
- if (entry === null || typeof entry !== "object") return null;
2695
- return pinPayloadFrom(entry);
2696
- }
2697
- function pinPayloadFrom(contact) {
2698
- const topFlag = contact.topFlag;
2699
- const payload = toPeerPinChangeData(contact);
2700
- if (topFlag === void 0 || payload === null) return null;
2701
- return {
2702
- chatType: contact.chatType,
2703
- peerUin: payload.peerUin,
2704
- topFlag,
2705
- topFlagTime: payload.topFlagTime,
2706
- data: payload.data
2707
- };
2708
- }
2709
- /** 秒级时间戳归一(空/非法 → 当前时间;topFlagTime/msgTime 均为秒级字符串)。 */
2710
- function secondsOf(raw) {
2711
- return numericUin(raw ?? null) ?? Math.floor(Date.now() / 1e3);
2712
- }
2713
2473
  // src/milky/inbound/file-notice.ts
2714
2474
  /**
2715
2475
  * Milky inbound 轻量通知域:私聊文件双回调(friend_file_upload,按 msgId 去重)
@@ -2734,7 +2494,7 @@ var MilkyInboundFileNotice = class {
2734
2494
  }, "milky: friend_file_upload senderUin 缺失(user_id=0)");
2735
2495
  if (!this.fileKeys.claim(`file:${msg.msgId}`)) return;
2736
2496
  this.deps.broadcast({
2737
- time: secondsOf(msg.msgTime),
2497
+ time: toUnixSeconds(msg.msgTime),
2738
2498
  self_id: Number(this.deps.api.self.uin),
2739
2499
  event_type: "friend_file_upload",
2740
2500
  data
@@ -2756,12 +2516,10 @@ var MilkyInboundFileNotice = class {
2756
2516
  }
2757
2517
  };
2758
2518
  // src/milky/helper/event/notice.ts
2759
- /** 毫秒 → 秒(Unix 时间戳)。 */
2760
- const MS_TO_SEC = 1e3;
2761
2519
  /** 事件信封公共字段。 */
2762
2520
  function envelope(msg, ctx, eventType, data) {
2763
2521
  return {
2764
- time: Math.floor(Number(msg.msgTime) / MS_TO_SEC),
2522
+ time: toUnixSeconds(msg.msgTime),
2765
2523
  self_id: Number(ctx.selfUin),
2766
2524
  event_type: eventType,
2767
2525
  data
@@ -2782,7 +2540,7 @@ const GROUP_CHANGE_MAPPERS = {
2782
2540
  [TipGroupElementType.DISBANDED]: toDisband
2783
2541
  };
2784
2542
  function groupElementToEvent(msg, grp, ctx) {
2785
- if (grp === void 0 || grp.type === void 0) return null;
2543
+ if (grp == null || grp.type === void 0) return null;
2786
2544
  const mapper = GROUP_CHANGE_MAPPERS[grp.type];
2787
2545
  if (mapper === void 0) return null;
2788
2546
  return mapper(msg, groupChangeCommon(grp, Number(msg.peerUid)), grp, ctx);
@@ -2885,7 +2643,7 @@ function aioOpToEvent(msg, g, ctx) {
2885
2643
  function toMilkyNoticeEvent(msg, ctx) {
2886
2644
  for (const el of msg.elements) {
2887
2645
  const g = el.grayTipElement;
2888
- if (g === void 0) continue;
2646
+ if (g == null) continue;
2889
2647
  const event = translateGrayTip(msg, g, ctx);
2890
2648
  if (event !== null) return event;
2891
2649
  }
@@ -2962,6 +2720,126 @@ var MilkyInboundMessage = class {
2962
2720
  return msg.elements.find((el) => el.multiForwardMsgElement != null)?.multiForwardMsgElement;
2963
2721
  }
2964
2722
  };
2723
+ // src/milky/helper/event/peer-pin.ts
2724
+ /**
2725
+ * peer_pin_change 翻译(Milky ,RecentContact/onRecentContactListChangedVer2)
2726
+ *
2727
+ * 回调随消息活动高频快照(含 topFlag 的全量条目 + chatType=7 影子条目),
2728
+ * 不能见条目就广播——按「同会话 topFlag 前后值翻转」检测(PinWatch)。
2729
+ * 启动期以 getPinnedContacts 播种基线(重启后首个取消置顶也能观测到)。
2730
+ *
2731
+ * 证据:set_peer_pin 自触发翻转实验——changedList 条目
2732
+ * {chatType, peerUin, topFlag(1/0), topFlagTime(秒级 unix 字符串)},与操作
2733
+ * 一一对应(milky.md §0.8.6)。
2734
+ */
2735
+ /** uin 形判别(peer_id 必须是数字串)。 */
2736
+ const NUMERIC_RE$1 = /^\d+$/;
2737
+ /** 置顶翻转检测(每适配器实例一份,键 = chatType:peerUin——群号与 uin 数值空间可重叠)。 */
2738
+ var PinWatch = class {
2739
+ states = /* @__PURE__ */ new Map();
2740
+ /** 启动基线:置顶会话播种(只记状态,不产生事件)。 */
2741
+ seed(pins) {
2742
+ for (const pin of pins) {
2743
+ if (pin.peerUin === void 0 || pin.peerUin === "") continue;
2744
+ const chatType = pin.scene === "group" ? ChatType.GROUP : ChatType.C2C;
2745
+ this.states.set(`${chatType}:${pin.peerUin}`, 1);
2746
+ }
2747
+ }
2748
+ /**
2749
+ * 观测一个变更条目:topFlag 相对上次观测翻转 → true(应广播);
2750
+ * 首见(基线未建立)或未变 → false。
2751
+ */
2752
+ observe(chatType, peerUin, topFlag) {
2753
+ const key = `${chatType}:${peerUin}`;
2754
+ const prev = this.states.get(key);
2755
+ this.states.set(key, topFlag);
2756
+ return prev !== void 0 && prev !== topFlag;
2757
+ }
2758
+ };
2759
+ /** 场景映射(changedList 条目 chatType → Milky message_scene;影子/其他类型丢弃)。 */
2760
+ function pinScene(chatType) {
2761
+ if (chatType === ChatType.GROUP) return "group";
2762
+ if (chatType === ChatType.C2C) return "friend";
2763
+ return null;
2764
+ }
2765
+ /** 变更条目 → 事件载荷(null = 条目不含置顶字段/场景不支持,跳过不广播)。 */
2766
+ function toPeerPinChangeData(entry) {
2767
+ const scene = pinScene(entry.chatType);
2768
+ if (scene === null || entry.topFlag === void 0) return null;
2769
+ const peerUin = typeof entry.peerUin === "string" && entry.peerUin !== "" ? entry.peerUin : scene === "group" ? entry.peerUid : "";
2770
+ if (peerUin === "" || !NUMERIC_RE$1.test(peerUin)) return null;
2771
+ return {
2772
+ data: {
2773
+ message_scene: scene,
2774
+ peer_id: Number(peerUin),
2775
+ is_pinned: entry.topFlag === 1
2776
+ },
2777
+ topFlagTime: typeof entry.topFlagTime === "string" ? entry.topFlagTime : void 0,
2778
+ peerUin
2779
+ };
2780
+ }
2781
+ // src/milky/inbound/pin.ts
2782
+ /** Milky 置顶域处理器(翻转检测 + 播种基线 + peer_pin_change 广播)。 */
2783
+ var MilkyInboundPin = class {
2784
+ deps;
2785
+ /** peer_pin 翻转检测(启动期 getPinnedContacts 播种)。 */
2786
+ pinWatch = new PinWatch();
2787
+ constructor(deps) {
2788
+ this.deps = deps;
2789
+ }
2790
+ /** 会话列表变更 → 翻转检测逐条处理(首见/未变/不支持场景静默跳过)。 */
2791
+ handleChanges(lists) {
2792
+ const arr = Array.isArray(lists) ? lists : [lists];
2793
+ for (const list of arr) for (const entry of changedListOf(list)) this.handleEntry(entry);
2794
+ }
2795
+ /** 启动基线:置顶会话播种(失败补 debug 日志,不再静默)。 */
2796
+ seed() {
2797
+ this.deps.api.recentContactApi.getPinnedContacts().then((pins) => {
2798
+ this.pinWatch.seed(pins);
2799
+ }).catch((err) => {
2800
+ this.deps.logger?.debug({ err: String(err) }, "milky: 置顶基线播种失败(跳过)");
2801
+ });
2802
+ }
2803
+ /** 单个变更条目:翻译 + 翻转检测 + 广播。 */
2804
+ handleEntry(entry) {
2805
+ const payload = pinPayloadOf(entry);
2806
+ if (payload === null) return;
2807
+ if (!this.pinWatch.observe(payload.chatType, payload.peerUin, payload.topFlag)) return;
2808
+ this.deps.broadcast({
2809
+ time: secondsOf(payload.topFlagTime),
2810
+ self_id: Number(this.deps.api.self.uin),
2811
+ event_type: "peer_pin_change",
2812
+ data: payload.data
2813
+ });
2814
+ }
2815
+ };
2816
+ /** 变更列表 → changedList 条目数组(形状不符 → 空)。 */
2817
+ function changedListOf(list) {
2818
+ if (list === null || typeof list !== "object") return [];
2819
+ const changed = list.changedList;
2820
+ return Array.isArray(changed) ? changed : [];
2821
+ }
2822
+ /** 变更条目 → 翻转检测输入(null = 条目不支持/缺置顶字段)。 */
2823
+ function pinPayloadOf(entry) {
2824
+ if (entry === null || typeof entry !== "object") return null;
2825
+ return pinPayloadFrom(entry);
2826
+ }
2827
+ function pinPayloadFrom(contact) {
2828
+ const topFlag = contact.topFlag;
2829
+ const payload = toPeerPinChangeData(contact);
2830
+ if (topFlag === void 0 || payload === null) return null;
2831
+ return {
2832
+ chatType: contact.chatType,
2833
+ peerUin: payload.peerUin,
2834
+ topFlag,
2835
+ topFlagTime: payload.topFlagTime,
2836
+ data: payload.data
2837
+ };
2838
+ }
2839
+ /** 秒级时间戳归一(空/非法 → 当前时间;topFlagTime/msgTime 均为秒级字符串)。 */
2840
+ function secondsOf(raw) {
2841
+ return numericUin(raw ?? null) ?? Math.floor(Date.now() / 1e3);
2842
+ }
2965
2843
  // src/milky/inbound/request.ts
2966
2844
  /** Milky 请求域处理器(群通知 / 好友申请的 uid 回填与广播)。 */
2967
2845
  var MilkyInboundRequest = class {
@@ -2979,7 +2857,7 @@ var MilkyInboundRequest = class {
2979
2857
  }
2980
2858
  /** 好友请求通道:Buddy/onBuddyReqChange(防御收窄,未知形状 raw 日志)。 */
2981
2859
  buddyReqs(arg) {
2982
- this.broadcastBuddyReqs(arg);
2860
+ this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "milky: friend request 翻译失败(整批丢弃)", err));
2983
2861
  }
2984
2862
  async broadcastBuddyReqs(arg) {
2985
2863
  const reqs = narrowBuddyReqs(arg);
@@ -3001,7 +2879,7 @@ var MilkyInboundRequest = class {
3001
2879
  };
3002
2880
  // src/milky/helper/event/sysmsg.ts
3003
2881
  /**
3004
- * Milky sysmsg 识别表(批次三,2026-11-01;识别机制共享自 core/sysmsg.ts)
2882
+ * Milky sysmsg 识别表(识别机制共享自 shared/sysmsg.ts)
3005
2883
  *
3006
2884
  * 键 = 原生分发键 "msgType:subType",规则产出事件 data 体(信封 time/self_id/
3007
2885
  * event_type 由适配器统一包装)。路径依据 = 三轮录制 wire bytes 全量解码
@@ -3011,8 +2889,8 @@ var MilkyInboundRequest = class {
3011
2889
  * f3={f1 faceId 字符串, f5: 1=添加/2=撤销, f3:1 仅添加时存在}}。
3012
2890
  * operator 不在 push(f4=bot 自身 uid 占位)——user_id 省略。
3013
2891
  * - 732:1 群精华设置:f1.f1=群号, f1.f8.f8.f1=msgSeq(路径提取共享自
3014
- * core/shared/essence.ts extractEssenceSetSysMsg);取消精华无独立 sysmsg
3015
- * (remove 走 onGroupEssenceListChange 列表 diff,core/shared/essence.ts)。
2892
+ * shared/essence.ts extractEssenceSetSysMsg);取消精华无独立 sysmsg
2893
+ * (remove 走 onGroupEssenceListChange 列表 diff,shared/essence.ts)。
3016
2894
  * - 528:349/381/382 多端设备同步族:不广播。
3017
2895
  */
3018
2896
  /** 数字串判别(faceId 实证为数字字符串)。 */
@@ -3092,7 +2970,7 @@ function recognizeMilkySysMsg(msgType, subType, table = KIND_TABLE) {
3092
2970
  // src/milky/inbound/sysmsg.ts
3093
2971
  /**
3094
2972
  * Milky inbound sysmsg 域:Msg/onRecvSysMsg 总闸——参数收窄(未知形状 raw warn)
3095
- * → 单条字节块走 core/shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 →
2973
+ * → 单条字节块走 shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 →
3096
2974
  * 信封 → 识别 → 分流)。表命中提取 data 体 → 精华快路径 claim 去重 → 信封包装
3097
2975
  * 广播;未识别 / 提取失败落校准路径,不广播半成品。
3098
2976
  */
@@ -3319,7 +3197,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
3319
3197
  seqIndex = new MessageSeqIndex();
3320
3198
  /** 动作注册表(公共只读:装配方/测试枚举)。 */
3321
3199
  registry;
3322
- /** 收链路事件管道(订阅 / 过滤 / 去重 / 翻译派发,2026-11-14 拆出)。 */
3200
+ /** 收链路事件管道(订阅 / 过滤 / 去重 / 翻译派发,拆出)。 */
3323
3201
  pipeline;
3324
3202
  stopTransports = null;
3325
3203
  constructor(opts) {
@@ -3362,7 +3240,8 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
3362
3240
  enrich
3363
3241
  }),
3364
3242
  fileNotice: new MilkyInboundFileNotice(base),
3365
- pin: new MilkyInboundPin(base)
3243
+ pin: new MilkyInboundPin(base),
3244
+ logger: opts.logger
3366
3245
  });
3367
3246
  this.registry = createMilkyActionRegistry({ api: this.api });
3368
3247
  }
@@ -3406,7 +3285,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
3406
3285
  };
3407
3286
  // src/milky/config.ts
3408
3287
  /**
3409
- * Milky 协议配置(zod schema,归属本包,ADR-012)
3288
+ * Milky 协议配置(zod schema,归属本包)
3410
3289
  *
3411
3290
  * 单一 TOML 的 `[accounts.milky]` 账号段(docs/protocols/milky.md §4):
3412
3291
  * 单端口 HTTP 模型(/api + /event 同端口),`enabled` 缺省 false = 不启用。