@relaymessenger/chat-sdk-adapter 0.2.0 → 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 -175
- 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/dist/src/threadId.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Relay thread ids are `relay:{conversation_id}`. A Relay conversation has no
|
|
3
|
-
* enclosing channel, so the channel id is the same string. Both are written
|
|
4
|
-
* out here rather than left to the Chat SDK defaults, because the default
|
|
5
|
-
* channel derivation keeps the first two colon-separated segments and that
|
|
6
|
-
* only happens to be correct for this shape.
|
|
7
|
-
*/
|
|
8
|
-
export const RELAY_THREAD_PREFIX = "relay:";
|
|
9
|
-
export function encodeRelayThreadId(platformData) {
|
|
10
|
-
const conversationId = platformData.conversationId;
|
|
11
|
-
if (!conversationId) {
|
|
12
|
-
throw new Error("conversationId is required to encode a Relay thread id");
|
|
13
|
-
}
|
|
14
|
-
return `${RELAY_THREAD_PREFIX}${conversationId}`;
|
|
15
|
-
}
|
|
16
|
-
export function decodeRelayThreadId(threadId) {
|
|
17
|
-
if (!threadId.startsWith(RELAY_THREAD_PREFIX)) {
|
|
18
|
-
throw new Error(`not a Relay thread id: ${threadId}`);
|
|
19
|
-
}
|
|
20
|
-
const conversationId = threadId.slice(RELAY_THREAD_PREFIX.length);
|
|
21
|
-
if (!conversationId) {
|
|
22
|
-
throw new Error(`Relay thread id carries no conversation id: ${threadId}`);
|
|
23
|
-
}
|
|
24
|
-
return { conversationId };
|
|
25
|
-
}
|
|
26
|
-
export function relayChannelIdFromThreadId(threadId) {
|
|
27
|
-
return encodeRelayThreadId(decodeRelayThreadId(threadId));
|
|
28
|
-
}
|
package/dist/src/turn.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the inbound event told us about the turn now in flight. `postMessage`
|
|
3
|
-
* and `startTyping` never see the event, so the invocation id a group reply
|
|
4
|
-
* must echo, and the event id an idempotency key must be derived from, are
|
|
5
|
-
* carried here.
|
|
6
|
-
*
|
|
7
|
-
* The turn rides on the async execution context of the dispatch that created
|
|
8
|
-
* it rather than on a map keyed by conversation. A map is wrong: the Chat SDK
|
|
9
|
-
* takes its per-thread lock inside `processMessage`, well after the adapter
|
|
10
|
-
* would have written the entry, so two messages arriving together in one group
|
|
11
|
-
* let the second overwrite the first's entry and then get dropped by the lock,
|
|
12
|
-
* leaving the first turn replying with the second's invocation and key. A
|
|
13
|
-
* context store cannot be overwritten by a sibling dispatch, and it needs no
|
|
14
|
-
* cleanup, so there is nothing to grow without bound either.
|
|
15
|
-
*
|
|
16
|
-
* The Chat SDK already runs on `AsyncLocalStorage` for its own conversation
|
|
17
|
-
* context (`chat/dist/chunk-23HOOUQ5.js:130`), so this adds no runtime
|
|
18
|
-
* requirement the peer dependency did not already impose.
|
|
19
|
-
*/
|
|
20
|
-
export interface RelayTurn {
|
|
21
|
-
/** The conversation the inbound event arrived on. */
|
|
22
|
-
readonly conversationId: string;
|
|
23
|
-
readonly eventId: string;
|
|
24
|
-
/** Present only for a group event: Relay scopes a group reply to it. */
|
|
25
|
-
readonly invocationId?: string;
|
|
26
|
-
/** Set once the invocation has been spent on a committed message. */
|
|
27
|
-
invocationUsed: boolean;
|
|
28
|
-
/** Messages this turn has committed. Advances only on a successful send. */
|
|
29
|
-
sent: number;
|
|
30
|
-
}
|
|
31
|
-
/** Run one inbound dispatch with its turn bound to the async context. */
|
|
32
|
-
export declare function runInTurn<T>(turn: RelayTurn, fn: () => Promise<T>): Promise<T>;
|
|
33
|
-
/**
|
|
34
|
-
* The turn in flight, when it belongs to this conversation. A handler that
|
|
35
|
-
* posts into some other conversation is not replying to the event, so it gets
|
|
36
|
-
* nothing here and falls back to an unkeyed send.
|
|
37
|
-
*/
|
|
38
|
-
export declare function activeTurn(conversationId: string): RelayTurn | undefined;
|
package/dist/src/turn.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
const storage = new AsyncLocalStorage();
|
|
3
|
-
/** Run one inbound dispatch with its turn bound to the async context. */
|
|
4
|
-
export function runInTurn(turn, fn) {
|
|
5
|
-
return storage.run(turn, fn);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* The turn in flight, when it belongs to this conversation. A handler that
|
|
9
|
-
* posts into some other conversation is not replying to the event, so it gets
|
|
10
|
-
* nothing here and falls back to an unkeyed send.
|
|
11
|
-
*/
|
|
12
|
-
export function activeTurn(conversationId) {
|
|
13
|
-
const turn = storage.getStore();
|
|
14
|
-
return turn?.conversationId === conversationId ? turn : undefined;
|
|
15
|
-
}
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wire types for the Relay v1 developer API, scoped to what this adapter
|
|
3
|
-
* consumes and produces. The authoritative contract is the published OpenAPI
|
|
4
|
-
* document at https://docs.relayapp.im/api-reference. The part discriminator
|
|
5
|
-
* is `type`.
|
|
6
|
-
*/
|
|
7
|
-
export interface RelayEventEnvelope<TData = unknown> {
|
|
8
|
-
event_id: string;
|
|
9
|
-
event_type: string;
|
|
10
|
-
agent_id: string;
|
|
11
|
-
created_at: string;
|
|
12
|
-
data: TData;
|
|
13
|
-
}
|
|
14
|
-
export interface RelaySender {
|
|
15
|
-
kind: "user" | "agent" | "system";
|
|
16
|
-
id: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Inline mention of a conversation participant. Offsets are UTF-16 code units
|
|
20
|
-
* into the part's `text`, which holds the inserted display name with no "@".
|
|
21
|
-
* Ranges are sorted by `start` and never overlap.
|
|
22
|
-
*/
|
|
23
|
-
export interface RelayMentionRange {
|
|
24
|
-
start: number;
|
|
25
|
-
length: number;
|
|
26
|
-
participant_id: string;
|
|
27
|
-
}
|
|
28
|
-
export type RelayTextStyle = "bold" | "italic" | "underline" | "strikethrough" | "monospace" | "spoiler";
|
|
29
|
-
/**
|
|
30
|
-
* One formatting run over a text part, offsets in UTF-16 code units like
|
|
31
|
-
* mentions. An EMPTY `styles` array on the part is meaningful: it marks
|
|
32
|
-
* structured plain text as opposed to a legacy Markdown body.
|
|
33
|
-
*/
|
|
34
|
-
export interface RelayStyleRange {
|
|
35
|
-
start: number;
|
|
36
|
-
length: number;
|
|
37
|
-
styles: RelayTextStyle[];
|
|
38
|
-
}
|
|
39
|
-
/** Outgoing part shapes accepted by `POST /v1/messages`. */
|
|
40
|
-
export type RelayOutgoingPart = {
|
|
41
|
-
type: "text";
|
|
42
|
-
text: string;
|
|
43
|
-
mentions?: RelayMentionRange[];
|
|
44
|
-
styles?: RelayStyleRange[];
|
|
45
|
-
} | {
|
|
46
|
-
type: "media";
|
|
47
|
-
attachment_id?: string;
|
|
48
|
-
url?: string;
|
|
49
|
-
content_type?: string;
|
|
50
|
-
} | {
|
|
51
|
-
type: "voice_memo";
|
|
52
|
-
attachment_id?: string;
|
|
53
|
-
url?: string;
|
|
54
|
-
duration_ms?: number;
|
|
55
|
-
} | {
|
|
56
|
-
type: "link_preview";
|
|
57
|
-
url: string;
|
|
58
|
-
title?: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
} | {
|
|
61
|
-
type: "data";
|
|
62
|
-
data: Record<string, unknown>;
|
|
63
|
-
};
|
|
64
|
-
/** Stored canonical part as delivered in events and history. */
|
|
65
|
-
export interface RelayPart {
|
|
66
|
-
type: string;
|
|
67
|
-
part_index?: number;
|
|
68
|
-
text?: string;
|
|
69
|
-
mentions?: RelayMentionRange[];
|
|
70
|
-
styles?: RelayStyleRange[];
|
|
71
|
-
url?: string;
|
|
72
|
-
attachment_id?: string;
|
|
73
|
-
content_type?: string;
|
|
74
|
-
media_kind?: "image" | "video" | "audio" | "file";
|
|
75
|
-
filename?: string;
|
|
76
|
-
size_bytes?: number;
|
|
77
|
-
duration_ms?: number;
|
|
78
|
-
width?: number;
|
|
79
|
-
height?: number;
|
|
80
|
-
blur_hash?: string;
|
|
81
|
-
title?: string;
|
|
82
|
-
description?: string;
|
|
83
|
-
data?: Record<string, unknown>;
|
|
84
|
-
[key: string]: unknown;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* A message as Relay projects it for this agent. A tombstone carries no
|
|
88
|
-
* `parts`, so every reader must treat that field as optional.
|
|
89
|
-
*/
|
|
90
|
-
export interface RelayMessage {
|
|
91
|
-
id: string;
|
|
92
|
-
conversation_id: string;
|
|
93
|
-
sequence: number;
|
|
94
|
-
sender: RelaySender;
|
|
95
|
-
is_from_me?: boolean;
|
|
96
|
-
parts?: RelayPart[];
|
|
97
|
-
reply_to?: {
|
|
98
|
-
message_id?: string;
|
|
99
|
-
} | null;
|
|
100
|
-
invoked_agents?: string[];
|
|
101
|
-
reactions?: unknown[];
|
|
102
|
-
fallback_text?: string;
|
|
103
|
-
status: string;
|
|
104
|
-
delivered_at?: string;
|
|
105
|
-
read_at?: string;
|
|
106
|
-
edited_at?: string;
|
|
107
|
-
unsent_at?: string;
|
|
108
|
-
created_at: string;
|
|
109
|
-
}
|
|
110
|
-
export interface RelayMessageEventData {
|
|
111
|
-
message: RelayMessage;
|
|
112
|
-
invocation_id?: string;
|
|
113
|
-
}
|
|
114
|
-
export interface RelayMessageUnsentEventData {
|
|
115
|
-
message_id: string;
|
|
116
|
-
conversation_id: string;
|
|
117
|
-
sequence: number;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* The 202 from `POST /v1/messages`. The server splits the accepted parts at
|
|
121
|
-
* ingest: each visible non-media part becomes its own message, contiguous
|
|
122
|
-
* media parts stay one media message, and a voice memo always commits alone,
|
|
123
|
-
* so one send commits one or more messages, in display order.
|
|
124
|
-
*/
|
|
125
|
-
export interface RelaySendResult {
|
|
126
|
-
messages: RelayMessage[];
|
|
127
|
-
}
|
|
128
|
-
export interface RelayConversation {
|
|
129
|
-
id: string;
|
|
130
|
-
kind: "direct" | "group";
|
|
131
|
-
title: string | null;
|
|
132
|
-
counterpart_user: {
|
|
133
|
-
id: string;
|
|
134
|
-
display_name: string;
|
|
135
|
-
avatar_url: string | null;
|
|
136
|
-
} | null;
|
|
137
|
-
participant_count: number;
|
|
138
|
-
last_sequence: number;
|
|
139
|
-
last_message_at: string | null;
|
|
140
|
-
created_at: string;
|
|
141
|
-
}
|
|
142
|
-
export interface RelayUserProfile {
|
|
143
|
-
id: string;
|
|
144
|
-
name: string;
|
|
145
|
-
first_name: string;
|
|
146
|
-
last_name: string;
|
|
147
|
-
phone_number: string | null;
|
|
148
|
-
avatar_url: string | null;
|
|
149
|
-
created_at: string;
|
|
150
|
-
}
|
|
151
|
-
export interface RelayAttachment {
|
|
152
|
-
id: string;
|
|
153
|
-
url: string;
|
|
154
|
-
content_type: string;
|
|
155
|
-
size_bytes: number;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Relay carries one reaction kind. The field survives because the wire still
|
|
159
|
-
* names it, not because there is a choice to make.
|
|
160
|
-
*/
|
|
161
|
-
export type RelayReactionType = "emoji";
|
|
162
|
-
/**
|
|
163
|
-
* The raw payload this adapter hands to the Chat SDK. It carries the group
|
|
164
|
-
* invocation id alongside the message because Relay scopes a group reply to
|
|
165
|
-
* the invocation that produced the inbound event, and `Adapter.postMessage`
|
|
166
|
-
* never sees the event.
|
|
167
|
-
*/
|
|
168
|
-
export interface RelayRawMessage {
|
|
169
|
-
message: RelayMessage;
|
|
170
|
-
invocation_id?: string;
|
|
171
|
-
event_id?: string;
|
|
172
|
-
event_type?: string;
|
|
173
|
-
}
|
|
174
|
-
/** Platform-specific data behind a Relay thread id. */
|
|
175
|
-
export interface RelayThreadId {
|
|
176
|
-
conversationId: string;
|
|
177
|
-
}
|
package/dist/src/types.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wire types for the Relay v1 developer API, scoped to what this adapter
|
|
3
|
-
* consumes and produces. The authoritative contract is the published OpenAPI
|
|
4
|
-
* document at https://docs.relayapp.im/api-reference. The part discriminator
|
|
5
|
-
* is `type`.
|
|
6
|
-
*/
|
|
7
|
-
export {};
|