@headwai/chat-bubble 1.0.3 → 2.0.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.dev.md +604 -0
- package/README.md +160 -443
- 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/docs/images/api-keys.png +0 -0
- package/docs/images/model-edit.png +0 -0
- package/docs/images/model-id.png +0 -0
- package/docs/images/settings.png +0 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,209 +1,18 @@
|
|
|
1
|
-
# Chat Bubble
|
|
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.
|
|
1
|
+
# Headwai Chat Bubble
|
|
4
2
|
|
|
5
3
|
## Features
|
|
6
4
|
|
|
7
5
|
- 🚀 Easy integration
|
|
8
|
-
-
|
|
9
|
-
-
|
|
6
|
+
- 💬 Connect to any LocalChat Model
|
|
7
|
+
- 📋 Review conversations in LocalChat
|
|
10
8
|
- 📱 Responsive design
|
|
11
9
|
- 🎨 Customizable UI components
|
|
12
10
|
- 🔄 Real-time messaging with WebSocket support
|
|
13
11
|
|
|
14
|
-
|
|
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_NAME=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
|
|
12
|
+
### Easy Website Integration
|
|
78
13
|
|
|
79
|
-
|
|
14
|
+
Add the Headwai Chat Bubble to the respective .html file.
|
|
80
15
|
|
|
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_NAME
|
|
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
|
-
#### Option 1: Build and Deploy (Complete Application)
|
|
162
|
-
|
|
163
|
-
This option bundles everything into a ready-to-use application including all interceptors and logic.
|
|
164
|
-
|
|
165
|
-
**What gets bundled:**
|
|
166
|
-
- ✅ Request/Response interceptors (OpenAI compatibility)
|
|
167
|
-
- ✅ Environment variable configuration
|
|
168
|
-
- ✅ All chat functionality
|
|
169
|
-
- ✅ UI components and styling
|
|
170
|
-
|
|
171
|
-
**Build and deployment steps:**
|
|
172
|
-
1. **Configure environment variables** for production:
|
|
173
|
-
```bash
|
|
174
|
-
# Production .env file
|
|
175
|
-
VITE_CHAT_BUBBLE_API_URL=https://api.customer-domain.com/chat
|
|
176
|
-
VITE_CHAT_BUBBLE_API_KEY=prod-api-key
|
|
177
|
-
VITE_CHAT_BUBBLE_MODEL_NAME=gpt-4
|
|
178
|
-
VITE_CHAT_BUBBLE_CONNECTION_TYPE=websocket
|
|
179
|
-
VITE_CHAT_BUBBLE_DEMO_MODE=false
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
2. **Build the widget**:
|
|
183
|
-
```bash
|
|
184
|
-
npm run build:widget
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
3. **Deploy the `dist-widget` folder** to your web server or CDN.
|
|
188
|
-
|
|
189
|
-
**Result:** Customers get a complete chat application - no additional coding required!
|
|
190
|
-
|
|
191
|
-
#### Option 2: Embed Chat Bubble as Script (Plug-and-Play)
|
|
192
|
-
|
|
193
|
-
After building the widget, you can include the chat component in any website as a complete widget.
|
|
194
|
-
|
|
195
|
-
**Build steps:**
|
|
196
|
-
1. **Build the widget**:
|
|
197
|
-
```bash
|
|
198
|
-
npm run build:widget
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
2. **Publish to NPM** (for jsDelivr access):
|
|
202
|
-
```bash
|
|
203
|
-
npm publish
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
**Customer integration:**
|
|
207
16
|
```html
|
|
208
17
|
<!DOCTYPE html>
|
|
209
18
|
<html>
|
|
@@ -212,11 +21,19 @@ npm publish
|
|
|
212
21
|
<!-- Configure via global variables -->
|
|
213
22
|
<script>
|
|
214
23
|
// Runtime configuration override
|
|
215
|
-
window.
|
|
216
|
-
apiUrl: 'https://
|
|
217
|
-
apiKey: 'customer-api-key',
|
|
218
|
-
|
|
219
|
-
|
|
24
|
+
window.HEADWAI_CHAT_BUBBLE_CONFIG = {
|
|
25
|
+
apiUrl: 'https://company.localchat.at', // required
|
|
26
|
+
apiKey: 'customer-support-user-api-key', // required
|
|
27
|
+
modelId: 'customer-support-model-id', // required
|
|
28
|
+
maxMessages: 0, // optional - 0 means unlimited
|
|
29
|
+
placeholderText: 'Ask your question here!', // optional - default: 'Enter your questions here'
|
|
30
|
+
faviconPath: 'https://cdn.company.at/icons/favicon.svg', // optional - default: '/icons/favicon.svg'
|
|
31
|
+
initialMessage: 'Hey! My name is Supporty, how can I help you?', // optional - default: 'Hey, how can I help you?'
|
|
32
|
+
userMessageBackgroundColor: '#007bff', // optional - default: '#007bff'
|
|
33
|
+
aiMessageBackgroundColor: '#f1f3f4', // optional - default: '#f1f3f4'
|
|
34
|
+
userMessageTextColor: '#000000', // optional - default: '#000000'
|
|
35
|
+
aiMessageTextColor: '#000000', // optional - default: '#000000'
|
|
36
|
+
faviconBackgroundColor: '#667eea' // optional - default: '#667eea'
|
|
220
37
|
};
|
|
221
38
|
</script>
|
|
222
39
|
</head>
|
|
@@ -233,274 +50,191 @@ npm publish
|
|
|
233
50
|
</html>
|
|
234
51
|
```
|
|
235
52
|
|
|
236
|
-
|
|
53
|
+
Set the configuration of the Headwai Chat Bubble in the `<script>` tag of the `<head>`.
|
|
54
|
+
Get the desired version of the JavaScript and CSS in your `<body>`.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<!-- Latest version -->
|
|
60
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.css">
|
|
61
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.js"></script>
|
|
62
|
+
|
|
63
|
+
<!-- Specific version -->
|
|
64
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.css">
|
|
65
|
+
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.js"></script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Place the Headwai Chat Bubble into the `<body>` tag. It will apear on the right corner of your website.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
#### Multiple Headwai Chat Bubbles
|
|
72
|
+
|
|
73
|
+
For multiple instances use data attributes of the `<div>` tag for configuration instead.
|
|
74
|
+
|
|
237
75
|
```html
|
|
238
76
|
<!-- Chat bubble with specific configuration -->
|
|
239
77
|
<div data-chat-bubble
|
|
240
|
-
data-chat-bubble-api-url="https://
|
|
241
|
-
data-chat-bubble-api-key="
|
|
78
|
+
data-chat-bubble-api-url="https://company.localchat.at"
|
|
79
|
+
data-chat-bubble-api-key="customer-support-user-api-key"
|
|
80
|
+
data-chat-bubble-model-id="customer-support-model-id"
|
|
81
|
+
data-chat-bubble-max-messages="0"
|
|
82
|
+
data-chat-bubble-placeholder-text="Ask your question here!"
|
|
83
|
+
data-chat-bubble-favicon-path="https://cdn.company.at/icons/favicon.svg"
|
|
84
|
+
data-chat-bubble-initial-message="Hey! My name is Supporty, how can I help you?"
|
|
85
|
+
data-chat-bubble-user-message-background-color="#007bff"
|
|
86
|
+
data-chat-bubble-ai-message-background-color="#f1f3f4"
|
|
87
|
+
data-chat-bubble-user-message-text-color="#000000"
|
|
88
|
+
data-chat-bubble-ai-message-text-color="#000000"
|
|
89
|
+
data-chat-bubble-favicon-background-color="#667eea">
|
|
90
|
+
</div>
|
|
242
91
|
|
|
243
92
|
<!-- Another chat bubble with different config -->
|
|
244
93
|
<div data-chat-bubble
|
|
245
|
-
data-chat-bubble-api-url="https://
|
|
246
|
-
data-chat-bubble-api-key="
|
|
94
|
+
data-chat-bubble-api-url="https://company.localchat.at"
|
|
95
|
+
data-chat-bubble-api-key="customer-support-user-api-key"
|
|
96
|
+
data-chat-bubble-model-id="FAQ-model-id"
|
|
97
|
+
data-chat-bubble-max-messages="10"
|
|
98
|
+
data-chat-bubble-placeholder-text="Ask about our FAQ..."
|
|
99
|
+
data-chat-bubble-favicon-path="https://cdn.company.at/icons/faq-icon.svg"
|
|
100
|
+
data-chat-bubble-initial-message="Hello! I can help you with frequently asked questions."
|
|
101
|
+
data-chat-bubble-user-message-background-color="#28a745"
|
|
102
|
+
data-chat-bubble-ai-message-background-color="#e9ecef"
|
|
103
|
+
data-chat-bubble-user-message-text-color="#ffffff"
|
|
104
|
+
data-chat-bubble-ai-message-text-color="#495057"
|
|
105
|
+
data-chat-bubble-favicon-background-color="#28a745">
|
|
106
|
+
</div>
|
|
247
107
|
|
|
108
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.css">
|
|
248
109
|
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist-widget/chat-bubble.js"></script>
|
|
249
110
|
```
|
|
250
111
|
|
|
251
|
-
|
|
252
|
-
- ✅ Complete chat interface
|
|
253
|
-
- ✅ All interceptors included
|
|
254
|
-
- ✅ OpenAI API compatibility built-in
|
|
255
|
-
- ✅ Just needs API configuration
|
|
256
|
-
- ✅ Auto-initialization on page load
|
|
112
|
+
## Configuration
|
|
257
113
|
|
|
258
|
-
|
|
114
|
+
The Headwai Chat Bubble can be configured using either the global `window.HEADWAI_CHAT_BUBBLE_CONFIG` object or data attributes on individual chat bubble elements. Below are all available configuration options:
|
|
259
115
|
|
|
260
|
-
|
|
116
|
+
### Required Configuration
|
|
261
117
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
118
|
+
#### `apiUrl`
|
|
119
|
+
**Type:** `string` | **Required:** ✅
|
|
120
|
+
The base URL of your LocalChat API endpoint where the chat bubble will send messages. This is the same URL you access your LocalCaht instance in the Webbrowser.
|
|
121
|
+
```javascript
|
|
122
|
+
apiUrl: 'https://company.localchat.at'
|
|
266
123
|
```
|
|
267
124
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
125
|
+
#### `apiKey`
|
|
126
|
+
**Type:** `string` | **Required:** ✅
|
|
127
|
+
The API Key of a dedicated Headwai Chat Bubble user in LocalChat.
|
|
128
|
+
```javascript
|
|
129
|
+
apiKey: 'customer-support-user-api-key'
|
|
271
130
|
```
|
|
272
131
|
|
|
273
|
-
**
|
|
274
|
-
```bash
|
|
275
|
-
# Install in customer's project
|
|
276
|
-
npm install @headwai/chat-bubble
|
|
277
|
-
```
|
|
132
|
+
**How to get your API Key:**
|
|
278
133
|
|
|
279
|
-
**
|
|
280
|
-
```svelte
|
|
281
|
-
<!-- Customer's Svelte component -->
|
|
282
|
-
<script>
|
|
283
|
-
import { ChatBubble } from '@headwai/chat-bubble';
|
|
284
|
-
|
|
285
|
-
// Customers MUST implement these interceptors themselves
|
|
286
|
-
const requestInterceptor = (details) => {
|
|
287
|
-
if (details.body && details.body.messages) {
|
|
288
|
-
details.body.messages = details.body.messages.map(message => ({
|
|
289
|
-
role: message.role === "ai" ? "assistant" : message.role,
|
|
290
|
-
content: message.text || message.content
|
|
291
|
-
}));
|
|
292
|
-
}
|
|
293
|
-
return details;
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const responseInterceptor = (response) => {
|
|
297
|
-
if (response.choices && response.choices[0] && response.choices[0].message) {
|
|
298
|
-
const message = response.choices[0].message;
|
|
299
|
-
return {
|
|
300
|
-
text: message.content,
|
|
301
|
-
role: message.role === "assistant" ? "ai" : message.role
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
return response;
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const connect = {
|
|
308
|
-
type: "websocket",
|
|
309
|
-
url: process.env.API_URL,
|
|
310
|
-
headers: {
|
|
311
|
-
Authorization: `Bearer ${process.env.API_KEY}`,
|
|
312
|
-
"Content-Type": "application/json"
|
|
313
|
-
},
|
|
314
|
-
additionalBodyProps: {
|
|
315
|
-
model: process.env.MODEL_NAME
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
</script>
|
|
319
|
-
|
|
320
|
-
<ChatBubble
|
|
321
|
-
connect={connect}
|
|
322
|
-
requestInterceptor={requestInterceptor}
|
|
323
|
-
responseInterceptor={responseInterceptor}
|
|
324
|
-
/>
|
|
325
|
-
```
|
|
134
|
+
1. **Access Settings**: Login to LocalChat with the dedicated Headwai Chat Bubble user (All conversations will be stored at this user's chats list) and click on the user menu, then select `Settings`.
|
|
326
135
|
|
|
327
|
-
|
|
328
|
-
```html
|
|
329
|
-
<script type="module">
|
|
330
|
-
import { createChatBubble } from 'https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist/index.js';
|
|
331
|
-
|
|
332
|
-
// Initialize manually with custom configuration
|
|
333
|
-
const chatBubble = createChatBubble(
|
|
334
|
-
document.getElementById('chat-container'),
|
|
335
|
-
{
|
|
336
|
-
apiUrl: 'https://api.example.com/chat',
|
|
337
|
-
apiKey: 'your-api-key',
|
|
338
|
-
// ... other props
|
|
339
|
-
}
|
|
340
|
-
);
|
|
341
|
-
</script>
|
|
342
|
-
```
|
|
136
|
+
<img src="docs/images/settings.png" alt="LocalChat User Menu" width="50%" />
|
|
343
137
|
|
|
344
|
-
**
|
|
345
|
-
- ❌ Request/Response interceptors (manual setup required)
|
|
346
|
-
- ❌ Environment variable handling
|
|
347
|
-
- ❌ API configuration logic
|
|
348
|
-
- ✅ Deep chat component only
|
|
349
|
-
|
|
350
|
-
## Deployment Options Comparison
|
|
351
|
-
|
|
352
|
-
| Feature | Built App (Option 1) | Script Embed (Option 2) | NPM Package (Option 3) |
|
|
353
|
-
|---------|----------------------|--------------------------|-------------------------|
|
|
354
|
-
| **Build Command** | `npm run build:widget` | `npm run build:widget` + publish | `npm run build:lib` + publish |
|
|
355
|
-
| **Interceptors Included** | ✅ Yes, automatically | ✅ Yes, automatically | ❌ No, manual setup required |
|
|
356
|
-
| **Environment Variables** | ✅ Built-in support | ✅ Runtime configuration | ❌ Customer implements |
|
|
357
|
-
| **OpenAI Compatibility** | ✅ Ready to use | ✅ Ready to use | ❌ Customer implements |
|
|
358
|
-
| **Setup Complexity** | 🟢 Minimal (just config) | � Minimal (script tag) | �🟡 Moderate (coding required) |
|
|
359
|
-
| **Customization** | 🟡 Limited to env vars | � Limited to config object | �🟢 Full control |
|
|
360
|
-
| **File Size** | 🟡 Larger (complete app) | � Larger (complete app) | �🟢 Smaller (just component) |
|
|
361
|
-
| **Use Case** | Self-hosted deployment | CDN/jsDelivr embedding | Developers, custom integration |
|
|
362
|
-
| **Auto-initialization** | ✅ Yes | ✅ Yes | ❌ Manual setup |
|
|
363
|
-
|
|
364
|
-
### Recommended Approach
|
|
365
|
-
|
|
366
|
-
**For most customers:** Use **Option 2** (Script Embed via jsDelivr)
|
|
367
|
-
- ✅ No coding required
|
|
368
|
-
- ✅ All interceptors included
|
|
369
|
-
- ✅ Easy CDN access via jsDelivr
|
|
370
|
-
- ✅ Just configure via JavaScript object
|
|
371
|
-
- ✅ Ready-to-deploy solution
|
|
372
|
-
- ✅ Auto-initialization
|
|
373
|
-
|
|
374
|
-
**For self-hosted deployments:** Use **Option 1** (Built Application)
|
|
375
|
-
- ✅ Complete control over hosting
|
|
376
|
-
- ✅ No external CDN dependencies
|
|
377
|
-
- ✅ All interceptors included
|
|
378
|
-
- ✅ Environment variable configuration
|
|
379
|
-
|
|
380
|
-
**For developers who need customization:** Use **Option 3** (NPM Package)
|
|
381
|
-
- ✅ Full control over interceptors
|
|
382
|
-
- ✅ Custom API integrations
|
|
383
|
-
- ✅ Smaller bundle size
|
|
384
|
-
- ❌ More setup required
|
|
385
|
-
|
|
386
|
-
## Publishing to NPM and jsDelivr Access
|
|
387
|
-
|
|
388
|
-
### Publishing Steps
|
|
389
|
-
|
|
390
|
-
1. **Build both library and widget**:
|
|
391
|
-
```bash
|
|
392
|
-
npm run build
|
|
393
|
-
```
|
|
138
|
+
2. **Navigate to Account**: In the Settings sidebar, click on `Account` to access your account settings.
|
|
394
139
|
|
|
395
|
-
|
|
396
|
-
```bash
|
|
397
|
-
npm login
|
|
398
|
-
```
|
|
140
|
+
<img src="docs/images/api-keys.png" alt="LocalChat Settings Account" width="50%" />
|
|
399
141
|
|
|
400
|
-
3. **
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
```
|
|
142
|
+
3. **Get your API credentials**: In the API keys section, you have two options:
|
|
143
|
+
- **JWT Token**: Copy the existing JWT Token (expires after 7 days)
|
|
144
|
+
- **API Key**: Generate an API Key via `Generate API Key` button. Click the copy button next to the API Key field, or click the refresh button to generate a new permanent API Key
|
|
404
145
|
|
|
405
|
-
|
|
146
|
+
**⚠️ Security Note:** When using permanent API Keys, ensure they are stored securely (e.g., environment variables, secure configuration) and never expose them directly in client-side code. If using JWT Tokens, implement an automatic refresh mechanism since they expire after 7 days - consider using a server-side proxy to handle token renewal and keep tokens secure.
|
|
406
147
|
|
|
407
|
-
Once published to NPM, your package is automatically available on jsDelivr:
|
|
408
148
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
<!-- Specific version -->
|
|
416
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.css">
|
|
417
|
-
<script src="https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@1.0.0/dist-widget/chat-bubble.js"></script>
|
|
149
|
+
#### `modelId`
|
|
150
|
+
**Type:** `string` | **Required:** ✅
|
|
151
|
+
The identifier of the AI model to use for generating responses. This should match a model configured in your LocalChat instance.
|
|
152
|
+
```javascript
|
|
153
|
+
modelId: 'customer-support-model-id'
|
|
418
154
|
```
|
|
419
155
|
|
|
420
|
-
**
|
|
421
|
-
```html
|
|
422
|
-
<!-- ES Module -->
|
|
423
|
-
<script type="module">
|
|
424
|
-
import { ChatBubble, createChatBubble } from 'https://cdn.jsdelivr.net/npm/@headwai/chat-bubble@latest/dist/index.js';
|
|
425
|
-
</script>
|
|
156
|
+
1. **Navigate to Model**: Login to LocalChat with the dedicated Headwai Chat Bubble user (Or any other user that is allowed to see the desired model) and click on the `Workspace` menu, then select `Models`. Search for the name of the desired model (Or create one). Click onto the edit-`Pen`.
|
|
426
157
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
158
|
+
<img src="docs/images/model-edit.png" alt="LocalChat User Menu" width="50%" />
|
|
159
|
+
|
|
160
|
+
1. **Copy Model Id**: Now the model is displayed with its `name` and right underneath the `model-id`. Copy the `model-id`.
|
|
161
|
+
|
|
162
|
+
<img src="docs/images/model-id.png" alt="LocalChat User Menu" width="50%" />
|
|
430
163
|
|
|
431
|
-
###
|
|
164
|
+
### Optional Configuration
|
|
432
165
|
|
|
166
|
+
#### `maxMessages`
|
|
167
|
+
**Type:** `number` | **Default:** `0` (unlimited)
|
|
168
|
+
Limits the number of messages stored in the conversation history in one singel conversation. Set to `0` for unlimited messages, or specify a positive number to limit history.
|
|
169
|
+
```javascript
|
|
170
|
+
maxMessages: 10 // Keep and use only last 10 messages
|
|
433
171
|
```
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
├── widget.html # Demo page
|
|
441
|
-
├── chat-bubble.js # Complete widget with auto-init
|
|
442
|
-
├── chat-bubble.css # Widget styles
|
|
443
|
-
└── assets/ # Additional assets
|
|
172
|
+
|
|
173
|
+
#### `placeholderText`
|
|
174
|
+
**Type:** `string` | **Default:** `'Type your message...'`
|
|
175
|
+
The placeholder text displayed in the message input field when it's empty.
|
|
176
|
+
```javascript
|
|
177
|
+
placeholderText: 'Ask your question here!'
|
|
444
178
|
```
|
|
445
179
|
|
|
446
|
-
|
|
180
|
+
#### `faviconPath`
|
|
181
|
+
**Type:** `string` | **Default:** `'/icons/favicon.svg'`
|
|
182
|
+
Path or URL to the icon displayed on the chat bubble toggle button. Can be a relative path or absolute URL.
|
|
183
|
+
```javascript
|
|
184
|
+
faviconPath: 'https://cdn.company.at/icons/favicon.svg'
|
|
185
|
+
```
|
|
447
186
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
| `VITE_CHAT_BUBBLE_CONTENT_TYPE` | HTTP Content-Type header | `application/json` | ❌ |
|
|
455
|
-
| `VITE_CHAT_BUBBLE_MAX_MESSAGES` | Maximum messages in conversation history | `0` (unlimited) | ❌ |
|
|
456
|
-
| `VITE_CHAT_BUBBLE_PLACEHOLDER_TEXT` | Chat input placeholder text | `Type your message...` | ❌ |
|
|
457
|
-
| `VITE_CHAT_BUBBLE_DEMO_MODE` | Enable demo mode | `false` | ❌ |
|
|
458
|
-
| `VITE_CHAT_BUBBLE_FAVICON_PATH` | Path to favicon/icon for chat toggle button | `/icons/favicon.svg` | ❌ |
|
|
187
|
+
#### `initialMessage`
|
|
188
|
+
**Type:** `string` | **Default:** `undefined`
|
|
189
|
+
An optional welcome message that appears when the chat is first opened. If not set, no initial message is displayed.
|
|
190
|
+
```javascript
|
|
191
|
+
initialMessage: 'Hey! My name is Supporty, how can I help you?'
|
|
192
|
+
```
|
|
459
193
|
|
|
460
|
-
|
|
194
|
+
### Styling Configuration
|
|
461
195
|
|
|
462
|
-
|
|
196
|
+
#### `userMessageBackgroundColor`
|
|
197
|
+
**Type:** `string` | **Default:** `'#007bff'`
|
|
198
|
+
Background color for messages sent by the user. Accepts any valid CSS color value.
|
|
199
|
+
```javascript
|
|
200
|
+
userMessageBackgroundColor: '#007bff'
|
|
201
|
+
```
|
|
463
202
|
|
|
464
|
-
|
|
203
|
+
#### `aiMessageBackgroundColor`
|
|
204
|
+
**Type:** `string` | **Default:** `'#f1f3f4'`
|
|
205
|
+
Background color for messages sent by the AI assistant. Accepts any valid CSS color value.
|
|
206
|
+
```javascript
|
|
207
|
+
aiMessageBackgroundColor: '#f1f3f4'
|
|
208
|
+
```
|
|
465
209
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
210
|
+
#### `userMessageTextColor`
|
|
211
|
+
**Type:** `string` | **Default:** `'#000000'`
|
|
212
|
+
Text color for user messages. Accepts any valid CSS color value.
|
|
213
|
+
```javascript
|
|
214
|
+
userMessageTextColor: '#ffffff'
|
|
215
|
+
```
|
|
471
216
|
|
|
472
|
-
|
|
217
|
+
#### `aiMessageTextColor`
|
|
218
|
+
**Type:** `string` | **Default:** `'#000000'`
|
|
219
|
+
Text color for AI assistant messages. Accepts any valid CSS color value.
|
|
220
|
+
```javascript
|
|
221
|
+
aiMessageTextColor: '#333333'
|
|
222
|
+
```
|
|
473
223
|
|
|
474
|
-
|
|
224
|
+
#### `faviconBackgroundColor`
|
|
225
|
+
**Type:** `string` | **Default:** `'#667eea'`
|
|
226
|
+
Base color used for the assistant icon gradient. This color influences the overall appearance of the AI assistant's avatar.
|
|
227
|
+
```javascript
|
|
228
|
+
faviconBackgroundColor: '#667eea'
|
|
229
|
+
```
|
|
475
230
|
|
|
476
|
-
|
|
477
|
-
- `npm run build` - Build both library and widget for production
|
|
478
|
-
- `npm run build:lib` - Build NPM package (Option 3)
|
|
479
|
-
- `npm run build:widget` - Build standalone widget (Options 1 & 2)
|
|
480
|
-
- `npm run build:app` - Build demo application
|
|
481
|
-
- `npm run preview` - Preview production build
|
|
231
|
+
### Data Attribute Format
|
|
482
232
|
|
|
483
|
-
|
|
233
|
+
When using data attributes for multiple chat bubbles, convert camelCase property names to kebab-case with the `data-chat-bubble-` prefix:
|
|
484
234
|
|
|
485
|
-
|
|
486
|
-
chat-bubble
|
|
487
|
-
|
|
488
|
-
│ ├── App.svelte # Main chat component
|
|
489
|
-
│ ├── main.js # Development entry point
|
|
490
|
-
│ ├── lib.js # NPM package entry point
|
|
491
|
-
│ └── widget.js # Widget/standalone entry point
|
|
492
|
-
├── dist/ # NPM package build output
|
|
493
|
-
├── dist-widget/ # Widget build output
|
|
494
|
-
├── package.json # Dependencies and scripts
|
|
495
|
-
├── vite.config.js # Default Vite configuration
|
|
496
|
-
├── vite.lib.config.js # Library build configuration
|
|
497
|
-
├── vite.widget.config.js # Widget build configuration
|
|
498
|
-
├── vite.app.config.js # App build configuration
|
|
499
|
-
├── svelte.config.js # Svelte configuration
|
|
500
|
-
├── index.html # Development HTML
|
|
501
|
-
├── widget.html # Widget HTML template
|
|
502
|
-
└── README.md # This file
|
|
503
|
-
```
|
|
235
|
+
- `apiUrl` → `data-chat-bubble-api-url`
|
|
236
|
+
- `userMessageBackgroundColor` → `data-chat-bubble-user-message-background-color`
|
|
237
|
+
- `initialMessage` → `data-chat-bubble-initial-message`
|
|
504
238
|
|
|
505
239
|
## Troubleshooting
|
|
506
240
|
|
|
@@ -508,21 +242,4 @@ chat-bubble/
|
|
|
508
242
|
|
|
509
243
|
1. **CORS Errors**: Ensure your API endpoint allows requests from your domain
|
|
510
244
|
2. **Authentication Failures**: Verify your API key is correct and has proper permissions
|
|
511
|
-
3. **WebSocket Connection Issues**: Check if your API supports WebSocket connections
|
|
512
|
-
4. **Environment Variables Not Loading**: Ensure variables are prefixed with `VITE_CHAT_BUBBLE_`
|
|
513
|
-
|
|
514
|
-
### Debug Mode
|
|
515
|
-
|
|
516
|
-
Enable debug mode by setting:
|
|
517
|
-
```env
|
|
518
|
-
VITE_CHAT_BUBBLE_DEMO_MODE=true
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
This will enable demo features that can help test the component without a real API connection.
|
|
522
|
-
|
|
523
|
-
## Support
|
|
524
245
|
|
|
525
|
-
For issues and questions:
|
|
526
|
-
- Create an issue in this repository
|
|
527
|
-
- Check the [deep-chat documentation](https://deepchat.dev/)
|
|
528
|
-
- Review the [API compatibility guide](https://deepchat.dev/docs/connect)
|