@_solaris/messenger-widget 0.5.60 → 0.5.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/iframe/iframe.css +1 -1
- package/dist/iframe/iframe.js +1 -1
- package/dist/messenger.cjs +2 -2
- package/dist/messenger.js +81 -73
- package/dist/snippet.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/iframe/iframe.js
CHANGED
|
@@ -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 f=[];for(;r<t.length&&!/^\s*```\s*$/.test(t[r]);)f.push(t[r]),r++;r<t.length&&r++,n.push({type:"block",html:`<pre class="wm-md-pre"><code>${f.join(`
|
|
72
72
|
`)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(s)){const f=[];for(;r<t.length;){const p=/^\s*[-*]\s+(.*)$/.exec(t[r]);if(!p)break;f.push(p[1]),r++}const c=f.map(p=>`<li>${sn(p)}</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 f=parseInt(a[1],10),c=[a[2]];for(r++;r<t.length;){const w=/^\s*\d+\.\s+(.*)$/.exec(t[r]);if(!w)break;c.push(w[1]),r++}const p=c.map(w=>`<li>${sn(w)}</li>`).join(""),S=f!==1?` start="${f}"`:"";n.push({type:"block",html:`<ol class="wm-md-ol"${S}>${p}</ol>`});continue}const l=/^(#{1,6})\s+(.*)$/.exec(s);if(l){const f=l[1].length;n.push({type:"block",html:`<h${f} class="wm-md-h wm-md-h${f}">${sn(l[2])}</h${f}>`}),r++;continue}n.push({type:"text",html:sn(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 wn(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 ft(e){if(e==null)return null;const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:null}function Jr(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 Sc(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 xc(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=Sc(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 Tc(e,t,n=xe(),r){if(!e)return;const i=xc(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 Mc={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||!wn(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)}}}},Zt=Object.freeze({firstRevealDelayMs:450,msPerChar:50,minTypingMs:900,maxTypingMs:12e3,pauseBetweenMs:300}),en=(e,t)=>Number.isFinite(e)?e:t,Ec={computed:{revealPacing(){var t;const e=((t=this.widget)==null?void 0:t.reveal_pacing)||{};return{firstRevealDelayMs:en(e.first_reveal_delay_ms,Zt.firstRevealDelayMs),msPerChar:en(e.ms_per_char,Zt.msPerChar),minTypingMs:en(e.min_typing_ms,Zt.minTypingMs),maxTypingMs:en(e.max_typing_ms,Zt.maxTypingMs),pauseBetweenMs:en(e.pause_between_ms,Zt.pauseBetweenMs)}}},data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[],_liveRevealOff:null,_liveRevealConvSnapshot:null}},methods:{cancelReveals(){for(const e of this.revealTimers)clearTimeout(e);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},setupLiveReveal(){var n;if(!this.transport)return;this.teardownLiveReveal();const e=this.transport.on("message",r=>{const i=r==null?void 0:r.conversation_id,s=r==null?void 0:r.message;i&&s&&this.paceLiveMessage(s,i)});this._liveRevealConvSnapshot=new Map((((n=this.s)==null?void 0:n.conversations)||[]).map(r=>[r.id,(r==null?void 0:r.last_message_at)||""]));const t=this.transport.on("activity",r=>{this.handleLiveActivity(r)});this._liveRevealOff=()=>{try{e()}catch{}try{t()}catch{}}},teardownLiveReveal(){if(this._liveRevealOff){try{this._liveRevealOff()}catch{}this._liveRevealOff=null}this._liveRevealConvSnapshot=null},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),f=e.id,c=setTimeout(()=>{this.revealedAt={...this.revealedAt,[f]:Date.now()},this.revealTimers=this.revealTimers.filter(p=>p!==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(!wn(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 i;if(!(e!=null&&e.id)||this.revealedAt[e.id]!==void 0)return;if(!wn(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((i=e==null?void 0:e.payload)==null?void 0:i.attachments)&&e.payload.attachments.length>0;if(!n&&!r){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}this.revealedAt={...this.revealedAt,[e.id]:0},this.scheduleReveal(e,t)}}},Oc={data(){return{approvalSettled:!0,approvalSettleTimer:null,approvalLatchId:null}},methods:{resetApprovalPacing(){this.approvalSettleTimer&&(clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=null),this.approvalSettled=!0,this.approvalLatchId=null},bumpApprovalSettle(e=800){this.approvalSettled=!1,this.approvalSettleTimer&&clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=setTimeout(()=>{this.approvalSettled=!0,this.approvalSettleTimer=null},e)}}},Ic=300,Rc={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=ft(e.last_read_message_id),i=ft(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)},Ic))))}}};function Lc(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(!(!n||n._pending)&&ft(n.id)!=null)return n.id}return null}const we=(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":Qs(this.name)},initials(){return Zs(this.name)}}},Bc=["src","alt"];function Dc(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-huav",{"wm-huav--tail":n.tail}]),style:Oe({width:n.size+"px",height:n.size+"px","--wm-avr":Math.round(n.size*.32)+"px",background:s.bg})},[n.avatarUrl?(h(),g("img",{key:0,src:n.avatarUrl,alt:n.name||""},null,8,Bc)):(h(),g("span",{key:1,style:Oe({fontSize:n.size*.36+"px"})},R(s.initials),5))],6)}const ss=we(Pc,[["render",Dc],["__scopeId","data-v-14e10c0d"]]),Fc=3,Nc={name:"WmLauncher",components:{HumanAvatar:ss},inject:{t:{default:()=>xe()}},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,Fc).reverse()}}},jc=["aria-label","onClick","onKeydown"],Hc=["aria-label","onClick"],Uc={class:"wm-peek__avatar"},$c=["aria-label"],Vc={class:"wm-peek__body"},Kc={class:"wm-peek__head"},Wc={class:"wm-peek__name"},zc={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=ye("HumanAvatar");return h(),g("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))},[ve(ko,{name:"wm-peek"},{default:zs(()=>[s.visiblePeeks.length?(h(),g("div",{key:0,class:re(["wm-peekStack",{"wm-peekStack--multi":s.visiblePeeks.length>1}])},[(h(!0),g(ee,null,Ae(s.visiblePeeks,(a,l)=>(h(),g("div",{key:a.convId,class:"wm-peek",style:Oe({"--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:f=>e.$emit("open",a.convId),onKeydown:[Hn(ht(f=>e.$emit("open",a.convId),["prevent"]),["enter"]),Hn(ht(f=>e.$emit("open",a.convId),["prevent"]),["space"])]},[u("button",{type:"button",class:"wm-peek__close","aria-label":s.t("launcher.dismiss"),onClick:ht(f=>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,Hc),u("div",Uc,[ve(o,{name:a.senderName,"avatar-url":a.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),a.count>1?(h(),g("span",{key:0,class:"wm-peek__avatarBadge","aria-label":s.t("launcher.unreadMessages",{count:a.count})},R(a.count>9?"9+":a.count),9,$c)):D("",!0)]),u("div",Vc,[u("div",Kc,[u("span",Wc,R(a.senderName||s.t("common.agent")),1),u("span",zc,R(s.t("launcher.repliedToYou")),1)]),u("p",qc,R(a.preview),1)]),u("button",{type:"button",class:"wm-peek__open",onClick:ht(f=>e.$emit("open",a.convId),["stop"])},R(s.t("common.open")),9,Gc)],44,jc))),128))],2)):D("",!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(),g("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)):D("",!0)],8,Yc)],32)}const Qc=we(Nc,[["render",Xc],["__scopeId","data-v-44ddf1a1"]]),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 Zs(this.name)},bgColor(){return Qs(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(),g("div",{class:re(["wm-aiav",{"wm-aiav--tail":n.tail}]),style:Oe({width:n.size+"px",height:n.size+"px","--wm-avr":n.size*.32+"px"})},[n.pulse?(h(),g("div",eu)):D("",!0),u("div",{class:re(["wm-aiav__inner",{"wm-aiav__inner--glow":n.pulse,"wm-aiav__inner--img":!!n.imageUrl,"wm-aiav__inner--initials":!n.imageUrl&&!!s.initials}]),style:Oe(!n.imageUrl&&s.initials?{background:s.bgColor}:null)},[n.imageUrl?(h(),g("img",{key:0,src:n.imageUrl,alt:n.name||""},null,8,tu)):s.initials?(h(),g("span",{key:1,style:Oe({fontSize:n.size*.36+"px"})},R(s.initials),5)):(h(),g("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 qt=we(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":Qs(e.name||"")},initialsFor(e){return Zs(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(),g("div",iu,[u("div",{class:"wm-team__stack",style:Oe({width:s.stackWidth+"px"})},[(h(!0),g(ee,null,Ae(n.members.slice(0,3),(o,a)=>(h(),g("div",{key:a,class:"wm-team__pill",style:Oe({left:a*13+"px",zIndex:3-a,background:s.colorFor(o)})},[o.avatar_url?(h(),g("img",{key:0,src:o.avatar_url,alt:o.name||""},null,8,ou)):(h(),g("span",au,R(s.initialsFor(o)),1))],4))),128))],4),n.responseLabel?(h(),g("span",lu,R(n.responseLabel),1)):D("",!0)])):D("",!0)}const uu=we(ru,[["render",cu],["__scopeId","data-v-e49a9063"]]),du={name:"WmHeader",components:{AIAvatar:qt,TeamAvatars:uu},inject:{t:{default:()=>xe()}},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"}},pu={class:"wm-header__avatar"},gu={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=ye("AIAvatar"),a=ye("TeamAvatars");return h(),g("div",fu,[n.showBack?(h(),g("button",{key:0,type:"button",class:"wm-header__icon","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(),g("div",mu)),n.showIdentity?(h(),g(ee,{key:2},[u("div",pu,[ve(o,{size:30,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",gu,[u("div",_u,R(n.title),1)]),s.hasTeam?(h(),ge(a,{key:0,members:s.displayedTeamMembers,"response-label":""},null,8,["members"])):D("",!0)],64)):(h(),g("div",yu)),u("div",vu,[n.showMore?(h(),g("button",{key:0,type:"button",class:re(["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)):D("",!0),n.showClose?(h(),g("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)):D("",!0)])])}const Cu=we(du,[["render",ku],["__scopeId","data-v-7af4c118"]]),Xr={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"},Au={name:"WmOnboarding",components:{AIAvatar:qt,HumanAvatar:ss},inject:{t:{default:()=>xe()},wmLocale:{default:()=>()=>"fr"}},props:{title:{type:String,default:""},subtitle:{type:String,default:""},agentName:{type:String,default:""},defaultIconUrl:{type:String,default:null},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1}},emits:["start","select","resume","view-history"],computed:{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)}},methods:{iconPath(e){return Xr[e]||Xr.link},isExternalLink(e){const t=e==null?void 0:e.url;return!!t&&!t.startsWith("#")},safeIconUrl(e){return vc(e==null?void 0:e.icon_url)},iconUrlStyle(e){const t=this.safeIconUrl(e);return t?{"--icon-url":`url("${t}")`}:null},renderPreview(e){return To(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"})}}},Su={class:"wm-onb"},xu={class:"wm-onb__hero"},Tu={class:"wm-onb__hero-text"},Mu={class:"wm-onb__title"},Eu={class:"wm-onb__sub"},Ou={key:0,class:"wm-onb__alertList"},Iu=["onClick"],Ru={key:0,class:"wm-onb__defaultAvatar"},Lu=["aria-label"],Pu={class:"wm-onb__alert-body"},Bu={class:"wm-onb__alert-title"},Du={class:"wm-onb__alert-preview"},Fu={key:0,class:"wm-onb__alert-sender"},Nu=["innerHTML"],ju={class:"wm-onb__alert-meta"},Hu={key:0,class:"wm-onb__alert-time"},Uu={class:"wm-onb__alert-resume"},$u={class:"wm-onb__actions"},Vu=["disabled"],Ku={class:"wm-onb__btn-label"},Wu=["onClick"],zu={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"};function sd(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",Su,[u("div",xu,[t[2]||(t[2]=u("svg",{class:"wm-onb__hero-deco",width:"180",height:"180",viewBox:"0 0 180 180",fill:"none","aria-hidden":"true"},[u("circle",{cx:"170",cy:"10",r:"105",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.35"}),u("circle",{cx:"170",cy:"10",r:"72",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.5"}),u("circle",{cx:"152",cy:"34",r:"2.5",fill:"#5B5FEF",opacity:"0.65"})],-1)),ve(o,{size:52,"image-url":n.defaultIconUrl},null,8,["image-url"]),u("div",Tu,[u("div",Mu,R(s.heroTitle),1),u("div",Eu,R(s.heroSub),1)])]),s.unreadThreads.length?(h(),g("div",Ou,[(h(!0),g(ee,null,Ae(s.unreadThreads,a=>(h(),g("button",{key:a.id,type:"button",class:"wm-onb__alert",onClick:l=>e.$emit("resume",a)},[u("span",{class:re(["wm-onb__alert-avatar",s.avatarWrapperClass(a)])},[s.isDefaultAvatar(a)?(h(),g("span",Ru,[...t[3]||(t[3]=[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(),ge(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,Lu)],2),u("span",Pu,[u("span",Bu,R(a.title),1),u("span",Du,[s.senderLabel(a)?(h(),g("span",Fu,R(s.senderLabel(a))+" · ",1)):D("",!0),u("span",{innerHTML:s.renderPreview(a.preview)},null,8,Nu)])]),u("span",ju,[s.formatTs(a._ts)?(h(),g("span",Hu,R(s.formatTs(a._ts)),1)):D("",!0),u("span",Uu,R(s.t("onboarding.resume")),1)])],8,Iu))),128))])):D("",!0),u("div",$u,[u("button",{type:"button",class:"wm-onb__btn wm-onb__btn--start",disabled:n.busy,onClick:t[0]||(t[0]=a=>e.$emit("start"))},[t[4]||(t[4]=u("span",{class:"wm-onb__btn-icon"},[u("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M12 5v14M5 12h14"})])],-1)),u("span",Ku,R(n.busy?"…":s.t("onboarding.start")),1)],8,Vu),(h(!0),g(ee,null,Ae(n.quickLinks,(a,l)=>(h(),g("button",{key:"ql-"+l,type:"button",class:"wm-onb__btn",onClick:f=>e.$emit("select",a)},[u("span",zu,[s.safeIconUrl(a)?(h(),g("span",{key:0,class:"wm-onb__btn-iconImg",style:Oe(s.iconUrlStyle(a)),role:"img","aria-label":a.label||""},null,12,qu)):(h(),g("svg",Gu,[u("path",{d:s.iconPath(a.icon)},null,8,Yu)]))]),u("span",Ju,R(a.label),1),s.isExternalLink(a)?(h(),g("svg",Xu,[...t[5]||(t[5]=[u("path",{d:"M7 17L17 7M9 7h8v8"},null,-1)])])):D("",!0)],8,Wu))),128)),n.openThreads.length?(h(),g("button",{key:0,type:"button",class:"wm-onb__btn",onClick:t[1]||(t[1]=a=>e.$emit("view-history"))},[u("span",Qu,[(h(),g("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[6]||(t[6]=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))])):D("",!0)])])}const rd=we(Au,[["render",sd],["__scopeId","data-v-136c3afe"]]),id={name:"WmHistory",components:{AIAvatar:qt,HumanAvatar:ss},inject:{t:{default:()=>xe()},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 To(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"})}}},od={class:"wm-hist"},ad={class:"wm-hist__search"},ld=["placeholder","aria-label"],cd={class:"wm-hist__list"},ud=["onClick"],dd={key:0,class:"wm-hist__defaultAvatar"},fd=["aria-label"],hd={class:"wm-hist__thread-body"},md={class:"wm-hist__thread-title"},pd=["innerHTML"],gd={class:"wm-hist__thread-meta"},_d={key:0,class:"wm-hist__thread-time"},yd={key:0,class:"wm-hist__empty"};function vd(e,t,n,r,i,s){return h(),g("div",od,[u("div",ad,[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)),at(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,ld),[[Rt,i.query]])]),u("div",cd,[(h(!0),g(ee,null,Ae(s.filteredThreads,o=>(h(),g("button",{key:o.id,type:"button",class:re(["wm-hist__thread",{"wm-hist__thread--unread":o.unread}]),onClick:a=>e.$emit("resume",o)},[u("span",{class:re(["wm-hist__thread-avatar",s.avatarWrapperClass(o)])},[s.isDefaultAvatar(o)?(h(),g("span",dd,[...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(),ge(qs(s.avatarComponent(o)),Xs({key:1,ref_for:!0},s.avatarProps(o)),null,16)),o.unread?(h(),g("span",{key:2,class:"wm-hist__thread-dot","aria-label":s.t("onboarding.unread")},null,8,fd)):D("",!0)],2),u("span",hd,[u("span",md,R(o.title),1),u("span",{class:"wm-hist__thread-preview",innerHTML:s.renderPreview(o.preview)},null,8,pd)]),u("span",gd,[s.formatTs(o._ts)?(h(),g("span",_d,R(s.formatTs(o._ts)),1)):D("",!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,ud))),128)),s.filteredThreads.length?D("",!0):(h(),g("div",yd,R(i.query?s.t("onboarding.noResults",{query:i.query}):s.t("onboarding.noConversations")),1))])])}const bd=we(id,[["render",vd],["__scopeId","data-v-6bf35ef1"]]);function wd(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 kd={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return wd(this.detail)}}},Cd={class:"wm-result__icon","aria-hidden":"true"},Ad={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"},Sd={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"},xd={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"},Td={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"},Md={class:"wm-result__body"},Ed={class:"wm-result__label"},Od={class:"wm-result__detail"};function Id(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-result",`wm-result--${n.state}`])},[u("span",Cd,[n.state==="success"?(h(),g("svg",Ad,[...t[0]||(t[0]=[u("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):n.state==="rejected"?(h(),g("svg",Sd,[...t[1]||(t[1]=[u("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):n.state==="awaiting"?(h(),g("svg",xd,[...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(),g("svg",Td,[...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",Md,[u("span",Ed,R(n.label),1),s.detailText?(h(),g(ee,{key:0},[t[4]||(t[4]=u("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),u("span",Od,R(s.detailText),1)],64)):D("",!0)])],2)}const Rd=we(kd,[["render",Id],["__scopeId","data-v-7284acd0"]]),Ld={name:"WmArtifactFormResponse",inject:{t:{default:()=>xe()}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]}}},Pd={class:"wm-art wm-art--formResponse"},Bd={class:"wm-art__head"},Dd={class:"wm-art__title"},Fd={class:"wm-art__badge wm-art__badge--success"},Nd={class:"wm-art__body"},jd={class:"wm-art__fieldLabel"};function Hd(e,t,n,r,i,s){return h(),g("div",Pd,[u("div",Bd,[u("div",Dd,R(n.data.title||s.t("form.title")),1),u("span",Fd,[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)),ts(" "+R(s.t("form.sent")),1)])]),u("div",Nd,[(h(!0),g(ee,null,Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",jd,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128))])])}const Ud=we(Ld,[["render",Hd],["__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}}},Vd={class:"wm-art wm-art--infoCard"},Kd={key:0,class:"wm-art__image"},Wd=["src","alt"],zd={class:"wm-art__head"},qd={class:"wm-art__headMain"},Gd={class:"wm-art__title"},Yd={key:0,class:"wm-art__subtitle"},Jd={key:1,class:"wm-art__body"},Xd={key:0,class:"wm-art__text"},Qd={class:"wm-art__fieldLabel"};function Zd(e,t,n,r,i,s){return h(),g("div",Vd,[n.data.image_url?(h(),g("figure",Kd,[u("img",{src:n.data.image_url,alt:n.data.title||"",loading:"lazy"},null,8,Wd)])):D("",!0),u("div",zd,[u("div",qd,[u("div",Gd,R(n.data.title),1),n.data.subtitle?(h(),g("div",Yd,R(n.data.subtitle),1)):D("",!0)]),n.data.badge&&n.data.badge.label?(h(),g("span",{key:0,class:re(["wm-art__badge",`wm-art__badge--${n.data.badge.tone||"neutral"}`])},R(n.data.badge.label),3)):D("",!0)]),s.hasBody?(h(),g("div",Jd,[n.data.body?(h(),g("div",Xd,R(n.data.body),1)):D("",!0),s.fields.length?(h(!0),g(ee,{key:1},Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",Qd,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128)):D("",!0)])):D("",!0)])}const ef=we($d,[["render",Zd],["__scopeId","data-v-7eae0e4a"]]);function tf(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 nf={name:"WmArtifactTicket",inject:{t:{default:()=>xe()},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 tf((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}}},sf={class:"wm-art wm-art--ticket"},rf={class:"wm-art__head wm-tk__head"},of={class:"wm-art__title wm-tk__title"},af={class:"wm-tk__sub"},lf={class:"wm-tk__ref"},cf={key:0,class:"wm-tk__text"},uf={key:0,class:"wm-art__body"},df={class:"wm-art__fieldLabel"},ff=["data-level"],hf={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"},mf={key:1,class:"wm-art__footer wm-tk__footer"};function pf(e,t,n,r,i,s){return h(),g("div",sf,[u("div",rf,[u("div",of,R(n.data.title),1),u("div",af,[u("div",lf,[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:re(["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)),ts(" "+R(n.data.status.label),1)],2)]),n.data.body?(h(),g("div",cf,R(n.data.body),1)):D("",!0)]),s.fields.length?(h(),g("div",uf,[(h(!0),g(ee,null,Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",df,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},[s.isPriority(o.label)?(h(),g("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,ff)):s.isDate(o.label)?(h(),g("svg",hf,[...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)])])):D("",!0),u("span",null,R(o.value),1)],2)]))),128))])):D("",!0),n.data.created_at?(h(),g("div",mf,[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)])):D("",!0)])}const gf=we(nf,[["render",pf],["__scopeId","data-v-5f30c914"]]),_f={form_response:Ud,info_card:ef,ticket:gf},yf={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const e=(t=this.artifact)==null?void 0:t.kind;return e&&_f[e]||null}}};function vf(e,t,n,r,i,s){return s.component?(h(),ge(qs(s.component),{key:0,data:n.artifact.data},null,8,["data"])):D("",!0)}const bf=we(yf,[["render",vf]]),wf={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null},t:{default:()=>xe()}},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()}}},kf=["href"],Cf=["src","alt"],Af=["src"],Sf=["src"],xf=["href","download"],Tf={class:"wm-att__main"},Mf={class:"wm-att__name"},Ef={key:0,class:"wm-att__meta"},Of={key:0,class:"wm-att__spin","aria-hidden":"true"};function If(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-att",["wm-att--"+(s.kind||"file")]])},[s.kind==="image"&&i.url?(h(),g("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,Cf)],8,kf)):s.kind==="audio"&&i.url?(h(),g("audio",{key:1,src:i.url,controls:"",preload:"metadata"},null,8,Af)):s.kind==="video"&&i.url?(h(),g("video",{key:2,src:i.url,controls:"",preload:"metadata"},null,8,Sf)):(h(),g("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",Tf,[u("span",Mf,R(s.displayName),1),s.sizeLabel?(h(),g("span",Ef,R(s.sizeLabel),1)):D("",!0)]),i.loading?(h(),g("span",Of)):D("",!0)],8,xf))],2)}const Rf=we(wf,[["render",If],["__scopeId","data-v-0c877a62"]]),Lf={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return Cc(this.text)}}},Pf=["innerHTML"];function Bf(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-bubble","wm-bubble--"+n.role])},[Ba(e.$slots,"default",{},()=>[u("span",{innerHTML:s.rendered},null,8,Pf)])],2)}const Df=we(Lf,[["render",Bf],["__scopeId","data-v-7ab13147"]]),Ff={name:"WmTyping"},Nf={class:"wm-typing"};function jf(e,t,n,r,i,s){return h(),g("div",Nf,[...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 Hf=we(Ff,[["render",jf],["__scopeId","data-v-df2447fd"]]);function Et(e){return e?e.client_msg_id||e.id:""}const Uf={transferred_to_human:"system.transferredToHuman",assigned:"system.assigned",unassigned:"system.unassigned",resolved:"system.resolved",reopened:"system.reopened",idle:"system.idle"},$f=80,Vf=200,Kf={name:"WmMessageList",components:{AIAvatar:qt,HumanAvatar:ss,Bubble:Df,Typing:Hf,ActionResult:Rd,AttachmentPreview:Rf,ArtifactRenderer:bf},inject:{t:{default:()=>xe()},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;const e=[];for(const o of this.messages){const a=this.roleOf(o);if(a==="system"){if(((n=o==null?void 0:o.payload)==null?void 0:n.event)==="action_admin_pending"){const c=e[e.length-1];c&&c.role==="ai"?c.messages.push(o):e.push({key:`g-${Et(o)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[o],items:[]});continue}e.push({key:`sys-${Et(o)}`,role:a,messages:[o],items:[],systemLabel:this.systemLabel(o)});continue}const l=e[e.length-1];l&&l.role===a&&(a==="ai"||l.agentName===(((r=o==null?void 0:o.author)==null?void 0:r.name)||""))?l.messages.push(o):e.push({key:`g-${Et(o)}`,role:a,agentName:((i=o==null?void 0:o.author)==null?void 0:i.name)||"",agentAvatarUrl:((s=o==null?void 0:o.author)==null?void 0:s.avatar_url)||null,messages:[o],items:[]})}for(const o of e){if(o.role==="system")continue;const a=[];for(const l of o.messages)for(const f of this.itemsOf(l))a.push(f);o.items=a}const t=[];for(const o of e){if(o.role!=="system"&&!o.items.length)continue;const a=t[t.length-1];if(a&&a.role!=="system"&&a.role===o.role&&(o.role==="ai"||a.agentName===o.agentName)){a.messages.push(...o.messages),a.items.push(...o.items);continue}t.push(o)}for(const o of t)o.role!=="system"&&(o.key=this.stableGroupKey(o.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=ft(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._pressTimer&&clearTimeout(this._pressTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:Et,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=Et(r);if(i&&t.has(i)){n=t.get(i);break}}n==null&&(n=++this._groupIdCounter);for(const r of e){const i=Et(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<=Vf&&(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 f=a.getBoundingClientRect().top-e.getBoundingClientRect().top-o.relY;Math.abs(f)>.5&&(e.scrollTop+=f)};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 $,se,_e;const n=e.items,r=($=n[t])==null?void 0:$.kind,i=(se=n[t-1])==null?void 0:se.kind,s=(_e=n[t+1])==null?void 0:_e.kind,o=e.role==="user",a=14,l=4,f=i==null?void 0:i.bottom,c=s==null?void 0:s.top,p=this.widthByKey[this.rowKeyOf(e,t)],S=this.widthByKey[this.rowKeyOf(e,t-1)],w=this.widthByKey[this.rowKeyOf(e,t+1)],V=.5,O=(he,ke,G)=>he!=null&&p!=null?he+V>=p:ke===G||ke==="card"&&G==="bubble";let J=a,z=a,U=a,Q=a;return o?(f&&(z=l),(c||!s)&&(U=l),f&&O(S,f,r==null?void 0:r.top)&&(J=l),c&&O(w,c,r==null?void 0:r.bottom)&&(Q=l)):(f&&(J=l),(c||!s)&&(Q=l),f&&O(S,f,r==null?void 0:r.top)&&(z=l),c&&O(w,c,r==null?void 0:r.bottom)&&(U=l)),{tl:J,tr:z,br:U,bl:Q}},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?`${Et(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 Ps(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 Ps(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;const t=e==null?void 0:e.payload;return t?t.state==="success"?((n=t.success)==null?void 0:n.summary)||((i=(r=t.success)==null?void 0:r.metadata)==null?void 0:i.description)||"":t.state==="rejected"?((s=t.rejected)==null?void 0:s.reason)||this.t("action.rejectedByUser"):t.state==="failure"&&(((o=t.failure)==null?void 0:o.summary)||((a=t.failure)==null?void 0:a.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=Uf[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},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)}}},Wf={class:"wm-list__wrap"},zf={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},qf={class:"wm-list__loadMore-lbl"},Gf={key:1,class:"wm-list__historyEnd"},Yf={key:2,class:"wm-list__sep"},Jf={class:"wm-list__sep-label"},Xf={key:0,class:"wm-list__sep wm-list__sep--unread"},Qf={class:"wm-list__sep-label wm-list__sep-label--unread"},Zf={key:0,class:"wm-list__sysep"},eh={class:"wm-list__sysep-label"},th=["data-row-key","onPointerdown"],nh={key:0,class:"wm-list__avatarSlot"},sh={key:5,class:"wm-list__body"},rh={key:0},ih={key:1,"aria-hidden":"true"},oh={key:2},ah={key:0},lh={key:1,"aria-hidden":"true"},ch={key:2},uh={key:3,class:"wm-list__row wm-list__row--ai fade-up"},dh={class:"wm-list__avatarSlot"},fh=["aria-label","title"];function hh(e,t,n,r,i,s){const o=ye("AIAvatar"),a=ye("HumanAvatar"),l=ye("ActionResult"),f=ye("ArtifactRenderer"),c=ye("Bubble"),p=ye("AttachmentPreview"),S=ye("Typing");return h(),g("div",Wf,[u("div",{ref:"scrollEl",class:re(["wm-list",{"wm-list--silent":i.silentFades}]),onScrollPassive:t[4]||(t[4]=(...w)=>s.onScroll&&s.onScroll(...w))},[n.loadingMore?(h(),g("div",zf,[t[6]||(t[6]=u("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1)),u("span",qf,R(s.t("messageList.loadingHistory")),1)])):s.historyExhausted?(h(),g("div",Gf,R(s.t("messageList.conversationStart")),1)):D("",!0),n.dateLabel?(h(),g("div",Yf,[t[7]||(t[7]=u("div",{class:"wm-list__line"},null,-1)),u("span",Jf,R(n.dateLabel),1),t[8]||(t[8]=u("div",{class:"wm-list__line"},null,-1))])):D("",!0),(h(!0),g(ee,null,Ae(s.groups,(w,V)=>(h(),g(ee,{key:w.key},[w.key===s.unreadGroupKey?(h(),g("div",Xf,[t[9]||(t[9]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1)),u("span",Qf,R(s.t("messageList.unread")),1),t[10]||(t[10]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1))])):D("",!0),w.role==="system"||w.items.length?(h(),g("div",{key:1,class:re(["wm-list__group","wm-list__group--"+w.role])},[w.role==="system"?(h(),g("div",Zf,[t[11]||(t[11]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),u("span",eh,R(w.systemLabel),1),t[12]||(t[12]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(h(),g(ee,{key:1},[(h(!0),g(ee,null,Ae(w.items,(O,J)=>(h(),g(ee,{key:`${s.messageKey(O.message)}-${O.partKey}`},[u("div",{"data-row-key":`${s.messageKey(O.message)}-${O.partKey}`,class:re(["wm-list__row fade-up",["wm-list__row--"+w.role,{"is-pending":O.message._pending,"is-failed":O.message._failed}]]),style:Oe(s.cornersStyle(w,J)),onPointerdown:z=>s.onPressStart(`${s.messageKey(O.message)}-${O.partKey}`),onPointerup:t[0]||(t[0]=z=>s.onPressEnd()),onPointercancel:t[1]||(t[1]=z=>s.onPressEnd()),onPointerleave:t[2]||(t[2]=z=>s.onPressEnd()),onContextmenu:t[3]||(t[3]=ht(()=>{},["prevent"]))},[w.role!=="user"?(h(),g("div",nh,[J===w.items.length-1?(h(),g(ee,{key:0},[w.role==="ai"?(h(),ge(o,{key:0,size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])):(h(),ge(a,{key:1,name:w.agentName,"avatar-url":w.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):D("",!0)])):D("",!0),O.renderAs==="action"?(h(),ge(l,{key:1,state:O.message.payload.state,label:s.actionLabel(O.message),detail:s.actionDetail(O.message)},null,8,["state","label","detail"])):O.renderAs==="admin-pending"?(h(),ge(l,{key:2,state:"awaiting",label:s.t("messageList.approvalRequestSent"),detail:O.message.text_md||""},null,8,["label","detail"])):O.renderAs==="artifact-of-action"?(h(),ge(f,{key:3,artifact:s.actionArtifact(O.message)},null,8,["artifact"])):O.renderAs==="artifact"?(h(),ge(f,{key:4,artifact:s.artifactOf(O.message)},null,8,["artifact"])):(h(),g("div",sh,[O.message.text_md?(h(),ge(c,{key:0,role:w.role,text:O.message.text_md},null,8,["role","text"])):D("",!0),s.attachmentsOf(O.message).length?(h(),g("div",{key:1,class:re(["wm-list__atts",{"wm-list__atts--align-end":w.role==="user"}])},[(h(!0),g(ee,null,Ae(s.attachmentsOf(O.message),(z,U)=>(h(),ge(p,{key:`${s.messageKey(O.message)}-att-${U}`,attachment:z},null,8,["attachment"]))),128))],2)):D("",!0)]))],46,th),J<w.items.length-1&&i.pressedItemKey===`${s.messageKey(O.message)}-${O.partKey}`&&(w.role!=="user"||s.timeOf(O.message))?(h(),g("div",{key:0,class:re(["wm-list__meta wm-list__meta--press",{"wm-list__meta--right":w.role==="user"}])},[w.role!=="user"?(h(),g("span",rh,R(s.roleLabel(w)),1)):D("",!0),w.role!=="user"&&s.timeOf(O.message)?(h(),g("span",ih,"•")):D("",!0),s.timeOf(O.message)?(h(),g("span",oh,R(s.timeOf(O.message)),1)):D("",!0)],2)):D("",!0)],64))),128)),(w.role!=="user"||s.lastTimeOf(w))&&!s.hasTrailingOverlay(w)?(h(),g("div",{key:0,class:re(["wm-list__meta",{"wm-list__meta--right":w.role==="user"}])},[w.role!=="user"?(h(),g("span",ah,R(s.roleLabel(w)),1)):D("",!0),w.role!=="user"&&s.lastTimeOf(w)?(h(),g("span",lh,"•")):D("",!0),s.lastTimeOf(w)?(h(),g("span",ch,R(s.lastTimeOf(w)),1)):D("",!0)],2)):D("",!0)],64))],2)):D("",!0)],64))),128)),n.streamingActive?(h(),g("div",uh,[u("div",dh,[ve(o,{size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])]),ve(S)])):D("",!0)],34),ve(ko,{name:"wm-scrollDown"},{default:zs(()=>[i.showScrollDown?(h(),g("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]=(...w)=>s.scrollToBottomSmooth&&s.scrollToBottomSmooth(...w))},[...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,fh)):D("",!0)]),_:1})])}const mh=we(Kf,[["render",hh],["__scopeId","data-v-cf20685c"]]),Un=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",tr=typeof window<"u"&&typeof window.MediaRecorder<"u";function ph(){return tr&&["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 Mo({audio:e}){return{video:!0,audio:!!e,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:e?"include":"exclude"}}async function gh(){if(!Un)return null;let e;try{e=await navigator.mediaDevices.getDisplayMedia(Mo({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await _h(e)}catch(t){return console.error("[media] screenshot capture",t),null}finally{e.getTracks().forEach(t=>{t.stop()})}}async function _h(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(f=>f?a(f):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 yh(e={}){var f;if(!Un||!tr)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Mo({audio:!0}))}catch(c){return(c==null?void 0:c.name)!=="NotAllowedError"&&console.error("[media] record picker",c),null}const n=ph();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(p=>{p.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,p;if(s&&clearInterval(s),t.getTracks().forEach(S=>{S.stop()}),i.length){const S=r.mimeType||n||"video/webm",w=new Blob(i,{type:S}),V=/mp4/.test(S)?"mp4":"webm",O=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),J=new File([w],`ecran-${O}.${V}`,{type:S});(c=e.onfinalize)==null||c.call(e,J)}else(p=e.oncancel)==null||p.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(p=>{p.stop()}),null}(f=e.onstart)==null||f.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 vh=[{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"}],bh={name:"WmComposer",inject:{t:{default:()=>xe()}},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"],data(){return{local:this.modelValue,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null,kbOffset:0}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},attachItems(){return vh.map(e=>({...e,label:this.t(e.labelKey),disabled:e.action==="screenshot"&&!Un||e.action==="record"&&(!Un||!tr)}))},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()}},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;e&&(e.clientWidth<80||(e.style.height="auto",e.style.height=`${e.scrollHeight}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 gh();e&&this.$emit("attach",e)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const e=await yh({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)}}},wh={key:0,class:"wm-rec"},kh={class:"wm-rec__lbl"},Ch={key:1,class:"wm-compose__menu",role:"menu"},Ah=["disabled","onClick"],Sh={class:"wm-compose__menuIcon"},xh={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},Th=["d"],Mh=["placeholder","disabled"],Eh={class:"wm-compose__actions"},Oh=["title","aria-label","disabled"],Ih=["disabled","aria-label"];function Rh(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-compose-wrap",{"wm-compose-wrap--sheet":n.displayMode==="sheet"}]),style:Oe(i.kbOffset?{transform:`translateY(-${i.kbOffset}px)`}:null)},[i.recording?(h(),g("div",wh,[t[8]||(t[8]=u("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),u("span",kh,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)])):D("",!0),u("form",{class:re(["wm-compose",{"has-attach":i.attachOpen}]),onSubmit:t[7]||(t[7]=ht((...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(),g("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=o=>i.attachOpen=!1)})):D("",!0),i.attachOpen?(h(),g("div",Ch,[(h(!0),g(ee,null,Ae(s.attachItems,o=>(h(),g("button",{key:o.action,type:"button",class:"wm-compose__menuItem",disabled:o.disabled,onClick:a=>s.onAttachAction(o.action)},[u("span",Sh,[(h(),g("svg",xh,[u("path",{d:o.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,Th)]))]),u("span",null,R(o.label),1)],8,Ah))),128))])):D("",!0),at(u("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=o=>i.local=o),class:"wm-compose__input",rows:"3",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))},null,40,Mh),[[Rt,i.local]]),u("div",Eh,[u("button",{type:"button",class:re(["wm-compose__icon",{"is-open":i.attachOpen}]),title:n.attachLabel,"aria-label":n.attachLabel,disabled:i.recording,onClick:t[6]||(t[6]=o=>i.attachOpen=!i.attachOpen)},[...t[9]||(t[9]=[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)])],10,Oh),u("button",{type:"submit",class:re(["wm-compose__send",{"is-empty":!s.canSend}]),disabled:!s.canSend,"aria-label":s.t("composer.send")},[...t[10]||(t[10]=[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:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,Ih)])],34)],6)}const Lh=we(bh,[["render",Rh],["__scopeId","data-v-01e81a27"]]),Ph={name:"WmSuggestionChips",props:{items:{type:Array,default:()=>[]},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("§")}}},Bh=["onClick"];function Dh(e,t,n,r,i,s){return n.items.length?(h(),g("div",{key:s.batchKey,class:"wm-chips"},[(h(!0),g(ee,null,Ae(n.items,(o,a)=>(h(),g("button",{key:a,type:"button",class:"wm-chip",style:Oe({animationDelay:n.baseDelay+a*n.stepDelay+"ms"}),onClick:l=>e.$emit("select",o)},R(o.label),13,Bh))),128))])):D("",!0)}const Fh=we(Ph,[["render",Dh],["__scopeId","data-v-47ad8085"]]),Nh={name:"WmApprovalCard",components:{AIAvatar:qt},inject:{t:{default:()=>xe()}},props:{action:{type:String,required:!0},detail:{type:String,default:""},callbacks:{type:Array,default:()=>[]},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["callback"],computed:{approveCallback(){return this.callbacks.find(e=>e.id==="approve"||e.style==="primary")||this.callbacks[0]},rejectCallback(){return this.callbacks.find(e=>e.id==="reject"||e.style==="danger"||e.style==="neutral")||(this.callbacks.length>1?this.callbacks[1]:null)},approveId(){var e;return(e=this.approveCallback)==null?void 0:e.id},rejectId(){var e;return(e=this.rejectCallback)==null?void 0:e.id},approveLabel(){var e;return((e=this.approveCallback)==null?void 0:e.label)||this.t("approval.approve")},rejectLabel(){var e;return((e=this.rejectCallback)==null?void 0:e.label)||this.t("approval.reject")}}},jh={class:"wm-approval"},Hh={class:"wm-approval__head"},Uh={class:"wm-approval__icon"},$h={class:"wm-approval__main"},Vh={class:"wm-approval__title"},Kh={key:0,class:"wm-approval__detail"},Wh={class:"wm-approval__actions"};function zh(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",jh,[u("div",Hh,[u("div",Uh,[ve(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",$h,[u("div",Vh,R(n.action),1),n.detail?(h(),g("div",Kh,R(n.detail),1)):D("",!0)])]),u("div",Wh,[s.rejectId?(h(),g("button",{key:0,type:"button",class:"wm-approval__btn wm-approval__btn--neutral",onClick:t[0]||(t[0]=a=>e.$emit("callback",s.rejectId))},R(s.rejectLabel),1)):D("",!0),s.approveId?(h(),g("button",{key:1,type:"button",class:"wm-approval__btn wm-approval__btn--primary",onClick:t[1]||(t[1]=a=>e.$emit("callback",s.approveId))},R(s.approveLabel),1)):D("",!0)])])}const qh=we(Nh,[["render",zh],["__scopeId","data-v-a2bed37e"]]);let Qr=0;const Gh=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Yh={name:"WmFormCard",components:{AIAvatar:qt},inject:{t:{default:()=>xe()}},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 Qr+=1,{_uid:Qr,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)||!Gh.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}}}},Jh={class:"wm-form"},Xh={class:"wm-form__head"},Qh={class:"wm-form__icon"},Zh={class:"wm-form__main"},em={class:"wm-form__title"},tm={key:0,class:"wm-form__detail"},nm=["for"],sm={key:0,class:"wm-form__req","aria-hidden":"true"},rm=["id","onUpdate:modelValue","placeholder","required","disabled"],im=["id","onUpdate:modelValue","placeholder","required","disabled"],om=["id","onUpdate:modelValue","placeholder","required","disabled"],am=["id","onUpdate:modelValue","required","disabled"],lm={key:4,class:"wm-form__bool"},cm=["id","onUpdate:modelValue","disabled"],um=["id","onUpdate:modelValue","required","disabled"],dm={value:"",disabled:""},fm=["value"],hm={key:6,class:"wm-form__multi"},mm=["value","checked","disabled","onChange"],pm={key:0,class:"wm-form__err"},gm=["disabled"],_m={key:0,class:"wm-form__spinner","aria-hidden":"true"},ym={key:2,class:"wm-form__doneLbl"};function vm(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",Jh,[u("div",Xh,[u("div",Qh,[ve(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",Zh,[u("div",em,R(n.form.title||s.t("form.title")),1),n.form.description?(h(),g("div",tm,R(n.form.description),1)):D("",!0)])]),u("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=ht((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]))},[(h(!0),g(ee,null,Ae(s.normalizedFields,a=>(h(),g("div",{key:a.key,class:"wm-form__field"},[u("label",{for:`wm-f-${i._uid}-${a.key}`,class:"wm-form__label"},[ts(R(a.label),1),a.required?(h(),g("span",sm,"*")):D("",!0)],8,nm),a.type==="text"?at((h(),g("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,rm)),[[Rt,i.values[a.key]]]):a.type==="textarea"?at((h(),g("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,im)),[[Rt,i.values[a.key]]]):a.type==="number"?at((h(),g("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,om)),[[Rt,i.values[a.key],void 0,{number:!0}]]):a.type==="date"?at((h(),g("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,am)),[[Rt,i.values[a.key]]]):a.type==="boolean"?(h(),g("label",lm,[at(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,cm),[[Yl,i.values[a.key]]]),u("span",null,R(a.placeholder||s.t("common.yes")),1)])):a.type==="select"?at((h(),g("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",dm,R(a.placeholder||s.t("form.choose")),1),(h(!0),g(ee,null,Ae(a.options,l=>(h(),g("option",{key:l.value,value:l.value},R(l.label),9,fm))),128))],8,um)),[[Jl,i.values[a.key]]]):a.type==="multiselect"?(h(),g("div",hm,[(h(!0),g(ee,null,Ae(a.options,l=>(h(),g("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:f=>s.toggleMulti(a.key,l.value,f.target.checked)},null,40,mm),u("span",null,R(l.label),1)]))),128))])):D("",!0)]))),128)),i.error?(h(),g("div",pm,R(i.error),1)):D("",!0),n.readOnly?(h(),g("div",ym,R(s.t("form.responseSent")),1)):(h(),g("button",{key:1,type:"submit",class:"wm-form__submit",disabled:i.busy},[i.busy?(h(),g("span",_m)):D("",!0),u("span",null,R(i.busy?s.t("common.sending"):n.form.submit_label||s.t("common.send")),1)],8,gm))],32)])}const bm=we(Yh,[["render",vm],["__scopeId","data-v-fe65cc56"]]),wm={name:"WmFeedback",inject:{t:{default:()=>xe()}},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})}}},km={class:"wm-fb"},Cm={class:"wm-fb__title"},Am={class:"wm-fb__sub"},Sm={class:"wm-fb__row"},xm=["onClick"],Tm={class:"wm-fb__emoji"},Mm={class:"wm-fb__label"},Em=["disabled"],Om={key:1,class:"wm-fb__done"},Im={class:"wm-fb__doneTitle"},Rm={class:"wm-fb__doneSub"};function Lm(e,t,n,r,i,s){return h(),g("div",km,[n.done?(h(),g("div",Om,[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",Im,R(s.t("feedback.doneTitle")),1),u("div",Rm,R(s.t("feedback.doneSubtitle")),1)])):(h(),g(ee,{key:0},[u("div",Cm,R(s.t("feedback.question")),1),u("div",Am,R(s.t("feedback.subtitle")),1),u("div",Sm,[(h(!0),g(ee,null,Ae(s.options,o=>(h(),g("button",{key:o.v,type:"button",class:re(["wm-fb__opt",{"is-selected":i.sel===o.v}]),onClick:a=>i.sel=o.v},[u("span",Tm,R(o.e),1),u("span",Mm,R(o.l),1)],10,xm))),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,Em)],64))])}const Pm=we(wm,[["render",Lm],["__scopeId","data-v-9b630564"]]),Bm={name:"WmMoreMenu",inject:{t:{default:()=>xe()}},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)}}},Dm={class:"wm-mm"},Fm={class:"wm-mm__pop",role:"menu"},Nm={key:0,class:"wm-mm__section"},jm={class:"wm-mm__label"},Hm={class:"wm-mm__label"},Um={key:1,class:"wm-mm__sep"},$m={class:"wm-mm__section"},Vm={class:"wm-mm__label"},Km={class:"wm-mm__section"},Wm={class:"wm-mm__label"},zm={class:"wm-mm__label"};function qm(e,t,n,r,i,s){return h(),g("div",Dm,[u("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Fm,[n.canRename||n.canExport?(h(),g("div",Nm,[n.canRename?(h(),g("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",jm,R(s.t("moreMenu.editTitle")),1)])):D("",!0),n.canExport?(h(),g("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",Hm,R(s.t("moreMenu.exportTranscript")),1),t[8]||(t[8]=u("span",{class:"wm-mm__hint"},".txt",-1))])):D("",!0)])):D("",!0),n.canRename||n.canExport?(h(),g("div",Um)):D("",!0),u("div",$m,[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",Vm,R(s.t("moreMenu.sound")),1),u("span",{class:re(["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",Km,[n.statusUrl?(h(),g("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",Wm,R(s.t("moreMenu.serviceStatus")),1)])):D("",!0),n.helpUrl?(h(),g("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",zm,R(s.t("moreMenu.helpCenter")),1)])):D("",!0)])])])}const Gm=we(Bm,[["render",qm],["__scopeId","data-v-4cf6d578"]]),Ym={name:"WmRenameDialog",inject:{t:{default:()=>xe()}},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())}}},Jm={class:"wm-dialog"},Xm={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},Qm={class:"wm-dialog__head"},Zm={class:"wm-dialog__title"},ep=["aria-label"],tp={class:"wm-dialog__body"},np=["placeholder"],sp={class:"wm-dialog__actions"},rp=["disabled"];function ip(e,t,n,r,i,s){return h(),g("div",Jm,[u("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Xm,[u("div",Qm,[u("div",Zm,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,ep)]),u("div",tp,[at(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]=Hn(ht((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]),["enter"])),t[4]||(t[4]=Hn(ht(o=>e.$emit("close"),["prevent"]),["esc"]))]},null,40,np),[[Rt,i.value]])]),u("div",sp,[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,rp)])])])}const op=we(Ym,[["render",ip],["__scopeId","data-v-6d5f94a8"]]),Zr="ww-messenger-tokens",ap={name:"Messenger",components:{Launcher:Qc,Header:Cu,Onboarding:rd,History:bd,MessageList:mh,Composer:Lh,SuggestionChips:Fh,ApprovalCard:qh,FormCard:bm,Feedback:Pm,MoreMenu:Gm,RenameDialog:op},mixins:[Mc,Ec,Oc,Rc],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:mc},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:!1,convOpenedAt:0,moreOpen:!1,renameDialogOpen:!1,draftConv:null,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 er(this.language||this.customerLanguage||((e=this.widget)==null?void 0:e.default_language)||"")},translator(){return xe(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 f;const i=e[r.id]||[],s=ft(r.last_read_message_id);let o=0,a=null;for(let c=i.length-1;c>=0;c--){const p=i[c];if(!p)continue;if(((f=p.author)==null?void 0:f.type)==="user")break;const S=ft(p.id);if(S!=null){if(s!=null&&S<=s)break;t[p.id]!==0&&(!a&&p.author&&(a=p.author),o++)}}if(!i.length){const c=ft(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=>n.status!=="resolved").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:Jr(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=Jr(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)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&&yc(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},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(){var t;const e=(t=this.currentConv)==null?void 0:t.status;return e==="waiting"||e==="handled"},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,f,c,p;return(o==null?void 0:o.type)==="action"&&((a=o==null?void 0:o.payload)==null?void 0:a.state)==="pending"||wn(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((f=o==null?void 0:o.payload)==null?void 0:f.attachments)&&o.payload.attachments.length||(c=o==null?void 0:o.metadata)!=null&&c.artifact||(p=o==null?void 0:o.metadata)!=null&&p.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=>wn(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])||[]:[]},pendingApproval(){return!this.currentConv||!this.store||this.actionInFlight?null:this.store.getPendingApproval(this.currentConv.id)},approvalReady(){return this.pendingApproval?this.pendingApproval.id===this.approvalLatchId?!0:!(this.streamingActive||!this.approvalSettled):!1},approvalTitle(){var e,t,n;return((t=(e=this.pendingApproval)==null?void 0:e.payload)==null?void 0:t.name)||((n=this.pendingApproval)==null?void 0:n.text_md)||this.t("action.title")},approvalDetail(){var r,i,s,o,a,l;const e=(s=(i=(r=this.pendingApproval)==null?void 0:r.payload)==null?void 0:i.pending)==null?void 0:s.user_explanation;if(typeof e=="string"&&e.trim())return e.trim();const t=(l=(a=(o=this.pendingApproval)==null?void 0:o.payload)==null?void 0:a.pending)==null?void 0:l.prepared_params;if(!t||typeof t!="object")return"";const n=Object.entries(t);return n.length?n.slice(0,2).map(([f,c])=>`${f}: ${c}`).join(" · "):""},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.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.pendingApproval||this.actionInFlight||this.streamingActive||!this.approvalSettled?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.feedbackDone?!0:e.status!=="resolved"?!1:!((t=e.metadata)!=null&&t.feedback):!1},floatVisible(){return this.approvalReady||!!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:Ps(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.resetApprovalPacing(),this.isViewingThread&&(this.unreadAnchorId=ft((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=ft((n=this.currentConv)==null?void 0:n.last_read_message_id),this.unreadBoundaryTs=new Date().toISOString()):e||(this.unreadAnchorId=null,this.unreadBoundaryTs="")},pendingApproval:{handler(e,t){if(e&&!t){const n=e!=null&&e.created_at?Date.parse(e.created_at):NaN;if(!(Number.isFinite(n)&&n>=this.convOpenedAt)){this.resetApprovalPacing();return}this.bumpApprovalSettle(2600)}else!e&&t&&this.resetApprovalPacing()},immediate:!1},streamingActive(e,t){e!==t&&this.pendingApproval&&this.pendingApproval.id!==this.approvalLatchId&&this.bumpApprovalSettle()},approvalReady(e){e&&this.pendingApproval&&(this.approvalLatchId=this.pendingApproval.id)},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(Zr)){const e=document.createElement("style");e.id=Zr,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.resetApprovalPacing(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{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=xs(cc({baseUrl:this.baseUrl,widgetId:this.widgetId})),this.store=xs(hc(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=!1,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.scrollToBottom)==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,p,S,w,V,O,J;if(this.isOpen)return;const e=(p=(c=this.$el)==null?void 0:c.querySelector)==null?void 0:p.call(c,".wm-launcherWrap");if(!e)return;const t=e.getBoundingClientRect();if(!t.width||!t.height)return;const n=(((S=this.launcherPeeks)==null?void 0:S.length)??0)>0,r=16,i=Math.ceil(t.width),s=Math.ceil(t.height),o=(V=(w=this.$el)==null?void 0:w.querySelector)==null?void 0:V.call(w,".wm-launcher"),a=(J=(O=this.$el)==null?void 0:O.querySelectorAll)==null?void 0:J.call(O,".wm-peek"),l=a&&a.length?a[a.length-1]:null;let f=null;if(l){const z=l.getBoundingClientRect();f={width:Math.ceil(z.width),height:Math.ceil(z.height),rightOffset:Math.max(0,Math.ceil(t.right-z.right)),bottomOffset:Math.max(0,Math.ceil(t.bottom-z.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:f,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})},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()},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}),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;this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:0};const n=this.revealPacing,r=t.trim().length,i=Math.min(n.maxTypingMs,Math.max(n.minTypingMs,r*n.msPerChar)),s=n.firstRevealDelayMs+i,o=setTimeout(()=>{this.welcomeRevealedAt={...this.welcomeRevealedAt,[e]:Date.now()};const a={...this.welcomeRevealTimers};delete a[e],this.welcomeRevealTimers=a},s);this.welcomeRevealTimers={...this.welcomeRevealTimers,[e]:o}},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":Tc(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(Rn(this.statusUrl))try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(Rn(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="",await this.store.send(n,e,{attachments:r.length?r: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 onApprovalCallback(e){const t=this.pendingApproval;t&&await this.store.clickCallback(t.id,e)},async onFormSubmit({values:e}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const n=wc(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:kc(t.form,e,this.translator)}}))},async onAttach(e){if(!(!e||!this.transport))try{const t=await this.transport.uploadAttachment(e);this.pendingAttachments.push({type:t.type||"file",path:t.path,name:e.name||this.t("attachment.fileFallbackName"),mime_type:e.type,size_bytes:e.size})}catch(t){console.error("[ww-messenger] attachment upload failed",t)}},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(!Rn(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=!0}catch(n){console.error("[ww-messenger] feedback failed",n)}finally{this.feedbackBusy=!1}}}}},lp={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},cp=["aria-label"],up={key:0,class:"wm-state"},dp={class:"wm-state__err"},fp={class:"wm-state__errTitle"},hp={class:"wm-state__errSub"},mp={class:"wm-bottom"},pp={key:0,ref:"floatEl",class:"wm-float"},gp={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},_p={class:"wm-actionWait__lbl"},yp={key:2,class:"wm-attached"},vp=["aria-label","onClick"];function bp(e,t,n,r,i,s){const o=ye("Launcher"),a=ye("Header"),l=ye("History"),f=ye("Onboarding"),c=ye("MessageList"),p=ye("ApprovalCard"),S=ye("FormCard"),w=ye("Feedback"),V=ye("SuggestionChips"),O=ye("Composer"),J=ye("MoreMenu"),z=ye("RenameDialog");return h(),g("div",{class:re(["wm-root",`wm-root--${n.displayMode}`]),style:Oe(s.rootStyle)},[!i.isOpen&&!s.isEmbedded?(h(),ge(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"])):D("",!0),i.isOpen||s.isEmbedded?(h(),g("section",{key:1,class:re(["wm-panel",`wm-panel--${n.displayMode}`,{"wm-panel--welcome":s.ready&&!s.error&&!s.currentConv}]),style:Oe(i.floatHeight?{"--wm-float-h":i.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger",onClick:t[6]||(t[6]=(...U)=>s.onPanelClick&&s.onPanelClick(...U))},[!s.ready&&!s.error?(h(),g("div",lp,[s.isEmbedded?D("",!0):(h(),g("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[7]||(t[7]=[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,cp)),t[8]||(t[8]=u("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(h(),g(ee,{key:1},[ve(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"]),s.error?(h(),g("div",up,[u("div",dp,[t[9]||(t[9]=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",fp,R(s.t("error.connectionFailed")),1),u("div",hp,R(s.error),1)])])])):!s.currentConv&&i.showHistory?(h(),ge(l,{key:1,threads:s.openThreads,onResume:s.onDrawerPick},null,8,["threads","onResume"])):s.currentConv?(h(),g(ee,{key:3},[ve(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",mp,[s.floatVisible?(h(),g("div",pp,[s.approvalReady?(h(),ge(p,{key:0,action:s.approvalTitle,detail:s.approvalDetail,callbacks:s.pendingApproval.callbacks,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onCallback:s.onApprovalCallback},null,8,["action","detail","callbacks","agent-name","agent-avatar-url","onCallback"])):s.pendingForm?(h(),ge(S,{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(),ge(w,{key:2,busy:i.feedbackBusy,done:i.feedbackDone,onSubmit:s.onFeedback},null,8,["busy","done","onSubmit"])):(h(),ge(V,{key:3,items:s.suggestions,onSelect:s.onSuggestion},null,8,["items","onSelect"]))],512)):D("",!0),s.actionInFlight?(h(),g("div",gp,[t[10]||(t[10]=u("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),u("span",_p,R(s.t("action.inProgress",{name:s.actionInFlightName})),1)])):(h(),ge(O,{key:2,ref:"composer",modelValue:i.draft,"onUpdate:modelValue":t[2]||(t[2]=U=>i.draft=U),placeholder:s.composerPlaceholder,disabled:!!s.pendingApproval,"attach-label":s.t("composer.attachFile"),"display-mode":n.displayMode,onSend:s.onSend,onAttach:s.onAttach},null,8,["modelValue","placeholder","disabled","attach-label","display-mode","onSend","onAttach"]))]),i.moreOpen?(h(),ge(J,{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[3]||(t[3]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["can-rename","can-export","sound-enabled","status-url","help-url","onSoundToggle","onAction"])):D("",!0),i.renameDialogOpen&&s.currentConv&&!s.currentConv._draft?(h(),ge(z,{key:1,"initial-value":s.currentConv.name||"",title:s.t("rename.dialogTitle"),onClose:t[4]||(t[4]=U=>i.renameDialogOpen=!1),onSubmit:s.onRenameSubmit},null,8,["initial-value","title","onSubmit"])):D("",!0),i.pendingAttachments.length?(h(),g("div",yp,[(h(!0),g(ee,null,Ae(i.pendingAttachments,(U,Q)=>(h(),g("div",{key:Q,class:"wm-attached__chip"},[t[12]||(t[12]=u("svg",{width:"11",height:"11",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)),u("span",null,R(U.name),1),u("button",{type:"button","aria-label":s.t("attachment.remove"),onClick:$=>i.pendingAttachments.splice(Q,1)},[...t[11]||(t[11]=[u("svg",{width:"10",height:"10",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,vp)]))),128))])):D("",!0)],64)):(h(),ge(f,{key:2,title:s.widgetTitle,subtitle:s.widgetSubtitle,"agent-name":s.agentName,"default-icon-url":s.defaultIconUrl,"quick-links":s.quickLinks,"open-threads":s.openThreads,busy:i.busy,onStart:s.startConv,onSelect:s.onQuickLink,onResume:s.onDrawerPick,onViewHistory:t[1]||(t[1]=U=>i.showHistory=!0)},null,8,["title","subtitle","agent-name","default-icon-url","quick-links","open-threads","busy","onStart","onSelect","onResume"])),i.moreOpen&&!s.currentConv?(h(),ge(J,{key:4,"can-rename":!1,"can-export":!1,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[5]||(t[5]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["sound-enabled","status-url","help-url","onSoundToggle","onAction"])):D("",!0)],64))],6)):D("",!0)],6)}const wp=we(ap,[["render",bp],["__scopeId","data-v-79d619be"]]),ei=window.__WIDGET_ID,ti=window.__BASE_URL,kp=window.__DISPLAY_MODE||"floating",ni=window.__LANGUAGE||"";window.__MESSENGER_IFRAME_VERSION="0.5.60";if(!ei||!ti)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)}nc({render:()=>vo(wp,{baseUrl:ti,widgetId:ei,displayMode:kp,...ni?{language:ni}:{}})}).mount("#app")}
|
|
74
|
+
`)}function Tc(e,t,n=xe(),r){if(!e)return;const i=xc(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 Mc={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||!wn(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)}}}},Zt=Object.freeze({firstRevealDelayMs:450,msPerChar:50,minTypingMs:900,maxTypingMs:12e3,pauseBetweenMs:300}),en=(e,t)=>Number.isFinite(e)?e:t,Ec={computed:{revealPacing(){var t;const e=((t=this.widget)==null?void 0:t.reveal_pacing)||{};return{firstRevealDelayMs:en(e.first_reveal_delay_ms,Zt.firstRevealDelayMs),msPerChar:en(e.ms_per_char,Zt.msPerChar),minTypingMs:en(e.min_typing_ms,Zt.minTypingMs),maxTypingMs:en(e.max_typing_ms,Zt.maxTypingMs),pauseBetweenMs:en(e.pause_between_ms,Zt.pauseBetweenMs)}}},data(){return{revealedAt:{},nextRevealAt:0,revealTimers:[],_liveRevealOff:null,_liveRevealConvSnapshot:null}},methods:{cancelReveals(){for(const e of this.revealTimers)clearTimeout(e);this.revealTimers=[]},resetRevealQueue(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0},setupLiveReveal(){var n;if(!this.transport)return;this.teardownLiveReveal();const e=this.transport.on("message",r=>{const i=r==null?void 0:r.conversation_id,s=r==null?void 0:r.message;i&&s&&this.paceLiveMessage(s,i)});this._liveRevealConvSnapshot=new Map((((n=this.s)==null?void 0:n.conversations)||[]).map(r=>[r.id,(r==null?void 0:r.last_message_at)||""]));const t=this.transport.on("activity",r=>{this.handleLiveActivity(r)});this._liveRevealOff=()=>{try{e()}catch{}try{t()}catch{}}},teardownLiveReveal(){if(this._liveRevealOff){try{this._liveRevealOff()}catch{}this._liveRevealOff=null}this._liveRevealConvSnapshot=null},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),f=e.id,c=setTimeout(()=>{this.revealedAt={...this.revealedAt,[f]:Date.now()},this.revealTimers=this.revealTimers.filter(p=>p!==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(!wn(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 i;if(!(e!=null&&e.id)||this.revealedAt[e.id]!==void 0)return;if(!wn(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((i=e==null?void 0:e.payload)==null?void 0:i.attachments)&&e.payload.attachments.length>0;if(!n&&!r){this.revealedAt={...this.revealedAt,[e.id]:Date.now()};return}this.revealedAt={...this.revealedAt,[e.id]:0},this.scheduleReveal(e,t)}}},Oc={data(){return{approvalSettled:!0,approvalSettleTimer:null,approvalLatchId:null}},methods:{resetApprovalPacing(){this.approvalSettleTimer&&(clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=null),this.approvalSettled=!0,this.approvalLatchId=null},bumpApprovalSettle(e=800){this.approvalSettled=!1,this.approvalSettleTimer&&clearTimeout(this.approvalSettleTimer),this.approvalSettleTimer=setTimeout(()=>{this.approvalSettled=!0,this.approvalSettleTimer=null},e)}}},Ic=300,Rc={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=ft(e.last_read_message_id),i=ft(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)},Ic))))}}};function Lc(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(!(!n||n._pending)&&ft(n.id)!=null)return n.id}return null}const we=(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":Qs(this.name)},initials(){return Zs(this.name)}}},Bc=["src","alt"];function Dc(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-huav",{"wm-huav--tail":n.tail}]),style:Oe({width:n.size+"px",height:n.size+"px","--wm-avr":Math.round(n.size*.32)+"px",background:s.bg})},[n.avatarUrl?(h(),g("img",{key:0,src:n.avatarUrl,alt:n.name||""},null,8,Bc)):(h(),g("span",{key:1,style:Oe({fontSize:n.size*.36+"px"})},R(s.initials),5))],6)}const ss=we(Pc,[["render",Dc],["__scopeId","data-v-14e10c0d"]]),Fc=3,Nc={name:"WmLauncher",components:{HumanAvatar:ss},inject:{t:{default:()=>xe()}},props:{unreadCount:{type:Number,default:0},peeks:{type:Array,default:()=>[]}},emits:["open","dismiss"],computed:{visiblePeeks(){return this.peeks.slice(0,Fc).reverse()}}},jc=["aria-label","onClick","onKeydown"],Hc=["aria-label","onClick"],Uc={class:"wm-peek__avatar"},$c=["aria-label"],Vc={class:"wm-peek__body"},Kc={class:"wm-peek__head"},Wc={class:"wm-peek__name"},zc={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=ye("HumanAvatar");return h(),g("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))},[ve(ko,{name:"wm-peek"},{default:zs(()=>[s.visiblePeeks.length?(h(),g("div",{key:0,class:re(["wm-peekStack",{"wm-peekStack--multi":s.visiblePeeks.length>1}])},[(h(!0),g(ee,null,Ae(s.visiblePeeks,(a,l)=>(h(),g("div",{key:a.convId,class:"wm-peek",style:Oe({"--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:f=>e.$emit("open",a.convId),onKeydown:[Hn(ht(f=>e.$emit("open",a.convId),["prevent"]),["enter"]),Hn(ht(f=>e.$emit("open",a.convId),["prevent"]),["space"])]},[u("button",{type:"button",class:"wm-peek__close","aria-label":s.t("launcher.dismiss"),onClick:ht(f=>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,Hc),u("div",Uc,[ve(o,{name:a.senderName,"avatar-url":a.senderAvatarUrl,size:34},null,8,["name","avatar-url"]),a.count>1?(h(),g("span",{key:0,class:"wm-peek__avatarBadge","aria-label":s.t("launcher.unreadMessages",{count:a.count})},R(a.count>9?"9+":a.count),9,$c)):D("",!0)]),u("div",Vc,[u("div",Kc,[u("span",Wc,R(a.senderName||s.t("common.agent")),1),u("span",zc,R(s.t("launcher.repliedToYou")),1)]),u("p",qc,R(a.preview),1)]),u("button",{type:"button",class:"wm-peek__open",onClick:ht(f=>e.$emit("open",a.convId),["stop"])},R(s.t("common.open")),9,Gc)],44,jc))),128))],2)):D("",!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(),g("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)):D("",!0)],8,Yc)],32)}const Qc=we(Nc,[["render",Xc],["__scopeId","data-v-44ddf1a1"]]),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 Zs(this.name)},bgColor(){return Qs(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(),g("div",{class:re(["wm-aiav",{"wm-aiav--tail":n.tail}]),style:Oe({width:n.size+"px",height:n.size+"px","--wm-avr":n.size*.32+"px"})},[n.pulse?(h(),g("div",eu)):D("",!0),u("div",{class:re(["wm-aiav__inner",{"wm-aiav__inner--glow":n.pulse,"wm-aiav__inner--img":!!n.imageUrl,"wm-aiav__inner--initials":!n.imageUrl&&!!s.initials}]),style:Oe(!n.imageUrl&&s.initials?{background:s.bgColor}:null)},[n.imageUrl?(h(),g("img",{key:0,src:n.imageUrl,alt:n.name||""},null,8,tu)):s.initials?(h(),g("span",{key:1,style:Oe({fontSize:n.size*.36+"px"})},R(s.initials),5)):(h(),g("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 qt=we(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":Qs(e.name||"")},initialsFor(e){return Zs(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(),g("div",iu,[u("div",{class:"wm-team__stack",style:Oe({width:s.stackWidth+"px"})},[(h(!0),g(ee,null,Ae(n.members.slice(0,3),(o,a)=>(h(),g("div",{key:a,class:"wm-team__pill",style:Oe({left:a*13+"px",zIndex:3-a,background:s.colorFor(o)})},[o.avatar_url?(h(),g("img",{key:0,src:o.avatar_url,alt:o.name||""},null,8,ou)):(h(),g("span",au,R(s.initialsFor(o)),1))],4))),128))],4),n.responseLabel?(h(),g("span",lu,R(n.responseLabel),1)):D("",!0)])):D("",!0)}const uu=we(ru,[["render",cu],["__scopeId","data-v-e49a9063"]]),du={name:"WmHeader",components:{AIAvatar:qt,TeamAvatars:uu},inject:{t:{default:()=>xe()}},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"}},pu={class:"wm-header__avatar"},gu={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=ye("AIAvatar"),a=ye("TeamAvatars");return h(),g("div",fu,[n.showBack?(h(),g("button",{key:0,type:"button",class:"wm-header__icon","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(),g("div",mu)),n.showIdentity?(h(),g(ee,{key:2},[u("div",pu,[ve(o,{size:30,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",gu,[u("div",_u,R(n.title),1)]),s.hasTeam?(h(),ge(a,{key:0,members:s.displayedTeamMembers,"response-label":""},null,8,["members"])):D("",!0)],64)):(h(),g("div",yu)),u("div",vu,[n.showMore?(h(),g("button",{key:0,type:"button",class:re(["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)):D("",!0),n.showClose?(h(),g("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)):D("",!0)])])}const Cu=we(du,[["render",ku],["__scopeId","data-v-7af4c118"]]),Xr={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"},Au={name:"WmOnboarding",components:{AIAvatar:qt,HumanAvatar:ss},inject:{t:{default:()=>xe()},wmLocale:{default:()=>()=>"fr"}},props:{title:{type:String,default:""},subtitle:{type:String,default:""},agentName:{type:String,default:""},defaultIconUrl:{type:String,default:null},quickLinks:{type:Array,default:()=>[]},openThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1}},emits:["start","select","resume","view-history"],computed:{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)}},methods:{iconPath(e){return Xr[e]||Xr.link},isExternalLink(e){const t=e==null?void 0:e.url;return!!t&&!t.startsWith("#")},safeIconUrl(e){return vc(e==null?void 0:e.icon_url)},iconUrlStyle(e){const t=this.safeIconUrl(e);return t?{"--icon-url":`url("${t}")`}:null},renderPreview(e){return To(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"})}}},Su={class:"wm-onb"},xu={class:"wm-onb__hero"},Tu={class:"wm-onb__hero-text"},Mu={class:"wm-onb__title"},Eu={class:"wm-onb__sub"},Ou={key:0,class:"wm-onb__alertList"},Iu=["onClick"],Ru={key:0,class:"wm-onb__defaultAvatar"},Lu=["aria-label"],Pu={class:"wm-onb__alert-body"},Bu={class:"wm-onb__alert-title"},Du={class:"wm-onb__alert-preview"},Fu={key:0,class:"wm-onb__alert-sender"},Nu=["innerHTML"],ju={class:"wm-onb__alert-meta"},Hu={key:0,class:"wm-onb__alert-time"},Uu={class:"wm-onb__alert-resume"},$u={class:"wm-onb__actions"},Vu=["disabled"],Ku={class:"wm-onb__btn-label"},Wu=["onClick"],zu={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"};function sd(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",Su,[u("div",xu,[t[2]||(t[2]=u("svg",{class:"wm-onb__hero-deco",width:"180",height:"180",viewBox:"0 0 180 180",fill:"none","aria-hidden":"true"},[u("circle",{cx:"170",cy:"10",r:"105",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.35"}),u("circle",{cx:"170",cy:"10",r:"72",stroke:"#5B5FEF","stroke-width":"1","stroke-dasharray":"1 5",opacity:"0.5"}),u("circle",{cx:"152",cy:"34",r:"2.5",fill:"#5B5FEF",opacity:"0.65"})],-1)),ve(o,{size:52,"image-url":n.defaultIconUrl},null,8,["image-url"]),u("div",Tu,[u("div",Mu,R(s.heroTitle),1),u("div",Eu,R(s.heroSub),1)])]),s.unreadThreads.length?(h(),g("div",Ou,[(h(!0),g(ee,null,Ae(s.unreadThreads,a=>(h(),g("button",{key:a.id,type:"button",class:"wm-onb__alert",onClick:l=>e.$emit("resume",a)},[u("span",{class:re(["wm-onb__alert-avatar",s.avatarWrapperClass(a)])},[s.isDefaultAvatar(a)?(h(),g("span",Ru,[...t[3]||(t[3]=[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(),ge(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,Lu)],2),u("span",Pu,[u("span",Bu,R(a.title),1),u("span",Du,[s.senderLabel(a)?(h(),g("span",Fu,R(s.senderLabel(a))+" · ",1)):D("",!0),u("span",{innerHTML:s.renderPreview(a.preview)},null,8,Nu)])]),u("span",ju,[s.formatTs(a._ts)?(h(),g("span",Hu,R(s.formatTs(a._ts)),1)):D("",!0),u("span",Uu,R(s.t("onboarding.resume")),1)])],8,Iu))),128))])):D("",!0),u("div",$u,[u("button",{type:"button",class:"wm-onb__btn wm-onb__btn--start",disabled:n.busy,onClick:t[0]||(t[0]=a=>e.$emit("start"))},[t[4]||(t[4]=u("span",{class:"wm-onb__btn-icon"},[u("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[u("path",{d:"M12 5v14M5 12h14"})])],-1)),u("span",Ku,R(n.busy?"…":s.t("onboarding.start")),1)],8,Vu),(h(!0),g(ee,null,Ae(n.quickLinks,(a,l)=>(h(),g("button",{key:"ql-"+l,type:"button",class:"wm-onb__btn",onClick:f=>e.$emit("select",a)},[u("span",zu,[s.safeIconUrl(a)?(h(),g("span",{key:0,class:"wm-onb__btn-iconImg",style:Oe(s.iconUrlStyle(a)),role:"img","aria-label":a.label||""},null,12,qu)):(h(),g("svg",Gu,[u("path",{d:s.iconPath(a.icon)},null,8,Yu)]))]),u("span",Ju,R(a.label),1),s.isExternalLink(a)?(h(),g("svg",Xu,[...t[5]||(t[5]=[u("path",{d:"M7 17L17 7M9 7h8v8"},null,-1)])])):D("",!0)],8,Wu))),128)),n.openThreads.length?(h(),g("button",{key:0,type:"button",class:"wm-onb__btn",onClick:t[1]||(t[1]=a=>e.$emit("view-history"))},[u("span",Qu,[(h(),g("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[6]||(t[6]=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))])):D("",!0)])])}const rd=we(Au,[["render",sd],["__scopeId","data-v-136c3afe"]]),id={name:"WmHistory",components:{AIAvatar:qt,HumanAvatar:ss},inject:{t:{default:()=>xe()},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 To(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"})}}},od={class:"wm-hist"},ad={class:"wm-hist__search"},ld=["placeholder","aria-label"],cd={class:"wm-hist__list"},ud=["onClick"],dd={key:0,class:"wm-hist__defaultAvatar"},fd=["aria-label"],hd={class:"wm-hist__thread-body"},md={class:"wm-hist__thread-title"},pd=["innerHTML"],gd={class:"wm-hist__thread-meta"},_d={key:0,class:"wm-hist__thread-time"},yd={key:0,class:"wm-hist__empty"};function vd(e,t,n,r,i,s){return h(),g("div",od,[u("div",ad,[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)),at(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,ld),[[Rt,i.query]])]),u("div",cd,[(h(!0),g(ee,null,Ae(s.filteredThreads,o=>(h(),g("button",{key:o.id,type:"button",class:re(["wm-hist__thread",{"wm-hist__thread--unread":o.unread}]),onClick:a=>e.$emit("resume",o)},[u("span",{class:re(["wm-hist__thread-avatar",s.avatarWrapperClass(o)])},[s.isDefaultAvatar(o)?(h(),g("span",dd,[...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(),ge(qs(s.avatarComponent(o)),Xs({key:1,ref_for:!0},s.avatarProps(o)),null,16)),o.unread?(h(),g("span",{key:2,class:"wm-hist__thread-dot","aria-label":s.t("onboarding.unread")},null,8,fd)):D("",!0)],2),u("span",hd,[u("span",md,R(o.title),1),u("span",{class:"wm-hist__thread-preview",innerHTML:s.renderPreview(o.preview)},null,8,pd)]),u("span",gd,[s.formatTs(o._ts)?(h(),g("span",_d,R(s.formatTs(o._ts)),1)):D("",!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,ud))),128)),s.filteredThreads.length?D("",!0):(h(),g("div",yd,R(i.query?s.t("onboarding.noResults",{query:i.query}):s.t("onboarding.noConversations")),1))])])}const bd=we(id,[["render",vd],["__scopeId","data-v-6bf35ef1"]]);function wd(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 kd={name:"WmActionResult",props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""}},computed:{detailText(){return wd(this.detail)}}},Cd={class:"wm-result__icon","aria-hidden":"true"},Ad={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"},Sd={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"},xd={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"},Td={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"},Md={class:"wm-result__body"},Ed={class:"wm-result__label"},Od={class:"wm-result__detail"};function Id(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-result",`wm-result--${n.state}`])},[u("span",Cd,[n.state==="success"?(h(),g("svg",Ad,[...t[0]||(t[0]=[u("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):n.state==="rejected"?(h(),g("svg",Sd,[...t[1]||(t[1]=[u("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])])):n.state==="awaiting"?(h(),g("svg",xd,[...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(),g("svg",Td,[...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",Md,[u("span",Ed,R(n.label),1),s.detailText?(h(),g(ee,{key:0},[t[4]||(t[4]=u("span",{class:"wm-result__sep","aria-hidden":"true"}," · ",-1)),u("span",Od,R(s.detailText),1)],64)):D("",!0)])],2)}const Rd=we(kd,[["render",Id],["__scopeId","data-v-7284acd0"]]),Ld={name:"WmArtifactFormResponse",inject:{t:{default:()=>xe()}},props:{data:{type:Object,required:!0}},computed:{fields(){var e;return Array.isArray((e=this.data)==null?void 0:e.fields)?this.data.fields:[]}}},Pd={class:"wm-art wm-art--formResponse"},Bd={class:"wm-art__head"},Dd={class:"wm-art__title"},Fd={class:"wm-art__badge wm-art__badge--success"},Nd={class:"wm-art__body"},jd={class:"wm-art__fieldLabel"};function Hd(e,t,n,r,i,s){return h(),g("div",Pd,[u("div",Bd,[u("div",Dd,R(n.data.title||s.t("form.title")),1),u("span",Fd,[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)),ts(" "+R(s.t("form.sent")),1)])]),u("div",Nd,[(h(!0),g(ee,null,Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",jd,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128))])])}const Ud=we(Ld,[["render",Hd],["__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}}},Vd={class:"wm-art wm-art--infoCard"},Kd={key:0,class:"wm-art__image"},Wd=["src","alt"],zd={class:"wm-art__head"},qd={class:"wm-art__headMain"},Gd={class:"wm-art__title"},Yd={key:0,class:"wm-art__subtitle"},Jd={key:1,class:"wm-art__body"},Xd={key:0,class:"wm-art__text"},Qd={class:"wm-art__fieldLabel"};function Zd(e,t,n,r,i,s){return h(),g("div",Vd,[n.data.image_url?(h(),g("figure",Kd,[u("img",{src:n.data.image_url,alt:n.data.title||"",loading:"lazy"},null,8,Wd)])):D("",!0),u("div",zd,[u("div",qd,[u("div",Gd,R(n.data.title),1),n.data.subtitle?(h(),g("div",Yd,R(n.data.subtitle),1)):D("",!0)]),n.data.badge&&n.data.badge.label?(h(),g("span",{key:0,class:re(["wm-art__badge",`wm-art__badge--${n.data.badge.tone||"neutral"}`])},R(n.data.badge.label),3)):D("",!0)]),s.hasBody?(h(),g("div",Jd,[n.data.body?(h(),g("div",Xd,R(n.data.body),1)):D("",!0),s.fields.length?(h(!0),g(ee,{key:1},Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",Qd,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},R(o.value),3)]))),128)):D("",!0)])):D("",!0)])}const ef=we($d,[["render",Zd],["__scopeId","data-v-7eae0e4a"]]);function tf(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 nf={name:"WmArtifactTicket",inject:{t:{default:()=>xe()},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 tf((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}}},sf={class:"wm-art wm-art--ticket"},rf={class:"wm-art__head wm-tk__head"},of={class:"wm-art__title wm-tk__title"},af={class:"wm-tk__sub"},lf={class:"wm-tk__ref"},cf={key:0,class:"wm-tk__text"},uf={key:0,class:"wm-art__body"},df={class:"wm-art__fieldLabel"},ff=["data-level"],hf={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"},mf={key:1,class:"wm-art__footer wm-tk__footer"};function pf(e,t,n,r,i,s){return h(),g("div",sf,[u("div",rf,[u("div",of,R(n.data.title),1),u("div",af,[u("div",lf,[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:re(["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)),ts(" "+R(n.data.status.label),1)],2)]),n.data.body?(h(),g("div",cf,R(n.data.body),1)):D("",!0)]),s.fields.length?(h(),g("div",uf,[(h(!0),g(ee,null,Ae(s.fields,(o,a)=>(h(),g("div",{key:a,class:"wm-art__field"},[u("div",df,R(o.label),1),u("div",{class:re(["wm-art__fieldValue",{"wm-art__fieldValue--multi":o.multiline}])},[s.isPriority(o.label)?(h(),g("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,ff)):s.isDate(o.label)?(h(),g("svg",hf,[...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)])])):D("",!0),u("span",null,R(o.value),1)],2)]))),128))])):D("",!0),n.data.created_at?(h(),g("div",mf,[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)])):D("",!0)])}const gf=we(nf,[["render",pf],["__scopeId","data-v-5f30c914"]]),_f={form_response:Ud,info_card:ef,ticket:gf},yf={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const e=(t=this.artifact)==null?void 0:t.kind;return e&&_f[e]||null}}};function vf(e,t,n,r,i,s){return s.component?(h(),ge(qs(s.component),{key:0,data:n.artifact.data},null,8,["data"])):D("",!0)}const bf=we(yf,[["render",vf]]),wf={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null},t:{default:()=>xe()}},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()}}},kf=["href"],Cf=["src","alt"],Af=["src"],Sf=["src"],xf=["href","download"],Tf={class:"wm-att__main"},Mf={class:"wm-att__name"},Ef={key:0,class:"wm-att__meta"},Of={key:0,class:"wm-att__spin","aria-hidden":"true"};function If(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-att",["wm-att--"+(s.kind||"file")]])},[s.kind==="image"&&i.url?(h(),g("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,Cf)],8,kf)):s.kind==="audio"&&i.url?(h(),g("audio",{key:1,src:i.url,controls:"",preload:"metadata"},null,8,Af)):s.kind==="video"&&i.url?(h(),g("video",{key:2,src:i.url,controls:"",preload:"metadata"},null,8,Sf)):(h(),g("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",Tf,[u("span",Mf,R(s.displayName),1),s.sizeLabel?(h(),g("span",Ef,R(s.sizeLabel),1)):D("",!0)]),i.loading?(h(),g("span",Of)):D("",!0)],8,xf))],2)}const Rf=we(wf,[["render",If],["__scopeId","data-v-0c877a62"]]),Lf={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return Cc(this.text)}}},Pf=["innerHTML"];function Bf(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-bubble","wm-bubble--"+n.role])},[Ba(e.$slots,"default",{},()=>[u("span",{innerHTML:s.rendered},null,8,Pf)])],2)}const Df=we(Lf,[["render",Bf],["__scopeId","data-v-7ab13147"]]),Ff={name:"WmTyping"},Nf={class:"wm-typing"};function jf(e,t,n,r,i,s){return h(),g("div",Nf,[...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 Hf=we(Ff,[["render",jf],["__scopeId","data-v-df2447fd"]]);function Et(e){return e?e.client_msg_id||e.id:""}const Uf={transferred_to_human:"system.transferredToHuman",assigned:"system.assigned",unassigned:"system.unassigned",resolved:"system.resolved",reopened:"system.reopened",idle:"system.idle"},$f=80,Vf=200,Kf={name:"WmMessageList",components:{AIAvatar:qt,HumanAvatar:ss,Bubble:Df,Typing:Hf,ActionResult:Rd,AttachmentPreview:Rf,ArtifactRenderer:bf},inject:{t:{default:()=>xe()},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;const e=[];for(const o of this.messages){const a=this.roleOf(o);if(a==="system"){if(((n=o==null?void 0:o.payload)==null?void 0:n.event)==="action_admin_pending"){const c=e[e.length-1];c&&c.role==="ai"?c.messages.push(o):e.push({key:`g-${Et(o)}`,role:"ai",agentName:"",agentAvatarUrl:null,messages:[o],items:[]});continue}e.push({key:`sys-${Et(o)}`,role:a,messages:[o],items:[],systemLabel:this.systemLabel(o)});continue}const l=e[e.length-1];l&&l.role===a&&(a==="ai"||l.agentName===(((r=o==null?void 0:o.author)==null?void 0:r.name)||""))?l.messages.push(o):e.push({key:`g-${Et(o)}`,role:a,agentName:((i=o==null?void 0:o.author)==null?void 0:i.name)||"",agentAvatarUrl:((s=o==null?void 0:o.author)==null?void 0:s.avatar_url)||null,messages:[o],items:[]})}for(const o of e){if(o.role==="system")continue;const a=[];for(const l of o.messages)for(const f of this.itemsOf(l))a.push(f);o.items=a}const t=[];for(const o of e){if(o.role!=="system"&&!o.items.length)continue;const a=t[t.length-1];if(a&&a.role!=="system"&&a.role===o.role&&(o.role==="ai"||a.agentName===o.agentName)){a.messages.push(...o.messages),a.items.push(...o.items);continue}t.push(o)}for(const o of t)o.role!=="system"&&(o.key=this.stableGroupKey(o.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=ft(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._pressTimer&&clearTimeout(this._pressTimer)},updated(){this.scheduleMeasure()},methods:{messageKey:Et,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=Et(r);if(i&&t.has(i)){n=t.get(i);break}}n==null&&(n=++this._groupIdCounter);for(const r of e){const i=Et(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<=Vf&&(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 f=a.getBoundingClientRect().top-e.getBoundingClientRect().top-o.relY;Math.abs(f)>.5&&(e.scrollTop+=f)};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 $,se,_e;const n=e.items,r=($=n[t])==null?void 0:$.kind,i=(se=n[t-1])==null?void 0:se.kind,s=(_e=n[t+1])==null?void 0:_e.kind,o=e.role==="user",a=14,l=4,f=i==null?void 0:i.bottom,c=s==null?void 0:s.top,p=this.widthByKey[this.rowKeyOf(e,t)],S=this.widthByKey[this.rowKeyOf(e,t-1)],w=this.widthByKey[this.rowKeyOf(e,t+1)],V=.5,O=(he,ke,G)=>he!=null&&p!=null?he+V>=p:ke===G||ke==="card"&&G==="bubble";let J=a,z=a,U=a,Q=a;return o?(f&&(z=l),(c||!s)&&(U=l),f&&O(S,f,r==null?void 0:r.top)&&(J=l),c&&O(w,c,r==null?void 0:r.bottom)&&(Q=l)):(f&&(J=l),(c||!s)&&(Q=l),f&&O(S,f,r==null?void 0:r.top)&&(z=l),c&&O(w,c,r==null?void 0:r.bottom)&&(U=l)),{tl:J,tr:z,br:U,bl:Q}},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?`${Et(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 Ps(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 Ps(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;const t=e==null?void 0:e.payload;return t?t.state==="success"?((n=t.success)==null?void 0:n.summary)||((i=(r=t.success)==null?void 0:r.metadata)==null?void 0:i.description)||"":t.state==="rejected"?((s=t.rejected)==null?void 0:s.reason)||this.t("action.rejectedByUser"):t.state==="failure"&&(((o=t.failure)==null?void 0:o.summary)||((a=t.failure)==null?void 0:a.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=Uf[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},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)}}},Wf={class:"wm-list__wrap"},zf={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},qf={class:"wm-list__loadMore-lbl"},Gf={key:1,class:"wm-list__historyEnd"},Yf={key:2,class:"wm-list__sep"},Jf={class:"wm-list__sep-label"},Xf={key:0,class:"wm-list__sep wm-list__sep--unread"},Qf={class:"wm-list__sep-label wm-list__sep-label--unread"},Zf={key:0,class:"wm-list__sysep"},eh={class:"wm-list__sysep-label"},th=["data-row-key","onPointerdown"],nh={key:0,class:"wm-list__avatarSlot"},sh={key:5,class:"wm-list__body"},rh={key:0},ih={key:1,"aria-hidden":"true"},oh={key:2},ah={key:0},lh={key:1,"aria-hidden":"true"},ch={key:2},uh={key:3,class:"wm-list__row wm-list__row--ai fade-up"},dh={class:"wm-list__avatarSlot"},fh=["aria-label","title"];function hh(e,t,n,r,i,s){const o=ye("AIAvatar"),a=ye("HumanAvatar"),l=ye("ActionResult"),f=ye("ArtifactRenderer"),c=ye("Bubble"),p=ye("AttachmentPreview"),S=ye("Typing");return h(),g("div",Wf,[u("div",{ref:"scrollEl",class:re(["wm-list",{"wm-list--silent":i.silentFades}]),onScrollPassive:t[4]||(t[4]=(...w)=>s.onScroll&&s.onScroll(...w))},[n.loadingMore?(h(),g("div",zf,[t[6]||(t[6]=u("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1)),u("span",qf,R(s.t("messageList.loadingHistory")),1)])):s.historyExhausted?(h(),g("div",Gf,R(s.t("messageList.conversationStart")),1)):D("",!0),n.dateLabel?(h(),g("div",Yf,[t[7]||(t[7]=u("div",{class:"wm-list__line"},null,-1)),u("span",Jf,R(n.dateLabel),1),t[8]||(t[8]=u("div",{class:"wm-list__line"},null,-1))])):D("",!0),(h(!0),g(ee,null,Ae(s.groups,(w,V)=>(h(),g(ee,{key:w.key},[w.key===s.unreadGroupKey?(h(),g("div",Xf,[t[9]||(t[9]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1)),u("span",Qf,R(s.t("messageList.unread")),1),t[10]||(t[10]=u("div",{class:"wm-list__line wm-list__line--unread"},null,-1))])):D("",!0),w.role==="system"||w.items.length?(h(),g("div",{key:1,class:re(["wm-list__group","wm-list__group--"+w.role])},[w.role==="system"?(h(),g("div",Zf,[t[11]||(t[11]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),u("span",eh,R(w.systemLabel),1),t[12]||(t[12]=u("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(h(),g(ee,{key:1},[(h(!0),g(ee,null,Ae(w.items,(O,J)=>(h(),g(ee,{key:`${s.messageKey(O.message)}-${O.partKey}`},[u("div",{"data-row-key":`${s.messageKey(O.message)}-${O.partKey}`,class:re(["wm-list__row fade-up",["wm-list__row--"+w.role,{"is-pending":O.message._pending,"is-failed":O.message._failed}]]),style:Oe(s.cornersStyle(w,J)),onPointerdown:z=>s.onPressStart(`${s.messageKey(O.message)}-${O.partKey}`),onPointerup:t[0]||(t[0]=z=>s.onPressEnd()),onPointercancel:t[1]||(t[1]=z=>s.onPressEnd()),onPointerleave:t[2]||(t[2]=z=>s.onPressEnd()),onContextmenu:t[3]||(t[3]=ht(()=>{},["prevent"]))},[w.role!=="user"?(h(),g("div",nh,[J===w.items.length-1?(h(),g(ee,{key:0},[w.role==="ai"?(h(),ge(o,{key:0,size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])):(h(),ge(a,{key:1,name:w.agentName,"avatar-url":w.agentAvatarUrl,size:26,tail:!0},null,8,["name","avatar-url"]))],64)):D("",!0)])):D("",!0),O.renderAs==="action"?(h(),ge(l,{key:1,state:O.message.payload.state,label:s.actionLabel(O.message),detail:s.actionDetail(O.message)},null,8,["state","label","detail"])):O.renderAs==="admin-pending"?(h(),ge(l,{key:2,state:"awaiting",label:s.t("messageList.approvalRequestSent"),detail:O.message.text_md||""},null,8,["label","detail"])):O.renderAs==="artifact-of-action"?(h(),ge(f,{key:3,artifact:s.actionArtifact(O.message)},null,8,["artifact"])):O.renderAs==="artifact"?(h(),ge(f,{key:4,artifact:s.artifactOf(O.message)},null,8,["artifact"])):(h(),g("div",sh,[O.message.text_md?(h(),ge(c,{key:0,role:w.role,text:O.message.text_md},null,8,["role","text"])):D("",!0),s.attachmentsOf(O.message).length?(h(),g("div",{key:1,class:re(["wm-list__atts",{"wm-list__atts--align-end":w.role==="user"}])},[(h(!0),g(ee,null,Ae(s.attachmentsOf(O.message),(z,U)=>(h(),ge(p,{key:`${s.messageKey(O.message)}-att-${U}`,attachment:z},null,8,["attachment"]))),128))],2)):D("",!0)]))],46,th),J<w.items.length-1&&i.pressedItemKey===`${s.messageKey(O.message)}-${O.partKey}`&&(w.role!=="user"||s.timeOf(O.message))?(h(),g("div",{key:0,class:re(["wm-list__meta wm-list__meta--press",{"wm-list__meta--right":w.role==="user"}])},[w.role!=="user"?(h(),g("span",rh,R(s.roleLabel(w)),1)):D("",!0),w.role!=="user"&&s.timeOf(O.message)?(h(),g("span",ih,"•")):D("",!0),s.timeOf(O.message)?(h(),g("span",oh,R(s.timeOf(O.message)),1)):D("",!0)],2)):D("",!0)],64))),128)),(w.role!=="user"||s.lastTimeOf(w))&&!s.hasTrailingOverlay(w)?(h(),g("div",{key:0,class:re(["wm-list__meta",{"wm-list__meta--right":w.role==="user"}])},[w.role!=="user"?(h(),g("span",ah,R(s.roleLabel(w)),1)):D("",!0),w.role!=="user"&&s.lastTimeOf(w)?(h(),g("span",lh,"•")):D("",!0),s.lastTimeOf(w)?(h(),g("span",ch,R(s.lastTimeOf(w)),1)):D("",!0)],2)):D("",!0)],64))],2)):D("",!0)],64))),128)),n.streamingActive?(h(),g("div",uh,[u("div",dh,[ve(o,{size:26,tail:!0,name:n.aiAgentName,"image-url":n.aiAgentAvatarUrl},null,8,["name","image-url"])]),ve(S)])):D("",!0)],34),ve(ko,{name:"wm-scrollDown"},{default:zs(()=>[i.showScrollDown?(h(),g("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]=(...w)=>s.scrollToBottomSmooth&&s.scrollToBottomSmooth(...w))},[...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,fh)):D("",!0)]),_:1})])}const mh=we(Kf,[["render",hh],["__scopeId","data-v-cf20685c"]]),Un=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",tr=typeof window<"u"&&typeof window.MediaRecorder<"u";function ph(){return tr&&["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 Mo({audio:e}){return{video:!0,audio:!!e,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:e?"include":"exclude"}}async function gh(){if(!Un)return null;let e;try{e=await navigator.mediaDevices.getDisplayMedia(Mo({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await _h(e)}catch(t){return console.error("[media] screenshot capture",t),null}finally{e.getTracks().forEach(t=>{t.stop()})}}async function _h(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(f=>f?a(f):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 yh(e={}){var f;if(!Un||!tr)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(Mo({audio:!0}))}catch(c){return(c==null?void 0:c.name)!=="NotAllowedError"&&console.error("[media] record picker",c),null}const n=ph();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(p=>{p.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,p;if(s&&clearInterval(s),t.getTracks().forEach(S=>{S.stop()}),i.length){const S=r.mimeType||n||"video/webm",w=new Blob(i,{type:S}),V=/mp4/.test(S)?"mp4":"webm",O=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),J=new File([w],`ecran-${O}.${V}`,{type:S});(c=e.onfinalize)==null||c.call(e,J)}else(p=e.oncancel)==null||p.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(p=>{p.stop()}),null}(f=e.onstart)==null||f.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 vh=[{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"}],bh={name:"WmComposer",inject:{t:{default:()=>xe()}},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"],data(){return{local:this.modelValue,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null,kbOffset:0}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},attachItems(){return vh.map(e=>({...e,label:this.t(e.labelKey),disabled:e.action==="screenshot"&&!Un||e.action==="record"&&(!Un||!tr)}))},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()}},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;e&&(e.clientWidth<80||(e.style.height="auto",e.style.height=`${e.scrollHeight}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 gh();e&&this.$emit("attach",e)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const e=await yh({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)}}},wh={key:0,class:"wm-rec"},kh={class:"wm-rec__lbl"},Ch={key:1,class:"wm-compose__menu",role:"menu"},Ah=["disabled","onClick"],Sh={class:"wm-compose__menuIcon"},xh={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},Th=["d"],Mh=["placeholder","disabled"],Eh={class:"wm-compose__actions"},Oh=["title","aria-label","disabled"],Ih=["disabled","aria-label"];function Rh(e,t,n,r,i,s){return h(),g("div",{class:re(["wm-compose-wrap",{"wm-compose-wrap--sheet":n.displayMode==="sheet"}]),style:Oe(i.kbOffset?{transform:`translateY(-${i.kbOffset}px)`}:null)},[i.recording?(h(),g("div",wh,[t[8]||(t[8]=u("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),u("span",kh,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)])):D("",!0),u("form",{class:re(["wm-compose",{"has-attach":i.attachOpen}]),onSubmit:t[7]||(t[7]=ht((...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(),g("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=o=>i.attachOpen=!1)})):D("",!0),i.attachOpen?(h(),g("div",Ch,[(h(!0),g(ee,null,Ae(s.attachItems,o=>(h(),g("button",{key:o.action,type:"button",class:"wm-compose__menuItem",disabled:o.disabled,onClick:a=>s.onAttachAction(o.action)},[u("span",Sh,[(h(),g("svg",xh,[u("path",{d:o.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,Th)]))]),u("span",null,R(o.label),1)],8,Ah))),128))])):D("",!0),at(u("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=o=>i.local=o),class:"wm-compose__input",rows:"3",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))},null,40,Mh),[[Rt,i.local]]),u("div",Eh,[u("button",{type:"button",class:re(["wm-compose__icon",{"is-open":i.attachOpen}]),title:n.attachLabel,"aria-label":n.attachLabel,disabled:i.recording,onClick:t[6]||(t[6]=o=>i.attachOpen=!i.attachOpen)},[...t[9]||(t[9]=[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)])],10,Oh),u("button",{type:"submit",class:re(["wm-compose__send",{"is-empty":!s.canSend}]),disabled:!s.canSend,"aria-label":s.t("composer.send")},[...t[10]||(t[10]=[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:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,Ih)])],34)],6)}const Lh=we(bh,[["render",Rh],["__scopeId","data-v-01e81a27"]]),Ph={name:"WmSuggestionChips",props:{items:{type:Array,default:()=>[]},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("§")}}},Bh=["onClick"];function Dh(e,t,n,r,i,s){return n.items.length?(h(),g("div",{key:s.batchKey,class:"wm-chips"},[(h(!0),g(ee,null,Ae(n.items,(o,a)=>(h(),g("button",{key:a,type:"button",class:"wm-chip",style:Oe({animationDelay:n.baseDelay+a*n.stepDelay+"ms"}),onClick:l=>e.$emit("select",o)},R(o.label),13,Bh))),128))])):D("",!0)}const Fh=we(Ph,[["render",Dh],["__scopeId","data-v-47ad8085"]]),Nh={name:"WmApprovalCard",components:{AIAvatar:qt},inject:{t:{default:()=>xe()}},props:{action:{type:String,required:!0},detail:{type:String,default:""},callbacks:{type:Array,default:()=>[]},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null}},emits:["callback"],computed:{approveCallback(){return this.callbacks.find(e=>e.id==="approve"||e.style==="primary")||this.callbacks[0]},rejectCallback(){return this.callbacks.find(e=>e.id==="reject"||e.style==="danger"||e.style==="neutral")||(this.callbacks.length>1?this.callbacks[1]:null)},approveId(){var e;return(e=this.approveCallback)==null?void 0:e.id},rejectId(){var e;return(e=this.rejectCallback)==null?void 0:e.id},approveLabel(){var e;return((e=this.approveCallback)==null?void 0:e.label)||this.t("approval.approve")},rejectLabel(){var e;return((e=this.rejectCallback)==null?void 0:e.label)||this.t("approval.reject")}}},jh={class:"wm-approval"},Hh={class:"wm-approval__head"},Uh={class:"wm-approval__icon"},$h={class:"wm-approval__main"},Vh={class:"wm-approval__title"},Kh={key:0,class:"wm-approval__detail"},Wh={class:"wm-approval__actions"};function zh(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",jh,[u("div",Hh,[u("div",Uh,[ve(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",$h,[u("div",Vh,R(n.action),1),n.detail?(h(),g("div",Kh,R(n.detail),1)):D("",!0)])]),u("div",Wh,[s.rejectId?(h(),g("button",{key:0,type:"button",class:"wm-approval__btn wm-approval__btn--neutral",onClick:t[0]||(t[0]=a=>e.$emit("callback",s.rejectId))},R(s.rejectLabel),1)):D("",!0),s.approveId?(h(),g("button",{key:1,type:"button",class:"wm-approval__btn wm-approval__btn--primary",onClick:t[1]||(t[1]=a=>e.$emit("callback",s.approveId))},R(s.approveLabel),1)):D("",!0)])])}const qh=we(Nh,[["render",zh],["__scopeId","data-v-a2bed37e"]]);let Qr=0;const Gh=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Yh={name:"WmFormCard",components:{AIAvatar:qt},inject:{t:{default:()=>xe()}},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 Qr+=1,{_uid:Qr,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)||!Gh.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}}}},Jh={class:"wm-form"},Xh={class:"wm-form__head"},Qh={class:"wm-form__icon"},Zh={class:"wm-form__main"},em={class:"wm-form__title"},tm={key:0,class:"wm-form__detail"},nm=["for"],sm={key:0,class:"wm-form__req","aria-hidden":"true"},rm=["id","onUpdate:modelValue","placeholder","required","disabled"],im=["id","onUpdate:modelValue","placeholder","required","disabled"],om=["id","onUpdate:modelValue","placeholder","required","disabled"],am=["id","onUpdate:modelValue","required","disabled"],lm={key:4,class:"wm-form__bool"},cm=["id","onUpdate:modelValue","disabled"],um=["id","onUpdate:modelValue","required","disabled"],dm={value:"",disabled:""},fm=["value"],hm={key:6,class:"wm-form__multi"},mm=["value","checked","disabled","onChange"],pm={key:0,class:"wm-form__err"},gm=["disabled"],_m={key:0,class:"wm-form__spinner","aria-hidden":"true"},ym={key:2,class:"wm-form__doneLbl"};function vm(e,t,n,r,i,s){const o=ye("AIAvatar");return h(),g("div",Jh,[u("div",Xh,[u("div",Qh,[ve(o,{size:24,name:n.agentName,"image-url":n.agentAvatarUrl},null,8,["name","image-url"])]),u("div",Zh,[u("div",em,R(n.form.title||s.t("form.title")),1),n.form.description?(h(),g("div",tm,R(n.form.description),1)):D("",!0)])]),u("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=ht((...a)=>s.onSubmit&&s.onSubmit(...a),["prevent"]))},[(h(!0),g(ee,null,Ae(s.normalizedFields,a=>(h(),g("div",{key:a.key,class:"wm-form__field"},[u("label",{for:`wm-f-${i._uid}-${a.key}`,class:"wm-form__label"},[ts(R(a.label),1),a.required?(h(),g("span",sm,"*")):D("",!0)],8,nm),a.type==="text"?at((h(),g("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,rm)),[[Rt,i.values[a.key]]]):a.type==="textarea"?at((h(),g("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,im)),[[Rt,i.values[a.key]]]):a.type==="number"?at((h(),g("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,om)),[[Rt,i.values[a.key],void 0,{number:!0}]]):a.type==="date"?at((h(),g("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,am)),[[Rt,i.values[a.key]]]):a.type==="boolean"?(h(),g("label",lm,[at(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,cm),[[Yl,i.values[a.key]]]),u("span",null,R(a.placeholder||s.t("common.yes")),1)])):a.type==="select"?at((h(),g("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",dm,R(a.placeholder||s.t("form.choose")),1),(h(!0),g(ee,null,Ae(a.options,l=>(h(),g("option",{key:l.value,value:l.value},R(l.label),9,fm))),128))],8,um)),[[Jl,i.values[a.key]]]):a.type==="multiselect"?(h(),g("div",hm,[(h(!0),g(ee,null,Ae(a.options,l=>(h(),g("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:f=>s.toggleMulti(a.key,l.value,f.target.checked)},null,40,mm),u("span",null,R(l.label),1)]))),128))])):D("",!0)]))),128)),i.error?(h(),g("div",pm,R(i.error),1)):D("",!0),n.readOnly?(h(),g("div",ym,R(s.t("form.responseSent")),1)):(h(),g("button",{key:1,type:"submit",class:"wm-form__submit",disabled:i.busy},[i.busy?(h(),g("span",_m)):D("",!0),u("span",null,R(i.busy?s.t("common.sending"):n.form.submit_label||s.t("common.send")),1)],8,gm))],32)])}const bm=we(Yh,[["render",vm],["__scopeId","data-v-fe65cc56"]]),wm={name:"WmFeedback",inject:{t:{default:()=>xe()}},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})}}},km={class:"wm-fb"},Cm={class:"wm-fb__title"},Am={class:"wm-fb__sub"},Sm={class:"wm-fb__row"},xm=["onClick"],Tm={class:"wm-fb__emoji"},Mm={class:"wm-fb__label"},Em=["disabled"],Om={key:1,class:"wm-fb__done"},Im={class:"wm-fb__doneTitle"},Rm={class:"wm-fb__doneSub"};function Lm(e,t,n,r,i,s){return h(),g("div",km,[n.done?(h(),g("div",Om,[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",Im,R(s.t("feedback.doneTitle")),1),u("div",Rm,R(s.t("feedback.doneSubtitle")),1)])):(h(),g(ee,{key:0},[u("div",Cm,R(s.t("feedback.question")),1),u("div",Am,R(s.t("feedback.subtitle")),1),u("div",Sm,[(h(!0),g(ee,null,Ae(s.options,o=>(h(),g("button",{key:o.v,type:"button",class:re(["wm-fb__opt",{"is-selected":i.sel===o.v}]),onClick:a=>i.sel=o.v},[u("span",Tm,R(o.e),1),u("span",Mm,R(o.l),1)],10,xm))),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,Em)],64))])}const Pm=we(wm,[["render",Lm],["__scopeId","data-v-9b630564"]]),Bm={name:"WmMoreMenu",inject:{t:{default:()=>xe()}},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)}}},Dm={class:"wm-mm"},Fm={class:"wm-mm__pop",role:"menu"},Nm={key:0,class:"wm-mm__section"},jm={class:"wm-mm__label"},Hm={class:"wm-mm__label"},Um={key:1,class:"wm-mm__sep"},$m={class:"wm-mm__section"},Vm={class:"wm-mm__label"},Km={class:"wm-mm__section"},Wm={class:"wm-mm__label"},zm={class:"wm-mm__label"};function qm(e,t,n,r,i,s){return h(),g("div",Dm,[u("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Fm,[n.canRename||n.canExport?(h(),g("div",Nm,[n.canRename?(h(),g("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",jm,R(s.t("moreMenu.editTitle")),1)])):D("",!0),n.canExport?(h(),g("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",Hm,R(s.t("moreMenu.exportTranscript")),1),t[8]||(t[8]=u("span",{class:"wm-mm__hint"},".txt",-1))])):D("",!0)])):D("",!0),n.canRename||n.canExport?(h(),g("div",Um)):D("",!0),u("div",$m,[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",Vm,R(s.t("moreMenu.sound")),1),u("span",{class:re(["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",Km,[n.statusUrl?(h(),g("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",Wm,R(s.t("moreMenu.serviceStatus")),1)])):D("",!0),n.helpUrl?(h(),g("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",zm,R(s.t("moreMenu.helpCenter")),1)])):D("",!0)])])])}const Gm=we(Bm,[["render",qm],["__scopeId","data-v-4cf6d578"]]),Ym={name:"WmRenameDialog",inject:{t:{default:()=>xe()}},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())}}},Jm={class:"wm-dialog"},Xm={class:"wm-dialog__card",role:"dialog","aria-modal":"true"},Qm={class:"wm-dialog__head"},Zm={class:"wm-dialog__title"},ep=["aria-label"],tp={class:"wm-dialog__body"},np=["placeholder"],sp={class:"wm-dialog__actions"},rp=["disabled"];function ip(e,t,n,r,i,s){return h(),g("div",Jm,[u("div",{class:"wm-dialog__scrim",onClick:t[0]||(t[0]=o=>e.$emit("close"))}),u("div",Xm,[u("div",Qm,[u("div",Zm,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,ep)]),u("div",tp,[at(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]=Hn(ht((...o)=>s.onSubmit&&s.onSubmit(...o),["prevent"]),["enter"])),t[4]||(t[4]=Hn(ht(o=>e.$emit("close"),["prevent"]),["esc"]))]},null,40,np),[[Rt,i.value]])]),u("div",sp,[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,rp)])])])}const op=we(Ym,[["render",ip],["__scopeId","data-v-6d5f94a8"]]),Zr="ww-messenger-tokens",ap={name:"Messenger",components:{Launcher:Qc,Header:Cu,Onboarding:rd,History:bd,MessageList:mh,Composer:Lh,SuggestionChips:Fh,ApprovalCard:qh,FormCard:bm,Feedback:Pm,MoreMenu:Gm,RenameDialog:op},mixins:[Mc,Ec,Oc,Rc],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:mc},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:!1,convOpenedAt:0,moreOpen:!1,renameDialogOpen:!1,draftConv:null,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 er(this.language||this.customerLanguage||((e=this.widget)==null?void 0:e.default_language)||"")},translator(){return xe(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 f;const i=e[r.id]||[],s=ft(r.last_read_message_id);let o=0,a=null;for(let c=i.length-1;c>=0;c--){const p=i[c];if(!p)continue;if(((f=p.author)==null?void 0:f.type)==="user")break;const S=ft(p.id);if(S!=null){if(s!=null&&S<=s)break;t[p.id]!==0&&(!a&&p.author&&(a=p.author),o++)}}if(!i.length){const c=ft(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=>n.status!=="resolved").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:Jr(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=Jr(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)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&&yc(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},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(){var t;const e=(t=this.currentConv)==null?void 0:t.status;return e==="waiting"||e==="handled"},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,f,c,p;return(o==null?void 0:o.type)==="action"&&((a=o==null?void 0:o.payload)==null?void 0:a.state)==="pending"||wn(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((f=o==null?void 0:o.payload)==null?void 0:f.attachments)&&o.payload.attachments.length||(c=o==null?void 0:o.metadata)!=null&&c.artifact||(p=o==null?void 0:o.metadata)!=null&&p.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=>wn(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])||[]:[]},pendingApproval(){return!this.currentConv||!this.store||this.actionInFlight?null:this.store.getPendingApproval(this.currentConv.id)},approvalReady(){return this.pendingApproval?this.pendingApproval.id===this.approvalLatchId?!0:!(this.streamingActive||!this.approvalSettled):!1},approvalTitle(){var e,t,n;return((t=(e=this.pendingApproval)==null?void 0:e.payload)==null?void 0:t.name)||((n=this.pendingApproval)==null?void 0:n.text_md)||this.t("action.title")},approvalDetail(){var r,i,s,o,a,l;const e=(s=(i=(r=this.pendingApproval)==null?void 0:r.payload)==null?void 0:i.pending)==null?void 0:s.user_explanation;if(typeof e=="string"&&e.trim())return e.trim();const t=(l=(a=(o=this.pendingApproval)==null?void 0:o.payload)==null?void 0:a.pending)==null?void 0:l.prepared_params;if(!t||typeof t!="object")return"";const n=Object.entries(t);return n.length?n.slice(0,2).map(([f,c])=>`${f}: ${c}`).join(" · "):""},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.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.pendingApproval||this.actionInFlight||this.streamingActive||!this.approvalSettled?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.feedbackDone?!0:e.status!=="resolved"?!1:!((t=e.metadata)!=null&&t.feedback):!1},floatVisible(){return this.approvalReady||!!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:Ps(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.resetApprovalPacing(),this.isViewingThread&&(this.unreadAnchorId=ft((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=ft((n=this.currentConv)==null?void 0:n.last_read_message_id),this.unreadBoundaryTs=new Date().toISOString()):e||(this.unreadAnchorId=null,this.unreadBoundaryTs="")},pendingApproval:{handler(e,t){if(e&&!t){const n=e!=null&&e.created_at?Date.parse(e.created_at):NaN;if(!(Number.isFinite(n)&&n>=this.convOpenedAt)){this.resetApprovalPacing();return}this.bumpApprovalSettle(2600)}else!e&&t&&this.resetApprovalPacing()},immediate:!1},streamingActive(e,t){e!==t&&this.pendingApproval&&this.pendingApproval.id!==this.approvalLatchId&&this.bumpApprovalSettle()},approvalReady(e){e&&this.pendingApproval&&(this.approvalLatchId=this.pendingApproval.id)},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(Zr)){const e=document.createElement("style");e.id=Zr,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.resetApprovalPacing(),this.teardownNotifications(),this.store&&this.store.destroy()},methods:{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=xs(cc({baseUrl:this.baseUrl,widgetId:this.widgetId})),this.store=xs(hc(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=!1,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.scrollToBottom)==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,p,S,w,V,O,J;if(this.isOpen)return;const e=(p=(c=this.$el)==null?void 0:c.querySelector)==null?void 0:p.call(c,".wm-launcherWrap");if(!e)return;const t=e.getBoundingClientRect();if(!t.width||!t.height)return;const n=(((S=this.launcherPeeks)==null?void 0:S.length)??0)>0,r=16,i=Math.ceil(t.width),s=Math.ceil(t.height),o=(V=(w=this.$el)==null?void 0:w.querySelector)==null?void 0:V.call(w,".wm-launcher"),a=(J=(O=this.$el)==null?void 0:O.querySelectorAll)==null?void 0:J.call(O,".wm-peek"),l=a&&a.length?a[a.length-1]:null;let f=null;if(l){const z=l.getBoundingClientRect();f={width:Math.ceil(z.width),height:Math.ceil(z.height),rightOffset:Math.max(0,Math.ceil(t.right-z.right)),bottomOffset:Math.max(0,Math.ceil(t.bottom-z.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:f,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})},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()},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 f={...this.welcomeRevealTimers};delete f[e],this.welcomeRevealTimers=f},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":Tc(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(Rn(this.statusUrl))try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(Rn(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="",await this.store.send(n,e,{attachments:r.length?r: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 onApprovalCallback(e){const t=this.pendingApproval;t&&await this.store.clickCallback(t.id,e)},async onFormSubmit({values:e}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const n=wc(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:kc(t.form,e,this.translator)}}))},async onAttach(e){if(!(!e||!this.transport))try{const t=await this.transport.uploadAttachment(e);this.pendingAttachments.push({type:t.type||"file",path:t.path,name:e.name||this.t("attachment.fileFallbackName"),mime_type:e.type,size_bytes:e.size})}catch(t){console.error("[ww-messenger] attachment upload failed",t)}},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(!Rn(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=!0}catch(n){console.error("[ww-messenger] feedback failed",n)}finally{this.feedbackBusy=!1}}}}},lp={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},cp=["aria-label"],up={key:0,class:"wm-state"},dp={class:"wm-state__err"},fp={class:"wm-state__errTitle"},hp={class:"wm-state__errSub"},mp={class:"wm-bottom"},pp={key:0,ref:"floatEl",class:"wm-float"},gp={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},_p={class:"wm-actionWait__lbl"},yp={key:2,class:"wm-attached"},vp=["aria-label","onClick"];function bp(e,t,n,r,i,s){const o=ye("Launcher"),a=ye("Header"),l=ye("History"),f=ye("Onboarding"),c=ye("MessageList"),p=ye("ApprovalCard"),S=ye("FormCard"),w=ye("Feedback"),V=ye("SuggestionChips"),O=ye("Composer"),J=ye("MoreMenu"),z=ye("RenameDialog");return h(),g("div",{class:re(["wm-root",`wm-root--${n.displayMode}`]),style:Oe(s.rootStyle)},[!i.isOpen&&!s.isEmbedded?(h(),ge(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"])):D("",!0),i.isOpen||s.isEmbedded?(h(),g("section",{key:1,class:re(["wm-panel",`wm-panel--${n.displayMode}`,{"wm-panel--welcome":s.ready&&!s.error&&!s.currentConv}]),style:Oe(i.floatHeight?{"--wm-float-h":i.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger",onClick:t[6]||(t[6]=(...U)=>s.onPanelClick&&s.onPanelClick(...U))},[!s.ready&&!s.error?(h(),g("div",lp,[s.isEmbedded?D("",!0):(h(),g("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[7]||(t[7]=[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,cp)),t[8]||(t[8]=u("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(h(),g(ee,{key:1},[ve(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"]),s.error?(h(),g("div",up,[u("div",dp,[t[9]||(t[9]=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",fp,R(s.t("error.connectionFailed")),1),u("div",hp,R(s.error),1)])])])):!s.currentConv&&i.showHistory?(h(),ge(l,{key:1,threads:s.openThreads,onResume:s.onDrawerPick},null,8,["threads","onResume"])):s.currentConv?(h(),g(ee,{key:3},[ve(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",mp,[s.floatVisible?(h(),g("div",pp,[s.approvalReady?(h(),ge(p,{key:0,action:s.approvalTitle,detail:s.approvalDetail,callbacks:s.pendingApproval.callbacks,"agent-name":s.agentName,"agent-avatar-url":s.agentAvatarUrl,onCallback:s.onApprovalCallback},null,8,["action","detail","callbacks","agent-name","agent-avatar-url","onCallback"])):s.pendingForm?(h(),ge(S,{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(),ge(w,{key:2,busy:i.feedbackBusy,done:i.feedbackDone,onSubmit:s.onFeedback},null,8,["busy","done","onSubmit"])):(h(),ge(V,{key:3,items:s.suggestions,onSelect:s.onSuggestion},null,8,["items","onSelect"]))],512)):D("",!0),s.actionInFlight?(h(),g("div",gp,[t[10]||(t[10]=u("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),u("span",_p,R(s.t("action.inProgress",{name:s.actionInFlightName})),1)])):(h(),ge(O,{key:2,ref:"composer",modelValue:i.draft,"onUpdate:modelValue":t[2]||(t[2]=U=>i.draft=U),placeholder:s.composerPlaceholder,disabled:!!s.pendingApproval,"attach-label":s.t("composer.attachFile"),"display-mode":n.displayMode,onSend:s.onSend,onAttach:s.onAttach},null,8,["modelValue","placeholder","disabled","attach-label","display-mode","onSend","onAttach"]))]),i.moreOpen?(h(),ge(J,{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[3]||(t[3]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["can-rename","can-export","sound-enabled","status-url","help-url","onSoundToggle","onAction"])):D("",!0),i.renameDialogOpen&&s.currentConv&&!s.currentConv._draft?(h(),ge(z,{key:1,"initial-value":s.currentConv.name||"",title:s.t("rename.dialogTitle"),onClose:t[4]||(t[4]=U=>i.renameDialogOpen=!1),onSubmit:s.onRenameSubmit},null,8,["initial-value","title","onSubmit"])):D("",!0),i.pendingAttachments.length?(h(),g("div",yp,[(h(!0),g(ee,null,Ae(i.pendingAttachments,(U,Q)=>(h(),g("div",{key:Q,class:"wm-attached__chip"},[t[12]||(t[12]=u("svg",{width:"11",height:"11",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)),u("span",null,R(U.name),1),u("button",{type:"button","aria-label":s.t("attachment.remove"),onClick:$=>i.pendingAttachments.splice(Q,1)},[...t[11]||(t[11]=[u("svg",{width:"10",height:"10",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,vp)]))),128))])):D("",!0)],64)):(h(),ge(f,{key:2,title:s.widgetTitle,subtitle:s.widgetSubtitle,"agent-name":s.agentName,"default-icon-url":s.defaultIconUrl,"quick-links":s.quickLinks,"open-threads":s.openThreads,busy:i.busy,onStart:s.startConv,onSelect:s.onQuickLink,onResume:s.onDrawerPick,onViewHistory:t[1]||(t[1]=U=>i.showHistory=!0)},null,8,["title","subtitle","agent-name","default-icon-url","quick-links","open-threads","busy","onStart","onSelect","onResume"])),i.moreOpen&&!s.currentConv?(h(),ge(J,{key:4,"can-rename":!1,"can-export":!1,"sound-enabled":e.soundEnabled,"status-url":s.statusUrl,"help-url":s.helpUrl,onClose:t[5]||(t[5]=U=>i.moreOpen=!1),onSoundToggle:e.onSoundToggle,onAction:s.onMoreAction},null,8,["sound-enabled","status-url","help-url","onSoundToggle","onAction"])):D("",!0)],64))],6)):D("",!0)],6)}const wp=we(ap,[["render",bp],["__scopeId","data-v-a3812812"]]),ei=window.__WIDGET_ID,ti=window.__BASE_URL,kp=window.__DISPLAY_MODE||"floating",ni=window.__LANGUAGE||"";window.__MESSENGER_IFRAME_VERSION="0.5.61";if(!ei||!ti)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)}nc({render:()=>vo(wp,{baseUrl:ti,widgetId:ei,displayMode:kp,...ni?{language:ni}:{}})}).mount("#app")}
|