@napuketto/adapter 0.14.2 → 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 { S as ActionRegistry, _ 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, y as BaseProtocolAdapter } from "../core-CECIwO6s.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 { a as MS_TO_SEC$3, i as narrowBuddyReqs, n as extractEssenceSetSysMsg, o as resolveUin, r as narrowEssenceGroupArg, t as diffEssenceList } from "../essence-Bdms4trk.mjs";
4
- import { n as firstUntranslatedGrayTip, t as collectGrayTipUids } from "../gray-tip-ByF-MKeV.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
  /**
@@ -1884,15 +1884,6 @@ const GROUP_FILE_BUS_ID = 102;
1884
1884
  function hasFileElement(msg) {
1885
1885
  return msg.elements.some((el) => el.fileElement != null);
1886
1886
  }
1887
- /** 检查消息是否含可翻译的 grayTip 元素(空值判定同 hasFileElement)。 */
1888
- function hasGrayTip(msg) {
1889
- return msg.elements.some((el) => el.grayTipElement != null);
1890
- }
1891
- /** uid → uin(上下文映射缺省退化为 uid)。 */
1892
- function toUin$1(uid, ctx) {
1893
- const uin = ctx.uidToUin.get(uid);
1894
- return Number(uin ?? uid);
1895
- }
1896
1887
  /** 基础字段(time/self_id/post_type)。 */
1897
1888
  function base(msg, ctx) {
1898
1889
  return {
@@ -1911,14 +1902,14 @@ function toRecall(msg, g, ctx) {
1911
1902
  self_id: Number(ctx.selfUin),
1912
1903
  post_type: "notice",
1913
1904
  notice_type: "friend_recall",
1914
- user_id: toUin$1(revoke.operatorUid, ctx),
1905
+ user_id: toUin(revoke.operatorUid, ctx),
1915
1906
  message_id: Number(msg.msgSeq)
1916
1907
  };
1917
1908
  return {
1918
1909
  ...base(msg, ctx),
1919
1910
  notice_type: "group_recall",
1920
- user_id: toUin$1(revoke.operatorUid, ctx),
1921
- operator_id: toUin$1(revoke.operatorUid, ctx),
1911
+ user_id: toUin(revoke.operatorUid, ctx),
1912
+ operator_id: toUin(revoke.operatorUid, ctx),
1922
1913
  message_id: Number(msg.msgSeq)
1923
1914
  };
1924
1915
  }
@@ -1941,8 +1932,8 @@ function toPoke(msg, g, ctx) {
1941
1932
  notice_type: "notify",
1942
1933
  sub_type: "poke",
1943
1934
  group_id: isGroup ? Number(msg.peerUid) : 0,
1944
- user_id: toUin$1(msg.senderUid, ctx),
1945
- target_id: toUin$1(aioOp?.peerUid ?? "", ctx)
1935
+ user_id: toUin(msg.senderUid, ctx),
1936
+ target_id: toUin(aioOp?.peerUid ?? "", ctx)
1946
1937
  };
1947
1938
  }
1948
1939
  /** 群成员变动映射器表(键 = TipGroupElementType;缺项 = 不可翻译返回 null)。 */
@@ -1977,8 +1968,8 @@ function toMemberAdd(common, _grp, ctx) {
1977
1968
  notice_type: "group_increase",
1978
1969
  sub_type: adminUid === memberUid ? "approve" : "invite",
1979
1970
  group_id: groupId,
1980
- operator_id: toUin$1(adminUid, ctx),
1981
- user_id: toUin$1(memberUid, ctx)
1971
+ operator_id: toUin(adminUid, ctx),
1972
+ user_id: toUin(memberUid, ctx)
1982
1973
  };
1983
1974
  }
1984
1975
  /** 群成员退出(leave)。 */
@@ -1991,8 +1982,8 @@ function toQuit(common, _grp, ctx) {
1991
1982
  notice_type: "group_decrease",
1992
1983
  sub_type: "leave",
1993
1984
  group_id: groupId,
1994
- operator_id: toUin$1(adminUid, ctx),
1995
- user_id: toUin$1(memberUid, ctx)
1985
+ operator_id: toUin(adminUid, ctx),
1986
+ user_id: toUin(memberUid, ctx)
1996
1987
  };
1997
1988
  }
1998
1989
  /** 管理员变更(BLOCK=set / UNBLOCK=unset)。 */
@@ -2005,7 +1996,7 @@ function toAdminChange(common, grp, ctx) {
2005
1996
  notice_type: "group_admin",
2006
1997
  sub_type: grp.type === TipGroupElementType.BLOCK ? "set" : "unset",
2007
1998
  group_id: groupId,
2008
- user_id: toUin$1(memberUid === "" ? adminUid : memberUid, ctx)
1999
+ user_id: toUin(memberUid === "" ? adminUid : memberUid, ctx)
2009
2000
  };
2010
2001
  }
2011
2002
  /** 禁言(duration>0=ban / 否则 lift_ban)。 */
@@ -2019,8 +2010,8 @@ function toBan(common, grp, ctx) {
2019
2010
  notice_type: "group_ban",
2020
2011
  sub_type: duration > 0 ? "ban" : "lift_ban",
2021
2012
  group_id: common.groupId,
2022
- operator_id: toUin$1(shutUp?.admin?.uid ?? common.adminUid, ctx),
2023
- user_id: toUin$1(shutUp?.member?.uid ?? common.memberUid, ctx),
2013
+ operator_id: toUin(shutUp?.admin?.uid ?? common.adminUid, ctx),
2014
+ user_id: toUin(shutUp?.member?.uid ?? common.memberUid, ctx),
2024
2015
  duration
2025
2016
  };
2026
2017
  }
@@ -2032,7 +2023,7 @@ function toBan(common, grp, ctx) {
2032
2023
  function toFriendAdd(entry, selfUin) {
2033
2024
  const uin = entry.coreInfo?.uin ?? entry.uin ?? "";
2034
2025
  return {
2035
- time: Math.floor(Date.now() / MS_TO_SEC$2),
2026
+ time: Math.floor(Date.now() / MS_TO_SEC$1),
2036
2027
  self_id: Number(selfUin),
2037
2028
  post_type: "notice",
2038
2029
  notice_type: "friend_add",
@@ -2106,10 +2097,6 @@ function toOb11NoticeEvent(msg, ctx) {
2106
2097
  * ⚠️ onBuddyReqChange 回调参数形状未经真实事件校准(wrapper 字符串证据仅有方法名),
2107
2098
  * narrowBuddyReqs 防御性收窄,未知形状返回 null 由调用方打 raw 日志积累校准数据。
2108
2099
  */
2109
- /** uid → uin(core 共享解析;ctx 携带映射)。 */
2110
- function toUin(uid, ctx) {
2111
- return resolveUin(uid, ctx.uidToUin);
2112
- }
2113
2100
  /**
2114
2101
  * GroupNotify → OB11 群请求事件(group_add / group_invite)。
2115
2102
  *
@@ -2131,7 +2118,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2131
2118
  default: return null;
2132
2119
  }
2133
2120
  return {
2134
- time: Math.floor(Date.now() / MS_TO_SEC$3),
2121
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
2135
2122
  self_id: Number(ctx.selfUin),
2136
2123
  post_type: "request",
2137
2124
  request_type: "group",
@@ -2149,7 +2136,7 @@ function toOb11GroupRequestEvent(notify, ctx) {
2149
2136
  function toOb11FriendRequestEvent(req, ctx) {
2150
2137
  const words = req["words"];
2151
2138
  return {
2152
- time: Math.floor(Date.now() / MS_TO_SEC$3),
2139
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
2153
2140
  self_id: Number(ctx.selfUin),
2154
2141
  post_type: "request",
2155
2142
  request_type: "friend",
@@ -3634,61 +3621,154 @@ var OneBotApi = class {
3634
3621
  }
3635
3622
  }
3636
3623
  };
3637
- // src/onebot11/helper/message-event.ts
3638
- /** RawMessage → OB11 消息事件(message_id 经 MessageUnique 映射并记录 peer)。
3639
- * messageFormat 决定 message 字段格式:array = 消息段数组(标准),string = CQ 码字符串。
3640
- * ctx(可选):接收方向 ID 转换上下文(at uid→uin、reply NT msgId→OB11 id,P2-19)。 */
3641
- function toOb11MessageEvent(msg, selfUin, unique, messageFormat = "array", ctx = {}) {
3642
- const elements = applyReceiveContext(toCanonicalElements(msg), ctx);
3643
- const segments = canonicalToSegments(elements);
3644
- const time = toUnixSeconds(msg.msgTime);
3645
- const selfId = Number(selfUin);
3646
- const userId = Number(msg.senderUin);
3647
- const base = {
3648
- time,
3649
- self_id: selfId,
3650
- post_type: "message",
3651
- message_id: unique.alloc(msg.msgId, {
3652
- chatType: msg.chatType,
3653
- peerUid: msg.peerUid
3654
- }),
3655
- message: messageFormat === "string" ? canonicalToCqMessage(elements) : segments,
3656
- raw_message: canonicalToCqMessage(elements),
3657
- font: 0
3658
- };
3659
- if (msg.chatType === ChatType.GROUP) {
3660
- const sender = {
3661
- user_id: userId,
3662
- nickname: senderNickname(msg),
3663
- role: ctx.senderRole ?? "member"
3664
- };
3665
- 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;
3666
3662
  return {
3667
- ...base,
3668
- message_type: "group",
3669
- sub_type: "normal",
3670
- group_id: Number(msg.peerUid),
3671
- user_id: userId,
3672
- sender
3663
+ ...uidToUin !== void 0 ? { uidToUin } : {},
3664
+ ...senderRole !== void 0 ? { senderRole } : {},
3665
+ msgIdToOb11Id: (msgId) => this.api.messageUnique.getMessageId(msgId)
3673
3666
  };
3674
3667
  }
3675
- let subType = "friend";
3676
- if (msg.chatType === ChatType.C2C_TEMP) subType = "group";
3677
- const sender = {
3678
- user_id: userId,
3679
- nickname: senderNickname(msg)
3680
- };
3681
- return {
3682
- ...base,
3683
- message_type: "private",
3684
- sub_type: subType,
3685
- user_id: userId,
3686
- sender
3687
- };
3688
- }
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
+ };
3689
3769
  // src/onebot11/helper/notice-extra.ts
3690
3770
  /** 毫秒 → 秒(Unix 时间戳)。 */
3691
- const MS_TO_SEC$1 = 1e3;
3771
+ const MS_TO_SEC = 1e3;
3692
3772
  /** 候选 uin 字段(按优先级取第一个数字串;uid 串不硬转——待校准)。 */
3693
3773
  function pickUin(item) {
3694
3774
  for (const key of [
@@ -3747,7 +3827,7 @@ function narrowOfflineFiles(arg) {
3747
3827
  /** 归一化项 → OB11 offline_file notice(time 取当前时刻,friend_add 同款)。 */
3748
3828
  function toOfflineFileNotice(item, selfUin) {
3749
3829
  return {
3750
- time: Math.floor(Date.now() / MS_TO_SEC$1),
3830
+ time: Math.floor(Date.now() / MS_TO_SEC),
3751
3831
  self_id: Number(selfUin),
3752
3832
  post_type: "notice",
3753
3833
  notice_type: "offline_file",
@@ -3759,6 +3839,187 @@ function toOfflineFileNotice(item, selfUin) {
3759
3839
  }
3760
3840
  };
3761
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
+ }
3762
4023
  // src/onebot11/helper/sysmsg.ts
3763
4024
  /**
3764
4025
  * OB11 sysmsg 识别表(2026-11-01 自 helper/sysmsg.ts 瘦身——解码层上移
@@ -3774,7 +4035,7 @@ function toOfflineFileNotice(item, selfUin) {
3774
4035
  * 从 `core/shared/sysmsg.js` 导入使用。
3775
4036
  */
3776
4037
  /** 群号判别(strings[0] 必须是数字串)。 */
3777
- const NUMERIC_RE$1 = /^\d+$/;
4038
+ const NUMERIC_RE = /^\d+$/;
3778
4039
  /**
3779
4040
  * (msgType, subType) → 规则表(键 = 原生分发键,design.md §7.1)。
3780
4041
  *
@@ -3790,7 +4051,7 @@ const KIND_TABLE = /* @__PURE__ */ new Map([["732:21", {
3790
4051
  },
3791
4052
  extract: (_tree, env, uinOf, ctx) => {
3792
4053
  const [groupCode, subject, cardNew, cardOld] = env.strings;
3793
- 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;
3794
4055
  return {
3795
4056
  time: ctx.time,
3796
4057
  self_id: ctx.selfUin,
@@ -3813,6 +4074,111 @@ const OBSERVED_UNNAMED = /* @__PURE__ */ new Set([
3813
4074
  function recognizeOb11SysMsg(msgType, subType, table = KIND_TABLE) {
3814
4075
  return recognizeSysMsg(msgType, subType, table, OBSERVED_UNNAMED);
3815
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
+ };
3816
4182
  // src/onebot11/transport.ts
3817
4183
  /**
3818
4184
  * OB11 传输装配(P2-5,2026-08-05)
@@ -3958,50 +4324,19 @@ function authorizeHeader(token) {
3958
4324
  return { authorization: `${BEARER_PREFIX}${token}` };
3959
4325
  }
3960
4326
  // src/onebot11/adapter.ts
3961
- /** 毫秒 → 秒(Unix 时间戳)。 */
3962
- const MS_TO_SEC = 1e3;
3963
- /**
3964
- * info/warn 级 raw 字段截断上限(2026-10-25 输出内容治理):hex/base64/JSON
3965
- * 原文对运行状态无信息量,保留前缀定位 + 缺省长度;完整值仅在 debug 级
3966
- * ([log.levels].ob11 = "debug")与日志文件中出现。
3967
- */
3968
- const RAW_INFO_LIMIT = 64;
3969
- /** raw 字段截断:超限截断 + 缺省长度标注(…(+N))。 */
3970
- function truncRaw(value, keep = RAW_INFO_LIMIT) {
3971
- if (value === void 0) return "";
3972
- return value.length <= keep ? value : `${value.slice(0, keep)}…(+${value.length - keep})`;
3973
- }
3974
- /** 数字串判别(uin)。 */
3975
- const NUMERIC_RE = /^\d+$/;
3976
- /** 数字串 uin → number(缺失/非法 → null,调用方按口径省略或跳过)。 */
3977
- function numericUin(value) {
3978
- return value !== null && NUMERIC_RE.test(value) ? Number(value) : null;
3979
- }
3980
4327
  /** OneBot 11 协议适配器。 */
3981
4328
  var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
3982
4329
  protocol = "onebot11";
3983
- msgChannel;
3984
- groupChannel;
3985
- friendChannel;
3986
- buddyCacheEvents;
3987
- calibLogger;
3988
4330
  selfUin;
3989
4331
  oneBotApi;
3990
4332
  /** 动作注册表(公共只读:IPC 桥等装配方枚举动作名直接挂载)。 */
3991
4333
  registry;
3992
- unsubscribes = [];
4334
+ /** 收链路事件管道(订阅 / 过滤 / 翻译派发,2026-11-14 拆出)。 */
4335
+ pipeline;
3993
4336
  transports = null;
3994
4337
  heartbeatTimer = null;
3995
- reportSelfMessage = false;
3996
- messageFormat = "array";
3997
- /** 群文件报形式(B4):true = fileElement 群消息报 group_upload notice 替代 message。 */
3998
- groupUploadAsNotice = false;
3999
4338
  /** IPC 桥模式标记(subscribeOnly 启动;reload 时跳过传输重建)。 */
4000
4339
  subscribedOnly = false;
4001
- /** 精华列表缓存(群号 → seq → 条目{操作者/发送者/加精时间};group_essence diff 路径)。 */
4002
- essenceCaches = /* @__PURE__ */ new Map();
4003
- /** 精华列表拉取串行链(并发回写乱序会把新列表覆盖成旧列表;732:1 触发器与列表回调共用)。 */
4004
- essenceChain = Promise.resolve();
4005
4340
  constructor(opts) {
4006
4341
  super({
4007
4342
  config: opts.config,
@@ -4012,13 +4347,18 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4012
4347
  onReload: (config) => this.reloadTransports(config)
4013
4348
  }
4014
4349
  });
4015
- this.msgChannel = opts.msgChannel;
4016
- this.groupChannel = opts.groupChannel;
4017
- this.friendChannel = opts.friendChannel;
4018
- this.buddyCacheEvents = opts.buddyCacheEvents;
4019
- this.calibLogger = opts.logger;
4020
4350
  this.selfUin = opts.self.uin;
4021
4351
  this.oneBotApi = new OneBotApi(opts);
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 } : {}
4361
+ });
4022
4362
  this.registry = createOb11ActionRegistry({ api: this.oneBotApi });
4023
4363
  }
4024
4364
  /**
@@ -4027,9 +4367,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4027
4367
  */
4028
4368
  async reloadTransports(config) {
4029
4369
  if (this.subscribedOnly) {
4030
- this.reportSelfMessage = config.reportSelfMessage;
4031
- this.messageFormat = config.messagePostFormat;
4032
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4370
+ this.pipeline.applyConfig(config);
4033
4371
  return;
4034
4372
  }
4035
4373
  await this.stopAll();
@@ -4038,9 +4376,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4038
4376
  /** 启动传输:装配(HTTP/WS)+ 打开 server/client + 广播 lifecycle enable + 起心跳。 */
4039
4377
  async startTransports(config) {
4040
4378
  this.subscribedOnly = false;
4041
- this.reportSelfMessage = config.reportSelfMessage;
4042
- this.messageFormat = config.messagePostFormat;
4043
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4379
+ this.pipeline.applyConfig(config);
4044
4380
  const broadcaster = this.getBroadcaster();
4045
4381
  if (broadcaster !== void 0) {
4046
4382
  this.transports = assembleOb11Transports({
@@ -4063,9 +4399,9 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4063
4399
  await Promise.all(this.transports.servers.map((s) => s.open()));
4064
4400
  await Promise.all(this.transports.transports.map((t) => t.open()));
4065
4401
  }
4066
- this.subscribe();
4402
+ this.pipeline.subscribe();
4067
4403
  this.broadcastEvent({
4068
- time: Math.floor(Date.now() / MS_TO_SEC),
4404
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
4069
4405
  self_id: Number(this.selfUin),
4070
4406
  post_type: "meta_event",
4071
4407
  meta_event_type: "lifecycle",
@@ -4078,7 +4414,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4078
4414
  if (intervalMs <= 0) return;
4079
4415
  this.heartbeatTimer = setInterval(() => {
4080
4416
  this.broadcastEvent({
4081
- time: Math.floor(Date.now() / MS_TO_SEC),
4417
+ time: Math.floor(Date.now() / MS_TO_SEC$2),
4082
4418
  self_id: Number(this.selfUin),
4083
4419
  post_type: "meta_event",
4084
4420
  meta_event_type: "heartbeat",
@@ -4096,329 +4432,29 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4096
4432
  clearInterval(this.heartbeatTimer);
4097
4433
  this.heartbeatTimer = null;
4098
4434
  }
4099
- this.unsubscribeAll();
4435
+ this.pipeline.unsubscribeAll();
4100
4436
  if (this.transports !== null) {
4101
4437
  await this.transports.close();
4102
4438
  this.transports = null;
4103
4439
  }
4104
4440
  }
4105
- /** 订阅 kernel 事件(消息 + 群通知 + 好友请求,幂等)。 */
4106
- subscribe() {
4107
- if (this.unsubscribes.length > 0) return;
4108
- this.unsubscribes.push(subscribeRawMessages(this.msgChannel, (msg) => {
4109
- if (hasGrayTip(msg)) {
4110
- this.broadcastNotice(msg).catch(() => {});
4111
- return;
4112
- }
4113
- if (!this.reportSelfMessage && String(msg.senderUin) === this.selfUin) return;
4114
- if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement(msg)) {
4115
- const notice = toGroupUpload(msg, this.selfUin);
4116
- if (notice !== null) {
4117
- this.broadcastEvent(notice);
4118
- return;
4119
- }
4120
- }
4121
- this.broadcastMessageEvent(msg);
4122
- }));
4123
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvOfflineFileMsg", (arg) => {
4124
- const items = narrowOfflineFiles(arg);
4125
- if (items === null) {
4126
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvOfflineFileMsg 未知参数形状");
4127
- return;
4128
- }
4129
- for (const item of items) this.broadcastEvent(toOfflineFileNotice(item, this.selfUin));
4130
- }));
4131
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvSysMsg", (arg) => {
4132
- const blobs = narrowSysMsgBlobs(arg);
4133
- if (blobs === null) {
4134
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onRecvSysMsg 未知参数形状");
4135
- return;
4136
- }
4137
- for (const blob of blobs) this.handleSysMsgBlob(blob);
4138
- }));
4139
- this.unsubscribes.push(this.msgChannel.on("Msg/onRecvOnlineFileMsg", (arg) => {
4140
- this.calibLogger?.debug({ raw: JSON.stringify(arg)?.slice(0, 2e3) }, "ob11: onRecvOnlineFileMsg raw(校准数据)");
4141
- }));
4142
- if (this.groupChannel !== void 0) {
4143
- this.unsubscribes.push(this.groupChannel.on("Group/onGroupNotifiesUpdated", (doubt, notifies) => {
4144
- if (doubt || !Array.isArray(notifies)) return;
4145
- this.broadcastGroupRequests(notifies);
4146
- }));
4147
- this.unsubscribes.push(this.groupChannel.on("Group/onGroupEssenceListChange", (arg) => {
4148
- this.handleEssenceChange(arg);
4149
- }));
4150
- }
4151
- if (this.friendChannel !== void 0) {
4152
- this.unsubscribes.push(this.friendChannel.on("Buddy/onBuddyReqChange", (arg) => {
4153
- const reqs = narrowBuddyReqs(arg);
4154
- if (reqs === null) {
4155
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onBuddyReqChange 未知参数形状");
4156
- return;
4157
- }
4158
- this.broadcastFriendRequests(reqs);
4159
- }));
4160
- for (const evt of ["Buddy/onBuddyListChange", "Buddy/onBuddyListChangedV2"]) this.unsubscribes.push(this.friendChannel.on(evt, (arg) => {
4161
- this.calibLogger?.info({ raw: truncRaw(JSON.stringify(arg)) }, `ob11: ${evt} raw(friend_add 校准数据)`);
4162
- }));
4163
- }
4164
- if (this.buddyCacheEvents !== void 0) this.unsubscribes.push(this.buddyCacheEvents.on("BuddyCache/onBuddyAdded", (entry) => {
4165
- this.broadcastEvent(toFriendAdd(entry, this.selfUin));
4166
- }));
4167
- }
4168
4441
  /**
4169
4442
  * 仅启动接收链路(IPC 桥模式,2026-08-27):订阅消息通道维护 messageUnique +
4170
- * 灰色通知翻译,与 start() 的差别仅在传输层——不装配 HTTP/WS、不起心跳、
4171
- * 不广播 lifecycle。配置经 seed 装配(load() 返回内存初值)。
4443
+ * 灰色通知翻译;与 start() 的差别仅在传输层(无 HTTP/WS、无心跳、无 lifecycle)。
4444
+ * 配置经 seed 装配(load() 返回内存初值)。
4172
4445
  */
4173
4446
  async subscribeOnly() {
4174
4447
  const config = await this.config.load();
4175
- this.reportSelfMessage = config.reportSelfMessage;
4176
- this.messageFormat = config.messagePostFormat;
4177
- this.groupUploadAsNotice = config.groupUploadAsNotice;
4448
+ this.pipeline.applyConfig(config);
4178
4449
  this.subscribedOnly = true;
4179
- this.subscribe();
4450
+ this.pipeline.subscribe();
4180
4451
  }
4181
4452
  /** 仅退订(与 subscribeOnly 配对的进程级清理;传输关闭仍走 stop())。 */
4182
4453
  unsubscribeOnly() {
4183
4454
  this.subscribedOnly = false;
4184
- this.unsubscribeAll();
4185
- }
4186
- /** sysmsg 规则的 uid→uin 解析器(collectUids 声明才批量转换;失败/缺省恒 0)。 */
4187
- async sysMsgUinResolver(rule, tree, env) {
4188
- if (rule.collectUids === void 0) return () => 0;
4189
- const uids = rule.collectUids(tree, env).filter((uid) => uid !== "");
4190
- if (uids.length === 0) return () => 0;
4191
- try {
4192
- const map = await this.oneBotApi.uidToUin(uids);
4193
- return (uid) => Number(map.get(uid) ?? 0);
4194
- } catch {
4195
- return () => 0;
4196
- }
4197
- }
4198
- /**
4199
- * 单条 sysmsg 字节块:解码 → 识别 → 命中才广播,未识别打结构化校准日志
4200
- * (识别表 2026-11-01 起含 732:21 group_card;732:1 精华为加速触发器,
4201
- * design.md §1/§7.5)。规则声明 collectUids 时先批量 uid→uin 再提取。
4202
- */
4203
- async handleSysMsgBlob(blob) {
4204
- const tree = decodeProtoTree(blob);
4205
- if (tree === null) {
4206
- this.calibLogger?.warn({ raw: truncRaw(toHex(blob).slice(0, 1024)) }, "ob11: onRecvSysMsg protobuf 解码失败");
4207
- return;
4208
- }
4209
- const env = extractSysMsgEnvelope(tree);
4210
- const rec = recognizeOb11SysMsg(env.msgType, env.subType);
4211
- if (await this.handleRecognizedSysMsg(tree, env, rec)) return;
4212
- this.calibLogger?.debug({
4213
- verdict: rec.kind,
4214
- msgType: env.msgType,
4215
- subType: env.subType,
4216
- subTypeAlt: env.subTypeAlt,
4217
- groupCodes: env.groupCodes,
4218
- time: env.time,
4219
- actorUin: env.actorUin,
4220
- actorUid: env.actorUid,
4221
- strings: env.strings,
4222
- raw: toHex(blob).slice(0, 1024)
4223
- }, "ob11: onRecvSysMsg 校准数据(未识别,不广播)");
4224
- }
4225
- /**
4226
- * 已识别 sysmsg 处理(732:1 精华触发器 / 识别表规则广播);命中返回 true。
4227
- * 提取失败返回 false 落入校准路径(不硬广播半成品事件)。
4228
- */
4229
- async handleRecognizedSysMsg(tree, env, rec) {
4230
- if (env.msgType === 732 && env.subType === 1 && this.triggerEssenceSync(tree)) return true;
4231
- if (rec.kind !== "notice") return false;
4232
- const uinOf = await this.sysMsgUinResolver(rec.rule, tree, env);
4233
- const ctx = {
4234
- selfUin: Number(this.selfUin),
4235
- time: env.time ?? Math.floor(Date.now() / 1e3)
4236
- };
4237
- const event = rec.rule.extract(tree, env, uinOf, ctx);
4238
- if (event === null) return false;
4239
- this.broadcastEvent(event);
4240
- return true;
4241
- }
4242
- /** sysmsg 732:1 → 加速触发器:抽取群号踢入串行 sync 链(抽取失败走校准路径)。 */
4243
- triggerEssenceSync(tree) {
4244
- const hit = extractEssenceSetSysMsg(tree);
4245
- if (hit === null) return false;
4246
- this.enqueueEssenceSync(String(hit.groupCode));
4247
- return true;
4248
- }
4249
- /** 精华列表变更:拉全量列表 diff(唯一发射路径;参数收窄失败走校准日志)。 */
4250
- handleEssenceChange(arg) {
4251
- const groupCode = narrowEssenceGroupArg(arg);
4252
- if (groupCode === null) {
4253
- this.calibLogger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onGroupEssenceListChange 未知参数形状");
4254
- return;
4255
- }
4256
- this.enqueueEssenceSync(groupCode);
4257
- }
4258
- /** 精华 sync 入队(串行防乱序:并发回写会把新列表覆盖成旧列表)。 */
4259
- enqueueEssenceSync(groupCode) {
4260
- this.essenceChain = this.essenceChain.then(() => this.syncEssenceList(groupCode), () => void 0);
4261
- }
4262
- /** 单群精华列表同步:拉取 → diff → 广播 → 更新缓存(基线未建立只建基线)。 */
4263
- async syncEssenceList(groupCode) {
4264
- let items;
4265
- try {
4266
- items = await this.oneBotApi.webApi.getEssenceMsgList(groupCode);
4267
- } catch (e) {
4268
- this.calibLogger?.warn({
4269
- group: groupCode,
4270
- err: String(e)
4271
- }, "ob11: 精华列表拉取失败(diff 跳过)");
4272
- return;
4273
- }
4274
- const prev = this.essenceCaches.get(groupCode);
4275
- const { cache, added, removed } = diffEssenceList(prev, items);
4276
- this.essenceCaches.set(groupCode, cache);
4277
- if (prev === void 0) return;
4278
- await this.broadcastEssenceAdded(groupCode, added);
4279
- await this.broadcastEssenceRemoved(groupCode, removed, prev);
4280
- }
4281
- /** diff 新增项 → group_essence add(sender 必填,operator 回填,message_id 反查)。 */
4282
- async broadcastEssenceAdded(groupCode, added) {
4283
- for (const item of added) {
4284
- const senderId = numericUin(item.senderUin);
4285
- if (senderId === null) {
4286
- this.calibLogger?.warn({
4287
- group: groupCode,
4288
- seq: item.messageSeq
4289
- }, "ob11: 精华新增 sender_uin 缺失(跳过事件)");
4290
- continue;
4291
- }
4292
- const messageId = await this.resolveEssenceMsgId(groupCode, item.messageSeq);
4293
- if (messageId === null) continue;
4294
- const operatorId = numericUin(item.operatorUin);
4295
- this.broadcastEvent({
4296
- time: item.addDigestTime ?? Math.floor(Date.now() / MS_TO_SEC),
4297
- self_id: Number(this.selfUin),
4298
- post_type: "notice",
4299
- notice_type: "group_essence",
4300
- sub_type: "add",
4301
- group_id: Number(groupCode),
4302
- sender_id: senderId,
4303
- ...operatorId !== null ? { operator_id: operatorId } : {},
4304
- message_id: messageId
4305
- });
4306
- }
4307
- }
4308
- /** diff 移除项 → group_essence delete(sender 从 prev 缓存回填;operator 无数据源省略)。 */
4309
- async broadcastEssenceRemoved(groupCode, removed, prev) {
4310
- for (const seq of removed) {
4311
- const senderId = numericUin(prev.get(seq)?.senderUin ?? null);
4312
- if (senderId === null) {
4313
- this.calibLogger?.warn({
4314
- group: groupCode,
4315
- seq
4316
- }, "ob11: 精华移除 sender 不可得(跳过事件)");
4317
- continue;
4318
- }
4319
- const messageId = await this.resolveEssenceMsgId(groupCode, seq);
4320
- if (messageId === null) continue;
4321
- this.broadcastEvent({
4322
- time: Math.floor(Date.now() / MS_TO_SEC),
4323
- self_id: Number(this.selfUin),
4324
- post_type: "notice",
4325
- notice_type: "group_essence",
4326
- sub_type: "delete",
4327
- group_id: Number(groupCode),
4328
- sender_id: senderId,
4329
- message_id: messageId
4330
- });
4331
- }
4332
- }
4333
- /**
4334
- * 精华 message_id 反查:msgSeq → 近段历史扫描(60 条,对齐 milky
4335
- * resolveMsgIdBySeq fallback 层)→ MessageUnique.alloc 幂等分配(可被 get_msg
4336
- * 反查的正确空间,对照 recall 的 msgSeq 错位)。未命中返回 null(跳过事件)。
4337
- */
4338
- async resolveEssenceMsgId(groupCode, seq) {
4339
- const peer = {
4340
- chatType: ChatType.GROUP,
4341
- peerUid: groupCode
4342
- };
4343
- const hit = (await this.oneBotApi.msgApi.fetchMessages(peer, { count: 60 }).catch(() => [])).find((m) => Number(m.msgSeq) === seq);
4344
- if (hit === void 0) {
4345
- this.calibLogger?.warn({
4346
- group: groupCode,
4347
- seq
4348
- }, "ob11: 精华 message_id 反查未命中(跳过事件)");
4349
- return null;
4350
- }
4351
- return this.oneBotApi.messageUnique.alloc(hit.msgId, peer);
4352
- }
4353
- /**
4354
- * 广播消息事件(P2-19:接收方向 ID 转换)。
4355
- * 收集 at uid → 一次批量 uidToUin → 构造上下文 → 翻译广播。
4356
- * 群消息另查发送者角色(GroupCache 缓存优先,失败回退缺省 member)。
4357
- * 翻译失败退化为原样(不阻塞上报)。
4358
- */
4359
- async broadcastMessageEvent(msg) {
4360
- const { atUids } = collectReceiveNeeds(toCanonicalElements(msg));
4361
- let uidToUin;
4362
- if (atUids.length > 0) try {
4363
- uidToUin = await this.oneBotApi.uidToUin(atUids);
4364
- } catch {}
4365
- const senderRole = msg.chatType === ChatType.GROUP ? await this.oneBotApi.groupMemberRole(msg.peerUid, msg.senderUid) : void 0;
4366
- const ctx = {
4367
- ...uidToUin !== void 0 ? { uidToUin } : {},
4368
- ...senderRole !== void 0 ? { senderRole } : {},
4369
- msgIdToOb11Id: (msgId) => this.oneBotApi.messageUnique.getMessageId(msgId)
4370
- };
4371
- this.broadcastEvent(toOb11MessageEvent(msg, this.selfUin, this.oneBotApi.messageUnique, this.messageFormat, ctx));
4372
- }
4373
- /** 广播 grayTip → notice 事件(批量 uidToUin 后翻译,纯函数)。 */
4374
- async broadcastNotice(msg) {
4375
- const uids = collectGrayTipUids(msg);
4376
- let uidToUin = /* @__PURE__ */ new Map();
4377
- if (uids.length > 0) uidToUin = await this.oneBotApi.uidToUin(uids);
4378
- const notice = toOb11NoticeEvent(msg, {
4379
- selfUin: this.selfUin,
4380
- uidToUin,
4381
- ...this.calibLogger !== void 0 ? { logger: this.calibLogger } : {}
4382
- });
4383
- if (notice !== null) this.broadcastEvent(notice);
4384
- }
4385
- /** 广播群系统通知 → OB11 group request 事件(批量 uidToUin 后翻译,纯函数)。 */
4386
- async broadcastGroupRequests(notifies) {
4387
- const ctx = {
4388
- selfUin: this.selfUin,
4389
- uidToUin: await this.uidToUinMap(collectGroupNotifyUids(notifies))
4390
- };
4391
- for (const n of notifies) {
4392
- const event = toOb11GroupRequestEvent(n, ctx);
4393
- if (event !== null) this.broadcastEvent(event);
4394
- }
4395
- }
4396
- /** 广播好友申请 → OB11 friend request 事件(批量 uidToUin 后翻译,纯函数)。 */
4397
- async broadcastFriendRequests(reqs) {
4398
- const ctx = {
4399
- selfUin: this.selfUin,
4400
- uidToUin: await this.uidToUinMap(reqs.map((r) => r.friendUid).filter((uid) => uid !== ""))
4401
- };
4402
- for (const req of reqs) this.broadcastEvent(toOb11FriendRequestEvent(req, ctx));
4403
- }
4404
- /** uid 批量 → uin(失败退空 Map:翻译层退化为 uid 数值,不阻塞请求上报)。 */
4405
- async uidToUinMap(uids) {
4406
- if (uids.length === 0) return /* @__PURE__ */ new Map();
4407
- try {
4408
- return await this.oneBotApi.uidToUin(uids);
4409
- } catch {
4410
- return /* @__PURE__ */ new Map();
4411
- }
4412
- }
4413
- /** 退订(幂等)。 */
4414
- unsubscribeAll() {
4415
- for (const off of this.unsubscribes) off();
4416
- this.unsubscribes = [];
4455
+ this.pipeline.unsubscribeAll();
4417
4456
  }
4418
- /**
4419
- * 请求分发(挂到 network transport 的 onRequest):
4420
- * OB11 标准请求 { action, params, echo } → 动作注册表 → handle(HTTP)/websocketHandle(WS)。
4421
- */
4457
+ /** 请求分发(挂到 transport 的 onRequest):{ action, params, echo } → 注册表分发。 */
4422
4458
  async handleRequest(req, respond) {
4423
4459
  const parsed = req ?? {};
4424
4460
  const { action: rawAction, echo } = parsed;
@@ -4450,15 +4486,6 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
4450
4486
  respond(result);
4451
4487
  }
4452
4488
  };
4453
- /** 收集群系统通知涉及的 uid(user1/user2 双方,空 uid 跳过)。 */
4454
- function collectGroupNotifyUids(notifies) {
4455
- const uids = [];
4456
- for (const n of notifies) {
4457
- const notify = n;
4458
- for (const u of [notify.user1, notify.user2]) if (typeof u?.uid === "string" && u.uid !== "") uids.push(u.uid);
4459
- }
4460
- return uids;
4461
- }
4462
4489
  export { MessageUnique, NapukettoOneBot11Adapter, OneBotApi, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
4463
4490
 
4464
4491
  //# sourceMappingURL=index.mjs.map