@cuekit-ai/react 1.0.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 +289 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +1153 -0
- package/dist/index.mjs +1110 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# CueKit Web SDK
|
|
2
|
+
|
|
3
|
+
A powerful voice-controlled navigation and interaction SDK for React applications. CueKit enables users to navigate and interact with web applications using natural voice commands, providing an accessible and intuitive user experience.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **Voice Recognition**: Real-time speech-to-text using Web Speech API
|
|
8
|
+
- **Text-to-Speech**: Built-in TTS for audio feedback
|
|
9
|
+
- **Smart Navigation**: Automatic route detection and navigation
|
|
10
|
+
- **Element Interaction**: Click buttons and interact with UI elements via voice commands
|
|
11
|
+
- **Screen Context Awareness**: Captures and analyzes current screen elements
|
|
12
|
+
- **Cross-Platform**: Works with any React application (Next.js, Create React App, etc.)
|
|
13
|
+
- **Customizable UI**: Flexible microphone button with multiple positioning options
|
|
14
|
+
- **TypeScript Support**: Full TypeScript support with comprehensive type definitions
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install cuekit-web-sdk
|
|
20
|
+
# or
|
|
21
|
+
yarn add cuekit-web-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🏗️ Quick Start
|
|
25
|
+
|
|
26
|
+
### 1. Initialize CueKit
|
|
27
|
+
|
|
28
|
+
Wrap your app with the `CuekitProvider`:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { CuekitProvider } from 'cuekit-web-sdk'
|
|
32
|
+
|
|
33
|
+
function App() {
|
|
34
|
+
return (
|
|
35
|
+
<CuekitProvider apiKey="your-api-key" appId="your-app-id" deviceId="optional-device-id">
|
|
36
|
+
<YourApp />
|
|
37
|
+
</CuekitProvider>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Add Voice Control Button
|
|
43
|
+
|
|
44
|
+
Add the `MicButton` component to enable voice interactions:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { MicButton } from 'cuekit-web-sdk'
|
|
48
|
+
|
|
49
|
+
function YourApp() {
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
{/* Your app content */}
|
|
53
|
+
<MicButton screenPosition="bottom-right" buttonSize={60} hasText={false} />
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Initialize the SDK
|
|
60
|
+
|
|
61
|
+
Call `InitCuekit` with your API key:
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { InitCuekit } from 'cuekit-web-sdk'
|
|
65
|
+
|
|
66
|
+
// Initialize with API key
|
|
67
|
+
InitCuekit('your-api-key')
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🎯 Core Components
|
|
71
|
+
|
|
72
|
+
### CuekitProvider
|
|
73
|
+
|
|
74
|
+
The main provider component that sets up the voice control context.
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<CuekitProvider
|
|
78
|
+
apiKey="your-api-key"
|
|
79
|
+
appId="your-app-id"
|
|
80
|
+
deviceId="optional-device-id"
|
|
81
|
+
navigator={router} // Optional: Pass your router instance
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</CuekitProvider>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Props:**
|
|
88
|
+
|
|
89
|
+
- `apiKey` (required): Your CueKit API key
|
|
90
|
+
- `appId` (required): Your application ID
|
|
91
|
+
- `deviceId` (optional): Unique device identifier
|
|
92
|
+
- `navigator` (optional): Router instance for navigation
|
|
93
|
+
- `children`: React components to wrap
|
|
94
|
+
|
|
95
|
+
### MicButton
|
|
96
|
+
|
|
97
|
+
A customizable microphone button for voice input.
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
<MicButton
|
|
101
|
+
hasText={false}
|
|
102
|
+
text="Voice Control"
|
|
103
|
+
screenPosition="bottom-right"
|
|
104
|
+
buttonSize={60}
|
|
105
|
+
imageSource="path/to/mic-icon.png"
|
|
106
|
+
buttonStyle={{ backgroundColor: '#007bff' }}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Props:**
|
|
111
|
+
|
|
112
|
+
- `hasText` (optional): Show text instead of icon
|
|
113
|
+
- `text` (optional): Button text when `hasText` is true
|
|
114
|
+
- `textStyle` (optional): Custom styles for text
|
|
115
|
+
- `imageSource` (optional): Custom microphone icon URL
|
|
116
|
+
- `imageStyle` (optional): Custom styles for image
|
|
117
|
+
- `buttonStyle` (optional): Custom button styles
|
|
118
|
+
- `screenPosition` (optional): Button position (`'bottom-right'`, `'bottom-left'`, `'bottom-center'`)
|
|
119
|
+
- `buttonSize` (optional): Button size in pixels
|
|
120
|
+
|
|
121
|
+
## 🎤 Voice Recognition
|
|
122
|
+
|
|
123
|
+
### useVoice Hook
|
|
124
|
+
|
|
125
|
+
Custom hook for voice recognition functionality:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { useVoice } from 'cuekit-web-sdk'
|
|
129
|
+
|
|
130
|
+
function VoiceComponent() {
|
|
131
|
+
const { isListening, start, stop, transcript } = useVoice()
|
|
132
|
+
|
|
133
|
+
const handleVoiceToggle = async () => {
|
|
134
|
+
if (isListening) {
|
|
135
|
+
await stop()
|
|
136
|
+
} else {
|
|
137
|
+
await start('Hello, how can I help you?')
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return <button onClick={handleVoiceToggle}>{isListening ? 'Stop' : 'Start'} Voice</button>
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### useVoiceRecognition Hook
|
|
146
|
+
|
|
147
|
+
Lower-level hook for speech recognition:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { useVoiceRecognition } from 'cuekit-web-sdk'
|
|
151
|
+
|
|
152
|
+
function CustomVoiceComponent() {
|
|
153
|
+
const { isListening, startListening, stopListening, speechText } = useVoiceRecognition('en-US')
|
|
154
|
+
|
|
155
|
+
// Custom voice recognition logic
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 🔧 Advanced Usage
|
|
160
|
+
|
|
161
|
+
### Custom Voice Processing
|
|
162
|
+
|
|
163
|
+
Process voice input manually:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { processVoice } from 'cuekit-web-sdk'
|
|
167
|
+
|
|
168
|
+
const handleVoiceInput = async (transcript: string) => {
|
|
169
|
+
const result = await processVoice(transcript, 'your-api-key', 'your-app-id', 'device-id')
|
|
170
|
+
|
|
171
|
+
console.log('Voice processing result:', result)
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Audio Controller
|
|
176
|
+
|
|
177
|
+
Manage text-to-speech functionality:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import { useAudioController } from 'cuekit-web-sdk'
|
|
181
|
+
|
|
182
|
+
function AudioComponent() {
|
|
183
|
+
const { speak, stop, isSpeaking } = useAudioController()
|
|
184
|
+
|
|
185
|
+
const handleSpeak = () => {
|
|
186
|
+
speak('Hello, this is a test message')
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<div>
|
|
191
|
+
<button onClick={handleSpeak}>Speak</button>
|
|
192
|
+
<button onClick={stop}>Stop</button>
|
|
193
|
+
{isSpeaking && <span>Speaking...</span>}
|
|
194
|
+
</div>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Navigation Integration
|
|
200
|
+
|
|
201
|
+
For custom navigation handling:
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import { onStateChange } from 'cuekit-web-sdk'
|
|
205
|
+
|
|
206
|
+
// Call this when your app's route changes
|
|
207
|
+
onStateChange()
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## 🎨 Customization
|
|
211
|
+
|
|
212
|
+
### Styling the MicButton
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
<MicButton
|
|
216
|
+
buttonStyle={{
|
|
217
|
+
backgroundColor: '#ff6b6b',
|
|
218
|
+
boxShadow: '0 4px 12px rgba(0,0,0,0.3)',
|
|
219
|
+
border: '2px solid #fff',
|
|
220
|
+
}}
|
|
221
|
+
textStyle={{
|
|
222
|
+
fontSize: '16px',
|
|
223
|
+
fontWeight: 'bold',
|
|
224
|
+
color: '#fff',
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Custom Positioning
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
// Bottom right (default)
|
|
233
|
+
<MicButton screenPosition="bottom-right" />
|
|
234
|
+
|
|
235
|
+
// Bottom left
|
|
236
|
+
<MicButton screenPosition="bottom-left" />
|
|
237
|
+
|
|
238
|
+
// Bottom center
|
|
239
|
+
<MicButton screenPosition="bottom-center" />
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 🔌 API Integration
|
|
243
|
+
|
|
244
|
+
The SDK automatically sends component data to the CueKit API for intelligent voice processing. The API analyzes:
|
|
245
|
+
|
|
246
|
+
- Current screen elements (buttons, links, etc.)
|
|
247
|
+
- User voice input
|
|
248
|
+
- Screen context
|
|
249
|
+
- Navigation patterns
|
|
250
|
+
|
|
251
|
+
### API Response Format
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
interface CueKitResponse {
|
|
255
|
+
actionType: 'navigate' | 'click' | 'audio_only'
|
|
256
|
+
routeName?: string
|
|
257
|
+
component?: {
|
|
258
|
+
hash: string
|
|
259
|
+
text: string
|
|
260
|
+
componentType: string
|
|
261
|
+
}
|
|
262
|
+
text?: string
|
|
263
|
+
claudeError?: boolean
|
|
264
|
+
errorMessage?: string
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## 🔒 Security
|
|
269
|
+
|
|
270
|
+
- API keys are stored securely in the global context
|
|
271
|
+
- Device IDs are automatically generated and persisted
|
|
272
|
+
- Network requests are validated and error-handled
|
|
273
|
+
- No sensitive data is logged to console
|
|
274
|
+
|
|
275
|
+
## 🌐 Browser Support
|
|
276
|
+
|
|
277
|
+
- Chrome/Chromium (recommended)
|
|
278
|
+
- Firefox
|
|
279
|
+
- Safari (limited TTS support)
|
|
280
|
+
- Edge
|
|
281
|
+
|
|
282
|
+
**Note**: Voice recognition requires HTTPS in production environments.
|
|
283
|
+
|
|
284
|
+
## 📝 License
|
|
285
|
+
|
|
286
|
+
This project is licensed under the MIT License.
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
**CueKit Web SDK** - Making web applications voice-controlled and accessible.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
declare const processVoice: (transcript: string, apiKey?: string, appId?: string, deviceId?: string) => Promise<any | null>;
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface CueKitGlobalStore {
|
|
7
|
+
intent: string | null;
|
|
8
|
+
lastText: string;
|
|
9
|
+
lastClickedLabel: string;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
appId?: string;
|
|
12
|
+
deviceId?: string;
|
|
13
|
+
update: (data: Partial<CueKitGlobalStore>) => void;
|
|
14
|
+
}
|
|
15
|
+
var CuekitStore: CueKitGlobalStore;
|
|
16
|
+
}
|
|
17
|
+
type Props = {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
deviceId?: string;
|
|
20
|
+
appId: string;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
navigator?: any;
|
|
23
|
+
};
|
|
24
|
+
declare const CuekitProvider: React.FC<Props>;
|
|
25
|
+
|
|
26
|
+
declare const useAudioController: () => {
|
|
27
|
+
stop: () => void;
|
|
28
|
+
isPlaying: () => boolean;
|
|
29
|
+
play: (url: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
declare function onStateChange(): void;
|
|
33
|
+
|
|
34
|
+
type ScreenPosition = 'bottom-center' | 'bottom-left' | 'bottom-right';
|
|
35
|
+
type MicButtonProps = {
|
|
36
|
+
hasText?: boolean;
|
|
37
|
+
text?: string;
|
|
38
|
+
textStyle?: React.CSSProperties;
|
|
39
|
+
imageSource?: string;
|
|
40
|
+
imageStyle?: React.CSSProperties;
|
|
41
|
+
buttonStyle?: React.CSSProperties;
|
|
42
|
+
screenPosition?: ScreenPosition;
|
|
43
|
+
bottomSpace?: number;
|
|
44
|
+
buttonSize?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare const MicButton: React.FC<MicButtonProps>;
|
|
48
|
+
|
|
49
|
+
declare function InitCuekit(apiKey: string, navigator?: any): void;
|
|
50
|
+
|
|
51
|
+
declare const useVoiceRecognition: (lang?: string) => {
|
|
52
|
+
isListening: boolean;
|
|
53
|
+
startListening: () => Promise<string>;
|
|
54
|
+
stopListening: () => Promise<void>;
|
|
55
|
+
speechText: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { CuekitProvider, InitCuekit, MicButton, onStateChange, processVoice, useAudioController, useVoiceRecognition };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
declare const processVoice: (transcript: string, apiKey?: string, appId?: string, deviceId?: string) => Promise<any | null>;
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface CueKitGlobalStore {
|
|
7
|
+
intent: string | null;
|
|
8
|
+
lastText: string;
|
|
9
|
+
lastClickedLabel: string;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
appId?: string;
|
|
12
|
+
deviceId?: string;
|
|
13
|
+
update: (data: Partial<CueKitGlobalStore>) => void;
|
|
14
|
+
}
|
|
15
|
+
var CuekitStore: CueKitGlobalStore;
|
|
16
|
+
}
|
|
17
|
+
type Props = {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
deviceId?: string;
|
|
20
|
+
appId: string;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
navigator?: any;
|
|
23
|
+
};
|
|
24
|
+
declare const CuekitProvider: React.FC<Props>;
|
|
25
|
+
|
|
26
|
+
declare const useAudioController: () => {
|
|
27
|
+
stop: () => void;
|
|
28
|
+
isPlaying: () => boolean;
|
|
29
|
+
play: (url: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
declare function onStateChange(): void;
|
|
33
|
+
|
|
34
|
+
type ScreenPosition = 'bottom-center' | 'bottom-left' | 'bottom-right';
|
|
35
|
+
type MicButtonProps = {
|
|
36
|
+
hasText?: boolean;
|
|
37
|
+
text?: string;
|
|
38
|
+
textStyle?: React.CSSProperties;
|
|
39
|
+
imageSource?: string;
|
|
40
|
+
imageStyle?: React.CSSProperties;
|
|
41
|
+
buttonStyle?: React.CSSProperties;
|
|
42
|
+
screenPosition?: ScreenPosition;
|
|
43
|
+
bottomSpace?: number;
|
|
44
|
+
buttonSize?: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare const MicButton: React.FC<MicButtonProps>;
|
|
48
|
+
|
|
49
|
+
declare function InitCuekit(apiKey: string, navigator?: any): void;
|
|
50
|
+
|
|
51
|
+
declare const useVoiceRecognition: (lang?: string) => {
|
|
52
|
+
isListening: boolean;
|
|
53
|
+
startListening: () => Promise<string>;
|
|
54
|
+
stopListening: () => Promise<void>;
|
|
55
|
+
speechText: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { CuekitProvider, InitCuekit, MicButton, onStateChange, processVoice, useAudioController, useVoiceRecognition };
|