reachat 2.1.0-alpha.20 → 2.1.0-alpha.22

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.
Files changed (36) hide show
  1. package/dist/{CSVFileRenderer-B7eSDub6.js → CSVFileRenderer-DC2ZhtNx.js} +2 -2
  2. package/dist/{CSVFileRenderer-B7eSDub6.js.map → CSVFileRenderer-DC2ZhtNx.js.map} +1 -1
  3. package/dist/ChatInput/ChatInput.d.ts +9 -1
  4. package/dist/ChatInput/FileDropzone.d.ts +33 -0
  5. package/dist/ChatInput/FileInput.d.ts +0 -4
  6. package/dist/ChatInput/index.d.ts +1 -0
  7. package/dist/ChatSuggestions/ChatSuggestion.d.ts +9 -0
  8. package/dist/ChatSuggestions/ChatSuggestions.d.ts +22 -0
  9. package/dist/ChatSuggestions/index.d.ts +2 -0
  10. package/dist/{DefaultFileRenderer-CszY8p_0.js → DefaultFileRenderer-3oHDLIk4.js} +2 -2
  11. package/dist/{DefaultFileRenderer-CszY8p_0.js.map → DefaultFileRenderer-3oHDLIk4.js.map} +1 -1
  12. package/dist/MessageStatus/MessageStatus.d.ts +44 -0
  13. package/dist/MessageStatus/MessageStatusItem.d.ts +9 -0
  14. package/dist/MessageStatus/StatusIcon.d.ts +17 -0
  15. package/dist/MessageStatus/index.d.ts +3 -0
  16. package/dist/SessionMessages/SessionMessages.d.ts +4 -0
  17. package/dist/docs.json +555 -16
  18. package/dist/{index-DNefh8rs.js → index-CWCW-OiG.js} +477 -124
  19. package/dist/index-CWCW-OiG.js.map +1 -0
  20. package/dist/index.css +186 -55
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.js +30 -24
  23. package/dist/index.umd.cjs +450 -99
  24. package/dist/index.umd.cjs.map +1 -1
  25. package/dist/stories/ChatSuggestions.stories.tsx +542 -0
  26. package/dist/stories/Console.stories.tsx +101 -623
  27. package/dist/stories/Files.stories.tsx +348 -0
  28. package/dist/stories/Markdown.stories.tsx +108 -1
  29. package/dist/stories/MessageStatus.stories.tsx +326 -0
  30. package/dist/stories/SessionsList.stories.tsx +276 -0
  31. package/dist/stories/assets/sparkles.svg +7 -0
  32. package/dist/stories/examples.ts +34 -0
  33. package/dist/theme.d.ts +46 -0
  34. package/dist/types.d.ts +10 -0
  35. package/package.json +7 -4
  36. package/dist/index-DNefh8rs.js.map +0 -1
@@ -0,0 +1,542 @@
1
+ import type { Meta } from '@storybook/react';
2
+ import { useState } from 'react';
3
+
4
+ import {
5
+ Chat,
6
+ ChatInput,
7
+ ChatSuggestions,
8
+ NewSessionButton,
9
+ type Session,
10
+ SessionGroups,
11
+ SessionMessagePanel,
12
+ SessionMessages,
13
+ SessionMessagesHeader,
14
+ SessionsList,
15
+ type Suggestion
16
+ } from 'reachat';
17
+ import { defaultSuggestions, sessionWithSuggestions } from './examples';
18
+ import Placeholder from './assets/placeholder.svg?react';
19
+ import PlaceholderDark from './assets/placeholder-dark.svg?react';
20
+ import SparklesIcon from './assets/sparkles.svg?react';
21
+
22
+ export default {
23
+ title: 'Demos/Suggestions',
24
+ component: ChatSuggestions
25
+ } as Meta;
26
+
27
+ export const Basic = () => {
28
+ const [sessions, setSessions] = useState<Session[]>(sessionWithSuggestions);
29
+ const [activeId, setActiveId] = useState<string>('session-suggestions');
30
+
31
+ return (
32
+ <div
33
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
34
+ style={{
35
+ position: 'absolute',
36
+ top: 0,
37
+ left: 0,
38
+ right: 0,
39
+ bottom: 0,
40
+ padding: 20,
41
+ margin: 20,
42
+ borderRadius: 5
43
+ }}
44
+ >
45
+ <Chat
46
+ viewType="console"
47
+ sessions={sessions}
48
+ activeSessionId={activeId}
49
+ onSelectSession={setActiveId}
50
+ onSendMessage={message => {
51
+ setSessions(prev =>
52
+ prev.map(session =>
53
+ session.id === activeId
54
+ ? {
55
+ ...session,
56
+ conversations: [
57
+ ...session.conversations,
58
+ {
59
+ id: Date.now().toString(),
60
+ question: message,
61
+ response: 'This is a response to your question.',
62
+ createdAt: new Date()
63
+ }
64
+ ]
65
+ }
66
+ : session
67
+ )
68
+ );
69
+ }}
70
+ onDeleteSession={() => alert('delete!')}
71
+ >
72
+ <SessionsList>
73
+ <NewSessionButton />
74
+ <SessionGroups />
75
+ </SessionsList>
76
+ <SessionMessagePanel>
77
+ <SessionMessagesHeader />
78
+ <SessionMessages />
79
+ <ChatSuggestions suggestions={defaultSuggestions} />
80
+ <ChatInput placeholder="Type a message..." />
81
+ </SessionMessagePanel>
82
+ </Chat>
83
+ </div>
84
+ );
85
+ };
86
+
87
+ export const LongSuggestions = () => {
88
+ const [sessions, setSessions] = useState<Session[]>(sessionWithSuggestions);
89
+ const [activeId, setActiveId] = useState<string>('session-suggestions');
90
+
91
+ const longSuggestions: Suggestion[] = [
92
+ {
93
+ id: '1',
94
+ content:
95
+ 'Can you explain in detail how machine learning algorithms work and what are the key differences between supervised and unsupervised learning?'
96
+ },
97
+ {
98
+ id: '2',
99
+ content:
100
+ 'What are the best practices for building scalable and maintainable React applications with TypeScript?'
101
+ },
102
+ {
103
+ id: '3',
104
+ content:
105
+ 'How do I implement authentication and authorization in a modern web application using OAuth 2.0 and OpenID Connect?'
106
+ },
107
+ {
108
+ id: '4',
109
+ content: 'Short one'
110
+ }
111
+ ];
112
+
113
+ return (
114
+ <div
115
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
116
+ style={{
117
+ position: 'absolute',
118
+ top: 0,
119
+ left: 0,
120
+ right: 0,
121
+ bottom: 0,
122
+ padding: 20,
123
+ margin: 20,
124
+ borderRadius: 5
125
+ }}
126
+ >
127
+ <Chat
128
+ viewType="console"
129
+ sessions={sessions}
130
+ activeSessionId={activeId}
131
+ onSelectSession={setActiveId}
132
+ onSendMessage={message => {
133
+ setSessions(prev =>
134
+ prev.map(session =>
135
+ session.id === activeId
136
+ ? {
137
+ ...session,
138
+ conversations: [
139
+ ...session.conversations,
140
+ {
141
+ id: Date.now().toString(),
142
+ question: message,
143
+ response: 'This is a response to your question.',
144
+ createdAt: new Date()
145
+ }
146
+ ]
147
+ }
148
+ : session
149
+ )
150
+ );
151
+ }}
152
+ onDeleteSession={() => alert('delete!')}
153
+ >
154
+ <SessionsList>
155
+ <NewSessionButton />
156
+ <SessionGroups />
157
+ </SessionsList>
158
+ <SessionMessagePanel>
159
+ <SessionMessagesHeader />
160
+ <SessionMessages />
161
+ <ChatSuggestions suggestions={longSuggestions} />
162
+ <ChatInput placeholder="Type a message..." />
163
+ </SessionMessagePanel>
164
+ </Chat>
165
+ </div>
166
+ );
167
+ };
168
+
169
+ export const EmptySession = () => {
170
+ const [sessions, setSessions] = useState<Session[]>([]);
171
+ const [activeId, setActiveId] = useState<string>();
172
+
173
+ const initialSuggestions: Suggestion[] = [
174
+ { id: '1', content: 'What can you help me with?' },
175
+ { id: '2', content: 'Tell me about your capabilities' },
176
+ { id: '3', content: 'How do I get started?' },
177
+ { id: '4', content: 'Show me some examples' }
178
+ ];
179
+
180
+ return (
181
+ <div
182
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
183
+ style={{
184
+ position: 'absolute',
185
+ top: 0,
186
+ left: 0,
187
+ right: 0,
188
+ bottom: 0,
189
+ padding: 20,
190
+ margin: 20,
191
+ borderRadius: 5
192
+ }}
193
+ >
194
+ <Chat
195
+ viewType="console"
196
+ sessions={sessions}
197
+ activeSessionId={activeId}
198
+ onSelectSession={setActiveId}
199
+ onNewSession={() => {
200
+ const newId = Date.now().toString();
201
+ setSessions(prev => [
202
+ ...prev,
203
+ {
204
+ id: newId,
205
+ title: 'New Session',
206
+ createdAt: new Date(),
207
+ conversations: []
208
+ }
209
+ ]);
210
+ setActiveId(newId);
211
+ }}
212
+ onSendMessage={message => {
213
+ if (!activeId) {
214
+ const newId = Date.now().toString();
215
+ setSessions([
216
+ {
217
+ id: newId,
218
+ title: message.substring(0, 30),
219
+ createdAt: new Date(),
220
+ conversations: [
221
+ {
222
+ id: '1',
223
+ question: message,
224
+ response: 'This is a response to your question.',
225
+ createdAt: new Date()
226
+ }
227
+ ]
228
+ }
229
+ ]);
230
+ setActiveId(newId);
231
+ } else {
232
+ setSessions(prev =>
233
+ prev.map(session =>
234
+ session.id === activeId
235
+ ? {
236
+ ...session,
237
+ conversations: [
238
+ ...session.conversations,
239
+ {
240
+ id: Date.now().toString(),
241
+ question: message,
242
+ response: 'This is a response to your question.',
243
+ createdAt: new Date()
244
+ }
245
+ ]
246
+ }
247
+ : session
248
+ )
249
+ );
250
+ }
251
+ }}
252
+ onDeleteSession={() => alert('delete!')}
253
+ >
254
+ <SessionsList>
255
+ <NewSessionButton />
256
+ <SessionGroups />
257
+ </SessionsList>
258
+ <div className="flex-1 h-full flex flex-col">
259
+ <SessionMessages
260
+ newSessionContent={
261
+ <div className="flex flex-col gap-4 items-center justify-center h-full">
262
+ <Placeholder className="w-48 block dark:hidden" />
263
+ <PlaceholderDark className="w-48 hidden dark:block" />
264
+ <p className="text-gray-500 max-w-[400px] text-center">
265
+ Welcome! Start a conversation or choose one of the suggestions
266
+ below.
267
+ </p>
268
+ <ChatSuggestions suggestions={initialSuggestions} />
269
+ </div>
270
+ }
271
+ />
272
+ <ChatInput placeholder="Type a message..." />
273
+ </div>
274
+ </Chat>
275
+ </div>
276
+ );
277
+ };
278
+
279
+ export const Companion = () => {
280
+ const [sessions, setSessions] = useState<Session[]>(sessionWithSuggestions);
281
+ const [activeId, setActiveId] = useState<string>('session-suggestions');
282
+
283
+ return (
284
+ <div
285
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
286
+ style={{
287
+ width: 350,
288
+ height: 500,
289
+ padding: 20,
290
+ borderRadius: 5
291
+ }}
292
+ >
293
+ <Chat
294
+ viewType="companion"
295
+ sessions={sessions}
296
+ activeSessionId={activeId}
297
+ onSelectSession={setActiveId}
298
+ onSendMessage={message => {
299
+ setSessions(prev =>
300
+ prev.map(session =>
301
+ session.id === activeId
302
+ ? {
303
+ ...session,
304
+ conversations: [
305
+ ...session.conversations,
306
+ {
307
+ id: Date.now().toString(),
308
+ question: message,
309
+ response: 'This is a response to your question.',
310
+ createdAt: new Date()
311
+ }
312
+ ]
313
+ }
314
+ : session
315
+ )
316
+ );
317
+ }}
318
+ onDeleteSession={() => alert('delete!')}
319
+ >
320
+ <SessionsList>
321
+ <NewSessionButton />
322
+ <SessionGroups />
323
+ </SessionsList>
324
+ <SessionMessagePanel>
325
+ <SessionMessagesHeader />
326
+ <SessionMessages />
327
+ <ChatSuggestions suggestions={defaultSuggestions} />
328
+ <ChatInput placeholder="Type a message..." />
329
+ </SessionMessagePanel>
330
+ </Chat>
331
+ </div>
332
+ );
333
+ };
334
+
335
+ export const CustomItemRendering = () => {
336
+ const [sessions, setSessions] = useState<Session[]>(sessionWithSuggestions);
337
+ const [activeId, setActiveId] = useState<string>('session-suggestions');
338
+
339
+ const suggestions: Suggestion[] = [
340
+ { id: '1', content: 'How does this work?' },
341
+ { id: '2', content: 'What are the limitations?' },
342
+ { id: '3', content: 'Can you explain further?' }
343
+ ];
344
+
345
+ return (
346
+ <div
347
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
348
+ style={{
349
+ position: 'absolute',
350
+ top: 0,
351
+ left: 0,
352
+ right: 0,
353
+ bottom: 0,
354
+ padding: 20,
355
+ margin: 20,
356
+ borderRadius: 5
357
+ }}
358
+ >
359
+ <Chat
360
+ viewType="console"
361
+ sessions={sessions}
362
+ activeSessionId={activeId}
363
+ onSelectSession={setActiveId}
364
+ onSendMessage={message => {
365
+ setSessions(prev =>
366
+ prev.map(session =>
367
+ session.id === activeId
368
+ ? {
369
+ ...session,
370
+ conversations: [
371
+ ...session.conversations,
372
+ {
373
+ id: Date.now().toString(),
374
+ question: message,
375
+ response: 'This is a response to your question.',
376
+ createdAt: new Date()
377
+ }
378
+ ]
379
+ }
380
+ : session
381
+ )
382
+ );
383
+ }}
384
+ onDeleteSession={() => alert('delete!')}
385
+ >
386
+ <SessionsList>
387
+ <NewSessionButton />
388
+ <SessionGroups />
389
+ </SessionsList>
390
+ <SessionMessagePanel>
391
+ <SessionMessagesHeader />
392
+ <SessionMessages />
393
+ <ChatSuggestions suggestions={suggestions}>
394
+ <CustomSuggestionItem />
395
+ </ChatSuggestions>
396
+ <ChatInput placeholder="Type a message..." />
397
+ </SessionMessagePanel>
398
+ </Chat>
399
+ </div>
400
+ );
401
+ };
402
+
403
+ const CustomSuggestionItem = ({
404
+ content,
405
+ onClick
406
+ }: {
407
+ content?: string;
408
+ onClick?: (c: string) => void;
409
+ }) => (
410
+ <button
411
+ className="px-4 py-2 bg-gradient-to-r from-blue-500 to-purple-500 text-white rounded-lg hover:from-blue-600 hover:to-purple-600 transition-all duration-200 shadow-md hover:shadow-lg"
412
+ onClick={() => onClick?.(content || '')}
413
+ >
414
+ <span className="flex items-center gap-2">
415
+ <SparklesIcon className="w-4 h-4" />
416
+ {content}
417
+ </span>
418
+ </button>
419
+ );
420
+
421
+ export const DynamicSuggestions = () => {
422
+ const [sessions, setSessions] = useState<Session[]>([
423
+ {
424
+ id: 'session-1',
425
+ title: 'Dynamic Suggestions Demo',
426
+ createdAt: new Date(),
427
+ conversations: []
428
+ }
429
+ ]);
430
+ const [activeId, setActiveId] = useState<string>('session-1');
431
+ const [suggestions, setSuggestions] = useState<Suggestion[]>([
432
+ { id: '1', content: 'What is machine learning?' },
433
+ { id: '2', content: 'Explain neural networks' },
434
+ { id: '3', content: 'What is deep learning?' }
435
+ ]);
436
+
437
+ const suggestionResponseMap: Record<
438
+ string,
439
+ { response: string; nextSuggestions: Suggestion[] }
440
+ > = {
441
+ 'What is machine learning?': {
442
+ response:
443
+ 'Machine learning is a subset of artificial intelligence that enables systems to learn and improve from experience.',
444
+ nextSuggestions: [
445
+ { id: '4', content: 'What are the types of machine learning?' },
446
+ { id: '5', content: 'How is ML different from AI?' },
447
+ { id: '6', content: 'What are common ML algorithms?' }
448
+ ]
449
+ },
450
+ 'Explain neural networks': {
451
+ response:
452
+ 'Neural networks are computing systems inspired by biological neural networks in the human brain.',
453
+ nextSuggestions: [
454
+ { id: '7', content: 'How do neurons work in a network?' },
455
+ { id: '8', content: 'What is backpropagation?' },
456
+ { id: '9', content: 'What are activation functions?' }
457
+ ]
458
+ },
459
+ 'What is deep learning?': {
460
+ response:
461
+ 'Deep learning is a type of machine learning based on artificial neural networks with multiple layers.',
462
+ nextSuggestions: [
463
+ { id: '10', content: 'What are CNNs?' },
464
+ { id: '11', content: 'What are RNNs?' },
465
+ { id: '12', content: 'What is a transformer model?' }
466
+ ]
467
+ }
468
+ };
469
+
470
+ const handleSendMessage = (message: string) => {
471
+ const mapping = suggestionResponseMap[message];
472
+ const response =
473
+ mapping?.response ||
474
+ 'Thank you for your question. Here is a helpful response.';
475
+ const nextSuggestions = mapping?.nextSuggestions || [
476
+ { id: Date.now().toString(), content: 'Tell me more' },
477
+ { id: (Date.now() + 1).toString(), content: 'Can you clarify?' }
478
+ ];
479
+
480
+ setSessions(prev =>
481
+ prev.map(session =>
482
+ session.id === activeId
483
+ ? {
484
+ ...session,
485
+ conversations: [
486
+ ...session.conversations,
487
+ {
488
+ id: Date.now().toString(),
489
+ question: message,
490
+ response,
491
+ createdAt: new Date()
492
+ }
493
+ ]
494
+ }
495
+ : session
496
+ )
497
+ );
498
+
499
+ setSuggestions(nextSuggestions);
500
+ };
501
+
502
+ return (
503
+ <div
504
+ className="dark:bg-(--color-background-basic-black) bg-(--color-background-basic-white)"
505
+ style={{
506
+ position: 'absolute',
507
+ top: 0,
508
+ left: 0,
509
+ right: 0,
510
+ bottom: 0,
511
+ padding: 20,
512
+ margin: 20,
513
+ borderRadius: 5
514
+ }}
515
+ >
516
+ <Chat
517
+ viewType="console"
518
+ sessions={sessions}
519
+ activeSessionId={activeId}
520
+ onSelectSession={setActiveId}
521
+ onSendMessage={handleSendMessage}
522
+ onDeleteSession={() => alert('delete!')}
523
+ >
524
+ <SessionsList>
525
+ <NewSessionButton />
526
+ <SessionGroups />
527
+ </SessionsList>
528
+ <SessionMessagePanel>
529
+ <SessionMessagesHeader />
530
+ <SessionMessages />
531
+ <ChatSuggestions
532
+ suggestions={suggestions}
533
+ onSuggestionClick={suggestion =>
534
+ console.log('Suggestion clicked:', suggestion)
535
+ }
536
+ />
537
+ <ChatInput placeholder="Type a message..." />
538
+ </SessionMessagePanel>
539
+ </Chat>
540
+ </div>
541
+ );
542
+ };