@relaymessenger/chat-sdk-adapter 0.2.1 → 0.3.0-staging.1
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/LICENSE +3 -3
- package/README.md +218 -98
- package/dist/adapter.d.ts +156 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +723 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client.d.ts +84 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +266 -0
- package/dist/client.js.map +1 -0
- package/dist/content.d.ts +11 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +172 -0
- package/dist/content.js.map +1 -0
- package/dist/credentials.d.ts +13 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +28 -0
- package/dist/credentials.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/reactions.d.ts +15 -0
- package/dist/reactions.d.ts.map +1 -0
- package/dist/reactions.js +58 -0
- package/dist/reactions.js.map +1 -0
- package/dist/signature.d.ts +22 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +98 -0
- package/dist/signature.js.map +1 -0
- package/dist/thread-id.d.ts +8 -0
- package/dist/thread-id.d.ts.map +1 -0
- package/dist/thread-id.js +27 -0
- package/dist/thread-id.js.map +1 -0
- package/dist/turn.d.ts +16 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +22 -0
- package/dist/turn.js.map +1 -0
- package/dist/types.d.ts +193 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +27 -0
- package/dist/types.js.map +1 -0
- package/dist/webhook.d.ts +9 -0
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +115 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +52 -32
- package/dist/src/adapter.d.ts +0 -125
- package/dist/src/adapter.js +0 -724
- package/dist/src/chunk.d.ts +0 -25
- package/dist/src/chunk.js +0 -108
- package/dist/src/client.d.ts +0 -112
- package/dist/src/client.js +0 -180
- package/dist/src/format.d.ts +0 -43
- package/dist/src/format.js +0 -266
- package/dist/src/idempotency.d.ts +0 -50
- package/dist/src/idempotency.js +0 -75
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.js +0 -8
- package/dist/src/reactions.d.ts +0 -12
- package/dist/src/reactions.js +0 -98
- package/dist/src/signature.d.ts +0 -46
- package/dist/src/signature.js +0 -95
- package/dist/src/threadId.d.ts +0 -12
- package/dist/src/threadId.js +0 -28
- package/dist/src/turn.d.ts +0 -38
- package/dist/src/turn.js +0 -15
- package/dist/src/types.d.ts +0 -177
- package/dist/src/types.js +0 -7
package/LICENSE
CHANGED
|
@@ -5,9 +5,9 @@ Copyright (c) 2026 Companion Inc.
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
7
7
|
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
11
|
|
|
12
12
|
The above copyright notice and this permission notice shall be included in all
|
|
13
13
|
copies or substantial portions of the Software.
|
package/README.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# @relaymessenger/chat-sdk-adapter
|
|
2
2
|
|
|
3
|
-
Relay adapter for
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Vendor-official Relay adapter for
|
|
4
|
+
[Vercel Chat SDK](https://chat-sdk.dev), targeting `chat@4.39.0`.
|
|
5
|
+
|
|
6
|
+
Source is maintained in
|
|
7
|
+
[`RelayMessenger/Relay-SDK`](https://github.com/RelayMessenger/Relay-SDK/tree/main/packages/chat-sdk-adapter)
|
|
8
|
+
under `packages/chat-sdk-adapter`.
|
|
9
|
+
|
|
10
|
+
Relay Chats map one-to-one to Chat SDK threads. Provider thread IDs are stable
|
|
11
|
+
`relay:<chat UUID>` values; provider message IDs are bare Relay Message UUIDs.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install chat@4.39.0 @chat-adapter/state-memory@4.39.0 \
|
|
17
|
+
@relaymessenger/chat-sdk-adapter
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Minimal use
|
|
8
21
|
|
|
9
22
|
```ts
|
|
10
23
|
import { createMemoryState } from "@chat-adapter/state-memory";
|
|
@@ -12,11 +25,11 @@ import { createRelayAdapter } from "@relaymessenger/chat-sdk-adapter";
|
|
|
12
25
|
import { Chat } from "chat";
|
|
13
26
|
|
|
14
27
|
const chat = new Chat({
|
|
15
|
-
userName: "My Agent",
|
|
28
|
+
userName: "My Relay Agent",
|
|
16
29
|
adapters: {
|
|
17
30
|
relay: createRelayAdapter({
|
|
18
|
-
token: process.env.RELAY_AGENT_TOKEN
|
|
19
|
-
webhookSecret: process.env.RELAY_WEBHOOK_SECRET
|
|
31
|
+
token: process.env.RELAY_AGENT_TOKEN,
|
|
32
|
+
webhookSecret: process.env.RELAY_WEBHOOK_SECRET,
|
|
20
33
|
}),
|
|
21
34
|
},
|
|
22
35
|
state: createMemoryState(),
|
|
@@ -24,98 +37,205 @@ const chat = new Chat({
|
|
|
24
37
|
|
|
25
38
|
chat.onNewMention(async (thread, message) => {
|
|
26
39
|
await thread.subscribe();
|
|
27
|
-
await thread.post(
|
|
40
|
+
await thread.post(`You said: ${message.text}`);
|
|
28
41
|
});
|
|
29
42
|
|
|
30
|
-
// Mount
|
|
43
|
+
// Mount this on the Relay webhook URL.
|
|
31
44
|
export const POST = (request: Request) => chat.webhooks.relay(request);
|
|
32
45
|
```
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
##
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
47
|
+
An executable Node HTTP example is in [`examples/server.mjs`](examples/server.mjs).
|
|
48
|
+
|
|
49
|
+
## Factory API
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
type RelayCredential =
|
|
53
|
+
| string
|
|
54
|
+
| (() => string | Promise<string>);
|
|
55
|
+
|
|
56
|
+
interface RelayAdapterOptions {
|
|
57
|
+
token?: RelayCredential; // RELAY_AGENT_TOKEN fallback
|
|
58
|
+
webhookSecret?: RelayCredential; // RELAY_WEBHOOK_SECRET fallback
|
|
59
|
+
typing?: boolean; // default true
|
|
60
|
+
userName?: string; // default "Relay Agent"
|
|
61
|
+
agentId?: string; // this agent's Relay Contact UUID
|
|
62
|
+
baseUrl?: string; // default https://api.relayapp.im
|
|
63
|
+
fetch?: typeof fetch;
|
|
64
|
+
client?: RelayClient;
|
|
65
|
+
signatureToleranceSeconds?: number; // default 300
|
|
66
|
+
idempotencyKeyResolver?: (context: {
|
|
67
|
+
chatId: string;
|
|
68
|
+
threadId: string;
|
|
69
|
+
parts: readonly RelayOutgoingPart[];
|
|
70
|
+
replyToMessageId?: string;
|
|
71
|
+
}) => string | Promise<string>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
createRelayAdapter(options?: RelayAdapterOptions): RelayAdapter;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Credential functions satisfy Vercel's vendor-official non-static credential
|
|
78
|
+
requirement. The token resolver is called for every Relay API request. The
|
|
79
|
+
webhook-secret resolver is called for every webhook delivery. Values are not
|
|
80
|
+
cached.
|
|
81
|
+
|
|
82
|
+
Every send caused by an inbound webhook carries
|
|
83
|
+
`Idempotency-Key: relay-chat-sdk:<event_id>:<send ordinal>`. A redelivery starts
|
|
84
|
+
at ordinal zero again, so the same event/body replays while changed recovery
|
|
85
|
+
content reaches Relay under the same key and receives the contract's 409
|
|
86
|
+
`idempotency_conflict`. This context uses `AsyncLocalStorage` only for the
|
|
87
|
+
active turn and is never persisted.
|
|
88
|
+
|
|
89
|
+
Posts made outside an inbound webhook have no Relay `event_id`. The adapter
|
|
90
|
+
therefore requires `idempotencyKeyResolver` for those non-empty posts rather
|
|
91
|
+
than manufacturing a random key that changes on recovery. Think integrations
|
|
92
|
+
should return their stable Action/delivery identity from this resolver.
|
|
93
|
+
|
|
94
|
+
### Think runtime typing
|
|
95
|
+
|
|
96
|
+
For a runtime that owns typing timing, disable Chat SDK surface typing:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const relay = createRelayAdapter({
|
|
100
|
+
token,
|
|
101
|
+
webhookSecret,
|
|
102
|
+
typing: false,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
With `typing: false`, both `startTyping()` and `endTyping()` validate the thread
|
|
107
|
+
ID but make no Relay request. This prevents Think's pre-inference
|
|
108
|
+
`ChatThread.startTyping()` from surfacing. Other adapter instances default to
|
|
109
|
+
normal `POST`/`DELETE /v1/chats/{chatId}/typing` support.
|
|
110
|
+
|
|
111
|
+
## Locked contract
|
|
112
|
+
|
|
113
|
+
This package was rewritten against:
|
|
114
|
+
|
|
115
|
+
- Relay Server `9b4d5bb32cc749c6fd271969948c385300d404d6`
|
|
116
|
+
- OpenAPI SHA-256
|
|
117
|
+
`f62f431fc0daa48500926bf87753f81c3fdda25ab463b130ca97f2896367e0a5`
|
|
118
|
+
- Relay API `v1`
|
|
119
|
+
- Relay webhook payload version `2026-08-30`
|
|
120
|
+
- `chat@4.39.0`
|
|
121
|
+
|
|
122
|
+
The exact OpenAPI snapshot is retained under `contracts/` for reproducible
|
|
123
|
+
contract tests and is excluded from the npm package.
|
|
124
|
+
|
|
125
|
+
## Supported surface
|
|
126
|
+
|
|
127
|
+
| Chat SDK operation | Locked Relay v1 operation |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `postMessage`, `postChannelMessage` | `POST /v1/chats/{chatId}/messages` |
|
|
130
|
+
| `reply` | Same route with `message.reply_to` |
|
|
131
|
+
| `stream` | Buffered, then one canonical Message; never partial bubbles |
|
|
132
|
+
| outbound public-URL media | Message `media` part |
|
|
133
|
+
| outbound bytes/files | Explicitly allocate/upload with `@relaymessenger/sdk`, then post a stable public HTTPS URL |
|
|
134
|
+
| inbound media | Chat SDK `Attachment` with `fetchData()` |
|
|
135
|
+
| `addReaction`, `removeReaction` | `POST /v1/messages/{messageId}/reactions` |
|
|
136
|
+
| `startTyping`, `endTyping` | `POST`/`DELETE /v1/chats/{chatId}/typing` |
|
|
137
|
+
| `markAsRead` | `POST /v1/chats/{chatId}/read` |
|
|
138
|
+
| `fetchMessages({ direction: "forward" })` | `GET /v1/chats/{chatId}/messages` |
|
|
139
|
+
| `fetchMessage` | `GET /v1/messages/{messageId}` |
|
|
140
|
+
| `fetchThread`, `fetchChannelInfo` | `GET /v1/chats/{chatId}` |
|
|
141
|
+
|
|
142
|
+
### Inbound attachments
|
|
143
|
+
|
|
144
|
+
An inbound Relay media part becomes a Chat SDK `Attachment` carrying
|
|
145
|
+
`url`, `mimeType`, `name`, `size`, `type`, `width`, `height`, and a
|
|
146
|
+
`fetchData()` that resolves to the bytes as an `ArrayBuffer`. Nothing is
|
|
147
|
+
downloaded until you call it.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
for (const attachment of message.attachments) {
|
|
151
|
+
const bytes = await attachment.fetchData?.();
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**A Relay download URL expires 60 minutes after Relay minted it.** The URL is a
|
|
156
|
+
sealed, unauthenticated download capability, so `fetchData()` sends no Agent
|
|
157
|
+
Token; after that window the download fails with `RelayApiError` HTTP 404.
|
|
158
|
+
|
|
159
|
+
That expiry is not a limit on queued work. `Message.toJSON()` drops
|
|
160
|
+
`fetchData`, so queue and debounce strategies call `rehydrateAttachment()` to
|
|
161
|
+
rebuild it — and the rebuilt closure calls `GET /v1/attachments/{attachmentId}`
|
|
162
|
+
first, which mints a new 60-minute download link on every request. A Message may
|
|
163
|
+
sit in a queue for as long as you like and still read its bytes. The serialized
|
|
164
|
+
URL is kept in `fetchMetadata` only as the fallback for an attachment whose
|
|
165
|
+
metadata predates this behavior.
|
|
166
|
+
|
|
167
|
+
`GET /v1/attachments/{attachmentId}` authorizes any Chat participant who could
|
|
168
|
+
read the Message, so an agent reads the attachments of messages sent to it
|
|
169
|
+
without owning them.
|
|
170
|
+
|
|
171
|
+
Relay text parts are plain text and are limited to 10,000 UTF-16 code units.
|
|
172
|
+
Long Chat SDK text is split without breaking surrogate pairs. A Relay Message
|
|
173
|
+
is limited to 100 parts. A public HTTPS attachment URL is sent directly.
|
|
174
|
+
Automatic byte/file uploads are rejected because a fresh Attachment allocation
|
|
175
|
+
would change the Message body after an ambiguous send. Allocate and upload with
|
|
176
|
+
`@relaymessenger/sdk`, retain that prepared identity durably, then give this
|
|
177
|
+
adapter the stable HTTPS URL.
|
|
178
|
+
|
|
179
|
+
Think's `thread.post(callback.stream())` path is safe when the stream is empty:
|
|
180
|
+
the adapter returns a local no-op result so Chat SDK does not enter its
|
|
181
|
+
post-then-edit fallback. Non-empty streams are fully buffered and committed in
|
|
182
|
+
one request. Empty string posts are the same no-op. No partial or placeholder
|
|
183
|
+
Message reaches Relay.
|
|
184
|
+
|
|
185
|
+
## Explicitly unsupported
|
|
186
|
+
|
|
187
|
+
The adapter throws Chat SDK `NotImplementedError` rather than calling an
|
|
188
|
+
undocumented route for:
|
|
189
|
+
|
|
190
|
+
- message editing and deletion;
|
|
191
|
+
- editable drafts or partial streaming bubbles;
|
|
192
|
+
- open-only direct messages;
|
|
193
|
+
- public Contact lookup;
|
|
194
|
+
- backward history pagination.
|
|
195
|
+
|
|
196
|
+
Relay's locked chat-history cursor advances oldest-to-newest. It cannot satisfy
|
|
197
|
+
Chat SDK's backward-cursor semantics, so callers must request
|
|
198
|
+
`direction: "forward"` explicitly.
|
|
199
|
+
|
|
200
|
+
Cards have no Relay interaction surface. Their fallback text is sent; a card
|
|
201
|
+
without text is rejected.
|
|
202
|
+
|
|
203
|
+
## Webhooks
|
|
204
|
+
|
|
205
|
+
The adapter internally verifies current signed Standard Webhooks over the exact
|
|
206
|
+
raw body:
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
HMAC-SHA256(secret, "${webhook-id}.${webhook-timestamp}.${rawBody}")
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Every valid current event type is acknowledged. `message.received` is
|
|
213
|
+
dispatched to Chat SDK message handlers, and non-self `reaction.added` /
|
|
214
|
+
`reaction.removed` events are dispatched to reaction handlers. Receipt,
|
|
215
|
+
participant, Chat metadata, typing, and Contact events have no matching Chat
|
|
216
|
+
SDK inbound hook and are acknowledged without fabricated behavior.
|
|
217
|
+
|
|
218
|
+
Direct Chats route through Chat SDK's direct-message path and do not need an
|
|
219
|
+
`isMention` flag. In a group, `isMention` is true only when a canonical text
|
|
220
|
+
part's `mention` equals the receiving Chat `owner_handle`; when `agentId` is
|
|
221
|
+
configured, the owner UUID must match it.
|
|
222
|
+
|
|
223
|
+
This package adds no persistence and no adapter-owned delivery-idempotency
|
|
224
|
+
store. Think Actions remain the delivery-idempotency owner outside webhook
|
|
225
|
+
turns. `RelayClient.sendMessage()` requires an explicit idempotency key.
|
|
226
|
+
|
|
227
|
+
## Development
|
|
228
|
+
|
|
229
|
+
```sh
|
|
230
|
+
npm ci
|
|
231
|
+
npm run check
|
|
232
|
+
npm run build
|
|
233
|
+
npm run test:unit
|
|
234
|
+
npm run test:workerd
|
|
235
|
+
npm run test:installed
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`@chat-adapter/shared@4.39.0` provides shared adapter utilities and errors. That
|
|
239
|
+
published package has no `/tests` export; Vercel's published contract runner is
|
|
240
|
+
`@chat-adapter/tests@4.39.0`, which this package uses alongside
|
|
241
|
+
`@chat-adapter/shared`.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Message, type Adapter, type AdapterPostableMessage, type Attachment, type ChatInstance, type EmojiValue, type FetchOptions, type FetchResult, type FormattedContent, type RawMessage, type StreamChunk, type ThreadInfo, type UserInfo, type WebhookOptions } from "chat";
|
|
2
|
+
import { RelayClient } from "./client.js";
|
|
3
|
+
import type { RelayClientOptions } from "./client.js";
|
|
4
|
+
import { type RelayCredential } from "./credentials.js";
|
|
5
|
+
import type { RelayRawMessage, RelayThreadId } from "./types.js";
|
|
6
|
+
export declare const RELAY_ADAPTER_NAME = "relay";
|
|
7
|
+
export interface RelayIdempotencyKeyContext {
|
|
8
|
+
chatId: string;
|
|
9
|
+
parts: ReadonlyArray<import("./types.js").RelayOutgoingPart>;
|
|
10
|
+
replyToMessageId?: string;
|
|
11
|
+
threadId: string;
|
|
12
|
+
}
|
|
13
|
+
export type RelayIdempotencyKeyResolver = (context: RelayIdempotencyKeyContext) => string | Promise<string>;
|
|
14
|
+
export interface RelayAdapterOptions extends Omit<RelayClientOptions, "token"> {
|
|
15
|
+
/**
|
|
16
|
+
* Relay Agent Token or per-call resolver.
|
|
17
|
+
* Defaults to `RELAY_AGENT_TOKEN`.
|
|
18
|
+
*/
|
|
19
|
+
token?: RelayCredential;
|
|
20
|
+
/**
|
|
21
|
+
* Standard Webhooks signing secret or per-delivery resolver.
|
|
22
|
+
* Defaults to `RELAY_WEBHOOK_SECRET`.
|
|
23
|
+
*/
|
|
24
|
+
webhookSecret?: RelayCredential;
|
|
25
|
+
/**
|
|
26
|
+
* Disable Chat SDK surface typing for runtimes that own typing UX.
|
|
27
|
+
* Defaults to true.
|
|
28
|
+
*/
|
|
29
|
+
typing?: boolean;
|
|
30
|
+
/** Display name shown to Chat SDK handlers. */
|
|
31
|
+
userName?: string;
|
|
32
|
+
/** This Relay agent Contact UUID, when known. */
|
|
33
|
+
agentId?: string;
|
|
34
|
+
/** Standard Webhooks timestamp tolerance in seconds. */
|
|
35
|
+
signatureToleranceSeconds?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Stable key source for posts made outside an inbound webhook turn.
|
|
38
|
+
* Inbound turns always derive keys from event_id plus send ordinal.
|
|
39
|
+
*/
|
|
40
|
+
idempotencyKeyResolver?: RelayIdempotencyKeyResolver;
|
|
41
|
+
/** Controlled client injection for tests and custom transports. */
|
|
42
|
+
client?: RelayClient;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Relay adapter for `chat@4.39.0`, limited to the locked public v1 contract.
|
|
46
|
+
*/
|
|
47
|
+
export declare class RelayAdapter implements Adapter<RelayThreadId, RelayRawMessage> {
|
|
48
|
+
readonly name = "relay";
|
|
49
|
+
readonly userName: string;
|
|
50
|
+
readonly botUserId?: string;
|
|
51
|
+
readonly lockScope: "thread";
|
|
52
|
+
readonly persistThreadHistory = false;
|
|
53
|
+
readonly typing: boolean;
|
|
54
|
+
readonly client: RelayClient;
|
|
55
|
+
private readonly signatureToleranceSeconds?;
|
|
56
|
+
private readonly webhookSecret;
|
|
57
|
+
private readonly idempotencyKeyResolver;
|
|
58
|
+
private readonly turns;
|
|
59
|
+
/**
|
|
60
|
+
* Request-scoped Chat kind hints. Entries exist only while an inbound
|
|
61
|
+
* dispatch is active; this is not persistence or a delivery-idempotency
|
|
62
|
+
* store.
|
|
63
|
+
*/
|
|
64
|
+
private readonly activeChatKinds;
|
|
65
|
+
private chat?;
|
|
66
|
+
constructor(options?: RelayAdapterOptions);
|
|
67
|
+
initialize(chat: ChatInstance): Promise<void>;
|
|
68
|
+
encodeThreadId(data: RelayThreadId): string;
|
|
69
|
+
decodeThreadId(threadId: string): RelayThreadId;
|
|
70
|
+
channelIdFromThreadId(threadId: string): string;
|
|
71
|
+
renderFormatted(content: FormattedContent): string;
|
|
72
|
+
/**
|
|
73
|
+
* Build the Chat SDK `fetchData` closure for one Relay media part.
|
|
74
|
+
*
|
|
75
|
+
* The download runs through this adapter's own Relay client, so a consumer
|
|
76
|
+
* supplied `fetch` (Workers, a proxy, a test double) serves attachment bytes
|
|
77
|
+
* exactly as it serves every other Relay call.
|
|
78
|
+
*/
|
|
79
|
+
private attachmentData;
|
|
80
|
+
/**
|
|
81
|
+
* Mint a replacement download URL for an attachment id.
|
|
82
|
+
*
|
|
83
|
+
* Returns `undefined` when the call cannot produce one and the caller still
|
|
84
|
+
* holds a fallback URL; rethrows when there is nothing to fall back to, so a
|
|
85
|
+
* genuine authorization or not-found failure is never swallowed.
|
|
86
|
+
*/
|
|
87
|
+
private freshDownloadUrl;
|
|
88
|
+
/**
|
|
89
|
+
* Build the `fetchData` closure for an attachment that survived a queue.
|
|
90
|
+
*
|
|
91
|
+
* The stored URL may already have expired, so the id is tried first: Relay
|
|
92
|
+
* mints a new download link on every `GET /v1/attachments/{attachmentId}`.
|
|
93
|
+
* The serialized URL is the fallback for the one case the id cannot cover —
|
|
94
|
+
* an attachment whose `fetchMetadata` predates this adapter version.
|
|
95
|
+
*/
|
|
96
|
+
private rehydratedAttachmentData;
|
|
97
|
+
/**
|
|
98
|
+
* Rebuild `fetchData` on an attachment that survived serialization.
|
|
99
|
+
*
|
|
100
|
+
* `Message.toJSON()` drops `data` and `fetchData`, so Chat SDK calls this
|
|
101
|
+
* when a queue or debounce strategy rehydrates a Message. A Relay download
|
|
102
|
+
* URL expires 60 minutes after Relay minted it, and a queue can hold a
|
|
103
|
+
* Message for longer, so this re-mints from `fetchMetadata.attachmentId` and
|
|
104
|
+
* falls back to the stored URL only when the id call cannot serve one.
|
|
105
|
+
*/
|
|
106
|
+
rehydrateAttachment(attachment: Attachment): Attachment;
|
|
107
|
+
parseMessage(raw: RelayRawMessage): Message<RelayRawMessage>;
|
|
108
|
+
private unsupported;
|
|
109
|
+
private send;
|
|
110
|
+
private sendInTurn;
|
|
111
|
+
private resolveExternalIdempotencyKey;
|
|
112
|
+
private noopResult;
|
|
113
|
+
private isMentioned;
|
|
114
|
+
private enterChatKind;
|
|
115
|
+
/**
|
|
116
|
+
* Chat SDK asks synchronously while dispatching. Relay's stable thread ID
|
|
117
|
+
* intentionally contains only the Chat UUID, so the direct/group hint is
|
|
118
|
+
* scoped to the active webhook dispatch and never persisted.
|
|
119
|
+
*/
|
|
120
|
+
isDM(threadId: string): boolean;
|
|
121
|
+
postMessage(threadId: string, message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
122
|
+
postChannelMessage(channelId: string, message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
123
|
+
reply(threadId: string, messageId: string, message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
124
|
+
editMessage(threadId: string, messageId: string, _message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
125
|
+
deleteMessage(threadId: string, messageId: string): Promise<void>;
|
|
126
|
+
addReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
127
|
+
removeReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
128
|
+
startTyping(threadId: string): Promise<void>;
|
|
129
|
+
endTyping(threadId: string): Promise<void>;
|
|
130
|
+
markAsRead(threadId: string, messageId: string): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Relay's public chat cursor advances oldest-to-newest. Chat SDK's backward
|
|
133
|
+
* cursor contract cannot be represented, so only explicit forward reads are
|
|
134
|
+
* supported rather than faking backward pagination.
|
|
135
|
+
*/
|
|
136
|
+
fetchMessages(threadId: string, options?: FetchOptions): Promise<FetchResult<RelayRawMessage>>;
|
|
137
|
+
fetchChannelMessages(channelId: string, options?: FetchOptions): Promise<FetchResult<RelayRawMessage>>;
|
|
138
|
+
fetchMessage(threadId: string, messageId: string): Promise<Message<RelayRawMessage> | null>;
|
|
139
|
+
fetchThread(threadId: string): Promise<ThreadInfo>;
|
|
140
|
+
fetchChannelInfo(channelId: string): Promise<{
|
|
141
|
+
channelVisibility: import("chat").ChannelVisibility | undefined;
|
|
142
|
+
id: string;
|
|
143
|
+
isDM: boolean | undefined;
|
|
144
|
+
metadata: Record<string, unknown>;
|
|
145
|
+
name?: string | undefined;
|
|
146
|
+
}>;
|
|
147
|
+
getChannelVisibility(): "private";
|
|
148
|
+
getUser(_userId: string): Promise<UserInfo | null>;
|
|
149
|
+
openDM(_userId: string): Promise<string>;
|
|
150
|
+
stream(threadId: string, stream: AsyncIterable<string | StreamChunk>): Promise<RawMessage<RelayRawMessage> | null>;
|
|
151
|
+
handleWebhook(request: Request, options?: WebhookOptions): Promise<Response>;
|
|
152
|
+
private initializedChat;
|
|
153
|
+
private dispatch;
|
|
154
|
+
}
|
|
155
|
+
export declare function createRelayAdapter(options?: RelayAdapterOptions): RelayAdapter;
|
|
156
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAMP,KAAK,OAAO,EACZ,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAErB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,cAAc,EACpB,MAAM,MAAM,CAAC;AACd,OAAO,EAAiB,WAAW,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,kBAAkB,CAAC;AAoB1B,OAAO,KAAK,EAIV,eAAe,EAEf,aAAa,EAGd,MAAM,YAAY,CAAC;AAcpB,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,aAAa,CAAC,OAAO,YAAY,EAAE,iBAAiB,CAAC,CAAC;IAC7D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,2BAA2B,GAAG,CACxC,OAAO,EAAE,0BAA0B,KAChC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9B,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACzC;;;OAGG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;;OAGG;IAC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