reachat 2.2.0 → 3.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.
Files changed (46) hide show
  1. package/dist/{CSVFileRenderer-BOdL4Jte.js → CSVFileRenderer-C2E4Xnkz.js} +2 -2
  2. package/dist/{CSVFileRenderer-BOdL4Jte.js.map → CSVFileRenderer-C2E4Xnkz.js.map} +1 -1
  3. package/dist/Chat.d.ts +12 -0
  4. package/dist/{Markdown/charts/ChartError.d.ts → ComponentCatalog/ComponentError.d.ts} +2 -2
  5. package/dist/ComponentCatalog/ComponentPre.d.ts +18 -0
  6. package/dist/ComponentCatalog/ComponentRenderer.d.ts +17 -0
  7. package/dist/ComponentCatalog/chartComponentDef.d.ts +36 -0
  8. package/dist/ComponentCatalog/componentCatalog.d.ts +44 -0
  9. package/dist/ComponentCatalog/componentCatalog.spec.d.ts +1 -0
  10. package/dist/ComponentCatalog/generatePrompt.d.ts +9 -0
  11. package/dist/ComponentCatalog/generatePrompt.spec.d.ts +1 -0
  12. package/dist/ComponentCatalog/index.d.ts +9 -0
  13. package/dist/ComponentCatalog/types.d.ts +108 -0
  14. package/dist/ComponentCatalog/validateSpec.d.ts +17 -0
  15. package/dist/ComponentCatalog/validateSpec.spec.d.ts +1 -0
  16. package/dist/{DefaultFileRenderer-C2MsQ9wz.js → DefaultFileRenderer-Day12qYs.js} +2 -2
  17. package/dist/{DefaultFileRenderer-C2MsQ9wz.js.map → DefaultFileRenderer-Day12qYs.js.map} +1 -1
  18. package/dist/Markdown/charts/ChartRenderer.d.ts +1 -1
  19. package/dist/Markdown/charts/ComponentError.d.ts +1 -0
  20. package/dist/Markdown/charts/index.d.ts +2 -6
  21. package/dist/Markdown/charts/types.d.ts +21 -0
  22. package/dist/Markdown/plugins/index.d.ts +1 -1
  23. package/dist/Markdown/plugins/remarkComponent.d.ts +27 -0
  24. package/dist/docs.json +275 -93
  25. package/dist/{index-DdRyk11n.js → index-CZSBRZbI.js} +524 -230
  26. package/dist/index-CZSBRZbI.js.map +1 -0
  27. package/dist/index.css +101 -1077
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +22 -22
  30. package/dist/index.umd.cjs +509 -215
  31. package/dist/index.umd.cjs.map +1 -1
  32. package/dist/stories/Changelog.mdx +1 -1
  33. package/dist/stories/Charts.stories.tsx +118 -130
  34. package/dist/stories/ComponentCatalog.stories.tsx +509 -0
  35. package/dist/stories/{ChartError.stories.tsx → ComponentError.stories.tsx} +14 -11
  36. package/dist/stories/Intro.mdx +1 -1
  37. package/dist/theme.d.ts +3 -0
  38. package/dist/utils/getChildText.d.ts +10 -0
  39. package/dist/utils/getChildText.spec.d.ts +1 -0
  40. package/package.json +27 -30
  41. package/dist/Markdown/charts/ChartPre.d.ts +0 -6
  42. package/dist/Markdown/charts/chartHelpers.d.ts +0 -40
  43. package/dist/Markdown/plugins/remarkChart.d.ts +0 -59
  44. package/dist/index-DdRyk11n.js.map +0 -1
  45. package/dist/stories/Integration.stories.tsx +0 -312
  46. /package/dist/{Markdown/charts/chartHelpers.spec.d.ts → ComponentCatalog/chartComponentDef.spec.d.ts} +0 -0
@@ -1,312 +0,0 @@
1
- import { useState, useCallback, useRef, useEffect } from 'react';
2
- import OpenAI from 'openai';
3
- import { Meta } from '@storybook/react';
4
- import {
5
- Chat,
6
- Session,
7
- SessionsList,
8
- NewSessionButton,
9
- SessionMessages,
10
- SessionGroups,
11
- ChatInput,
12
- SessionMessagePanel,
13
- SessionMessagesHeader
14
- } from 'reachat';
15
- import { Input } from 'reablocks';
16
- import { generateText } from 'ai';
17
- import { createOpenAI } from '@ai-sdk/openai';
18
-
19
- export default {
20
- title: 'Demos/Integrations',
21
- component: Chat
22
- } as Meta;
23
-
24
- export const _OpenAI = () => {
25
- const [sessions, setSessions] = useState<Session[]>([]);
26
- const [isLoading, setIsLoading] = useState(false);
27
- const [activeSessionId, setActiveSessionId] = useState(null);
28
- const [apiKey, setApiKey] = useState('');
29
-
30
- const openai = useRef<OpenAI | null>(null);
31
-
32
- useEffect(() => {
33
- if (apiKey) {
34
- openai.current = new OpenAI({
35
- apiKey: apiKey,
36
- dangerouslyAllowBrowser: true // For demo purposes only
37
- });
38
- }
39
- }, [apiKey]);
40
-
41
- const handleNewMessage = useCallback(
42
- async (message: string, sessionId: string = '1') => {
43
- setIsLoading(true);
44
- try {
45
- const response = await openai.current.chat.completions.create({
46
- model: 'gpt-3.5-turbo',
47
- messages: [{ role: 'user', content: message }]
48
- });
49
-
50
- const aiResponse =
51
- response.choices[0]?.message?.content ||
52
- 'Sorry, I couldnt generate a response.';
53
-
54
- setSessions(prevSessions => {
55
- const sessionIndex = prevSessions.findIndex(s => s.id === sessionId);
56
- if (sessionIndex === -1) {
57
- // Create a new session
58
- return [
59
- ...prevSessions,
60
- {
61
- id: sessionId,
62
- title: message.slice(0, 30),
63
- createdAt: new Date(),
64
- updatedAt: new Date(),
65
- conversations: [
66
- {
67
- id: Date.now().toString(),
68
- question: message,
69
- response: aiResponse,
70
- createdAt: new Date(),
71
- updatedAt: new Date()
72
- }
73
- ]
74
- }
75
- ];
76
- } else {
77
- // Add to existing session
78
- const updatedSessions = [...prevSessions];
79
- updatedSessions[sessionIndex] = {
80
- ...updatedSessions[sessionIndex],
81
- updatedAt: new Date(),
82
- conversations: [
83
- ...updatedSessions[sessionIndex].conversations,
84
- {
85
- id: Date.now().toString(),
86
- question: message,
87
- response: aiResponse,
88
- createdAt: new Date(),
89
- updatedAt: new Date()
90
- }
91
- ]
92
- };
93
- return updatedSessions;
94
- }
95
- });
96
-
97
- setActiveSessionId(sessionId);
98
- } catch (error) {
99
- console.error('Error calling OpenAI API:', error);
100
- } finally {
101
- setIsLoading(false);
102
- }
103
- },
104
- [openai]
105
- );
106
-
107
- const handleDeleteSession = useCallback((sessionId: string) => {
108
- setSessions(prevSessions => prevSessions.filter(s => s.id !== sessionId));
109
- }, []);
110
-
111
- return (
112
- <div
113
- style={{
114
- position: 'absolute',
115
- top: 0,
116
- left: 0,
117
- right: 0,
118
- bottom: 0,
119
- padding: 20
120
- }}
121
- >
122
- <Input
123
- fullWidth
124
- placeholder="OpenAI API Key"
125
- value={apiKey}
126
- onChange={e => setApiKey(e.target.value)}
127
- />
128
- <div
129
- className="dark:bg-gray-950 bg-white"
130
- style={{
131
- position: 'absolute',
132
- top: 50,
133
- left: 0,
134
- right: 0,
135
- bottom: 0,
136
- padding: 20,
137
- margin: 20,
138
- borderRadius: 5
139
- }}
140
- >
141
- <Chat
142
- viewType="console"
143
- sessions={sessions}
144
- isLoading={isLoading}
145
- disabled={!apiKey}
146
- onDeleteSession={handleDeleteSession}
147
- onSendMessage={handleNewMessage}
148
- activeSessionId={activeSessionId}
149
- >
150
- <SessionsList>
151
- <NewSessionButton />
152
- <SessionGroups />
153
- </SessionsList>
154
-
155
- <SessionMessagePanel>
156
- <SessionMessagesHeader />
157
- <SessionMessages />
158
- <ChatInput />
159
- </SessionMessagePanel>
160
- </Chat>
161
- </div>
162
- </div>
163
- );
164
- };
165
-
166
- export const VercelAI = () => {
167
- const [sessions, setSessions] = useState<Session[]>([]);
168
- const [isLoading, setIsLoading] = useState(false);
169
- const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
170
- const [apiKey, setApiKey] = useState('');
171
-
172
- const handleNewMessage = useCallback(
173
- async (message: string, sessionId: string | null = null) => {
174
- if (!apiKey) {
175
- console.error('API key not set');
176
- return;
177
- }
178
-
179
- setIsLoading(true);
180
- try {
181
- const openai = createOpenAI({ apiKey });
182
- const req = await generateText({
183
- model: openai('gpt-3.5-turbo'),
184
- prompt: message
185
- });
186
-
187
- const response = req.text;
188
-
189
- setSessions(prevSessions => {
190
- const newSessionId = sessionId || Date.now().toString();
191
- const sessionIndex = prevSessions.findIndex(
192
- s => s.id === newSessionId
193
- );
194
-
195
- if (sessionIndex === -1) {
196
- // Create a new session
197
- const newSession: Session = {
198
- id: newSessionId,
199
- title: message.slice(0, 30),
200
- createdAt: new Date(),
201
- updatedAt: new Date(),
202
- conversations: [
203
- {
204
- id: Date.now().toString(),
205
- question: message,
206
- response: response,
207
- createdAt: new Date(),
208
- updatedAt: new Date()
209
- }
210
- ]
211
- };
212
- return [...prevSessions, newSession];
213
- } else {
214
- // Add to existing session
215
- const updatedSessions = [...prevSessions];
216
- updatedSessions[sessionIndex] = {
217
- ...updatedSessions[sessionIndex],
218
- updatedAt: new Date(),
219
- conversations: [
220
- ...updatedSessions[sessionIndex].conversations,
221
- {
222
- id: Date.now().toString(),
223
- question: message,
224
- response: response,
225
- createdAt: new Date(),
226
- updatedAt: new Date()
227
- }
228
- ]
229
- };
230
- return updatedSessions;
231
- }
232
- });
233
-
234
- setActiveSessionId(sessionId || Date.now().toString());
235
- } catch (error) {
236
- console.error('Error generating text:', error);
237
- } finally {
238
- setIsLoading(false);
239
- }
240
- },
241
- [apiKey]
242
- );
243
-
244
- const handleDeleteSession = useCallback(
245
- (sessionId: string) => {
246
- setSessions(prevSessions => prevSessions.filter(s => s.id !== sessionId));
247
- if (activeSessionId === sessionId) {
248
- setActiveSessionId(null);
249
- }
250
- },
251
- [activeSessionId]
252
- );
253
-
254
- const handleNewSession = useCallback(() => {
255
- setActiveSessionId(null);
256
- }, []);
257
-
258
- return (
259
- <div
260
- style={{
261
- position: 'absolute',
262
- top: 0,
263
- left: 0,
264
- right: 0,
265
- bottom: 0,
266
- padding: 20
267
- }}
268
- >
269
- <Input
270
- fullWidth
271
- placeholder="OpenAI API Key"
272
- value={apiKey}
273
- onChange={e => setApiKey(e.target.value)}
274
- />
275
- <div
276
- className="dark:bg-gray-950 bg-white"
277
- style={{
278
- position: 'absolute',
279
- top: 50,
280
- left: 0,
281
- right: 0,
282
- bottom: 0,
283
- padding: 20,
284
- margin: 20,
285
- borderRadius: 5
286
- }}
287
- >
288
- <Chat
289
- viewType="console"
290
- sessions={sessions}
291
- isLoading={isLoading}
292
- disabled={!apiKey}
293
- onSendMessage={handleNewMessage}
294
- onDeleteSession={handleDeleteSession}
295
- activeSessionId={activeSessionId}
296
- onSelectSession={setActiveSessionId}
297
- >
298
- <SessionsList>
299
- <NewSessionButton />
300
- <SessionGroups />
301
- </SessionsList>
302
-
303
- <SessionMessagePanel>
304
- <SessionMessagesHeader />
305
- <SessionMessages />
306
- <ChatInput />
307
- </SessionMessagePanel>
308
- </Chat>
309
- </div>
310
- </div>
311
- );
312
- };