@_solaris/messenger-widget 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,127 @@
1
+ messenger-widget — Proprietary Software License Agreement
2
+
3
+ Copyright (c) 2026 Victor Cazenave
4
+ (the "Licensor"). All rights reserved.
5
+
6
+ PLEASE READ THIS AGREEMENT CAREFULLY. By installing, downloading, copying,
7
+ embedding, or otherwise using the Software, you (the "Licensee" or "You")
8
+ agree to be bound by this Agreement. If you do not agree, do not use the
9
+ Software.
10
+
11
+ This Software is proprietary and source-available. It is licensed, not sold.
12
+ Public availability of the Software (including, without limitation, on the
13
+ npm registry or any other public distribution channel) does NOT place it in
14
+ the public domain and does NOT grant any right beyond those expressly stated
15
+ below. The absence of a technical restriction is not permission.
16
+
17
+ 1. DEFINITIONS
18
+
19
+ "Software" means the messenger-widget package, including its source code,
20
+ builds, assets, and documentation, in original unmodified form.
21
+
22
+ "Licensor Service" means the messaging backend, servers, and APIs operated
23
+ by or on behalf of the Licensor (the "messenger-server") with which the
24
+ Software is designed to communicate.
25
+
26
+ "Authorized Application" means Licensee's own application, website, or SaaS
27
+ product into which the Software is embedded for use by that application's
28
+ end users.
29
+
30
+ 2. LICENSE GRANT
31
+
32
+ Subject to continuous compliance with this Agreement, the Licensor grants
33
+ Licensee a limited, non-exclusive, non-transferable, non-sublicensable,
34
+ revocable license to:
35
+
36
+ (a) install and use the Software, in its original unmodified form, solely
37
+ as embedded within an Authorized Application; and
38
+
39
+ (b) use the Software solely to connect to and interoperate with the
40
+ Licensor Service.
41
+
42
+ End users of an Authorized Application may use the functionality the
43
+ Software provides as part of the normal operation of that application.
44
+
45
+ 3. RESTRICTIONS
46
+
47
+ Except as expressly permitted in Section 2, Licensee shall NOT, and shall
48
+ not permit any third party to:
49
+
50
+ (a) use the Software with, or cause it to connect to, any backend, server,
51
+ service, or API other than the Licensor Service;
52
+
53
+ (b) modify, adapt, translate, or create derivative works of the Software,
54
+ or merge it into other software except mere embedding as permitted
55
+ in Section 2;
56
+
57
+ (c) reverse engineer, decompile, or disassemble the Software, or attempt
58
+ to derive its source organization, except, and only to the extent,
59
+ such restriction is expressly prohibited by applicable law;
60
+
61
+ (d) distribute, publish, sublicense, sell, rent, lease, lend, or otherwise
62
+ make the Software available to any third party, except as strictly
63
+ embedded within an Authorized Application for that application's normal
64
+ operation;
65
+
66
+ (e) remove, alter, or obscure any copyright, trademark, or other
67
+ proprietary notices;
68
+
69
+ (f) circumvent or disable any technical, security, or usage limitation;
70
+ or
71
+
72
+ (g) use the Software to build, train, or operate a product or service that
73
+ competes with the Software or the Licensor Service.
74
+
75
+ 4. RESERVATION OF RIGHTS / OWNERSHIP
76
+
77
+ The Software is and remains the exclusive property of the Licensor and is
78
+ protected by intellectual property laws. All rights not expressly granted
79
+ in this Agreement are reserved by the Licensor. No title to or ownership of
80
+ the Software is transferred.
81
+
82
+ 5. TERM AND TERMINATION
83
+
84
+ This Agreement is effective until terminated. It terminates automatically,
85
+ without notice, if Licensee breaches any term. The Licensor may also
86
+ terminate it at any time where permitted by law. Upon termination, Licensee
87
+ must immediately cease all use of the Software and remove it from all
88
+ Authorized Applications and systems. Sections 3, 4, 6, 7, and 8 survive
89
+ termination.
90
+
91
+ 6. UPDATES
92
+
93
+ Any updates, patches, or new versions provided by the Licensor are governed
94
+ by this Agreement unless accompanied by a separate license, in which case
95
+ that separate license governs those updates.
96
+
97
+ 7. DISCLAIMER OF WARRANTY
98
+
99
+ THE SOFTWARE IS PROVIDED "AS IS" AND "AS AVAILABLE", WITHOUT WARRANTY OF
100
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
101
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
102
+ NON-INFRINGEMENT. LICENSEE BEARS THE ENTIRE RISK AS TO THE USE AND
103
+ PERFORMANCE OF THE SOFTWARE.
104
+
105
+ 8. LIMITATION OF LIABILITY
106
+
107
+ TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL THE LICENSOR BE
108
+ LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE
109
+ DAMAGES, OR ANY LOSS OF PROFITS, REVENUE, DATA, OR USE, ARISING OUT OF OR
110
+ RELATED TO THIS AGREEMENT OR THE SOFTWARE, EVEN IF ADVISED OF THE
111
+ POSSIBILITY OF SUCH DAMAGES. THE LICENSOR'S TOTAL AGGREGATE LIABILITY
112
+ SHALL NOT EXCEED THE GREATER OF THE AMOUNTS PAID BY LICENSEE TO THE
113
+ LICENSOR FOR THE SOFTWARE IN THE TWELVE MONTHS PRECEDING THE CLAIM, OR
114
+ EUR 100.
115
+
116
+ 9. GOVERNING LAW
117
+
118
+ This Agreement is governed by the laws of France, without regard to
119
+ conflict-of-law rules. The competent courts of France shall have
120
+ exclusive jurisdiction.
121
+
122
+ 10. CONTACT
123
+
124
+ For licensing inquiries: admin@victorc.fr.
125
+
126
+ This document is not legal advice. Have it reviewed by qualified legal
127
+ counsel before commercial use.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # messenger-widget
2
+
3
+ Embeddable chat messenger widget. Same UI as the former `ww-messenger` WeWeb
4
+ plugin, repackaged as a framework-agnostic npm package.
5
+
6
+ Published as `@_solaris/messenger-widget`.
7
+
8
+ ## Two ways to use it
9
+
10
+ ### 1. Vue 3 library
11
+
12
+ ```bash
13
+ npm i @_solaris/messenger-widget vue
14
+ ```
15
+
16
+ ```js
17
+ import { Messenger } from '@_solaris/messenger-widget';
18
+ import '@_solaris/messenger-widget/style.css';
19
+
20
+ // In a Vue 3 app:
21
+ // <Messenger :base-url="..." :widget-id="..." :user-id="..." :user-hash="..." display-mode="floating" />
22
+ ```
23
+
24
+ It also exports the individual presentational components, the design tokens and
25
+ helpers — used by the WeWeb "conversation admin" plugin which supplies its own
26
+ WeWeb-managed data instead of the built-in HMAC/SSE transport:
27
+
28
+ ```js
29
+ import {
30
+ MessageList, Bubble, Composer, ApprovalCard, FormCard,
31
+ ArtifactRenderer, AIAvatar, HumanAvatar, TeamAvatars, AttachmentPreview,
32
+ tokens, renderMarkdown, uuid, createStore, createTransport,
33
+ } from '@_solaris/messenger-widget';
34
+ ```
35
+
36
+ ### 2. Standalone embed (any site, no build step)
37
+
38
+ ```html
39
+ <script src="https://your-cdn/messenger.embed.js"></script>
40
+ <script>
41
+ Messenger.init({
42
+ baseUrl: 'https://messenger.your-saas.com',
43
+ widgetId: '…',
44
+ userId: '…',
45
+ userHash: '…', // HMAC-SHA256(secret, userId), computed server-side
46
+ displayMode: 'floating' // 'floating' | 'sheet' | 'embedded'
47
+ });
48
+ // Messenger.destroy() to tear it down.
49
+ </script>
50
+ ```
51
+
52
+ `init()` is idempotent and credential-aware (no-op until creds are complete,
53
+ no-op if re-called with identical options) — see
54
+ [examples/weweb-embed.md](examples/weweb-embed.md) for the WeWeb integration
55
+ (reactive HMAC via WeWeb variables + workflow).
56
+
57
+ ## Build
58
+
59
+ ```bash
60
+ npm install
61
+ npm run build # build:lib + build:embed + build:types → dist/
62
+ ```
63
+
64
+ | Output | Target | Vue |
65
+ | -------------------------- | ------ | ---------- |
66
+ | `dist/messenger.js` / `.cjs` + `dist/style.css` | lib | external (peer) |
67
+ | `dist/messenger.embed.js` | embed | bundled in |
68
+ | `dist/types/` | types | from JSDoc |
69
+
70
+ ## License
71
+
72
+ Proprietary and source-available. The Software may be embedded in your own
73
+ application **only** to interoperate with the Licensor's backend service; no
74
+ modification, no use with any other backend, no redistribution. Public
75
+ availability on npm grants no rights beyond the license. See
76
+ [LICENSE](LICENSE).
@@ -0,0 +1,56 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),Ie=["connected","message","message_stream","conversation_updated","config_updated","action_status"],Oe=5*60*1e3,De=10*60*1e3,Le=30*1e3;function ae(n){const t={baseUrl:Re(n.baseUrl||""),widgetId:n.widgetId||"",userId:n.userId||"",userHash:n.userHash||"",listeners:new Map,eventSource:null,connection:"idle",visibilityHandler:null,started:!1,panelOpen:!1,pollTimer:null,burstTimer:null,hiddenGraceTimer:null,lastActivityAt:null};if(!t.baseUrl||!t.widgetId||!t.userId||!t.userHash)throw new Error("[transport] baseUrl, widgetId, userId, userHash are all required");function r(u,h){return t.listeners.has(u)||t.listeners.set(u,new Set),t.listeners.get(u).add(h),()=>t.listeners.get(u).delete(h)}function a(u,h){const v=t.listeners.get(u);v&&v.forEach(w=>{try{w(h)}catch(E){console.error("[transport] listener",u,E)}})}function s(u){t.connection!==u&&(t.connection=u,a("connection",u))}function o(){return{"X-User-Id":t.userId,"X-User-Hash":t.userHash,"X-Widget-Id":t.widgetId}}async function i(u,h,v){const w=await fetch(`${t.baseUrl}${h}`,{method:u,headers:{"Content-Type":"application/json",...o()},body:v!==void 0?JSON.stringify(v):void 0});if(!w.ok){const E=await l(w),M=new Error(`HTTP ${w.status} ${u} ${h} :: ${(E==null?void 0:E.error)||w.statusText}`);throw M.status=w.status,M.body=E,M}return w.status===204?null:w.json()}async function l(u){try{return await u.json()}catch{return null}}async function p(){const[u,h]=await Promise.all([fetch(`${t.baseUrl}/widgets/${encodeURIComponent(t.widgetId)}/config`).then(async v=>{if(!v.ok){const w=await l(v);throw new Error(`HTTP ${v.status} GET /widgets/:id/config :: ${(w==null?void 0:w.error)||v.statusText}`)}return v.json()}),i("GET","/customers/me")]);return{config:u,customer:(h==null?void 0:h.customer)??null}}async function g(){const u=await i("GET","/customers/me");return(u==null?void 0:u.customer)??null}async function f(u){const h=await i("PATCH","/customers/me",u);return(h==null?void 0:h.customer)??null}async function C(){const u=await i("GET","/conversations");return(u==null?void 0:u.conversations)??[]}async function V(u={}){return(await i("POST","/conversations",u)).conversation}async function b(u){return(await i("GET",`/conversations/${encodeURIComponent(u)}`)).conversation}async function x(u,h){return(await i("PATCH",`/conversations/${encodeURIComponent(u)}`,h)).conversation}async function B(u,h={}){const v=new URLSearchParams;h.before&&v.set("before",h.before),h.since&&v.set("since",h.since),h.limit&&v.set("limit",String(h.limit));const w=v.toString()?`?${v.toString()}`:"";return i("GET",`/conversations/${encodeURIComponent(u)}/messages${w}`)}async function T(u,h){O();const v={client_msg_id:h.client_msg_id,type:"content",text_md:h.text_md,author:{id:t.userId,type:"user"},created_at:h.created_at||new Date().toISOString()};return Array.isArray(h.attachments)&&h.attachments.length&&(v.payload={type:"content",attachments:h.attachments}),h.metadata&&typeof h.metadata=="object"&&(v.metadata=h.metadata),i("POST",`/conversations/${encodeURIComponent(u)}/messages`,v)}async function S(u,h,v){return O(),i("POST",`/messages/${encodeURIComponent(u)}/callbacks/${encodeURIComponent(h)}`,v?{inputs:v}:{})}async function I(u){const h=u.name||"attachment",v=u.type||"application/octet-stream",w=u.size||0,E=await i("POST","/attachments",{mime_type:v,size_bytes:w,name:h}),M=await fetch(E.upload_url,{method:"PUT",headers:{"Content-Type":v},body:u});if(!M.ok)throw new Error(`HTTP ${M.status} PUT signed upload`);return{type:Fe(v),path:E.path,mime_type:v,size_bytes:w}}async function $(u){return i("GET",`/attachments/sign?path=${encodeURIComponent(u)}`)}function z(){const u=new URLSearchParams({userId:t.userId,userHash:t.userHash,widgetId:t.widgetId}).toString();return`${t.baseUrl}/stream?${u}`}function L(){if(!t.eventSource&&!(typeof document<"u"&&document.hidden))try{const u=new EventSource(z());for(const h of Ie)u.addEventListener(h,v=>q(h,v.data));u.addEventListener("error",()=>a("error",new Error("SSE error"))),t.eventSource=u,s("open")}catch(u){console.error("[transport] SSE open failed",u),a("error",u)}}function q(u,h){try{const v=JSON.parse(h),w=v&&typeof v=="object"&&"data"in v?v.data:v;a(u,w)}catch(v){console.error("[transport] bad SSE payload",u,v)}}function R(){t.eventSource&&(t.eventSource.close(),t.eventSource=null),t.connection!=="paused"&&s("idle")}function O(){clearTimeout(t.burstTimer),L(),t.panelOpen||(t.burstTimer=setTimeout(()=>{t.panelOpen||R()},De))}function W(u){t.panelOpen=!!u,t.panelOpen?(clearTimeout(t.burstTimer),L()):O()}async function c(){try{const u=await C(),h=u.reduce((w,E)=>{const M=E==null?void 0:E.last_message_at;return M&&(!w||M>w)?M:w},null);h&&(!t.lastActivityAt||h>t.lastActivityAt)&&(t.lastActivityAt=h,a("activity",{conversations:u,latestAt:h}),O())}catch(u){console.error("[transport] poll failed",u)}}function d(){m(),!(typeof document<"u"&&document.hidden)&&(t.pollTimer=setInterval(c,Oe))}function m(){t.pollTimer&&(clearInterval(t.pollTimer),t.pollTimer=null)}function _(){if(document.hidden)clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=setTimeout(()=>{t.hiddenGraceTimer=null,document.hidden&&(m(),R(),s("paused"))},Le);else{if(t.hiddenGraceTimer){clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null;return}s("idle"),d(),t.panelOpen&&L()}}async function k(){if(t.started)return t.lastBootstrap;t.started=!0;const u=await p();t.lastBootstrap=u;try{const h=await C();t.lastActivityAt=h.reduce((v,w)=>{const E=w==null?void 0:w.last_message_at;return E&&(!v||E>v)?E:v},null)}catch(h){console.error("[transport] initial /conversations failed",h)}return typeof document<"u"&&(t.visibilityHandler=_,document.addEventListener("visibilitychange",t.visibilityHandler)),d(),u}function y(){m(),clearTimeout(t.burstTimer),clearTimeout(t.hiddenGraceTimer),t.hiddenGraceTimer=null,R(),t.visibilityHandler&&(document.removeEventListener("visibilitychange",t.visibilityHandler),t.visibilityHandler=null),t.started=!1}return{on:r,start:k,stop:y,setPanelOpen:W,bootstrap:p,getCustomer:g,patchCustomer:f,listConversations:C,createConversation:V,getConversation:b,patchConversation:x,listMessages:B,postMessage:T,postCallback:S,uploadAttachment:I,signAttachment:$,get connection(){return t.connection}}}function Re(n){return n.endsWith("/")?n.slice(0,-1):n}function Fe(n){return n.startsWith("image/")?"image":n.startsWith("video/")?"video":n.startsWith("audio/")?"audio":"file"}function Y(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const n=new Uint8Array(16);if(typeof crypto<"u"&&crypto.getRandomValues)crypto.getRandomValues(n);else for(let r=0;r<16;r++)n[r]=Math.floor(Math.random()*256);n[6]=n[6]&15|64,n[8]=n[8]&63|128;const t=[...n].map(r=>r.toString(16).padStart(2,"0"));return t.slice(0,4).join("")+"-"+t.slice(4,6).join("")+"-"+t.slice(6,8).join("")+"-"+t.slice(8,10).join("")+"-"+t.slice(10,16).join("")}function ie(n){const t=e.reactive({ready:!1,error:null,config:null,customer:null,conversations:[],messagesByConv:{},paginationByConv:{},streamingByMsgId:{},awaitingCallback:{},runningActionsByConv:{},connection:"idle"}),r=[];r.push(n.on("connection",c=>{t.connection=c})),r.push(n.on("message",c=>{const d=c==null?void 0:c.conversation_id,m=c==null?void 0:c.message;!d||!(m!=null&&m.id)||(z(d,m),m.client_msg_id&&delete t.streamingByMsgId[m.client_msg_id],R(d,m.created_at))})),r.push(n.on("message_stream",c=>{const d=c==null?void 0:c.message_id,m=c==null?void 0:c.token;!d||typeof m!="string"||(t.streamingByMsgId[d]=(t.streamingByMsgId[d]||"")+m)})),r.push(n.on("conversation_updated",c=>{const d=c==null?void 0:c.conversation_id,m=c==null?void 0:c.changes;if(!d||!m)return;const _=t.conversations.findIndex(k=>k.id===d);_!==-1&&(t.conversations[_]={...t.conversations[_],...m})})),r.push(n.on("config_updated",c=>{c!=null&&c.config&&(t.config=c.config)})),r.push(n.on("action_status",c=>{const d=c==null?void 0:c.conversation_id,m=c==null?void 0:c.action_id,_=c==null?void 0:c.action_name;if(!d||!m)return;const k=t.runningActionsByConv[d]||{};c.state==="running"?(k[m]=_||m,t.runningActionsByConv[d]={...k}):c.state==="done"&&(delete k[m],t.runningActionsByConv[d]={...k})})),r.push(n.on("activity",c=>{Array.isArray(c==null?void 0:c.conversations)&&(t.conversations=c.conversations)}));async function a(){try{const c=new Promise((m,_)=>setTimeout(()=>_(new Error("bootstrap timeout (15s) — check baseUrl, CORS, and network")),15e3)),d=await Promise.race([n.start(),c]);t.config=d.config,t.customer=d.customer,t.conversations=await Promise.race([n.listConversations(),c]),t.ready=!0}catch(c){console.error("[store] start failed",c),t.error=(c==null?void 0:c.message)||String(c)}}function s(){for(const c of r)try{c()}catch{}n.stop()}async function o(c={}){const d=await n.createConversation(c),m=t.conversations.findIndex(_=>_.id===d.id);return m===-1?t.conversations=[d,...t.conversations]:t.conversations[m]=d,d}const i=50;async function l(c){if(t.messagesByConv[c])return;const d=await n.listMessages(c,{limit:i});t.messagesByConv[c]=(d==null?void 0:d.messages)??[],g(c,{nextCursor:(d==null?void 0:d.next_cursor)??null,loading:!1,loaded:!0})}async function p(c){const d=t.paginationByConv[c];if(!(!d||d.loading||!d.nextCursor)){g(c,{...d,loading:!0});try{let k=d.nextCursor,y=[],u=0;for(;u<6&&k;u++){const E=await n.listMessages(c,{before:k,limit:i}),M=(E==null?void 0:E.messages)??[];if(y=[...M,...y],k=(E==null?void 0:E.next_cursor)??null,!M.length||y.length>=60)break}const h=t.messagesByConv[c]||[],v=new Set(h.map(E=>String(E==null?void 0:E.id))),w=[...y.filter(E=>!v.has(String(E==null?void 0:E.id))),...h];t.messagesByConv[c]=w,g(c,{nextCursor:k,loading:!1,loaded:!0})}catch(m){console.error("[store] loadMore failed",m),g(c,{...d,loading:!1})}}}function g(c,d){t.paginationByConv={...t.paginationByConv,[c]:d}}async function f(c,d){const m=await n.patchConversation(c,d),_=t.conversations.findIndex(k=>k.id===c);_!==-1&&(t.conversations[_]=m)}async function C(c,d,{attachments:m,metadata:_}={}){var w;const k=(d||"").trim(),y=Array.isArray(m)&&m.length>0;if(!c||!k&&!y)return;const u=Y(),h=W(c),v={id:u,client_msg_id:u,conversation_id:c,type:"content",text_md:k,author:{type:"user",id:((w=t.customer)==null?void 0:w.external_id)||null},created_at:h,_pending:!0,...y?{payload:{type:"content",attachments:m}}:{},..._&&typeof _=="object"?{metadata:_}:{}};z(c,v);try{await n.postMessage(c,{client_msg_id:u,text_md:k,created_at:h,...y?{attachments:m}:{},..._&&typeof _=="object"?{metadata:_}:{}})}catch(E){console.error("[store] send failed",E),q(c,u,{_failed:!0,_pending:!1})}}async function V(c,d,m){c!=null&&(t.awaitingCallback[c]=!0);try{await n.postCallback(c,d,m)}catch(_){console.error("[store] callback failed",_),c!=null&&delete t.awaitingCallback[c]}}const b=new Map;async function x(c){if(!c)return null;const d=b.get(c);if(d!=null&&d.url){const m=d.expires_at?Date.parse(d.expires_at):0;if(!m||m-Date.now()>6e4)return d.url}try{const m=await n.signAttachment(c);if(m!=null&&m.signed_url)return b.set(c,{url:m.signed_url,expires_at:m.expires_at}),m.signed_url}catch(m){console.error("[store] sign attachment failed",m)}return null}async function B(c,{rating:d,comment:m}={}){const _=t.conversations.find(u=>u.id===c),y={...(_==null?void 0:_.metadata)||{},feedback:{rating:d,comment:m||null,submitted_at:new Date().toISOString()}};await f(c,{metadata:y})}function T(c){var m,_;const d=t.messagesByConv[c]||[];for(let k=d.length-1;k>=0;k--){const y=d[k];if((y==null?void 0:y.type)==="action"&&((m=y==null?void 0:y.payload)==null?void 0:m.type)==="action"&&((_=y==null?void 0:y.payload)==null?void 0:_.state)==="pending"&&Array.isArray(y==null?void 0:y.callbacks)&&y.callbacks.length>0&&!t.awaitingCallback[y.id])return y}return null}function S(c){var m,_,k;const d=t.messagesByConv[c]||[];for(let y=d.length-1;y>=0;y--){const u=d[y];if(((m=u==null?void 0:u.author)==null?void 0:m.type)==="user"||(u==null?void 0:u.type)==="action"&&((_=u==null?void 0:u.payload)==null?void 0:_.state)==="pending")return null;const h=(k=u==null?void 0:u.metadata)==null?void 0:k.form;if(h&&Array.isArray(h.fields)&&h.fields.length>0)return{message:u,form:h}}return null}function I(c){const d=t.runningActionsByConv[c];if(!d)return null;const m=Object.keys(d);if(m.length===0)return null;const _=m[0];return{id:_,payload:{name:d[_]}}}function $(c){var m,_,k,y;const d=t.messagesByConv[c]||[];for(let u=d.length-1;u>=0;u--){const h=d[u];if(((m=h==null?void 0:h.author)==null?void 0:m.type)==="user")return[];if((h==null?void 0:h.type)==="action"&&((_=h==null?void 0:h.payload)==null?void 0:_.state)==="pending")return[];if(((k=h==null?void 0:h.author)==null?void 0:k.type)!=="agent_ia")continue;const v=(y=h==null?void 0:h.metadata)==null?void 0:y.suggested_replies;return Array.isArray(v)&&v.length?v.map(w=>{if(typeof w=="string"){const E=w.trim();return E?{label:E,kind:null}:null}if(w&&typeof w=="object"&&typeof w.label=="string"){const E=w.label.trim();if(!E)return null;const M=w.kind==="cta"||w.kind==="choice"||w.kind==="followup"?w.kind:null;return{label:E,kind:M}}return null}).filter(Boolean).slice(0,4):[]}return[]}function z(c,d){var y;const m=t.messagesByConv[c]||[];let _=-1;d!=null&&d.client_msg_id&&(_=m.findIndex(u=>(u==null?void 0:u.client_msg_id)&&u.client_msg_id===d.client_msg_id)),_===-1&&(d==null?void 0:d.id)!==void 0&&(d==null?void 0:d.id)!==null&&(_=m.findIndex(u=>L(u==null?void 0:u.id,d.id)));let k;_===-1?k=[...m,d].sort(O):(k=m.slice(),k[_]={...m[_],...d,_pending:!1,_failed:!1}),t.messagesByConv[c]=k,(d==null?void 0:d.type)==="action"&&((y=d==null?void 0:d.payload)!=null&&y.state)&&d.payload.state!=="pending"&&(d==null?void 0:d.id)!=null&&t.awaitingCallback[d.id]&&delete t.awaitingCallback[d.id]}function L(c,d){return c===d?!0:c==null||d==null?!1:String(c)===String(d)}function q(c,d,m){const _=t.messagesByConv[c];if(!_)return;const k=_.findIndex(u=>u.id===d);if(k===-1)return;const y=_.slice();y[k]={..._[k],...m},t.messagesByConv[c]=y}function R(c,d){const m=t.conversations.findIndex(k=>k.id===c);if(m===-1)return;const _=t.conversations[m];if(d&&(!_.last_message_at||d>_.last_message_at)){const k=t.conversations.slice();k[m]={..._,last_message_at:d},k.sort((y,u)=>(u.last_message_at||"").localeCompare(y.last_message_at||"")),t.conversations=k}}function O(c,d){return(c.created_at||"").localeCompare(d.created_at||"")}function W(c){const d=t.messagesByConv[c]||[];let m="";for(const y of d)y!=null&&y.created_at&&y.created_at>m&&(m=y.created_at);const _=new Date().toISOString();return!m||_>m?_:new Date(Date.parse(m)+1).toISOString()}return{state:t,start:a,destroy:s,createConversation:o,openConversation:l,loadMore:p,patchConversation:f,send:C,clickCallback:V,signAttachment:x,submitFeedback:B,getPendingApproval:T,getActionInFlight:I,getLatestSuggestions:$,getLatestForm:S,setPanelOpen:n.setPanelOpen}}const A={w:"#ffffff",g50:"#F9F9F7",g100:"#F2F1EE",g150:"#E8E6E2",g200:"#D9D6CF",g300:"#B4B0A8",g400:"#888480",g500:"#5A5753",g700:"#2B2926",g900:"#17161A",accent:"#5B5FEF",accentLight:"#EEEFFE",green:"#22C55E",red:"#B91C1C",redBg:"#FDECEC"},j=["#5B5FEF","#7C3AED","#DB2777","#0891B2","#D97706","#059669"];function J(n=""){return n?j[n.charCodeAt(0)%j.length]:j[0]}function X(n=""){return n.split(" ").map(t=>t[0]||"").join("").toUpperCase().slice(0,2)}function Q(n=new Date){return n.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"})}const le=`
2
+ @import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');
3
+
4
+ .wm-root {
5
+ --wm-f: 'Geist', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
6
+ --wm-fm: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
7
+ --wm-w: ${A.w};
8
+ --wm-g50: ${A.g50};
9
+ --wm-g100: ${A.g100};
10
+ --wm-g150: ${A.g150};
11
+ --wm-g200: ${A.g200};
12
+ --wm-g300: ${A.g300};
13
+ --wm-g400: ${A.g400};
14
+ --wm-g500: ${A.g500};
15
+ --wm-g700: ${A.g700};
16
+ --wm-g900: ${A.g900};
17
+ --wm-a: ${A.accent};
18
+ --wm-al: ${A.accentLight};
19
+ --wm-green: ${A.green};
20
+ --wm-red: ${A.red};
21
+ --wm-redBg: ${A.redBg};
22
+ --wm-sh1: 0 1px 3px rgba(0,0,0,.06);
23
+ --wm-sh2: 0 4px 24px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.05);
24
+ --wm-shPanel: 0 12px 40px rgba(0,0,0,.13), 0 2px 8px rgba(0,0,0,.06);
25
+ }
26
+
27
+ @keyframes wm-heroGlow {
28
+ 0%, 100% { box-shadow: 0 8px 32px rgba(0,0,0,0.28), 0 0 0 0 rgba(0,0,0,0.10); }
29
+ 50% { box-shadow: 0 14px 52px rgba(0,0,0,0.42), 0 0 36px 14px rgba(0,0,0,0.15); }
30
+ }
31
+ @keyframes wm-typingDot {
32
+ 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
33
+ 30% { transform: translateY(-4px); opacity: 1; }
34
+ }
35
+ @keyframes wm-fadeUp {
36
+ from { opacity: 0; transform: translateY(6px); }
37
+ to { opacity: 1; transform: translateY(0); }
38
+ }
39
+ @keyframes wm-widgetPop {
40
+ 0% { transform: scale(0.85) translateY(10px); opacity: 0; }
41
+ 100% { transform: scale(1) translateY(0); opacity: 1; }
42
+ }
43
+ @keyframes wm-sheetSlide {
44
+ 0% { transform: translateX(110%); opacity: 0; }
45
+ 100% { transform: translateX(0); opacity: 1; }
46
+ }
47
+ `,N=(n,t)=>{const r=n.__vccOpts||n;for(const[a,s]of t)r[a]=s;return r},$e={name:"WmLauncher",props:{unreadCount:{type:Number,default:0},peek:{type:String,default:""}},emits:["open","dismiss"]},ze={class:"wm-launcherWrap"},Ue={class:"wm-peek__text"},je=["aria-label"];function Pe(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",ze,[e.createVNode(e.Transition,{name:"wm-peek"},{default:e.withCtx(()=>[r.peek?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-peek",role:"button",tabindex:"0","aria-label":"Ouvrir le messenger sur le dernier message",onClick:t[1]||(t[1]=i=>n.$emit("open")),onKeydown:[t[2]||(t[2]=e.withKeys(e.withModifiers(i=>n.$emit("open"),["prevent"]),["enter"])),t[3]||(t[3]=e.withKeys(e.withModifiers(i=>n.$emit("open"),["prevent"]),["space"]))]},[e.createElementVNode("p",Ue,e.toDisplayString(r.peek),1),e.createElementVNode("button",{type:"button",class:"wm-peek__close","aria-label":"Ignorer",onClick:t[0]||(t[0]=e.withModifiers(i=>n.$emit("dismiss"),["stop"]))},[...t[5]||(t[5]=[e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.4","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])],32)):e.createCommentVNode("",!0)]),_:1}),e.createElementVNode("button",{type:"button",class:"wm-launcher","aria-label":"Ouvrir le messenger",onClick:t[4]||(t[4]=i=>n.$emit("open"))},[t[6]||(t[6]=e.createElementVNode("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"},[e.createElementVNode("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)),r.unreadCount>0?(e.openBlock(),e.createElementBlock("span",{key:0,class:"wm-launcher__badge","aria-label":`${r.unreadCount} conversation${r.unreadCount>1?"s":""} non lue${r.unreadCount>1?"s":""}`},e.toDisplayString(r.unreadCount>9?"9+":r.unreadCount),9,je)):e.createCommentVNode("",!0)])])}const ce=N($e,[["render",Pe],["__scopeId","data-v-fabef371"]]),He={name:"WmAIAvatar",props:{size:{type:Number,default:26},pulse:{type:Boolean,default:!1}}},qe=["width","height"];function We(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:"wm-aiav",style:e.normalizeStyle({width:r.size+"px",height:r.size+"px"})},[r.pulse?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-aiav__pulse",style:e.normalizeStyle({borderRadius:r.size*.32+3+"px"})},null,4)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["wm-aiav__inner",{"wm-aiav__inner--glow":r.pulse}]),style:e.normalizeStyle({borderRadius:r.size*.32+"px"})},[(e.openBlock(),e.createElementBlock("svg",{width:r.size*.5,height:r.size*.5,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[...t[0]||(t[0]=[e.createElementVNode("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),e.createElementVNode("circle",{cx:"19",cy:"5",r:"1.5",fill:"white",opacity:"0.55"},null,-1),e.createElementVNode("circle",{cx:"5",cy:"18",r:"1",fill:"white",opacity:"0.38"},null,-1)])],8,qe))],6)],4)}const D=N(He,[["render",We],["__scopeId","data-v-fe042be7"]]),Ge={name:"WmHumanAvatar",props:{name:{type:String,default:""},avatarUrl:{type:String,default:null},size:{type:Number,default:26}},computed:{bg(){return this.avatarUrl?"transparent":J(this.name)},initials(){return X(this.name)}}},Ke=["src","alt"];function Ye(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:"wm-huav",style:e.normalizeStyle({width:r.size+"px",height:r.size+"px",borderRadius:Math.round(r.size*.32)+"px",background:o.bg})},[r.avatarUrl?(e.openBlock(),e.createElementBlock("img",{key:0,src:r.avatarUrl,alt:r.name||""},null,8,Ke)):(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle({fontSize:r.size*.36+"px"})},e.toDisplayString(o.initials),5))],4)}const Z=N(Ge,[["render",Ye],["__scopeId","data-v-79449443"]]),Je={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(n){return n.avatar_url?"transparent":J(n.name||"")},initialsFor(n){return X(n.name||"")}}},Xe={key:0,class:"wm-team"},Qe=["src","alt"],Ze={key:1},et={key:0,class:"wm-team__label"};function tt(n,t,r,a,s,o){return o.visible?(e.openBlock(),e.createElementBlock("div",Xe,[e.createElementVNode("div",{class:"wm-team__stack",style:e.normalizeStyle({width:o.stackWidth+"px"})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.members.slice(0,3),(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-team__pill",style:e.normalizeStyle({left:l*13+"px",zIndex:3-l,background:o.colorFor(i)})},[i.avatar_url?(e.openBlock(),e.createElementBlock("img",{key:0,src:i.avatar_url,alt:i.name||""},null,8,Qe)):(e.openBlock(),e.createElementBlock("span",Ze,e.toDisplayString(o.initialsFor(i)),1))],4))),128))],4),r.responseLabel?(e.openBlock(),e.createElementBlock("span",et,e.toDisplayString(r.responseLabel),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}const de=N(Je,[["render",tt],["__scopeId","data-v-3659b9c1"]]),nt={name:"WmHeader",components:{AIAvatar:D,HumanAvatar:Z,TeamAvatars:de},props:{title:{type:String,default:"Nouvelle conversation"},escalated:{type:Boolean,default:!1},agentName:{type:String,default:""},agentAvatarUrl:{type:String,default:null},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}},emits:["back","close","more"],computed:{hasTeam(){return Array.isArray(this.teamMembers)&&this.teamMembers.length>0},showPresence(){return this.hasTeam||this.escalated&&!!this.agentName},statusText(){return this.escalated&&this.agentName?this.agentName:"En ligne"}}},rt={class:"wm-header"},ot={key:1,style:{width:"30px",height:"30px","flex-shrink":"0"}},st={class:"wm-header__avatar"},at={class:"wm-header__main"},it={class:"wm-header__title"},lt={key:0,class:"wm-header__sub"},ct={class:"wm-header__status"},dt={key:3,class:"wm-header__fill"},ut={class:"wm-header__actions"};function mt(n,t,r,a,s,o){const i=e.resolveComponent("HumanAvatar"),l=e.resolveComponent("AIAvatar"),p=e.resolveComponent("TeamAvatars");return e.openBlock(),e.createElementBlock("div",rt,[r.showBack?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-header__icon","aria-label":"Retour à l'accueil",onClick:t[0]||(t[0]=g=>n.$emit("back"))},[...t[3]||(t[3]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M19 12H5M12 5l-7 7 7 7"})],-1)])])):(e.openBlock(),e.createElementBlock("div",ot)),r.showIdentity?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("div",st,[r.escalated?(e.openBlock(),e.createBlock(i,{key:0,name:r.agentName,"avatar-url":r.agentAvatarUrl,size:34},null,8,["name","avatar-url"])):(e.openBlock(),e.createBlock(l,{key:1,size:34}))]),e.createElementVNode("div",at,[e.createElementVNode("div",it,e.toDisplayString(r.title),1),o.showPresence?(e.openBlock(),e.createElementBlock("div",lt,[o.hasTeam?(e.openBlock(),e.createBlock(p,{key:0,members:r.teamMembers,"response-label":r.responseLabel},null,8,["members","response-label"])):e.createCommentVNode("",!0),e.createElementVNode("span",ct,[t[4]||(t[4]=e.createElementVNode("span",{class:"wm-header__dot"},null,-1)),e.createTextVNode(" "+e.toDisplayString(o.statusText),1)])])):e.createCommentVNode("",!0)])],64)):(e.openBlock(),e.createElementBlock("div",dt)),e.createElementVNode("div",ut,[r.showMore?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(["wm-header__icon",{"wm-header__icon--active":r.moreActive}]),"aria-label":"Plus d'options",title:"Plus d'options",onClick:t[1]||(t[1]=g=>n.$emit("more"))},[...t[5]||(t[5]=[e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},[e.createElementVNode("circle",{cx:"12",cy:"5",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"12",r:"1.6"}),e.createElementVNode("circle",{cx:"12",cy:"19",r:"1.6"})],-1)])],2)):e.createCommentVNode("",!0),r.showClose?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-header__icon","aria-label":"Fermer le widget",title:"Fermer le widget",onClick:t[2]||(t[2]=g=>n.$emit("close"))},[...t[6]||(t[6]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])):e.createCommentVNode("",!0)])])}const ue=N(nt,[["render",mt],["__scopeId","data-v-b5f5f6a9"]]),ne={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"},ht={name:"WmOnboarding",components:{AIAvatar:D},props:{welcomeMessage:{type:String,default:""},agentName:{type:String,default:""},quickLinks:{type:Array,default:()=>[]},unreadThreads:{type:Array,default:()=>[]},busy:{type:Boolean,default:!1}},emits:["start","select","resume"],computed:{heroTitle(){return this.welcomeMessage?this.welcomeMessage:this.agentName?`Bonjour, je suis ${this.agentName}`:"Bonjour, je suis votre assistant"},heroSub(){return`Posez-moi n'importe quelle question.
48
+ Je réponds en quelques secondes.`}},methods:{iconPath(n){return ne[n]||ne.link}}},pt={class:"wm-onb"},ft={class:"wm-onb__hero"},_t={class:"wm-onb__title"},vt={class:"wm-onb__sub"},gt={key:0,class:"wm-onb__section"},yt={class:"wm-onb__links"},kt=["onClick"],wt={class:"wm-onb__resume-body"},bt={class:"wm-onb__resume-title"},Et={class:"wm-onb__resume-preview"},Ct={key:1,class:"wm-onb__section"},Bt={class:"wm-onb__links"},Nt=["onClick"],Vt={class:"wm-onb__link-icon"},At={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"},St=["d"],Mt={class:"wm-onb__link-label"},xt={class:"wm-onb__cta"},Tt=["disabled"];function It(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",pt,[e.createElementVNode("div",ft,[e.createVNode(i,{size:56,pulse:!0}),e.createElementVNode("div",_t,e.toDisplayString(o.heroTitle),1),e.createElementVNode("div",vt,e.toDisplayString(o.heroSub),1)]),r.unreadThreads.length?(e.openBlock(),e.createElementBlock("div",gt,[t[3]||(t[3]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Messages non lus",-1)),e.createElementVNode("div",yt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.unreadThreads,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:"wm-onb__link wm-onb__resume",onClick:p=>n.$emit("resume",l)},[t[1]||(t[1]=e.createElementVNode("span",{class:"wm-onb__link-icon wm-onb__resume-icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})]),e.createElementVNode("span",{class:"wm-onb__resume-dot","aria-label":"Non lu"})],-1)),e.createElementVNode("span",wt,[e.createElementVNode("span",bt,e.toDisplayString(l.title),1),e.createElementVNode("span",Et,e.toDisplayString(l.preview),1)]),t[2]||(t[2]=e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-onb__link-chev","aria-hidden":"true"},[e.createElementVNode("path",{d:"M9 18l6-6-6-6"})],-1))],8,kt))),128))])])):e.createCommentVNode("",!0),r.quickLinks.length?(e.openBlock(),e.createElementBlock("div",Ct,[t[5]||(t[5]=e.createElementVNode("div",{class:"wm-onb__section-title"},"Accès rapide",-1)),e.createElementVNode("div",Bt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.quickLinks,(l,p)=>(e.openBlock(),e.createElementBlock("button",{key:p,type:"button",class:"wm-onb__link",onClick:g=>n.$emit("select",l)},[e.createElementVNode("span",Vt,[(e.openBlock(),e.createElementBlock("svg",At,[e.createElementVNode("path",{d:o.iconPath(l.icon)},null,8,St)]))]),e.createElementVNode("span",Mt,e.toDisplayString(l.label),1),t[4]||(t[4]=e.createElementVNode("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",class:"wm-onb__link-chev","aria-hidden":"true"},[e.createElementVNode("path",{d:"M9 18l6-6-6-6"})],-1))],8,Nt))),128))])])):e.createCommentVNode("",!0),e.createElementVNode("div",xt,[e.createElementVNode("button",{type:"button",class:"wm-onb__startBtn",disabled:r.busy,onClick:t[0]||(t[0]=l=>n.$emit("start"))},e.toDisplayString(r.busy?"…":"Commencer une conversation"),9,Tt)])])}const me=N(ht,[["render",It],["__scopeId","data-v-bd89bc8f"]]);function Ot(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Dt(n){return/^(https?:\/\/|mailto:|tel:)/i.test(String(n).trim())}const re="";function U(n){let t=n;const r=[];return t=t.replace(/`([^`\n]+)`/g,(a,s)=>{const o=r.length;return r.push(s),`${re}CODE${o}${re}`}),t=t.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g,(a,s,o)=>Dt(o)?`<a href="${o}" target="_blank" rel="noopener noreferrer">${s}</a>`:s),t=t.replace(/\*\*([^\n*][^\n]*?)\*\*/g,"<strong>$1</strong>"),t=t.replace(/__([^\n_][^\n]*?)__/g,"<u>$1</u>"),t=t.replace(/~~([^\n~][^\n]*?)~~/g,"<s>$1</s>"),t=t.replace(/(^|[^\w*])\*([^\n*]+?)\*(?!\w)/g,"$1<em>$2</em>"),t=t.replace(/(^|[^\w_])_([^\n_]+?)_(?!\w)/g,"$1<em>$2</em>"),t=t.replace(/CODE(\d+)/g,(a,s)=>`<code class="wm-md-code">${r[+s]}</code>`),t}function ee(n){if(!n)return"";const t=Ot(n).split(`
49
+ `),r=[];let a=0;for(;a<t.length;){const o=t[a];if(/^\s*```([\w-]*)\s*$/.exec(o)){a++;const g=[];for(;a<t.length&&!/^\s*```\s*$/.test(t[a]);)g.push(t[a]),a++;a<t.length&&a++,r.push({type:"block",html:`<pre class="wm-md-pre"><code>${g.join(`
50
+ `)}</code></pre>`});continue}if(/^\s*[-*]\s+/.test(o)){const g=[];for(;a<t.length;){const C=/^\s*[-*]\s+(.*)$/.exec(t[a]);if(!C)break;g.push(C[1]),a++}const f=g.map(C=>`<li>${U(C)}</li>`).join("");r.push({type:"block",html:`<ul class="wm-md-ul">${f}</ul>`});continue}const l=/^\s*(\d+)\.\s+(.*)$/.exec(o);if(l){const g=parseInt(l[1],10),f=[l[2]];for(a++;a<t.length;){const b=/^\s*\d+\.\s+(.*)$/.exec(t[a]);if(!b)break;f.push(b[1]),a++}const C=f.map(b=>`<li>${U(b)}</li>`).join(""),V=g!==1?` start="${g}"`:"";r.push({type:"block",html:`<ol class="wm-md-ol"${V}>${C}</ol>`});continue}const p=/^(#{1,6})\s+(.*)$/.exec(o);if(p){const g=p[1].length;r.push({type:"block",html:`<h${g} class="wm-md-h wm-md-h${g}">${U(p[2])}</h${g}>`}),a++;continue}r.push({type:"text",html:U(o)}),a++}let s="";for(let o=0;o<r.length;o++){const i=r[o];s+=i.html;const l=r[o+1];l&&i.type!=="block"&&l.type!=="block"&&(s+=`
51
+ `)}return s}const Lt={name:"WmArtifactFormResponse",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]}}},Rt={class:"wm-art wm-art--formResponse"},Ft={class:"wm-art__head"},$t={class:"wm-art__title"},zt={class:"wm-art__body"},Ut={class:"wm-art__fieldLabel"};function jt(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Rt,[e.createElementVNode("div",Ft,[e.createElementVNode("div",$t,e.toDisplayString(r.data.title||"Formulaire"),1),t[0]||(t[0]=e.createElementVNode("span",{class:"wm-art__badge wm-art__badge--success"},[e.createElementVNode("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"},[e.createElementVNode("polyline",{points:"20 6 9 17 4 12"})]),e.createTextVNode(" Envoyé ")],-1))]),e.createElementVNode("div",zt,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Ut,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128))])])}const he=N(Lt,[["render",jt],["__scopeId","data-v-812bda8b"]]),Pt={name:"WmArtifactInfoCard",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]},hasBody(){var n;return!!((n=this.data)!=null&&n.body)||this.fields.length>0}}},Ht={class:"wm-art wm-art--infoCard"},qt={key:0,class:"wm-art__image"},Wt=["src","alt"],Gt={class:"wm-art__head"},Kt={class:"wm-art__headMain"},Yt={class:"wm-art__title"},Jt={key:0,class:"wm-art__subtitle"},Xt={key:1,class:"wm-art__body"},Qt={key:0,class:"wm-art__text"},Zt={class:"wm-art__fieldLabel"};function en(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Ht,[r.data.image_url?(e.openBlock(),e.createElementBlock("figure",qt,[e.createElementVNode("img",{src:r.data.image_url,alt:r.data.title||"",loading:"lazy"},null,8,Wt)])):e.createCommentVNode("",!0),e.createElementVNode("div",Gt,[e.createElementVNode("div",Kt,[e.createElementVNode("div",Yt,e.toDisplayString(r.data.title),1),r.data.subtitle?(e.openBlock(),e.createElementBlock("div",Jt,e.toDisplayString(r.data.subtitle),1)):e.createCommentVNode("",!0)]),r.data.badge&&r.data.badge.label?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(["wm-art__badge",`wm-art__badge--${r.data.badge.tone||"neutral"}`])},e.toDisplayString(r.data.badge.label),3)):e.createCommentVNode("",!0)]),o.hasBody?(e.openBlock(),e.createElementBlock("div",Xt,[r.data.body?(e.openBlock(),e.createElementBlock("div",Qt,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0),o.fields.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",Zt,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},e.toDisplayString(i.value),3)]))),128)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])}const pe=N(Pt,[["render",en],["__scopeId","data-v-d7369333"]]);function tn(n){if(!n)return"";const t=new Date(n);if(Number.isNaN(t.getTime()))return n;const r=t.toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"}),a=t.toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"});return`${r} à ${a}`}const nn={name:"WmArtifactTicket",props:{data:{type:Object,required:!0}},computed:{fields(){var n;return Array.isArray((n=this.data)==null?void 0:n.fields)?this.data.fields:[]},hasBody(){var n;return!!((n=this.data)!=null&&n.body)||this.fields.length>0},formattedDate(){var n;return tn((n=this.data)==null?void 0:n.created_at)}},methods:{isPriority(n){return/priorit|^prio$/i.test(String(n||"").trim())},priorityLevel(n){const t=String(n||"").toLowerCase();return/high|haute|élev|elev|critic|critiq|urgent/.test(t)?3:/low|basse|faible|minor/.test(t)?1:2}}},rn={class:"wm-art wm-art--ticket"},on={class:"wm-art__head wm-tk__head"},sn={class:"wm-art__title wm-tk__title"},an={class:"wm-tk__sub"},ln={class:"wm-tk__ref"},cn={key:0,class:"wm-art__body"},dn={key:0,class:"wm-tk__text"},un={class:"wm-art__fieldLabel"},mn=["data-level"],hn={key:1,class:"wm-art__footer wm-tk__footer"};function pn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",rn,[e.createElementVNode("div",on,[e.createElementVNode("div",sn,e.toDisplayString(r.data.title),1),e.createElementVNode("div",an,[e.createElementVNode("div",ln,[t[0]||(t[0]=e.createElementVNode("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"},[e.createElementVNode("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"}),e.createElementVNode("path",{d:"M13 5v2M13 17v2M13 11v2"})],-1)),e.createElementVNode("span",null,e.toDisplayString(r.data.reference),1)]),e.createElementVNode("span",{class:e.normalizeClass(["wm-art__badge","wm-tk__badge",`wm-art__badge--${r.data.status.tone||"neutral"}`])},[t[1]||(t[1]=e.createElementVNode("span",{class:"wm-tk__dot","aria-hidden":"true"},null,-1)),e.createTextVNode(" "+e.toDisplayString(r.data.status.label),1)],2)])]),o.hasBody?(e.openBlock(),e.createElementBlock("div",cn,[r.data.body?(e.openBlock(),e.createElementBlock("div",dn,e.toDisplayString(r.data.body),1)):e.createCommentVNode("",!0),o.fields.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(o.fields,(i,l)=>(e.openBlock(),e.createElementBlock("div",{key:l,class:"wm-art__field"},[e.createElementVNode("div",un,e.toDisplayString(i.label),1),e.createElementVNode("div",{class:e.normalizeClass(["wm-art__fieldValue",{"wm-art__fieldValue--multi":i.multiline}])},[o.isPriority(i.label)?(e.openBlock(),e.createElementBlock("svg",{key:0,class:"wm-tk__prio","data-level":o.priorityLevel(i.value),width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true"},[...t[2]||(t[2]=[e.createElementVNode("rect",{x:"1",y:"8",width:"2",height:"3",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"5",y:"5",width:"2",height:"6",rx:"0.5"},null,-1),e.createElementVNode("rect",{x:"9",y:"2",width:"2",height:"9",rx:"0.5"},null,-1)])],8,mn)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(i.value),1)],2)]))),128)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),r.data.created_at?(e.openBlock(),e.createElementBlock("div",hn,[t[3]||(t[3]=e.createElementVNode("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"},[e.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}),e.createElementVNode("path",{d:"M16 2v4M8 2v4M3 10h18"})],-1)),e.createElementVNode("span",null,e.toDisplayString(o.formattedDate),1)])):e.createCommentVNode("",!0)])}const fe=N(nn,[["render",pn],["__scopeId","data-v-f0495924"]]),fn={form_response:he,info_card:pe,ticket:fe},_n={name:"WmArtifactRenderer",props:{artifact:{type:Object,required:!0}},computed:{component(){var t;const n=(t=this.artifact)==null?void 0:t.kind;return n&&fn[n]||null}}};function vn(n,t,r,a,s,o){return o.component?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.component),{key:0,data:r.artifact.data},null,8,["data"])):e.createCommentVNode("",!0)}const te=N(_n,[["render",vn]]),gn={name:"WmActionResult",components:{ArtifactRenderer:te},props:{state:{type:String,default:"success"},label:{type:String,required:!0},detail:{type:String,default:""},artifact:{type:Object,default:null}},computed:{ok(){return this.state==="success"},detailHtml(){return ee(this.detail)}}},yn={class:"wm-result-wrap"},kn={class:"wm-result"},wn={key:0,width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"#fff","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},bn={key:1,width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},En={class:"wm-result__body"},Cn=["innerHTML"],Bn={key:0,class:"wm-result-art"};function Nn(n,t,r,a,s,o){const i=e.resolveComponent("ArtifactRenderer");return e.openBlock(),e.createElementBlock("div",yn,[e.createElementVNode("div",kn,[e.createElementVNode("div",{class:e.normalizeClass(["wm-result__check",{"wm-result__check--ok":o.ok}])},[o.ok?(e.openBlock(),e.createElementBlock("svg",wn,[...t[0]||(t[0]=[e.createElementVNode("path",{d:"M20 6L9 17l-5-5"},null,-1)])])):(e.openBlock(),e.createElementBlock("svg",bn,[...t[1]||(t[1]=[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"},null,-1)])]))],2),e.createElementVNode("div",En,[e.createElementVNode("div",{class:e.normalizeClass(["wm-result__label",{"wm-result__label--struck":!o.ok}])},e.toDisplayString(r.label),3),r.detail?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-result__detail",innerHTML:o.detailHtml},null,8,Cn)):e.createCommentVNode("",!0)])]),r.artifact?(e.openBlock(),e.createElementBlock("div",Bn,[e.createVNode(i,{artifact:r.artifact},null,8,["artifact"])])):e.createCommentVNode("",!0)])}const _e=N(gn,[["render",Nn],["__scopeId","data-v-037fd69e"]]),Vn={name:"WmAttachmentPreview",inject:{signAttachmentFn:{default:null}},props:{attachment:{type:Object,required:!0}},data(){return{url:null,loading:!1}},computed:{kind(){var r,a;const n=(r=this.attachment)==null?void 0:r.type;if(n)return n;const t=(((a=this.attachment)==null?void 0:a.mime_type)||"").toLowerCase();return t.startsWith("image/")?"image":t.startsWith("audio/")?"audio":t.startsWith("video/")?"video":"file"},displayName(){var n,t,r;return((t=(n=this.attachment)==null?void 0:n.metadata)==null?void 0:t.name)||((r=this.attachment)==null?void 0:r.name)||this.guessNameFromPath()||"Pièce jointe"},sizeLabel(){var t;const n=(t=this.attachment)==null?void 0:t.size_bytes;return n?n<1024?`${n} o`:n<1024*1024?`${(n/1024).toFixed(0)} ko`:`${(n/(1024*1024)).toFixed(1)} Mo`:""}},watch:{"attachment.path":{handler(){this.refresh()},immediate:!0}},methods:{guessNameFromPath(){var r;return((((r=this.attachment)==null?void 0:r.path)||"").split("/").pop()||"").replace(/^[0-9a-f-]{8,}-/,"")},async refresh(){var n;if(!(!((n=this.attachment)!=null&&n.path)||!this.signAttachmentFn)){this.loading=!0;try{this.url=await this.signAttachmentFn(this.attachment.path)}finally{this.loading=!1}}},onFileClick(n){this.url||n.preventDefault()}}},An=["href"],Sn=["src","alt"],Mn=["src"],xn=["src"],Tn=["href","download"],In={class:"wm-att__main"},On={class:"wm-att__name"},Dn={key:0,class:"wm-att__meta"},Ln={key:0,class:"wm-att__spin","aria-hidden":"true"};function Rn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-att",["wm-att--"+(o.kind||"file")]])},[o.kind==="image"&&s.url?(e.openBlock(),e.createElementBlock("a",{key:0,href:s.url,target:"_blank",rel:"noopener",class:"wm-att__imgWrap"},[e.createElementVNode("img",{src:s.url,alt:o.displayName,loading:"lazy"},null,8,Sn)],8,An)):o.kind==="audio"&&s.url?(e.openBlock(),e.createElementBlock("audio",{key:1,src:s.url,controls:"",preload:"metadata"},null,8,Mn)):o.kind==="video"&&s.url?(e.openBlock(),e.createElementBlock("video",{key:2,src:s.url,controls:"",preload:"metadata"},null,8,xn)):(e.openBlock(),e.createElementBlock("a",{key:3,class:"wm-att__file",href:s.url||"#",download:o.displayName,target:"_blank",rel:"noopener",onClick:t[0]||(t[0]=(...i)=>o.onFileClick&&o.onFileClick(...i))},[t[1]||(t[1]=e.createElementVNode("span",{class:"wm-att__icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.createElementVNode("path",{d:"M14 2v6h6"})])],-1)),e.createElementVNode("span",In,[e.createElementVNode("span",On,e.toDisplayString(o.displayName),1),o.sizeLabel?(e.openBlock(),e.createElementBlock("span",Dn,e.toDisplayString(o.sizeLabel),1)):e.createCommentVNode("",!0)]),s.loading?(e.openBlock(),e.createElementBlock("span",Ln)):e.createCommentVNode("",!0)],8,Tn))],2)}const ve=N(Vn,[["render",Rn],["__scopeId","data-v-1cd1267b"]]),Fn={name:"WmBubble",props:{role:{type:String,default:"ai"},text:{type:String,default:""}},computed:{rendered(){return ee(this.text)}}},$n=["innerHTML"];function zn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-bubble","wm-bubble--"+r.role])},[e.renderSlot(n.$slots,"default",{},()=>[e.createElementVNode("span",{innerHTML:o.rendered},null,8,$n)],!0)],2)}const ge=N(Fn,[["render",zn],["__scopeId","data-v-bcbe5969"]]),Un={name:"WmTyping"},jn={class:"wm-typing"};function Pn(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",jn,[...t[0]||(t[0]=[e.createElementVNode("span",{style:{"animation-delay":"0s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.2s"}},null,-1),e.createElementVNode("span",{style:{"animation-delay":"0.4s"}},null,-1)])])}const ye=N(Un,[["render",Pn],["__scopeId","data-v-df2447fd"]]);function G(n){return n?n.client_msg_id||n.id:""}const Hn={transferred_to_human:"Conversation transférée à un humain",assigned:"{name} a rejoint la conversation",unassigned:"L'agent a quitté la conversation",resolved:"Conversation résolue",reopened:"Conversation rouverte",idle:"Conversation en pause"},qn=80,Wn=200,Gn={name:"WmMessageList",components:{AIAvatar:D,HumanAvatar:Z,Bubble:ge,Typing:ye,ActionResult:_e,AttachmentPreview:ve,ArtifactRenderer:te},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}},emits:["load-more"],data(){return{silentFades:!1}},computed:{historyExhausted(){return!this.hasMore&&!this.loadingMore&&this.messages.length>=20},groups(){var t,r,a;const n=[];for(const s of this.messages){const o=this.roleOf(s);if(o==="system"){n.push({key:`sys-${G(s)}`,role:o,messages:[s],systemLabel:this.systemLabel(s)});continue}const i=n[n.length-1];i&&i.role===o&&(o==="ai"||i.agentName===(((t=s==null?void 0:s.author)==null?void 0:t.name)||""))?i.messages.push(s):n.push({key:`g-${G(s)}`,role:o,agentName:((r=s==null?void 0:s.author)==null?void 0:r.name)||"",agentAvatarUrl:((a=s==null?void 0:s.author)==null?void 0:a.avatar_url)||null,messages:[s]})}return n}},watch:{messages:{handler:"snapshotAndRestore",deep:!0},loadingMore(n){n||(this._pendingLoadMore=!1),this.silentFades=!0,clearTimeout(this._silenceTimer),n||(this._silenceTimer=setTimeout(()=>{this.silentFades=!1},250)),this.snapshotAndRestore()},streamingActive:"snapshotAndRestore"},mounted(){this._lastSeenConvId=this.conversationId,this.scrollToBottom()},methods:{messageKey:G,isAtBottom(n){return n.scrollHeight-n.scrollTop-n.clientHeight<=qn},onScroll(){const n=this.$refs.scrollEl;n&&(this.loadingMore||!this.hasMore||this._pendingLoadMore||n.scrollTop<=Wn&&(this._pendingLoadMore=!0,this.$emit("load-more")))},snapshotAndRestore(){const n=this.$refs.scrollEl;if(!n||this._scrollSnap)return;const t=this._lastSeenConvId!==this.conversationId;this._lastSeenConvId=this.conversationId;const r=this.isAtBottom(n);let a=null;if(!t&&!r){const o=this.pickAnchor(n);if(o!=null&&o.el){const i=n.getBoundingClientRect().top;a={el:o.el,relY:o.el.getBoundingClientRect().top-i}}}const s={forceBottom:t,wasPinned:r,anchor:a};this._scrollSnap=s,this.$nextTick(()=>{if(this._scrollSnap=null,s.forceBottom||s.wasPinned){n.scrollTop=n.scrollHeight;return}if(!s.anchor)return;const o=()=>{var g;const i=s.anchor;if(!((g=i.el)!=null&&g.isConnected))return;const p=i.el.getBoundingClientRect().top-n.getBoundingClientRect().top-i.relY;Math.abs(p)>.5&&(n.scrollTop+=p)};o(),requestAnimationFrame(()=>{o(),requestAnimationFrame(o)})})},pickAnchor(n){const t=n.scrollTop;let r=null;for(const a of n.children)if(a.classList.contains("wm-list__group")&&(r||(r=a),a.offsetTop+a.offsetHeight>=t))return{el:a,offsetTop:a.offsetTop};return r?{el:r,offsetTop:r.offsetTop}:null},roleOf(n){var r,a;if((n==null?void 0:n.type)==="system"||((r=n==null?void 0:n.payload)==null?void 0:r.type)==="system")return"system";const t=(a=n==null?void 0:n.author)==null?void 0:a.type;return t==="user"?"user":t==="agent_human"?"human":"ai"},roleLabel(n){return n.role==="human"?n.agentName||"Agent":"Assistant IA"},itemKindOf(n){return n?n.type==="action"&&n.payload&&n.payload.state!=="pending"||this.artifactOf(n)?"card":n.text_md?"bubble":null:null},cornersFor(n,t){const r=n.messages,a=this.itemKindOf(r[t]),s=this.itemKindOf(r[t-1]),o=this.itemKindOf(r[t+1]),i=n.role==="user",l=14,p=4,g=(x,B)=>x==="card"&&B==="bubble";let f=l,C=l,V=l,b=l;return i?(s&&(C=p,g(s,a)&&(f=p)),o&&(V=p,g(o,a)&&(b=p)),!s&&!o&&a==="bubble"&&(V=p)):(s&&(f=p,g(s,a)&&(C=p)),o&&(b=p,g(o,a)&&(V=p)),!s&&!o&&a==="bubble"&&(f=p)),{tl:f,tr:C,br:V,bl:b}},cornersStyle(n,t){if(n.messages.reduce((s,o)=>s+(this.itemKindOf(o)?1:0),0)<2)return null;const a=this.cornersFor(n,t);return{"--wm-r-tl":`${a.tl}px`,"--wm-r-tr":`${a.tr}px`,"--wm-r-br":`${a.br}px`,"--wm-r-bl":`${a.bl}px`}},lastTimeOf(n){const t=n.messages[n.messages.length-1];if(!(t!=null&&t.created_at))return"";try{return Q(new Date(t.created_at))}catch{return""}},attachmentsOf(n){var r;const t=(r=n==null?void 0:n.payload)==null?void 0:r.attachments;return Array.isArray(t)?t:[]},artifactOf(n){var r;const t=(r=n==null?void 0:n.metadata)==null?void 0:r.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},actionLabel(n){var t;return((t=n==null?void 0:n.payload)==null?void 0:t.name)||(n==null?void 0:n.text_md)||"Action"},actionDetail(n){var r,a,s,o,i,l;const t=n==null?void 0:n.payload;return t?t.state==="success"?((r=t.success)==null?void 0:r.summary)||((s=(a=t.success)==null?void 0:a.metadata)==null?void 0:s.description)||"":t.state==="rejected"?((o=t.rejected)==null?void 0:o.reason)||"Action annulée par l'utilisateur.":t.state==="failure"&&(((i=t.failure)==null?void 0:i.summary)||((l=t.failure)==null?void 0:l.error))||"":""},actionArtifact(n){var r,a;const t=(a=(r=n==null?void 0:n.payload)==null?void 0:r.success)==null?void 0:a.artifact;return!t||typeof t!="object"||typeof t.kind!="string"?null:t},systemLabel(n){var s,o,i;const t=(s=n==null?void 0:n.payload)==null?void 0:s.event,r=Hn[t]||(n==null?void 0:n.text_md)||"Mise à jour de la conversation",a=((o=n==null?void 0:n.metadata)==null?void 0:o.agent_name)||((i=n==null?void 0:n.author)==null?void 0:i.name)||"";return r.replace("{name}",a||"Un agent")},scrollToBottom(){const n=this.$refs.scrollEl;n&&(n.scrollTop=n.scrollHeight)}}},Kn={key:0,class:"wm-list__loadMore",role:"status","aria-live":"polite"},Yn={key:1,class:"wm-list__historyEnd"},Jn={key:2,class:"wm-list__sep"},Xn={class:"wm-list__sep-label"},Qn={key:0,class:"wm-list__sysep"},Zn={class:"wm-list__sysep-label"},er={key:0,class:"wm-list__role"},tr={key:0,class:"wm-list__avatarSlot"},nr={key:3,class:"wm-list__body"},rr={key:3,class:"wm-list__row wm-list__row--ai fade-up"},or={class:"wm-list__avatarSlot"};function sr(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar"),l=e.resolveComponent("HumanAvatar"),p=e.resolveComponent("ActionResult"),g=e.resolveComponent("ArtifactRenderer"),f=e.resolveComponent("Bubble"),C=e.resolveComponent("AttachmentPreview"),V=e.resolveComponent("Typing");return e.openBlock(),e.createElementBlock("div",{ref:"scrollEl",class:e.normalizeClass(["wm-list",{"wm-list--silent":s.silentFades}]),onScrollPassive:t[0]||(t[0]=(...b)=>o.onScroll&&o.onScroll(...b))},[r.loadingMore?(e.openBlock(),e.createElementBlock("div",Kn,[...t[1]||(t[1]=[e.createElementVNode("span",{class:"wm-list__loadMore-spinner","aria-hidden":"true"},null,-1),e.createElementVNode("span",{class:"wm-list__loadMore-lbl"},"Chargement de l'historique…",-1)])])):o.historyExhausted?(e.openBlock(),e.createElementBlock("div",Yn,"Début de la conversation")):e.createCommentVNode("",!0),r.dateLabel?(e.openBlock(),e.createElementBlock("div",Jn,[t[2]||(t[2]=e.createElementVNode("div",{class:"wm-list__line"},null,-1)),e.createElementVNode("span",Xn,e.toDisplayString(r.dateLabel),1),t[3]||(t[3]=e.createElementVNode("div",{class:"wm-list__line"},null,-1))])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.groups,(b,x)=>(e.openBlock(),e.createElementBlock("div",{key:b.key,class:e.normalizeClass(["wm-list__group","wm-list__group--"+b.role])},[b.role==="system"?(e.openBlock(),e.createElementBlock("div",Qn,[t[4]||(t[4]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1)),e.createElementVNode("span",Zn,e.toDisplayString(b.systemLabel),1),t[5]||(t[5]=e.createElementVNode("div",{class:"wm-list__line wm-list__line--strong"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[b.role!=="user"?(e.openBlock(),e.createElementBlock("div",er,e.toDisplayString(o.roleLabel(b)),1)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.messages,(B,T)=>(e.openBlock(),e.createElementBlock("div",{key:o.messageKey(B),class:e.normalizeClass(["wm-list__row fade-up",["wm-list__row--"+b.role,{"is-pending":B._pending,"is-failed":B._failed}]]),style:e.normalizeStyle(o.cornersStyle(b,T))},[b.role!=="user"?(e.openBlock(),e.createElementBlock("div",tr,[T===b.messages.length-1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[b.role==="ai"?(e.openBlock(),e.createBlock(i,{key:0,size:26})):(e.openBlock(),e.createBlock(l,{key:1,name:b.agentName,"avatar-url":b.agentAvatarUrl,size:26},null,8,["name","avatar-url"]))],64)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),B.type==="action"&&B.payload&&B.payload.state!=="pending"?(e.openBlock(),e.createBlock(p,{key:1,state:B.payload.state,label:o.actionLabel(B),detail:o.actionDetail(B),artifact:o.actionArtifact(B)},null,8,["state","label","detail","artifact"])):o.artifactOf(B)?(e.openBlock(),e.createBlock(g,{key:2,artifact:o.artifactOf(B)},null,8,["artifact"])):(e.openBlock(),e.createElementBlock("div",nr,[B.text_md?(e.openBlock(),e.createBlock(f,{key:0,role:b.role,text:B.text_md},null,8,["role","text"])):e.createCommentVNode("",!0),o.attachmentsOf(B).length?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__atts",{"wm-list__atts--align-end":b.role==="user"}])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachmentsOf(B),(S,I)=>(e.openBlock(),e.createBlock(C,{key:`${o.messageKey(B)}-att-${I}`,attachment:S},null,8,["attachment"]))),128))],2)):e.createCommentVNode("",!0)]))],6))),128)),o.lastTimeOf(b)?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["wm-list__time",{"wm-list__time--right":b.role==="user"}])},e.toDisplayString(o.lastTimeOf(b)),3)):e.createCommentVNode("",!0)],64))],2))),128)),r.streamingActive?(e.openBlock(),e.createElementBlock("div",rr,[e.createElementVNode("div",or,[e.createVNode(i,{size:26})]),e.createVNode(V)])):e.createCommentVNode("",!0)],34)}const ke=N(Gn,[["render",sr],["__scopeId","data-v-f23f2f8c"]]),F=typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function",H=typeof window<"u"&&typeof window.MediaRecorder<"u";function we(){return H&&["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(t=>{var r,a;return(a=(r=window.MediaRecorder).isTypeSupported)==null?void 0:a.call(r,t)})||""}function be({audio:n}){return{video:!0,audio:!!n,selfBrowserSurface:"include",surfaceSwitching:"include",systemAudio:n?"include":"exclude"}}function ar(n){return n?n.startsWith("image/")?"image":n.startsWith("video/")?"video":"file":"file"}async function Ee(){if(!F)return null;let n;try{n=await navigator.mediaDevices.getDisplayMedia(be({audio:!1}))}catch(t){return(t==null?void 0:t.name)!=="NotAllowedError"&&console.error("[media] screenshot picker",t),null}try{return await ir(n)}catch(t){return console.error("[media] screenshot capture",t),null}finally{n.getTracks().forEach(t=>{t.stop()})}}async function ir(n){const t=document.createElement("video");t.muted=!0,t.playsInline=!0,t.srcObject=n,await t.play(),await new Promise(l=>requestAnimationFrame(l));const r=t.videoWidth||1280,a=t.videoHeight||720,s=document.createElement("canvas");s.width=r,s.height=a,s.getContext("2d").drawImage(t,0,0,r,a);const o=await new Promise((l,p)=>{s.toBlob(g=>g?l(g):p(new Error("toBlob failed")),"image/png")}),i=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([o],`capture-${i}.png`,{type:"image/png"})}async function Ce(n={}){var g;if(!F||!H)return null;let t;try{t=await navigator.mediaDevices.getDisplayMedia(be({audio:!0}))}catch(f){return(f==null?void 0:f.name)!=="NotAllowedError"&&console.error("[media] record picker",f),null}const r=we();let a;try{a=r?new window.MediaRecorder(t,{mimeType:r}):new window.MediaRecorder(t)}catch(f){return console.error("[media] recorder init",f),t.getTracks().forEach(C=>{C.stop()}),null}const s=[];let o=null,i=!1;a.addEventListener("dataavailable",f=>{f.data&&f.data.size>0&&s.push(f.data)}),a.addEventListener("stop",()=>{var f,C;if(o&&clearInterval(o),t.getTracks().forEach(V=>{V.stop()}),s.length){const V=a.mimeType||r||"video/webm",b=new Blob(s,{type:V}),x=/mp4/.test(V)?"mp4":"webm",B=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),T=new File([b],`ecran-${B}.${x}`,{type:V});(f=n.onfinalize)==null||f.call(n,T)}else(C=n.oncancel)==null||C.call(n)}),t.getVideoTracks().forEach(f=>{f.addEventListener("ended",()=>l(),{once:!0})});function l(){if(!i&&(i=!0,a.state!=="inactive"))try{a.stop()}catch(f){console.error("[media] recorder stop",f)}}try{a.start(1e3)}catch(f){return console.error("[media] recorder start",f),t.getTracks().forEach(C=>{C.stop()}),null}(g=n.onstart)==null||g.call(n);const p=Date.now();return o=setInterval(()=>{var f;(f=n.ontick)==null||f.call(n,Date.now()-p)},500),{stop:l,get state(){return a.state}}}const lr=[{action:"file",label:"Joindre un fichier",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",label:"Capture d'écran",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",label:"Enregistrer l'écran",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"}],cr={name:"WmComposer",props:{modelValue:{type:String,default:""},placeholder:{type:String,default:"Écrivez votre message…"},disabled:{type:Boolean,default:!1},attachLabel:{type:String,default:"Joindre"}},emits:["update:modelValue","send","attach"],data(){return{local:this.modelValue,attachOpen:!1,recording:!1,recordingElapsed:0,recorder:null}},computed:{canSend(){return!this.disabled&&!!this.local.trim()},attachItems(){return lr.map(n=>({...n,disabled:n.action==="screenshot"&&!F||n.action==="record"&&(!F||!H)}))},recordingElapsedLabel(){const n=Math.floor(this.recordingElapsed/1e3),t=Math.floor(n/60),r=n%60;return`${t}:${r.toString().padStart(2,"0")}`}},watch:{modelValue(n){n!==this.local&&(this.local=n,this.$nextTick(()=>this.autosize()))},local(n){this.$emit("update:modelValue",n)}},mounted(){this.autosize()},beforeUnmount(){if(this.recorder)try{this.recorder.stop()}catch{}},methods:{focus(){const n=this.$refs.inputEl;if(!(!n||this.disabled))try{n.focus({preventScroll:!0})}catch{n.focus()}},onSubmit(){if(!this.canSend)return;const n=this.local.trim();this.local="",this.$emit("send",n),this.$nextTick(()=>this.autosize())},onKeydown(n){n.key==="Enter"&&!n.shiftKey&&!n.ctrlKey&&!n.metaKey&&!n.isComposing&&(n.preventDefault(),this.onSubmit())},autosize(){const n=this.$refs.inputEl;n&&(n.style.height="auto",n.style.height=`${n.scrollHeight}px`)},onFile(n){const t=Array.from(n.target.files||[]);for(const r of t)this.$emit("attach",r);n.target.value=""},onAttachAction(n){this.attachOpen=!1,n==="file"?this.pickFile():n==="screenshot"?this.captureScreenshot():n==="record"&&this.startRecording()},pickFile(){var n;(n=this.$refs.fileEl)==null||n.click()},async captureScreenshot(){if(this.disabled)return;const n=await Ee();n&&this.$emit("attach",n)},async startRecording(){if(this.recording||this.disabled)return;this.recordingElapsed=0;const n=await Ce({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}});n&&(this.recorder=n)},stopRecording(){if(this.recorder)try{this.recorder.stop()}catch(n){console.error("[composer] stop recording",n)}}}},dr={class:"wm-compose-wrap"},ur={key:0,class:"wm-rec"},mr={class:"wm-rec__lbl"},hr={key:1,class:"wm-compose__menu",role:"menu"},pr=["disabled","onClick"],fr={class:"wm-compose__menuIcon"},_r={viewBox:"0 0 24 24",width:"14",height:"14","aria-hidden":"true"},vr=["d"],gr=["placeholder","disabled"],yr={class:"wm-compose__actions"},kr=["title","aria-label","disabled"],wr=["disabled"];function br(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",dr,[s.recording?(e.openBlock(),e.createElementBlock("div",ur,[t[8]||(t[8]=e.createElementVNode("span",{class:"wm-rec__dot","aria-hidden":"true"},null,-1)),e.createElementVNode("span",mr,"Enregistrement · "+e.toDisplayString(o.recordingElapsedLabel),1),e.createElementVNode("button",{type:"button",class:"wm-rec__stop",onClick:t[0]||(t[0]=(...i)=>o.stopRecording&&o.stopRecording(...i))},"Arrêter")])):e.createCommentVNode("",!0),e.createElementVNode("form",{class:e.normalizeClass(["wm-compose",{"has-attach":s.attachOpen}]),onSubmit:t[7]||(t[7]=e.withModifiers((...i)=>o.onSubmit&&o.onSubmit(...i),["prevent"]))},[e.createElementVNode("input",{ref:"fileEl",type:"file",hidden:"",multiple:"",onChange:t[1]||(t[1]=(...i)=>o.onFile&&o.onFile(...i))},null,544),s.attachOpen?(e.openBlock(),e.createElementBlock("div",{key:0,class:"wm-compose__overlay",onClick:t[2]||(t[2]=i=>s.attachOpen=!1)})):e.createCommentVNode("",!0),s.attachOpen?(e.openBlock(),e.createElementBlock("div",hr,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.attachItems,i=>(e.openBlock(),e.createElementBlock("button",{key:i.action,type:"button",class:"wm-compose__menuItem",disabled:i.disabled,onClick:l=>o.onAttachAction(i.action)},[e.createElementVNode("span",fr,[(e.openBlock(),e.createElementBlock("svg",_r,[e.createElementVNode("path",{d:i.path,stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round",fill:"none"},null,8,vr)]))]),e.createElementVNode("span",null,e.toDisplayString(i.label),1)],8,pr))),128))])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("textarea",{ref:"inputEl","onUpdate:modelValue":t[3]||(t[3]=i=>s.local=i),class:"wm-compose__input",rows:"3",placeholder:r.placeholder,disabled:r.disabled,onKeydown:t[4]||(t[4]=(...i)=>o.onKeydown&&o.onKeydown(...i)),onInput:t[5]||(t[5]=(...i)=>o.autosize&&o.autosize(...i))},null,40,gr),[[e.vModelText,s.local]]),e.createElementVNode("div",yr,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["wm-compose__icon",{"is-open":s.attachOpen}]),title:r.attachLabel,"aria-label":r.attachLabel,disabled:s.recording,onClick:t[6]||(t[6]=i=>s.attachOpen=!s.attachOpen)},[...t[9]||(t[9]=[e.createElementVNode("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"},[e.createElementVNode("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,kr),e.createElementVNode("button",{type:"submit",class:e.normalizeClass(["wm-compose__send",{"is-empty":!o.canSend}]),disabled:!o.canSend,"aria-label":"Envoyer"},[...t[10]||(t[10]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],10,wr)])],34)])}const Be=N(cr,[["render",br],["__scopeId","data-v-14fa9ec0"]]),Er={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(n=>(n==null?void 0:n.label)||(n==null?void 0:n.text)||"").join("§")}}},Cr=["onClick"];function Br(n,t,r,a,s,o){return r.items.length?(e.openBlock(),e.createElementBlock("div",{key:o.batchKey,class:"wm-chips"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,(i,l)=>(e.openBlock(),e.createElementBlock("button",{key:l,type:"button",class:"wm-chip",style:e.normalizeStyle({animationDelay:r.baseDelay+l*r.stepDelay+"ms"}),onClick:p=>n.$emit("select",i)},e.toDisplayString(i.label),13,Cr))),128))])):e.createCommentVNode("",!0)}const Ne=N(Er,[["render",Br],["__scopeId","data-v-55aa529d"]]),Nr={name:"WmApprovalCard",components:{AIAvatar:D},props:{action:{type:String,required:!0},detail:{type:String,default:""},callbacks:{type:Array,default:()=>[]}},emits:["callback"],computed:{approveCallback(){return this.callbacks.find(n=>n.id==="approve"||n.style==="primary")||this.callbacks[0]},rejectCallback(){return this.callbacks.find(n=>n.id==="reject"||n.style==="danger"||n.style==="neutral")||(this.callbacks.length>1?this.callbacks[1]:null)},approveId(){var n;return(n=this.approveCallback)==null?void 0:n.id},rejectId(){var n;return(n=this.rejectCallback)==null?void 0:n.id},approveLabel(){var n;return((n=this.approveCallback)==null?void 0:n.label)||"Autoriser"},rejectLabel(){var n;return((n=this.rejectCallback)==null?void 0:n.label)||"Refuser"}}},Vr={class:"wm-approval"},Ar={class:"wm-approval__head"},Sr={class:"wm-approval__icon"},Mr={class:"wm-approval__main"},xr={class:"wm-approval__title"},Tr={key:0,class:"wm-approval__detail"},Ir={class:"wm-approval__actions"};function Or(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Vr,[e.createElementVNode("div",Ar,[e.createElementVNode("div",Sr,[e.createVNode(i,{size:24})]),e.createElementVNode("div",Mr,[e.createElementVNode("div",xr,e.toDisplayString(r.action),1),r.detail?(e.openBlock(),e.createElementBlock("div",Tr,e.toDisplayString(r.detail),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("div",Ir,[o.rejectId?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-approval__btn wm-approval__btn--neutral",onClick:t[0]||(t[0]=l=>n.$emit("callback",o.rejectId))},e.toDisplayString(o.rejectLabel),1)):e.createCommentVNode("",!0),o.approveId?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-approval__btn wm-approval__btn--primary",onClick:t[1]||(t[1]=l=>n.$emit("callback",o.approveId))},e.toDisplayString(o.approveLabel),1)):e.createCommentVNode("",!0)])])}const Ve=N(Nr,[["render",Or],["__scopeId","data-v-b1be139c"]]);let oe=0;const Dr=new Set(["text","textarea","number","boolean","select","multiselect","date"]),Lr={name:"WmFormCard",components:{AIAvatar:D},props:{form:{type:Object,required:!0},readOnly:{type:Boolean,default:!1},initialValues:{type:Object,default:null}},emits:["submit"],data(){return oe+=1,{_uid:oe,values:{},busy:!1,error:""}},computed:{normalizedFields(){var t;return(Array.isArray((t=this.form)==null?void 0:t.fields)?this.form.fields:[]).filter(r=>!(!(r!=null&&r.key)||!(r!=null&&r.label)||!Dr.has(r==null?void 0:r.type)||(r.type==="select"||r.type==="multiselect")&&(!Array.isArray(r.options)||r.options.length===0)))}},created(){this.resetValues()},methods:{resetValues(){const n=this.initialValues&&typeof this.initialValues=="object"?this.initialValues:{},t={};for(const r of this.normalizedFields){if(n[r.key]!==void 0){t[r.key]=n[r.key];continue}r.type==="boolean"?t[r.key]=!1:r.type==="multiselect"?t[r.key]=[]:t[r.key]=""}this.values=t,this.error=""},toggleMulti(n,t,r){const a=Array.isArray(this.values[n])?this.values[n].slice():[],s=a.indexOf(t);r&&s===-1?a.push(t):!r&&s!==-1&&a.splice(s,1),this.values={...this.values,[n]:a}},validate(){for(const n of this.normalizedFields){if(!n.required)continue;const t=this.values[n.key];if(n.type!=="boolean"){if(n.type==="multiselect"){if(!Array.isArray(t)||t.length===0)return`« ${n.label} » est requis.`;continue}if(t==null||t==="")return`« ${n.label} » est requis.`}}return""},async onSubmit(){if(this.readOnly||this.busy)return;const n=this.validate();if(n){this.error=n;return}this.error="",this.busy=!0;try{await this.$emit("submit",{values:this.values})}finally{this.busy=!1}}}},Rr={class:"wm-form"},Fr={class:"wm-form__head"},$r={class:"wm-form__icon"},zr={class:"wm-form__main"},Ur={class:"wm-form__title"},jr={key:0,class:"wm-form__detail"},Pr=["for"],Hr={key:0,class:"wm-form__req","aria-hidden":"true"},qr=["id","onUpdate:modelValue","placeholder","required","disabled"],Wr=["id","onUpdate:modelValue","placeholder","required","disabled"],Gr=["id","onUpdate:modelValue","placeholder","required","disabled"],Kr=["id","onUpdate:modelValue","required","disabled"],Yr={key:4,class:"wm-form__bool"},Jr=["id","onUpdate:modelValue","disabled"],Xr=["id","onUpdate:modelValue","required","disabled"],Qr={value:"",disabled:""},Zr=["value"],eo={key:6,class:"wm-form__multi"},to=["value","checked","disabled","onChange"],no={key:0,class:"wm-form__err"},ro=["disabled"],oo={key:0,class:"wm-form__spinner","aria-hidden":"true"},so={key:2,class:"wm-form__doneLbl"};function ao(n,t,r,a,s,o){const i=e.resolveComponent("AIAvatar");return e.openBlock(),e.createElementBlock("div",Rr,[e.createElementVNode("div",Fr,[e.createElementVNode("div",$r,[e.createVNode(i,{size:24})]),e.createElementVNode("div",zr,[e.createElementVNode("div",Ur,e.toDisplayString(r.form.title||"Formulaire"),1),r.form.description?(e.openBlock(),e.createElementBlock("div",jr,e.toDisplayString(r.form.description),1)):e.createCommentVNode("",!0)])]),e.createElementVNode("form",{class:"wm-form__body",onSubmit:t[0]||(t[0]=e.withModifiers((...l)=>o.onSubmit&&o.onSubmit(...l),["prevent"]))},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.normalizedFields,l=>(e.openBlock(),e.createElementBlock("div",{key:l.key,class:"wm-form__field"},[e.createElementVNode("label",{for:`wm-f-${s._uid}-${l.key}`,class:"wm-form__label"},[e.createTextVNode(e.toDisplayString(l.label),1),l.required?(e.openBlock(),e.createElementBlock("span",Hr,"*")):e.createCommentVNode("",!0)],8,Pr),l.type==="text"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:0,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"text",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,qr)),[[e.vModelText,s.values[l.key]]]):l.type==="textarea"?e.withDirectives((e.openBlock(),e.createElementBlock("textarea",{key:1,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,class:"wm-form__textarea",rows:"3",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Wr)),[[e.vModelText,s.values[l.key]]]):l.type==="number"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"number",class:"wm-form__input",placeholder:l.placeholder||"",required:l.required,disabled:r.readOnly||s.busy},null,8,Gr)),[[e.vModelText,s.values[l.key],void 0,{number:!0}]]):l.type==="date"?e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:3,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"date",class:"wm-form__input",required:l.required,disabled:r.readOnly||s.busy},null,8,Kr)),[[e.vModelText,s.values[l.key]]]):l.type==="boolean"?(e.openBlock(),e.createElementBlock("label",Yr,[e.withDirectives(e.createElementVNode("input",{id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,type:"checkbox",disabled:r.readOnly||s.busy},null,8,Jr),[[e.vModelCheckbox,s.values[l.key]]]),e.createElementVNode("span",null,e.toDisplayString(l.placeholder||"Oui"),1)])):l.type==="select"?e.withDirectives((e.openBlock(),e.createElementBlock("select",{key:5,id:`wm-f-${s._uid}-${l.key}`,"onUpdate:modelValue":p=>s.values[l.key]=p,class:"wm-form__select",required:l.required,disabled:r.readOnly||s.busy},[e.createElementVNode("option",Qr,e.toDisplayString(l.placeholder||"Choisir…"),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,p=>(e.openBlock(),e.createElementBlock("option",{key:p.value,value:p.value},e.toDisplayString(p.label),9,Zr))),128))],8,Xr)),[[e.vModelSelect,s.values[l.key]]]):l.type==="multiselect"?(e.openBlock(),e.createElementBlock("div",eo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,p=>(e.openBlock(),e.createElementBlock("label",{key:p.value,class:"wm-form__multiItem"},[e.createElementVNode("input",{type:"checkbox",value:p.value,checked:Array.isArray(s.values[l.key])&&s.values[l.key].includes(p.value),disabled:r.readOnly||s.busy,onChange:g=>o.toggleMulti(l.key,p.value,g.target.checked)},null,40,to),e.createElementVNode("span",null,e.toDisplayString(p.label),1)]))),128))])):e.createCommentVNode("",!0)]))),128)),s.error?(e.openBlock(),e.createElementBlock("div",no,e.toDisplayString(s.error),1)):e.createCommentVNode("",!0),r.readOnly?(e.openBlock(),e.createElementBlock("div",so,"Réponse envoyée")):(e.openBlock(),e.createElementBlock("button",{key:1,type:"submit",class:"wm-form__submit",disabled:s.busy},[s.busy?(e.openBlock(),e.createElementBlock("span",oo)):e.createCommentVNode("",!0),e.createElementVNode("span",null,e.toDisplayString(s.busy?"Envoi…":r.form.submit_label||"Envoyer"),1)],8,ro))],32)])}const Ae=N(Lr,[["render",ao],["__scopeId","data-v-64b40f76"]]),io={name:"WmFeedback",props:{busy:{type:Boolean,default:!1},done:{type:Boolean,default:!1}},emits:["submit"],data(){return{sel:null,options:[{v:1,e:"😞",l:"Pas bien"},{v:2,e:"😐",l:"Moyen"},{v:3,e:"🙂",l:"Bien"},{v:4,e:"😄",l:"Super"},{v:5,e:"🤩",l:"Excellent"}]}},methods:{onSend(){!this.sel||this.busy||this.$emit("submit",{rating:this.sel})}}},lo={class:"wm-fb"},co={class:"wm-fb__row"},uo=["onClick"],mo={class:"wm-fb__emoji"},ho={class:"wm-fb__label"},po=["disabled"],fo={key:1,class:"wm-fb__done"};function _o(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",lo,[r.done?(e.openBlock(),e.createElementBlock("div",fo,[...t[3]||(t[3]=[e.createStaticVNode('<div class="wm-fb__check" data-v-6f45ff3b><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" data-v-6f45ff3b><path d="M20 6L9 17l-5-5" data-v-6f45ff3b></path></svg></div><div class="wm-fb__doneTitle" data-v-6f45ff3b>Merci pour votre retour !</div><div class="wm-fb__doneSub" data-v-6f45ff3b>Votre avis a bien été pris en compte.</div>',3)])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t[1]||(t[1]=e.createElementVNode("div",{class:"wm-fb__title"},"Comment s'est passée cette conversation ?",-1)),t[2]||(t[2]=e.createElementVNode("div",{class:"wm-fb__sub"},"Votre avis nous aide à améliorer l'assistant.",-1)),e.createElementVNode("div",co,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.options,i=>(e.openBlock(),e.createElementBlock("button",{key:i.v,type:"button",class:e.normalizeClass(["wm-fb__opt",{"is-selected":s.sel===i.v}]),onClick:l=>s.sel=i.v},[e.createElementVNode("span",mo,e.toDisplayString(i.e),1),e.createElementVNode("span",ho,e.toDisplayString(i.l),1)],10,uo))),128))]),e.createElementVNode("button",{type:"button",class:"wm-fb__send",disabled:!s.sel||r.busy,onClick:t[0]||(t[0]=(...i)=>o.onSend&&o.onSend(...i))},e.toDisplayString(r.busy?"Envoi…":"Envoyer mon avis"),9,po)],64))])}const Se=N(io,[["render",_o],["__scopeId","data-v-6f45ff3b"]]);function vo(n){const t=new Date(n);return t.setHours(0,0,0,0),t}const go={name:"WmHistoryDrawer",props:{conversations:{type:Array,default:()=>[]},activeId:{type:[String,Number],default:null}},emits:["close","new","pick"],data(){return{query:""}},computed:{normalized(){return(Array.isArray(this.conversations)?this.conversations.slice():[]).map(t=>{var s;const r=t.last_message_at||t.updated_at||t.created_at||null,a=r?Date.parse(r):0;return{id:t.id,raw:t,title:t.name||"Nouvelle conversation",preview:t._preview||t.last_message_preview||t.preview||((s=t.metadata)==null?void 0:s.last_preview)||"",unread:!!t._unread,stamp:a}}).sort((t,r)=>r.stamp-t.stamp)},filtered(){const n=this.query.trim().toLowerCase();return n?this.normalized.filter(t=>(t.title||"").toLowerCase().includes(n)||(t.preview||"").toLowerCase().includes(n)):this.normalized},groups(){const t=vo(new Date).getTime(),r=t-6*864e5,a=[],s=[],o=[];for(const i of this.filtered){if(!i.stamp){o.push(i);continue}i.stamp>=t?a.push(i):i.stamp>=r?s.push(i):o.push(i)}return[{key:"today",label:"Aujourd'hui",items:a},{key:"week",label:"Cette semaine",items:s},{key:"older",label:"Plus ancien",items:o}]},hasAny(){return this.filtered.length>0}}},yo={class:"wm-hd"},ko={class:"wm-hd__panel",role:"dialog","aria-label":"Vos discussions"},wo={class:"wm-hd__head"},bo={class:"wm-hd__top"},Eo={class:"wm-hd__search"},Co={class:"wm-hd__list"},Bo={key:0,class:"wm-hd__group"},No={class:"wm-hd__groupLabel"},Vo={class:"wm-hd__rows"},Ao=["onClick"],So={class:"wm-hd__rowIcon"},Mo={key:0,class:"wm-hd__rowDot","aria-label":"Message non lu"},xo={class:"wm-hd__rowBody"},To={class:"wm-hd__rowTop"},Io={class:"wm-hd__rowTitle"},Oo={class:"wm-hd__rowPreview"},Do={key:0,class:"wm-hd__empty"};function Lo(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",yo,[e.createElementVNode("div",{class:"wm-hd__scrim",onClick:t[0]||(t[0]=i=>n.$emit("close"))}),e.createElementVNode("aside",ko,[e.createElementVNode("div",wo,[t[5]||(t[5]=e.createElementVNode("div",{class:"wm-hd__heading"},[e.createElementVNode("div",{class:"wm-hd__title"},"Vos discussions"),e.createElementVNode("div",{class:"wm-hd__sub"},"Reprenez là où vous en étiez.")],-1)),e.createElementVNode("button",{type:"button",class:"wm-hd__close","aria-label":"Fermer",onClick:t[1]||(t[1]=i=>n.$emit("close"))},[...t[4]||(t[4]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])]),e.createElementVNode("div",bo,[e.createElementVNode("button",{type:"button",class:"wm-hd__new",onClick:t[2]||(t[2]=i=>n.$emit("new"))},[...t[6]||(t[6]=[e.createElementVNode("span",{class:"wm-hd__newIcon"},[e.createElementVNode("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2.2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M12 5v14M5 12h14"})])],-1),e.createElementVNode("span",null,"Démarrer un nouveau fil",-1)])]),e.createElementVNode("div",Eo,[t[7]||(t[7]=e.createElementVNode("span",{class:"wm-hd__searchIcon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M21 21l-4.35-4.35M11 17a6 6 0 100-12 6 6 0 000 12z"})])],-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":t[3]||(t[3]=i=>s.query=i),type:"text",placeholder:"Rechercher dans vos messages","aria-label":"Rechercher dans vos messages"},null,512),[[e.vModelText,s.query]])])]),e.createElementVNode("div",Co,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.groups,i=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:i.key},[i.items.length?(e.openBlock(),e.createElementBlock("div",Bo,[e.createElementVNode("div",No,e.toDisplayString(i.label),1),e.createElementVNode("div",Vo,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.items,l=>(e.openBlock(),e.createElementBlock("button",{key:l.id,type:"button",class:e.normalizeClass(["wm-hd__row",{"wm-hd__row--active":l.id===r.activeId,"wm-hd__row--unread":l.unread}]),onClick:p=>n.$emit("pick",l)},[e.createElementVNode("div",So,[t[8]||(t[8]=e.createElementVNode("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true"},[e.createElementVNode("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"})],-1)),l.unread?(e.openBlock(),e.createElementBlock("span",Mo)):e.createCommentVNode("",!0)]),e.createElementVNode("div",xo,[e.createElementVNode("div",To,[e.createElementVNode("span",Io,e.toDisplayString(l.title),1)]),e.createElementVNode("div",Oo,e.toDisplayString(l.preview||"Aucun message"),1)])],10,Ao))),128))])])):e.createCommentVNode("",!0)],64))),128)),o.hasAny?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Do," Aucun fil pour le moment. "))])])])}const Me=N(go,[["render",Lo],["__scopeId","data-v-1259e822"]]),Ro={name:"WmMoreMenu",props:{canRename:{type:Boolean,default:!0},canClear:{type:Boolean,default:!0},canExport:{type:Boolean,default:!0},notifEnabled:{type:Boolean,default:!0},statusUrl:{type:String,default:""},helpUrl:{type:String,default:""}},emits:["close","action","notif-toggle"],data(){return{notifOn:this.notifEnabled}},watch:{notifEnabled(n){this.notifOn=!!n}},methods:{emit(n){this.$emit("action",n)},toggleNotif(){this.notifOn=!this.notifOn,this.$emit("notif-toggle",this.notifOn)}}},Fo={class:"wm-mm"},$o={class:"wm-mm__pop",role:"menu"},zo={class:"wm-mm__section"},Uo={class:"wm-mm__section"},jo={class:"wm-mm__section"};function Po(n,t,r,a,s,o){return e.openBlock(),e.createElementBlock("div",Fo,[e.createElementVNode("div",{class:"wm-mm__scrim",onClick:t[0]||(t[0]=i=>n.$emit("close"))}),e.createElementVNode("div",$o,[e.createElementVNode("div",zo,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[1]||(t[1]=i=>o.emit("history"))},[...t[8]||(t[8]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M3 3v5h5M3.05 13A9 9 0 1 0 6 5.3L3 8M12 7v5l4 2"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Historique des discussions",-1)])]),r.canRename?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[2]||(t[2]=i=>o.emit("rename"))},[...t[9]||(t[9]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-c1bb81d2><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" data-v-c1bb81d2><path d="M12 20h9" data-v-c1bb81d2></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" data-v-c1bb81d2></path></svg></span><span class="wm-mm__label" data-v-c1bb81d2>Renommer le fil</span>',2)])])):e.createCommentVNode("",!0),r.canClear?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[3]||(t[3]=i=>o.emit("clear"))},[...t[10]||(t[10]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M4 7h16M10 11v6M14 11v6M5 7l1 13a2 2 0 002 2h8a2 2 0 002-2l1-13M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Effacer ce fil",-1)])])):e.createCommentVNode("",!0),r.canExport?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",class:"wm-mm__item",onClick:t[4]||(t[4]=i=>o.emit("export"))},[...t[11]||(t[11]=[e.createStaticVNode('<span class="wm-mm__icon" data-v-c1bb81d2><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" data-v-c1bb81d2><path d="M4 12v8a2 2 0 002 2h12a2 2 0 002-2v-8M16 6l-4-4-4 4M12 2v13" data-v-c1bb81d2></path></svg></span><span class="wm-mm__label" data-v-c1bb81d2>Exporter la transcription</span><span class="wm-mm__hint" data-v-c1bb81d2>.txt</span>',3)])])):e.createCommentVNode("",!0)]),t[17]||(t[17]=e.createElementVNode("div",{class:"wm-mm__sep"},null,-1)),e.createElementVNode("div",Uo,[e.createElementVNode("button",{type:"button",class:"wm-mm__item",onClick:t[5]||(t[5]=(...i)=>o.toggleNotif&&o.toggleNotif(...i))},[t[13]||(t[13]=e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2c0 .5-.2 1-.6 1.4L4 17h5m6 0a3 3 0 11-6 0"})])],-1)),t[14]||(t[14]=e.createElementVNode("span",{class:"wm-mm__label"},"Notifications",-1)),e.createElementVNode("span",{class:e.normalizeClass(["wm-mm__toggle",{"wm-mm__toggle--on":s.notifOn}])},[...t[12]||(t[12]=[e.createElementVNode("span",{class:"wm-mm__knob"},null,-1)])],2)])]),t[18]||(t[18]=e.createElementVNode("div",{class:"wm-mm__sep"},null,-1)),e.createElementVNode("div",jo,[r.statusUrl?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-mm__item",onClick:t[6]||(t[6]=i=>o.emit("status"))},[...t[15]||(t[15]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zM10 6v4l3 2"})])],-1),e.createElementVNode("span",{class:"wm-mm__label"},"Statut des services",-1)])])):e.createCommentVNode("",!0),r.helpUrl?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"wm-mm__item",onClick:t[7]||(t[7]=i=>o.emit("help"))},[...t[16]||(t[16]=[e.createElementVNode("span",{class:"wm-mm__icon"},[e.createElementVNode("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"},[e.createElementVNode("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),e.createElementVNode("span",{class:"wm-mm__label"},"Centre d'aide",-1)])])):e.createCommentVNode("",!0)])])])}const xe=N(Ro,[["render",Po],["__scopeId","data-v-c1bb81d2"]]),se="ww-messenger-tokens";function K(n){var r;const t=(r=n==null?void 0:n.author)==null?void 0:r.type;return t==="agent_ia"||t==="agent_human"}function Ho(n,t){if(!n||!t)return"";const r=Array.isArray(n.fields)?n.fields:[],a=[];for(const s of r){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=t[s.key];if(o==null||o==="")continue;let i;if(Array.isArray(o)){if(i=o.map(l=>P(s,String(l))).join(", "),!i)continue}else typeof o=="boolean"?i=o?"Oui":"Non":i=P(s,String(o));a.push(`${s.label} :
52
+ ${i}`)}return a.join(`
53
+
54
+ `)}function P(n,t){if(!Array.isArray(n==null?void 0:n.options))return t;const r=n.options.find(a=>(a==null?void 0:a.value)===t);return(r==null?void 0:r.label)||t}function qo(n,t){const r=[],a=Array.isArray(n==null?void 0:n.fields)?n.fields:[];for(const s of a){if(!(s!=null&&s.key)||!(s!=null&&s.label))continue;const o=t==null?void 0:t[s.key];if(o==null||o==="")continue;let i;if(Array.isArray(o)){if(i=o.map(p=>P(s,String(p))).join(", "),!i)continue}else typeof o=="boolean"?i=o?"Oui":"Non":i=P(s,String(o));const l=s.type==="textarea"||typeof i=="string"&&(i.length>60||i.includes(`
55
+ `));r.push({label:s.label,value:i,multiline:l})}return{kind:"form_response",data:{title:(n==null?void 0:n.title)||"Formulaire",fields:r}}}const Wo=450,Go=50,Ko=900,Yo=12e3,Jo=300,Xo={name:"Messenger",components:{Launcher:ce,Header:ue,Onboarding:me,MessageList:ke,Composer:Be,SuggestionChips:Ne,ApprovalCard:Ve,FormCard:Ae,Feedback:Se,HistoryDrawer:Me,MoreMenu:xe},provide(){return{signAttachmentFn:n=>{var t,r;return((r=(t=this.store)==null?void 0:t.signAttachment)==null?void 0:r.call(t,n))||null}}},props:{baseUrl:{type:String,default:""},widgetId:{type:String,default:""},userId:{type:String,default:""},userHash:{type:String,default:""},displayMode:{type:String,default:"floating"},devtools:{type:Boolean,default:!1}},data(){return{transport:null,store:null,isOpen:!1,draft:"",busy:!1,bootError:null,pendingAttachments:[],feedbackBusy:!1,feedbackDone:!1,revealedAt:{},nextRevealAt:0,revealTimers:[],convOpenedAt:0,historyOpen:!1,moreOpen:!1,activeConvId:null,showOnboarding:!1,notifEnabled:!0,labelDismissed:!1,readState:{},floatHeight:0,floatRO:null,approvalSettled:!0,approvalSettleTimer:null,approvalLatchId:null}},computed:{isEditor(){return!!this.devtools},isEmbedded(){return this.displayMode==="embedded"},error(){var n;return this.bootError||((n=this.s)==null?void 0:n.error)||null},canBoot(){return!!(this.baseUrl&&this.widgetId&&this.userId&&this.userHash)},s(){var n;return((n=this.store)==null?void 0:n.state)||null},ready(){var n;return!!((n=this.s)!=null&&n.ready)},allConversations(){var t;const n=(t=this.s)==null?void 0:t.conversations;return Array.isArray(n)?n:[]},drawerConversations(){var r;const n=this.readState,t=((r=this.s)==null?void 0:r.messagesByConv)||{};return this.allConversations.map(a=>{const s=t[a.id]||[],o=this.convLastActivity(a,s),i=n[a.id]||"",l=this.lastMessageAuthorType(s),p=!!o&&l!=="user"&&(!i||o>i);return{...a,_preview:this.convPreview(a,s),_unread:p}})},unreadCount(){return this.drawerConversations.filter(n=>n._unread).length},unreadThreads(){var t;const n=((t=this.s)==null?void 0:t.messagesByConv)||{};return this.drawerConversations.filter(r=>r._unread).map(r=>({id:r.id,title:r.name||"Nouvelle conversation",preview:r._preview||"Nouveau message",_ts:this.convLastActivity(r,n[r.id]||[])})).sort((r,a)=>r._ts<a._ts?1:r._ts>a._ts?-1:0).slice(0,3)},latestUnread(){var r;const n=((r=this.s)==null?void 0:r.messagesByConv)||{};let t=null;for(const a of this.drawerConversations){if(!a._unread)continue;const s=this.convLastActivity(a,n[a.id]||[]);(!t||s>t.ts)&&(t={convId:a.id,preview:a._preview,ts:s})}return t},launcherPeek(){if(this.isOpen||this.isEmbedded||this.labelDismissed)return"";const n=this.latestUnread;return n?n.preview||"Vous avez un nouveau message":""},currentConv(){if(this.showOnboarding)return null;const n=this.allConversations;if(!n.length)return null;if(this.activeConvId!=null){const t=n.find(r=>r.id===this.activeConvId);if(t)return t}return n[0]||null},canBack(){return!!this.currentConv},statusUrl(){var r;const n=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(n))return"";const t=n.find(a=>a.icon==="status"&&a.url);return(t==null?void 0:t.url)||""},helpUrl(){var r;const n=(r=this.widget)==null?void 0:r.quick_links;if(!Array.isArray(n))return"";const t=n.find(a=>(a.icon==="chat"||a.icon==="help")&&a.url);return(t==null?void 0:t.url)||""},widget(){var n,t;return((t=(n=this.s)==null?void 0:n.config)==null?void 0:t.widget)||null},widgetWelcomeMessage(){var n;return((n=this.widget)==null?void 0:n.welcome_message)||""},agentName(){var n,t,r;return((r=(t=(n=this.s)==null?void 0:n.config)==null?void 0:t.agent)==null?void 0:r.name)||""},agentAvatarUrl(){var n,t,r;return((r=(t=(n=this.s)==null?void 0:n.config)==null?void 0:t.agent)==null?void 0:r.avatar_url)||null},quickLinks(){var t;const n=(t=this.widget)==null?void 0:t.quick_links;return Array.isArray(n)?n:[]},teamMembers(){var t;const n=(t=this.widget)==null?void 0:t.team_members;return Array.isArray(n)?n:[]},responseLabel(){var n;return((n=this.widget)==null?void 0:n.response_time_label)||""},humanMessageAuthor(){var t,r,a;if(!this.currentConv)return null;const n=((t=this.s.messagesByConv)==null?void 0:t[this.currentConv.id])||[];for(let s=n.length-1;s>=0;s--)if(((a=(r=n[s])==null?void 0:r.author)==null?void 0:a.type)==="agent_human")return n[s].author;return null},humanAgentName(){var n;return((n=this.humanMessageAuthor)==null?void 0:n.name)||""},humanAgentAvatarUrl(){var n;return((n=this.humanMessageAuthor)==null?void 0:n.avatar_url)||null},isEscalated(){return!!this.humanMessageAuthor},isWaitingHuman(){var t;const n=(t=this.currentConv)==null?void 0:t.status;return n==="waiting"||n==="handled"},headerTitle(){var n,t;return((n=this.currentConv)==null?void 0:n.name)||((t=this.widget)==null?void 0:t.name)||"Nouvelle conversation"},composerPlaceholder(){return this.isEscalated&&this.humanAgentName?`Répondre à ${this.humanAgentName.split(" ")[0]}…`:this.isWaitingHuman?"Un agent prend le relais…":"Écrivez votre message…"},displayedMessages(){const n=this.currentConv;if(!n)return[];const t=s=>{var o,i;return(s==null?void 0:s.type)==="action"||(s==null?void 0:s.type)==="system"||((o=s==null?void 0:s.payload)==null?void 0:o.type)==="system"||Array.isArray((i=s==null?void 0:s.payload)==null?void 0:i.attachments)&&s.payload.attachments.length?!0:typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0},r=s=>{var o;return(s==null?void 0:s.type)==="action"&&((o=s==null?void 0:s.payload)==null?void 0:o.state)==="pending"},a=this.revealedAt;return(this.s.messagesByConv[n.id]||[]).filter(s=>!r(s)).filter(s=>K(s)?a[s.id]>0:!0).filter(t)},streamingActive(){var r,a,s;const n=this.currentConv;return n?Object.keys(((r=this.s)==null?void 0:r.streamingByMsgId)||{}).length>0?!0:this.actionInFlight?!1:(((s=(a=this.s)==null?void 0:a.messagesByConv)==null?void 0:s[n.id])||[]).some(o=>K(o)&&!(this.revealedAt[o.id]>0)):!1},currentConvMessages(){var t,r,a;const n=(t=this.currentConv)==null?void 0:t.id;return n?((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[n])||[]:[]},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 n,t,r;return((t=(n=this.pendingApproval)==null?void 0:n.payload)==null?void 0:t.name)||((r=this.pendingApproval)==null?void 0:r.text_md)||"Confirmer l'action"},approvalDetail(){var a,s,o,i,l,p;const n=(o=(s=(a=this.pendingApproval)==null?void 0:a.payload)==null?void 0:s.pending)==null?void 0:o.user_explanation;if(typeof n=="string"&&n.trim())return n.trim();const t=(p=(l=(i=this.pendingApproval)==null?void 0:i.payload)==null?void 0:l.pending)==null?void 0:p.prepared_params;if(!t||typeof t!="object")return"";const r=Object.entries(t);return r.length?r.slice(0,2).map(([g,f])=>`${g}: ${f}`).join(" · "):""},actionInFlight(){var n,t;return!this.currentConv||!this.store?null:((t=(n=this.store).getActionInFlight)==null?void 0:t.call(n,this.currentConv.id))||null},actionInFlightName(){var t;const n=this.actionInFlight;return n?((t=n.payload)==null?void 0:t.name)||n.text_md||"Action":""},suggestions(){return!this.currentConv||!this.store?[]:this.streamingActive?[]:this.pendingForm?[]:this.store.getLatestSuggestions(this.currentConv.id)},pendingForm(){var n,t;return!this.currentConv||!this.store||this.pendingApproval||this.actionInFlight||this.streamingActive||!this.approvalSettled?null:((t=(n=this.store).getLatestForm)==null?void 0:t.call(n,this.currentConv.id))||null},showFeedback(){var t;const n=this.currentConv;return n?this.feedbackDone?!0:n.status!=="resolved"?!1:!((t=n.metadata)!=null&&t.feedback):!1},floatVisible(){return this.approvalReady||!!this.pendingForm||this.showFeedback||this.suggestions.length>0},dateLabel(){var r,a,s;const n=this.currentConv;let t=new Date;if(n){const i=((s=(((a=(r=this.s)==null?void 0:r.messagesByConv)==null?void 0:a[n.id])||[]).find(l=>l==null?void 0:l.created_at))==null?void 0:s.created_at)||n.created_at;if(i){const l=new Date(i);Number.isNaN(l.getTime())||(t=l)}}return`Aujourd'hui · ${Q(t)}`},paginationState(){var r,a,s;const n=(r=this.currentConv)==null?void 0:r.id,t=n?(s=(a=this.s)==null?void 0:a.paginationByConv)==null?void 0:s[n]:null;return{loading:!!(t!=null&&t.loading),hasMore:!!(t!=null&&t.nextCursor)}}},watch:{latestUnread:{handler(n,t){if(!n){this.labelDismissed=!1;return}(!t||n.convId!==t.convId||n.ts>t.ts)&&(this.labelDismissed=!1)},deep:!0},"currentConv.id":{handler(){this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0,this.convOpenedAt=Date.now(),this.moreOpen=!1,this.resetApprovalPacing()},immediate:!0},pendingApproval:{handler(n,t){if(n&&!t){const r=n!=null&&n.created_at?Date.parse(n.created_at):NaN;if(!(Number.isFinite(r)&&r>=this.convOpenedAt)){this.resetApprovalPacing();return}this.bumpApprovalSettle(2600)}else!n&&t&&this.resetApprovalPacing()},immediate:!1},streamingActive(n,t){n!==t&&this.pendingApproval&&this.pendingApproval.id!==this.approvalLatchId&&this.bumpApprovalSettle()},approvalReady(n){n&&this.pendingApproval&&(this.approvalLatchId=this.pendingApproval.id)},floatVisible:{handler(n){this.$nextTick(()=>this.syncFloatObserver(n))},immediate:!0},currentConvMessages(n){var a;if(!Array.isArray(n)||!n.length)return;const t=Date.now(),r={...this.revealedAt};for(const s of n){if((s==null?void 0:s.id)==null||r[s.id]!==void 0)continue;if(!K(s)){r[s.id]=t;continue}const o=s!=null&&s.created_at?Date.parse(s.created_at):NaN;if(!Number.isFinite(o)||o<this.convOpenedAt){r[s.id]=t;continue}const i=typeof(s==null?void 0:s.text_md)=="string"&&s.text_md.trim().length>0,l=Array.isArray((a=s==null?void 0:s.payload)==null?void 0:a.attachments)&&s.payload.attachments.length>0;if(!i&&!l){r[s.id]=t;continue}r[s.id]=0,this.scheduleReveal(s)}this.revealedAt=r,(this.isOpen||this.isEmbedded)&&!this.historyOpen&&this.currentConv&&this.markConvRead(this.currentConv)}},async mounted(){if(console.log("[messenger] mounted",{isEditor:this.isEditor,canBoot:this.canBoot,hasBaseUrl:!!this.baseUrl,hasWidgetId:!!this.widgetId,hasUserId:!!this.userId,hasUserHash:!!this.userHash}),typeof document<"u"&&!document.getElementById(se)){const n=document.createElement("style");n.id=se,n.textContent=le,document.head.appendChild(n)}this.hydrateReadState(),await this.boot(),this.isEmbedded&&this.store&&await this.open()},beforeUnmount(){this.cancelReveals(),this.disconnectFloatRO(),this.resetApprovalPacing(),this.store&&this.store.destroy()},methods:{syncFloatObserver(n){if(this.disconnectFloatRO(),!n){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(r=>{const a=r[0];if(!a)return;const s=Math.ceil(a.contentRect.height+8);s!==this.floatHeight&&(this.floatHeight=s,this.$nextTick(()=>{var o,i;(i=(o=this.$refs.messageList)==null?void 0:o.scrollToBottom)==null||i.call(o)}))}),this.floatRO.observe(t)}},disconnectFloatRO(){if(this.floatRO){try{this.floatRO.disconnect()}catch{}this.floatRO=null}},convLastActivity(n,t){let r=(n==null?void 0:n.last_message_at)||(n==null?void 0:n.updated_at)||(n==null?void 0:n.created_at)||"";for(const a of t)a!=null&&a.created_at&&a.created_at>r&&(r=a.created_at);return r},lastMessageAuthorType(n){var t,r;for(let a=n.length-1;a>=0;a--){const s=(r=(t=n[a])==null?void 0:t.author)==null?void 0:r.type;if(s)return s}return""},convPreview(n,t){var r,a,s;for(let o=t.length-1;o>=0;o--){const i=t[o];if(!i)continue;const l=typeof i.text_md=="string"?i.text_md.trim():"";if(l)return(((r=i.author)==null?void 0:r.type)==="user"?"Vous : ":"")+l.replace(/\s+/g," ");const p=(a=i.payload)==null?void 0:a.attachments;if(Array.isArray(p)&&p.length)return"📎 Pièce jointe"}return(n==null?void 0:n.last_message_preview)||(n==null?void 0:n.preview)||((s=n==null?void 0:n.metadata)==null?void 0:s.last_preview)||""},readStorageKey(){const n=this.widgetId||"",t=this.userId||"";return`wm:read:${n}:${t}`},hydrateReadState(){try{if(typeof localStorage>"u")return;const n=localStorage.getItem(this.readStorageKey());if(!n)return;const t=JSON.parse(n);t&&typeof t=="object"&&(this.readState=t)}catch{}},persistReadState(){try{if(typeof localStorage>"u")return;localStorage.setItem(this.readStorageKey(),JSON.stringify(this.readState))}catch{}},markConvRead(n){var a,s;if(!(n!=null&&n.id))return;const t=((s=(a=this.s)==null?void 0:a.messagesByConv)==null?void 0:s[n.id])||[],r=this.convLastActivity(n,t);r&&this.readState[n.id]!==r&&(this.readState={...this.readState,[n.id]:r},this.persistReadState())},cancelReveals(){for(const n of this.revealTimers)try{clearTimeout(n)}catch{}this.revealTimers=[]},resetApprovalPacing(){if(this.approvalSettleTimer){try{clearTimeout(this.approvalSettleTimer)}catch{}this.approvalSettleTimer=null}this.approvalSettled=!0,this.approvalLatchId=null},bumpApprovalSettle(n=800){if(this.approvalSettled=!1,this.approvalSettleTimer)try{clearTimeout(this.approvalSettleTimer)}catch{}this.approvalSettleTimer=setTimeout(()=>{this.approvalSettled=!0,this.approvalSettleTimer=null},n)},scheduleReveal(n){const t=Date.now(),r=((n==null?void 0:n.text_md)||"").length,a=Math.min(Yo,Math.max(Ko,r*Go)),o=Math.max(t+Wo,this.nextRevealAt+Jo)+a;this.nextRevealAt=o;const i=Math.max(0,o-t),l=n.id,p=setTimeout(()=>{this.revealedAt={...this.revealedAt,[l]:Date.now()},this.revealTimers=this.revealTimers.filter(f=>f!==p)},i);this.revealTimers.push(p);const g=setTimeout(()=>{this.revealedAt[l]>0||(this.revealedAt={...this.revealedAt,[l]:Date.now()}),this.revealTimers=this.revealTimers.filter(f=>f!==g)},i+4e3);this.revealTimers.push(g)},async boot(){if(!this.canBoot){console.warn("[messenger] boot skipped — missing creds",{baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,hasUserHash:!!this.userHash});return}try{console.log("[messenger] boot start",{baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId}),this.transport=e.markRaw(ae({baseUrl:this.baseUrl,widgetId:this.widgetId,userId:this.userId,userHash:this.userHash})),this.store=e.markRaw(ie(this.transport)),await this.store.start(),console.log("[ww-messenger] boot done",{ready:this.store.state.ready,error:this.store.state.error})}catch(n){console.error("[ww-messenger] bootstrap failed",n),this.bootError=(n==null?void 0:n.message)||String(n)}},async refresh(){this.store&&this.store.destroy(),this.cancelReveals(),this.revealedAt={},this.nextRevealAt=0,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.historyOpen=!1,this.moreOpen=!1,this.activeConvId=null,this.showOnboarding=!1,await this.boot(),this.isEmbedded&&this.store&&await this.open()},async openFromPeek(){var t,r;const n=(t=this.latestUnread)==null?void 0:t.convId;n&&n!==((r=this.currentConv)==null?void 0:r.id)&&(this.activeConvId=n,this.showOnboarding=!1),await this.open()},async open(){if(this.isOpen=!0,this.store&&this.store.setPanelOpen(!0),this.currentConv){try{await this.store.openConversation(this.currentConv.id)}catch(n){console.error("[ww-messenger] load messages failed",n)}this.markConvRead(this.currentConv)}},close(){this.isOpen=!1,this.store&&this.store.setPanelOpen(!1)},async startConv(){if(!this.busy){this.busy=!0;try{const n=await this.store.createConversation({});this.activeConvId=n.id,this.showOnboarding=!1,await this.store.openConversation(n.id),this.markConvRead(n),this.focusComposer()}catch(n){console.error("[ww-messenger] create conv failed",n),this.bootError=(n==null?void 0:n.message)||String(n)}finally{this.busy=!1}}},focusComposer(){this.$nextTick(()=>{var n;return(n=this.$refs.composer)==null?void 0:n.focus()})},toggleMore(){this.historyOpen=!1,this.moreOpen=!this.moreOpen},goHome(){this.historyOpen=!1,this.moreOpen=!1,this.activeConvId=null,this.showOnboarding=!0},async onDrawerPick(n){if(!(n!=null&&n.id)||!this.store)return;this.historyOpen=!1,this.activeConvId=n.id,this.showOnboarding=!1;try{await this.store.openConversation(n.id)}catch(r){console.error("[ww-messenger] open conv failed",r)}const t=this.allConversations.find(r=>r.id===n.id);t&&this.markConvRead(t)},async onDrawerNew(){this.historyOpen=!1,await this.startConv()},onNotifToggle(n){this.notifEnabled=!!n},async onMoreAction(n){switch(this.moreOpen=!1,n){case"history":this.historyOpen=!0;break;case"rename":await this.renameCurrentConv();break;case"clear":await this.clearCurrentConv();break;case"export":this.exportCurrentConv();break;case"status":if(this.statusUrl)try{window.open(this.statusUrl,"_blank","noopener")}catch{}break;case"help":if(this.helpUrl)try{window.open(this.helpUrl,"_blank","noopener")}catch{}break}},async renameCurrentConv(){const n=this.currentConv;if(!n||!this.store)return;let t;try{t=typeof window<"u"&&typeof window.prompt=="function"?window.prompt("Nouveau nom du fil",n.name||""):null}catch{t=null}if(t==null)return;const r=t.trim();if(!(!r||r===n.name))try{await this.store.patchConversation(n.id,{name:r})}catch(a){console.error("[ww-messenger] rename failed",a)}},async clearCurrentConv(){var r;const n=this.currentConv;!n||!this.store||!(!(typeof window<"u"&&typeof window.confirm=="function")||window.confirm("Effacer ce fil de votre côté ? Cette action ne supprime pas les messages côté agent."))||((r=this.s)!=null&&r.messagesByConv&&(this.s.messagesByConv[n.id]=[]),this.activeConvId=null,this.showOnboarding=!0)},exportCurrentConv(){var s,o,i,l,p,g;const n=this.currentConv;if(!n)return;const t=(((o=(s=this.s)==null?void 0:s.messagesByConv)==null?void 0:o[n.id])||[]).slice(),r=[`# ${n.name||"Conversation"}`,n.created_at?`Créée le : ${n.created_at}`:"",""];for(const f of t){if(!f)continue;const C=((i=f.author)==null?void 0:i.name)||(((l=f.author)==null?void 0:l.type)==="user"?"Vous":((p=f.author)==null?void 0:p.type)==="agent_human"?"Agent":((g=f.author)==null?void 0:g.type)==="agent_ia"?"Assistant IA":"Système"),V=f.created_at?new Date(f.created_at).toLocaleString("fr-FR"):"",b=(f.text_md||"").trim();b&&(r.push(`[${V}] ${C} :`),r.push(b),r.push(""))}const a=new Blob([r.join(`
56
+ `)],{type:"text/plain;charset=utf-8"});try{const f=URL.createObjectURL(a),C=document.createElement("a");C.href=f,C.download=`${(n.name||"conversation").replace(/[^a-z0-9-_]+/gi,"_")}.txt`,document.body.appendChild(C),C.click(),document.body.removeChild(C),setTimeout(()=>URL.revokeObjectURL(f),1e3)}catch(f){console.error("[ww-messenger] export failed",f)}},async onSend(n){const t=this.currentConv;if(!t&&(await this.startConv(),!this.currentConv))return;const r=(this.currentConv||t).id,a=this.pendingAttachments.slice();this.pendingAttachments=[],await this.store.send(r,n,{attachments:a.length?a:void 0})},async onSuggestion(n){const t=n==null?void 0:n.label;t&&await this.onSend(t)},async onLoadMore(){var t;const n=(t=this.currentConv)==null?void 0:t.id;!n||!this.store||await this.store.loadMore(n)},async onApprovalCallback(n){const t=this.pendingApproval;t&&await this.store.clickCallback(t.id,n)},async onFormSubmit({values:n}){const t=this.pendingForm;if(!(t!=null&&t.form))return;const r=Ho(t.form,n);if(!r)return;const a=this.currentConv;a&&await this.store.send(a.id,r,{metadata:{artifact:qo(t.form,n)}})},async onAttach(n){if(!(!n||!this.transport))try{const t=await this.transport.uploadAttachment(n);this.pendingAttachments.push({type:t.type||"file",path:t.path,name:n.name||"fichier",mime_type:n.type,size_bytes:n.size})}catch(t){console.error("[ww-messenger] attachment upload failed",t)}},async onQuickLink(n){if(n){if(n.url){try{window.open(n.url,"_blank","noopener")}catch{}return}await this.startConv(),this.currentConv&&await this.store.send(this.currentConv.id,n.label)}},async onFeedback({rating:n,comment:t}){if(this.currentConv){this.feedbackBusy=!0;try{await this.store.submitFeedback(this.currentConv.id,{rating:n,comment:t}),this.feedbackDone=!0}catch(r){console.error("[ww-messenger] feedback failed",r)}finally{this.feedbackBusy=!1}}}}},Qo={key:0,class:"wm-loading","aria-busy":"true","aria-live":"polite"},Zo={key:0,class:"wm-state"},es={class:"wm-state__err"},ts={class:"wm-state__errSub"},ns={class:"wm-bottom"},rs={key:0,ref:"floatEl",class:"wm-float"},os={key:1,class:"wm-actionWait",role:"status","aria-live":"polite"},ss={class:"wm-actionWait__lbl"},as={key:1,class:"wm-attached"},is=["onClick"];function ls(n,t,r,a,s,o){const i=e.resolveComponent("Launcher"),l=e.resolveComponent("Header"),p=e.resolveComponent("Onboarding"),g=e.resolveComponent("MessageList"),f=e.resolveComponent("ApprovalCard"),C=e.resolveComponent("FormCard"),V=e.resolveComponent("Feedback"),b=e.resolveComponent("SuggestionChips"),x=e.resolveComponent("Composer"),B=e.resolveComponent("MoreMenu"),T=e.resolveComponent("HistoryDrawer");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["wm-root",`wm-root--${r.displayMode}`])},[!s.isOpen&&!o.isEmbedded?(e.openBlock(),e.createBlock(i,{key:0,"unread-count":o.unreadCount,peek:o.launcherPeek,onOpen:o.openFromPeek,onDismiss:t[0]||(t[0]=S=>s.labelDismissed=!0)},null,8,["unread-count","peek","onOpen"])):e.createCommentVNode("",!0),s.isOpen||o.isEmbedded?(e.openBlock(),e.createElementBlock("section",{key:1,class:e.normalizeClass(["wm-panel",`wm-panel--${r.displayMode}`]),style:e.normalizeStyle(s.floatHeight?{"--wm-float-h":s.floatHeight+"px"}:null),role:"dialog","aria-label":"Messenger"},[!o.ready&&!o.error?(e.openBlock(),e.createElementBlock("div",Qo,[o.isEmbedded?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"wm-loading__close","aria-label":"Réduire",onClick:t[1]||(t[1]=(...S)=>o.close&&o.close(...S))},[...t[6]||(t[6]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])])),t[7]||(t[7]=e.createElementVNode("div",{class:"wm-loading__spinner","aria-hidden":"true"},null,-1))])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createVNode(l,{title:o.headerTitle,escalated:o.isEscalated,"agent-name":o.humanAgentName,"agent-avatar-url":o.humanAgentAvatarUrl,"team-members":o.teamMembers,"response-label":o.responseLabel,"show-identity":!!o.currentConv,"show-back":o.canBack,"show-close":!o.isEmbedded,"more-active":s.moreOpen,onBack:o.goHome,onMore:o.toggleMore,onClose:o.close},null,8,["title","escalated","agent-name","agent-avatar-url","team-members","response-label","show-identity","show-back","show-close","more-active","onBack","onMore","onClose"]),o.error?(e.openBlock(),e.createElementBlock("div",Zo,[e.createElementVNode("div",es,[t[9]||(t[9]=e.createElementVNode("div",{class:"wm-state__errIcon"},[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})])],-1)),e.createElementVNode("div",null,[t[8]||(t[8]=e.createElementVNode("div",{class:"wm-state__errTitle"},"Connexion impossible",-1)),e.createElementVNode("div",ts,e.toDisplayString(o.error),1)])])])):o.currentConv?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createVNode(g,{ref:"messageList",messages:o.displayedMessages,"streaming-active":o.streamingActive,"date-label":o.dateLabel,"conversation-id":o.currentConv?o.currentConv.id:null,"loading-more":o.paginationState.loading,"has-more":o.paginationState.hasMore,onLoadMore:o.onLoadMore},null,8,["messages","streaming-active","date-label","conversation-id","loading-more","has-more","onLoadMore"]),e.createElementVNode("div",ns,[o.floatVisible?(e.openBlock(),e.createElementBlock("div",rs,[o.approvalReady?(e.openBlock(),e.createBlock(f,{key:0,action:o.approvalTitle,detail:o.approvalDetail,callbacks:o.pendingApproval.callbacks,onCallback:o.onApprovalCallback},null,8,["action","detail","callbacks","onCallback"])):o.pendingForm?(e.openBlock(),e.createBlock(C,{key:o.pendingForm.message&&o.pendingForm.message.id,form:o.pendingForm.form,onSubmit:o.onFormSubmit},null,8,["form","onSubmit"])):o.showFeedback?(e.openBlock(),e.createBlock(V,{key:2,busy:s.feedbackBusy,done:s.feedbackDone,onSubmit:o.onFeedback},null,8,["busy","done","onSubmit"])):(e.openBlock(),e.createBlock(b,{key:3,items:o.suggestions,onSelect:o.onSuggestion},null,8,["items","onSelect"]))],512)):e.createCommentVNode("",!0),o.actionInFlight?(e.openBlock(),e.createElementBlock("div",os,[t[10]||(t[10]=e.createElementVNode("span",{class:"wm-actionWait__spinner","aria-hidden":"true"},null,-1)),e.createElementVNode("span",ss,e.toDisplayString(o.actionInFlightName)+" en cours, veuillez patienter…",1)])):(e.openBlock(),e.createBlock(x,{key:2,ref:"composer",modelValue:s.draft,"onUpdate:modelValue":t[2]||(t[2]=S=>s.draft=S),placeholder:o.composerPlaceholder,disabled:!!o.pendingApproval,"attach-label":"Joindre un fichier",onSend:o.onSend,onAttach:o.onAttach},null,8,["modelValue","placeholder","disabled","onSend","onAttach"]))]),s.moreOpen?(e.openBlock(),e.createBlock(B,{key:0,"can-rename":!!o.currentConv,"can-clear":!!o.currentConv,"can-export":!!o.currentConv,"notif-enabled":s.notifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:t[3]||(t[3]=S=>s.moreOpen=!1),onNotifToggle:o.onNotifToggle,onAction:o.onMoreAction},null,8,["can-rename","can-clear","can-export","notif-enabled","status-url","help-url","onNotifToggle","onAction"])):e.createCommentVNode("",!0),s.pendingAttachments.length?(e.openBlock(),e.createElementBlock("div",as,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.pendingAttachments,(S,I)=>(e.openBlock(),e.createElementBlock("div",{key:I,class:"wm-attached__chip"},[t[12]||(t[12]=e.createElementVNode("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"},[e.createElementVNode("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)),e.createElementVNode("span",null,e.toDisplayString(S.name),1),e.createElementVNode("button",{type:"button","aria-label":"Retirer",onClick:$=>s.pendingAttachments.splice(I,1)},[...t[11]||(t[11]=[e.createElementVNode("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"},[e.createElementVNode("path",{d:"M18 6L6 18M6 6l12 12"})],-1)])],8,is)]))),128))])):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createBlock(p,{key:1,"welcome-message":o.widgetWelcomeMessage,"agent-name":o.agentName,"quick-links":o.quickLinks,"unread-threads":o.unreadThreads,busy:s.busy,onStart:o.startConv,onSelect:o.onQuickLink,onResume:o.onDrawerPick},null,8,["welcome-message","agent-name","quick-links","unread-threads","busy","onStart","onSelect","onResume"])),s.historyOpen?(e.openBlock(),e.createBlock(T,{key:3,conversations:o.drawerConversations,"active-id":o.currentConv?o.currentConv.id:null,onClose:t[4]||(t[4]=S=>s.historyOpen=!1),onNew:o.onDrawerNew,onPick:o.onDrawerPick},null,8,["conversations","active-id","onNew","onPick"])):e.createCommentVNode("",!0),s.moreOpen&&!o.currentConv?(e.openBlock(),e.createBlock(B,{key:4,"can-rename":!1,"can-clear":!1,"can-export":!1,"notif-enabled":s.notifEnabled,"status-url":o.statusUrl,"help-url":o.helpUrl,onClose:t[5]||(t[5]=S=>s.moreOpen=!1),onNotifToggle:o.onNotifToggle,onAction:o.onMoreAction},null,8,["notif-enabled","status-url","help-url","onNotifToggle","onAction"])):e.createCommentVNode("",!0)],64))],6)):e.createCommentVNode("",!0)],2)}const Te=N(Xo,[["render",ls],["__scopeId","data-v-da51a155"]]);exports.AIAvatar=D;exports.AVATAR_COLORS=j;exports.ActionResult=_e;exports.ApprovalCard=Ve;exports.ArtifactFormResponse=he;exports.ArtifactInfoCard=pe;exports.ArtifactRenderer=te;exports.ArtifactTicket=fe;exports.AttachmentPreview=ve;exports.Bubble=ge;exports.Composer=Be;exports.Feedback=Se;exports.FormCard=Ae;exports.Header=ue;exports.HistoryDrawer=Me;exports.HumanAvatar=Z;exports.Launcher=ce;exports.MEDIA_RECORDER_SUPPORTED=H;exports.MessageList=ke;exports.Messenger=Te;exports.MoreMenu=xe;exports.Onboarding=me;exports.SCREEN_CAPTURE_SUPPORTED=F;exports.SuggestionChips=Ne;exports.TeamAvatars=de;exports.Typing=ye;exports.avatarColor=J;exports.avatarInitials=X;exports.captureScreenshotFile=Ee;exports.colors=A;exports.createStore=ie;exports.createTransport=ae;exports.default=Te;exports.formatTime=Q;exports.guessAttachmentKind=ar;exports.pickRecorderMime=we;exports.renderMarkdown=ee;exports.startScreenRecording=Ce;exports.tokensCss=le;exports.uuid=Y;exports.v4=Y;