@deepdesk/deepdesk-sdk 17.2.1-beta.0 → 17.2.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.iife.js +2 -2
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -77,9 +77,9 @@ Please report this to https://github.com/markedjs/marked.`,t){let o="<p>An error
|
|
|
77
77
|
c-17.9,17.9-27.3,40.1-27.3,65.7C163.4,163,163.4,233,163.4,233z M465.5,267.9V477c0,9.4-3.4,17.9-10.2,24.7
|
|
78
78
|
c-6.8,6.8-15.4,10.2-24.7,10.2h-349c-9.4,0-17.9-3.4-24.7-10.2c-6.8-6.8-10.2-15.4-10.2-24.7V267.9c0-9.4,3.4-17.9,10.2-24.7
|
|
79
79
|
c6.8-6.8,15.4-10.2,24.7-10.2h11.9v-70c0-44.4,16.2-82.8,47.8-115.2S212.1,0,256.4,0s82.8,16.2,115.2,47.8
|
|
80
|
-
c32.4,32.4,47.8,70,47.8,115.2v70h11.9c9.4,0,17.9,3.4,24.7,10.2C462.1,250,465.5,257.7,465.5,267.9z`})})});var p0=b(R()),_4={green:"#0A5E52",pink:"#CD8EF2",red:"#DF341D",yellow:"#DEBD00"},WR=({className:e,color:t})=>(0,p0.jsx)("svg",{className:e,viewBox:"0 0 345 345",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,p0.jsx)("path",{d:"M172.03 0.0199966H0V86.03C47.5 86.03 86 124.54 86 172.04C86 124.54 124.51 86.03 172.01 86.03C219.51 86.03 258.03 124.54 258.03 172.04C258.03 219.54 219.52 258.05 172.01 258.05C124.5 258.05 86 219.54 86 172.04C86 219.54 47.5 258.05 0 258.05V344.06H172.03C267.04 344.06 344.06 267.04 344.06 172.03C344.06 77.02 267.04 0 172.03 0V0.0199966Z",fill:_4[t||"pink"]})});var jR={root:"dd-LbeUM",text:"dd-Dpfn1",isLoggedIn:"dd-XvHAn",isLoggedOut:"dd-21y-z",icon:"dd-8rLqS",logo:"dd-slXhD",lock:"dd-ByzlR"};var m0={};pt(m0,{enUS:()=>D4,nlNL:()=>F4});var D4={signin:[{type:0,value:"Sign in to "},{type:1,value:"productName"}],search:[{type:1,value:"productName"},{type:0,value:" Search"}]},F4={signin:[{type:0,value:"Log in bij "},{type:1,value:"productName"}],search:[{type:1,value:"productName"},{type:0,value:" Zoeken"}]};var mi=b(R()),GR=({onLogIn:e})=>{let t=ie(m0),n=te("floatingMenu"),r=te("productName"),o=ve(),s=W(Wt),i=_("FloatingMenu",jR);if(s===null||n===!1)return null;let a=()=>{s===!0?o(Fn(!0)):e()};return(0,mi.jsxs)("button",{type:"button",className:(0,KR.default)(i.root,{[i.isLoggedIn]:s,[i.isLoggedOut]:!s}),onClick:a,children:[(0,mi.jsx)("div",{className:i.text,children:t(s?"search":"signin",{productName:r})}),(0,mi.jsxs)("div",{className:i.icon,children:[(0,mi.jsx)(WR,{className:i.logo,color:"pink"}),s===!1&&(0,mi.jsx)($R,{className:i.lock})]})]})};var Kp=b(Y());function Or(e){let{showMidSentenceSuggestions:t,showSuggestionsBeforePattern:n,showSuggestionsAfterPattern:r}=e.settings,{text:o,selection:s}=e.input;return s.start!==s.end?!1:s.end>=o.length?!0:t?n&&new RegExp(n).test(o.substring(s.end))||r&&new RegExp(r).test(o.substring(0,s.end))?!0:n===!1&&r===!1:!1}var z4={showTabHint:!1,inputHasFocus:!1,overlayCollapsed:!1,openOverlayWhenTyping:!1,overlayCollapsedUserOverwrite:!1},$p=({ui:e})=>e.overlayCollapsed,qR=ke({name:"ui",initialState:z4,reducers:{setShowTabHint(e,t){e.showTabHint=t.payload},setInputFocus(e,t){e.overlayCollapsedUserOverwrite!==!0&&(t.payload===!0&&(e.overlayCollapsed=!1),e.inputHasFocus=t.payload)},setOverlayCollapsed(e,t){t.payload.collapse===!1&&(e.openOverlayWhenTyping=!1),!(t.payload.skipWhenInputFocus&&e.inputHasFocus)&&(e.overlayCollapsed=t.payload.collapse)},setOpenOverlayWhenTyping(e,t){e.openOverlayWhenTyping=t.payload},setOverlayCollapsedUserOverwrite(e,t){e.overlayCollapsedUserOverwrite=t.payload,e.overlayCollapsed=t.payload}}}),{setShowTabHint:tu,setInputFocus:Wp,setOverlayCollapsed:is,setOpenOverlayWhenTyping:YR,setOverlayCollapsedUserOverwrite:XR}=qR.actions,QR=qR.reducer;var rP=b(Y());var as=b(Y());var ZR=b(Y());function JR(e,t,n){(0,ZR.useEffect)(()=>{let r=e.current;return r?(r.addEventListener(t,n),()=>{r.removeEventListener(t,n)}):()=>{}},[e,t,n])}var eP={root:"dd-1MBCO",actions:"dd--x4cy",closeIconContainer:"dd-1z5NR",closeIcon:"dd-8qMF-",badge:"dd-4Fpkz",formattedText:"dd-EzvTB"};var nu=b(R()),tP=({title:e})=>(0,nu.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18px",height:"18px",viewBox:"0 0 24 24","aria-labelledby":"closeTitle",children:[(0,nu.jsx)("title",{id:"closeTitle",children:e}),(0,nu.jsx)("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})]});var g0={};pt(g0,{enUS:()=>H4,nlNL:()=>B4});var H4={assistant:[{type:0,value:"Assistant"}],close:[{type:0,value:"Close"}]},B4={assistant:[{type:0,value:"Assistent"}],close:[{type:0,value:"Sluiten"}]};var _r=b(R()),V4=["search","personal-collection-search","search-autocomplete"];function $4(e,t,n,r={}){var s;let o="";return V4.includes(t)?o=vC(gv(e,n,{stripAgentPart:!0}),(s=r.searchKeywords)!=null?s:[n]):o=gv(e,n,r),r.placeholders===!0&&(o=xC(o)),o}var W4=()=>{},j4=({selected:e,suggestion:t})=>{let n=ie(g0),r=te("inlineSuggestions"),o=W(ca),[s,i]=(0,as.useState)(!1),a=te("enableSuggestionFeedback"),l=W(x=>x.input.text),c=ve(),u=_("TextSuggestion",eP),d=(0,as.useRef)(null),f=t.source==="assistant",p=a&&!f;(0,as.useEffect)(()=>{let x=setTimeout(()=>{c(V1({text:t.text,suggestion:t}))},500);return()=>{clearTimeout(x)}},[t]),JR(d,"click",()=>{c(er({suggestion:t,text:t.text,eventMetrics:{inputType:"mouse"},replace:"until-selection-end"}))});let y=()=>{c(Hs({source:t.source,text:t.text,assistantCode:t.assistantCode}))},g=(0,as.useMemo)(()=>$4(t.text,t.source,o,{stripAgentPart:r,placeholders:!0,searchKeywords:t.searchKeywords}),[r,t.text,t.source,o,t.searchKeywords]);return t.source==="gpt"&&!r?null:(0,_r.jsxs)("div",{className:u.root,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[(0,_r.jsx)(ge,{ref:d,as:"button","data-testid":"suggestions-overlay-item",selected:e,onClick:W4,children:(0,_r.jsx)(Js,{attributes:t.source==="assistant"?{"data-label":n("assistant")}:void 0,containerTagName:"div",noWrap:!1,tagName:"span",className:u.formattedText,content:g})}),p&&s&&(0,_r.jsx)("div",{className:u.actions,children:(0,_r.jsx)(Hp,{source:"overlay",context:l,suggestion:t})}),f&&s&&(0,_r.jsx)("div",{className:u.closeIconContainer,children:(0,_r.jsx)("button",{type:"button",className:u.closeIcon,onClick:y,title:n("close"),children:(0,_r.jsx)(tP,{title:n("close")})})})]})},nP=j4;var oP=b(R()),K4=({suggestions:e,selectedIndex:t,reverse:n})=>(0,rP.useMemo)(()=>{let o=e.map((s,i)=>(0,oP.jsx)(nP,{index:i,selected:i===t,suggestion:s},`${s.text}-${s.source}`));return n?o.reverse():o},[e,t,n]),jp=K4;var sP={root:"dd-PfvRI",paper:"dd-HYlyY"};var ru=b(R()),G4=()=>{let e=(0,Kp.useRef)(null),t=_("InlineSuggestionsOverlay",sP),n=W(Or),r=ve(),o=W(Wt),s=W(la),i=W($p),a=te("showTextSuggestions"),l=W(zs),c=W(Zl);return ss(()=>{setTimeout(()=>{r(is({collapse:!0,skipWhenInputFocus:!0}))})}),(0,Kp.useEffect)(()=>{let u=e.current;if(!u||!u.parentElement)return;u.parentElement.style.left="0px";let d=u.getBoundingClientRect();u.parentElement.style.left=`${Math.min(window.innerWidth-4-d.right,0)}px`}),i||!n||!a||l.length===0||o!==!0||s===!1?null:(0,ru.jsx)("div",{className:t.root,"data-variant":"inline",children:(0,ru.jsx)("div",{ref:e,className:t.paper,children:(0,ru.jsx)(Ht,{children:(0,ru.jsx)(jp,{suggestions:l,selectedIndex:c})})})})},iP=G4;var ou=b(R()),q4=({children:e})=>{let n=te("locale").replace("-","");return(0,ou.jsx)(jy.Provider,{value:n,children:e})},Y4=({store:e,customStyles:t={},children:n})=>(0,ou.jsx)(h1,{store:e,children:(0,ou.jsx)(q4,{children:(0,ou.jsx)(Qa.Provider,{value:t,children:n})})}),ls=Y4;var qp=b(Oe()),Da=b(Y());var aP=b(Y());function lP(e,t){let[n,r]=(0,aP.useState)(()=>{if(typeof window=="undefined")return t;try{let s=window.localStorage.getItem(e);return s?JSON.parse(s):t}catch(s){return Z.error(s),t}});return[n,s=>{try{let i=s instanceof Function?s(n):s;r(i),typeof window!="undefined"&&window.localStorage.setItem(e,JSON.stringify(i))}catch(i){Z.error(i)}}]}var cP=()=>/Mac/i.test(navigator.platform);var dP=b(Oe()),yo=b(Y());var h0={};pt(h0,{enUS:()=>X4,nlNL:()=>Q4});var X4={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Sign in"}]},{type:0,value:" to enable "},{type:1,value:"productName"},{type:0,value:"."}],snooze:[{type:0,value:"Snooze for "},{type:8,value:"min",children:[{type:0,value:"10 minutes"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 hour"}]},{type:0,value:" or "},{type:8,value:"day",children:[{type:0,value:"1 day"}]}]},Q4={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Log in"}]},{type:0,value:" bij "},{type:1,value:"productName"},{type:0,value:"."}],snooze:[{type:0,value:"Snooze voor "},{type:8,value:"min",children:[{type:0,value:"10 minuten"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 uur"}]},{type:0,value:" of "},{type:8,value:"day",children:[{type:0,value:"1 dag"}]}]};var uP={root:"dd-uTPjX",anchor:"dd-C8lsZ",anchorButton:"dd-IoSx9"};var cs=b(R()),y0=(e,t,n)=>r=>(0,cs.jsx)("button",{className:e.anchorButton,type:"button",value:t,onClick:n,children:r},t),Z4=({className:e,loginUrl:t,isEmbedded:n,onSnooze:r,onLogIn:o})=>{let s=ie(h0),i=dn(),a=_("Login",uP),l=te("productName"),c=(0,yo.useCallback)(x=>{x.preventDefault(),r&&r(Number.parseInt(x.target.value,10))},[]),u=(0,yo.useCallback)(x=>{x.preventDefault(),i.send(fa,!0)},[t]),d=(0,yo.useMemo)(()=>x=>(0,cs.jsx)("a",{onClick:h=>{h.preventDefault(),o()},href:t,className:a.anchor,target:"_blank",rel:"noreferrer",children:x},"login"),[t]),f=(0,yo.useCallback)(x=>(0,cs.jsx)("button",{type:"button",className:a.anchorButton,onClick:u,children:x},"prompt"),[u]),{min:p,hour:y,day:g}=(0,yo.useMemo)(()=>({min:y0(a,60*10,c),hour:y0(a,60*60,c),day:y0(a,60*60*12,c)}),[]);return(0,cs.jsxs)("div",{className:(0,dP.default)(e,a.root),children:[s("loginPlease",{login:n?f:d,productName:l}),r&&(0,cs.jsxs)(yo.Fragment,{children:[(0,cs.jsx)("br",{}),s("snooze",{min:p,hour:y,day:g})]})]})},Gp=Z4;var fP={root:"dd-DoQhb",text:"dd-Jwnev"};var su=b(R()),J4=({title:e})=>{let t=_("SearchTrigger",fP),n=ve(),r=ut();return(0,su.jsxs)("button",{type:"button",className:t.root,onClick:()=>{n(Fn(!0)),r("open search",{via:"autocomplete-overlay"})},children:[(0,su.jsx)(Aa,{}),(0,su.jsx)("span",{className:t.text,children:e})]})},pP=J4;var v0={};pt(v0,{enUS:()=>eF,nlNL:()=>tF});var eF={arrowHint:[{type:0,value:"Tip: use arrow keys to navigate suggestions"}],searchHintWindows:[{type:0,value:"Press CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],searchHintMac:[{type:0,value:"Press CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],open:[{type:0,value:"Open "},{type:1,value:"productName"}],collapse:[{type:0,value:"Close"}],search:[{type:0,value:"Search"}]},tF={arrowHint:[{type:0,value:"Tip: Selecteer suggesties met pijltoetsen"}],searchHintWindows:[{type:0,value:"Druk CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],searchHintMac:[{type:0,value:"Druk CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],open:[{type:0,value:"Open "},{type:1,value:"productName"}],collapse:[{type:0,value:"Sluiten"}],search:[{type:0,value:"Zoeken"}]};var mP={root:"dd-oa7Vc",isInline:"dd-bwk31",toggleButton:"dd-MSB8Z",toggleButtonWrapper:"dd-ZkCzT",toggleButtonWrapperHidden:"dd-Sq66c",isCollapsed:"dd-vkrPk",collapsible:"dd-CWQJe",hints:"dd-IOoo3",hintsHidden:"dd-psVuT",triggers:"dd-toIoo",triggersRight:"dd-mc4l2"};var $e=b(R()),nF=({onLogIn:e})=>{let t=_("SuggestionsOverlay",mP),n=ie(v0),r=W(Or),o=W(U1),s=ve(),i=(0,Da.useRef)(null),a=te("searchTriggerKey"),l=te("productName"),c=W($p),u=W(Wt),d=W(la),[f,p]=(0,Da.useState)(null),y=te("showSearch"),g=te("showTextSuggestions"),x=te("adminUrl"),v=te("isEmbedded"),[h,m]=lP("dd-snooze-until-ms",0),w=c||h>Date.now(),E=W(zs),k=W(Zl),C=E.filter(O=>O.source!=="gpt").length,A=()=>{w&&m(0),s(XR(!w))},V=O=>{let L=Date.now()+O*1e3;m(L),Z.info(`Snooze until: ${new Date(L)}`),s(is({collapse:!0}))};return(0,Da.useEffect)(()=>{C===0&&p(null)},[E,C]),ss(()=>{s(is({collapse:!0,skipWhenInputFocus:!0}))}),u===null||d===!1?null:u===!1?(0,$e.jsxs)("div",{ref:i,className:(0,qp.default)(t.root,{[t.isCollapsed]:w}),children:[!w&&(0,$e.jsxs)("div",{className:t.triggers,children:[(0,$e.jsx)("div",{style:{flex:1}}),(0,$e.jsx)("div",{className:t.triggersRight,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("collapse"),onClick:A,isCollapsed:!1})})]}),(0,$e.jsx)("div",{className:t.toggleButtonWrapper,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("open",{productName:l}),onClick:A,isCollapsed:!0})}),(0,$e.jsx)("div",{className:t.collapsible,children:(0,$e.jsx)(Gp,{loginUrl:x,isEmbedded:v,onLogIn:e,onSnooze:V})})]}):!o||!r?null:(0,$e.jsxs)("div",{ref:i,className:(0,qp.default)(t.root,{[t.isCollapsed]:w}),children:[!w&&(0,$e.jsxs)("div",{className:t.triggers,children:[(0,$e.jsx)("div",{style:{flex:1},children:y&&(0,$e.jsx)("div",{style:{display:"inline-block"},onFocus:()=>{},onMouseOver:()=>p(n(cP()?"searchHintMac":"searchHintWindows",{searchTriggerKey:a.toUpperCase()})),onMouseLeave:()=>p(null),children:(0,$e.jsx)(pP,{title:n("search")})})}),(0,$e.jsxs)("div",{className:t.triggersRight,onFocus:()=>{},children:[(0,$e.jsx)("div",{className:(0,qp.default)(!f&&t.hintsHidden,t.hints),children:f}),(0,$e.jsx)(xs,{className:t.toggleButton,title:n("collapse"),onClick:A,isCollapsed:!1})]})]}),(0,$e.jsx)("div",{className:t.toggleButtonWrapper,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("open",{productName:l}),onClick:A,isCollapsed:!0})}),C>0&&g&&(0,$e.jsx)("div",{className:t.collapsible,onFocus:()=>{},children:(0,$e.jsx)(Ht,{children:(0,$e.jsx)(jp,{suggestions:E,selectedIndex:k,reverse:!0})})})]})},gP=nF;var im=b(Oe());var wo=b(Y());var Fa=b(Y());function Yp(e){return e.contentEditable==="true"}function rF(e){let t=0,n=0,r=window.getSelection();if(r.rangeCount!==0){let o=r.getRangeAt(0),s=o.cloneRange();s.selectNodeContents(e),s.setEnd(o.endContainer,o.endOffset),n=s.toString().length,s.selectNodeContents(e),s.setEnd(o.startContainer,o.startOffset),t=s.toString().length}return{selectionStart:t,selectionEnd:n}}function hP(e){let{selectionStart:t,selectionEnd:n}=Yp(e)?rF(e):e;return[t,n]}function yP(e){let[,t]=(0,Fa.useState)(),n=(0,Fa.useRef)(null);return n.current=hP(e),(0,Fa.useEffect)(()=>{let r=()=>{var a;let[o,s]=(a=n.current)!=null?a:[],i=hP(e);(!i||o!==i[0]||s!==i[1])&&(n.current=i,t({}))};return e.addEventListener("keyup",r),e.addEventListener("click",r),e.addEventListener("focus",r),document.addEventListener("selectionchange",r),()=>{e.removeEventListener("keyup",r),e.removeEventListener("click",r),e.removeEventListener("focus",r),document.removeEventListener("selectionchange",r)}},[e]),n.current}function vP(e,t){if(!t)return;let n=e,{value:r}=n,[o,s]=t,i=r.match(Du);if(!i||i.length===0)return;let a=0;i.find(l=>{let c=r.indexOf(l,a);return o>c&&s<c+l.length?(n.selectionStart=c,n.selectionEnd=c+l.length,!0):(a=c+l.length,!1)})}var xP=b(Y()),oF=["div","span","mark","strong","b","i","u","em"];function x0(e,t,n=0){var s;let r=e[e.length-1],o=typeof r=="object"&&r!==null?(s=r.props)==null?void 0:s.tagName:void 0;if(o==="br")return e.pop(),[...e,...t,r];if(oF.includes(o)){let i=Array.isArray(r.props.children)?r.props.children:[r.props.children];return[...e.slice(0,e.length-1),(0,xP.cloneElement)(r,{children:x0(i,t,n+1)})]}return[...e,...t]}function gi(e){return e.tagName.toLowerCase()==="textarea"}var wP={root:"dd-7-cgW",container:"dd-PsRQ8",agentText:"dd-qnW-V",tabText:"dd-cUHUr",hint:"dd-v7fSg",matchSelection:"dd-8cr8y",focus:"dd-3tr9l",resetIndent:"dd-TvQfZ",matchKeyword:"dd-oJkRD",matchPlaceholder:"dd-QvNoo",hover:"dd--wi0R",hintText:"dd-7gQQh",popover:"dd-xbRu-",popoverRoot:"dd-rA2x8",popoverContentContainer:"dd-JHICl",popoverContent:"dd--mfkC",selectionOptions:"dd-p52wn",selectionOptionsIsHidden:"dd-sSTDp",selectionOptionsButton:"dd-Q6kRY",caret:"dd-jIhc8",popoverSuggestionsRoot:"dd-iFDbL",suggestionsOverlayInputStyles:"dd-zzENA"};var CP=b(Oe());var tm=b(Y());var za=b(Y());function SP(e,t){let n;return[(...r)=>{window.cancelAnimationFrame(n);let o=t?t(...r):r;n=window.requestAnimationFrame(()=>{e(...o)})},()=>window.cancelAnimationFrame(n)]}function Xp(e){let t=(0,za.useRef)(null),[n,r]=(0,za.useState)(!1);return(0,za.useEffect)(()=>{var u;let o=!1,s=Number.parseFloat((u=window.getComputedStyle(document.body).zoom)!=null?u:"1"),[i,a]=SP((d,f)=>{let p=t.current;if(!p)return;let y=d/s,g=f/s,x=p.getBoundingClientRect(),v=y>x.x&&y<x.x+x.width&&g>x.y&&g<x.y+x.height;v&&!o?(o=!0,r(!0)):!v&&o&&(o=!1,r(!1))},({clientX:d,clientY:f})=>[d,f]),[l,c]=SP(()=>{o=!1,r(!1)});return e.addEventListener("mousemove",i),e.addEventListener("mouseleave",l),()=>{a(),c(),e.removeEventListener("mousemove",i),e.removeEventListener("mouseleave",l)}},[t]),[t,n]}function bP(e){return e.replace(/[.*+^${}()|[\]\\]/g,"\\$&")}function Qp(e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}}function EP(e){return e!=null}var TP=b(Oe()),Zp=b(Y());var vo={root:"dd-7-cgW",container:"dd-PsRQ8",agentText:"dd-qnW-V",tabText:"dd-cUHUr",hint:"dd-v7fSg",matchSelection:"dd-8cr8y",focus:"dd-3tr9l",resetIndent:"dd-TvQfZ",matchKeyword:"dd-oJkRD",matchPlaceholder:"dd-QvNoo",hover:"dd--wi0R",hintText:"dd-7gQQh",popover:"dd-xbRu-",popoverRoot:"dd-rA2x8",popoverContentContainer:"dd-JHICl",popoverContent:"dd--mfkC",selectionOptions:"dd-p52wn",selectionOptionsIsHidden:"dd-sSTDp",selectionOptionsButton:"dd-Q6kRY",caret:"dd-jIhc8",popoverSuggestionsRoot:"dd-iFDbL",suggestionsOverlayInputStyles:"dd-zzENA"};var w0=b(R()),Jp=(0,Zp.forwardRef)((o,r)=>{var s=o,{className:e,children:t}=s,n=oe(s,["className","children"]);let i=(0,Zp.useRef)(null),a=_("TabCompletion",vo);return(0,w0.jsx)("div",P(S({ref:Qp([i,r]),className:(0,TP.default)(e,a.popoverContentContainer)},n),{children:(0,w0.jsx)("div",{className:a.popoverContent,children:t})}))});var us=b(R()),sF=e=>t=>{let n=c0(t);return"top"in n&&(n.width=e.width-(t.left-e.left)-10),n},iF=({inputElement:e,boundaryRef:t,inputStyle:n,children:r,suggestion:o})=>{let s=_("TabCompletion",vo),i=Dp(),a=(0,tm.useMemo)(()=>sF(e.getBoundingClientRect()),[e]),[l,c]=Xp(e);return(0,tm.useEffect)(()=>{c?i.open():i.close()},[c]),(0,us.jsxs)("span",{children:[(0,us.jsx)("mark",{ref:Qp([l,i.triggerRef]),className:(0,CP.default)(s.matchKeyword,{[s.hover]:c}),"aria-haspopup":"dialog","aria-expanded":i.opened?"true":"false",children:r}),i.opened&&(0,us.jsx)(_a,{className:s.popover,triggerRef:i.triggerRef,boundaryRef:t,position:"below",align:"start",toStyle:a,children:(0,us.jsx)(Jp,{style:n,children:(0,us.jsx)("div",{className:s.hintText,children:o})})})]})},em=class extends ao{constructor(){super(...arguments);this.keywordMatches=[];this.preparedKeywordMatches=[];this.usedKeywordMatches=new Set}onBeforeParse(n,r){return r.keywordMatches&&r.keywordMatches!==this.keywordMatches&&(this.preparedKeywordMatches=r.keywordMatches.map(o=>P(S({},o),{keywordRegex:new RegExp(`\\b${bP(o.keyword)}\\b`,"i")})),this.keywordMatches=r.keywordMatches),this.usedKeywordMatches.clear(),n}match(n){let r=this.preparedKeywordMatches.map(s=>{if(this.usedKeywordMatches.has(s))return null;let i=n.match(s.keywordRegex);if(!i)return null;let a=n.charAt(i.index-1),l=n.charAt(i.index+s.keyword.length);return a==="{"&&l==="}"?null:{index:i.index,length:i[0].length,match:i[0],matchString:i[0],suggestion:s.suggestion,preparedKeywordMatch:s,valid:!0}}).filter(EP);if(r.length===0)return null;let o=r.reduce((s,i)=>i.index<s.index?i:s);return this.usedKeywordMatches.add(o.preparedKeywordMatch),o}replaceWith(n,r){return(0,us.jsx)(iF,{inputElement:r.inputElement,suggestion:r.suggestion,inputStyle:r.inputStyle,boundaryRef:r.boundaryRef,children:n},`keyword_${r.matchString}_${r.key}`)}asTag(){return"mark"}};var kP=b(Oe());var S0=b(R()),aF=({inputElement:e,children:t})=>{let n=_("TabCompletion",vo),[r,o]=Xp(e);return(0,S0.jsx)("mark",{ref:r,className:(0,kP.default)(n.matchPlaceholder,{[n.hover]:o}),children:t})},nm=class extends ao{match(t){let n=t.match(/(((\$!\{)|(\{))[a-zA-Z0-9_.]+\}(?!\}))/);return n?{index:n.index,length:n[0].length,match:n[0],matchString:n[0],valid:!0}:null}replaceWith(t,n){return(0,S0.jsx)(aF,{inputElement:n.inputElement,children:t},`placeholder_${n.matchString}_${n.key}`)}asTag(){return"mark"}};var om=b(Oe());var Jt=b(Y());var b0=b(R()),RP=()=>(0,b0.jsx)("svg",{width:"1.3em",height:"1.3em",focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"InsertLinkIcon",tabIndex:-1,children:(0,b0.jsx)("path",{fill:"currentColor",d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})});var Dr=b(Y());var AP=b(Xy());var PP={root:"dd-ky-Bv",content:"dd-kV5e1"};function rm(e,t,n){var o;let r=((o=e.imageSizes)==null?void 0:o[t])||e.image||n;if(!r)return null;try{return new URL(r).toString()}catch(s){return null}}function E0(e){return e.replace("https://www.","").replace("https://","")}var Vn=b(R()),lF=3,cF=e=>({image:e.image||"",text:e.text,id:e.id,title:e.title}),uF=({onSelectLink:e,onDismiss:t,placeholder:n,visitUrlText:r,linkCount:o=lF})=>{let s=_("LinkSearch",PP),[i,a]=(0,Dr.useState)(""),l=ve(),c=W(NR("url")),u=W(cT("URL")),d=(0,Dr.useMemo)(()=>u.map(cF),[u]),[f,p]=(0,Dr.useState)(d.length-1),y=te("fallbackImage"),g=m=>{let w=m.target;a(w.value)},x=(m,w)=>{m.stopPropagation(),m.preventDefault(),window.open(w,"_blank")},v=m=>{var k;let w=f-1<0?d.length-1:f-1,E=f+1===d.length?0:f+1;m.code==="Escape"&&(a(""),t()),m.code==="ArrowUp"&&p(w),m.code==="ArrowDown"&&p(E),m.code==="Enter"&&e(((k=d[f])==null?void 0:k.text)||i)},h=(0,Dr.useCallback)((0,AP.default)(m=>{l(Us({query:m,type:"URL",tags:["link-search"]}))},300),[]);return(0,Dr.useEffect)(()=>{i&&h(i)},[i]),(0,Dr.useEffect)(()=>()=>{l(If())},[]),(0,Vn.jsxs)("div",{className:s.root,children:[(0,Vn.jsx)(Ht,{withDivider:!0,children:(i?d:c).slice(0,o).map((m,w)=>(0,Vn.jsx)(ge,{selected:f===w,onClick:()=>e(m.text),"data-testid":"linksearch-suggestion",children:(0,Vn.jsxs)(Se,{children:[(0,Vn.jsx)(Se.Image,{src:rm(m,"small",y||void 0),title:m.title||m.text}),(0,Vn.jsxs)(Se.Content,{className:s.content,cropText:!0,children:[(0,Vn.jsx)(Se.Title,{children:m.title||E0(m.text)}),m.title&&E0(m.text)]}),(0,Vn.jsx)(ge.Actions,{children:(0,Vn.jsx)(ge.ActionButton,{label:r,onClick:E=>x(E,m.text)})})]})},m.text))}),(0,Vn.jsx)(mc,{value:i,onChange:g,autoFocus:!0,placeholder:n,onKeyUp:v})]})},IP=uF;var T0={};pt(T0,{enUS:()=>dF,nlNL:()=>fF});var dF={insertLink:[{type:0,value:"Insert link"}],linkInputPlaceholder:[{type:0,value:"Search, type or paste link"}],visitUrl:[{type:0,value:"Visit"}]},fF={insertLink:[{type:0,value:"Voeg link toe"}],linkInputPlaceholder:[{type:0,value:"Zoek, typ of plak link"}],visitUrl:[{type:0,value:"Bekijk"}]};var Zt=b(R()),pF=(0,Jt.forwardRef)((e,t)=>{let n=_("TabCompletion",vo);return(0,Zt.jsx)("mark",{ref:t,className:(0,om.default)(n.matchSelection)},"selection-start")}),mF=({startRef:e,boundaryRef:t,inputStyle:n,inputElement:r,children:o})=>{let s=ie(T0),i=_("TabCompletion",vo),a=(0,Jt.useRef)(null),l=(0,Jt.useRef)(null),[c,u]=(0,Jt.useState)(null),d=ve(),f=Dp(document.activeElement===r),[p]=(0,Jt.useState)(()=>document.createRange());f.triggerRef.current=p,(0,Jt.useEffect)(()=>()=>p.detach(),[]),(0,Jt.useEffect)(()=>{let g=e.current,x=a.current;!g||!x||(p.setStart(g,0),p.setEnd(x,0))},[e.current,a.current]),ss(()=>{f.close()});let y=(0,Jt.useCallback)(g=>{let x=p.toString(),v=/^http(s?):\/\//.test(g)?g:`https://${g}`;d(Ef({text:`[${x}](${v})`,replace:"selection"}))},[]);return(0,Zt.jsxs)("span",{children:[(0,Zt.jsx)("mark",{ref:a,className:(0,om.default)(i.matchSelection),"aria-haspopup":"dialog","aria-expanded":f.opened?"true":"false",children:o}),f.opened&&(0,Zt.jsx)(_a,{className:i.popoverRoot,triggerRef:f.triggerRef,boundaryRef:t,position:"above",align:"start",children:(0,Zt.jsxs)(Jp,{style:n,ref:l,children:[(0,Zt.jsx)("div",{className:(0,om.default)(i.selectionOptions,{[i.selectionOptionsIsHidden]:c!==null}),children:(0,Zt.jsxs)("button",{type:"button",tabIndex:c===null?-1:void 0,className:i.selectionOptionsButton,onClick:()=>u("insertLink"),children:[(0,Zt.jsx)(RP,{}),(0,Zt.jsx)("span",{children:"\xA0"}),(0,Zt.jsx)("span",{children:s("insertLink")})]})}),c==="insertLink"&&(0,Zt.jsx)(IP,{placeholder:s("linkInputPlaceholder"),visitUrlText:s("visitUrl"),onSelectLink:y,onDismiss:()=>{u(null),f.close()}})]})})]},"selection-end")},sm=class extends ao{constructor(){super(...arguments);this.charCount=0;this.foundIndex=0;this.startRef=null}onBeforeParse(n,r){return this.props=r,this.charCount=0,this.startRef=(0,Jt.createRef)(),this.foundIndex=0,n}match(n){if(!this.props||this.props.selection===null||this.foundIndex===2)return null;let[r,o]=this.props.selection;if(r===o)return null;let s=this.foundIndex===0?r:o,i=s>=this.charCount&&s<=this.charCount+n.length?{index:s-this.charCount,length:0,match:"",valid:!0}:null;i&&this.foundIndex++;let a=this.foundIndex===1;return i&&a?this.charCount+=s-this.charCount:this.charCount+=n.length,i?S({isStart:a},i):null}replaceWith(n,r){return r.isStart?(0,Zt.jsx)(pF,{ref:this.startRef}):(0,Zt.jsx)(mF,{inputElement:r.inputElement,startRef:this.startRef,boundaryRef:r.boundaryRef,inputStyle:r.inputStyle})}asTag(){return"mark"}};var xo=b(R()),gF=({enabled:e,content:t,tabText:n,showTabHint:r,showTabCompletion:o,showStyleSuggestions:s,keywordMatches:i,inputElement:a,source:l})=>{let c=_("TabCompletion",wP),u=te("insertLink"),d=te("showMidSentenceSuggestions"),f=te("inlineSuggestions"),p=yP(a),y=(0,wo.useRef)(null),g=W(Wt);(0,wo.useEffect)(()=>{gi(a)&&p&&vP(a,p)},[p]);let x=(0,wo.useCallback)(m=>{if(!o||!n)return m;let w=[(0,xo.jsx)("span",{className:c.resetIndent,children:"\u200B"},"u200B"),(0,xo.jsx)("span",{"data-testid":"tab-completion",className:(0,im.default)(c.tabText,c.resetIndent),"data-source":l,children:n},"tabText")];return r&&w.push((0,xo.jsx)("span",{className:(0,im.default)(c.hint,c.resetIndent),children:(0,xo.jsx)(Nu,{keyCode:"tab"},"tabHint")},"tabHint")),x0(m,w)},[o,n,r]),v=(0,wo.useMemo)(()=>{let m=[];return u&&m.push(new sm("selection")),m.push(new nm("placeholders")),s&&m.push(new em("keywords")),m},[f,u,s]),h=(0,wo.useMemo)(()=>{let m=window.getComputedStyle(a);return{"--dd-color":m.color,"--dd-font-size":m.fontSize,"--dd-font-family":m.fontFamily,"--dd-font-variant":m.fontVariant}},[]);return!e||!g?null:(0,xo.jsxs)("div",{ref:m=>{m!=null&&m.parentElement&&(y.current=m==null?void 0:m.parentElement)},className:c.root,style:h,children:[(0,xo.jsx)(Js,{tagName:"span",containerTagName:"div",className:(0,im.default)(c.container,c.agentText),disableLineBreaks:gi(a),content:t||"\u200B",onAfterParse:x,matchers:v,selection:p,keywordMatches:i,inputElement:a,inputStyle:h,boundaryRef:y,inlineSuggestionsOnlyAtEnd:!d}),(0,xo.jsx)("br",{})]},"tab-completion")},hF=e=>{var x,v,h;let{input:t,ui:n,settings:r,styleSuggestions:o,conversation:s}=e,i=ua({input:t}),a=(i==null?void 0:i.text)||"",l=(i==null?void 0:i.source)||"",c=(x=t.html)!=null?x:ha(t.text),u=a.indexOf(t.text)===0?a.slice(t.text.length):"",{showTabHint:d}=n,{isSupported:f}=s,{showTabCompletion:p,visible:y,showStyleSuggestions:g}=r;return{showTabHint:d,showStyleSuggestions:g,showTabCompletion:p&&Or(e),content:c,tabText:u,source:l,keywordMatches:(h=(v=o.list)==null?void 0:v.keywordMatches)!=null?h:[],enabled:y&&f!==!1}},LP=g1(hF)(gF);var ds=b(Y());var yF={token:null,interval:null},C0=he("passwordlessToken/getTemporaryPasswordlessToken",(e,t)=>I(void 0,null,function*(){let{deepdeskAPI:n}=t.extra;return{token:yield n.requestPasswordlessToken()}})),k0=he("passwordlessToken/pollPasswordlessToken",(e={},t)=>{let{interval:n=1e3*60*10}=e,{dispatch:r}=t;return r(C0()),setInterval(()=>r(C0()),n)}),MP=ke({name:"passwordlessToken",initialState:yF,reducers:{stopPollPasswordlessToken(e){e.interval&&clearInterval(e.interval),e.interval=null}},extraReducers:e=>{e.addCase(C0.fulfilled,(t,n)=>{t.token=n.payload.token}),e.addCase(k0.fulfilled,(t,n)=>{t.interval=n.payload})}}),{stopPollPasswordlessToken:NP}=MP.actions,OP=MP.reducer;function vF(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}var _P=$t([QT],e=>e.map(n=>({text:n.response,title:n.name,callToAction:n.callToAction,editable:n.editable,isLoading:n.isLoading,specialType:n.specialType,rule:{id:vF(n.code),label:n.code,name:n.name,description:n.name}})));var am=b(Y());var P0=b(Oe());var R0=b(R()),iu=()=>(0,R0.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 512 512",xmlns:"http://www.w3.org/2000/svg",children:(0,R0.jsx)("path",{d:"M502.6 70.63l-61.25-61.25C435.4 3.371 427.2 0 418.7 0H255.1c-35.35 0-64 28.66-64 64l.0195 256C192 355.4 220.7 384 256 384h192c35.2 0 64-28.8 64-64V93.25C512 84.77 508.6 76.63 502.6 70.63zM464 320c0 8.836-7.164 16-16 16H255.1c-8.838 0-16-7.164-16-16L239.1 64.13c0-8.836 7.164-16 16-16h128L384 96c0 17.67 14.33 32 32 32h47.1V320zM272 448c0 8.836-7.164 16-16 16H63.1c-8.838 0-16-7.164-16-16L47.98 192.1c0-8.836 7.164-16 16-16H160V128H63.99c-35.35 0-64 28.65-64 64l.0098 256C.002 483.3 28.66 512 64 512h192c35.2 0 64-28.8 64-64v-32h-47.1L272 448z"})});var DP={root:"dd-WcEru",entity:"dd-LfP8y",entityText:"dd-L-v0f",iconWrapper:"dd-9Deh1",icon:"dd-tM7E2",iconClicked:"dd-EEdDL"};var Fr=b(R()),xF=({entities:e})=>{let t=_("EntitiesWidgetList",DP),[n,r]=(0,am.useState)(void 0),o=ve(),s=()=>{r(void 0)},i=a=>{e&&(r(e.indexOf(a)),Ir(a.text),o(ro({name:"entity copied",data:{entity:a,type:"copy"}})))};return(0,am.useEffect)(()=>{let a=setTimeout(s,500);return()=>{clearTimeout(a)}},[n]),!e||e.length===0?null:(0,Fr.jsx)("div",{className:t.root,"data-testid":"widget-entities-list",children:e.map((a,l)=>(0,Fr.jsxs)("button",{title:a.text,className:t.entity,type:"button",onClick:()=>i(a),children:[(0,Fr.jsx)("span",{className:t.entityText,children:a.text}),(0,Fr.jsxs)("span",{className:t.iconWrapper,children:[(0,Fr.jsx)("span",{className:(0,P0.default)(t.icon),children:(0,Fr.jsx)(iu,{})}),(0,Fr.jsx)("span",{className:(0,P0.default)(t.icon,n===l&&t.iconClicked),children:(0,Fr.jsx)(iu,{})})]})]},a.text))})},FP=xF;var A0=b(R()),zP=()=>(0,A0.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,A0.jsx)("path",{d:"M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9",stroke:"currentColor",strokeWidth:"1.5",fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"})});var jP=b(Y());var HP={root:"dd-ohnXe",trigger:"dd-7i-S3",button:"dd-t53Cg",nav:"dd-qZFnm",item:"dd-FZC0F"};var BP={root:"dd-nazq3",rotation:"dd-3EHTv"};var VP=b(R()),wF=({size:e=12})=>{let t=_("LoadingSpinner",BP);return(0,VP.jsx)("span",{"data-testid":"loading-spinner",style:{width:`${e}px`,height:`${e}px`},className:t.root})},UP=wF;var I0=b(R()),$P=()=>(0,I0.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",height:"1em",viewBox:"0 0 512 512",fill:"currentColor",children:(0,I0.jsx)("path",{d:"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32s14.3 32 32 32s32-14.3 32-32z"})});var au=b(R()),WP=e=>(0,au.jsxs)("svg",P(S({xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 448 512","aria-labelledby":"checkTitle"},e),{children:[(0,au.jsx)("title",{id:"checkTitle",children:"Check"}),(0,au.jsx)("path",{fill:"#666",d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"})]}));var L0={};pt(L0,{enUS:()=>SF,nlNL:()=>bF});var SF={error:[{type:0,value:"Something went wrong"}]},bF={error:[{type:0,value:"Er ging iets fout"}]};var Pn=b(R()),EF=3e3,TF=({assistantOptions:e})=>{let t=_("OnDemandAssistants",HP),n=ie(L0),r=(0,jP.useRef)(),o=ai(or),s=ai(so),i=W(oC),a=W(sC),l=ut(),c=a.filter(f=>f.isPinned),u=a.filter(f=>!f.isPinned),d=f=>I(void 0,null,function*(){clearTimeout(r.current),l("trigger on demand assistant",{assistantCode:f}),f===i?yield s.call({transcript:e.transcript}):yield o.call(P(S({},e),{assistantCode:f})),r.current=setTimeout(()=>o.reset(),EF)});return a.length===0?null:(0,Pn.jsxs)("div",{className:t.root,children:[c.map(({assistant:f,assistantName:p,displayName:y})=>(0,Pn.jsx)("button",{type:"button",className:t.button,disabled:o.state==="loading",onClick:()=>d(f),children:y||p},f)),u.length>0&&(0,Pn.jsxs)(vt,{placement:"top-end",children:[(0,Pn.jsx)(vt.Trigger,{className:t.trigger,disabled:o.state==="loading",children:(0,Pn.jsx)(Fp,{"data-testid":"trigger"})}),(0,Pn.jsx)(vt.Content,{className:t.nav,"data-testid":"popover",children:u.map(({assistant:f,assistantName:p,displayName:y})=>(0,Pn.jsx)(vt.Button,{className:t.item,disabled:o.state==="loading",onClick:()=>d(f),children:y||p},f))})]}),o.state==="loading"&&(0,Pn.jsx)(UP,{}),o.state==="done"&&(0,Pn.jsx)(WP,{"data-testid":"trigger-done"}),o.state==="error"&&(0,Pn.jsx)(Vk,{trigger:(0,Pn.jsx)($P,{}),children:n("error")})]})},KP=TF;var YP=b(Y());var GP={loadingBar:"dd-6as-V",placeHolderShimmer:"dd-TFYmA"};var qP=b(R()),CF=({width:e})=>{let t=_("LoadingProgressBar",GP);return(0,qP.jsx)("div",{className:t.loadingBar,style:{width:e}})},lm=CF;var So=b(R()),cm=({title:e})=>{let t=(0,YP.useRef)(null);return Ou(t),(0,So.jsx)(ge,{ref:t,children:(0,So.jsx)(Se,{children:(0,So.jsxs)(Se.Content,{children:[(0,So.jsx)(Se.Title,{children:e}),(0,So.jsx)(lm,{width:"60%"}),(0,So.jsx)(lm,{width:"90%"}),(0,So.jsx)(lm,{width:"50%"})]})})})};var lu={};pt(lu,{enUS:()=>kF,nlNL:()=>RF});var kF={useCue:[{type:0,value:"Add to message"}],__summarizerAssistant__:[{type:0,value:"Summary"}],copyCue:[{type:0,value:"Copy"}],removeCue:[{type:0,value:"Close"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}]},RF={useCue:[{type:0,value:"Voeg toe aan bericht"}],__summarizerAssistant__:[{type:0,value:"Samenvatting"}],copyCue:[{type:0,value:"Kopi\xEBren"}],removeCue:[{type:0,value:"Sluiten"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}]};var hi=b(Y());var M0={title:"dd-YBHrC",fadeup:"dd-cRM0K",fadedown:"dd-7D4Pq",selected:"dd-bueui",actions:"dd-9Iqn9",thumbsUp:"dd-6QwVx",thumbsDown:"dd-d3E8l",form:"dd-sPNU2",formInput:"dd-F3E4I",formSubmit:"dd-vw5S0",actionButton:"dd-cCWyJ",editableCue:"dd-nWSD-",inputSpace:"dd-DGYB1"};var Ot=b(R()),PF=500,AF=100,IF=({content:e,onChange:t,onCopy:n})=>{let r=(0,hi.useRef)(null),o=_("WidgetCue",M0);return(0,hi.useEffect)(()=>{let s=r.current;if(!s)return;s.style.setProperty("height","0px");let i=Math.min(Math.max(s.scrollHeight,AF),PF);s.style.setProperty("height",`${i}px`)},[e]),(0,Ot.jsx)("textarea",{ref:r,className:o.editableCue,onCopy:n,onChange:t,value:e})},LF=({cue:e,onCallToAction:t,onRemove:n,onCopy:r,onUse:o})=>{var g;let s=_("WidgetCue",M0),i=ie(lu),a=ut(),l=te("hasKeyboardInput"),[c,u]=(0,hi.useState)(e.text),d=()=>{t&&t(e),n(e)},f=x=>{r&&r(x,e)},p=x=>{o&&o(x,e)},y=x=>{x.preventDefault(),x.stopPropagation(),n(e)};return(0,hi.useEffect)(()=>{a("Assistant response displayed",{name:e.rule.name,description:e.rule.description,group:e.rule.label,cueText:e.text})},[]),(0,Ot.jsxs)(ge,{"data-testid":"cue",children:[(0,Ot.jsx)(Se,{children:(0,Ot.jsxs)(Se.Content,{children:[e.title&&(0,Ot.jsx)(Se.Title,{className:s.title,"data-testid":"widget-cue-title",children:e.rule.label.startsWith("__")?i(e.rule.label):e.title}),e.specialType==="summary"||e.editable?(0,Ot.jsx)(IF,{content:c,onCopy:()=>{let x=document.getSelection();x&&f(x.toString())},onChange:x=>{var v;return u((v=x.target.value)!=null?v:"")}}):(0,Ot.jsx)(ho,{content:e.text,useLabel:i("useCue"),copyLabel:i("copyCue"),onCopy:f,onUse:l?p:void 0})]})}),(0,Ot.jsxs)(ge.ButtonsContainer,{children:[(0,Ot.jsxs)("div",{className:s.actions,children:[(e.specialType==="summary"||e.editable)&&(0,Ot.jsx)(ge.Button,{onClick:()=>f(c),children:i("copyCue")}),e.callToAction&&(0,Ot.jsx)(ge.Button,{onClick:d,children:e.callToAction.label}),(0,Ot.jsx)(ge.Button,{onClick:y,children:i("removeCue")})]}),e.specialType==="summary"?(0,Ot.jsx)(li,{eventName:"summary feedback",feedbackText:(g=e.text)!=null?g:"",feedbackType:"summary",eventData:{summary:e.text}}):(0,Ot.jsx)(li,{eventName:"Assistant response feedback",eventData:{name:e.rule.name,group:e.rule.label,description:e.rule.description,cueText:e.text},feedbackText:e.text,feedbackType:"assistant"})]})]})},XP=LF;var Ha=b(R()),MF=({cues:e})=>{let t=ve(),n=dn(),r=ie(lu),o=ut(),s=c=>{t(Gf({code:c.rule.label})),o("Assistant response closed",{name:c.rule.name,group:c.rule.label,description:c.rule.description,cueText:c.text})},i=(c,u)=>{switch(Ir(c),u.specialType){case"summary":o("summary copied to clipboard",{originalText:u.text,finalText:c,assistant:u.rule.label});break;default:o("Assistant response copied",{name:u.rule.name,group:u.rule.label,description:u.rule.description,copiedText:c})}},a=c=>{c.callToAction&&(t(Kf(c)),o("Assistant call to action",{name:c.rule.name,group:c.rule.label,description:c.rule.description,eventName:c.callToAction.event,value:c.callToAction.value}))},l=(c,u)=>{var d;n.send(Pr,{text:c,suggestion:{source:"assistant",assistantCode:(d=u.rule)==null?void 0:d.label,sourceText:c}}),o("Assistant response used",{name:u.rule.name,group:u.rule.label,description:u.rule.description,usedText:c})};return(0,Ha.jsx)(Ha.Fragment,{children:e.map(c=>c.isLoading?(0,Ha.jsx)(cm,{title:c.rule.label.startsWith("__")?r(c.rule.label):c.title},c.rule.id):(0,Ha.jsx)(XP,{cue:c,onCallToAction:a,onRemove:s,onCopy:i,onUse:l},c.rule.id))})},QP=MF;var um=b(Y());var ZP={root:"dd-cvTAY",label:"dd-QWQxD",value:"dd-WSUHF",copyButton:"dd-67o9H",copyButtonText:"dd-oos-l",isTrue:"dd--1g2O",isFalse:"dd-sz2ir"};var hr=b(R());function NF(e,t){return t.split(".").reduce((n,r)=>!n||typeof n!="object"||!(r in n)?null:n[r],e)}var JP=({data:e,schema:t})=>{let n=_("WidgetCustomData",ZP),r=o=>{Ir(o)};return(0,um.useEffect)(()=>{Z.info("Custom data",e,t)},[e]),(0,hr.jsx)("dl",{className:n.root,children:t.map(o=>{let s=NF(e,o.path);return(0,hr.jsxs)(um.Fragment,{children:[(0,hr.jsx)("dt",{className:n.label,children:o.label}),(0,hr.jsx)("dd",{className:n.value,children:o.type==="boolean"&&s?(0,hr.jsx)("span",{className:n.isTrue,children:o.trueValue}):o.type==="boolean"&&!s?(0,hr.jsx)("span",{className:n.isFalse,children:o.falseValue}):typeof s=="string"||typeof s=="number"?(0,hr.jsxs)("button",{type:"button",onClick:()=>r(`${s}`),className:n.copyButton,children:[(0,hr.jsx)("span",{className:n.copyButtonText,children:s}),(0,hr.jsx)(iu,{})]}):"-"})]},o.label)})})};var rt=b(Y());var Ba={};pt(Ba,{enUS:()=>OF,nlNL:()=>_F});var OF={inputPlaceholder:[{type:0,value:"What is your question?"}],useCue:[{type:0,value:"Add to message"}],copyCue:[{type:0,value:"Copy"}],removeCue:[{type:0,value:"Close"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}],submitLabel:[{type:0,value:"Submit"}],resetLabel:[{type:0,value:"Reset"}],showMore:[{type:0,value:"Show "},{type:1,value:"amount"},{type:0,value:" more"}]},_F={inputPlaceholder:[{type:0,value:"Wat is je vraag?"}],useCue:[{type:0,value:"Voeg toe aan bericht"}],copyCue:[{type:0,value:"Kopi\xEBren"}],removeCue:[{type:0,value:"Sluiten"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}],submitLabel:[{type:0,value:"Verzend"}],resetLabel:[{type:0,value:"Gesprek wissen"}],showMore:[{type:0,value:"Toon "},{type:1,value:"amount"},{type:0,value:" meer"}]};var dm={form:"dd-pleCH",formInput:"dd-pGJMY",formSubmit:"dd--gkRg",actionButton:"dd-I2NEH",resetContainer:"dd-qKIDX",sources:"dd-xf9c6",source:"dd-a-vyX",tooltip:"dd-EsgcZ",linkContent:"dd-gARDA",showMoreSources:"dd-uDGi-"};var tA=b(Y());var eA={error:"dd-CoAuB"};var N0={};pt(N0,{enUS:()=>DF,nlNL:()=>FF});var DF={errorPrefix:[{type:0,value:"Error:"}]},FF={errorPrefix:[{type:0,value:"Foutmelding:"}]};var cu=b(R()),nA=({message:e})=>{let t=(0,tA.useRef)(null),n=_("WidgetCardError",eA),r=ie(N0);return Ou(t),(0,cu.jsx)(ge,{ref:t,children:(0,cu.jsx)(Se,{children:(0,cu.jsxs)(Se.Content,{className:n.error,children:[r("errorPrefix")," ",e]})})})};var we=b(R()),zF=3,HF=({sources:e,onClick:t})=>{let n=ie(Ba),r=_("WidgetKnowledgeAssistant",dm),[o,s]=(0,rt.useState)(!1),i=o?e:e.slice(0,zF);return i.length===0?null:(0,we.jsxs)("ul",{className:r.sources,children:[i.map(a=>(0,we.jsx)("li",{className:r.source,"data-testid":"knowledge-assist-source",children:(0,we.jsxs)(vt,{tooltip:!0,placement:"top-start",children:[(0,we.jsx)(vt.Trigger,{as:"a",rel:"noreferrer",target:"_blank",href:a.url,onClick:l=>{l.stopPropagation(),t(a)},children:(0,we.jsx)("span",{className:r.linkContent,children:a.name})}),a.url&&(0,we.jsx)(vt.Content,{className:r.tooltip,children:decodeURIComponent(a.url)})]})},a.name)),i<e&&(0,we.jsx)("button",{type:"button",className:r.showMoreSources,onClick:()=>s(!0),children:n("showMore",{amount:e.length-i.length})})]})},BF=({title:e,description:t})=>(0,we.jsx)(ge,{"data-testid":"knowledge-assist-empty-state",children:(0,we.jsx)(Se,{children:(0,we.jsxs)(Se.Content,{children:[(0,we.jsx)(Se.Title,{children:e}),(0,we.jsx)(ho,{content:t})]})})}),UF=({innerRef:e,item:t,index:n,hasKeyboardInput:r,onCopy:o,onUse:s,onSourceClick:i})=>{var l;let a=ie(Ba);return(0,we.jsxs)(ge,{"data-testid":"knowledge-assist-answer",ref:e,children:[(0,we.jsx)(Se,{children:(0,we.jsxs)(Se.Content,{children:[(0,we.jsx)(Se.Title,{children:t.question}),(0,we.jsx)(ho,{content:t.answer.answer,useLabel:a("useCue"),copyLabel:a("copyCue"),onCopy:o,onUse:r?s:void 0}),(0,we.jsx)(HF,{sources:(l=t.answer.sources)!=null?l:[],onClick:c=>i(c,t.question)})]})}),(0,we.jsxs)(ge.ButtonsContainer,{children:[(0,we.jsx)("div",{}),(0,we.jsx)(li,{eventName:"knowledge assist feedback",eventData:{question:t.question,isFollowUpQuestion:n>0,isAgent:!0,answer:t.answer.answer},feedbackText:t.answer.answer,feedbackType:"assistant"})]})]})},O0=(0,rt.createContext)(null),fm=({assistantCode:e,evaluateKnowledgeAssistFn:t,initialQuestion:n,children:r})=>{let[o,s]=(0,rt.useState)(null),[i,a]=(0,rt.useState)(!1),[l,c]=(0,rt.useState)(null),[u,d]=(0,rt.useState)(!!n),[f,p]=(0,rt.useState)(null),y=ve(),g=ut(),x=ai(m=>{if(!e)throw new Error("No knowledge assistant was defined");return c(null),t({assistantCode:e,input:m,threadId:o,onNewThreadId(w){s(w)}})},{onSuccess(m){var w;g("knowledge assist question answered",{question:m.question,answer:m.answer.answer,sources:(w=m.answer.sources)!=null?w:[],isFollowUpQuestion:m.threadId===o,isAutoInitiated:u}),d(!1)},onError(m){var w;c((w=m.message)!=null?w:"Unknown error")}}),v=m=>I(void 0,null,function*(){a(!0),p(m),yield x.call(m),a(!1),p(null)}),h={isEnabled:!!e,isSubmitting:i,threadId:o,pendingInput:f,errorMessage:l,onSubmit:v,onReset(){o&&y(ga(o)),c(null),s(null)}};return(0,rt.useEffect)(()=>{n&&h.isEnabled&&v(n)},[n]),(0,we.jsx)(O0.Provider,{value:h,children:r})},pm=()=>{let e=ie(Ba),t=_("WidgetKnowledgeAssistant",dm),n=(0,rt.useContext)(O0),r=(0,rt.useRef)(null),[o,s]=(0,rt.useState)(""),i=l=>{s(l.target.value)},a=l=>{l.preventDefault(),n.onSubmit(o).then(()=>{var c;r.current&&((c=r.current)==null||c.focus(),s(""))})};return n.isEnabled?(0,we.jsxs)("form",{className:t.form,onSubmit:a,children:[(0,we.jsx)("input",{ref:r,className:t.formInput,placeholder:e("inputPlaceholder"),type:"text",disabled:n.isSubmitting,value:o,onChange:i}),(0,we.jsx)("button",{type:"submit",disabled:n.isSubmitting||o==="",className:t.formSubmit,children:e("submitLabel")})]}):null},mm=({title:e,emptyState:t})=>{var y,g;let n=ie(Ba),r=ut(),o=_("WidgetKnowledgeAssistant",dm),s=(0,rt.useRef)(null),i=(0,rt.useContext)(O0),a=(g=W(bc((y=i.threadId)!=null?y:-1)))!=null?g:[],l=te("hasKeyboardInput"),c=dn(),u=x=>{Ir(x),r("Assistant response copied",{name:"Knowledge Assistant",group:"knowlegde-assist",description:"",copiedText:x})},d=(x,v)=>{r("knowledge assist source viewed",{question:v,sourceViewed:x.url||x.name})},f=x=>{var v;x.preventDefault(),i.onReset(),r("knowledge assist reset",{threadId:(v=i.threadId)!=null?v:void 0})},p=x=>{c.send(Pr,{text:x,suggestion:{source:"assistant",sourceText:x}}),r("Assistant response used",{name:"Knowledge Assistant",group:"knowlegde-assist",description:"",usedText:x})};return!i.isEnabled||(a==null?void 0:a.length)===0&&!i.isSubmitting&&!t&&!i.errorMessage?null:(0,we.jsxs)(rt.Fragment,{children:[(0,we.jsx)(wr,{type:"knowledge",title:e,"data-testid":"knowledge",children:(0,we.jsxs)(Ht,{withDivider:!0,children:[t&&a.length===0&&!i.pendingInput&&(0,we.jsx)(BF,S({},t)),a.map((x,v)=>(0,we.jsx)(UF,{innerRef:v===a.length-1?s:void 0,item:x,index:v,hasKeyboardInput:l,onCopy:u,onUse:p,onSourceClick:d},`${x.question}_${x.answer}_${v}`)),i.pendingInput&&(0,we.jsx)(cm,{title:i.pendingInput}),i.errorMessage&&(0,we.jsx)(nA,{message:i.errorMessage})]})}),a.length>0&&(0,we.jsx)("div",{className:o.resetContainer,children:(0,we.jsx)(ge.Button,{disabled:i.threadId===null||i.isSubmitting,onClick:f,children:n("resetLabel")})})]})};var sA=b(Y());var VF=/(https?:\/\/[^\s]+)/,oA=e=>e.split(" ").find(t=>VF.test(t));var $n=b(R()),$F=({suggestion:e,lines:t,onUse:n})=>{var d;let r=e.text||e.url||e.message,o=oA(r),s=ie(Qc),i=te("showImages"),a=te("fallbackImage"),l=te("hasKeyboardInput"),c=f=>{f.preventDefault(),f.stopPropagation(),l&&n(r)},u=(0,sA.useCallback)(f=>{window.open(o,"_blank"),f.stopPropagation(),f.preventDefault()},[o]);return(0,$n.jsxs)(ge,{onClick:l?c:void 0,"data-testid":"edit-suggestion",children:[(0,$n.jsxs)(Se,{children:[i&&e.image&&(0,$n.jsx)(Se.Image,{src:rm(e,"small",a||void 0),title:e.title}),(0,$n.jsxs)(Se.Content,{children:[e.title&&(0,$n.jsx)(Se.Title,{"data-testid":"widget-suggestion-title",children:e.title}),e.searchKeywords&&((d=e.searchKeywords)==null?void 0:d.length)>0&&(0,$n.jsx)(ge.Labels,{labels:e.searchKeywords}),(0,$n.jsx)(Se.Content,{cropText:t==="single",lineClamp:t==="multiple",children:r})]})]}),(0,$n.jsxs)(ge.Actions,{children:[o&&(0,$n.jsx)(ge.ActionButton,{onClick:u,label:s("visitUrl")}),l&&(0,$n.jsx)(ge.ActionButton,{primary:!0,onClick:c,label:s("useSuggestion")})]})]})},iA=$F;var uu=b(R()),WF=({lines:e,suggestions:t})=>{let n=dn(),r=(o,s)=>{n.send(Pr,{text:o,suggestion:P(S({},s),{source:s.source,sourceText:s.text})})};return(0,uu.jsx)(uu.Fragment,{children:t.map(o=>(0,uu.jsx)(iA,{suggestion:o,lines:e,onUse:s=>r(s,o)},o.text||o.url||o.message))})},aA=WF;var du={};pt(du,{enUS:()=>jF,nlNL:()=>KF});var jF={waiting:[{type:0,value:"Loading\u2026"}],waitingForConversation:[{type:0,value:"Waiting for conversation\u2026"}],notSupported:[{type:0,value:"This conversation is not supported"}],noResults:[{type:0,value:"No results found\u2026"}],titleCues:[{type:0,value:"Assistant updates"}],actions:[{type:0,value:"Shortcuts"}],linkStudioLogin:[{type:0,value:"My "},{type:1,value:"productName"}],linkSummary:[{type:0,value:"Summarize"}],linkKnowledgeSearch:[{type:0,value:"Knowledge Assist"}],linkSearch:[{type:0,value:"Search"}],close:[{type:0,value:"Close"}]},KF={waiting:[{type:0,value:"Laden\u2026"}],waitingForConversation:[{type:0,value:"Wachten op gesprek\u2026"}],notSupported:[{type:0,value:"Dit gesprek wordt niet ondersteund"}],noResults:[{type:0,value:"Geen resultaten gevonden\u2026"}],titleCues:[{type:0,value:"Assistant updates"}],actions:[{type:0,value:"Shortcuts"}],linkStudioLogin:[{type:0,value:"Mijn "},{type:1,value:"productName"}],linkSummary:[{type:0,value:"Gesprek samenvatten"}],linkKnowledgeSearch:[{type:0,value:"Knowledge assist"}],linkSearch:[{type:0,value:"Zoeken"}],close:[{type:0,value:"Sluiten"}]};var Ua={root:"dd-W9VCG",loginText:"dd--dS6t",stateText:"dd-348OC",footer:"dd-tvofr",shortcutList:"dd-MuKK-",shortcut:"dd-5CnK9",footerShortcut:"dd-dH7XJ",link:"dd-DRo0x"};var ue=b(R()),lA=(e,t)=>{let n=W(Wt);(0,ds.useEffect)(()=>n?t.every(r=>!!r)?e():()=>{}:()=>{},[...t,n])},GF=({onLogIn:e})=>{let t=_("Widget",Ua),n=te("isEmbedded"),r=te("adminUrl");return(0,ue.jsx)("div",{className:t.loginText,children:(0,ue.jsx)("div",{children:(0,ue.jsx)(Gp,{isEmbedded:n,loginUrl:r,onLogIn:e})})},"login")},_0=({text:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.stateText,children:(0,ue.jsx)("div",{children:(0,ue.jsx)("p",{children:e})})},"notification")},qF=()=>{let e=ie(du),t=ve(),n=_("Widget",Ua),r=te("showSearch"),o=te("isEmbedded"),s=W(Na("/admin/")),i=dn(),a=te("productName"),l=ut();return lA(()=>{if(o)return t(k0()),()=>{t(NP())}},[t,o]),!r&&!s?null:(0,ue.jsxs)("div",{className:n.shortcutList,children:[r&&(0,ue.jsx)(ge.Button,{"data-testid":"shortcut-search","aria-label":e("linkSearch"),className:n.shortcut,icon:(0,ue.jsx)(Aa,{}),onClick:()=>{i.send("ShowCommandPalette",{isOpen:!0}),l("open search",{via:"widget-shortcut"})},children:e("linkSearch")}),s&&(0,ue.jsx)(ge.Button,{as:"a",target:"_blank",icon:(0,ue.jsx)(zP,{}),href:s,"data-testid":"shortcut-studio-login","aria-label":e("linkStudioLogin",{productName:a}),className:n.shortcut,rel:"noreferrer",onClick:()=>{l("open my deepdesk",{via:"widget-shortcut"})},children:e("linkStudioLogin",{productName:a})})]})},YF=({title:e,content:t})=>{let n=ie(du),[r,o]=(0,ds.useState)(!0);return r?(0,ue.jsx)(wr,{"data-testid":"custom-data-banner",type:"custom-data-banner",title:e,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsxs)(ge,{children:[(0,ue.jsx)(Se,{children:(0,ue.jsx)(Se.Content,{children:(0,ue.jsx)(ho,{content:t})})}),(0,ue.jsx)(ge.ButtonsContainer,{children:(0,ue.jsx)(ge.Button,{onClick:()=>o(!1),children:n("close")})})]})})}):null},XF=()=>{let e=ve(),t=W(Cc),n=W(aC),r=W(_P),o=W(eT),s=W(Ap),i=W(Bp),a=W(qs),l=W(Rr);return(0,ds.useEffect)(()=>{!!o&&!n&&Z.warn("Custom data provided, but no schema.")},[o,n]),lA(()=>{t.forEach(({type:c})=>{c==="entities"?e(fr()):Fu.includes(c)||e(gr(c))})},[e,l,a]),(0,ds.useEffect)(()=>{r.length>0&&!t.some(c=>c.type==="cues")&&Z.warn("Received cues, but cues are not configured in widget.")},[t,r]),(0,ue.jsx)(ds.Fragment,{children:t.map(({type:c,title:u,amount:d,lines:f,schema:p,property:y})=>{var g,x;switch(c){case"entities":return s&&s.length>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(FP,{entities:s})},c);case"cues":return r&&r.length>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(QP,{cues:r})})},c);case"custom-data-banner":return o&&y&&o[y]&&(0,ue.jsx)(YF,{title:u,content:String(o[y])},c);case"custom-data":return o&&p&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(JP,{data:o,schema:p})})},c);default:return((x=(g=i[c])==null?void 0:g.suggestions)==null?void 0:x.length)>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(aA,{lines:f,contentType:c,suggestions:i[c].suggestions.slice(0,d)||[]})})},c)}})})},D0=({children:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.footer,children:e})},F0=({children:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.root,"data-testid":"widget",children:e})},QF=({onLogIn:e,knowledgeAssistOptions:t={},assistantOptions:n={transcript:"in-memory-transcript",expectFormat:"json-schema:cues"}})=>{let r=ie(du),o=W(la),s=W(Wt),i=W(z1),a=W(qs),l=W(iC("knowledge-assist")),c=W(qf),u=W(Yf);return o===!1?(0,ue.jsx)(_0,{text:r("notSupported")}):s===!1?(0,ue.jsx)(GF,{onLogIn:e}):s===null?(0,ue.jsx)(_0,{text:r("waiting")}):!i||!a?(0,ue.jsx)(_0,{text:r("waitingForConversation")}):(0,ue.jsx)(F0,{children:(0,ue.jsxs)(fm,{initialQuestion:t.initialQuestion,assistantCode:c!=null?c:u,evaluateKnowledgeAssistFn:u?Ks:Gs,children:[(0,ue.jsxs)(Ri,{children:[(0,ue.jsx)(qF,{}),(0,ue.jsx)(XF,{}),l&&(0,ue.jsx)(mm,{title:l.title,emptyState:t.emptyState})]}),(0,ue.jsxs)(D0,{children:[l&&(0,ue.jsx)(pm,{}),(0,ue.jsx)(KP,{assistantOptions:n})]})]})})},cA=QF;function Va(e){let t=new Range;return t.selectNodeContents(e),t}function uA(e,t,n){try{return fs(e,t,n),!0}catch(r){return!1}}function gm(e){return"tagName"in e&&(e.tagName==="DIV"||e.tagName==="P")}function hm(e){return"tagName"in e&&e.tagName==="BR"}var fu=/[\u200B-\u200D\uFEFF]/g;function fs(e,t,n){let r=new Range;if(e.firstChild===null&&t===0&&n===0)return r.selectNodeContents(e),r;let o=0,s=!1;function i(l,c){let u=-1,d=/[\u200B-\u200D\uFEFF]/;if(!d.test(l))return c;for(let f=0;f<=l.length;f++)if(d.test(l[f])||u++,u===c)return f;throw new Error("Offset out of range")}function a(l){switch(l.nodeType){case Node.TEXT_NODE:{let c=l.textContent,u=c.replace(fu,""),d=o+u.length,f=t>=o&&t<=d,p=n>=o&&n<=d;if(f){let y=i(c,t-o);y===0&&!p?r.setStartBefore(l):r.setStart(l,y)}p&&(r.setEnd(l,i(c,n-o)),s=!0),o=d;break}case Node.ELEMENT_NODE:{if(hm(l)&&(o===t&&r.setStartBefore(l),o++,o===n)){r.setEndAfter(l),s=!0;return}for(let u=0;u<l.childNodes.length&&(a(l.childNodes[u]),!s);u++);let c=l.lastChild;gm(l)&&c&&!gm(c)&&!hm(c)&&o++;break}default:break}}if(a(e),r.startContainer===document)throw new Error("Offsets out of bound");return r}function pu(e,t){if(!e.contains(t.startContainer)||!e.contains(t.endContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:r,endContainer:o,endOffset:s,collapsed:i}=t,a,l,c=0;function u(d){let f=d===e,p=d===n,y=d===o;switch(d.nodeType){case Node.TEXT_NODE:{let g=d.textContent;p&&(a=c+g.substring(0,r).replace(fu,"").length),y&&(l=c+g.substring(0,s).replace(fu,"").length),c+=g.replace(fu,"").length;break}case Node.ELEMENT_NODE:{if(hm(d)&&d.nextSibling){c++;break}!f&&gm(d)&&d.previousSibling&&c++;for(let g=0;g<d.childNodes.length;g++){let x=p&&g===r,v=y&&g===s;if(x&&(a=c),v&&(l=c),l!==void 0||((!x||!i)&&u(d.childNodes[g]),y&&g===s-1&&(l=c),l!==void 0))break}y&&(l=c);break}default:break}}if(u(e),l===void 0)throw new Error("Could not determine start and end");return{start:a!=null?a:l,end:l}}function mu(e,t){if(!e.contains(t.startContainer)||!e.contains(t.endContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:r,endContainer:o,endOffset:s,collapsed:i}=t,a=0,l="";function c(u){let d=u===e,f=u===n,p=u===o;switch(f&&(a=1),u.nodeType){case Node.TEXT_NODE:{if(a!==1)return;let y=f?r:0,g=p?s:void 0;l+=u.textContent.replace(fu,"").substring(y,g);break}case Node.ELEMENT_NODE:{if(!i&&a===1&&hm(u)&&u.nextSibling){l+=`
|
|
80
|
+
c32.4,32.4,47.8,70,47.8,115.2v70h11.9c9.4,0,17.9,3.4,24.7,10.2C462.1,250,465.5,257.7,465.5,267.9z`})})});var p0=b(R()),_4={green:"#0A5E52",pink:"#CD8EF2",red:"#DF341D",yellow:"#DEBD00"},WR=({className:e,color:t})=>(0,p0.jsx)("svg",{className:e,viewBox:"0 0 345 345",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,p0.jsx)("path",{d:"M172.03 0.0199966H0V86.03C47.5 86.03 86 124.54 86 172.04C86 124.54 124.51 86.03 172.01 86.03C219.51 86.03 258.03 124.54 258.03 172.04C258.03 219.54 219.52 258.05 172.01 258.05C124.5 258.05 86 219.54 86 172.04C86 219.54 47.5 258.05 0 258.05V344.06H172.03C267.04 344.06 344.06 267.04 344.06 172.03C344.06 77.02 267.04 0 172.03 0V0.0199966Z",fill:_4[t||"pink"]})});var jR={root:"dd-LbeUM",text:"dd-Dpfn1",isLoggedIn:"dd-XvHAn",isLoggedOut:"dd-21y-z",icon:"dd-8rLqS",logo:"dd-slXhD",lock:"dd-ByzlR"};var m0={};pt(m0,{enUS:()=>D4,nlNL:()=>F4});var D4={signin:[{type:0,value:"Sign in to "},{type:1,value:"productName"}],search:[{type:1,value:"productName"},{type:0,value:" Search"}]},F4={signin:[{type:0,value:"Log in bij "},{type:1,value:"productName"}],search:[{type:1,value:"productName"},{type:0,value:" Zoeken"}]};var mi=b(R()),GR=({onLogIn:e})=>{let t=ie(m0),n=te("floatingMenu"),r=te("productName"),o=ve(),s=W(Wt),i=_("FloatingMenu",jR);if(s===null||n===!1)return null;let a=()=>{s===!0?o(Fn(!0)):e()};return(0,mi.jsxs)("button",{type:"button",className:(0,KR.default)(i.root,{[i.isLoggedIn]:s,[i.isLoggedOut]:!s}),onClick:a,children:[(0,mi.jsx)("div",{className:i.text,children:t(s?"search":"signin",{productName:r})}),(0,mi.jsxs)("div",{className:i.icon,children:[(0,mi.jsx)(WR,{className:i.logo,color:"pink"}),s===!1&&(0,mi.jsx)($R,{className:i.lock})]})]})};var Kp=b(Y());function Or(e){let{showMidSentenceSuggestions:t,showSuggestionsBeforePattern:n,showSuggestionsAfterPattern:r}=e.settings,{text:o,selection:s}=e.input;return s.start!==s.end?!1:s.end>=o.length?!0:t?n&&new RegExp(n).test(o.substring(s.end))||r&&new RegExp(r).test(o.substring(0,s.end))?!0:n===!1&&r===!1:!1}var z4={showTabHint:!1,inputHasFocus:!1,overlayCollapsed:!1,openOverlayWhenTyping:!1,overlayCollapsedUserOverwrite:!1},$p=({ui:e})=>e.overlayCollapsed,qR=ke({name:"ui",initialState:z4,reducers:{setShowTabHint(e,t){e.showTabHint=t.payload},setInputFocus(e,t){e.overlayCollapsedUserOverwrite!==!0&&(t.payload===!0&&(e.overlayCollapsed=!1),e.inputHasFocus=t.payload)},setOverlayCollapsed(e,t){t.payload.collapse===!1&&(e.openOverlayWhenTyping=!1),!(t.payload.skipWhenInputFocus&&e.inputHasFocus)&&(e.overlayCollapsed=t.payload.collapse)},setOpenOverlayWhenTyping(e,t){e.openOverlayWhenTyping=t.payload},setOverlayCollapsedUserOverwrite(e,t){e.overlayCollapsedUserOverwrite=t.payload,e.overlayCollapsed=t.payload}}}),{setShowTabHint:tu,setInputFocus:Wp,setOverlayCollapsed:is,setOpenOverlayWhenTyping:YR,setOverlayCollapsedUserOverwrite:XR}=qR.actions,QR=qR.reducer;var rP=b(Y());var as=b(Y());var ZR=b(Y());function JR(e,t,n){(0,ZR.useEffect)(()=>{let r=e.current;return r?(r.addEventListener(t,n),()=>{r.removeEventListener(t,n)}):()=>{}},[e,t,n])}var eP={root:"dd-1MBCO",actions:"dd--x4cy",closeIconContainer:"dd-1z5NR",closeIcon:"dd-8qMF-",badge:"dd-4Fpkz",formattedText:"dd-EzvTB"};var nu=b(R()),tP=({title:e})=>(0,nu.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18px",height:"18px",viewBox:"0 0 24 24","aria-labelledby":"closeTitle",children:[(0,nu.jsx)("title",{id:"closeTitle",children:e}),(0,nu.jsx)("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"})]});var g0={};pt(g0,{enUS:()=>H4,nlNL:()=>B4});var H4={assistant:[{type:0,value:"Assistant"}],close:[{type:0,value:"Close"}]},B4={assistant:[{type:0,value:"Assistent"}],close:[{type:0,value:"Sluiten"}]};var _r=b(R()),V4=["search","personal-collection-search","search-autocomplete"];function $4(e,t,n,r={}){var s;let o="";return V4.includes(t)?o=vC(gv(e,n,{stripAgentPart:!0}),(s=r.searchKeywords)!=null?s:[n]):o=gv(e,n,r),r.placeholders===!0&&(o=xC(o)),o}var W4=()=>{},j4=({selected:e,suggestion:t})=>{let n=ie(g0),r=te("inlineSuggestions"),o=W(ca),[s,i]=(0,as.useState)(!1),a=te("enableSuggestionFeedback"),l=W(x=>x.input.text),c=ve(),u=_("TextSuggestion",eP),d=(0,as.useRef)(null),f=t.source==="assistant",p=a&&!f;(0,as.useEffect)(()=>{let x=setTimeout(()=>{c(V1({text:t.text,suggestion:t}))},500);return()=>{clearTimeout(x)}},[t]),JR(d,"click",()=>{c(er({suggestion:t,text:t.text,eventMetrics:{inputType:"mouse"},replace:"until-selection-end"}))});let y=()=>{c(Hs({source:t.source,text:t.text,assistantCode:t.assistantCode}))},g=(0,as.useMemo)(()=>$4(t.text,t.source,o,{stripAgentPart:r,placeholders:!0,searchKeywords:t.searchKeywords}),[r,t.text,t.source,o,t.searchKeywords]);return t.source==="gpt"&&!r?null:(0,_r.jsxs)("div",{className:u.root,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[(0,_r.jsx)(ge,{ref:d,as:"button","data-testid":"suggestions-overlay-item",selected:e,onClick:W4,children:(0,_r.jsx)(Js,{attributes:t.source==="assistant"?{"data-label":n("assistant")}:void 0,containerTagName:"div",noWrap:!1,tagName:"span",className:u.formattedText,content:g})}),p&&s&&(0,_r.jsx)("div",{className:u.actions,children:(0,_r.jsx)(Hp,{source:"overlay",context:l,suggestion:t})}),f&&s&&(0,_r.jsx)("div",{className:u.closeIconContainer,children:(0,_r.jsx)("button",{type:"button",className:u.closeIcon,onClick:y,title:n("close"),children:(0,_r.jsx)(tP,{title:n("close")})})})]})},nP=j4;var oP=b(R()),K4=({suggestions:e,selectedIndex:t,reverse:n})=>(0,rP.useMemo)(()=>{let o=e.map((s,i)=>(0,oP.jsx)(nP,{index:i,selected:i===t,suggestion:s},`${s.text}-${s.source}`));return n?o.reverse():o},[e,t,n]),jp=K4;var sP={root:"dd-PfvRI",paper:"dd-HYlyY"};var ru=b(R()),G4=()=>{let e=(0,Kp.useRef)(null),t=_("InlineSuggestionsOverlay",sP),n=W(Or),r=ve(),o=W(Wt),s=W(la),i=W($p),a=te("showTextSuggestions"),l=W(zs),c=W(Zl);return ss(()=>{setTimeout(()=>{r(is({collapse:!0,skipWhenInputFocus:!0}))})}),(0,Kp.useEffect)(()=>{let u=e.current;if(!u||!u.parentElement)return;u.parentElement.style.left="0px";let d=u.getBoundingClientRect();u.parentElement.style.left=`${Math.min(window.innerWidth-4-d.right,0)}px`}),i||!n||!a||l.length===0||o!==!0||s===!1?null:(0,ru.jsx)("div",{className:t.root,"data-variant":"inline",children:(0,ru.jsx)("div",{ref:e,className:t.paper,children:(0,ru.jsx)(Ht,{children:(0,ru.jsx)(jp,{suggestions:l,selectedIndex:c})})})})},iP=G4;var ou=b(R()),q4=({children:e})=>{let n=te("locale").replace("-","");return(0,ou.jsx)(jy.Provider,{value:n,children:e})},Y4=({store:e,customStyles:t={},children:n})=>(0,ou.jsx)(h1,{store:e,children:(0,ou.jsx)(q4,{children:(0,ou.jsx)(Qa.Provider,{value:t,children:n})})}),ls=Y4;var qp=b(Oe()),Da=b(Y());var aP=b(Y());function lP(e,t){let[n,r]=(0,aP.useState)(()=>{if(typeof window=="undefined")return t;try{let s=window.localStorage.getItem(e);return s?JSON.parse(s):t}catch(s){return Z.error(s),t}});return[n,s=>{try{let i=s instanceof Function?s(n):s;r(i),typeof window!="undefined"&&window.localStorage.setItem(e,JSON.stringify(i))}catch(i){Z.error(i)}}]}var cP=()=>/Mac/i.test(navigator.platform);var dP=b(Oe()),yo=b(Y());var h0={};pt(h0,{enUS:()=>X4,nlNL:()=>Q4});var X4={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Sign in"}]},{type:0,value:" to enable "},{type:1,value:"productName"},{type:0,value:"."}],snooze:[{type:0,value:"Snooze for "},{type:8,value:"min",children:[{type:0,value:"10 minutes"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 hour"}]},{type:0,value:" or "},{type:8,value:"day",children:[{type:0,value:"1 day"}]}]},Q4={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Log in"}]},{type:0,value:" bij "},{type:1,value:"productName"},{type:0,value:"."}],snooze:[{type:0,value:"Snooze voor "},{type:8,value:"min",children:[{type:0,value:"10 minuten"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 uur"}]},{type:0,value:" of "},{type:8,value:"day",children:[{type:0,value:"1 dag"}]}]};var uP={root:"dd-uTPjX",anchor:"dd-C8lsZ",anchorButton:"dd-IoSx9"};var cs=b(R()),y0=(e,t,n)=>r=>(0,cs.jsx)("button",{className:e.anchorButton,type:"button",value:t,onClick:n,children:r},t),Z4=({className:e,loginUrl:t,isEmbedded:n,onSnooze:r,onLogIn:o})=>{let s=ie(h0),i=dn(),a=_("Login",uP),l=te("productName"),c=(0,yo.useCallback)(x=>{x.preventDefault(),r&&r(Number.parseInt(x.target.value,10))},[]),u=(0,yo.useCallback)(x=>{x.preventDefault(),i.send(fa,!0)},[t]),d=(0,yo.useMemo)(()=>x=>(0,cs.jsx)("a",{onClick:h=>{h.preventDefault(),o()},href:t,className:a.anchor,target:"_blank",rel:"noreferrer",children:x},"login"),[t]),f=(0,yo.useCallback)(x=>(0,cs.jsx)("button",{type:"button",className:a.anchorButton,onClick:u,children:x},"prompt"),[u]),{min:p,hour:y,day:g}=(0,yo.useMemo)(()=>({min:y0(a,60*10,c),hour:y0(a,60*60,c),day:y0(a,60*60*12,c)}),[]);return(0,cs.jsxs)("div",{className:(0,dP.default)(e,a.root),children:[s("loginPlease",{login:n?f:d,productName:l}),r&&(0,cs.jsxs)(yo.Fragment,{children:[(0,cs.jsx)("br",{}),s("snooze",{min:p,hour:y,day:g})]})]})},Gp=Z4;var fP={root:"dd-DoQhb",text:"dd-Jwnev"};var su=b(R()),J4=({title:e})=>{let t=_("SearchTrigger",fP),n=ve(),r=ut();return(0,su.jsxs)("button",{type:"button",className:t.root,onClick:()=>{n(Fn(!0)),r("open search",{via:"autocomplete-overlay"})},children:[(0,su.jsx)(Aa,{}),(0,su.jsx)("span",{className:t.text,children:e})]})},pP=J4;var v0={};pt(v0,{enUS:()=>eF,nlNL:()=>tF});var eF={arrowHint:[{type:0,value:"Tip: use arrow keys to navigate suggestions"}],searchHintWindows:[{type:0,value:"Press CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],searchHintMac:[{type:0,value:"Press CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],open:[{type:0,value:"Open "},{type:1,value:"productName"}],collapse:[{type:0,value:"Close"}],search:[{type:0,value:"Search"}]},tF={arrowHint:[{type:0,value:"Tip: Selecteer suggesties met pijltoetsen"}],searchHintWindows:[{type:0,value:"Druk CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],searchHintMac:[{type:0,value:"Druk CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],open:[{type:0,value:"Open "},{type:1,value:"productName"}],collapse:[{type:0,value:"Sluiten"}],search:[{type:0,value:"Zoeken"}]};var mP={root:"dd-oa7Vc",isInline:"dd-bwk31",toggleButton:"dd-MSB8Z",toggleButtonWrapper:"dd-ZkCzT",toggleButtonWrapperHidden:"dd-Sq66c",isCollapsed:"dd-vkrPk",collapsible:"dd-CWQJe",hints:"dd-IOoo3",hintsHidden:"dd-psVuT",triggers:"dd-toIoo",triggersRight:"dd-mc4l2"};var $e=b(R()),nF=({onLogIn:e})=>{let t=_("SuggestionsOverlay",mP),n=ie(v0),r=W(Or),o=W(U1),s=ve(),i=(0,Da.useRef)(null),a=te("searchTriggerKey"),l=te("productName"),c=W($p),u=W(Wt),d=W(la),[f,p]=(0,Da.useState)(null),y=te("showSearch"),g=te("showTextSuggestions"),x=te("adminUrl"),v=te("isEmbedded"),[h,m]=lP("dd-snooze-until-ms",0),w=c||h>Date.now(),E=W(zs),k=W(Zl),C=E.filter(O=>O.source!=="gpt").length,A=()=>{w&&m(0),s(XR(!w))},V=O=>{let L=Date.now()+O*1e3;m(L),Z.info(`Snooze until: ${new Date(L)}`),s(is({collapse:!0}))};return(0,Da.useEffect)(()=>{C===0&&p(null)},[E,C]),ss(()=>{s(is({collapse:!0,skipWhenInputFocus:!0}))}),u===null||d===!1?null:u===!1?(0,$e.jsxs)("div",{ref:i,className:(0,qp.default)(t.root,{[t.isCollapsed]:w}),children:[!w&&(0,$e.jsxs)("div",{className:t.triggers,children:[(0,$e.jsx)("div",{style:{flex:1}}),(0,$e.jsx)("div",{className:t.triggersRight,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("collapse"),onClick:A,isCollapsed:!1})})]}),(0,$e.jsx)("div",{className:t.toggleButtonWrapper,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("open",{productName:l}),onClick:A,isCollapsed:!0})}),(0,$e.jsx)("div",{className:t.collapsible,children:(0,$e.jsx)(Gp,{loginUrl:x,isEmbedded:v,onLogIn:e,onSnooze:V})})]}):!o||!r?null:(0,$e.jsxs)("div",{ref:i,className:(0,qp.default)(t.root,{[t.isCollapsed]:w}),children:[!w&&(0,$e.jsxs)("div",{className:t.triggers,children:[(0,$e.jsx)("div",{style:{flex:1},children:y&&(0,$e.jsx)("div",{style:{display:"inline-block"},onFocus:()=>{},onMouseOver:()=>p(n(cP()?"searchHintMac":"searchHintWindows",{searchTriggerKey:a.toUpperCase()})),onMouseLeave:()=>p(null),children:(0,$e.jsx)(pP,{title:n("search")})})}),(0,$e.jsxs)("div",{className:t.triggersRight,onFocus:()=>{},children:[(0,$e.jsx)("div",{className:(0,qp.default)(!f&&t.hintsHidden,t.hints),children:f}),(0,$e.jsx)(xs,{className:t.toggleButton,title:n("collapse"),onClick:A,isCollapsed:!1})]})]}),(0,$e.jsx)("div",{className:t.toggleButtonWrapper,children:(0,$e.jsx)(xs,{className:t.toggleButton,title:n("open",{productName:l}),onClick:A,isCollapsed:!0})}),C>0&&g&&(0,$e.jsx)("div",{className:t.collapsible,onFocus:()=>{},children:(0,$e.jsx)(Ht,{children:(0,$e.jsx)(jp,{suggestions:E,selectedIndex:k,reverse:!0})})})]})},gP=nF;var im=b(Oe());var wo=b(Y());var Fa=b(Y());function Yp(e){return e.contentEditable==="true"}function rF(e){let t=0,n=0,r=window.getSelection();if(r.rangeCount!==0){let o=r.getRangeAt(0),s=o.cloneRange();s.selectNodeContents(e),s.setEnd(o.endContainer,o.endOffset),n=s.toString().length,s.selectNodeContents(e),s.setEnd(o.startContainer,o.startOffset),t=s.toString().length}return{selectionStart:t,selectionEnd:n}}function hP(e){let{selectionStart:t,selectionEnd:n}=Yp(e)?rF(e):e;return[t,n]}function yP(e){let[,t]=(0,Fa.useState)(),n=(0,Fa.useRef)(null);return n.current=hP(e),(0,Fa.useEffect)(()=>{let r=()=>{var a;let[o,s]=(a=n.current)!=null?a:[],i=hP(e);(!i||o!==i[0]||s!==i[1])&&(n.current=i,t({}))};return e.addEventListener("keyup",r),e.addEventListener("click",r),e.addEventListener("focus",r),document.addEventListener("selectionchange",r),()=>{e.removeEventListener("keyup",r),e.removeEventListener("click",r),e.removeEventListener("focus",r),document.removeEventListener("selectionchange",r)}},[e]),n.current}function vP(e,t){if(!t)return;let n=e,{value:r}=n,[o,s]=t,i=r.match(Du);if(!i||i.length===0)return;let a=0;i.find(l=>{let c=r.indexOf(l,a);return o>c&&s<c+l.length?(n.selectionStart=c,n.selectionEnd=c+l.length,!0):(a=c+l.length,!1)})}var xP=b(Y()),oF=["div","span","mark","strong","b","i","u","em"];function x0(e,t,n=0){var s;let r=e[e.length-1],o=typeof r=="object"&&r!==null?(s=r.props)==null?void 0:s.tagName:void 0;if(o==="br")return e.pop(),[...e,...t,r];if(oF.includes(o)){let i=Array.isArray(r.props.children)?r.props.children:[r.props.children];return[...e.slice(0,e.length-1),(0,xP.cloneElement)(r,{children:x0(i,t,n+1)})]}return[...e,...t]}function gi(e){return e.tagName.toLowerCase()==="textarea"}var wP={root:"dd-7-cgW",container:"dd-PsRQ8",agentText:"dd-qnW-V",tabText:"dd-cUHUr",hint:"dd-v7fSg",matchSelection:"dd-8cr8y",focus:"dd-3tr9l",resetIndent:"dd-TvQfZ",matchKeyword:"dd-oJkRD",matchPlaceholder:"dd-QvNoo",hover:"dd--wi0R",hintText:"dd-7gQQh",popover:"dd-xbRu-",popoverRoot:"dd-rA2x8",popoverContentContainer:"dd-JHICl",popoverContent:"dd--mfkC",selectionOptions:"dd-p52wn",selectionOptionsIsHidden:"dd-sSTDp",selectionOptionsButton:"dd-Q6kRY",caret:"dd-jIhc8",popoverSuggestionsRoot:"dd-iFDbL",suggestionsOverlayInputStyles:"dd-zzENA"};var CP=b(Oe());var tm=b(Y());var za=b(Y());function SP(e,t){let n;return[(...r)=>{window.cancelAnimationFrame(n);let o=t?t(...r):r;n=window.requestAnimationFrame(()=>{e(...o)})},()=>window.cancelAnimationFrame(n)]}function Xp(e){let t=(0,za.useRef)(null),[n,r]=(0,za.useState)(!1);return(0,za.useEffect)(()=>{var u;let o=!1,s=Number.parseFloat((u=window.getComputedStyle(document.body).zoom)!=null?u:"1"),[i,a]=SP((d,f)=>{let p=t.current;if(!p)return;let y=d/s,g=f/s,x=p.getBoundingClientRect(),v=y>x.x&&y<x.x+x.width&&g>x.y&&g<x.y+x.height;v&&!o?(o=!0,r(!0)):!v&&o&&(o=!1,r(!1))},({clientX:d,clientY:f})=>[d,f]),[l,c]=SP(()=>{o=!1,r(!1)});return e.addEventListener("mousemove",i),e.addEventListener("mouseleave",l),()=>{a(),c(),e.removeEventListener("mousemove",i),e.removeEventListener("mouseleave",l)}},[t]),[t,n]}function bP(e){return e.replace(/[.*+^${}()|[\]\\]/g,"\\$&")}function Qp(e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}}function EP(e){return e!=null}var TP=b(Oe()),Zp=b(Y());var vo={root:"dd-7-cgW",container:"dd-PsRQ8",agentText:"dd-qnW-V",tabText:"dd-cUHUr",hint:"dd-v7fSg",matchSelection:"dd-8cr8y",focus:"dd-3tr9l",resetIndent:"dd-TvQfZ",matchKeyword:"dd-oJkRD",matchPlaceholder:"dd-QvNoo",hover:"dd--wi0R",hintText:"dd-7gQQh",popover:"dd-xbRu-",popoverRoot:"dd-rA2x8",popoverContentContainer:"dd-JHICl",popoverContent:"dd--mfkC",selectionOptions:"dd-p52wn",selectionOptionsIsHidden:"dd-sSTDp",selectionOptionsButton:"dd-Q6kRY",caret:"dd-jIhc8",popoverSuggestionsRoot:"dd-iFDbL",suggestionsOverlayInputStyles:"dd-zzENA"};var w0=b(R()),Jp=(0,Zp.forwardRef)((o,r)=>{var s=o,{className:e,children:t}=s,n=oe(s,["className","children"]);let i=(0,Zp.useRef)(null),a=_("TabCompletion",vo);return(0,w0.jsx)("div",P(S({ref:Qp([i,r]),className:(0,TP.default)(e,a.popoverContentContainer)},n),{children:(0,w0.jsx)("div",{className:a.popoverContent,children:t})}))});var us=b(R()),sF=e=>t=>{let n=c0(t);return"top"in n&&(n.width=e.width-(t.left-e.left)-10),n},iF=({inputElement:e,boundaryRef:t,inputStyle:n,children:r,suggestion:o})=>{let s=_("TabCompletion",vo),i=Dp(),a=(0,tm.useMemo)(()=>sF(e.getBoundingClientRect()),[e]),[l,c]=Xp(e);return(0,tm.useEffect)(()=>{c?i.open():i.close()},[c]),(0,us.jsxs)("span",{children:[(0,us.jsx)("mark",{ref:Qp([l,i.triggerRef]),className:(0,CP.default)(s.matchKeyword,{[s.hover]:c}),"aria-haspopup":"dialog","aria-expanded":i.opened?"true":"false",children:r}),i.opened&&(0,us.jsx)(_a,{className:s.popover,triggerRef:i.triggerRef,boundaryRef:t,position:"below",align:"start",toStyle:a,children:(0,us.jsx)(Jp,{style:n,children:(0,us.jsx)("div",{className:s.hintText,children:o})})})]})},em=class extends ao{constructor(){super(...arguments);this.keywordMatches=[];this.preparedKeywordMatches=[];this.usedKeywordMatches=new Set}onBeforeParse(n,r){return r.keywordMatches&&r.keywordMatches!==this.keywordMatches&&(this.preparedKeywordMatches=r.keywordMatches.map(o=>P(S({},o),{keywordRegex:new RegExp(`\\b${bP(o.keyword)}\\b`,"i")})),this.keywordMatches=r.keywordMatches),this.usedKeywordMatches.clear(),n}match(n){let r=this.preparedKeywordMatches.map(s=>{if(this.usedKeywordMatches.has(s))return null;let i=n.match(s.keywordRegex);if(!i)return null;let a=n.charAt(i.index-1),l=n.charAt(i.index+s.keyword.length);return a==="{"&&l==="}"?null:{index:i.index,length:i[0].length,match:i[0],matchString:i[0],suggestion:s.suggestion,preparedKeywordMatch:s,valid:!0}}).filter(EP);if(r.length===0)return null;let o=r.reduce((s,i)=>i.index<s.index?i:s);return this.usedKeywordMatches.add(o.preparedKeywordMatch),o}replaceWith(n,r){return(0,us.jsx)(iF,{inputElement:r.inputElement,suggestion:r.suggestion,inputStyle:r.inputStyle,boundaryRef:r.boundaryRef,children:n},`keyword_${r.matchString}_${r.key}`)}asTag(){return"mark"}};var kP=b(Oe());var S0=b(R()),aF=({inputElement:e,children:t})=>{let n=_("TabCompletion",vo),[r,o]=Xp(e);return(0,S0.jsx)("mark",{ref:r,className:(0,kP.default)(n.matchPlaceholder,{[n.hover]:o}),children:t})},nm=class extends ao{match(t){let n=t.match(/(((\$!\{)|(\{))[a-zA-Z0-9_.]+\}(?!\}))/);return n?{index:n.index,length:n[0].length,match:n[0],matchString:n[0],valid:!0}:null}replaceWith(t,n){return(0,S0.jsx)(aF,{inputElement:n.inputElement,children:t},`placeholder_${n.matchString}_${n.key}`)}asTag(){return"mark"}};var om=b(Oe());var Jt=b(Y());var b0=b(R()),RP=()=>(0,b0.jsx)("svg",{width:"1.3em",height:"1.3em",focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"InsertLinkIcon",tabIndex:-1,children:(0,b0.jsx)("path",{fill:"currentColor",d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})});var Dr=b(Y());var AP=b(Xy());var PP={root:"dd-ky-Bv",content:"dd-kV5e1"};function rm(e,t,n){var o;let r=((o=e.imageSizes)==null?void 0:o[t])||e.image||n;if(!r)return null;try{return new URL(r).toString()}catch(s){return null}}function E0(e){return e.replace("https://www.","").replace("https://","")}var Vn=b(R()),lF=3,cF=e=>({image:e.image||"",text:e.text,id:e.id,title:e.title}),uF=({onSelectLink:e,onDismiss:t,placeholder:n,visitUrlText:r,linkCount:o=lF})=>{let s=_("LinkSearch",PP),[i,a]=(0,Dr.useState)(""),l=ve(),c=W(NR("url")),u=W(cT("URL")),d=(0,Dr.useMemo)(()=>u.map(cF),[u]),[f,p]=(0,Dr.useState)(d.length-1),y=te("fallbackImage"),g=m=>{let w=m.target;a(w.value)},x=(m,w)=>{m.stopPropagation(),m.preventDefault(),window.open(w,"_blank")},v=m=>{var k;let w=f-1<0?d.length-1:f-1,E=f+1===d.length?0:f+1;m.code==="Escape"&&(a(""),t()),m.code==="ArrowUp"&&p(w),m.code==="ArrowDown"&&p(E),m.code==="Enter"&&e(((k=d[f])==null?void 0:k.text)||i)},h=(0,Dr.useCallback)((0,AP.default)(m=>{l(Us({query:m,type:"URL",tags:["link-search"]}))},300),[]);return(0,Dr.useEffect)(()=>{i&&h(i)},[i]),(0,Dr.useEffect)(()=>()=>{l(If())},[]),(0,Vn.jsxs)("div",{className:s.root,children:[(0,Vn.jsx)(Ht,{withDivider:!0,children:(i?d:c).slice(0,o).map((m,w)=>(0,Vn.jsx)(ge,{selected:f===w,onClick:()=>e(m.text),"data-testid":"linksearch-suggestion",children:(0,Vn.jsxs)(Se,{children:[(0,Vn.jsx)(Se.Image,{src:rm(m,"small",y||void 0),title:m.title||m.text}),(0,Vn.jsxs)(Se.Content,{className:s.content,cropText:!0,children:[(0,Vn.jsx)(Se.Title,{children:m.title||E0(m.text)}),m.title&&E0(m.text)]}),(0,Vn.jsx)(ge.Actions,{children:(0,Vn.jsx)(ge.ActionButton,{label:r,onClick:E=>x(E,m.text)})})]})},m.text))}),(0,Vn.jsx)(mc,{value:i,onChange:g,autoFocus:!0,placeholder:n,onKeyUp:v})]})},IP=uF;var T0={};pt(T0,{enUS:()=>dF,nlNL:()=>fF});var dF={insertLink:[{type:0,value:"Insert link"}],linkInputPlaceholder:[{type:0,value:"Search, type or paste link"}],visitUrl:[{type:0,value:"Visit"}]},fF={insertLink:[{type:0,value:"Voeg link toe"}],linkInputPlaceholder:[{type:0,value:"Zoek, typ of plak link"}],visitUrl:[{type:0,value:"Bekijk"}]};var Zt=b(R()),pF=(0,Jt.forwardRef)((e,t)=>{let n=_("TabCompletion",vo);return(0,Zt.jsx)("mark",{ref:t,className:(0,om.default)(n.matchSelection)},"selection-start")}),mF=({startRef:e,boundaryRef:t,inputStyle:n,inputElement:r,children:o})=>{let s=ie(T0),i=_("TabCompletion",vo),a=(0,Jt.useRef)(null),l=(0,Jt.useRef)(null),[c,u]=(0,Jt.useState)(null),d=ve(),f=Dp(document.activeElement===r),[p]=(0,Jt.useState)(()=>document.createRange());f.triggerRef.current=p,(0,Jt.useEffect)(()=>()=>p.detach(),[]),(0,Jt.useEffect)(()=>{let g=e.current,x=a.current;!g||!x||(p.setStart(g,0),p.setEnd(x,0))},[e.current,a.current]),ss(()=>{f.close()});let y=(0,Jt.useCallback)(g=>{let x=p.toString(),v=/^http(s?):\/\//.test(g)?g:`https://${g}`;d(Ef({text:`[${x}](${v})`,replace:"selection"}))},[]);return(0,Zt.jsxs)("span",{children:[(0,Zt.jsx)("mark",{ref:a,className:(0,om.default)(i.matchSelection),"aria-haspopup":"dialog","aria-expanded":f.opened?"true":"false",children:o}),f.opened&&(0,Zt.jsx)(_a,{className:i.popoverRoot,triggerRef:f.triggerRef,boundaryRef:t,position:"above",align:"start",children:(0,Zt.jsxs)(Jp,{style:n,ref:l,children:[(0,Zt.jsx)("div",{className:(0,om.default)(i.selectionOptions,{[i.selectionOptionsIsHidden]:c!==null}),children:(0,Zt.jsxs)("button",{type:"button",tabIndex:c===null?-1:void 0,className:i.selectionOptionsButton,onClick:()=>u("insertLink"),children:[(0,Zt.jsx)(RP,{}),(0,Zt.jsx)("span",{children:"\xA0"}),(0,Zt.jsx)("span",{children:s("insertLink")})]})}),c==="insertLink"&&(0,Zt.jsx)(IP,{placeholder:s("linkInputPlaceholder"),visitUrlText:s("visitUrl"),onSelectLink:y,onDismiss:()=>{u(null),f.close()}})]})})]},"selection-end")},sm=class extends ao{constructor(){super(...arguments);this.charCount=0;this.foundIndex=0;this.startRef=null}onBeforeParse(n,r){return this.props=r,this.charCount=0,this.startRef=(0,Jt.createRef)(),this.foundIndex=0,n}match(n){if(!this.props||this.props.selection===null||this.foundIndex===2)return null;let[r,o]=this.props.selection;if(r===o)return null;let s=this.foundIndex===0?r:o,i=s>=this.charCount&&s<=this.charCount+n.length?{index:s-this.charCount,length:0,match:"",valid:!0}:null;i&&this.foundIndex++;let a=this.foundIndex===1;return i&&a?this.charCount+=s-this.charCount:this.charCount+=n.length,i?S({isStart:a},i):null}replaceWith(n,r){return r.isStart?(0,Zt.jsx)(pF,{ref:this.startRef}):(0,Zt.jsx)(mF,{inputElement:r.inputElement,startRef:this.startRef,boundaryRef:r.boundaryRef,inputStyle:r.inputStyle})}asTag(){return"mark"}};var xo=b(R()),gF=({enabled:e,content:t,tabText:n,showTabHint:r,showTabCompletion:o,showStyleSuggestions:s,keywordMatches:i,inputElement:a,source:l})=>{let c=_("TabCompletion",wP),u=te("insertLink"),d=te("showMidSentenceSuggestions"),f=te("inlineSuggestions"),p=yP(a),y=(0,wo.useRef)(null),g=W(Wt);(0,wo.useEffect)(()=>{gi(a)&&p&&vP(a,p)},[p]);let x=(0,wo.useCallback)(m=>{if(!o||!n)return m;let w=[(0,xo.jsx)("span",{className:c.resetIndent,children:"\u200B"},"u200B"),(0,xo.jsx)("span",{"data-testid":"tab-completion",className:(0,im.default)(c.tabText,c.resetIndent),"data-source":l,children:n},"tabText")];return r&&w.push((0,xo.jsx)("span",{className:(0,im.default)(c.hint,c.resetIndent),children:(0,xo.jsx)(Nu,{keyCode:"tab"},"tabHint")},"tabHint")),x0(m,w)},[o,n,r]),v=(0,wo.useMemo)(()=>{let m=[];return u&&m.push(new sm("selection")),m.push(new nm("placeholders")),s&&m.push(new em("keywords")),m},[f,u,s]),h=(0,wo.useMemo)(()=>{let m=window.getComputedStyle(a);return{"--dd-color":m.color,"--dd-font-size":m.fontSize,"--dd-font-family":m.fontFamily,"--dd-font-variant":m.fontVariant}},[]);return!e||!g?null:(0,xo.jsxs)("div",{ref:m=>{m!=null&&m.parentElement&&(y.current=m==null?void 0:m.parentElement)},className:c.root,style:h,children:[(0,xo.jsx)(Js,{tagName:"span",containerTagName:"div",className:(0,im.default)(c.container,c.agentText),disableLineBreaks:gi(a),content:t||"\u200B",onAfterParse:x,matchers:v,selection:p,keywordMatches:i,inputElement:a,inputStyle:h,boundaryRef:y,inlineSuggestionsOnlyAtEnd:!d}),(0,xo.jsx)("br",{})]},"tab-completion")},hF=e=>{var x,v,h;let{input:t,ui:n,settings:r,styleSuggestions:o,conversation:s}=e,i=ua({input:t}),a=(i==null?void 0:i.text)||"",l=(i==null?void 0:i.source)||"",c=(x=t.html)!=null?x:ha(t.text),u=a.indexOf(t.text)===0?a.slice(t.text.length):"",{showTabHint:d}=n,{isSupported:f}=s,{showTabCompletion:p,visible:y,showStyleSuggestions:g}=r;return{showTabHint:d,showStyleSuggestions:g,showTabCompletion:p&&Or(e),content:c,tabText:u,source:l,keywordMatches:(h=(v=o.list)==null?void 0:v.keywordMatches)!=null?h:[],enabled:y&&f!==!1}},LP=g1(hF)(gF);var ds=b(Y());var yF={token:null,interval:null},C0=he("passwordlessToken/getTemporaryPasswordlessToken",(e,t)=>I(void 0,null,function*(){let{deepdeskAPI:n}=t.extra;return{token:yield n.requestPasswordlessToken()}})),k0=he("passwordlessToken/pollPasswordlessToken",(e={},t)=>{let{interval:n=1e3*60*10}=e,{dispatch:r}=t;return r(C0()),setInterval(()=>r(C0()),n)}),MP=ke({name:"passwordlessToken",initialState:yF,reducers:{stopPollPasswordlessToken(e){e.interval&&clearInterval(e.interval),e.interval=null}},extraReducers:e=>{e.addCase(C0.fulfilled,(t,n)=>{t.token=n.payload.token}),e.addCase(k0.fulfilled,(t,n)=>{t.interval=n.payload})}}),{stopPollPasswordlessToken:NP}=MP.actions,OP=MP.reducer;function vF(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t}var _P=$t([QT],e=>e.map(n=>({text:n.response,title:n.name,callToAction:n.callToAction,editable:n.editable,isLoading:n.isLoading,specialType:n.specialType,rule:{id:vF(n.code),label:n.code,name:n.name,description:n.name}})));var am=b(Y());var P0=b(Oe());var R0=b(R()),iu=()=>(0,R0.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 512 512",xmlns:"http://www.w3.org/2000/svg",children:(0,R0.jsx)("path",{d:"M502.6 70.63l-61.25-61.25C435.4 3.371 427.2 0 418.7 0H255.1c-35.35 0-64 28.66-64 64l.0195 256C192 355.4 220.7 384 256 384h192c35.2 0 64-28.8 64-64V93.25C512 84.77 508.6 76.63 502.6 70.63zM464 320c0 8.836-7.164 16-16 16H255.1c-8.838 0-16-7.164-16-16L239.1 64.13c0-8.836 7.164-16 16-16h128L384 96c0 17.67 14.33 32 32 32h47.1V320zM272 448c0 8.836-7.164 16-16 16H63.1c-8.838 0-16-7.164-16-16L47.98 192.1c0-8.836 7.164-16 16-16H160V128H63.99c-35.35 0-64 28.65-64 64l.0098 256C.002 483.3 28.66 512 64 512h192c35.2 0 64-28.8 64-64v-32h-47.1L272 448z"})});var DP={root:"dd-WcEru",entity:"dd-LfP8y",entityText:"dd-L-v0f",iconWrapper:"dd-9Deh1",icon:"dd-tM7E2",iconClicked:"dd-EEdDL"};var Fr=b(R()),xF=({entities:e})=>{let t=_("EntitiesWidgetList",DP),[n,r]=(0,am.useState)(void 0),o=ve(),s=()=>{r(void 0)},i=a=>{e&&(r(e.indexOf(a)),Ir(a.text),o(ro({name:"entity copied",data:{entity:a,type:"copy"}})))};return(0,am.useEffect)(()=>{let a=setTimeout(s,500);return()=>{clearTimeout(a)}},[n]),!e||e.length===0?null:(0,Fr.jsx)("div",{className:t.root,"data-testid":"widget-entities-list",children:e.map((a,l)=>(0,Fr.jsxs)("button",{title:a.text,className:t.entity,type:"button",onClick:()=>i(a),children:[(0,Fr.jsx)("span",{className:t.entityText,children:a.text}),(0,Fr.jsxs)("span",{className:t.iconWrapper,children:[(0,Fr.jsx)("span",{className:(0,P0.default)(t.icon),children:(0,Fr.jsx)(iu,{})}),(0,Fr.jsx)("span",{className:(0,P0.default)(t.icon,n===l&&t.iconClicked),children:(0,Fr.jsx)(iu,{})})]})]},a.text))})},FP=xF;var A0=b(R()),zP=()=>(0,A0.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,A0.jsx)("path",{d:"M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9",stroke:"currentColor",strokeWidth:"1.5",fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"})});var jP=b(Y());var HP={root:"dd-ohnXe",trigger:"dd-7i-S3",button:"dd-t53Cg",nav:"dd-qZFnm",item:"dd-FZC0F"};var BP={root:"dd-nazq3",rotation:"dd-3EHTv"};var VP=b(R()),wF=({size:e=12})=>{let t=_("LoadingSpinner",BP);return(0,VP.jsx)("span",{"data-testid":"loading-spinner",style:{width:`${e}px`,height:`${e}px`},className:t.root})},UP=wF;var I0=b(R()),$P=()=>(0,I0.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",height:"1em",viewBox:"0 0 512 512",fill:"currentColor",children:(0,I0.jsx)("path",{d:"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32s14.3 32 32 32s32-14.3 32-32z"})});var au=b(R()),WP=e=>(0,au.jsxs)("svg",P(S({xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 448 512","aria-labelledby":"checkTitle"},e),{children:[(0,au.jsx)("title",{id:"checkTitle",children:"Check"}),(0,au.jsx)("path",{fill:"#666",d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"})]}));var L0={};pt(L0,{enUS:()=>SF,nlNL:()=>bF});var SF={error:[{type:0,value:"Something went wrong"}]},bF={error:[{type:0,value:"Er ging iets fout"}]};var Pn=b(R()),EF=3e3,TF=({assistantOptions:e})=>{let t=_("OnDemandAssistants",HP),n=ie(L0),r=(0,jP.useRef)(),o=ai(or),s=ai(so),i=W(oC),a=W(sC),l=ut(),c=a.filter(f=>f.isPinned),u=a.filter(f=>!f.isPinned),d=f=>I(void 0,null,function*(){clearTimeout(r.current),l("trigger on demand assistant",{assistantCode:f}),f===i?yield s.call({transcript:e.transcript}):yield o.call(P(S({},e),{assistantCode:f})),r.current=setTimeout(()=>o.reset(),EF)});return a.length===0?null:(0,Pn.jsxs)("div",{className:t.root,children:[c.map(({assistant:f,assistantName:p,displayName:y})=>(0,Pn.jsx)("button",{type:"button",className:t.button,disabled:o.state==="loading",onClick:()=>d(f),children:y||p},f)),u.length>0&&(0,Pn.jsxs)(vt,{placement:"top-end",children:[(0,Pn.jsx)(vt.Trigger,{className:t.trigger,disabled:o.state==="loading",children:(0,Pn.jsx)(Fp,{"data-testid":"trigger"})}),(0,Pn.jsx)(vt.Content,{className:t.nav,"data-testid":"popover",children:u.map(({assistant:f,assistantName:p,displayName:y})=>(0,Pn.jsx)(vt.Button,{className:t.item,disabled:o.state==="loading",onClick:()=>d(f),children:y||p},f))})]}),o.state==="loading"&&(0,Pn.jsx)(UP,{}),o.state==="done"&&(0,Pn.jsx)(WP,{"data-testid":"trigger-done"}),o.state==="error"&&(0,Pn.jsx)(Vk,{trigger:(0,Pn.jsx)($P,{}),children:n("error")})]})},KP=TF;var YP=b(Y());var GP={loadingBar:"dd-6as-V",placeHolderShimmer:"dd-TFYmA"};var qP=b(R()),CF=({width:e})=>{let t=_("LoadingProgressBar",GP);return(0,qP.jsx)("div",{className:t.loadingBar,style:{width:e}})},lm=CF;var So=b(R()),cm=({title:e})=>{let t=(0,YP.useRef)(null);return Ou(t),(0,So.jsx)(ge,{ref:t,children:(0,So.jsx)(Se,{children:(0,So.jsxs)(Se.Content,{children:[(0,So.jsx)(Se.Title,{children:e}),(0,So.jsx)(lm,{width:"60%"}),(0,So.jsx)(lm,{width:"90%"}),(0,So.jsx)(lm,{width:"50%"})]})})})};var lu={};pt(lu,{enUS:()=>kF,nlNL:()=>RF});var kF={useCue:[{type:0,value:"Add to message"}],__summarizerAssistant__:[{type:0,value:"Summary"}],copyCue:[{type:0,value:"Copy"}],removeCue:[{type:0,value:"Close"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}]},RF={useCue:[{type:0,value:"Voeg toe aan bericht"}],__summarizerAssistant__:[{type:0,value:"Samenvatting"}],copyCue:[{type:0,value:"Kopi\xEBren"}],removeCue:[{type:0,value:"Sluiten"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}]};var hi=b(Y());var M0={title:"dd-YBHrC",fadeup:"dd-cRM0K",fadedown:"dd-7D4Pq",selected:"dd-bueui",actions:"dd-9Iqn9",thumbsUp:"dd-6QwVx",thumbsDown:"dd-d3E8l",form:"dd-sPNU2",formInput:"dd-F3E4I",formSubmit:"dd-vw5S0",actionButton:"dd-cCWyJ",editableCue:"dd-nWSD-",inputSpace:"dd-DGYB1"};var Ot=b(R()),PF=500,AF=100,IF=({content:e,onChange:t,onCopy:n})=>{let r=(0,hi.useRef)(null),o=_("WidgetCue",M0);return(0,hi.useEffect)(()=>{let s=r.current;if(!s)return;s.style.setProperty("height","0px");let i=Math.min(Math.max(s.scrollHeight,AF),PF);s.style.setProperty("height",`${i}px`)},[e]),(0,Ot.jsx)("textarea",{ref:r,className:o.editableCue,onCopy:n,onChange:t,value:e})},LF=({cue:e,onCallToAction:t,onRemove:n,onCopy:r,onUse:o})=>{var g;let s=_("WidgetCue",M0),i=ie(lu),a=ut(),l=te("hasKeyboardInput"),[c,u]=(0,hi.useState)(e.text),d=()=>{t&&t(c,e),n(e)},f=x=>{r&&r(x,e)},p=x=>{o&&o(x,e)},y=x=>{x.preventDefault(),x.stopPropagation(),n(e)};return(0,hi.useEffect)(()=>{a("Assistant response displayed",{name:e.rule.name,description:e.rule.description,group:e.rule.label,cueText:e.text})},[]),(0,Ot.jsxs)(ge,{"data-testid":"cue",children:[(0,Ot.jsx)(Se,{children:(0,Ot.jsxs)(Se.Content,{children:[e.title&&(0,Ot.jsx)(Se.Title,{className:s.title,"data-testid":"widget-cue-title",children:e.rule.label.startsWith("__")?i(e.rule.label):e.title}),e.specialType==="summary"||e.editable?(0,Ot.jsx)(IF,{content:c,onCopy:()=>{let x=document.getSelection();x&&f(x.toString())},onChange:x=>{var v;return u((v=x.target.value)!=null?v:"")}}):(0,Ot.jsx)(ho,{content:e.text,useLabel:i("useCue"),copyLabel:i("copyCue"),onCopy:f,onUse:l?p:void 0})]})}),(0,Ot.jsxs)(ge.ButtonsContainer,{children:[(0,Ot.jsxs)("div",{className:s.actions,children:[(e.specialType==="summary"||e.editable)&&(0,Ot.jsx)(ge.Button,{onClick:()=>f(c),children:i("copyCue")}),e.callToAction&&(0,Ot.jsx)(ge.Button,{onClick:d,children:e.callToAction.label}),(0,Ot.jsx)(ge.Button,{onClick:y,children:i("removeCue")})]}),e.specialType==="summary"?(0,Ot.jsx)(li,{eventName:"summary feedback",feedbackText:(g=e.text)!=null?g:"",feedbackType:"summary",eventData:{summary:e.text}}):(0,Ot.jsx)(li,{eventName:"Assistant response feedback",eventData:{name:e.rule.name,group:e.rule.label,description:e.rule.description,cueText:e.text},feedbackText:e.text,feedbackType:"assistant"})]})]})},XP=LF;var Ha=b(R()),MF=({cues:e})=>{let t=ve(),n=dn(),r=ie(lu),o=ut(),s=c=>{t(Gf({code:c.rule.label})),o("Assistant response closed",{name:c.rule.name,group:c.rule.label,description:c.rule.description,cueText:c.text})},i=(c,u)=>{switch(Ir(c),u.specialType){case"summary":o("summary copied to clipboard",{originalText:u.text,finalText:c,assistant:u.rule.label});break;default:o("Assistant response copied",{name:u.rule.name,group:u.rule.label,description:u.rule.description,copiedText:c,originalText:u.text})}},a=(c,u)=>{var d;u.callToAction&&(t(Kf(u)),o("Assistant call to action",{name:u.rule.name,group:u.rule.label,description:u.rule.description,eventName:u.callToAction.event,value:(d=u.callToAction.value)!=null?d:c,originalText:u.text}))},l=(c,u)=>{var d;n.send(Pr,{text:c,suggestion:{source:"assistant",assistantCode:(d=u.rule)==null?void 0:d.label,sourceText:c}}),o("Assistant response used",{name:u.rule.name,group:u.rule.label,description:u.rule.description,usedText:c,originalText:u.text})};return(0,Ha.jsx)(Ha.Fragment,{children:e.map(c=>c.isLoading?(0,Ha.jsx)(cm,{title:c.rule.label.startsWith("__")?r(c.rule.label):c.title},c.rule.id):(0,Ha.jsx)(XP,{cue:c,onCallToAction:a,onRemove:s,onCopy:i,onUse:l},c.rule.id))})},QP=MF;var um=b(Y());var ZP={root:"dd-cvTAY",label:"dd-QWQxD",value:"dd-WSUHF",copyButton:"dd-67o9H",copyButtonText:"dd-oos-l",isTrue:"dd--1g2O",isFalse:"dd-sz2ir"};var hr=b(R());function NF(e,t){return t.split(".").reduce((n,r)=>!n||typeof n!="object"||!(r in n)?null:n[r],e)}var JP=({data:e,schema:t})=>{let n=_("WidgetCustomData",ZP),r=o=>{Ir(o)};return(0,um.useEffect)(()=>{Z.info("Custom data",e,t)},[e]),(0,hr.jsx)("dl",{className:n.root,children:t.map(o=>{let s=NF(e,o.path);return(0,hr.jsxs)(um.Fragment,{children:[(0,hr.jsx)("dt",{className:n.label,children:o.label}),(0,hr.jsx)("dd",{className:n.value,children:o.type==="boolean"&&s?(0,hr.jsx)("span",{className:n.isTrue,children:o.trueValue}):o.type==="boolean"&&!s?(0,hr.jsx)("span",{className:n.isFalse,children:o.falseValue}):typeof s=="string"||typeof s=="number"?(0,hr.jsxs)("button",{type:"button",onClick:()=>r(`${s}`),className:n.copyButton,children:[(0,hr.jsx)("span",{className:n.copyButtonText,children:s}),(0,hr.jsx)(iu,{})]}):"-"})]},o.label)})})};var rt=b(Y());var Ba={};pt(Ba,{enUS:()=>OF,nlNL:()=>_F});var OF={inputPlaceholder:[{type:0,value:"What is your question?"}],useCue:[{type:0,value:"Add to message"}],copyCue:[{type:0,value:"Copy"}],removeCue:[{type:0,value:"Close"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}],submitLabel:[{type:0,value:"Submit"}],resetLabel:[{type:0,value:"Reset"}],showMore:[{type:0,value:"Show "},{type:1,value:"amount"},{type:0,value:" more"}]},_F={inputPlaceholder:[{type:0,value:"Wat is je vraag?"}],useCue:[{type:0,value:"Voeg toe aan bericht"}],copyCue:[{type:0,value:"Kopi\xEBren"}],removeCue:[{type:0,value:"Sluiten"}],thumbsUp:[{type:0,value:"Thumbs up"}],thumbsDown:[{type:0,value:"Thumbs down"}],submitLabel:[{type:0,value:"Verzend"}],resetLabel:[{type:0,value:"Gesprek wissen"}],showMore:[{type:0,value:"Toon "},{type:1,value:"amount"},{type:0,value:" meer"}]};var dm={form:"dd-pleCH",formInput:"dd-pGJMY",formSubmit:"dd--gkRg",actionButton:"dd-I2NEH",resetContainer:"dd-qKIDX",sources:"dd-xf9c6",source:"dd-a-vyX",tooltip:"dd-EsgcZ",linkContent:"dd-gARDA",showMoreSources:"dd-uDGi-"};var tA=b(Y());var eA={error:"dd-CoAuB"};var N0={};pt(N0,{enUS:()=>DF,nlNL:()=>FF});var DF={errorPrefix:[{type:0,value:"Error:"}]},FF={errorPrefix:[{type:0,value:"Foutmelding:"}]};var cu=b(R()),nA=({message:e})=>{let t=(0,tA.useRef)(null),n=_("WidgetCardError",eA),r=ie(N0);return Ou(t),(0,cu.jsx)(ge,{ref:t,children:(0,cu.jsx)(Se,{children:(0,cu.jsxs)(Se.Content,{className:n.error,children:[r("errorPrefix")," ",e]})})})};var we=b(R()),zF=3,HF=({sources:e,onClick:t})=>{let n=ie(Ba),r=_("WidgetKnowledgeAssistant",dm),[o,s]=(0,rt.useState)(!1),i=o?e:e.slice(0,zF);return i.length===0?null:(0,we.jsxs)("ul",{className:r.sources,children:[i.map(a=>(0,we.jsx)("li",{className:r.source,"data-testid":"knowledge-assist-source",children:(0,we.jsxs)(vt,{tooltip:!0,placement:"top-start",children:[(0,we.jsx)(vt.Trigger,{as:"a",rel:"noreferrer",target:"_blank",href:a.url,onClick:l=>{l.stopPropagation(),t(a)},children:(0,we.jsx)("span",{className:r.linkContent,children:a.name})}),a.url&&(0,we.jsx)(vt.Content,{className:r.tooltip,children:decodeURIComponent(a.url)})]})},a.name)),i<e&&(0,we.jsx)("button",{type:"button",className:r.showMoreSources,onClick:()=>s(!0),children:n("showMore",{amount:e.length-i.length})})]})},BF=({title:e,description:t})=>(0,we.jsx)(ge,{"data-testid":"knowledge-assist-empty-state",children:(0,we.jsx)(Se,{children:(0,we.jsxs)(Se.Content,{children:[(0,we.jsx)(Se.Title,{children:e}),(0,we.jsx)(ho,{content:t})]})})}),UF=({innerRef:e,item:t,index:n,hasKeyboardInput:r,onCopy:o,onUse:s,onSourceClick:i})=>{var l;let a=ie(Ba);return(0,we.jsxs)(ge,{"data-testid":"knowledge-assist-answer",ref:e,children:[(0,we.jsx)(Se,{children:(0,we.jsxs)(Se.Content,{children:[(0,we.jsx)(Se.Title,{children:t.question}),(0,we.jsx)(ho,{content:t.answer.answer,useLabel:a("useCue"),copyLabel:a("copyCue"),onCopy:o,onUse:r?s:void 0}),(0,we.jsx)(HF,{sources:(l=t.answer.sources)!=null?l:[],onClick:c=>i(c,t.question)})]})}),(0,we.jsxs)(ge.ButtonsContainer,{children:[(0,we.jsx)("div",{}),(0,we.jsx)(li,{eventName:"knowledge assist feedback",eventData:{question:t.question,isFollowUpQuestion:n>0,isAgent:!0,answer:t.answer.answer},feedbackText:t.answer.answer,feedbackType:"assistant"})]})]})},O0=(0,rt.createContext)(null),fm=({assistantCode:e,evaluateKnowledgeAssistFn:t,initialQuestion:n,children:r})=>{let[o,s]=(0,rt.useState)(null),[i,a]=(0,rt.useState)(!1),[l,c]=(0,rt.useState)(null),[u,d]=(0,rt.useState)(!!n),[f,p]=(0,rt.useState)(null),y=ve(),g=ut(),x=ai(m=>{if(!e)throw new Error("No knowledge assistant was defined");return c(null),t({assistantCode:e,input:m,threadId:o,onNewThreadId(w){s(w)}})},{onSuccess(m){var w;g("knowledge assist question answered",{question:m.question,answer:m.answer.answer,sources:(w=m.answer.sources)!=null?w:[],isFollowUpQuestion:m.threadId===o,isAutoInitiated:u}),d(!1)},onError(m){var w;c((w=m.message)!=null?w:"Unknown error")}}),v=m=>I(void 0,null,function*(){a(!0),p(m),yield x.call(m),a(!1),p(null)}),h={isEnabled:!!e,isSubmitting:i,threadId:o,pendingInput:f,errorMessage:l,onSubmit:v,onReset(){o&&y(ga(o)),c(null),s(null)}};return(0,rt.useEffect)(()=>{n&&h.isEnabled&&v(n)},[n]),(0,we.jsx)(O0.Provider,{value:h,children:r})},pm=()=>{let e=ie(Ba),t=_("WidgetKnowledgeAssistant",dm),n=(0,rt.useContext)(O0),r=(0,rt.useRef)(null),[o,s]=(0,rt.useState)(""),i=l=>{s(l.target.value)},a=l=>{l.preventDefault(),n.onSubmit(o).then(()=>{var c;r.current&&((c=r.current)==null||c.focus(),s(""))})};return n.isEnabled?(0,we.jsxs)("form",{className:t.form,onSubmit:a,children:[(0,we.jsx)("input",{ref:r,className:t.formInput,placeholder:e("inputPlaceholder"),type:"text",disabled:n.isSubmitting,value:o,onChange:i}),(0,we.jsx)("button",{type:"submit",disabled:n.isSubmitting||o==="",className:t.formSubmit,children:e("submitLabel")})]}):null},mm=({title:e,emptyState:t})=>{var y,g;let n=ie(Ba),r=ut(),o=_("WidgetKnowledgeAssistant",dm),s=(0,rt.useRef)(null),i=(0,rt.useContext)(O0),a=(g=W(bc((y=i.threadId)!=null?y:-1)))!=null?g:[],l=te("hasKeyboardInput"),c=dn(),u=x=>{Ir(x),r("Assistant response copied",{name:"Knowledge Assistant",group:"knowlegde-assist",description:"",copiedText:x,originalText:x})},d=(x,v)=>{r("knowledge assist source viewed",{question:v,sourceViewed:x.url||x.name})},f=x=>{var v;x.preventDefault(),i.onReset(),r("knowledge assist reset",{threadId:(v=i.threadId)!=null?v:void 0})},p=x=>{c.send(Pr,{text:x,suggestion:{source:"assistant",sourceText:x}}),r("Assistant response used",{name:"Knowledge Assistant",group:"knowlegde-assist",description:"",usedText:x,originalText:x})};return!i.isEnabled||(a==null?void 0:a.length)===0&&!i.isSubmitting&&!t&&!i.errorMessage?null:(0,we.jsxs)(rt.Fragment,{children:[(0,we.jsx)(wr,{type:"knowledge",title:e,"data-testid":"knowledge",children:(0,we.jsxs)(Ht,{withDivider:!0,children:[t&&a.length===0&&!i.pendingInput&&(0,we.jsx)(BF,S({},t)),a.map((x,v)=>(0,we.jsx)(UF,{innerRef:v===a.length-1?s:void 0,item:x,index:v,hasKeyboardInput:l,onCopy:u,onUse:p,onSourceClick:d},`${x.question}_${x.answer}_${v}`)),i.pendingInput&&(0,we.jsx)(cm,{title:i.pendingInput}),i.errorMessage&&(0,we.jsx)(nA,{message:i.errorMessage})]})}),a.length>0&&(0,we.jsx)("div",{className:o.resetContainer,children:(0,we.jsx)(ge.Button,{disabled:i.threadId===null||i.isSubmitting,onClick:f,children:n("resetLabel")})})]})};var sA=b(Y());var VF=/(https?:\/\/[^\s]+)/,oA=e=>e.split(" ").find(t=>VF.test(t));var $n=b(R()),$F=({suggestion:e,lines:t,onUse:n})=>{var d;let r=e.text||e.url||e.message,o=oA(r),s=ie(Qc),i=te("showImages"),a=te("fallbackImage"),l=te("hasKeyboardInput"),c=f=>{f.preventDefault(),f.stopPropagation(),l&&n(r)},u=(0,sA.useCallback)(f=>{window.open(o,"_blank"),f.stopPropagation(),f.preventDefault()},[o]);return(0,$n.jsxs)(ge,{onClick:l?c:void 0,"data-testid":"edit-suggestion",children:[(0,$n.jsxs)(Se,{children:[i&&e.image&&(0,$n.jsx)(Se.Image,{src:rm(e,"small",a||void 0),title:e.title}),(0,$n.jsxs)(Se.Content,{children:[e.title&&(0,$n.jsx)(Se.Title,{"data-testid":"widget-suggestion-title",children:e.title}),e.searchKeywords&&((d=e.searchKeywords)==null?void 0:d.length)>0&&(0,$n.jsx)(ge.Labels,{labels:e.searchKeywords}),(0,$n.jsx)(Se.Content,{cropText:t==="single",lineClamp:t==="multiple",children:r})]})]}),(0,$n.jsxs)(ge.Actions,{children:[o&&(0,$n.jsx)(ge.ActionButton,{onClick:u,label:s("visitUrl")}),l&&(0,$n.jsx)(ge.ActionButton,{primary:!0,onClick:c,label:s("useSuggestion")})]})]})},iA=$F;var uu=b(R()),WF=({lines:e,suggestions:t})=>{let n=dn(),r=(o,s)=>{n.send(Pr,{text:o,suggestion:P(S({},s),{source:s.source,sourceText:s.text})})};return(0,uu.jsx)(uu.Fragment,{children:t.map(o=>(0,uu.jsx)(iA,{suggestion:o,lines:e,onUse:s=>r(s,o)},o.text||o.url||o.message))})},aA=WF;var du={};pt(du,{enUS:()=>jF,nlNL:()=>KF});var jF={waiting:[{type:0,value:"Loading\u2026"}],waitingForConversation:[{type:0,value:"Waiting for conversation\u2026"}],notSupported:[{type:0,value:"This conversation is not supported"}],noResults:[{type:0,value:"No results found\u2026"}],titleCues:[{type:0,value:"Assistant updates"}],actions:[{type:0,value:"Shortcuts"}],linkStudioLogin:[{type:0,value:"My "},{type:1,value:"productName"}],linkSummary:[{type:0,value:"Summarize"}],linkKnowledgeSearch:[{type:0,value:"Knowledge Assist"}],linkSearch:[{type:0,value:"Search"}],close:[{type:0,value:"Close"}]},KF={waiting:[{type:0,value:"Laden\u2026"}],waitingForConversation:[{type:0,value:"Wachten op gesprek\u2026"}],notSupported:[{type:0,value:"Dit gesprek wordt niet ondersteund"}],noResults:[{type:0,value:"Geen resultaten gevonden\u2026"}],titleCues:[{type:0,value:"Assistant updates"}],actions:[{type:0,value:"Shortcuts"}],linkStudioLogin:[{type:0,value:"Mijn "},{type:1,value:"productName"}],linkSummary:[{type:0,value:"Gesprek samenvatten"}],linkKnowledgeSearch:[{type:0,value:"Knowledge assist"}],linkSearch:[{type:0,value:"Zoeken"}],close:[{type:0,value:"Sluiten"}]};var Ua={root:"dd-W9VCG",loginText:"dd--dS6t",stateText:"dd-348OC",footer:"dd-tvofr",shortcutList:"dd-MuKK-",shortcut:"dd-5CnK9",footerShortcut:"dd-dH7XJ",link:"dd-DRo0x"};var ue=b(R()),lA=(e,t)=>{let n=W(Wt);(0,ds.useEffect)(()=>n?t.every(r=>!!r)?e():()=>{}:()=>{},[...t,n])},GF=({onLogIn:e})=>{let t=_("Widget",Ua),n=te("isEmbedded"),r=te("adminUrl");return(0,ue.jsx)("div",{className:t.loginText,children:(0,ue.jsx)("div",{children:(0,ue.jsx)(Gp,{isEmbedded:n,loginUrl:r,onLogIn:e})})},"login")},_0=({text:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.stateText,children:(0,ue.jsx)("div",{children:(0,ue.jsx)("p",{children:e})})},"notification")},qF=()=>{let e=ie(du),t=ve(),n=_("Widget",Ua),r=te("showSearch"),o=te("isEmbedded"),s=W(Na("/admin/")),i=dn(),a=te("productName"),l=ut();return lA(()=>{if(o)return t(k0()),()=>{t(NP())}},[t,o]),!r&&!s?null:(0,ue.jsxs)("div",{className:n.shortcutList,children:[r&&(0,ue.jsx)(ge.Button,{"data-testid":"shortcut-search","aria-label":e("linkSearch"),className:n.shortcut,icon:(0,ue.jsx)(Aa,{}),onClick:()=>{i.send("ShowCommandPalette",{isOpen:!0}),l("open search",{via:"widget-shortcut"})},children:e("linkSearch")}),s&&(0,ue.jsx)(ge.Button,{as:"a",target:"_blank",icon:(0,ue.jsx)(zP,{}),href:s,"data-testid":"shortcut-studio-login","aria-label":e("linkStudioLogin",{productName:a}),className:n.shortcut,rel:"noreferrer",onClick:()=>{l("open my deepdesk",{via:"widget-shortcut"})},children:e("linkStudioLogin",{productName:a})})]})},YF=({title:e,content:t})=>{let n=ie(du),[r,o]=(0,ds.useState)(!0);return r?(0,ue.jsx)(wr,{"data-testid":"custom-data-banner",type:"custom-data-banner",title:e,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsxs)(ge,{children:[(0,ue.jsx)(Se,{children:(0,ue.jsx)(Se.Content,{children:(0,ue.jsx)(ho,{content:t})})}),(0,ue.jsx)(ge.ButtonsContainer,{children:(0,ue.jsx)(ge.Button,{onClick:()=>o(!1),children:n("close")})})]})})}):null},XF=()=>{let e=ve(),t=W(Cc),n=W(aC),r=W(_P),o=W(eT),s=W(Ap),i=W(Bp),a=W(qs),l=W(Rr);return(0,ds.useEffect)(()=>{!!o&&!n&&Z.warn("Custom data provided, but no schema.")},[o,n]),lA(()=>{t.forEach(({type:c})=>{c==="entities"?e(fr()):Fu.includes(c)||e(gr(c))})},[e,l,a]),(0,ds.useEffect)(()=>{r.length>0&&!t.some(c=>c.type==="cues")&&Z.warn("Received cues, but cues are not configured in widget.")},[t,r]),(0,ue.jsx)(ds.Fragment,{children:t.map(({type:c,title:u,amount:d,lines:f,schema:p,property:y})=>{var g,x;switch(c){case"entities":return s&&s.length>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(FP,{entities:s})},c);case"cues":return r&&r.length>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(QP,{cues:r})})},c);case"custom-data-banner":return o&&y&&o[y]&&(0,ue.jsx)(YF,{title:u,content:String(o[y])},c);case"custom-data":return o&&p&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(JP,{data:o,schema:p})})},c);default:return((x=(g=i[c])==null?void 0:g.suggestions)==null?void 0:x.length)>0&&(0,ue.jsx)(wr,{type:c,title:u,"data-testid":`type-${c}`,children:(0,ue.jsx)(Ht,{withDivider:!0,children:(0,ue.jsx)(aA,{lines:f,contentType:c,suggestions:i[c].suggestions.slice(0,d)||[]})})},c)}})})},D0=({children:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.footer,children:e})},F0=({children:e})=>{let t=_("Widget",Ua);return(0,ue.jsx)("div",{className:t.root,"data-testid":"widget",children:e})},QF=({onLogIn:e,knowledgeAssistOptions:t={},assistantOptions:n={transcript:"in-memory-transcript",expectFormat:"json-schema:cues"}})=>{let r=ie(du),o=W(la),s=W(Wt),i=W(z1),a=W(qs),l=W(iC("knowledge-assist")),c=W(qf),u=W(Yf);return o===!1?(0,ue.jsx)(_0,{text:r("notSupported")}):s===!1?(0,ue.jsx)(GF,{onLogIn:e}):s===null?(0,ue.jsx)(_0,{text:r("waiting")}):!i||!a?(0,ue.jsx)(_0,{text:r("waitingForConversation")}):(0,ue.jsx)(F0,{children:(0,ue.jsxs)(fm,{initialQuestion:t.initialQuestion,assistantCode:c!=null?c:u,evaluateKnowledgeAssistFn:u?Ks:Gs,children:[(0,ue.jsxs)(Ri,{children:[(0,ue.jsx)(qF,{}),(0,ue.jsx)(XF,{}),l&&(0,ue.jsx)(mm,{title:l.title,emptyState:t.emptyState})]}),(0,ue.jsxs)(D0,{children:[l&&(0,ue.jsx)(pm,{}),(0,ue.jsx)(KP,{assistantOptions:n})]})]})})},cA=QF;function Va(e){let t=new Range;return t.selectNodeContents(e),t}function uA(e,t,n){try{return fs(e,t,n),!0}catch(r){return!1}}function gm(e){return"tagName"in e&&(e.tagName==="DIV"||e.tagName==="P")}function hm(e){return"tagName"in e&&e.tagName==="BR"}var fu=/[\u200B-\u200D\uFEFF]/g;function fs(e,t,n){let r=new Range;if(e.firstChild===null&&t===0&&n===0)return r.selectNodeContents(e),r;let o=0,s=!1;function i(l,c){let u=-1,d=/[\u200B-\u200D\uFEFF]/;if(!d.test(l))return c;for(let f=0;f<=l.length;f++)if(d.test(l[f])||u++,u===c)return f;throw new Error("Offset out of range")}function a(l){switch(l.nodeType){case Node.TEXT_NODE:{let c=l.textContent,u=c.replace(fu,""),d=o+u.length,f=t>=o&&t<=d,p=n>=o&&n<=d;if(f){let y=i(c,t-o);y===0&&!p?r.setStartBefore(l):r.setStart(l,y)}p&&(r.setEnd(l,i(c,n-o)),s=!0),o=d;break}case Node.ELEMENT_NODE:{if(hm(l)&&(o===t&&r.setStartBefore(l),o++,o===n)){r.setEndAfter(l),s=!0;return}for(let u=0;u<l.childNodes.length&&(a(l.childNodes[u]),!s);u++);let c=l.lastChild;gm(l)&&c&&!gm(c)&&!hm(c)&&o++;break}default:break}}if(a(e),r.startContainer===document)throw new Error("Offsets out of bound");return r}function pu(e,t){if(!e.contains(t.startContainer)||!e.contains(t.endContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:r,endContainer:o,endOffset:s,collapsed:i}=t,a,l,c=0;function u(d){let f=d===e,p=d===n,y=d===o;switch(d.nodeType){case Node.TEXT_NODE:{let g=d.textContent;p&&(a=c+g.substring(0,r).replace(fu,"").length),y&&(l=c+g.substring(0,s).replace(fu,"").length),c+=g.replace(fu,"").length;break}case Node.ELEMENT_NODE:{if(hm(d)&&d.nextSibling){c++;break}!f&&gm(d)&&d.previousSibling&&c++;for(let g=0;g<d.childNodes.length;g++){let x=p&&g===r,v=y&&g===s;if(x&&(a=c),v&&(l=c),l!==void 0||((!x||!i)&&u(d.childNodes[g]),y&&g===s-1&&(l=c),l!==void 0))break}y&&(l=c);break}default:break}}if(u(e),l===void 0)throw new Error("Could not determine start and end");return{start:a!=null?a:l,end:l}}function mu(e,t){if(!e.contains(t.startContainer)||!e.contains(t.endContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:r,endContainer:o,endOffset:s,collapsed:i}=t,a=0,l="";function c(u){let d=u===e,f=u===n,p=u===o;switch(f&&(a=1),u.nodeType){case Node.TEXT_NODE:{if(a!==1)return;let y=f?r:0,g=p?s:void 0;l+=u.textContent.replace(fu,"").substring(y,g);break}case Node.ELEMENT_NODE:{if(!i&&a===1&&hm(u)&&u.nextSibling){l+=`
|
|
81
81
|
`;break}!d&&!i&&a===1&&gm(u)&&u.previousSibling&&(l+=`
|
|
82
|
-
`);let y=f?r:0,g=p?Math.min(s,u.childNodes.length):u.childNodes.length;for(let x=y;x<g&&(c(u.childNodes[x]),a!==2);x++);break}default:break}p&&(a=2)}return c(e),l}var dA=(i=>(i.CUT="Cut",i.BACKSPACE="Backspace",i.DELETE="Delete",i.ERASEEOF="EraseEof",i.UNDO="Undo",i.CLEAR="Clear",i))(dA||{}),bo=class{constructor(t){this.element=t;this.isFocused=!1;this.isActive=!0;this.isDisposed=!1;this.eventListeners={};this.disposeHandlers=[];this.cachedText="";this.cachedCaretPosition=null;this.cachedSelection={start:0,end:0};this.cachedHTML="";this.isSubmitting=!1;this.isPossibleClearInputAction=!1;this.cachedText=this.getText(),this.cachedHTML=this.getHTML(),this.cachedSelection=this.getSelection(),this.listen()}addEventListener(t,n){let r=o=>{n(o)};this.element.addEventListener(t,r),this.disposeHandlers.push(()=>{this.element.removeEventListener(t,r)})}removeEventListener(t,n){this.element.removeEventListener(t,n)}handleInteraction(){let t=this.getText(),n=this.getHTML(),r=this.getSelection(),o=this.cachedCaretPosition===null;if(!this.isActive||(t===""&&this.cachedText!==""&&!this.isPossibleClearInputAction&&this.emit("submit"),t!==this.cachedText?(this.cachedText=t,this.cachedHTML=n,o=!0,this.emit("change",{plainText:t,rawHTML:n})):n!==null&&n!==this.cachedHTML&&(this.cachedHTML=n,o=!0,this.emit("change",{plainText:t,rawHTML:n})),(r.start!==this.cachedSelection.start||r.end!==this.cachedSelection.end)&&(this.cachedSelection=r,o=!0,this.emit("selection",r)),!o))return;let s=this.getCaretPosition();Xo(s,this.cachedCaretPosition)||(this.cachedCaretPosition=s,this.emit("caretposition",s))}handleClick(){this.handleInteraction()}handleFocus(){let t=!this.isFocused;this.isFocused=!0,t&&this.emit("focus"),this.handleInteraction()}handleBlur(){this.isPossibleClearInputAction=!1;let t=this.isFocused;this.isFocused=!1,t&&this.emit("blur")}handleKeyDown(t){let{key:n,ctrlKey:r,metaKey:o}=t;this.isPossibleClearInputAction=Object.values(dA).includes(n)||n.toLowerCase()==="z"&&(r||o),this.emit("keydown",t)}handleKeyUp(t){this.handleInteraction(),this.emit("keyup",t)}handleCut(){this.isPossibleClearInputAction=!0,this.emit("cut",{selectionText:this.getSelectedText()})}handlePaste(t){var r,o;let n=((r=t.clipboardData)==null?void 0:r.getData("text"))||((o=t.clipboardData)==null?void 0:o.getData("text/plain"))||"";this.emit("paste",{pastedText:n,selectionText:this.getSelectedText()})}listen(){this.addEventListener("keydown",n=>this.handleKeyDown(n)),this.addEventListener("keyup",n=>this.handleKeyUp(n)),this.addEventListener("input",()=>this.handleInteraction()),this.addEventListener("change",()=>this.handleInteraction()),this.addEventListener("focus",()=>this.handleFocus()),this.addEventListener("blur",()=>this.handleBlur()),this.addEventListener("cut",()=>this.handleCut()),this.addEventListener("paste",n=>this.handlePaste(n)),this.addEventListener("click",()=>this.handleInteraction()),document.activeElement===this.element&&(this.isFocused=!0);let t=new MutationObserver(()=>{this.element.isConnected||(this.emit("unmounted"),this.dispose())});t.observe(document.body,{subtree:!0,childList:!0}),this.disposeHandlers.push(()=>{t.disconnect()})}focus(){this.element.focus()}emit(t,...n){this.isDisposed||this.eventListeners[t]&&this.eventListeners[t].forEach(r=>{r(...n)})}on(t,n){this.isDisposed||(this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(n))}off(t,n){if(!this.eventListeners[t])return;let r=this.eventListeners[t].indexOf(n);r!==-1&&this.eventListeners[t].splice(r,1)}activate(){let t=this.isActive===!1;this.isActive=!0,t&&this.handleInteraction()}deactivate(){this.isActive=!1}dispose(){this.disposeHandlers.forEach(t=>t()),this.eventListeners={},this.isDisposed=!0}};function fA(e){return e.top!==0||e.left!==0||e.height!==0||e.width!==0}var yi=class extends bo{constructor(){super(...arguments);this.lastKnownSelection=null}getRootNode(){return this.element.getRootNode()}getText(){let n=new Range;return n.selectNodeContents(this.element),mu(this.element,n)}getHTML(){return this.element.innerHTML||""}getRange(){var i;let n=this.getRootNode();if(n.activeElement!==this.element)return null;let r="getSelection"in n?n.getSelection():window.getSelection();if(!r)return null;let o="getComposedRanges"in r&&n instanceof ShadowRoot?(i=r.getComposedRanges(n))==null?void 0:i[0]:r.rangeCount>0?r.getRangeAt(0):null;if(!o)return null;let s=this.element.ownerDocument.createRange();return s.setStart(o==null?void 0:o.startContainer,o==null?void 0:o.startOffset),s.setEnd(o==null?void 0:o.endContainer,o==null?void 0:o.endOffset),!s||!this.element.contains(s.startContainer)||!this.element.contains(s.endContainer)?null:s}getCaretPosition(){let n=this.getRange();if(!n||!n.collapsed||!("getBoundingClientRect"in n))return null;let r=n.getBoundingClientRect();return!fA(r)&&(n.insertNode(this.element.ownerDocument.createTextNode("\u2060")),r=n.getBoundingClientRect(),n.deleteContents(),!fA(r))?null:{top:r.top+r.height,left:r.left}}getSelection(){let n=this.getRange();if(n)return pu(this.element,n);let r=this.lastKnownSelection;if(r&&uA(this.element,r.start,r.end))return r;let o=Va(this.element);return o.collapse(!1),pu(this.element,o)}getSelectedText(){let{start:n,end:r}=this.getSelection();return mu(this.element,fs(this.element,n,r))}listen(){super.listen();let n=new MutationObserver(s=>{var i,a;s.length===2&&s[0].addedNodes.length===1&&((i=s[0].addedNodes[0])==null?void 0:i.textContent)==="\u2060"&&((a=s[1].removedNodes[0])==null?void 0:a.textContent)==="\u2060"||setTimeout(()=>{this.handleInteraction()},0)});n.observe(this.element,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),this.disposeHandlers.push(()=>n.disconnect());let r=this.element.isContentEditable,o=new MutationObserver(()=>{this.element.isContentEditable!==r&&(r=this.element.isContentEditable,this.emit(this.element.isContentEditable?"enabled":"disabled"))});o.observe(this.element,{attributes:!0,attributeFilter:["contenteditable"]}),this.disposeHandlers.push(()=>o.disconnect())}};var ZF=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize"];function pA(e,t){let n="mozInnerScreenX"in window,r=document.createElement("div");r.id="input-textarea-caret-position-mirror-div";let o=r.style,s=window.getComputedStyle(e),i=e.ownerDocument.body;o.whiteSpace="pre-wrap",o.wordWrap="break-word",o.position="absolute",o.visibility="hidden",ZF.forEach(u=>{o[u]=s[u]}),n?e.scrollHeight>Number.parseInt(s.height)&&(o.overflowY="scroll"):o.overflow="hidden",r.textContent=e.value.substring(0,t);let a=document.createElement("span");a.textContent=e.value.substring(t)||".",r.appendChild(a),i.appendChild(r);let l=e.getBoundingClientRect(),c={top:l.top-e.scrollTop+a.offsetTop+Number.parseInt(s.borderTopWidth)+a.offsetHeight,left:l.left-e.scrollLeft+a.offsetLeft+Number.parseInt(s.borderLeftWidth)};return i.removeChild(r),c}var vi=class extends bo{constructor(){super(...arguments);this.lastKnownSelection=null}getText(){return this.element.value}getHTML(){return null}getSelection(){let{selectionStart:n,selectionEnd:r}=this.element;return{start:n,end:r}}getSelectedText(){let n=this.getSelection();return n?this.getText().slice(n.start,n.end):""}getCaretPosition(){return pA(this.element,this.element.selectionEnd)}listen(){super.listen();let n=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value");Object.defineProperty(this.element,"value",{configurable:!0,get:()=>{var s;return(s=n==null?void 0:n.get)==null?void 0:s.call(this.element)},set:s=>{var i;(i=n==null?void 0:n.set)==null||i.call(this.element,s),this.handleInteraction()}}),this.addEventListener("scroll",()=>{this.emit("caretposition",this.getCaretPosition())});let r=this.element.disabled,o=new MutationObserver(()=>{this.element.disabled!==r&&(r=this.element.disabled,this.emit(r?"disabled":"enabled"))});o.observe(this.element,{attributes:!0,attributeFilter:["disabled"]}),this.disposeHandlers.push(()=>o.disconnect())}};function mA(e,t,n){let r=`deepdesk-iframe-${e}`,o=document.getElementById(r);if(o)return o;let s=document.createElement("iframe"),i=new URL(t);return Object.entries(n).forEach(([a,l])=>{i.searchParams.append(a,l)}),s.style.position="absolute",s.style.left="-999em",s.style.width="0px",s.style.height="0px",s.tabIndex=-1,s.id=r,s.title=`iframe-${e}`,s.src=i.toString(),window.document.body.appendChild(s),s}function JF(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch(t){return e}}var z0=class{constructor(t){this.name=t;this.disposeHandlers=[];this.broadcastChannel=new BroadcastChannel(t)}onMessage(t){this.broadcastChannel.addEventListener("message",t),this.disposeHandlers.push(()=>{this.broadcastChannel.removeEventListener("message",t)})}postMessage(t){this.broadcastChannel.postMessage(JSON.stringify(t))}close(){this.disposeHandlers.forEach(t=>t()),this.broadcastChannel.close()}},H0=class{constructor(t,n,r){this.name=t;this.targetOrigin=n;this.options=r;this.disposeHandlers=[];this.iframe=mA(t,`${this.targetOrigin}/sdk/proxy/proxy.html`,{channel:this.name,host:window.location.origin,debug:"1"}),document.body.appendChild(this.iframe)}onMessage(t){window.addEventListener("message",t),this.disposeHandlers.push(()=>{window.removeEventListener("message",t)})}postMessage(t){var n;(n=this.iframe.contentWindow)==null||n.postMessage(JSON.stringify(t),this.targetOrigin)}close(){var t;this.disposeHandlers.forEach(n=>n()),(t=this.iframe)==null||t.remove()}},B0=class{constructor(t){this.params=t;this.deepdeskUrl=t.deepdeskUrl,this.eventMap=t.eventMap,this.externalId="deepdesk-general",this.defaultChannel=this.createChannel("deepdesk-general")}get isCrossOrigin(){return this.params.deepdeskUrl!==(this.params.origin||window.location.origin)}setExternalId(t){this.externalId!==t&&(this.cleanup(),Z.info("Set externalId",t),this.externalId=t,this.channel=this.createChannel(t))}createChannel(t){let n=this.params.createCustomChannel?this.params.createCustomChannel(t):this.isCrossOrigin?new H0(t,this.deepdeskUrl,{debug:!0}):new z0(t),r=o=>{var i,a;if(o.origin!==this.deepdeskUrl)return;let s=JF(o.data);typeof s!="object"||s.type!=="event"||s.channel!==t||(Z.info("Received broadcast event",this.externalId,o),(a=(i=this.eventMap)[s.name])==null||a.call(i,s.payload))};return n.onMessage(r),n}send(t,n,r){var i,a;Z.info("Broadcast event",{externalId:this.externalId,name:t,payload:n});let o={type:"event",name:t,payload:n};r!==!1&&((a=(i=this.eventMap)[t])==null||a.call(i,n));let s=this.externalId==="deepdesk-general"?this.defaultChannel:this.channel;s==null||s.postMessage(P(S({},o),{channel:this.externalId}))}cleanup(t=!1){var n,r;(n=this.channel)==null||n.close(),this.channel=void 0,t&&((r=this.defaultChannel)==null||r.close(),this.defaultChannel=void 0)}},gA=B0;function e5(e){return e.replace(/(_\w)/g,t=>t[1].toUpperCase())}function Fe(e){return Array.isArray(e)?e.map(Fe):typeof e=="object"&&e!==null?Object.keys(e).reduce((t,n)=>P(S({},t),{[e5(n)]:Fe(e[n])}),{}):e}function t5(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function _t(e){return Array.isArray(e)?e.map(_t):typeof e=="object"&&e!==null?Object.keys(e).reduce((t,n)=>P(S({},t),{[t5(n)]:_t(e[n])}),{}):e}var $a=class extends Error{constructor(n,r){super(n);this.body=r;this.name="CustomError"}};var U0=e=>new Promise(t=>{setTimeout(t,e)});var Wa=class extends $a{constructor(){super(...arguments);this.name="ClientError"}},$0=class extends $a{constructor(){super(...arguments);this.name="ServerError"}},V0=new Map;function n5(e){return I(this,null,function*(){if(e.status===204)return e.text().catch(()=>{}),null;let t=e.headers.get("content-type");if(t!=null&&t.includes("application/json"))return e.json();let n=yield e.text();return n===""?null:(Z.warn("Unexpected response body:",n.slice(0,20)),JSON.parse(n))})}var ps=class ps{constructor(t="",n={}){this.baseUrl=t;this.options=n;this.latestRequestByUrl={};this.fetch=window.fetch.bind(window);n.fetch&&(this.fetch=n.fetch)}patchFetch(t){this.fetch=t(this.fetch)}setCsrfToken(t){this.csrfToken=t}request(t,n={}){return new Promise((r,o)=>{let s={isAborted:!1,reject:o},i=`${this.baseUrl}${t}`,a=this.fetch,l=n.method===void 0||n.method.toLowerCase()==="get",k=n,{useCache:c=!1,abortLatest:u=!1,attempts:d=1,retryDelay:f=500,refreshTokenOn401:p=!0,retryOnError:y=C=>C instanceof TypeError,retryOnResponse:g=C=>C.status>=500,version:x=null}=k,v=oe(k,["useCache","abortLatest","attempts","retryDelay","refreshTokenOn401","retryOnError","retryOnResponse","version"]);if(c){if(!l)throw new Error(`Can't use 'useCache' for ${n.method}`);if(V0.has(i)){r(V0.get(i));return}}let h=P(S({credentials:"include"},v),{headers:S({Accept:"application/json","Content-Type":"application/json"},v.headers)});!l&&this.csrfToken&&(h.headers=P(S({},h.headers),{"X-CSRFToken":this.csrfToken})),typeof x=="string"&&(h.headers=P(S({},h.headers),{"X-Deepdesk-API-Version":x}));let m=d,w=!1;if(!a)throw new Error("fetch is not set");this.latestRequestByUrl[i]&&u&&(this.latestRequestByUrl[i].isAborted=!0,this.latestRequestByUrl[i].reject(new Error("Aborted"))),this.latestRequestByUrl[i]=s;let E=()=>I(this,null,function*(){return m--,a(i,h).then(C=>I(this,null,function*(){return g(C)&&!s.isAborted&&m>0?(yield U0(f),E()):C.status===401&&p===!0&&w===!1?(w=!0,yield this.refreshToken(),E()):C})).catch(C=>I(this,null,function*(){if(y(C)&&!s.isAborted&&m>0)return yield U0(f),E();throw C}))});E().then(C=>I(this,null,function*(){let A=yield n5(C);if(delete this.latestRequestByUrl[i],C.status>=500){o(new $0("Server Error",A));return}if(C.status===401){o(new Wa("Unauthorized",A));return}if(C.status===403){o(new Wa("Forbidden",A));return}if(C.status===404){o(new Wa("Not Found",A));return}if(C.status>=400){o(new Wa("Bad Request",A));return}c&&V0.set(i,A),r(A)})).catch(C=>{o(C)})})}validateToken(){return I(this,null,function*(){let{has_valid_access_token:t}=yield this.get("/auth/validate");if(!t)try{yield this.refreshToken()}catch(r){return!1}let{is_logged_in:n}=yield this.get("/apis/admin/session/validate/");return!!n})}refreshToken(){return ps.refreshingToken||(ps.refreshingToken=this.get("/apis/admin/session/refresh/",{refreshTokenOn401:!1}).finally(()=>{setTimeout(()=>{ps.refreshingToken=null},1e3*60)})),ps.refreshingToken}get(t,n){return this.request(t,n)}post(t,n,r){return this.request(t,S({method:"POST",body:JSON.stringify(n)},r))}patch(t,n,r){return this.request(t,S({method:"PATCH",body:JSON.stringify(n)},r))}put(t,n,r){return this.request(t,S({method:"PUT",body:JSON.stringify(n)},r))}delete(t,n){return this.request(t,S({method:"DELETE"},n))}};ps.refreshingToken=null;var xi=ps;function W0(e){return P(S({},Fe(e)),{metadata:e.metadata})}var wi=class wi{constructor(t,n={}){this.options=n;this.latestReceivedDeepdeskVersions={};this.shouldFetchCsrfToken=!0;this.client=new xi(t,{fetch:n.fetch}),this.client.patchFetch(r=>(o,s)=>I(this,null,function*(){let i=yield r(o,s);return this.handleDeepdeskVersionHeaders(i),i}))}preflight(){return I(this,null,function*(){if(this.shouldFetchCsrfToken){this.shouldFetchCsrfToken=!1;let t=yield this.getCsrfToken();this.client.setCsrfToken(t)}return this.options.token?(wi.exchangeTokenPromise||(wi.exchangeTokenPromise=this.exchangeTokenForAccessCookie(this.options.token)),wi.exchangeTokenPromise):Promise.resolve()})}createConversation(t){return I(this,null,function*(){var r;yield this.preflight(),Z.info(`Creating conversation for session ${t.externalId} and agent ${t.agentId}`);let n=yield this.client.post("/api/v2/conversations",P(S({chat_start_time:new Date().toISOString()},_t(t)),{metadata:(r=t.metadata)!=null?r:{}}));return W0(n)})}getMe(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/session/me/");return Fe(t)})}postIdentity(t){return I(this,null,function*(){yield this.preflight(),yield this.client.post("/apis/admin/session/me/identities/",_t(t))})}patchMe(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.patch("/apis/admin/session/me/",_t(t));return Fe(n)})}getProfile(t){return I(this,null,function*(){let n=yield this.client.get(`/apis/admin/profiles/${t}/`,{useCache:!0});return Fe(n)})}getKnowledgeAssistant(t){return I(this,null,function*(){let n=yield this.client.get(`/apis/admin/knowledge-assist/assistants/${t}/`,{useCache:!0});return Fe(n)})}getContentTypes(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/content-types/",{useCache:!0});return Fe(t)})}getAccount(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/account/",{useCache:!0});return Fe(t)})}getPlatformConfig(t){return I(this,null,function*(){let n=t!==void 0?`/platform/config/${t}/`:"/platform/config/",{config:r}=yield this.client.get(n,{useCache:!0});return Fe(r)})}checkUserExists(t){return I(this,null,function*(){let{exists:n}=yield this.client.get(`/apis/admin/users/exists?external_id=${t}`,{version:"v1"});return n})}getConversationByExternalId(r){return I(this,arguments,function*(t,n={}){yield this.preflight(),Z.info(`Getting conversation for session ${t}`);let{attempts:o=1,retryDelay:s=1e3}=n,i=yield this.client.get(`/api/v2/conversations/by_external_id/${t}`,{attempts:o,retryDelay:s,retryOnResponse:a=>a.status===404||a.status>=500,version:"v2"});return Z.info(`Successfully retrieved conversation ${i.id} for session ${t}`),W0(i)})}isConversationSupported(r){return I(this,arguments,function*(t,n={}){Z.info(`Check if conversation for session ${t} is supported`);let{attempts:o=1,retryDelay:s=1e3}=n;return(yield this.client.get(`/api/v2/conversations/by_external_id/${t}/has_active_profile`,{attempts:o,retryDelay:s,retryOnResponse:a=>a.status===404||a.status>=500})).has_active_profile})}updateConversation(t,n){return I(this,null,function*(){var s;yield this.preflight();let r=_t(n);n.metadata&&(r.metadata=(s=n.metadata)!=null?s:{});let o=yield this.client.put(`/api/v2/conversations/${t}`,r);return W0(o)})}postMessages(t,n){return I(this,null,function*(){yield this.preflight(),yield this.client.post(`/api/v2/conversations/${t}/messages`,n.map(r=>P(S({},_t(r)),{metadata:r.metadata})))})}sendEvent(t,n){return I(this,null,function*(){yield this.preflight();let i=n,{data:r}=i,o=oe(i,["data"]),s=Object.entries(this.latestReceivedDeepdeskVersions).reduce((a,[l,c])=>P(S({},a),{[l]:c}),{});return this.client.post("/api/v2/events",_t(P(S(S({},s),o),{data:r,name:t})),{version:"v2"})})}getEntities(t){return I(this,null,function*(){return yield this.preflight(),(yield this.client.post("/api/entities",{messages:t.filter(r=>r.text)},{version:"v1"})).entities})}getTemporaryExchangeToken(){return I(this,null,function*(){return(yield this.client.get("/auth/exchange-token")).jwt})}exchangeTokenForAccessCookie(t){return I(this,null,function*(){return this.client.post("/apis/admin/session/jwt/",{jwt:t}).catch(n=>{throw Z.warn(`Invalid token '${t}'`),n})})}authenticateWithKey(t,n){return I(this,null,function*(){yield this.preflight(),yield this.client.post("/apis/admin/session/api-key/",_t(n),{refreshTokenOn401:!1,headers:{apikey:t}})})}getTextSuggestions(o){return I(this,arguments,function*(t,n={},r){if(yield this.preflight(),r==="sticky-messages")throw new Error("Use getPinnedMessages instead");return(yield this.client.post(`/api/v2/conversations/${t}/recommend/${r}`,_t(n),{abortLatest:!0})).map(i=>P(S({},Fe(i)),{text:i.text||i.url||i.message,source:r,type:r})).filter((i,a,l)=>a===l.findIndex(c=>c.text===i.text))})}isLoggedIn(){return I(this,null,function*(){return yield this.preflight(),this.client.validateToken()})}getAutocompleteSuggestions(t,n){return I(this,null,function*(){return yield this.preflight(),(yield this.client.post(`/api/v2/conversations/${t}/autocomplete`,_t(n),{abortLatest:!0})).map(o=>({score:1,source:o.source,sourceText:o.source_text,text:o.label,trainingJobs:o.training_jobs,searchKeywords:o.search_keywords,type:o.source})).filter((o,s,i)=>s===i.findIndex(a=>a.text===o.text))})}getPinnedMessages(t){return I(this,null,function*(){let n=yield this.client.get(`/api/v2/profiles/${t}/pinned-messages`,{abortLatest:!0});return Fe(n).map(r=>P(S({},r),{text:r.message,source:"sticky-messages",type:"pinned-message"}))})}getStyleSuggestions(t){return I(this,null,function*(){let n=yield this.client.post("/api/style-suggestions",_t(t),{abortLatest:!0,version:"v1"});return Fe(n)})}search(t){return I(this,null,function*(){let n=yield this.client.post(`/api/v2/profiles/${t.profile}/search`,_t(t));return Fe(n)})}knowledgeAssist(s,i,a){return I(this,arguments,function*(t,n,r,o={}){yield this.preflight();let l=yield this.client.post(`/api/knowledge-assist/assistants/${r}/search`,_t({question:t.question,doNotKnowAnswer:t.doNotKnowAnswer,customerInstruction:t.customerInstruction,chatHistory:n.map(c=>({question:c.question,answer:c.answer.answer})),agentId:o.agentId,conversationId:o.conversationId}),{version:"v2"});return Fe(l)})}requestLoginByEmail(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.post("/apis/admin/session/passwordless/request/",{email:t});return Fe(n)})}requestPasswordlessToken(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/session/passwordless/request/");return Fe(t.token)})}getCsrfToken(){return I(this,null,function*(){let{token:t}=yield this.client.get("/apis/admin/session/csrf/");return t})}verifyLoginToken(t){return I(this,null,function*(){let n=yield this.client.post("/apis/admin/session/passwordless/login/",{token:t});return Fe(n)})}getSummary(r){return I(this,arguments,function*(t,n={}){yield this.preflight();let o=yield this.client.post("/api/summary",{conversation:{messages:t.filter(s=>s.text&&s.source),agent_id:n.agentId,id:n.externalConversationId},prompt_instruction:n.promptInstruction,model:n.model},{version:"v1"});return Fe(o)})}evaluateAssistant(t,n){return I(this,null,function*(){var a;yield this.preflight();let r=new URLSearchParams,{expectFormat:o="text"}=n||{};if(o.startsWith("json-schema:")){let l=o.replace("json-schema:","");r.append("expect_response_format","json-schema"),r.append("expect_response_format_schema",l)}else r.append("expect_response_format",o);n!=null&&n.externalConversationId&&r.append("external_conversation_id",n.externalConversationId);let s=n!=null&&n.threadId?`/api/v2/assistants/${t}/threads/${n==null?void 0:n.threadId}/evaluate?${r.toString()}`:`/api/v2/assistants/${t}/evaluate?${r.toString()}`,i=yield this.client.post(s,{input:(a=n==null?void 0:n.input)!=null?a:{},conversation:n==null?void 0:n.transcript});return Fe(i.output)})}createAssistantThread(t){return I(this,null,function*(){yield this.preflight();let{assistantCode:n}=t,r=yield this.client.post(`/apis/admin/assistants/${n}/threads/`,{});return Fe(r)})}postMessageToAssistantThread(t){return I(this,null,function*(){yield this.preflight();let{assistantCode:n,threadId:r,message:o}=t,s=yield this.client.post(`/apis/admin/assistants/${n}/threads/${r}/messages/`,{content:o,role:"user"});return Fe(s)})}translateMessages(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.post("/api/translate",_t(t),{version:"v2"});return Fe(n)})}handleDeepdeskVersionHeaders(t){t.headers.forEach((n,r)=>{let o=r.toLowerCase(),s=o.match(ew);if(!n||!s)return;let i=s[1].replace("-","_"),a=this.latestReceivedDeepdeskVersions[i];a&&n&&a!==n&&Z.warn(`Overwritten Version header ${o}: ${JSON.stringify(a)} -> ${JSON.stringify(n)}`),this.latestReceivedDeepdeskVersions[i]=n})}};wi.exchangeTokenPromise=null;var Eo=wi;var hA={startTime:null,stopTime:null},yA=e=>e.handlingTime,vA=ke({name:"handlingTime",initialState:hA,reducers:{handlingTimeStart(e){if(e.startTime&&!e.stopTime)throw new Error("Timing already started");e.startTime=new Date,e.stopTime=null},handlingTimeStop(e){if(!e.startTime)throw new Error("Timing not started");e.stopTime=new Date},handlingTimeReset(e){e.startTime=null,e.stopTime=null}},extraReducers:e=>{e.addCase(lt,()=>hA)}}),{handlingTimeStart:xA,handlingTimeStop:ym,handlingTimeReset:wA}=vA.actions,SA=vA.reducer;var bA=(e={})=>{let t=S({onAuthError:aa(!1)},e);return n=>r=>o=>("error"in o&&o.error.message==="Unauthorized"&&n.dispatch(t.onAuthError),r(o))};var vm={list:{keywordMatches:[]},fetchState:"idle"};var Si=he("styleSuggestions/getAll",(n,r)=>I(void 0,[n,r],function*({text:e},t){var l;let{deepdeskAPI:o}=t.extra,s=t.getState(),{showStyleSuggestions:i}=s.settings,a=(l=s.conversation.current)==null?void 0:l.profileCode;if(!i)return vm.list;if(!a)throw new Error("No current conversation to fetch pinned messages");return o.getStyleSuggestions({profileCode:a,message:e})})),r5=ke({name:"styleSuggestions",initialState:vm,reducers:{},extraReducers:e=>{e.addCase(Si.pending,t=>{t.fetchState="loading"}).addCase(Si.rejected,t=>{t.fetchState="error"}).addCase(Si.fulfilled,(t,n)=>{t.fetchState="done",Xo(t.list,n.payload)||(t.list=n.payload)}).addCase(Bs,t=>{t.list=vm.list}).addCase(lt,()=>vm)}}),EA=r5.reducer;var TA=(e={})=>{let t,n=!0,r=S({getStyleSuggestions:Si,debounce:500},e);return o=>s=>i=>{var p;let a=o.getState().input.text,l=s(i),c=o.getState();if(c.auth.isLoggedIn!==!0)return l;let{showStyleSuggestions:u}=c.settings;if(!((p=c.conversation.current)==null?void 0:p.id)||!u)return l;let{text:f}=c.input;return f===a&&!n||(clearTimeout(t),f==="")||(t=setTimeout(()=>{n=!1,o.dispatch(r.getStyleSuggestions({text:f}))},e.debounce)),l}};function o5(e,t){return e.text===t.text&&e.selection.start===t.selection.start&&e.selection.end===t.selection.end}var CA=(e={})=>{let t=S({getTextSuggestions:gr,getAutocompleteSuggestions:Jc,debounce:200,check:Or},e),n;return r=>o=>s=>{var g;let{input:i}=r.getState(),a=o(s),l=r.getState();if(l.auth.isLoggedIn!==!0)return a;let{recommendTextSuggestions:c,showTabCompletion:u}=l.settings,d=(g=l.conversation.current)==null?void 0:g.id,f=s.type===Up.toString();if(!d||!c&&!u)return a;let{input:p}=l;return o5(p,i)&&!f||(clearTimeout(n),!t.check(l))||(n=setTimeout(()=>{let x=ca(l);x===""?r.dispatch(t.getTextSuggestions("default")):r.dispatch(t.getAutocompleteSuggestions(x))},f?0:t.debounce)),a}};var kA=Si.fulfilled.toString();function s5(e,t){let n=new Set([...t.keywordMatches.map(o=>o.keyword)]),r=[];return n.forEach(o=>{let s=e.keywordMatches.filter(l=>l.keyword===o),i=t.keywordMatches.filter(l=>l.keyword===o),a=i.length-s.length;a<=0||r.push(...i.slice(0,a))}),r}var RA=e=>t=>n=>r=>{var c;if(r.type!==kA){n(r);return}let o=t.getState().styleSuggestions.list;n(r);let s=t.getState(),i=s.styleSuggestions.list,a=(c=s.conversation)==null?void 0:c.current;if(o===i)return;let l=s5(o,i);r.type===kA&&l.length>0&&e.sendEvent("style suggested",{conversationId:a==null?void 0:a.id,data:{keywordMatches:l}})};var i5=sf({assistants:tC,auth:P1,conversation:H1,contentTypes:rC,passwordlessToken:OP,entities:Qk,handlingTime:SA,info:sT,input:Q1,settings:S1,profile:lC,search:dT,styleSuggestions:EA,ui:QR,textSuggestions:DR});function PA(e){return qE({reducer:i5,middleware:t=>{var r;let n=t({thunk:{extraArgument:{dynamicThunkObject:e.dynamicThunkObject,deepdeskAPI:e.deepdeskAPI}},serializableCheck:!1}).concat(bA()).concat(CA({debounce:200})).concat(TA({debounce:500})).concat(RA(e.deepdeskAPI));return((r=e.middleware)!=null?r:[]).reduce((o,s)=>o.concat(s),n)},preloadedState:e.preloadedState})}var a5=e=>{var t,n;return(n=(t=e==null?void 0:e.type)==null?void 0:t.toLowerCase())!=null?n:"unknown"},l5=e=>t=>n=>r=>{var a,l,c,u,d,f;let o=t.getState(),s=Yl("inlineSuggestions")(o);switch(r.type){case aa.toString():{!r.payload&&e.emit("logout",void 0);break}case fr.fulfilled.toString():r.payload.length>0&&e.sendEvent("entities found",{conversationId:(a=o.conversation.current)==null?void 0:a.id,data:{entities:r.payload}});break;case ro.toString():e.sendEvent(r.payload.name,{conversationId:((l=r.payload.options)==null?void 0:l.includeConversationData)&&((c=o.conversation.current)==null?void 0:c.id),data:r.payload.data});break;case Bs.toString():e.logSendMessage(r.payload);break;case Kf.toString():e.emit("call-to-action",{cue:r.payload});break;case or.fulfilled.toString():r.isBroadcasted||e.broadcast(_y,r,!1);break;default:break}let i=n(r);switch(r.type){case Bs.toString():e.handleAfterSendMessage(r.payload);break;case tu.toString():e.onUpdateShowTabHint(r.payload);break;case ym.toString():e.logHandlingTime();break;case Rf.toString():e.broadcast(nc,r);break;case Hs.toString():e.broadcast(nc,r);break;case Gf.toString():t.dispatch(Hs({source:"assistant",assistantCode:r.payload.code}));break;case"analytics/logEvent/fulfilled":{e.emit("event",r.meta.arg);break}case Ef.toString():{let{start:p,end:y}=o.input.selection;e.emit("replace",P(S({},r.payload),{replace:r.payload.replace==="selection"?{start:p,end:y}:{start:0,end:y}}));break}case er.toString():{let{start:p,end:y}=o.input.selection;e.emit("select-suggestion",P(S({type:a5(r.payload.suggestion)},r.payload),{replace:r.payload.replace==="selection"?{start:p,end:y}:{start:0,end:y}})),s&&t.dispatch(Qo([]));break}case Tf.toString():e.emit("select-image",r.payload),e.sendEvent("Image attached",{conversationId:(u=o.conversation.current)==null?void 0:u.id,data:{path:r.payload.suggestion.image,title:r.payload.suggestion.title}});break;case Qo.toString():{s&&r.payload.length>0&&t.dispatch(Cf(0));break}case so.fulfilled.toString():{if(r.isBroadcasted)break;e.broadcast(nc,r,!1),e.sendEvent("conversation summarized",{conversationId:(d=o.conversation.current)==null?void 0:d.id,data:{summary:r.payload,assistant:(f=t.getState().profile.data)==null?void 0:f.summarizerAssistantNew}}),e.emit("summary-generated",{summary:r.payload});break}default:break}return i},AA=l5;function j0(e){return e.toISOString().replace("T"," ").replace("Z","")}var c5=(e,t)=>t.version,IA=$t([da,Rr,yA,c5],(e,t,n,r)=>{if(!t)return Z.warn("No conversationId for handling time metrics"),null;let{startTime:o,stopTime:s}=n;return!o||!s?(Z.warn("No startTime and stopTime for handling time metrics"),null):{conversationId:t,clientVersion:r,agentId:e==null?void 0:e.agentId,agentName:e==null?void 0:e.agentName,agentEmail:e==null?void 0:e.agentEmail,timeStart:j0(o),timeStop:j0(s)}});function LA(e,t){let{text:n,metrics:{numPaste:r,pastes:o,textSuggestions:s}}=e.input,i=n.length;return{source:"agent",clientVersion:t.version,pastes:o,lenTextTotal:i,numPastes:r,suggestions:s}}function K0(e,t){var s;let n=e.closest(t);if(n)return n;let r=e.getRootNode().host;if(r instanceof HTMLElement)return K0(r,t);let o=(s=e.ownerDocument.defaultView)==null?void 0:s.frameElement;return o?K0(o,t):null}function G0(e,t){return K0(e,t)}function MA(e){return typeof e=="object"&&e!==null&&"name"in e&&"message"in e}function u5(e){return typeof e=="object"&&e!==null&&"tagName"in e}function xm(e){return u5(e)&&(gi(e)||Yp(e))}var OA,zr=new Map,d5=["bottom","height","left","right","top","width"],NA=(e,t)=>!e&&!t?!1:e&&!t||!e&&t?!0:d5.some(n=>e[n]!==t[n]);function _A(e){var n,r,o;if(e.ownerDocument===document)return[];let t=(o=(r=(n=e.ownerDocument)==null?void 0:n.defaultView)==null?void 0:r.frameElement)!=null?o:null;return t?[t,..._A(t)]:[]}function DA(e,t){return!e||!t?null:P(S({},e),{top:e.top+t.top,left:e.left+t.left})}var wm=!1,FA=()=>{wm=!0;let e=[];if(zr.forEach((t,n)=>{if(!n.isConnected){t.rect=null,e.push(t),zr.delete(n);return}let r=n.getBoundingClientRect();NA(r,t.rect)&&(t.rect=r,e.push(t))}),e.forEach(t=>{let n=t.parentRects?t.parentRects.reduce(DA,t.rect):t.rect;NA(n,t.totalRect)&&t.callbacks.forEach(r=>r(n)),t.totalRect=n}),zr.size===0){wm=!1;return}OA=window.requestAnimationFrame(FA)};function q0(e,t){let n=_A(e),r=[],o=n.map((s,i)=>q0(s,a=>{r[i]=a;let l=zr.get(e);if(!l)return;let c=r.reduce(DA,l.rect);l.callbacks.forEach(u=>u(c))}));return{observe(s=!0){if(o.forEach(i=>i.observe(!1)),zr.has(e)){let i=zr.get(e);i.callbacks.push(t),i.rect&&t(i.rect)}else zr.set(e,{rect:void 0,callbacks:[t],parentRects:r});s&&!wm&&FA()},unobserve(){o.forEach(i=>i.unobserve());let s=zr.get(e);if(s){let i=s.callbacks.indexOf(t);i>=0&&s.callbacks.splice(i,1),s.callbacks.length||zr.delete(e),zr.size||(cancelAnimationFrame(OA),wm=!1)}}}}var zA,Hr=new Map,HA=()=>{Hr.forEach((e,t)=>{if(!t.isConnected){Hr.delete(t);return}let{clientHeight:n,scrollHeight:r}=t,o=r>n;e.visible!==o&&(e.visible=o,e.callbacks.forEach(s=>s(e.visible)))}),Hr.size!==0&&(zA=window.requestAnimationFrame(HA))};function BA(e,t){return{observe(){let n=Hr.size===0;Hr.has(e)?Hr.get(e).callbacks.push(t):Hr.set(e,{visible:void 0,callbacks:[t]}),n&&HA()},unobserve(){let n=Hr.get(e);if(n){let r=n.callbacks.indexOf(t);r>=0&&n.callbacks.splice(r,1),n.callbacks.length||Hr.delete(e),Hr.size||cancelAnimationFrame(zA)}}}}var Y0=["borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth","borderStyle","boxSizing","color","overflowWrap","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontWeight","fontKerning","lineHeight","letterSpacing","paddingLeft","paddingTop","paddingRight","paddingBottom","width","height","textIndent","whiteSpace","wordBreak","wordSpacing","wordWrap"];function X0(e,t,n){return n.forEach(r=>{t.style[r]=e[r]})}function ja(e){return Number.parseFloat(e)}function Sm(e){return Math.round(e*1e6)}function UA(e){return e/1e6}function Q0(e,t,n){if(e.boxSizing==="content-box")return;let{clientWidth:r}=t,o=ja(e.width),s=ja(e.borderLeftWidth),i=ja(e.borderRightWidth),a=ja(e.paddingRight),l=UA(Sm(o)-Sm(s)-Sm(i)),c=UA(Sm(r));if(l-c>2){let u=l-c;n.style.paddingRight=`${a+u}px`}}function gu(e,t={}){var u,d;let n=t.overlayContainer||document.createElement("div");n.style.display="none",n.style.position=(u=t.position)!=null?u:"fixed",n.style.pointerEvents="none",n.style.borderColor="transparent",ui(n);let r=window.getComputedStyle(e),o=!0,s=()=>{n.scrollTop=e.scrollTop};X0(r,n,Y0),Q0(r,e,n),t.mirrorOverflow&&(n.style.overflow="hidden",e.addEventListener("scroll",s));let i=BA(e,()=>{X0(r,n,Y0),Q0(r,e,n),s(),setTimeout(s,0)}),a,l=!0,c=q0(e,f=>{if(f===null){t.onRemove&&t.onRemove(),n.remove();return}if(!l&&t.onMoveStart&&(Promise.resolve().then(()=>t.onMoveStart()),l=!0),clearTimeout(a),a=setTimeout(()=>{t.onMoveEnd&&t.onMoveEnd(),l=!1},200),f.height===0&&f.width===0){if(o===!0)return;t.onHide&&t.onHide(),n.style.display="none",o=!0;return}if(X0(r,n,Y0),Q0(r,e,n),s(),n.style.top=`${f.top}px`,n.style.left=`${f.left}px`,t.closestScrollElement&&t.closestScrollElement!==e){let p=t.closestScrollElement.getBoundingClientRect(),y=window.getComputedStyle(t.closestScrollElement),g=ja(y.borderTopWidth),x=ja(y.borderBottomWidth),v=p.top+g-f.top,h=f.top+f.height+-(p.top+p.height-x);n.style.clipPath=`inset(${v}px 0px ${h}px 0px)`}o&&(n.style.display="block",t.onShow&&t.onShow(),o=!1)});return t.appendTo?t.appendTo.appendChild(n):(d=e.parentElement)==null||d.appendChild(n),c.observe(),i.observe(),[n,()=>{e.removeEventListener("scroll",s),c.unobserve(),i.unobserve(),n.remove()}]}var VA=(e,t)=>({value(){try{let n=sessionStorage.getItem(`dd-${e}`);if(!n)return t;try{return JSON.parse(n)}catch(r){return t}}catch(n){return t}},update(n){try{sessionStorage.setItem(`dd-${e}`,JSON.stringify(n))}catch(r){Z.warn("[Deepdesk] SessionStorage is blocked by browser")}}});function f5(e){return e.offsetParent!==null}function $A(e){if(!f5(e))return!1;let t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function bm(e,t,n=100){let r=$A(e);t({isVisible:r});let o=setInterval(()=>{let s=$A(e);s!==r&&(r=s,t({isVisible:r}))},n);return()=>{clearTimeout(o)}}var hu=class extends Error{};function p5(){let e,t;return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}}var Em=class{constructor(){this.queues={}}push(t,n){let r=()=>{let s=this.queues[t][1];s?(this.queues[t]=[s.promise,null],s.resolve()):delete this.queues[t]};if(!this.queues[t]){let s=n().finally(r);return this.queues[t]=[s,null],s}this.queues[t][1]&&this.queues[t][1].reject(new hu("Queued async function is outdated"));let o=p5();return this.queues[t][1]=o,o.promise.then(()=>n().finally(r))}};var m5={accepted:"onConversationAcceptedAssistants","new-message":"onConversationNewMessageAssistants",ended:"onConversationEndedAssistants"},WA=(e,t)=>{let n=e[m5[t]];return n&&n.length>0?n.map(r=>r.code):(Z.warn(`No assistant set in profile for conversation event "${t}"`),[])};var Tm=class{constructor(t){this.options=t;this.socket=null;this.maxReconnectAttempts=5;this.reconnectInterval=25e3;var n,r;this.socket,this.eventListeners=new Map,this.url=t.url,this.maxReconnectAttempts=(n=t.maxReconnectAttempts)!=null?n:this.maxReconnectAttempts,this.reconnectInterval=(r=t.reconnectInterval)!=null?r:this.reconnectInterval,this.shouldReconnect=t.shouldReconnect,this.reconnect(),window.addEventListener("beforeunload",()=>this.cleanup())}setupListeners(){this.socket&&(this.socket.onmessage=t=>{var n;try{let r=Fe(JSON.parse(t.data));r.event&&this.eventListeners.has(r.event)&&((n=this.eventListeners.get(r.event))==null||n.forEach(o=>o(r.data)))}catch(r){console.error("Error parsing WebSocket message:",r)}},this.socket.onclose=t=>{console.log("WebSocket connection closed:",t),setTimeout(()=>{this.reconnect()},this.reconnectInterval)},this.socket.onerror=t=>{console.error("WebSocket error:",t)})}reconnect(){var t,n;if(this.maxReconnectAttempts<=0){console.error("Max reconnect attempts reached, closing WebSocket connection."),(t=this.socket)==null||t.close();return}if(!this.shouldReconnect()){console.error("Should not reconnect, closing WebSocket connection."),(n=this.socket)==null||n.close();return}this.socket&&(this.socket.onmessage=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.close()),this.socket=new WebSocket(this.url),this.setupListeners(),this.maxReconnectAttempts--}send(t,n){if(!this.socket){console.error("WebSocket connection is not open.");return}this.socket.send(JSON.stringify({event:t,data:n}))}on(t,n){this.eventListeners.has(t)||this.eventListeners.set(t,[]);let r=this.eventListeners.get(t);r&&!r.includes(n)&&r.push(n)}close(){var t;(t=this.socket)==null||t.close()}cleanup(){this.close(),window.removeEventListener("beforeunload",()=>this.cleanup())}};var Le=b(R());var jA=VA("showTabHint",!0),Ka=class Ka{constructor({deepdeskUrl:t,version:n=Ka.version||"unknown",locale:r="en-US",token:o,fetch:s,productName:i,createCustomChannel:a,websocketClient:l=Tm}){this.inputMediator=null;this.eventListeners={};this.unmountHandlers=[];this.inlineSuggestions=null;this.aboveSuggestions=null;this.floatingMenu=null;this.widgetElement=null;this.widgetRoot=null;this.dynamicThunkObject={};this.queues=new Em;this.isMounted=!1;this.shouldRender=!0;this.loadProfileConfigPromise=null;let c=t.replace(/\/api$/,"");this.deepdeskApi=new Eo(c,{token:o,fetch:s}),this.version=n,this.instanceId=Ka.count++;let u={deepdeskAPI:this.deepdeskApi,dynamicThunkObject:this.dynamicThunkObject,middleware:[AA({broadcast:(d,f,p)=>{this.broadcastEvents.send(d,f,p)},emit:(d,f)=>this.emit(d,f),handleAfterSendMessage:d=>this.handleAfterSendMessage(d),logHandlingTime:()=>this.logHandlingTime(),logSendMessage:d=>this.logSendMessage(d),onUpdateShowTabHint:d=>jA.update(d),sendEvent:(d,f)=>this.deepdeskApi.sendEvent(d,f)})]};this.store=PA(u),this.broadcastEvents=new gA({debug:!0,deepdeskUrl:c,eventMap:fT(this.store),createCustomChannel:a}),this.ws=new l({url:`${t}/api/v2/me/realtime`.replace("https","wss"),reconnectInterval:25e3,shouldReconnect:()=>I(this,null,function*(){var d;return(d=this.isLoggedIn())!=null?d:!1})}),this.store.dispatch(tu(jA.value())),this.store.dispatch(vf({locale:r,adminUrl:c,productName:i})),this.ws.on("assistants::user_notification",d=>{d.conversationId&&d.conversationId!==this.conversationId().toString()||this.store.dispatch(eC(d))}),this.ws.on("assistants::response_chunk",d=>{d.conversationId&&d.conversationId!==this.conversationId().toString()||this.store.dispatch(JT(d))})}get state(){return this.store.getState()}get settings(){return this.state.settings}get selectedTextSuggestion(){var t;return(t=zs(this.state)[this.state.input.selectedSuggestionIndex])!=null?t:null}hasConversation(){return!!this.state.conversation.current}conversationId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.id}externalId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.externalId}shouldAbort(){return this.state.conversation.isSupported===!1?(Z.warn("Conversation is not supported"),!0):this.hasConversation()?this.state.profile.data?!1:(Z.warn("Profile has not been loaded (yet)"),!0):(Z.warn("No conversation loaded (yet)"),!0)}login(){this.store.dispatch(aa(null)),this.store.dispatch(to());let t=n=>Wt(n)&&b1(n)!=="loading";return new Promise(n=>{let r=this.subscribe(t,o=>{o&&(r(),n())});this.unmountHandlers.push(()=>{r()})})}isLoggedIn(){return I(this,null,function*(){return(yield this.store.dispatch(to())).payload})}isConversationSupported(t,n){return I(this,null,function*(){return(yield this.store.dispatch(Py({externalId:t,options:n}))).payload})}createConversation(t){return I(this,null,function*(){var r;return this.hasConversation()&&this.externalId()!==t.externalId&&this.resetConversation(),(yield this.store.dispatch(wf(P(S({},t),{metadata:(r=t.metadata)!=null?r:{}})))).payload})}getConversationByExternalId(t,n){return I(this,null,function*(){return this.hasConversation()&&this.externalId()!==t&&this.resetConversation(),(yield this.store.dispatch(Sf({externalId:t,options:n}))).payload})}upsertConversation(t){return I(this,null,function*(){var r;return this.hasConversation()&&this.externalId()!==t.externalId&&this.resetConversation(),(yield this.store.dispatch(Ay(P(S({},t),{metadata:(r=t.metadata)!=null?r:{}})))).payload})}postMessages(t){return I(this,null,function*(){yield this.store.dispatch(Iy(t))})}updateConversation(t){return I(this,null,function*(){return(yield this.store.dispatch(bf(t))).payload})}resetConversation(){this.store.dispatch(lt()),this.loadProfileConfigPromise=null,this.dynamicThunkObject.conversationQuery=null}configure(t){this.store.dispatch(vf(t))}setVisitorInfo(t){this.store.dispatch(nT(t))}setCustomData(t){this.store.dispatch(rT(t))}setAgentInfo(t,n){return I(this,null,function*(){yield this.store.dispatch(Jl(S(S({},t),n)))})}setAgentSettings(t){return I(this,null,function*(){yield this.store.dispatch(My(t))})}getAgentSettings(){return I(this,null,function*(){return(yield this.store.dispatch(Ny())).payload})}refresh(){return I(this,null,function*(){if(this.shouldAbort())return Promise.resolve();let t=[];return t.push(this.refreshTextSuggestions()),t.push(this.refreshWidgetSuggestions()),Promise.all(t).then(()=>{})})}syncInputMediator(){this.inputMediator&&this.store.dispatch(kf({text:this.inputMediator.getText(),html:this.inputMediator.getHTML()}))}notifyExternalSuggestion(t){this.store.dispatch(er(t))}evaluateAssistant(t,n){return I(this,null,function*(){let u=n||{},{input:r={},transcript:o,showCuesInWidget:s=!0,includeMetadata:i,expectFormat:a}=u,l=oe(u,["input","transcript","showCuesInWidget","includeMetadata","expectFormat"]);Object.assign(r,l);let c=yield this.store.dispatch(or({assistantCode:t,expectFormat:a||"json-schema:cues",transcript:o,includeMetadata:i,input:r,skipState:!s}));if(c.error)throw new Error(c.error.message);return c.payload})}evaluateConversationAssistant(t,n){return I(this,null,function*(){yield this.loadProfileConfig();let r=this.state.profile.data;if(!r){Z.warn("Can't evaluate assistant when profile is not loaded yet.");return}let o=WA(r,t);yield Promise.all(o.map(s=>this.queues.push(s,()=>I(this,null,function*(){if(s===r.summarizerAssistantNew)return this.getSummary(S({includeMetadata:!0},n));yield this.evaluateAssistant(s,S({includeMetadata:!0},n))})).catch(i=>{if(i instanceof hu){Z.warn(`Queued assistant "${s}" was outdated and dropped`);return}throw i})))})}getSummary(){return I(this,arguments,function*(t={}){var r;if(!this.hasConversation())return Z.warn("No conversation to create summary for."),null;(r=this.state.profile.data)!=null&&r.summarizerAssistantNew||Z.warn("No profile loaded yet, or no summarizer assistant set in profile");let n=yield this.store.dispatch(so(t));if(n.error)throw new Error(n.error.message);return n.payload})}handleKeyDown(t){let{overlayCollapsed:n,openOverlayWhenTyping:r}=this.state.ui,{textSuggestions:o,selectedSuggestionIndex:s,selection:i}=this.state.input,{inlineSuggestions:a,showTextSuggestions:l}=this.settings,c=a?"below":"above",u=o.length>0;if(this.store.dispatch(W1(Ly(t))),!Or(this.state)||t.key!=="Tab"&&!l)return;let d=()=>{n||!u||i&&(t.shiftKey||(this.store.dispatch(G1()),t.preventDefault()))},f=()=>{n||!u||a&&s<=0||i&&(t.shiftKey||(this.store.dispatch(q1()),t.preventDefault()))};switch(t.key){case"ArrowUp":c==="below"?f():d();break;case"ArrowDown":{c==="below"?d():f();break}case"Escape":{n||(this.store.dispatch(Cf(-1)),this.store.dispatch(is({collapse:!0})),this.store.dispatch(YR(!0)),t.preventDefault());break}case"Tab":{t.preventDefault();let p=ua(this.state);if(!p)return;this.store.dispatch(tu(!1)),this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"tab"},replace:"until-selection-end"}));break}case" ":{if(this.settings.inlineSuggestions||this.state.input.selectedSuggestionIndex===-1)return;let p=ua(this.state);if(!p)return;this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"space"},replace:"until-selection-end"}));break}case"Enter":{if(this.settings.inlineSuggestions||t.shiftKey||this.state.input.selectedSuggestionIndex===-1)return;let p=ua(this.state);if(!p)return;this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"enter"},replace:"until-selection-end"})),t.preventDefault();break}default:}n&&r&&this.store.dispatch(is({collapse:!1}))}handleAfterSendMessage(t){this.emit("send-message",t),this.store.dispatch(Qo([]))}handlingTimeStart(){this.state.handlingTime.startTime||(Z.info("Start handling time"),this.store.dispatch(xA()))}handlingTimeStop(){this.state.handlingTime.startTime&&(Z.info("Stop handling time"),this.store.dispatch(ym()))}logSendMessage(t){let n=LA(this.state,{version:this.version});n&&(t&&(Object.assign(n,{text:t}),Object.assign(n,{lenTextTotal:t.length})),this.deepdeskApi.sendEvent("Send Message",{conversationId:this.conversationId(),data:n}),this.emit("send-message-event",n))}logHandlingTime(){let t=IA(this.state,{version:this.version});t&&(this.deepdeskApi.sendEvent("Handling Time",{conversationId:this.conversationId(),data:t}),this.store.dispatch(wA()))}notifySubmit(t={}){var n;this.shouldAbort()||(this.store.dispatch(Bs((n=t.text)!=null?n:this.state.input.text)),this.store.dispatch(X1()))}emit(t,n){let r=this.eventListeners[t];r&&r.forEach(o=>{try{o(n)}catch(s){Z.warn(`The following error occurred in deepdeskSDK.on('${t}', handler)`),Z.error(s)}})}on(t,n){return this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(n),()=>{this.off(t,n)}}off(t,n){if(!t&&!n){this.eventListeners={};return}let r;this.eventListeners[t]&&(r=this.eventListeners[t].indexOf(n),r>-1&&this.eventListeners[t].splice(r,1))}setConversationQuery(t){this.dynamicThunkObject.conversationQuery=t}setPlatformVariables(t){this.store.dispatch(oT(t))}whenConversationLoaded(t){let n=o=>{var s;return(s=o.conversation.current)==null?void 0:s.id},r=()=>this.loadProfileConfig().then(()=>t());n(this.state)&&r(),this.subscribe(n,o=>{o&&r()})}overlayContainerFactory(t,n,r,o){let[s,i]=gu(n,r);return s.setAttribute("translate","no"),s.dataset.testid=t,o&&s.classList.add(o),[s,i]}createInlineContainer(t,n){var a;let r=document.createElement("div");r.style.position="absolute",r.style.top="0px",r.style.left="0px",r.style.height="0px",r.style.width="0px";let o=document.createElement("div");o.style.display="none",o.style.position="absolute",o.style.height="0px",o.style.width="0px",o.style.backgroundColor="red",r.appendChild(o);let s=(a=t.ownerDocument.defaultView)==null?void 0:a.frameElement,i=s?s.ownerDocument.defaultView:null;if(s&&(i===window||(i==null?void 0:i.parent)===window)){let[l,c]=gu(s,{appendTo:document.body,onMoveStart:()=>{o.style.display="none"}});l.dataset.testid=n,l.style.zIndex="2",l.appendChild(r),this.unmountHandlers.push(()=>{c()})}else document.body.appendChild(r);return o}createContainer(t,n=document.body){let r=window.getComputedStyle(n),o=document.createElement("div");return ui(o),o.dataset.testid=t,o.style.color=r.color,o.style.fontSize=r.fontSize,o.style.fontFamily=r.fontFamily,o.style.fontVariant=r.fontVariant,o.setAttribute("translate","no"),n.appendChild(o),o}storeMetrics(){try{let t=`dd-metrics-${this.conversationId()}`,n=JSON.stringify({text:this.state.input.text,metrics:this.state.input.metrics});window.sessionStorage.setItem(t,n),Z.info(`Stored analytics for ${this.conversationId()}`)}catch(t){}}restoreMetrics(){try{let t=`dd-metrics-${this.conversationId()}`,n=window.sessionStorage.getItem(t);if(!n)return;let r=JSON.parse(n);r.text.trim()===this.state.input.text.trim()?(Z.info(`Restored metrics for ${this.conversationId()}`),this.store.dispatch(Y1(r.metrics))):Z.warn(`Metrics mismatch, disregarding stored metrics for ${this.conversationId()}`),window.sessionStorage.removeItem(t)}catch(t){}}mount(t,n={}){if(this.isMounted)throw new Error("[Deepdesk] This instance was already mounted. Make sure to unmount before you remount.");if(!xm(t))throw new Error("[Deepdesk] Only mount on textarea or contentEditable div.");if(!this.shouldRender)return;let f=n,{customStyles:r,closestScrollSelector:o,floatingMenuParent:s,appendOverlayTo:i,inputMediator:a}=f,l=oe(f,["customStyles","closestScrollSelector","floatingMenuParent","appendOverlayTo","inputMediator"]),c={customStyles:r,closestScrollSelector:o,floatingMenuParent:s,appendOverlayTo:i};this.configure(l),this.settings.automaticHandlingTime&&this.setupHandlingTime(t),ui(t),this.inputMediator=a||(gi(t)?new vi(t):new yi(t)),this.inputMediator.on("change",({plainText:p,rawHTML:y})=>{this.store.dispatch(kf({text:p,html:y}))}),this.inputMediator.on("keyup",p=>{this.store.dispatch(j1(Ly(p)))}),this.inputMediator.on("keydown",p=>{this.handleKeyDown(p)}),this.inputMediator.on("paste",({pastedText:p,selectionText:y})=>{this.store.dispatch(K1({text:p,selectionText:y}))}),this.inputMediator.on("cut",({selectionText:p})=>{this.store.dispatch($1(p))});let u;this.inputMediator.on("selection",p=>{clearTimeout(u),p===null?u=setTimeout(()=>{p!==null&&this.store.dispatch(Pf(p))},500):this.store.dispatch(Pf(p))}),this.inputMediator.on("disabled",()=>{var p;(p=this.inputMediator)==null||p.deactivate(),this.configure({visible:!1})}),this.inputMediator.on("enabled",()=>{this.inputMediator&&(this.configure({visible:!0}),this.inputMediator.activate())}),this.inputMediator.on("submit",()=>{this.settings.detectSubmit&&this.notifySubmit()}),this.inputMediator.on("blur",()=>{this.store.dispatch(Wp(!1))}),this.inputMediator.on("focus",()=>{this.store.dispatch(Wp(!0))}),this.renderSuggestions(t,c),this.subscribe(Yl("inlineSuggestions"),()=>{this.renderSuggestions(t,c)});let d=this.renderOverlays(n);this.unmountHandlers.push(()=>{d.unmount()}),this.store.dispatch(kf({text:this.inputMediator.getText(),html:this.inputMediator.getHTML()})),this.store.dispatch(Pf(this.inputMediator.getSelection())),this.store.dispatch(Wp(this.inputMediator.isFocused)),this.unmountHandlers.push(()=>{this.state.input.text!==""&&this.storeMetrics()}),this.whenConversationLoaded(()=>{var p;this.restoreMetrics(),this.syncInputMediator(),this.refreshTextSuggestions(),this.broadcastEvents.setExternalId((p=this.state.conversation.current)==null?void 0:p.externalId)}),this.isMounted=!0}subscribe(t,n){let r=t(this.store.getState());return this.store.subscribe(()=>{let o=t(this.store.getState());o!==r&&(r=o,n(r))})}unmount(){var t,n,r,o;(t=this.inlineSuggestions)==null||t.unmount(),(n=this.aboveSuggestions)==null||n.unmount(),(r=this.floatingMenu)==null||r.unmount(),this.unmountHandlers.forEach(s=>s()),this.unmountHandlers=[],(o=this.inputMediator)==null||o.dispose(),this.broadcastEvents.cleanup(),this.isMounted=!1}renderSuggestions(t,n){var r,o,s;(r=this.floatingMenu)==null||r.unmount(),(o=this.inlineSuggestions)==null||o.unmount(),(s=this.aboveSuggestions)==null||s.unmount(),this.settings.floatingMenu&&(this.floatingMenu=this.renderFloatingMenu(t,n)),this.settings.inlineSuggestions?this.inlineSuggestions=this.renderInlineSuggestions(t,n):this.aboveSuggestions=this.renderAboveSuggestions(t,n)}renderInlineSuggestions(t,n){let{customStyles:r}=n,o=this.createInlineContainer(t,"deepdesk-caret"),s=(0,ms.createRoot)(o);s.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(iP,{})})}));let i=a=>{a?(o.style.display="block",o.style.top=`${a.top}px`,o.style.left=`${a.left}px`):o.style.display="none"};return this.inputMediator.on("caretposition",i),{unmount:()=>{var a;(a=this.inputMediator)==null||a.off("caretposition",i),s.unmount(),o.remove()}}}renderAboveSuggestions(t,n){let{customStyles:r,closestScrollSelector:o,appendOverlayTo:s}=n,i=o&&G0(t,o)||void 0,[a,l]=this.overlayContainerFactory("deepdesk-tab-completion",i||t,{appendTo:s,closestScrollElement:i,mirrorOverflow:!0,onRemove:()=>this.unmount()},r==null?void 0:r.rootNode),[c,u]=this.overlayContainerFactory("deepdesk-suggestions-overlay",i||t,{appendTo:s},r==null?void 0:r.suggestionsRootNode),d=(0,ms.createRoot)(a);d.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(LP,{inputElement:t})})}));let f=(0,ms.createRoot)(c);return f.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(gP,{onLogIn:()=>this.loginViaPopup().catch(p=>Z.warn(p.message))})})})),{unmount(){d.unmount(),f.unmount(),l(),u()}}}renderFloatingMenu(t,n){let{customStyles:r,closestScrollSelector:o,appendOverlayTo:s,floatingMenuParent:i}=n,a=o&&G0(t,o)||void 0,[l,c]=this.overlayContainerFactory("floating-menu",a||t,{appendTo:i!=null?i:s},r==null?void 0:r.floatingMenuParent),u=(0,ms.createRoot)(l);return u.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(GR,{onLogIn:()=>this.loginViaPopup().catch(d=>Z.warn(d.message))})})})),{unmount(){u.unmount(),c()}}}renderOverlays(t){let{customStyles:n}=t,r=this.createContainer("deepdesk-overlays"),o=(0,ms.createRoot)(r);return o.render((0,Le.jsx)(ls,{store:this.store,customStyles:n,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(VR,{})})})),{unmount(){o.unmount(),r.remove()}}}renderWidget(t,n={}){if(this.widgetElement&&Z.warn("A widget was already rendered for this instance. Make sure to unmountWidget before rerendering"),!this.shouldRender)return;let{customStyles:r,showImages:o,isEmbedded:s}=n;this.widgetElement=t,this.configure({showImages:o,isEmbedded:s}),this.widgetRoot=(0,ms.createRoot)(t),this.widgetRoot.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(cA,{assistantOptions:n.assistantOptions,knowledgeAssistOptions:n.knowledgeAssist,onLogIn:()=>this.loginViaPopup().catch(i=>Z.warn(i.message))})})})),this.whenConversationLoaded(()=>{var i;this.broadcastEvents.setExternalId((i=this.state.conversation.current)==null?void 0:i.externalId)})}unmountWidget(){var t,n;(t=this.widgetRoot)==null||t.unmount(),this.widgetRoot=null,(n=this.widgetElement)==null||n.remove(),this.widgetElement=null}renderKnowledgeAssistantWidget(t,n,r={}){let{customStyles:o,initialQuestion:s}=r,i=(0,ms.createRoot)(n);return i.render((0,Le.jsx)(ls,{store:this.store,customStyles:o,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(F0,{children:(0,Le.jsxs)(fm,{assistantCode:t,initialQuestion:s,evaluateKnowledgeAssistFn:r.isLegacyKnowledgeAssist?Ks:Gs,children:[(0,Le.jsx)(Ri,{children:(0,Le.jsx)(mm,{title:r.title,emptyState:r.emptyState})}),(0,Le.jsx)(D0,{children:(0,Le.jsx)(pm,{})})]})})})})),{unmount(){i.unmount()}}}setupHandlingTime(t){let n=bm(t,({isVisible:r})=>{r?this.handlingTimeStart():this.handlingTimeStop()});this.unmountHandlers.push(()=>{this.handlingTimeStop(),n()}),this.whenConversationLoaded(()=>{this.handlingTimeStart()})}handleError(t){MA(t)&&t.message==="Unauthorized"&&this.login()}loadProfileConfig(){return this.loadProfileConfigPromise?this.loadProfileConfigPromise:(this.loadProfileConfigPromise=Promise.resolve().then(()=>I(this,null,function*(){yield this.store.dispatch(Tc());let t=qs(this.state);t&&this.store.dispatch(vf({showSearch:t.search,showImageSearch:t.imageSearch,showEntitiesCommand:t.entitiesCommand,showSummaryCommand:!!t.summarizerAssistantNew,showKnowledgeSearch:!!t.knowledgeAssistantNew||!!t.knowledgeAssistant,recommendTextSuggestions:t.recommendTextSuggestions}))})),this.loadProfileConfigPromise)}loginViaPopup(t){return I(this,null,function*(){return new Promise((n,r)=>{let o=new MessageChannel,s=o.port1,i=this.settings.adminUrl,a=new URL(t!=null&&t.url?t==null?void 0:t.url:`${i}/platform/sso/`);a.searchParams.append("redirect","/sdk/popup/close.html");let l=!1,c=()=>{u&&!u.closed&&u.close(),window.removeEventListener("message",d),clearInterval(f)};s.onmessage=p=>I(this,null,function*(){var y,g;if((y=p.data)!=null&&y.jwt)try{yield this.deepdeskApi.exchangeTokenForAccessCookie((g=p.data)==null?void 0:g.jwt),yield this.isLoggedIn(),this.broadcastEvents.send(tc),l=!0,o.port1.close(),n()}catch(x){console.error(x),r(x)}finally{l=!0,c()}});let u=window.open(a.toString(),"deepdesk-login","scrollbars=no,left=100,top=150,width=500,height=500");u===null&&r(new Error("Popup blocked by browser"));let d=p=>I(this,null,function*(){var y;if(p.origin===a.origin)switch((y=p.data)==null?void 0:y.type){case"deepdesk-popup-loaded":{try{let g=JSON.stringify({type:"deepdesk-popup-create-channel"});u==null||u.postMessage(g,a.origin,[o.port2])}catch(g){Z.error("Error posting message to popup",g),r(g)}break}case"deepdesk-popup-error":{c(),p.data.message==="Timeout"&&Z.warn("Popup timed out. Check if the account's platform url is configured correctly."),r(new Error(p.data.message));break}}});window.addEventListener("message",d);let f=setInterval(()=>{u&&!u.closed||(c(),l||r(new Error("Popup closed by user")))},200);this.unmountHandlers.push(c)})})}translateMessages(t){return this.deepdeskApi.translateMessages(t)}checkForTrialMode(t){return I(this,null,function*(){try{let{account:n}=yield this.deepdeskApi.getPlatformConfig();if(!n.isTrial){this.shouldRender=!0;return}if(Z.info("Trial is active"),!(yield this.deepdeskApi.checkUserExists(t)))throw new Error("User is not in trial");this.shouldRender=!0}catch(n){let{message:r}=n;Z.info(r),this.shouldRender=!1}})}refreshTextSuggestions(){return I(this,null,function*(){this.isMounted&&(yield this.store.dispatch(Up()))})}refreshWidgetSuggestions(){return I(this,null,function*(){if(!this.widgetRoot)return;let{uiConfig:t}=this.state.profile.data;if(!t.widget)return;let n=Cc(this.state);try{n.forEach(({type:r})=>{switch(r){case"entities":this.store.dispatch(fr());break;case"pinned-messages":case"sticky-messages":break;default:Fu.includes(r)||this.store.dispatch(gr(r))}})}catch(r){this.handleError(r)}})}};Ka.version="17.2.1-beta.0",Ka.count=0;var yu=Ka;function g5(e){return I(this,null,function*(){var o,s,i;let n=yield((o=e.fetch)!=null?o:window.fetch)(e.url),r=yield n.blob();return new File([r],e.name,{type:(i=(s=e.mimeType)!=null?s:n.headers.get("Content-Type"))!=null?i:"image/jpeg"})})}function KA(e,t){return I(this,null,function*(){let n=yield g5(t),r=new Event("change",{bubbles:!0,cancelable:!0});try{Object.defineProperty(e,"files",{configurable:!0,get:()=>[n]}),e.dispatchEvent(r)}finally{Object.hasOwn(e,"files")&&delete e.files}})}function GA(e,t,n){return I(this,null,function*(){yield new Eo(e).authenticateWithKey(t,n)})}function qA(e){return e.replace(/\[([\w\s\d]+)\]\((https?:\/\/[^\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>')}function YA(r,o){return I(this,arguments,function*(e,t,n={}){var d,f;let{value:s}=e,{start:i,end:a}=(d=n.replace)!=null?d:{start:0,end:s.length},l=`${s.slice(0,i)}${t}${s.slice(a)}`,c=(f=n.selectionAfter)!=null?f:{start:i+t.length,end:i+t.length},u=()=>{if(n.setValue)return n.setValue(l);e.value=l};return Promise.resolve(u()).then(()=>{e.selectionStart=c.start,e.selectionEnd=c.end,e.blur(),e.focus()})})}function XA(r,o){return I(this,arguments,function*(e,t,n={}){let s=n.replace?fs(e,n.replace.start,n.replace.end):Va(e),i,a=()=>{if(n.setRange)return n.setRange(s.cloneRange());s.deleteContents(),i=document.createElement("span"),s.insertNode(i),n.insertBRs!==!1?t.split(`
|
|
82
|
+
`);let y=f?r:0,g=p?Math.min(s,u.childNodes.length):u.childNodes.length;for(let x=y;x<g&&(c(u.childNodes[x]),a!==2);x++);break}default:break}p&&(a=2)}return c(e),l}var dA=(i=>(i.CUT="Cut",i.BACKSPACE="Backspace",i.DELETE="Delete",i.ERASEEOF="EraseEof",i.UNDO="Undo",i.CLEAR="Clear",i))(dA||{}),bo=class{constructor(t){this.element=t;this.isFocused=!1;this.isActive=!0;this.isDisposed=!1;this.eventListeners={};this.disposeHandlers=[];this.cachedText="";this.cachedCaretPosition=null;this.cachedSelection={start:0,end:0};this.cachedHTML="";this.isSubmitting=!1;this.isPossibleClearInputAction=!1;this.cachedText=this.getText(),this.cachedHTML=this.getHTML(),this.cachedSelection=this.getSelection(),this.listen()}addEventListener(t,n){let r=o=>{n(o)};this.element.addEventListener(t,r),this.disposeHandlers.push(()=>{this.element.removeEventListener(t,r)})}removeEventListener(t,n){this.element.removeEventListener(t,n)}handleInteraction(){let t=this.getText(),n=this.getHTML(),r=this.getSelection(),o=this.cachedCaretPosition===null;if(!this.isActive||(t===""&&this.cachedText!==""&&!this.isPossibleClearInputAction&&this.emit("submit"),t!==this.cachedText?(this.cachedText=t,this.cachedHTML=n,o=!0,this.emit("change",{plainText:t,rawHTML:n})):n!==null&&n!==this.cachedHTML&&(this.cachedHTML=n,o=!0,this.emit("change",{plainText:t,rawHTML:n})),(r.start!==this.cachedSelection.start||r.end!==this.cachedSelection.end)&&(this.cachedSelection=r,o=!0,this.emit("selection",r)),!o))return;let s=this.getCaretPosition();Xo(s,this.cachedCaretPosition)||(this.cachedCaretPosition=s,this.emit("caretposition",s))}handleClick(){this.handleInteraction()}handleFocus(){let t=!this.isFocused;this.isFocused=!0,t&&this.emit("focus"),this.handleInteraction()}handleBlur(){this.isPossibleClearInputAction=!1;let t=this.isFocused;this.isFocused=!1,t&&this.emit("blur")}handleKeyDown(t){let{key:n,ctrlKey:r,metaKey:o}=t;this.isPossibleClearInputAction=Object.values(dA).includes(n)||n.toLowerCase()==="z"&&(r||o),this.emit("keydown",t)}handleKeyUp(t){this.handleInteraction(),this.emit("keyup",t)}handleCut(){this.isPossibleClearInputAction=!0,this.emit("cut",{selectionText:this.getSelectedText()})}handlePaste(t){var r,o;let n=((r=t.clipboardData)==null?void 0:r.getData("text"))||((o=t.clipboardData)==null?void 0:o.getData("text/plain"))||"";this.emit("paste",{pastedText:n,selectionText:this.getSelectedText()})}listen(){this.addEventListener("keydown",n=>this.handleKeyDown(n)),this.addEventListener("keyup",n=>this.handleKeyUp(n)),this.addEventListener("input",()=>this.handleInteraction()),this.addEventListener("change",()=>this.handleInteraction()),this.addEventListener("focus",()=>this.handleFocus()),this.addEventListener("blur",()=>this.handleBlur()),this.addEventListener("cut",()=>this.handleCut()),this.addEventListener("paste",n=>this.handlePaste(n)),this.addEventListener("click",()=>this.handleInteraction()),document.activeElement===this.element&&(this.isFocused=!0);let t=new MutationObserver(()=>{this.element.isConnected||(this.emit("unmounted"),this.dispose())});t.observe(document.body,{subtree:!0,childList:!0}),this.disposeHandlers.push(()=>{t.disconnect()})}focus(){this.element.focus()}emit(t,...n){this.isDisposed||this.eventListeners[t]&&this.eventListeners[t].forEach(r=>{r(...n)})}on(t,n){this.isDisposed||(this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(n))}off(t,n){if(!this.eventListeners[t])return;let r=this.eventListeners[t].indexOf(n);r!==-1&&this.eventListeners[t].splice(r,1)}activate(){let t=this.isActive===!1;this.isActive=!0,t&&this.handleInteraction()}deactivate(){this.isActive=!1}dispose(){this.disposeHandlers.forEach(t=>t()),this.eventListeners={},this.isDisposed=!0}};function fA(e){return e.top!==0||e.left!==0||e.height!==0||e.width!==0}var yi=class extends bo{constructor(){super(...arguments);this.lastKnownSelection=null}getRootNode(){return this.element.getRootNode()}getText(){let n=new Range;return n.selectNodeContents(this.element),mu(this.element,n)}getHTML(){return this.element.innerHTML||""}getRange(){var i;let n=this.getRootNode();if(n.activeElement!==this.element)return null;let r="getSelection"in n?n.getSelection():window.getSelection();if(!r)return null;let o="getComposedRanges"in r&&n instanceof ShadowRoot?(i=r.getComposedRanges(n))==null?void 0:i[0]:r.rangeCount>0?r.getRangeAt(0):null;if(!o)return null;let s=this.element.ownerDocument.createRange();return s.setStart(o==null?void 0:o.startContainer,o==null?void 0:o.startOffset),s.setEnd(o==null?void 0:o.endContainer,o==null?void 0:o.endOffset),!s||!this.element.contains(s.startContainer)||!this.element.contains(s.endContainer)?null:s}getCaretPosition(){let n=this.getRange();if(!n||!n.collapsed||!("getBoundingClientRect"in n))return null;let r=n.getBoundingClientRect();return!fA(r)&&(n.insertNode(this.element.ownerDocument.createTextNode("\u2060")),r=n.getBoundingClientRect(),n.deleteContents(),!fA(r))?null:{top:r.top+r.height,left:r.left}}getSelection(){let n=this.getRange();if(n)return pu(this.element,n);let r=this.lastKnownSelection;if(r&&uA(this.element,r.start,r.end))return r;let o=Va(this.element);return o.collapse(!1),pu(this.element,o)}getSelectedText(){let{start:n,end:r}=this.getSelection();return mu(this.element,fs(this.element,n,r))}listen(){super.listen();let n=new MutationObserver(s=>{var i,a;s.length===2&&s[0].addedNodes.length===1&&((i=s[0].addedNodes[0])==null?void 0:i.textContent)==="\u2060"&&((a=s[1].removedNodes[0])==null?void 0:a.textContent)==="\u2060"||setTimeout(()=>{this.handleInteraction()},0)});n.observe(this.element,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),this.disposeHandlers.push(()=>n.disconnect());let r=this.element.isContentEditable,o=new MutationObserver(()=>{this.element.isContentEditable!==r&&(r=this.element.isContentEditable,this.emit(this.element.isContentEditable?"enabled":"disabled"))});o.observe(this.element,{attributes:!0,attributeFilter:["contenteditable"]}),this.disposeHandlers.push(()=>o.disconnect())}};var ZF=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize"];function pA(e,t){let n="mozInnerScreenX"in window,r=document.createElement("div");r.id="input-textarea-caret-position-mirror-div";let o=r.style,s=window.getComputedStyle(e),i=e.ownerDocument.body;o.whiteSpace="pre-wrap",o.wordWrap="break-word",o.position="absolute",o.visibility="hidden",ZF.forEach(u=>{o[u]=s[u]}),n?e.scrollHeight>Number.parseInt(s.height)&&(o.overflowY="scroll"):o.overflow="hidden",r.textContent=e.value.substring(0,t);let a=document.createElement("span");a.textContent=e.value.substring(t)||".",r.appendChild(a),i.appendChild(r);let l=e.getBoundingClientRect(),c={top:l.top-e.scrollTop+a.offsetTop+Number.parseInt(s.borderTopWidth)+a.offsetHeight,left:l.left-e.scrollLeft+a.offsetLeft+Number.parseInt(s.borderLeftWidth)};return i.removeChild(r),c}var vi=class extends bo{constructor(){super(...arguments);this.lastKnownSelection=null}getText(){return this.element.value}getHTML(){return null}getSelection(){let{selectionStart:n,selectionEnd:r}=this.element;return{start:n,end:r}}getSelectedText(){let n=this.getSelection();return n?this.getText().slice(n.start,n.end):""}getCaretPosition(){return pA(this.element,this.element.selectionEnd)}listen(){super.listen();let n=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value");Object.defineProperty(this.element,"value",{configurable:!0,get:()=>{var s;return(s=n==null?void 0:n.get)==null?void 0:s.call(this.element)},set:s=>{var i;(i=n==null?void 0:n.set)==null||i.call(this.element,s),this.handleInteraction()}}),this.addEventListener("scroll",()=>{this.emit("caretposition",this.getCaretPosition())});let r=this.element.disabled,o=new MutationObserver(()=>{this.element.disabled!==r&&(r=this.element.disabled,this.emit(r?"disabled":"enabled"))});o.observe(this.element,{attributes:!0,attributeFilter:["disabled"]}),this.disposeHandlers.push(()=>o.disconnect())}};function mA(e,t,n){let r=`deepdesk-iframe-${e}`,o=document.getElementById(r);if(o)return o;let s=document.createElement("iframe"),i=new URL(t);return Object.entries(n).forEach(([a,l])=>{i.searchParams.append(a,l)}),s.style.position="absolute",s.style.left="-999em",s.style.width="0px",s.style.height="0px",s.tabIndex=-1,s.id=r,s.title=`iframe-${e}`,s.src=i.toString(),window.document.body.appendChild(s),s}function JF(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch(t){return e}}var z0=class{constructor(t){this.name=t;this.disposeHandlers=[];this.broadcastChannel=new BroadcastChannel(t)}onMessage(t){this.broadcastChannel.addEventListener("message",t),this.disposeHandlers.push(()=>{this.broadcastChannel.removeEventListener("message",t)})}postMessage(t){this.broadcastChannel.postMessage(JSON.stringify(t))}close(){this.disposeHandlers.forEach(t=>t()),this.broadcastChannel.close()}},H0=class{constructor(t,n,r){this.name=t;this.targetOrigin=n;this.options=r;this.disposeHandlers=[];this.iframe=mA(t,`${this.targetOrigin}/sdk/proxy/proxy.html`,{channel:this.name,host:window.location.origin,debug:"1"}),document.body.appendChild(this.iframe)}onMessage(t){window.addEventListener("message",t),this.disposeHandlers.push(()=>{window.removeEventListener("message",t)})}postMessage(t){var n;(n=this.iframe.contentWindow)==null||n.postMessage(JSON.stringify(t),this.targetOrigin)}close(){var t;this.disposeHandlers.forEach(n=>n()),(t=this.iframe)==null||t.remove()}},B0=class{constructor(t){this.params=t;this.deepdeskUrl=t.deepdeskUrl,this.eventMap=t.eventMap,this.externalId="deepdesk-general",this.defaultChannel=this.createChannel("deepdesk-general")}get isCrossOrigin(){return this.params.deepdeskUrl!==(this.params.origin||window.location.origin)}setExternalId(t){this.externalId!==t&&(this.cleanup(),Z.info("Set externalId",t),this.externalId=t,this.channel=this.createChannel(t))}createChannel(t){let n=this.params.createCustomChannel?this.params.createCustomChannel(t):this.isCrossOrigin?new H0(t,this.deepdeskUrl,{debug:!0}):new z0(t),r=o=>{var i,a;if(o.origin!==this.deepdeskUrl)return;let s=JF(o.data);typeof s!="object"||s.type!=="event"||s.channel!==t||(Z.info("Received broadcast event",this.externalId,o),(a=(i=this.eventMap)[s.name])==null||a.call(i,s.payload))};return n.onMessage(r),n}send(t,n,r){var i,a;Z.info("Broadcast event",{externalId:this.externalId,name:t,payload:n});let o={type:"event",name:t,payload:n};r!==!1&&((a=(i=this.eventMap)[t])==null||a.call(i,n));let s=this.externalId==="deepdesk-general"?this.defaultChannel:this.channel;s==null||s.postMessage(P(S({},o),{channel:this.externalId}))}cleanup(t=!1){var n,r;(n=this.channel)==null||n.close(),this.channel=void 0,t&&((r=this.defaultChannel)==null||r.close(),this.defaultChannel=void 0)}},gA=B0;function e5(e){return e.replace(/(_\w)/g,t=>t[1].toUpperCase())}function Fe(e){return Array.isArray(e)?e.map(Fe):typeof e=="object"&&e!==null?Object.keys(e).reduce((t,n)=>P(S({},t),{[e5(n)]:Fe(e[n])}),{}):e}function t5(e){return e.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function _t(e){return Array.isArray(e)?e.map(_t):typeof e=="object"&&e!==null?Object.keys(e).reduce((t,n)=>P(S({},t),{[t5(n)]:_t(e[n])}),{}):e}var $a=class extends Error{constructor(n,r){super(n);this.body=r;this.name="CustomError"}};var U0=e=>new Promise(t=>{setTimeout(t,e)});var Wa=class extends $a{constructor(){super(...arguments);this.name="ClientError"}},$0=class extends $a{constructor(){super(...arguments);this.name="ServerError"}},V0=new Map;function n5(e){return I(this,null,function*(){if(e.status===204)return e.text().catch(()=>{}),null;let t=e.headers.get("content-type");if(t!=null&&t.includes("application/json"))return e.json();let n=yield e.text();return n===""?null:(Z.warn("Unexpected response body:",n.slice(0,20)),JSON.parse(n))})}var ps=class ps{constructor(t="",n={}){this.baseUrl=t;this.options=n;this.latestRequestByUrl={};this.fetch=window.fetch.bind(window);n.fetch&&(this.fetch=n.fetch)}patchFetch(t){this.fetch=t(this.fetch)}setCsrfToken(t){this.csrfToken=t}request(t,n={}){return new Promise((r,o)=>{let s={isAborted:!1,reject:o},i=`${this.baseUrl}${t}`,a=this.fetch,l=n.method===void 0||n.method.toLowerCase()==="get",k=n,{useCache:c=!1,abortLatest:u=!1,attempts:d=1,retryDelay:f=500,refreshTokenOn401:p=!0,retryOnError:y=C=>C instanceof TypeError,retryOnResponse:g=C=>C.status>=500,version:x=null}=k,v=oe(k,["useCache","abortLatest","attempts","retryDelay","refreshTokenOn401","retryOnError","retryOnResponse","version"]);if(c){if(!l)throw new Error(`Can't use 'useCache' for ${n.method}`);if(V0.has(i)){r(V0.get(i));return}}let h=P(S({credentials:"include"},v),{headers:S({Accept:"application/json","Content-Type":"application/json"},v.headers)});!l&&this.csrfToken&&(h.headers=P(S({},h.headers),{"X-CSRFToken":this.csrfToken})),typeof x=="string"&&(h.headers=P(S({},h.headers),{"X-Deepdesk-API-Version":x}));let m=d,w=!1;if(!a)throw new Error("fetch is not set");this.latestRequestByUrl[i]&&u&&(this.latestRequestByUrl[i].isAborted=!0,this.latestRequestByUrl[i].reject(new Error("Aborted"))),this.latestRequestByUrl[i]=s;let E=()=>I(this,null,function*(){return m--,a(i,h).then(C=>I(this,null,function*(){return g(C)&&!s.isAborted&&m>0?(yield U0(f),E()):C.status===401&&p===!0&&w===!1?(w=!0,yield this.refreshToken(),E()):C})).catch(C=>I(this,null,function*(){if(y(C)&&!s.isAborted&&m>0)return yield U0(f),E();throw C}))});E().then(C=>I(this,null,function*(){let A=yield n5(C);if(delete this.latestRequestByUrl[i],C.status>=500){o(new $0("Server Error",A));return}if(C.status===401){o(new Wa("Unauthorized",A));return}if(C.status===403){o(new Wa("Forbidden",A));return}if(C.status===404){o(new Wa("Not Found",A));return}if(C.status>=400){o(new Wa("Bad Request",A));return}c&&V0.set(i,A),r(A)})).catch(C=>{o(C)})})}validateToken(){return I(this,null,function*(){let{has_valid_access_token:t}=yield this.get("/auth/validate");if(!t)try{yield this.refreshToken()}catch(r){return!1}let{is_logged_in:n}=yield this.get("/apis/admin/session/validate/");return!!n})}refreshToken(){return ps.refreshingToken||(ps.refreshingToken=this.get("/apis/admin/session/refresh/",{refreshTokenOn401:!1}).finally(()=>{setTimeout(()=>{ps.refreshingToken=null},1e3*60)})),ps.refreshingToken}get(t,n){return this.request(t,n)}post(t,n,r){return this.request(t,S({method:"POST",body:JSON.stringify(n)},r))}patch(t,n,r){return this.request(t,S({method:"PATCH",body:JSON.stringify(n)},r))}put(t,n,r){return this.request(t,S({method:"PUT",body:JSON.stringify(n)},r))}delete(t,n){return this.request(t,S({method:"DELETE"},n))}};ps.refreshingToken=null;var xi=ps;function W0(e){return P(S({},Fe(e)),{metadata:e.metadata})}var wi=class wi{constructor(t,n={}){this.options=n;this.latestReceivedDeepdeskVersions={};this.shouldFetchCsrfToken=!0;this.client=new xi(t,{fetch:n.fetch}),this.client.patchFetch(r=>(o,s)=>I(this,null,function*(){let i=yield r(o,s);return this.handleDeepdeskVersionHeaders(i),i}))}preflight(){return I(this,null,function*(){if(this.shouldFetchCsrfToken){this.shouldFetchCsrfToken=!1;let t=yield this.getCsrfToken();this.client.setCsrfToken(t)}return this.options.token?(wi.exchangeTokenPromise||(wi.exchangeTokenPromise=this.exchangeTokenForAccessCookie(this.options.token)),wi.exchangeTokenPromise):Promise.resolve()})}createConversation(t){return I(this,null,function*(){var r;yield this.preflight(),Z.info(`Creating conversation for session ${t.externalId} and agent ${t.agentId}`);let n=yield this.client.post("/api/v2/conversations",P(S({chat_start_time:new Date().toISOString()},_t(t)),{metadata:(r=t.metadata)!=null?r:{}}));return W0(n)})}getMe(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/session/me/");return Fe(t)})}postIdentity(t){return I(this,null,function*(){yield this.preflight(),yield this.client.post("/apis/admin/session/me/identities/",_t(t))})}patchMe(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.patch("/apis/admin/session/me/",_t(t));return Fe(n)})}getProfile(t){return I(this,null,function*(){let n=yield this.client.get(`/apis/admin/profiles/${t}/`,{useCache:!0});return Fe(n)})}getKnowledgeAssistant(t){return I(this,null,function*(){let n=yield this.client.get(`/apis/admin/knowledge-assist/assistants/${t}/`,{useCache:!0});return Fe(n)})}getContentTypes(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/content-types/",{useCache:!0});return Fe(t)})}getAccount(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/account/",{useCache:!0});return Fe(t)})}getPlatformConfig(t){return I(this,null,function*(){let n=t!==void 0?`/platform/config/${t}/`:"/platform/config/",{config:r}=yield this.client.get(n,{useCache:!0});return Fe(r)})}checkUserExists(t){return I(this,null,function*(){let{exists:n}=yield this.client.get(`/apis/admin/users/exists?external_id=${t}`,{version:"v1"});return n})}getConversationByExternalId(r){return I(this,arguments,function*(t,n={}){yield this.preflight(),Z.info(`Getting conversation for session ${t}`);let{attempts:o=1,retryDelay:s=1e3}=n,i=yield this.client.get(`/api/v2/conversations/by_external_id/${t}`,{attempts:o,retryDelay:s,retryOnResponse:a=>a.status===404||a.status>=500,version:"v2"});return Z.info(`Successfully retrieved conversation ${i.id} for session ${t}`),W0(i)})}isConversationSupported(r){return I(this,arguments,function*(t,n={}){Z.info(`Check if conversation for session ${t} is supported`);let{attempts:o=1,retryDelay:s=1e3}=n;return(yield this.client.get(`/api/v2/conversations/by_external_id/${t}/has_active_profile`,{attempts:o,retryDelay:s,retryOnResponse:a=>a.status===404||a.status>=500})).has_active_profile})}updateConversation(t,n){return I(this,null,function*(){var s;yield this.preflight();let r=_t(n);n.metadata&&(r.metadata=(s=n.metadata)!=null?s:{});let o=yield this.client.put(`/api/v2/conversations/${t}`,r);return W0(o)})}postMessages(t,n){return I(this,null,function*(){yield this.preflight(),yield this.client.post(`/api/v2/conversations/${t}/messages`,n.map(r=>P(S({},_t(r)),{metadata:r.metadata})))})}sendEvent(t,n){return I(this,null,function*(){yield this.preflight();let i=n,{data:r}=i,o=oe(i,["data"]),s=Object.entries(this.latestReceivedDeepdeskVersions).reduce((a,[l,c])=>P(S({},a),{[l]:c}),{});return this.client.post("/api/v2/events",_t(P(S(S({},s),o),{data:r,name:t})),{version:"v2"})})}getEntities(t){return I(this,null,function*(){return yield this.preflight(),yield this.client.post("/api/v2/entities",{messages:t.filter(r=>r.text)})})}getTemporaryExchangeToken(){return I(this,null,function*(){return(yield this.client.get("/auth/exchange-token")).jwt})}exchangeTokenForAccessCookie(t){return I(this,null,function*(){return this.client.post("/apis/admin/session/jwt/",{jwt:t}).catch(n=>{throw Z.warn(`Invalid token '${t}'`),n})})}authenticateWithKey(t,n){return I(this,null,function*(){yield this.preflight(),yield this.client.post("/apis/admin/session/api-key/",_t(n),{refreshTokenOn401:!1,headers:{apikey:t}})})}getTextSuggestions(o){return I(this,arguments,function*(t,n={},r){if(yield this.preflight(),r==="sticky-messages")throw new Error("Use getPinnedMessages instead");return(yield this.client.post(`/api/v2/conversations/${t}/recommend/${r}`,_t(n),{abortLatest:!0})).map(i=>P(S({},Fe(i)),{text:i.text||i.url||i.message,source:r,type:r})).filter((i,a,l)=>a===l.findIndex(c=>c.text===i.text))})}isLoggedIn(){return I(this,null,function*(){return yield this.preflight(),this.client.validateToken()})}getAutocompleteSuggestions(t,n){return I(this,null,function*(){return yield this.preflight(),(yield this.client.post(`/api/v2/conversations/${t}/autocomplete`,_t(n),{abortLatest:!0})).map(o=>({score:1,source:o.source,sourceText:o.source_text,text:o.label,trainingJobs:o.training_jobs,searchKeywords:o.search_keywords,type:o.source})).filter((o,s,i)=>s===i.findIndex(a=>a.text===o.text))})}getPinnedMessages(t){return I(this,null,function*(){let n=yield this.client.get(`/api/v2/profiles/${t}/pinned-messages`,{abortLatest:!0});return Fe(n).map(r=>P(S({},r),{text:r.message,source:"sticky-messages",type:"pinned-message"}))})}getStyleSuggestions(t){return I(this,null,function*(){let n=yield this.client.post("/api/style-suggestions",_t(t),{abortLatest:!0,version:"v1"});return Fe(n)})}search(t){return I(this,null,function*(){let n=yield this.client.post(`/api/v2/profiles/${t.profile}/search`,_t(t));return Fe(n)})}knowledgeAssist(s,i,a){return I(this,arguments,function*(t,n,r,o={}){yield this.preflight();let l=yield this.client.post(`/api/knowledge-assist/assistants/${r}/search`,_t({question:t.question,doNotKnowAnswer:t.doNotKnowAnswer,customerInstruction:t.customerInstruction,chatHistory:n.map(c=>({question:c.question,answer:c.answer.answer})),agentId:o.agentId,conversationId:o.conversationId}),{version:"v2"});return Fe(l)})}requestLoginByEmail(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.post("/apis/admin/session/passwordless/request/",{email:t});return Fe(n)})}requestPasswordlessToken(){return I(this,null,function*(){let t=yield this.client.get("/apis/admin/session/passwordless/request/");return Fe(t.token)})}getCsrfToken(){return I(this,null,function*(){let{token:t}=yield this.client.get("/apis/admin/session/csrf/");return t})}verifyLoginToken(t){return I(this,null,function*(){let n=yield this.client.post("/apis/admin/session/passwordless/login/",{token:t});return Fe(n)})}getSummary(r){return I(this,arguments,function*(t,n={}){yield this.preflight();let o=yield this.client.post("/api/summary",{conversation:{messages:t.filter(s=>s.text&&s.source),agent_id:n.agentId,id:n.externalConversationId},prompt_instruction:n.promptInstruction,model:n.model},{version:"v1"});return Fe(o)})}evaluateAssistant(t,n){return I(this,null,function*(){var a;yield this.preflight();let r=new URLSearchParams,{expectFormat:o="text"}=n||{};if(o.startsWith("json-schema:")){let l=o.replace("json-schema:","");r.append("expect_response_format","json-schema"),r.append("expect_response_format_schema",l)}else r.append("expect_response_format",o);n!=null&&n.externalConversationId&&r.append("external_conversation_id",n.externalConversationId);let s=n!=null&&n.threadId?`/api/v2/assistants/${t}/threads/${n==null?void 0:n.threadId}/evaluate?${r.toString()}`:`/api/v2/assistants/${t}/evaluate?${r.toString()}`,i=yield this.client.post(s,{input:(a=n==null?void 0:n.input)!=null?a:{},conversation:n==null?void 0:n.transcript});return Fe(i.output)})}createAssistantThread(t){return I(this,null,function*(){yield this.preflight();let{assistantCode:n}=t,r=yield this.client.post(`/apis/admin/assistants/${n}/threads/`,{});return Fe(r)})}postMessageToAssistantThread(t){return I(this,null,function*(){yield this.preflight();let{assistantCode:n,threadId:r,message:o}=t,s=yield this.client.post(`/apis/admin/assistants/${n}/threads/${r}/messages/`,{content:o,role:"user"});return Fe(s)})}translateMessages(t){return I(this,null,function*(){yield this.preflight();let n=yield this.client.post("/api/translate",_t(t),{version:"v2"});return Fe(n)})}handleDeepdeskVersionHeaders(t){t.headers.forEach((n,r)=>{let o=r.toLowerCase(),s=o.match(ew);if(!n||!s)return;let i=s[1].replace("-","_"),a=this.latestReceivedDeepdeskVersions[i];a&&n&&a!==n&&Z.warn(`Overwritten Version header ${o}: ${JSON.stringify(a)} -> ${JSON.stringify(n)}`),this.latestReceivedDeepdeskVersions[i]=n})}};wi.exchangeTokenPromise=null;var Eo=wi;var hA={startTime:null,stopTime:null},yA=e=>e.handlingTime,vA=ke({name:"handlingTime",initialState:hA,reducers:{handlingTimeStart(e){if(e.startTime&&!e.stopTime)throw new Error("Timing already started");e.startTime=new Date,e.stopTime=null},handlingTimeStop(e){if(!e.startTime)throw new Error("Timing not started");e.stopTime=new Date},handlingTimeReset(e){e.startTime=null,e.stopTime=null}},extraReducers:e=>{e.addCase(lt,()=>hA)}}),{handlingTimeStart:xA,handlingTimeStop:ym,handlingTimeReset:wA}=vA.actions,SA=vA.reducer;var bA=(e={})=>{let t=S({onAuthError:aa(!1)},e);return n=>r=>o=>("error"in o&&o.error.message==="Unauthorized"&&n.dispatch(t.onAuthError),r(o))};var vm={list:{keywordMatches:[]},fetchState:"idle"};var Si=he("styleSuggestions/getAll",(n,r)=>I(void 0,[n,r],function*({text:e},t){var l;let{deepdeskAPI:o}=t.extra,s=t.getState(),{showStyleSuggestions:i}=s.settings,a=(l=s.conversation.current)==null?void 0:l.profileCode;if(!i)return vm.list;if(!a)throw new Error("No current conversation to fetch pinned messages");return o.getStyleSuggestions({profileCode:a,message:e})})),r5=ke({name:"styleSuggestions",initialState:vm,reducers:{},extraReducers:e=>{e.addCase(Si.pending,t=>{t.fetchState="loading"}).addCase(Si.rejected,t=>{t.fetchState="error"}).addCase(Si.fulfilled,(t,n)=>{t.fetchState="done",Xo(t.list,n.payload)||(t.list=n.payload)}).addCase(Bs,t=>{t.list=vm.list}).addCase(lt,()=>vm)}}),EA=r5.reducer;var TA=(e={})=>{let t,n=!0,r=S({getStyleSuggestions:Si,debounce:500},e);return o=>s=>i=>{var p;let a=o.getState().input.text,l=s(i),c=o.getState();if(c.auth.isLoggedIn!==!0)return l;let{showStyleSuggestions:u}=c.settings;if(!((p=c.conversation.current)==null?void 0:p.id)||!u)return l;let{text:f}=c.input;return f===a&&!n||(clearTimeout(t),f==="")||(t=setTimeout(()=>{n=!1,o.dispatch(r.getStyleSuggestions({text:f}))},e.debounce)),l}};function o5(e,t){return e.text===t.text&&e.selection.start===t.selection.start&&e.selection.end===t.selection.end}var CA=(e={})=>{let t=S({getTextSuggestions:gr,getAutocompleteSuggestions:Jc,debounce:200,check:Or},e),n;return r=>o=>s=>{var g;let{input:i}=r.getState(),a=o(s),l=r.getState();if(l.auth.isLoggedIn!==!0)return a;let{recommendTextSuggestions:c,showTabCompletion:u}=l.settings,d=(g=l.conversation.current)==null?void 0:g.id,f=s.type===Up.toString();if(!d||!c&&!u)return a;let{input:p}=l;return o5(p,i)&&!f||(clearTimeout(n),!t.check(l))||(n=setTimeout(()=>{let x=ca(l);x===""?r.dispatch(t.getTextSuggestions("default")):r.dispatch(t.getAutocompleteSuggestions(x))},f?0:t.debounce)),a}};var kA=Si.fulfilled.toString();function s5(e,t){let n=new Set([...t.keywordMatches.map(o=>o.keyword)]),r=[];return n.forEach(o=>{let s=e.keywordMatches.filter(l=>l.keyword===o),i=t.keywordMatches.filter(l=>l.keyword===o),a=i.length-s.length;a<=0||r.push(...i.slice(0,a))}),r}var RA=e=>t=>n=>r=>{var c;if(r.type!==kA){n(r);return}let o=t.getState().styleSuggestions.list;n(r);let s=t.getState(),i=s.styleSuggestions.list,a=(c=s.conversation)==null?void 0:c.current;if(o===i)return;let l=s5(o,i);r.type===kA&&l.length>0&&e.sendEvent("style suggested",{conversationId:a==null?void 0:a.id,data:{keywordMatches:l}})};var i5=sf({assistants:tC,auth:P1,conversation:H1,contentTypes:rC,passwordlessToken:OP,entities:Qk,handlingTime:SA,info:sT,input:Q1,settings:S1,profile:lC,search:dT,styleSuggestions:EA,ui:QR,textSuggestions:DR});function PA(e){return qE({reducer:i5,middleware:t=>{var r;let n=t({thunk:{extraArgument:{dynamicThunkObject:e.dynamicThunkObject,deepdeskAPI:e.deepdeskAPI}},serializableCheck:!1}).concat(bA()).concat(CA({debounce:200})).concat(TA({debounce:500})).concat(RA(e.deepdeskAPI));return((r=e.middleware)!=null?r:[]).reduce((o,s)=>o.concat(s),n)},preloadedState:e.preloadedState})}var a5=e=>{var t,n;return(n=(t=e==null?void 0:e.type)==null?void 0:t.toLowerCase())!=null?n:"unknown"},l5=e=>t=>n=>r=>{var a,l,c,u,d,f;let o=t.getState(),s=Yl("inlineSuggestions")(o);switch(r.type){case aa.toString():{!r.payload&&e.emit("logout",void 0);break}case fr.fulfilled.toString():r.payload.length>0&&e.sendEvent("entities found",{conversationId:(a=o.conversation.current)==null?void 0:a.id,data:{entities:r.payload}});break;case ro.toString():e.sendEvent(r.payload.name,{conversationId:((l=r.payload.options)==null?void 0:l.includeConversationData)&&((c=o.conversation.current)==null?void 0:c.id),data:r.payload.data});break;case Bs.toString():e.logSendMessage(r.payload);break;case Kf.toString():e.emit("call-to-action",{cue:r.payload});break;case or.fulfilled.toString():r.isBroadcasted||e.broadcast(_y,r,!1);break;default:break}let i=n(r);switch(r.type){case Bs.toString():e.handleAfterSendMessage(r.payload);break;case tu.toString():e.onUpdateShowTabHint(r.payload);break;case ym.toString():e.logHandlingTime();break;case Rf.toString():e.broadcast(nc,r);break;case Hs.toString():e.broadcast(nc,r);break;case Gf.toString():t.dispatch(Hs({source:"assistant",assistantCode:r.payload.code}));break;case"analytics/logEvent/fulfilled":{e.emit("event",r.meta.arg);break}case Ef.toString():{let{start:p,end:y}=o.input.selection;e.emit("replace",P(S({},r.payload),{replace:r.payload.replace==="selection"?{start:p,end:y}:{start:0,end:y}}));break}case er.toString():{let{start:p,end:y}=o.input.selection;e.emit("select-suggestion",P(S({type:a5(r.payload.suggestion)},r.payload),{replace:r.payload.replace==="selection"?{start:p,end:y}:{start:0,end:y}})),s&&t.dispatch(Qo([]));break}case Tf.toString():e.emit("select-image",r.payload),e.sendEvent("Image attached",{conversationId:(u=o.conversation.current)==null?void 0:u.id,data:{path:r.payload.suggestion.image,title:r.payload.suggestion.title}});break;case Qo.toString():{s&&r.payload.length>0&&t.dispatch(Cf(0));break}case so.fulfilled.toString():{if(r.isBroadcasted)break;e.broadcast(nc,r,!1),e.sendEvent("conversation summarized",{conversationId:(d=o.conversation.current)==null?void 0:d.id,data:{summary:r.payload,assistant:(f=t.getState().profile.data)==null?void 0:f.summarizerAssistantNew}}),e.emit("summary-generated",{summary:r.payload});break}default:break}return i},AA=l5;function j0(e){return e.toISOString().replace("T"," ").replace("Z","")}var c5=(e,t)=>t.version,IA=$t([da,Rr,yA,c5],(e,t,n,r)=>{if(!t)return Z.warn("No conversationId for handling time metrics"),null;let{startTime:o,stopTime:s}=n;return!o||!s?(Z.warn("No startTime and stopTime for handling time metrics"),null):{conversationId:t,clientVersion:r,agentId:e==null?void 0:e.agentId,agentName:e==null?void 0:e.agentName,agentEmail:e==null?void 0:e.agentEmail,timeStart:j0(o),timeStop:j0(s)}});function LA(e,t){let{text:n,metrics:{numPaste:r,pastes:o,textSuggestions:s}}=e.input,i=n.length;return{source:"agent",clientVersion:t.version,pastes:o,lenTextTotal:i,numPastes:r,suggestions:s}}function K0(e,t){var s;let n=e.closest(t);if(n)return n;let r=e.getRootNode().host;if(r instanceof HTMLElement)return K0(r,t);let o=(s=e.ownerDocument.defaultView)==null?void 0:s.frameElement;return o?K0(o,t):null}function G0(e,t){return K0(e,t)}function MA(e){return typeof e=="object"&&e!==null&&"name"in e&&"message"in e}function u5(e){return typeof e=="object"&&e!==null&&"tagName"in e}function xm(e){return u5(e)&&(gi(e)||Yp(e))}var OA,zr=new Map,d5=["bottom","height","left","right","top","width"],NA=(e,t)=>!e&&!t?!1:e&&!t||!e&&t?!0:d5.some(n=>e[n]!==t[n]);function _A(e){var n,r,o;if(e.ownerDocument===document)return[];let t=(o=(r=(n=e.ownerDocument)==null?void 0:n.defaultView)==null?void 0:r.frameElement)!=null?o:null;return t?[t,..._A(t)]:[]}function DA(e,t){return!e||!t?null:P(S({},e),{top:e.top+t.top,left:e.left+t.left})}var wm=!1,FA=()=>{wm=!0;let e=[];if(zr.forEach((t,n)=>{if(!n.isConnected){t.rect=null,e.push(t),zr.delete(n);return}let r=n.getBoundingClientRect();NA(r,t.rect)&&(t.rect=r,e.push(t))}),e.forEach(t=>{let n=t.parentRects?t.parentRects.reduce(DA,t.rect):t.rect;NA(n,t.totalRect)&&t.callbacks.forEach(r=>r(n)),t.totalRect=n}),zr.size===0){wm=!1;return}OA=window.requestAnimationFrame(FA)};function q0(e,t){let n=_A(e),r=[],o=n.map((s,i)=>q0(s,a=>{r[i]=a;let l=zr.get(e);if(!l)return;let c=r.reduce(DA,l.rect);l.callbacks.forEach(u=>u(c))}));return{observe(s=!0){if(o.forEach(i=>i.observe(!1)),zr.has(e)){let i=zr.get(e);i.callbacks.push(t),i.rect&&t(i.rect)}else zr.set(e,{rect:void 0,callbacks:[t],parentRects:r});s&&!wm&&FA()},unobserve(){o.forEach(i=>i.unobserve());let s=zr.get(e);if(s){let i=s.callbacks.indexOf(t);i>=0&&s.callbacks.splice(i,1),s.callbacks.length||zr.delete(e),zr.size||(cancelAnimationFrame(OA),wm=!1)}}}}var zA,Hr=new Map,HA=()=>{Hr.forEach((e,t)=>{if(!t.isConnected){Hr.delete(t);return}let{clientHeight:n,scrollHeight:r}=t,o=r>n;e.visible!==o&&(e.visible=o,e.callbacks.forEach(s=>s(e.visible)))}),Hr.size!==0&&(zA=window.requestAnimationFrame(HA))};function BA(e,t){return{observe(){let n=Hr.size===0;Hr.has(e)?Hr.get(e).callbacks.push(t):Hr.set(e,{visible:void 0,callbacks:[t]}),n&&HA()},unobserve(){let n=Hr.get(e);if(n){let r=n.callbacks.indexOf(t);r>=0&&n.callbacks.splice(r,1),n.callbacks.length||Hr.delete(e),Hr.size||cancelAnimationFrame(zA)}}}}var Y0=["borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth","borderStyle","boxSizing","color","overflowWrap","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontWeight","fontKerning","lineHeight","letterSpacing","paddingLeft","paddingTop","paddingRight","paddingBottom","width","height","textIndent","whiteSpace","wordBreak","wordSpacing","wordWrap"];function X0(e,t,n){return n.forEach(r=>{t.style[r]=e[r]})}function ja(e){return Number.parseFloat(e)}function Sm(e){return Math.round(e*1e6)}function UA(e){return e/1e6}function Q0(e,t,n){if(e.boxSizing==="content-box")return;let{clientWidth:r}=t,o=ja(e.width),s=ja(e.borderLeftWidth),i=ja(e.borderRightWidth),a=ja(e.paddingRight),l=UA(Sm(o)-Sm(s)-Sm(i)),c=UA(Sm(r));if(l-c>2){let u=l-c;n.style.paddingRight=`${a+u}px`}}function gu(e,t={}){var u,d;let n=t.overlayContainer||document.createElement("div");n.style.display="none",n.style.position=(u=t.position)!=null?u:"fixed",n.style.pointerEvents="none",n.style.borderColor="transparent",ui(n);let r=window.getComputedStyle(e),o=!0,s=()=>{n.scrollTop=e.scrollTop};X0(r,n,Y0),Q0(r,e,n),t.mirrorOverflow&&(n.style.overflow="hidden",e.addEventListener("scroll",s));let i=BA(e,()=>{X0(r,n,Y0),Q0(r,e,n),s(),setTimeout(s,0)}),a,l=!0,c=q0(e,f=>{if(f===null){t.onRemove&&t.onRemove(),n.remove();return}if(!l&&t.onMoveStart&&(Promise.resolve().then(()=>t.onMoveStart()),l=!0),clearTimeout(a),a=setTimeout(()=>{t.onMoveEnd&&t.onMoveEnd(),l=!1},200),f.height===0&&f.width===0){if(o===!0)return;t.onHide&&t.onHide(),n.style.display="none",o=!0;return}if(X0(r,n,Y0),Q0(r,e,n),s(),n.style.top=`${f.top}px`,n.style.left=`${f.left}px`,t.closestScrollElement&&t.closestScrollElement!==e){let p=t.closestScrollElement.getBoundingClientRect(),y=window.getComputedStyle(t.closestScrollElement),g=ja(y.borderTopWidth),x=ja(y.borderBottomWidth),v=p.top+g-f.top,h=f.top+f.height+-(p.top+p.height-x);n.style.clipPath=`inset(${v}px 0px ${h}px 0px)`}o&&(n.style.display="block",t.onShow&&t.onShow(),o=!1)});return t.appendTo?t.appendTo.appendChild(n):(d=e.parentElement)==null||d.appendChild(n),c.observe(),i.observe(),[n,()=>{e.removeEventListener("scroll",s),c.unobserve(),i.unobserve(),n.remove()}]}var VA=(e,t)=>({value(){try{let n=sessionStorage.getItem(`dd-${e}`);if(!n)return t;try{return JSON.parse(n)}catch(r){return t}}catch(n){return t}},update(n){try{sessionStorage.setItem(`dd-${e}`,JSON.stringify(n))}catch(r){Z.warn("[Deepdesk] SessionStorage is blocked by browser")}}});function f5(e){return e.offsetParent!==null}function $A(e){if(!f5(e))return!1;let t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&t.right<=(window.innerWidth||document.documentElement.clientWidth)}function bm(e,t,n=100){let r=$A(e);t({isVisible:r});let o=setInterval(()=>{let s=$A(e);s!==r&&(r=s,t({isVisible:r}))},n);return()=>{clearTimeout(o)}}var hu=class extends Error{};function p5(){let e,t;return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}}var Em=class{constructor(){this.queues={}}push(t,n){let r=()=>{let s=this.queues[t][1];s?(this.queues[t]=[s.promise,null],s.resolve()):delete this.queues[t]};if(!this.queues[t]){let s=n().finally(r);return this.queues[t]=[s,null],s}this.queues[t][1]&&this.queues[t][1].reject(new hu("Queued async function is outdated"));let o=p5();return this.queues[t][1]=o,o.promise.then(()=>n().finally(r))}};var m5={accepted:"onConversationAcceptedAssistants","new-message":"onConversationNewMessageAssistants",ended:"onConversationEndedAssistants"},WA=(e,t)=>{let n=e[m5[t]];return n&&n.length>0?n.map(r=>r.code):(Z.warn(`No assistant set in profile for conversation event "${t}"`),[])};var Tm=class{constructor(t){this.options=t;this.socket=null;this.maxReconnectAttempts=5;this.reconnectInterval=25e3;var n,r;this.socket,this.eventListeners=new Map,this.url=t.url,this.maxReconnectAttempts=(n=t.maxReconnectAttempts)!=null?n:this.maxReconnectAttempts,this.reconnectInterval=(r=t.reconnectInterval)!=null?r:this.reconnectInterval,this.shouldReconnect=t.shouldReconnect,this.reconnect(),window.addEventListener("beforeunload",()=>this.cleanup())}setupListeners(){this.socket&&(this.socket.onmessage=t=>{var n;try{let r=Fe(JSON.parse(t.data));r.event&&this.eventListeners.has(r.event)&&((n=this.eventListeners.get(r.event))==null||n.forEach(o=>o(r.data)))}catch(r){console.error("Error parsing WebSocket message:",r)}},this.socket.onclose=t=>{console.log("WebSocket connection closed:",t),setTimeout(()=>{this.reconnect()},this.reconnectInterval)},this.socket.onerror=t=>{console.error("WebSocket error:",t)})}reconnect(){var t,n;if(this.maxReconnectAttempts<=0){console.error("Max reconnect attempts reached, closing WebSocket connection."),(t=this.socket)==null||t.close();return}if(!this.shouldReconnect()){console.error("Should not reconnect, closing WebSocket connection."),(n=this.socket)==null||n.close();return}this.socket&&(this.socket.onmessage=null,this.socket.onclose=null,this.socket.onerror=null,this.socket.close()),this.socket=new WebSocket(this.url),this.setupListeners(),this.maxReconnectAttempts--}send(t,n){if(!this.socket){console.error("WebSocket connection is not open.");return}this.socket.send(JSON.stringify({event:t,data:n}))}on(t,n){this.eventListeners.has(t)||this.eventListeners.set(t,[]);let r=this.eventListeners.get(t);r&&!r.includes(n)&&r.push(n)}close(){var t;(t=this.socket)==null||t.close()}cleanup(){this.close(),window.removeEventListener("beforeunload",()=>this.cleanup())}};var Le=b(R());var jA=VA("showTabHint",!0),Ka=class Ka{constructor({deepdeskUrl:t,version:n=Ka.version||"unknown",locale:r="en-US",token:o,fetch:s,productName:i,createCustomChannel:a,websocketClient:l=Tm}){this.inputMediator=null;this.eventListeners={};this.unmountHandlers=[];this.inlineSuggestions=null;this.aboveSuggestions=null;this.floatingMenu=null;this.widgetElement=null;this.widgetRoot=null;this.dynamicThunkObject={};this.queues=new Em;this.isMounted=!1;this.shouldRender=!0;this.loadProfileConfigPromise=null;let c=t.replace(/\/api$/,"");this.deepdeskApi=new Eo(c,{token:o,fetch:s}),this.version=n,this.instanceId=Ka.count++;let u={deepdeskAPI:this.deepdeskApi,dynamicThunkObject:this.dynamicThunkObject,middleware:[AA({broadcast:(d,f,p)=>{this.broadcastEvents.send(d,f,p)},emit:(d,f)=>this.emit(d,f),handleAfterSendMessage:d=>this.handleAfterSendMessage(d),logHandlingTime:()=>this.logHandlingTime(),logSendMessage:d=>this.logSendMessage(d),onUpdateShowTabHint:d=>jA.update(d),sendEvent:(d,f)=>this.deepdeskApi.sendEvent(d,f)})]};this.store=PA(u),this.broadcastEvents=new gA({debug:!0,deepdeskUrl:c,eventMap:fT(this.store),createCustomChannel:a}),this.ws=new l({url:`${t}/api/v2/me/realtime`.replace("https","wss"),reconnectInterval:25e3,shouldReconnect:()=>I(this,null,function*(){var d;return(d=this.isLoggedIn())!=null?d:!1})}),this.store.dispatch(tu(jA.value())),this.store.dispatch(vf({locale:r,adminUrl:c,productName:i})),this.ws.on("assistants::user_notification",d=>{d.conversationId&&d.conversationId!==this.conversationId().toString()||this.store.dispatch(eC(d))}),this.ws.on("assistants::response_chunk",d=>{d.conversationId&&d.conversationId!==this.conversationId().toString()||this.store.dispatch(JT(d))})}get state(){return this.store.getState()}get settings(){return this.state.settings}get selectedTextSuggestion(){var t;return(t=zs(this.state)[this.state.input.selectedSuggestionIndex])!=null?t:null}hasConversation(){return!!this.state.conversation.current}conversationId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.id}externalId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.externalId}shouldAbort(){return this.state.conversation.isSupported===!1?(Z.warn("Conversation is not supported"),!0):this.hasConversation()?this.state.profile.data?!1:(Z.warn("Profile has not been loaded (yet)"),!0):(Z.warn("No conversation loaded (yet)"),!0)}login(){this.store.dispatch(aa(null)),this.store.dispatch(to());let t=n=>Wt(n)&&b1(n)!=="loading";return new Promise(n=>{let r=this.subscribe(t,o=>{o&&(r(),n())});this.unmountHandlers.push(()=>{r()})})}isLoggedIn(){return I(this,null,function*(){return(yield this.store.dispatch(to())).payload})}isConversationSupported(t,n){return I(this,null,function*(){return(yield this.store.dispatch(Py({externalId:t,options:n}))).payload})}createConversation(t){return I(this,null,function*(){var r;return this.hasConversation()&&this.externalId()!==t.externalId&&this.resetConversation(),(yield this.store.dispatch(wf(P(S({},t),{metadata:(r=t.metadata)!=null?r:{}})))).payload})}getConversationByExternalId(t,n){return I(this,null,function*(){return this.hasConversation()&&this.externalId()!==t&&this.resetConversation(),(yield this.store.dispatch(Sf({externalId:t,options:n}))).payload})}upsertConversation(t){return I(this,null,function*(){var r;return this.hasConversation()&&this.externalId()!==t.externalId&&this.resetConversation(),(yield this.store.dispatch(Ay(P(S({},t),{metadata:(r=t.metadata)!=null?r:{}})))).payload})}postMessages(t){return I(this,null,function*(){yield this.store.dispatch(Iy(t))})}updateConversation(t){return I(this,null,function*(){return(yield this.store.dispatch(bf(t))).payload})}resetConversation(){this.store.dispatch(lt()),this.loadProfileConfigPromise=null,this.dynamicThunkObject.conversationQuery=null}configure(t){this.store.dispatch(vf(t))}setVisitorInfo(t){this.store.dispatch(nT(t))}setCustomData(t){this.store.dispatch(rT(t))}setAgentInfo(t,n){return I(this,null,function*(){yield this.store.dispatch(Jl(S(S({},t),n)))})}setAgentSettings(t){return I(this,null,function*(){yield this.store.dispatch(My(t))})}getAgentSettings(){return I(this,null,function*(){return(yield this.store.dispatch(Ny())).payload})}refresh(){return I(this,null,function*(){if(this.shouldAbort())return Promise.resolve();let t=[];return t.push(this.refreshTextSuggestions()),t.push(this.refreshWidgetSuggestions()),Promise.all(t).then(()=>{})})}syncInputMediator(){this.inputMediator&&this.store.dispatch(kf({text:this.inputMediator.getText(),html:this.inputMediator.getHTML()}))}notifyExternalSuggestion(t){this.store.dispatch(er(t))}evaluateAssistant(t,n){return I(this,null,function*(){let u=n||{},{input:r={},transcript:o,showCuesInWidget:s=!0,includeMetadata:i,expectFormat:a}=u,l=oe(u,["input","transcript","showCuesInWidget","includeMetadata","expectFormat"]);Object.assign(r,l);let c=yield this.store.dispatch(or({assistantCode:t,expectFormat:a||"json-schema:cues",transcript:o,includeMetadata:i,input:r,skipState:!s}));if(c.error)throw new Error(c.error.message);return c.payload})}evaluateConversationAssistant(t,n){return I(this,null,function*(){yield this.loadProfileConfig();let r=this.state.profile.data;if(!r){Z.warn("Can't evaluate assistant when profile is not loaded yet.");return}let o=WA(r,t);yield Promise.all(o.map(s=>this.queues.push(s,()=>I(this,null,function*(){if(s===r.summarizerAssistantNew)return this.getSummary(S({includeMetadata:!0},n));yield this.evaluateAssistant(s,S({includeMetadata:!0},n))})).catch(i=>{if(i instanceof hu){Z.warn(`Queued assistant "${s}" was outdated and dropped`);return}throw i})))})}getSummary(){return I(this,arguments,function*(t={}){var r;if(!this.hasConversation())return Z.warn("No conversation to create summary for."),null;(r=this.state.profile.data)!=null&&r.summarizerAssistantNew||Z.warn("No profile loaded yet, or no summarizer assistant set in profile");let n=yield this.store.dispatch(so(t));if(n.error)throw new Error(n.error.message);return n.payload})}handleKeyDown(t){let{overlayCollapsed:n,openOverlayWhenTyping:r}=this.state.ui,{textSuggestions:o,selectedSuggestionIndex:s,selection:i}=this.state.input,{inlineSuggestions:a,showTextSuggestions:l}=this.settings,c=a?"below":"above",u=o.length>0;if(this.store.dispatch(W1(Ly(t))),!Or(this.state)||t.key!=="Tab"&&!l)return;let d=()=>{n||!u||i&&(t.shiftKey||(this.store.dispatch(G1()),t.preventDefault()))},f=()=>{n||!u||a&&s<=0||i&&(t.shiftKey||(this.store.dispatch(q1()),t.preventDefault()))};switch(t.key){case"ArrowUp":c==="below"?f():d();break;case"ArrowDown":{c==="below"?d():f();break}case"Escape":{n||(this.store.dispatch(Cf(-1)),this.store.dispatch(is({collapse:!0})),this.store.dispatch(YR(!0)),t.preventDefault());break}case"Tab":{t.preventDefault();let p=ua(this.state);if(!p)return;this.store.dispatch(tu(!1)),this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"tab"},replace:"until-selection-end"}));break}case" ":{if(this.settings.inlineSuggestions||this.state.input.selectedSuggestionIndex===-1)return;let p=ua(this.state);if(!p)return;this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"space"},replace:"until-selection-end"}));break}case"Enter":{if(this.settings.inlineSuggestions||t.shiftKey||this.state.input.selectedSuggestionIndex===-1)return;let p=ua(this.state);if(!p)return;this.store.dispatch(er({text:p.text,suggestion:p,eventMetrics:{inputType:"enter"},replace:"until-selection-end"})),t.preventDefault();break}default:}n&&r&&this.store.dispatch(is({collapse:!1}))}handleAfterSendMessage(t){this.emit("send-message",t),this.store.dispatch(Qo([]))}handlingTimeStart(){this.state.handlingTime.startTime||(Z.info("Start handling time"),this.store.dispatch(xA()))}handlingTimeStop(){this.state.handlingTime.startTime&&(Z.info("Stop handling time"),this.store.dispatch(ym()))}logSendMessage(t){let n=LA(this.state,{version:this.version});n&&(t&&(Object.assign(n,{text:t}),Object.assign(n,{lenTextTotal:t.length})),this.deepdeskApi.sendEvent("Send Message",{conversationId:this.conversationId(),data:n}),this.emit("send-message-event",n))}logHandlingTime(){let t=IA(this.state,{version:this.version});t&&(this.deepdeskApi.sendEvent("Handling Time",{conversationId:this.conversationId(),data:t}),this.store.dispatch(wA()))}notifySubmit(t={}){var n;this.shouldAbort()||(this.store.dispatch(Bs((n=t.text)!=null?n:this.state.input.text)),this.store.dispatch(X1()))}emit(t,n){let r=this.eventListeners[t];r&&r.forEach(o=>{try{o(n)}catch(s){Z.warn(`The following error occurred in deepdeskSDK.on('${t}', handler)`),Z.error(s)}})}on(t,n){return this.eventListeners[t]||(this.eventListeners[t]=[]),this.eventListeners[t].push(n),()=>{this.off(t,n)}}off(t,n){if(!t&&!n){this.eventListeners={};return}let r;this.eventListeners[t]&&(r=this.eventListeners[t].indexOf(n),r>-1&&this.eventListeners[t].splice(r,1))}setConversationQuery(t){this.dynamicThunkObject.conversationQuery=t}setPlatformVariables(t){this.store.dispatch(oT(t))}whenConversationLoaded(t){let n=o=>{var s;return(s=o.conversation.current)==null?void 0:s.id},r=()=>this.loadProfileConfig().then(()=>t());n(this.state)&&r(),this.subscribe(n,o=>{o&&r()})}overlayContainerFactory(t,n,r,o){let[s,i]=gu(n,r);return s.setAttribute("translate","no"),s.dataset.testid=t,o&&s.classList.add(o),[s,i]}createInlineContainer(t,n){var a;let r=document.createElement("div");r.style.position="absolute",r.style.top="0px",r.style.left="0px",r.style.height="0px",r.style.width="0px";let o=document.createElement("div");o.style.display="none",o.style.position="absolute",o.style.height="0px",o.style.width="0px",o.style.backgroundColor="red",r.appendChild(o);let s=(a=t.ownerDocument.defaultView)==null?void 0:a.frameElement,i=s?s.ownerDocument.defaultView:null;if(s&&(i===window||(i==null?void 0:i.parent)===window)){let[l,c]=gu(s,{appendTo:document.body,onMoveStart:()=>{o.style.display="none"}});l.dataset.testid=n,l.style.zIndex="2",l.appendChild(r),this.unmountHandlers.push(()=>{c()})}else document.body.appendChild(r);return o}createContainer(t,n=document.body){let r=window.getComputedStyle(n),o=document.createElement("div");return ui(o),o.dataset.testid=t,o.style.color=r.color,o.style.fontSize=r.fontSize,o.style.fontFamily=r.fontFamily,o.style.fontVariant=r.fontVariant,o.setAttribute("translate","no"),n.appendChild(o),o}storeMetrics(){try{let t=`dd-metrics-${this.conversationId()}`,n=JSON.stringify({text:this.state.input.text,metrics:this.state.input.metrics});window.sessionStorage.setItem(t,n),Z.info(`Stored analytics for ${this.conversationId()}`)}catch(t){}}restoreMetrics(){try{let t=`dd-metrics-${this.conversationId()}`,n=window.sessionStorage.getItem(t);if(!n)return;let r=JSON.parse(n);r.text.trim()===this.state.input.text.trim()?(Z.info(`Restored metrics for ${this.conversationId()}`),this.store.dispatch(Y1(r.metrics))):Z.warn(`Metrics mismatch, disregarding stored metrics for ${this.conversationId()}`),window.sessionStorage.removeItem(t)}catch(t){}}mount(t,n={}){if(this.isMounted)throw new Error("[Deepdesk] This instance was already mounted. Make sure to unmount before you remount.");if(!xm(t))throw new Error("[Deepdesk] Only mount on textarea or contentEditable div.");if(!this.shouldRender)return;let f=n,{customStyles:r,closestScrollSelector:o,floatingMenuParent:s,appendOverlayTo:i,inputMediator:a}=f,l=oe(f,["customStyles","closestScrollSelector","floatingMenuParent","appendOverlayTo","inputMediator"]),c={customStyles:r,closestScrollSelector:o,floatingMenuParent:s,appendOverlayTo:i};this.configure(l),this.settings.automaticHandlingTime&&this.setupHandlingTime(t),ui(t),this.inputMediator=a||(gi(t)?new vi(t):new yi(t)),this.inputMediator.on("change",({plainText:p,rawHTML:y})=>{this.store.dispatch(kf({text:p,html:y}))}),this.inputMediator.on("keyup",p=>{this.store.dispatch(j1(Ly(p)))}),this.inputMediator.on("keydown",p=>{this.handleKeyDown(p)}),this.inputMediator.on("paste",({pastedText:p,selectionText:y})=>{this.store.dispatch(K1({text:p,selectionText:y}))}),this.inputMediator.on("cut",({selectionText:p})=>{this.store.dispatch($1(p))});let u;this.inputMediator.on("selection",p=>{clearTimeout(u),p===null?u=setTimeout(()=>{p!==null&&this.store.dispatch(Pf(p))},500):this.store.dispatch(Pf(p))}),this.inputMediator.on("disabled",()=>{var p;(p=this.inputMediator)==null||p.deactivate(),this.configure({visible:!1})}),this.inputMediator.on("enabled",()=>{this.inputMediator&&(this.configure({visible:!0}),this.inputMediator.activate())}),this.inputMediator.on("submit",()=>{this.settings.detectSubmit&&this.notifySubmit()}),this.inputMediator.on("blur",()=>{this.store.dispatch(Wp(!1))}),this.inputMediator.on("focus",()=>{this.store.dispatch(Wp(!0))}),this.renderSuggestions(t,c),this.subscribe(Yl("inlineSuggestions"),()=>{this.renderSuggestions(t,c)});let d=this.renderOverlays(n);this.unmountHandlers.push(()=>{d.unmount()}),this.store.dispatch(kf({text:this.inputMediator.getText(),html:this.inputMediator.getHTML()})),this.store.dispatch(Pf(this.inputMediator.getSelection())),this.store.dispatch(Wp(this.inputMediator.isFocused)),this.unmountHandlers.push(()=>{this.state.input.text!==""&&this.storeMetrics()}),this.whenConversationLoaded(()=>{var p;this.restoreMetrics(),this.syncInputMediator(),this.refreshTextSuggestions(),this.broadcastEvents.setExternalId((p=this.state.conversation.current)==null?void 0:p.externalId)}),this.isMounted=!0}subscribe(t,n){let r=t(this.store.getState());return this.store.subscribe(()=>{let o=t(this.store.getState());o!==r&&(r=o,n(r))})}unmount(){var t,n,r,o;(t=this.inlineSuggestions)==null||t.unmount(),(n=this.aboveSuggestions)==null||n.unmount(),(r=this.floatingMenu)==null||r.unmount(),this.unmountHandlers.forEach(s=>s()),this.unmountHandlers=[],(o=this.inputMediator)==null||o.dispose(),this.broadcastEvents.cleanup(),this.isMounted=!1}renderSuggestions(t,n){var r,o,s;(r=this.floatingMenu)==null||r.unmount(),(o=this.inlineSuggestions)==null||o.unmount(),(s=this.aboveSuggestions)==null||s.unmount(),this.settings.floatingMenu&&(this.floatingMenu=this.renderFloatingMenu(t,n)),this.settings.inlineSuggestions?this.inlineSuggestions=this.renderInlineSuggestions(t,n):this.aboveSuggestions=this.renderAboveSuggestions(t,n)}renderInlineSuggestions(t,n){let{customStyles:r}=n,o=this.createInlineContainer(t,"deepdesk-caret"),s=(0,ms.createRoot)(o);s.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(iP,{})})}));let i=a=>{a?(o.style.display="block",o.style.top=`${a.top}px`,o.style.left=`${a.left}px`):o.style.display="none"};return this.inputMediator.on("caretposition",i),{unmount:()=>{var a;(a=this.inputMediator)==null||a.off("caretposition",i),s.unmount(),o.remove()}}}renderAboveSuggestions(t,n){let{customStyles:r,closestScrollSelector:o,appendOverlayTo:s}=n,i=o&&G0(t,o)||void 0,[a,l]=this.overlayContainerFactory("deepdesk-tab-completion",i||t,{appendTo:s,closestScrollElement:i,mirrorOverflow:!0,onRemove:()=>this.unmount()},r==null?void 0:r.rootNode),[c,u]=this.overlayContainerFactory("deepdesk-suggestions-overlay",i||t,{appendTo:s},r==null?void 0:r.suggestionsRootNode),d=(0,ms.createRoot)(a);d.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(LP,{inputElement:t})})}));let f=(0,ms.createRoot)(c);return f.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(gP,{onLogIn:()=>this.loginViaPopup().catch(p=>Z.warn(p.message))})})})),{unmount(){d.unmount(),f.unmount(),l(),u()}}}renderFloatingMenu(t,n){let{customStyles:r,closestScrollSelector:o,appendOverlayTo:s,floatingMenuParent:i}=n,a=o&&G0(t,o)||void 0,[l,c]=this.overlayContainerFactory("floating-menu",a||t,{appendTo:i!=null?i:s},r==null?void 0:r.floatingMenuParent),u=(0,ms.createRoot)(l);return u.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(GR,{onLogIn:()=>this.loginViaPopup().catch(d=>Z.warn(d.message))})})})),{unmount(){u.unmount(),c()}}}renderOverlays(t){let{customStyles:n}=t,r=this.createContainer("deepdesk-overlays"),o=(0,ms.createRoot)(r);return o.render((0,Le.jsx)(ls,{store:this.store,customStyles:n,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(VR,{})})})),{unmount(){o.unmount(),r.remove()}}}renderWidget(t,n={}){if(this.widgetElement&&Z.warn("A widget was already rendered for this instance. Make sure to unmountWidget before rerendering"),!this.shouldRender)return;let{customStyles:r,showImages:o,isEmbedded:s}=n;this.widgetElement=t,this.configure({showImages:o,isEmbedded:s}),this.widgetRoot=(0,ms.createRoot)(t),this.widgetRoot.render((0,Le.jsx)(ls,{store:this.store,customStyles:r,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(cA,{assistantOptions:n.assistantOptions,knowledgeAssistOptions:n.knowledgeAssist,onLogIn:()=>this.loginViaPopup().catch(i=>Z.warn(i.message))})})})),this.whenConversationLoaded(()=>{var i;this.broadcastEvents.setExternalId((i=this.state.conversation.current)==null?void 0:i.externalId)})}unmountWidget(){var t,n;(t=this.widgetRoot)==null||t.unmount(),this.widgetRoot=null,(n=this.widgetElement)==null||n.remove(),this.widgetElement=null}renderKnowledgeAssistantWidget(t,n,r={}){let{customStyles:o,initialQuestion:s}=r,i=(0,ms.createRoot)(n);return i.render((0,Le.jsx)(ls,{store:this.store,customStyles:o,children:(0,Le.jsx)(Zo,{broadcastEvents:this.broadcastEvents,children:(0,Le.jsx)(F0,{children:(0,Le.jsxs)(fm,{assistantCode:t,initialQuestion:s,evaluateKnowledgeAssistFn:r.isLegacyKnowledgeAssist?Ks:Gs,children:[(0,Le.jsx)(Ri,{children:(0,Le.jsx)(mm,{title:r.title,emptyState:r.emptyState})}),(0,Le.jsx)(D0,{children:(0,Le.jsx)(pm,{})})]})})})})),{unmount(){i.unmount()}}}setupHandlingTime(t){let n=bm(t,({isVisible:r})=>{r?this.handlingTimeStart():this.handlingTimeStop()});this.unmountHandlers.push(()=>{this.handlingTimeStop(),n()}),this.whenConversationLoaded(()=>{this.handlingTimeStart()})}handleError(t){MA(t)&&t.message==="Unauthorized"&&this.login()}loadProfileConfig(){return this.loadProfileConfigPromise?this.loadProfileConfigPromise:(this.loadProfileConfigPromise=Promise.resolve().then(()=>I(this,null,function*(){yield this.store.dispatch(Tc());let t=qs(this.state);t&&this.store.dispatch(vf({showSearch:t.search,showImageSearch:t.imageSearch,showEntitiesCommand:t.entitiesCommand,showSummaryCommand:!!t.summarizerAssistantNew,showKnowledgeSearch:!!t.knowledgeAssistantNew||!!t.knowledgeAssistant,recommendTextSuggestions:t.recommendTextSuggestions}))})),this.loadProfileConfigPromise)}loginViaPopup(t){return I(this,null,function*(){return new Promise((n,r)=>{let o=new MessageChannel,s=o.port1,i=this.settings.adminUrl,a=new URL(t!=null&&t.url?t==null?void 0:t.url:`${i}/platform/sso/`);a.searchParams.append("redirect","/sdk/popup/close.html");let l=!1,c=()=>{u&&!u.closed&&u.close(),window.removeEventListener("message",d),clearInterval(f)};s.onmessage=p=>I(this,null,function*(){var y,g;if((y=p.data)!=null&&y.jwt)try{yield this.deepdeskApi.exchangeTokenForAccessCookie((g=p.data)==null?void 0:g.jwt),yield this.isLoggedIn(),this.broadcastEvents.send(tc),l=!0,o.port1.close(),n()}catch(x){console.error(x),r(x)}finally{l=!0,c()}});let u=window.open(a.toString(),"deepdesk-login","scrollbars=no,left=100,top=150,width=500,height=500");u===null&&r(new Error("Popup blocked by browser"));let d=p=>I(this,null,function*(){var y;if(p.origin===a.origin)switch((y=p.data)==null?void 0:y.type){case"deepdesk-popup-loaded":{try{let g=JSON.stringify({type:"deepdesk-popup-create-channel"});u==null||u.postMessage(g,a.origin,[o.port2])}catch(g){Z.error("Error posting message to popup",g),r(g)}break}case"deepdesk-popup-error":{c(),p.data.message==="Timeout"&&Z.warn("Popup timed out. Check if the account's platform url is configured correctly."),r(new Error(p.data.message));break}}});window.addEventListener("message",d);let f=setInterval(()=>{u&&!u.closed||(c(),l||r(new Error("Popup closed by user")))},200);this.unmountHandlers.push(c)})})}translateMessages(t){return this.deepdeskApi.translateMessages(t)}checkForTrialMode(t){return I(this,null,function*(){try{let{account:n}=yield this.deepdeskApi.getPlatformConfig();if(!n.isTrial){this.shouldRender=!0;return}if(Z.info("Trial is active"),!(yield this.deepdeskApi.checkUserExists(t)))throw new Error("User is not in trial");this.shouldRender=!0}catch(n){let{message:r}=n;Z.info(r),this.shouldRender=!1}})}refreshTextSuggestions(){return I(this,null,function*(){this.isMounted&&(yield this.store.dispatch(Up()))})}refreshWidgetSuggestions(){return I(this,null,function*(){if(!this.widgetRoot)return;let{uiConfig:t}=this.state.profile.data;if(!t.widget)return;let n=Cc(this.state);try{n.forEach(({type:r})=>{switch(r){case"entities":this.store.dispatch(fr());break;case"pinned-messages":case"sticky-messages":break;default:Fu.includes(r)||this.store.dispatch(gr(r))}})}catch(r){this.handleError(r)}})}};Ka.version="17.2.1-beta.2",Ka.count=0;var yu=Ka;function g5(e){return I(this,null,function*(){var o,s,i;let n=yield((o=e.fetch)!=null?o:window.fetch)(e.url),r=yield n.blob();return new File([r],e.name,{type:(i=(s=e.mimeType)!=null?s:n.headers.get("Content-Type"))!=null?i:"image/jpeg"})})}function KA(e,t){return I(this,null,function*(){let n=yield g5(t),r=new Event("change",{bubbles:!0,cancelable:!0});try{Object.defineProperty(e,"files",{configurable:!0,get:()=>[n]}),e.dispatchEvent(r)}finally{Object.hasOwn(e,"files")&&delete e.files}})}function GA(e,t,n){return I(this,null,function*(){yield new Eo(e).authenticateWithKey(t,n)})}function qA(e){return e.replace(/\[([\w\s\d]+)\]\((https?:\/\/[^\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>')}function YA(r,o){return I(this,arguments,function*(e,t,n={}){var d,f;let{value:s}=e,{start:i,end:a}=(d=n.replace)!=null?d:{start:0,end:s.length},l=`${s.slice(0,i)}${t}${s.slice(a)}`,c=(f=n.selectionAfter)!=null?f:{start:i+t.length,end:i+t.length},u=()=>{if(n.setValue)return n.setValue(l);e.value=l};return Promise.resolve(u()).then(()=>{e.selectionStart=c.start,e.selectionEnd=c.end,e.blur(),e.focus()})})}function XA(r,o){return I(this,arguments,function*(e,t,n={}){let s=n.replace?fs(e,n.replace.start,n.replace.end):Va(e),i,a=()=>{if(n.setRange)return n.setRange(s.cloneRange());s.deleteContents(),i=document.createElement("span"),s.insertNode(i),n.insertBRs!==!1?t.split(`
|
|
83
83
|
`).reverse().forEach((l,c)=>{c>0&&s.insertNode(document.createElement("br")),s.insertNode(document.createTextNode(l))}):s.insertNode(document.createTextNode(t))};return Promise.resolve(a()).then(()=>{try{if(n.selectionAfter!==!1){e.focus();let l=n.selectionAfter?fs(e,n.selectionAfter.start,n.selectionAfter.end):(s.collapse(!1),s),c=window.getSelection();c==null||c.removeAllRanges(),c==null||c.addRange(l)}if(!i)return;i.scrollIntoView&&i.scrollIntoView({block:"nearest",inline:"nearest"})}finally{i&&i.remove()}})})}function h5(e){let t=document.createElement("template");return t.innerHTML=e.replace(/(\[([^\]]+)])\(([^)]+)\)/g,'<a href="$3" target="_blank" rel="noopener noreferrer">$2</a>'),t.content}function y5(e){let t=document.createDocumentFragment();return e.split(`
|
|
84
84
|
`).forEach((n,r)=>{r>0&&t.appendChild(document.createElement("br"));let o={index:0},s=0;for(;o=n.slice(s).match(/(\[([^\]]+)])\(([^)]+)\)/);){let i=document.createElement("a");i.href=o[3],i.setAttribute("target","_blank"),i.setAttribute("rel","noopener noreferrer"),i.appendChild(document.createTextNode(o[2])),t.appendChild(document.createTextNode(n.slice(s,s+o.index))),t.appendChild(i),s=s+o.index+o[0].length}t.appendChild(document.createTextNode(n.slice(s)))}),t}function QA(e,t){let n=e.parentElement;if(!n){console.warn("No insert point found");return}let{display:r}=window.getComputedStyle(n);r.includes("block")||r==="table-cell"?n==null||n.insertBefore(t,e.nextSibling):QA(n,t)}function ZA(o,s){return I(this,arguments,function*(e,t,{isBlock:n,isHTML:r}={}){let i;e.dispatchEvent(new InputEvent("beforeinput",{inputType:"insertText",data:t,bubbles:!0,cancelable:!0}));let a=()=>{var f;let l=(f=e.ownerDocument.defaultView)!=null?f:window,c=l.getSelection();if((!c||c.rangeCount===0)&&(e.focus(),c=l.getSelection()),!c||c.rangeCount===0)return;let u=c.getRangeAt(0);if(!u)return;i=document.createElement("span"),u.insertNode(i);let d=r?h5(t):y5(t);n?QA(u.startContainer,d):(u.insertNode(d),u.collapse(!1))};return Promise.resolve(a()).then(()=>{if(e.dispatchEvent(new InputEvent("input",{inputType:"insertText",data:t,bubbles:!0,cancelable:!0})),e.focus(),!!i)try{i.scrollIntoView&&i.scrollIntoView({block:"nearest",inline:"nearest"})}finally{i&&i.remove()}})})}return fI(v5);})();
|
|
85
85
|
/*! Bundled license information:
|