@blotoutio/providers-shop-gpt-sdk 1.8.0 → 1.9.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 +270 -77
- package/index.js +270 -77
- package/index.mjs +270 -77
- package/package.json +1 -1
package/index.js
CHANGED
@@ -473,7 +473,6 @@ var ProvidersShopGptSdk = (function () {
|
|
473
473
|
return url;
|
474
474
|
};
|
475
475
|
const processQuery = async (query, threadId, productHandle) => {
|
476
|
-
var _a;
|
477
476
|
const response = await fetchImpl(getURL('/query'), {
|
478
477
|
method: 'POST',
|
479
478
|
headers: getHeaders(),
|
@@ -488,14 +487,7 @@ var ProvidersShopGptSdk = (function () {
|
|
488
487
|
if (!response.ok) {
|
489
488
|
throw new Error(`Failed to process the query - ${response.status}: ${await response.text()}`);
|
490
489
|
}
|
491
|
-
|
492
|
-
return {
|
493
|
-
messageId: data.messageId,
|
494
|
-
message: data.message,
|
495
|
-
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
496
|
-
chatTitle: data.chatTitle,
|
497
|
-
welcomePrompts: data.welcomePrompts,
|
498
|
-
};
|
490
|
+
return response;
|
499
491
|
};
|
500
492
|
const fetchChatHistory = async (threadId) => {
|
501
493
|
if (!threadId) {
|
@@ -629,7 +621,7 @@ var ProvidersShopGptSdk = (function () {
|
|
629
621
|
// exit if not in top window
|
630
622
|
return;
|
631
623
|
}
|
632
|
-
const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
624
|
+
const { enabled, mode, devMode, merchantUrl, profiles, productHandles, targetPath, view, brandName, quickPrompts, merchantImage, latestThreadLoad, botIconUrl, css, } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
633
625
|
const experiment = createExperiment({
|
634
626
|
name: getExperimentName(mode),
|
635
627
|
userId: params.userId,
|
@@ -663,6 +655,8 @@ var ProvidersShopGptSdk = (function () {
|
|
663
655
|
quickPrompts,
|
664
656
|
merchantImage,
|
665
657
|
latestThreadLoad: latestThreadLoad !== null && latestThreadLoad !== void 0 ? latestThreadLoad : DEFAULT_MAX_THREAD_AGE,
|
658
|
+
botIconUrl,
|
659
|
+
css,
|
666
660
|
});
|
667
661
|
}
|
668
662
|
};
|
@@ -789,6 +783,14 @@ var ProvidersShopGptSdk = (function () {
|
|
789
783
|
const shopGPTStyles = i$4 `
|
790
784
|
${scrollBarStyles}
|
791
785
|
|
786
|
+
:host {
|
787
|
+
--shopgpt-primary: #001531;
|
788
|
+
--shopgpt-secondary: #172a41;
|
789
|
+
--shopgpt-white: #ffffff;
|
790
|
+
--shopgpt-border: #dbe2eb;
|
791
|
+
--shopgpt-warning: #ffcc81;
|
792
|
+
}
|
793
|
+
|
792
794
|
* {
|
793
795
|
box-sizing: border-box;
|
794
796
|
}
|
@@ -821,6 +823,7 @@ var ProvidersShopGptSdk = (function () {
|
|
821
823
|
0px 20px 20px 0px rgba(0, 0, 0, 0.08);
|
822
824
|
position: fixed;
|
823
825
|
z-index: 2000;
|
826
|
+
background: var(--shopgpt-white);
|
824
827
|
|
825
828
|
@media screen and (max-width: 768px) {
|
826
829
|
min-height: unset;
|
@@ -839,21 +842,21 @@ var ProvidersShopGptSdk = (function () {
|
|
839
842
|
z-index: 1000;
|
840
843
|
|
841
844
|
button {
|
842
|
-
color:
|
845
|
+
color: var(--shopgpt-white);
|
843
846
|
border: none;
|
844
847
|
cursor: pointer;
|
845
848
|
width: 56px;
|
846
849
|
height: 56px;
|
847
|
-
background-color:
|
850
|
+
background-color: var(--shopgpt-primary);
|
848
851
|
border-radius: 50%;
|
849
852
|
justify-content: center;
|
850
853
|
align-items: center;
|
851
|
-
box-shadow: 0 0 4px 1px
|
854
|
+
box-shadow: 0 0 4px 1px var(--shopgpt-white);
|
852
855
|
}
|
853
856
|
|
854
857
|
.chatbot-hover-text {
|
855
858
|
position: absolute;
|
856
|
-
color:
|
859
|
+
color: var(--shopgpt-secondary);
|
857
860
|
padding: 8px;
|
858
861
|
white-space: nowrap;
|
859
862
|
font-size: 16px;
|
@@ -866,7 +869,7 @@ var ProvidersShopGptSdk = (function () {
|
|
866
869
|
right: calc(100% + 5px);
|
867
870
|
|
868
871
|
border-radius: 5px 5px 0px;
|
869
|
-
background:
|
872
|
+
background: var(--shopgpt-warning);
|
870
873
|
box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1),
|
871
874
|
0px 2px 4px -1px rgba(0, 0, 0, 0.06);
|
872
875
|
|
@@ -888,7 +891,7 @@ var ProvidersShopGptSdk = (function () {
|
|
888
891
|
display: flex;
|
889
892
|
overflow: hidden;
|
890
893
|
height: 100%;
|
891
|
-
background:
|
894
|
+
background: var(--shopgpt-white);
|
892
895
|
justify-content: center;
|
893
896
|
align-items: center;
|
894
897
|
padding: 25px;
|
@@ -899,7 +902,7 @@ var ProvidersShopGptSdk = (function () {
|
|
899
902
|
.shopgpt-container {
|
900
903
|
display: flex;
|
901
904
|
gap: 1px;
|
902
|
-
background:
|
905
|
+
background: var(--shopgpt-border);
|
903
906
|
height: 100%;
|
904
907
|
width: 100%;
|
905
908
|
|
@@ -1226,6 +1229,16 @@ var ProvidersShopGptSdk = (function () {
|
|
1226
1229
|
constructor() {
|
1227
1230
|
super(...arguments);
|
1228
1231
|
this.deleteAllThreads = false;
|
1232
|
+
this.isStylesheetInjected = false;
|
1233
|
+
}
|
1234
|
+
connectedCallback() {
|
1235
|
+
super.connectedCallback();
|
1236
|
+
if (!this.isStylesheetInjected && this.css) {
|
1237
|
+
const sheet = new CSSStyleSheet();
|
1238
|
+
sheet.replaceSync(this.css);
|
1239
|
+
this.shadowRoot.adoptedStyleSheets.push(sheet);
|
1240
|
+
this.isStylesheetInjected = true;
|
1241
|
+
}
|
1229
1242
|
}
|
1230
1243
|
getDomain() {
|
1231
1244
|
var _a;
|
@@ -1394,6 +1407,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1394
1407
|
r(),
|
1395
1408
|
__metadata("design:type", Object)
|
1396
1409
|
], ChatThreads.prototype, "deleteAllThreads", void 0);
|
1410
|
+
__decorate([
|
1411
|
+
n({ type: String }),
|
1412
|
+
__metadata("design:type", String)
|
1413
|
+
], ChatThreads.prototype, "css", void 0);
|
1397
1414
|
if (!customElements.get('chat-threads')) {
|
1398
1415
|
customElements.define('chat-threads', ChatThreads);
|
1399
1416
|
}
|
@@ -1832,8 +1849,18 @@ var ProvidersShopGptSdk = (function () {
|
|
1832
1849
|
}
|
1833
1850
|
|
1834
1851
|
class ProductsSection extends r$2 {
|
1852
|
+
constructor() {
|
1853
|
+
super(...arguments);
|
1854
|
+
this.isStylesheetInjected = false;
|
1855
|
+
}
|
1835
1856
|
connectedCallback() {
|
1836
1857
|
super.connectedCallback();
|
1858
|
+
if (!this.isStylesheetInjected && this.css) {
|
1859
|
+
const sheet = new CSSStyleSheet();
|
1860
|
+
sheet.replaceSync(this.css);
|
1861
|
+
this.shadowRoot.adoptedStyleSheets.push(sheet);
|
1862
|
+
this.isStylesheetInjected = true;
|
1863
|
+
}
|
1837
1864
|
}
|
1838
1865
|
renderMerchantImage() {
|
1839
1866
|
if (this.merchantImage) {
|
@@ -1910,6 +1937,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1910
1937
|
e$3('.products'),
|
1911
1938
|
__metadata("design:type", Object)
|
1912
1939
|
], ProductsSection.prototype, "productsEle", void 0);
|
1940
|
+
__decorate([
|
1941
|
+
n({ type: String }),
|
1942
|
+
__metadata("design:type", String)
|
1943
|
+
], ProductsSection.prototype, "css", void 0);
|
1913
1944
|
if (!customElements.get('products-section')) {
|
1914
1945
|
customElements.define('products-section', ProductsSection);
|
1915
1946
|
}
|
@@ -2026,8 +2057,8 @@ var ProvidersShopGptSdk = (function () {
|
|
2026
2057
|
}
|
2027
2058
|
|
2028
2059
|
.chatbot-section.modal-view {
|
2029
|
-
height: calc(100% -
|
2030
|
-
padding: 0px 16px
|
2060
|
+
height: calc(100% - 93px);
|
2061
|
+
padding: 0px 16px 16px;
|
2031
2062
|
gap: 16px;
|
2032
2063
|
}
|
2033
2064
|
|
@@ -2176,6 +2207,9 @@ var ProvidersShopGptSdk = (function () {
|
|
2176
2207
|
border-radius: 5px;
|
2177
2208
|
border: 1px solid #dbe2eb;
|
2178
2209
|
background: #fff;
|
2210
|
+
width: 36px;
|
2211
|
+
height: 36px;
|
2212
|
+
box-sizing: border-box;
|
2179
2213
|
}
|
2180
2214
|
|
2181
2215
|
.line {
|
@@ -2412,6 +2446,17 @@ var ProvidersShopGptSdk = (function () {
|
|
2412
2446
|
}
|
2413
2447
|
}
|
2414
2448
|
|
2449
|
+
footer {
|
2450
|
+
text-align: center;
|
2451
|
+
font-size: 10px;
|
2452
|
+
color: #4e647f;
|
2453
|
+
font-weight: 500;
|
2454
|
+
|
2455
|
+
a {
|
2456
|
+
text-decoration: none;
|
2457
|
+
}
|
2458
|
+
}
|
2459
|
+
|
2415
2460
|
${scrollBarStyles}
|
2416
2461
|
`;
|
2417
2462
|
|
@@ -3081,12 +3126,12 @@ var ProvidersShopGptSdk = (function () {
|
|
3081
3126
|
};
|
3082
3127
|
|
3083
3128
|
class MarkdownRenderer extends r$2 {
|
3129
|
+
constructor() {
|
3130
|
+
super(...arguments);
|
3131
|
+
this.content = '';
|
3132
|
+
}
|
3084
3133
|
render() {
|
3085
|
-
|
3086
|
-
const slotContent = this.innerHTML
|
3087
|
-
.trim()
|
3088
|
-
.replace(/<!--\?lit\$[\d$]+-->/g, '');
|
3089
|
-
return o(markdown(slotContent));
|
3134
|
+
return o(markdown(this.content));
|
3090
3135
|
}
|
3091
3136
|
}
|
3092
3137
|
MarkdownRenderer.styles = i$4 `
|
@@ -3100,6 +3145,10 @@ var ProvidersShopGptSdk = (function () {
|
|
3100
3145
|
}
|
3101
3146
|
}
|
3102
3147
|
`;
|
3148
|
+
__decorate([
|
3149
|
+
n({ type: String }),
|
3150
|
+
__metadata("design:type", Object)
|
3151
|
+
], MarkdownRenderer.prototype, "content", void 0);
|
3103
3152
|
if (!customElements.get('markdown-renderer')) {
|
3104
3153
|
customElements.define('markdown-renderer', MarkdownRenderer);
|
3105
3154
|
}
|
@@ -3555,6 +3604,16 @@ ${this.comment ? this.comment : E}</textarea
|
|
3555
3604
|
this.showChatThreads = false;
|
3556
3605
|
this.deleteAllThreads = false;
|
3557
3606
|
this.userQuery = '';
|
3607
|
+
this.isStylesheetInjected = false;
|
3608
|
+
}
|
3609
|
+
connectedCallback() {
|
3610
|
+
super.connectedCallback();
|
3611
|
+
if (!this.isStylesheetInjected && this.css) {
|
3612
|
+
const sheet = new CSSStyleSheet();
|
3613
|
+
sheet.replaceSync(this.css);
|
3614
|
+
this.shadowRoot.adoptedStyleSheets.push(sheet);
|
3615
|
+
this.isStylesheetInjected = true;
|
3616
|
+
}
|
3558
3617
|
}
|
3559
3618
|
scrollToBottom() {
|
3560
3619
|
var _a;
|
@@ -3625,12 +3684,12 @@ ${this.comment ? this.comment : E}</textarea
|
|
3625
3684
|
return x `
|
3626
3685
|
<div class="message-wrapper">
|
3627
3686
|
<div class="message bot">
|
3628
|
-
<div>
|
3629
|
-
<div class="bot-icon">${botIcon}</div>
|
3630
|
-
</div>
|
3687
|
+
<div>${this.renderBotIcon()}</div>
|
3631
3688
|
<div>
|
3632
3689
|
${message.message
|
3633
|
-
? x ` <markdown-renderer
|
3690
|
+
? x ` <markdown-renderer
|
3691
|
+
.content=${message.message}
|
3692
|
+
></markdown-renderer>`
|
3634
3693
|
: E}
|
3635
3694
|
${this.viewType !== 'modal' && ((_a = message.products) === null || _a === void 0 ? void 0 : _a[0])
|
3636
3695
|
? x `
|
@@ -3675,6 +3734,14 @@ ${this.comment ? this.comment : E}</textarea
|
|
3675
3734
|
</div>
|
3676
3735
|
`;
|
3677
3736
|
}
|
3737
|
+
renderBotIcon() {
|
3738
|
+
if (this.botIconUrl) {
|
3739
|
+
return x `<div class="bot-icon">
|
3740
|
+
<img src=${this.botIconUrl} width="30" height="30" />
|
3741
|
+
</div>`;
|
3742
|
+
}
|
3743
|
+
return x ` <div class="bot-icon">${botIcon}</div> `;
|
3744
|
+
}
|
3678
3745
|
chatWindow() {
|
3679
3746
|
if (this.isLoadingHistory || this.isLoadingThreads) {
|
3680
3747
|
return x `<div class="messages loading">
|
@@ -3685,17 +3752,13 @@ ${this.comment ? this.comment : E}</textarea
|
|
3685
3752
|
<div class="messages">
|
3686
3753
|
${this.isTyping
|
3687
3754
|
? x ` <div class="message bot">
|
3688
|
-
<div>
|
3689
|
-
<div class="bot-icon">${botIcon}</div>
|
3690
|
-
</div>
|
3755
|
+
<div>${this.renderBotIcon()}</div>
|
3691
3756
|
${this.typingIndicator()}
|
3692
3757
|
</div>`
|
3693
3758
|
: ''}
|
3694
3759
|
${this.isFailed
|
3695
3760
|
? x `<div class="message bot">
|
3696
|
-
<div>
|
3697
|
-
<div class="bot-icon">${botIcon}</div>
|
3698
|
-
</div>
|
3761
|
+
<div>${this.renderBotIcon()}</div>
|
3699
3762
|
<div>
|
3700
3763
|
<p>
|
3701
3764
|
Uh-oh! Looks like I tripped over some alpha-stage wires.
|
@@ -3713,9 +3776,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
3713
3776
|
return x ` <div class="message user">${message.message}</div> `;
|
3714
3777
|
})}
|
3715
3778
|
<div class="message bot">
|
3716
|
-
<div>
|
3717
|
-
<div class="bot-icon">${botIcon}</div>
|
3718
|
-
</div>
|
3779
|
+
<div>${this.renderBotIcon()}</div>
|
3719
3780
|
<div>
|
3720
3781
|
<p>
|
3721
3782
|
Hi,
|
@@ -3840,7 +3901,11 @@ ${this.comment ? this.comment : E}</textarea
|
|
3840
3901
|
modalViewHeader() {
|
3841
3902
|
var _a;
|
3842
3903
|
return x `
|
3843
|
-
<div
|
3904
|
+
<div>
|
3905
|
+
${this.botIconUrl
|
3906
|
+
? x `<img src=${this.botIconUrl} width="30" height="30" />`
|
3907
|
+
: botIcon}
|
3908
|
+
</div>
|
3844
3909
|
<h2>${((_a = this.thread) === null || _a === void 0 ? void 0 : _a.title) || 'New Search'}</h2>
|
3845
3910
|
<div class="btns-wrapper">
|
3846
3911
|
<tooltip-component .position=${'bottom-right'} .text=${'New Chat'}>
|
@@ -4026,6 +4091,11 @@ ${this.comment ? this.comment : E}</textarea
|
|
4026
4091
|
${sendFilledIcon}
|
4027
4092
|
</button>
|
4028
4093
|
</form>
|
4094
|
+
${this.viewType === 'modal'
|
4095
|
+
? x ` <footer>
|
4096
|
+
Powered by <a href="https://blotout.io">Blotout</a>
|
4097
|
+
</footer>`
|
4098
|
+
: E}
|
4029
4099
|
</div>
|
4030
4100
|
<personalize-dialog
|
4031
4101
|
.createChatThread=${this.createChatThread.bind(this)}
|
@@ -4082,6 +4152,10 @@ ${this.comment ? this.comment : E}</textarea
|
|
4082
4152
|
n({ type: String }),
|
4083
4153
|
__metadata("design:type", Object)
|
4084
4154
|
], ChatSection.prototype, "merchantImage", void 0);
|
4155
|
+
__decorate([
|
4156
|
+
n({ type: String }),
|
4157
|
+
__metadata("design:type", Object)
|
4158
|
+
], ChatSection.prototype, "botIconUrl", void 0);
|
4085
4159
|
__decorate([
|
4086
4160
|
n({ type: String }),
|
4087
4161
|
__metadata("design:type", Object)
|
@@ -4170,15 +4244,69 @@ ${this.comment ? this.comment : E}</textarea
|
|
4170
4244
|
n({ type: String }),
|
4171
4245
|
__metadata("design:type", Object)
|
4172
4246
|
], ChatSection.prototype, "userQuery", void 0);
|
4247
|
+
__decorate([
|
4248
|
+
n({ type: String }),
|
4249
|
+
__metadata("design:type", String)
|
4250
|
+
], ChatSection.prototype, "css", void 0);
|
4173
4251
|
if (!customElements.get('chat-section')) {
|
4174
4252
|
customElements.define('chat-section', ChatSection);
|
4175
4253
|
}
|
4176
4254
|
|
4255
|
+
const handleEventSource = async (response, onEvent) => {
|
4256
|
+
var _a, _b;
|
4257
|
+
if (!response.body) {
|
4258
|
+
throw new Error('No body found in response');
|
4259
|
+
}
|
4260
|
+
let buffer = '';
|
4261
|
+
for await (const chunk of response.body.pipeThrough(new TextDecoderStream())) {
|
4262
|
+
buffer += chunk;
|
4263
|
+
const sections = buffer.split('\n\n');
|
4264
|
+
buffer = sections.pop() || '';
|
4265
|
+
for (const section of sections) {
|
4266
|
+
const event = parseMessage(section, true);
|
4267
|
+
onEvent((_a = event.event) !== null && _a !== void 0 ? _a : '', event.data);
|
4268
|
+
}
|
4269
|
+
}
|
4270
|
+
if (buffer) {
|
4271
|
+
const event = parseMessage(buffer, true);
|
4272
|
+
onEvent((_b = event.event) !== null && _b !== void 0 ? _b : '', event.data);
|
4273
|
+
}
|
4274
|
+
};
|
4275
|
+
const parseMessage = (message, parseDataAsJSON) => {
|
4276
|
+
const fields = message.split('\n');
|
4277
|
+
const result = {};
|
4278
|
+
for (const field of fields) {
|
4279
|
+
if (field.startsWith(':')) {
|
4280
|
+
continue;
|
4281
|
+
}
|
4282
|
+
if (field.startsWith('event: ')) {
|
4283
|
+
result.event = field.slice(7);
|
4284
|
+
}
|
4285
|
+
else if (field.startsWith('data: ')) {
|
4286
|
+
if (result.data) {
|
4287
|
+
result.data += '\n';
|
4288
|
+
}
|
4289
|
+
else {
|
4290
|
+
result.data = '';
|
4291
|
+
}
|
4292
|
+
result.data += field.slice(6);
|
4293
|
+
}
|
4294
|
+
else if (field.startsWith('retry: ')) {
|
4295
|
+
result.retry = field.slice(7);
|
4296
|
+
}
|
4297
|
+
}
|
4298
|
+
if (result.data && parseDataAsJSON) {
|
4299
|
+
result.data = JSON.parse(result.data);
|
4300
|
+
}
|
4301
|
+
return result;
|
4302
|
+
};
|
4303
|
+
|
4177
4304
|
const DIALOG_DELAY = 1000;
|
4178
4305
|
const normalizePath = (path) => path.replace(/\/$/, '');
|
4179
4306
|
class ShopGPT extends r$2 {
|
4180
4307
|
constructor() {
|
4181
4308
|
super(...arguments);
|
4309
|
+
this.isStylesheetInjected = false;
|
4182
4310
|
this.latestThreadLoad = DEFAULT_MAX_THREAD_AGE;
|
4183
4311
|
this.modalState = 'close';
|
4184
4312
|
this.isLoadingHistory = false;
|
@@ -4212,6 +4340,12 @@ ${this.comment ? this.comment : E}</textarea
|
|
4212
4340
|
}
|
4213
4341
|
connectedCallback() {
|
4214
4342
|
super.connectedCallback();
|
4343
|
+
if (!this.isStylesheetInjected && this.css) {
|
4344
|
+
const sheet = new CSSStyleSheet();
|
4345
|
+
sheet.replaceSync(this.css);
|
4346
|
+
this.shadowRoot.adoptedStyleSheets.push(sheet);
|
4347
|
+
this.isStylesheetInjected = true;
|
4348
|
+
}
|
4215
4349
|
if (!this.view || this.view === 'overlay') {
|
4216
4350
|
if (!this.path) {
|
4217
4351
|
return;
|
@@ -4281,27 +4415,12 @@ ${this.comment ? this.comment : E}</textarea
|
|
4281
4415
|
: undefined;
|
4282
4416
|
try {
|
4283
4417
|
this.isTyping = true;
|
4284
|
-
const
|
4285
|
-
|
4286
|
-
this.setChatTitle(this.selectedThreadId, reply.chatTitle);
|
4287
|
-
}
|
4288
|
-
this.messages = [
|
4289
|
-
{
|
4290
|
-
messageId: reply.messageId,
|
4291
|
-
sender: 'bot',
|
4292
|
-
message: reply.message,
|
4293
|
-
products: reply.products,
|
4294
|
-
welcomePrompts: reply.welcomePrompts,
|
4295
|
-
},
|
4296
|
-
...this.messages,
|
4297
|
-
];
|
4298
|
-
this.products = reply.products || [];
|
4418
|
+
const response = await this.shopGPTAPI.processQuery('', thread.threadId, productHandle);
|
4419
|
+
this.processMessageResponse(response);
|
4299
4420
|
}
|
4300
4421
|
catch (error) {
|
4301
4422
|
logger.error(error);
|
4302
4423
|
this.isFailed = true;
|
4303
|
-
}
|
4304
|
-
finally {
|
4305
4424
|
this.isTyping = false;
|
4306
4425
|
}
|
4307
4426
|
}
|
@@ -4439,6 +4558,92 @@ ${this.comment ? this.comment : E}</textarea
|
|
4439
4558
|
.catch(logger.error)
|
4440
4559
|
.finally(() => (this.isLoadingThreads = false));
|
4441
4560
|
}
|
4561
|
+
handleMessageChunks(messageData) {
|
4562
|
+
if (!messageData.message) {
|
4563
|
+
return;
|
4564
|
+
}
|
4565
|
+
const latestMessage = this.messages[0];
|
4566
|
+
this.isTyping = false;
|
4567
|
+
if (latestMessage === null || latestMessage === void 0 ? void 0 : latestMessage.isChunk) {
|
4568
|
+
this.messages = [
|
4569
|
+
{
|
4570
|
+
...latestMessage,
|
4571
|
+
message: latestMessage.message + messageData.message,
|
4572
|
+
isChunk: messageData.isChunk,
|
4573
|
+
sender: 'bot',
|
4574
|
+
},
|
4575
|
+
...this.messages.slice(1),
|
4576
|
+
];
|
4577
|
+
}
|
4578
|
+
else {
|
4579
|
+
this.messages = [
|
4580
|
+
{
|
4581
|
+
sender: 'bot',
|
4582
|
+
message: messageData.message || '',
|
4583
|
+
isChunk: messageData.isChunk,
|
4584
|
+
},
|
4585
|
+
...this.messages,
|
4586
|
+
];
|
4587
|
+
}
|
4588
|
+
}
|
4589
|
+
handleCompleteMessage(messageData) {
|
4590
|
+
const latestMessage = this.messages[0];
|
4591
|
+
this.messages = [
|
4592
|
+
{
|
4593
|
+
...latestMessage,
|
4594
|
+
message: messageData.message || '',
|
4595
|
+
messageId: messageData.messageId,
|
4596
|
+
welcomePrompts: messageData.welcomePrompts,
|
4597
|
+
sender: 'bot',
|
4598
|
+
isChunk: false,
|
4599
|
+
},
|
4600
|
+
...this.messages.slice(1),
|
4601
|
+
];
|
4602
|
+
}
|
4603
|
+
handleProductsComplete(products, isMessageCompleted) {
|
4604
|
+
if (!products || !isMessageCompleted) {
|
4605
|
+
return;
|
4606
|
+
}
|
4607
|
+
const latestMessage = this.messages[0];
|
4608
|
+
this.messages = [
|
4609
|
+
{
|
4610
|
+
...latestMessage,
|
4611
|
+
products,
|
4612
|
+
},
|
4613
|
+
...this.messages.slice(1),
|
4614
|
+
];
|
4615
|
+
if (products.length) {
|
4616
|
+
this.products = products;
|
4617
|
+
}
|
4618
|
+
}
|
4619
|
+
processMessageResponse(response) {
|
4620
|
+
let isMessageCompleted = false;
|
4621
|
+
let products;
|
4622
|
+
handleEventSource(response, (eventName, data) => {
|
4623
|
+
if (eventName === 'ChatTitle') {
|
4624
|
+
this.setChatTitle(this.selectedThreadId, data.chatTitle || '');
|
4625
|
+
}
|
4626
|
+
else if (eventName === 'Message') {
|
4627
|
+
this.handleMessageChunks(data);
|
4628
|
+
}
|
4629
|
+
else if (eventName === 'MessageComplete') {
|
4630
|
+
isMessageCompleted = true;
|
4631
|
+
this.handleProductsComplete(products, isMessageCompleted);
|
4632
|
+
this.handleCompleteMessage(data);
|
4633
|
+
}
|
4634
|
+
else if (eventName === 'ProductsComplete') {
|
4635
|
+
this.handleProductsComplete(data.products, isMessageCompleted);
|
4636
|
+
products = data.products;
|
4637
|
+
}
|
4638
|
+
else if (eventName === 'error') {
|
4639
|
+
if (this.messages[0].isChunk) {
|
4640
|
+
this.messages = this.messages.slice(1);
|
4641
|
+
}
|
4642
|
+
this.isFailed = true;
|
4643
|
+
throw new Error(data);
|
4644
|
+
}
|
4645
|
+
});
|
4646
|
+
}
|
4442
4647
|
async sendMessageToServer(e, message) {
|
4443
4648
|
e.preventDefault();
|
4444
4649
|
e.stopPropagation();
|
@@ -4449,32 +4654,12 @@ ${this.comment ? this.comment : E}</textarea
|
|
4449
4654
|
try {
|
4450
4655
|
this.messages = [{ sender: 'user', message }, ...this.messages];
|
4451
4656
|
this.isTyping = true;
|
4452
|
-
const
|
4453
|
-
|
4454
|
-
return;
|
4455
|
-
}
|
4456
|
-
if (reply.chatTitle) {
|
4457
|
-
this.setChatTitle(this.selectedThreadId, reply.chatTitle);
|
4458
|
-
}
|
4459
|
-
this.messages = [
|
4460
|
-
{
|
4461
|
-
messageId: reply.messageId,
|
4462
|
-
sender: 'bot',
|
4463
|
-
message: reply.message,
|
4464
|
-
products: reply.products,
|
4465
|
-
welcomePrompts: reply.welcomePrompts,
|
4466
|
-
},
|
4467
|
-
...this.messages,
|
4468
|
-
];
|
4469
|
-
if (reply.products && reply.products.length > 0) {
|
4470
|
-
this.products = reply.products;
|
4471
|
-
}
|
4657
|
+
const response = await this.submitQuery(message);
|
4658
|
+
this.processMessageResponse(response);
|
4472
4659
|
}
|
4473
4660
|
catch (err) {
|
4474
4661
|
logger.error(err);
|
4475
4662
|
this.isFailed = true;
|
4476
|
-
}
|
4477
|
-
finally {
|
4478
4663
|
this.isTyping = false;
|
4479
4664
|
}
|
4480
4665
|
}
|
@@ -4521,6 +4706,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4521
4706
|
.isLoading=${this.isLoadingThreads}
|
4522
4707
|
.isTyping=${this.isTyping}
|
4523
4708
|
.merchantUrl=${this.merchantUrl}
|
4709
|
+
.css=${this.css}
|
4524
4710
|
></chat-threads>
|
4525
4711
|
<products-section
|
4526
4712
|
.merchantImage=${this.merchantImage}
|
@@ -4528,6 +4714,7 @@ ${this.comment ? this.comment : E}</textarea
|
|
4528
4714
|
.isLoadingHistory=${this.isLoadingHistory}
|
4529
4715
|
.siteCurrency=${this.getSiteCurrency()}
|
4530
4716
|
.isLoadingThreads=${this.isLoadingThreads}
|
4717
|
+
.css=${this.css}
|
4531
4718
|
></products-section>
|
4532
4719
|
<chat-section
|
4533
4720
|
.prompts=${this.quickPrompts}
|
@@ -4546,6 +4733,8 @@ ${this.comment ? this.comment : E}</textarea
|
|
4546
4733
|
.viewType=${'overlay'}
|
4547
4734
|
.isLoadingThreads=${this.isLoadingThreads}
|
4548
4735
|
.customPrompts=${this.customPrompts}
|
4736
|
+
.botIconUrl=${this.botIconUrl}
|
4737
|
+
.css=${this.css}
|
4549
4738
|
></chat-section>
|
4550
4739
|
</div>
|
4551
4740
|
</dialog>
|
@@ -4597,6 +4786,8 @@ ${this.comment ? this.comment : E}</textarea
|
|
4597
4786
|
.isLoadingThreads=${this.isLoadingThreads}
|
4598
4787
|
.merchantImage=${this.merchantImage}
|
4599
4788
|
.customPrompts=${this.customPrompts}
|
4789
|
+
.botIconUrl=${this.botIconUrl}
|
4790
|
+
.css=${this.css}
|
4600
4791
|
></chat-section>
|
4601
4792
|
</div>
|
4602
4793
|
`;
|
@@ -4678,6 +4869,8 @@ ${this.comment ? this.comment : E}</textarea
|
|
4678
4869
|
shopGPT.quickPrompts = params.quickPrompts;
|
4679
4870
|
shopGPT.merchantImage = params.merchantImage;
|
4680
4871
|
shopGPT.latestThreadLoad = params.latestThreadLoad;
|
4872
|
+
shopGPT.botIconUrl = params.botIconUrl;
|
4873
|
+
shopGPT.css = params.css;
|
4681
4874
|
document.body.append(shopGPT);
|
4682
4875
|
},
|
4683
4876
|
destroy() {
|