@convai/web-sdk 0.2.3 → 0.2.4

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 (2) hide show
  1. package/README.md +157 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -79,6 +79,163 @@ function App() {
79
79
 
80
80
  **That's it!** The widget auto-connects on first user interaction and handles all UI/audio for you.
81
81
 
82
+ ---
83
+
84
+ ## 🤖 For AI Code Generators (v0, Lovable, Bolt, etc.)
85
+
86
+ **If you're using an AI coding assistant to add Convai to your project, use this exact template to avoid errors:**
87
+
88
+ ### Copy-Paste Template (Works Every Time)
89
+
90
+ ```tsx
91
+ import { useConvaiClient, ConvaiWidget } from "@convai/web-sdk/react";
92
+
93
+ export default function App() {
94
+ // Step 1: Create the client with your credentials
95
+ const convaiClient = useConvaiClient({
96
+ apiKey: "your-api-key-here",
97
+ characterId: "your-character-id-here"
98
+ });
99
+
100
+ // Step 2: Pass ONLY the client to the widget
101
+ return <ConvaiWidget convaiClient={convaiClient} />;
102
+ }
103
+ ```
104
+
105
+ ### Common Mistakes AI Tools Make
106
+
107
+ ❌ **DON'T DO THIS:**
108
+ ```tsx
109
+ // Wrong: Passing props directly to ConvaiWidget
110
+ <ConvaiWidget apiKey="..." characterId="..." />
111
+
112
+ // Wrong: Stringifying the client
113
+ <ConvaiWidget convaiClient={JSON.stringify(convaiClient)} />
114
+
115
+ // Wrong: Spreading client properties
116
+ <ConvaiWidget {...convaiClient} />
117
+
118
+ // Wrong: Using client in string context
119
+ const info = `Client: ${convaiClient}`; // "Cannot convert object to primitive value"
120
+
121
+ // Wrong: Passing client through env vars
122
+ const client = process.env.CONVAI_CLIENT; // This won't work
123
+ ```
124
+
125
+ ✅ **DO THIS:**
126
+ ```tsx
127
+ // Correct: Client created in component, passed as object
128
+ const convaiClient = useConvaiClient({
129
+ apiKey: "your-api-key",
130
+ characterId: "your-character-id"
131
+ });
132
+
133
+ return <ConvaiWidget convaiClient={convaiClient} />;
134
+ ```
135
+
136
+ ### If You Get "Cannot convert object to primitive value"
137
+
138
+ This error means you're using the client object in a primitive context. Check for:
139
+
140
+ 1. **String concatenation:**
141
+ ```tsx
142
+ // ❌ Wrong
143
+ console.log("Client: " + convaiClient);
144
+
145
+ // ✅ Correct
146
+ console.log("Connected:", convaiClient.state.isConnected);
147
+ ```
148
+
149
+ 2. **Template literals:**
150
+ ```tsx
151
+ // ❌ Wrong
152
+ const text = `Client: ${convaiClient}`;
153
+
154
+ // ✅ Correct
155
+ const text = `Status: ${convaiClient.state.agentState}`;
156
+ ```
157
+
158
+ 3. **Using as a key:**
159
+ ```tsx
160
+ // ❌ Wrong
161
+ <div key={convaiClient}>...</div>
162
+
163
+ // ✅ Correct
164
+ <div key="convai-widget">...</div>
165
+ ```
166
+
167
+ ### Complete Working Example for AI Tools
168
+
169
+ ```tsx
170
+ import React from 'react';
171
+ import { useConvaiClient, ConvaiWidget } from "@convai/web-sdk/react";
172
+
173
+ function App() {
174
+ // Initialize the client
175
+ const convaiClient = useConvaiClient({
176
+ apiKey: "your-api-key-here",
177
+ characterId: "your-character-id-here",
178
+ enableVideo: false, // Set to true if you need video
179
+ });
180
+
181
+ // Optional: Add debug logging
182
+ console.log("Convai client initialized:", !!convaiClient);
183
+ console.log("Connection status:", convaiClient?.state?.isConnected);
184
+
185
+ return (
186
+ <div style={{ width: '100vw', height: '100vh' }}>
187
+ <ConvaiWidget convaiClient={convaiClient} />
188
+ </div>
189
+ );
190
+ }
191
+
192
+ export default App;
193
+ ```
194
+
195
+ ### Prompt for AI Code Generators
196
+
197
+ **Use this prompt to get correct code:**
198
+
199
+ ```
200
+ Add Convai voice chat to this app using @convai/web-sdk.
201
+
202
+ CRITICAL RULES:
203
+ 1. Import: import { useConvaiClient, ConvaiWidget } from "@convai/web-sdk/react";
204
+ 2. Create client INSIDE component: const convaiClient = useConvaiClient({ apiKey: "...", characterId: "..." });
205
+ 3. Pass ONLY client to widget: <ConvaiWidget convaiClient={convaiClient} />
206
+ 4. DO NOT pass apiKey or characterId directly to ConvaiWidget
207
+ 5. DO NOT stringify, spread, or destructure the client object
208
+ 6. DO NOT use the client object in string contexts
209
+
210
+ Example:
211
+ const convaiClient = useConvaiClient({ apiKey: "KEY", characterId: "ID" });
212
+ return <ConvaiWidget convaiClient={convaiClient} />;
213
+ ```
214
+
215
+ ### Video & Screen Share with AI Tools
216
+
217
+ If you need video/screen share, add these TWO changes:
218
+
219
+ ```tsx
220
+ // Step 1: Add enableVideo to client config
221
+ const convaiClient = useConvaiClient({
222
+ apiKey: "your-api-key",
223
+ characterId: "your-character-id",
224
+ enableVideo: true // ← Required for video features
225
+ });
226
+
227
+ // Step 2: Show controls in widget
228
+ <ConvaiWidget
229
+ convaiClient={convaiClient}
230
+ showVideo={true} // ← Shows video button
231
+ showScreenShare={true} // ← Shows screen share button
232
+ />
233
+ ```
234
+
235
+ **Without `enableVideo: true`, video and screen share will NOT work even if you show the buttons.**
236
+
237
+
238
+
82
239
  ### Vanilla JS/TS - ConvaiWidget
83
240
 
84
241
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convai/web-sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Convai Web SDK for AI voice assistants. Supports both React and vanilla JavaScript/TypeScript. Build voice-powered AI interactions with real-time audio/video streaming.",
5
5
  "private": false,
6
6
  "type": "module",