@zhin.js/adapter-satori 1.1.26 → 1.1.28

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/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { SatoriOpcode, buildWsUrl, callSatoriApi, extractCreatedMessageId, formatInboundContent, formatSatoriOutbound, isMessageEvent, isPrivateChannel, resolveInboundSender, resolveSatoriConfig, satoriInboundConversation, } from './protocol.js';
1
+ export { SatoriOpcode, buildWsUrl, callSatoriApi, extractCreatedMessageId, decodeSatoriContent, formatInboundContent, formatSatoriOutbound, inboundSatoriSegments, isMessageEvent, mapSatoriFriendRequest, normalizeSatoriGuildRoles, readSatoriFriend, satoriFriendApproveParams, satoriReactionParams, mapGuildEmojiNotice, satoriMessageCreateParams, withSatoriReferrer, isPrivateChannel, resolveInboundSender, resolveSatoriConfig, satoriInboundConversation, } from './protocol.js';
2
2
  export { SatoriWebhookEndpoint, SatoriWsEndpoint, } from './endpoint.js';
3
3
  export { handleSatoriWebhookRequest, registerSatoriWebhookRoutes, resolveSatoriOpcode, verifySatoriToken, } from './webhook.js';
4
4
  export { WS_OPEN, defaultCreateWebSocket, } from './ws.js';
package/lib/protocol.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { EndpointProfileConfiguration } from 'zhin.js/adapter';
2
- /** Satori protocol helpers. Spec: https://satori.chat/zh-CN/protocol/overview.html */
3
- import { type ConversationRef } from '@zhin.js/im-contract';
2
+ import { type IncomingNotice, type IncomingRequest } from '@zhin.js/core';
3
+ import { type ConversationRef, type Segment } from '@zhin.js/im-contract';
4
4
  /** Opcode:EVENT=0, PING=1, PONG=2, IDENTIFY=3, READY=4, META=5 */
5
5
  export declare const SatoriOpcode: {
6
6
  readonly EVENT: 0;
@@ -19,6 +19,48 @@ export interface SatoriUser {
19
19
  readonly name?: string;
20
20
  readonly avatar?: string;
21
21
  }
22
+ /**
23
+ * Satori Emoji。字段对齐文档 https://satori.chat/zh-CN/resources/emoji.html (`id`、`name?`)。
24
+ * `@imhelper/satori-v1` 1.0.7 / 1.0.10 没有这个类型。上游 `feat/satori-1.3-alignment`
25
+ * 会补上,但这次不发布 npm,适配器先用本地声明。上游发版后可以换成 SDK 导出的官方类型。
26
+ */
27
+ export interface SatoriEmoji {
28
+ readonly id: string;
29
+ readonly name?: string;
30
+ }
31
+ /**
32
+ * 群组角色。文档只声明 `id` 和 `name?`。
33
+ * 协议源码里还有 color、position 等字段,这里以文档为准,不建模它们。
34
+ * `@imhelper/satori-v1` 没有这个类型。上游 `feat/satori-1.3-alignment` 会补,但未发 npm。
35
+ * 上游发版后可以换成官方类型。
36
+ * @see https://satori.chat/zh-CN/resources/role.html
37
+ */
38
+ export interface SatoriGuildRole {
39
+ readonly id: string;
40
+ readonly name?: string;
41
+ }
42
+ /**
43
+ * 好友。文档形状是 `{ user?, nick? }`,不是带顶层 `id` / `name` / `avatar` 的 User。
44
+ * 1.0.10 的 `directory-api.getFriendList` 仍按 User 读取 `friend.id`。本地按文档解析。
45
+ * 上游发版后可以换成官方类型。
46
+ * @see https://satori.chat/zh-CN/resources/friend.html
47
+ */
48
+ export interface SatoriFriend {
49
+ readonly user?: SatoriUser;
50
+ readonly nick?: string;
51
+ }
52
+ /**
53
+ * 群组成员。`roles` 在 1.3 起是 `GuildRole[]`,不再是 `string[]`。
54
+ * 本地类型。上游发版后可以换成官方类型。
55
+ * @see https://satori.chat/zh-CN/resources/member.html
56
+ */
57
+ export interface SatoriGuildMember {
58
+ readonly user?: SatoriUser;
59
+ readonly nick?: string;
60
+ readonly avatar?: string;
61
+ readonly joined_at?: number;
62
+ readonly roles?: readonly SatoriGuildRole[];
63
+ }
22
64
  export interface SatoriChannel {
23
65
  readonly id: string;
24
66
  /** 0=TEXT, 1=DIRECT, 2=CATEGORY, 3=VOICE */
@@ -56,11 +98,26 @@ export interface SatoriEventBody {
56
98
  readonly id: string;
57
99
  readonly name?: string;
58
100
  };
59
- readonly member?: {
60
- readonly user?: SatoriUser;
61
- readonly nick?: string;
62
- readonly roles?: string[];
63
- };
101
+ readonly member?: SatoriGuildMember;
102
+ /**
103
+ * 事件里的好友。本地字段,原因见 {@link SatoriFriend}。
104
+ * @see https://satori.chat/zh-CN/protocol/events.html
105
+ */
106
+ readonly friend?: SatoriFriend;
107
+ readonly operator?: SatoriUser;
108
+ /**
109
+ * 事件表情。本地字段,原因见 {@link SatoriEmoji}。
110
+ * @see https://satori.chat/zh-CN/protocol/events.html
111
+ */
112
+ readonly emoji?: SatoriEmoji;
113
+ /**
114
+ * 被动请求的来源上下文。协议不约束内部结构,发送时必须原样回传。
115
+ * 资源页 `message.create` 表格目前没列出该字段,但被动请求页要求传入,
116
+ * 协议方法表也包含 `referrer`。这里以被动请求页为准。
117
+ * 本地字段:`SatoriV1Event` 尚未声明它。上游发版后可以换成官方类型。
118
+ * @see https://satori.chat/zh-CN/advanced/passive.html
119
+ */
120
+ readonly referrer?: unknown;
64
121
  readonly [key: string]: unknown;
65
122
  }
66
123
  export interface SatoriApiOptions {
@@ -73,6 +130,7 @@ export interface SatoriApiOptions {
73
130
  export interface SatoriWireSegment {
74
131
  readonly type: string;
75
132
  readonly data?: Record<string, unknown>;
133
+ readonly platform?: Record<string, unknown>;
76
134
  }
77
135
  /** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
78
136
  export interface SatoriEndpointConfig extends EndpointProfileConfiguration {
@@ -129,6 +187,19 @@ export declare function callSatoriApi<T = unknown>({ resource, method, params, .
129
187
  export declare function formatInboundContent(body: SatoriEventBody & {
130
188
  message: SatoriMessage;
131
189
  }): string;
190
+ export declare function decodeSatoriContent(content: string, depth?: number): Segment[];
191
+ /** 仅在出现非文本元素时把解码结果送进消息管道,纯文本保持原来的 content-only 形状。 */
192
+ export declare function inboundSatoriSegments(content: string): readonly Segment[] | undefined;
193
+ /**
194
+ * `guild-emoji-*` → `notice.group.emoji_*`。
195
+ * 文档只要求资源 `emoji`,没有可回复频道,因此不填 conversation。
196
+ * 上游 SDK 目前只把这些事件原样 emit("event"),映射放在适配器内。
197
+ * @see https://satori.chat/zh-CN/resources/emoji.html
198
+ */
199
+ export declare function mapGuildEmojiNotice(body: SatoriEventBody, endpointId: string): IncomingNotice | undefined;
200
+ export declare function withSatoriReferrer<T>(referrer: unknown, run: () => T): T;
201
+ /** `message.create` 参数。处理尚未结束时原样附带 referrer,不挑字段、不改名。 */
202
+ export declare function satoriMessageCreateParams(channelId: string, content: string): Record<string, unknown>;
132
203
  /**
133
204
  * 入站归一化 → ConversationRef:Channel.type 1 (DIRECT) → kind 'private';
134
205
  * 其余频道消息 → kind 'group',所属 guild 容器进 `parent`(kind 'channel')。
@@ -155,8 +226,49 @@ export declare function parseMessageRef(id: string): {
155
226
  messageId: string;
156
227
  };
157
228
  /**
158
- * Wire-encode an already-rendered outbound payload into Satori message content.
159
- * Segment canonicalization is intentionally not done here.
229
+ * 把已渲染的出站载荷编成 Satori 消息字符串。
230
+ * at / mention → `<at>`,image → `<img>`,其余媒体用同名标准元素,emoji → `<emoji>`。
231
+ * 整段字符串原样发送(调用方可能已经写好标记);段数组里的文本会转义。
232
+ * 上游 message-codec 把段编成 `{type, attrs}` 对象,而且不会把 mention/image 改成 at/img。
233
+ * 这里在适配器内按文档元素编码。上游发版后如果 SDK 直接产出这些元素,可以改走 SDK。
234
+ * @see https://satori.chat/zh-CN/protocol/elements.html
160
235
  */
161
236
  export declare function formatSatoriOutbound(payload: unknown): string;
162
237
  export declare function extractCreatedMessageId(result: unknown): string;
238
+ /**
239
+ * 把 `guild-member.list` 的 `roles` 收成 `GuildRole[]`。
240
+ * 旧 SDK 可能仍下发 `string[]`,这里收成 `{ id }`。上游发版并保证对象数组后,字符串分支可以去掉。
241
+ */
242
+ export declare function normalizeSatoriGuildRoles(value: unknown): readonly SatoriGuildRole[] | undefined;
243
+ /** 成员列表原样保留其余字段,只把 roles 收成 GuildRole[]。 */
244
+ export declare function withSatoriGuildRoles<T>(member: T): T;
245
+ /**
246
+ * 按 `{ user, nick }` 读取好友。顶层 `id` / `name` 是 1.0.10 误用的 User 形状,这里不认。
247
+ */
248
+ export declare function readSatoriFriend(value: unknown): SatoriFriend | undefined;
249
+ export type SatoriReactionMethod = 'create' | 'delete' | 'clear' | 'list';
250
+ /**
251
+ * reaction.* 的参数名是 `emoji_id`,不是 1.0.10 `addMessageReactionIn` 用的 `emoji`。
252
+ * clear 不传 emoji_id 表示清除全部表态。
253
+ * @see https://satori.chat/zh-CN/resources/reaction.html
254
+ */
255
+ export declare function satoriReactionParams(method: SatoriReactionMethod, input: {
256
+ readonly channelId: string;
257
+ readonly messageId: string;
258
+ readonly emojiId?: string;
259
+ readonly userId?: string;
260
+ readonly next?: string;
261
+ }): Record<string, unknown>;
262
+ /** `friend.approve` 同时表达通过和拒绝。 */
263
+ export declare function satoriFriendApproveParams(messageId: string, approve: boolean, comment?: string): Record<string, unknown>;
264
+ export interface SatoriFriendRequestActions {
265
+ approve(messageId: string, comment?: string): Promise<void>;
266
+ reject(messageId: string, reason?: string): Promise<void>;
267
+ }
268
+ /**
269
+ * `friend-request` → `request.friend.add`,让它进入 request.receive 管道。
270
+ * 文档的必需资源是 `user`。`friend.approve` 的请求 ID 是 `message_id`;
271
+ * 事件没有 `message.id` 时仍然投递,但批准/拒绝会说明缺少该字段。
272
+ * @see https://satori.chat/zh-CN/resources/friend.html
273
+ */
274
+ export declare function mapSatoriFriendRequest(body: SatoriEventBody, endpointId: string, actions: SatoriFriendRequestActions): IncomingRequest | undefined;