@headwai/chat-bubble 1.0.3 → 2.0.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.
- package/README.dev.md +604 -0
- package/README.md +160 -442
- package/dist/index.iife.js +60 -60
- package/dist/index.js +2227 -2154
- package/dist/index.umd.cjs +60 -60
- package/dist/style.css +1 -1
- package/dist-widget/chat-bubble.css +1 -1
- package/dist-widget/chat-bubble.js +60 -60
- package/package.json +2 -2
package/README.dev.md
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
# Chat Bubble Svelte
|
|
2
|
+
|
|
3
|
+
The chat bubble is based on a Svelte integration for the [deep-chat](https://www.npmjs.com/package/deep-chat) component, providing an easy-to-use AI chat interface for your web applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 Easy integration
|
|
8
|
+
- 🔧 Configurable via environment variables
|
|
9
|
+
- 💬 Support for various AI providers (LocalChat, OpenAI and more)
|
|
10
|
+
- 📱 Responsive design
|
|
11
|
+
- 🎨 Customizable UI components
|
|
12
|
+
- 🔄 Real-time messaging with WebSocket support
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### Prerequisites
|
|
17
|
+
|
|
18
|
+
- Node.js (version 16 or higher)
|
|
19
|
+
- npm or yarn
|
|
20
|
+
|
|
21
|
+
### Setup
|
|
22
|
+
|
|
23
|
+
1. Clone this repository:
|
|
24
|
+
```bash
|
|
25
|
+
git clone <your-repo-url>
|
|
26
|
+
cd chat-bubble
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. Install dependencies:
|
|
30
|
+
```bash
|
|
31
|
+
npm install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
3. Create a `.env` file in the root directory:
|
|
35
|
+
```bash
|
|
36
|
+
cp .env.example .env
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
4. Configure your environment variables (see [Configuration](#configuration) section)
|
|
40
|
+
|
|
41
|
+
5. Start the development server:
|
|
42
|
+
```bash
|
|
43
|
+
npm run dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
The deep-chat component can be configured using environment variables. Create a `.env` file in your project root with the following variables:
|
|
49
|
+
|
|
50
|
+
### Required Environment Variables
|
|
51
|
+
|
|
52
|
+
```env
|
|
53
|
+
# API Configuration
|
|
54
|
+
VITE_CHAT_BUBBLE_API_URL=https://your-api-endpoint.com/api/chat/completions
|
|
55
|
+
VITE_CHAT_BUBBLE_API_KEY=your-api-key-here
|
|
56
|
+
VITE_CHAT_BUBBLE_MODEL_ID=gpt-3.5-turbo
|
|
57
|
+
|
|
58
|
+
# Connection Type (websocket, openAI, etc.)
|
|
59
|
+
VITE_CHAT_BUBBLE_CONNECTION_TYPE=websocket
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Optional Environment Variables
|
|
63
|
+
|
|
64
|
+
```env
|
|
65
|
+
# Additional Headers
|
|
66
|
+
VITE_CHAT_BUBBLE_CONTENT_TYPE=application/json
|
|
67
|
+
|
|
68
|
+
# Request Configuration
|
|
69
|
+
VITE_CHAT_BUBBLE_MAX_MESSAGES=0
|
|
70
|
+
|
|
71
|
+
# UI Configuration
|
|
72
|
+
VITE_CHAT_BUBBLE_PLACEHOLDER_TEXT=Welcome to the chat!
|
|
73
|
+
VITE_CHAT_BUBBLE_DEMO_MODE=false
|
|
74
|
+
VITE_CHAT_BUBBLE_FAVICON_PATH=/icons/favicon.svg
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
### Basic Integration
|
|
80
|
+
|
|
81
|
+
To integrate the deep-chat component into your Svelte application:
|
|
82
|
+
|
|
83
|
+
1. **Install the package** (if using as a standalone package):
|
|
84
|
+
```bash
|
|
85
|
+
npm install deep-chat
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
2. **Import and use in your Svelte component**:
|
|
89
|
+
|
|
90
|
+
```svelte
|
|
91
|
+
<script>
|
|
92
|
+
import { DeepChat } from "deep-chat";
|
|
93
|
+
|
|
94
|
+
// Configuration using environment variables
|
|
95
|
+
const connect = {
|
|
96
|
+
type: import.meta.env.VITE_CHAT_BUBBLE_CONNECTION_TYPE || "websocket",
|
|
97
|
+
url: import.meta.env.VITE_CHAT_BUBBLE_API_URL,
|
|
98
|
+
headers: {
|
|
99
|
+
Authorization: `Bearer ${import.meta.env.VITE_CHAT_BUBBLE_API_KEY}`,
|
|
100
|
+
"Content-Type": import.meta.env.VITE_CHAT_BUBBLE_CONTENT_TYPE || "application/json"
|
|
101
|
+
},
|
|
102
|
+
additionalBodyProps: {
|
|
103
|
+
model: import.meta.env.VITE_CHAT_BUBBLE_MODEL_ID
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const requestBodyLimits = {
|
|
108
|
+
maxMessages: parseInt(import.meta.env.VITE_CHAT_BUBBLE_MAX_MESSAGES) || 0
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const textInputConfig = {
|
|
112
|
+
placeholder: {
|
|
113
|
+
text: import.meta.env.VITE_CHAT_BUBBLE_PLACEHOLDER_TEXT || "Type your message..."
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Message transformation for OpenAI compatibility
|
|
118
|
+
const requestInterceptor = (details) => {
|
|
119
|
+
if (details.body && details.body.messages) {
|
|
120
|
+
details.body.messages = details.body.messages.map(message => ({
|
|
121
|
+
role: message.role === "ai" ? "assistant" : message.role,
|
|
122
|
+
content: message.text || message.content
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
return details;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const responseInterceptor = (response) => {
|
|
129
|
+
if (response.choices && response.choices[0] && response.choices[0].message) {
|
|
130
|
+
const message = response.choices[0].message;
|
|
131
|
+
return {
|
|
132
|
+
text: message.content,
|
|
133
|
+
role: message.role === "assistant" ? "ai" : message.role
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (response.text || response.html || response.files) {
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof response === 'string') {
|
|
142
|
+
return { text: response };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return response;
|
|
146
|
+
};
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<deep-chat
|
|
150
|
+
demo={import.meta.env.VITE_CHAT_BUBBLE_DEMO_MODE === 'true'}
|
|
151
|
+
textInput={textInputConfig}
|
|
152
|
+
connect={connect}
|
|
153
|
+
requestBodyLimits={requestBodyLimits}
|
|
154
|
+
requestInterceptor={requestInterceptor}
|
|
155
|
+
responseInterceptor={responseInterceptor}
|
|
156
|
+
/>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Including Chat Bubble in Customer Websites
|
|
160
|
+
|
|
161
|
+
#### Customizing Message Colors
|
|
162
|
+
|
|
163
|
+
You can customize the background colors and text colors of user and AI messages, as well as the assistant icon color, in several ways:
|
|
164
|
+
|
|
165
|
+
**Via environment variables (.env file):**
|
|
166
|
+
```env
|
|
167
|
+
# Message styling
|
|
168
|
+
VITE_CHAT_BUBBLE_USER_MESSAGE_BG_COLOR=#007bff
|
|
169
|
+
VITE_CHAT_BUBBLE_AI_MESSAGE_BG_COLOR=#f1f3f4
|
|
170
|
+
VITE_CHAT_BUBBLE_USER_MESSAGE_TEXT_COLOR=#ffffff
|
|
171
|
+
VITE_CHAT_BUBBLE_AI_MESSAGE_TEXT_COLOR=#000000
|
|
172
|
+
|
|
173
|
+
# Assistant icon styling (creates a gradient automatically)
|
|
174
|
+
VITE_CHAT_BUBBLE_FAVICON_BG_COLOR=#667eea
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Via runtime configuration (Script Embed - Option 2):**
|
|
178
|
+
```html
|
|
179
|
+
<script>
|
|
180
|
+
window.HEADWAI_CHAT_BUBBLE_CONFIG = {
|
|
181
|
+
apiUrl: 'https://customer-api.com/chat',
|
|
182
|
+
apiKey: 'customer-api-key',
|
|
183
|
+
userMessageBackgroundColor: '#4a90e2', // Blue background for user messages
|
|
184
|
+
aiMessageBackgroundColor: '#e8f5e8', // Light green background for AI messages
|
|
185
|
+
userMessageTextColor: '#ffffff', // White text for user messages
|
|
186
|
+
aiMessageTextColor: '#2d5016', // Dark green text for AI messages
|
|
187
|
+
faviconBackgroundColor: '#28a745' // Green icon (gradient auto-generated)
|
|
188
|
+
};
|
|
189
|
+
</script>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Via props (NPM Package - Option 3):**
|
|
193
|
+
```svelte
|
|
194
|
+
<script>
|
|
195
|
+
import { ChatBubble } from '@headwai/chat-bubble';
|
|
196
|
+
</script>
|
|
197
|
+
|
|
198
|
+
<ChatBubble
|
|
199
|
+
apiUrl="https://api.example.com/chat"
|
|
200
|
+
apiKey="your-api-key"
|
|
201
|
+
userMessageBackgroundColor="#ff6b6b" <!-- Red background for user messages -->
|
|
202
|
+
aiMessageBackgroundColor="#4ecdc4" <!-- Teal background for AI messages -->
|
|
203
|
+
userMessageTextColor="#ffffff" <!-- White text for user messages -->
|
|
204
|
+
aiMessageTextColor="#2c3e50" <!-- Dark blue text for AI messages -->
|
|
205
|
+
faviconBackgroundColor="#e74c3c" <!-- Red icon (gradient auto-generated) -->
|
|
206
|
+
{/* ...other props */}
|
|
207
|
+
/>
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Via data attributes (Multiple chat bubbles):**
|
|
211
|
+
```html
|
|
212
|
+
<div data-chat-bubble
|
|
213
|
+
data-chat-bubble-api-url="https://api1.com/chat"
|
|
214
|
+
data-chat-bubble-api-key="key1"
|
|
215
|
+
data-chat-bubble-user-message-background-color="#ff9500"
|
|
216
|
+
data-chat-bubble-ai-message-background-color="#00c851"
|
|
217
|
+
data-chat-bubble-user-message-text-color="#ffffff"
|
|
218
|
+
data-chat-bubble-ai-message-text-color="#004225"
|
|
219
|
+
data-chat-bubble-assistant-icon-color="#ff6f00"></div>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Color Suggestions for Assistant Icon:**
|
|
223
|
+
- **Corporate Blue:** `#0066cc` (creates blue gradient)
|
|
224
|
+
- **Success Green:** `#28a745` (creates green gradient)
|
|
225
|
+
- **Warning Orange:** `#fd7e14` (creates orange gradient)
|
|
226
|
+
- **Danger Red:** `#dc3545` (creates red gradient)
|
|
227
|
+
- **Purple:** `#6f42c1` (creates purple gradient)
|
|
228
|
+
- **Teal:** `#20c997` (creates teal gradient)
|
|
229
|
+
|
|
230
|
+
The component automatically creates a beautiful linear gradient by making the second color 20% darker than your chosen base color.
|
|
231
|
+
|
|
232
|
+
#### Option 1: Build and Deploy (Complete Application)
|
|
233
|
+
|
|
234
|
+
This option bundles everything into a ready-to-use application including all interceptors and logic.
|
|
235
|
+
|
|
236
|
+
**What gets bundled:**
|
|
237
|
+
- ✅ Request/Response interceptors (OpenAI compatibility)
|
|
238
|
+
- ✅ Environment variable configuration
|
|
239
|
+
- ✅ All chat functionality
|
|
240
|
+
- ✅ UI components and styling
|
|
241
|
+
|
|
242
|
+
**Build and deployment steps:**
|
|
243
|
+
1. **Configure environment variables** for production:
|
|
244
|
+
```bash
|
|
245
|
+
# Production .env file
|
|
246
|
+
VITE_CHAT_BUBBLE_API_URL=https://api.customer-domain.com/chat
|
|
247
|
+
VITE_CHAT_BUBBLE_API_KEY=prod-api-key
|
|
248
|
+
VITE_CHAT_BUBBLE_MODEL_ID=gpt-4
|
|
249
|
+
VITE_CHAT_BUBBLE_CONNECTION_TYPE=websocket
|
|
250
|
+
VITE_CHAT_BUBBLE_DEMO_MODE=false
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
2. **Build the widget**:
|
|
254
|
+
```bash
|
|
255
|
+
npm run build:widget
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
3. **Deploy the `dist-widget` folder** to your web server or CDN.
|
|
259
|
+
|
|
260
|
+
**Result:** Customers get a complete chat application - no additional coding required!
|
|
261
|
+
|
|
262
|
+
#### Option 2: Embed Chat Bubble as Script (Plug-and-Play)
|
|
263
|
+
|
|
264
|
+
After building the widget, you can include the chat component in any website as a complete widget.
|
|
265
|
+
|
|
266
|
+
**Build steps:**
|
|
267
|
+
1. **Build the widget**:
|
|
268
|
+
```bash
|
|
269
|
+
npm run build:widget
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
2. **Publish to NPM** (for jsDelivr access):
|
|
273
|
+
```bash
|
|
274
|
+
npm publish
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Customer integration:**
|
|
278
|
+
```html
|
|
279
|
+
<!DOCTYPE html>
|
|
280
|
+
<html>
|
|
281
|
+
<head>
|
|
282
|
+
<title>Customer Website</title>
|
|
283
|
+
<!-- Configure via global variables -->
|
|
284
|
+
<script>
|
|
285
|
+
// Runtime configuration override
|
|
286
|
+
window.HEADWAI_CHAT_BUBBLE_CONFIG = {
|
|
287
|
+
apiUrl: 'https://customer-api.com/chat',
|
|
288
|
+
apiKey: 'customer-api-key',
|
|
289
|
+
modelId: 'gpt-4',
|
|
290
|
+
connectionType: 'websocket'
|
|
291
|
+
};
|
|
292
|
+
</script>
|
|
293
|
+
</head>
|
|
294
|
+
<body>
|
|
295
|
+
<!-- Your existing content -->
|
|
296
|
+
|
|
297
|
+
<!-- Chat Bubble Integration - Auto-initializes! -->
|
|
298
|
+
<div id="chat-bubble-container"></div>
|
|
299
|
+
|
|
300
|
+
<!-- Include from jsDelivr CDN -->
|
|
301
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.css">
|
|
302
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.js"></script>
|
|
303
|
+
</body>
|
|
304
|
+
</html>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**Alternative: Multiple chat bubbles with data attributes:**
|
|
308
|
+
```html
|
|
309
|
+
<!-- Chat bubble with specific configuration -->
|
|
310
|
+
<div data-chat-bubble
|
|
311
|
+
data-chat-bubble-api-url="https://api1.com/chat"
|
|
312
|
+
data-chat-bubble-api-key="key1"></div>
|
|
313
|
+
|
|
314
|
+
<!-- Another chat bubble with different config -->
|
|
315
|
+
<div data-chat-bubble
|
|
316
|
+
data-chat-bubble-api-url="https://api2.com/chat"
|
|
317
|
+
data-chat-bubble-api-key="key2"></div>
|
|
318
|
+
|
|
319
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.js"></script>
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**What customers get:**
|
|
323
|
+
- ✅ Complete chat interface
|
|
324
|
+
- ✅ All interceptors included
|
|
325
|
+
- ✅ OpenAI API compatibility built-in
|
|
326
|
+
- ✅ Just needs API configuration
|
|
327
|
+
- ✅ Auto-initialization on page load
|
|
328
|
+
|
|
329
|
+
#### Option 3: NPM Package Integration (Developer Integration)
|
|
330
|
+
|
|
331
|
+
For developers who need full control and customization.
|
|
332
|
+
|
|
333
|
+
**Build and publish steps:**
|
|
334
|
+
1. **Build the library**:
|
|
335
|
+
```bash
|
|
336
|
+
npm run build:lib
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
2. **Publish to NPM**:
|
|
340
|
+
```bash
|
|
341
|
+
npm publish
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Customer installation:**
|
|
345
|
+
```bash
|
|
346
|
+
# Install in customer's project
|
|
347
|
+
npm install @headwai/chat-bubble
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
**For Svelte projects:**
|
|
351
|
+
```svelte
|
|
352
|
+
<!-- Customer's Svelte component -->
|
|
353
|
+
<script>
|
|
354
|
+
import { ChatBubble } from '@headwai/chat-bubble';
|
|
355
|
+
|
|
356
|
+
// Customers MUST implement these interceptors themselves
|
|
357
|
+
const requestInterceptor = (details) => {
|
|
358
|
+
if (details.body && details.body.messages) {
|
|
359
|
+
details.body.messages = details.body.messages.map(message => ({
|
|
360
|
+
role: message.role === "ai" ? "assistant" : message.role,
|
|
361
|
+
content: message.text || message.content
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
return details;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const responseInterceptor = (response) => {
|
|
368
|
+
if (response.choices && response.choices[0] && response.choices[0].message) {
|
|
369
|
+
const message = response.choices[0].message;
|
|
370
|
+
return {
|
|
371
|
+
text: message.content,
|
|
372
|
+
role: message.role === "assistant" ? "ai" : message.role
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
return response;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const connect = {
|
|
379
|
+
type: "websocket",
|
|
380
|
+
url: process.env.API_URL,
|
|
381
|
+
headers: {
|
|
382
|
+
Authorization: `Bearer ${process.env.API_KEY}`,
|
|
383
|
+
"Content-Type": "application/json"
|
|
384
|
+
},
|
|
385
|
+
additionalBodyProps: {
|
|
386
|
+
model: process.env.MODEL_NAME
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
</script>
|
|
390
|
+
|
|
391
|
+
<ChatBubble
|
|
392
|
+
connect={connect}
|
|
393
|
+
requestInterceptor={requestInterceptor}
|
|
394
|
+
responseInterceptor={responseInterceptor}
|
|
395
|
+
/>
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**For vanilla JavaScript projects:**
|
|
399
|
+
```html
|
|
400
|
+
<script type="module">
|
|
401
|
+
import { createChatBubble } from 'https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist/index.js';
|
|
402
|
+
|
|
403
|
+
// Initialize manually with custom configuration
|
|
404
|
+
const chatBubble = createChatBubble(
|
|
405
|
+
document.getElementById('chat-container'),
|
|
406
|
+
{
|
|
407
|
+
apiUrl: 'https://api.example.com/chat',
|
|
408
|
+
apiKey: 'your-api-key',
|
|
409
|
+
// ... other props
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
</script>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**What customers need to implement:**
|
|
416
|
+
- ❌ Request/Response interceptors (manual setup required)
|
|
417
|
+
- ❌ Environment variable handling
|
|
418
|
+
- ❌ API configuration logic
|
|
419
|
+
- ✅ Deep chat component only
|
|
420
|
+
|
|
421
|
+
## Deployment Options Comparison
|
|
422
|
+
|
|
423
|
+
| Feature | Built App (Option 1) | Script Embed (Option 2) | NPM Package (Option 3) |
|
|
424
|
+
|---------|----------------------|--------------------------|-------------------------|
|
|
425
|
+
| **Build Command** | `npm run build:widget` | `npm run build:widget` + publish | `npm run build:lib` + publish |
|
|
426
|
+
| **Interceptors Included** | ✅ Yes, automatically | ✅ Yes, automatically | ❌ No, manual setup required |
|
|
427
|
+
| **Environment Variables** | ✅ Built-in support | ✅ Runtime configuration | ❌ Customer implements |
|
|
428
|
+
| **OpenAI Compatibility** | ✅ Ready to use | ✅ Ready to use | ❌ Customer implements |
|
|
429
|
+
| **Setup Complexity** | 🟢 Minimal (just config) | � Minimal (script tag) | �🟡 Moderate (coding required) |
|
|
430
|
+
| **Customization** | 🟡 Limited to env vars | � Limited to config object | �🟢 Full control |
|
|
431
|
+
| **File Size** | 🟡 Larger (complete app) | � Larger (complete app) | �🟢 Smaller (just component) |
|
|
432
|
+
| **Use Case** | Self-hosted deployment | CDN/jsDelivr embedding | Developers, custom integration |
|
|
433
|
+
| **Auto-initialization** | ✅ Yes | ✅ Yes | ❌ Manual setup |
|
|
434
|
+
|
|
435
|
+
### Recommended Approach
|
|
436
|
+
|
|
437
|
+
**For most customers:** Use **Option 2** (Script Embed via jsDelivr)
|
|
438
|
+
- ✅ No coding required
|
|
439
|
+
- ✅ All interceptors included
|
|
440
|
+
- ✅ Easy CDN access via jsDelivr
|
|
441
|
+
- ✅ Just configure via JavaScript object
|
|
442
|
+
- ✅ Ready-to-deploy solution
|
|
443
|
+
- ✅ Auto-initialization
|
|
444
|
+
|
|
445
|
+
**For self-hosted deployments:** Use **Option 1** (Built Application)
|
|
446
|
+
- ✅ Complete control over hosting
|
|
447
|
+
- ✅ No external CDN dependencies
|
|
448
|
+
- ✅ All interceptors included
|
|
449
|
+
- ✅ Environment variable configuration
|
|
450
|
+
|
|
451
|
+
**For developers who need customization:** Use **Option 3** (NPM Package)
|
|
452
|
+
- ✅ Full control over interceptors
|
|
453
|
+
- ✅ Custom API integrations
|
|
454
|
+
- ✅ Smaller bundle size
|
|
455
|
+
- ❌ More setup required
|
|
456
|
+
|
|
457
|
+
## Publishing to NPM and jsDelivr Access
|
|
458
|
+
|
|
459
|
+
### Publishing Steps
|
|
460
|
+
|
|
461
|
+
1. **Build both library and widget**:
|
|
462
|
+
```bash
|
|
463
|
+
npm run build
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
2. **Login to NPM** (if not already logged in):
|
|
467
|
+
```bash
|
|
468
|
+
npm login
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
3. **Publish the package**:
|
|
472
|
+
```bash
|
|
473
|
+
npm publish
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### jsDelivr CDN Access
|
|
477
|
+
|
|
478
|
+
Once published to NPM, your package is automatically available on jsDelivr:
|
|
479
|
+
|
|
480
|
+
**For Widget/Script Embed (Options 1 & 2):**
|
|
481
|
+
```html
|
|
482
|
+
<!-- Latest version -->
|
|
483
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.css">
|
|
484
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.js"></script>
|
|
485
|
+
|
|
486
|
+
<!-- Specific version -->
|
|
487
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.css">
|
|
488
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.js"></script>
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**For Library/Module Import (Option 3):**
|
|
492
|
+
```html
|
|
493
|
+
<!-- ES Module -->
|
|
494
|
+
<script type="module">
|
|
495
|
+
import { ChatBubble, createChatBubble } from 'https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist/index.js';
|
|
496
|
+
</script>
|
|
497
|
+
|
|
498
|
+
<!-- UMD (Universal Module Definition) -->
|
|
499
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist/index.umd.js"></script>
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### File Structure After Build
|
|
503
|
+
|
|
504
|
+
```
|
|
505
|
+
dist/ # NPM package (Option 3)
|
|
506
|
+
├── index.js # ES module
|
|
507
|
+
├── index.umd.js # UMD module
|
|
508
|
+
└── style.css # Component styles
|
|
509
|
+
|
|
510
|
+
dist-widget/ # Standalone widget (Options 1 & 2)
|
|
511
|
+
├── widget.html # Demo page
|
|
512
|
+
├── chat-bubble.js # Complete widget with auto-init
|
|
513
|
+
├── chat-bubble.css # Widget styles
|
|
514
|
+
└── assets/ # Additional assets
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
## Environment Variables Reference
|
|
518
|
+
|
|
519
|
+
| Variable | Description | Default | Required |
|
|
520
|
+
|----------|-------------|---------|----------|
|
|
521
|
+
| `VITE_CHAT_BUBBLE_API_URL` | The API endpoint URL | - | ✅ |
|
|
522
|
+
| `VITE_CHAT_BUBBLE_API_KEY` | API authentication key | - | ✅ |
|
|
523
|
+
| `VITE_CHAT_BUBBLE_MODEL_ID` | AI model name to use | `gpt-3.5-turbo` | ✅ |
|
|
524
|
+
| `VITE_CHAT_BUBBLE_CONNECTION_TYPE` | Connection type (websocket, openAI, etc.) | `websocket` | ✅ |
|
|
525
|
+
| `VITE_CHAT_BUBBLE_CONTENT_TYPE` | HTTP Content-Type header | `application/json` | ❌ |
|
|
526
|
+
| `VITE_CHAT_BUBBLE_MAX_MESSAGES` | Maximum messages in conversation history | `0` (unlimited) | ❌ |
|
|
527
|
+
| `VITE_CHAT_BUBBLE_PLACEHOLDER_TEXT` | Chat input placeholder text | `Type your message...` | ❌ |
|
|
528
|
+
| `VITE_CHAT_BUBBLE_DEMO_MODE` | Enable demo mode | `false` | ❌ |
|
|
529
|
+
| `VITE_CHAT_BUBBLE_FAVICON_PATH` | Path to favicon/icon for chat toggle button | `/icons/favicon.svg` | ❌ |
|
|
530
|
+
| `VITE_CHAT_BUBBLE_USER_MESSAGE_BG_COLOR` | Background color for user messages | `#007bff` | ❌ |
|
|
531
|
+
| `VITE_CHAT_BUBBLE_AI_MESSAGE_BG_COLOR` | Background color for AI messages | `#f1f3f4` | ❌ |
|
|
532
|
+
| `VITE_CHAT_BUBBLE_USER_MESSAGE_TEXT_COLOR` | Text color for user messages | `#000000` | ❌ |
|
|
533
|
+
| `VITE_CHAT_BUBBLE_AI_MESSAGE_TEXT_COLOR` | Text color for AI messages | `#000000` | ❌ |
|
|
534
|
+
| `VITE_CHAT_BUBBLE_FAVICON_BG_COLOR` | Base color for assistant icon gradient | `#667eea` | ❌ |
|
|
535
|
+
|
|
536
|
+
## API Compatibility
|
|
537
|
+
|
|
538
|
+
This component is designed to work with OpenAI-compatible APIs. The request and response interceptors handle the message format transformation between deep-chat and OpenAI formats.
|
|
539
|
+
|
|
540
|
+
### Supported Message Flow
|
|
541
|
+
|
|
542
|
+
1. **User Input** → Deep Chat format
|
|
543
|
+
2. **Request Interceptor** → Transforms to OpenAI format
|
|
544
|
+
3. **API Call** → Your configured endpoint
|
|
545
|
+
4. **Response Interceptor** → Transforms back to Deep Chat format
|
|
546
|
+
5. **Display** → Rendered in chat interface
|
|
547
|
+
|
|
548
|
+
## Development
|
|
549
|
+
|
|
550
|
+
### Scripts
|
|
551
|
+
|
|
552
|
+
- `npm run dev` - Start development server
|
|
553
|
+
- `npm run build` - Build both library and widget for production
|
|
554
|
+
- `npm run build:lib` - Build NPM package (Option 3)
|
|
555
|
+
- `npm run build:widget` - Build standalone widget (Options 1 & 2)
|
|
556
|
+
- `npm run build:app` - Build demo application
|
|
557
|
+
- `npm run preview` - Preview production build
|
|
558
|
+
|
|
559
|
+
### Project Structure
|
|
560
|
+
|
|
561
|
+
```
|
|
562
|
+
chat-bubble/
|
|
563
|
+
├── src/
|
|
564
|
+
│ ├── App.svelte # Main chat component
|
|
565
|
+
│ ├── main.js # Development entry point
|
|
566
|
+
│ ├── lib.js # NPM package entry point
|
|
567
|
+
│ └── widget.js # Widget/standalone entry point
|
|
568
|
+
├── dist/ # NPM package build output
|
|
569
|
+
├── dist-widget/ # Widget build output
|
|
570
|
+
├── package.json # Dependencies and scripts
|
|
571
|
+
├── vite.config.js # Default Vite configuration
|
|
572
|
+
├── vite.lib.config.js # Library build configuration
|
|
573
|
+
├── vite.widget.config.js # Widget build configuration
|
|
574
|
+
├── vite.app.config.js # App build configuration
|
|
575
|
+
├── svelte.config.js # Svelte configuration
|
|
576
|
+
├── index.html # Development HTML
|
|
577
|
+
├── widget.html # Widget HTML template
|
|
578
|
+
└── README.md # This file
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
## Troubleshooting
|
|
582
|
+
|
|
583
|
+
### Common Issues
|
|
584
|
+
|
|
585
|
+
1. **CORS Errors**: Ensure your API endpoint allows requests from your domain
|
|
586
|
+
2. **Authentication Failures**: Verify your API key is correct and has proper permissions
|
|
587
|
+
3. **WebSocket Connection Issues**: Check if your API supports WebSocket connections
|
|
588
|
+
4. **Environment Variables Not Loading**: Ensure variables are prefixed with `VITE_CHAT_BUBBLE_`
|
|
589
|
+
|
|
590
|
+
### Debug Mode
|
|
591
|
+
|
|
592
|
+
Enable debug mode by setting:
|
|
593
|
+
```env
|
|
594
|
+
VITE_CHAT_BUBBLE_DEMO_MODE=true
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
This will enable demo features that can help test the component without a real API connection.
|
|
598
|
+
|
|
599
|
+
## Support
|
|
600
|
+
|
|
601
|
+
For issues and questions:
|
|
602
|
+
- Create an issue in this repository
|
|
603
|
+
- Check the [deep-chat documentation](https://deepchat.dev/)
|
|
604
|
+
- Review the [API compatibility guide](https://deepchat.dev/docs/connect)
|