@napuketto/adapter 0.24.6 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -870,6 +870,7 @@ interface AssembleOb11TransportsOptions {
870
870
  handleRequest: (req: unknown, respond: (res: unknown) => void) => void;
871
871
  /** 机器人自身 uin(koishi 等第三方按 X-Self-ID 识别连接归属)。 */
872
872
  selfUin: string;
873
+ logger?: Pick<AdapterLoggerLike, "warn"> | undefined;
873
874
  }
874
875
  /** 按配置装配 OB11 传输。 */
875
876
  declare function assembleOb11Transports(opts: AssembleOb11TransportsOptions): Ob11TransportSet;
package/dist/index.d.mts CHANGED
@@ -18,7 +18,7 @@
18
18
  import { _ as ErrorCodeMap, a as ProtocolConfig, c as ProtocolHooks, g as ActionOutcome, h as ActionKernelSpec, i as ConfigSchema, m as ActionRegistry, n as ConfigFormat, o as createServerSchema, r as ConfigOptions, s as BaseProtocolAdapter, t as ConfigBase, v as runAction } from "./index-BO1TgLTT.mjs";
19
19
  import { et as KurobotConfig, l as KurobotAdapterOptions, nt as kurobotConfigSchema, u as NapukettoKurobotAdapter } from "./index-tW3a05Du.mjs";
20
20
  import { G as MilkyConfig, K as milkyConfigSchema, L as MilkyAdapterOptions, R as NapukettoMilkyAdapter } from "./index-CWUA38Aw.mjs";
21
- import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-Beq1S5ad.mjs";
21
+ import { C as ob11ConfigSchema, S as OB11Config, o as NapukettoOneBot11Adapter, s as OneBot11AdapterOptions } from "./index-k9tVdOyb.mjs";
22
22
  import { R as SatoriConfig, d as NapukettoSatoriAdapter, f as SatoriAdapterOptions, z as satoriConfigSchema } from "./index-DNuLYcSP.mjs";
23
23
  import { z } from "zod";
24
24
  declare const protocolMediaSchema: z.ZodObject<{
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { f as ActionRegistry, n as ProtocolConfig, o as BaseProtocolAdapter, p as runAction, r as createServerSchema, t as ConfigBase } from "./framework-CA3087JP.mjs";
2
2
  import { N as kurobotConfigSchema, t as NapukettoKurobotAdapter } from "./kurobot-xqbvEUYA.mjs";
3
- import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-DmlPzIeg.mjs";
4
- import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-Bq9Qd9ys.mjs";
3
+ import { r as milkyConfigSchema, t as NapukettoMilkyAdapter } from "./milky-DqdxZQV2.mjs";
4
+ import { t as NapukettoOneBot11Adapter, u as ob11ConfigSchema } from "./onebot11-zpsm4o9D.mjs";
5
5
  import { m as satoriConfigSchema, t as NapukettoSatoriAdapter } from "./satori-Cmu2QGGz.mjs";
6
6
  export { ActionRegistry, BaseProtocolAdapter, ConfigBase, NapukettoKurobotAdapter, NapukettoMilkyAdapter, NapukettoOneBot11Adapter, NapukettoSatoriAdapter, ProtocolConfig, createServerSchema, kurobotConfigSchema, milkyConfigSchema, ob11ConfigSchema, runAction, satoriConfigSchema };
@@ -1 +1 @@
1
- export { a as MilkyApi, t as NapukettoMilkyAdapter, n as assembleMilkyTransports, i as createMilkyActionRegistry, r as milkyConfigSchema, o as milkyErrorCodeMap } from "../milky-DmlPzIeg.mjs";
1
+ export { a as MilkyApi, t as NapukettoMilkyAdapter, n as assembleMilkyTransports, i as createMilkyActionRegistry, r as milkyConfigSchema, o as milkyErrorCodeMap } from "../milky-DqdxZQV2.mjs";
@@ -3202,20 +3202,18 @@ function assembleMilkyTransports(opts) {
3202
3202
  handleMilkyHttpRequest(ctx, req, respond, registry, logger);
3203
3203
  };
3204
3204
  const adapters = [server, hub];
3205
- for (const [index, url] of config.webhooks.entries()) {
3206
- const client = new HttpClient({
3207
- url,
3208
- ...token !== "" ? { headers: { authorization: `${BEARER_PREFIX}${token}` } } : {},
3209
- timeoutMs: 5e3,
3210
- onError: () => {
3211
- logger?.warn({
3212
- category: "webhook_delivery_failed",
3213
- index
3214
- }, "milky: webhook 推送失败");
3215
- }
3216
- });
3217
- adapters.push(client);
3218
- }
3205
+ const webhooks = config.webhooks.map((url, index) => new HttpClient({
3206
+ url,
3207
+ ...token !== "" ? { headers: { authorization: `${BEARER_PREFIX}${token}` } } : {},
3208
+ timeoutMs: 5e3,
3209
+ onError: () => {
3210
+ logger?.warn({
3211
+ category: "webhook_delivery_failed",
3212
+ index
3213
+ }, "milky: webhook 推送失败");
3214
+ }
3215
+ }));
3216
+ adapters.push(...webhooks);
3219
3217
  for (const adapter of adapters) broadcaster.register(adapter);
3220
3218
  let closing;
3221
3219
  return {
@@ -3224,7 +3222,7 @@ function assembleMilkyTransports(opts) {
3224
3222
  closing ??= (async () => {
3225
3223
  for (const adapter of adapters) broadcaster.unregister(adapter);
3226
3224
  try {
3227
- await hub.close();
3225
+ await Promise.all([hub.close(), ...webhooks.map((client) => client.close())]);
3228
3226
  } finally {
3229
3227
  await server.close();
3230
3228
  }
@@ -2,5 +2,5 @@
2
2
  * OneBot 11 协议适配器(当前主战场)
3
3
  * 公共面:类型 + 动作注册表 + 配置 schema + 翻译层(adapter.ts 于 打通 kernel 事件后接入)。
4
4
  */
5
- import { $ as OB11MessageInfo, A as serializeCqParts, B as canonicalToCqMessage, C as ob11ConfigSchema, D as escapeCqParam, E as encodeCqCode, F as ob11ErrorCodeMap, G as CurrentTalkative, H as cqMessageToCanonical, I as OneBotApi, J as GroupInfo, K as FriendInfo, L as OneBotApiOptions, M as Ob11ActionDeps, N as createOb11ActionRegistry, O as escapeCqText, P as AtAllRemainInfo, Q as OB11Message, R as OneBotSystemOptions, S as OB11Config, T as CqCode, U as cqMessageToSegments, V as canonicalToSegments, W as segmentsToCanonical, X as HonorMember, Y as GroupMemberInfo, Z as LoginInfo, _ as OB11GroupMessageEvent, a as assembleOb11Transports, at as VersionInfo, b as OB11BaseEvent, c as OB11Event, d as OB11RequestEvent, et as OB11MessageSegment, f as OB11NoticeEvent, g as OB11Status, h as OB11MetaEvent, i as Ob11TransportSet, it as StrangerInfo, j as unescapeCqText, k as parseCqMessage, l as OB11FriendRequestEvent, m as OB11LifecycleMetaEvent, n as Ob11OutboundTransport, nt as Sender, o as NapukettoOneBot11Adapter, p as OB11HeartbeatMetaEvent, q as GroupHonorInfo, r as Ob11OutboundWsReconnect, rt as Sex, s as OneBot11AdapterOptions, t as AssembleOb11TransportsOptions, tt as OB11Return, u as OB11GroupRequestEvent, v as OB11MessageEvent, w as segmentsToCqMessage, x as OB11PostType, y as OB11PrivateMessageEvent, z as MessageUnique } from "../index-Beq1S5ad.mjs";
5
+ import { $ as OB11MessageInfo, A as serializeCqParts, B as canonicalToCqMessage, C as ob11ConfigSchema, D as escapeCqParam, E as encodeCqCode, F as ob11ErrorCodeMap, G as CurrentTalkative, H as cqMessageToCanonical, I as OneBotApi, J as GroupInfo, K as FriendInfo, L as OneBotApiOptions, M as Ob11ActionDeps, N as createOb11ActionRegistry, O as escapeCqText, P as AtAllRemainInfo, Q as OB11Message, R as OneBotSystemOptions, S as OB11Config, T as CqCode, U as cqMessageToSegments, V as canonicalToSegments, W as segmentsToCanonical, X as HonorMember, Y as GroupMemberInfo, Z as LoginInfo, _ as OB11GroupMessageEvent, a as assembleOb11Transports, at as VersionInfo, b as OB11BaseEvent, c as OB11Event, d as OB11RequestEvent, et as OB11MessageSegment, f as OB11NoticeEvent, g as OB11Status, h as OB11MetaEvent, i as Ob11TransportSet, it as StrangerInfo, j as unescapeCqText, k as parseCqMessage, l as OB11FriendRequestEvent, m as OB11LifecycleMetaEvent, n as Ob11OutboundTransport, nt as Sender, o as NapukettoOneBot11Adapter, p as OB11HeartbeatMetaEvent, q as GroupHonorInfo, r as Ob11OutboundWsReconnect, rt as Sex, s as OneBot11AdapterOptions, t as AssembleOb11TransportsOptions, tt as OB11Return, u as OB11GroupRequestEvent, v as OB11MessageEvent, w as segmentsToCqMessage, x as OB11PostType, y as OB11PrivateMessageEvent, z as MessageUnique } from "../index-k9tVdOyb.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 Ob11OutboundTransport, type Ob11OutboundWsReconnect, 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-Bq9Qd9ys.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-zpsm4o9D.mjs";
@@ -1357,7 +1357,7 @@ const httpPostSchema = z.object({
1357
1357
  url: z.string().optional(),
1358
1358
  /** 实例级 token,覆盖全局 token(缺省继承全局)。 */
1359
1359
  token: z.string().optional(),
1360
- /** 上报超时(毫秒),缺省不超时。 */
1360
+ /** 上报超时(毫秒,含排队),缺省 5 秒。 */
1361
1361
  timeoutMs: z.number().int().optional()
1362
1362
  });
1363
1363
  /** 反向 WS server 实例(第三方 WS 连入,带 WS ping 间隔扩展字段)。 */
@@ -3764,7 +3764,7 @@ function assembleOb11Transports(opts) {
3764
3764
  const outbound = [];
3765
3765
  assembleHttpServers(config, handleRequest, servers);
3766
3766
  assembleWsServers(config, handleRequest, servers);
3767
- assembleHttpPosts(config, selfUin, transports, outbound);
3767
+ assembleHttpPosts(opts, transports, outbound);
3768
3768
  assembleWsReverses(config, selfUin, handleRequest, transports, outbound);
3769
3769
  for (const t of transports) broadcaster.register(t);
3770
3770
  for (const s of servers) broadcaster.register(s);
@@ -3773,8 +3773,9 @@ function assembleOb11Transports(opts) {
3773
3773
  transports,
3774
3774
  outbound,
3775
3775
  close: async () => {
3776
- await Promise.all([...servers, ...transports].map((t) => t.close()));
3777
- for (const t of [...servers, ...transports]) broadcaster.unregister(t);
3776
+ const adapters = [...servers, ...transports];
3777
+ for (const t of adapters) broadcaster.unregister(t);
3778
+ await Promise.all(adapters.map((t) => t.close()));
3778
3779
  }
3779
3780
  };
3780
3781
  }
@@ -3814,15 +3815,21 @@ function assembleWsServers(config, handleRequest, servers) {
3814
3815
  }
3815
3816
  }
3816
3817
  /** 装配 HTTP 正向上报 client 列表(fire-and-forget)。 */
3817
- function assembleHttpPosts(config, selfUin, transports, outbound) {
3818
- for (const item of config.httpPostUrls) if (item.enabled && item.url !== void 0) {
3818
+ function assembleHttpPosts({ config, selfUin, logger }, transports, outbound) {
3819
+ for (const [index, item] of config.httpPostUrls.entries()) if (item.enabled && item.url !== void 0) {
3819
3820
  const headers = {
3820
3821
  "x-self-id": selfUin,
3821
3822
  ...authorizeHeader(item.token ?? config.token) ?? {}
3822
3823
  };
3823
3824
  const options = {
3824
3825
  url: item.url,
3825
- headers
3826
+ headers,
3827
+ onError: () => {
3828
+ logger?.warn({
3829
+ category: "webhook_delivery_failed",
3830
+ index
3831
+ }, "onebot11: webhook 推送失败");
3832
+ }
3826
3833
  };
3827
3834
  if (item.timeoutMs !== void 0) options.timeoutMs = item.timeoutMs;
3828
3835
  const client = new HttpClient(options);
@@ -3933,6 +3940,7 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
3933
3940
  config,
3934
3941
  broadcaster,
3935
3942
  selfUin: this.selfUin,
3943
+ logger: this.logger,
3936
3944
  handleRequest: (req, respond) => {
3937
3945
  this.handleRequest(req, respond).catch((err) => {
3938
3946
  let message = String(err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@napuketto/adapter",
4
- "version": "0.24.6",
4
+ "version": "0.25.0",
5
5
  "type": "module",
6
6
  "description": "Protocol adapters (OneBot11 / Satori / KuroBot / Milky) for Napuketto",
7
7
  "keywords": [
@@ -82,9 +82,9 @@
82
82
  "dev": "tsdown --watch"
83
83
  },
84
84
  "dependencies": {
85
- "@napuketto/kernel": "^0.19.6",
85
+ "@napuketto/kernel": "^0.19.7",
86
86
  "@napuketto/media": "^0.4.1",
87
- "@napuketto/network": "^0.5.1",
87
+ "@napuketto/network": "^0.6.0",
88
88
  "zod": "^4.6.7"
89
89
  },
90
90
  "devDependencies": {