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