@napuketto/adapter 0.18.1 → 0.18.3

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 (41) hide show
  1. package/dist/{buddy-req-CN7gzJpq.mjs → buddy-req-BeEl05O8.mjs} +27 -3
  2. package/dist/{buddy-req-CN7gzJpq.mjs.map → buddy-req-BeEl05O8.mjs.map} +1 -1
  3. package/dist/core/index.d.mts +2 -2
  4. package/dist/core/index.mjs +1 -1
  5. package/dist/{core-4PwF_pJB.mjs → core-5cq8w_zB.mjs} +36 -2
  6. package/dist/core-5cq8w_zB.mjs.map +1 -0
  7. package/dist/{index-DAsCCf9S.d.mts → index-BFvhy1hU.d.mts} +2 -2
  8. package/dist/{index-DAsCCf9S.d.mts.map → index-BFvhy1hU.d.mts.map} +1 -1
  9. package/dist/{index-lKqnKSwo.d.mts → index-BHS4Wz74.d.mts} +2 -2
  10. package/dist/{index-lKqnKSwo.d.mts.map → index-BHS4Wz74.d.mts.map} +1 -1
  11. package/dist/{index-D9Nwf0_4.d.mts → index-BZfGz6FA.d.mts} +26 -3
  12. package/dist/index-BZfGz6FA.d.mts.map +1 -0
  13. package/dist/{index-CiitTshy.d.mts → index-BlRIp4xi.d.mts} +2 -2
  14. package/dist/{index-CiitTshy.d.mts.map → index-BlRIp4xi.d.mts.map} +1 -1
  15. package/dist/{index-CKH8uaU-.d.mts → index-oinf9f75.d.mts} +2 -2
  16. package/dist/{index-CKH8uaU-.d.mts.map → index-oinf9f75.d.mts.map} +1 -1
  17. package/dist/index.d.mts +5 -5
  18. package/dist/index.mjs +5 -5
  19. package/dist/kurobot/index.d.mts +1 -1
  20. package/dist/kurobot/index.mjs +1 -1
  21. package/dist/{kurobot-CG2qGU9G.mjs → kurobot-De610F3j.mjs} +3 -3
  22. package/dist/{kurobot-CG2qGU9G.mjs.map → kurobot-De610F3j.mjs.map} +1 -1
  23. package/dist/milky/index.d.mts +1 -1
  24. package/dist/milky/index.mjs +1 -1
  25. package/dist/{milky-DMmeotN9.mjs → milky-DvDcch01.mjs} +31 -70
  26. package/dist/milky-DvDcch01.mjs.map +1 -0
  27. package/dist/onebot11/index.d.mts +1 -1
  28. package/dist/onebot11/index.mjs +1 -1
  29. package/dist/{onebot11-CAf9fBoJ.mjs → onebot11-BL02tXe_.mjs} +30 -86
  30. package/dist/{onebot11-CAf9fBoJ.mjs.map → onebot11-BL02tXe_.mjs.map} +1 -1
  31. package/dist/{raw-message-Cs4vDKUU.mjs → raw-message-CXRlSiNk.mjs} +46 -12
  32. package/dist/raw-message-CXRlSiNk.mjs.map +1 -0
  33. package/dist/satori/index.d.mts +1 -1
  34. package/dist/satori/index.mjs +1 -1
  35. package/dist/{satori-D5lM6S3L.mjs → satori-CB-O6IN0.mjs} +5 -14
  36. package/dist/{satori-D5lM6S3L.mjs.map → satori-CB-O6IN0.mjs.map} +1 -1
  37. package/package.json +1 -1
  38. package/dist/core-4PwF_pJB.mjs.map +0 -1
  39. package/dist/index-D9Nwf0_4.d.mts.map +0 -1
  40. package/dist/milky-DMmeotN9.mjs.map +0 -1
  41. package/dist/raw-message-Cs4vDKUU.mjs.map +0 -1
@@ -2,5 +2,5 @@
2
2
  * OneBot 11 协议适配器(当前主战场)
3
3
  * 公共面:类型 + 动作注册表 + 配置 schema + 翻译层(adapter.ts 于 打通 kernel 事件后接入)。
4
4
  */
5
- import { $ as OB11Return, A as Ob11ActionDeps, B as cqMessageToCanonical, C as CqCode, D as parseCqMessage, E as escapeCqText, F as OneBotApiOptions, G as GroupHonorInfo, H as segmentsToCanonical, I as OneBotSystemOptions, J as HonorMember, K as GroupInfo, L as MessageUnique, M as AtAllRemainInfo, N as ob11ErrorCodeMap, O as serializeCqParts, P as OneBotApi, Q as OB11MessageSegment, R as canonicalToCqMessage, S as segmentsToCqMessage, T as escapeCqParam, U as CurrentTalkative, V as cqMessageToSegments, W as FriendInfo, X as OB11Message, Y as LoginInfo, Z as OB11MessageInfo, _ as OB11PrivateMessageEvent, a as OneBot11AdapterOptions, b as OB11Config, c as OB11GroupRequestEvent, d as OB11HeartbeatMetaEvent, et as Sender, f as OB11LifecycleMetaEvent, g as OB11MessageEvent, h as OB11GroupMessageEvent, i as NapukettoOneBot11Adapter, j as createOb11ActionRegistry, k as unescapeCqText, l as OB11RequestEvent, m as OB11Status, n as Ob11TransportSet, nt as StrangerInfo, o as OB11Event, p as OB11MetaEvent, q as GroupMemberInfo, r as assembleOb11Transports, rt as VersionInfo, s as OB11FriendRequestEvent, t as AssembleOb11TransportsOptions, tt as Sex, u as OB11NoticeEvent, v as OB11BaseEvent, w as encodeCqCode, x as ob11ConfigSchema, y as OB11PostType, z as canonicalToSegments } from "../index-lKqnKSwo.mjs";
5
+ import { $ as OB11Return, A as Ob11ActionDeps, B as cqMessageToCanonical, C as CqCode, D as parseCqMessage, E as escapeCqText, F as OneBotApiOptions, G as GroupHonorInfo, H as segmentsToCanonical, I as OneBotSystemOptions, J as HonorMember, K as GroupInfo, L as MessageUnique, M as AtAllRemainInfo, N as ob11ErrorCodeMap, O as serializeCqParts, P as OneBotApi, Q as OB11MessageSegment, R as canonicalToCqMessage, S as segmentsToCqMessage, T as escapeCqParam, U as CurrentTalkative, V as cqMessageToSegments, W as FriendInfo, X as OB11Message, Y as LoginInfo, Z as OB11MessageInfo, _ as OB11PrivateMessageEvent, a as OneBot11AdapterOptions, b as OB11Config, c as OB11GroupRequestEvent, d as OB11HeartbeatMetaEvent, et as Sender, f as OB11LifecycleMetaEvent, g as OB11MessageEvent, h as OB11GroupMessageEvent, i as NapukettoOneBot11Adapter, j as createOb11ActionRegistry, k as unescapeCqText, l as OB11RequestEvent, m as OB11Status, n as Ob11TransportSet, nt as StrangerInfo, o as OB11Event, p as OB11MetaEvent, q as GroupMemberInfo, r as assembleOb11Transports, rt as VersionInfo, s as OB11FriendRequestEvent, t as AssembleOb11TransportsOptions, tt as Sex, u as OB11NoticeEvent, v as OB11BaseEvent, w as encodeCqCode, x as ob11ConfigSchema, y as OB11PostType, z as canonicalToSegments } from "../index-BHS4Wz74.mjs";
6
6
  export { type AssembleOb11TransportsOptions, type AtAllRemainInfo, type CqCode, type CurrentTalkative, type FriendInfo, type GroupHonorInfo, type GroupInfo, type GroupMemberInfo, type HonorMember, type LoginInfo, MessageUnique, NapukettoOneBot11Adapter, type OB11BaseEvent, type OB11Config, type OB11Event, type OB11FriendRequestEvent, type OB11GroupMessageEvent, type OB11GroupRequestEvent, type OB11HeartbeatMetaEvent, type OB11LifecycleMetaEvent, type OB11Message, type OB11MessageEvent, type OB11MessageInfo, type OB11MessageSegment, type OB11MetaEvent, type OB11NoticeEvent, type OB11PostType, type OB11PrivateMessageEvent, type OB11RequestEvent, type OB11Return, type OB11Status, type Ob11ActionDeps, type Ob11TransportSet, type OneBot11AdapterOptions, OneBotApi, type OneBotApiOptions, type OneBotSystemOptions, type Sender, type Sex, type StrangerInfo, type VersionInfo, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
@@ -1 +1 @@
1
- export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-CAf9fBoJ.mjs";
1
+ export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-BL02tXe_.mjs";
@@ -1,7 +1,7 @@
1
- import { a as resolveProtocolConfig, i as BaseProtocolAdapter, o as ActionRegistry, r as createServerSchema, s as runAction } from "./core-4PwF_pJB.mjs";
2
- import { a as firstNonEmptyString, c as MS_TO_SEC, f as toUin, i as toUnixSeconds, l as NUMERIC_RE, n as senderNickname, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, u as numericUin } from "./raw-message-Cs4vDKUU.mjs";
1
+ import { a as resolveProtocolConfig, i as BaseProtocolAdapter, l as ActionRegistry, o as BEARER_PREFIX, r as createServerSchema, s as createTokenAuthorize, u as runAction } from "./core-5cq8w_zB.mjs";
2
+ import { a as firstNonEmptyString, c as MS_TO_SEC, d as numericUin, f as resolveUidToUinWithFallback, i as toUnixSeconds, l as NUMERIC_RE, m as toUin, n as senderNickname, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, u as collectGroupNotifyUids } from "./raw-message-CXRlSiNk.mjs";
3
3
  import { a as logEventFailure, c as downloadBufferToFile, d as prepareVideoElements, i as hasGrayTip, l as ensureSilk, o as sliceRaw, r as firstUntranslatedGrayTip, s as truncRaw, t as collectGrayTipUids, u as fileUriToPath } from "./gray-tip-DmZmdtjP.mjs";
4
- import { a as EssenceListSync, c as OBSERVED_UNNAMED_SYSMSG_KEYS, d as processSysMsgBlob, f as recognizeSysMsg, i as narrowBuddyReqs, l as narrowSysMsgBlobs, n as batchUnreadNums, o as extractEssenceSetSysMsg, r as filterBuddyReqs, s as narrowEssenceGroupArg, t as BuddyReqDedup } from "./buddy-req-CN7gzJpq.mjs";
4
+ import { a as narrowEssenceGroupArg, i as extractEssenceSetSysMsg, l as processSysMsgBlob, n as processInboundBuddyReqs, o as OBSERVED_UNNAMED_SYSMSG_KEYS, r as EssenceListSync, s as narrowSysMsgBlobs, t as BuddyReqDedup, u as recognizeSysMsg } from "./buddy-req-BeEl05O8.mjs";
5
5
  import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, hasStringProp, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
6
6
  import { HttpClient, HttpServer, WsClient, WsServer } from "@napuketto/network";
7
7
  import { z } from "zod";
@@ -3040,8 +3040,6 @@ var OneBotApi = class {
3040
3040
  }
3041
3041
  };
3042
3042
  // src/onebot11/enrichment.ts
3043
- /** 资料详情兜底的单批上限(好友申请批通常只有个位数,超限多为历史积压)。 */
3044
- const MAX_PROFILE_LOOKUPS = 10;
3045
3043
  /** OB11 收链路异步回填器。 */
3046
3044
  var Ob11Enrichment = class {
3047
3045
  api;
@@ -3055,39 +3053,17 @@ var Ob11Enrichment = class {
3055
3053
  *
3056
3054
  * 群成员口径(`getUinByUids`)解析不到的 uid 用资料详情兜底(issue #122):
3057
3055
  * 好友申请的申请人通常不在任何群里,群口径必然失败,不回退会让 `user_id` 恒 0。
3056
+ * 批量 / 兜底的 fail-soft 留痕在共享原语内完成。
3058
3057
  */
3059
3058
  async uidToUinMap(uids) {
3060
- if (uids.length === 0) return /* @__PURE__ */ new Map();
3061
- let map;
3062
- try {
3063
- map = await this.api.uidToUin(uids);
3064
- } catch (err) {
3065
- this.calibLogger?.warn({
3066
- count: uids.length,
3067
- error: errorMessage(err)
3068
- }, "ob11: 请求 uid→uin 批量转换失败,退用 uid");
3069
- map = /* @__PURE__ */ new Map();
3070
- }
3071
- await this.fillMissingUins(uids, map);
3072
- return map;
3073
- }
3074
- /**
3075
- * 群口径未命中的 uid 逐个走 `profileApi.getUinByUid` 兜底(原地补 map)。
3076
- * fail-soft:单条失败 / 查不到保持未命中(翻译层退 0);条数设上限,防历史积压
3077
- * 批次把逐条 IPC 打满。
3078
- */
3079
- async fillMissingUins(uids, map) {
3080
- const missing = [...new Set(uids)].filter((uid) => uid !== "" && !map.has(uid));
3081
- for (const uid of missing.slice(0, MAX_PROFILE_LOOKUPS)) try {
3082
- const uin = await this.api.profileApi.getUinByUid(uid);
3083
- if (uin !== null) map.set(uid, uin);
3084
- } catch (err) {
3085
- this.calibLogger?.debug({ error: errorMessage(err) }, "ob11: uid→uin 资料兜底失败(该 uid 退 0)");
3086
- }
3087
- if (missing.length > MAX_PROFILE_LOOKUPS) this.calibLogger?.debug({
3088
- missing: missing.length,
3089
- limit: MAX_PROFILE_LOOKUPS
3090
- }, "ob11: 待兜底 uid 超上限,其余保持未命中");
3059
+ return resolveUidToUinWithFallback(uids, {
3060
+ uidToUin: (batch) => this.api.uidToUin(batch),
3061
+ getUinByUid: (uid) => this.api.profileApi.getUinByUid(uid),
3062
+ logger: this.calibLogger,
3063
+ scope: "ob11",
3064
+ batchWarnMsg: "ob11: 请求 uid→uin 批量转换失败,退用 uid",
3065
+ profileFallback: true
3066
+ });
3091
3067
  }
3092
3068
  /**
3093
3069
  * notice uid 批量转换(空集退空 Map)。失败上抛不吞:grayTip 解析宽容但
@@ -3491,20 +3467,13 @@ var Ob11InboundRequest = class {
3491
3467
  }
3492
3468
  /** 好友申请翻译派发(flag=reqTime;uid→uin 批量失败退空 Map)。 */
3493
3469
  async broadcastBuddyReqs(arg) {
3494
- if (batchUnreadNums(arg) === 0) {
3495
- this.deps.logger?.debug({}, "ob11: onBuddyReqChange unreadNums=0(整批跳过)");
3496
- return;
3497
- }
3498
- const reqs = narrowBuddyReqs(arg);
3499
- if (reqs === null) {
3500
- this.deps.logger?.warn({ raw: truncRaw(JSON.stringify(arg)) }, "ob11: onBuddyReqChange 未知参数形状");
3501
- return;
3502
- }
3503
- const fresh = filterBuddyReqs(reqs, this.baselineSec).filter((req) => this.dedup.claim(req));
3504
- if (fresh.length < reqs.length) this.deps.logger?.debug({
3505
- total: reqs.length,
3506
- kept: fresh.length
3507
- }, "ob11: 好友申请过滤(历史积压 / 已读 / 已处理 / 重复)");
3470
+ const fresh = processInboundBuddyReqs(arg, {
3471
+ baselineSec: this.baselineSec,
3472
+ dedup: this.dedup,
3473
+ scope: "ob11",
3474
+ formatRaw: truncRaw,
3475
+ logger: this.deps.logger
3476
+ });
3508
3477
  if (fresh.length === 0) return;
3509
3478
  const ctx = await this.requestCtx(fresh.map((r) => r.friendUid).filter((uid) => uid !== ""));
3510
3479
  for (const req of fresh) this.deps.broadcast(toOb11FriendRequestEvent(req, ctx));
@@ -3517,12 +3486,6 @@ var Ob11InboundRequest = class {
3517
3486
  };
3518
3487
  }
3519
3488
  };
3520
- /** 收集群系统通知涉及的 uid(user1/user2 双方,空 uid 跳过)。 */
3521
- function collectGroupNotifyUids(notifies) {
3522
- const uids = [];
3523
- for (const notify of notifies) for (const user of [notify.user1, notify.user2]) if (typeof user?.uid === "string" && user.uid !== "") uids.push(user.uid);
3524
- return uids;
3525
- }
3526
3489
  // src/onebot11/helper/sysmsg.ts
3527
3490
  /**
3528
3491
  * OB11 sysmsg 识别表(自 helper/sysmsg.ts 瘦身——解码层上移
@@ -3689,35 +3652,10 @@ var Ob11EventPipeline = class {
3689
3652
  * - HTTP 正向(httpPost.enabled):HttpClient 事件上报(fire-and-forget)
3690
3653
  * - WS 正向(wsReverse.enabled):WsClient 主动连第三方(双向)
3691
3654
  *
3692
- * 鉴权:token 存在时校验 Authorization: Bearer <token> / access_token 查询参数。
3655
+ * 鉴权:token 存在时校验 Authorization: Bearer <token> / 裸 authorization 头 /
3656
+ * access_token 查询参数(方言开关由 core 鉴权原语参数化)。
3693
3657
  * 返回 transports(事件上报用,注册到 broadcaster)与 close(停止时关闭全部)。
3694
3658
  */
3695
- /** Authorization 头前缀。 */
3696
- const BEARER_PREFIX = "Bearer ";
3697
- /** 校验 URL 查询参数里的 access_token(WS client 连接 URL 可能带)。
3698
- * ⚠️ req.url 是纯路径(无 origin),new URL(相对路径) 必抛——
3699
- * E2E 实测抓到的 bug(查询参数鉴权从未生效,WS 全被 4401 关闭),
3700
- * 用 dummy base 解析。 */
3701
- function hasAccessTokenQuery(url, token) {
3702
- try {
3703
- return new URL(url, "http://localhost").searchParams.get("access_token") === token;
3704
- } catch {
3705
- return false;
3706
- }
3707
- }
3708
- /** 校验 Authorization: Bearer <token> 头。 */
3709
- function checkBearer(auth, token) {
3710
- if (auth === void 0 || !auth.startsWith(BEARER_PREFIX)) return false;
3711
- return auth.slice(7) === token;
3712
- }
3713
- /** 构造鉴权钩子(token 未配置则不鉴权)。 */
3714
- function makeAuthorize(token) {
3715
- if (token === void 0 || token === "") return;
3716
- return (ctx) => {
3717
- if (checkBearer(ctx.headers["authorization"] ?? ctx.headers["Authorization"], token) || ctx.headers["authorization"] === token) return true;
3718
- return hasAccessTokenQuery(ctx.url, token);
3719
- };
3720
- }
3721
3659
  /**
3722
3660
  * OneBot 客户端标识头:koishi 的 onebot 适配器按
3723
3661
  * x-client-role === "Universal" 与 x-self-id 校验 WS 连接(NapCat 同款头),
@@ -3757,7 +3695,10 @@ function assembleHttpServers(config, handleRequest, servers) {
3757
3695
  host: item.host,
3758
3696
  port: item.port
3759
3697
  };
3760
- const authorize = makeAuthorize(item.token ?? config.token);
3698
+ const authorize = createTokenAuthorize(item.token ?? config.token, {
3699
+ allowQueryToken: true,
3700
+ allowRawHeader: true
3701
+ });
3761
3702
  if (authorize !== void 0) options.authorize = authorize;
3762
3703
  const server = new HttpServer(options);
3763
3704
  server.onRequest = handleRequest;
@@ -3772,7 +3713,10 @@ function assembleWsServers(config, handleRequest, servers) {
3772
3713
  port: item.port,
3773
3714
  heartbeat: { intervalMs: item.heartbeatInterval }
3774
3715
  };
3775
- const authorize = makeAuthorize(item.token ?? config.token);
3716
+ const authorize = createTokenAuthorize(item.token ?? config.token, {
3717
+ allowQueryToken: true,
3718
+ allowRawHeader: true
3719
+ });
3776
3720
  if (authorize !== void 0) options.authorize = authorize;
3777
3721
  const server = new WsServer(options);
3778
3722
  server.onRequest = handleRequest;
@@ -4001,4 +3945,4 @@ function echoFieldOf(req) {
4001
3945
  }
4002
3946
  export { unescapeCqText as _, canonicalToCqMessage as a, cqMessageToSegments as c, segmentsToCqMessage as d, encodeCqCode as f, serializeCqParts as g, parseCqMessage as h, createOb11ActionRegistry as i, segmentsToCanonical as l, escapeCqText as m, assembleOb11Transports as n, canonicalToSegments as o, escapeCqParam as p, OneBotApi as r, cqMessageToCanonical as s, NapukettoOneBot11Adapter as t, ob11ConfigSchema as u, ob11ErrorCodeMap as v, MessageUnique as y };
4003
3947
 
4004
- //# sourceMappingURL=onebot11-CAf9fBoJ.mjs.map
3948
+ //# sourceMappingURL=onebot11-BL02tXe_.mjs.map