cosmic-ai-genius 0.3.7 → 0.3.9
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 -655
- package/package.json +1 -12
package/README.md
CHANGED
|
@@ -1,658 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cosmic-ai-genius
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Private AI SDK for internal use only.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- 🎤 **Voice Integration** - Voice call functionality with animated waveforms
|
|
9
|
-
- 🎨 **Fully Customizable** - Themes, positioning, and behavior customization
|
|
10
|
-
- 📱 **Mobile Responsive** - Optimized for all screen sizes
|
|
11
|
-
- 🚀 **Easy Integration** - Simple provider pattern for seamless integration
|
|
12
|
-
- ⚡ **TypeScript Support** - Full type safety and IntelliSense
|
|
13
|
-
- 🎯 **Multiple Components** - Flexible component architecture
|
|
14
|
-
- 🔄 **Streaming Support** - Real-time streaming responses with SSE
|
|
15
|
-
- 🤖 **Backend Integration** - Connect to AI backends with RAG support
|
|
16
|
-
- 📝 **Markdown Rendering** - Rich text formatting in messages
|
|
17
|
-
- 📚 **Source Citations** - Display grounding sources for AI responses
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
Install the package from npm:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
# Using npm
|
|
25
|
-
npm install cosmic-ai-genius
|
|
26
|
-
|
|
27
|
-
# Using yarn
|
|
28
|
-
yarn add cosmic-ai-genius
|
|
29
|
-
|
|
30
|
-
# Using pnpm
|
|
31
|
-
pnpm add cosmic-ai-genius
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Quick Start
|
|
35
|
-
|
|
36
|
-
### 1. Basic Setup
|
|
37
|
-
|
|
38
|
-
Wrap your app with the `GeniusChatbotProvider`:
|
|
39
|
-
|
|
40
|
-
```tsx
|
|
41
|
-
import { GeniusChatbotProvider, GeniusToggle } from 'cosmic-ai-genius';
|
|
42
|
-
|
|
43
|
-
function App() {
|
|
44
|
-
return (
|
|
45
|
-
<GeniusChatbotProvider
|
|
46
|
-
config={{
|
|
47
|
-
welcomeMessage: "Hi! How can I help you today?",
|
|
48
|
-
suggestions: ['How to get started?', 'Pricing', 'Support'],
|
|
49
|
-
position: 'bottom-right'
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
<YourAppContent />
|
|
53
|
-
<GeniusToggle />
|
|
54
|
-
</GeniusChatbotProvider>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 2. Programmatic Control
|
|
60
|
-
|
|
61
|
-
Use the `useGeniusChatbot` hook for programmatic control:
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
import { useGeniusChatbot } from 'cosmic-ai-genius';
|
|
65
|
-
|
|
66
|
-
function MyComponent() {
|
|
67
|
-
const { openChatbot, closeChatbot, toggleChatbot, isOpen } = useGeniusChatbot();
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<div>
|
|
71
|
-
<button onClick={openChatbot}>Open Chat</button>
|
|
72
|
-
<button onClick={toggleChatbot}>Toggle Chat</button>
|
|
73
|
-
<p>Chat is {isOpen ? 'open' : 'closed'}</p>
|
|
74
|
-
</div>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Components
|
|
80
|
-
|
|
81
|
-
### GeniusChatbotProvider
|
|
82
|
-
|
|
83
|
-
The main provider component that manages chatbot state and configuration.
|
|
84
|
-
|
|
85
|
-
```tsx
|
|
86
|
-
<GeniusChatbotProvider
|
|
87
|
-
config={{
|
|
88
|
-
// API Configuration
|
|
89
|
-
apiKey: "your-api-key",
|
|
90
|
-
apiEndpoint: "https://your-api.com/chat",
|
|
91
|
-
|
|
92
|
-
// UI Customization
|
|
93
|
-
welcomeMessage: "Welcome to Cosmic AI Genius!",
|
|
94
|
-
placeholder: "Type your message...",
|
|
95
|
-
suggestions: ['FAQ', 'Pricing', 'Contact'],
|
|
96
|
-
|
|
97
|
-
// Positioning & Theming
|
|
98
|
-
position: 'bottom-right',
|
|
99
|
-
width: 440,
|
|
100
|
-
height: 680,
|
|
101
|
-
theme: {
|
|
102
|
-
primaryColor: '#1b85ff',
|
|
103
|
-
backgroundColor: '#ffffff'
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
// Event Handlers
|
|
107
|
-
onMessage: (message) => console.log('New message:', message),
|
|
108
|
-
onClose: () => console.log('Chatbot closed'),
|
|
109
|
-
onExpand: () => console.log('Chatbot expanded')
|
|
110
|
-
}}
|
|
111
|
-
defaultOpen={false}
|
|
112
|
-
>
|
|
113
|
-
{children}
|
|
114
|
-
</GeniusChatbotProvider>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### GeniusChatbot
|
|
118
|
-
|
|
119
|
-
The main chatbot interface component (automatically rendered by provider):
|
|
120
|
-
|
|
121
|
-
```tsx
|
|
122
|
-
// Rendered automatically when chatbot is open
|
|
123
|
-
// Features:
|
|
124
|
-
// - Expandable interface (50% screen width on desktop)
|
|
125
|
-
// - Voice call integration
|
|
126
|
-
// - Message history
|
|
127
|
-
// - Suggested replies
|
|
128
|
-
// - Mobile responsive design
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### GeniusToggle
|
|
132
|
-
|
|
133
|
-
A floating toggle button to open the chatbot:
|
|
134
|
-
|
|
135
|
-
```tsx
|
|
136
|
-
<GeniusToggle
|
|
137
|
-
position="bottom-right" // 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
|
|
138
|
-
offsetX={20} // Horizontal offset from edge
|
|
139
|
-
offsetY={20} // Vertical offset from edge
|
|
140
|
-
/>
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### VoiceCall
|
|
144
|
-
|
|
145
|
-
Voice call interface component (automatically shown when voice is activated):
|
|
146
|
-
|
|
147
|
-
```tsx
|
|
148
|
-
// Activated when waveform icon is clicked
|
|
149
|
-
// Features:
|
|
150
|
-
// - Animated waveform visualization
|
|
151
|
-
// - Microphone and end call controls
|
|
152
|
-
// - Compact floating design
|
|
153
|
-
// - Smooth transitions
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Configuration Options
|
|
157
|
-
|
|
158
|
-
### GeniusChatbotConfig
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
interface GeniusChatbotConfig {
|
|
162
|
-
// API Settings
|
|
163
|
-
apiKey?: string;
|
|
164
|
-
baseUrl?: string; // Base URL for backend (e.g., 'https://api.example.com')
|
|
165
|
-
endpoints?: { // Custom endpoints (optional)
|
|
166
|
-
chat?: string; // Non-streaming chat endpoint
|
|
167
|
-
stream?: string; // Streaming chat endpoint
|
|
168
|
-
};
|
|
169
|
-
useStreaming?: boolean; // Enable real-time streaming responses
|
|
170
|
-
|
|
171
|
-
// Content
|
|
172
|
-
welcomeMessage?: string;
|
|
173
|
-
placeholder?: string;
|
|
174
|
-
suggestions?: string[];
|
|
175
|
-
|
|
176
|
-
// Layout
|
|
177
|
-
position?: 'bottom-right' | 'bottom-left' | 'center';
|
|
178
|
-
width?: number;
|
|
179
|
-
height?: number;
|
|
180
|
-
|
|
181
|
-
// Theming
|
|
182
|
-
theme?: {
|
|
183
|
-
primaryColor?: string;
|
|
184
|
-
backgroundColor?: string;
|
|
185
|
-
textColor?: string;
|
|
186
|
-
borderRadius?: number;
|
|
187
|
-
fontFamily?: string;
|
|
188
|
-
[key: string]: any;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// Event Handlers
|
|
192
|
-
onMessage?: (message: Message) => void;
|
|
193
|
-
onClose?: () => void;
|
|
194
|
-
onExpand?: () => void;
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### Message Interface
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
interface Message {
|
|
202
|
-
id: string;
|
|
203
|
-
content: string;
|
|
204
|
-
role: 'user' | 'assistant';
|
|
205
|
-
timestamp: Date;
|
|
206
|
-
sources?: GroundingChunk[]; // Optional source citations
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
interface GroundingChunk {
|
|
210
|
-
text: string;
|
|
211
|
-
title: string;
|
|
212
|
-
uri: string;
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## Backend Integration
|
|
217
|
-
|
|
218
|
-
The SDK supports integration with AI backends, including the provided Python FastAPI server with Google Gemini and RAG support.
|
|
219
|
-
|
|
220
|
-
### Quick Backend Setup
|
|
221
|
-
|
|
222
|
-
1. **Start the backend server** (see `/backend/README.md` for details):
|
|
223
|
-
```bash
|
|
224
|
-
cd backend
|
|
225
|
-
./run.sh
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
2. **Configure the SDK with backend URL**:
|
|
229
|
-
```tsx
|
|
230
|
-
<GeniusChatbotProvider
|
|
231
|
-
config={{
|
|
232
|
-
baseUrl: 'http://localhost:8001',
|
|
233
|
-
useStreaming: true, // Enable real-time responses
|
|
234
|
-
}}
|
|
235
|
-
>
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Backend Configuration Options
|
|
239
|
-
|
|
240
|
-
```tsx
|
|
241
|
-
// Option 1: Simple base URL (recommended)
|
|
242
|
-
config={{
|
|
243
|
-
baseUrl: 'https://api.example.com',
|
|
244
|
-
// SDK will append /chat and /chat/stream
|
|
245
|
-
}}
|
|
246
|
-
|
|
247
|
-
// Option 2: Custom endpoints
|
|
248
|
-
config={{
|
|
249
|
-
endpoints: {
|
|
250
|
-
chat: 'https://api.example.com/v1/chat',
|
|
251
|
-
stream: 'https://streaming.example.com/sse'
|
|
252
|
-
}
|
|
253
|
-
}}
|
|
254
|
-
|
|
255
|
-
// Option 3: Mix and match
|
|
256
|
-
config={{
|
|
257
|
-
baseUrl: 'https://api.example.com',
|
|
258
|
-
endpoints: {
|
|
259
|
-
stream: 'https://fast-stream.example.com/chat'
|
|
260
|
-
}
|
|
261
|
-
}}
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
## Advanced Usage
|
|
265
|
-
|
|
266
|
-
### Custom API Integration
|
|
267
|
-
|
|
268
|
-
```tsx
|
|
269
|
-
<GeniusChatbotProvider
|
|
270
|
-
config={{
|
|
271
|
-
baseUrl: "https://your-api.com",
|
|
272
|
-
apiKey: "your-secret-key",
|
|
273
|
-
useStreaming: true,
|
|
274
|
-
onMessage: async (message) => {
|
|
275
|
-
// Custom message handling
|
|
276
|
-
console.log('User sent:', message.content);
|
|
277
|
-
|
|
278
|
-
// Send to your analytics
|
|
279
|
-
analytics.track('chat_message_sent', {
|
|
280
|
-
content: message.content,
|
|
281
|
-
timestamp: message.timestamp
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}}
|
|
285
|
-
>
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### Custom Theming
|
|
289
|
-
|
|
290
|
-
```tsx
|
|
291
|
-
<GeniusChatbotProvider
|
|
292
|
-
config={{
|
|
293
|
-
theme: {
|
|
294
|
-
// Override CSS custom properties
|
|
295
|
-
'--genius-primary-blue': '#your-brand-color',
|
|
296
|
-
'--genius-background': '#f8f9fa',
|
|
297
|
-
'--genius-text-primary': '#1a1a1a',
|
|
298
|
-
'--genius-border-radius': '16px',
|
|
299
|
-
fontFamily: 'Inter, sans-serif'
|
|
300
|
-
}
|
|
301
|
-
}}
|
|
302
|
-
>
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Multiple Chatbot Instances
|
|
306
|
-
|
|
307
|
-
```tsx
|
|
308
|
-
// You can have multiple chatbot providers for different contexts
|
|
309
|
-
function App() {
|
|
310
|
-
return (
|
|
311
|
-
<div>
|
|
312
|
-
{/* Support chatbot */}
|
|
313
|
-
<GeniusChatbotProvider config={{
|
|
314
|
-
welcomeMessage: "Need help? I'm here to assist!",
|
|
315
|
-
position: 'bottom-right'
|
|
316
|
-
}}>
|
|
317
|
-
<SupportSection />
|
|
318
|
-
<GeniusToggle />
|
|
319
|
-
</GeniusChatbotProvider>
|
|
320
|
-
|
|
321
|
-
{/* Sales chatbot */}
|
|
322
|
-
<GeniusChatbotProvider config={{
|
|
323
|
-
welcomeMessage: "Interested in our products?",
|
|
324
|
-
position: 'bottom-left'
|
|
325
|
-
}}>
|
|
326
|
-
<SalesSection />
|
|
327
|
-
<GeniusToggle position="bottom-left" />
|
|
328
|
-
</GeniusChatbotProvider>
|
|
329
|
-
</div>
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### Voice Call Integration
|
|
335
|
-
|
|
336
|
-
The voice call feature is automatically available when using the chatbot:
|
|
337
|
-
|
|
338
|
-
1. **Activation**: Click the waveform icon when no text is entered
|
|
339
|
-
2. **Interface**: Shows compact voice call UI with animated waveform
|
|
340
|
-
3. **Controls**: Microphone status and end call button
|
|
341
|
-
4. **Exit**: Click end call button to return to chat interface
|
|
342
|
-
|
|
343
|
-
```tsx
|
|
344
|
-
// Voice call is automatically integrated
|
|
345
|
-
// No additional setup required
|
|
346
|
-
// Activated by clicking waveform icon in chat input
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## Responsive Behavior
|
|
350
|
-
|
|
351
|
-
### Desktop
|
|
352
|
-
- Default size: 440px × 680px
|
|
353
|
-
- Expandable to 50% screen width
|
|
354
|
-
- Floating position with shadows
|
|
355
|
-
|
|
356
|
-
### Mobile
|
|
357
|
-
- Full screen overlay
|
|
358
|
-
- Auto-collapse when expanded
|
|
359
|
-
- Hide expand/collapse buttons
|
|
360
|
-
- Touch-optimized interface
|
|
361
|
-
|
|
362
|
-
### Tablet
|
|
363
|
-
- Responsive sizing between mobile and desktop
|
|
364
|
-
- Optimized button sizes and spacing
|
|
365
|
-
|
|
366
|
-
## Events & Callbacks
|
|
367
|
-
|
|
368
|
-
### Message Events
|
|
369
|
-
|
|
370
|
-
```tsx
|
|
371
|
-
const handleMessage = (message: Message) => {
|
|
372
|
-
console.log('New message:', message);
|
|
373
|
-
|
|
374
|
-
// Send to analytics
|
|
375
|
-
if (message.role === 'user') {
|
|
376
|
-
analytics.track('user_message', { content: message.content });
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
<GeniusChatbotProvider config={{ onMessage: handleMessage }} />
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
### Lifecycle Events
|
|
384
|
-
|
|
385
|
-
```tsx
|
|
386
|
-
const config = {
|
|
387
|
-
onClose: () => {
|
|
388
|
-
console.log('Chatbot closed');
|
|
389
|
-
// Save conversation state
|
|
390
|
-
},
|
|
391
|
-
|
|
392
|
-
onExpand: () => {
|
|
393
|
-
console.log('Chatbot expanded');
|
|
394
|
-
// Track engagement
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
## Styling & Customization
|
|
400
|
-
|
|
401
|
-
### CSS Custom Properties
|
|
402
|
-
|
|
403
|
-
The SDK uses CSS custom properties for easy theming:
|
|
404
|
-
|
|
405
|
-
```css
|
|
406
|
-
:root {
|
|
407
|
-
--genius-primary-blue: #1B85FF;
|
|
408
|
-
--genius-grey-600: #8A8A8E;
|
|
409
|
-
--genius-grey-500: #9C9C9F;
|
|
410
|
-
--genius-grey-200: #E0E0E0;
|
|
411
|
-
--genius-grey-100: #EDEDED;
|
|
412
|
-
--genius-text-primary: #1c1c1c;
|
|
413
|
-
--genius-text-secondary: #5f5f5f;
|
|
414
|
-
--genius-white: #ffffff;
|
|
415
|
-
--genius-background: #fcfcfc;
|
|
416
|
-
}
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Override Styles
|
|
420
|
-
|
|
421
|
-
```css
|
|
422
|
-
/* Custom styles for your application */
|
|
423
|
-
.genius-chatbot-container {
|
|
424
|
-
border-radius: 20px !important;
|
|
425
|
-
box-shadow: 0 20px 40px rgba(0,0,0,0.1) !important;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
.genius-chatbot-send-button {
|
|
429
|
-
background: linear-gradient(45deg, #ff6b6b, #4ecdc4) !important;
|
|
430
|
-
}
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
## TypeScript Support
|
|
434
|
-
|
|
435
|
-
The SDK is fully typed with TypeScript. Import types as needed:
|
|
436
|
-
|
|
437
|
-
```typescript
|
|
438
|
-
import type {
|
|
439
|
-
GeniusChatbotConfig,
|
|
440
|
-
Message,
|
|
441
|
-
GeniusChatbotContextType
|
|
442
|
-
} from 'cosmic-ai-genius';
|
|
443
|
-
|
|
444
|
-
const config: GeniusChatbotConfig = {
|
|
445
|
-
welcomeMessage: "Hello!",
|
|
446
|
-
suggestions: ["Help", "Info"]
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
const handleMessage = (message: Message) => {
|
|
450
|
-
// Fully typed message object
|
|
451
|
-
console.log(message.content, message.role, message.timestamp);
|
|
452
|
-
};
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
## Browser Support
|
|
456
|
-
|
|
457
|
-
- ✅ Chrome 90+
|
|
458
|
-
- ✅ Firefox 88+
|
|
459
|
-
- ✅ Safari 14+
|
|
460
|
-
- ✅ Edge 90+
|
|
461
|
-
- ✅ Mobile browsers (iOS Safari, Chrome Mobile)
|
|
462
|
-
|
|
463
|
-
## Performance
|
|
464
|
-
|
|
465
|
-
- **Bundle size**: ~45KB gzipped
|
|
466
|
-
- **Runtime**: Lightweight React components
|
|
467
|
-
- **Memory**: Efficient state management
|
|
468
|
-
- **Animations**: Hardware-accelerated CSS animations
|
|
469
|
-
|
|
470
|
-
## Development
|
|
471
|
-
|
|
472
|
-
### Local Development
|
|
473
|
-
|
|
474
|
-
1. **Clone the repository:**
|
|
475
|
-
```bash
|
|
476
|
-
git clone https://github.com/cosmic-ai/genius-sdk.git
|
|
477
|
-
cd genius-sdk
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
2. **Install dependencies:**
|
|
481
|
-
```bash
|
|
482
|
-
npm install
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
3. **Start development server:**
|
|
486
|
-
```bash
|
|
487
|
-
npm run dev
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
4. **Build the SDK:**
|
|
491
|
-
```bash
|
|
492
|
-
npm run build:sdk
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
### Publishing Updates
|
|
496
|
-
|
|
497
|
-
1. **Update version:**
|
|
498
|
-
```bash
|
|
499
|
-
npm version patch # or minor/major
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
2. **Build and publish:**
|
|
503
|
-
```bash
|
|
504
|
-
npm run build:sdk
|
|
505
|
-
npm publish
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
## Troubleshooting
|
|
509
|
-
|
|
510
|
-
### Common Issues
|
|
511
|
-
|
|
512
|
-
1. **Chatbot not appearing**
|
|
513
|
-
```tsx
|
|
514
|
-
// Ensure you're using the provider
|
|
515
|
-
<GeniusChatbotProvider>
|
|
516
|
-
<YourApp />
|
|
517
|
-
</GeniusChatbotProvider>
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
2. **Styling conflicts**
|
|
521
|
-
```css
|
|
522
|
-
/* Use more specific selectors */
|
|
523
|
-
.your-app .genius-chatbot-container {
|
|
524
|
-
/* Your overrides */
|
|
525
|
-
}
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
3. **TypeScript errors**
|
|
529
|
-
```tsx
|
|
530
|
-
// Import types explicitly
|
|
531
|
-
import type { GeniusChatbotConfig } from 'cosmic-ai-genius';
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
4. **Installation issues**
|
|
535
|
-
```bash
|
|
536
|
-
# Clear cache and reinstall
|
|
537
|
-
npm cache clean --force
|
|
538
|
-
npm install cosmic-ai-genius
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
### Debug Mode
|
|
542
|
-
|
|
543
|
-
Enable debug logging:
|
|
544
|
-
|
|
545
|
-
```tsx
|
|
546
|
-
<GeniusChatbotProvider
|
|
547
|
-
config={{
|
|
548
|
-
debug: true, // Enable console logs
|
|
549
|
-
onMessage: (msg) => console.log('Debug:', msg)
|
|
550
|
-
}}
|
|
551
|
-
/>
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
## ReScript Integration
|
|
555
|
-
|
|
556
|
-
The SDK can be used with ReScript by creating bindings:
|
|
557
|
-
|
|
558
|
-
### 1. Create SDK bindings (`GeniusSDK.res`):
|
|
559
|
-
|
|
560
|
-
```rescript
|
|
561
|
-
module GeniusChatbotProvider = {
|
|
562
|
-
@module("cosmic-ai-genius") @react.component
|
|
563
|
-
external make: (
|
|
564
|
-
~config: GeniusConfig.t,
|
|
565
|
-
~defaultOpen: bool=?,
|
|
566
|
-
~children: React.element
|
|
567
|
-
) => React.element = "GeniusChatbotProvider"
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
module GeniusToggle = {
|
|
571
|
-
@module("cosmic-ai-genius") @react.component
|
|
572
|
-
external make: (
|
|
573
|
-
~position: [#"bottom-right" | #"bottom-left" | #"top-right" | #"top-left"]=?,
|
|
574
|
-
~offsetX: int=?,
|
|
575
|
-
~offsetY: int=?
|
|
576
|
-
) => React.element = "GeniusToggle"
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
@module("cosmic-ai-genius")
|
|
580
|
-
external useGeniusChatbot: unit => {
|
|
581
|
-
"openChatbot": unit => unit,
|
|
582
|
-
"closeChatbot": unit => unit,
|
|
583
|
-
"toggleChatbot": unit => unit,
|
|
584
|
-
"isOpen": bool
|
|
585
|
-
} = "useGeniusChatbot"
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
### 2. Define configuration types (`GeniusConfig.res`):
|
|
589
|
-
|
|
590
|
-
```rescript
|
|
591
|
-
type theme = {
|
|
592
|
-
primaryColor?: string,
|
|
593
|
-
backgroundColor?: string,
|
|
594
|
-
textColor?: string,
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
type endpoints = {
|
|
598
|
-
chat?: string,
|
|
599
|
-
stream?: string,
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
type message = {
|
|
603
|
-
id: string,
|
|
604
|
-
content: string,
|
|
605
|
-
role: [#user | #assistant],
|
|
606
|
-
timestamp: Js.Date.t,
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
type t = {
|
|
610
|
-
apiKey?: string,
|
|
611
|
-
baseUrl?: string,
|
|
612
|
-
endpoints?: endpoints,
|
|
613
|
-
welcomeMessage?: string,
|
|
614
|
-
placeholder?: string,
|
|
615
|
-
suggestions?: array<string>,
|
|
616
|
-
position?: [#"bottom-right" | #"bottom-left" | #center],
|
|
617
|
-
useStreaming?: bool,
|
|
618
|
-
onMessage?: message => unit,
|
|
619
|
-
onClose?: unit => unit,
|
|
620
|
-
onExpand?: unit => unit,
|
|
621
|
-
}
|
|
622
|
-
```
|
|
623
|
-
|
|
624
|
-
### 3. Use in your app:
|
|
625
|
-
|
|
626
|
-
```rescript
|
|
627
|
-
@react.component
|
|
628
|
-
let make = () => {
|
|
629
|
-
let config = {
|
|
630
|
-
GeniusConfig.welcomeMessage: Some("How can I help you?"),
|
|
631
|
-
suggestions: Some(["Question 1", "Question 2"]),
|
|
632
|
-
baseUrl: Some("http://localhost:8001"),
|
|
633
|
-
useStreaming: Some(true),
|
|
634
|
-
// ... other fields
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
<GeniusSDK.GeniusChatbotProvider config defaultOpen=false>
|
|
638
|
-
<div className="app">
|
|
639
|
-
<YourAppContent />
|
|
640
|
-
<GeniusSDK.GeniusToggle />
|
|
641
|
-
</div>
|
|
642
|
-
</GeniusSDK.GeniusChatbotProvider>
|
|
643
|
-
}
|
|
644
|
-
```
|
|
645
|
-
|
|
646
|
-
## Examples
|
|
647
|
-
|
|
648
|
-
Check out the `/src/App.tsx` file in this repository for a complete working example with all features demonstrated.
|
|
649
|
-
|
|
650
|
-
## Contributing
|
|
651
|
-
|
|
652
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
653
|
-
|
|
654
|
-
## License
|
|
655
|
-
|
|
656
|
-
MIT License - see [LICENSE](LICENSE) file for details.
|
|
657
|
-
|
|
658
|
-
Made with ❤️ by the Cosmic AI Team
|
|
7
|
+
(c) Cosmic AI Team
|
package/package.json
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cosmic-ai-genius",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A powerful, customizable AI chatbot SDK for React applications with voice capabilities and modern UI design",
|
|
7
|
-
"keywords": [
|
|
8
|
-
"react",
|
|
9
|
-
"chatbot",
|
|
10
|
-
"ai",
|
|
11
|
-
"voice",
|
|
12
|
-
"typescript",
|
|
13
|
-
"sdk",
|
|
14
|
-
"cosmic",
|
|
15
|
-
"genius",
|
|
16
|
-
"conversational-ai"
|
|
17
|
-
],
|
|
18
7
|
"author": {
|
|
19
8
|
"name": "Cosmic AI Team",
|
|
20
9
|
"email": "support@cosmicai.com"
|