@molin.ai/shop-ai 0.6.41 → 0.6.42
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.
|
@@ -163,7 +163,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
163
163
|
</div>
|
|
164
164
|
</div>
|
|
165
165
|
</div>
|
|
166
|
-
`;default:throw new Error(`Unknown side: ${this.side}`)}}};C(dr,"properties",{side:{type:String},status:{type:String},color:{type:String},logoUrl:{type:String,attribute:"logo"},position:{type:String}});customElements.get("mw-chat-message")||customElements.define("mw-chat-message",dr);var ii,Ne,rt,ri,Zs,hr=class{constructor(e,t){b(this,ri);b(this,ii);b(this,Ne);b(this,rt);if(!e)throw new Error("host is required");if(!t)throw new Error("config is required");S(this,ii,e),h(this,ii).addController(this),S(this,Ne,t)}connect(e){S(this,Ne,e),S(this,rt,$(this,ri,Zs).call(this))}hostConnected(){setTimeout(()=>{S(this,rt,$(this,ri,Zs).call(this))},0)}hostDisconnected(){h(this,rt)?.close(1e3,"lit_host_disconnected"),S(this,rt,void 0)}send(e){h(this,rt)?.send(e)}close(e,t){h(this,rt)?.close(e,t)}render(e={}){switch(h(this,rt)?.readyState){case WebSocket.CLOSED:return e.closed?.();case WebSocket.CLOSING:return e.closing?.();case WebSocket.CONNECTING:return e.connecting?.();case WebSocket.OPEN:return e.open?.()}}get isConnected(){return h(this,rt)?.readyState===WebSocket.OPEN}};ii=new WeakMap,Ne=new WeakMap,rt=new WeakMap,ri=new WeakSet,Zs=function(){let e=new WebSocket(h(this,Ne).url());return h(this,Ne).onClose&&(e.onclose=h(this,Ne).onClose),h(this,Ne).onOpen&&(e.onopen=h(this,Ne).onOpen),h(this,Ne).onError&&(e.onerror=h(this,Ne).onError),h(this,Ne).onMessage&&(e.onmessage=h(this,Ne).onMessage),e};var Rl="664df22d-d461-42d6-801e-f70247e2cd7c",me,ye,st,kn,Sn,we,Qt,Pl,Ol,Fl,Ml,vr=class{constructor(e,t){b(this,we);b(this,me);b(this,ye);b(this,st);C(this,"isStreaming",!1);C(this,"typingIndicator");C(this,"ranOutOfCredits",!1);C(this,"messages",[]);C(this,"conversationId","");b(this,kn,0);b(this,Sn);C(this,"isLiveMode",!1);S(this,me,e),S(this,ye,t),S(this,st,this.initWS()),e.addController(this)}sendUserInput(e,{role:t="user",expectStreaming:i=!1}={}){return $(this,we,Qt).call(this,{type:"USER_INPUT",value:e,role:t},{expectStreaming:i})}sendUserCancel(){return $(this,we,Qt).call(this,{type:"USER_CANCEL"})}sendUserTypingStart(){return $(this,we,Qt).call(this,{type:"USER_TYPING_START"})}sendUserTypingStop(){return $(this,we,Qt).call(this,{type:"USER_TYPING_STOP"})}reloadConfig(){$(this,we,Qt).call(this,{type:"RELOAD_CONFIG"})}close(){h(this,st).close(1e3,"closed by user")}retry(){clearTimeout(h(this,Sn)),S(this,Sn,setTimeout(()=>{h(this,ye).onReconnect?.(),S(this,st,this.initWS())},1e3*h(this,kn))),va(this,kn)._++}initWS(){return new hr(h(this,me),{url:()=>h(this,ye).url(this.conversationId,{}),onOpen:e=>$(this,we,Pl).call(this,e),onMessage:e=>$(this,we,Ol).call(this,JSON.parse(e.data)),onError:e=>$(this,we,Fl).call(this,e),onClose:e=>$(this,we,Ml).call(this,e)})}hostConnected(){this.conversationId=h(this,ye).restoreConversationState?.()?.conversationId||"",this.messages=h(this,ye).restoreConversationState?.()?.messages||[]}reset(){$(this,we,Qt).call(this,{type:"NEW_CHAT"}),h(this,ye).onReset?.(),this.isStreaming=!1,this.typingIndicator=void 0,this.ranOutOfCredits=!1,this.messages=[],this.conversationId="",this.isLiveMode=!1,h(this,me).requestUpdate()}hostDisconnected(){clearTimeout(h(this,Sn))}reconnectSocket(){h(this,st).close(1e3,"destroy"),S(this,st,this.initWS())}get lastMsg(){if(this.messages.length>0)return this.messages[this.messages.length-1]}};me=new WeakMap,ye=new WeakMap,st=new WeakMap,kn=new WeakMap,Sn=new WeakMap,we=new WeakSet,Qt=function(e,{expectStreaming:t=!1}={}){return h(this,st).isConnected?(t&&!this.isLiveMode&&(this.isStreaming=!0,h(this,me).requestUpdate()),h(this,st).send(JSON.stringify(e)),!0):(console.warn("WebSocket is not connected, message not sent - reconnecting now",e),this.retry(),!1)},Pl=function(e){S(this,kn,0)},Ol=function(e){switch(e.type){case"NEW_MESSAGE":{this.messages=[...this.messages,e.message].filter((t,i,r)=>i===r.findIndex(s=>s.id===t.id)),this.typingIndicator=void 0,h(this,me).requestUpdate(),h(this,ye).onNewMessage?.(e.message);break}case"UPDATE_MESSAGE":{let t=this.messages.find(i=>i.id===e.message.id);if(t)Object.assign(t,e.message),h(this,me).requestUpdate(),h(this,ye).onUpdateMessage?.(e);else throw new Error(`Message with id ${e.message.id} not found`);break}case"MESSAGE_DONE":{let t=this.messages.find(i=>i.id===e.message.id);if(t)Object.assign(t,e.message);else throw new Error(`Message with id ${e.message.id} not found`);this.isStreaming=!1,h(this,me).requestUpdate(),h(this,ye).onMessageDone?.(e,t),h(this,ye).persistConversationState?.(this.conversationId,this.messages);break}case"MESSAGE_CANCEL":{this.isStreaming=!1,this.typingIndicator=void 0,h(this,me).requestUpdate();break}case"ERROR":{h(this,ye).onMessageError?.(e);break}case"CONNECTED":{this.conversationId=e.conversationId,this.messages=e.messages,h(this,ye).onConnect?.(e.conversationId),h(this,ye).persistConversationState?.(this.conversationId,this.messages),this.isLiveMode=e.metadata?.isLiveMode,h(this,me).requestUpdate();break}case"TYPING_START":{e.role==="assistant"&&(this.isStreaming=!0),this.typingIndicator={role:e.role,metadata:e.metadata},h(this,me).requestUpdate();break}case"TYPING_STOP":{this.typingIndicator=void 0,h(this,me).requestUpdate();break}case"RAN_OUT_OF_CREDITS":{this.messages.some(t=>t.id===Rl)||this.messages.push({id:Rl,role:"assistant",content:"Sorry, I've run out of credits. Please contact the shop directly.",timestamp:Date.now()}),this.ranOutOfCredits=!0,h(this,me).requestUpdate();break}case"RECONNECT":{this.reconnectSocket(),h(this,me).requestUpdate();break}default:console.warn(`Unknown message type: ${JSON.stringify(e)}`)}},Fl=function(e){console.error("onError",e),h(this,ye).onError?.(e)},Ml=function(e){h(this,me).isConnected&&!h(this,st).isConnected&&e.reason==="reconnect"&&this.retry(),this.isStreaming=!1,this.typingIndicator=void 0,h(this,me).requestUpdate(),h(this,ye).onClose?.()};var si,En,Pt,Zt,mr,Dl,gr=class{constructor(e,t,{timeoutMs:i=2e3}={}){b(this,mr);b(this,si);b(this,En);b(this,Pt);b(this,Zt,!1);C(this,"timeoutMs");S(this,si,e),S(this,En,t),this.timeoutMs=i,e.addController(this)}get isTyping(){return h(this,Zt)}hostDisconnected(){clearTimeout(h(this,Pt)),S(this,Pt,void 0)}onInput(e){if(h(this,si).isConnected){if(!e.trim()){this.typingStopped();return}clearTimeout(h(this,Pt)),S(this,Pt,setTimeout(()=>this.typingStopped(),this.timeoutMs)),h(this,Zt)||$(this,mr,Dl).call(this)}}typingStopped(){clearTimeout(h(this,Pt)),S(this,Zt,!1),h(this,En).typingStopped()}};si=new WeakMap,En=new WeakMap,Pt=new WeakMap,Zt=new WeakMap,mr=new WeakSet,Dl=function(){S(this,Zt,!0),h(this,En).typingStarted()};function Ll(n,e){let t=new Map;for(let i of n){let r=e(i);t.has(r)||t.set(r,[]),(t.get(r)||[]).push(i)}return t}function Nl(n,e="en-US"){let t=new Intl.DateTimeFormat(e,{hour:"numeric",minute:"numeric"}).format(n);return`${n.toLocaleDateString(e,{year:"numeric",month:"short",day:"numeric"})}, ${t}`}var eo;function Qp(n){return{lang:n?.lang??eo?.lang,message:n?.message,abortEarly:n?.abortEarly??eo?.abortEarly,abortPipeEarly:n?.abortPipeEarly??eo?.abortPipeEarly}}var Zp;function ef(n){return Zp?.get(n)}var tf;function nf(n){return tf?.get(n)}var rf;function sf(n,e){return rf?.get(n)?.get(e)}function $n(n){let e=typeof n;return e==="string"?`"${n}"`:e==="number"||e==="bigint"||e==="boolean"?`${n}`:e==="object"||e==="function"?(n&&Object.getPrototypeOf(n)?.constructor?.name)??"null":e}function Ot(n,e,t,i,r){let s=r&&"input"in r?r.input:t.value,o=r?.expected??n.expects??null,a=r?.received??$n(s),l={kind:n.kind,type:n.type,input:s,expected:o,received:a,message:`Invalid ${e}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:n.requirement,path:r?.path,issues:r?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},u=n.kind==="schema",c=r?.message??n.message??sf(n.reference,l.lang)??(u?nf(l.lang):null)??i.message??ef(l.lang);c&&(l.message=typeof c=="function"?c(l):c),u&&(t.typed=!1),t.issues?t.issues.push(l):t.issues=[l]}function of(n,e){let t=[...new Set(n)];return t.length>1?`(${t.join(` ${e} `)})`:t[0]??"never"}var af=class extends Error{constructor(e){super(e[0].message);C(this,"issues");this.name="ValiError",this.issues=e}};function to(n,e){return{kind:"validation",type:"max_value",reference:to,async:!1,expects:`<=${n instanceof Date?n.toJSON():$n(n)}`,requirement:n,message:e,_run(t,i){return t.typed&&t.value>this.requirement&&Ot(this,"value",t,i,{received:t.value instanceof Date?t.value.toJSON():$n(t.value)}),t}}}function no(n,e){return{kind:"validation",type:"min_value",reference:no,async:!1,expects:`>=${n instanceof Date?n.toJSON():$n(n)}`,requirement:n,message:e,_run(t,i){return t.typed&&t.value<this.requirement&&Ot(this,"value",t,i,{received:t.value instanceof Date?t.value.toJSON():$n(t.value)}),t}}}function lf(n,e,t){return typeof n.default=="function"?n.default(e,t):n.default}function yt(n,e){return{kind:"schema",type:"array",reference:yt,expects:"Array",async:!1,item:n,message:e,_run(t,i){let r=t.value;if(Array.isArray(r)){t.typed=!0,t.value=[];for(let s=0;s<r.length;s++){let o=r[s],a=this.item._run({typed:!1,value:o},i);if(a.issues){let l={type:"array",origin:"value",input:r,key:s,value:o};for(let u of a.issues)u.path?u.path.unshift(l):u.path=[l],t.issues?.push(u);if(t.issues||(t.issues=a.issues),i.abortEarly){t.typed=!1;break}}a.typed||(t.typed=!1),t.value.push(a.value)}}else Ot(this,"type",t,i);return t}}}function Ce(n){return{kind:"schema",type:"boolean",reference:Ce,expects:"boolean",async:!1,message:n,_run(e,t){return typeof e.value=="boolean"?e.typed=!0:Ot(this,"type",e,t),e}}}function He(n){return{kind:"schema",type:"number",reference:He,expects:"number",async:!1,message:n,_run(e,t){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:Ot(this,"type",e,t),e}}}function re(n,e){return{kind:"schema",type:"object",reference:re,expects:"Object",async:!1,entries:n,message:e,_run(t,i){let r=t.value;if(r&&typeof r=="object"){t.typed=!0,t.value={};for(let s in this.entries){let o=r[s],a=this.entries[s]._run({typed:!1,value:o},i);if(a.issues){let l={type:"object",origin:"value",input:r,key:s,value:o};for(let u of a.issues)u.path?u.path.unshift(l):u.path=[l],t.issues?.push(u);if(t.issues||(t.issues=a.issues),i.abortEarly){t.typed=!1;break}}a.typed||(t.typed=!1),(a.value!==void 0||s in r)&&(t.value[s]=a.value)}}else Ot(this,"type",t,i);return t}}}function A(n,...e){let t={kind:"schema",type:"optional",reference:A,expects:`(${n.expects} | undefined)`,async:!1,wrapped:n,_run(i,r){return i.value===void 0&&("default"in this&&(i.value=lf(this,i,r)),i.value===void 0)?(i.typed=!0,i):this.wrapped._run(i,r)}};return 0 in e&&(t.default=e[0]),t}function Cn(n,e){return{kind:"schema",type:"picklist",reference:Cn,expects:of(n.map($n),"|"),async:!1,options:n,message:e,_run(t,i){return this.options.includes(t.value)?t.typed=!0:Ot(this,"type",t,i),t}}}function j(n){return{kind:"schema",type:"string",reference:j,expects:"string",async:!1,message:n,_run(e,t){return typeof e.value=="string"?e.typed=!0:Ot(this,"type",e,t),e}}}function jl(n,e,t){let i=n._run({typed:!1,value:e},Qp(t));if(i.issues)throw new af(i.issues);return i.value}function ql(...n){return{...n[0],pipe:n,_run(e,t){for(let i of n)if(i.kind!=="metadata"){if(e.issues&&(i.kind==="schema"||i.kind==="transformation")){e.typed=!1;break}(!e.issues||!t.abortEarly&&!t.abortPipeEarly)&&(e=i._run(e,t))}return e}}}var Qv=re({wsApiUrl:j(),url:j(),logoUrl:A(j()),title:j(),status:j(),color:j(),showStillLearningBanner:A(Ce()),allowedOrigins:A(yt(j())),input:re({placeholder:j()}),bubble:re({imageUrl:A(j()),position:re({bottom:A(j()),right:A(j()),left:A(j())}),mobilePosition:A(re({bottom:A(j()),right:A(j()),left:A(j())}))}),examples:re({title:j(),items:yt(j())}),instructions:re({items:yt(j())}),popup:A(re({mobileEnabled:A(Ce()),desktopEnabled:A(Ce()),delayMs:A(He()),text:A(j()),mobileTitleText:A(j()),mobileButtonText:A(j())})),tryItOut:A(re({mobileEnabled:A(Ce()),desktopEnabled:A(Ce()),text:A(j())})),contactDetails:A(re({email:A(j()),phone:A(j()),socialMedia:A(re({facebook:A(j()),instagram:A(j()),twitter:A(j())}))})),neverShowStillLearningBanner:A(Ce()),hidden:A(Ce()),newChatTitle:A(j()),webhookURL:A(j()),automatedResponse:A(re({enabled:A(Ce()),text:A(j()),latencyThresholdMs:A(He())})),removePoweredBy:A(Ce()),claimable:A(Ce()),feed:A(j()),scraper:A(Cn(["netkazan","jateknet","grandopet","insportline","partocean","google-rev1"])),platform:A(Cn(["shopify","shoprenter","unas","scraper"])),workingHours:A(re({dailyAvailability:yt(re({dayOfWeek:ql(He(),no(0),to(6)),startTime:j(),endTime:j(),isActive:Ce()})),userTimeZone:A(j())})),planOverrides:A(re({maxProducts:A(He()),conversations:A(He()),faqs:A(re({max:A(He()),questionLength:A(He()),answerLength:A(He())}))})),omitGeneralGuidelines:A(Ce()),forceStripe:A(Ce()),products:A(re({blocklistUrls:A(yt(j()))})),autoRefresh:A(re({enabled:A(Ce()),intervalMins:A(He())})),lang:A(j())});var oi=class extends yn{constructor(e){if(super(e),this.it=N,e.type!==lr.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===N||e==null)return this._t=void 0,this.it=e;if(e===nt)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}};oi.directiveName="unsafeHTML",oi.resultType=1;var Bl=ur(oi);var uf="\xB7 \xB7 \xB7",cf=re({conversationId:A(j()),messages:A(yt(re({id:j(),timestamp:He(),role:Cn(["user","assistant","support"]),content:j(),content_html:A(j())})))}),se,yr,li,ae,ot,Hl,zl,Wl,Vl,Gl,Xl,Jl,ro,_r=class _r extends z(U){constructor(){super();b(this,se);b(this,li,new gr(this,{typingStarted:()=>h(this,ae).sendUserTypingStart(),typingStopped:()=>h(this,ae).sendUserTypingStop()}));b(this,ae,new vr(this,{url:(t,{resume:i}={})=>{let r=new URL(this.config.wsApiUrl);return r.searchParams.set("widgetId",this.widgetId),r.searchParams.set("resume",i?"1":""),r.searchParams.set("conversationId",t),r.searchParams.set("pageUrl",window.location.href),r},onReconnect:()=>{},onError:t=>{console.error("ws error",t)},onClose:()=>{},onNewMessage:t=>{t.role==="user"&&h(this,se,ro)?.scrollTo(0,h(this,se,ro).scrollHeight),t.role==="assistant"&&this.callbacks.onNewMessageStartedStreaming?.({widgetId:this.widgetId,message:t,conversationId:this.conversationId})},onMessageDone:(t,i)=>{i.role==="assistant"&&this.callbacks.onMessageEndedStreaming?.({widgetId:this.widgetId,text:i.content??"",message:i,usage_TOKENS_COMPLETION:t.message.usage.TOKENS_COMPLETION,conversationId:this.conversationId})},onMessageError:t=>{console.error("ws message error",t),t.message&&this.callbacks.onError?.({widgetId:this.widgetId,error:"WS: "+t.message})},onReset:()=>{localStorage.removeItem(h(this,se,yr))},onConnect:t=>{},persistConversationState:(t,i)=>{localStorage.setItem(h(this,se,yr),JSON.stringify({conversationId:t,messages:i}))},restoreConversationState:()=>{try{let t=JSON.parse(localStorage.getItem(h(this,se,yr))||"{}"),i=jl(cf,t);return{conversationId:i.conversationId||"",messages:i.messages||[]}}catch(t){return console.error(t),{conversationId:"",messages:[]}}}}));b(this,ot,"single");this.config={},this.callbacks={},this.showClose=!1}get widgetId(){return this.config.widgetId}get conversationId(){return h(this,ae).conversationId}get messages(){return h(this,ae).messages}render(){console.assert(this.config,"config is required");let t=Ll(this.messages,i=>{let r=new Date(i.timestamp),s=Math.floor(r.getUTCMinutes()/5)*5;return r.setUTCMinutes(s,0,0),r.toISOString()});return D`
|
|
166
|
+
`;default:throw new Error(`Unknown side: ${this.side}`)}}};C(dr,"properties",{side:{type:String},status:{type:String},color:{type:String},logoUrl:{type:String,attribute:"logo"},position:{type:String}});customElements.get("mw-chat-message")||customElements.define("mw-chat-message",dr);var ii,Ne,rt,ri,Zs,hr=class{constructor(e,t){b(this,ri);b(this,ii);b(this,Ne);b(this,rt);if(!e)throw new Error("host is required");if(!t)throw new Error("config is required");S(this,ii,e),h(this,ii).addController(this),S(this,Ne,t)}connect(e){S(this,Ne,e),S(this,rt,$(this,ri,Zs).call(this))}hostConnected(){setTimeout(()=>{S(this,rt,$(this,ri,Zs).call(this))},0)}hostDisconnected(){h(this,rt)?.close(1e3,"lit_host_disconnected"),S(this,rt,void 0)}send(e){h(this,rt)?.send(e)}close(e,t){h(this,rt)?.close(e,t)}render(e={}){switch(h(this,rt)?.readyState){case WebSocket.CLOSED:return e.closed?.();case WebSocket.CLOSING:return e.closing?.();case WebSocket.CONNECTING:return e.connecting?.();case WebSocket.OPEN:return e.open?.()}}get isConnected(){return h(this,rt)?.readyState===WebSocket.OPEN}};ii=new WeakMap,Ne=new WeakMap,rt=new WeakMap,ri=new WeakSet,Zs=function(){let e=new WebSocket(h(this,Ne).url());return h(this,Ne).onClose&&(e.onclose=h(this,Ne).onClose),h(this,Ne).onOpen&&(e.onopen=h(this,Ne).onOpen),h(this,Ne).onError&&(e.onerror=h(this,Ne).onError),h(this,Ne).onMessage&&(e.onmessage=h(this,Ne).onMessage),e};var Rl="664df22d-d461-42d6-801e-f70247e2cd7c",me,ye,st,kn,Sn,we,Qt,Pl,Ol,Fl,Ml,vr=class{constructor(e,t){b(this,we);b(this,me);b(this,ye);b(this,st);C(this,"isStreaming",!1);C(this,"typingIndicator");C(this,"ranOutOfCredits",!1);C(this,"messages",[]);C(this,"conversationId","");b(this,kn,0);b(this,Sn);C(this,"isLiveMode",!1);S(this,me,e),S(this,ye,t),S(this,st,this.initWS()),e.addController(this)}sendUserInput(e,{role:t="user",expectStreaming:i=!1}={}){return $(this,we,Qt).call(this,{type:"USER_INPUT",value:e,role:t},{expectStreaming:i})}sendUserCancel(){return $(this,we,Qt).call(this,{type:"USER_CANCEL"})}sendUserTypingStart(){return $(this,we,Qt).call(this,{type:"USER_TYPING_START"})}sendUserTypingStop(){return $(this,we,Qt).call(this,{type:"USER_TYPING_STOP"})}reloadConfig(){$(this,we,Qt).call(this,{type:"RELOAD_CONFIG"})}close(){h(this,st).close(1e3,"closed by user")}retry(){clearTimeout(h(this,Sn)),S(this,Sn,setTimeout(()=>{h(this,ye).onReconnect?.(),S(this,st,this.initWS())},1e3*h(this,kn))),va(this,kn)._++}initWS(){return new hr(h(this,me),{url:()=>h(this,ye).url(this.conversationId,{}),onOpen:e=>$(this,we,Pl).call(this,e),onMessage:e=>$(this,we,Ol).call(this,JSON.parse(e.data)),onError:e=>$(this,we,Fl).call(this,e),onClose:e=>$(this,we,Ml).call(this,e)})}hostConnected(){this.conversationId=h(this,ye).restoreConversationState?.()?.conversationId||"",this.messages=h(this,ye).restoreConversationState?.()?.messages||[]}reset(){$(this,we,Qt).call(this,{type:"NEW_CHAT"}),h(this,ye).onReset?.(),this.isStreaming=!1,this.typingIndicator=void 0,this.ranOutOfCredits=!1,this.messages=[],this.conversationId="",this.isLiveMode=!1,h(this,me).requestUpdate()}hostDisconnected(){clearTimeout(h(this,Sn))}reconnectSocket(){h(this,st).close(1e3,"destroy"),S(this,st,this.initWS())}get lastMsg(){if(this.messages.length>0)return this.messages[this.messages.length-1]}};me=new WeakMap,ye=new WeakMap,st=new WeakMap,kn=new WeakMap,Sn=new WeakMap,we=new WeakSet,Qt=function(e,{expectStreaming:t=!1}={}){return h(this,st).isConnected?(t&&!this.isLiveMode&&(this.isStreaming=!0,h(this,me).requestUpdate()),h(this,st).send(JSON.stringify(e)),!0):(console.warn("WebSocket is not connected, message not sent - reconnecting now",e),this.retry(),!1)},Pl=function(e){S(this,kn,0)},Ol=function(e){switch(e.type){case"NEW_MESSAGE":{this.messages=[...this.messages,e.message].filter((t,i,r)=>i===r.findIndex(s=>s.id===t.id)),this.typingIndicator=void 0,h(this,me).requestUpdate(),h(this,ye).onNewMessage?.(e.message);break}case"UPDATE_MESSAGE":{let t=this.messages.find(i=>i.id===e.message.id);if(t)Object.assign(t,e.message),h(this,me).requestUpdate(),h(this,ye).onUpdateMessage?.(e);else throw new Error(`Message with id ${e.message.id} not found`);break}case"MESSAGE_DONE":{let t=this.messages.find(i=>i.id===e.message.id);if(t)Object.assign(t,e.message);else throw new Error(`Message with id ${e.message.id} not found`);this.isStreaming=!1,h(this,me).requestUpdate(),h(this,ye).onMessageDone?.(e,t),h(this,ye).persistConversationState?.(this.conversationId,this.messages);break}case"MESSAGE_CANCEL":{this.isStreaming=!1,this.typingIndicator=void 0,h(this,me).requestUpdate();break}case"ERROR":{h(this,ye).onMessageError?.(e);break}case"CONNECTED":{this.conversationId=e.conversationId,this.messages=e.messages,h(this,ye).onConnect?.(e.conversationId),h(this,ye).persistConversationState?.(this.conversationId,this.messages),this.isLiveMode=e.metadata?.isLiveMode,h(this,me).requestUpdate();break}case"TYPING_START":{e.role==="assistant"&&(this.isStreaming=!0),this.typingIndicator={role:e.role,metadata:e.metadata},h(this,me).requestUpdate();break}case"TYPING_STOP":{this.typingIndicator=void 0,h(this,me).requestUpdate();break}case"RAN_OUT_OF_CREDITS":{this.messages.some(t=>t.id===Rl)||this.messages.push({id:Rl,role:"assistant",content:"Sorry, I've run out of credits. Please contact the shop directly.",timestamp:Date.now()}),this.ranOutOfCredits=!0,h(this,me).requestUpdate();break}case"RECONNECT":{this.reconnectSocket(),h(this,me).requestUpdate();break}default:console.warn(`Unknown message type: ${JSON.stringify(e)}`)}},Fl=function(e){console.error("onError",e),h(this,ye).onError?.(e)},Ml=function(e){h(this,me).isConnected&&!h(this,st).isConnected&&e.reason==="reconnect"&&this.retry(),this.isStreaming=!1,this.typingIndicator=void 0,h(this,me).requestUpdate(),h(this,ye).onClose?.()};var si,En,Pt,Zt,mr,Dl,gr=class{constructor(e,t,{timeoutMs:i=2e3}={}){b(this,mr);b(this,si);b(this,En);b(this,Pt);b(this,Zt,!1);C(this,"timeoutMs");S(this,si,e),S(this,En,t),this.timeoutMs=i,e.addController(this)}get isTyping(){return h(this,Zt)}hostDisconnected(){clearTimeout(h(this,Pt)),S(this,Pt,void 0)}onInput(e){if(h(this,si).isConnected){if(!e.trim()){this.typingStopped();return}clearTimeout(h(this,Pt)),S(this,Pt,setTimeout(()=>this.typingStopped(),this.timeoutMs)),h(this,Zt)||$(this,mr,Dl).call(this)}}typingStopped(){clearTimeout(h(this,Pt)),S(this,Zt,!1),h(this,En).typingStopped()}};si=new WeakMap,En=new WeakMap,Pt=new WeakMap,Zt=new WeakMap,mr=new WeakSet,Dl=function(){S(this,Zt,!0),h(this,En).typingStarted()};function Ll(n,e){let t=new Map;for(let i of n){let r=e(i);t.has(r)||t.set(r,[]),(t.get(r)||[]).push(i)}return t}function Nl(n,e="en-US"){let t=new Intl.DateTimeFormat(e,{hour:"numeric",minute:"numeric"}).format(n);return`${n.toLocaleDateString(e,{year:"numeric",month:"short",day:"numeric"})}, ${t}`}var eo;function Qp(n){return{lang:n?.lang??eo?.lang,message:n?.message,abortEarly:n?.abortEarly??eo?.abortEarly,abortPipeEarly:n?.abortPipeEarly??eo?.abortPipeEarly}}var Zp;function ef(n){return Zp?.get(n)}var tf;function nf(n){return tf?.get(n)}var rf;function sf(n,e){return rf?.get(n)?.get(e)}function $n(n){let e=typeof n;return e==="string"?`"${n}"`:e==="number"||e==="bigint"||e==="boolean"?`${n}`:e==="object"||e==="function"?(n&&Object.getPrototypeOf(n)?.constructor?.name)??"null":e}function Ot(n,e,t,i,r){let s=r&&"input"in r?r.input:t.value,o=r?.expected??n.expects??null,a=r?.received??$n(s),l={kind:n.kind,type:n.type,input:s,expected:o,received:a,message:`Invalid ${e}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:n.requirement,path:r?.path,issues:r?.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},u=n.kind==="schema",c=r?.message??n.message??sf(n.reference,l.lang)??(u?nf(l.lang):null)??i.message??ef(l.lang);c&&(l.message=typeof c=="function"?c(l):c),u&&(t.typed=!1),t.issues?t.issues.push(l):t.issues=[l]}function of(n,e){let t=[...new Set(n)];return t.length>1?`(${t.join(` ${e} `)})`:t[0]??"never"}var af=class extends Error{constructor(e){super(e[0].message);C(this,"issues");this.name="ValiError",this.issues=e}};function to(n,e){return{kind:"validation",type:"max_value",reference:to,async:!1,expects:`<=${n instanceof Date?n.toJSON():$n(n)}`,requirement:n,message:e,_run(t,i){return t.typed&&t.value>this.requirement&&Ot(this,"value",t,i,{received:t.value instanceof Date?t.value.toJSON():$n(t.value)}),t}}}function no(n,e){return{kind:"validation",type:"min_value",reference:no,async:!1,expects:`>=${n instanceof Date?n.toJSON():$n(n)}`,requirement:n,message:e,_run(t,i){return t.typed&&t.value<this.requirement&&Ot(this,"value",t,i,{received:t.value instanceof Date?t.value.toJSON():$n(t.value)}),t}}}function lf(n,e,t){return typeof n.default=="function"?n.default(e,t):n.default}function yt(n,e){return{kind:"schema",type:"array",reference:yt,expects:"Array",async:!1,item:n,message:e,_run(t,i){let r=t.value;if(Array.isArray(r)){t.typed=!0,t.value=[];for(let s=0;s<r.length;s++){let o=r[s],a=this.item._run({typed:!1,value:o},i);if(a.issues){let l={type:"array",origin:"value",input:r,key:s,value:o};for(let u of a.issues)u.path?u.path.unshift(l):u.path=[l],t.issues?.push(u);if(t.issues||(t.issues=a.issues),i.abortEarly){t.typed=!1;break}}a.typed||(t.typed=!1),t.value.push(a.value)}}else Ot(this,"type",t,i);return t}}}function Ce(n){return{kind:"schema",type:"boolean",reference:Ce,expects:"boolean",async:!1,message:n,_run(e,t){return typeof e.value=="boolean"?e.typed=!0:Ot(this,"type",e,t),e}}}function He(n){return{kind:"schema",type:"number",reference:He,expects:"number",async:!1,message:n,_run(e,t){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:Ot(this,"type",e,t),e}}}function re(n,e){return{kind:"schema",type:"object",reference:re,expects:"Object",async:!1,entries:n,message:e,_run(t,i){let r=t.value;if(r&&typeof r=="object"){t.typed=!0,t.value={};for(let s in this.entries){let o=r[s],a=this.entries[s]._run({typed:!1,value:o},i);if(a.issues){let l={type:"object",origin:"value",input:r,key:s,value:o};for(let u of a.issues)u.path?u.path.unshift(l):u.path=[l],t.issues?.push(u);if(t.issues||(t.issues=a.issues),i.abortEarly){t.typed=!1;break}}a.typed||(t.typed=!1),(a.value!==void 0||s in r)&&(t.value[s]=a.value)}}else Ot(this,"type",t,i);return t}}}function A(n,...e){let t={kind:"schema",type:"optional",reference:A,expects:`(${n.expects} | undefined)`,async:!1,wrapped:n,_run(i,r){return i.value===void 0&&("default"in this&&(i.value=lf(this,i,r)),i.value===void 0)?(i.typed=!0,i):this.wrapped._run(i,r)}};return 0 in e&&(t.default=e[0]),t}function Cn(n,e){return{kind:"schema",type:"picklist",reference:Cn,expects:of(n.map($n),"|"),async:!1,options:n,message:e,_run(t,i){return this.options.includes(t.value)?t.typed=!0:Ot(this,"type",t,i),t}}}function j(n){return{kind:"schema",type:"string",reference:j,expects:"string",async:!1,message:n,_run(e,t){return typeof e.value=="string"?e.typed=!0:Ot(this,"type",e,t),e}}}function jl(n,e,t){let i=n._run({typed:!1,value:e},Qp(t));if(i.issues)throw new af(i.issues);return i.value}function ql(...n){return{...n[0],pipe:n,_run(e,t){for(let i of n)if(i.kind!=="metadata"){if(e.issues&&(i.kind==="schema"||i.kind==="transformation")){e.typed=!1;break}(!e.issues||!t.abortEarly&&!t.abortPipeEarly)&&(e=i._run(e,t))}return e}}}var Qv=re({wsApiUrl:j(),url:j(),logoUrl:A(j()),title:j(),status:j(),color:j(),showStillLearningBanner:A(Ce()),allowedOrigins:A(yt(j())),input:re({placeholder:j()}),bubble:re({imageUrl:A(j()),position:re({bottom:A(j()),right:A(j()),left:A(j())}),mobilePosition:A(re({bottom:A(j()),right:A(j()),left:A(j())}))}),examples:re({title:j(),items:yt(j())}),instructions:re({items:yt(j())}),popup:A(re({mobileEnabled:A(Ce()),desktopEnabled:A(Ce()),delayMs:A(He()),text:A(j()),mobileTitleText:A(j()),mobileButtonText:A(j())})),tryItOut:A(re({mobileEnabled:A(Ce()),desktopEnabled:A(Ce()),text:A(j())})),contactDetails:A(re({email:A(j()),phone:A(j()),socialMedia:A(re({facebook:A(j()),instagram:A(j()),twitter:A(j())}))})),neverShowStillLearningBanner:A(Ce()),hidden:A(Ce()),newChatTitle:A(j()),webhookURL:A(j()),automatedResponse:A(re({enabled:A(Ce()),text:A(j()),latencyThresholdMs:A(He())})),removePoweredBy:A(Ce()),claimable:A(Ce()),feed:A(j()),scraper:A(Cn(["netkazan","jateknet","grandopet","insportline","partocean","google-rev1"])),platform:A(Cn(["shopify","shoprenter","unas","scraper"])),workingHours:A(re({dailyAvailability:yt(re({dayOfWeek:ql(He(),no(0),to(6)),startTime:j(),endTime:j(),isActive:Ce()})),userTimeZone:A(j())})),planOverrides:A(re({maxProducts:A(He()),conversations:A(He()),faqs:A(re({max:A(He()),questionLength:A(He()),answerLength:A(He())}))})),omitGeneralGuidelines:A(Ce()),forceStripe:A(Ce()),products:A(re({blocklistUrls:A(yt(j()))})),autoRefresh:A(re({enabled:A(Ce()),intervalMins:A(He())})),lang:A(j())});var oi=class extends yn{constructor(e){if(super(e),this.it=N,e.type!==lr.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===N||e==null)return this._t=void 0,this.it=e;if(e===nt)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}};oi.directiveName="unsafeHTML",oi.resultType=1;var Bl=ur(oi);var uf="\xB7 \xB7 \xB7",cf=re({conversationId:A(j()),messages:A(yt(re({id:j(),timestamp:He(),role:Cn(["user","assistant","support"]),content:j(),content_html:A(j())})))}),se,yr,li,ae,ot,Hl,zl,Wl,Vl,Gl,Xl,Jl,ro,_r=class _r extends z(U){constructor(){super();b(this,se);b(this,li,new gr(this,{typingStarted:()=>h(this,ae).sendUserTypingStart(),typingStopped:()=>h(this,ae).sendUserTypingStop()}));b(this,ae,new vr(this,{url:(t,{resume:i}={})=>{let r=new URL(this.config.wsApiUrl);return r.searchParams.set("widgetId",this.widgetId),r.searchParams.set("resume",i?"1":""),r.searchParams.set("conversationId",t),r.searchParams.set("pageUrl",window.location.href),r},onReconnect:()=>{},onError:t=>{console.error("ws error",t)},onClose:()=>{},onNewMessage:t=>{t.role==="user"&&h(this,se,ro)?.scrollTo(0,h(this,se,ro).scrollHeight),t.role==="assistant"&&this.callbacks.onNewMessageStartedStreaming?.({widgetId:this.widgetId,message:t,conversationId:this.conversationId})},onMessageDone:(t,i)=>{i.role==="assistant"&&this.callbacks.onMessageEndedStreaming?.({widgetId:this.widgetId,text:i.content??"",message:i,usage_TOKENS_COMPLETION:t.message.usage.TOKENS_COMPLETION,conversationId:this.conversationId})},onMessageError:t=>{console.error("ws message error",t),t.message&&this.callbacks.onError?.({widgetId:this.widgetId,error:"WS: "+t.message})},onReset:()=>{localStorage.removeItem(h(this,se,yr))},onConnect:t=>{},persistConversationState:(t,i)=>{localStorage.setItem(h(this,se,yr),JSON.stringify({conversationId:t,messages:i}))},restoreConversationState:()=>{try{let t=JSON.parse(localStorage.getItem(h(this,se,yr))||"{}"),i=jl(cf,t);return{conversationId:i.conversationId||"",messages:i.messages||[]}}catch(t){return console.error(t),{conversationId:"",messages:[]}}}}));b(this,ot,"single");this.config={},this.callbacks={},this.showClose=!1}get widgetId(){return this.config.widgetId}get conversationId(){return h(this,ae).conversationId}get messages(){return h(this,ae).messages}render(){console.assert(this.config,"config is required");let t=Ll(this.messages,i=>{try{let r=new Date(i.timestamp),s=Math.floor(r.getUTCMinutes()/5)*5;return r.setUTCMinutes(s,0,0),r.valueOf().toString()}catch(r){console.error(r)}});return D`
|
|
167
167
|
<div class="relative mx-auto h-full font-sans text-base before:absolute before:inset-0 before:bg-[#8d8d8d] before:opacity-10 sm:p-1.5 sm:before:rounded-[36px]">
|
|
168
168
|
<div 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]">
|
|
169
169
|
<mw-chat-header
|