@nexlylab/widget 1.32.17 → 1.32.18

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.
Files changed (66) hide show
  1. package/dist/INSTALL.txt +1 -1
  2. package/dist/runtime/{1.32.17/chunks/ClickToLoadEmbed-D9eMaBG8-r9dN9klo.js → 1.32.18/chunks/ClickToLoadEmbed-BLIUFZOn-BwY-LAJ8.js} +2 -2
  3. package/dist/runtime/{1.32.17/chunks/PanelInfoVideo-DMU0-9Az-BrU-Qlul.js → 1.32.18/chunks/PanelInfoVideo-BNVzih9J-BrU-Qlul.js} +1 -1
  4. package/dist/runtime/{1.32.17/chunks/assistant-link-components-D0uKk8Hv-xEDu0ls0.js → 1.32.18/chunks/assistant-link-components-DUrLEPUB-DKaQavIJ.js} +2 -2
  5. package/dist/runtime/{1.32.17/chunks/assistant-link-policy-CogLpq-3-Cc-yj-a-.js → 1.32.18/chunks/assistant-link-policy-DHB-k1Aa-Cc-yj-a-.js} +1 -1
  6. package/dist/runtime/{1.32.17/chunks/block-rating-BgOeTm52-CoiP5C2K.js → 1.32.18/chunks/block-rating-D7hR2gTc-CoiP5C2K.js} +1 -1
  7. package/dist/runtime/{1.32.17/chunks/external-url-ninK7gY9-CJQjg_od.js → 1.32.18/chunks/external-url-qbs1SznX-CJQjg_od.js} +1 -1
  8. package/dist/runtime/{1.32.17/chunks/index-DsQ3ssZW-DbuSZfeK.js → 1.32.18/chunks/index--xfG4CIn-DbuSZfeK.js} +1 -1
  9. package/dist/runtime/{1.32.17/chunks/index-CHUW1nlj-DAdxCQyi.js → 1.32.18/chunks/index-7N5M1HdS-DAdxCQyi.js} +1 -1
  10. package/dist/runtime/{1.32.17/chunks/index-CaHbIY6I-QeFj7CR9.js → 1.32.18/chunks/index-99heIIoH-QeFj7CR9.js} +1 -1
  11. package/dist/runtime/{1.32.17/chunks/index-D3OBLy0s-k8E4HOBM.js → 1.32.18/chunks/index-B3DeMFo7-BbdAbuAw.js} +2 -2
  12. package/dist/runtime/{1.32.17/chunks/index-ByEsnceF-CSQQTbsg.js → 1.32.18/chunks/index-BIGVEl9--CSQQTbsg.js} +1 -1
  13. package/dist/runtime/{1.32.17/chunks/index-zmuItIIf-oy07dUaV.js → 1.32.18/chunks/index-BKZyJMr2-oy07dUaV.js} +1 -1
  14. package/dist/runtime/{1.32.17/chunks/index-D6YQ4lFv-pbKZ0WGs.js → 1.32.18/chunks/index-BKrM_uoq-CABL-0v-.js} +2 -2
  15. package/dist/runtime/{1.32.17/chunks/index-BWMbr4oS-Dsa9X9U7.js → 1.32.18/chunks/index-BX6ig9BJ-Dsa9X9U7.js} +1 -1
  16. package/dist/runtime/{1.32.17/chunks/index-B0-9mIbB-DP0QKkgf.js → 1.32.18/chunks/index-BZO9Qaiw-DP0QKkgf.js} +1 -1
  17. package/dist/runtime/{1.32.17/chunks/index-CSDD7Z6C-BpgnWlB8.js → 1.32.18/chunks/index-BauMKr5c-BpgnWlB8.js} +1 -1
  18. package/dist/runtime/{1.32.17/chunks/index-DzCfV77F-C1BzRUwZ.js → 1.32.18/chunks/index-Bf_npmqm-C1BzRUwZ.js} +1 -1
  19. package/dist/runtime/{1.32.17/chunks/index-Dwtd4id8-CiRb-0NX.js → 1.32.18/chunks/index-BtkNePSj-CiRb-0NX.js} +1 -1
  20. package/dist/runtime/{1.32.17/chunks/index-B97ASd4H-ZRnEJoQe.js → 1.32.18/chunks/index-C1Fa-E3e-ZRnEJoQe.js} +1 -1
  21. package/dist/runtime/{1.32.17/chunks/index-CIFQrVkq-DUgMllqN.js → 1.32.18/chunks/index-C5RVj6y1-DUgMllqN.js} +1 -1
  22. package/dist/runtime/{1.32.17/chunks/index-Ba5nbqA8-B620AdXN.js → 1.32.18/chunks/index-CCEWGjHV-BTsOZg4v.js} +2 -2
  23. package/dist/runtime/{1.32.17/chunks/index-D3fwWbIM-BcW8HKb8.js → 1.32.18/chunks/index-CF37rhgu-BcW8HKb8.js} +1 -1
  24. package/dist/runtime/{1.32.17/chunks/index-CtNAXlUH-DQBGsPwB.js → 1.32.18/chunks/index-COTfVuju-DQBGsPwB.js} +1 -1
  25. package/dist/runtime/{1.32.17/chunks/index-1JK_DoDz-D6wzHiS0.js → 1.32.18/chunks/index-COfQIa8G-D6wzHiS0.js} +1 -1
  26. package/dist/runtime/{1.32.17/chunks/index-BlGeDG8W-CoI3p0S7.js → 1.32.18/chunks/index-CSRoJRaW-CoI3p0S7.js} +1 -1
  27. package/dist/runtime/{1.32.17/chunks/index-CpCgmp7C-C9wFr7fa.js → 1.32.18/chunks/index-CV2tGt-4-C9wFr7fa.js} +1 -1
  28. package/dist/runtime/{1.32.17/chunks/index-D30-Ox5Z-BLxOZxZv.js → 1.32.18/chunks/index-CYeJYTiB-BLxOZxZv.js} +1 -1
  29. package/dist/runtime/{1.32.17/chunks/index-_R8QyLD7-TEMHje2B.js → 1.32.18/chunks/index-CZ-JrY2X-TEMHje2B.js} +1 -1
  30. package/dist/runtime/{1.32.17/chunks/index-BsUIWTU6-BQ7DWJhg.js → 1.32.18/chunks/index-Cd1-jHFp-Za3SKEQp.js} +2 -2
  31. package/dist/runtime/{1.32.17/chunks/index-C5olj-Fr-C3bBvEcm.js → 1.32.18/chunks/index-Ce9TuEzb-C3bBvEcm.js} +1 -1
  32. package/dist/runtime/{1.32.17/chunks/index-DIMi29lU-3B-eE3K7.js → 1.32.18/chunks/index-D1YmJ3gf-3B-eE3K7.js} +1 -1
  33. package/dist/runtime/{1.32.17/chunks/index-DnDMirl9-Dp5AxBD4.js → 1.32.18/chunks/index-D96sEJQ6-Dp5AxBD4.js} +1 -1
  34. package/dist/runtime/{1.32.17/chunks/index-CPjLHywY-DBhSkJ7i.js → 1.32.18/chunks/index-DAICBUgn-DBhSkJ7i.js} +1 -1
  35. package/dist/runtime/{1.32.17/chunks/index-DAJM_cb9-VhJcCfAC.js → 1.32.18/chunks/index-DATkkw3P-VhJcCfAC.js} +1 -1
  36. package/dist/runtime/{1.32.17/chunks/index-CM0iRJSw-pkywvGDF.js → 1.32.18/chunks/index-DaW9uf4--pkywvGDF.js} +1 -1
  37. package/dist/runtime/{1.32.17/chunks/index-C_zmepmr-H31PHMqm.js → 1.32.18/chunks/index-DiZcd1hz-H31PHMqm.js} +1 -1
  38. package/dist/runtime/{1.32.17/chunks/index-D5EHdeyl-_M0CWPEY.js → 1.32.18/chunks/index-DuPFNKhZ-_M0CWPEY.js} +1 -1
  39. package/dist/runtime/{1.32.17/chunks/index-DAai_PkG-Dr1V6OGz.js → 1.32.18/chunks/index-Dw7QeZq3-Dr1V6OGz.js} +1 -1
  40. package/dist/runtime/{1.32.17/chunks/index-DDHI4Kxr-DrVjDDba.js → 1.32.18/chunks/index-E59S8-Gw-CovGUxIZ.js} +2 -2
  41. package/dist/runtime/{1.32.17/chunks/index-Ce0ahORn-bdo5pwX-.js → 1.32.18/chunks/index-OcrS6o5Y-bdo5pwX-.js} +1 -1
  42. package/dist/runtime/{1.32.17/chunks/index-Bl_8GpS0-CahNhEcx.js → 1.32.18/chunks/index-PxSB6BA6-DFxY6dqO.js} +2 -2
  43. package/dist/runtime/{1.32.17/chunks/index-Wza_7CGb-W1lJrIDD.js → 1.32.18/chunks/index-cCAzBYyN-W1lJrIDD.js} +1 -1
  44. package/dist/runtime/{1.32.17/chunks/index-DzHo_iNR-Dm9kbc85.js → 1.32.18/chunks/index-kAGaGinD-Dm9kbc85.js} +1 -1
  45. package/dist/runtime/{1.32.17/chunks/index-BDhTixUR-Aqz1AnQ5.js → 1.32.18/chunks/index-l8Oxwea3-Aqz1AnQ5.js} +1 -1
  46. package/dist/runtime/{1.32.17/chunks/index-DMM00SC5-R_xuAEQV.js → 1.32.18/chunks/index-oxM4Cgtc-R_xuAEQV.js} +1 -1
  47. package/dist/runtime/{1.32.17/chunks/index-BJxJr5j5-C_0Ll4qr.js → 1.32.18/chunks/index-qN6oEHVu-C_0Ll4qr.js} +1 -1
  48. package/dist/runtime/{1.32.17/chunks/index-D0qsMexH-I68tb-d3.js → 1.32.18/chunks/index-rblri-2U-I68tb-d3.js} +1 -1
  49. package/dist/runtime/1.32.18/chunks/index-xx1GG5d1-CW29F9vY.js +6 -0
  50. package/dist/runtime/{1.32.17 → 1.32.18}/nexly.js +5 -5
  51. package/dist/v1.js +1 -1
  52. package/package.json +1 -1
  53. package/dist/runtime/1.32.17/chunks/index-tapacGlG--YMQ21rc.js +0 -6
  54. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/PanelVideoOverlay-BY__oBYV-B8OPC1xh.js +0 -0
  55. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/_commonjsHelpers-C6fGbg64-BC8KDfbh.js +0 -0
  56. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/accent-legibility-BJF2VO5n-CDPQ7suO.js +0 -0
  57. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/allowed-elements-BXnLJV1S-C-_lr2zm.js +0 -0
  58. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/block-helpers-Cg_zAqG6-DnN2COvk.js +0 -0
  59. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index-BPDIV1BN-DINkyYvc.js +0 -0
  60. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index-BcsmWDTX-Dw9WA5Ac.js +0 -0
  61. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index-C262wwK4-DpyhuXqd.js +0 -0
  62. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index-DMQkz1bV-BuMYksln.js +0 -0
  63. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index-DZADUAKv-DPfvWVuj.js +0 -0
  64. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/index.modern-CioVZ357-BA5NTOmY.js +0 -0
  65. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/inert-assistant-components-B6Cx9pG5-DWb6n3Yq.js +0 -0
  66. /package/dist/runtime/{1.32.17 → 1.32.18}/chunks/use-deferred-rating-XlgCUwcY-DDVOwURi.js +0 -0
package/dist/v1.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function(){"use strict";(function(){var y;const l=document.currentScript;if(!l||window.Nexly)return;const n=e=>l.getAttribute(`data-${e}`),m=()=>{try{return new URL(l.src,location.href).href.replace(/\/[^/]*$/,"")}catch{return""}},u=n("api-key");if(!u){console.error(`[Nexly] Brak data-api-key na tagu skryptu.
2
- Skopiuj gotowy snippet z panelu (Produkt → Instalacja) — klucz jest w nim już wpisany.`);return}const o={apiKey:u,server:n("server")||"https://e-commerce-studio.nexlylab.dev",theme:n("theme")||"system",position:n("position")||"bottom-right",version:n("version")||"1.32.17",cdn:n("cdn")||m()||"https://cdn.jsdelivr.net/npm/@nexlylab/widget@1.32.17/dist",preload:n("preload")||"hover",debug:n("debug")!==null||/[?&]nexly-debug=1/.test(location.search)},c=(...e)=>{o.debug&&console.info("[Nexly]",...e)},p=[];let i=null;const w=function(e){if(i)return i(e);p.push(e)};window.Nexly=w;for(const e of[o.cdn,o.server])try{const t=document.createElement("link");t.rel="preconnect",t.href=new URL(e,location.href).origin,t.crossOrigin="",document.head.appendChild(t)}catch{}document.addEventListener("securitypolicyviolation",e=>{const t=e.blockedURI||"";/nexlylab|elevenlabs|livekit|maps\.googleapis/.test(t)&&console.error(`[Nexly] CSP tej strony zablokowało ${t}
2
+ Skopiuj gotowy snippet z panelu (Produkt → Instalacja) — klucz jest w nim już wpisany.`);return}const o={apiKey:u,server:n("server")||"https://e-commerce-studio.nexlylab.dev",theme:n("theme")||"system",position:n("position")||"bottom-right",version:n("version")||"1.32.18",cdn:n("cdn")||m()||"https://cdn.jsdelivr.net/npm/@nexlylab/widget@1.32.18/dist",preload:n("preload")||"hover",debug:n("debug")!==null||/[?&]nexly-debug=1/.test(location.search)},c=(...e)=>{o.debug&&console.info("[Nexly]",...e)},p=[];let i=null;const w=function(e){if(i)return i(e);p.push(e)};window.Nexly=w;for(const e of[o.cdn,o.server])try{const t=document.createElement("link");t.rel="preconnect",t.href=new URL(e,location.href).origin,t.crossOrigin="",document.head.appendChild(t)}catch{}document.addEventListener("securitypolicyviolation",e=>{const t=e.blockedURI||"";/nexlylab|elevenlabs|livekit|maps\.googleapis/.test(t)&&console.error(`[Nexly] CSP tej strony zablokowało ${t}
3
3
  Naruszona dyrektywa: ${e.violatedDirective}
4
4
  Gotowy blok CSP do wklejenia: ${o.server}/install/csp?key=${o.apiKey.slice(0,11)}`)});function b(e){const t=document.createElement("button");return t.type="button",t.id="nexly-launcher",t.setAttribute("aria-label","Otwórz czat"),t.style.cssText=["position:fixed","bottom:20px",o.position==="bottom-left"?"left:20px":"right:20px","width:80px","height:80px","border-radius:50%","border:none","cursor:pointer","display:flex","align-items:center","justify-content:center","background:#1c1c1e","color:#f4c95d","box-shadow:0 4px 16px rgba(0,0,0,.28)","z-index:2147483000","padding:0","transition:transform .2s ease"].join(";"),t.innerHTML='<svg width="34" height="34" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 9 9 0 0 1-3.5-.7L3 21l1.9-5a8.2 8.2 0 0 1-.9-3.7 8.4 8.4 0 0 1 8.5-8.3 8.4 8.4 0 0 1 8.5 8z" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',t.addEventListener("click",e),document.body.appendChild(t),t}let s=null,a=!1;function d(e){if(i)return e==null?void 0:e();if(a)return;a=!0;const t=`${o.cdn.replace(/\/$/,"")}/runtime/${o.version}/nexly.js`,g=performance.now(),r=document.createElement("script");r.src=t,r.type="module",r.async=!0,r.crossOrigin="anonymous",r.onload=()=>{const f=window.__nexlyRuntime;if(!f){console.error(`[Nexly] Runtime wczytany z ${t}, ale nie zarejestrował się poprawnie.`),a=!1;return}i=f({...o,initialOpen:!0}),c(`runtime gotowy w ${Math.round(performance.now()-g)} ms`),s==null||s.remove();for(const x of p.splice(0))i(x);e==null||e()},r.onerror=()=>{a=!1,console.error(`[Nexly] Nie udało się wczytać runtime z ${t}
5
5
  Sprawdź, czy CSP tej strony zezwala na script-src z tego adresu.`)},document.head.appendChild(r),c("pobieram runtime",t)}s=b(()=>d(()=>{var e;return(e=window.Nexly)==null?void 0:e.call(window,"open")})),o.preload==="hover"?s.addEventListener("pointerenter",()=>d(),{once:!0}):o.preload==="idle"&&((y=window.requestIdleCallback)!=null?y:(t=>window.setTimeout(t,2e3)))(()=>d()),c("loader gotowy",{version:o.version,server:o.server,preload:o.preload})})()})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexlylab/widget",
3
- "version": "1.32.17",
3
+ "version": "1.32.18",
4
4
  "description": "Agent AI na dowolnej stronie w jednej linijce HTML. Bez builda, bez frameworka, bez konfiguracji.",
5
5
  "license": "MIT",
6
6
  "author": "NexlyLab",
@@ -1,6 +0,0 @@
1
- import{r as s,j as t,a as kt,b as Te,Q as ts,_ as Ws,t as Xs}from"../nexly.js";import{H as Js,P as Vs}from"./use-deferred-rating-XlgCUwcY-DDVOwURi.js";import{j as Ys}from"./PanelInfoVideo-DMU0-9Az-BrU-Qlul.js";import{x as Zs,s as Gs,c as en,a as tn}from"./allowed-elements-BXnLJV1S-C-_lr2zm.js";import{f as sn}from"./assistant-link-components-D0uKk8Hv-xEDu0ls0.js";import{j as nn,X as an}from"./ClickToLoadEmbed-D9eMaBG8-r9dN9klo.js";import"./_commonjsHelpers-C6fGbg64-BC8KDfbh.js";import"./assistant-link-policy-CogLpq-3-Cc-yj-a-.js";const ca={slug:"support-chat",name:"Support Chat",version:"1.0.0",category:"interactive",requiredService:"support-chat",configSchema:{properties:{voiceEnabled:{type:"boolean",default:!0},voiceConversationEnabled:{type:"boolean",default:!1},voiceReadAloudEnabled:{type:"boolean",default:!1},welcomeMessage:{type:"string",default:""},headerTitle:{type:"string",default:""},placeholder:{type:"string",default:""},showSuggestedQuestions:{type:"boolean",default:!0},suggestedQuestions:{type:"array",items:{type:"string"},default:[]},escalationLabel:{type:"string",default:""},humanHandoffButton:{type:"boolean",default:!1}}},defaultConfig:{voiceEnabled:!0,voiceConversationEnabled:!1,voiceReadAloudEnabled:!1,welcomeMessage:"",headerTitle:"",placeholder:"",showSuggestedQuestions:!0,suggestedQuestions:[],escalationLabel:"",humanHandoffButton:!1},dataContract:{serviceSlug:"support-chat",inputSchema:{type:"object",properties:{answer:{type:"string",description:"AI response text"},confidence:{type:"number",description:"Confidence score 0-1"},sources:{type:"array",items:{type:"object",properties:{title:{type:"string"},url:{type:"string"},excerpt:{type:"string"}}},description:"Source citations for the answer"}},required:["answer"]},previewDataOverride:{answer:"Our return policy allows returns within 30 days of purchase. Items must be in original condition with tags attached.",confidence:.85,sources:[{title:"Return Policy",url:"/policies/returns",excerpt:"Returns accepted within 30 days."}]}},fields:[{id:"voiceConversationEnabled",type:"toggle",label:"Voice conversation (live)",default:!1,group:"Voice"},{id:"voiceReadAloudEnabled",type:"toggle",label:"Read messages aloud",default:!1,group:"Voice"},{id:"headerTitle",type:"localized-text",label:"Header title",default:"",placeholder:'Leave empty to use translated default (e.g. "Support")',group:"Content"},{id:"welcomeMessage",type:"localized-text",label:"Welcome message",default:"",placeholder:'Leave empty to use translated default (e.g. "Hi! How can I help you today?")',group:"Content"},{id:"placeholder",type:"localized-text",label:"Input placeholder",default:"",placeholder:'Leave empty to use translated default (e.g. "Ask a question...")',group:"Content"},{id:"escalationLabel",type:"text",label:"Escalation button label",default:"",placeholder:'Leave empty to use translated default (e.g. "Contact Support")',group:"Content"},{id:"humanHandoffButton",type:"toggle",label:'Show "Human" button',default:!1,group:"Behavior"},{id:"showSuggestedQuestions",type:"toggle",label:"Show suggested questions",default:!0,group:"Behavior"},{id:"suggestedQuestions",type:"json",label:"Suggested questions",default:[],placeholder:'["What is your return policy?", "Do you ship internationally?"]',group:"Behavior"}],events:{emits:[{name:"support-chat:messageSent",description:"User sent a message"},{name:"support-chat:escalated",description:"User requested escalation to human support"},{name:"support-chat:feedbackSubmitted",description:"User rated helpfulness of answer"}],listens:[{name:"support-chat:clearHistory",description:"Clear chat history"}]},sizing:{minWidth:280,preferredHeight:"fill",scrollable:!0},supportedPlacements:["main","sidebar","fullscreen"]};function ss({text:n,allowedLinkHosts:a}){return t.jsx("div",{className:"es-sc__bubble-text es-sc__bubble-text--md",children:t.jsx(Zs,{remarkPlugins:[...en],allowedElements:[...Gs],transformLinkUri:o=>tn(o)??"",transformImageUri:()=>"",components:{input:({node:o,type:i,checked:l,...f})=>i==="checkbox"?t.jsx("input",{...f,type:"checkbox",checked:!!l,disabled:!0,readOnly:!0,className:"es-sc__md-task"}):null,...sn({allowedHosts:a})},children:n})})}function rn({media:n,t:a}){const{embeds:o,images:i}=n;return o.length===0&&i.length===0?null:t.jsxs("div",{className:"es-sc__media","data-testid":"support-chat-media",children:[o.map(l=>t.jsx(an,{embed:l,t:a,classPrefix:"es-sc"},`${l.provider}:${l.id}`)),i.map(l=>t.jsx("img",{className:"es-sc__media-img",src:l.src,alt:l.alt||a("support_chat.media_image_alt"),loading:"lazy",decoding:"async",referrerPolicy:"no-referrer"},l.src))]})}function wt(n){return n?n.join(","):""}const on=s.memo(function({text:n,allowEmbeds:a,allowedImageHosts:o,t:i}){const l=wt(o),f=s.useMemo(()=>nn(n,{allowEmbeds:a,allowedImageHosts:o}),[n,a,l]);return t.jsx(rn,{media:f,t:i})},(n,a)=>n.text===a.text&&n.allowEmbeds===a.allowEmbeds&&n.t===a.t&&wt(n.allowedImageHosts)===wt(a.allowedImageHosts));function cn(n,a){const o=Math.round((Date.now()-n.getTime())/1e3);if(o<60)return a("time.just_now");const i=Math.round(o/60);if(i<60)return a("time.minutes_ago",{count:i});const l=Math.round(i/60);if(l<24)return a("time.hours_ago",{count:l});const f=Math.round(l/24);return a("time.days_ago",{count:f})}function us({card:n,t:a,onSelect:o}){const i=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"es-sc__ticket-card-head",children:[t.jsxs("span",{className:"es-sc__ticket-card-number",children:["#",n.externalNumber]}),t.jsx("span",{className:`es-sc__ticket-card-status es-sc__ticket-card-status--${n.status}`,children:a(`escalation.status_${n.status}`)})]}),n.summary&&t.jsx("p",{className:"es-sc__ticket-card-summary",title:n.summary,children:n.summary}),t.jsxs("p",{className:"es-sc__ticket-card-meta",children:[cn(new Date(n.createdAt),a),n.priority?` · ${a(`support_chat.priority_${n.priority}`)}`:""]})]});if(o&&n.sessionId){const l=n.sessionId;return t.jsx("button",{type:"button",className:"es-sc__ticket-card es-sc__ticket-card--clickable",onClick:()=>o(l),"aria-label":a("support_chat.open_ticket_conversation"),title:a("support_chat.open_ticket_conversation"),children:i})}return t.jsx("div",{className:"es-sc__ticket-card",children:i})}const ln=[{value:"open",key:"support_chat.filter_open"},{value:"closed",key:"support_chat.filter_closed"},{value:"all",key:"support_chat.filter_all"}];function un(n){const{status:a,loading:o,tickets:i,onSelectStatus:l,onSelectSession:f,t:v}=n;return t.jsxs("div",{className:"es-sc__tickets-view",children:[t.jsx("div",{className:"es-sc__tickets-filters",children:ln.map(m=>t.jsx("button",{type:"button",className:`es-sc__tickets-chip${a===m.value?" es-sc__tickets-chip--active":""}`,onClick:()=>l(m.value),children:v(m.key)},m.value))}),t.jsx("div",{className:"es-sc__tickets-view-list",children:o?t.jsx("p",{className:"es-sc__tickets-empty",role:"status","aria-live":"polite",children:"…"}):i.length===0?t.jsx("p",{className:"es-sc__tickets-empty",children:v("support_chat.tickets_empty")}):i.map(m=>t.jsx(us,{card:m,t:v,onSelect:f},m.externalNumber))})]})}const dn=["audio/webm;codecs=opus","audio/webm","audio/mp4"];function pn(){return typeof navigator>"u"||typeof window>"u"?!1:typeof navigator.mediaDevices?.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function fn(){if(typeof window>"u"||typeof window.MediaRecorder>"u")return;const n=typeof window.MediaRecorder.isTypeSupported=="function";for(const a of dn)if(!n||window.MediaRecorder.isTypeSupported(a))return a}function hn({baseUrl:n,apiKey:a,jwt:o,language:i,onTranscript:l,t:f,disabled:v=!1,streaming:m,voiceStream:g,baseText:b,onText:r}){const[p]=s.useState(pn),[_,k]=s.useState("idle"),[w,E]=s.useState(null),[U,H]=s.useState("idle"),x=!!(m&&g&&b&&r),T=s.useRef(null),ee=s.useRef(null),X=s.useRef([]),J=s.useRef(!0);s.useEffect(()=>()=>{J.current=!1},[]);const ce=s.useRef({baseUrl:n,apiKey:a,jwt:o,language:i,onTranscript:l});s.useEffect(()=>{ce.current={baseUrl:n,apiKey:a,jwt:o,language:i,onTranscript:l}},[n,a,o,i,l]);const le=s.useCallback(()=>{ee.current?.getTracks().forEach(I=>I.stop()),ee.current=null,T.current=null,X.current=[]},[]);s.useEffect(()=>le,[le]);const R=s.useRef(()=>{});R.current=()=>{x&&(U==="connecting"||U==="listening")&&g?.stop()},s.useEffect(()=>()=>R.current(),[]);const O=s.useCallback(async I=>{const{baseUrl:F,apiKey:V,jwt:Y,language:$,onTranscript:P}=ce.current,te=new FormData;te.append("audio",I,"recording.webm"),te.append("language",$);const ae={};V&&(ae["X-API-Key"]=V),Y&&(ae.Authorization=`Bearer ${Y}`);const ke=await fetch(`${F}/api/widget/transcribe`,{method:"POST",headers:ae,credentials:"include",body:te});if(!ke.ok){const Q=new Error(`HTTP ${ke.status}`);throw Q.status=ke.status,Q}const Ie=await ke.json();P(Ie.text??"")},[]),pe=s.useCallback(async()=>{E(null);let I;try{I=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{k("error"),E("voice.permission_denied");return}const F=fn();let V;try{V=F?new MediaRecorder(I,{mimeType:F}):new MediaRecorder(I)}catch{I.getTracks().forEach(Y=>Y.stop()),k("error"),E("voice.error_generic");return}ee.current=I,T.current=V,X.current=[],V.ondataavailable=Y=>{Y.data&&Y.data.size>0&&X.current.push(Y.data)},V.onstop=async()=>{const Y=V.mimeType||F||"audio/webm",$=new Blob(X.current,{type:Y});if(le(),$.size===0){k("idle");return}k("transcribing");try{if(await O($),!J.current)return;k("idle"),E(null)}catch(P){if(!J.current)return;const te=P.status;k("error"),E(te===413?"voice.error_too_large":"voice.error_generic")}},V.start(),k("recording")},[le,O]),ue=s.useCallback(()=>{const I=T.current;I&&I.state!=="inactive"?I.stop():(le(),k("idle"))},[le]),ne=s.useCallback(()=>{p&&(x?U==="connecting"||U==="listening"?(g.stop(),H("idle")):(E(null),g.start({language:i,baseText:b,onText:r,onState:I=>H(I),onError:I=>{E(I),H("error")}})):_==="recording"?ue():(_==="idle"||_==="error")&&pe())},[p,x,U,_,i,b,r,g,pe,ue]);if(!p)return null;const fe=x?U==="connecting"||U==="listening":_==="recording",he=!x&&_==="transcribing",Oe=x?U==="error":_==="error",xe=f(fe?"voice.stop":"voice.start"),me=w?f(w):he?f("voice.transcribing"):xe,ye=["es-sc__mic",fe&&"es-sc__mic--recording",he&&"es-sc__mic--transcribing",Oe&&"es-sc__mic--error"].filter(Boolean).join(" ");return t.jsx("button",{type:"button",className:ye,onClick:ne,disabled:he||v,"aria-label":xe,"aria-pressed":fe,title:me,children:he?t.jsx("svg",{width:18,height:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"es-sc__mic-spinner","aria-hidden":"true",children:t.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}):fe?t.jsx("svg",{width:18,height:18,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:t.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}):t.jsxs("svg",{width:18,height:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"}),t.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),t.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"22"})]})})}function mn(){return t.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none","aria-hidden":"true",children:t.jsx("path",{d:"M8 5.14v13.72a1 1 0 0 0 1.5.86l11-6.86a1 1 0 0 0 0-1.72l-11-6.86A1 1 0 0 0 8 5.14Z"})})}function gn(){return t.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none","aria-hidden":"true",children:[t.jsx("rect",{x:"6",y:"5",width:"4",height:"14",rx:"1"}),t.jsx("rect",{x:"14",y:"5",width:"4",height:"14",rx:"1"})]})}function _n(){return t.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none","aria-hidden":"true",children:t.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})})}function bn(){return t.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"es-sc__readaloud-spinner","aria-hidden":"true",children:t.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}const vn=s.memo(function({id:n,session:a,onActivate:o,t:i}){const l=a.activeId===n?a.status:"idle",f=s.useCallback(()=>{if(l==="idle"||l==="error"){o();return}l!=="loading"&&a.togglePause()},[l,o,a]),v=s.useCallback(()=>a.stop(),[a]),m=i(l==="playing"?"voice_output.pause":"voice_output.play"),g=l==="error"?i("voice_output.error"):m;return t.jsxs("span",{className:"es-sc__readaloud-group",children:[t.jsx("button",{type:"button",className:["es-sc__readaloud-btn",l==="playing"&&"es-sc__readaloud-btn--playing",l==="paused"&&"es-sc__readaloud-btn--paused",l==="error"&&"es-sc__readaloud-btn--error"].filter(Boolean).join(" "),onClick:f,disabled:l==="loading","aria-label":m,"aria-pressed":l==="playing",title:g,children:l==="loading"?t.jsx(bn,{}):l==="playing"?t.jsx(gn,{}):t.jsx(mn,{})}),(l==="playing"||l==="paused")&&t.jsx("button",{type:"button",className:"es-sc__readaloud-btn es-sc__readaloud-btn--stop",onClick:v,"aria-label":i("voice_output.stop"),title:i("voice_output.stop"),children:t.jsx(_n,{})})]})});function xn(n){let a=null,o=0,i=null;const l=new Set,f={ended:new Set},v=g=>{for(const b of[...f[g]])b()},m=g=>{g.onended=null,Xs(()=>g.stop())};return{push(g){const b=new Uint8Array(g);let r;i&&i.length>0?(r=new Uint8Array(i.length+b.length),r.set(i,0),r.set(b,i.length),i=null):r=b;const p=r.length-r.length%2;if(p<r.length&&(i=r.slice(p)),p===0)return;const _=new Int16Array(r.buffer,r.byteOffset,p/2);if(_.length===0)return;a??(a=new AudioContext({sampleRate:n}));const k=a.createBuffer(1,_.length,n);k.getChannelData(0).set(Float32Array.from(_,U=>U/32768));const w=a.createBufferSource();w.buffer=k,w.connect(a.destination),w.onended=()=>{l.delete(w),l.size===0&&v("ended")},l.add(w);const E=Math.max(a.currentTime,o);w.start(E),o=E+k.duration},reset(){for(const g of[...l])m(g);l.clear(),o=0,i=null},pause(){a?.suspend()},resume(){a?.resume()},on(g,b){return f[g].add(b),()=>{f[g].delete(b)}},close(){for(const g of[...l])m(g);l.clear(),a?.close(),a=null,o=0,f.ended.clear()}}}function yn({baseUrl:n,apiKey:a,getJwt:o}){const[i,l]=s.useState(null),[f,v]=s.useState("idle"),m=s.useRef(null),g=s.useRef(null),b=s.useRef([]),r=s.useRef(!1),p=s.useRef(!1),_=s.useRef(!1),k=s.useRef(0),w=s.useRef(null),E=s.useRef(null),U=s.useCallback(()=>{E.current&&(clearTimeout(E.current),E.current=null)},[]),H=s.useCallback(()=>{w.current?.abort(),w.current=null,E.current&&(clearTimeout(E.current),E.current=null),g.current?.close(),g.current=null,b.current=[],r.current=!1,p.current=!1,_.current=!1},[]),x=s.useCallback(()=>{k.current+=1,H(),m.current=null,l(null),v("idle")},[H]),T=s.useCallback(()=>{const R=g.current;R&&v(O=>O==="playing"?(R.pause(),"paused"):O==="paused"?(R.resume(),"playing"):O)},[]),ee=s.useCallback(R=>{if(m.current===R)return;H(),k.current+=1,w.current=new AbortController,m.current=R,l(R),v("loading");const O=k.current;E.current=setTimeout(()=>{O===k.current&&(w.current?.abort(),v("error"))},12e3)},[H]),X=s.useCallback(async R=>{if(!R)return;const O=o?.();await Te(fetch(`${n}/api/widget/read-aloud-play`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"X-API-Key":a}:{},...O?{Authorization:`Bearer ${O}`}:{}},body:JSON.stringify({messageId:R})}))},[n,a,o]),J=s.useCallback((R,O)=>{r.current||(r.current=!0,(async()=>{for(;b.current.length>0;){if(R!==k.current){r.current=!1;return}const pe=b.current.shift();if(!pe)continue;const ue=o?.(),[ne,fe]=await Te(fetch(`${n}/api/widget/read-aloud`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"X-API-Key":a}:{},...ue?{Authorization:`Bearer ${ue}`}:{}},body:JSON.stringify({text:pe,language:O,messageId:m.current??void 0}),signal:w.current?.signal}));if(R!==k.current){r.current=!1;return}if(fe||!ne||!ne.ok||!ne.body){v("error"),r.current=!1;return}const he=ne.headers.get("X-Audio-Encoding");if(he&&he!=="pcm16"){v("error"),r.current=!1;return}if(!g.current){const me=Number(ne.headers.get("X-Audio-Sample-Rate"))||24e3,ye=xn(me);g.current=ye,ye.on("ended",()=>{R===k.current&&(!p.current||b.current.length>0||r.current||x())})}const Oe=g.current,xe=ne.body.getReader();for(;;){const[me,ye]=await Te(xe.read());if(R!==k.current){r.current=!1;return}if(ye){v("error"),r.current=!1;return}const{done:I,value:F}=me;if(I)break;F&&F.byteLength>0&&(Oe.push(F.buffer.slice(F.byteOffset,F.byteOffset+F.byteLength)),_.current||(_.current=!0,U(),v("playing"),X(m.current)))}}r.current=!1,p.current&&!_.current&&R===k.current&&x()})())},[n,a,o,x,X]),ce=s.useCallback((R,O,pe)=>{if(m.current!==R)return;const ue=O.trim();ue&&(b.current.push(ue),J(k.current,pe))},[J]),le=s.useCallback(R=>{m.current===R&&(p.current=!0,b.current.length===0&&!r.current&&!_.current&&x())},[x]);return s.useEffect(()=>()=>x(),[x]),{activeId:i,status:f,activate:ee,feed:ce,finish:le,togglePause:T,stop:x}}const kn=1200;function wn(n={language:"en"}){const{voiceStream:a,language:o,silenceMs:i=kn}=n;let l=null,f=null,v="",m=!1;const g=()=>{f&&clearTimeout(f),f=null},b=()=>{!a||!m||(v="",a.start({language:o,baseText:()=>"",onText:r=>{const p=r.trim();!p||p===v||(v=p,l?.({type:"user_partial",text:p}),g(),f=setTimeout(()=>{const _=v;_&&(v="",l?.({type:"user_final",text:_}),a.stop(),b())},i))},onError:r=>l?.({type:"error",message:r})}))};return{get available(){return!!a},async start({onEvent:r}){if(!a)throw new Error("conversation transport unavailable");l=r,m=!0,b()},stop(){m=!1,g(),v="",a&&a.stop(),l=null}}}function jn(n){let a=null,o=null;return{get available(){return n.enabled&&typeof RTCPeerConnection<"u"},async start({onEvent:i}){o=i;const l={"Content-Type":"application/json","X-API-Key":n.apiKey};n.jwt&&(l.Authorization=`Bearer ${n.jwt}`);const f=n.getSessionId?.()??null,v=await fetch(`${n.baseUrl}/api/widget/realtime-voice`,{method:"POST",headers:l,body:JSON.stringify({language:n.language,...f?{sessionId:f}:{}})});if(!v.ok)throw new Error("eleven token refused");const m=await v.json(),g=m.data?.token;if(m.data?.provider!=="elevenlabs"||!g)throw new Error("not an elevenlabs session");m.data?.sessionId&&n.onSessionId?.(m.data.sessionId);const b=m.data?.endUserToken??"",{Conversation:r}=await Ws(async()=>{const{Conversation:x}=await import("./index-DMQkz1bV-BuMYksln.js");return{Conversation:x}},[]);let p=!1,_=null;const k=.6,w=.35,E=x=>{x!==p&&(p=x,o?.({type:"user_speaking",active:x}))};let U="";const H=x=>{const T=x?.trim();T&&(E(!1),o?.({type:"thinking"}),T!==U&&(U=T,n.onUserTurnEnd?.()))};a=await r.startSession({conversationToken:g,connectionType:"webrtc",customLlmExtraBody:{end_user_token:b},onModeChange:({mode:x})=>{o?.(x==="speaking"?{type:"agent_delta",text:""}:{type:"agent_done"})},onVadScore:({vadScore:x})=>{x>=k?(_&&(clearTimeout(_),_=null),E(!0)):x<=w&&p&&!_&&(_=setTimeout(()=>{_=null,E(!1)},600))},onMessage:({message:x,role:T})=>{const ee=x?.trim();ee&&(T==="user"?H(ee):(n.onTranscript({role:"assistant",text:ee,streaming:!1}),U=""))},onIncomingEvent:x=>{x?.type==="user_transcript"&&H(x.user_transcription_event?.user_transcript)},onAgentTyping:()=>o?.({type:"thinking"}),onAgentChatResponsePart:x=>{const T=x?.text??"";T&&n.onTranscript({role:"assistant",text:T,streaming:!0})},onInterruption:()=>o?.({type:"interrupted"}),onError:x=>{console.warn("[voice] eleven blad:",x),o?.({type:"error",message:"voice_conv.error"})}})},setMuted(i){a?.setMicMuted?.(i)},sendUserMessage(i){const l=i.trim();return!l||!a||(a.sendUserActivity?.(),!a.sendUserMessage)?!1:(a.sendUserMessage(l),!0)},stop(){o=null;const i=a;a=null,i?.endSession()}}}function ns({followUps:n,isNewest:a,isPending:o,hasQuickReplies:i,isSending:l,onSelect:f,t:v}){return!a||o||i||!n||n.length===0?null:t.jsx("div",{className:"es-sc__followups",role:"list","aria-label":v("support_chat.followups_aria"),"data-es-no-read":!0,children:n.map(m=>t.jsx("button",{type:"button",role:"listitem",disabled:l,className:"es-sc__suggestion es-sc__suggestion--followup",onClick:()=>f(m.message),children:m.label},m.message))})}function Cn(n){switch(n){case"OUT_OF_HOURS":return"support_chat.handoff.out_of_hours";case"QUEUE_FULL":return"support_chat.handoff.queue_full";default:return"support_chat.handoff.no_operator_title"}}const jt={email:254,phone:32,note:2e3},Sn={email:"",phone:"",note:""};function Nn(n){const[a,o]=s.useState(()=>Date.now());return s.useEffect(()=>{if(n===null)return;const i=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(i)},[n]),n===null?null:Math.max(0,Math.ceil((n-a)/1e3))}function Rn({status:n,onSubmitContact:a,onDismissContact:o,t:i}){const[l,f]=s.useState(Sn),[v,m]=s.useState(!1),[g,b]=s.useState(null),r=s.useRef(null),p=Nn(n.kind==="waiting"?n.until:null);return s.useEffect(()=>{n.kind==="unavailable"&&r.current?.focus()},[n.kind]),n.kind==="idle"?null:n.kind==="waiting"?t.jsxs("div",{className:"es-sc__handoff es-sc__handoff--waiting",role:"status","aria-live":"polite",children:[t.jsx("span",{className:"es-sc__handoff-dot","aria-hidden":"true"}),t.jsx("span",{className:"es-sc__handoff-text",children:p===null?i("support_chat.handoff.queued"):i("support_chat.handoff.waiting",{seconds:p})})]}):n.kind==="human"?t.jsx("div",{className:"es-sc__handoff es-sc__handoff--human",role:"status","aria-live":"polite",children:t.jsx("span",{className:"es-sc__handoff-text",children:n.displayName?i("support_chat.handoff.human_joined",{name:n.displayName}):i("support_chat.handoff.human_joined_unnamed")})}):n.kind==="contact_left"?t.jsx("div",{className:"es-sc__handoff es-sc__handoff--done",role:"status","aria-live":"polite",children:t.jsx("span",{className:"es-sc__handoff-text",children:i("support_chat.handoff.contact_success")})}):t.jsxs("form",{className:"es-sc__handoff es-sc__handoff--form",onSubmit:async _=>{if(_.preventDefault(),v)return;if(l.email.trim().length===0&&l.phone.trim().length===0){b(i("support_chat.handoff.contact_validation")),r.current?.focus();return}m(!0),b(null);const k=await a({email:l.email.trim(),phone:l.phone.trim(),note:l.note.trim()});m(!1),k||b(i("support_chat.handoff.contact_error"))},noValidate:!0,children:[t.jsx("p",{className:"es-sc__handoff-title",children:i(Cn(n.reason))}),t.jsx("p",{className:"es-sc__handoff-text",children:i("support_chat.handoff.contact_prompt")}),t.jsx("label",{className:"es-sc__handoff-label",htmlFor:"es-sc-handoff-email",children:i("support_chat.handoff.contact_email_label")}),t.jsx("input",{id:"es-sc-handoff-email",ref:r,className:"es-sc__handoff-input",type:"email",autoComplete:"email",maxLength:jt.email,value:l.email,"aria-invalid":g!==null,"aria-describedby":g?"es-sc-handoff-error":void 0,onChange:_=>f(k=>({...k,email:_.target.value}))}),t.jsx("label",{className:"es-sc__handoff-label",htmlFor:"es-sc-handoff-phone",children:i("support_chat.handoff.contact_phone_label")}),t.jsx("input",{id:"es-sc-handoff-phone",className:"es-sc__handoff-input",type:"tel",autoComplete:"tel",maxLength:jt.phone,value:l.phone,onChange:_=>f(k=>({...k,phone:_.target.value}))}),t.jsx("label",{className:"es-sc__handoff-label",htmlFor:"es-sc-handoff-note",children:i("support_chat.handoff.contact_note_label")}),t.jsx("textarea",{id:"es-sc-handoff-note",className:"es-sc__handoff-input es-sc__handoff-textarea",rows:3,maxLength:jt.note,value:l.note,onChange:_=>f(k=>({...k,note:_.target.value}))}),g&&t.jsx("p",{className:"es-sc__handoff-error",id:"es-sc-handoff-error",role:"alert",children:g}),t.jsxs("div",{className:"es-sc__handoff-actions",children:[t.jsx("button",{className:"es-sc__handoff-submit",type:"submit",disabled:v,children:i("support_chat.handoff.contact_submit")}),t.jsx("button",{className:"es-sc__handoff-dismiss",type:"button",onClick:o,children:i("support_chat.handoff.contact_dismiss")})]})]})}const ds="live:";function De(n){return n.id.startsWith(ds)}function En(n,a){return n.text!==a.text?!0:JSON.stringify(n.metadata??null)!==JSON.stringify(a.metadata??null)}function Tn(n,a){if(a.length===0)return n;const o=new Map;n.forEach((b,r)=>o.set(b.id,r));let i=null;const l=[];let f=!1;for(const b of a){const r=o.get(b.id);if(r===void 0){l.push(b),b.role==="assistant"&&(f=!0);continue}const p=n[r];En(p,b)&&(i??(i=[...n]),i[r]={...p,...b})}if(l.length===0)return i??n;const v=i??[...n],m=f?v.filter(b=>!De(b)):v,g=m.filter(De);return[...m.filter(b=>!De(b)),...l,...g]}function In({transport:n,agentId:a,onUserMessage:o,onStopPlayback:i}){const[l,f]=s.useState("idle"),[v,m]=s.useState(null),[g,b]=s.useState(!1),[r,p]=s.useState(null),_=s.useRef(o);_.current=o;const k=s.useRef(i);k.current=i;const w=s.useCallback(x=>{switch(x.type){case"user_partial":k.current(),m(x.text),f("listening");return;case"user_final":m(null),b(!1),f("listening"),x.text.trim()&&_.current(x.text);return;case"user_speaking":b(x.active),x.active&&(k.current(),f("listening"));return;case"thinking":m(null),b(!1),f("thinking");return;case"agent_delta":f("speaking");return;case"agent_done":f("listening");return;case"interrupted":k.current(),f("listening");return;case"error":p(x.message),f("error");return}},[]),E=s.useCallback(async()=>{if(!n.available){p("voice_conv.error"),f("error");return}p(null),f("connecting"),k.current();const[,x]=await Te(n.start({agentId:a,onEvent:w}));if(x){p("voice_conv.error"),f("error");return}f("listening")},[n,a,w]),U=s.useCallback(()=>{n.stop(),m(null),b(!1),f("idle")},[n]),H=s.useRef(n);return H.current=n,s.useEffect(()=>()=>H.current.stop(),[]),{state:l,draft:v,userSpeaking:g,error:r,start:E,stop:U}}const Mn=()=>t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),t.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]}),as=()=>t.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 4l16 16"}),t.jsx("path",{d:"M9 5a3 3 0 0 1 6 0v5m-6 1.5V11"}),t.jsx("path",{d:"M5 11a7 7 0 0 0 10.9 5.8M19 11a7 7 0 0 1-.4 2.3M12 18v3"})]}),An=()=>t.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M6 6l12 12M18 6L6 18"})});function Pn({running:n}){const[a,o]=s.useState(0);return s.useEffect(()=>{if(!n)return;const i=setInterval(()=>o(l=>l+1),1e3);return()=>clearInterval(i)},[n]),t.jsx("span",{className:"es-vm__elapsed","data-testid":"voice-mode-elapsed",children:$n(a)})}function $n(n){const a=Math.floor(n/60),o=n%60;return`${a}:${String(o).padStart(2,"0")}`}function Ln({state:n,draft:a,error:o,muted:i,listening:l,hasTranscript:f,transcript:v,onToggleMute:m,onEnd:g,onRetry:b,t:r}){const p=s.useRef(null);if(s.useEffect(()=>{const w=p.current;w&&(w.scrollTop=w.scrollHeight)},[v]),n==="error")return t.jsxs("div",{className:"es-vm","data-testid":"voice-mode",children:[t.jsxs("div",{className:"es-vm__top",children:[t.jsx("span",{className:"es-vm__dot es-vm__dot--error"}),t.jsx("span",{className:"es-vm__label",children:r("voice_conv.title")})]}),t.jsxs("div",{className:"es-vm__denied",children:[t.jsx("div",{className:"es-vm__denied-icon",children:t.jsx(as,{})}),t.jsxs("div",{children:[t.jsx("div",{className:"es-vm__denied-title",children:r("voice_conv.denied_title")}),t.jsx("div",{className:"es-vm__denied-body",children:r(o||"voice_conv.denied_body")})]}),t.jsxs("div",{className:"es-vm__denied-actions",children:[t.jsx("button",{type:"button",className:"es-vm__action es-vm__action--primary",onClick:b,"data-testid":"voice-mode-retry",children:r("voice_conv.retry")}),t.jsx("button",{type:"button",className:"es-vm__action",onClick:g,"data-testid":"voice-mode-back",children:r("voice_conv.back_to_typing")})]})]})]});const _=!i&&(!!l||!!(a&&a.trim())),k=i?"muted":n==="speaking"?"speaking":n==="thinking"?"thinking":"listening";return t.jsxs("div",{className:"es-vm","data-testid":"voice-mode","data-state":n,children:[t.jsxs("div",{className:"es-vm__top",children:[t.jsx("span",{className:"es-vm__label",children:r("voice_conv.title")}),t.jsx(Pn,{running:n!=="idle"})]}),t.jsxs("div",{className:"es-vm__orbwrap",children:[t.jsxs("div",{className:"es-vm__orb","data-s":k,"data-active":_?"1":void 0,"data-testid":"voice-mode-orb","aria-hidden":"true",children:[t.jsx("span",{className:"es-vm__orb-halo"}),t.jsx("span",{className:"es-vm__orb-halo es-vm__orb-halo--delayed"}),t.jsx("span",{className:"es-vm__orb-core"})]}),t.jsx("div",{className:"es-vm__orb-state",role:"status","data-testid":"voice-mode-state",children:r(`voice_conv.state_${k}`)}),t.jsx("div",{className:"es-vm__orb-hint",children:r(`voice_conv.state_${k}_hint`)})]}),t.jsx("div",{className:"es-vm__transcript","data-testid":"voice-mode-transcript",ref:p,children:f?v:t.jsx("div",{className:"es-vm__invite","data-testid":"voice-mode-invite",children:r("voice_conv.invite")})}),t.jsxs("div",{className:"es-vm__controls",children:[t.jsx("button",{type:"button",className:`es-vm__btn${i?" es-vm__btn--on":""}`,"aria-label":r(i?"voice_conv.unmute":"voice_conv.mute"),onClick:m,"data-testid":"voice-mode-mute",children:i?t.jsx(as,{}):t.jsx(Mn,{})}),t.jsx("button",{type:"button",className:"es-vm__btn es-vm__btn--end","aria-label":r("voice_conv.end"),onClick:g,"data-testid":"voice-mode-end",children:t.jsx(An,{})})]})]})}const rs=/[.!?]+(?:['")\]]+)?(\s+)/g;function Un(n){const a=[];let o=0;rs.lastIndex=0;let i;for(;i=rs.exec(n);){const l=i.index+i[0].length,f=n.slice(o,l).trim();f&&a.push(f),o=l}return{complete:a,remainder:n.slice(o)}}function Dn(n,a,o){return n===void 0?o:n.map(i=>{const l=i.translations?.[a]?.trim();return l||i.translations?.[i.baseLanguage]?.trim()||(Object.values(i.translations??{}).find(v=>v?.trim())?.trim()??"")}).filter(i=>i.length>0)}function On({size:n=16}){return t.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("polyline",{points:"12 6 12 12 16 14"})]})}function qn({size:n=18}){return t.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M12 5H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7"}),t.jsx("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]})}function Bn({size:n=16}){return t.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M2 9a3 3 0 1 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 1 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z"}),t.jsx("path",{d:"m9 12 2 2 4-4"})]})}const Hn=["confirm_escalation","cancel_escalation","confirm_handoff","decline_handoff"],Fn="<followups>",Kn=/<followups>/i;function zn(n){const a=n.search(Kn);if(a!==-1)return n.slice(0,a).trimEnd();const o=n.lastIndexOf("<");return o!==-1&&Fn.startsWith(n.slice(o).toLowerCase())?n.slice(0,o).trimEnd():n}function is(n){return n>=.6?"high":n>=.35?"medium":"low"}function Qn(n){return/^https?:\/\//i.test(n)}function Wn(n){return n==="OUT_OF_HOURS"||n==="QUEUE_FULL"||n==="NO_OPERATOR"?n:null}function os(n){const{metadata:a,...o}=n;return{...o,...a&&typeof a=="object"?a:{}}}function Xn(n){let a=null;const o=[];for(const i of n.split(`
2
- `))i.startsWith("event:")?a=i.slice(6).trim():i.startsWith("data:")&&o.push(i.slice(5).trimStart());return{event:a,data:o.join(`
3
- `)}}const Jn=12e4,cs=1500,Vn=6e4,ls=120,Yn=25e3,Zn=600;function Gn({value:n,onChange:a,disabled:o,t:i}){const[l,f]=s.useState(null),v=n??0,m=!o&&l!==null?l:v;return t.jsxs("div",{className:"es-sc__rating-group",children:[t.jsx("div",{className:"es-sc__rating",role:"radiogroup","aria-label":i("support_chat.rate_aria"),onMouseLeave:()=>!o&&f(null),children:[1,2,3,4,5].map(g=>{const b=g<=m;return t.jsx("button",{type:"button",role:"radio","aria-checked":g===v,"aria-label":i("support_chat.rate_star",{count:g}),disabled:o,onMouseEnter:()=>!o&&f(g),onFocus:()=>!o&&f(g),onBlur:()=>!o&&f(null),onClick:()=>!o&&a?.(g),className:`es-sc__rating-star${b?" es-sc__rating-star--filled":""}${o?" es-sc__rating-star--disabled":""}`,children:t.jsx("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:b?"currentColor":"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})},g)})}),t.jsx("span",{className:"es-sc__rating-label","aria-live":"polite",children:m>0?i(`support_chat.rate_label_${m}`):""})]})}function la({config:n,actions:a,baseUrl:o,externalContext:i,productId:l,i18n:f,supportSessionId:v,auth:m,readOnly:g}){const b=g===!0,r=f?.t??(e=>e),p=i?.apiKey??"",_=s.useRef(m?.jwt);s.useEffect(()=>{_.current=m?.jwt},[m?.jwt]);const k=i?.voice,w=f?.currentLanguage??"en",E=!!k?.enabled&&(k?.languages??[]).includes(w),U=n.voiceConversationEnabled===!0,H=n.voiceReadAloudEnabled===!0,x=i?.voiceOutput,T=yn({baseUrl:o,apiKey:p,getJwt:()=>_.current}),ee=s.useRef(T);ee.current=T;const X=H&&!!x?.enabled&&(x?.languages??[]).includes(w),J=s.useRef(0),ce=i?.userContext??void 0,le=i?.resetSession??!1,R=i?.showTicketsTab??!1,O=kt(n.welcomeMessage,w,{t:r,fallbackKey:"support_chat.welcome_message",enDefault:"Hi! How can I help you today?"}),pe=kt(n.placeholder,w,{t:r,fallbackKey:"support_chat.input_placeholder",enDefault:"Ask a question..."}),ue=n.showSuggestedQuestions??!0,ne=Dn(n.localizedSuggestedQuestions,w,n.suggestedQuestions??[]),fe=n.escalationLabel||r("support_chat.escalation_label"),he=n.humanHandoffButton===!0,Oe=kt(n.headerTitle,w,{t:r,fallbackKey:"support.title",enDefault:"Support"}),xe=n.allowedLinkHosts,me=s.useMemo(()=>Array.isArray(xe)?xe.filter(e=>typeof e=="string"):void 0,[xe]),ye=n.allowMediaEmbeds===!0,I=typeof n._draft=="string"?n._draft:void 0,F=n._autoSend===!0,V=Array.isArray(n._quickChips)?n._quickChips:[],Y=JSON.stringify(V),[$,P]=s.useState([]);s.useEffect(()=>{if(!X)return;const e=T.activeId;if(!e){J.current=0;return}const c=$.find(h=>h.id===e);if(!c)return;const u=c.role==="assistant"&&c.refusalReason?r(`support_chat.refusal_${c.refusalReason}`,{productName:c.refusalProductName??""}):c.text??"";if(u.length>J.current){const h=u.slice(J.current),{complete:d,remainder:j}=Un(h);if(d.length>0){J.current=u.length-j.length;for(const C of d)T.feed(e,C,w)}}if(!c.isPending){const h=u.slice(J.current).trim();h&&(T.feed(e,h,w),J.current=u.length),T.finish(e)}},[$,T,X,w]);const[te,ae]=s.useState(""),[ke,Ie]=s.useState([]),[Q,qe]=s.useState(!1),[Ct,Ye]=s.useState(null),[Be,Ze]=s.useState(null),[W,Ne]=s.useState(v??null),[Me,it]=s.useState(null),[ot,ps]=s.useState(!1),[Re,St]=s.useState(null),[fs,Nt]=s.useState(0),[Ae,hs]=s.useState("open"),[ms,He]=s.useState([]),[gs,Ge]=s.useState(!1),[re,Fe]=s.useState("chat"),[Rt,ie]=s.useState({kind:"idle"}),Ee=s.useRef(null),et=s.useRef(le),Et=s.useRef(null),ct=s.useRef(!1),{containerRef:_s,isPinned:bs,scrollToBottom:Pe,stickToBottom:Tt}=Js(),Z=s.useRef(null),ge=s.useRef(null),tt=s.useRef(null),st=s.useRef(null);s.useEffect(()=>{Tt()},[$,Tt]),s.useEffect(()=>()=>{ge.current?.abort()},[]),s.useEffect(()=>{if(Me==null)return;const e=Me-Date.now();if(e<=0){it(null);return}const c=setTimeout(()=>it(null),e);return()=>clearTimeout(c)},[Me]),s.useEffect(()=>{if(Re==null)return;const e=()=>{const u=Re-Date.now();if(u<=0){St(null),Nt(0);return}Nt(Math.ceil(u/1e3))};e();const c=setInterval(e,1e3);return()=>clearInterval(c)},[Re]);const $e=s.useRef(null),we=s.useCallback(()=>{$e.current&&($e.current.cancelled=!0),$e.current=null},[]);s.useEffect(()=>a.on("support-chat:clearHistory",()=>{ge.current?.abort(),we(),P([]),Ye(null),Ze(null),qe(!1),Ne(null),st.current=null,et.current=!0}),[a,we]),s.useEffect(()=>{a.emit("support-chat:session",{sessionId:W})},[a,W]);const It=s.useCallback((e,c,u)=>{we();const h={cancelled:!1};$e.current=h;const d=u?.trim()?u:null,j=`resume-${crypto.randomUUID()}`;P(D=>[...D,{id:j,role:"assistant",text:d??"",isPending:!d}]),Pe();const C=Date.now()+(d?6e3:Vn),S=async()=>{if(h.cancelled)return;let D=null;try{const y=_.current,M=await fetch(`${o}/api/support-chat/sessions/${e}/messages?limit=50`,{headers:{...p?{"X-API-Key":p}:{},...y?{Authorization:`Bearer ${y}`}:{}}});if(M.ok){const z=await M.json(),ve=z.success&&z.data?z.data.messages:[];for(let A=ve.length-1;A>=0;A--){const K=ve[A];if(K.role!=="assistant")continue;const N=K.createdAt?Date.parse(K.createdAt):NaN;if(Number.isFinite(N)&&N>c){D=K;break}}}}catch{}if(!h.cancelled){if(D){const y=D.metadata??{},M=y.confidence,z=typeof M=="number"?is(M):void 0;P(ve=>ve.map(A=>A.id===j?{...A,id:D.id,serverId:D.id,promptLogId:D.promptLogId??null,text:D.content,isPending:!1,confidence:M,confidenceLevel:z,sources:y.sources&&y.sources.length>0?y.sources:void 0,actions:y.actions&&y.actions.length>0?y.actions:void 0,quickReplies:y.quickReplies&&y.quickReplies.length>0?y.quickReplies:void 0,ticketCards:y.ticketCards&&y.ticketCards.length>0?y.ticketCards:void 0,suggestedFollowUps:y.suggestedFollowUps&&y.suggestedFollowUps.length>0?y.suggestedFollowUps:void 0,awaitingConfirmation:y.awaitingConfirmation,refusalReason:y.refusalReason,refusalProductName:y.refusalProductName}:A)),Pe(),$e.current=null;return}if(Date.now()>=C){d||P(y=>y.map(M=>M.id===j?{...M,text:r("support_chat.error_message"),isPending:!1}:M)),$e.current=null;return}setTimeout(S,cs)}};setTimeout(S,cs)},[p,o,we,Pe,r]),Ke=s.useCallback(async(e,c)=>{try{const u=_.current,h=await fetch(`${o}/api/support-chat/sessions/${e}/messages?limit=50`,{headers:{...p?{"X-API-Key":p}:{},...u?{Authorization:`Bearer ${u}`}:{}}});if(!h.ok)return;const d=await h.json();if(!d.success||!d.data)return;const j=d.data.messages.filter(y=>y.role==="user"||y.role==="assistant").map(y=>{const M=y.metadata??void 0,z=M?.ticketCards&&M.ticketCards.length>0?M.ticketCards:void 0;return{id:y.id,role:y.role,text:y.content,promptLogId:y.promptLogId??null,rating:y.userScore??null,...z?{ticketCards:z}:{},...M?.suggestedFollowUps&&M.suggestedFollowUps.length>0?{suggestedFollowUps:M.suggestedFollowUps}:{},...M?.refusalReason?{refusalReason:M.refusalReason,refusalProductName:M.refusalProductName}:{}}}),C=j.length-1,S=C>=0?j[C]:void 0;if(S&&S.role==="assistant"){const y=d.data.messages[d.data.messages.length-1]?.metadata;y?.quickReplies&&y.quickReplies.length>0&&(j[C]={...S,quickReplies:y.quickReplies,...y.awaitingConfirmation?{awaitingConfirmation:y.awaitingConfirmation}:{}})}P(j),st.current=e;const D=d.data.messages[d.data.messages.length-1];if(D&&D.role==="user"){const y=D.createdAt?Date.parse(D.createdAt):NaN;Number.isFinite(y)&&Date.now()-y<Jn&&It(e,y,c)}}catch{}},[p,o,It]),_e=s.useCallback(async e=>{if(!R)return[];try{const c=_.current,u=await fetch(`${o}/api/widget/support-chat/tickets?status=${e}`,{headers:{...p?{"X-API-Key":p}:{},...c?{Authorization:`Bearer ${c}`}:{}}});if(!u.ok)return[];const h=await u.json();return h.data?.counts&&h.data?.tickets?h.data.tickets:[]}catch{return[]}},[o,p,R]);s.useEffect(()=>{let e=!1;return(async()=>{const c=await _e("open").catch(()=>[]);e||He(c)})(),()=>{e=!0}},[_e,m?.jwt]);const vs=s.useCallback(async e=>{hs(e),Ge(!0);const c=await _e(e).catch(()=>[]);He(c),Ge(!1)},[_e]),Mt=s.useRef(!1);s.useEffect(()=>{Mt.current||v&&m?.jwt&&(Mt.current=!0,Ke(v))},[m?.jwt,v,Ke]),s.useEffect(()=>we,[we]),s.useEffect(()=>a.on("support-chat:select-session",e=>{const{sessionId:c}=e;Fe("chat"),!(!c||c===st.current)&&(ge.current?.abort(),P([]),Ye(null),Ze(null),qe(!1),Ne(c),Ke(c))}),[a,Ke]);const je=s.useCallback(()=>{const e=Z.current;if(!e)return;e.style.height="auto";const c=e.scrollHeight>ls;e.style.height=`${Math.min(e.scrollHeight,ls)}px`,e.style.overflowY=c?"auto":"hidden"},[]);s.useEffect(()=>{je()},[je]);const lt=s.useCallback((e,c)=>{const u=c.metadata??{},h=u.confidence,d=typeof h=="number"?is(h):void 0;P(j=>j.map(C=>C.id===e?{...C,id:c.id,serverId:c.id,promptLogId:c.promptLogId,rating:null,text:c.content,isPending:!1,confidence:h,confidenceLevel:d,sources:u.sources&&u.sources.length>0?u.sources:void 0,actions:u.actions&&u.actions.length>0?u.actions:void 0,quickReplies:u.quickReplies&&u.quickReplies.length>0?u.quickReplies:void 0,ticketCards:u.ticketCards&&u.ticketCards.length>0?u.ticketCards:void 0,suggestedFollowUps:u.suggestedFollowUps&&u.suggestedFollowUps.length>0?u.suggestedFollowUps:void 0,awaitingConfirmation:u.awaitingConfirmation,refusalReason:u.refusalReason,refusalProductName:u.refusalProductName}:C))},[]),At=s.useCallback(e=>{ps(!0),P(c=>c.map(u=>u.id===e?{...u,role:"assistant",text:r("support_chat.demo_quota_reached"),isPending:!1}:u))},[r]),ut=s.useCallback((e,c)=>{it(c??Date.now()+6e4),P(u=>u.map(h=>h.id===e?{...h,role:"assistant",text:r("support_chat.daily_limit_reached"),isPending:!1}:h))},[r]),dt=s.useCallback((e,c)=>{const u=typeof c=="number"&&c>0?c:6e4;St(Date.now()+u);const h=Math.ceil(u/1e3);P(d=>d.map(j=>j.id===e?{...j,role:"assistant",text:r("support_chat.rate_limited",{seconds:String(h)}),isPending:!1}:j))},[r]),Pt=s.useCallback((e,c)=>{P(u=>u.filter(h=>h.id!==e)),ie(c==="human"?{kind:"human",displayName:null}:{kind:"waiting",until:Ee.current})},[]),Ce=s.useCallback(()=>{ct.current&&(ct.current=!1,a.emit("chat:draftConsumed",void 0))},[a]),G=s.useCallback(async(e,c)=>{const u=e.trim();if(!u)return;Ce(),we(),ge.current?.abort(),ge.current=new AbortController,Ye(null),Ze(null),ae(""),Ie([]),Z.current&&(Z.current.style.height="auto");const h={id:`user-${crypto.randomUUID()}`,role:"user",text:u},d=`assistant-${crypto.randomUUID()}`,j={id:d,role:"assistant",text:"",isPending:!0};P(A=>[...A,h,j]),Pe(),qe(!0),tt.current=d;const C=Date.now(),S=async()=>{const A=Zn-(Date.now()-C);A>0&&await new Promise(K=>setTimeout(K,A))};a.emit("support-chat:messageSent",{text:u});const[D]=await Te(async()=>await m?.ensureValidToken?.()??null),y=D??_.current,M={"Content-Type":"application/json",...p?{"X-API-Key":p}:{},...y?{Authorization:`Bearer ${y}`}:{}},z=et.current||W===null;let ve=!1;try{if(c?.quickReplyClick){const q=await fetch(`${o}/api/widget/support-chat/message`,{method:"POST",headers:M,body:JSON.stringify({message:u,productId:l,...z?{newSession:!0}:{},...ce?{userContext:os(ce)}:{},quickReplyClick:c.quickReplyClick}),signal:ge.current.signal}),B=await q.json();if(q.status===429&&B?.error?.code==="DAILY_TOKEN_LIMIT_EXCEEDED"){await S(),ut(d,B.error.resetAtMs);return}if(q.status===429&&B?.error?.code==="DEMO_QUOTA_EXCEEDED"){await S(),At(d);return}if(q.status===429&&B?.error?.code==="RATE_LIMITED"){await S(),dt(d,B.error.retryAfterMs);return}if(q.status===409&&B?.error?.code==="HANDOFF_ACTIVE"){await S(),Pt(d,B.data?.handoffState),B.data?.sessionId&&Ne(B.data.sessionId);return}if(!q.ok||!B.success||!B.data)throw new Error(B.error?.message??`HTTP ${q.status}`);Ne(B.data.sessionId),et.current=!1,lt(d,B.data.assistantMessage),c.quickReplyClick.payload==="confirm_handoff"&&((B.data.assistantMessage.metadata?.toolCalls?.includes("request_human_handoff")??!1)||(ie({kind:"idle"}),Ee.current=null)),_e(Ae).then(bt=>He(bt));return}let A;const K=()=>{A&&clearTimeout(A),A=setTimeout(()=>{ve=!0,ge.current?.abort()},Yn)};K();const N=ge.current;if(!N){clearTimeout(A);return}const[Se,Zt]=await Te(async()=>{const q=await fetch(`${o}/api/widget/support-chat/stream`,{method:"POST",headers:M,body:JSON.stringify({message:u,productId:l,...z?{newSession:!0}:{},...ce?{userContext:os(ce)}:{}}),signal:N.signal});if(!q.ok||!q.body){const se=await q.json().catch(()=>null);if(q.status===429&&se?.error?.code==="DAILY_TOKEN_LIMIT_EXCEEDED")return{dailyLimitResetAtMs:se.error.resetAtMs};if(q.status===429&&se?.error?.code==="DEMO_QUOTA_EXCEEDED")return{demoQuotaExhausted:!0};if(q.status===429&&se?.error?.code==="RATE_LIMITED")return{rateLimitRetryAfterMs:se.error.retryAfterMs??6e4};if(q.status===409&&se?.error?.code==="HANDOFF_ACTIVE")return se.data?.sessionId&&Ne(se.data.sessionId),{handoffState:se.data?.handoffState??null};throw new Error(se?.error?.message??`HTTP ${q.status}`)}const B=q.body.getReader(),bt=new TextDecoder;let Xe="",Gt="",es=!1;for(;;){const{done:se,value:Ks}=await B.read();if(se)break;K(),Xe+=bt.decode(Ks,{stream:!0});let vt;for(;(vt=Xe.indexOf(`
4
-
5
- `))!==-1;){const zs=Xe.slice(0,vt);Xe=Xe.slice(vt+2);const{event:Je,data:Ve}=Xn(zs);if(!(!Je||!Ve)){if(Je==="start"){const de=JSON.parse(Ve);de.sessionId&&(Ne(de.sessionId),st.current=de.sessionId),et.current=!1}else if(Je==="token"){const de=JSON.parse(Ve);Gt+=de.value??"";const xt=zn(Gt);P(Qs=>Qs.map(yt=>yt.id===d?{...yt,text:xt}:yt))}else if(Je==="meta"){const de=JSON.parse(Ve);lt(d,de.assistantMessage),_e(Ae).then(xt=>He(xt)),es=!0}else if(Je==="error"){const de=JSON.parse(Ve);if(de.code==="HANDOFF_ACTIVE")return{handoffState:null};throw new Error(de.message??"Stream error")}}}}if(!es)throw new Error("Stream ended before completion");return null});if(A&&clearTimeout(A),Zt)throw Zt;if(Se&&"handoffState"in Se){await S(),Pt(d,Se.handoffState);return}if(Se?.dailyLimitResetAtMs!==void 0){await S(),ut(d,Se.dailyLimitResetAtMs);return}if(Se?.demoQuotaExhausted){await S(),At(d);return}if(Se?.rateLimitRetryAfterMs!==void 0){await S(),dt(d,Se.rateLimitRetryAfterMs);return}}catch(A){if(A instanceof Error&&A.name==="AbortError"&&!ve){P(K=>K.filter(N=>N.id!==d));return}await S(),P(K=>K.filter(N=>N.id!==d)),tt.current===d&&(Ze({text:u,options:c}),Ye(r("support_chat.error_message")))}finally{tt.current===d&&qe(!1)}},[a,o,ce,p,l,r,lt,ut,dt,_e,Ae,Pe,m,we,Ce]),be=k?.realtimeProvider==="elevenlabs",[pt,ft]=s.useState([]),$t=s.useRef(0),ze=s.useRef([]);ze.current=pt;const nt=s.useRef(null),ht=s.useRef(null),Lt=s.useRef(new Set),mt=s.useRef(new Set),Qe=s.useRef(!1),Le=s.useRef(null),gt=s.useRef(null),at=s.useRef(!1),Ut=s.useRef(W);Ut.current=W;const Dt=k?.realtime===!0,Ot=s.useRef(i?.voiceStream);Ot.current=i?.voiceStream;const qt=s.useMemo(()=>{if(be){const e=jn({baseUrl:o,apiKey:p,jwt:_.current,language:w,enabled:!0,getSessionId:()=>Ut.current,onSessionId:c=>{ht.current=c,Ne(c)},onUserTurnEnd:()=>Le.current?.(),onTranscript:c=>ft(u=>{const h=u[u.length-1];if(!(h&&De(h)&&h.streaming&&h.role===c.role)){$t.current+=1;const j=`${ds}${$t.current}`;return[...u,{id:j,role:c.role,text:c.text,streaming:c.streaming}]}const d=c.role==="assistant"&&c.streaming?h.text+c.text:c.text;return[...u.slice(0,-1),{...h,text:d,streaming:c.streaming}]})});return nt.current=e,e}return nt.current=null,wn({voiceStream:Ot.current,language:w})},[be,o,p,w]),L=In({transport:qt,agentId:i?.voiceAgentId??"",onUserMessage:e=>{G(e)},onStopPlayback:()=>ee.current?.stop()}),Bt=L.state!=="idle"&&L.state!=="error",oe=L.state!=="idle",Ht=s.useRef(!1);s.useEffect(()=>{const e=Ht.current;if(Ht.current=oe,!oe){const c=(()=>{const u=ze.current;for(let h=u.length-1;h>=0;h-=1){const d=u[h];if(d&&d.role==="assistant"&&d.text?.trim())return d.text}return null})();if(ft([]),e){const u=ht.current??W;u&&Ke(u,c??void 0)}}},[oe]),s.useEffect(()=>{try{window.dispatchEvent(new CustomEvent("es-support-voice-mode",{detail:{active:oe}}))}catch{}},[oe]),s.useEffect(()=>{if(!be||!oe){Lt.current=new Set,mt.current=new Set,Qe.current=!1,Le.current=null;return}let e=!1,c=!1;at.current=!1;const u=async(C=!1)=>{const S=ht.current??W;if(!S||e)return!1;const D=_.current;let y=null;try{const N=await fetch(`${o}/api/support-chat/sessions/${S}/messages?limit=30`,{headers:{...p?{"X-API-Key":p}:{},...D?{Authorization:`Bearer ${D}`}:{}}});if(!N.ok)return!1;y=await N.json()}catch{return!1}if(e)return!1;const M=y?.data?.messages??[],z=Lt.current;if(!Qe.current){if(!C)return!1;for(const N of M)N.id&&mt.current.add(N.id),N.role==="user"&&N.id&&z.add(N.id);return Qe.current=!0,!1}const ve=mt.current,A=M.filter(N=>N.id&&N.content?.trim()&&(N.role==="user"||N.role==="assistant")&&!ve.has(N.id)).map(N=>({id:N.id,role:N.role,text:N.content,...N.metadata?{metadata:N.metadata}:{}}));if(A.length===0)return!1;ft(N=>Tn(N,A));const K=A.filter(N=>N.role==="user"&&!z.has(N.id));if(K.length===0)return!1;for(const N of K)z.add(N.id);return at.current=!0,!0},h=async()=>{if(!(c||e)){c=!0;for(let C=0;C<10&&!e&&!await u(!1);C++)await new Promise(S=>setTimeout(S,500));c=!1}};let d=0;const j=5e3;return Le.current=()=>{if(at.current)return;const C=Date.now();C-d<j||(d=C,h())},gt.current=async()=>{for(let C=0;C<6&&!e;C+=1){if(await u(!1),!ze.current.some(De))return;await new Promise(S=>setTimeout(S,700))}},(async()=>{for(let C=0;C<4&&!e&&!Qe.current;C+=1){if(await u(!0),Qe.current)return;await new Promise(S=>setTimeout(S,300))}})(),()=>{e=!0,Le.current=null,gt.current=null}},[be,oe,W,o,p]);const Ft=s.useRef(!1);s.useEffect(()=>{const e=Ft.current;Ft.current=L.userSpeaking,!e&&L.userSpeaking&&(at.current=!1),e&&!L.userSpeaking&&Le.current?.()},[L.userSpeaking]);const Kt=s.useRef(L.state);s.useEffect(()=>{const e=Kt.current;Kt.current=L.state,(L.state==="thinking"||L.state==="speaking")&&!(e==="thinking"||e==="speaking")&&Le.current?.()},[L.state]);const We=s.useRef(null);s.useEffect(()=>{if(!be||!oe)return;const e=ze.current[ze.current.length-1];if(!(!e||!De(e)||e.role!=="assistant"||!e.text.trim()))return We.current&&clearTimeout(We.current),We.current=setTimeout(()=>{gt.current?.()},900),()=>{We.current&&clearTimeout(We.current)}},[pt,be,oe]);const[zt,xs]=s.useState(!1),[ys,Qt]=s.useState(!1),ks=s.useCallback(e=>{nt.current?.sendUserMessage(e)&&Qt(!0)},[]);s.useEffect(()=>{(L.state==="thinking"||L.state==="speaking")&&Qt(!1)},[L.state]);const Ue=be?pt.map(e=>({key:e.id,role:e.role,text:e.text,...e.metadata?{metadata:e.metadata}:{},...e.streaming?{streaming:!0}:{}})):$.map(e=>{const c=e.role==="assistant"&&e.refusalReason?r(`support_chat.refusal_${e.refusalReason}`,{productName:e.refusalProductName??""}):e.text;return c?{key:e.id,role:e.role==="assistant"?"assistant":"user",text:c,confidence:e.confidenceLevel}:null}).filter(e=>e!==null),ws=be&&oe&&Ue.length>0&&Ue[Ue.length-1].role==="user",js=t.jsxs("div",{className:"es-sc__messages",children:[Ue.map((e,c)=>{const u=c===Ue.length-1;return t.jsxs("div",{className:`es-sc__bubble es-sc__bubble--${e.role}`,"data-confidence":e.confidence,children:[e.role==="assistant"?t.jsx(ss,{text:e.text,allowedLinkHosts:me}):t.jsx("div",{className:"es-sc__bubble-text",children:e.text}),e.role==="assistant"&&t.jsx(ns,{followUps:e.metadata?.suggestedFollowUps,isNewest:u,isPending:!!e.streaming,hasQuickReplies:!!e.metadata?.quickReplies?.length,isSending:ys,onSelect:ks,t:r})]},e.key)}),ws?t.jsx("div",{className:"es-vm__answer-pending",role:"status","aria-label":r("voice_conv.thinking"),children:t.jsxs("div",{className:"es-vm__answer-wave",children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]})}):null]}),Wt=s.useRef(null);s.useEffect(()=>{if(Dt||!Bt||!T||!X)return;const e=$[$.length-1];!e||e.role!=="assistant"||Wt.current!==e.id&&(Wt.current=e.id,T.activate(e.id))},[$,Bt,T,X]);const _t=s.useCallback(()=>{const e=i?.voiceStream;e?.getState&&e.getState()!=="idle"&&e.stop(),G(te)},[te,G,i]),Cs=s.useCallback(()=>{ge.current?.abort(),qe(!1);const e=tt.current;e&&P(c=>c.filter(u=>u.id!==e))},[]),Ss=s.useCallback(()=>{Be&&G(Be.text,Be.options)},[Be,G]),Ns=s.useCallback(e=>{if(e.autoSend){G(e.message);return}Ie([]),ae(""),Ce(),Z.current&&(Z.current.style.height="auto",Z.current.focus())},[G,Ce]);s.useEffect(()=>{if(!(I!==void 0||V.length>0))return;const e=`${I}${String(F)}${Y}`;if(Et.current!==e){if(Et.current=e,ct.current=!0,F&&I!==void 0){Ie([]),G(I);return}Ie(V),I!==void 0&&(ae(I),requestAnimationFrame(()=>{je(),Z.current?.focus()}))}},[I,F,Y,G]),s.useEffect(()=>{const e=i?.voiceStream;e?.getState&&e.getState()!=="idle"&&e.stop()},[v]);const Rs=s.useCallback(e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),_t())},[_t]),Es=s.useCallback(e=>{Ce(),ae(e.target.value),je()},[je,Ce]),Ts=s.useCallback(()=>{Ce(),ae(""),Z.current&&(Z.current.style.height="auto",Z.current.focus())},[Ce]),Is=s.useCallback(e=>{const c=e.trim();c&&(ae(u=>u?`${u} ${c}`:c),requestAnimationFrame(()=>{je(),Z.current?.focus()}))},[je]),Ms=s.useCallback(e=>{a.emit("support-chat:escalated",{messageId:e})},[a]),Xt=s.useRef($);s.useEffect(()=>{Xt.current=$},[$]);const As=s.useCallback(({messageId:e,rating:c},{keepalive:u})=>{const h=Xt.current.find(d=>d.id===e);!h||!h.promptLogId||_.current&&(P(d=>d.map(j=>j.id===e?{...j,rating:c,ratingPending:!0}:j)),(async()=>{const[d,j]=await Te(fetch(`${o}/api/widget/ai-feedback`,{method:"POST",keepalive:u,headers:{"Content-Type":"application/json",...p?{"X-API-Key":p}:{},Authorization:`Bearer ${_.current}`},body:JSON.stringify({promptLogId:h.promptLogId,rating:c})}));if(!j&&d.status===409){P(C=>C.map(S=>S.id===e?{...S,rating:c,ratingPending:!1}:S));return}if(j||!d.ok){P(C=>C.map(S=>S.id===e?{...S,rating:null,ratingPending:!1}:S));return}P(C=>C.map(S=>S.id===e?{...S,rating:c,ratingPending:!1}:S)),a.emit("support-chat:feedbackSubmitted",{messageId:e,rating:c})})())},[a,p,o]),{pending:Jt,rate:Vt,undo:Ps}=Vs({submit:As}),$s=s.useCallback((e,c)=>{const u=$.find(h=>h.id===e);!u||!u.promptLogId||u.ratingPending||_.current&&Vt(e,c)},[$,Vt]),Ls=s.useCallback(()=>{Fe("chat"),ie({kind:"idle"}),Ee.current=null,a.emit("support-chat:clearHistory",void 0)},[a]),Us=s.useCallback(async()=>{if(!W)return;const e=_.current;try{const c=await fetch(`${o}/api/widget/support-chat/handoff/request`,{method:"POST",headers:{"Content-Type":"application/json",...p?{"X-API-Key":p}:{},...e?{Authorization:`Bearer ${e}`}:{}},body:JSON.stringify({sessionId:W,productId:l,conversationLanguage:w})}),u=await c.json();if(!c.ok||!u.success){ie({kind:"idle"});return}if(u.data?.outcome==="unavailable"){ie({kind:"unavailable",reason:Wn(u.data.reason)});return}if(u.data?.outcome==="already_active"){ie(u.data.state==="human"?{kind:"human",displayName:null}:{kind:"waiting",until:Ee.current});return}if(u.data?.outcome==="offered"){const h=u.data.acceptTimeoutSec;Ee.current=typeof h=="number"?Date.now()+h*1e3:null,ie({kind:"waiting",until:Ee.current})}}catch{ie({kind:"idle"})}},[p,o,w,l,W]),Ds=s.useCallback(async e=>{if(!W)return!1;const c=_.current;try{const u=await fetch(`${o}/api/widget/support-chat/handoff/contact`,{method:"POST",headers:{"Content-Type":"application/json",...p?{"X-API-Key":p}:{},...c?{Authorization:`Bearer ${c}`}:{}},body:JSON.stringify({sessionId:W,productId:l,...e.email?{email:e.email}:{},...e.phone?{phone:e.phone}:{},...e.note?{note:e.note}:{}})}),h=await u.json();return!u.ok||!h.success?!1:(ie({kind:"contact_left"}),!0)}catch{return!1}},[p,o,l,W]),Os=s.useCallback(()=>{ie({kind:"idle"})},[]),rt=s.useCallback(()=>{Fe("tickets"),Ge(!0),_e(Ae).then(e=>He(e)).catch(()=>{}).finally(()=>Ge(!1))},[_e,Ae]),qs=s.useCallback(()=>{re==="tickets"?Fe("chat"):rt()},[re,rt]),Bs=s.useCallback(e=>{Fe("chat"),a.emit("support-chat:select-session",{sessionId:e})},[a]);s.useEffect(()=>R?a.on("support-chat:showTickets",()=>{rt()}):void 0,[a,rt,R]);const Hs=s.useCallback((e,c,u)=>{P(j=>j.map(C=>C.id===e?{...C,quickReplyAnswered:c}:C));const h=$.find(j=>j.id===e)?.awaitingConfirmation,d=Hn.includes(u);u==="confirm_handoff"&&ie({kind:"waiting",until:Ee.current}),G(c,{...d?{quickReplyClick:{payload:u,summary:h?.summary,details:h?.details??void 0,priority:h?.priority,sourceMessageId:e}}:{}})},[$,G]),Fs=s.useCallback(()=>{a.emit("support-chat:showHistory",void 0)},[a]),Yt=$.length===0;return oe?t.jsx(ts,{blockType:"support-chat",children:t.jsx(Ln,{state:L.state,draft:L.draft,error:L.error,muted:zt,listening:L.userSpeaking,hasTranscript:Ue.length>0,transcript:js,onToggleMute:()=>{const e=!zt;xs(e),nt.current?.setMuted(e)},onEnd:()=>L.stop(),onRetry:()=>{L.start()},t:r})}):t.jsxs(ts,{blockType:"support-chat",children:[t.jsxs("div",{className:"es-sc__chat-header",children:[t.jsx("span",{className:"es-sc__chat-header-title",children:R&&re==="tickets"?r("support_chat.tickets_view_title"):Oe}),t.jsxs("div",{className:"es-sc__chat-header-actions",children:[t.jsx("button",{type:"button",className:"es-sc__chat-action-btn","aria-label":r("support_chat.new_conversation_button"),title:r("support_chat.new_conversation_button"),onClick:Ls,children:t.jsx(qn,{size:18})}),t.jsx("button",{type:"button",className:"es-sc__chat-action-btn","aria-label":r("support_chat.history_button"),title:r("support_chat.history_button"),onClick:Fs,children:t.jsx(On,{size:16})}),he&&re==="chat"&&Rt.kind==="idle"&&t.jsx("button",{type:"button",className:"es-sc__chat-action-btn es-sc__chat-action-btn--label","aria-label":r("support_chat.handoff.button_label"),title:r("support_chat.handoff.button_label"),onClick:()=>{Us()},children:r("support_chat.handoff.button_label")}),R&&t.jsx("button",{type:"button",className:`es-sc__chat-action-btn${re==="tickets"?" es-sc__chat-action-btn--active":""}`,"aria-label":r("support_chat.tickets_tab_button"),title:r("support_chat.tickets_tab_button"),"aria-pressed":re==="tickets",onClick:qs,children:t.jsx(Bn,{size:16})}),t.jsx(Ys,{panelKey:"support-chat",baseUrl:o,apiKey:p||void 0,t:r})]})]}),t.jsx("div",{className:"es-block__body es-sc__body",children:R&&re==="tickets"?t.jsx(un,{status:Ae,loading:gs,tickets:ms,onSelectStatus:vs,onSelectSession:Bs,t:r}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"es-sc__messages",ref:_s,children:[Yt&&t.jsx("div",{className:"es-sc__welcome",children:t.jsx("div",{className:"es-sc__welcome-text",children:O})}),$.map((e,c)=>{const u=c===$.length-1,h=e.role==="assistant"&&e.refusalReason?r(`support_chat.refusal_${e.refusalReason}`,{productName:e.refusalProductName??""}):e.text;return t.jsxs("div",{className:`es-sc__bubble es-sc__bubble--${e.role}`,"data-confidence":e.confidenceLevel,children:[h&&(e.role==="assistant"?t.jsxs(t.Fragment,{children:[t.jsx(ss,{text:h,allowedLinkHosts:me}),t.jsx(on,{text:h,allowEmbeds:ye,allowedImageHosts:me,t:r}),X&&t.jsx(vn,{id:e.id,session:T,onActivate:()=>T.activate(e.id),t:r})]}):t.jsx("div",{className:"es-sc__bubble-text",children:h})),e.isPending&&!e.text&&t.jsxs("div",{className:"es-sc__typing","aria-label":r("support_chat.typing_aria"),children:[t.jsx("span",{className:"es-sc__typing-dot"}),t.jsx("span",{className:"es-sc__typing-dot"}),t.jsx("span",{className:"es-sc__typing-dot"})]}),e.actions&&e.actions.length>0&&t.jsx("div",{className:"es-sc__actions","data-es-no-read":!0,children:e.actions.map(d=>t.jsx("a",{href:Qn(d.url)?d.url:"#",target:"_blank",rel:"noopener noreferrer",className:"es-sc__action-btn",children:d.title},d.slug))}),e.ticketCards&&e.ticketCards.length>0&&t.jsx("div",{className:"es-sc__ticket-cards",children:e.ticketCards.map(d=>t.jsx(us,{card:d,t:r},d.externalNumber))}),e.quickReplies&&e.quickReplies.length>0&&t.jsx("div",{className:"es-sc__quick-replies",children:e.quickReplies.map(d=>{const j=e.quickReplyAnswered===d.value;if(e.quickReplyAnswered!==void 0&&!j)return null;const C=d.payload==="confirm_escalation"?r("escalation.confirm_yes"):d.payload==="cancel_escalation"?r("escalation.confirm_no"):d.payload==="confirm_handoff"?r("support_chat.handoff.confirm_yes"):d.payload==="decline_handoff"?r("support_chat.handoff.confirm_no"):d.label;return t.jsx("button",{type:"button",disabled:j||Q,onClick:()=>Hs(e.id,d.value,d.payload??""),className:`es-sc__quick-reply-btn${j?" es-sc__quick-reply-btn--clicked":""}`,children:C},d.value)})}),e.role==="assistant"&&t.jsx(ns,{followUps:e.suggestedFollowUps,isNewest:u,isPending:!!e.isPending,hasQuickReplies:!!e.quickReplies?.length,isSending:Q,onSelect:d=>G(d),t:r}),e.role==="assistant"&&!e.isPending&&e.text&&t.jsxs(t.Fragment,{children:[e.promptLogId&&_.current&&(()=>{const d=Jt?.messageId===e.id?Jt.rating:null;return t.jsxs("div",{className:"es-sc__feedback","aria-label":r("support_chat.rate_aria"),"data-es-no-read":!0,children:[t.jsx("span",{className:"es-sc__feedback-label",children:e.rating&&d===null?r("support_chat.feedback_thanks"):r("support_chat.rate_aria")}),t.jsx(Gn,{value:d??e.rating??null,onChange:j=>$s(e.id,j),disabled:d===null&&(!!e.rating||e.ratingPending),t:r}),d!==null&&t.jsxs("div",{className:"es-sc__rating-undo",role:"status",children:[t.jsx("span",{className:"es-sc__rating-undo-text",children:r("support_chat.rating_undo_toast",{rating:d})}),t.jsx("button",{type:"button",className:"es-sc__rating-undo-btn",onClick:Ps,children:r("support_chat.rating_undo_button")})]})]})})(),e.confidenceLevel==="low"&&t.jsxs("div",{className:"es-sc__escalation",children:[t.jsx("span",{className:"es-sc__escalation-text",children:r("support_chat.low_confidence")}),t.jsx("button",{className:"es-sc__escalation-btn",onClick:()=>Ms(e.id),type:"button","aria-label":fe,children:fe})]})]})]},e.id)}),Ct&&t.jsxs("div",{className:"es-sc__error",role:"alert",children:[t.jsx("span",{className:"es-sc__error-text",children:Ct}),Be&&t.jsx("button",{type:"button",className:"es-sc__error-retry",onClick:Ss,children:r("support_chat.retry")})]})]}),!bs&&$.length>0&&t.jsxs("button",{type:"button",className:"es-sc__jump",onClick:()=>Pe(),"aria-label":r("support_chat.jump_to_latest"),title:r("support_chat.jump_to_latest"),children:[t.jsxs("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M12 5v14"}),t.jsx("path",{d:"m19 12-7 7-7-7"})]}),t.jsx("span",{className:"es-sc__jump-label",children:r("support_chat.jump_to_latest")})]})]})}),re!=="tickets"&&ke.length>0&&t.jsx("div",{className:"es-sc__suggestions",role:"group","aria-label":r("support_chat.quick_actions_aria"),children:ke.map((e,c)=>t.jsx("button",{className:"es-sc__suggestion",onClick:()=>Ns(e),type:"button",disabled:Q||b,children:e.labelKey?r(e.labelKey):e.label},`${e.labelKey??e.label}-${c}`))}),re!=="tickets"&&ke.length===0&&Yt&&ue&&ne.length>0&&t.jsx("div",{className:"es-sc__suggestions",role:"list","aria-label":r("support_chat.suggestions_aria"),children:ne.map((e,c)=>t.jsx("button",{className:"es-sc__suggestion",onClick:()=>G(e),type:"button",role:"listitem",children:e},c))}),re!=="tickets"&&t.jsx(Rn,{status:Rt,onSubmitContact:Ds,onDismissContact:Os,t:r}),re!=="tickets"&&t.jsxs("div",{className:"es-block__footer es-sc__footer",children:[t.jsx("div",{className:"es-sc__disclaimer","data-es-no-read":!0,children:r("support_chat.disclaimer")}),t.jsxs("div",{className:"es-sc__input-row",children:[U&&qt.available&&(be||Dt||E)&&t.jsx("button",{type:"button",className:"es-sc__conv-start","data-testid":"conversation-start","aria-label":r("voice_conv.start"),title:r("voice_conv.start"),onClick:()=>{L.start()},children:t.jsx("svg",{width:"19",height:"19",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 10v4M8 6v12M12 3v18M16 6v12M20 10v4"})})}),t.jsxs("div",{className:"es-sc__textarea-wrap",children:[t.jsx("textarea",{ref:Z,className:"es-sc__textarea",value:te,onChange:Es,onKeyDown:Rs,placeholder:Re!=null?r("support_chat.rate_limited_wait",{seconds:String(fs)}):pe,rows:1,maxLength:2e3,disabled:Q||b||Me!=null||Re!=null||ot,"aria-label":r("support_chat.input_aria")}),te.length>0&&t.jsx("button",{className:"es-sc__clear",onClick:Ts,disabled:Q,type:"button","aria-label":r("support_chat.clear_input_aria"),children:t.jsx("span",{"aria-hidden":"true",children:"✕"})})]}),E&&!b&&t.jsx(hn,{baseUrl:o,apiKey:p,jwt:_.current,language:w,onTranscript:Is,t:r,disabled:Q||Me!=null||Re!=null||ot,streaming:k?.streaming,voiceStream:i?.voiceStream,baseText:()=>te,onText:e=>{if(ae(e.length>2e3?e.slice(0,2e3):e),e.length>=2e3){const c=i?.voiceStream;c?.getState&&c.getState()!=="idle"&&c.stop()}requestAnimationFrame(()=>{je(),Z.current?.focus()})}}),t.jsx("button",{className:`es-sc__send${Q?" es-sc__send--stop":""}`,onClick:Q?Cs:_t,disabled:!Q&&(b||!te.trim()||Me!=null||Re!=null||ot),type:"button","aria-label":r(Q?"support_chat.stop_aria":"chat.send_aria"),children:Q?t.jsx("span",{className:"es-sc__stop-icon","aria-hidden":"true"}):t.jsx("span",{"aria-hidden":"true",children:"➤"})})]})]})]})}export{on as AssistantMessageMedia,la as Component,ss as MarkdownBubble,rn as MessageMedia,Ln as VoiceModeView,ca as manifest};
6
- //# sourceMappingURL=index-tapacGlG--YMQ21rc.js.map