@rapidaai/react 1.1.54 → 1.1.55

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,10 +1,17 @@
1
- ## Overview
1
+ # @rapidaai/react
2
2
 
3
- The `VoiceAgent` library provides a set of components, hooks, and utilities for integrating AI-powered voice assistants into applications. It supports real-time messaging, audio device management, and connection handling for seamless interaction.
3
+ The official React/TypeScript SDK for the [Rapida](https://rapida.ai) platform. Build real-time voice agents, make phone calls, manage assistants, knowledge bases, endpoints, conversations, and more all from your React application via gRPC.
4
4
 
5
- ## Installation
6
5
 
7
- To install the package, run:
6
+
7
+ [![Build and Publish](https://github.com/rapidaai/rapida-react/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/rapidaai/rapida-react/actions/workflows/npm-publish.yml)
8
+ [![Test](https://github.com/rapidaai/rapida-react/actions/workflows/test.yml/badge.svg)](https://github.com/rapidaai/rapida-react/actions/workflows/test.yml)
9
+ [![Twitter Follow](https://img.shields.io/twitter/follow/rapidaai)](https://twitter.com/rapidaai)
10
+ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/rapidaai/rapida-react)](https://github.com/rapidaai/voice-ai/releases/latest)
11
+
12
+ ---
13
+
14
+ ## Installation
8
15
 
9
16
  ```sh
10
17
  npm install @rapidaai/react@latest
@@ -16,80 +23,1112 @@ or using Yarn:
16
23
  yarn add @rapidaai/react@latest
17
24
  ```
18
25
 
19
- ## Usage Example
26
+ ### Peer Dependencies
27
+
28
+ ```json
29
+ {
30
+ "react": ">=16.8.0",
31
+ "react-dom": ">=16.8.0"
32
+ }
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Table of Contents
38
+
39
+ - [Connection Setup](#connection-setup)
40
+ - [Authentication](#authentication)
41
+ - [Assistants](#assistants)
42
+ - [Phone Calls](#phone-calls)
43
+ - [Voice Agent (Web)](#voice-agent-web)
44
+ - [Conversations](#conversations)
45
+ - [Knowledge Bases](#knowledge-bases)
46
+ - [Endpoints](#endpoints)
47
+ - [Projects & Organizations](#projects--organizations)
48
+ - [Vault (Provider Credentials)](#vault-provider-credentials)
49
+ - [Connectors](#connectors)
50
+ - [Activity Logs](#activity-logs)
51
+ - [Telemetry](#telemetry)
52
+ - [Notifications](#notifications)
53
+ - [Voice Agent Hooks Reference](#voice-agent-hooks-reference)
54
+ - [Voice Agent Components](#voice-agent-components)
55
+ - [Types & Configurations](#types--configurations)
56
+ - [Connection Modes](#connection-modes)
57
+ - [License](#license)
58
+
59
+ ---
60
+
61
+ ## Connection Setup
62
+
63
+ All SDK functions require a `ConnectionConfig` instance. Create one using an auth mode that fits your use case:
64
+
65
+ ```ts
66
+ import { ConnectionConfig } from "@rapidaai/react";
67
+
68
+ // Public / SDK access (API key)
69
+ const config = ConnectionConfig.DefaultConnectionConfig(
70
+ ConnectionConfig.WithSDK({
71
+ ApiKey: "{YOUR_API_KEY}",
72
+ UserId: "user-123",
73
+ })
74
+ );
75
+
76
+ // Authenticated user access
77
+ const config = ConnectionConfig.DefaultConnectionConfig(
78
+ ConnectionConfig.WithPersonalToken({
79
+ Authorization: "{JWT_TOKEN}",
80
+ AuthId: "{USER_ID}",
81
+ ProjectId: "{PROJECT_ID}",
82
+ })
83
+ );
84
+
85
+ // Debugger / internal testing
86
+ const config = ConnectionConfig.DefaultConnectionConfig(
87
+ ConnectionConfig.WithDebugger({
88
+ authorization: "{JWT_TOKEN}",
89
+ userId: "{USER_ID}",
90
+ projectId: "{PROJECT_ID}",
91
+ })
92
+ );
93
+ ```
94
+
95
+ ### Custom Endpoint (Self-Hosted)
96
+
97
+ ```ts
98
+ const config = ConnectionConfig.DefaultConnectionConfig(
99
+ ConnectionConfig.WithSDK({ ApiKey: "...", UserId: "..." })
100
+ ).withCustomEndpoint({
101
+ assistant: "https://your-assistant-api.example.com",
102
+ web: "https://your-web-api.example.com",
103
+ endpoint: "https://your-endpoint-api.example.com",
104
+ });
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Authentication
110
+
111
+ Authenticate users, manage passwords, and integrate social login.
112
+
113
+ ```ts
114
+ import {
115
+ AuthenticateUser,
116
+ AuthorizeUser,
117
+ RegisterUser,
118
+ VerifyToken,
119
+ ForgotPassword,
120
+ CreatePassword,
121
+ ChangePassword,
122
+ GetUser,
123
+ UpdateUser,
124
+ GetAllUser,
125
+ Google,
126
+ Linkedin,
127
+ Github,
128
+ } from "@rapidaai/react";
129
+ ```
130
+
131
+ ### Authenticate a User
132
+
133
+ ```ts
134
+ AuthenticateUser(config, "user@example.com", "password123", (err, response) => {
135
+ if (err) return console.error(err);
136
+ console.log("Token:", response.getToken());
137
+ });
138
+ ```
139
+
140
+ ### Register a New User
141
+
142
+ ```ts
143
+ RegisterUser(config, request, (err, response) => {
144
+ if (err) return console.error(err);
145
+ console.log("Registered:", response.getToken());
146
+ });
147
+ ```
148
+
149
+ ### Social Authentication
150
+
151
+ ```ts
152
+ // Google OAuth
153
+ Google(config, token, authHeader, (err, response) => {
154
+ console.log("Google auth:", response);
155
+ });
156
+
157
+ // LinkedIn OAuth
158
+ Linkedin(config, token, authHeader, (err, response) => {
159
+ console.log("LinkedIn auth:", response);
160
+ });
161
+
162
+ // GitHub OAuth
163
+ Github(config, token, authHeader, (err, response) => {
164
+ console.log("GitHub auth:", response);
165
+ });
166
+ ```
167
+
168
+ ### Password Management
169
+
170
+ ```ts
171
+ // Forgot password
172
+ ForgotPassword(config, email, (err, response) => { /* ... */ });
173
+
174
+ // Create new password (from reset link)
175
+ CreatePassword(config, request, (err, response) => { /* ... */ });
176
+
177
+ // Change password (authenticated)
178
+ ChangePassword(config, request, authHeader, (err, response) => { /* ... */ });
179
+ ```
180
+
181
+ ### User Management
182
+
183
+ ```ts
184
+ // Get user details
185
+ GetUser(config, userId, authHeader, (err, response) => { /* ... */ });
186
+
187
+ // Update user
188
+ UpdateUser(config, request, authHeader, (err, response) => { /* ... */ });
189
+
190
+ // List all users
191
+ GetAllUser(config, page, pageSize, criteria, (err, response) => { /* ... */ }, authHeader);
192
+ ```
193
+
194
+ ---
195
+
196
+ ## Assistants
197
+
198
+ Full CRUD for voice assistants, including deployments, webhooks, tools, knowledge associations, analysis, and providers.
199
+
200
+ ```ts
201
+ import {
202
+ GetAllAssistant,
203
+ GetAssistant,
204
+ CreateAssistant,
205
+ DeleteAssistant,
206
+ UpdateAssistantVersion,
207
+ UpdateAssistantDetail,
208
+ CreateAssistantTag,
209
+ GetAssistantMessages,
210
+ GetMessages,
211
+ GetAllAssistantConversationMessage,
212
+ GetAssistantConversation,
213
+ } from "@rapidaai/react";
214
+ ```
215
+
216
+ ### List Assistants
217
+
218
+ ```ts
219
+ GetAllAssistant(config, page, pageSize, criteria, (err, response) => {
220
+ if (err) return console.error(err);
221
+ const assistants = response.getAssistantsList();
222
+ assistants.forEach((a) => console.log(a.getName(), a.getId()));
223
+ }, authHeader);
224
+ ```
225
+
226
+ ### Get a Single Assistant
227
+
228
+ ```ts
229
+ const response = await GetAssistant(config, request, authHeader);
230
+ console.log(response.getAssistant()?.getName());
231
+ ```
232
+
233
+ ### Create an Assistant
234
+
235
+ ```ts
236
+ const response = await CreateAssistant(config, request, authHeader);
237
+ console.log("Created assistant:", response.getAssistant()?.getId());
238
+ ```
239
+
240
+ ### Update an Assistant
241
+
242
+ ```ts
243
+ // Update version (full configuration update)
244
+ const response = await UpdateAssistantVersion(config, request, authHeader);
245
+
246
+ // Update details (name, description, tags)
247
+ const response = await UpdateAssistantDetail(config, request, authHeader);
248
+ ```
249
+
250
+ ### Delete an Assistant
251
+
252
+ ```ts
253
+ const response = await DeleteAssistant(config, request, authHeader);
254
+ ```
255
+
256
+ ### Assistant Deployments
257
+
258
+ Create and manage deployments for different channels:
259
+
260
+ ```ts
261
+ import {
262
+ CreateAssistantDebuggerDeployment,
263
+ GetAssistantDebuggerDeployment,
264
+ CreateAssistantApiDeployment,
265
+ GetAssistantApiDeployment,
266
+ CreateAssistantWebpluginDeployment,
267
+ GetAssistantWebpluginDeployment,
268
+ CreateAssistantPhoneDeployment,
269
+ GetAssistantPhoneDeployment,
270
+ CreateAssistantWhatsappDeployment,
271
+ GetAssistantWhatsappDeployment,
272
+ } from "@rapidaai/react";
273
+
274
+ // Create a phone deployment
275
+ const response = await CreateAssistantPhoneDeployment(config, request, authHeader);
276
+
277
+ // Get debugger deployment
278
+ const response = await GetAssistantDebuggerDeployment(config, request, authHeader);
279
+ ```
280
+
281
+ ### Webhooks
282
+
283
+ ```ts
284
+ import {
285
+ GetAllAssistantWebhook,
286
+ CreateWebhook,
287
+ UpdateWebhook,
288
+ GetAssistantWebhook,
289
+ DeleteAssistantWebhook,
290
+ GetAllWebhookLog,
291
+ GetWebhookLog,
292
+ } from "@rapidaai/react";
293
+
294
+ // Create a webhook
295
+ const response = await CreateWebhook(config, request, authHeader);
296
+
297
+ // List webhook logs
298
+ GetAllWebhookLog(config, page, pageSize, criteria, (err, response) => {
299
+ console.log("Logs:", response.getLogsList());
300
+ }, authHeader);
301
+ ```
302
+
303
+ ### Tools
304
+
305
+ ```ts
306
+ import {
307
+ GetAllAssistantTool,
308
+ CreateAssistantTool,
309
+ UpdateAssistantTool,
310
+ GetAssistantTool,
311
+ DeleteAssistantTool,
312
+ GetAssistantToolLog,
313
+ GetAllAssistantToolLog,
314
+ } from "@rapidaai/react";
315
+
316
+ // Create a tool
317
+ const response = await CreateAssistantTool(config, request, authHeader);
318
+
319
+ // List tool logs
320
+ GetAllAssistantToolLog(config, page, pageSize, criteria, (err, response) => {
321
+ console.log("Tool logs:", response.getLogsList());
322
+ }, authHeader);
323
+ ```
324
+
325
+ ### Assistant Knowledge Associations
326
+
327
+ ```ts
328
+ import {
329
+ GetAllAssistantKnowledge,
330
+ CreateAssistantKnowledge,
331
+ UpdateAssistantKnowledge,
332
+ GetAssistantKnowledge,
333
+ DeleteAssistantKnowledge,
334
+ } from "@rapidaai/react";
335
+
336
+ // Link a knowledge base to an assistant
337
+ const response = await CreateAssistantKnowledge(config, request, authHeader);
338
+ ```
339
+
340
+ ### Analysis
341
+
342
+ ```ts
343
+ import {
344
+ GetAllAssistantAnalysis,
345
+ CreateAnalysis,
346
+ UpdateAnalysis,
347
+ GetAssistantAnalysis,
348
+ DeleteAssistantAnalysis,
349
+ } from "@rapidaai/react";
350
+
351
+ const response = await CreateAnalysis(config, request, authHeader);
352
+ ```
353
+
354
+ ### Providers
355
+
356
+ ```ts
357
+ import {
358
+ CreateAssistantProvider,
359
+ GetAllAssistantProvider,
360
+ } from "@rapidaai/react";
361
+
362
+ const response = await CreateAssistantProvider(config, request, authHeader);
363
+ ```
364
+
365
+ ---
366
+
367
+ ## Phone Calls
368
+
369
+ Initiate outbound phone calls and bulk calls via SIP/telephony.
370
+
371
+ ```ts
372
+ import {
373
+ CreatePhoneCall,
374
+ CreateBulkPhoneCall,
375
+ CreatePhoneCallRequest,
376
+ CreateBulkPhoneCallRequest,
377
+ } from "@rapidaai/react";
378
+ ```
379
+
380
+ ### Make a Phone Call
381
+
382
+ ```ts
383
+ const request = new CreatePhoneCallRequest();
384
+ request.setAssistantid("{ASSISTANT_ID}");
385
+ request.setPhonenumber("+1234567890");
386
+
387
+ const response = await CreatePhoneCall(config, request, authHeader);
388
+ console.log("Call initiated:", response.getConversationid());
389
+ ```
390
+
391
+ ### Make Bulk Phone Calls
392
+
393
+ ```ts
394
+ const request = new CreateBulkPhoneCallRequest();
395
+ request.setAssistantid("{ASSISTANT_ID}");
396
+ request.setPhonenumbersList(["+1234567890", "+0987654321"]);
397
+
398
+ const response = await CreateBulkPhoneCall(config, request, authHeader);
399
+ console.log("Bulk calls initiated:", response.getConversationidsList());
400
+ ```
401
+
402
+ ---
403
+
404
+ ## Voice Agent (Web)
405
+
406
+ Build real-time voice and text conversation agents with WebRTC + gRPC streaming, audio visualization, device management, and feedback hooks.
407
+
408
+ ### Quick Start
409
+
410
+ ```tsx
411
+ import {
412
+ VoiceAgent,
413
+ ConnectionConfig,
414
+ AgentConfig,
415
+ Channel,
416
+ InputOptions,
417
+ StringToAny,
418
+ } from "@rapidaai/react";
419
+
420
+ const agent = new VoiceAgent(
421
+ ConnectionConfig.DefaultConnectionConfig(
422
+ ConnectionConfig.WithSDK({
423
+ ApiKey: "{YOUR_API_KEY}",
424
+ UserId: "user-123",
425
+ })
426
+ ).withConnectionCallback({
427
+ onConnect: () => console.log("Connected"),
428
+ onDisconnect: () => console.log("Disconnected"),
429
+ onError: () => console.log("Connection error"),
430
+ }),
431
+
432
+ new AgentConfig(
433
+ "{ASSISTANT_ID}",
434
+ new InputOptions([Channel.Audio, Channel.Text], Channel.Text)
435
+ )
436
+ .addKeywords(["Rapida"])
437
+ .addArgument("name", "John")
438
+ .addMetadata("utm_source", StringToAny("landing_page")),
439
+
440
+ {
441
+ onAssistantMessage: (msg) => console.log("Assistant:", msg?.messageText),
442
+ onUserMessage: (msg) => console.log("User:", msg?.messageText),
443
+ onConfiguration: (cfg) => console.log("Config:", cfg),
444
+ onInterrupt: () => console.log("Interrupted"),
445
+ onInitialization: (init) => console.log("Session started:", init),
446
+ onDirective: (dir) => console.log("Directive:", dir),
447
+ }
448
+ );
449
+ ```
450
+
451
+ ### Full Voice Agent UI Example
452
+
453
+ A production-ready example showing connection, messaging, audio visualization, input mode toggling, mute controls, device selection, and message rendering.
454
+
455
+ #### 1. Create the Voice Agent Component
456
+
457
+ ```tsx
458
+ import React, { FC, useMemo, useState } from "react";
459
+ import {
460
+ VoiceAgent as VoiceAgentCore,
461
+ ConnectionConfig,
462
+ AgentConfig,
463
+ AgentCallback,
464
+ useConnectAgent,
465
+ useAgentMessages,
466
+ useInputModeToggleAgent,
467
+ useMuteAgent,
468
+ useMultibandMicrophoneTrackVolume,
469
+ useSelectInputDeviceAgent,
470
+ useMessageFeedback,
471
+ MultibandAudioVisualizerComponent,
472
+ Channel,
473
+ MessageRole,
474
+ MessageStatus,
475
+ Feedback,
476
+ } from "@rapidaai/react";
477
+
478
+ interface VoiceAgentProps {
479
+ connectConfig: ConnectionConfig;
480
+ agentConfig: AgentConfig;
481
+ agentCallback?: AgentCallback;
482
+ }
483
+
484
+ export const VoiceAgent: FC<VoiceAgentProps> = ({
485
+ connectConfig,
486
+ agentConfig,
487
+ agentCallback,
488
+ }) => {
489
+ const agent = useMemo(
490
+ () => new VoiceAgentCore(connectConfig, agentConfig, agentCallback),
491
+ [connectConfig, agentConfig, agentCallback]
492
+ );
493
+
494
+ return (
495
+ <div className="flex flex-col h-screen">
496
+ <ConversationMessages agent={agent} />
497
+ <MessagingControls agent={agent} />
498
+ </div>
499
+ );
500
+ };
501
+ ```
502
+
503
+ #### 2. Display Conversation Messages
504
+
505
+ ```tsx
506
+ const ConversationMessages: FC<{ agent: VoiceAgentCore }> = ({ agent }) => {
507
+ const { messages } = useAgentMessages(agent);
508
+ const { handleHelpfulnessFeedback } = useMessageFeedback(agent);
509
+
510
+ return (
511
+ <div className="flex-1 overflow-y-auto p-4 space-y-4">
512
+ {messages.map((msg) => (
513
+ <div
514
+ key={msg.id}
515
+ className={`flex ${
516
+ msg.role === MessageRole.User ? "justify-end" : "justify-start"
517
+ }`}
518
+ >
519
+ <div
520
+ className={`max-w-md px-4 py-2 rounded-lg ${
521
+ msg.role === MessageRole.User
522
+ ? "bg-blue-600 text-white"
523
+ : "bg-gray-100 text-gray-900"
524
+ }`}
525
+ >
526
+ {msg.messages.map((text, i) => (
527
+ <p key={i}>{text}</p>
528
+ ))}
529
+ {msg.status === MessageStatus.Pending && (
530
+ <span className="text-xs opacity-50">typing...</span>
531
+ )}
532
+ </div>
533
+
534
+ {msg.role === MessageRole.System && (
535
+ <div className="flex gap-1 ml-2">
536
+ <button
537
+ onClick={() =>
538
+ handleHelpfulnessFeedback(msg.id, Feedback.Helpful)
539
+ }
540
+ >
541
+ 👍
542
+ </button>
543
+ <button
544
+ onClick={() =>
545
+ handleHelpfulnessFeedback(msg.id, Feedback.NotHelpful)
546
+ }
547
+ >
548
+ 👎
549
+ </button>
550
+ </div>
551
+ )}
552
+ </div>
553
+ ))}
554
+ </div>
555
+ );
556
+ };
557
+ ```
558
+
559
+ #### 3. Build Messaging Controls (Text + Voice)
560
+
561
+ ```tsx
562
+ const MessagingControls: FC<{ agent: VoiceAgentCore }> = ({ agent }) => {
563
+ const [text, setText] = useState("");
564
+ const { handleConnectAgent, handleDisconnectAgent, isConnected, isConnecting } =
565
+ useConnectAgent(agent);
566
+ const { channel, handleTextToggle, handleVoiceToggle } =
567
+ useInputModeToggleAgent(agent);
568
+ const { isMuted, handleToggleMute } = useMuteAgent(agent);
569
+
570
+ const micVolume = useMultibandMicrophoneTrackVolume(agent, 5, 0.05, 0.85);
571
+
572
+ const { devices, activeDeviceId, setActiveMediaDevice } =
573
+ useSelectInputDeviceAgent({ voiceAgent: agent, requestPermissions: true });
574
+
575
+ const handleSendText = () => {
576
+ if (!text.trim()) return;
577
+ agent.onSendText(text);
578
+ setText("");
579
+ };
580
+
581
+ return (
582
+ <div className="border-t p-4">
583
+ <div className="flex gap-2 mb-3">
584
+ <button
585
+ onClick={handleTextToggle}
586
+ className={channel === Channel.Text ? "font-bold" : ""}
587
+ >
588
+ Text
589
+ </button>
590
+ <button
591
+ onClick={async () => {
592
+ await handleVoiceToggle();
593
+ if (!isConnected) await handleConnectAgent();
594
+ }}
595
+ className={channel === Channel.Audio ? "font-bold" : ""}
596
+ >
597
+ Voice
598
+ </button>
599
+ </div>
600
+
601
+ {channel === Channel.Text && (
602
+ <div className="flex gap-2">
603
+ <input
604
+ value={text}
605
+ onChange={(e) => setText(e.target.value)}
606
+ onKeyDown={(e) => e.key === "Enter" && handleSendText()}
607
+ placeholder="Type a message..."
608
+ className="flex-1 border rounded px-3 py-2"
609
+ />
610
+ <button onClick={handleSendText}>Send</button>
611
+ {!isConnected && (
612
+ <button onClick={handleConnectAgent} disabled={isConnecting}>
613
+ {isConnecting ? "Connecting..." : "Connect"}
614
+ </button>
615
+ )}
616
+ </div>
617
+ )}
618
+
619
+ {channel === Channel.Audio && isConnected && (
620
+ <div className="flex items-center gap-4">
621
+ <MultibandAudioVisualizerComponent
622
+ state={isMuted ? "disconnected" : "listening"}
623
+ barWidth={4}
624
+ minBarHeight={2}
625
+ maxBarHeight={40}
626
+ frequencies={micVolume}
627
+ />
628
+ <button onClick={handleToggleMute}>
629
+ {isMuted ? "Unmute" : "Mute"}
630
+ </button>
631
+ <select
632
+ value={activeDeviceId}
633
+ onChange={(e) => setActiveMediaDevice(e.target.value)}
634
+ >
635
+ {devices.map((d) => (
636
+ <option key={d.deviceId} value={d.deviceId}>
637
+ {d.label || "Unknown Device"}
638
+ </option>
639
+ ))}
640
+ </select>
641
+ <button onClick={handleDisconnectAgent}>Stop</button>
642
+ </div>
643
+ )}
644
+ </div>
645
+ );
646
+ };
647
+ ```
648
+
649
+ #### 4. Wire It Up
20
650
 
21
- Here's a minimal setup for initializing and using a `VoiceAgent`:
651
+ ```tsx
652
+ import { ConnectionConfig, AgentConfig, Channel, InputOptions, StringToAny } from "@rapidaai/react";
653
+ import { VoiceAgent } from "./voice-agent";
22
654
 
23
- ```ts
24
- import { VoiceAgent, ConnectionConfig, AgentConfig, Channel, InputOptions } from "@rapidaai/react";
25
- new VoiceAgent(
26
- ConnectionConfig.DefaultConnectionConfig(
655
+ function App() {
656
+ const connectConfig = ConnectionConfig.DefaultConnectionConfig(
27
657
  ConnectionConfig.WithSDK({
28
- ApiKey: "{API_KEY}",
29
- UserId: "random-user / identified-user",
658
+ ApiKey: "{YOUR_API_KEY}",
659
+ UserId: "user-123",
30
660
  })
31
- ).withConnectionCallback({
32
- onDisconnect: () => {
33
- // do what you want when finished
34
- console.log("disconnect");
35
- },
36
- onConnect() {
37
- console.log("connected");
38
- },
39
- onError() {
40
- console.log("error");
41
- },
42
- }),
43
- new AgentConfig(
44
- // replace this with actual agent id from rapida console
45
- "{AGENT_ID}",
46
- // you can select only Audio/ Text
661
+ );
662
+
663
+ const agentConfig = new AgentConfig(
664
+ "{ASSISTANT_ID}",
47
665
  new InputOptions([Channel.Audio, Channel.Text], Channel.Text)
48
- )
49
- .addKeywords([
50
- "dictionary - which you want the model to speak clearly",
51
- ])
52
- .addArgument("name", "<name>")
53
- .addMetadata("utm_1", StringToAny("utm_X")),
54
- {
55
- onAssistantMessage: (msg) => {
56
- console.log("onStart: ()");
57
- },
58
- onUserMessage: (args) => {
59
- console.log("onComplete:");
60
- },
61
- onConfiguration: (args) => {
62
- console.log("onTranscript");
63
- },
64
- onInterrupt: (args) => {
65
- console.log("onInterrupt");
66
- },
67
- onMessage: (args) => {
68
- console.log("onGeneration");
69
- },
70
- }
71
- )
72
- ```
73
-
74
- ## Available Exports
75
-
76
- The following components, hooks, and utilities are available for import:
77
-
78
- ### Types & Configurations
79
-
80
- - `Channel`: Defines communication channels.
81
- - `ConnectionConfig`: Configures the connection settings for a voice agent.
82
- - `AgentConfig`: Configures the agent settings, including parameters and keywords.
83
-
84
- ### Core
85
-
86
- - `VoiceAgent`: The core AI voice agent instance.
87
-
88
- ### Hooks
89
-
90
- - `useConnectAgent`: Establishes a connection to the voice agent.
91
- - `useAgentMessages`: Retrieves messages exchanged with the voice agent.
666
+ )
667
+ .setUserIdentifier("user-123", "John Doe")
668
+ .addKeywords(["Rapida"])
669
+ .addMetadata("source", StringToAny("web"));
670
+
671
+ return <VoiceAgent connectConfig={connectConfig} agentConfig={agentConfig} />;
672
+ }
673
+ ```
674
+
675
+ #### AgentConfig Methods
676
+
677
+ | Method | Description |
678
+ | --- | --- |
679
+ | `.addKeywords(string[])` | Add pronunciation keywords the model should speak clearly. |
680
+ | `.addArgument(key, value)` | Add a prompt variable argument (used in prompt templates). |
681
+ | `.addMetadata(key, Any)` | Attach metadata (e.g., tracking IDs, UTM params). |
682
+ | `.addCustomOption(key, Any)` | Add custom options (e.g., `listen.language`, `speak.language`). |
683
+ | `.setUserIdentifier(id, name?)` | Set the end-user's identity for conversation context. |
684
+
685
+ ---
686
+
687
+ ## Conversations
688
+
689
+ Manage assistant conversations, message/conversation metrics, and bidirectional talk streams.
690
+
691
+ ```ts
692
+ import {
693
+ AssistantTalk,
694
+ GetAllAssistantConversation,
695
+ CreateMessageMetric,
696
+ CreateConversationMetric,
697
+ GetAssistantConversation,
698
+ GetAllAssistantConversationMessage,
699
+ } from "@rapidaai/react";
700
+ ```
701
+
702
+ ### List Conversations
703
+
704
+ ```ts
705
+ GetAllAssistantConversation(config, page, pageSize, criteria, (err, response) => {
706
+ if (err) return console.error(err);
707
+ const conversations = response.getConversationsList();
708
+ conversations.forEach((c) => console.log(c.getId(), c.getStatus()));
709
+ }, authHeader);
710
+ ```
711
+
712
+ ### Get Conversation Details
713
+
714
+ ```ts
715
+ const response = await GetAssistantConversation(config, request, authHeader);
716
+ console.log("Conversation:", response.getConversation());
717
+ ```
718
+
719
+ ### Get Conversation Messages
720
+
721
+ ```ts
722
+ GetAllAssistantConversationMessage(config, page, pageSize, criteria, (err, response) => {
723
+ const messages = response.getMessagesList();
724
+ messages.forEach((m) => console.log(m.getRole(), m.getText()));
725
+ }, authHeader);
726
+ ```
727
+
728
+ ### Submit Message Feedback
729
+
730
+ ```ts
731
+ const response = await CreateMessageMetric(config, request, authHeader);
732
+ ```
733
+
734
+ ### Submit Conversation Feedback
735
+
736
+ ```ts
737
+ const response = await CreateConversationMetric(config, request, authHeader);
738
+ ```
739
+
740
+ ### Bidirectional Talk Stream
741
+
742
+ ```ts
743
+ const stream = AssistantTalk(config, authHeader);
744
+ // stream is a bidirectional gRPC stream for real-time conversation
745
+ ```
746
+
747
+ ---
748
+
749
+ ## Knowledge Bases
750
+
751
+ Create, manage, and index knowledge bases and their documents.
752
+
753
+ ```ts
754
+ import {
755
+ CreateKnowledge,
756
+ GetKnowledgeBase,
757
+ GetAllKnowledgeBases,
758
+ UpdateKnowledgeDetail,
759
+ CreateKnowledgeTag,
760
+ CreateKnowledgeDocument,
761
+ GetAllKnowledgeDocument,
762
+ GetAllKnowledgeDocumentSegment,
763
+ DeleteKnowledgeDocumentSegment,
764
+ UpdateKnowledgeDocumentSegment,
765
+ GetKnowledgeLog,
766
+ GetAllKnowledgeLog,
767
+ IndexKnowledgeDocument,
768
+ } from "@rapidaai/react";
769
+ ```
770
+
771
+ ### Create a Knowledge Base
772
+
773
+ ```ts
774
+ CreateKnowledge(config, providerModelId, providerId, name, description, tags, authHeader, (err, response) => {
775
+ if (err) return console.error(err);
776
+ console.log("Knowledge created:", response.getKnowledge()?.getId());
777
+ });
778
+ ```
779
+
780
+ ### Upload and Index Documents
781
+
782
+ ```ts
783
+ // Create a document in the knowledge base
784
+ CreateKnowledgeDocument(config, knowledgeId, documents, authHeader, (err, response) => {
785
+ console.log("Document uploaded:", response.getKnowledgedocumentsList());
786
+ });
787
+
788
+ // Index the document for search
789
+ IndexKnowledgeDocument(config, knowledgeId, documentIds, indexType, authHeader, (err, response) => {
790
+ console.log("Indexing started");
791
+ });
792
+ ```
793
+
794
+ ### List Documents
795
+
796
+ ```ts
797
+ GetAllKnowledgeDocument(config, knowledgeId, page, pageSize, criteria, authHeader, (err, response) => {
798
+ const docs = response.getKnowledgedocumentsList();
799
+ docs.forEach((d) => console.log(d.getName(), d.getStatus()));
800
+ });
801
+ ```
802
+
803
+ ### Document Segments
804
+
805
+ ```ts
806
+ // List segments
807
+ GetAllKnowledgeDocumentSegment(config, documentId, page, pageSize, criteria, authHeader, (err, response) => {
808
+ console.log("Segments:", response.getKnowledgedocumentsegmentsList());
809
+ });
810
+
811
+ // Update a segment
812
+ UpdateKnowledgeDocumentSegment(config, request, authHeader, (err, response) => { /* ... */ });
813
+
814
+ // Delete a segment
815
+ DeleteKnowledgeDocumentSegment(config, request, authHeader, (err, response) => { /* ... */ });
816
+ ```
817
+
818
+ ### Knowledge Logs
819
+
820
+ ```ts
821
+ GetAllKnowledgeLog(config, page, pageSize, criteria, (err, response) => {
822
+ console.log("Knowledge logs:", response.getLogsList());
823
+ }, authHeader);
824
+ ```
825
+
826
+ ---
827
+
828
+ ## Endpoints
829
+
830
+ Create and manage LLM endpoints with provider models, retry/cache configurations, and invocation.
831
+
832
+ ```ts
833
+ import {
834
+ GetAllEndpoint,
835
+ GetEndpoint,
836
+ CreateEndpoint,
837
+ UpdateEndpointVersion,
838
+ UpdateEndpointDetail,
839
+ CreateEndpointTag,
840
+ GetAllEndpointProviderModel,
841
+ CreateEndpointProviderModel,
842
+ CreateEndpointRetryConfiguration,
843
+ CreateEndpointCacheConfiguration,
844
+ GetAllEndpointLog,
845
+ GetEndpointLog,
846
+ Invoke,
847
+ } from "@rapidaai/react";
848
+ ```
849
+
850
+ ### List Endpoints
851
+
852
+ ```ts
853
+ GetAllEndpoint(config, page, pageSize, criteria, (err, response) => {
854
+ const endpoints = response.getEndpointsList();
855
+ endpoints.forEach((e) => console.log(e.getName(), e.getId()));
856
+ }, authHeader);
857
+ ```
858
+
859
+ ### Create an Endpoint
860
+
861
+ ```ts
862
+ const response = await CreateEndpoint(config, request, authHeader);
863
+ console.log("Endpoint created:", response.getEndpoint()?.getId());
864
+ ```
865
+
866
+ ### Configure Retry and Cache
867
+
868
+ ```ts
869
+ // Set retry configuration
870
+ const retryResponse = await CreateEndpointRetryConfiguration(config, request, authHeader);
871
+
872
+ // Set cache configuration
873
+ const cacheResponse = await CreateEndpointCacheConfiguration(config, request, authHeader);
874
+ ```
875
+
876
+ ### Invoke an Endpoint
877
+
878
+ ```ts
879
+ import { InvokeRequest } from "@rapidaai/react";
880
+
881
+ const request = new InvokeRequest();
882
+ // ... set endpoint ID, parameters, etc.
883
+
884
+ const response = await Invoke(config, request, authHeader);
885
+ console.log("Result:", response.getResult());
886
+ ```
887
+
888
+ ### Endpoint Logs
889
+
890
+ ```ts
891
+ GetAllEndpointLog(config, page, pageSize, criteria, (err, response) => {
892
+ console.log("Endpoint logs:", response.getLogsList());
893
+ }, authHeader);
894
+ ```
895
+
896
+ ---
897
+
898
+ ## Projects & Organizations
899
+
900
+ ### Organizations
901
+
902
+ ```ts
903
+ import {
904
+ CreateOrganization,
905
+ UpdateOrganization,
906
+ GetOrganization,
907
+ } from "@rapidaai/react";
908
+
909
+ // Create organization
910
+ CreateOrganization(config, "Acme Corp", "50-200", "Technology", authHeader, (err, response) => {
911
+ console.log("Org created:", response.getOrganization()?.getId());
912
+ });
913
+
914
+ // Update organization
915
+ UpdateOrganization(config, orgId, authHeader, (err, response) => { /* ... */ },
916
+ "New Name", "Finance", "contact@acme.com"
917
+ );
918
+
919
+ // Get organization
920
+ GetOrganization(config, orgId, authHeader, (err, response) => {
921
+ console.log("Org:", response.getOrganization()?.getOrganizationname());
922
+ });
923
+ ```
924
+
925
+ ### Projects
926
+
927
+ ```ts
928
+ import {
929
+ CreateProject,
930
+ UpdateProject,
931
+ GetProject,
932
+ GetAllProject,
933
+ DeleteProject,
934
+ AddUsersToProject,
935
+ GetAllProjectCredential,
936
+ CreateProjectCredential,
937
+ } from "@rapidaai/react";
938
+
939
+ // Create project
940
+ const response = await CreateProject(config, request, authHeader);
941
+
942
+ // List projects
943
+ GetAllProject(config, page, pageSize, criteria, (err, response) => {
944
+ response.getProjectsList().forEach((p) => console.log(p.getName()));
945
+ }, authHeader);
946
+
947
+ // Add users to project
948
+ AddUsersToProject(config, "user@example.com", "admin", ["project-id-1"], (err, response) => {
949
+ console.log("User added");
950
+ }, authHeader);
951
+
952
+ // Manage project credentials (API keys)
953
+ GetAllProjectCredential(config, projectId, page, pageSize, authHeader, (err, response) => {
954
+ console.log("Credentials:", response.getCredentialsList());
955
+ });
956
+
957
+ const credential = await CreateProjectCredential(config, request, authHeader);
958
+ ```
959
+
960
+ ---
961
+
962
+ ## Vault (Provider Credentials)
963
+
964
+ Securely manage API keys for external providers (OpenAI, Anthropic, etc.).
965
+
966
+ ```ts
967
+ import {
968
+ CreateProviderKey,
969
+ DeleteProviderKey,
970
+ GetAllOrganizationCredential,
971
+ } from "@rapidaai/react";
972
+
973
+ // Store a provider API key
974
+ const response = await CreateProviderKey(config, request, authHeader);
975
+
976
+ // List all credentials
977
+ GetAllOrganizationCredential(config, page, pageSize, criteria, (err, response) => {
978
+ console.log("Credentials:", response.getCredentialsList());
979
+ }, authHeader);
980
+
981
+ // Delete a credential
982
+ DeleteProviderKey(config, providerKeyId, (err, response) => {
983
+ console.log("Deleted");
984
+ }, authHeader);
985
+ ```
986
+
987
+ ---
988
+
989
+ ## Connectors
990
+
991
+ Connect to external platforms (Google, GitHub, Slack, etc.) via OAuth.
992
+
993
+ ```ts
994
+ import { GeneralConnect, GetConnectorFiles } from "@rapidaai/react";
995
+
996
+ // Establish an OAuth connection
997
+ GeneralConnect(config, "google", code, state, scope, authHeader, (err, response) => {
998
+ console.log("Connected:", response);
999
+ });
1000
+
1001
+ // Retrieve files from a connector
1002
+ GetConnectorFiles(config, "google", criterias, authHeader, (err, response) => {
1003
+ console.log("Files:", response.getFilesList());
1004
+ });
1005
+ ```
1006
+
1007
+ ---
1008
+
1009
+ ## Activity Logs
1010
+
1011
+ Access audit logs for tracking platform operations.
1012
+
1013
+ ```ts
1014
+ import { GetActivities, GetActivity } from "@rapidaai/react";
1015
+
1016
+ // List audit logs with pagination and filtering
1017
+ GetActivities(config, projectId, page, pageSize, criteria, (err, response) => {
1018
+ console.log("Activities:", response.getAuditlogsList());
1019
+ }, authHeader);
1020
+
1021
+ // Get a single audit log entry
1022
+ GetActivity(config, logId, (err, response) => {
1023
+ console.log("Activity:", response.getAuditlog());
1024
+ }, authHeader);
1025
+ ```
1026
+
1027
+ ---
1028
+
1029
+ ## Telemetry
1030
+
1031
+ Retrieve assistant telemetry data (latency, usage, performance metrics).
1032
+
1033
+ ```ts
1034
+ import { GetAllAssistantTelemetry } from "@rapidaai/react";
1035
+
1036
+ const response = await GetAllAssistantTelemetry(config, request, authHeader);
1037
+ console.log("Telemetry:", response.getTelemetryList());
1038
+ ```
1039
+
1040
+ ---
1041
+
1042
+ ## Notifications
1043
+
1044
+ Manage notification preferences.
1045
+
1046
+ ```ts
1047
+ import {
1048
+ GetNotificationSetting,
1049
+ UpdateNotificationSetting,
1050
+ } from "@rapidaai/react";
1051
+
1052
+ // Get current settings
1053
+ const settings = await GetNotificationSetting(config, request, authHeader);
1054
+
1055
+ // Update settings
1056
+ const updated = await UpdateNotificationSetting(config, request, authHeader);
1057
+ ```
1058
+
1059
+ ---
1060
+
1061
+ ## Voice Agent Hooks Reference
1062
+
1063
+ | Hook | Returns |
1064
+ | --- | --- |
1065
+ | `useConnectAgent(agent)` | `{ handleConnectAgent, handleDisconnectAgent, isConnected, isConnecting }` |
1066
+ | `useAgentMessages(agent)` | `{ messages }` — reactive list of `Message` objects. |
1067
+ | `useInputModeToggleAgent(agent)` | `{ handleTextToggle, handleVoiceToggle, channel }` — switch between text and audio. |
1068
+ | `useMuteAgent(agent)` | `{ handleMute, handleUnmute, handleToggleMute, isMuted }` |
1069
+ | `useSelectInputDeviceAgent(opts)` | `{ devices, activeDeviceId, setActiveMediaDevice }` — microphone selection. |
1070
+ | `useMessageFeedback(agent)` | `{ handleMessageFeedback, handleHelpfulnessFeedback }` — per-message feedback. |
1071
+ | `useConversationFeedback(agent)` | `{ handleConversationFeedback, handleHelpfulnessFeedback }` — conversation-level feedback. |
1072
+ | `useMultibandMicrophoneTrackVolume(agent, bands, lo, hi)` | `Float32Array[]` — mic frequency data for visualization. |
1073
+ | `useMultiband3DSpeakerTrackVolume(agent, bands, lo, hi)` | `Float32Array[]` — speaker frequency data. |
1074
+
1075
+ ---
1076
+
1077
+ ## Voice Agent Components
1078
+
1079
+ | Component | Description |
1080
+ | --- | --- |
1081
+ | `MultibandAudioVisualizerComponent` | Animated multiband frequency bar visualizer for mic or speaker audio. |
1082
+ | `DeviceSelectorComponent` | Dropdown UI for selecting the active microphone device. |
1083
+
1084
+ ---
1085
+
1086
+ ## Types & Configurations
1087
+
1088
+ | Type | Description |
1089
+ | --- | --- |
1090
+ | `ConnectionConfig` | Connection settings. Use `DefaultConnectionConfig()` with `WithSDK()`, `WithDebugger()`, `WithPersonalToken()`, or `WithWebpluginClient()`. |
1091
+ | `AgentConfig` | Agent configuration: assistant ID, input/output options, keywords, arguments, metadata, user identifier. |
1092
+ | `InputOptions` | Input channel config: `channels`, `channel`, `device`, `iceServers`. |
1093
+ | `OutputOptions` | Output channel config: `channels`, `channel`, `device`. |
1094
+ | `UserIdentifier` | User identity: `id` and optional `name`. |
1095
+ | `AgentCallback` | Callback interface: `onAssistantMessage`, `onUserMessage`, `onConfiguration`, `onInterrupt`, `onDirective`, `onInitialization`, `onConnectionStateChange`, `onConnected`, `onDisconnected`, `onError`. |
1096
+ | `Channel` | Enum: `Channel.Audio`, `Channel.Text` |
1097
+ | `ConnectionState` | Enum: `ConnectionState.Disconnected`, `ConnectionState.Connecting`, `ConnectionState.Connected` |
1098
+ | `Message` | Message object: `id`, `role`, `messages[]`, `feedback?`, `time`, `status` |
1099
+ | `MessageRole` | Enum: `MessageRole.System`, `MessageRole.User` |
1100
+ | `MessageStatus` | Enum: `MessageStatus.Pending`, `MessageStatus.Complete` |
1101
+ | `Feedback` | Enum: `Feedback.Helpful`, `Feedback.NotHelpful`, `Feedback.Other` |
1102
+ | `MediaDeviceFailure` | Media device error type. |
1103
+
1104
+ ### Utilities
1105
+
1106
+ | Export | Description |
1107
+ | --- | --- |
1108
+ | `StringToAny(value)` | Wraps a string into a protobuf `Any` for use with `addMetadata()` / `addArgument()`. |
1109
+ | `StringArrayToAny(values)` | Wraps a string array into a protobuf `Any`. |
1110
+ | `WithPlatform()` | Sets platform metadata on requests. |
1111
+ | `WithAuthContext(auth)` | Creates gRPC metadata from auth info. Automatically used by all client functions. |
1112
+ | `WithClientContext(auth)` | Creates client context metadata. |
1113
+ | `getClientInfo()` | Returns client information (browser, OS, etc.). |
1114
+ | `DEBUGGER_SOURCE`, `SDK_SOURCE`, `WEB_PLUGIN_SOURCE` | Source identifiers for connection context. |
1115
+ | `HEADER_*` constants | Header keys for environment, source, region, API key, auth, etc. |
1116
+ | `agentEventSelector(event)` | Selector for filtering agent events from the event stream. |
1117
+ | `AgentEvent` | Enum of all agent event types. |
1118
+
1119
+ ---
1120
+
1121
+ ## Connection Modes
1122
+
1123
+ | Mode | Factory Method | Use Case |
1124
+ | --- | --- | --- |
1125
+ | **SDK** | `ConnectionConfig.WithSDK({ ApiKey, UserId })` | Public-facing apps, embedded agents |
1126
+ | **Debugger** | `ConnectionConfig.WithDebugger({ authorization, userId, projectId })` | Internal testing with user auth |
1127
+ | **Personal Token** | `ConnectionConfig.WithPersonalToken({ Authorization, AuthId, ProjectId })` | Server-side or admin operations |
1128
+ | **Web Plugin** | `ConnectionConfig.WithWebpluginClient({ ApiKey, UserId })` | Embedded web plugin deployments |
1129
+
1130
+ ---
92
1131
 
93
1132
  ## License
94
1133
 
95
- This project is licensed under the MIT License.
1134
+ This project is licensed under the [MIT License](./LICENSE).