@zhin.js/adapter-onebot12 3.0.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +460 -0
  2. package/README.md +40 -74
  3. package/adapters/onebot12.ts +50 -0
  4. package/lib/index.d.ts +6 -19
  5. package/lib/index.js +5 -27
  6. package/lib/protocol.d.ts +151 -0
  7. package/lib/protocol.js +242 -0
  8. package/lib/webhook.d.ts +25 -0
  9. package/lib/webhook.js +140 -0
  10. package/lib/ws-endpoint.d.ts +25 -0
  11. package/lib/ws-endpoint.js +240 -0
  12. package/lib/ws-types.d.ts +16 -0
  13. package/lib/ws-types.js +1 -0
  14. package/lib/wss-auth.d.ts +2 -0
  15. package/lib/wss-auth.js +16 -0
  16. package/lib/wss-endpoint.d.ts +24 -0
  17. package/lib/wss-endpoint.js +193 -0
  18. package/package.json +41 -15
  19. package/plugin.ts +8 -0
  20. package/schema.json +66 -0
  21. package/src/index.ts +46 -37
  22. package/src/protocol.ts +387 -0
  23. package/src/webhook.ts +180 -0
  24. package/src/ws-endpoint.ts +287 -0
  25. package/src/ws-types.ts +19 -0
  26. package/src/wss-auth.ts +17 -0
  27. package/src/wss-endpoint.ts +226 -0
  28. package/lib/adapter.d.ts +0 -20
  29. package/lib/adapter.d.ts.map +0 -1
  30. package/lib/adapter.js +0 -43
  31. package/lib/adapter.js.map +0 -1
  32. package/lib/api.d.ts +0 -14
  33. package/lib/api.d.ts.map +0 -1
  34. package/lib/api.js +0 -34
  35. package/lib/api.js.map +0 -1
  36. package/lib/endpoint-webhook.d.ts +0 -25
  37. package/lib/endpoint-webhook.d.ts.map +0 -1
  38. package/lib/endpoint-webhook.js +0 -122
  39. package/lib/endpoint-webhook.js.map +0 -1
  40. package/lib/endpoint-ws.d.ts +0 -26
  41. package/lib/endpoint-ws.d.ts.map +0 -1
  42. package/lib/endpoint-ws.js +0 -214
  43. package/lib/endpoint-ws.js.map +0 -1
  44. package/lib/endpoint-wss.d.ts +0 -26
  45. package/lib/endpoint-wss.d.ts.map +0 -1
  46. package/lib/endpoint-wss.js +0 -191
  47. package/lib/endpoint-wss.js.map +0 -1
  48. package/lib/index.d.ts.map +0 -1
  49. package/lib/index.js.map +0 -1
  50. package/lib/segment-mapper.d.ts +0 -2
  51. package/lib/segment-mapper.d.ts.map +0 -1
  52. package/lib/segment-mapper.js +0 -2
  53. package/lib/segment-mapper.js.map +0 -1
  54. package/lib/types.d.ts +0 -77
  55. package/lib/types.d.ts.map +0 -1
  56. package/lib/types.js +0 -5
  57. package/lib/types.js.map +0 -1
  58. package/lib/utils.d.ts +0 -45
  59. package/lib/utils.d.ts.map +0 -1
  60. package/lib/utils.js +0 -62
  61. package/lib/utils.js.map +0 -1
  62. package/src/adapter.ts +0 -56
  63. package/src/api.ts +0 -48
  64. package/src/endpoint-webhook.ts +0 -136
  65. package/src/endpoint-ws.ts +0 -228
  66. package/src/endpoint-wss.ts +0 -208
  67. package/src/segment-mapper.ts +0 -1
  68. package/src/types.ts +0 -86
  69. package/src/utils.ts +0 -89
package/CHANGELOG.md ADDED
@@ -0,0 +1,460 @@
1
+ # @zhin.js/adapter-onebot12
2
+
3
+ ## 4.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7db69c1: 命令前缀改为适配器配置项:`MessageDispatcher` 不再硬编码 `/`,默认按消息所属适配器实例 config 的 `commandPrefix` 解析(默认 `''` 无前缀,任意文本按命令匹配),`endpoints[i].commandPrefix` 逐项覆盖;`ImRuntime({ commandPrefix })` 仍可设全局静态前缀。全部 20 个平台适配器 schema 新增 `commandPrefix` 属性。
8
+
9
+ BREAKING(行为变化):未配置时命令不再需要 `/` 前缀——原 `/zt` 写法不再命中,直接发 `zt` 即可;需要斜杠风格的适配器请在配置里显式设 `commandPrefix: '/'`。
10
+
11
+ - 713445c: 适配器配置格式定稿(不兼容旧格式):`plugins.<adapter>` 顶层仅共享字段 + `commandPrefix`,`endpoints[i]` 携带 endpoint 级字段(`name` + 凭据,各 schema 已类型化),`endpoints` 为必填(icqq 另需顶层 `master`);icqq 新增 `trusted` 列表(顶层/逐项均可)。scaffold-wizard 全部字段式与自定义 configure() 产出改为新格式,examples(full-bot / qq-games-bot)与 20 个适配器 README 同步迁移。
12
+ - Updated dependencies [7db69c1]
13
+ - Updated dependencies [e5c84ed]
14
+ - Updated dependencies [3ea84a0]
15
+ - Updated dependencies [1ddcd70]
16
+ - Updated dependencies [ac9da66]
17
+ - @zhin.js/core@1.4.0
18
+ - @zhin.js/adapter@1.1.0
19
+ - @zhin.js/plugin-runtime@1.1.0
20
+ - @zhin.js/host-http@1.0.2
21
+ - zhin.js@5.0.0
22
+
23
+ ## 3.0.3
24
+
25
+ ### Patch Changes
26
+
27
+ - cc5c94d: 约定式插件运行时迁移(breaking):插件与适配器由 `usePlugin()` / `extends Adapter` 迁移为 `definePlugin` / `defineAdapter` + `plugin.ts` + 约定目录(`adapters/`、`commands/`、`components/`、`tools/` 等)。
28
+
29
+ - 新增约定式运行时包:`@zhin.js/plugin-runtime`、`@zhin.js/adapter`、`@zhin.js/runtime`、`@zhin.js/host-http`(首版 1.0.0 走 init-publish,不在本 changeset 内 bump)。
30
+ - 全部 20 个平台适配器改为约定式 `defineAdapter`,旧 `usePlugin` / `extends Adapter` / `segment-mapper` 生产入口已删除;onebot11 反向 WSS、onebot12 webhook/wss、milky sse/webhook/wss、satori webhook、kook webhook、qq webhook/middleware 等 slice 1 推迟的连接模式已补齐。
31
+ - 游戏 / 工具 / 服务插件同步迁移到约定目录结构。
32
+ - CLI 增加 plugin-runtime host installer(http/database/outbound/schedule/console 等)。
33
+
34
+ 后续加固(同批):
35
+
36
+ - CLI:`zhin runtime start --daemon`(pidfile/崩溃拉起/风暴保护),orphan watchdog 防僵尸进程;legacy `zhin dev` / `zhin start` 已移除(含 `zhin restart`),`zhin stop` 兼容新 daemon。
37
+ - 安全:builtin 工具统一走 `security/policy-facade.ts` 的 `runToolPolicies`(声明式策略表,deny 优先);审计日志 close flush + 背压队列;`splitCompoundCommand` 引号感知、`extractCommandName` 去引号堵绕过。
38
+ - 日志:Logger 双堆栈修复、本地时区、`getLogger` 挂树(`setLevel` 递归生效)、第三方库(log4js/discord)桥接、启动人读总结。
39
+ - 结构:`plugins/games/shared` 迁为 `packages/game-kit`(`@zhin.js/game-kit`);死目录 `plugins/adapters/common` 删除。
40
+ - 脚手架:`create-zhin-app` / `zhin new` / scaffold-wizard 生成物改为 Plugin Runtime 形态(minimal-bot 同构,新配置格式)。
41
+ - Console:endpoint.list 真实名称与 phase、schema:get-all 按 instanceKey 映射、db:\* 接 DatabaseHost。
42
+
43
+ 注:按仓库发布惯例(见 1bb345dd2),本次 breaking 迁移统一使用 patch,避免 zhin.js 5.0 级联。
44
+
45
+ - 447f3e2: 迁移缺口修复(legacy 功能对齐):
46
+
47
+ - html 段出站规范化:经 `@zhin.js/html-renderer` 渲染为 image 段(sandbox 豁免、无渲染器时降级文本),修复真实平台 `[object Object]`。
48
+ - 群聊 @ 触发 AI:适配器入站标注 `metadata.mentioned`(icqq/qq/slack/onebot11/onebot12/napcat/milky/discord/telegram/kook/dingtalk/satori),`matchAiTrigger` 补齐 ignorePrefixes/respondToAt/respondToPrivate/keywords(默认值与 legacy 对齐)。
49
+ - im_transcripts 全量流水恢复写入(chat_history 工具可用);群聊旁听上下文回迁。
50
+ - `ai.trigger.timeout/thinkingMessage/errorTemplate` 生效;masters/trusted 角色解析对齐 legacy。
51
+ - `Message.sender` 统一为用户 ID(onebot11/12、napcat、milky 原误传显示名);quote_id 经 metadata 接入 AI 引用上下文。
52
+
53
+ - Updated dependencies [16ec4e8]
54
+ - Updated dependencies [cc5c94d]
55
+ - Updated dependencies [447f3e2]
56
+ - @zhin.js/core@1.3.5
57
+ - @zhin.js/host-http@1.0.1
58
+ - zhin.js@4.1.3
59
+ - @zhin.js/logger@1.0.75
60
+ - @zhin.js/plugin-runtime@1.0.1
61
+ - @zhin.js/adapter@1.0.1
62
+
63
+ ## 3.0.2
64
+
65
+ ### Patch Changes
66
+
67
+ - 872c583: fix: 代码格式优化
68
+ - Updated dependencies [872c583]
69
+ - Updated dependencies [872c583]
70
+ - @zhin.js/host-router@2.0.3
71
+ - zhin.js@4.1.2
72
+
73
+ ## 3.0.1
74
+
75
+ ### Patch Changes
76
+
77
+ - 5cc9c03: fix: ai 优化
78
+ - b9b3881: fix: 增加游戏引擎以及部分游戏
79
+ - Updated dependencies [5cc9c03]
80
+ - Updated dependencies [7700903]
81
+ - @zhin.js/host-router@2.0.2
82
+ - zhin.js@4.1.1
83
+
84
+ ## 3.0.0
85
+
86
+ ### Patch Changes
87
+
88
+ - c4575c9: fix: 输入输出优化,文档优化
89
+ - Updated dependencies [c4575c9]
90
+ - Updated dependencies [c4575c9]
91
+ - @zhin.js/host-router@2.0.1
92
+ - zhin.js@4.1.0
93
+
94
+ ## 2.0.1
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [ae5239c]
99
+ - zhin.js@4.0.1
100
+ - @zhin.js/host-router@2.0.0
101
+
102
+ ## 2.0.0
103
+
104
+ ### Patch Changes
105
+
106
+ - zhin.js@3.0.0
107
+ - @zhin.js/host-router@2.0.0
108
+
109
+ ## 1.0.1
110
+
111
+ ### Patch Changes
112
+
113
+ - d8def69: fix: 性能优化
114
+ - 2ef4896: fix: 更新概念 Bot=>Endpoint,已适配后续更多的业务场景;统一角色权限
115
+ - Updated dependencies [d8def69]
116
+ - Updated dependencies [2ef4896]
117
+ - @zhin.js/host-router@1.0.1
118
+ - zhin.js@2.0.1
119
+
120
+ ## 1.0.0
121
+
122
+ ### Patch Changes
123
+
124
+ - zhin.js@2.0.0
125
+ - @zhin.js/host-router@1.0.0
126
+
127
+ ## 0.0.42
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [d8547d2]
132
+ - zhin.js@1.0.92
133
+ - @zhin.js/host-router@0.0.3
134
+
135
+ ## 0.0.41
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [3735e96]
140
+ - zhin.js@1.0.91
141
+ - @zhin.js/host-router@0.0.3
142
+
143
+ ## 0.0.40
144
+
145
+ ### Patch Changes
146
+
147
+ - c8f8207: fix: 修复内存泄露问题
148
+ - Updated dependencies [c8f8207]
149
+ - @zhin.js/host-router@0.0.3
150
+ - zhin.js@1.0.90
151
+
152
+ ## 0.0.39
153
+
154
+ ### Patch Changes
155
+
156
+ - Updated dependencies [c78d2cd]
157
+ - @zhin.js/host-router@0.0.2
158
+ - zhin.js@1.0.89
159
+
160
+ ## 0.0.38
161
+
162
+ ### Patch Changes
163
+
164
+ - Updated dependencies [ccb6e24]
165
+ - zhin.js@1.0.88
166
+
167
+ ## 0.0.37
168
+
169
+ ### Patch Changes
170
+
171
+ - 90d9efd: fix: 处理包名
172
+ - zhin.js@1.0.87
173
+ - @zhin.js/host-router@0.0.1
174
+
175
+ ## 0.0.36
176
+
177
+ ### Patch Changes
178
+
179
+ - 7e14f8d: fix: 统一发个版,优化一些列安全问题
180
+ - Updated dependencies [7e14f8d]
181
+ - zhin.js@1.0.86
182
+ - @zhin.js/host-router@1.0.79
183
+
184
+ ## 0.0.35
185
+
186
+ ### Patch Changes
187
+
188
+ - zhin.js@1.0.85
189
+ - @zhin.js/host-router@1.0.78
190
+
191
+ ## 0.0.34
192
+
193
+ ### Patch Changes
194
+
195
+ - f19d2e0: fix: remove multiple runtime support
196
+ - Updated dependencies [0db9fed]
197
+ - Updated dependencies [f19d2e0]
198
+ - zhin.js@1.0.84
199
+ - @zhin.js/host-router@1.0.77
200
+
201
+ ## 0.0.33
202
+
203
+ ### Patch Changes
204
+
205
+ - 775427e: fix: edge 支持
206
+ - Updated dependencies [775427e]
207
+ - @zhin.js/host-router@1.0.76
208
+ - zhin.js@1.0.83
209
+
210
+ ## 0.0.32
211
+
212
+ ### Patch Changes
213
+
214
+ - 32049f5: fix: init publish
215
+ - Updated dependencies [32049f5]
216
+ - @zhin.js/host-router@1.0.75
217
+ - zhin.js@1.0.82
218
+
219
+ ## 0.0.31
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [8086ccb]
224
+ - zhin.js@1.0.81
225
+ - @zhin.js/host-router@1.0.74
226
+
227
+ ## 0.0.30
228
+
229
+ ### Patch Changes
230
+
231
+ - zhin.js@1.0.80
232
+ - @zhin.js/host-router@1.0.73
233
+
234
+ ## 0.0.29
235
+
236
+ ### Patch Changes
237
+
238
+ - zhin.js@1.0.79
239
+ - @zhin.js/host-router@1.0.72
240
+
241
+ ## 0.0.28
242
+
243
+ ### Patch Changes
244
+
245
+ - zhin.js@1.0.78
246
+ - @zhin.js/host-router@1.0.71
247
+
248
+ ## 0.0.27
249
+
250
+ ### Patch Changes
251
+
252
+ - zhin.js@1.0.77
253
+ - @zhin.js/host-router@1.0.70
254
+
255
+ ## 0.0.26
256
+
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [cb9fbf1]
260
+ - zhin.js@1.0.76
261
+ - @zhin.js/host-router@1.0.69
262
+
263
+ ## 0.0.25
264
+
265
+ ### Patch Changes
266
+
267
+ - zhin.js@1.0.75
268
+ - @zhin.js/host-router@1.0.68
269
+
270
+ ## 0.0.24
271
+
272
+ ### Patch Changes
273
+
274
+ - Updated dependencies [c9dec38]
275
+ - zhin.js@1.0.74
276
+ - @zhin.js/host-router@1.0.67
277
+
278
+ ## 0.0.23
279
+
280
+ ### Patch Changes
281
+
282
+ - f1e9a76: fix: 提高 skill 质量
283
+ - zhin.js@1.0.73
284
+ - @zhin.js/host-router@1.0.66
285
+
286
+ ## 0.0.22
287
+
288
+ ### Patch Changes
289
+
290
+ - abc75a4: fix: 优化,客户端构建优化
291
+
292
+ ## 0.0.21
293
+
294
+ ### Patch Changes
295
+
296
+ - e28fd7c: fix: 重新发版
297
+ - Updated dependencies [e28fd7c]
298
+ - zhin.js@1.0.72
299
+ - @zhin.js/host-router@1.0.65
300
+
301
+ ## 0.0.20
302
+
303
+ ### Patch Changes
304
+
305
+ - 4304825: fix: 重新发版
306
+ - Updated dependencies [4304825]
307
+ - zhin.js@1.0.71
308
+ - @zhin.js/host-router@1.0.64
309
+
310
+ ## 0.0.19
311
+
312
+ ### Patch Changes
313
+
314
+ - zhin.js@1.0.68
315
+ - @zhin.js/host-router@1.0.63
316
+
317
+ ## 0.0.18
318
+
319
+ ### Patch Changes
320
+
321
+ - Updated dependencies [0eba6d6]
322
+ - @zhin.js/host-router@1.0.62
323
+ - zhin.js@1.0.67
324
+
325
+ ## 0.0.17
326
+
327
+ ### Patch Changes
328
+
329
+ - zhin.js@1.0.66
330
+ - @zhin.js/host-router@1.0.61
331
+
332
+ ## 0.0.16
333
+
334
+ ### Patch Changes
335
+
336
+ - zhin.js@1.0.65
337
+ - @zhin.js/host-router@1.0.60
338
+
339
+ ## 0.0.15
340
+
341
+ ### Patch Changes
342
+
343
+ - 9577eba: fix: tool 收集 bug,升级 ts 到 6.0.2
344
+ - Updated dependencies [9577eba]
345
+ - zhin.js@1.0.64
346
+ - @zhin.js/host-router@1.0.59
347
+
348
+ ## 0.0.14
349
+
350
+ ### Patch Changes
351
+
352
+ - Updated dependencies [ba30934]
353
+ - @zhin.js/host-router@1.0.58
354
+ - zhin.js@1.0.63
355
+
356
+ ## 0.0.13
357
+
358
+ ### Patch Changes
359
+
360
+ - zhin.js@1.0.62
361
+ - @zhin.js/host-router@1.0.57
362
+
363
+ ## 0.0.12
364
+
365
+ ### Patch Changes
366
+
367
+ - zhin.js@1.0.61
368
+ - @zhin.js/host-router@1.0.56
369
+
370
+ ## 0.0.11
371
+
372
+ ### Patch Changes
373
+
374
+ - 5073d4c: chore: chore: update TypeScript version to ^5.9.3 across all plugins and packages
375
+ feat: enhance ai-text-as-image output registration with off handler for cleanup
376
+ fix: remove unnecessary logging in ensureBuiltinFontsCached function
377
+ refactor: simplify action handlers in html-renderer tools
378
+ chore: add README files for queue-sandbox-poc and event-delivery packages
379
+ chore: adjust pnpm workspace configuration to exclude games directory
380
+ chore: update tsconfig to include plugins directory for TypeScript compilation
381
+ - Updated dependencies [5073d4c]
382
+ - zhin.js@1.0.60
383
+ - @zhin.js/host-router@1.0.55
384
+
385
+ ## 0.0.10
386
+
387
+ ### Patch Changes
388
+
389
+ - c212bf7: fix: 适配器优化
390
+ - Updated dependencies [c212bf7]
391
+ - zhin.js@1.0.59
392
+ - @zhin.js/host-router@1.0.54
393
+
394
+ ## 0.0.9
395
+
396
+ ### Patch Changes
397
+
398
+ - zhin.js@1.0.58
399
+ - @zhin.js/host-router@1.0.53
400
+
401
+ ## 0.0.8
402
+
403
+ ### Patch Changes
404
+
405
+ - zhin.js@1.0.57
406
+ - @zhin.js/host-router@1.0.52
407
+
408
+ ## 0.0.7
409
+
410
+ ### Patch Changes
411
+
412
+ - zhin.js@1.0.56
413
+ - @zhin.js/host-router@1.0.51
414
+
415
+ ## 0.0.6
416
+
417
+ ### Patch Changes
418
+
419
+ - zhin.js@1.0.55
420
+ - @zhin.js/host-router@1.0.50
421
+
422
+ ## 0.0.5
423
+
424
+ ### Patch Changes
425
+
426
+ - 16c8f92: fix: 统一发一次版
427
+ - Updated dependencies [16c8f92]
428
+ - zhin.js@1.0.54
429
+ - @zhin.js/host-router@1.0.49
430
+
431
+ ## 0.0.4
432
+
433
+ ### Patch Changes
434
+
435
+ - zhin.js@1.0.53
436
+ - @zhin.js/host-router@1.0.48
437
+
438
+ ## 0.0.3
439
+
440
+ ### Patch Changes
441
+
442
+ - a3511a0: 各包内 Agent 技能说明已固定为随包发布的 `skills/*/SKILL.md`(替代已移除的运行时 `declareSkill`)。本批为 registry / 分发侧对齐的 **patch** 版本递增。
443
+ - Updated dependencies [a3511a0]
444
+ - @zhin.js/host-router@1.0.47
445
+
446
+ ## 0.0.2
447
+
448
+ ### Patch Changes
449
+
450
+ - Updated dependencies [bb6bfa8]
451
+ - Updated dependencies [bb6bfa8]
452
+ - zhin.js@1.0.52
453
+ - @zhin.js/host-router@1.0.46
454
+
455
+ ## 0.0.1
456
+
457
+ ### Patch Changes
458
+
459
+ - zhin.js@1.0.51
460
+ - @zhin.js/host-router@1.0.45
package/README.md CHANGED
@@ -1,110 +1,76 @@
1
1
  # @zhin.js/adapter-onebot12
2
2
 
3
- Zhin.js [OneBot 12](https://12.onebot.dev/) 协议适配器,**一个适配器**支持正向 WebSocket、HTTP Webhook、反向 WebSocket 三种连接方式,由配置项 `connection` 区分。
3
+ Zhin.js [OneBot 12](https://12.onebot.dev/) 适配器(Plugin Runtime)。默认 **正向 WebSocket 客户端**(`connection: ws`);亦支持 **HTTP Webhook** 与 **反向 WS**(经 `httpHostToken` 注册路由)。
4
4
 
5
5
  ## 功能特性
6
6
 
7
- - 🔌 [OneBot 12 标准](https://12.onebot.dev/) 兼容(OneBot Connect + 接口定义)
8
- - 📦 **单一适配器**:`context: onebot12`,通过 `connection` 选择连接方式
9
- - 🌐 **正向 WebSocket**(`connection: ws`):应用连 OneBot 实现的 WS 服务器
10
- - 📮 **HTTP Webhook**(`connection: webhook`):OneBot 实现 POST 事件到应用提供的 path,可选 `api_url` 用于发消息/撤回
11
- - 🔄 **反向 WebSocket**(`connection: wss`):应用开 WS 服务端,OneBot 实现连上来
12
- - 🔐 `access_token` 鉴权(Bearer)
13
- - 📨 私聊 / 群聊 / 频道消息收发,消息段与 OneBot 12 标准一致
7
+ - [OneBot 12 标准](https://12.onebot.dev/) 兼容(事件 + 动作)
8
+ - 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
9
+ - **正向 WebSocket**(`connection: ws`):应用连 OneBot 实现的 WS 服务器
10
+ - `access_token` 鉴权(Bearer + query)
11
+ - 入站经 `messageGatewayToken`;出站 `send({ target, payload })`
14
12
 
15
13
  ## 安装
16
14
 
17
15
  ```bash
18
- pnpm add @zhin.js/adapter-onebot12 ws
16
+ pnpm add @zhin.js/adapter-onebot12
19
17
  ```
20
18
 
21
- Webhook / 反向 WS 需启用 `@zhin.js/host-router`:
19
+ ## Plugin Runtime
22
20
 
23
- ```bash
24
- pnpm add @zhin.js/host-router
25
- ```
26
-
27
- ## 配置
21
+ - `@zhin.js/adapter` — 约定式 `adapters/onebot12.ts`(`defineAdapter`)
22
+ - `@zhin.js/core` — `messageGatewayToken` 入站/出站
23
+ - `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
24
+ - 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
28
25
 
29
- 所有 Endpoint 使用 **同一 context:`onebot12`**,通过 **`connection`** 区分连接方式。
26
+ 入站:`gateway.receive({ adapter, target: "private:uid"| "group:gid"|…, content, sender, metadata })`
27
+ 出站:`send({ target, payload })` → WS `send_message`(payload 已由 gateway/core 渲染;无 segment-mapper)
30
28
 
31
- ### 正向 WebSocket
29
+ ## 最小配置
32
30
 
33
31
  ```yaml
32
+ # zhin.config.yml(Plugin Runtime)
34
33
  plugins:
35
- - "@zhin.js/adapter-onebot12"
36
-
37
- endpoints:
38
- - context: onebot12
34
+ onebot12:
39
35
  connection: ws
40
- name: ob12-bot
41
- url: "ws://127.0.0.1:6700"
42
- access_token: "${ONEBOT12_ACCESS_TOKEN}"
43
36
  reconnect_interval: 5000
44
37
  heartbeat_interval: 30000
38
+ endpoints:
39
+ - name: ob12-bot
40
+ url: "ws://127.0.0.1:6700"
41
+ access_token: "${ONEBOT12_ACCESS_TOKEN}"
45
42
  ```
46
43
 
47
- ### HTTP Webhook
44
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-onebot12`(`instanceKey: onebot12`)。
48
45
 
49
- OneBot 实现会向你的 `path` 发送 POST 事件;若需发消息/撤回,请配置实现提供的 HTTP 端点 `api_url`。
46
+ ## 连接方式
50
47
 
51
- ```yaml
52
- plugins:
53
- - "@zhin.js/host-router"
54
- - "@zhin.js/adapter-onebot12"
55
-
56
- endpoints:
57
- - context: onebot12
58
- connection: webhook
59
- name: ob12-webhook-bot
60
- path: "/onebot12/webhook"
61
- api_url: "http://127.0.0.1:6700" # 可选,用于 send_message / delete_message
62
- access_token: "${ONEBOT12_ACCESS_TOKEN}"
63
- ```
64
-
65
- ### 反向 WebSocket
66
-
67
- ```yaml
68
- plugins:
69
- - "@zhin.js/host-router"
70
- - "@zhin.js/adapter-onebot12"
71
-
72
- endpoints:
73
- - context: onebot12
74
- connection: wss
75
- name: ob12-wss-bot
76
- path: "/onebot12/event"
77
- access_token: "${ONEBOT12_ACCESS_TOKEN}"
78
- heartbeat_interval: 30000
79
- ```
48
+ | connection | 状态 |
49
+ |------------|------|
50
+ | `ws` | 已实现(推荐) |
51
+ | `webhook` | 已实现:POST 入站 + `api_url` HTTP 出站 |
52
+ | `wss` | 已实现:反向 WS(httpHostToken) |
80
53
 
81
54
  ## 鉴权
82
55
 
83
- - **Bearer**:请求头 `Authorization: Bearer <access_token>`
84
- - 正向 WS 在建立连接时通过 HTTP Upgrade 头鉴权;Webhook / 反向 WS 同上
85
-
86
- 配置 `access_token` 并与 OneBot 实现端一致即可。
87
-
88
- ## 连接方式对比
89
-
90
- | connection | 说明 |
91
- |------------|------|
92
- | `ws` | 应用连实现的 WebSocket 服务器 |
93
- | `webhook` | 实现 POST 事件到应用 path;发消息需配置 `api_url` |
94
- | `wss` | 应用开 WS 服务端,实现连上来 |
56
+ - **Bearer**:`Authorization: Bearer <access_token>`
57
+ - 正向 WS 在 Upgrade 时附带请求头,并在 URL query 写入 `access_token`
95
58
 
96
59
  ## 动作与事件
97
60
 
98
- - 事件:`type`(meta/message/notice/request)、`detail_type`、`message`(消息段数组)等,见 [事件](https://12.onebot.dev/connect/data-protocol/event/)。
99
- - 动作:`send_message`(params: detail_type, user_id/group_id/channel_id, message)、`delete_message` 等,见 [动作请求](https://12.onebot.dev/connect/data-protocol/action-request/)。
61
+ - 事件:`type`(meta/message/notice/request)、`detail_type`、`message` 等,见 [事件](https://12.onebot.dev/connect/data-protocol/event/)。
62
+ - 动作:`send_message`、`delete_message`、`get_status` 等,见 [动作请求](https://12.onebot.dev/connect/data-protocol/action-request/)。
100
63
 
101
64
  ## AI 工具
102
65
 
103
- 技能说明见 `agent/skills/onebot12.md`。群管标准工具由 `createSceneManagementTools()` 注册。
104
-
66
+ 技能说明见 `agent/skills/onebot12.md`。
105
67
 
106
- ## 协议文档
68
+ ## 文档链接
107
69
 
108
70
  - [OneBot 12 标准](https://12.onebot.dev/)
109
- - [OneBot Connect 通信方式](https://12.onebot.dev/connect/communication/websocket/)
110
- - [数据协议(事件 / 动作)](https://12.onebot.dev/connect/data-protocol/event/)
71
+ - [OneBot Connect WebSocket](https://12.onebot.dev/connect/communication/websocket/)
72
+ - [适配器概览](https://zhin.js.org/essentials/adapters)
73
+
74
+ ## 许可证
75
+
76
+ MIT License
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Convention entry: discover `adapters/onebot12.ts` → defineAdapter.
3
+ */
4
+ import { defineAdapter } from '@zhin.js/adapter';
5
+ import { messageGatewayToken } from '@zhin.js/core/runtime';
6
+ import { httpHostToken } from '@zhin.js/host-http';
7
+ import { OneBot12WebhookEndpoint } from '../src/webhook.js';
8
+ import { OneBot12WsEndpoint } from '../src/ws-endpoint.js';
9
+ import { OneBot12WssEndpoint } from '../src/wss-endpoint.js';
10
+ import {
11
+ resolveOneBot12Config,
12
+ type OneBot12AdapterConfig,
13
+ } from '../src/protocol.js';
14
+
15
+ export { OneBot12WebhookEndpoint } from '../src/webhook.js';
16
+ export type { OneBot12WebhookEndpointOptions } from '../src/webhook.js';
17
+ export { OneBot12WsEndpoint } from '../src/ws-endpoint.js';
18
+ export type { OneBot12WsEndpointOptions } from '../src/ws-endpoint.js';
19
+ export { OneBot12WssEndpoint } from '../src/wss-endpoint.js';
20
+ export type { OneBot12WssEndpointOptions } from '../src/wss-endpoint.js';
21
+ export type { OneBot12WsSocket, OneBot12WsCreateOptions } from '../src/ws-types.js';
22
+
23
+ export default defineAdapter<OneBot12AdapterConfig>({
24
+ capabilities: ['inbound', 'outbound'],
25
+ create(context) {
26
+ const config = resolveOneBot12Config(context.config);
27
+ const gateway = context.use(messageGatewayToken);
28
+ if (config.connection === 'webhook') {
29
+ return new OneBot12WebhookEndpoint({
30
+ id: context.id,
31
+ gateway,
32
+ http: context.use(httpHostToken),
33
+ config,
34
+ });
35
+ }
36
+ if (config.connection === 'wss') {
37
+ return new OneBot12WssEndpoint({
38
+ id: context.id,
39
+ gateway,
40
+ http: context.use(httpHostToken),
41
+ config,
42
+ });
43
+ }
44
+ return new OneBot12WsEndpoint({
45
+ id: context.id,
46
+ gateway,
47
+ config,
48
+ });
49
+ },
50
+ });
package/lib/index.d.ts CHANGED
@@ -1,19 +1,6 @@
1
- import { OneBot12Adapter } from './adapter.js';
2
- export * from './types.js';
3
- export { callOneBot12Action } from './api.js';
4
- export * from './utils.js';
5
- export { OneBot12WsClient } from './endpoint-ws.js';
6
- export { OneBot12WebhookEndpoint } from './endpoint-webhook.js';
7
- export { OneBot12WssServer } from './endpoint-wss.js';
8
- export { OneBot12Adapter, type OneBot12Bot } from './adapter.js';
9
- declare module 'zhin.js' {
10
- namespace Plugin {
11
- interface Contexts {
12
- router: import('@zhin.js/host-router').Router;
13
- }
14
- }
15
- interface Adapters {
16
- onebot12: OneBot12Adapter;
17
- }
18
- }
19
- //# sourceMappingURL=index.d.ts.map
1
+ export { buildSendMessageParams, buildWsConnectOptions, callOneBot12Action, formatInboundContent, formatInboundTarget, formatOutboundSegments, getChannelId, isBotMentioned, isMessageEvent, parseSendTarget, resolveOneBot12Config, senderNickname, senderUserId, type OneBot12ActionRequest, type OneBot12ActionResponse, type OneBot12AdapterConfig, type OneBot12ConfigBase, type OneBot12EndpointConfig, type OneBot12Event, type OneBot12HttpOptions, type OneBot12Segment, type OneBot12Self, type OneBot12WebhookConfig, type OneBot12WireSegment, type OneBot12WsConfig, type OneBot12WssConfig, type ParsedSendTarget, type ResolvedOneBot12Config, } from './protocol.js';
2
+ export { OneBot12WebhookEndpoint, type OneBot12WebhookEndpointOptions, } from './webhook.js';
3
+ export { OneBot12WsEndpoint, type OneBot12WsEndpointOptions, } from './ws-endpoint.js';
4
+ export { OneBot12WssEndpoint, type OneBot12WssEndpointOptions, } from './wss-endpoint.js';
5
+ export type { OneBot12WsSocket, OneBot12WsCreateOptions } from './ws-types.js';
6
+ export { verifyOneBotAccessToken } from './wss-auth.js';