@napuketto/adapter 0.15.3 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) 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-Byoso-c3.mjs +108 -0
  5. package/dist/core-Byoso-c3.mjs.map +1 -0
  6. package/dist/{core-CxDffqmA.mjs → essence-CYb60NC6.mjs} +164 -255
  7. package/dist/essence-CYb60NC6.mjs.map +1 -0
  8. package/dist/{gray-tip-C0pnbB__.mjs → gray-tip-C7lAbfOf.mjs} +10 -10
  9. package/dist/gray-tip-C7lAbfOf.mjs.map +1 -0
  10. package/dist/index-RMEWjNfV.d.mts +91 -0
  11. package/dist/index-RMEWjNfV.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 +18 -17
  15. package/dist/kurobot/index.mjs.map +1 -1
  16. package/dist/media-DMMn74TC.mjs +126 -0
  17. package/dist/media-DMMn74TC.mjs.map +1 -0
  18. package/dist/milky/index.d.mts +20 -23
  19. package/dist/milky/index.d.mts.map +1 -1
  20. package/dist/milky/index.mjs +1286 -1297
  21. package/dist/milky/index.mjs.map +1 -1
  22. package/dist/onebot11/index.d.mts +43 -22
  23. package/dist/onebot11/index.d.mts.map +1 -1
  24. package/dist/onebot11/index.mjs +1280 -1863
  25. package/dist/onebot11/index.mjs.map +1 -1
  26. package/dist/{raw-message-D2vA27kj.mjs → raw-message-DE3sdJg8.mjs} +18 -4
  27. package/dist/raw-message-DE3sdJg8.mjs.map +1 -0
  28. package/dist/satori/index.d.mts +24 -37
  29. package/dist/satori/index.d.mts.map +1 -1
  30. package/dist/satori/index.mjs +396 -564
  31. package/dist/satori/index.mjs.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/core-CxDffqmA.mjs.map +0 -1
  34. package/dist/gray-tip-C0pnbB__.mjs.map +0 -1
  35. package/dist/index-B0AaQNnq.d.mts +0 -261
  36. package/dist/index-B0AaQNnq.d.mts.map +0 -1
  37. package/dist/log-DiPRjA5P.mjs +0 -176
  38. package/dist/log-DiPRjA5P.mjs.map +0 -1
  39. package/dist/lookup-Dw0W04Ng.mjs +0 -22
  40. package/dist/lookup-Dw0W04Ng.mjs.map +0 -1
  41. package/dist/raw-message-D2vA27kj.mjs.map +0 -1
  42. package/dist/transport-schema-BEzr06W3.mjs +0 -29
  43. 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-CxDffqmA.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-DiPRjA5P.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-Byoso-c3.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 { a as MS_TO_SEC$2, c as toUin, i as hasGrayTip, o as numericUin, r as firstUntranslatedGrayTip, t as collectGrayTipUids } from "../gray-tip-C7lAbfOf.mjs";
5
+ import { d as logEventFailure, f as sliceRaw, i as narrowSysMsgBlobs, m as narrowBuddyReqs, n as extractEssenceSetSysMsg, o as processSysMsgBlob, p as truncRaw, r as narrowEssenceGroupArg, s as recognizeSysMsg, t as EssenceListSync } from "../essence-CYb60NC6.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;
@@ -1050,83 +782,75 @@ function toGroupAddRequestItem(notify) {
1050
782
  user_nick: userNick,
1051
783
  type,
1052
784
  checked: status !== 1,
1053
- postscript: postscript ?? ""
1054
- };
1055
- }
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
- */
785
+ postscript: postscript ?? ""
786
+ };
787
+ }
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。 */
@@ -1174,137 +898,88 @@ function toOb11GroupMemberInfo(groupCode, member, uidToUin) {
1174
898
  }
1175
899
  // src/onebot11/action/group/query.ts
1176
900
  /**
1177
- * 群查询域动作(2026-11-14 自 get-group-info / get-group-list / get-group-member-info /
1178
- * get-group-member-list / get-group-at-all-remain 合并)
901
+ * 群查询域动作
1179
902
  *
1180
- * P2-4 接 kernel GroupApi;P2-17 群信息/成员动作优先读 GroupCache,no_cache=true
903
+ * 接 kernel GroupApi;群信息/成员动作优先读 GroupCache,no_cache=true
1181
904
  * 直查 api。get_group_list 有实测校准:原生 getGroupList 返回值无数据(仅
1182
905
  * { result, errMsg }),列表经 onGroupListUpdate 事件推送 → GroupCache 维护。
1183
906
  */
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
- };
1298
- }
1299
- };
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";
@@ -1809,7 +1484,7 @@ const GROUP_FILE_BUS_ID = 102;
1809
1484
  /**
1810
1485
  * 检查消息是否含文件元素(group_upload 开关分支判定)。
1811
1486
  *
1812
- * ⚠️ 用空值判定(`!= null`)而非 `!== undefined`(2026-11-10,Linux 原生宿主):
1487
+ * ⚠️ 用空值判定(`!= null`)而非 `!== undefined`(Linux 原生宿主):
1813
1488
  * Windows 原生对象省略未命中的元素变体字段,Linux 3.2.x 原生对象则把**全部**
1814
1489
  * 变体字段显式置 `null`(`"grayTipElement":null` 等)。用 `!== undefined`
1815
1490
  * 会把每条普通消息都判成「含该元素」——OB11 入站消息因此全部被误路由到
@@ -1827,7 +1502,7 @@ function base(msg, ctx) {
1827
1502
  group_id: Number(msg.peerUid)
1828
1503
  };
1829
1504
  }
1830
- /** 撤回事件(chatType 分流:GROUP→group_recall / C2C→friend_recall,2026-09-08)。 */
1505
+ /** 撤回事件(chatType 分流:GROUP→group_recall / C2C→friend_recall)。 */
1831
1506
  function toRecall(msg, g, ctx) {
1832
1507
  if (g?.revokeElement === void 0) return null;
1833
1508
  const revoke = g.revokeElement;
@@ -1848,7 +1523,7 @@ function toRecall(msg, g, ctx) {
1848
1523
  };
1849
1524
  }
1850
1525
  /**
1851
- * 戳一戳(notify.poke,aioOpGrayTipElement,2026-09-08)。
1526
+ * 戳一戳(notify.poke,aioOpGrayTipElement)。
1852
1527
  *
1853
1528
  * ⚠️ 待真实 poke 事件验证:aioOp 载荷的完整字段形状未经实测(实体类型仅有
1854
1529
  * operateType/peerUid 两个已证字段)。当前口径:user_id = 消息发送者,
@@ -1950,7 +1625,7 @@ function toBan(common, grp, ctx) {
1950
1625
  };
1951
1626
  }
1952
1627
  /**
1953
- * 好友添加(friend_add,B2,2026-09-08)。
1628
+ * 好友添加(friend_add,)。
1954
1629
  * 数据源 = kernel BuddyCache 快照 diff(Buddy/onBuddyListChange 全量快照对比,
1955
1630
  * 首帧 baseline 不发)——非 grayTip 路径。user_id 取 coreInfo.uin(顶层 uin 兜底)。
1956
1631
  */
@@ -1965,7 +1640,7 @@ function toFriendAdd(entry, selfUin) {
1965
1640
  };
1966
1641
  }
1967
1642
  /**
1968
- * 群文件上传(group_upload,B4,2026-09-08)。
1643
+ * 群文件上传(group_upload,)。
1969
1644
  * 数据源 = 含 fileElement 的群消息(开关 groupUploadAsNotice=true 时替代
1970
1645
  * message 事件报出)。file.id 取 fileUuid(缺省文件名)、size 取 fileSize、
1971
1646
  * busid 固定 102(群文件业务类型,与 kernel GROUP_FILE_BIZ_TYPE 同源语义)。
@@ -2005,7 +1680,7 @@ function logUntranslatedGrayTip(msg, ctx) {
2005
1680
  }, "ob11: 未翻译的 grayTip 子类型(raw 校准数据)");
2006
1681
  }
2007
1682
  /** RawMessage → OB11 notice 事件(无 grayTip 返回 null)。
2008
- * 未知/未翻译子类型打 raw JSON 日志(校准数据积累,2026-09-08)。 */
1683
+ * 未知/未翻译子类型打 raw JSON 日志(校准数据积累)。 */
2009
1684
  function toOb11NoticeEvent(msg, ctx) {
2010
1685
  for (const el of msg.elements) {
2011
1686
  const g = el.grayTipElement;
@@ -2017,7 +1692,7 @@ function toOb11NoticeEvent(msg, ctx) {
2017
1692
  }
2018
1693
  // src/onebot11/helper/request.ts
2019
1694
  /**
2020
- * OB11 request 事件翻译(2026-09-08)
1695
+ * OB11 request 事件翻译
2021
1696
  *
2022
1697
  * 事件源(kernel 事件通道,本次接线):
2023
1698
  * - `Group/onGroupNotifiesUpdated`(GroupBridge,群系统通知推送)→ group_add / group_invite
@@ -2027,7 +1702,7 @@ function toOb11NoticeEvent(msg, ctx) {
2027
1702
  * - 群请求 flag = GroupNotify.seq(set_group_add_request 按 `item.seq === flag` 匹配)
2028
1703
  * - 好友请求 flag = BuddyReq.reqTime(set_friend_add_request 按 `reqTime === flag` 匹配)
2029
1704
  *
2030
- * 纯函数(ADR-008):uid→uin 由调用方批量转换后传入。
1705
+ * 纯函数:uid→uin 由调用方批量转换后传入。
2031
1706
  * ⚠️ onBuddyReqChange 回调参数形状未经真实事件校准(wrapper 字符串证据仅有方法名),
2032
1707
  * narrowBuddyReqs 防御性收窄,未知形状返回 null 由调用方打 raw 日志积累校准数据。
2033
1708
  */
@@ -2081,7 +1756,7 @@ function toOb11FriendRequestEvent(req, ctx) {
2081
1756
  }
2082
1757
  // src/onebot11/action/message/resolve-peer.ts
2083
1758
  /**
2084
- * OB11 目标 Peer 解析 / 单条消息拉取(多个动作共用,2026-08-08 克隆合并)
1759
+ * OB11 目标 Peer 解析 / 单条消息拉取(多个动作共用)
2085
1760
  *
2086
1761
  * group_id 直通(群消息 peerUid = 群号);user_id 经 uin→uid 解析。
2087
1762
  */
@@ -2117,16 +1792,15 @@ async function fetchMsgById(messageId, messageUnique, msgApi) {
2117
1792
  }
2118
1793
  // src/onebot11/action/message/forward.ts
2119
1794
  /**
2120
- * 消息转发域动作(2026-11-14 自 send-forward-msg / forward-single-msg /
2121
- * get-forward-msg 合并)
1795
+ * 消息转发域动作
2122
1796
  *
2123
- * - send_group_forward_msg / send_private_forward_msg(P2-12):messages 每项为
1797
+ * - send_group_forward_msg / send_private_forward_msg:messages 每项为
2124
1798
  * node 元素 `{ type: "node", data: { id } }`——id 是此前 send_msg 返回的 OB11
2125
1799
  * message_id。经 MessageUnique 反查源 msgId + peer,组装到目标 peer(群直通 /
2126
1800
  * 私聊 uinToUid)→ MsgApi.sendForwardMessage
2127
- * - forward_group_single_msg / forward_friend_single_msg(P2-12):message_id 反查
1801
+ * - forward_group_single_msg / forward_friend_single_msg:message_id 反查
2128
1802
  * 源 msgId + peer;group_id/user_id 为目标 → MsgApi.forwardSingleMessage
2129
- * - get_forward_msg(P2-12):message_id / id → fetchForwardMessage(getMultiMsg)
1803
+ * - get_forward_msg:message_id / id → fetchForwardMessage(getMultiMsg)
2130
1804
  * → 每条 toOb11MessageInfo → { messages }
2131
1805
  */
2132
1806
  const forwardNodeSchema = z.object({
@@ -2141,6 +1815,15 @@ const sendPrivateForwardMsgSchema = z.object({
2141
1815
  user_id: z.number(),
2142
1816
  messages: z.array(z.unknown()).max(500).default([])
2143
1817
  });
1818
+ const forwardSingleMsgSchema = z.object({
1819
+ message_id: z.union([z.number(), z.string()]),
1820
+ group_id: z.number().optional(),
1821
+ user_id: z.number().optional()
1822
+ });
1823
+ const getForwardMsgSchema = z.object({
1824
+ message_id: z.union([z.number(), z.string()]).optional(),
1825
+ id: z.union([z.number(), z.string()]).optional()
1826
+ });
2144
1827
  /** 解析 node 元素列表 → 源消息 (msgId, peer) 列表(id 反查,跳过无法解析的项)。 */
2145
1828
  function resolveSourceMessages(messages, unique) {
2146
1829
  const out = [];
@@ -2170,140 +1853,70 @@ async function sendForward(messages, target, deps) {
2170
1853
  const { msgId } = await deps.msgApi.sendForwardMessage(target, firstSource.peer, sources.map((s) => s.msgId));
2171
1854
  return { message_id: deps.messageUnique.alloc(msgId, target) };
2172
1855
  }
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)。 */
1856
+ /** 单条转发共用实现:message_id 反查源消息 + 目标 Peer 解析 → forwardSingleMessage。 */
1857
+ async function forwardSingleMsg(payload, deps) {
1858
+ const { msgId, peer: sourcePeer } = resolveMsgIdAndPeer(payload.message_id, deps.messageUnique);
1859
+ const dstPeer = await resolveTargetPeer(payload, deps, "单条转发需要 group_id 或 user_id");
1860
+ await deps.msgApi.forwardSingleMessage(sourcePeer, [msgId], dstPeer);
1861
+ return null;
1862
+ }
1863
+ /** 消息转发域动作工厂(合并转发 ×2 / get_forward_msg / 单条转发 ×2)。 */
2262
1864
  function createForwardActions(api) {
2263
1865
  return [
2264
- new SendGroupForwardMsgAction(api),
2265
- new SendPrivateForwardMsgAction(api),
2266
- new GetForwardMsgAction(api),
2267
- new ForwardGroupSingleMsgAction(api),
2268
- new ForwardFriendSingleMsgAction(api)
1866
+ defineOb11Action({
1867
+ name: "send_group_forward_msg",
1868
+ schema: sendGroupForwardMsgSchema,
1869
+ handle: async (payload) => {
1870
+ const target = {
1871
+ chatType: ChatType.GROUP,
1872
+ peerUid: String(payload.group_id)
1873
+ };
1874
+ return await sendForward(payload.messages, target, api);
1875
+ }
1876
+ }),
1877
+ defineOb11Action({
1878
+ name: "send_private_forward_msg",
1879
+ schema: sendPrivateForwardMsgSchema,
1880
+ handle: async (payload) => {
1881
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
1882
+ const target = {
1883
+ chatType: ChatType.C2C,
1884
+ peerUid: uid
1885
+ };
1886
+ return await sendForward(payload.messages, target, api);
1887
+ }
1888
+ }),
1889
+ defineOb11Action({
1890
+ name: "get_forward_msg",
1891
+ schema: getForwardMsgSchema,
1892
+ handle: async (payload) => {
1893
+ const id = payload.message_id ?? payload.id;
1894
+ if (id === void 0) throw kernelError("get_forward_msg 需要 message_id 或 id", "INVALID_PARAM");
1895
+ const { msgId, peer } = resolveMsgIdAndPeer(id, api.messageUnique);
1896
+ return { messages: (await api.msgApi.fetchForwardMessage(peer, msgId)).map((msg) => toOb11MessageInfo(msg, api.messageUnique)) };
1897
+ }
1898
+ }),
1899
+ defineOb11Action({
1900
+ name: "forward_group_single_msg",
1901
+ schema: forwardSingleMsgSchema,
1902
+ handle: (payload) => forwardSingleMsg(payload, api)
1903
+ }),
1904
+ defineOb11Action({
1905
+ name: "forward_friend_single_msg",
1906
+ schema: forwardSingleMsgSchema,
1907
+ handle: (payload) => forwardSingleMsg(payload, api)
1908
+ })
2269
1909
  ];
2270
1910
  }
2271
1911
  // src/onebot11/action/message/history.ts
2272
1912
  /**
2273
- * 消息读取域动作(2026-11-14 自 get-msg / msg-history / get-group-msg-history /
2274
- * get-friend-msg-history 合并)
1913
+ * 消息读取域动作
2275
1914
  *
2276
1915
  * - get_msg:message_id → msgId + peer(MessageUnique 反查)→ 拉消息 → OB11 消息信息
2277
1916
  * - get_group_msg_history(go-cqhttp 扩展)/ get_friend_msg_history(NapCat 扩展):
2278
1917
  * 拉取历史消息 → at uid 批量转换 → OB11 消息信息数组(共享 fetchAndTranslateHistory)
2279
1918
  */
2280
1919
  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 {}
2298
- const senderRole = msg.chatType === ChatType.GROUP ? await this.deps.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
2299
- const ctx = {
2300
- ...uidToUin !== void 0 ? { uidToUin } : {},
2301
- ...senderRole !== void 0 ? { senderRole } : {},
2302
- msgIdToOb11Id: (m) => this.deps.messageUnique.getMessageId(m)
2303
- };
2304
- return toOb11MessageInfo(msg, this.deps.messageUnique, ctx);
2305
- }
2306
- };
2307
1920
  /** 历史消息公共参数(message_seq / count / 反向排序)。 */
2308
1921
  const msgHistoryParamsSchema = {
2309
1922
  /** 起始消息序号(message_seq,缺省从最新拉)。 */
@@ -2323,7 +1936,7 @@ function resolveStartMsgId(messageSeq, messageUnique) {
2323
1936
  }
2324
1937
  /**
2325
1938
  * 拉取历史消息并翻译为 OB11 消息信息数组。
2326
- * 收集全部消息 at uid → 一次批量 uidToUin → 上下文注入(P2-19)。
1939
+ * 收集全部消息 at uid → 一次批量 uidToUin → 上下文注入。
2327
1940
  * 群聊另取发送者角色表(GroupCache 一次整表读取,失败回退缺省 member)。
2328
1941
  */
2329
1942
  async function fetchAndTranslateHistory(peer, messageSeq, count, deps) {
@@ -2340,7 +1953,12 @@ async function fetchAndTranslateHistory(peer, messageSeq, count, deps) {
2340
1953
  let uidToUin;
2341
1954
  if (atUids.size > 0) try {
2342
1955
  uidToUin = await deps.uidToUin([...atUids]);
2343
- } catch {}
1956
+ } catch (err) {
1957
+ deps.logger?.warn({
1958
+ count: atUids.size,
1959
+ error: err instanceof Error ? err.message : String(err)
1960
+ }, "ob11: 历史消息 at uid→uin 失败,at 原样");
1961
+ }
2344
1962
  const ctx = {
2345
1963
  ...uidToUin !== void 0 ? { uidToUin } : {},
2346
1964
  msgIdToOb11Id: (m) => deps.messageUnique.getMessageId(m)
@@ -2359,65 +1977,71 @@ const getGroupMsgHistorySchema = z.object({
2359
1977
  group_id: z.number(),
2360
1978
  ...msgHistoryParamsSchema
2361
1979
  });
2362
- /** 获取群历史消息(P2-10 接 kernel fetchMessages)。 */
2363
- var GetGroupMsgHistoryAction = class extends BaseAction {
2364
- name = "get_group_msg_history";
2365
- schema = getGroupMsgHistorySchema;
2366
- errorCodeMap = ob11ErrorCodeMap;
2367
- deps;
2368
- constructor(deps) {
2369
- super();
2370
- this.deps = deps;
2371
- }
2372
- async _handle(payload) {
2373
- return await fetchAndTranslateHistory({
2374
- chatType: ChatType.GROUP,
2375
- peerUid: String(payload.group_id)
2376
- }, payload.message_seq, payload.count, this.deps);
2377
- }
2378
- };
2379
1980
  const getFriendMsgHistorySchema = z.object({
2380
1981
  user_id: z.number(),
2381
1982
  ...msgHistoryParamsSchema
2382
1983
  });
2383
- /** 获取私聊历史消息(P2-10 接 kernel fetchMessages)。 */
2384
- var GetFriendMsgHistoryAction = class extends BaseAction {
2385
- name = "get_friend_msg_history";
2386
- schema = getFriendMsgHistorySchema;
2387
- errorCodeMap = ob11ErrorCodeMap;
2388
- deps;
2389
- constructor(deps) {
2390
- super();
2391
- this.deps = deps;
2392
- }
2393
- async _handle(payload) {
2394
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2395
- return await fetchAndTranslateHistory({
2396
- chatType: ChatType.C2C,
2397
- peerUid: uid
2398
- }, payload.message_seq, payload.count, this.deps);
2399
- }
2400
- };
2401
1984
  /** 消息读取域动作工厂(get_msg / get_group_msg_history / get_friend_msg_history)。 */
2402
1985
  function createHistoryActions(api) {
2403
1986
  return [
2404
- new GetMsgAction(api),
2405
- new GetGroupMsgHistoryAction(api),
2406
- new GetFriendMsgHistoryAction(api)
1987
+ defineOb11Action({
1988
+ name: "get_msg",
1989
+ schema: getMsgSchema,
1990
+ handle: async (payload) => {
1991
+ const { msg } = await fetchMsgById(payload.message_id, api.messageUnique, api.msgApi);
1992
+ const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
1993
+ let uidToUin;
1994
+ if (atUids.length > 0) try {
1995
+ uidToUin = await api.uidToUin(atUids);
1996
+ } catch (err) {
1997
+ api.logger?.warn({
1998
+ count: atUids.length,
1999
+ error: err instanceof Error ? err.message : String(err)
2000
+ }, "ob11: get_msg at uid→uin 失败,at 原样");
2001
+ }
2002
+ const senderRole = msg.chatType === ChatType.GROUP ? await api.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
2003
+ const ctx = {
2004
+ ...uidToUin !== void 0 ? { uidToUin } : {},
2005
+ ...senderRole !== void 0 ? { senderRole } : {},
2006
+ msgIdToOb11Id: (m) => api.messageUnique.getMessageId(m)
2007
+ };
2008
+ return toOb11MessageInfo(msg, api.messageUnique, ctx);
2009
+ }
2010
+ }),
2011
+ defineOb11Action({
2012
+ name: "get_group_msg_history",
2013
+ schema: getGroupMsgHistorySchema,
2014
+ handle: async (payload) => {
2015
+ return await fetchAndTranslateHistory({
2016
+ chatType: ChatType.GROUP,
2017
+ peerUid: String(payload.group_id)
2018
+ }, payload.message_seq, payload.count, api);
2019
+ }
2020
+ }),
2021
+ defineOb11Action({
2022
+ name: "get_friend_msg_history",
2023
+ schema: getFriendMsgHistorySchema,
2024
+ handle: async (payload) => {
2025
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2026
+ return await fetchAndTranslateHistory({
2027
+ chatType: ChatType.C2C,
2028
+ peerUid: uid
2029
+ }, payload.message_seq, payload.count, api);
2030
+ }
2031
+ })
2407
2032
  ];
2408
2033
  }
2409
2034
  // src/onebot11/action/message/media.ts
2410
2035
  /**
2411
- * 消息媒体域动作(2026-11-14 自 get-media / fetch-ptt-text 合并)
2036
+ * 消息媒体域动作
2412
2037
  *
2413
- * - get_image / get_record:获取图片/语音文件(P2-14;2026-09-08 T5 接主动下载;
2414
- * 2026-09-08 B1 语音接原生 downloadRichMedia)。message_id 反查 → fetchMsgsByMsgId
2415
- * → 找 PIC/PTT 元素:
2038
+ * - get_image / get_record:获取图片/语音文件(图片接主动下载;语音接原生
2039
+ * downloadRichMedia)。message_id 反查 → fetchMsgsByMsgId → 找 PIC/PTT 元素:
2416
2040
  * - 本地文件解析:NT 相对路径(sourcePath/filePath)按 mediaBaseDir(QQ NT
2417
2041
  * global 目录)解析为绝对路径,命中磁盘即返回 file
2418
2042
  * - 图片主动下载:本地未命中且有 picUrl → @napuketto/media downloadUrl 落
2419
2043
  * cacheDir/media/,返回 file(绝对路径)+ url + file_size/file_name
2420
- * - 语音主动下载(B1):本地未命中 → kernel MsgApi.downloadPtt(原生
2044
+ * - 语音主动下载:本地未命中 → kernel MsgApi.downloadPtt(原生
2421
2045
  * downloadRichMedia + 轮询元素回查)→ filePath 落盘后返回绝对路径;
2422
2046
  * 失败回退原始 filePath(NT 相对/绝对)+ 元数据,不抛错
2423
2047
  * - fetch_ptt_text:message_id → MsgApi.fetchPttText(内部:拉消息 → 找 PTT 元素
@@ -2428,6 +2052,7 @@ const getMediaSchema = z.object({
2428
2052
  file: z.string().optional(),
2429
2053
  message_id: z.union([z.number(), z.string()]).optional()
2430
2054
  });
2055
+ const fetchPttTextSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2431
2056
  /**
2432
2057
  * NT 相对路径 → 本地绝对路径(存在才返回)。
2433
2058
  * 候选:原样绝对路径 / mediaBaseDir 下相对路径(反斜杠归一化)。
@@ -2453,7 +2078,11 @@ async function downloadImageToCache(url, deps) {
2453
2078
  try {
2454
2079
  await downloadUrl(url, dest);
2455
2080
  return dest;
2456
- } catch {
2081
+ } catch (err) {
2082
+ deps.logger?.warn({
2083
+ url,
2084
+ error: err instanceof Error ? err.message : String(err)
2085
+ }, "ob11: 图片主动下载失败,get_image 退原始 url");
2457
2086
  return null;
2458
2087
  }
2459
2088
  }
@@ -2477,110 +2106,95 @@ function takeId(payload, actionName) {
2477
2106
  if (id === void 0) throw kernelError(`${actionName} 需要 message_id 或 file`, "INVALID_PARAM");
2478
2107
  return id;
2479
2108
  }
2480
- /** 获取图片信息(本地优先,picUrl 主动下载兜底)。 */
2481
- var GetImageAction = class extends BaseAction {
2482
- name = "get_image";
2483
- schema = getMediaSchema;
2484
- errorCodeMap = ob11ErrorCodeMap;
2485
- deps;
2486
- constructor(deps) {
2487
- super();
2488
- this.deps = deps;
2109
+ /** 提取 pic 元素 → 媒体信息(url / 本地 file / 元数据;非 pic 元素返回 undefined)。 */
2110
+ function extractPicElement(el, deps) {
2111
+ const pic = el.picElement;
2112
+ if (pic === void 0) return;
2113
+ const out = {};
2114
+ if (pic.fileSize !== void 0) out.file_size = pic.fileSize;
2115
+ if (pic.fileName !== void 0) out.file_name = pic.fileName;
2116
+ if (pic.picUrl !== void 0) out.url = pic.picUrl;
2117
+ const rel = pic.sourcePath ?? pic.picPath;
2118
+ if (rel !== void 0) {
2119
+ const local = resolveLocalMediaFile(rel, deps);
2120
+ if (local !== null) out.file = local;
2489
2121
  }
2490
- async _handle(payload) {
2491
- const base = await resolveMedia(takeId(payload, "get_image"), "图片", this.deps, (el) => {
2492
- const pic = el.picElement;
2493
- if (pic === void 0) return;
2494
- const out = {};
2495
- if (pic.fileSize !== void 0) out.file_size = pic.fileSize;
2496
- if (pic.fileName !== void 0) out.file_name = pic.fileName;
2497
- if (pic.picUrl !== void 0) out.url = pic.picUrl;
2498
- const rel = pic.sourcePath ?? pic.picPath;
2499
- if (rel !== void 0) {
2500
- const local = resolveLocalMediaFile(rel, this.deps);
2501
- if (local !== null) out.file = local;
2502
- }
2503
- return out;
2504
- });
2505
- if (base.file === void 0 && base.url !== void 0) {
2506
- const downloaded = await downloadImageToCache(base.url, this.deps);
2507
- if (downloaded !== null) base.file = downloaded;
2122
+ return out;
2123
+ }
2124
+ /** 原生下载语音 → 元素回查本地路径;下载失败/未命中 null(warn 留痕,不抛错)。 */
2125
+ async function downloadPttFallback(msgId, peer, id, deps) {
2126
+ try {
2127
+ const downloaded = await deps.msgApi.downloadPtt(msgId, peer);
2128
+ const rel = downloaded.filePath;
2129
+ if (rel !== void 0 && rel !== "") {
2130
+ const localAfter = resolveLocalMediaFile(rel, deps);
2131
+ if (localAfter !== null) return {
2132
+ ...downloaded.fileSize !== void 0 ? { file_size: downloaded.fileSize } : {},
2133
+ ...downloaded.fileName !== void 0 ? { file_name: downloaded.fileName } : {},
2134
+ file: localAfter
2135
+ };
2508
2136
  }
2509
- return base;
2510
- }
2511
- };
2512
- /** 获取语音信息(本地优先;未命中走原生 downloadRichMedia,失败回退原始路径)。 */
2513
- var GetRecordAction = class extends BaseAction {
2514
- name = "get_record";
2515
- schema = getMediaSchema;
2516
- errorCodeMap = ob11ErrorCodeMap;
2517
- deps;
2518
- constructor(deps) {
2519
- super();
2520
- this.deps = deps;
2521
- }
2522
- async _handle(payload) {
2523
- const id = takeId(payload, "get_record");
2524
- const { msgId, peer } = resolveMsgIdAndPeer(id, this.deps.messageUnique);
2525
- const [first] = await this.deps.msgApi.fetchMsgsByMsgId(peer, [msgId]);
2526
- if (first === void 0) throw kernelError(`消息 ${id} 不存在或已被撤回`, "NOT_FOUND");
2527
- const ptt = first.elements.find((e) => e.pttElement !== void 0)?.pttElement;
2528
- if (ptt === void 0 || ptt.filePath === void 0) throw kernelError(`消息 ${id} 不包含语音`, "NOT_FOUND");
2529
- const meta = () => ({
2530
- ...ptt.fileSize !== void 0 ? { file_size: ptt.fileSize } : {},
2531
- ...ptt.fileName !== void 0 ? { file_name: ptt.fileName } : {}
2532
- });
2533
- const local = resolveLocalMediaFile(ptt.filePath, this.deps);
2534
- if (local !== null) return {
2535
- ...meta(),
2536
- file: local
2537
- };
2538
- try {
2539
- const downloaded = await this.deps.msgApi.downloadPtt(msgId, peer);
2540
- const rel = downloaded.filePath;
2541
- if (rel !== void 0 && rel !== "") {
2542
- const localAfter = resolveLocalMediaFile(rel, this.deps);
2543
- if (localAfter !== null) return {
2544
- ...downloaded.fileSize !== void 0 ? { file_size: downloaded.fileSize } : {},
2545
- ...downloaded.fileName !== void 0 ? { file_name: downloaded.fileName } : {},
2546
- file: localAfter
2547
- };
2548
- }
2549
- } catch {}
2550
- return {
2551
- ...meta(),
2552
- file: ptt.filePath
2553
- };
2554
- }
2555
- };
2556
- const fetchPttTextSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2557
- /** 获取语音转文字结果(P2-10 接 kernel fetchPttText)。 */
2558
- var FetchPttTextAction = class extends BaseAction {
2559
- name = "fetch_ptt_text";
2560
- schema = fetchPttTextSchema;
2561
- errorCodeMap = ob11ErrorCodeMap;
2562
- deps;
2563
- constructor(deps) {
2564
- super();
2565
- this.deps = deps;
2137
+ } catch (err) {
2138
+ deps.logger?.warn({
2139
+ message_id: id,
2140
+ error: err instanceof Error ? err.message : String(err)
2141
+ }, "ob11: 语音原生下载失败,get_record 回退原始路径");
2566
2142
  }
2567
- async _handle(payload) {
2568
- const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
2569
- return { text: await this.deps.msgApi.fetchPttText(msgId, peer) };
2570
- }
2571
- };
2143
+ return null;
2144
+ }
2572
2145
  /** 消息媒体域动作工厂(get_image / get_record / fetch_ptt_text)。 */
2573
2146
  function createMediaActions(api) {
2574
2147
  return [
2575
- new GetImageAction(api),
2576
- new GetRecordAction(api),
2577
- new FetchPttTextAction(api)
2148
+ defineOb11Action({
2149
+ name: "get_image",
2150
+ schema: getMediaSchema,
2151
+ handle: async (payload) => {
2152
+ const base = await resolveMedia(takeId(payload, "get_image"), "图片", api, (el) => extractPicElement(el, api));
2153
+ if (base.file === void 0 && base.url !== void 0) {
2154
+ const downloaded = await downloadImageToCache(base.url, api);
2155
+ if (downloaded !== null) base.file = downloaded;
2156
+ }
2157
+ return base;
2158
+ }
2159
+ }),
2160
+ defineOb11Action({
2161
+ name: "get_record",
2162
+ schema: getMediaSchema,
2163
+ handle: async (payload) => {
2164
+ const id = takeId(payload, "get_record");
2165
+ const { msgId, peer } = resolveMsgIdAndPeer(id, api.messageUnique);
2166
+ const [first] = await api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
2167
+ if (first === void 0) throw kernelError(`消息 ${id} 不存在或已被撤回`, "NOT_FOUND");
2168
+ const ptt = first.elements.find((e) => e.pttElement !== void 0)?.pttElement;
2169
+ if (ptt === void 0 || ptt.filePath === void 0) throw kernelError(`消息 ${id} 不包含语音`, "NOT_FOUND");
2170
+ const meta = () => ({
2171
+ ...ptt.fileSize !== void 0 ? { file_size: ptt.fileSize } : {},
2172
+ ...ptt.fileName !== void 0 ? { file_name: ptt.fileName } : {}
2173
+ });
2174
+ const local = resolveLocalMediaFile(ptt.filePath, api);
2175
+ if (local !== null) return {
2176
+ ...meta(),
2177
+ file: local
2178
+ };
2179
+ return await downloadPttFallback(msgId, peer, id, api) ?? {
2180
+ ...meta(),
2181
+ file: ptt.filePath
2182
+ };
2183
+ }
2184
+ }),
2185
+ defineOb11Action({
2186
+ name: "fetch_ptt_text",
2187
+ schema: fetchPttTextSchema,
2188
+ handle: async (payload) => {
2189
+ const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, api.messageUnique);
2190
+ return { text: await api.msgApi.fetchPttText(msgId, peer) };
2191
+ }
2192
+ })
2578
2193
  ];
2579
2194
  }
2580
2195
  // src/onebot11/action/message/ops.ts
2581
2196
  /**
2582
- * 消息操作域动作(2026-11-14 自 delete-msg / mark-msg-as-read(-aliases) /
2583
- * set-msg-emoji-like / set-input-status 合并)
2197
+ * 消息操作域动作
2584
2198
  *
2585
2199
  * - delete_msg:撤回消息(OB11 标准只有 message_id,peer 经 MessageUnique 反查;
2586
2200
  * 群聊管理员 / 私聊 2 分钟内可撤回)
@@ -2590,93 +2204,12 @@ function createMediaActions(api) {
2590
2204
  * - set_input_status:user_id → uinToUid → MsgApi.setInputStatus(1=输入中,0=停止)
2591
2205
  */
2592
2206
  const deleteMsgSchema = z.object({ message_id: z.union([z.number(), z.string()]) });
2593
- /** 撤回消息(P2-10 接 kernel recallMessage)。 */
2594
- var DeleteMsgAction = class extends BaseAction {
2595
- name = "delete_msg";
2596
- schema = deleteMsgSchema;
2597
- errorCodeMap = ob11ErrorCodeMap;
2598
- deps;
2599
- constructor(deps) {
2600
- super();
2601
- this.deps = deps;
2602
- }
2603
- async _handle(payload) {
2604
- const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, this.deps.messageUnique);
2605
- await this.deps.msgApi.recallMessage(peer, [msgId]);
2606
- return null;
2607
- }
2608
- };
2609
2207
  const markMsgAsReadSchema = z.object({
2610
2208
  user_id: z.number().optional(),
2611
2209
  group_id: z.number().optional()
2612
2210
  }).refine((v) => v.user_id !== void 0 || v.group_id !== void 0, { message: "mark_msg_as_read 需要 user_id 或 group_id" });
2613
- /** 标记消息已读(P2-10 接 kernel markRead)。 */
2614
- var MarkMsgAsReadAction = class extends BaseAction {
2615
- name = "mark_msg_as_read";
2616
- schema = markMsgAsReadSchema;
2617
- errorCodeMap = ob11ErrorCodeMap;
2618
- deps;
2619
- constructor(deps) {
2620
- super();
2621
- this.deps = deps;
2622
- }
2623
- async _handle(payload) {
2624
- if (payload.group_id !== void 0) {
2625
- await this.deps.msgApi.markRead({
2626
- chatType: ChatType.GROUP,
2627
- peerUid: String(payload.group_id)
2628
- });
2629
- return null;
2630
- }
2631
- if (payload.user_id !== void 0) {
2632
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2633
- await this.deps.msgApi.markRead({
2634
- chatType: ChatType.C2C,
2635
- peerUid: uid
2636
- });
2637
- }
2638
- return null;
2639
- }
2640
- };
2641
2211
  const markPrivateMsgAsReadSchema = z.object({ user_id: z.number() });
2642
2212
  const markGroupMsgAsReadSchema = z.object({ group_id: z.number() });
2643
- /** 标记私聊已读(P2-13)。 */
2644
- var MarkPrivateMsgAsReadAction = class extends BaseAction {
2645
- name = "mark_private_msg_as_read";
2646
- schema = markPrivateMsgAsReadSchema;
2647
- errorCodeMap = ob11ErrorCodeMap;
2648
- deps;
2649
- constructor(deps) {
2650
- super();
2651
- this.deps = deps;
2652
- }
2653
- async _handle(payload) {
2654
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2655
- await this.deps.msgApi.markRead({
2656
- chatType: ChatType.C2C,
2657
- peerUid: uid
2658
- });
2659
- return null;
2660
- }
2661
- };
2662
- /** 标记群聊已读(P2-13)。 */
2663
- var MarkGroupMsgAsReadAction = class extends BaseAction {
2664
- name = "mark_group_msg_as_read";
2665
- schema = markGroupMsgAsReadSchema;
2666
- errorCodeMap = ob11ErrorCodeMap;
2667
- deps;
2668
- constructor(deps) {
2669
- super();
2670
- this.deps = deps;
2671
- }
2672
- async _handle(payload) {
2673
- await this.deps.msgApi.markRead({
2674
- chatType: ChatType.GROUP,
2675
- peerUid: String(payload.group_id)
2676
- });
2677
- return null;
2678
- }
2679
- };
2680
2213
  const setMsgEmojiLikeSchema = z.object({
2681
2214
  message_id: z.union([z.number(), z.string()]),
2682
2215
  /** 表情 ID(如 105 点赞)。 */
@@ -2686,27 +2219,6 @@ const setMsgEmojiLikeSchema = z.object({
2686
2219
  /** 是否点赞(false 取消)。 */
2687
2220
  like: z.boolean().optional()
2688
2221
  });
2689
- /** 消息表情表态(P2-10 接 kernel setMsgEmojiLike)。 */
2690
- var SetMsgEmojiLikeAction = class extends BaseAction {
2691
- name = "set_msg_emoji_like";
2692
- schema = setMsgEmojiLikeSchema;
2693
- errorCodeMap = ob11ErrorCodeMap;
2694
- deps;
2695
- constructor(deps) {
2696
- super();
2697
- this.deps = deps;
2698
- }
2699
- async _handle(payload) {
2700
- const { msg, peer } = await fetchMsgById(payload.message_id, this.deps.messageUnique, this.deps.msgApi);
2701
- await this.deps.msgApi.setMsgEmojiLike(peer, {
2702
- msgSeq: msg.msgSeq,
2703
- emojiId: String(payload.emoji_id),
2704
- emojiType: String(payload.emoji_type ?? 1),
2705
- like: payload.like ?? true
2706
- });
2707
- return null;
2708
- }
2709
- };
2710
2222
  const setInputStatusSchema = z.object({
2711
2223
  user_id: z.number(),
2712
2224
  /** 输入事件类型:1=输入中,0=停止。 */
@@ -2714,37 +2226,91 @@ const setInputStatusSchema = z.object({
2714
2226
  });
2715
2227
  /** 输入中事件类型。 */
2716
2228
  const EVENT_TYPE_TYPING = 1;
2717
- /** 发送输入状态(P2-11 接 kernel setInputStatus)。 */
2718
- var SetInputStatusAction = class extends BaseAction {
2719
- name = "set_input_status";
2720
- schema = setInputStatusSchema;
2721
- errorCodeMap = ob11ErrorCodeMap;
2722
- deps;
2723
- constructor(deps) {
2724
- super();
2725
- this.deps = deps;
2726
- }
2727
- async _handle(payload) {
2728
- const uid = await resolveUid(String(payload.user_id), this.deps.uinToUid);
2729
- await this.deps.msgApi.setInputStatus({
2730
- chatType: ChatType.C2C,
2731
- peerUid: uid
2732
- }, payload.event_type ?? EVENT_TYPE_TYPING);
2733
- return null;
2734
- }
2735
- };
2736
2229
  /**
2737
2230
  * 消息操作域动作工厂(delete_msg / mark_msg_as_read 系列 / set_msg_emoji_like /
2738
2231
  * set_input_status)。
2739
2232
  */
2740
2233
  function createMsgOpsActions(api) {
2741
2234
  return [
2742
- new DeleteMsgAction(api),
2743
- new MarkMsgAsReadAction(api),
2744
- new MarkPrivateMsgAsReadAction(api),
2745
- new MarkGroupMsgAsReadAction(api),
2746
- new SetMsgEmojiLikeAction(api),
2747
- new SetInputStatusAction(api)
2235
+ defineOb11Action({
2236
+ name: "delete_msg",
2237
+ schema: deleteMsgSchema,
2238
+ handle: async (payload) => {
2239
+ const { msgId, peer } = resolveMsgIdAndPeer(payload.message_id, api.messageUnique);
2240
+ await api.msgApi.recallMessage(peer, [msgId]);
2241
+ return null;
2242
+ }
2243
+ }),
2244
+ defineOb11Action({
2245
+ name: "mark_msg_as_read",
2246
+ schema: markMsgAsReadSchema,
2247
+ handle: async (payload) => {
2248
+ if (payload.group_id !== void 0) {
2249
+ await api.msgApi.markRead({
2250
+ chatType: ChatType.GROUP,
2251
+ peerUid: String(payload.group_id)
2252
+ });
2253
+ return null;
2254
+ }
2255
+ if (payload.user_id !== void 0) {
2256
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2257
+ await api.msgApi.markRead({
2258
+ chatType: ChatType.C2C,
2259
+ peerUid: uid
2260
+ });
2261
+ }
2262
+ return null;
2263
+ }
2264
+ }),
2265
+ defineOb11Action({
2266
+ name: "mark_private_msg_as_read",
2267
+ schema: markPrivateMsgAsReadSchema,
2268
+ handle: async (payload) => {
2269
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2270
+ await api.msgApi.markRead({
2271
+ chatType: ChatType.C2C,
2272
+ peerUid: uid
2273
+ });
2274
+ return null;
2275
+ }
2276
+ }),
2277
+ defineOb11Action({
2278
+ name: "mark_group_msg_as_read",
2279
+ schema: markGroupMsgAsReadSchema,
2280
+ handle: async (payload) => {
2281
+ await api.msgApi.markRead({
2282
+ chatType: ChatType.GROUP,
2283
+ peerUid: String(payload.group_id)
2284
+ });
2285
+ return null;
2286
+ }
2287
+ }),
2288
+ defineOb11Action({
2289
+ name: "set_msg_emoji_like",
2290
+ schema: setMsgEmojiLikeSchema,
2291
+ handle: async (payload) => {
2292
+ const { msg, peer } = await fetchMsgById(payload.message_id, api.messageUnique, api.msgApi);
2293
+ await api.msgApi.setMsgEmojiLike(peer, {
2294
+ msgSeq: msg.msgSeq,
2295
+ emojiId: String(payload.emoji_id),
2296
+ emojiType: String(payload.emoji_type ?? 1),
2297
+ like: payload.like ?? true
2298
+ });
2299
+ return null;
2300
+ }
2301
+ }),
2302
+ defineOb11Action({
2303
+ name: "set_input_status",
2304
+ schema: setInputStatusSchema,
2305
+ handle: async (payload) => {
2306
+ const uid = await resolveUid(String(payload.user_id), api.uinToUid);
2307
+ await api.msgApi.setInputStatus({
2308
+ chatType: ChatType.C2C,
2309
+ peerUid: uid
2310
+ }, payload.event_type ?? EVENT_TYPE_TYPING);
2311
+ return null;
2312
+ }
2313
+ })
2748
2314
  ];
2749
2315
  }
2750
2316
  // src/onebot11/action/message/send.ts
@@ -2755,6 +2321,19 @@ const sendMsgSchema = z.object({
2755
2321
  message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2756
2322
  auto_escape: z.boolean().optional()
2757
2323
  });
2324
+ /** send_private / send_group 共用的消息与转义字段(上界见 action/limits.ts)。 */
2325
+ const sendMsgBodyFields = {
2326
+ message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2327
+ auto_escape: z.boolean().optional()
2328
+ };
2329
+ const sendPrivateMsgSchema = z.object({
2330
+ user_id: z.number(),
2331
+ ...sendMsgBodyFields
2332
+ });
2333
+ const sendGroupMsgSchema = z.object({
2334
+ group_id: z.number(),
2335
+ ...sendMsgBodyFields
2336
+ });
2758
2337
  /** 共享发送核心:解析 Peer → canonical 翻译(含 auto_escape)→ sendMessage → 映射 message_id。 */
2759
2338
  async function sendOb11Message(payload, deps) {
2760
2339
  const peer = await resolveTargetPeer(payload, deps, "send_msg 需要 group_id 或 user_id");
@@ -2766,7 +2345,12 @@ async function sendOb11Message(payload, deps) {
2766
2345
  let uinToUid;
2767
2346
  if (atUins.length > 0) try {
2768
2347
  uinToUid = await deps.uinToUid(atUins);
2769
- } catch {}
2348
+ } catch (err) {
2349
+ deps.logger?.warn({
2350
+ count: atUins.length,
2351
+ error: err instanceof Error ? err.message : String(err)
2352
+ }, "ob11: at uin→uid 失败,at 段原样发送");
2353
+ }
2770
2354
  canonical = applySendContext(canonical, {
2771
2355
  ...uinToUid !== void 0 ? { uinToUid } : {},
2772
2356
  ob11IdToMsgId: (id) => deps.messageUnique.getMsgId(id)
@@ -2778,7 +2362,7 @@ async function sendOb11Message(payload, deps) {
2778
2362
  };
2779
2363
  return el;
2780
2364
  });
2781
- canonical = await ensureVoiceSilk(canonical);
2365
+ canonical = await ensureVoiceSilk(canonical, deps.logger);
2782
2366
  const prepared = await prepareVideoElements(canonical);
2783
2367
  try {
2784
2368
  const { msgId } = await deps.msgApi.sendMessage(peer, prepared.elements);
@@ -2787,271 +2371,174 @@ async function sendOb11Message(payload, deps) {
2787
2371
  await prepared.cleanup();
2788
2372
  }
2789
2373
  }
2790
- /** 发送消息(P2-3 接 kernel apis/msg,返回真实 message_id)。 */
2791
- var SendMsgAction = class extends BaseAction {
2792
- name = "send_msg";
2793
- schema = sendMsgSchema;
2794
- errorCodeMap = ob11ErrorCodeMap;
2795
- deps;
2796
- constructor(deps) {
2797
- super();
2798
- this.deps = deps;
2799
- }
2800
- _handle(payload) {
2801
- return sendOb11Message(payload, this.deps);
2802
- }
2803
- };
2804
- const sendPrivateMsgSchema = z.object({
2805
- user_id: z.number(),
2806
- message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2807
- auto_escape: z.boolean().optional()
2808
- });
2809
- /** 发送私聊消息(P2-10 复用 sendOb11Message)。 */
2810
- var SendPrivateMsgAction = class extends BaseAction {
2811
- name = "send_private_msg";
2812
- schema = sendPrivateMsgSchema;
2813
- errorCodeMap = ob11ErrorCodeMap;
2814
- deps;
2815
- constructor(deps) {
2816
- super();
2817
- this.deps = deps;
2818
- }
2819
- _handle(payload) {
2820
- return sendOb11Message(payload, this.deps);
2821
- }
2822
- };
2823
- const sendGroupMsgSchema = z.object({
2824
- group_id: z.number(),
2825
- message: z.union([z.string(), z.array(z.unknown()).max(200)]),
2826
- auto_escape: z.boolean().optional()
2827
- });
2828
- /** 发送群聊消息(P2-10 复用 sendOb11Message)。 */
2829
- var SendGroupMsgAction = class extends BaseAction {
2830
- name = "send_group_msg";
2831
- schema = sendGroupMsgSchema;
2832
- errorCodeMap = ob11ErrorCodeMap;
2833
- deps;
2834
- constructor(deps) {
2835
- super();
2836
- this.deps = deps;
2837
- }
2838
- _handle(payload) {
2839
- return sendOb11Message(payload, this.deps);
2840
- }
2841
- };
2842
2374
  /** CQ 特殊字符转义(auto_escape,&、[、]、, 前置 &)。 */
2843
2375
  function escapeText(text) {
2844
2376
  return text.replaceAll("&", "&").replaceAll("[", "[").replaceAll("]", "]").replaceAll(",", ",");
2845
2377
  }
2846
2378
  /** 语音元素统一转 silk:非 silk 自动转码(QQ 语音格式),已是 silk 原样。 */
2847
- async function ensureVoiceSilk(elements) {
2379
+ async function ensureVoiceSilk(elements, logger) {
2848
2380
  const out = [];
2849
2381
  for (const el of elements) if (el.type === "voice") out.push({
2850
2382
  ...el,
2851
- path: await ensureSilk(el.path)
2383
+ path: await ensureSilk(el.path, logger)
2852
2384
  });
2853
2385
  else out.push(el);
2854
2386
  return out;
2855
2387
  }
2856
2388
  /** 消息发送域动作工厂(send_msg / send_private_msg / send_group_msg)。 */
2857
2389
  function createSendActions(api) {
2390
+ const deps = api;
2858
2391
  return [
2859
- new SendMsgAction(api),
2860
- new SendPrivateMsgAction(api),
2861
- new SendGroupMsgAction(api)
2392
+ defineOb11Action({
2393
+ name: "send_msg",
2394
+ schema: sendMsgSchema,
2395
+ handle: (payload) => sendOb11Message(payload, deps)
2396
+ }),
2397
+ defineOb11Action({
2398
+ name: "send_private_msg",
2399
+ schema: sendPrivateMsgSchema,
2400
+ handle: (payload) => sendOb11Message(payload, deps)
2401
+ }),
2402
+ defineOb11Action({
2403
+ name: "send_group_msg",
2404
+ schema: sendGroupMsgSchema,
2405
+ handle: (payload) => sendOb11Message(payload, deps)
2406
+ })
2862
2407
  ];
2863
2408
  }
2864
2409
  // src/onebot11/action/system/account.ts
2865
2410
  /**
2866
- * 账号票据与资料域动作(2026-11-14 自 get-cookies / get-clientkey /
2867
- * get-credentials / profile-actions 合并)
2411
+ * 账号票据与资料域动作
2868
2412
  *
2869
- * - get_cookies(P2-13):kernel TicketApi.getCookies,domain 缺省 v2.qq.com
2413
+ * - get_cookies:kernel TicketApi.getCookies,domain 缺省 v2.qq.com
2870
2414
  * (NapCat 行为);user_id 缺省用机器人自身 uin
2871
- * - get_clientkey(P2-13):kernel TicketApi.getClientKey
2872
- * - get_csrf_token / get_credentials(P2-15):qun.qq.com cookies 的 skey → bkn
2415
+ * - get_clientkey:kernel TicketApi.getClientKey
2416
+ * - get_csrf_token / get_credentials:qun.qq.com cookies 的 skey → bkn
2873
2417
  * (csrf 等价物);get_credentials 返回指定域名 cookies + bkn
2874
- * - set_self_longnick / set_qq_profile / set_qq_avatar(P2-14):kernel ProfileApi;
2418
+ * - set_self_longnick / set_qq_profile / set_qq_avatar:kernel ProfileApi;
2875
2419
  * set_qq_profile 的 sex 忽略,头像 URL 需先经 cacheDir 下载
2876
2420
  */
2877
2421
  /** URL 前缀(头像在线文件识别)。 */
2878
2422
  const URL_PREFIX = /^https?:\/\//;
2423
+ /** 默认域名。 */
2424
+ const DEFAULT_DOMAIN = "v2.qq.com";
2425
+ /** 默认域名(bkn 计算用)。 */
2426
+ const BKN_DOMAIN = "qun.qq.com";
2879
2427
  const getCookiesSchema = z.object({
2880
2428
  domain: z.string().optional(),
2881
2429
  user_id: z.number().optional()
2882
2430
  });
2883
- /** 默认域名。 */
2884
- const DEFAULT_DOMAIN = "v2.qq.com";
2885
- /** 获取 cookies(P2-13 接 kernel TicketApi.getCookies)。 */
2886
- var GetCookiesAction = class extends BaseAction {
2887
- name = "get_cookies";
2888
- schema = getCookiesSchema;
2889
- errorCodeMap = ob11ErrorCodeMap;
2890
- deps;
2891
- constructor(deps) {
2892
- super();
2893
- this.deps = deps;
2894
- }
2895
- _handle(payload) {
2896
- const domain = payload.domain ?? DEFAULT_DOMAIN;
2897
- let uin = this.deps.selfUin;
2898
- if (payload.user_id !== void 0) uin = String(payload.user_id);
2899
- return this.deps.ticketApi.getCookies(domain, uin);
2900
- }
2901
- };
2902
2431
  const getClientkeySchema = z.object({});
2903
- /** 获取 clientKey(P2-13 接 kernel TicketApi)。 */
2904
- var GetClientkeyAction = class extends BaseAction {
2905
- name = "get_clientkey";
2906
- schema = getClientkeySchema;
2907
- errorCodeMap = ob11ErrorCodeMap;
2908
- ticketApi;
2909
- constructor(ticketApi) {
2910
- super();
2911
- this.ticketApi = ticketApi;
2912
- }
2913
- async _handle(_payload) {
2914
- const raw = await this.ticketApi.getClientKey();
2915
- return {
2916
- clientKey: raw.clientKey,
2917
- keyIndex: raw.keyIndex,
2918
- expireTime: raw.expireTime,
2919
- url: raw.url
2920
- };
2921
- }
2922
- };
2923
2432
  const getCsrfTokenSchema = z.object({});
2924
- /** 默认域名(bkn 计算用)。 */
2925
- const BKN_DOMAIN = "qun.qq.com";
2926
- /** 获取 csrf_token(bkn,P2-15)。 */
2927
- var GetCsrfTokenAction = class extends BaseAction {
2928
- name = "get_csrf_token";
2929
- schema = getCsrfTokenSchema;
2930
- errorCodeMap = ob11ErrorCodeMap;
2931
- deps;
2932
- constructor(deps) {
2933
- super();
2934
- this.deps = deps;
2935
- }
2936
- async _handle(_payload) {
2937
- const skey = (await this.deps.ticketApi.getCookies(BKN_DOMAIN, this.deps.selfUin))["skey"] ?? "";
2938
- return { token: Number(TicketApi.getBkn(skey)) };
2939
- }
2940
- };
2941
2433
  const getCredentialsSchema = z.object({ domain: z.string().optional() });
2942
- /** 获取凭据(cookies + csrf_token,P2-15)。 */
2943
- var GetCredentialsAction = class extends BaseAction {
2944
- name = "get_credentials";
2945
- schema = getCredentialsSchema;
2946
- errorCodeMap = ob11ErrorCodeMap;
2947
- deps;
2948
- constructor(deps) {
2949
- super();
2950
- this.deps = deps;
2951
- }
2952
- async _handle(payload) {
2953
- const domain = payload.domain ?? BKN_DOMAIN;
2954
- const cookies = await this.deps.ticketApi.getCookies(domain, this.deps.selfUin);
2955
- return {
2956
- cookies,
2957
- csrf_token: Number(TicketApi.getBkn(cookies["skey"] ?? ""))
2958
- };
2959
- }
2960
- };
2961
2434
  const setSelfLongnickSchema = z.object({ longNick: z.string() });
2962
- /** 设置个性签名(P2-14 接 kernel ProfileApi.setLongNick)。 */
2963
- var SetSelfLongnickAction = class extends BaseAction {
2964
- name = "set_self_longnick";
2965
- schema = setSelfLongnickSchema;
2966
- errorCodeMap = ob11ErrorCodeMap;
2967
- profileApi;
2968
- constructor(profileApi) {
2969
- super();
2970
- this.profileApi = profileApi;
2971
- }
2972
- async _handle(payload) {
2973
- await this.profileApi.setLongNick(payload.longNick);
2974
- return null;
2975
- }
2976
- };
2977
2435
  const setQQProfileSchema = z.object({
2978
2436
  nickname: z.string(),
2979
2437
  personal_note: z.string().optional(),
2980
2438
  sex: z.union([z.number(), z.string()]).optional()
2981
2439
  });
2982
- /** 设置 QQ 资料(P2-14;nickname → setNickName,personal_note → setLongNick,sex 忽略)。 */
2983
- var SetQQProfileAction = class extends BaseAction {
2984
- name = "set_qq_profile";
2985
- schema = setQQProfileSchema;
2986
- errorCodeMap = ob11ErrorCodeMap;
2987
- profileApi;
2988
- constructor(profileApi) {
2989
- super();
2990
- this.profileApi = profileApi;
2991
- }
2992
- async _handle(payload) {
2993
- await this.profileApi.setNickName(payload.nickname);
2994
- if (payload.personal_note !== void 0) await this.profileApi.setLongNick(payload.personal_note);
2995
- return null;
2996
- }
2997
- };
2998
2440
  const setQQAvatarSchema = z.object({
2999
2441
  /** 本地路径(URL 需先下载,由装配方 cacheDir 支持)。 */
3000
2442
  file: z.string() });
3001
- /** 设置 QQ 头像(P2-14 接 kernel ProfileApi.setHeader)。 */
3002
- var SetQQAvatarAction = class extends BaseAction {
3003
- name = "set_qq_avatar";
3004
- schema = setQQAvatarSchema;
3005
- errorCodeMap = ob11ErrorCodeMap;
3006
- deps;
3007
- constructor(deps) {
3008
- super();
3009
- this.deps = deps;
3010
- }
3011
- async _handle(payload) {
3012
- let filePath = payload.file;
3013
- if (URL_PREFIX.test(filePath)) filePath = await this.downloadToCache(filePath);
3014
- if (!existsSync(filePath)) throw kernelError(`头像文件不存在: ${filePath}`, "NOT_FOUND");
3015
- await this.deps.profileApi.setHeader(filePath);
3016
- return null;
3017
- }
3018
- /** URL 下载到缓存目录(cacheDir 缺省抛错)。 */
3019
- async downloadToCache(url) {
3020
- const { cacheDir } = this.deps;
3021
- if (cacheDir === void 0 || cacheDir === "") throw kernelError("set_qq_avatar 处理 URL 需要缓存目录(装配方未注入)", "INVALID_STATE");
3022
- const safeName = basename(new URL(url).pathname) || "avatar.bin";
3023
- const filePath = join(cacheDir, `avatar-${Date.now()}-${safeName}`);
3024
- const res = await fetch(url);
3025
- if (!res.ok) throw new Error(`头像下载失败: ${res.status} ${res.statusText}`);
3026
- const buf = new Uint8Array(await res.arrayBuffer());
3027
- writeFileSync(filePath, buf);
3028
- return filePath;
3029
- }
3030
- };
2443
+ /** URL 头像下载到缓存目录(cacheDir 缺省抛错)。 */
2444
+ async function downloadAvatarToCache(url, cacheDir) {
2445
+ if (cacheDir === void 0 || cacheDir === "") throw kernelError("set_qq_avatar 处理 URL 需要缓存目录(装配方未注入)", "INVALID_STATE");
2446
+ const safeName = basename(new URL(url).pathname) || "avatar.bin";
2447
+ const filePath = join(cacheDir, `avatar-${Date.now()}-${safeName}`);
2448
+ const res = await fetch(url);
2449
+ if (!res.ok) throw new Error(`头像下载失败: ${res.status} ${res.statusText}`);
2450
+ const buf = new Uint8Array(await res.arrayBuffer());
2451
+ writeFileSync(filePath, buf);
2452
+ return filePath;
2453
+ }
3031
2454
  /**
3032
2455
  * 账号票据与资料域动作工厂(cookies / clientkey / csrf_token / credentials /
3033
2456
  * self_longnick / qq_profile / qq_avatar)。
3034
2457
  */
3035
2458
  function createSystemAccountActions(api) {
3036
2459
  return [
3037
- new GetClientkeyAction(api.ticketApi),
3038
- new GetCookiesAction(api),
3039
- new GetCsrfTokenAction(api),
3040
- new GetCredentialsAction(api),
3041
- new SetSelfLongnickAction(api.profileApi),
3042
- new SetQQProfileAction(api.profileApi),
3043
- new SetQQAvatarAction(api)
2460
+ defineOb11Action({
2461
+ name: "get_clientkey",
2462
+ schema: getClientkeySchema,
2463
+ handle: async () => {
2464
+ const raw = await api.ticketApi.getClientKey();
2465
+ return {
2466
+ clientKey: raw.clientKey,
2467
+ keyIndex: raw.keyIndex,
2468
+ expireTime: raw.expireTime,
2469
+ url: raw.url
2470
+ };
2471
+ }
2472
+ }),
2473
+ defineOb11Action({
2474
+ name: "get_cookies",
2475
+ schema: getCookiesSchema,
2476
+ handle: (payload) => {
2477
+ const domain = payload.domain ?? DEFAULT_DOMAIN;
2478
+ let uin = api.selfUin;
2479
+ if (payload.user_id !== void 0) uin = String(payload.user_id);
2480
+ return api.ticketApi.getCookies(domain, uin);
2481
+ }
2482
+ }),
2483
+ defineOb11Action({
2484
+ name: "get_csrf_token",
2485
+ schema: getCsrfTokenSchema,
2486
+ handle: async () => {
2487
+ const skey = (await api.ticketApi.getCookies(BKN_DOMAIN, api.selfUin))["skey"] ?? "";
2488
+ return { token: Number(TicketApi.getBkn(skey)) };
2489
+ }
2490
+ }),
2491
+ defineOb11Action({
2492
+ name: "get_credentials",
2493
+ schema: getCredentialsSchema,
2494
+ handle: async (payload) => {
2495
+ const domain = payload.domain ?? BKN_DOMAIN;
2496
+ const cookies = await api.ticketApi.getCookies(domain, api.selfUin);
2497
+ return {
2498
+ cookies,
2499
+ csrf_token: Number(TicketApi.getBkn(cookies["skey"] ?? ""))
2500
+ };
2501
+ }
2502
+ }),
2503
+ defineOb11Action({
2504
+ name: "set_self_longnick",
2505
+ schema: setSelfLongnickSchema,
2506
+ handle: async (payload) => {
2507
+ await api.profileApi.setLongNick(payload.longNick);
2508
+ return null;
2509
+ }
2510
+ }),
2511
+ defineOb11Action({
2512
+ name: "set_qq_profile",
2513
+ schema: setQQProfileSchema,
2514
+ handle: async (payload) => {
2515
+ await api.profileApi.setNickName(payload.nickname);
2516
+ if (payload.personal_note !== void 0) await api.profileApi.setLongNick(payload.personal_note);
2517
+ return null;
2518
+ }
2519
+ }),
2520
+ defineOb11Action({
2521
+ name: "set_qq_avatar",
2522
+ schema: setQQAvatarSchema,
2523
+ handle: async (payload) => {
2524
+ let filePath = payload.file;
2525
+ if (URL_PREFIX.test(filePath)) filePath = await downloadAvatarToCache(filePath, api.cacheDir);
2526
+ if (!existsSync(filePath)) throw kernelError(`头像文件不存在: ${filePath}`, "NOT_FOUND");
2527
+ await api.profileApi.setHeader(filePath);
2528
+ return null;
2529
+ }
2530
+ })
3044
2531
  ];
3045
2532
  }
3046
2533
  // src/onebot11/action/system/file.ts
3047
2534
  /**
3048
- * 文件收发域动作(2026-11-14 自 system/download-file 与根部 upload-file 合并)
2535
+ * 文件收发域动作
3049
2536
  *
3050
- * - download_file(P2-12):url → fetch 下载 → 存 cacheDir(缺省抛错)→ 返回
2537
+ * - download_file:url → fetch 下载 → 存 cacheDir(缺省抛错)→ 返回
3051
2538
  * { file }。文件名:download-<timestamp>-<basename>(headers 等扩展字段忽略)
3052
2539
  * - upload_group_file / upload_private_file——**闪传通道**
3053
2540
  *
3054
- * ⚠️ 语义降级(2026-11-11 决定,探测依据见 kernel design §15):
2541
+ * ⚠️ 语义降级(探测依据见 kernel design §15):
3055
2542
  * QQ NT 没有任何「把文件传进群文件列表」的 NAPI,`sendMsg` 带 fileElement 时原生走的
3056
2543
  * 文件传输命令被服务端拒绝(`170019002`,逐维扫参无效),`fileUuid` 永远拿不到。唯一实测
3057
2544
  * 可用的投递通道是闪传:上传文件集 → 发分享卡片。因此本动作:
@@ -3064,40 +2551,15 @@ function createSystemAccountActions(api) {
3064
2551
  * 输入只接受本地路径与 `file://` URI:远程 `http(s)://` / `base64://` 需要下载缓存与媒体
3065
2552
  * 依赖,当前未接(明确报错,不静默失败)。
3066
2553
  */
2554
+ /** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
2555
+ const FILE_URI_PREFIX_RE = /^file:\/\//;
2556
+ /** 路径分隔符(取文件名用)。 */
2557
+ const PATH_SEPARATORS = /[\\/]/;
3067
2558
  const downloadFileSchema = z.object({
3068
2559
  url: z.string(),
3069
2560
  thread_count: z.number().optional(),
3070
2561
  headers: z.record(z.string(), z.string()).optional()
3071
2562
  });
3072
- /** 下载文件到缓存目录(P2-12)。 */
3073
- var DownloadFileAction = class extends BaseAction {
3074
- name = "download_file";
3075
- schema = downloadFileSchema;
3076
- errorCodeMap = ob11ErrorCodeMap;
3077
- deps;
3078
- constructor(deps) {
3079
- super();
3080
- this.deps = deps;
3081
- }
3082
- async _handle(payload) {
3083
- const { cacheDir } = this.deps;
3084
- if (cacheDir === void 0 || cacheDir === "") throw kernelError("download_file 未配置缓存目录(装配方未注入)", "INVALID_STATE");
3085
- const safeName = basename(new URL(payload.url).pathname) || "download.bin";
3086
- const filePath = join(cacheDir, `download-${Date.now()}-${safeName}`);
3087
- mkdirSync(cacheDir, { recursive: true });
3088
- const init = {};
3089
- if (payload.headers !== void 0) init.headers = payload.headers;
3090
- const res = await fetch(payload.url, init);
3091
- if (!res.ok) throw new Error(`下载失败: ${res.status} ${res.statusText}`);
3092
- const buf = new Uint8Array(await res.arrayBuffer());
3093
- writeFileSync(filePath, buf);
3094
- return { file: filePath };
3095
- }
3096
- };
3097
- /** file:// 前缀(fileURLToPath 失败时的裸剥离兜底)。 */
3098
- const FILE_URI_PREFIX_RE = /^file:\/\//;
3099
- /** 路径分隔符(取文件名用)。 */
3100
- const PATH_SEPARATORS = /[\\/]/;
3101
2563
  const uploadGroupFileSchema = z.object({
3102
2564
  group_id: z.number(),
3103
2565
  file: z.string().min(1),
@@ -3110,41 +2572,6 @@ const uploadPrivateFileSchema = z.object({
3110
2572
  file: z.string().min(1),
3111
2573
  name: z.string().optional()
3112
2574
  });
3113
- /** upload_group_file:上传文件并投递到群(闪传卡片;语义降级见文件头)。 */
3114
- var UploadGroupFileAction = class extends BaseAction {
3115
- name = "upload_group_file";
3116
- schema = uploadGroupFileSchema;
3117
- errorCodeMap = ob11ErrorCodeMap;
3118
- deps;
3119
- constructor(deps) {
3120
- super();
3121
- this.deps = deps;
3122
- }
3123
- async _handle(payload) {
3124
- const path = resolveLocalFile(payload.file);
3125
- const peer = {
3126
- chatType: ChatType.GROUP,
3127
- peerUid: String(payload.group_id)
3128
- };
3129
- return { file_id: (await this.deps.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
3130
- }
3131
- };
3132
- /** upload_private_file:上传文件并投递到私聊(闪传卡片;语义降级见文件头)。 */
3133
- var UploadPrivateFileAction = class extends BaseAction {
3134
- name = "upload_private_file";
3135
- schema = uploadPrivateFileSchema;
3136
- errorCodeMap = ob11ErrorCodeMap;
3137
- deps;
3138
- constructor(deps) {
3139
- super();
3140
- this.deps = deps;
3141
- }
3142
- async _handle(payload) {
3143
- const path = resolveLocalFile(payload.file);
3144
- const peer = await resolveTargetPeer({ user_id: payload.user_id }, this.deps, "upload_private_file 需要 user_id");
3145
- return { file_id: (await this.deps.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
3146
- }
3147
- };
3148
2575
  /** 本地路径 / file:// 展开;远程 URI 明确拒绝(未接下载缓存)。 */
3149
2576
  function resolveLocalFile(file) {
3150
2577
  if (file.startsWith("http://") || file.startsWith("https://") || file.startsWith("base64://")) throw kernelError("upload_group_file/upload_private_file 目前只支持本地路径与 file:// URI(远程 URI 需要下载缓存,未接入)", "INVALID_PARAM");
@@ -3164,148 +2591,136 @@ function basename$1(path) {
3164
2591
  /** 文件收发域动作工厂(download_file / upload_group_file / upload_private_file)。 */
3165
2592
  function createSystemFileActions(api) {
3166
2593
  return [
3167
- new DownloadFileAction(api),
3168
- new UploadGroupFileAction(api),
3169
- new UploadPrivateFileAction(api)
2594
+ defineOb11Action({
2595
+ name: "download_file",
2596
+ schema: downloadFileSchema,
2597
+ handle: async (payload) => {
2598
+ const { cacheDir } = api;
2599
+ if (cacheDir === void 0 || cacheDir === "") throw kernelError("download_file 未配置缓存目录(装配方未注入)", "INVALID_STATE");
2600
+ const safeName = basename(new URL(payload.url).pathname) || "download.bin";
2601
+ const filePath = join(cacheDir, `download-${Date.now()}-${safeName}`);
2602
+ mkdirSync(cacheDir, { recursive: true });
2603
+ const init = {};
2604
+ if (payload.headers !== void 0) init.headers = payload.headers;
2605
+ const res = await fetch(payload.url, init);
2606
+ if (!res.ok) throw new Error(`下载失败: ${res.status} ${res.statusText}`);
2607
+ const buf = new Uint8Array(await res.arrayBuffer());
2608
+ writeFileSync(filePath, buf);
2609
+ return { file: filePath };
2610
+ }
2611
+ }),
2612
+ defineOb11Action({
2613
+ name: "upload_group_file",
2614
+ schema: uploadGroupFileSchema,
2615
+ handle: async (payload) => {
2616
+ const path = resolveLocalFile(payload.file);
2617
+ const peer = {
2618
+ chatType: ChatType.GROUP,
2619
+ peerUid: String(payload.group_id)
2620
+ };
2621
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
2622
+ }
2623
+ }),
2624
+ defineOb11Action({
2625
+ name: "upload_private_file",
2626
+ schema: uploadPrivateFileSchema,
2627
+ handle: async (payload) => {
2628
+ const path = resolveLocalFile(payload.file);
2629
+ const peer = await resolveTargetPeer({ user_id: payload.user_id }, api, "upload_private_file 需要 user_id");
2630
+ return { file_id: (await api.flashTransferApi.sendFile(peer, [path], { name: payload.name ?? basename$1(path) })).fileSetId };
2631
+ }
2632
+ })
3170
2633
  ];
3171
2634
  }
3172
2635
  // src/onebot11/action/system/info.ts
3173
- const getLoginInfoSchema = z.object({});
3174
- /** 获取登录信息(self 由装配方注入,P2-5 接 kernel selfInfo 维护后取真实昵称)。 */
3175
- var GetLoginInfoAction = class extends BaseAction {
3176
- name = "get_login_info";
3177
- schema = getLoginInfoSchema;
3178
- errorCodeMap = ob11ErrorCodeMap;
3179
- self;
3180
- constructor(self) {
3181
- super();
3182
- this.self = self;
3183
- }
3184
- _handle(_payload) {
3185
- return Promise.resolve({
3186
- user_id: Number(this.self.uin),
3187
- nickname: this.self.nickname
3188
- });
3189
- }
3190
- };
3191
- const getVersionInfoSchema = z.object({});
3192
- /** 获取版本信息(本地组装,P2-11)。 */
3193
- var GetVersionInfoAction = class extends BaseAction {
3194
- name = "get_version_info";
3195
- schema = getVersionInfoSchema;
3196
- errorCodeMap = ob11ErrorCodeMap;
3197
- deps;
3198
- constructor(deps) {
3199
- super();
3200
- this.deps = deps;
3201
- }
3202
- _handle(_payload) {
3203
- return Promise.resolve({
3204
- app_name: "napuketto-qq",
3205
- app_version: this.deps.appVersion,
3206
- protocol_version: "v11"
3207
- });
3208
- }
3209
- };
3210
- const getStatusSchema = z.object({});
3211
- /** 获取运行状态(本地组装,P2-11)。 */
3212
- var GetStatusAction = class extends BaseAction {
3213
- name = "get_status";
3214
- schema = getStatusSchema;
3215
- errorCodeMap = ob11ErrorCodeMap;
3216
- _handle(_payload) {
3217
- return Promise.resolve({
3218
- online: true,
3219
- good: true
3220
- });
3221
- }
3222
- };
3223
- const getRobotUinRangeSchema = z.object({});
2636
+ /**
2637
+ * 系统信息域动作——只读信息查询,多为本地组装。
2638
+ *
2639
+ * - get_login_info:self 由装配方注入(接 kernel selfInfo 取真实昵称)
2640
+ * - get_version_info:appVersion 由装配方注入(kernel wrapper 版本或
2641
+ * NAPUTO_QQ_VERSION)
2642
+ * - get_status:返回与心跳 status 同构的 OB11Status(online/good)
2643
+ * - get_robot_uin_range:NapCat 从配置返回;这里给通用范围(min/max)
2644
+ * - translate_en2zh:kernel RichMediaApi.translateWords(词条数组限长)
2645
+ */
3224
2646
  /** QQ 号下限。 */
3225
2647
  const UIN_MIN = 10001;
3226
2648
  /** QQ 号上限。 */
3227
2649
  const UIN_MAX = 4294967295;
3228
- /** 获取机器人 QQ 号范围(P2-11 本地组装)。 */
3229
- var GetRobotUinRangeAction = class extends BaseAction {
3230
- name = "get_robot_uin_range";
3231
- schema = getRobotUinRangeSchema;
3232
- errorCodeMap = ob11ErrorCodeMap;
3233
- _handle(_payload) {
3234
- return Promise.resolve({
3235
- min: UIN_MIN,
3236
- max: UIN_MAX
3237
- });
3238
- }
3239
- };
2650
+ const getLoginInfoSchema = z.object({});
2651
+ const getVersionInfoSchema = z.object({});
2652
+ const getStatusSchema = z.object({});
2653
+ const getRobotUinRangeSchema = z.object({});
3240
2654
  const translateEn2ZhSchema = z.object({ words: z.array(z.string()).max(MAX_TRANSLATE_WORDS) });
3241
- /** 英文单词翻译(P2-14)。 */
3242
- var TranslateEn2ZhAction = class extends BaseAction {
3243
- name = "translate_en2zh";
3244
- schema = translateEn2ZhSchema;
3245
- errorCodeMap = ob11ErrorCodeMap;
3246
- richMediaApi;
3247
- constructor(richMediaApi) {
3248
- super();
3249
- this.richMediaApi = richMediaApi;
3250
- }
3251
- async _handle(payload) {
3252
- return { words: await this.richMediaApi.translateWords(payload.words) };
3253
- }
3254
- };
3255
2655
  /**
3256
2656
  * 系统信息域动作工厂(login_info / version_info / status / robot_uin_range /
3257
2657
  * translate_en2zh)。
3258
2658
  */
3259
2659
  function createSystemInfoActions(api) {
3260
2660
  return [
3261
- new GetLoginInfoAction(api.self),
3262
- new GetVersionInfoAction(api),
3263
- new GetStatusAction(),
3264
- new GetRobotUinRangeAction(),
3265
- new TranslateEn2ZhAction(api.richMediaApi)
2661
+ defineOb11Action({
2662
+ name: "get_login_info",
2663
+ schema: getLoginInfoSchema,
2664
+ handle: () => Promise.resolve({
2665
+ user_id: Number(api.self.uin),
2666
+ nickname: api.self.nickname
2667
+ })
2668
+ }),
2669
+ defineOb11Action({
2670
+ name: "get_version_info",
2671
+ schema: getVersionInfoSchema,
2672
+ handle: () => Promise.resolve({
2673
+ app_name: "napuketto-qq",
2674
+ app_version: api.appVersion,
2675
+ protocol_version: "v11"
2676
+ })
2677
+ }),
2678
+ defineOb11Action({
2679
+ name: "get_status",
2680
+ schema: getStatusSchema,
2681
+ handle: () => Promise.resolve({
2682
+ online: true,
2683
+ good: true
2684
+ })
2685
+ }),
2686
+ defineOb11Action({
2687
+ name: "get_robot_uin_range",
2688
+ schema: getRobotUinRangeSchema,
2689
+ handle: () => Promise.resolve({
2690
+ min: UIN_MIN,
2691
+ max: UIN_MAX
2692
+ })
2693
+ }),
2694
+ defineOb11Action({
2695
+ name: "translate_en2zh",
2696
+ schema: translateEn2ZhSchema,
2697
+ handle: async (payload) => {
2698
+ return { words: await api.richMediaApi.translateWords(payload.words) };
2699
+ }
2700
+ })
3266
2701
  ];
3267
2702
  }
3268
2703
  // src/onebot11/action/system/status.ts
3269
2704
  /**
3270
- * 系统状态与维护域动作(2026-11-14 自 set-online-status / set-diy-online-status /
3271
- * can-send-image / can-send-record / clean-cache / process-control 合并)
2705
+ * 系统状态与维护域动作
3272
2706
  *
3273
- * - set_online_status(P2-12):status/ext_status/battery_status 见 NapCat 状态表
2707
+ * - set_online_status:status/ext_status/battery_status 见 NapCat 状态表
3274
2708
  * (在线 10 / 离开 30 / 隐身 40 / 忙碌 50 / Q我吧 60 / 请勿打扰 70 等)
3275
- * - set_diy_online_status(P2-12):customStatus(faceId/wording/faceType)随
2709
+ * - set_diy_online_status:customStatus(faceId/wording/faceType)随
3276
2710
  * setStatus 一并提交;status 缺省 10(在线)
3277
- * - can_send_image / can_send_record(P2-11):本地恒 true
3278
- * - clean_cache(P2-11):cleanCache 回调由装配方注入(boot.cjs 接 kernel
2711
+ * - can_send_image / can_send_record:本地恒 true
2712
+ * - clean_cache:cleanCache 回调由装配方注入(boot.cjs 接 kernel
3279
2713
  * PathWrapper.clearCache),未配置时明确报错(不静默)
3280
- * - bot_exit / set_restart(P2-12):exit/restart 回调由装配方注入(boot.cjs 接
2714
+ * - bot_exit / set_restart:exit/restart 回调由装配方注入(boot.cjs 接
3281
2715
  * 进程控制),未配置时明确报错;重启缺省退化为退出
3282
2716
  */
2717
+ /** 默认在线状态值。 */
2718
+ const STATUS_ONLINE = 10;
3283
2719
  const setOnlineStatusSchema = z.object({
3284
2720
  status: z.number().optional(),
3285
2721
  ext_status: z.number().optional(),
3286
2722
  battery_status: z.number().optional()
3287
2723
  });
3288
- /** 默认在线状态值。 */
3289
- const STATUS_ONLINE = 10;
3290
- /** 设置在线状态(P2-12 接 kernel setOnlineStatus)。 */
3291
- var SetOnlineStatusAction = class extends BaseAction {
3292
- name = "set_online_status";
3293
- schema = setOnlineStatusSchema;
3294
- errorCodeMap = ob11ErrorCodeMap;
3295
- msgApi;
3296
- constructor(msgApi) {
3297
- super();
3298
- this.msgApi = msgApi;
3299
- }
3300
- async _handle(payload) {
3301
- await this.msgApi.setOnlineStatus({
3302
- status: payload.status ?? STATUS_ONLINE,
3303
- extStatus: payload.ext_status ?? 0,
3304
- batteryStatus: payload.battery_status ?? 0
3305
- });
3306
- return null;
3307
- }
3308
- };
3309
2724
  const setDiyOnlineStatusSchema = z.object({
3310
2725
  status: z.number().optional(),
3311
2726
  /** 自定义状态文案。 */
@@ -3315,126 +2730,95 @@ const setDiyOnlineStatusSchema = z.object({
3315
2730
  /** 表情类型。 */
3316
2731
  face_type: z.string().optional()
3317
2732
  });
3318
- /** 设置自定义在线状态(P2-12 接 kernel setOnlineStatus customStatus)。 */
3319
- var SetDiyOnlineStatusAction = class extends BaseAction {
3320
- name = "set_diy_online_status";
3321
- schema = setDiyOnlineStatusSchema;
3322
- errorCodeMap = ob11ErrorCodeMap;
3323
- msgApi;
3324
- constructor(msgApi) {
3325
- super();
3326
- this.msgApi = msgApi;
3327
- }
3328
- async _handle(payload) {
3329
- const customStatus = {
3330
- faceId: payload.face_id ?? "",
3331
- wording: payload.wording,
3332
- faceType: payload.face_type ?? "1"
3333
- };
3334
- await this.msgApi.setOnlineStatus({
3335
- status: payload.status ?? STATUS_ONLINE,
3336
- extStatus: 0,
3337
- batteryStatus: 0,
3338
- customStatus
3339
- });
3340
- return null;
3341
- }
3342
- };
3343
2733
  const canSendImageSchema = z.object({});
3344
- /** 是否可以发送图片(本地 true,P2-11)。 */
3345
- var CanSendImageAction = class extends BaseAction {
3346
- name = "can_send_image";
3347
- schema = canSendImageSchema;
3348
- errorCodeMap = ob11ErrorCodeMap;
3349
- _handle(_payload) {
3350
- return Promise.resolve({ yes: true });
3351
- }
3352
- };
3353
2734
  const canSendRecordSchema = z.object({});
3354
- /** 是否可以发送语音(本地 true,P2-11)。 */
3355
- var CanSendRecordAction = class extends BaseAction {
3356
- name = "can_send_record";
3357
- schema = canSendRecordSchema;
3358
- errorCodeMap = ob11ErrorCodeMap;
3359
- _handle(_payload) {
3360
- return Promise.resolve({ yes: true });
3361
- }
3362
- };
3363
2735
  const cleanCacheSchema = z.object({});
3364
- /** 清理缓存(P2-11)。 */
3365
- var CleanCacheAction = class extends BaseAction {
3366
- name = "clean_cache";
3367
- schema = cleanCacheSchema;
3368
- errorCodeMap = ob11ErrorCodeMap;
3369
- deps;
3370
- constructor(deps) {
3371
- super();
3372
- this.deps = deps;
3373
- }
3374
- async _handle(_payload) {
3375
- if (this.deps.cleanCache === void 0) throw kernelError("clean_cache 未配置(装配方未注入清理回调)", "INVALID_STATE");
3376
- await this.deps.cleanCache();
3377
- return null;
3378
- }
3379
- };
3380
2736
  const botExitSchema = z.object({});
3381
- /** 退出机器人进程(P2-12)。 */
3382
- var BotExitAction = class extends BaseAction {
3383
- name = "bot_exit";
3384
- schema = botExitSchema;
3385
- errorCodeMap = ob11ErrorCodeMap;
3386
- deps;
3387
- constructor(deps) {
3388
- super();
3389
- this.deps = deps;
3390
- }
3391
- async _handle(_payload) {
3392
- if (this.deps.exit === void 0) throw kernelError("bot_exit 未配置(装配方未注入退出回调)", "INVALID_STATE");
3393
- await this.deps.exit();
3394
- return null;
3395
- }
3396
- };
3397
- /** 重启机器人(P2-12;重启交给装配方,缺省退化为退出)。 */
3398
- var SetRestartAction = class extends BaseAction {
3399
- name = "set_restart";
3400
- schema = botExitSchema;
3401
- errorCodeMap = ob11ErrorCodeMap;
3402
- deps;
3403
- constructor(deps) {
3404
- super();
3405
- this.deps = deps;
3406
- }
3407
- async _handle(_payload) {
3408
- const restart = this.deps.restart ?? this.deps.exit;
3409
- if (restart === void 0) throw kernelError("set_restart 未配置(装配方未注入重启回调)", "INVALID_STATE");
3410
- await restart();
3411
- return null;
3412
- }
3413
- };
3414
2737
  /**
3415
2738
  * 系统状态与维护域动作工厂(set_online_status ×2 / can_send ×2 / clean_cache /
3416
2739
  * bot_exit / set_restart)。
3417
2740
  */
3418
2741
  function createSystemStatusActions(api) {
3419
2742
  return [
3420
- new SetOnlineStatusAction(api.msgApi),
3421
- new SetDiyOnlineStatusAction(api.msgApi),
3422
- new CanSendImageAction(),
3423
- new CanSendRecordAction(),
3424
- new CleanCacheAction(api),
3425
- new BotExitAction(api),
3426
- new SetRestartAction(api)
2743
+ defineOb11Action({
2744
+ name: "set_online_status",
2745
+ schema: setOnlineStatusSchema,
2746
+ handle: async (payload) => {
2747
+ await api.msgApi.setOnlineStatus({
2748
+ status: payload.status ?? STATUS_ONLINE,
2749
+ extStatus: payload.ext_status ?? 0,
2750
+ batteryStatus: payload.battery_status ?? 0
2751
+ });
2752
+ return null;
2753
+ }
2754
+ }),
2755
+ defineOb11Action({
2756
+ name: "set_diy_online_status",
2757
+ schema: setDiyOnlineStatusSchema,
2758
+ handle: async (payload) => {
2759
+ const customStatus = {
2760
+ faceId: payload.face_id ?? "",
2761
+ wording: payload.wording,
2762
+ faceType: payload.face_type ?? "1"
2763
+ };
2764
+ await api.msgApi.setOnlineStatus({
2765
+ status: payload.status ?? STATUS_ONLINE,
2766
+ extStatus: 0,
2767
+ batteryStatus: 0,
2768
+ customStatus
2769
+ });
2770
+ return null;
2771
+ }
2772
+ }),
2773
+ defineOb11Action({
2774
+ name: "can_send_image",
2775
+ schema: canSendImageSchema,
2776
+ handle: async () => ({ yes: true })
2777
+ }),
2778
+ defineOb11Action({
2779
+ name: "can_send_record",
2780
+ schema: canSendRecordSchema,
2781
+ handle: async () => ({ yes: true })
2782
+ }),
2783
+ defineOb11Action({
2784
+ name: "clean_cache",
2785
+ schema: cleanCacheSchema,
2786
+ handle: async () => {
2787
+ if (api.cleanCache === void 0) throw kernelError("clean_cache 未配置(装配方未注入清理回调)", "INVALID_STATE");
2788
+ await api.cleanCache();
2789
+ return null;
2790
+ }
2791
+ }),
2792
+ defineOb11Action({
2793
+ name: "bot_exit",
2794
+ schema: botExitSchema,
2795
+ handle: async () => {
2796
+ if (api.exit === void 0) throw kernelError("bot_exit 未配置(装配方未注入退出回调)", "INVALID_STATE");
2797
+ await api.exit();
2798
+ return null;
2799
+ }
2800
+ }),
2801
+ defineOb11Action({
2802
+ name: "set_restart",
2803
+ schema: botExitSchema,
2804
+ handle: async () => {
2805
+ const restart = api.restart ?? api.exit;
2806
+ if (restart === void 0) throw kernelError("set_restart 未配置(装配方未注入重启回调)", "INVALID_STATE");
2807
+ await restart();
2808
+ return null;
2809
+ }
2810
+ })
3427
2811
  ];
3428
2812
  }
3429
2813
  // src/onebot11/action/index.ts
3430
2814
  /**
3431
- * OneBot 11 动作注册表(ADR-013 延伸)
2815
+ * OneBot 11 动作注册表
3432
2816
  * 各协议维护自己的 ActionRegistry,由协议 adapter 挂到请求分发。
3433
- * P2-16:deps 收敛为 { api: OneBotApi } 单聚合对象(基础设施第一项)。
2817
+ * deps 收敛为 { api: OneBotApi } 单聚合对象。
3434
2818
  *
3435
- * 同时是 action 域 barrel:re-export error-map / resolve-uid / AtAllRemainInfo,
3436
- * 协议外部只从本入口消费动作面。动作类按领域分文件(message/ group/ friend/
3437
- * system/),各领域文件导出 create*Actions 工厂,此处遍历注册——新增动作在
2819
+ * 同时是 action 域 barrel:re-export ob11ErrorCodeMap / resolveUid(base-action)/
2820
+ * AtAllRemainInfo,协议外部只从本入口消费动作面。动作按领域分文件(message/ group/
2821
+ * friend/ system/),各领域文件导出 create*Actions 工厂,此处遍历注册——新增动作在
3438
2822
  * 领域文件的工厂里登记即可。
3439
2823
  */
3440
2824
  /** 全部领域工厂(18 个:message×5 + group×7 + friend×2 + system×4)。 */
@@ -3466,7 +2850,7 @@ function createOb11ActionRegistry(deps) {
3466
2850
  }
3467
2851
  // src/onebot11/api/one-bot-api.ts
3468
2852
  /**
3469
- * OneBot 11 动作统一依赖聚合(P2-16)。
2853
+ * OneBot 11 动作统一依赖聚合。
3470
2854
  * 各动作经 `Pick<OneBotApi, ...>` 取所需成员;注册处只构造一次本对象。
3471
2855
  */
3472
2856
  var OneBotApi = class {
@@ -3490,7 +2874,7 @@ var OneBotApi = class {
3490
2874
  profileLikeApi;
3491
2875
  /** kernel 群空间 web API(精华/荣誉用)。 */
3492
2876
  webApi;
3493
- /** 群/成员缓存(ADR-008;翻译层只读消费,缺失惰性回填)。 */
2877
+ /** 群/成员缓存(翻译层只读消费,缺失惰性回填)。 */
3494
2878
  groupCache;
3495
2879
  /** OB11 message_id ↔ NT msgId 双向映射(收链路与动作共用同一映射空间)。 */
3496
2880
  messageUnique;
@@ -3510,6 +2894,8 @@ var OneBotApi = class {
3510
2894
  exit;
3511
2895
  /** 进程重启回调(set_restart 用)。 */
3512
2896
  restart;
2897
+ /** 降级分支可观测出口(缺省静默)。 */
2898
+ logger;
3513
2899
  constructor(opts) {
3514
2900
  this.msgApi = opts.msgApi;
3515
2901
  this.groupApi = opts.groupApi;
@@ -3531,6 +2917,7 @@ var OneBotApi = class {
3531
2917
  this.mediaBaseDir = opts.system.mediaBaseDir;
3532
2918
  this.exit = opts.system.exit;
3533
2919
  this.restart = opts.system.restart;
2920
+ this.logger = opts.logger;
3534
2921
  }
3535
2922
  /**
3536
2923
  * uin→uid 转换(委托 groupApi;私聊目标/成员 user_id 用)。
@@ -3554,7 +2941,12 @@ var OneBotApi = class {
3554
2941
  try {
3555
2942
  const member = await this.groupCache.getMember(groupCode, uid);
3556
2943
  return member === void 0 ? void 0 : GroupApi.roleToString(member.role);
3557
- } catch {
2944
+ } catch (err) {
2945
+ this.logger?.warn({
2946
+ group: groupCode,
2947
+ uid,
2948
+ error: err instanceof Error ? err.message : String(err)
2949
+ }, "ob11: 群成员缓存读取失败,sender.role 回退 member");
3558
2950
  return;
3559
2951
  }
3560
2952
  }
@@ -3568,7 +2960,11 @@ var OneBotApi = class {
3568
2960
  const out = /* @__PURE__ */ new Map();
3569
2961
  for (const member of await this.groupCache.getMembers(groupCode)) out.set(member.uid, GroupApi.roleToString(member.role));
3570
2962
  return out;
3571
- } catch {
2963
+ } catch (err) {
2964
+ this.logger?.warn({
2965
+ group: groupCode,
2966
+ error: err instanceof Error ? err.message : String(err)
2967
+ }, "ob11: 群成员表缓存读取失败,历史 role 回退 member");
3572
2968
  return;
3573
2969
  }
3574
2970
  }
@@ -3587,7 +2983,11 @@ var Ob11Enrichment = class {
3587
2983
  if (uids.length === 0) return /* @__PURE__ */ new Map();
3588
2984
  try {
3589
2985
  return await this.api.uidToUin(uids);
3590
- } catch {
2986
+ } catch (err) {
2987
+ this.calibLogger?.warn({
2988
+ count: uids.length,
2989
+ error: err instanceof Error ? err.message : String(err)
2990
+ }, "ob11: 请求 uid→uin 批量转换失败,退用 uid");
3591
2991
  return /* @__PURE__ */ new Map();
3592
2992
  }
3593
2993
  }
@@ -3600,7 +3000,7 @@ var Ob11Enrichment = class {
3600
3000
  return this.api.uidToUin(uids);
3601
3001
  }
3602
3002
  /**
3603
- * 消息事件翻译上下文(P2-19:接收方向 ID 转换)。
3003
+ * 消息事件翻译上下文(接收方向 ID 转换)。
3604
3004
  * at uid → 一次批量 uidToUin;群消息另查发送者角色(GroupCache 缓存优先,
3605
3005
  * 失败回退缺省 member);msgId → OB11 id 经 messageUnique 反查。
3606
3006
  */
@@ -3609,7 +3009,12 @@ var Ob11Enrichment = class {
3609
3009
  let uidToUin;
3610
3010
  if (atUids.length > 0) try {
3611
3011
  uidToUin = await this.api.uidToUin(atUids);
3612
- } catch {}
3012
+ } catch (err) {
3013
+ this.calibLogger?.warn({
3014
+ count: atUids.length,
3015
+ error: err instanceof Error ? err.message : String(err)
3016
+ }, "ob11: 消息 at uid→uin 失败,at 原样");
3017
+ }
3613
3018
  const senderRole = msg.chatType === ChatType.GROUP ? await this.api.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
3614
3019
  return {
3615
3020
  ...uidToUin !== void 0 ? { uidToUin } : {},
@@ -3625,7 +3030,13 @@ var Ob11Enrichment = class {
3625
3030
  try {
3626
3031
  const map = await this.api.uidToUin(uids);
3627
3032
  return (uid) => Number(map.get(uid) ?? 0);
3628
- } catch {
3033
+ } catch (err) {
3034
+ this.calibLogger?.warn({
3035
+ msgType: env.msgType,
3036
+ subType: env.subType,
3037
+ count: uids.length,
3038
+ error: err instanceof Error ? err.message : String(err)
3039
+ }, "ob11: sysmsg uid→uin 失败,实体 uin 恒 0");
3629
3040
  return () => 0;
3630
3041
  }
3631
3042
  }
@@ -3639,7 +3050,13 @@ var Ob11Enrichment = class {
3639
3050
  chatType: ChatType.GROUP,
3640
3051
  peerUid: groupCode
3641
3052
  };
3642
- const hit = (await this.api.msgApi.fetchMessages(peer, { count: 60 }).catch(() => [])).find((m) => Number(m.msgSeq) === seq);
3053
+ const hit = (await this.api.msgApi.fetchMessages(peer, { count: 60 }).catch((err) => {
3054
+ this.calibLogger?.debug({
3055
+ group: groupCode,
3056
+ error: err instanceof Error ? err.message : String(err)
3057
+ }, "ob11: 精华反查近段历史拉取失败");
3058
+ return [];
3059
+ })).find((m) => Number(m.msgSeq) === seq);
3643
3060
  if (hit === void 0) {
3644
3061
  this.calibLogger?.warn({
3645
3062
  group: groupCode,
@@ -3799,7 +3216,7 @@ var Ob11InboundFileNotice = class {
3799
3216
  this.deps = deps;
3800
3217
  }
3801
3218
  /**
3802
- * 离线文件(c3,2026-09-10):Msg/onRecvOfflineFileMsg → OB11 offline_file
3219
+ * 离线文件(c3):Msg/onRecvOfflineFileMsg → OB11 offline_file
3803
3220
  * notice(payload 形状待校准:防御性收窄,未知形状 raw 日志积累)。
3804
3221
  */
3805
3222
  offlineFile(arg) {
@@ -3810,7 +3227,7 @@ var Ob11InboundFileNotice = class {
3810
3227
  }
3811
3228
  for (const item of items) this.deps.broadcast(toOfflineFileNotice(item, this.deps.selfUin));
3812
3229
  }
3813
- /** 在线文件:OB11 无对应通知类型;debug 级 raw 校准日志(2026-10-25)。 */
3230
+ /** 在线文件:OB11 无对应通知类型;debug 级 raw 校准日志。 */
3814
3231
  onlineFile(arg) {
3815
3232
  this.deps.logger?.debug({ raw: sliceRaw(JSON.stringify(arg)) }, "ob11: onRecvOnlineFileMsg raw(校准数据)");
3816
3233
  }
@@ -3818,7 +3235,7 @@ var Ob11InboundFileNotice = class {
3818
3235
  buddyList(evt, arg) {
3819
3236
  this.deps.logger?.info({ raw: truncRaw(JSON.stringify(arg)) }, `ob11: ${evt} raw(friend_add 校准数据)`);
3820
3237
  }
3821
- /** 好友缓存 diff 新增(B2,2026-09-08)→ friend_add notice(翻译纯函数)。 */
3238
+ /** 好友缓存 diff 新增()→ friend_add notice(翻译纯函数)。 */
3822
3239
  friendAdd(entry) {
3823
3240
  this.deps.broadcast(toFriendAdd(entry, this.deps.selfUin));
3824
3241
  }
@@ -3826,7 +3243,7 @@ var Ob11InboundFileNotice = class {
3826
3243
  // src/onebot11/helper/message-event.ts
3827
3244
  /** RawMessage → OB11 消息事件(message_id 经 MessageUnique 映射并记录 peer)。
3828
3245
  * messageFormat 决定 message 字段格式:array = 消息段数组(标准),string = CQ 码字符串。
3829
- * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
3246
+ * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id)。 */
3830
3247
  function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx = {}) {
3831
3248
  const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
3832
3249
  const segments = canonicalToSegments(elements);
@@ -3881,7 +3298,7 @@ var Ob11InboundMessage = class {
3881
3298
  deps;
3882
3299
  reportSelfMessage = false;
3883
3300
  messageFormat = "array";
3884
- /** 群文件报形式(B4):true = fileElement 群消息报 group_upload notice 替代 message。 */
3301
+ /** 群文件报形式():true = fileElement 群消息报 group_upload notice 替代 message。 */
3885
3302
  groupUploadAsNotice = false;
3886
3303
  constructor(deps) {
3887
3304
  this.deps = deps;
@@ -3908,10 +3325,10 @@ var Ob11InboundMessage = class {
3908
3325
  return;
3909
3326
  }
3910
3327
  }
3911
- this.broadcastMessageEvent(msg);
3328
+ this.broadcastMessageEvent(msg).catch((err) => logEventFailure(this.deps.logger, "ob11: message 事件翻译失败(单条丢弃)", err));
3912
3329
  }
3913
3330
  /**
3914
- * 广播消息事件(P2-19):回填 ctx 后交纯函数翻译;ID 转换在 enrichment 批量完成。
3331
+ * 广播消息事件:回填 ctx 后交纯函数翻译;ID 转换在 enrichment 批量完成。
3915
3332
  */
3916
3333
  async broadcastMessageEvent(msg) {
3917
3334
  const ctx = await this.deps.enrich.messageContext(msg);
@@ -3946,7 +3363,7 @@ var Ob11InboundRequest = class {
3946
3363
  }
3947
3364
  /** 好友申请 → friend request 事件(防御收窄;未知形状 raw warn 校准)。 */
3948
3365
  buddyReqs(arg) {
3949
- this.broadcastBuddyReqs(arg);
3366
+ this.broadcastBuddyReqs(arg).catch((err) => logEventFailure(this.deps.logger, "ob11: friend request 翻译失败(整批丢弃)", err));
3950
3367
  }
3951
3368
  /** 好友申请翻译派发(flag=reqTime;uid→uin 批量失败退空 Map)。 */
3952
3369
  async broadcastBuddyReqs(arg) {
@@ -3974,7 +3391,7 @@ function collectGroupNotifyUids(notifies) {
3974
3391
  }
3975
3392
  // src/onebot11/helper/sysmsg.ts
3976
3393
  /**
3977
- * OB11 sysmsg 识别表(2026-11-01 自 helper/sysmsg.ts 瘦身——解码层上移
3394
+ * OB11 sysmsg 识别表(自 helper/sysmsg.ts 瘦身——解码层上移
3978
3395
  * core/sysmsg.ts 共享,milky.md §0.8.3/§0.8.6)
3979
3396
  *
3980
3397
  * 本模块只保留 OB11 侧内容:
@@ -3991,7 +3408,7 @@ const NUMERIC_RE = /^\d+$/;
3991
3408
  /**
3992
3409
  * (msgType, subType) → 规则表(键 = 原生分发键,design.md §7.1)。
3993
3410
  *
3994
- * 2026-11-01 起不再是空表:732:21(群名片变更)为批次三轮录制取得的首个
3411
+ * 不再是空表:732:21(群名片变更)为轮录制取得的首个
3995
3412
  * 实证条目。card/title 等其余判别值仍无样本支撑,宁可漏报不错报;未识别
3996
3413
  * 一律走结构化校准日志,不广播。
3997
3414
  */
@@ -4028,7 +3445,7 @@ function recognizeOb11SysMsg(msgType, subType, table = KIND_TABLE) {
4028
3445
  }
4029
3446
  // src/onebot11/inbound/sysmsg.ts
4030
3447
  /**
4031
- * OB11 inbound sysmsg 域(2026-11-14 自 event-pipeline.ts 拆出)
3448
+ * OB11 inbound sysmsg 域(自 event-pipeline.ts 拆出)
4032
3449
  *
4033
3450
  * Msg/onRecvSysMsg 总闸:参数收窄(未知形状 raw warn)→ 单条字节块走
4034
3451
  * core/shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 → 信封 → 识别 →
@@ -4118,7 +3535,7 @@ var Ob11EventPipeline = class {
4118
3535
  const { msgChannel, groupChannel, friendChannel, buddyCacheEvents } = this.deps;
4119
3536
  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)));
4120
3537
  if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
4121
- this.request.groupNotifies(doubt, notifies);
3538
+ this.request.groupNotifies(doubt, notifies).catch((err) => logEventFailure(this.deps.logger, "ob11: group request 翻译失败(整批丢弃)", err));
4122
3539
  }), groupChannel.on("Group/onGroupEssenceListChange", (a) => this.essence.change(a)));
4123
3540
  if (friendChannel !== void 0) {
4124
3541
  this.unsubscribes.push(friendChannel.on("Buddy/onBuddyReqChange", (a) => this.request.buddyReqs(a)));
@@ -4133,7 +3550,7 @@ var Ob11EventPipeline = class {
4133
3550
  };
4134
3551
  // src/onebot11/transport.ts
4135
3552
  /**
4136
- * OB11 传输装配(P2-5,2026-08-05)
3553
+ * OB11 传输装配
4137
3554
  *
4138
3555
  * 按 OB11Config 创建/装配 network 传输适配器:
4139
3556
  * - HTTP 反向(http.enabled):HttpServer 接收第三方调用 → handleRequest → 响应
@@ -4147,8 +3564,8 @@ var Ob11EventPipeline = class {
4147
3564
  /** Authorization 头前缀。 */
4148
3565
  const BEARER_PREFIX = "Bearer ";
4149
3566
  /** 校验 URL 查询参数里的 access_token(WS client 连接 URL 可能带)。
4150
- * ⚠️ req.url 是纯路径(无 origin),new URL(相对路径) 必抛——2026-09-08
4151
- * T10 E2E 实测抓到的 bug(查询参数鉴权从未生效,WS 全被 4401 关闭),
3567
+ * ⚠️ req.url 是纯路径(无 origin),new URL(相对路径) 必抛——
3568
+ * E2E 实测抓到的 bug(查询参数鉴权从未生效,WS 全被 4401 关闭),
4152
3569
  * 用 dummy base 解析。 */
4153
3570
  function hasAccessTokenQuery(url, token) {
4154
3571
  try {
@@ -4283,7 +3700,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4283
3700
  oneBotApi;
4284
3701
  /** 动作注册表(公共只读:IPC 桥等装配方枚举动作名直接挂载)。 */
4285
3702
  registry;
4286
- /** 收链路事件管道(订阅 / 过滤 / 翻译派发,2026-11-14 拆出)。 */
3703
+ /** 收链路事件管道(订阅 / 过滤 / 翻译派发,拆出)。 */
4287
3704
  pipeline;
4288
3705
  transports = null;
4289
3706
  heartbeatTimer = null;
@@ -4314,7 +3731,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4314
3731
  this.registry = createOb11ActionRegistry({ api: this.oneBotApi });
4315
3732
  }
4316
3733
  /**
4317
- * 配置热更新(P2-6,2026-09-08 实现):stop 旧传输/心跳/退订 → 按新配置重建。
3734
+ * 配置热更新(实现):stop 旧传输/心跳/退订 → 按新配置重建。
4318
3735
  * IPC 桥模式(subscribeOnly,无传输)只刷新上报开关字段,不重建。
4319
3736
  */
4320
3737
  async reloadTransports(config) {
@@ -4391,7 +3808,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4391
3808
  }
4392
3809
  }
4393
3810
  /**
4394
- * 仅启动接收链路(IPC 桥模式,2026-08-27):订阅消息通道维护 messageUnique +
3811
+ * 仅启动接收链路(IPC 桥模式):订阅消息通道维护 messageUnique +
4395
3812
  * 灰色通知翻译;与 start() 的差别仅在传输层(无 HTTP/WS、无心跳、无 lifecycle)。
4396
3813
  * 配置经 seed 装配(load() 返回内存初值)。
4397
3814
  */