@blotoutio/providers-shop-gpt-sdk 0.68.2 → 0.70.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 +85 -56
- package/index.js +85 -56
- package/index.mjs +85 -56
- package/package.json +1 -1
- package/stores/shopify/index.cjs.js +7 -0
- package/stores/shopify/index.js +7 -0
- package/stores/shopify/index.mjs +7 -0
package/index.cjs.js
CHANGED
@@ -34,6 +34,12 @@ new Set([
|
|
34
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
35
|
]);
|
36
36
|
|
37
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
38
|
+
style: 'currency',
|
39
|
+
currency: currency || 'USD',
|
40
|
+
...options,
|
41
|
+
});
|
42
|
+
|
37
43
|
const packageName = 'shopGPT';
|
38
44
|
|
39
45
|
var _a$1;
|
@@ -63,11 +69,11 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
63
69
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
64
70
|
return url;
|
65
71
|
};
|
66
|
-
const processQuery = async (query) => {
|
72
|
+
const processQuery = async (query, productHandle) => {
|
67
73
|
const response = await fetchImpl(getURL('/query'), {
|
68
74
|
method: 'POST',
|
69
75
|
headers: getHeaders(),
|
70
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
76
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
71
77
|
credentials: 'include',
|
72
78
|
});
|
73
79
|
if (!response.ok) {
|
@@ -216,20 +222,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
216
222
|
* Copyright 2019 Google LLC
|
217
223
|
* SPDX-License-Identifier: BSD-3-Clause
|
218
224
|
*/
|
219
|
-
const t$
|
225
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.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$6&&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$3=(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$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?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
226
|
|
221
227
|
/**
|
222
228
|
* @license
|
223
229
|
* Copyright 2017 Google LLC
|
224
230
|
* SPDX-License-Identifier: BSD-3-Clause
|
225
|
-
*/const{is:i$
|
231
|
+
*/const{is:i$2,defineProperty:e$5,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$2(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$5(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
232
|
|
227
233
|
/**
|
228
234
|
* @license
|
229
235
|
* Copyright 2017 Google LLC
|
230
236
|
* SPDX-License-Identifier: BSD-3-Clause
|
231
237
|
*/
|
232
|
-
const t$
|
238
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$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$4+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$4)){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$1?i$1.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$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.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
239
|
|
234
240
|
/**
|
235
241
|
* @license
|
@@ -237,6 +243,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
237
243
|
* SPDX-License-Identifier: BSD-3-Clause
|
238
244
|
*/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
245
|
|
246
|
+
/**
|
247
|
+
* @license
|
248
|
+
* Copyright 2017 Google LLC
|
249
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
250
|
+
*/
|
251
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
252
|
+
|
253
|
+
/**
|
254
|
+
* @license
|
255
|
+
* Copyright 2018 Google LLC
|
256
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
257
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
258
|
+
|
240
259
|
/**
|
241
260
|
* @license
|
242
261
|
* Copyright 2017 Google LLC
|
@@ -277,40 +296,31 @@ const canLog = () => {
|
|
277
296
|
return false;
|
278
297
|
}
|
279
298
|
};
|
299
|
+
const prefix = `[EdgeTag]`;
|
280
300
|
const logger = {
|
281
301
|
log: (...args) => {
|
282
302
|
if (canLog()) {
|
283
|
-
console.log(...args);
|
303
|
+
console.log(prefix, ...args);
|
284
304
|
}
|
285
305
|
},
|
286
306
|
error: (...args) => {
|
287
307
|
if (canLog()) {
|
288
|
-
console.error(...args);
|
308
|
+
console.error(prefix, ...args);
|
289
309
|
}
|
290
310
|
},
|
291
311
|
info: (...args) => {
|
292
312
|
if (canLog()) {
|
293
|
-
console.info(...args);
|
313
|
+
console.info(prefix, ...args);
|
294
314
|
}
|
295
315
|
},
|
296
316
|
trace: (...args) => {
|
297
317
|
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);
|
318
|
+
console.trace(prefix, ...args);
|
309
319
|
}
|
310
320
|
},
|
311
321
|
};
|
312
322
|
|
313
|
-
const shopGPTStyles = () => i$
|
323
|
+
const shopGPTStyles = () => i$3 `
|
314
324
|
:host {
|
315
325
|
position: fixed;
|
316
326
|
top: 0;
|
@@ -858,6 +868,7 @@ const shopGPTStyles = () => i$2 `
|
|
858
868
|
.chat-input {
|
859
869
|
display: flex;
|
860
870
|
align-items: center;
|
871
|
+
margin: 0;
|
861
872
|
|
862
873
|
input {
|
863
874
|
flex: 1;
|
@@ -938,6 +949,9 @@ const botIcon = () => b `
|
|
938
949
|
|
939
950
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
940
951
|
const getImageProperties = (src) => {
|
952
|
+
if (!src) {
|
953
|
+
return;
|
954
|
+
}
|
941
955
|
const image = new URL(src);
|
942
956
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
943
957
|
image.searchParams.set('width', width.toString());
|
@@ -986,6 +1000,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
986
1000
|
return;
|
987
1001
|
}
|
988
1002
|
await this.loadHistory();
|
1003
|
+
await this.loadInitialQuery();
|
989
1004
|
});
|
990
1005
|
}
|
991
1006
|
async loadHistory() {
|
@@ -1018,6 +1033,31 @@ let ShopGPT = class ShopGPT extends s {
|
|
1018
1033
|
this.isLoadingHistory = false;
|
1019
1034
|
}
|
1020
1035
|
}
|
1036
|
+
async loadInitialQuery() {
|
1037
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1038
|
+
if (this.chatbotMessages.length) {
|
1039
|
+
return;
|
1040
|
+
}
|
1041
|
+
try {
|
1042
|
+
this.isTyping = true;
|
1043
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1044
|
+
this.chatbotMessages = [
|
1045
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1046
|
+
...this.chatbotMessages,
|
1047
|
+
];
|
1048
|
+
this.recommendedProduct = reply.products[0];
|
1049
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1050
|
+
this.setChatWindowHeight();
|
1051
|
+
}
|
1052
|
+
catch (error) {
|
1053
|
+
logger.error(error);
|
1054
|
+
this.resetProductRecommendations();
|
1055
|
+
this.isFailed = true;
|
1056
|
+
}
|
1057
|
+
finally {
|
1058
|
+
this.isTyping = false;
|
1059
|
+
}
|
1060
|
+
}
|
1021
1061
|
redirect(url) {
|
1022
1062
|
var _a;
|
1023
1063
|
if (!url) {
|
@@ -1073,9 +1113,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1073
1113
|
this.isTyping = false;
|
1074
1114
|
}
|
1075
1115
|
}
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1116
|
+
getLocalPrice(price) {
|
1117
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1118
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1119
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1079
1120
|
}
|
1080
1121
|
handleShowMore(value) {
|
1081
1122
|
if (!this.chatWindowElement) {
|
@@ -1120,9 +1161,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1120
1161
|
var _a;
|
1121
1162
|
return x `
|
1122
1163
|
<div
|
1123
|
-
class
|
1124
|
-
|
1125
|
-
:
|
1164
|
+
class=${e$2({
|
1165
|
+
'products-section': true,
|
1166
|
+
'no-recommended-product': !this.recommendedProduct,
|
1167
|
+
})}
|
1126
1168
|
>
|
1127
1169
|
<div class="product-section recommended-product">
|
1128
1170
|
<h2>Recommended product</h2>
|
@@ -1158,13 +1200,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1158
1200
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1159
1201
|
this.recommendedProduct.variants[0].price
|
1160
1202
|
? x `<p class="compared-at-price">
|
1161
|
-
${this.
|
1162
|
-
.
|
1203
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1204
|
+
.comparedAtPrice)}
|
1163
1205
|
</p>`
|
1164
1206
|
: T}
|
1165
1207
|
<p class="price">
|
1166
|
-
${this.
|
1167
|
-
.variants[0].price}
|
1208
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1168
1209
|
</p>
|
1169
1210
|
</div>
|
1170
1211
|
<button
|
@@ -1179,9 +1220,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1179
1220
|
</div>
|
1180
1221
|
|
1181
1222
|
<div
|
1182
|
-
class
|
1183
|
-
|
1184
|
-
:
|
1223
|
+
class=${e$2({
|
1224
|
+
'product-section': true,
|
1225
|
+
'more-recommendations': true,
|
1226
|
+
'show-more-sml': this.showMore,
|
1227
|
+
})}
|
1185
1228
|
>
|
1186
1229
|
<h2>More Recommendations</h2>
|
1187
1230
|
${this.moreRecommendations.length === 0
|
@@ -1193,12 +1236,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1193
1236
|
`
|
1194
1237
|
: x `<div class="products">
|
1195
1238
|
${this.moreRecommendations.map((product) => {
|
1196
|
-
|
1239
|
+
var _a, _b, _c;
|
1240
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1197
1241
|
return x `
|
1198
1242
|
<div class="product">
|
1199
1243
|
<img
|
1200
|
-
srcset=${imageProperties.srcset}
|
1201
|
-
sizes=${imageProperties.sizes}
|
1244
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1245
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1202
1246
|
src=${product.image.url}
|
1203
1247
|
alt=${product.image.alt}
|
1204
1248
|
@click=${() => this.redirect(product.url)}
|
@@ -1215,13 +1259,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1215
1259
|
product.variants[0].comparedAtPrice !==
|
1216
1260
|
product.variants[0].price
|
1217
1261
|
? x `<p class="compared-at-price">
|
1218
|
-
${this.
|
1219
|
-
.comparedAtPrice}
|
1262
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1220
1263
|
</p>`
|
1221
1264
|
: T}
|
1222
1265
|
<p class="price">
|
1223
|
-
${this.
|
1224
|
-
.price}
|
1266
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1225
1267
|
</p>
|
1226
1268
|
</div>
|
1227
1269
|
</div>
|
@@ -1248,17 +1290,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1248
1290
|
if (this.isLoadingHistory) {
|
1249
1291
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1250
1292
|
}
|
1251
|
-
if (this.chatbotMessages.length === 0) {
|
1252
|
-
return x `
|
1253
|
-
<div class="chat-header">
|
1254
|
-
<div class="chat-header-title">ShopGPT</div>
|
1255
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1256
|
-
<div class="chat-header-description">
|
1257
|
-
Hi, type a message to get started!
|
1258
|
-
</div>
|
1259
|
-
</div>
|
1260
|
-
`;
|
1261
|
-
}
|
1262
1293
|
return x `
|
1263
1294
|
<div class="chat-window">
|
1264
1295
|
${this.isTyping
|
@@ -1281,7 +1312,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1281
1312
|
<div class="bot-message-container">
|
1282
1313
|
${botIcon()}
|
1283
1314
|
<div class="message bot">
|
1284
|
-
|
1315
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1285
1316
|
${message.product
|
1286
1317
|
? x `<div class="product">
|
1287
1318
|
<img
|
@@ -1302,13 +1333,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1302
1333
|
message.product.variants[0].comparedAtPrice !==
|
1303
1334
|
message.product.variants[0].comparedAtPrice
|
1304
1335
|
? x `<p class="compared-at-price">
|
1305
|
-
${this.
|
1306
|
-
.variants[0].comparedAtPrice}
|
1336
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1307
1337
|
</p>`
|
1308
1338
|
: T}
|
1309
1339
|
<p class="price">
|
1310
|
-
${this.
|
1311
|
-
.variants[0].price}
|
1340
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1312
1341
|
</p>
|
1313
1342
|
</div>
|
1314
1343
|
</div>
|
package/index.js
CHANGED
@@ -35,6 +35,12 @@ var ProvidersShopGptSdk = (function () {
|
|
35
35
|
...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'),
|
36
36
|
]);
|
37
37
|
|
38
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
39
|
+
style: 'currency',
|
40
|
+
currency: currency || 'USD',
|
41
|
+
...options,
|
42
|
+
});
|
43
|
+
|
38
44
|
const packageName = 'shopGPT';
|
39
45
|
|
40
46
|
var _a$1;
|
@@ -64,11 +70,11 @@ var ProvidersShopGptSdk = (function () {
|
|
64
70
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
65
71
|
return url;
|
66
72
|
};
|
67
|
-
const processQuery = async (query) => {
|
73
|
+
const processQuery = async (query, productHandle) => {
|
68
74
|
const response = await fetchImpl(getURL('/query'), {
|
69
75
|
method: 'POST',
|
70
76
|
headers: getHeaders(),
|
71
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
77
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
72
78
|
credentials: 'include',
|
73
79
|
});
|
74
80
|
if (!response.ok) {
|
@@ -217,20 +223,20 @@ var ProvidersShopGptSdk = (function () {
|
|
217
223
|
* Copyright 2019 Google LLC
|
218
224
|
* SPDX-License-Identifier: BSD-3-Clause
|
219
225
|
*/
|
220
|
-
const t$
|
226
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.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$6&&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$3=(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$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
|
221
227
|
|
222
228
|
/**
|
223
229
|
* @license
|
224
230
|
* Copyright 2017 Google LLC
|
225
231
|
* SPDX-License-Identifier: BSD-3-Clause
|
226
|
-
*/const{is:i$
|
232
|
+
*/const{is:i$2,defineProperty:e$5,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$2(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$5(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");
|
227
233
|
|
228
234
|
/**
|
229
235
|
* @license
|
230
236
|
* Copyright 2017 Google LLC
|
231
237
|
* SPDX-License-Identifier: BSD-3-Clause
|
232
238
|
*/
|
233
|
-
const t$
|
239
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$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$4+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$4)){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$1?i$1.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$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.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};
|
234
240
|
|
235
241
|
/**
|
236
242
|
* @license
|
@@ -238,6 +244,19 @@ var ProvidersShopGptSdk = (function () {
|
|
238
244
|
* SPDX-License-Identifier: BSD-3-Clause
|
239
245
|
*/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");
|
240
246
|
|
247
|
+
/**
|
248
|
+
* @license
|
249
|
+
* Copyright 2017 Google LLC
|
250
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
251
|
+
*/
|
252
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* @license
|
256
|
+
* Copyright 2018 Google LLC
|
257
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
258
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
259
|
+
|
241
260
|
/**
|
242
261
|
* @license
|
243
262
|
* Copyright 2017 Google LLC
|
@@ -278,40 +297,31 @@ var ProvidersShopGptSdk = (function () {
|
|
278
297
|
return false;
|
279
298
|
}
|
280
299
|
};
|
300
|
+
const prefix = `[EdgeTag]`;
|
281
301
|
const logger = {
|
282
302
|
log: (...args) => {
|
283
303
|
if (canLog()) {
|
284
|
-
console.log(...args);
|
304
|
+
console.log(prefix, ...args);
|
285
305
|
}
|
286
306
|
},
|
287
307
|
error: (...args) => {
|
288
308
|
if (canLog()) {
|
289
|
-
console.error(...args);
|
309
|
+
console.error(prefix, ...args);
|
290
310
|
}
|
291
311
|
},
|
292
312
|
info: (...args) => {
|
293
313
|
if (canLog()) {
|
294
|
-
console.info(...args);
|
314
|
+
console.info(prefix, ...args);
|
295
315
|
}
|
296
316
|
},
|
297
317
|
trace: (...args) => {
|
298
318
|
if (canLog()) {
|
299
|
-
console.trace(...args);
|
300
|
-
}
|
301
|
-
},
|
302
|
-
table: (...args) => {
|
303
|
-
if (canLog()) {
|
304
|
-
console.table(...args);
|
305
|
-
}
|
306
|
-
},
|
307
|
-
dir: (...args) => {
|
308
|
-
if (canLog()) {
|
309
|
-
console.dir(...args);
|
319
|
+
console.trace(prefix, ...args);
|
310
320
|
}
|
311
321
|
},
|
312
322
|
};
|
313
323
|
|
314
|
-
const shopGPTStyles = () => i$
|
324
|
+
const shopGPTStyles = () => i$3 `
|
315
325
|
:host {
|
316
326
|
position: fixed;
|
317
327
|
top: 0;
|
@@ -859,6 +869,7 @@ var ProvidersShopGptSdk = (function () {
|
|
859
869
|
.chat-input {
|
860
870
|
display: flex;
|
861
871
|
align-items: center;
|
872
|
+
margin: 0;
|
862
873
|
|
863
874
|
input {
|
864
875
|
flex: 1;
|
@@ -939,6 +950,9 @@ var ProvidersShopGptSdk = (function () {
|
|
939
950
|
|
940
951
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
941
952
|
const getImageProperties = (src) => {
|
953
|
+
if (!src) {
|
954
|
+
return;
|
955
|
+
}
|
942
956
|
const image = new URL(src);
|
943
957
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
944
958
|
image.searchParams.set('width', width.toString());
|
@@ -987,6 +1001,7 @@ var ProvidersShopGptSdk = (function () {
|
|
987
1001
|
return;
|
988
1002
|
}
|
989
1003
|
await this.loadHistory();
|
1004
|
+
await this.loadInitialQuery();
|
990
1005
|
});
|
991
1006
|
}
|
992
1007
|
async loadHistory() {
|
@@ -1019,6 +1034,31 @@ var ProvidersShopGptSdk = (function () {
|
|
1019
1034
|
this.isLoadingHistory = false;
|
1020
1035
|
}
|
1021
1036
|
}
|
1037
|
+
async loadInitialQuery() {
|
1038
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1039
|
+
if (this.chatbotMessages.length) {
|
1040
|
+
return;
|
1041
|
+
}
|
1042
|
+
try {
|
1043
|
+
this.isTyping = true;
|
1044
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1045
|
+
this.chatbotMessages = [
|
1046
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1047
|
+
...this.chatbotMessages,
|
1048
|
+
];
|
1049
|
+
this.recommendedProduct = reply.products[0];
|
1050
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1051
|
+
this.setChatWindowHeight();
|
1052
|
+
}
|
1053
|
+
catch (error) {
|
1054
|
+
logger.error(error);
|
1055
|
+
this.resetProductRecommendations();
|
1056
|
+
this.isFailed = true;
|
1057
|
+
}
|
1058
|
+
finally {
|
1059
|
+
this.isTyping = false;
|
1060
|
+
}
|
1061
|
+
}
|
1022
1062
|
redirect(url) {
|
1023
1063
|
var _a;
|
1024
1064
|
if (!url) {
|
@@ -1074,9 +1114,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1074
1114
|
this.isTyping = false;
|
1075
1115
|
}
|
1076
1116
|
}
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1117
|
+
getLocalPrice(price) {
|
1118
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1119
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1120
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1080
1121
|
}
|
1081
1122
|
handleShowMore(value) {
|
1082
1123
|
if (!this.chatWindowElement) {
|
@@ -1121,9 +1162,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1121
1162
|
var _a;
|
1122
1163
|
return x `
|
1123
1164
|
<div
|
1124
|
-
class
|
1125
|
-
|
1126
|
-
:
|
1165
|
+
class=${e$2({
|
1166
|
+
'products-section': true,
|
1167
|
+
'no-recommended-product': !this.recommendedProduct,
|
1168
|
+
})}
|
1127
1169
|
>
|
1128
1170
|
<div class="product-section recommended-product">
|
1129
1171
|
<h2>Recommended product</h2>
|
@@ -1159,13 +1201,12 @@ var ProvidersShopGptSdk = (function () {
|
|
1159
1201
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1160
1202
|
this.recommendedProduct.variants[0].price
|
1161
1203
|
? x `<p class="compared-at-price">
|
1162
|
-
${this.
|
1163
|
-
.
|
1204
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1205
|
+
.comparedAtPrice)}
|
1164
1206
|
</p>`
|
1165
1207
|
: T}
|
1166
1208
|
<p class="price">
|
1167
|
-
${this.
|
1168
|
-
.variants[0].price}
|
1209
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1169
1210
|
</p>
|
1170
1211
|
</div>
|
1171
1212
|
<button
|
@@ -1180,9 +1221,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1180
1221
|
</div>
|
1181
1222
|
|
1182
1223
|
<div
|
1183
|
-
class
|
1184
|
-
|
1185
|
-
:
|
1224
|
+
class=${e$2({
|
1225
|
+
'product-section': true,
|
1226
|
+
'more-recommendations': true,
|
1227
|
+
'show-more-sml': this.showMore,
|
1228
|
+
})}
|
1186
1229
|
>
|
1187
1230
|
<h2>More Recommendations</h2>
|
1188
1231
|
${this.moreRecommendations.length === 0
|
@@ -1194,12 +1237,13 @@ var ProvidersShopGptSdk = (function () {
|
|
1194
1237
|
`
|
1195
1238
|
: x `<div class="products">
|
1196
1239
|
${this.moreRecommendations.map((product) => {
|
1197
|
-
|
1240
|
+
var _a, _b, _c;
|
1241
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1198
1242
|
return x `
|
1199
1243
|
<div class="product">
|
1200
1244
|
<img
|
1201
|
-
srcset=${imageProperties.srcset}
|
1202
|
-
sizes=${imageProperties.sizes}
|
1245
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1246
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1203
1247
|
src=${product.image.url}
|
1204
1248
|
alt=${product.image.alt}
|
1205
1249
|
@click=${() => this.redirect(product.url)}
|
@@ -1216,13 +1260,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1216
1260
|
product.variants[0].comparedAtPrice !==
|
1217
1261
|
product.variants[0].price
|
1218
1262
|
? x `<p class="compared-at-price">
|
1219
|
-
${this.
|
1220
|
-
.comparedAtPrice}
|
1263
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1221
1264
|
</p>`
|
1222
1265
|
: T}
|
1223
1266
|
<p class="price">
|
1224
|
-
${this.
|
1225
|
-
.price}
|
1267
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1226
1268
|
</p>
|
1227
1269
|
</div>
|
1228
1270
|
</div>
|
@@ -1249,17 +1291,6 @@ var ProvidersShopGptSdk = (function () {
|
|
1249
1291
|
if (this.isLoadingHistory) {
|
1250
1292
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1251
1293
|
}
|
1252
|
-
if (this.chatbotMessages.length === 0) {
|
1253
|
-
return x `
|
1254
|
-
<div class="chat-header">
|
1255
|
-
<div class="chat-header-title">ShopGPT</div>
|
1256
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1257
|
-
<div class="chat-header-description">
|
1258
|
-
Hi, type a message to get started!
|
1259
|
-
</div>
|
1260
|
-
</div>
|
1261
|
-
`;
|
1262
|
-
}
|
1263
1294
|
return x `
|
1264
1295
|
<div class="chat-window">
|
1265
1296
|
${this.isTyping
|
@@ -1282,7 +1313,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1282
1313
|
<div class="bot-message-container">
|
1283
1314
|
${botIcon()}
|
1284
1315
|
<div class="message bot">
|
1285
|
-
|
1316
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1286
1317
|
${message.product
|
1287
1318
|
? x `<div class="product">
|
1288
1319
|
<img
|
@@ -1303,13 +1334,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1303
1334
|
message.product.variants[0].comparedAtPrice !==
|
1304
1335
|
message.product.variants[0].comparedAtPrice
|
1305
1336
|
? x `<p class="compared-at-price">
|
1306
|
-
${this.
|
1307
|
-
.variants[0].comparedAtPrice}
|
1337
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1308
1338
|
</p>`
|
1309
1339
|
: T}
|
1310
1340
|
<p class="price">
|
1311
|
-
${this.
|
1312
|
-
.variants[0].price}
|
1341
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1313
1342
|
</p>
|
1314
1343
|
</div>
|
1315
1344
|
</div>
|
package/index.mjs
CHANGED
@@ -32,6 +32,12 @@ new Set([
|
|
32
32
|
...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'),
|
33
33
|
]);
|
34
34
|
|
35
|
+
const formatMoney = (n, currency, options) => n.toLocaleString('en-US', {
|
36
|
+
style: 'currency',
|
37
|
+
currency: currency || 'USD',
|
38
|
+
...options,
|
39
|
+
});
|
40
|
+
|
35
41
|
const packageName = 'shopGPT';
|
36
42
|
|
37
43
|
var _a$1;
|
@@ -61,11 +67,11 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
61
67
|
const url = new URL(`/providers/shopGPT${path}`, baseURL);
|
62
68
|
return url;
|
63
69
|
};
|
64
|
-
const processQuery = async (query) => {
|
70
|
+
const processQuery = async (query, productHandle) => {
|
65
71
|
const response = await fetchImpl(getURL('/query'), {
|
66
72
|
method: 'POST',
|
67
73
|
headers: getHeaders(),
|
68
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
74
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
69
75
|
credentials: 'include',
|
70
76
|
});
|
71
77
|
if (!response.ok) {
|
@@ -214,20 +220,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
214
220
|
* Copyright 2019 Google LLC
|
215
221
|
* SPDX-License-Identifier: BSD-3-Clause
|
216
222
|
*/
|
217
|
-
const t$
|
223
|
+
const t$3=globalThis,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.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$6&&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$3=(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$6)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$3.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$5(e)})(t):t;
|
218
224
|
|
219
225
|
/**
|
220
226
|
* @license
|
221
227
|
* Copyright 2017 Google LLC
|
222
228
|
* SPDX-License-Identifier: BSD-3-Clause
|
223
|
-
*/const{is:i$
|
229
|
+
*/const{is:i$2,defineProperty:e$5,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$2(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$5(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");
|
224
230
|
|
225
231
|
/**
|
226
232
|
* @license
|
227
233
|
* Copyright 2017 Google LLC
|
228
234
|
* SPDX-License-Identifier: BSD-3-Clause
|
229
235
|
*/
|
230
|
-
const t$
|
236
|
+
const t$2=globalThis,i$1=t$2.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$4="$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$4+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$4)){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$1?i$1.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$2.litHtmlPolyfillSupport;Z?.(V,M),(t$2.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};
|
231
237
|
|
232
238
|
/**
|
233
239
|
* @license
|
@@ -235,6 +241,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
235
241
|
* SPDX-License-Identifier: BSD-3-Clause
|
236
242
|
*/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");
|
237
243
|
|
244
|
+
/**
|
245
|
+
* @license
|
246
|
+
* Copyright 2017 Google LLC
|
247
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
248
|
+
*/
|
249
|
+
const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},e$3=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* @license
|
253
|
+
* Copyright 2018 Google LLC
|
254
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
255
|
+
*/const e$2=e$3(class extends i{constructor(t){if(super(t),t.type!==t$1.ATTRIBUTE||"class"!==t.name||t.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return w}});
|
256
|
+
|
238
257
|
/**
|
239
258
|
* @license
|
240
259
|
* Copyright 2017 Google LLC
|
@@ -275,40 +294,31 @@ const canLog = () => {
|
|
275
294
|
return false;
|
276
295
|
}
|
277
296
|
};
|
297
|
+
const prefix = `[EdgeTag]`;
|
278
298
|
const logger = {
|
279
299
|
log: (...args) => {
|
280
300
|
if (canLog()) {
|
281
|
-
console.log(...args);
|
301
|
+
console.log(prefix, ...args);
|
282
302
|
}
|
283
303
|
},
|
284
304
|
error: (...args) => {
|
285
305
|
if (canLog()) {
|
286
|
-
console.error(...args);
|
306
|
+
console.error(prefix, ...args);
|
287
307
|
}
|
288
308
|
},
|
289
309
|
info: (...args) => {
|
290
310
|
if (canLog()) {
|
291
|
-
console.info(...args);
|
311
|
+
console.info(prefix, ...args);
|
292
312
|
}
|
293
313
|
},
|
294
314
|
trace: (...args) => {
|
295
315
|
if (canLog()) {
|
296
|
-
console.trace(...args);
|
297
|
-
}
|
298
|
-
},
|
299
|
-
table: (...args) => {
|
300
|
-
if (canLog()) {
|
301
|
-
console.table(...args);
|
302
|
-
}
|
303
|
-
},
|
304
|
-
dir: (...args) => {
|
305
|
-
if (canLog()) {
|
306
|
-
console.dir(...args);
|
316
|
+
console.trace(prefix, ...args);
|
307
317
|
}
|
308
318
|
},
|
309
319
|
};
|
310
320
|
|
311
|
-
const shopGPTStyles = () => i$
|
321
|
+
const shopGPTStyles = () => i$3 `
|
312
322
|
:host {
|
313
323
|
position: fixed;
|
314
324
|
top: 0;
|
@@ -856,6 +866,7 @@ const shopGPTStyles = () => i$2 `
|
|
856
866
|
.chat-input {
|
857
867
|
display: flex;
|
858
868
|
align-items: center;
|
869
|
+
margin: 0;
|
859
870
|
|
860
871
|
input {
|
861
872
|
flex: 1;
|
@@ -936,6 +947,9 @@ const botIcon = () => b `
|
|
936
947
|
|
937
948
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
938
949
|
const getImageProperties = (src) => {
|
950
|
+
if (!src) {
|
951
|
+
return;
|
952
|
+
}
|
939
953
|
const image = new URL(src);
|
940
954
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
941
955
|
image.searchParams.set('width', width.toString());
|
@@ -984,6 +998,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
984
998
|
return;
|
985
999
|
}
|
986
1000
|
await this.loadHistory();
|
1001
|
+
await this.loadInitialQuery();
|
987
1002
|
});
|
988
1003
|
}
|
989
1004
|
async loadHistory() {
|
@@ -1016,6 +1031,31 @@ let ShopGPT = class ShopGPT extends s {
|
|
1016
1031
|
this.isLoadingHistory = false;
|
1017
1032
|
}
|
1018
1033
|
}
|
1034
|
+
async loadInitialQuery() {
|
1035
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1036
|
+
if (this.chatbotMessages.length) {
|
1037
|
+
return;
|
1038
|
+
}
|
1039
|
+
try {
|
1040
|
+
this.isTyping = true;
|
1041
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1042
|
+
this.chatbotMessages = [
|
1043
|
+
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1044
|
+
...this.chatbotMessages,
|
1045
|
+
];
|
1046
|
+
this.recommendedProduct = reply.products[0];
|
1047
|
+
this.moreRecommendations = reply.products.slice(1, 4);
|
1048
|
+
this.setChatWindowHeight();
|
1049
|
+
}
|
1050
|
+
catch (error) {
|
1051
|
+
logger.error(error);
|
1052
|
+
this.resetProductRecommendations();
|
1053
|
+
this.isFailed = true;
|
1054
|
+
}
|
1055
|
+
finally {
|
1056
|
+
this.isTyping = false;
|
1057
|
+
}
|
1058
|
+
}
|
1019
1059
|
redirect(url) {
|
1020
1060
|
var _a;
|
1021
1061
|
if (!url) {
|
@@ -1071,9 +1111,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1071
1111
|
this.isTyping = false;
|
1072
1112
|
}
|
1073
1113
|
}
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1114
|
+
getLocalPrice(price) {
|
1115
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1116
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1117
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1077
1118
|
}
|
1078
1119
|
handleShowMore(value) {
|
1079
1120
|
if (!this.chatWindowElement) {
|
@@ -1118,9 +1159,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1118
1159
|
var _a;
|
1119
1160
|
return x `
|
1120
1161
|
<div
|
1121
|
-
class
|
1122
|
-
|
1123
|
-
:
|
1162
|
+
class=${e$2({
|
1163
|
+
'products-section': true,
|
1164
|
+
'no-recommended-product': !this.recommendedProduct,
|
1165
|
+
})}
|
1124
1166
|
>
|
1125
1167
|
<div class="product-section recommended-product">
|
1126
1168
|
<h2>Recommended product</h2>
|
@@ -1156,13 +1198,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1156
1198
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1157
1199
|
this.recommendedProduct.variants[0].price
|
1158
1200
|
? x `<p class="compared-at-price">
|
1159
|
-
${this.
|
1160
|
-
.
|
1201
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1202
|
+
.comparedAtPrice)}
|
1161
1203
|
</p>`
|
1162
1204
|
: T}
|
1163
1205
|
<p class="price">
|
1164
|
-
${this.
|
1165
|
-
.variants[0].price}
|
1206
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1166
1207
|
</p>
|
1167
1208
|
</div>
|
1168
1209
|
<button
|
@@ -1177,9 +1218,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1177
1218
|
</div>
|
1178
1219
|
|
1179
1220
|
<div
|
1180
|
-
class
|
1181
|
-
|
1182
|
-
:
|
1221
|
+
class=${e$2({
|
1222
|
+
'product-section': true,
|
1223
|
+
'more-recommendations': true,
|
1224
|
+
'show-more-sml': this.showMore,
|
1225
|
+
})}
|
1183
1226
|
>
|
1184
1227
|
<h2>More Recommendations</h2>
|
1185
1228
|
${this.moreRecommendations.length === 0
|
@@ -1191,12 +1234,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1191
1234
|
`
|
1192
1235
|
: x `<div class="products">
|
1193
1236
|
${this.moreRecommendations.map((product) => {
|
1194
|
-
|
1237
|
+
var _a, _b, _c;
|
1238
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1195
1239
|
return x `
|
1196
1240
|
<div class="product">
|
1197
1241
|
<img
|
1198
|
-
srcset=${imageProperties.srcset}
|
1199
|
-
sizes=${imageProperties.sizes}
|
1242
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1243
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1200
1244
|
src=${product.image.url}
|
1201
1245
|
alt=${product.image.alt}
|
1202
1246
|
@click=${() => this.redirect(product.url)}
|
@@ -1213,13 +1257,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1213
1257
|
product.variants[0].comparedAtPrice !==
|
1214
1258
|
product.variants[0].price
|
1215
1259
|
? x `<p class="compared-at-price">
|
1216
|
-
${this.
|
1217
|
-
.comparedAtPrice}
|
1260
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1218
1261
|
</p>`
|
1219
1262
|
: T}
|
1220
1263
|
<p class="price">
|
1221
|
-
${this.
|
1222
|
-
.price}
|
1264
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1223
1265
|
</p>
|
1224
1266
|
</div>
|
1225
1267
|
</div>
|
@@ -1246,17 +1288,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1246
1288
|
if (this.isLoadingHistory) {
|
1247
1289
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1248
1290
|
}
|
1249
|
-
if (this.chatbotMessages.length === 0) {
|
1250
|
-
return x `
|
1251
|
-
<div class="chat-header">
|
1252
|
-
<div class="chat-header-title">ShopGPT</div>
|
1253
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1254
|
-
<div class="chat-header-description">
|
1255
|
-
Hi, type a message to get started!
|
1256
|
-
</div>
|
1257
|
-
</div>
|
1258
|
-
`;
|
1259
|
-
}
|
1260
1291
|
return x `
|
1261
1292
|
<div class="chat-window">
|
1262
1293
|
${this.isTyping
|
@@ -1279,7 +1310,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1279
1310
|
<div class="bot-message-container">
|
1280
1311
|
${botIcon()}
|
1281
1312
|
<div class="message bot">
|
1282
|
-
|
1313
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1283
1314
|
${message.product
|
1284
1315
|
? x `<div class="product">
|
1285
1316
|
<img
|
@@ -1300,13 +1331,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1300
1331
|
message.product.variants[0].comparedAtPrice !==
|
1301
1332
|
message.product.variants[0].comparedAtPrice
|
1302
1333
|
? x `<p class="compared-at-price">
|
1303
|
-
${this.
|
1304
|
-
.variants[0].comparedAtPrice}
|
1334
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1305
1335
|
</p>`
|
1306
1336
|
: T}
|
1307
1337
|
<p class="price">
|
1308
|
-
${this.
|
1309
|
-
.variants[0].price}
|
1338
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1310
1339
|
</p>
|
1311
1340
|
</div>
|
1312
1341
|
</div>
|
package/package.json
CHANGED
@@ -25,6 +25,13 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
25
25
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
26
26
|
}
|
27
27
|
},
|
28
|
+
getSiteCurrency() {
|
29
|
+
var _a, _b, _c, _d;
|
30
|
+
return {
|
31
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
32
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
33
|
+
};
|
34
|
+
},
|
28
35
|
getCurrentProductHandle() {
|
29
36
|
const pathname = window.location.pathname;
|
30
37
|
return pathname.split('/').at(-1);
|
package/stores/shopify/index.js
CHANGED
@@ -26,6 +26,13 @@
|
|
26
26
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
27
27
|
}
|
28
28
|
},
|
29
|
+
getSiteCurrency() {
|
30
|
+
var _a, _b, _c, _d;
|
31
|
+
return {
|
32
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
33
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
34
|
+
};
|
35
|
+
},
|
29
36
|
getCurrentProductHandle() {
|
30
37
|
const pathname = window.location.pathname;
|
31
38
|
return pathname.split('/').at(-1);
|
package/stores/shopify/index.mjs
CHANGED
@@ -23,6 +23,13 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
23
23
|
throw new Error(`Could not add items`, { cause: await response.text() });
|
24
24
|
}
|
25
25
|
},
|
26
|
+
getSiteCurrency() {
|
27
|
+
var _a, _b, _c, _d;
|
28
|
+
return {
|
29
|
+
currency: ((_b = (_a = window.Shopify) === null || _a === void 0 ? void 0 : _a.currency) === null || _b === void 0 ? void 0 : _b.active) || 'USD',
|
30
|
+
rate: parseFloat(((_d = (_c = window.Shopify) === null || _c === void 0 ? void 0 : _c.currency) === null || _d === void 0 ? void 0 : _d.rate) || '1'),
|
31
|
+
};
|
32
|
+
},
|
26
33
|
getCurrentProductHandle() {
|
27
34
|
const pathname = window.location.pathname;
|
28
35
|
return pathname.split('/').at(-1);
|