@_solaris/messenger-widget 0.6.27 → 0.6.28

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.
@@ -14,7 +14,7 @@
14
14
  * @vue/runtime-dom v3.5.34
15
15
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
16
16
  * @license MIT
17
- **/let Ps;const xr=typeof window<"u"&&window.trustedTypes;if(xr)try{Ps=xr.createPolicy("vue",{createHTML:e=>e})}catch{}const ko=Ps?e=>Ps.createHTML(e):e=>e,Cl="http://www.w3.org/2000/svg",Sl="http://www.w3.org/1998/Math/MathML",lt=typeof document<"u"?document:null,Tr=lt&&lt.createElement("template"),Al={insert:(e,t,n)=>{t.insertBefore(e,n||null)},remove:e=>{const t=e.parentNode;t&&t.removeChild(e)},createElement:(e,t,n,r)=>{const i=t==="svg"?lt.createElementNS(Cl,e):t==="mathml"?lt.createElementNS(Sl,e):n?lt.createElement(e,{is:n}):lt.createElement(e);return e==="select"&&r&&r.multiple!=null&&i.setAttribute("multiple",r.multiple),i},createText:e=>lt.createTextNode(e),createComment:e=>lt.createComment(e),setText:(e,t)=>{e.nodeValue=t},setElementText:(e,t)=>{e.textContent=t},parentNode:e=>e.parentNode,nextSibling:e=>e.nextSibling,querySelector:e=>lt.querySelector(e),setScopeId(e,t){e.setAttribute(t,"")},insertStaticContent(e,t,n,r,i,s){const o=n?n.previousSibling:t.lastChild;if(i&&(i===s||i.nextSibling))for(;t.insertBefore(i.cloneNode(!0),n),!(i===s||!(i=i.nextSibling)););else{Tr.innerHTML=ko(r==="svg"?`<svg>${e}</svg>`:r==="mathml"?`<math>${e}</math>`:e);const a=Tr.content;if(r==="svg"||r==="mathml"){const l=a.firstChild;for(;l.firstChild;)a.appendChild(l.firstChild);a.removeChild(l)}t.insertBefore(a,n)}return[o?o.nextSibling:t.firstChild,n?n.previousSibling:t.lastChild]}},vt="transition",Xt="animation",_n=Symbol("_vtc"),Co={name:String,type:String,css:{type:Boolean,default:!0},duration:[String,Number,Object],enterFromClass:String,enterActiveClass:String,enterToClass:String,appearFromClass:String,appearActiveClass:String,appearToClass:String,leaveFromClass:String,leaveActiveClass:String,leaveToClass:String},xl=Ae({},Ni,Co),Tl=e=>(e.displayName="Transition",e.props=xl,e),Qs=Tl((e,{slots:t})=>wo(Aa,Ml(e),t)),Mt=(e,t=[])=>{W(e)?e.forEach(n=>n(...t)):e&&e(...t)},Mr=e=>e?W(e)?e.some(t=>t.length>1):e.length>1:!1;function Ml(e){const t={};for(const j in e)j in Co||(t[j]=e[j]);if(e.css===!1)return t;const{name:n="v",type:r,duration:i,enterFromClass:s=`${n}-enter-from`,enterActiveClass:o=`${n}-enter-active`,enterToClass:a=`${n}-enter-to`,appearFromClass:l=s,appearActiveClass:d=o,appearToClass:c=a,leaveFromClass:m=`${n}-leave-from`,leaveActiveClass:C=`${n}-leave-active`,leaveToClass:b=`${n}-leave-to`}=e,K=El(i),S=K&&K[0],J=K&&K[1],{onBeforeEnter:U,onEnter:$,onEnterCancelled:ne,onLeave:V,onLeaveCancelled:re,onBeforeAppear:ce=U,onAppear:_e=$,onAppearCancelled:we=ne}=t,G=(j,_,v,k)=>{j._enterCancelled=k,Et(j,_?c:a),Et(j,_?d:o),v&&v()},se=(j,_)=>{j._isLeaving=!1,Et(j,m),Et(j,b),Et(j,C),_&&_()},ue=j=>(_,v)=>{const k=j?_e:$,x=()=>G(_,j,v);Mt(k,[_,x]),Er(()=>{Et(_,j?l:s),at(_,j?c:a),Mr(k)||Or(_,r,S,x)})};return Ae(t,{onBeforeEnter(j){Mt(U,[j]),at(j,s),at(j,o)},onBeforeAppear(j){Mt(ce,[j]),at(j,l),at(j,d)},onEnter:ue(!1),onAppear:ue(!0),onLeave(j,_){j._isLeaving=!0;const v=()=>se(j,_);at(j,m),j._enterCancelled?(at(j,C),Lr(j)):(Lr(j),at(j,C)),Er(()=>{j._isLeaving&&(Et(j,m),at(j,b),Mr(V)||Or(j,r,J,v))}),Mt(V,[j,v])},onEnterCancelled(j){G(j,!1,void 0,!0),Mt(ne,[j])},onAppearCancelled(j){G(j,!0,void 0,!0),Mt(we,[j])},onLeaveCancelled(j){se(j),Mt(re,[j])}})}function El(e){if(e==null)return null;if(ae(e))return[ps(e.enter),ps(e.leave)];{const t=ps(e);return[t,t]}}function ps(e){return Po(e)}function at(e,t){t.split(/\s+/).forEach(n=>n&&e.classList.add(n)),(e[_n]||(e[_n]=new Set)).add(t)}function Et(e,t){t.split(/\s+/).forEach(r=>r&&e.classList.remove(r));const n=e[_n];n&&(n.delete(t),n.size||(e[_n]=void 0))}function Er(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}let Ol=0;function Or(e,t,n,r){const i=e._endId=++Ol,s=()=>{i===e._endId&&r()};if(n!=null)return setTimeout(s,n);const{type:o,timeout:a,propCount:l}=Rl(e,t);if(!o)return r();const d=o+"end";let c=0;const m=()=>{e.removeEventListener(d,C),s()},C=b=>{b.target===e&&++c>=l&&m()};setTimeout(()=>{c<l&&m()},a+1),e.addEventListener(d,C)}function Rl(e,t){const n=window.getComputedStyle(e),r=K=>(n[K]||"").split(", "),i=r(`${vt}Delay`),s=r(`${vt}Duration`),o=Rr(i,s),a=r(`${Xt}Delay`),l=r(`${Xt}Duration`),d=Rr(a,l);let c=null,m=0,C=0;t===vt?o>0&&(c=vt,m=o,C=s.length):t===Xt?d>0&&(c=Xt,m=d,C=l.length):(m=Math.max(o,d),c=m>0?o>d?vt:Xt:null,C=c?c===vt?s.length:l.length:0);const b=c===vt&&/\b(?:transform|all)(?:,|$)/.test(r(`${vt}Property`).toString());return{type:c,timeout:m,propCount:C,hasTransform:b}}function Rr(e,t){for(;e.length<t.length;)e=e.concat(e);return Math.max(...t.map((n,r)=>Ir(n)+Ir(e[r])))}function Ir(e){return e==="auto"?0:Number(e.slice(0,-1).replace(",","."))*1e3}function Lr(e){return(e?e.ownerDocument:document).body.offsetHeight}function Il(e,t,n){const r=e[_n];r&&(t=(t?[t,...r]:[...r]).join(" ")),t==null?e.removeAttribute("class"):n?e.setAttribute("class",t):e.className=t}const Pr=Symbol("_vod"),Ll=Symbol("_vsh"),Pl=Symbol(""),Bl=/(?:^|;)\s*display\s*:/;function Fl(e,t,n){const r=e.style,i=ye(n);let s=!1;if(n&&!i){if(t)if(ye(t))for(const o of t.split(";")){const a=o.slice(0,o.indexOf(":")).trim();n[a]==null&&tn(r,a,"")}else for(const o in t)n[o]==null&&tn(r,o,"");for(const o in n){o==="display"&&(s=!0);const a=n[o];a!=null?Nl(e,o,!ye(t)&&t?t[o]:void 0,a)||tn(r,o,a):tn(r,o,"")}}else if(i){if(t!==n){const o=r[Pl];o&&(n+=";"+o),r.cssText=n,s=Bl.test(n)}}else t&&e.removeAttribute("style");Pr in e&&(e[Pr]=s?r.display:"",e[Ll]&&(r.display="none"))}const Br=/\s*!important$/;function tn(e,t,n){if(W(n))n.forEach(r=>tn(e,t,r));else if(n==null&&(n=""),t.startsWith("--"))e.setProperty(t,n);else{const r=Dl(e,t);Br.test(n)?e.setProperty(At(r),n.replace(Br,""),"important"):e[r]=n}}const Fr=["Webkit","Moz","ms"],_s={};function Dl(e,t){const n=_s[t];if(n)return n;let r=De(t);if(r!=="filter"&&r in e)return _s[t]=r;r=Wn(r);for(let i=0;i<Fr.length;i++){const s=Fr[i]+r;if(s in e)return _s[t]=s}return t}function Nl(e,t,n,r){return e.tagName==="TEXTAREA"&&(t==="width"||t==="height")&&ye(r)&&n===r}const Dr="http://www.w3.org/1999/xlink";function Nr(e,t,n,r,i,s=Uo(t)){r&&t.startsWith("xlink:")?n==null?e.removeAttributeNS(Dr,t.slice(6,t.length)):e.setAttributeNS(Dr,t,n):n==null||s&&!ui(n)?e.removeAttribute(t):e.setAttribute(t,s?"":Ge(n)?String(n):n)}function Hr(e,t,n,r,i){if(t==="innerHTML"||t==="textContent"){n!=null&&(e[t]=t==="innerHTML"?ko(n):n);return}const s=e.tagName;if(t==="value"&&s!=="PROGRESS"&&!s.includes("-")){const a=s==="OPTION"?e.getAttribute("value")||"":e.value,l=n==null?e.type==="checkbox"?"on":"":String(n);(a!==l||!("_value"in e))&&(e.value=l),n==null&&e.removeAttribute(t),e._value=n;return}let o=!1;if(n===""||n==null){const a=typeof e[t];a==="boolean"?n=ui(n):n==null&&a==="string"?(n="",o=!0):a==="number"&&(n=0,o=!0)}try{e[t]=n}catch{}o&&e.removeAttribute(i||t)}function wt(e,t,n,r){e.addEventListener(t,n,r)}function Hl(e,t,n,r){e.removeEventListener(t,n,r)}const Ur=Symbol("_vei");function Ul(e,t,n,r,i=null){const s=e[Ur]||(e[Ur]={}),o=s[t];if(r&&o)o.value=r;else{const[a,l]=jl(t);if(r){const d=s[t]=zl(r,i);wt(e,a,d,l)}else o&&(Hl(e,a,o,l),s[t]=void 0)}}const jr=/(?:Once|Passive|Capture)$/;function jl(e){let t;if(jr.test(e)){t={};let r;for(;r=e.match(jr);)e=e.slice(0,e.length-r[0].length),t[r[0].toLowerCase()]=!0}return[e[2]===":"?e.slice(3):At(e.slice(2)),t]}let ys=0;const Vl=Promise.resolve(),Kl=()=>ys||(Vl.then(()=>ys=0),ys=Date.now());function zl(e,t){const n=r=>{if(!r._vts)r._vts=Date.now();else if(r._vts<=n.attached)return;Ye(Wl(r,n.value),t,5,[r])};return n.value=e,n.attached=Kl(),n}function Wl(e,t){if(W(t)){const n=e.stopImmediatePropagation;return e.stopImmediatePropagation=()=>{n.call(e),e._stopped=!0},t.map(r=>i=>!i._stopped&&r&&r(i))}else return t}const Vr=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&e.charCodeAt(2)>96&&e.charCodeAt(2)<123,$l=(e,t,n,r,i,s)=>{const o=i==="svg";t==="class"?Il(e,r,o):t==="style"?Fl(e,n,r):Vn(t)?Kn(t)||Ul(e,t,n,r,s):(t[0]==="."?(t=t.slice(1),!0):t[0]==="^"?(t=t.slice(1),!1):ql(e,t,r,o))?(Hr(e,t,r),!e.tagName.includes("-")&&(t==="value"||t==="checked"||t==="selected")&&Nr(e,t,r,o,s,t!=="value")):e._isVueCE&&(Gl(e,t)||e._def.__asyncLoader&&(/[A-Z]/.test(t)||!ye(r)))?Hr(e,De(t),r,s,t):(t==="true-value"?e._trueValue=r:t==="false-value"&&(e._falseValue=r),Nr(e,t,r,o))};function ql(e,t,n,r){if(r)return!!(t==="innerHTML"||t==="textContent"||t in e&&Vr(t)&&Q(n));if(t==="spellcheck"||t==="draggable"||t==="translate"||t==="autocorrect"||t==="sandbox"&&e.tagName==="IFRAME"||t==="form"||t==="list"&&e.tagName==="INPUT"||t==="type"&&e.tagName==="TEXTAREA")return!1;if(t==="width"||t==="height"){const i=e.tagName;if(i==="IMG"||i==="VIDEO"||i==="CANVAS"||i==="SOURCE")return!1}return Vr(t)&&ye(n)?!1:t in e}function Gl(e,t){const n=e._def.props;if(!n)return!1;const r=De(t);return Array.isArray(n)?n.some(i=>De(i)===r):Object.keys(n).some(i=>De(i)===r)}const zt=e=>{const t=e.props["onUpdate:modelValue"]||!1;return W(t)?n=>En(t,n):t};function Yl(e){e.target.composing=!0}function Kr(e){const t=e.target;t.composing&&(t.composing=!1,t.dispatchEvent(new Event("input")))}const mt=Symbol("_assign");function zr(e,t,n){return t&&(e=e.trim()),n&&(e=$n(e)),e}const kt={created(e,{modifiers:{lazy:t,trim:n,number:r}},i){e[mt]=zt(i);const s=r||i.props&&i.props.type==="number";wt(e,t?"change":"input",o=>{o.target.composing||e[mt](zr(e.value,n,s))}),(n||s)&&wt(e,"change",()=>{e.value=zr(e.value,n,s)}),t||(wt(e,"compositionstart",Yl),wt(e,"compositionend",Kr),wt(e,"change",Kr))},mounted(e,{value:t}){e.value=t??""},beforeUpdate(e,{value:t,oldValue:n,modifiers:{lazy:r,trim:i,number:s}},o){if(e[mt]=zt(o),e.composing)return;const a=(s||e.type==="number")&&!/^0\d/.test(e.value)?$n(e.value):e.value,l=t??"";if(a===l)return;const d=e.getRootNode();(d instanceof Document||d instanceof ShadowRoot)&&d.activeElement===e&&e.type!=="range"&&(r&&t===n||i&&e.value.trim()===l)||(e.value=l)}},Jl={deep:!0,created(e,t,n){e[mt]=zt(n),wt(e,"change",()=>{const r=e._modelValue,i=yn(e),s=e.checked,o=e[mt];if(W(r)){const a=Hs(r,i),l=a!==-1;if(s&&!l)o(r.concat(i));else if(!s&&l){const d=[...r];d.splice(a,1),o(d)}}else if(Wt(r)){const a=new Set(r);s?a.add(i):a.delete(i),o(a)}else o(So(e,s))})},mounted:Wr,beforeUpdate(e,t,n){e[mt]=zt(n),Wr(e,t,n)}};function Wr(e,{value:t,oldValue:n},r){e._modelValue=t;let i;if(W(t))i=Hs(t,r.props.value)>-1;else if(Wt(t))i=t.has(r.props.value);else{if(t===n)return;i=$t(t,So(e,!0))}e.checked!==i&&(e.checked=i)}const Xl={deep:!0,created(e,{value:t,modifiers:{number:n}},r){const i=Wt(t);wt(e,"change",()=>{const s=Array.prototype.filter.call(e.options,o=>o.selected).map(o=>n?$n(yn(o)):yn(o));e[mt](e.multiple?i?new Set(s):s:s[0]),e._assigning=!0,Oi(()=>{e._assigning=!1})}),e[mt]=zt(r)},mounted(e,{value:t}){$r(e,t)},beforeUpdate(e,t,n){e[mt]=zt(n)},updated(e,{value:t}){e._assigning||$r(e,t)}};function $r(e,t){const n=e.multiple,r=W(t);if(!(n&&!r&&!Wt(t))){for(let i=0,s=e.options.length;i<s;i++){const o=e.options[i],a=yn(o);if(n)if(r){const l=typeof a;l==="string"||l==="number"?o.selected=t.some(d=>String(d)===String(a)):o.selected=Hs(t,a)>-1}else o.selected=t.has(a);else if($t(yn(o),t)){e.selectedIndex!==i&&(e.selectedIndex=i);return}}!n&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function yn(e){return"_value"in e?e._value:e.value}function So(e,t){const n=t?"_trueValue":"_falseValue";return n in e?e[n]:t}const Ql=["ctrl","shift","alt","meta"],Zl={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>"button"in e&&e.button!==0,middle:e=>"button"in e&&e.button!==1,right:e=>"button"in e&&e.button!==2,exact:(e,t)=>Ql.some(n=>e[`${n}Key`]&&!t.includes(n))},We=(e,t)=>{if(!e)return e;const n=e._withMods||(e._withMods={}),r=t.join(".");return n[r]||(n[r]=(i,...s)=>{for(let o=0;o<t.length;o++){const a=Zl[t[o]];if(a&&a(i,t))return}return e(i,...s)})},ec={esc:"escape",space:" ",up:"arrow-up",left:"arrow-left",right:"arrow-right",down:"arrow-down",delete:"backspace"},Un=(e,t)=>{const n=e._withKeys||(e._withKeys={}),r=t.join(".");return n[r]||(n[r]=i=>{if(!("key"in i))return;const s=At(i.key);if(t.some(o=>o===s||ec[o]===s))return e(i)})},tc=Ae({patchProp:$l},Al);let qr;function nc(){return qr||(qr=rl(tc))}const sc=(...e)=>{const t=nc().createApp(...e),{mount:n}=t;return t.mount=r=>{const i=ic(r);if(!i)return;const s=t._component;!Q(s)&&!s.render&&!s.template&&(s.template=i.innerHTML),i.nodeType===1&&(i.textContent="");const o=n(i,!1,rc(i));return i instanceof Element&&(i.removeAttribute("v-cloak"),i.setAttribute("data-v-app","")),o},t};function rc(e){if(e instanceof SVGElement)return"svg";if(typeof MathMLElement=="function"&&e instanceof MathMLElement)return"mathml"}function ic(e){return ye(e)?document.querySelector(e):e}const oc=["connected","message","message_stream","conversation_updated","config_updated","action_status"],vs="/client",ac=5*60*1e3,lc=15*1e3,cc=10*60*1e3,uc=5*60*1e3;function dc(e){const t={baseUrl:fc(e.baseUrl||""),widgetId:e.widgetId||"",userId:"",origin:"",token:"",currentContext:{},listeners:new Map,eventSource:null,connection:"idle",visibilityHandler:null,started:!1,panelOpen:!1,pollTimer:null,burstTimer:null,hiddenGraceTimer:null,lastActivityAt:null};if(!t.baseUrl||!t.widgetId)throw new Error("[transport] baseUrl and widgetId are required");function n(y,A){return t.listeners.has(y)||t.listeners.set(y,new Set),t.listeners.get(y).add(A),()=>t.listeners.get(y).delete(A)}function r(y,A){const L=t.listeners.get(y);L&&L.forEach(X=>{try{X(A)}catch(ee){console.error("[transport] listener",y,ee)}})}function i(y){t.connection!==y&&(t.connection=y,r("connection",y))}function s(){return{"Content-Type":"application/json","X-Widget-Id":t.widgetId,...t.origin?{"X-Parent-Origin":t.origin}:{}}}async function o(y,A,L){const X=await fetch(`${t.baseUrl}${vs}${A}`,{method:y,credentials:"include",headers:s(),body:L!==void 0?JSON.stringify(L):void 0});if(!X.ok){const ee=await a(X),Pe=new Error(`HTTP ${X.status} ${y} ${A} :: ${(ee==null?void 0:ee.error)||X.statusText}`);throw Pe.status=X.status,Pe.body=ee,Pe}return X.status===204?null:X.json()}async function a(y){try{return await y.json()}catch{return null}}async function l(y){if(t.started)return t.lastBootstrap;if(!(y!=null&&y.origin))throw new Error("[transport] start requires origin");t.started=!0,t.origin=y.origin,t.token=y.token||"";const A=await fetch(`${t.baseUrl}${vs}/session`,{method:"POST",credentials:"include",headers:s(),body:JSON.stringify({origin:t.origin,...t.token?{token:t.token}:{},allowUnauthenticated:y.allowUnauthenticated===!0,...y.variables&&typeof y.variables=="object"?{variables:y.variables}:{}})});if(!A.ok){const Ke=await a(A),Ue=new Error(`Session bootstrap failed: HTTP ${A.status} :: ${(Ke==null?void 0:Ke.error)||A.statusText}`);throw Ue.status=A.status,Ue.body=Ke,Ue}const L=await A.json();t.userId=L.external_id;const[X,ee]=await Promise.all([fetch(`${t.baseUrl}/widgets/${encodeURIComponent(t.widgetId)}/config`,{credentials:"include"}).then(async Ke=>{if(!Ke.ok){const Ue=await a(Ke);throw new Error(`HTTP ${Ke.status} GET /widgets/:id/config :: ${(Ue==null?void 0:Ue.error)||Ke.statusText}`)}return Ke.json()}),o("GET","/customers/me")]),Pe={config:X,customer:(ee==null?void 0:ee.customer)??null};return t.lastBootstrap=Pe,await d(),typeof document<"u"&&(t.visibilityHandler=k,document.addEventListener("visibilitychange",t.visibilityHandler)),_(),Pe}async function d(){try{const y=await C();t.lastActivityAt=y.reduce((A,L)=>{const X=L==null?void 0:L.last_message_at;return X&&(!A||X>A)?X:A},null)}catch(y){console.error("[transport] initial /conversations failed",y)}}async function c(){const y=await o("GET","/customers/me");return(y==null?void 0:y.customer)??null}async function m(y){const A=await o("PATCH","/customers/me",y);return(A==null?void 0:A.customer)??null}async function C(){const y=await o("GET","/conversations");return(y==null?void 0:y.conversations)??[]}async function b(y={}){return(await o("POST","/conversations",y)).conversation}async function K(y){return(await o("GET",`/conversations/${encodeURIComponent(y)}`)).conversation}async function S(y,A){return(await o("PATCH",`/conversations/${encodeURIComponent(y)}`,A)).conversation}async function J(y,A){return o("PATCH",`/conversations/${encodeURIComponent(y)}/read`,{message_id:A})}async function U(y,A={}){const L=new URLSearchParams;A.before&&L.set("before",A.before),A.since&&L.set("since",A.since),A.limit&&L.set("limit",String(A.limit));const X=L.toString()?`?${L.toString()}`:"";return o("GET",`/conversations/${encodeURIComponent(y)}/messages${X}`)}async function $(y,A){se();const L={client_msg_id:A.client_msg_id,type:"content",text_md:A.text_md,author:{id:t.userId,type:"user"},created_at:A.created_at||new Date().toISOString()};return Array.isArray(A.attachments)&&A.attachments.length&&(L.payload={type:"content",attachments:A.attachments}),A.metadata&&typeof A.metadata=="object"&&(L.metadata=A.metadata),t.currentContext&&Object.keys(t.currentContext).length>0&&(L.context=t.currentContext),o("POST",`/conversations/${encodeURIComponent(y)}/messages`,L)}async function ne(y,A,L){return se(),o("POST",`/messages/${encodeURIComponent(y)}/callbacks/${encodeURIComponent(A)}`,L?{inputs:L}:{})}async function V(y){const A=y.name||"attachment",L=y.type||"application/octet-stream",X=y.size||0,ee=await o("POST","/attachments",{mime_type:L,size_bytes:X,name:A}),Pe=await fetch(ee.upload_url,{method:"PUT",headers:{"Content-Type":L},body:y});if(!Pe.ok)throw new Error(`HTTP ${Pe.status} PUT signed upload`);return{type:hc(L),path:ee.path,mime_type:L,size_bytes:X}}async function re(y){return o("GET",`/attachments/sign?path=${encodeURIComponent(y)}`)}function ce(){const y=new URLSearchParams({widgetId:t.widgetId}).toString();return`${t.baseUrl}${vs}/stream?${y}`}function _e(){if(!t.eventSource&&!(typeof document<"u"&&document.hidden)&&t.started)try{const y=new EventSource(ce(),{withCredentials:!0});for(const A of oc)y.addEventListener(A,L=>we(A,L.data));y.addEventListener("error",()=>r("error",new Error("SSE error"))),t.eventSource=y,i("open")}catch(y){console.error("[transport] SSE open failed",y),r("error",y)}}function we(y,A){try{const L=JSON.parse(A),X=L&&typeof L=="object"&&"data"in L?L.data:L;r(y,X)}catch(L){console.error("[transport] bad SSE payload",y,L)}}function G(){t.eventSource&&(t.eventSource.close(),t.eventSource=null),t.connection!=="paused"&&i("idle")}function se(){clearTimeout(t.burstTimer),_e(),t.panelOpen||(t.burstTimer=setTimeout(()=>{t.panelOpen||G()},cc))}function ue(y){const A=t.panelOpen;t.panelOpen=!!y,t.panelOpen?(clearTimeout(t.burstTimer),_e()):se(),A!==t.panelOpen&&_()}async function j(){try{const y=await C(),A=y.reduce((X,ee)=>{const Pe=ee==null?void 0:ee.last_message_at;return Pe&&(!X||Pe>X)?Pe:X},null);A&&(!t.lastActivityAt||A>t.lastActivityAt)&&(t.lastActivityAt=A,r("activity",{conversations:y,latestAt:A}),se())}catch(y){console.error("[transport] poll failed",y)}}function _(){if(v(),typeof document<"u"&&document.hidden)return;const y=t.panelOpen?lc:ac;t.pollTimer=setInterval(j,y)}function v(){t.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null)}function k(){if(document.hidden)clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=setTimeout(()=>{t.hiddenGraceTimer=null,document.hidden&&(v(),G(),i("paused"))},uc);else{if(t.hiddenGraceTimer){clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null;return}i("idle"),_(),t.panelOpen&&_e()}}function x(){v(),clearTimeout(t.burstTimer),clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null,G(),t.visibilityHandler&&(document.removeEventListener("visibilitychange",t.visibilityHandler),t.visibilityHandler=null),t.started=!1}async function P(y){return!y||typeof y!="object"?null:o("POST","/update",y)}function I(y){if(!(!y||typeof y!="object"))for(const[A,L]of Object.entries(y)){if(L===null){delete t.currentContext[A];continue}typeof L=="object"&&!Array.isArray(L)&&(t.currentContext[A]={...L})}}return{on:n,start:l,stop:x,setPanelOpen:ue,update:P,context:I,getCustomer:c,patchCustomer:m,listConversations:C,createConversation:b,getConversation:K,patchConversation:S,markConversationRead:J,listMessages:U,postMessage:$,postCallback:ne,uploadAttachment:V,signAttachment:re,get connection(){return t.connection}}}function fc(e){return e.endsWith("/")?e.slice(0,-1):e}function hc(e){return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":"file"}function mc(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const e=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let n=0;n<16;n++)e[n]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(n=>n.toString(16).padStart(2,"0"));return t.slice(0,4).join("")+"-"+t.slice(4,6).join("")+"-"+t.slice(6,8).join("")+"-"+t.slice(8,10).join("")+"-"+t.slice(10,16).join("")}function gc(e){const t=Yn({ready:!1,error:null,config:null,customer:null,conversations:[],messagesByConv:{},paginationByConv:{},streamingByMsgId:{},awaitingCallback:{},runningActionsByConv:{},connection:"idle"}),n=[];n.push(e.on("connection",_=>{t.connection=_})),n.push(e.on("message",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.message;!v||!(k!=null&&k.id)||(ce(v,k),k.client_msg_id&&delete t.streamingByMsgId[k.client_msg_id],G(v,k.created_at))})),n.push(e.on("message_stream",_=>{const v=_==null?void 0:_.message_id,k=_==null?void 0:_.token;!v||typeof k!="string"||(t.streamingByMsgId[v]=(t.streamingByMsgId[v]||"")+k)})),n.push(e.on("conversation_updated",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.changes;if(!v||!k)return;const x=t.conversations.findIndex(P=>P.id===v);x!==-1&&(t.conversations[x]={...t.conversations[x],...k})})),n.push(e.on("config_updated",_=>{_!=null&&_.config&&(t.config=_.config)})),n.push(e.on("action_status",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.action_id,x=_==null?void 0:_.action_name;if(!v||!k)return;const P=t.runningActionsByConv[v]||{};_.state==="running"?(P[k]=x||k,t.runningActionsByConv[v]={...P}):_.state==="done"&&(delete P[k],t.runningActionsByConv[v]={...P})})),n.push(e.on("activity",_=>{Array.isArray(_==null?void 0:_.conversations)&&(t.conversations=_.conversations)}));async function r(_){try{const v=new Promise((x,P)=>setTimeout(()=>P(new Error("bootstrap timeout (15s) — check baseUrl, CORS, and network")),15e3)),k=await Promise.race([e.start(_),v]);t.config=k.config,t.customer=k.customer,t.conversations=await Promise.race([e.listConversations(),v]),t.ready=!0}catch(v){console.error("[store] start failed",v),t.error=(v==null?void 0:v.message)||String(v)}}function i(){for(const _ of n)try{_()}catch{}e.stop()}async function s(_){const v=ue(_);if(!v)return t.customer;try{const k=await e.patchCustomer(v);k&&(t.customer=k)}catch(k){console.error("[store] applyCustomer failed",k)}return t.customer}async function o(_={}){const v=await e.createConversation(_),k=t.conversations.findIndex(x=>x.id===v.id);return k===-1?t.conversations=[v,...t.conversations]:t.conversations[k]=v,v}const a=50;async function l(_){const v=t.paginationByConv[_];if(!(v!=null&&v.loaded||v!=null&&v.loading)){c(_,{nextCursor:null,loading:!0,loaded:!1});try{const k=await e.listMessages(_,{limit:a}),x=(k==null?void 0:k.messages)??[],P=t.messagesByConv[_]||[],I=new Set;for(const A of x)(A==null?void 0:A.id)!=null&&I.add(`id:${String(A.id)}`),A!=null&&A.client_msg_id&&I.add(`c:${A.client_msg_id}`);const y=P.filter(A=>!((A==null?void 0:A.id)!=null&&I.has(`id:${String(A.id)}`)||A!=null&&A.client_msg_id&&I.has(`c:${A.client_msg_id}`)));t.messagesByConv[_]=[...x,...y].sort(se),c(_,{nextCursor:(k==null?void 0:k.next_cursor)??null,loading:!1,loaded:!0})}catch(k){console.error("[store] openConversation failed",k),c(_,{nextCursor:null,loading:!1,loaded:!1})}}}async function d(_){var P;const v=t.paginationByConv[_];if(!v||v.loading||!v.nextCursor)return;const x=(P=(t.messagesByConv[_]||[]).find(I=>I==null?void 0:I.created_at))==null?void 0:P.created_at;if(x){c(_,{...v,loading:!0});try{const I=await e.listMessages(_,{before:x,limit:a}),y=(I==null?void 0:I.messages)??[],A=t.messagesByConv[_]||[],L=new Set;for(const ee of A)(ee==null?void 0:ee.id)!=null&&L.add(`id:${String(ee.id)}`),ee!=null&&ee.client_msg_id&&L.add(`c:${ee.client_msg_id}`);const X=y.filter(ee=>!((ee==null?void 0:ee.id)!=null&&L.has(`id:${String(ee.id)}`)||ee!=null&&ee.client_msg_id&&L.has(`c:${ee.client_msg_id}`)));t.messagesByConv[_]=[...X,...A],c(_,{nextCursor:(I==null?void 0:I.next_cursor)??null,loading:!1,loaded:!0})}catch(I){console.error("[store] loadMore failed",I),c(_,{...v,loading:!1})}}}function c(_,v){t.paginationByConv={...t.paginationByConv,[_]:v}}async function m(_,v){const k=await e.patchConversation(_,v),x=t.conversations.findIndex(P=>P.id===_);x!==-1&&(t.conversations[x]=k)}async function C(_){if(!_)return[];const v=t.messagesByConv[_]||[];let k="";for(const x of v)x!=null&&x.created_at&&x.created_at>k&&(k=x.created_at);try{const x=await e.listMessages(_,k?{since:k}:{}),P=(x==null?void 0:x.messages)||[];if(!P.length)return[];const I=new Set,y=new Set;for(const L of v)(L==null?void 0:L.id)!=null&&I.add(String(L.id)),L!=null&&L.client_msg_id&&y.add(L.client_msg_id);const A=[];for(const L of P){const X=(L==null?void 0:L.id)!=null&&I.has(String(L.id))||(L==null?void 0:L.client_msg_id)&&y.has(L.client_msg_id);ce(_,L),X||A.push(L)}return A}catch(x){return console.error("[store] fetchSinceLast failed",x),[]}}async function b(_,v){if(!(!_||v==null))try{const k=await e.markConversationRead(_,v),x=(k==null?void 0:k.last_read_message_id)??v,P=t.conversations.findIndex(I=>(I==null?void 0:I.id)===_);P!==-1&&(t.conversations[P]={...t.conversations[P],last_read_message_id:x})}catch(k){console.error("[store] markConversationRead failed",k)}}async function K(_,v,{attachments:k,metadata:x}={}){var X;const P=(v||"").trim(),I=Array.isArray(k)&&k.length>0;if(!_||!P&&!I)return;const y=mc(),A=j(_),L={id:y,client_msg_id:y,conversation_id:_,type:"content",text_md:P,author:{type:"user",id:((X=t.customer)==null?void 0:X.external_id)||null},created_at:A,_pending:!0,...I?{payload:{type:"content",attachments:k}}:{},...x&&typeof x=="object"?{metadata:x}:{}};ce(_,L);try{await e.postMessage(_,{client_msg_id:y,text_md:P,created_at:A,...I?{attachments:k}:{},...x&&typeof x=="object"?{metadata:x}:{}})}catch(ee){console.error("[store] send failed",ee),we(_,y,{_failed:!0,_pending:!1})}}async function S(_,v,k){_!=null&&(t.awaitingCallback[_]=!0);try{await e.postCallback(_,v,k)}catch(x){console.error("[store] callback failed",x),_!=null&&delete t.awaitingCallback[_]}}const J=new Map;async function U(_){if(!_)return null;const v=J.get(_);if(v!=null&&v.url){const k=v.expires_at?Date.parse(v.expires_at):0;if(!k||k-Date.now()>6e4)return v.url}try{const k=await e.signAttachment(_);if(k!=null&&k.signed_url)return J.set(_,{url:k.signed_url,expires_at:k.expires_at}),k.signed_url}catch(k){console.error("[store] sign attachment failed",k)}return null}async function $(_,{rating:v,comment:k}={}){const x=t.conversations.find(y=>y.id===_),I={...(x==null?void 0:x.metadata)||{},feedback:{rating:v,comment:k||null,submitted_at:new Date().toISOString()}};await m(_,{metadata:I})}function ne(_){var k,x;const v=t.messagesByConv[_]||[];for(let P=v.length-1;P>=0;P--){const I=v[P];if(((k=I==null?void 0:I.author)==null?void 0:k.type)==="user"||(I==null?void 0:I.type)==="action"&&((x=I==null?void 0:I.payload)==null?void 0:x.state)==="pending")return null;const y=Array.isArray(I==null?void 0:I.callbacks)?I.callbacks.find(A=>(A==null?void 0:A.intent)==="submit_form"):null;if(y&&Array.isArray(y.inputs)&&y.inputs.length>0)return{message:I,form:{title:y.title||"",description:y.description||null,submit_label:y.label||null,fields:y.inputs}}}return null}function V(_){const v=t.runningActionsByConv[_];if(!v)return null;const k=Object.keys(v);if(k.length===0)return null;const x=k[0];return{id:x,payload:{name:v[x]}}}function re(_){var k,x,P;const v=t.messagesByConv[_]||[];for(let I=v.length-1;I>=0;I--){const y=v[I];if(((k=y==null?void 0:y.author)==null?void 0:k.type)==="user")return[];if((y==null?void 0:y.type)==="action"&&((x=y==null?void 0:y.payload)==null?void 0:x.state)==="pending")return[];if(((P=y==null?void 0:y.author)==null?void 0:P.type)!=="agent_ia")continue;const A=Array.isArray(y==null?void 0:y.callbacks)?y.callbacks.filter(L=>(L==null?void 0:L.intent)==="send_message"&&(L.render??"inline")==="inline"):[];return A.length?A.map(L=>typeof L.label=="string"&&L.label.trim()?{label:L.label.trim(),kind:null}:null).filter(Boolean).slice(0,4):[]}return[]}function ce(_,v){var I;const k=t.messagesByConv[_]||[];let x=-1;v!=null&&v.client_msg_id&&(x=k.findIndex(y=>(y==null?void 0:y.client_msg_id)&&y.client_msg_id===v.client_msg_id)),x===-1&&(v==null?void 0:v.id)!==void 0&&(v==null?void 0:v.id)!==null&&(x=k.findIndex(y=>_e(y==null?void 0:y.id,v.id)));let P;x===-1?P=[...k,v].sort(se):(P=k.slice(),P[x]={...k[x],...v,_pending:!1,_failed:!1}),t.messagesByConv[_]=P,(v==null?void 0:v.type)==="action"&&((I=v==null?void 0:v.payload)!=null&&I.state)&&v.payload.state!=="pending"&&(v==null?void 0:v.id)!=null&&t.awaitingCallback[v.id]&&delete t.awaitingCallback[v.id]}function _e(_,v){return _===v?!0:_==null||v==null?!1:String(_)===String(v)}function we(_,v,k){const x=t.messagesByConv[_];if(!x)return;const P=x.findIndex(y=>y.id===v);if(P===-1)return;const I=x.slice();I[P]={...x[P],...k},t.messagesByConv[_]=I}function G(_,v){const k=t.conversations.findIndex(P=>P.id===_);if(k===-1)return;const x=t.conversations[k];if(v&&(!x.last_message_at||v>x.last_message_at)){const P=t.conversations.slice();P[k]={...x,last_message_at:v},P.sort((I,y)=>(y.last_message_at||"").localeCompare(I.last_message_at||"")),t.conversations=P}}function se(_,v){return(_.created_at||"").localeCompare(v.created_at||"")}function ue(_){if(!_||typeof _!="object")return null;const v={},k={};for(const[x,P]of Object.entries(_))P!==void 0&&(x==="name"||x==="email"||x==="language"?P!=null&&String(P).trim()!==""&&(v[x]=P):(x==="values"||x==="metadata")&&P&&typeof P=="object"?Object.assign(k,P):k[x]=P);return Object.keys(k).length&&(v.values=k),Object.keys(v).length?v:null}function j(_){const v=t.messagesByConv[_]||[];let k="";for(const I of v)I!=null&&I.created_at&&I.created_at>k&&(k=I.created_at);const x=new Date().toISOString();return!k||x>k?x:new Date(Date.parse(k)+1).toISOString()}return{state:t,start:r,destroy:i,applyCustomer:s,createConversation:o,openConversation:l,loadMore:d,fetchSinceLast:C,patchConversation:m,markConversationRead:b,send:K,clickCallback:S,signAttachment:U,submitFeedback:$,getActionInFlight:V,getLatestSuggestions:re,getLatestForm:ne,setPanelOpen:e.setPanelOpen}}const Oe={w:"#ffffff",g50:"#F9F9F7",g100:"#F2F1EE",g150:"#E8E6E2",g200:"#D9D6CF",g300:"#B4B0A8",g400:"#888480",g500:"#5A5753",g700:"#2B2926",g900:"#17161A",accent:"#5B5FEF",accentLight:"#EEEFFE",green:"#22C55E",red:"#B91C1C",redBg:"#FDECEC"},bs=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function Zs(e=""){return e?bs[e.charCodeAt(0)%bs.length]:bs[0]}function er(e=""){return e.split(" ").map(t=>t[0]||"").join("").toUpperCase().slice(0,2)}function Bs(e=new Date,t="fr-FR"){return e.toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit"})}const Ao=`
17
+ **/let Ps;const xr=typeof window<"u"&&window.trustedTypes;if(xr)try{Ps=xr.createPolicy("vue",{createHTML:e=>e})}catch{}const ko=Ps?e=>Ps.createHTML(e):e=>e,Cl="http://www.w3.org/2000/svg",Sl="http://www.w3.org/1998/Math/MathML",lt=typeof document<"u"?document:null,Tr=lt&&lt.createElement("template"),Al={insert:(e,t,n)=>{t.insertBefore(e,n||null)},remove:e=>{const t=e.parentNode;t&&t.removeChild(e)},createElement:(e,t,n,r)=>{const i=t==="svg"?lt.createElementNS(Cl,e):t==="mathml"?lt.createElementNS(Sl,e):n?lt.createElement(e,{is:n}):lt.createElement(e);return e==="select"&&r&&r.multiple!=null&&i.setAttribute("multiple",r.multiple),i},createText:e=>lt.createTextNode(e),createComment:e=>lt.createComment(e),setText:(e,t)=>{e.nodeValue=t},setElementText:(e,t)=>{e.textContent=t},parentNode:e=>e.parentNode,nextSibling:e=>e.nextSibling,querySelector:e=>lt.querySelector(e),setScopeId(e,t){e.setAttribute(t,"")},insertStaticContent(e,t,n,r,i,s){const o=n?n.previousSibling:t.lastChild;if(i&&(i===s||i.nextSibling))for(;t.insertBefore(i.cloneNode(!0),n),!(i===s||!(i=i.nextSibling)););else{Tr.innerHTML=ko(r==="svg"?`<svg>${e}</svg>`:r==="mathml"?`<math>${e}</math>`:e);const a=Tr.content;if(r==="svg"||r==="mathml"){const l=a.firstChild;for(;l.firstChild;)a.appendChild(l.firstChild);a.removeChild(l)}t.insertBefore(a,n)}return[o?o.nextSibling:t.firstChild,n?n.previousSibling:t.lastChild]}},vt="transition",Xt="animation",_n=Symbol("_vtc"),Co={name:String,type:String,css:{type:Boolean,default:!0},duration:[String,Number,Object],enterFromClass:String,enterActiveClass:String,enterToClass:String,appearFromClass:String,appearActiveClass:String,appearToClass:String,leaveFromClass:String,leaveActiveClass:String,leaveToClass:String},xl=Ae({},Ni,Co),Tl=e=>(e.displayName="Transition",e.props=xl,e),Qs=Tl((e,{slots:t})=>wo(Aa,Ml(e),t)),Mt=(e,t=[])=>{W(e)?e.forEach(n=>n(...t)):e&&e(...t)},Mr=e=>e?W(e)?e.some(t=>t.length>1):e.length>1:!1;function Ml(e){const t={};for(const j in e)j in Co||(t[j]=e[j]);if(e.css===!1)return t;const{name:n="v",type:r,duration:i,enterFromClass:s=`${n}-enter-from`,enterActiveClass:o=`${n}-enter-active`,enterToClass:a=`${n}-enter-to`,appearFromClass:l=s,appearActiveClass:d=o,appearToClass:c=a,leaveFromClass:m=`${n}-leave-from`,leaveActiveClass:C=`${n}-leave-active`,leaveToClass:b=`${n}-leave-to`}=e,K=El(i),S=K&&K[0],J=K&&K[1],{onBeforeEnter:U,onEnter:$,onEnterCancelled:ne,onLeave:V,onLeaveCancelled:re,onBeforeAppear:ce=U,onAppear:_e=$,onAppearCancelled:we=ne}=t,G=(j,_,v,k)=>{j._enterCancelled=k,Et(j,_?c:a),Et(j,_?d:o),v&&v()},se=(j,_)=>{j._isLeaving=!1,Et(j,m),Et(j,b),Et(j,C),_&&_()},ue=j=>(_,v)=>{const k=j?_e:$,x=()=>G(_,j,v);Mt(k,[_,x]),Er(()=>{Et(_,j?l:s),at(_,j?c:a),Mr(k)||Or(_,r,S,x)})};return Ae(t,{onBeforeEnter(j){Mt(U,[j]),at(j,s),at(j,o)},onBeforeAppear(j){Mt(ce,[j]),at(j,l),at(j,d)},onEnter:ue(!1),onAppear:ue(!0),onLeave(j,_){j._isLeaving=!0;const v=()=>se(j,_);at(j,m),j._enterCancelled?(at(j,C),Lr(j)):(Lr(j),at(j,C)),Er(()=>{j._isLeaving&&(Et(j,m),at(j,b),Mr(V)||Or(j,r,J,v))}),Mt(V,[j,v])},onEnterCancelled(j){G(j,!1,void 0,!0),Mt(ne,[j])},onAppearCancelled(j){G(j,!0,void 0,!0),Mt(we,[j])},onLeaveCancelled(j){se(j),Mt(re,[j])}})}function El(e){if(e==null)return null;if(ae(e))return[ps(e.enter),ps(e.leave)];{const t=ps(e);return[t,t]}}function ps(e){return Po(e)}function at(e,t){t.split(/\s+/).forEach(n=>n&&e.classList.add(n)),(e[_n]||(e[_n]=new Set)).add(t)}function Et(e,t){t.split(/\s+/).forEach(r=>r&&e.classList.remove(r));const n=e[_n];n&&(n.delete(t),n.size||(e[_n]=void 0))}function Er(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}let Ol=0;function Or(e,t,n,r){const i=e._endId=++Ol,s=()=>{i===e._endId&&r()};if(n!=null)return setTimeout(s,n);const{type:o,timeout:a,propCount:l}=Rl(e,t);if(!o)return r();const d=o+"end";let c=0;const m=()=>{e.removeEventListener(d,C),s()},C=b=>{b.target===e&&++c>=l&&m()};setTimeout(()=>{c<l&&m()},a+1),e.addEventListener(d,C)}function Rl(e,t){const n=window.getComputedStyle(e),r=K=>(n[K]||"").split(", "),i=r(`${vt}Delay`),s=r(`${vt}Duration`),o=Rr(i,s),a=r(`${Xt}Delay`),l=r(`${Xt}Duration`),d=Rr(a,l);let c=null,m=0,C=0;t===vt?o>0&&(c=vt,m=o,C=s.length):t===Xt?d>0&&(c=Xt,m=d,C=l.length):(m=Math.max(o,d),c=m>0?o>d?vt:Xt:null,C=c?c===vt?s.length:l.length:0);const b=c===vt&&/\b(?:transform|all)(?:,|$)/.test(r(`${vt}Property`).toString());return{type:c,timeout:m,propCount:C,hasTransform:b}}function Rr(e,t){for(;e.length<t.length;)e=e.concat(e);return Math.max(...t.map((n,r)=>Ir(n)+Ir(e[r])))}function Ir(e){return e==="auto"?0:Number(e.slice(0,-1).replace(",","."))*1e3}function Lr(e){return(e?e.ownerDocument:document).body.offsetHeight}function Il(e,t,n){const r=e[_n];r&&(t=(t?[t,...r]:[...r]).join(" ")),t==null?e.removeAttribute("class"):n?e.setAttribute("class",t):e.className=t}const Pr=Symbol("_vod"),Ll=Symbol("_vsh"),Pl=Symbol(""),Bl=/(?:^|;)\s*display\s*:/;function Fl(e,t,n){const r=e.style,i=ye(n);let s=!1;if(n&&!i){if(t)if(ye(t))for(const o of t.split(";")){const a=o.slice(0,o.indexOf(":")).trim();n[a]==null&&tn(r,a,"")}else for(const o in t)n[o]==null&&tn(r,o,"");for(const o in n){o==="display"&&(s=!0);const a=n[o];a!=null?Nl(e,o,!ye(t)&&t?t[o]:void 0,a)||tn(r,o,a):tn(r,o,"")}}else if(i){if(t!==n){const o=r[Pl];o&&(n+=";"+o),r.cssText=n,s=Bl.test(n)}}else t&&e.removeAttribute("style");Pr in e&&(e[Pr]=s?r.display:"",e[Ll]&&(r.display="none"))}const Br=/\s*!important$/;function tn(e,t,n){if(W(n))n.forEach(r=>tn(e,t,r));else if(n==null&&(n=""),t.startsWith("--"))e.setProperty(t,n);else{const r=Dl(e,t);Br.test(n)?e.setProperty(At(r),n.replace(Br,""),"important"):e[r]=n}}const Fr=["Webkit","Moz","ms"],_s={};function Dl(e,t){const n=_s[t];if(n)return n;let r=De(t);if(r!=="filter"&&r in e)return _s[t]=r;r=Wn(r);for(let i=0;i<Fr.length;i++){const s=Fr[i]+r;if(s in e)return _s[t]=s}return t}function Nl(e,t,n,r){return e.tagName==="TEXTAREA"&&(t==="width"||t==="height")&&ye(r)&&n===r}const Dr="http://www.w3.org/1999/xlink";function Nr(e,t,n,r,i,s=Uo(t)){r&&t.startsWith("xlink:")?n==null?e.removeAttributeNS(Dr,t.slice(6,t.length)):e.setAttributeNS(Dr,t,n):n==null||s&&!ui(n)?e.removeAttribute(t):e.setAttribute(t,s?"":Ge(n)?String(n):n)}function Hr(e,t,n,r,i){if(t==="innerHTML"||t==="textContent"){n!=null&&(e[t]=t==="innerHTML"?ko(n):n);return}const s=e.tagName;if(t==="value"&&s!=="PROGRESS"&&!s.includes("-")){const a=s==="OPTION"?e.getAttribute("value")||"":e.value,l=n==null?e.type==="checkbox"?"on":"":String(n);(a!==l||!("_value"in e))&&(e.value=l),n==null&&e.removeAttribute(t),e._value=n;return}let o=!1;if(n===""||n==null){const a=typeof e[t];a==="boolean"?n=ui(n):n==null&&a==="string"?(n="",o=!0):a==="number"&&(n=0,o=!0)}try{e[t]=n}catch{}o&&e.removeAttribute(i||t)}function wt(e,t,n,r){e.addEventListener(t,n,r)}function Hl(e,t,n,r){e.removeEventListener(t,n,r)}const Ur=Symbol("_vei");function Ul(e,t,n,r,i=null){const s=e[Ur]||(e[Ur]={}),o=s[t];if(r&&o)o.value=r;else{const[a,l]=jl(t);if(r){const d=s[t]=zl(r,i);wt(e,a,d,l)}else o&&(Hl(e,a,o,l),s[t]=void 0)}}const jr=/(?:Once|Passive|Capture)$/;function jl(e){let t;if(jr.test(e)){t={};let r;for(;r=e.match(jr);)e=e.slice(0,e.length-r[0].length),t[r[0].toLowerCase()]=!0}return[e[2]===":"?e.slice(3):At(e.slice(2)),t]}let ys=0;const Vl=Promise.resolve(),Kl=()=>ys||(Vl.then(()=>ys=0),ys=Date.now());function zl(e,t){const n=r=>{if(!r._vts)r._vts=Date.now();else if(r._vts<=n.attached)return;Ye(Wl(r,n.value),t,5,[r])};return n.value=e,n.attached=Kl(),n}function Wl(e,t){if(W(t)){const n=e.stopImmediatePropagation;return e.stopImmediatePropagation=()=>{n.call(e),e._stopped=!0},t.map(r=>i=>!i._stopped&&r&&r(i))}else return t}const Vr=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&e.charCodeAt(2)>96&&e.charCodeAt(2)<123,$l=(e,t,n,r,i,s)=>{const o=i==="svg";t==="class"?Il(e,r,o):t==="style"?Fl(e,n,r):Vn(t)?Kn(t)||Ul(e,t,n,r,s):(t[0]==="."?(t=t.slice(1),!0):t[0]==="^"?(t=t.slice(1),!1):ql(e,t,r,o))?(Hr(e,t,r),!e.tagName.includes("-")&&(t==="value"||t==="checked"||t==="selected")&&Nr(e,t,r,o,s,t!=="value")):e._isVueCE&&(Gl(e,t)||e._def.__asyncLoader&&(/[A-Z]/.test(t)||!ye(r)))?Hr(e,De(t),r,s,t):(t==="true-value"?e._trueValue=r:t==="false-value"&&(e._falseValue=r),Nr(e,t,r,o))};function ql(e,t,n,r){if(r)return!!(t==="innerHTML"||t==="textContent"||t in e&&Vr(t)&&Q(n));if(t==="spellcheck"||t==="draggable"||t==="translate"||t==="autocorrect"||t==="sandbox"&&e.tagName==="IFRAME"||t==="form"||t==="list"&&e.tagName==="INPUT"||t==="type"&&e.tagName==="TEXTAREA")return!1;if(t==="width"||t==="height"){const i=e.tagName;if(i==="IMG"||i==="VIDEO"||i==="CANVAS"||i==="SOURCE")return!1}return Vr(t)&&ye(n)?!1:t in e}function Gl(e,t){const n=e._def.props;if(!n)return!1;const r=De(t);return Array.isArray(n)?n.some(i=>De(i)===r):Object.keys(n).some(i=>De(i)===r)}const zt=e=>{const t=e.props["onUpdate:modelValue"]||!1;return W(t)?n=>En(t,n):t};function Yl(e){e.target.composing=!0}function Kr(e){const t=e.target;t.composing&&(t.composing=!1,t.dispatchEvent(new Event("input")))}const mt=Symbol("_assign");function zr(e,t,n){return t&&(e=e.trim()),n&&(e=$n(e)),e}const kt={created(e,{modifiers:{lazy:t,trim:n,number:r}},i){e[mt]=zt(i);const s=r||i.props&&i.props.type==="number";wt(e,t?"change":"input",o=>{o.target.composing||e[mt](zr(e.value,n,s))}),(n||s)&&wt(e,"change",()=>{e.value=zr(e.value,n,s)}),t||(wt(e,"compositionstart",Yl),wt(e,"compositionend",Kr),wt(e,"change",Kr))},mounted(e,{value:t}){e.value=t??""},beforeUpdate(e,{value:t,oldValue:n,modifiers:{lazy:r,trim:i,number:s}},o){if(e[mt]=zt(o),e.composing)return;const a=(s||e.type==="number")&&!/^0\d/.test(e.value)?$n(e.value):e.value,l=t??"";if(a===l)return;const d=e.getRootNode();(d instanceof Document||d instanceof ShadowRoot)&&d.activeElement===e&&e.type!=="range"&&(r&&t===n||i&&e.value.trim()===l)||(e.value=l)}},Jl={deep:!0,created(e,t,n){e[mt]=zt(n),wt(e,"change",()=>{const r=e._modelValue,i=yn(e),s=e.checked,o=e[mt];if(W(r)){const a=Hs(r,i),l=a!==-1;if(s&&!l)o(r.concat(i));else if(!s&&l){const d=[...r];d.splice(a,1),o(d)}}else if(Wt(r)){const a=new Set(r);s?a.add(i):a.delete(i),o(a)}else o(So(e,s))})},mounted:Wr,beforeUpdate(e,t,n){e[mt]=zt(n),Wr(e,t,n)}};function Wr(e,{value:t,oldValue:n},r){e._modelValue=t;let i;if(W(t))i=Hs(t,r.props.value)>-1;else if(Wt(t))i=t.has(r.props.value);else{if(t===n)return;i=$t(t,So(e,!0))}e.checked!==i&&(e.checked=i)}const Xl={deep:!0,created(e,{value:t,modifiers:{number:n}},r){const i=Wt(t);wt(e,"change",()=>{const s=Array.prototype.filter.call(e.options,o=>o.selected).map(o=>n?$n(yn(o)):yn(o));e[mt](e.multiple?i?new Set(s):s:s[0]),e._assigning=!0,Oi(()=>{e._assigning=!1})}),e[mt]=zt(r)},mounted(e,{value:t}){$r(e,t)},beforeUpdate(e,t,n){e[mt]=zt(n)},updated(e,{value:t}){e._assigning||$r(e,t)}};function $r(e,t){const n=e.multiple,r=W(t);if(!(n&&!r&&!Wt(t))){for(let i=0,s=e.options.length;i<s;i++){const o=e.options[i],a=yn(o);if(n)if(r){const l=typeof a;l==="string"||l==="number"?o.selected=t.some(d=>String(d)===String(a)):o.selected=Hs(t,a)>-1}else o.selected=t.has(a);else if($t(yn(o),t)){e.selectedIndex!==i&&(e.selectedIndex=i);return}}!n&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function yn(e){return"_value"in e?e._value:e.value}function So(e,t){const n=t?"_trueValue":"_falseValue";return n in e?e[n]:t}const Ql=["ctrl","shift","alt","meta"],Zl={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>"button"in e&&e.button!==0,middle:e=>"button"in e&&e.button!==1,right:e=>"button"in e&&e.button!==2,exact:(e,t)=>Ql.some(n=>e[`${n}Key`]&&!t.includes(n))},We=(e,t)=>{if(!e)return e;const n=e._withMods||(e._withMods={}),r=t.join(".");return n[r]||(n[r]=(i,...s)=>{for(let o=0;o<t.length;o++){const a=Zl[t[o]];if(a&&a(i,t))return}return e(i,...s)})},ec={esc:"escape",space:" ",up:"arrow-up",left:"arrow-left",right:"arrow-right",down:"arrow-down",delete:"backspace"},Un=(e,t)=>{const n=e._withKeys||(e._withKeys={}),r=t.join(".");return n[r]||(n[r]=i=>{if(!("key"in i))return;const s=At(i.key);if(t.some(o=>o===s||ec[o]===s))return e(i)})},tc=Ae({patchProp:$l},Al);let qr;function nc(){return qr||(qr=rl(tc))}const sc=(...e)=>{const t=nc().createApp(...e),{mount:n}=t;return t.mount=r=>{const i=ic(r);if(!i)return;const s=t._component;!Q(s)&&!s.render&&!s.template&&(s.template=i.innerHTML),i.nodeType===1&&(i.textContent="");const o=n(i,!1,rc(i));return i instanceof Element&&(i.removeAttribute("v-cloak"),i.setAttribute("data-v-app","")),o},t};function rc(e){if(e instanceof SVGElement)return"svg";if(typeof MathMLElement=="function"&&e instanceof MathMLElement)return"mathml"}function ic(e){return ye(e)?document.querySelector(e):e}const oc=["connected","message","message_stream","conversation_updated","config_updated","action_status"],vs="/client",ac=5*60*1e3,lc=15*1e3,cc=10*60*1e3,uc=5*60*1e3;function dc(e){const t={baseUrl:fc(e.baseUrl||""),widgetId:e.widgetId||"",userId:"",origin:"",token:"",currentContext:{},listeners:new Map,eventSource:null,connection:"idle",visibilityHandler:null,started:!1,panelOpen:!1,pollTimer:null,burstTimer:null,hiddenGraceTimer:null,lastActivityAt:null};if(!t.baseUrl||!t.widgetId)throw new Error("[transport] baseUrl and widgetId are required");function n(y,A){return t.listeners.has(y)||t.listeners.set(y,new Set),t.listeners.get(y).add(A),()=>t.listeners.get(y).delete(A)}function r(y,A){const L=t.listeners.get(y);L&&L.forEach(X=>{try{X(A)}catch(ee){console.error("[transport] listener",y,ee)}})}function i(y){t.connection!==y&&(t.connection=y,r("connection",y))}function s(){return{"Content-Type":"application/json","X-Widget-Id":t.widgetId,...t.origin?{"X-Parent-Origin":t.origin}:{}}}async function o(y,A,L){const X=await fetch(`${t.baseUrl}${vs}${A}`,{method:y,credentials:"include",headers:s(),body:L!==void 0?JSON.stringify(L):void 0});if(!X.ok){const ee=await a(X),Pe=new Error(`HTTP ${X.status} ${y} ${A} :: ${(ee==null?void 0:ee.error)||X.statusText}`);throw Pe.status=X.status,Pe.body=ee,Pe}return X.status===204?null:X.json()}async function a(y){try{return await y.json()}catch{return null}}async function l(y){if(t.started)return t.lastBootstrap;if(!(y!=null&&y.origin))throw new Error("[transport] start requires origin");t.started=!0,t.origin=y.origin,t.token=y.token||"";const A=await fetch(`${t.baseUrl}${vs}/session`,{method:"POST",credentials:"include",headers:s(),body:JSON.stringify({origin:t.origin,...t.token?{token:t.token}:{},allowUnauthenticated:y.allowUnauthenticated===!0,...y.variables&&typeof y.variables=="object"?{variables:y.variables}:{}})});if(!A.ok){const Ke=await a(A),Ue=new Error(`Session bootstrap failed: HTTP ${A.status} :: ${(Ke==null?void 0:Ke.error)||A.statusText}`);throw Ue.status=A.status,Ue.body=Ke,Ue}const L=await A.json();t.userId=L.external_id;const[X,ee]=await Promise.all([fetch(`${t.baseUrl}/widgets/${encodeURIComponent(t.widgetId)}/config`,{credentials:"include"}).then(async Ke=>{if(!Ke.ok){const Ue=await a(Ke);throw new Error(`HTTP ${Ke.status} GET /widgets/:id/config :: ${(Ue==null?void 0:Ue.error)||Ke.statusText}`)}return Ke.json()}),o("GET","/customers/me")]),Pe={config:X,customer:(ee==null?void 0:ee.customer)??null};return t.lastBootstrap=Pe,await d(),typeof document<"u"&&(t.visibilityHandler=k,document.addEventListener("visibilitychange",t.visibilityHandler)),_(),Pe}async function d(){try{const y=await C();t.lastActivityAt=y.reduce((A,L)=>{const X=L==null?void 0:L.last_message_at;return X&&(!A||X>A)?X:A},null)}catch(y){console.error("[transport] initial /conversations failed",y)}}async function c(){const y=await o("GET","/customers/me");return(y==null?void 0:y.customer)??null}async function m(y){const A=await o("PATCH","/customers/me",y);return(A==null?void 0:A.customer)??null}async function C(){const y=await o("GET","/conversations");return(y==null?void 0:y.conversations)??[]}async function b(y={}){return(await o("POST","/conversations",y)).conversation}async function K(y){return(await o("GET",`/conversations/${encodeURIComponent(y)}`)).conversation}async function S(y,A){return(await o("PATCH",`/conversations/${encodeURIComponent(y)}`,A)).conversation}async function J(y,A){return o("PATCH",`/conversations/${encodeURIComponent(y)}/read`,{message_id:A})}async function U(y,A={}){const L=new URLSearchParams;A.before&&L.set("before",A.before),A.since&&L.set("since",A.since),A.limit&&L.set("limit",String(A.limit));const X=L.toString()?`?${L.toString()}`:"";return o("GET",`/conversations/${encodeURIComponent(y)}/messages${X}`)}async function $(y,A){se();const L={client_msg_id:A.client_msg_id,type:"content",text_md:A.text_md,author:{id:t.userId,type:"user"},created_at:A.created_at||new Date().toISOString()};return Array.isArray(A.attachments)&&A.attachments.length&&(L.payload={type:"content",attachments:A.attachments}),A.metadata&&typeof A.metadata=="object"&&(L.metadata=A.metadata),t.currentContext&&Object.keys(t.currentContext).length>0&&(L.context=t.currentContext),o("POST",`/conversations/${encodeURIComponent(y)}/messages`,L)}async function ne(y,A,L){return se(),o("POST",`/messages/${encodeURIComponent(y)}/callbacks/${encodeURIComponent(A)}`,L?{inputs:L}:{})}async function V(y){const A=y.name||"attachment",L=y.type||"application/octet-stream",X=y.size||0,ee=await o("POST","/attachments",{mime_type:L,size_bytes:X,name:A}),Pe=await fetch(ee.upload_url,{method:"PUT",headers:{"Content-Type":L},body:y});if(!Pe.ok)throw new Error(`HTTP ${Pe.status} PUT signed upload`);return{type:hc(L),path:ee.path,mime_type:L,size_bytes:X}}async function re(y){return o("GET",`/attachments/sign?path=${encodeURIComponent(y)}`)}function ce(){const y=new URLSearchParams({widgetId:t.widgetId}).toString();return`${t.baseUrl}${vs}/stream?${y}`}function _e(){if(!t.eventSource&&!(typeof document<"u"&&document.hidden)&&t.started)try{const y=new EventSource(ce(),{withCredentials:!0});for(const A of oc)y.addEventListener(A,L=>we(A,L.data));y.addEventListener("error",()=>r("error",new Error("SSE error"))),t.eventSource=y,i("open")}catch(y){console.error("[transport] SSE open failed",y),r("error",y)}}function we(y,A){try{const L=JSON.parse(A),X=L&&typeof L=="object"&&"data"in L?L.data:L;r(y,X)}catch(L){console.error("[transport] bad SSE payload",y,L)}}function G(){t.eventSource&&(t.eventSource.close(),t.eventSource=null),t.connection!=="paused"&&i("idle")}function se(){clearTimeout(t.burstTimer),_e(),t.panelOpen||(t.burstTimer=setTimeout(()=>{t.panelOpen||G()},cc))}function ue(y){const A=t.panelOpen;t.panelOpen=!!y,t.panelOpen?(clearTimeout(t.burstTimer),_e()):se(),A!==t.panelOpen&&_()}async function j(){try{const y=await C(),A=y.reduce((X,ee)=>{const Pe=ee==null?void 0:ee.last_message_at;return Pe&&(!X||Pe>X)?Pe:X},null);A&&(!t.lastActivityAt||A>t.lastActivityAt)&&(t.lastActivityAt=A,r("activity",{conversations:y,latestAt:A}),se())}catch(y){console.error("[transport] poll failed",y)}}function _(){if(v(),typeof document<"u"&&document.hidden)return;const y=t.panelOpen?lc:ac;t.pollTimer=setInterval(j,y)}function v(){t.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null)}function k(){if(document.hidden)clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=setTimeout(()=>{t.hiddenGraceTimer=null,document.hidden&&(v(),G(),i("paused"))},uc);else{if(t.hiddenGraceTimer){clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null;return}i("idle"),_(),t.panelOpen&&_e()}}function x(){v(),clearTimeout(t.burstTimer),clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null,G(),t.visibilityHandler&&(document.removeEventListener("visibilitychange",t.visibilityHandler),t.visibilityHandler=null),t.started=!1}async function P(y){return!y||typeof y!="object"?null:o("POST","/update",y)}function I(y){if(!(!y||typeof y!="object"))for(const[A,L]of Object.entries(y)){if(L===null){delete t.currentContext[A];continue}typeof L=="object"&&!Array.isArray(L)&&(t.currentContext[A]={...L})}}return{on:n,start:l,stop:x,setPanelOpen:ue,update:P,context:I,getCustomer:c,patchCustomer:m,listConversations:C,createConversation:b,getConversation:K,patchConversation:S,markConversationRead:J,listMessages:U,postMessage:$,postCallback:ne,uploadAttachment:V,signAttachment:re,get connection(){return t.connection}}}function fc(e){return e.endsWith("/")?e.slice(0,-1):e}function hc(e){return e.startsWith("image/")?"image":e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":"file"}function mc(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const e=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let n=0;n<16;n++)e[n]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(n=>n.toString(16).padStart(2,"0"));return t.slice(0,4).join("")+"-"+t.slice(4,6).join("")+"-"+t.slice(6,8).join("")+"-"+t.slice(8,10).join("")+"-"+t.slice(10,16).join("")}function gc(e){const t=Yn({ready:!1,error:null,config:null,customer:null,conversations:[],messagesByConv:{},paginationByConv:{},streamingByMsgId:{},awaitingCallback:{},runningActionsByConv:{},connection:"idle"}),n=[];n.push(e.on("connection",_=>{t.connection=_})),n.push(e.on("message",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.message;!v||!(k!=null&&k.id)||(ce(v,k),k.client_msg_id&&delete t.streamingByMsgId[k.client_msg_id],G(v,k.created_at))})),n.push(e.on("message_stream",_=>{const v=_==null?void 0:_.message_id,k=_==null?void 0:_.token;!v||typeof k!="string"||(t.streamingByMsgId[v]=(t.streamingByMsgId[v]||"")+k)})),n.push(e.on("conversation_updated",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.changes;if(!v||!k)return;const x=t.conversations.findIndex(P=>P.id===v);x!==-1&&(t.conversations[x]={...t.conversations[x],...k})})),n.push(e.on("config_updated",_=>{_!=null&&_.config&&(t.config=_.config)})),n.push(e.on("action_status",_=>{const v=_==null?void 0:_.conversation_id,k=_==null?void 0:_.action_id,x=_==null?void 0:_.action_name;if(!v||!k)return;const P=t.runningActionsByConv[v]||{};_.state==="running"?(P[k]=x||k,t.runningActionsByConv[v]={...P}):_.state==="done"&&(delete P[k],t.runningActionsByConv[v]={...P})})),n.push(e.on("activity",_=>{Array.isArray(_==null?void 0:_.conversations)&&(t.conversations=_.conversations)}));async function r(_){try{const v=new Promise((x,P)=>setTimeout(()=>P(new Error("bootstrap timeout (15s) — check baseUrl, CORS, and network")),15e3)),k=await Promise.race([e.start(_),v]);t.config=k.config,t.customer=k.customer,t.conversations=await Promise.race([e.listConversations(),v]),t.ready=!0}catch(v){console.error("[store] start failed",v),t.error=(v==null?void 0:v.message)||String(v)}}function i(){for(const _ of n)try{_()}catch{}e.stop()}async function s(_){const v=ue(_);if(!v)return t.customer;try{const k=await e.patchCustomer(v);k&&(t.customer=k)}catch(k){console.error("[store] applyCustomer failed",k)}return t.customer}async function o(_={}){const v=await e.createConversation(_),k=t.conversations.findIndex(x=>x.id===v.id);return k===-1?t.conversations=[v,...t.conversations]:t.conversations[k]=v,v}const a=50;async function l(_){const v=t.paginationByConv[_];if(!(v!=null&&v.loaded||v!=null&&v.loading)){c(_,{nextCursor:null,loading:!0,loaded:!1});try{const k=await e.listMessages(_,{limit:a}),x=(k==null?void 0:k.messages)??[],P=t.messagesByConv[_]||[],I=new Set;for(const A of x)(A==null?void 0:A.id)!=null&&I.add(`id:${String(A.id)}`),A!=null&&A.client_msg_id&&I.add(`c:${A.client_msg_id}`);const y=P.filter(A=>!((A==null?void 0:A.id)!=null&&I.has(`id:${String(A.id)}`)||A!=null&&A.client_msg_id&&I.has(`c:${A.client_msg_id}`)));t.messagesByConv[_]=[...x,...y].sort(se),c(_,{nextCursor:(k==null?void 0:k.next_cursor)??null,loading:!1,loaded:!0})}catch(k){console.error("[store] openConversation failed",k),c(_,{nextCursor:null,loading:!1,loaded:!1})}}}async function d(_){var P;const v=t.paginationByConv[_];if(!v||v.loading||!v.nextCursor)return;const x=(P=(t.messagesByConv[_]||[]).find(I=>I==null?void 0:I.created_at))==null?void 0:P.created_at;if(x){c(_,{...v,loading:!0});try{const I=await e.listMessages(_,{before:x,limit:a}),y=(I==null?void 0:I.messages)??[],A=t.messagesByConv[_]||[],L=new Set;for(const ee of A)(ee==null?void 0:ee.id)!=null&&L.add(`id:${String(ee.id)}`),ee!=null&&ee.client_msg_id&&L.add(`c:${ee.client_msg_id}`);const X=y.filter(ee=>!((ee==null?void 0:ee.id)!=null&&L.has(`id:${String(ee.id)}`)||ee!=null&&ee.client_msg_id&&L.has(`c:${ee.client_msg_id}`)));t.messagesByConv[_]=[...X,...A],c(_,{nextCursor:(I==null?void 0:I.next_cursor)??null,loading:!1,loaded:!0})}catch(I){console.error("[store] loadMore failed",I),c(_,{...v,loading:!1})}}}function c(_,v){t.paginationByConv={...t.paginationByConv,[_]:v}}async function m(_,v){const k=await e.patchConversation(_,v),x=t.conversations.findIndex(P=>P.id===_);x!==-1&&(t.conversations[x]=k)}async function C(_){if(!_)return[];const v=t.messagesByConv[_]||[];let k="";for(const x of v)x!=null&&x.created_at&&x.created_at>k&&(k=x.created_at);try{const x=await e.listMessages(_,k?{since:k}:{}),P=(x==null?void 0:x.messages)||[];if(!P.length)return[];const I=new Set,y=new Set;for(const L of v)(L==null?void 0:L.id)!=null&&I.add(String(L.id)),L!=null&&L.client_msg_id&&y.add(L.client_msg_id);const A=[];for(const L of P){const X=(L==null?void 0:L.id)!=null&&I.has(String(L.id))||(L==null?void 0:L.client_msg_id)&&y.has(L.client_msg_id);ce(_,L),X||A.push(L)}return A}catch(x){return console.error("[store] fetchSinceLast failed",x),[]}}async function b(_,v){if(!(!_||v==null))try{const k=await e.markConversationRead(_,v),x=(k==null?void 0:k.last_read_message_id)??v,P=t.conversations.findIndex(I=>(I==null?void 0:I.id)===_);P!==-1&&(t.conversations[P]={...t.conversations[P],last_read_message_id:x})}catch(k){console.error("[store] markConversationRead failed",k)}}async function K(_,v,{attachments:k,metadata:x}={}){var X;const P=(v||"").trim(),I=Array.isArray(k)&&k.length>0;if(!_||!P&&!I)return;const y=mc(),A=j(_),L={id:y,client_msg_id:y,conversation_id:_,type:"content",text_md:P,author:{type:"user",id:((X=t.customer)==null?void 0:X.external_id)||null},created_at:A,_pending:!0,...I?{payload:{type:"content",attachments:k}}:{},...x&&typeof x=="object"?{metadata:x}:{}};ce(_,L);try{await e.postMessage(_,{client_msg_id:y,text_md:P,created_at:A,...I?{attachments:k}:{},...x&&typeof x=="object"?{metadata:x}:{}})}catch(ee){console.error("[store] send failed",ee),we(_,y,{_failed:!0,_pending:!1})}}async function S(_,v,k){_!=null&&(t.awaitingCallback[_]=!0);try{await e.postCallback(_,v,k)}catch(x){console.error("[store] callback failed",x),_!=null&&delete t.awaitingCallback[_]}}const J=new Map;async function U(_){if(!_)return null;const v=J.get(_);if(v!=null&&v.url){const k=v.expires_at?Date.parse(v.expires_at):0;if(!k||k-Date.now()>6e4)return v.url}try{const k=await e.signAttachment(_);if(k!=null&&k.signed_url)return J.set(_,{url:k.signed_url,expires_at:k.expires_at}),k.signed_url}catch(k){console.error("[store] sign attachment failed",k)}return null}async function $(_,{rating:v,comment:k}={}){const x=t.conversations.find(y=>y.id===_),I={...(x==null?void 0:x.metadata)||{},feedback:{rating:v,comment:k||null,submitted_at:new Date().toISOString()}};await m(_,{metadata:I})}function ne(_){var k,x;const v=t.messagesByConv[_]||[];for(let P=v.length-1;P>=0;P--){const I=v[P];if(((k=I==null?void 0:I.author)==null?void 0:k.type)==="user"||(I==null?void 0:I.type)==="action"&&((x=I==null?void 0:I.payload)==null?void 0:x.state)==="pending")return null;const y=Array.isArray(I==null?void 0:I.callbacks)?I.callbacks.find(A=>(A==null?void 0:A.intent)==="submit_form"):null;if(y&&Array.isArray(y.inputs)&&y.inputs.length>0)return{message:I,form:{title:y.title||"",description:y.description||null,submit_label:y.label||null,fields:y.inputs}}}return null}function V(_){const v=t.runningActionsByConv[_];if(!v)return null;const k=Object.keys(v);if(k.length===0)return null;const x=k[0];return{id:x,payload:{name:v[x]}}}function re(_){var k,x,P;const v=t.messagesByConv[_]||[];for(let I=v.length-1;I>=0;I--){const y=v[I];if(((k=y==null?void 0:y.author)==null?void 0:k.type)==="user")return[];if((y==null?void 0:y.type)==="action"&&((x=y==null?void 0:y.payload)==null?void 0:x.state)==="pending")return[];if(((P=y==null?void 0:y.author)==null?void 0:P.type)!=="agent_ia")continue;const A=Array.isArray(y==null?void 0:y.callbacks)?y.callbacks.filter(L=>(L==null?void 0:L.intent)==="send_message"&&(L.render??"inline")==="inline"):[];return A.length?A.map(L=>typeof L.label=="string"&&L.label.trim()?{label:L.label.trim(),kind:null}:null).filter(Boolean).slice(0,4):[]}return[]}function ce(_,v){var I;const k=t.messagesByConv[_]||[];let x=-1;v!=null&&v.client_msg_id&&(x=k.findIndex(y=>(y==null?void 0:y.client_msg_id)&&y.client_msg_id===v.client_msg_id)),x===-1&&(v==null?void 0:v.id)!==void 0&&(v==null?void 0:v.id)!==null&&(x=k.findIndex(y=>_e(y==null?void 0:y.id,v.id)));let P;x===-1?P=[...k,v].sort(se):(P=k.slice(),P[x]={...k[x],...v,_pending:!1,_failed:!1}),t.messagesByConv[_]=P,(v==null?void 0:v.type)==="action"&&((I=v==null?void 0:v.payload)!=null&&I.state)&&v.payload.state!=="pending"&&(v==null?void 0:v.id)!=null&&t.awaitingCallback[v.id]&&delete t.awaitingCallback[v.id]}function _e(_,v){return _===v?!0:_==null||v==null?!1:String(_)===String(v)}function we(_,v,k){const x=t.messagesByConv[_];if(!x)return;const P=x.findIndex(y=>y.id===v);if(P===-1)return;const I=x.slice();I[P]={...x[P],...k},t.messagesByConv[_]=I}function G(_,v){const k=t.conversations.findIndex(P=>P.id===_);if(k===-1)return;const x=t.conversations[k];if(v&&(!x.last_message_at||v>x.last_message_at)){const P=t.conversations.slice();P[k]={...x,last_message_at:v},P.sort((I,y)=>(y.last_message_at||"").localeCompare(I.last_message_at||"")),t.conversations=P}}function se(_,v){return(_.created_at||"").localeCompare(v.created_at||"")}function ue(_){if(!_||typeof _!="object")return null;const v={},k={};for(const[x,P]of Object.entries(_))P!==void 0&&(x==="name"||x==="email"||x==="language"?P!=null&&String(P).trim()!==""&&(v[x]=P):(x==="values"||x==="metadata")&&P&&typeof P=="object"?Object.assign(k,P):k[x]=P);return Object.keys(k).length&&(v.values=k),Object.keys(v).length?v:null}function j(_){const v=t.messagesByConv[_]||[];let k="";for(const I of v)I!=null&&I.created_at&&I.created_at>k&&(k=I.created_at);const x=new Date().toISOString();return!k||x>k?x:new Date(Date.parse(k)+1).toISOString()}return{state:t,start:r,destroy:i,applyCustomer:s,createConversation:o,openConversation:l,loadMore:d,fetchSinceLast:C,patchConversation:m,markConversationRead:b,send:K,clickCallback:S,signAttachment:U,submitFeedback:$,getActionInFlight:V,getLatestSuggestions:re,getLatestForm:ne,setPanelOpen:e.setPanelOpen}}const Oe={w:"#ffffff",g50:"#F9F9F7",g100:"#F5F5F5",g150:"#E8E6E2",g200:"#D9D6CF",g300:"#B4B0A8",g400:"#888480",g500:"#5A5753",g700:"#2B2926",g900:"#17161A",accent:"#5B5FEF",accentLight:"#EEEFFE",green:"#22C55E",red:"#B91C1C",redBg:"#FDECEC"},bs=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function Zs(e=""){return e?bs[e.charCodeAt(0)%bs.length]:bs[0]}function er(e=""){return e.split(" ").map(t=>t[0]||"").join("").toUpperCase().slice(0,2)}function Bs(e=new Date,t="fr-FR"){return e.toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit"})}const Ao=`
18
18
  @import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');
19
19
 
20
20
  .wm-root {
@@ -71,4 +71,4 @@ ${a}`)}return i.join(`
71
71
  `),n=[];let r=0;for(;r<t.length;){const s=t[r];if(/^\s*```([\w-]*)\s*$/.exec(s)){r++;const d=[];for(;r<t.length&&!/^\s*```\s*$/.test(t[r]);)d.push(t[r]),r++;r<t.length&&r++,n.push({type:"block",html:`<pre class="wm-md-pre"><code>${d.join(`
72
72
  `)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(s)){const d=[];for(;r<t.length;){const m=/^\s*[-*]\s+(.*)$/.exec(t[r]);if(!m)break;d.push(m[1]),r++}const c=d.map(m=>`<li>${nn(m)}</li>`).join("");n.push({type:"block",html:`<ul class="wm-md-ul">${c}</ul>`});continue}const a=/^\s*(\d+)\.\s+(.*)$/.exec(s);if(a){const d=parseInt(a[1],10),c=[a[2]];for(r++;r<t.length;){const b=/^\s*\d+\.\s+(.*)$/.exec(t[r]);if(!b)break;c.push(b[1]),r++}const m=c.map(b=>`<li>${nn(b)}</li>`).join(""),C=d!==1?` start="${d}"`:"";n.push({type:"block",html:`<ol class="wm-md-ol"${C}>${m}</ol>`});continue}const l=/^(#{1,6})\s+(.*)$/.exec(s);if(l){const d=l[1].length;n.push({type:"block",html:`<h${d} class="wm-md-h wm-md-h${d}">${nn(l[2])}</h${d}>`}),r++;continue}n.push({type:"text",html:nn(s)}),r++}let i="";for(let s=0;s<n.length;s++){const o=n[s];i+=o.html;const a=n[s+1];a&&o.type!=="block"&&a.type!=="block"&&(i+=`
73
73
  `)}return i}function bn(e){var n;const t=(n=e==null?void 0:e.author)==null?void 0:n.type;return t==="agent_ia"||t==="agent_human"}function ht(e){if(e==null)return null;const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:null}function Qr(e,t){let n=(e==null?void 0:e.last_message_at)||(e==null?void 0:e.updated_at)||(e==null?void 0:e.created_at)||"";for(const r of t)r!=null&&r.created_at&&r.created_at>n&&(n=r.created_at);return n}function Ac(e,t){var n,r,i;for(let s=t.length-1;s>=0;s--){const o=t[s];if(!o)continue;const a=typeof o.text_md=="string"?o.text_md.trim():"";if(a)return(((n=o.author)==null?void 0:n.type)==="user"?"Vous : ":"")+a.replace(/\s+/g," ");const l=(r=o.payload)==null?void 0:r.attachments;if(Array.isArray(l)&&l.length)return"📎 Pièce jointe"}return(e==null?void 0:e.last_message_preview)||(e==null?void 0:e.preview)||((i=e==null?void 0:e.metadata)==null?void 0:i.last_preview)||""}function xc(e,t){return(e==null?void 0:e.name)||((e==null?void 0:e.type)==="user"?t("common.you"):(e==null?void 0:e.type)==="agent_human"?t("common.agent"):(e==null?void 0:e.type)==="agent_ia"?t("common.aiAssistant"):t("common.system"))}function Tc(e,t,n,r){const i=[`# ${e.name||n("common.conversation")}`,e.created_at?n("export.createdOn",{date:new Date(e.created_at).toLocaleString(r)}):"",""];for(const s of t){if(!s)continue;const o=(s.text_md||"").trim();if(!o)continue;const a=xc(s.author,n),l=s.created_at?new Date(s.created_at).toLocaleString(r):"";i.push(`[${l}] ${a} :`),i.push(o),i.push("")}return i.join(`
74
- `)}function Mc(e,t,n=Ee(),r){if(!e)return;const i=Tc(e,t||[],n,Bt(r)),s=new Blob([i],{type:"text/plain;charset=utf-8"});try{const o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${(e.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(()=>URL.revokeObjectURL(o),1e3)}catch(o){console.error("[ww-messenger] export failed",o)}}const Ec={data(){const e=typeof Notification<"u";return{notifPermission:e?Notification.permission:"denied",soundEnabled:!0,browserNotifEnabled:e&&Notification.permission==="granted",_audioCtx:null}},methods:{teardownNotifications(){var e,t;if(this._audioCtx){try{(t=(e=this._audioCtx).close)==null||t.call(e)}catch{}this._audioCtx=null}},soundStorageKey(){return`wm:notif:sound:${this.widgetId||""}`},browserNotifStorageKey(){return`wm:notif:browser:${this.widgetId||""}`},hydrateNotifPref(){try{if(typeof localStorage>"u")return;const e=localStorage.getItem(this.soundStorageKey());e==="0"?this.soundEnabled=!1:e==="1"&&(this.soundEnabled=!0);const t=localStorage.getItem(this.browserNotifStorageKey());t==="0"?this.browserNotifEnabled=!1:t==="1"&&(this.browserNotifEnabled=typeof Notification<"u"&&Notification.permission==="granted")}catch{}},persistSoundPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.soundStorageKey(),this.soundEnabled?"1":"0")}catch{}},persistBrowserNotifPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.browserNotifStorageKey(),this.browserNotifEnabled?"1":"0")}catch{}},onSoundToggle(e){this.soundEnabled=!!e,this.persistSoundPref()},async onBrowserNotifToggle(e){if(typeof Notification>"u"){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}if(!e){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}let t=Notification.permission;if(t==="default"){try{t=await Notification.requestPermission()}catch(n){console.warn("[ww-messenger] notif permission request failed",n),t="denied"}this.notifPermission=t}this.browserNotifEnabled=t==="granted",this.persistBrowserNotifPref()},onMessageRevealed(e,t){var i;if(!this.soundEnabled&&!this.browserNotifEnabled||!t||!e||!bn(e))return;const n=typeof document<"u"&&document.hidden;this.isOpen&&!n&&((i=this.currentConv)==null?void 0:i.id)===t||(this.soundEnabled&&this.playNotificationSound(),this.browserNotifEnabled&&this.showBrowserNotification(t,e))},playNotificationSound(){if(typeof window>"u")return;const e=window.AudioContext||window.webkitAudioContext;if(e)try{this._audioCtx||(this._audioCtx=new e);const t=this._audioCtx;if(t.state==="suspended")try{t.resume()}catch{}const n=t.currentTime,r=t.createOscillator(),i=t.createGain();r.connect(i),i.connect(t.destination),r.type="sine",r.frequency.setValueAtTime(880,n),r.frequency.exponentialRampToValueAtTime(1320,n+.08),i.gain.setValueAtTime(0,n),i.gain.linearRampToValueAtTime(.12,n+.02),i.gain.exponentialRampToValueAtTime(1e-4,n+.28),r.start(n),r.stop(n+.32)}catch{}},showBrowserNotification(e,t){if(typeof Notification>"u"||Notification.permission!=="granted")return;const n=t==null?void 0:t.author,r=!n||n.type==="agent_ia",s=((n==null?void 0:n.name)||(r?this.agentName:"")||this.t("launcher.theAgent"))+this.t("launcher.repliedToYou"),o=typeof(t==null?void 0:t.text_md)=="string"?t.text_md.trim():"",a=o?o.slice(0,140):this.t("notification.youHaveNewMessage");try{const l=new Notification(s,{body:a,tag:`wm-${e}`,renotify:!1,silent:!0});l.onclick=()=>{try{window.focus()}catch{}this.draftConv=null,this.showOnboarding=!1,this.activeConvId=e,this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);try{l.close()}catch{}}}catch(l){console.warn("[ww-messenger] notification failed",l)}}}},Qt=Object.freeze({firstRevealDelayMs:450,msPerChar:50,minTypingMs:900,maxTypingMs:12e3,pauseBetweenMs:300}),Zt=(e,t)=>Number.isFinite(e)?e:t,Oc={computed:{revealPacing(){var t;const e=((t=this.widget)==null?void 0:t.reveal_pacing)||{};return{firstRevealDelayMs:Zt(e.first_reveal_delay_ms,Qt.firstRevealDelayMs),msPerChar:Zt(e.ms_per_char,Qt.msPerChar),minTypingMs:Zt(e.min_typing_ms,Qt.minTypingMs),maxTypingMs:Zt(e.max_typing_ms,Qt.maxTypingMs),pauseBetweenMs:Zt(e.pause_between_ms,Qt.pauseBetweenMs)}}},data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[],_liveRevealOff:null,_liveRevealConvSnapshot:null,_liveHwm:{}}},methods:{cancelReveals(){for(const e of this.revealTimers)clearTimeout(e);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},setupLiveReveal(){var n,r;if(!this.transport)return;this.teardownLiveReveal();const e=this.transport.on("message",i=>{const s=i==null?void 0:i.conversation_id,o=i==null?void 0:i.message;s&&o&&this.paceLiveMessage(o,s)});this._liveRevealConvSnapshot=new Map((((n=this.s)==null?void 0:n.conversations)||[]).map(i=>[i.id,(i==null?void 0:i.last_message_at)||""])),this._liveHwm=Object.fromEntries((((r=this.s)==null?void 0:r.conversations)||[]).map(i=>[i.id,(i==null?void 0:i.last_message_at)||""]));const t=this.transport.on("activity",i=>{this.handleLiveActivity(i)});this._liveRevealOff=()=>{try{e()}catch{}try{t()}catch{}}},teardownLiveReveal(){if(this._liveRevealOff){try{this._liveRevealOff()}catch{}this._liveRevealOff=null}this._liveRevealConvSnapshot=null,this._liveHwm={}},async handleLiveActivity(e){var i,s;const t=e==null?void 0:e.conversations;if(!Array.isArray(t)||!this.store)return;const n=this._liveRevealConvSnapshot||new Map,r=[];for(const o of t){if(!(o!=null&&o.id))continue;const a=o.last_message_at||"";if(!a)continue;const l=n.get(o.id)||"";a>l&&r.push(o.id)}this._liveRevealConvSnapshot=new Map(t.map(o=>[o.id,(o==null?void 0:o.last_message_at)||""]));for(const o of r)try{const a=await((s=(i=this.store).fetchSinceLast)==null?void 0:s.call(i,o));if(!Array.isArray(a))continue;for(const l of a)this.paceLiveMessage(l,o)}catch(a){console.error("[ww-messenger] activity delta fetch failed",a)}},scheduleReveal(e,t){const n=this.revealPacing,r=Date.now(),i=((e==null?void 0:e.text_md)||"").length,s=Math.min(n.maxTypingMs,Math.max(n.minTypingMs,i*n.msPerChar)),a=Math.max(r+n.firstRevealDelayMs,this.nextRevealAt+n.pauseBetweenMs)+s;this.nextRevealAt=a;const l=Math.max(0,a-r),d=e.id,c=setTimeout(()=>{this.revealedAt={...this.revealedAt,[d]:Date.now()},this.revealTimers=this.revealTimers.filter(m=>m!==c),typeof this.onMessageRevealed=="function"&&this.onMessageRevealed(e,t)},l);this.revealTimers.push(c)},paceMessages(e,t){var i;if(!Array.isArray(e)||!e.length)return;const n=Date.now(),r={...this.revealedAt};for(const s of e){if((s==null?void 0:s.id)==null||r[s.id]!==void 0)continue;if(!bn(s)){r[s.id]=n;continue}const o=s!=null&&s.created_at?Date.parse(s.created_at):NaN;if(!Number.isFinite(o)||o<this.convOpenedAt){r[s.id]=n;continue}const a=typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0,l=Array.isArray((i=s==null?void 0:s.payload)==null?void 0:i.attachments)&&s.payload.attachments.length>0;if(!a&&!l){r[s.id]=n;continue}r[s.id]=0,this.scheduleReveal(s,t)}this.revealedAt=r},paceLiveMessage(e,t){var a;if(!(e!=null&&e.id)||this.revealedAt[e.id]!==void 0)return;if(!bn(e)){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}const n=typeof(e==null?void 0:e.text_md)=="string"&&e.text_md.trim().length>0,r=Array.isArray((a=e==null?void 0:e.payload)==null?void 0:a.attachments)&&e.payload.attachments.length>0;if(!n&&!r){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}const i=this._liveHwm[t],s=(e==null?void 0:e.created_at)||"";if(s&&(i===void 0||s>i)&&(this._liveHwm={...this._liveHwm,[t]:s}),!(i!==void 0&&s&&s>i)){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}this.revealedAt={...this.revealedAt,[e.id]:0},this.scheduleReveal(e,t)}}},Rc=300,Ic={data(){return{unreadAnchorId:null,unreadBoundaryTs:""}},created(){this._readMarkerTimer=null,this._readMarkerPending=null},beforeUnmount(){this._readMarkerTimer&&(clearTimeout(this._readMarkerTimer),this._readMarkerTimer=null),this._readMarkerPending=null},methods:{markConvRead(e){var s,o;if(!(e!=null&&e.id)||e._draft||!this.store)return;const t=((o=(s=this.s)==null?void 0:s.messagesByConv)==null?void 0:o[e.id])||[],n=Lc(t);if(n==null)return;const r=ht(e.last_read_message_id),i=ht(n);i!=null&&(r!=null&&i<=r||(this._readMarkerPending={convId:e.id,messageId:n},!this._readMarkerTimer&&(this._readMarkerTimer=setTimeout(()=>{const a=this._readMarkerPending;this._readMarkerPending=null,this._readMarkerTimer=null,a&&this.store&&this.store.markConversationRead(a.convId,a.messageId)},Rc))))}}};function Lc(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(!(!n||n._pending)&&ht(n.id)!=null)return n.id}return null}const be=(e,t)=>{const n=e.__vccOpts||e;for(const[r,i]of t)n[r]=i;return n},Pc={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26},tail:{type:Boolean,default:!1}},computed:{bg(){return this.avatarUrl?"transparent":Zs(this.name)},initials(){return er(this.name)}}},Bc=["src","alt"];function Fc(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-huav",{"wm-huav--tail":n.tail}]),style:Ce({width:n.size+"px",height:n.size+"px","--wm-avr":Math.round(n.size*.32)+"px",background:s.bg})},[n.avatarUrl?(h(),p("img",{key:0,src:n.avatarUrl,alt:n.name||""},null,8,Bc)):(h(),p("span",{key:1,style:Ce({fontSize:n.size*.36+"px"})},R(s.initials),5))],6)}const rs=be(Pc,[["render",Fc],["__scopeId","data-v-14e10c0d"]]),Dc=3,Nc={name:"WmLauncher",components:{HumanAvatar:rs},inject:{t:{default:()=>Ee()}},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,Dc).reverse()}}},Hc=["aria-label","onClick","onKeydown"],Uc=["aria-label","onClick"],jc={class:"wm-peek__avatar"},Vc=["aria-label"],Kc={class:"wm-peek__body"},zc={class:"wm-peek__head"},Wc={class:"wm-peek__name"},$c={class:"wm-peek__action"},qc={class:"wm-peek__text"},Gc=["onClick"],Yc=["aria-label"],Jc=["aria-label"];function Xc(e,t,n,r,i,s){const o=ve("HumanAvatar");return h(),p("div",{class:"wm-launcherWrap",onMouseenter:t[1]||(t[1]=a=>e.$emit("hover",!0)),onMouseleave:t[2]||(t[2]=a=>e.$emit("hover",!1)),onFocusin:t[3]||(t[3]=a=>e.$emit("hover",!0)),onFocusout:t[4]||(t[4]=a=>e.$emit("hover",!1))},[pe(Qs,{name:"wm-peek"},{default:Xn(()=>[s.visiblePeeks.length?(h(),p("div",{key:0,class:te(["wm-peekStack",{"wm-peekStack--multi":s.visiblePeeks.length>1}])},[(h(!0),p(Z,null,Se(s.visiblePeeks,(a,l)=>(h(),p("div",{key:a.convId,class:"wm-peek",style:Ce({"--depth":s.visiblePeeks.length-1-l,zIndex:l+1}),role:"button",tabindex:"0","aria-label":s.t("launcher.openConversationWith",{name:a.senderName||s.t("launcher.theAgent")}),onClick:d=>e.$emit("open",a.convId),onKeydown:[Un(We(d=>e.$emit("open",a.convId),["prevent"]),["enter"]),Un(We(d=>e.$emit("open",a.convId),["prevent"]),["space"])]},[u("button",{type:"button",class:"wm-peek__close","aria-label":s.t("launcher.dismiss"),onClick:We(d=>e.$emit("dismiss",a.convId),["stop"])},[...t[5]||(t[5]=[u("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,Uc),u("div",jc,[pe(o,{name:a.senderName,"avatar-url":a.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),a.count>1?(h(),p("span",{key:0,class:"wm-peek__avatarBadge","aria-label":s.t("launcher.unreadMessages",{count:a.count})},R(a.count>9?"9+":a.count),9,Vc)):F("",!0)]),u("div",Kc,[u("div",zc,[u("span",Wc,R(a.senderName||s.t("common.agent")),1),u("span",$c,R(s.t("launcher.repliedToYou")),1)]),u("p",qc,R(a.preview),1)]),u("button",{type:"button",class:"wm-peek__open",onClick:We(d=>e.$emit("open",a.convId),["stop"])},R(s.t("common.open")),9,Gc)],44,Hc))),128))],2)):F("",!0)]),_:1}),u("button",{type:"button",class:"wm-launcher","aria-label":s.t("launcher.open"),onClick:t[0]||(t[0]=a=>e.$emit("open"))},[t[6]||(t[6]=u("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)),n.unreadCount>0?(h(),p("span",{key:0,class:"wm-launcher__badge","aria-label":n.unreadCount>1?s.t("launcher.unreadConversationsMany",{count:n.unreadCount}):s.t("launcher.unreadConversationsOne",{count:n.unreadCount})},R(n.unreadCount>9?"9+":n.unreadCount),9,Jc)):F("",!0)],8,Yc)],32)}const Qc=be(Nc,[["render",Xc],["__scopeId","data-v-d81459bc"]]),Zc={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1},tail:{type:Boolean,default:!1},name:{type:String,default:""},imageUrl:{type:String,default:null}},computed:{initials(){return er(this.name)},bgColor(){return Zs(this.name)}}},eu={key:0,class:"wm-aiav__pulse"},tu=["src","alt"],nu=["width","height"];function su(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-aiav",{"wm-aiav--tail":n.tail}]),style:Ce({width:n.size+"px",height:n.size+"px","--wm-avr":n.size*.32+"px"})},[n.pulse?(h(),p("div",eu)):F("",!0),u("div",{class:te(["wm-aiav__inner",{"wm-aiav__inner--glow":n.pulse,"wm-aiav__inner--img":!!n.imageUrl,"wm-aiav__inner--initials":!n.imageUrl&&!!s.initials}]),style:Ce(!n.imageUrl&&s.initials?{background:s.bgColor}:null)},[n.imageUrl?(h(),p("img",{key:0,src:n.imageUrl,alt:n.name||""},null,8,tu)):s.initials?(h(),p("span",{key:1,style:Ce({fontSize:n.size*.36+"px"})},R(s.initials),5)):(h(),p("svg",{key:2,width:n.size*.5,height:n.size*.5,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[...t[0]||(t[0]=[u("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"white",opacity:"0.92"},null,-1),u("circle",{cx:"19",cy:"5",r:"1.5",fill:"white",opacity:"0.55"},null,-1),u("circle",{cx:"5",cy:"18",r:"1",fill:"white",opacity:"0.38"},null,-1)])],8,nu))],6)],6)}const Sn=be(Zc,[["render",su],["__scopeId","data-v-6f7f685d"]]),ru={name:"WmTeamAvatars",props:{members:{type:Array,default:()=>[]},responseLabel:{type:String,default:""}},computed:{visible(){return Array.isArray(this.members)&&this.members.length>0},stackWidth(){return Math.min(this.members.length,3)===1?20:16+Math.min(this.members.length,3)*13}},methods:{colorFor(e){return e.avatar_url?"transparent":Zs(e.name||"")},initialsFor(e){return er(e.name||"")}}},iu={key:0,class:"wm-team"},ou=["src","alt"],au={key:1},lu={key:0,class:"wm-team__label"};function cu(e,t,n,r,i,s){return s.visible?(h(),p("div",iu,[u("div",{class:"wm-team__stack",style:Ce({width:s.stackWidth+"px"})},[(h(!0),p(Z,null,Se(n.members.slice(0,3),(o,a)=>(h(),p("div",{key:a,class:"wm-team__pill",style:Ce({left:a*13+"px",zIndex:3-a,background:s.colorFor(o)})},[o.avatar_url?(h(),p("img",{key:0,src:o.avatar_url,alt:o.name||""},null,8,ou)):(h(),p("span",au,R(s.initialsFor(o)),1))],4))),128))],4),n.responseLabel?(h(),p("span",lu,R(n.responseLabel),1)):F("",!0)])):F("",!0)}const uu=be(ru,[["render",cu],["__scopeId","data-v-e49a9063"]]),du={name:"WmHeader",components:{AIAvatar:Sn,TeamAvatars:uu},inject:{t:{default:()=>Ee()}},props:{title:{type:String,default:"Nouvelle conversation"},showBack:{type:Boolean,default:!1},teamMembers:{type:Array,default:()=>[]},responseLabel:{type:String,default:""},showClose:{type:Boolean,default:!0},showMore:{type:Boolean,default:!0},moreActive:{type:Boolean,default:!1},showIdentity:{type:Boolean,default:!0},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["back","close","more"],computed:{hasTeam(){return Array.isArray(this.teamMembers)&&this.teamMembers.length>0},displayedTeamMembers(){const e=Array.isArray(this.teamMembers)?this.teamMembers:[];if(e.length<=3)return e;const t=new Date().getHours()%e.length,n=[];for(let r=0;r<3;r++)n.push(e[(t+r)%e.length]);return n}}},fu={class:"wm-header"},hu=["aria-label"],mu={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},gu={class:"wm-header__avatar"},pu={class:"wm-header__main"},_u={class:"wm-header__title"},yu={key:3,class:"wm-header__fill"},vu={class:"wm-header__actions"},bu=["aria-label","title"],wu=["aria-label","title"];function ku(e,t,n,r,i,s){const o=ve("AIAvatar"),a=ve("TeamAvatars");return h(),p("div",fu,[n.showBack?(h(),p("button",{key:0,type:"button",class:"wm-header__icon wm-header__back","aria-label":s.t("header.backToHome"),onClick:t[0]||(t[0]=l=>e.$emit("back"))},[...t[3]||(t[3]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M19 12H5M12 5l-7 7 7 7"})],-1)])],8,hu)):(h(),p("div",mu)),n.showIdentity?(h(),p(Z,{key:2},[u("div",gu,[pe(o,{size:30,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",pu,[u("div",_u,R(n.title),1)]),s.hasTeam?(h(),fe(a,{key:0,members:s.displayedTeamMembers,"response-label":""},null,8,["members"])):F("",!0)],64)):(h(),p("div",yu)),u("div",vu,[n.showMore?(h(),p("button",{key:0,type:"button",class:te(["wm-header__icon",{"wm-header__icon--active":n.moreActive}]),"aria-label":s.t("header.moreOptions"),title:s.t("header.moreOptions"),onClick:t[1]||(t[1]=l=>e.$emit("more"))},[...t[4]||(t[4]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},[u("circle",{cx:"12",cy:"5",r:"1.6"}),u("circle",{cx:"12",cy:"12",r:"1.6"}),u("circle",{cx:"12",cy:"19",r:"1.6"})],-1)])],10,bu)):F("",!0),n.showClose?(h(),p("button",{key:1,type:"button",class:"wm-header__icon","aria-label":s.t("header.closeWidget"),title:s.t("header.closeWidget"),onClick:t[2]||(t[2]=l=>e.$emit("close"))},[...t[5]||(t[5]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,wu)):F("",!0)])])}const Cu=be(du,[["render",ku],["__scopeId","data-v-27232009"]]),Zr={book:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253",changelog:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",status:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",chat:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z",link:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"},Su={name:"WmOnboarding",components:{AIAvatar:Sn,HumanAvatar:rs},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{title:{type:String,default:""},subtitle:{type:String,default:""},agentName:{type:String,default:""},defaultIconUrl:{type:String,default:null},coverImageUrl:{type:String,default:null},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1},launching:{type:Boolean,default:!1},welcomeMessage:{type:String,default:""}},emits:["start","launched","select","resume","view-history"],data(){return{launchPhase:"idle",inputFocused:!1,launchDone:!1,starterText:""}},watch:{launching(e){e&&this.runLaunch()}},computed:{canStart(){return!this.busy&&!!this.starterText.trim()},typing(){return this.inputFocused&&!!this.starterText.trim()},heroTitle(){return this.title?this.title:this.agentName?this.t("onboarding.greetingNamed",{name:this.agentName}):this.t("onboarding.greeting")},heroSub(){return this.subtitle||this.t("onboarding.heroSub")},unreadThreads(){return this.openThreads.filter(e=>e.unread)},safeCoverUrl(){return Gr(this.coverImageUrl)},hasCover(){return!!this.safeCoverUrl},coverStyle(){return this.safeCoverUrl?{backgroundImage:`url("${this.safeCoverUrl}")`}:null}},methods:{submitStarter(){this.canStart&&this.$emit("start",this.starterText.trim())},onStarterKeydown(e){e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.submitStarter())},onInputFocus(){this.launchPhase==="idle"&&(this.inputFocused=!0,this.$nextTick(()=>this.autosize()))},onInputBlur(){this.launchPhase==="idle"&&(this.inputFocused=!1,this.$nextTick(()=>this.autosize()))},autosize(){const e=this.$refs.starterInput;if(!e||e.clientWidth<40)return;e.style.height="auto",e.style.minHeight="0px";const t=e.scrollHeight;e.style.minHeight="",e.style.height=t>62?`${Math.min(t,120)}px`:""},async runLaunch(){const e=this.$refs.starterForm,t=typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(!e||t){this.launchPhase="fade",await this.wait(t?120:0),this.finishLaunch();return}this.launchPhase="fade",await this.wait(320);const n=e.getBoundingClientRect();this.launchPhase="slide",await this.$nextTick();const r=e.getBoundingClientRect(),i=n.left-r.left,s=n.top-r.top;e.style.transition="none",e.style.transform=`translate(${i}px, ${s}px)`,e.offsetWidth,e.style.transition="transform 0.44s cubic-bezier(0.32, 0.72, 0, 1)",e.style.transform="translate(0, 0)";const o=()=>{e.removeEventListener("transitionend",o),this.finishLaunch()};e.addEventListener("transitionend",o),this.wait(520).then(()=>this.finishLaunch())},finishLaunch(){this.launchDone||(this.launchDone=!0,this.$emit("launched"))},wait(e){return new Promise(t=>window.setTimeout(t,e))},iconPath(e){return Zr[e]||Zr.link},isExternalLink(e){const t=e==null?void 0:e.url;return!!t&&!t.startsWith("#")},safeIconUrl(e){return Gr(e==null?void 0:e.icon_url)},iconUrlStyle(e){const t=this.safeIconUrl(e);return t?{"--icon-url":`url("${t}")`}:null},renderPreview(e){return Mo(e)},avatarComponent(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.type)==="agent_human"?"HumanAvatar":"AIAvatar"},avatarProps(e){const t=e==null?void 0:e.author;return(t==null?void 0:t.type)==="agent_human"?{size:40,name:t.name||"",avatarUrl:t.avatar_url||null}:{size:40,name:(t==null?void 0:t.name)||"",imageUrl:(t==null?void 0:t.avatar_url)||null}},isDefaultAvatar(e){const t=e==null?void 0:e.author;return!(t!=null&&t.avatar_url||t!=null&&t.name)},avatarWrapperClass(e){return this.isDefaultAvatar(e)&&!(e!=null&&e.unread)?"wm-onb__avatar--muted":null},senderLabel(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.name)||""},formatTs(e){if(!e)return"";const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=Bt(this.wmLocale()),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});if(r.getTime()-t.getTime()<7*864e5){const o=t.toLocaleDateString(n,{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return t.toLocaleDateString(n,{day:"2-digit",month:"2-digit"})}}},Au=["aria-label"],xu={key:1,class:"wm-onb__hero-deco",width:"180",height:"180",viewBox:"0 0 180 180",fill:"none","aria-hidden":"true"},Tu={class:"wm-onb__hero-text"},Mu={class:"wm-onb__hero-default"},Eu={class:"wm-onb__title"},Ou={class:"wm-onb__sub"},Ru={key:0,class:"wm-onb__welcome"},Iu={key:0,class:"wm-onb__alertList"},Lu=["onClick"],Pu={key:0,class:"wm-onb__defaultAvatar"},Bu=["aria-label"],Fu={class:"wm-onb__alert-body"},Du={class:"wm-onb__alert-title"},Nu={class:"wm-onb__alert-preview"},Hu={key:0,class:"wm-onb__alert-sender"},Uu=["innerHTML"],ju={class:"wm-onb__alert-meta"},Vu={key:0,class:"wm-onb__alert-time"},Ku={class:"wm-onb__alert-resume"},zu={class:"wm-onb__actions"},Wu=["onClick"],$u={class:"wm-onb__btn-icon"},qu=["aria-label"],Gu={key:1,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.9","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},Yu=["d"],Ju={class:"wm-onb__btn-label"},Xu={key:0,class:"wm-onb__btn-trail",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},Qu={class:"wm-onb__btn-icon"},Zu={width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},ed=["d"],td={class:"wm-onb__btn-label"},nd={class:"wm-onb__btn-count"},sd=["placeholder","disabled","aria-label"],rd=["disabled","aria-label"],id={key:0,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},od={key:1,class:"wm-onb__starter-spinner","aria-hidden":"true"};function ad(e,t,n,r,i,s){const o=ve("AIAvatar");return h(),p("div",{class:te(["wm-onb",{"wm-onb--launching":i.launchPhase!=="idle","wm-onb--sliding":i.launchPhase==="slide","wm-onb--focused":i.inputFocused,"wm-onb--typing":s.typing}])},[u("div",{class:te(["wm-onb__hero",{"wm-onb__hero--cover":s.hasCover}])},[s.hasCover?(h(),p("div",{key:0,class:"wm-onb__cover",style:Ce(s.coverStyle),role:"img","aria-label":s.heroTitle},null,12,Au)):F("",!0),s.hasCover?F("",!0):(h(),p("svg",xu,[...t[7]||(t[7]=[u("circle",{cx:"170",cy:"10",r:"105",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.35"},null,-1),u("circle",{cx:"170",cy:"10",r:"72",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.5"},null,-1),u("circle",{cx:"152",cy:"34",r:"2.5",fill:"#5B5FEF",opacity:"0.65"},null,-1)])])),pe(o,{size:52,"image-url":n.defaultIconUrl},null,8,["image-url"]),u("div",Tu,[u("div",Mu,[u("div",Eu,R(s.heroTitle),1),u("div",Ou,R(s.heroSub),1)]),n.welcomeMessage?(h(),p("div",Ru,R(n.welcomeMessage),1)):F("",!0)])],2),s.unreadThreads.length?(h(),p("div",Iu,[(h(!0),p(Z,null,Se(s.unreadThreads,a=>(h(),p("button",{key:a.id,type:"button",class:"wm-onb__alert",onClick:l=>e.$emit("resume",a)},[u("span",{class:te(["wm-onb__alert-avatar",s.avatarWrapperClass(a)])},[s.isDefaultAvatar(a)?(h(),p("span",Pu,[...t[8]||(t[8]=[u("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)])])):(h(),fe(qs(s.avatarComponent(a)),Xs({key:1,ref_for:!0},s.avatarProps(a)),null,16)),u("span",{class:"wm-onb__alert-dot","aria-label":s.t("onboarding.unread")},null,8,Bu)],2),u("span",Fu,[u("span",Du,R(a.title),1),u("span",Nu,[s.senderLabel(a)?(h(),p("span",Hu,R(s.senderLabel(a))+" · ",1)):F("",!0),u("span",{innerHTML:s.renderPreview(a.preview)},null,8,Uu)])]),u("span",ju,[s.formatTs(a._ts)?(h(),p("span",Vu,R(s.formatTs(a._ts)),1)):F("",!0),u("span",Ku,R(s.t("onboarding.resume")),1)])],8,Lu))),128))])):F("",!0),u("div",zu,[(h(!0),p(Z,null,Se(n.quickLinks,(a,l)=>(h(),p("button",{key:"ql-"+l,type:"button",class:"wm-onb__btn",onClick:d=>e.$emit("select",a)},[u("span",$u,[s.safeIconUrl(a)?(h(),p("span",{key:0,class:"wm-onb__btn-iconImg",style:Ce(s.iconUrlStyle(a)),role:"img","aria-label":a.label||""},null,12,qu)):(h(),p("svg",Gu,[u("path",{d:s.iconPath(a.icon)},null,8,Yu)]))]),u("span",Ju,R(a.label),1),s.isExternalLink(a)?(h(),p("svg",Xu,[...t[9]||(t[9]=[u("path",{d:"M7 17L17 7M9 7h8v8"},null,-1)])])):F("",!0)],8,Wu))),128)),n.openThreads.length?(h(),p("button",{key:0,type:"button",class:"wm-onb__btn",onClick:t[0]||(t[0]=a=>e.$emit("view-history"))},[u("span",Qu,[(h(),p("svg",Zu,[u("path",{d:s.iconPath("chat")},null,8,ed)]))]),u("span",td,R(s.t("onboarding.allConversations")),1),u("span",nd,R(n.openThreads.length),1),t[10]||(t[10]=u("svg",{class:"wm-onb__btn-trail",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M9 18l6-6-6-6"})],-1))])):F("",!0),u("form",{ref:"starterForm",class:te(["wm-onb__starter",{"is-active":!!i.starterText.trim(),"is-expanded":i.inputFocused,"wm-onb__starter--toBottom":i.launchPhase==="slide"}]),onSubmit:t[6]||(t[6]=We((...a)=>s.submitStarter&&s.submitStarter(...a),["prevent"]))},[st(u("textarea",{ref:"starterInput","onUpdate:modelValue":t[1]||(t[1]=a=>i.starterText=a),class:"wm-onb__starter-input",rows:"1",placeholder:s.t("onboarding.starterPlaceholder"),disabled:n.busy,"aria-label":s.t("onboarding.start"),enterkeyhint:"send",onKeydown:t[2]||(t[2]=(...a)=>s.onStarterKeydown&&s.onStarterKeydown(...a)),onInput:t[3]||(t[3]=(...a)=>s.autosize&&s.autosize(...a)),onFocus:t[4]||(t[4]=(...a)=>s.onInputFocus&&s.onInputFocus(...a)),onBlur:t[5]||(t[5]=(...a)=>s.onInputBlur&&s.onInputBlur(...a))},null,40,sd),[[kt,i.starterText]]),u("button",{type:"submit",class:te(["wm-onb__starter-send",{"is-empty":!s.canStart}]),disabled:n.busy||!s.canStart,"aria-label":s.t("composer.send")},[n.busy?(h(),p("span",od)):(h(),p("svg",id,[...t[11]||(t[11]=[u("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"},null,-1)])]))],10,rd)],34)])],2)}const ld=be(Su,[["render",ad],["__scopeId","data-v-cfaffcfa"]]),cd={name:"WmHistory",components:{AIAvatar:Sn,HumanAvatar:rs},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{threads:{type:Array,default:()=>[]}},emits:["resume"],data(){return{query:""}},computed:{filteredThreads(){const e=this.query.trim().toLowerCase();return e?this.threads.filter(t=>(t.title||"").toLowerCase().includes(e)||(t.preview||"").toLowerCase().includes(e)):this.threads}},methods:{renderPreview(e){return Mo(e)},avatarComponent(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.type)==="agent_human"?"HumanAvatar":"AIAvatar"},avatarProps(e){const t=e==null?void 0:e.author;return(t==null?void 0:t.type)==="agent_human"?{size:40,name:t.name||"",avatarUrl:t.avatar_url||null}:{size:40,name:(t==null?void 0:t.name)||"",imageUrl:(t==null?void 0:t.avatar_url)||null}},isDefaultAvatar(e){const t=e==null?void 0:e.author;return!(t!=null&&t.avatar_url||t!=null&&t.name)},avatarWrapperClass(e){return this.isDefaultAvatar(e)&&!(e!=null&&e.unread)?"wm-hist__avatar--muted":null},formatTs(e){if(!e)return"";const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=Bt(this.wmLocale()),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});if(r.getTime()-t.getTime()<7*864e5){const o=t.toLocaleDateString(n,{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return t.toLocaleDateString(n,{day:"2-digit",month:"2-digit"})}}},ud={class:"wm-hist"},dd={class:"wm-hist__search"},fd=["placeholder","aria-label"],hd={class:"wm-hist__list"},md=["onClick"],gd={key:0,class:"wm-hist__defaultAvatar"},pd=["aria-label"],_d={class:"wm-hist__thread-body"},yd={class:"wm-hist__thread-title"},vd=["innerHTML"],bd={class:"wm-hist__thread-meta"},wd={key:0,class:"wm-hist__thread-time"},kd={key:0,class:"wm-hist__empty"};function Cd(e,t,n,r,i,s){return h(),p("div",ud,[u("div",dd,[t[1]||(t[1]=u("span",{class:"wm-hist__searchIcon"},[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),st(u("input",{"onUpdate:modelValue":t[0]||(t[0]=o=>i.query=o),type:"text",placeholder:s.t("onboarding.search"),"aria-label":s.t("onboarding.search")},null,8,fd),[[kt,i.query]])]),u("div",hd,[(h(!0),p(Z,null,Se(s.filteredThreads,o=>(h(),p("button",{key:o.id,type:"button",class:te(["wm-hist__thread",{"wm-hist__thread--unread":o.unread}]),onClick:a=>e.$emit("resume",o)},[u("span",{class:te(["wm-hist__thread-avatar",s.avatarWrapperClass(o)])},[s.isDefaultAvatar(o)?(h(),p("span",gd,[...t[2]||(t[2]=[u("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})],-1)])])):(h(),fe(qs(s.avatarComponent(o)),Xs({key:1,ref_for:!0},s.avatarProps(o)),null,16)),o.unread?(h(),p("span",{key:2,class:"wm-hist__thread-dot","aria-label":s.t("onboarding.unread")},null,8,pd)):F("",!0)],2),u("span",_d,[u("span",yd,R(o.title),1),u("span",{class:"wm-hist__thread-preview",innerHTML:s.renderPreview(o.preview)},null,8,vd)]),u("span",bd,[s.formatTs(o._ts)?(h(),p("span",wd,R(s.formatTs(o._ts)),1)):F("",!0),t[3]||(t[3]=u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-hist__thread-chev","aria-hidden":"true"},[u("path",{d:"M5 12h14M13 5l7 7-7 7"})],-1))])],10,md))),128)),s.filteredThreads.length?F("",!0):(h(),p("div",kd,R(i.query?s.t("onboarding.noResults",{query:i.query}):s.t("onboarding.noConversations")),1))])])}const Sd=be(cd,[["render",Cd],["__scopeId","data-v-6bf35ef1"]]);function Ad(e){return typeof e!="string"?"":e.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"$1").replace(/__([^_]+)__/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\s+/g," ").trim()}const xd={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return Ad(this.detail)}}},Td={class:"wm-result__icon","aria-hidden":"true"},Md={key:0,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round"},Ed={key:1,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.6","stroke-linecap":"round","stroke-linejoin":"round"},Od={key:2,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round"},Rd={key:3,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round"},Id={class:"wm-result__body"},Ld={class:"wm-result__label"},Pd={class:"wm-result__detail"};function Bd(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-result",`wm-result--${n.state}`])},[u("span",Td,[n.state==="success"?(h(),p("svg",Md,[...t[0]||(t[0]=[u("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):n.state==="rejected"?(h(),p("svg",Ed,[...t[1]||(t[1]=[u("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):n.state==="awaiting"?(h(),p("svg",Od,[...t[2]||(t[2]=[u("circle",{cx:"12",cy:"12",r:"10"},null,-1),u("polyline",{points:"12 7 12 12 15 14"},null,-1)])])):(h(),p("svg",Rd,[...t[3]||(t[3]=[u("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"},null,-1),u("line",{x1:"12",y1:"9",x2:"12",y2:"13"},null,-1),u("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"},null,-1)])]))]),u("span",Id,[u("span",Ld,R(n.label),1),s.detailText?(h(),p(Z,{key:0},[t[4]||(t[4]=u("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),u("span",Pd,R(s.detailText),1)],64)):F("",!0)])],2)}const Fd=be(xd,[["render",Bd],["__scopeId","data-v-7284acd0"]]),Dd={name:"WmArtifactFormResponse",inject:{t:{default:()=>Ee()}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]}}},Nd={class:"wm-art wm-art--formResponse"},Hd={class:"wm-art__head"},Ud={class:"wm-art__title"},jd={class:"wm-art__badge wm-art__badge--success"},Vd={class:"wm-art__body"},Kd={class:"wm-art__fieldLabel"};function zd(e,t,n,r,i,s){return h(),p("div",Nd,[u("div",Hd,[u("div",Ud,R(n.data.title||s.t("form.title")),1),u("span",jd,[t[0]||(t[0]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("polyline",{points:"20 6 9 17 4 12"})],-1)),ns(" "+R(s.t("form.sent")),1)])]),u("div",Vd,[(h(!0),p(Z,null,Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",Kd,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128))])])}const Wd=be(Dd,[["render",zd],["__scopeId","data-v-713aecf1"]]),$d={name:"WmArtifactInfoCard",props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]},hasBody(){var e;return!!((e=this.data)!=null&&e.body)||this.fields.length>0}}},qd={class:"wm-art wm-art--infoCard"},Gd={key:0,class:"wm-art__image"},Yd=["src","alt"],Jd={class:"wm-art__head"},Xd={class:"wm-art__headMain"},Qd={class:"wm-art__title"},Zd={key:0,class:"wm-art__subtitle"},ef={key:1,class:"wm-art__body"},tf={key:0,class:"wm-art__text"},nf={class:"wm-art__fieldLabel"};function sf(e,t,n,r,i,s){return h(),p("div",qd,[n.data.image_url?(h(),p("figure",Gd,[u("img",{src:n.data.image_url,alt:n.data.title||"",loading:"lazy"},null,8,Yd)])):F("",!0),u("div",Jd,[u("div",Xd,[u("div",Qd,R(n.data.title),1),n.data.subtitle?(h(),p("div",Zd,R(n.data.subtitle),1)):F("",!0)]),n.data.badge&&n.data.badge.label?(h(),p("span",{key:0,class:te(["wm-art__badge",`wm-art__badge--${n.data.badge.tone||"neutral"}`])},R(n.data.badge.label),3)):F("",!0)]),s.hasBody?(h(),p("div",ef,[n.data.body?(h(),p("div",tf,R(n.data.body),1)):F("",!0),s.fields.length?(h(!0),p(Z,{key:1},Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",nf,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128)):F("",!0)])):F("",!0)])}const rf=be($d,[["render",sf],["__scopeId","data-v-7eae0e4a"]]);function of(e,t,n){if(!e)return"";const r=new Date(e);if(Number.isNaN(r.getTime()))return e;const i=r.toLocaleDateString(t,{day:"numeric",month:"long",year:"numeric"}),s=r.toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit"});return`${i}${n}${s}`}const af={name:"WmArtifactTicket",inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]},formattedDate(){var e;return of((e=this.data)==null?void 0:e.created_at,Bt(this.wmLocale()),this.t("ticket.dateAt"))}},methods:{isPriority(e){return/priorit|^prio$/i.test(String(e||"").trim())},isDate(e){return/date|échéanc|echeanc|deadline|due|créé|cree/i.test(String(e||"").trim())},priorityLevel(e){const t=String(e||"").toLowerCase();return/high|haute|élev|elev|critic|critiq|urgent/.test(t)?3:/low|basse|faible|minor/.test(t)?1:2}}},lf={class:"wm-art wm-art--ticket"},cf={class:"wm-art__head wm-tk__head"},uf={class:"wm-art__title wm-tk__title"},df={class:"wm-tk__sub"},ff={class:"wm-tk__ref"},hf={key:0,class:"wm-tk__text"},mf={key:0,class:"wm-art__body"},gf={class:"wm-art__fieldLabel"},pf=["data-level"],_f={key:1,class:"wm-tk__date",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},yf={key:1,class:"wm-art__footer wm-tk__footer"};function vf(e,t,n,r,i,s){return h(),p("div",lf,[u("div",cf,[u("div",uf,R(n.data.title),1),u("div",df,[u("div",ff,[t[0]||(t[0]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M20 12a2 2 0 0 1 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v4a2 2 0 0 1 0 4v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 1-2-2z"}),u("path",{d:"M13 5v2M13 17v2M13 11v2"})],-1)),u("span",null,R(n.data.reference),1)]),u("span",{class:te(["wm-art__badge","wm-tk__badge",`wm-art__badge--${n.data.status.tone||"neutral"}`])},[t[1]||(t[1]=u("span",{class:"wm-tk__dot","aria-hidden":"true"},null,-1)),ns(" "+R(n.data.status.label),1)],2)]),n.data.body?(h(),p("div",hf,R(n.data.body),1)):F("",!0)]),s.fields.length?(h(),p("div",mf,[(h(!0),p(Z,null,Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",gf,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},[s.isPriority(o.label)?(h(),p("svg",{key:0,class:"wm-tk__prio","data-level":s.priorityLevel(o.value),width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true"},[...t[2]||(t[2]=[u("rect",{x:"1",y:"8",width:"2",height:"3",rx:"0.5"},null,-1),u("rect",{x:"5",y:"5",width:"2",height:"6",rx:"0.5"},null,-1),u("rect",{x:"9",y:"2",width:"2",height:"9",rx:"0.5"},null,-1)])],8,pf)):s.isDate(o.label)?(h(),p("svg",_f,[...t[3]||(t[3]=[u("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"},null,-1),u("path",{d:"M16 2v4M8 2v4M3 10h18"},null,-1)])])):F("",!0),u("span",null,R(o.value),1)],2)]))),128))])):F("",!0),n.data.created_at?(h(),p("div",yf,[t[4]||(t[4]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),u("path",{d:"M16 2v4M8 2v4M3 10h18"})],-1)),u("span",null,R(s.formattedDate),1)])):F("",!0)])}const bf=be(af,[["render",vf],["__scopeId","data-v-5f30c914"]]),wf={form_response:Wd,info_card:rf,ticket:bf},kf={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const e=(t=this.artifact)==null?void 0:t.kind;return e&&wf[e]||null}}};function Cf(e,t,n,r,i,s){return s.component?(h(),fe(qs(s.component),{key:0,data:n.artifact.data},null,8,["data"])):F("",!0)}const Sf=be(kf,[["render",Cf]]),Af={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null},t:{default:()=>Ee()}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var n,r;const e=(n=this.attachment)==null?void 0:n.type;if(e)return e;const t=(((r=this.attachment)==null?void 0:r.mime_type)||"").toLowerCase();return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"file"},displayName(){var e,t,n;return((t=(e=this.attachment)==null?void 0:e.metadata)==null?void 0:t.name)||((n=this.attachment)==null?void 0:n.name)||this.guessNameFromPath()||this.t("attachment.fallbackName")},safeHref(){const e=String(this.url||"").trim();return/^(https?:\/\/|blob:|data:image\/)/i.test(e)?e:"#"},sizeLabel(){var t;const e=(t=this.attachment)==null?void 0:t.size_bytes;return e?e<1024?this.t("attachment.bytes",{size:e}):e<1024*1024?this.t("attachment.kilobytes",{size:(e/1024).toFixed(0)}):this.t("attachment.megabytes",{size:(e/(1024*1024)).toFixed(1)}):""}},watch:{"attachment.path":{handler(){this.refresh()},immediate:!0}},methods:{guessNameFromPath(){var n;return((((n=this.attachment)==null?void 0:n.path)||"").split("/").pop()||"").replace(/^[0-9a-f-]{8,}-/,"")},async refresh(){var e;if(!(!((e=this.attachment)!=null&&e.path)||!this.signAttachmentFn)){this.loading=!0;try{this.url=await this.signAttachmentFn(this.attachment.path)}finally{this.loading=!1}}},onFileClick(e){this.safeHref==="#"&&e.preventDefault()}}},xf=["href"],Tf=["src","alt"],Mf=["src"],Ef=["src"],Of=["href","download"],Rf={class:"wm-att__main"},If={class:"wm-att__name"},Lf={key:0,class:"wm-att__meta"},Pf={key:0,class:"wm-att__spin","aria-hidden":"true"};function Bf(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-att",["wm-att--"+(s.kind||"file")]])},[s.kind==="image"&&i.url?(h(),p("a",{key:0,href:s.safeHref,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[u("img",{src:i.url,alt:s.displayName,loading:"lazy"},null,8,Tf)],8,xf)):s.kind==="audio"&&i.url?(h(),p("audio",{key:1,src:i.url,controls:"",preload:"metadata"},null,8,Mf)):s.kind==="video"&&i.url?(h(),p("video",{key:2,src:i.url,controls:"",playsinline:"",preload:"auto"},null,8,Ef)):(h(),p("a",{key:3,class:"wm-att__file",href:s.safeHref,download:s.displayName,target:"_blank",rel:"noopener",onClick:t[0]||(t[0]=(...o)=>s.onFileClick&&s.onFileClick(...o))},[t[1]||(t[1]=u("span",{class:"wm-att__icon"},[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),u("path",{d:"M14 2v6h6"})])],-1)),u("span",Rf,[u("span",If,R(s.displayName),1),s.sizeLabel?(h(),p("span",Lf,R(s.sizeLabel),1)):F("",!0)]),i.loading?(h(),p("span",Pf)):F("",!0)],8,Of))],2)}const Ff=be(Af,[["render",Bf],["__scopeId","data-v-b207a8bd"]]),Df={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return Sc(this.text)}}},Nf=["innerHTML"];function Hf(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-bubble","wm-bubble--"+n.role])},[Fa(e.$slots,"default",{},()=>[u("span",{innerHTML:s.rendered},null,8,Nf)])],2)}const Uf=be(Df,[["render",Hf],["__scopeId","data-v-7c8e2766"]]),jf={name:"WmTyping"},Vf={class:"wm-typing"};function Kf(e,t,n,r,i,s){return h(),p("div",Vf,[...t[0]||(t[0]=[u("span",{style:{"animation-delay":"0s"}},null,-1),u("span",{style:{"animation-delay":"0.2s"}},null,-1),u("span",{style:{"animation-delay":"0.4s"}},null,-1)])])}const zf=be(jf,[["render",Kf],["__scopeId","data-v-df2447fd"]]);function Ot(e){return e?e.client_msg_id||e.id:""}const Wf={transferred_to_human:"system.transferredToHuman",assigned:"system.assigned",unassigned:"system.unassigned",resolved:"system.resolved",closed:"system.closed",reopened:"system.reopened",idle:"system.idle"},$f=80,qf=200,Gf={name:"WmMessageList",components:{AIAvatar:Sn,HumanAvatar:rs,Bubble:Uf,Typing:zf,ActionResult:Fd,AttachmentPreview:Ff,ArtifactRenderer:Sf},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{messages:{type:Array,default:()=>[]},streamingActive:{type:Boolean,default:!1},dateLabel:{type:String,default:""},conversationId:{type:[String,Number],default:null},loadingMore:{type:Boolean,default:!1},hasMore:{type:Boolean,default:!1},unreadAnchorId:{type:Number,default:null},unreadBoundaryTs:{type:String,default:""},aiAgentName:{type:String,default:""},aiAgentAvatarUrl:{type:String,default:null}},emits:["load-more"],data(){return{silentFades:!1,widthByKey:Object.freeze({}),showScrollDown:!1,pressedItemKey:null}},computed:{historyExhausted(){return!this.hasMore&&!this.loadingMore&&this.messages.length>=20},groups(){var n,r,i,s,o;const e=[];for(const a of this.messages){if((n=a==null?void 0:a.metadata)!=null&&n.resolution_request)continue;const l=this.roleOf(a);if(l==="system"){if(((r=a==null?void 0:a.payload)==null?void 0:r.event)==="action_admin_pending"){const m=e[e.length-1];m&&m.role==="ai"?m.messages.push(a):e.push({key:`g-${Ot(a)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[a],items:[]});continue}e.push({key:`sys-${Ot(a)}`,role:l,messages:[a],items:[],systemLabel:this.systemLabel(a)});continue}const d=e[e.length-1];d&&d.role===l&&(l==="ai"||d.agentName===(((i=a==null?void 0:a.author)==null?void 0:i.name)||""))?d.messages.push(a):e.push({key:`g-${Ot(a)}`,role:l,agentName:((s=a==null?void 0:a.author)==null?void 0:s.name)||"",agentAvatarUrl:((o=a==null?void 0:a.author)==null?void 0:o.avatar_url)||null,messages:[a],items:[]})}for(const a of e){if(a.role==="system")continue;const l=[];for(const d of a.messages)for(const c of this.itemsOf(d))l.push(c);a.items=l}const t=[];for(const a of e){if(a.role!=="system"&&!a.items.length)continue;const l=t[t.length-1];if(l&&l.role!=="system"&&l.role===a.role&&(a.role==="ai"||l.agentName===a.agentName)){l.messages.push(...a.messages),l.items.push(...a.items);continue}t.push(a)}for(const a of t)a.role!=="system"&&(a.key=this.stableGroupKey(a.messages));return t},unreadGroupKey(){if(this.unreadAnchorId==null)return null;const e=this.unreadAnchorId,t=this.unreadBoundaryTs;for(const n of this.groups){if(n.role==="user"||n.role==="system"||!n.items.length)continue;const r=n.messages[0];if(!r)continue;const i=ht(r.id);if(i!=null&&!(i<=e)&&!(t&&r.created_at&&r.created_at>t))return n.key}return null}},watch:{messages:{handler:"snapshotAndRestore",deep:!0},conversationId(e,t){e!==t&&(this._groupIdByMsgKey=null,this.silentFades=!1)},loadingMore(e){e||(this._pendingLoadMore=!1),e&&(this.silentFades=!0),this.snapshotAndRestore()},streamingActive:"snapshotAndRestore"},mounted(){this._lastSeenConvId=this.conversationId,this.scrollToBottom(),this._measureFrame=null,this._ro=new ResizeObserver(()=>this.scheduleMeasure()),this.$refs.scrollEl&&this._ro.observe(this.$refs.scrollEl),this.$nextTick(()=>this.measureRows())},beforeUnmount(){var e;(e=this._ro)==null||e.disconnect(),this._measureFrame&&cancelAnimationFrame(this._measureFrame),this._pinFrame&&cancelAnimationFrame(this._pinFrame),this._pressTimer&&clearTimeout(this._pressTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:Ot,stableGroupKey(e){this._groupIdByMsgKey||(this._groupIdByMsgKey=new Map,this._groupIdCounter=0);const t=this._groupIdByMsgKey;let n=null;for(const r of e){const i=Ot(r);if(i&&t.has(i)){n=t.get(i);break}}n==null&&(n=++this._groupIdCounter);for(const r of e){const i=Ot(r);i&&t.set(i,n)}return`g-${n}`},isAtBottom(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=$f},onScroll(){const e=this.$refs.scrollEl;e&&(this.showScrollDown=!this.isAtBottom(e),!(this.loadingMore||!this.hasMore)&&(this._pendingLoadMore||e.scrollTop<=qf&&(this._pendingLoadMore=!0,this.$emit("load-more"))))},snapshotAndRestore(){const e=this.$refs.scrollEl;if(!e||this._scrollSnap)return;const t=this._lastSeenConvId!==this.conversationId;this._lastSeenConvId=this.conversationId;const n=this.isAtBottom(e);let r=null;if(!t&&!n){const s=this.pickAnchor(e);if(s!=null&&s.rowKey){const o=this.findRowByKey(e,s.rowKey);if(o){const a=e.getBoundingClientRect().top;r={rowKey:s.rowKey,relY:o.getBoundingClientRect().top-a}}}}const i={forceBottom:t,wasPinned:n,anchor:r};this._scrollSnap=i,this.$nextTick(()=>{if(this._scrollSnap=null,i.forceBottom||i.wasPinned){e.scrollTop=e.scrollHeight;return}if(!i.anchor)return;const s=()=>{const o=i.anchor,a=this.findRowByKey(e,o.rowKey);if(!a)return;const d=a.getBoundingClientRect().top-e.getBoundingClientRect().top-o.relY;Math.abs(d)>.5&&(e.scrollTop+=d)};s(),requestAnimationFrame(()=>{s(),requestAnimationFrame(s)})})},pickAnchor(e){const t=e.getBoundingClientRect().top,n=e.querySelectorAll(".wm-list__row[data-row-key]");let r=null;for(const i of n)if(r||(r=i),i.getBoundingClientRect().bottom>=t)return{rowKey:i.dataset.rowKey};return r?{rowKey:r.dataset.rowKey}:null},findRowByKey(e,t){if(!t)return null;const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&");return e.querySelector(`.wm-list__row[data-row-key="${n}"]`)},roleOf(e){var n,r;if((e==null?void 0:e.type)==="system"||((n=e==null?void 0:e.payload)==null?void 0:n.type)==="system")return"system";const t=(r=e==null?void 0:e.author)==null?void 0:r.type;return t==="user"?"user":t==="agent_human"?"human":"ai"},roleLabel(e){if(e.role==="human")return e.agentName||this.t("common.agent");const t=this.t("common.aiAssistant");return this.aiAgentName?`${this.aiAgentName} • ${t}`:t},itemsOf(e){var t;if(!e)return[];if(e.type==="system"&&((t=e==null?void 0:e.payload)==null?void 0:t.event)==="action_admin_pending")return[{message:e,partKey:"main",renderAs:"admin-pending",kind:{top:"bubble",bottom:"bubble"}}];if(e.type==="action"&&e.payload&&e.payload.state!=="pending"){const n=[{message:e,partKey:"main",renderAs:"action",kind:{top:"bubble",bottom:"bubble"}}];return this.actionArtifact(e)&&n.push({message:e,partKey:"artifact",renderAs:"artifact-of-action",kind:{top:"card",bottom:"card"}}),n}return this.artifactOf(e)?[{message:e,partKey:"main",renderAs:"artifact",kind:{top:"card",bottom:"card"}}]:e.text_md||this.attachmentsOf(e).length?[{message:e,partKey:"main",renderAs:"bubble",kind:{top:"bubble",bottom:"bubble"}}]:[]},cornersFor(e,t){var V,re,ce;const n=e.items,r=(V=n[t])==null?void 0:V.kind,i=(re=n[t-1])==null?void 0:re.kind,s=(ce=n[t+1])==null?void 0:ce.kind,o=e.role==="user",a=14,l=4,d=i==null?void 0:i.bottom,c=s==null?void 0:s.top,m=this.widthByKey[this.rowKeyOf(e,t)],C=this.widthByKey[this.rowKeyOf(e,t-1)],b=this.widthByKey[this.rowKeyOf(e,t+1)],K=.5,S=(_e,we,G)=>_e!=null&&m!=null?_e+K>=m:we===G||we==="card"&&G==="bubble";let J=a,U=a,$=a,ne=a;return o?(d&&(U=l),(c||!s)&&($=l),d&&S(C,d,r==null?void 0:r.top)&&(J=l),c&&S(b,c,r==null?void 0:r.bottom)&&(ne=l)):(d&&(J=l),(c||!s)&&(ne=l),d&&S(C,d,r==null?void 0:r.top)&&(U=l),c&&S(b,c,r==null?void 0:r.bottom)&&($=l)),{tl:J,tr:U,br:$,bl:ne}},mosaicGridStyle(e){return!e||e<2?null:{"grid-template-columns":`repeat(${Math.min(e,4)}, 1fr)`}},mosaicCornerStyle(e,t,n){if(!t||t<2)return null;const r=Math.min(t,4),i=Math.floor(e/r),s=e%r,o=s>0,a=s<r-1&&e+1<t,l=i>0,d=e+r<t,c="4px",m={};return(o||l)&&(m["--wm-r-tl"]=c),(a||l)&&(m["--wm-r-tr"]=c),(o||d)&&(m["--wm-r-bl"]=c),(a||d)&&(m["--wm-r-br"]=c),n&&(m["--wm-r-tl"]=c,m["--wm-r-tr"]=c),Object.keys(m).length?m:null},cornersStyle(e,t){if(e.items.length<2)return null;const n=this.cornersFor(e,t);return{"--wm-r-tl":`${n.tl}px`,"--wm-r-tr":`${n.tr}px`,"--wm-r-br":`${n.br}px`,"--wm-r-bl":`${n.bl}px`}},rowKeyOf(e,t){var r;const n=(r=e==null?void 0:e.items)==null?void 0:r[t];return n?`${Ot(n.message)}-${n.partKey}`:""},scheduleMeasure(){this._measureFrame||(this._measureFrame=requestAnimationFrame(()=>{this._measureFrame=null,this.measureRows()}))},measureRows(){const e=this.$refs.scrollEl;if(!e)return;const t={};for(const s of e.querySelectorAll(".wm-list__row[data-row-key]")){const o=s.dataset.rowKey;if(!o)continue;const a=s.querySelector(".wm-bubble, .wm-result, .wm-art, .wm-list__body");if(!a)continue;const l=a.getBoundingClientRect().width;l>0&&(t[o]=l)}const n=this.widthByKey,r=Object.keys(n),i=Object.keys(t);if(r.length===i.length){let s=!0;for(const o of i)if(Math.abs((n[o]??0)-t[o])>.5){s=!1;break}if(s)return}this.widthByKey=Object.freeze(t)},onPressStart(e){this.onPressEnd(),this._pressTimer=setTimeout(()=>{this._pressTimer=null,this.pressedItemKey=e},400)},onPressEnd(){this._pressTimer&&(clearTimeout(this._pressTimer),this._pressTimer=null),this.pressedItemKey!==null&&(this.pressedItemKey=null)},timeOf(e){if(!(e!=null&&e.created_at))return"";try{return Bs(new Date(e.created_at),Bt(this.wmLocale()))}catch{return""}},lastTimeOf(e){const t=e.items[e.items.length-1],n=(t==null?void 0:t.message)||e.messages[e.messages.length-1];if(!(n!=null&&n.created_at))return"";try{return Bs(new Date(n.created_at),Bt(this.wmLocale()))}catch{return""}},hasTrailingOverlay(e){if(!e.messages.length)return!1;const t=e.messages[e.messages.length-1],n=e.items[e.items.length-1];return!!t&&(n==null?void 0:n.message)!==t},attachmentsOf(e){var n;const t=(n=e==null?void 0:e.payload)==null?void 0:n.attachments;return Array.isArray(t)?t:[]},artifactOf(e){var n;const t=(n=e==null?void 0:e.metadata)==null?void 0:n.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},actionLabel(e){var t;return((t=e==null?void 0:e.payload)==null?void 0:t.name)||(e==null?void 0:e.text_md)||this.t("common.action")},actionDetail(e){var n,r,i,s,o,a,l,d;const t=e==null?void 0:e.payload;if(!t)return"";if(t.state==="success")return((n=t.success)==null?void 0:n.summary)||((i=(r=t.success)==null?void 0:r.metadata)==null?void 0:i.description)||"";if(t.state==="rejected"){if((s=t.rejected)!=null&&s.reason)return t.rejected.reason;const c=(a=(o=t.rejected)==null?void 0:o.metadata)==null?void 0:a.resolution,m=typeof c=="string"&&c.startsWith("admin")?"action.rejectedByAdmin":"action.rejectedByUser";return this.t(m)}return t.state==="failure"&&(((l=t.failure)==null?void 0:l.summary)||((d=t.failure)==null?void 0:d.error))||""},actionArtifact(e){var n,r;const t=(r=(n=e==null?void 0:e.payload)==null?void 0:n.success)==null?void 0:r.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},systemLabel(e){var i,s,o;const t=(i=e==null?void 0:e.payload)==null?void 0:i.event,n=Wf[t],r=((s=e==null?void 0:e.metadata)==null?void 0:s.agent_name)||((o=e==null?void 0:e.author)==null?void 0:o.name)||this.t("messageList.anAgent");return n?this.t(n,{name:r}):(e==null?void 0:e.text_md)||this.t("messageList.conversationUpdate")},scrollToBottom(){const e=this.$refs.scrollEl;e&&(e.scrollTop=e.scrollHeight),this.showScrollDown=!1},keepPinnedToBottom(e=320){const t=this.$refs.scrollEl;if(!t)return;this._pinFrame&&cancelAnimationFrame(this._pinFrame);let n=null;const r=i=>{n===null&&(n=i),t.scrollTop=t.scrollHeight,i-n<e?this._pinFrame=requestAnimationFrame(r):this._pinFrame=null};this._pinFrame=requestAnimationFrame(r),this.showScrollDown=!1},scrollToBottomSmooth(){const e=this.$refs.scrollEl;e&&(typeof e.scrollTo=="function"?e.scrollTo({top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight,this.showScrollDown=!1)}}},Yf={class:"wm-list__wrap"},Jf={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},Xf={class:"wm-list__loadMore-lbl"},Qf={key:1,class:"wm-list__historyEnd"},Zf={key:2,class:"wm-list__sep"},eh={class:"wm-list__sep-label"},th={key:0,class:"wm-list__sep wm-list__sep--unread"},nh={class:"wm-list__sep-label wm-list__sep-label--unread"},sh={key:0,class:"wm-list__sysep"},rh={class:"wm-list__sysep-label"},ih=["data-row-key","onPointerdown"],oh={key:0,class:"wm-list__avatarSlot"},ah={key:0},lh={key:1,"aria-hidden":"true"},ch={key:2},uh={key:0},dh={key:1,"aria-hidden":"true"},fh={key:2},hh={key:3,class:"wm-list__row wm-list__row--ai fade-up"},mh={class:"wm-list__avatarSlot"},gh=["aria-label","title"];function ph(e,t,n,r,i,s){const o=ve("AIAvatar"),a=ve("HumanAvatar"),l=ve("ActionResult"),d=ve("ArtifactRenderer"),c=ve("Bubble"),m=ve("AttachmentPreview"),C=ve("Typing");return h(),p("div",Yf,[u("div",{ref:"scrollEl",class:te(["wm-list",{"wm-list--silent":i.silentFades}]),onScrollPassive:t[4]||(t[4]=(...b)=>s.onScroll&&s.onScroll(...b))},[n.loadingMore?(h(),p("div",Jf,[t[6]||(t[6]=u("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1)),u("span",Xf,R(s.t("messageList.loadingHistory")),1)])):s.historyExhausted?(h(),p("div",Qf,R(s.t("messageList.conversationStart")),1)):F("",!0),n.dateLabel?(h(),p("div",Zf,[t[7]||(t[7]=u("div",{class:"wm-list__line"},null,-1)),u("span",eh,R(n.dateLabel),1),t[8]||(t[8]=u("div",{class:"wm-list__line"},null,-1))])):F("",!0),(h(!0),p(Z,null,Se(s.groups,(b,K)=>(h(),p(Z,{key:b.key},[b.key===s.unreadGroupKey?(h(),p("div",th,[t[9]||(t[9]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1)),u("span",nh,R(s.t("messageList.unread")),1),t[10]||(t[10]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1))])):F("",!0),b.role==="system"||b.items.length?(h(),p("div",{key:1,class:te(["wm-list__group","wm-list__group--"+b.role])},[b.role==="system"?(h(),p("div",sh,[t[11]||(t[11]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),u("span",rh,R(b.systemLabel),1),t[12]||(t[12]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(h(),p(Z,{key:1},[(h(!0),p(Z,null,Se(b.items,(S,J)=>(h(),p(Z,{key:`${s.messageKey(S.message)}-${S.partKey}`},[u("div",{"data-row-key":`${s.messageKey(S.message)}-${S.partKey}`,class:te(["wm-list__row fade-up",["wm-list__row--"+b.role,{"is-pending":S.message._pending,"is-failed":S.message._failed}]]),style:Ce(s.cornersStyle(b,J)),onPointerdown:U=>s.onPressStart(`${s.messageKey(S.message)}-${S.partKey}`),onPointerup:t[0]||(t[0]=U=>s.onPressEnd()),onPointercancel:t[1]||(t[1]=U=>s.onPressEnd()),onPointerleave:t[2]||(t[2]=U=>s.onPressEnd()),onContextmenu:t[3]||(t[3]=We(()=>{},["prevent"]))},[b.role!=="user"?(h(),p("div",oh,[J===b.items.length-1?(h(),p(Z,{key:0},[b.role==="ai"?(h(),fe(o,{key:0,size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])):(h(),fe(a,{key:1,name:b.agentName,"avatar-url":b.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):F("",!0)])):F("",!0),S.renderAs==="action"?(h(),fe(l,{key:1,state:S.message.payload.state,label:s.actionLabel(S.message),detail:s.actionDetail(S.message)},null,8,["state","label","detail"])):S.renderAs==="admin-pending"?(h(),fe(l,{key:2,state:"awaiting",label:s.t("messageList.approvalRequestSent"),detail:S.message.text_md||""},null,8,["label","detail"])):S.renderAs==="artifact-of-action"?(h(),fe(d,{key:3,artifact:s.actionArtifact(S.message)},null,8,["artifact"])):S.renderAs==="artifact"?(h(),fe(d,{key:4,artifact:s.artifactOf(S.message)},null,8,["artifact"])):(h(),p("div",{key:5,class:te(["wm-list__body",{"wm-list__body--mixed":!!S.message.text_md&&s.attachmentsOf(S.message).length>0}])},[S.message.text_md?(h(),fe(c,{key:0,role:b.role,text:S.message.text_md},null,8,["role","text"])):F("",!0),s.attachmentsOf(S.message).length?(h(),p("div",{key:1,class:te(["wm-list__atts",{"wm-list__atts--align-end":b.role==="user","wm-list__atts--mosaic":s.attachmentsOf(S.message).length>=2}]),style:Ce(s.mosaicGridStyle(s.attachmentsOf(S.message).length))},[(h(!0),p(Z,null,Se(s.attachmentsOf(S.message),(U,$)=>(h(),fe(m,{key:`${s.messageKey(S.message)}-att-${$}`,attachment:U,style:Ce(s.mosaicCornerStyle($,s.attachmentsOf(S.message).length,!!S.message.text_md))},null,8,["attachment","style"]))),128))],6)):F("",!0)],2))],46,ih),J<b.items.length-1&&i.pressedItemKey===`${s.messageKey(S.message)}-${S.partKey}`&&(b.role!=="user"||s.timeOf(S.message))?(h(),p("div",{key:0,class:te(["wm-list__meta wm-list__meta--press",{"wm-list__meta--right":b.role==="user"}])},[b.role!=="user"?(h(),p("span",ah,R(s.roleLabel(b)),1)):F("",!0),b.role!=="user"&&s.timeOf(S.message)?(h(),p("span",lh,"•")):F("",!0),s.timeOf(S.message)?(h(),p("span",ch,R(s.timeOf(S.message)),1)):F("",!0)],2)):F("",!0)],64))),128)),(b.role!=="user"||s.lastTimeOf(b))&&!s.hasTrailingOverlay(b)?(h(),p("div",{key:0,class:te(["wm-list__meta",{"wm-list__meta--right":b.role==="user"}])},[b.role!=="user"?(h(),p("span",uh,R(s.roleLabel(b)),1)):F("",!0),b.role!=="user"&&s.lastTimeOf(b)?(h(),p("span",dh,"•")):F("",!0),s.lastTimeOf(b)?(h(),p("span",fh,R(s.lastTimeOf(b)),1)):F("",!0)],2)):F("",!0)],64))],2)):F("",!0)],64))),128)),n.streamingActive?(h(),p("div",hh,[u("div",mh,[pe(o,{size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])]),pe(C)])):F("",!0)],34),pe(Qs,{name:"wm-scrollDown"},{default:Xn(()=>[i.showScrollDown?(h(),p("button",{key:0,type:"button",class:"wm-list__scrollDown","aria-label":s.t("messageList.scrollToBottom"),title:s.t("messageList.scrollToBottom"),onClick:t[5]||(t[5]=(...b)=>s.scrollToBottomSmooth&&s.scrollToBottomSmooth(...b))},[...t[13]||(t[13]=[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M6 9l6 6 6-6"})],-1)])],8,gh)):F("",!0)]),_:1})])}const _h=be(Gf,[["render",ph],["__scopeId","data-v-1a6f0182"]]),jn=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",nr=typeof window<"u"&&typeof window.MediaRecorder<"u";function yh(){return nr&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(t=>{var n,r;return(r=(n=window.MediaRecorder).isTypeSupported)==null?void 0:r.call(n,t)})||""}function Eo({audio:e}){return{video:!0,audio:!!e,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:e?"include":"exclude"}}async function vh(){if(!jn)return null;let e;try{e=await navigator.mediaDevices.getDisplayMedia(Eo({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await bh(e)}catch(t){return console.error("[media] screenshot capture",t),null}finally{e.getTracks().forEach(t=>{t.stop()})}}async function bh(e){const t=document.createElement("video");t.muted=!0,t.playsInline=!0,t.srcObject=e,await t.play(),await new Promise(a=>requestAnimationFrame(a));const n=t.videoWidth||1280,r=t.videoHeight||720,i=document.createElement("canvas");i.width=n,i.height=r,i.getContext("2d").drawImage(t,0,0,n,r);const s=await new Promise((a,l)=>{i.toBlob(d=>d?a(d):l(new Error("toBlob failed")),"image/png")}),o=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([s],`capture-${o}.png`,{type:"image/png"})}async function wh(e={}){var d;if(!jn||!nr)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Eo({audio:!0}))}catch(c){return(c==null?void 0:c.name)!=="NotAllowedError"&&console.error("[media] record picker",c),null}const n=yh();let r;try{r=n?new window.MediaRecorder(t,{mimeType:n}):new window.MediaRecorder(t)}catch(c){return console.error("[media] recorder init",c),t.getTracks().forEach(m=>{m.stop()}),null}const i=[];let s=null,o=!1;r.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&i.push(c.data)}),r.addEventListener("stop",()=>{var c,m;if(s&&clearInterval(s),t.getTracks().forEach(C=>{C.stop()}),i.length){const C=r.mimeType||n||"video/webm",b=new Blob(i,{type:C}),K=/mp4/.test(C)?"mp4":"webm",S=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),J=new File([b],`ecran-${S}.${K}`,{type:C});(c=e.onfinalize)==null||c.call(e,J)}else(m=e.oncancel)==null||m.call(e)}),t.getVideoTracks().forEach(c=>{c.addEventListener("ended",()=>a(),{once:!0})});function a(){if(!o&&(o=!0,r.state!=="inactive"))try{r.stop()}catch(c){console.error("[media] recorder stop",c)}}try{r.start(1e3)}catch(c){return console.error("[media] recorder start",c),t.getTracks().forEach(m=>{m.stop()}),null}(d=e.onstart)==null||d.call(e);const l=Date.now();return s=setInterval(()=>{var c;(c=e.ontick)==null||c.call(e,Date.now()-l)},500),{stop:a,get state(){return r.state}}}const kh=[{action:"file",labelKey:"composer.attachFile",path:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"},{action:"screenshot",labelKey:"composer.screenshot",path:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z M12 17a4 4 0 100-8 4 4 0 000 8z"},{action:"record",labelKey:"composer.recordScreen",path:"M23 7l-7 5 7 5V7z M1 5a2 2 0 012-2h12a2 2 0 012 2v14a2 2 0 01-2 2H3a2 2 0 01-2-2V5z"}],Ch={name:"WmComposer",inject:{t:{default:()=>Ee()}},props:{modelValue:{type:String,default:""},placeholder:{type:String,default:"Écrivez votre message…"},disabled:{type:Boolean,default:!1},attachLabel:{type:String,default:"Joindre"},displayMode:{type:String,default:"floating"}},emits:["update:modelValue","send","attach","focus","blur"],data(){return{local:this.modelValue,focused:!1,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null,kbOffset:0}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},expanded(){return this.focused||!!this.local.trim()||this.attachOpen||this.recording},attachItems(){return kh.map(e=>({...e,label:this.t(e.labelKey),disabled:e.action==="screenshot"&&!jn||e.action==="record"&&(!jn||!nr)}))},recordingElapsedLabel(){const e=Math.floor(this.recordingElapsed/1e3),t=Math.floor(e/60),n=e%60;return`${t}:${n.toString().padStart(2,"0")}`}},watch:{modelValue(e){e!==this.local&&(this.local=e,this.$nextTick(()=>this.autosize()))},local(e){this.$emit("update:modelValue",e)}},mounted(){this.autosize(),this.displayMode==="sheet"&&this.setupKeyboardTracking()},beforeUnmount(){if(this.recorder)try{this.recorder.stop()}catch{}this.teardownKeyboardTracking()},methods:{focus(){const e=this.$refs.inputEl;if(!(!e||this.disabled))try{e.focus({preventScroll:!0})}catch{e.focus()}},onFocus(){this.focused=!0,this.$emit("focus"),this.$nextTick(()=>this.autosize())},onBlur(){this.focused=!1,this.$emit("blur"),this.$nextTick(()=>this.autosize())},onSubmit(){if(!this.canSend)return;const e=this.local.trim();this.local="",this.$emit("send",e),this.$nextTick(()=>this.autosize())},onKeydown(e){e.key==="Enter"&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&!e.isComposing&&(e.preventDefault(),this.onSubmit())},autosize(){const e=this.$refs.inputEl;if(!e||e.clientWidth<80)return;e.style.height="auto",e.style.minHeight="0px";const t=e.scrollHeight;e.style.minHeight="",e.style.height=t>62?`${Math.min(t,120)}px`:""},onFile(e){const t=Array.from(e.target.files||[]);for(const n of t)this.$emit("attach",n);e.target.value=""},onAttachAction(e){this.attachOpen=!1,e==="file"?this.pickFile():e==="screenshot"?this.captureScreenshot():e==="record"&&this.startRecording()},pickFile(){var e;(e=this.$refs.fileEl)==null||e.click()},async captureScreenshot(){if(this.disabled)return;const e=await vh();e&&this.$emit("attach",e)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const e=await wh({onstart:()=>{this.recording=!0},ontick:t=>{this.recordingElapsed=t},onfinalize:t=>{this.$emit("attach",t),this.recording=!1,this.recordingElapsed=0,this.recorder=null},oncancel:()=>{this.recording=!1,this.recordingElapsed=0,this.recorder=null}});e&&(this.recorder=e)},stopRecording(){if(this.recorder)try{this.recorder.stop()}catch(e){console.error("[composer] stop recording",e)}},setupKeyboardTracking(){const e=window.visualViewport;e&&(this._vvHandler=()=>{const t=Math.max(0,window.innerHeight-e.height-e.offsetTop);this.kbOffset=t},e.addEventListener("resize",this._vvHandler),e.addEventListener("scroll",this._vvHandler))},teardownKeyboardTracking(){const e=window.visualViewport;!e||!this._vvHandler||(e.removeEventListener("resize",this._vvHandler),e.removeEventListener("scroll",this._vvHandler),this._vvHandler=null)}}},Sh={key:0,class:"wm-rec"},Ah={class:"wm-rec__lbl"},xh={key:1,class:"wm-compose__menu",role:"menu"},Th=["disabled","onClick"],Mh={class:"wm-compose__menuIcon"},Eh={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},Oh=["d"],Rh=["placeholder","disabled"],Ih={class:"wm-compose__actions"},Lh=["title","aria-label","disabled"],Ph=["disabled","aria-label"];function Bh(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-compose-wrap",{"wm-compose-wrap--sheet":n.displayMode==="sheet"}]),style:Ce(i.kbOffset?{transform:`translateY(-${i.kbOffset}px)`}:null)},[i.recording?(h(),p("div",Sh,[t[11]||(t[11]=u("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),u("span",Ah,R(s.t("composer.recording",{time:s.recordingElapsedLabel})),1),u("button",{type:"button",class:"wm-rec__stop",onClick:t[0]||(t[0]=(...o)=>s.stopRecording&&s.stopRecording(...o))},R(s.t("composer.stop")),1)])):F("",!0),u("form",{class:te(["wm-compose",{"has-attach":i.attachOpen,"is-expanded":s.expanded}]),onSubmit:t[10]||(t[10]=We((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]))},[u("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:t[1]||(t[1]=(...o)=>s.onFile&&s.onFile(...o))},null,544),i.attachOpen?(h(),p("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=o=>i.attachOpen=!1)})):F("",!0),i.attachOpen?(h(),p("div",xh,[(h(!0),p(Z,null,Se(s.attachItems,o=>(h(),p("button",{key:o.action,type:"button",class:"wm-compose__menuItem",disabled:o.disabled,onClick:a=>s.onAttachAction(o.action)},[u("span",Mh,[(h(),p("svg",Eh,[u("path",{d:o.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,Oh)]))]),u("span",null,R(o.label),1)],8,Th))),128))])):F("",!0),st(u("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=o=>i.local=o),class:"wm-compose__input",rows:"1",placeholder:n.placeholder,disabled:n.disabled,onKeydown:t[4]||(t[4]=(...o)=>s.onKeydown&&s.onKeydown(...o)),onInput:t[5]||(t[5]=(...o)=>s.autosize&&s.autosize(...o)),onFocus:t[6]||(t[6]=(...o)=>s.onFocus&&s.onFocus(...o)),onBlur:t[7]||(t[7]=(...o)=>s.onBlur&&s.onBlur(...o))},null,40,Rh),[[kt,i.local]]),u("div",Ih,[u("button",{type:"button",class:te(["wm-compose__icon",{"is-open":i.attachOpen}]),title:n.attachLabel,"aria-label":n.attachLabel,disabled:i.recording,onMousedown:t[8]||(t[8]=We(()=>{},["prevent"])),onClick:t[9]||(t[9]=o=>i.attachOpen=!i.attachOpen)},[...t[12]||(t[12]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)])],42,Lh),u("button",{type:"submit",class:te(["wm-compose__send",{"is-empty":!s.canSend}]),disabled:!s.canSend,"aria-label":s.t("composer.send")},[...t[13]||(t[13]=[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,Ph)])],34)],6)}const Fh=be(Ch,[["render",Bh],["__scopeId","data-v-a9738520"]]),Dh={name:"WmInlineCallbacks",props:{items:{type:Array,default:()=>[]},variant:{type:String,default:"chips",validator:e=>e==="chips"||e==="buttons"},baseDelay:{type:Number,default:360},stepDelay:{type:Number,default:90}},emits:["select"],computed:{batchKey(){return this.items.map(e=>(e==null?void 0:e.label)||(e==null?void 0:e.text)||"").join("§")},headerTitle(){if(this.variant!=="buttons")return"";const e=this.items.find(t=>typeof(t==null?void 0:t.title)=="string"&&t.title.trim());return e?e.title.trim():""}},methods:{btnClass(e){return this.variant==="chips"?"wm-icb__btn--chip":["wm-icb__btn--action",`wm-icb__btn--${(e==null?void 0:e.style)||"neutral"}`]}}},Nh=["onClick"],Hh={key:0,class:"wm-icb__title"},Uh={class:"wm-icb__row"},jh=["onClick"];function Vh(e,t,n,r,i,s){return n.items.length?(h(),p("div",{key:s.batchKey,class:te(["wm-icb",`wm-icb--${n.variant}`])},[n.variant==="chips"?(h(!0),p(Z,{key:0},Se(n.items,(o,a)=>(h(),p("button",{key:o.id!=null?o.id:a,type:"button",class:"wm-icb__btn wm-icb__btn--chip",style:Ce({animationDelay:n.baseDelay+a*n.stepDelay+"ms"}),onClick:l=>e.$emit("select",o)},R(o.label),13,Nh))),128)):(h(),p(Z,{key:1},[s.headerTitle?(h(),p("div",Hh,R(s.headerTitle),1)):F("",!0),u("div",Uh,[(h(!0),p(Z,null,Se(n.items,(o,a)=>(h(),p("button",{key:o.id!=null?o.id:a,type:"button",class:te(["wm-icb__btn",s.btnClass(o)]),onClick:l=>e.$emit("select",o)},R(o.label),11,jh))),128))])],64))],2)):F("",!0)}const Kh=be(Dh,[["render",Vh],["__scopeId","data-v-c8cc8cbf"]]);let ei=0;const zh=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Wh={name:"WmFormCard",components:{AIAvatar:Sn},inject:{t:{default:()=>Ee()}},props:{form:{type:Object,required:!0},readOnly:{type:Boolean,default:!1},initialValues:{type:Object,default:null},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["submit"],data(){return ei+=1,{_uid:ei,values:{},busy:!1,error:""}},computed:{normalizedFields(){var t;return(Array.isArray((t=this.form)==null?void 0:t.fields)?this.form.fields:[]).filter(n=>!(!(n!=null&&n.key)||!(n!=null&&n.label)||!zh.has(n==null?void 0:n.type)||(n.type==="select"||n.type==="multiselect")&&(!Array.isArray(n.options)||n.options.length===0)))}},created(){this.resetValues()},methods:{resetValues(){const e=this.initialValues&&typeof this.initialValues=="object"?this.initialValues:{},t={};for(const n of this.normalizedFields){if(e[n.key]!==void 0){t[n.key]=e[n.key];continue}n.type==="boolean"?t[n.key]=!1:n.type==="multiselect"?t[n.key]=[]:t[n.key]=""}this.values=t,this.error=""},toggleMulti(e,t,n){const r=Array.isArray(this.values[e])?this.values[e].slice():[],i=r.indexOf(t);n&&i===-1?r.push(t):!n&&i!==-1&&r.splice(i,1),this.values={...this.values,[e]:r}},validate(){for(const e of this.normalizedFields){if(!e.required)continue;const t=this.values[e.key];if(e.type!=="boolean"){if(e.type==="multiselect"){if(!Array.isArray(t)||t.length===0)return this.t("form.fieldRequired",{label:e.label});continue}if(t==null||t==="")return this.t("form.fieldRequired",{label:e.label})}}return""},async onSubmit(){if(this.readOnly||this.busy)return;const e=this.validate();if(e){this.error=e;return}this.error="",this.busy=!0;try{await this.$emit("submit",{values:this.values})}finally{this.busy=!1}}}},$h={class:"wm-form"},qh={class:"wm-form__head"},Gh={class:"wm-form__icon"},Yh={class:"wm-form__main"},Jh={class:"wm-form__title"},Xh={key:0,class:"wm-form__detail"},Qh=["for"],Zh={key:0,class:"wm-form__req","aria-hidden":"true"},em=["id","onUpdate:modelValue","placeholder","required","disabled"],tm=["id","onUpdate:modelValue","placeholder","required","disabled"],nm=["id","onUpdate:modelValue","placeholder","required","disabled"],sm=["id","onUpdate:modelValue","required","disabled"],rm={key:4,class:"wm-form__bool"},im=["id","onUpdate:modelValue","disabled"],om=["id","onUpdate:modelValue","required","disabled"],am={value:"",disabled:""},lm=["value"],cm={key:6,class:"wm-form__multi"},um=["value","checked","disabled","onChange"],dm={key:0,class:"wm-form__err"},fm=["disabled"],hm={key:0,class:"wm-form__spinner","aria-hidden":"true"},mm={key:2,class:"wm-form__doneLbl"};function gm(e,t,n,r,i,s){const o=ve("AIAvatar");return h(),p("div",$h,[u("div",qh,[u("div",Gh,[pe(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",Yh,[u("div",Jh,R(n.form.title||s.t("form.title")),1),n.form.description?(h(),p("div",Xh,R(n.form.description),1)):F("",!0)])]),u("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=We((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]))},[(h(!0),p(Z,null,Se(s.normalizedFields,a=>(h(),p("div",{key:a.key,class:"wm-form__field"},[u("label",{for:`wm-f-${i._uid}-${a.key}`,class:"wm-form__label"},[ns(R(a.label),1),a.required?(h(),p("span",Zh,"*")):F("",!0)],8,Qh),a.type==="text"?st((h(),p("input",{key:0,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"text",class:"wm-form__input",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,em)),[[kt,i.values[a.key]]]):a.type==="textarea"?st((h(),p("textarea",{key:1,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,class:"wm-form__textarea",rows:"3",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,tm)),[[kt,i.values[a.key]]]):a.type==="number"?st((h(),p("input",{key:2,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"number",class:"wm-form__input",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,nm)),[[kt,i.values[a.key],void 0,{number:!0}]]):a.type==="date"?st((h(),p("input",{key:3,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"date",class:"wm-form__input",required:a.required,disabled:n.readOnly||i.busy},null,8,sm)),[[kt,i.values[a.key]]]):a.type==="boolean"?(h(),p("label",rm,[st(u("input",{id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"checkbox",disabled:n.readOnly||i.busy},null,8,im),[[Jl,i.values[a.key]]]),u("span",null,R(a.placeholder||s.t("common.yes")),1)])):a.type==="select"?st((h(),p("select",{key:5,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,class:"wm-form__select",required:a.required,disabled:n.readOnly||i.busy},[u("option",am,R(a.placeholder||s.t("form.choose")),1),(h(!0),p(Z,null,Se(a.options,l=>(h(),p("option",{key:l.value,value:l.value},R(l.label),9,lm))),128))],8,om)),[[Xl,i.values[a.key]]]):a.type==="multiselect"?(h(),p("div",cm,[(h(!0),p(Z,null,Se(a.options,l=>(h(),p("label",{key:l.value,class:"wm-form__multiItem"},[u("input",{type:"checkbox",value:l.value,checked:Array.isArray(i.values[a.key])&&i.values[a.key].includes(l.value),disabled:n.readOnly||i.busy,onChange:d=>s.toggleMulti(a.key,l.value,d.target.checked)},null,40,um),u("span",null,R(l.label),1)]))),128))])):F("",!0)]))),128)),i.error?(h(),p("div",dm,R(i.error),1)):F("",!0),n.readOnly?(h(),p("div",mm,R(s.t("form.responseSent")),1)):(h(),p("button",{key:1,type:"submit",class:"wm-form__submit",disabled:i.busy},[i.busy?(h(),p("span",hm)):F("",!0),u("span",null,R(i.busy?s.t("common.sending"):n.form.submit_label||s.t("common.send")),1)],8,fm))],32)])}const pm=be(Wh,[["render",gm],["__scopeId","data-v-fe65cc56"]]),_m={name:"WmFeedback",inject:{t:{default:()=>Ee()}},props:{busy:{type:Boolean,default:!1},done:{type:Boolean,default:!1}},emits:["submit"],data(){return{sel:null}},computed:{options(){return[{v:1,e:"😞",l:this.t("feedback.rating1")},{v:2,e:"😐",l:this.t("feedback.rating2")},{v:3,e:"🙂",l:this.t("feedback.rating3")},{v:4,e:"😄",l:this.t("feedback.rating4")},{v:5,e:"🤩",l:this.t("feedback.rating5")}]}},methods:{onSend(){!this.sel||this.busy||this.$emit("submit",{rating:this.sel})}}},ym={class:"wm-fb"},vm={class:"wm-fb__title"},bm={class:"wm-fb__sub"},wm={class:"wm-fb__row"},km=["onClick"],Cm={class:"wm-fb__emoji"},Sm={class:"wm-fb__label"},Am=["disabled"],xm={key:1,class:"wm-fb__done"},Tm={class:"wm-fb__doneTitle"},Mm={class:"wm-fb__doneSub"};function Em(e,t,n,r,i,s){return h(),p("div",ym,[n.done?(h(),p("div",xm,[t[1]||(t[1]=u("div",{class:"wm-fb__check"},[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#fff","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M20 6L9 17l-5-5"})])],-1)),u("div",Tm,R(s.t("feedback.doneTitle")),1),u("div",Mm,R(s.t("feedback.doneSubtitle")),1)])):(h(),p(Z,{key:0},[u("div",vm,R(s.t("feedback.question")),1),u("div",bm,R(s.t("feedback.subtitle")),1),u("div",wm,[(h(!0),p(Z,null,Se(s.options,o=>(h(),p("button",{key:o.v,type:"button",class:te(["wm-fb__opt",{"is-selected":i.sel===o.v}]),onClick:a=>i.sel=o.v},[u("span",Cm,R(o.e),1),u("span",Sm,R(o.l),1)],10,km))),128))]),u("button",{type:"button",class:"wm-fb__send",disabled:!i.sel||n.busy,onClick:t[0]||(t[0]=(...o)=>s.onSend&&s.onSend(...o))},R(n.busy?s.t("common.sending"):s.t("feedback.submit")),9,Am)],64))])}const Om=be(_m,[["render",Em],["__scopeId","data-v-9b630564"]]),Rm={name:"WmMoreMenu",inject:{t:{default:()=>Ee()}},props:{canRename:{type:Boolean,default:!0},canExport:{type:Boolean,default:!0},soundEnabled:{type:Boolean,default:!0},statusUrl:{type:String,default:""},helpUrl:{type:String,default:""}},emits:["close","action","sound-toggle"],data(){return{soundOn:this.soundEnabled}},watch:{soundEnabled(e){this.soundOn=!!e}},methods:{emit(e){this.$emit("action",e)},toggleSound(){this.soundOn=!this.soundOn,this.$emit("sound-toggle",this.soundOn)}}},Im={class:"wm-mm"},Lm={class:"wm-mm__pop",role:"menu"},Pm={key:0,class:"wm-mm__section"},Bm={class:"wm-mm__label"},Fm={class:"wm-mm__label"},Dm={key:1,class:"wm-mm__sep"},Nm={class:"wm-mm__section"},Hm={class:"wm-mm__label"},Um={class:"wm-mm__section"},jm={class:"wm-mm__label"},Vm={class:"wm-mm__label"};function Km(e,t,n,r,i,s){return h(),p("div",Im,[u("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Lm,[n.canRename||n.canExport?(h(),p("div",Pm,[n.canRename?(h(),p("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[1]||(t[1]=o=>s.emit("rename"))},[t[6]||(t[6]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M12 20h9"}),u("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})])],-1)),u("span",Bm,R(s.t("moreMenu.editTitle")),1)])):F("",!0),n.canExport?(h(),p("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[2]||(t[2]=o=>s.emit("export"))},[t[7]||(t[7]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8M16 6l-4-4-4 4M12 2v13"})])],-1)),u("span",Fm,R(s.t("moreMenu.exportTranscript")),1),t[8]||(t[8]=u("span",{class:"wm-mm__hint"},".txt",-1))])):F("",!0)])):F("",!0),n.canRename||n.canExport?(h(),p("div",Dm)):F("",!0),u("div",Nm,[u("button",{type:"button",class:"wm-mm__item",onClick:t[3]||(t[3]=(...o)=>s.toggleSound&&s.toggleSound(...o))},[t[10]||(t[10]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M11 5L6 9H2v6h4l5 4V5z"}),u("path",{d:"M15.54 8.46a5 5 0 010 7.07M19.07 4.93a10 10 0 010 14.14"})])],-1)),u("span",Hm,R(s.t("moreMenu.sound")),1),u("span",{class:te(["wm-mm__toggle",{"wm-mm__toggle--on":i.soundOn}])},[...t[9]||(t[9]=[u("span",{class:"wm-mm__knob"},null,-1)])],2)])]),t[13]||(t[13]=u("div",{class:"wm-mm__sep"},null,-1)),u("div",Um,[n.statusUrl?(h(),p("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[4]||(t[4]=o=>s.emit("status"))},[t[11]||(t[11]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM10 6v4l3 2"})])],-1)),u("span",jm,R(s.t("moreMenu.serviceStatus")),1)])):F("",!0),n.helpUrl?(h(),p("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[5]||(t[5]=o=>s.emit("help"))},[t[12]||(t[12]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M9 11a3 3 0 116 0c0 2-3 2-3 5M12 19h.01M12 22a10 10 0 110-20 10 10 0 010 20z"})])],-1)),u("span",Vm,R(s.t("moreMenu.helpCenter")),1)])):F("",!0)])])])}const zm=be(Rm,[["render",Km],["__scopeId","data-v-4cf6d578"]]),Wm={name:"WmRenameDialog",inject:{t:{default:()=>Ee()}},props:{title:{type:String,default:""},initialValue:{type:String,default:""},placeholder:{type:String,default:""}},emits:["close","submit"],data(){return{value:this.initialValue||""}},computed:{canSubmit(){const e=(this.value||"").trim();return!!e&&e!==(this.initialValue||"").trim()}},mounted(){this.$nextTick(()=>{const e=this.$refs.input;if(e){e.focus();try{e.select()}catch{}}})},methods:{onSubmit(){this.canSubmit&&this.$emit("submit",this.value.trim())}}},$m={class:"wm-dialog"},qm={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},Gm={class:"wm-dialog__head"},Ym={class:"wm-dialog__title"},Jm=["aria-label"],Xm={class:"wm-dialog__body"},Qm=["placeholder"],Zm={class:"wm-dialog__actions"},eg=["disabled"];function tg(e,t,n,r,i,s){return h(),p("div",$m,[u("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",qm,[u("div",Gm,[u("div",Ym,R(n.title||s.t("rename.title")),1),u("button",{type:"button",class:"wm-dialog__close","aria-label":s.t("common.close"),onClick:t[1]||(t[1]=o=>e.$emit("close"))},[...t[7]||(t[7]=[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,Jm)]),u("div",Xm,[st(u("input",{ref:"input","onUpdate:modelValue":t[2]||(t[2]=o=>i.value=o),type:"text",class:"wm-dialog__input",placeholder:n.placeholder||s.t("rename.placeholder"),maxlength:120,onKeydown:[t[3]||(t[3]=Un(We((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]),["enter"])),t[4]||(t[4]=Un(We(o=>e.$emit("close"),["prevent"]),["esc"]))]},null,40,Qm),[[kt,i.value]])]),u("div",Zm,[u("button",{type:"button",class:"wm-dialog__btn",onClick:t[5]||(t[5]=o=>e.$emit("close"))},R(s.t("common.cancel")),1),u("button",{type:"button",class:"wm-dialog__btn wm-dialog__btn--primary",disabled:!s.canSubmit,onClick:t[6]||(t[6]=(...o)=>s.onSubmit&&s.onSubmit(...o))},R(s.t("common.save")),9,eg)])])])}const ng=be(Wm,[["render",tg],["__scopeId","data-v-6d5f94a8"]]),ti="ww-messenger-tokens",sg={name:"Messenger",components:{Launcher:Qc,Header:Cu,Onboarding:ld,History:Sd,MessageList:_h,Composer:Fh,InlineCallbacks:Kh,FormCard:pm,Feedback:Om,MoreMenu:zm,RenameDialog:ng},mixins:[Ec,Oc,Ic],provide(){return{signAttachmentFn:e=>{var t,n;return((n=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:n.call(t,e))||null},t:(e,t)=>this.t(e,t),wmLocale:()=>this.locale}},props:{baseUrl:{type:String,default:pc},widgetId:{type:String,default:""},context:{type:Object,default:null},displayMode:{type:String,default:"floating"},devtools:{type:Boolean,default:!1},language:{type:String,default:""}},data(){return{transport:null,store:null,isOpen:!1,launcherHovered:!1,draft:"",busy:!1,bootError:null,pendingAttachments:[],feedbackBusy:!1,feedbackDone:{},convOpenedAt:0,moreOpen:!1,renameDialogOpen:!1,draftConv:null,launching:!1,launchStage:"idle",pendingLaunchText:"",reopenedLocally:{},activeConvId:null,showOnboarding:!1,showHistory:!1,backToHistory:!1,welcomeRevealedAt:{},welcomeRevealTimers:{},dismissedPeeks:{},floatHeight:0,floatRO:null,parentOrigin:"",parentToken:"",parentVariables:null,parentAllowUnauthenticated:!1,parentInitReceived:!1,parentInitDeferred:null}},computed:{isEditor(){return!!this.devtools},isEmbedded(){return this.displayMode==="embedded"},customerLanguage(){var n,r,i,s;const e=(n=this.s)==null?void 0:n.customer,t=e&&(e.language||((r=e.values)==null?void 0:r.language));return t||((s=(i=this.context)==null?void 0:i.customer)==null?void 0:s.language)||""},locale(){var e;return tr(this.language||this.customerLanguage||((e=this.widget)==null?void 0:e.default_language)||"")},translator(){return Ee(this.locale)},error(){var e;return this.bootError||((e=this.s)==null?void 0:e.error)||null},canBoot(){return!!(this.baseUrl&&this.widgetId)},s(){var e;return((e=this.store)==null?void 0:e.state)||null},ready(){var e;return!!((e=this.s)!=null&&e.ready)},allConversations(){var t;const e=(t=this.s)==null?void 0:t.conversations;return Array.isArray(e)?e:[]},drawerConversations(){var n;const e=((n=this.s)==null?void 0:n.messagesByConv)||{},t=this.revealedAt;return this.allConversations.map(r=>{var d;const i=e[r.id]||[],s=ht(r.last_read_message_id);let o=0,a=null;for(let c=i.length-1;c>=0;c--){const m=i[c];if(!m)continue;if(((d=m.author)==null?void 0:d.type)==="user")break;const C=ht(m.id);if(C!=null){if(s!=null&&C<=s)break;t[m.id]!==0&&(!a&&m.author&&(a=m.author),o++)}}if(!i.length){const c=ht(r.last_message_id);c!=null&&(s==null||c>s)&&(o=1,a=r.last_message_author||null)}const l=i.filter(c=>!((c==null?void 0:c.id)!=null&&t[c.id]===0));return{...r,_preview:Ac(r,l),_unread:o>0,_unreadCount:o,_lastAuthor:a}})},unreadCount(){return this.drawerConversations.filter(e=>e._unread).length},openThreads(){var t;const e=((t=this.s)==null?void 0:t.messagesByConv)||{};return this.drawerConversations.filter(n=>{const r=this.convStatus(n);return r!=="resolved"&&r!=="closed"}).map(n=>({id:n.id,title:n.name||this.t("common.newConversation"),preview:n._preview||this.t("onboarding.newMessage"),unread:!!n._unread,author:n._lastAuthor||null,_ts:Qr(n,e[n.id]||[])})).sort((n,r)=>n._ts<r._ts?1:n._ts>r._ts?-1:0)},latestUnreads(){var n;const e=((n=this.s)==null?void 0:n.messagesByConv)||{},t=[];for(const r of this.drawerConversations){if(!r._unread)continue;const i=Qr(r,e[r.id]||[]),s=r._lastAuthor,o=!s||s.type==="agent_ia",a=(s==null?void 0:s.name)||(o?this.agentName:"")||"",l=(s==null?void 0:s.avatar_url)||(o?this.agentAvatarUrl:null);t.push({convId:r.id,preview:r._preview||this.t("notification.youHaveNewMessage"),ts:i,count:r._unreadCount||1,senderName:a,senderAvatarUrl:l})}return t.sort((r,i)=>r.ts<i.ts?1:r.ts>i.ts?-1:0),t},launcherPeeks(){if(this.isOpen||this.isEmbedded)return[];const e=this.dismissedPeeks||{};return this.latestUnreads.filter(t=>e[t.convId]!==t.ts)},isViewingThread(){return(this.isOpen||this.isEmbedded)&&!!this.currentConv},currentConv(){if(this.draftConv)return this.draftConv;if(this.showOnboarding||this.showHistory)return null;const e=this.allConversations;if(!e.length)return null;if(this.activeConvId!=null){const t=e.find(n=>n.id===this.activeConvId);if(t)return t}return e[0]||null},canBack(){return!!this.currentConv||this.showHistory},statusUrl(){var n;const e=(n=this.widget)==null?void 0:n.quick_links;if(!Array.isArray(e))return"";const t=e.find(r=>r.icon==="status"&&r.url);return(t==null?void 0:t.url)||""},helpUrl(){var n;const e=(n=this.widget)==null?void 0:n.quick_links;if(!Array.isArray(e))return"";const t=e.find(r=>(r.icon==="chat"||r.icon==="help")&&r.url);return(t==null?void 0:t.url)||""},widget(){var e,t;return((t=(e=this.s)==null?void 0:e.config)==null?void 0:t.widget)||null},rootStyle(){var t;const e=(t=this.widget)==null?void 0:t.primary_color;return e&&bc(e)?{"--wm-primary":e}:null},widgetTitle(){var e;return((e=this.widget)==null?void 0:e.title)||""},widgetWelcomeMessage(){var e;return((e=this.widget)==null?void 0:e.welcome_message)||""},widgetSubtitle(){var e;return((e=this.widget)==null?void 0:e.subtitle)||""},defaultIconUrl(){var e;return((e=this.widget)==null?void 0:e.default_icon_url)||null},coverImageUrl(){var e;return((e=this.widget)==null?void 0:e.cover_image_url)||null},agentName(){var e,t,n;return((n=(t=(e=this.s)==null?void 0:e.config)==null?void 0:t.agent)==null?void 0:n.name)||""},agentAvatarUrl(){var e,t,n;return((n=(t=(e=this.s)==null?void 0:e.config)==null?void 0:t.agent)==null?void 0:n.avatar_url)||null},quickLinks(){var t;const e=(t=this.widget)==null?void 0:t.quick_links;return Array.isArray(e)?e:[]},teamMembers(){var t;const e=(t=this.widget)==null?void 0:t.team_members;return Array.isArray(e)?e:[]},responseLabel(){var e;return((e=this.widget)==null?void 0:e.response_time_label)||""},humanMessageAuthor(){var t,n,r;if(!this.currentConv)return null;const e=((t=this.s.messagesByConv)==null?void 0:t[this.currentConv.id])||[];for(let i=e.length-1;i>=0;i--)if(((r=(n=e[i])==null?void 0:n.author)==null?void 0:r.type)==="agent_human")return e[i].author;return null},humanAgentName(){var e;return((e=this.humanMessageAuthor)==null?void 0:e.name)||""},humanAgentAvatarUrl(){var e;return((e=this.humanMessageAuthor)==null?void 0:e.avatar_url)||null},isEscalated(){return!!this.humanMessageAuthor},isWaitingHuman(){return this.currentStatus==="waiting_human_response"},isTerminal(){return this.currentStatus==="resolved"||this.currentStatus==="closed"},isClosed(){return this.currentStatus==="closed"},endedBlockVisible(){var e;return!(!this.isTerminal||this.isClosed&&this.reopenedLocally[(e=this.currentConv)==null?void 0:e.id])},headerTitle(){var e,t;return((e=this.currentConv)==null?void 0:e.name)||((t=this.widget)==null?void 0:t.name)||this.t("common.newConversation")},composerPlaceholder(){return this.isEscalated&&this.humanAgentName?this.t("composer.replyTo",{name:this.humanAgentName.split(" ")[0]}):this.isWaitingHuman?this.t("composer.agentTakingOver"):this.t("composer.placeholder")},displayedMessages(){var i,s;const e=this.currentConv;if(!e)return[];const t=this.welcomeRevealedAt[e.id]>0?this.buildWelcomePrefix(e):[];if(!e._draft){const o=(s=(i=this.s)==null?void 0:i.paginationByConv)==null?void 0:s[e.id];if(!(o!=null&&o.loaded))return t}const n=this.revealedAt,r=(this.s.messagesByConv[e.id]||[]).filter(o=>{var a,l,d,c,m;return(o==null?void 0:o.type)==="action"&&((a=o==null?void 0:o.payload)==null?void 0:a.state)==="pending"||bn(o)&&!(n[o.id]>0)?!1:(o==null?void 0:o.type)==="action"||(o==null?void 0:o.type)==="system"||((l=o==null?void 0:o.payload)==null?void 0:l.type)==="system"||Array.isArray((d=o==null?void 0:o.payload)==null?void 0:d.attachments)&&o.payload.attachments.length||(c=o==null?void 0:o.metadata)!=null&&c.artifact||(m=o==null?void 0:o.metadata)!=null&&m.form||Array.isArray(o==null?void 0:o.callbacks)&&o.callbacks.some(C=>(C==null?void 0:C.intent)==="submit_form")?!0:typeof(o==null?void 0:o.text_md)=="string"&&o.text_md.trim().length>0});return t.length?[...t,...r]:r},streamingActive(){var n,r,i;const e=this.currentConv;return e?Object.keys(((n=this.s)==null?void 0:n.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:this.widgetWelcomeMessage&&this.welcomeRevealedAt[e.id]===0?!0:(((i=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:i[e.id])||[]).some(s=>bn(s)&&!(this.revealedAt[s.id]>0)):!1},currentConvMessages(){var t,n,r;const e=(t=this.currentConv)==null?void 0:t.id;return e?((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e])||[]:[]},pendingResolution(){var t,n,r,i,s;if(!this.currentConv)return null;const e=((n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id])||[];for(let o=e.length-1;o>=0;o--){const a=e[o];if((r=a==null?void 0:a.metadata)!=null&&r.resolution_request)return!Array.isArray(a.callbacks)||!a.callbacks.length||(s=(i=this.s)==null?void 0:i.awaitingCallback)!=null&&s[a.id]?null:a}return null},resolutionCallbacks(){const e=this.pendingResolution;if(!e||!Array.isArray(e.callbacks))return[];const t={resolve_confirm:this.t("resolution.confirm"),resolve_decline:this.t("resolution.decline")};return e.callbacks.map(n=>({...n,label:t[n.id]||n.label}))},pendingApproval(){var t,n,r,i;if(!this.currentConv)return null;const e=((n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id])||[];for(let s=e.length-1;s>=0;s--){const o=e[s];if(!(!Array.isArray(o==null?void 0:o.callbacks)||!o.callbacks.length||!o.callbacks.some(l=>(l==null?void 0:l.intent)==="approve"&&(l.audience??"customer")==="customer")))return(i=(r=this.s)==null?void 0:r.awaitingCallback)!=null&&i[o.id]?null:o}return null},approvalCallbacks(){const e=this.pendingApproval;return!e||!Array.isArray(e.callbacks)?[]:e.callbacks.filter(t=>(t==null?void 0:t.intent)==="approve"||(t==null?void 0:t.intent)==="reject")},currentStatus(){return this.convStatus(this.currentConv)},actionInFlight(){var e,t;return!this.currentConv||!this.store?null:((t=(e=this.store).getActionInFlight)==null?void 0:t.call(e,this.currentConv.id))||null},actionInFlightName(){var t;const e=this.actionInFlight;return e?((t=e.payload)==null?void 0:t.name)||e.text_md||this.t("common.action"):""},suggestions(){return this.currentConv?this.isTerminal?[]:this.streamingActive?[]:this.pendingForm?[]:this.conversationIsEmpty?this.starterPrompts:this.store?this.store.getLatestSuggestions(this.currentConv.id):[]:[]},conversationIsEmpty(){var n,r;const e=this.currentConv;return e?e._draft?!0:(((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[]).length===0:!1},starterPrompts(){var n;const e=(n=this.widget)==null?void 0:n.starter_prompts;if(!Array.isArray(e))return[];const t=[];for(const r of e){if(!r||typeof r!="object")continue;const i=typeof r.title=="string"?r.title.trim():"";if(!i)continue;const s=typeof r.message=="string"?r.message.trim():"";t.push({label:i,text:s||i,kind:"starter"})}return t},pendingForm(){var e,t;return!this.currentConv||!this.store||this.actionInFlight||this.streamingActive?null:((t=(e=this.store).getLatestForm)==null?void 0:t.call(e,this.currentConv.id))||null},showFeedback(){var t;const e=this.currentConv;return!e||this.currentStatus!=="resolved"?!1:this.feedbackDone[e.id]?!0:!((t=e.metadata)!=null&&t.feedback)},floatVisible(){return!!this.pendingApproval||!!this.pendingResolution||!!this.pendingForm||this.showFeedback||this.suggestions.length>0},dateLabel(){var n,r,i;const e=this.currentConv;let t=new Date;if(e){const o=((i=(((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[]).find(a=>a==null?void 0:a.created_at))==null?void 0:i.created_at)||e.created_at;if(o){const a=new Date(o);Number.isNaN(a.getTime())||(t=a)}}return this.t("messageList.today",{time:Bs(t,Bt(this.locale))})},paginationState(){var n,r,i;const e=(n=this.currentConv)==null?void 0:n.id,t=e?(i=(r=this.s)==null?void 0:r.paginationByConv)==null?void 0:i[e]:null;return{loading:!!(t!=null&&t.loading),hasMore:!!(t!=null&&t.nextCursor)}}},watch:{latestUnreads:{handler(e){const t=new Set(e.map(o=>o.convId)),n=this.dismissedPeeks||{},r=Object.keys(n);if(!r.length)return;const i={};let s=!1;for(const o of r)t.has(o)?i[o]=n[o]:s=!0;s&&(this.dismissedPeeks=i)},deep:!0},"currentConv.id":{handler(e){var t;this.resetRevealQueue(),this.convOpenedAt=Date.now(),this.moreOpen=!1,this.renameDialogOpen=!1,this.isViewingThread&&(this.unreadAnchorId=ht((t=this.currentConv)==null?void 0:t.last_read_message_id),this.unreadBoundaryTs=e?new Date().toISOString():""),e&&this.scheduleWelcomeReveal(e)},immediate:!0},isViewingThread(e,t){var n;e&&!t?(this.unreadAnchorId=ht((n=this.currentConv)==null?void 0:n.last_read_message_id),this.unreadBoundaryTs=new Date().toISOString()):e||(this.unreadAnchorId=null,this.unreadBoundaryTs="")},floatVisible:{handler(e){this.$nextTick(()=>this.syncFloatObserver(e))},immediate:!0},currentConvMessages(e){var t;this.paceMessages(e,(t=this.currentConv)==null?void 0:t.id),(this.isOpen||this.isEmbedded)&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(typeof document<"u"&&!document.getElementById(ti)){const e=document.createElement("style");e.id=ti,e.textContent=Ao,document.head.appendChild(e)}this._parentMessageHandler=this.onParentMessage.bind(this),window.addEventListener("message",this._parentMessageHandler),window.parent&&window.parent!==window&&window.parent.postMessage({type:"READY"},"*"),this.isEmbedded?(await this.boot(),this.store&&await this.open()):(await this.$nextTick(),this.sendCurrentLauncherSize(),this.observeLauncherSize())},beforeUnmount(){this._parentMessageHandler&&(window.removeEventListener("message",this._parentMessageHandler),this._parentMessageHandler=null),this._launcherRo&&(this._launcherRo.disconnect(),this._launcherRo=null),this.cancelReveals(),this.cancelWelcomeTimers(),this.teardownLiveReveal(),this.disconnectFloatRO(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{convStatus(e){var n,r,i,s;if(!e)return"open";const t=((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[];for(let o=t.length-1;o>=0;o--){const a=(s=(i=t[o])==null?void 0:i.metadata)==null?void 0:s.conversation_status;if(a)return a}return e.status||"open"},t(e,t){return this.translator(e,t)},waitForParentInit(){if(this.parentInitReceived)return Promise.resolve();if(!this.parentInitDeferred){let e;this.parentInitDeferred=new Promise(t=>{e=t}),this.parentInitDeferred._resolve=e}return this.parentInitDeferred},onParentMessage(e){var n;const t=e==null?void 0:e.data;if(!(!t||typeof t!="object")){if(t.type==="UPDATE"){this.transport&&t.payload&&this.transport.update(t.payload).catch(r=>{console.warn("[messenger] update failed",r)});return}if(t.type==="CONTEXT"){this.transport&&t.payload&&this.transport.context(t.payload);return}t.type==="INIT"&&(this.parentOrigin=e.origin,this.parentToken=typeof t.token=="string"?t.token:"",this.parentVariables=t.variables&&typeof t.variables=="object"?t.variables:t.context&&typeof t.context=="object"?t.context:null,this.parentAllowUnauthenticated=t.allowUnauthenticated===!0,this.parentInitReceived=!0,(n=this.parentInitDeferred)!=null&&n._resolve&&this.parentInitDeferred._resolve(),!this.isEmbedded&&!this.isOpen&&!this.parentAllowUnauthenticated&&this.parentToken&&this.hasValidSessionMarker()&&this.boot().catch(r=>{console.warn("[messenger] eager boot failed",r)}))}},hasValidSessionMarker(){if(typeof document>"u")return!1;const t=(document.cookie||"").match(/(?:^|; )messenger_session_marker=([^;]+)/);if(!t)return!1;const n=parseInt(t[1],10);return Number.isFinite(n)?n>Date.now():!1},async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds");return}try{await this.waitForParentInit(),this.transport=Ts(dc({baseUrl:this.baseUrl,widgetId:this.widgetId})),this.store=Ts(gc(this.transport)),this.hydrateNotifPref();const e=this.parentVariables||this.context||null;if(await this.store.start({origin:this.parentOrigin,token:this.parentToken||void 0,allowUnauthenticated:this.parentAllowUnauthenticated,variables:e&&typeof e=="object"?e:void 0}),e&&typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))n!=="customer"&&r&&typeof r=="object"&&!Array.isArray(r)&&(t[n]=r);Object.keys(t).length>0&&this.transport.context(t)}this.setupLiveReveal()}catch(e){console.error("[ww-messenger] bootstrap failed",e),this.bootError=(e==null?void 0:e.message)||String(e)}},async refresh(){this.store&&this.store.destroy(),this.cancelReveals(),this.cancelWelcomeTimers(),this.welcomeRevealedAt={},this.teardownLiveReveal(),this.teardownNotifications(),this.convOpenedAt=0,this.transport=null,this.store=null,this.isOpen=!1,this.draft="",this.busy=!1,this.bootError=null,this.pendingAttachments=[],this.feedbackBusy=!1,this.feedbackDone={},this.moreOpen=!1,this.renameDialogOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1,await this.boot(),this.isEmbedded&&this.store&&await this.open()},syncFloatObserver(e){if(this.disconnectFloatRO(),!e){this.floatHeight=0;return}const t=this.$refs.floatEl;if(t){if(typeof ResizeObserver>"u"){this.floatHeight=Math.ceil(t.getBoundingClientRect().height+8);return}this.floatRO=new ResizeObserver(n=>{const r=n[0];if(!r)return;const i=Math.ceil(r.contentRect.height+8);i!==this.floatHeight&&(this.floatHeight=i,this.$nextTick(()=>{var s,o;(o=(s=this.$refs.messageList)==null?void 0:s.keepPinnedToBottom)==null||o.call(s)}))}),this.floatRO.observe(t)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},async open(){this.isOpen=!0,this.notifyParentResize("open"),this._launcherRo&&this._launcherRo.disconnect(),this.store||await this.boot(),this.store&&this.store.setPanelOpen(!0);const e=this.currentConv;if(e&&!e._draft){this.activeConvId==null&&(this.activeConvId=e.id);try{await this.store.openConversation(e.id)}catch(t){console.error("[ww-messenger] load messages failed",t)}this.markConvRead(e)}},async close(){this.isOpen=!1,await this.$nextTick(),this.sendCurrentLauncherSize(),this.observeLauncherSize(),this.store&&this.store.setPanelOpen(!1)},notifyParentResize(e,t){if(window.parent&&window.parent!==window)try{window.parent.postMessage({type:"RESIZE",state:e,displayMode:this.displayMode,...t||{}},"*")}catch(n){console.warn("[ww-messenger] notifyParentResize failed",n)}},onLauncherHover(e){this.launcherHovered=e,this.sendCurrentLauncherSize()},sendCurrentLauncherSize(){var c,m,C,b,K,S,J;if(this.isOpen)return;const e=(m=(c=this.$el)==null?void 0:c.querySelector)==null?void 0:m.call(c,".wm-launcherWrap");if(!e)return;const t=e.getBoundingClientRect();if(!t.width||!t.height)return;const n=(((C=this.launcherPeeks)==null?void 0:C.length)??0)>0,r=16,i=Math.ceil(t.width),s=Math.ceil(t.height),o=(K=(b=this.$el)==null?void 0:b.querySelector)==null?void 0:K.call(b,".wm-launcher"),a=(J=(S=this.$el)==null?void 0:S.querySelectorAll)==null?void 0:J.call(S,".wm-peek"),l=a&&a.length?a[a.length-1]:null;let d=null;if(l){const U=l.getBoundingClientRect();d={width:Math.ceil(U.width),height:Math.ceil(U.height),rightOffset:Math.max(0,Math.ceil(t.right-U.right)),bottomOffset:Math.max(0,Math.ceil(t.bottom-U.bottom))}}this.notifyParentResize("closed",{width:i+r,height:s+r,launcherWidth:(o==null?void 0:o.offsetWidth)||null,launcherHeight:(o==null?void 0:o.offsetHeight)||null,launcherHovered:this.launcherHovered,peek:d,peekHovered:this.launcherHovered&&n})},observeLauncherSize(){var n,r;if(typeof ResizeObserver>"u")return;const e=(r=(n=this.$el)==null?void 0:n.querySelector)==null?void 0:r.call(n,".wm-launcherWrap");if(!e)return;this._launcherRo&&this._launcherRo.disconnect();const t=new ResizeObserver(()=>{this.isOpen||this.sendCurrentLauncherSize()});t.observe(e),this._launcherRo=t},async openFromPeek(e){var n,r;const t=e||((n=this.latestUnreads[0])==null?void 0:n.convId);t&&t!==((r=this.currentConv)==null?void 0:r.id)&&(this.draftConv=null,this.activeConvId=t,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1),await this.open()},dismissPeek(e){const t=this.latestUnreads.find(n=>n.convId===e);t&&(this.dismissedPeeks={...this.dismissedPeeks,[e]:t.ts})},onOnboardingStart(e){this.pendingLaunchText=(e||"").trim(),this.launching=!0,this.launchStage="whiteslide"},onHomeLaunched(){const e=this.pendingLaunchText;this.pendingLaunchText="",this.startConv(),e&&this.$nextTick(()=>this.onSend(e)),this.launchStage="header",window.setTimeout(()=>{this.launching&&(this.launchStage="messages")},520),window.setTimeout(()=>{this.launching=!1,this.launchStage="idle"},1160)},startConv(){this.draftConv={id:"__draft__",_draft:!0,name:"",created_at:new Date().toISOString()},this.activeConvId=null,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1,this.focusComposer()},onReopen(){var t;const e=(t=this.currentConv)==null?void 0:t.id;e&&(this.reopenedLocally={...this.reopenedLocally,[e]:!0},this.focusComposer())},async ensureRealConv(){const e=this.currentConv;if(!e)return null;if(!e._draft)return e;if(this.busy)return null;this.busy=!0;try{const t=await this.store.createConversation({}),n=this.welcomeRevealedAt.__draft__;return n!==void 0&&(this.welcomeRevealedAt={...this.welcomeRevealedAt,[t.id]:n>0?n:Date.now()}),this.draftConv=null,this.activeConvId=t.id,await this.store.openConversation(t.id),this.markConvRead(t),t}catch(t){return console.error("[ww-messenger] create conv failed",t),this.bootError=(t==null?void 0:t.message)||String(t),null}finally{this.busy=!1}},focusComposer(){this.$nextTick(()=>{var e;return(e=this.$refs.composer)==null?void 0:e.focus()})},buildWelcomePrefix(e){const t=this.widgetWelcomeMessage;return!t||typeof t!="string"||!t.trim()?[]:[{id:"__welcome__",text_md:t.trim(),author:{type:"agent_ia",name:this.agentName,avatar_url:this.agentAvatarUrl},created_at:(e==null?void 0:e.created_at)||new Date(0).toISOString()}]},scheduleWelcomeReveal(e){if(!e)return;const t=this.widgetWelcomeMessage;if(!t||typeof t!="string"||!t.trim()||this.welcomeRevealedAt[e]!==void 0)return;const n=this.currentConv;if(!((n==null?void 0:n._draft)||!(n!=null&&n.last_message_id))){this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:Date.now()};return}this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:0};const i=this.revealPacing,s=t.trim().length,o=Math.min(i.maxTypingMs,Math.max(i.minTypingMs,s*i.msPerChar)),a=i.firstRevealDelayMs+o,l=setTimeout(()=>{this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:Date.now()};const d={...this.welcomeRevealTimers};delete d[e],this.welcomeRevealTimers=d},a);this.welcomeRevealTimers={...this.welcomeRevealTimers,[e]:l}},cancelWelcomeTimers(){for(const e of Object.values(this.welcomeRevealTimers))try{clearTimeout(e)}catch{}this.welcomeRevealTimers={}},toggleMore(){this.moreOpen=!this.moreOpen},goHome(){this.moreOpen=!1,this.draftConv=null,this.activeConvId=null,this.backToHistory?(this.showOnboarding=!1,this.showHistory=!0,this.backToHistory=!1):(this.showOnboarding=!0,this.showHistory=!1)},async onDrawerPick(e){if(!(e!=null&&e.id)||!this.store)return;const t=this.showHistory;this.draftConv=null,this.activeConvId=e.id,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=t;try{await this.store.openConversation(e.id)}catch(r){console.error("[ww-messenger] open conv failed",r)}const n=this.allConversations.find(r=>r.id===e.id);n&&this.markConvRead(n)},async onMoreAction(e){var t,n;switch(this.moreOpen=!1,e){case"rename":this.openRenameDialog();break;case"export":Mc(this.currentConv,this.currentConv?(n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id]:[],this.translator,this.locale);break;case"status":if(In(this.statusUrl))try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(In(this.helpUrl))try{window.open(this.helpUrl,"_blank","noopener")}catch{}break}},openRenameDialog(){const e=this.currentConv;!e||e._draft||(this.renameDialogOpen=!0)},async onRenameSubmit(e){const t=this.currentConv;if(this.renameDialogOpen=!1,!t||t._draft||!this.store)return;const n=(e||"").trim();if(!(!n||n===t.name))try{await this.store.patchConversation(t.id,{name:n})}catch(r){console.error("[ww-messenger] rename failed",r)}},async onSend(e){let t=this.currentConv;if(!t&&(this.startConv(),t=this.currentConv,!t)||t._draft&&(t=await this.ensureRealConv(),!t))return;const n=t.id,r=this.pendingAttachments.slice();this.pendingAttachments=[],this.unreadAnchorId=null,this.unreadBoundaryTs="";const i=r.map(s=>{const{previewUrl:o,...a}=s;return a});await this.store.send(n,e,{attachments:i.length?i:void 0})},async onSuggestion(e){const t=(e==null?void 0:e.text)||(e==null?void 0:e.label);t&&await this.onSend(t)},async onLoadMore(){var t;const e=(t=this.currentConv)==null?void 0:t.id;!e||!this.store||await this.store.loadMore(e)},async onResolutionSelect(e){const t=this.pendingResolution;!t||!(e!=null&&e.id)||await this.store.clickCallback(t.id,e.id)},async onApprovalSelect(e){const t=this.pendingApproval;!t||!(e!=null&&e.id)||await this.store.clickCallback(t.id,e.id)},async onFormSubmit({values:e}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const n=kc(t.form,e,this.translator);if(!n)return;let r=this.currentConv;r&&(r._draft&&(r=await this.ensureRealConv(),!r)||await this.store.send(r.id,n,{metadata:{artifact:Cc(t.form,e,this.translator)}}))},formatAttachmentSize(e){return e?e<1024?this.t("attachment.bytes",{size:e}):e<1024*1024?this.t("attachment.kilobytes",{size:(e/1024).toFixed(0)}):this.t("attachment.megabytes",{size:(e/(1024*1024)).toFixed(1)}):""},removePendingAttachment(e){this.pendingAttachments.splice(e,1)},async onAttach(e){var t,n;if(!(!e||!this.transport))try{const r=await this.transport.uploadAttachment(e),i=(r==null?void 0:r.type)==="image"||(e.type||"").toLowerCase().startsWith("image/")||((r==null?void 0:r.mime_type)||"").toLowerCase().startsWith("image/");let s=null;if(i)try{s=await((n=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:n.call(t,r.path))||null}catch{}this.pendingAttachments.push({type:r.type||"file",path:r.path,name:e.name||this.t("attachment.fileFallbackName"),mime_type:e.type,size_bytes:e.size,previewUrl:s})}catch(r){console.error("[ww-messenger] attachment upload failed",r)}},onPanelClick(e){const t=e.target&&e.target.closest?e.target.closest('a[href^="#"]'):null;t&&(e.preventDefault(),this.openInternalUrl(t.getAttribute("href")))},async openInternalUrl(e){if(typeof e!="string"||!e.startsWith("#"))return!1;const t=e.slice(1);if(t==="new"||t==="new-conversation")return this.isOpen||await this.open(),this.startConv(),!0;if(t.startsWith("conversation/")){const n=t.slice(13);return n&&await this.openFromPeek(n),!0}return console.warn("[messenger] unknown internal url",e),!0},async onQuickLink(e){if(e){if(e.url){if(await this.openInternalUrl(e.url))return;if(!In(e.url)){console.warn("[messenger] refusing unsafe quick-link url",e.url);return}try{window.open(e.url,"_blank","noopener")}catch{}return}this.currentConv||this.startConv(),await this.onSend(e.label)}},async onFeedback({rating:e,comment:t}){if(this.currentConv){this.feedbackBusy=!0;try{await this.store.submitFeedback(this.currentConv.id,{rating:e,comment:t}),this.feedbackDone={...this.feedbackDone,[this.currentConv.id]:!0}}catch(n){console.error("[ww-messenger] feedback failed",n)}finally{this.feedbackBusy=!1}}}}},rg={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},ig=["aria-label"],og={class:"wm-screens"},ag={key:"error",class:"wm-screen wm-state"},lg={class:"wm-state__err"},cg={class:"wm-state__errTitle"},ug={class:"wm-state__errSub"},dg={key:"chat",class:"wm-screen wm-screen--chat"},fg={class:"wm-bottom"},hg={key:0,ref:"floatEl",class:"wm-float"},mg={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},gg={class:"wm-actionWait__lbl"},pg={key:2,class:"wm-attached"},_g=["src","alt"],yg={key:1,class:"wm-attached__file"},vg={class:"wm-attached__fileMeta"},bg={class:"wm-attached__fileName"},wg={key:0,class:"wm-attached__fileSize"},kg=["aria-label","onClick"],Cg={key:3,class:"wm-ended",role:"status","aria-live":"polite"},Sg={class:"wm-ended__lbl"};function Ag(e,t,n,r,i,s){const o=ve("Launcher"),a=ve("Header"),l=ve("History"),d=ve("Onboarding"),c=ve("MessageList"),m=ve("InlineCallbacks"),C=ve("FormCard"),b=ve("Feedback"),K=ve("Composer"),S=ve("MoreMenu"),J=ve("RenameDialog");return h(),p("div",{class:te(["wm-root",`wm-root--${n.displayMode}`]),style:Ce(s.rootStyle)},[!i.isOpen&&!s.isEmbedded?(h(),fe(o,{key:0,"unread-count":s.unreadCount,peeks:s.launcherPeeks,onOpen:s.openFromPeek,onDismiss:s.dismissPeek,onHover:s.onLauncherHover},null,8,["unread-count","peeks","onOpen","onDismiss","onHover"])):F("",!0),i.isOpen||s.isEmbedded?(h(),p("section",{key:1,class:te(["wm-panel",`wm-panel--${n.displayMode}`,{"wm-panel--welcome":s.ready&&!s.error&&!s.currentConv},i.launching?`wm-launch-${i.launchStage}`:""]),style:Ce(i.floatHeight?{"--wm-float-h":i.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger",onClick:t[7]||(t[7]=(...U)=>s.onPanelClick&&s.onPanelClick(...U))},[!s.ready&&!s.error?(h(),p("div",rg,[s.isEmbedded?F("",!0):(h(),p("button",{key:0,type:"button",class:"wm-loading__close","aria-label":s.t("loading.minimize"),onClick:t[0]||(t[0]=(...U)=>s.close&&s.close(...U))},[...t[8]||(t[8]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,ig)),t[9]||(t[9]=u("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(h(),p(Z,{key:1},[pe(a,{title:s.headerTitle,"team-members":s.teamMembers,"response-label":s.responseLabel,"show-identity":!!s.currentConv,"show-back":s.canBack,"show-close":!s.isEmbedded,"more-active":i.moreOpen,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onBack:s.goHome,onMore:s.toggleMore,onClose:s.close},null,8,["title","team-members","response-label","show-identity","show-back","show-close","more-active","agent-name","agent-avatar-url","onBack","onMore","onClose"]),u("div",og,[pe(Qs,{name:"wm-none"},{default:Xn(()=>[s.error?(h(),p("div",ag,[u("div",lg,[t[10]||(t[10]=u("div",{class:"wm-state__errIcon"},[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})])],-1)),u("div",null,[u("div",cg,R(s.t("error.connectionFailed")),1),u("div",ug,R(s.error),1)])])])):!s.currentConv&&i.showHistory?(h(),fe(l,{key:"history",class:"wm-screen",threads:s.openThreads,onResume:s.onDrawerPick},null,8,["threads","onResume"])):s.currentConv?(h(),p("div",dg,[pe(c,{ref:"messageList",messages:s.displayedMessages,"streaming-active":s.streamingActive,"date-label":s.dateLabel,"conversation-id":s.currentConv?s.currentConv.id:null,"loading-more":s.paginationState.loading,"has-more":s.paginationState.hasMore,"unread-anchor-id":e.unreadAnchorId,"unread-boundary-ts":e.unreadBoundaryTs,"ai-agent-name":s.agentName,"ai-agent-avatar-url":s.agentAvatarUrl,onLoadMore:s.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","unread-anchor-id","unread-boundary-ts","ai-agent-name","ai-agent-avatar-url","onLoadMore"]),u("div",fg,[s.floatVisible?(h(),p("div",hg,[s.pendingApproval?(h(),fe(m,{key:`appr-${s.pendingApproval.id}`,variant:"buttons",items:s.approvalCallbacks,onSelect:s.onApprovalSelect},null,8,["items","onSelect"])):s.pendingResolution?(h(),fe(m,{key:`res-${s.pendingResolution.id}`,variant:"buttons",items:s.resolutionCallbacks,onSelect:s.onResolutionSelect},null,8,["items","onSelect"])):s.pendingForm?(h(),fe(C,{key:s.pendingForm.message&&s.pendingForm.message.id,form:s.pendingForm.form,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onSubmit:s.onFormSubmit},null,8,["form","agent-name","agent-avatar-url","onSubmit"])):s.showFeedback?(h(),fe(b,{key:3,busy:i.feedbackBusy,done:!!(s.currentConv&&i.feedbackDone[s.currentConv.id]),onSubmit:s.onFeedback},null,8,["busy","done","onSubmit"])):(h(),fe(m,{key:4,items:s.suggestions,onSelect:s.onSuggestion},null,8,["items","onSelect"]))],512)):F("",!0),s.actionInFlight?(h(),p("div",mg,[t[11]||(t[11]=u("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),u("span",gg,R(s.t("action.inProgress",{name:s.actionInFlightName})),1)])):F("",!0),i.pendingAttachments.length?(h(),p("div",pg,[(h(!0),p(Z,null,Se(i.pendingAttachments,(U,$)=>(h(),p("div",{key:U.path||$,class:"wm-attached__item"},[U.previewUrl?(h(),p("img",{key:0,class:"wm-attached__thumb",src:U.previewUrl,alt:U.name},null,8,_g)):(h(),p("div",yg,[t[12]||(t[12]=u("span",{class:"wm-attached__fileIcon"},[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),u("path",{d:"M14 2v6h6"})])],-1)),u("span",vg,[u("span",bg,R(U.name),1),s.formatAttachmentSize(U.size_bytes)?(h(),p("span",wg,R(s.formatAttachmentSize(U.size_bytes)),1)):F("",!0)])])),u("button",{type:"button",class:"wm-attached__remove","aria-label":s.t("attachment.remove"),onClick:ne=>s.removePendingAttachment($)},[...t[13]||(t[13]=[u("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,kg)]))),128))])):F("",!0),s.endedBlockVisible?(h(),p("div",Cg,[u("span",Sg,R(s.isClosed?s.t("composer.conversationClosed"):s.t("composer.conversationEnded")),1),u("button",{type:"button",class:"wm-ended__btn",onClick:t[2]||(t[2]=U=>s.isClosed?s.onReopen():s.startConv())},R(s.isClosed?s.t("composer.reopen"):s.t("composer.newConversation")),1)])):s.actionInFlight?F("",!0):(h(),fe(K,{key:4,ref:"composer",modelValue:i.draft,"onUpdate:modelValue":t[3]||(t[3]=U=>i.draft=U),placeholder:s.composerPlaceholder,"attach-label":s.t("composer.attachFile"),"display-mode":n.displayMode,onSend:s.onSend,onAttach:s.onAttach},null,8,["modelValue","placeholder","attach-label","display-mode","onSend","onAttach"]))]),i.moreOpen?(h(),fe(S,{key:0,"can-rename":!!s.currentConv&&!s.currentConv._draft,"can-export":!!s.currentConv&&!s.currentConv._draft,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[4]||(t[4]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["can-rename","can-export","sound-enabled","status-url","help-url","onSoundToggle","onAction"])):F("",!0),i.renameDialogOpen&&s.currentConv&&!s.currentConv._draft?(h(),fe(J,{key:1,"initial-value":s.currentConv.name||"",title:s.t("rename.dialogTitle"),onClose:t[5]||(t[5]=U=>i.renameDialogOpen=!1),onSubmit:s.onRenameSubmit},null,8,["initial-value","title","onSubmit"])):F("",!0)])):(h(),fe(d,{key:"home",class:"wm-screen",title:s.widgetTitle,subtitle:s.widgetSubtitle,"agent-name":s.agentName,"default-icon-url":s.defaultIconUrl,"cover-image-url":s.coverImageUrl,"quick-links":s.quickLinks,"open-threads":s.openThreads,busy:i.busy,launching:i.launching,"welcome-message":s.widgetWelcomeMessage,onStart:s.onOnboardingStart,onLaunched:s.onHomeLaunched,onSelect:s.onQuickLink,onResume:s.onDrawerPick,onViewHistory:t[1]||(t[1]=U=>i.showHistory=!0)},null,8,["title","subtitle","agent-name","default-icon-url","cover-image-url","quick-links","open-threads","busy","launching","welcome-message","onStart","onLaunched","onSelect","onResume"]))]),_:1})]),i.moreOpen&&!s.currentConv?(h(),fe(S,{key:0,"can-rename":!1,"can-export":!1,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[6]||(t[6]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["sound-enabled","status-url","help-url","onSoundToggle","onAction"])):F("",!0)],64))],6)):F("",!0)],6)}const xg=be(sg,[["render",Ag],["__scopeId","data-v-801581ca"]]),ni=window.__WIDGET_ID,si=window.__BASE_URL,Tg=window.__DISPLAY_MODE||"floating",ri=window.__LANGUAGE||"";window.__MESSENGER_IFRAME_VERSION="0.6.27";if(!ni||!si)console.error("[messenger-iframe] missing __WIDGET_ID or __BASE_URL globals");else{if(!document.getElementById("wm-tokens")){const e=document.createElement("style");e.id="wm-tokens",e.textContent=Ao,document.head.appendChild(e)}sc({render:()=>wo(xg,{baseUrl:si,widgetId:ni,displayMode:Tg,...ri?{language:ri}:{}})}).mount("#app")}
74
+ `)}function Mc(e,t,n=Ee(),r){if(!e)return;const i=Tc(e,t||[],n,Bt(r)),s=new Blob([i],{type:"text/plain;charset=utf-8"});try{const o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${(e.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(()=>URL.revokeObjectURL(o),1e3)}catch(o){console.error("[ww-messenger] export failed",o)}}const Ec={data(){const e=typeof Notification<"u";return{notifPermission:e?Notification.permission:"denied",soundEnabled:!0,browserNotifEnabled:e&&Notification.permission==="granted",_audioCtx:null}},methods:{teardownNotifications(){var e,t;if(this._audioCtx){try{(t=(e=this._audioCtx).close)==null||t.call(e)}catch{}this._audioCtx=null}},soundStorageKey(){return`wm:notif:sound:${this.widgetId||""}`},browserNotifStorageKey(){return`wm:notif:browser:${this.widgetId||""}`},hydrateNotifPref(){try{if(typeof localStorage>"u")return;const e=localStorage.getItem(this.soundStorageKey());e==="0"?this.soundEnabled=!1:e==="1"&&(this.soundEnabled=!0);const t=localStorage.getItem(this.browserNotifStorageKey());t==="0"?this.browserNotifEnabled=!1:t==="1"&&(this.browserNotifEnabled=typeof Notification<"u"&&Notification.permission==="granted")}catch{}},persistSoundPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.soundStorageKey(),this.soundEnabled?"1":"0")}catch{}},persistBrowserNotifPref(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.browserNotifStorageKey(),this.browserNotifEnabled?"1":"0")}catch{}},onSoundToggle(e){this.soundEnabled=!!e,this.persistSoundPref()},async onBrowserNotifToggle(e){if(typeof Notification>"u"){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}if(!e){this.browserNotifEnabled=!1,this.persistBrowserNotifPref();return}let t=Notification.permission;if(t==="default"){try{t=await Notification.requestPermission()}catch(n){console.warn("[ww-messenger] notif permission request failed",n),t="denied"}this.notifPermission=t}this.browserNotifEnabled=t==="granted",this.persistBrowserNotifPref()},onMessageRevealed(e,t){var i;if(!this.soundEnabled&&!this.browserNotifEnabled||!t||!e||!bn(e))return;const n=typeof document<"u"&&document.hidden;this.isOpen&&!n&&((i=this.currentConv)==null?void 0:i.id)===t||(this.soundEnabled&&this.playNotificationSound(),this.browserNotifEnabled&&this.showBrowserNotification(t,e))},playNotificationSound(){if(typeof window>"u")return;const e=window.AudioContext||window.webkitAudioContext;if(e)try{this._audioCtx||(this._audioCtx=new e);const t=this._audioCtx;if(t.state==="suspended")try{t.resume()}catch{}const n=t.currentTime,r=t.createOscillator(),i=t.createGain();r.connect(i),i.connect(t.destination),r.type="sine",r.frequency.setValueAtTime(880,n),r.frequency.exponentialRampToValueAtTime(1320,n+.08),i.gain.setValueAtTime(0,n),i.gain.linearRampToValueAtTime(.12,n+.02),i.gain.exponentialRampToValueAtTime(1e-4,n+.28),r.start(n),r.stop(n+.32)}catch{}},showBrowserNotification(e,t){if(typeof Notification>"u"||Notification.permission!=="granted")return;const n=t==null?void 0:t.author,r=!n||n.type==="agent_ia",s=((n==null?void 0:n.name)||(r?this.agentName:"")||this.t("launcher.theAgent"))+this.t("launcher.repliedToYou"),o=typeof(t==null?void 0:t.text_md)=="string"?t.text_md.trim():"",a=o?o.slice(0,140):this.t("notification.youHaveNewMessage");try{const l=new Notification(s,{body:a,tag:`wm-${e}`,renotify:!1,silent:!0});l.onclick=()=>{try{window.focus()}catch{}this.draftConv=null,this.showOnboarding=!1,this.activeConvId=e,this.isOpen=!0,this.store&&this.store.setPanelOpen(!0);try{l.close()}catch{}}}catch(l){console.warn("[ww-messenger] notification failed",l)}}}},Qt=Object.freeze({firstRevealDelayMs:450,msPerChar:50,minTypingMs:900,maxTypingMs:12e3,pauseBetweenMs:300}),Zt=(e,t)=>Number.isFinite(e)?e:t,Oc={computed:{revealPacing(){var t;const e=((t=this.widget)==null?void 0:t.reveal_pacing)||{};return{firstRevealDelayMs:Zt(e.first_reveal_delay_ms,Qt.firstRevealDelayMs),msPerChar:Zt(e.ms_per_char,Qt.msPerChar),minTypingMs:Zt(e.min_typing_ms,Qt.minTypingMs),maxTypingMs:Zt(e.max_typing_ms,Qt.maxTypingMs),pauseBetweenMs:Zt(e.pause_between_ms,Qt.pauseBetweenMs)}}},data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[],_liveRevealOff:null,_liveRevealConvSnapshot:null,_liveHwm:{}}},methods:{cancelReveals(){for(const e of this.revealTimers)clearTimeout(e);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},setupLiveReveal(){var n,r;if(!this.transport)return;this.teardownLiveReveal();const e=this.transport.on("message",i=>{const s=i==null?void 0:i.conversation_id,o=i==null?void 0:i.message;s&&o&&this.paceLiveMessage(o,s)});this._liveRevealConvSnapshot=new Map((((n=this.s)==null?void 0:n.conversations)||[]).map(i=>[i.id,(i==null?void 0:i.last_message_at)||""])),this._liveHwm=Object.fromEntries((((r=this.s)==null?void 0:r.conversations)||[]).map(i=>[i.id,(i==null?void 0:i.last_message_at)||""]));const t=this.transport.on("activity",i=>{this.handleLiveActivity(i)});this._liveRevealOff=()=>{try{e()}catch{}try{t()}catch{}}},teardownLiveReveal(){if(this._liveRevealOff){try{this._liveRevealOff()}catch{}this._liveRevealOff=null}this._liveRevealConvSnapshot=null,this._liveHwm={}},async handleLiveActivity(e){var i,s;const t=e==null?void 0:e.conversations;if(!Array.isArray(t)||!this.store)return;const n=this._liveRevealConvSnapshot||new Map,r=[];for(const o of t){if(!(o!=null&&o.id))continue;const a=o.last_message_at||"";if(!a)continue;const l=n.get(o.id)||"";a>l&&r.push(o.id)}this._liveRevealConvSnapshot=new Map(t.map(o=>[o.id,(o==null?void 0:o.last_message_at)||""]));for(const o of r)try{const a=await((s=(i=this.store).fetchSinceLast)==null?void 0:s.call(i,o));if(!Array.isArray(a))continue;for(const l of a)this.paceLiveMessage(l,o)}catch(a){console.error("[ww-messenger] activity delta fetch failed",a)}},scheduleReveal(e,t){const n=this.revealPacing,r=Date.now(),i=((e==null?void 0:e.text_md)||"").length,s=Math.min(n.maxTypingMs,Math.max(n.minTypingMs,i*n.msPerChar)),a=Math.max(r+n.firstRevealDelayMs,this.nextRevealAt+n.pauseBetweenMs)+s;this.nextRevealAt=a;const l=Math.max(0,a-r),d=e.id,c=setTimeout(()=>{this.revealedAt={...this.revealedAt,[d]:Date.now()},this.revealTimers=this.revealTimers.filter(m=>m!==c),typeof this.onMessageRevealed=="function"&&this.onMessageRevealed(e,t)},l);this.revealTimers.push(c)},paceMessages(e,t){var i;if(!Array.isArray(e)||!e.length)return;const n=Date.now(),r={...this.revealedAt};for(const s of e){if((s==null?void 0:s.id)==null||r[s.id]!==void 0)continue;if(!bn(s)){r[s.id]=n;continue}const o=s!=null&&s.created_at?Date.parse(s.created_at):NaN;if(!Number.isFinite(o)||o<this.convOpenedAt){r[s.id]=n;continue}const a=typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0,l=Array.isArray((i=s==null?void 0:s.payload)==null?void 0:i.attachments)&&s.payload.attachments.length>0;if(!a&&!l){r[s.id]=n;continue}r[s.id]=0,this.scheduleReveal(s,t)}this.revealedAt=r},paceLiveMessage(e,t){var a;if(!(e!=null&&e.id)||this.revealedAt[e.id]!==void 0)return;if(!bn(e)){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}const n=typeof(e==null?void 0:e.text_md)=="string"&&e.text_md.trim().length>0,r=Array.isArray((a=e==null?void 0:e.payload)==null?void 0:a.attachments)&&e.payload.attachments.length>0;if(!n&&!r){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}const i=this._liveHwm[t],s=(e==null?void 0:e.created_at)||"";if(s&&(i===void 0||s>i)&&(this._liveHwm={...this._liveHwm,[t]:s}),!(i!==void 0&&s&&s>i)){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}this.revealedAt={...this.revealedAt,[e.id]:0},this.scheduleReveal(e,t)}}},Rc=300,Ic={data(){return{unreadAnchorId:null,unreadBoundaryTs:""}},created(){this._readMarkerTimer=null,this._readMarkerPending=null},beforeUnmount(){this._readMarkerTimer&&(clearTimeout(this._readMarkerTimer),this._readMarkerTimer=null),this._readMarkerPending=null},methods:{markConvRead(e){var s,o;if(!(e!=null&&e.id)||e._draft||!this.store)return;const t=((o=(s=this.s)==null?void 0:s.messagesByConv)==null?void 0:o[e.id])||[],n=Lc(t);if(n==null)return;const r=ht(e.last_read_message_id),i=ht(n);i!=null&&(r!=null&&i<=r||(this._readMarkerPending={convId:e.id,messageId:n},!this._readMarkerTimer&&(this._readMarkerTimer=setTimeout(()=>{const a=this._readMarkerPending;this._readMarkerPending=null,this._readMarkerTimer=null,a&&this.store&&this.store.markConversationRead(a.convId,a.messageId)},Rc))))}}};function Lc(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(!(!n||n._pending)&&ht(n.id)!=null)return n.id}return null}const be=(e,t)=>{const n=e.__vccOpts||e;for(const[r,i]of t)n[r]=i;return n},Pc={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26},tail:{type:Boolean,default:!1}},computed:{bg(){return this.avatarUrl?"transparent":Zs(this.name)},initials(){return er(this.name)}}},Bc=["src","alt"];function Fc(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-huav",{"wm-huav--tail":n.tail}]),style:Ce({width:n.size+"px",height:n.size+"px","--wm-avr":Math.round(n.size*.32)+"px",background:s.bg})},[n.avatarUrl?(h(),p("img",{key:0,src:n.avatarUrl,alt:n.name||""},null,8,Bc)):(h(),p("span",{key:1,style:Ce({fontSize:n.size*.36+"px"})},R(s.initials),5))],6)}const rs=be(Pc,[["render",Fc],["__scopeId","data-v-14e10c0d"]]),Dc=3,Nc={name:"WmLauncher",components:{HumanAvatar:rs},inject:{t:{default:()=>Ee()}},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,Dc).reverse()}}},Hc=["aria-label","onClick","onKeydown"],Uc=["aria-label","onClick"],jc={class:"wm-peek__avatar"},Vc=["aria-label"],Kc={class:"wm-peek__body"},zc={class:"wm-peek__head"},Wc={class:"wm-peek__name"},$c={class:"wm-peek__action"},qc={class:"wm-peek__text"},Gc=["onClick"],Yc=["aria-label"],Jc=["aria-label"];function Xc(e,t,n,r,i,s){const o=ve("HumanAvatar");return h(),p("div",{class:"wm-launcherWrap",onMouseenter:t[1]||(t[1]=a=>e.$emit("hover",!0)),onMouseleave:t[2]||(t[2]=a=>e.$emit("hover",!1)),onFocusin:t[3]||(t[3]=a=>e.$emit("hover",!0)),onFocusout:t[4]||(t[4]=a=>e.$emit("hover",!1))},[pe(Qs,{name:"wm-peek"},{default:Xn(()=>[s.visiblePeeks.length?(h(),p("div",{key:0,class:te(["wm-peekStack",{"wm-peekStack--multi":s.visiblePeeks.length>1}])},[(h(!0),p(Z,null,Se(s.visiblePeeks,(a,l)=>(h(),p("div",{key:a.convId,class:"wm-peek",style:Ce({"--depth":s.visiblePeeks.length-1-l,zIndex:l+1}),role:"button",tabindex:"0","aria-label":s.t("launcher.openConversationWith",{name:a.senderName||s.t("launcher.theAgent")}),onClick:d=>e.$emit("open",a.convId),onKeydown:[Un(We(d=>e.$emit("open",a.convId),["prevent"]),["enter"]),Un(We(d=>e.$emit("open",a.convId),["prevent"]),["space"])]},[u("button",{type:"button",class:"wm-peek__close","aria-label":s.t("launcher.dismiss"),onClick:We(d=>e.$emit("dismiss",a.convId),["stop"])},[...t[5]||(t[5]=[u("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,Uc),u("div",jc,[pe(o,{name:a.senderName,"avatar-url":a.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),a.count>1?(h(),p("span",{key:0,class:"wm-peek__avatarBadge","aria-label":s.t("launcher.unreadMessages",{count:a.count})},R(a.count>9?"9+":a.count),9,Vc)):F("",!0)]),u("div",Kc,[u("div",zc,[u("span",Wc,R(a.senderName||s.t("common.agent")),1),u("span",$c,R(s.t("launcher.repliedToYou")),1)]),u("p",qc,R(a.preview),1)]),u("button",{type:"button",class:"wm-peek__open",onClick:We(d=>e.$emit("open",a.convId),["stop"])},R(s.t("common.open")),9,Gc)],44,Hc))),128))],2)):F("",!0)]),_:1}),u("button",{type:"button",class:"wm-launcher","aria-label":s.t("launcher.open"),onClick:t[0]||(t[0]=a=>e.$emit("open"))},[t[6]||(t[6]=u("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)),n.unreadCount>0?(h(),p("span",{key:0,class:"wm-launcher__badge","aria-label":n.unreadCount>1?s.t("launcher.unreadConversationsMany",{count:n.unreadCount}):s.t("launcher.unreadConversationsOne",{count:n.unreadCount})},R(n.unreadCount>9?"9+":n.unreadCount),9,Jc)):F("",!0)],8,Yc)],32)}const Qc=be(Nc,[["render",Xc],["__scopeId","data-v-d81459bc"]]),Zc={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1},tail:{type:Boolean,default:!1},name:{type:String,default:""},imageUrl:{type:String,default:null}},computed:{initials(){return er(this.name)},bgColor(){return Zs(this.name)}}},eu={key:0,class:"wm-aiav__pulse"},tu=["src","alt"],nu=["width","height"];function su(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-aiav",{"wm-aiav--tail":n.tail}]),style:Ce({width:n.size+"px",height:n.size+"px","--wm-avr":n.size*.32+"px"})},[n.pulse?(h(),p("div",eu)):F("",!0),u("div",{class:te(["wm-aiav__inner",{"wm-aiav__inner--glow":n.pulse,"wm-aiav__inner--img":!!n.imageUrl,"wm-aiav__inner--initials":!n.imageUrl&&!!s.initials}]),style:Ce(!n.imageUrl&&s.initials?{background:s.bgColor}:null)},[n.imageUrl?(h(),p("img",{key:0,src:n.imageUrl,alt:n.name||""},null,8,tu)):s.initials?(h(),p("span",{key:1,style:Ce({fontSize:n.size*.36+"px"})},R(s.initials),5)):(h(),p("svg",{key:2,width:n.size*.5,height:n.size*.5,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[...t[0]||(t[0]=[u("path",{d:"M12 2 L13.5 9 L20 10.5 L13.5 12 L12 19 L10.5 12 L4 10.5 L10.5 9 Z",fill:"white",opacity:"0.92"},null,-1),u("circle",{cx:"19",cy:"5",r:"1.5",fill:"white",opacity:"0.55"},null,-1),u("circle",{cx:"5",cy:"18",r:"1",fill:"white",opacity:"0.38"},null,-1)])],8,nu))],6)],6)}const Sn=be(Zc,[["render",su],["__scopeId","data-v-6f7f685d"]]),ru={name:"WmTeamAvatars",props:{members:{type:Array,default:()=>[]},responseLabel:{type:String,default:""}},computed:{visible(){return Array.isArray(this.members)&&this.members.length>0},stackWidth(){return Math.min(this.members.length,3)===1?20:16+Math.min(this.members.length,3)*13}},methods:{colorFor(e){return e.avatar_url?"transparent":Zs(e.name||"")},initialsFor(e){return er(e.name||"")}}},iu={key:0,class:"wm-team"},ou=["src","alt"],au={key:1},lu={key:0,class:"wm-team__label"};function cu(e,t,n,r,i,s){return s.visible?(h(),p("div",iu,[u("div",{class:"wm-team__stack",style:Ce({width:s.stackWidth+"px"})},[(h(!0),p(Z,null,Se(n.members.slice(0,3),(o,a)=>(h(),p("div",{key:a,class:"wm-team__pill",style:Ce({left:a*13+"px",zIndex:3-a,background:s.colorFor(o)})},[o.avatar_url?(h(),p("img",{key:0,src:o.avatar_url,alt:o.name||""},null,8,ou)):(h(),p("span",au,R(s.initialsFor(o)),1))],4))),128))],4),n.responseLabel?(h(),p("span",lu,R(n.responseLabel),1)):F("",!0)])):F("",!0)}const uu=be(ru,[["render",cu],["__scopeId","data-v-e49a9063"]]),du={name:"WmHeader",components:{AIAvatar:Sn,TeamAvatars:uu},inject:{t:{default:()=>Ee()}},props:{title:{type:String,default:"Nouvelle conversation"},showBack:{type:Boolean,default:!1},teamMembers:{type:Array,default:()=>[]},responseLabel:{type:String,default:""},showClose:{type:Boolean,default:!0},showMore:{type:Boolean,default:!0},moreActive:{type:Boolean,default:!1},showIdentity:{type:Boolean,default:!0},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["back","close","more"],computed:{hasTeam(){return Array.isArray(this.teamMembers)&&this.teamMembers.length>0},displayedTeamMembers(){const e=Array.isArray(this.teamMembers)?this.teamMembers:[];if(e.length<=3)return e;const t=new Date().getHours()%e.length,n=[];for(let r=0;r<3;r++)n.push(e[(t+r)%e.length]);return n}}},fu={class:"wm-header"},hu=["aria-label"],mu={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},gu={class:"wm-header__avatar"},pu={class:"wm-header__main"},_u={class:"wm-header__title"},yu={key:3,class:"wm-header__fill"},vu={class:"wm-header__actions"},bu=["aria-label","title"],wu=["aria-label","title"];function ku(e,t,n,r,i,s){const o=ve("AIAvatar"),a=ve("TeamAvatars");return h(),p("div",fu,[n.showBack?(h(),p("button",{key:0,type:"button",class:"wm-header__icon wm-header__back","aria-label":s.t("header.backToHome"),onClick:t[0]||(t[0]=l=>e.$emit("back"))},[...t[3]||(t[3]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M19 12H5M12 5l-7 7 7 7"})],-1)])],8,hu)):(h(),p("div",mu)),n.showIdentity?(h(),p(Z,{key:2},[u("div",gu,[pe(o,{size:30,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",pu,[u("div",_u,R(n.title),1)]),s.hasTeam?(h(),fe(a,{key:0,members:s.displayedTeamMembers,"response-label":""},null,8,["members"])):F("",!0)],64)):(h(),p("div",yu)),u("div",vu,[n.showMore?(h(),p("button",{key:0,type:"button",class:te(["wm-header__icon",{"wm-header__icon--active":n.moreActive}]),"aria-label":s.t("header.moreOptions"),title:s.t("header.moreOptions"),onClick:t[1]||(t[1]=l=>e.$emit("more"))},[...t[4]||(t[4]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},[u("circle",{cx:"12",cy:"5",r:"1.6"}),u("circle",{cx:"12",cy:"12",r:"1.6"}),u("circle",{cx:"12",cy:"19",r:"1.6"})],-1)])],10,bu)):F("",!0),n.showClose?(h(),p("button",{key:1,type:"button",class:"wm-header__icon","aria-label":s.t("header.closeWidget"),title:s.t("header.closeWidget"),onClick:t[2]||(t[2]=l=>e.$emit("close"))},[...t[5]||(t[5]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,wu)):F("",!0)])])}const Cu=be(du,[["render",ku],["__scopeId","data-v-27232009"]]),Zr={book:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253",changelog:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2",status:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",chat:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z",link:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"},Su={name:"WmOnboarding",components:{AIAvatar:Sn,HumanAvatar:rs},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{title:{type:String,default:""},subtitle:{type:String,default:""},agentName:{type:String,default:""},defaultIconUrl:{type:String,default:null},coverImageUrl:{type:String,default:null},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1},launching:{type:Boolean,default:!1},welcomeMessage:{type:String,default:""}},emits:["start","launched","select","resume","view-history"],data(){return{launchPhase:"idle",inputFocused:!1,launchDone:!1,starterText:""}},watch:{launching(e){e&&this.runLaunch()}},computed:{canStart(){return!this.busy&&!!this.starterText.trim()},typing(){return this.inputFocused&&!!this.starterText.trim()},heroTitle(){return this.title?this.title:this.agentName?this.t("onboarding.greetingNamed",{name:this.agentName}):this.t("onboarding.greeting")},heroSub(){return this.subtitle||this.t("onboarding.heroSub")},unreadThreads(){return this.openThreads.filter(e=>e.unread)},safeCoverUrl(){return Gr(this.coverImageUrl)},hasCover(){return!!this.safeCoverUrl},coverStyle(){return this.safeCoverUrl?{backgroundImage:`url("${this.safeCoverUrl}")`}:null}},methods:{submitStarter(){this.canStart&&this.$emit("start",this.starterText.trim())},onStarterKeydown(e){e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),this.submitStarter())},onInputFocus(){this.launchPhase==="idle"&&(this.inputFocused=!0,this.$nextTick(()=>this.autosize()))},onInputBlur(){this.launchPhase==="idle"&&(this.inputFocused=!1,this.$nextTick(()=>this.autosize()))},autosize(){const e=this.$refs.starterInput;if(!e||e.clientWidth<40)return;e.style.height="auto",e.style.minHeight="0px";const t=e.scrollHeight;e.style.minHeight="",e.style.height=t>62?`${Math.min(t,120)}px`:""},async runLaunch(){const e=this.$refs.starterForm,t=typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;if(!e||t){this.launchPhase="fade",await this.wait(t?120:0),this.finishLaunch();return}this.launchPhase="fade",await this.wait(320);const n=e.getBoundingClientRect();this.launchPhase="slide",await this.$nextTick();const r=e.getBoundingClientRect(),i=n.left-r.left,s=n.top-r.top;e.style.transition="none",e.style.transform=`translate(${i}px, ${s}px)`,e.offsetWidth,e.style.transition="transform 0.44s cubic-bezier(0.32, 0.72, 0, 1)",e.style.transform="translate(0, 0)";const o=()=>{e.removeEventListener("transitionend",o),this.finishLaunch()};e.addEventListener("transitionend",o),this.wait(520).then(()=>this.finishLaunch())},finishLaunch(){this.launchDone||(this.launchDone=!0,this.$emit("launched"))},wait(e){return new Promise(t=>window.setTimeout(t,e))},iconPath(e){return Zr[e]||Zr.link},isExternalLink(e){const t=e==null?void 0:e.url;return!!t&&!t.startsWith("#")},safeIconUrl(e){return Gr(e==null?void 0:e.icon_url)},iconUrlStyle(e){const t=this.safeIconUrl(e);return t?{"--icon-url":`url("${t}")`}:null},renderPreview(e){return Mo(e)},avatarComponent(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.type)==="agent_human"?"HumanAvatar":"AIAvatar"},avatarProps(e){const t=e==null?void 0:e.author;return(t==null?void 0:t.type)==="agent_human"?{size:40,name:t.name||"",avatarUrl:t.avatar_url||null}:{size:40,name:(t==null?void 0:t.name)||"",imageUrl:(t==null?void 0:t.avatar_url)||null}},isDefaultAvatar(e){const t=e==null?void 0:e.author;return!(t!=null&&t.avatar_url||t!=null&&t.name)},avatarWrapperClass(e){return this.isDefaultAvatar(e)&&!(e!=null&&e.unread)?"wm-onb__avatar--muted":null},senderLabel(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.name)||""},formatTs(e){if(!e)return"";const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=Bt(this.wmLocale()),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});if(r.getTime()-t.getTime()<7*864e5){const o=t.toLocaleDateString(n,{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return t.toLocaleDateString(n,{day:"2-digit",month:"2-digit"})}}},Au=["aria-label"],xu={key:1,class:"wm-onb__hero-deco",width:"180",height:"180",viewBox:"0 0 180 180",fill:"none","aria-hidden":"true"},Tu={class:"wm-onb__hero-text"},Mu={class:"wm-onb__hero-default"},Eu={class:"wm-onb__title"},Ou={class:"wm-onb__sub"},Ru={key:0,class:"wm-onb__welcome"},Iu={key:0,class:"wm-onb__alertList"},Lu=["onClick"],Pu={key:0,class:"wm-onb__defaultAvatar"},Bu=["aria-label"],Fu={class:"wm-onb__alert-body"},Du={class:"wm-onb__alert-title"},Nu={class:"wm-onb__alert-preview"},Hu={key:0,class:"wm-onb__alert-sender"},Uu=["innerHTML"],ju={class:"wm-onb__alert-meta"},Vu={key:0,class:"wm-onb__alert-time"},Ku={class:"wm-onb__alert-resume"},zu={class:"wm-onb__actions"},Wu=["onClick"],$u={class:"wm-onb__btn-icon"},qu=["aria-label"],Gu={key:1,width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.9","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},Yu=["d"],Ju={class:"wm-onb__btn-label"},Xu={key:0,class:"wm-onb__btn-trail",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},Qu={class:"wm-onb__btn-icon"},Zu={width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},ed=["d"],td={class:"wm-onb__btn-label"},nd={class:"wm-onb__btn-count"},sd=["placeholder","disabled","aria-label"],rd=["disabled","aria-label"],id={key:0,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},od={key:1,class:"wm-onb__starter-spinner","aria-hidden":"true"};function ad(e,t,n,r,i,s){const o=ve("AIAvatar");return h(),p("div",{class:te(["wm-onb",{"wm-onb--launching":i.launchPhase!=="idle","wm-onb--sliding":i.launchPhase==="slide","wm-onb--focused":i.inputFocused,"wm-onb--typing":s.typing}])},[u("div",{class:te(["wm-onb__hero",{"wm-onb__hero--cover":s.hasCover}])},[s.hasCover?(h(),p("div",{key:0,class:"wm-onb__cover",style:Ce(s.coverStyle),role:"img","aria-label":s.heroTitle},null,12,Au)):F("",!0),s.hasCover?F("",!0):(h(),p("svg",xu,[...t[7]||(t[7]=[u("circle",{cx:"170",cy:"10",r:"105",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.35"},null,-1),u("circle",{cx:"170",cy:"10",r:"72",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.5"},null,-1),u("circle",{cx:"152",cy:"34",r:"2.5",fill:"#5B5FEF",opacity:"0.65"},null,-1)])])),pe(o,{size:52,"image-url":n.defaultIconUrl},null,8,["image-url"]),u("div",Tu,[u("div",Mu,[u("div",Eu,R(s.heroTitle),1),u("div",Ou,R(s.heroSub),1)]),n.welcomeMessage?(h(),p("div",Ru,R(n.welcomeMessage),1)):F("",!0)])],2),s.unreadThreads.length?(h(),p("div",Iu,[(h(!0),p(Z,null,Se(s.unreadThreads,a=>(h(),p("button",{key:a.id,type:"button",class:"wm-onb__alert",onClick:l=>e.$emit("resume",a)},[u("span",{class:te(["wm-onb__alert-avatar",s.avatarWrapperClass(a)])},[s.isDefaultAvatar(a)?(h(),p("span",Pu,[...t[8]||(t[8]=[u("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})],-1)])])):(h(),fe(qs(s.avatarComponent(a)),Xs({key:1,ref_for:!0},s.avatarProps(a)),null,16)),u("span",{class:"wm-onb__alert-dot","aria-label":s.t("onboarding.unread")},null,8,Bu)],2),u("span",Fu,[u("span",Du,R(a.title),1),u("span",Nu,[s.senderLabel(a)?(h(),p("span",Hu,R(s.senderLabel(a))+" · ",1)):F("",!0),u("span",{innerHTML:s.renderPreview(a.preview)},null,8,Uu)])]),u("span",ju,[s.formatTs(a._ts)?(h(),p("span",Vu,R(s.formatTs(a._ts)),1)):F("",!0),u("span",Ku,R(s.t("onboarding.resume")),1)])],8,Lu))),128))])):F("",!0),u("div",zu,[(h(!0),p(Z,null,Se(n.quickLinks,(a,l)=>(h(),p("button",{key:"ql-"+l,type:"button",class:"wm-onb__btn",onClick:d=>e.$emit("select",a)},[u("span",$u,[s.safeIconUrl(a)?(h(),p("span",{key:0,class:"wm-onb__btn-iconImg",style:Ce(s.iconUrlStyle(a)),role:"img","aria-label":a.label||""},null,12,qu)):(h(),p("svg",Gu,[u("path",{d:s.iconPath(a.icon)},null,8,Yu)]))]),u("span",Ju,R(a.label),1),s.isExternalLink(a)?(h(),p("svg",Xu,[...t[9]||(t[9]=[u("path",{d:"M7 17L17 7M9 7h8v8"},null,-1)])])):F("",!0)],8,Wu))),128)),n.openThreads.length?(h(),p("button",{key:0,type:"button",class:"wm-onb__btn",onClick:t[0]||(t[0]=a=>e.$emit("view-history"))},[u("span",Qu,[(h(),p("svg",Zu,[u("path",{d:s.iconPath("chat")},null,8,ed)]))]),u("span",td,R(s.t("onboarding.allConversations")),1),u("span",nd,R(n.openThreads.length),1),t[10]||(t[10]=u("svg",{class:"wm-onb__btn-trail",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M9 18l6-6-6-6"})],-1))])):F("",!0),u("form",{ref:"starterForm",class:te(["wm-onb__starter",{"is-active":!!i.starterText.trim(),"is-expanded":i.inputFocused,"wm-onb__starter--toBottom":i.launchPhase==="slide"}]),onSubmit:t[6]||(t[6]=We((...a)=>s.submitStarter&&s.submitStarter(...a),["prevent"]))},[st(u("textarea",{ref:"starterInput","onUpdate:modelValue":t[1]||(t[1]=a=>i.starterText=a),class:"wm-onb__starter-input",rows:"1",placeholder:s.t("onboarding.starterPlaceholder"),disabled:n.busy,"aria-label":s.t("onboarding.start"),enterkeyhint:"send",onKeydown:t[2]||(t[2]=(...a)=>s.onStarterKeydown&&s.onStarterKeydown(...a)),onInput:t[3]||(t[3]=(...a)=>s.autosize&&s.autosize(...a)),onFocus:t[4]||(t[4]=(...a)=>s.onInputFocus&&s.onInputFocus(...a)),onBlur:t[5]||(t[5]=(...a)=>s.onInputBlur&&s.onInputBlur(...a))},null,40,sd),[[kt,i.starterText]]),u("button",{type:"submit",class:te(["wm-onb__starter-send",{"is-empty":!s.canStart}]),disabled:n.busy||!s.canStart,"aria-label":s.t("composer.send")},[n.busy?(h(),p("span",od)):(h(),p("svg",id,[...t[11]||(t[11]=[u("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"},null,-1)])]))],10,rd)],34)])],2)}const ld=be(Su,[["render",ad],["__scopeId","data-v-cfaffcfa"]]),cd={name:"WmHistory",components:{AIAvatar:Sn,HumanAvatar:rs},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{threads:{type:Array,default:()=>[]}},emits:["resume"],data(){return{query:""}},computed:{filteredThreads(){const e=this.query.trim().toLowerCase();return e?this.threads.filter(t=>(t.title||"").toLowerCase().includes(e)||(t.preview||"").toLowerCase().includes(e)):this.threads}},methods:{renderPreview(e){return Mo(e)},avatarComponent(e){var t;return((t=e==null?void 0:e.author)==null?void 0:t.type)==="agent_human"?"HumanAvatar":"AIAvatar"},avatarProps(e){const t=e==null?void 0:e.author;return(t==null?void 0:t.type)==="agent_human"?{size:40,name:t.name||"",avatarUrl:t.avatar_url||null}:{size:40,name:(t==null?void 0:t.name)||"",imageUrl:(t==null?void 0:t.avatar_url)||null}},isDefaultAvatar(e){const t=e==null?void 0:e.author;return!(t!=null&&t.avatar_url||t!=null&&t.name)},avatarWrapperClass(e){return this.isDefaultAvatar(e)&&!(e!=null&&e.unread)?"wm-hist__avatar--muted":null},formatTs(e){if(!e)return"";const t=new Date(e);if(Number.isNaN(t.getTime()))return"";const n=Bt(this.wmLocale()),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"});if(r.getTime()-t.getTime()<7*864e5){const o=t.toLocaleDateString(n,{weekday:"short"});return o.charAt(0).toUpperCase()+o.slice(1)}return t.toLocaleDateString(n,{day:"2-digit",month:"2-digit"})}}},ud={class:"wm-hist"},dd={class:"wm-hist__search"},fd=["placeholder","aria-label"],hd={class:"wm-hist__list"},md=["onClick"],gd={key:0,class:"wm-hist__defaultAvatar"},pd=["aria-label"],_d={class:"wm-hist__thread-body"},yd={class:"wm-hist__thread-title"},vd=["innerHTML"],bd={class:"wm-hist__thread-meta"},wd={key:0,class:"wm-hist__thread-time"},kd={key:0,class:"wm-hist__empty"};function Cd(e,t,n,r,i,s){return h(),p("div",ud,[u("div",dd,[t[1]||(t[1]=u("span",{class:"wm-hist__searchIcon"},[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),st(u("input",{"onUpdate:modelValue":t[0]||(t[0]=o=>i.query=o),type:"text",placeholder:s.t("onboarding.search"),"aria-label":s.t("onboarding.search")},null,8,fd),[[kt,i.query]])]),u("div",hd,[(h(!0),p(Z,null,Se(s.filteredThreads,o=>(h(),p("button",{key:o.id,type:"button",class:te(["wm-hist__thread",{"wm-hist__thread--unread":o.unread}]),onClick:a=>e.$emit("resume",o)},[u("span",{class:te(["wm-hist__thread-avatar",s.avatarWrapperClass(o)])},[s.isDefaultAvatar(o)?(h(),p("span",gd,[...t[2]||(t[2]=[u("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})],-1)])])):(h(),fe(qs(s.avatarComponent(o)),Xs({key:1,ref_for:!0},s.avatarProps(o)),null,16)),o.unread?(h(),p("span",{key:2,class:"wm-hist__thread-dot","aria-label":s.t("onboarding.unread")},null,8,pd)):F("",!0)],2),u("span",_d,[u("span",yd,R(o.title),1),u("span",{class:"wm-hist__thread-preview",innerHTML:s.renderPreview(o.preview)},null,8,vd)]),u("span",bd,[s.formatTs(o._ts)?(h(),p("span",wd,R(s.formatTs(o._ts)),1)):F("",!0),t[3]||(t[3]=u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-hist__thread-chev","aria-hidden":"true"},[u("path",{d:"M5 12h14M13 5l7 7-7 7"})],-1))])],10,md))),128)),s.filteredThreads.length?F("",!0):(h(),p("div",kd,R(i.query?s.t("onboarding.noResults",{query:i.query}):s.t("onboarding.noConversations")),1))])])}const Sd=be(cd,[["render",Cd],["__scopeId","data-v-6bf35ef1"]]);function Ad(e){return typeof e!="string"?"":e.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*]+)\*\*/g,"$1").replace(new RegExp("(?<!\\*)\\*([^*]+)\\*(?!\\*)","g"),"$1").replace(/__([^_]+)__/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\s+/g," ").trim()}const xd={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return Ad(this.detail)}}},Td={class:"wm-result__icon","aria-hidden":"true"},Md={key:0,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.8","stroke-linecap":"round","stroke-linejoin":"round"},Ed={key:1,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.6","stroke-linecap":"round","stroke-linejoin":"round"},Od={key:2,width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round"},Rd={key:3,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round"},Id={class:"wm-result__body"},Ld={class:"wm-result__label"},Pd={class:"wm-result__detail"};function Bd(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-result",`wm-result--${n.state}`])},[u("span",Td,[n.state==="success"?(h(),p("svg",Md,[...t[0]||(t[0]=[u("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):n.state==="rejected"?(h(),p("svg",Ed,[...t[1]||(t[1]=[u("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):n.state==="awaiting"?(h(),p("svg",Od,[...t[2]||(t[2]=[u("circle",{cx:"12",cy:"12",r:"10"},null,-1),u("polyline",{points:"12 7 12 12 15 14"},null,-1)])])):(h(),p("svg",Rd,[...t[3]||(t[3]=[u("path",{d:"M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"},null,-1),u("line",{x1:"12",y1:"9",x2:"12",y2:"13"},null,-1),u("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"},null,-1)])]))]),u("span",Id,[u("span",Ld,R(n.label),1),s.detailText?(h(),p(Z,{key:0},[t[4]||(t[4]=u("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),u("span",Pd,R(s.detailText),1)],64)):F("",!0)])],2)}const Fd=be(xd,[["render",Bd],["__scopeId","data-v-7284acd0"]]),Dd={name:"WmArtifactFormResponse",inject:{t:{default:()=>Ee()}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]}}},Nd={class:"wm-art wm-art--formResponse"},Hd={class:"wm-art__head"},Ud={class:"wm-art__title"},jd={class:"wm-art__badge wm-art__badge--success"},Vd={class:"wm-art__body"},Kd={class:"wm-art__fieldLabel"};function zd(e,t,n,r,i,s){return h(),p("div",Nd,[u("div",Hd,[u("div",Ud,R(n.data.title||s.t("form.title")),1),u("span",jd,[t[0]||(t[0]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("polyline",{points:"20 6 9 17 4 12"})],-1)),ns(" "+R(s.t("form.sent")),1)])]),u("div",Vd,[(h(!0),p(Z,null,Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",Kd,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128))])])}const Wd=be(Dd,[["render",zd],["__scopeId","data-v-713aecf1"]]),$d={name:"WmArtifactInfoCard",props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]},hasBody(){var e;return!!((e=this.data)!=null&&e.body)||this.fields.length>0}}},qd={class:"wm-art wm-art--infoCard"},Gd={key:0,class:"wm-art__image"},Yd=["src","alt"],Jd={class:"wm-art__head"},Xd={class:"wm-art__headMain"},Qd={class:"wm-art__title"},Zd={key:0,class:"wm-art__subtitle"},ef={key:1,class:"wm-art__body"},tf={key:0,class:"wm-art__text"},nf={class:"wm-art__fieldLabel"};function sf(e,t,n,r,i,s){return h(),p("div",qd,[n.data.image_url?(h(),p("figure",Gd,[u("img",{src:n.data.image_url,alt:n.data.title||"",loading:"lazy"},null,8,Yd)])):F("",!0),u("div",Jd,[u("div",Xd,[u("div",Qd,R(n.data.title),1),n.data.subtitle?(h(),p("div",Zd,R(n.data.subtitle),1)):F("",!0)]),n.data.badge&&n.data.badge.label?(h(),p("span",{key:0,class:te(["wm-art__badge",`wm-art__badge--${n.data.badge.tone||"neutral"}`])},R(n.data.badge.label),3)):F("",!0)]),s.hasBody?(h(),p("div",ef,[n.data.body?(h(),p("div",tf,R(n.data.body),1)):F("",!0),s.fields.length?(h(!0),p(Z,{key:1},Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",nf,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128)):F("",!0)])):F("",!0)])}const rf=be($d,[["render",sf],["__scopeId","data-v-7eae0e4a"]]);function of(e,t,n){if(!e)return"";const r=new Date(e);if(Number.isNaN(r.getTime()))return e;const i=r.toLocaleDateString(t,{day:"numeric",month:"long",year:"numeric"}),s=r.toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit"});return`${i}${n}${s}`}const af={name:"WmArtifactTicket",inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]},formattedDate(){var e;return of((e=this.data)==null?void 0:e.created_at,Bt(this.wmLocale()),this.t("ticket.dateAt"))}},methods:{isPriority(e){return/priorit|^prio$/i.test(String(e||"").trim())},isDate(e){return/date|échéanc|echeanc|deadline|due|créé|cree/i.test(String(e||"").trim())},priorityLevel(e){const t=String(e||"").toLowerCase();return/high|haute|élev|elev|critic|critiq|urgent/.test(t)?3:/low|basse|faible|minor/.test(t)?1:2}}},lf={class:"wm-art wm-art--ticket"},cf={class:"wm-art__head wm-tk__head"},uf={class:"wm-art__title wm-tk__title"},df={class:"wm-tk__sub"},ff={class:"wm-tk__ref"},hf={key:0,class:"wm-tk__text"},mf={key:0,class:"wm-art__body"},gf={class:"wm-art__fieldLabel"},pf=["data-level"],_f={key:1,class:"wm-tk__date",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},yf={key:1,class:"wm-art__footer wm-tk__footer"};function vf(e,t,n,r,i,s){return h(),p("div",lf,[u("div",cf,[u("div",uf,R(n.data.title),1),u("div",df,[u("div",ff,[t[0]||(t[0]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M20 12a2 2 0 0 1 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v4a2 2 0 0 1 0 4v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 1-2-2z"}),u("path",{d:"M13 5v2M13 17v2M13 11v2"})],-1)),u("span",null,R(n.data.reference),1)]),u("span",{class:te(["wm-art__badge","wm-tk__badge",`wm-art__badge--${n.data.status.tone||"neutral"}`])},[t[1]||(t[1]=u("span",{class:"wm-tk__dot","aria-hidden":"true"},null,-1)),ns(" "+R(n.data.status.label),1)],2)]),n.data.body?(h(),p("div",hf,R(n.data.body),1)):F("",!0)]),s.fields.length?(h(),p("div",mf,[(h(!0),p(Z,null,Se(s.fields,(o,a)=>(h(),p("div",{key:a,class:"wm-art__field"},[u("div",gf,R(o.label),1),u("div",{class:te(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},[s.isPriority(o.label)?(h(),p("svg",{key:0,class:"wm-tk__prio","data-level":s.priorityLevel(o.value),width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true"},[...t[2]||(t[2]=[u("rect",{x:"1",y:"8",width:"2",height:"3",rx:"0.5"},null,-1),u("rect",{x:"5",y:"5",width:"2",height:"6",rx:"0.5"},null,-1),u("rect",{x:"9",y:"2",width:"2",height:"9",rx:"0.5"},null,-1)])],8,pf)):s.isDate(o.label)?(h(),p("svg",_f,[...t[3]||(t[3]=[u("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"},null,-1),u("path",{d:"M16 2v4M8 2v4M3 10h18"},null,-1)])])):F("",!0),u("span",null,R(o.value),1)],2)]))),128))])):F("",!0),n.data.created_at?(h(),p("div",yf,[t[4]||(t[4]=u("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),u("path",{d:"M16 2v4M8 2v4M3 10h18"})],-1)),u("span",null,R(s.formattedDate),1)])):F("",!0)])}const bf=be(af,[["render",vf],["__scopeId","data-v-5f30c914"]]),wf={form_response:Wd,info_card:rf,ticket:bf},kf={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const e=(t=this.artifact)==null?void 0:t.kind;return e&&wf[e]||null}}};function Cf(e,t,n,r,i,s){return s.component?(h(),fe(qs(s.component),{key:0,data:n.artifact.data},null,8,["data"])):F("",!0)}const Sf=be(kf,[["render",Cf]]),Af={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null},t:{default:()=>Ee()}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var n,r;const e=(n=this.attachment)==null?void 0:n.type;if(e)return e;const t=(((r=this.attachment)==null?void 0:r.mime_type)||"").toLowerCase();return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"file"},displayName(){var e,t,n;return((t=(e=this.attachment)==null?void 0:e.metadata)==null?void 0:t.name)||((n=this.attachment)==null?void 0:n.name)||this.guessNameFromPath()||this.t("attachment.fallbackName")},safeHref(){const e=String(this.url||"").trim();return/^(https?:\/\/|blob:|data:image\/)/i.test(e)?e:"#"},sizeLabel(){var t;const e=(t=this.attachment)==null?void 0:t.size_bytes;return e?e<1024?this.t("attachment.bytes",{size:e}):e<1024*1024?this.t("attachment.kilobytes",{size:(e/1024).toFixed(0)}):this.t("attachment.megabytes",{size:(e/(1024*1024)).toFixed(1)}):""}},watch:{"attachment.path":{handler(){this.refresh()},immediate:!0}},methods:{guessNameFromPath(){var n;return((((n=this.attachment)==null?void 0:n.path)||"").split("/").pop()||"").replace(/^[0-9a-f-]{8,}-/,"")},async refresh(){var e;if(!(!((e=this.attachment)!=null&&e.path)||!this.signAttachmentFn)){this.loading=!0;try{this.url=await this.signAttachmentFn(this.attachment.path)}finally{this.loading=!1}}},onFileClick(e){this.safeHref==="#"&&e.preventDefault()}}},xf=["href"],Tf=["src","alt"],Mf=["src"],Ef=["src"],Of=["href","download"],Rf={class:"wm-att__main"},If={class:"wm-att__name"},Lf={key:0,class:"wm-att__meta"},Pf={key:0,class:"wm-att__spin","aria-hidden":"true"};function Bf(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-att",["wm-att--"+(s.kind||"file")]])},[s.kind==="image"&&i.url?(h(),p("a",{key:0,href:s.safeHref,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[u("img",{src:i.url,alt:s.displayName,loading:"lazy"},null,8,Tf)],8,xf)):s.kind==="audio"&&i.url?(h(),p("audio",{key:1,src:i.url,controls:"",preload:"metadata"},null,8,Mf)):s.kind==="video"&&i.url?(h(),p("video",{key:2,src:i.url,controls:"",playsinline:"",preload:"auto"},null,8,Ef)):(h(),p("a",{key:3,class:"wm-att__file",href:s.safeHref,download:s.displayName,target:"_blank",rel:"noopener",onClick:t[0]||(t[0]=(...o)=>s.onFileClick&&s.onFileClick(...o))},[t[1]||(t[1]=u("span",{class:"wm-att__icon"},[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),u("path",{d:"M14 2v6h6"})])],-1)),u("span",Rf,[u("span",If,R(s.displayName),1),s.sizeLabel?(h(),p("span",Lf,R(s.sizeLabel),1)):F("",!0)]),i.loading?(h(),p("span",Pf)):F("",!0)],8,Of))],2)}const Ff=be(Af,[["render",Bf],["__scopeId","data-v-b207a8bd"]]),Df={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return Sc(this.text)}}},Nf=["innerHTML"];function Hf(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-bubble","wm-bubble--"+n.role])},[Fa(e.$slots,"default",{},()=>[u("span",{innerHTML:s.rendered},null,8,Nf)])],2)}const Uf=be(Df,[["render",Hf],["__scopeId","data-v-7ab13147"]]),jf={name:"WmTyping"},Vf={class:"wm-typing"};function Kf(e,t,n,r,i,s){return h(),p("div",Vf,[...t[0]||(t[0]=[u("span",{style:{"animation-delay":"0s"}},null,-1),u("span",{style:{"animation-delay":"0.2s"}},null,-1),u("span",{style:{"animation-delay":"0.4s"}},null,-1)])])}const zf=be(jf,[["render",Kf],["__scopeId","data-v-df2447fd"]]);function Ot(e){return e?e.client_msg_id||e.id:""}const Wf={transferred_to_human:"system.transferredToHuman",assigned:"system.assigned",unassigned:"system.unassigned",resolved:"system.resolved",closed:"system.closed",reopened:"system.reopened",idle:"system.idle"},$f=80,qf=200,Gf={name:"WmMessageList",components:{AIAvatar:Sn,HumanAvatar:rs,Bubble:Uf,Typing:zf,ActionResult:Fd,AttachmentPreview:Ff,ArtifactRenderer:Sf},inject:{t:{default:()=>Ee()},wmLocale:{default:()=>()=>"fr"}},props:{messages:{type:Array,default:()=>[]},streamingActive:{type:Boolean,default:!1},dateLabel:{type:String,default:""},conversationId:{type:[String,Number],default:null},loadingMore:{type:Boolean,default:!1},hasMore:{type:Boolean,default:!1},unreadAnchorId:{type:Number,default:null},unreadBoundaryTs:{type:String,default:""},aiAgentName:{type:String,default:""},aiAgentAvatarUrl:{type:String,default:null}},emits:["load-more"],data(){return{silentFades:!1,widthByKey:Object.freeze({}),showScrollDown:!1,pressedItemKey:null}},computed:{historyExhausted(){return!this.hasMore&&!this.loadingMore&&this.messages.length>=20},groups(){var n,r,i,s,o;const e=[];for(const a of this.messages){if((n=a==null?void 0:a.metadata)!=null&&n.resolution_request)continue;const l=this.roleOf(a);if(l==="system"){if(((r=a==null?void 0:a.payload)==null?void 0:r.event)==="action_admin_pending"){const m=e[e.length-1];m&&m.role==="ai"?m.messages.push(a):e.push({key:`g-${Ot(a)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[a],items:[]});continue}e.push({key:`sys-${Ot(a)}`,role:l,messages:[a],items:[],systemLabel:this.systemLabel(a)});continue}const d=e[e.length-1];d&&d.role===l&&(l==="ai"||d.agentName===(((i=a==null?void 0:a.author)==null?void 0:i.name)||""))?d.messages.push(a):e.push({key:`g-${Ot(a)}`,role:l,agentName:((s=a==null?void 0:a.author)==null?void 0:s.name)||"",agentAvatarUrl:((o=a==null?void 0:a.author)==null?void 0:o.avatar_url)||null,messages:[a],items:[]})}for(const a of e){if(a.role==="system")continue;const l=[];for(const d of a.messages)for(const c of this.itemsOf(d))l.push(c);a.items=l}const t=[];for(const a of e){if(a.role!=="system"&&!a.items.length)continue;const l=t[t.length-1];if(l&&l.role!=="system"&&l.role===a.role&&(a.role==="ai"||l.agentName===a.agentName)){l.messages.push(...a.messages),l.items.push(...a.items);continue}t.push(a)}for(const a of t)a.role!=="system"&&(a.key=this.stableGroupKey(a.messages));return t},unreadGroupKey(){if(this.unreadAnchorId==null)return null;const e=this.unreadAnchorId,t=this.unreadBoundaryTs;for(const n of this.groups){if(n.role==="user"||n.role==="system"||!n.items.length)continue;const r=n.messages[0];if(!r)continue;const i=ht(r.id);if(i!=null&&!(i<=e)&&!(t&&r.created_at&&r.created_at>t))return n.key}return null}},watch:{messages:{handler:"snapshotAndRestore",deep:!0},conversationId(e,t){e!==t&&(this._groupIdByMsgKey=null,this.silentFades=!1)},loadingMore(e){e||(this._pendingLoadMore=!1),e&&(this.silentFades=!0),this.snapshotAndRestore()},streamingActive:"snapshotAndRestore"},mounted(){this._lastSeenConvId=this.conversationId,this.scrollToBottom(),this._measureFrame=null,this._ro=new ResizeObserver(()=>this.scheduleMeasure()),this.$refs.scrollEl&&this._ro.observe(this.$refs.scrollEl),this.$nextTick(()=>this.measureRows())},beforeUnmount(){var e;(e=this._ro)==null||e.disconnect(),this._measureFrame&&cancelAnimationFrame(this._measureFrame),this._pinFrame&&cancelAnimationFrame(this._pinFrame),this._pressTimer&&clearTimeout(this._pressTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:Ot,stableGroupKey(e){this._groupIdByMsgKey||(this._groupIdByMsgKey=new Map,this._groupIdCounter=0);const t=this._groupIdByMsgKey;let n=null;for(const r of e){const i=Ot(r);if(i&&t.has(i)){n=t.get(i);break}}n==null&&(n=++this._groupIdCounter);for(const r of e){const i=Ot(r);i&&t.set(i,n)}return`g-${n}`},isAtBottom(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=$f},onScroll(){const e=this.$refs.scrollEl;e&&(this.showScrollDown=!this.isAtBottom(e),!(this.loadingMore||!this.hasMore)&&(this._pendingLoadMore||e.scrollTop<=qf&&(this._pendingLoadMore=!0,this.$emit("load-more"))))},snapshotAndRestore(){const e=this.$refs.scrollEl;if(!e||this._scrollSnap)return;const t=this._lastSeenConvId!==this.conversationId;this._lastSeenConvId=this.conversationId;const n=this.isAtBottom(e);let r=null;if(!t&&!n){const s=this.pickAnchor(e);if(s!=null&&s.rowKey){const o=this.findRowByKey(e,s.rowKey);if(o){const a=e.getBoundingClientRect().top;r={rowKey:s.rowKey,relY:o.getBoundingClientRect().top-a}}}}const i={forceBottom:t,wasPinned:n,anchor:r};this._scrollSnap=i,this.$nextTick(()=>{if(this._scrollSnap=null,i.forceBottom||i.wasPinned){e.scrollTop=e.scrollHeight;return}if(!i.anchor)return;const s=()=>{const o=i.anchor,a=this.findRowByKey(e,o.rowKey);if(!a)return;const d=a.getBoundingClientRect().top-e.getBoundingClientRect().top-o.relY;Math.abs(d)>.5&&(e.scrollTop+=d)};s(),requestAnimationFrame(()=>{s(),requestAnimationFrame(s)})})},pickAnchor(e){const t=e.getBoundingClientRect().top,n=e.querySelectorAll(".wm-list__row[data-row-key]");let r=null;for(const i of n)if(r||(r=i),i.getBoundingClientRect().bottom>=t)return{rowKey:i.dataset.rowKey};return r?{rowKey:r.dataset.rowKey}:null},findRowByKey(e,t){if(!t)return null;const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&");return e.querySelector(`.wm-list__row[data-row-key="${n}"]`)},roleOf(e){var n,r;if((e==null?void 0:e.type)==="system"||((n=e==null?void 0:e.payload)==null?void 0:n.type)==="system")return"system";const t=(r=e==null?void 0:e.author)==null?void 0:r.type;return t==="user"?"user":t==="agent_human"?"human":"ai"},roleLabel(e){if(e.role==="human")return e.agentName||this.t("common.agent");const t=this.t("common.aiAssistant");return this.aiAgentName?`${this.aiAgentName} • ${t}`:t},itemsOf(e){var t;if(!e)return[];if(e.type==="system"&&((t=e==null?void 0:e.payload)==null?void 0:t.event)==="action_admin_pending")return[{message:e,partKey:"main",renderAs:"admin-pending",kind:{top:"bubble",bottom:"bubble"}}];if(e.type==="action"&&e.payload&&e.payload.state!=="pending"){const n=[{message:e,partKey:"main",renderAs:"action",kind:{top:"bubble",bottom:"bubble"}}];return this.actionArtifact(e)&&n.push({message:e,partKey:"artifact",renderAs:"artifact-of-action",kind:{top:"card",bottom:"card"}}),n}return this.artifactOf(e)?[{message:e,partKey:"main",renderAs:"artifact",kind:{top:"card",bottom:"card"}}]:e.text_md||this.attachmentsOf(e).length?[{message:e,partKey:"main",renderAs:"bubble",kind:{top:"bubble",bottom:"bubble"}}]:[]},cornersFor(e,t){var V,re,ce;const n=e.items,r=(V=n[t])==null?void 0:V.kind,i=(re=n[t-1])==null?void 0:re.kind,s=(ce=n[t+1])==null?void 0:ce.kind,o=e.role==="user",a=14,l=4,d=i==null?void 0:i.bottom,c=s==null?void 0:s.top,m=this.widthByKey[this.rowKeyOf(e,t)],C=this.widthByKey[this.rowKeyOf(e,t-1)],b=this.widthByKey[this.rowKeyOf(e,t+1)],K=.5,S=(_e,we,G)=>_e!=null&&m!=null?_e+K>=m:we===G||we==="card"&&G==="bubble";let J=a,U=a,$=a,ne=a;return o?(d&&(U=l),(c||!s)&&($=l),d&&S(C,d,r==null?void 0:r.top)&&(J=l),c&&S(b,c,r==null?void 0:r.bottom)&&(ne=l)):(d&&(J=l),(c||!s)&&(ne=l),d&&S(C,d,r==null?void 0:r.top)&&(U=l),c&&S(b,c,r==null?void 0:r.bottom)&&($=l)),{tl:J,tr:U,br:$,bl:ne}},mosaicGridStyle(e){return!e||e<2?null:{"grid-template-columns":`repeat(${Math.min(e,4)}, 1fr)`}},mosaicCornerStyle(e,t,n){if(!t||t<2)return null;const r=Math.min(t,4),i=Math.floor(e/r),s=e%r,o=s>0,a=s<r-1&&e+1<t,l=i>0,d=e+r<t,c="4px",m={};return(o||l)&&(m["--wm-r-tl"]=c),(a||l)&&(m["--wm-r-tr"]=c),(o||d)&&(m["--wm-r-bl"]=c),(a||d)&&(m["--wm-r-br"]=c),n&&(m["--wm-r-tl"]=c,m["--wm-r-tr"]=c),Object.keys(m).length?m:null},cornersStyle(e,t){if(e.items.length<2)return null;const n=this.cornersFor(e,t);return{"--wm-r-tl":`${n.tl}px`,"--wm-r-tr":`${n.tr}px`,"--wm-r-br":`${n.br}px`,"--wm-r-bl":`${n.bl}px`}},rowKeyOf(e,t){var r;const n=(r=e==null?void 0:e.items)==null?void 0:r[t];return n?`${Ot(n.message)}-${n.partKey}`:""},scheduleMeasure(){this._measureFrame||(this._measureFrame=requestAnimationFrame(()=>{this._measureFrame=null,this.measureRows()}))},measureRows(){const e=this.$refs.scrollEl;if(!e)return;const t={};for(const s of e.querySelectorAll(".wm-list__row[data-row-key]")){const o=s.dataset.rowKey;if(!o)continue;const a=s.querySelector(".wm-bubble, .wm-result, .wm-art, .wm-list__body");if(!a)continue;const l=a.getBoundingClientRect().width;l>0&&(t[o]=l)}const n=this.widthByKey,r=Object.keys(n),i=Object.keys(t);if(r.length===i.length){let s=!0;for(const o of i)if(Math.abs((n[o]??0)-t[o])>.5){s=!1;break}if(s)return}this.widthByKey=Object.freeze(t)},onPressStart(e){this.onPressEnd(),this._pressTimer=setTimeout(()=>{this._pressTimer=null,this.pressedItemKey=e},400)},onPressEnd(){this._pressTimer&&(clearTimeout(this._pressTimer),this._pressTimer=null),this.pressedItemKey!==null&&(this.pressedItemKey=null)},timeOf(e){if(!(e!=null&&e.created_at))return"";try{return Bs(new Date(e.created_at),Bt(this.wmLocale()))}catch{return""}},lastTimeOf(e){const t=e.items[e.items.length-1],n=(t==null?void 0:t.message)||e.messages[e.messages.length-1];if(!(n!=null&&n.created_at))return"";try{return Bs(new Date(n.created_at),Bt(this.wmLocale()))}catch{return""}},hasTrailingOverlay(e){if(!e.messages.length)return!1;const t=e.messages[e.messages.length-1],n=e.items[e.items.length-1];return!!t&&(n==null?void 0:n.message)!==t},attachmentsOf(e){var n;const t=(n=e==null?void 0:e.payload)==null?void 0:n.attachments;return Array.isArray(t)?t:[]},artifactOf(e){var n;const t=(n=e==null?void 0:e.metadata)==null?void 0:n.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},actionLabel(e){var t;return((t=e==null?void 0:e.payload)==null?void 0:t.name)||(e==null?void 0:e.text_md)||this.t("common.action")},actionDetail(e){var n,r,i,s,o,a,l,d;const t=e==null?void 0:e.payload;if(!t)return"";if(t.state==="success")return((n=t.success)==null?void 0:n.summary)||((i=(r=t.success)==null?void 0:r.metadata)==null?void 0:i.description)||"";if(t.state==="rejected"){if((s=t.rejected)!=null&&s.reason)return t.rejected.reason;const c=(a=(o=t.rejected)==null?void 0:o.metadata)==null?void 0:a.resolution,m=typeof c=="string"&&c.startsWith("admin")?"action.rejectedByAdmin":"action.rejectedByUser";return this.t(m)}return t.state==="failure"&&(((l=t.failure)==null?void 0:l.summary)||((d=t.failure)==null?void 0:d.error))||""},actionArtifact(e){var n,r;const t=(r=(n=e==null?void 0:e.payload)==null?void 0:n.success)==null?void 0:r.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},systemLabel(e){var i,s,o;const t=(i=e==null?void 0:e.payload)==null?void 0:i.event,n=Wf[t],r=((s=e==null?void 0:e.metadata)==null?void 0:s.agent_name)||((o=e==null?void 0:e.author)==null?void 0:o.name)||this.t("messageList.anAgent");return n?this.t(n,{name:r}):(e==null?void 0:e.text_md)||this.t("messageList.conversationUpdate")},scrollToBottom(){const e=this.$refs.scrollEl;e&&(e.scrollTop=e.scrollHeight),this.showScrollDown=!1},keepPinnedToBottom(e=320){const t=this.$refs.scrollEl;if(!t)return;this._pinFrame&&cancelAnimationFrame(this._pinFrame);let n=null;const r=i=>{n===null&&(n=i),t.scrollTop=t.scrollHeight,i-n<e?this._pinFrame=requestAnimationFrame(r):this._pinFrame=null};this._pinFrame=requestAnimationFrame(r),this.showScrollDown=!1},scrollToBottomSmooth(){const e=this.$refs.scrollEl;e&&(typeof e.scrollTo=="function"?e.scrollTo({top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight,this.showScrollDown=!1)}}},Yf={class:"wm-list__wrap"},Jf={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},Xf={class:"wm-list__loadMore-lbl"},Qf={key:1,class:"wm-list__historyEnd"},Zf={key:2,class:"wm-list__sep"},eh={class:"wm-list__sep-label"},th={key:0,class:"wm-list__sep wm-list__sep--unread"},nh={class:"wm-list__sep-label wm-list__sep-label--unread"},sh={key:0,class:"wm-list__sysep"},rh={class:"wm-list__sysep-label"},ih=["data-row-key","onPointerdown"],oh={key:0,class:"wm-list__avatarSlot"},ah={key:0},lh={key:1,"aria-hidden":"true"},ch={key:2},uh={key:0},dh={key:1,"aria-hidden":"true"},fh={key:2},hh={key:3,class:"wm-list__row wm-list__row--ai fade-up"},mh={class:"wm-list__avatarSlot"},gh=["aria-label","title"];function ph(e,t,n,r,i,s){const o=ve("AIAvatar"),a=ve("HumanAvatar"),l=ve("ActionResult"),d=ve("ArtifactRenderer"),c=ve("Bubble"),m=ve("AttachmentPreview"),C=ve("Typing");return h(),p("div",Yf,[u("div",{ref:"scrollEl",class:te(["wm-list",{"wm-list--silent":i.silentFades}]),onScrollPassive:t[4]||(t[4]=(...b)=>s.onScroll&&s.onScroll(...b))},[n.loadingMore?(h(),p("div",Jf,[t[6]||(t[6]=u("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1)),u("span",Xf,R(s.t("messageList.loadingHistory")),1)])):s.historyExhausted?(h(),p("div",Qf,R(s.t("messageList.conversationStart")),1)):F("",!0),n.dateLabel?(h(),p("div",Zf,[t[7]||(t[7]=u("div",{class:"wm-list__line"},null,-1)),u("span",eh,R(n.dateLabel),1),t[8]||(t[8]=u("div",{class:"wm-list__line"},null,-1))])):F("",!0),(h(!0),p(Z,null,Se(s.groups,(b,K)=>(h(),p(Z,{key:b.key},[b.key===s.unreadGroupKey?(h(),p("div",th,[t[9]||(t[9]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1)),u("span",nh,R(s.t("messageList.unread")),1),t[10]||(t[10]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1))])):F("",!0),b.role==="system"||b.items.length?(h(),p("div",{key:1,class:te(["wm-list__group","wm-list__group--"+b.role])},[b.role==="system"?(h(),p("div",sh,[t[11]||(t[11]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),u("span",rh,R(b.systemLabel),1),t[12]||(t[12]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(h(),p(Z,{key:1},[(h(!0),p(Z,null,Se(b.items,(S,J)=>(h(),p(Z,{key:`${s.messageKey(S.message)}-${S.partKey}`},[u("div",{"data-row-key":`${s.messageKey(S.message)}-${S.partKey}`,class:te(["wm-list__row fade-up",["wm-list__row--"+b.role,{"is-pending":S.message._pending,"is-failed":S.message._failed}]]),style:Ce(s.cornersStyle(b,J)),onPointerdown:U=>s.onPressStart(`${s.messageKey(S.message)}-${S.partKey}`),onPointerup:t[0]||(t[0]=U=>s.onPressEnd()),onPointercancel:t[1]||(t[1]=U=>s.onPressEnd()),onPointerleave:t[2]||(t[2]=U=>s.onPressEnd()),onContextmenu:t[3]||(t[3]=We(()=>{},["prevent"]))},[b.role!=="user"?(h(),p("div",oh,[J===b.items.length-1?(h(),p(Z,{key:0},[b.role==="ai"?(h(),fe(o,{key:0,size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])):(h(),fe(a,{key:1,name:b.agentName,"avatar-url":b.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):F("",!0)])):F("",!0),S.renderAs==="action"?(h(),fe(l,{key:1,state:S.message.payload.state,label:s.actionLabel(S.message),detail:s.actionDetail(S.message)},null,8,["state","label","detail"])):S.renderAs==="admin-pending"?(h(),fe(l,{key:2,state:"awaiting",label:s.t("messageList.approvalRequestSent"),detail:S.message.text_md||""},null,8,["label","detail"])):S.renderAs==="artifact-of-action"?(h(),fe(d,{key:3,artifact:s.actionArtifact(S.message)},null,8,["artifact"])):S.renderAs==="artifact"?(h(),fe(d,{key:4,artifact:s.artifactOf(S.message)},null,8,["artifact"])):(h(),p("div",{key:5,class:te(["wm-list__body",{"wm-list__body--mixed":!!S.message.text_md&&s.attachmentsOf(S.message).length>0}])},[S.message.text_md?(h(),fe(c,{key:0,role:b.role,text:S.message.text_md},null,8,["role","text"])):F("",!0),s.attachmentsOf(S.message).length?(h(),p("div",{key:1,class:te(["wm-list__atts",{"wm-list__atts--align-end":b.role==="user","wm-list__atts--mosaic":s.attachmentsOf(S.message).length>=2}]),style:Ce(s.mosaicGridStyle(s.attachmentsOf(S.message).length))},[(h(!0),p(Z,null,Se(s.attachmentsOf(S.message),(U,$)=>(h(),fe(m,{key:`${s.messageKey(S.message)}-att-${$}`,attachment:U,style:Ce(s.mosaicCornerStyle($,s.attachmentsOf(S.message).length,!!S.message.text_md))},null,8,["attachment","style"]))),128))],6)):F("",!0)],2))],46,ih),J<b.items.length-1&&i.pressedItemKey===`${s.messageKey(S.message)}-${S.partKey}`&&(b.role!=="user"||s.timeOf(S.message))?(h(),p("div",{key:0,class:te(["wm-list__meta wm-list__meta--press",{"wm-list__meta--right":b.role==="user"}])},[b.role!=="user"?(h(),p("span",ah,R(s.roleLabel(b)),1)):F("",!0),b.role!=="user"&&s.timeOf(S.message)?(h(),p("span",lh,"•")):F("",!0),s.timeOf(S.message)?(h(),p("span",ch,R(s.timeOf(S.message)),1)):F("",!0)],2)):F("",!0)],64))),128)),(b.role!=="user"||s.lastTimeOf(b))&&!s.hasTrailingOverlay(b)?(h(),p("div",{key:0,class:te(["wm-list__meta",{"wm-list__meta--right":b.role==="user"}])},[b.role!=="user"?(h(),p("span",uh,R(s.roleLabel(b)),1)):F("",!0),b.role!=="user"&&s.lastTimeOf(b)?(h(),p("span",dh,"•")):F("",!0),s.lastTimeOf(b)?(h(),p("span",fh,R(s.lastTimeOf(b)),1)):F("",!0)],2)):F("",!0)],64))],2)):F("",!0)],64))),128)),n.streamingActive?(h(),p("div",hh,[u("div",mh,[pe(o,{size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])]),pe(C)])):F("",!0)],34),pe(Qs,{name:"wm-scrollDown"},{default:Xn(()=>[i.showScrollDown?(h(),p("button",{key:0,type:"button",class:"wm-list__scrollDown","aria-label":s.t("messageList.scrollToBottom"),title:s.t("messageList.scrollToBottom"),onClick:t[5]||(t[5]=(...b)=>s.scrollToBottomSmooth&&s.scrollToBottomSmooth(...b))},[...t[13]||(t[13]=[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M6 9l6 6 6-6"})],-1)])],8,gh)):F("",!0)]),_:1})])}const _h=be(Gf,[["render",ph],["__scopeId","data-v-1a6f0182"]]),jn=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",nr=typeof window<"u"&&typeof window.MediaRecorder<"u";function yh(){return nr&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(t=>{var n,r;return(r=(n=window.MediaRecorder).isTypeSupported)==null?void 0:r.call(n,t)})||""}function Eo({audio:e}){return{video:!0,audio:!!e,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:e?"include":"exclude"}}async function vh(){if(!jn)return null;let e;try{e=await navigator.mediaDevices.getDisplayMedia(Eo({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await bh(e)}catch(t){return console.error("[media] screenshot capture",t),null}finally{e.getTracks().forEach(t=>{t.stop()})}}async function bh(e){const t=document.createElement("video");t.muted=!0,t.playsInline=!0,t.srcObject=e,await t.play(),await new Promise(a=>requestAnimationFrame(a));const n=t.videoWidth||1280,r=t.videoHeight||720,i=document.createElement("canvas");i.width=n,i.height=r,i.getContext("2d").drawImage(t,0,0,n,r);const s=await new Promise((a,l)=>{i.toBlob(d=>d?a(d):l(new Error("toBlob failed")),"image/png")}),o=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([s],`capture-${o}.png`,{type:"image/png"})}async function wh(e={}){var d;if(!jn||!nr)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Eo({audio:!0}))}catch(c){return(c==null?void 0:c.name)!=="NotAllowedError"&&console.error("[media] record picker",c),null}const n=yh();let r;try{r=n?new window.MediaRecorder(t,{mimeType:n}):new window.MediaRecorder(t)}catch(c){return console.error("[media] recorder init",c),t.getTracks().forEach(m=>{m.stop()}),null}const i=[];let s=null,o=!1;r.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&i.push(c.data)}),r.addEventListener("stop",()=>{var c,m;if(s&&clearInterval(s),t.getTracks().forEach(C=>{C.stop()}),i.length){const C=r.mimeType||n||"video/webm",b=new Blob(i,{type:C}),K=/mp4/.test(C)?"mp4":"webm",S=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),J=new File([b],`ecran-${S}.${K}`,{type:C});(c=e.onfinalize)==null||c.call(e,J)}else(m=e.oncancel)==null||m.call(e)}),t.getVideoTracks().forEach(c=>{c.addEventListener("ended",()=>a(),{once:!0})});function a(){if(!o&&(o=!0,r.state!=="inactive"))try{r.stop()}catch(c){console.error("[media] recorder stop",c)}}try{r.start(1e3)}catch(c){return console.error("[media] recorder start",c),t.getTracks().forEach(m=>{m.stop()}),null}(d=e.onstart)==null||d.call(e);const l=Date.now();return s=setInterval(()=>{var c;(c=e.ontick)==null||c.call(e,Date.now()-l)},500),{stop:a,get state(){return r.state}}}const kh=[{action:"file",labelKey:"composer.attachFile",path:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"},{action:"screenshot",labelKey:"composer.screenshot",path:"M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z M12 17a4 4 0 100-8 4 4 0 000 8z"},{action:"record",labelKey:"composer.recordScreen",path:"M23 7l-7 5 7 5V7z M1 5a2 2 0 012-2h12a2 2 0 012 2v14a2 2 0 01-2 2H3a2 2 0 01-2-2V5z"}],Ch={name:"WmComposer",inject:{t:{default:()=>Ee()}},props:{modelValue:{type:String,default:""},placeholder:{type:String,default:"Écrivez votre message…"},disabled:{type:Boolean,default:!1},attachLabel:{type:String,default:"Joindre"},displayMode:{type:String,default:"floating"}},emits:["update:modelValue","send","attach","focus","blur"],data(){return{local:this.modelValue,focused:!1,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null,kbOffset:0}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},expanded(){return this.focused||!!this.local.trim()||this.attachOpen||this.recording},attachItems(){return kh.map(e=>({...e,label:this.t(e.labelKey),disabled:e.action==="screenshot"&&!jn||e.action==="record"&&(!jn||!nr)}))},recordingElapsedLabel(){const e=Math.floor(this.recordingElapsed/1e3),t=Math.floor(e/60),n=e%60;return`${t}:${n.toString().padStart(2,"0")}`}},watch:{modelValue(e){e!==this.local&&(this.local=e,this.$nextTick(()=>this.autosize()))},local(e){this.$emit("update:modelValue",e)}},mounted(){this.autosize(),this.displayMode==="sheet"&&this.setupKeyboardTracking()},beforeUnmount(){if(this.recorder)try{this.recorder.stop()}catch{}this.teardownKeyboardTracking()},methods:{focus(){const e=this.$refs.inputEl;if(!(!e||this.disabled))try{e.focus({preventScroll:!0})}catch{e.focus()}},onFocus(){this.focused=!0,this.$emit("focus"),this.$nextTick(()=>this.autosize())},onBlur(){this.focused=!1,this.$emit("blur"),this.$nextTick(()=>this.autosize())},onSubmit(){if(!this.canSend)return;const e=this.local.trim();this.local="",this.$emit("send",e),this.$nextTick(()=>this.autosize())},onKeydown(e){e.key==="Enter"&&!e.shiftKey&&!e.ctrlKey&&!e.metaKey&&!e.isComposing&&(e.preventDefault(),this.onSubmit())},autosize(){const e=this.$refs.inputEl;if(!e||e.clientWidth<80)return;e.style.height="auto",e.style.minHeight="0px";const t=e.scrollHeight;e.style.minHeight="",e.style.height=t>62?`${Math.min(t,120)}px`:""},onFile(e){const t=Array.from(e.target.files||[]);for(const n of t)this.$emit("attach",n);e.target.value=""},onAttachAction(e){this.attachOpen=!1,e==="file"?this.pickFile():e==="screenshot"?this.captureScreenshot():e==="record"&&this.startRecording()},pickFile(){var e;(e=this.$refs.fileEl)==null||e.click()},async captureScreenshot(){if(this.disabled)return;const e=await vh();e&&this.$emit("attach",e)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const e=await wh({onstart:()=>{this.recording=!0},ontick:t=>{this.recordingElapsed=t},onfinalize:t=>{this.$emit("attach",t),this.recording=!1,this.recordingElapsed=0,this.recorder=null},oncancel:()=>{this.recording=!1,this.recordingElapsed=0,this.recorder=null}});e&&(this.recorder=e)},stopRecording(){if(this.recorder)try{this.recorder.stop()}catch(e){console.error("[composer] stop recording",e)}},setupKeyboardTracking(){const e=window.visualViewport;e&&(this._vvHandler=()=>{const t=Math.max(0,window.innerHeight-e.height-e.offsetTop);this.kbOffset=t},e.addEventListener("resize",this._vvHandler),e.addEventListener("scroll",this._vvHandler))},teardownKeyboardTracking(){const e=window.visualViewport;!e||!this._vvHandler||(e.removeEventListener("resize",this._vvHandler),e.removeEventListener("scroll",this._vvHandler),this._vvHandler=null)}}},Sh={key:0,class:"wm-rec"},Ah={class:"wm-rec__lbl"},xh={key:1,class:"wm-compose__menu",role:"menu"},Th=["disabled","onClick"],Mh={class:"wm-compose__menuIcon"},Eh={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},Oh=["d"],Rh=["placeholder","disabled"],Ih={class:"wm-compose__actions"},Lh=["title","aria-label","disabled"],Ph=["disabled","aria-label"];function Bh(e,t,n,r,i,s){return h(),p("div",{class:te(["wm-compose-wrap",{"wm-compose-wrap--sheet":n.displayMode==="sheet"}]),style:Ce(i.kbOffset?{transform:`translateY(-${i.kbOffset}px)`}:null)},[i.recording?(h(),p("div",Sh,[t[11]||(t[11]=u("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),u("span",Ah,R(s.t("composer.recording",{time:s.recordingElapsedLabel})),1),u("button",{type:"button",class:"wm-rec__stop",onClick:t[0]||(t[0]=(...o)=>s.stopRecording&&s.stopRecording(...o))},R(s.t("composer.stop")),1)])):F("",!0),u("form",{class:te(["wm-compose",{"has-attach":i.attachOpen,"is-expanded":s.expanded}]),onSubmit:t[10]||(t[10]=We((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]))},[u("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:t[1]||(t[1]=(...o)=>s.onFile&&s.onFile(...o))},null,544),i.attachOpen?(h(),p("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=o=>i.attachOpen=!1)})):F("",!0),i.attachOpen?(h(),p("div",xh,[(h(!0),p(Z,null,Se(s.attachItems,o=>(h(),p("button",{key:o.action,type:"button",class:"wm-compose__menuItem",disabled:o.disabled,onClick:a=>s.onAttachAction(o.action)},[u("span",Mh,[(h(),p("svg",Eh,[u("path",{d:o.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,Oh)]))]),u("span",null,R(o.label),1)],8,Th))),128))])):F("",!0),st(u("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=o=>i.local=o),class:"wm-compose__input",rows:"1",placeholder:n.placeholder,disabled:n.disabled,onKeydown:t[4]||(t[4]=(...o)=>s.onKeydown&&s.onKeydown(...o)),onInput:t[5]||(t[5]=(...o)=>s.autosize&&s.autosize(...o)),onFocus:t[6]||(t[6]=(...o)=>s.onFocus&&s.onFocus(...o)),onBlur:t[7]||(t[7]=(...o)=>s.onBlur&&s.onBlur(...o))},null,40,Rh),[[kt,i.local]]),u("div",Ih,[u("button",{type:"button",class:te(["wm-compose__icon",{"is-open":i.attachOpen}]),title:n.attachLabel,"aria-label":n.attachLabel,disabled:i.recording,onMousedown:t[8]||(t[8]=We(()=>{},["prevent"])),onClick:t[9]||(t[9]=o=>i.attachOpen=!i.attachOpen)},[...t[12]||(t[12]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48"})],-1)])],42,Lh),u("button",{type:"submit",class:te(["wm-compose__send",{"is-empty":!s.canSend}]),disabled:!s.canSend,"aria-label":s.t("composer.send")},[...t[13]||(t[13]=[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,Ph)])],34)],6)}const Fh=be(Ch,[["render",Bh],["__scopeId","data-v-a9738520"]]),Dh={name:"WmInlineCallbacks",props:{items:{type:Array,default:()=>[]},variant:{type:String,default:"chips",validator:e=>e==="chips"||e==="buttons"},baseDelay:{type:Number,default:360},stepDelay:{type:Number,default:90}},emits:["select"],computed:{batchKey(){return this.items.map(e=>(e==null?void 0:e.label)||(e==null?void 0:e.text)||"").join("§")},headerTitle(){if(this.variant!=="buttons")return"";const e=this.items.find(t=>typeof(t==null?void 0:t.title)=="string"&&t.title.trim());return e?e.title.trim():""}},methods:{btnClass(e){return this.variant==="chips"?"wm-icb__btn--chip":["wm-icb__btn--action",`wm-icb__btn--${(e==null?void 0:e.style)||"neutral"}`]}}},Nh=["onClick"],Hh={key:0,class:"wm-icb__title"},Uh={class:"wm-icb__row"},jh=["onClick"];function Vh(e,t,n,r,i,s){return n.items.length?(h(),p("div",{key:s.batchKey,class:te(["wm-icb",`wm-icb--${n.variant}`])},[n.variant==="chips"?(h(!0),p(Z,{key:0},Se(n.items,(o,a)=>(h(),p("button",{key:o.id!=null?o.id:a,type:"button",class:"wm-icb__btn wm-icb__btn--chip",style:Ce({animationDelay:n.baseDelay+a*n.stepDelay+"ms"}),onClick:l=>e.$emit("select",o)},R(o.label),13,Nh))),128)):(h(),p(Z,{key:1},[s.headerTitle?(h(),p("div",Hh,R(s.headerTitle),1)):F("",!0),u("div",Uh,[(h(!0),p(Z,null,Se(n.items,(o,a)=>(h(),p("button",{key:o.id!=null?o.id:a,type:"button",class:te(["wm-icb__btn",s.btnClass(o)]),onClick:l=>e.$emit("select",o)},R(o.label),11,jh))),128))])],64))],2)):F("",!0)}const Kh=be(Dh,[["render",Vh],["__scopeId","data-v-c8cc8cbf"]]);let ei=0;const zh=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Wh={name:"WmFormCard",components:{AIAvatar:Sn},inject:{t:{default:()=>Ee()}},props:{form:{type:Object,required:!0},readOnly:{type:Boolean,default:!1},initialValues:{type:Object,default:null},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["submit"],data(){return ei+=1,{_uid:ei,values:{},busy:!1,error:""}},computed:{normalizedFields(){var t;return(Array.isArray((t=this.form)==null?void 0:t.fields)?this.form.fields:[]).filter(n=>!(!(n!=null&&n.key)||!(n!=null&&n.label)||!zh.has(n==null?void 0:n.type)||(n.type==="select"||n.type==="multiselect")&&(!Array.isArray(n.options)||n.options.length===0)))}},created(){this.resetValues()},methods:{resetValues(){const e=this.initialValues&&typeof this.initialValues=="object"?this.initialValues:{},t={};for(const n of this.normalizedFields){if(e[n.key]!==void 0){t[n.key]=e[n.key];continue}n.type==="boolean"?t[n.key]=!1:n.type==="multiselect"?t[n.key]=[]:t[n.key]=""}this.values=t,this.error=""},toggleMulti(e,t,n){const r=Array.isArray(this.values[e])?this.values[e].slice():[],i=r.indexOf(t);n&&i===-1?r.push(t):!n&&i!==-1&&r.splice(i,1),this.values={...this.values,[e]:r}},validate(){for(const e of this.normalizedFields){if(!e.required)continue;const t=this.values[e.key];if(e.type!=="boolean"){if(e.type==="multiselect"){if(!Array.isArray(t)||t.length===0)return this.t("form.fieldRequired",{label:e.label});continue}if(t==null||t==="")return this.t("form.fieldRequired",{label:e.label})}}return""},async onSubmit(){if(this.readOnly||this.busy)return;const e=this.validate();if(e){this.error=e;return}this.error="",this.busy=!0;try{await this.$emit("submit",{values:this.values})}finally{this.busy=!1}}}},$h={class:"wm-form"},qh={class:"wm-form__head"},Gh={class:"wm-form__icon"},Yh={class:"wm-form__main"},Jh={class:"wm-form__title"},Xh={key:0,class:"wm-form__detail"},Qh=["for"],Zh={key:0,class:"wm-form__req","aria-hidden":"true"},em=["id","onUpdate:modelValue","placeholder","required","disabled"],tm=["id","onUpdate:modelValue","placeholder","required","disabled"],nm=["id","onUpdate:modelValue","placeholder","required","disabled"],sm=["id","onUpdate:modelValue","required","disabled"],rm={key:4,class:"wm-form__bool"},im=["id","onUpdate:modelValue","disabled"],om=["id","onUpdate:modelValue","required","disabled"],am={value:"",disabled:""},lm=["value"],cm={key:6,class:"wm-form__multi"},um=["value","checked","disabled","onChange"],dm={key:0,class:"wm-form__err"},fm=["disabled"],hm={key:0,class:"wm-form__spinner","aria-hidden":"true"},mm={key:2,class:"wm-form__doneLbl"};function gm(e,t,n,r,i,s){const o=ve("AIAvatar");return h(),p("div",$h,[u("div",qh,[u("div",Gh,[pe(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",Yh,[u("div",Jh,R(n.form.title||s.t("form.title")),1),n.form.description?(h(),p("div",Xh,R(n.form.description),1)):F("",!0)])]),u("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=We((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]))},[(h(!0),p(Z,null,Se(s.normalizedFields,a=>(h(),p("div",{key:a.key,class:"wm-form__field"},[u("label",{for:`wm-f-${i._uid}-${a.key}`,class:"wm-form__label"},[ns(R(a.label),1),a.required?(h(),p("span",Zh,"*")):F("",!0)],8,Qh),a.type==="text"?st((h(),p("input",{key:0,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"text",class:"wm-form__input",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,em)),[[kt,i.values[a.key]]]):a.type==="textarea"?st((h(),p("textarea",{key:1,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,class:"wm-form__textarea",rows:"3",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,tm)),[[kt,i.values[a.key]]]):a.type==="number"?st((h(),p("input",{key:2,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"number",class:"wm-form__input",placeholder:a.placeholder||"",required:a.required,disabled:n.readOnly||i.busy},null,8,nm)),[[kt,i.values[a.key],void 0,{number:!0}]]):a.type==="date"?st((h(),p("input",{key:3,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"date",class:"wm-form__input",required:a.required,disabled:n.readOnly||i.busy},null,8,sm)),[[kt,i.values[a.key]]]):a.type==="boolean"?(h(),p("label",rm,[st(u("input",{id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,type:"checkbox",disabled:n.readOnly||i.busy},null,8,im),[[Jl,i.values[a.key]]]),u("span",null,R(a.placeholder||s.t("common.yes")),1)])):a.type==="select"?st((h(),p("select",{key:5,id:`wm-f-${i._uid}-${a.key}`,"onUpdate:modelValue":l=>i.values[a.key]=l,class:"wm-form__select",required:a.required,disabled:n.readOnly||i.busy},[u("option",am,R(a.placeholder||s.t("form.choose")),1),(h(!0),p(Z,null,Se(a.options,l=>(h(),p("option",{key:l.value,value:l.value},R(l.label),9,lm))),128))],8,om)),[[Xl,i.values[a.key]]]):a.type==="multiselect"?(h(),p("div",cm,[(h(!0),p(Z,null,Se(a.options,l=>(h(),p("label",{key:l.value,class:"wm-form__multiItem"},[u("input",{type:"checkbox",value:l.value,checked:Array.isArray(i.values[a.key])&&i.values[a.key].includes(l.value),disabled:n.readOnly||i.busy,onChange:d=>s.toggleMulti(a.key,l.value,d.target.checked)},null,40,um),u("span",null,R(l.label),1)]))),128))])):F("",!0)]))),128)),i.error?(h(),p("div",dm,R(i.error),1)):F("",!0),n.readOnly?(h(),p("div",mm,R(s.t("form.responseSent")),1)):(h(),p("button",{key:1,type:"submit",class:"wm-form__submit",disabled:i.busy},[i.busy?(h(),p("span",hm)):F("",!0),u("span",null,R(i.busy?s.t("common.sending"):n.form.submit_label||s.t("common.send")),1)],8,fm))],32)])}const pm=be(Wh,[["render",gm],["__scopeId","data-v-fe65cc56"]]),_m={name:"WmFeedback",inject:{t:{default:()=>Ee()}},props:{busy:{type:Boolean,default:!1},done:{type:Boolean,default:!1}},emits:["submit"],data(){return{sel:null}},computed:{options(){return[{v:1,e:"😞",l:this.t("feedback.rating1")},{v:2,e:"😐",l:this.t("feedback.rating2")},{v:3,e:"🙂",l:this.t("feedback.rating3")},{v:4,e:"😄",l:this.t("feedback.rating4")},{v:5,e:"🤩",l:this.t("feedback.rating5")}]}},methods:{onSend(){!this.sel||this.busy||this.$emit("submit",{rating:this.sel})}}},ym={class:"wm-fb"},vm={class:"wm-fb__title"},bm={class:"wm-fb__sub"},wm={class:"wm-fb__row"},km=["onClick"],Cm={class:"wm-fb__emoji"},Sm={class:"wm-fb__label"},Am=["disabled"],xm={key:1,class:"wm-fb__done"},Tm={class:"wm-fb__doneTitle"},Mm={class:"wm-fb__doneSub"};function Em(e,t,n,r,i,s){return h(),p("div",ym,[n.done?(h(),p("div",xm,[t[1]||(t[1]=u("div",{class:"wm-fb__check"},[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#fff","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M20 6L9 17l-5-5"})])],-1)),u("div",Tm,R(s.t("feedback.doneTitle")),1),u("div",Mm,R(s.t("feedback.doneSubtitle")),1)])):(h(),p(Z,{key:0},[u("div",vm,R(s.t("feedback.question")),1),u("div",bm,R(s.t("feedback.subtitle")),1),u("div",wm,[(h(!0),p(Z,null,Se(s.options,o=>(h(),p("button",{key:o.v,type:"button",class:te(["wm-fb__opt",{"is-selected":i.sel===o.v}]),onClick:a=>i.sel=o.v},[u("span",Cm,R(o.e),1),u("span",Sm,R(o.l),1)],10,km))),128))]),u("button",{type:"button",class:"wm-fb__send",disabled:!i.sel||n.busy,onClick:t[0]||(t[0]=(...o)=>s.onSend&&s.onSend(...o))},R(n.busy?s.t("common.sending"):s.t("feedback.submit")),9,Am)],64))])}const Om=be(_m,[["render",Em],["__scopeId","data-v-9b630564"]]),Rm={name:"WmMoreMenu",inject:{t:{default:()=>Ee()}},props:{canRename:{type:Boolean,default:!0},canExport:{type:Boolean,default:!0},soundEnabled:{type:Boolean,default:!0},statusUrl:{type:String,default:""},helpUrl:{type:String,default:""}},emits:["close","action","sound-toggle"],data(){return{soundOn:this.soundEnabled}},watch:{soundEnabled(e){this.soundOn=!!e}},methods:{emit(e){this.$emit("action",e)},toggleSound(){this.soundOn=!this.soundOn,this.$emit("sound-toggle",this.soundOn)}}},Im={class:"wm-mm"},Lm={class:"wm-mm__pop",role:"menu"},Pm={key:0,class:"wm-mm__section"},Bm={class:"wm-mm__label"},Fm={class:"wm-mm__label"},Dm={key:1,class:"wm-mm__sep"},Nm={class:"wm-mm__section"},Hm={class:"wm-mm__label"},Um={class:"wm-mm__section"},jm={class:"wm-mm__label"},Vm={class:"wm-mm__label"};function Km(e,t,n,r,i,s){return h(),p("div",Im,[u("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Lm,[n.canRename||n.canExport?(h(),p("div",Pm,[n.canRename?(h(),p("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[1]||(t[1]=o=>s.emit("rename"))},[t[6]||(t[6]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M12 20h9"}),u("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})])],-1)),u("span",Bm,R(s.t("moreMenu.editTitle")),1)])):F("",!0),n.canExport?(h(),p("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[2]||(t[2]=o=>s.emit("export"))},[t[7]||(t[7]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8M16 6l-4-4-4 4M12 2v13"})])],-1)),u("span",Fm,R(s.t("moreMenu.exportTranscript")),1),t[8]||(t[8]=u("span",{class:"wm-mm__hint"},".txt",-1))])):F("",!0)])):F("",!0),n.canRename||n.canExport?(h(),p("div",Dm)):F("",!0),u("div",Nm,[u("button",{type:"button",class:"wm-mm__item",onClick:t[3]||(t[3]=(...o)=>s.toggleSound&&s.toggleSound(...o))},[t[10]||(t[10]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M11 5L6 9H2v6h4l5 4V5z"}),u("path",{d:"M15.54 8.46a5 5 0 010 7.07M19.07 4.93a10 10 0 010 14.14"})])],-1)),u("span",Hm,R(s.t("moreMenu.sound")),1),u("span",{class:te(["wm-mm__toggle",{"wm-mm__toggle--on":i.soundOn}])},[...t[9]||(t[9]=[u("span",{class:"wm-mm__knob"},null,-1)])],2)])]),t[13]||(t[13]=u("div",{class:"wm-mm__sep"},null,-1)),u("div",Um,[n.statusUrl?(h(),p("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[4]||(t[4]=o=>s.emit("status"))},[t[11]||(t[11]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM10 6v4l3 2"})])],-1)),u("span",jm,R(s.t("moreMenu.serviceStatus")),1)])):F("",!0),n.helpUrl?(h(),p("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[5]||(t[5]=o=>s.emit("help"))},[t[12]||(t[12]=u("span",{class:"wm-mm__icon"},[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M9 11a3 3 0 116 0c0 2-3 2-3 5M12 19h.01M12 22a10 10 0 110-20 10 10 0 010 20z"})])],-1)),u("span",Vm,R(s.t("moreMenu.helpCenter")),1)])):F("",!0)])])])}const zm=be(Rm,[["render",Km],["__scopeId","data-v-4cf6d578"]]),Wm={name:"WmRenameDialog",inject:{t:{default:()=>Ee()}},props:{title:{type:String,default:""},initialValue:{type:String,default:""},placeholder:{type:String,default:""}},emits:["close","submit"],data(){return{value:this.initialValue||""}},computed:{canSubmit(){const e=(this.value||"").trim();return!!e&&e!==(this.initialValue||"").trim()}},mounted(){this.$nextTick(()=>{const e=this.$refs.input;if(e){e.focus();try{e.select()}catch{}}})},methods:{onSubmit(){this.canSubmit&&this.$emit("submit",this.value.trim())}}},$m={class:"wm-dialog"},qm={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},Gm={class:"wm-dialog__head"},Ym={class:"wm-dialog__title"},Jm=["aria-label"],Xm={class:"wm-dialog__body"},Qm=["placeholder"],Zm={class:"wm-dialog__actions"},eg=["disabled"];function tg(e,t,n,r,i,s){return h(),p("div",$m,[u("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",qm,[u("div",Gm,[u("div",Ym,R(n.title||s.t("rename.title")),1),u("button",{type:"button",class:"wm-dialog__close","aria-label":s.t("common.close"),onClick:t[1]||(t[1]=o=>e.$emit("close"))},[...t[7]||(t[7]=[u("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,Jm)]),u("div",Xm,[st(u("input",{ref:"input","onUpdate:modelValue":t[2]||(t[2]=o=>i.value=o),type:"text",class:"wm-dialog__input",placeholder:n.placeholder||s.t("rename.placeholder"),maxlength:120,onKeydown:[t[3]||(t[3]=Un(We((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]),["enter"])),t[4]||(t[4]=Un(We(o=>e.$emit("close"),["prevent"]),["esc"]))]},null,40,Qm),[[kt,i.value]])]),u("div",Zm,[u("button",{type:"button",class:"wm-dialog__btn",onClick:t[5]||(t[5]=o=>e.$emit("close"))},R(s.t("common.cancel")),1),u("button",{type:"button",class:"wm-dialog__btn wm-dialog__btn--primary",disabled:!s.canSubmit,onClick:t[6]||(t[6]=(...o)=>s.onSubmit&&s.onSubmit(...o))},R(s.t("common.save")),9,eg)])])])}const ng=be(Wm,[["render",tg],["__scopeId","data-v-6d5f94a8"]]),ti="ww-messenger-tokens",sg={name:"Messenger",components:{Launcher:Qc,Header:Cu,Onboarding:ld,History:Sd,MessageList:_h,Composer:Fh,InlineCallbacks:Kh,FormCard:pm,Feedback:Om,MoreMenu:zm,RenameDialog:ng},mixins:[Ec,Oc,Ic],provide(){return{signAttachmentFn:e=>{var t,n;return((n=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:n.call(t,e))||null},t:(e,t)=>this.t(e,t),wmLocale:()=>this.locale}},props:{baseUrl:{type:String,default:pc},widgetId:{type:String,default:""},context:{type:Object,default:null},displayMode:{type:String,default:"floating"},devtools:{type:Boolean,default:!1},language:{type:String,default:""}},data(){return{transport:null,store:null,isOpen:!1,launcherHovered:!1,draft:"",busy:!1,bootError:null,pendingAttachments:[],feedbackBusy:!1,feedbackDone:{},convOpenedAt:0,moreOpen:!1,renameDialogOpen:!1,draftConv:null,launching:!1,launchStage:"idle",pendingLaunchText:"",reopenedLocally:{},activeConvId:null,showOnboarding:!1,showHistory:!1,backToHistory:!1,welcomeRevealedAt:{},welcomeRevealTimers:{},dismissedPeeks:{},floatHeight:0,floatRO:null,parentOrigin:"",parentToken:"",parentVariables:null,parentAllowUnauthenticated:!1,parentInitReceived:!1,parentInitDeferred:null}},computed:{isEditor(){return!!this.devtools},isEmbedded(){return this.displayMode==="embedded"},customerLanguage(){var n,r,i,s;const e=(n=this.s)==null?void 0:n.customer,t=e&&(e.language||((r=e.values)==null?void 0:r.language));return t||((s=(i=this.context)==null?void 0:i.customer)==null?void 0:s.language)||""},locale(){var e;return tr(this.language||this.customerLanguage||((e=this.widget)==null?void 0:e.default_language)||"")},translator(){return Ee(this.locale)},error(){var e;return this.bootError||((e=this.s)==null?void 0:e.error)||null},canBoot(){return!!(this.baseUrl&&this.widgetId)},s(){var e;return((e=this.store)==null?void 0:e.state)||null},ready(){var e;return!!((e=this.s)!=null&&e.ready)},allConversations(){var t;const e=(t=this.s)==null?void 0:t.conversations;return Array.isArray(e)?e:[]},drawerConversations(){var n;const e=((n=this.s)==null?void 0:n.messagesByConv)||{},t=this.revealedAt;return this.allConversations.map(r=>{var d;const i=e[r.id]||[],s=ht(r.last_read_message_id);let o=0,a=null;for(let c=i.length-1;c>=0;c--){const m=i[c];if(!m)continue;if(((d=m.author)==null?void 0:d.type)==="user")break;const C=ht(m.id);if(C!=null){if(s!=null&&C<=s)break;t[m.id]!==0&&(!a&&m.author&&(a=m.author),o++)}}if(!i.length){const c=ht(r.last_message_id);c!=null&&(s==null||c>s)&&(o=1,a=r.last_message_author||null)}const l=i.filter(c=>!((c==null?void 0:c.id)!=null&&t[c.id]===0));return{...r,_preview:Ac(r,l),_unread:o>0,_unreadCount:o,_lastAuthor:a}})},unreadCount(){return this.drawerConversations.filter(e=>e._unread).length},openThreads(){var t;const e=((t=this.s)==null?void 0:t.messagesByConv)||{};return this.drawerConversations.filter(n=>{const r=this.convStatus(n);return r!=="resolved"&&r!=="closed"}).map(n=>({id:n.id,title:n.name||this.t("common.newConversation"),preview:n._preview||this.t("onboarding.newMessage"),unread:!!n._unread,author:n._lastAuthor||null,_ts:Qr(n,e[n.id]||[])})).sort((n,r)=>n._ts<r._ts?1:n._ts>r._ts?-1:0)},latestUnreads(){var n;const e=((n=this.s)==null?void 0:n.messagesByConv)||{},t=[];for(const r of this.drawerConversations){if(!r._unread)continue;const i=Qr(r,e[r.id]||[]),s=r._lastAuthor,o=!s||s.type==="agent_ia",a=(s==null?void 0:s.name)||(o?this.agentName:"")||"",l=(s==null?void 0:s.avatar_url)||(o?this.agentAvatarUrl:null);t.push({convId:r.id,preview:r._preview||this.t("notification.youHaveNewMessage"),ts:i,count:r._unreadCount||1,senderName:a,senderAvatarUrl:l})}return t.sort((r,i)=>r.ts<i.ts?1:r.ts>i.ts?-1:0),t},launcherPeeks(){if(this.isOpen||this.isEmbedded)return[];const e=this.dismissedPeeks||{};return this.latestUnreads.filter(t=>e[t.convId]!==t.ts)},isViewingThread(){return(this.isOpen||this.isEmbedded)&&!!this.currentConv},currentConv(){if(this.draftConv)return this.draftConv;if(this.showOnboarding||this.showHistory)return null;const e=this.allConversations;if(!e.length)return null;if(this.activeConvId!=null){const t=e.find(n=>n.id===this.activeConvId);if(t)return t}return e[0]||null},canBack(){return!!this.currentConv||this.showHistory},statusUrl(){var n;const e=(n=this.widget)==null?void 0:n.quick_links;if(!Array.isArray(e))return"";const t=e.find(r=>r.icon==="status"&&r.url);return(t==null?void 0:t.url)||""},helpUrl(){var n;const e=(n=this.widget)==null?void 0:n.quick_links;if(!Array.isArray(e))return"";const t=e.find(r=>(r.icon==="chat"||r.icon==="help")&&r.url);return(t==null?void 0:t.url)||""},widget(){var e,t;return((t=(e=this.s)==null?void 0:e.config)==null?void 0:t.widget)||null},rootStyle(){var t;const e=(t=this.widget)==null?void 0:t.primary_color;return e&&bc(e)?{"--wm-primary":e}:null},widgetTitle(){var e;return((e=this.widget)==null?void 0:e.title)||""},widgetWelcomeMessage(){var e;return((e=this.widget)==null?void 0:e.welcome_message)||""},widgetSubtitle(){var e;return((e=this.widget)==null?void 0:e.subtitle)||""},defaultIconUrl(){var e;return((e=this.widget)==null?void 0:e.default_icon_url)||null},coverImageUrl(){var e;return((e=this.widget)==null?void 0:e.cover_image_url)||null},agentName(){var e,t,n;return((n=(t=(e=this.s)==null?void 0:e.config)==null?void 0:t.agent)==null?void 0:n.name)||""},agentAvatarUrl(){var e,t,n;return((n=(t=(e=this.s)==null?void 0:e.config)==null?void 0:t.agent)==null?void 0:n.avatar_url)||null},quickLinks(){var t;const e=(t=this.widget)==null?void 0:t.quick_links;return Array.isArray(e)?e:[]},teamMembers(){var t;const e=(t=this.widget)==null?void 0:t.team_members;return Array.isArray(e)?e:[]},responseLabel(){var e;return((e=this.widget)==null?void 0:e.response_time_label)||""},humanMessageAuthor(){var t,n,r;if(!this.currentConv)return null;const e=((t=this.s.messagesByConv)==null?void 0:t[this.currentConv.id])||[];for(let i=e.length-1;i>=0;i--)if(((r=(n=e[i])==null?void 0:n.author)==null?void 0:r.type)==="agent_human")return e[i].author;return null},humanAgentName(){var e;return((e=this.humanMessageAuthor)==null?void 0:e.name)||""},humanAgentAvatarUrl(){var e;return((e=this.humanMessageAuthor)==null?void 0:e.avatar_url)||null},isEscalated(){return!!this.humanMessageAuthor},isWaitingHuman(){return this.currentStatus==="waiting_human_response"},isTerminal(){return this.currentStatus==="resolved"||this.currentStatus==="closed"},isClosed(){return this.currentStatus==="closed"},endedBlockVisible(){var e;return!(!this.isTerminal||this.isClosed&&this.reopenedLocally[(e=this.currentConv)==null?void 0:e.id])},headerTitle(){var e,t;return((e=this.currentConv)==null?void 0:e.name)||((t=this.widget)==null?void 0:t.name)||this.t("common.newConversation")},composerPlaceholder(){return this.isEscalated&&this.humanAgentName?this.t("composer.replyTo",{name:this.humanAgentName.split(" ")[0]}):this.isWaitingHuman?this.t("composer.agentTakingOver"):this.t("composer.placeholder")},displayedMessages(){var i,s;const e=this.currentConv;if(!e)return[];const t=this.welcomeRevealedAt[e.id]>0?this.buildWelcomePrefix(e):[];if(!e._draft){const o=(s=(i=this.s)==null?void 0:i.paginationByConv)==null?void 0:s[e.id];if(!(o!=null&&o.loaded))return t}const n=this.revealedAt,r=(this.s.messagesByConv[e.id]||[]).filter(o=>{var a,l,d,c,m;return(o==null?void 0:o.type)==="action"&&((a=o==null?void 0:o.payload)==null?void 0:a.state)==="pending"||bn(o)&&!(n[o.id]>0)?!1:(o==null?void 0:o.type)==="action"||(o==null?void 0:o.type)==="system"||((l=o==null?void 0:o.payload)==null?void 0:l.type)==="system"||Array.isArray((d=o==null?void 0:o.payload)==null?void 0:d.attachments)&&o.payload.attachments.length||(c=o==null?void 0:o.metadata)!=null&&c.artifact||(m=o==null?void 0:o.metadata)!=null&&m.form||Array.isArray(o==null?void 0:o.callbacks)&&o.callbacks.some(C=>(C==null?void 0:C.intent)==="submit_form")?!0:typeof(o==null?void 0:o.text_md)=="string"&&o.text_md.trim().length>0});return t.length?[...t,...r]:r},streamingActive(){var n,r,i;const e=this.currentConv;return e?Object.keys(((n=this.s)==null?void 0:n.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:this.widgetWelcomeMessage&&this.welcomeRevealedAt[e.id]===0?!0:(((i=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:i[e.id])||[]).some(s=>bn(s)&&!(this.revealedAt[s.id]>0)):!1},currentConvMessages(){var t,n,r;const e=(t=this.currentConv)==null?void 0:t.id;return e?((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e])||[]:[]},pendingResolution(){var t,n,r,i,s;if(!this.currentConv)return null;const e=((n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id])||[];for(let o=e.length-1;o>=0;o--){const a=e[o];if((r=a==null?void 0:a.metadata)!=null&&r.resolution_request)return!Array.isArray(a.callbacks)||!a.callbacks.length||(s=(i=this.s)==null?void 0:i.awaitingCallback)!=null&&s[a.id]?null:a}return null},resolutionCallbacks(){const e=this.pendingResolution;if(!e||!Array.isArray(e.callbacks))return[];const t={resolve_confirm:this.t("resolution.confirm"),resolve_decline:this.t("resolution.decline")};return e.callbacks.map(n=>({...n,label:t[n.id]||n.label}))},pendingApproval(){var t,n,r,i;if(!this.currentConv)return null;const e=((n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id])||[];for(let s=e.length-1;s>=0;s--){const o=e[s];if(!(!Array.isArray(o==null?void 0:o.callbacks)||!o.callbacks.length||!o.callbacks.some(l=>(l==null?void 0:l.intent)==="approve"&&(l.audience??"customer")==="customer")))return(i=(r=this.s)==null?void 0:r.awaitingCallback)!=null&&i[o.id]?null:o}return null},approvalCallbacks(){const e=this.pendingApproval;return!e||!Array.isArray(e.callbacks)?[]:e.callbacks.filter(t=>(t==null?void 0:t.intent)==="approve"||(t==null?void 0:t.intent)==="reject")},currentStatus(){return this.convStatus(this.currentConv)},actionInFlight(){var e,t;return!this.currentConv||!this.store?null:((t=(e=this.store).getActionInFlight)==null?void 0:t.call(e,this.currentConv.id))||null},actionInFlightName(){var t;const e=this.actionInFlight;return e?((t=e.payload)==null?void 0:t.name)||e.text_md||this.t("common.action"):""},suggestions(){return this.currentConv?this.isTerminal?[]:this.streamingActive?[]:this.pendingForm?[]:this.conversationIsEmpty?this.starterPrompts:this.store?this.store.getLatestSuggestions(this.currentConv.id):[]:[]},conversationIsEmpty(){var n,r;const e=this.currentConv;return e?e._draft?!0:(((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[]).length===0:!1},starterPrompts(){var n;const e=(n=this.widget)==null?void 0:n.starter_prompts;if(!Array.isArray(e))return[];const t=[];for(const r of e){if(!r||typeof r!="object")continue;const i=typeof r.title=="string"?r.title.trim():"";if(!i)continue;const s=typeof r.message=="string"?r.message.trim():"";t.push({label:i,text:s||i,kind:"starter"})}return t},pendingForm(){var e,t;return!this.currentConv||!this.store||this.actionInFlight||this.streamingActive?null:((t=(e=this.store).getLatestForm)==null?void 0:t.call(e,this.currentConv.id))||null},showFeedback(){var t;const e=this.currentConv;return!e||this.currentStatus!=="resolved"?!1:this.feedbackDone[e.id]?!0:!((t=e.metadata)!=null&&t.feedback)},floatVisible(){return!!this.pendingApproval||!!this.pendingResolution||!!this.pendingForm||this.showFeedback||this.suggestions.length>0},dateLabel(){var n,r,i;const e=this.currentConv;let t=new Date;if(e){const o=((i=(((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[]).find(a=>a==null?void 0:a.created_at))==null?void 0:i.created_at)||e.created_at;if(o){const a=new Date(o);Number.isNaN(a.getTime())||(t=a)}}return this.t("messageList.today",{time:Bs(t,Bt(this.locale))})},paginationState(){var n,r,i;const e=(n=this.currentConv)==null?void 0:n.id,t=e?(i=(r=this.s)==null?void 0:r.paginationByConv)==null?void 0:i[e]:null;return{loading:!!(t!=null&&t.loading),hasMore:!!(t!=null&&t.nextCursor)}}},watch:{latestUnreads:{handler(e){const t=new Set(e.map(o=>o.convId)),n=this.dismissedPeeks||{},r=Object.keys(n);if(!r.length)return;const i={};let s=!1;for(const o of r)t.has(o)?i[o]=n[o]:s=!0;s&&(this.dismissedPeeks=i)},deep:!0},"currentConv.id":{handler(e){var t;this.resetRevealQueue(),this.convOpenedAt=Date.now(),this.moreOpen=!1,this.renameDialogOpen=!1,this.isViewingThread&&(this.unreadAnchorId=ht((t=this.currentConv)==null?void 0:t.last_read_message_id),this.unreadBoundaryTs=e?new Date().toISOString():""),e&&this.scheduleWelcomeReveal(e)},immediate:!0},isViewingThread(e,t){var n;e&&!t?(this.unreadAnchorId=ht((n=this.currentConv)==null?void 0:n.last_read_message_id),this.unreadBoundaryTs=new Date().toISOString()):e||(this.unreadAnchorId=null,this.unreadBoundaryTs="")},floatVisible:{handler(e){this.$nextTick(()=>this.syncFloatObserver(e))},immediate:!0},currentConvMessages(e){var t;this.paceMessages(e,(t=this.currentConv)==null?void 0:t.id),(this.isOpen||this.isEmbedded)&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(typeof document<"u"&&!document.getElementById(ti)){const e=document.createElement("style");e.id=ti,e.textContent=Ao,document.head.appendChild(e)}this._parentMessageHandler=this.onParentMessage.bind(this),window.addEventListener("message",this._parentMessageHandler),window.parent&&window.parent!==window&&window.parent.postMessage({type:"READY"},"*"),this.isEmbedded?(await this.boot(),this.store&&await this.open()):(await this.$nextTick(),this.sendCurrentLauncherSize(),this.observeLauncherSize())},beforeUnmount(){this._parentMessageHandler&&(window.removeEventListener("message",this._parentMessageHandler),this._parentMessageHandler=null),this._launcherRo&&(this._launcherRo.disconnect(),this._launcherRo=null),this.cancelReveals(),this.cancelWelcomeTimers(),this.teardownLiveReveal(),this.disconnectFloatRO(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{convStatus(e){var n,r,i,s;if(!e)return"open";const t=((r=(n=this.s)==null?void 0:n.messagesByConv)==null?void 0:r[e.id])||[];for(let o=t.length-1;o>=0;o--){const a=(s=(i=t[o])==null?void 0:i.metadata)==null?void 0:s.conversation_status;if(a)return a}return e.status||"open"},t(e,t){return this.translator(e,t)},waitForParentInit(){if(this.parentInitReceived)return Promise.resolve();if(!this.parentInitDeferred){let e;this.parentInitDeferred=new Promise(t=>{e=t}),this.parentInitDeferred._resolve=e}return this.parentInitDeferred},onParentMessage(e){var n;const t=e==null?void 0:e.data;if(!(!t||typeof t!="object")){if(t.type==="UPDATE"){this.transport&&t.payload&&this.transport.update(t.payload).catch(r=>{console.warn("[messenger] update failed",r)});return}if(t.type==="CONTEXT"){this.transport&&t.payload&&this.transport.context(t.payload);return}t.type==="INIT"&&(this.parentOrigin=e.origin,this.parentToken=typeof t.token=="string"?t.token:"",this.parentVariables=t.variables&&typeof t.variables=="object"?t.variables:t.context&&typeof t.context=="object"?t.context:null,this.parentAllowUnauthenticated=t.allowUnauthenticated===!0,this.parentInitReceived=!0,(n=this.parentInitDeferred)!=null&&n._resolve&&this.parentInitDeferred._resolve(),!this.isEmbedded&&!this.isOpen&&!this.parentAllowUnauthenticated&&this.parentToken&&this.hasValidSessionMarker()&&this.boot().catch(r=>{console.warn("[messenger] eager boot failed",r)}))}},hasValidSessionMarker(){if(typeof document>"u")return!1;const t=(document.cookie||"").match(/(?:^|; )messenger_session_marker=([^;]+)/);if(!t)return!1;const n=parseInt(t[1],10);return Number.isFinite(n)?n>Date.now():!1},async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds");return}try{await this.waitForParentInit(),this.transport=Ts(dc({baseUrl:this.baseUrl,widgetId:this.widgetId})),this.store=Ts(gc(this.transport)),this.hydrateNotifPref();const e=this.parentVariables||this.context||null;if(await this.store.start({origin:this.parentOrigin,token:this.parentToken||void 0,allowUnauthenticated:this.parentAllowUnauthenticated,variables:e&&typeof e=="object"?e:void 0}),e&&typeof e=="object"){const t={};for(const[n,r]of Object.entries(e))n!=="customer"&&r&&typeof r=="object"&&!Array.isArray(r)&&(t[n]=r);Object.keys(t).length>0&&this.transport.context(t)}this.setupLiveReveal()}catch(e){console.error("[ww-messenger] bootstrap failed",e),this.bootError=(e==null?void 0:e.message)||String(e)}},async refresh(){this.store&&this.store.destroy(),this.cancelReveals(),this.cancelWelcomeTimers(),this.welcomeRevealedAt={},this.teardownLiveReveal(),this.teardownNotifications(),this.convOpenedAt=0,this.transport=null,this.store=null,this.isOpen=!1,this.draft="",this.busy=!1,this.bootError=null,this.pendingAttachments=[],this.feedbackBusy=!1,this.feedbackDone={},this.moreOpen=!1,this.renameDialogOpen=!1,this.draftConv=null,this.activeConvId=null,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1,await this.boot(),this.isEmbedded&&this.store&&await this.open()},syncFloatObserver(e){if(this.disconnectFloatRO(),!e){this.floatHeight=0;return}const t=this.$refs.floatEl;if(t){if(typeof ResizeObserver>"u"){this.floatHeight=Math.ceil(t.getBoundingClientRect().height+8);return}this.floatRO=new ResizeObserver(n=>{const r=n[0];if(!r)return;const i=Math.ceil(r.contentRect.height+8);i!==this.floatHeight&&(this.floatHeight=i,this.$nextTick(()=>{var s,o;(o=(s=this.$refs.messageList)==null?void 0:s.keepPinnedToBottom)==null||o.call(s)}))}),this.floatRO.observe(t)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},async open(){this.isOpen=!0,this.notifyParentResize("open"),this._launcherRo&&this._launcherRo.disconnect(),this.store||await this.boot(),this.store&&this.store.setPanelOpen(!0);const e=this.currentConv;if(e&&!e._draft){this.activeConvId==null&&(this.activeConvId=e.id);try{await this.store.openConversation(e.id)}catch(t){console.error("[ww-messenger] load messages failed",t)}this.markConvRead(e)}},async close(){this.isOpen=!1,await this.$nextTick(),this.sendCurrentLauncherSize(),this.observeLauncherSize(),this.store&&this.store.setPanelOpen(!1)},notifyParentResize(e,t){if(window.parent&&window.parent!==window)try{window.parent.postMessage({type:"RESIZE",state:e,displayMode:this.displayMode,...t||{}},"*")}catch(n){console.warn("[ww-messenger] notifyParentResize failed",n)}},onLauncherHover(e){this.launcherHovered=e,this.sendCurrentLauncherSize()},sendCurrentLauncherSize(){var c,m,C,b,K,S,J;if(this.isOpen)return;const e=(m=(c=this.$el)==null?void 0:c.querySelector)==null?void 0:m.call(c,".wm-launcherWrap");if(!e)return;const t=e.getBoundingClientRect();if(!t.width||!t.height)return;const n=(((C=this.launcherPeeks)==null?void 0:C.length)??0)>0,r=16,i=Math.ceil(t.width),s=Math.ceil(t.height),o=(K=(b=this.$el)==null?void 0:b.querySelector)==null?void 0:K.call(b,".wm-launcher"),a=(J=(S=this.$el)==null?void 0:S.querySelectorAll)==null?void 0:J.call(S,".wm-peek"),l=a&&a.length?a[a.length-1]:null;let d=null;if(l){const U=l.getBoundingClientRect();d={width:Math.ceil(U.width),height:Math.ceil(U.height),rightOffset:Math.max(0,Math.ceil(t.right-U.right)),bottomOffset:Math.max(0,Math.ceil(t.bottom-U.bottom))}}this.notifyParentResize("closed",{width:i+r,height:s+r,launcherWidth:(o==null?void 0:o.offsetWidth)||null,launcherHeight:(o==null?void 0:o.offsetHeight)||null,launcherHovered:this.launcherHovered,peek:d,peekHovered:this.launcherHovered&&n})},observeLauncherSize(){var n,r;if(typeof ResizeObserver>"u")return;const e=(r=(n=this.$el)==null?void 0:n.querySelector)==null?void 0:r.call(n,".wm-launcherWrap");if(!e)return;this._launcherRo&&this._launcherRo.disconnect();const t=new ResizeObserver(()=>{this.isOpen||this.sendCurrentLauncherSize()});t.observe(e),this._launcherRo=t},async openFromPeek(e){var n,r;const t=e||((n=this.latestUnreads[0])==null?void 0:n.convId);t&&t!==((r=this.currentConv)==null?void 0:r.id)&&(this.draftConv=null,this.activeConvId=t,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1),await this.open()},dismissPeek(e){const t=this.latestUnreads.find(n=>n.convId===e);t&&(this.dismissedPeeks={...this.dismissedPeeks,[e]:t.ts})},onOnboardingStart(e){this.pendingLaunchText=(e||"").trim(),this.launching=!0,this.launchStage="whiteslide"},onHomeLaunched(){const e=this.pendingLaunchText;this.pendingLaunchText="",this.startConv(),e&&this.$nextTick(()=>this.onSend(e)),this.launchStage="header",window.setTimeout(()=>{this.launching&&(this.launchStage="messages")},520),window.setTimeout(()=>{this.launching=!1,this.launchStage="idle"},1160)},startConv(){this.draftConv={id:"__draft__",_draft:!0,name:"",created_at:new Date().toISOString()},this.activeConvId=null,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=!1,this.focusComposer()},onReopen(){var t;const e=(t=this.currentConv)==null?void 0:t.id;e&&(this.reopenedLocally={...this.reopenedLocally,[e]:!0},this.focusComposer())},async ensureRealConv(){const e=this.currentConv;if(!e)return null;if(!e._draft)return e;if(this.busy)return null;this.busy=!0;try{const t=await this.store.createConversation({}),n=this.welcomeRevealedAt.__draft__;return n!==void 0&&(this.welcomeRevealedAt={...this.welcomeRevealedAt,[t.id]:n>0?n:Date.now()}),this.draftConv=null,this.activeConvId=t.id,await this.store.openConversation(t.id),this.markConvRead(t),t}catch(t){return console.error("[ww-messenger] create conv failed",t),this.bootError=(t==null?void 0:t.message)||String(t),null}finally{this.busy=!1}},focusComposer(){this.$nextTick(()=>{var e;return(e=this.$refs.composer)==null?void 0:e.focus()})},buildWelcomePrefix(e){const t=this.widgetWelcomeMessage;return!t||typeof t!="string"||!t.trim()?[]:[{id:"__welcome__",text_md:t.trim(),author:{type:"agent_ia",name:this.agentName,avatar_url:this.agentAvatarUrl},created_at:(e==null?void 0:e.created_at)||new Date(0).toISOString()}]},scheduleWelcomeReveal(e){if(!e)return;const t=this.widgetWelcomeMessage;if(!t||typeof t!="string"||!t.trim()||this.welcomeRevealedAt[e]!==void 0)return;const n=this.currentConv;if(!((n==null?void 0:n._draft)||!(n!=null&&n.last_message_id))){this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:Date.now()};return}this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:0};const i=this.revealPacing,s=t.trim().length,o=Math.min(i.maxTypingMs,Math.max(i.minTypingMs,s*i.msPerChar)),a=i.firstRevealDelayMs+o,l=setTimeout(()=>{this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:Date.now()};const d={...this.welcomeRevealTimers};delete d[e],this.welcomeRevealTimers=d},a);this.welcomeRevealTimers={...this.welcomeRevealTimers,[e]:l}},cancelWelcomeTimers(){for(const e of Object.values(this.welcomeRevealTimers))try{clearTimeout(e)}catch{}this.welcomeRevealTimers={}},toggleMore(){this.moreOpen=!this.moreOpen},goHome(){this.moreOpen=!1,this.draftConv=null,this.activeConvId=null,this.backToHistory?(this.showOnboarding=!1,this.showHistory=!0,this.backToHistory=!1):(this.showOnboarding=!0,this.showHistory=!1)},async onDrawerPick(e){if(!(e!=null&&e.id)||!this.store)return;const t=this.showHistory;this.draftConv=null,this.activeConvId=e.id,this.showOnboarding=!1,this.showHistory=!1,this.backToHistory=t;try{await this.store.openConversation(e.id)}catch(r){console.error("[ww-messenger] open conv failed",r)}const n=this.allConversations.find(r=>r.id===e.id);n&&this.markConvRead(n)},async onMoreAction(e){var t,n;switch(this.moreOpen=!1,e){case"rename":this.openRenameDialog();break;case"export":Mc(this.currentConv,this.currentConv?(n=(t=this.s)==null?void 0:t.messagesByConv)==null?void 0:n[this.currentConv.id]:[],this.translator,this.locale);break;case"status":if(In(this.statusUrl))try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(In(this.helpUrl))try{window.open(this.helpUrl,"_blank","noopener")}catch{}break}},openRenameDialog(){const e=this.currentConv;!e||e._draft||(this.renameDialogOpen=!0)},async onRenameSubmit(e){const t=this.currentConv;if(this.renameDialogOpen=!1,!t||t._draft||!this.store)return;const n=(e||"").trim();if(!(!n||n===t.name))try{await this.store.patchConversation(t.id,{name:n})}catch(r){console.error("[ww-messenger] rename failed",r)}},async onSend(e){let t=this.currentConv;if(!t&&(this.startConv(),t=this.currentConv,!t)||t._draft&&(t=await this.ensureRealConv(),!t))return;const n=t.id,r=this.pendingAttachments.slice();this.pendingAttachments=[],this.unreadAnchorId=null,this.unreadBoundaryTs="";const i=r.map(s=>{const{previewUrl:o,...a}=s;return a});await this.store.send(n,e,{attachments:i.length?i:void 0})},async onSuggestion(e){const t=(e==null?void 0:e.text)||(e==null?void 0:e.label);t&&await this.onSend(t)},async onLoadMore(){var t;const e=(t=this.currentConv)==null?void 0:t.id;!e||!this.store||await this.store.loadMore(e)},async onResolutionSelect(e){const t=this.pendingResolution;!t||!(e!=null&&e.id)||await this.store.clickCallback(t.id,e.id)},async onApprovalSelect(e){const t=this.pendingApproval;!t||!(e!=null&&e.id)||await this.store.clickCallback(t.id,e.id)},async onFormSubmit({values:e}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const n=kc(t.form,e,this.translator);if(!n)return;let r=this.currentConv;r&&(r._draft&&(r=await this.ensureRealConv(),!r)||await this.store.send(r.id,n,{metadata:{artifact:Cc(t.form,e,this.translator)}}))},formatAttachmentSize(e){return e?e<1024?this.t("attachment.bytes",{size:e}):e<1024*1024?this.t("attachment.kilobytes",{size:(e/1024).toFixed(0)}):this.t("attachment.megabytes",{size:(e/(1024*1024)).toFixed(1)}):""},removePendingAttachment(e){this.pendingAttachments.splice(e,1)},async onAttach(e){var t,n;if(!(!e||!this.transport))try{const r=await this.transport.uploadAttachment(e),i=(r==null?void 0:r.type)==="image"||(e.type||"").toLowerCase().startsWith("image/")||((r==null?void 0:r.mime_type)||"").toLowerCase().startsWith("image/");let s=null;if(i)try{s=await((n=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:n.call(t,r.path))||null}catch{}this.pendingAttachments.push({type:r.type||"file",path:r.path,name:e.name||this.t("attachment.fileFallbackName"),mime_type:e.type,size_bytes:e.size,previewUrl:s})}catch(r){console.error("[ww-messenger] attachment upload failed",r)}},onPanelClick(e){const t=e.target&&e.target.closest?e.target.closest('a[href^="#"]'):null;t&&(e.preventDefault(),this.openInternalUrl(t.getAttribute("href")))},async openInternalUrl(e){if(typeof e!="string"||!e.startsWith("#"))return!1;const t=e.slice(1);if(t==="new"||t==="new-conversation")return this.isOpen||await this.open(),this.startConv(),!0;if(t.startsWith("conversation/")){const n=t.slice(13);return n&&await this.openFromPeek(n),!0}return console.warn("[messenger] unknown internal url",e),!0},async onQuickLink(e){if(e){if(e.url){if(await this.openInternalUrl(e.url))return;if(!In(e.url)){console.warn("[messenger] refusing unsafe quick-link url",e.url);return}try{window.open(e.url,"_blank","noopener")}catch{}return}this.currentConv||this.startConv(),await this.onSend(e.label)}},async onFeedback({rating:e,comment:t}){if(this.currentConv){this.feedbackBusy=!0;try{await this.store.submitFeedback(this.currentConv.id,{rating:e,comment:t}),this.feedbackDone={...this.feedbackDone,[this.currentConv.id]:!0}}catch(n){console.error("[ww-messenger] feedback failed",n)}finally{this.feedbackBusy=!1}}}}},rg={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},ig=["aria-label"],og={class:"wm-screens"},ag={key:"error",class:"wm-screen wm-state"},lg={class:"wm-state__err"},cg={class:"wm-state__errTitle"},ug={class:"wm-state__errSub"},dg={key:"chat",class:"wm-screen wm-screen--chat"},fg={class:"wm-bottom"},hg={key:0,ref:"floatEl",class:"wm-float"},mg={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},gg={class:"wm-actionWait__lbl"},pg={key:2,class:"wm-attached"},_g=["src","alt"],yg={key:1,class:"wm-attached__file"},vg={class:"wm-attached__fileMeta"},bg={class:"wm-attached__fileName"},wg={key:0,class:"wm-attached__fileSize"},kg=["aria-label","onClick"],Cg={key:3,class:"wm-ended",role:"status","aria-live":"polite"},Sg={class:"wm-ended__lbl"};function Ag(e,t,n,r,i,s){const o=ve("Launcher"),a=ve("Header"),l=ve("History"),d=ve("Onboarding"),c=ve("MessageList"),m=ve("InlineCallbacks"),C=ve("FormCard"),b=ve("Feedback"),K=ve("Composer"),S=ve("MoreMenu"),J=ve("RenameDialog");return h(),p("div",{class:te(["wm-root",`wm-root--${n.displayMode}`]),style:Ce(s.rootStyle)},[!i.isOpen&&!s.isEmbedded?(h(),fe(o,{key:0,"unread-count":s.unreadCount,peeks:s.launcherPeeks,onOpen:s.openFromPeek,onDismiss:s.dismissPeek,onHover:s.onLauncherHover},null,8,["unread-count","peeks","onOpen","onDismiss","onHover"])):F("",!0),i.isOpen||s.isEmbedded?(h(),p("section",{key:1,class:te(["wm-panel",`wm-panel--${n.displayMode}`,{"wm-panel--welcome":s.ready&&!s.error&&!s.currentConv},i.launching?`wm-launch-${i.launchStage}`:""]),style:Ce(i.floatHeight?{"--wm-float-h":i.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger",onClick:t[7]||(t[7]=(...U)=>s.onPanelClick&&s.onPanelClick(...U))},[!s.ready&&!s.error?(h(),p("div",rg,[s.isEmbedded?F("",!0):(h(),p("button",{key:0,type:"button",class:"wm-loading__close","aria-label":s.t("loading.minimize"),onClick:t[0]||(t[0]=(...U)=>s.close&&s.close(...U))},[...t[8]||(t[8]=[u("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,ig)),t[9]||(t[9]=u("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(h(),p(Z,{key:1},[pe(a,{title:s.headerTitle,"team-members":s.teamMembers,"response-label":s.responseLabel,"show-identity":!!s.currentConv,"show-back":s.canBack,"show-close":!s.isEmbedded,"more-active":i.moreOpen,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onBack:s.goHome,onMore:s.toggleMore,onClose:s.close},null,8,["title","team-members","response-label","show-identity","show-back","show-close","more-active","agent-name","agent-avatar-url","onBack","onMore","onClose"]),u("div",og,[pe(Qs,{name:"wm-none"},{default:Xn(()=>[s.error?(h(),p("div",ag,[u("div",lg,[t[10]||(t[10]=u("div",{class:"wm-state__errIcon"},[u("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})])],-1)),u("div",null,[u("div",cg,R(s.t("error.connectionFailed")),1),u("div",ug,R(s.error),1)])])])):!s.currentConv&&i.showHistory?(h(),fe(l,{key:"history",class:"wm-screen",threads:s.openThreads,onResume:s.onDrawerPick},null,8,["threads","onResume"])):s.currentConv?(h(),p("div",dg,[pe(c,{ref:"messageList",messages:s.displayedMessages,"streaming-active":s.streamingActive,"date-label":s.dateLabel,"conversation-id":s.currentConv?s.currentConv.id:null,"loading-more":s.paginationState.loading,"has-more":s.paginationState.hasMore,"unread-anchor-id":e.unreadAnchorId,"unread-boundary-ts":e.unreadBoundaryTs,"ai-agent-name":s.agentName,"ai-agent-avatar-url":s.agentAvatarUrl,onLoadMore:s.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","unread-anchor-id","unread-boundary-ts","ai-agent-name","ai-agent-avatar-url","onLoadMore"]),u("div",fg,[s.floatVisible?(h(),p("div",hg,[s.pendingApproval?(h(),fe(m,{key:`appr-${s.pendingApproval.id}`,variant:"buttons",items:s.approvalCallbacks,onSelect:s.onApprovalSelect},null,8,["items","onSelect"])):s.pendingResolution?(h(),fe(m,{key:`res-${s.pendingResolution.id}`,variant:"buttons",items:s.resolutionCallbacks,onSelect:s.onResolutionSelect},null,8,["items","onSelect"])):s.pendingForm?(h(),fe(C,{key:s.pendingForm.message&&s.pendingForm.message.id,form:s.pendingForm.form,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onSubmit:s.onFormSubmit},null,8,["form","agent-name","agent-avatar-url","onSubmit"])):s.showFeedback?(h(),fe(b,{key:3,busy:i.feedbackBusy,done:!!(s.currentConv&&i.feedbackDone[s.currentConv.id]),onSubmit:s.onFeedback},null,8,["busy","done","onSubmit"])):(h(),fe(m,{key:4,items:s.suggestions,onSelect:s.onSuggestion},null,8,["items","onSelect"]))],512)):F("",!0),s.actionInFlight?(h(),p("div",mg,[t[11]||(t[11]=u("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),u("span",gg,R(s.t("action.inProgress",{name:s.actionInFlightName})),1)])):F("",!0),i.pendingAttachments.length?(h(),p("div",pg,[(h(!0),p(Z,null,Se(i.pendingAttachments,(U,$)=>(h(),p("div",{key:U.path||$,class:"wm-attached__item"},[U.previewUrl?(h(),p("img",{key:0,class:"wm-attached__thumb",src:U.previewUrl,alt:U.name},null,8,_g)):(h(),p("div",yg,[t[12]||(t[12]=u("span",{class:"wm-attached__fileIcon"},[u("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.7","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),u("path",{d:"M14 2v6h6"})])],-1)),u("span",vg,[u("span",bg,R(U.name),1),s.formatAttachmentSize(U.size_bytes)?(h(),p("span",wg,R(s.formatAttachmentSize(U.size_bytes)),1)):F("",!0)])])),u("button",{type:"button",class:"wm-attached__remove","aria-label":s.t("attachment.remove"),onClick:ne=>s.removePendingAttachment($)},[...t[13]||(t[13]=[u("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,kg)]))),128))])):F("",!0),s.endedBlockVisible?(h(),p("div",Cg,[u("span",Sg,R(s.isClosed?s.t("composer.conversationClosed"):s.t("composer.conversationEnded")),1),u("button",{type:"button",class:"wm-ended__btn",onClick:t[2]||(t[2]=U=>s.isClosed?s.onReopen():s.startConv())},R(s.isClosed?s.t("composer.reopen"):s.t("composer.newConversation")),1)])):s.actionInFlight?F("",!0):(h(),fe(K,{key:4,ref:"composer",modelValue:i.draft,"onUpdate:modelValue":t[3]||(t[3]=U=>i.draft=U),placeholder:s.composerPlaceholder,"attach-label":s.t("composer.attachFile"),"display-mode":n.displayMode,onSend:s.onSend,onAttach:s.onAttach},null,8,["modelValue","placeholder","attach-label","display-mode","onSend","onAttach"]))]),i.moreOpen?(h(),fe(S,{key:0,"can-rename":!!s.currentConv&&!s.currentConv._draft,"can-export":!!s.currentConv&&!s.currentConv._draft,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[4]||(t[4]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["can-rename","can-export","sound-enabled","status-url","help-url","onSoundToggle","onAction"])):F("",!0),i.renameDialogOpen&&s.currentConv&&!s.currentConv._draft?(h(),fe(J,{key:1,"initial-value":s.currentConv.name||"",title:s.t("rename.dialogTitle"),onClose:t[5]||(t[5]=U=>i.renameDialogOpen=!1),onSubmit:s.onRenameSubmit},null,8,["initial-value","title","onSubmit"])):F("",!0)])):(h(),fe(d,{key:"home",class:"wm-screen",title:s.widgetTitle,subtitle:s.widgetSubtitle,"agent-name":s.agentName,"default-icon-url":s.defaultIconUrl,"cover-image-url":s.coverImageUrl,"quick-links":s.quickLinks,"open-threads":s.openThreads,busy:i.busy,launching:i.launching,"welcome-message":s.widgetWelcomeMessage,onStart:s.onOnboardingStart,onLaunched:s.onHomeLaunched,onSelect:s.onQuickLink,onResume:s.onDrawerPick,onViewHistory:t[1]||(t[1]=U=>i.showHistory=!0)},null,8,["title","subtitle","agent-name","default-icon-url","cover-image-url","quick-links","open-threads","busy","launching","welcome-message","onStart","onLaunched","onSelect","onResume"]))]),_:1})]),i.moreOpen&&!s.currentConv?(h(),fe(S,{key:0,"can-rename":!1,"can-export":!1,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[6]||(t[6]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["sound-enabled","status-url","help-url","onSoundToggle","onAction"])):F("",!0)],64))],6)):F("",!0)],6)}const xg=be(sg,[["render",Ag],["__scopeId","data-v-801581ca"]]),ni=window.__WIDGET_ID,si=window.__BASE_URL,Tg=window.__DISPLAY_MODE||"floating",ri=window.__LANGUAGE||"";window.__MESSENGER_IFRAME_VERSION="0.6.28";if(!ni||!si)console.error("[messenger-iframe] missing __WIDGET_ID or __BASE_URL globals");else{if(!document.getElementById("wm-tokens")){const e=document.createElement("style");e.id="wm-tokens",e.textContent=Ao,document.head.appendChild(e)}sc({render:()=>wo(xg,{baseUrl:si,widgetId:ni,displayMode:Tg,...ri?{language:ri}:{}})}).mount("#app")}