@cuekit-ai/react 1.1.0 → 1.2.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 CHANGED
@@ -1,22 +1,19 @@
1
1
  # @cuekit-ai/react
2
2
 
3
- A powerful React SDK for integrating AI-powered voice interactions into your web applications. Built with TypeScript and designed for seamless voice navigation, commands, and interactions.
3
+ A powerful React SDK for integrating AI-powered voice interactions into your web applications. Built with TypeScript and designed for seamless voice navigation, commands, and interactions with WebRTC support for real-time voice communication.
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/%40cuekit-ai%2Freact.svg)](https://badge.fury.io/js/%40cuekit-ai%2Freact)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
8
  ## 🚀 Features
9
9
 
10
- - **🎤 Voice Recognition**: Real-time speech-to-text with high accuracy
11
- - **🤖 AI-Powered Navigation**: Intelligent voice commands for app navigation
12
- - **🎯 Intent Recognition**: Understands user intent and performs actions
13
- - **🔊 Text-to-Speech**: Natural voice responses using ElevenLabs
14
- - **🎨 Beautiful UI**: Modern, animated voice assistant interface
15
- - **📱 Responsive Design**: Works seamlessly across all devices
16
- - **⚡ Real-time Processing**: Instant voice command processing
17
- - **🔄 State Management**: Robust state handling for voice interactions
18
- - **🎭 Portal Rendering**: Modal components render at document body level
19
- - **✨ Visual Feedback**: Border glow effects and animations
10
+ - **🎤 Real-time Voice Recognition**: High-accuracy, real-time speech-to-text powered by WebRTC.
11
+ - **🤖 AI-Powered Navigation**: Intelligent voice commands for seamless app navigation.
12
+ - **🎯 Intent Recognition**: Understands user intent to perform actions on your site.
13
+ - **🎨 Modern UI**: A beautiful, animated, and customizable voice assistant interface.
14
+ - **🌙 Theme Support**: Automatic light/dark theme detection, with the ability to override.
15
+ - **✍️ Text Input**: A built-in chat interface for text-based commands.
16
+ - **🔧 Customizable**: Easily customize the look and feel to match your brand.
20
17
 
21
18
  ## 📦 Installation
22
19
 
@@ -24,321 +21,201 @@ A powerful React SDK for integrating AI-powered voice interactions into your web
24
21
  npm install @cuekit-ai/react
25
22
  ```
26
23
 
27
- ```bash
28
- yarn add @cuekit-ai/react
29
- ```
24
+ After installation, you need to import the CSS file for styling:
30
25
 
31
- ```bash
32
- pnpm add @cuekit-ai/react
26
+ ```tsx
27
+ // In your main CSS file or a root component
28
+ import '@cuekit-ai/react/styles.css'
33
29
  ```
34
30
 
35
31
  ## 🎯 Quick Start
36
32
 
37
- ### 1. Wrap your app with CuekitProvider
33
+ Get up and running with CueKit in just two steps.
34
+
35
+ ### 1. Wrap Your App with `CuekitProvider`
36
+
37
+ The `CuekitProvider` initializes the SDK and provides the necessary context to all child components. You should wrap your application's root component with it.
38
38
 
39
39
  ```tsx
40
+ // Example for a React Router v6 application
40
41
  import { CuekitProvider } from '@cuekit-ai/react'
42
+ import { useNavigate } from 'react-router-dom'
41
43
 
42
44
  function App() {
45
+ const navigate = useNavigate()
46
+
47
+ const handleNavigation = (path, params) => {
48
+ navigate(path, { state: params })
49
+ }
50
+
43
51
  return (
44
- <CuekitProvider apiKey="your-api-key" appId="your-app-id" deviceId="optional-device-id">
45
- <YourApp />
52
+ <CuekitProvider apiKey="YOUR_API_KEY" appId="YOUR_APP_ID" navigationHandler={handleNavigation}>
53
+ {/* Your application components */}
46
54
  </CuekitProvider>
47
55
  )
48
56
  }
49
57
  ```
50
58
 
51
- ### 2. Add the MicButton component
59
+ ### 2. Add the `MicButton`
60
+
61
+ The `MicButton` is the main UI component for the voice assistant. It can be placed anywhere in your application, but it's best to place it in a layout component that's always visible.
52
62
 
53
63
  ```tsx
54
64
  import { MicButton } from '@cuekit-ai/react'
55
65
 
56
- function YourApp() {
66
+ function Layout({ children }) {
57
67
  return (
58
68
  <div>
59
- <h1>My Voice-Enabled App</h1>
60
- <MicButton
61
- screenPosition="bottom-right"
62
- buttonStyle={{
63
- backgroundColor: 'blue',
64
- borderRadius: '50%',
65
- }}
66
- />
69
+ {children}
70
+ <MicButton screenPosition="bottom-right" />
67
71
  </div>
68
72
  )
69
73
  }
70
74
  ```
71
75
 
72
- ## 🎨 Components
76
+ ## API Reference
73
77
 
74
- ### MicButton
78
+ ### `CuekitProvider`
75
79
 
76
- The main voice interaction component with a beautiful animated interface.
80
+ The main provider component that enables all CueKit functionality.
77
81
 
78
- ```tsx
79
- import { MicButton } from '@cuekit-ai/react'
80
- ;<MicButton
81
- screenPosition="bottom-right" // 'bottom-left' | 'bottom-center' | 'bottom-right'
82
- buttonStyle={
83
- {
84
- /* custom styles */
85
- }
86
- }
87
- buttonSize={60}
88
- hasText={false}
89
- text="Voice Assistant"
90
- textStyle={
91
- {
92
- /* text styles */
93
- }
94
- }
95
- imageSource="path/to/image.png"
96
- imageStyle={
97
- {
98
- /* image styles */
99
- }
100
- }
101
- />
102
- ```
103
-
104
- #### Props
105
-
106
- | Prop | Type | Default | Description |
107
- | ---------------- | ---------------------------------------------------- | ---------------- | ------------------------------------ |
108
- | `screenPosition` | `'bottom-left' \| 'bottom-center' \| 'bottom-right'` | `'bottom-right'` | Position of the mic button |
109
- | `buttonStyle` | `React.CSSProperties` | `{}` | Custom styles for the button |
110
- | `buttonSize` | `number` | `60` | Size of the button in pixels |
111
- | `hasText` | `boolean` | `false` | Whether to show text with the button |
112
- | `text` | `string` | `'CueKit VC'` | Text to display with the button |
113
- | `textStyle` | `React.CSSProperties` | `{}` | Styles for the text |
114
- | `imageSource` | `string` | `undefined` | Image source for the button |
115
- | `imageStyle` | `React.CSSProperties` | `{}` | Styles for the image |
116
-
117
- ### CuekitProvider
118
-
119
- The context provider that initializes the voice assistant.
120
-
121
- ```tsx
122
- import { CuekitProvider } from '@cuekit-ai/react'
123
- ;<CuekitProvider
124
- apiKey="your-api-key"
125
- appId="your-app-id"
126
- deviceId="optional-device-id"
127
- navigator={yourNavigator}
128
- >
129
- {children}
130
- </CuekitProvider>
131
- ```
82
+ | Prop | Type | Required | Description |
83
+ | ------------------------- | ------------------------------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------- |
84
+ | `apiKey` | `string` | ✅ | Your CueKit API key. |
85
+ | `appId` | `string` | | Your application ID. |
86
+ | `navigationHandler` | `(path: string, params?: Record<string, any>) => void` | ❌ | A function to handle navigation events. See [Routing Integration](#-routing-integration) for more details. |
87
+ | `onConnectionStateChange` | `(state: ConnectionState) => void` | ❌ | A callback for WebRTC connection state changes. |
88
+ | `onParticipantUpdate` | `(participants: string[]) => void` | ❌ | A callback for when the list of participants in the room changes. |
89
+ | `children` | `ReactNode` | ✅ | Your app components. |
132
90
 
133
- #### Props
91
+ ### `MicButton`
134
92
 
135
- | Prop | Type | Required | Description |
136
- | ----------- | ----------- | -------- | --------------------------------------------------------- |
137
- | `apiKey` | `string` | ✅ | Your CueKit API key |
138
- | `appId` | `string` | ✅ | Your application ID |
139
- | `deviceId` | `string` | ❌ | Unique device identifier (auto-generated if not provided) |
140
- | `navigator` | `any` | ❌ | Navigation object for routing |
141
- | `children` | `ReactNode` | ✅ | Your app components |
93
+ The main UI component for the voice assistant.
142
94
 
143
- ## 🔧 Hooks
95
+ | Prop | Type | Default | Description |
96
+ | ---------------- | ---------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------ |
97
+ | `screenPosition` | `'bottom-left' \| 'bottom-center' \| 'bottom-right'` | `'bottom-right'` | The position of the mic button on the screen. |
98
+ | `bottomSpace` | `number` | `20` | The distance of the button from the bottom of the screen, in pixels. |
99
+ | `buttonSize` | `number` | `52` | The size of the button, in pixels. |
100
+ | `defaultTheme` | `'light' \| 'dark' \| 'system'` | `'system'` | The default theme for the chat popup. `'system'` will auto-detect the user's system theme. |
101
+ | `buttonStyle` | `React.CSSProperties` | `{}` | Custom styles for the button. |
102
+ | `imageSource` | `string` | `undefined` | An image to display in the button instead of the default icon. |
103
+ | `imageStyle` | `React.CSSProperties` | `{}` | Custom styles for the image. |
104
+ | `showBorderGlow` | `boolean` | `false` | Whether to show an animated border glow around the button during active states. |
144
105
 
145
- ### useVoice
106
+ ### `useCuekit` Hook
146
107
 
147
- Hook for voice recognition and processing.
108
+ The `useCuekit` hook is the primary way to interact with the CueKit SDK. It provides all the necessary state and functions to build a custom voice experience.
148
109
 
149
110
  ```tsx
150
- import { useVoice } from '@cuekit-ai/react'
151
-
152
- function MyComponent() {
153
- const { isListening, start, stop, transcript } = useVoice()
154
-
155
- const handleVoiceStart = () => {
156
- start('Hello, how can I help you?')
157
- }
158
-
159
- const handleVoiceStop = () => {
160
- stop()
161
- }
162
-
163
- return (
164
- <div>
165
- <p>Listening: {isListening ? 'Yes' : 'No'}</p>
166
- <p>Transcript: {transcript}</p>
167
- <button onClick={handleVoiceStart}>Start Listening</button>
168
- <button onClick={handleVoiceStop}>Stop Listening</button>
169
- </div>
170
- )
111
+ import { useCuekit } from '@cuekit-ai/react'
112
+
113
+ function CustomVoiceComponent() {
114
+ const {
115
+ isConnected,
116
+ isConnecting,
117
+ error,
118
+ connect,
119
+ disconnect,
120
+ sendUserCommand,
121
+ messages,
122
+ micState,
123
+ status,
124
+ } = useCuekit()
125
+
126
+ // Your custom UI and logic here
171
127
  }
172
128
  ```
173
129
 
174
- ### useAudioController
130
+ **Return Values**:
175
131
 
176
- Hook for audio playback control.
132
+ | Property | Type | Description |
133
+ | ----------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------- |
134
+ | `isConnected` | `boolean` | Whether the SDK is currently connected to the CueKit backend. |
135
+ | `isConnecting` | `boolean` | Whether the SDK is currently attempting to connect. |
136
+ | `error` | `string \| null` | Any error that occurred during connection or operation. |
137
+ | `connect` | `(identity: string, apiKey?: string, appId?: string) => Promise<void>` | A function to connect to the CueKit backend. |
138
+ | `disconnect` | `() => Promise<void>` | A function to disconnect from the CueKit backend. |
139
+ | `sendUserCommand` | `(command: string) => Promise<void>` | A function to send a text command to the CueKit backend. |
140
+ | `messages` | `ChatMessage[]` | An array of chat messages. |
141
+ | `micState` | `'idle' \| 'listening' \| 'thinking' \| 'replying'` | The current state of the microphone. |
142
+ | `status` | `string` | A user-friendly status message. |
177
143
 
178
- ```tsx
179
- import { useAudioController } from '@cuekit-ai/react'
180
-
181
- function AudioComponent() {
182
- const { play, pause, stop, isPlaying } = useAudioController()
144
+ ## 🎨 Styling
183
145
 
184
- return (
185
- <div>
186
- <button onClick={play}>Play</button>
187
- <button onClick={pause}>Pause</button>
188
- <button onClick={stop}>Stop</button>
189
- <p>Playing: {isPlaying ? 'Yes' : 'No'}</p>
190
- </div>
191
- )
146
+ The SDK is styled with CSS variables, which makes it easy to customize the look and feel of the components.
147
+
148
+ ### CSS Variables
149
+
150
+ You can override the default values of these variables in your own CSS to match your brand.
151
+
152
+ ```css
153
+ /* Light theme (default) */
154
+ :root {
155
+ --voice-bg: 0 0% 100%;
156
+ --voice-surface: 0 0% 100%;
157
+ --voice-border: 214.3 31.8% 91.4%;
158
+ --voice-text: 222.2 84% 4.9%;
159
+ --voice-text-muted: 215.4 16.3% 46.9%;
160
+ --voice-accent: 200 98% 39%;
161
+ --voice-accent-light: 200 98% 95%;
162
+ --voice-user-bubble: 200 98% 39%;
163
+ --voice-user-text: 0 0% 100%;
164
+ --voice-ai-bubble: 0 0% 95%;
165
+ --voice-ai-text: 222.2 84% 4.9%;
192
166
  }
193
- ```
194
-
195
- ### useVoiceRecognition
196
-
197
- Hook for advanced voice recognition features.
198
-
199
- ```tsx
200
- import { useVoiceRecognition } from '@cuekit-ai/react'
201
167
 
202
- function VoiceRecognitionComponent() {
203
- const { isListening, transcript, startListening, stopListening, resetTranscript } =
204
- useVoiceRecognition()
205
-
206
- return (
207
- <div>
208
- <button onClick={startListening}>Start</button>
209
- <button onClick={stopListening}>Stop</button>
210
- <button onClick={resetTranscript}>Reset</button>
211
- <p>Transcript: {transcript}</p>
212
- </div>
213
- )
168
+ /* Dark theme */
169
+ .cuekit-dark {
170
+ --voice-bg: 211 32% 11%;
171
+ --voice-surface: 217.2 32.6% 17.5%;
172
+ --voice-border: 217.2 32.6% 17.5%;
173
+ --voice-text: 210 40% 98%;
174
+ --voice-text-muted: 215 20.2% 65.1%;
175
+ --voice-accent: 200 98% 60%;
176
+ --voice-accent-light: 200 98% 20%;
177
+ --voice-user-bubble: 200.12 80.39% 60%;
178
+ --voice-user-text: 0 0% 100%;
179
+ --voice-ai-bubble: 200.57 32.71% 20.98%;
180
+ --voice-ai-text: 0 0% 100%;
214
181
  }
215
182
  ```
216
183
 
217
- ## 🛠️ Utilities
184
+ ### Routing Integration
218
185
 
219
- ### processVoice
186
+ The SDK can integrate with your application's router via the `navigationHandler` prop on the `CuekitProvider`.
220
187
 
221
- Process voice commands and execute actions.
188
+ **React Router v6 Example**:
222
189
 
223
190
  ```tsx
224
- import { processVoice } from '@cuekit-ai/react'
191
+ import { useNavigate } from 'react-router-dom'
192
+ import { CuekitProvider } from '@cuekit-ai/react'
225
193
 
226
- const handleVoiceCommand = async (transcript: string) => {
227
- const result = await processVoice(transcript, apiKey, appId, deviceId)
194
+ function AppProviders({ children }) {
195
+ const navigate = useNavigate()
228
196
 
229
- if (result) {
230
- console.log('Voice command processed:', result)
231
- }
197
+ return (
198
+ <CuekitProvider
199
+ apiKey="YOUR_API_KEY"
200
+ appId="YOUR_APP_ID"
201
+ navigationHandler={(path, params) => {
202
+ navigate(path, { state: params })
203
+ }}
204
+ >
205
+ {children}
206
+ </CuekitProvider>
207
+ )
232
208
  }
233
209
  ```
234
210
 
235
- ### onStateChange
236
-
237
- Handle navigation state changes.
238
-
239
- ```tsx
240
- import { onStateChange } from '@cuekit-ai/react'
241
-
242
- // Automatically called by CuekitProvider
243
- // Handles route changes and voice command re-triggering
244
- ```
245
-
246
- ## 🎯 Voice Commands
247
-
248
- The SDK supports various voice commands for navigation and interaction:
249
-
250
- ### Navigation Commands
251
-
252
- - "Go to home"
253
- - "Navigate to settings"
254
- - "Open profile page"
255
- - "Go back"
256
-
257
- ### Action Commands
258
-
259
- - "Click the submit button"
260
- - "Press the login button"
261
- - "Select the first option"
262
- - "Scroll down"
263
-
264
- ### Information Commands
265
-
266
- - "What's on this page?"
267
- - "Tell me about this screen"
268
- - "What can I do here?"
269
-
270
- ## 🎨 Styling
271
-
272
- ### Custom Button Styling
273
-
274
- ```tsx
275
- <MicButton
276
- buttonStyle={{
277
- backgroundColor: 'linear-gradient(45deg, #667eea 0%, #764ba2 100%)',
278
- boxShadow: '0 4px 15px rgba(0, 0, 0, 0.2)',
279
- transform: 'scale(1.1)',
280
- }}
281
- />
282
- ```
283
-
284
- ### Custom Modal Styling
285
-
286
- The modal automatically adapts to your app's theme and provides:
287
-
288
- - Beautiful gradient backgrounds
289
- - Smooth animations
290
- - Responsive design
291
- - Accessibility features
292
-
293
- ```env
294
- CUEKIT_API_KEY=your-api-key
295
- CUEKIT_APP_ID=your-app-id
296
- CUEKIT_DEVICE_ID=optional-device-id
297
- ```
298
-
299
- ### API Configuration
300
-
301
- The SDK communicates with the CueKit API for:
302
-
303
- - Voice command processing
304
- - Intent recognition
305
- - Navigation handling
306
- - Text-to-speech synthesis
307
-
308
- ## 🔒 Security
309
-
310
- - All API calls are made over HTTPS
311
- - API keys are stored securely
312
- - No sensitive data is logged
313
- - Device IDs are anonymized
314
-
315
- ## 🚀 Performance
316
-
317
- - Lightweight bundle (~40KB gzipped)
318
- - Optimized for React 18+
319
- - Efficient re-rendering
320
- - Minimal memory footprint
321
-
322
211
  ## 🐛 Troubleshooting
323
212
 
324
- ### Common Issues
325
-
326
- 1. **Mic not working**
327
-
328
- - Check browser permissions
329
- - Ensure HTTPS connection
330
- - Verify API key is valid
331
-
332
- 2. **Voice commands not recognized**
333
-
334
- - Check internet connection
335
- - Verify app ID is correct
336
- - Ensure proper CuekitProvider setup
213
+ If you're having trouble, here are a few things to check:
337
214
 
338
- 3. **Modal not appearing**
339
- - Check z-index conflicts
340
- - Verify portal rendering
341
- - Ensure proper state management
215
+ - **Microphone Not Working**: Ensure that you've granted microphone permissions to your site. Also, the SDK requires a secure (HTTPS) connection to function.
216
+ - **Voice Commands Not Recognized**: Check your internet connection and ensure that you've provided a valid API key and app ID to the `CuekitProvider`.
217
+ - **Styling Issues**: Make sure you've imported the CSS file as described in the [Installation](#-installation) section.
218
+ - **WebRTC Connection Issues**: Check your browser's console for any error messages related to WebRTC. Ensure your network doesn't block the necessary ports.
342
219
 
343
220
  ---
344
221