@a.izzuddin/ai-chat 0.2.4 → 0.2.6
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 +166 -215
- package/README.npm.md +3 -3
- package/custom-elements.json +188 -12
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +384 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +384 -65
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,293 +1,244 @@
|
|
|
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
|
|
9
14
|
|
|
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
|
|
15
|
+
## Quick Start
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
### Installation
|
|
20
18
|
|
|
21
19
|
```bash
|
|
22
|
-
npm install
|
|
23
|
-
|
|
24
|
-
yarn add @a.izzuddin/ai-chat
|
|
25
|
-
# or
|
|
26
|
-
pnpm add @a.izzuddin/ai-chat
|
|
20
|
+
npm install
|
|
21
|
+
npm run dev
|
|
27
22
|
```
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Vanilla JavaScript / HTML
|
|
24
|
+
### Basic Usage
|
|
32
25
|
|
|
33
26
|
```html
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<ai-chat
|
|
42
|
-
api-url="https://your-api.com"
|
|
43
|
-
session-id="user-123"
|
|
44
|
-
title="My AI Assistant">
|
|
45
|
-
</ai-chat>
|
|
46
|
-
</body>
|
|
47
|
-
</html>
|
|
27
|
+
<ai-chat
|
|
28
|
+
api-url="https://your-api-endpoint.com"
|
|
29
|
+
session-id="user-123"
|
|
30
|
+
title="AI Assistant">
|
|
31
|
+
</ai-chat>
|
|
48
32
|
```
|
|
49
33
|
|
|
50
|
-
|
|
34
|
+
## Configuration
|
|
51
35
|
|
|
52
|
-
|
|
53
|
-
import '@a.izzuddin/ai-chat';
|
|
36
|
+
### Display Modes
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
38
|
+
#### Fullscreen Mode (Default)
|
|
39
|
+
```html
|
|
40
|
+
<ai-chat
|
|
41
|
+
api-url="https://api.example.com"
|
|
42
|
+
session-id="user-123"
|
|
43
|
+
title="AI Assistant"
|
|
44
|
+
mode="fullscreen">
|
|
45
|
+
</ai-chat>
|
|
64
46
|
```
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
</
|
|
76
|
-
|
|
77
|
-
<script setup>
|
|
78
|
-
import '@a.izzuddin/ai-chat';
|
|
79
|
-
const apiUrl = import.meta.env.VITE_API_URL;
|
|
80
|
-
</script>
|
|
48
|
+
#### Widget Mode
|
|
49
|
+
```html
|
|
50
|
+
<ai-chat
|
|
51
|
+
api-url="https://api.example.com"
|
|
52
|
+
session-id="user-123"
|
|
53
|
+
title="AI Assistant"
|
|
54
|
+
mode="widget"
|
|
55
|
+
widget-width="400px"
|
|
56
|
+
widget-height="650px">
|
|
57
|
+
</ai-chat>
|
|
81
58
|
```
|
|
82
59
|
|
|
83
|
-
###
|
|
84
|
-
|
|
85
|
-
```svelte
|
|
86
|
-
<script>
|
|
87
|
-
import '@a.izzuddin/ai-chat';
|
|
88
|
-
export let apiUrl;
|
|
89
|
-
</script>
|
|
60
|
+
### Theme Customization
|
|
90
61
|
|
|
62
|
+
#### Custom Colors
|
|
63
|
+
```html
|
|
91
64
|
<ai-chat
|
|
92
|
-
api-url=
|
|
65
|
+
api-url="https://api.example.com"
|
|
93
66
|
session-id="user-123"
|
|
94
67
|
title="AI Assistant"
|
|
95
|
-
|
|
68
|
+
primary-color="#10B981"
|
|
69
|
+
primary-color-hover="#059669"
|
|
70
|
+
user-message-bg="#D1FAE5"
|
|
71
|
+
bot-message-bg="#F3F4F6">
|
|
72
|
+
</ai-chat>
|
|
96
73
|
```
|
|
97
74
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
108
|
-
})
|
|
109
|
-
export class AppComponent {}
|
|
75
|
+
#### Custom Avatars and Background
|
|
76
|
+
```html
|
|
77
|
+
<ai-chat
|
|
78
|
+
api-url="https://api.example.com"
|
|
79
|
+
session-id="user-123"
|
|
80
|
+
title="AI Assistant"
|
|
81
|
+
bot-avatar-url="/path/to/avatar.png"
|
|
82
|
+
background-image-url="/path/to/background.png">
|
|
83
|
+
</ai-chat>
|
|
110
84
|
```
|
|
111
85
|
|
|
112
|
-
|
|
86
|
+
### Dark Mode
|
|
87
|
+
```html
|
|
88
|
+
<ai-chat
|
|
89
|
+
api-url="https://api.example.com"
|
|
90
|
+
session-id="user-123"
|
|
91
|
+
title="AI Assistant"
|
|
92
|
+
theme="dark">
|
|
93
|
+
</ai-chat>
|
|
94
|
+
```
|
|
113
95
|
|
|
114
|
-
|
|
96
|
+
## Available Attributes
|
|
115
97
|
|
|
116
98
|
| Attribute | Type | Default | Description |
|
|
117
99
|
|-----------|------|---------|-------------|
|
|
118
|
-
| `api-url` |
|
|
119
|
-
| `session-id` |
|
|
120
|
-
| `title` |
|
|
121
|
-
| `theme` |
|
|
122
|
-
| `
|
|
100
|
+
| `api-url` | string | '' | API endpoint URL for chat backend |
|
|
101
|
+
| `session-id` | string | 'default-session' | Unique session identifier |
|
|
102
|
+
| `title` | string | 'My AI Agent' | Chat widget title |
|
|
103
|
+
| `theme` | 'light' or 'dark' | 'light' | Color theme |
|
|
104
|
+
| `mode` | 'fullscreen' or 'widget' | 'fullscreen' | Display mode |
|
|
105
|
+
| `widget-width` | string | '380px' | Widget width (widget mode only) |
|
|
106
|
+
| `widget-height` | string | '600px' | Widget height (widget mode only) |
|
|
107
|
+
| `primary-color` | string | '#4169E1' | Primary brand color |
|
|
108
|
+
| `primary-color-hover` | string | '#3457C7' | Hover state color |
|
|
109
|
+
| `user-message-bg` | string | '#D6E4FF' | User message background |
|
|
110
|
+
| `bot-message-bg` | string | '#F5F5F5' | Bot message background |
|
|
111
|
+
| `bot-avatar-url` | string | '' | Custom bot avatar image |
|
|
112
|
+
| `background-image-url` | string | '' | Chat background image |
|
|
113
|
+
|
|
114
|
+
## API Integration
|
|
115
|
+
|
|
116
|
+
The chat widget sends POST requests to the configured api-url with the following payload:
|
|
123
117
|
|
|
124
|
-
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"session_id": "string",
|
|
121
|
+
"question": "string"
|
|
122
|
+
}
|
|
123
|
+
```
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
const chat = document.querySelector('ai-chat');
|
|
125
|
+
Expected response format:
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"response": "string",
|
|
130
|
+
"faqs_used": [
|
|
131
|
+
{
|
|
132
|
+
"no.": "1",
|
|
133
|
+
"question": "Related question?"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
## Events
|
|
140
|
+
|
|
141
|
+
The component fires custom events you can listen to:
|
|
140
142
|
|
|
141
143
|
```javascript
|
|
142
144
|
const chat = document.querySelector('ai-chat');
|
|
143
145
|
|
|
144
146
|
// User sends a message
|
|
145
147
|
chat.addEventListener('message-sent', (event) => {
|
|
146
|
-
console.log('
|
|
147
|
-
// event.detail: { id: string, role: 'user', content: string }
|
|
148
|
+
console.log('Message sent:', event.detail);
|
|
148
149
|
});
|
|
149
150
|
|
|
150
151
|
// AI responds
|
|
151
152
|
chat.addEventListener('response-received', (event) => {
|
|
152
|
-
console.log('
|
|
153
|
-
// event.detail: { id: string, role: 'assistant', content: string }
|
|
153
|
+
console.log('Response received:', event.detail);
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
// Error occurs
|
|
157
157
|
chat.addEventListener('error', (event) => {
|
|
158
|
-
console.error('
|
|
159
|
-
// event.detail: Error object
|
|
158
|
+
console.error('Error:', event.detail);
|
|
160
159
|
});
|
|
161
160
|
```
|
|
162
161
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
import type { Message } from '@a.izzuddin/ai-chat';
|
|
162
|
+
## Theme Examples
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
### Green Theme (Success)
|
|
165
|
+
```html
|
|
166
|
+
<ai-chat
|
|
167
|
+
primary-color="#10B981"
|
|
168
|
+
primary-color-hover="#059669"
|
|
169
|
+
user-message-bg="#D1FAE5"
|
|
170
|
+
bot-message-bg="#F3F4F6">
|
|
171
|
+
</ai-chat>
|
|
173
172
|
```
|
|
174
173
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
"session_id": "string",
|
|
185
|
-
"question": "string"
|
|
186
|
-
}
|
|
174
|
+
### Purple Theme (Creative)
|
|
175
|
+
```html
|
|
176
|
+
<ai-chat
|
|
177
|
+
primary-color="#8B5CF6"
|
|
178
|
+
primary-color-hover="#7C3AED"
|
|
179
|
+
user-message-bg="#EDE9FE"
|
|
180
|
+
bot-message-bg="#F5F3FF">
|
|
181
|
+
</ai-chat>
|
|
187
182
|
```
|
|
188
183
|
|
|
189
|
-
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
"
|
|
193
|
-
|
|
184
|
+
### Red Theme (Alert)
|
|
185
|
+
```html
|
|
186
|
+
<ai-chat
|
|
187
|
+
primary-color="#EF4444"
|
|
188
|
+
primary-color-hover="#DC2626"
|
|
189
|
+
user-message-bg="#FEE2E2"
|
|
190
|
+
bot-message-bg="#FEF2F2">
|
|
191
|
+
</ai-chat>
|
|
194
192
|
```
|
|
195
193
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
### Built-in Themes
|
|
199
|
-
|
|
194
|
+
### Orange Theme (Warm)
|
|
200
195
|
```html
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
<ai-chat
|
|
197
|
+
primary-color="#F97316"
|
|
198
|
+
primary-color-hover="#EA580C"
|
|
199
|
+
user-message-bg="#FFEDD5"
|
|
200
|
+
bot-message-bg="#FFF7ED">
|
|
201
|
+
</ai-chat>
|
|
206
202
|
```
|
|
207
203
|
|
|
208
|
-
|
|
204
|
+
## Responsive Behavior
|
|
209
205
|
|
|
210
|
-
|
|
206
|
+
The widget automatically adapts to different screen sizes:
|
|
211
207
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
/* ... more variables */
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Shadow DOM
|
|
208
|
+
- **Desktop (>1024px)**: Full widget size
|
|
209
|
+
- **Tablet (769-1024px)**: Slightly larger widget (400px × 650px)
|
|
210
|
+
- **Small Tablet (481-768px)**: Compact widget (360px × 550px)
|
|
211
|
+
- **Mobile Portrait (≤480px)**: Nearly fullscreen (90vw × 70vh)
|
|
212
|
+
- **Mobile Landscape**: Wider widget (500px × adjusted height)
|
|
222
213
|
|
|
223
|
-
|
|
214
|
+
## Development
|
|
224
215
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
216
|
+
### Build for Production
|
|
217
|
+
```bash
|
|
218
|
+
npm run build
|
|
229
219
|
```
|
|
230
220
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
- [Vanilla JavaScript](./examples/vanilla.html)
|
|
236
|
-
- [React](./examples/react.tsx)
|
|
237
|
-
- [Vue](./examples/vue.vue)
|
|
238
|
-
- [Svelte](./examples/svelte.svelte)
|
|
239
|
-
- [Angular](./examples/angular.component.ts)
|
|
240
|
-
|
|
241
|
-
## 🌍 Browser Support
|
|
242
|
-
|
|
243
|
-
- Chrome/Edge 90+
|
|
244
|
-
- Firefox 88+
|
|
245
|
-
- Safari 14+
|
|
246
|
-
- Mobile browsers (iOS Safari 14+, Chrome Android)
|
|
247
|
-
|
|
248
|
-
Requires native Web Components support (Custom Elements v1, Shadow DOM v1).
|
|
249
|
-
|
|
250
|
-
## 🔄 Migration from React Version
|
|
251
|
-
|
|
252
|
-
If you were using the React-only version:
|
|
253
|
-
|
|
254
|
-
**Before:**
|
|
255
|
-
```tsx
|
|
256
|
-
import { AIChat } from '@a.izzuddin/ai-chat';
|
|
257
|
-
<AIChat apiUrl="..." />
|
|
221
|
+
### Run Development Server
|
|
222
|
+
```bash
|
|
223
|
+
npm run dev
|
|
258
224
|
```
|
|
259
225
|
|
|
260
|
-
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
<ai-chat api-url="..." />
|
|
226
|
+
### Lint Code
|
|
227
|
+
```bash
|
|
228
|
+
npm run lint
|
|
264
229
|
```
|
|
265
230
|
|
|
266
|
-
|
|
267
|
-
- Component name is lowercase: `<ai-chat>` instead of `<AIChat>`
|
|
268
|
-
- Attributes use kebab-case: `api-url` instead of `apiUrl`
|
|
269
|
-
- Events instead of callback props
|
|
270
|
-
|
|
271
|
-
## 🤝 Contributing
|
|
272
|
-
|
|
273
|
-
Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md).
|
|
274
|
-
|
|
275
|
-
## 📄 License
|
|
276
|
-
|
|
277
|
-
MIT © a.izzuddin
|
|
278
|
-
|
|
279
|
-
## 🔗 Links
|
|
231
|
+
## Browser Support
|
|
280
232
|
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
-
|
|
284
|
-
-
|
|
233
|
+
- Chrome/Edge (latest)
|
|
234
|
+
- Firefox (latest)
|
|
235
|
+
- Safari (latest)
|
|
236
|
+
- Modern mobile browsers
|
|
285
237
|
|
|
286
|
-
##
|
|
238
|
+
## License
|
|
287
239
|
|
|
288
|
-
|
|
289
|
-
- [Lit](https://lit.dev/) - The library powering this component
|
|
240
|
+
MIT
|
|
290
241
|
|
|
291
|
-
|
|
242
|
+
## Contributing
|
|
292
243
|
|
|
293
|
-
|
|
244
|
+
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)
|