@theokit/gateway 0.12.0 → 0.14.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.
- package/CHANGELOG.md +157 -0
- package/README.md +104 -15
- package/dist/index.cjs +437 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +383 -86
- package/dist/index.d.ts +383 -86
- package/dist/index.js +435 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The event variants of the platforms added in S-003: batch 1 (B-354 to B-358) and batch 2 (B-359
|
|
3
|
+
* to B-363).
|
|
4
|
+
*
|
|
5
|
+
* They live beside `message-event.ts` rather than in it to keep that file, which holds the registry
|
|
6
|
+
* and its guard, within the 500-line budget. `message-event.ts` files each of them under its key
|
|
7
|
+
* in `PlatformEventRegistry`; the package barrel exports them.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Signal-specific event variant (B-354), received from `signal-cli jsonRpc`. */
|
|
11
|
+
interface SignalMessageEvent extends BaseMessageEvent {
|
|
12
|
+
readonly platform: "signal";
|
|
13
|
+
readonly signal: {
|
|
14
|
+
/** Envelope timestamp (ms since epoch); Signal's own message id. */
|
|
15
|
+
readonly timestamp: number;
|
|
16
|
+
/** Sender's phone number, when signal-cli knows it. */
|
|
17
|
+
readonly sourceNumber?: string;
|
|
18
|
+
/** Sender's account UUID, when signal-cli knows it. */
|
|
19
|
+
readonly sourceUuid?: string;
|
|
20
|
+
/** Group id, present only for a group message. */
|
|
21
|
+
readonly groupId?: string;
|
|
22
|
+
/** Raw signal-cli envelope — escape hatch. */
|
|
23
|
+
readonly raw: unknown;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** iMessage-specific event variant (B-355), received from `imsg rpc` on a signed-in Mac. */
|
|
27
|
+
interface IMessageMessageEvent extends BaseMessageEvent {
|
|
28
|
+
readonly platform: "imessage";
|
|
29
|
+
readonly imessage: {
|
|
30
|
+
/** `imsg`'s numeric chat id; the send target for a reply. */
|
|
31
|
+
readonly chatId: number;
|
|
32
|
+
/** Messages' own message GUID. */
|
|
33
|
+
readonly guid: string;
|
|
34
|
+
/** `imsg`'s `is_group` for the chat; agrees with `channel.type === "group"`. */
|
|
35
|
+
readonly isGroup: boolean;
|
|
36
|
+
/** Participant handles (phone numbers or emails) as `imsg` reports them for the chat. */
|
|
37
|
+
readonly participants: readonly string[];
|
|
38
|
+
/** Raw `imsg` notification payload — escape hatch. */
|
|
39
|
+
readonly raw: unknown;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Google Chat-specific event variant (B-356), posted to the Chat app's HTTPS endpoint. */
|
|
43
|
+
interface GoogleChatMessageEvent extends BaseMessageEvent {
|
|
44
|
+
readonly platform: "google_chat";
|
|
45
|
+
readonly google_chat: {
|
|
46
|
+
/** The message's resource name, `spaces/<space>/messages/<message>`. */
|
|
47
|
+
readonly messageName: string;
|
|
48
|
+
/** The space's resource name, `spaces/<space>`; the send target for a reply. */
|
|
49
|
+
readonly spaceName: string;
|
|
50
|
+
/** The space's `spaceType` (`SPACE`, `GROUP_CHAT` or `DIRECT_MESSAGE`), when Chat sent one. */
|
|
51
|
+
readonly spaceType?: string;
|
|
52
|
+
/** The thread's resource name, when the message is in a thread. */
|
|
53
|
+
readonly threadName?: string;
|
|
54
|
+
/** Raw Chat event — escape hatch. */
|
|
55
|
+
readonly raw: unknown;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** IRC-specific event variant (B-357), read from a PRIVMSG on the adapter's own connection. */
|
|
59
|
+
interface IrcMessageEvent extends BaseMessageEvent {
|
|
60
|
+
readonly platform: "irc";
|
|
61
|
+
readonly irc: {
|
|
62
|
+
/** Where the PRIVMSG was addressed: a channel, `#name`, or the adapter's own nick for a DM. */
|
|
63
|
+
readonly target: string;
|
|
64
|
+
/** The sender's nick, from the line's prefix. */
|
|
65
|
+
readonly nick: string;
|
|
66
|
+
/** True for a CTCP ACTION (`/me`); `text` then holds the action without its CTCP framing. */
|
|
67
|
+
readonly action: boolean;
|
|
68
|
+
/** The line's IRCv3 message tags, unescaped; empty when the server sent none. */
|
|
69
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
70
|
+
/** The raw line as the server sent it, without CRLF — escape hatch. */
|
|
71
|
+
readonly raw: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Nextcloud Talk event variant (B-358), read from a bot webhook `Create` activity that carried a
|
|
76
|
+
* signature the adapter verified.
|
|
77
|
+
*/
|
|
78
|
+
interface NextcloudTalkMessageEvent extends BaseMessageEvent {
|
|
79
|
+
readonly platform: "nextcloud_talk";
|
|
80
|
+
readonly nextcloud_talk: {
|
|
81
|
+
/** The conversation's token, the `target.id` of the activity; a reply goes to it. */
|
|
82
|
+
readonly roomToken: string;
|
|
83
|
+
/** Talk's id for the message, the activity's `object.id`. */
|
|
84
|
+
readonly messageId: string;
|
|
85
|
+
/** Who wrote it, as Talk names actors: `users/<id>`, `guests/<id>`, `bots/<id>`… */
|
|
86
|
+
readonly actorId: string;
|
|
87
|
+
/** The id of the message this one answers, when it is a reply. */
|
|
88
|
+
readonly replyToId?: string;
|
|
89
|
+
/** The parsed webhook body — escape hatch. */
|
|
90
|
+
readonly raw: unknown;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Nostr event variant (B-359): a NIP-17 direct message (kind 14) or a NIP-04 one (kind 4). */
|
|
94
|
+
interface NostrMessageEvent extends BaseMessageEvent {
|
|
95
|
+
readonly platform: "nostr";
|
|
96
|
+
readonly nostr: {
|
|
97
|
+
/** The sender's public key, 64 lowercase hex characters; the send target for a reply. */
|
|
98
|
+
readonly pubkey: string;
|
|
99
|
+
/** 14 for a NIP-17 rumor unwrapped from a gift wrap, 4 for a NIP-04 encrypted message. */
|
|
100
|
+
readonly kind: 4 | 14;
|
|
101
|
+
/** The message's `created_at` in Unix seconds, as its sender stated it. */
|
|
102
|
+
readonly createdAt: number;
|
|
103
|
+
/** The decrypted rumor or kind 4 event — escape hatch. */
|
|
104
|
+
readonly raw: unknown;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Feishu/Lark event variant (B-360), an `im.message.receive_v1` event from the long connection. */
|
|
108
|
+
interface FeishuLarkMessageEvent extends BaseMessageEvent {
|
|
109
|
+
readonly platform: "feishu_lark";
|
|
110
|
+
readonly feishu_lark: {
|
|
111
|
+
/** The chat's `chat_id`; the send target for a reply. */
|
|
112
|
+
readonly chatId: string;
|
|
113
|
+
/** The message's `message_id`. */
|
|
114
|
+
readonly messageId: string;
|
|
115
|
+
/** The sender's `open_id`. */
|
|
116
|
+
readonly openId: string;
|
|
117
|
+
/** The event's `event_id`, which a redelivery repeats. */
|
|
118
|
+
readonly eventId: string;
|
|
119
|
+
/** Raw event — escape hatch. */
|
|
120
|
+
readonly raw: unknown;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** Synology Chat event variant (B-361), an outgoing bot callback from the NAS. */
|
|
124
|
+
interface SynologyChatMessageEvent extends BaseMessageEvent {
|
|
125
|
+
readonly platform: "synology_chat";
|
|
126
|
+
readonly synology_chat: {
|
|
127
|
+
/** The sender's numeric user id; a reply goes to `user_ids: [userId]`. */
|
|
128
|
+
readonly userId: number;
|
|
129
|
+
/** The sender's user name. */
|
|
130
|
+
readonly username: string;
|
|
131
|
+
/** The callback's `post_id`. */
|
|
132
|
+
readonly postId: string;
|
|
133
|
+
/** The callback's `timestamp`. */
|
|
134
|
+
readonly timestamp: number;
|
|
135
|
+
/** The parsed callback body — escape hatch. */
|
|
136
|
+
readonly raw: unknown;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Tlon event variant (B-362), a DM read from the ship's `chat` app at `/v3`. */
|
|
140
|
+
interface TlonUrbitMessageEvent extends BaseMessageEvent {
|
|
141
|
+
readonly platform: "tlon_urbit";
|
|
142
|
+
readonly tlon_urbit: {
|
|
143
|
+
/** The sender's ship, `~name`; the send target for a reply. */
|
|
144
|
+
readonly ship: string;
|
|
145
|
+
/** The message id, `<ship>/<@ud>`. */
|
|
146
|
+
readonly messageId: string;
|
|
147
|
+
/** The essay's `sent` time in Unix milliseconds. */
|
|
148
|
+
readonly sent: number;
|
|
149
|
+
/** The `/v3` event — escape hatch. */
|
|
150
|
+
readonly raw: unknown;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** Buzz event variant (B-367), a `message.created` realtime event. */
|
|
154
|
+
interface BuzzMessageEvent extends BaseMessageEvent {
|
|
155
|
+
readonly platform: "buzz";
|
|
156
|
+
readonly buzz: {
|
|
157
|
+
/** The message's id. */
|
|
158
|
+
readonly messageId: string;
|
|
159
|
+
/** The channel the message was posted in; for a DM, the DM channel id. */
|
|
160
|
+
readonly channelId: string;
|
|
161
|
+
/** The workspace the event belongs to, when the event names one. */
|
|
162
|
+
readonly workspaceId: string;
|
|
163
|
+
/** The parent message id when the message is a thread reply, else `""`. */
|
|
164
|
+
readonly threadId: string;
|
|
165
|
+
/** The realtime cursor of the event, `""` when absent. */
|
|
166
|
+
readonly cursor: string;
|
|
167
|
+
/** The event object — escape hatch. */
|
|
168
|
+
readonly raw: unknown;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** ClickClack event variant (B-366), a `message.created` realtime event. */
|
|
172
|
+
interface ClickClackMessageEvent extends BaseMessageEvent {
|
|
173
|
+
readonly platform: "clickclack";
|
|
174
|
+
readonly clickclack: {
|
|
175
|
+
/** The message's id. */
|
|
176
|
+
readonly messageId: string;
|
|
177
|
+
/** The channel the message was posted in; for a DM, the DM channel id. */
|
|
178
|
+
readonly channelId: string;
|
|
179
|
+
/** The workspace the event belongs to, when the event names one. */
|
|
180
|
+
readonly workspaceId: string;
|
|
181
|
+
/** The parent message id when the message is a thread reply, else `""`. */
|
|
182
|
+
readonly threadId: string;
|
|
183
|
+
/** The realtime cursor of the event, `""` when absent. */
|
|
184
|
+
readonly cursor: string;
|
|
185
|
+
/** The event object — escape hatch. */
|
|
186
|
+
readonly raw: unknown;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Zalo Personal event variant (B-365), a message read from a personal Zalo account's listener. */
|
|
190
|
+
interface ZaloPersonalMessageEvent extends BaseMessageEvent {
|
|
191
|
+
readonly platform: "zalo_personal";
|
|
192
|
+
readonly zalo_personal: {
|
|
193
|
+
/** The message's `msgId`. */
|
|
194
|
+
readonly messageId: string;
|
|
195
|
+
/** The conversation's id: the peer's uid for a direct chat, the group id for a group. */
|
|
196
|
+
readonly threadId: string;
|
|
197
|
+
/** `"user"` for a direct chat, `"group"` for a group. */
|
|
198
|
+
readonly threadType: "user" | "group";
|
|
199
|
+
/** The sender's uid. */
|
|
200
|
+
readonly senderUid: string;
|
|
201
|
+
/** The listener's message object — escape hatch. */
|
|
202
|
+
readonly raw: unknown;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/** Twitch event variant (B-363), a `channel.chat.message` EventSub notification. */
|
|
206
|
+
interface TwitchMessageEvent extends BaseMessageEvent {
|
|
207
|
+
readonly platform: "twitch";
|
|
208
|
+
readonly twitch: {
|
|
209
|
+
/** The channel's broadcaster user id; the send target for a reply. */
|
|
210
|
+
readonly broadcasterUserId: string;
|
|
211
|
+
/** The chatter's user id. */
|
|
212
|
+
readonly chatterUserId: string;
|
|
213
|
+
/** The chatter's login name. */
|
|
214
|
+
readonly chatterLogin: string;
|
|
215
|
+
/** The chat message's `message_id`. */
|
|
216
|
+
readonly messageId: string;
|
|
217
|
+
/** The notification's `event` object — escape hatch. */
|
|
218
|
+
readonly raw: unknown;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
1
222
|
/**
|
|
2
223
|
* `MessageEvent` — canonical inbound shape every adapter emits (T1.1, ADR D173).
|
|
3
224
|
*
|
|
@@ -23,6 +244,21 @@
|
|
|
23
244
|
*
|
|
24
245
|
* @public
|
|
25
246
|
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The audio of a voice note an inbound message carries (B-715): its bytes, their media type and
|
|
250
|
+
* the length the platform reported.
|
|
251
|
+
*
|
|
252
|
+
* The bytes travel by reference, as an outbound attachment's do: hooks and the handler see the
|
|
253
|
+
* same array.
|
|
254
|
+
*/
|
|
255
|
+
interface InboundAudio {
|
|
256
|
+
readonly data: Uint8Array;
|
|
257
|
+
/** The media type of `data`, such as `audio/ogg`. */
|
|
258
|
+
readonly mediaType: string;
|
|
259
|
+
/** The length in whole seconds the platform reported; 0 when it reported none. */
|
|
260
|
+
readonly durationSeconds: number;
|
|
261
|
+
}
|
|
26
262
|
/** Fields common to every platform's inbound event. */
|
|
27
263
|
interface BaseMessageEvent {
|
|
28
264
|
/** Stable id used as a session-key segment and for dedup. */
|
|
@@ -55,6 +291,11 @@ interface BaseMessageEvent {
|
|
|
55
291
|
readonly receivedAt: number;
|
|
56
292
|
/** Optional reply-target message id. */
|
|
57
293
|
readonly replyTo?: string;
|
|
294
|
+
/**
|
|
295
|
+
* The voice note's audio, when the adapter read one (B-715). Absent for a message with no voice,
|
|
296
|
+
* and for a voice the adapter could not read.
|
|
297
|
+
*/
|
|
298
|
+
readonly audio?: InboundAudio;
|
|
58
299
|
}
|
|
59
300
|
/** Telegram-specific event variant. */
|
|
60
301
|
interface TelegramMessageEvent extends BaseMessageEvent {
|
|
@@ -247,89 +488,6 @@ interface MatrixMessageEvent extends BaseMessageEvent {
|
|
|
247
488
|
readonly raw: unknown;
|
|
248
489
|
};
|
|
249
490
|
}
|
|
250
|
-
/** Signal-specific event variant (B-354), received from `signal-cli jsonRpc`. */
|
|
251
|
-
interface SignalMessageEvent extends BaseMessageEvent {
|
|
252
|
-
readonly platform: "signal";
|
|
253
|
-
readonly signal: {
|
|
254
|
-
/** Envelope timestamp (ms since epoch); Signal's own message id. */
|
|
255
|
-
readonly timestamp: number;
|
|
256
|
-
/** Sender's phone number, when signal-cli knows it. */
|
|
257
|
-
readonly sourceNumber?: string;
|
|
258
|
-
/** Sender's account UUID, when signal-cli knows it. */
|
|
259
|
-
readonly sourceUuid?: string;
|
|
260
|
-
/** Group id, present only for a group message. */
|
|
261
|
-
readonly groupId?: string;
|
|
262
|
-
/** Raw signal-cli envelope — escape hatch. */
|
|
263
|
-
readonly raw: unknown;
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/** iMessage-specific event variant (B-355), received from `imsg rpc` on a signed-in Mac. */
|
|
267
|
-
interface IMessageMessageEvent extends BaseMessageEvent {
|
|
268
|
-
readonly platform: "imessage";
|
|
269
|
-
readonly imessage: {
|
|
270
|
-
/** `imsg`'s numeric chat id; the send target for a reply. */
|
|
271
|
-
readonly chatId: number;
|
|
272
|
-
/** Messages' own message GUID. */
|
|
273
|
-
readonly guid: string;
|
|
274
|
-
/** `imsg`'s `is_group` for the chat; agrees with `channel.type === "group"`. */
|
|
275
|
-
readonly isGroup: boolean;
|
|
276
|
-
/** Participant handles (phone numbers or emails) as `imsg` reports them for the chat. */
|
|
277
|
-
readonly participants: readonly string[];
|
|
278
|
-
/** Raw `imsg` notification payload — escape hatch. */
|
|
279
|
-
readonly raw: unknown;
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
/** Google Chat-specific event variant (B-356), posted to the Chat app's HTTPS endpoint. */
|
|
283
|
-
interface GoogleChatMessageEvent extends BaseMessageEvent {
|
|
284
|
-
readonly platform: "google_chat";
|
|
285
|
-
readonly google_chat: {
|
|
286
|
-
/** The message's resource name, `spaces/<space>/messages/<message>`. */
|
|
287
|
-
readonly messageName: string;
|
|
288
|
-
/** The space's resource name, `spaces/<space>`; the send target for a reply. */
|
|
289
|
-
readonly spaceName: string;
|
|
290
|
-
/** The space's `spaceType` (`SPACE`, `GROUP_CHAT` or `DIRECT_MESSAGE`), when Chat sent one. */
|
|
291
|
-
readonly spaceType?: string;
|
|
292
|
-
/** The thread's resource name, when the message is in a thread. */
|
|
293
|
-
readonly threadName?: string;
|
|
294
|
-
/** Raw Chat event — escape hatch. */
|
|
295
|
-
readonly raw: unknown;
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
/** IRC-specific event variant (B-357), read from a PRIVMSG on the adapter's own connection. */
|
|
299
|
-
interface IrcMessageEvent extends BaseMessageEvent {
|
|
300
|
-
readonly platform: "irc";
|
|
301
|
-
readonly irc: {
|
|
302
|
-
/** Where the PRIVMSG was addressed: a channel, `#name`, or the adapter's own nick for a DM. */
|
|
303
|
-
readonly target: string;
|
|
304
|
-
/** The sender's nick, from the line's prefix. */
|
|
305
|
-
readonly nick: string;
|
|
306
|
-
/** True for a CTCP ACTION (`/me`); `text` then holds the action without its CTCP framing. */
|
|
307
|
-
readonly action: boolean;
|
|
308
|
-
/** The line's IRCv3 message tags, unescaped; empty when the server sent none. */
|
|
309
|
-
readonly tags: Readonly<Record<string, string>>;
|
|
310
|
-
/** The raw line as the server sent it, without CRLF — escape hatch. */
|
|
311
|
-
readonly raw: string;
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Nextcloud Talk event variant (B-358), read from a bot webhook `Create` activity that carried a
|
|
316
|
-
* signature the adapter verified.
|
|
317
|
-
*/
|
|
318
|
-
interface NextcloudTalkMessageEvent extends BaseMessageEvent {
|
|
319
|
-
readonly platform: "nextcloud_talk";
|
|
320
|
-
readonly nextcloud_talk: {
|
|
321
|
-
/** The conversation's token, the `target.id` of the activity; a reply goes to it. */
|
|
322
|
-
readonly roomToken: string;
|
|
323
|
-
/** Talk's id for the message, the activity's `object.id`. */
|
|
324
|
-
readonly messageId: string;
|
|
325
|
-
/** Who wrote it, as Talk names actors: `users/<id>`, `guests/<id>`, `bots/<id>`… */
|
|
326
|
-
readonly actorId: string;
|
|
327
|
-
/** The id of the message this one answers, when it is a reply. */
|
|
328
|
-
readonly replyToId?: string;
|
|
329
|
-
/** The parsed webhook body — escape hatch. */
|
|
330
|
-
readonly raw: unknown;
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
491
|
/**
|
|
334
492
|
* The open registry every platform's inbound event is filed under.
|
|
335
493
|
*
|
|
@@ -368,6 +526,14 @@ interface PlatformEventRegistry {
|
|
|
368
526
|
google_chat: GoogleChatMessageEvent;
|
|
369
527
|
irc: IrcMessageEvent;
|
|
370
528
|
nextcloud_talk: NextcloudTalkMessageEvent;
|
|
529
|
+
nostr: NostrMessageEvent;
|
|
530
|
+
feishu_lark: FeishuLarkMessageEvent;
|
|
531
|
+
synology_chat: SynologyChatMessageEvent;
|
|
532
|
+
tlon_urbit: TlonUrbitMessageEvent;
|
|
533
|
+
twitch: TwitchMessageEvent;
|
|
534
|
+
zalo_personal: ZaloPersonalMessageEvent;
|
|
535
|
+
clickclack: ClickClackMessageEvent;
|
|
536
|
+
buzz: BuzzMessageEvent;
|
|
371
537
|
}
|
|
372
538
|
/**
|
|
373
539
|
* `true` only for `any` — the one type that would otherwise swallow the union.
|
|
@@ -474,6 +640,32 @@ type PlatformName = MessageEvent["platform"];
|
|
|
474
640
|
* (`TelegramAdapter`, `DiscordAdapter`, ...).
|
|
475
641
|
*/
|
|
476
642
|
|
|
643
|
+
/**
|
|
644
|
+
* An image an outbound message carries: its bytes and their media type (B-674).
|
|
645
|
+
*
|
|
646
|
+
* The bytes travel by reference: the runner does not copy them on the way to the adapter. The
|
|
647
|
+
* caller must not change `data` or the list until the send's promise settles: an adapter that
|
|
648
|
+
* sends several attachments reads each one only when its turn comes.
|
|
649
|
+
*/
|
|
650
|
+
interface OutboundImageAttachment {
|
|
651
|
+
readonly kind: "image";
|
|
652
|
+
/** The media type of `data`, such as `image/png`. */
|
|
653
|
+
readonly mediaType: string;
|
|
654
|
+
readonly data: Uint8Array;
|
|
655
|
+
/** A file name the platform may show; optional. */
|
|
656
|
+
readonly filename?: string;
|
|
657
|
+
}
|
|
658
|
+
/** An audio clip an outbound message carries, such as a spoken reply (B-715). Same rules as an image. */
|
|
659
|
+
interface OutboundAudioAttachment {
|
|
660
|
+
readonly kind: "audio";
|
|
661
|
+
/** The media type of `data`, such as `audio/ogg`. */
|
|
662
|
+
readonly mediaType: string;
|
|
663
|
+
readonly data: Uint8Array;
|
|
664
|
+
/** A file name the platform may show; optional. */
|
|
665
|
+
readonly filename?: string;
|
|
666
|
+
}
|
|
667
|
+
/** An attachment an outbound message carries, told apart by `kind`. */
|
|
668
|
+
type OutboundAttachment = OutboundImageAttachment | OutboundAudioAttachment;
|
|
477
669
|
/** Outbound message shape — what `sendMessage` accepts. */
|
|
478
670
|
interface OutboundMessage {
|
|
479
671
|
readonly channel: {
|
|
@@ -486,6 +678,11 @@ interface OutboundMessage {
|
|
|
486
678
|
readonly format?: "plain" | "markdown" | "html";
|
|
487
679
|
/** Optional reply target. */
|
|
488
680
|
readonly replyTo?: string;
|
|
681
|
+
/**
|
|
682
|
+
* Images to send with the text. An adapter whose {@link BasePlatformAdapter.supportsAttachments}
|
|
683
|
+
* is `false` refuses a non-empty list with `attachments_unsupported`; it never drops it.
|
|
684
|
+
*/
|
|
685
|
+
readonly attachments?: ReadonlyArray<OutboundAttachment>;
|
|
489
686
|
}
|
|
490
687
|
/** Send result — adapters return this instead of throwing on platform errors. */
|
|
491
688
|
interface SendResult {
|
|
@@ -510,13 +707,19 @@ interface SendResult {
|
|
|
510
707
|
* (rate-limit, 4xx, network). Programmer errors (missing config) MAY throw.
|
|
511
708
|
* - `onInbound(handler)` returns an unsubscribe function. EC-H: calling
|
|
512
709
|
* `onInbound` twice replaces the previous handler — does NOT stack.
|
|
513
|
-
* - `sendMessage` with empty text returns `{ ok: false, code: "empty_text" }`.
|
|
710
|
+
* - `sendMessage` with empty text and no attachments returns `{ ok: false, code: "empty_text" }`.
|
|
711
|
+
* An adapter that refuses attachments answers `attachments_unsupported` first, and one that
|
|
712
|
+
* sends them (Telegram) accepts empty text with an image.
|
|
514
713
|
* - `supportsEdit` says whether the adapter has an edit call. It is `false` unless the adapter
|
|
515
714
|
* overrides it, and it MUST NOT change with `connect()`. `true` does not promise that every
|
|
516
715
|
* edit is accepted: an adapter whose injected client lacks the edit call (Matrix) still answers
|
|
517
716
|
* `edit_unsupported`, which a caller handles like any other refusal.
|
|
518
717
|
* - `editMessage` returns a `SendResult` and never throws on platform errors. The default refuses
|
|
519
718
|
* with `edit_unsupported` and makes no platform call.
|
|
719
|
+
* - `supportsAttachments` says whether `sendMessage` can send `out.attachments`. It is `false`
|
|
720
|
+
* unless the adapter overrides it, and it MUST NOT change with `connect()`. An adapter that
|
|
721
|
+
* does not support them refuses a non-empty list with `attachments_unsupported` and makes no
|
|
722
|
+
* platform call; an edit carrying an attachment is refused the same way.
|
|
520
723
|
* - Edits are not ordered by the adapter. Two edits of one message id in flight at once reach the
|
|
521
724
|
* platform in either order, so a caller awaits each edit before the next, or keeps one in flight
|
|
522
725
|
* and coalesces to the latest text.
|
|
@@ -582,6 +785,14 @@ declare abstract class BasePlatformAdapter {
|
|
|
582
785
|
* edit-capable adapter can override it with `true`.
|
|
583
786
|
*/
|
|
584
787
|
readonly supportsEdit: boolean;
|
|
788
|
+
/**
|
|
789
|
+
* Whether {@link sendMessage} can send the images of `out.attachments` (B-674).
|
|
790
|
+
*
|
|
791
|
+
* Read it before attaching: on `false`, the adapter refuses a non-empty list with
|
|
792
|
+
* `attachments_unsupported`. Set at construction, never changed by `connect()`. Annotated as
|
|
793
|
+
* `boolean` so that an adapter that sends images can override it with `true`.
|
|
794
|
+
*/
|
|
795
|
+
readonly supportsAttachments: boolean;
|
|
585
796
|
/**
|
|
586
797
|
* Replace the text of a message this adapter sent, keeping its id.
|
|
587
798
|
*
|
|
@@ -733,9 +944,16 @@ interface ChannelRejection {
|
|
|
733
944
|
readonly platform: PlatformName;
|
|
734
945
|
readonly error: GatewayConfigurationError;
|
|
735
946
|
}
|
|
947
|
+
/** A built adapter paired with the descriptor that built it, so a consumer need not re-pair them. */
|
|
948
|
+
interface BuiltChannel {
|
|
949
|
+
readonly descriptor: ChannelDescriptor<BasePlatformAdapter>;
|
|
950
|
+
readonly adapter: BasePlatformAdapter;
|
|
951
|
+
}
|
|
736
952
|
/** What `createChannels` built and what it refused. */
|
|
737
953
|
interface CreateChannelsResult {
|
|
738
954
|
readonly adapters: BasePlatformAdapter[];
|
|
955
|
+
/** The same adapters, in the same order, each paired with its descriptor. */
|
|
956
|
+
readonly channels: BuiltChannel[];
|
|
739
957
|
readonly rejected: ChannelRejection[];
|
|
740
958
|
}
|
|
741
959
|
/**
|
|
@@ -785,6 +1003,8 @@ interface DeliveryRequest extends DeliveryTarget {
|
|
|
785
1003
|
readonly text: string;
|
|
786
1004
|
readonly format?: "plain" | "markdown" | "html";
|
|
787
1005
|
readonly replyTo?: string;
|
|
1006
|
+
/** Images to send with the text; an empty list is left out (B-674). */
|
|
1007
|
+
readonly attachments?: ReadonlyArray<OutboundAttachment>;
|
|
788
1008
|
}
|
|
789
1009
|
/**
|
|
790
1010
|
* Routes outbound requests to the correct adapter.
|
|
@@ -793,6 +1013,8 @@ interface DeliveryRequest extends DeliveryTarget {
|
|
|
793
1013
|
* - `register` is last-writer-wins by platform.
|
|
794
1014
|
* - `send` with unknown platform returns `{ ok: false, code: "no_adapter" }`.
|
|
795
1015
|
* - `send` never throws on platform errors (delegates to adapter's SendResult).
|
|
1016
|
+
* - `send` with attachments refuses with `attachments_unsupported`, calling no `sendMessage`, when
|
|
1017
|
+
* the adapter does not declare `supportsAttachments`.
|
|
796
1018
|
*
|
|
797
1019
|
* @public
|
|
798
1020
|
*/
|
|
@@ -949,6 +1171,8 @@ interface GatewayContext {
|
|
|
949
1171
|
/** Send a reply to the originating channel (auto-routed by `event.platform`). */
|
|
950
1172
|
reply(text: string, opts?: {
|
|
951
1173
|
format?: "plain" | "markdown" | "html";
|
|
1174
|
+
/** Images to send with the text; an empty list is left out (B-674). */
|
|
1175
|
+
attachments?: ReadonlyArray<OutboundAttachment>;
|
|
952
1176
|
}): Promise<SendResult>;
|
|
953
1177
|
/** The triggering event. */
|
|
954
1178
|
readonly event: MessageEvent;
|
|
@@ -1010,7 +1234,6 @@ interface StartResult {
|
|
|
1010
1234
|
*/
|
|
1011
1235
|
declare class GatewayRunner {
|
|
1012
1236
|
private readonly opts;
|
|
1013
|
-
private readonly adaptersByPlatform;
|
|
1014
1237
|
private readonly hookExecutor;
|
|
1015
1238
|
private readonly inflight;
|
|
1016
1239
|
private readonly unsubs;
|
|
@@ -1280,6 +1503,14 @@ interface ChunkTextOptions {
|
|
|
1280
1503
|
* (WhatsApp/Teams). Also applied to the single-chunk fast path. Default `false`.
|
|
1281
1504
|
*/
|
|
1282
1505
|
readonly trimParts?: boolean;
|
|
1506
|
+
/**
|
|
1507
|
+
* When true, a cut that would fall inside a Markdown table row (a line whose first non-blank
|
|
1508
|
+
* character is `|`) moves back to the start of that row, provided the row fits in the window and
|
|
1509
|
+
* does not open the chunk; the row then opens the next chunk whole and byte-identical (B-556).
|
|
1510
|
+
* A row longer than the window is cut by length as before. Text with no table row splits exactly
|
|
1511
|
+
* as without the option. Default: `false`.
|
|
1512
|
+
*/
|
|
1513
|
+
readonly keepTableRows?: boolean;
|
|
1283
1514
|
}
|
|
1284
1515
|
/**
|
|
1285
1516
|
* Split `text` into chunks no longer than the configured window, preferring
|
|
@@ -1317,6 +1548,72 @@ declare function chunkByGrapheme(text: string, options: ChunkByGraphemeOptions):
|
|
|
1317
1548
|
*/
|
|
1318
1549
|
declare function toDialect(text: string, platform: string): string;
|
|
1319
1550
|
|
|
1551
|
+
/**
|
|
1552
|
+
* Fenced code block scanner (B-518).
|
|
1553
|
+
*
|
|
1554
|
+
* Reads the fences of CommonMark § 4.5: a line of at most three blanks, then three or more
|
|
1555
|
+
* backticks or tildes (an info string after a backtick run holds no backtick), closed by a line of
|
|
1556
|
+
* the same character, at least as many, and nothing after them but blanks. A fence never closed runs
|
|
1557
|
+
* to the end of the text. Fences inside a list item or block quote (indented four or more, or behind
|
|
1558
|
+
* a `>`) are not read.
|
|
1559
|
+
*
|
|
1560
|
+
* @public
|
|
1561
|
+
*/
|
|
1562
|
+
/** One fenced code block, as offsets into the scanned text. */
|
|
1563
|
+
interface FenceRegion {
|
|
1564
|
+
/** Offset of the first character of the opening line. */
|
|
1565
|
+
readonly start: number;
|
|
1566
|
+
/** Offset just past the opening line, before its line ending. */
|
|
1567
|
+
readonly openerEnd: number;
|
|
1568
|
+
/** Offset of the first character after the opening line's line ending (the first code line). */
|
|
1569
|
+
readonly contentStart: number;
|
|
1570
|
+
/** Offset just past the last character of the closing line (its line ending excluded), or the text length when never closed. */
|
|
1571
|
+
readonly end: number;
|
|
1572
|
+
/** The opening line, byte for byte. */
|
|
1573
|
+
readonly opener: string;
|
|
1574
|
+
/** The marker run that closes the block: the opening run, without its indent. */
|
|
1575
|
+
readonly closer: string;
|
|
1576
|
+
/** False when the text ends before a closing line. */
|
|
1577
|
+
readonly closed: boolean;
|
|
1578
|
+
}
|
|
1579
|
+
/** Every fenced region of `text`, in order. */
|
|
1580
|
+
declare function scanFences(text: string): readonly FenceRegion[];
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* A bounded set of ids, oldest evicted first, so a long-running process remembers what it delivered
|
|
1584
|
+
* without growing for ever (NFR-003).
|
|
1585
|
+
*/
|
|
1586
|
+
/**
|
|
1587
|
+
* The ids an adapter has already delivered, at most `limit` of them.
|
|
1588
|
+
*/
|
|
1589
|
+
declare class SeenIds {
|
|
1590
|
+
private readonly limit;
|
|
1591
|
+
private readonly ids;
|
|
1592
|
+
/** @param limit the most ids held at once; the oldest is forgotten when one more arrives */
|
|
1593
|
+
constructor(limit?: number);
|
|
1594
|
+
/**
|
|
1595
|
+
* Record `id`.
|
|
1596
|
+
*
|
|
1597
|
+
* @returns `true` when the id was new, `false` when it was already held
|
|
1598
|
+
*/
|
|
1599
|
+
add(id: string): boolean;
|
|
1600
|
+
/** Whether `id` is held. */
|
|
1601
|
+
has(id: string): boolean;
|
|
1602
|
+
/** How many ids are held. */
|
|
1603
|
+
get size(): number;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* Grapheme-safe splitting of long text that keeps Markdown table rows whole (B-556).
|
|
1608
|
+
*
|
|
1609
|
+
* @internal
|
|
1610
|
+
*/
|
|
1611
|
+
/**
|
|
1612
|
+
* Parts of at most `partLimit` units, cut at grapheme boundaries and before straddled rows.
|
|
1613
|
+
* Shared by the SMS and LINE splitters (text no longer than a part is theirs to handle).
|
|
1614
|
+
*/
|
|
1615
|
+
declare function splitKeepingRows(text: string, partLimit: number): string[];
|
|
1616
|
+
|
|
1320
1617
|
/**
|
|
1321
1618
|
* The half of an Express webhook server that is the same for every platform.
|
|
1322
1619
|
*
|
|
@@ -1423,4 +1720,4 @@ declare function listenerLifecycle(opts: {
|
|
|
1423
1720
|
stop(): Promise<void>;
|
|
1424
1721
|
};
|
|
1425
1722
|
|
|
1426
|
-
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChunkByGraphemeOptions, type ChunkTextOptions, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type NextcloudTalkMessageEvent, type OnErrorContext, type OutboundMessage, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type RawBodyCaptureOptions, type RawBodyRequest, type SMSMessageEvent, type SendResult, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type StartResult, type TeamsMessageEvent, type TelegramMessageEvent, type UncoveredShape, type WebhookRequest, type WhatsAppMessageEvent, channelRendering, chunkByGrapheme, chunkText, createChannels, defaultStrategy, listenerLifecycle, loadPeer, maskShapes, rawBodyCapture, redactSecrets, toDialect };
|
|
1723
|
+
export { type AgentIdStrategy, type BaseMessageEvent, BasePlatformAdapter, type BuiltChannel, type BuzzMessageEvent, CREDENTIAL_SHAPES, type ChannelConfigField, type ChannelDescriptor, type ChannelEntry, type ChannelRejection, type ChannelRendering, type ChannelWebhook, type ChunkByGraphemeOptions, type ChunkTextOptions, type ClickClackMessageEvent, type ConnectFailure, type CoveredShape, type CreateChannelsResult, type DeliveryRequest, DeliveryRouter, type DeliveryTarget, type DiscordMessageEvent, type EmailMessageEvent, type FeishuLarkMessageEvent, type FenceRegion, GatewayConfigurationError, type GatewayConfigurationErrorOptions, type GatewayContext, type GatewayHandler, type GatewayHook, GatewayLifecycleError, type GatewayLifecycleErrorOptions, GatewayRunner, type GatewayRunnerOptions, type GoogleChatMessageEvent, type HookDecision, HookExecutor, type HookName, type IMessageMessageEvent, type InboundAudio, type IngestResult, type IrcMessageEvent, type LineMessageEvent, type ListenableApp, type ListenerLike, type MatrixMessageEvent, type MattermostMessageEvent, type MessageEvent, type NextcloudTalkMessageEvent, type NostrMessageEvent, type OnErrorContext, type OutboundAttachment, type OutboundMessage, type PlatformEventRegistry, type PlatformName, type PostOutboundContext, type PreInboundContext, type RawBodyCaptureOptions, type RawBodyRequest, type SMSMessageEvent, SeenIds, type SendResult, SessionRouter, type SignalMessageEvent, type SlackMessageEvent, type StartResult, type SynologyChatMessageEvent, type TeamsMessageEvent, type TelegramMessageEvent, type TlonUrbitMessageEvent, type TwitchMessageEvent, type UncoveredShape, type WebhookRequest, type WhatsAppMessageEvent, type ZaloPersonalMessageEvent, channelRendering, chunkByGrapheme, chunkText, createChannels, defaultStrategy, listenerLifecycle, loadPeer, maskShapes, rawBodyCapture, redactSecrets, scanFences, splitKeepingRows, toDialect };
|