@bootdesk/js-web-adapter-core 0.1.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/README.md +78 -0
- package/dist/index.cjs +1042 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +433 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.js +997 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import Pusher from 'pusher-js';
|
|
2
|
+
import Echo from 'laravel-echo';
|
|
3
|
+
|
|
4
|
+
declare abstract class ChatEvent {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly threadId: string;
|
|
7
|
+
readonly timestamp: number;
|
|
8
|
+
constructor(type: string, threadId: string, timestamp: number);
|
|
9
|
+
static fromJSON: ((json: Record<string, unknown>) => ChatEvent) | undefined;
|
|
10
|
+
}
|
|
11
|
+
declare class UnknownEvent extends ChatEvent {
|
|
12
|
+
readonly data: Record<string, unknown>;
|
|
13
|
+
constructor(type: string, threadId: string, data: Record<string, unknown>, timestamp: number);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class TypingStartedEvent extends ChatEvent {
|
|
17
|
+
readonly userId: string;
|
|
18
|
+
constructor(threadId: string, userId: string, timestamp?: number);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class StreamingChunkEvent extends ChatEvent {
|
|
22
|
+
readonly messageId: string;
|
|
23
|
+
readonly chunk: string;
|
|
24
|
+
readonly isFinal: boolean;
|
|
25
|
+
constructor(threadId: string, messageId: string, chunk: string, isFinal: boolean, timestamp?: number);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface BaseCard {
|
|
29
|
+
type: string;
|
|
30
|
+
}
|
|
31
|
+
interface PHPCard extends BaseCard {
|
|
32
|
+
type: "card";
|
|
33
|
+
fallbackText: string;
|
|
34
|
+
header?: string;
|
|
35
|
+
image?: {
|
|
36
|
+
url: string;
|
|
37
|
+
alt: string;
|
|
38
|
+
};
|
|
39
|
+
sections?: CardSection[];
|
|
40
|
+
actions?: CardAction[];
|
|
41
|
+
elements?: CardElement[];
|
|
42
|
+
}
|
|
43
|
+
interface CardSection {
|
|
44
|
+
type: "section";
|
|
45
|
+
text?: string;
|
|
46
|
+
fields?: CardField[];
|
|
47
|
+
}
|
|
48
|
+
interface CardField {
|
|
49
|
+
title?: string;
|
|
50
|
+
value: string;
|
|
51
|
+
}
|
|
52
|
+
interface CardAction {
|
|
53
|
+
type: "button";
|
|
54
|
+
id: string;
|
|
55
|
+
label: string;
|
|
56
|
+
style?: "primary" | "secondary" | "danger";
|
|
57
|
+
value?: string;
|
|
58
|
+
href?: string;
|
|
59
|
+
}
|
|
60
|
+
type CardElement = TextElement | DividerElement | LinkElement | TableElement | LinkButtonElement | ImageElement;
|
|
61
|
+
interface TextElement {
|
|
62
|
+
type: "text";
|
|
63
|
+
content: string;
|
|
64
|
+
style?: "plain" | "bold" | "muted";
|
|
65
|
+
}
|
|
66
|
+
interface DividerElement {
|
|
67
|
+
type: "divider";
|
|
68
|
+
}
|
|
69
|
+
interface LinkElement {
|
|
70
|
+
type: "link";
|
|
71
|
+
label: string;
|
|
72
|
+
url: string;
|
|
73
|
+
}
|
|
74
|
+
interface TableElement {
|
|
75
|
+
type: "table";
|
|
76
|
+
headers: string[];
|
|
77
|
+
rows: string[][];
|
|
78
|
+
}
|
|
79
|
+
interface LinkButtonElement {
|
|
80
|
+
type: "link_button";
|
|
81
|
+
label: string;
|
|
82
|
+
url: string;
|
|
83
|
+
style?: "primary" | "secondary" | "danger";
|
|
84
|
+
}
|
|
85
|
+
interface ImageElement {
|
|
86
|
+
type: "image";
|
|
87
|
+
url: string;
|
|
88
|
+
alt: string;
|
|
89
|
+
}
|
|
90
|
+
interface ImageCard extends BaseCard {
|
|
91
|
+
type: "image";
|
|
92
|
+
url: string;
|
|
93
|
+
alt?: string;
|
|
94
|
+
title?: string;
|
|
95
|
+
}
|
|
96
|
+
interface FileCard extends BaseCard {
|
|
97
|
+
type: "file";
|
|
98
|
+
name: string;
|
|
99
|
+
url: string;
|
|
100
|
+
size?: number;
|
|
101
|
+
mimeType?: string;
|
|
102
|
+
}
|
|
103
|
+
type Card = PHPCard | ImageCard | FileCard;
|
|
104
|
+
interface CustomCard extends BaseCard {
|
|
105
|
+
type: string;
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface Message {
|
|
110
|
+
id: string;
|
|
111
|
+
threadId: string;
|
|
112
|
+
content: MessageContent;
|
|
113
|
+
author: User;
|
|
114
|
+
timestamp: number;
|
|
115
|
+
isStreaming?: boolean;
|
|
116
|
+
reactions?: Reaction[];
|
|
117
|
+
replyTo?: Message;
|
|
118
|
+
attachments?: Attachment[];
|
|
119
|
+
}
|
|
120
|
+
interface MessageContent {
|
|
121
|
+
text?: string;
|
|
122
|
+
cards?: Card[];
|
|
123
|
+
}
|
|
124
|
+
interface User {
|
|
125
|
+
id: string;
|
|
126
|
+
name?: string;
|
|
127
|
+
avatarUrl?: string;
|
|
128
|
+
isMe?: boolean;
|
|
129
|
+
isBot?: boolean;
|
|
130
|
+
}
|
|
131
|
+
interface Reaction {
|
|
132
|
+
emoji: string;
|
|
133
|
+
count: number;
|
|
134
|
+
users: string[];
|
|
135
|
+
hasReacted?: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface Attachment {
|
|
138
|
+
id: string;
|
|
139
|
+
name: string;
|
|
140
|
+
url: string;
|
|
141
|
+
type?: string;
|
|
142
|
+
size?: number;
|
|
143
|
+
mimeType?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare class MessagePostedEvent extends ChatEvent {
|
|
147
|
+
readonly messageId: string;
|
|
148
|
+
readonly text: string;
|
|
149
|
+
readonly author: User;
|
|
150
|
+
readonly card?: Card;
|
|
151
|
+
readonly attachments?: Array<{
|
|
152
|
+
type: string;
|
|
153
|
+
url?: string;
|
|
154
|
+
name?: string;
|
|
155
|
+
mimeType?: string;
|
|
156
|
+
size?: number | null;
|
|
157
|
+
}>;
|
|
158
|
+
constructor(threadId: string, messageId: string, text: string, author: User, card?: Card, attachments?: Array<{
|
|
159
|
+
type: string;
|
|
160
|
+
url?: string;
|
|
161
|
+
name?: string;
|
|
162
|
+
mimeType?: string;
|
|
163
|
+
size?: number | null;
|
|
164
|
+
}>, timestamp?: number);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
interface HttpClientConfig {
|
|
168
|
+
apiUrl: string;
|
|
169
|
+
headers?: Record<string, string>;
|
|
170
|
+
timeout?: number;
|
|
171
|
+
verifyToken?: string;
|
|
172
|
+
}
|
|
173
|
+
interface ChatResponse {
|
|
174
|
+
id: string;
|
|
175
|
+
role: "assistant" | "user";
|
|
176
|
+
text: string;
|
|
177
|
+
attachments?: Array<{
|
|
178
|
+
type: string;
|
|
179
|
+
url: string;
|
|
180
|
+
name?: string;
|
|
181
|
+
mime_type?: string;
|
|
182
|
+
size?: number;
|
|
183
|
+
}>;
|
|
184
|
+
events?: Array<Record<string, unknown>>;
|
|
185
|
+
}
|
|
186
|
+
declare class HttpClient {
|
|
187
|
+
private config;
|
|
188
|
+
constructor(config: HttpClientConfig);
|
|
189
|
+
get(url: string, signal?: AbortSignal): Promise<unknown>;
|
|
190
|
+
post(url: string, body: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
191
|
+
delete(url: string, signal?: AbortSignal): Promise<unknown>;
|
|
192
|
+
sendMessage(messages: Array<{
|
|
193
|
+
id: string;
|
|
194
|
+
role: string;
|
|
195
|
+
text: string;
|
|
196
|
+
attachments?: Array<{
|
|
197
|
+
url: string;
|
|
198
|
+
name?: string;
|
|
199
|
+
mime_type?: string;
|
|
200
|
+
size?: number;
|
|
201
|
+
}>;
|
|
202
|
+
}>, endpoint?: string, conversationId?: string): Promise<ChatResponse>;
|
|
203
|
+
sendAction(actionId: string, value: string, messageId: string, conversationId: string, endpoint?: string): Promise<Record<string, unknown>>;
|
|
204
|
+
editMessage(messageId: string, newText: string, endpointTemplate?: string): Promise<void>;
|
|
205
|
+
deleteMessage(messageId: string, endpointTemplate?: string): Promise<void>;
|
|
206
|
+
addReaction(messageId: string, emoji: string, endpointTemplate?: string): Promise<void>;
|
|
207
|
+
removeReaction(messageId: string, emoji: string, endpointTemplate?: string): Promise<void>;
|
|
208
|
+
private resolve;
|
|
209
|
+
private expandTemplate;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class DMRequestedEvent extends ChatEvent {
|
|
213
|
+
readonly userId: string;
|
|
214
|
+
constructor(threadId: string, userId: string, timestamp?: number);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
declare class ReactionRemovedEvent extends ChatEvent {
|
|
218
|
+
readonly messageId: string;
|
|
219
|
+
readonly emoji: string;
|
|
220
|
+
readonly user: User;
|
|
221
|
+
constructor(threadId: string, messageId: string, emoji: string, user: User, timestamp?: number);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare class ReactionAddedEvent extends ChatEvent {
|
|
225
|
+
readonly messageId: string;
|
|
226
|
+
readonly emoji: string;
|
|
227
|
+
readonly user: User;
|
|
228
|
+
constructor(threadId: string, messageId: string, emoji: string, user: User, timestamp?: number);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare class MessageDeletedEvent extends ChatEvent {
|
|
232
|
+
readonly messageId: string;
|
|
233
|
+
constructor(threadId: string, messageId: string, timestamp?: number);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare class MessageEditedEvent extends ChatEvent {
|
|
237
|
+
readonly messageId: string;
|
|
238
|
+
readonly newText: string;
|
|
239
|
+
readonly card?: Card;
|
|
240
|
+
constructor(threadId: string, messageId: string, newText: string, card?: Card, timestamp?: number);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
interface EventHandlers {
|
|
244
|
+
onMessagePosted?: (event: MessagePostedEvent) => void;
|
|
245
|
+
onMessageEdited?: (event: MessageEditedEvent) => void;
|
|
246
|
+
onMessageDeleted?: (event: MessageDeletedEvent) => void;
|
|
247
|
+
onReactionAdded?: (event: ReactionAddedEvent) => void;
|
|
248
|
+
onReactionRemoved?: (event: ReactionRemovedEvent) => void;
|
|
249
|
+
onTypingStarted?: (event: TypingStartedEvent) => void;
|
|
250
|
+
onStreamingChunk?: (event: StreamingChunkEvent) => void;
|
|
251
|
+
onDMRequested?: (event: DMRequestedEvent) => void;
|
|
252
|
+
}
|
|
253
|
+
type Unsubscribe = () => void;
|
|
254
|
+
interface ChannelTypeConfig {
|
|
255
|
+
threadChannel?: "public" | "private" | "presence";
|
|
256
|
+
userChannel?: "private" | "presence";
|
|
257
|
+
}
|
|
258
|
+
interface BroadcastClient {
|
|
259
|
+
connect(): void | Promise<void>;
|
|
260
|
+
disconnect(): void;
|
|
261
|
+
subscribe(threadId: string, handlers: EventHandlers): Unsubscribe;
|
|
262
|
+
subscribeToUser(threadId: string, userId: string, handlers: EventHandlers): Unsubscribe;
|
|
263
|
+
isConnected(): boolean;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface WebChatClientConfig {
|
|
267
|
+
apiUrl: string;
|
|
268
|
+
userId: string;
|
|
269
|
+
userName: string;
|
|
270
|
+
broadcastClient?: BroadcastClient;
|
|
271
|
+
headers?: Record<string, string>;
|
|
272
|
+
verifyToken?: string;
|
|
273
|
+
conversationId?: string;
|
|
274
|
+
endpoints?: {
|
|
275
|
+
sendMessage?: string;
|
|
276
|
+
loadMessages?: string;
|
|
277
|
+
editMessage?: string;
|
|
278
|
+
deleteMessage?: string;
|
|
279
|
+
addReaction?: string;
|
|
280
|
+
removeReaction?: string;
|
|
281
|
+
};
|
|
282
|
+
features?: {
|
|
283
|
+
editMessages?: boolean;
|
|
284
|
+
deleteMessages?: boolean;
|
|
285
|
+
reactions?: boolean;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
interface LoadMessagesOptions {
|
|
289
|
+
limit?: number;
|
|
290
|
+
before?: number;
|
|
291
|
+
after?: number;
|
|
292
|
+
skipStateSeed?: boolean;
|
|
293
|
+
}
|
|
294
|
+
interface LoadMessagesResult {
|
|
295
|
+
messages: Message[];
|
|
296
|
+
hasMore: boolean;
|
|
297
|
+
nextCursor?: number;
|
|
298
|
+
prevCursor?: number;
|
|
299
|
+
}
|
|
300
|
+
declare class WebChatClient {
|
|
301
|
+
private config;
|
|
302
|
+
private httpClient;
|
|
303
|
+
private broadcastClient?;
|
|
304
|
+
private conversationId;
|
|
305
|
+
private messages;
|
|
306
|
+
private currentUserId;
|
|
307
|
+
private eventHandlers;
|
|
308
|
+
private streamingMessages;
|
|
309
|
+
private pendingTyping;
|
|
310
|
+
private subscribers;
|
|
311
|
+
private unsubscribeUserChannel?;
|
|
312
|
+
constructor(config: WebChatClientConfig);
|
|
313
|
+
connect(): Promise<void>;
|
|
314
|
+
disconnect(): void;
|
|
315
|
+
loadMessages(options?: LoadMessagesOptions, signal?: AbortSignal): Promise<LoadMessagesResult>;
|
|
316
|
+
sendMessage(text: string, attachments?: any[]): Promise<void>;
|
|
317
|
+
sendAction(messageId: string, actionId: string, value: string): Promise<void>;
|
|
318
|
+
editMessage(messageId: string, newText: string): Promise<void>;
|
|
319
|
+
deleteMessage(messageId: string): Promise<void>;
|
|
320
|
+
addReaction(messageId: string, emoji: string): Promise<void>;
|
|
321
|
+
removeReaction(messageId: string, emoji: string): Promise<void>;
|
|
322
|
+
onMessagePosted(handler: (event: MessagePostedEvent) => void): Unsubscribe;
|
|
323
|
+
onStreamingChunk(handler: (event: StreamingChunkEvent) => void): Unsubscribe;
|
|
324
|
+
onTypingStarted(handler: (event: TypingStartedEvent) => void): Unsubscribe;
|
|
325
|
+
getConversationId(): string;
|
|
326
|
+
getMessages(): Message[];
|
|
327
|
+
getThreadId(): string;
|
|
328
|
+
getCurrentUserId(): string;
|
|
329
|
+
getFeatures(): NonNullable<WebChatClientConfig["features"]>;
|
|
330
|
+
getEndpoints(): NonNullable<WebChatClientConfig["endpoints"]>;
|
|
331
|
+
getHttpClient(): HttpClient;
|
|
332
|
+
addEventListener(eventType: string, handler: (event: any) => void): Unsubscribe;
|
|
333
|
+
private handleMessagePosted;
|
|
334
|
+
private handleMessageEdited;
|
|
335
|
+
private handleMessageDeleted;
|
|
336
|
+
private handleReactionAdded;
|
|
337
|
+
private handleReactionRemoved;
|
|
338
|
+
private handleStreamingChunk;
|
|
339
|
+
private handleTypingStarted;
|
|
340
|
+
private handleDMRequested;
|
|
341
|
+
private notifySubscribers;
|
|
342
|
+
private dispatchEvent;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface PusherConfig {
|
|
346
|
+
key: string;
|
|
347
|
+
cluster?: string;
|
|
348
|
+
host?: string;
|
|
349
|
+
port?: number;
|
|
350
|
+
forceTLS?: boolean;
|
|
351
|
+
authEndpoint?: string;
|
|
352
|
+
}
|
|
353
|
+
declare class PusherBroadcastClient implements BroadcastClient {
|
|
354
|
+
private pusher;
|
|
355
|
+
private channelPrefix;
|
|
356
|
+
private threadChannelType;
|
|
357
|
+
private userChannelType;
|
|
358
|
+
private subscriptions;
|
|
359
|
+
constructor(pusher: Pusher, channelPrefix?: string, channelTypes?: ChannelTypeConfig);
|
|
360
|
+
constructor(config: PusherConfig, channelPrefix?: string, channelTypes?: ChannelTypeConfig);
|
|
361
|
+
private buildChannelName;
|
|
362
|
+
connect(): void;
|
|
363
|
+
disconnect(): void;
|
|
364
|
+
subscribe(threadId: string, handlers: EventHandlers): Unsubscribe;
|
|
365
|
+
subscribeToUser(threadId: string, userId: string, handlers: EventHandlers): Unsubscribe;
|
|
366
|
+
isConnected(): boolean;
|
|
367
|
+
private dispatchToHandler;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
declare class LaravelEchoBroadcastClient implements BroadcastClient {
|
|
371
|
+
private echo;
|
|
372
|
+
private channelPrefix;
|
|
373
|
+
private threadChannelType;
|
|
374
|
+
private userChannelType;
|
|
375
|
+
private subscriptions;
|
|
376
|
+
constructor(echo: Echo<any>, channelPrefix?: string, channelTypes?: ChannelTypeConfig);
|
|
377
|
+
private subscribeToEcho;
|
|
378
|
+
connect(): void | Promise<void>;
|
|
379
|
+
disconnect(): void;
|
|
380
|
+
subscribe(threadId: string, handlers: EventHandlers): Unsubscribe;
|
|
381
|
+
subscribeToUser(threadId: string, userId: string, handlers: EventHandlers): Unsubscribe;
|
|
382
|
+
isConnected(): boolean;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
declare function parseChatEvent(json: Record<string, unknown>): ChatEvent;
|
|
386
|
+
|
|
387
|
+
declare function generateId(): string;
|
|
388
|
+
declare function generateConversationId(): string;
|
|
389
|
+
|
|
390
|
+
type PushSubscriptionStatus = "unsupported" | "denied" | "default" | "subscribing" | "subscribed" | "error";
|
|
391
|
+
interface PushConfig {
|
|
392
|
+
getVapidPublicKey: () => Promise<string>;
|
|
393
|
+
serviceWorkerUrl?: string;
|
|
394
|
+
serviceWorkerScope?: string;
|
|
395
|
+
onSubscribe: (subscription: PushSubscriptionJSON) => Promise<void>;
|
|
396
|
+
onUnsubscribe: (subscription: PushSubscriptionJSON) => Promise<void>;
|
|
397
|
+
notificationOptions?: {
|
|
398
|
+
icon?: string;
|
|
399
|
+
badge?: string;
|
|
400
|
+
sound?: string;
|
|
401
|
+
requireInteraction?: boolean;
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
interface PushEventData {
|
|
405
|
+
threadId: string;
|
|
406
|
+
messageId: string;
|
|
407
|
+
senderName: string;
|
|
408
|
+
preview: string;
|
|
409
|
+
timestamp: number;
|
|
410
|
+
deepLink?: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
declare class PushManager {
|
|
414
|
+
private config;
|
|
415
|
+
private registration;
|
|
416
|
+
private status;
|
|
417
|
+
private statusListeners;
|
|
418
|
+
private messageListeners;
|
|
419
|
+
constructor(config: PushConfig);
|
|
420
|
+
static isSupported(): boolean;
|
|
421
|
+
getStatus(): PushSubscriptionStatus;
|
|
422
|
+
onStatusChange(listener: (status: PushSubscriptionStatus) => void): () => void;
|
|
423
|
+
onMessage(listener: (data: PushEventData) => void): () => void;
|
|
424
|
+
initialize(): Promise<void>;
|
|
425
|
+
subscribe(): Promise<void>;
|
|
426
|
+
unsubscribe(): Promise<void>;
|
|
427
|
+
private urlBase64ToUint8Array;
|
|
428
|
+
private setStatus;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
declare function createPushSubscriptionHandlers(httpClient: HttpClient, userId: string): Pick<PushConfig, "onSubscribe" | "onUnsubscribe">;
|
|
432
|
+
|
|
433
|
+
export { type Attachment, type BaseCard, type BroadcastClient, type Card, type CardAction, type CardElement, type CardField, type CardSection, type ChannelTypeConfig, ChatEvent, type ChatResponse, type CustomCard, DMRequestedEvent, type DividerElement, type EventHandlers, type FileCard, HttpClient, type HttpClientConfig, type ImageCard, type ImageElement, LaravelEchoBroadcastClient, type LinkButtonElement, type LinkElement, type LoadMessagesOptions, type LoadMessagesResult, type Message, type MessageContent, MessageDeletedEvent, MessageEditedEvent, MessagePostedEvent, type PHPCard, type PushConfig, type PushEventData, PushManager, type PushSubscriptionStatus, PusherBroadcastClient, type PusherConfig, type Reaction, ReactionAddedEvent, ReactionRemovedEvent, StreamingChunkEvent, type TableElement, type TextElement, TypingStartedEvent, UnknownEvent, type Unsubscribe, type User, WebChatClient, type WebChatClientConfig, createPushSubscriptionHandlers, generateConversationId, generateId, parseChatEvent };
|