@a.izzuddin/ai-chat 0.2.4 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +230 -192
- package/README.npm.md +3 -3
- package/custom-elements.json +242 -12
- package/dist/index.d.mts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +548 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +548 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,61 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AI Chat Widget
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A modern, customizable chat widget built with Lit web components. Features a clean UI, responsive design, and extensive theming options.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/@a.izzuddin/ai-chat)
|
|
5
|
+
## Features
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- 🎨 **Fully Customizable Theme** - Change colors, backgrounds, and styles
|
|
8
|
+
- 📱 **Responsive Design** - Works seamlessly on desktop, tablet, and mobile
|
|
9
|
+
- 🌓 **Dark Mode Support** - Built-in light and dark themes
|
|
10
|
+
- 📦 **Two Display Modes** - Fullscreen or floating widget
|
|
11
|
+
- 🔧 **Easy Integration** - Simple HTML attributes for configuration
|
|
12
|
+
- ⚡ **Built with Lit** - Fast, lightweight web component
|
|
13
|
+
- 🎯 **TypeScript Support** - Full type safety
|
|
14
|
+
- 📝 **List Formatting** - Automatic rendering of bulleted and numbered lists
|
|
15
|
+
- 💡 **Suggested Questions** - Clickable follow-up questions for better UX
|
|
16
|
+
- 🔗 **Related FAQs** - Display related FAQ references
|
|
17
|
+
- 👋 **Customizable Welcome Message** - Set custom greeting with optional subtitle
|
|
9
18
|
|
|
10
|
-
|
|
11
|
-
- 🎨 **Beautiful UI** - Modern chat interface with light/dark mode
|
|
12
|
-
- ⚡ **Lightweight** - Only ~15KB (gzipped)
|
|
13
|
-
- 🔧 **Fully Customizable** - Configure API endpoint, styling, and behavior
|
|
14
|
-
- 📱 **Responsive** - Mobile-friendly design
|
|
15
|
-
- 🎯 **TypeScript** - Full type safety and IntelliSense
|
|
16
|
-
- ♿ **Accessible** - Semantic HTML and ARIA attributes
|
|
17
|
-
- 🎪 **Event-Driven** - Listen to messages, responses, and errors
|
|
19
|
+
## Quick Start
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
### Installation
|
|
20
22
|
|
|
21
23
|
```bash
|
|
22
24
|
npm install @a.izzuddin/ai-chat
|
|
23
|
-
# or
|
|
24
|
-
yarn add @a.izzuddin/ai-chat
|
|
25
|
-
# or
|
|
26
|
-
pnpm add @a.izzuddin/ai-chat
|
|
27
25
|
```
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Vanilla JavaScript / HTML
|
|
27
|
+
### Basic Usage
|
|
32
28
|
|
|
29
|
+
**HTML:**
|
|
33
30
|
```html
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<script type="module">
|
|
38
|
-
import '@a.izzuddin/ai-chat';
|
|
39
|
-
</script>
|
|
31
|
+
<script type="module">
|
|
32
|
+
import '@a.izzuddin/ai-chat';
|
|
33
|
+
</script>
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</body>
|
|
47
|
-
</html>
|
|
35
|
+
<ai-chat
|
|
36
|
+
api-url="https://your-api-endpoint.com"
|
|
37
|
+
session-id="user-123"
|
|
38
|
+
title="AI Assistant">
|
|
39
|
+
</ai-chat>
|
|
48
40
|
```
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
42
|
+
**React:**
|
|
43
|
+
```jsx
|
|
53
44
|
import '@a.izzuddin/ai-chat';
|
|
54
45
|
|
|
55
46
|
function App() {
|
|
56
47
|
return (
|
|
57
48
|
<ai-chat
|
|
58
|
-
api-url=
|
|
49
|
+
api-url="https://your-api-endpoint.com"
|
|
59
50
|
session-id="user-123"
|
|
60
51
|
title="AI Assistant"
|
|
61
52
|
/>
|
|
@@ -63,122 +54,118 @@ function App() {
|
|
|
63
54
|
}
|
|
64
55
|
```
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
**Vue:**
|
|
68
58
|
```vue
|
|
69
59
|
<template>
|
|
70
60
|
<ai-chat
|
|
71
|
-
|
|
61
|
+
api-url="https://your-api-endpoint.com"
|
|
72
62
|
session-id="user-123"
|
|
73
|
-
title="AI Assistant"
|
|
74
|
-
|
|
63
|
+
title="AI Assistant">
|
|
64
|
+
</ai-chat>
|
|
75
65
|
</template>
|
|
76
66
|
|
|
77
67
|
<script setup>
|
|
78
68
|
import '@a.izzuddin/ai-chat';
|
|
79
|
-
const apiUrl = import.meta.env.VITE_API_URL;
|
|
80
69
|
</script>
|
|
81
70
|
```
|
|
82
71
|
|
|
83
|
-
|
|
72
|
+
## Configuration
|
|
84
73
|
|
|
85
|
-
|
|
86
|
-
<script>
|
|
87
|
-
import '@a.izzuddin/ai-chat';
|
|
88
|
-
export let apiUrl;
|
|
89
|
-
</script>
|
|
74
|
+
### Display Modes
|
|
90
75
|
|
|
76
|
+
#### Fullscreen Mode (Default)
|
|
77
|
+
```html
|
|
91
78
|
<ai-chat
|
|
92
|
-
api-url=
|
|
79
|
+
api-url="https://api.example.com"
|
|
93
80
|
session-id="user-123"
|
|
94
81
|
title="AI Assistant"
|
|
95
|
-
|
|
82
|
+
mode="fullscreen">
|
|
83
|
+
</ai-chat>
|
|
96
84
|
```
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
export class AppComponent {}
|
|
86
|
+
#### Widget Mode
|
|
87
|
+
```html
|
|
88
|
+
<ai-chat
|
|
89
|
+
api-url="https://api.example.com"
|
|
90
|
+
session-id="user-123"
|
|
91
|
+
title="AI Assistant"
|
|
92
|
+
mode="widget"
|
|
93
|
+
widget-width="400px"
|
|
94
|
+
widget-height="650px">
|
|
95
|
+
</ai-chat>
|
|
110
96
|
```
|
|
111
97
|
|
|
112
|
-
|
|
98
|
+
### Theme Customization
|
|
113
99
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
const chat = document.querySelector('ai-chat');
|
|
128
|
-
|
|
129
|
-
// Set properties
|
|
130
|
-
chat.apiUrl = 'https://api.example.com';
|
|
131
|
-
chat.sessionId = 'user-123';
|
|
132
|
-
chat.title = 'Support Bot';
|
|
133
|
-
chat.theme = 'dark';
|
|
134
|
-
chat.initialMessages = [
|
|
135
|
-
{ id: '1', role: 'assistant', content: 'Hello! How can I help?' }
|
|
136
|
-
];
|
|
100
|
+
#### Custom Colors
|
|
101
|
+
```html
|
|
102
|
+
<ai-chat
|
|
103
|
+
api-url="https://api.example.com"
|
|
104
|
+
session-id="user-123"
|
|
105
|
+
title="AI Assistant"
|
|
106
|
+
primary-color="#10B981"
|
|
107
|
+
primary-color-hover="#059669"
|
|
108
|
+
user-message-bg="#D1FAE5"
|
|
109
|
+
bot-message-bg="#F3F4F6">
|
|
110
|
+
</ai-chat>
|
|
137
111
|
```
|
|
138
112
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// AI responds
|
|
151
|
-
chat.addEventListener('response-received', (event) => {
|
|
152
|
-
console.log('AI response:', event.detail);
|
|
153
|
-
// event.detail: { id: string, role: 'assistant', content: string }
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// Error occurs
|
|
157
|
-
chat.addEventListener('error', (event) => {
|
|
158
|
-
console.error('Chat error:', event.detail);
|
|
159
|
-
// event.detail: Error object
|
|
160
|
-
});
|
|
113
|
+
#### Custom Avatars and Background
|
|
114
|
+
```html
|
|
115
|
+
<ai-chat
|
|
116
|
+
api-url="https://api.example.com"
|
|
117
|
+
session-id="user-123"
|
|
118
|
+
title="AI Assistant"
|
|
119
|
+
bot-avatar-url="/path/to/avatar.png"
|
|
120
|
+
background-image-url="/path/to/background.png">
|
|
121
|
+
</ai-chat>
|
|
161
122
|
```
|
|
162
123
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
124
|
+
#### Custom Welcome Message
|
|
125
|
+
```html
|
|
126
|
+
<ai-chat
|
|
127
|
+
api-url="https://api.example.com"
|
|
128
|
+
session-id="user-123"
|
|
129
|
+
title="AI Assistant"
|
|
130
|
+
welcome-message="Hello! How may I assist you?"
|
|
131
|
+
welcome-subtitle="Ask me anything about our services">
|
|
132
|
+
</ai-chat>
|
|
173
133
|
```
|
|
174
134
|
|
|
175
|
-
|
|
135
|
+
### Dark Mode
|
|
136
|
+
```html
|
|
137
|
+
<ai-chat
|
|
138
|
+
api-url="https://api.example.com"
|
|
139
|
+
session-id="user-123"
|
|
140
|
+
title="AI Assistant"
|
|
141
|
+
theme="dark">
|
|
142
|
+
</ai-chat>
|
|
143
|
+
```
|
|
176
144
|
|
|
177
|
-
|
|
145
|
+
## Available Attributes
|
|
178
146
|
|
|
179
|
-
|
|
147
|
+
| Attribute | Type | Default | Description |
|
|
148
|
+
|-----------|------|---------|-------------|
|
|
149
|
+
| `api-url` | string | '' | API endpoint URL for chat backend |
|
|
150
|
+
| `session-id` | string | 'default-session' | Unique session identifier |
|
|
151
|
+
| `title` | string | 'My AI Agent' | Chat widget title |
|
|
152
|
+
| `theme` | 'light' or 'dark' | 'light' | Color theme |
|
|
153
|
+
| `mode` | 'fullscreen' or 'widget' | 'fullscreen' | Display mode |
|
|
154
|
+
| `widget-width` | string | '380px' | Widget width (widget mode only) |
|
|
155
|
+
| `widget-height` | string | '600px' | Widget height (widget mode only) |
|
|
156
|
+
| `primary-color` | string | '#4169E1' | Primary brand color |
|
|
157
|
+
| `primary-color-hover` | string | '#3457C7' | Hover state color |
|
|
158
|
+
| `user-message-bg` | string | '#D6E4FF' | User message background |
|
|
159
|
+
| `bot-message-bg` | string | '#F5F5F5' | Bot message background |
|
|
160
|
+
| `bot-avatar-url` | string | '' | Custom bot avatar image |
|
|
161
|
+
| `background-image-url` | string | '' | Chat background image |
|
|
162
|
+
| `welcome-message` | string | 'How can I help you today?' | Initial welcome message shown when chat is empty |
|
|
163
|
+
| `welcome-subtitle` | string | '' | Optional subtitle text shown below welcome message |
|
|
164
|
+
|
|
165
|
+
## API Integration
|
|
166
|
+
|
|
167
|
+
The chat widget sends POST requests to the configured api-url with the following payload:
|
|
180
168
|
|
|
181
|
-
Request:
|
|
182
169
|
```json
|
|
183
170
|
{
|
|
184
171
|
"session_id": "string",
|
|
@@ -186,108 +173,159 @@ Request:
|
|
|
186
173
|
}
|
|
187
174
|
```
|
|
188
175
|
|
|
189
|
-
|
|
176
|
+
Expected response format:
|
|
177
|
+
|
|
190
178
|
```json
|
|
191
179
|
{
|
|
192
|
-
"response": "string"
|
|
180
|
+
"response": "string",
|
|
181
|
+
"faq_used": [
|
|
182
|
+
{
|
|
183
|
+
"no.": "1",
|
|
184
|
+
"question": "What is MySTI?"
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
"suggested_follow_ups": [
|
|
188
|
+
"What are the main objectives of the program?",
|
|
189
|
+
"How can companies apply?",
|
|
190
|
+
"Who is eligible for the MySTI logo?"
|
|
191
|
+
]
|
|
193
192
|
}
|
|
194
193
|
```
|
|
195
194
|
|
|
196
|
-
|
|
195
|
+
**Supported field variations:**
|
|
196
|
+
- `faq_used` or `faqs_used` for related FAQs
|
|
197
|
+
- `suggested_follow_ups` or `suggested_questions` for clickable follow-up questions
|
|
197
198
|
|
|
198
|
-
###
|
|
199
|
+
### Response Behavior
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
<ai-chat theme="dark"></ai-chat>
|
|
206
|
-
```
|
|
201
|
+
- **Related FAQs** - Displayed as non-clickable text references
|
|
202
|
+
- **Suggested Questions** - Displayed as clickable buttons that send the question when clicked
|
|
203
|
+
- **List Formatting** - Messages support automatic list rendering:
|
|
204
|
+
- Unordered lists: Lines starting with `-`, `*`, or `•`
|
|
205
|
+
- Ordered lists: Lines starting with `1.`, `2.`, etc.
|
|
207
206
|
|
|
208
|
-
###
|
|
207
|
+
### List Formatting Example
|
|
209
208
|
|
|
210
|
-
|
|
209
|
+
Your API can return text with lists:
|
|
211
210
|
|
|
212
|
-
```css
|
|
213
|
-
ai-chat {
|
|
214
|
-
--ai-chat-primary: #2563eb;
|
|
215
|
-
--ai-chat-background: #ffffff;
|
|
216
|
-
--ai-chat-text: #09090b;
|
|
217
|
-
/* ... more variables */
|
|
218
|
-
}
|
|
219
211
|
```
|
|
212
|
+
MySTI is a government initiative. Key objectives include:
|
|
220
213
|
|
|
221
|
-
|
|
214
|
+
1. Stimulating local industry growth
|
|
215
|
+
2. Driving technology-based economic growth
|
|
216
|
+
3. Creating job opportunities
|
|
222
217
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
background: linear-gradient(to right, #667eea, #764ba2);
|
|
228
|
-
}
|
|
218
|
+
Key features:
|
|
219
|
+
- Platform for applicants
|
|
220
|
+
- Database of approved goods
|
|
221
|
+
- Reference for procurement
|
|
229
222
|
```
|
|
230
223
|
|
|
231
|
-
|
|
224
|
+
This will be automatically rendered as proper HTML lists.
|
|
232
225
|
|
|
233
|
-
|
|
226
|
+
## Events
|
|
234
227
|
|
|
235
|
-
|
|
236
|
-
- [React](./examples/react.tsx)
|
|
237
|
-
- [Vue](./examples/vue.vue)
|
|
238
|
-
- [Svelte](./examples/svelte.svelte)
|
|
239
|
-
- [Angular](./examples/angular.component.ts)
|
|
228
|
+
The component fires custom events you can listen to:
|
|
240
229
|
|
|
241
|
-
|
|
230
|
+
```javascript
|
|
231
|
+
const chat = document.querySelector('ai-chat');
|
|
242
232
|
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
// User sends a message
|
|
234
|
+
chat.addEventListener('message-sent', (event) => {
|
|
235
|
+
console.log('Message sent:', event.detail);
|
|
236
|
+
});
|
|
247
237
|
|
|
248
|
-
|
|
238
|
+
// AI responds
|
|
239
|
+
chat.addEventListener('response-received', (event) => {
|
|
240
|
+
console.log('Response received:', event.detail);
|
|
241
|
+
});
|
|
249
242
|
|
|
250
|
-
|
|
243
|
+
// Error occurs
|
|
244
|
+
chat.addEventListener('error', (event) => {
|
|
245
|
+
console.error('Error:', event.detail);
|
|
246
|
+
});
|
|
247
|
+
```
|
|
251
248
|
|
|
252
|
-
|
|
249
|
+
## Theme Examples
|
|
253
250
|
|
|
254
|
-
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
|
|
251
|
+
### Green Theme (Success)
|
|
252
|
+
```html
|
|
253
|
+
<ai-chat
|
|
254
|
+
primary-color="#10B981"
|
|
255
|
+
primary-color-hover="#059669"
|
|
256
|
+
user-message-bg="#D1FAE5"
|
|
257
|
+
bot-message-bg="#F3F4F6">
|
|
258
|
+
</ai-chat>
|
|
258
259
|
```
|
|
259
260
|
|
|
260
|
-
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
### Purple Theme (Creative)
|
|
262
|
+
```html
|
|
263
|
+
<ai-chat
|
|
264
|
+
primary-color="#8B5CF6"
|
|
265
|
+
primary-color-hover="#7C3AED"
|
|
266
|
+
user-message-bg="#EDE9FE"
|
|
267
|
+
bot-message-bg="#F5F3FF">
|
|
268
|
+
</ai-chat>
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Red Theme (Alert)
|
|
272
|
+
```html
|
|
273
|
+
<ai-chat
|
|
274
|
+
primary-color="#EF4444"
|
|
275
|
+
primary-color-hover="#DC2626"
|
|
276
|
+
user-message-bg="#FEE2E2"
|
|
277
|
+
bot-message-bg="#FEF2F2">
|
|
278
|
+
</ai-chat>
|
|
264
279
|
```
|
|
265
280
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
-
|
|
269
|
-
-
|
|
281
|
+
### Orange Theme (Warm)
|
|
282
|
+
```html
|
|
283
|
+
<ai-chat
|
|
284
|
+
primary-color="#F97316"
|
|
285
|
+
primary-color-hover="#EA580C"
|
|
286
|
+
user-message-bg="#FFEDD5"
|
|
287
|
+
bot-message-bg="#FFF7ED">
|
|
288
|
+
</ai-chat>
|
|
289
|
+
```
|
|
270
290
|
|
|
271
|
-
##
|
|
291
|
+
## Responsive Behavior
|
|
272
292
|
|
|
273
|
-
|
|
293
|
+
The widget automatically adapts to different screen sizes:
|
|
274
294
|
|
|
275
|
-
|
|
295
|
+
- **Desktop (>1024px)**: Full widget size
|
|
296
|
+
- **Tablet (769-1024px)**: Slightly larger widget (400px × 650px)
|
|
297
|
+
- **Small Tablet (481-768px)**: Compact widget (360px × 550px)
|
|
298
|
+
- **Mobile Portrait (≤480px)**: Nearly fullscreen (90vw × 70vh)
|
|
299
|
+
- **Mobile Landscape**: Wider widget (500px × adjusted height)
|
|
276
300
|
|
|
277
|
-
|
|
301
|
+
## Development
|
|
302
|
+
|
|
303
|
+
### Build for Production
|
|
304
|
+
```bash
|
|
305
|
+
npm run build
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Run Development Server
|
|
309
|
+
```bash
|
|
310
|
+
npm run dev
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Lint Code
|
|
314
|
+
```bash
|
|
315
|
+
npm run lint
|
|
316
|
+
```
|
|
278
317
|
|
|
279
|
-
##
|
|
318
|
+
## Browser Support
|
|
280
319
|
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
320
|
+
- Chrome/Edge (latest)
|
|
321
|
+
- Firefox (latest)
|
|
322
|
+
- Safari (latest)
|
|
323
|
+
- Modern mobile browsers
|
|
285
324
|
|
|
286
|
-
##
|
|
325
|
+
## License
|
|
287
326
|
|
|
288
|
-
|
|
289
|
-
- [Lit](https://lit.dev/) - The library powering this component
|
|
327
|
+
MIT
|
|
290
328
|
|
|
291
|
-
|
|
329
|
+
## Contributing
|
|
292
330
|
|
|
293
|
-
|
|
331
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/README.npm.md
CHANGED
|
@@ -288,6 +288,6 @@ MIT © [Your Name]
|
|
|
288
288
|
|
|
289
289
|
## Support
|
|
290
290
|
|
|
291
|
-
- 📖 [Documentation](https://github.com/
|
|
292
|
-
- 🐛 [Issue Tracker](https://github.com/
|
|
293
|
-
- 💬 [Discussions](https://github.com/
|
|
291
|
+
- 📖 [Documentation](https://github.com/aiddin/ai-chat#readme)
|
|
292
|
+
- 🐛 [Issue Tracker](https://github.com/aiddin/ai-chat/issues)
|
|
293
|
+
- 💬 [Discussions](https://github.com/aiddin/ai-chat/discussions)
|