@zhin.js/adapter-satori 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 (58) hide show
  1. package/CHANGELOG.md +460 -0
  2. package/README.md +38 -40
  3. package/adapters/satori.ts +41 -0
  4. package/lib/endpoint.d.ts +61 -0
  5. package/lib/endpoint.js +379 -0
  6. package/lib/index.d.ts +4 -18
  7. package/lib/index.js +4 -25
  8. package/lib/protocol.d.ts +150 -0
  9. package/lib/protocol.js +196 -0
  10. package/lib/webhook.d.ts +17 -0
  11. package/lib/webhook.js +79 -0
  12. package/lib/ws.d.ts +13 -0
  13. package/lib/ws.js +5 -0
  14. package/package.json +41 -15
  15. package/plugin.ts +8 -0
  16. package/schema.json +59 -0
  17. package/src/endpoint.ts +462 -0
  18. package/src/index.ts +47 -35
  19. package/src/protocol.ts +315 -0
  20. package/src/webhook.ts +104 -0
  21. package/src/ws.ts +22 -0
  22. package/lib/adapter.d.ts +0 -19
  23. package/lib/adapter.d.ts.map +0 -1
  24. package/lib/adapter.js +0 -37
  25. package/lib/adapter.js.map +0 -1
  26. package/lib/api.d.ts +0 -15
  27. package/lib/api.d.ts.map +0 -1
  28. package/lib/api.js +0 -37
  29. package/lib/api.js.map +0 -1
  30. package/lib/endpoint-webhook.d.ts +0 -27
  31. package/lib/endpoint-webhook.d.ts.map +0 -1
  32. package/lib/endpoint-webhook.js +0 -99
  33. package/lib/endpoint-webhook.js.map +0 -1
  34. package/lib/endpoint-ws.d.ts +0 -30
  35. package/lib/endpoint-ws.d.ts.map +0 -1
  36. package/lib/endpoint-ws.js +0 -195
  37. package/lib/endpoint-ws.js.map +0 -1
  38. package/lib/index.d.ts.map +0 -1
  39. package/lib/index.js.map +0 -1
  40. package/lib/segment-mapper.d.ts +0 -2
  41. package/lib/segment-mapper.d.ts.map +0 -1
  42. package/lib/segment-mapper.js +0 -2
  43. package/lib/segment-mapper.js.map +0 -1
  44. package/lib/types.d.ts +0 -91
  45. package/lib/types.d.ts.map +0 -1
  46. package/lib/types.js +0 -13
  47. package/lib/types.js.map +0 -1
  48. package/lib/utils.d.ts +0 -40
  49. package/lib/utils.d.ts.map +0 -1
  50. package/lib/utils.js +0 -34
  51. package/lib/utils.js.map +0 -1
  52. package/src/adapter.ts +0 -45
  53. package/src/api.ts +0 -48
  54. package/src/endpoint-webhook.ts +0 -117
  55. package/src/endpoint-ws.ts +0 -214
  56. package/src/segment-mapper.ts +0 -1
  57. package/src/types.ts +0 -91
  58. package/src/utils.ts +0 -65
package/CHANGELOG.md ADDED
@@ -0,0 +1,460 @@
1
+ # @zhin.js/adapter-satori
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,63 +1,71 @@
1
1
  # @zhin.js/adapter-satori
2
2
 
3
- Zhin.js [Satori](https://satori.chat/zh-CN/introduction.html) **聊天协议**适配器,**一个适配器**支持 WebSocket 正向与 Webhook 两种连接方式,由配置项 `connection` 区分;支持 HTTP API 与 Bearer Token 鉴权。
3
+ Zhin.js [Satori](https://satori.chat/zh-CN/introduction.html) **聊天协议**适配器(Plugin Runtime)。支持 **WebSocket 正向客户端**(`connection: ws`)与 **Webhook 入站**(`connection: webhook`,经 `httpHostToken` POST 路由)。
4
4
 
5
5
  > **勿与本仓库的 `@zhin.js/satori` 混淆**:后者是 [Vercel satori](https://github.com/vercel/satori) 的 **SVG 图片渲染**工具包(`packages/toolkit/satori`),用于把 HTML/React 画成 SVG,**不是**聊天协议。参见 [@zhin.js/satori README](https://github.com/zhinjs/zhin/tree/main/packages/toolkit/satori)。
6
6
 
7
7
  ## 功能特性
8
8
 
9
9
  - 🔌 [Satori 协议](https://satori.chat/zh-CN/introduction.html) 兼容
10
- - 📦 **单一适配器**:`context: satori`,通过 `connection` 选择连接方式
11
- - 🌐 **WebSocket 正向**(`connection: ws`):应用连 SDK `ws(s)://baseUrl/v1/events`
12
- - 📮 **Webhook**(`connection: webhook`):应用提供 POST 端点收事件
10
+ - 🌐 **WebSocket 正向**(`connection: ws`,默认):应用连 SDK `ws(s)://baseUrl`,IDENTIFY + 心跳
13
11
  - 🔐 Bearer Token 鉴权(API 与 WS IDENTIFY)
14
12
  - 📨 频道 / 私聊消息收发,消息 id 格式为 `channelId:messageId`
13
+ - 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
14
+ - **Webhook**(`connection: webhook`):SDK POST `Satori-Opcode: 0` 事件到 `path`
15
15
 
16
16
  ## 安装
17
17
 
18
18
  ```bash
19
- pnpm add @zhin.js/adapter-satori ws
19
+ pnpm add @zhin.js/adapter-satori
20
20
  ```
21
21
 
22
- Webhook 方式需启用 `@zhin.js/host-router`(适配器依赖 router 注册):
22
+ ## Plugin Runtime
23
23
 
24
- ```bash
25
- pnpm add @zhin.js/host-router
26
- ```
24
+ - `@zhin.js/adapter` — 约定式 `adapters/satori.ts`(`defineAdapter`)
25
+ - `@zhin.js/core` — `messageGatewayToken` 入站/出站
26
+ - `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
27
+ - `@zhin.js/host-http` — Webhook 模式需 `httpHostToken` 注册 POST 路由
28
+ - 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`(`baseUrl` / `token` / …)
27
29
 
28
- ## 配置
30
+ 入站:`gateway.receive({ adapter, target: channelId, content: text, sender, id, metadata })`
31
+ 出站:`send({ target: channelId, payload })` → Satori `message.create`(payload 已由 gateway/core 渲染;无 segment-mapper)
29
32
 
30
- 所有 Endpoint 使用 **同一 context:`satori`**,通过 **`connection`** 区分连接方式。
33
+ 入站 `metadata.mentioned`:消息 content `<at id="…"/>` 元素的 id 等于登录 selfId(READY/事件 `login.user.id`)时置 `true`。
31
34
 
32
- ### WebSocket 正向
35
+ ## 最小配置
33
36
 
34
37
  ```yaml
38
+ # zhin.config.yml(Plugin Runtime)
35
39
  plugins:
36
- - "@zhin.js/adapter-satori"
37
-
38
- endpoints:
39
- - context: satori
40
+ satori:
40
41
  connection: ws
41
- name: satori-bot
42
- baseUrl: "http://127.0.0.1:5140"
43
- token: "${SATORI_TOKEN}"
44
42
  heartbeat_interval: 10000
43
+ endpoints:
44
+ - name: satori-bot
45
+ baseUrl: "http://127.0.0.1:5140"
46
+ token: "${SATORI_TOKEN}"
45
47
  ```
46
48
 
49
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-satori`(`instanceKey: satori`)。
50
+
51
+ ### 可选字段
52
+
53
+ | 字段 | 说明 |
54
+ |------|------|
55
+ | `heartbeat_interval` | WS PING 间隔(毫秒),默认 `10000` |
56
+ | `token` | Bearer;也可设环境变量 `SATORI_TOKEN` |
57
+
47
58
  ### Webhook
48
59
 
49
60
  ```yaml
50
61
  plugins:
51
- - "@zhin.js/host-router"
52
- - "@zhin.js/adapter-satori"
53
-
54
- endpoints:
55
- - context: satori
62
+ satori:
56
63
  connection: webhook
57
- name: satori-webhook-bot
58
- baseUrl: "http://satori-sdk 地址"
59
- path: "/satori/webhook"
60
- token: "${SATORI_TOKEN}"
64
+ endpoints:
65
+ - name: satori-bot
66
+ baseUrl: "http://127.0.0.1:5140"
67
+ path: "/satori/webhook"
68
+ token: "${SATORI_TOKEN}"
61
69
  ```
62
70
 
63
71
  SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;适配器从首个事件的 `login` 取得 platform / userId 用于后续 API 调用。
@@ -67,24 +75,14 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;适
67
75
  - **API**:请求头 `Authorization: Bearer {token}`
68
76
  - **WebSocket**:IDENTIFY 时 body 中传 `token`
69
77
 
70
- 配置 `token` 并与 Satori SDK 端一致即可。
71
-
72
- ## 连接方式对比
73
-
74
- | connection | 说明 |
75
- |------------|------|
76
- | `ws` | 应用主动连 SDK `/v1/events`,IDENTIFY + 心跳 |
77
- | `webhook` | 应用提供 POST path,SDK 推送事件 |
78
-
79
78
  ## 消息 id 与撤回
80
79
 
81
- - 消息 `$id` 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
80
+ - 消息 id 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
82
81
  - 撤回时需 `channel_id` + `message_id`,适配器已按上述格式解析。
83
82
 
84
83
  ## AI 工具
85
84
 
86
- 技能说明见 `agent/skills/satori.md`。群管标准工具由 `createSceneManagementTools()` 注册。
87
-
85
+ 技能说明见 `agent/skills/satori.md`。
88
86
 
89
87
  ## 协议文档
90
88
 
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Convention entry: discover `adapters/satori.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 { SatoriWebhookEndpoint, SatoriWsEndpoint } from '../src/endpoint.js';
8
+ import {
9
+ resolveSatoriConfig,
10
+ type SatoriAdapterConfig,
11
+ } from '../src/protocol.js';
12
+
13
+ export { SatoriWebhookEndpoint, SatoriWsEndpoint } from '../src/endpoint.js';
14
+ export type {
15
+ CreateSatoriWebSocket,
16
+ SatoriApiCaller,
17
+ SatoriWebhookEndpointOptions,
18
+ SatoriWsEndpointOptions,
19
+ SatoriWsSocket,
20
+ } from '../src/endpoint.js';
21
+
22
+ export default defineAdapter<SatoriAdapterConfig>({
23
+ capabilities: ['inbound', 'outbound'],
24
+ create(context) {
25
+ const config = resolveSatoriConfig(context.config);
26
+ const gateway = context.use(messageGatewayToken);
27
+ if (config.connection === 'webhook') {
28
+ return new SatoriWebhookEndpoint({
29
+ id: context.id,
30
+ gateway,
31
+ http: context.use(httpHostToken),
32
+ config,
33
+ });
34
+ }
35
+ return new SatoriWsEndpoint({
36
+ id: context.id,
37
+ gateway,
38
+ config,
39
+ });
40
+ },
41
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * SatoriEndpoint — WebSocket and webhook lifecycle, outbound, admit.
3
+ */
4
+ import type { EndpointInstance } from '@zhin.js/adapter';
5
+ import type { MessageGateway } from '@zhin.js/core/runtime';
6
+ import type { HttpHost } from '@zhin.js/host-http';
7
+ import type { CapabilityId } from '@zhin.js/plugin-runtime';
8
+ import { callSatoriApi, type ResolvedSatoriWebhookConfig, type ResolvedSatoriWsConfig, type SatoriEventBody, type SatoriLogin } from './protocol.js';
9
+ import { type CreateSatoriWebSocket } from './ws.js';
10
+ export type SatoriApiCaller = typeof callSatoriApi;
11
+ export interface SatoriWsEndpointOptions {
12
+ readonly id: CapabilityId;
13
+ readonly gateway: MessageGateway;
14
+ readonly config: ResolvedSatoriWsConfig;
15
+ readonly createWebSocket?: CreateSatoriWebSocket;
16
+ readonly callApi?: SatoriApiCaller;
17
+ }
18
+ export declare class SatoriWsEndpoint implements EndpointInstance {
19
+ #private;
20
+ constructor(options: SatoriWsEndpointOptions);
21
+ start(): Promise<void>;
22
+ open(): void;
23
+ close(): void;
24
+ stop(): Promise<void>;
25
+ send({ target, payload }: {
26
+ readonly target: string;
27
+ readonly payload: unknown;
28
+ }): Promise<string>;
29
+ /** Test / internal: admit a gateway event when the endpoint is open. */
30
+ admit(body: SatoriEventBody): void;
31
+ recall(id: string): Promise<void>;
32
+ /** Test helper: inject a READY login without a live socket. */
33
+ setLogin(login: SatoriLogin): void;
34
+ }
35
+ export interface SatoriWebhookEndpointOptions {
36
+ readonly id: CapabilityId;
37
+ readonly gateway: MessageGateway;
38
+ readonly http: HttpHost;
39
+ readonly config: ResolvedSatoriWebhookConfig;
40
+ readonly callApi?: SatoriApiCaller;
41
+ }
42
+ export declare class SatoriWebhookEndpoint implements EndpointInstance {
43
+ #private;
44
+ constructor(options: SatoriWebhookEndpointOptions);
45
+ /** Used by webhook handler. */
46
+ get isOpen(): boolean;
47
+ get config(): ResolvedSatoriWebhookConfig;
48
+ start(): Promise<void>;
49
+ open(): void;
50
+ close(): void;
51
+ stop(): Promise<void>;
52
+ send({ target, payload }: {
53
+ readonly target: string;
54
+ readonly payload: unknown;
55
+ }): Promise<string>;
56
+ admit(body: SatoriEventBody): void;
57
+ recall(id: string): Promise<void>;
58
+ /** Test helper: inject login without a live webhook push. */
59
+ setLogin(login: SatoriLogin): void;
60
+ }
61
+ export type { CreateSatoriWebSocket, SatoriWsSocket } from './ws.js';