@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,18 +1,30 @@
1
- import { S as ActionRegistry, _ as ensureSilk, b as BaseProtocolAdapter, c as narrowSysMsgBlobs, d as recognizeSysMsg, t as toUnixSeconds, u as processSysMsgBlob, v as prepareVideoElements, x as BaseAction } from "../core-DOyFBFOW.mjs";
2
- import { n as senderNickname, r as subscribeRawMessages } from "../raw-message-D2vA27kj.mjs";
3
- import { a as MS_TO_SEC$2, c as toUin, i as hasGrayTip, o as numericUin, r as firstUntranslatedGrayTip, t as collectGrayTipUids } from "../gray-tip-C0pnbB__.mjs";
4
- import { a as narrowEssenceGroupArg, i as extractEssenceSetSysMsg, n as truncRaw, o as narrowBuddyReqs, r as EssenceListSync, t as sliceRaw } from "../log-DYEB3Eto.mjs";
5
- import { n as createWsServerSchema, t as createHttpServerSchema } from "../transport-schema-BEzr06W3.mjs";
1
+ import { i as runAction, n as BaseProtocolAdapter, r as ActionRegistry } from "../core-D5c78lFV.mjs";
2
+ import { i as toUnixSeconds, n as senderNickname, r as subscribeRawMessages } from "../raw-message-DE3sdJg8.mjs";
3
+ import { n as prepareVideoElements, r as createServerSchema, t as ensureSilk } from "../media-DMMn74TC.mjs";
4
+ import { c as MS_TO_SEC, d as toUin, i as collectGrayTipUids, l as numericUin, n as sliceRaw, o as firstUntranslatedGrayTip, r as truncRaw, s as hasGrayTip, t as logEventFailure } from "../log-BsInJV_y.mjs";
5
+ import { d as narrowBuddyReqs, i as narrowSysMsgBlobs, n as extractEssenceSetSysMsg, o as processSysMsgBlob, r as narrowEssenceGroupArg, s as recognizeSysMsg, t as EssenceListSync } from "../essence-Bxs-aKSC.mjs";
6
6
  import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, kernelError, toCanonicalElements } from "@napuketto/kernel";
7
- import { basename, join } from "node:path";
8
- import { downloadUrl, inferExtension } from "@napuketto/media";
9
7
  import { z } from "zod";
10
8
  import { randomUUID } from "node:crypto";
11
9
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
10
+ import { basename, join } from "node:path";
11
+ import { downloadUrl, inferExtension } from "@napuketto/media";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { HttpClient, HttpServer, WsClient, WsServer } from "@napuketto/network";
14
- // src/onebot11/action/error-map.ts
15
- /** OB11 错误码映射表(send_msg 等所有 OB11 动作共用)。 */
14
+ // src/onebot11/action/base-action.ts
15
+ /**
16
+ * OB11 动作运行时:声明式动作工厂 + 响应信封 + 错误码映射 + 共享解析助手。
17
+ *
18
+ * 动作 = `{ name, schema, handle }` 声明对象,经 defineOb11Action 组装出
19
+ * HTTP `handle`(校验失败 retcode=400)与 WS `websocketHandle`(1400 +
20
+ * echo 透传)两个入口;执行骨架走 core runAction(zod safeParse → 执行 →
21
+ * isKernelError 统一映射,映射表收拢为本文件 ob11ErrorCodeMap)。
22
+ */
23
+ /** 校验失败 retcode:HTTP 入口。 */
24
+ const INVALID_RETCODE_HTTP = 400;
25
+ /** 校验失败 retcode:WS 入口。 */
26
+ const INVALID_RETCODE_WS = 1400;
27
+ /** OB11 错误码映射表(kernel KernelErrorCode → retcode;全部 OB11 动作共用)。 */
16
28
  const ob11ErrorCodeMap = {
17
29
  SEND_FAILED: 100,
18
30
  PERMISSION_DENIED: 101,
@@ -23,11 +35,37 @@ const ob11ErrorCodeMap = {
23
35
  INVALID_STATE: 106,
24
36
  UNKNOWN: 999
25
37
  };
26
- // src/onebot11/action/resolve-uid.ts
27
- /**
28
- * OB11 用户 ID 解析(uin → uid,多个动作共用,2026-08-08 克隆合并)
29
- */
30
- /** 解析单个 uin → uid(失败抛 KernelError INVALID_PARAM)。 */
38
+ /** 声明式动作工厂:闭包依赖 + 统一信封与错误映射。 */
39
+ function defineOb11Action(spec) {
40
+ const run = async (payload, invalidRetcode, echo) => {
41
+ const outcome = await runAction({
42
+ schema: spec.schema,
43
+ handle: spec.handle,
44
+ errorCodeMap: ob11ErrorCodeMap,
45
+ invalidRetcode
46
+ }, payload);
47
+ const result = outcome.ok ? {
48
+ retcode: 0,
49
+ status: "ok",
50
+ data: outcome.data,
51
+ message: ""
52
+ } : {
53
+ retcode: outcome.retcode,
54
+ status: "failed",
55
+ data: null,
56
+ message: outcome.message
57
+ };
58
+ if (echo !== void 0) result.echo = echo;
59
+ return result;
60
+ };
61
+ return {
62
+ name: spec.name,
63
+ schema: spec.schema,
64
+ handle: (payload) => run(payload, INVALID_RETCODE_HTTP),
65
+ websocketHandle: (payload, echo) => run(payload, INVALID_RETCODE_WS, echo)
66
+ };
67
+ }
68
+ /** 解析单个 uin → uid(失败抛 KernelError INVALID_PARAM;多动作共用)。 */
31
69
  async function resolveUid(uin, uinToUid) {
32
70
  const uid = (await uinToUid([uin])).get(uin);
33
71
  if (uid === void 0) throw kernelError(`用户 ${uin} 的 uid 解析失败`, "INVALID_PARAM");
@@ -35,211 +73,126 @@ async function resolveUid(uin, uinToUid) {
35
73
  }
36
74
  // src/onebot11/action/friend/manage.ts
37
75
  /**
38
- * 好友管理域动作(2026-11-14 自 friend/ 微文件合并)
76
+ * 好友管理域动作
39
77
  *
40
- * - set_friend_add_request(P2-11):flag=reqTime(NapCat 约定,需从好友请求事件
41
- * 上报中获取)→ getBuddyReqList 匹配 → handleFriendRequest + optional remark
42
- * - set_friend_remark / delete_friend(P2-11):user_id 经 uin→uid
43
- * - set_doubt_friends_add_request(P2-11 可疑好友申请处理,NapCat 扩展;
44
- * approve 字段 NapCat 强制为 true,该接口无语义仅保留)
45
- * - send_like(P2-14):ProfileLikeApi.sendLike
78
+ * - set_friend_add_request:flag=reqTime(NapCat 约定,需从好友请求事件上报中
79
+ * 获取)→ getBuddyReqList 匹配 → handleFriendRequest + optional remark
80
+ * - set_friend_remark / delete_friend:user_id 经 uin→uid
81
+ * - set_doubt_friends_add_request(可疑好友申请处理,NapCat 扩展;approve 字段
82
+ * NapCat 强制为 true,该接口无语义仅保留)
83
+ * - send_like:ProfileLikeApi.sendLike
46
84
  */
47
- const setDoubtFriendsAddRequestSchema = z.object({
48
- flag: z.string(),
49
- approve: z.boolean().optional()
50
- });
51
- /** 处理可疑好友申请(P2-11 接 kernel handleDoubtFriendRequest)。 */
52
- var SetDoubtFriendsAddRequestAction = class extends BaseAction {
53
- name = "set_doubt_friends_add_request";
54
- schema = setDoubtFriendsAddRequestSchema;
55
- errorCodeMap = ob11ErrorCodeMap;
56
- friendApi;
57
- constructor(friendApi) {
58
- super();
59
- this.friendApi = friendApi;
60
- }
61
- _handle(payload) {
62
- this.friendApi.handleDoubtFriendRequest(payload.flag);
63
- return Promise.resolve(null);
64
- }
65
- };
66
- const setFriendAddRequestSchema = z.object({
67
- flag: z.string(),
68
- approve: z.boolean().optional(),
69
- remark: z.string().optional()
70
- });
71
- /** 处理加好友请求(P2-11 接 kernel FriendApi)。 */
72
- var SetFriendAddRequestAction = class extends BaseAction {
73
- name = "set_friend_add_request";
74
- schema = setFriendAddRequestSchema;
75
- errorCodeMap = ob11ErrorCodeMap;
76
- friendApi;
77
- constructor(friendApi) {
78
- super();
79
- this.friendApi = friendApi;
80
- }
81
- async _handle(payload) {
82
- const notify = (await this.friendApi.getBuddyReqList()).find((req) => req.reqTime === payload.flag);
83
- if (notify === void 0) throw kernelError("未找到对应的好友请求(flag 无效或已过期)", "NOT_FOUND");
84
- await this.friendApi.handleFriendRequest(notify, payload.approve !== false);
85
- if (payload.remark !== void 0) this.friendApi.setFriendRemark(notify.friendUid, payload.remark);
86
- return null;
87
- }
88
- };
89
- const setFriendRemarkSchema = z.object({
90
- user_id: z.number(),
91
- remark: z.string()
92
- });
93
- /** 设置好友备注(P2-11 接 kernel setFriendRemark)。 */
94
- var SetFriendRemarkAction = class extends BaseAction {
95
- name = "set_friend_remark";
96
- schema = setFriendRemarkSchema;
97
- errorCodeMap = ob11ErrorCodeMap;
98
- deps;
99
- constructor(deps) {
100
- super();
101
- this.deps = deps;
102
- }
103
- async _handle(payload) {
104
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
105
- this.deps.friendApi.setFriendRemark(uid, payload.remark);
106
- return null;
107
- }
108
- };
109
- const deleteFriendSchema = z.object({ user_id: z.number() });
110
- /** 删除好友(P2-11 接 kernel deleteFriend)。 */
111
- var DeleteFriendAction = class extends BaseAction {
112
- name = "delete_friend";
113
- schema = deleteFriendSchema;
114
- errorCodeMap = ob11ErrorCodeMap;
115
- deps;
116
- constructor(deps) {
117
- super();
118
- this.deps = deps;
119
- }
120
- async _handle(payload) {
121
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
122
- await this.deps.friendApi.deleteFriend(uid);
123
- return null;
124
- }
125
- };
126
- const sendLikeSchema = z.object({
127
- user_id: z.number(),
128
- times: z.number().optional()
129
- });
130
- /** 点赞(P2-14 接 kernel ProfileLikeApi)。 */
131
- var SendLikeAction = class extends BaseAction {
132
- name = "send_like";
133
- schema = sendLikeSchema;
134
- errorCodeMap = ob11ErrorCodeMap;
135
- deps;
136
- constructor(deps) {
137
- super();
138
- this.deps = deps;
139
- }
140
- async _handle(payload) {
141
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
142
- await this.deps.profileLikeApi.sendLike(uid, payload.times ?? 1);
143
- return null;
144
- }
145
- };
146
85
  /** 好友管理域动作工厂(friend_add_request / friend_remark / delete_friend /
147
86
  * doubt 申请处理 / send_like)。 */
148
87
  function createFriendManageActions(api) {
149
88
  return [
150
- new SetFriendAddRequestAction(api.friendApi),
151
- new SetFriendRemarkAction(api),
152
- new DeleteFriendAction(api),
153
- new SetDoubtFriendsAddRequestAction(api.friendApi),
154
- new SendLikeAction(api)
89
+ defineOb11Action({
90
+ name: "set_friend_add_request",
91
+ schema: z.object({
92
+ flag: z.string(),
93
+ approve: z.boolean().optional(),
94
+ remark: z.string().optional()
95
+ }),
96
+ handle: async (payload) => {
97
+ const notify = (await api.friendApi.getBuddyReqList()).find((req) => req.reqTime === payload.flag);
98
+ if (notify === void 0) throw kernelError("未找到对应的好友请求(flag 无效或已过期)", "NOT_FOUND");
99
+ await api.friendApi.handleFriendRequest(notify, payload.approve !== false);
100
+ if (payload.remark !== void 0) api.friendApi.setFriendRemark(notify.friendUid, payload.remark);
101
+ return null;
102
+ }
103
+ }),
104
+ defineOb11Action({
105
+ name: "set_friend_remark",
106
+ schema: z.object({
107
+ user_id: z.number(),
108
+ remark: z.string()
109
+ }),
110
+ handle: async (payload) => {
111
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
112
+ api.friendApi.setFriendRemark(uid, payload.remark);
113
+ return null;
114
+ }
115
+ }),
116
+ defineOb11Action({
117
+ name: "delete_friend",
118
+ schema: z.object({ user_id: z.number() }),
119
+ handle: async (payload) => {
120
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
121
+ await api.friendApi.deleteFriend(uid);
122
+ return null;
123
+ }
124
+ }),
125
+ defineOb11Action({
126
+ name: "set_doubt_friends_add_request",
127
+ schema: z.object({
128
+ flag: z.string(),
129
+ approve: z.boolean().optional()
130
+ }),
131
+ handle: async (payload) => {
132
+ api.friendApi.handleDoubtFriendRequest(payload.flag);
133
+ return null;
134
+ }
135
+ }),
136
+ defineOb11Action({
137
+ name: "send_like",
138
+ schema: z.object({
139
+ user_id: z.number(),
140
+ times: z.number().optional()
141
+ }),
142
+ handle: async (payload) => {
143
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
144
+ await api.profileLikeApi.sendLike(uid, payload.times ?? 1);
145
+ return null;
146
+ }
147
+ })
155
148
  ];
156
149
  }
157
150
  // src/onebot11/action/friend/query.ts
158
- const getFriendListSchema = z.object({
159
- /** 是否忽略缓存(go-cqhttp 扩展)。 */
160
- no_cache: z.boolean().optional() });
161
- /** 获取好友列表(P2-4 接 kernel apis/friend)。 */
162
- var GetFriendListAction = class extends BaseAction {
163
- name = "get_friend_list";
164
- schema = getFriendListSchema;
165
- errorCodeMap = ob11ErrorCodeMap;
166
- friendApi;
167
- constructor(friendApi) {
168
- super();
169
- this.friendApi = friendApi;
170
- }
171
- async _handle(_payload) {
172
- return (await this.friendApi.getFriendList()).map((f) => {
173
- const info = {
174
- user_id: Number(f.uin),
175
- nickname: f.nickname
176
- };
177
- if (f.remark !== "") info.remark = f.remark;
178
- return info;
179
- });
180
- }
181
- };
182
- const getFriendsWithCategorySchema = z.object({});
183
- /** 获取好友列表(含分类,P2-11 接 kernel getFriendCategories)。 */
184
- var GetFriendsWithCategoryAction = class extends BaseAction {
185
- name = "get_friends_with_category";
186
- schema = getFriendsWithCategorySchema;
187
- errorCodeMap = ob11ErrorCodeMap;
188
- friendApi;
189
- constructor(friendApi) {
190
- super();
191
- this.friendApi = friendApi;
192
- }
193
- _handle(_payload) {
194
- return this.friendApi.getFriendCategories();
195
- }
196
- };
197
- const getStrangerInfoSchema = z.object({
198
- user_id: z.number(),
199
- no_cache: z.boolean().optional()
200
- });
201
- /** 获取陌生人信息(P2-15 接 kernel ProfileApi)。 */
202
- var GetStrangerInfoAction = class extends BaseAction {
203
- name = "get_stranger_info";
204
- schema = getStrangerInfoSchema;
205
- errorCodeMap = ob11ErrorCodeMap;
206
- profileApi;
207
- constructor(profileApi) {
208
- super();
209
- this.profileApi = profileApi;
210
- }
211
- async _handle(payload) {
212
- return {
213
- ...await this.profileApi.getStrangerInfo(String(payload.user_id)),
214
- user_id: payload.user_id
215
- };
216
- }
217
- };
218
- const getDoubtFriendsAddRequestSchema = z.object({ count: z.number().optional() });
219
- /** 默认获取数量。 */
220
- const DEFAULT_COUNT$2 = 50;
221
- /** 获取可疑好友申请(P2-11 接 kernel getDoubtFriendRequest)。 */
222
- var GetDoubtFriendsAddRequestAction = class extends BaseAction {
223
- name = "get_doubt_friends_add_request";
224
- schema = getDoubtFriendsAddRequestSchema;
225
- errorCodeMap = ob11ErrorCodeMap;
226
- friendApi;
227
- constructor(friendApi) {
228
- super();
229
- this.friendApi = friendApi;
230
- }
231
- _handle(payload) {
232
- return this.friendApi.getDoubtFriendRequest(payload.count ?? DEFAULT_COUNT$2);
233
- }
234
- };
151
+ /** 可疑好友申请默认获取数量。 */
152
+ const DEFAULT_DOUBT_COUNT = 50;
235
153
  /** 好友查询域动作工厂(friend_list / friends_with_category / stranger_info /
236
154
  * doubt_friends_add_request)。 */
237
155
  function createFriendQueryActions(api) {
238
156
  return [
239
- new GetFriendListAction(api.friendApi),
240
- new GetFriendsWithCategoryAction(api.friendApi),
241
- new GetStrangerInfoAction(api.profileApi),
242
- new GetDoubtFriendsAddRequestAction(api.friendApi)
157
+ defineOb11Action({
158
+ name: "get_friend_list",
159
+ schema: z.object({
160
+ /** 是否忽略缓存(go-cqhttp 扩展)。 */
161
+ no_cache: z.boolean().optional() }),
162
+ handle: async () => {
163
+ return (await api.friendApi.getFriendList()).map((f) => {
164
+ const info = {
165
+ user_id: Number(f.uin),
166
+ nickname: f.nickname
167
+ };
168
+ if (f.remark !== "") info.remark = f.remark;
169
+ return info;
170
+ });
171
+ }
172
+ }),
173
+ defineOb11Action({
174
+ name: "get_friends_with_category",
175
+ schema: z.object({}),
176
+ handle: () => api.friendApi.getFriendCategories()
177
+ }),
178
+ defineOb11Action({
179
+ name: "get_stranger_info",
180
+ schema: z.object({
181
+ user_id: z.number(),
182
+ no_cache: z.boolean().optional()
183
+ }),
184
+ handle: async (payload) => {
185
+ return {
186
+ ...await api.profileApi.getStrangerInfo(String(payload.user_id)),
187
+ user_id: payload.user_id
188
+ };
189
+ }
190
+ }),
191
+ defineOb11Action({
192
+ name: "get_doubt_friends_add_request",
193
+ schema: z.object({ count: z.number().optional() }),
194
+ handle: (payload) => api.friendApi.getDoubtFriendRequest(payload.count ?? DEFAULT_DOUBT_COUNT)
195
+ })
243
196
  ];
244
197
  }
245
198
  // src/onebot11/helper/message-unique.ts
@@ -331,87 +284,25 @@ function resolveMsgIdAndPeer(messageId, unique) {
331
284
  }
332
285
  // src/onebot11/action/group/essence.ts
333
286
  /**
334
- * 群精华/荣誉域动作(2026-11-14 自 set-essence-msg / delete-essence-msg /
335
- * get-essence-msg-list / get-group-honor-info 合并)
287
+ * 群精华/荣誉域动作
336
288
  *
337
- * - set/delete_essence_msg(P2-10):message_id → msgId + peer(MessageUnique 反查,
338
- * 需群消息)→ GroupApi.addGroupEssence / removeGroupEssence(共用 EssenceMsgBase)
339
- * - get_essence_msg_list(P2-15):qun.qq.com digest_list web 接口 → msg_list,
289
+ * - set/delete_essence_msg:message_id → msgId + peer(MessageUnique 反查,
290
+ * 需群消息)→ GroupApi.addGroupEssence / removeGroupEssence(共用实现)
291
+ * - get_essence_msg_list:qun.qq.com digest_list web 接口 → msg_list,
340
292
  * msg_content 映射 text/image 段
341
- * - get_group_honor_info(P2-15):qun.qq.com honorlist web 接口;type 缺省 all
293
+ * - get_group_honor_info:qun.qq.com honorlist web 接口;type 缺省 all
342
294
  */
343
- const setEssenceMsgSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
344
- /** 精华消息基类(set/delete 共用实现,2026-08-08 克隆合并)。 */
345
- var EssenceMsgBase = class extends BaseAction {
346
- errorCodeMap = ob11ErrorCodeMap;
347
- deps;
348
- constructor(deps) {
349
- super();
350
- this.deps = deps;
351
- }
352
- async _handle(payload) {
353
- const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
354
- if (peer.chatType !== ChatType.GROUP) throw kernelError("精华消息仅支持群聊消息", "INVALID_PARAM");
355
- await this.operate(peer.peerUid, msgId);
356
- return null;
357
- }
358
- };
359
- /** 设置精华消息(P2-10 接 kernel addGroupEssence)。 */
360
- var SetEssenceMsgAction = class extends EssenceMsgBase {
361
- name = "set_essence_msg";
362
- schema = setEssenceMsgSchema;
363
- async operate(groupCode, msgId) {
364
- await this.deps.groupApi.addGroupEssence(groupCode, msgId);
365
- }
366
- };
367
- const deleteEssenceMsgSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
368
- /** 取消精华消息(P2-10 接 kernel removeGroupEssence)。 */
369
- var DeleteEssenceMsgAction = class extends EssenceMsgBase {
370
- name = "delete_essence_msg";
371
- schema = deleteEssenceMsgSchema;
372
- async operate(groupCode, msgId) {
373
- await this.deps.groupApi.removeGroupEssence(groupCode, msgId);
374
- }
375
- };
376
- const getEssenceMsgListSchema = z.object({ group_id: z.number() });
377
295
  /** 文本段类型(msg_content.msg_type)。 */
378
296
  const MSG_TYPE_TEXT = 1;
379
297
  /** 图片段类型(msg_content.msg_type)。 */
380
298
  const MSG_TYPE_IMAGE = 3;
381
- /** 获取群精华消息列表(P2-15 接 kernel WebApi)。 */
382
- var GetEssenceMsgListAction = class extends BaseAction {
383
- name = "get_essence_msg_list";
384
- schema = getEssenceMsgListSchema;
385
- errorCodeMap = ob11ErrorCodeMap;
386
- webApi;
387
- constructor(webApi) {
388
- super();
389
- this.webApi = webApi;
390
- }
391
- async _handle(payload) {
392
- const list = await this.webApi.getEssenceMsgList(String(payload.group_id));
393
- const out = [];
394
- for (const item of list) {
395
- const content = [];
396
- for (const part of item.msg_content ?? []) {
397
- const seg = toSegment(part);
398
- if (seg !== null) content.push(seg);
399
- }
400
- out.push({
401
- msg_seq: item.msg_seq,
402
- msg_random: item.msg_random,
403
- sender_id: Number(item.sender_uin),
404
- sender_nick: item.sender_nick,
405
- operator_id: Number(item.add_digest_uin),
406
- operator_nick: item.add_digest_nick,
407
- operator_time: item.add_digest_time,
408
- message_id: 0,
409
- content
410
- });
411
- }
412
- return out;
413
- }
414
- };
299
+ /** set/delete 精华共用实现:message_id 反查 + 群聊校验 + 具体精华操作。 */
300
+ async function operateEssence(api, messageId, operate) {
301
+ const { msgId, peer } = resolveMsgIdAndPeer(messageId, api.messageUnique);
302
+ if (peer.chatType !== ChatType.GROUP) throw kernelError("精华消息仅支持群聊消息", "INVALID_PARAM");
303
+ await operate(peer.peerUid, msgId);
304
+ return null;
305
+ }
415
306
  /** msg_content 项 → OB11 段(1=text 3=image,纯函数)。 */
416
307
  function toSegment(part) {
417
308
  if (part.msg_type === MSG_TYPE_TEXT) return {
@@ -424,25 +315,6 @@ function toSegment(part) {
424
315
  };
425
316
  return null;
426
317
  }
427
- const getGroupHonorInfoSchema = z.object({
428
- group_id: z.number(),
429
- type: z.string().optional()
430
- });
431
- /** 获取群荣誉信息(P2-15 接 kernel WebApi)。 */
432
- var GetGroupHonorInfoAction = class extends BaseAction {
433
- name = "get_group_honor_info";
434
- schema = getGroupHonorInfoSchema;
435
- errorCodeMap = ob11ErrorCodeMap;
436
- webApi;
437
- constructor(webApi) {
438
- super();
439
- this.webApi = webApi;
440
- }
441
- _handle(payload) {
442
- const type = mapHonorType(payload.type);
443
- return this.webApi.getGroupHonorInfo(String(payload.group_id), type);
444
- }
445
- };
446
318
  /** type 字符串 → WebHonorType(talkative/performer/legend/emotion/all,纯函数)。 */
447
319
  function mapHonorType(raw) {
448
320
  if (raw === "talkative") return WebHonorType.TALKATIVE;
@@ -454,62 +326,73 @@ function mapHonorType(raw) {
454
326
  /** 群精华/荣誉域动作工厂(set/delete_essence_msg / essence_msg_list / honor_info)。 */
455
327
  function createGroupEssenceActions(api) {
456
328
  return [
457
- new SetEssenceMsgAction(api),
458
- new DeleteEssenceMsgAction(api),
459
- new GetEssenceMsgListAction(api.webApi),
460
- new GetGroupHonorInfoAction(api.webApi)
329
+ defineOb11Action({
330
+ name: "set_essence_msg",
331
+ schema: z.object({ message_id: z.union([z.number(), z.string()]) }),
332
+ handle: (payload) => operateEssence(api, payload.message_id, (groupCode, msgId) => api.groupApi.addGroupEssence(groupCode, msgId))
333
+ }),
334
+ defineOb11Action({
335
+ name: "delete_essence_msg",
336
+ schema: z.object({ message_id: z.union([z.number(), z.string()]) }),
337
+ handle: (payload) => operateEssence(api, payload.message_id, (groupCode, msgId) => api.groupApi.removeGroupEssence(groupCode, msgId))
338
+ }),
339
+ defineOb11Action({
340
+ name: "get_essence_msg_list",
341
+ schema: z.object({ group_id: z.number() }),
342
+ handle: async (payload) => {
343
+ const list = await api.webApi.getEssenceMsgList(String(payload.group_id));
344
+ const out = [];
345
+ for (const item of list) {
346
+ const content = [];
347
+ for (const part of item.msg_content ?? []) {
348
+ const seg = toSegment(part);
349
+ if (seg !== null) content.push(seg);
350
+ }
351
+ out.push({
352
+ msg_seq: item.msg_seq,
353
+ msg_random: item.msg_random,
354
+ sender_id: Number(item.sender_uin),
355
+ sender_nick: item.sender_nick,
356
+ operator_id: Number(item.add_digest_uin),
357
+ operator_nick: item.add_digest_nick,
358
+ operator_time: item.add_digest_time,
359
+ message_id: 0,
360
+ content
361
+ });
362
+ }
363
+ return out;
364
+ }
365
+ }),
366
+ defineOb11Action({
367
+ name: "get_group_honor_info",
368
+ schema: z.object({
369
+ group_id: z.number(),
370
+ type: z.string().optional()
371
+ }),
372
+ handle: (payload) => api.webApi.getGroupHonorInfo(String(payload.group_id), mapHonorType(payload.type))
373
+ })
461
374
  ];
462
375
  }
463
376
  // src/onebot11/action/group/get-group-system-msg.ts
464
- const getGroupSystemMsgSchema = z.object({ count: z.number().optional() });
465
377
  /** 默认获取数量。 */
466
378
  const DEFAULT_COUNT$1 = 50;
467
- /** 获取群系统消息(P2-13 接 kernel GroupNotifyApi)。 */
468
- var GetGroupSystemMsgAction = class extends BaseAction {
469
- name = "get_group_system_msg";
470
- schema = getGroupSystemMsgSchema;
471
- errorCodeMap = ob11ErrorCodeMap;
472
- deps;
473
- constructor(deps) {
474
- super();
475
- this.deps = deps;
476
- }
477
- async _handle(payload) {
478
- const count = payload.count ?? DEFAULT_COUNT$1;
479
- const notifies = await this.deps.groupNotifyApi.getSingleScreenNotifies(false, count);
480
- const uinMap = await this.collectUinMap(notifies);
481
- const invited = [];
482
- const joined = [];
483
- for (const notify of notifies) {
484
- const info = toMessageInfo(notify, uinMap);
485
- if (notify.type === GroupNotifyMsgType.INVITED_BY_MEMBER) invited.push(info);
486
- else if (notify.type === GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS) joined.push(info);
379
+ /** 收集全部涉及的 uid 批量转 uin(循环外一次请求)。 */
380
+ async function collectUinMap(api, notifies) {
381
+ const uids = [];
382
+ for (const notify of notifies) {
383
+ const { user1, user2 } = notify;
384
+ if (user1 !== void 0) {
385
+ const { uid } = user1;
386
+ if (uid !== "") uids.push(uid);
487
387
  }
488
- const result = {
489
- invited_requests: invited,
490
- join_requests: joined
491
- };
492
- result["InvitedRequest"] = invited;
493
- return result;
494
- }
495
- /** 收集全部涉及的 uid 批量转 uin(循环外一次请求)。 */
496
- async collectUinMap(notifies) {
497
- const uids = [];
498
- for (const notify of notifies) {
499
- const { user1, user2 } = notify;
500
- if (user1 !== void 0) {
501
- const { uid } = user1;
502
- if (uid !== "") uids.push(uid);
503
- }
504
- if (user2 !== void 0) {
505
- const { uid } = user2;
506
- if (uid !== "") uids.push(uid);
507
- }
388
+ if (user2 !== void 0) {
389
+ const { uid } = user2;
390
+ if (uid !== "") uids.push(uid);
508
391
  }
509
- if (uids.length === 0) return /* @__PURE__ */ new Map();
510
- return await this.deps.uidToUin(uids);
511
392
  }
512
- };
393
+ if (uids.length === 0) return /* @__PURE__ */ new Map();
394
+ return await api.uidToUin(uids);
395
+ }
513
396
  /** GroupNotify → OB11 群系统消息结构(纯函数,uin 已批量转换)。 */
514
397
  function toMessageInfo(notify, uinMap) {
515
398
  const { seq, status, postscript, user1, user2, group } = notify;
@@ -555,205 +438,118 @@ function toMessageInfo(notify, uinMap) {
555
438
  }
556
439
  /** 群系统消息动作工厂(get_group_system_msg)。 */
557
440
  function createGroupSystemMsgActions(api) {
558
- return [new GetGroupSystemMsgAction(api)];
441
+ return [defineOb11Action({
442
+ name: "get_group_system_msg",
443
+ schema: z.object({ count: z.number().optional() }),
444
+ handle: async (payload) => {
445
+ const count = payload.count ?? DEFAULT_COUNT$1;
446
+ const notifies = await api.groupNotifyApi.getSingleScreenNotifies(false, count);
447
+ const uinMap = await collectUinMap(api, notifies);
448
+ const invited = [];
449
+ const joined = [];
450
+ for (const notify of notifies) {
451
+ const info = toMessageInfo(notify, uinMap);
452
+ if (notify.type === GroupNotifyMsgType.INVITED_BY_MEMBER) invited.push(info);
453
+ else if (notify.type === GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS) joined.push(info);
454
+ }
455
+ const result = {
456
+ invited_requests: invited,
457
+ join_requests: joined
458
+ };
459
+ result["InvitedRequest"] = invited;
460
+ return result;
461
+ }
462
+ })];
559
463
  }
560
464
  // src/onebot11/action/limits.ts
561
465
  /** 批量翻译的词条上限(translate_en2zh)。 */
562
466
  const MAX_TRANSLATE_WORDS = 2e3;
563
467
  // src/onebot11/action/group/group-files-op.ts
564
- const createGroupFileFolderSchema = z.object({
565
- group_id: z.number(),
566
- folder_name: z.string()
567
- });
568
- /** 创建群文件夹(P2-14)。 */
569
- var CreateGroupFileFolderAction = class extends BaseAction {
570
- name = "create_group_file_folder";
571
- schema = createGroupFileFolderSchema;
572
- errorCodeMap = ob11ErrorCodeMap;
573
- richMediaApi;
574
- constructor(richMediaApi) {
575
- super();
576
- this.richMediaApi = richMediaApi;
577
- }
578
- async _handle(payload) {
579
- return { folder_id: await this.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
580
- }
581
- };
582
- const deleteGroupFileSchema = z.object({
583
- group_id: z.number(),
584
- file_id: z.string(),
585
- /** 兼容 go-cqhttp 的 file_ids 数组(取第一个)。 */
586
- file_ids: z.array(z.string()).max(100).optional()
587
- });
588
- /** 删除群文件(P2-14)。 */
589
- var DeleteGroupFileAction = class extends BaseAction {
590
- name = "delete_group_file";
591
- schema = deleteGroupFileSchema;
592
- errorCodeMap = ob11ErrorCodeMap;
593
- richMediaApi;
594
- constructor(richMediaApi) {
595
- super();
596
- this.richMediaApi = richMediaApi;
597
- }
598
- async _handle(payload) {
599
- const ids = payload.file_ids ?? [payload.file_id];
600
- await this.richMediaApi.deleteGroupFile(String(payload.group_id), ids);
601
- return null;
602
- }
603
- };
604
- const deleteGroupFolderSchema = z.object({
605
- group_id: z.number(),
606
- folder_id: z.string()
607
- });
608
- /** 删除群文件夹(P2-14)。 */
609
- var DeleteGroupFolderAction = class extends BaseAction {
610
- name = "delete_group_folder";
611
- schema = deleteGroupFolderSchema;
612
- errorCodeMap = ob11ErrorCodeMap;
613
- richMediaApi;
614
- constructor(richMediaApi) {
615
- super();
616
- this.richMediaApi = richMediaApi;
617
- }
618
- async _handle(payload) {
619
- await this.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
620
- return null;
621
- }
622
- };
623
- const renameGroupFileSchema = z.object({
624
- group_id: z.number(),
625
- file_id: z.string(),
626
- new_name: z.string()
627
- });
628
- /** 重命名群文件(P2-14)。 */
629
- var RenameGroupFileAction = class extends BaseAction {
630
- name = "rename_group_file";
631
- schema = renameGroupFileSchema;
632
- errorCodeMap = ob11ErrorCodeMap;
633
- richMediaApi;
634
- constructor(richMediaApi) {
635
- super();
636
- this.richMediaApi = richMediaApi;
637
- }
638
- async _handle(payload) {
639
- await this.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_name);
640
- return null;
641
- }
642
- };
643
- const moveGroupFileSchema = z.object({
644
- group_id: z.number(),
645
- file_id: z.string(),
646
- file_ids: z.array(z.string()).max(100).optional(),
647
- /** 目标文件夹 ID(空为根目录)。 */
648
- folder_id: z.string().optional()
649
- });
650
- /** 移动群文件(P2-14)。 */
651
- var MoveGroupFileAction = class extends BaseAction {
652
- name = "move_group_file";
653
- schema = moveGroupFileSchema;
654
- errorCodeMap = ob11ErrorCodeMap;
655
- richMediaApi;
656
- constructor(richMediaApi) {
657
- super();
658
- this.richMediaApi = richMediaApi;
659
- }
660
- async _handle(payload) {
661
- const ids = payload.file_ids ?? [payload.file_id];
662
- await this.richMediaApi.moveGroupFile(String(payload.group_id), ids, payload.folder_id ?? "");
663
- return null;
664
- }
665
- };
666
- const transGroupFileSchema = z.object({
667
- group_id: z.number(),
668
- file_id: z.string()
669
- });
670
- /** 转存群文件(P2-14)。 */
671
- var TransGroupFileAction = class extends BaseAction {
672
- name = "trans_group_file";
673
- schema = transGroupFileSchema;
674
- errorCodeMap = ob11ErrorCodeMap;
675
- richMediaApi;
676
- constructor(richMediaApi) {
677
- super();
678
- this.richMediaApi = richMediaApi;
679
- }
680
- async _handle(payload) {
681
- await this.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
682
- return null;
683
- }
684
- };
468
+ /**
469
+ * 群文件操作动作:create_group_file_folder / delete_group_file /
470
+ * delete_group_folder / rename_group_file / move_group_file / trans_group_file
471
+ */
685
472
  /** 群文件操作域动作工厂(create/delete folder、delete/rename/move/trans file)。 */
686
473
  function createGroupFileOpActions(api) {
687
474
  return [
688
- new CreateGroupFileFolderAction(api.richMediaApi),
689
- new DeleteGroupFileAction(api.richMediaApi),
690
- new DeleteGroupFolderAction(api.richMediaApi),
691
- new RenameGroupFileAction(api.richMediaApi),
692
- new MoveGroupFileAction(api.richMediaApi),
693
- new TransGroupFileAction(api.richMediaApi)
475
+ defineOb11Action({
476
+ name: "create_group_file_folder",
477
+ schema: z.object({
478
+ group_id: z.number(),
479
+ folder_name: z.string()
480
+ }),
481
+ handle: async (payload) => {
482
+ return { folder_id: await api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
483
+ }
484
+ }),
485
+ defineOb11Action({
486
+ name: "delete_group_file",
487
+ schema: z.object({
488
+ group_id: z.number(),
489
+ file_id: z.string(),
490
+ /** 兼容 go-cqhttp 的 file_ids 数组(取第一个)。 */
491
+ file_ids: z.array(z.string()).max(100).optional()
492
+ }),
493
+ handle: async (payload) => {
494
+ const ids = payload.file_ids ?? [payload.file_id];
495
+ await api.richMediaApi.deleteGroupFile(String(payload.group_id), ids);
496
+ return null;
497
+ }
498
+ }),
499
+ defineOb11Action({
500
+ name: "delete_group_folder",
501
+ schema: z.object({
502
+ group_id: z.number(),
503
+ folder_id: z.string()
504
+ }),
505
+ handle: async (payload) => {
506
+ await api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
507
+ return null;
508
+ }
509
+ }),
510
+ defineOb11Action({
511
+ name: "rename_group_file",
512
+ schema: z.object({
513
+ group_id: z.number(),
514
+ file_id: z.string(),
515
+ new_name: z.string()
516
+ }),
517
+ handle: async (payload) => {
518
+ await api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_name);
519
+ return null;
520
+ }
521
+ }),
522
+ defineOb11Action({
523
+ name: "move_group_file",
524
+ schema: z.object({
525
+ group_id: z.number(),
526
+ file_id: z.string(),
527
+ file_ids: z.array(z.string()).max(100).optional(),
528
+ /** 目标文件夹 ID(空为根目录)。 */
529
+ folder_id: z.string().optional()
530
+ }),
531
+ handle: async (payload) => {
532
+ const ids = payload.file_ids ?? [payload.file_id];
533
+ await api.richMediaApi.moveGroupFile(String(payload.group_id), ids, payload.folder_id ?? "");
534
+ return null;
535
+ }
536
+ }),
537
+ defineOb11Action({
538
+ name: "trans_group_file",
539
+ schema: z.object({
540
+ group_id: z.number(),
541
+ file_id: z.string()
542
+ }),
543
+ handle: async (payload) => {
544
+ await api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
545
+ return null;
546
+ }
547
+ })
694
548
  ];
695
549
  }
696
550
  // src/onebot11/action/group/group-files-query.ts
697
- const getGroupRootFilesSchema = z.object({
698
- group_id: z.number(),
699
- file_count: z.number().optional()
700
- });
701
551
  /** 默认文件数量。 */
702
552
  const DEFAULT_FILE_COUNT = 50;
703
- /** 获取群根目录文件列表(P2-14 接 kernel RichMediaApi)。 */
704
- var GetGroupRootFilesAction = class extends BaseAction {
705
- name = "get_group_root_files";
706
- schema = getGroupRootFilesSchema;
707
- errorCodeMap = ob11ErrorCodeMap;
708
- richMediaApi;
709
- constructor(richMediaApi) {
710
- super();
711
- this.richMediaApi = richMediaApi;
712
- }
713
- async _handle(payload) {
714
- return splitFilesAndFolders(await this.richMediaApi.getGroupFileList(String(payload.group_id), "", payload.file_count ?? DEFAULT_FILE_COUNT));
715
- }
716
- };
717
- const getGroupFilesByFolderSchema = z.object({
718
- group_id: z.number(),
719
- folder_id: z.string(),
720
- file_count: z.number().optional()
721
- });
722
- /** 获取群指定文件夹文件列表(P2-14)。 */
723
- var GetGroupFilesByFolderAction = class extends BaseAction {
724
- name = "get_group_files_by_folder";
725
- schema = getGroupFilesByFolderSchema;
726
- errorCodeMap = ob11ErrorCodeMap;
727
- richMediaApi;
728
- constructor(richMediaApi) {
729
- super();
730
- this.richMediaApi = richMediaApi;
731
- }
732
- async _handle(payload) {
733
- return splitFilesAndFolders(await this.richMediaApi.getGroupFileList(String(payload.group_id), payload.folder_id, payload.file_count ?? DEFAULT_FILE_COUNT));
734
- }
735
- };
736
- const getGroupFileSystemInfoSchema = z.object({ group_id: z.number() });
737
- /** 群文件系统信息(P2-14)。 */
738
- var GetGroupFileSystemInfoAction = class extends BaseAction {
739
- name = "get_group_file_system_info";
740
- schema = getGroupFileSystemInfoSchema;
741
- errorCodeMap = ob11ErrorCodeMap;
742
- richMediaApi;
743
- constructor(richMediaApi) {
744
- super();
745
- this.richMediaApi = richMediaApi;
746
- }
747
- async _handle(payload) {
748
- const info = await this.richMediaApi.getGroupFileSystemInfo(String(payload.group_id));
749
- return {
750
- file_count: info.fileCount,
751
- limit_count: info.limitCount,
752
- used_space: info.usedSpace,
753
- total_space: info.totalSpace
754
- };
755
- }
756
- };
757
553
  /** 列表拆分 files/folders(fileInfo/folderInfo 取其一,纯函数)。 */
758
554
  function splitFilesAndFolders(list) {
759
555
  const files = [];
@@ -795,236 +591,172 @@ function toGroupFolderInfo(folder) {
795
591
  /** 群文件查询域动作工厂(root files / by folder / system info)。 */
796
592
  function createGroupFileQueryActions(api) {
797
593
  return [
798
- new GetGroupRootFilesAction(api.richMediaApi),
799
- new GetGroupFilesByFolderAction(api.richMediaApi),
800
- new GetGroupFileSystemInfoAction(api.richMediaApi)
594
+ defineOb11Action({
595
+ name: "get_group_root_files",
596
+ schema: z.object({
597
+ group_id: z.number(),
598
+ file_count: z.number().optional()
599
+ }),
600
+ handle: async (payload) => {
601
+ return splitFilesAndFolders(await api.richMediaApi.getGroupFileList(String(payload.group_id), "", payload.file_count ?? DEFAULT_FILE_COUNT));
602
+ }
603
+ }),
604
+ defineOb11Action({
605
+ name: "get_group_files_by_folder",
606
+ schema: z.object({
607
+ group_id: z.number(),
608
+ folder_id: z.string(),
609
+ file_count: z.number().optional()
610
+ }),
611
+ handle: async (payload) => {
612
+ return splitFilesAndFolders(await api.richMediaApi.getGroupFileList(String(payload.group_id), payload.folder_id, payload.file_count ?? DEFAULT_FILE_COUNT));
613
+ }
614
+ }),
615
+ defineOb11Action({
616
+ name: "get_group_file_system_info",
617
+ schema: z.object({ group_id: z.number() }),
618
+ handle: async (payload) => {
619
+ const info = await api.richMediaApi.getGroupFileSystemInfo(String(payload.group_id));
620
+ return {
621
+ file_count: info.fileCount,
622
+ limit_count: info.limitCount,
623
+ used_space: info.usedSpace,
624
+ total_space: info.totalSpace
625
+ };
626
+ }
627
+ })
801
628
  ];
802
629
  }
803
630
  // src/onebot11/action/group/manage.ts
804
631
  /**
805
- * 群管理域动作(2026-11-14 自 set-group-kick / set-group-ban / set-group-whole-ban /
806
- * set-group-admin / set-group-card / set-group-name / set-group-leave 合并)
632
+ * 群管理域动作
807
633
  *
808
634
  * 踢人 / 单人与全员禁言 / 管理员 / 名片 / 群名 / 退群,均接 kernel GroupApi;
809
635
  * user_id(uin)→ uid 经 resolveUid。
810
636
  */
811
- const setGroupKickSchema = z.object({
812
- group_id: z.number(),
813
- user_id: z.number(),
814
- /** 是否拒绝加群请求(拉黑)。 */
815
- reject_add_request: z.boolean().optional(),
816
- /** 踢人理由。 */
817
- kick_reason: z.string().optional()
818
- });
819
- /** 群组踢人(P2-10 接 kernel kickMember)。 */
820
- var SetGroupKickAction = class extends BaseAction {
821
- name = "set_group_kick";
822
- schema = setGroupKickSchema;
823
- errorCodeMap = ob11ErrorCodeMap;
824
- groupApi;
825
- constructor(groupApi) {
826
- super();
827
- this.groupApi = groupApi;
828
- }
829
- async _handle(payload) {
830
- const uid = await this.resolveUid(payload.user_id);
831
- await this.groupApi.kickMember(String(payload.group_id), [uid], payload.reject_add_request === true, payload.kick_reason ?? "");
832
- return null;
833
- }
834
- /** user_id(uin)→ uid。 */
835
- async resolveUid(userId) {
836
- const uid = (await this.groupApi.uinToUid([String(userId)])).get(String(userId));
837
- if (uid === void 0) throw kernelError(`用户 ${userId} 的 uid 解析失败`, "INVALID_PARAM");
838
- return uid;
839
- }
840
- };
841
- const setGroupBanSchema = z.object({
842
- group_id: z.number(),
843
- user_id: z.number(),
844
- /** 禁言时长(秒),0 解除。 */
845
- duration: z.number().default(30)
846
- });
847
- /** 群组单人禁言(P2-10 接 kernel setMemberShutUp)。 */
848
- var SetGroupBanAction = class extends BaseAction {
849
- name = "set_group_ban";
850
- schema = setGroupBanSchema;
851
- errorCodeMap = ob11ErrorCodeMap;
852
- groupApi;
853
- constructor(groupApi) {
854
- super();
855
- this.groupApi = groupApi;
856
- }
857
- async _handle(payload) {
858
- const uid = await resolveUid(String(payload.user_id), (uins) => this.groupApi.uinToUid(uins));
859
- await this.groupApi.setMemberShutUp(String(payload.group_id), [{
860
- uid,
861
- duration: payload.duration
862
- }]);
863
- return null;
864
- }
865
- };
866
- const setGroupWholeBanSchema = z.object({
867
- group_id: z.number(),
868
- /** 是否开启全员禁言。 */
869
- enable: z.boolean().default(true)
870
- });
871
- /** 群组全员禁言(P2-10 接 kernel setGroupShutUp)。 */
872
- var SetGroupWholeBanAction = class extends BaseAction {
873
- name = "set_group_whole_ban";
874
- schema = setGroupWholeBanSchema;
875
- errorCodeMap = ob11ErrorCodeMap;
876
- groupApi;
877
- constructor(groupApi) {
878
- super();
879
- this.groupApi = groupApi;
880
- }
881
- async _handle(payload) {
882
- await this.groupApi.setGroupShutUp(String(payload.group_id), payload.enable);
883
- return null;
884
- }
885
- };
886
- const setGroupAdminSchema = z.object({
887
- group_id: z.number(),
888
- user_id: z.number(),
889
- /** 是否设为管理员。 */
890
- enable: z.boolean().default(true)
891
- });
892
- /** 设置群管理员(P2-10 接 kernel setMemberRole)。 */
893
- var SetGroupAdminAction = class extends BaseAction {
894
- name = "set_group_admin";
895
- schema = setGroupAdminSchema;
896
- errorCodeMap = ob11ErrorCodeMap;
897
- groupApi;
898
- constructor(groupApi) {
899
- super();
900
- this.groupApi = groupApi;
901
- }
902
- async _handle(payload) {
903
- const uid = await resolveUid(String(payload.user_id), (uins) => this.groupApi.uinToUid(uins));
904
- let role = NTGroupMemberRole.MEMBER;
905
- if (payload.enable) role = NTGroupMemberRole.ADMIN;
906
- this.groupApi.setMemberRole(String(payload.group_id), uid, role);
907
- return null;
908
- }
909
- };
910
- const setGroupCardSchema = z.object({
911
- group_id: z.number(),
912
- user_id: z.number(),
913
- /** 群名片(空串清除)。 */
914
- card: z.string().optional().default("")
915
- });
916
- /** 设置群名片(P2-10 接 kernel setMemberCardName)。 */
917
- var SetGroupCardAction = class extends BaseAction {
918
- name = "set_group_card";
919
- schema = setGroupCardSchema;
920
- errorCodeMap = ob11ErrorCodeMap;
921
- groupApi;
922
- constructor(groupApi) {
923
- super();
924
- this.groupApi = groupApi;
925
- }
926
- async _handle(payload) {
927
- const uid = await resolveUid(String(payload.user_id), (uins) => this.groupApi.uinToUid(uins));
928
- this.groupApi.setMemberCardName(String(payload.group_id), uid, payload.card);
929
- return null;
930
- }
931
- };
932
- const setGroupNameSchema = z.object({
933
- group_id: z.number(),
934
- group_name: z.string()
935
- });
936
- /** 修改群名(P2-10 接 kernel modifyGroupName)。 */
937
- var SetGroupNameAction = class extends BaseAction {
938
- name = "set_group_name";
939
- schema = setGroupNameSchema;
940
- errorCodeMap = ob11ErrorCodeMap;
941
- groupApi;
942
- constructor(groupApi) {
943
- super();
944
- this.groupApi = groupApi;
945
- }
946
- async _handle(payload) {
947
- await this.groupApi.modifyGroupName(String(payload.group_id), payload.group_name);
948
- return null;
949
- }
950
- };
951
- const setGroupLeaveSchema = z.object({
952
- group_id: z.number(),
953
- /** 是否解散群(仅群主可用)。 */
954
- is_dismiss: z.boolean().optional().default(false)
955
- });
956
- /** 退出群聊(P2-10 接 kernel quitGroup)。 */
957
- var SetGroupLeaveAction = class extends BaseAction {
958
- name = "set_group_leave";
959
- schema = setGroupLeaveSchema;
960
- errorCodeMap = ob11ErrorCodeMap;
961
- groupApi;
962
- constructor(groupApi) {
963
- super();
964
- this.groupApi = groupApi;
965
- }
966
- async _handle(payload) {
967
- await this.groupApi.quitGroup(String(payload.group_id), payload.is_dismiss);
968
- return null;
969
- }
970
- };
971
- /**
972
- * 群管理域动作工厂(kick / ban / whole_ban / admin / card / name / leave)。
973
- */
637
+ /** 默认禁言时长(秒)。 */
638
+ const DEFAULT_BAN_DURATION = 30;
639
+ /** 群管理域动作工厂(kick / ban / whole_ban / admin / card / name / leave)。 */
640
+ /** uin → uid(groupApi.uinToUid 绑定视图;kernel 方法非箭头绑定)。 */
641
+ function memberUidOf(api, uin) {
642
+ return resolveUid(String(uin), (uins) => api.groupApi.uinToUid(uins));
643
+ }
974
644
  function createGroupManageActions(api) {
975
645
  return [
976
- new SetGroupKickAction(api.groupApi),
977
- new SetGroupBanAction(api.groupApi),
978
- new SetGroupWholeBanAction(api.groupApi),
979
- new SetGroupAdminAction(api.groupApi),
980
- new SetGroupCardAction(api.groupApi),
981
- new SetGroupNameAction(api.groupApi),
982
- new SetGroupLeaveAction(api.groupApi)
646
+ defineOb11Action({
647
+ name: "set_group_kick",
648
+ schema: z.object({
649
+ group_id: z.number(),
650
+ user_id: z.number(),
651
+ /** 是否拒绝加群请求(拉黑)。 */
652
+ reject_add_request: z.boolean().optional(),
653
+ /** 踢人理由。 */
654
+ kick_reason: z.string().optional()
655
+ }),
656
+ handle: async (payload) => {
657
+ const uid = await memberUidOf(api, payload.user_id);
658
+ await api.groupApi.kickMember(String(payload.group_id), [uid], payload.reject_add_request === true, payload.kick_reason ?? "");
659
+ return null;
660
+ }
661
+ }),
662
+ defineOb11Action({
663
+ name: "set_group_ban",
664
+ schema: z.object({
665
+ group_id: z.number(),
666
+ user_id: z.number(),
667
+ /** 禁言时长(秒),0 解除。 */
668
+ duration: z.number().default(DEFAULT_BAN_DURATION)
669
+ }),
670
+ handle: async (payload) => {
671
+ const uid = await memberUidOf(api, payload.user_id);
672
+ await api.groupApi.setMemberShutUp(String(payload.group_id), [{
673
+ uid,
674
+ duration: payload.duration
675
+ }]);
676
+ return null;
677
+ }
678
+ }),
679
+ defineOb11Action({
680
+ name: "set_group_whole_ban",
681
+ schema: z.object({
682
+ group_id: z.number(),
683
+ /** 是否开启全员禁言。 */
684
+ enable: z.boolean().default(true)
685
+ }),
686
+ handle: async (payload) => {
687
+ await api.groupApi.setGroupShutUp(String(payload.group_id), payload.enable);
688
+ return null;
689
+ }
690
+ }),
691
+ defineOb11Action({
692
+ name: "set_group_admin",
693
+ schema: z.object({
694
+ group_id: z.number(),
695
+ user_id: z.number(),
696
+ /** 是否设为管理员。 */
697
+ enable: z.boolean().default(true)
698
+ }),
699
+ handle: async (payload) => {
700
+ const uid = await memberUidOf(api, payload.user_id);
701
+ let role = NTGroupMemberRole.MEMBER;
702
+ if (payload.enable) role = NTGroupMemberRole.ADMIN;
703
+ api.groupApi.setMemberRole(String(payload.group_id), uid, role);
704
+ return null;
705
+ }
706
+ }),
707
+ defineOb11Action({
708
+ name: "set_group_card",
709
+ schema: z.object({
710
+ group_id: z.number(),
711
+ user_id: z.number(),
712
+ /** 群名片(空串清除)。 */
713
+ card: z.string().optional().default("")
714
+ }),
715
+ handle: async (payload) => {
716
+ const uid = await memberUidOf(api, payload.user_id);
717
+ api.groupApi.setMemberCardName(String(payload.group_id), uid, payload.card);
718
+ return null;
719
+ }
720
+ }),
721
+ defineOb11Action({
722
+ name: "set_group_name",
723
+ schema: z.object({
724
+ group_id: z.number(),
725
+ group_name: z.string()
726
+ }),
727
+ handle: async (payload) => {
728
+ await api.groupApi.modifyGroupName(String(payload.group_id), payload.group_name);
729
+ return null;
730
+ }
731
+ }),
732
+ defineOb11Action({
733
+ name: "set_group_leave",
734
+ schema: z.object({
735
+ group_id: z.number(),
736
+ /** 是否解散群(仅群主可用)。 */
737
+ is_dismiss: z.boolean().optional().default(false)
738
+ }),
739
+ handle: async (payload) => {
740
+ await api.groupApi.quitGroup(String(payload.group_id), payload.is_dismiss);
741
+ return null;
742
+ }
743
+ })
983
744
  ];
984
745
  }
985
746
  // src/onebot11/action/group/notify.ts
986
747
  /**
987
- * 群通知域动作(2026-11-14 自 get-group-add-request / set-group-add-request /
988
- * get-group-shut-list 合并,均接 kernel GroupNotifyApi)
748
+ * 群通知域动作(均接 kernel GroupNotifyApi)
989
749
  *
990
- * - get_group_add_request / get_group_ignored_notifies(P2-15):未处理申请列表 /
750
+ * - get_group_add_request / get_group_ignored_notifies:未处理申请列表 /
991
751
  * 可疑忽略列表(getSingleScreenNotifies(false|true));flag=seq 用于应答
992
- * - set_group_add_request(P2-13):flag=seq 匹配 → handleGroupRequest
752
+ * - set_group_add_request:flag=seq 匹配 → handleGroupRequest
993
753
  * (approve=true→同意 / false→拒绝,reason 默认空格)
994
- * - get_group_shut_list(P2-13):getGroupShutUpMemberList → 禁言成员列表
754
+ * - get_group_shut_list:getGroupShutUpMemberList → 禁言成员列表
995
755
  * (uin 经 uidToUin 批量转换)
996
756
  */
997
757
  const getGroupAddRequestSchema = z.object({ count: z.number().optional() });
998
758
  /** 默认获取数量。 */
999
759
  const DEFAULT_COUNT = 100;
1000
- /** 获取未处理群申请(P2-15)。 */
1001
- var GetGroupAddRequestAction = class extends BaseAction {
1002
- name = "get_group_add_request";
1003
- schema = getGroupAddRequestSchema;
1004
- errorCodeMap = ob11ErrorCodeMap;
1005
- groupNotifyApi;
1006
- constructor(groupNotifyApi) {
1007
- super();
1008
- this.groupNotifyApi = groupNotifyApi;
1009
- }
1010
- async _handle(payload) {
1011
- return (await this.groupNotifyApi.getSingleScreenNotifies(false, payload.count ?? DEFAULT_COUNT)).map(toGroupAddRequestItem);
1012
- }
1013
- };
1014
- /** 获取被忽略群申请(P2-15)。 */
1015
- var GetGroupIgnoredNotifiesAction = class extends BaseAction {
1016
- name = "get_group_ignored_notifies";
1017
- schema = getGroupAddRequestSchema;
1018
- errorCodeMap = ob11ErrorCodeMap;
1019
- groupNotifyApi;
1020
- constructor(groupNotifyApi) {
1021
- super();
1022
- this.groupNotifyApi = groupNotifyApi;
1023
- }
1024
- async _handle(payload) {
1025
- return (await this.groupNotifyApi.getSingleScreenNotifies(true, payload.count ?? DEFAULT_COUNT)).map(toGroupAddRequestItem);
1026
- }
1027
- };
1028
760
  /** GroupNotify → OB11 群请求项(纯函数)。 */
1029
761
  function toGroupAddRequestItem(notify) {
1030
762
  const { seq, type, status, postscript, user1, group } = notify;
@@ -1053,80 +785,72 @@ function toGroupAddRequestItem(notify) {
1053
785
  postscript: postscript ?? ""
1054
786
  };
1055
787
  }
1056
- const setGroupAddRequestSchema = z.object({
1057
- flag: z.string(),
1058
- approve: z.boolean().optional(),
1059
- reason: z.string().optional(),
1060
- count: z.number().optional()
1061
- });
1062
- /** 处理加群请求(P2-13 接 kernel GroupNotifyApi)。 */
1063
- var SetGroupAddRequestAction = class extends BaseAction {
1064
- name = "set_group_add_request";
1065
- schema = setGroupAddRequestSchema;
1066
- errorCodeMap = ob11ErrorCodeMap;
1067
- groupNotifyApi;
1068
- constructor(groupNotifyApi) {
1069
- super();
1070
- this.groupNotifyApi = groupNotifyApi;
1071
- }
1072
- async _handle(payload) {
1073
- const count = payload.count ?? DEFAULT_COUNT;
1074
- const notify = await this.findNotify(payload.flag, count);
1075
- if (notify === null) throw kernelError("未找到对应的群请求(flag 无效或已过期)", "NOT_FOUND");
1076
- let operateType = NTGroupRequestOperateTypes.KREFUSE;
1077
- if (payload.approve !== false) operateType = NTGroupRequestOperateTypes.KAGREE;
1078
- await this.groupNotifyApi.handleGroupRequest(false, notify, operateType, payload.reason ?? " ");
1079
- return null;
1080
- }
1081
- /** 按 seq 匹配通知(先非可疑,后可疑)。 */
1082
- async findNotify(flag, count) {
1083
- const hit = (await this.groupNotifyApi.getSingleScreenNotifies(false, count)).find((item) => item.seq === flag);
1084
- if (hit !== void 0) return hit;
1085
- return (await this.groupNotifyApi.getSingleScreenNotifies(true, count)).find((item) => item.seq === flag) ?? null;
1086
- }
1087
- };
1088
- const getGroupShutListSchema = z.object({ group_id: z.number() });
1089
- /** 获取群禁言列表(P2-13 接 kernel GroupNotifyApi)。 */
1090
- var GetGroupShutListAction = class extends BaseAction {
1091
- name = "get_group_shut_list";
1092
- schema = getGroupShutListSchema;
1093
- errorCodeMap = ob11ErrorCodeMap;
1094
- deps;
1095
- constructor(deps) {
1096
- super();
1097
- this.deps = deps;
1098
- }
1099
- async _handle(payload) {
1100
- const members = await this.deps.groupNotifyApi.getGroupShutUpMemberList(String(payload.group_id));
1101
- const uids = members.map((m) => m.uid);
1102
- let uinMap = /* @__PURE__ */ new Map();
1103
- if (uids.length > 0) uinMap = await this.deps.uidToUin(uids);
1104
- const out = [];
1105
- for (const member of members) out.push({
1106
- user_id: Number(uinMap.get(member.uid) ?? member.uin ?? member.uid),
1107
- nickname: member.nick,
1108
- shut_up_time: member.shutUpTime
1109
- });
1110
- return out;
1111
- }
1112
- };
1113
- /**
1114
- * 群通知域动作工厂(get_group_add_request / get_group_ignored_notifies /
1115
- * set_group_add_request / get_group_shut_list)。
1116
- */
788
+ /** 按 seq 匹配通知(先非可疑,后可疑)。 */
789
+ async function findGroupNotify(groupNotifyApi, flag, count) {
790
+ const hit = (await groupNotifyApi.getSingleScreenNotifies(false, count)).find((item) => item.seq === flag);
791
+ if (hit !== void 0) return hit;
792
+ return (await groupNotifyApi.getSingleScreenNotifies(true, count)).find((item) => item.seq === flag) ?? null;
793
+ }
794
+ /** 群通知域动作工厂(get_group_add_request / get_group_ignored_notifies /
795
+ * set_group_add_request / get_group_shut_list)。 */
1117
796
  function createGroupNotifyActions(api) {
1118
797
  return [
1119
- new GetGroupAddRequestAction(api.groupNotifyApi),
1120
- new GetGroupIgnoredNotifiesAction(api.groupNotifyApi),
1121
- new SetGroupAddRequestAction(api.groupNotifyApi),
1122
- new GetGroupShutListAction(api)
798
+ defineOb11Action({
799
+ name: "get_group_add_request",
800
+ schema: getGroupAddRequestSchema,
801
+ handle: async (payload) => {
802
+ return (await api.groupNotifyApi.getSingleScreenNotifies(false, payload.count ?? DEFAULT_COUNT)).map(toGroupAddRequestItem);
803
+ }
804
+ }),
805
+ defineOb11Action({
806
+ name: "get_group_ignored_notifies",
807
+ schema: getGroupAddRequestSchema,
808
+ handle: async (payload) => {
809
+ return (await api.groupNotifyApi.getSingleScreenNotifies(true, payload.count ?? DEFAULT_COUNT)).map(toGroupAddRequestItem);
810
+ }
811
+ }),
812
+ defineOb11Action({
813
+ name: "set_group_add_request",
814
+ schema: z.object({
815
+ flag: z.string(),
816
+ approve: z.boolean().optional(),
817
+ reason: z.string().optional(),
818
+ count: z.number().optional()
819
+ }),
820
+ handle: async (payload) => {
821
+ const count = payload.count ?? DEFAULT_COUNT;
822
+ const notify = await findGroupNotify(api.groupNotifyApi, payload.flag, count);
823
+ if (notify === null) throw kernelError("未找到对应的群请求(flag 无效或已过期)", "NOT_FOUND");
824
+ let operateType = NTGroupRequestOperateTypes.KREFUSE;
825
+ if (payload.approve !== false) operateType = NTGroupRequestOperateTypes.KAGREE;
826
+ await api.groupNotifyApi.handleGroupRequest(false, notify, operateType, payload.reason ?? " ");
827
+ return null;
828
+ }
829
+ }),
830
+ defineOb11Action({
831
+ name: "get_group_shut_list",
832
+ schema: z.object({ group_id: z.number() }),
833
+ handle: async (payload) => {
834
+ const members = await api.groupNotifyApi.getGroupShutUpMemberList(String(payload.group_id));
835
+ const uids = members.map((m) => m.uid);
836
+ let uinMap = /* @__PURE__ */ new Map();
837
+ if (uids.length > 0) uinMap = await api.uidToUin(uids);
838
+ const out = [];
839
+ for (const member of members) out.push({
840
+ user_id: Number(uinMap.get(member.uid) ?? member.uin ?? member.uid),
841
+ nickname: member.nick,
842
+ shut_up_time: member.shutUpTime
843
+ });
844
+ return out;
845
+ }
846
+ })
1123
847
  ];
1124
848
  }
1125
849
  // src/onebot11/helper/translate.ts
1126
850
  /**
1127
- * OB11 翻译辅助(NT 实体 → OB11 结构,P2-4)
851
+ * OB11 翻译辅助(NT 实体 → OB11 结构)
1128
852
  *
1129
- * 纯函数(ADR-008):只读入参,不调 API、不读缓存。
853
+ * 纯函数:只读入参,不调 API、不读缓存。
1130
854
  * 群成员/群信息等 NT 实体 → OB11 返回结构的薄映射。
1131
855
  */
1132
856
  /** NT Group → OB11 GroupInfo。 */
@@ -1140,171 +864,122 @@ function toOb11GroupInfo(group) {
1140
864
  return info;
1141
865
  }
1142
866
  /** NT GroupDetailInfo → OB11 GroupInfo(getGroupDetailInfo / GroupCache 用)。 */
1143
- function toOb11GroupInfoDetail(detail) {
1144
- const info = {
1145
- group_id: Number(detail.groupCode),
1146
- group_name: detail.groupName
1147
- };
1148
- if (typeof detail.memberNum === "number") info.member_count = detail.memberNum;
1149
- if (typeof detail.maxMemberNum === "number") info.max_member_count = detail.maxMemberNum;
1150
- return info;
1151
- }
1152
- /** 禁言秒 → 毫秒(shut_up_timestamp 单位)。 */
1153
- const SEC_TO_MS = 1e3;
1154
- /** NT GroupMember → OB11 GroupMemberInfo(uin 由 uidToUin 映射补全)。 */
1155
- function toOb11GroupMemberInfo(groupCode, member, uidToUin) {
1156
- let uinStr = member.uin;
1157
- if (uinStr === "") uinStr = uidToUin.get(member.uid) ?? member.uid;
1158
- const info = {
1159
- group_id: Number(groupCode),
1160
- user_id: Number(uinStr),
1161
- nickname: member.nick,
1162
- role: GroupApi.roleToString(member.role)
1163
- };
1164
- if (member.cardName !== "") info.card = member.cardName;
1165
- if (member.memberSpecialTitle !== void 0 && member.memberSpecialTitle !== "") {
1166
- info.title = member.memberSpecialTitle;
1167
- info.special_title = member.memberSpecialTitle;
1168
- }
1169
- if (member.shutUpTime > 0) info.shut_up_timestamp = member.shutUpTime * SEC_TO_MS;
1170
- if (member.joinTime !== "" && member.joinTime !== "0") info.join_time = Number(member.joinTime);
1171
- if (member.lastSpeakTime !== "" && member.lastSpeakTime !== "0") info.last_sent_time = Number(member.lastSpeakTime);
1172
- if (typeof member.age === "number") info.age = member.age;
1173
- return info;
1174
- }
1175
- // src/onebot11/action/group/query.ts
1176
- /**
1177
- * 群查询域动作(2026-11-14 自 get-group-info / get-group-list / get-group-member-info /
1178
- * get-group-member-list / get-group-at-all-remain 合并)
1179
- *
1180
- * P2-4 接 kernel GroupApi;P2-17 群信息/成员动作优先读 GroupCache,no_cache=true
1181
- * 直查 api。get_group_list 有实测校准:原生 getGroupList 返回值无数据(仅
1182
- * { result, errMsg }),列表经 onGroupListUpdate 事件推送 → GroupCache 维护。
1183
- */
1184
- const getGroupInfoSchema = z.object({
1185
- group_id: z.number(),
1186
- /** 是否忽略缓存(go-cqhttp 扩展)。 */
1187
- no_cache: z.boolean().optional()
1188
- });
1189
- /** 获取群信息(P2-4 接 kernel apis/group;P2-17 优先读 GroupCache)。 */
1190
- var GetGroupInfoAction = class extends BaseAction {
1191
- name = "get_group_info";
1192
- schema = getGroupInfoSchema;
1193
- errorCodeMap = ob11ErrorCodeMap;
1194
- deps;
1195
- constructor(deps) {
1196
- super();
1197
- this.deps = deps;
1198
- }
1199
- async _handle(payload) {
1200
- const groupCode = String(payload.group_id);
1201
- if (payload.no_cache !== true && this.deps.groupCache !== void 0) return toOb11GroupInfoDetail(await this.deps.groupCache.getGroupDetail(groupCode));
1202
- return toOb11GroupInfoDetail(await this.deps.groupApi.getGroupInfo(groupCode));
1203
- }
1204
- };
1205
- const getGroupListSchema = z.object({
1206
- /** 是否忽略缓存(go-cqhttp 扩展)。 */
1207
- no_cache: z.boolean().optional() });
1208
- /** 获取群列表(P2-4 接 kernel apis/group;群列表数据经事件推送,从 GroupCache 读)。 */
1209
- var GetGroupListAction = class extends BaseAction {
1210
- name = "get_group_list";
1211
- schema = getGroupListSchema;
1212
- errorCodeMap = ob11ErrorCodeMap;
1213
- deps;
1214
- constructor(deps) {
1215
- super();
1216
- this.deps = deps;
1217
- }
1218
- async _handle(payload) {
1219
- return (this.deps.groupCache === void 0 ? await this.deps.groupApi.getGroupList(true) : payload.no_cache === true ? await this.deps.groupCache.listGroupsRefreshed() : this.deps.groupCache.listGroups()).map(toOb11GroupInfo);
1220
- }
1221
- };
1222
- const getGroupMemberInfoSchema = z.object({
1223
- group_id: z.number(),
1224
- user_id: z.number(),
1225
- /** 是否忽略缓存(go-cqhttp 扩展)。 */
1226
- no_cache: z.boolean().optional()
1227
- });
1228
- /** 获取群成员信息(P2-4 接 kernel apis/group;P2-17 优先读 GroupCache)。 */
1229
- var GetGroupMemberInfoAction = class extends BaseAction {
1230
- name = "get_group_member_info";
1231
- schema = getGroupMemberInfoSchema;
1232
- errorCodeMap = ob11ErrorCodeMap;
1233
- deps;
1234
- constructor(deps) {
1235
- super();
1236
- this.deps = deps;
1237
- }
1238
- async _handle(payload) {
1239
- const groupCode = String(payload.group_id);
1240
- const uid = (await this.deps.groupApi.uinToUid([String(payload.user_id)])).get(String(payload.user_id));
1241
- if (uid === void 0) throw kernelError(`成员 ${payload.user_id} 不在群 ${payload.group_id}`, "NOT_FOUND");
1242
- const member = await this.resolveMember(groupCode, uid, payload.no_cache === true);
1243
- if (member === void 0) throw kernelError(`成员 ${payload.user_id} 不在群 ${payload.group_id}`, "NOT_FOUND");
1244
- return toOb11GroupMemberInfo(groupCode, member, await this.deps.groupApi.uidToUin([uid]));
1245
- }
1246
- /** 读缓存(缺省)或直查 api(no_cache=true / 未装配缓存)。 */
1247
- async resolveMember(groupCode, uid, noCache) {
1248
- if (noCache || this.deps.groupCache === void 0) {
1249
- const [member] = await this.deps.groupApi.getGroupMemberInfo(groupCode, [uid]);
1250
- return member;
1251
- }
1252
- return await this.deps.groupCache.getMember(groupCode, uid);
1253
- }
1254
- };
1255
- const getGroupMemberListSchema = z.object({
1256
- group_id: z.number(),
1257
- /** 是否忽略缓存(go-cqhttp 扩展)。 */
1258
- no_cache: z.boolean().optional()
1259
- });
1260
- /** 获取群成员列表(P2-4 接 kernel apis/group;P2-17 优先读 GroupCache)。 */
1261
- var GetGroupMemberListAction = class extends BaseAction {
1262
- name = "get_group_member_list";
1263
- schema = getGroupMemberListSchema;
1264
- errorCodeMap = ob11ErrorCodeMap;
1265
- deps;
1266
- constructor(deps) {
1267
- super();
1268
- this.deps = deps;
1269
- }
1270
- async _handle(payload) {
1271
- const groupCode = String(payload.group_id);
1272
- const noCache = payload.no_cache === true;
1273
- let members;
1274
- if (noCache || this.deps.groupCache === void 0) members = await this.deps.groupApi.getGroupMemberList(groupCode, noCache);
1275
- else members = await this.deps.groupCache.getMembers(groupCode);
1276
- const uinMap = await this.deps.groupApi.uidToUin(members.map((m) => m.uid));
1277
- return members.map((m) => toOb11GroupMemberInfo(groupCode, m, uinMap));
1278
- }
1279
- };
1280
- const getGroupAtAllRemainSchema = z.object({ group_id: z.number() });
1281
- /** 获取群 @全体成员 剩余次数(P2-10 接 kernel getGroupRemainAtTimes)。 */
1282
- var GetGroupAtAllRemainAction = class extends BaseAction {
1283
- name = "get_group_at_all_remain";
1284
- schema = getGroupAtAllRemainSchema;
1285
- errorCodeMap = ob11ErrorCodeMap;
1286
- groupApi;
1287
- constructor(groupApi) {
1288
- super();
1289
- this.groupApi = groupApi;
1290
- }
1291
- async _handle(payload) {
1292
- const remain = await this.groupApi.getGroupRemainAtTimes(String(payload.group_id));
1293
- return {
1294
- can_at_all: remain.canAtAll,
1295
- remain_at_all_count_for_uin: remain.remainAtAllCountForUin,
1296
- remain_at_all_count_for_group: remain.remainAtAllCountForGroup
1297
- };
867
+ function toOb11GroupInfoDetail(detail) {
868
+ const info = {
869
+ group_id: Number(detail.groupCode),
870
+ group_name: detail.groupName
871
+ };
872
+ if (typeof detail.memberNum === "number") info.member_count = detail.memberNum;
873
+ if (typeof detail.maxMemberNum === "number") info.max_member_count = detail.maxMemberNum;
874
+ return info;
875
+ }
876
+ /** 禁言秒 → 毫秒(shut_up_timestamp 单位)。 */
877
+ const SEC_TO_MS = 1e3;
878
+ /** NT GroupMember → OB11 GroupMemberInfo(uin 由 uidToUin 映射补全)。 */
879
+ function toOb11GroupMemberInfo(groupCode, member, uidToUin) {
880
+ let uinStr = member.uin;
881
+ if (uinStr === "") uinStr = uidToUin.get(member.uid) ?? member.uid;
882
+ const info = {
883
+ group_id: Number(groupCode),
884
+ user_id: Number(uinStr),
885
+ nickname: member.nick,
886
+ role: GroupApi.roleToString(member.role)
887
+ };
888
+ if (member.cardName !== "") info.card = member.cardName;
889
+ if (member.memberSpecialTitle !== void 0 && member.memberSpecialTitle !== "") {
890
+ info.title = member.memberSpecialTitle;
891
+ info.special_title = member.memberSpecialTitle;
1298
892
  }
1299
- };
893
+ if (member.shutUpTime > 0) info.shut_up_timestamp = member.shutUpTime * SEC_TO_MS;
894
+ if (member.joinTime !== "" && member.joinTime !== "0") info.join_time = Number(member.joinTime);
895
+ if (member.lastSpeakTime !== "" && member.lastSpeakTime !== "0") info.last_sent_time = Number(member.lastSpeakTime);
896
+ if (typeof member.age === "number") info.age = member.age;
897
+ return info;
898
+ }
899
+ // src/onebot11/action/group/query.ts
900
+ /**
901
+ * 群查询域动作
902
+ *
903
+ * 接 kernel GroupApi;群信息/成员动作优先读 GroupCache,no_cache=true
904
+ * 直查 api。get_group_list 有实测校准:原生 getGroupList 返回值无数据(仅
905
+ * { result, errMsg }),列表经 onGroupListUpdate 事件推送 → GroupCache 维护。
906
+ */
1300
907
  /** 群查询域动作工厂(group_info / group_list / member_info / member_list / at_all_remain)。 */
1301
908
  function createGroupQueryActions(api) {
1302
909
  return [
1303
- new GetGroupInfoAction(api),
1304
- new GetGroupListAction(api),
1305
- new GetGroupMemberInfoAction(api),
1306
- new GetGroupMemberListAction(api),
1307
- new GetGroupAtAllRemainAction(api.groupApi)
910
+ defineOb11Action({
911
+ name: "get_group_info",
912
+ schema: z.object({
913
+ group_id: z.number(),
914
+ /** 是否忽略缓存(go-cqhttp 扩展)。 */
915
+ no_cache: z.boolean().optional()
916
+ }),
917
+ handle: async (payload) => {
918
+ const groupCode = String(payload.group_id);
919
+ if (payload.no_cache !== true && api.groupCache !== void 0) return toOb11GroupInfoDetail(await api.groupCache.getGroupDetail(groupCode));
920
+ return toOb11GroupInfoDetail(await api.groupApi.getGroupInfo(groupCode));
921
+ }
922
+ }),
923
+ defineOb11Action({
924
+ name: "get_group_list",
925
+ schema: z.object({
926
+ /** 是否忽略缓存(go-cqhttp 扩展)。 */
927
+ no_cache: z.boolean().optional() }),
928
+ handle: async (payload) => {
929
+ return (api.groupCache === void 0 ? await api.groupApi.getGroupList(true) : payload.no_cache === true ? await api.groupCache.listGroupsRefreshed() : api.groupCache.listGroups()).map(toOb11GroupInfo);
930
+ }
931
+ }),
932
+ defineOb11Action({
933
+ name: "get_group_member_info",
934
+ schema: z.object({
935
+ group_id: z.number(),
936
+ user_id: z.number(),
937
+ /** 是否忽略缓存(go-cqhttp 扩展)。 */
938
+ no_cache: z.boolean().optional()
939
+ }),
940
+ handle: async (payload) => {
941
+ const groupCode = String(payload.group_id);
942
+ const uid = (await api.groupApi.uinToUid([String(payload.user_id)])).get(String(payload.user_id));
943
+ if (uid === void 0) throw kernelError(`成员 ${payload.user_id} 不在群 ${payload.group_id}`, "NOT_FOUND");
944
+ let member;
945
+ if (payload.no_cache === true || api.groupCache === void 0) {
946
+ const [first] = await api.groupApi.getGroupMemberInfo(groupCode, [uid]);
947
+ member = first;
948
+ } else member = await api.groupCache.getMember(groupCode, uid);
949
+ if (member === void 0) throw kernelError(`成员 ${payload.user_id} 不在群 ${payload.group_id}`, "NOT_FOUND");
950
+ const uinMap = await api.groupApi.uidToUin([uid]);
951
+ return toOb11GroupMemberInfo(groupCode, member, uinMap);
952
+ }
953
+ }),
954
+ defineOb11Action({
955
+ name: "get_group_member_list",
956
+ schema: z.object({
957
+ group_id: z.number(),
958
+ /** 是否忽略缓存(go-cqhttp 扩展)。 */
959
+ no_cache: z.boolean().optional()
960
+ }),
961
+ handle: async (payload) => {
962
+ const groupCode = String(payload.group_id);
963
+ const noCache = payload.no_cache === true;
964
+ let members;
965
+ if (noCache || api.groupCache === void 0) members = await api.groupApi.getGroupMemberList(groupCode, noCache);
966
+ else members = await api.groupCache.getMembers(groupCode);
967
+ const uinMap = await api.groupApi.uidToUin(members.map((m) => m.uid));
968
+ return members.map((m) => toOb11GroupMemberInfo(groupCode, m, uinMap));
969
+ }
970
+ }),
971
+ defineOb11Action({
972
+ name: "get_group_at_all_remain",
973
+ schema: z.object({ group_id: z.number() }),
974
+ handle: async (payload) => {
975
+ const remain = await api.groupApi.getGroupRemainAtTimes(String(payload.group_id));
976
+ return {
977
+ can_at_all: remain.canAtAll,
978
+ remain_at_all_count_for_uin: remain.remainAtAllCountForUin,
979
+ remain_at_all_count_for_group: remain.remainAtAllCountForGroup
980
+ };
981
+ }
982
+ })
1308
983
  ];
1309
984
  }
1310
985
  // src/onebot11/helper/codec/cqcode.ts
@@ -1577,10 +1252,10 @@ function segmentsToCqMessage(segments) {
1577
1252
  }
1578
1253
  // src/onebot11/helper/config.ts
1579
1254
  /**
1580
- * OneBot 11 协议配置(zod schema,归属本包,ADR-012)
1255
+ * OneBot 11 协议配置(zod schema,归属本包)
1581
1256
  * 协议配置 schema 在各自协议包,kernel 只提供 ConfigBase 基类。
1582
1257
  *
1583
- * 2026-08-07 多实例化(P2-18):对齐 NapCat——httpServers / httpPostUrls / wsServers /
1258
+ * 多实例化:对齐 NapCat——httpServers / httpPostUrls / wsServers /
1584
1259
  * wsReverseUrls 四个数组实例(每实例可覆盖全局 token);旧单对象字段 http/httpPost/ws/
1585
1260
  * wsReverse 废弃(zod strip 静默忽略,不兼容迁移)。
1586
1261
  */
@@ -1597,7 +1272,7 @@ const DEFAULT_RECONNECT_DELAY_MS = 5e3;
1597
1272
  /** 消息内容格式(NapCat messagePostFormat)。 */
1598
1273
  const MESSAGE_FORMATS = ["array", "string"];
1599
1274
  /** HTTP 反向服务器实例(第三方 POST 指令入口)。 */
1600
- const httpServerSchema = createHttpServerSchema(DEFAULT_HTTP_PORT);
1275
+ const httpServerSchema = createServerSchema(DEFAULT_HTTP_PORT);
1601
1276
  /** HTTP 正向上报实例(Webhook 事件推送)。 */
1602
1277
  const httpPostSchema = z.object({
1603
1278
  enabled: z.boolean().default(false),
@@ -1608,7 +1283,7 @@ const httpPostSchema = z.object({
1608
1283
  timeoutMs: z.number().int().optional()
1609
1284
  });
1610
1285
  /** 反向 WS server 实例(第三方 WS 连入,带 WS ping 间隔扩展字段)。 */
1611
- const wsServerSchema = createWsServerSchema(DEFAULT_WS_PORT).extend({
1286
+ const wsServerSchema = createServerSchema(DEFAULT_WS_PORT).extend({
1612
1287
  /** WS ping 间隔(毫秒)。 */
1613
1288
  heartbeatInterval: z.number().int().default(DEFAULT_WS_HEARTBEAT_MS) });
1614
1289
  /** 正向 WS client 实例(主动连接第三方,双向)。 */
@@ -1637,7 +1312,7 @@ const ob11ConfigSchema = z.object({
1637
1312
  /** 消息内容格式:array = 消息段数组(标准),string = CQ 码字符串。 */
1638
1313
  messagePostFormat: z.enum(MESSAGE_FORMATS).default("array"),
1639
1314
  /**
1640
- * 群文件报形式(B4,2026-09-08):false(缺省)= message 事件 + file 段
1315
+ * 群文件报形式():false(缺省)= message 事件 + file 段
1641
1316
  * (go-cqhttp 兼容;此前 file 元素被静默丢弃,本版本起透出);true = 含
1642
1317
  * fileElement 的群消息改报 group_upload notice 事件(替代 message 事件)。
1643
1318
  */
@@ -1774,7 +1449,7 @@ function cqMessageToCanonical(text) {
1774
1449
  }
1775
1450
  // src/onebot11/helper/message-info.ts
1776
1451
  /** RawMessage → OB11 消息信息(message_id 经 MessageUnique 映射)。
1777
- * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
1452
+ * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id)。 */
1778
1453
  function toOb11MessageInfo(msg, unique, ctx = {}) {
1779
1454
  const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
1780
1455
  let messageType = "private";
@@ -1802,14 +1477,12 @@ function toOb11MessageInfo(msg, unique, ctx = {}) {
1802
1477
  return info;
1803
1478
  }
1804
1479
  // src/onebot11/helper/notice.ts
1805
- /** 毫秒 → 秒(Unix 时间戳)。 */
1806
- const MS_TO_SEC$1 = 1e3;
1807
1480
  /** 群文件业务类型(group_upload 的 file.busid,与 kernel 群文件系列同源语义)。 */
1808
1481
  const GROUP_FILE_BUS_ID = 102;
1809
1482
  /**
1810
1483
  * 检查消息是否含文件元素(group_upload 开关分支判定)。
1811
1484
  *
1812
- * ⚠️ 用空值判定(`!= null`)而非 `!== undefined`(2026-11-10,Linux 原生宿主):
1485
+ * ⚠️ 用空值判定(`!= null`)而非 `!== undefined`(Linux 原生宿主):
1813
1486
  * Windows 原生对象省略未命中的元素变体字段,Linux 3.2.x 原生对象则把**全部**
1814
1487
  * 变体字段显式置 `null`(`"grayTipElement":null` 等)。用 `!== undefined`
1815
1488
  * 会把每条普通消息都判成「含该元素」——OB11 入站消息因此全部被误路由到
@@ -1827,9 +1500,9 @@ function base(msg, ctx) {
1827
1500
  group_id: Number(msg.peerUid)
1828
1501
  };
1829
1502
  }
1830
- /** 撤回事件(chatType 分流:GROUP→group_recall / C2C→friend_recall,2026-09-08)。 */
1503
+ /** 撤回事件(chatType 分流:GROUP→group_recall / C2C→friend_recall)。 */
1831
1504
  function toRecall(msg, g, ctx) {
1832
- if (g?.revokeElement === void 0) return null;
1505
+ if (g?.revokeElement == null) return null;
1833
1506
  const revoke = g.revokeElement;
1834
1507
  if (msg.chatType === ChatType.C2C) return {
1835
1508
  time: toUnixSeconds(msg.msgTime),
@@ -1848,7 +1521,7 @@ function toRecall(msg, g, ctx) {
1848
1521
  };
1849
1522
  }
1850
1523
  /**
1851
- * 戳一戳(notify.poke,aioOpGrayTipElement,2026-09-08)。
1524
+ * 戳一戳(notify.poke,aioOpGrayTipElement)。
1852
1525
  *
1853
1526
  * ⚠️ 待真实 poke 事件验证:aioOp 载荷的完整字段形状未经实测(实体类型仅有
1854
1527
  * operateType/peerUid 两个已证字段)。当前口径:user_id = 消息发送者,
@@ -1881,7 +1554,7 @@ const GROUP_CHANGE_BUILDERS = {
1881
1554
  /** 群成员变动(group_increase / group_decrease / group_admin / group_ban)。 */
1882
1555
  function toGroupChange(msg, g, ctx) {
1883
1556
  const grp = g?.groupElement;
1884
- if (grp === void 0 || grp.type === void 0) return null;
1557
+ if (grp == null || grp.type === void 0) return null;
1885
1558
  const builder = GROUP_CHANGE_BUILDERS[grp.type];
1886
1559
  if (builder === void 0) return null;
1887
1560
  return builder({
@@ -1950,14 +1623,14 @@ function toBan(common, grp, ctx) {
1950
1623
  };
1951
1624
  }
1952
1625
  /**
1953
- * 好友添加(friend_add,B2,2026-09-08)。
1626
+ * 好友添加(friend_add,)。
1954
1627
  * 数据源 = kernel BuddyCache 快照 diff(Buddy/onBuddyListChange 全量快照对比,
1955
1628
  * 首帧 baseline 不发)——非 grayTip 路径。user_id 取 coreInfo.uin(顶层 uin 兜底)。
1956
1629
  */
1957
1630
  function toFriendAdd(entry, selfUin) {
1958
1631
  const uin = entry.coreInfo?.uin ?? entry.uin ?? "";
1959
1632
  return {
1960
- time: Math.floor(Date.now() / MS_TO_SEC$1),
1633
+ time: Math.floor(Date.now() / MS_TO_SEC),
1961
1634
  self_id: Number(selfUin),
1962
1635
  post_type: "notice",
1963
1636
  notice_type: "friend_add",
@@ -1965,7 +1638,7 @@ function toFriendAdd(entry, selfUin) {
1965
1638
  };
1966
1639
  }
1967
1640
  /**
1968
- * 群文件上传(group_upload,B4,2026-09-08)。
1641
+ * 群文件上传(group_upload,)。
1969
1642
  * 数据源 = 含 fileElement 的群消息(开关 groupUploadAsNotice=true 时替代
1970
1643
  * message 事件报出)。file.id 取 fileUuid(缺省文件名)、size 取 fileSize、
1971
1644
  * busid 固定 102(群文件业务类型,与 kernel GROUP_FILE_BIZ_TYPE 同源语义)。
@@ -2005,11 +1678,11 @@ function logUntranslatedGrayTip(msg, ctx) {
2005
1678
  }, "ob11: 未翻译的 grayTip 子类型(raw 校准数据)");
2006
1679
  }
2007
1680
  /** RawMessage → OB11 notice 事件(无 grayTip 返回 null)。
2008
- * 未知/未翻译子类型打 raw JSON 日志(校准数据积累,2026-09-08)。 */
1681
+ * 未知/未翻译子类型打 raw JSON 日志(校准数据积累)。 */
2009
1682
  function toOb11NoticeEvent(msg, ctx) {
2010
1683
  for (const el of msg.elements) {
2011
1684
  const g = el.grayTipElement;
2012
- if (g === void 0) continue;
1685
+ if (g == null) continue;
2013
1686
  const event = translateGrayTip(msg, g, ctx);
2014
1687
  if (event !== null) return event;
2015
1688
  }
@@ -2017,7 +1690,7 @@ function toOb11NoticeEvent(msg, ctx) {
2017
1690
  }
2018
1691
  // src/onebot11/helper/request.ts
2019
1692
  /**
2020
- * OB11 request 事件翻译(2026-09-08)
1693
+ * OB11 request 事件翻译
2021
1694
  *
2022
1695
  * 事件源(kernel 事件通道,本次接线):
2023
1696
  * - `Group/onGroupNotifiesUpdated`(GroupBridge,群系统通知推送)→ group_add / group_invite
@@ -2027,7 +1700,7 @@ function toOb11NoticeEvent(msg, ctx) {
2027
1700
  * - 群请求 flag = GroupNotify.seq(set_group_add_request 按 `item.seq === flag` 匹配)
2028
1701
  * - 好友请求 flag = BuddyReq.reqTime(set_friend_add_request 按 `reqTime === flag` 匹配)
2029
1702
  *
2030
- * 纯函数(ADR-008):uid→uin 由调用方批量转换后传入。
1703
+ * 纯函数:uid→uin 由调用方批量转换后传入。
2031
1704
  * ⚠️ onBuddyReqChange 回调参数形状未经真实事件校准(wrapper 字符串证据仅有方法名),
2032
1705
  * narrowBuddyReqs 防御性收窄,未知形状返回 null 由调用方打 raw 日志积累校准数据。
2033
1706
  */
@@ -2052,7 +1725,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2052
1725
  default: return null;
2053
1726
  }
2054
1727
  return {
2055
- time: Math.floor(Date.now() / MS_TO_SEC$2),
1728
+ time: Math.floor(Date.now() / MS_TO_SEC),
2056
1729
  self_id: Number(ctx.selfUin),
2057
1730
  post_type: "request",
2058
1731
  request_type: "group",
@@ -2070,7 +1743,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2070
1743
  function toOb11FriendRequestEvent(req, ctx) {
2071
1744
  const words = req["words"];
2072
1745
  return {
2073
- time: Math.floor(Date.now() / MS_TO_SEC$2),
1746
+ time: Math.floor(Date.now() / MS_TO_SEC),
2074
1747
  self_id: Number(ctx.selfUin),
2075
1748
  post_type: "request",
2076
1749
  request_type: "friend",
@@ -2081,7 +1754,7 @@ function toOb11FriendRequestEvent(req, ctx) {
2081
1754
  }
2082
1755
  // src/onebot11/action/message/resolve-peer.ts
2083
1756
  /**
2084
- * OB11 目标 Peer 解析 / 单条消息拉取(多个动作共用,2026-08-08 克隆合并)
1757
+ * OB11 目标 Peer 解析 / 单条消息拉取(多个动作共用)
2085
1758
  *
2086
1759
  * group_id 直通(群消息 peerUid = 群号);user_id 经 uin→uid 解析。
2087
1760
  */
@@ -2117,16 +1790,15 @@ async function fetchMsgById(messageId, messageUnique, msgApi) {
2117
1790
  }
2118
1791
  // src/onebot11/action/message/forward.ts
2119
1792
  /**
2120
- * 消息转发域动作(2026-11-14 自 send-forward-msg / forward-single-msg /
2121
- * get-forward-msg 合并)
1793
+ * 消息转发域动作
2122
1794
  *
2123
- * - send_group_forward_msg / send_private_forward_msg(P2-12):messages 每项为
1795
+ * - send_group_forward_msg / send_private_forward_msg:messages 每项为
2124
1796
  * node 元素 `{ type: "node", data: { id } }`——id 是此前 send_msg 返回的 OB11
2125
1797
  * message_id。经 MessageUnique 反查源 msgId + peer,组装到目标 peer(群直通 /
2126
1798
  * 私聊 uinToUid)→ MsgApi.sendForwardMessage
2127
- * - forward_group_single_msg / forward_friend_single_msg(P2-12):message_id 反查
1799
+ * - forward_group_single_msg / forward_friend_single_msg:message_id 反查
2128
1800
  * 源 msgId + peer;group_id/user_id 为目标 → MsgApi.forwardSingleMessage
2129
- * - get_forward_msg(P2-12):message_id / id → fetchForwardMessage(getMultiMsg)
1801
+ * - get_forward_msg:message_id / id → fetchForwardMessage(getMultiMsg)
2130
1802
  * → 每条 toOb11MessageInfo → { messages }
2131
1803
  */
2132
1804
  const forwardNodeSchema = z.object({
@@ -2141,6 +1813,15 @@ const sendPrivateForwardMsgSchema = z.object({
2141
1813
  user_id: z.number(),
2142
1814
  messages: z.array(z.unknown()).max(500).default([])
2143
1815
  });
1816
+ const forwardSingleMsgSchema = z.object({
1817
+ message_id: z.union([z.number(), z.string()]),
1818
+ group_id: z.number().optional(),
1819
+ user_id: z.number().optional()
1820
+ });
1821
+ const getForwardMsgSchema = z.object({
1822
+ message_id: z.union([z.number(), z.string()]).optional(),
1823
+ id: z.union([z.number(), z.string()]).optional()
1824
+ });
2144
1825
  /** 解析 node 元素列表 → 源消息 (msgId, peer) 列表(id 反查,跳过无法解析的项)。 */
2145
1826
  function resolveSourceMessages(messages, unique) {
2146
1827
  const out = [];
@@ -2170,145 +1851,70 @@ async function sendForward(messages, target, deps) {
2170
1851
  const { msgId } = await deps.msgApi.sendForwardMessage(target, firstSource.peer, sources.map((s) => s.msgId));
2171
1852
  return { message_id: deps.messageUnique.alloc(msgId, target) };
2172
1853
  }
2173
- /** 发送群合并转发(P2-12 接 kernel sendForwardMessage)。 */
2174
- var SendGroupForwardMsgAction = class extends BaseAction {
2175
- name = "send_group_forward_msg";
2176
- schema = sendGroupForwardMsgSchema;
2177
- errorCodeMap = ob11ErrorCodeMap;
2178
- deps;
2179
- constructor(deps) {
2180
- super();
2181
- this.deps = deps;
2182
- }
2183
- async _handle(payload) {
2184
- const target = {
2185
- chatType: ChatType.GROUP,
2186
- peerUid: String(payload.group_id)
2187
- };
2188
- return await sendForward(payload.messages, target, this.deps);
2189
- }
2190
- };
2191
- /** 发送私聊合并转发(P2-12)。 */
2192
- var SendPrivateForwardMsgAction = class extends BaseAction {
2193
- name = "send_private_forward_msg";
2194
- schema = sendPrivateForwardMsgSchema;
2195
- errorCodeMap = ob11ErrorCodeMap;
2196
- deps;
2197
- constructor(deps) {
2198
- super();
2199
- this.deps = deps;
2200
- }
2201
- async _handle(payload) {
2202
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2203
- const target = {
2204
- chatType: ChatType.C2C,
2205
- peerUid: uid
2206
- };
2207
- return await sendForward(payload.messages, target, this.deps);
2208
- }
2209
- };
2210
- const forwardSingleMsgSchema = z.object({
2211
- message_id: z.union([z.number(), z.string()]),
2212
- group_id: z.number().optional(),
2213
- user_id: z.number().optional()
2214
- });
2215
- /** 单条转发基类(两个动作共用实现)。 */
2216
- var ForwardSingleMsgBase = class extends BaseAction {
2217
- errorCodeMap = ob11ErrorCodeMap;
2218
- deps;
2219
- constructor(deps) {
2220
- super();
2221
- this.deps = deps;
2222
- }
2223
- async _handle(payload) {
2224
- const { msgId, peer: sourcePeer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
2225
- const dstPeer = await resolveTargetPeer(payload, this.deps, "单条转发需要 group_id 或 user_id");
2226
- await this.deps.msgApi.forwardSingleMessage(sourcePeer, [msgId], dstPeer);
2227
- return null;
2228
- }
2229
- };
2230
- /** 转发单条消息到群(P2-12)。 */
2231
- var ForwardGroupSingleMsgAction = class extends ForwardSingleMsgBase {
2232
- name = "forward_group_single_msg";
2233
- schema = forwardSingleMsgSchema;
2234
- };
2235
- /** 转发单条消息到好友(P2-12)。 */
2236
- var ForwardFriendSingleMsgAction = class extends ForwardSingleMsgBase {
2237
- name = "forward_friend_single_msg";
2238
- schema = forwardSingleMsgSchema;
2239
- };
2240
- const getForwardMsgSchema = z.object({
2241
- message_id: z.union([z.number(), z.string()]).optional(),
2242
- id: z.union([z.number(), z.string()]).optional()
2243
- });
2244
- /** 获取合并转发内容(P2-12 接 kernel fetchForwardMessage)。 */
2245
- var GetForwardMsgAction = class extends BaseAction {
2246
- name = "get_forward_msg";
2247
- schema = getForwardMsgSchema;
2248
- errorCodeMap = ob11ErrorCodeMap;
2249
- deps;
2250
- constructor(deps) {
2251
- super();
2252
- this.deps = deps;
2253
- }
2254
- async _handle(payload) {
2255
- const id = payload.message_id ?? payload.id;
2256
- if (id === void 0) throw kernelError("get_forward_msg 需要 message_id 或 id", "INVALID_PARAM");
2257
- const { msgId, peer } = resolveMsgIdAndPeer(id, this.deps.messageUnique);
2258
- return { messages: (await this.deps.msgApi.fetchForwardMessage(peer, msgId)).map((msg) => toOb11MessageInfo(msg, this.deps.messageUnique)) };
2259
- }
2260
- };
2261
- /** 消息转发域动作工厂(合并转发 ×2 / 单条转发 ×2 / get_forward_msg)。 */
1854
+ /** 单条转发共用实现:message_id 反查源消息 + 目标 Peer 解析 → forwardSingleMessage。 */
1855
+ async function forwardSingleMsg(payload, deps) {
1856
+ const { msgId, peer: sourcePeer } = resolveMsgIdAndPeer(payload.message_id, deps.messageUnique);
1857
+ const dstPeer = await resolveTargetPeer(payload, deps, "单条转发需要 group_id 或 user_id");
1858
+ await deps.msgApi.forwardSingleMessage(sourcePeer, [msgId], dstPeer);
1859
+ return null;
1860
+ }
1861
+ /** 消息转发域动作工厂(合并转发 ×2 / get_forward_msg / 单条转发 ×2)。 */
2262
1862
  function createForwardActions(api) {
2263
1863
  return [
2264
- new SendGroupForwardMsgAction(api),
2265
- new SendPrivateForwardMsgAction(api),
2266
- new GetForwardMsgAction(api),
2267
- new ForwardGroupSingleMsgAction(api),
2268
- new ForwardFriendSingleMsgAction(api)
1864
+ defineOb11Action({
1865
+ name: "send_group_forward_msg",
1866
+ schema: sendGroupForwardMsgSchema,
1867
+ handle: async (payload) => {
1868
+ const target = {
1869
+ chatType: ChatType.GROUP,
1870
+ peerUid: String(payload.group_id)
1871
+ };
1872
+ return await sendForward(payload.messages, target, api);
1873
+ }
1874
+ }),
1875
+ defineOb11Action({
1876
+ name: "send_private_forward_msg",
1877
+ schema: sendPrivateForwardMsgSchema,
1878
+ handle: async (payload) => {
1879
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
1880
+ const target = {
1881
+ chatType: ChatType.C2C,
1882
+ peerUid: uid
1883
+ };
1884
+ return await sendForward(payload.messages, target, api);
1885
+ }
1886
+ }),
1887
+ defineOb11Action({
1888
+ name: "get_forward_msg",
1889
+ schema: getForwardMsgSchema,
1890
+ handle: async (payload) => {
1891
+ const id = payload.message_id ?? payload.id;
1892
+ if (id === void 0) throw kernelError("get_forward_msg 需要 message_id 或 id", "INVALID_PARAM");
1893
+ const { msgId, peer } = resolveMsgIdAndPeer(id, api.messageUnique);
1894
+ return { messages: (await api.msgApi.fetchForwardMessage(peer, msgId)).map((msg) => toOb11MessageInfo(msg, api.messageUnique)) };
1895
+ }
1896
+ }),
1897
+ defineOb11Action({
1898
+ name: "forward_group_single_msg",
1899
+ schema: forwardSingleMsgSchema,
1900
+ handle: (payload) => forwardSingleMsg(payload, api)
1901
+ }),
1902
+ defineOb11Action({
1903
+ name: "forward_friend_single_msg",
1904
+ schema: forwardSingleMsgSchema,
1905
+ handle: (payload) => forwardSingleMsg(payload, api)
1906
+ })
2269
1907
  ];
2270
1908
  }
2271
1909
  // src/onebot11/action/message/history.ts
2272
1910
  /**
2273
- * 消息读取域动作(2026-11-14 自 get-msg / msg-history / get-group-msg-history /
2274
- * get-friend-msg-history 合并)
1911
+ * 消息读取域动作
2275
1912
  *
2276
1913
  * - get_msg:message_id → msgId + peer(MessageUnique 反查)→ 拉消息 → OB11 消息信息
2277
1914
  * - get_group_msg_history(go-cqhttp 扩展)/ get_friend_msg_history(NapCat 扩展):
2278
1915
  * 拉取历史消息 → at uid 批量转换 → OB11 消息信息数组(共享 fetchAndTranslateHistory)
2279
1916
  */
2280
1917
  const getMsgSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2281
- /** 获取消息详情(P2-10 接 kernel fetchMsgsByMsgId)。 */
2282
- var GetMsgAction = class extends BaseAction {
2283
- name = "get_msg";
2284
- schema = getMsgSchema;
2285
- errorCodeMap = ob11ErrorCodeMap;
2286
- deps;
2287
- constructor(deps) {
2288
- super();
2289
- this.deps = deps;
2290
- }
2291
- async _handle(payload) {
2292
- const { msg } = await fetchMsgById(payload.message_id, this.deps.messageUnique, this.deps.msgApi);
2293
- const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
2294
- let uidToUin;
2295
- if (atUids.length > 0) try {
2296
- uidToUin = await this.deps.uidToUin(atUids);
2297
- } catch (err) {
2298
- this.deps.logger?.warn({
2299
- count: atUids.length,
2300
- error: err instanceof Error ? err.message : String(err)
2301
- }, "ob11: get_msg at uid→uin 失败,at 原样");
2302
- }
2303
- const senderRole = msg.chatType === ChatType.GROUP ? await this.deps.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
2304
- const ctx = {
2305
- ...uidToUin !== void 0 ? { uidToUin } : {},
2306
- ...senderRole !== void 0 ? { senderRole } : {},
2307
- msgIdToOb11Id: (m) => this.deps.messageUnique.getMessageId(m)
2308
- };
2309
- return toOb11MessageInfo(msg, this.deps.messageUnique, ctx);
2310
- }
2311
- };
2312
1918
  /** 历史消息公共参数(message_seq / count / 反向排序)。 */
2313
1919
  const msgHistoryParamsSchema = {
2314
1920
  /** 起始消息序号(message_seq,缺省从最新拉)。 */
@@ -2328,7 +1934,7 @@ function resolveStartMsgId(messageSeq, messageUnique) {
2328
1934
  }
2329
1935
  /**
2330
1936
  * 拉取历史消息并翻译为 OB11 消息信息数组。
2331
- * 收集全部消息 at uid → 一次批量 uidToUin → 上下文注入(P2-19)。
1937
+ * 收集全部消息 at uid → 一次批量 uidToUin → 上下文注入。
2332
1938
  * 群聊另取发送者角色表(GroupCache 一次整表读取,失败回退缺省 member)。
2333
1939
  */
2334
1940
  async function fetchAndTranslateHistory(peer, messageSeq, count, deps) {
@@ -2369,65 +1975,71 @@ const getGroupMsgHistorySchema = z.object({
2369
1975
  group_id: z.number(),
2370
1976
  ...msgHistoryParamsSchema
2371
1977
  });
2372
- /** 获取群历史消息(P2-10 接 kernel fetchMessages)。 */
2373
- var GetGroupMsgHistoryAction = class extends BaseAction {
2374
- name = "get_group_msg_history";
2375
- schema = getGroupMsgHistorySchema;
2376
- errorCodeMap = ob11ErrorCodeMap;
2377
- deps;
2378
- constructor(deps) {
2379
- super();
2380
- this.deps = deps;
2381
- }
2382
- async _handle(payload) {
2383
- return await fetchAndTranslateHistory({
2384
- chatType: ChatType.GROUP,
2385
- peerUid: String(payload.group_id)
2386
- }, payload.message_seq, payload.count, this.deps);
2387
- }
2388
- };
2389
1978
  const getFriendMsgHistorySchema = z.object({
2390
1979
  user_id: z.number(),
2391
1980
  ...msgHistoryParamsSchema
2392
1981
  });
2393
- /** 获取私聊历史消息(P2-10 接 kernel fetchMessages)。 */
2394
- var GetFriendMsgHistoryAction = class extends BaseAction {
2395
- name = "get_friend_msg_history";
2396
- schema = getFriendMsgHistorySchema;
2397
- errorCodeMap = ob11ErrorCodeMap;
2398
- deps;
2399
- constructor(deps) {
2400
- super();
2401
- this.deps = deps;
2402
- }
2403
- async _handle(payload) {
2404
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2405
- return await fetchAndTranslateHistory({
2406
- chatType: ChatType.C2C,
2407
- peerUid: uid
2408
- }, payload.message_seq, payload.count, this.deps);
2409
- }
2410
- };
2411
1982
  /** 消息读取域动作工厂(get_msg / get_group_msg_history / get_friend_msg_history)。 */
2412
1983
  function createHistoryActions(api) {
2413
1984
  return [
2414
- new GetMsgAction(api),
2415
- new GetGroupMsgHistoryAction(api),
2416
- new GetFriendMsgHistoryAction(api)
1985
+ defineOb11Action({
1986
+ name: "get_msg",
1987
+ schema: getMsgSchema,
1988
+ handle: async (payload) => {
1989
+ const { msg } = await fetchMsgById(payload.message_id, api.messageUnique, api.msgApi);
1990
+ const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
1991
+ let uidToUin;
1992
+ if (atUids.length > 0) try {
1993
+ uidToUin = await api.uidToUin(atUids);
1994
+ } catch (err) {
1995
+ api.logger?.warn({
1996
+ count: atUids.length,
1997
+ error: err instanceof Error ? err.message : String(err)
1998
+ }, "ob11: get_msg at uid→uin 失败,at 原样");
1999
+ }
2000
+ const senderRole = msg.chatType === ChatType.GROUP ? await api.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
2001
+ const ctx = {
2002
+ ...uidToUin !== void 0 ? { uidToUin } : {},
2003
+ ...senderRole !== void 0 ? { senderRole } : {},
2004
+ msgIdToOb11Id: (m) => api.messageUnique.getMessageId(m)
2005
+ };
2006
+ return toOb11MessageInfo(msg, api.messageUnique, ctx);
2007
+ }
2008
+ }),
2009
+ defineOb11Action({
2010
+ name: "get_group_msg_history",
2011
+ schema: getGroupMsgHistorySchema,
2012
+ handle: async (payload) => {
2013
+ return await fetchAndTranslateHistory({
2014
+ chatType: ChatType.GROUP,
2015
+ peerUid: String(payload.group_id)
2016
+ }, payload.message_seq, payload.count, api);
2017
+ }
2018
+ }),
2019
+ defineOb11Action({
2020
+ name: "get_friend_msg_history",
2021
+ schema: getFriendMsgHistorySchema,
2022
+ handle: async (payload) => {
2023
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2024
+ return await fetchAndTranslateHistory({
2025
+ chatType: ChatType.C2C,
2026
+ peerUid: uid
2027
+ }, payload.message_seq, payload.count, api);
2028
+ }
2029
+ })
2417
2030
  ];
2418
2031
  }
2419
2032
  // src/onebot11/action/message/media.ts
2420
2033
  /**
2421
- * 消息媒体域动作(2026-11-14 自 get-media / fetch-ptt-text 合并)
2034
+ * 消息媒体域动作
2422
2035
  *
2423
- * - get_image / get_record:获取图片/语音文件(P2-14;2026-09-08 T5 接主动下载;
2424
- * 2026-09-08 B1 语音接原生 downloadRichMedia)。message_id 反查 → fetchMsgsByMsgId
2425
- * → 找 PIC/PTT 元素:
2036
+ * - get_image / get_record:获取图片/语音文件(图片接主动下载;语音接原生
2037
+ * downloadRichMedia)。message_id 反查 → fetchMsgsByMsgId → 找 PIC/PTT 元素:
2426
2038
  * - 本地文件解析:NT 相对路径(sourcePath/filePath)按 mediaBaseDir(QQ NT
2427
2039
  * global 目录)解析为绝对路径,命中磁盘即返回 file
2428
2040
  * - 图片主动下载:本地未命中且有 picUrl → @napuketto/media downloadUrl 落
2429
2041
  * cacheDir/media/,返回 file(绝对路径)+ url + file_size/file_name
2430
- * - 语音主动下载(B1):本地未命中 → kernel MsgApi.downloadPtt(原生
2042
+ * - 语音主动下载:本地未命中 → kernel MsgApi.downloadPtt(原生
2431
2043
  * downloadRichMedia + 轮询元素回查)→ filePath 落盘后返回绝对路径;
2432
2044
  * 失败回退原始 filePath(NT 相对/绝对)+ 元数据,不抛错
2433
2045
  * - fetch_ptt_text:message_id → MsgApi.fetchPttText(内部:拉消息 → 找 PTT 元素
@@ -2438,6 +2050,7 @@ const getMediaSchema = z.object({
2438
2050
  file: z.string().optional(),
2439
2051
  message_id: z.union([z.number(), z.string()]).optional()
2440
2052
  });
2053
+ const fetchPttTextSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2441
2054
  /**
2442
2055
  * NT 相对路径 → 本地绝对路径(存在才返回)。
2443
2056
  * 候选:原样绝对路径 / mediaBaseDir 下相对路径(反斜杠归一化)。
@@ -2491,119 +2104,95 @@ function takeId(payload, actionName) {
2491
2104
  if (id === void 0) throw kernelError(`${actionName} 需要 message_id 或 file`, "INVALID_PARAM");
2492
2105
  return id;
2493
2106
  }
2494
- /** 获取图片信息(本地优先,picUrl 主动下载兜底)。 */
2495
- var GetImageAction = class extends BaseAction {
2496
- name = "get_image";
2497
- schema = getMediaSchema;
2498
- errorCodeMap = ob11ErrorCodeMap;
2499
- deps;
2500
- constructor(deps) {
2501
- super();
2502
- this.deps = deps;
2503
- }
2504
- async _handle(payload) {
2505
- const base = await resolveMedia(takeId(payload, "get_image"), "图片", this.deps, (el) => {
2506
- const pic = el.picElement;
2507
- if (pic === void 0) return;
2508
- const out = {};
2509
- if (pic.fileSize !== void 0) out.file_size = pic.fileSize;
2510
- if (pic.fileName !== void 0) out.file_name = pic.fileName;
2511
- if (pic.picUrl !== void 0) out.url = pic.picUrl;
2512
- const rel = pic.sourcePath ?? pic.picPath;
2513
- if (rel !== void 0) {
2514
- const local = resolveLocalMediaFile(rel, this.deps);
2515
- if (local !== null) out.file = local;
2516
- }
2517
- return out;
2518
- });
2519
- if (base.file === void 0 && base.url !== void 0) {
2520
- const downloaded = await downloadImageToCache(base.url, this.deps);
2521
- if (downloaded !== null) base.file = downloaded;
2522
- }
2523
- return base;
2107
+ /** 提取 pic 元素 → 媒体信息(url / 本地 file / 元数据;非 pic 元素返回 undefined)。 */
2108
+ function extractPicElement(el, deps) {
2109
+ const pic = el.picElement;
2110
+ if (pic == null) return;
2111
+ const out = {};
2112
+ if (pic.fileSize !== void 0) out.file_size = pic.fileSize;
2113
+ if (pic.fileName !== void 0) out.file_name = pic.fileName;
2114
+ if (pic.picUrl !== void 0) out.url = pic.picUrl;
2115
+ const rel = pic.sourcePath ?? pic.picPath;
2116
+ if (rel !== void 0) {
2117
+ const local = resolveLocalMediaFile(rel, deps);
2118
+ if (local !== null) out.file = local;
2524
2119
  }
2525
- };
2526
- /** 获取语音信息(本地优先;未命中走原生 downloadRichMedia,失败回退原始路径)。 */
2527
- var GetRecordAction = class extends BaseAction {
2528
- name = "get_record";
2529
- schema = getMediaSchema;
2530
- errorCodeMap = ob11ErrorCodeMap;
2531
- deps;
2532
- constructor(deps) {
2533
- super();
2534
- this.deps = deps;
2535
- }
2536
- async _handle(payload) {
2537
- const id = takeId(payload, "get_record");
2538
- const { msgId, peer } = resolveMsgIdAndPeer(id, this.deps.messageUnique);
2539
- const [first] = await this.deps.msgApi.fetchMsgsByMsgId(peer, [msgId]);
2540
- if (first === void 0) throw kernelError(`消息 ${id} 不存在或已被撤回`, "NOT_FOUND");
2541
- const ptt = first.elements.find((e) => e.pttElement !== void 0)?.pttElement;
2542
- if (ptt === void 0 || ptt.filePath === void 0) throw kernelError(`消息 ${id} 不包含语音`, "NOT_FOUND");
2543
- const meta = () => ({
2544
- ...ptt.fileSize !== void 0 ? { file_size: ptt.fileSize } : {},
2545
- ...ptt.fileName !== void 0 ? { file_name: ptt.fileName } : {}
2546
- });
2547
- const local = resolveLocalMediaFile(ptt.filePath, this.deps);
2548
- if (local !== null) return {
2549
- ...meta(),
2550
- file: local
2551
- };
2552
- return await this.downloadPttFallback(msgId, peer, id) ?? {
2553
- ...meta(),
2554
- file: ptt.filePath
2555
- };
2556
- }
2557
- /** 原生下载语音 → 元素回查本地路径;下载失败/未命中 null(warn 留痕,不抛错)。 */
2558
- async downloadPttFallback(msgId, peer, id) {
2559
- try {
2560
- const downloaded = await this.deps.msgApi.downloadPtt(msgId, peer);
2561
- const rel = downloaded.filePath;
2562
- if (rel !== void 0 && rel !== "") {
2563
- const localAfter = resolveLocalMediaFile(rel, this.deps);
2564
- if (localAfter !== null) return {
2565
- ...downloaded.fileSize !== void 0 ? { file_size: downloaded.fileSize } : {},
2566
- ...downloaded.fileName !== void 0 ? { file_name: downloaded.fileName } : {},
2567
- file: localAfter
2568
- };
2569
- }
2570
- } catch (err) {
2571
- this.deps.logger?.warn({
2572
- message_id: id,
2573
- error: err instanceof Error ? err.message : String(err)
2574
- }, "ob11: 语音原生下载失败,get_record 回退原始路径");
2120
+ return out;
2121
+ }
2122
+ /** 原生下载语音 → 元素回查本地路径;下载失败/未命中 null(warn 留痕,不抛错)。 */
2123
+ async function downloadPttFallback(msgId, peer, id, deps) {
2124
+ try {
2125
+ const downloaded = await deps.msgApi.downloadPtt(msgId, peer);
2126
+ const rel = downloaded.filePath;
2127
+ if (rel !== void 0 && rel !== "") {
2128
+ const localAfter = resolveLocalMediaFile(rel, deps);
2129
+ if (localAfter !== null) return {
2130
+ ...downloaded.fileSize !== void 0 ? { file_size: downloaded.fileSize } : {},
2131
+ ...downloaded.fileName !== void 0 ? { file_name: downloaded.fileName } : {},
2132
+ file: localAfter
2133
+ };
2575
2134
  }
2576
- return null;
2577
- }
2578
- };
2579
- const fetchPttTextSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2580
- /** 获取语音转文字结果(P2-10 接 kernel fetchPttText)。 */
2581
- var FetchPttTextAction = class extends BaseAction {
2582
- name = "fetch_ptt_text";
2583
- schema = fetchPttTextSchema;
2584
- errorCodeMap = ob11ErrorCodeMap;
2585
- deps;
2586
- constructor(deps) {
2587
- super();
2588
- this.deps = deps;
2589
- }
2590
- async _handle(payload) {
2591
- const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
2592
- return { text: await this.deps.msgApi.fetchPttText(msgId, peer) };
2135
+ } catch (err) {
2136
+ deps.logger?.warn({
2137
+ message_id: id,
2138
+ error: err instanceof Error ? err.message : String(err)
2139
+ }, "ob11: 语音原生下载失败,get_record 回退原始路径");
2593
2140
  }
2594
- };
2141
+ return null;
2142
+ }
2595
2143
  /** 消息媒体域动作工厂(get_image / get_record / fetch_ptt_text)。 */
2596
2144
  function createMediaActions(api) {
2597
2145
  return [
2598
- new GetImageAction(api),
2599
- new GetRecordAction(api),
2600
- new FetchPttTextAction(api)
2146
+ defineOb11Action({
2147
+ name: "get_image",
2148
+ schema: getMediaSchema,
2149
+ handle: async (payload) => {
2150
+ const base = await resolveMedia(takeId(payload, "get_image"), "图片", api, (el) => extractPicElement(el, api));
2151
+ if (base.file === void 0 && base.url !== void 0) {
2152
+ const downloaded = await downloadImageToCache(base.url, api);
2153
+ if (downloaded !== null) base.file = downloaded;
2154
+ }
2155
+ return base;
2156
+ }
2157
+ }),
2158
+ defineOb11Action({
2159
+ name: "get_record",
2160
+ schema: getMediaSchema,
2161
+ handle: async (payload) => {
2162
+ const id = takeId(payload, "get_record");
2163
+ const { msgId, peer } = resolveMsgIdAndPeer(id, api.messageUnique);
2164
+ const [first] = await api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
2165
+ if (first === void 0) throw kernelError(`消息 ${id} 不存在或已被撤回`, "NOT_FOUND");
2166
+ const ptt = first.elements.find((e) => e.pttElement != null)?.pttElement;
2167
+ if (ptt == null || ptt.filePath === void 0) throw kernelError(`消息 ${id} 不包含语音`, "NOT_FOUND");
2168
+ const meta = () => ({
2169
+ ...ptt.fileSize !== void 0 ? { file_size: ptt.fileSize } : {},
2170
+ ...ptt.fileName !== void 0 ? { file_name: ptt.fileName } : {}
2171
+ });
2172
+ const local = resolveLocalMediaFile(ptt.filePath, api);
2173
+ if (local !== null) return {
2174
+ ...meta(),
2175
+ file: local
2176
+ };
2177
+ return await downloadPttFallback(msgId, peer, id, api) ?? {
2178
+ ...meta(),
2179
+ file: ptt.filePath
2180
+ };
2181
+ }
2182
+ }),
2183
+ defineOb11Action({
2184
+ name: "fetch_ptt_text",
2185
+ schema: fetchPttTextSchema,
2186
+ handle: async (payload) => {
2187
+ const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, api.messageUnique);
2188
+ return { text: await api.msgApi.fetchPttText(msgId, peer) };
2189
+ }
2190
+ })
2601
2191
  ];
2602
2192
  }
2603
2193
  // src/onebot11/action/message/ops.ts
2604
2194
  /**
2605
- * 消息操作域动作(2026-11-14 自 delete-msg / mark-msg-as-read(-aliases) /
2606
- * set-msg-emoji-like / set-input-status 合并)
2195
+ * 消息操作域动作
2607
2196
  *
2608
2197
  * - delete_msg:撤回消息(OB11 标准只有 message_id,peer 经 MessageUnique 反查;
2609
2198
  * 群聊管理员 / 私聊 2 分钟内可撤回)
@@ -2613,93 +2202,12 @@ function createMediaActions(api) {
2613
2202
  * - set_input_status:user_id → uinToUid → MsgApi.setInputStatus(1=输入中,0=停止)
2614
2203
  */
2615
2204
  const deleteMsgSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2616
- /** 撤回消息(P2-10 接 kernel recallMessage)。 */
2617
- var DeleteMsgAction = class extends BaseAction {
2618
- name = "delete_msg";
2619
- schema = deleteMsgSchema;
2620
- errorCodeMap = ob11ErrorCodeMap;
2621
- deps;
2622
- constructor(deps) {
2623
- super();
2624
- this.deps = deps;
2625
- }
2626
- async _handle(payload) {
2627
- const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
2628
- await this.deps.msgApi.recallMessage(peer, [msgId]);
2629
- return null;
2630
- }
2631
- };
2632
2205
  const markMsgAsReadSchema = z.object({
2633
2206
  user_id: z.number().optional(),
2634
2207
  group_id: z.number().optional()
2635
2208
  }).refine((v) => v.user_id !== void 0 || v.group_id !== void 0, { message: "mark_msg_as_read 需要 user_id 或 group_id" });
2636
- /** 标记消息已读(P2-10 接 kernel markRead)。 */
2637
- var MarkMsgAsReadAction = class extends BaseAction {
2638
- name = "mark_msg_as_read";
2639
- schema = markMsgAsReadSchema;
2640
- errorCodeMap = ob11ErrorCodeMap;
2641
- deps;
2642
- constructor(deps) {
2643
- super();
2644
- this.deps = deps;
2645
- }
2646
- async _handle(payload) {
2647
- if (payload.group_id !== void 0) {
2648
- await this.deps.msgApi.markRead({
2649
- chatType: ChatType.GROUP,
2650
- peerUid: String(payload.group_id)
2651
- });
2652
- return null;
2653
- }
2654
- if (payload.user_id !== void 0) {
2655
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2656
- await this.deps.msgApi.markRead({
2657
- chatType: ChatType.C2C,
2658
- peerUid: uid
2659
- });
2660
- }
2661
- return null;
2662
- }
2663
- };
2664
2209
  const markPrivateMsgAsReadSchema = z.object({ user_id: z.number() });
2665
2210
  const markGroupMsgAsReadSchema = z.object({ group_id: z.number() });
2666
- /** 标记私聊已读(P2-13)。 */
2667
- var MarkPrivateMsgAsReadAction = class extends BaseAction {
2668
- name = "mark_private_msg_as_read";
2669
- schema = markPrivateMsgAsReadSchema;
2670
- errorCodeMap = ob11ErrorCodeMap;
2671
- deps;
2672
- constructor(deps) {
2673
- super();
2674
- this.deps = deps;
2675
- }
2676
- async _handle(payload) {
2677
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2678
- await this.deps.msgApi.markRead({
2679
- chatType: ChatType.C2C,
2680
- peerUid: uid
2681
- });
2682
- return null;
2683
- }
2684
- };
2685
- /** 标记群聊已读(P2-13)。 */
2686
- var MarkGroupMsgAsReadAction = class extends BaseAction {
2687
- name = "mark_group_msg_as_read";
2688
- schema = markGroupMsgAsReadSchema;
2689
- errorCodeMap = ob11ErrorCodeMap;
2690
- deps;
2691
- constructor(deps) {
2692
- super();
2693
- this.deps = deps;
2694
- }
2695
- async _handle(payload) {
2696
- await this.deps.msgApi.markRead({
2697
- chatType: ChatType.GROUP,
2698
- peerUid: String(payload.group_id)
2699
- });
2700
- return null;
2701
- }
2702
- };
2703
2211
  const setMsgEmojiLikeSchema = z.object({
2704
2212
  message_id: z.union([z.number(), z.string()]),
2705
2213
  /** 表情 ID(如 105 点赞)。 */
@@ -2709,65 +2217,98 @@ const setMsgEmojiLikeSchema = z.object({
2709
2217
  /** 是否点赞(false 取消)。 */
2710
2218
  like: z.boolean().optional()
2711
2219
  });
2712
- /** 消息表情表态(P2-10 接 kernel setMsgEmojiLike)。 */
2713
- var SetMsgEmojiLikeAction = class extends BaseAction {
2714
- name = "set_msg_emoji_like";
2715
- schema = setMsgEmojiLikeSchema;
2716
- errorCodeMap = ob11ErrorCodeMap;
2717
- deps;
2718
- constructor(deps) {
2719
- super();
2720
- this.deps = deps;
2721
- }
2722
- async _handle(payload) {
2723
- const { msg, peer } = await fetchMsgById(payload.message_id, this.deps.messageUnique, this.deps.msgApi);
2724
- await this.deps.msgApi.setMsgEmojiLike(peer, {
2725
- msgSeq: msg.msgSeq,
2726
- emojiId: String(payload.emoji_id),
2727
- emojiType: String(payload.emoji_type ?? 1),
2728
- like: payload.like ?? true
2729
- });
2730
- return null;
2731
- }
2732
- };
2733
2220
  const setInputStatusSchema = z.object({
2734
2221
  user_id: z.number(),
2735
2222
  /** 输入事件类型:1=输入中,0=停止。 */
2736
2223
  event_type: z.number().optional()
2737
2224
  });
2738
2225
  /** 输入中事件类型。 */
2739
- const EVENT_TYPE_TYPING = 1;
2740
- /** 发送输入状态(P2-11 接 kernel setInputStatus)。 */
2741
- var SetInputStatusAction = class extends BaseAction {
2742
- name = "set_input_status";
2743
- schema = setInputStatusSchema;
2744
- errorCodeMap = ob11ErrorCodeMap;
2745
- deps;
2746
- constructor(deps) {
2747
- super();
2748
- this.deps = deps;
2749
- }
2750
- async _handle(payload) {
2751
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2752
- await this.deps.msgApi.setInputStatus({
2753
- chatType: ChatType.C2C,
2754
- peerUid: uid
2755
- }, payload.event_type ?? EVENT_TYPE_TYPING);
2756
- return null;
2757
- }
2758
- };
2226
+ const EVENT_TYPE_TYPING = 1;
2759
2227
  /**
2760
2228
  * 消息操作域动作工厂(delete_msg / mark_msg_as_read 系列 / set_msg_emoji_like /
2761
2229
  * set_input_status)。
2762
2230
  */
2763
2231
  function createMsgOpsActions(api) {
2764
2232
  return [
2765
- new DeleteMsgAction(api),
2766
- new MarkMsgAsReadAction(api),
2767
- new MarkPrivateMsgAsReadAction(api),
2768
- new MarkGroupMsgAsReadAction(api),
2769
- new SetMsgEmojiLikeAction(api),
2770
- new SetInputStatusAction(api)
2233
+ defineOb11Action({
2234
+ name: "delete_msg",
2235
+ schema: deleteMsgSchema,
2236
+ handle: async (payload) => {
2237
+ const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, api.messageUnique);
2238
+ await api.msgApi.recallMessage(peer, [msgId]);
2239
+ return null;
2240
+ }
2241
+ }),
2242
+ defineOb11Action({
2243
+ name: "mark_msg_as_read",
2244
+ schema: markMsgAsReadSchema,
2245
+ handle: async (payload) => {
2246
+ if (payload.group_id !== void 0) {
2247
+ await api.msgApi.markRead({
2248
+ chatType: ChatType.GROUP,
2249
+ peerUid: String(payload.group_id)
2250
+ });
2251
+ return null;
2252
+ }
2253
+ if (payload.user_id !== void 0) {
2254
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2255
+ await api.msgApi.markRead({
2256
+ chatType: ChatType.C2C,
2257
+ peerUid: uid
2258
+ });
2259
+ }
2260
+ return null;
2261
+ }
2262
+ }),
2263
+ defineOb11Action({
2264
+ name: "mark_private_msg_as_read",
2265
+ schema: markPrivateMsgAsReadSchema,
2266
+ handle: async (payload) => {
2267
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2268
+ await api.msgApi.markRead({
2269
+ chatType: ChatType.C2C,
2270
+ peerUid: uid
2271
+ });
2272
+ return null;
2273
+ }
2274
+ }),
2275
+ defineOb11Action({
2276
+ name: "mark_group_msg_as_read",
2277
+ schema: markGroupMsgAsReadSchema,
2278
+ handle: async (payload) => {
2279
+ await api.msgApi.markRead({
2280
+ chatType: ChatType.GROUP,
2281
+ peerUid: String(payload.group_id)
2282
+ });
2283
+ return null;
2284
+ }
2285
+ }),
2286
+ defineOb11Action({
2287
+ name: "set_msg_emoji_like",
2288
+ schema: setMsgEmojiLikeSchema,
2289
+ handle: async (payload) => {
2290
+ const { msg, peer } = await fetchMsgById(payload.message_id, api.messageUnique, api.msgApi);
2291
+ await api.msgApi.setMsgEmojiLike(peer, {
2292
+ msgSeq: msg.msgSeq,
2293
+ emojiId: String(payload.emoji_id),
2294
+ emojiType: String(payload.emoji_type ?? 1),
2295
+ like: payload.like ?? true
2296
+ });
2297
+ return null;
2298
+ }
2299
+ }),
2300
+ defineOb11Action({
2301
+ name: "set_input_status",
2302
+ schema: setInputStatusSchema,
2303
+ handle: async (payload) => {
2304
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2305
+ await api.msgApi.setInputStatus({
2306
+ chatType: ChatType.C2C,
2307
+ peerUid: uid
2308
+ }, payload.event_type ?? EVENT_TYPE_TYPING);
2309
+ return null;
2310
+ }
2311
+ })
2771
2312
  ];
2772
2313
  }
2773
2314
  // src/onebot11/action/message/send.ts
@@ -2778,6 +2319,19 @@ const sendMsgSchema = z.object({
2778
2319
  message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2779
2320
  auto_escape: z.boolean().optional()
2780
2321
  });
2322
+ /** send_private / send_group 共用的消息与转义字段(上界见 action/limits.ts)。 */
2323
+ const sendMsgBodyFields = {
2324
+ message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2325
+ auto_escape: z.boolean().optional()
2326
+ };
2327
+ const sendPrivateMsgSchema = z.object({
2328
+ user_id: z.number(),
2329
+ ...sendMsgBodyFields
2330
+ });
2331
+ const sendGroupMsgSchema = z.object({
2332
+ group_id: z.number(),
2333
+ ...sendMsgBodyFields
2334
+ });
2781
2335
  /** 共享发送核心:解析 Peer → canonical 翻译(含 auto_escape)→ sendMessage → 映射 message_id。 */
2782
2336
  async function sendOb11Message(payload, deps) {
2783
2337
  const peer = await resolveTargetPeer(payload, deps, "send_msg 需要 group_id 或 user_id");
@@ -2815,58 +2369,6 @@ async function sendOb11Message(payload, deps) {
2815
2369
  await prepared.cleanup();
2816
2370
  }
2817
2371
  }
2818
- /** 发送消息(P2-3 接 kernel apis/msg,返回真实 message_id)。 */
2819
- var SendMsgAction = class extends BaseAction {
2820
- name = "send_msg";
2821
- schema = sendMsgSchema;
2822
- errorCodeMap = ob11ErrorCodeMap;
2823
- deps;
2824
- constructor(deps) {
2825
- super();
2826
- this.deps = deps;
2827
- }
2828
- _handle(payload) {
2829
- return sendOb11Message(payload, this.deps);
2830
- }
2831
- };
2832
- const sendPrivateMsgSchema = z.object({
2833
- user_id: z.number(),
2834
- message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2835
- auto_escape: z.boolean().optional()
2836
- });
2837
- /** 发送私聊消息(P2-10 复用 sendOb11Message)。 */
2838
- var SendPrivateMsgAction = class extends BaseAction {
2839
- name = "send_private_msg";
2840
- schema = sendPrivateMsgSchema;
2841
- errorCodeMap = ob11ErrorCodeMap;
2842
- deps;
2843
- constructor(deps) {
2844
- super();
2845
- this.deps = deps;
2846
- }
2847
- _handle(payload) {
2848
- return sendOb11Message(payload, this.deps);
2849
- }
2850
- };
2851
- const sendGroupMsgSchema = z.object({
2852
- group_id: z.number(),
2853
- message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2854
- auto_escape: z.boolean().optional()
2855
- });
2856
- /** 发送群聊消息(P2-10 复用 sendOb11Message)。 */
2857
- var SendGroupMsgAction = class extends BaseAction {
2858
- name = "send_group_msg";
2859
- schema = sendGroupMsgSchema;
2860
- errorCodeMap = ob11ErrorCodeMap;
2861
- deps;
2862
- constructor(deps) {
2863
- super();
2864
- this.deps = deps;
2865
- }
2866
- _handle(payload) {
2867
- return sendOb11Message(payload, this.deps);
2868
- }
2869
- };
2870
2372
  /** CQ 特殊字符转义(auto_escape,&、[、]、, 前置 &)。 */
2871
2373
  function escapeText(text) {
2872
2374
  return text.replaceAll("&", "&").replaceAll("[", "[").replaceAll("]", "]").replaceAll(",", ",");
@@ -2883,203 +2385,158 @@ async function ensureVoiceSilk(elements, logger) {
2883
2385
  }
2884
2386
  /** 消息发送域动作工厂(send_msg / send_private_msg / send_group_msg)。 */
2885
2387
  function createSendActions(api) {
2388
+ const deps = api;
2886
2389
  return [
2887
- new SendMsgAction(api),
2888
- new SendPrivateMsgAction(api),
2889
- new SendGroupMsgAction(api)
2390
+ defineOb11Action({
2391
+ name: "send_msg",
2392
+ schema: sendMsgSchema,
2393
+ handle: (payload) => sendOb11Message(payload, deps)
2394
+ }),
2395
+ defineOb11Action({
2396
+ name: "send_private_msg",
2397
+ schema: sendPrivateMsgSchema,
2398
+ handle: (payload) => sendOb11Message(payload, deps)
2399
+ }),
2400
+ defineOb11Action({
2401
+ name: "send_group_msg",
2402
+ schema: sendGroupMsgSchema,
2403
+ handle: (payload) => sendOb11Message(payload, deps)
2404
+ })
2890
2405
  ];
2891
2406
  }
2892
2407
  // src/onebot11/action/system/account.ts
2893
2408
  /**
2894
- * 账号票据与资料域动作(2026-11-14 自 get-cookies / get-clientkey /
2895
- * get-credentials / profile-actions 合并)
2409
+ * 账号票据与资料域动作
2896
2410
  *
2897
- * - get_cookies(P2-13):kernel TicketApi.getCookies,domain 缺省 v2.qq.com
2411
+ * - get_cookies:kernel TicketApi.getCookies,domain 缺省 v2.qq.com
2898
2412
  * (NapCat 行为);user_id 缺省用机器人自身 uin
2899
- * - get_clientkey(P2-13):kernel TicketApi.getClientKey
2900
- * - get_csrf_token / get_credentials(P2-15):qun.qq.com cookies 的 skey → bkn
2413
+ * - get_clientkey:kernel TicketApi.getClientKey
2414
+ * - get_csrf_token / get_credentials:qun.qq.com cookies 的 skey → bkn
2901
2415
  * (csrf 等价物);get_credentials 返回指定域名 cookies + bkn
2902
- * - set_self_longnick / set_qq_profile / set_qq_avatar(P2-14):kernel ProfileApi;
2416
+ * - set_self_longnick / set_qq_profile / set_qq_avatar:kernel ProfileApi;
2903
2417
  * set_qq_profile 的 sex 忽略,头像 URL 需先经 cacheDir 下载
2904
2418
  */
2905
2419
  /** URL 前缀(头像在线文件识别)。 */
2906
2420
  const URL_PREFIX = /^https?:\/\//;
2421
+ /** 默认域名。 */
2422
+ const DEFAULT_DOMAIN = "v2.qq.com";
2423
+ /** 默认域名(bkn 计算用)。 */
2424
+ const BKN_DOMAIN = "qun.qq.com";
2907
2425
  const getCookiesSchema = z.object({
2908
2426
  domain: z.string().optional(),
2909
2427
  user_id: z.number().optional()
2910
2428
  });
2911
- /** 默认域名。 */
2912
- const DEFAULT_DOMAIN = "v2.qq.com";
2913
- /** 获取 cookies(P2-13 接 kernel TicketApi.getCookies)。 */
2914
- var GetCookiesAction = class extends BaseAction {
2915
- name = "get_cookies";
2916
- schema = getCookiesSchema;
2917
- errorCodeMap = ob11ErrorCodeMap;
2918
- deps;
2919
- constructor(deps) {
2920
- super();
2921
- this.deps = deps;
2922
- }
2923
- _handle(payload) {
2924
- const domain = payload.domain ?? DEFAULT_DOMAIN;
2925
- let uin = this.deps.selfUin;
2926
- if (payload.user_id !== void 0) uin = String(payload.user_id);
2927
- return this.deps.ticketApi.getCookies(domain, uin);
2928
- }
2929
- };
2930
2429
  const getClientkeySchema = z.object({});
2931
- /** 获取 clientKey(P2-13 接 kernel TicketApi)。 */
2932
- var GetClientkeyAction = class extends BaseAction {
2933
- name = "get_clientkey";
2934
- schema = getClientkeySchema;
2935
- errorCodeMap = ob11ErrorCodeMap;
2936
- ticketApi;
2937
- constructor(ticketApi) {
2938
- super();
2939
- this.ticketApi = ticketApi;
2940
- }
2941
- async _handle(_payload) {
2942
- const raw = await this.ticketApi.getClientKey();
2943
- return {
2944
- clientKey: raw.clientKey,
2945
- keyIndex: raw.keyIndex,
2946
- expireTime: raw.expireTime,
2947
- url: raw.url
2948
- };
2949
- }
2950
- };
2951
2430
  const getCsrfTokenSchema = z.object({});
2952
- /** 默认域名(bkn 计算用)。 */
2953
- const BKN_DOMAIN = "qun.qq.com";
2954
- /** 获取 csrf_token(bkn,P2-15)。 */
2955
- var GetCsrfTokenAction = class extends BaseAction {
2956
- name = "get_csrf_token";
2957
- schema = getCsrfTokenSchema;
2958
- errorCodeMap = ob11ErrorCodeMap;
2959
- deps;
2960
- constructor(deps) {
2961
- super();
2962
- this.deps = deps;
2963
- }
2964
- async _handle(_payload) {
2965
- const skey = (await this.deps.ticketApi.getCookies(BKN_DOMAIN, this.deps.selfUin))["skey"] ?? "";
2966
- return { token: Number(TicketApi.getBkn(skey)) };
2967
- }
2968
- };
2969
2431
  const getCredentialsSchema = z.object({ domain: z.string().optional() });
2970
- /** 获取凭据(cookies + csrf_token,P2-15)。 */
2971
- var GetCredentialsAction = class extends BaseAction {
2972
- name = "get_credentials";
2973
- schema = getCredentialsSchema;
2974
- errorCodeMap = ob11ErrorCodeMap;
2975
- deps;
2976
- constructor(deps) {
2977
- super();
2978
- this.deps = deps;
2979
- }
2980
- async _handle(payload) {
2981
- const domain = payload.domain ?? BKN_DOMAIN;
2982
- const cookies = await this.deps.ticketApi.getCookies(domain, this.deps.selfUin);
2983
- return {
2984
- cookies,
2985
- csrf_token: Number(TicketApi.getBkn(cookies["skey"] ?? ""))
2986
- };
2987
- }
2988
- };
2989
2432
  const setSelfLongnickSchema = z.object({ longNick: z.string() });
2990
- /** 设置个性签名(P2-14 接 kernel ProfileApi.setLongNick)。 */
2991
- var SetSelfLongnickAction = class extends BaseAction {
2992
- name = "set_self_longnick";
2993
- schema = setSelfLongnickSchema;
2994
- errorCodeMap = ob11ErrorCodeMap;
2995
- profileApi;
2996
- constructor(profileApi) {
2997
- super();
2998
- this.profileApi = profileApi;
2999
- }
3000
- async _handle(payload) {
3001
- await this.profileApi.setLongNick(payload.longNick);
3002
- return null;
3003
- }
3004
- };
3005
2433
  const setQQProfileSchema = z.object({
3006
2434
  nickname: z.string(),
3007
2435
  personal_note: z.string().optional(),
3008
2436
  sex: z.union([z.number(), z.string()]).optional()
3009
2437
  });
3010
- /** 设置 QQ 资料(P2-14;nickname → setNickName,personal_note → setLongNick,sex 忽略)。 */
3011
- var SetQQProfileAction = class extends BaseAction {
3012
- name = "set_qq_profile";
3013
- schema = setQQProfileSchema;
3014
- errorCodeMap = ob11ErrorCodeMap;
3015
- profileApi;
3016
- constructor(profileApi) {
3017
- super();
3018
- this.profileApi = profileApi;
3019
- }
3020
- async _handle(payload) {
3021
- await this.profileApi.setNickName(payload.nickname);
3022
- if (payload.personal_note !== void 0) await this.profileApi.setLongNick(payload.personal_note);
3023
- return null;
3024
- }
3025
- };
3026
2438
  const setQQAvatarSchema = z.object({
3027
2439
  /** 本地路径(URL 需先下载,由装配方 cacheDir 支持)。 */
3028
2440
  file: z.string() });
3029
- /** 设置 QQ 头像(P2-14 接 kernel ProfileApi.setHeader)。 */
3030
- var SetQQAvatarAction = class extends BaseAction {
3031
- name = "set_qq_avatar";
3032
- schema = setQQAvatarSchema;
3033
- errorCodeMap = ob11ErrorCodeMap;
3034
- deps;
3035
- constructor(deps) {
3036
- super();
3037
- this.deps = deps;
3038
- }
3039
- async _handle(payload) {
3040
- let filePath = payload.file;
3041
- if (URL_PREFIX.test(filePath)) filePath = await this.downloadToCache(filePath);
3042
- if (!existsSync(filePath)) throw kernelError(`头像文件不存在: ${filePath}`, "NOT_FOUND");
3043
- await this.deps.profileApi.setHeader(filePath);
3044
- return null;
3045
- }
3046
- /** URL 下载到缓存目录(cacheDir 缺省抛错)。 */
3047
- async downloadToCache(url) {
3048
- const { cacheDir } = this.deps;
3049
- if (cacheDir === void 0 || cacheDir === "") throw kernelError("set_qq_avatar 处理 URL 需要缓存目录(装配方未注入)", "INVALID_STATE");
3050
- const safeName = basename(new URL(url).pathname) || "avatar.bin";
3051
- const filePath = join(cacheDir, `avatar-${Date.now()}-${safeName}`);
3052
- const res = await fetch(url);
3053
- if (!res.ok) throw new Error(`头像下载失败: ${res.status} ${res.statusText}`);
3054
- const buf = new Uint8Array(await res.arrayBuffer());
3055
- writeFileSync(filePath, buf);
3056
- return filePath;
3057
- }
3058
- };
2441
+ /** URL 头像下载到缓存目录(cacheDir 缺省抛错)。 */
2442
+ async function downloadAvatarToCache(url, cacheDir) {
2443
+ if (cacheDir === void 0 || cacheDir === "") throw kernelError("set_qq_avatar 处理 URL 需要缓存目录(装配方未注入)", "INVALID_STATE");
2444
+ const safeName = basename(new URL(url).pathname) || "avatar.bin";
2445
+ const filePath = join(cacheDir, `avatar-${Date.now()}-${safeName}`);
2446
+ const res = await fetch(url);
2447
+ if (!res.ok) throw new Error(`头像下载失败: ${res.status} ${res.statusText}`);
2448
+ const buf = new Uint8Array(await res.arrayBuffer());
2449
+ writeFileSync(filePath, buf);
2450
+ return filePath;
2451
+ }
3059
2452
  /**
3060
2453
  * 账号票据与资料域动作工厂(cookies / clientkey / csrf_token / credentials /
3061
2454
  * self_longnick / qq_profile / qq_avatar)。
3062
2455
  */
3063
2456
  function createSystemAccountActions(api) {
3064
2457
  return [
3065
- new GetClientkeyAction(api.ticketApi),
3066
- new GetCookiesAction(api),
3067
- new GetCsrfTokenAction(api),
3068
- new GetCredentialsAction(api),
3069
- new SetSelfLongnickAction(api.profileApi),
3070
- new SetQQProfileAction(api.profileApi),
3071
- new SetQQAvatarAction(api)
2458
+ defineOb11Action({
2459
+ name: "get_clientkey",
2460
+ schema: getClientkeySchema,
2461
+ handle: async () => {
2462
+ const raw = await api.ticketApi.getClientKey();
2463
+ return {
2464
+ clientKey: raw.clientKey,
2465
+ keyIndex: raw.keyIndex,
2466
+ expireTime: raw.expireTime,
2467
+ url: raw.url
2468
+ };
2469
+ }
2470
+ }),
2471
+ defineOb11Action({
2472
+ name: "get_cookies",
2473
+ schema: getCookiesSchema,
2474
+ handle: (payload) => {
2475
+ const domain = payload.domain ?? DEFAULT_DOMAIN;
2476
+ let uin = api.selfUin;
2477
+ if (payload.user_id !== void 0) uin = String(payload.user_id);
2478
+ return api.ticketApi.getCookies(domain, uin);
2479
+ }
2480
+ }),
2481
+ defineOb11Action({
2482
+ name: "get_csrf_token",
2483
+ schema: getCsrfTokenSchema,
2484
+ handle: async () => {
2485
+ const skey = (await api.ticketApi.getCookies(BKN_DOMAIN, api.selfUin))["skey"] ?? "";
2486
+ return { token: Number(TicketApi.getBkn(skey)) };
2487
+ }
2488
+ }),
2489
+ defineOb11Action({
2490
+ name: "get_credentials",
2491
+ schema: getCredentialsSchema,
2492
+ handle: async (payload) => {
2493
+ const domain = payload.domain ?? BKN_DOMAIN;
2494
+ const cookies = await api.ticketApi.getCookies(domain, api.selfUin);
2495
+ return {
2496
+ cookies,
2497
+ csrf_token: Number(TicketApi.getBkn(cookies["skey"] ?? ""))
2498
+ };
2499
+ }
2500
+ }),
2501
+ defineOb11Action({
2502
+ name: "set_self_longnick",
2503
+ schema: setSelfLongnickSchema,
2504
+ handle: async (payload) => {
2505
+ await api.profileApi.setLongNick(payload.longNick);
2506
+ return null;
2507
+ }
2508
+ }),
2509
+ defineOb11Action({
2510
+ name: "set_qq_profile",
2511
+ schema: setQQProfileSchema,
2512
+ handle: async (payload) => {
2513
+ await api.profileApi.setNickName(payload.nickname);
2514
+ if (payload.personal_note !== void 0) await api.profileApi.setLongNick(payload.personal_note);
2515
+ return null;
2516
+ }
2517
+ }),
2518
+ defineOb11Action({
2519
+ name: "set_qq_avatar",
2520
+ schema: setQQAvatarSchema,
2521
+ handle: async (payload) => {
2522
+ let filePath = payload.file;
2523
+ if (URL_PREFIX.test(filePath)) filePath = await downloadAvatarToCache(filePath, api.cacheDir);
2524
+ if (!existsSync(filePath)) throw kernelError(`头像文件不存在: ${filePath}`, "NOT_FOUND");
2525
+ await api.profileApi.setHeader(filePath);
2526
+ return null;
2527
+ }
2528
+ })
3072
2529
  ];
3073
2530
  }
3074
2531
  // src/onebot11/action/system/file.ts
3075
2532
  /**
3076
- * 文件收发域动作(2026-11-14 自 system/download-file 与根部 upload-file 合并)
2533
+ * 文件收发域动作
3077
2534
  *
3078
- * - download_file(P2-12):url → fetch 下载 → 存 cacheDir(缺省抛错)→ 返回
2535
+ * - download_file:url → fetch 下载 → 存 cacheDir(缺省抛错)→ 返回
3079
2536
  * { file }。文件名:download-<timestamp>-<basename>(headers 等扩展字段忽略)
3080
2537
  * - upload_group_file / upload_private_file——**闪传通道**
3081
2538
  *
3082
- * ⚠️ 语义降级(2026-11-11 决定,探测依据见 kernel design §15):
2539
+ * ⚠️ 语义降级(探测依据见 kernel design §15):
3083
2540
  * QQ NT 没有任何「把文件传进群文件列表」的 NAPI,`sendMsg` 带 fileElement 时原生走的
3084
2541
  * 文件传输命令被服务端拒绝(`170019002`,逐维扫参无效),`fileUuid` 永远拿不到。唯一实测
3085
2542
  * 可用的投递通道是闪传:上传文件集 → 发分享卡片。因此本动作:
@@ -3092,40 +2549,15 @@ function createSystemAccountActions(api) {
3092
2549
  * 输入只接受本地路径与 `file://` URI:远程 `http(s)://` / `base64://` 需要下载缓存与媒体
3093
2550
  * 依赖,当前未接(明确报错,不静默失败)。
3094
2551
  */
2552
+ /** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
2553
+ const FILE_URI_PREFIX_RE = /^file:\/\//;
2554
+ /** 路径分隔符(取文件名用)。 */
2555
+ const PATH_SEPARATORS = /[\\/]/;
3095
2556
  const downloadFileSchema = z.object({
3096
2557
  url: z.string(),
3097
2558
  thread_count: z.number().optional(),
3098
2559
  headers: z.record(z.string(), z.string()).optional()
3099
2560
  });
3100
- /** 下载文件到缓存目录(P2-12)。 */
3101
- var DownloadFileAction = class extends BaseAction {
3102
- name = "download_file";
3103
- schema = downloadFileSchema;
3104
- errorCodeMap = ob11ErrorCodeMap;
3105
- deps;
3106
- constructor(deps) {
3107
- super();
3108
- this.deps = deps;
3109
- }
3110
- async _handle(payload) {
3111
- const { cacheDir } = this.deps;
3112
- if (cacheDir === void 0 || cacheDir === "") throw kernelError("download_file 未配置缓存目录(装配方未注入)", "INVALID_STATE");
3113
- const safeName = basename(new URL(payload.url).pathname) || "download.bin";
3114
- const filePath = join(cacheDir, `download-${Date.now()}-${safeName}`);
3115
- mkdirSync(cacheDir, { recursive: true });
3116
- const init = {};
3117
- if (payload.headers !== void 0) init.headers = payload.headers;
3118
- const res = await fetch(payload.url, init);
3119
- if (!res.ok) throw new Error(`下载失败: ${res.status} ${res.statusText}`);
3120
- const buf = new Uint8Array(await res.arrayBuffer());
3121
- writeFileSync(filePath, buf);
3122
- return { file: filePath };
3123
- }
3124
- };
3125
- /** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
3126
- const FILE_URI_PREFIX_RE = /^file:\/\//;
3127
- /** 路径分隔符(取文件名用)。 */
3128
- const PATH_SEPARATORS = /[\\/]/;
3129
2561
  const uploadGroupFileSchema = z.object({
3130
2562
  group_id: z.number(),
3131
2563
  file: z.string().min(1),
@@ -3138,41 +2570,6 @@ const uploadPrivateFileSchema = z.object({
3138
2570
  file: z.string().min(1),
3139
2571
  name: z.string().optional()
3140
2572
  });
3141
- /** upload_group_file:上传文件并投递到群(闪传卡片;语义降级见文件头)。 */
3142
- var UploadGroupFileAction = class extends BaseAction {
3143
- name = "upload_group_file";
3144
- schema = uploadGroupFileSchema;
3145
- errorCodeMap = ob11ErrorCodeMap;
3146
- deps;
3147
- constructor(deps) {
3148
- super();
3149
- this.deps = deps;
3150
- }
3151
- async _handle(payload) {
3152
- const path = resolveLocalFile(payload.file);
3153
- const peer = {
3154
- chatType: ChatType.GROUP,
3155
- peerUid: String(payload.group_id)
3156
- };
3157
- return { file_id: (await this.deps.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
3158
- }
3159
- };
3160
- /** upload_private_file:上传文件并投递到私聊(闪传卡片;语义降级见文件头)。 */
3161
- var UploadPrivateFileAction = class extends BaseAction {
3162
- name = "upload_private_file";
3163
- schema = uploadPrivateFileSchema;
3164
- errorCodeMap = ob11ErrorCodeMap;
3165
- deps;
3166
- constructor(deps) {
3167
- super();
3168
- this.deps = deps;
3169
- }
3170
- async _handle(payload) {
3171
- const path = resolveLocalFile(payload.file);
3172
- const peer = await resolveTargetPeer({ user_id: payload.user_id }, this.deps, "upload_private_file 需要 user_id");
3173
- return { file_id: (await this.deps.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
3174
- }
3175
- };
3176
2573
  /** 本地路径 / file:// 展开;远程 URI 明确拒绝(未接下载缓存)。 */
3177
2574
  function resolveLocalFile(file) {
3178
2575
  if (file.startsWith("http://") || file.startsWith("https://") || file.startsWith("base64://")) throw kernelError("upload_group_file/upload_private_file 目前只支持本地路径与 file:// URI(远程 URI 需要下载缓存,未接入)", "INVALID_PARAM");
@@ -3192,148 +2589,136 @@ function basename$1(path) {
3192
2589
  /** 文件收发域动作工厂(download_file / upload_group_file / upload_private_file)。 */
3193
2590
  function createSystemFileActions(api) {
3194
2591
  return [
3195
- new DownloadFileAction(api),
3196
- new UploadGroupFileAction(api),
3197
- new UploadPrivateFileAction(api)
2592
+ defineOb11Action({
2593
+ name: "download_file",
2594
+ schema: downloadFileSchema,
2595
+ handle: async (payload) => {
2596
+ const { cacheDir } = api;
2597
+ if (cacheDir === void 0 || cacheDir === "") throw kernelError("download_file 未配置缓存目录(装配方未注入)", "INVALID_STATE");
2598
+ const safeName = basename(new URL(payload.url).pathname) || "download.bin";
2599
+ const filePath = join(cacheDir, `download-${Date.now()}-${safeName}`);
2600
+ mkdirSync(cacheDir, { recursive: true });
2601
+ const init = {};
2602
+ if (payload.headers !== void 0) init.headers = payload.headers;
2603
+ const res = await fetch(payload.url, init);
2604
+ if (!res.ok) throw new Error(`下载失败: ${res.status} ${res.statusText}`);
2605
+ const buf = new Uint8Array(await res.arrayBuffer());
2606
+ writeFileSync(filePath, buf);
2607
+ return { file: filePath };
2608
+ }
2609
+ }),
2610
+ defineOb11Action({
2611
+ name: "upload_group_file",
2612
+ schema: uploadGroupFileSchema,
2613
+ handle: async (payload) => {
2614
+ const path = resolveLocalFile(payload.file);
2615
+ const peer = {
2616
+ chatType: ChatType.GROUP,
2617
+ peerUid: String(payload.group_id)
2618
+ };
2619
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
2620
+ }
2621
+ }),
2622
+ defineOb11Action({
2623
+ name: "upload_private_file",
2624
+ schema: uploadPrivateFileSchema,
2625
+ handle: async (payload) => {
2626
+ const path = resolveLocalFile(payload.file);
2627
+ const peer = await resolveTargetPeer({ user_id: payload.user_id }, api, "upload_private_file 需要 user_id");
2628
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
2629
+ }
2630
+ })
3198
2631
  ];
3199
2632
  }
3200
2633
  // src/onebot11/action/system/info.ts
3201
- const getLoginInfoSchema = z.object({});
3202
- /** 获取登录信息(self 由装配方注入,P2-5 接 kernel selfInfo 维护后取真实昵称)。 */
3203
- var GetLoginInfoAction = class extends BaseAction {
3204
- name = "get_login_info";
3205
- schema = getLoginInfoSchema;
3206
- errorCodeMap = ob11ErrorCodeMap;
3207
- self;
3208
- constructor(self) {
3209
- super();
3210
- this.self = self;
3211
- }
3212
- _handle(_payload) {
3213
- return Promise.resolve({
3214
- user_id: Number(this.self.uin),
3215
- nickname: this.self.nickname
3216
- });
3217
- }
3218
- };
3219
- const getVersionInfoSchema = z.object({});
3220
- /** 获取版本信息(本地组装,P2-11)。 */
3221
- var GetVersionInfoAction = class extends BaseAction {
3222
- name = "get_version_info";
3223
- schema = getVersionInfoSchema;
3224
- errorCodeMap = ob11ErrorCodeMap;
3225
- deps;
3226
- constructor(deps) {
3227
- super();
3228
- this.deps = deps;
3229
- }
3230
- _handle(_payload) {
3231
- return Promise.resolve({
3232
- app_name: "napuketto-qq",
3233
- app_version: this.deps.appVersion,
3234
- protocol_version: "v11"
3235
- });
3236
- }
3237
- };
3238
- const getStatusSchema = z.object({});
3239
- /** 获取运行状态(本地组装,P2-11)。 */
3240
- var GetStatusAction = class extends BaseAction {
3241
- name = "get_status";
3242
- schema = getStatusSchema;
3243
- errorCodeMap = ob11ErrorCodeMap;
3244
- _handle(_payload) {
3245
- return Promise.resolve({
3246
- online: true,
3247
- good: true
3248
- });
3249
- }
3250
- };
3251
- const getRobotUinRangeSchema = z.object({});
2634
+ /**
2635
+ * 系统信息域动作——只读信息查询,多为本地组装。
2636
+ *
2637
+ * - get_login_info:self 由装配方注入(接 kernel selfInfo 取真实昵称)
2638
+ * - get_version_info:appVersion 由装配方注入(kernel wrapper 版本或
2639
+ * NAPUTO_QQ_VERSION)
2640
+ * - get_status:返回与心跳 status 同构的 OB11Status(online/good)
2641
+ * - get_robot_uin_range:NapCat 从配置返回;这里给通用范围(min/max)
2642
+ * - translate_en2zh:kernel RichMediaApi.translateWords(词条数组限长)
2643
+ */
3252
2644
  /** QQ 号下限。 */
3253
2645
  const UIN_MIN = 10001;
3254
2646
  /** QQ 号上限。 */
3255
2647
  const UIN_MAX = 4294967295;
3256
- /** 获取机器人 QQ 号范围(P2-11 本地组装)。 */
3257
- var GetRobotUinRangeAction = class extends BaseAction {
3258
- name = "get_robot_uin_range";
3259
- schema = getRobotUinRangeSchema;
3260
- errorCodeMap = ob11ErrorCodeMap;
3261
- _handle(_payload) {
3262
- return Promise.resolve({
3263
- min: UIN_MIN,
3264
- max: UIN_MAX
3265
- });
3266
- }
3267
- };
2648
+ const getLoginInfoSchema = z.object({});
2649
+ const getVersionInfoSchema = z.object({});
2650
+ const getStatusSchema = z.object({});
2651
+ const getRobotUinRangeSchema = z.object({});
3268
2652
  const translateEn2ZhSchema = z.object({ words: z.array(z.string()).max(MAX_TRANSLATE_WORDS) });
3269
- /** 英文单词翻译(P2-14)。 */
3270
- var TranslateEn2ZhAction = class extends BaseAction {
3271
- name = "translate_en2zh";
3272
- schema = translateEn2ZhSchema;
3273
- errorCodeMap = ob11ErrorCodeMap;
3274
- richMediaApi;
3275
- constructor(richMediaApi) {
3276
- super();
3277
- this.richMediaApi = richMediaApi;
3278
- }
3279
- async _handle(payload) {
3280
- return { words: await this.richMediaApi.translateWords(payload.words) };
3281
- }
3282
- };
3283
2653
  /**
3284
2654
  * 系统信息域动作工厂(login_info / version_info / status / robot_uin_range /
3285
2655
  * translate_en2zh)。
3286
2656
  */
3287
2657
  function createSystemInfoActions(api) {
3288
2658
  return [
3289
- new GetLoginInfoAction(api.self),
3290
- new GetVersionInfoAction(api),
3291
- new GetStatusAction(),
3292
- new GetRobotUinRangeAction(),
3293
- new TranslateEn2ZhAction(api.richMediaApi)
2659
+ defineOb11Action({
2660
+ name: "get_login_info",
2661
+ schema: getLoginInfoSchema,
2662
+ handle: () => Promise.resolve({
2663
+ user_id: Number(api.self.uin),
2664
+ nickname: api.self.nickname
2665
+ })
2666
+ }),
2667
+ defineOb11Action({
2668
+ name: "get_version_info",
2669
+ schema: getVersionInfoSchema,
2670
+ handle: () => Promise.resolve({
2671
+ app_name: "napuketto-qq",
2672
+ app_version: api.appVersion,
2673
+ protocol_version: "v11"
2674
+ })
2675
+ }),
2676
+ defineOb11Action({
2677
+ name: "get_status",
2678
+ schema: getStatusSchema,
2679
+ handle: () => Promise.resolve({
2680
+ online: true,
2681
+ good: true
2682
+ })
2683
+ }),
2684
+ defineOb11Action({
2685
+ name: "get_robot_uin_range",
2686
+ schema: getRobotUinRangeSchema,
2687
+ handle: () => Promise.resolve({
2688
+ min: UIN_MIN,
2689
+ max: UIN_MAX
2690
+ })
2691
+ }),
2692
+ defineOb11Action({
2693
+ name: "translate_en2zh",
2694
+ schema: translateEn2ZhSchema,
2695
+ handle: async (payload) => {
2696
+ return { words: await api.richMediaApi.translateWords(payload.words) };
2697
+ }
2698
+ })
3294
2699
  ];
3295
2700
  }
3296
2701
  // src/onebot11/action/system/status.ts
3297
2702
  /**
3298
- * 系统状态与维护域动作(2026-11-14 自 set-online-status / set-diy-online-status /
3299
- * can-send-image / can-send-record / clean-cache / process-control 合并)
2703
+ * 系统状态与维护域动作
3300
2704
  *
3301
- * - set_online_status(P2-12):status/ext_status/battery_status 见 NapCat 状态表
2705
+ * - set_online_status:status/ext_status/battery_status 见 NapCat 状态表
3302
2706
  * (在线 10 / 离开 30 / 隐身 40 / 忙碌 50 / Q我吧 60 / 请勿打扰 70 等)
3303
- * - set_diy_online_status(P2-12):customStatus(faceId/wording/faceType)随
2707
+ * - set_diy_online_status:customStatus(faceId/wording/faceType)随
3304
2708
  * setStatus 一并提交;status 缺省 10(在线)
3305
- * - can_send_image / can_send_record(P2-11):本地恒 true
3306
- * - clean_cache(P2-11):cleanCache 回调由装配方注入(boot.cjs 接 kernel
2709
+ * - can_send_image / can_send_record:本地恒 true
2710
+ * - clean_cache:cleanCache 回调由装配方注入(boot.cjs 接 kernel
3307
2711
  * PathWrapper.clearCache),未配置时明确报错(不静默)
3308
- * - bot_exit / set_restart(P2-12):exit/restart 回调由装配方注入(boot.cjs 接
2712
+ * - bot_exit / set_restart:exit/restart 回调由装配方注入(boot.cjs 接
3309
2713
  * 进程控制),未配置时明确报错;重启缺省退化为退出
3310
2714
  */
2715
+ /** 默认在线状态值。 */
2716
+ const STATUS_ONLINE = 10;
3311
2717
  const setOnlineStatusSchema = z.object({
3312
2718
  status: z.number().optional(),
3313
2719
  ext_status: z.number().optional(),
3314
2720
  battery_status: z.number().optional()
3315
2721
  });
3316
- /** 默认在线状态值。 */
3317
- const STATUS_ONLINE = 10;
3318
- /** 设置在线状态(P2-12 接 kernel setOnlineStatus)。 */
3319
- var SetOnlineStatusAction = class extends BaseAction {
3320
- name = "set_online_status";
3321
- schema = setOnlineStatusSchema;
3322
- errorCodeMap = ob11ErrorCodeMap;
3323
- msgApi;
3324
- constructor(msgApi) {
3325
- super();
3326
- this.msgApi = msgApi;
3327
- }
3328
- async _handle(payload) {
3329
- await this.msgApi.setOnlineStatus({
3330
- status: payload.status ?? STATUS_ONLINE,
3331
- extStatus: payload.ext_status ?? 0,
3332
- batteryStatus: payload.battery_status ?? 0
3333
- });
3334
- return null;
3335
- }
3336
- };
3337
2722
  const setDiyOnlineStatusSchema = z.object({
3338
2723
  status: z.number().optional(),
3339
2724
  /** 自定义状态文案。 */
@@ -3343,126 +2728,95 @@ const setDiyOnlineStatusSchema = z.object({
3343
2728
  /** 表情类型。 */
3344
2729
  face_type: z.string().optional()
3345
2730
  });
3346
- /** 设置自定义在线状态(P2-12 接 kernel setOnlineStatus customStatus)。 */
3347
- var SetDiyOnlineStatusAction = class extends BaseAction {
3348
- name = "set_diy_online_status";
3349
- schema = setDiyOnlineStatusSchema;
3350
- errorCodeMap = ob11ErrorCodeMap;
3351
- msgApi;
3352
- constructor(msgApi) {
3353
- super();
3354
- this.msgApi = msgApi;
3355
- }
3356
- async _handle(payload) {
3357
- const customStatus = {
3358
- faceId: payload.face_id ?? "",
3359
- wording: payload.wording,
3360
- faceType: payload.face_type ?? "1"
3361
- };
3362
- await this.msgApi.setOnlineStatus({
3363
- status: payload.status ?? STATUS_ONLINE,
3364
- extStatus: 0,
3365
- batteryStatus: 0,
3366
- customStatus
3367
- });
3368
- return null;
3369
- }
3370
- };
3371
2731
  const canSendImageSchema = z.object({});
3372
- /** 是否可以发送图片(本地 true,P2-11)。 */
3373
- var CanSendImageAction = class extends BaseAction {
3374
- name = "can_send_image";
3375
- schema = canSendImageSchema;
3376
- errorCodeMap = ob11ErrorCodeMap;
3377
- _handle(_payload) {
3378
- return Promise.resolve({ yes: true });
3379
- }
3380
- };
3381
2732
  const canSendRecordSchema = z.object({});
3382
- /** 是否可以发送语音(本地 true,P2-11)。 */
3383
- var CanSendRecordAction = class extends BaseAction {
3384
- name = "can_send_record";
3385
- schema = canSendRecordSchema;
3386
- errorCodeMap = ob11ErrorCodeMap;
3387
- _handle(_payload) {
3388
- return Promise.resolve({ yes: true });
3389
- }
3390
- };
3391
2733
  const cleanCacheSchema = z.object({});
3392
- /** 清理缓存(P2-11)。 */
3393
- var CleanCacheAction = class extends BaseAction {
3394
- name = "clean_cache";
3395
- schema = cleanCacheSchema;
3396
- errorCodeMap = ob11ErrorCodeMap;
3397
- deps;
3398
- constructor(deps) {
3399
- super();
3400
- this.deps = deps;
3401
- }
3402
- async _handle(_payload) {
3403
- if (this.deps.cleanCache === void 0) throw kernelError("clean_cache 未配置(装配方未注入清理回调)", "INVALID_STATE");
3404
- await this.deps.cleanCache();
3405
- return null;
3406
- }
3407
- };
3408
2734
  const botExitSchema = z.object({});
3409
- /** 退出机器人进程(P2-12)。 */
3410
- var BotExitAction = class extends BaseAction {
3411
- name = "bot_exit";
3412
- schema = botExitSchema;
3413
- errorCodeMap = ob11ErrorCodeMap;
3414
- deps;
3415
- constructor(deps) {
3416
- super();
3417
- this.deps = deps;
3418
- }
3419
- async _handle(_payload) {
3420
- if (this.deps.exit === void 0) throw kernelError("bot_exit 未配置(装配方未注入退出回调)", "INVALID_STATE");
3421
- await this.deps.exit();
3422
- return null;
3423
- }
3424
- };
3425
- /** 重启机器人(P2-12;重启交给装配方,缺省退化为退出)。 */
3426
- var SetRestartAction = class extends BaseAction {
3427
- name = "set_restart";
3428
- schema = botExitSchema;
3429
- errorCodeMap = ob11ErrorCodeMap;
3430
- deps;
3431
- constructor(deps) {
3432
- super();
3433
- this.deps = deps;
3434
- }
3435
- async _handle(_payload) {
3436
- const restart = this.deps.restart ?? this.deps.exit;
3437
- if (restart === void 0) throw kernelError("set_restart 未配置(装配方未注入重启回调)", "INVALID_STATE");
3438
- await restart();
3439
- return null;
3440
- }
3441
- };
3442
2735
  /**
3443
2736
  * 系统状态与维护域动作工厂(set_online_status ×2 / can_send ×2 / clean_cache /
3444
2737
  * bot_exit / set_restart)。
3445
2738
  */
3446
2739
  function createSystemStatusActions(api) {
3447
2740
  return [
3448
- new SetOnlineStatusAction(api.msgApi),
3449
- new SetDiyOnlineStatusAction(api.msgApi),
3450
- new CanSendImageAction(),
3451
- new CanSendRecordAction(),
3452
- new CleanCacheAction(api),
3453
- new BotExitAction(api),
3454
- new SetRestartAction(api)
2741
+ defineOb11Action({
2742
+ name: "set_online_status",
2743
+ schema: setOnlineStatusSchema,
2744
+ handle: async (payload) => {
2745
+ await api.msgApi.setOnlineStatus({
2746
+ status: payload.status ?? STATUS_ONLINE,
2747
+ extStatus: payload.ext_status ?? 0,
2748
+ batteryStatus: payload.battery_status ?? 0
2749
+ });
2750
+ return null;
2751
+ }
2752
+ }),
2753
+ defineOb11Action({
2754
+ name: "set_diy_online_status",
2755
+ schema: setDiyOnlineStatusSchema,
2756
+ handle: async (payload) => {
2757
+ const customStatus = {
2758
+ faceId: payload.face_id ?? "",
2759
+ wording: payload.wording,
2760
+ faceType: payload.face_type ?? "1"
2761
+ };
2762
+ await api.msgApi.setOnlineStatus({
2763
+ status: payload.status ?? STATUS_ONLINE,
2764
+ extStatus: 0,
2765
+ batteryStatus: 0,
2766
+ customStatus
2767
+ });
2768
+ return null;
2769
+ }
2770
+ }),
2771
+ defineOb11Action({
2772
+ name: "can_send_image",
2773
+ schema: canSendImageSchema,
2774
+ handle: async () => ({ yes: true })
2775
+ }),
2776
+ defineOb11Action({
2777
+ name: "can_send_record",
2778
+ schema: canSendRecordSchema,
2779
+ handle: async () => ({ yes: true })
2780
+ }),
2781
+ defineOb11Action({
2782
+ name: "clean_cache",
2783
+ schema: cleanCacheSchema,
2784
+ handle: async () => {
2785
+ if (api.cleanCache === void 0) throw kernelError("clean_cache 未配置(装配方未注入清理回调)", "INVALID_STATE");
2786
+ await api.cleanCache();
2787
+ return null;
2788
+ }
2789
+ }),
2790
+ defineOb11Action({
2791
+ name: "bot_exit",
2792
+ schema: botExitSchema,
2793
+ handle: async () => {
2794
+ if (api.exit === void 0) throw kernelError("bot_exit 未配置(装配方未注入退出回调)", "INVALID_STATE");
2795
+ await api.exit();
2796
+ return null;
2797
+ }
2798
+ }),
2799
+ defineOb11Action({
2800
+ name: "set_restart",
2801
+ schema: botExitSchema,
2802
+ handle: async () => {
2803
+ const restart = api.restart ?? api.exit;
2804
+ if (restart === void 0) throw kernelError("set_restart 未配置(装配方未注入重启回调)", "INVALID_STATE");
2805
+ await restart();
2806
+ return null;
2807
+ }
2808
+ })
3455
2809
  ];
3456
2810
  }
3457
2811
  // src/onebot11/action/index.ts
3458
2812
  /**
3459
- * OneBot 11 动作注册表(ADR-013 延伸)
2813
+ * OneBot 11 动作注册表
3460
2814
  * 各协议维护自己的 ActionRegistry,由协议 adapter 挂到请求分发。
3461
- * P2-16:deps 收敛为 { api: OneBotApi } 单聚合对象(基础设施第一项)。
2815
+ * deps 收敛为 { api: OneBotApi } 单聚合对象。
3462
2816
  *
3463
- * 同时是 action 域 barrel:re-export error-map / resolve-uid / AtAllRemainInfo,
3464
- * 协议外部只从本入口消费动作面。动作类按领域分文件(message/ group/ friend/
3465
- * system/),各领域文件导出 create*Actions 工厂,此处遍历注册——新增动作在
2817
+ * 同时是 action 域 barrel:re-export ob11ErrorCodeMap / resolveUid(base-action)/
2818
+ * AtAllRemainInfo,协议外部只从本入口消费动作面。动作按领域分文件(message/ group/
2819
+ * friend/ system/),各领域文件导出 create*Actions 工厂,此处遍历注册——新增动作在
3466
2820
  * 领域文件的工厂里登记即可。
3467
2821
  */
3468
2822
  /** 全部领域工厂(18 个:message×5 + group×7 + friend×2 + system×4)。 */
@@ -3494,7 +2848,7 @@ function createOb11ActionRegistry(deps) {
3494
2848
  }
3495
2849
  // src/onebot11/api/one-bot-api.ts
3496
2850
  /**
3497
- * OneBot 11 动作统一依赖聚合(P2-16)。
2851
+ * OneBot 11 动作统一依赖聚合。
3498
2852
  * 各动作经 `Pick<OneBotApi, ...>` 取所需成员;注册处只构造一次本对象。
3499
2853
  */
3500
2854
  var OneBotApi = class {
@@ -3518,7 +2872,7 @@ var OneBotApi = class {
3518
2872
  profileLikeApi;
3519
2873
  /** kernel 群空间 web API(精华/荣誉用)。 */
3520
2874
  webApi;
3521
- /** 群/成员缓存(ADR-008;翻译层只读消费,缺失惰性回填)。 */
2875
+ /** 群/成员缓存(翻译层只读消费,缺失惰性回填)。 */
3522
2876
  groupCache;
3523
2877
  /** OB11 message_id ↔ NT msgId 双向映射(收链路与动作共用同一映射空间)。 */
3524
2878
  messageUnique;
@@ -3644,7 +2998,7 @@ var Ob11Enrichment = class {
3644
2998
  return this.api.uidToUin(uids);
3645
2999
  }
3646
3000
  /**
3647
- * 消息事件翻译上下文(P2-19:接收方向 ID 转换)。
3001
+ * 消息事件翻译上下文(接收方向 ID 转换)。
3648
3002
  * at uid → 一次批量 uidToUin;群消息另查发送者角色(GroupCache 缓存优先,
3649
3003
  * 失败回退缺省 member);msgId → OB11 id 经 messageUnique 反查。
3650
3004
  */
@@ -3780,8 +3134,19 @@ var Ob11InboundEssence = class {
3780
3134
  }
3781
3135
  };
3782
3136
  // src/onebot11/helper/notice-extra.ts
3783
- /** 毫秒 → 秒(Unix 时间戳)。 */
3784
- const MS_TO_SEC = 1e3;
3137
+ /**
3138
+ * OB11 notice 事件翻译·扩展源(c3)
3139
+ *
3140
+ * 数据源 = kernel 桥 新接线回调(notice.ts 的 grayTip 路径之外):
3141
+ * - Msg/onRecvOfflineFileMsg → OB11 offline_file notice(翻译)
3142
+ * - Msg/onRecvSysMsg / Msg/onRecvOnlineFileMsg / Group/onGroupEssenceListChange
3143
+ * → 暂不翻译(adapter 侧 raw 校准日志;sys msg 为群名片/头衔/精华等系统
3144
+ * 事件的总载体,真实 payload 到达后回填翻译)
3145
+ *
3146
+ * ⚠️ payload 形状未经真实事件校准(方法名证据 = wrapper.node 字符串,见 kernel
3147
+ * listeners 注释)——防御性收窄:未知形状返回 null,调用方打 raw 日志积累校准
3148
+ * 数据(与 narrowBuddyReqs 同模式)。翻译纯函数。
3149
+ */
3785
3150
  /** 候选 uin 字段(按优先级取第一个数字串;uid 串不硬转——待校准)。 */
3786
3151
  function pickUin(item) {
3787
3152
  for (const key of [
@@ -3811,7 +3176,7 @@ function narrowItem(item) {
3811
3176
  const obj = item;
3812
3177
  if (Array.isArray(obj["elements"])) {
3813
3178
  const file = obj["elements"].find((e) => typeof e === "object" && e !== null && "fileElement" in e)?.fileElement;
3814
- if (file === void 0) return null;
3179
+ if (file == null) return null;
3815
3180
  return {
3816
3181
  senderUin: pickUin(obj),
3817
3182
  name: typeof file["fileName"] === "string" ? file["fileName"] : "",
@@ -3860,7 +3225,7 @@ var Ob11InboundFileNotice = class {
3860
3225
  this.deps = deps;
3861
3226
  }
3862
3227
  /**
3863
- * 离线文件(c3,2026-09-10):Msg/onRecvOfflineFileMsg → OB11 offline_file
3228
+ * 离线文件(c3):Msg/onRecvOfflineFileMsg → OB11 offline_file
3864
3229
  * notice(payload 形状待校准:防御性收窄,未知形状 raw 日志积累)。
3865
3230
  */
3866
3231
  offlineFile(arg) {
@@ -3871,7 +3236,7 @@ var Ob11InboundFileNotice = class {
3871
3236
  }
3872
3237
  for (const item of items) this.deps.broadcast(toOfflineFileNotice(item, this.deps.selfUin));
3873
3238
  }
3874
- /** 在线文件:OB11 无对应通知类型;debug 级 raw 校准日志(2026-10-25)。 */
3239
+ /** 在线文件:OB11 无对应通知类型;debug 级 raw 校准日志。 */
3875
3240
  onlineFile(arg) {
3876
3241
  this.deps.logger?.debug({ raw: sliceRaw(JSON.stringify(arg)) }, "ob11: onRecvOnlineFileMsg raw(校准数据)");
3877
3242
  }
@@ -3879,7 +3244,7 @@ var Ob11InboundFileNotice = class {
3879
3244
  buddyList(evt, arg) {
3880
3245
  this.deps.logger?.info({ raw: truncRaw(JSON.stringify(arg)) }, `ob11: ${evt} raw(friend_add 校准数据)`);
3881
3246
  }
3882
- /** 好友缓存 diff 新增(B2,2026-09-08)→ friend_add notice(翻译纯函数)。 */
3247
+ /** 好友缓存 diff 新增()→ friend_add notice(翻译纯函数)。 */
3883
3248
  friendAdd(entry) {
3884
3249
  this.deps.broadcast(toFriendAdd(entry, this.deps.selfUin));
3885
3250
  }
@@ -3887,7 +3252,7 @@ var Ob11InboundFileNotice = class {
3887
3252
  // src/onebot11/helper/message-event.ts
3888
3253
  /** RawMessage → OB11 消息事件(message_id 经 MessageUnique 映射并记录 peer)。
3889
3254
  * messageFormat 决定 message 字段格式:array = 消息段数组(标准),string = CQ 码字符串。
3890
- * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
3255
+ * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id)。 */
3891
3256
  function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx = {}) {
3892
3257
  const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
3893
3258
  const segments = canonicalToSegments(elements);
@@ -3942,7 +3307,7 @@ var Ob11InboundMessage = class {
3942
3307
  deps;
3943
3308
  reportSelfMessage = false;
3944
3309
  messageFormat = "array";
3945
- /** 群文件报形式(B4):true = fileElement 群消息报 group_upload notice 替代 message。 */
3310
+ /** 群文件报形式():true = fileElement 群消息报 group_upload notice 替代 message。 */
3946
3311
  groupUploadAsNotice = false;
3947
3312
  constructor(deps) {
3948
3313
  this.deps = deps;
@@ -3969,10 +3334,10 @@ var Ob11InboundMessage = class {
3969
3334
  return;
3970
3335
  }
3971
3336
  }
3972
- this.broadcastMessageEvent(msg);
3337
+ this.broadcastMessageEvent(msg).catch((err) => logEventFailure(this.deps.logger, "ob11: message 事件翻译失败(单条丢弃)", err));
3973
3338
  }
3974
3339
  /**
3975
- * 广播消息事件(P2-19):回填 ctx 后交纯函数翻译;ID 转换在 enrichment 批量完成。
3340
+ * 广播消息事件:回填 ctx 后交纯函数翻译;ID 转换在 enrichment 批量完成。
3976
3341
  */
3977
3342
  async broadcastMessageEvent(msg) {
3978
3343
  const ctx = await this.deps.enrich.messageContext(msg);
@@ -4007,7 +3372,7 @@ var Ob11InboundRequest = class {
4007
3372
  }
4008
3373
  /** 好友申请 → friend request 事件(防御收窄;未知形状 raw warn 校准)。 */
4009
3374
  buddyReqs(arg) {
4010
- this.broadcastBuddyReqs(arg);
3375
+ this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "ob11: friend request 翻译失败(整批丢弃)", err));
4011
3376
  }
4012
3377
  /** 好友申请翻译派发(flag=reqTime;uid→uin 批量失败退空 Map)。 */
4013
3378
  async broadcastBuddyReqs(arg) {
@@ -4035,8 +3400,8 @@ function collectGroupNotifyUids(notifies) {
4035
3400
  }
4036
3401
  // src/onebot11/helper/sysmsg.ts
4037
3402
  /**
4038
- * OB11 sysmsg 识别表(2026-11-01 自 helper/sysmsg.ts 瘦身——解码层上移
4039
- * core/sysmsg.ts 共享,milky.md §0.8.3/§0.8.6)
3403
+ * OB11 sysmsg 识别表(自 helper/sysmsg.ts 瘦身——解码层上移
3404
+ * shared/sysmsg.ts 共享,milky.md §0.8.3/§0.8.6)
4040
3405
  *
4041
3406
  * 本模块只保留 OB11 侧内容:
4042
3407
  * - SysMsgNoticeKind:sysmsg 可映射的 OB11 notice 种类(event/notice.ts 既有类型)
@@ -4045,14 +3410,14 @@ function collectGroupNotifyUids(notifies) {
4045
3410
  * - recognizeSysMsg:绑定 OB11 表的识别入口
4046
3411
  *
4047
3412
  * 解码原语(decodeProtoTree / extractSysMsgEnvelope / narrowSysMsgBlobs 等)
4048
- * 从 `core/shared/sysmsg.js` 导入使用。
3413
+ * 从 `shared/sysmsg.js` 导入使用。
4049
3414
  */
4050
3415
  /** 群号判别(strings[0] 必须是数字串)。 */
4051
3416
  const NUMERIC_RE = /^\d+$/;
4052
3417
  /**
4053
3418
  * (msgType, subType) → 规则表(键 = 原生分发键,design.md §7.1)。
4054
3419
  *
4055
- * 2026-11-01 起不再是空表:732:21(群名片变更)为批次三轮录制取得的首个
3420
+ * 不再是空表:732:21(群名片变更)为轮录制取得的首个
4056
3421
  * 实证条目。card/title 等其余判别值仍无样本支撑,宁可漏报不错报;未识别
4057
3422
  * 一律走结构化校准日志,不广播。
4058
3423
  */
@@ -4089,10 +3454,10 @@ function recognizeOb11SysMsg(msgType, subType, table = KIND_TABLE) {
4089
3454
  }
4090
3455
  // src/onebot11/inbound/sysmsg.ts
4091
3456
  /**
4092
- * OB11 inbound sysmsg 域(2026-11-14 自 event-pipeline.ts 拆出)
3457
+ * OB11 inbound sysmsg 域(自 event-pipeline.ts 拆出)
4093
3458
  *
4094
3459
  * Msg/onRecvSysMsg 总闸:参数收窄(未知形状 raw warn)→ 单条字节块走
4095
- * core/shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 → 信封 → 识别 →
3460
+ * shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 → 信封 → 识别 →
4096
3461
  * 分流)。表命中做两件事:732:1 精华加速触发器(表外,踢入 essence 域的串行
4097
3462
  * diff 链)与识别表规则广播(uid→uin 经 enrichment 批量回填后 extract);
4098
3463
  * 未识别 / 提取失败落校准路径,不广播半成品。
@@ -4179,7 +3544,7 @@ var Ob11EventPipeline = class {
4179
3544
  const { msgChannel, groupChannel, friendChannel, buddyCacheEvents } = this.deps;
4180
3545
  this.unsubscribes.push(subscribeRawMessages(msgChannel, (msg) => this.message.handleRawMessage(msg)), msgChannel.on("Msg/onRecvOfflineFileMsg", (a) => this.fileNotice.offlineFile(a)), msgChannel.on("Msg/onRecvSysMsg", (a) => this.sysMsg.handleRawArg(a)), msgChannel.on("Msg/onRecvOnlineFileMsg", (a) => this.fileNotice.onlineFile(a)));
4181
3546
  if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
4182
- this.request.groupNotifies(doubt, notifies);
3547
+ this.request.groupNotifies(doubt, notifies).catch((err) => logEventFailure(this.deps.logger, "ob11: group request 翻译失败(整批丢弃)", err));
4183
3548
  }), groupChannel.on("Group/onGroupEssenceListChange", (a) => this.essence.change(a)));
4184
3549
  if (friendChannel !== void 0) {
4185
3550
  this.unsubscribes.push(friendChannel.on("Buddy/onBuddyReqChange", (a) => this.request.buddyReqs(a)));
@@ -4194,7 +3559,7 @@ var Ob11EventPipeline = class {
4194
3559
  };
4195
3560
  // src/onebot11/transport.ts
4196
3561
  /**
4197
- * OB11 传输装配(P2-5,2026-08-05)
3562
+ * OB11 传输装配
4198
3563
  *
4199
3564
  * 按 OB11Config 创建/装配 network 传输适配器:
4200
3565
  * - HTTP 反向(http.enabled):HttpServer 接收第三方调用 → handleRequest → 响应
@@ -4208,8 +3573,8 @@ var Ob11EventPipeline = class {
4208
3573
  /** Authorization 头前缀。 */
4209
3574
  const BEARER_PREFIX = "Bearer ";
4210
3575
  /** 校验 URL 查询参数里的 access_token(WS client 连接 URL 可能带)。
4211
- * ⚠️ req.url 是纯路径(无 origin),new URL(相对路径) 必抛——2026-09-08
4212
- * T10 E2E 实测抓到的 bug(查询参数鉴权从未生效,WS 全被 4401 关闭),
3576
+ * ⚠️ req.url 是纯路径(无 origin),new URL(相对路径) 必抛——
3577
+ * E2E 实测抓到的 bug(查询参数鉴权从未生效,WS 全被 4401 关闭),
4213
3578
  * 用 dummy base 解析。 */
4214
3579
  function hasAccessTokenQuery(url, token) {
4215
3580
  try {
@@ -4344,7 +3709,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4344
3709
  oneBotApi;
4345
3710
  /** 动作注册表(公共只读:IPC 桥等装配方枚举动作名直接挂载)。 */
4346
3711
  registry;
4347
- /** 收链路事件管道(订阅 / 过滤 / 翻译派发,2026-11-14 拆出)。 */
3712
+ /** 收链路事件管道(订阅 / 过滤 / 翻译派发,拆出)。 */
4348
3713
  pipeline;
4349
3714
  transports = null;
4350
3715
  heartbeatTimer = null;
@@ -4375,7 +3740,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4375
3740
  this.registry = createOb11ActionRegistry({ api: this.oneBotApi });
4376
3741
  }
4377
3742
  /**
4378
- * 配置热更新(P2-6,2026-09-08 实现):stop 旧传输/心跳/退订 → 按新配置重建。
3743
+ * 配置热更新(实现):stop 旧传输/心跳/退订 → 按新配置重建。
4379
3744
  * IPC 桥模式(subscribeOnly,无传输)只刷新上报开关字段,不重建。
4380
3745
  */
4381
3746
  async reloadTransports(config) {
@@ -4404,7 +3769,8 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4404
3769
  status: "failed",
4405
3770
  retcode: 999,
4406
3771
  data: null,
4407
- message
3772
+ message,
3773
+ ...echoFieldOf(req)
4408
3774
  });
4409
3775
  });
4410
3776
  }
@@ -4414,7 +3780,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4414
3780
  }
4415
3781
  this.pipeline.subscribe();
4416
3782
  this.broadcastEvent({
4417
- time: Math.floor(Date.now() / MS_TO_SEC$2),
3783
+ time: Math.floor(Date.now() / MS_TO_SEC),
4418
3784
  self_id: Number(this.selfUin),
4419
3785
  post_type: "meta_event",
4420
3786
  meta_event_type: "lifecycle",
@@ -4422,12 +3788,13 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4422
3788
  });
4423
3789
  this.startHeartbeat(config.heartbeatInterval);
4424
3790
  }
4425
- /** 心跳 meta 事件(interval 毫秒,0 关闭)。 */
3791
+ /** 心跳 meta 事件(interval 毫秒,0 关闭;启动前清理残留定时器防重复)。 */
4426
3792
  startHeartbeat(intervalMs) {
4427
3793
  if (intervalMs <= 0) return;
3794
+ if (this.heartbeatTimer !== null) clearInterval(this.heartbeatTimer);
4428
3795
  this.heartbeatTimer = setInterval(() => {
4429
3796
  this.broadcastEvent({
4430
- time: Math.floor(Date.now() / MS_TO_SEC$2),
3797
+ time: Math.floor(Date.now() / MS_TO_SEC),
4431
3798
  self_id: Number(this.selfUin),
4432
3799
  post_type: "meta_event",
4433
3800
  meta_event_type: "heartbeat",
@@ -4452,7 +3819,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4452
3819
  }
4453
3820
  }
4454
3821
  /**
4455
- * 仅启动接收链路(IPC 桥模式,2026-08-27):订阅消息通道维护 messageUnique +
3822
+ * 仅启动接收链路(IPC 桥模式):订阅消息通道维护 messageUnique +
4456
3823
  * 灰色通知翻译;与 start() 的差别仅在传输层(无 HTTP/WS、无心跳、无 lifecycle)。
4457
3824
  * 配置经 seed 装配(load() 返回内存初值)。
4458
3825
  */
@@ -4479,7 +3846,8 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4479
3846
  status: "failed",
4480
3847
  retcode: 404,
4481
3848
  data: null,
4482
- message: "请求缺少 action"
3849
+ message: "请求缺少 action",
3850
+ ...echo !== void 0 ? { echo } : {}
4483
3851
  });
4484
3852
  return;
4485
3853
  }
@@ -4489,7 +3857,8 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4489
3857
  status: "failed",
4490
3858
  retcode: 404,
4491
3859
  data: null,
4492
- message: `未知动作: ${action}`
3860
+ message: `未知动作: ${action}`,
3861
+ ...echo !== void 0 ? { echo } : {}
4493
3862
  });
4494
3863
  return;
4495
3864
  }
@@ -4499,6 +3868,14 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4499
3868
  respond(result);
4500
3869
  }
4501
3870
  };
3871
+ /** 请求体 echo 字段提取(透传用;非对象 / 缺省 / undefined 返回空对象)。 */
3872
+ function echoFieldOf(req) {
3873
+ if (req !== null && typeof req === "object") {
3874
+ const echo = req.echo;
3875
+ if (echo !== void 0) return { echo };
3876
+ }
3877
+ return {};
3878
+ }
4502
3879
  export { MessageUnique, NapukettoOneBot11Adapter, OneBotApi, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
4503
3880
 
4504
3881
  //# sourceMappingURL=index.mjs.map