@molin.ai/shop-ai 0.8.29 → 0.8.30

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.
@@ -572,7 +572,7 @@ var uu=Object.defineProperty;var Qs=t=>{throw TypeError(t)};var cu=(t,e,r)=>e in
572
572
  ?links-new-tab="${i}"
573
573
  .searchParams="${s}"
574
574
  .imagesByProductUrl="${n}"></mw-product-card-horizontal>
575
- `}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 Ir,Nt,Ne,lt,Jn,vl,Gn=class{constructor(e,r,{timeoutMs:n=2e3}={}){d(this,Jn);d(this,Ir);d(this,Nt);d(this,Ne);d(this,lt,!1);y(this,"timeoutMs");m(this,Ir,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,Ir).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,vl).call(this)}}typingStopped(){clearTimeout(l(this,Ne)),m(this,lt,!1),l(this,Nt).typingStopped()}};Ir=new WeakMap,Nt=new WeakMap,Ne=new WeakMap,lt=new WeakMap,Jn=new WeakSet,vl=function(){m(this,lt,!0),l(this,Nt).typingStarted()};function wl(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 bl=()=>{if(window.Shopify)try{return{customerId:n1()}}catch{return null}return null},n1=()=>{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&&r!=="00000000-0000-0000-0000-000000000000")return r}catch{}}catch{return null}return null},xl=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 kl=()=>{if(window.ShopRenter)try{let t=s1();return{customerEmail:t?.customerEmail,customerId:t?.customerId,customerName:t?.customerName}}catch{return null}return null},s1=()=>{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}}},Cl=async()=>{try{let t=window.ShopRenter.shop?.domain;if(!t)return[];let e=va(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 $l=()=>{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},Sl=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 El=Wn(q(),Vt([q(),zn(),Is(),Ls()])),_l=ml(q(),As(1),_s(5e3)),Al=()=>{try{return window.UNAS?$l():window.Shopify?bl():window.ShopRenter?kl():null}catch{return null}},Ml=async()=>{try{return window.UNAS?await Sl():window.Shopify?await xl():window.ShopRenter?await Cl():[]}catch{return[]}},Ft={schema:Le({conversationId:Ut(q()),messages:Ut(Pt(Le({id:q(),timestamp:zn(),role:Ts(["user","assistant","support"]),content:q(),parts:Ut(Pt(Vt([Le({text:q()}),Le({html:q()}),Le({tag:q(),data:Wn(q(),Ms())})])))})))}),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=hl(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 l1=!0,Os="Invariant failed";function Il(t,e){if(!t){if(l1)throw new Error(Os);var r=typeof e=="function"?e():e,n=r?"".concat(Os,": ").concat(r):Os;throw new Error(n)}}var u1="\xB7 \xB7 \xB7",Fe,He,P,Ds,Tr,ut,R,Or,Ll,Tl,Ol,jl,Dl,Rl,Pl,Ul,Xn,Kn=class Kn extends _(S){constructor(){super();d(this,P);d(this,Fe);d(this,He);d(this,Tr,new Gn(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=Al();l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,language:window.navigator.language,cart:[]}),Ml().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,Or,"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,Ds).call(this)}updated(){g(this,P,Ds).call(this)}render(){Il(this.config,"config is required");let r=al(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`
575
+ `}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 Ir,Nt,Ne,lt,Jn,vl,Gn=class{constructor(e,r,{timeoutMs:n=2e3}={}){d(this,Jn);d(this,Ir);d(this,Nt);d(this,Ne);d(this,lt,!1);y(this,"timeoutMs");m(this,Ir,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,Ir).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,vl).call(this)}}typingStopped(){clearTimeout(l(this,Ne)),m(this,lt,!1),l(this,Nt).typingStopped()}};Ir=new WeakMap,Nt=new WeakMap,Ne=new WeakMap,lt=new WeakMap,Jn=new WeakSet,vl=function(){m(this,lt,!0),l(this,Nt).typingStarted()};function wl(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 bl=()=>{if(window.Shopify)try{return{customerId:n1()}}catch{return null}return null},n1=()=>{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(/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(r))continue;if(r)return r}catch{}}catch{return null}return null},xl=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 kl=()=>{if(window.ShopRenter)try{let t=s1();return{customerEmail:t?.customerEmail,customerId:t?.customerId,customerName:t?.customerName}}catch{return null}return null},s1=()=>{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}}},Cl=async()=>{try{let t=window.ShopRenter.shop?.domain;if(!t)return[];let e=va(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 $l=()=>{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},Sl=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 El=Wn(q(),Vt([q(),zn(),Is(),Ls()])),_l=ml(q(),As(1),_s(5e3)),Al=()=>{try{return window.UNAS?$l():window.Shopify?bl():window.ShopRenter?kl():null}catch{return null}},Ml=async()=>{try{return window.UNAS?await Sl():window.Shopify?await xl():window.ShopRenter?await Cl():[]}catch{return[]}},Ft={schema:Le({conversationId:Ut(q()),messages:Ut(Pt(Le({id:q(),timestamp:zn(),role:Ts(["user","assistant","support"]),content:q(),parts:Ut(Pt(Vt([Le({text:q()}),Le({html:q()}),Le({tag:q(),data:Wn(q(),Ms())})])))})))}),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=hl(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 l1=!0,Os="Invariant failed";function Il(t,e){if(!t){if(l1)throw new Error(Os);var r=typeof e=="function"?e():e,n=r?"".concat(Os,": ").concat(r):Os;throw new Error(n)}}var u1="\xB7 \xB7 \xB7",Fe,He,P,Ds,Tr,ut,R,Or,Ll,Tl,Ol,jl,Dl,Rl,Pl,Ul,Xn,Kn=class Kn extends _(S){constructor(){super();d(this,P);d(this,Fe);d(this,He);d(this,Tr,new Gn(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=Al();l(this,R).sendUserMeta({xUserData:l(this,Fe),xCustomInstructions:l(this,He),customerInformation:n,language:window.navigator.language,cart:[]}),Ml().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,Or,"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,Ds).call(this)}updated(){g(this,P,Ds).call(this)}render(){Il(this.config,"config is required");let r=al(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`
576
576
  <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]">
577
577
  <div
578
578
  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]">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molin.ai/shop-ai",
3
- "version": "0.8.29",
3
+ "version": "0.8.30",
4
4
  "description": "Molin Shop AI",
5
5
  "keywords": [
6
6
  "molin",