@blotoutio/providers-shop-gpt-sdk 0.69.0 → 0.70.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 +91 -51
- package/index.js +91 -51
- package/index.mjs +91 -51
- 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,12 @@ 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) => {
|
73
|
+
var _a;
|
67
74
|
const response = await fetchImpl(getURL('/query'), {
|
68
75
|
method: 'POST',
|
69
76
|
headers: getHeaders(),
|
70
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
77
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
71
78
|
credentials: 'include',
|
72
79
|
});
|
73
80
|
if (!response.ok) {
|
@@ -76,7 +83,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
76
83
|
const data = (await response.json());
|
77
84
|
return {
|
78
85
|
message: data.message,
|
79
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
86
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
80
87
|
};
|
81
88
|
};
|
82
89
|
const queryPrompts = async () => {
|
@@ -216,20 +223,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
216
223
|
* Copyright 2019 Google LLC
|
217
224
|
* SPDX-License-Identifier: BSD-3-Clause
|
218
225
|
*/
|
219
|
-
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;
|
220
227
|
|
221
228
|
/**
|
222
229
|
* @license
|
223
230
|
* Copyright 2017 Google LLC
|
224
231
|
* SPDX-License-Identifier: BSD-3-Clause
|
225
|
-
*/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");
|
226
233
|
|
227
234
|
/**
|
228
235
|
* @license
|
229
236
|
* Copyright 2017 Google LLC
|
230
237
|
* SPDX-License-Identifier: BSD-3-Clause
|
231
238
|
*/
|
232
|
-
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};
|
233
240
|
|
234
241
|
/**
|
235
242
|
* @license
|
@@ -237,6 +244,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
237
244
|
* SPDX-License-Identifier: BSD-3-Clause
|
238
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");
|
239
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
|
+
|
240
260
|
/**
|
241
261
|
* @license
|
242
262
|
* Copyright 2017 Google LLC
|
@@ -301,7 +321,7 @@ const logger = {
|
|
301
321
|
},
|
302
322
|
};
|
303
323
|
|
304
|
-
const shopGPTStyles = () => i$
|
324
|
+
const shopGPTStyles = () => i$3 `
|
305
325
|
:host {
|
306
326
|
position: fixed;
|
307
327
|
top: 0;
|
@@ -849,6 +869,7 @@ const shopGPTStyles = () => i$2 `
|
|
849
869
|
.chat-input {
|
850
870
|
display: flex;
|
851
871
|
align-items: center;
|
872
|
+
margin: 0;
|
852
873
|
|
853
874
|
input {
|
854
875
|
flex: 1;
|
@@ -929,6 +950,9 @@ const botIcon = () => b `
|
|
929
950
|
|
930
951
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
931
952
|
const getImageProperties = (src) => {
|
953
|
+
if (!src) {
|
954
|
+
return;
|
955
|
+
}
|
932
956
|
const image = new URL(src);
|
933
957
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
934
958
|
image.searchParams.set('width', width.toString());
|
@@ -942,7 +966,6 @@ const getImageProperties = (src) => {
|
|
942
966
|
let ShopGPT = class ShopGPT extends s {
|
943
967
|
constructor() {
|
944
968
|
super(...arguments);
|
945
|
-
this.recommendedProduct = null;
|
946
969
|
this.moreRecommendations = [];
|
947
970
|
this.chatbotMessages = [];
|
948
971
|
this.userMessage = '';
|
@@ -977,10 +1000,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
977
1000
|
return;
|
978
1001
|
}
|
979
1002
|
await this.loadHistory();
|
1003
|
+
await this.loadInitialQuery();
|
980
1004
|
});
|
981
1005
|
}
|
982
1006
|
async loadHistory() {
|
983
|
-
var _a, _b, _c;
|
1007
|
+
var _a, _b, _c, _d;
|
984
1008
|
try {
|
985
1009
|
this.isLoadingHistory = true;
|
986
1010
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -993,8 +1017,8 @@ let ShopGPT = class ShopGPT extends s {
|
|
993
1017
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
994
1018
|
});
|
995
1019
|
});
|
996
|
-
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)
|
997
|
-
const products = data[0].products.map((product) => ({
|
1020
|
+
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)) {
|
1021
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
998
1022
|
...product,
|
999
1023
|
quantity: 1,
|
1000
1024
|
}));
|
@@ -1009,6 +1033,32 @@ let ShopGPT = class ShopGPT extends s {
|
|
1009
1033
|
this.isLoadingHistory = false;
|
1010
1034
|
}
|
1011
1035
|
}
|
1036
|
+
async loadInitialQuery() {
|
1037
|
+
var _a, _b, _c, _d;
|
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: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1047
|
+
...this.chatbotMessages,
|
1048
|
+
];
|
1049
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1050
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
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
|
+
}
|
1012
1062
|
redirect(url) {
|
1013
1063
|
var _a;
|
1014
1064
|
if (!url) {
|
@@ -1026,10 +1076,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1026
1076
|
});
|
1027
1077
|
}
|
1028
1078
|
resetProductRecommendations() {
|
1029
|
-
this.recommendedProduct =
|
1079
|
+
this.recommendedProduct = undefined;
|
1030
1080
|
this.moreRecommendations = [];
|
1031
1081
|
}
|
1032
1082
|
async sendMessageToServer(e, message) {
|
1083
|
+
var _a, _b, _c, _d;
|
1033
1084
|
e.preventDefault();
|
1034
1085
|
e.stopPropagation();
|
1035
1086
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1048,11 +1099,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1048
1099
|
return;
|
1049
1100
|
}
|
1050
1101
|
this.chatbotMessages = [
|
1051
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1102
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1052
1103
|
...this.chatbotMessages,
|
1053
1104
|
];
|
1054
|
-
this.recommendedProduct = reply.products[0];
|
1055
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1105
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1106
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1056
1107
|
this.setChatWindowHeight();
|
1057
1108
|
}
|
1058
1109
|
catch (e) {
|
@@ -1064,9 +1115,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1064
1115
|
this.isTyping = false;
|
1065
1116
|
}
|
1066
1117
|
}
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1118
|
+
getLocalPrice(price) {
|
1119
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1120
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1121
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1070
1122
|
}
|
1071
1123
|
handleShowMore(value) {
|
1072
1124
|
if (!this.chatWindowElement) {
|
@@ -1111,9 +1163,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1111
1163
|
var _a;
|
1112
1164
|
return x `
|
1113
1165
|
<div
|
1114
|
-
class
|
1115
|
-
|
1116
|
-
:
|
1166
|
+
class=${e$2({
|
1167
|
+
'products-section': true,
|
1168
|
+
'no-recommended-product': !this.recommendedProduct,
|
1169
|
+
})}
|
1117
1170
|
>
|
1118
1171
|
<div class="product-section recommended-product">
|
1119
1172
|
<h2>Recommended product</h2>
|
@@ -1149,13 +1202,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1149
1202
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1150
1203
|
this.recommendedProduct.variants[0].price
|
1151
1204
|
? x `<p class="compared-at-price">
|
1152
|
-
${this.
|
1153
|
-
.
|
1205
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1206
|
+
.comparedAtPrice)}
|
1154
1207
|
</p>`
|
1155
1208
|
: T}
|
1156
1209
|
<p class="price">
|
1157
|
-
${this.
|
1158
|
-
.variants[0].price}
|
1210
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1159
1211
|
</p>
|
1160
1212
|
</div>
|
1161
1213
|
<button
|
@@ -1170,9 +1222,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1170
1222
|
</div>
|
1171
1223
|
|
1172
1224
|
<div
|
1173
|
-
class
|
1174
|
-
|
1175
|
-
:
|
1225
|
+
class=${e$2({
|
1226
|
+
'product-section': true,
|
1227
|
+
'more-recommendations': true,
|
1228
|
+
'show-more-sml': this.showMore,
|
1229
|
+
})}
|
1176
1230
|
>
|
1177
1231
|
<h2>More Recommendations</h2>
|
1178
1232
|
${this.moreRecommendations.length === 0
|
@@ -1184,12 +1238,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1184
1238
|
`
|
1185
1239
|
: x `<div class="products">
|
1186
1240
|
${this.moreRecommendations.map((product) => {
|
1187
|
-
|
1241
|
+
var _a, _b, _c;
|
1242
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1188
1243
|
return x `
|
1189
1244
|
<div class="product">
|
1190
1245
|
<img
|
1191
|
-
srcset=${imageProperties.srcset}
|
1192
|
-
sizes=${imageProperties.sizes}
|
1246
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1247
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1193
1248
|
src=${product.image.url}
|
1194
1249
|
alt=${product.image.alt}
|
1195
1250
|
@click=${() => this.redirect(product.url)}
|
@@ -1206,13 +1261,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1206
1261
|
product.variants[0].comparedAtPrice !==
|
1207
1262
|
product.variants[0].price
|
1208
1263
|
? x `<p class="compared-at-price">
|
1209
|
-
${this.
|
1210
|
-
.comparedAtPrice}
|
1264
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1211
1265
|
</p>`
|
1212
1266
|
: T}
|
1213
1267
|
<p class="price">
|
1214
|
-
${this.
|
1215
|
-
.price}
|
1268
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1216
1269
|
</p>
|
1217
1270
|
</div>
|
1218
1271
|
</div>
|
@@ -1239,17 +1292,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1239
1292
|
if (this.isLoadingHistory) {
|
1240
1293
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1241
1294
|
}
|
1242
|
-
if (this.chatbotMessages.length === 0) {
|
1243
|
-
return x `
|
1244
|
-
<div class="chat-header">
|
1245
|
-
<div class="chat-header-title">ShopGPT</div>
|
1246
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1247
|
-
<div class="chat-header-description">
|
1248
|
-
Hi, type a message to get started!
|
1249
|
-
</div>
|
1250
|
-
</div>
|
1251
|
-
`;
|
1252
|
-
}
|
1253
1295
|
return x `
|
1254
1296
|
<div class="chat-window">
|
1255
1297
|
${this.isTyping
|
@@ -1272,7 +1314,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1272
1314
|
<div class="bot-message-container">
|
1273
1315
|
${botIcon()}
|
1274
1316
|
<div class="message bot">
|
1275
|
-
|
1317
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1276
1318
|
${message.product
|
1277
1319
|
? x `<div class="product">
|
1278
1320
|
<img
|
@@ -1293,13 +1335,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1293
1335
|
message.product.variants[0].comparedAtPrice !==
|
1294
1336
|
message.product.variants[0].comparedAtPrice
|
1295
1337
|
? x `<p class="compared-at-price">
|
1296
|
-
${this.
|
1297
|
-
.variants[0].comparedAtPrice}
|
1338
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1298
1339
|
</p>`
|
1299
1340
|
: T}
|
1300
1341
|
<p class="price">
|
1301
|
-
${this.
|
1302
|
-
.variants[0].price}
|
1342
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1303
1343
|
</p>
|
1304
1344
|
</div>
|
1305
1345
|
</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,12 @@ 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) => {
|
74
|
+
var _a;
|
68
75
|
const response = await fetchImpl(getURL('/query'), {
|
69
76
|
method: 'POST',
|
70
77
|
headers: getHeaders(),
|
71
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
78
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
72
79
|
credentials: 'include',
|
73
80
|
});
|
74
81
|
if (!response.ok) {
|
@@ -77,7 +84,7 @@ var ProvidersShopGptSdk = (function () {
|
|
77
84
|
const data = (await response.json());
|
78
85
|
return {
|
79
86
|
message: data.message,
|
80
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
87
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
81
88
|
};
|
82
89
|
};
|
83
90
|
const queryPrompts = async () => {
|
@@ -217,20 +224,20 @@ var ProvidersShopGptSdk = (function () {
|
|
217
224
|
* Copyright 2019 Google LLC
|
218
225
|
* SPDX-License-Identifier: BSD-3-Clause
|
219
226
|
*/
|
220
|
-
const t$
|
227
|
+
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
228
|
|
222
229
|
/**
|
223
230
|
* @license
|
224
231
|
* Copyright 2017 Google LLC
|
225
232
|
* SPDX-License-Identifier: BSD-3-Clause
|
226
|
-
*/const{is:i$
|
233
|
+
*/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
234
|
|
228
235
|
/**
|
229
236
|
* @license
|
230
237
|
* Copyright 2017 Google LLC
|
231
238
|
* SPDX-License-Identifier: BSD-3-Clause
|
232
239
|
*/
|
233
|
-
const t$
|
240
|
+
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
241
|
|
235
242
|
/**
|
236
243
|
* @license
|
@@ -238,6 +245,19 @@ var ProvidersShopGptSdk = (function () {
|
|
238
245
|
* SPDX-License-Identifier: BSD-3-Clause
|
239
246
|
*/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
247
|
|
248
|
+
/**
|
249
|
+
* @license
|
250
|
+
* Copyright 2017 Google LLC
|
251
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
252
|
+
*/
|
253
|
+
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)}}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* @license
|
257
|
+
* Copyright 2018 Google LLC
|
258
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
259
|
+
*/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}});
|
260
|
+
|
241
261
|
/**
|
242
262
|
* @license
|
243
263
|
* Copyright 2017 Google LLC
|
@@ -302,7 +322,7 @@ var ProvidersShopGptSdk = (function () {
|
|
302
322
|
},
|
303
323
|
};
|
304
324
|
|
305
|
-
const shopGPTStyles = () => i$
|
325
|
+
const shopGPTStyles = () => i$3 `
|
306
326
|
:host {
|
307
327
|
position: fixed;
|
308
328
|
top: 0;
|
@@ -850,6 +870,7 @@ var ProvidersShopGptSdk = (function () {
|
|
850
870
|
.chat-input {
|
851
871
|
display: flex;
|
852
872
|
align-items: center;
|
873
|
+
margin: 0;
|
853
874
|
|
854
875
|
input {
|
855
876
|
flex: 1;
|
@@ -930,6 +951,9 @@ var ProvidersShopGptSdk = (function () {
|
|
930
951
|
|
931
952
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
932
953
|
const getImageProperties = (src) => {
|
954
|
+
if (!src) {
|
955
|
+
return;
|
956
|
+
}
|
933
957
|
const image = new URL(src);
|
934
958
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
935
959
|
image.searchParams.set('width', width.toString());
|
@@ -943,7 +967,6 @@ var ProvidersShopGptSdk = (function () {
|
|
943
967
|
let ShopGPT = class ShopGPT extends s {
|
944
968
|
constructor() {
|
945
969
|
super(...arguments);
|
946
|
-
this.recommendedProduct = null;
|
947
970
|
this.moreRecommendations = [];
|
948
971
|
this.chatbotMessages = [];
|
949
972
|
this.userMessage = '';
|
@@ -978,10 +1001,11 @@ var ProvidersShopGptSdk = (function () {
|
|
978
1001
|
return;
|
979
1002
|
}
|
980
1003
|
await this.loadHistory();
|
1004
|
+
await this.loadInitialQuery();
|
981
1005
|
});
|
982
1006
|
}
|
983
1007
|
async loadHistory() {
|
984
|
-
var _a, _b, _c;
|
1008
|
+
var _a, _b, _c, _d;
|
985
1009
|
try {
|
986
1010
|
this.isLoadingHistory = true;
|
987
1011
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -994,8 +1018,8 @@ var ProvidersShopGptSdk = (function () {
|
|
994
1018
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
995
1019
|
});
|
996
1020
|
});
|
997
|
-
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)
|
998
|
-
const products = data[0].products.map((product) => ({
|
1021
|
+
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)) {
|
1022
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
999
1023
|
...product,
|
1000
1024
|
quantity: 1,
|
1001
1025
|
}));
|
@@ -1010,6 +1034,32 @@ var ProvidersShopGptSdk = (function () {
|
|
1010
1034
|
this.isLoadingHistory = false;
|
1011
1035
|
}
|
1012
1036
|
}
|
1037
|
+
async loadInitialQuery() {
|
1038
|
+
var _a, _b, _c, _d;
|
1039
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1040
|
+
if (this.chatbotMessages.length) {
|
1041
|
+
return;
|
1042
|
+
}
|
1043
|
+
try {
|
1044
|
+
this.isTyping = true;
|
1045
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1046
|
+
this.chatbotMessages = [
|
1047
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1048
|
+
...this.chatbotMessages,
|
1049
|
+
];
|
1050
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1051
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1052
|
+
this.setChatWindowHeight();
|
1053
|
+
}
|
1054
|
+
catch (error) {
|
1055
|
+
logger.error(error);
|
1056
|
+
this.resetProductRecommendations();
|
1057
|
+
this.isFailed = true;
|
1058
|
+
}
|
1059
|
+
finally {
|
1060
|
+
this.isTyping = false;
|
1061
|
+
}
|
1062
|
+
}
|
1013
1063
|
redirect(url) {
|
1014
1064
|
var _a;
|
1015
1065
|
if (!url) {
|
@@ -1027,10 +1077,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1027
1077
|
});
|
1028
1078
|
}
|
1029
1079
|
resetProductRecommendations() {
|
1030
|
-
this.recommendedProduct =
|
1080
|
+
this.recommendedProduct = undefined;
|
1031
1081
|
this.moreRecommendations = [];
|
1032
1082
|
}
|
1033
1083
|
async sendMessageToServer(e, message) {
|
1084
|
+
var _a, _b, _c, _d;
|
1034
1085
|
e.preventDefault();
|
1035
1086
|
e.stopPropagation();
|
1036
1087
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1049,11 +1100,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1049
1100
|
return;
|
1050
1101
|
}
|
1051
1102
|
this.chatbotMessages = [
|
1052
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1103
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1053
1104
|
...this.chatbotMessages,
|
1054
1105
|
];
|
1055
|
-
this.recommendedProduct = reply.products[0];
|
1056
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1106
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1107
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1057
1108
|
this.setChatWindowHeight();
|
1058
1109
|
}
|
1059
1110
|
catch (e) {
|
@@ -1065,9 +1116,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1065
1116
|
this.isTyping = false;
|
1066
1117
|
}
|
1067
1118
|
}
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1119
|
+
getLocalPrice(price) {
|
1120
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1121
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1122
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1071
1123
|
}
|
1072
1124
|
handleShowMore(value) {
|
1073
1125
|
if (!this.chatWindowElement) {
|
@@ -1112,9 +1164,10 @@ var ProvidersShopGptSdk = (function () {
|
|
1112
1164
|
var _a;
|
1113
1165
|
return x `
|
1114
1166
|
<div
|
1115
|
-
class
|
1116
|
-
|
1117
|
-
:
|
1167
|
+
class=${e$2({
|
1168
|
+
'products-section': true,
|
1169
|
+
'no-recommended-product': !this.recommendedProduct,
|
1170
|
+
})}
|
1118
1171
|
>
|
1119
1172
|
<div class="product-section recommended-product">
|
1120
1173
|
<h2>Recommended product</h2>
|
@@ -1150,13 +1203,12 @@ var ProvidersShopGptSdk = (function () {
|
|
1150
1203
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1151
1204
|
this.recommendedProduct.variants[0].price
|
1152
1205
|
? x `<p class="compared-at-price">
|
1153
|
-
${this.
|
1154
|
-
.
|
1206
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1207
|
+
.comparedAtPrice)}
|
1155
1208
|
</p>`
|
1156
1209
|
: T}
|
1157
1210
|
<p class="price">
|
1158
|
-
${this.
|
1159
|
-
.variants[0].price}
|
1211
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1160
1212
|
</p>
|
1161
1213
|
</div>
|
1162
1214
|
<button
|
@@ -1171,9 +1223,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1171
1223
|
</div>
|
1172
1224
|
|
1173
1225
|
<div
|
1174
|
-
class
|
1175
|
-
|
1176
|
-
:
|
1226
|
+
class=${e$2({
|
1227
|
+
'product-section': true,
|
1228
|
+
'more-recommendations': true,
|
1229
|
+
'show-more-sml': this.showMore,
|
1230
|
+
})}
|
1177
1231
|
>
|
1178
1232
|
<h2>More Recommendations</h2>
|
1179
1233
|
${this.moreRecommendations.length === 0
|
@@ -1185,12 +1239,13 @@ var ProvidersShopGptSdk = (function () {
|
|
1185
1239
|
`
|
1186
1240
|
: x `<div class="products">
|
1187
1241
|
${this.moreRecommendations.map((product) => {
|
1188
|
-
|
1242
|
+
var _a, _b, _c;
|
1243
|
+
const imageProperties = getImageProperties((_a = product === null || product === void 0 ? void 0 : product.image) === null || _a === void 0 ? void 0 : _a.url);
|
1189
1244
|
return x `
|
1190
1245
|
<div class="product">
|
1191
1246
|
<img
|
1192
|
-
srcset=${imageProperties.srcset}
|
1193
|
-
sizes=${imageProperties.sizes}
|
1247
|
+
srcset=${(_b = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.srcset) !== null && _b !== void 0 ? _b : T}
|
1248
|
+
sizes=${(_c = imageProperties === null || imageProperties === void 0 ? void 0 : imageProperties.sizes) !== null && _c !== void 0 ? _c : T}
|
1194
1249
|
src=${product.image.url}
|
1195
1250
|
alt=${product.image.alt}
|
1196
1251
|
@click=${() => this.redirect(product.url)}
|
@@ -1207,13 +1262,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1207
1262
|
product.variants[0].comparedAtPrice !==
|
1208
1263
|
product.variants[0].price
|
1209
1264
|
? x `<p class="compared-at-price">
|
1210
|
-
${this.
|
1211
|
-
.comparedAtPrice}
|
1265
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1212
1266
|
</p>`
|
1213
1267
|
: T}
|
1214
1268
|
<p class="price">
|
1215
|
-
${this.
|
1216
|
-
.price}
|
1269
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1217
1270
|
</p>
|
1218
1271
|
</div>
|
1219
1272
|
</div>
|
@@ -1240,17 +1293,6 @@ var ProvidersShopGptSdk = (function () {
|
|
1240
1293
|
if (this.isLoadingHistory) {
|
1241
1294
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1242
1295
|
}
|
1243
|
-
if (this.chatbotMessages.length === 0) {
|
1244
|
-
return x `
|
1245
|
-
<div class="chat-header">
|
1246
|
-
<div class="chat-header-title">ShopGPT</div>
|
1247
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1248
|
-
<div class="chat-header-description">
|
1249
|
-
Hi, type a message to get started!
|
1250
|
-
</div>
|
1251
|
-
</div>
|
1252
|
-
`;
|
1253
|
-
}
|
1254
1296
|
return x `
|
1255
1297
|
<div class="chat-window">
|
1256
1298
|
${this.isTyping
|
@@ -1273,7 +1315,7 @@ var ProvidersShopGptSdk = (function () {
|
|
1273
1315
|
<div class="bot-message-container">
|
1274
1316
|
${botIcon()}
|
1275
1317
|
<div class="message bot">
|
1276
|
-
|
1318
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1277
1319
|
${message.product
|
1278
1320
|
? x `<div class="product">
|
1279
1321
|
<img
|
@@ -1294,13 +1336,11 @@ var ProvidersShopGptSdk = (function () {
|
|
1294
1336
|
message.product.variants[0].comparedAtPrice !==
|
1295
1337
|
message.product.variants[0].comparedAtPrice
|
1296
1338
|
? x `<p class="compared-at-price">
|
1297
|
-
${this.
|
1298
|
-
.variants[0].comparedAtPrice}
|
1339
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1299
1340
|
</p>`
|
1300
1341
|
: T}
|
1301
1342
|
<p class="price">
|
1302
|
-
${this.
|
1303
|
-
.variants[0].price}
|
1343
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1304
1344
|
</p>
|
1305
1345
|
</div>
|
1306
1346
|
</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,12 @@ 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) => {
|
71
|
+
var _a;
|
65
72
|
const response = await fetchImpl(getURL('/query'), {
|
66
73
|
method: 'POST',
|
67
74
|
headers: getHeaders(),
|
68
|
-
body: JSON.stringify({ query, timestamp: Date.now() }),
|
75
|
+
body: JSON.stringify({ query, timestamp: Date.now(), productHandle }),
|
69
76
|
credentials: 'include',
|
70
77
|
});
|
71
78
|
if (!response.ok) {
|
@@ -74,7 +81,7 @@ const createShopGPTAPI = ({ fetch: fetchImpl = window.fetch, baseURL, userId, st
|
|
74
81
|
const data = (await response.json());
|
75
82
|
return {
|
76
83
|
message: data.message,
|
77
|
-
products: data.products.map((item) => ({ ...item, quantity: 1 })),
|
84
|
+
products: (_a = data.products) === null || _a === void 0 ? void 0 : _a.filter((item) => !!item).map((item) => ({ ...item, quantity: 1 })),
|
78
85
|
};
|
79
86
|
};
|
80
87
|
const queryPrompts = async () => {
|
@@ -214,20 +221,20 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
214
221
|
* Copyright 2019 Google LLC
|
215
222
|
* SPDX-License-Identifier: BSD-3-Clause
|
216
223
|
*/
|
217
|
-
const t$
|
224
|
+
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
225
|
|
219
226
|
/**
|
220
227
|
* @license
|
221
228
|
* Copyright 2017 Google LLC
|
222
229
|
* SPDX-License-Identifier: BSD-3-Clause
|
223
|
-
*/const{is:i$
|
230
|
+
*/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
231
|
|
225
232
|
/**
|
226
233
|
* @license
|
227
234
|
* Copyright 2017 Google LLC
|
228
235
|
* SPDX-License-Identifier: BSD-3-Clause
|
229
236
|
*/
|
230
|
-
const t$
|
237
|
+
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
238
|
|
232
239
|
/**
|
233
240
|
* @license
|
@@ -235,6 +242,19 @@ const t$1=globalThis,i=t$1.trustedTypes,s$1=i?i.createPolicy("lit-html",{createH
|
|
235
242
|
* SPDX-License-Identifier: BSD-3-Clause
|
236
243
|
*/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
244
|
|
245
|
+
/**
|
246
|
+
* @license
|
247
|
+
* Copyright 2017 Google LLC
|
248
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
249
|
+
*/
|
250
|
+
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)}}
|
251
|
+
|
252
|
+
/**
|
253
|
+
* @license
|
254
|
+
* Copyright 2018 Google LLC
|
255
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
256
|
+
*/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}});
|
257
|
+
|
238
258
|
/**
|
239
259
|
* @license
|
240
260
|
* Copyright 2017 Google LLC
|
@@ -299,7 +319,7 @@ const logger = {
|
|
299
319
|
},
|
300
320
|
};
|
301
321
|
|
302
|
-
const shopGPTStyles = () => i$
|
322
|
+
const shopGPTStyles = () => i$3 `
|
303
323
|
:host {
|
304
324
|
position: fixed;
|
305
325
|
top: 0;
|
@@ -847,6 +867,7 @@ const shopGPTStyles = () => i$2 `
|
|
847
867
|
.chat-input {
|
848
868
|
display: flex;
|
849
869
|
align-items: center;
|
870
|
+
margin: 0;
|
850
871
|
|
851
872
|
input {
|
852
873
|
flex: 1;
|
@@ -927,6 +948,9 @@ const botIcon = () => b `
|
|
927
948
|
|
928
949
|
const IMAGE_WIDTHS = [165, 360, 533, 720, 940, 1066, 1600];
|
929
950
|
const getImageProperties = (src) => {
|
951
|
+
if (!src) {
|
952
|
+
return;
|
953
|
+
}
|
930
954
|
const image = new URL(src);
|
931
955
|
const srcSet = IMAGE_WIDTHS.map((width) => {
|
932
956
|
image.searchParams.set('width', width.toString());
|
@@ -940,7 +964,6 @@ const getImageProperties = (src) => {
|
|
940
964
|
let ShopGPT = class ShopGPT extends s {
|
941
965
|
constructor() {
|
942
966
|
super(...arguments);
|
943
|
-
this.recommendedProduct = null;
|
944
967
|
this.moreRecommendations = [];
|
945
968
|
this.chatbotMessages = [];
|
946
969
|
this.userMessage = '';
|
@@ -975,10 +998,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
975
998
|
return;
|
976
999
|
}
|
977
1000
|
await this.loadHistory();
|
1001
|
+
await this.loadInitialQuery();
|
978
1002
|
});
|
979
1003
|
}
|
980
1004
|
async loadHistory() {
|
981
|
-
var _a, _b, _c;
|
1005
|
+
var _a, _b, _c, _d;
|
982
1006
|
try {
|
983
1007
|
this.isLoadingHistory = true;
|
984
1008
|
const data = await this.shopGPTAPI.fetchChatHistory();
|
@@ -991,8 +1015,8 @@ let ShopGPT = class ShopGPT extends s {
|
|
991
1015
|
product: ((_a = message.products) === null || _a === void 0 ? void 0 : _a.length) ? message.products[0] : null,
|
992
1016
|
});
|
993
1017
|
});
|
994
|
-
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)
|
995
|
-
const products = data[0].products.map((product) => ({
|
1018
|
+
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)) {
|
1019
|
+
const products = (_d = data[0].products) === null || _d === void 0 ? void 0 : _d.map((product) => ({
|
996
1020
|
...product,
|
997
1021
|
quantity: 1,
|
998
1022
|
}));
|
@@ -1007,6 +1031,32 @@ let ShopGPT = class ShopGPT extends s {
|
|
1007
1031
|
this.isLoadingHistory = false;
|
1008
1032
|
}
|
1009
1033
|
}
|
1034
|
+
async loadInitialQuery() {
|
1035
|
+
var _a, _b, _c, _d;
|
1036
|
+
const productHandle = this.storeAPI.getCurrentProductHandle();
|
1037
|
+
if (this.chatbotMessages.length) {
|
1038
|
+
return;
|
1039
|
+
}
|
1040
|
+
try {
|
1041
|
+
this.isTyping = true;
|
1042
|
+
const reply = await this.shopGPTAPI.processQuery('', productHandle);
|
1043
|
+
this.chatbotMessages = [
|
1044
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1045
|
+
...this.chatbotMessages,
|
1046
|
+
];
|
1047
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1048
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1049
|
+
this.setChatWindowHeight();
|
1050
|
+
}
|
1051
|
+
catch (error) {
|
1052
|
+
logger.error(error);
|
1053
|
+
this.resetProductRecommendations();
|
1054
|
+
this.isFailed = true;
|
1055
|
+
}
|
1056
|
+
finally {
|
1057
|
+
this.isTyping = false;
|
1058
|
+
}
|
1059
|
+
}
|
1010
1060
|
redirect(url) {
|
1011
1061
|
var _a;
|
1012
1062
|
if (!url) {
|
@@ -1024,10 +1074,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1024
1074
|
});
|
1025
1075
|
}
|
1026
1076
|
resetProductRecommendations() {
|
1027
|
-
this.recommendedProduct =
|
1077
|
+
this.recommendedProduct = undefined;
|
1028
1078
|
this.moreRecommendations = [];
|
1029
1079
|
}
|
1030
1080
|
async sendMessageToServer(e, message) {
|
1081
|
+
var _a, _b, _c, _d;
|
1031
1082
|
e.preventDefault();
|
1032
1083
|
e.stopPropagation();
|
1033
1084
|
if (!message || this.isTyping || this.isLoadingHistory) {
|
@@ -1046,11 +1097,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1046
1097
|
return;
|
1047
1098
|
}
|
1048
1099
|
this.chatbotMessages = [
|
1049
|
-
{ sender: 'bot', message: reply.message, product: reply.products[0] },
|
1100
|
+
{ sender: 'bot', message: reply.message, product: (_a = reply.products) === null || _a === void 0 ? void 0 : _a[0] },
|
1050
1101
|
...this.chatbotMessages,
|
1051
1102
|
];
|
1052
|
-
this.recommendedProduct = reply.products[0];
|
1053
|
-
this.moreRecommendations = reply.products.slice(1, 4);
|
1103
|
+
this.recommendedProduct = (_b = reply.products) === null || _b === void 0 ? void 0 : _b[0];
|
1104
|
+
this.moreRecommendations = (_d = (_c = reply.products) === null || _c === void 0 ? void 0 : _c.slice(1, 4)) !== null && _d !== void 0 ? _d : [];
|
1054
1105
|
this.setChatWindowHeight();
|
1055
1106
|
}
|
1056
1107
|
catch (e) {
|
@@ -1062,9 +1113,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1062
1113
|
this.isTyping = false;
|
1063
1114
|
}
|
1064
1115
|
}
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1116
|
+
getLocalPrice(price) {
|
1117
|
+
const siteCurrency = this.storeAPI.getSiteCurrency();
|
1118
|
+
const localPrice = parseFloat(price) * siteCurrency.rate;
|
1119
|
+
return formatMoney(localPrice, siteCurrency.currency);
|
1068
1120
|
}
|
1069
1121
|
handleShowMore(value) {
|
1070
1122
|
if (!this.chatWindowElement) {
|
@@ -1109,9 +1161,10 @@ let ShopGPT = class ShopGPT extends s {
|
|
1109
1161
|
var _a;
|
1110
1162
|
return x `
|
1111
1163
|
<div
|
1112
|
-
class
|
1113
|
-
|
1114
|
-
:
|
1164
|
+
class=${e$2({
|
1165
|
+
'products-section': true,
|
1166
|
+
'no-recommended-product': !this.recommendedProduct,
|
1167
|
+
})}
|
1115
1168
|
>
|
1116
1169
|
<div class="product-section recommended-product">
|
1117
1170
|
<h2>Recommended product</h2>
|
@@ -1147,13 +1200,12 @@ let ShopGPT = class ShopGPT extends s {
|
|
1147
1200
|
this.recommendedProduct.variants[0].comparedAtPrice !==
|
1148
1201
|
this.recommendedProduct.variants[0].price
|
1149
1202
|
? x `<p class="compared-at-price">
|
1150
|
-
${this.
|
1151
|
-
.
|
1203
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0]
|
1204
|
+
.comparedAtPrice)}
|
1152
1205
|
</p>`
|
1153
1206
|
: T}
|
1154
1207
|
<p class="price">
|
1155
|
-
${this.
|
1156
|
-
.variants[0].price}
|
1208
|
+
${this.getLocalPrice(this.recommendedProduct.variants[0].price)}
|
1157
1209
|
</p>
|
1158
1210
|
</div>
|
1159
1211
|
<button
|
@@ -1168,9 +1220,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1168
1220
|
</div>
|
1169
1221
|
|
1170
1222
|
<div
|
1171
|
-
class
|
1172
|
-
|
1173
|
-
:
|
1223
|
+
class=${e$2({
|
1224
|
+
'product-section': true,
|
1225
|
+
'more-recommendations': true,
|
1226
|
+
'show-more-sml': this.showMore,
|
1227
|
+
})}
|
1174
1228
|
>
|
1175
1229
|
<h2>More Recommendations</h2>
|
1176
1230
|
${this.moreRecommendations.length === 0
|
@@ -1182,12 +1236,13 @@ let ShopGPT = class ShopGPT extends s {
|
|
1182
1236
|
`
|
1183
1237
|
: x `<div class="products">
|
1184
1238
|
${this.moreRecommendations.map((product) => {
|
1185
|
-
|
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);
|
1186
1241
|
return x `
|
1187
1242
|
<div class="product">
|
1188
1243
|
<img
|
1189
|
-
srcset=${imageProperties.srcset}
|
1190
|
-
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}
|
1191
1246
|
src=${product.image.url}
|
1192
1247
|
alt=${product.image.alt}
|
1193
1248
|
@click=${() => this.redirect(product.url)}
|
@@ -1204,13 +1259,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1204
1259
|
product.variants[0].comparedAtPrice !==
|
1205
1260
|
product.variants[0].price
|
1206
1261
|
? x `<p class="compared-at-price">
|
1207
|
-
${this.
|
1208
|
-
.comparedAtPrice}
|
1262
|
+
${this.getLocalPrice(product.variants[0].comparedAtPrice)}
|
1209
1263
|
</p>`
|
1210
1264
|
: T}
|
1211
1265
|
<p class="price">
|
1212
|
-
${this.
|
1213
|
-
.price}
|
1266
|
+
${this.getLocalPrice(product.variants[0].price)}
|
1214
1267
|
</p>
|
1215
1268
|
</div>
|
1216
1269
|
</div>
|
@@ -1237,17 +1290,6 @@ let ShopGPT = class ShopGPT extends s {
|
|
1237
1290
|
if (this.isLoadingHistory) {
|
1238
1291
|
return x ` <div class="loader"><div class="spinner"></div></div> `;
|
1239
1292
|
}
|
1240
|
-
if (this.chatbotMessages.length === 0) {
|
1241
|
-
return x `
|
1242
|
-
<div class="chat-header">
|
1243
|
-
<div class="chat-header-title">ShopGPT</div>
|
1244
|
-
<div class="chat-header-sub-title">powered by Blotout</div>
|
1245
|
-
<div class="chat-header-description">
|
1246
|
-
Hi, type a message to get started!
|
1247
|
-
</div>
|
1248
|
-
</div>
|
1249
|
-
`;
|
1250
|
-
}
|
1251
1293
|
return x `
|
1252
1294
|
<div class="chat-window">
|
1253
1295
|
${this.isTyping
|
@@ -1270,7 +1312,7 @@ let ShopGPT = class ShopGPT extends s {
|
|
1270
1312
|
<div class="bot-message-container">
|
1271
1313
|
${botIcon()}
|
1272
1314
|
<div class="message bot">
|
1273
|
-
|
1315
|
+
${message.message ? x `<p>${message.message}</p>` : T}
|
1274
1316
|
${message.product
|
1275
1317
|
? x `<div class="product">
|
1276
1318
|
<img
|
@@ -1291,13 +1333,11 @@ let ShopGPT = class ShopGPT extends s {
|
|
1291
1333
|
message.product.variants[0].comparedAtPrice !==
|
1292
1334
|
message.product.variants[0].comparedAtPrice
|
1293
1335
|
? x `<p class="compared-at-price">
|
1294
|
-
${this.
|
1295
|
-
.variants[0].comparedAtPrice}
|
1336
|
+
${this.getLocalPrice(message.product.variants[0].comparedAtPrice)}
|
1296
1337
|
</p>`
|
1297
1338
|
: T}
|
1298
1339
|
<p class="price">
|
1299
|
-
${this.
|
1300
|
-
.variants[0].price}
|
1340
|
+
${this.getLocalPrice(message.product.variants[0].price)}
|
1301
1341
|
</p>
|
1302
1342
|
</div>
|
1303
1343
|
</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);
|