@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 CHANGED
@@ -1,61 +1,52 @@
1
- # @a.izzuddin/ai-chat
1
+ # AI Chat Widget
2
2
 
3
- A **framework-agnostic** AI chat web component built with Lit and TypeScript. Works seamlessly with React, Vue, Svelte, Angular, and vanilla JavaScript.
3
+ A modern, customizable chat widget built with Lit web components. Features a clean UI, responsive design, and extensive theming options.
4
4
 
5
- [![npm version](https://img.shields.io/npm/v/@a.izzuddin/ai-chat)](https://www.npmjs.com/package/@a.izzuddin/ai-chat)
6
- [![npm downloads](https://img.shields.io/npm/dm/@a.izzuddin/ai-chat)](https://www.npmjs.com/package/@a.izzuddin/ai-chat)
5
+ ## Features
7
6
 
8
- ## Features
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
- - 🌐 **Framework Agnostic** - Works with any framework or no framework
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
- ## 📦 Installation
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
- ## 🚀 Quick Start
30
-
31
- ### Vanilla JavaScript / HTML
27
+ ### Basic Usage
32
28
 
29
+ **HTML:**
33
30
  ```html
34
- <!DOCTYPE html>
35
- <html>
36
- <body>
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
- <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>
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
- ### React
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={process.env.REACT_APP_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
- ### Vue
67
-
57
+ **Vue:**
68
58
  ```vue
69
59
  <template>
70
60
  <ai-chat
71
- :api-url="apiUrl"
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
- ### Svelte
72
+ ## Configuration
84
73
 
85
- ```svelte
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={apiUrl}
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
- ### Angular
99
-
100
- ```typescript
101
- import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
102
- import '@a.izzuddin/ai-chat';
103
-
104
- @Component({
105
- selector: 'app-root',
106
- template: '<ai-chat api-url="..." session-id="user-123"></ai-chat>',
107
- schemas: [CUSTOM_ELEMENTS_SCHEMA]
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
- ## 📖 API
98
+ ### Theme Customization
113
99
 
114
- ### Attributes
115
-
116
- | Attribute | Type | Default | Description |
117
- |-----------|------|---------|-------------|
118
- | `api-url` | `string` | **required** | Your API endpoint URL |
119
- | `session-id` | `string` | `"default-session"` | Session identifier for conversation context |
120
- | `title` | `string` | `"My AI Agent"` | Chat header title |
121
- | `theme` | `"light" \| "dark"` | `"light"` | UI theme |
122
- | `initial-messages` | `Message[]` | `[]` | Pre-populate chat with messages |
123
-
124
- ### Properties (JavaScript)
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
- ### Events
140
-
141
- ```javascript
142
- const chat = document.querySelector('ai-chat');
143
-
144
- // User sends a message
145
- chat.addEventListener('message-sent', (event) => {
146
- console.log('User message:', event.detail);
147
- // event.detail: { id: string, role: 'user', content: string }
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
- ### TypeScript Types
164
-
165
- ```typescript
166
- import type { Message } from '@a.izzuddin/ai-chat';
167
-
168
- interface Message {
169
- id: string;
170
- role: 'user' | 'assistant';
171
- content: string;
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
- ## 🔌 Backend API Requirements
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
- Your API must implement this endpoint:
145
+ ## Available Attributes
178
146
 
179
- **POST `/ask`**
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
- Response:
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
- ## 🎨 Theming
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
- ### Built-in Themes
199
+ ### Response Behavior
199
200
 
200
- ```html
201
- <!-- Light mode (default) -->
202
- <ai-chat theme="light"></ai-chat>
203
-
204
- <!-- Dark mode -->
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
- ### CSS Custom Properties
207
+ ### List Formatting Example
209
208
 
210
- Customize colors by overriding CSS variables:
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
- ### Shadow DOM
214
+ 1. Stimulating local industry growth
215
+ 2. Driving technology-based economic growth
216
+ 3. Creating job opportunities
222
217
 
223
- The component uses Shadow DOM for style encapsulation. To style internal elements, use `::part()`:
224
-
225
- ```css
226
- ai-chat::part(header) {
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
- ## 📚 Examples
224
+ This will be automatically rendered as proper HTML lists.
232
225
 
233
- Check out the [examples](./examples) directory for complete working examples:
226
+ ## Events
234
227
 
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)
228
+ The component fires custom events you can listen to:
240
229
 
241
- ## 🌍 Browser Support
230
+ ```javascript
231
+ const chat = document.querySelector('ai-chat');
242
232
 
243
- - Chrome/Edge 90+
244
- - Firefox 88+
245
- - Safari 14+
246
- - Mobile browsers (iOS Safari 14+, Chrome Android)
233
+ // User sends a message
234
+ chat.addEventListener('message-sent', (event) => {
235
+ console.log('Message sent:', event.detail);
236
+ });
247
237
 
248
- Requires native Web Components support (Custom Elements v1, Shadow DOM v1).
238
+ // AI responds
239
+ chat.addEventListener('response-received', (event) => {
240
+ console.log('Response received:', event.detail);
241
+ });
249
242
 
250
- ## 🔄 Migration from React Version
243
+ // Error occurs
244
+ chat.addEventListener('error', (event) => {
245
+ console.error('Error:', event.detail);
246
+ });
247
+ ```
251
248
 
252
- If you were using the React-only version:
249
+ ## Theme Examples
253
250
 
254
- **Before:**
255
- ```tsx
256
- import { AIChat } from '@a.izzuddin/ai-chat';
257
- <AIChat apiUrl="..." />
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
- **After:**
261
- ```tsx
262
- import '@a.izzuddin/ai-chat';
263
- <ai-chat api-url="..." />
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
- Key differences:
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
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
- ## 🤝 Contributing
291
+ ## Responsive Behavior
272
292
 
273
- Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md).
293
+ The widget automatically adapts to different screen sizes:
274
294
 
275
- ## 📄 License
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
- MIT © a.izzuddin
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
- ## 🔗 Links
318
+ ## Browser Support
280
319
 
281
- - [Documentation](https://github.com/a.izzuddin/ai-chat#readme)
282
- - [Examples](./examples)
283
- - [Issue Tracker](https://github.com/a.izzuddin/ai-chat/issues)
284
- - [npm Package](https://www.npmjs.com/package/@a.izzuddin/ai-chat)
320
+ - Chrome/Edge (latest)
321
+ - Firefox (latest)
322
+ - Safari (latest)
323
+ - Modern mobile browsers
285
324
 
286
- ## ⭐ Similar Projects
325
+ ## License
287
326
 
288
- - [@n8n/chat](https://www.npmjs.com/package/@n8n/chat) - n8n's chat widget
289
- - [Lit](https://lit.dev/) - The library powering this component
327
+ MIT
290
328
 
291
- ---
329
+ ## Contributing
292
330
 
293
- **Built with [Lit](https://lit.dev/)** **Powered by Web Components**
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/a.izzuddin/ai-chat#readme)
292
- - 🐛 [Issue Tracker](https://github.com/a.izzuddin/ai-chat/issues)
293
- - 💬 [Discussions](https://github.com/a.izzuddin/ai-chat/discussions)
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)