@molin.ai/shop-ai 0.8.16 → 0.8.17
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.
|
@@ -523,7 +523,7 @@ var au=Object.defineProperty;var Ys=t=>{throw TypeError(t)};var lu=(t,e,r)=>e in
|
|
|
523
523
|
?links-new-tab="${i}"
|
|
524
524
|
.searchParams="${s}"
|
|
525
525
|
.imagesByProductUrl="${n}"></mw-product-card-horizontal>
|
|
526
|
-
`}console.warn(c.issues);break}case"order-status-card-v1":return h`<mw-product-order-status-card order-details="${JSON.stringify(t.data)}" ?streaming="${!a}" ?links-new-tab="${i}"></mw-product-order-status-card> `}return console.warn("could not render part:",t),h`<p><i>data type not supported</i></p>`}var Ar,Nt,Ne,lt,Jn,gl,Zn=class{constructor(e,r,{timeoutMs:n=2e3}={}){d(this,Jn);d(this,Ar);d(this,Nt);d(this,Ne);d(this,lt,!1);w(this,"timeoutMs");m(this,Ar,e),m(this,Nt,r),this.timeoutMs=n,e.addController(this)}get isTyping(){return l(this,lt)}hostDisconnected(){clearTimeout(l(this,Ne)),m(this,Ne,void 0)}onInput(e){if(l(this,Ar).isConnected){if(!e.trim()){this.typingStopped();return}clearTimeout(l(this,Ne)),m(this,Ne,setTimeout(()=>this.typingStopped(),this.timeoutMs)),l(this,lt)||g(this,Jn,gl).call(this)}}typingStopped(){clearTimeout(l(this,Ne)),m(this,lt,!1),l(this,Nt).typingStopped()}};Ar=new WeakMap,Nt=new WeakMap,Ne=new WeakMap,lt=new WeakMap,Jn=new WeakSet,gl=function(){m(this,lt,!0),l(this,Nt).typingStarted()};function yl(t,e="en-US"){let r=new Intl.DateTimeFormat(e,{hour:"numeric",minute:"numeric"}).format(t);return`${t.toLocaleDateString(e,{year:"numeric",month:"short",day:"numeric"})}, ${r}`}var vl=()=>{if(window.Shopify)try{return{customerId:tp()}}catch{return null}return null},tp=()=>{try{let t=[()=>window.ShopifyAnalytics?.meta?.page?.customerId,()=>window.meta?.page?.customerId,()=>window._st?.cid,()=>window.ShopifyAnalytics?.lib?.user()?.traits()?.uniqToken];for(let e of t)try{let r=e();if(r)return r}catch{}}catch{return null}return null},wl=async()=>{try{return(await(await fetch(window.Shopify.routes.root+"cart.js")).json()).items.map(n=>({id:n.id,name:n.title,quantity:n.quantity,price:n.price,variantId:n.variant_id,sku:n.sku,url:n.url,description:n.product_description,image:n.featured_image?.url}))}catch{return[]}};var bl=()=>{if(window.ShopRenter)try{let t=np();return{customerEmail:t?.customerEmail,customerId:t?.customerId,customerName:t?.customerName}}catch{return null}return null},np=()=>{try{if(window.ShopRenter){let t=window.ShopRenter.customer;return{customerEmail:t?.email,customerId:t?.userId,customerName:[t?.name?.firstName,t?.name?.lastName].filter(Boolean).join(" ")}}return{customerEmail:null,customerId:null,customerName:null}}catch{return{customerEmail:null,customerId:null,customerName:null}}},xl=async()=>{try{let t=window.ShopRenter.shop?.domain;if(!t)return[];let e=ga(t,"https")+"/cart.json";return(await(await fetch(e)).json()).items.map(s=>({id:s.id,name:s.name,quantity:s.quantity,price:s.price,sku:s.sku,image:s.image,url:s.href}))}catch{return[]}};var kl=()=>{if(window.UNAS)try{let t=window.UNAS.customer;return{customerEmail:t?.email,customerId:t?.id}}catch(t){return console.error("Error fetching customer information:",t),null}return null},Cl=async()=>new Promise((t,e)=>{try{window.UNAS.getCart(r=>{let i=r.items.map(s=>({id:s.id,name:s.name,quantity:s.quantity,price:s.price,sku:s.sku}));t(i)})}catch(r){console.error("Error fetching cart information:",r),e(r)}});var $l=Wn(q(),Vt([q(),zn(),Ms(),Is()])),Sl=hl(q(),_s(1),Es(5e3)),El=()=>{try{return window.UNAS?kl():window.Shopify?vl():window.ShopRenter?bl():null}catch{return null}},_l=async()=>{try{return window.UNAS?await Cl():window.Shopify?await wl():window.ShopRenter?await xl():[]}catch{return[]}},Ft={schema:Ie({conversationId:Ut(q()),messages:Ut(Pt(Ie({id:q(),timestamp:zn(),role:Ts(["user","assistant","support"]),content:q(),parts:Ut(Pt(Vt([Ie({text:q()}),Ie({html:q()}),Ie({tag:q(),data:Wn(q(),As())})])))})))}),getStorageKey(t){if(!t)throw new Error("widgetId is not set");return`_molin_${t}`},persist(t,e,r){let n=this.getStorageKey(t);localStorage.setItem(n,JSON.stringify({conversationId:e,messages:r}))},restore(t){try{let e=this.getStorageKey(t),r=JSON.parse(localStorage.getItem(e)||"{}"),n=pl(this.schema,r);return{conversationId:n.conversationId||"",messages:n.messages||[]}}catch(e){return console.error("Failed to restore conversation state:",e),{conversationId:"",messages:[]}}},reset(t){let e=this.getStorageKey(t);localStorage.removeItem(e)}};var op=!0,Os="Invariant failed";function Al(t,e){if(!t){if(op)throw new Error(Os);var r=typeof e=="function"?e():e,n=r?"".concat(Os,": ").concat(r):Os;throw new Error(n)}}var ap="\xB7 \xB7 \xB7",Fe,He,P,Ls,Ir,ut,R,Tr,Ml,Il,Tl,Ol,jl,Ll,Dl,Rl,Xn,Kn=class Kn extends M(E){constructor(){super();d(this,P);d(this,Fe);d(this,He);d(this,Ir,new Zn(this,{typingStarted:()=>l(this,R).sendUserTypingStart(),typingStopped:()=>l(this,R).sendUserTypingStop()}));d(this,ut,!1);d(this,R,new qn(this,{url:r=>{let n=new URL(this.config.wsApiUrl);return n.searchParams.set("widgetId",this.widgetId),n.searchParams.set("conversationId",r),n.searchParams.set("pageUrl",window.location.href),n},onReconnect:()=>{},onError:r=>{console.error("ws error",r)},onClose:()=>{},onNewMessage:r=>{m(this,ut,!1),r.role==="user"&&l(this,P,Xn)?.scrollTo(0,l(this,P,Xn).scrollHeight),r.role==="assistant"&&this.callbacks.onNewMessageStartedStreaming?.({widgetId:this.widgetId,message:r,conversationId:this.conversationId})},onMessageAppend:r=>{let n=l(this,P,Xn);if(!n)return;let i=l(this,R).lastMsg;!i||i.role!=="assistant"||requestAnimationFrame(()=>{let s=n.querySelector(`[data-id="${i.id}"]`);if(!s)return;let o=s.offsetHeight,u=n.getClientRects()[0].height-70;o>u&&!l(this,ut)&&(n.scrollTop=s.offsetTop-80)})},onMessageDone:(r,n)=>{m(this,ut,!1),n.role==="assistant"&&this.callbacks.onMessageEndedStreaming?.({widgetId:this.widgetId,text:n.content??"",message:n,usage_TOKENS_COMPLETION:r.message.usage.TOKENS_COMPLETION,conversationId:this.conversationId})},onMessageError:r=>{console.error("ws message error",r),r.message&&this.callbacks.onError?.({widgetId:this.widgetId,error:"WS: "+r.message})},onReset:()=>{Ft.reset(this.widgetId)},onConnect:r=>{let n=El();l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,language:window.navigator.language,cart:[]}),_l().then(i=>{l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,cart:i,language:window.navigator.language})}).catch(i=>{console.error(i)})},persistConversationState:(r,n)=>{Ft.persist(this.widgetId,r,n)},restoreConversationState:()=>Ft.restore(this.widgetId)}));d(this,Tr,"single");this.widgetId="",this.config={},this.callbacks={},this.showClose=!1,this.xUserData={},this.xCustomInstructions=""}get conversationId(){return l(this,R).conversationId}get messages(){return l(this,R).messages}firstUpdated(){g(this,P,Ls).call(this)}updated(){g(this,P,Ls).call(this)}render(){Al(this.config,"config is required");let r=sl(this.messages,n=>{try{let i=new Date(n.timestamp),s=Math.floor(i.getUTCMinutes()/5)*5;return i.setUTCMinutes(s,0,0),i.valueOf().toString()}catch(i){console.error(i)}});return h`
|
|
526
|
+
`}console.warn(c.issues);break}case"order-status-card-v1":return h`<mw-product-order-status-card order-details="${JSON.stringify(t.data)}" ?streaming="${!a}" ?links-new-tab="${i}"></mw-product-order-status-card> `}return console.warn("could not render part:",t),h`<p><i>data type not supported</i></p>`}var Ar,Nt,Ne,lt,Jn,gl,Zn=class{constructor(e,r,{timeoutMs:n=2e3}={}){d(this,Jn);d(this,Ar);d(this,Nt);d(this,Ne);d(this,lt,!1);w(this,"timeoutMs");m(this,Ar,e),m(this,Nt,r),this.timeoutMs=n,e.addController(this)}get isTyping(){return l(this,lt)}hostDisconnected(){clearTimeout(l(this,Ne)),m(this,Ne,void 0)}onInput(e){if(l(this,Ar).isConnected){if(!e.trim()){this.typingStopped();return}clearTimeout(l(this,Ne)),m(this,Ne,setTimeout(()=>this.typingStopped(),this.timeoutMs)),l(this,lt)||g(this,Jn,gl).call(this)}}typingStopped(){clearTimeout(l(this,Ne)),m(this,lt,!1),l(this,Nt).typingStopped()}};Ar=new WeakMap,Nt=new WeakMap,Ne=new WeakMap,lt=new WeakMap,Jn=new WeakSet,gl=function(){m(this,lt,!0),l(this,Nt).typingStarted()};function yl(t,e="en-US"){let r=new Intl.DateTimeFormat(e,{hour:"numeric",minute:"numeric"}).format(t);return`${t.toLocaleDateString(e,{year:"numeric",month:"short",day:"numeric"})}, ${r}`}var vl=()=>{if(window.Shopify)try{return{customerId:tp()}}catch{return null}return null},tp=()=>{try{let t=[()=>window.ShopifyAnalytics?.meta?.page?.customerId,()=>window.meta?.page?.customerId,()=>window._st?.cid,()=>window.ShopifyAnalytics?.lib?.user()?.traits()?.uniqToken];for(let e of t)try{let r=e();if(r)return r}catch{}}catch{return null}return null},wl=async()=>{try{return(await(await fetch(window.Shopify.routes.root+"cart.js")).json()).items.map(n=>({id:n.id,name:n.title,quantity:n.quantity,price:n.price,variantId:n.variant_id,sku:n.sku,url:n.url,description:n.product_description,image:n.featured_image?.url}))}catch{return[]}};var bl=()=>{if(window.ShopRenter)try{let t=np();return{customerEmail:t?.customerEmail,customerId:t?.customerId,customerName:t?.customerName}}catch{return null}return null},np=()=>{try{if(window.ShopRenter){let t=window.ShopRenter.customer;return{customerEmail:t?.email,customerId:t?.userId,customerName:[t?.name?.firstName,t?.name?.lastName].filter(Boolean).join(" ")}}return{customerEmail:null,customerId:null,customerName:null}}catch{return{customerEmail:null,customerId:null,customerName:null}}},xl=async()=>{try{let t=window.ShopRenter.shop?.domain;if(!t)return[];let e=ga(t,"https")+"/cart.json";return(await(await fetch(e)).json()).items.map(s=>({id:s.id,name:s.name,quantity:s.quantity,price:s.price,sku:s.sku,image:s.image,url:s.href}))}catch{return[]}};var kl=()=>{if(window.UNAS)try{let t=window.UNAS.customer;return{customerEmail:t?.email,customerId:t?.id}}catch(t){return console.error("Error fetching customer information:",t),null}return null},Cl=async()=>new Promise((t,e)=>{try{window.UNAS.getCart(r=>{let i=r.items.map(s=>({id:s.id,name:s.name,quantity:s.quantity,price:s.price,sku:s.sku}));t(i)})}catch(r){console.error("Error fetching cart information:",r),e(r)}});var $l=Wn(q(),Vt([q(),zn(),Ms(),Is()])),Sl=hl(q(),_s(1),Es(5e3)),El=()=>{try{return window.UNAS?kl():window.Shopify?vl():window.ShopRenter?bl():null}catch{return null}},_l=async()=>{try{return window.UNAS?await Cl():window.Shopify?await wl():window.ShopRenter?await xl():[]}catch{return[]}},Ft={schema:Ie({conversationId:Ut(q()),messages:Ut(Pt(Ie({id:q(),timestamp:zn(),role:Ts(["user","assistant","support"]),content:q(),parts:Ut(Pt(Vt([Ie({text:q()}),Ie({html:q()}),Ie({tag:q(),data:Wn(q(),As())})])))})))}),getStorageKey(t){if(!t)throw new Error("widgetId is not set");return`_molin_${t}`},persist(t,e,r){let n=this.getStorageKey(t);localStorage.setItem(n,JSON.stringify({conversationId:e,messages:r}))},restore(t){try{let e=this.getStorageKey(t),r=JSON.parse(localStorage.getItem(e)||"{}"),n=pl(this.schema,r);return{conversationId:n.conversationId||"",messages:n.messages||[]}}catch(e){return console.error("Failed to restore conversation state:",e),{conversationId:"",messages:[]}}},reset(t){let e=this.getStorageKey(t);localStorage.removeItem(e)}};var op=!0,Os="Invariant failed";function Al(t,e){if(!t){if(op)throw new Error(Os);var r=typeof e=="function"?e():e,n=r?"".concat(Os,": ").concat(r):Os;throw new Error(n)}}var ap="\xB7 \xB7 \xB7",Fe,He,P,Ls,Ir,ut,R,Tr,Ml,Il,Tl,Ol,jl,Ll,Dl,Rl,Xn,Kn=class Kn extends M(E){constructor(){super();d(this,P);d(this,Fe);d(this,He);d(this,Ir,new Zn(this,{typingStarted:()=>l(this,R).sendUserTypingStart(),typingStopped:()=>l(this,R).sendUserTypingStop()}));d(this,ut,!1);d(this,R,new qn(this,{url:r=>{let n=new URL(this.config.wsApiUrl);return n.searchParams.set("widgetId",this.widgetId),n.searchParams.set("conversationId",r),n.searchParams.set("pageUrl",window.location.href),n},onReconnect:()=>{},onError:r=>{console.error("ws error",r)},onClose:()=>{},onNewMessage:r=>{m(this,ut,!1),r.role==="user"&&l(this,P,Xn)?.scrollTo(0,l(this,P,Xn).scrollHeight),r.role==="assistant"&&this.callbacks.onNewMessageStartedStreaming?.({widgetId:this.widgetId,message:r,conversationId:this.conversationId})},onMessageAppend:r=>{let n=l(this,P,Xn);if(!n)return;let i=l(this,R).lastMsg;!i||i.role!=="assistant"||requestAnimationFrame(()=>{let s=n.querySelector(`[data-id="${i.id}"]`);if(!s)return;let o=s.offsetHeight,u=n.getClientRects()[0].height-70;o>u&&!l(this,ut)&&(n.scrollTop=s.offsetTop-80)})},onMessageDone:(r,n)=>{m(this,ut,!1),n.role==="assistant"&&this.callbacks.onMessageEndedStreaming?.({widgetId:this.widgetId,text:n.content??"",message:n,usage_TOKENS_COMPLETION:r.message.usage.TOKENS_COMPLETION,conversationId:this.conversationId})},onMessageError:r=>{console.error("ws message error",r),r.message&&this.callbacks.onError?.({widgetId:this.widgetId,error:"WS: "+r.message})},onReset:()=>{Ft.reset(this.widgetId)},onConnect:r=>{let n=El();l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,language:window.navigator.language,cart:[]}),_l().then(i=>{i?.length>0&&l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,cart:i,language:window.navigator.language})}).catch(i=>{console.error(i)})},persistConversationState:(r,n)=>{Ft.persist(this.widgetId,r,n)},restoreConversationState:()=>Ft.restore(this.widgetId)}));d(this,Tr,"single");this.widgetId="",this.config={},this.callbacks={},this.showClose=!1,this.xUserData={},this.xCustomInstructions=""}get conversationId(){return l(this,R).conversationId}get messages(){return l(this,R).messages}firstUpdated(){g(this,P,Ls).call(this)}updated(){g(this,P,Ls).call(this)}render(){Al(this.config,"config is required");let r=sl(this.messages,n=>{try{let i=new Date(n.timestamp),s=Math.floor(i.getUTCMinutes()/5)*5;return i.setUTCMinutes(s,0,0),i.valueOf().toString()}catch(i){console.error(i)}});return h`
|
|
527
527
|
<div class="relative mx-auto h-full bg-[#FDFDFD] font-sans text-base before:absolute before:inset-0 before:bg-[#8d8d8d] before:opacity-10 sm:rounded-[36px] sm:p-1.5 sm:before:rounded-[36px]">
|
|
528
528
|
<div
|
|
529
529
|
class="relative flex h-full flex-col bg-white shadow-[0px_4px_4px_0px_rgba(0,0,0,0.25),-116px_177px_59px_0px_rgba(0,0,0,0.00),-74px_113px_54px_0px_rgba(0,0,0,0.01),-42px_64px_46px_0px_rgba(0,0,0,0.03),-19px_28px_34px_0px_rgba(0,0,0,0.06)] sm:rounded-[30px]">
|