@cuekit-ai/react 1.1.2 → 1.2.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 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,183 +21,185 @@ 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
45
- apiKey="your-api-key"
46
- appId="your-app-id"
47
- deviceId="optional-device-id"
48
- navigationHandler={(path, params) => {
49
- const qs = params ? `?${new URLSearchParams(params).toString()}` : ''
50
- // Example with Next.js App Router
51
- router.push(`${path}${qs}`)
52
- // Or with React Router v6
53
- // navigate(`${path}${qs}`)
54
- }}
52
+ <CuekitProvider apiKey="YOUR_API_KEY" appId="YOUR_APP_ID" navigationHandler={handleNavigation}>
53
+ {/* Your application components */}
54
+ </CuekitProvider>
55
55
  )
56
56
  }
57
57
  ```
58
58
 
59
- ### 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.
60
62
 
61
63
  ```tsx
62
64
  import { MicButton } from '@cuekit-ai/react'
63
65
 
64
- function YourApp() {
66
+ function Layout({ children }) {
65
67
  return (
66
68
  <div>
67
- <h1>My Voice-Enabled App</h1>
68
- <MicButton
69
- screenPosition="bottom-right"
70
- buttonStyle={{
71
- backgroundColor: 'blue',
72
- borderRadius: '50%',
73
- }}
74
- />
69
+ {children}
70
+ <MicButton screenPosition="bottom-right" />
75
71
  </div>
76
72
  )
77
73
  }
78
74
  ```
79
75
 
80
- ## 🎨 Components
76
+ ## API Reference
81
77
 
82
- ### MicButton
78
+ ### `CuekitProvider`
83
79
 
84
- The main voice interaction component with a beautiful animated interface.
80
+ The main provider component that enables all CueKit functionality.
85
81
 
86
- ```tsx
87
- import { MicButton } from '@cuekit-ai/react'
88
- ;<MicButton
89
- screenPosition="bottom-right" // 'bottom-left' | 'bottom-center' | 'bottom-right'
90
- buttonStyle={
91
- {
92
- /* custom styles */
93
- }
94
- }
95
- buttonSize={60}
96
- hasText={false}
97
- text="Voice Assistant"
98
- textStyle={
99
- {
100
- /* text styles */
101
- }
102
- }
103
- imageSource="path/to/image.png"
104
- imageStyle={
105
- {
106
- /* image styles */
107
- }
108
- }
109
- />
110
- ```
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. |
111
90
 
112
- #### Props
91
+ ### `MicButton`
113
92
 
114
- | Prop | Type | Default | Description |
115
- | ---------------- | ---------------------------------------------------- | ---------------- | ------------------------------------ |
116
- | `screenPosition` | `'bottom-left' \| 'bottom-center' \| 'bottom-right'` | `'bottom-right'` | Position of the mic button |
117
- | `buttonStyle` | `React.CSSProperties` | `{}` | Custom styles for the button |
118
- | `buttonSize` | `number` | `60` | Size of the button in pixels |
119
- | `hasText` | `boolean` | `false` | Whether to show text with the button |
120
- | `text` | `string` | `'CueKit VC'` | Text to display with the button |
121
- | `textStyle` | `React.CSSProperties` | `{}` | Styles for the text |
122
- | `imageSource` | `string` | `undefined` | Image source for the button |
123
- | `imageStyle` | `React.CSSProperties` | `{}` | Styles for the image |
93
+ The main UI component for the voice assistant.
124
94
 
125
- ### CuekitProvider
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. |
126
105
 
127
- The context provider that initializes the voice assistant.
106
+ ### `useCuekit` Hook
128
107
 
129
- ```tsx
130
- import { CuekitProvider } from '@cuekit-ai/react'
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.
131
109
 
132
- ;<CuekitProvider
133
- apiKey="your-api-key"
134
- appId="your-app-id"
135
- deviceId="optional-device-id"
136
- navigationHandler={(path, params) => {
137
- const qs = params ? `?${new URLSearchParams(params).toString()}` : ''
138
- // Example with Next.js App Router
139
- router.push(`${path}${qs}`)
140
- // Or with React Router v6
141
- // navigate(`${path}${qs}`)
142
- }}
143
- >
144
- {children}
145
- </CuekitProvider>
110
+ ```tsx
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
127
+ }
146
128
  ```
147
129
 
148
- #### Props
130
+ **Return Values**:
149
131
 
150
- | Prop | Type | Required | Description |
151
- | ------------------- | ------------------------------------------------------ | -------- | -------------------------------------------------------------------------- |
152
- | `apiKey` | `string` | ✅ | Your CueKit API key |
153
- | `appId` | `string` | ✅ | Your application ID |
154
- | `deviceId` | `string` | ❌ | Unique device identifier (auto-generated if not provided) |
155
- | `navigationHandler` | `(path: string, params?: Record<string, any>) => void` | ❌ | Custom router handler. If not provided, falls back to internal navigation. |
156
- | `children` | `ReactNode` | | Your app components |
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. |
157
143
 
158
- ### Routing integration
159
-
160
- You can integrate your app's router by passing a `navigationHandler` to `CuekitProvider`.
161
-
162
- Next.js App Router example:
163
-
164
- ```tsx
165
- 'use client'
166
- import { useEffect } from 'react'
167
- import { useRouter } from 'next/navigation'
168
- import { CuekitProvider } from '@cuekit-ai/react'
144
+ ## 🎨 Styling
169
145
 
170
- export default function Providers({ children }: { children: React.ReactNode }) {
171
- const router = useRouter()
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%;
166
+ }
172
167
 
173
- return (
174
- <CuekitProvider
175
- apiKey={process.env.NEXT_PUBLIC_CUEKIT_API_KEY!}
176
- appId={process.env.NEXT_PUBLIC_CUEKIT_APP_ID!}
177
- navigationHandler={(path, params) => {
178
- const qs = params ? `?${new URLSearchParams(params).toString()}` : ''
179
- router.push(`${path}${qs}`)
180
- }}
181
- >
182
- {children}
183
- </CuekitProvider>
184
- )
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%;
185
181
  }
186
182
  ```
187
183
 
188
- React Router v6 example:
184
+ ### Routing Integration
185
+
186
+ The SDK can integrate with your application's router via the `navigationHandler` prop on the `CuekitProvider`.
187
+
188
+ **React Router v6 Example**:
189
189
 
190
190
  ```tsx
191
191
  import { useNavigate } from 'react-router-dom'
192
192
  import { CuekitProvider } from '@cuekit-ai/react'
193
193
 
194
- function AppProviders({ children }: { children: React.ReactNode }) {
194
+ function AppProviders({ children }) {
195
195
  const navigate = useNavigate()
196
196
 
197
197
  return (
198
198
  <CuekitProvider
199
- apiKey={import.meta.env.VITE_CUEKIT_API_KEY}
200
- appId={import.meta.env.VITE_CUEKIT_APP_ID}
199
+ apiKey="YOUR_API_KEY"
200
+ appId="YOUR_APP_ID"
201
201
  navigationHandler={(path, params) => {
202
- const qs = params ? `?${new URLSearchParams(params).toString()}` : ''
203
- navigate(`${path}${qs}`)
202
+ navigate(path, { state: params })
204
203
  }}
205
204
  >
206
205
  {children}
@@ -209,205 +208,13 @@ function AppProviders({ children }: { children: React.ReactNode }) {
209
208
  }
210
209
  ```
211
210
 
212
- ## 🔧 Hooks
213
-
214
- ### useVoice
215
-
216
- Hook for voice recognition and processing.
217
-
218
- ```tsx
219
- import { useVoice } from '@cuekit-ai/react'
220
-
221
- function MyComponent() {
222
- const { isListening, start, stop, transcript } = useVoice()
223
-
224
- const handleVoiceStart = () => {
225
- start('Hello, how can I help you?')
226
- }
227
-
228
- const handleVoiceStop = () => {
229
- stop()
230
- }
231
-
232
- return (
233
- <div>
234
- <p>Listening: {isListening ? 'Yes' : 'No'}</p>
235
- <p>Transcript: {transcript}</p>
236
- <button onClick={handleVoiceStart}>Start Listening</button>
237
- <button onClick={handleVoiceStop}>Stop Listening</button>
238
- </div>
239
- )
240
- }
241
- ```
242
-
243
- ### useAudioController
244
-
245
- Hook for audio playback control.
246
-
247
- ```tsx
248
- import { useAudioController } from '@cuekit-ai/react'
249
-
250
- function AudioComponent() {
251
- const { play, pause, stop, isPlaying } = useAudioController()
252
-
253
- return (
254
- <div>
255
- <button onClick={play}>Play</button>
256
- <button onClick={pause}>Pause</button>
257
- <button onClick={stop}>Stop</button>
258
- <p>Playing: {isPlaying ? 'Yes' : 'No'}</p>
259
- </div>
260
- )
261
- }
262
- ```
263
-
264
- ### useVoiceRecognition
265
-
266
- Hook for advanced voice recognition features.
267
-
268
- ```tsx
269
- import { useVoiceRecognition } from '@cuekit-ai/react'
270
-
271
- function VoiceRecognitionComponent() {
272
- const { isListening, transcript, startListening, stopListening, resetTranscript } =
273
- useVoiceRecognition()
274
-
275
- return (
276
- <div>
277
- <button onClick={startListening}>Start</button>
278
- <button onClick={stopListening}>Stop</button>
279
- <button onClick={resetTranscript}>Reset</button>
280
- <p>Transcript: {transcript}</p>
281
- </div>
282
- )
283
- }
284
- ```
285
-
286
- ## 🛠️ Utilities
287
-
288
- ### processVoice
289
-
290
- Process voice commands and execute actions.
291
-
292
- ```tsx
293
- import { processVoice } from '@cuekit-ai/react'
294
-
295
- const handleVoiceCommand = async (transcript: string) => {
296
- const result = await processVoice(transcript, apiKey, appId, deviceId)
297
-
298
- if (result) {
299
- console.log('Voice command processed:', result)
300
- }
301
- }
302
- ```
303
-
304
- ### onStateChange
305
-
306
- Handle navigation state changes.
307
-
308
- ```tsx
309
- import { onStateChange } from '@cuekit-ai/react'
310
-
311
- // Automatically called by CuekitProvider
312
- // Handles route changes and voice command re-triggering
313
- ```
314
-
315
- ## 🎯 Voice Commands
316
-
317
- The SDK supports various voice commands for navigation and interaction:
318
-
319
- ### Navigation Commands
320
-
321
- - "Go to home"
322
- - "Navigate to settings"
323
- - "Open profile page"
324
- - "Go back"
325
-
326
- ### Action Commands
327
-
328
- - "Click the submit button"
329
- - "Press the login button"
330
- - "Select the first option"
331
- - "Scroll down"
332
-
333
- ### Information Commands
334
-
335
- - "What's on this page?"
336
- - "Tell me about this screen"
337
- - "What can I do here?"
338
-
339
- ## 🎨 Styling
340
-
341
- ### Custom Button Styling
342
-
343
- ```tsx
344
- <MicButton
345
- buttonStyle={{
346
- backgroundColor: 'linear-gradient(45deg, #667eea 0%, #764ba2 100%)',
347
- boxShadow: '0 4px 15px rgba(0, 0, 0, 0.2)',
348
- transform: 'scale(1.1)',
349
- }}
350
- />
351
- ```
352
-
353
- ### Custom Modal Styling
354
-
355
- The modal automatically adapts to your app's theme and provides:
356
-
357
- - Beautiful gradient backgrounds
358
- - Smooth animations
359
- - Responsive design
360
- - Accessibility features
361
-
362
- ```env
363
- CUEKIT_API_KEY=your-api-key
364
- CUEKIT_APP_ID=your-app-id
365
- CUEKIT_DEVICE_ID=optional-device-id
366
- ```
367
-
368
- ### API Configuration
369
-
370
- The SDK communicates with the CueKit API for:
371
-
372
- - Voice command processing
373
- - Intent recognition
374
- - Navigation handling
375
- - Text-to-speech synthesis
376
-
377
- ## 🔒 Security
378
-
379
- - All API calls are made over HTTPS
380
- - API keys are stored securely
381
- - No sensitive data is logged
382
- - Device IDs are anonymized
383
-
384
- ## 🚀 Performance
385
-
386
- - Lightweight bundle (~40KB gzipped)
387
- - Optimized for React 18+
388
- - Efficient re-rendering
389
- - Minimal memory footprint
390
-
391
211
  ## 🐛 Troubleshooting
392
212
 
393
- ### Common Issues
394
-
395
- 1. **Mic not working**
396
-
397
- - Check browser permissions
398
- - Ensure HTTPS connection
399
- - Verify API key is valid
400
-
401
- 2. **Voice commands not recognized**
402
-
403
- - Check internet connection
404
- - Verify app ID is correct
405
- - Ensure proper CuekitProvider setup
213
+ If you're having trouble, here are a few things to check:
406
214
 
407
- 3. **Modal not appearing**
408
- - Check z-index conflicts
409
- - Verify portal rendering
410
- - 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.
411
218
 
412
219
  ---
413
220