@molin.ai/shop-ai 0.6.38 → 0.6.40
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/dist/molin-shop-ai.min.js +34 -34
- package/package.json +1 -1
|
@@ -28,7 +28,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
28
28
|
`);this.state="open",this.src=""}};C(ar,"properties",{state:{type:String},src:{type:String}});customElements.get("mw-bubble")||customElements.define("mw-bubble",ar);var lr={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},ur=n=>(...e)=>({_$litDirective$:n,values:e}),yn=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,i){this.t=e,this._$AM=t,this.i=i}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}};var{I:Jp}=Ra;var _l=()=>document.createComment(""),_n=(n,e,t)=>{let i=n._$AA.parentNode,r=e===void 0?n._$AB:e._$AA;if(t===void 0){let s=i.insertBefore(_l(),r),o=i.insertBefore(_l(),r);t=new Jp(s,o,n,n.options)}else{let s=t._$AB.nextSibling,o=t._$AM,a=o!==n;if(a){let l;t._$AQ?.(n),t._$AM=n,t._$AP!==void 0&&(l=n._$AU)!==o._$AU&&t._$AP(l)}if(s!==r||a){let l=t._$AA;for(;l!==s;){let u=l.nextSibling;i.insertBefore(l,r),l=u}}}return t},Rt=(n,e,t=n)=>(n._$AI(e,t),n),Yp={},bl=(n,e=Yp)=>n._$AH=e,wl=n=>n._$AH,cr=n=>{n._$AP?.(!1,!0);let e=n._$AA,t=n._$AB.nextSibling;for(;e!==t;){let i=e.nextSibling;e.remove(),e=i}};var xl=(n,e,t)=>{let i=new Map;for(let r=e;r<=t;r++)i.set(n[r],r);return i},ti=ur(class extends yn{constructor(n){if(super(n),n.type!==lr.CHILD)throw Error("repeat() can only be used in text expressions")}dt(n,e,t){let i;t===void 0?t=e:e!==void 0&&(i=e);let r=[],s=[],o=0;for(let a of n)r[o]=i?i(a,o):o,s[o]=t(a,o),o++;return{values:s,keys:r}}render(n,e,t){return this.dt(n,e,t).values}update(n,[e,t,i]){let r=wl(n),{values:s,keys:o}=this.dt(e,t,i);if(!Array.isArray(r))return this.ut=o,s;let a=this.ut??=[],l=[],u,c,p=0,f=r.length-1,d=0,g=s.length-1;for(;p<=f&&d<=g;)if(r[p]===null)p++;else if(r[f]===null)f--;else if(a[p]===o[d])l[d]=Rt(r[p],s[d]),p++,d++;else if(a[f]===o[g])l[g]=Rt(r[f],s[g]),f--,g--;else if(a[p]===o[g])l[g]=Rt(r[p],s[g]),_n(n,l[g+1],r[p]),p++,g--;else if(a[f]===o[d])l[d]=Rt(r[f],s[d]),_n(n,r[p],r[f]),f--,d++;else if(u===void 0&&(u=xl(o,d,g),c=xl(a,p,f)),u.has(a[p]))if(u.has(a[f])){let m=c.get(o[d]),E=m!==void 0?r[m]:null;if(E===null){let L=_n(n,r[p]);Rt(L,s[d]),l[d]=L}else l[d]=Rt(E,s[d]),_n(n,r[p],E),r[m]=null;d++}else cr(r[f]),f--;else cr(r[p]),p++;for(;d<=g;){let m=_n(n,l[g+1]);Rt(m,s[d]),l[d++]=m}for(;p<=f;){let m=r[p++];m!==null&&cr(m)}return this.ut=o,bl(n,l),nt}});function kl(n,e,t){return n?e(n):t?.(n)}var pr,Sl,fr=class fr extends z(U){constructor(){super();b(this,pr);this.examples={title:"",items:[]},this.color=""}render(){return!this.examples?.title&&!this.examples?.items?.length?N:D`
|
|
29
29
|
<div class="flex h-full w-full flex-1 flex-col overflow-y-auto px-4 pb-2 pt-6">
|
|
30
30
|
${kl(this.examples.title,()=>D`
|
|
31
|
-
<h2 class="mt-14 max-w-[18rem] px-2 pb-2 pt-9 text-3xl font-bold leading-tight tracking-tight">
|
|
31
|
+
<h2 class="mt-14 max-w-[18rem] px-2 pb-2 pt-9 text-left text-3xl font-bold leading-tight tracking-tight">
|
|
32
32
|
<span>${this.examples.title}</span>
|
|
33
33
|
<svg class="inline-block h-9 w-9 align-middle" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 58 61">
|
|
34
34
|
<path
|
|
@@ -40,7 +40,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
40
40
|
${this.examples?.items?.length?D`
|
|
41
41
|
<ul class="mt-auto flex select-none flex-wrap justify-end gap-2.5 text-sm/6 text-black">
|
|
42
42
|
${ti(this.examples.items,t=>t,t=>D`
|
|
43
|
-
<li class="border-1 hover:bg-[${this.color}]/[0.08] border-gray my-auto inline-block cursor-pointer rounded-2xl px-4 py-2 transition-all duration-200 hover:-translate-y-0.5 hover:opacity-80 hover:shadow" @click="${()=>$(this,pr,Sl).call(this,t)}">
|
|
43
|
+
<li class="border-1 hover:bg-[${this.color}]/[0.08] border-gray my-auto inline-block cursor-pointer rounded-2xl px-4 py-2 text-left transition-all duration-200 hover:-translate-y-0.5 hover:opacity-80 hover:shadow" @click="${()=>$(this,pr,Sl).call(this,t)}">
|
|
44
44
|
<span>${t.trim()}</span>
|
|
45
45
|
</li>
|
|
46
46
|
`)}
|
|
@@ -108,28 +108,26 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
108
108
|
background-image: linear-gradient(to bottom, white 20%, transparent);
|
|
109
109
|
}
|
|
110
110
|
`);var Kt=bn,Ws;Kt.NewChatClickEvent=(Ws=class extends CustomEvent{constructor(e={}){super(Kt.NewChatClickEvent.type,{...e})}},C(Ws,"type","mw:new-chat-click"),Ws);var Vs;Kt.CloseClickEvent=(Vs=class extends CustomEvent{constructor(e={}){super(Kt.CloseClickEvent.type,{...e})}},C(Vs,"type","mw:close-click"),Vs);customElements.get("mw-chat-header")||customElements.define("mw-chat-header",Kt);var Gs={maxHeight:120,initialHeight:32,paddingY:12},$e,Ks,Cl,Il,Al,Tl,Qs,xn=class xn extends z(U){constructor(){super();b(this,$e);this.disabled=!1,this.streaming=!1,this.placeholder="Type a message..."}render(){return D`
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
</slot>
|
|
132
|
-
</div>
|
|
111
|
+
<form @submit="${$(this,$e,Al)}" class="flex w-full items-center overflow-hidden rounded-[18px] bg-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.2)]">
|
|
112
|
+
<textarea name="input" @input="${$(this,$e,Tl)}" @keydown="${$(this,$e,Il)}" autofocus ?disabled="${this.disabled}" placeholder="${this.placeholder}" class="box-content h-[${Gs.initialHeight}px] w-full resize-none place-content-center rounded bg-white px-3 py-[${Gs.paddingY}px] text-base text-gray-800 outline-none"></textarea>
|
|
113
|
+
|
|
114
|
+
<button type="submit" ?disabled="${this.disabled}" class="mx-1 px-2 transition-opacity duration-200 hover:opacity-80">
|
|
115
|
+
${this.streaming?D`
|
|
116
|
+
<!-- x -->
|
|
117
|
+
<svg class="h-6 w-6 fill-current" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="#312E30">
|
|
118
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
|
|
119
|
+
</svg>
|
|
120
|
+
`:D`
|
|
121
|
+
<!-- airplane -->
|
|
122
|
+
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 35 34">
|
|
123
|
+
<path stroke="#312E30" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M33 16.99a1.07 1.07 0 0 0-.589-.955L5.107 2.22a2.162 2.162 0 0 0-2.515.447 2.141 2.141 0 0 0-.318 2.524L9.537 16.99 2.274 28.808a2.138 2.138 0 0 0 .318 2.524 2.157 2.157 0 0 0 2.515.447l27.304-13.832A1.075 1.075 0 0 0 33 16.99Zm0 0H9.53" />
|
|
124
|
+
</svg>
|
|
125
|
+
`}
|
|
126
|
+
</button>
|
|
127
|
+
</form>
|
|
128
|
+
<slot>
|
|
129
|
+
<div class="h-5 w-full"></div>
|
|
130
|
+
</slot>
|
|
133
131
|
`}};$e=new WeakSet,Ks=function(){return this.renderRoot.querySelector('textarea[name="input"]')??null},Cl=function(){return this.renderRoot.querySelector('button[type="submit"]')??null},Il=function(t){Kp(t)&&(t.preventDefault(),this.streaming||h(this,$e,Cl)?.click())},Al=function(t){if(t.preventDefault(),this.streaming){this.dispatchEvent(new xn.CancelEvent);return}let i=h(this,$e,Ks);if(!i)throw new Error("Expected input element to be present");i.value&&this.dispatchEvent(new xn.SubmitEvent(i.value))&&(i.value=""),$(this,$e,Qs).call(this)},Tl=function(t){this.dispatchEvent(new xn.ChangeEvent({delta:t.data,full:t.target instanceof HTMLTextAreaElement?t.target.value:""})),$(this,$e,Qs).call(this)},Qs=function(){let t=h(this,$e,Ks);if(!t)return;let{maxHeight:i,initialHeight:r,paddingY:s}=Gs;t.style.height=`${r}px`;let o=t.scrollHeight,a=s*2,l=Math.min(o-a,i);t.style.height=`${l}px`},C(xn,"properties",{disabled:{type:Boolean},streaming:{type:Boolean},placeholder:{type:String}});var mt=xn,Xs;mt.ChangeEvent=(Xs=class extends CustomEvent{constructor(e,t={}){super(mt.ChangeEvent.type,{detail:e,...t})}},C(Xs,"type","mw:change"),Xs);var Js;mt.SubmitEvent=(Js=class extends CustomEvent{constructor(e,t={}){super(mt.SubmitEvent.type,{detail:e,...t,cancelable:!0})}},C(Js,"type","mw:submit"),Js);var Ys;mt.CancelEvent=(Ys=class extends CustomEvent{constructor(e={}){super(mt.CancelEvent.type,{...e})}},C(Ys,"type","mw:cancel"),Ys);function Kp(n){return n.code==="Enter"&&!n.ctrlKey&&!n.metaKey&&!n.shiftKey}customElements.get("mw-chat-input")||customElements.define("mw-chat-input",mt);var dr=class extends z(U){constructor(){super(),this.side="assistant",this.status="",this.color="",this.logoUrl="",this.position="single"}render(){let e="rounded-2xl";switch(!0){case(this.side==="user"&&this.position==="single"):e="rounded-2xl";break;case(this.side==="user"&&["single-current","first"].includes(this.position)):e="rounded-2xl rounded-br-[4px]";break;case(this.side==="user"&&["middle","last-current"].includes(this.position)):e="rounded-2xl rounded-r-[4px]";break;case(this.side==="user"&&this.position==="last"):e="rounded-2xl rounded-tr-[4px]";break;case(["support","assistant"].includes(this.side)&&["single","single-current"].includes(this.position)):e="rounded-2xl";break;case(["support","assistant"].includes(this.side)&&this.position==="first"):e="rounded-2xl rounded-bl-[4px]";break;case(["support","assistant"].includes(this.side)&&this.position==="middle"):e="rounded-2xl rounded-l-[4px]";break;case(["support","assistant"].includes(this.side)&&["last","last-current"].includes(this.position)):e="rounded-2xl rounded-tl-[4px]";break;default:e="rounded-2xl";break}switch(this.side){case"user":return D`
|
|
134
132
|
<div class="ml-20 flex justify-end font-sans text-base">
|
|
135
133
|
<div class="max-w-full">
|
|
@@ -166,7 +164,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
166
164
|
</div>
|
|
167
165
|
</div>
|
|
168
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=>new Date(i.timestamp).setSeconds(0,0).toString());return D`
|
|
169
|
-
<div class="relative mx-auto h-full font-sans text-base before:absolute before:inset-0 before:bg-[#8d8d8d]
|
|
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]">
|
|
170
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]">
|
|
171
169
|
<mw-chat-header
|
|
172
170
|
class="absolute left-1.5 right-1.5 top-1.5"
|
|
@@ -183,7 +181,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
183
181
|
</div>
|
|
184
182
|
|
|
185
183
|
<!-- this structure of 2 divs is required for the browser native stick/scroll to bottom -->
|
|
186
|
-
<div id="scrollable-content" class="
|
|
184
|
+
<div id="scrollable-content" class="mt-6 flex h-full flex-shrink flex-grow flex-col-reverse overflow-auto bg-[#FDFDFD]">
|
|
187
185
|
${this.config?.showStillLearningBanner?D`
|
|
188
186
|
<div class="flex justify-center">
|
|
189
187
|
<div class="mb-2 flex max-w-[70%] select-none items-center justify-center rounded-full bg-black px-3 py-2">
|
|
@@ -221,7 +219,7 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
221
219
|
|
|
222
220
|
<!-- show typing indicator if the non-user side is typing -->
|
|
223
221
|
${["assistant","support"].includes(h(this,ae)?.typingIndicator?.role??"")&&h(this,ae)?.typingIndicator?.role?D`
|
|
224
|
-
<mw-chat-message class="mx-
|
|
222
|
+
<mw-chat-message class="mx-2 mb-3 block" color="${this.config.color}" logo="${h(this,ae)?.typingIndicator?.metadata?.avatar||this.config.logoUrl}" side="${h(this,ae).typingIndicator.role}">
|
|
225
223
|
<div class="prose break-words text-inherit">
|
|
226
224
|
<mw-loading class="-mx-2 block h-8 max-h-[24px] w-8 fill-[${this.config.color}]"></mw-loading>
|
|
227
225
|
</div>
|
|
@@ -236,17 +234,19 @@ var ep=Object.defineProperty;var ha=n=>{throw TypeError(n)};var tp=(n,e,t)=>e in
|
|
|
236
234
|
@mw:example-click="${$(this,se,zl)}"></mw-chat-background>
|
|
237
235
|
</div>
|
|
238
236
|
|
|
239
|
-
<div class="flex-shrink-0 flex-grow-0 space-y-2
|
|
240
|
-
<mw-chat-input @mw:change="${$(this,se,Vl)}" @mw:submit="${$(this,se,Wl)}" @mw:cancel="${$(this,se,Gl)}" placeholder="${this.config.input?.placeholder}" ?disabled="${h(this,ae).ranOutOfCredits}" ?streaming="${h(this,ae)?.isStreaming??!0}">
|
|
241
|
-
<!-- spacing between input box and powered-by or bottom -->
|
|
242
|
-
<div class="h-1"></div>
|
|
237
|
+
<div class="m-1.5 flex-shrink-0 flex-grow-0 space-y-2 rounded-3xl bg-[#eeedf1] p-1.5">
|
|
238
|
+
<mw-chat-input @mw:change="${$(this,se,Vl)}" @mw:submit="${$(this,se,Wl)}" @mw:cancel="${$(this,se,Gl)}" placeholder="${this.config.input?.placeholder}" ?disabled="${h(this,ae).ranOutOfCredits}" ?streaming="${h(this,ae)?.isStreaming??!0}"> </mw-chat-input>
|
|
243
239
|
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
${this.config.removePoweredBy?N:D`
|
|
241
|
+
<!-- spacing between input box and powered-by or bottom -->
|
|
242
|
+
<div class="h-4">
|
|
243
|
+
<mw-powered-by></mw-powered-by>
|
|
244
|
+
</div>
|
|
245
|
+
`}
|
|
246
246
|
</div>
|
|
247
247
|
</div>
|
|
248
248
|
</div>
|
|
249
|
-
`}reloadConfig(){h(this,ae).reloadConfig(),this.requestUpdate()}};se=new WeakSet,yr=function(){if(!this.widgetId)throw new Error("widgetId is not set");return`_molin_${this.widgetId}`},li=new WeakMap,ae=new WeakMap,ot=new WeakMap,Hl=function(t){let i=t.target;if(i instanceof HTMLAnchorElement){if(t.preventDefault(),this.callbacks.onUserClickedLink?.({widgetId:this.widgetId,url:i.href,conversationId:this.conversationId}),window.self!==window.top){window.open(i.href,"_blank");return}window.open(i.href,i.target)}},zl=function(t){let i=t.detail.example;if(!h(this,ae)?.sendUserInput(i)){t.preventDefault();return}this.callbacks.onUserSentInput?.({widgetId:this.widgetId,text:i,example:!0,conversationId:this.conversationId})},Wl=function(t){let i=t.detail;if(!h(this,ae)?.sendUserInput(i)){t.preventDefault();return}h(this,li).typingStopped(),this.callbacks.onUserSentInput?.({widgetId:this.widgetId,text:i,example:!1,conversationId:this.conversationId})},Vl=function(t){h(this,li).onInput(t.detail.full)},Gl=function(){h(this,ae)?.sendUserCancel(),this.callbacks.onUserCanceledStreaming?.({widgetId:this.widgetId})},Xl=function(){h(this,ae).reset()},Jl=function(){this.dispatchEvent(new _r.CloseClickEvent)},ro=function(){return this.renderRoot.querySelector("#scrollable-content")},C(_r,"properties",{config:{type:Object,attribute:!1},callbacks:{type:Object,attribute:!1},showClose:{type:Boolean,attribute:"show-close"}});var ai=_r,io;ai.CloseClickEvent=(io=class extends CustomEvent{constructor(e={}){super(ai.CloseClickEvent.type,{...e})}},C(io,"type","mw:close-click"),io);customElements.define("mw-chat",ai);var so=class extends z(U){constructor(){super(...arguments);C(this,"render",()=>D`
|
|
249
|
+
`}reloadConfig(){h(this,ae).reloadConfig(),this.requestUpdate()}};se=new WeakSet,yr=function(){if(!this.widgetId)throw new Error("widgetId is not set");return`_molin_${this.widgetId}`},li=new WeakMap,ae=new WeakMap,ot=new WeakMap,Hl=function(t){let i=t.target;if(i instanceof HTMLAnchorElement){if(t.preventDefault(),this.callbacks.onUserClickedLink?.({widgetId:this.widgetId,url:i.href,conversationId:this.conversationId}),window.self!==window.top){window.open(i.href,"_blank");return}window.open(i.href,i.target)}},zl=function(t){let i=t.detail.example;if(!h(this,ae)?.sendUserInput(i)){t.preventDefault();return}this.callbacks.onUserSentInput?.({widgetId:this.widgetId,text:i,example:!0,conversationId:this.conversationId})},Wl=function(t){let i=t.detail;if(!h(this,ae)?.sendUserInput(i)){t.preventDefault();return}h(this,li).typingStopped(),this.callbacks.onUserSentInput?.({widgetId:this.widgetId,text:i,example:!1,conversationId:this.conversationId})},Vl=function(t){h(this,li).onInput(t.detail.full)},Gl=function(){h(this,ae)?.sendUserCancel(),this.callbacks.onUserCanceledStreaming?.({widgetId:this.widgetId})},Xl=function(){h(this,ae).reset()},Jl=function(){this.dispatchEvent(new _r.CloseClickEvent)},ro=function(){return this.renderRoot.querySelector("#scrollable-content")},C(_r,"properties",{config:{type:Object,attribute:!1},callbacks:{type:Object,attribute:!1},showClose:{type:Boolean,attribute:"show-close"}});var ai=_r,io;ai.CloseClickEvent=(io=class extends CustomEvent{constructor(e={}){super(ai.CloseClickEvent.type,{...e})}},C(io,"type","mw:close-click"),io);customElements.get("mw-chat")||customElements.define("mw-chat",ai);var so=class extends z(U){constructor(){super(...arguments);C(this,"render",()=>D`
|
|
250
250
|
<svg class="leading-0 inline-block h-full w-full" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100" xml:space="preserve">
|
|
251
251
|
<circle fill="currentFill" stroke="none" cx="27" cy="50" r="6">
|
|
252
252
|
<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1" />
|