@zhin.js/adapter-satori 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 (59) hide show
  1. package/CHANGELOG.md +440 -0
  2. package/README.md +34 -34
  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 +42 -16
  15. package/plugin.ts +8 -0
  16. package/schema.json +35 -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 -50
  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
  59. /package/{skills/satori/SKILL.md → agent/skills/satori.md} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,440 @@
1
+ # @zhin.js/adapter-satori
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,61 +1,66 @@
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
- connection: ws
40
+ satori:
41
41
  name: satori-bot
42
+ connection: ws
42
43
  baseUrl: "http://127.0.0.1:5140"
43
44
  token: "${SATORI_TOKEN}"
44
45
  heartbeat_interval: 10000
45
46
  ```
46
47
 
48
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-satori`(`instanceKey: satori`)。
49
+
50
+ ### 可选字段
51
+
52
+ | 字段 | 说明 |
53
+ |------|------|
54
+ | `heartbeat_interval` | WS PING 间隔(毫秒),默认 `10000` |
55
+ | `token` | Bearer;也可设环境变量 `SATORI_TOKEN` |
56
+
47
57
  ### Webhook
48
58
 
49
59
  ```yaml
50
60
  plugins:
51
- - "@zhin.js/host-router"
52
- - "@zhin.js/adapter-satori"
53
-
54
- endpoints:
55
- - context: satori
61
+ satori:
56
62
  connection: webhook
57
- name: satori-webhook-bot
58
- baseUrl: "http://satori-sdk 地址"
63
+ baseUrl: "http://127.0.0.1:5140"
59
64
  path: "/satori/webhook"
60
65
  token: "${SATORI_TOKEN}"
61
66
  ```
@@ -67,20 +72,15 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;适
67
72
  - **API**:请求头 `Authorization: Bearer {token}`
68
73
  - **WebSocket**:IDENTIFY 时 body 中传 `token`
69
74
 
70
- 配置 `token` 并与 Satori SDK 端一致即可。
71
-
72
- ## 连接方式对比
73
-
74
- | connection | 说明 |
75
- |------------|------|
76
- | `ws` | 应用主动连 SDK `/v1/events`,IDENTIFY + 心跳 |
77
- | `webhook` | 应用提供 POST path,SDK 推送事件 |
78
-
79
75
  ## 消息 id 与撤回
80
76
 
81
- - 消息 `$id` 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
77
+ - 消息 id 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
82
78
  - 撤回时需 `channel_id` + `message_id`,适配器已按上述格式解析。
83
79
 
80
+ ## AI 工具
81
+
82
+ 技能说明见 `agent/skills/satori.md`。
83
+
84
84
  ## 协议文档
85
85
 
86
86
  - [介绍](https://satori.chat/zh-CN/introduction.html)
@@ -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';