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