@zhin.js/adapter-satori 1.0.1 → 1.1.2
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.
- package/CHANGELOG.md +912 -0
- package/README.md +60 -38
- package/adapters/satori/index.js +38 -0
- package/adapters/satori/index.ts +49 -0
- package/commands/satori/endpoint/add/[id]/index.js +3 -0
- package/commands/satori/endpoint/add/[id]/index.ts +3 -0
- package/commands/satori/endpoint/definition.js +19 -0
- package/commands/satori/endpoint/definition.ts +19 -0
- package/commands/satori/endpoint/list/index.js +3 -0
- package/commands/satori/endpoint/list/index.ts +3 -0
- package/commands/satori/endpoint/remove/[id]/index.js +3 -0
- package/commands/satori/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +18 -0
- package/lib/client.js +21 -0
- package/lib/endpoint.d.ts +56 -0
- package/lib/endpoint.js +472 -0
- package/lib/index.d.ts +8 -18
- package/lib/index.js +6 -25
- package/lib/protocol.d.ts +148 -0
- package/lib/protocol.js +230 -0
- package/lib/satori-runtime-state.d.ts +1 -0
- package/lib/satori-runtime-state.js +6 -0
- package/lib/webhook.d.ts +12 -0
- package/lib/webhook.js +60 -0
- package/lib/ws.d.ts +13 -0
- package/lib/ws.js +5 -0
- package/package.json +68 -17
- package/plugin.js +14 -0
- package/schema.json +109 -0
- package/src/client.ts +57 -0
- package/src/endpoint.ts +580 -0
- package/src/index.ts +61 -35
- package/src/protocol.ts +353 -0
- package/src/satori-runtime-state.ts +7 -0
- package/src/webhook.ts +79 -0
- package/src/ws.ts +22 -0
- package/lib/adapter.d.ts +0 -17
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -35
- package/lib/adapter.js.map +0 -1
- package/lib/api.d.ts +0 -15
- package/lib/api.d.ts.map +0 -1
- package/lib/api.js +0 -37
- package/lib/api.js.map +0 -1
- package/lib/endpoint-webhook.d.ts +0 -27
- package/lib/endpoint-webhook.d.ts.map +0 -1
- package/lib/endpoint-webhook.js +0 -99
- package/lib/endpoint-webhook.js.map +0 -1
- package/lib/endpoint-ws.d.ts +0 -30
- package/lib/endpoint-ws.d.ts.map +0 -1
- package/lib/endpoint-ws.js +0 -195
- package/lib/endpoint-ws.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -91
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -13
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts +0 -40
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -33
- package/lib/utils.js.map +0 -1
- package/skills/satori/SKILL.md +0 -33
- package/src/adapter.ts +0 -48
- package/src/api.ts +0 -48
- package/src/endpoint-webhook.ts +0 -117
- package/src/endpoint-ws.ts +0 -214
- package/src/types.ts +0 -91
- package/src/utils.ts +0 -64
package/README.md
CHANGED
|
@@ -1,63 +1,81 @@
|
|
|
1
1
|
# @zhin.js/adapter-satori
|
|
2
2
|
|
|
3
|
-
Zhin.js [Satori](https://satori.chat/zh-CN/introduction.html)
|
|
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
|
-
-
|
|
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
|
|
19
|
+
pnpm add @zhin.js/adapter-satori
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## Plugin Runtime
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
- `@zhin.js/adapter` — 约定式 `adapters/satori/index.ts`(`defineAdapter`)
|
|
25
|
+
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
26
|
+
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
27
|
+
- `@zhin.js/host-http` — Webhook 模式需 `httpHostToken` 注册 POST 路由
|
|
28
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`(`baseUrl` / `token` / …)
|
|
29
|
+
|
|
30
|
+
入站:`gateway.receive({ conversation, message, content, sender, metadata })`(`conversation` 为 ConversationRef:DIRECT 频道 → kind `private`,其余 → kind `group`、所属 guild 进 `parent`)
|
|
31
|
+
出站:`send({ conversation, payload })` → Satori `message.create`(`channel_id = conversation.id`;payload 已由 gateway/core 渲染;无 segment-mapper)
|
|
32
|
+
|
|
33
|
+
入站 `metadata.mentioned`:消息 content 中 `<at id="…"/>` 元素的 id 等于登录 selfId(READY/事件 `login.user.id`)时置 `true`。
|
|
34
|
+
|
|
35
|
+
每个 Endpoint 的 `$client` 是 `@imhelper/satori-v1` 的 `SatoriV1Client`。业务代码直接调用
|
|
36
|
+
`$client.call(resource, method, params)` 或其公开便捷方法;Client 负责协议事件变换,Endpoint
|
|
37
|
+
只负责 Satori IDENTIFY/心跳、Webhook 鉴权和 Zhin 投影。
|
|
27
38
|
|
|
28
|
-
##
|
|
39
|
+
## 前置条件
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
1. 准备兼容 Satori 的服务端,记录 API Base、平台标识和用户标识。
|
|
42
|
+
2. 正向 WS 需 Zhin 可达 Satori 服务;Webhook 需服务端可达 Zhin HTTP Host。
|
|
43
|
+
3. 若服务启用鉴权,在两端配置相同的 Bearer token。
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
## 最小配置
|
|
33
46
|
|
|
34
47
|
```yaml
|
|
48
|
+
# zhin.config.yml(Plugin Runtime)
|
|
35
49
|
plugins:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
endpoints:
|
|
39
|
-
- context: satori
|
|
50
|
+
satori:
|
|
40
51
|
connection: ws
|
|
41
|
-
name: satori-bot
|
|
42
|
-
baseUrl: "http://127.0.0.1:5140"
|
|
43
|
-
token: "${SATORI_TOKEN}"
|
|
44
52
|
heartbeat_interval: 10000
|
|
53
|
+
endpoints:
|
|
54
|
+
- id: satori-bot
|
|
55
|
+
baseUrl: "http://127.0.0.1:5140"
|
|
56
|
+
token: "${SATORI_TOKEN}"
|
|
45
57
|
```
|
|
46
58
|
|
|
59
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-satori`(`instanceKey: satori`)。
|
|
60
|
+
|
|
61
|
+
### 可选字段
|
|
62
|
+
|
|
63
|
+
| 字段 | 说明 |
|
|
64
|
+
|------|------|
|
|
65
|
+
| `heartbeat_interval` | WS PING 间隔(毫秒),默认 `10000` |
|
|
66
|
+
| `token` | Bearer;可在 YAML 中引用 `${SATORI_TOKEN}` |
|
|
67
|
+
|
|
47
68
|
### Webhook
|
|
48
69
|
|
|
49
70
|
```yaml
|
|
50
71
|
plugins:
|
|
51
|
-
|
|
52
|
-
- "@zhin.js/adapter-satori"
|
|
53
|
-
|
|
54
|
-
endpoints:
|
|
55
|
-
- context: satori
|
|
72
|
+
satori:
|
|
56
73
|
connection: webhook
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
endpoints:
|
|
75
|
+
- id: satori-bot
|
|
76
|
+
baseUrl: "http://127.0.0.1:5140"
|
|
77
|
+
path: "/satori/webhook"
|
|
78
|
+
token: "${SATORI_TOKEN}"
|
|
61
79
|
```
|
|
62
80
|
|
|
63
81
|
SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;适配器从首个事件的 `login` 取得 platform / userId 用于后续 API 调用。
|
|
@@ -67,22 +85,26 @@ SDK 会向 `path` 发送 POST,请求头 `Satori-Opcode: 0` 表示事件;适
|
|
|
67
85
|
- **API**:请求头 `Authorization: Bearer {token}`
|
|
68
86
|
- **WebSocket**:IDENTIFY 时 body 中传 `token`
|
|
69
87
|
|
|
70
|
-
配置 `token` 并与 Satori SDK 端一致即可。
|
|
71
|
-
|
|
72
|
-
## 连接方式对比
|
|
73
|
-
|
|
74
|
-
| connection | 说明 |
|
|
75
|
-
|------------|------|
|
|
76
|
-
| `ws` | 应用主动连 SDK `/v1/events`,IDENTIFY + 心跳 |
|
|
77
|
-
| `webhook` | 应用提供 POST path,SDK 推送事件 |
|
|
78
|
-
|
|
79
88
|
## 消息 id 与撤回
|
|
80
89
|
|
|
81
|
-
- 消息
|
|
90
|
+
- 消息 id 格式为 `channelId:messageId`,便于发消息 / 撤回时解析。
|
|
82
91
|
- 撤回时需 `channel_id` + `message_id`,适配器已按上述格式解析。
|
|
83
92
|
|
|
93
|
+
## AI 工具
|
|
94
|
+
|
|
95
|
+
技能说明见 `skills/satori/SKILL.md`。
|
|
96
|
+
|
|
84
97
|
## 协议文档
|
|
85
98
|
|
|
86
99
|
- [介绍](https://satori.chat/zh-CN/introduction.html)
|
|
87
100
|
- [总览](https://satori.chat/zh-CN/protocol/overview.html)
|
|
88
101
|
- [API](https://satori.chat/zh-CN/protocol/api.html)
|
|
102
|
+
|
|
103
|
+
## 故障排查
|
|
104
|
+
|
|
105
|
+
| 现象 | 排查 |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| WS IDENTIFY 失败 | 检查 `baseUrl`、平台/用户标识与 token |
|
|
108
|
+
| Webhook 无事件 | 确认路径、`Satori-Opcode: 0` 与 HTTP Host |
|
|
109
|
+
| 401 | 检查 API、WS IDENTIFY 与 Webhook 使用的 token 是否一致 |
|
|
110
|
+
| 发送目标错误 | 核对 `channel_id` 与 Conversation kind;DIRECT 才映射为 private |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Convention entry: discover `adapters/satori/index.ts` → defineAdapter.
|
|
4
|
+
*/
|
|
5
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
+
import { SatoriWebhookEndpoint, SatoriWsEndpoint } from "../../lib/endpoint.js";
|
|
8
|
+
import { resolveSatoriConfig, } from "../../lib/protocol.js";
|
|
9
|
+
import { satoriRuntimeStateToken } from "../../lib/satori-runtime-state.js";
|
|
10
|
+
export { SatoriWebhookEndpoint, SatoriWsEndpoint } from "../../lib/endpoint.js";
|
|
11
|
+
export default defineAdapter({
|
|
12
|
+
capabilities: ['inbound', 'outbound'],
|
|
13
|
+
operations: ['recall'],
|
|
14
|
+
// Satori 协议 img/file 元素消费 url 与 base64 内联数据;无卡片交互面,交互段降级纯文本。
|
|
15
|
+
segments: {
|
|
16
|
+
outboundMedia: ['url', 'base64'],
|
|
17
|
+
interactive: 'text',
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const config = resolveSatoriConfig(context.config);
|
|
21
|
+
// 注册到插件运行时状态(satori endpoint list 的"运行中"数据源)
|
|
22
|
+
context.use(satoriRuntimeStateToken).endpoints.set(config.id, {
|
|
23
|
+
id: config.id,
|
|
24
|
+
mode: config.connection,
|
|
25
|
+
});
|
|
26
|
+
if (config.connection === 'webhook') {
|
|
27
|
+
return new SatoriWebhookEndpoint({
|
|
28
|
+
id: context.id,
|
|
29
|
+
http: context.use(httpHostToken),
|
|
30
|
+
config,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return new SatoriWsEndpoint({
|
|
34
|
+
id: context.id,
|
|
35
|
+
config,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/satori/index.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
6
|
+
import { SatoriWebhookEndpoint, SatoriWsEndpoint } from '../../src/endpoint.js';
|
|
7
|
+
import {
|
|
8
|
+
resolveSatoriConfig,
|
|
9
|
+
type SatoriEndpointConfig,
|
|
10
|
+
} from '../../src/protocol.js';
|
|
11
|
+
import { satoriRuntimeStateToken } from '../../src/satori-runtime-state.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<SatoriEndpointConfig>({
|
|
23
|
+
capabilities: ['inbound', 'outbound'],
|
|
24
|
+
operations: ['recall'],
|
|
25
|
+
// Satori 协议 img/file 元素消费 url 与 base64 内联数据;无卡片交互面,交互段降级纯文本。
|
|
26
|
+
segments: {
|
|
27
|
+
outboundMedia: ['url', 'base64'],
|
|
28
|
+
interactive: 'text',
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const config = resolveSatoriConfig(context.config);
|
|
32
|
+
// 注册到插件运行时状态(satori endpoint list 的"运行中"数据源)
|
|
33
|
+
context.use(satoriRuntimeStateToken).endpoints.set(config.id, {
|
|
34
|
+
id: config.id,
|
|
35
|
+
mode: config.connection,
|
|
36
|
+
});
|
|
37
|
+
if (config.connection === 'webhook') {
|
|
38
|
+
return new SatoriWebhookEndpoint({
|
|
39
|
+
id: context.id,
|
|
40
|
+
http: context.use(httpHostToken),
|
|
41
|
+
config,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return new SatoriWsEndpoint({
|
|
45
|
+
id: context.id,
|
|
46
|
+
config,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* `satori endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
|
|
4
|
+
* commands/satori/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
5
|
+
*/
|
|
6
|
+
import { createEndpointCommands } from 'zhin.js/adapter';
|
|
7
|
+
import { defineCommand } from 'zhin.js/command';
|
|
8
|
+
import { satoriRuntimeStateToken } from "../../../lib/satori-runtime-state.js";
|
|
9
|
+
export const satoriEndpointCommands = createEndpointCommands({
|
|
10
|
+
adapterKey: 'satori',
|
|
11
|
+
adapterDisplayName: 'Satori',
|
|
12
|
+
fields: [
|
|
13
|
+
{ key: 'baseUrl', required: true, description: 'Satori 服务 base URL' },
|
|
14
|
+
{ key: 'path', description: 'webhook 路径(connection: webhook)' },
|
|
15
|
+
{ key: 'token', env: true, description: 'Satori access token' },
|
|
16
|
+
],
|
|
17
|
+
running: (use) => use(satoriRuntimeStateToken).endpoints.values(),
|
|
18
|
+
describeEntry: (entry) => `baseUrl: ${String(entry.baseUrl)}`,
|
|
19
|
+
}, defineCommand);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `satori endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
|
|
3
|
+
* commands/satori/endpoint/ 下的 list / add / remove 直接默认导出这三项。
|
|
4
|
+
*/
|
|
5
|
+
import { createEndpointCommands } from 'zhin.js/adapter';
|
|
6
|
+
import { defineCommand } from 'zhin.js/command';
|
|
7
|
+
import { satoriRuntimeStateToken } from '../../../src/satori-runtime-state.js';
|
|
8
|
+
|
|
9
|
+
export const satoriEndpointCommands = createEndpointCommands({
|
|
10
|
+
adapterKey: 'satori',
|
|
11
|
+
adapterDisplayName: 'Satori',
|
|
12
|
+
fields: [
|
|
13
|
+
{ key: 'baseUrl', required: true, description: 'Satori 服务 base URL' },
|
|
14
|
+
{ key: 'path', description: 'webhook 路径(connection: webhook)' },
|
|
15
|
+
{ key: 'token', env: true, description: 'Satori access token' },
|
|
16
|
+
],
|
|
17
|
+
running: (use) => use(satoriRuntimeStateToken).endpoints.values(),
|
|
18
|
+
describeEntry: (entry) => `baseUrl: ${String(entry.baseUrl)}`,
|
|
19
|
+
}, defineCommand);
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SatoriV1Client, type SatoriV1Event } from '@imhelper/satori-v1';
|
|
2
|
+
import { type EventMap, type ImHelperEventMap } from 'imhelper';
|
|
3
|
+
import { type ClientEventPayloads } from 'zhin.js/adapter';
|
|
4
|
+
import type { ResolvedSatoriConfig, SatoriApiOptions, callSatoriApi } from './protocol.js';
|
|
5
|
+
export { SatoriV1Client as SatoriClient } from '@imhelper/satori-v1';
|
|
6
|
+
type SatoriClientEvents = ImHelperEventMap<string, SatoriV1Event, EventMap<string>>;
|
|
7
|
+
export type SatoriClientEventMap = ClientEventPayloads<SatoriClientEvents>;
|
|
8
|
+
export declare function createSatoriEndpointClient(config: ResolvedSatoriConfig, request: typeof callSatoriApi, apiOptions: () => SatoriApiOptions): SatoriV1Client;
|
|
9
|
+
export declare function forwardSatoriClientEvents(client: SatoriV1Client, receive: (name: string, payload: unknown) => void): () => void;
|
|
10
|
+
declare module '@zhin.js/feature-kit' {
|
|
11
|
+
interface AdapterClientRegistry {
|
|
12
|
+
readonly satori: {
|
|
13
|
+
readonly client: SatoriV1Client;
|
|
14
|
+
readonly events: SatoriClientEventMap;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const satoriClient: import("@zhin.js/adapter").EndpointClientToken<SatoriV1Client, ClientEventPayloads<SatoriClientEvents>>;
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SatoriV1Client, } from '@imhelper/satori-v1';
|
|
2
|
+
import { EventFactory } from 'imhelper';
|
|
3
|
+
import { defineEndpointClient, forwardEndpointClientEvents, } from 'zhin.js/adapter';
|
|
4
|
+
export { SatoriV1Client as SatoriClient } from '@imhelper/satori-v1';
|
|
5
|
+
export function createSatoriEndpointClient(config, request, apiOptions) {
|
|
6
|
+
return new SatoriV1Client({
|
|
7
|
+
baseUrl: config.baseUrl,
|
|
8
|
+
selfId: config.id,
|
|
9
|
+
accessToken: config.token,
|
|
10
|
+
receiveMode: 'manual',
|
|
11
|
+
call: (resource, method, params) => request(apiOptions(), resource, method, params ?? {}),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const satoriClientEventNames = Object.freeze([
|
|
15
|
+
...EventFactory.getSupportedEventTypes(),
|
|
16
|
+
'event',
|
|
17
|
+
]);
|
|
18
|
+
export function forwardSatoriClientEvents(client, receive) {
|
|
19
|
+
return forwardEndpointClientEvents(client, satoriClientEventNames, receive);
|
|
20
|
+
}
|
|
21
|
+
export const satoriClient = defineEndpointClient('satori');
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* SatoriEndpoint — WebSocket and webhook lifecycle, outbound, admit.
|
|
4
|
+
*/
|
|
5
|
+
import { ClientEndpoint, type EndpointControl, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
|
|
6
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
7
|
+
import type { CapabilityId } from 'zhin.js';
|
|
8
|
+
import { callSatoriApi, type ResolvedSatoriWebhookConfig, type ResolvedSatoriWsConfig } from './protocol.js';
|
|
9
|
+
import { type SatoriClient } from './client.js';
|
|
10
|
+
import { type CreateSatoriWebSocket } from './ws.js';
|
|
11
|
+
export type SatoriApiCaller = typeof callSatoriApi;
|
|
12
|
+
export interface SatoriWsEndpointOptions {
|
|
13
|
+
readonly id: CapabilityId;
|
|
14
|
+
readonly config: ResolvedSatoriWsConfig;
|
|
15
|
+
readonly createWebSocket?: CreateSatoriWebSocket;
|
|
16
|
+
readonly callApi?: SatoriApiCaller;
|
|
17
|
+
}
|
|
18
|
+
export declare class SatoriWsEndpoint extends ClientEndpoint<SatoriClient> {
|
|
19
|
+
#private;
|
|
20
|
+
readonly client: SatoriClient;
|
|
21
|
+
readonly management: EndpointManagement;
|
|
22
|
+
readonly control: EndpointControl;
|
|
23
|
+
constructor(options: SatoriWsEndpointOptions);
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
send({ conversation, payload }: EndpointSendRequest): Promise<string>;
|
|
27
|
+
recall(id: string, fallbackChannelId?: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export interface SatoriWebhookEndpointOptions {
|
|
30
|
+
readonly id: CapabilityId;
|
|
31
|
+
readonly http: HttpHost;
|
|
32
|
+
readonly config: ResolvedSatoriWebhookConfig;
|
|
33
|
+
readonly callApi?: SatoriApiCaller;
|
|
34
|
+
}
|
|
35
|
+
export declare class SatoriWebhookEndpoint extends ClientEndpoint<SatoriClient> {
|
|
36
|
+
#private;
|
|
37
|
+
readonly client: SatoriClient;
|
|
38
|
+
readonly management: EndpointManagement;
|
|
39
|
+
readonly control: EndpointControl;
|
|
40
|
+
constructor(options: SatoriWebhookEndpointOptions);
|
|
41
|
+
/** Used by webhook handler. */
|
|
42
|
+
get isOpen(): boolean;
|
|
43
|
+
get config(): ResolvedSatoriWebhookConfig;
|
|
44
|
+
acceptHttp(request: IncomingMessage, response: ServerResponse): Promise<void>;
|
|
45
|
+
start(): Promise<void>;
|
|
46
|
+
stop(): Promise<void>;
|
|
47
|
+
send({ conversation, payload }: EndpointSendRequest): Promise<string>;
|
|
48
|
+
recall(id: string, fallbackChannelId?: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export type SatoriManagementApi = (resource: string, method: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Satori endpoint 的 EndpointManagement 语义端口(ws / webhook 共用),
|
|
53
|
+
* 数据走协议 API:guild.list / channel.list / guild-member.list。
|
|
54
|
+
*/
|
|
55
|
+
export declare function createSatoriEndpointManagement(api: SatoriManagementApi): EndpointManagement;
|
|
56
|
+
export type { CreateSatoriWebSocket, SatoriWsSocket } from './ws.js';
|