@napuketto/adapter 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { _ as prepareVideoElements, a as extractSysMsgEnvelope, b as BaseAction, c as narrowSysMsgBlobs, f as toHex, g as ensureSilk, r as decodeProtoTree, t as toUnixSeconds, u as recognizeSysMsg, x as ActionRegistry, y as BaseProtocolAdapter } from "../core-Be1hDKmc.mjs";
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
2
  import { n as senderNickname, r as subscribeRawMessages } from "../raw-message-D2vA27kj.mjs";
3
- import { i as narrowBuddyReqs, n as extractEssenceSetSysMsg, r as narrowEssenceGroupArg, t as EssenceListSync } from "../essence-BP3LE1Bm.mjs";
4
- import { i as MS_TO_SEC$3, n as firstUntranslatedGrayTip, o as toUin, r as hasGrayTip, t as collectGrayTipUids } from "../gray-tip-CitrbUCZ.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
5
  import { n as createWsServerSchema, t as createHttpServerSchema } from "../transport-schema-BEzr06W3.mjs";
6
6
  import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, kernelError, toCanonicalElements } from "@napuketto/kernel";
7
7
  import { basename, join } from "node:path";
@@ -1869,7 +1869,7 @@ function toOb11MessageInfo(msg, unique, ctx = {}) {
1869
1869
  }
1870
1870
  // src/onebot11/helper/notice.ts
1871
1871
  /** 毫秒 → 秒(Unix 时间戳)。 */
1872
- const MS_TO_SEC$2 = 1e3;
1872
+ const MS_TO_SEC$1 = 1e3;
1873
1873
  /** 群文件业务类型(group_upload 的 file.busid,与 kernel 群文件系列同源语义)。 */
1874
1874
  const GROUP_FILE_BUS_ID = 102;
1875
1875
  /**
@@ -2023,7 +2023,7 @@ function toBan(common, grp, ctx) {
2023
2023
  function toFriendAdd(entry, selfUin) {
2024
2024
  const uin = entry.coreInfo?.uin ?? entry.uin ?? "";
2025
2025
  return {
2026
- time: Math.floor(Date.now() / MS_TO_SEC$2),
2026
+ time: Math.floor(Date.now() / MS_TO_SEC$1),
2027
2027
  self_id: Number(selfUin),
2028
2028
  post_type: "notice",
2029
2029
  notice_type: "friend_add",
@@ -2118,7 +2118,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2118
2118
  default: return null;
2119
2119
  }
2120
2120
  return {
2121
- time: Math.floor(Date.now() / MS_TO_SEC$3),
2121
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
2122
2122
  self_id: Number(ctx.selfUin),
2123
2123
  post_type: "request",
2124
2124
  request_type: "group",
@@ -2136,7 +2136,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2136
2136
  function toOb11FriendRequestEvent(req, ctx) {
2137
2137
  const words = req["words"];
2138
2138
  return {
2139
- time: Math.floor(Date.now() / MS_TO_SEC$3),
2139
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
2140
2140
  self_id: Number(ctx.selfUin),
2141
2141
  post_type: "request",
2142
2142
  request_type: "friend",
@@ -3621,61 +3621,154 @@ var OneBotApi = class {
3621
3621
  }
3622
3622
  }
3623
3623
  };
3624
- // src/onebot11/helper/message-event.ts
3625
- /** RawMessage → OB11 消息事件(message_id 经 MessageUnique 映射并记录 peer)。
3626
- * messageFormat 决定 message 字段格式:array = 消息段数组(标准),string = CQ 码字符串。
3627
- * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
3628
- function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx = {}) {
3629
- const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
3630
- const segments = canonicalToSegments(elements);
3631
- const time = toUnixSeconds(msg.msgTime);
3632
- const selfId = Number(selfUin);
3633
- const userId = Number(msg.senderUin);
3634
- const base = {
3635
- time,
3636
- self_id: selfId,
3637
- post_type: "message",
3638
- message_id: unique.alloc(msg.msgId, {
3639
- chatType: msg.chatType,
3640
- peerUid: msg.peerUid
3641
- }),
3642
- message: messageFormat === "string" ? canonicalToCqMessage(elements) : segments,
3643
- raw_message: canonicalToCqMessage(elements),
3644
- font: 0
3645
- };
3646
- if (msg.chatType === ChatType.GROUP) {
3647
- const sender = {
3648
- user_id: userId,
3649
- nickname: senderNickname(msg),
3650
- role: ctx.senderRole ?? "member"
3651
- };
3652
- if (msg.sendMemberName !== void 0) sender.card = msg.sendMemberName;
3624
+ // src/onebot11/enrichment.ts
3625
+ /** OB11 收链路异步回填器。 */
3626
+ var Ob11Enrichment = class {
3627
+ api;
3628
+ calibLogger;
3629
+ constructor(deps) {
3630
+ this.api = deps.api;
3631
+ this.calibLogger = deps.logger;
3632
+ }
3633
+ /** uid 批量 → uin(失败退空 Map:翻译层退化为 uid 数值,不阻塞请求上报)。 */
3634
+ async uidToUinMap(uids) {
3635
+ if (uids.length === 0) return /* @__PURE__ */ new Map();
3636
+ try {
3637
+ return await this.api.uidToUin(uids);
3638
+ } catch {
3639
+ return /* @__PURE__ */ new Map();
3640
+ }
3641
+ }
3642
+ /**
3643
+ * notice uid 批量转换(空集退空 Map)。失败上抛不吞:grayTip 解析宽容但
3644
+ * uid 查询炸掉时整个 notice 丢弃(与原 adapter 行为一致,调用方 catch)。
3645
+ */
3646
+ async noticeUidMap(uids) {
3647
+ if (uids.length === 0) return /* @__PURE__ */ new Map();
3648
+ return this.api.uidToUin(uids);
3649
+ }
3650
+ /**
3651
+ * 消息事件翻译上下文(P2-19:接收方向 ID 转换)。
3652
+ * at uid → 一次批量 uidToUin;群消息另查发送者角色(GroupCache 缓存优先,
3653
+ * 失败回退缺省 member);msgId → OB11 id 经 messageUnique 反查。
3654
+ */
3655
+ async messageContext(msg) {
3656
+ const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
3657
+ let uidToUin;
3658
+ if (atUids.length > 0) try {
3659
+ uidToUin = await this.api.uidToUin(atUids);
3660
+ } catch {}
3661
+ const senderRole = msg.chatType === ChatType.GROUP ? await this.api.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
3653
3662
  return {
3654
- ...base,
3655
- message_type: "group",
3656
- sub_type: "normal",
3657
- group_id: Number(msg.peerUid),
3658
- user_id: userId,
3659
- sender
3663
+ ...uidToUin !== void 0 ? { uidToUin } : {},
3664
+ ...senderRole !== void 0 ? { senderRole } : {},
3665
+ msgIdToOb11Id: (msgId) => this.api.messageUnique.getMessageId(msgId)
3660
3666
  };
3661
3667
  }
3662
- let subType = "friend";
3663
- if (msg.chatType === ChatType.C2C_TEMP) subType = "group";
3664
- const sender = {
3665
- user_id: userId,
3666
- nickname: senderNickname(msg)
3667
- };
3668
- return {
3669
- ...base,
3670
- message_type: "private",
3671
- sub_type: subType,
3672
- user_id: userId,
3673
- sender
3674
- };
3675
- }
3668
+ /** sysmsg 规则的 uid→uin 解析器(collectUids 声明才批量转换;失败/缺省恒 0)。 */
3669
+ async sysMsgUinResolver(rule, tree, env) {
3670
+ if (rule.collectUids === void 0) return () => 0;
3671
+ const uids = rule.collectUids(tree, env).filter((uid) => uid !== "");
3672
+ if (uids.length === 0) return () => 0;
3673
+ try {
3674
+ const map = await this.api.uidToUin(uids);
3675
+ return (uid) => Number(map.get(uid) ?? 0);
3676
+ } catch {
3677
+ return () => 0;
3678
+ }
3679
+ }
3680
+ /**
3681
+ * 精华 message_id 反查:msgSeq → 近段历史扫描(60 条,对齐 milky
3682
+ * resolveMsgIdBySeq fallback 层)→ MessageUnique.alloc 幂等分配(可被 get_msg
3683
+ * 反查的正确空间,对照 recall 的 msgSeq 错位)。未命中返回 null(跳过事件)。
3684
+ */
3685
+ async resolveEssenceMsgId(groupCode, seq) {
3686
+ const peer = {
3687
+ chatType: ChatType.GROUP,
3688
+ peerUid: groupCode
3689
+ };
3690
+ const hit = (await this.api.msgApi.fetchMessages(peer, { count: 60 }).catch(() => [])).find((m) => Number(m.msgSeq) === seq);
3691
+ if (hit === void 0) {
3692
+ this.calibLogger?.warn({
3693
+ group: groupCode,
3694
+ seq
3695
+ }, "ob11: 精华 message_id 反查未命中(跳过事件)");
3696
+ return null;
3697
+ }
3698
+ return this.api.messageUnique.alloc(hit.msgId, peer);
3699
+ }
3700
+ };
3701
+ // src/onebot11/inbound/essence.ts
3702
+ /** OB11 精华域处理器(串行 diff 同步 + group_essence notice 广播)。 */
3703
+ var Ob11InboundEssence = class {
3704
+ deps;
3705
+ essenceSync;
3706
+ constructor(deps) {
3707
+ this.deps = deps;
3708
+ this.essenceSync = new EssenceListSync({
3709
+ fetchList: (groupCode) => deps.api.webApi.getEssenceMsgList(groupCode),
3710
+ onAdded: (groupCode, added) => this.broadcastDiff(groupCode, added, "add"),
3711
+ onRemoved: (groupCode, removed, prev) => this.broadcastDiff(groupCode, removed.map((seq) => ({
3712
+ messageSeq: seq,
3713
+ senderUin: prev.get(seq)?.senderUin ?? null,
3714
+ operatorUin: null,
3715
+ addDigestTime: null
3716
+ })), "delete"),
3717
+ onFetchError: (g, err) => deps.logger?.warn({
3718
+ group: g,
3719
+ err: String(err)
3720
+ }, "ob11: 精华列表拉取失败(diff 跳过)")
3721
+ });
3722
+ }
3723
+ /** sysmsg 732:1 加速触发器:抽取群号踢入串行链(抽取失败 → false 落校准路径)。 */
3724
+ triggerFromSysMsg(tree) {
3725
+ const hit = extractEssenceSetSysMsg(tree);
3726
+ if (hit === null) return false;
3727
+ this.essenceSync.enqueue(String(hit.groupCode));
3728
+ return true;
3729
+ }
3730
+ /** 精华列表变更:拉全量列表 diff(唯一发射路径;参数收窄失败走校准日志)。 */
3731
+ change(arg) {
3732
+ const groupCode = narrowEssenceGroupArg(arg);
3733
+ if (groupCode === null) {
3734
+ this.deps.logger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onGroupEssenceListChange 未知参数形状");
3735
+ return;
3736
+ }
3737
+ this.essenceSync.enqueue(groupCode);
3738
+ }
3739
+ /** diff 逐条广播(add/delete 共用):sender 必填 → message_id 反查 → notice 装配。 */
3740
+ async broadcastDiff(groupCode, items, subType) {
3741
+ const { enrich, broadcast, selfUin } = this.deps;
3742
+ for (const item of items) {
3743
+ const senderId = numericUin(item.senderUin);
3744
+ if (senderId === null) {
3745
+ const detail = subType === "add" ? "新增 sender_uin 缺失" : "移除 sender 不可得";
3746
+ this.deps.logger?.warn({
3747
+ group: groupCode,
3748
+ seq: item.messageSeq
3749
+ }, `ob11: 精华${detail}(跳过事件)`);
3750
+ continue;
3751
+ }
3752
+ const messageId = await enrich.resolveEssenceMsgId(groupCode, item.messageSeq);
3753
+ if (messageId === null) continue;
3754
+ const operatorId = numericUin(item.operatorUin);
3755
+ broadcast({
3756
+ time: item.addDigestTime ?? Math.floor(Date.now() / 1e3),
3757
+ self_id: Number(selfUin),
3758
+ post_type: "notice",
3759
+ notice_type: "group_essence",
3760
+ sub_type: subType,
3761
+ group_id: Number(groupCode),
3762
+ sender_id: senderId,
3763
+ ...operatorId !== null ? { operator_id: operatorId } : {},
3764
+ message_id: messageId
3765
+ });
3766
+ }
3767
+ }
3768
+ };
3676
3769
  // src/onebot11/helper/notice-extra.ts
3677
3770
  /** 毫秒 → 秒(Unix 时间戳)。 */
3678
- const MS_TO_SEC$1 = 1e3;
3771
+ const MS_TO_SEC = 1e3;
3679
3772
  /** 候选 uin 字段(按优先级取第一个数字串;uid 串不硬转——待校准)。 */
3680
3773
  function pickUin(item) {
3681
3774
  for (const key of [
@@ -3734,7 +3827,7 @@ function narrowOfflineFiles(arg) {
3734
3827
  /** 归一化项 → OB11 offline_file notice(time 取当前时刻,friend_add 同款)。 */
3735
3828
  function toOfflineFileNotice(item, selfUin) {
3736
3829
  return {
3737
- time: Math.floor(Date.now() / MS_TO_SEC$1),
3830
+ time: Math.floor(Date.now() / MS_TO_SEC),
3738
3831
  self_id: Number(selfUin),
3739
3832
  post_type: "notice",
3740
3833
  notice_type: "offline_file",
@@ -3746,6 +3839,187 @@ function toOfflineFileNotice(item, selfUin) {
3746
3839
  }
3747
3840
  };
3748
3841
  }
3842
+ // src/onebot11/inbound/file-notice.ts
3843
+ /** OB11 轻量通知域处理器(文件 / 好友新增等无独立翻译链的通知)。 */
3844
+ var Ob11InboundFileNotice = class {
3845
+ deps;
3846
+ constructor(deps) {
3847
+ this.deps = deps;
3848
+ }
3849
+ /**
3850
+ * 离线文件(c3,2026-09-10):Msg/onRecvOfflineFileMsg → OB11 offline_file
3851
+ * notice(payload 形状待校准:防御性收窄,未知形状 raw 日志积累)。
3852
+ */
3853
+ offlineFile(arg) {
3854
+ const items = narrowOfflineFiles(arg);
3855
+ if (items === null) {
3856
+ this.deps.logger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvOfflineFileMsg 未知参数形状");
3857
+ return;
3858
+ }
3859
+ for (const item of items) this.deps.broadcast(toOfflineFileNotice(item, this.deps.selfUin));
3860
+ }
3861
+ /** 在线文件:OB11 无对应通知类型;debug 级 raw 校准日志(2026-10-25)。 */
3862
+ onlineFile(arg) {
3863
+ this.deps.logger?.debug({ raw: sliceRaw(JSON.stringify(arg)) }, "ob11: onRecvOnlineFileMsg raw(校准数据)");
3864
+ }
3865
+ /** 好友列表变化:快照字段较多,raw 日志保留积累校准数据(翻译走 friendAdd)。 */
3866
+ buddyList(evt, arg) {
3867
+ this.deps.logger?.info({ raw: truncRaw(JSON.stringify(arg)) }, `ob11: ${evt} raw(friend_add 校准数据)`);
3868
+ }
3869
+ /** 好友缓存 diff 新增(B2,2026-09-08)→ friend_add notice(翻译纯函数)。 */
3870
+ friendAdd(entry) {
3871
+ this.deps.broadcast(toFriendAdd(entry, this.deps.selfUin));
3872
+ }
3873
+ };
3874
+ // src/onebot11/helper/message-event.ts
3875
+ /** RawMessage → OB11 消息事件(message_id 经 MessageUnique 映射并记录 peer)。
3876
+ * messageFormat 决定 message 字段格式:array = 消息段数组(标准),string = CQ 码字符串。
3877
+ * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
3878
+ function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx = {}) {
3879
+ const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
3880
+ const segments = canonicalToSegments(elements);
3881
+ const time = toUnixSeconds(msg.msgTime);
3882
+ const selfId = Number(selfUin);
3883
+ const userId = Number(msg.senderUin);
3884
+ const base = {
3885
+ time,
3886
+ self_id: selfId,
3887
+ post_type: "message",
3888
+ message_id: unique.alloc(msg.msgId, {
3889
+ chatType: msg.chatType,
3890
+ peerUid: msg.peerUid
3891
+ }),
3892
+ message: messageFormat === "string" ? canonicalToCqMessage(elements) : segments,
3893
+ raw_message: canonicalToCqMessage(elements),
3894
+ font: 0
3895
+ };
3896
+ if (msg.chatType === ChatType.GROUP) {
3897
+ const sender = {
3898
+ user_id: userId,
3899
+ nickname: senderNickname(msg),
3900
+ role: ctx.senderRole ?? "member"
3901
+ };
3902
+ if (msg.sendMemberName !== void 0) sender.card = msg.sendMemberName;
3903
+ return {
3904
+ ...base,
3905
+ message_type: "group",
3906
+ sub_type: "normal",
3907
+ group_id: Number(msg.peerUid),
3908
+ user_id: userId,
3909
+ sender
3910
+ };
3911
+ }
3912
+ let subType = "friend";
3913
+ if (msg.chatType === ChatType.C2C_TEMP) subType = "group";
3914
+ const sender = {
3915
+ user_id: userId,
3916
+ nickname: senderNickname(msg)
3917
+ };
3918
+ return {
3919
+ ...base,
3920
+ message_type: "private",
3921
+ sub_type: subType,
3922
+ user_id: userId,
3923
+ sender
3924
+ };
3925
+ }
3926
+ // src/onebot11/inbound/message.ts
3927
+ /** OB11 消息域处理器(Msg/onRecvMsg 分流与翻译派发)。 */
3928
+ var Ob11InboundMessage = class {
3929
+ deps;
3930
+ reportSelfMessage = false;
3931
+ messageFormat = "array";
3932
+ /** 群文件报形式(B4):true = fileElement 群消息报 group_upload notice 替代 message。 */
3933
+ groupUploadAsNotice = false;
3934
+ constructor(deps) {
3935
+ this.deps = deps;
3936
+ }
3937
+ /** 刷新收链路开关(start / subscribeOnly / reload 共用)。 */
3938
+ applyConfig(config) {
3939
+ this.reportSelfMessage = config.reportSelfMessage;
3940
+ this.messageFormat = config.messagePostFormat;
3941
+ this.groupUploadAsNotice = config.groupUploadAsNotice;
3942
+ }
3943
+ /** 单条收向消息:grayTip→notice / 自消息过滤 / 群文件开关 / message 事件。 */
3944
+ handleRawMessage(msg) {
3945
+ if (hasGrayTip(msg)) {
3946
+ this.broadcastNotice(msg).catch((err) => {
3947
+ this.deps.logger?.debug({ err: err instanceof Error ? err.message : String(err) }, "ob11: notice 翻译失败(整个事件丢弃)");
3948
+ });
3949
+ return;
3950
+ }
3951
+ if (!this.reportSelfMessage && String(msg.senderUin) === this.deps.selfUin) return;
3952
+ if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement(msg)) {
3953
+ const notice = toGroupUpload(msg, this.deps.selfUin);
3954
+ if (notice !== null) {
3955
+ this.deps.broadcast(notice);
3956
+ return;
3957
+ }
3958
+ }
3959
+ this.broadcastMessageEvent(msg);
3960
+ }
3961
+ /**
3962
+ * 广播消息事件(P2-19):回填 ctx 后交纯函数翻译;ID 转换在 enrichment 批量完成。
3963
+ */
3964
+ async broadcastMessageEvent(msg) {
3965
+ const ctx = await this.deps.enrich.messageContext(msg);
3966
+ this.deps.broadcast(toOb11MessageEvent(msg, this.deps.selfUin, this.deps.api.messageUnique, this.messageFormat, ctx));
3967
+ }
3968
+ /** 广播 grayTip → notice 事件(批量 uidToUin 后翻译,纯函数)。 */
3969
+ async broadcastNotice(msg) {
3970
+ const uidToUin = await this.deps.enrich.noticeUidMap(collectGrayTipUids(msg));
3971
+ const notice = toOb11NoticeEvent(msg, {
3972
+ selfUin: this.deps.selfUin,
3973
+ uidToUin,
3974
+ ...this.deps.logger !== void 0 ? { logger: this.deps.logger } : {}
3975
+ });
3976
+ if (notice !== null) this.deps.broadcast(notice);
3977
+ }
3978
+ };
3979
+ // src/onebot11/inbound/request.ts
3980
+ /** OB11 请求域处理器(群通知 / 好友申请的 uid 回填与广播)。 */
3981
+ var Ob11InboundRequest = class {
3982
+ deps;
3983
+ constructor(deps) {
3984
+ this.deps = deps;
3985
+ }
3986
+ /** 群系统通知 → group request 事件(批量 uidToUin 后翻译,纯函数)。 */
3987
+ async groupNotifies(doubt, notifies) {
3988
+ if (doubt || !Array.isArray(notifies)) return;
3989
+ const ctx = await this.requestCtx(collectGroupNotifyUids(notifies));
3990
+ for (const notify of notifies) {
3991
+ const event = toOb11GroupRequestEvent(notify, ctx);
3992
+ if (event !== null) this.deps.broadcast(event);
3993
+ }
3994
+ }
3995
+ /** 好友申请 → friend request 事件(防御收窄;未知形状 raw warn 校准)。 */
3996
+ buddyReqs(arg) {
3997
+ this.broadcastBuddyReqs(arg);
3998
+ }
3999
+ /** 好友申请翻译派发(flag=reqTime;uid→uin 批量失败退空 Map)。 */
4000
+ async broadcastBuddyReqs(arg) {
4001
+ const reqs = narrowBuddyReqs(arg);
4002
+ if (reqs === null) {
4003
+ this.deps.logger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onBuddyReqChange 未知参数形状");
4004
+ return;
4005
+ }
4006
+ const ctx = await this.requestCtx(reqs.map((r) => r.friendUid).filter((uid) => uid !== ""));
4007
+ for (const req of reqs) this.deps.broadcast(toOb11FriendRequestEvent(req, ctx));
4008
+ }
4009
+ /** request 翻译上下文(uid→uin 批量;失败退空 Map 不阻塞上报)。 */
4010
+ async requestCtx(uids) {
4011
+ return {
4012
+ selfUin: this.deps.selfUin,
4013
+ uidToUin: await this.deps.enrich.uidToUinMap(uids)
4014
+ };
4015
+ }
4016
+ };
4017
+ /** 收集群系统通知涉及的 uid(user1/user2 双方,空 uid 跳过)。 */
4018
+ function collectGroupNotifyUids(notifies) {
4019
+ const uids = [];
4020
+ for (const notify of notifies) for (const user of [notify.user1, notify.user2]) if (typeof user?.uid === "string" && user.uid !== "") uids.push(user.uid);
4021
+ return uids;
4022
+ }
3749
4023
  // src/onebot11/helper/sysmsg.ts
3750
4024
  /**
3751
4025
  * OB11 sysmsg 识别表(2026-11-01 自 helper/sysmsg.ts 瘦身——解码层上移
@@ -3761,7 +4035,7 @@ function toOfflineFileNotice(item, selfUin) {
3761
4035
  * 从 `core/shared/sysmsg.js` 导入使用。
3762
4036
  */
3763
4037
  /** 群号判别(strings[0] 必须是数字串)。 */
3764
- const NUMERIC_RE$1 = /^\d+$/;
4038
+ const NUMERIC_RE = /^\d+$/;
3765
4039
  /**
3766
4040
  * (msgType, subType) → 规则表(键 = 原生分发键,design.md §7.1)。
3767
4041
  *
@@ -3777,7 +4051,7 @@ const KIND_TABLE = /* @__PURE__ */ new Map([["732:21", {
3777
4051
  },
3778
4052
  extract: (_tree, env, uinOf, ctx) => {
3779
4053
  const [groupCode, subject, cardNew, cardOld] = env.strings;
3780
- if (groupCode === void 0 || subject === void 0 || !NUMERIC_RE$1.test(groupCode) || !subject.startsWith("u_")) return null;
4054
+ if (groupCode === void 0 || subject === void 0 || !NUMERIC_RE.test(groupCode) || !subject.startsWith("u_")) return null;
3781
4055
  return {
3782
4056
  time: ctx.time,
3783
4057
  self_id: ctx.selfUin,
@@ -3800,6 +4074,111 @@ const OBSERVED_UNNAMED = /* @__PURE__ */ new Set([
3800
4074
  function recognizeOb11SysMsg(msgType, subType, table = KIND_TABLE) {
3801
4075
  return recognizeSysMsg(msgType, subType, table, OBSERVED_UNNAMED);
3802
4076
  }
4077
+ // src/onebot11/inbound/sysmsg.ts
4078
+ /**
4079
+ * OB11 inbound sysmsg 域(2026-11-14 自 event-pipeline.ts 拆出)
4080
+ *
4081
+ * Msg/onRecvSysMsg 总闸:参数收窄(未知形状 raw warn)→ 单条字节块走
4082
+ * core/shared/sysmsg.ts 的 processSysMsgBlob 通用管线(解码 → 信封 → 识别 →
4083
+ * 分流)。表命中做两件事:732:1 精华加速触发器(表外,踢入 essence 域的串行
4084
+ * diff 链)与识别表规则广播(uid→uin 经 enrichment 批量回填后 extract);
4085
+ * 未识别 / 提取失败落校准路径,不广播半成品。
4086
+ */
4087
+ /** OB11 sysmsg 域处理器(解码识别分流 + 精华触发器)。 */
4088
+ var Ob11InboundSysMsg = class {
4089
+ deps;
4090
+ constructor(deps) {
4091
+ this.deps = deps;
4092
+ }
4093
+ /** onRecvSysMsg 总闸:参数收窄(未知形状 raw warn)→ 逐块走通用管线。 */
4094
+ handleRawArg(arg) {
4095
+ const blobs = narrowSysMsgBlobs(arg);
4096
+ if (blobs === null) {
4097
+ this.deps.logger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvSysMsg 未知参数形状");
4098
+ return;
4099
+ }
4100
+ for (const blob of blobs) processSysMsgBlob(blob, {
4101
+ scope: "ob11",
4102
+ logger: this.deps.logger,
4103
+ decodeFailLevel: "warn",
4104
+ recognize: (msgType, subType) => recognizeOb11SysMsg(msgType, subType),
4105
+ onNotice: (tree, env, rec) => this.handleRecognized(tree, env, rec)
4106
+ });
4107
+ }
4108
+ /**
4109
+ * 已解码 sysmsg 分流(732:1 精华触发器 / 识别表规则广播);返回 true =
4110
+ * 已消费。提取失败返回 false 落入校准路径(不硬广播半成品事件)。
4111
+ */
4112
+ async handleRecognized(tree, env, rec) {
4113
+ if (env.msgType === 732 && env.subType === 1 && this.deps.essence.triggerFromSysMsg(tree)) return true;
4114
+ if (rec.kind !== "notice") return false;
4115
+ const uinOf = await this.deps.enrich.sysMsgUinResolver(rec.rule, tree, env);
4116
+ const ctx = {
4117
+ selfUin: Number(this.deps.selfUin),
4118
+ time: env.time ?? Math.floor(Date.now() / 1e3)
4119
+ };
4120
+ const event = rec.rule.extract(tree, env, uinOf, ctx);
4121
+ if (event === null) return false;
4122
+ this.deps.broadcast(event);
4123
+ return true;
4124
+ }
4125
+ };
4126
+ // src/onebot11/event-pipeline.ts
4127
+ var Ob11EventPipeline = class {
4128
+ deps;
4129
+ essence;
4130
+ message;
4131
+ sysMsg;
4132
+ request;
4133
+ fileNotice;
4134
+ unsubscribes = [];
4135
+ constructor(deps) {
4136
+ this.deps = deps;
4137
+ const enrich = new Ob11Enrichment({
4138
+ api: deps.api,
4139
+ logger: deps.logger
4140
+ });
4141
+ this.essence = new Ob11InboundEssence({
4142
+ ...deps,
4143
+ enrich
4144
+ });
4145
+ this.message = new Ob11InboundMessage({
4146
+ ...deps,
4147
+ enrich
4148
+ });
4149
+ this.sysMsg = new Ob11InboundSysMsg({
4150
+ ...deps,
4151
+ enrich,
4152
+ essence: this.essence
4153
+ });
4154
+ this.request = new Ob11InboundRequest({
4155
+ ...deps,
4156
+ enrich
4157
+ });
4158
+ this.fileNotice = new Ob11InboundFileNotice(deps);
4159
+ }
4160
+ applyConfig(config) {
4161
+ this.message.applyConfig(config);
4162
+ }
4163
+ /** 订阅 kernel 事件(消息 + 群 + 好友 + 好友缓存,幂等;路由到 inbound/)。 */
4164
+ subscribe() {
4165
+ if (this.unsubscribes.length > 0) return;
4166
+ const { msgChannel, groupChannel, friendChannel, buddyCacheEvents } = this.deps;
4167
+ 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)));
4168
+ if (groupChannel !== void 0) this.unsubscribes.push(groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
4169
+ this.request.groupNotifies(doubt, notifies);
4170
+ }), groupChannel.on("Group/onGroupEssenceListChange", (a) => this.essence.change(a)));
4171
+ if (friendChannel !== void 0) {
4172
+ this.unsubscribes.push(friendChannel.on("Buddy/onBuddyReqChange", (a) => this.request.buddyReqs(a)));
4173
+ for (const evt of ["Buddy/onBuddyListChange", "Buddy/onBuddyListChangedV2"]) this.unsubscribes.push(friendChannel.on(evt, (a) => this.fileNotice.buddyList(evt, a)));
4174
+ }
4175
+ if (buddyCacheEvents !== void 0) this.unsubscribes.push(buddyCacheEvents.on("BuddyCache/onBuddyAdded", (e) => this.fileNotice.friendAdd(e)));
4176
+ }
4177
+ unsubscribeAll() {
4178
+ for (const off of this.unsubscribes) off();
4179
+ this.unsubscribes = [];
4180
+ }
4181
+ };
3803
4182
  // src/onebot11/transport.ts
3804
4183
  /**
3805
4184
  * OB11 传输装配(P2-5,2026-08-05)
@@ -3945,48 +4324,19 @@ function authorizeHeader(token) {
3945
4324
  return { authorization: `${BEARER_PREFIX}${token}` };
3946
4325
  }
3947
4326
  // src/onebot11/adapter.ts
3948
- /** 毫秒 → 秒(Unix 时间戳)。 */
3949
- const MS_TO_SEC = 1e3;
3950
- /**
3951
- * info/warn 级 raw 字段截断上限(2026-10-25 输出内容治理):hex/base64/JSON
3952
- * 原文对运行状态无信息量,保留前缀定位 + 缺省长度;完整值仅在 debug 级
3953
- * ([log.levels].ob11 = "debug")与日志文件中出现。
3954
- */
3955
- const RAW_INFO_LIMIT = 64;
3956
- /** raw 字段截断:超限截断 + 缺省长度标注(…(+N))。 */
3957
- function truncRaw(value, keep = RAW_INFO_LIMIT) {
3958
- if (value === void 0) return "";
3959
- return value.length <= keep ? value : `${value.slice(0, keep)}…(+${value.length - keep})`;
3960
- }
3961
- /** 数字串判别(uin)。 */
3962
- const NUMERIC_RE = /^\d+$/;
3963
- /** 数字串 uin → number(缺失/非法 → null,调用方按口径省略或跳过)。 */
3964
- function numericUin(value) {
3965
- return value !== null && NUMERIC_RE.test(value) ? Number(value) : null;
3966
- }
3967
4327
  /** OneBot 11 协议适配器。 */
3968
4328
  var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
3969
4329
  protocol = "onebot11";
3970
- msgChannel;
3971
- groupChannel;
3972
- friendChannel;
3973
- buddyCacheEvents;
3974
- calibLogger;
3975
4330
  selfUin;
3976
4331
  oneBotApi;
3977
4332
  /** 动作注册表(公共只读:IPC 桥等装配方枚举动作名直接挂载)。 */
3978
4333
  registry;
3979
- unsubscribes = [];
4334
+ /** 收链路事件管道(订阅 / 过滤 / 翻译派发,2026-11-14 拆出)。 */
4335
+ pipeline;
3980
4336
  transports = null;
3981
4337
  heartbeatTimer = null;
3982
- reportSelfMessage = false;
3983
- messageFormat = "array";
3984
- /** 群文件报形式(B4):true = fileElement 群消息报 group_upload notice 替代 message。 */
3985
- groupUploadAsNotice = false;
3986
4338
  /** IPC 桥模式标记(subscribeOnly 启动;reload 时跳过传输重建)。 */
3987
4339
  subscribedOnly = false;
3988
- /** 精华列表串行同步(core 共享组件:缓存 + 串行链 + diff;732:1 触发器与列表回调共用)。 */
3989
- essenceSync;
3990
4340
  constructor(opts) {
3991
4341
  super({
3992
4342
  config: opts.config,
@@ -3997,23 +4347,17 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
3997
4347
  onReload: (config) => this.reloadTransports(config)
3998
4348
  }
3999
4349
  });
4000
- this.msgChannel = opts.msgChannel;
4001
- this.groupChannel = opts.groupChannel;
4002
- this.friendChannel = opts.friendChannel;
4003
- this.buddyCacheEvents = opts.buddyCacheEvents;
4004
- this.calibLogger = opts.logger;
4005
4350
  this.selfUin = opts.self.uin;
4006
4351
  this.oneBotApi = new OneBotApi(opts);
4007
- this.essenceSync = new EssenceListSync({
4008
- fetchList: (groupCode) => this.oneBotApi.webApi.getEssenceMsgList(groupCode),
4009
- onAdded: (groupCode, added) => this.broadcastEssenceAdded(groupCode, added),
4010
- onRemoved: (groupCode, removed, prev) => this.broadcastEssenceRemoved(groupCode, removed, prev),
4011
- onFetchError: (groupCode, err) => {
4012
- this.calibLogger?.warn({
4013
- group: groupCode,
4014
- err: String(err)
4015
- }, "ob11: 精华列表拉取失败(diff 跳过)");
4016
- }
4352
+ this.pipeline = new Ob11EventPipeline({
4353
+ selfUin: this.selfUin,
4354
+ api: this.oneBotApi,
4355
+ broadcast: (event) => this.broadcastEvent(event),
4356
+ ...opts.logger !== void 0 ? { logger: opts.logger } : {},
4357
+ msgChannel: opts.msgChannel,
4358
+ ...opts.groupChannel !== void 0 ? { groupChannel: opts.groupChannel } : {},
4359
+ ...opts.friendChannel !== void 0 ? { friendChannel: opts.friendChannel } : {},
4360
+ ...opts.buddyCacheEvents !== void 0 ? { buddyCacheEvents: opts.buddyCacheEvents } : {}
4017
4361
  });
4018
4362
  this.registry = createOb11ActionRegistry({ api: this.oneBotApi });
4019
4363
  }
@@ -4023,9 +4367,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4023
4367
  */
4024
4368
  async reloadTransports(config) {
4025
4369
  if (this.subscribedOnly) {
4026
- this.reportSelfMessage = config.reportSelfMessage;
4027
- this.messageFormat = config.messagePostFormat;
4028
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4370
+ this.pipeline.applyConfig(config);
4029
4371
  return;
4030
4372
  }
4031
4373
  await this.stopAll();
@@ -4034,9 +4376,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4034
4376
  /** 启动传输:装配(HTTP/WS)+ 打开 server/client + 广播 lifecycle enable + 起心跳。 */
4035
4377
  async startTransports(config) {
4036
4378
  this.subscribedOnly = false;
4037
- this.reportSelfMessage = config.reportSelfMessage;
4038
- this.messageFormat = config.messagePostFormat;
4039
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4379
+ this.pipeline.applyConfig(config);
4040
4380
  const broadcaster = this.getBroadcaster();
4041
4381
  if (broadcaster !== void 0) {
4042
4382
  this.transports = assembleOb11Transports({
@@ -4059,9 +4399,9 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4059
4399
  await Promise.all(this.transports.servers.map((s) => s.open()));
4060
4400
  await Promise.all(this.transports.transports.map((t) => t.open()));
4061
4401
  }
4062
- this.subscribe();
4402
+ this.pipeline.subscribe();
4063
4403
  this.broadcastEvent({
4064
- time: Math.floor(Date.now() / MS_TO_SEC),
4404
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
4065
4405
  self_id: Number(this.selfUin),
4066
4406
  post_type: "meta_event",
4067
4407
  meta_event_type: "lifecycle",
@@ -4074,7 +4414,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4074
4414
  if (intervalMs <= 0) return;
4075
4415
  this.heartbeatTimer = setInterval(() => {
4076
4416
  this.broadcastEvent({
4077
- time: Math.floor(Date.now() / MS_TO_SEC),
4417
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
4078
4418
  self_id: Number(this.selfUin),
4079
4419
  post_type: "meta_event",
4080
4420
  meta_event_type: "heartbeat",
@@ -4092,306 +4432,29 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4092
4432
  clearInterval(this.heartbeatTimer);
4093
4433
  this.heartbeatTimer = null;
4094
4434
  }
4095
- this.unsubscribeAll();
4435
+ this.pipeline.unsubscribeAll();
4096
4436
  if (this.transports !== null) {
4097
4437
  await this.transports.close();
4098
4438
  this.transports = null;
4099
4439
  }
4100
4440
  }
4101
- /** 订阅 kernel 事件(消息 + 群通知 + 好友请求,幂等)。 */
4102
- subscribe() {
4103
- if (this.unsubscribes.length > 0) return;
4104
- this.unsubscribes.push(subscribeRawMessages(this.msgChannel, (msg) => {
4105
- if (hasGrayTip(msg)) {
4106
- this.broadcastNotice(msg).catch(() => {});
4107
- return;
4108
- }
4109
- if (!this.reportSelfMessage && String(msg.senderUin) === this.selfUin) return;
4110
- if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement(msg)) {
4111
- const notice = toGroupUpload(msg, this.selfUin);
4112
- if (notice !== null) {
4113
- this.broadcastEvent(notice);
4114
- return;
4115
- }
4116
- }
4117
- this.broadcastMessageEvent(msg);
4118
- }));
4119
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvOfflineFileMsg", (arg) => {
4120
- const items = narrowOfflineFiles(arg);
4121
- if (items === null) {
4122
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvOfflineFileMsg 未知参数形状");
4123
- return;
4124
- }
4125
- for (const item of items) this.broadcastEvent(toOfflineFileNotice(item, this.selfUin));
4126
- }));
4127
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvSysMsg", (arg) => {
4128
- const blobs = narrowSysMsgBlobs(arg);
4129
- if (blobs === null) {
4130
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvSysMsg 未知参数形状");
4131
- return;
4132
- }
4133
- for (const blob of blobs) this.handleSysMsgBlob(blob);
4134
- }));
4135
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvOnlineFileMsg", (arg) => {
4136
- this.calibLogger?.debug({ raw: JSON.stringify(arg)?.slice(0, 2e3) }, "ob11: onRecvOnlineFileMsg raw(校准数据)");
4137
- }));
4138
- if (this.groupChannel !== void 0) {
4139
- this.unsubscribes.push(this.groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
4140
- if (doubt || !Array.isArray(notifies)) return;
4141
- this.broadcastGroupRequests(notifies);
4142
- }));
4143
- this.unsubscribes.push(this.groupChannel.on("Group/onGroupEssenceListChange", (arg) => {
4144
- this.handleEssenceChange(arg);
4145
- }));
4146
- }
4147
- if (this.friendChannel !== void 0) {
4148
- this.unsubscribes.push(this.friendChannel.on("Buddy/onBuddyReqChange", (arg) => {
4149
- const reqs = narrowBuddyReqs(arg);
4150
- if (reqs === null) {
4151
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onBuddyReqChange 未知参数形状");
4152
- return;
4153
- }
4154
- this.broadcastFriendRequests(reqs);
4155
- }));
4156
- for (const evt of ["Buddy/onBuddyListChange", "Buddy/onBuddyListChangedV2"]) this.unsubscribes.push(this.friendChannel.on(evt, (arg) => {
4157
- this.calibLogger?.info({ raw: truncRaw(JSON.stringify(arg)) }, `ob11: ${evt} raw(friend_add 校准数据)`);
4158
- }));
4159
- }
4160
- if (this.buddyCacheEvents !== void 0) this.unsubscribes.push(this.buddyCacheEvents.on("BuddyCache/onBuddyAdded", (entry) => {
4161
- this.broadcastEvent(toFriendAdd(entry, this.selfUin));
4162
- }));
4163
- }
4164
4441
  /**
4165
4442
  * 仅启动接收链路(IPC 桥模式,2026-08-27):订阅消息通道维护 messageUnique +
4166
- * 灰色通知翻译,与 start() 的差别仅在传输层——不装配 HTTP/WS、不起心跳、
4167
- * 不广播 lifecycle。配置经 seed 装配(load() 返回内存初值)。
4443
+ * 灰色通知翻译;与 start() 的差别仅在传输层(无 HTTP/WS、无心跳、无 lifecycle)。
4444
+ * 配置经 seed 装配(load() 返回内存初值)。
4168
4445
  */
4169
4446
  async subscribeOnly() {
4170
4447
  const config = await this.config.load();
4171
- this.reportSelfMessage = config.reportSelfMessage;
4172
- this.messageFormat = config.messagePostFormat;
4173
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4448
+ this.pipeline.applyConfig(config);
4174
4449
  this.subscribedOnly = true;
4175
- this.subscribe();
4450
+ this.pipeline.subscribe();
4176
4451
  }
4177
4452
  /** 仅退订(与 subscribeOnly 配对的进程级清理;传输关闭仍走 stop())。 */
4178
4453
  unsubscribeOnly() {
4179
4454
  this.subscribedOnly = false;
4180
- this.unsubscribeAll();
4181
- }
4182
- /** sysmsg 规则的 uid→uin 解析器(collectUids 声明才批量转换;失败/缺省恒 0)。 */
4183
- async sysMsgUinResolver(rule, tree, env) {
4184
- if (rule.collectUids === void 0) return () => 0;
4185
- const uids = rule.collectUids(tree, env).filter((uid) => uid !== "");
4186
- if (uids.length === 0) return () => 0;
4187
- try {
4188
- const map = await this.oneBotApi.uidToUin(uids);
4189
- return (uid) => Number(map.get(uid) ?? 0);
4190
- } catch {
4191
- return () => 0;
4192
- }
4193
- }
4194
- /**
4195
- * 单条 sysmsg 字节块:解码 → 识别 → 命中才广播,未识别打结构化校准日志
4196
- * (识别表 2026-11-01 起含 732:21 group_card;732:1 精华为加速触发器,
4197
- * design.md §1/§7.5)。规则声明 collectUids 时先批量 uid→uin 再提取。
4198
- */
4199
- async handleSysMsgBlob(blob) {
4200
- const tree = decodeProtoTree(blob);
4201
- if (tree === null) {
4202
- this.calibLogger?.warn({ raw: truncRaw(toHex(blob).slice(0, 1024)) }, "ob11: onRecvSysMsg protobuf 解码失败");
4203
- return;
4204
- }
4205
- const env = extractSysMsgEnvelope(tree);
4206
- const rec = recognizeOb11SysMsg(env.msgType, env.subType);
4207
- if (await this.handleRecognizedSysMsg(tree, env, rec)) return;
4208
- this.calibLogger?.debug({
4209
- verdict: rec.kind,
4210
- msgType: env.msgType,
4211
- subType: env.subType,
4212
- subTypeAlt: env.subTypeAlt,
4213
- groupCodes: env.groupCodes,
4214
- time: env.time,
4215
- actorUin: env.actorUin,
4216
- actorUid: env.actorUid,
4217
- strings: env.strings,
4218
- raw: toHex(blob).slice(0, 1024)
4219
- }, "ob11: onRecvSysMsg 校准数据(未识别,不广播)");
4220
- }
4221
- /**
4222
- * 已识别 sysmsg 处理(732:1 精华触发器 / 识别表规则广播);命中返回 true。
4223
- * 提取失败返回 false 落入校准路径(不硬广播半成品事件)。
4224
- */
4225
- async handleRecognizedSysMsg(tree, env, rec) {
4226
- if (env.msgType === 732 && env.subType === 1 && this.triggerEssenceSync(tree)) return true;
4227
- if (rec.kind !== "notice") return false;
4228
- const uinOf = await this.sysMsgUinResolver(rec.rule, tree, env);
4229
- const ctx = {
4230
- selfUin: Number(this.selfUin),
4231
- time: env.time ?? Math.floor(Date.now() / 1e3)
4232
- };
4233
- const event = rec.rule.extract(tree, env, uinOf, ctx);
4234
- if (event === null) return false;
4235
- this.broadcastEvent(event);
4236
- return true;
4237
- }
4238
- /** sysmsg 732:1 → 加速触发器:抽取群号踢入串行 sync 链(抽取失败走校准路径)。 */
4239
- triggerEssenceSync(tree) {
4240
- const hit = extractEssenceSetSysMsg(tree);
4241
- if (hit === null) return false;
4242
- this.essenceSync.enqueue(String(hit.groupCode));
4243
- return true;
4244
- }
4245
- /** 精华列表变更:拉全量列表 diff(唯一发射路径;参数收窄失败走校准日志)。 */
4246
- handleEssenceChange(arg) {
4247
- const groupCode = narrowEssenceGroupArg(arg);
4248
- if (groupCode === null) {
4249
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onGroupEssenceListChange 未知参数形状");
4250
- return;
4251
- }
4252
- this.essenceSync.enqueue(groupCode);
4253
- }
4254
- /** diff 新增项 → group_essence add(sender 必填,operator 回填,message_id 反查)。 */
4255
- async broadcastEssenceAdded(groupCode, added) {
4256
- for (const item of added) {
4257
- const senderId = numericUin(item.senderUin);
4258
- if (senderId === null) {
4259
- this.calibLogger?.warn({
4260
- group: groupCode,
4261
- seq: item.messageSeq
4262
- }, "ob11: 精华新增 sender_uin 缺失(跳过事件)");
4263
- continue;
4264
- }
4265
- const messageId = await this.resolveEssenceMsgId(groupCode, item.messageSeq);
4266
- if (messageId === null) continue;
4267
- const operatorId = numericUin(item.operatorUin);
4268
- this.broadcastEvent({
4269
- time: item.addDigestTime ?? Math.floor(Date.now() / MS_TO_SEC),
4270
- self_id: Number(this.selfUin),
4271
- post_type: "notice",
4272
- notice_type: "group_essence",
4273
- sub_type: "add",
4274
- group_id: Number(groupCode),
4275
- sender_id: senderId,
4276
- ...operatorId !== null ? { operator_id: operatorId } : {},
4277
- message_id: messageId
4278
- });
4279
- }
4280
- }
4281
- /** diff 移除项 → group_essence delete(sender 从 prev 缓存回填;operator 无数据源省略)。 */
4282
- async broadcastEssenceRemoved(groupCode, removed, prev) {
4283
- for (const seq of removed) {
4284
- const senderId = numericUin(prev.get(seq)?.senderUin ?? null);
4285
- if (senderId === null) {
4286
- this.calibLogger?.warn({
4287
- group: groupCode,
4288
- seq
4289
- }, "ob11: 精华移除 sender 不可得(跳过事件)");
4290
- continue;
4291
- }
4292
- const messageId = await this.resolveEssenceMsgId(groupCode, seq);
4293
- if (messageId === null) continue;
4294
- this.broadcastEvent({
4295
- time: Math.floor(Date.now() / MS_TO_SEC),
4296
- self_id: Number(this.selfUin),
4297
- post_type: "notice",
4298
- notice_type: "group_essence",
4299
- sub_type: "delete",
4300
- group_id: Number(groupCode),
4301
- sender_id: senderId,
4302
- message_id: messageId
4303
- });
4304
- }
4305
- }
4306
- /**
4307
- * 精华 message_id 反查:msgSeq → 近段历史扫描(60 条,对齐 milky
4308
- * resolveMsgIdBySeq fallback 层)→ MessageUnique.alloc 幂等分配(可被 get_msg
4309
- * 反查的正确空间,对照 recall 的 msgSeq 错位)。未命中返回 null(跳过事件)。
4310
- */
4311
- async resolveEssenceMsgId(groupCode, seq) {
4312
- const peer = {
4313
- chatType: ChatType.GROUP,
4314
- peerUid: groupCode
4315
- };
4316
- const hit = (await this.oneBotApi.msgApi.fetchMessages(peer, { count: 60 }).catch(() => [])).find((m) => Number(m.msgSeq) === seq);
4317
- if (hit === void 0) {
4318
- this.calibLogger?.warn({
4319
- group: groupCode,
4320
- seq
4321
- }, "ob11: 精华 message_id 反查未命中(跳过事件)");
4322
- return null;
4323
- }
4324
- return this.oneBotApi.messageUnique.alloc(hit.msgId, peer);
4325
- }
4326
- /**
4327
- * 广播消息事件(P2-19:接收方向 ID 转换)。
4328
- * 收集 at uid → 一次批量 uidToUin → 构造上下文 → 翻译广播。
4329
- * 群消息另查发送者角色(GroupCache 缓存优先,失败回退缺省 member)。
4330
- * 翻译失败退化为原样(不阻塞上报)。
4331
- */
4332
- async broadcastMessageEvent(msg) {
4333
- const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
4334
- let uidToUin;
4335
- if (atUids.length > 0) try {
4336
- uidToUin = await this.oneBotApi.uidToUin(atUids);
4337
- } catch {}
4338
- const senderRole = msg.chatType === ChatType.GROUP ? await this.oneBotApi.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
4339
- const ctx = {
4340
- ...uidToUin !== void 0 ? { uidToUin } : {},
4341
- ...senderRole !== void 0 ? { senderRole } : {},
4342
- msgIdToOb11Id: (msgId) => this.oneBotApi.messageUnique.getMessageId(msgId)
4343
- };
4344
- this.broadcastEvent(toOb11MessageEvent(msg, this.selfUin, this.oneBotApi.messageUnique, this.messageFormat, ctx));
4345
- }
4346
- /** 广播 grayTip → notice 事件(批量 uidToUin 后翻译,纯函数)。 */
4347
- async broadcastNotice(msg) {
4348
- const uids = collectGrayTipUids(msg);
4349
- let uidToUin = /* @__PURE__ */ new Map();
4350
- if (uids.length > 0) uidToUin = await this.oneBotApi.uidToUin(uids);
4351
- const notice = toOb11NoticeEvent(msg, {
4352
- selfUin: this.selfUin,
4353
- uidToUin,
4354
- ...this.calibLogger !== void 0 ? { logger: this.calibLogger } : {}
4355
- });
4356
- if (notice !== null) this.broadcastEvent(notice);
4357
- }
4358
- /** 广播群系统通知 → OB11 group request 事件(批量 uidToUin 后翻译,纯函数)。 */
4359
- async broadcastGroupRequests(notifies) {
4360
- const ctx = {
4361
- selfUin: this.selfUin,
4362
- uidToUin: await this.uidToUinMap(collectGroupNotifyUids(notifies))
4363
- };
4364
- for (const n of notifies) {
4365
- const event = toOb11GroupRequestEvent(n, ctx);
4366
- if (event !== null) this.broadcastEvent(event);
4367
- }
4368
- }
4369
- /** 广播好友申请 → OB11 friend request 事件(批量 uidToUin 后翻译,纯函数)。 */
4370
- async broadcastFriendRequests(reqs) {
4371
- const ctx = {
4372
- selfUin: this.selfUin,
4373
- uidToUin: await this.uidToUinMap(reqs.map((r) => r.friendUid).filter((uid) => uid !== ""))
4374
- };
4375
- for (const req of reqs) this.broadcastEvent(toOb11FriendRequestEvent(req, ctx));
4376
- }
4377
- /** uid 批量 → uin(失败退空 Map:翻译层退化为 uid 数值,不阻塞请求上报)。 */
4378
- async uidToUinMap(uids) {
4379
- if (uids.length === 0) return /* @__PURE__ */ new Map();
4380
- try {
4381
- return await this.oneBotApi.uidToUin(uids);
4382
- } catch {
4383
- return /* @__PURE__ */ new Map();
4384
- }
4385
- }
4386
- /** 退订(幂等)。 */
4387
- unsubscribeAll() {
4388
- for (const off of this.unsubscribes) off();
4389
- this.unsubscribes = [];
4455
+ this.pipeline.unsubscribeAll();
4390
4456
  }
4391
- /**
4392
- * 请求分发(挂到 network transport 的 onRequest):
4393
- * OB11 标准请求 { action, params, echo } → 动作注册表 → handle(HTTP)/websocketHandle(WS)。
4394
- */
4457
+ /** 请求分发(挂到 transport 的 onRequest):{ action, params, echo } → 注册表分发。 */
4395
4458
  async handleRequest(req, respond) {
4396
4459
  const parsed = req ?? {};
4397
4460
  const { action: rawAction, echo } = parsed;
@@ -4423,15 +4486,6 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4423
4486
  respond(result);
4424
4487
  }
4425
4488
  };
4426
- /** 收集群系统通知涉及的 uid(user1/user2 双方,空 uid 跳过)。 */
4427
- function collectGroupNotifyUids(notifies) {
4428
- const uids = [];
4429
- for (const n of notifies) {
4430
- const notify = n;
4431
- for (const u of [notify.user1, notify.user2]) if (typeof u?.uid === "string" && u.uid !== "") uids.push(u.uid);
4432
- }
4433
- return uids;
4434
- }
4435
4489
  export { MessageUnique, NapukettoOneBot11Adapter, OneBotApi, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
4436
4490
 
4437
4491
  //# sourceMappingURL=index.mjs.map