@courseecho/ai-widget-jquery 1.0.0 → 1.0.2
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/LICENSE +25 -0
- package/README.md +397 -0
- package/dist/ai-widget-jquery.d.ts +27 -0
- package/dist/ai-widget-jquery.d.ts.map +1 -0
- package/dist/ai-widget-jquery.js +260 -0
- package/dist/ai-widget-jquery.js.map +1 -0
- package/package.json +49 -26
- package/ai-widget-jquery.ts +0 -328
- package/tsconfig.json +0 -25
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CourseEcho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
For more information about CourseEcho, visit https://courseecho.com
|
package/README.md
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# 📜 @courseecho/ai-widget-jquery
|
|
2
|
+
|
|
3
|
+
**jQuery plugin for AI chat widget** - Script tag integration for vanilla JavaScript and legacy projects.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@courseecho/ai-widget-jquery)
|
|
6
|
+
[](https://unpkg.com/@courseecho/ai-widget-jquery)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## 📖 Overview
|
|
10
|
+
|
|
11
|
+
A **jQuery plugin** for integrating CourseEcho AI chat into vanilla JavaScript, HTML, WordPress, and legacy projects.
|
|
12
|
+
|
|
13
|
+
- ✅ jQuery 1.0+ compatible
|
|
14
|
+
- ✅ Works with script tags (no build required)
|
|
15
|
+
- ✅ Available on CDN (unpkg, jsDelivr)
|
|
16
|
+
- ✅ 10KB minified
|
|
17
|
+
- ✅ Zero build dependencies
|
|
18
|
+
|
|
19
|
+
## 🚀 Quick Start
|
|
20
|
+
|
|
21
|
+
### Option 1: Script Tag (Easiest)
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<!DOCTYPE html>
|
|
25
|
+
<html>
|
|
26
|
+
<head>
|
|
27
|
+
<!-- jQuery -->
|
|
28
|
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
29
|
+
|
|
30
|
+
<!-- AI Widget -->
|
|
31
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div id="widget"></div>
|
|
35
|
+
|
|
36
|
+
<script>
|
|
37
|
+
$(document).ready(function() {
|
|
38
|
+
$('#widget').aiChatWidget({
|
|
39
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
40
|
+
context: {
|
|
41
|
+
pageType: 'course',
|
|
42
|
+
entityId: 'course-123',
|
|
43
|
+
userId: 'user-456'
|
|
44
|
+
},
|
|
45
|
+
jwtToken: 'your-token-here'
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Option 2: npm + Bundler
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install @courseecho/ai-widget-jquery
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import jQuery from 'jquery';
|
|
61
|
+
import { createJQueryPlugin } from '@courseecho/ai-widget-jquery';
|
|
62
|
+
|
|
63
|
+
const $ = jQuery;
|
|
64
|
+
createJQueryPlugin($);
|
|
65
|
+
|
|
66
|
+
$('#widget').aiChatWidget({ /* options */ });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 📦 CDN URLs
|
|
70
|
+
|
|
71
|
+
**unpkg (Recommended):**
|
|
72
|
+
```html
|
|
73
|
+
<!-- Latest -->
|
|
74
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery/dist/ai-widget-jquery.js"></script>
|
|
75
|
+
|
|
76
|
+
<!-- Specific version -->
|
|
77
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
78
|
+
|
|
79
|
+
<!-- Minified -->
|
|
80
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.min.js"></script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**jsDelivr:**
|
|
84
|
+
```html
|
|
85
|
+
<script src="https://cdn.jsdelivr.net/npm/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 🎯 API Methods
|
|
89
|
+
|
|
90
|
+
### Initialization
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
$('#container').aiChatWidget({
|
|
94
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
95
|
+
context: {
|
|
96
|
+
pageType: 'course',
|
|
97
|
+
entityId: '123',
|
|
98
|
+
userId: 'user@example.com'
|
|
99
|
+
},
|
|
100
|
+
jwtToken: 'your-jwt-token',
|
|
101
|
+
apiKey: 'alternative-api-key',
|
|
102
|
+
theme: 'light', // or 'dark'
|
|
103
|
+
position: 'bottom-right', // or 'bottom-left', 'top-left', 'top-right'
|
|
104
|
+
onMessage: function(msg) { },
|
|
105
|
+
onError: function(err) { },
|
|
106
|
+
onLoading: function(isLoading) { }
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Send Message
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
$('#widget').aiChatWidget('send', 'Hello, ask me anything!');
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Get Messages
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
const messages = $('#widget').aiChatWidget('getMessages');
|
|
120
|
+
console.log(messages);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Get Loading State
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
const isLoading = $('#widget').aiChatWidget('isLoading');
|
|
127
|
+
if (isLoading) {
|
|
128
|
+
console.log('Waiting for response...');
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Set Context
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
$('#widget').aiChatWidget('setContext', {
|
|
136
|
+
userId: 'new-user-id',
|
|
137
|
+
courseId: 'new-course-id'
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Clear History
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
$('#widget').aiChatWidget('clear');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Destroy
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
$('#widget').aiChatWidget('destroy');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 💡 Examples
|
|
154
|
+
|
|
155
|
+
### Example 1: Static HTML Page
|
|
156
|
+
|
|
157
|
+
```html
|
|
158
|
+
<!DOCTYPE html>
|
|
159
|
+
<html lang="en">
|
|
160
|
+
<head>
|
|
161
|
+
<meta charset="UTF-8">
|
|
162
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
163
|
+
<title>Course Page</title>
|
|
164
|
+
<style>
|
|
165
|
+
body { font-family: Arial, sans-serif; }
|
|
166
|
+
.content { max-width: 1000px; margin: 0 auto; padding: 20px; }
|
|
167
|
+
</style>
|
|
168
|
+
</head>
|
|
169
|
+
<body>
|
|
170
|
+
<div class="content">
|
|
171
|
+
<h1>Learn JavaScript</h1>
|
|
172
|
+
<p>Welcome to our JavaScript course...</p>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
176
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
177
|
+
|
|
178
|
+
<script>
|
|
179
|
+
$(function() {
|
|
180
|
+
$('#ai-widget').aiChatWidget({
|
|
181
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
182
|
+
context: {
|
|
183
|
+
pageType: 'course',
|
|
184
|
+
entityId: 'js-101',
|
|
185
|
+
userId: 'student-123'
|
|
186
|
+
},
|
|
187
|
+
jwtToken: localStorage.getItem('token'),
|
|
188
|
+
theme: 'light',
|
|
189
|
+
position: 'bottom-right'
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
<!-- Widget container -->
|
|
195
|
+
<div id="ai-widget"></div>
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Example 2: WordPress Plugin
|
|
201
|
+
|
|
202
|
+
Add to your WordPress theme's `functions.php`:
|
|
203
|
+
|
|
204
|
+
```php
|
|
205
|
+
<?php
|
|
206
|
+
add_action('wp_footer', function() {
|
|
207
|
+
if (is_single() && get_post_type() === 'course') {
|
|
208
|
+
?>
|
|
209
|
+
<div id="course-ai-widget"></div>
|
|
210
|
+
|
|
211
|
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
212
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
213
|
+
|
|
214
|
+
<script>
|
|
215
|
+
jQuery(function($) {
|
|
216
|
+
$('#course-ai-widget').aiChatWidget({
|
|
217
|
+
apiEndpoint: '<?php echo get_option("ai_api_endpoint"); ?>',
|
|
218
|
+
context: {
|
|
219
|
+
pageType: 'course',
|
|
220
|
+
entityId: '<?php echo get_the_ID(); ?>',
|
|
221
|
+
userId: '<?php echo get_current_user_id(); ?>'
|
|
222
|
+
},
|
|
223
|
+
jwtToken: '<?php echo get_user_meta(get_current_user_id(), "jwt_token", true); ?>'
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
</script>
|
|
227
|
+
<?php
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Example 3: Multiple Widgets
|
|
233
|
+
|
|
234
|
+
```html
|
|
235
|
+
<button onclick="toggleWidget(1)">Chat about Course 1</button>
|
|
236
|
+
<div id="widget-1"></div>
|
|
237
|
+
|
|
238
|
+
<button onclick="toggleWidget(2)">Chat about Course 2</button>
|
|
239
|
+
<div id="widget-2"></div>
|
|
240
|
+
|
|
241
|
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
242
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
243
|
+
|
|
244
|
+
<script>
|
|
245
|
+
function toggleWidget(courseId) {
|
|
246
|
+
const widgetId = '#widget-' + courseId;
|
|
247
|
+
|
|
248
|
+
$(widgetId).aiChatWidget({
|
|
249
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
250
|
+
context: {
|
|
251
|
+
pageType: 'course',
|
|
252
|
+
entityId: 'course-' + courseId,
|
|
253
|
+
userId: getUserId()
|
|
254
|
+
},
|
|
255
|
+
jwtToken: getToken()
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
</script>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Example 4: Real-time User Tracking
|
|
262
|
+
|
|
263
|
+
```html
|
|
264
|
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
265
|
+
<script src="https://unpkg.com/@courseecho/ai-widget-jquery@1.0.1/dist/ai-widget-jquery.js"></script>
|
|
266
|
+
|
|
267
|
+
<script>
|
|
268
|
+
$(function() {
|
|
269
|
+
const $widget = $('#ai-widget');
|
|
270
|
+
|
|
271
|
+
// Initialize
|
|
272
|
+
$widget.aiChatWidget({
|
|
273
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
274
|
+
context: {
|
|
275
|
+
pageType: getCurrentPage(),
|
|
276
|
+
entityId: getCurrentEntityId(),
|
|
277
|
+
userId: getCurrentUserId()
|
|
278
|
+
},
|
|
279
|
+
jwtToken: getToken()
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Update context when page changes
|
|
283
|
+
$(document).on('pagechange', function(e) {
|
|
284
|
+
$widget.aiChatWidget('setContext', {
|
|
285
|
+
pageType: e.pageType,
|
|
286
|
+
entityId: e.entityId
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Handle messages
|
|
291
|
+
$widget.on('message', function(e, message) {
|
|
292
|
+
console.log('User sent:', message);
|
|
293
|
+
logToAnalytics('ai_chat_message', { message });
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// Handle errors
|
|
297
|
+
$widget.on('error', function(e, error) {
|
|
298
|
+
console.error('Chat error:', error);
|
|
299
|
+
showErrorNotification(error);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
</script>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 🔐 Authentication
|
|
306
|
+
|
|
307
|
+
### JWT Token
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
$('#widget').aiChatWidget({
|
|
311
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
312
|
+
context: { pageType: 'course' },
|
|
313
|
+
jwtToken: 'eyJhbGciOiJIUzI1NiIs...'
|
|
314
|
+
});
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### API Key
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
$('#widget').aiChatWidget({
|
|
321
|
+
apiEndpoint: 'https://api.courseecho.com/api',
|
|
322
|
+
context: { pageType: 'course' },
|
|
323
|
+
apiKey: 'sk-123456789...'
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## 🎨 Styling
|
|
328
|
+
|
|
329
|
+
Default styles are included. Override with CSS:
|
|
330
|
+
|
|
331
|
+
```css
|
|
332
|
+
.ai-chat-widget {
|
|
333
|
+
border-radius: 8px;
|
|
334
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.ai-chat-message.user {
|
|
338
|
+
background: #3b82f6;
|
|
339
|
+
color: white;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.ai-chat-message.assistant {
|
|
343
|
+
background: #f3f4f6;
|
|
344
|
+
color: #1f2937;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
.ai-chat-input {
|
|
348
|
+
border: 1px solid #e5e7eb;
|
|
349
|
+
border-radius: 4px;
|
|
350
|
+
padding: 8px;
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 📊 Data Export
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
// Get all messages
|
|
358
|
+
const messages = $('#widget').aiChatWidget('getMessages');
|
|
359
|
+
|
|
360
|
+
// Export as JSON
|
|
361
|
+
const json = JSON.stringify(messages);
|
|
362
|
+
|
|
363
|
+
// Save to file
|
|
364
|
+
const blob = new Blob([json], { type: 'application/json' });
|
|
365
|
+
const url = URL.createObjectURL(blob);
|
|
366
|
+
const a = document.createElement('a');
|
|
367
|
+
a.href = url;
|
|
368
|
+
a.download = 'chat-history.json';
|
|
369
|
+
a.click();
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## 🌍 About CourseEcho
|
|
373
|
+
|
|
374
|
+
[CourseEcho](https://courseecho.com) - Intelligent education powered by AI.
|
|
375
|
+
|
|
376
|
+
- 🌐 Website: https://courseecho.com
|
|
377
|
+
- 📧 Support: support@courseecho.com
|
|
378
|
+
- 📱 Product: https://courseecho.com/products/ai-widget
|
|
379
|
+
|
|
380
|
+
## 📄 License
|
|
381
|
+
|
|
382
|
+
MIT © 2026 CourseEcho
|
|
383
|
+
|
|
384
|
+
## 📞 Support
|
|
385
|
+
|
|
386
|
+
- 📖 Docs: https://courseecho.com/docs
|
|
387
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/courseecho/ai-widget-sdk/issues)
|
|
388
|
+
- 💬 Chat: [Discord](https://discord.gg/courseecho)
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
**Other frameworks:**
|
|
393
|
+
- [React](../ai-widget-react)
|
|
394
|
+
- [Vue 3](../ai-widget-vue)
|
|
395
|
+
- [Angular 19+](../ai-widget-angular)
|
|
396
|
+
- [Node.js](../ai-client-node)
|
|
397
|
+
- [Core SDK](../ai-core-sdk)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Chat Widget - jQuery Plugin
|
|
3
|
+
* Usage: $('#container').aiChatWidget(options)
|
|
4
|
+
*/
|
|
5
|
+
export interface AiWidgetOptions {
|
|
6
|
+
apiEndpoint: string;
|
|
7
|
+
context: {
|
|
8
|
+
pageType: string;
|
|
9
|
+
entityId?: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
customData?: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
jwtToken?: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
theme?: 'light' | 'dark';
|
|
16
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
17
|
+
onMessage?: (message: any) => void;
|
|
18
|
+
onError?: (error: string) => void;
|
|
19
|
+
onLoading?: (isLoading: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
declare global {
|
|
22
|
+
interface JQuery {
|
|
23
|
+
aiChatWidget(options?: AiWidgetOptions | string, arg?: any): JQuery;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export declare function createJQueryPlugin(jQuery: any): void;
|
|
27
|
+
//# sourceMappingURL=ai-widget-jquery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-widget-jquery.d.ts","sourceRoot":"","sources":["../ai-widget-jquery.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAClC,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;IACrE,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;KACrE;CACF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,QA8E7C"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Chat Widget - jQuery Plugin
|
|
3
|
+
* Usage: $('#container').aiChatWidget(options)
|
|
4
|
+
*/
|
|
5
|
+
export function createJQueryPlugin(jQuery) {
|
|
6
|
+
const methods = {
|
|
7
|
+
init(element, options) {
|
|
8
|
+
const $elem = jQuery(element);
|
|
9
|
+
const instance = new AiWidgetInstance(element, options);
|
|
10
|
+
$elem.data('aiWidget', instance);
|
|
11
|
+
return $elem;
|
|
12
|
+
},
|
|
13
|
+
send(element, message) {
|
|
14
|
+
const instance = jQuery(element).data('aiWidget');
|
|
15
|
+
if (instance) {
|
|
16
|
+
return instance.sendMessage(message);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
getMessages(element) {
|
|
20
|
+
const instance = jQuery(element).data('aiWidget');
|
|
21
|
+
if (instance) {
|
|
22
|
+
return instance.getMessages();
|
|
23
|
+
}
|
|
24
|
+
return [];
|
|
25
|
+
},
|
|
26
|
+
clear(element) {
|
|
27
|
+
const instance = jQuery(element).data('aiWidget');
|
|
28
|
+
if (instance) {
|
|
29
|
+
instance.clearMessages();
|
|
30
|
+
}
|
|
31
|
+
return jQuery(element);
|
|
32
|
+
},
|
|
33
|
+
setContext(element, context) {
|
|
34
|
+
const instance = jQuery(element).data('aiWidget');
|
|
35
|
+
if (instance) {
|
|
36
|
+
instance.updateContext(context);
|
|
37
|
+
}
|
|
38
|
+
return jQuery(element);
|
|
39
|
+
},
|
|
40
|
+
isLoading(element) {
|
|
41
|
+
const instance = jQuery(element).data('aiWidget');
|
|
42
|
+
if (instance) {
|
|
43
|
+
return instance.isLoadingState();
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
destroy(element) {
|
|
48
|
+
const instance = jQuery(element).data('aiWidget');
|
|
49
|
+
if (instance) {
|
|
50
|
+
instance.destroy();
|
|
51
|
+
}
|
|
52
|
+
jQuery(element).removeData('aiWidget').empty();
|
|
53
|
+
return jQuery(element);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
jQuery.fn.aiChatWidget = function (...args) {
|
|
57
|
+
const methodOrOptions = args[0];
|
|
58
|
+
const additionalArgs = args.slice(1);
|
|
59
|
+
if (methodOrOptions === undefined || typeof methodOrOptions === 'object') {
|
|
60
|
+
// Init
|
|
61
|
+
return this.each(function () {
|
|
62
|
+
if (!jQuery(this).data('aiWidget')) {
|
|
63
|
+
methods.init(this, methodOrOptions || {});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (methods[methodOrOptions]) {
|
|
68
|
+
// Method call
|
|
69
|
+
return this.each(function () {
|
|
70
|
+
methods[methodOrOptions](this, ...additionalArgs);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
class AiWidgetInstance {
|
|
77
|
+
constructor(element, options) {
|
|
78
|
+
this.messages = [];
|
|
79
|
+
this.isOpen = false;
|
|
80
|
+
this.isLoading = false;
|
|
81
|
+
this.element = element;
|
|
82
|
+
this.options = {
|
|
83
|
+
theme: 'light',
|
|
84
|
+
position: 'bottom-right',
|
|
85
|
+
...options,
|
|
86
|
+
};
|
|
87
|
+
this.initialize();
|
|
88
|
+
}
|
|
89
|
+
initialize() {
|
|
90
|
+
const $ = window.$;
|
|
91
|
+
const $elem = $(this.element);
|
|
92
|
+
$elem.addClass(`ai-widget-container ai-widget-${this.options.theme} ai-widget-${this.options.position}`);
|
|
93
|
+
// Create toggle button
|
|
94
|
+
this.$button = $(`
|
|
95
|
+
<button class="ai-widget-toggle-button" aria-label="Open AI Chat">
|
|
96
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
97
|
+
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
98
|
+
</svg>
|
|
99
|
+
</button>
|
|
100
|
+
`);
|
|
101
|
+
// Create widget window
|
|
102
|
+
this.$widget = $(`
|
|
103
|
+
<div class="ai-widget-window" style="display: none;">
|
|
104
|
+
<div class="ai-widget-header">
|
|
105
|
+
<h3>AI Assistant</h3>
|
|
106
|
+
<button class="ai-widget-close-button">×</button>
|
|
107
|
+
</div>
|
|
108
|
+
<div class="ai-widget-messages">
|
|
109
|
+
<div class="ai-widget-welcome">
|
|
110
|
+
<p>👋 Hello! I'm your AI assistant.</p>
|
|
111
|
+
<p>How can I help you today?</p>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
<form class="ai-widget-form">
|
|
115
|
+
<input type="text" class="ai-widget-input" placeholder="Type your message..." />
|
|
116
|
+
<button type="submit" class="ai-widget-send-button">→</button>
|
|
117
|
+
</form>
|
|
118
|
+
</div>
|
|
119
|
+
`);
|
|
120
|
+
this.$messages = this.$widget.find('.ai-widget-messages');
|
|
121
|
+
this.$input = this.$widget.find('.ai-widget-input');
|
|
122
|
+
// Event handlers
|
|
123
|
+
this.$button.on('click', () => this.open());
|
|
124
|
+
this.$widget.find('.ai-widget-close-button').on('click', () => this.close());
|
|
125
|
+
this.$widget.find('.ai-widget-form').on('submit', (e) => {
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
this.sendMessage(this.$input.val());
|
|
128
|
+
this.$input.val('');
|
|
129
|
+
});
|
|
130
|
+
// Append to element
|
|
131
|
+
$(this.element).append(this.$button).append(this.$widget);
|
|
132
|
+
}
|
|
133
|
+
open() {
|
|
134
|
+
this.isOpen = true;
|
|
135
|
+
window.$(this.element)
|
|
136
|
+
.find('.ai-widget-button')
|
|
137
|
+
.hide();
|
|
138
|
+
window.$(this.element)
|
|
139
|
+
.find('.ai-widget-window')
|
|
140
|
+
.show();
|
|
141
|
+
}
|
|
142
|
+
close() {
|
|
143
|
+
this.isOpen = false;
|
|
144
|
+
window.$(this.element)
|
|
145
|
+
.find('.ai-widget-button')
|
|
146
|
+
.show();
|
|
147
|
+
window.$(this.element)
|
|
148
|
+
.find('.ai-widget-window')
|
|
149
|
+
.hide();
|
|
150
|
+
}
|
|
151
|
+
async sendMessage(message) {
|
|
152
|
+
if (!message.trim() || this.isLoading)
|
|
153
|
+
return;
|
|
154
|
+
// Add user message
|
|
155
|
+
const userMsg = {
|
|
156
|
+
id: `${Date.now()}-${Math.random()}`,
|
|
157
|
+
role: 'user',
|
|
158
|
+
content: message,
|
|
159
|
+
timestamp: new Date(),
|
|
160
|
+
};
|
|
161
|
+
this.messages.push(userMsg);
|
|
162
|
+
this.appendMessageToUI(userMsg);
|
|
163
|
+
// Set loading
|
|
164
|
+
this.isLoadingState(true);
|
|
165
|
+
if (this.options.onLoading) {
|
|
166
|
+
this.options.onLoading(true);
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
// Call backend
|
|
170
|
+
const response = await window.fetch(`${this.options.apiEndpoint}/api/aiorchestrator/query`, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: {
|
|
173
|
+
'Content-Type': 'application/json',
|
|
174
|
+
Authorization: `Bearer ${this.options.jwtToken || ''}`,
|
|
175
|
+
},
|
|
176
|
+
body: JSON.stringify({
|
|
177
|
+
userQuery: message,
|
|
178
|
+
pageType: this.options.context.pageType,
|
|
179
|
+
entityId: this.options.context.entityId,
|
|
180
|
+
contextData: this.options.context.customData,
|
|
181
|
+
}),
|
|
182
|
+
});
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
throw new Error(`HTTP ${response.status}`);
|
|
185
|
+
}
|
|
186
|
+
const data = await response.json();
|
|
187
|
+
// Add assistant message
|
|
188
|
+
const assistantMsg = {
|
|
189
|
+
id: data.sessionId,
|
|
190
|
+
role: 'assistant',
|
|
191
|
+
content: data.response,
|
|
192
|
+
timestamp: new Date(data.timestamp),
|
|
193
|
+
};
|
|
194
|
+
this.messages.push(assistantMsg);
|
|
195
|
+
this.appendMessageToUI(assistantMsg);
|
|
196
|
+
if (this.options.onMessage) {
|
|
197
|
+
this.options.onMessage(assistantMsg);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
const errorText = String(error);
|
|
202
|
+
if (this.options.onError) {
|
|
203
|
+
this.options.onError(errorText);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
this.isLoadingState(false);
|
|
208
|
+
if (this.options.onLoading) {
|
|
209
|
+
this.options.onLoading(false);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
appendMessageToUI(message) {
|
|
214
|
+
const $ = window.$;
|
|
215
|
+
const messageEl = $(`
|
|
216
|
+
<div class="ai-widget-message ai-widget-message-${message.role}">
|
|
217
|
+
<div class="ai-widget-message-content">${message.content}</div>
|
|
218
|
+
<div class="ai-widget-message-time">
|
|
219
|
+
${new Date(message.timestamp).toLocaleTimeString([], {
|
|
220
|
+
hour: '2-digit',
|
|
221
|
+
minute: '2-digit',
|
|
222
|
+
})}
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
`);
|
|
226
|
+
if (this.$messages.find('.ai-widget-welcome').length) {
|
|
227
|
+
this.$messages.find('.ai-widget-welcome').remove();
|
|
228
|
+
}
|
|
229
|
+
this.$messages.append(messageEl);
|
|
230
|
+
this.$messages.scrollTop(this.$messages.prop('scrollHeight'));
|
|
231
|
+
}
|
|
232
|
+
getMessages() {
|
|
233
|
+
return [...this.messages];
|
|
234
|
+
}
|
|
235
|
+
clearMessages() {
|
|
236
|
+
this.messages = [];
|
|
237
|
+
const $ = window.$;
|
|
238
|
+
this.$messages.html(`
|
|
239
|
+
<div class="ai-widget-welcome">
|
|
240
|
+
<p>👋 Hello! I'm your AI assistant.</p>
|
|
241
|
+
<p>How can I help you today?</p>
|
|
242
|
+
</div>
|
|
243
|
+
`);
|
|
244
|
+
}
|
|
245
|
+
updateContext(context) {
|
|
246
|
+
this.options.context = { ...this.options.context, ...context };
|
|
247
|
+
}
|
|
248
|
+
isLoadingState(value) {
|
|
249
|
+
if (value !== undefined) {
|
|
250
|
+
this.isLoading = value;
|
|
251
|
+
}
|
|
252
|
+
return this.isLoading;
|
|
253
|
+
}
|
|
254
|
+
destroy() {
|
|
255
|
+
this.$button.off('click');
|
|
256
|
+
this.$widget.find('.ai-widget-close-button').off('click');
|
|
257
|
+
this.$widget.find('.ai-widget-form').off('submit');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=ai-widget-jquery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-widget-jquery.js","sourceRoot":"","sources":["../ai-widget-jquery.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyBH,MAAM,UAAU,kBAAkB,CAAC,MAAW;IAC5C,MAAM,OAAO,GAA6B;QACxC,IAAI,CAAC,OAAY,EAAE,OAAwB;YACzC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACxD,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,OAAY,EAAE,OAAe;YAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,QAAQ,EAAE,CAAC;gBAC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+
"name": "@courseecho/ai-widget-jquery",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "jQuery plugin for AI Chat Widget - enables vanilla JavaScript/HTML integration via npm or script tag",
|
|
5
|
+
"main": "dist/ai-widget-jquery.cjs",
|
|
6
|
+
"module": "dist/ai-widget-jquery.mjs",
|
|
7
|
+
"browser": "dist/ai-widget-jquery.umd.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"unpkg": "dist/ai-widget-jquery.umd.min.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/ai-widget-jquery.mjs",
|
|
13
|
+
"require": "./dist/ai-widget-jquery.cjs",
|
|
14
|
+
"browser": "./dist/ai-widget-jquery.umd.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"build:umd": "tsc \u0026\u0026 npm run esbuild",
|
|
25
|
+
"esbuild": "esbuild dist/index.js --bundle --minify --format=umd --global-name=AiWidgetjQuery --outfile=dist/ai-widget-jquery.umd.min.js",
|
|
26
|
+
"dev": "tsc --watch"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"jquery": "\u003e=1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"typescript": "^5.3.0",
|
|
33
|
+
"esbuild": "^0.19.0"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"ai",
|
|
37
|
+
"chatbot",
|
|
38
|
+
"jquery",
|
|
39
|
+
"widget",
|
|
40
|
+
"vanilla-js",
|
|
41
|
+
"html",
|
|
42
|
+
"script-tag",
|
|
43
|
+
"cdn"
|
|
44
|
+
],
|
|
45
|
+
"author": "CourseEcho",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/courseecho/ai-widget-sdk.git"
|
|
50
|
+
}
|
|
28
51
|
}
|
package/ai-widget-jquery.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI Chat Widget - jQuery Plugin
|
|
3
|
-
* Usage: $('#container').aiChatWidget(options)
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface AiWidgetOptions {
|
|
7
|
-
apiEndpoint: string;
|
|
8
|
-
context: {
|
|
9
|
-
pageType: string;
|
|
10
|
-
entityId?: string;
|
|
11
|
-
userId?: string;
|
|
12
|
-
customData?: Record<string, any>;
|
|
13
|
-
};
|
|
14
|
-
jwtToken?: string;
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
theme?: 'light' | 'dark';
|
|
17
|
-
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
18
|
-
onMessage?: (message: any) => void;
|
|
19
|
-
onError?: (error: string) => void;
|
|
20
|
-
onLoading?: (isLoading: boolean) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
declare global {
|
|
24
|
-
interface JQuery {
|
|
25
|
-
aiChatWidget(options?: AiWidgetOptions | string, arg?: any): JQuery;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function createJQueryPlugin(jQuery: any) {
|
|
30
|
-
const methods: Record<string, Function> = {
|
|
31
|
-
init(element: any, options: AiWidgetOptions) {
|
|
32
|
-
const $elem = jQuery(element);
|
|
33
|
-
const instance = new AiWidgetInstance(element, options);
|
|
34
|
-
$elem.data('aiWidget', instance);
|
|
35
|
-
return $elem;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
send(element: any, message: string) {
|
|
39
|
-
const instance = jQuery(element).data('aiWidget');
|
|
40
|
-
if (instance) {
|
|
41
|
-
return instance.sendMessage(message);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
getMessages(element: any) {
|
|
46
|
-
const instance = jQuery(element).data('aiWidget');
|
|
47
|
-
if (instance) {
|
|
48
|
-
return instance.getMessages();
|
|
49
|
-
}
|
|
50
|
-
return [];
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
clear(element: any) {
|
|
54
|
-
const instance = jQuery(element).data('aiWidget');
|
|
55
|
-
if (instance) {
|
|
56
|
-
instance.clearMessages();
|
|
57
|
-
}
|
|
58
|
-
return jQuery(element);
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
setContext(element: any, context: any) {
|
|
62
|
-
const instance = jQuery(element).data('aiWidget');
|
|
63
|
-
if (instance) {
|
|
64
|
-
instance.updateContext(context);
|
|
65
|
-
}
|
|
66
|
-
return jQuery(element);
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
isLoading(element: any) {
|
|
70
|
-
const instance = jQuery(element).data('aiWidget');
|
|
71
|
-
if (instance) {
|
|
72
|
-
return instance.isLoadingState();
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
destroy(element: any) {
|
|
78
|
-
const instance = jQuery(element).data('aiWidget');
|
|
79
|
-
if (instance) {
|
|
80
|
-
instance.destroy();
|
|
81
|
-
}
|
|
82
|
-
jQuery(element).removeData('aiWidget').empty();
|
|
83
|
-
return jQuery(element);
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
jQuery.fn.aiChatWidget = function (...args: any[]) {
|
|
88
|
-
const methodOrOptions = args[0];
|
|
89
|
-
const additionalArgs = args.slice(1);
|
|
90
|
-
|
|
91
|
-
if (methodOrOptions === undefined || typeof methodOrOptions === 'object') {
|
|
92
|
-
// Init
|
|
93
|
-
return this.each(function () {
|
|
94
|
-
if (!jQuery(this).data('aiWidget')) {
|
|
95
|
-
methods.init(this, methodOrOptions || {});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
} else if (methods[methodOrOptions]) {
|
|
99
|
-
// Method call
|
|
100
|
-
return this.each(function () {
|
|
101
|
-
methods[methodOrOptions](this, ...additionalArgs);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return this;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
class AiWidgetInstance {
|
|
110
|
-
private element: HTMLElement;
|
|
111
|
-
private options: AiWidgetOptions;
|
|
112
|
-
private messages: any[] = [];
|
|
113
|
-
private isOpen = false;
|
|
114
|
-
private isLoading = false;
|
|
115
|
-
private $widget: any;
|
|
116
|
-
private $messages: any;
|
|
117
|
-
private $input: any;
|
|
118
|
-
private $button: any;
|
|
119
|
-
|
|
120
|
-
constructor(element: HTMLElement, options: AiWidgetOptions) {
|
|
121
|
-
this.element = element;
|
|
122
|
-
this.options = {
|
|
123
|
-
theme: 'light',
|
|
124
|
-
position: 'bottom-right',
|
|
125
|
-
...options,
|
|
126
|
-
};
|
|
127
|
-
this.initialize();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private initialize(): void {
|
|
131
|
-
const $ = (window as any).$;
|
|
132
|
-
const $elem = $(this.element);
|
|
133
|
-
|
|
134
|
-
$elem.addClass(
|
|
135
|
-
`ai-widget-container ai-widget-${this.options.theme} ai-widget-${this.options.position}`
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
// Create toggle button
|
|
139
|
-
this.$button = $(`
|
|
140
|
-
<button class="ai-widget-toggle-button" aria-label="Open AI Chat">
|
|
141
|
-
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
142
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
143
|
-
</svg>
|
|
144
|
-
</button>
|
|
145
|
-
`);
|
|
146
|
-
|
|
147
|
-
// Create widget window
|
|
148
|
-
this.$widget = $(`
|
|
149
|
-
<div class="ai-widget-window" style="display: none;">
|
|
150
|
-
<div class="ai-widget-header">
|
|
151
|
-
<h3>AI Assistant</h3>
|
|
152
|
-
<button class="ai-widget-close-button">×</button>
|
|
153
|
-
</div>
|
|
154
|
-
<div class="ai-widget-messages">
|
|
155
|
-
<div class="ai-widget-welcome">
|
|
156
|
-
<p>👋 Hello! I'm your AI assistant.</p>
|
|
157
|
-
<p>How can I help you today?</p>
|
|
158
|
-
</div>
|
|
159
|
-
</div>
|
|
160
|
-
<form class="ai-widget-form">
|
|
161
|
-
<input type="text" class="ai-widget-input" placeholder="Type your message..." />
|
|
162
|
-
<button type="submit" class="ai-widget-send-button">→</button>
|
|
163
|
-
</form>
|
|
164
|
-
</div>
|
|
165
|
-
`);
|
|
166
|
-
|
|
167
|
-
this.$messages = this.$widget.find('.ai-widget-messages');
|
|
168
|
-
this.$input = this.$widget.find('.ai-widget-input');
|
|
169
|
-
|
|
170
|
-
// Event handlers
|
|
171
|
-
this.$button.on('click', () => this.open());
|
|
172
|
-
this.$widget.find('.ai-widget-close-button').on('click', () => this.close());
|
|
173
|
-
this.$widget.find('.ai-widget-form').on('submit', (e: any) => {
|
|
174
|
-
e.preventDefault();
|
|
175
|
-
this.sendMessage(this.$input.val());
|
|
176
|
-
this.$input.val('');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// Append to element
|
|
180
|
-
$(this.element).append(this.$button).append(this.$widget);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private open(): void {
|
|
184
|
-
this.isOpen = true;
|
|
185
|
-
(window as any).$(this.element)
|
|
186
|
-
.find('.ai-widget-button')
|
|
187
|
-
.hide();
|
|
188
|
-
(window as any).$(this.element)
|
|
189
|
-
.find('.ai-widget-window')
|
|
190
|
-
.show();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private close(): void {
|
|
194
|
-
this.isOpen = false;
|
|
195
|
-
(window as any).$(this.element)
|
|
196
|
-
.find('.ai-widget-button')
|
|
197
|
-
.show();
|
|
198
|
-
(window as any).$(this.element)
|
|
199
|
-
.find('.ai-widget-window')
|
|
200
|
-
.hide();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async sendMessage(message: string): Promise<void> {
|
|
204
|
-
if (!message.trim() || this.isLoading) return;
|
|
205
|
-
|
|
206
|
-
// Add user message
|
|
207
|
-
const userMsg = {
|
|
208
|
-
id: `${Date.now()}-${Math.random()}`,
|
|
209
|
-
role: 'user',
|
|
210
|
-
content: message,
|
|
211
|
-
timestamp: new Date(),
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
this.messages.push(userMsg);
|
|
215
|
-
this.appendMessageToUI(userMsg);
|
|
216
|
-
|
|
217
|
-
// Set loading
|
|
218
|
-
this.isLoadingState(true);
|
|
219
|
-
if (this.options.onLoading) {
|
|
220
|
-
this.options.onLoading(true);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
// Call backend
|
|
225
|
-
const response = await (window as any).fetch(
|
|
226
|
-
`${this.options.apiEndpoint}/api/aiorchestrator/query`,
|
|
227
|
-
{
|
|
228
|
-
method: 'POST',
|
|
229
|
-
headers: {
|
|
230
|
-
'Content-Type': 'application/json',
|
|
231
|
-
Authorization: `Bearer ${this.options.jwtToken || ''}`,
|
|
232
|
-
},
|
|
233
|
-
body: JSON.stringify({
|
|
234
|
-
userQuery: message,
|
|
235
|
-
pageType: this.options.context.pageType,
|
|
236
|
-
entityId: this.options.context.entityId,
|
|
237
|
-
contextData: this.options.context.customData,
|
|
238
|
-
}),
|
|
239
|
-
}
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
if (!response.ok) {
|
|
243
|
-
throw new Error(`HTTP ${response.status}`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const data = await response.json();
|
|
247
|
-
|
|
248
|
-
// Add assistant message
|
|
249
|
-
const assistantMsg = {
|
|
250
|
-
id: data.sessionId,
|
|
251
|
-
role: 'assistant',
|
|
252
|
-
content: data.response,
|
|
253
|
-
timestamp: new Date(data.timestamp),
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
this.messages.push(assistantMsg);
|
|
257
|
-
this.appendMessageToUI(assistantMsg);
|
|
258
|
-
|
|
259
|
-
if (this.options.onMessage) {
|
|
260
|
-
this.options.onMessage(assistantMsg);
|
|
261
|
-
}
|
|
262
|
-
} catch (error) {
|
|
263
|
-
const errorText = String(error);
|
|
264
|
-
if (this.options.onError) {
|
|
265
|
-
this.options.onError(errorText);
|
|
266
|
-
}
|
|
267
|
-
} finally {
|
|
268
|
-
this.isLoadingState(false);
|
|
269
|
-
if (this.options.onLoading) {
|
|
270
|
-
this.options.onLoading(false);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private appendMessageToUI(message: any): void {
|
|
276
|
-
const $ = (window as any).$;
|
|
277
|
-
const messageEl = $(`
|
|
278
|
-
<div class="ai-widget-message ai-widget-message-${message.role}">
|
|
279
|
-
<div class="ai-widget-message-content">${message.content}</div>
|
|
280
|
-
<div class="ai-widget-message-time">
|
|
281
|
-
${new Date(message.timestamp).toLocaleTimeString([], {
|
|
282
|
-
hour: '2-digit',
|
|
283
|
-
minute: '2-digit',
|
|
284
|
-
})}
|
|
285
|
-
</div>
|
|
286
|
-
</div>
|
|
287
|
-
`);
|
|
288
|
-
|
|
289
|
-
if (this.$messages.find('.ai-widget-welcome').length) {
|
|
290
|
-
this.$messages.find('.ai-widget-welcome').remove();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
this.$messages.append(messageEl);
|
|
294
|
-
this.$messages.scrollTop(this.$messages.prop('scrollHeight'));
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
getMessages(): any[] {
|
|
298
|
-
return [...this.messages];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
clearMessages(): void {
|
|
302
|
-
this.messages = [];
|
|
303
|
-
const $ = (window as any).$;
|
|
304
|
-
this.$messages.html(`
|
|
305
|
-
<div class="ai-widget-welcome">
|
|
306
|
-
<p>👋 Hello! I'm your AI assistant.</p>
|
|
307
|
-
<p>How can I help you today?</p>
|
|
308
|
-
</div>
|
|
309
|
-
`);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
updateContext(context: any): void {
|
|
313
|
-
this.options.context = { ...this.options.context, ...context };
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
isLoadingState(value?: boolean): boolean {
|
|
317
|
-
if (value !== undefined) {
|
|
318
|
-
this.isLoading = value;
|
|
319
|
-
}
|
|
320
|
-
return this.isLoading;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
destroy(): void {
|
|
324
|
-
this.$button.off('click');
|
|
325
|
-
this.$widget.find('.ai-widget-close-button').off('click');
|
|
326
|
-
this.$widget.find('.ai-widget-form').off('submit');
|
|
327
|
-
}
|
|
328
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2020", "DOM"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"rootDir": "./",
|
|
11
|
-
"strict": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"moduleResolution": "node"
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"*.ts"
|
|
20
|
-
],
|
|
21
|
-
"exclude": [
|
|
22
|
-
"node_modules",
|
|
23
|
-
"dist"
|
|
24
|
-
]
|
|
25
|
-
}
|