@relaymessenger/chat-sdk-adapter 0.2.1 → 0.3.0-staging.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/LICENSE +3 -3
- package/README.md +185 -98
- package/dist/adapter.d.ts +121 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +643 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client.d.ts +64 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +230 -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 +177 -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 +51 -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/package.json
CHANGED
|
@@ -1,59 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relaymessenger/chat-sdk-adapter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Relay adapter for
|
|
5
|
-
"homepage": "https://docs.relayapp.im/integrations/chat-sdk",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/relaymessenger/Relay-SDK/issues"
|
|
8
|
-
},
|
|
9
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.3.0-staging.0",
|
|
4
|
+
"description": "Vendor-official Relay adapter for Vercel Chat SDK.",
|
|
10
5
|
"keywords": [
|
|
11
6
|
"relay",
|
|
12
7
|
"chat-sdk",
|
|
13
8
|
"adapter",
|
|
14
9
|
"messaging",
|
|
15
|
-
"agent",
|
|
16
10
|
"webhook"
|
|
17
11
|
],
|
|
18
|
-
"
|
|
19
|
-
|
|
12
|
+
"homepage": "https://docs.relayapp.im/integrations/chat-sdk",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/RelayMessenger/Relay-Chat-SDK/issues"
|
|
20
15
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/RelayMessenger/Relay-Chat-SDK.git"
|
|
23
19
|
},
|
|
20
|
+
"license": "MIT",
|
|
24
21
|
"type": "module",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
29
|
-
"types": "./dist/
|
|
30
|
-
"
|
|
31
|
-
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
32
35
|
},
|
|
33
36
|
"files": [
|
|
37
|
+
"dist/",
|
|
34
38
|
"README.md",
|
|
35
|
-
"LICENSE"
|
|
36
|
-
"dist/**/*.js",
|
|
37
|
-
"dist/**/*.d.ts"
|
|
39
|
+
"LICENSE"
|
|
38
40
|
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org/",
|
|
44
|
+
"tag": "staging",
|
|
45
|
+
"provenance": true
|
|
46
|
+
},
|
|
39
47
|
"scripts": {
|
|
40
48
|
"build": "tsc -p tsconfig.build.json",
|
|
41
49
|
"check": "tsc --noEmit",
|
|
42
|
-
"test": "
|
|
43
|
-
"
|
|
50
|
+
"test": "npm run test:unit && npm run test:workerd",
|
|
51
|
+
"test:unit": "vitest run --config vitest.config.ts",
|
|
52
|
+
"test:workerd": "vitest run --config vitest.workerd.config.ts",
|
|
53
|
+
"test:installed": "node scripts/test-installed-package.mjs",
|
|
54
|
+
"test:all": "npm run check && npm run build && npm run test && npm run test:installed",
|
|
55
|
+
"example:check": "RELAY_EXAMPLE_CHECK=1 node examples/server.mjs",
|
|
56
|
+
"prepack": "npm run check && npm run test && npm run build",
|
|
57
|
+
"wrangler:types": "wrangler types",
|
|
58
|
+
"wrangler:types:check": "wrangler types --check"
|
|
44
59
|
},
|
|
45
60
|
"peerDependencies": {
|
|
46
|
-
"chat": "^4.
|
|
61
|
+
"chat": "^4.39.0"
|
|
47
62
|
},
|
|
48
|
-
"
|
|
49
|
-
"@
|
|
50
|
-
"chat": "^4.38.1",
|
|
51
|
-
"typescript": "^7.0.2",
|
|
52
|
-
"vitest": "^4.1.10"
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@chat-adapter/shared": "4.39.0"
|
|
53
65
|
},
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@chat-adapter/state-memory": "4.39.0",
|
|
68
|
+
"@chat-adapter/tests": "4.39.0",
|
|
69
|
+
"@cloudflare/vitest-plugin": "1.1.2",
|
|
70
|
+
"@types/node": "26.4.0",
|
|
71
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
72
|
+
"chat": "4.39.0",
|
|
73
|
+
"typescript": "7.0.2",
|
|
74
|
+
"vitest": "4.1.11",
|
|
75
|
+
"wrangler": "4.127.1",
|
|
76
|
+
"yaml": "2.9.0"
|
|
58
77
|
}
|
|
59
78
|
}
|
package/dist/src/adapter.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { Message } from "chat";
|
|
2
|
-
import type { Adapter, AdapterPostableMessage, ChatInstance, EmojiValue, FetchOptions, FetchResult, FormattedContent, RawMessage, StreamChunk, ThreadInfo, UserInfo, WebhookOptions } from "chat";
|
|
3
|
-
import { RelayClient } from "./client.js";
|
|
4
|
-
import type { RelayClientOptions } from "./client.js";
|
|
5
|
-
import type { RelayMessage, RelayRawMessage, RelayThreadId } from "./types.js";
|
|
6
|
-
export declare const RELAY_ADAPTER_NAME = "relay";
|
|
7
|
-
export interface RelayAdapterOptions extends Omit<RelayClientOptions, "token"> {
|
|
8
|
-
/** Agent Token. Defaults to `RELAY_AGENT_TOKEN`. */
|
|
9
|
-
token?: string;
|
|
10
|
-
/** Webhook signing secret. Defaults to `RELAY_WEBHOOK_SECRET`. */
|
|
11
|
-
webhookSecret?: string;
|
|
12
|
-
/** Display name for the agent. Defaults to `Relay Agent`. */
|
|
13
|
-
userName?: string;
|
|
14
|
-
/** This agent's `agt_` id, when the caller knows it. */
|
|
15
|
-
agentId?: string;
|
|
16
|
-
/** Clock tolerance for signature verification, in seconds. */
|
|
17
|
-
toleranceSeconds?: number;
|
|
18
|
-
/** How many handled `event_id` values to remember. */
|
|
19
|
-
dedupeWindow?: number;
|
|
20
|
-
/** Override the client, mainly for tests. */
|
|
21
|
-
client?: RelayClient;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A group turn tried to commit a second message. Relay's invocation is single
|
|
25
|
-
* use, so there is nothing valid for the second message to cite and the server
|
|
26
|
-
* would answer 403.
|
|
27
|
-
*/
|
|
28
|
-
export declare class RelayInvocationSpentError extends Error {
|
|
29
|
-
constructor(message: string);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Relay adapter for the Vercel Chat SDK.
|
|
33
|
-
*
|
|
34
|
-
* Relay is a consumer messenger where people talk to agents as contacts, so
|
|
35
|
-
* this adapter maps the Chat SDK's thread model onto Relay conversations one
|
|
36
|
-
* to one: a Relay conversation has no enclosing channel, and a thread id is
|
|
37
|
-
* `relay:{conversation_id}`.
|
|
38
|
-
*
|
|
39
|
-
* Two Relay rules shape the surface. A streamed turn commits exactly one
|
|
40
|
-
* canonical message, so `stream` buffers and posts once rather than editing a
|
|
41
|
-
* draft bubble into place. And a group reply is scoped to the single-use
|
|
42
|
-
* invocation that produced the inbound event, so the first send of a turn
|
|
43
|
-
* carries it and a second cannot.
|
|
44
|
-
*/
|
|
45
|
-
export declare class RelayAdapter implements Adapter<RelayThreadId, RelayRawMessage> {
|
|
46
|
-
readonly name = "relay";
|
|
47
|
-
readonly userName: string;
|
|
48
|
-
readonly botUserId?: string;
|
|
49
|
-
readonly lockScope: "thread";
|
|
50
|
-
/** Relay serves history from `GET /v1/conversations/{id}/messages`. */
|
|
51
|
-
readonly persistThreadHistory = false;
|
|
52
|
-
private readonly client;
|
|
53
|
-
private readonly webhookSecret?;
|
|
54
|
-
private readonly toleranceSeconds?;
|
|
55
|
-
private readonly dedupe;
|
|
56
|
-
private chat?;
|
|
57
|
-
constructor(options?: RelayAdapterOptions);
|
|
58
|
-
initialize(chat: ChatInstance): Promise<void>;
|
|
59
|
-
encodeThreadId(platformData: RelayThreadId): string;
|
|
60
|
-
decodeThreadId(threadId: string): RelayThreadId;
|
|
61
|
-
channelIdFromThreadId(threadId: string): string;
|
|
62
|
-
renderFormatted(content: FormattedContent): string;
|
|
63
|
-
parseMessage(raw: RelayRawMessage): Message<RelayRawMessage>;
|
|
64
|
-
postMessage(threadId: string, message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
65
|
-
editMessage(threadId: string, messageId: string, message: AdapterPostableMessage): Promise<RawMessage<RelayRawMessage>>;
|
|
66
|
-
deleteMessage(threadId: string, messageId: string): Promise<void>;
|
|
67
|
-
addReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
68
|
-
removeReaction(threadId: string, messageId: string, emoji: EmojiValue | string): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Relay's typing indicator is ephemeral and carries an optional label of up
|
|
71
|
-
* to 80 characters. The invocation is peeked rather than consumed: typing is
|
|
72
|
-
* not the group reply the invocation is spent on.
|
|
73
|
-
*
|
|
74
|
-
* Failures are swallowed. Group typing without a live pending invocation is a
|
|
75
|
-
* 403 (`Relay-Server/server/src/domain/typing.ts:70-73`), which is exactly
|
|
76
|
-
* what typing after the first send of a group turn looks like. The Chat SDK
|
|
77
|
-
* treats this call as best effort and has no `stopTyping` to strand, so a
|
|
78
|
-
* hint that cannot be shown must never take the reply down with it.
|
|
79
|
-
*/
|
|
80
|
-
startTyping(threadId: string, status?: string): Promise<void>;
|
|
81
|
-
markAsRead(threadId: string, messageId: string): Promise<void>;
|
|
82
|
-
getUser(userId: string): Promise<UserInfo | null>;
|
|
83
|
-
/**
|
|
84
|
-
* Relay pages history backwards with `before_sequence` and returns newest
|
|
85
|
-
* first; the Chat SDK wants each page in chronological order. There is no
|
|
86
|
-
* forward cursor on the route, so `direction: "forward"` has nothing to call.
|
|
87
|
-
*/
|
|
88
|
-
fetchMessages(threadId: string, options?: FetchOptions): Promise<FetchResult<RelayRawMessage>>;
|
|
89
|
-
fetchThread(threadId: string): Promise<ThreadInfo>;
|
|
90
|
-
/**
|
|
91
|
-
* Relay commits one canonical message per turn and has no draft bubble to
|
|
92
|
-
* edit, so the stream is buffered and posted once. Nothing partial ever
|
|
93
|
-
* reaches a recipient, and no cleanup is needed if the stream fails midway.
|
|
94
|
-
*/
|
|
95
|
-
stream(threadId: string, textStream: AsyncIterable<string | StreamChunk>): Promise<RawMessage<RelayRawMessage> | null>;
|
|
96
|
-
/**
|
|
97
|
-
* Verify the Standard Webhooks signature over the exact raw body, refuse a
|
|
98
|
-
* replay by `event_id`, and hand the event to the Chat SDK. Relay redelivers
|
|
99
|
-
* on 5xx, so a dispatch failure must not answer 2xx.
|
|
100
|
-
*/
|
|
101
|
-
handleWebhook(request: Request, options?: WebhookOptions): Promise<Response>;
|
|
102
|
-
private dispatch;
|
|
103
|
-
private buildParts;
|
|
104
|
-
private textParts;
|
|
105
|
-
/**
|
|
106
|
-
* Relay has no card surface: interactive components were removed from the
|
|
107
|
-
* app, so buttons cannot render and a human cannot answer one in Relay. The
|
|
108
|
-
* card's words are still delivered, as text, rather than dropped.
|
|
109
|
-
*/
|
|
110
|
-
private cardToText;
|
|
111
|
-
private attachmentPart;
|
|
112
|
-
private filePart;
|
|
113
|
-
/**
|
|
114
|
-
* Send the parts in one call when they fit, and as follow-up calls when
|
|
115
|
-
* they do not. The server splits each call at ingest into one or more
|
|
116
|
-
* messages, and the one call that carries the invocation owns every message
|
|
117
|
-
* it commits. A group turn cannot overflow, and cannot POST twice: Relay's
|
|
118
|
-
* invocation is single use per call, so a second POST has nothing valid to
|
|
119
|
-
* cite and the server answers 403.
|
|
120
|
-
*/
|
|
121
|
-
private sendParts;
|
|
122
|
-
}
|
|
123
|
-
/** Build a Relay adapter for the Vercel Chat SDK. */
|
|
124
|
-
export declare function createRelayAdapter(options?: RelayAdapterOptions): RelayAdapter;
|
|
125
|
-
export type { RelayMessage };
|