@convai/web-sdk 0.1.0 → 0.1.1-beta.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 +277 -185
- package/dist/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/components/ConvaiWidget.js +13 -0
- package/dist/components/ConvaiWidget.js.map +1 -1
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js +1 -1
- package/dist/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -1
- package/dist/components/rtc-widget/styles/styledComponents.d.ts.map +1 -1
- package/dist/components/rtc-widget/styles/styledComponents.js +72 -51
- package/dist/components/rtc-widget/styles/styledComponents.js.map +1 -1
- package/dist/core/AudioManager.d.ts +75 -0
- package/dist/core/AudioManager.d.ts.map +1 -0
- package/dist/core/AudioManager.js +219 -0
- package/dist/core/AudioManager.js.map +1 -0
- package/dist/core/ConvaiClient.d.ts +122 -0
- package/dist/core/ConvaiClient.d.ts.map +1 -0
- package/dist/core/ConvaiClient.js +514 -0
- package/dist/core/ConvaiClient.js.map +1 -0
- package/dist/core/EventEmitter.d.ts +38 -0
- package/dist/core/EventEmitter.d.ts.map +1 -0
- package/dist/core/EventEmitter.js +68 -0
- package/dist/core/EventEmitter.js.map +1 -0
- package/dist/core/MessageHandler.d.ts +52 -0
- package/dist/core/MessageHandler.d.ts.map +1 -0
- package/dist/core/MessageHandler.js +281 -0
- package/dist/core/MessageHandler.js.map +1 -0
- package/dist/core/ScreenShareManager.d.ts +57 -0
- package/dist/core/ScreenShareManager.d.ts.map +1 -0
- package/dist/core/ScreenShareManager.js +206 -0
- package/dist/core/ScreenShareManager.js.map +1 -0
- package/dist/core/VideoManager.d.ts +69 -0
- package/dist/core/VideoManager.d.ts.map +1 -0
- package/dist/core/VideoManager.js +207 -0
- package/dist/core/VideoManager.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +311 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/hooks/useAudioControls.d.ts.map +1 -1
- package/dist/hooks/useAudioControls.js +9 -1
- package/dist/hooks/useAudioControls.js.map +1 -1
- package/dist/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/hooks/useConvaiClient.js +32 -8
- package/dist/hooks/useConvaiClient.js.map +1 -1
- package/dist/hooks/useMessageHandler.d.ts.map +1 -1
- package/dist/hooks/useMessageHandler.js +39 -14
- package/dist/hooks/useMessageHandler.js.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -1
- package/dist/react/components/ConvaiWidget.d.ts +59 -0
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -0
- package/dist/react/components/ConvaiWidget.js +421 -0
- package/dist/react/components/ConvaiWidget.js.map +1 -0
- package/dist/react/components/index.d.ts +3 -0
- package/dist/react/components/index.d.ts.map +1 -0
- package/dist/react/components/index.js +5 -0
- package/dist/react/components/index.js.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +10 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +316 -0
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +10 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.js +14 -0
- package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts +9 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.js +122 -0
- package/dist/react/components/rtc-widget/components/FloatingVideo.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +7 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +68 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.d.ts +10 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.js +23 -0
- package/dist/react/components/rtc-widget/components/MessageBubble.js.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageList.d.ts +11 -0
- package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/MessageList.js +89 -0
- package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.d.ts +9 -0
- package/dist/react/components/rtc-widget/components/UserMessage.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js +15 -0
- package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +6 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +15 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +25 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +172 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +17 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +66 -0
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +12 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +68 -0
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +8 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +199 -0
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +6 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.js +6 -0
- package/dist/react/components/rtc-widget/components/conviComponents/index.js.map +1 -0
- package/dist/react/components/rtc-widget/components/index.d.ts +8 -0
- package/dist/react/components/rtc-widget/components/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/components/index.js +13 -0
- package/dist/react/components/rtc-widget/components/index.js.map +1 -0
- package/dist/react/components/rtc-widget/index.d.ts +6 -0
- package/dist/react/components/rtc-widget/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/index.js +9 -0
- package/dist/react/components/rtc-widget/index.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.d.ts +116 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.js +73 -0
- package/dist/react/components/rtc-widget/styles/framerConfig.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/icons.d.ts +28 -0
- package/dist/react/components/rtc-widget/styles/icons.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/icons.js +257 -0
- package/dist/react/components/rtc-widget/styles/icons.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/index.d.ts +6 -0
- package/dist/react/components/rtc-widget/styles/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/index.js +9 -0
- package/dist/react/components/rtc-widget/styles/index.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.d.ts +90 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.js +661 -0
- package/dist/react/components/rtc-widget/styles/styledComponents.js.map +1 -0
- package/dist/react/components/rtc-widget/styles/theme.d.ts +188 -0
- package/dist/react/components/rtc-widget/styles/theme.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/styles/theme.js +290 -0
- package/dist/react/components/rtc-widget/styles/theme.js.map +1 -0
- package/dist/react/components/rtc-widget/types/index.d.ts +60 -0
- package/dist/react/components/rtc-widget/types/index.d.ts.map +1 -0
- package/dist/react/components/rtc-widget/types/index.js +2 -0
- package/dist/react/components/rtc-widget/types/index.js.map +1 -0
- package/dist/react/hooks/index.d.ts +4 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/index.js +6 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/useCharacterInfo.d.ts +17 -0
- package/dist/react/hooks/useCharacterInfo.d.ts.map +1 -0
- package/dist/react/hooks/useCharacterInfo.js +60 -0
- package/dist/react/hooks/useCharacterInfo.js.map +1 -0
- package/dist/react/hooks/useConvaiClient.d.ts +32 -0
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -0
- package/dist/react/hooks/useConvaiClient.js +140 -0
- package/dist/react/hooks/useConvaiClient.js.map +1 -0
- package/dist/react/hooks/useLocalCameraTrack.d.ts +22 -0
- package/dist/react/hooks/useLocalCameraTrack.d.ts.map +1 -0
- package/dist/react/hooks/useLocalCameraTrack.js +34 -0
- package/dist/react/hooks/useLocalCameraTrack.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +15 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/speakerManagement.d.ts +22 -0
- package/dist/utils/speakerManagement.d.ts.map +1 -0
- package/dist/utils/speakerManagement.js +69 -0
- package/dist/utils/speakerManagement.js.map +1 -0
- package/dist/vanilla/index.d.ts +3 -0
- package/dist/vanilla/index.d.ts.map +1 -0
- package/dist/vanilla/index.js +5 -0
- package/dist/vanilla/index.js.map +1 -0
- package/package.json +22 -5
package/README.md
CHANGED
|
@@ -1,278 +1,370 @@
|
|
|
1
1
|
# @convai/web-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Multi-platform SDK for Convai AI voice assistants. Build voice-powered AI interactions for web applications with real-time audio/video streaming.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🌟 Features
|
|
6
|
+
|
|
7
|
+
- **Multi-Platform Support**: Works with React, Vanilla JS/TS, and any JavaScript framework
|
|
8
|
+
- **Tree-Shakeable**: Import only what you need for optimal bundle size
|
|
9
|
+
- **Voice & Video**: Real-time audio/video conversations with AI characters
|
|
10
|
+
- **Screen Sharing**: Share your screen with the AI assistant
|
|
11
|
+
- **TypeScript**: Fully typed for excellent developer experience
|
|
12
|
+
- **WebRTC Powered**: Built on LiveKit for robust real-time communication
|
|
13
|
+
- **Customizable UI**: Pre-built widgets or build your own
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
6
16
|
|
|
7
17
|
```bash
|
|
8
18
|
npm install @convai/web-sdk
|
|
9
19
|
```
|
|
10
20
|
|
|
11
|
-
##
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### React
|
|
12
24
|
|
|
13
25
|
```tsx
|
|
14
|
-
import { useConvaiClient, ConvaiWidget } from
|
|
26
|
+
import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk';
|
|
15
27
|
|
|
16
28
|
function App() {
|
|
17
29
|
const convaiClient = useConvaiClient({
|
|
18
|
-
apiKey:
|
|
19
|
-
characterId:
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
apiKey: 'your-api-key',
|
|
31
|
+
characterId: 'your-character-id',
|
|
32
|
+
// endUserId: 'user-uuid', // Optional: enables memory & analytics
|
|
33
|
+
enableVideo: true
|
|
22
34
|
});
|
|
23
35
|
|
|
24
|
-
return
|
|
25
|
-
<ConvaiWidget
|
|
26
|
-
convaiClient={convaiClient}
|
|
27
|
-
showVideo={true}
|
|
28
|
-
showScreenShare={true}
|
|
29
|
-
/>
|
|
30
|
-
);
|
|
36
|
+
return <ConvaiWidget convaiClient={convaiClient} />;
|
|
31
37
|
}
|
|
32
38
|
```
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
[**→ Full React Guide**](./docs/REACT_USAGE.md)
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
2. Navigate to your dashboard
|
|
38
|
-
3. Create a new character or use an existing one
|
|
39
|
-
4. Copy your **API Key** from the dashboard
|
|
40
|
-
5. Copy your **Character ID** from the character details
|
|
42
|
+
### Vanilla JavaScript/TypeScript
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
import { ConvaiClient, ConvaiWidget } from '@convai/web-sdk/vanilla';
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
const client = new ConvaiClient();
|
|
48
|
+
const widget = new ConvaiWidget(client, {
|
|
49
|
+
characterName: 'AI Assistant'
|
|
50
|
+
});
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
widget.mount(document.body);
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
const convaiClient = useConvaiClient({
|
|
54
|
+
await client.connect({
|
|
50
55
|
apiKey: 'your-api-key',
|
|
51
56
|
characterId: 'your-character-id',
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
// endUserId: 'user-uuid', // Optional: enables memory & analytics
|
|
58
|
+
enableVideo: true
|
|
54
59
|
});
|
|
55
60
|
```
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
[**→ Full Vanilla Guide**](./docs/VANILLA_USAGE.md)
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
### Core Only (Framework Agnostic)
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
state: ConvaiClientState; // Connection and activity state
|
|
64
|
-
connectionType: 'audio' | 'video' | null; // Current connection type
|
|
65
|
-
apiKey: string | null; // Stored API key
|
|
66
|
-
characterId: string | null; // Stored character ID
|
|
67
|
-
connect: (config?) => Promise<void>; // Connect using stored or override config
|
|
68
|
-
disconnect: () => Promise<void>; // Disconnect from Convai
|
|
69
|
-
reconnect: () => Promise<void>; // Disconnect and reconnect
|
|
70
|
-
resetSession: () => void; // Reset the session ID for fresh start
|
|
71
|
-
room: Room; // Internal LiveKit room instance
|
|
72
|
-
sendUserTextMessage: (text) => void; // Send text message
|
|
73
|
-
sendTriggerMessage: (name?, msg?) => void; // Send trigger message
|
|
74
|
-
updateTemplateKeys: (keys) => void; // Update template keys
|
|
75
|
-
updateDynamicInfo: (info) => void; // Update dynamic info
|
|
76
|
-
chatMessages: ChatMessage[]; // Message history
|
|
77
|
-
audioControls: AudioControls; // Audio control methods
|
|
78
|
-
videoControls: VideoControls; // Video control methods
|
|
79
|
-
screenShareControls: ScreenShareControls; // Screen share controls
|
|
80
|
-
toggleTts: (enabled) => void; // Toggle text-to-speech
|
|
81
|
-
}
|
|
82
|
-
```
|
|
66
|
+
For custom framework integrations:
|
|
83
67
|
|
|
84
|
-
|
|
68
|
+
```typescript
|
|
69
|
+
import { ConvaiClient } from '@convai/web-sdk/core';
|
|
85
70
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
71
|
+
const client = new ConvaiClient();
|
|
72
|
+
|
|
73
|
+
// Listen for events
|
|
74
|
+
client.on('stateChange', (state) => {
|
|
75
|
+
console.log('State:', state.agentState);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
client.on('message', (message) => {
|
|
79
|
+
console.log('New message:', message.content);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Connect
|
|
83
|
+
await client.connect({
|
|
84
|
+
apiKey: 'your-api-key',
|
|
85
|
+
characterId: 'your-character-id',
|
|
86
|
+
// endUserId: 'user-uuid' // Optional: enables memory & analytics
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Send message
|
|
90
|
+
client.sendUserTextMessage('Hello!');
|
|
100
91
|
```
|
|
101
92
|
|
|
102
|
-
|
|
93
|
+
## 📖 Platform-Specific Guides
|
|
103
94
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
Choose your platform:
|
|
96
|
+
|
|
97
|
+
- [**React Usage Guide**](./docs/REACT_USAGE.md) - Hooks, components, and React integration
|
|
98
|
+
- [**Vanilla JS/TS Guide**](./docs/VANILLA_USAGE.md) - Class-based API for vanilla JavaScript
|
|
99
|
+
- [**API Reference**](./API_REFERENCE.md) - Complete API documentation
|
|
100
|
+
|
|
101
|
+
## Import Options
|
|
102
|
+
|
|
103
|
+
The SDK supports multiple import paths for tree-shaking:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Default: React version (backward compatible)
|
|
107
|
+
import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk';
|
|
108
|
+
|
|
109
|
+
// Explicit React import
|
|
110
|
+
import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk/react';
|
|
111
|
+
|
|
112
|
+
// Vanilla JavaScript/TypeScript
|
|
113
|
+
import { ConvaiClient, ConvaiWidget } from '@convai/web-sdk/vanilla';
|
|
114
|
+
|
|
115
|
+
// Core only (no UI, framework agnostic)
|
|
116
|
+
import { ConvaiClient } from '@convai/web-sdk/core';
|
|
111
117
|
```
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
## 🔑 Get Convai Credentials
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
1. Visit [convai.com](https://convai.com) and create an account
|
|
122
|
+
2. Navigate to your dashboard
|
|
123
|
+
3. Create a new character or use an existing one
|
|
124
|
+
4. Copy your **API Key** from the dashboard
|
|
125
|
+
5. Copy your **Character ID** from the character details
|
|
126
|
+
|
|
127
|
+
## Core Features
|
|
128
|
+
|
|
129
|
+
### Connection Management
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// Connect
|
|
133
|
+
await client.connect(config);
|
|
134
|
+
|
|
135
|
+
// Disconnect
|
|
136
|
+
await client.disconnect();
|
|
137
|
+
|
|
138
|
+
// Reset session (clear history)
|
|
139
|
+
client.resetSession();
|
|
140
|
+
|
|
141
|
+
// Reconnect
|
|
142
|
+
await client.reconnect();
|
|
121
143
|
```
|
|
122
144
|
|
|
123
|
-
|
|
145
|
+
### Messaging
|
|
124
146
|
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
147
|
+
```typescript
|
|
148
|
+
// Send text message
|
|
149
|
+
client.sendUserTextMessage('Hello!');
|
|
150
|
+
|
|
151
|
+
// Send trigger for specific actions
|
|
152
|
+
client.sendTriggerMessage('greet', 'User entered room');
|
|
153
|
+
|
|
154
|
+
// Update context
|
|
155
|
+
client.updateTemplateKeys({ user_name: 'John' });
|
|
156
|
+
client.updateDynamicInfo({ text: 'User is happy' });
|
|
130
157
|
```
|
|
131
158
|
|
|
132
|
-
###
|
|
159
|
+
### Media Controls
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Audio (always available)
|
|
163
|
+
await client.audioControls.toggleAudio();
|
|
164
|
+
await client.audioControls.muteAudio();
|
|
165
|
+
await client.audioControls.unmuteAudio();
|
|
133
166
|
|
|
134
|
-
|
|
167
|
+
// Video (if enableVideo: true)
|
|
168
|
+
await client.videoControls.toggleVideo();
|
|
169
|
+
await client.videoControls.enableVideo();
|
|
170
|
+
await client.videoControls.disableVideo();
|
|
135
171
|
|
|
136
|
-
|
|
172
|
+
// Screen Share (if enableVideo: true)
|
|
173
|
+
await client.screenShareControls.toggleScreenShare();
|
|
174
|
+
```
|
|
137
175
|
|
|
138
|
-
|
|
139
|
-
- Connects on first user click (using config from useConvaiClient)
|
|
140
|
-
- Text and voice mode support
|
|
141
|
-
- Video controls with floating video window (when connection type is video)
|
|
142
|
-
- Screen sharing capability (when connection type is video)
|
|
176
|
+
### State Monitoring
|
|
143
177
|
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
178
|
+
```typescript
|
|
179
|
+
// React
|
|
180
|
+
const { state, chatMessages, userTranscription } = convaiClient;
|
|
181
|
+
|
|
182
|
+
// Vanilla
|
|
183
|
+
client.on('stateChange', (state) => {
|
|
184
|
+
console.log(state.agentState); // 'listening' | 'thinking' | 'speaking'
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
client.on('message', (message) => {
|
|
188
|
+
console.log('New message:', message);
|
|
189
|
+
});
|
|
150
190
|
```
|
|
151
191
|
|
|
152
|
-
|
|
192
|
+
## 🎨 UI Components
|
|
153
193
|
|
|
154
|
-
|
|
155
|
-
| ------------------ | -------------- | -------- | ------- | ---------------------------------------------------------------- |
|
|
156
|
-
| `convaiClient` | `ConvaiClient` | Yes | - | ConvaiClient instance from useConvaiClient() with stored config |
|
|
157
|
-
| `showVideo` | `boolean` | No | `true` | Show video toggle button (only works if connection type is video)|
|
|
158
|
-
| `showScreenShare` | `boolean` | No | `true` | Show screen share button (only works if connection type is video)|
|
|
194
|
+
### Pre-built Widget
|
|
159
195
|
|
|
160
|
-
|
|
196
|
+
Both React and Vanilla versions include a complete chat widget:
|
|
161
197
|
|
|
162
|
-
|
|
198
|
+
- Expandable circular button
|
|
199
|
+
- Chat interface with message history
|
|
200
|
+
- Voice/text input modes
|
|
201
|
+
- Video controls (when enabled)
|
|
202
|
+
- Screen sharing (when enabled)
|
|
203
|
+
- Auto-connects on first interaction
|
|
163
204
|
|
|
164
|
-
|
|
205
|
+
### Custom UI
|
|
206
|
+
|
|
207
|
+
Build your own UI using the client API. The client handles all the AI logic while you control the presentation.
|
|
208
|
+
|
|
209
|
+
## Message Types
|
|
210
|
+
|
|
211
|
+
The SDK handles various message types:
|
|
212
|
+
|
|
213
|
+
- `user-transcription` - Real-time speech-to-text
|
|
214
|
+
- `bot-llm-text` - AI character responses
|
|
215
|
+
- `bot-emotion` - Character emotional states
|
|
216
|
+
- `action` - Action executions
|
|
217
|
+
- `behavior-tree` - Behavior responses
|
|
218
|
+
|
|
219
|
+
## 🔧 Configuration
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
165
222
|
interface ConvaiConfig {
|
|
166
|
-
apiKey: string;
|
|
167
|
-
characterId: string;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
223
|
+
apiKey: string; // Required
|
|
224
|
+
characterId: string; // Required
|
|
225
|
+
endUserId?: string; // Optional: unique ID for memory & analytics
|
|
226
|
+
url?: string; // Optional: API URL
|
|
227
|
+
enableVideo?: boolean; // Optional: Enable video (default: false)
|
|
228
|
+
startWithVideoOn?: boolean; // Optional: Start with camera on
|
|
229
|
+
ttsEnabled?: boolean; // Optional: Enable TTS (default: true)
|
|
230
|
+
actionConfig?: { // Optional: Actions & context
|
|
231
|
+
actions: string[];
|
|
232
|
+
characters: Array<{ name: string; bio: string }>;
|
|
233
|
+
objects: Array<{ name: string; description: string }>;
|
|
234
|
+
};
|
|
176
235
|
}
|
|
177
236
|
```
|
|
178
237
|
|
|
179
|
-
|
|
238
|
+
### About endUserId
|
|
180
239
|
|
|
181
|
-
|
|
240
|
+
The `endUserId` parameter is **optional** and serves two important purposes:
|
|
182
241
|
|
|
183
|
-
|
|
242
|
+
1. **Long-term Memory**: When provided, the character remembers context from previous conversations with this user, enabling personalized and continuous interactions across sessions.
|
|
184
243
|
|
|
185
|
-
|
|
186
|
-
// Send text message
|
|
187
|
-
convaiClient.sendUserTextMessage("Hello!");
|
|
244
|
+
2. **Analytics & Tracking**: Track user engagement, behavior patterns, and conversation metrics for your application.
|
|
188
245
|
|
|
189
|
-
|
|
190
|
-
|
|
246
|
+
**Usage:**
|
|
247
|
+
- **With endUserId**: Pass a unique identifier (UUID, device ID, or user ID) to enable persistent memory and analytics
|
|
248
|
+
- **Without endUserId**: Anonymous mode - each session is independent with no conversation history or tracking
|
|
191
249
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
250
|
+
```typescript
|
|
251
|
+
// With persistent memory and analytics
|
|
252
|
+
await client.connect({
|
|
253
|
+
apiKey: 'your-api-key',
|
|
254
|
+
characterId: 'your-character-id',
|
|
255
|
+
endUserId: 'user-12345' // User will be remembered
|
|
196
256
|
});
|
|
197
257
|
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
258
|
+
// Anonymous mode (no memory, no tracking)
|
|
259
|
+
await client.connect({
|
|
260
|
+
apiKey: 'your-api-key',
|
|
261
|
+
characterId: 'your-character-id'
|
|
262
|
+
// No endUserId = anonymous
|
|
201
263
|
});
|
|
202
264
|
```
|
|
203
265
|
|
|
204
|
-
|
|
266
|
+
## Browser Support
|
|
205
267
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// Mute/unmute
|
|
211
|
-
await convaiClient.audioControls.muteAudio();
|
|
212
|
-
await convaiClient.audioControls.unmuteAudio();
|
|
268
|
+
- Chrome/Edge: Full support
|
|
269
|
+
- Firefox: Full support
|
|
270
|
+
- Safari: Full support
|
|
271
|
+
- Mobile browsers: Supported
|
|
213
272
|
|
|
214
|
-
|
|
215
|
-
await convaiClient.videoControls.enableVideo();
|
|
216
|
-
await convaiClient.videoControls.disableVideo();
|
|
273
|
+
## Package Structure
|
|
217
274
|
|
|
218
|
-
|
|
219
|
-
|
|
275
|
+
```
|
|
276
|
+
@convai/web-sdk
|
|
277
|
+
├── /core # Framework-agnostic core (ConvaiClient)
|
|
278
|
+
├── /react # React hooks and components
|
|
279
|
+
├── /vanilla # Vanilla JS/TS widget
|
|
280
|
+
└── (default) # React (backward compatible)
|
|
220
281
|
```
|
|
221
282
|
|
|
222
|
-
|
|
283
|
+
## 🔄 Migration from Previous Versions
|
|
223
284
|
|
|
224
|
-
|
|
225
|
-
// Reset session (clears history)
|
|
226
|
-
convaiClient.resetSession();
|
|
285
|
+
### Backward Compatible
|
|
227
286
|
|
|
228
|
-
|
|
229
|
-
await convaiClient.disconnect();
|
|
287
|
+
No breaking changes! Existing code continues to work:
|
|
230
288
|
|
|
231
|
-
|
|
232
|
-
|
|
289
|
+
```tsx
|
|
290
|
+
// Still works
|
|
291
|
+
import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk';
|
|
233
292
|
```
|
|
234
293
|
|
|
235
|
-
|
|
294
|
+
### New Features Available
|
|
236
295
|
|
|
237
|
-
|
|
296
|
+
```tsx
|
|
297
|
+
// New: Explicit React import
|
|
298
|
+
import { useConvaiClient } from '@convai/web-sdk/react';
|
|
238
299
|
|
|
239
|
-
|
|
300
|
+
// New: Vanilla JS/TS support
|
|
301
|
+
import { ConvaiClient, ConvaiWidget } from '@convai/web-sdk/vanilla';
|
|
240
302
|
|
|
241
|
-
|
|
242
|
-
import {
|
|
243
|
-
|
|
244
|
-
function CustomApp() {
|
|
245
|
-
const convaiClient = useConvaiClient();
|
|
246
|
-
|
|
247
|
-
return (
|
|
248
|
-
<AudioContext.Provider value={convaiClient.room}>
|
|
249
|
-
{/* AudioRenderer is required for audio playback */}
|
|
250
|
-
<AudioRenderer />
|
|
251
|
-
|
|
252
|
-
{/* Your custom UI here */}
|
|
253
|
-
<YourCustomUI />
|
|
254
|
-
</AudioContext.Provider>
|
|
255
|
-
);
|
|
256
|
-
}
|
|
303
|
+
// New: Core-only for custom frameworks
|
|
304
|
+
import { ConvaiClient } from '@convai/web-sdk/core';
|
|
257
305
|
```
|
|
258
306
|
|
|
259
|
-
|
|
307
|
+
## 🎓 Examples
|
|
260
308
|
|
|
261
|
-
|
|
309
|
+
- [React Example](./examples/react/) - Complete React application
|
|
310
|
+
- More examples coming soon!
|
|
262
311
|
|
|
263
|
-
|
|
312
|
+
## Best Practices
|
|
264
313
|
|
|
265
|
-
|
|
266
|
-
|
|
314
|
+
1. **Single Client Instance**: Create one client per application
|
|
315
|
+
2. **State Management**: Check `state.isConnected` before sending messages
|
|
316
|
+
3. **Session Management**: Use `resetSession()` when changing contexts
|
|
317
|
+
4. **Error Handling**: Always wrap connect/disconnect in try-catch
|
|
318
|
+
5. **Resource Cleanup**: Disconnect when done to free resources
|
|
319
|
+
6. **Tree Shaking**: Import from specific paths to reduce bundle size
|
|
320
|
+
|
|
321
|
+
## TypeScript Support
|
|
322
|
+
|
|
323
|
+
Fully typed with TypeScript:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import type {
|
|
267
327
|
ConvaiClient,
|
|
268
328
|
ConvaiConfig,
|
|
269
329
|
ConvaiClientState,
|
|
270
330
|
ChatMessage,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
331
|
+
AudioControls,
|
|
332
|
+
VideoControls,
|
|
333
|
+
ScreenShareControls,
|
|
334
|
+
} from '@convai/web-sdk';
|
|
274
335
|
```
|
|
275
336
|
|
|
276
|
-
##
|
|
337
|
+
## 🔗 Dependencies
|
|
338
|
+
|
|
339
|
+
### Core
|
|
340
|
+
- `livekit-client` - WebRTC functionality
|
|
341
|
+
|
|
342
|
+
### React (Peer)
|
|
343
|
+
- `react ^18.0.0`
|
|
344
|
+
- `react-dom ^18.0.0`
|
|
345
|
+
- `@livekit/components-react`
|
|
346
|
+
- `styled-components`
|
|
347
|
+
- `framer-motion`
|
|
348
|
+
- `react-icons`
|
|
349
|
+
|
|
350
|
+
### Vanilla
|
|
351
|
+
- None! Pure JavaScript
|
|
352
|
+
|
|
353
|
+
## 📄 License
|
|
277
354
|
|
|
278
355
|
MIT
|
|
356
|
+
|
|
357
|
+
## 🆘 Support
|
|
358
|
+
|
|
359
|
+
- [GitHub Issues](https://github.com/convai/web-sdk/issues)
|
|
360
|
+
- [Documentation](./docs/)
|
|
361
|
+
- [API Reference](./API_REFERENCE.md)
|
|
362
|
+
- [Convai Website](https://convai.com)
|
|
363
|
+
|
|
364
|
+
## 🤝 Contributing
|
|
365
|
+
|
|
366
|
+
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
Built by [Convai](https://convai.com)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConvaiWidget.d.ts","sourceRoot":"","sources":["../../src/components/ConvaiWidget.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAyCxC,UAAU,iBAAiB;IACzB,wCAAwC;IACxC,YAAY,EAAE,YAAY,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ConvaiWidget.d.ts","sourceRoot":"","sources":["../../src/components/ConvaiWidget.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAyCxC,UAAU,iBAAiB;IACzB,wCAAwC;IACxC,YAAY,EAAE,YAAY,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAqpBpD,CAAC"}
|
|
@@ -66,6 +66,16 @@ export const ConvaiWidget = ({ convaiClient, showVideo = true, showScreenShare =
|
|
|
66
66
|
name: characterName,
|
|
67
67
|
image: characterImage,
|
|
68
68
|
};
|
|
69
|
+
// Get bot status color for character image border
|
|
70
|
+
const getBotStatusColor = () => {
|
|
71
|
+
if (!convaiClient.state.isConnected) {
|
|
72
|
+
return { color: "#ef4444", label: "Disconnected" }; // Red
|
|
73
|
+
}
|
|
74
|
+
if (convaiClient.state.isConnecting || !convaiClient.isBotReady) {
|
|
75
|
+
return { color: "#f59e0b", label: "Connecting" }; // Yellow/Orange
|
|
76
|
+
}
|
|
77
|
+
return { color: "#10b981", label: "Connected" }; // Green
|
|
78
|
+
};
|
|
69
79
|
// Format chat messages for UI
|
|
70
80
|
const formatMessages = () => {
|
|
71
81
|
// Filter to only show relevant message types and exclude empty messages
|
|
@@ -268,6 +278,9 @@ export const ConvaiWidget = ({ convaiClient, showVideo = true, showScreenShare =
|
|
|
268
278
|
borderRadius: "50%",
|
|
269
279
|
objectFit: "cover",
|
|
270
280
|
marginRight: "0.5rem",
|
|
281
|
+
border: `1.5px solid ${getBotStatusColor().color}`,
|
|
282
|
+
boxShadow: `0 0 6px ${getBotStatusColor().color}40`,
|
|
283
|
+
transition: "all 0.3s ease",
|
|
271
284
|
} })), selectedCharacter.name, _jsx(motion.button, { onClick: handleToggleMute, whileHover: { scale: 1.1 }, whileTap: { scale: 0.9 }, transition: iosTransitions.snappy, style: {
|
|
272
285
|
cursor: "pointer",
|
|
273
286
|
pointerEvents: "auto",
|