arcy.js 0.1.4 → 0.1.6

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.
@@ -1288,5 +1288,5 @@ ${t}`,!0;let r=e.host.ownerDocument.createElement("style");return Re(r),r.setAtt
1288
1288
  transition: none;
1289
1289
  }
1290
1290
  }
1291
- `+Zt+Wt+pn,Fn="http://www.w3.org/2000/svg";function te(e,t,n=17){let r=e.createElementNS(Fn,"svg");r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true"),r.setAttribute("width",String(n)),r.setAttribute("height",String(n));for(let o of typeof t=="string"?[t]:t){let a=e.createElementNS(Fn,"path");a.setAttribute("d",o),a.setAttribute("fill","none"),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width","2"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.appendChild(a);}return r}var _o="M12 21a9 9 0 100-18 9 9 0 000 18zM12 7v5l3 2",Pn="M13 3L5 14h6l-1 7 8-11h-6l1-7z",So="M6 9l6 6 6-6",Lo="M18 6L6 18M6 6l12 12",Io=["M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z","M9 12a3 3 0 1 0 6 0 3 3 0 1 0-6 0"],Ro=["M19 13V19H13","M5 5L19 19"],$n=["M5 8h10","M9 4v4","M12 20l4-9 4 9","M13.5 17h5","M13 8a10 10 0 0 1-8 8","M8 11a10 10 0 0 0 5 5"],Mo="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z";function Ue(e,t){let n=e.style,r=t.bar.getMetrics(),o=t.getMaxHeightPercent?.()??Ao,a=r.bottomOffset+r.keyboardOffset+r.height+8;if(n.setProperty("bottom",`${a}px`),n.setProperty("left","50%"),n.setProperty("translate","-50%"),n.setProperty("transform",xe(r.offset)),r.isMobile){e.setAttribute("data-sheet",""),n.setProperty("width",`calc(100% - ${24}px)`),n.setProperty("max-width","none"),n.setProperty("height",`calc(100% - ${a+12}px)`),n.setProperty("max-height","none");return}e.removeAttribute("data-sheet");let s=Oe(r.widthPercent,{width:r.viewportWidth,height:r.viewportHeight});n.setProperty("width",`${s}px`),n.setProperty("max-width",`calc(100vw - ${32}px)`),n.setProperty("transform",xe({x:De(r.offset.x,s,r.viewportWidth),y:r.offset.y}));let h=a-r.offset.y,C=un(o,r.viewportHeight,h);n.setProperty("height",`${C}px`),n.setProperty("max-height",`${C}px`);}function Fo(e){try{let ee=function(){try{for(;Q.firstChild;)Q.removeChild(Q.firstChild);Q.style.setProperty("display",P.length>0?"flex":"none");let i=d().removeImage;for(let p of P){let f=c.createElement("div");if(f.className=J,f.setAttribute("data-state",p.attachment?"ready":"uploading"),p.previewUrl){let _=c.createElement("img");_.src=p.previewUrl,_.alt="",f.appendChild(_);}let b=c.createElement("button");b.type="button",b.setAttribute("aria-label",i),b.setAttribute("data-tip",i),b.appendChild(te(c,Lo,12)),b.addEventListener("click",()=>{P=P.filter(_=>_!==p),bt(p),ee();}),f.appendChild(b),Q.appendChild(f);}e.bar.setAttachmentCount(P.length);}catch{}},vt=function(){e.setConversationId?.(null),M.clear(),yt(),X();},he=function(i){let p=ie;p&&(ie=null,oe.hide(),e.bar.setAwaitingInput?.(!1),e.bar.setDisabled(_e),e.bar.setPlaceholder(w()?.inputPlaceholder??null),p.resolve(i));},je=function(i){let p=ie;if(!p)return;let f=p.request,b=f.kind==="select"||f.kind==="radio"?gn(i,f.options):f.kind==="password"?i:i.trim(),_=mn(b,f);if(_!==null){oe.setError(_);return}he(b);},At=function(i){if(_e)return;let p=P.filter(f=>f.attachment!==null);P=P.filter(f=>f.attachment===null),ee(),M.addMessage("user",i,{images:p.length,imageUrls:p.map(f=>f.previewUrl).filter(f=>f!==null)}),X(),_e=!0,e.bar.setDisabled(!0),M.setPending(!0),wn({apiBase:e.apiBase??D,publicKey:e.publicKey??"",sessionId:e.getSessionId?.()??"",sessionToken:e.getSessionToken?.()??"",query:i,route:e.getRoute?.()??l?.location?.pathname??"",conversationId:e.getConversationId?.()??"",attachments:p.map(f=>({objectKey:f.attachment.objectKey}))}).then(f=>{let b=d();if(f.ok){M.addMessage("assistant",f.message,{messageId:f.messageId,citedSources:f.citedSources,flowOffers:f.flowsOffered}),e.touchConversation?.(),f.isFallback&&e.track?.("fallback_triggered",{},{question:i});for(let _ of f.flowsOffered)e.track?.("flow_suggested",{},{flowCvid:_.flowCvid});return}if(f.reason==="cap_denied"){ko.has(f.capReason)?e.onOrgCapExceeded?.():M.addMessage("system",b.userCapReached);return}M.addMessage("system",b.genericError);}).finally(()=>{_e=!1,M.setPending(!1),e.bar.setDisabled(!1);});},ge=function(){if(!u.hasAttribute("data-open")){Ke(),st(e.host,c,e.apiBase),e.bar.setMode("open"),Ue(u,e),u.setAttribute("data-open","");try{let i=e.isolated?e.root:c,p=e.isolated?i.activeElement:c.activeElement;Le=(e.isolated?p!==null:!!(p&&e.host.contains(p)))?null:c.activeElement,e.bar.focusInput();}catch{}}},Ke=function(){let i=w(),p=d();N(),W(),ie||e.bar.setPlaceholder(i?.inputPlaceholder??null),e.bar.setAttachEnabled(i?.allowImageUpload===!0),e.bar.setDisclaimer(j());for(let[f,b]of [[x,p.historyTitle],[A,p.flowsTitle],[$,p.settingsTitle],[U,p.collapse]])f.setAttribute("aria-label",b),f.setAttribute("data-tip",b);for(let f of [O,G,B])f.setTexts({backLabel:p.back,closeLabel:p.closeSheet});X();},_t=function(){if(u.hasAttribute("data-open")){u.removeAttribute("data-open"),O.close(),G.close(),B.close(),Z="root",e.bar.setMode("idle"),e.bar.setDisclaimer(null);try{let i=Le;Le=null;let p=u.getRootNode();(p instanceof ShadowRoot?p.activeElement:document.activeElement!==null&&document.activeElement!==document.body)&&i&&i.isConnected&&typeof i.focus=="function"&&i.focus();}catch{}}};var t=ee,n=vt,r=he,o=je,a=At,s=ge,h=Ke,C=_t;let g={host:e.host,root:e.root,isolated:e.isolated,destroy(){}};Xe(g,To),Xe(g,fn);let c=e.host.ownerDocument,l=c.defaultView,w=()=>{try{return e.getWidget?.()??null}catch{return null}},d=()=>w()?.chrome??Ft,u=c.createElement("div");u.className=de,u.setAttribute("role","dialog"),u.setAttribute("aria-label","ARCY chat"),u.tabIndex=-1,u.style.setProperty("position","absolute","important"),u.style.setProperty("pointer-events","auto","important"),u.style.setProperty("box-sizing","border-box");let v=c.createElement("div");v.className=dt;let m=(i,p,f)=>{let b=c.createElement("button");return b.type="button",b.className=ze,b.setAttribute("aria-label",i),b.setAttribute("data-tip",i),b.setAttribute("data-tip-placement","below"),b.setAttribute("data-tip-align",f),b.appendChild(te(c,p)),b},x=m(d().historyTitle,_o,"start"),A=m(d().flowsTitle,Pn,"start");A.style.setProperty("display","none");let E=c.createElement("div");E.className="arcy-chat-identity";let L=c.createElement("span"),H=c.createElement("span");H.className=On,E.appendChild(L),E.appendChild(H);let $=m(d().settingsTitle,Io,"end");e.bar.dock||$.style.setProperty("display","none");let U=m(d().collapse,So,"end");v.appendChild(x),v.appendChild(A),v.appendChild(E),v.appendChild($),v.appendChild(U);let N=()=>{let i=w(),p=at(i?.logoUrl,e.apiBase);if(H.textContent=p?"":i?.name??"",H.style.setProperty("display",p?"none":"block"),p&&L.getAttribute("data-src")===p)return;let f=p?c.createElement("img"):c.createElement("span");if(f.className=p?Nn:"",p){let b=f;b.alt=i?.name??"",b.decoding="async",b.onerror=()=>{try{let _=c.createElement("span");b.replaceWith(_),L=_,H.textContent=i?.name??"",H.style.setProperty("display","block");}catch{}},b.setAttribute("data-src",p),b.src=p;}L.replaceWith(f),L=f;},y=c.createElement("div");y.className=ne;let k=c.createElement("div");k.className=Dn;let T=c.createElement("a");T.className=Ae,T.href=Co,T.target="_blank",T.rel="noopener noreferrer";let I=c.createElement("span"),q=Ln(c);q&&q.setAttribute("class",ke),T.appendChild(I),q&&T.appendChild(q),k.appendChild(T);let W=()=>{let i=d();I.textContent=i.poweredBy.replace(/\s*ARCY\s*$/i,""),T.setAttribute("aria-label",i.poweredBy);},j=()=>{let i=w(),p=d(),f=i?.privacyPolicyUrl,b=i?.name?p.aiDisclaimer.replace("{app}",i.name):p.aiDisclaimer;if(typeof f=="string"&&/^https:\/\//i.test(f)){let _=p.consentWithPolicy.indexOf("{policy}"),Y=_>=0?p.consentWithPolicy.slice(0,_):`${p.consentWithPolicy} `,R=_>=0?p.consentWithPolicy.slice(_+8):"";return {before:`${b}${p.disclaimerJoin}${Y}`,linkLabel:p.privacyPolicy,linkHref:f,after:R}}return b},ue=c.createElement("div");ue.className=Bn,ue.appendChild(y),u.appendChild(v),u.appendChild(ue),u.appendChild(k),e.root.appendChild(u),st(e.host,c,e.apiBase),Ue(u,e);let M=en(y,c,{labels:{likeAnswer:d().likeAnswer,dislikeAnswer:d().dislikeAnswer},answeringLabel:()=>d().answering,searchedSourcesLabel:d().searchedSourcesLabel,sourcesLabel:d().sourcesLabel,flowOfferHint:()=>d().flowOfferHint,onStartFlow:i=>{e.track?.("flow_pill_clicked",{},{flowCvid:i}),e.onStartFlow?.(i);},onFeedback:(i,p)=>{e.track?.("answer_feedback",{},{value:i});let f=e.getSessionToken?.()??"",b=e.getConversationId?.()??"";!p||!f||!b||Sn({apiBase:e.apiBase,sessionToken:f,conversationId:b,messageId:p,value:i,visitorId:e.getVisitorId?.()??void 0});}}),z=c.createElement("div");z.className=re,y.insertBefore(z,y.firstChild);let ft=[],fe=!0,ht=null,X=()=>{try{for(;z.firstChild;)z.removeChild(z.firstChild);if(!M.isEmpty()){z.style.setProperty("display","none");return}z.style.setProperty("display","flex");let i=w(),p=c.createElement("div");p.className="arcy-chat-welcome-icon";let f=at(i?.welcomeIconUrl,e.apiBase);if(f&&f!==ht){let R=c.createElement("img");R.src=f,R.alt="",R.addEventListener("error",()=>{ht=f,X();},{once:!0}),p.appendChild(R);}else p.appendChild(te(c,Mo,18));z.appendChild(p);let b=i?.welcomeHeadline?.trim()??"",_=i?.welcomeMessage?.trim()??"";if(b){let R=c.createElement("div");R.className="arcy-chat-headline",R.textContent=b,z.appendChild(R);}if(_){let R=c.createElement("div");R.className="arcy-chat-greeting",R.textContent=_,z.appendChild(R);}let Y=c.createElement("div");Y.className=pt,fe&&Y.setAttribute("data-pending","");for(let R of ft){let K=c.createElement("button");K.type="button",K.className=pe,K.textContent=R.publicName,K.addEventListener("click",()=>{e.track?.("starter_flow_clicked",{},{flowCvid:R.cvid}),e.onStartFlow?.(R.cvid);}),Y.appendChild(K);}z.appendChild(Y);}catch{}},Q=c.createElement("div");Q.className=ut,Q.style.setProperty("display","none");let mt=e.bar.attachmentSlot?.()??null;mt?mt.appendChild(Q):y.insertBefore(Q,y.firstChild);let P=[],gt=In(c),Hn=gt.fetchImpl??(typeof fetch<"u"?fetch.bind(globalThis):null),Un=i=>{try{return l?.URL?.createObjectURL?.(i)??URL.createObjectURL(i)}catch{return null}},Ve=i=>{if(i.previewUrl){try{(l?.URL??URL).revokeObjectURL(i.previewUrl);}catch{}i.previewUrl=null;}},bt=i=>{Ve(i);let p=i.attachment?.objectKey;p&&Mn(p,{apiBase:e.apiBase,sessionToken:e.getSessionToken?.()??"",fetchImpl:Hn});},yt=()=>{let i=P;P=[];for(let p of i)bt(p);ee();},Ee=Promise.resolve(),wt=i=>{Ee=Ee.then(async()=>{for(let p of i){let f=e.getSessionToken?.()??"",b=K=>{let Ie=d();M.addMessage("system",K==="type"?Ie.imageWrongType:K==="size"?Ie.imageTooLarge:K==="count"?Ie.imageTooMany:Ie.imageFailed);},_=ct(p,P.length);if(!_.ok){b(_.reason),X();continue}let Y={previewUrl:Un(p),attachment:null};P=[...P,Y],ee();let R=await Rn(p,P.length-1,{apiBase:e.apiBase,sessionToken:f,env:gt});if(R.ok){Y.attachment=R.attachment,ee();continue}P=P.filter(K=>K!==Y),Ve(Y),ee(),b(R.reason),X();}}),Ee=Ee.catch(()=>{});},We=[],O=$e(u,c,{title:d().historyTitle,emptyText:d().historyEmpty,actionLabel:d().newChat,subtitleTips:!1,backLabel:d().back,closeLabel:d().closeSheet,onBack:()=>O.close(),onAction:()=>{vt(),O.close();},onSelect:i=>{if((e.getConversationId?.()??"")===i&&!M.isEmpty()){O.close();return}e.setConversationId?.(i),M.clear(),yt(),X(),O.close(),zn(i);}});async function zn(i){let p=e.getSessionToken?.()??"";if(!p)return;let f=await _n({apiBase:e.apiBase,sessionToken:p,conversationId:i,visitorId:e.getVisitorId?.()??void 0});if(f.ok&&(e.getConversationId?.()??"")===i){M.clear();for(let b of f.messages)M.addMessage(Tn(b.role),b.text,{images:b.images,at:b.occurredAt?new Date(b.occurredAt):void 0,messageId:b.id,feedback:b.feedback});X(),M.scrollToEnd();}}let G=$e(u,c,{title:d().flowsTitle,emptyText:d().flowsEmpty,actionLabel:null,backLabel:d().back,closeLabel:d().closeSheet,itemIcon:i=>te(i,Pn,16),onBack:()=>G.close(),onSelect:i=>{G.close(),e.onStartFlow?.(i);}}),Z="root",B=$e(u,c,{title:d().settingsTitle,side:"right",actionLabel:null,backLabel:d().back,closeLabel:d().closeSheet,onBack:()=>{if(Z==="language"){Z="root",Te();return}B.close();},onSelect:i=>{if(Z==="language"){B.close(),Z="root",e.onSelectLocale?.(i);return}if(i==="language"){Z="language",Te();return}i==="dock"&&(B.close(),e.onRequestClose(),e.bar.dock?.());}}),Vn=()=>{if(!e.onSelectLocale)return [];let i=w()?.locales??[];return i.length>=2?i:[]},Te=()=>{let i=d(),p=Vn();if(Z==="language"){B.setTitle(i.language),B.setItems(p.map(b=>({id:b.code,title:b.label,active:b.code===w()?.activeLocale,icon:_=>te(_,$n,16)})));return}B.setTitle(i.settingsTitle);let f=p.find(b=>b.code===w()?.activeLocale);B.setItems([...p.length?[{id:"language",title:i.language,subtitle:f?.label??null,icon:b=>te(b,$n,16)}]:[],{id:"dock",title:i.dockChat,subtitle:i.dockChatHint,icon:b=>te(b,Ro,16)}]);},xt=()=>{let i=d();O.setTitle(i.historyTitle),O.setTexts({emptyText:i.historyEmpty,actionLabel:i.newChat}),O.setItems(lt(We,i.imageConversation,e.getConversationId?.())),O.open(),Wn();};async function Wn(){let i=e.getSessionToken?.()??"",p=e.getVisitorId?.()??"";if(!i||!p)return;let f=await En({apiBase:e.apiBase,sessionToken:i,visitorId:p});f.ok&&(We=f.conversations,O.isOpen()&&O.setItems(lt(We,d().imageConversation,e.getConversationId?.())));}x.addEventListener("click",xt),A.addEventListener("click",()=>{let i=d();G.setTitle(i.flowsTitle),G.setTexts({emptyText:i.flowsEmpty}),G.open();});let Ct=()=>{Z="root",Te(),B.open();};$.addEventListener("click",Ct);let kt=()=>e.onRequestClose();U.addEventListener("click",kt);let oe=hn(e,()=>d()),ie=null,_e=!1;e.bar.onSubmit(i=>{if(ie){je(i);return}ge(),At(i);}),e.bar.onFiles?.(i=>{ge(),wt(i);});let jn=()=>w()?.allowImageUpload===!0,Gn=i=>{qe(i)&&i.preventDefault();},Yn=i=>{if(!qe(i)||(i.preventDefault(),!jn()))return;let p=Pt(i);p.length>0&&wt(p);};u.addEventListener("dragover",Gn),u.addEventListener("drop",Yn);let me=i=>{ft=i,fe=!1,X();},Se=!1,Ge=null,Ye=()=>{if(Se)return !0;let i=e.getSessionToken?.();return i?(Se=!0,Ge=w()?.audience||null,bn({apiBase:e.apiBase,sessionToken:i,sessionId:e.getSessionId?.()}).then(p=>{if(!p.ok){me([]);return}let f=yn(p.flows);me(p.starterFlows),f.length!==0&&(A.style.setProperty("display","flex"),G.setItems(f.map(b=>({id:b.cvid,title:b.publicName,subtitle:b.summary}))));}).catch(()=>{me([]);}),!0):!1};if(!Ye())try{l?.setTimeout(()=>{!Ye()&&fe&&me([]);},Eo);}catch{}let Et=i=>{if(i.key==="Escape"){if(i.stopPropagation(),O.isOpen()){O.close();return}if(G.isOpen()){G.close();return}if(B.isOpen()){B.close();return}e.onRequestClose();}};u.addEventListener("keydown",Et);let Tt=()=>{u.hasAttribute("data-open")&&Ue(u,e),oe.reposition();};l?.addEventListener("resize",Tt);let Le=null;return {open:ge,close:_t,reposition(){u.hasAttribute("data-open")&&Ue(u,e),oe.reposition();},refreshChrome(){let i=w()?.audience||null;Se&&i!==null&&Ge!==null&&i!==Ge&&M.isEmpty()&&(Se=!1,fe=!0),!Ye()&&fe&&me([]),u.hasAttribute("data-open")&&(Ke(),B.isOpen()&&Te());},destroy(){x.removeEventListener("click",xt),$.removeEventListener("click",Ct),U.removeEventListener("click",kt),u.removeEventListener("keydown",Et),l?.removeEventListener("resize",Tt),Le=null,he(null),oe.destroy(),O.destroy(),G.destroy(),B.destroy(),M.destroy();for(let i of P)Ve(i);P=[],Q.remove(),e.bar.setAttachmentCount(0),u.remove();},promptFill(i){return new Promise(p=>{he(null),e.onRequestClose(),oe.show(i,{onAnswer:f=>je(f)}),e.bar.setAwaitingInput?.(!0),i.kind==="password"?e.bar.setDisabled(!0):(e.bar.setPlaceholder(i.question),e.bar.focusInput()),ie={resolve:p,request:i};})},cancelFill(){he(null);},showFlowFailure(){ge(),M.addMessage("assistant",d().flowFailed),X();}}}catch{return null}}var Po={contract:4,mount:Fo};if(typeof window<"u")try{window[St]=Po;}catch{}
1291
+ `+Zt+Wt+pn,Fn="http://www.w3.org/2000/svg";function te(e,t,n=17){let r=e.createElementNS(Fn,"svg");r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true"),r.setAttribute("width",String(n)),r.setAttribute("height",String(n));for(let o of typeof t=="string"?[t]:t){let a=e.createElementNS(Fn,"path");a.setAttribute("d",o),a.setAttribute("fill","none"),a.setAttribute("stroke","currentColor"),a.setAttribute("stroke-width","2"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),r.appendChild(a);}return r}var _o="M12 21a9 9 0 100-18 9 9 0 000 18zM12 7v5l3 2",Pn="M13 3L5 14h6l-1 7 8-11h-6l1-7z",So="M6 9l6 6 6-6",Lo="M18 6L6 18M6 6l12 12",Io=["M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z","M9 12a3 3 0 1 0 6 0 3 3 0 1 0-6 0"],Ro=["M19 13V19H13","M5 5L19 19"],$n=["M5 8h10","M9 4v4","M12 20l4-9 4 9","M13.5 17h5","M13 8a10 10 0 0 1-8 8","M8 11a10 10 0 0 0 5 5"],Mo="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z";function Ue(e,t){let n=e.style,r=t.bar.getMetrics(),o=t.getMaxHeightPercent?.()??Ao,a=r.bottomOffset+r.keyboardOffset+r.height+8;if(n.setProperty("bottom",`${a}px`),n.setProperty("left","50%"),n.setProperty("translate","-50%"),n.setProperty("transform",xe(r.offset)),r.isMobile){e.setAttribute("data-sheet",""),n.setProperty("width",`calc(100% - ${24}px)`),n.setProperty("max-width","none"),n.setProperty("height",`calc(100% - ${a+12}px)`),n.setProperty("max-height","none");return}e.removeAttribute("data-sheet");let s=Oe(r.widthPercent,{width:r.viewportWidth,height:r.viewportHeight});n.setProperty("width",`${s}px`),n.setProperty("max-width",`calc(100vw - ${32}px)`),n.setProperty("transform",xe({x:De(r.offset.x,s,r.viewportWidth),y:r.offset.y}));let h=a-r.offset.y,C=un(o,r.viewportHeight,h);n.setProperty("height",`${C}px`),n.setProperty("max-height",`${C}px`);}function Fo(e){try{let ee=function(){try{for(;Q.firstChild;)Q.removeChild(Q.firstChild);Q.style.setProperty("display",P.length>0?"flex":"none");let i=d().removeImage;for(let p of P){let f=c.createElement("div");if(f.className=J,f.setAttribute("data-state",p.attachment?"ready":"uploading"),p.previewUrl){let _=c.createElement("img");_.src=p.previewUrl,_.alt="",f.appendChild(_);}let b=c.createElement("button");b.type="button",b.setAttribute("aria-label",i),b.setAttribute("data-tip",i),b.appendChild(te(c,Lo,12)),b.addEventListener("click",()=>{P=P.filter(_=>_!==p),bt(p),ee();}),f.appendChild(b),Q.appendChild(f);}e.bar.setAttachmentCount(P.length);}catch{}},vt=function(){e.setConversationId?.(null),M.clear(),yt(),X();},he=function(i){let p=ie;p&&(ie=null,oe.hide(),e.bar.setAwaitingInput?.(!1),e.bar.setDisabled(_e),e.bar.setPlaceholder(w()?.inputPlaceholder??null),p.resolve(i));},je=function(i){let p=ie;if(!p)return;let f=p.request,b=f.kind==="select"||f.kind==="radio"?gn(i,f.options):f.kind==="password"?i:i.trim(),_=mn(b,f);if(_!==null){oe.setError(_);return}he(b);},At=function(i){if(_e)return;let p=P.filter(f=>f.attachment!==null);P=P.filter(f=>f.attachment===null),ee(),M.addMessage("user",i,{images:p.length,imageUrls:p.map(f=>f.previewUrl).filter(f=>f!==null)}),X(),_e=!0,e.bar.setDisabled(!0),M.setPending(!0),wn({apiBase:e.apiBase??D,publicKey:e.publicKey??"",sessionId:e.getSessionId?.()??"",sessionToken:e.getSessionToken?.()??"",query:i,route:e.getRoute?.()??l?.location?.pathname??"",conversationId:e.getConversationId?.()??"",attachments:p.map(f=>({objectKey:f.attachment.objectKey}))}).then(f=>{let b=d();if(f.ok){M.addMessage("assistant",f.message,{messageId:f.messageId,citedSources:f.citedSources,flowOffers:f.flowsOffered}),e.touchConversation?.();for(let _ of f.flowsOffered)e.track?.("flow_suggested",{},{flowCvid:_.flowCvid});return}if(f.reason==="cap_denied"){ko.has(f.capReason)?e.onOrgCapExceeded?.():M.addMessage("system",b.userCapReached);return}M.addMessage("system",b.genericError);}).finally(()=>{_e=!1,M.setPending(!1),e.bar.setDisabled(!1);});},ge=function(){if(!u.hasAttribute("data-open")){Ke(),st(e.host,c,e.apiBase),e.bar.setMode("open"),Ue(u,e),u.setAttribute("data-open","");try{let i=e.isolated?e.root:c,p=e.isolated?i.activeElement:c.activeElement;Le=(e.isolated?p!==null:!!(p&&e.host.contains(p)))?null:c.activeElement,e.bar.focusInput();}catch{}}},Ke=function(){let i=w(),p=d();N(),W(),ie||e.bar.setPlaceholder(i?.inputPlaceholder??null),e.bar.setAttachEnabled(i?.allowImageUpload===!0),e.bar.setDisclaimer(j());for(let[f,b]of [[x,p.historyTitle],[A,p.flowsTitle],[$,p.settingsTitle],[U,p.collapse]])f.setAttribute("aria-label",b),f.setAttribute("data-tip",b);for(let f of [O,G,B])f.setTexts({backLabel:p.back,closeLabel:p.closeSheet});X();},_t=function(){if(u.hasAttribute("data-open")){u.removeAttribute("data-open"),O.close(),G.close(),B.close(),Z="root",e.bar.setMode("idle"),e.bar.setDisclaimer(null);try{let i=Le;Le=null;let p=u.getRootNode();(p instanceof ShadowRoot?p.activeElement:document.activeElement!==null&&document.activeElement!==document.body)&&i&&i.isConnected&&typeof i.focus=="function"&&i.focus();}catch{}}};var t=ee,n=vt,r=he,o=je,a=At,s=ge,h=Ke,C=_t;let g={host:e.host,root:e.root,isolated:e.isolated,destroy(){}};Xe(g,To),Xe(g,fn);let c=e.host.ownerDocument,l=c.defaultView,w=()=>{try{return e.getWidget?.()??null}catch{return null}},d=()=>w()?.chrome??Ft,u=c.createElement("div");u.className=de,u.setAttribute("role","dialog"),u.setAttribute("aria-label","ARCY chat"),u.tabIndex=-1,u.style.setProperty("position","absolute","important"),u.style.setProperty("pointer-events","auto","important"),u.style.setProperty("box-sizing","border-box");let v=c.createElement("div");v.className=dt;let m=(i,p,f)=>{let b=c.createElement("button");return b.type="button",b.className=ze,b.setAttribute("aria-label",i),b.setAttribute("data-tip",i),b.setAttribute("data-tip-placement","below"),b.setAttribute("data-tip-align",f),b.appendChild(te(c,p)),b},x=m(d().historyTitle,_o,"start"),A=m(d().flowsTitle,Pn,"start");A.style.setProperty("display","none");let E=c.createElement("div");E.className="arcy-chat-identity";let L=c.createElement("span"),H=c.createElement("span");H.className=On,E.appendChild(L),E.appendChild(H);let $=m(d().settingsTitle,Io,"end");e.bar.dock||$.style.setProperty("display","none");let U=m(d().collapse,So,"end");v.appendChild(x),v.appendChild(A),v.appendChild(E),v.appendChild($),v.appendChild(U);let N=()=>{let i=w(),p=at(i?.logoUrl,e.apiBase);if(H.textContent=p?"":i?.name??"",H.style.setProperty("display",p?"none":"block"),p&&L.getAttribute("data-src")===p)return;let f=p?c.createElement("img"):c.createElement("span");if(f.className=p?Nn:"",p){let b=f;b.alt=i?.name??"",b.decoding="async",b.onerror=()=>{try{let _=c.createElement("span");b.replaceWith(_),L=_,H.textContent=i?.name??"",H.style.setProperty("display","block");}catch{}},b.setAttribute("data-src",p),b.src=p;}L.replaceWith(f),L=f;},y=c.createElement("div");y.className=ne;let k=c.createElement("div");k.className=Dn;let T=c.createElement("a");T.className=Ae,T.href=Co,T.target="_blank",T.rel="noopener noreferrer";let I=c.createElement("span"),q=Ln(c);q&&q.setAttribute("class",ke),T.appendChild(I),q&&T.appendChild(q),k.appendChild(T);let W=()=>{let i=d();I.textContent=i.poweredBy.replace(/\s*ARCY\s*$/i,""),T.setAttribute("aria-label",i.poweredBy);},j=()=>{let i=w(),p=d(),f=i?.privacyPolicyUrl,b=i?.name?p.aiDisclaimer.replace("{app}",i.name):p.aiDisclaimer;if(typeof f=="string"&&/^https:\/\//i.test(f)){let _=p.consentWithPolicy.indexOf("{policy}"),Y=_>=0?p.consentWithPolicy.slice(0,_):`${p.consentWithPolicy} `,R=_>=0?p.consentWithPolicy.slice(_+8):"";return {before:`${b}${p.disclaimerJoin}${Y}`,linkLabel:p.privacyPolicy,linkHref:f,after:R}}return b},ue=c.createElement("div");ue.className=Bn,ue.appendChild(y),u.appendChild(v),u.appendChild(ue),u.appendChild(k),e.root.appendChild(u),st(e.host,c,e.apiBase),Ue(u,e);let M=en(y,c,{labels:{likeAnswer:d().likeAnswer,dislikeAnswer:d().dislikeAnswer},answeringLabel:()=>d().answering,searchedSourcesLabel:d().searchedSourcesLabel,sourcesLabel:d().sourcesLabel,flowOfferHint:()=>d().flowOfferHint,onStartFlow:i=>{e.track?.("flow_pill_clicked",{},{flowCvid:i}),e.onStartFlow?.(i);},onFeedback:(i,p)=>{e.track?.("answer_feedback",{},{value:i});let f=e.getSessionToken?.()??"",b=e.getConversationId?.()??"";!p||!f||!b||Sn({apiBase:e.apiBase,sessionToken:f,conversationId:b,messageId:p,value:i,visitorId:e.getVisitorId?.()??void 0});}}),z=c.createElement("div");z.className=re,y.insertBefore(z,y.firstChild);let ft=[],fe=!0,ht=null,X=()=>{try{for(;z.firstChild;)z.removeChild(z.firstChild);if(!M.isEmpty()){z.style.setProperty("display","none");return}z.style.setProperty("display","flex");let i=w(),p=c.createElement("div");p.className="arcy-chat-welcome-icon";let f=at(i?.welcomeIconUrl,e.apiBase);if(f&&f!==ht){let R=c.createElement("img");R.src=f,R.alt="",R.addEventListener("error",()=>{ht=f,X();},{once:!0}),p.appendChild(R);}else p.appendChild(te(c,Mo,18));z.appendChild(p);let b=i?.welcomeHeadline?.trim()??"",_=i?.welcomeMessage?.trim()??"";if(b){let R=c.createElement("div");R.className="arcy-chat-headline",R.textContent=b,z.appendChild(R);}if(_){let R=c.createElement("div");R.className="arcy-chat-greeting",R.textContent=_,z.appendChild(R);}let Y=c.createElement("div");Y.className=pt,fe&&Y.setAttribute("data-pending","");for(let R of ft){let K=c.createElement("button");K.type="button",K.className=pe,K.textContent=R.publicName,K.addEventListener("click",()=>{e.track?.("starter_flow_clicked",{},{flowCvid:R.cvid}),e.onStartFlow?.(R.cvid);}),Y.appendChild(K);}z.appendChild(Y);}catch{}},Q=c.createElement("div");Q.className=ut,Q.style.setProperty("display","none");let mt=e.bar.attachmentSlot?.()??null;mt?mt.appendChild(Q):y.insertBefore(Q,y.firstChild);let P=[],gt=In(c),Hn=gt.fetchImpl??(typeof fetch<"u"?fetch.bind(globalThis):null),Un=i=>{try{return l?.URL?.createObjectURL?.(i)??URL.createObjectURL(i)}catch{return null}},Ve=i=>{if(i.previewUrl){try{(l?.URL??URL).revokeObjectURL(i.previewUrl);}catch{}i.previewUrl=null;}},bt=i=>{Ve(i);let p=i.attachment?.objectKey;p&&Mn(p,{apiBase:e.apiBase,sessionToken:e.getSessionToken?.()??"",fetchImpl:Hn});},yt=()=>{let i=P;P=[];for(let p of i)bt(p);ee();},Ee=Promise.resolve(),wt=i=>{Ee=Ee.then(async()=>{for(let p of i){let f=e.getSessionToken?.()??"",b=K=>{let Ie=d();M.addMessage("system",K==="type"?Ie.imageWrongType:K==="size"?Ie.imageTooLarge:K==="count"?Ie.imageTooMany:Ie.imageFailed);},_=ct(p,P.length);if(!_.ok){b(_.reason),X();continue}let Y={previewUrl:Un(p),attachment:null};P=[...P,Y],ee();let R=await Rn(p,P.length-1,{apiBase:e.apiBase,sessionToken:f,env:gt});if(R.ok){Y.attachment=R.attachment,ee();continue}P=P.filter(K=>K!==Y),Ve(Y),ee(),b(R.reason),X();}}),Ee=Ee.catch(()=>{});},We=[],O=$e(u,c,{title:d().historyTitle,emptyText:d().historyEmpty,actionLabel:d().newChat,subtitleTips:!1,backLabel:d().back,closeLabel:d().closeSheet,onBack:()=>O.close(),onAction:()=>{vt(),O.close();},onSelect:i=>{if((e.getConversationId?.()??"")===i&&!M.isEmpty()){O.close();return}e.setConversationId?.(i),M.clear(),yt(),X(),O.close(),zn(i);}});async function zn(i){let p=e.getSessionToken?.()??"";if(!p)return;let f=await _n({apiBase:e.apiBase,sessionToken:p,conversationId:i,visitorId:e.getVisitorId?.()??void 0});if(f.ok&&(e.getConversationId?.()??"")===i){M.clear();for(let b of f.messages)M.addMessage(Tn(b.role),b.text,{images:b.images,at:b.occurredAt?new Date(b.occurredAt):void 0,messageId:b.id,feedback:b.feedback});X(),M.scrollToEnd();}}let G=$e(u,c,{title:d().flowsTitle,emptyText:d().flowsEmpty,actionLabel:null,backLabel:d().back,closeLabel:d().closeSheet,itemIcon:i=>te(i,Pn,16),onBack:()=>G.close(),onSelect:i=>{G.close(),e.onStartFlow?.(i);}}),Z="root",B=$e(u,c,{title:d().settingsTitle,side:"right",actionLabel:null,backLabel:d().back,closeLabel:d().closeSheet,onBack:()=>{if(Z==="language"){Z="root",Te();return}B.close();},onSelect:i=>{if(Z==="language"){B.close(),Z="root",e.onSelectLocale?.(i);return}if(i==="language"){Z="language",Te();return}i==="dock"&&(B.close(),e.onRequestClose(),e.bar.dock?.());}}),Vn=()=>{if(!e.onSelectLocale)return [];let i=w()?.locales??[];return i.length>=2?i:[]},Te=()=>{let i=d(),p=Vn();if(Z==="language"){B.setTitle(i.language),B.setItems(p.map(b=>({id:b.code,title:b.label,active:b.code===w()?.activeLocale,icon:_=>te(_,$n,16)})));return}B.setTitle(i.settingsTitle);let f=p.find(b=>b.code===w()?.activeLocale);B.setItems([...p.length?[{id:"language",title:i.language,subtitle:f?.label??null,icon:b=>te(b,$n,16)}]:[],{id:"dock",title:i.dockChat,subtitle:i.dockChatHint,icon:b=>te(b,Ro,16)}]);},xt=()=>{let i=d();O.setTitle(i.historyTitle),O.setTexts({emptyText:i.historyEmpty,actionLabel:i.newChat}),O.setItems(lt(We,i.imageConversation,e.getConversationId?.())),O.open(),Wn();};async function Wn(){let i=e.getSessionToken?.()??"",p=e.getVisitorId?.()??"";if(!i||!p)return;let f=await En({apiBase:e.apiBase,sessionToken:i,visitorId:p});f.ok&&(We=f.conversations,O.isOpen()&&O.setItems(lt(We,d().imageConversation,e.getConversationId?.())));}x.addEventListener("click",xt),A.addEventListener("click",()=>{let i=d();G.setTitle(i.flowsTitle),G.setTexts({emptyText:i.flowsEmpty}),G.open();});let Ct=()=>{Z="root",Te(),B.open();};$.addEventListener("click",Ct);let kt=()=>e.onRequestClose();U.addEventListener("click",kt);let oe=hn(e,()=>d()),ie=null,_e=!1;e.bar.onSubmit(i=>{if(ie){je(i);return}ge(),At(i);}),e.bar.onFiles?.(i=>{ge(),wt(i);});let jn=()=>w()?.allowImageUpload===!0,Gn=i=>{qe(i)&&i.preventDefault();},Yn=i=>{if(!qe(i)||(i.preventDefault(),!jn()))return;let p=Pt(i);p.length>0&&wt(p);};u.addEventListener("dragover",Gn),u.addEventListener("drop",Yn);let me=i=>{ft=i,fe=!1,X();},Se=!1,Ge=null,Ye=()=>{if(Se)return !0;let i=e.getSessionToken?.();return i?(Se=!0,Ge=w()?.audience||null,bn({apiBase:e.apiBase,sessionToken:i,sessionId:e.getSessionId?.()}).then(p=>{if(!p.ok){me([]);return}let f=yn(p.flows);me(p.starterFlows),f.length!==0&&(A.style.setProperty("display","flex"),G.setItems(f.map(b=>({id:b.cvid,title:b.publicName,subtitle:b.summary}))));}).catch(()=>{me([]);}),!0):!1};if(!Ye())try{l?.setTimeout(()=>{!Ye()&&fe&&me([]);},Eo);}catch{}let Et=i=>{if(i.key==="Escape"){if(i.stopPropagation(),O.isOpen()){O.close();return}if(G.isOpen()){G.close();return}if(B.isOpen()){B.close();return}e.onRequestClose();}};u.addEventListener("keydown",Et);let Tt=()=>{u.hasAttribute("data-open")&&Ue(u,e),oe.reposition();};l?.addEventListener("resize",Tt);let Le=null;return {open:ge,close:_t,reposition(){u.hasAttribute("data-open")&&Ue(u,e),oe.reposition();},refreshChrome(){let i=w()?.audience||null;Se&&i!==null&&Ge!==null&&i!==Ge&&M.isEmpty()&&(Se=!1,fe=!0),!Ye()&&fe&&me([]),u.hasAttribute("data-open")&&(Ke(),B.isOpen()&&Te());},destroy(){x.removeEventListener("click",xt),$.removeEventListener("click",Ct),U.removeEventListener("click",kt),u.removeEventListener("keydown",Et),l?.removeEventListener("resize",Tt),Le=null,he(null),oe.destroy(),O.destroy(),G.destroy(),B.destroy(),M.destroy();for(let i of P)Ve(i);P=[],Q.remove(),e.bar.setAttachmentCount(0),u.remove();},promptFill(i){return new Promise(p=>{he(null),e.onRequestClose(),oe.show(i,{onAnswer:f=>je(f)}),e.bar.setAwaitingInput?.(!0),i.kind==="password"?e.bar.setDisabled(!0):(e.bar.setPlaceholder(i.question),e.bar.focusInput()),ie={resolve:p,request:i};})},cancelFill(){he(null);},showFlowFailure(){ge(),M.addMessage("assistant",d().flowFailed),X();}}}catch{return null}}var Po={contract:4,mount:Fo};if(typeof window<"u")try{window[St]=Po;}catch{}
1292
1292
  exports.ARCY_HOME_URL=Co;exports.BODY_CLASS=ne;exports.CATALOG_RETRY_MS=Eo;exports.CHAT_CSS=To;exports.CHIPS_CLASS=ut;exports.CHIP_CLASS=J;exports.HEADER_BUTTON_CLASS=ze;exports.HEADER_CLASS=dt;exports.HEADER_ICON_CLASS=Nn;exports.HEADER_NAME_CLASS=On;exports.MAIN_CLASS=Bn;exports.MARK_CLASS=ke;exports.MARK_LINK_CLASS=Ae;exports.PANEL_CLASS=de;exports.POLICY_CLASS=Oi;exports.STARTER_CLASS=pe;exports.STARTER_ROW_CLASS=pt;exports.STRIP_CLASS=Dn;exports.WELCOME_CLASS=re;exports.mount=Fo;exports.resolveImageUrl=at;return exports;})({});
@@ -0,0 +1,3 @@
1
+ (function(){'use strict';/* arcy.js — https://arcyai.com */
2
+ function I(t){if(t.parentElement!==null)return t.parentElement;let e=t.parentNode;return e!==null&&"host"in e?e.host:null}function nt(t,e){let n=e;for(;n!==null;){if(n===t)return true;n=I(n);}return false}var rt=100;function S(t,e=0){let n=[],r=t.querySelectorAll("*");for(let o=0;o<r.length;o+=1){let i=r[o];n.push(i),i.shadowRoot!==null&&e<rt&&n.push(...S(i.shadowRoot,e+1));}return n}function H(t,e,n=0){let r=Array.from(t.querySelectorAll(e)),o=t.querySelectorAll("*");for(let i=0;i<o.length;i+=1){let s=o[i];s.shadowRoot!==null&&n<rt&&r.push(...H(s.shadowRoot,e,n+1));}return r}var ot=[/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,/\b\d{3}-\d{2}-\d{4}\b/g,/\b\d(?:[ -]?\d){12,18}\b/g],x="[masked]";function W(t){return ot.some(e=>(e.lastIndex=0,e.test(t)))}var V=4096,Lt=100,Nt=64;function k(t){if(!t)return;let e=t.slice(0,V);if(t.length>V){let r=e.search(/\s\S*$/);e=r===-1?e.slice(0,V-Lt):e.slice(0,r);}let n=e.replace(/\s+/g," ").trim();if(n){for(let r of ot)n=n.replace(r,x);return n.slice(0,80)}}function it(t){return !(t.length===0||t.length>64||t.includes(":")||t.startsWith("radix-")||/^\d+$/.test(t)||/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(t))}var Mt=new Set(["button","input","select","textarea","label","summary"]),Pt=new Set(["button","link","menuitem","tab","option"]);function R(t){let e=t.tagName.toLowerCase();if(Mt.has(e)||e==="a"&&t.hasAttribute("href"))return true;let n=t.getAttribute("role");if(n!==null&&Pt.has(n))return true;let r=t.getAttribute("contenteditable");return r===""||r==="true"}var Ot=["data-testid","data-test","data-cy","id","name","aria-label"],Dt=["data-testid","data-test","data-cy"],Ht=64;function Vt(t){for(let e of Dt){let n=t.getAttribute(e);if(n===null)continue;let r=n.trim();if(!(r===""||r.length>Ht)&&!W(r))return r}}var Wt=new Set(["navigation","main","banner","contentinfo","search","form","region","dialog"]);function Kt(t){let e=I(t);for(;e!==null;){let n=e.tagName.toLowerCase();if(n==="body"||n==="html")return;for(let o of Ot){let i=e.getAttribute(o);if(i===null||o==="id"&&!it(i))continue;let s=k(i);if(s!==void 0)return {tag:n,attr:o,value:s}}let r=e.getAttribute("role");if(r!==null&&Wt.has(r))return {tag:n,attr:"role",value:r};e=I(e);}}function $t(t){let e=0,n=t.previousElementSibling;for(;n!==null;)n.tagName===t.tagName&&(e+=1),n=n.previousElementSibling;return e}function C(t){let e={tag:t.tagName.toLowerCase(),siblingIndex:$t(t)},n=k(t.textContent);n!==void 0&&(e.text=n);let r=k(t.getAttribute("aria-label"));r!==void 0&&(e.ariaLabel=r);let o=k(t.getAttribute("placeholder"));o!==void 0&&(e.placeholder=o);let i=t.getAttribute("id");i!==null&&it(i)&&!W(i)&&(e.id=i);let s=t.getAttribute("role");if(s!==null){let u=s.trim();u!==""&&u.length<=Nt&&!W(u)&&(e.role=u);}let l=Vt(t);l!==void 0&&(e.testId=l);let a=Kt(t);return a!==void 0&&(e.ancestorTag=a.tag,e.ancestorAttr=a.attr,e.ancestorValue=a.value),e}function jt(t){return t.getClientRects().length>0}var Bt=50,Ut=40,Gt=10,Xt=15,Jt=15,Yt=10,zt=10,qt=10,Zt=5,Qt=5,te=.6,ee=.7,ne={1:.3,2:.45,3:.6,4:.75,5:.9};function A(t){return t.split(x).join(" ").replace(/\s+/g," ").trim()}function re(t,e){if(e===void 0)return 0;let n=A(t),r=A(e);return n===""||r===""?0:r===n?1:r.includes(n)||n.includes(r)?te:0}function T(t,e){return e===t?1:0}function K(t){return t.includes(x)&&A(t)===""}function oe(t,e,n){let r=0,o=0,i=(s,l)=>{r+=s,o+=s*l;};if(t.testId!==void 0&&i(Bt,T(t.testId,e.testId)),t.text!==void 0&&A(t.text)!==""&&i(n?Gt:Ut,re(t.text,e.text)),t.ariaLabel!==void 0&&!K(t.ariaLabel)&&i(Xt,T(t.ariaLabel,e.ariaLabel)),t.placeholder!==void 0&&!K(t.placeholder)&&i(zt,T(t.placeholder,e.placeholder)),t.id!==void 0&&i(Jt,T(t.id,e.id)),t.role!==void 0&&i(Zt,T(t.role,e.role)),i(Yt,e.tag===t.tag?1:0),i(Qt,e.siblingIndex===t.siblingIndex?1:0),t.ancestorAttr!==void 0&&t.ancestorValue!==void 0&&!K(t.ancestorValue)){let s=0;e.ancestorAttr===t.ancestorAttr&&e.ancestorValue===t.ancestorValue&&(s=e.ancestorTag===t.ancestorTag?1:ee),i(qt,s);}return r===0?0:o/r}function ie(t,e){if(t.selector===null)return null;try{return H(e,t.selector)}catch{return null}}function se(t,e){let n=t.core.tag,r=[];for(let o of S(e))(o.tagName.toLowerCase()===n||R(o))&&r.push(o);return r}function st(t,e){if(e.length===0)return {status:"not_found",reason:"no_candidates",matchCount:0};let n=ne[t.precision],r=false,o=[];for(let s of e){if(!jt(s))continue;r=true;let l=oe(t.core,C(s),t.dynamicText);l>=n&&o.push({element:s,score:l});}if(o=o.filter((s,l)=>{let a=o[l+1];return a===void 0?true:!(nt(s.element,a.element)&&s.score<=a.score)}),o.length===0)return {status:"not_found",reason:r?"below_threshold":"not_visible",matchCount:0};let i=t.ordinal>=1?o[t.ordinal-1]:void 0;return i===void 0?{status:"not_found",reason:"ordinal_out_of_range",matchCount:o.length}:{status:"matched",element:i.element,score:i.score,matchCount:o.length}}function g(t,e){try{let n=ie(t,e);if(n!==null&&n.length>0){let r=st(t,n);if(r.status==="matched"||r.reason==="ordinal_out_of_range")return r}return st(t,se(t,e))}catch{return {status:"not_found",reason:"error",matchCount:0}}}var le=40;function lt(t=document){try{let e=S(t),n=[];for(let r of e){if(n.length>=le)break;R(r)&&n.push(C(r));}return n}catch{return []}}var $={getItem:()=>null,setItem:()=>{},removeItem:()=>{}};function y(t){return t?{getItem(e){try{return t.getItem(e)}catch{return null}},setItem(e,n){try{t.setItem(e,n);}catch{}},removeItem(e){try{t.removeItem(e);}catch{}}}:$}function at(){try{let t=globalThis.localStorage;return y(t)}catch{return $}}function ut(){try{let t=globalThis.sessionStorage;return y(t)}catch{return $}}function L(t,e){let n=t.getItem(e);if(!n)return null;try{let r=JSON.parse(n);return !r||typeof r!="object"||Array.isArray(r)?null:r}catch{return null}}function N(t,e,n){try{t.setItem(e,JSON.stringify(n));}catch{}}var ae=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;function j(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;if(e&&typeof e.randomUUID=="function")try{let o=e.randomUUID();if(ae.test(o))return o}catch{}let n=new Uint8Array(16);if(e&&typeof e.getRandomValues=="function")e.getRandomValues(n);else for(let o=0;o<n.length;o++)n[o]=Math.floor(Math.random()*256);n[6]=(n[6]??0)&15|64,n[8]=(n[8]??0)&63|128;let r="";for(let o=0;o<n.length;o++)r+=(n[o]??0).toString(16).padStart(2,"0");return `${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`}var ue=3,ce=["attribute","current_page","element","text_input","user_fills_input","current_time","user_idle","visitor","always_true","group"];function v(t){if(!t||typeof t!="object")return false;let e=t;return e.v===1&&!!e.core&&typeof e.core=="object"&&typeof e.core.tag=="string"&&(e.selector===null||typeof e.selector=="string")&&typeof e.ordinal=="number"&&typeof e.precision=="number"}function ht(t,e){if(e>ue||!t||typeof t!="object")return null;let n=t,r=n.type;if(typeof r!="string"||!ce.includes(r))return null;switch(r){case "attribute":return typeof n.codeName!="string"||typeof n.operator!="string"?null:{type:"attribute",codeName:n.codeName,operator:n.operator,value:n.value};case "current_page":return !Array.isArray(n.matches)||!Array.isArray(n.doesNotMatch)?null:{type:"current_page",matches:n.matches.filter(o=>typeof o=="string"),doesNotMatch:n.doesNotMatch.filter(o=>typeof o=="string")};case "element":return !v(n.target)||typeof n.state!="string"?null:{type:"element",target:n.target,state:n.state};case "text_input":return !v(n.target)||typeof n.operator!="string"||typeof n.value!="string"?null:{type:"text_input",target:n.target,operator:n.operator,value:n.value};case "user_fills_input":return v(n.target)?{type:"user_fills_input",target:n.target}:null;case "current_time":{let o=n.from,i=n.to;return o!==null&&typeof o!="string"||i!==null&&typeof i!="string"?null:{type:"current_time",from:o??null,to:i??null}}case "user_idle":{let o=n.seconds;return typeof o!="number"||!Number.isFinite(o)||o<1||o>600?null:{type:"user_idle",seconds:o}}case "visitor":return n.state!=="first_visit"&&n.state!=="returning"?null:{type:"visitor",state:n.state};case "always_true":return {type:"always_true"};case "group":{if(!Array.isArray(n.children)||n.operator!=="and"&&n.operator!=="or")return null;let o=[];for(let i of n.children){let s=ht(i,e+1);s&&o.push(s);}return {type:"group",operator:n.operator,children:o}}default:return null}}function gt(t){if(!t||typeof t!="object")return null;let e=t;if(e.v!==1)return null;let n=ht(e.node,0);return n?{v:1,node:n}:null}function ct(t){let e=/^(\d{2}):(\d{2})$/.exec(t);if(!e)return null;let n=Number(e[1]),r=Number(e[2]);return n>23||r>59?null:n*60+r}function de(t,e){if(t.from===null&&t.to===null)return true;let n=e.getHours()*60+e.getMinutes(),r=t.from!==null?ct(t.from):null,o=t.to!==null?ct(t.to):null;return t.from!==null&&r===null||t.to!==null&&o===null?false:r!==null&&o===null?n>=r:r===null&&o!==null?n<=o:r!==null&&o!==null?r<=o?n>=r&&n<=o:n>=r||n<=o:true}function B(t,e){let n=t.split("*").map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");try{return new RegExp(`^${n}$`).test(e)}catch{return false}}function fe(t,e){return t.doesNotMatch.some(n=>B(n,e))?false:t.matches.length===0?true:t.matches.some(n=>B(n,e))}var pe=/^\d{4}-\d{2}-\d{2}/;function dt(t){if(!pe.test(t))return null;let e=new Date(t).getTime();return Number.isFinite(e)?e:null}function me(t,e){if(t.trim()===""||e.trim()==="")return null;let n=Number(t),r=Number(e);if(Number.isFinite(n)&&Number.isFinite(r))return n-r;let o=dt(t),i=dt(e);return o!==null&&i!==null?o-i:null}function wt(t,e,n){if(e===void 0)return false;switch(t){case "is":return e===n;case "is_not":return e!==n;case "contains":return e.includes(n);case "does_not_contain":return !e.includes(n);case "starts_with":return e.startsWith(n);case "ends_with":return e.endsWith(n);case "is_empty":return e==="";case "is_not_empty":return e!=="";case "greater_than":case "less_than":{let r=me(e,n);return r===null?false:t==="greater_than"?r>0:r<0}case "matches_pattern":return B(n,e);default:return false}}function ft(t,e){try{if(t.getClientRects().length===0)return !1}catch{return false}try{let n=e.defaultView?.getComputedStyle(t);if(n&&n.visibility==="hidden")return !1}catch{}return true}function pt(t,e){try{let n=e.activeElement;for(;n;){if(n===t||t.contains(n))return !0;n=n.shadowRoot?.activeElement??null;}}catch{}return false}function he(t,e){let n=g(t.target,e.doc);switch(t.state){case "is_present":return n.status==="matched";case "is_not_present":return n.status==="not_found";case "is_disabled":case "is_not_disabled":{if(n.status!=="matched")return false;let r="disabled"in n.element&&n.element.disabled===true;return t.state==="is_disabled"?r:!r}case "is_clicked":return e.wasClicked(t.target);case "is_not_clicked":return !e.wasClicked(t.target);case "is_visible":return n.status==="matched"&&ft(n.element,e.doc);case "is_not_visible":return n.status!=="matched"||!ft(n.element,e.doc);case "is_checked":case "is_not_checked":{if(n.status!=="matched")return false;let r="checked"in n.element&&n.element.checked===true;return t.state==="is_checked"?r:!r}case "is_focused":return n.status==="matched"&&pt(n.element,e.doc);case "is_not_focused":return n.status!=="matched"||!pt(n.element,e.doc);default:return false}}function mt(t){return t==null||t===""?true:Array.isArray(t)?t.length===0:typeof t=="object"?Object.keys(t).length===0:false}function ge(t,e){let n=e.getTrait?.(t.codeName);switch(t.operator){case "has_any_value":return !mt(n);case "is_empty":return mt(n);}if(n===void 0||typeof n=="object")return false;let r=String(n),o=t.value===void 0?"":String(t.value);return wt(t.operator,r,o)}function M(t,e){switch(t.type){case "always_true":return true;case "current_time":return de(t,e.now());case "current_page":return fe(t,e.href());case "element":return he(t,e);case "attribute":return ge(t,e);case "text_input":{let n=e.readInputValue(t.target);return wt(t.operator,n,t.value)}case "user_fills_input":{let n=e.readInputValue(t.target),r=e.initialInputValue(t.target);return n!==void 0&&n!==""&&n!==r}case "user_idle":{let n=e.idleSeconds?.();return n!==void 0&&n>=t.seconds}case "visitor":{let n=e.isFirstVisit?.();return n===void 0?false:t.state==="first_visit"?n:!n}case "group":return t.children.length===0?false:t.operator==="and"?t.children.every(n=>M(n,e)):t.children.some(n=>M(n,e));default:return false}}function U(t){return t.type==="current_time"||t.type==="user_idle"?true:t.type==="group"?t.children.some(U):false}function G(t){return t.type==="user_idle"?true:t.type==="group"?t.children.some(G):false}var we="https://api.arcyai.com";var ye="/api/v1/sdk/flows";function ve(t){return t!==void 0?t:typeof fetch<"u"?fetch.bind(globalThis):null}function be(t,e,n,r){return new Promise(o=>{let i=false,s=l=>{i||(i=true,o(l));};t.then(s,()=>s(r));try{n(()=>s(r),e);}catch{}})}function Se(t){return !t||typeof t!="object"||Array.isArray(t)?null:P(t.flow)}function P(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t;return typeof e.cvid!="string"||!Array.isArray(e.steps)?null:t}function Te(t){return {"Content-Type":"application/json",Authorization:`Bearer ${t}`}}async function yt(t,e){let{apiBase:n=we,sessionToken:r,sessionId:o,setTimeoutImpl:i=(u,p)=>setTimeout(u,p),timeoutMs:s=8e3}=e,l=ve(e.fetchImpl);if(!l)return {ok:false,reason:"unusable"};let a=(async()=>{let u;try{u=await l(`${n}${ye}/${encodeURIComponent(t)}/run`,{method:"POST",headers:Te(r),body:JSON.stringify(o?{sessionId:o}:{}),credentials:"omit"});}catch{return {ok:false,reason:"network"}}if(u.status===404)return {ok:false,reason:"not_found"};if(!u.ok)return {ok:false,reason:"rejected"};let p;try{p=await u.json();}catch{return {ok:false,reason:"unusable"}}let f=Se(p);return f?{ok:true,flow:f}:{ok:false,reason:"unusable"}})();return be(a,s,i,{ok:false,reason:"network"})}var Ee="arcy.flow.";function _e(t){return typeof t.flowId=="string"&&t.flowId.length>0&&typeof t.currentStepCvid=="string"&&t.currentStepCvid.length>0&&typeof t.flowSessionId=="string"&&t.flowSessionId.length>0&&typeof t.startedAt=="number"}function vt(t,{store:e=at()}={}){let n=y(e),r=Ee+t;return {read(){let o=L(n,r);return !o||!_e(o)?null:{flowId:o.flowId,currentStepCvid:o.currentStepCvid,flowSessionId:o.flowSessionId,startedAt:o.startedAt}},save(o){N(n,r,o);},clear(){n.removeItem(r);}}}var Fe="arcy.preview.";function Ie(t){return typeof t.flowId=="string"&&t.flowId.length>0&&typeof t.currentStepCvid=="string"&&t.currentStepCvid.length>0&&typeof t.flowSessionId=="string"&&t.flowSessionId.length>0&&typeof t.startedAt=="number"&&t.flow!==void 0&&t.flow!==null}function X(t,{store:e=ut()}={}){let n=y(e),r=Fe+t;return {read(){let o=L(n,r);return !o||!Ie(o)?null:o},save(o){N(n,r,o);},clear(){n.removeItem(r);}}}var ke=250,xe=15e3,Re=1e3,Ce=["pointerdown","pointermove","keydown","wheel","scroll","touchstart"],J=250,Ae=3e3,Le=250,Y=()=>{},Ne=()=>Promise.resolve({status:"wait"});function z(t,e){return t.steps.findIndex(n=>n.cvid===e)}function St(t){return t?t.type==="element"?[t.target]:t.type==="group"?t.children.flatMap(e=>St(e)):[]:[]}var q=class{constructor(e,n,r,o,i,s,l,a,u,p,f,w,h,D,b,d){this.flow=e;this.stepIndex=n;this.startedAt=r;this.flowSessionId=o;this.doc=i;this.win=s;this.runState=l;this.executor=a;this.getTrait=u;this.isFirstVisit=p;this.track=f;this.now=w;this.setTimeoutImpl=h;this.clearTimeoutImpl=D;this.setIntervalImpl=b;this.clearIntervalImpl=d;this.stopped=false;this.dwellTimer=null;this.observer=null;this.intervalHandle=null;this.throttleHandle=null;this.lastCheck=0;this.trueSince=new Map;this.clicked=new Set;this.initialValues=new Map;this.clickListener=null;this.lastActivityAt=0;this.activityListeners=[];this.inputPending=false;this.actionPending=false;this.inputListeners=[];this.parsedTriggers=new Map;this.lastStopReason=null;this.onStatus=null;this.onFailure=null;this.onCancelFill=null;}resolveElement(e,n=0){return g(e,this.doc)}waitForElement(e){let n=()=>{let l=g(e,this.doc),a=l.status==="matched"&&l.element.isConnected;return {result:l,found:a}},r=n(),o=Math.max(0,this.flow.waitSeconds*1e3);if(r.found||o===0)return Promise.resolve(r.result);let i=this.stepIndex,s=this.now()+o;return new Promise(l=>{let a=()=>{let u=n();if(u.found||this.stopped||this.stepIndex!==i||this.now()>=s){l(u.result);return}this.setTimeoutImpl(a,J);};this.setTimeoutImpl(a,J);})}conditionContext(){return {doc:this.doc,now:()=>new Date(this.now()),href:()=>this.win.location?.href??"",getTrait:this.getTrait,idleSeconds:()=>Math.max(0,(this.now()-this.lastActivityAt)/1e3),isFirstVisit:this.isFirstVisit,wasClicked:e=>this.clicked.has(e),readInputValue:e=>{let n=g(e,this.doc);if(n.status!=="matched")return;let r=n.element;return typeof r.value=="string"?r.value:void 0},initialInputValue:e=>{if(!this.initialValues.has(e)){let n=g(e,this.doc),r=n.status==="matched"?n.element:null;this.initialValues.set(e,r&&typeof r.value=="string"?r.value:void 0);}return this.initialValues.get(e)}}}currentStep(){return this.flow.steps[this.stepIndex]}persist(){let e=this.currentStep();e&&this.runState.save({flowId:this.flow.cvid,currentStepCvid:e.cvid,flowSessionId:this.flowSessionId,startedAt:this.startedAt});}teardownWatch(){if(this.observer?.disconnect(),this.observer=null,this.intervalHandle!==null&&(this.clearIntervalImpl(this.intervalHandle),this.intervalHandle=null),this.throttleHandle!==null&&(this.clearTimeoutImpl(this.throttleHandle),this.throttleHandle=null),this.dwellTimer!==null&&(this.clearTimeoutImpl(this.dwellTimer),this.dwellTimer=null),this.clickListener){try{this.doc.removeEventListener("click",this.clickListener,!0);}catch{}this.clickListener=null;}for(let[e,n]of this.inputListeners)try{this.doc.removeEventListener(e,n,!0);}catch{}this.inputListeners=[];for(let[e,n]of this.activityListeners)try{this.doc.removeEventListener(e,n,!0);}catch{}this.activityListeners=[],this.inputPending=false,this.actionPending=false,this.trueSince.clear(),this.clicked.clear(),this.initialValues.clear();}jumpTo(e){let n=z(this.flow,e);if(n===-1){this.finish("error",{reason:"step_not_found"});return}this.stopStep(),this.stepIndex=n,this.persist(),this.enterStep();}emitStatus(e){try{this.onStatus?.(e);}catch{}}dismiss(){this.stopped||this.finish("dismissed");}emit(e,n){try{this.track(e,{flowId:this.flow.cvid,flowSessionId:this.flowSessionId,stepCvid:this.currentStep()?.cvid},n);}catch{}}finish(e,n){this.lastStopReason=e;let r=e==="completed"?"flow_completed":e==="dismissed"?"flow_abandoned":"flow_error";this.emit(r,n);try{this.onCancelFill?.();}catch{}if(this.stopStep(),this.stopped=true,this.runState.clear(),e==="completed"&&this.emitStatus({name:this.flow.publicName??this.flow.name,step:this.flow.steps.length,total:this.flow.steps.length,phase:"done"}),this.emitStatus(null),e==="error")try{this.onFailure?.();}catch{}}stopStep(){this.teardownWatch();}fireTrigger(e){if(e.actionType==="dismiss_flow"){this.finish("dismissed");return}e.actionType==="go_to_step"&&e.targetStepCvid&&this.jumpTo(e.targetStepCvid);}parsedTrigger(e){return this.parsedTriggers.has(e.cvid)||this.parsedTriggers.set(e.cvid,gt(e.condition)),this.parsedTriggers.get(e.cvid)??null}checkTriggers(e,n){if(this.stopped)return;let r=!this.inputPending&&!this.actionPending,o=this.now();for(let i of [...e.triggers].sort((s,l)=>s.position-l.position)){let s=this.parsedTrigger(i);if(!s)continue;let l=M(s.node,n),a=i.cvid;if(!l){this.trueSince.delete(a);continue}let u=this.trueSince.get(a)??o;this.trueSince.has(a)||this.trueSince.set(a,u);let p=(i.waitSeconds??0)*1e3;if(o-u>=p&&r){this.fireTrigger(i);return}}}scheduleCheck(e){if(this.stopped||this.throttleHandle!==null)return;let n=Math.max(0,ke-(this.now()-this.lastCheck));this.throttleHandle=this.setTimeoutImpl(()=>{this.throttleHandle=null,this.lastCheck=this.now(),this.checkTriggers(e,this.conditionContext());},n);}startWatch(e){let n=e.triggers.some(o=>{let i=this.parsedTrigger(o);return i?U(i.node):false}),r=e.triggers.some(o=>{let i=this.parsedTrigger(o);return i?G(i.node):false});if(this.lastActivityAt=this.now(),typeof MutationObserver=="function")try{this.observer=new MutationObserver(()=>this.scheduleCheck(e)),this.observer.observe(this.doc.documentElement,{childList:!0,subtree:!0,attributes:!0,characterData:!0});}catch{}if(n)try{this.intervalHandle=this.setIntervalImpl(()=>this.scheduleCheck(e),r?Re:xe);}catch{}if(r)for(let o of Ce){let i=()=>{this.lastActivityAt=this.now();};try{this.doc.addEventListener(o,i,{capture:!0,passive:!0}),this.activityListeners.push([o,i]);}catch{}}this.clickListener=o=>{for(let i of e.triggers){let s=this.parsedTrigger(i),l=St(s?.node);for(let a of l){let u=g(a,this.doc);u.status==="matched"&&o.target instanceof Node&&(u.element===o.target||u.element.contains(o.target))&&this.clicked.add(a);}}this.scheduleCheck(e);};try{this.doc.addEventListener("click",this.clickListener,!0);}catch{this.clickListener=null;}for(let o of ["input","change","focusin","focusout"]){let i=()=>this.scheduleCheck(e);try{this.doc.addEventListener(o,i,!0),this.inputListeners.push([o,i]);}catch{}}this.checkTriggers(e,this.conditionContext());}async runExecutor(e,n){try{let r=await this.executor(e,{doc:this.doc,win:this.win,resolveElement:(o,i)=>this.resolveElement(o,i),waitForElement:o=>this.waitForElement(o),setInputPending:o=>{this.inputPending=o;}});if(this.stopped||this.stepIndex!==n)return;if(this.actionPending=!1,r.status==="advance"){if(this.emit("flow_step_completed"),e.isCompletion){this.finish("completed");return}let o=this.stepIndex+1;if(o>=this.flow.steps.length){this.finish("completed");return}this.stopStep(),this.stepIndex=o,this.persist(),this.enterStep();return}if(r.status==="navigated"){if(this.emit("flow_step_completed"),r.navigateTarget==="new_tab"){this.finish("completed");return}if(this.stopStep(),e.isCompletion){this.finish("completed");return}let o=this.stepIndex+1;if(o>=this.flow.steps.length){this.finish("completed");return}this.stepIndex=o,this.persist();return}if(r.status==="error"){this.finish("error",r.reason==="element_not_found"?{reason:r.reason,liveManifest:lt(this.doc)}:{reason:r.reason});return}this.scheduleCheck(e);}catch{this.actionPending=false;}}enterStep(){let e=this.currentStep(),n=this.stepIndex;if(!e||this.stopped){this.finish(e?"completed":"error",e?void 0:{reason:"missing_step"});return}this.persist(),this.emit("flow_step_entered"),this.emitStatus({name:this.flow.publicName??this.flow.name,step:this.stepIndex+1,total:this.flow.steps.length,phase:"running"});let r=()=>{this.stopped||(this.actionPending=true,this.startWatch(e),this.runExecutor(e,n));};this.waitForPageReady(r);}waitForPageReady(e){let n=this.now()+Ae,r=()=>{this.dwellTimer=this.setTimeoutImpl(()=>{this.dwellTimer=null,e();},Le);},o=()=>{if(!this.stopped){if(this.doc.readyState!=="loading"||this.now()>=n){r();return}this.dwellTimer=this.setTimeoutImpl(()=>{this.dwellTimer=null,o();},J);}};o();}begin(){this.enterStep();}stop(){if(!this.stopped){try{this.onCancelFill?.();}catch{}this.stopStep(),this.stopped=true;}}};function Tt(t){let{context:e,executor:n=Ne,track:r=e.track??Y,now:o=()=>Date.now(),setTimeoutImpl:i=(d,c)=>setTimeout(d,c),clearTimeoutImpl:s=d=>clearTimeout(d),setIntervalImpl:l=(d,c)=>setInterval(d,c),clearIntervalImpl:a=d=>clearInterval(d)}=t,u=e.doc??document,p=e.win??window,f=vt(e.token),w={apiBase:e.apiBase,sessionToken:e.sessionToken,sessionId:e.sessionId},h=null;async function D(d){let c=await yt(d,w);return c.ok?c.flow:null}function b(d,c,m,F,et={}){h?.stop(),h=new q(d,c,m,F,u,p,et.runState??f,n,e.getTrait,e.isFirstVisit,et.track??r,o,i,s,l,a),h.onStatus=At=>e.onStatus?.(At),h.onFailure=()=>e.onFailure?.(),h.onCancelFill=()=>e.cancelFill?.(),h.begin();}return {async start(d){let c=await D(d);if(!c||c.steps.length===0)return;let m=j();try{r("flow_started",{flowId:c.cvid,flowSessionId:m});}catch{}b(c,0,o(),m);},async resume(){let d=f.read();if(!d)return false;let c=await D(d.flowId);if(!c||c.steps.length===0)return f.clear(),false;let m=z(c,d.currentStepCvid);return m===-1?(f.clear(),false):(b(c,m,d.startedAt,d.flowSessionId),true)},stop(){h?.dismiss(),h=null;},async startPreview(d){let c=P(d);if(!c||c.steps.length===0)return;let m=X(e.token);b(c,0,o(),j(),{runState:bt(m,d),track:Y});},async resumePreview(){let d=X(e.token),c=d.read();if(!c)return false;let m=P(c.flow);if(!m||m.steps.length===0)return d.clear(),false;let F=z(m,c.currentStepCvid);return F===-1?(d.clear(),false):(b(m,F,c.startedAt,c.flowSessionId,{runState:bt(d,c.flow),track:Y}),true)},destroy(){h?.stop(),h=null;}}}function bt(t,e){return {read:()=>null,save:n=>t.save({...n,flow:e}),clear:()=>t.clear()}}var Me=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Pe=/^\d{4}-\d{2}-\d{2}$/,Oe=/^([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/,De=/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/,He=/^\d{4}-\d{2}$/,Ve=/^\d{4}-W\d{2}$/,We=/^\+?[\d\s().-]{3,}$/;function Ke(t){let e=Date.parse(t);return Number.isFinite(e)}function $e(t,e){if(e.min!==null){let n=Number(e.min);if(Number.isFinite(n)&&t<n)return "number_too_small"}if(e.max!==null){let n=Number(e.max);if(Number.isFinite(n)&&t>n)return "number_too_large"}return null}function Z(t){return /^\d:/.test(t)?`0${t}`:t}function E(t,e){return e.min!==null&&e.min.length>0&&t<e.min?"date_too_early":e.max!==null&&e.max.length>0&&t>e.max?"date_too_late":null}function Et(t,e){let n=e.kind==="password"?t:t.trim();if(n.length===0)return e.required?"required":null;if(e.maxLength!==null&&n.length>e.maxLength)return "too_long";switch(e.kind){case "number":case "range":{let r=Number(n);return Number.isFinite(r)?$e(r,e):"invalid_number"}case "email":return Me.test(n)?null:"invalid_email";case "url":try{let r=new URL(n);return r.protocol==="http:"||r.protocol==="https:"?null:"invalid_url"}catch{return "invalid_url"}case "tel":return We.test(n)?null:"invalid";case "date":return !Pe.test(n)||!Ke(n)?"invalid_date":E(n,e);case "datetime":return De.test(n)?E(n,e):"invalid_date";case "month":return He.test(n)?E(n,e):"invalid_date";case "week":return Ve.test(n)?E(n,e):"invalid_date";case "time":return Oe.test(n)?E(Z(n),{...e,min:e.min!==null?Z(e.min):null,max:e.max!==null?Z(e.max):null}):"invalid_time";case "select":case "radio":return (e.options??[]).some(o=>o.value===n)?null:"invalid_option";case "checkbox":return n==="true"||n==="false"?null:"invalid_option";default:{if(e.pattern)try{if(!new RegExp(`^(?:${e.pattern})$`).test(n))return "invalid"}catch{}return null}}}function _t(t,e){if(!e||e.length===0)return t;let n=t.trim();if(e.some(i=>i.value===n))return n;let r=n.toLowerCase(),o=e.find(i=>i.label.trim().toLowerCase()===r);return o?o.value:t}var Q=24;function je(t,e,n){let r=e-Math.max(0,n);if(!(e>0)||r<=0)return 0;if(t.bottom>r){let o=t.bottom-r+Q,i=Math.max(0,t.top-Q);return Math.min(o,i)}return t.top<0?t.top-Q:0}function kt(t,e,n){try{let r=n.getBottomOcclusion?.()??0,o=t.getBoundingClientRect(),i=e.doc.documentElement?.clientHeight||e.win.innerHeight||0,s=je(o,i,r);if(s===0)return;e.win.scrollBy({top:s,behavior:"smooth"});}catch{}}function tt(t,e){let r=e.defaultView?.PointerEvent,o=(()=>{try{return t.getBoundingClientRect()}catch{return null}})(),i={bubbles:true,cancelable:true,clientX:o?o.left+o.width/2:0,clientY:o?o.top+o.height/2:0},s=a=>{try{typeof r=="function"&&t.dispatchEvent(new r(a,{...i,pointerType:"mouse"}));}catch{}},l=a=>{try{t.dispatchEvent(new MouseEvent(a,i));}catch{}};s("pointerover"),s("pointerenter"),s("pointerdown"),l("mousedown");try{typeof t.focus=="function"&&t.focus();}catch{}s("pointerup"),l("mouseup"),l("click");}function Be(t,e){let n=t instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:t instanceof HTMLInputElement?HTMLInputElement.prototype:t instanceof HTMLSelectElement?HTMLSelectElement.prototype:null;if(!n)return false;let o=Object.getOwnPropertyDescriptor(n,"value")?.set;if(!o)return false;try{return o.call(t,e),!0}catch{return false}}function O(t,e){let n=e.defaultView;try{t.dispatchEvent(new(n?.Event??Event)("input",{bubbles:!0}));}catch{}try{t.dispatchEvent(new(n?.Event??Event)("change",{bubbles:!0}));}catch{}}async function Ue(t,e,n){if(!v(t.target))return {status:"error",reason:"invalid_target"};let r=await e.waitForElement(t.target);if(r.status!=="matched"||!r.element.isConnected)return {status:"error",reason:"element_not_found"};kt(r.element,e,n);try{tt(r.element,e.doc);}catch{return {status:"error",reason:"dispatch_failed"}}return {status:"advance"}}var Ge=["text","number","email","date","url","tel"];function Ft(t){return Ge.includes(t)?t:null}var Xe={text:"text",search:"text",number:"number",email:"email",url:"url",tel:"tel",password:"password",date:"date",time:"time","datetime-local":"datetime",month:"month",week:"week",checkbox:"checkbox",radio:"radio",range:"range"};function _(t,e){try{let n=t.getAttribute(e);return n===null||n===""?null:n}catch{return null}}function Je(t){let e=[];for(let n=0;n<t.options.length;n+=1){let r=t.options[n];if(!r||r.disabled)continue;let o=(r.label||r.textContent||"").trim();r.value!==""&&e.push({value:r.value,label:o||r.value});}return e}function Ye(t,e){let n=t.getAttribute("name"),r=t.form??e,o=[];if(n)try{let i=`input[type="radio"][name="${CSS.escape(n)}"]`;r.querySelectorAll(i).forEach(s=>{s instanceof HTMLInputElement&&o.push(s);});}catch{}return o.length===0&&o.push(t),o.map(i=>({value:i.value,label:ze(i)||i.value}))}function xt(t){try{let e=t.labels;if(e&&e.length>0)return (e[0]?.textContent??"").trim()}catch{}try{let e=t.closest("label");if(e)return (e.textContent??"").trim()}catch{}return ""}function ze(t){return xt(t)}function It(t,e,n){let r="custom",o=null,i=false,s=null,l=null,a=null,u=null,p=null;if(t instanceof HTMLSelectElement)r="select",o=Je(t),i=t.required||!t.querySelector('option[value=""]');else if(t instanceof HTMLTextAreaElement)r="textarea",i=t.required,t.maxLength>0&&(u=t.maxLength);else if(t instanceof HTMLInputElement){let f=(_(t,"type")??"text").toLowerCase();r=Xe[f]??"text",i=t.required,s=_(t,"min"),l=_(t,"max"),a=_(t,"step"),p=_(t,"pattern"),t.maxLength>0&&(u=t.maxLength),r==="radio"&&(o=Ye(t,n)),r==="checkbox"&&(o=[{value:"true",label:xt(t)}]);}return e&&e!=="text"&&(r==="text"||r==="custom"||r==="textarea")&&(r=e),{kind:r,required:i,options:o,min:s,max:l,step:a,maxLength:u,pattern:p}}function qe(t){if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLElement&&t.isContentEditable)return t;try{let e=t.querySelector('input:not([type="hidden"]), textarea, select, [contenteditable="true"], [contenteditable=""]');return e instanceof HTMLElement?e:null}catch{return null}}function Ze(t,e){let r=e.defaultView?.KeyboardEvent;if(typeof r=="function")for(let o of ["keydown","keyup"])try{t.dispatchEvent(new r(o,{bubbles:!0,cancelable:!0}));}catch{}}function Qe(t,e,n,r){if(n==="checkbox"&&t instanceof HTMLInputElement){let i=e==="true";return t.checked!==i&&tt(t,r),t.checked!==i&&(t.checked=i,O(t,r)),true}if(n==="radio"&&t instanceof HTMLInputElement){let i=t.form??r,s=t.getAttribute("name"),l=null;if(s)try{let p=`input[type="radio"][name="${CSS.escape(s)}"]`;i.querySelectorAll(p).forEach(f=>{f instanceof HTMLInputElement&&f.value===e&&(l=f);});}catch{}let a=l??(t.value===e?t:null);if(!a)return false;tt(a,r);let u=a;return u.checked||(u.checked=true,O(u,r)),true}let o=qe(t);if(!o)return false;if(o instanceof HTMLElement&&o.isContentEditable){try{o.focus();}catch{}try{o.textContent=e;}catch{return false}return O(o,r),true}try{o.focus();}catch{}return Be(o,e)?(Ze(o,r),O(o,r),true):false}async function tn(t,e,n){if(!v(t.target))return {status:"error",reason:"invalid_target"};if(!n.promptFill)return {status:"wait"};let r=await e.waitForElement(t.target);if(r.status!=="matched"||!r.element.isConnected)return {status:"error",reason:"element_not_found"};let o=It(r.element,Ft(t.fillInputType),e.doc),i=(t.fillDescription??"").trim()||t.label||"",s=null,l=null,a;for(;;){let f;e.setInputPending(true);try{f=await n.promptFill({...o,question:i,errorCode:s});}catch{return {status:"error",reason:"prompt_failed"}}finally{e.setInputPending(false);}if(f===null)return {status:"error",reason:"fill_cancelled"};let w=o.kind==="select"||o.kind==="radio"?_t(f,o.options):o.kind==="password"?f:f.trim();if(s=Et(w,{...o,question:i,errorCode:null}),s===null){a=w;break}if(l!==null&&l===w)return {status:"error",reason:"fill_invalid"};l=w;}let u=await e.waitForElement(t.target);if(u.status!=="matched"||!u.element.isConnected)return {status:"error",reason:"element_not_found"};let p=It(u.element,Ft(t.fillInputType),e.doc);return p.kind!==o.kind?{status:"error",reason:"unfillable_target"}:(kt(u.element,e,n),Qe(u.element,a,p.kind,e.doc)?{status:"advance"}:{status:"error",reason:"unfillable_target"})}function en(t){if(t.startsWith("/")&&!t.startsWith("//"))return true;try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return false}}async function nn(t,e){if(!t.navigateUrl||!t.navigateTarget)return {status:"error",reason:"invalid_navigate_step"};if(!en(t.navigateUrl))return {status:"error",reason:"invalid_navigate_step"};try{t.navigateTarget==="new_tab"?e.win.open(t.navigateUrl,"_blank","noopener,noreferrer"):e.win.location.assign(t.navigateUrl);}catch{return {status:"error",reason:"navigate_failed"}}return {status:"navigated",navigateTarget:t.navigateTarget}}function Rt(t={}){return async(e,n)=>{try{switch(e.type){case "click":return await Ue(e,n,t);case "fill":return await tn(e,n,t);case "navigate":return await nn(e,n);default:return {status:"error",reason:"unknown_step_type"}}}catch{return {status:"error",reason:"executor_threw"}}}}var Ct="__arcyFlow";function on(t){try{let e=Rt({promptFill:t.promptFill,getBottomOcclusion:t.getBottomOcclusion});return Tt({context:t,executor:e})}catch{return null}}var sn={contract:2,mount:on};if(typeof window<"u")try{window[Ct]=sn;}catch{}
3
+ })();