@blotoutio/providers-shop-gpt-sdk 1.4.0 → 1.6.0
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/index.cjs.js +426 -13
- package/index.js +426 -13
- package/index.mjs +426 -13
- package/package.json +1 -1
package/index.js
CHANGED
@@ -300,9 +300,73 @@ var ProvidersShopGptSdk = (function () {
|
|
300
300
|
['ZM', 'Zambia'],
|
301
301
|
['ZW', 'Zimbabwe'],
|
302
302
|
]);
|
303
|
-
|
303
|
+
/**
|
304
|
+
* ISO-3166 US state ISO codes
|
305
|
+
* @see https://en.wikipedia.org/wiki/ISO_3166-2:US
|
306
|
+
* */
|
307
|
+
const usStates = new Map([
|
308
|
+
['US-AL', 'Alabama'],
|
309
|
+
['US-AK', 'Alaska'],
|
310
|
+
['US-AZ', 'Arizona'],
|
311
|
+
['US-AR', 'Arkansas'],
|
312
|
+
['US-CA', 'California'],
|
313
|
+
['US-CO', 'Colorado'],
|
314
|
+
['US-CT', 'Connecticut'],
|
315
|
+
['US-DE', 'Delaware'],
|
316
|
+
['US-FL', 'Florida'],
|
317
|
+
['US-GA', 'Georgia'],
|
318
|
+
['US-HI', 'Hawaii'],
|
319
|
+
['US-ID', 'Idaho'],
|
320
|
+
['US-IL', 'Illinois'],
|
321
|
+
['US-IN', 'Indiana'],
|
322
|
+
['US-IA', 'Iowa'],
|
323
|
+
['US-KS', 'Kansas'],
|
324
|
+
['US-KY', 'Kentucky'],
|
325
|
+
['US-LA', 'Louisiana'],
|
326
|
+
['US-ME', 'Maine'],
|
327
|
+
['US-MD', 'Maryland'],
|
328
|
+
['US-MA', 'Massachusetts'],
|
329
|
+
['US-MI', 'Michigan'],
|
330
|
+
['US-MN', 'Minnesota'],
|
331
|
+
['US-MS', 'Mississippi'],
|
332
|
+
['US-MO', 'Missouri'],
|
333
|
+
['US-MT', 'Montana'],
|
334
|
+
['US-NE', 'Nebraska'],
|
335
|
+
['US-NV', 'Nevada'],
|
336
|
+
['US-NH', 'New Hampshire'],
|
337
|
+
['US-NJ', 'New Jersey'],
|
338
|
+
['US-NM', 'New Mexico'],
|
339
|
+
['US-NY', 'New York'],
|
340
|
+
['US-NC', 'North Carolina'],
|
341
|
+
['US-ND', 'North Dakota'],
|
342
|
+
['US-OH', 'Ohio'],
|
343
|
+
['US-OK', 'Oklahoma'],
|
344
|
+
['US-OR', 'Oregon'],
|
345
|
+
['US-PA', 'Pennsylvania'],
|
346
|
+
['US-RI', 'Rhode Island'],
|
347
|
+
['US-SC', 'South Carolina'],
|
348
|
+
['US-SD', 'South Dakota'],
|
349
|
+
['US-TN', 'Tennessee'],
|
350
|
+
['US-TX', 'Texas'],
|
351
|
+
['US-UT', 'Utah'],
|
352
|
+
['US-VT', 'Vermont'],
|
353
|
+
['US-VA', 'Virginia'],
|
354
|
+
['US-WA', 'Washington'],
|
355
|
+
['US-WV', 'West Virginia'],
|
356
|
+
['US-WI', 'Wisconsin'],
|
357
|
+
['US-WY', 'Wyoming'],
|
358
|
+
['US-DC', 'District of Columbia'],
|
359
|
+
['US-AS', 'American Samoa'],
|
360
|
+
['US-GU', 'Guam'],
|
361
|
+
['US-MP', 'Northern Mariana Islands'],
|
362
|
+
['US-PR', 'Puerto Rico'],
|
363
|
+
['US-UM', 'United States Minor Outlying Islands'],
|
364
|
+
['US-VI', 'Virgin Islands, U.S.'],
|
365
|
+
]);
|
366
|
+
new Set([...isoCountries.keys(), ...usStates.keys()]);
|
304
367
|
|
305
368
|
const packageName = 'shopGPT';
|
369
|
+
const DEFAULT_MAX_THREAD_AGE = 14;
|
306
370
|
const previewKeyName = 'previewShopGPT';
|
307
371
|
|
308
372
|
const canLog = () => {
|
@@ -382,6 +446,7 @@ var ProvidersShopGptSdk = (function () {
|
|
382
446
|
}
|
383
447
|
const data = (await response.json());
|
384
448
|
return {
|
449
|
+
messageId: data.messageId,
|
385
450
|
message: data.message,
|
386
451
|
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
387
452
|
chatTitle: data.chatTitle,
|
@@ -452,6 +517,20 @@ var ProvidersShopGptSdk = (function () {
|
|
452
517
|
throw new Error(`Failed to delete all chat threads - ${response.status}: ${await response.text()}`);
|
453
518
|
}
|
454
519
|
};
|
520
|
+
const saveFeedback = async (messageId, feedback) => {
|
521
|
+
const response = await fetchImpl(getURL('/feedback'), {
|
522
|
+
method: 'POST',
|
523
|
+
headers: getHeaders(),
|
524
|
+
credentials: 'include',
|
525
|
+
body: JSON.stringify({
|
526
|
+
messageId,
|
527
|
+
feedback,
|
528
|
+
}),
|
529
|
+
});
|
530
|
+
if (!response.ok) {
|
531
|
+
throw new Error(`Failed to save feedback - ${response.status}: ${await response.text()}`);
|
532
|
+
}
|
533
|
+
};
|
455
534
|
return {
|
456
535
|
processQuery,
|
457
536
|
fetchChatHistory,
|
@@ -459,6 +538,7 @@ var ProvidersShopGptSdk = (function () {
|
|
459
538
|
createChatThread,
|
460
539
|
deleteSingleThread,
|
461
540
|
deleteAllThreads,
|
541
|
+
saveFeedback,
|
462
542
|
};
|
463
543
|
};
|
464
544
|
|
@@ -492,7 +572,7 @@ var ProvidersShopGptSdk = (function () {
|
|
492
572
|
// exit if not in top window
|
493
573
|
return;
|
494
574
|
}
|
495
|
-
const { enabled, devMode, merchantUrl, profiles, productHandles, targetPath, uiMode, brandName, quickPrompts, merchantImage, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
575
|
+
const { enabled, devMode, merchantUrl, profiles, productHandles, targetPath, uiMode, brandName, quickPrompts, merchantImage, latestThreadLoad, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
496
576
|
let shouldShowUI = enabled;
|
497
577
|
if (!enabled && hasPreviewKey()) {
|
498
578
|
logger.log('Enabling UI in preview mode');
|
@@ -521,6 +601,7 @@ var ProvidersShopGptSdk = (function () {
|
|
521
601
|
brandName,
|
522
602
|
quickPrompts,
|
523
603
|
merchantImage,
|
604
|
+
latestThreadLoad: latestThreadLoad !== null && latestThreadLoad !== void 0 ? latestThreadLoad : DEFAULT_MAX_THREAD_AGE,
|
524
605
|
});
|
525
606
|
}
|
526
607
|
};
|
@@ -1582,14 +1663,18 @@ var ProvidersShopGptSdk = (function () {
|
|
1582
1663
|
super(...arguments);
|
1583
1664
|
this.showButtons = true;
|
1584
1665
|
this.updateButtonsState = () => {
|
1585
|
-
if (!this.
|
1666
|
+
if (!this.productsEle) {
|
1586
1667
|
return;
|
1587
1668
|
}
|
1588
1669
|
const { scrollWidth, clientWidth } = this.productsEle;
|
1589
1670
|
this.showButtons = scrollWidth > clientWidth;
|
1590
|
-
this.leftBtnEle
|
1671
|
+
if (this.leftBtnEle) {
|
1672
|
+
this.leftBtnEle.classList.toggle('disabled', this.productsEle.scrollLeft === 0);
|
1673
|
+
}
|
1591
1674
|
const maxScroll = this.productsEle.scrollWidth - this.productsEle.clientWidth;
|
1592
|
-
this.rightBtnEle
|
1675
|
+
if (this.rightBtnEle) {
|
1676
|
+
this.rightBtnEle.classList.toggle('disabled', this.productsEle.scrollLeft >= maxScroll - 1);
|
1677
|
+
}
|
1593
1678
|
};
|
1594
1679
|
}
|
1595
1680
|
connectedCallback() {
|
@@ -1997,6 +2082,26 @@ var ProvidersShopGptSdk = (function () {
|
|
1997
2082
|
}
|
1998
2083
|
}
|
1999
2084
|
|
2085
|
+
.bot-response-actions {
|
2086
|
+
display: flex;
|
2087
|
+
margin-left: 12px;
|
2088
|
+
margin-top: -10px;
|
2089
|
+
|
2090
|
+
button {
|
2091
|
+
display: flex;
|
2092
|
+
align-items: center;
|
2093
|
+
justify-content: center;
|
2094
|
+
padding: 8px;
|
2095
|
+
background: none;
|
2096
|
+
color: rgb(140, 137, 156);
|
2097
|
+
border-radius: 50%;
|
2098
|
+
|
2099
|
+
&:hover {
|
2100
|
+
background-color: rgba(47, 43, 61, 0.08);
|
2101
|
+
}
|
2102
|
+
}
|
2103
|
+
}
|
2104
|
+
|
2000
2105
|
.bot-icon {
|
2001
2106
|
display: flex;
|
2002
2107
|
padding: 8px 11px;
|
@@ -2256,6 +2361,18 @@ var ProvidersShopGptSdk = (function () {
|
|
2256
2361
|
const crossBtn = b `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
2257
2362
|
<path d="M18 7.05L16.95 6L12 10.95L7.05 6L6 7.05L10.95 12L6 16.95L7.05 18L12 13.05L16.95 18L18 16.95L13.05 12L18 7.05Z" fill="white"/>
|
2258
2363
|
</svg>`;
|
2364
|
+
const thumbsUpBtn = b `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--tabler" font-size="1.375rem" width="1em" height="1em" viewBox="0 0 24 24">
|
2365
|
+
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 11v8a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3a4 4 0 0 0 4-4V6a2 2 0 0 1 4 0v5h3a2 2 0 0 1 2 2l-1 5a2 3 0 0 1-2 2h-7a3 3 0 0 1-3-3"></path>
|
2366
|
+
</svg>`;
|
2367
|
+
const thumbsUpFilledBtn = b `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--tabler" font-size="1.375rem" width="1em" height="1em" viewBox="0 0 24 24">
|
2368
|
+
<path fill="currentColor" d="M13 3a3 3 0 0 1 2.995 2.824L16 6v4h2a3 3 0 0 1 2.98 2.65l.015.174L21 13l-.02.196l-1.006 5.032c-.381 1.626-1.502 2.796-2.81 2.78L17 21H9a1 1 0 0 1-.993-.883L8 20l.001-9.536a1 1 0 0 1 .5-.865a3 3 0 0 0 1.492-2.397L10 7V6a3 3 0 0 1 3-3m-8 7a1 1 0 0 1 .993.883L6 11v9a1 1 0 0 1-.883.993L5 21H4a2 2 0 0 1-1.995-1.85L2 19v-7a2 2 0 0 1 1.85-1.995L4 10z"></path>
|
2369
|
+
</svg>`;
|
2370
|
+
const thumbsDownBtn = b `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--tabler" font-size="1.375rem" width="1em" height="1em" viewBox="0 0 24 24">
|
2371
|
+
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 13V5a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h3a4 4 0 0 1 4 4v1a2 2 0 0 0 4 0v-5h3a2 2 0 0 0 2-2l-1-5a2 3 0 0 0-2-2h-7a3 3 0 0 0-3 3"></path>
|
2372
|
+
</svg>`;
|
2373
|
+
const thumbsDownFilledBtn = b `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--tabler" font-size="1.375rem" width="1em" height="1em" viewBox="0 0 24 24">
|
2374
|
+
<path fill="currentColor" d="M13 21.008a3 3 0 0 0 2.995-2.823l.005-.177v-4h2a3 3 0 0 0 2.98-2.65l.015-.173l.005-.177l-.02-.196l-1.006-5.032c-.381-1.625-1.502-2.796-2.81-2.78L17 3.008H9a1 1 0 0 0-.993.884L8 4.008l.001 9.536a1 1 0 0 0 .5.866a3 3 0 0 1 1.492 2.396l.007.202v1a3 3 0 0 0 3 3m-8-7a1 1 0 0 0 .993-.883L6 13.008v-9a1 1 0 0 0-.883-.993L5 3.008H4A2 2 0 0 0 2.005 4.86L2 5.01v7a2 2 0 0 0 1.85 1.994l.15.005h1z"></path>
|
2375
|
+
</svg>`;
|
2259
2376
|
|
2260
2377
|
const personalizeDialogStyles = i$4 `
|
2261
2378
|
:host {
|
@@ -3159,6 +3276,212 @@ var ProvidersShopGptSdk = (function () {
|
|
3159
3276
|
customElements.define('confirm-dialog', ConfirmDialog);
|
3160
3277
|
}
|
3161
3278
|
|
3279
|
+
const feedbackDialogStyles = i$4 `
|
3280
|
+
:host {
|
3281
|
+
font-family: 'Inter', sans-serif;
|
3282
|
+
font-size: 16px;
|
3283
|
+
line-height: 24px;
|
3284
|
+
font-weight: 400;
|
3285
|
+
|
3286
|
+
display: flex;
|
3287
|
+
position: absolute;
|
3288
|
+
top: 0;
|
3289
|
+
left: 0;
|
3290
|
+
width: 100%;
|
3291
|
+
height: 100%;
|
3292
|
+
background: #00000050;
|
3293
|
+
}
|
3294
|
+
|
3295
|
+
.modal {
|
3296
|
+
width: 75%;
|
3297
|
+
max-width: 400px;
|
3298
|
+
background: #fff;
|
3299
|
+
padding: 24px;
|
3300
|
+
margin: auto;
|
3301
|
+
|
3302
|
+
border-radius: 8px;
|
3303
|
+
box-shadow: rgba(47, 43, 61, 0.28) 0px 8px 23px 0px;
|
3304
|
+
|
3305
|
+
z-index: 2000;
|
3306
|
+
}
|
3307
|
+
|
3308
|
+
.header {
|
3309
|
+
display: flex;
|
3310
|
+
justify-content: space-between;
|
3311
|
+
align-items: center;
|
3312
|
+
margin-bottom: 16px;
|
3313
|
+
}
|
3314
|
+
|
3315
|
+
.close {
|
3316
|
+
display: flex;
|
3317
|
+
justify-content: center;
|
3318
|
+
align-items: center;
|
3319
|
+
cursor: pointer;
|
3320
|
+
}
|
3321
|
+
|
3322
|
+
h3 {
|
3323
|
+
margin: 0;
|
3324
|
+
font-size: 20px;
|
3325
|
+
font-weight: 700;
|
3326
|
+
color: #172a41;
|
3327
|
+
line-height: 24px;
|
3328
|
+
}
|
3329
|
+
|
3330
|
+
form {
|
3331
|
+
display: flex;
|
3332
|
+
flex-direction: column;
|
3333
|
+
gap: 12px;
|
3334
|
+
margin: 0;
|
3335
|
+
}
|
3336
|
+
|
3337
|
+
textarea {
|
3338
|
+
padding: 16px;
|
3339
|
+
border: 1px solid #2f2b3d28;
|
3340
|
+
border-radius: 10px;
|
3341
|
+
font-size: 16px;
|
3342
|
+
resize: none;
|
3343
|
+
min-height: 104px;
|
3344
|
+
box-sizing: border-box;
|
3345
|
+
font-family: inherit;
|
3346
|
+
color: #4e647f;
|
3347
|
+
font-weight: 500;
|
3348
|
+
line-height: 24px;
|
3349
|
+
|
3350
|
+
&:focus {
|
3351
|
+
outline: none;
|
3352
|
+
box-shadow: rgba(57, 123, 244, 0.5) 0px 0px 4px;
|
3353
|
+
}
|
3354
|
+
|
3355
|
+
&::placeholder {
|
3356
|
+
font-style: italic;
|
3357
|
+
color: #8799af80;
|
3358
|
+
}
|
3359
|
+
}
|
3360
|
+
|
3361
|
+
.btns-container {
|
3362
|
+
display: flex;
|
3363
|
+
gap: 0 8px;
|
3364
|
+
margin-left: auto;
|
3365
|
+
margin-top: 10px;
|
3366
|
+
}
|
3367
|
+
|
3368
|
+
button {
|
3369
|
+
padding: 9px 20px;
|
3370
|
+
border: none;
|
3371
|
+
border-radius: 5px;
|
3372
|
+
cursor: pointer;
|
3373
|
+
}
|
3374
|
+
|
3375
|
+
.btn-skip {
|
3376
|
+
background-color: #dbe2eb;
|
3377
|
+
color: #172a41;
|
3378
|
+
font-weight: 500;
|
3379
|
+
|
3380
|
+
&:hover {
|
3381
|
+
background-color: rgb(219, 226, 235);
|
3382
|
+
}
|
3383
|
+
}
|
3384
|
+
|
3385
|
+
.btn-submit-feedback {
|
3386
|
+
background-color: rgb(23, 42, 65);
|
3387
|
+
color: #ffffff;
|
3388
|
+
font-weight: 500;
|
3389
|
+
|
3390
|
+
&:hover {
|
3391
|
+
background-color: rgb(9, 22, 39);
|
3392
|
+
}
|
3393
|
+
|
3394
|
+
&:disabled {
|
3395
|
+
background-color: #e0e0e0;
|
3396
|
+
cursor: not-allowed;
|
3397
|
+
}
|
3398
|
+
}
|
3399
|
+
`;
|
3400
|
+
|
3401
|
+
class FeedbackDialog extends r$2 {
|
3402
|
+
dispatchFeedbackEvent(feedback) {
|
3403
|
+
this.dispatchEvent(new CustomEvent('submit-feedback', {
|
3404
|
+
detail: {
|
3405
|
+
messageId: this.messageId,
|
3406
|
+
feedback,
|
3407
|
+
},
|
3408
|
+
composed: true,
|
3409
|
+
bubbles: true,
|
3410
|
+
}));
|
3411
|
+
}
|
3412
|
+
handleSubmit(e) {
|
3413
|
+
var _a;
|
3414
|
+
e.preventDefault();
|
3415
|
+
const form = e.target;
|
3416
|
+
const data = new FormData(form);
|
3417
|
+
this.dispatchFeedbackEvent({
|
3418
|
+
rating: 'bad',
|
3419
|
+
comment: (_a = data.get('comment')) === null || _a === void 0 ? void 0 : _a.toString().trim(),
|
3420
|
+
});
|
3421
|
+
form.reset();
|
3422
|
+
}
|
3423
|
+
handleSkipComment(e) {
|
3424
|
+
e.preventDefault();
|
3425
|
+
this.comment = '';
|
3426
|
+
this.dispatchFeedbackEvent({ rating: 'bad', comment: null });
|
3427
|
+
}
|
3428
|
+
close(e) {
|
3429
|
+
e.preventDefault();
|
3430
|
+
this.dispatchEvent(new CustomEvent('close', {
|
3431
|
+
composed: true,
|
3432
|
+
bubbles: true,
|
3433
|
+
}));
|
3434
|
+
}
|
3435
|
+
render() {
|
3436
|
+
return x `
|
3437
|
+
<div class="modal">
|
3438
|
+
<div class="header">
|
3439
|
+
<h3>Provide Additional Feedback</h3>
|
3440
|
+
<div class="close" @click=${this.close}>${closeBtn}</div>
|
3441
|
+
</div>
|
3442
|
+
<form @submit=${this.handleSubmit}>
|
3443
|
+
<textarea
|
3444
|
+
name="comment"
|
3445
|
+
@input=${(e) => { var _a; return (this.comment = (_a = e.target) === null || _a === void 0 ? void 0 : _a.value); }}
|
3446
|
+
placeholder="Share your feedback"
|
3447
|
+
required
|
3448
|
+
>
|
3449
|
+
${this.comment ? this.comment : E}</textarea
|
3450
|
+
>
|
3451
|
+
<div class="btns-container">
|
3452
|
+
<button
|
3453
|
+
type="button"
|
3454
|
+
class="btn btn-skip"
|
3455
|
+
@click=${this.handleSkipComment}
|
3456
|
+
>
|
3457
|
+
Skip
|
3458
|
+
</button>
|
3459
|
+
<button
|
3460
|
+
type="submit"
|
3461
|
+
class="btn btn-submit-feedback"
|
3462
|
+
?disabled=${!this.comment}
|
3463
|
+
>
|
3464
|
+
Submit
|
3465
|
+
</button>
|
3466
|
+
</div>
|
3467
|
+
</form>
|
3468
|
+
</div>
|
3469
|
+
`;
|
3470
|
+
}
|
3471
|
+
}
|
3472
|
+
FeedbackDialog.styles = [feedbackDialogStyles];
|
3473
|
+
__decorate([
|
3474
|
+
n({ type: String }),
|
3475
|
+
__metadata("design:type", Object)
|
3476
|
+
], FeedbackDialog.prototype, "messageId", void 0);
|
3477
|
+
__decorate([
|
3478
|
+
n({ type: String }),
|
3479
|
+
__metadata("design:type", Object)
|
3480
|
+
], FeedbackDialog.prototype, "comment", void 0);
|
3481
|
+
if (!customElements.get('feedback-dialog')) {
|
3482
|
+
customElements.define('feedback-dialog', FeedbackDialog);
|
3483
|
+
}
|
3484
|
+
|
3162
3485
|
class ChatSection extends r$2 {
|
3163
3486
|
constructor() {
|
3164
3487
|
super(...arguments);
|
@@ -3206,6 +3529,23 @@ var ProvidersShopGptSdk = (function () {
|
|
3206
3529
|
}));
|
3207
3530
|
this.deleteThreadId = '';
|
3208
3531
|
}
|
3532
|
+
handleFeedback(rating, messageId, comment) {
|
3533
|
+
if (rating === 'bad') {
|
3534
|
+
this.feedbackDetails = { messageId, comment };
|
3535
|
+
return;
|
3536
|
+
}
|
3537
|
+
this.dispatchEvent(new CustomEvent('submit-feedback', {
|
3538
|
+
detail: {
|
3539
|
+
messageId: messageId,
|
3540
|
+
feedback: {
|
3541
|
+
rating,
|
3542
|
+
comment: null,
|
3543
|
+
},
|
3544
|
+
},
|
3545
|
+
composed: true,
|
3546
|
+
bubbles: true,
|
3547
|
+
}));
|
3548
|
+
}
|
3209
3549
|
typingIndicator() {
|
3210
3550
|
return x ` <div class="typing-dots">
|
3211
3551
|
<div class="dot"></div>
|
@@ -3214,7 +3554,7 @@ var ProvidersShopGptSdk = (function () {
|
|
3214
3554
|
</div>`;
|
3215
3555
|
}
|
3216
3556
|
botMessage(message) {
|
3217
|
-
var _a;
|
3557
|
+
var _a, _b, _c, _d, _e;
|
3218
3558
|
return x `
|
3219
3559
|
<div class="message-wrapper">
|
3220
3560
|
<div class="message bot">
|
@@ -3245,6 +3585,26 @@ var ProvidersShopGptSdk = (function () {
|
|
3245
3585
|
.viewType=${this.viewType}
|
3246
3586
|
></products-list>`
|
3247
3587
|
: E}
|
3588
|
+
${message.messageId
|
3589
|
+
? x `<div class="bot-response-actions">
|
3590
|
+
<button
|
3591
|
+
type="button"
|
3592
|
+
@click=${this.handleFeedback.bind(this, 'good', message.messageId, (_b = message.feedback) === null || _b === void 0 ? void 0 : _b.comment)}
|
3593
|
+
>
|
3594
|
+
${((_c = message.feedback) === null || _c === void 0 ? void 0 : _c.rating) === 'good'
|
3595
|
+
? thumbsUpFilledBtn
|
3596
|
+
: thumbsUpBtn}
|
3597
|
+
</button>
|
3598
|
+
<button
|
3599
|
+
type="button"
|
3600
|
+
@click=${this.handleFeedback.bind(this, 'bad', message.messageId, (_d = message.feedback) === null || _d === void 0 ? void 0 : _d.comment)}
|
3601
|
+
>
|
3602
|
+
${((_e = message.feedback) === null || _e === void 0 ? void 0 : _e.rating) === 'bad'
|
3603
|
+
? thumbsDownFilledBtn
|
3604
|
+
: thumbsDownBtn}
|
3605
|
+
</button>
|
3606
|
+
</div>`
|
3607
|
+
: E}
|
3248
3608
|
</div>
|
3249
3609
|
`;
|
3250
3610
|
}
|
@@ -3265,10 +3625,19 @@ var ProvidersShopGptSdk = (function () {
|
|
3265
3625
|
</div>`
|
3266
3626
|
: ''}
|
3267
3627
|
${this.isFailed
|
3268
|
-
?
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3628
|
+
? x `<div class="message bot">
|
3629
|
+
<div>
|
3630
|
+
<div class="bot-icon">${botIcon}</div>
|
3631
|
+
</div>
|
3632
|
+
<div>
|
3633
|
+
<p>
|
3634
|
+
Uh-oh! Looks like I tripped over some alpha-stage wires.
|
3635
|
+
Things are still a bit wobbly here, buy hey, that's what
|
3636
|
+
testing is for, Let's try that again; or feel free to throw
|
3637
|
+
another challenge my way!
|
3638
|
+
</p>
|
3639
|
+
</div>
|
3640
|
+
</div>`
|
3272
3641
|
: E}
|
3273
3642
|
${this.messages.map((message) => {
|
3274
3643
|
if (message.sender === 'bot') {
|
@@ -3300,7 +3669,7 @@ var ProvidersShopGptSdk = (function () {
|
|
3300
3669
|
? this.messages[0].welcomePrompts
|
3301
3670
|
: this.prompts
|
3302
3671
|
? this.prompts.split(',').map((prompt) => prompt.trim())
|
3303
|
-
: ['Best
|
3672
|
+
: ['Best Sellers'];
|
3304
3673
|
if (!prompts) {
|
3305
3674
|
return E;
|
3306
3675
|
}
|
@@ -3612,6 +3981,21 @@ var ProvidersShopGptSdk = (function () {
|
|
3612
3981
|
</confirm-dialog>
|
3613
3982
|
`
|
3614
3983
|
: E}
|
3984
|
+
${this.feedbackDetails
|
3985
|
+
? x `
|
3986
|
+
<feedback-dialog
|
3987
|
+
.messageId=${this.feedbackDetails.messageId}
|
3988
|
+
.comment=${this.feedbackDetails.comment}
|
3989
|
+
@submit-feedback=${() => {
|
3990
|
+
this.feedbackDetails = undefined;
|
3991
|
+
}}
|
3992
|
+
@close=${(e) => {
|
3993
|
+
e.stopPropagation();
|
3994
|
+
this.feedbackDetails = undefined;
|
3995
|
+
}}
|
3996
|
+
></feedback-dialog>
|
3997
|
+
`
|
3998
|
+
: E}
|
3615
3999
|
`;
|
3616
4000
|
}
|
3617
4001
|
}
|
@@ -3696,6 +4080,10 @@ var ProvidersShopGptSdk = (function () {
|
|
3696
4080
|
e$3('personalize-dialog'),
|
3697
4081
|
__metadata("design:type", Object)
|
3698
4082
|
], ChatSection.prototype, "personalizeDialogElement", void 0);
|
4083
|
+
__decorate([
|
4084
|
+
r(),
|
4085
|
+
__metadata("design:type", Object)
|
4086
|
+
], ChatSection.prototype, "feedbackDetails", void 0);
|
3699
4087
|
__decorate([
|
3700
4088
|
n({ type: String }),
|
3701
4089
|
__metadata("design:type", Object)
|
@@ -3705,11 +4093,11 @@ var ProvidersShopGptSdk = (function () {
|
|
3705
4093
|
}
|
3706
4094
|
|
3707
4095
|
const DIALOG_DELAY = 1000;
|
3708
|
-
const LATEST_THREAD_LOAD_DAYS = 14;
|
3709
4096
|
const normalizePath = (path) => path.replace(/\/$/, '');
|
3710
4097
|
class ShopGPT extends r$2 {
|
3711
4098
|
constructor() {
|
3712
4099
|
super(...arguments);
|
4100
|
+
this.latestThreadLoad = DEFAULT_MAX_THREAD_AGE;
|
3713
4101
|
this.modalState = 'close';
|
3714
4102
|
this.isLoadingHistory = false;
|
3715
4103
|
this.isLoadingThreads = false;
|
@@ -3816,6 +4204,7 @@ var ProvidersShopGptSdk = (function () {
|
|
3816
4204
|
}
|
3817
4205
|
this.messages = [
|
3818
4206
|
{
|
4207
|
+
messageId: reply.messageId,
|
3819
4208
|
sender: 'bot',
|
3820
4209
|
message: reply.message,
|
3821
4210
|
products: reply.products,
|
@@ -3847,7 +4236,7 @@ var ProvidersShopGptSdk = (function () {
|
|
3847
4236
|
}
|
3848
4237
|
}
|
3849
4238
|
selectLatestThread() {
|
3850
|
-
const cutoffTime = Date.now() -
|
4239
|
+
const cutoffTime = Date.now() - this.latestThreadLoad * 24 * 60 * 60 * 1000;
|
3851
4240
|
// If the latest thread is not older than cutoff we should load the thread
|
3852
4241
|
let latestThread;
|
3853
4242
|
for (const thread of this.chatThreads.values()) {
|
@@ -3883,10 +4272,12 @@ var ProvidersShopGptSdk = (function () {
|
|
3883
4272
|
latestAvailableProducts = products;
|
3884
4273
|
}
|
3885
4274
|
return {
|
4275
|
+
messageId: message.messageId,
|
3886
4276
|
message: message.message,
|
3887
4277
|
sender: message.sender,
|
3888
4278
|
products,
|
3889
4279
|
welcomePrompts: message.welcomePrompts,
|
4280
|
+
feedback: message.feedback,
|
3890
4281
|
};
|
3891
4282
|
});
|
3892
4283
|
this.products = latestAvailableProducts;
|
@@ -3967,6 +4358,7 @@ var ProvidersShopGptSdk = (function () {
|
|
3967
4358
|
}
|
3968
4359
|
this.messages = [
|
3969
4360
|
{
|
4361
|
+
messageId: reply.messageId,
|
3970
4362
|
sender: 'bot',
|
3971
4363
|
message: reply.message,
|
3972
4364
|
products: reply.products,
|
@@ -3986,6 +4378,20 @@ var ProvidersShopGptSdk = (function () {
|
|
3986
4378
|
this.isTyping = false;
|
3987
4379
|
}
|
3988
4380
|
}
|
4381
|
+
submitFeedback(e) {
|
4382
|
+
e.stopPropagation();
|
4383
|
+
this.shopGPTAPI
|
4384
|
+
.saveFeedback(e.detail.messageId, e.detail.feedback)
|
4385
|
+
.then(() => {
|
4386
|
+
const messages = this.messages;
|
4387
|
+
const messageIndex = messages.findIndex(({ messageId }) => messageId === e.detail.messageId);
|
4388
|
+
messages[messageIndex] = {
|
4389
|
+
...messages[messageIndex],
|
4390
|
+
feedback: e.detail.feedback,
|
4391
|
+
};
|
4392
|
+
this.messages = [...messages];
|
4393
|
+
});
|
4394
|
+
}
|
3989
4395
|
getSiteCurrency() {
|
3990
4396
|
return this.storeAPI.getSiteCurrency();
|
3991
4397
|
}
|
@@ -4002,6 +4408,7 @@ var ProvidersShopGptSdk = (function () {
|
|
4002
4408
|
id="shop-gpt-dialog-overlay"
|
4003
4409
|
@delete-thread=${this.handleThreadDelete}
|
4004
4410
|
@delete-all-threads=${this.handleAllThreadsDelete}
|
4411
|
+
@submit-feedback=${this.submitFeedback}
|
4005
4412
|
>
|
4006
4413
|
<div class="mobile-version">
|
4007
4414
|
Please switch to the desktop version for the best experience.
|
@@ -4066,6 +4473,7 @@ var ProvidersShopGptSdk = (function () {
|
|
4066
4473
|
id="shop-gpt-modal"
|
4067
4474
|
@delete-thread=${this.handleThreadDelete}
|
4068
4475
|
@delete-all-threads=${this.handleAllThreadsDelete}
|
4476
|
+
@submit-feedback=${this.submitFeedback}
|
4069
4477
|
>
|
4070
4478
|
<chat-section
|
4071
4479
|
.prompts=${this.quickPrompts}
|
@@ -4093,6 +4501,10 @@ var ProvidersShopGptSdk = (function () {
|
|
4093
4501
|
}
|
4094
4502
|
}
|
4095
4503
|
ShopGPT.styles = [shopGPTStyles];
|
4504
|
+
__decorate([
|
4505
|
+
n({ type: Number }),
|
4506
|
+
__metadata("design:type", Number)
|
4507
|
+
], ShopGPT.prototype, "latestThreadLoad", void 0);
|
4096
4508
|
__decorate([
|
4097
4509
|
e$3('#shop-gpt-dialog-overlay'),
|
4098
4510
|
__metadata("design:type", Object)
|
@@ -4159,6 +4571,7 @@ var ProvidersShopGptSdk = (function () {
|
|
4159
4571
|
shopGPT.brandName = params.brandName;
|
4160
4572
|
shopGPT.quickPrompts = params.quickPrompts;
|
4161
4573
|
shopGPT.merchantImage = params.merchantImage;
|
4574
|
+
shopGPT.latestThreadLoad = params.latestThreadLoad;
|
4162
4575
|
document.body.append(shopGPT);
|
4163
4576
|
},
|
4164
4577
|
destroy() {
|