@convai/web-sdk 0.1.0 → 0.1.1-beta.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.
Files changed (174) hide show
  1. package/README.md +277 -185
  2. package/dist/components/ConvaiWidget.d.ts.map +1 -1
  3. package/dist/components/ConvaiWidget.js +13 -0
  4. package/dist/components/ConvaiWidget.js.map +1 -1
  5. package/dist/components/rtc-widget/components/AudioSettingsPanel.js +1 -1
  6. package/dist/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -1
  7. package/dist/components/rtc-widget/styles/styledComponents.d.ts.map +1 -1
  8. package/dist/components/rtc-widget/styles/styledComponents.js +72 -51
  9. package/dist/components/rtc-widget/styles/styledComponents.js.map +1 -1
  10. package/dist/core/AudioManager.d.ts +75 -0
  11. package/dist/core/AudioManager.d.ts.map +1 -0
  12. package/dist/core/AudioManager.js +219 -0
  13. package/dist/core/AudioManager.js.map +1 -0
  14. package/dist/core/ConvaiClient.d.ts +122 -0
  15. package/dist/core/ConvaiClient.d.ts.map +1 -0
  16. package/dist/core/ConvaiClient.js +509 -0
  17. package/dist/core/ConvaiClient.js.map +1 -0
  18. package/dist/core/EventEmitter.d.ts +38 -0
  19. package/dist/core/EventEmitter.d.ts.map +1 -0
  20. package/dist/core/EventEmitter.js +68 -0
  21. package/dist/core/EventEmitter.js.map +1 -0
  22. package/dist/core/MessageHandler.d.ts +52 -0
  23. package/dist/core/MessageHandler.d.ts.map +1 -0
  24. package/dist/core/MessageHandler.js +281 -0
  25. package/dist/core/MessageHandler.js.map +1 -0
  26. package/dist/core/ScreenShareManager.d.ts +57 -0
  27. package/dist/core/ScreenShareManager.d.ts.map +1 -0
  28. package/dist/core/ScreenShareManager.js +206 -0
  29. package/dist/core/ScreenShareManager.js.map +1 -0
  30. package/dist/core/VideoManager.d.ts +69 -0
  31. package/dist/core/VideoManager.d.ts.map +1 -0
  32. package/dist/core/VideoManager.js +207 -0
  33. package/dist/core/VideoManager.js.map +1 -0
  34. package/dist/core/index.d.ts +9 -0
  35. package/dist/core/index.d.ts.map +1 -0
  36. package/dist/core/index.js +12 -0
  37. package/dist/core/index.js.map +1 -0
  38. package/dist/core/types.d.ts +311 -0
  39. package/dist/core/types.d.ts.map +1 -0
  40. package/dist/core/types.js +2 -0
  41. package/dist/core/types.js.map +1 -0
  42. package/dist/hooks/useConvaiClient.d.ts.map +1 -1
  43. package/dist/hooks/useConvaiClient.js +16 -0
  44. package/dist/hooks/useConvaiClient.js.map +1 -1
  45. package/dist/hooks/useMessageHandler.d.ts.map +1 -1
  46. package/dist/hooks/useMessageHandler.js +39 -14
  47. package/dist/hooks/useMessageHandler.js.map +1 -1
  48. package/dist/index.d.ts +1 -5
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +3 -10
  51. package/dist/index.js.map +1 -1
  52. package/dist/react/components/ConvaiWidget.d.ts +59 -0
  53. package/dist/react/components/ConvaiWidget.d.ts.map +1 -0
  54. package/dist/react/components/ConvaiWidget.js +421 -0
  55. package/dist/react/components/ConvaiWidget.js.map +1 -0
  56. package/dist/react/components/index.d.ts +3 -0
  57. package/dist/react/components/index.d.ts.map +1 -0
  58. package/dist/react/components/index.js +5 -0
  59. package/dist/react/components/index.js.map +1 -0
  60. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +10 -0
  61. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +1 -0
  62. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +316 -0
  63. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js.map +1 -0
  64. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +10 -0
  65. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +1 -0
  66. package/dist/react/components/rtc-widget/components/ConviMessage.js +14 -0
  67. package/dist/react/components/rtc-widget/components/ConviMessage.js.map +1 -0
  68. package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts +9 -0
  69. package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts.map +1 -0
  70. package/dist/react/components/rtc-widget/components/FloatingVideo.js +122 -0
  71. package/dist/react/components/rtc-widget/components/FloatingVideo.js.map +1 -0
  72. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +7 -0
  73. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -0
  74. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +68 -0
  75. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -0
  76. package/dist/react/components/rtc-widget/components/MessageBubble.d.ts +10 -0
  77. package/dist/react/components/rtc-widget/components/MessageBubble.d.ts.map +1 -0
  78. package/dist/react/components/rtc-widget/components/MessageBubble.js +23 -0
  79. package/dist/react/components/rtc-widget/components/MessageBubble.js.map +1 -0
  80. package/dist/react/components/rtc-widget/components/MessageList.d.ts +11 -0
  81. package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +1 -0
  82. package/dist/react/components/rtc-widget/components/MessageList.js +89 -0
  83. package/dist/react/components/rtc-widget/components/MessageList.js.map +1 -0
  84. package/dist/react/components/rtc-widget/components/UserMessage.d.ts +9 -0
  85. package/dist/react/components/rtc-widget/components/UserMessage.d.ts.map +1 -0
  86. package/dist/react/components/rtc-widget/components/UserMessage.js +15 -0
  87. package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -0
  88. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +6 -0
  89. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +1 -0
  90. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +15 -0
  91. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js.map +1 -0
  92. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +25 -0
  93. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +1 -0
  94. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +172 -0
  95. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js.map +1 -0
  96. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +17 -0
  97. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +1 -0
  98. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +66 -0
  99. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js.map +1 -0
  100. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +12 -0
  101. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -0
  102. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +68 -0
  103. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -0
  104. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +8 -0
  105. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -0
  106. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +199 -0
  107. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -0
  108. package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +6 -0
  109. package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts.map +1 -0
  110. package/dist/react/components/rtc-widget/components/conviComponents/index.js +6 -0
  111. package/dist/react/components/rtc-widget/components/conviComponents/index.js.map +1 -0
  112. package/dist/react/components/rtc-widget/components/index.d.ts +8 -0
  113. package/dist/react/components/rtc-widget/components/index.d.ts.map +1 -0
  114. package/dist/react/components/rtc-widget/components/index.js +13 -0
  115. package/dist/react/components/rtc-widget/components/index.js.map +1 -0
  116. package/dist/react/components/rtc-widget/index.d.ts +6 -0
  117. package/dist/react/components/rtc-widget/index.d.ts.map +1 -0
  118. package/dist/react/components/rtc-widget/index.js +9 -0
  119. package/dist/react/components/rtc-widget/index.js.map +1 -0
  120. package/dist/react/components/rtc-widget/styles/framerConfig.d.ts +116 -0
  121. package/dist/react/components/rtc-widget/styles/framerConfig.d.ts.map +1 -0
  122. package/dist/react/components/rtc-widget/styles/framerConfig.js +73 -0
  123. package/dist/react/components/rtc-widget/styles/framerConfig.js.map +1 -0
  124. package/dist/react/components/rtc-widget/styles/icons.d.ts +28 -0
  125. package/dist/react/components/rtc-widget/styles/icons.d.ts.map +1 -0
  126. package/dist/react/components/rtc-widget/styles/icons.js +257 -0
  127. package/dist/react/components/rtc-widget/styles/icons.js.map +1 -0
  128. package/dist/react/components/rtc-widget/styles/index.d.ts +6 -0
  129. package/dist/react/components/rtc-widget/styles/index.d.ts.map +1 -0
  130. package/dist/react/components/rtc-widget/styles/index.js +9 -0
  131. package/dist/react/components/rtc-widget/styles/index.js.map +1 -0
  132. package/dist/react/components/rtc-widget/styles/styledComponents.d.ts +90 -0
  133. package/dist/react/components/rtc-widget/styles/styledComponents.d.ts.map +1 -0
  134. package/dist/react/components/rtc-widget/styles/styledComponents.js +661 -0
  135. package/dist/react/components/rtc-widget/styles/styledComponents.js.map +1 -0
  136. package/dist/react/components/rtc-widget/styles/theme.d.ts +188 -0
  137. package/dist/react/components/rtc-widget/styles/theme.d.ts.map +1 -0
  138. package/dist/react/components/rtc-widget/styles/theme.js +290 -0
  139. package/dist/react/components/rtc-widget/styles/theme.js.map +1 -0
  140. package/dist/react/components/rtc-widget/types/index.d.ts +60 -0
  141. package/dist/react/components/rtc-widget/types/index.d.ts.map +1 -0
  142. package/dist/react/components/rtc-widget/types/index.js +2 -0
  143. package/dist/react/components/rtc-widget/types/index.js.map +1 -0
  144. package/dist/react/hooks/index.d.ts +4 -0
  145. package/dist/react/hooks/index.d.ts.map +1 -0
  146. package/dist/react/hooks/index.js +6 -0
  147. package/dist/react/hooks/index.js.map +1 -0
  148. package/dist/react/hooks/useCharacterInfo.d.ts +17 -0
  149. package/dist/react/hooks/useCharacterInfo.d.ts.map +1 -0
  150. package/dist/react/hooks/useCharacterInfo.js +60 -0
  151. package/dist/react/hooks/useCharacterInfo.js.map +1 -0
  152. package/dist/react/hooks/useConvaiClient.d.ts +32 -0
  153. package/dist/react/hooks/useConvaiClient.d.ts.map +1 -0
  154. package/dist/react/hooks/useConvaiClient.js +140 -0
  155. package/dist/react/hooks/useConvaiClient.js.map +1 -0
  156. package/dist/react/hooks/useLocalCameraTrack.d.ts +22 -0
  157. package/dist/react/hooks/useLocalCameraTrack.d.ts.map +1 -0
  158. package/dist/react/hooks/useLocalCameraTrack.js +34 -0
  159. package/dist/react/hooks/useLocalCameraTrack.js.map +1 -0
  160. package/dist/react/index.d.ts +8 -0
  161. package/dist/react/index.d.ts.map +1 -0
  162. package/dist/react/index.js +15 -0
  163. package/dist/react/index.js.map +1 -0
  164. package/dist/types/index.d.ts +20 -0
  165. package/dist/types/index.d.ts.map +1 -1
  166. package/dist/utils/speakerManagement.d.ts +22 -0
  167. package/dist/utils/speakerManagement.d.ts.map +1 -0
  168. package/dist/utils/speakerManagement.js +71 -0
  169. package/dist/utils/speakerManagement.js.map +1 -0
  170. package/dist/vanilla/index.d.ts +3 -0
  171. package/dist/vanilla/index.d.ts.map +1 -0
  172. package/dist/vanilla/index.js +5 -0
  173. package/dist/vanilla/index.js.map +1 -0
  174. package/package.json +22 -5
package/README.md CHANGED
@@ -1,278 +1,370 @@
1
1
  # @convai/web-sdk
2
2
 
3
- The convai/web-sdk helps power characters in websites (brain) and the communication UI with Convai characters. This SDK facilitates the capture of user audio streams and provides appropriate responses in the form of audio, actions, and facial expressions.
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
- ## Installation
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
- ## Quick Start
21
+ ## Quick Start
22
+
23
+ ### React
12
24
 
13
25
  ```tsx
14
- import { useConvaiClient, ConvaiWidget } from "@convai/web-sdk";
26
+ import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk';
15
27
 
16
28
  function App() {
17
29
  const convaiClient = useConvaiClient({
18
- apiKey: "your-convai-api-key",
19
- characterId: "your-character-id",
20
- enableVideo: true,
21
- startWithVideoOn: false,
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
- ## Get Convai Credentials
40
+ [**→ Full React Guide**](./docs/REACT_USAGE.md)
35
41
 
36
- 1. Visit [convai.com](https://convai.com) and create an account
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
- ## API Reference
44
+ ```typescript
45
+ import { ConvaiClient, ConvaiWidget } from '@convai/web-sdk/vanilla';
43
46
 
44
- ### useConvaiClient()
47
+ const client = new ConvaiClient();
48
+ const widget = new ConvaiWidget(client, {
49
+ characterName: 'AI Assistant'
50
+ });
45
51
 
46
- Main hook for managing Convai connections. Pass configuration to store it for later use when connecting.
52
+ widget.mount(document.body);
47
53
 
48
- ```tsx
49
- const convaiClient = useConvaiClient({
54
+ await client.connect({
50
55
  apiKey: 'your-api-key',
51
56
  characterId: 'your-character-id',
52
- enableVideo: true,
53
- startWithVideoOn: false,
57
+ // endUserId: 'user-uuid', // Optional: enables memory & analytics
58
+ enableVideo: true
54
59
  });
55
60
  ```
56
61
 
57
- **Note:** The hook stores the configuration but does not auto-connect. Connection happens when `convaiClient.connect()` is called (automatically by ConvaiWidget on first click, or manually in custom implementations).
62
+ [**→ Full Vanilla Guide**](./docs/VANILLA_USAGE.md)
58
63
 
59
- **Returns:**
64
+ ### Core Only (Framework Agnostic)
60
65
 
61
- ```tsx
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
- **State Object:**
68
+ ```typescript
69
+ import { ConvaiClient } from '@convai/web-sdk/core';
85
70
 
86
- ```tsx
87
- interface ConvaiClientState {
88
- isConnected: boolean; // Connected to Convai
89
- isConnecting: boolean; // Connection in progress
90
- isListening: boolean; // Listening to user
91
- isThinking: boolean; // Processing response
92
- isSpeaking: boolean; // Speaking to user
93
- agentState:
94
- | "disconnected"
95
- | "connected"
96
- | "listening"
97
- | "thinking"
98
- | "speaking";
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
- **Audio Controls:**
93
+ ## 📖 Platform-Specific Guides
103
94
 
104
- ```tsx
105
- audioControls: {
106
- isAudioMuted: boolean;
107
- toggleAudio: () => Promise<void>;
108
- muteAudio: () => Promise<void>;
109
- unmuteAudio: () => Promise<void>;
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
- **Video Controls:**
119
+ ## 🔑 Get Convai Credentials
114
120
 
115
- ```tsx
116
- videoControls: {
117
- isVideoEnabled: boolean;
118
- enableVideo: () => Promise<void>;
119
- disableVideo: () => Promise<void>;
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
- **Screen Share Controls:**
145
+ ### Messaging
124
146
 
125
- ```tsx
126
- screenShareControls: {
127
- isScreenShareActive: boolean;
128
- toggleScreenShare: () => Promise<void>;
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
- ### ConvaiWidget Component
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
- Complete all-in-one chat widget with automatic connection, voice mode, and video support.
167
+ // Video (if enableVideo: true)
168
+ await client.videoControls.toggleVideo();
169
+ await client.videoControls.enableVideo();
170
+ await client.videoControls.disableVideo();
135
171
 
136
- **Features:**
172
+ // Screen Share (if enableVideo: true)
173
+ await client.screenShareControls.toggleScreenShare();
174
+ ```
137
175
 
138
- - Collapsed circular button that expands on click
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
- ```tsx
145
- <ConvaiWidget
146
- convaiClient={convaiClient}
147
- showVideo={true}
148
- showScreenShare={true}
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
- **Props:**
192
+ ## 🎨 UI Components
153
193
 
154
- | Prop | Type | Required | Default | Description |
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
- ## Configuration
196
+ Both React and Vanilla versions include a complete chat widget:
161
197
 
162
- **Config Interface:**
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
- ```tsx
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; // Required: Your Convai API key
167
- characterId: string; // Required: Character ID
168
- url?: string; // Optional: Custom API URL
169
- enableVideo?: boolean; // Optional: Enable video capability (default: false)
170
- // If true, connection_type is "video" (audio + video + screenshare)
171
- // If false, connection_type is "audio" (audio only)
172
- startWithVideoOn?: boolean; // Optional: Start with camera on (default: false)
173
- // Only works if enableVideo is true
174
- ttsEnabled?: boolean; // Optional: Enable text-to-speech (default: true)
175
- actionConfig?: ActionConfig; // Optional: Action configuration
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
- **Note:** Audio is always enabled - the microphone is always active when connected. Use `enableVideo` to control whether video capabilities are available.
238
+ ### About endUserId
180
239
 
181
- ## Advanced Usage
240
+ The `endUserId` parameter is **optional** and serves two important purposes:
182
241
 
183
- ### Sending Messages
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
- ```tsx
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
- // Send trigger message
190
- convaiClient.sendTriggerMessage("greet", "Custom greeting");
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
- // Update template keys
193
- convaiClient.updateTemplateKeys({
194
- user_name: "John",
195
- location: "New York",
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
- // Update dynamic info
199
- convaiClient.updateDynamicInfo({
200
- text: "Additional context for the character",
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
- ### Control Audio/Video
266
+ ## Browser Support
205
267
 
206
- ```tsx
207
- // Toggle microphone
208
- await convaiClient.audioControls.toggleAudio();
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
- // Enable/disable video
215
- await convaiClient.videoControls.enableVideo();
216
- await convaiClient.videoControls.disableVideo();
273
+ ## Package Structure
217
274
 
218
- // Toggle screen share
219
- await convaiClient.screenShareControls.toggleScreenShare();
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
- ### Session Management
283
+ ## 🔄 Migration from Previous Versions
223
284
 
224
- ```tsx
225
- // Reset session (clears history)
226
- convaiClient.resetSession();
285
+ ### Backward Compatible
227
286
 
228
- // Disconnect
229
- await convaiClient.disconnect();
287
+ No breaking changes! Existing code continues to work:
230
288
 
231
- // Reconnect with new session
232
- await convaiClient.connect(config);
289
+ ```tsx
290
+ // Still works
291
+ import { useConvaiClient, ConvaiWidget } from '@convai/web-sdk';
233
292
  ```
234
293
 
235
- ## Advanced Usage
294
+ ### New Features Available
236
295
 
237
- ### Custom Audio/Video Rendering
296
+ ```tsx
297
+ // New: Explicit React import
298
+ import { useConvaiClient } from '@convai/web-sdk/react';
238
299
 
239
- For custom implementations, you can use the exported `AudioRenderer` and `AudioContext` components:
300
+ // New: Vanilla JS/TS support
301
+ import { ConvaiClient, ConvaiWidget } from '@convai/web-sdk/vanilla';
240
302
 
241
- ```tsx
242
- import { useConvaiClient, AudioRenderer, AudioContext } from "@convai/web-sdk";
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
- **Note:** `AudioRenderer` and `AudioContext` are re-exported from `@livekit/components-react` for convenience. These are required for proper audio/video functionality when building custom UIs instead of using `ConvaiWidget`.
307
+ ## 🎓 Examples
260
308
 
261
- ## TypeScript Support
309
+ - [React Example](./examples/react/) - Complete React application
310
+ - More examples coming soon!
262
311
 
263
- The SDK is written in TypeScript and provides full type definitions. Import types as needed:
312
+ ## Best Practices
264
313
 
265
- ```tsx
266
- import {
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
- AudioRenderer,
272
- AudioContext,
273
- } from "@convai/web-sdk";
331
+ AudioControls,
332
+ VideoControls,
333
+ ScreenShareControls,
334
+ } from '@convai/web-sdk';
274
335
  ```
275
336
 
276
- ## License
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,CAuoBpD,CAAC"}
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",