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