@blotoutio/providers-shop-gpt-sdk 1.10.2 → 1.11.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 +152 -39
- package/index.js +152 -39
- package/index.mjs +152 -39
- package/package.json +1 -1
package/index.js
CHANGED
@@ -409,13 +409,24 @@ var ProvidersShopGptSdk = (function () {
|
|
409
409
|
}
|
410
410
|
};
|
411
411
|
|
412
|
+
/** Action length should not exceed 42 */
|
412
413
|
const uiActions = new Set([
|
413
414
|
'shopGPTInitialized',
|
414
415
|
'chatbotOpened',
|
416
|
+
'chatbotClosed',
|
417
|
+
'singleThreadDelete',
|
418
|
+
'allThreadsDelete',
|
419
|
+
'switchThread',
|
420
|
+
'newSearch',
|
421
|
+
'thumbsUp',
|
422
|
+
'thumbsDown',
|
423
|
+
'showThreads',
|
415
424
|
'queryInteractions',
|
416
425
|
'promptClicked',
|
417
426
|
'productRecommendationClicked',
|
427
|
+
'blotoutLinkClicked',
|
418
428
|
]);
|
429
|
+
/** Action length should not exceed 42 */
|
419
430
|
new Set([
|
420
431
|
...uiActions,
|
421
432
|
'pageView',
|
@@ -768,10 +779,11 @@ var ProvidersShopGptSdk = (function () {
|
|
768
779
|
const data = (await response.json());
|
769
780
|
return data.customPrompts;
|
770
781
|
};
|
771
|
-
const sendEvent =
|
782
|
+
const sendEvent = (action, currency, actionData) => {
|
772
783
|
var _a;
|
773
784
|
const storageData = (_a = getProductActions(baseURL, sessionId)) !== null && _a !== void 0 ? _a : {};
|
774
|
-
|
785
|
+
// This endpoint sends user events to the server, we don't need to wait for the response
|
786
|
+
fetchImpl(getURL('/user/event'), {
|
775
787
|
method: 'POST',
|
776
788
|
headers: getHeaders(true),
|
777
789
|
body: JSON.stringify({
|
@@ -785,10 +797,13 @@ var ProvidersShopGptSdk = (function () {
|
|
785
797
|
},
|
786
798
|
}),
|
787
799
|
credentials: 'include',
|
788
|
-
})
|
789
|
-
|
790
|
-
|
791
|
-
|
800
|
+
})
|
801
|
+
.then(async (response) => {
|
802
|
+
if (!response.ok) {
|
803
|
+
throw new Error(`Error while recording user event - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
|
804
|
+
}
|
805
|
+
})
|
806
|
+
.catch(logger.error);
|
792
807
|
};
|
793
808
|
return {
|
794
809
|
processQuery,
|
@@ -824,8 +839,8 @@ var ProvidersShopGptSdk = (function () {
|
|
824
839
|
// exit if not in top window
|
825
840
|
return;
|
826
841
|
}
|
827
|
-
const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, botIconUrl, css, nudge,
|
828
|
-
setShopGPTLoaded(params.baseUrl, (_d = params.session) === null || _d === void 0 ? void 0 : _d.sessionId, !
|
842
|
+
const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, botIconUrl, css, nudge, loadUIManually, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
843
|
+
setShopGPTLoaded(params.baseUrl, (_d = params.session) === null || _d === void 0 ? void 0 : _d.sessionId, !loadUIManually);
|
829
844
|
const experiment = createExperiment({
|
830
845
|
name: getExperimentName(mode),
|
831
846
|
userId: params.userId,
|
@@ -865,8 +880,9 @@ var ProvidersShopGptSdk = (function () {
|
|
865
880
|
css,
|
866
881
|
nudge,
|
867
882
|
sessionId: (_f = params.session) === null || _f === void 0 ? void 0 : _f.sessionId,
|
883
|
+
loadUIManually,
|
868
884
|
});
|
869
|
-
if (!
|
885
|
+
if (!loadUIManually) {
|
870
886
|
uiImplementation.loadUI();
|
871
887
|
}
|
872
888
|
}
|
@@ -1089,6 +1105,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1089
1105
|
height: 56px;
|
1090
1106
|
background-color: var(--shopgpt-primary);
|
1091
1107
|
border-radius: 50%;
|
1108
|
+
display: flex;
|
1092
1109
|
justify-content: center;
|
1093
1110
|
align-items: center;
|
1094
1111
|
box-shadow: 0 0 4px 1px var(--shopgpt-white);
|
@@ -1521,6 +1538,13 @@ var ProvidersShopGptSdk = (function () {
|
|
1521
1538
|
}
|
1522
1539
|
return `https://${this.merchantUrl}`;
|
1523
1540
|
}
|
1541
|
+
sendEvent(action, actionData) {
|
1542
|
+
this.dispatchEvent(new CustomEvent('send-event', {
|
1543
|
+
detail: { action, actionData },
|
1544
|
+
composed: true,
|
1545
|
+
bubbles: true,
|
1546
|
+
}));
|
1547
|
+
}
|
1524
1548
|
handleThreadDelete() {
|
1525
1549
|
if (this.deleteAllThreads) {
|
1526
1550
|
this.dispatchEvent(new CustomEvent('delete-all-threads', {
|
@@ -1555,7 +1579,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1555
1579
|
? x `<div
|
1556
1580
|
class="trash-icon"
|
1557
1581
|
@click=${() => {
|
1558
|
-
if (this.isLoading || this.
|
1582
|
+
if (this.isLoading || this.isStreaming) {
|
1559
1583
|
return;
|
1560
1584
|
}
|
1561
1585
|
this.deleteAllThreads = true;
|
@@ -1572,13 +1596,15 @@ var ProvidersShopGptSdk = (function () {
|
|
1572
1596
|
class=${e$1({
|
1573
1597
|
'thread-wrapper': true,
|
1574
1598
|
active: this.selectedThreadId === thread.threadId,
|
1575
|
-
disabled: this.
|
1599
|
+
disabled: this.isStreaming,
|
1576
1600
|
})}
|
1577
1601
|
>
|
1578
1602
|
<div
|
1579
1603
|
class="thread-title"
|
1580
1604
|
@click=${async () => {
|
1581
|
-
if (this.isLoading ||
|
1605
|
+
if (this.isLoading ||
|
1606
|
+
this.isStreaming ||
|
1607
|
+
this.selectedThreadId === thread.threadId) {
|
1582
1608
|
return;
|
1583
1609
|
}
|
1584
1610
|
await this.setSelectedThreadId(thread.threadId);
|
@@ -1589,7 +1615,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1589
1615
|
<div
|
1590
1616
|
class="trash-icon"
|
1591
1617
|
@click=${() => {
|
1592
|
-
if (this.isLoading || this.
|
1618
|
+
if (this.isLoading || this.isStreaming) {
|
1593
1619
|
return;
|
1594
1620
|
}
|
1595
1621
|
this.deleteThreadId = thread.threadId;
|
@@ -1610,8 +1636,13 @@ var ProvidersShopGptSdk = (function () {
|
|
1610
1636
|
<span class="line"></span>
|
1611
1637
|
<button
|
1612
1638
|
class="btn-new-search"
|
1613
|
-
?disabled=${this.isLoading || this.
|
1614
|
-
@click=${() =>
|
1639
|
+
?disabled=${this.isLoading || this.isStreaming}
|
1640
|
+
@click=${() => {
|
1641
|
+
if (this.selectedThreadId) {
|
1642
|
+
this.sendEvent('newSearch');
|
1643
|
+
}
|
1644
|
+
this.setSelectedThreadId('');
|
1645
|
+
}}
|
1615
1646
|
>
|
1616
1647
|
New Search
|
1617
1648
|
</button>
|
@@ -1668,7 +1699,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1668
1699
|
__decorate([
|
1669
1700
|
n({ type: Boolean }),
|
1670
1701
|
__metadata("design:type", Boolean)
|
1671
|
-
], ChatThreads.prototype, "
|
1702
|
+
], ChatThreads.prototype, "isStreaming", void 0);
|
1672
1703
|
__decorate([
|
1673
1704
|
n({ type: String }),
|
1674
1705
|
__metadata("design:type", String)
|
@@ -2339,6 +2370,12 @@ var ProvidersShopGptSdk = (function () {
|
|
2339
2370
|
background: #2b65cf;
|
2340
2371
|
opacity: 1;
|
2341
2372
|
}
|
2373
|
+
|
2374
|
+
.new-search-btn:disabled {
|
2375
|
+
background: #808080;
|
2376
|
+
cursor: not-allowed;
|
2377
|
+
opacity: 0.5;
|
2378
|
+
}
|
2342
2379
|
}
|
2343
2380
|
}
|
2344
2381
|
|
@@ -2371,6 +2408,7 @@ var ProvidersShopGptSdk = (function () {
|
|
2371
2408
|
line-height: 150%;
|
2372
2409
|
letter-spacing: -0.32px;
|
2373
2410
|
|
2411
|
+
box-sizing: border-box;
|
2374
2412
|
background: #fff;
|
2375
2413
|
border-radius: 10px;
|
2376
2414
|
border: 1px solid #dbe2eb;
|
@@ -2489,6 +2527,11 @@ var ProvidersShopGptSdk = (function () {
|
|
2489
2527
|
color: rgb(140, 137, 156);
|
2490
2528
|
border-radius: 50%;
|
2491
2529
|
|
2530
|
+
& > svg {
|
2531
|
+
height: 22px;
|
2532
|
+
width: 22px;
|
2533
|
+
}
|
2534
|
+
|
2492
2535
|
&:hover {
|
2493
2536
|
background-color: rgba(47, 43, 61, 0.08);
|
2494
2537
|
}
|
@@ -3982,6 +4025,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
3982
4025
|
handleFeedback(rating, messageId, comment) {
|
3983
4026
|
var _a, _b;
|
3984
4027
|
if (rating === 'bad') {
|
4028
|
+
this.sendEvent('thumbsDown');
|
3985
4029
|
this.feedbackDetails = {
|
3986
4030
|
messageId,
|
3987
4031
|
threadId: ((_a = this.thread) === null || _a === void 0 ? void 0 : _a.threadId) || '',
|
@@ -3989,6 +4033,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
3989
4033
|
};
|
3990
4034
|
return;
|
3991
4035
|
}
|
4036
|
+
this.sendEvent('thumbsUp');
|
3992
4037
|
this.dispatchEvent(new CustomEvent('submit-feedback', {
|
3993
4038
|
detail: {
|
3994
4039
|
messageId: messageId,
|
@@ -4105,22 +4150,26 @@ ${this.comment ? this.comment : E}</textarea
|
|
4105
4150
|
}
|
4106
4151
|
return x ` <div class="message user">${message.message}</div> `;
|
4107
4152
|
})}
|
4153
|
+
${!this.fromAd || !this.thread
|
4154
|
+
? x `
|
4108
4155
|
<div class="message bot">
|
4109
4156
|
<div>${this.renderBotIcon()}</div>
|
4110
4157
|
<div>
|
4111
4158
|
<p>
|
4112
4159
|
Hi,
|
4113
4160
|
${this.brandName ? x `Welcome to ${this.brandName}.` : E}
|
4114
|
-
I'm here to help you find the perfect product
|
4115
|
-
|
4161
|
+
I'm here to help you find the perfect product. Pick a suggested
|
4162
|
+
prompt from below, or enter your own query.
|
4116
4163
|
</p>
|
4117
4164
|
</div>
|
4118
4165
|
</div>
|
4166
|
+
</div>`
|
4167
|
+
: E}
|
4119
4168
|
</div>
|
4120
4169
|
`;
|
4121
4170
|
}
|
4122
4171
|
renderPrompts() {
|
4123
|
-
if (this.isLoadingHistory || this.
|
4172
|
+
if (this.isLoadingHistory || this.isStreaming || this.isLoadingThreads) {
|
4124
4173
|
return E;
|
4125
4174
|
}
|
4126
4175
|
const isWelcomeMessage = this.messages.length === 1 && this.messages[0].sender === 'bot';
|
@@ -4251,10 +4300,14 @@ ${this.comment ? this.comment : E}</textarea
|
|
4251
4300
|
<button
|
4252
4301
|
class="btn btn-icon new-search-btn"
|
4253
4302
|
@click=${(e) => {
|
4254
|
-
var _a;
|
4303
|
+
var _a, _b;
|
4255
4304
|
e.preventDefault();
|
4256
|
-
(_a = this.
|
4305
|
+
if ((_a = this.thread) === null || _a === void 0 ? void 0 : _a.threadId) {
|
4306
|
+
this.sendEvent('newSearch');
|
4307
|
+
}
|
4308
|
+
(_b = this.setSelectedThreadId) === null || _b === void 0 ? void 0 : _b.call(this, '');
|
4257
4309
|
}}
|
4310
|
+
?disabled=${this.isStreaming}
|
4258
4311
|
>
|
4259
4312
|
${plusBtn}
|
4260
4313
|
</button>
|
@@ -4273,6 +4326,9 @@ ${this.comment ? this.comment : E}</textarea
|
|
4273
4326
|
@click=${(e) => {
|
4274
4327
|
e.preventDefault();
|
4275
4328
|
this.showChatThreads = !this.showChatThreads;
|
4329
|
+
if (this.showChatThreads) {
|
4330
|
+
this.sendEvent('showThreads');
|
4331
|
+
}
|
4276
4332
|
}}
|
4277
4333
|
>
|
4278
4334
|
${timerBtn}
|
@@ -4342,7 +4398,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4342
4398
|
? x `<div
|
4343
4399
|
class="trash-icon"
|
4344
4400
|
@click=${() => {
|
4345
|
-
if (this.
|
4401
|
+
if (this.isStreaming) {
|
4346
4402
|
return;
|
4347
4403
|
}
|
4348
4404
|
this.deleteAllThreads = true;
|
@@ -4358,17 +4414,18 @@ ${this.comment ? this.comment : E}</textarea
|
|
4358
4414
|
<div
|
4359
4415
|
class=${e$1({
|
4360
4416
|
'thread-title': true,
|
4361
|
-
disabled: this.
|
4417
|
+
disabled: this.isStreaming,
|
4362
4418
|
})}
|
4363
4419
|
>
|
4364
4420
|
<p
|
4365
4421
|
@click=${() => {
|
4366
|
-
var _a;
|
4367
|
-
if (this.
|
4422
|
+
var _a, _b;
|
4423
|
+
if (this.isStreaming ||
|
4424
|
+
((_a = this.thread) === null || _a === void 0 ? void 0 : _a.threadId) === thread.threadId) {
|
4368
4425
|
return;
|
4369
4426
|
}
|
4370
4427
|
this.showChatThreads = false;
|
4371
|
-
(
|
4428
|
+
(_b = this.setSelectedThreadId) === null || _b === void 0 ? void 0 : _b.call(this, thread.threadId);
|
4372
4429
|
}}
|
4373
4430
|
>
|
4374
4431
|
${thread.title || 'New Search'}
|
@@ -4376,7 +4433,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4376
4433
|
<div
|
4377
4434
|
class="trash-icon"
|
4378
4435
|
@click=${() => {
|
4379
|
-
if (this.
|
4436
|
+
if (this.isStreaming) {
|
4380
4437
|
return;
|
4381
4438
|
}
|
4382
4439
|
this.deleteThreadId = thread.threadId;
|
@@ -4425,7 +4482,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4425
4482
|
modal: this.viewType === 'modal',
|
4426
4483
|
})}
|
4427
4484
|
type="submit"
|
4428
|
-
?disabled=${this.
|
4485
|
+
?disabled=${this.isStreaming || this.isLoadingHistory}
|
4429
4486
|
>
|
4430
4487
|
${sendFilledIcon}
|
4431
4488
|
</button>
|
@@ -4433,9 +4490,15 @@ ${this.comment ? this.comment : E}</textarea
|
|
4433
4490
|
${this.viewType === 'modal'
|
4434
4491
|
? x ` <footer>
|
4435
4492
|
Powered by
|
4436
|
-
<a
|
4437
|
-
|
4493
|
+
<a
|
4494
|
+
target="_blank"
|
4495
|
+
href="https://shopgpt.edgeagents.ai"
|
4496
|
+
@click=${() => {
|
4497
|
+
this.sendEvent('blotoutLinkClicked');
|
4498
|
+
}}
|
4438
4499
|
>
|
4500
|
+
Blotout
|
4501
|
+
</a>
|
4439
4502
|
</footer>`
|
4440
4503
|
: E}
|
4441
4504
|
</div>
|
@@ -4539,6 +4602,10 @@ ${this.comment ? this.comment : E}</textarea
|
|
4539
4602
|
n({ type: Boolean }),
|
4540
4603
|
__metadata("design:type", Boolean)
|
4541
4604
|
], ChatSection.prototype, "isTyping", void 0);
|
4605
|
+
__decorate([
|
4606
|
+
n({ type: Boolean }),
|
4607
|
+
__metadata("design:type", Boolean)
|
4608
|
+
], ChatSection.prototype, "isStreaming", void 0);
|
4542
4609
|
__decorate([
|
4543
4610
|
n({ type: Boolean }),
|
4544
4611
|
__metadata("design:type", Boolean)
|
@@ -4591,6 +4658,10 @@ ${this.comment ? this.comment : E}</textarea
|
|
4591
4658
|
n({ type: String }),
|
4592
4659
|
__metadata("design:type", String)
|
4593
4660
|
], ChatSection.prototype, "css", void 0);
|
4661
|
+
__decorate([
|
4662
|
+
n({ type: Boolean }),
|
4663
|
+
__metadata("design:type", Boolean)
|
4664
|
+
], ChatSection.prototype, "fromAd", void 0);
|
4594
4665
|
if (!customElements.get('chat-section')) {
|
4595
4666
|
customElements.define('chat-section', ChatSection);
|
4596
4667
|
}
|
@@ -4667,6 +4738,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4667
4738
|
this.isLoadingHistory = false;
|
4668
4739
|
this.isLoadingThreads = false;
|
4669
4740
|
this.isTyping = false;
|
4741
|
+
this.isStreaming = false;
|
4670
4742
|
this.isFailed = false;
|
4671
4743
|
this.selectedThreadId = '';
|
4672
4744
|
this.products = [];
|
@@ -4687,6 +4759,16 @@ ${this.comment ? this.comment : E}</textarea
|
|
4687
4759
|
this.modalState = 'close';
|
4688
4760
|
(_a = this.shopGPTDialog) === null || _a === void 0 ? void 0 : _a.close();
|
4689
4761
|
};
|
4762
|
+
this.isFromAd = () => {
|
4763
|
+
var _a;
|
4764
|
+
if (this.devMode) {
|
4765
|
+
const thread = this.chatThreads.get(this.selectedThreadId);
|
4766
|
+
return thread ? !!((_a = thread.devContext) === null || _a === void 0 ? void 0 : _a.productHandle) : false;
|
4767
|
+
}
|
4768
|
+
const searchParams = new URLSearchParams(window.location.search);
|
4769
|
+
return ((isFromAd(searchParams) || searchParams.get('shopGPT') === '1') &&
|
4770
|
+
!!this.storeAPI.getCurrentProductHandle());
|
4771
|
+
};
|
4690
4772
|
this.submitQuery = (message) => {
|
4691
4773
|
if (!message) {
|
4692
4774
|
return;
|
@@ -4718,7 +4800,9 @@ ${this.comment ? this.comment : E}</textarea
|
|
4718
4800
|
this.startNudgeTimer();
|
4719
4801
|
}
|
4720
4802
|
disconnectedCallback() {
|
4721
|
-
|
4803
|
+
if (!this.loadUIManually) {
|
4804
|
+
window.removeEventListener('edgetag-initialized', this.loadData);
|
4805
|
+
}
|
4722
4806
|
window.removeEventListener('popstate', this.onPopState);
|
4723
4807
|
if (this.nudgeTimer) {
|
4724
4808
|
window.clearTimeout(this.nudgeTimer);
|
@@ -4726,7 +4810,14 @@ ${this.comment ? this.comment : E}</textarea
|
|
4726
4810
|
super.disconnectedCallback();
|
4727
4811
|
}
|
4728
4812
|
init() {
|
4729
|
-
|
4813
|
+
if (this.loadUIManually) {
|
4814
|
+
// this is because edgetag-initialized will already be
|
4815
|
+
// triggered before the loadUI function is called to load the UI
|
4816
|
+
this.loadData();
|
4817
|
+
}
|
4818
|
+
else {
|
4819
|
+
window.addEventListener('edgetag-initialized', this.loadData);
|
4820
|
+
}
|
4730
4821
|
window.addEventListener('popstate', this.onPopState);
|
4731
4822
|
this.shopGPTAPI.sendEvent('shopGPTInitialized', this.getSiteCurrency().currency);
|
4732
4823
|
if (!this.view || this.view === 'overlay') {
|
@@ -4770,15 +4861,18 @@ ${this.comment ? this.comment : E}</textarea
|
|
4770
4861
|
if (!thread) {
|
4771
4862
|
return;
|
4772
4863
|
}
|
4773
|
-
const
|
4774
|
-
const fromAd = isFromAd(searchParams) || searchParams.get('shopGPT') === '1';
|
4864
|
+
const fromAd = this.isFromAd();
|
4775
4865
|
const productHandle = this.devMode
|
4776
4866
|
? (_a = thread === null || thread === void 0 ? void 0 : thread.devContext) === null || _a === void 0 ? void 0 : _a.productHandle
|
4777
4867
|
: fromAd
|
4778
4868
|
? this.storeAPI.getCurrentProductHandle()
|
4779
4869
|
: undefined;
|
4870
|
+
if (!fromAd) {
|
4871
|
+
return;
|
4872
|
+
}
|
4780
4873
|
try {
|
4781
4874
|
this.isTyping = true;
|
4875
|
+
this.isStreaming = true;
|
4782
4876
|
const response = await this.shopGPTAPI.processQuery('', thread.threadId, productHandle);
|
4783
4877
|
this.processMessageResponse(response);
|
4784
4878
|
}
|
@@ -4786,6 +4880,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4786
4880
|
logger.error(error);
|
4787
4881
|
this.isFailed = true;
|
4788
4882
|
this.isTyping = false;
|
4883
|
+
this.isStreaming = false;
|
4789
4884
|
}
|
4790
4885
|
}
|
4791
4886
|
async loadChatThreads() {
|
@@ -4812,9 +4907,9 @@ ${this.comment ? this.comment : E}</textarea
|
|
4812
4907
|
}
|
4813
4908
|
}
|
4814
4909
|
if (latestThread) {
|
4815
|
-
this.setSelectedThreadId(latestThread.threadId);
|
4910
|
+
this.setSelectedThreadId(latestThread.threadId, true);
|
4816
4911
|
}
|
4817
|
-
else if (!this.devMode) {
|
4912
|
+
else if (!this.devMode && this.isFromAd()) {
|
4818
4913
|
this.createChatThread({ title: '' }, true);
|
4819
4914
|
}
|
4820
4915
|
}
|
@@ -4867,9 +4962,12 @@ ${this.comment ? this.comment : E}</textarea
|
|
4867
4962
|
logger.error(e);
|
4868
4963
|
}
|
4869
4964
|
}
|
4870
|
-
async setSelectedThreadId(threadId) {
|
4965
|
+
async setSelectedThreadId(threadId, silent) {
|
4871
4966
|
this.isFailed = false;
|
4872
4967
|
this.selectedThreadId = threadId;
|
4968
|
+
if (threadId && !silent) {
|
4969
|
+
this.shopGPTAPI.sendEvent('switchThread');
|
4970
|
+
}
|
4873
4971
|
await Promise.all([
|
4874
4972
|
this.loadHistory(threadId),
|
4875
4973
|
this.loadCustomPrompts(threadId),
|
@@ -4901,6 +4999,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4901
4999
|
logger.error('ThreadId is missing to delete the thread!');
|
4902
5000
|
return;
|
4903
5001
|
}
|
5002
|
+
this.shopGPTAPI.sendEvent('singleThreadDelete');
|
4904
5003
|
this.shopGPTAPI
|
4905
5004
|
.deleteSingleThread(threadId)
|
4906
5005
|
.then(this.loadChatThreads.bind(this))
|
@@ -4915,6 +5014,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4915
5014
|
handleAllThreadsDelete(e) {
|
4916
5015
|
e.stopPropagation();
|
4917
5016
|
this.isLoadingThreads = true;
|
5017
|
+
this.shopGPTAPI.sendEvent('allThreadsDelete');
|
4918
5018
|
this.shopGPTAPI
|
4919
5019
|
.deleteAllThreads()
|
4920
5020
|
.then(this.loadChatThreads.bind(this))
|
@@ -4992,6 +5092,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4992
5092
|
}
|
4993
5093
|
else if (eventName === 'MessageComplete') {
|
4994
5094
|
isMessageCompleted = true;
|
5095
|
+
this.isStreaming = false;
|
4995
5096
|
this.handleProductsComplete(products, isMessageCompleted);
|
4996
5097
|
this.handleCompleteMessage(data);
|
4997
5098
|
}
|
@@ -5011,7 +5112,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5011
5112
|
async sendMessageToServer(e, message, isPrompt = false) {
|
5012
5113
|
e.preventDefault();
|
5013
5114
|
e.stopPropagation();
|
5014
|
-
if (!message || this.
|
5115
|
+
if (!message || this.isStreaming || this.isLoadingHistory) {
|
5015
5116
|
return;
|
5016
5117
|
}
|
5017
5118
|
this.isFailed = false;
|
@@ -5022,6 +5123,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5022
5123
|
}
|
5023
5124
|
this.messages = [{ sender: 'user', message }, ...this.messages];
|
5024
5125
|
this.isTyping = true;
|
5126
|
+
this.isStreaming = true;
|
5025
5127
|
const response = await this.submitQuery(message);
|
5026
5128
|
this.processMessageResponse(response);
|
5027
5129
|
}
|
@@ -5029,6 +5131,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5029
5131
|
logger.error(err);
|
5030
5132
|
this.isFailed = true;
|
5031
5133
|
this.isTyping = false;
|
5134
|
+
this.isStreaming = false;
|
5032
5135
|
}
|
5033
5136
|
}
|
5034
5137
|
submitFeedback(e) {
|
@@ -5082,7 +5185,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5082
5185
|
.selectedThreadId=${this.selectedThreadId}
|
5083
5186
|
.setSelectedThreadId=${this.setSelectedThreadId.bind(this)}
|
5084
5187
|
.isLoading=${this.isLoadingThreads}
|
5085
|
-
.
|
5188
|
+
.isStreaming=${this.isStreaming}
|
5086
5189
|
.merchantUrl=${this.merchantUrl}
|
5087
5190
|
.css=${this.css}
|
5088
5191
|
></chat-threads>
|
@@ -5100,6 +5203,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5100
5203
|
.isFailed=${this.isFailed}
|
5101
5204
|
.isLoadingHistory=${this.isLoadingHistory}
|
5102
5205
|
.isTyping=${this.isTyping}
|
5206
|
+
.isStreaming=${this.isStreaming}
|
5103
5207
|
.messages=${this.messages}
|
5104
5208
|
.siteCurrency=${this.getSiteCurrency()}
|
5105
5209
|
.sendMessageToServer=${this.sendMessageToServer.bind(this)}
|
@@ -5113,6 +5217,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5113
5217
|
.customPrompts=${this.customPrompts}
|
5114
5218
|
.botIconUrl=${this.botIconUrl}
|
5115
5219
|
.css=${this.css}
|
5220
|
+
.fromAd=${this.isFromAd()}
|
5116
5221
|
></chat-section>
|
5117
5222
|
</div>
|
5118
5223
|
</dialog>
|
@@ -5123,6 +5228,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5123
5228
|
const thread = this.chatThreads.get(this.selectedThreadId);
|
5124
5229
|
const closeModal = () => {
|
5125
5230
|
this.modalState = 'close';
|
5231
|
+
this.shopGPTAPI.sendEvent('chatbotClosed');
|
5126
5232
|
};
|
5127
5233
|
if (this.modalState === 'close') {
|
5128
5234
|
return x ` <div class="chatbot-widget">
|
@@ -5169,6 +5275,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5169
5275
|
.isFailed=${this.isFailed}
|
5170
5276
|
.isLoadingHistory=${this.isLoadingHistory}
|
5171
5277
|
.isTyping=${this.isTyping}
|
5278
|
+
.isStreaming=${this.isStreaming}
|
5172
5279
|
.messages=${this.messages}
|
5173
5280
|
.siteCurrency=${this.getSiteCurrency()}
|
5174
5281
|
.sendMessageToServer=${this.sendMessageToServer.bind(this)}
|
@@ -5186,6 +5293,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5186
5293
|
.customPrompts=${this.customPrompts}
|
5187
5294
|
.botIconUrl=${this.botIconUrl}
|
5188
5295
|
.css=${this.css}
|
5296
|
+
.fromAd=${this.isFromAd()}
|
5189
5297
|
></chat-section>
|
5190
5298
|
</div>
|
5191
5299
|
`;
|
@@ -5258,6 +5366,10 @@ ${this.comment ? this.comment : E}</textarea
|
|
5258
5366
|
n({ type: Boolean }),
|
5259
5367
|
__metadata("design:type", Object)
|
5260
5368
|
], ShopGPT.prototype, "isTyping", void 0);
|
5369
|
+
__decorate([
|
5370
|
+
n({ type: Boolean }),
|
5371
|
+
__metadata("design:type", Object)
|
5372
|
+
], ShopGPT.prototype, "isStreaming", void 0);
|
5261
5373
|
__decorate([
|
5262
5374
|
n({ type: Boolean }),
|
5263
5375
|
__metadata("design:type", Object)
|
@@ -5322,6 +5434,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
5322
5434
|
shopGPT.css = params.css;
|
5323
5435
|
shopGPT.nudge = params.nudge;
|
5324
5436
|
shopGPT.sessionId = params.sessionId;
|
5437
|
+
shopGPT.loadUIManually = params.loadUIManually;
|
5325
5438
|
},
|
5326
5439
|
loadUI() {
|
5327
5440
|
if (!shopGPT) {
|