@revrag-ai/embed-react-native 1.0.7 → 1.0.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 CHANGED
@@ -1,33 +1,381 @@
1
1
  # @revrag-ai/embed-react-native
2
2
 
3
- voice agent library
3
+ A powerful React Native library for integrating AI-powered voice agents into your mobile applications. This SDK provides real-time voice communication capabilities with intelligent speech processing, perfect for building conversational AI experiences.
4
4
 
5
- ## Installation
5
+ ## 🚀 Features
6
+
7
+ - **AI Voice Agent Integration**: Seamlessly integrate intelligent voice agents into your React Native app
8
+ - **Real-time Voice Communication**: High-quality, low-latency voice chat powered by LiveKit
9
+ - **Voice Activity Detection**: Automatic speech detection and processing
10
+ - **Customizable UI Components**: Pre-built, customizable voice interface components
11
+ - **Cross-platform**: Works on both iOS and Android
12
+ - **TypeScript Support**: Full TypeScript definitions included
13
+ - **Event System**: Comprehensive event handling for voice interactions
14
+ - **Audio Visualization**: Built-in waveform visualization for voice activity
15
+
16
+ ## 📦 Installation
6
17
 
7
18
  ```sh
8
19
  npm install @revrag-ai/embed-react-native
9
20
  ```
10
21
 
11
- ## Usage
22
+ ### Peer Dependencies
23
+
24
+ Make sure to install the required peer dependencies:
25
+
26
+ ```sh
27
+ npm install @livekit/react-native @livekit/react-native-webrtc @react-native-async-storage/async-storage lottie-react-native react-native-gesture-handler react-native-linear-gradient react-native-reanimated react-native-safe-area-context
28
+ ```
29
+
30
+ ### iOS Setup
31
+
32
+ Add the following to your `ios/YourApp/Info.plist`:
33
+
34
+ ```xml
35
+ <key>NSMicrophoneUsageDescription</key>
36
+ <string>This app needs microphone access for voice communication</string>
37
+ ```
38
+
39
+ ### Android Setup
40
+
41
+ Add the following permissions to your `android/app/src/main/AndroidManifest.xml`:
42
+
43
+ ```xml
44
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
45
+ <uses-permission android:name="android.permission.INTERNET" />
46
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
47
+ ```
48
+
49
+ ## 🎯 Quick Start
50
+
51
+ ### 1. Initialize the SDK
52
+
53
+ Wrap your app with the initialization hook:
54
+
55
+ ```tsx
56
+ import React from 'react';
57
+ import { useInitialize } from '@revrag-ai/embed-react-native';
58
+
59
+ export default function App() {
60
+ useInitialize({
61
+ apiKey: 'your-api-key-here',
62
+ embedUrl: 'https://your-voice-agent-server.com',
63
+ });
64
+
65
+ return <YourAppContent />;
66
+ }
67
+ ```
68
+
69
+ ### 2. Add the Voice Button
70
+
71
+ Add the voice interface component to your screen:
72
+
73
+ ```tsx
74
+ import React from 'react';
75
+ import { View } from 'react-native';
76
+ import { EmbedButton } from '@revrag-ai/embed-react-native';
77
+
78
+ export default function HomeScreen() {
79
+ return (
80
+ <View style={{ flex: 1 }}>
81
+ {/* Your app content */}
82
+
83
+ {/* Voice agent button - floats over content */}
84
+ <EmbedButton />
85
+ </View>
86
+ );
87
+ }
88
+ ```
89
+
90
+ ### 3. Handle Voice Events (Optional)
91
+
92
+ Listen to voice agent events for custom handling:
93
+
94
+ ```tsx
95
+ import React, { useEffect } from 'react';
96
+ import { Embed, EmbedEventKeys } from '@revrag-ai/embed-react-native';
97
+
98
+ export default function VoiceEnabledScreen() {
99
+ useEffect(() => {
100
+ // Listen for user data events
101
+ Embed.on(EmbedEventKeys.USER_DATA, (data) => {
102
+ console.log('User data received:', data);
103
+ });
104
+
105
+ // Listen for screen state events
106
+ Embed.on(EmbedEventKeys.SCREEN_STATE, (state) => {
107
+ console.log('Screen state changed:', state);
108
+ });
109
+ }, []);
110
+
111
+ return (
112
+ // Your component JSX
113
+ );
114
+ }
115
+ ```
116
+
117
+ ## 📖 API Reference
118
+
119
+ ### `useInitialize(props: UseInitializeProps)`
120
+
121
+ Initializes the voice agent SDK with your configuration.
122
+
123
+ #### Parameters
124
+
125
+ | Parameter | Type | Required | Description |
126
+ |-----------|------|----------|-------------|
127
+ | `apiKey` | `string` | ✅ | Your unique API key from RevRag AI |
128
+ | `embedUrl` | `string` | ✅ | The voice agent server URL |
129
+
130
+ #### Example
131
+
132
+ ```tsx
133
+ useInitialize({
134
+ apiKey: 'key_abc123',
135
+ embedUrl: 'https://api.revrag.ai',
136
+ });
137
+ ```
138
+
139
+ ### `<EmbedButton />`
140
+
141
+ A floating action button that provides the voice interface.
142
+
143
+ #### Features
144
+
145
+ - **Draggable**: Users can drag the button around the screen
146
+ - **Expandable**: Expands to show voice controls when active
147
+ - **Auto-opening**: Automatically prompts users after 15 seconds
148
+ - **Visual Feedback**: Shows connection status and audio visualization
149
+ - **Customizable**: Supports custom styling
150
+
151
+ #### Example
152
+
153
+ ```tsx
154
+ import { EmbedButton } from '@revrag-ai/embed-react-native';
155
+
156
+ // Basic usage
157
+ <EmbedButton />
158
+
159
+ // The button automatically handles:
160
+ // - Voice agent connection
161
+ // - Microphone permissions
162
+ // - Audio recording and playback
163
+ // - Call management
164
+ ```
165
+
166
+ ### `useVoiceAgent()`
167
+
168
+ Hook for advanced voice agent control and state management.
169
+
170
+ #### Returns
171
+
172
+ | Property | Type | Description |
173
+ |----------|------|-------------|
174
+ | `initializeVoiceAgent` | `() => Promise<void>` | Manually initialize voice connection |
175
+ | `isLoading` | `boolean` | Connection loading state |
176
+ | `error` | `string \| null` | Current error message |
177
+ | `tokenDetails` | `TokenDetails` | Authentication token information |
178
+ | `endCall` | `() => Promise<void>` | End the current voice session |
179
+ | `room` | `Room` | LiveKit room instance |
180
+ | `roomRef` | `RefObject<Room>` | Room reference for advanced usage |
181
+ | `isMicMuted` | `boolean` | Microphone mute state |
182
+ | `muteMic` | `() => void` | Mute the microphone |
183
+ | `unmuteMic` | `() => void` | Unmute the microphone |
184
+ | `connectionState` | `ConnectionState` | Current connection status |
185
+ | `cleanup` | `() => void` | Clean up resources |
186
+
187
+ #### Example
188
+
189
+ ```tsx
190
+ import { useVoiceAgent } from '@revrag-ai/embed-react-native';
191
+
192
+ function CustomVoiceInterface() {
193
+ const {
194
+ initializeVoiceAgent,
195
+ endCall,
196
+ isMicMuted,
197
+ muteMic,
198
+ unmuteMic,
199
+ connectionState,
200
+ isLoading
201
+ } = useVoiceAgent();
202
+
203
+ const handleStartCall = async () => {
204
+ try {
205
+ await initializeVoiceAgent();
206
+ } catch (error) {
207
+ console.error('Failed to start call:', error);
208
+ }
209
+ };
210
+
211
+ return (
212
+ <View>
213
+ <Button
214
+ title={connectionState === 'connected' ? 'End Call' : 'Start Call'}
215
+ onPress={connectionState === 'connected' ? endCall : handleStartCall}
216
+ disabled={isLoading}
217
+ />
218
+
219
+ {connectionState === 'connected' && (
220
+ <Button
221
+ title={isMicMuted ? 'Unmute' : 'Mute'}
222
+ onPress={isMicMuted ? unmuteMic : muteMic}
223
+ />
224
+ )}
225
+
226
+ <Text>Status: {connectionState}</Text>
227
+ </View>
228
+ );
229
+ }
230
+ ```
231
+
232
+ ### Event System
233
+
234
+ The library provides an event system for handling voice agent interactions.
235
+
236
+ #### `Embed.on(eventKey: EmbedEventKeys, callback: Function)`
237
+
238
+ Listen to voice agent events.
239
+
240
+ #### `Embed.Event(eventKey: string, data: any)`
241
+
242
+ Send custom events to the voice agent.
243
+
244
+ #### Event Types
245
+
246
+ ```tsx
247
+ enum EmbedEventKeys {
248
+ USER_DATA = 'user_data',
249
+ SCREEN_STATE = 'state_data'
250
+ }
251
+ ```
252
+
253
+ #### Example
254
+
255
+ ```tsx
256
+ import { Embed, EmbedEventKeys } from '@revrag-ai/embed-react-native';
257
+
258
+ // Listen for events
259
+ Embed.on(EmbedEventKeys.USER_DATA, (userData) => {
260
+ console.log('Received user data:', userData);
261
+ // Handle user data updates
262
+ });
263
+
264
+ // Send events
265
+ await Embed.Event('custom_event', {
266
+ action: 'page_view',
267
+ page: 'profile',
268
+ timestamp: Date.now()
269
+ });
270
+ ```
12
271
 
272
+ ## 🎨 Customization
13
273
 
14
- ```js
15
- import { multiply } from '@revrag-ai/embed-react-native';
274
+ ### Styling the Voice Button
16
275
 
17
- // ...
276
+ The `EmbedButton` component comes with built-in styling but can be customized through the configuration metadata:
18
277
 
19
- const result = multiply(3, 7);
278
+ ```tsx
279
+ useInitialize({
280
+ apiKey: 'your-api-key',
281
+ embedUrl: 'your-server-url',
282
+ });
20
283
  ```
21
284
 
285
+ ## 🔧 Advanced Usage
22
286
 
23
- ## Contributing
287
+ ### Context Data Management
288
+
289
+ Provide rich context to your voice agent for more intelligent conversations:
290
+
291
+ ```tsx
292
+ const contextData = {
293
+ user: {
294
+ id: 'U123456',
295
+ name: 'John Doe',
296
+ accountDetails: {
297
+ balance: 1500.50,
298
+ lastTransaction: '2024-01-15',
299
+ accountType: 'premium'
300
+ }
301
+ },
302
+ currentScreen: 'dashboard',
303
+ availableActions: ['transfer', 'balance_inquiry', 'transaction_history']
304
+ };
305
+
306
+ useInitialize({
307
+ apiKey: 'your-api-key',
308
+ embedUrl: 'your-server-url',
309
+ });
310
+ ```
311
+
312
+ ### Error Handling
313
+
314
+ ```tsx
315
+ import { useVoiceAgent } from '@revrag-ai/embed-react-native';
316
+
317
+ function VoiceComponent() {
318
+ const { error, initializeVoiceAgent } = useVoiceAgent();
319
+
320
+ useEffect(() => {
321
+ if (error) {
322
+ console.error('Voice agent error:', error);
323
+ // Handle error - show user message, retry logic, etc.
324
+ }
325
+ }, [error]);
326
+
327
+ // Rest of component...
328
+ }
329
+ ```
330
+
331
+ ## 🛠 Troubleshooting
332
+
333
+ ### Common Issues
334
+
335
+ 1. **Microphone Permission Denied**
336
+ - Ensure you've added the microphone permission to your platform-specific config files
337
+ - Check that users have granted microphone permission
338
+
339
+ 2. **Connection Issues**
340
+ - Verify your API key is correct
341
+ - Ensure the `embedUrl` is accessible from your app
342
+ - Check network connectivity
343
+
344
+ 3. **Audio Not Working**
345
+ - Test on a physical device (audio may not work in simulators)
346
+ - Verify audio output settings
347
+ - Check that other apps can use the microphone
348
+
349
+ ### Debug Mode
350
+
351
+ Enable detailed logging for debugging:
352
+
353
+ ```tsx
354
+ // Add this before initializing
355
+ console.log('Voice Agent Debug Mode Enabled');
356
+
357
+ useInitialize({
358
+ apiKey: 'your-api-key',
359
+ embedUrl: 'your-server-url',
360
+ });
361
+ ```
362
+
363
+ ## 📱 Platform Support
364
+
365
+ - **iOS**: 12.0+
366
+ - **Android**: API level 21+ (Android 5.0)
367
+ - **React Native**: 0.70+
368
+
369
+ ## 🤝 Contributing
24
370
 
25
371
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
26
372
 
27
- ## License
373
+ ## 📄 License
28
374
 
29
375
  MIT
30
376
 
31
377
  ---
32
378
 
33
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
379
+ **Made with ❤️ by [RevRag AI](https://www.revrag.ai)**
380
+
381
+ For support, visit our [documentation](https://docs.revrag.ai) or contact us at [contact@revrag.ai](mailto:contact@revrag.ai).
@@ -33,8 +33,8 @@ class APIService {
33
33
  }
34
34
  const AgentData = await (0, _storeKey.getAgentData)();
35
35
  console.log('AgentData', AgentData);
36
- if (AgentData?.onwidUrl) {
37
- this.apiBaseUrl = AgentData.onwidUrl;
36
+ if (AgentData?.embedUrl) {
37
+ this.apiBaseUrl = AgentData.embedUrl;
38
38
  this.isInitialized = true;
39
39
  console.log('API_BASE_URL initialized:', this.apiBaseUrl);
40
40
  } else {
@@ -14,8 +14,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
14
14
  *
15
15
  * Required Parameters:
16
16
  * - apiKey: string - Unique identifier for the user
17
- * - deviceId: string - Unique identifier for the device
18
- * - metadata: object - Additional device/user information
19
17
  *
20
18
  * The initialization process:
21
19
  * 1. Validates required input parameters
@@ -25,8 +23,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
25
23
 
26
24
  function useInitialize({
27
25
  apiKey,
28
- onwidUrl,
29
- metadata
26
+ embedUrl
30
27
  }) {
31
28
  const checkPermissions = async () => {
32
29
  try {
@@ -57,11 +54,8 @@ function useInitialize({
57
54
  if (!apiKey || typeof apiKey !== 'string') {
58
55
  throw new Error('apiKey is required and must be a string');
59
56
  }
60
- if (!onwidUrl || typeof onwidUrl !== 'string') {
61
- throw new Error('onwidUrl is required and must be a string');
62
- }
63
- if (metadata && typeof metadata === 'object' && !metadata.config) {
64
- throw new Error('metadata must contain a config object');
57
+ if (!embedUrl || typeof embedUrl !== 'string') {
58
+ throw new Error('embedUrl is required and must be a string');
65
59
  }
66
60
  };
67
61
  const initialize = async () => {
@@ -75,7 +69,7 @@ function useInitialize({
75
69
  // Store API key in keychain
76
70
  await (0, _storeKey.setAgentData)({
77
71
  apiKey,
78
- onwidUrl
72
+ embedUrl
79
73
  });
80
74
 
81
75
  // Get the APIService instance and initialize it
@@ -30,8 +30,8 @@ export class APIService {
30
30
  }
31
31
  const AgentData = await getAgentData();
32
32
  console.log('AgentData', AgentData);
33
- if (AgentData?.onwidUrl) {
34
- this.apiBaseUrl = AgentData.onwidUrl;
33
+ if (AgentData?.embedUrl) {
34
+ this.apiBaseUrl = AgentData.embedUrl;
35
35
  this.isInitialized = true;
36
36
  console.log('API_BASE_URL initialized:', this.apiBaseUrl);
37
37
  } else {
@@ -5,8 +5,6 @@
5
5
  *
6
6
  * Required Parameters:
7
7
  * - apiKey: string - Unique identifier for the user
8
- * - deviceId: string - Unique identifier for the device
9
- * - metadata: object - Additional device/user information
10
8
  *
11
9
  * The initialization process:
12
10
  * 1. Validates required input parameters
@@ -19,8 +17,7 @@ import registerAgent from "./initialize.livekit.js";
19
17
  import { PermissionsAndroid, Platform } from 'react-native';
20
18
  export function useInitialize({
21
19
  apiKey,
22
- onwidUrl,
23
- metadata
20
+ embedUrl
24
21
  }) {
25
22
  const checkPermissions = async () => {
26
23
  try {
@@ -51,11 +48,8 @@ export function useInitialize({
51
48
  if (!apiKey || typeof apiKey !== 'string') {
52
49
  throw new Error('apiKey is required and must be a string');
53
50
  }
54
- if (!onwidUrl || typeof onwidUrl !== 'string') {
55
- throw new Error('onwidUrl is required and must be a string');
56
- }
57
- if (metadata && typeof metadata === 'object' && !metadata.config) {
58
- throw new Error('metadata must contain a config object');
51
+ if (!embedUrl || typeof embedUrl !== 'string') {
52
+ throw new Error('embedUrl is required and must be a string');
59
53
  }
60
54
  };
61
55
  const initialize = async () => {
@@ -69,7 +63,7 @@ export function useInitialize({
69
63
  // Store API key in keychain
70
64
  await setAgentData({
71
65
  apiKey,
72
- onwidUrl
66
+ embedUrl
73
67
  });
74
68
 
75
69
  // Get the APIService instance and initialize it
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@revrag-ai/embed-react-native",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "source": "./src/index.tsx",
5
- "description": "Voice Agent SDK for React Native - AI-powered voice communication with real-time speech processing",
5
+ "description": "A powerful React Native library for integrating AI-powered voice agents into mobile applications. Features real-time voice communication, intelligent speech processing, customizable UI components, and comprehensive event handling for building conversational AI experiences.",
6
6
  "main": "./lib/commonjs/index.js",
7
7
  "module": "./lib/module/index.js",
8
- "types": "./lib/typescript/commonjs/src/index.d.ts",
8
+ "types": "./lib/typescript/src/index.d.ts",
9
9
  "typesVersions": {
10
10
  "*": {
11
11
  "*": [
12
- "./lib/typescript/commonjs/src/*"
12
+ "./lib/typescript/src/*"
13
13
  ]
14
14
  }
15
15
  },
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./lib/typescript/commonjs/src/index.d.ts",
19
18
  "import": "./lib/module/index.js",
20
19
  "require": "./lib/commonjs/index.js",
21
20
  "default": "./lib/module/index.js"
@@ -62,7 +61,9 @@
62
61
  "protect": "node -e \"const crypto = require('crypto'); const fs = require('fs'); const config = { hash: crypto.randomBytes(32).toString('hex'), createdAt: new Date().toISOString(), note: 'Protected build', version: require('./package.json').version }; fs.writeFileSync('.onwid-security.json', JSON.stringify(config, null, 2)); console.log('✅ Code protected');\"",
63
62
  "publish:safe": "yarn clean && bob build && yarn fix-js && yarn protect && npm publish --access public",
64
63
  "publish:beta": "yarn clean && bob build && yarn fix-js && yarn protect && npm publish --access public --tag beta",
65
- "publish:alpha": "yarn clean && bob build && yarn fix-js && yarn protect && npm publish --access public --tag alpha"
64
+ "publish:alpha": "yarn clean && bob build && yarn fix-js && yarn protect && npm publish --access public --tag alpha",
65
+ "docs:check": "echo '📚 Documentation files:' && ls -la *.md && echo '✅ Documentation is up to date'",
66
+ "docs:validate": "echo '🔍 Validating documentation...' && node -e \"const fs = require('fs'); const files = ['README.md', 'API.md', 'EXAMPLES.md']; files.forEach(f => { if (!fs.existsSync(f)) throw new Error('Missing: ' + f); }); console.log('✅ All documentation files present');\""
66
67
  },
67
68
  "keywords": [
68
69
  "react-native",
@@ -220,8 +221,7 @@
220
221
  [
221
222
  "typescript",
222
223
  {
223
- "project": "tsconfig.build.json",
224
- "esm": true
224
+ "project": "tsconfig.build.json"
225
225
  }
226
226
  ]
227
227
  ]
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1 +0,0 @@
1
- {"type":"module"}