@blotoutio/providers-shop-gpt-sdk 0.68.1

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 ADDED
@@ -0,0 +1,1425 @@
1
+ 'use strict';
2
+
3
+ const expand = (str) => str.split(',').flatMap((entry) => {
4
+ if (!entry.includes('-')) {
5
+ return entry;
6
+ }
7
+ const result = [];
8
+ const [start, end] = entry.split('-').map(Number);
9
+ for (let i = start; i <= end; i++) {
10
+ result.push(i.toString());
11
+ }
12
+ return result;
13
+ });
14
+ /**
15
+ * Exported from https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes
16
+ *
17
+ * In Dev Tools, select the `tbody` element containing the area codes and run the following code,
18
+ * replacing the emdash character with a simple endash:
19
+ *
20
+ * ```ts
21
+ * [...$0.querySelectorAll('td:first-child')]
22
+ * .filter(cell => cell.firstChild.nodeName != 'A')
23
+ * .map(cell => cell.textContent.trim()).join(',')
24
+ * ```
25
+ */
26
+ new Set([
27
+ ...expand('200,211,221,222,230,232,233,235,237-238,241,243,244,245,247,255,257,258-259,261,265,266,271,273,274,275,277,278,280,282,283,285-287,288,290-299'),
28
+ ...expand('300,311,322,324,327,328,333,335,338,342,344,348-349,353,355,356,357-359,362,366,369,370-379,381,382,383-384,387,388,389,390-399'),
29
+ ...expand('400,411,420,421-422,426-427,428,429,433,439,444,446,449,451-454,455,456,457,459,460,461-462,465,466,467,471,476,477,481-483,485-486,487,488,489,490-499'),
30
+ ...expand('511,532,535,536,537,538,542-543,545-547,549-550,552-554,555,556,558,560,565,568,569,576,578,583,589,590-599'),
31
+ ...expand('611,621,624,625,627,632,633,634-635,637-638,642-643,644,648,652-654,655,663,665,666,668,673-676,677,679,685,686,687,688,690-699'),
32
+ ...expand('711,722,723,729,733,735-736,739,741,744,745-746,748,749-751,752,755,756,759,761,764,766,768,776,777,783,788,789,790-799'),
33
+ ...expand('811,821,822,823-824,827,834,836,841-842,846,851,852-853,871,874-875,879,880-887,889,890-899'),
34
+ ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
35
+ ]);
36
+
37
+ const packageName = 'shopGPT';
38
+
39
+ var _a$1;
40
+ const registryKey = Symbol.for('shop-gpt');
41
+ if (typeof window != 'undefined') {
42
+ (_a$1 = window[registryKey]) !== null && _a$1 !== void 0 ? _a$1 : (window[registryKey] = {});
43
+ }
44
+
45
+ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, storeAPI, }) => {
46
+ if (!baseURL) {
47
+ throw new Error(`baseURL missing`);
48
+ }
49
+ if (!userId) {
50
+ throw new Error(`userId missing`);
51
+ }
52
+ if (!storeAPI) {
53
+ throw new Error(`store API implementation missing`);
54
+ }
55
+ const getHeaders = (json = false) => {
56
+ const headers = new Headers({ EdgeTagUserId: userId });
57
+ if (json) {
58
+ headers.set('Content-type', 'application/json; charset=utf-8');
59
+ }
60
+ return headers;
61
+ };
62
+ const getURL = (path) => {
63
+ const url = new URL(`/providers/shopGPT${path}`, baseURL);
64
+ return url;
65
+ };
66
+ const processQuery = async (query) => {
67
+ const response = await fetchImpl(getURL('/query'), {
68
+ method: 'POST',
69
+ headers: getHeaders(),
70
+ body: JSON.stringify({ query, timestamp: Date.now() }),
71
+ credentials: 'include',
72
+ });
73
+ if (!response.ok) {
74
+ throw new Error(`Failed to process the query - ${response.status}: ${await response.text()}`);
75
+ }
76
+ const data = (await response.json());
77
+ return {
78
+ message: data.message,
79
+ products: data.products.map((item) => ({ ...item, quantity: 1 })),
80
+ };
81
+ };
82
+ const queryPrompts = async () => {
83
+ const response = await fetchImpl(getURL('/query-prompts'), {
84
+ method: 'GET',
85
+ headers: getHeaders(),
86
+ credentials: 'include',
87
+ });
88
+ if (!response.ok) {
89
+ throw new Error(`Could not fetch query Prompts - ${response.status}: ${await response.text()}`);
90
+ }
91
+ const data = (await response.json());
92
+ return data.prompts;
93
+ };
94
+ const initialPrompt = async (productId) => {
95
+ const response = await fetchImpl(getURL('/query-initial-prompt'), {
96
+ method: 'POST',
97
+ headers: getHeaders(),
98
+ body: JSON.stringify({ productId }),
99
+ credentials: 'include',
100
+ });
101
+ if (!response.ok) {
102
+ throw new Error(`Could not fetch query Prompts - ${response.status}: ${await response.text()}`);
103
+ }
104
+ const data = (await response.json());
105
+ return data.prompt;
106
+ };
107
+ const fetchChatHistory = async () => {
108
+ const response = await fetchImpl(getURL('/query-history'), {
109
+ method: 'GET',
110
+ headers: getHeaders(),
111
+ credentials: 'include',
112
+ });
113
+ if (!response.ok) {
114
+ throw new Error(`Could not fetch query history - ${response.status}: ${await response.text()}`);
115
+ }
116
+ const data = (await response.json());
117
+ return data.history;
118
+ };
119
+ return {
120
+ processQuery,
121
+ queryPrompts,
122
+ initialPrompt,
123
+ fetchChatHistory,
124
+ };
125
+ };
126
+
127
+ const error = (message) => console.error(message);
128
+ const init = (params) => {
129
+ var _a, _b, _c;
130
+ if (typeof window == 'undefined' || typeof document == 'undefined') {
131
+ // if loaded in non-browser SDKs, return early
132
+ return;
133
+ }
134
+ let storeAPI = window[registryKey].storeAPI;
135
+ if (!storeAPI) {
136
+ storeAPI = window[registryKey].storeAPI =
137
+ (_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a);
138
+ }
139
+ if (!storeAPI) {
140
+ error('Implementation for store API missing!');
141
+ return;
142
+ }
143
+ if (window.top !== window) {
144
+ // exit if not in top window
145
+ return;
146
+ }
147
+ const { enabled } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
148
+ if (enabled) {
149
+ const uiImplementation = window[registryKey].ui;
150
+ if (!uiImplementation) {
151
+ error('UI implementation is missing');
152
+ return;
153
+ }
154
+ const shopGPTAPI = createShopGPTAPI({
155
+ baseURL: params.baseUrl,
156
+ storeAPI,
157
+ userId: params.userId,
158
+ });
159
+ uiImplementation.init({
160
+ storeAPI,
161
+ shopGPTAPI,
162
+ });
163
+ }
164
+ };
165
+
166
+ // eslint-disable-next-line @nx/enforce-module-boundaries
167
+ const data = {
168
+ name: packageName,
169
+ init,
170
+ };
171
+ try {
172
+ if (typeof window !== 'undefined') {
173
+ window.edgetagProviders = window.edgetagProviders || [];
174
+ window.edgetagProviders.push(data);
175
+ }
176
+ }
177
+ catch {
178
+ // no window
179
+ }
180
+
181
+ /******************************************************************************
182
+ Copyright (c) Microsoft Corporation.
183
+
184
+ Permission to use, copy, modify, and/or distribute this software for any
185
+ purpose with or without fee is hereby granted.
186
+
187
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
188
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
189
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
190
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
191
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
192
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
193
+ PERFORMANCE OF THIS SOFTWARE.
194
+ ***************************************************************************** */
195
+ /* global Reflect, Promise, SuppressedError, Symbol */
196
+
197
+
198
+ function __decorate(decorators, target, key, desc) {
199
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
200
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
201
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
202
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
203
+ }
204
+
205
+ function __metadata(metadataKey, metadataValue) {
206
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
207
+ }
208
+
209
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
210
+ var e = new Error(message);
211
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
212
+ };
213
+
214
+ /**
215
+ * @license
216
+ * Copyright 2019 Google LLC
217
+ * SPDX-License-Identifier: BSD-3-Clause
218
+ */
219
+ const t$2=globalThis,e$4=t$2.ShadowRoot&&(void 0===t$2.ShadyCSS||t$2.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$4&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$5=t=>new n$3("string"==typeof t?t:t+"",void 0,s$2),i$2=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$2)},S$1=(s,o)=>{if(e$4)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$2.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$4?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
220
+
221
+ /**
222
+ * @license
223
+ * Copyright 2017 Google LLC
224
+ * SPDX-License-Identifier: BSD-3-Clause
225
+ */const{is:i$1,defineProperty:e$3,getOwnPropertyDescriptor:r$4,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$1(t,s),y$1={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let b$1 = class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$3(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$4(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return !1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&!0===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);}!1===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),!0===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=!0;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t)!0!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=!1;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(s)):this._$EU();}catch(s){throw t=!1,this._$EU(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$EU(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return !0}update(t){this._$Ej&&=this._$Ej.forEach((t=>this._$EC(t,this[t]))),this._$EU();}updated(t){}firstUpdated(t){}};b$1.elementStyles=[],b$1.shadowRootOptions={mode:"open"},b$1[d$1("elementProperties")]=new Map,b$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:b$1}),(a$1.reactiveElementVersions??=[]).push("2.0.4");
226
+
227
+ /**
228
+ * @license
229
+ * Copyright 2017 Google LLC
230
+ * SPDX-License-Identifier: BSD-3-Clause
231
+ */
232
+ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$2="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,r$3=document,l=()=>r$3.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),b=y(2),w=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),A=new WeakMap,E=r$3.createTreeWalker(r$3,129);function C(t,i){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s$1?s$1.createHTML(i):i}const P=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e$2+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [C(t,l+(t[s]||"<?>")+(2===i?"</svg>":"")),o]};class V{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=P(t,s);if(this.el=V.createElement(f,n),E.currentNode=this.el.content,2===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=E.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e$2)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?k:"?"===e[1]?H:"@"===e[1]?I:R}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i?i.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),E.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$3.createElement("template");return s.innerHTML=t,s}}function N(t,i,s=t,e){if(i===w)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(!1),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=N(t,h._$AS(t,i.values),h,e)),i}class S{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$3).importNode(i,!0);E.currentNode=e;let h=E.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new M(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new L(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=E.nextNode(),o++);}return E.currentNode=r$3,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class M{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=T,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=N(this,t,i),c(t)?t===T||null==t||""===t?(this._$AH!==T&&this._$AR(),this._$AH=T):t!==this._$AH&&t!==w&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}S(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.S(t));}_(t){this._$AH!==T&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$3.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=V.createElement(C(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new S(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new V(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new M(this.S(l()),this.S(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i;}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=T,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=T;}_$AI(t,i=this,s,e){const h=this.strings;let o=!1;if(void 0===h)t=N(this,t,i,0),o=!c(t)||t!==this._$AH&&t!==w,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=N(this,e[s+n],i,n),r===w&&(r=this._$AH[n]),o||=!c(r)||r!==this._$AH[n],r===T?t=T:t!==T&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===T?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class k extends R{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===T?void 0:t;}}class H extends R{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==T);}}class I extends R{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=N(this,t,i,0)??T)===w)return;const s=this._$AH,e=t===T&&s!==T||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==T&&(s===T||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class L{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){N(this,t);}}const Z=t$1.litHtmlPolyfillSupport;Z?.(V,M),(t$1.litHtmlVersions??=[]).push("3.1.3");const j=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new M(i.insertBefore(l(),t),t,void 0,s??{});}return h._$AI(t),h};
233
+
234
+ /**
235
+ * @license
236
+ * Copyright 2017 Google LLC
237
+ * SPDX-License-Identifier: BSD-3-Clause
238
+ */class s extends b$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=j(i,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1);}render(){return w}}s._$litElement$=!0,s[("finalized")]=!0,globalThis.litElementHydrateSupport?.({LitElement:s});const r$2=globalThis.litElementPolyfillSupport;r$2?.({LitElement:s});(globalThis.litElementVersions??=[]).push("4.0.5");
239
+
240
+ /**
241
+ * @license
242
+ * Copyright 2017 Google LLC
243
+ * SPDX-License-Identifier: BSD-3-Clause
244
+ */
245
+ const t=t=>(e,o)=>{void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
246
+
247
+ /**
248
+ * @license
249
+ * Copyright 2017 Google LLC
250
+ * SPDX-License-Identifier: BSD-3-Clause
251
+ */const o={attribute:!0,type:String,converter:u$1,reflect:!1,hasChanged:f$1},r$1=(t=o,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.P(o,void 0,t),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r$1(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,r?{...t,wrapped:!0}:t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
252
+
253
+ /**
254
+ * @license
255
+ * Copyright 2017 Google LLC
256
+ * SPDX-License-Identifier: BSD-3-Clause
257
+ */function r(r){return n({...r,state:!0,attribute:!1})}
258
+
259
+ /**
260
+ * @license
261
+ * Copyright 2017 Google LLC
262
+ * SPDX-License-Identifier: BSD-3-Clause
263
+ */
264
+ const e$1=(e,t,c)=>(c.configurable=!0,c.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,c),c);
265
+
266
+ /**
267
+ * @license
268
+ * Copyright 2017 Google LLC
269
+ * SPDX-License-Identifier: BSD-3-Clause
270
+ */function e(e,r){return (n,s,i)=>{const o=t=>t.renderRoot?.querySelector(e)??null;if(r){const{get:e,set:r}="object"==typeof s?n:i??(()=>{const t=Symbol();return {get(){return this[t]},set(e){this[t]=e;}}})();return e$1(n,s,{get(){let t=e.call(this);return void 0===t&&(t=o(this),(null!==t||this.hasUpdated)&&r.call(this,t)),t}})}return e$1(n,s,{get(){return o(this)}})}}
271
+
272
+ const canLog = () => {
273
+ try {
274
+ return localStorage.getItem('edgeTagDebug') === '1';
275
+ }
276
+ catch {
277
+ return false;
278
+ }
279
+ };
280
+ const logger = {
281
+ log: (...args) => {
282
+ if (canLog()) {
283
+ console.log(...args);
284
+ }
285
+ },
286
+ error: (...args) => {
287
+ if (canLog()) {
288
+ console.error(...args);
289
+ }
290
+ },
291
+ info: (...args) => {
292
+ if (canLog()) {
293
+ console.info(...args);
294
+ }
295
+ },
296
+ trace: (...args) => {
297
+ if (canLog()) {
298
+ console.trace(...args);
299
+ }
300
+ },
301
+ table: (...args) => {
302
+ if (canLog()) {
303
+ console.table(...args);
304
+ }
305
+ },
306
+ dir: (...args) => {
307
+ if (canLog()) {
308
+ console.dir(...args);
309
+ }
310
+ },
311
+ };
312
+
313
+ const shopGPTStyles = () => i$2 `
314
+ :host {
315
+ position: fixed;
316
+ top: 0;
317
+ left: 0;
318
+ height: 100%;
319
+ width: 100%;
320
+ }
321
+
322
+ ::-webkit-scrollbar {
323
+ width: 20px;
324
+ }
325
+
326
+ ::-webkit-scrollbar-track {
327
+ background-color: transparent;
328
+ }
329
+
330
+ ::-webkit-scrollbar-thumb {
331
+ background-color: #d6dee1;
332
+ border-radius: 20px;
333
+ border: 6px solid transparent;
334
+ background-clip: content-box;
335
+ }
336
+
337
+ ::-webkit-scrollbar-thumb:hover {
338
+ background-color: #a8bbbf;
339
+ }
340
+
341
+ * {
342
+ box-sizing: border-box;
343
+ }
344
+
345
+ body {
346
+ font-family: Inter;
347
+ margin: 0;
348
+ padding: 0;
349
+ }
350
+
351
+ .container {
352
+ display: flex;
353
+ flex-direction: column;
354
+ overflow: hidden;
355
+ height: 100%;
356
+ background: #ffffff;
357
+ font-size: 16px;
358
+ font-style: normal;
359
+ font-weight: 400;
360
+ line-height: 21px;
361
+ }
362
+
363
+ .header {
364
+ display: flex;
365
+ justify-content: space-between;
366
+ align-items: center;
367
+ padding: 24px;
368
+ text-align: center;
369
+ border-bottom: 1px solid #d4d4d8;
370
+ height: 114px;
371
+
372
+ @media screen and (max-width: 430px) {
373
+ height: 68px;
374
+ padding: 16px;
375
+ }
376
+ }
377
+
378
+ .header-title,
379
+ .chat-header-title {
380
+ color: #000;
381
+ font-size: 20px;
382
+ font-weight: 700;
383
+ font-style: normal;
384
+ line-height: 28px;
385
+ text-align: left;
386
+ text-underline-position: from-font;
387
+ text-decoration-skip-ink: none;
388
+ margin: 0;
389
+ }
390
+
391
+ @media screen and (max-width: 430px) {
392
+ .header-title {
393
+ font-size: 16px;
394
+ line-height: 24px;
395
+ }
396
+
397
+ .product-content {
398
+ max-width: calc(100vw - 150px);
399
+ }
400
+ }
401
+
402
+ .loader {
403
+ display: flex;
404
+ flex: 1;
405
+ width: 100%;
406
+ height: 100%;
407
+ align-items: center;
408
+ justify-content: center;
409
+ z-index: 5000;
410
+
411
+ .spinner {
412
+ /* --webkit-animation: spin 1s linear infinite; */
413
+ animation: 1s linear infinite spin;
414
+ border-radius: 50%;
415
+ border: 5px solid #f9d5ba;
416
+ border-top: 5px solid #555;
417
+ width: 30px;
418
+ height: 30px;
419
+ margin: 10px;
420
+ }
421
+ }
422
+
423
+ @keyframes spin {
424
+ 0% {
425
+ transform: rotate(0deg);
426
+ }
427
+ 100% {
428
+ transform: rotate(360deg);
429
+ }
430
+ }
431
+
432
+ .header-sub-title,
433
+ .chat-header-sub-title {
434
+ color: #000;
435
+ font-size: 12px;
436
+ font-weight: 400;
437
+ font-style: normal;
438
+ line-height: 12px;
439
+ text-align: left;
440
+ text-underline-position: from-font;
441
+ text-decoration-skip-ink: none;
442
+ margin: 0;
443
+ }
444
+
445
+ .header-pre-alpha {
446
+ @media screen and (max-width: 768px) {
447
+ display: none;
448
+ }
449
+ }
450
+
451
+ .body {
452
+ display: flex;
453
+ flex: 1;
454
+
455
+ @media screen and (max-width: 430px) {
456
+ flex-direction: column;
457
+ justify-content: flex-end;
458
+ }
459
+ }
460
+
461
+ .products-section {
462
+ flex: 1 0 0;
463
+ display: flex;
464
+ flex-direction: column;
465
+ justify-content: center;
466
+ align-items: center;
467
+ gap: 1px;
468
+ border-right: 1px solid #d4d4d8;
469
+ background: #f5f3ee;
470
+
471
+ .product-section {
472
+ flex: 1;
473
+ padding: 24px;
474
+ width: 100%;
475
+
476
+ h2 {
477
+ color: #a49b94;
478
+ font-size: 18px;
479
+ font-weight: 700;
480
+ line-height: 24px;
481
+ text-transform: uppercase;
482
+ margin: 0 0 24px;
483
+ }
484
+
485
+ p.no-product-text {
486
+ color: #000;
487
+ font-size: 18px;
488
+ line-height: 24px;
489
+ opacity: 0.6;
490
+ }
491
+ }
492
+
493
+ .hidden {
494
+ display: none;
495
+ }
496
+
497
+ .show-more,
498
+ .show-less {
499
+ display: none;
500
+ margin: 16px 0;
501
+ color: #a49b94;
502
+ text-align: center;
503
+ font-size: 14px;
504
+ font-weight: 700;
505
+ line-height: 12px;
506
+ letter-spacing: -0.28px;
507
+ text-transform: uppercase;
508
+ }
509
+
510
+ @media screen and (max-width: 430px) {
511
+ flex: 0;
512
+ box-shadow: 0px 4px 6px -1px rgba(0, 0, 0, 0.1),
513
+ 0px 2px 4px -1px rgba(0, 0, 0, 0.06);
514
+ z-index: 1;
515
+
516
+ .product-section {
517
+ padding: 16px 16px 0;
518
+
519
+ h2 {
520
+ display: flex;
521
+ font-size: 12px;
522
+ font-weight: 700;
523
+ line-height: 18px;
524
+ letter-spacing: -0.36px;
525
+ margin: 0 0 16px;
526
+ color: #53433a;
527
+ align-items: center;
528
+ gap: 16px;
529
+
530
+ &::after {
531
+ content: '';
532
+ flex-grow: 1;
533
+ height: 1px;
534
+ background: #a49b94;
535
+ }
536
+ }
537
+
538
+ .no-products {
539
+ display: none;
540
+ }
541
+ }
542
+
543
+ .product-section.recommended-product h2 {
544
+ display: none;
545
+ }
546
+
547
+ .show-more,
548
+ .show-less {
549
+ display: block;
550
+ }
551
+ }
552
+ }
553
+
554
+ @media screen and (max-width: 430px) {
555
+ .no-recommended-product {
556
+ display: none;
557
+ }
558
+ }
559
+
560
+ .recommended-product {
561
+ border-bottom: 1px solid #d4d4d8;
562
+
563
+ .product {
564
+ display: flex;
565
+ gap: 12px;
566
+
567
+ /* .buy-now-btn {
568
+ cursor: pointer;
569
+ padding: 7px 37px;
570
+ background: #971b1b;
571
+ border-radius: 5px;
572
+ margin-top: 12px;
573
+ color: #ffffff;
574
+ font-size: 18px;
575
+ line-height: 24px;
576
+ letter-spacing: -0.35px;
577
+ border: 0;
578
+ } */
579
+
580
+ /* Replica of TrueClassic */
581
+ .buy-now-btn {
582
+ cursor: pointer;
583
+ padding: 7px 37px;
584
+ background: #53433a;
585
+ border-radius: 5px;
586
+ margin-top: 12px;
587
+ color: #ffffff;
588
+ font-size: 18px;
589
+ line-height: 24px;
590
+ letter-spacing: -0.35px;
591
+ border: 0;
592
+ text-transform: uppercase;
593
+
594
+ :hover {
595
+ background-color: #2e2520;
596
+ }
597
+
598
+ :active {
599
+ background-color: #0c0a09;
600
+ }
601
+ }
602
+
603
+ p {
604
+ margin: 0;
605
+ }
606
+
607
+ img {
608
+ cursor: pointer;
609
+ width: 170px;
610
+ height: 213px;
611
+ }
612
+
613
+ .product-name,
614
+ .product-variation-details {
615
+ cursor: pointer;
616
+ font-size: 16px;
617
+ line-height: 24px;
618
+ color: #3f3f46;
619
+ white-space: nowrap;
620
+ overflow: hidden;
621
+ text-overflow: ellipsis;
622
+ margin-bottom: 12px;
623
+ }
624
+ }
625
+
626
+ @media screen and (max-width: 430px) {
627
+ border-bottom: unset;
628
+
629
+ .product {
630
+ img {
631
+ height: 132px;
632
+ width: 106px;
633
+ }
634
+
635
+ .product-name,
636
+ .product-variation-details {
637
+ margin: 0;
638
+ }
639
+ }
640
+ }
641
+ }
642
+
643
+ .more-recommendations {
644
+ padding: 15px;
645
+
646
+ .products {
647
+ display: flex;
648
+ overflow: hidden;
649
+ justify-content: space-between;
650
+ align-items: center;
651
+ padding: 0 16px;
652
+ }
653
+
654
+ .product {
655
+ max-width: 140px;
656
+
657
+ p {
658
+ margin: 0;
659
+ }
660
+
661
+ .product-name,
662
+ .product-variation-details {
663
+ cursor: pointer;
664
+ color: #3f3f46;
665
+ font-size: 16px;
666
+ line-height: 24px;
667
+ white-space: nowrap;
668
+ overflow: hidden;
669
+ text-overflow: ellipsis;
670
+ }
671
+
672
+ img {
673
+ cursor: pointer;
674
+ width: 140px;
675
+ height: 175px;
676
+ }
677
+ }
678
+
679
+ @media screen and (max-width: 430px) {
680
+ display: none;
681
+
682
+ .products {
683
+ padding: 0px;
684
+ }
685
+
686
+ .product {
687
+ max-width: 108px;
688
+
689
+ .product-name,
690
+ .product-variation-details {
691
+ font-size: 12px;
692
+ line-height: 18px;
693
+ letter-spacing: -0.36px;
694
+ margin: 0;
695
+ }
696
+
697
+ img {
698
+ height: 133px;
699
+ width: 108px;
700
+ }
701
+ }
702
+ }
703
+ }
704
+
705
+ @media screen and (max-width: 430px) {
706
+ .show-more-sml {
707
+ display: block;
708
+ }
709
+ }
710
+
711
+ .product-prices {
712
+ display: flex;
713
+ gap: 0 8px;
714
+ line-height: 24px;
715
+ font-weight: 700;
716
+ font-size: 18px;
717
+ color: #000000;
718
+
719
+ .compared-at-price {
720
+ color: #a1a1aa;
721
+ text-decoration: line-through;
722
+ }
723
+
724
+ @media screen and (max-width: 430px) {
725
+ font-size: 14px;
726
+ line-height: 21px;
727
+ }
728
+ }
729
+
730
+ .chatbot-section {
731
+ flex: 1;
732
+ flex-direction: column;
733
+ padding: 10px 24px 24px;
734
+ background: #fff;
735
+ display: flex;
736
+ gap: 25px;
737
+ align-self: stretch;
738
+
739
+ @media screen and (max-width: 430px) {
740
+ padding: 10px 16px 16px;
741
+ gap: 16px;
742
+ }
743
+ }
744
+
745
+ .chat-header {
746
+ flex: 1;
747
+ display: flex;
748
+ flex-direction: column;
749
+ overflow-y: auto;
750
+ justify-content: flex-end;
751
+ }
752
+
753
+ .chat-window {
754
+ flex: 1;
755
+ display: flex;
756
+ flex-direction: column-reverse;
757
+ overflow-y: auto;
758
+ gap: 28px;
759
+ max-height: calc(100vh - 211px);
760
+
761
+ @media screen and (max-width: 430px) {
762
+ max-height: unset;
763
+ gap: 24px;
764
+ }
765
+ }
766
+
767
+ .chat-header {
768
+ align-items: center;
769
+
770
+ .chat-header-sub-title {
771
+ margin-bottom: 16px;
772
+ }
773
+
774
+ .chat-header-description {
775
+ text-align: center;
776
+ line-height: 24px;
777
+ }
778
+ }
779
+
780
+ .bot-message-container {
781
+ display: flex;
782
+ gap: 0 16px;
783
+ }
784
+
785
+ .message {
786
+ color: #18181b;
787
+ font-size: 16px;
788
+ }
789
+
790
+ .message.user {
791
+ padding: 8px 14px;
792
+ background: #f1f1f1;
793
+ align-self: flex-end;
794
+ max-width: 45%;
795
+ border-radius: 17.5px;
796
+ text-align: right;
797
+ letter-spacing: -0.32px;
798
+
799
+ @media screen and (max-width: 430px) {
800
+ max-width: 70%;
801
+ }
802
+ }
803
+
804
+ .message.bot {
805
+ align-self: flex-start;
806
+ max-width: 70%;
807
+
808
+ p {
809
+ margin: 0;
810
+ }
811
+
812
+ .product {
813
+ margin-top: 16px;
814
+ display: flex;
815
+ gap: 12px;
816
+
817
+ .product-name,
818
+ .product-variation-details {
819
+ cursor: pointer;
820
+ margin-bottom: 8px;
821
+ }
822
+
823
+ img {
824
+ cursor: pointer;
825
+ width: 75px;
826
+ height: 93px;
827
+ }
828
+
829
+ @media screen and (max-width: 430px) {
830
+ display: none;
831
+
832
+ .product-name,
833
+ .product-variation-details {
834
+ margin: 0;
835
+ }
836
+ }
837
+ }
838
+ }
839
+
840
+ .predefined-prompts {
841
+ margin: 24px 0;
842
+ display: flex;
843
+ align-items: start;
844
+ flex-wrap: wrap;
845
+ gap: 16px 8px;
846
+
847
+ button {
848
+ padding: 10px 16px;
849
+ cursor: pointer;
850
+ border-radius: 21px;
851
+ border: 1px solid #d4d4d8;
852
+ color: #8b2822;
853
+ background: #fff;
854
+ }
855
+ }
856
+
857
+ .chat-input {
858
+ display: flex;
859
+ align-items: center;
860
+
861
+ input {
862
+ flex: 1;
863
+ height: 48px;
864
+ padding: 11px 50px 11px 16px;
865
+ border-radius: 24px;
866
+ background: #f1f1f1;
867
+ border-style: none;
868
+ border: 0px;
869
+ font-size: 16px;
870
+
871
+ &:focus {
872
+ outline-width: 0;
873
+ box-shadow: 0 0 4px rgba(57, 123, 244, 0.5);
874
+ }
875
+
876
+ &::placeholder {
877
+ color: #52525b;
878
+ }
879
+ }
880
+
881
+ button {
882
+ cursor: pointer;
883
+ position: absolute;
884
+ right: 36px;
885
+ width: 30px;
886
+ height: 30px;
887
+ display: flex;
888
+ justify-content: center;
889
+ align-items: center;
890
+ border: 0px solid;
891
+ border-radius: 50%;
892
+ background: #8b2822;
893
+
894
+ &:disabled {
895
+ background: #808080;
896
+ }
897
+ }
898
+ }
899
+
900
+ input {
901
+ &:focus {
902
+ outline-width: 0;
903
+ }
904
+ }
905
+
906
+ button {
907
+ &:focus {
908
+ outline-style: none;
909
+ }
910
+
911
+ &:focus-visible {
912
+ outline-style: none;
913
+ }
914
+ }
915
+ `;
916
+
917
+ const sendFilledIcon = () => b `
918
+ <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
919
+ <g id="send--filled 1" clip-path="url(#clip0_11627_1046)">
920
+ <path id="Vector" d="M18.1564 9.44101L4.40636 2.56601C4.29859 2.51211 4.17754 2.49052 4.05778 2.50382C3.93803 2.51713 3.82467 2.56477 3.73136 2.64101C3.64225 2.71569 3.57574 2.81375 3.5393 2.92416C3.50287 3.03457 3.49795 3.15296 3.52511 3.26601L5.18136 9.37226H12.2501V10.6223H5.18136L3.50011 16.7098C3.47463 16.8042 3.47165 16.9032 3.49143 16.999C3.5112 17.0948 3.55317 17.1846 3.61396 17.2612C3.67475 17.3378 3.75267 17.399 3.84144 17.44C3.93022 17.481 4.02738 17.5006 4.12511 17.4973C4.22295 17.4967 4.31928 17.4731 4.40636 17.4285L18.1564 10.5535C18.2587 10.5011 18.3447 10.4214 18.4046 10.3232C18.4646 10.2251 18.4964 10.1123 18.4964 9.99726C18.4964 9.88223 18.4646 9.76943 18.4046 9.67129C18.3447 9.57314 18.2587 9.49346 18.1564 9.44101Z" fill="white"/>
921
+ </g>
922
+ <defs>
923
+ <clip-path id="clip0_11627_1046">
924
+ <rect width="20" height="20" fill="white"/>
925
+ </clip-path>
926
+ </defs>
927
+ </svg>
928
+ `;
929
+ const botIcon = () => b `
930
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
931
+ <circle cx="12" cy="12" r="12" fill="black"/>
932
+ <path d="M10.6465 7.71833L11.048 8.83333C11.494 10.0708 12.4685 11.0453 13.706 11.4913L14.821 11.8928C14.9215 11.9293 14.9215 12.0718 14.821 12.1078L13.706 12.5093C12.4685 12.9553 11.494 13.9298 11.048 15.1673L10.6465 16.2823C10.61 16.3828 10.4675 16.3828 10.4315 16.2823L10.03 15.1673C9.58402 13.9298 8.60952 12.9553 7.37202 12.5093L6.25702 12.1078C6.15652 12.0713 6.15652 11.9288 6.25702 11.8928L7.37202 11.4913C8.60952 11.0453 9.58402 10.0708 10.03 8.83333L10.4315 7.71833C10.4675 7.61733 10.61 7.61733 10.6465 7.71833Z" fill="white"/>
933
+ <path d="M15.6655 5.03863L15.869 5.60313C16.095 6.22963 16.5885 6.72313 17.215 6.94913L17.7795 7.15263C17.8305 7.17113 17.8305 7.24312 17.7795 7.26163L17.215 7.46513C16.5885 7.69113 16.095 8.18463 15.869 8.81113L15.6655 9.37563C15.647 9.42663 15.575 9.42663 15.5565 9.37563L15.353 8.81113C15.127 8.18463 14.6335 7.69113 14.007 7.46513L13.4425 7.26163C13.3915 7.24312 13.3915 7.17113 13.4425 7.15263L14.007 6.94913C14.6335 6.72313 15.127 6.22963 15.353 5.60313L15.5565 5.03863C15.575 4.98712 15.6475 4.98712 15.6655 5.03863Z" fill="white"/>
934
+ <path d="M15.6655 14.6242L15.869 15.1887C16.095 15.8152 16.5885 16.3087 17.215 16.5347L17.7795 16.7382C17.8305 16.7567 17.8305 16.8287 17.7795 16.8472L17.215 17.0507C16.5885 17.2767 16.095 17.7702 15.869 18.3967L15.6655 18.9612C15.647 19.0122 15.575 19.0122 15.5565 18.9612L15.353 18.3967C15.127 17.7702 14.6335 17.2767 14.007 17.0507L13.4425 16.8472C13.3915 16.8287 13.3915 16.7567 13.4425 16.7382L14.007 16.5347C14.6335 16.3087 15.127 15.8152 15.353 15.1887L15.5565 14.6242C15.575 14.5732 15.6475 14.5732 15.6655 14.6242Z" fill="white"/>
935
+ </svg>
936
+ `;
937
+
938
+ const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
939
+ const getImageProperties = (src) => {
940
+ const image = new URL(src);
941
+ const srcSet = IMAGE_WIDTHS.map((width) => {
942
+ image.searchParams.set('width', width.toString());
943
+ return `${image.toString()} ${width}w`;
944
+ });
945
+ return {
946
+ srcset: srcSet.join(', '),
947
+ sizes: '(min-width: 1200px) 140px, (min-width: 990px) 33%',
948
+ };
949
+ };
950
+ let ShopGPT = class ShopGPT extends s {
951
+ constructor() {
952
+ super(...arguments);
953
+ this.recommendedProduct = null;
954
+ this.moreRecommendations = [];
955
+ this.chatbotMessages = [];
956
+ this.userMessage = '';
957
+ this.isLoadingHistory = false;
958
+ this.isTyping = false;
959
+ this.isFailed = false;
960
+ this.showMore = false;
961
+ this.promptSuggestions = [];
962
+ this.submitQuery = (message) => {
963
+ if (!message) {
964
+ return;
965
+ }
966
+ this.isFailed = false;
967
+ return this.shopGPTAPI.processQuery(message);
968
+ };
969
+ this.onAddToCart = async (ev) => {
970
+ ev.preventDefault();
971
+ ev.stopPropagation();
972
+ await this.storeAPI
973
+ .addToCart({
974
+ quantity: 1,
975
+ productId: this.productId.value,
976
+ variantId: this.variantId.value,
977
+ })
978
+ .catch(logger.error);
979
+ };
980
+ }
981
+ connectedCallback() {
982
+ super.connectedCallback();
983
+ window.addEventListener('edgetag-initialized', async () => {
984
+ if (!this.shopGPTAPI) {
985
+ return;
986
+ }
987
+ await this.loadHistory();
988
+ });
989
+ }
990
+ async loadHistory() {
991
+ var _a, _b, _c;
992
+ try {
993
+ this.isLoadingHistory = true;
994
+ const data = await this.shopGPTAPI.fetchChatHistory();
995
+ this.chatbotMessages = data.map((message) => {
996
+ var _a;
997
+ return ({
998
+ message: message.message,
999
+ sender: message.sender,
1000
+ quantity: 1,
1001
+ product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
1002
+ });
1003
+ });
1004
+ if (((_a = data[0]) === null || _a === void 0 ? void 0 : _a.sender) === 'bot' && ((_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.length) > 0) {
1005
+ const products = data[0].products.map((product) => ({
1006
+ ...product,
1007
+ quantity: 1,
1008
+ }));
1009
+ this.recommendedProduct = products[0];
1010
+ this.moreRecommendations = products.slice(1, 4);
1011
+ }
1012
+ }
1013
+ catch (e) {
1014
+ logger.error(e);
1015
+ }
1016
+ finally {
1017
+ this.isLoadingHistory = false;
1018
+ }
1019
+ }
1020
+ redirect(url) {
1021
+ var _a;
1022
+ if (!url) {
1023
+ return;
1024
+ }
1025
+ (_a = open(url, '_blank')) === null || _a === void 0 ? void 0 : _a.focus();
1026
+ }
1027
+ scrollToBottom() {
1028
+ if (!this.chatWindowElement) {
1029
+ return;
1030
+ }
1031
+ this.chatWindowElement.scrollTo({
1032
+ top: this.chatWindowElement.scrollHeight,
1033
+ behavior: 'smooth',
1034
+ });
1035
+ }
1036
+ resetProductRecommendations() {
1037
+ this.recommendedProduct = null;
1038
+ this.moreRecommendations = [];
1039
+ }
1040
+ async sendMessageToServer(e, message) {
1041
+ e.preventDefault();
1042
+ e.stopPropagation();
1043
+ if (!message || this.isTyping || this.isLoadingHistory) {
1044
+ return;
1045
+ }
1046
+ try {
1047
+ this.chatbotMessages = [
1048
+ { sender: 'user', message: message },
1049
+ ...this.chatbotMessages,
1050
+ ];
1051
+ this.isTyping = true;
1052
+ this.userMessage = '';
1053
+ this.scrollToBottom();
1054
+ const reply = await this.submitQuery(message);
1055
+ if (!reply) {
1056
+ return;
1057
+ }
1058
+ this.chatbotMessages = [
1059
+ { sender: 'bot', message: reply.message, product: reply.products[0] },
1060
+ ...this.chatbotMessages,
1061
+ ];
1062
+ this.recommendedProduct = reply.products[0];
1063
+ this.moreRecommendations = reply.products.slice(1, 4);
1064
+ this.setChatWindowHeight();
1065
+ }
1066
+ catch (e) {
1067
+ logger.error(e);
1068
+ this.resetProductRecommendations();
1069
+ this.isFailed = true;
1070
+ }
1071
+ finally {
1072
+ this.isTyping = false;
1073
+ }
1074
+ }
1075
+ // TODO: ShopGPT - This needs to come from StoreAPI and should utilize Store SDK to figure out the currency
1076
+ getCurrencySymbol() {
1077
+ return '$';
1078
+ }
1079
+ handleShowMore(value) {
1080
+ if (!this.chatWindowElement) {
1081
+ return;
1082
+ }
1083
+ this.showMore = value;
1084
+ // dynamically add the maximum height when more products are shown
1085
+ const height = value ? 'calc(100vh - 580px' : 'calc(100vh - 351px)';
1086
+ this.chatWindowElement.style.maxHeight = height;
1087
+ }
1088
+ setChatWindowHeight() {
1089
+ if (!this.chatWindowElement) {
1090
+ return;
1091
+ }
1092
+ if (window.innerWidth < 430) {
1093
+ this.chatWindowElement.style.maxHeight = 'calc(100vh - 351px)';
1094
+ }
1095
+ else {
1096
+ this.chatWindowElement.style.maxHeight = 'calc(100vh - 221px)';
1097
+ }
1098
+ }
1099
+ render() {
1100
+ return x `
1101
+ <div class="container">
1102
+ <div class="header">
1103
+ <div>
1104
+ <h1 class="header-title">ShopGPT</h1>
1105
+ <p class="header-sub-title">powered by Blotout</p>
1106
+ </div>
1107
+ <div class="header-pre-alpha">Pre-Alpha Release v0.1</div>
1108
+ </div>
1109
+
1110
+ <div class="body">${this.productSection()} ${this.chatSection()}</div>
1111
+ </div>
1112
+ `;
1113
+ }
1114
+ productSection() {
1115
+ var _a;
1116
+ return x `
1117
+ <div
1118
+ class="products-section ${!this.recommendedProduct
1119
+ ? 'no-recommended-product'
1120
+ : ''}"
1121
+ >
1122
+ <div class="product-section recommended-product">
1123
+ <h2>Recommended product</h2>
1124
+ ${!((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.id)
1125
+ ? x `
1126
+ <p class="no-product-text">
1127
+ Enter what you’re looking for in the chat to get product
1128
+ results.
1129
+ </p>
1130
+ `
1131
+ : x `
1132
+ <div class="product">
1133
+ <img
1134
+ src=${this.recommendedProduct.image.url}
1135
+ alt=${this.recommendedProduct.image.alt}
1136
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1137
+ />
1138
+ <div class="product-content">
1139
+ <p
1140
+ class="product-name"
1141
+ title=${this.recommendedProduct.title}
1142
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1143
+ >
1144
+ ${this.recommendedProduct.title}
1145
+ </p>
1146
+ ${this.recommendedProduct.variants[0].selectedOptions.map((option) => x `
1147
+ <p class="product-variation-details">
1148
+ ${option.name}: ${option.value}
1149
+ </p>
1150
+ `)}
1151
+ <div class="product-prices">
1152
+ ${this.recommendedProduct.variants[0].comparedAtPrice &&
1153
+ this.recommendedProduct.variants[0].comparedAtPrice !==
1154
+ this.recommendedProduct.variants[0].price
1155
+ ? x `<p class="compared-at-price">
1156
+ ${this.getCurrencySymbol()}${this.recommendedProduct
1157
+ .variants[0].comparedAtPrice}
1158
+ </p>`
1159
+ : T}
1160
+ <p class="price">
1161
+ ${this.getCurrencySymbol()}${this.recommendedProduct
1162
+ .variants[0].price}
1163
+ </p>
1164
+ </div>
1165
+ <button
1166
+ class="buy-now-btn"
1167
+ @click=${() => { var _a; return this.redirect((_a = this.recommendedProduct) === null || _a === void 0 ? void 0 : _a.url); }}
1168
+ >
1169
+ Add To Cart
1170
+ </button>
1171
+ </div>
1172
+ </div>
1173
+ `}
1174
+ </div>
1175
+
1176
+ <div
1177
+ class="product-section more-recommendations ${this.showMore
1178
+ ? 'show-more-sml'
1179
+ : ''}"
1180
+ >
1181
+ <h2>More Recommendations</h2>
1182
+ ${this.moreRecommendations.length === 0
1183
+ ? x `
1184
+ <p class="no-product-text">
1185
+ Enter what you’re looking for in the chat to get product
1186
+ results.
1187
+ </p>
1188
+ `
1189
+ : x `<div class="products">
1190
+ ${this.moreRecommendations.map((product) => {
1191
+ const imageProperties = getImageProperties(product.image.url);
1192
+ return x `
1193
+ <div class="product">
1194
+ <img
1195
+ srcset=${imageProperties.srcset}
1196
+ sizes=${imageProperties.sizes}
1197
+ src=${product.image.url}
1198
+ alt=${product.image.alt}
1199
+ @click=${() => this.redirect(product.url)}
1200
+ />
1201
+ <p
1202
+ class="product-name"
1203
+ title=${product.title}
1204
+ @click=${() => this.redirect(product.url)}
1205
+ >
1206
+ ${product.title}
1207
+ </p>
1208
+ <div class="product-prices">
1209
+ ${product.variants[0].comparedAtPrice &&
1210
+ product.variants[0].comparedAtPrice !==
1211
+ product.variants[0].price
1212
+ ? x `<p class="compared-at-price">
1213
+ ${this.getCurrencySymbol()}${product.variants[0]
1214
+ .comparedAtPrice}
1215
+ </p>`
1216
+ : T}
1217
+ <p class="price">
1218
+ ${this.getCurrencySymbol()}${product.variants[0]
1219
+ .price}
1220
+ </p>
1221
+ </div>
1222
+ </div>
1223
+ `;
1224
+ })}
1225
+ </div>`}
1226
+ </div>
1227
+
1228
+ ${this.showMore
1229
+ ? x `
1230
+ <div class="show-less" @click=${() => this.handleShowMore(false)}>
1231
+ Show less
1232
+ </div>
1233
+ `
1234
+ : x `
1235
+ <div class="show-more" @click=${() => this.handleShowMore(true)}>
1236
+ Show more
1237
+ </div>
1238
+ `}
1239
+ </div>
1240
+ `;
1241
+ }
1242
+ chatWindow() {
1243
+ if (this.isLoadingHistory) {
1244
+ return x ` <div class="loader"><div class="spinner"></div></div> `;
1245
+ }
1246
+ if (this.chatbotMessages.length === 0) {
1247
+ return x `
1248
+ <div class="chat-header">
1249
+ <div class="chat-header-title">ShopGPT</div>
1250
+ <div class="chat-header-sub-title">powered by Blotout</div>
1251
+ <div class="chat-header-description">
1252
+ Hi, type a message to get started!
1253
+ </div>
1254
+ </div>
1255
+ `;
1256
+ }
1257
+ return x `
1258
+ <div class="chat-window">
1259
+ ${this.isTyping
1260
+ ? x `<div class="bot-message-container">
1261
+ ${botIcon()}
1262
+ <div class="message bot">Typing...</div>
1263
+ </div>`
1264
+ : ''}
1265
+ ${this.isFailed
1266
+ ? x `<div class="bot-message-container">
1267
+ ${botIcon()}
1268
+ <div class="message bot">
1269
+ Something went wrong please try again!
1270
+ </div>
1271
+ </div>`
1272
+ : ''}
1273
+ ${this.chatbotMessages.map((message) => {
1274
+ if (message.sender === 'bot') {
1275
+ return x `
1276
+ <div class="bot-message-container">
1277
+ ${botIcon()}
1278
+ <div class="message bot">
1279
+ <p>${message.message}</p>
1280
+ ${message.product
1281
+ ? x `<div class="product">
1282
+ <img
1283
+ src=${message.product.image.url}
1284
+ alt=${message.product.image.alt}
1285
+ @click=${() => { var _a; return this.redirect((_a = message.product) === null || _a === void 0 ? void 0 : _a.url); }}
1286
+ />
1287
+ <div>
1288
+ <p
1289
+ class="product-name"
1290
+ title=${message.product.title}
1291
+ @click=${() => { var _a; return this.redirect((_a = message.product) === null || _a === void 0 ? void 0 : _a.url); }}
1292
+ >
1293
+ ${message.product.title}
1294
+ </p>
1295
+ <div class="product-prices">
1296
+ ${message.product.variants[0].comparedAtPrice &&
1297
+ message.product.variants[0].comparedAtPrice !==
1298
+ message.product.variants[0].comparedAtPrice
1299
+ ? x `<p class="compared-at-price">
1300
+ ${this.getCurrencySymbol()}${message.product
1301
+ .variants[0].comparedAtPrice}
1302
+ </p>`
1303
+ : T}
1304
+ <p class="price">
1305
+ ${this.getCurrencySymbol()}${message.product
1306
+ .variants[0].price}
1307
+ </p>
1308
+ </div>
1309
+ </div>
1310
+ </div>`
1311
+ : T}
1312
+ </div>
1313
+ </div>
1314
+ `;
1315
+ }
1316
+ return x ` <div class="message user">${message.message}</div> `;
1317
+ })}
1318
+ </div>
1319
+ `;
1320
+ }
1321
+ predefinedPrompts() {
1322
+ // TODO: ShopGPT - Handle prompt clicks, should enable this when LLM supports it.
1323
+ return x `
1324
+ <div class="predefined-prompts" style="display:none;">
1325
+ ${this.promptSuggestions.map((prompt) => x ` <button>${prompt}</button> `)}
1326
+ </div>
1327
+ `;
1328
+ }
1329
+ chatSection() {
1330
+ return x `
1331
+ <div class="chatbot-section">
1332
+ ${this.chatWindow()} ${this.predefinedPrompts()}
1333
+ <form
1334
+ class="chat-input"
1335
+ @submit=${async (e) => { var _a; return await this.sendMessageToServer(e, (_a = this.userMessage) === null || _a === void 0 ? void 0 : _a.trim()); }}
1336
+ >
1337
+ <input
1338
+ type="text"
1339
+ .value=${this.userMessage}
1340
+ @input=${(e) => (this.userMessage = e.target.value)}
1341
+ placeholder="Type your message here"
1342
+ />
1343
+ <button
1344
+ type="submit"
1345
+ ?disabled=${this.isTyping || this.isLoadingHistory}
1346
+ >
1347
+ ${sendFilledIcon()}
1348
+ </button>
1349
+ </form>
1350
+ </div>
1351
+ `;
1352
+ }
1353
+ };
1354
+ ShopGPT.styles = [shopGPTStyles()];
1355
+ __decorate([
1356
+ n({ type: Object }),
1357
+ __metadata("design:type", Object)
1358
+ ], ShopGPT.prototype, "recommendedProduct", void 0);
1359
+ __decorate([
1360
+ n({ type: Array }),
1361
+ __metadata("design:type", Array)
1362
+ ], ShopGPT.prototype, "moreRecommendations", void 0);
1363
+ __decorate([
1364
+ r(),
1365
+ __metadata("design:type", Array)
1366
+ ], ShopGPT.prototype, "chatbotMessages", void 0);
1367
+ __decorate([
1368
+ r(),
1369
+ __metadata("design:type", Object)
1370
+ ], ShopGPT.prototype, "userMessage", void 0);
1371
+ __decorate([
1372
+ e('input[name=productId]'),
1373
+ __metadata("design:type", HTMLInputElement)
1374
+ ], ShopGPT.prototype, "productId", void 0);
1375
+ __decorate([
1376
+ e('input[name=variantId]'),
1377
+ __metadata("design:type", HTMLInputElement)
1378
+ ], ShopGPT.prototype, "variantId", void 0);
1379
+ __decorate([
1380
+ e('.chat-window'),
1381
+ __metadata("design:type", Object)
1382
+ ], ShopGPT.prototype, "chatWindowElement", void 0);
1383
+ __decorate([
1384
+ n({ type: Boolean }),
1385
+ __metadata("design:type", Boolean)
1386
+ ], ShopGPT.prototype, "isLoadingHistory", void 0);
1387
+ __decorate([
1388
+ n({ type: Boolean }),
1389
+ __metadata("design:type", Boolean)
1390
+ ], ShopGPT.prototype, "isTyping", void 0);
1391
+ __decorate([
1392
+ n({ type: Boolean }),
1393
+ __metadata("design:type", Boolean)
1394
+ ], ShopGPT.prototype, "isFailed", void 0);
1395
+ __decorate([
1396
+ n({ type: Boolean }),
1397
+ __metadata("design:type", Boolean)
1398
+ ], ShopGPT.prototype, "showMore", void 0);
1399
+ __decorate([
1400
+ r(),
1401
+ __metadata("design:type", Array)
1402
+ ], ShopGPT.prototype, "promptSuggestions", void 0);
1403
+ ShopGPT = __decorate([
1404
+ t('shop-gpt')
1405
+ ], ShopGPT);
1406
+
1407
+ var _a, _b;
1408
+ var _c;
1409
+ let shopGPT;
1410
+ if (typeof window != 'undefined' && typeof document != 'undefined') {
1411
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
1412
+ (_b = (_c = window[registryKey]).ui) !== null && _b !== void 0 ? _b : (_c.ui = {
1413
+ init(params) {
1414
+ if (shopGPT) {
1415
+ return;
1416
+ }
1417
+ shopGPT = document.createElement('shop-gpt');
1418
+ shopGPT.storeAPI = params.storeAPI;
1419
+ shopGPT.shopGPTAPI = params.shopGPTAPI;
1420
+ document.body.append(shopGPT);
1421
+ },
1422
+ });
1423
+ }
1424
+
1425
+ module.exports = data;