@sciol/xyzen 1.9.88-beta.01fba8a → 1.9.88-beta.fb40704

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/xyzen.es.js CHANGED
@@ -113277,7 +113277,7 @@ function Mra({
113277
113277
  ),
113278
113278
  children: [
113279
113279
  /* @__PURE__ */ A.jsx(VYe, { children: /* @__PURE__ */ A.jsx(ZYe, { className: "text-lg font-bold text-neutral-900 dark:text-neutral-100", children: r }) }),
113280
- /* @__PURE__ */ A.jsxs("div", { className: "flex items-start gap-4", children: [
113280
+ /* @__PURE__ */ A.jsxs("div", { className: "custom-scrollbar flex max-h-[60vh] items-start gap-4 overflow-y-auto", children: [
113281
113281
  /* @__PURE__ */ A.jsx("div", { className: "flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30", children: /* @__PURE__ */ A.jsx(
113282
113282
  km,
113283
113283
  {
@@ -113285,7 +113285,7 @@ function Mra({
113285
113285
  "aria-hidden": "true"
113286
113286
  }
113287
113287
  ) }),
113288
- /* @__PURE__ */ A.jsx(XYe, { className: "text-sm text-neutral-600 dark:text-neutral-400", children: i })
113288
+ /* @__PURE__ */ A.jsx(XYe, { className: "whitespace-pre-line text-sm text-neutral-600 dark:text-neutral-400", children: i })
113289
113289
  ] }),
113290
113290
  /* @__PURE__ */ A.jsxs(KYe, { children: [
113291
113291
  /* @__PURE__ */ A.jsx(
package/dist/xyzen.umd.js CHANGED
@@ -572,7 +572,7 @@ const partysocket = new PartySocket({
572
572
  WebSocket: WS
573
573
  });
574
574
 
575
- `),iNt=!0);const o=this._options.WebSocket||WebSocket;this._debug("connect",{url:r,protocols:i}),this._ws=i?new o(r,i):new o(r),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),n)}).catch(r=>{this._connectLock=!1,this._handleError(new zNe.ErrorEvent(Error(r.message),this))})}_handleTimeout(){this._debug("timeout event"),this._handleError(new zNe.ErrorEvent(Error("TIMEOUT"),this))}_disconnect(e=1e3,n){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{(this._ws.readyState===this.OPEN||this._ws.readyState===this.CONNECTING)&&this._ws.close(e,n),this._handleClose(new zNe.CloseEvent(e,n,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_handleOpen=e=>{this._debug("open event");const{minUptime:n=HR.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),n),lOr(this._ws,"WebSocket is not defined"),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(r=>{this._ws?.send(r)}),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent($oe(e))};_handleMessage=e=>{this._debug("message event"),this.onmessage&&this.onmessage(e),this.dispatchEvent($oe(e))};_handleError=e=>{this._debug("error event",e.message),this._disconnect(void 0,e.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(e),this._debug("exec error listeners"),this.dispatchEvent($oe(e)),this._connect()};_handleClose=e=>{this._debug("close event"),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent($oe(e))};_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};const rk=Object.create(null);rk.open="0",rk.close="1",rk.ping="2",rk.pong="3",rk.message="4",rk.upgrade="5",rk.noop="6";const joe=Object.create(null);Object.keys(rk).forEach(t=>{joe[rk[t]]=t});const UNe={type:"error",data:"parser error"},sNt=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",oNt=typeof ArrayBuffer=="function",lNt=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,qNe=({type:t,data:e},n,r)=>sNt&&e instanceof Blob?n?r(e):cNt(e,r):oNt&&(e instanceof ArrayBuffer||lNt(e))?n?r(e):cNt(new Blob([e]),r):r(rk[t]+(e||"")),cNt=(t,e)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];e("b"+(r||""))},n.readAsDataURL(t)};function uNt(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let GNe;function gOr(t,e){if(sNt&&t.data instanceof Blob)return t.data.arrayBuffer().then(uNt).then(e);if(oNt&&(t.data instanceof ArrayBuffer||lNt(t.data)))return e(uNt(t.data));qNe(t,!1,n=>{GNe||(GNe=new TextEncoder),e(GNe.encode(n))})}const dNt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Yq=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let t=0;t<dNt.length;t++)Yq[dNt.charCodeAt(t)]=t;const hOr=t=>{let e=t.length*.75,n=t.length,r,i=0,o,l,u,d;t[t.length-1]==="="&&(e--,t[t.length-2]==="="&&e--);const p=new ArrayBuffer(e),m=new Uint8Array(p);for(r=0;r<n;r+=4)o=Yq[t.charCodeAt(r)],l=Yq[t.charCodeAt(r+1)],u=Yq[t.charCodeAt(r+2)],d=Yq[t.charCodeAt(r+3)],m[i++]=o<<2|l>>4,m[i++]=(l&15)<<4|u>>2,m[i++]=(u&3)<<6|d&63;return p},fOr=typeof ArrayBuffer=="function",HNe=(t,e)=>{if(typeof t!="string")return{type:"message",data:pNt(t,e)};const n=t.charAt(0);return n==="b"?{type:"message",data:AOr(t.substring(1),e)}:joe[n]?t.length>1?{type:joe[n],data:t.substring(1)}:{type:joe[n]}:UNe},AOr=(t,e)=>{if(fOr){const n=hOr(t);return pNt(n,e)}else return{base64:!0,data:t}},pNt=(t,e)=>e==="blob"?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,mNt="",bOr=(t,e)=>{const n=t.length,r=new Array(n);let i=0;t.forEach((o,l)=>{qNe(o,!1,u=>{r[l]=u,++i===n&&e(r.join(mNt))})})},yOr=(t,e)=>{const n=t.split(mNt),r=[];for(let i=0;i<n.length;i++){const o=HNe(n[i],e);if(r.push(o),o.type==="error")break}return r};function vOr(){return new TransformStream({transform(t,e){gOr(t,n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const o=new DataView(i.buffer);o.setUint8(0,126),o.setUint16(1,r)}else{i=new Uint8Array(9);const o=new DataView(i.buffer);o.setUint8(0,127),o.setBigUint64(1,BigInt(r))}t.data&&typeof t.data!="string"&&(i[0]|=128),e.enqueue(i),e.enqueue(n)})}})}let WNe;function zoe(t){return t.reduce((e,n)=>e+n.length,0)}function Uoe(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let r=0;for(let i=0;i<e;i++)n[i]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),n}function _Or(t,e){WNe||(WNe=new TextDecoder);const n=[];let r=0,i=-1,o=!1;return new TransformStream({transform(l,u){for(n.push(l);;){if(r===0){if(zoe(n)<1)break;const d=Uoe(n,1);o=(d[0]&128)===128,i=d[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(zoe(n)<2)break;const d=Uoe(n,2);i=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),r=3}else if(r===2){if(zoe(n)<8)break;const d=Uoe(n,8),p=new DataView(d.buffer,d.byteOffset,d.length),m=p.getUint32(0);if(m>Math.pow(2,21)-1){u.enqueue(UNe);break}i=m*Math.pow(2,32)+p.getUint32(4),r=3}else{if(zoe(n)<i)break;const d=Uoe(n,i);u.enqueue(HNe(o?d:WNe.decode(d),e)),r=0}if(i===0||i>t){u.enqueue(UNe);break}}}})}const gNt=4;function pp(t){if(t)return wOr(t)}function wOr(t){for(var e in pp.prototype)t[e]=pp.prototype[e];return t}pp.prototype.on=pp.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},pp.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},pp.prototype.off=pp.prototype.removeListener=pp.prototype.removeAllListeners=pp.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+t];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+t],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===e||r.fn===e){n.splice(i,1);break}return n.length===0&&delete this._callbacks["$"+t],this},pp.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,e)}return this},pp.prototype.emitReserved=pp.prototype.emit,pp.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},pp.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Ey=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function hNt(t,...e){return e.reduce((n,r)=>(t.hasOwnProperty(r)&&(n[r]=t[r]),n),{})}const xOr=Ey.setTimeout,kOr=Ey.clearTimeout;function qoe(t,e){e.useNativeTimers?(t.setTimeoutFn=xOr.bind(Ey),t.clearTimeoutFn=kOr.bind(Ey)):(t.setTimeoutFn=Ey.setTimeout.bind(Ey),t.clearTimeoutFn=Ey.clearTimeout.bind(Ey))}const EOr=1.33;function COr(t){return typeof t=="string"?SOr(t):Math.ceil((t.byteLength||t.size)*EOr)}function SOr(t){let e=0,n=0;for(let r=0,i=t.length;r<i;r++)e=t.charCodeAt(r),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(r++,n+=4);return n}function IOr(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}function TOr(t){let e={},n=t.split("&");for(let r=0,i=n.length;r<i;r++){let o=n[r].split("=");e[decodeURIComponent(o[0])]=decodeURIComponent(o[1])}return e}class BOr extends Error{constructor(e,n,r){super(e),this.description=n,this.context=r,this.type="TransportError"}}class YNe extends pp{constructor(e){super(),this.writable=!1,qoe(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,n,r){return super.emitReserved("error",new BOr(e,n,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const n=HNe(e,this.socket.binaryType);this.onPacket(n)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,n={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(n)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const n=IOr(e);return n.length?"?"+n:""}}const fNt="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),VNe=64,DOr={};let ANt=0,Goe=0,bNt;function yNt(t){let e="";do e=fNt[t%VNe]+e,t=Math.floor(t/VNe);while(t>0);return e}function vNt(){const t=yNt(+new Date);return t!==bNt?(ANt=0,bNt=t):t+"."+yNt(ANt++)}for(;Goe<VNe;Goe++)DOr[fNt[Goe]]=Goe;let _Nt=!1;try{_Nt=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const NOr=_Nt;function wNt(t){const e=t.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||NOr))return new XMLHttpRequest}catch{}if(!e)try{return new Ey[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function w0s(){}function ROr(){}const LOr=(function(){return new wNt({xdomain:!1}).responseType!=null})();class MOr extends YNe{constructor(e){if(super(e),this.polling=!1,typeof location<"u"){const r=location.protocol==="https:";let i=location.port;i||(i=r?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||i!==e.port}const n=e&&e.forceBase64;this.supportsBinary=LOr&&!n,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const n=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};yOr(e,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,bOr(e,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=vNt()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(e,n)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new nF(this.uri(),e)}doWrite(e,n){const r=this.request({method:"POST",data:e});r.on("success",n),r.on("error",(i,o)=>{this.onError("xhr post error",i,o)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=e}}let nF=class wxe extends pp{constructor(e,n){super(),qoe(this,n),this.opts=n,this.method=n.method||"GET",this.uri=e,this.data=n.data!==void 0?n.data:null,this.create()}create(){var e;const n=hNt(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new wNt(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(e=this.opts.cookieJar)===null||e===void 0||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=wxe.requestsCount++,wxe.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=ROr,e)try{this.xhr.abort()}catch{}typeof document<"u"&&delete wxe.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};if(nF.requestsCount=0,nF.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",xNt);else if(typeof addEventListener=="function"){const t="onpagehide"in Ey?"pagehide":"unload";addEventListener(t,xNt,!1)}}function xNt(){for(let t in nF.requests)nF.requests.hasOwnProperty(t)&&nF.requests[t].abort()}const KNe=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,n)=>n(e,0),Hoe=Ey.WebSocket||Ey.MozWebSocket,kNt=!0,POr="arraybuffer",ENt=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class OOr extends YNe{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),n=this.opts.protocols,r=ENt?{}:hNt(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=kNt&&!ENt?n?new Hoe(e,n):new Hoe(e):new Hoe(e,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;qNe(r,this.supportsBinary,o=>{const l={};try{kNt&&this.ws.send(o)}catch{}i&&KNe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=vNt()),this.supportsBinary||(n.b64=1),this.createUri(e,n)}check(){return!!Hoe}}class FOr extends YNe{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(e=>{const n=_Or(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(n).getReader(),i=vOr();i.readable.pipeTo(e.writable),this.writer=i.writable.getWriter();const o=()=>{r.read().then(({done:u,value:d})=>{u||(this.onPacket(d),o())}).catch(u=>{})};o();const l={type:"open"};this.query.sid&&(l.data=`{"sid":"${this.query.sid}"}`),this.writer.write(l).then(()=>this.onOpen())})}))}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;this.writer.write(r).then(()=>{i&&KNe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const QOr={websocket:OOr,webtransport:FOr,polling:MOr},$Or=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,jOr=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ZNe(t){if(t.length>2e3)throw"URI too long";const e=t,n=t.indexOf("["),r=t.indexOf("]");n!=-1&&r!=-1&&(t=t.substring(0,n)+t.substring(n,r).replace(/:/g,";")+t.substring(r,t.length));let i=$Or.exec(t||""),o={},l=14;for(;l--;)o[jOr[l]]=i[l]||"";return n!=-1&&r!=-1&&(o.source=e,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=zOr(o,o.path),o.queryKey=UOr(o,o.query),o}function zOr(t,e){const n=/\/{2,9}/g,r=e.replace(n,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&r.splice(0,1),e.slice(-1)=="/"&&r.splice(r.length-1,1),r}function UOr(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,o){i&&(n[i]=o)}),n}let CNt=class N7 extends pp{constructor(e,n={}){super(),this.binaryType=POr,this.writeBuffer=[],e&&typeof e=="object"&&(n=e,e=null),e?(e=ZNe(e),n.hostname=e.host,n.secure=e.protocol==="https"||e.protocol==="wss",n.port=e.port,e.query&&(n.query=e.query)):n.host&&(n.hostname=ZNe(n.host).host),qoe(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=TOr(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const n=Object.assign({},this.opts.query);n.EIO=gNt,n.transport=e,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new QOr[e](r)}open(){let e;if(this.opts.rememberUpgrade&&N7.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)e="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else e=this.transports[0];this.readyState="opening";try{e=this.createTransport(e)}catch{this.transports.shift(),this.open();return}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(e){let n=this.createTransport(e),r=!1;N7.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",g=>{if(!r)if(g.type==="pong"&&g.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;N7.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(m(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const h=new Error("probe error");h.transport=n.name,this.emitReserved("upgradeError",h)}}))};function o(){r||(r=!0,m(),n.close(),n=null)}const l=g=>{const h=new Error("probe error: "+g);h.transport=n.name,o(),this.emitReserved("upgradeError",h)};function u(){l("transport closed")}function d(){l("socket closed")}function p(g){n&&g.name!==n.name&&o()}const m=()=>{n.removeListener("open",i),n.removeListener("error",l),n.removeListener("close",u),this.off("close",d),this.off("upgrading",p)};n.once("open",i),n.once("error",l),n.once("close",u),this.once("close",d),this.once("upgrading",p),this.upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",N7.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let e=0;const n=this.upgrades.length;for(;e<n;e++)this.probe(this.upgrades[e])}}onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const n=new Error("server error");n.code=e.data,this.onError(n);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r<this.writeBuffer.length;r++){const i=this.writeBuffer[r].data;if(i&&(n+=COr(i)),r>0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(e,n,r){return this.sendPacket("message",e,n,r),this}send(e,n,r){return this.sendPacket("message",e,n,r),this}sendPacket(e,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const o={type:e,data:n,options:r};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),i&&this.once("flush",i),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),e()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():e()}):this.upgrading?r():e()),this}onError(e){N7.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const n=[];let r=0;const i=e.length;for(;r<i;r++)~this.transports.indexOf(e[r])&&n.push(e[r]);return n}};CNt.protocol=gNt;function qOr(t,e="",n){let r=t;n=n||typeof location<"u"&&location,t==null&&(t=n.protocol+"//"+n.host),typeof t=="string"&&(t.charAt(0)==="/"&&(t.charAt(1)==="/"?t=n.protocol+t:t=n.host+t),/^(https?|wss?):\/\//.test(t)||(typeof n<"u"?t=n.protocol+"//"+t:t="https://"+t),r=ZNe(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const o=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+o+":"+r.port+e,r.href=r.protocol+"://"+o+(n&&n.port===r.port?"":":"+r.port),r}const GOr=typeof ArrayBuffer=="function",HOr=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,SNt=Object.prototype.toString,WOr=typeof Blob=="function"||typeof Blob<"u"&&SNt.call(Blob)==="[object BlobConstructor]",YOr=typeof File=="function"||typeof File<"u"&&SNt.call(File)==="[object FileConstructor]";function XNe(t){return GOr&&(t instanceof ArrayBuffer||HOr(t))||WOr&&t instanceof Blob||YOr&&t instanceof File}function Woe(t,e){if(!t||typeof t!="object")return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(Woe(t[n]))return!0;return!1}if(XNe(t))return!0;if(t.toJSON&&typeof t.toJSON=="function"&&arguments.length===1)return Woe(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&Woe(t[n]))return!0;return!1}function VOr(t){const e=[],n=t.data,r=t;return r.data=JNe(n,e),r.attachments=e.length,{packet:r,buffers:e}}function JNe(t,e){if(!t)return t;if(XNe(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}else if(Array.isArray(t)){const n=new Array(t.length);for(let r=0;r<t.length;r++)n[r]=JNe(t[r],e);return n}else if(typeof t=="object"&&!(t instanceof Date)){const n={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=JNe(t[r],e));return n}return t}function KOr(t,e){return t.data=eRe(t.data,e),delete t.attachments,t}function eRe(t,e){if(!t)return t;if(t&&t._placeholder===!0){if(typeof t.num=="number"&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}else if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=eRe(t[n],e);else if(typeof t=="object")for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=eRe(t[n],e));return t}const ZOr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Oo;(function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"})(Oo||(Oo={}));class XOr{constructor(e){this.replacer=e}encode(e){return(e.type===Oo.EVENT||e.type===Oo.ACK)&&Woe(e)?this.encodeAsBinary({type:e.type===Oo.EVENT?Oo.BINARY_EVENT:Oo.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let n=""+e.type;return(e.type===Oo.BINARY_EVENT||e.type===Oo.BINARY_ACK)&&(n+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(n+=e.nsp+","),e.id!=null&&(n+=e.id),e.data!=null&&(n+=JSON.stringify(e.data,this.replacer)),n}encodeAsBinary(e){const n=VOr(e),r=this.encodeAsString(n.packet),i=n.buffers;return i.unshift(r),i}}class tRe extends pp{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e=="function"?{reviver:e}:e)}add(e){let n;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");n=this.decodeString(e);const r=n.type===Oo.BINARY_EVENT;r||n.type===Oo.BINARY_ACK?(n.type=r?Oo.EVENT:Oo.ACK,this.reconstructor=new JOr(n),n.attachments===0&&super.emitReserved("decoded",n)):super.emitReserved("decoded",n)}else if(XNe(e)||e.base64)if(this.reconstructor)n=this.reconstructor.takeBinaryData(e),n&&(this.reconstructor=null,super.emitReserved("decoded",n));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let n=0;const r={type:Number(e.charAt(0))};if(Oo[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===Oo.BINARY_EVENT||r.type===Oo.BINARY_ACK){const o=n+1;for(;e.charAt(++n)!=="-"&&n!=e.length;);const l=e.substring(o,n);if(l!=Number(l)||e.charAt(n)!=="-")throw new Error("Illegal attachments");const u=Number(l);if(!eFr(u)||u<0)throw new Error("Illegal attachments");if(u>this.opts.maxAttachments)throw new Error("too many attachments");r.attachments=u}if(e.charAt(n+1)==="/"){const o=n+1;for(;++n&&!(e.charAt(n)===","||n===e.length););r.nsp=e.substring(o,n)}else r.nsp="/";const i=e.charAt(n+1);if(i!==""&&Number(i)==i){const o=n+1;for(;++n;){const l=e.charAt(n);if(l==null||Number(l)!=l){--n;break}if(n===e.length)break}r.id=Number(e.substring(o,n+1))}if(e.charAt(++n)){const o=this.tryParse(e.substr(n));if(tRe.isPayloadValid(r.type,o))r.data=o;else throw new Error("invalid payload")}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,n){switch(e){case Oo.CONNECT:return INt(n);case Oo.DISCONNECT:return n===void 0;case Oo.CONNECT_ERROR:return typeof n=="string"||INt(n);case Oo.EVENT:case Oo.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&ZOr.indexOf(n[0])===-1);case Oo.ACK:case Oo.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class JOr{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const n=KOr(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const eFr=Number.isInteger||function(t){return typeof t=="number"&&isFinite(t)&&Math.floor(t)===t};function INt(t){return Object.prototype.toString.call(t)==="[object Object]"}const tFr=Object.freeze(Object.defineProperty({__proto__:null,Decoder:tRe,Encoder:XOr,get PacketType(){return Oo}},Symbol.toStringTag,{value:"Module"}));function S_(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const nFr=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});let TNt=class extends pp{constructor(e,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[S_(e,"open",this.onopen.bind(this)),S_(e,"packet",this.onpacket.bind(this)),S_(e,"error",this.onerror.bind(this)),S_(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...n){if(nFr.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(n.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;const r={type:Oo.EVENT,data:n};if(r.options={},r.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){const l=this.ids++,u=n.pop();this._registerAckCallback(l,u),r.id=l}const i=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!i||!this.connected)||(this.connected?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(e,n){var r;const i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[e]=n;return}const o=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let l=0;l<this.sendBuffer.length;l++)this.sendBuffer[l].id===e&&this.sendBuffer.splice(l,1);n.call(this,new Error("operation has timed out"))},i);this.acks[e]=(...l)=>{this.io.clearTimeoutFn(o),n.apply(this,[null,...l])}}emitWithAck(e,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,o)=>{n.push((l,u)=>r?l?o(l):i(u):i(l)),this.emit(e,...n)})}_addToQueue(e){let n;typeof e[e.length-1]=="function"&&(n=e.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((i,...o)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...o)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!e||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:Oo.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,n)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case Oo.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Oo.EVENT:case Oo.BINARY_EVENT:this.onevent(e);break;case Oo.ACK:case Oo.BINARY_ACK:this.onack(e);break;case Oo.DISCONNECT:this.ondisconnect();break;case Oo.CONNECT_ERROR:this.destroy();const r=new Error(e.data.message);r.data=e.data.data,this.emitReserved("connect_error",r);break}}onevent(e){const n=e.data||[];e.id!=null&&n.push(this.ack(e.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:Oo.ACK,id:e,data:i}))}}onack(e){const n=this.acks[e.id];typeof n=="function"&&(n.apply(this,e.data),delete this.acks[e.id])}onconnect(e,n){this.id=e,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Oo.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const n=this._anyListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const n=this._anyOutgoingListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const n=this._anyOutgoingListeners.slice();for(const r of n)r.apply(this,e.data)}}};function rF(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}rF.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=(Math.floor(e*10)&1)==0?t-n:t+n}return Math.min(t,this.max)|0},rF.prototype.reset=function(){this.attempts=0},rF.prototype.setMin=function(t){this.ms=t},rF.prototype.setMax=function(t){this.max=t},rF.prototype.setJitter=function(t){this.jitter=t};class nRe extends pp{constructor(e,n){var r;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(n=e,e=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,qoe(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new rF({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=e;const i=n.parser||tFr;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var n;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(n=this.backoff)===null||n===void 0||n.setMin(e),this)}randomizationFactor(e){var n;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(n=this.backoff)===null||n===void 0||n.setJitter(e),this)}reconnectionDelayMax(e){var n;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(n=this.backoff)===null||n===void 0||n.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new CNt(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=S_(n,"open",function(){r.onopen(),e&&e()}),o=u=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",u),e?e(u):this.maybeReconnectOnOpen()},l=S_(n,"error",o);if(this._timeout!==!1){const u=this._timeout,d=this.setTimeoutFn(()=>{i(),o(new Error("timeout")),n.close()},u);this.opts.autoUnref&&d.unref(),this.subs.push(()=>{this.clearTimeoutFn(d)})}return this.subs.push(i),this.subs.push(l),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(S_(e,"ping",this.onping.bind(this)),S_(e,"data",this.ondata.bind(this)),S_(e,"error",this.onerror.bind(this)),S_(e,"close",this.onclose.bind(this)),S_(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(n){this.onclose("parse error",n)}}ondecoded(e){KNe(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,n){let r=this.nsps[e];return r?this._autoConnect&&!r.active&&r.connect():(r=new TNt(this,e,n),this.nsps[e]=r),r}_destroy(e){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(e){const n=this.encoder.encode(e);for(let r=0;r<n.length;r++)this.engine.write(n[r],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(i=>{i?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",i)):e.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const Vq={};function Yoe(t,e){typeof t=="object"&&(e=t,t=void 0),e=e||{};const n=qOr(t,e.path||"/socket.io"),r=n.source,i=n.id,o=n.path,l=Vq[i]&&o in Vq[i].nsps,u=e.forceNew||e["force new connection"]||e.multiplex===!1||l;let d;return u?d=new nRe(r,e):(Vq[i]||(Vq[i]=new nRe(r,e)),d=Vq[i]),n.query&&!e.query&&(e.query=n.queryKey),d.socket(n.path,e)}Object.assign(Yoe,{Manager:nRe,Socket:TNt,io:Yoe,connect:Yoe});var BNt=(t,e)=>t===e?!0:!t||!e||t.length!==e.length?!1:t.every((n,r)=>n===e[r]),rRe=(t,e)=>BNt(t,e)||!t&&e?.length===0||t?.length===0&&!e,rFr=(t,e)=>{const n=Array.isArray(t)?t:t?[t]:[],r=Array.isArray(e)?e:e?[e]:[];return BNt(n,r)},DNt=(t,e)=>{if(!t&&!e)return!0;if(!t||!e)return!1;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return!1}},Voe=(t,e)=>DNt(t.data,e.data)&&rRe(t.tags,e.tags)&&t.read===e.read&&t.archived===e.archived&&t.snoozed===e.snoozed&&t.seen===e.seen&&rFr(t.severity,e.severity);function aFr(t,e){return!e||Object.keys(e).length===0?!0:t?Object.entries(e).every(([n,r])=>{const i=t[n];if(i===void 0&&r!==void 0)return!1;if(Array.isArray(r))if(Array.isArray(i)){if(r.length!==i.length)return!1;const o=[...r].sort(),l=[...i].sort();return o.every((u,d)=>u===l[d])}else return r.includes(i);else return i===r}):!1}function iFr(t,e){return!e||e.length===0?!0:!t||t.length===0?!1:e.some(n=>t.includes(n))}function sFr(t,e){return!(e.read!==void 0&&t.isRead!==e.read||e.seen!==void 0&&t.isSeen!==e.seen||e.archived!==void 0&&t.isArchived!==e.archived||e.snoozed!==void 0&&t.isSnoozed!==e.snoozed)}function oFr(t,e){return sFr(t,e)&&iFr(t.tags,e.tags)&&aFr(t.data,e.data)}var gT,hT,WR,YR,Kq,Zq=class{constructor(t,e,n,r,i){qa(this,gT),qa(this,hT),qa(this,WR),qa(this,YR),qa(this,Kq,!1);var o;di(this,gT,e),di(this,hT,n),di(this,WR,r),di(this,YR,i),this.id=t.id,this.identifier=t.identifier,this.topicKey=t.topicKey,this.preferences=(o=t.preferences)==null?void 0:o.map(l=>new Xq(fi({},l),tn(this,gT),tn(this,hT),tn(this,WR),tn(this,YR)))}update(t){return Rr(this,null,function*(){return NNt({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:wc(fi({},t),{subscription:this})})})}updatePreference(t){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot update a deleted subscription",new Error("Subscription is stale"))}:RNt({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:wc(fi({},t),{subscriptionId:this.identifier})})})}bulkUpdatePreferences(t){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot bulk update a deleted subscription",new Error("Subscription is stale"))}:dFr({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:t.map(e=>wc(fi({},e),{subscriptionId:this.identifier}))})})}delete(){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot delete an already deleted subscription",new Error("Subscription is stale"))}:LNt({emitter:tn(this,gT),apiService:tn(this,hT),args:{subscription:this}})})}};gT=new WeakMap,hT=new WeakMap,WR=new WeakMap,YR=new WeakMap,Kq=new WeakMap;var lFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,options:i,args:o}){try{const{useCache:l,refetch:u}=i;let d=l&&!u?r.getAll(o):void 0;return e.emit("subscriptions.list.pending",{args:o,data:d}),(!d||u)&&(d=(yield n.fetchSubscriptions(o.topicKey)).map(m=>new Zq(wc(fi({},m),{topicKey:o.topicKey}),e,n,r,l)),l&&(r.set(o,d),d=r.getAll(o))),e.emit("subscriptions.list.resolved",{args:o,data:d}),{data:d}}catch(l){return e.emit("subscriptions.list.resolved",{args:o,error:l}),{error:new go("Failed to fetch subscriptions",l)}}}),cFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,options:i,args:o}){try{const{useCache:l,refetch:u}=i;let d=l&&!u?r.get(o):void 0;if(e.emit("subscription.get.pending",{args:o,data:d}),!d||u){const p=yield n.getSubscription(o.topicKey,o.identifier,o.workflowIds,o.tags);if(!p)return e.emit("subscription.get.resolved",{args:o,data:null}),{data:null};d=new Zq(wc(fi({},p),{topicKey:o.topicKey}),e,n,r,l),l&&(r.setOne(o,d),d=r.get(o))}return e.emit("subscription.get.resolved",{args:o,data:d}),{data:d}}catch(l){return e.emit("subscription.get.resolved",{args:o,error:l}),{error:new go("Failed to fetch subscription",l)}}}),uFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l;try{e.emit("subscription.create.pending",{args:o});const u=yield n.createSubscription({identifier:(l=o.identifier)!=null?l:"",name:o.name,topicKey:o.topicKey,topicName:o.topicName,preferences:o.preferences}),d=new Zq(wc(fi({},u),{topicKey:o.topicKey}),e,n,r,i);return e.emit("subscription.create.resolved",{args:o,data:d}),{data:d}}catch(u){return e.emit("subscription.create.resolved",{args:o,error:u}),{error:new go("Failed to create subscription",u)}}}),NNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){const l="identifier"in o?o.identifier:o.subscription.identifier,u="topicKey"in o?o.topicKey:o.subscription.topicKey;try{e.emit("subscription.update.pending",{args:o});const d=yield n.updateSubscription({topicKey:u,identifier:l,name:o.name,preferences:o.preferences}),p=new Zq(wc(fi({},d),{topicKey:u}),e,n,r,i);return e.emit("subscription.update.resolved",{args:o,data:p}),{data:p}}catch(d){return e.emit("subscription.update.resolved",{args:o,error:d}),{error:new go("Failed to update subscription",d)}}}),RNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l,u;const d="workflowId"in o?o.workflowId:(u=(l=o.preference)==null?void 0:l.workflow)==null?void 0:u.id;try{e.emit("subscription.preference.update.pending",{args:o,data:"preference"in o?new Xq(fi(fi({},o.preference),typeof o.value=="boolean"?{enabled:o.value}:{condition:o.value}),e,n,r,i):void 0});const p=yield n.updateSubscriptionPreference(fi({subscriptionIdentifier:o.subscriptionId,workflowId:d},typeof o.value=="boolean"?{enabled:o.value,email:o.value,sms:o.value,in_app:o.value,chat:o.value,push:o.value}:{condition:o.value})),m=new Xq(fi({},p),e,n,r,i);return e.emit("subscription.preference.update.resolved",{args:o,data:m}),{data:m}}catch(p){return e.emit("subscription.preference.update.resolved",{args:o,error:p}),{error:new go("Failed to update subscription",p)}}}),dFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){try{const l=o.map(m=>"preference"in m?new Xq(fi(fi({},m.preference),typeof m.value=="boolean"?{enabled:m.value}:{condition:m.value}),e,n,r,i):void 0).filter(m=>m!==void 0);e.emit("subscription.preferences.bulk_update.pending",{args:o,data:l});const u=o.map(m=>{var g,h,f,b,y,v;return fi({subscriptionIdentifier:m.subscriptionId,workflowId:"workflowId"in m?m.workflowId:(v=(y=(h=(g=m.preference)==null?void 0:g.workflow)==null?void 0:h.id)!=null?y:(b=(f=m.preference)==null?void 0:f.workflow)==null?void 0:b.identifier)!=null?v:""},typeof m.value=="boolean"?{enabled:m.value,email:m.value,sms:m.value,in_app:m.value,chat:m.value,push:m.value}:{condition:m.value})}),p=(yield n.bulkUpdateSubscriptionPreferences(u)).map(m=>new Xq(m,e,n,r,i));return e.emit("subscription.preferences.bulk_update.resolved",{args:o,data:p}),{data:p}}catch(l){return e.emit("subscription.preferences.bulk_update.resolved",{args:o,error:l}),{error:new go("Failed to bulk update subscription preferences",l)}}}),LNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,args:r}){const i="identifier"in r?r.identifier:r.subscription.identifier,o="topicKey"in r?r.topicKey:r.subscription.topicKey;try{return e.emit("subscription.delete.pending",{args:r}),yield n.deleteSubscription({topicKey:o,identifier:i}),e.emit("subscription.delete.resolved",{args:r}),{data:void 0}}catch(l){return e.emit("subscription.delete.resolved",{args:r,error:l}),{error:new go("Failed to delete subscription",l)}}}),Koe,Zoe,Xoe,Joe,Xq=class{constructor(t,e,n,r,i){qa(this,Koe),qa(this,Zoe),qa(this,Xoe),qa(this,Joe);var o;di(this,Koe,e),di(this,Zoe,n),di(this,Xoe,r),di(this,Joe,i),this.enabled=t.enabled,this.condition=(o=t.condition)!=null?o:void 0,this.workflow=t.workflow,this.subscriptionId=t.subscriptionId}update(t){return Rr(this,null,function*(){var e;return RNt({emitter:tn(this,Koe),apiService:tn(this,Zoe),cache:tn(this,Xoe),useCache:tn(this,Joe),args:{subscriptionId:this.subscriptionId,workflowId:(e=this.workflow)==null?void 0:e.id,value:t.value,preference:this}})})}};Koe=new WeakMap,Zoe=new WeakMap,Xoe=new WeakMap,Joe=new WeakMap;var VR,Jq,aF=class{constructor({inboxServiceInstance:t,eventEmitterInstance:e}){qa(this,VR,[]),qa(this,Jq),this._emitter=e,this._inboxService=t,this._emitter.on("session.initialize.resolved",({error:n,data:r})=>{r?(this.onSessionSuccess(r),tn(this,VR).forEach(i=>Rr(this,[i],function*({fn:o,resolve:l}){l(yield o())})),di(this,VR,[])):n&&(this.onSessionError(n),di(this,Jq,n),tn(this,VR).forEach(({resolve:i})=>{i({error:new go("Failed to initialize session, please contact the support",n)})}),di(this,VR,[]))})}onSessionSuccess(t){}onSessionError(t){}callWithSession(t){return Rr(this,null,function*(){return this._inboxService.isSessionInitialized?t():tn(this,Jq)?Promise.resolve({error:new go("Failed to initialize session, please contact the support",tn(this,Jq))}):new Promise((e,n)=>{tn(this,VR).push({fn:t,resolve:e,reject:n})})})}};VR=new WeakMap,Jq=new WeakMap;var ak,eG=class{constructor(){qa(this,ak),di(this,ak,new Map)}get(t){return tn(this,ak).get(t)}getValues(){return Array.from(tn(this,ak).values())}entries(){return Array.from(tn(this,ak).entries())}keys(){return Array.from(tn(this,ak).keys())}set(t,e){tn(this,ak).set(t,e)}remove(t){tn(this,ak).delete(t)}clear(){tn(this,ak).clear()}};ak=new WeakMap;var KR=t=>`list:${t.topicKey}`,MNt=t=>t.split(":")[1],fT=t=>`item:${t.topicKey}:${t.identifier}`,Th,Rd,ele,mp,tle,pFr=class{constructor({emitterInstance:t,inboxServiceInstance:e,useCache:n}){qa(this,Th),qa(this,Rd),qa(this,ele),qa(this,mp),qa(this,tle),this.handleCreate=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=[...o,r];tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).set(fT({topicKey:r.topicKey,identifier:r.identifier}),r)},this.handleUpdate=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=o.map(u=>u.id===r.id?r:u);tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).set(fT({topicKey:r.topicKey,identifier:r.identifier}),r)},this.handlePreferenceUpdate=r=>{this.updateSubscriptionPreferences([r])},this.handleBulkPreferenceUpdate=r=>{this.updateSubscriptionPreferences(r)},this.updateSubscriptionPreferences=r=>{var i;const o=new Map;for(const d of r){const p=(i=o.get(d.subscriptionId))!=null?i:[];p.push(d),o.set(d.subscriptionId,p)}const l=tn(this,Rd).keys();for(const d of l){const p=tn(this,Rd).get(d);if(!p)continue;let m=!1;const g=p.map(h=>{const f=o.get(h.id);return f?(m=!0,this.createUpdatedSubscription(h,f)):h});m&&(tn(this,Rd).set(d,g),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:MNt(d),subscriptions:g}}))}const u=tn(this,mp).keys();for(const d of u){const p=tn(this,mp).get(d);if(!p)continue;const m=o.get(p.id);if(m){const g=this.createUpdatedSubscription(p,m);tn(this,mp).set(d,g),tn(this,Th).emit("subscription.update.resolved",{args:{subscription:p},data:g})}}},this.createUpdatedSubscription=(r,i)=>{var o;const l=(o=r.preferences)==null?void 0:o.map(u=>{const d=i.find(p=>p.workflow.id===u.workflow.id);return d||u});return new Zq({id:r.id,identifier:r.identifier,topicKey:r.topicKey,preferences:l},tn(this,Th),tn(this,tle),this,tn(this,ele))},this.handleDelete=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=o.filter(u=>u.id!==r.id);tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).remove(fT({topicKey:r.topicKey,identifier:r.identifier}))},this.handleDeleteByIdentifier=r=>{const i=tn(this,Rd).keys();for(const l of i){const u=tn(this,Rd).get(l);if(u){const d=u.find(p=>p.identifier===r);if(d){const p=u.filter(m=>m.identifier!==r);tn(this,Rd).set(l,p),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:MNt(l),subscriptions:p}}),tn(this,mp).remove(fT({topicKey:d.topicKey,identifier:d.identifier}));return}}}const o=tn(this,mp).keys();for(const l of o){const u=tn(this,mp).get(l);if(u&&u.identifier===r){tn(this,mp).remove(l);return}}},di(this,Th,t),di(this,Rd,new eG),di(this,mp,new eG),di(this,tle,e),di(this,ele,n),tn(this,Th).on("subscription.create.resolved",({data:r})=>{r&&this.handleCreate(r)}),tn(this,Th).on("subscription.update.resolved",({data:r})=>{r&&this.handleUpdate(r)}),tn(this,Th).on("subscription.delete.resolved",({args:r})=>{"subscription"in r?this.handleDelete(r.subscription):"identifier"in r&&this.handleDeleteByIdentifier(r.identifier)}),tn(this,Th).on("subscription.preference.update.pending",({data:r})=>{r&&this.handlePreferenceUpdate(r)}),tn(this,Th).on("subscription.preference.update.resolved",({data:r})=>{r&&this.handlePreferenceUpdate(r)}),tn(this,Th).on("subscription.preferences.bulk_update.resolved",({data:r})=>{r&&r.length>0&&this.handleBulkPreferenceUpdate(r)})}has(t){return tn(this,Rd).get(KR(t))!==void 0}set(t,e){tn(this,Rd).set(KR(t),e);for(const n of e)tn(this,mp).set(fT({topicKey:t.topicKey,identifier:n.identifier}),n)}setOne(t,e){tn(this,mp).set(fT(t),e)}getAll(t){return tn(this,Rd).get(KR(t))}get(t){return tn(this,mp).get(fT(t))}invalidate(t){const e=KR({topicKey:t.topicKey}),n=tn(this,Rd).get(e);if(n)for(const i of n)tn(this,mp).remove(fT({topicKey:t.topicKey,identifier:i.identifier}));tn(this,Rd).remove(e);const r=tn(this,mp).keys();for(const i of r)i.startsWith(`item:${t.topicKey}:`)&&tn(this,mp).remove(i)}clearAll(){tn(this,Rd).clear(),tn(this,mp).clear()}};Th=new WeakMap,Rd=new WeakMap,ele=new WeakMap,mp=new WeakMap,tle=new WeakMap;var ZR,nle,rle,mFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n,subscriber:r,contextKey:i}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,ZR),qa(this,nle),qa(this,rle),this.cache=new pFr({emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,useCache:t}),di(this,ZR,t),di(this,nle,r),di(this,rle,i)}list(t,e){return Rr(this,null,function*(){return this.callWithSession(()=>{var n;return lFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,options:wc(fi({},e),{useCache:(n=e?.useCache)!=null?n:tn(this,ZR)}),args:t})})})}get(t,e){return Rr(this,null,function*(){return this.callWithSession(()=>{var n,r;return cFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,options:wc(fi({},e),{useCache:(n=e?.useCache)!=null?n:tn(this,ZR)}),args:wc(fi({},t),{identifier:(r=t.identifier)!=null?r:eOr({topicKey:t.topicKey,subscriberId:tn(this,nle).subscriberId,contextKey:tn(this,rle)})})})})})}create(t){return Rr(this,null,function*(){return this.callWithSession(()=>uFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,ZR),args:t}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>NNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,ZR),args:t}))})}delete(t){return Rr(this,null,function*(){return this.callWithSession(()=>LNt({emitter:this._emitter,apiService:this._inboxService,args:t}))})}};ZR=new WeakMap,nle=new WeakMap,rle=new WeakMap;var gFr="v1",PNt="@novu/js@3.13.0",hFr=class{constructor(t={}){this.DEFAULT_BACKEND_URL=typeof window<"u"&&window.NOVU_LOCAL_BACKEND_URL||"https://api.novu.co";const{apiVersion:e=gFr,apiUrl:n=this.DEFAULT_BACKEND_URL,userAgent:r=PNt,headers:i={}}=t||{};this.apiVersion=e,this.apiUrl=`${n}/${e}`,this.headers=fi({"Novu-API-Version":"2024-06-26","Novu-Client-Version":PNt,"Content-Type":"application/json","User-Agent":r},i)}setAuthorizationToken(t){this.headers.Authorization=`Bearer ${t}`}setKeylessHeader(t){var e;const n=t||typeof window<"u"&&((e=window.localStorage)==null?void 0:e.getItem("novu_keyless_application_identifier"));!n||!n.startsWith("pk_keyless_")||(this.headers["Novu-Application-Identifier"]=n)}setHeaders(t){this.headers=fi(fi({},this.headers),t)}get(t,e,n=!0){return Rr(this,null,function*(){return this.doFetch({path:t,searchParams:e,options:{method:"GET"},unwrapEnvelope:n})})}post(t,e,n){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"POST",body:e,headers:n?.headers}})})}patch(t,e){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"PATCH",body:e}})})}delete(t,e){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"DELETE",body:e}})})}doFetch(t){return Rr(this,arguments,function*({path:e,searchParams:n,options:r,unwrapEnvelope:i=!0}){const o=fFr(this.apiUrl,e,n?`?${n.toString()}`:""),l={method:r?.method||"GET",headers:fi(fi({},this.headers),r?.headers||{}),body:r?.body?JSON.stringify(r.body):void 0},u=yield fetch(o,l);if(!u.ok){const p=yield u.json();throw new Error(`${this.headers["Novu-Client-Version"]} error. Status: ${u.status}, Message: ${p.message}`)}if(u.status===204)return;const d=yield u.json();return i?d.data:d})}};function fFr(...t){return t.reduce((e,n)=>(n&&e.push(n.replace(new RegExp("(?<!https?:)\\/+","g"),"/").replace(/^\/+|\/+$/g,"")),e),[]).join("/").replace(/\/\?/,"?")}var qA="/inbox",Bh=`${qA}/notifications`,Fo,AFr=class{constructor(t={}){this.isSessionInitialized=!1,qa(this,Fo),di(this,Fo,new hFr(t))}initializeSession(t){return Rr(this,arguments,function*({applicationIdentifier:e,subscriberHash:n,contextHash:r,subscriber:i,defaultSchedule:o,context:l}){const u=yield tn(this,Fo).post(`${qA}/session`,{applicationIdentifier:e,subscriberHash:n,contextHash:r,subscriber:i,defaultSchedule:o,context:l});return tn(this,Fo).setAuthorizationToken(u.token),tn(this,Fo).setKeylessHeader(u.applicationIdentifier),this.isSessionInitialized=!0,u})}fetchNotifications({after:t,archived:e,limit:n=10,offset:r,read:i,tags:o,snoozed:l,seen:u,data:d,severity:p}){const m=new URLSearchParams(`limit=${n}`);if(t&&m.append("after",t),r&&m.append("offset",`${r}`),o)for(const g of o)m.append("tags[]",g);if(i!==void 0&&m.append("read",`${i}`),e!==void 0&&m.append("archived",`${e}`),l!==void 0&&m.append("snoozed",`${l}`),u!==void 0&&m.append("seen",`${u}`),d!==void 0&&m.append("data",JSON.stringify(d)),p&&Array.isArray(p))for(const g of p)m.append("severity[]",g);else p&&m.append("severity",p);return tn(this,Fo).get(Bh,m,!1)}count({filters:t}){return tn(this,Fo).get(`${Bh}/count`,new URLSearchParams({filters:JSON.stringify(t)}),!1)}read(t){return tn(this,Fo).patch(`${Bh}/${t}/read`)}unread(t){return tn(this,Fo).patch(`${Bh}/${t}/unread`)}archive(t){return tn(this,Fo).patch(`${Bh}/${t}/archive`)}unarchive(t){return tn(this,Fo).patch(`${Bh}/${t}/unarchive`)}snooze(t,e){return tn(this,Fo).patch(`${Bh}/${t}/snooze`,{snoozeUntil:e})}unsnooze(t){return tn(this,Fo).patch(`${Bh}/${t}/unsnooze`)}readAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/read`,{tags:t,data:e?JSON.stringify(e):void 0})}archiveAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/archive`,{tags:t,data:e?JSON.stringify(e):void 0})}archiveAllRead({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/read-archive`,{tags:t,data:e?JSON.stringify(e):void 0})}delete(t){return tn(this,Fo).delete(`${Bh}/${t}/delete`)}deleteAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/delete`,{tags:t,data:e?JSON.stringify(e):void 0})}markAsSeen({notificationIds:t,tags:e,data:n}){return tn(this,Fo).post(`${Bh}/seen`,{notificationIds:t,tags:e,data:n?JSON.stringify(n):void 0})}seen(t){return this.markAsSeen({notificationIds:[t]})}completeAction({actionType:t,notificationId:e}){return tn(this,Fo).patch(`${Bh}/${e}/complete`,{actionType:t})}revertAction({actionType:t,notificationId:e}){return tn(this,Fo).patch(`${Bh}/${e}/revert`,{actionType:t})}fetchPreferences({tags:t,severity:e,criticality:n}){const r=new URLSearchParams;if(t)for(const o of t)r.append("tags[]",o);if(e&&Array.isArray(e))for(const o of e)r.append("severity[]",o);else e&&r.append("severity",e);n&&r.append("criticality",n);const i=r.size?`?${r.toString()}`:"";return tn(this,Fo).get(`${qA}/preferences${i}`)}bulkUpdatePreferences(t){return tn(this,Fo).patch(`${qA}/preferences/bulk`,{preferences:t})}updateGlobalPreferences(t){return tn(this,Fo).patch(`${qA}/preferences`,t)}updateWorkflowPreferences({workflowId:t,channels:e}){return tn(this,Fo).patch(`${qA}/preferences/${t}`,e)}fetchGlobalPreferences(){return tn(this,Fo).get(`${qA}/preferences/global`)}triggerHelloWorldEvent(){const t={name:"hello-world",to:{subscriberId:"keyless-subscriber-id"},payload:{subject:"Novu Keyless Environment",body:"You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",primaryActionText:"Obtain API Key",primaryActionUrl:"https://go.novu.co/keyless",secondaryActionText:"Explore Documentation",secondaryActionUrl:"https://go.novu.co/keyless-docs"}};return tn(this,Fo).post("/inbox/events",t)}fetchSubscriptions(t){return tn(this,Fo).get(`${qA}/topics/${t}/subscriptions`)}getSubscription(t,e,n,r){const i=new URLSearchParams;if(n?.length)for(const l of n)i.append("workflowIds",l);if(r?.length)for(const l of r)i.append("tags",l);const o=i.size?`?${i.toString()}`:"";return tn(this,Fo).get(`${qA}/topics/${t}/subscriptions/${e}${o}`)}createSubscription({identifier:t,name:e,topicKey:n,topicName:r,preferences:i}){return tn(this,Fo).post(`${qA}/topics/${n}/subscriptions`,fi(fi({identifier:t,name:e},r&&{topic:{name:r}}),i!==void 0&&{preferences:i}))}updateSubscription({topicKey:t,identifier:e,name:n,preferences:r}){return tn(this,Fo).patch(`${qA}/topics/${t}/subscriptions/${e}`,fi({name:n},r!==void 0&&{preferences:r}))}updateSubscriptionPreference({subscriptionIdentifier:t,workflowId:e,enabled:n,condition:r,email:i,sms:o,in_app:l,chat:u,push:d}){return tn(this,Fo).patch(`${qA}/subscriptions/${t}/preferences/${e}`,{enabled:n,condition:r,email:i,sms:o,in_app:l,chat:u,push:d})}bulkUpdateSubscriptionPreferences(t){return tn(this,Fo).patch(`${qA}/preferences/bulk`,{preferences:t})}deleteSubscription({topicKey:t,identifier:e}){return tn(this,Fo).delete(`${qA}/topics/${t}/subscriptions/${e}`)}};Fo=new WeakMap;var iF,bFr=class{constructor(){qa(this,iF),di(this,iF,sOr())}on(t,e){return tn(this,iF).on(t,e),()=>{this.off(t,e)}}off(t,e){tn(this,iF).off(t,e)}emit(t,e){tn(this,iF).emit(t,e)}};iF=new WeakMap;var ONt=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})=>Object.entries({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p}).filter(([m,g])=>g!=null&&!(Array.isArray(g)&&g.length===0)).reduce((m,[g,h])=>(m[g]=h,m),{}),tG=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})=>JSON.stringify(ONt({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})),yFr=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l})=>JSON.stringify(ONt({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l})),XR=t=>JSON.parse(t),vFr=["notification.read.pending","notification.read.resolved","notification.unread.pending","notification.unread.resolved","notification.complete_action.pending","notification.complete_action.resolved","notification.revert_action.pending","notification.revert_action.resolved","notifications.read_all.pending","notifications.read_all.resolved"],_Fr=["notification.archive.pending","notification.unarchive.pending","notification.snooze.pending","notification.unsnooze.pending","notification.delete.pending","notifications.archive_all.pending","notifications.archive_all_read.pending","notifications.delete_all.pending"],AT,ale,Ld,wFr=class{constructor({emitter:t,inboxService:e}){qa(this,AT),qa(this,ale),qa(this,Ld),this.updateNotification=(n,r)=>{const i=tn(this,Ld).get(n);if(!i)return!1;const o=i.notifications.findIndex(u=>u.id===r.id);if(o===-1)return!1;const l=[...i.notifications];return l[o]=r,tn(this,Ld).set(n,wc(fi({},i),{notifications:l})),!0},this.removeNotification=(n,r)=>{const i=tn(this,Ld).get(n);if(!i)return!1;const o=i.notifications.findIndex(u=>u.id===r.id);if(o===-1)return!1;const l=[...i.notifications];return l.splice(o,1),tn(this,Ld).set(n,wc(fi({},i),{notifications:l})),!0},this.handleNotificationEvent=({remove:n}={remove:!1})=>r=>{const{data:i,args:o}=r;let l=[];if(i!=null)Array.isArray(i)&&i.every(d=>typeof d=="object"&&"id"in d)?l=i:typeof i=="object"&&"id"in i&&(l=[i]);else if(n&&o){if("notification"in o&&o.notification)l=[o.notification];else if("notificationId"in o&&o.notificationId){const d=[];tn(this,Ld).keys().forEach(p=>{const m=tn(this,Ld).get(p);if(m){const g=m.notifications.find(h=>h.id===o.notificationId);g&&d.push(g)}}),l=d}}if(l.length===0)return;const u=new Set;tn(this,Ld).keys().forEach(d=>{l.forEach(p=>{let m=!1;n?m=this.removeNotification(d,p):m=this.updateNotification(d,p),m&&u.add(yFr(XR(d)))})}),u.forEach(d=>{const p=this.getAggregated(XR(d));tn(this,AT).emit("notifications.list.updated",{data:p})})},di(this,AT,t),di(this,ale,e),vFr.forEach(n=>{tn(this,AT).on(n,this.handleNotificationEvent())}),_Fr.forEach(n=>{tn(this,AT).on(n,this.handleNotificationEvent({remove:!0}))}),di(this,Ld,new eG)}getAggregated(t){return tn(this,Ld).keys().filter(n=>{const r=XR(n);return Voe(r,t)}).map(n=>tn(this,Ld).get(n)).reduce((n,r)=>r?{hasMore:r.hasMore,filter:r.filter,notifications:[...n.notifications,...r.notifications]}:n,{hasMore:!1,filter:{},notifications:[]})}get(t){return tn(this,Ld).get(tG(t))}has(t){return tn(this,Ld).get(tG(t))!==void 0}set(t,e){tn(this,Ld).set(tG(t),e)}unshift(t,e){const n=tG(t),r=tn(this,Ld).get(n)||{hasMore:!1,filter:XR(n),notifications:[]},i=iOr({notification:fi({},e),emitter:tn(this,AT),inboxService:tn(this,ale)});this.update(t,wc(fi({},r),{notifications:[i,...r.notifications]}))}update(t,e){this.set(t,e);const n=this.getAggregated(XR(tG(t)));tn(this,AT).emit("notifications.list.updated",{data:n})}getAll(t){if(this.has(t))return this.getAggregated({tags:t.tags,data:t.data,read:t.read,snoozed:t.snoozed,archived:t.archived,seen:t.seen,severity:t.severity})}getUniqueNotifications({tags:t,read:e,data:n}){const r=tn(this,Ld).keys(),i=new Map;return r.forEach(o=>{const l=XR(o);if(rRe(t,l.tags)&&DNt(n,l.data)){const u=tn(this,Ld).get(o);if(!u)return;u.notifications.filter(d=>typeof e>"u"||e===d.isRead).forEach(d=>{i.set(d.id,d)})}}),Array.from(i.values())}clear(t){tn(this,Ld).keys().forEach(n=>{Voe(XR(n),t)&&tn(this,Ld).remove(n)})}clearAll(){tn(this,Ld).clear()}};AT=new WeakMap,ale=new WeakMap,Ld=new WeakMap;var ile,xFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,ile),this.cache=new wFr({emitter:n,inboxService:e}),di(this,ile,t)}list(){return Rr(this,arguments,function*(t={}){var e=t,{limit:n=10}=e,r=JPr(e,["limit"]);return this.callWithSession(()=>Rr(this,null,function*(){const i=fi({limit:n},r);try{const o="useCache"in i?i.useCache:tn(this,ile);let l=o?this.cache.getAll(i):void 0;if(this._emitter.emit("notifications.list.pending",{args:i,data:l}),!l){const u=yield this._inboxService.fetchNotifications(fi({limit:n},r));l={hasMore:u.hasMore,filter:u.filter,notifications:u.data.map(d=>new Nm(d,this._emitter,this._inboxService))},o&&(this.cache.set(i,l),l=this.cache.getAll(i))}return this._emitter.emit("notifications.list.resolved",{args:i,data:l}),{data:l}}catch(o){return this._emitter.emit("notifications.list.resolved",{args:i,error:o}),{error:new go("Failed to fetch notifications",o)}}}))})}count(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){const e=t&&"filters"in t?t.filters:[fi({},t)];try{this._emitter.emit("notifications.count.pending",{args:t});const n=yield this._inboxService.count({filters:e}),r=t&&"filters"in t?{counts:n.data}:n.data[0];return this._emitter.emit("notifications.count.resolved",{args:t,data:r}),{data:r}}catch(n){return this._emitter.emit("notifications.count.resolved",{args:t,error:n}),{error:new go("Failed to count notifications",n)}}}))})}read(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return HDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unread(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return WDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}seen(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return YDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}archive(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return VDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unarchive(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return KDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}delete(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return eNt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}snooze(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return ZDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unsnooze(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return XDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}completePrimary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Foe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"primary"})}))})}completeSecondary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Foe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"secondary"})}))})}revertPrimary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Qoe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"primary"})}))})}revertSecondary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Qoe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"secondary"})}))})}readAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return tOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}seenAll(){return Rr(this,arguments,function*(t={}){return this.callWithSession(()=>Rr(this,null,function*(){return"notificationIds"in t?JDt({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,notificationIds:t.notificationIds}):JDt({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:"tags"in t?t.tags:void 0,data:"data"in t?t.data:void 0})}))})}archiveAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return nOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}archiveAllRead(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return rOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}deleteAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return aOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}clearCache({filter:t}={}){if(t){this.cache.clear(t??{});return}this.cache.clearAll()}triggerHelloWorldEvent(){return Rr(this,null,function*(){return this._inboxService.triggerHelloWorldEvent()})}};ile=new WeakMap;var sle,ole,lle,cle,ule=class{constructor(t,{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i}){qa(this,sle),qa(this,ole),qa(this,lle),qa(this,cle),di(this,sle,e),di(this,ole,n),di(this,lle,r),di(this,cle,i),this.isEnabled=t.isEnabled,this.weeklySchedule=t.weeklySchedule}update(t){return Rr(this,null,function*(){var e;const n=!!t.weeklySchedule||!!this.weeklySchedule;return QNt({emitter:tn(this,sle),apiService:tn(this,ole),cache:tn(this,lle),useCache:tn(this,cle),args:fi({isEnabled:(e=t.isEnabled)!=null?e:this.isEnabled},n&&{weeklySchedule:fi(fi({},this.weeklySchedule),t.weeklySchedule)})})})}};sle=new WeakMap,ole=new WeakMap,lle=new WeakMap,cle=new WeakMap;var dle,ple,mle,gle,hle,sF=class{constructor(t,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}){qa(this,dle),qa(this,ple),qa(this,mle),qa(this,gle),qa(this,hle),di(this,dle,e),di(this,ple,n),di(this,mle,r),di(this,gle,i),di(this,hle,o),this.level=t.level,this.enabled=t.enabled,this.channels=t.channels,this.workflow=t.workflow,this.schedule=new ule(fi({},t.schedule),{emitterInstance:e,inboxServiceInstance:n,cache:i,useCache:o})}update({channels:t,channelPreferences:e}){var n;return FNt({emitter:tn(this,dle),apiService:tn(this,ple),cache:tn(this,mle),scheduleCache:tn(this,gle),useCache:tn(this,hle),args:{workflowId:(n=this.workflow)==null?void 0:n.id,channels:t||e,preference:this}})}};dle=new WeakMap,ple=new WeakMap,mle=new WeakMap,gle=new WeakMap,hle=new WeakMap;var FNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}){var u;const{channels:d}=l,p="workflowId"in l?l.workflowId:(u=l.preference.workflow)==null?void 0:u.id;try{e.emit("preference.update.pending",{args:l,data:"preference"in l?new sF(wc(fi({},l.preference),{channels:fi(fi({},l.preference.channels),d)}),{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}):void 0});let m;p?m=yield n.updateWorkflowPreferences({workflowId:p,channels:d}):(EFr({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}),m=yield n.updateGlobalPreferences(d));const g=new sF(m,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o});return e.emit("preference.update.resolved",{args:l,data:g}),{data:g}}catch(m){return e.emit("preference.update.resolved",{args:l,error:m}),{error:new go("Failed to update preference",m)}}}),kFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}){if(l.find(d=>"preference"in d&&d.preference.level==="global"))return{error:new go("Global preference is not supported in bulk update","")};try{const d=l.map(h=>"preference"in h?new sF(wc(fi({},h.preference),{channels:fi(fi({},h.preference.channels),h.channels)}),{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}):void 0).filter(h=>h!==void 0);e.emit("preferences.bulk_update.pending",{args:l,data:d});const p=l.map(h=>{var f,b,y,v;return fi({workflowId:"workflowId"in h?h.workflowId:(v=(y=(f=h.preference.workflow)==null?void 0:f.id)!=null?y:(b=h.preference.workflow)==null?void 0:b.identifier)!=null?v:""},h.channels)}),g=(yield n.bulkUpdatePreferences(p)).map(h=>new sF(h,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}));return e.emit("preferences.bulk_update.resolved",{args:l,data:g}),{data:g}}catch(d){return e.emit("preferences.bulk_update.resolved",{args:l,error:d}),{error:new go("Failed to bulk update preferences",d)}}}),EFr=({emitter:t,apiService:e,cache:n,scheduleCache:r,useCache:i,args:o})=>{const l=i?n?.getAll({}):void 0;l?.forEach(u=>{var d,p;if(u.level==="template"){const m=wc(fi({},u),{channels:Object.entries(u.channels).reduce((h,[f,b])=>{var y;const v=f;return h[v]=(y=o.channels[v])!=null?y:b,h},{})}),g="preference"in o?new sF(m,{emitterInstance:t,inboxServiceInstance:e,cache:n,scheduleCache:r,useCache:i}):void 0;g&&t.emit("preference.update.pending",{args:{workflowId:(p=(d=u.workflow)==null?void 0:d.id)!=null?p:"",channels:g.channels},data:g})}})},QNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l,u;try{const{isEnabled:d,weeklySchedule:p}=o,m=new ule({isEnabled:d,weeklySchedule:p},{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i});e.emit("preference.schedule.update.pending",{args:o,data:m});const g=yield n.updateGlobalPreferences({schedule:{isEnabled:d,weeklySchedule:p}}),h=new ule({isEnabled:(l=g.schedule)==null?void 0:l.isEnabled,weeklySchedule:(u=g.schedule)==null?void 0:u.weeklySchedule},{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i});return e.emit("preference.schedule.update.resolved",{args:o,data:h}),{data:h}}catch(d){return e.emit("preference.schedule.update.resolved",{args:o,error:d}),{error:new go("Failed to update preference",d)}}}),JR,CFr=class extends aF{constructor({cache:t,useCache:e,inboxServiceInstance:n,eventEmitterInstance:r}){super({eventEmitterInstance:r,inboxServiceInstance:n}),qa(this,JR),this.cache=t,di(this,JR,e)}get(){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){var t,e;try{let n=tn(this,JR)?this.cache.getAll():void 0;if(this._emitter.emit("preference.schedule.get.pending",{args:void 0,data:n}),!n){const r=yield this._inboxService.fetchGlobalPreferences();n=new ule({isEnabled:(t=r?.schedule)==null?void 0:t.isEnabled,weeklySchedule:(e=r?.schedule)==null?void 0:e.weeklySchedule},{emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,cache:this.cache,useCache:tn(this,JR)}),tn(this,JR)&&(this.cache.set(n),n=this.cache.getAll())}return this._emitter.emit("preference.schedule.get.resolved",{args:void 0,data:n}),{data:n}}catch(n){throw this._emitter.emit("preference.schedule.get.resolved",{args:void 0,error:n}),n}}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>QNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,JR),args:t}))})}};JR=new WeakMap;var SFr=["preference.update.pending","preference.update.resolved","preferences.bulk_update.pending","preferences.bulk_update.resolved"],IFr=["preference.schedule.update.pending","preference.schedule.update.resolved"],TFr=({tags:t,severity:e})=>Object.entries({tags:t,severity:e}).reduce((n,[r,i])=>(i==null||Array.isArray(i)&&i.length===0||(n[r]=i),n),{}),aRe=({tags:t,severity:e})=>JSON.stringify(TFr({tags:t,severity:e})),e3,Cg,BFr=class{constructor({emitterInstance:t}){qa(this,e3),qa(this,Cg),this.updatePreference=(e,n)=>{const r=tn(this,Cg).get(e);if(!r)return!1;const i=r.findIndex(l=>{var u,d;return((u=l.workflow)==null?void 0:u.id)===((d=n.workflow)==null?void 0:d.id)||l.level===n.level&&n.level==="global"});if(i===-1)return!1;const o=[...r];return o[i]=n,tn(this,Cg).set(e,o),!0},this.updatePreferenceSchedule=(e,n)=>{const r=tn(this,Cg).get(e);if(!r)return!1;const i=r.findIndex(l=>l.level==="global");if(i===-1)return!1;const o=[...r];return o[i].schedule=n,tn(this,Cg).set(e,o),!0},this.handleScheduleEvent=({data:e})=>{var n;if(!e)return;const r=tn(this,Cg).keys(),i=new Set;for(const o of r){const l=this.updatePreferenceSchedule(o,e),u=tn(this,Cg).get(o);!l||!u||i.add(o)}for(const o of i)tn(this,e3).emit("preferences.list.updated",{data:(n=tn(this,Cg).get(o))!=null?n:[]})},this.handlePreferenceEvent=({data:e})=>{if(!e)return;const n=Array.isArray(e)?e:[e],r=new Set;tn(this,Cg).keys().forEach(i=>{n.forEach(o=>{const l=this.updatePreference(i,o),u=tn(this,Cg).get(i);!l||!u||r.add(i)})}),r.forEach(i=>{var o;tn(this,e3).emit("preferences.list.updated",{data:(o=tn(this,Cg).get(i))!=null?o:[]})})},di(this,e3,t);for(const e of SFr)tn(this,e3).on(e,this.handlePreferenceEvent);for(const e of IFr)tn(this,e3).on(e,this.handleScheduleEvent);di(this,Cg,new eG)}has(t){return tn(this,Cg).get(aRe(t))!==void 0}set(t,e){tn(this,Cg).set(aRe(t),e)}getAll(t){if(this.has(t))return tn(this,Cg).get(aRe(t))}clearAll(){tn(this,Cg).clear()}};e3=new WeakMap,Cg=new WeakMap;var DFr=["preference.schedule.update.pending","preference.schedule.update.resolved"],iRe=()=>"schedule",nG,Cy,NFr=class{constructor({emitterInstance:t}){qa(this,nG),qa(this,Cy),this.updateScheduleInCache=(e,n)=>tn(this,Cy).get(e)?(tn(this,Cy).set(e,n),!0):!1,this.handleScheduleEvent=({data:e})=>{if(!e)return;const n=new Set,r=tn(this,Cy).keys();for(const i of r){const o=this.updateScheduleInCache(i,e),l=tn(this,Cy).get(i);!o||!l||n.add(i)}for(const i of n)tn(this,nG).emit("preference.schedule.get.updated",{data:tn(this,Cy).get(i)})},di(this,nG,t);for(const e of DFr)tn(this,nG).on(e,this.handleScheduleEvent);di(this,Cy,new eG)}has(){return tn(this,Cy).get(iRe())!==void 0}set(t){tn(this,Cy).set(iRe(),t)}getAll(){if(this.has())return tn(this,Cy).get(iRe())}clearAll(){tn(this,Cy).clear()}};nG=new WeakMap,Cy=new WeakMap;var bT,RFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,bT),this.cache=new BFr({emitterInstance:this._emitter}),this.scheduleCache=new NFr({emitterInstance:this._emitter}),di(this,bT,t),this.schedule=new CFr({cache:this.scheduleCache,useCache:t,inboxServiceInstance:e,eventEmitterInstance:n})}list(){return Rr(this,arguments,function*(t={}){return this.callWithSession(()=>Rr(this,null,function*(){var e;try{let n=tn(this,bT)?this.cache.getAll(t):void 0;return this._emitter.emit("preferences.list.pending",{args:t,data:n}),n||(n=(yield this._inboxService.fetchPreferences({tags:t.tags,severity:t.severity,criticality:(e=t.criticality)!=null?e:"nonCritical"})).map(i=>new sF(i,{emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT)})),tn(this,bT)&&(this.cache.set(t,n),n=this.cache.getAll(t))),this._emitter.emit("preferences.list.resolved",{args:t,data:n}),{data:n}}catch(n){throw this._emitter.emit("preferences.list.resolved",{args:t,error:n}),n}}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>FNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT),args:t}))})}bulkUpdate(t){return Rr(this,null,function*(){return this.callWithSession(()=>kFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT),args:t}))})}};bT=new WeakMap;function LFr(){return typeof window<"u"}var oF,fle,Dh,MFr=class{constructor(t,e,n){qa(this,oF),qa(this,fle),qa(this,Dh),di(this,oF,n),di(this,fle,e),di(this,Dh,t)}get applicationIdentifier(){return tn(this,Dh).applicationIdentifier}get subscriberId(){var t;return(t=tn(this,Dh).subscriber)==null?void 0:t.subscriberId}get context(){return tn(this,Dh).context}get subscriberHash(){return tn(this,Dh).subscriberHash}get contextHash(){return tn(this,Dh).contextHash}get subscriber(){return tn(this,Dh).subscriber}handleApplicationIdentifier(t,e){if(typeof window>"u"||!window.localStorage)return null;const n="novu_keyless_application_identifier";switch(t){case"get":return window.localStorage.getItem(n);case"store":return e&&window.localStorage.setItem(n,e),null;case"delete":return window.localStorage.removeItem(n),null;default:return null}}initialize(t){return Rr(this,null,function*(){var e,n,r,i,o,l;const u=((e=tn(this,Dh).subscriber)==null?void 0:e.subscriberId)===((n=t?.subscriber)==null?void 0:n.subscriberId),d=JSON.stringify(tn(this,Dh).context)===JSON.stringify(t?.context);if(!(u&&d))try{t&&di(this,Dh,t);const{subscriber:p,subscriberHash:m,contextHash:g,applicationIdentifier:h,defaultSchedule:f,context:b}=tn(this,Dh);let y;LFr()&&(y=Intl.DateTimeFormat().resolvedOptions().timeZone);let v=h;if(v)this.handleApplicationIdentifier("delete");else{const w=this.handleApplicationIdentifier("get");w&&(v=w)}tn(this,oF).emit("session.initialize.pending",{args:tn(this,Dh)});const _=yield tn(this,fle).initializeSession({applicationIdentifier:v,subscriberHash:m,contextHash:g,subscriber:wc(fi({},p),{subscriberId:(r=p?.subscriberId)!=null?r:"",timezone:(i=p?.timezone)!=null?i:y}),defaultSchedule:f,context:b});(o=_?.applicationIdentifier)!=null&&o.startsWith("pk_keyless_")&&this.handleApplicationIdentifier("store",_.applicationIdentifier),(l=_?.applicationIdentifier)!=null&&l.startsWith("pk_keyless_")||this.handleApplicationIdentifier("delete"),tn(this,oF).emit("session.initialize.resolved",{args:tn(this,Dh),data:_})}catch(p){tn(this,oF).emit("session.initialize.resolved",{args:tn(this,Dh),error:p})}})}};oF=new WeakMap,fle=new WeakMap,Dh=new WeakMap;var Ale="wss://socket.novu.co",$Nt="notifications.notification_received",jNt="notifications.unseen_count_changed",zNt="notifications.unread_count_changed",PFr=({_id:t,transactionId:e,content:n,read:r,seen:i,archived:o,snoozedUntil:l,deliveredAt:u,createdAt:d,lastReadDate:p,firstSeenDate:m,archivedAt:g,channel:h,subscriber:f,subject:b,avatar:y,cta:v,tags:_,data:w,workflow:x,severity:k})=>{var C,E,S,I,B,N,L,M;const R={id:f?._id,subscriberId:f?.subscriberId,firstName:f?.firstName,lastName:f?.lastName,avatar:f?.avatar,locale:f?.locale,data:f?.data,timezone:f?.timezone,email:f?.email,phone:f?.phone},D=(E=(C=v.action)==null?void 0:C.buttons)==null?void 0:E.find($=>$.type==="primary"),P=(I=(S=v.action)==null?void 0:S.buttons)==null?void 0:I.find($=>$.type==="secondary"),O=(N=(B=v.action)==null?void 0:B.result)==null?void 0:N.type,F=(L=v.action)==null?void 0:L.status;return wc(fi(fi({id:t,transactionId:e,subject:b,body:n,to:R,isRead:r,isSeen:i,isArchived:o,isSnoozed:!!l},u&&{deliveredAt:u}),l&&{snoozedUntil:l}),{createdAt:d,readAt:p,firstSeenAt:m,archivedAt:g,avatar:y,primaryAction:D&&{label:D.content,isCompleted:O==="primary"&&F==="done",redirect:D.url?{target:D.target,url:D.url}:void 0},secondaryAction:P&&{label:P.content,isCompleted:O==="secondary"&&F==="done",redirect:P.url?{target:P.target,url:P.url}:void 0},channelType:h,tags:_,redirect:(M=v.data)!=null&&M.url?{url:v.data.url,target:v.data.target}:void 0,data:w,workflow:x,severity:k})},rG,ik,sk,aG,sRe,oRe,lRe,cRe,t3,UNt,uRe,dRe,OFr=class extends aF{constructor({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,t3),qa(this,rG),qa(this,ik),qa(this,sk),qa(this,aG),qa(this,sRe,r=>{try{const i=JSON.parse(r.data);i.event==="notification_received"&&tn(this,ik).emit($Nt,{result:new Nm(PFr(i.data.message),tn(this,ik),this._inboxService)})}catch(i){console.log("error",i)}}),qa(this,oRe,r=>{try{const i=JSON.parse(r.data);i.event==="unseen_count_changed"&&tn(this,ik).emit(jNt,{result:i.data.unseenCount})}catch{}}),qa(this,lRe,r=>{try{const i=JSON.parse(r.data);i.event==="unread_count_changed"&&tn(this,ik).emit(zNt,{result:i.data.counts})}catch{}}),qa(this,cRe,r=>{try{switch(JSON.parse(r.data).event){case"notification_received":tn(this,sRe).call(this,r);break;case"unseen_count_changed":tn(this,oRe).call(this,r);break;case"unread_count_changed":tn(this,lRe).call(this,r);break;default:}}catch{}}),di(this,ik,n),di(this,aG,t??Ale)}onSessionSuccess({token:t}){di(this,rG,t)}isSocketEvent(t){return t===$Nt||t===jNt||t===zNt}connect(){return Rr(this,null,function*(){return tn(this,rG)?tk(this,t3,uRe).call(this):this.callWithSession(tk(this,t3,uRe).bind(this))})}disconnect(){return Rr(this,null,function*(){return tn(this,sk)?tk(this,t3,dRe).call(this):this.callWithSession(tk(this,t3,dRe).bind(this))})}};rG=new WeakMap,ik=new WeakMap,sk=new WeakMap,aG=new WeakMap,sRe=new WeakMap,oRe=new WeakMap,lRe=new WeakMap,cRe=new WeakMap,t3=new WeakSet,UNt=function(){return Rr(this,null,function*(){if(tn(this,sk))return;const t={socketUrl:tn(this,aG)};tn(this,ik).emit("socket.connect.pending",{args:t});const e=new URL(tn(this,aG));e.searchParams.set("token",tn(this,rG)),di(this,sk,new mOr(e.toString())),tn(this,sk).addEventListener("open",()=>{tn(this,ik).emit("socket.connect.resolved",{args:t})}),tn(this,sk).addEventListener("error",n=>{tn(this,ik).emit("socket.connect.resolved",{args:t,error:n})}),tn(this,sk).addEventListener("message",tn(this,cRe))})},uRe=function(){return Rr(this,null,function*(){try{return yield tk(this,t3,UNt).call(this),{}}catch(t){return{error:new go("Failed to initialize the PartySocket",t)}}})},dRe=function(){return Rr(this,null,function*(){var t;try{return(t=tn(this,sk))==null||t.close(),di(this,sk,void 0),{}}catch(e){return{error:new go("Failed to disconnect from the PartySocket",e)}}})};var FFr="https://ws.novu.co",qNt="notifications.notification_received",GNt="notifications.unseen_count_changed",HNt="notifications.unread_count_changed",QFr=({_id:t,transactionId:e,content:n,read:r,seen:i,archived:o,snoozedUntil:l,deliveredAt:u,createdAt:d,lastReadDate:p,firstSeenDate:m,archivedAt:g,channel:h,subscriber:f,subject:b,avatar:y,cta:v,tags:_,data:w,workflow:x,severity:k})=>{var C,E,S,I,B,N,L,M;const R={id:f?._id,subscriberId:f?.subscriberId,firstName:f?.firstName,lastName:f?.lastName,avatar:f?.avatar,locale:f?.locale,data:f?.data,timezone:f?.timezone,email:f?.email,phone:f?.phone},D=(E=(C=v.action)==null?void 0:C.buttons)==null?void 0:E.find($=>$.type==="primary"),P=(I=(S=v.action)==null?void 0:S.buttons)==null?void 0:I.find($=>$.type==="secondary"),O=(N=(B=v.action)==null?void 0:B.result)==null?void 0:N.type,F=(L=v.action)==null?void 0:L.status;return wc(fi(fi({id:t,transactionId:e,subject:b,body:n,to:R,isRead:r,isSeen:i,isArchived:o,isSnoozed:!!l},u&&{deliveredAt:u}),l&&{snoozedUntil:l}),{createdAt:d,readAt:p,firstSeenAt:m,archivedAt:g,avatar:y,primaryAction:D&&{label:D.content,isCompleted:O==="primary"&&F==="done",redirect:D.url?{target:D.target,url:D.url}:void 0},secondaryAction:P&&{label:P.content,isCompleted:O==="secondary"&&F==="done",redirect:P.url?{target:P.target,url:P.url}:void 0},channelType:h,tags:_,redirect:(M=v.data)!=null&&M.url?{url:v.data.url,target:v.data.target}:void 0,data:w,workflow:x,severity:k})},iG,ok,Sy,sG,pRe,mRe,gRe,n3,WNt,hRe,fRe,$Fr=class extends aF{constructor({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,n3),qa(this,iG),qa(this,ok),qa(this,Sy),qa(this,sG),qa(this,pRe,({message:r})=>{tn(this,ok).emit(qNt,{result:new Nm(QFr(r),tn(this,ok),this._inboxService)})}),qa(this,mRe,({unseenCount:r})=>{tn(this,ok).emit(GNt,{result:r})}),qa(this,gRe,({counts:r})=>{tn(this,ok).emit(HNt,{result:r})}),di(this,ok,n),di(this,sG,t??FFr)}onSessionSuccess({token:t}){di(this,iG,t)}isSocketEvent(t){return t===qNt||t===GNt||t===HNt}connect(){return Rr(this,null,function*(){return tn(this,iG)?tk(this,n3,hRe).call(this):this.callWithSession(tk(this,n3,hRe).bind(this))})}disconnect(){return Rr(this,null,function*(){return tn(this,Sy)?tk(this,n3,fRe).call(this):this.callWithSession(tk(this,n3,fRe).bind(this))})}};iG=new WeakMap,ok=new WeakMap,Sy=new WeakMap,sG=new WeakMap,pRe=new WeakMap,mRe=new WeakMap,gRe=new WeakMap,n3=new WeakSet,WNt=function(){return Rr(this,null,function*(){var t,e,n;if(tn(this,Sy))return;const r={socketUrl:tn(this,sG)};tn(this,ok).emit("socket.connect.pending",{args:r}),di(this,Sy,Yoe(tn(this,sG),{reconnectionDelayMax:1e4,transports:["websocket"],query:{token:`${tn(this,iG)}`}})),tn(this,Sy).on("connect",()=>{tn(this,ok).emit("socket.connect.resolved",{args:r})}),tn(this,Sy).on("connect_error",i=>{tn(this,ok).emit("socket.connect.resolved",{args:r,error:i})}),(t=tn(this,Sy))==null||t.on("notification_received",tn(this,pRe)),(e=tn(this,Sy))==null||e.on("unseen_count_changed",tn(this,mRe)),(n=tn(this,Sy))==null||n.on("unread_count_changed",tn(this,gRe))})},hRe=function(){return Rr(this,null,function*(){try{return yield tk(this,n3,WNt).call(this),{}}catch(t){return{error:new go("Failed to initialize the socket",t)}}})},fRe=function(){return Rr(this,null,function*(){var t;try{return(t=tn(this,Sy))==null||t.disconnect(),di(this,Sy,void 0),{}}catch(e){return{error:new go("Failed to disconnect from the socket",e)}}})};var jFr=["wss://eu.socket.novu.co",Ale,"wss://socket.novu-staging.co","wss://socket-worker-local.cli-shortener.workers.dev"],zFr={"https://eu.ws.novu.co":"wss://eu.socket.novu.co","https://ws.novu.co":Ale,"https://dev.ws.novu.co":"wss://socket.novu-staging.co"};function UFr(t){return t?zFr[t]||t:Ale}function qFr(t){return!t||jFr.includes(t)}function GFr({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){const r=UFr(t);return(qFr(r)?"partysocket":"socket.io")==="partysocket"?new OFr({socketUrl:r,inboxServiceInstance:e,eventEmitterInstance:n}):new $Fr({socketUrl:r,inboxServiceInstance:e,eventEmitterInstance:n})}var lk,Nh,yT,ble,HFr=class{constructor(t){qa(this,lk),qa(this,Nh),qa(this,yT),qa(this,ble);var e,n,r;di(this,ble,t),di(this,yT,new AFr({apiUrl:t.apiUrl||t.backendUrl,userAgent:t.__userAgent})),di(this,lk,new bFr);const i=jNe({subscriberId:t.subscriberId,subscriber:t.subscriber}),o=GDt(t.context);di(this,Nh,new MFr({applicationIdentifier:t.applicationIdentifier||"",subscriberHash:t.subscriberHash,subscriber:i,defaultSchedule:t.defaultSchedule,context:t.context,contextHash:t.contextHash},tn(this,yT),tn(this,lk))),tn(this,Nh).initialize(),this.notifications=new xFr({useCache:(e=t.useCache)!=null?e:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.preferences=new RFr({useCache:(n=t.useCache)!=null?n:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.subscriptions=new mFr({subscriber:i,contextKey:o,useCache:(r=t.useCache)!=null?r:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.socket=GFr({socketUrl:t.socketUrl,eventEmitterInstance:tn(this,lk),inboxServiceInstance:tn(this,yT)}),this.on=(l,u)=>{this.socket.isSocketEvent(l)&&this.socket.connect();const d=tn(this,lk).on(l,u);return()=>{d()}},this.off=(l,u)=>{tn(this,lk).off(l,u)}}get applicationIdentifier(){return tn(this,Nh).applicationIdentifier}get subscriberId(){return tn(this,Nh).subscriberId}get context(){return tn(this,Nh).context}get options(){return tn(this,ble)}get contextKey(){return GDt(tn(this,Nh).context)}clearCache(){this.notifications.cache.clearAll(),this.preferences.cache.clearAll(),this.preferences.scheduleCache.clearAll(),this.subscriptions.cache.clearAll()}changeSubscriber(t){return Rr(this,null,function*(){yield tn(this,Nh).initialize({applicationIdentifier:tn(this,Nh).applicationIdentifier||"",subscriberHash:t.subscriberHash,subscriber:t.subscriber,context:tn(this,Nh).context,contextHash:tn(this,Nh).contextHash}),this.clearCache(),(yield this.socket.disconnect()).error||(yield this.socket.connect())})}changeContext(t){return Rr(this,null,function*(){const e=tn(this,Nh).subscriber;if(!e)throw new Error("Cannot change context without an active subscriber");yield tn(this,Nh).initialize({applicationIdentifier:tn(this,Nh).applicationIdentifier||"",subscriberHash:tn(this,Nh).subscriberHash,subscriber:e,context:t.context,contextHash:t.contextHash}),this.clearCache(),(yield this.socket.disconnect()).error||(yield this.socket.connect())})}};lk=new WeakMap,Nh=new WeakMap,yT=new WeakMap,ble=new WeakMap;var WFr="3.13.0",YFr="@novu/react",VFr=`${YFr}@${WFr}`,YNt=T.createContext(void 0),KFr=t=>{const{subscriberId:e,...n}=t,r=T.useMemo(()=>jNe({subscriberId:e,subscriber:t.subscriber}),[e,t.subscriber]),i=n.applicationIdentifier?n.applicationIdentifier:"",o={...n,applicationIdentifier:i,subscriber:r};return A.jsx(ZFr,{...o,applicationIdentifier:i,userAgentType:"hooks",children:t.children})},ZFr=t=>{const e=t.applicationIdentifier||"",n=T.useMemo(()=>jNe({subscriberId:t.subscriberId,subscriber:t.subscriber}),[t.subscriberId,t.subscriber]),{children:r,subscriberHash:i,contextHash:o,backendUrl:l,apiUrl:u,socketUrl:d,useCache:p,userAgentType:m,defaultSchedule:g,context:h}=t,f=T.useMemo(()=>new HFr({applicationIdentifier:e,subscriberHash:i,contextHash:o,backendUrl:l,apiUrl:u,socketUrl:d,useCache:p,__userAgent:`${VFr} ${m}`,subscriber:n,defaultSchedule:g,context:h}),[e,i,n,h,o,l,u,d,p,m]);return A.jsx(YNt.Provider,{value:f,children:r})},ARe=()=>{const t=T.useContext(YNt);if(!t)throw new Error("useNovu must be used within a <NovuProvider />");return t},yle=t=>{const e=T.useRef(t);return e.current=t,e};function XFr(t,e){if(!("locks"in navigator))return e(t),()=>{};let n=!1,r;const i=new Promise(o=>{r=o});return navigator.locks.request(t,()=>(n||e(t),i)),()=>{n=!0,r()}}var JFr=({channelName:t,onMessage:e})=>{const[n]=T.useState(typeof BroadcastChannel<"u"?new BroadcastChannel(t):void 0),r=i=>{n?.postMessage(i)};return T.useEffect(()=>{const i=o=>{e(o.data)};return n?.addEventListener("message",i),()=>{n?.removeEventListener("message",i)}},[]),{postMessage:r}},bRe=({event:t,eventHandler:e})=>{const n=ARe(),r=`nv_ws_connection:a=${n.applicationIdentifier}:s=${n.subscriberId}:c=${n.contextKey}:e=${t}`,{postMessage:i}=JFr({channelName:r,onMessage:e}),o=l=>{e(l),i(l)};T.useEffect(()=>{let l;const u=XFr(r,()=>{l=n.on(t,o)});return()=>{l&&l(),u()}},[])},e8r=t=>{const{filters:e,onSuccess:n,onError:r}=t,{notifications:i}=ARe(),o=yle(e),[l,u]=T.useState(),[d,p]=T.useState(),[m,g]=T.useState(!0),[h,f]=T.useState(!1),b=async(v,_)=>{const w=_||o.current,x=w.map(S=>({count:0,filter:S}));let k=[];if(v)for(let S=0;S<x.length;S++){const I=w[S],B=!I.severity||Array.isArray(I.severity)&&I.severity.length===0||Array.isArray(I.severity)&&I.severity.includes(v.severity)||!Array.isArray(I.severity)&&I.severity===v.severity;rRe(I.tags,v.tags)&&B&&k.push(I)}else k=w;if(k.length===0)return;f(!0);const C=await i.count({filters:k});if(f(!1),g(!1),C.error){u(C.error),r?.(C.error);return}const E=C.data;n?.(E.counts),p(S=>{const I=[],B=E.counts;for(let N=0;N<x.length;N++){const L=x[N].filter,R=B.find(D=>Voe(D.filter,L))||S?.[N];R&&I.push(R)}return I})};return bRe({event:"notifications.notification_received",eventHandler:v=>{b(v.result)}}),bRe({event:"notifications.unread_count_changed",eventHandler:()=>{b()}}),T.useEffect(()=>{u(void 0),g(!0),f(!1),b(void 0,e)},[JSON.stringify(e)]),{counts:d,error:l,refetch:async()=>{await b()},isLoading:m,isFetching:h}},t8r=t=>{const{tags:e,data:n,read:r,archived:i=!1,snoozed:o=!1,seen:l,severity:u,limit:d=10,onSuccess:p,onError:m}=t||{},g=yle(d),h=yle({tags:e,data:n,read:r,archived:i,snoozed:o,seen:l,severity:u}),f=ARe(),[b,y]=T.useState(),[v,_]=T.useState(),[w,x]=T.useState(!0),[k,C]=T.useState(!1),[E,S]=T.useState(!1),I=b?.length,B=I?b[I-1].id:void 0,N=yle(B);T.useEffect(()=>{const $=({data:Q})=>{!Q||!Voe(h.current,Q.filter)||(y(Q.notifications),S(Q.hasMore))},j=f.on("notifications.list.updated",$);return()=>{j()}},[h,f]),bRe({event:"notifications.notification_received",eventHandler:({result:$})=>{const j=h.current;if(oFr($,j)){const z={...j,limit:g.current};f.notifications.cache.unshift(z,$)}}});const L=T.useCallback(async $=>{$?.refetch&&(_(void 0),x(!0),C(!1)),C(!0);const j=await f.notifications.list({...h.current,limit:d,after:$?.refetch?void 0:N.current});if(j.error)_(j.error),m?.(j.error),x(!1),C(!1);else if(j.data){const Q=j.data;p?.(Q.notifications),y(Q.notifications),S(Q.hasMore),x(!1),C(!1)}},[f,h,N,d,m,p]);T.useEffect(()=>{f.notifications.clearCache({filter:h.current}),L({refetch:!0})},[h,f,JSON.stringify(h.current),L]);const M=T.useCallback(()=>(f.notifications.clearCache({filter:h.current}),L({refetch:!0})),[h,f,L]),R=T.useCallback(async()=>{if(!(!E||k))return L()},[E,k,L]),D=T.useCallback(async()=>await f.notifications.readAll({tags:h.current.tags,data:h.current.data}),[h,f]),P=T.useCallback(async()=>await f.notifications.seenAll({tags:h.current.tags,data:h.current.data}),[h,f]),O=T.useCallback(async()=>await f.notifications.archiveAll({tags:h.current.tags,data:h.current.data}),[h,f]),F=T.useCallback(async()=>await f.notifications.archiveAllRead({tags:h.current.tags,data:h.current.data}),[h,f]);return{readAll:D,seenAll:P,archiveAll:O,archiveAllRead:F,notifications:b,error:v,isLoading:w,isFetching:k,refetch:M,fetchMore:R,hasMore:E}};const yRe=[{id:"pwa-install",titleKey:"notifications.system.pwa.title",bodyKey:"notifications.system.pwa.body",dismissStorageKey:"xyzen-pwa-prompt-dismissed",condition:()=>{const t=window.matchMedia("(display-mode: standalone)").matches;return window.matchMedia("(min-width: 1024px)").matches&&!t}}];function n8r(){const{t}=En(),[e,n]=T.useState(()=>{const o=new Set;for(const l of yRe)localStorage.getItem(l.dismissStorageKey)&&o.add(l.id);return o}),r=T.useMemo(()=>yRe.filter(o=>!e.has(o.id)&&o.condition()).map(o=>({id:o.id,title:t(o.titleKey),body:t(o.bodyKey)})),[t,e]),i=T.useCallback(o=>{const l=yRe.find(u=>u.id===o);l&&localStorage.setItem(l.dismissStorageKey,"true"),n(u=>new Set(u).add(o))},[]);return{notifications:r,dismiss:i,count:r.length}}const r8r=[{key:"all",icon:D9n},{key:"unread",icon:tlt},{key:"archived",icon:Oke}],a8r=/\n<!-- meta:(.*?) -->$/;function i8r(t){const e=a8r.exec(t);if(!e)return{body:t,title:"",agentName:"",agentAvatar:"",url:"",messageId:""};const n=t.slice(0,e.index);try{const r=JSON.parse(e[1]);return{body:n,title:r.title??"",agentName:r.agent_name??"",agentAvatar:r.agent_avatar??"",url:r.url??"",messageId:r.message_id??""}}catch{return{body:t,title:"",agentName:"",agentAvatar:"",url:"",messageId:""}}}function VNt({items:t,onDismiss:e}){const{t:n}=En();return t.length===0?null:A.jsxs("div",{className:"border-b border-neutral-100 dark:border-neutral-800/60",children:[A.jsx("div",{className:"px-4 pt-2 pb-1",children:A.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-neutral-400 dark:text-neutral-500",children:n("notifications.system.title")})}),t.map(r=>A.jsxs("div",{className:"group flex gap-3 px-4 py-3 bg-amber-50/40 dark:bg-amber-950/10",children:[A.jsx("div",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-600 dark:bg-amber-500/10 dark:text-amber-400",children:A.jsx(Fae,{className:"h-4.5 w-4.5"})}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsx("p",{className:"text-[13px] font-semibold text-neutral-900 dark:text-neutral-100",children:r.title}),A.jsx("p",{className:"mt-0.5 text-[13px] leading-snug text-neutral-500 dark:text-neutral-400",children:r.body})]}),A.jsx("button",{onClick:()=>e(r.id),className:"flex-shrink-0 self-start rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-200/70 hover:text-neutral-600 dark:hover:bg-neutral-700/50 dark:hover:text-neutral-300",title:n("notifications.system.dismiss"),children:A.jsx(D1,{className:"h-3.5 w-3.5"})})]},r.id))]})}function s8r({systemCount:t=0}){const{counts:e}=e8r({filters:[{read:!1}]}),n=(e?.[0]?.count??0)+t;return n===0?null:A.jsx("span",{className:"absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-red-500 px-1 text-[10px] font-bold text-white shadow-sm",children:n>99?"99+":n})}const oG="rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-200/70 hover:text-neutral-600 active:bg-neutral-200/70 dark:hover:bg-neutral-700/50 dark:hover:text-neutral-300",o8r=T.memo(function({notification:e,isArchivedView:n,onNavigate:r}){const i=$Dt(e.createdAt),o=i8r(e.body??""),l=T.useCallback(async()=>{e.isRead||await e.read();const h=o.url||e.redirect?.url;if(!h)return;const f=/\/#\/chat\/([a-zA-Z0-9_-]+)/.exec(h),b=/[?&]topic=([^&]+)/.exec(h),y=f?.[1]??b?.[1];y&&r?r(y,o.messageId||void 0):window.location.hash=`#${h}`},[e,o.url,o.messageId,r]),u=T.useCallback(async h=>{h.stopPropagation(),e.isRead?await e.unread():await e.read()},[e]),d=T.useCallback(async h=>{h.stopPropagation(),await e.delete()},[e]),p=T.useCallback(async h=>{h.stopPropagation(),await e.unarchive()},[e]),m=T.useCallback(async h=>{h.stopPropagation(),await e.archive()},[e]),g=o.agentName||o.title;return A.jsxs(Ct.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,x:60},transition:{duration:.2},onClick:l,className:Yt("group relative flex cursor-pointer gap-3 px-4 py-3","border-b border-neutral-100 dark:border-neutral-800/60","transition-colors hover:bg-neutral-50/80 dark:hover:bg-neutral-800/40",!e.isRead&&"bg-blue-50/40 dark:bg-blue-950/20"),children:[A.jsxs("div",{className:"relative flex-shrink-0 pt-0.5",children:[o.agentAvatar?A.jsx("img",{src:o.agentAvatar,alt:g,className:"h-9 w-9 rounded-full object-cover"}):A.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-indigo-600 text-xs font-semibold text-white",children:(g||"N").charAt(0).toUpperCase()}),!e.isRead&&A.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2 border-white bg-blue-500 dark:border-neutral-900"})]}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsxs("div",{className:"flex items-center gap-1",children:[g&&A.jsx("p",{className:"truncate text-[13px] font-semibold text-neutral-900 dark:text-neutral-100",children:g}),A.jsx("span",{className:"flex-shrink-0 text-[11px] text-neutral-400 dark:text-neutral-500",children:i}),A.jsx("div",{className:"ml-auto flex flex-shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 max-md:opacity-100",children:n?A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:p,className:oG,title:"Restore",children:A.jsx(slt,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:d,className:oG,title:"Delete",children:A.jsx(qte,{className:"h-3.5 w-3.5"})})]}):A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:u,className:oG,title:e.isRead?"Mark as unread":"Mark as read",children:e.isRead?A.jsx(tlt,{className:"h-3.5 w-3.5"}):A.jsx(sh,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:m,className:oG,title:"Archive",children:A.jsx(Oke,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:d,className:oG,title:"Delete",children:A.jsx(qte,{className:"h-3.5 w-3.5"})})]})})]}),A.jsx("p",{className:Yt("mt-0.5 line-clamp-2 text-[13px] leading-snug",g?"text-neutral-500 dark:text-neutral-400":"text-neutral-700 dark:text-neutral-300"),children:o.body})]})]})});function l8r({filter:t,onNavigate:e}){const{t:n}=En(),{notifications:r,isLoading:i,hasMore:o,fetchMore:l,readAll:u,archiveAllRead:d}=t8r(t),p=!!t.archived,[m,g]=T.useState(!1),h=T.useCallback(async()=>{if(!(!r||r.length===0||m)){g(!0);try{await Promise.all(r.map(b=>b.delete()))}finally{g(!1)}}},[r,m]),f=T.useRef(null);return T.useEffect(()=>{if(!f.current||!o)return;const b=new IntersectionObserver(([y])=>{y.isIntersecting&&l()},{rootMargin:"200px"});return b.observe(f.current),()=>b.disconnect()},[o,l]),A.jsxs("div",{className:"flex h-full flex-col",children:[!p&&A.jsxs("div",{className:"flex items-center justify-end gap-1 border-b border-neutral-100 px-4 py-1.5 dark:border-neutral-800/60",children:[A.jsx("button",{onClick:()=>u(),className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800/40 dark:hover:text-neutral-300",title:n("notifications.actions.readAll"),children:A.jsx(g9n,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:()=>d(),className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800/40 dark:hover:text-neutral-300",title:n("notifications.actions.archiveRead"),children:A.jsx(Oke,{className:"h-3.5 w-3.5"})})]}),p&&r&&r.length>0&&A.jsx("div",{className:"flex items-center justify-end gap-1 border-b border-neutral-100 px-4 py-1.5 dark:border-neutral-800/60",children:A.jsxs(BNe,{children:[A.jsx(qPr,{asChild:!0,children:A.jsx("button",{disabled:m,className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-red-50 hover:text-red-500 disabled:opacity-40 dark:hover:bg-red-500/10 dark:hover:text-red-400",title:n("notifications.actions.deleteAll"),children:A.jsx(qte,{className:"h-3.5 w-3.5"})})}),A.jsxs(DNe,{className:"sm:max-w-sm rounded-sm",children:[A.jsxs(NNe,{children:[A.jsx(LNe,{className:"text-sm",children:n("notifications.actions.deleteAll")}),A.jsx(MNe,{className:"text-xs",children:n("notifications.actions.deleteAllConfirm")})]}),A.jsxs(RNe,{children:[A.jsx(ONe,{className:"h-8 rounded-sm text-xs",children:n("common.cancel")}),A.jsx(PNe,{onClick:h,className:"h-8 rounded-sm bg-red-500 text-xs text-white hover:bg-red-600 dark:bg-red-600 dark:hover:bg-red-500",children:n("notifications.actions.confirmDelete")})]})]})]})}),A.jsxs("div",{className:"custom-scrollbar flex-1 overflow-y-auto",children:[A.jsx(Fr,{mode:"popLayout",children:r?.map(b=>A.jsx(o8r,{notification:b,isArchivedView:p,onNavigate:e},b.id))}),i&&A.jsx("div",{className:"space-y-1 p-4",children:Array.from({length:3}).map((b,y)=>A.jsxs("div",{className:"flex animate-pulse gap-3 py-3",children:[A.jsx("div",{className:"h-9 w-9 flex-shrink-0 rounded-full bg-neutral-200 dark:bg-neutral-700"}),A.jsxs("div",{className:"flex-1 space-y-2",children:[A.jsx("div",{className:"h-3 w-3/4 rounded bg-neutral-200 dark:bg-neutral-700"}),A.jsx("div",{className:"h-3 w-1/2 rounded bg-neutral-200 dark:bg-neutral-700"})]})]},y))}),!i&&(!r||r.length===0)&&A.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-neutral-400 dark:text-neutral-500",children:[A.jsx(Fae,{className:"mb-3 h-10 w-10 opacity-40"}),A.jsx("p",{className:"text-sm",children:n("notifications.empty")})]}),o&&A.jsx("div",{ref:f,className:"h-4"})]})]})}const c8r={all:{archived:!1},unread:{read:!1,archived:!1},archived:{archived:!0}};function KNt({onNavigate:t}){const{t:e}=En(),[n,r]=T.useState("all");return A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsx("div",{className:"px-4 pt-1 pb-1.5",children:A.jsx("div",{className:"flex rounded-lg bg-neutral-100/80 p-0.5 dark:bg-neutral-800/50",children:r8r.map(({key:i,icon:o})=>A.jsxs("button",{onClick:()=>r(i),className:Yt("relative flex flex-1 items-center justify-center gap-1.5 rounded-md py-1.5 text-xs font-medium transition-colors",n===i?"text-neutral-900 dark:text-neutral-100":"text-neutral-500 hover:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-200"),children:[n===i&&A.jsx(Ct.div,{layoutId:"notification-tab",className:"absolute inset-0 rounded-md bg-white shadow-sm dark:bg-neutral-700",transition:{type:"spring",stiffness:400,damping:30}}),A.jsxs("span",{className:"relative z-10 flex items-center gap-1.5",children:[A.jsx(o,{className:"h-3.5 w-3.5"}),e(`notifications.filter.${i}`)]})]},i))})}),A.jsx(l8r,{filter:c8r[n],onNavigate:t},n)]})}function u8r(){const{t}=En(),e=Hq(),n=n8r(),{activateChannel:r,setActivePanel:i,requestFocusAgent:o,setMobilePage:l,setMobileCeoOverlay:u,highlightMessage:d}=Un(Ws(v=>({activateChannel:v.activateChannel,setActivePanel:v.setActivePanel,requestFocusAgent:v.requestFocusAgent,setMobilePage:v.setMobilePage,setMobileCeoOverlay:v.setMobileCeoOverlay,highlightMessage:v.highlightMessage}))),[p,m]=T.useState(!1),[g,h]=T.useState(!1),f=T.useCallback(()=>m(v=>!v),[]),b=T.useCallback(()=>m(!1),[]),y=T.useCallback(async(v,_)=>{b(),i("chat"),e&&(u(!1),l(1)),await r(v);const w=Un.getState().channels[v];w?.agentId&&o(w.agentId),_&&d(_)},[b,r,i,o,e,l,u,d]);return T.useEffect(()=>{if(!p)return;const v=_=>{_.key==="Escape"&&b()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[p,b]),A.jsxs(A.Fragment,{children:[A.jsxs("div",{className:"relative",children:[A.jsxs(Ct.button,{whileHover:{scale:1.1},whileTap:{scale:.9},onClick:f,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:"relative flex items-center justify-center h-7 w-7 text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors",children:[A.jsx(Fae,{className:"h-4.5 w-4.5"}),A.jsx(s8r,{systemCount:n.count})]}),A.jsx(Fr,{children:g&&!p&&!e&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-10 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[t("notifications.bell.title"),A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})})]}),e&&A.jsx(Hc,{isOpen:p,onClose:b,mobileHeight:"h-[85vh]",size:"sm",children:A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsxs("div",{className:"flex items-center justify-between px-5 pt-6 pb-2 md:py-2",children:[A.jsx("h2",{className:"text-base font-semibold text-neutral-900 dark:text-neutral-100",children:t("notifications.bell.title")}),A.jsx("button",{onClick:b,className:"rounded-lg p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800 dark:hover:text-neutral-300",children:A.jsx(D1,{className:"h-5 w-5"})})]}),A.jsx(VNt,{items:n.notifications,onDismiss:n.dismiss}),A.jsx(KNt,{onNavigate:y})]})}),!e&&zi.createPortal(A.jsx(Fr,{children:p&&A.jsxs(A.Fragment,{children:[A.jsx(Ct.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-[70]",onClick:b}),A.jsx(Ct.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",damping:30,stiffness:300,mass:.8},className:Yt("fixed top-0 right-0 z-[71] h-full w-[380px]","bg-white/90 dark:bg-neutral-900/90","backdrop-blur-2xl","border-l border-neutral-200/60 dark:border-neutral-700/50","shadow-2xl","text-neutral-900 dark:text-neutral-100"),style:{paddingBottom:GA},children:A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsxs("div",{className:"flex items-center justify-between px-5 py-4",children:[A.jsx("h2",{className:"text-base font-semibold",children:t("notifications.bell.title")}),A.jsx("button",{onClick:b,className:"rounded-lg p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800 dark:hover:text-neutral-300",children:A.jsx(D1,{className:"h-5 w-5"})})]}),A.jsx(VNt,{items:n.notifications,onDismiss:n.dismiss}),A.jsx(KNt,{onNavigate:y})]})},"notification-drawer")]})}),document.body)]})}function ZNt(){const{notificationEnabled:t,novuAppIdentifier:e,novuApiUrl:n,novuWsUrl:r}=FNe(),i=ah();return!t||!e||!i.isAuthenticated?null:A.jsx(KFr,{applicationIdentifier:e,subscriberId:i.user?.id??"",backendUrl:n||void 0,socketUrl:r||void 0,children:A.jsx(u8r,{})})}const GA=72,Rm=8,lF=Yl()?28:Rm;function d8r({mouseX:t,item:e,isActive:n,onClick:r}){const i=T.useRef(null),[o,l]=T.useState(!1),u=Ub(t,y=>{const v=i.current?.getBoundingClientRect()??{x:0,width:0};return y-v.x-v.width/2}),d=Ub(u,[-100,0,100],[44,56,44]),p=Ub(u,[-100,0,100],[20,26,20]),m=Ub(u,[-100,0,100],[0,-6,0]),g=YN(d,{mass:.1,stiffness:200,damping:15}),h=YN(p,{mass:.1,stiffness:200,damping:15}),f=YN(m,{mass:.1,stiffness:200,damping:15}),b=e.icon;return A.jsxs(Ct.button,{ref:i,style:{width:g,height:g,y:f},onClick:r,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),className:Yt("relative flex flex-col items-center justify-center gap-0.5 rounded-sm transition-colors duration-200","bg-white/80 dark:bg-neutral-800/60","hover:bg-white dark:hover:bg-neutral-700/80","border border-neutral-200/40 dark:border-neutral-700/30",n&&"bg-white dark:bg-neutral-700/80 shadow-md"),children:[A.jsx(Fr,{children:o&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-10 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[e.label,A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})}),A.jsx(Ct.div,{style:{width:h,height:h},className:"flex items-center justify-center",children:A.jsx(b,{className:Yt("w-full h-full transition-colors duration-200",n?"text-indigo-600 dark:text-indigo-400":"text-neutral-600 dark:text-neutral-400")})}),n&&A.jsx(Ct.div,{layoutId:"dock-active-indicator",className:"h-1 w-1 rounded-full bg-indigo-500",transition:{type:"spring",stiffness:300,damping:30}})]})}function p8r({compact:t=!1}){const e=ah(),{t:n}=En(),[r,i]=T.useState(!1),[o,l]=T.useState(!1),[u,d]=T.useState(!1),[p,m]=T.useState(!1),g=Un(y=>y.openSettingsModal),h=BO(),f=e.isAuthenticated||!!e.token,b=t?"h-10 w-10":"h-11 w-11";return e.isLoading?A.jsx("div",{className:Yt(b,"flex items-center justify-center rounded-full bg-white/80 dark:bg-neutral-800/60"),children:A.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-neutral-300 border-t-indigo-600 dark:border-neutral-700 dark:border-t-indigo-500"})}):f?A.jsxs(A.Fragment,{children:[A.jsxs(iq,{open:r,onOpenChange:i,children:[A.jsx(sq,{asChild:!0,children:A.jsx(Ct.button,{whileHover:{scale:1.05},whileTap:{scale:.95},className:Yt(b,"relative flex items-center justify-center rounded-full overflow-hidden transition-shadow hover:shadow-lg","ring-2 ring-neutral-200/60 dark:ring-neutral-700/50"),children:e.user?.avatar?A.jsx("img",{src:e.user.avatar,alt:e.user?.username??"User",className:"h-full w-full object-cover"}):A.jsx("div",{className:"flex h-full w-full items-center justify-center bg-gradient-to-br from-indigo-500 to-purple-600",children:A.jsx(GP,{className:"h-5 w-5 text-white"})})})}),A.jsxs(oq,{align:"start",side:"top",sideOffset:12,className:"w-72 mb-2",children:[A.jsxs(NBe,{className:"flex items-center gap-3 p-3",children:[e.user?.avatar?A.jsx("img",{src:e.user.avatar,alt:e.user?.username??"User",className:"h-10 w-10 rounded-full"}):A.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-indigo-500 to-purple-600",children:A.jsx(GP,{className:"h-5 w-5 text-white"})}),A.jsx("div",{className:"flex flex-col",children:A.jsx("span",{className:"text-sm font-semibold text-neutral-900 dark:text-neutral-100",children:e.user?.username??n("app.authStatus.loggedIn")})})]}),A.jsx(EO,{}),h&&A.jsx("div",{className:"px-3 py-2",children:A.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-gradient-to-r from-indigo-50 to-purple-50 dark:from-indigo-950/30 dark:to-purple-950/30 px-3 py-2",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx(xo,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),A.jsxs("div",{children:[A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:n("app.authStatus.pointsBalance")}),A.jsx("div",{className:"text-lg font-bold text-indigo-600 dark:text-indigo-400",children:h.isLoading?"...":h.points??"--"})]})]}),A.jsx("button",{onClick:()=>{i(!1),d(!0)},className:"rounded-full p-1.5 text-neutral-400 hover:bg-white/50 hover:text-indigo-600 dark:hover:bg-neutral-800 dark:hover:text-indigo-400 transition-colors",children:A.jsx(pu,{className:"h-5 w-5"})})]})}),A.jsx(EO,{}),OA("developerReward")&&A.jsxs(lC,{onSelect:()=>{i(!1),m(!0)},className:"flex items-center gap-2 px-3 py-2 cursor-pointer",children:[A.jsx(qae,{className:"h-4 w-4"}),n("subscription.creator")]}),A.jsxs(lC,{onSelect:()=>{i(!1),g()},className:"flex items-center gap-2 px-3 py-2 cursor-pointer",children:[A.jsx(gh,{className:"h-4 w-4"}),n("app.authStatus.settings")]}),A.jsx(EO,{}),A.jsxs(lC,{onSelect:()=>{i(!1),U5()},className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/20",children:[A.jsx(E2e,{className:"h-4 w-4"}),n("app.authStatus.logout")]})]})]}),h&&A.jsx(NO,{isOpen:u,onClose:()=>d(!1)}),A.jsx(RBe,{isOpen:p,onClose:()=>m(!1)})]}):A.jsxs(A.Fragment,{children:[A.jsx(Ct.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>l(!0),className:Yt(b,"flex items-center justify-center rounded-full bg-white/80 dark:bg-neutral-800/60 border border-amber-200/60 dark:border-amber-700/50 transition-shadow hover:shadow-lg"),title:n("app.authStatus.unauthorized"),children:A.jsx(Fp,{className:"h-5 w-5 text-amber-500"})}),A.jsx(WSt,{isOpen:o,onClose:()=>l(!1),onSubmit:async y=>{await e.login(y)}})]})}const m8r="https://github.com/ScienceOL/Xyzen";function g8r(){const{backend:t}=lNe(),{t:e}=En(),[n,r]=T.useState(!1),[i,o]=T.useState(!1),u=k1()!=="zh-cn";return A.jsxs("div",{className:"relative flex items-center gap-1.5",children:[A.jsx(PPr,{onClick:()=>o(!0),children:e("app.toolbar.joinBeta")}),A.jsx(zPr,{isOpen:i,onClose:()=>o(!1)}),A.jsx("a",{href:m8r,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center h-7 w-7 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-neutral-700/50",children:A.jsx(Xot,{className:"h-4 w-4 text-neutral-500 dark:text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition-colors"})}),A.jsxs("div",{className:"relative flex items-center gap-1 cursor-default",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[A.jsx("span",{className:"text-[11px] font-medium text-neutral-500 dark:text-neutral-500 tabular-nums",children:t.version||"..."}),A.jsx("div",{className:"flex items-center justify-center h-4 w-4 rounded-sm",title:e(`app.region.${u?"international":"china"}`),children:A.jsx(nz,{className:Yt("h-3 w-3 transition-colors",u?"text-indigo-400/60 dark:text-indigo-500/60":"text-emerald-400/60 dark:text-emerald-500/60")})}),A.jsx(Fr,{children:n&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-12 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("span",{className:"font-medium",children:e(`app.region.${u?"international":"china"}`)}),A.jsx("span",{className:"text-neutral-400 dark:text-neutral-500",children:"•"}),A.jsx("span",{className:"text-neutral-300 dark:text-neutral-600",children:t.versionName||t.version})]}),A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})})]})]})}const XNt={free:{bg:"bg-neutral-100/80 dark:bg-neutral-800/80",text:"text-neutral-600 dark:text-neutral-400",border:"border-neutral-200/50 dark:border-neutral-700/50",icon:Gte},standard:{bg:"bg-blue-50/80 dark:bg-blue-950/40",text:"text-blue-600 dark:text-blue-400",border:"border-blue-200/50 dark:border-blue-800/50",icon:Ute},professional:{bg:"bg-purple-50/80 dark:bg-purple-950/40",text:"text-purple-600 dark:text-purple-400",border:"border-purple-200/50 dark:border-purple-800/50",icon:jte},ultra:{bg:"bg-amber-100/90 dark:bg-amber-950/40",text:"text-amber-600 dark:text-amber-400",border:"border-amber-300/70 dark:border-amber-800/50",icon:T1}};function JNt(t){return t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function h8r({visible:t,anchorRef:e,usage:n,daysLeft:r,roleName:i,isExpired:o,isUrgent:l,isWarning:u,respondingCount:d,chatLimit:p,hasOverQuota:m}){const g=e.current?.getBoundingClientRect(),h=t&&n&&g;return zi.createPortal(A.jsx(Fr,{children:h&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.2,ease:"easeOut"},style:{position:"fixed",bottom:window.innerHeight-g.top+8,right:window.innerWidth-g.right},className:"z-[60]",children:[A.jsx("div",{className:Yt("relative flex flex-col gap-1.5 min-w-[180px] rounded-2xl px-4 py-3 text-xs shadow-2xl","bg-white/90 text-neutral-900 backdrop-blur-lg","border border-neutral-200/60","dark:bg-white/5 dark:text-white","dark:border-white/[0.08]"),children:A.jsxs("div",{className:"flex flex-col gap-1.5",children:[r!==null&&i!=="free"&&A.jsxs("div",{className:"flex flex-col gap-1 pb-1.5 mb-0.5 border-b border-neutral-200/40 dark:border-neutral-700/40",children:[A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Expires"}),A.jsx("span",{className:Yt(o&&"text-red-500 dark:text-red-400",l&&"text-red-500 dark:text-red-400",u&&"text-amber-500 dark:text-amber-400"),children:o?"Expired":r===0?"Today":`${r} day${r===1?"":"s"}`})]}),!o&&A.jsx("div",{className:"h-1 rounded-full bg-neutral-200 dark:bg-neutral-700/50 overflow-hidden",children:A.jsx("div",{className:Yt("h-full rounded-full transition-all",l&&"bg-red-500",u&&"bg-amber-500",!l&&!u&&"bg-emerald-500"),style:{width:`${Math.min(100,Math.max(2,r/30*100))}%`}})})]}),A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Storage"}),A.jsxs("span",{className:"font-medium",children:[JNt(n.storage.used_bytes)," /"," ",JNt(n.storage.limit_bytes)]})]}),d>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Chats"}),A.jsxs("span",{className:"font-medium",children:[d," / ",p||"∞"]})]}),n.sandboxes.limit>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Sandboxes"}),A.jsxs("span",{className:"font-medium",children:[n.sandboxes.used," / ",n.sandboxes.limit]})]}),n.scheduled_tasks?.limit>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Tasks"}),A.jsxs("span",{className:"font-medium",children:[n.scheduled_tasks.used," / ",n.scheduled_tasks.limit]})]}),A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Files"}),A.jsxs("span",{className:"font-medium",children:[n.files.used," / ",n.files.limit]})]}),m&&A.jsx("div",{className:"text-red-500 dark:text-red-400 text-[10px] mt-0.5 font-semibold",children:"Quota exceeded"})]})}),A.jsx("div",{className:"absolute -bottom-[5px] right-4 h-2.5 w-2.5 rotate-45 bg-white/90 dark:bg-white/5 backdrop-blur-lg border-b border-r border-neutral-200/60 dark:border-white/[0.06]"})]})}),document.body)}function f8r(){const{t}=En(),e=DO(),n=BO(),r=Un(B=>B.respondingChannelIds.size),[i,o]=T.useState(!1),[l,u]=T.useState(!1),d=T.useRef(null);if(!e||e.subQuery.isLoading)return null;const{subQuery:p,usageQuery:m,roleName:g}=e,h=t(`subscription.plan.${g}`),f=p.data?.subscription?.expires_at,b=p.data?.can_claim_credits??!1,y=XNt[g]??XNt.free,v=g==="free",_=!v&&f?new Date(f)<new Date:!1,w=!v&&f?Math.max(0,Math.ceil((new Date(f).getTime()-Date.now())/(1e3*60*60*24))):null,x=w!==null&&w<=3&&!_,k=w!==null&&w<=7&&!x&&!_,C=m.data,E=C?.chats.limit??0,S=C&&(E>0&&r>E||C.storage.usage_percentage>100),I=y.icon;return A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"relative",ref:d,children:A.jsxs(Ct.button,{whileHover:{scale:1.03},whileTap:{scale:.97},onClick:()=>o(!0),onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:Yt("flex items-center gap-1.5 px-2.5 py-1 rounded-lg transition-colors border text-xs font-medium",y.bg,y.text,y.border,_&&"opacity-60",S&&"ring-1 ring-red-400/50"),children:[A.jsx(I,{className:"size-3.5"}),A.jsx("span",{children:h}),_&&A.jsx("span",{className:"text-[10px] text-red-500 dark:text-red-400 font-semibold",children:"expired"}),b&&!_&&A.jsxs("span",{className:"absolute -top-1 -right-1 flex h-2.5 w-2.5",children:[A.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75"}),A.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-red-500"})]})]})}),A.jsx(h8r,{visible:l&&!!C,anchorRef:d,usage:C??null,daysLeft:w,roleName:g,isExpired:_,isUrgent:x,isWarning:k,respondingCount:r,chatLimit:E,hasOverQuota:!!S}),n&&A.jsx(NO,{isOpen:i,onClose:()=>o(!1)})]})}function A8r({activePanel:t,onPanelChange:e,className:n}){const{t:r}=En(),i=ah(),o=sy(1/0),l=YBe(),[u,d]=T.useState(!1),p=Un(f=>f.dockMinimized),m=i.isAuthenticated||!!i.token,g=[{id:"chat",icon:Wb,label:r("app.activityBar.chat"),panel:"chat"},{id:"knowledge",icon:V1,label:r("app.activityBar.knowledge"),panel:"knowledge"},{id:"skills",icon:zI,label:r("app.activityBar.skills","Skills"),panel:"skills"},{id:"memory",icon:L2e,label:r("app.activityBar.memory"),panel:"memory"},{id:"sandbox",icon:Sf,label:r("app.activityBar.sandbox","Sandbox"),panel:"sandbox"},{id:"runner",icon:pU,label:r("app.activityBar.runner"),panel:"runner"},{id:"tasks",icon:W1,label:r("app.activityBar.tasks","Tasks"),panel:"tasks"},{id:"marketplace",icon:xo,label:r("app.activityBar.community"),panel:"marketplace"}],h=T.useCallback(f=>{f.panel&&e(f.panel),f.onClick?.()},[e]);return p?null:A.jsxs(A.Fragment,{children:[A.jsx("div",{className:Yt("fixed bottom-0 left-0 z-50 pb-2",n),style:{paddingLeft:Rm,paddingRight:Rm},children:A.jsx("div",{className:Yt("h-14 rounded-2xl px-4","bg-white/80 dark:bg-neutral-900/60","backdrop-blur-2xl","border border-neutral-200/50 dark:border-neutral-700/50"),style:{width:`calc(100vw - ${Rm*2}px)`,boxShadow:"0 8px 32px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.12)"},children:A.jsxs("div",{className:"flex h-full items-center",children:[A.jsx("div",{className:"shrink-0",children:A.jsx(p8r,{compact:!0})}),A.jsxs("div",{className:"flex items-center gap-3",children:[A.jsx("div",{className:"h-8 w-px bg-neutral-300/80 dark:bg-neutral-600/30 ml-3"}),A.jsx("div",{className:"flex items-end gap-1.5",onMouseMove:f=>o.set(f.pageX),onMouseLeave:()=>o.set(1/0),children:g.map(f=>A.jsx(d8r,{mouseX:o,item:f,isActive:f.panel===t,onClick:()=>h(f)},f.id))})]}),A.jsx("div",{className:"flex-1"}),A.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[A.jsx(g8r,{}),A.jsx("div",{className:"h-6 w-px bg-neutral-300/80 dark:bg-neutral-600/30"}),l&&m&&A.jsx(Ct.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>d(!0),className:"relative flex items-center justify-center h-8 w-8 rounded-lg text-amber-600 transition-colors hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300",title:r("app.toolbar.checkIn"),children:A.jsx(vR,{className:"h-5 w-5"})}),A.jsx("div",{className:"h-6 w-px bg-neutral-300/80 dark:bg-neutral-600/30"}),A.jsx(f8r,{}),A.jsx(ZNt,{})]})]})})}),l&&A.jsx(TNe,{isOpen:u,onClose:()=>d(!1)})]})}const b8r=ph("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[box-shadow,_color,_background-color,_border-color,_outline-color,_text-decoration-color,_fill,_stroke] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",accent:"bg-accent text-accent-foreground shadow-xs hover:bg-accent/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8 rounded-md","icon-lg":"size-10 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),[y8r,v8r]=QA("RippleButtonContext");function _8r({ref:t,onClick:e,hoverScale:n=1.05,tapScale:r=.95,asChild:i=!1,style:o,...l}){const[u,d]=ee.useState([]),p=ee.useRef(null);ee.useImperativeHandle(t,()=>p.current);const m=ee.useCallback(f=>{const b=p.current;if(!b)return;const y=b.getBoundingClientRect(),v=f.clientX-y.left,_=f.clientY-y.top,w={id:Date.now(),x:v,y:_};d(x=>[...x,w]),setTimeout(()=>{d(x=>x.filter(k=>k.id!==w.id))},600)},[]),g=ee.useCallback(f=>{m(f),e&&e(f)},[m,e]),h=i?G1:Ct.button;return A.jsx(y8r,{value:{ripples:u,setRipples:d},children:A.jsx(h,{ref:p,"data-slot":"ripple-button",onClick:g,whileTap:{scale:r},whileHover:{scale:n},style:{position:"relative",overflow:"hidden",...o},...l})})}function w8r({color:t="var(--ripple-button-ripple-color)",scale:e=10,transition:n={duration:.6,ease:"easeOut"},asChild:r=!1,style:i,...o}){const{ripples:l}=v8r(),u=r?G1:Ct.span;return l.map(d=>A.jsx(u,{initial:{scale:0,opacity:.5},animate:{scale:e,opacity:0},transition:n,style:{position:"absolute",borderRadius:"50%",pointerEvents:"none",width:"20px",height:"20px",backgroundColor:t,top:d.y-10,left:d.x-10,...i},...o},d.id))}const x8r={default:"[--ripple-button-ripple-color:var(--primary-foreground)]",accent:"[--ripple-button-ripple-color:var(--accent-foreground)]",destructive:"[--ripple-button-ripple-color:var(--destructive-foreground)]",outline:"[--ripple-button-ripple-color:var(--foreground)]",secondary:"[--ripple-button-ripple-color:var(--secondary-foreground)]",ghost:"[--ripple-button-ripple-color:var(--foreground)]",link:"[--ripple-button-ripple-color:var(--primary-foreground)]"};function k8r({className:t,variant:e,size:n,...r}){return A.jsx(_8r,{className:Yt(b8r({variant:e,size:n,className:t}),x8r[e]),...r})}function E8r(t){return A.jsx(w8r,{...t})}const eRt=["adventurer","avataaars","bottts","fun-emoji","lorelei","micah","miniavs","notionists","open-peeps","personas","pixel-art","shapes","thumbs"],lG=(t,e,n)=>n?`${n}/xyzen/api/v1/avatar/${t}/svg?seed=${encodeURIComponent(e)}`:`https://api.dicebear.com/9.x/${t}/svg?seed=${e}`,C8r=t=>{const e=[];return eRt.forEach(n=>{for(let r=0;r<6;r++){const i=`${n}_${r}_preset`;e.push({url:lG(n,i,t),seed:i,style:n})}}),e},tRt=t=>{if(!t)return"";try{const e=new URL(t).searchParams.get("seed");return e?decodeURIComponent(e):""}catch{const e=t.match(/[?&]seed=([^&]*)/);return e?decodeURIComponent(e[1]):""}};function vRe({currentAvatar:t,onSelect:e,backendUrl:n}){const{t:r}=En(),[i,o]=T.useState("avataaars"),[l,u]=T.useState(()=>tRt(t)),[d,p]=T.useState(!1);T.useEffect(()=>{const _=tRt(t);u(_)},[t]);const[m,g]=T.useState(!1),f=T.useMemo(()=>C8r(n),[n]).filter(_=>_.style===i),b=T.useCallback(async()=>{g(!0),await new Promise(x=>setTimeout(x,300));const _=Math.random().toString(36).slice(2,10),w=lG(i,_,n);e(w),g(!1)},[i,e,n]),y=T.useCallback(async()=>{if(!l.trim())return;g(!0),await new Promise(w=>setTimeout(w,200));const _=lG(i,l.trim(),n);e(_),g(!1)},[i,l,e,n]),v=T.useCallback(async _=>{g(!0),await new Promise(w=>setTimeout(w,150)),e(_),g(!1)},[e]);return A.jsxs("div",{className:"flex gap-5",children:[A.jsx("div",{className:"flex shrink-0 items-start pt-6 px-2",children:A.jsxs(Ct.div,{className:"group relative",whileHover:{scale:1.05},transition:{type:"spring",stiffness:300},children:[A.jsx("div",{className:"absolute -inset-1 rounded-full bg-linear-to-tr from-indigo-500 via-purple-500 to-pink-500 opacity-40 blur-md transition-opacity duration-500 group-hover:opacity-70"}),A.jsx(Fr,{children:m&&A.jsx(Ct.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-10 flex items-center justify-center rounded-full bg-white/50 dark:bg-black/50",children:A.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-indigo-500 border-t-transparent"})})}),A.jsx("img",{src:t||lG("avataaars","default",n),alt:"Current avatar",className:"relative h-20 w-20 rounded-full border-[3px] border-white bg-white shadow-xl dark:border-neutral-700 dark:bg-neutral-800"}),t&&!m&&A.jsx(Ct.div,{initial:{scale:0},animate:{scale:1},className:"absolute -bottom-0.5 -right-0.5 flex h-6 w-6 items-center justify-center rounded-full border-2 border-white bg-green-500 shadow dark:border-neutral-800",children:A.jsx(Vs,{className:"h-3 w-3 text-white"})})]})}),A.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[A.jsxs("div",{className:"space-y-1.5",children:[A.jsx("label",{className:"pl-0.5 text-[13px] font-medium text-neutral-600 dark:text-neutral-400",children:r("agents.sessionSettings.avatar.style")}),A.jsx("div",{className:"custom-scrollbar -mx-1 flex max-h-16 flex-wrap gap-1.5 overflow-y-auto p-1",children:eRt.map(_=>A.jsx(Vi,{type:"button",variant:i===_?"default":"outline",size:"sm",className:Yt("h-7 rounded-full px-2.5 text-xs transition-all duration-300",i===_?"border-transparent bg-indigo-600 text-white shadow-md shadow-indigo-500/25 hover:bg-indigo-700":"border-neutral-200 text-neutral-600 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-400 dark:hover:bg-neutral-800"),onClick:()=>o(_),children:_},_))})]}),A.jsx("div",{className:"grid grid-cols-8 gap-2",children:f.map((_,w)=>A.jsx(Ct.button,{type:"button",whileHover:{scale:1.12},whileTap:{scale:.95},onClick:()=>v(_.url),className:Yt("aspect-square h-16 rounded-full overflow-hidden border-2 transition-colors duration-200 shadow-sm hover:shadow-lg",t===_.url?"border-indigo-500 ring-2 ring-indigo-200 dark:ring-indigo-900 shadow-indigo-500/30":"border-transparent hover:border-neutral-300 dark:hover:border-neutral-600 bg-neutral-50 dark:bg-neutral-800"),children:A.jsx("img",{src:_.url,alt:`Avatar option ${w+1}`,className:"h-full w-full object-cover"})},w))}),A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsxs(k8r,{type:"button",variant:"outline",onClick:b,disabled:m,className:"h-8 shrink-0 gap-1.5 px-3 text-xs font-medium",children:[A.jsx(xo,{className:"h-3.5 w-3.5 text-indigo-500"}),A.jsx("span",{className:"truncate",children:r(m?"agents.sessionSettings.avatar.loading":"agents.sessionSettings.avatar.random")}),A.jsx(E8r,{})]}),A.jsxs("button",{type:"button",onClick:()=>p(_=>!_),className:"flex items-center gap-1 rounded px-1.5 py-1 text-xs text-neutral-400 transition-colors hover:text-neutral-600 dark:hover:text-neutral-300",children:[r("agents.sessionSettings.avatar.advanced"),A.jsx(Tx,{className:Yt("h-3 w-3 transition-transform duration-200",d&&"rotate-180")})]})]}),A.jsx(Fr,{children:d&&A.jsx(Ct.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:A.jsxs("div",{className:"flex gap-2 p-1",children:[A.jsx("div",{className:"flex-1",children:A.jsx(Qi,{type:"text",placeholder:r("agents.sessionSettings.avatar.seedPlaceholder"),value:l,onChange:_=>u(_.target.value),onKeyDown:_=>_.key==="Enter"&&y(),className:"text-xs",wrapperClassName:"h-8"})}),A.jsx(Vi,{type:"button",size:"sm",onClick:y,disabled:!l.trim()||m,className:"h-8 px-3 text-xs transition-all hover:shadow-md",children:r("agents.sessionSettings.avatar.apply")})]})})})]})]})}function nRt({isOpen:t,onClose:e,onCreated:n,parentId:r}){const{t:i}=En(),{createAgent:o,isCreatingAgent:l,backendUrl:u,agents:d}=Un(Ws(x=>({createAgent:x.createAgent,isCreatingAgent:x.isCreatingAgent,backendUrl:x.backendUrl,agents:x.agents}))),[p,m]=T.useState({name:"",description:"",prompt:""}),[g,h]=T.useState(""),[f,b]=T.useState(!1);T.useEffect(()=>{if(t&&!g){const x=Math.random().toString(36).slice(2,10);h(lG("avataaars",x,u))}},[t,g,u]);const y=x=>{const{name:k,value:C}=x.target;m(E=>({...E,[k]:C}))},v=async x=>{if(x.preventDefault(),!f){if(!p.name){alert(i("agents.errors.nameRequired"));return}if(d.some(k=>k.name===p.name)){alert(i("agents.errors.nameDuplicate"));return}b(!0);try{const k=await o({...p,avatar:g,parent_id:r??void 0,mcp_server_ids:[],user_id:"temp",mcp_servers:[],created_at:new Date().toISOString(),updated_at:new Date().toISOString()});w(),k&&n&&n(k)}catch(k){console.error("Failed to create agent:",k),alert(i("agents.errors.createFailed"))}finally{b(!1)}}},_=f||l||!p.name,w=()=>{m({name:"",description:"",prompt:""}),h(""),e()};return A.jsx(Hc,{isOpen:t,onClose:w,size:"md",children:A.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[A.jsx("div",{className:"shrink-0 px-5 pt-5 pb-1 md:pt-2",children:A.jsx("h2",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:i("agents.createTitle")})}),A.jsxs("form",{onSubmit:v,className:"flex-1 overflow-y-auto custom-scrollbar px-5 pb-5 space-y-5",children:[A.jsx(vRe,{currentAvatar:g,onSelect:h,backendUrl:u}),A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsx(hi,{label:i("agents.fields.name.required"),required:!0,children:A.jsx(Qi,{name:"name",value:p.name,onChange:y,placeholder:i("agents.fields.name.placeholder"),required:!0})}),A.jsx(hi,{label:i("agents.fields.description.label"),children:A.jsx(Qi,{name:"description",value:p.description,onChange:y,placeholder:i("agents.fields.description.placeholder")})}),A.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:[A.jsx(qc,{type:"button",onClick:w,className:"inline-flex items-center gap-2 rounded-md bg-neutral-100 py-2 px-4 text-sm font-medium text-neutral-700 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-200 dark:hover:bg-neutral-700 transition-colors",children:i("agents.actions.cancel")}),A.jsx(qc,{type:"submit",disabled:_,className:Yt("inline-flex items-center gap-2 rounded-md py-2 px-4 text-sm font-medium transition-colors",_?"bg-neutral-400 text-white cursor-not-allowed":"bg-indigo-600 text-white hover:bg-indigo-500"),children:i(f||l?"agents.actions.creating":"agents.actions.create")})]})]})]})})}class S8r{listSecrets(){return nn.get("/xyzen/api/v1/payment-secrets")}createSecret(e){return nn.post("/xyzen/api/v1/payment-secrets",e)}updateSecret(e,n){return nn.put(`/xyzen/api/v1/payment-secrets/${e}`,n)}deleteSecret(e){return nn.delete(`/xyzen/api/v1/payment-secrets/${e}`)}getBinding(e){return nn.get(`/xyzen/api/v1/agents/${e}/payment-binding`)}upsertBinding(e,n){return nn.put(`/xyzen/api/v1/agents/${e}/payment-binding`,n)}deleteBinding(e){return nn.delete(`/xyzen/api/v1/agents/${e}/payment-binding`)}}const ck=new S8r;class I8r{async createKnowledgeSet(e){return nn.post("/xyzen/api/v1/knowledge-sets/",e)}async listKnowledgeSets(e=!1){return nn.get("/xyzen/api/v1/knowledge-sets/",{params:{include_deleted:e||void 0}})}async getKnowledgeSet(e){return nn.get(`/xyzen/api/v1/knowledge-sets/${e}`)}async updateKnowledgeSet(e,n){return nn.patch(`/xyzen/api/v1/knowledge-sets/${e}`,n)}async deleteKnowledgeSet(e,n=!1){return nn.delete(`/xyzen/api/v1/knowledge-sets/${e}`,void 0,{params:{hard_delete:n}})}async linkFileToKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/${n}`)}async unlinkFileFromKnowledgeSet(e,n){return nn.delete(`/xyzen/api/v1/knowledge-sets/${e}/files/${n}`)}async getFilesInKnowledgeSet(e){return nn.get(`/xyzen/api/v1/knowledge-sets/${e}/files`)}async bulkLinkFilesToKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/bulk-link`,{file_ids:n})}async bulkUnlinkFilesFromKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/bulk-unlink`,{file_ids:n})}}const Rh=new I8r;class T8r{async listSkills(){return nn.get("/xyzen/api/v1/skills/")}async listAgentSkills(e){return nn.get(`/xyzen/api/v1/agents/${e}/skills`)}async attachSkill(e,n){const r={skill_id:n};return nn.post(`/xyzen/api/v1/agents/${e}/skills`,r)}async detachSkill(e,n){return nn.delete(`/xyzen/api/v1/agents/${e}/skills/${n}`)}async parseSkill(e){return nn.post("/xyzen/api/v1/skills/parse",e)}async createSkill(e){return nn.post("/xyzen/api/v1/skills/",e)}async listSkillResources(e){return nn.get(`/xyzen/api/v1/skills/${e}/resources`)}async updateSkill(e,n){return nn.patch(`/xyzen/api/v1/skills/${e}`,n)}async deleteSkill(e){return nn.delete(`/xyzen/api/v1/skills/${e}`)}}const Lh=new T8r,rRt=["official","builtin:"];function aRt({open:t,onOpenChange:e,agentId:n,graphConfig:r,mcpServers:i=[],knowledgeSetId:o,tags:l,isPublished:u=!1,readme:d,onPublishSuccess:p}){const{t:m}=En(),[g,h]=T.useState(""),[f,b]=T.useState(d||""),[y,v]=T.useState(!0),[_,w]=T.useState("editable"),[x,k]=T.useState(l??[]),[C,E]=T.useState(""),[S,I]=T.useState([]),[B,N]=T.useState(o??null),[L,M]=T.useState([]),[R,D]=T.useState(new Set),[P,O]=T.useState(new Set),[F,$]=T.useState(""),[j,Q]=T.useState(null),z=Nir(),U=k2e(t),H=m("marketplace.realPerson.publishAgent");T.useEffect(()=>{if(t){const Z=(l??[]).filter(ne=>!rRt.some(ce=>ne===ce||ne.startsWith(ce)));k(Z)}},[t,l]);const te=T.useCallback(Z=>{const ne=Z.trim().toLowerCase();if(!ne||x.includes(ne)){E("");return}if(rRt.some(ce=>ne===ce||ne.startsWith(ce))){E("");return}k(ce=>[...ce,ne]),E("")},[x]),K=T.useCallback(Z=>{k(ne=>ne.filter(ce=>ce!==Z))},[]),ae=T.useCallback(Z=>{Z.key==="Enter"||Z.key===","?(Z.preventDefault(),te(C)):Z.key==="Backspace"&&!C&&x.length>0&&k(ne=>ne.slice(0,-1))},[te,C,x.length]);T.useEffect(()=>{if(!t)return;let Z=!1;$("");async function ne(){try{const[ce,oe,ue,me]=await Promise.all([Rh.listKnowledgeSets(),Lh.listAgentSkills(n),Lh.listSkills(),ck.getBinding(n)]);if(Z)return;I(ce),M(ue),Q(me);const fe=new Set(oe.map(Be=>Be.id));D(fe),O(new Set(fe)),N(o??null)}catch(ce){console.error("Failed to fetch publish modal data:",ce)}}return ne(),()=>{Z=!0}},[t,n,o]);const se=async(Z=!1)=>{if(g.trim()&&!(!Z&&!await U.ensureVerified()))try{const ne=await z.mutateAsync({agent_id:n,commit_message:g.trim(),is_published:y,readme:f.trim()||null,fork_mode:_,knowledge_set_id:B||null,skill_ids:P.size>0?Array.from(P):void 0,tags:x});p&&p(ne.marketplace_id),h(""),e(!1)}catch(ne){if(U.handleRequiredError(ne))return;console.error("Failed to publish agent:",ne)}},X=Z=>{O(ne=>{const ce=new Set(ne);return ce.has(Z)?ce.delete(Z):ce.add(Z),ce})},W=T.useMemo(()=>{const Z=F.trim().toLowerCase();if(!Z)return L;const ne=ue=>ue.name.toLowerCase().includes(Z)||ue.description?.toLowerCase().includes(Z)||ue.tags?.some(me=>me.toLowerCase().includes(Z)),ce=[],oe=[];for(const ue of L){if(P.has(ue.id)){ce.push(ue);continue}ne(ue)&&oe.push(ue)}return[...ce,...oe]},[L,P,F]),q=!!r&&Object.keys(r).length>0,Y=g.trim().length>0&&q;return A.jsxs(A.Fragment,{children:[A.jsxs(Hc,{isOpen:t,onClose:()=>e(!1),size:"xl",children:[A.jsxs("div",{className:"shrink-0 border-b border-neutral-200/60 px-5 pb-3 pt-5 dark:border-neutral-800/60",children:[A.jsx("h2",{className:"text-lg font-semibold text-neutral-900 dark:text-white",children:m(u?"marketplace.publish.titleUpdate":"marketplace.publish.title")}),A.jsx("p",{className:"mt-1 text-[13px] text-neutral-500 dark:text-neutral-400",children:m(u?"marketplace.publish.descriptionUpdate":"marketplace.publish.description")})]}),A.jsx("div",{className:"custom-scrollbar flex-1 overflow-y-auto",children:A.jsxs("div",{className:"space-y-6 px-5 py-5",children:[A.jsx(O2e,{status:U.statusQuery.data,isLoading:U.statusQuery.isLoading,actionLabel:H,onVerify:()=>U.setVerificationOpen(!0)}),(()=>{const Z=A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx(pu,{className:"h-4 w-4 shrink-0 text-neutral-400"}),A.jsxs("p",{className:"text-[13px] text-neutral-600 dark:text-neutral-400",children:[A.jsx("strong",{children:m("marketplace.publish.info.title")})," ",m("marketplace.publish.info.content")," ",A.jsx("strong",{children:m("marketplace.publish.info.note")})," ",m("marketplace.publish.info.noteContent")]})]}),ne=A.jsx(hi,{label:m("marketplace.publish.commitMessage.label"),required:!0,hint:m("marketplace.publish.commitMessage.charCount",{count:g.length}),children:A.jsx(Ih,{id:"commit-message",placeholder:m("marketplace.publish.commitMessage.placeholder"),value:g,onChange:rt=>h(rt.target.value),rows:3})}),ce=A.jsx(hi,{label:m("marketplace.publish.readme.label"),hint:m("marketplace.publish.readme.hint"),children:A.jsx(Ih,{id:"readme-editor",placeholder:m("marketplace.publish.readme.placeholder"),value:f,onChange:rt=>b(rt.target.value),rows:6,className:"font-mono"})}),oe=A.jsx(hi,{label:m("marketplace.publish.tags.label"),hint:m("marketplace.publish.tags.hint"),children:A.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 rounded-sm border border-neutral-200 bg-white px-2.5 py-2 transition-colors focus-within:border-indigo-400 focus-within:ring-2 focus-within:ring-indigo-500/20 dark:border-neutral-700 dark:bg-neutral-800",children:[x.map(rt=>A.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-indigo-50/80 px-2.5 py-0.5 text-xs font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",children:[rt,A.jsx("button",{type:"button",onClick:()=>K(rt),className:"ml-0.5 rounded-full p-0.5 transition-colors hover:bg-indigo-200/60 dark:hover:bg-indigo-800/40",children:A.jsx(Pl,{className:"h-3 w-3"})})]},rt)),A.jsx("input",{type:"text",value:C,onChange:rt=>E(rt.target.value),onKeyDown:ae,onBlur:()=>C.trim()&&te(C),placeholder:x.length===0?m("marketplace.publish.tags.placeholder"):"",className:"min-w-[80px] flex-1 border-none bg-transparent py-0.5 text-[13px] text-neutral-700 outline-none placeholder:text-neutral-400 dark:text-neutral-300 dark:placeholder:text-neutral-500"})]})}),ue=A.jsx(hi,{label:m("marketplace.publish.knowledgeBase.label"),hint:m("marketplace.publish.knowledgeBase.hint"),children:A.jsxs("select",{value:B??"",onChange:rt=>N(rt.target.value||null),className:"w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-[13px] text-neutral-700 transition-colors focus:border-indigo-400 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-300",children:[A.jsx("option",{value:"",children:m("marketplace.publish.knowledgeBase.none")}),S.map(rt=>A.jsxs("option",{value:rt.id,children:[rt.name," (",m("marketplace.publish.knowledgeBase.fileCount",{count:rt.file_count}),")"]},rt.id))]})}),me=A.jsx(hi,{label:m("marketplace.publish.skills.label"),hint:m("marketplace.publish.skills.hint"),children:L.length===0?A.jsx("p",{className:"text-xs text-neutral-400 dark:text-neutral-500",children:m("marketplace.publish.skills.empty")}):A.jsxs("div",{className:"space-y-1.5",children:[A.jsx(Qi,{value:F,onChange:rt=>$(rt.target.value),placeholder:m("marketplace.publish.skills.searchPlaceholder")}),W.length===0?A.jsx("p",{className:"rounded-lg bg-neutral-100/60 px-3 py-2.5 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:m("marketplace.publish.skills.noResults")}):W.map(rt=>A.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-lg bg-neutral-100/60 px-3 py-2.5 transition-colors hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]",children:[A.jsx("input",{type:"checkbox",checked:P.has(rt.id),onChange:()=>X(rt.id),className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:rt.name}),rt.scope==="builtin"&&A.jsx("span",{className:"rounded bg-indigo-50/80 px-1.5 py-0.5 text-[10px] font-medium text-indigo-600 dark:bg-indigo-900/30 dark:text-indigo-400",children:m("marketplace.publish.skills.builtin")}),R.has(rt.id)&&A.jsx("span",{className:"rounded bg-green-50/80 px-1.5 py-0.5 text-[10px] font-medium text-green-600 dark:bg-green-900/30 dark:text-green-400",children:m("marketplace.publish.skills.attached")})]}),rt.description&&A.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-neutral-500 dark:text-neutral-400",children:rt.description})]})]},rt.id))]})}),fe=A.jsx(hi,{label:m("marketplace.publish.mcpServers.label"),hint:m("marketplace.publish.mcpServers.hint"),children:i.length===0?A.jsx("p",{className:"text-xs text-neutral-400 dark:text-neutral-500",children:m("marketplace.publish.mcpServers.empty")}):A.jsx("div",{className:"space-y-1.5",children:i.map(rt=>A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-3 py-2.5 dark:bg-white/[0.04]",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:rt.name}),rt.description&&A.jsx("p",{className:"mt-0.5 text-xs text-neutral-500 dark:text-neutral-400 line-clamp-1",children:rt.description})]},rt.id))})}),Be=j?A.jsx(hi,{label:m("agents.payment.publishSummaryTitle"),hint:m("agents.payment.publishSummaryHint"),children:A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:j.provider.toUpperCase()}),A.jsx("span",{className:"rounded-full bg-green-50/80 px-2 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:j.enabled?m("agents.payment.enabled"):m("agents.payment.disabled")}),A.jsx("span",{className:"rounded-full bg-indigo-50/80 px-2 py-0.5 text-[10px] font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",children:j.required?m("agents.payment.required"):m("agents.payment.optional")}),A.jsx("span",{className:"rounded-full bg-neutral-200/80 px-2 py-0.5 text-[10px] font-medium text-neutral-700 dark:bg-white/[0.08] dark:text-neutral-300",children:j.status})]}),A.jsx("p",{className:"mt-2 text-xs text-neutral-500 dark:text-neutral-400",children:j.secret?.app_id_masked??m("agents.payment.unconfigured")}),A.jsx("p",{className:"mt-2 text-xs text-neutral-500 dark:text-neutral-400",children:j.tool_names.join(", ")})]})}):null,He=A.jsxs(od,{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3.5 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"space-y-0.5 pr-4",children:[A.jsx(Gc,{htmlFor:"publish-toggle",className:"cursor-pointer text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.publish.publishImmediately.label")}),A.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.publish.publishImmediately.description")})]}),A.jsx(l2e,{id:"publish-toggle",checked:y,onChange:v,className:`${y?"bg-indigo-500":"bg-neutral-300 dark:bg-neutral-600"} relative inline-flex h-[26px] w-[46px] shrink-0 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500/40 focus:ring-offset-2`,children:A.jsx("span",{className:`${y?"translate-x-[22px]":"translate-x-[3px]"} inline-block h-5 w-5 transform rounded-full bg-white shadow-sm transition-transform`})})]}),Le=A.jsx(hi,{label:m("marketplace.publish.forkMode.label"),hint:m("marketplace.publish.forkMode.help"),children:A.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[A.jsxs("button",{type:"button",onClick:()=>w("editable"),className:`flex items-center gap-3 rounded-lg p-3 text-left transition-colors ${_==="editable"?"bg-green-50/80 ring-1 ring-green-500/30 dark:bg-green-900/15 dark:ring-green-500/20":"bg-neutral-100/60 hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]"}`,children:[A.jsx("div",{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${_==="editable"?"bg-green-500 text-white":"bg-neutral-200/70 text-neutral-500 dark:bg-neutral-700/70 dark:text-neutral-400"}`,children:A.jsx(M2e,{className:"h-4 w-4"})}),A.jsxs("div",{className:"flex-1 min-w-0",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.forkMode.editable")}),A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.forkMode.editableDescription")}),A.jsx("div",{className:"mt-1 text-[10px] font-medium text-green-600 dark:text-green-400",children:m("marketplace.forkMode.rewardRate",{rate:"30%"})})]})]}),A.jsxs("button",{type:"button",onClick:()=>w("locked"),className:`flex items-center gap-3 rounded-lg p-3 text-left transition-colors ${_==="locked"?"bg-amber-50/80 ring-1 ring-amber-500/30 dark:bg-amber-900/15 dark:ring-amber-500/20":"bg-neutral-100/60 hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]"}`,children:[A.jsx("div",{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${_==="locked"?"bg-amber-500 text-white":"bg-neutral-200/70 text-neutral-500 dark:bg-neutral-700/70 dark:text-neutral-400"}`,children:A.jsx(Yb,{className:"h-4 w-4"})}),A.jsxs("div",{className:"flex-1 min-w-0",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.forkMode.locked")}),A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.forkMode.lockedDescription")}),A.jsx("div",{className:"mt-1 text-[10px] font-medium text-amber-600 dark:text-amber-400",children:m("marketplace.forkMode.rewardRate",{rate:"3%"})})]})]})]})});return A.jsxs("div",{className:"space-y-6",children:[!q&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-red-50/80 px-4 py-3 dark:bg-red-950/30",children:[A.jsx(Fp,{className:"h-4 w-4 shrink-0 text-red-500 dark:text-red-400"}),A.jsx("p",{className:"text-[13px] text-red-700 dark:text-red-400",children:m("marketplace.publish.validation.noConfig")})]}),A.jsxs("div",{className:"space-y-6 md:hidden",children:[Z,ne,ce,oe,ue,me,fe,Be,He,OA("developerReward")&&Le]}),A.jsxs("div",{className:"hidden md:grid md:grid-cols-[55%_45%]",children:[A.jsxs("div",{className:"space-y-6 pr-5 border-r border-neutral-200/60 dark:border-neutral-800/60",children:[Z,ne,ce,oe]}),A.jsxs("div",{className:"space-y-6 pl-5",children:[ue,me,fe,Be,He,OA("developerReward")&&Le]})]}),z.isSuccess&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-green-50/80 px-4 py-3 dark:bg-green-950/30",children:[A.jsx(_l,{className:"h-4 w-4 shrink-0 text-green-500"}),A.jsx("p",{className:"text-[13px] text-green-700 dark:text-green-400",children:m(u?"marketplace.publish.success.updated":"marketplace.publish.success.published")})]}),z.isError&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-red-50/80 px-4 py-3 dark:bg-red-950/30",children:[A.jsx(Fp,{className:"h-4 w-4 shrink-0 text-red-500 dark:text-red-400"}),A.jsx("p",{className:"text-[13px] text-red-700 dark:text-red-400",children:z.error instanceof Error?z.error.message:m("marketplace.publish.error.default")})]})]})})()]})}),A.jsx("div",{className:"shrink-0 border-t border-neutral-200/60 px-5 py-4 dark:border-neutral-800/60",children:A.jsxs("div",{className:"flex justify-end gap-2.5",children:[A.jsx(qc,{onClick:()=>{h(""),e(!1)},disabled:z.isPending,className:"rounded-lg bg-neutral-100/80 px-4 py-2 text-[13px] font-medium text-neutral-700 transition-colors hover:bg-neutral-200/80 disabled:opacity-50 dark:bg-white/[0.06] dark:text-neutral-300 dark:hover:bg-white/[0.1]",children:m("marketplace.publish.actions.cancel")}),A.jsx(qc,{onClick:()=>{se()},disabled:!Y||z.isPending,className:"rounded-lg bg-indigo-500 px-4 py-2 text-[13px] font-semibold text-white transition-colors hover:bg-indigo-600 disabled:opacity-50 dark:bg-indigo-500 dark:hover:bg-indigo-400",children:z.isPending?m("marketplace.publish.actions.publishing"):m(u?"marketplace.publish.actions.update":y?"marketplace.publish.actions.publish":"marketplace.publish.actions.saveAsDraft")})]})})]}),A.jsx(Gae,{open:U.verificationOpen,onOpenChange:U.setVerificationOpen,actionLabel:H,onStatusChange:()=>{U.statusQuery.refetch()},onVerified:()=>{U.statusQuery.refetch(),se(!0)}})]})}const B8r=["create-alipay-payment-agent","query-alipay-payment","refund-alipay-payment","query-alipay-refund"],D8r=T.lazy(()=>Promise.resolve().then(()=>_Ea)),N8r=[{id:"profile",icon:P2e,labelKey:"profile"},{id:"automation",icon:xo,labelKey:"automation"},{id:"size",icon:dU,labelKey:"size"},{id:"workflow",icon:gh,labelKey:"workflow"},{id:"danger",icon:Fp,labelKey:"danger",color:"text-red-500"}];function R8r({currentW:t=1,currentH:e=1,onResize:n}){const[r,i]=T.useState(null);return A.jsxs("div",{className:"flex flex-col gap-6",children:[A.jsx("div",{className:"flex justify-center",children:A.jsx("div",{className:"grid grid-cols-3 gap-3",onMouseLeave:()=>i(null),children:Array.from({length:9}).map((o,l)=>{const u=l%3+1,d=Math.floor(l/3)+1,p=r&&u<=r.w&&d<=r.h,m=!r&&u<=t&&d<=e;return A.jsx(Ct.div,{whileHover:{scale:1.05},whileTap:{scale:.95},className:Yt("h-14 w-14 cursor-pointer rounded-sm border-2 transition-colors duration-200 shadow-sm",p||m?"border-indigo-500 bg-indigo-500/20 dark:border-indigo-400 dark:bg-indigo-400/20 shadow-indigo-500/30 shadow-lg":"border-neutral-200 bg-white hover:border-neutral-300 dark:border-neutral-700 dark:bg-neutral-800 dark:hover:border-neutral-600"),onMouseEnter:()=>i({w:u,h:d}),onClick:g=>{g.preventDefault(),g.stopPropagation(),n(u,d)}},l)})})}),A.jsx("div",{className:"text-center",children:A.jsx(Ct.span,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"inline-block px-5 py-2 rounded-full bg-neutral-100 dark:bg-neutral-800 text-base font-bold text-neutral-700 dark:text-neutral-200 shadow-sm border border-neutral-200 dark:border-neutral-700",children:r?`${r.w} × ${r.h}`:`${t} × ${e}`},r?`${r.w}x${r.h}`:`${t}x${e}`)})]})}function L8r({agent:t,currentAvatar:e,onAvatarChange:n,onClose:r}){const{t:i}=En(),o=Un(L=>L.backendUrl),{updateAgent:l,agents:u,openSettingsModal:d}=Un(Ws(L=>({updateAgent:L.updateAgent,agents:L.agents,openSettingsModal:L.openSettingsModal}))),p=t.original_source_id!=null,[m,g]=T.useState(t),[h,f]=T.useState(!1),[b,y]=T.useState(null),[v,_]=T.useState([]),[w,x]=T.useState(""),[k,C]=T.useState(!1),[E,S]=T.useState(!1);T.useEffect(()=>{g(t)},[t]),T.useEffect(()=>{let L=!1;async function M(){try{const[R,D]=await Promise.all([ck.getBinding(t.id),ck.listSecrets()]);if(L)return;y(R),_(D),x(R?.secret?.id??""),C(R?.enabled??!1),S(R?.required??!1)}catch(R){console.error("Failed to load agent payment binding:",R)}}return M(),()=>{L=!0}},[t.id]);const I=L=>{const{name:M,value:R}=L.target;g({...m,[M]:R})},B=async L=>{if(L.preventDefault(),!h){if(m.name!==t.name&&u.some(M=>M.id!==m.id&&M.name===m.name)){alert(i("agents.errors.nameDuplicate"));return}f(!0);try{if(await l({id:m.id,name:m.name,description:m.description}),!p&&b!=null&&!k&&!w)await ck.deleteBinding(m.id),y(null),x(""),C(!1),S(!1);else{if(!(!p&&(b!=null||k))){Nr.success(i("agents.payment.saveSuccess")),r();return}if(!w){Nr.error(i("agents.payment.noSecretsHint"));return}const D=await ck.upsertBinding(m.id,{enabled:k,required:k&&E,secret_id:w,tool_names:[...B8r]});y(D)}Nr.success(i("agents.payment.saveSuccess")),r()}catch(M){console.error("Failed to update agent:",M),Nr.error(M instanceof Error?M.message:i("agents.errors.updateFailed"))}finally{f(!1)}}},N=async()=>{if(b){f(!0);try{await ck.deleteBinding(m.id),y(null),x(""),C(!1),S(!1),Nr.success(i("agents.payment.deleteSuccess"))}catch(L){console.error("Failed to delete payment binding:",L),Nr.error(L instanceof Error?L.message:i("agents.payment.deleteFailed"))}finally{f(!1)}}};return A.jsxs("form",{onSubmit:B,className:"space-y-6 px-4",children:[A.jsx(vRe,{currentAvatar:e,onSelect:n,backendUrl:o}),A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.fields.name.label")}),A.jsx(Qi,{name:"name",value:m.name,onChange:I,placeholder:i("agents.fields.name.placeholder"),required:!0})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.fields.description.label")}),A.jsx(Qi,{name:"description",value:m.description,onChange:I,placeholder:i("agents.fields.description.placeholder")})]})]}),!p&&A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-4 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[A.jsxs("div",{children:[A.jsx("p",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:i("agents.payment.title")}),A.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:i("agents.payment.description")})]}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx("span",{className:"rounded-full bg-neutral-200/80 px-2 py-0.5 text-[10px] font-medium text-neutral-700 dark:bg-white/[0.08] dark:text-neutral-300",children:b?.status??i("agents.payment.unconfigured")}),b?.required&&A.jsx("span",{className:"rounded-full bg-indigo-50/80 px-2 py-0.5 text-[10px] font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",children:i("agents.payment.required")})]})]}),b?.last_error&&A.jsx("p",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:b.last_error})]}),A.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[A.jsxs("label",{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-800 dark:text-neutral-200",children:i("agents.payment.enabled")}),A.jsx("input",{type:"checkbox",checked:k,onChange:L=>{const M=L.target.checked;C(M),M||S(!1)},className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"})]}),A.jsxs("label",{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx("span",{className:Yt("text-[13px] font-medium",k?"text-neutral-800 dark:text-neutral-200":"text-neutral-400 dark:text-neutral-500"),children:i("agents.payment.required")}),A.jsx("input",{type:"checkbox",checked:E,disabled:!k,onChange:L=>S(L.target.checked),className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"})]})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.payment.secret")}),A.jsxs("select",{value:w,onChange:L=>x(L.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-[13px] text-neutral-900 focus:border-indigo-400 focus:outline-none focus:ring-2 focus:ring-indigo-400/20 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-100",children:[A.jsx("option",{value:"",children:i("agents.payment.secretPlaceholder")}),v.map(L=>A.jsx("option",{value:L.id,children:L.app_id_masked},L.id))]})]}),w&&A.jsx("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:v.find(L=>L.id===w)?.gateway}),k&&v.length===0&&A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:[A.jsx("p",{children:i("agents.payment.noSecretsHint")}),A.jsx("button",{type:"button",onClick:()=>d("payment"),className:"mt-2 text-xs font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400",children:i("agents.payment.manageSecrets")})]}),b&&A.jsx("div",{className:"flex justify-end",children:A.jsx("button",{type:"button",onClick:()=>{N()},className:"rounded-lg bg-red-50/80 px-3 py-2 text-xs font-medium text-red-700 transition-colors hover:bg-red-100 dark:bg-red-950/30 dark:text-red-400 dark:hover:bg-red-950/50",children:i("agents.payment.delete")})})]})]}),A.jsx("div",{className:"flex justify-end gap-3 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:A.jsx(qc,{type:"submit",disabled:h,className:`inline-flex items-center gap-2 rounded-md py-2 px-4 text-sm font-medium transition-colors ${h?"bg-indigo-400 text-white cursor-not-allowed":"bg-indigo-600 text-white hover:bg-indigo-500"}`,children:i(h?"agents.actions.saving":"agents.actions.save")})})]})}const _Re="09:00",M8r=[{value:"0",label:"Sunday"},{value:"1",label:"Monday"},{value:"2",label:"Tuesday"},{value:"3",label:"Wednesday"},{value:"4",label:"Thursday"},{value:"5",label:"Friday"},{value:"6",label:"Saturday"}];function iRt(){return typeof Intl>"u"?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function P8r(t){if(!t)return{mode:"daily",time:_Re,dayOfWeek:"1",cronExpression:"0 9 * * *"};const e=t.trim().split(/\s+/);if(e.length===5){const[n,r,i,o,l]=e;if(/^\d+$/.test(n)&&/^\d+$/.test(r)&&i==="*"&&o==="*"&&l==="*")return{mode:"daily",time:`${r.padStart(2,"0")}:${n.padStart(2,"0")}`,dayOfWeek:"1",cronExpression:t};if(/^\d+$/.test(n)&&/^\d+$/.test(r)&&i==="*"&&o==="*"&&/^\d+$/.test(l))return{mode:"weekly",time:`${r.padStart(2,"0")}:${n.padStart(2,"0")}`,dayOfWeek:l,cronExpression:t}}return{mode:"cron",time:_Re,dayOfWeek:"1",cronExpression:t}}function O8r(t,e,n,r){if(t==="cron")return r.trim();const[i="9",o="0"]=e.split(":"),l=String(Number(o||"0")),u=String(Number(i||"9"));return t==="weekly"?`${l} ${u} * * ${n}`:`${l} ${u} * * *`}function sRt(t){if(!t)return null;const e=new Date(t);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(e)}function F8r(){const{t}=En(),{autoExplore:e,autoExploreLoading:n,fetchAutoExplore:r,saveAutoExplore:i,toggleAutoExplore:o}=Un(Ws(E=>({autoExplore:E.autoExplore,autoExploreLoading:E.autoExploreLoading,fetchAutoExplore:E.fetchAutoExplore,saveAutoExplore:E.saveAutoExplore,toggleAutoExplore:E.toggleAutoExplore}))),[l,u]=T.useState("daily"),[d,p]=T.useState(_Re),[m,g]=T.useState("1"),[h,f]=T.useState("0 9 * * *"),[b,y]=T.useState(iRt()),[v,_]=T.useState("auto");T.useEffect(()=>{if(!e){r().catch(()=>{});return}const E=P8r(e.cron_expression);u(E.mode),p(E.time),g(E.dayOfWeek),f(E.cronExpression),y(e.timezone||iRt()),_(e.language||"auto")},[e,r]);const w=async()=>{const E=O8r(l,d,m,h);try{await i({cronExpression:E,timezone:b,language:v}),Nr.success(t("agents.rootAgent.autoExploreUpdated"))}catch(S){console.error("Failed to save auto-explore:",S),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},x=async()=>{try{await o(!1),Nr.success(t("agents.rootAgent.autoExploreDisabled"))}catch(E){console.error("Failed to disable auto-explore:",E),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},k=sRt(e?.next_run_at||null),C=sRt(e?.last_run_at||null);return A.jsxs("div",{className:"space-y-6 px-4",children:[A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-4 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex items-center justify-between gap-3",children:[A.jsxs("div",{children:[A.jsx("p",{className:"text-[13px] font-medium text-neutral-800 dark:text-neutral-200",children:t("agents.rootAgent.autoExploreSchedule")}),A.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:t("agents.rootAgent.autoExploreScheduleHint")})]}),A.jsx("span",{className:Yt("rounded-sm px-2 py-1 text-xs font-medium",e?.enabled?"bg-amber-500/10 text-amber-700 dark:text-amber-300":"bg-neutral-200/80 text-neutral-600 dark:bg-white/[0.06] dark:text-neutral-400"),children:e?.enabled?t("agents.rootAgent.autoExploreEnabledState"):t("agents.rootAgent.autoExploreDisabledState")})]}),A.jsxs("div",{className:"mt-3 space-y-1 text-xs text-neutral-500 dark:text-neutral-400",children:[A.jsxs("p",{children:[t("agents.rootAgent.autoExploreTimezone"),": ",b]}),k&&A.jsxs("p",{children:[t("agents.rootAgent.autoExploreNextRun"),": ",k]}),C&&A.jsxs("p",{children:[t("agents.rootAgent.autoExploreLastRun"),": ",C]}),e?.last_error&&A.jsxs("p",{className:"text-red-600 dark:text-red-400",children:[t("agents.rootAgent.autoExploreLastError"),":"," ",e.last_error]})]})]}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreCadence")}),A.jsx("div",{className:"mt-2 grid grid-cols-3 gap-2",children:["daily","weekly","cron"].map(E=>A.jsx("button",{type:"button",onClick:()=>u(E),className:Yt("rounded-lg px-3 py-2 text-sm transition-colors",l===E?"bg-indigo-500 text-white":"bg-neutral-100 text-neutral-700 hover:bg-neutral-200 dark:bg-white/[0.04] dark:text-neutral-300 dark:hover:bg-white/[0.08]"),children:t(`agents.rootAgent.autoExploreCadence${E[0].toUpperCase()}${E.slice(1)}`)},E))})]}),l!=="cron"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreTime")}),A.jsx(Qi,{type:"time",value:d,onChange:E=>p(E.target.value)})]}),l==="weekly"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreWeekday")}),A.jsx("select",{value:m,onChange:E=>g(E.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-700 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200",children:M8r.map(E=>A.jsx("option",{value:E.value,children:t(`agents.rootAgent.autoExploreWeekday${E.label}`)},E.value))})]}),l==="cron"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreCron")}),A.jsx(Qi,{value:h,onChange:E=>f(E.target.value),placeholder:"0 9 * * *"})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreLanguage")}),A.jsxs("select",{value:v,onChange:E=>_(E.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-700 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200",children:[A.jsx("option",{value:"auto",children:t("agents.rootAgent.autoExploreLanguageAuto")}),A.jsx("option",{value:"zh",children:"中文"}),A.jsx("option",{value:"en",children:"English"}),A.jsx("option",{value:"ja",children:"日本語"})]})]})]}),A.jsxs("div",{className:"flex justify-end gap-3 border-t border-neutral-200 pt-4 dark:border-neutral-700",children:[e?.enabled&&A.jsx(Vi,{type:"button",variant:"outline",disabled:n,onClick:x,children:t("agents.rootAgent.autoExploreDisableAction")}),A.jsx(Vi,{type:"button",disabled:n,onClick:w,children:e?.enabled?t("agents.rootAgent.autoExploreUpdateAction"):t("agents.rootAgent.autoExploreEnableAction")})]})]})}const wRe=({isOpen:t,onClose:e,agentName:n,agent:r,currentAvatar:i,currentGridSize:o,onAvatarChange:l,onGridSizeChange:u,onDelete:d})=>{const{t:p}=En(),m=Un(P=>P.backendUrl),g=Un(P=>P.rootAgentId),h=!!r&&!!g&&r.id===g,[f,b]=T.useState("profile"),[y,v]=T.useState(null),[_,w]=T.useState(!1),[x,k]=T.useState(!1),C=typeof window<"u"&&window.innerWidth<768,E=!!r,S=r?.config_visibility!=="hidden",I=r?.original_source_id!=null,B=T.useMemo(()=>N8r.filter(P=>!(P.id==="automation"&&!h||P.id==="workflow"&&(!E||!S)||P.id==="danger"&&!d)),[E,S,d]),N=P=>{C?v(P):b(P),w(!1)},L=()=>{v(null),w(!1)},M=P=>{switch(P){case"profile":return r?A.jsx(L8r,{agent:r,currentAvatar:i,onAvatarChange:l,onClose:e}):A.jsx(vRe,{currentAvatar:i,onSelect:l,backendUrl:m});case"automation":return A.jsx(F8r,{});case"size":return A.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[A.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 mb-8 text-center max-w-64",children:p("agents.sessionSettings.size.description")}),A.jsx(R8r,{currentW:o?.w,currentH:o?.h,onResize:u})]});case"workflow":return r?A.jsx(T.Suspense,{children:A.jsx(D8r,{agent:r,onClose:e})}):null;case"danger":return A.jsx("div",{className:"flex flex-col items-center justify-center h-full py-8 space-y-6",children:_?A.jsxs(Ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"w-full max-w-sm rounded-2xl bg-red-50 dark:bg-red-900/10 p-6 space-y-4 border border-red-100 dark:border-red-900/20",children:[A.jsxs("div",{className:"text-center space-y-2",children:[A.jsx("h3",{className:"text-base font-semibold text-red-700 dark:text-red-300",children:p("agents.sessionSettings.danger.deleteConfirmTitle")}),A.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:p("agents.sessionSettings.danger.deleteConfirmMessage",{name:n})})]}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx(Vi,{variant:"outline",className:"flex-1 bg-white dark:bg-transparent border-red-200 dark:border-red-900/30 text-red-700 dark:text-red-300 hover:bg-red-100 dark:hover:bg-red-900/20",onClick:()=>w(!1),children:p("common.cancel")}),A.jsx(Vi,{variant:"destructive",className:"flex-1 shadow-lg shadow-red-500/20",onClick:()=>{d?.(),e()},children:p("common.delete")})]})]}):A.jsxs(A.Fragment,{children:[A.jsxs("div",{className:"text-center space-y-2",children:[A.jsx(Fp,{className:"w-12 h-12 mx-auto text-red-400"}),A.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 max-w-64",children:p("agents.sessionSettings.danger.description")})]}),d&&A.jsxs(Vi,{variant:"destructive",size:"lg",className:"h-11 px-6 gap-3 shadow-lg shadow-red-500/20",onClick:()=>w(!0),children:[A.jsx(wl,{className:"w-5 h-5"}),p("agents.sessionSettings.danger.deleteButton")]})]})});default:return null}},R=A.jsx("div",{className:"flex-1 min-w-0",children:A.jsx(Fr,{mode:"wait",children:y===null?A.jsx(Ct.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"space-y-2",children:B.map(P=>A.jsxs("button",{onClick:()=>N(P.id),className:Yt("w-full flex items-center gap-4 px-4 py-4 rounded-sm transition-all text-left","bg-neutral-50 dark:bg-neutral-800/50 hover:bg-neutral-100 dark:hover:bg-neutral-800",P.color),children:[A.jsx(P.icon,{className:"w-6 h-6 shrink-0"}),A.jsx("span",{className:"text-base font-medium",children:p(`agents.sessionSettings.tabs.${P.labelKey}`)})]},P.id))},"nav"):A.jsxs(Ct.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},children:[A.jsxs("button",{onClick:L,className:"flex items-center gap-2 text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 mb-4",children:[A.jsx(c_,{className:"w-4 h-4"}),p("settings.modal.back")]}),M(y)]},y)})}),D=A.jsxs(FP,{value:f,onValueChange:P=>{b(P),w(!1)},className:"flex flex-row gap-6",children:[A.jsx("div",{className:"w-44 shrink-0",children:A.jsx(QP,{className:"flex items-start flex-col w-full h-auto bg-neutral-50 dark:bg-neutral-900 rounded-sm p-1.5",children:B.map(P=>A.jsxs(Op,{value:P.id,className:Yt("w-44 justify-start gap-3 px-3 py-2.5 text-sm font-medium rounded-lg","data-[state=active]:bg-white data-[state=active]:shadow-sm dark:data-[state=active]:bg-neutral-800",P.id==="danger"&&"data-[state=active]:text-red-600 dark:data-[state=active]:text-red-400",P.color&&f!==P.id&&P.color),children:[A.jsx(P.icon,{className:"w-5 h-5 shrink-0"}),p(`agents.sessionSettings.tabs.${P.labelKey}`)]},P.id))})}),A.jsx("div",{className:"flex-1 min-w-0",children:A.jsx(lU,{children:B.map(P=>A.jsx(mh,{value:P.id,className:"h-full",children:M(P.id)},P.id))})})]});return A.jsxs(A.Fragment,{children:[A.jsx(Hc,{isOpen:t,onClose:e,size:"lg",children:A.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[A.jsx("div",{className:"shrink-0 px-5 pt-5 pb-1 md:pt-2",children:A.jsx("h2",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:p("agents.sessionSettings.title",{name:n})})}),A.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar px-5 pb-5",children:[A.jsxs("div",{className:"py-2",children:[A.jsx("div",{className:"md:hidden",children:R}),A.jsx("div",{className:"hidden md:block",children:D})]}),r&&!I&&!h&&A.jsx("div",{className:"mt-4 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:A.jsxs(Vi,{type:"button",variant:"outline",onClick:()=>k(!0),disabled:!r.graph_config,className:"w-full gap-2 h-10 text-purple-700 border-purple-200 hover:bg-purple-50 dark:text-purple-300 dark:border-purple-800 dark:hover:bg-purple-900/20",title:r.graph_config?p("agents.actions.publish"):p("agents.actions.publishTooltip"),children:[A.jsx(xo,{className:"h-4 w-4"}),p("agents.actions.publish")]})})]})]})}),r&&!I&&!h&&A.jsx(aRt,{open:x,onOpenChange:k,agentId:r.id,agentName:r.name,agentDescription:r.description,graphConfig:r.graph_config,mcpServers:r.mcp_servers?.map(P=>({id:P.id,name:P.name,description:P.description||void 0})),knowledgeSetId:r.knowledge_set_id,tags:r.tags,onPublishSuccess:P=>{console.log("Agent published to marketplace:",P),k(!1)}})]})};function Q8r({isOpen:t,onClose:e,onConfirm:n,title:r,message:i,confirmLabel:o="Confirm",cancelLabel:l="Cancel",destructive:u=!0,className:d}){return A.jsx(BNe,{open:t,onOpenChange:p=>!p&&e(),children:A.jsxs(DNe,{className:Yt("space-y-4 border border-neutral-200/20 bg-white/95 shadow-2xl shadow-black/20 backdrop-blur-xl dark:border-neutral-700/30 dark:bg-neutral-900/95 dark:shadow-black/40","p-6 sm:p-6 rounded-sm",d),children:[A.jsx(NNe,{children:A.jsx(LNe,{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:r})}),A.jsxs("div",{className:"flex items-start gap-4",children:[A.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30",children:A.jsx(Fp,{className:"h-6 w-6 text-red-600 dark:text-red-400","aria-hidden":"true"})}),A.jsx(MNe,{className:"text-sm text-neutral-600 dark:text-neutral-400",children:i})]}),A.jsxs(RNe,{children:[A.jsx(ONe,{className:Yt("inline-flex items-center gap-2","font-semibold","dark:bg-neutral-800 dark:text-neutral-200 dark:hover:bg-neutral-700"),children:l}),A.jsx(PNe,{autoFocus:!0,onClick:async()=>{await n(),e()},className:Yt("inline-flex items-center gap-2 font-semibold",u?"bg-red-600 text-white shadow-inner shadow-white/10 hover:bg-red-500 dark:bg-red-500 dark:hover:bg-red-400":"bg-neutral-900 text-white hover:bg-neutral-800 dark:bg-neutral-100 dark:text-neutral-900 dark:hover:bg-neutral-200"),children:o})]})]})})}const Iy=ee.memo(Q8r);function oRt(){const{t}=En(),e=Un(i=>i.toggleAutoExplore),n=Un(i=>i.autoExploreLoading);return{handleToggle:T.useCallback(async i=>{if(!n)try{await e(i),Nr.success(t(i?"agents.rootAgent.autoExploreEnabled":"agents.rootAgent.autoExploreDisabled"))}catch(o){console.error("Failed to toggle auto-explore:",o),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},[n,e,t]),loading:n}}function lRt(t,e){const n={};for(const r of t){const i=e[r.id];if(!i)continue;const o=n[i];(!o||r.updatedAt>o)&&(n[i]=r.updatedAt)}return n}function $8r({onClick:t}){const{t:e}=En();return A.jsxs(Ct.button,{onClick:t,initial:{opacity:0,y:10},animate:{opacity:1,y:0},whileHover:{scale:1.02},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:25},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg
575
+ `),iNt=!0);const o=this._options.WebSocket||WebSocket;this._debug("connect",{url:r,protocols:i}),this._ws=i?new o(r,i):new o(r),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),n)}).catch(r=>{this._connectLock=!1,this._handleError(new zNe.ErrorEvent(Error(r.message),this))})}_handleTimeout(){this._debug("timeout event"),this._handleError(new zNe.ErrorEvent(Error("TIMEOUT"),this))}_disconnect(e=1e3,n){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{(this._ws.readyState===this.OPEN||this._ws.readyState===this.CONNECTING)&&this._ws.close(e,n),this._handleClose(new zNe.CloseEvent(e,n,this))}catch{}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_handleOpen=e=>{this._debug("open event");const{minUptime:n=HR.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),n),lOr(this._ws,"WebSocket is not defined"),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(r=>{this._ws?.send(r)}),this._messageQueue=[],this.onopen&&this.onopen(e),this.dispatchEvent($oe(e))};_handleMessage=e=>{this._debug("message event"),this.onmessage&&this.onmessage(e),this.dispatchEvent($oe(e))};_handleError=e=>{this._debug("error event",e.message),this._disconnect(void 0,e.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(e),this._debug("exec error listeners"),this.dispatchEvent($oe(e)),this._connect()};_handleClose=e=>{this._debug("close event"),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this.dispatchEvent($oe(e))};_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}};const rk=Object.create(null);rk.open="0",rk.close="1",rk.ping="2",rk.pong="3",rk.message="4",rk.upgrade="5",rk.noop="6";const joe=Object.create(null);Object.keys(rk).forEach(t=>{joe[rk[t]]=t});const UNe={type:"error",data:"parser error"},sNt=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",oNt=typeof ArrayBuffer=="function",lNt=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,qNe=({type:t,data:e},n,r)=>sNt&&e instanceof Blob?n?r(e):cNt(e,r):oNt&&(e instanceof ArrayBuffer||lNt(e))?n?r(e):cNt(new Blob([e]),r):r(rk[t]+(e||"")),cNt=(t,e)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];e("b"+(r||""))},n.readAsDataURL(t)};function uNt(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let GNe;function gOr(t,e){if(sNt&&t.data instanceof Blob)return t.data.arrayBuffer().then(uNt).then(e);if(oNt&&(t.data instanceof ArrayBuffer||lNt(t.data)))return e(uNt(t.data));qNe(t,!1,n=>{GNe||(GNe=new TextEncoder),e(GNe.encode(n))})}const dNt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Yq=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let t=0;t<dNt.length;t++)Yq[dNt.charCodeAt(t)]=t;const hOr=t=>{let e=t.length*.75,n=t.length,r,i=0,o,l,u,d;t[t.length-1]==="="&&(e--,t[t.length-2]==="="&&e--);const p=new ArrayBuffer(e),m=new Uint8Array(p);for(r=0;r<n;r+=4)o=Yq[t.charCodeAt(r)],l=Yq[t.charCodeAt(r+1)],u=Yq[t.charCodeAt(r+2)],d=Yq[t.charCodeAt(r+3)],m[i++]=o<<2|l>>4,m[i++]=(l&15)<<4|u>>2,m[i++]=(u&3)<<6|d&63;return p},fOr=typeof ArrayBuffer=="function",HNe=(t,e)=>{if(typeof t!="string")return{type:"message",data:pNt(t,e)};const n=t.charAt(0);return n==="b"?{type:"message",data:AOr(t.substring(1),e)}:joe[n]?t.length>1?{type:joe[n],data:t.substring(1)}:{type:joe[n]}:UNe},AOr=(t,e)=>{if(fOr){const n=hOr(t);return pNt(n,e)}else return{base64:!0,data:t}},pNt=(t,e)=>e==="blob"?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,mNt="",bOr=(t,e)=>{const n=t.length,r=new Array(n);let i=0;t.forEach((o,l)=>{qNe(o,!1,u=>{r[l]=u,++i===n&&e(r.join(mNt))})})},yOr=(t,e)=>{const n=t.split(mNt),r=[];for(let i=0;i<n.length;i++){const o=HNe(n[i],e);if(r.push(o),o.type==="error")break}return r};function vOr(){return new TransformStream({transform(t,e){gOr(t,n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const o=new DataView(i.buffer);o.setUint8(0,126),o.setUint16(1,r)}else{i=new Uint8Array(9);const o=new DataView(i.buffer);o.setUint8(0,127),o.setBigUint64(1,BigInt(r))}t.data&&typeof t.data!="string"&&(i[0]|=128),e.enqueue(i),e.enqueue(n)})}})}let WNe;function zoe(t){return t.reduce((e,n)=>e+n.length,0)}function Uoe(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let r=0;for(let i=0;i<e;i++)n[i]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),n}function _Or(t,e){WNe||(WNe=new TextDecoder);const n=[];let r=0,i=-1,o=!1;return new TransformStream({transform(l,u){for(n.push(l);;){if(r===0){if(zoe(n)<1)break;const d=Uoe(n,1);o=(d[0]&128)===128,i=d[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(zoe(n)<2)break;const d=Uoe(n,2);i=new DataView(d.buffer,d.byteOffset,d.length).getUint16(0),r=3}else if(r===2){if(zoe(n)<8)break;const d=Uoe(n,8),p=new DataView(d.buffer,d.byteOffset,d.length),m=p.getUint32(0);if(m>Math.pow(2,21)-1){u.enqueue(UNe);break}i=m*Math.pow(2,32)+p.getUint32(4),r=3}else{if(zoe(n)<i)break;const d=Uoe(n,i);u.enqueue(HNe(o?d:WNe.decode(d),e)),r=0}if(i===0||i>t){u.enqueue(UNe);break}}}})}const gNt=4;function pp(t){if(t)return wOr(t)}function wOr(t){for(var e in pp.prototype)t[e]=pp.prototype[e];return t}pp.prototype.on=pp.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},pp.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},pp.prototype.off=pp.prototype.removeListener=pp.prototype.removeAllListeners=pp.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+t];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+t],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===e||r.fn===e){n.splice(i,1);break}return n.length===0&&delete this._callbacks["$"+t],this},pp.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,e)}return this},pp.prototype.emitReserved=pp.prototype.emit,pp.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},pp.prototype.hasListeners=function(t){return!!this.listeners(t).length};const Ey=typeof self<"u"?self:typeof window<"u"?window:Function("return this")();function hNt(t,...e){return e.reduce((n,r)=>(t.hasOwnProperty(r)&&(n[r]=t[r]),n),{})}const xOr=Ey.setTimeout,kOr=Ey.clearTimeout;function qoe(t,e){e.useNativeTimers?(t.setTimeoutFn=xOr.bind(Ey),t.clearTimeoutFn=kOr.bind(Ey)):(t.setTimeoutFn=Ey.setTimeout.bind(Ey),t.clearTimeoutFn=Ey.clearTimeout.bind(Ey))}const EOr=1.33;function COr(t){return typeof t=="string"?SOr(t):Math.ceil((t.byteLength||t.size)*EOr)}function SOr(t){let e=0,n=0;for(let r=0,i=t.length;r<i;r++)e=t.charCodeAt(r),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(r++,n+=4);return n}function IOr(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}function TOr(t){let e={},n=t.split("&");for(let r=0,i=n.length;r<i;r++){let o=n[r].split("=");e[decodeURIComponent(o[0])]=decodeURIComponent(o[1])}return e}class BOr extends Error{constructor(e,n,r){super(e),this.description=n,this.context=r,this.type="TransportError"}}class YNe extends pp{constructor(e){super(),this.writable=!1,qoe(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,n,r){return super.emitReserved("error",new BOr(e,n,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const n=HNe(e,this.socket.binaryType);this.onPacket(n)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,n={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(n)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const n=IOr(e);return n.length?"?"+n:""}}const fNt="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),VNe=64,DOr={};let ANt=0,Goe=0,bNt;function yNt(t){let e="";do e=fNt[t%VNe]+e,t=Math.floor(t/VNe);while(t>0);return e}function vNt(){const t=yNt(+new Date);return t!==bNt?(ANt=0,bNt=t):t+"."+yNt(ANt++)}for(;Goe<VNe;Goe++)DOr[fNt[Goe]]=Goe;let _Nt=!1;try{_Nt=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const NOr=_Nt;function wNt(t){const e=t.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||NOr))return new XMLHttpRequest}catch{}if(!e)try{return new Ey[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function w0s(){}function ROr(){}const LOr=(function(){return new wNt({xdomain:!1}).responseType!=null})();class MOr extends YNe{constructor(e){if(super(e),this.polling=!1,typeof location<"u"){const r=location.protocol==="https:";let i=location.port;i||(i=r?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||i!==e.port}const n=e&&e.forceBase64;this.supportsBinary=LOr&&!n,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const n=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let r=0;this.polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};yOr(e,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,bOr(e,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=vNt()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(e,n)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new nF(this.uri(),e)}doWrite(e,n){const r=this.request({method:"POST",data:e});r.on("success",n),r.on("error",(i,o)=>{this.onError("xhr post error",i,o)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=e}}let nF=class wxe extends pp{constructor(e,n){super(),qoe(this,n),this.opts=n,this.method=n.method||"GET",this.uri=e,this.data=n.data!==void 0?n.data:null,this.create()}create(){var e;const n=hNt(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this.opts.xd;const r=this.xhr=new wNt(n);try{r.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this.opts.extraHeaders[i])}}catch{}if(this.method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(e=this.opts.cookieJar)===null||e===void 0||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(r.timeout=this.opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this.opts.cookieJar)===null||i===void 0||i.parseCookies(r)),r.readyState===4&&(r.status===200||r.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof r.status=="number"?r.status:0)},0))},r.send(this.data)}catch(i){this.setTimeoutFn(()=>{this.onError(i)},0);return}typeof document<"u"&&(this.index=wxe.requestsCount++,wxe.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=ROr,e)try{this.xhr.abort()}catch{}typeof document<"u"&&delete wxe.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}};if(nF.requestsCount=0,nF.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",xNt);else if(typeof addEventListener=="function"){const t="onpagehide"in Ey?"pagehide":"unload";addEventListener(t,xNt,!1)}}function xNt(){for(let t in nF.requests)nF.requests.hasOwnProperty(t)&&nF.requests[t].abort()}const KNe=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,n)=>n(e,0),Hoe=Ey.WebSocket||Ey.MozWebSocket,kNt=!0,POr="arraybuffer",ENt=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class OOr extends YNe{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),n=this.opts.protocols,r=ENt?{}:hNt(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=kNt&&!ENt?n?new Hoe(e,n):new Hoe(e):new Hoe(e,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;qNe(r,this.supportsBinary,o=>{const l={};try{kNt&&this.ws.send(o)}catch{}i&&KNe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=vNt()),this.supportsBinary||(n.b64=1),this.createUri(e,n)}check(){return!!Hoe}}class FOr extends YNe{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(e=>{const n=_Or(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(n).getReader(),i=vOr();i.readable.pipeTo(e.writable),this.writer=i.writable.getWriter();const o=()=>{r.read().then(({done:u,value:d})=>{u||(this.onPacket(d),o())}).catch(u=>{})};o();const l={type:"open"};this.query.sid&&(l.data=`{"sid":"${this.query.sid}"}`),this.writer.write(l).then(()=>this.onOpen())})}))}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;this.writer.write(r).then(()=>{i&&KNe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this.transport)===null||e===void 0||e.close()}}const QOr={websocket:OOr,webtransport:FOr,polling:MOr},$Or=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,jOr=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ZNe(t){if(t.length>2e3)throw"URI too long";const e=t,n=t.indexOf("["),r=t.indexOf("]");n!=-1&&r!=-1&&(t=t.substring(0,n)+t.substring(n,r).replace(/:/g,";")+t.substring(r,t.length));let i=$Or.exec(t||""),o={},l=14;for(;l--;)o[jOr[l]]=i[l]||"";return n!=-1&&r!=-1&&(o.source=e,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=zOr(o,o.path),o.queryKey=UOr(o,o.query),o}function zOr(t,e){const n=/\/{2,9}/g,r=e.replace(n,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&r.splice(0,1),e.slice(-1)=="/"&&r.splice(r.length-1,1),r}function UOr(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,o){i&&(n[i]=o)}),n}let CNt=class N7 extends pp{constructor(e,n={}){super(),this.binaryType=POr,this.writeBuffer=[],e&&typeof e=="object"&&(n=e,e=null),e?(e=ZNe(e),n.hostname=e.host,n.secure=e.protocol==="https"||e.protocol==="wss",n.port=e.port,e.query&&(n.query=e.query)):n.host&&(n.hostname=ZNe(n.host).host),qoe(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=n.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=TOr(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const n=Object.assign({},this.opts.query);n.EIO=gNt,n.transport=e,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new QOr[e](r)}open(){let e;if(this.opts.rememberUpgrade&&N7.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)e="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else e=this.transports[0];this.readyState="opening";try{e=this.createTransport(e)}catch{this.transports.shift(),this.open();return}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",n=>this.onClose("transport close",n))}probe(e){let n=this.createTransport(e),r=!1;N7.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",g=>{if(!r)if(g.type==="pong"&&g.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;N7.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(m(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const h=new Error("probe error");h.transport=n.name,this.emitReserved("upgradeError",h)}}))};function o(){r||(r=!0,m(),n.close(),n=null)}const l=g=>{const h=new Error("probe error: "+g);h.transport=n.name,o(),this.emitReserved("upgradeError",h)};function u(){l("transport closed")}function d(){l("socket closed")}function p(g){n&&g.name!==n.name&&o()}const m=()=>{n.removeListener("open",i),n.removeListener("error",l),n.removeListener("close",u),this.off("close",d),this.off("upgrading",p)};n.once("open",i),n.once("error",l),n.once("close",u),this.once("close",d),this.once("upgrading",p),this.upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onOpen(){if(this.readyState="open",N7.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let e=0;const n=this.upgrades.length;for(;e<n;e++)this.probe(this.upgrades[e])}}onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const n=new Error("server error");n.code=e.data,this.onError(n);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r<this.writeBuffer.length;r++){const i=this.writeBuffer[r].data;if(i&&(n+=COr(i)),r>0&&n>this.maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}write(e,n,r){return this.sendPacket("message",e,n,r),this}send(e,n,r){return this.sendPacket("message",e,n,r),this}sendPacket(e,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const o={type:e,data:n,options:r};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),i&&this.once("flush",i),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),e()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():e()}):this.upgrading?r():e()),this}onError(e){N7.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,n){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,n),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const n=[];let r=0;const i=e.length;for(;r<i;r++)~this.transports.indexOf(e[r])&&n.push(e[r]);return n}};CNt.protocol=gNt;function qOr(t,e="",n){let r=t;n=n||typeof location<"u"&&location,t==null&&(t=n.protocol+"//"+n.host),typeof t=="string"&&(t.charAt(0)==="/"&&(t.charAt(1)==="/"?t=n.protocol+t:t=n.host+t),/^(https?|wss?):\/\//.test(t)||(typeof n<"u"?t=n.protocol+"//"+t:t="https://"+t),r=ZNe(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const o=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+o+":"+r.port+e,r.href=r.protocol+"://"+o+(n&&n.port===r.port?"":":"+r.port),r}const GOr=typeof ArrayBuffer=="function",HOr=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,SNt=Object.prototype.toString,WOr=typeof Blob=="function"||typeof Blob<"u"&&SNt.call(Blob)==="[object BlobConstructor]",YOr=typeof File=="function"||typeof File<"u"&&SNt.call(File)==="[object FileConstructor]";function XNe(t){return GOr&&(t instanceof ArrayBuffer||HOr(t))||WOr&&t instanceof Blob||YOr&&t instanceof File}function Woe(t,e){if(!t||typeof t!="object")return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(Woe(t[n]))return!0;return!1}if(XNe(t))return!0;if(t.toJSON&&typeof t.toJSON=="function"&&arguments.length===1)return Woe(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&Woe(t[n]))return!0;return!1}function VOr(t){const e=[],n=t.data,r=t;return r.data=JNe(n,e),r.attachments=e.length,{packet:r,buffers:e}}function JNe(t,e){if(!t)return t;if(XNe(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}else if(Array.isArray(t)){const n=new Array(t.length);for(let r=0;r<t.length;r++)n[r]=JNe(t[r],e);return n}else if(typeof t=="object"&&!(t instanceof Date)){const n={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=JNe(t[r],e));return n}return t}function KOr(t,e){return t.data=eRe(t.data,e),delete t.attachments,t}function eRe(t,e){if(!t)return t;if(t&&t._placeholder===!0){if(typeof t.num=="number"&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}else if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=eRe(t[n],e);else if(typeof t=="object")for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=eRe(t[n],e));return t}const ZOr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var Oo;(function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"})(Oo||(Oo={}));class XOr{constructor(e){this.replacer=e}encode(e){return(e.type===Oo.EVENT||e.type===Oo.ACK)&&Woe(e)?this.encodeAsBinary({type:e.type===Oo.EVENT?Oo.BINARY_EVENT:Oo.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let n=""+e.type;return(e.type===Oo.BINARY_EVENT||e.type===Oo.BINARY_ACK)&&(n+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(n+=e.nsp+","),e.id!=null&&(n+=e.id),e.data!=null&&(n+=JSON.stringify(e.data,this.replacer)),n}encodeAsBinary(e){const n=VOr(e),r=this.encodeAsString(n.packet),i=n.buffers;return i.unshift(r),i}}class tRe extends pp{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e=="function"?{reviver:e}:e)}add(e){let n;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");n=this.decodeString(e);const r=n.type===Oo.BINARY_EVENT;r||n.type===Oo.BINARY_ACK?(n.type=r?Oo.EVENT:Oo.ACK,this.reconstructor=new JOr(n),n.attachments===0&&super.emitReserved("decoded",n)):super.emitReserved("decoded",n)}else if(XNe(e)||e.base64)if(this.reconstructor)n=this.reconstructor.takeBinaryData(e),n&&(this.reconstructor=null,super.emitReserved("decoded",n));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let n=0;const r={type:Number(e.charAt(0))};if(Oo[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===Oo.BINARY_EVENT||r.type===Oo.BINARY_ACK){const o=n+1;for(;e.charAt(++n)!=="-"&&n!=e.length;);const l=e.substring(o,n);if(l!=Number(l)||e.charAt(n)!=="-")throw new Error("Illegal attachments");const u=Number(l);if(!eFr(u)||u<0)throw new Error("Illegal attachments");if(u>this.opts.maxAttachments)throw new Error("too many attachments");r.attachments=u}if(e.charAt(n+1)==="/"){const o=n+1;for(;++n&&!(e.charAt(n)===","||n===e.length););r.nsp=e.substring(o,n)}else r.nsp="/";const i=e.charAt(n+1);if(i!==""&&Number(i)==i){const o=n+1;for(;++n;){const l=e.charAt(n);if(l==null||Number(l)!=l){--n;break}if(n===e.length)break}r.id=Number(e.substring(o,n+1))}if(e.charAt(++n)){const o=this.tryParse(e.substr(n));if(tRe.isPayloadValid(r.type,o))r.data=o;else throw new Error("invalid payload")}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,n){switch(e){case Oo.CONNECT:return INt(n);case Oo.DISCONNECT:return n===void 0;case Oo.CONNECT_ERROR:return typeof n=="string"||INt(n);case Oo.EVENT:case Oo.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&ZOr.indexOf(n[0])===-1);case Oo.ACK:case Oo.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class JOr{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const n=KOr(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const eFr=Number.isInteger||function(t){return typeof t=="number"&&isFinite(t)&&Math.floor(t)===t};function INt(t){return Object.prototype.toString.call(t)==="[object Object]"}const tFr=Object.freeze(Object.defineProperty({__proto__:null,Decoder:tRe,Encoder:XOr,get PacketType(){return Oo}},Symbol.toStringTag,{value:"Module"}));function S_(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const nFr=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});let TNt=class extends pp{constructor(e,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[S_(e,"open",this.onopen.bind(this)),S_(e,"packet",this.onpacket.bind(this)),S_(e,"error",this.onerror.bind(this)),S_(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...n){if(nFr.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(n.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;const r={type:Oo.EVENT,data:n};if(r.options={},r.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){const l=this.ids++,u=n.pop();this._registerAckCallback(l,u),r.id=l}const i=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!i||!this.connected)||(this.connected?(this.notifyOutgoingListeners(r),this.packet(r)):this.sendBuffer.push(r)),this.flags={},this}_registerAckCallback(e,n){var r;const i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[e]=n;return}const o=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let l=0;l<this.sendBuffer.length;l++)this.sendBuffer[l].id===e&&this.sendBuffer.splice(l,1);n.call(this,new Error("operation has timed out"))},i);this.acks[e]=(...l)=>{this.io.clearTimeoutFn(o),n.apply(this,[null,...l])}}emitWithAck(e,...n){const r=this.flags.timeout!==void 0||this._opts.ackTimeout!==void 0;return new Promise((i,o)=>{n.push((l,u)=>r?l?o(l):i(u):i(l)),this.emit(e,...n)})}_addToQueue(e){let n;typeof e[e.length-1]=="function"&&(n=e.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((i,...o)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...o)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!e||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:Oo.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,n)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case Oo.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Oo.EVENT:case Oo.BINARY_EVENT:this.onevent(e);break;case Oo.ACK:case Oo.BINARY_ACK:this.onack(e);break;case Oo.DISCONNECT:this.ondisconnect();break;case Oo.CONNECT_ERROR:this.destroy();const r=new Error(e.data.message);r.data=e.data.data,this.emitReserved("connect_error",r);break}}onevent(e){const n=e.data||[];e.id!=null&&n.push(this.ack(e.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:Oo.ACK,id:e,data:i}))}}onack(e){const n=this.acks[e.id];typeof n=="function"&&(n.apply(this,e.data),delete this.acks[e.id])}onconnect(e,n){this.id=e,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Oo.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const n=this._anyListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const n=this._anyOutgoingListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const n=this._anyOutgoingListeners.slice();for(const r of n)r.apply(this,e.data)}}};function rF(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}rF.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=(Math.floor(e*10)&1)==0?t-n:t+n}return Math.min(t,this.max)|0},rF.prototype.reset=function(){this.attempts=0},rF.prototype.setMin=function(t){this.ms=t},rF.prototype.setMax=function(t){this.max=t},rF.prototype.setJitter=function(t){this.jitter=t};class nRe extends pp{constructor(e,n){var r;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(n=e,e=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,qoe(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new rF({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=e;const i=n.parser||tFr;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var n;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(n=this.backoff)===null||n===void 0||n.setMin(e),this)}randomizationFactor(e){var n;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(n=this.backoff)===null||n===void 0||n.setJitter(e),this)}reconnectionDelayMax(e){var n;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(n=this.backoff)===null||n===void 0||n.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new CNt(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=S_(n,"open",function(){r.onopen(),e&&e()}),o=u=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",u),e?e(u):this.maybeReconnectOnOpen()},l=S_(n,"error",o);if(this._timeout!==!1){const u=this._timeout,d=this.setTimeoutFn(()=>{i(),o(new Error("timeout")),n.close()},u);this.opts.autoUnref&&d.unref(),this.subs.push(()=>{this.clearTimeoutFn(d)})}return this.subs.push(i),this.subs.push(l),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(S_(e,"ping",this.onping.bind(this)),S_(e,"data",this.ondata.bind(this)),S_(e,"error",this.onerror.bind(this)),S_(e,"close",this.onclose.bind(this)),S_(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(n){this.onclose("parse error",n)}}ondecoded(e){KNe(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,n){let r=this.nsps[e];return r?this._autoConnect&&!r.active&&r.connect():(r=new TNt(this,e,n),this.nsps[e]=r),r}_destroy(e){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(e){const n=this.encoder.encode(e);for(let r=0;r<n.length;r++)this.engine.write(n[r],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,n){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(i=>{i?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",i)):e.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const Vq={};function Yoe(t,e){typeof t=="object"&&(e=t,t=void 0),e=e||{};const n=qOr(t,e.path||"/socket.io"),r=n.source,i=n.id,o=n.path,l=Vq[i]&&o in Vq[i].nsps,u=e.forceNew||e["force new connection"]||e.multiplex===!1||l;let d;return u?d=new nRe(r,e):(Vq[i]||(Vq[i]=new nRe(r,e)),d=Vq[i]),n.query&&!e.query&&(e.query=n.queryKey),d.socket(n.path,e)}Object.assign(Yoe,{Manager:nRe,Socket:TNt,io:Yoe,connect:Yoe});var BNt=(t,e)=>t===e?!0:!t||!e||t.length!==e.length?!1:t.every((n,r)=>n===e[r]),rRe=(t,e)=>BNt(t,e)||!t&&e?.length===0||t?.length===0&&!e,rFr=(t,e)=>{const n=Array.isArray(t)?t:t?[t]:[],r=Array.isArray(e)?e:e?[e]:[];return BNt(n,r)},DNt=(t,e)=>{if(!t&&!e)return!0;if(!t||!e)return!1;try{return JSON.stringify(t)===JSON.stringify(e)}catch{return!1}},Voe=(t,e)=>DNt(t.data,e.data)&&rRe(t.tags,e.tags)&&t.read===e.read&&t.archived===e.archived&&t.snoozed===e.snoozed&&t.seen===e.seen&&rFr(t.severity,e.severity);function aFr(t,e){return!e||Object.keys(e).length===0?!0:t?Object.entries(e).every(([n,r])=>{const i=t[n];if(i===void 0&&r!==void 0)return!1;if(Array.isArray(r))if(Array.isArray(i)){if(r.length!==i.length)return!1;const o=[...r].sort(),l=[...i].sort();return o.every((u,d)=>u===l[d])}else return r.includes(i);else return i===r}):!1}function iFr(t,e){return!e||e.length===0?!0:!t||t.length===0?!1:e.some(n=>t.includes(n))}function sFr(t,e){return!(e.read!==void 0&&t.isRead!==e.read||e.seen!==void 0&&t.isSeen!==e.seen||e.archived!==void 0&&t.isArchived!==e.archived||e.snoozed!==void 0&&t.isSnoozed!==e.snoozed)}function oFr(t,e){return sFr(t,e)&&iFr(t.tags,e.tags)&&aFr(t.data,e.data)}var gT,hT,WR,YR,Kq,Zq=class{constructor(t,e,n,r,i){qa(this,gT),qa(this,hT),qa(this,WR),qa(this,YR),qa(this,Kq,!1);var o;di(this,gT,e),di(this,hT,n),di(this,WR,r),di(this,YR,i),this.id=t.id,this.identifier=t.identifier,this.topicKey=t.topicKey,this.preferences=(o=t.preferences)==null?void 0:o.map(l=>new Xq(fi({},l),tn(this,gT),tn(this,hT),tn(this,WR),tn(this,YR)))}update(t){return Rr(this,null,function*(){return NNt({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:wc(fi({},t),{subscription:this})})})}updatePreference(t){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot update a deleted subscription",new Error("Subscription is stale"))}:RNt({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:wc(fi({},t),{subscriptionId:this.identifier})})})}bulkUpdatePreferences(t){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot bulk update a deleted subscription",new Error("Subscription is stale"))}:dFr({emitter:tn(this,gT),apiService:tn(this,hT),cache:tn(this,WR),useCache:tn(this,YR),args:t.map(e=>wc(fi({},e),{subscriptionId:this.identifier}))})})}delete(){return Rr(this,null,function*(){return tn(this,Kq)?{error:new go("Cannot delete an already deleted subscription",new Error("Subscription is stale"))}:LNt({emitter:tn(this,gT),apiService:tn(this,hT),args:{subscription:this}})})}};gT=new WeakMap,hT=new WeakMap,WR=new WeakMap,YR=new WeakMap,Kq=new WeakMap;var lFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,options:i,args:o}){try{const{useCache:l,refetch:u}=i;let d=l&&!u?r.getAll(o):void 0;return e.emit("subscriptions.list.pending",{args:o,data:d}),(!d||u)&&(d=(yield n.fetchSubscriptions(o.topicKey)).map(m=>new Zq(wc(fi({},m),{topicKey:o.topicKey}),e,n,r,l)),l&&(r.set(o,d),d=r.getAll(o))),e.emit("subscriptions.list.resolved",{args:o,data:d}),{data:d}}catch(l){return e.emit("subscriptions.list.resolved",{args:o,error:l}),{error:new go("Failed to fetch subscriptions",l)}}}),cFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,options:i,args:o}){try{const{useCache:l,refetch:u}=i;let d=l&&!u?r.get(o):void 0;if(e.emit("subscription.get.pending",{args:o,data:d}),!d||u){const p=yield n.getSubscription(o.topicKey,o.identifier,o.workflowIds,o.tags);if(!p)return e.emit("subscription.get.resolved",{args:o,data:null}),{data:null};d=new Zq(wc(fi({},p),{topicKey:o.topicKey}),e,n,r,l),l&&(r.setOne(o,d),d=r.get(o))}return e.emit("subscription.get.resolved",{args:o,data:d}),{data:d}}catch(l){return e.emit("subscription.get.resolved",{args:o,error:l}),{error:new go("Failed to fetch subscription",l)}}}),uFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l;try{e.emit("subscription.create.pending",{args:o});const u=yield n.createSubscription({identifier:(l=o.identifier)!=null?l:"",name:o.name,topicKey:o.topicKey,topicName:o.topicName,preferences:o.preferences}),d=new Zq(wc(fi({},u),{topicKey:o.topicKey}),e,n,r,i);return e.emit("subscription.create.resolved",{args:o,data:d}),{data:d}}catch(u){return e.emit("subscription.create.resolved",{args:o,error:u}),{error:new go("Failed to create subscription",u)}}}),NNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){const l="identifier"in o?o.identifier:o.subscription.identifier,u="topicKey"in o?o.topicKey:o.subscription.topicKey;try{e.emit("subscription.update.pending",{args:o});const d=yield n.updateSubscription({topicKey:u,identifier:l,name:o.name,preferences:o.preferences}),p=new Zq(wc(fi({},d),{topicKey:u}),e,n,r,i);return e.emit("subscription.update.resolved",{args:o,data:p}),{data:p}}catch(d){return e.emit("subscription.update.resolved",{args:o,error:d}),{error:new go("Failed to update subscription",d)}}}),RNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l,u;const d="workflowId"in o?o.workflowId:(u=(l=o.preference)==null?void 0:l.workflow)==null?void 0:u.id;try{e.emit("subscription.preference.update.pending",{args:o,data:"preference"in o?new Xq(fi(fi({},o.preference),typeof o.value=="boolean"?{enabled:o.value}:{condition:o.value}),e,n,r,i):void 0});const p=yield n.updateSubscriptionPreference(fi({subscriptionIdentifier:o.subscriptionId,workflowId:d},typeof o.value=="boolean"?{enabled:o.value,email:o.value,sms:o.value,in_app:o.value,chat:o.value,push:o.value}:{condition:o.value})),m=new Xq(fi({},p),e,n,r,i);return e.emit("subscription.preference.update.resolved",{args:o,data:m}),{data:m}}catch(p){return e.emit("subscription.preference.update.resolved",{args:o,error:p}),{error:new go("Failed to update subscription",p)}}}),dFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){try{const l=o.map(m=>"preference"in m?new Xq(fi(fi({},m.preference),typeof m.value=="boolean"?{enabled:m.value}:{condition:m.value}),e,n,r,i):void 0).filter(m=>m!==void 0);e.emit("subscription.preferences.bulk_update.pending",{args:o,data:l});const u=o.map(m=>{var g,h,f,b,y,v;return fi({subscriptionIdentifier:m.subscriptionId,workflowId:"workflowId"in m?m.workflowId:(v=(y=(h=(g=m.preference)==null?void 0:g.workflow)==null?void 0:h.id)!=null?y:(b=(f=m.preference)==null?void 0:f.workflow)==null?void 0:b.identifier)!=null?v:""},typeof m.value=="boolean"?{enabled:m.value,email:m.value,sms:m.value,in_app:m.value,chat:m.value,push:m.value}:{condition:m.value})}),p=(yield n.bulkUpdateSubscriptionPreferences(u)).map(m=>new Xq(m,e,n,r,i));return e.emit("subscription.preferences.bulk_update.resolved",{args:o,data:p}),{data:p}}catch(l){return e.emit("subscription.preferences.bulk_update.resolved",{args:o,error:l}),{error:new go("Failed to bulk update subscription preferences",l)}}}),LNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,args:r}){const i="identifier"in r?r.identifier:r.subscription.identifier,o="topicKey"in r?r.topicKey:r.subscription.topicKey;try{return e.emit("subscription.delete.pending",{args:r}),yield n.deleteSubscription({topicKey:o,identifier:i}),e.emit("subscription.delete.resolved",{args:r}),{data:void 0}}catch(l){return e.emit("subscription.delete.resolved",{args:r,error:l}),{error:new go("Failed to delete subscription",l)}}}),Koe,Zoe,Xoe,Joe,Xq=class{constructor(t,e,n,r,i){qa(this,Koe),qa(this,Zoe),qa(this,Xoe),qa(this,Joe);var o;di(this,Koe,e),di(this,Zoe,n),di(this,Xoe,r),di(this,Joe,i),this.enabled=t.enabled,this.condition=(o=t.condition)!=null?o:void 0,this.workflow=t.workflow,this.subscriptionId=t.subscriptionId}update(t){return Rr(this,null,function*(){var e;return RNt({emitter:tn(this,Koe),apiService:tn(this,Zoe),cache:tn(this,Xoe),useCache:tn(this,Joe),args:{subscriptionId:this.subscriptionId,workflowId:(e=this.workflow)==null?void 0:e.id,value:t.value,preference:this}})})}};Koe=new WeakMap,Zoe=new WeakMap,Xoe=new WeakMap,Joe=new WeakMap;var VR,Jq,aF=class{constructor({inboxServiceInstance:t,eventEmitterInstance:e}){qa(this,VR,[]),qa(this,Jq),this._emitter=e,this._inboxService=t,this._emitter.on("session.initialize.resolved",({error:n,data:r})=>{r?(this.onSessionSuccess(r),tn(this,VR).forEach(i=>Rr(this,[i],function*({fn:o,resolve:l}){l(yield o())})),di(this,VR,[])):n&&(this.onSessionError(n),di(this,Jq,n),tn(this,VR).forEach(({resolve:i})=>{i({error:new go("Failed to initialize session, please contact the support",n)})}),di(this,VR,[]))})}onSessionSuccess(t){}onSessionError(t){}callWithSession(t){return Rr(this,null,function*(){return this._inboxService.isSessionInitialized?t():tn(this,Jq)?Promise.resolve({error:new go("Failed to initialize session, please contact the support",tn(this,Jq))}):new Promise((e,n)=>{tn(this,VR).push({fn:t,resolve:e,reject:n})})})}};VR=new WeakMap,Jq=new WeakMap;var ak,eG=class{constructor(){qa(this,ak),di(this,ak,new Map)}get(t){return tn(this,ak).get(t)}getValues(){return Array.from(tn(this,ak).values())}entries(){return Array.from(tn(this,ak).entries())}keys(){return Array.from(tn(this,ak).keys())}set(t,e){tn(this,ak).set(t,e)}remove(t){tn(this,ak).delete(t)}clear(){tn(this,ak).clear()}};ak=new WeakMap;var KR=t=>`list:${t.topicKey}`,MNt=t=>t.split(":")[1],fT=t=>`item:${t.topicKey}:${t.identifier}`,Th,Rd,ele,mp,tle,pFr=class{constructor({emitterInstance:t,inboxServiceInstance:e,useCache:n}){qa(this,Th),qa(this,Rd),qa(this,ele),qa(this,mp),qa(this,tle),this.handleCreate=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=[...o,r];tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).set(fT({topicKey:r.topicKey,identifier:r.identifier}),r)},this.handleUpdate=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=o.map(u=>u.id===r.id?r:u);tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).set(fT({topicKey:r.topicKey,identifier:r.identifier}),r)},this.handlePreferenceUpdate=r=>{this.updateSubscriptionPreferences([r])},this.handleBulkPreferenceUpdate=r=>{this.updateSubscriptionPreferences(r)},this.updateSubscriptionPreferences=r=>{var i;const o=new Map;for(const d of r){const p=(i=o.get(d.subscriptionId))!=null?i:[];p.push(d),o.set(d.subscriptionId,p)}const l=tn(this,Rd).keys();for(const d of l){const p=tn(this,Rd).get(d);if(!p)continue;let m=!1;const g=p.map(h=>{const f=o.get(h.id);return f?(m=!0,this.createUpdatedSubscription(h,f)):h});m&&(tn(this,Rd).set(d,g),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:MNt(d),subscriptions:g}}))}const u=tn(this,mp).keys();for(const d of u){const p=tn(this,mp).get(d);if(!p)continue;const m=o.get(p.id);if(m){const g=this.createUpdatedSubscription(p,m);tn(this,mp).set(d,g),tn(this,Th).emit("subscription.update.resolved",{args:{subscription:p},data:g})}}},this.createUpdatedSubscription=(r,i)=>{var o;const l=(o=r.preferences)==null?void 0:o.map(u=>{const d=i.find(p=>p.workflow.id===u.workflow.id);return d||u});return new Zq({id:r.id,identifier:r.identifier,topicKey:r.topicKey,preferences:l},tn(this,Th),tn(this,tle),this,tn(this,ele))},this.handleDelete=r=>{const i=KR({topicKey:r.topicKey}),o=tn(this,Rd).get(i);if(o){const l=o.filter(u=>u.id!==r.id);tn(this,Rd).set(i,l),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:r.topicKey,subscriptions:l}})}tn(this,mp).remove(fT({topicKey:r.topicKey,identifier:r.identifier}))},this.handleDeleteByIdentifier=r=>{const i=tn(this,Rd).keys();for(const l of i){const u=tn(this,Rd).get(l);if(u){const d=u.find(p=>p.identifier===r);if(d){const p=u.filter(m=>m.identifier!==r);tn(this,Rd).set(l,p),tn(this,Th).emit("subscriptions.list.updated",{data:{topicKey:MNt(l),subscriptions:p}}),tn(this,mp).remove(fT({topicKey:d.topicKey,identifier:d.identifier}));return}}}const o=tn(this,mp).keys();for(const l of o){const u=tn(this,mp).get(l);if(u&&u.identifier===r){tn(this,mp).remove(l);return}}},di(this,Th,t),di(this,Rd,new eG),di(this,mp,new eG),di(this,tle,e),di(this,ele,n),tn(this,Th).on("subscription.create.resolved",({data:r})=>{r&&this.handleCreate(r)}),tn(this,Th).on("subscription.update.resolved",({data:r})=>{r&&this.handleUpdate(r)}),tn(this,Th).on("subscription.delete.resolved",({args:r})=>{"subscription"in r?this.handleDelete(r.subscription):"identifier"in r&&this.handleDeleteByIdentifier(r.identifier)}),tn(this,Th).on("subscription.preference.update.pending",({data:r})=>{r&&this.handlePreferenceUpdate(r)}),tn(this,Th).on("subscription.preference.update.resolved",({data:r})=>{r&&this.handlePreferenceUpdate(r)}),tn(this,Th).on("subscription.preferences.bulk_update.resolved",({data:r})=>{r&&r.length>0&&this.handleBulkPreferenceUpdate(r)})}has(t){return tn(this,Rd).get(KR(t))!==void 0}set(t,e){tn(this,Rd).set(KR(t),e);for(const n of e)tn(this,mp).set(fT({topicKey:t.topicKey,identifier:n.identifier}),n)}setOne(t,e){tn(this,mp).set(fT(t),e)}getAll(t){return tn(this,Rd).get(KR(t))}get(t){return tn(this,mp).get(fT(t))}invalidate(t){const e=KR({topicKey:t.topicKey}),n=tn(this,Rd).get(e);if(n)for(const i of n)tn(this,mp).remove(fT({topicKey:t.topicKey,identifier:i.identifier}));tn(this,Rd).remove(e);const r=tn(this,mp).keys();for(const i of r)i.startsWith(`item:${t.topicKey}:`)&&tn(this,mp).remove(i)}clearAll(){tn(this,Rd).clear(),tn(this,mp).clear()}};Th=new WeakMap,Rd=new WeakMap,ele=new WeakMap,mp=new WeakMap,tle=new WeakMap;var ZR,nle,rle,mFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n,subscriber:r,contextKey:i}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,ZR),qa(this,nle),qa(this,rle),this.cache=new pFr({emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,useCache:t}),di(this,ZR,t),di(this,nle,r),di(this,rle,i)}list(t,e){return Rr(this,null,function*(){return this.callWithSession(()=>{var n;return lFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,options:wc(fi({},e),{useCache:(n=e?.useCache)!=null?n:tn(this,ZR)}),args:t})})})}get(t,e){return Rr(this,null,function*(){return this.callWithSession(()=>{var n,r;return cFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,options:wc(fi({},e),{useCache:(n=e?.useCache)!=null?n:tn(this,ZR)}),args:wc(fi({},t),{identifier:(r=t.identifier)!=null?r:eOr({topicKey:t.topicKey,subscriberId:tn(this,nle).subscriberId,contextKey:tn(this,rle)})})})})})}create(t){return Rr(this,null,function*(){return this.callWithSession(()=>uFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,ZR),args:t}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>NNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,ZR),args:t}))})}delete(t){return Rr(this,null,function*(){return this.callWithSession(()=>LNt({emitter:this._emitter,apiService:this._inboxService,args:t}))})}};ZR=new WeakMap,nle=new WeakMap,rle=new WeakMap;var gFr="v1",PNt="@novu/js@3.13.0",hFr=class{constructor(t={}){this.DEFAULT_BACKEND_URL=typeof window<"u"&&window.NOVU_LOCAL_BACKEND_URL||"https://api.novu.co";const{apiVersion:e=gFr,apiUrl:n=this.DEFAULT_BACKEND_URL,userAgent:r=PNt,headers:i={}}=t||{};this.apiVersion=e,this.apiUrl=`${n}/${e}`,this.headers=fi({"Novu-API-Version":"2024-06-26","Novu-Client-Version":PNt,"Content-Type":"application/json","User-Agent":r},i)}setAuthorizationToken(t){this.headers.Authorization=`Bearer ${t}`}setKeylessHeader(t){var e;const n=t||typeof window<"u"&&((e=window.localStorage)==null?void 0:e.getItem("novu_keyless_application_identifier"));!n||!n.startsWith("pk_keyless_")||(this.headers["Novu-Application-Identifier"]=n)}setHeaders(t){this.headers=fi(fi({},this.headers),t)}get(t,e,n=!0){return Rr(this,null,function*(){return this.doFetch({path:t,searchParams:e,options:{method:"GET"},unwrapEnvelope:n})})}post(t,e,n){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"POST",body:e,headers:n?.headers}})})}patch(t,e){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"PATCH",body:e}})})}delete(t,e){return Rr(this,null,function*(){return this.doFetch({path:t,options:{method:"DELETE",body:e}})})}doFetch(t){return Rr(this,arguments,function*({path:e,searchParams:n,options:r,unwrapEnvelope:i=!0}){const o=fFr(this.apiUrl,e,n?`?${n.toString()}`:""),l={method:r?.method||"GET",headers:fi(fi({},this.headers),r?.headers||{}),body:r?.body?JSON.stringify(r.body):void 0},u=yield fetch(o,l);if(!u.ok){const p=yield u.json();throw new Error(`${this.headers["Novu-Client-Version"]} error. Status: ${u.status}, Message: ${p.message}`)}if(u.status===204)return;const d=yield u.json();return i?d.data:d})}};function fFr(...t){return t.reduce((e,n)=>(n&&e.push(n.replace(new RegExp("(?<!https?:)\\/+","g"),"/").replace(/^\/+|\/+$/g,"")),e),[]).join("/").replace(/\/\?/,"?")}var qA="/inbox",Bh=`${qA}/notifications`,Fo,AFr=class{constructor(t={}){this.isSessionInitialized=!1,qa(this,Fo),di(this,Fo,new hFr(t))}initializeSession(t){return Rr(this,arguments,function*({applicationIdentifier:e,subscriberHash:n,contextHash:r,subscriber:i,defaultSchedule:o,context:l}){const u=yield tn(this,Fo).post(`${qA}/session`,{applicationIdentifier:e,subscriberHash:n,contextHash:r,subscriber:i,defaultSchedule:o,context:l});return tn(this,Fo).setAuthorizationToken(u.token),tn(this,Fo).setKeylessHeader(u.applicationIdentifier),this.isSessionInitialized=!0,u})}fetchNotifications({after:t,archived:e,limit:n=10,offset:r,read:i,tags:o,snoozed:l,seen:u,data:d,severity:p}){const m=new URLSearchParams(`limit=${n}`);if(t&&m.append("after",t),r&&m.append("offset",`${r}`),o)for(const g of o)m.append("tags[]",g);if(i!==void 0&&m.append("read",`${i}`),e!==void 0&&m.append("archived",`${e}`),l!==void 0&&m.append("snoozed",`${l}`),u!==void 0&&m.append("seen",`${u}`),d!==void 0&&m.append("data",JSON.stringify(d)),p&&Array.isArray(p))for(const g of p)m.append("severity[]",g);else p&&m.append("severity",p);return tn(this,Fo).get(Bh,m,!1)}count({filters:t}){return tn(this,Fo).get(`${Bh}/count`,new URLSearchParams({filters:JSON.stringify(t)}),!1)}read(t){return tn(this,Fo).patch(`${Bh}/${t}/read`)}unread(t){return tn(this,Fo).patch(`${Bh}/${t}/unread`)}archive(t){return tn(this,Fo).patch(`${Bh}/${t}/archive`)}unarchive(t){return tn(this,Fo).patch(`${Bh}/${t}/unarchive`)}snooze(t,e){return tn(this,Fo).patch(`${Bh}/${t}/snooze`,{snoozeUntil:e})}unsnooze(t){return tn(this,Fo).patch(`${Bh}/${t}/unsnooze`)}readAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/read`,{tags:t,data:e?JSON.stringify(e):void 0})}archiveAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/archive`,{tags:t,data:e?JSON.stringify(e):void 0})}archiveAllRead({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/read-archive`,{tags:t,data:e?JSON.stringify(e):void 0})}delete(t){return tn(this,Fo).delete(`${Bh}/${t}/delete`)}deleteAll({tags:t,data:e}){return tn(this,Fo).post(`${Bh}/delete`,{tags:t,data:e?JSON.stringify(e):void 0})}markAsSeen({notificationIds:t,tags:e,data:n}){return tn(this,Fo).post(`${Bh}/seen`,{notificationIds:t,tags:e,data:n?JSON.stringify(n):void 0})}seen(t){return this.markAsSeen({notificationIds:[t]})}completeAction({actionType:t,notificationId:e}){return tn(this,Fo).patch(`${Bh}/${e}/complete`,{actionType:t})}revertAction({actionType:t,notificationId:e}){return tn(this,Fo).patch(`${Bh}/${e}/revert`,{actionType:t})}fetchPreferences({tags:t,severity:e,criticality:n}){const r=new URLSearchParams;if(t)for(const o of t)r.append("tags[]",o);if(e&&Array.isArray(e))for(const o of e)r.append("severity[]",o);else e&&r.append("severity",e);n&&r.append("criticality",n);const i=r.size?`?${r.toString()}`:"";return tn(this,Fo).get(`${qA}/preferences${i}`)}bulkUpdatePreferences(t){return tn(this,Fo).patch(`${qA}/preferences/bulk`,{preferences:t})}updateGlobalPreferences(t){return tn(this,Fo).patch(`${qA}/preferences`,t)}updateWorkflowPreferences({workflowId:t,channels:e}){return tn(this,Fo).patch(`${qA}/preferences/${t}`,e)}fetchGlobalPreferences(){return tn(this,Fo).get(`${qA}/preferences/global`)}triggerHelloWorldEvent(){const t={name:"hello-world",to:{subscriberId:"keyless-subscriber-id"},payload:{subject:"Novu Keyless Environment",body:"You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",primaryActionText:"Obtain API Key",primaryActionUrl:"https://go.novu.co/keyless",secondaryActionText:"Explore Documentation",secondaryActionUrl:"https://go.novu.co/keyless-docs"}};return tn(this,Fo).post("/inbox/events",t)}fetchSubscriptions(t){return tn(this,Fo).get(`${qA}/topics/${t}/subscriptions`)}getSubscription(t,e,n,r){const i=new URLSearchParams;if(n?.length)for(const l of n)i.append("workflowIds",l);if(r?.length)for(const l of r)i.append("tags",l);const o=i.size?`?${i.toString()}`:"";return tn(this,Fo).get(`${qA}/topics/${t}/subscriptions/${e}${o}`)}createSubscription({identifier:t,name:e,topicKey:n,topicName:r,preferences:i}){return tn(this,Fo).post(`${qA}/topics/${n}/subscriptions`,fi(fi({identifier:t,name:e},r&&{topic:{name:r}}),i!==void 0&&{preferences:i}))}updateSubscription({topicKey:t,identifier:e,name:n,preferences:r}){return tn(this,Fo).patch(`${qA}/topics/${t}/subscriptions/${e}`,fi({name:n},r!==void 0&&{preferences:r}))}updateSubscriptionPreference({subscriptionIdentifier:t,workflowId:e,enabled:n,condition:r,email:i,sms:o,in_app:l,chat:u,push:d}){return tn(this,Fo).patch(`${qA}/subscriptions/${t}/preferences/${e}`,{enabled:n,condition:r,email:i,sms:o,in_app:l,chat:u,push:d})}bulkUpdateSubscriptionPreferences(t){return tn(this,Fo).patch(`${qA}/preferences/bulk`,{preferences:t})}deleteSubscription({topicKey:t,identifier:e}){return tn(this,Fo).delete(`${qA}/topics/${t}/subscriptions/${e}`)}};Fo=new WeakMap;var iF,bFr=class{constructor(){qa(this,iF),di(this,iF,sOr())}on(t,e){return tn(this,iF).on(t,e),()=>{this.off(t,e)}}off(t,e){tn(this,iF).off(t,e)}emit(t,e){tn(this,iF).emit(t,e)}};iF=new WeakMap;var ONt=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})=>Object.entries({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p}).filter(([m,g])=>g!=null&&!(Array.isArray(g)&&g.length===0)).reduce((m,[g,h])=>(m[g]=h,m),{}),tG=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})=>JSON.stringify(ONt({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l,limit:u,offset:d,after:p})),yFr=({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l})=>JSON.stringify(ONt({tags:t,data:e,read:n,archived:r,snoozed:i,seen:o,severity:l})),XR=t=>JSON.parse(t),vFr=["notification.read.pending","notification.read.resolved","notification.unread.pending","notification.unread.resolved","notification.complete_action.pending","notification.complete_action.resolved","notification.revert_action.pending","notification.revert_action.resolved","notifications.read_all.pending","notifications.read_all.resolved"],_Fr=["notification.archive.pending","notification.unarchive.pending","notification.snooze.pending","notification.unsnooze.pending","notification.delete.pending","notifications.archive_all.pending","notifications.archive_all_read.pending","notifications.delete_all.pending"],AT,ale,Ld,wFr=class{constructor({emitter:t,inboxService:e}){qa(this,AT),qa(this,ale),qa(this,Ld),this.updateNotification=(n,r)=>{const i=tn(this,Ld).get(n);if(!i)return!1;const o=i.notifications.findIndex(u=>u.id===r.id);if(o===-1)return!1;const l=[...i.notifications];return l[o]=r,tn(this,Ld).set(n,wc(fi({},i),{notifications:l})),!0},this.removeNotification=(n,r)=>{const i=tn(this,Ld).get(n);if(!i)return!1;const o=i.notifications.findIndex(u=>u.id===r.id);if(o===-1)return!1;const l=[...i.notifications];return l.splice(o,1),tn(this,Ld).set(n,wc(fi({},i),{notifications:l})),!0},this.handleNotificationEvent=({remove:n}={remove:!1})=>r=>{const{data:i,args:o}=r;let l=[];if(i!=null)Array.isArray(i)&&i.every(d=>typeof d=="object"&&"id"in d)?l=i:typeof i=="object"&&"id"in i&&(l=[i]);else if(n&&o){if("notification"in o&&o.notification)l=[o.notification];else if("notificationId"in o&&o.notificationId){const d=[];tn(this,Ld).keys().forEach(p=>{const m=tn(this,Ld).get(p);if(m){const g=m.notifications.find(h=>h.id===o.notificationId);g&&d.push(g)}}),l=d}}if(l.length===0)return;const u=new Set;tn(this,Ld).keys().forEach(d=>{l.forEach(p=>{let m=!1;n?m=this.removeNotification(d,p):m=this.updateNotification(d,p),m&&u.add(yFr(XR(d)))})}),u.forEach(d=>{const p=this.getAggregated(XR(d));tn(this,AT).emit("notifications.list.updated",{data:p})})},di(this,AT,t),di(this,ale,e),vFr.forEach(n=>{tn(this,AT).on(n,this.handleNotificationEvent())}),_Fr.forEach(n=>{tn(this,AT).on(n,this.handleNotificationEvent({remove:!0}))}),di(this,Ld,new eG)}getAggregated(t){return tn(this,Ld).keys().filter(n=>{const r=XR(n);return Voe(r,t)}).map(n=>tn(this,Ld).get(n)).reduce((n,r)=>r?{hasMore:r.hasMore,filter:r.filter,notifications:[...n.notifications,...r.notifications]}:n,{hasMore:!1,filter:{},notifications:[]})}get(t){return tn(this,Ld).get(tG(t))}has(t){return tn(this,Ld).get(tG(t))!==void 0}set(t,e){tn(this,Ld).set(tG(t),e)}unshift(t,e){const n=tG(t),r=tn(this,Ld).get(n)||{hasMore:!1,filter:XR(n),notifications:[]},i=iOr({notification:fi({},e),emitter:tn(this,AT),inboxService:tn(this,ale)});this.update(t,wc(fi({},r),{notifications:[i,...r.notifications]}))}update(t,e){this.set(t,e);const n=this.getAggregated(XR(tG(t)));tn(this,AT).emit("notifications.list.updated",{data:n})}getAll(t){if(this.has(t))return this.getAggregated({tags:t.tags,data:t.data,read:t.read,snoozed:t.snoozed,archived:t.archived,seen:t.seen,severity:t.severity})}getUniqueNotifications({tags:t,read:e,data:n}){const r=tn(this,Ld).keys(),i=new Map;return r.forEach(o=>{const l=XR(o);if(rRe(t,l.tags)&&DNt(n,l.data)){const u=tn(this,Ld).get(o);if(!u)return;u.notifications.filter(d=>typeof e>"u"||e===d.isRead).forEach(d=>{i.set(d.id,d)})}}),Array.from(i.values())}clear(t){tn(this,Ld).keys().forEach(n=>{Voe(XR(n),t)&&tn(this,Ld).remove(n)})}clearAll(){tn(this,Ld).clear()}};AT=new WeakMap,ale=new WeakMap,Ld=new WeakMap;var ile,xFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,ile),this.cache=new wFr({emitter:n,inboxService:e}),di(this,ile,t)}list(){return Rr(this,arguments,function*(t={}){var e=t,{limit:n=10}=e,r=JPr(e,["limit"]);return this.callWithSession(()=>Rr(this,null,function*(){const i=fi({limit:n},r);try{const o="useCache"in i?i.useCache:tn(this,ile);let l=o?this.cache.getAll(i):void 0;if(this._emitter.emit("notifications.list.pending",{args:i,data:l}),!l){const u=yield this._inboxService.fetchNotifications(fi({limit:n},r));l={hasMore:u.hasMore,filter:u.filter,notifications:u.data.map(d=>new Nm(d,this._emitter,this._inboxService))},o&&(this.cache.set(i,l),l=this.cache.getAll(i))}return this._emitter.emit("notifications.list.resolved",{args:i,data:l}),{data:l}}catch(o){return this._emitter.emit("notifications.list.resolved",{args:i,error:o}),{error:new go("Failed to fetch notifications",o)}}}))})}count(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){const e=t&&"filters"in t?t.filters:[fi({},t)];try{this._emitter.emit("notifications.count.pending",{args:t});const n=yield this._inboxService.count({filters:e}),r=t&&"filters"in t?{counts:n.data}:n.data[0];return this._emitter.emit("notifications.count.resolved",{args:t,data:r}),{data:r}}catch(n){return this._emitter.emit("notifications.count.resolved",{args:t,error:n}),{error:new go("Failed to count notifications",n)}}}))})}read(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return HDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unread(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return WDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}seen(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return YDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}archive(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return VDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unarchive(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return KDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}delete(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return eNt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}snooze(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return ZDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}unsnooze(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return XDt({emitter:this._emitter,apiService:this._inboxService,args:t})}))})}completePrimary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Foe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"primary"})}))})}completeSecondary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Foe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"secondary"})}))})}revertPrimary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Qoe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"primary"})}))})}revertSecondary(t){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){return Qoe({emitter:this._emitter,apiService:this._inboxService,args:t,actionType:"secondary"})}))})}readAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return tOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}seenAll(){return Rr(this,arguments,function*(t={}){return this.callWithSession(()=>Rr(this,null,function*(){return"notificationIds"in t?JDt({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,notificationIds:t.notificationIds}):JDt({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:"tags"in t?t.tags:void 0,data:"data"in t?t.data:void 0})}))})}archiveAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return nOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}archiveAllRead(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return rOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}deleteAll(){return Rr(this,arguments,function*({tags:t,data:e}={}){return this.callWithSession(()=>Rr(this,null,function*(){return aOr({emitter:this._emitter,inboxService:this._inboxService,notificationsCache:this.cache,tags:t,data:e})}))})}clearCache({filter:t}={}){if(t){this.cache.clear(t??{});return}this.cache.clearAll()}triggerHelloWorldEvent(){return Rr(this,null,function*(){return this._inboxService.triggerHelloWorldEvent()})}};ile=new WeakMap;var sle,ole,lle,cle,ule=class{constructor(t,{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i}){qa(this,sle),qa(this,ole),qa(this,lle),qa(this,cle),di(this,sle,e),di(this,ole,n),di(this,lle,r),di(this,cle,i),this.isEnabled=t.isEnabled,this.weeklySchedule=t.weeklySchedule}update(t){return Rr(this,null,function*(){var e;const n=!!t.weeklySchedule||!!this.weeklySchedule;return QNt({emitter:tn(this,sle),apiService:tn(this,ole),cache:tn(this,lle),useCache:tn(this,cle),args:fi({isEnabled:(e=t.isEnabled)!=null?e:this.isEnabled},n&&{weeklySchedule:fi(fi({},this.weeklySchedule),t.weeklySchedule)})})})}};sle=new WeakMap,ole=new WeakMap,lle=new WeakMap,cle=new WeakMap;var dle,ple,mle,gle,hle,sF=class{constructor(t,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}){qa(this,dle),qa(this,ple),qa(this,mle),qa(this,gle),qa(this,hle),di(this,dle,e),di(this,ple,n),di(this,mle,r),di(this,gle,i),di(this,hle,o),this.level=t.level,this.enabled=t.enabled,this.channels=t.channels,this.workflow=t.workflow,this.schedule=new ule(fi({},t.schedule),{emitterInstance:e,inboxServiceInstance:n,cache:i,useCache:o})}update({channels:t,channelPreferences:e}){var n;return FNt({emitter:tn(this,dle),apiService:tn(this,ple),cache:tn(this,mle),scheduleCache:tn(this,gle),useCache:tn(this,hle),args:{workflowId:(n=this.workflow)==null?void 0:n.id,channels:t||e,preference:this}})}};dle=new WeakMap,ple=new WeakMap,mle=new WeakMap,gle=new WeakMap,hle=new WeakMap;var FNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}){var u;const{channels:d}=l,p="workflowId"in l?l.workflowId:(u=l.preference.workflow)==null?void 0:u.id;try{e.emit("preference.update.pending",{args:l,data:"preference"in l?new sF(wc(fi({},l.preference),{channels:fi(fi({},l.preference.channels),d)}),{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}):void 0});let m;p?m=yield n.updateWorkflowPreferences({workflowId:p,channels:d}):(EFr({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}),m=yield n.updateGlobalPreferences(d));const g=new sF(m,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o});return e.emit("preference.update.resolved",{args:l,data:g}),{data:g}}catch(m){return e.emit("preference.update.resolved",{args:l,error:m}),{error:new go("Failed to update preference",m)}}}),kFr=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,scheduleCache:i,useCache:o,args:l}){if(l.find(d=>"preference"in d&&d.preference.level==="global"))return{error:new go("Global preference is not supported in bulk update","")};try{const d=l.map(h=>"preference"in h?new sF(wc(fi({},h.preference),{channels:fi(fi({},h.preference.channels),h.channels)}),{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}):void 0).filter(h=>h!==void 0);e.emit("preferences.bulk_update.pending",{args:l,data:d});const p=l.map(h=>{var f,b,y,v;return fi({workflowId:"workflowId"in h?h.workflowId:(v=(y=(f=h.preference.workflow)==null?void 0:f.id)!=null?y:(b=h.preference.workflow)==null?void 0:b.identifier)!=null?v:""},h.channels)}),g=(yield n.bulkUpdatePreferences(p)).map(h=>new sF(h,{emitterInstance:e,inboxServiceInstance:n,cache:r,scheduleCache:i,useCache:o}));return e.emit("preferences.bulk_update.resolved",{args:l,data:g}),{data:g}}catch(d){return e.emit("preferences.bulk_update.resolved",{args:l,error:d}),{error:new go("Failed to bulk update preferences",d)}}}),EFr=({emitter:t,apiService:e,cache:n,scheduleCache:r,useCache:i,args:o})=>{const l=i?n?.getAll({}):void 0;l?.forEach(u=>{var d,p;if(u.level==="template"){const m=wc(fi({},u),{channels:Object.entries(u.channels).reduce((h,[f,b])=>{var y;const v=f;return h[v]=(y=o.channels[v])!=null?y:b,h},{})}),g="preference"in o?new sF(m,{emitterInstance:t,inboxServiceInstance:e,cache:n,scheduleCache:r,useCache:i}):void 0;g&&t.emit("preference.update.pending",{args:{workflowId:(p=(d=u.workflow)==null?void 0:d.id)!=null?p:"",channels:g.channels},data:g})}})},QNt=t=>Rr(void 0,[t],function*({emitter:e,apiService:n,cache:r,useCache:i,args:o}){var l,u;try{const{isEnabled:d,weeklySchedule:p}=o,m=new ule({isEnabled:d,weeklySchedule:p},{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i});e.emit("preference.schedule.update.pending",{args:o,data:m});const g=yield n.updateGlobalPreferences({schedule:{isEnabled:d,weeklySchedule:p}}),h=new ule({isEnabled:(l=g.schedule)==null?void 0:l.isEnabled,weeklySchedule:(u=g.schedule)==null?void 0:u.weeklySchedule},{emitterInstance:e,inboxServiceInstance:n,cache:r,useCache:i});return e.emit("preference.schedule.update.resolved",{args:o,data:h}),{data:h}}catch(d){return e.emit("preference.schedule.update.resolved",{args:o,error:d}),{error:new go("Failed to update preference",d)}}}),JR,CFr=class extends aF{constructor({cache:t,useCache:e,inboxServiceInstance:n,eventEmitterInstance:r}){super({eventEmitterInstance:r,inboxServiceInstance:n}),qa(this,JR),this.cache=t,di(this,JR,e)}get(){return Rr(this,null,function*(){return this.callWithSession(()=>Rr(this,null,function*(){var t,e;try{let n=tn(this,JR)?this.cache.getAll():void 0;if(this._emitter.emit("preference.schedule.get.pending",{args:void 0,data:n}),!n){const r=yield this._inboxService.fetchGlobalPreferences();n=new ule({isEnabled:(t=r?.schedule)==null?void 0:t.isEnabled,weeklySchedule:(e=r?.schedule)==null?void 0:e.weeklySchedule},{emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,cache:this.cache,useCache:tn(this,JR)}),tn(this,JR)&&(this.cache.set(n),n=this.cache.getAll())}return this._emitter.emit("preference.schedule.get.resolved",{args:void 0,data:n}),{data:n}}catch(n){throw this._emitter.emit("preference.schedule.get.resolved",{args:void 0,error:n}),n}}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>QNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,useCache:tn(this,JR),args:t}))})}};JR=new WeakMap;var SFr=["preference.update.pending","preference.update.resolved","preferences.bulk_update.pending","preferences.bulk_update.resolved"],IFr=["preference.schedule.update.pending","preference.schedule.update.resolved"],TFr=({tags:t,severity:e})=>Object.entries({tags:t,severity:e}).reduce((n,[r,i])=>(i==null||Array.isArray(i)&&i.length===0||(n[r]=i),n),{}),aRe=({tags:t,severity:e})=>JSON.stringify(TFr({tags:t,severity:e})),e3,Cg,BFr=class{constructor({emitterInstance:t}){qa(this,e3),qa(this,Cg),this.updatePreference=(e,n)=>{const r=tn(this,Cg).get(e);if(!r)return!1;const i=r.findIndex(l=>{var u,d;return((u=l.workflow)==null?void 0:u.id)===((d=n.workflow)==null?void 0:d.id)||l.level===n.level&&n.level==="global"});if(i===-1)return!1;const o=[...r];return o[i]=n,tn(this,Cg).set(e,o),!0},this.updatePreferenceSchedule=(e,n)=>{const r=tn(this,Cg).get(e);if(!r)return!1;const i=r.findIndex(l=>l.level==="global");if(i===-1)return!1;const o=[...r];return o[i].schedule=n,tn(this,Cg).set(e,o),!0},this.handleScheduleEvent=({data:e})=>{var n;if(!e)return;const r=tn(this,Cg).keys(),i=new Set;for(const o of r){const l=this.updatePreferenceSchedule(o,e),u=tn(this,Cg).get(o);!l||!u||i.add(o)}for(const o of i)tn(this,e3).emit("preferences.list.updated",{data:(n=tn(this,Cg).get(o))!=null?n:[]})},this.handlePreferenceEvent=({data:e})=>{if(!e)return;const n=Array.isArray(e)?e:[e],r=new Set;tn(this,Cg).keys().forEach(i=>{n.forEach(o=>{const l=this.updatePreference(i,o),u=tn(this,Cg).get(i);!l||!u||r.add(i)})}),r.forEach(i=>{var o;tn(this,e3).emit("preferences.list.updated",{data:(o=tn(this,Cg).get(i))!=null?o:[]})})},di(this,e3,t);for(const e of SFr)tn(this,e3).on(e,this.handlePreferenceEvent);for(const e of IFr)tn(this,e3).on(e,this.handleScheduleEvent);di(this,Cg,new eG)}has(t){return tn(this,Cg).get(aRe(t))!==void 0}set(t,e){tn(this,Cg).set(aRe(t),e)}getAll(t){if(this.has(t))return tn(this,Cg).get(aRe(t))}clearAll(){tn(this,Cg).clear()}};e3=new WeakMap,Cg=new WeakMap;var DFr=["preference.schedule.update.pending","preference.schedule.update.resolved"],iRe=()=>"schedule",nG,Cy,NFr=class{constructor({emitterInstance:t}){qa(this,nG),qa(this,Cy),this.updateScheduleInCache=(e,n)=>tn(this,Cy).get(e)?(tn(this,Cy).set(e,n),!0):!1,this.handleScheduleEvent=({data:e})=>{if(!e)return;const n=new Set,r=tn(this,Cy).keys();for(const i of r){const o=this.updateScheduleInCache(i,e),l=tn(this,Cy).get(i);!o||!l||n.add(i)}for(const i of n)tn(this,nG).emit("preference.schedule.get.updated",{data:tn(this,Cy).get(i)})},di(this,nG,t);for(const e of DFr)tn(this,nG).on(e,this.handleScheduleEvent);di(this,Cy,new eG)}has(){return tn(this,Cy).get(iRe())!==void 0}set(t){tn(this,Cy).set(iRe(),t)}getAll(){if(this.has())return tn(this,Cy).get(iRe())}clearAll(){tn(this,Cy).clear()}};nG=new WeakMap,Cy=new WeakMap;var bT,RFr=class extends aF{constructor({useCache:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,bT),this.cache=new BFr({emitterInstance:this._emitter}),this.scheduleCache=new NFr({emitterInstance:this._emitter}),di(this,bT,t),this.schedule=new CFr({cache:this.scheduleCache,useCache:t,inboxServiceInstance:e,eventEmitterInstance:n})}list(){return Rr(this,arguments,function*(t={}){return this.callWithSession(()=>Rr(this,null,function*(){var e;try{let n=tn(this,bT)?this.cache.getAll(t):void 0;return this._emitter.emit("preferences.list.pending",{args:t,data:n}),n||(n=(yield this._inboxService.fetchPreferences({tags:t.tags,severity:t.severity,criticality:(e=t.criticality)!=null?e:"nonCritical"})).map(i=>new sF(i,{emitterInstance:this._emitter,inboxServiceInstance:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT)})),tn(this,bT)&&(this.cache.set(t,n),n=this.cache.getAll(t))),this._emitter.emit("preferences.list.resolved",{args:t,data:n}),{data:n}}catch(n){throw this._emitter.emit("preferences.list.resolved",{args:t,error:n}),n}}))})}update(t){return Rr(this,null,function*(){return this.callWithSession(()=>FNt({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT),args:t}))})}bulkUpdate(t){return Rr(this,null,function*(){return this.callWithSession(()=>kFr({emitter:this._emitter,apiService:this._inboxService,cache:this.cache,scheduleCache:this.scheduleCache,useCache:tn(this,bT),args:t}))})}};bT=new WeakMap;function LFr(){return typeof window<"u"}var oF,fle,Dh,MFr=class{constructor(t,e,n){qa(this,oF),qa(this,fle),qa(this,Dh),di(this,oF,n),di(this,fle,e),di(this,Dh,t)}get applicationIdentifier(){return tn(this,Dh).applicationIdentifier}get subscriberId(){var t;return(t=tn(this,Dh).subscriber)==null?void 0:t.subscriberId}get context(){return tn(this,Dh).context}get subscriberHash(){return tn(this,Dh).subscriberHash}get contextHash(){return tn(this,Dh).contextHash}get subscriber(){return tn(this,Dh).subscriber}handleApplicationIdentifier(t,e){if(typeof window>"u"||!window.localStorage)return null;const n="novu_keyless_application_identifier";switch(t){case"get":return window.localStorage.getItem(n);case"store":return e&&window.localStorage.setItem(n,e),null;case"delete":return window.localStorage.removeItem(n),null;default:return null}}initialize(t){return Rr(this,null,function*(){var e,n,r,i,o,l;const u=((e=tn(this,Dh).subscriber)==null?void 0:e.subscriberId)===((n=t?.subscriber)==null?void 0:n.subscriberId),d=JSON.stringify(tn(this,Dh).context)===JSON.stringify(t?.context);if(!(u&&d))try{t&&di(this,Dh,t);const{subscriber:p,subscriberHash:m,contextHash:g,applicationIdentifier:h,defaultSchedule:f,context:b}=tn(this,Dh);let y;LFr()&&(y=Intl.DateTimeFormat().resolvedOptions().timeZone);let v=h;if(v)this.handleApplicationIdentifier("delete");else{const w=this.handleApplicationIdentifier("get");w&&(v=w)}tn(this,oF).emit("session.initialize.pending",{args:tn(this,Dh)});const _=yield tn(this,fle).initializeSession({applicationIdentifier:v,subscriberHash:m,contextHash:g,subscriber:wc(fi({},p),{subscriberId:(r=p?.subscriberId)!=null?r:"",timezone:(i=p?.timezone)!=null?i:y}),defaultSchedule:f,context:b});(o=_?.applicationIdentifier)!=null&&o.startsWith("pk_keyless_")&&this.handleApplicationIdentifier("store",_.applicationIdentifier),(l=_?.applicationIdentifier)!=null&&l.startsWith("pk_keyless_")||this.handleApplicationIdentifier("delete"),tn(this,oF).emit("session.initialize.resolved",{args:tn(this,Dh),data:_})}catch(p){tn(this,oF).emit("session.initialize.resolved",{args:tn(this,Dh),error:p})}})}};oF=new WeakMap,fle=new WeakMap,Dh=new WeakMap;var Ale="wss://socket.novu.co",$Nt="notifications.notification_received",jNt="notifications.unseen_count_changed",zNt="notifications.unread_count_changed",PFr=({_id:t,transactionId:e,content:n,read:r,seen:i,archived:o,snoozedUntil:l,deliveredAt:u,createdAt:d,lastReadDate:p,firstSeenDate:m,archivedAt:g,channel:h,subscriber:f,subject:b,avatar:y,cta:v,tags:_,data:w,workflow:x,severity:k})=>{var C,E,S,I,B,N,L,M;const R={id:f?._id,subscriberId:f?.subscriberId,firstName:f?.firstName,lastName:f?.lastName,avatar:f?.avatar,locale:f?.locale,data:f?.data,timezone:f?.timezone,email:f?.email,phone:f?.phone},D=(E=(C=v.action)==null?void 0:C.buttons)==null?void 0:E.find($=>$.type==="primary"),P=(I=(S=v.action)==null?void 0:S.buttons)==null?void 0:I.find($=>$.type==="secondary"),O=(N=(B=v.action)==null?void 0:B.result)==null?void 0:N.type,F=(L=v.action)==null?void 0:L.status;return wc(fi(fi({id:t,transactionId:e,subject:b,body:n,to:R,isRead:r,isSeen:i,isArchived:o,isSnoozed:!!l},u&&{deliveredAt:u}),l&&{snoozedUntil:l}),{createdAt:d,readAt:p,firstSeenAt:m,archivedAt:g,avatar:y,primaryAction:D&&{label:D.content,isCompleted:O==="primary"&&F==="done",redirect:D.url?{target:D.target,url:D.url}:void 0},secondaryAction:P&&{label:P.content,isCompleted:O==="secondary"&&F==="done",redirect:P.url?{target:P.target,url:P.url}:void 0},channelType:h,tags:_,redirect:(M=v.data)!=null&&M.url?{url:v.data.url,target:v.data.target}:void 0,data:w,workflow:x,severity:k})},rG,ik,sk,aG,sRe,oRe,lRe,cRe,t3,UNt,uRe,dRe,OFr=class extends aF{constructor({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,t3),qa(this,rG),qa(this,ik),qa(this,sk),qa(this,aG),qa(this,sRe,r=>{try{const i=JSON.parse(r.data);i.event==="notification_received"&&tn(this,ik).emit($Nt,{result:new Nm(PFr(i.data.message),tn(this,ik),this._inboxService)})}catch(i){console.log("error",i)}}),qa(this,oRe,r=>{try{const i=JSON.parse(r.data);i.event==="unseen_count_changed"&&tn(this,ik).emit(jNt,{result:i.data.unseenCount})}catch{}}),qa(this,lRe,r=>{try{const i=JSON.parse(r.data);i.event==="unread_count_changed"&&tn(this,ik).emit(zNt,{result:i.data.counts})}catch{}}),qa(this,cRe,r=>{try{switch(JSON.parse(r.data).event){case"notification_received":tn(this,sRe).call(this,r);break;case"unseen_count_changed":tn(this,oRe).call(this,r);break;case"unread_count_changed":tn(this,lRe).call(this,r);break;default:}}catch{}}),di(this,ik,n),di(this,aG,t??Ale)}onSessionSuccess({token:t}){di(this,rG,t)}isSocketEvent(t){return t===$Nt||t===jNt||t===zNt}connect(){return Rr(this,null,function*(){return tn(this,rG)?tk(this,t3,uRe).call(this):this.callWithSession(tk(this,t3,uRe).bind(this))})}disconnect(){return Rr(this,null,function*(){return tn(this,sk)?tk(this,t3,dRe).call(this):this.callWithSession(tk(this,t3,dRe).bind(this))})}};rG=new WeakMap,ik=new WeakMap,sk=new WeakMap,aG=new WeakMap,sRe=new WeakMap,oRe=new WeakMap,lRe=new WeakMap,cRe=new WeakMap,t3=new WeakSet,UNt=function(){return Rr(this,null,function*(){if(tn(this,sk))return;const t={socketUrl:tn(this,aG)};tn(this,ik).emit("socket.connect.pending",{args:t});const e=new URL(tn(this,aG));e.searchParams.set("token",tn(this,rG)),di(this,sk,new mOr(e.toString())),tn(this,sk).addEventListener("open",()=>{tn(this,ik).emit("socket.connect.resolved",{args:t})}),tn(this,sk).addEventListener("error",n=>{tn(this,ik).emit("socket.connect.resolved",{args:t,error:n})}),tn(this,sk).addEventListener("message",tn(this,cRe))})},uRe=function(){return Rr(this,null,function*(){try{return yield tk(this,t3,UNt).call(this),{}}catch(t){return{error:new go("Failed to initialize the PartySocket",t)}}})},dRe=function(){return Rr(this,null,function*(){var t;try{return(t=tn(this,sk))==null||t.close(),di(this,sk,void 0),{}}catch(e){return{error:new go("Failed to disconnect from the PartySocket",e)}}})};var FFr="https://ws.novu.co",qNt="notifications.notification_received",GNt="notifications.unseen_count_changed",HNt="notifications.unread_count_changed",QFr=({_id:t,transactionId:e,content:n,read:r,seen:i,archived:o,snoozedUntil:l,deliveredAt:u,createdAt:d,lastReadDate:p,firstSeenDate:m,archivedAt:g,channel:h,subscriber:f,subject:b,avatar:y,cta:v,tags:_,data:w,workflow:x,severity:k})=>{var C,E,S,I,B,N,L,M;const R={id:f?._id,subscriberId:f?.subscriberId,firstName:f?.firstName,lastName:f?.lastName,avatar:f?.avatar,locale:f?.locale,data:f?.data,timezone:f?.timezone,email:f?.email,phone:f?.phone},D=(E=(C=v.action)==null?void 0:C.buttons)==null?void 0:E.find($=>$.type==="primary"),P=(I=(S=v.action)==null?void 0:S.buttons)==null?void 0:I.find($=>$.type==="secondary"),O=(N=(B=v.action)==null?void 0:B.result)==null?void 0:N.type,F=(L=v.action)==null?void 0:L.status;return wc(fi(fi({id:t,transactionId:e,subject:b,body:n,to:R,isRead:r,isSeen:i,isArchived:o,isSnoozed:!!l},u&&{deliveredAt:u}),l&&{snoozedUntil:l}),{createdAt:d,readAt:p,firstSeenAt:m,archivedAt:g,avatar:y,primaryAction:D&&{label:D.content,isCompleted:O==="primary"&&F==="done",redirect:D.url?{target:D.target,url:D.url}:void 0},secondaryAction:P&&{label:P.content,isCompleted:O==="secondary"&&F==="done",redirect:P.url?{target:P.target,url:P.url}:void 0},channelType:h,tags:_,redirect:(M=v.data)!=null&&M.url?{url:v.data.url,target:v.data.target}:void 0,data:w,workflow:x,severity:k})},iG,ok,Sy,sG,pRe,mRe,gRe,n3,WNt,hRe,fRe,$Fr=class extends aF{constructor({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){super({eventEmitterInstance:n,inboxServiceInstance:e}),qa(this,n3),qa(this,iG),qa(this,ok),qa(this,Sy),qa(this,sG),qa(this,pRe,({message:r})=>{tn(this,ok).emit(qNt,{result:new Nm(QFr(r),tn(this,ok),this._inboxService)})}),qa(this,mRe,({unseenCount:r})=>{tn(this,ok).emit(GNt,{result:r})}),qa(this,gRe,({counts:r})=>{tn(this,ok).emit(HNt,{result:r})}),di(this,ok,n),di(this,sG,t??FFr)}onSessionSuccess({token:t}){di(this,iG,t)}isSocketEvent(t){return t===qNt||t===GNt||t===HNt}connect(){return Rr(this,null,function*(){return tn(this,iG)?tk(this,n3,hRe).call(this):this.callWithSession(tk(this,n3,hRe).bind(this))})}disconnect(){return Rr(this,null,function*(){return tn(this,Sy)?tk(this,n3,fRe).call(this):this.callWithSession(tk(this,n3,fRe).bind(this))})}};iG=new WeakMap,ok=new WeakMap,Sy=new WeakMap,sG=new WeakMap,pRe=new WeakMap,mRe=new WeakMap,gRe=new WeakMap,n3=new WeakSet,WNt=function(){return Rr(this,null,function*(){var t,e,n;if(tn(this,Sy))return;const r={socketUrl:tn(this,sG)};tn(this,ok).emit("socket.connect.pending",{args:r}),di(this,Sy,Yoe(tn(this,sG),{reconnectionDelayMax:1e4,transports:["websocket"],query:{token:`${tn(this,iG)}`}})),tn(this,Sy).on("connect",()=>{tn(this,ok).emit("socket.connect.resolved",{args:r})}),tn(this,Sy).on("connect_error",i=>{tn(this,ok).emit("socket.connect.resolved",{args:r,error:i})}),(t=tn(this,Sy))==null||t.on("notification_received",tn(this,pRe)),(e=tn(this,Sy))==null||e.on("unseen_count_changed",tn(this,mRe)),(n=tn(this,Sy))==null||n.on("unread_count_changed",tn(this,gRe))})},hRe=function(){return Rr(this,null,function*(){try{return yield tk(this,n3,WNt).call(this),{}}catch(t){return{error:new go("Failed to initialize the socket",t)}}})},fRe=function(){return Rr(this,null,function*(){var t;try{return(t=tn(this,Sy))==null||t.disconnect(),di(this,Sy,void 0),{}}catch(e){return{error:new go("Failed to disconnect from the socket",e)}}})};var jFr=["wss://eu.socket.novu.co",Ale,"wss://socket.novu-staging.co","wss://socket-worker-local.cli-shortener.workers.dev"],zFr={"https://eu.ws.novu.co":"wss://eu.socket.novu.co","https://ws.novu.co":Ale,"https://dev.ws.novu.co":"wss://socket.novu-staging.co"};function UFr(t){return t?zFr[t]||t:Ale}function qFr(t){return!t||jFr.includes(t)}function GFr({socketUrl:t,inboxServiceInstance:e,eventEmitterInstance:n}){const r=UFr(t);return(qFr(r)?"partysocket":"socket.io")==="partysocket"?new OFr({socketUrl:r,inboxServiceInstance:e,eventEmitterInstance:n}):new $Fr({socketUrl:r,inboxServiceInstance:e,eventEmitterInstance:n})}var lk,Nh,yT,ble,HFr=class{constructor(t){qa(this,lk),qa(this,Nh),qa(this,yT),qa(this,ble);var e,n,r;di(this,ble,t),di(this,yT,new AFr({apiUrl:t.apiUrl||t.backendUrl,userAgent:t.__userAgent})),di(this,lk,new bFr);const i=jNe({subscriberId:t.subscriberId,subscriber:t.subscriber}),o=GDt(t.context);di(this,Nh,new MFr({applicationIdentifier:t.applicationIdentifier||"",subscriberHash:t.subscriberHash,subscriber:i,defaultSchedule:t.defaultSchedule,context:t.context,contextHash:t.contextHash},tn(this,yT),tn(this,lk))),tn(this,Nh).initialize(),this.notifications=new xFr({useCache:(e=t.useCache)!=null?e:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.preferences=new RFr({useCache:(n=t.useCache)!=null?n:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.subscriptions=new mFr({subscriber:i,contextKey:o,useCache:(r=t.useCache)!=null?r:!0,inboxServiceInstance:tn(this,yT),eventEmitterInstance:tn(this,lk)}),this.socket=GFr({socketUrl:t.socketUrl,eventEmitterInstance:tn(this,lk),inboxServiceInstance:tn(this,yT)}),this.on=(l,u)=>{this.socket.isSocketEvent(l)&&this.socket.connect();const d=tn(this,lk).on(l,u);return()=>{d()}},this.off=(l,u)=>{tn(this,lk).off(l,u)}}get applicationIdentifier(){return tn(this,Nh).applicationIdentifier}get subscriberId(){return tn(this,Nh).subscriberId}get context(){return tn(this,Nh).context}get options(){return tn(this,ble)}get contextKey(){return GDt(tn(this,Nh).context)}clearCache(){this.notifications.cache.clearAll(),this.preferences.cache.clearAll(),this.preferences.scheduleCache.clearAll(),this.subscriptions.cache.clearAll()}changeSubscriber(t){return Rr(this,null,function*(){yield tn(this,Nh).initialize({applicationIdentifier:tn(this,Nh).applicationIdentifier||"",subscriberHash:t.subscriberHash,subscriber:t.subscriber,context:tn(this,Nh).context,contextHash:tn(this,Nh).contextHash}),this.clearCache(),(yield this.socket.disconnect()).error||(yield this.socket.connect())})}changeContext(t){return Rr(this,null,function*(){const e=tn(this,Nh).subscriber;if(!e)throw new Error("Cannot change context without an active subscriber");yield tn(this,Nh).initialize({applicationIdentifier:tn(this,Nh).applicationIdentifier||"",subscriberHash:tn(this,Nh).subscriberHash,subscriber:e,context:t.context,contextHash:t.contextHash}),this.clearCache(),(yield this.socket.disconnect()).error||(yield this.socket.connect())})}};lk=new WeakMap,Nh=new WeakMap,yT=new WeakMap,ble=new WeakMap;var WFr="3.13.0",YFr="@novu/react",VFr=`${YFr}@${WFr}`,YNt=T.createContext(void 0),KFr=t=>{const{subscriberId:e,...n}=t,r=T.useMemo(()=>jNe({subscriberId:e,subscriber:t.subscriber}),[e,t.subscriber]),i=n.applicationIdentifier?n.applicationIdentifier:"",o={...n,applicationIdentifier:i,subscriber:r};return A.jsx(ZFr,{...o,applicationIdentifier:i,userAgentType:"hooks",children:t.children})},ZFr=t=>{const e=t.applicationIdentifier||"",n=T.useMemo(()=>jNe({subscriberId:t.subscriberId,subscriber:t.subscriber}),[t.subscriberId,t.subscriber]),{children:r,subscriberHash:i,contextHash:o,backendUrl:l,apiUrl:u,socketUrl:d,useCache:p,userAgentType:m,defaultSchedule:g,context:h}=t,f=T.useMemo(()=>new HFr({applicationIdentifier:e,subscriberHash:i,contextHash:o,backendUrl:l,apiUrl:u,socketUrl:d,useCache:p,__userAgent:`${VFr} ${m}`,subscriber:n,defaultSchedule:g,context:h}),[e,i,n,h,o,l,u,d,p,m]);return A.jsx(YNt.Provider,{value:f,children:r})},ARe=()=>{const t=T.useContext(YNt);if(!t)throw new Error("useNovu must be used within a <NovuProvider />");return t},yle=t=>{const e=T.useRef(t);return e.current=t,e};function XFr(t,e){if(!("locks"in navigator))return e(t),()=>{};let n=!1,r;const i=new Promise(o=>{r=o});return navigator.locks.request(t,()=>(n||e(t),i)),()=>{n=!0,r()}}var JFr=({channelName:t,onMessage:e})=>{const[n]=T.useState(typeof BroadcastChannel<"u"?new BroadcastChannel(t):void 0),r=i=>{n?.postMessage(i)};return T.useEffect(()=>{const i=o=>{e(o.data)};return n?.addEventListener("message",i),()=>{n?.removeEventListener("message",i)}},[]),{postMessage:r}},bRe=({event:t,eventHandler:e})=>{const n=ARe(),r=`nv_ws_connection:a=${n.applicationIdentifier}:s=${n.subscriberId}:c=${n.contextKey}:e=${t}`,{postMessage:i}=JFr({channelName:r,onMessage:e}),o=l=>{e(l),i(l)};T.useEffect(()=>{let l;const u=XFr(r,()=>{l=n.on(t,o)});return()=>{l&&l(),u()}},[])},e8r=t=>{const{filters:e,onSuccess:n,onError:r}=t,{notifications:i}=ARe(),o=yle(e),[l,u]=T.useState(),[d,p]=T.useState(),[m,g]=T.useState(!0),[h,f]=T.useState(!1),b=async(v,_)=>{const w=_||o.current,x=w.map(S=>({count:0,filter:S}));let k=[];if(v)for(let S=0;S<x.length;S++){const I=w[S],B=!I.severity||Array.isArray(I.severity)&&I.severity.length===0||Array.isArray(I.severity)&&I.severity.includes(v.severity)||!Array.isArray(I.severity)&&I.severity===v.severity;rRe(I.tags,v.tags)&&B&&k.push(I)}else k=w;if(k.length===0)return;f(!0);const C=await i.count({filters:k});if(f(!1),g(!1),C.error){u(C.error),r?.(C.error);return}const E=C.data;n?.(E.counts),p(S=>{const I=[],B=E.counts;for(let N=0;N<x.length;N++){const L=x[N].filter,R=B.find(D=>Voe(D.filter,L))||S?.[N];R&&I.push(R)}return I})};return bRe({event:"notifications.notification_received",eventHandler:v=>{b(v.result)}}),bRe({event:"notifications.unread_count_changed",eventHandler:()=>{b()}}),T.useEffect(()=>{u(void 0),g(!0),f(!1),b(void 0,e)},[JSON.stringify(e)]),{counts:d,error:l,refetch:async()=>{await b()},isLoading:m,isFetching:h}},t8r=t=>{const{tags:e,data:n,read:r,archived:i=!1,snoozed:o=!1,seen:l,severity:u,limit:d=10,onSuccess:p,onError:m}=t||{},g=yle(d),h=yle({tags:e,data:n,read:r,archived:i,snoozed:o,seen:l,severity:u}),f=ARe(),[b,y]=T.useState(),[v,_]=T.useState(),[w,x]=T.useState(!0),[k,C]=T.useState(!1),[E,S]=T.useState(!1),I=b?.length,B=I?b[I-1].id:void 0,N=yle(B);T.useEffect(()=>{const $=({data:Q})=>{!Q||!Voe(h.current,Q.filter)||(y(Q.notifications),S(Q.hasMore))},j=f.on("notifications.list.updated",$);return()=>{j()}},[h,f]),bRe({event:"notifications.notification_received",eventHandler:({result:$})=>{const j=h.current;if(oFr($,j)){const z={...j,limit:g.current};f.notifications.cache.unshift(z,$)}}});const L=T.useCallback(async $=>{$?.refetch&&(_(void 0),x(!0),C(!1)),C(!0);const j=await f.notifications.list({...h.current,limit:d,after:$?.refetch?void 0:N.current});if(j.error)_(j.error),m?.(j.error),x(!1),C(!1);else if(j.data){const Q=j.data;p?.(Q.notifications),y(Q.notifications),S(Q.hasMore),x(!1),C(!1)}},[f,h,N,d,m,p]);T.useEffect(()=>{f.notifications.clearCache({filter:h.current}),L({refetch:!0})},[h,f,JSON.stringify(h.current),L]);const M=T.useCallback(()=>(f.notifications.clearCache({filter:h.current}),L({refetch:!0})),[h,f,L]),R=T.useCallback(async()=>{if(!(!E||k))return L()},[E,k,L]),D=T.useCallback(async()=>await f.notifications.readAll({tags:h.current.tags,data:h.current.data}),[h,f]),P=T.useCallback(async()=>await f.notifications.seenAll({tags:h.current.tags,data:h.current.data}),[h,f]),O=T.useCallback(async()=>await f.notifications.archiveAll({tags:h.current.tags,data:h.current.data}),[h,f]),F=T.useCallback(async()=>await f.notifications.archiveAllRead({tags:h.current.tags,data:h.current.data}),[h,f]);return{readAll:D,seenAll:P,archiveAll:O,archiveAllRead:F,notifications:b,error:v,isLoading:w,isFetching:k,refetch:M,fetchMore:R,hasMore:E}};const yRe=[{id:"pwa-install",titleKey:"notifications.system.pwa.title",bodyKey:"notifications.system.pwa.body",dismissStorageKey:"xyzen-pwa-prompt-dismissed",condition:()=>{const t=window.matchMedia("(display-mode: standalone)").matches;return window.matchMedia("(min-width: 1024px)").matches&&!t}}];function n8r(){const{t}=En(),[e,n]=T.useState(()=>{const o=new Set;for(const l of yRe)localStorage.getItem(l.dismissStorageKey)&&o.add(l.id);return o}),r=T.useMemo(()=>yRe.filter(o=>!e.has(o.id)&&o.condition()).map(o=>({id:o.id,title:t(o.titleKey),body:t(o.bodyKey)})),[t,e]),i=T.useCallback(o=>{const l=yRe.find(u=>u.id===o);l&&localStorage.setItem(l.dismissStorageKey,"true"),n(u=>new Set(u).add(o))},[]);return{notifications:r,dismiss:i,count:r.length}}const r8r=[{key:"all",icon:D9n},{key:"unread",icon:tlt},{key:"archived",icon:Oke}],a8r=/\n<!-- meta:(.*?) -->$/;function i8r(t){const e=a8r.exec(t);if(!e)return{body:t,title:"",agentName:"",agentAvatar:"",url:"",messageId:""};const n=t.slice(0,e.index);try{const r=JSON.parse(e[1]);return{body:n,title:r.title??"",agentName:r.agent_name??"",agentAvatar:r.agent_avatar??"",url:r.url??"",messageId:r.message_id??""}}catch{return{body:t,title:"",agentName:"",agentAvatar:"",url:"",messageId:""}}}function VNt({items:t,onDismiss:e}){const{t:n}=En();return t.length===0?null:A.jsxs("div",{className:"border-b border-neutral-100 dark:border-neutral-800/60",children:[A.jsx("div",{className:"px-4 pt-2 pb-1",children:A.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wide text-neutral-400 dark:text-neutral-500",children:n("notifications.system.title")})}),t.map(r=>A.jsxs("div",{className:"group flex gap-3 px-4 py-3 bg-amber-50/40 dark:bg-amber-950/10",children:[A.jsx("div",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full bg-amber-100 text-amber-600 dark:bg-amber-500/10 dark:text-amber-400",children:A.jsx(Fae,{className:"h-4.5 w-4.5"})}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsx("p",{className:"text-[13px] font-semibold text-neutral-900 dark:text-neutral-100",children:r.title}),A.jsx("p",{className:"mt-0.5 text-[13px] leading-snug text-neutral-500 dark:text-neutral-400",children:r.body})]}),A.jsx("button",{onClick:()=>e(r.id),className:"flex-shrink-0 self-start rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-200/70 hover:text-neutral-600 dark:hover:bg-neutral-700/50 dark:hover:text-neutral-300",title:n("notifications.system.dismiss"),children:A.jsx(D1,{className:"h-3.5 w-3.5"})})]},r.id))]})}function s8r({systemCount:t=0}){const{counts:e}=e8r({filters:[{read:!1}]}),n=(e?.[0]?.count??0)+t;return n===0?null:A.jsx("span",{className:"absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-red-500 px-1 text-[10px] font-bold text-white shadow-sm",children:n>99?"99+":n})}const oG="rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-200/70 hover:text-neutral-600 active:bg-neutral-200/70 dark:hover:bg-neutral-700/50 dark:hover:text-neutral-300",o8r=T.memo(function({notification:e,isArchivedView:n,onNavigate:r}){const i=$Dt(e.createdAt),o=i8r(e.body??""),l=T.useCallback(async()=>{e.isRead||await e.read();const h=o.url||e.redirect?.url;if(!h)return;const f=/\/#\/chat\/([a-zA-Z0-9_-]+)/.exec(h),b=/[?&]topic=([^&]+)/.exec(h),y=f?.[1]??b?.[1];y&&r?r(y,o.messageId||void 0):window.location.hash=`#${h}`},[e,o.url,o.messageId,r]),u=T.useCallback(async h=>{h.stopPropagation(),e.isRead?await e.unread():await e.read()},[e]),d=T.useCallback(async h=>{h.stopPropagation(),await e.delete()},[e]),p=T.useCallback(async h=>{h.stopPropagation(),await e.unarchive()},[e]),m=T.useCallback(async h=>{h.stopPropagation(),await e.archive()},[e]),g=o.agentName||o.title;return A.jsxs(Ct.div,{layout:!0,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,x:60},transition:{duration:.2},onClick:l,className:Yt("group relative flex cursor-pointer gap-3 px-4 py-3","border-b border-neutral-100 dark:border-neutral-800/60","transition-colors hover:bg-neutral-50/80 dark:hover:bg-neutral-800/40",!e.isRead&&"bg-blue-50/40 dark:bg-blue-950/20"),children:[A.jsxs("div",{className:"relative flex-shrink-0 pt-0.5",children:[o.agentAvatar?A.jsx("img",{src:o.agentAvatar,alt:g,className:"h-9 w-9 rounded-full object-cover"}):A.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-indigo-600 text-xs font-semibold text-white",children:(g||"N").charAt(0).toUpperCase()}),!e.isRead&&A.jsx("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2 border-white bg-blue-500 dark:border-neutral-900"})]}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsxs("div",{className:"flex items-center gap-1",children:[g&&A.jsx("p",{className:"truncate text-[13px] font-semibold text-neutral-900 dark:text-neutral-100",children:g}),A.jsx("span",{className:"flex-shrink-0 text-[11px] text-neutral-400 dark:text-neutral-500",children:i}),A.jsx("div",{className:"ml-auto flex flex-shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 max-md:opacity-100",children:n?A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:p,className:oG,title:"Restore",children:A.jsx(slt,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:d,className:oG,title:"Delete",children:A.jsx(qte,{className:"h-3.5 w-3.5"})})]}):A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:u,className:oG,title:e.isRead?"Mark as unread":"Mark as read",children:e.isRead?A.jsx(tlt,{className:"h-3.5 w-3.5"}):A.jsx(sh,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:m,className:oG,title:"Archive",children:A.jsx(Oke,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:d,className:oG,title:"Delete",children:A.jsx(qte,{className:"h-3.5 w-3.5"})})]})})]}),A.jsx("p",{className:Yt("mt-0.5 line-clamp-2 text-[13px] leading-snug",g?"text-neutral-500 dark:text-neutral-400":"text-neutral-700 dark:text-neutral-300"),children:o.body})]})]})});function l8r({filter:t,onNavigate:e}){const{t:n}=En(),{notifications:r,isLoading:i,hasMore:o,fetchMore:l,readAll:u,archiveAllRead:d}=t8r(t),p=!!t.archived,[m,g]=T.useState(!1),h=T.useCallback(async()=>{if(!(!r||r.length===0||m)){g(!0);try{await Promise.all(r.map(b=>b.delete()))}finally{g(!1)}}},[r,m]),f=T.useRef(null);return T.useEffect(()=>{if(!f.current||!o)return;const b=new IntersectionObserver(([y])=>{y.isIntersecting&&l()},{rootMargin:"200px"});return b.observe(f.current),()=>b.disconnect()},[o,l]),A.jsxs("div",{className:"flex h-full flex-col",children:[!p&&A.jsxs("div",{className:"flex items-center justify-end gap-1 border-b border-neutral-100 px-4 py-1.5 dark:border-neutral-800/60",children:[A.jsx("button",{onClick:()=>u(),className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800/40 dark:hover:text-neutral-300",title:n("notifications.actions.readAll"),children:A.jsx(g9n,{className:"h-3.5 w-3.5"})}),A.jsx("button",{onClick:()=>d(),className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800/40 dark:hover:text-neutral-300",title:n("notifications.actions.archiveRead"),children:A.jsx(Oke,{className:"h-3.5 w-3.5"})})]}),p&&r&&r.length>0&&A.jsx("div",{className:"flex items-center justify-end gap-1 border-b border-neutral-100 px-4 py-1.5 dark:border-neutral-800/60",children:A.jsxs(BNe,{children:[A.jsx(qPr,{asChild:!0,children:A.jsx("button",{disabled:m,className:"rounded-md p-1.5 text-neutral-400 transition-colors hover:bg-red-50 hover:text-red-500 disabled:opacity-40 dark:hover:bg-red-500/10 dark:hover:text-red-400",title:n("notifications.actions.deleteAll"),children:A.jsx(qte,{className:"h-3.5 w-3.5"})})}),A.jsxs(DNe,{className:"sm:max-w-sm rounded-sm",children:[A.jsxs(NNe,{children:[A.jsx(LNe,{className:"text-sm",children:n("notifications.actions.deleteAll")}),A.jsx(MNe,{className:"text-xs",children:n("notifications.actions.deleteAllConfirm")})]}),A.jsxs(RNe,{children:[A.jsx(ONe,{className:"h-8 rounded-sm text-xs",children:n("common.cancel")}),A.jsx(PNe,{onClick:h,className:"h-8 rounded-sm bg-red-500 text-xs text-white hover:bg-red-600 dark:bg-red-600 dark:hover:bg-red-500",children:n("notifications.actions.confirmDelete")})]})]})]})}),A.jsxs("div",{className:"custom-scrollbar flex-1 overflow-y-auto",children:[A.jsx(Fr,{mode:"popLayout",children:r?.map(b=>A.jsx(o8r,{notification:b,isArchivedView:p,onNavigate:e},b.id))}),i&&A.jsx("div",{className:"space-y-1 p-4",children:Array.from({length:3}).map((b,y)=>A.jsxs("div",{className:"flex animate-pulse gap-3 py-3",children:[A.jsx("div",{className:"h-9 w-9 flex-shrink-0 rounded-full bg-neutral-200 dark:bg-neutral-700"}),A.jsxs("div",{className:"flex-1 space-y-2",children:[A.jsx("div",{className:"h-3 w-3/4 rounded bg-neutral-200 dark:bg-neutral-700"}),A.jsx("div",{className:"h-3 w-1/2 rounded bg-neutral-200 dark:bg-neutral-700"})]})]},y))}),!i&&(!r||r.length===0)&&A.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-neutral-400 dark:text-neutral-500",children:[A.jsx(Fae,{className:"mb-3 h-10 w-10 opacity-40"}),A.jsx("p",{className:"text-sm",children:n("notifications.empty")})]}),o&&A.jsx("div",{ref:f,className:"h-4"})]})]})}const c8r={all:{archived:!1},unread:{read:!1,archived:!1},archived:{archived:!0}};function KNt({onNavigate:t}){const{t:e}=En(),[n,r]=T.useState("all");return A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsx("div",{className:"px-4 pt-1 pb-1.5",children:A.jsx("div",{className:"flex rounded-lg bg-neutral-100/80 p-0.5 dark:bg-neutral-800/50",children:r8r.map(({key:i,icon:o})=>A.jsxs("button",{onClick:()=>r(i),className:Yt("relative flex flex-1 items-center justify-center gap-1.5 rounded-md py-1.5 text-xs font-medium transition-colors",n===i?"text-neutral-900 dark:text-neutral-100":"text-neutral-500 hover:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-200"),children:[n===i&&A.jsx(Ct.div,{layoutId:"notification-tab",className:"absolute inset-0 rounded-md bg-white shadow-sm dark:bg-neutral-700",transition:{type:"spring",stiffness:400,damping:30}}),A.jsxs("span",{className:"relative z-10 flex items-center gap-1.5",children:[A.jsx(o,{className:"h-3.5 w-3.5"}),e(`notifications.filter.${i}`)]})]},i))})}),A.jsx(l8r,{filter:c8r[n],onNavigate:t},n)]})}function u8r(){const{t}=En(),e=Hq(),n=n8r(),{activateChannel:r,setActivePanel:i,requestFocusAgent:o,setMobilePage:l,setMobileCeoOverlay:u,highlightMessage:d}=Un(Ws(v=>({activateChannel:v.activateChannel,setActivePanel:v.setActivePanel,requestFocusAgent:v.requestFocusAgent,setMobilePage:v.setMobilePage,setMobileCeoOverlay:v.setMobileCeoOverlay,highlightMessage:v.highlightMessage}))),[p,m]=T.useState(!1),[g,h]=T.useState(!1),f=T.useCallback(()=>m(v=>!v),[]),b=T.useCallback(()=>m(!1),[]),y=T.useCallback(async(v,_)=>{b(),i("chat"),e&&(u(!1),l(1)),await r(v);const w=Un.getState().channels[v];w?.agentId&&o(w.agentId),_&&d(_)},[b,r,i,o,e,l,u,d]);return T.useEffect(()=>{if(!p)return;const v=_=>{_.key==="Escape"&&b()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[p,b]),A.jsxs(A.Fragment,{children:[A.jsxs("div",{className:"relative",children:[A.jsxs(Ct.button,{whileHover:{scale:1.1},whileTap:{scale:.9},onClick:f,onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),className:"relative flex items-center justify-center h-7 w-7 text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors",children:[A.jsx(Fae,{className:"h-4.5 w-4.5"}),A.jsx(s8r,{systemCount:n.count})]}),A.jsx(Fr,{children:g&&!p&&!e&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-10 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[t("notifications.bell.title"),A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})})]}),e&&A.jsx(Hc,{isOpen:p,onClose:b,mobileHeight:"h-[85vh]",size:"sm",children:A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsxs("div",{className:"flex items-center justify-between px-5 pt-6 pb-2 md:py-2",children:[A.jsx("h2",{className:"text-base font-semibold text-neutral-900 dark:text-neutral-100",children:t("notifications.bell.title")}),A.jsx("button",{onClick:b,className:"rounded-lg p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800 dark:hover:text-neutral-300",children:A.jsx(D1,{className:"h-5 w-5"})})]}),A.jsx(VNt,{items:n.notifications,onDismiss:n.dismiss}),A.jsx(KNt,{onNavigate:y})]})}),!e&&zi.createPortal(A.jsx(Fr,{children:p&&A.jsxs(A.Fragment,{children:[A.jsx(Ct.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-[70]",onClick:b}),A.jsx(Ct.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",damping:30,stiffness:300,mass:.8},className:Yt("fixed top-0 right-0 z-[71] h-full w-[380px]","bg-white/90 dark:bg-neutral-900/90","backdrop-blur-2xl","border-l border-neutral-200/60 dark:border-neutral-700/50","shadow-2xl","text-neutral-900 dark:text-neutral-100"),style:{paddingBottom:GA},children:A.jsxs("div",{className:"flex h-full flex-col",children:[A.jsxs("div",{className:"flex items-center justify-between px-5 py-4",children:[A.jsx("h2",{className:"text-base font-semibold",children:t("notifications.bell.title")}),A.jsx("button",{onClick:b,className:"rounded-lg p-1.5 text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 dark:hover:bg-neutral-800 dark:hover:text-neutral-300",children:A.jsx(D1,{className:"h-5 w-5"})})]}),A.jsx(VNt,{items:n.notifications,onDismiss:n.dismiss}),A.jsx(KNt,{onNavigate:y})]})},"notification-drawer")]})}),document.body)]})}function ZNt(){const{notificationEnabled:t,novuAppIdentifier:e,novuApiUrl:n,novuWsUrl:r}=FNe(),i=ah();return!t||!e||!i.isAuthenticated?null:A.jsx(KFr,{applicationIdentifier:e,subscriberId:i.user?.id??"",backendUrl:n||void 0,socketUrl:r||void 0,children:A.jsx(u8r,{})})}const GA=72,Rm=8,lF=Yl()?28:Rm;function d8r({mouseX:t,item:e,isActive:n,onClick:r}){const i=T.useRef(null),[o,l]=T.useState(!1),u=Ub(t,y=>{const v=i.current?.getBoundingClientRect()??{x:0,width:0};return y-v.x-v.width/2}),d=Ub(u,[-100,0,100],[44,56,44]),p=Ub(u,[-100,0,100],[20,26,20]),m=Ub(u,[-100,0,100],[0,-6,0]),g=YN(d,{mass:.1,stiffness:200,damping:15}),h=YN(p,{mass:.1,stiffness:200,damping:15}),f=YN(m,{mass:.1,stiffness:200,damping:15}),b=e.icon;return A.jsxs(Ct.button,{ref:i,style:{width:g,height:g,y:f},onClick:r,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),className:Yt("relative flex flex-col items-center justify-center gap-0.5 rounded-sm transition-colors duration-200","bg-white/80 dark:bg-neutral-800/60","hover:bg-white dark:hover:bg-neutral-700/80","border border-neutral-200/40 dark:border-neutral-700/30",n&&"bg-white dark:bg-neutral-700/80 shadow-md"),children:[A.jsx(Fr,{children:o&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-10 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs font-medium text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[e.label,A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})}),A.jsx(Ct.div,{style:{width:h,height:h},className:"flex items-center justify-center",children:A.jsx(b,{className:Yt("w-full h-full transition-colors duration-200",n?"text-indigo-600 dark:text-indigo-400":"text-neutral-600 dark:text-neutral-400")})}),n&&A.jsx(Ct.div,{layoutId:"dock-active-indicator",className:"h-1 w-1 rounded-full bg-indigo-500",transition:{type:"spring",stiffness:300,damping:30}})]})}function p8r({compact:t=!1}){const e=ah(),{t:n}=En(),[r,i]=T.useState(!1),[o,l]=T.useState(!1),[u,d]=T.useState(!1),[p,m]=T.useState(!1),g=Un(y=>y.openSettingsModal),h=BO(),f=e.isAuthenticated||!!e.token,b=t?"h-10 w-10":"h-11 w-11";return e.isLoading?A.jsx("div",{className:Yt(b,"flex items-center justify-center rounded-full bg-white/80 dark:bg-neutral-800/60"),children:A.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-neutral-300 border-t-indigo-600 dark:border-neutral-700 dark:border-t-indigo-500"})}):f?A.jsxs(A.Fragment,{children:[A.jsxs(iq,{open:r,onOpenChange:i,children:[A.jsx(sq,{asChild:!0,children:A.jsx(Ct.button,{whileHover:{scale:1.05},whileTap:{scale:.95},className:Yt(b,"relative flex items-center justify-center rounded-full overflow-hidden transition-shadow hover:shadow-lg","ring-2 ring-neutral-200/60 dark:ring-neutral-700/50"),children:e.user?.avatar?A.jsx("img",{src:e.user.avatar,alt:e.user?.username??"User",className:"h-full w-full object-cover"}):A.jsx("div",{className:"flex h-full w-full items-center justify-center bg-gradient-to-br from-indigo-500 to-purple-600",children:A.jsx(GP,{className:"h-5 w-5 text-white"})})})}),A.jsxs(oq,{align:"start",side:"top",sideOffset:12,className:"w-72 mb-2",children:[A.jsxs(NBe,{className:"flex items-center gap-3 p-3",children:[e.user?.avatar?A.jsx("img",{src:e.user.avatar,alt:e.user?.username??"User",className:"h-10 w-10 rounded-full"}):A.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-indigo-500 to-purple-600",children:A.jsx(GP,{className:"h-5 w-5 text-white"})}),A.jsx("div",{className:"flex flex-col",children:A.jsx("span",{className:"text-sm font-semibold text-neutral-900 dark:text-neutral-100",children:e.user?.username??n("app.authStatus.loggedIn")})})]}),A.jsx(EO,{}),h&&A.jsx("div",{className:"px-3 py-2",children:A.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-gradient-to-r from-indigo-50 to-purple-50 dark:from-indigo-950/30 dark:to-purple-950/30 px-3 py-2",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx(xo,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),A.jsxs("div",{children:[A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:n("app.authStatus.pointsBalance")}),A.jsx("div",{className:"text-lg font-bold text-indigo-600 dark:text-indigo-400",children:h.isLoading?"...":h.points??"--"})]})]}),A.jsx("button",{onClick:()=>{i(!1),d(!0)},className:"rounded-full p-1.5 text-neutral-400 hover:bg-white/50 hover:text-indigo-600 dark:hover:bg-neutral-800 dark:hover:text-indigo-400 transition-colors",children:A.jsx(pu,{className:"h-5 w-5"})})]})}),A.jsx(EO,{}),OA("developerReward")&&A.jsxs(lC,{onSelect:()=>{i(!1),m(!0)},className:"flex items-center gap-2 px-3 py-2 cursor-pointer",children:[A.jsx(qae,{className:"h-4 w-4"}),n("subscription.creator")]}),A.jsxs(lC,{onSelect:()=>{i(!1),g()},className:"flex items-center gap-2 px-3 py-2 cursor-pointer",children:[A.jsx(gh,{className:"h-4 w-4"}),n("app.authStatus.settings")]}),A.jsx(EO,{}),A.jsxs(lC,{onSelect:()=>{i(!1),U5()},className:"flex items-center gap-2 px-3 py-2 cursor-pointer text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/20",children:[A.jsx(E2e,{className:"h-4 w-4"}),n("app.authStatus.logout")]})]})]}),h&&A.jsx(NO,{isOpen:u,onClose:()=>d(!1)}),A.jsx(RBe,{isOpen:p,onClose:()=>m(!1)})]}):A.jsxs(A.Fragment,{children:[A.jsx(Ct.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>l(!0),className:Yt(b,"flex items-center justify-center rounded-full bg-white/80 dark:bg-neutral-800/60 border border-amber-200/60 dark:border-amber-700/50 transition-shadow hover:shadow-lg"),title:n("app.authStatus.unauthorized"),children:A.jsx(Fp,{className:"h-5 w-5 text-amber-500"})}),A.jsx(WSt,{isOpen:o,onClose:()=>l(!1),onSubmit:async y=>{await e.login(y)}})]})}const m8r="https://github.com/ScienceOL/Xyzen";function g8r(){const{backend:t}=lNe(),{t:e}=En(),[n,r]=T.useState(!1),[i,o]=T.useState(!1),u=k1()!=="zh-cn";return A.jsxs("div",{className:"relative flex items-center gap-1.5",children:[A.jsx(PPr,{onClick:()=>o(!0),children:e("app.toolbar.joinBeta")}),A.jsx(zPr,{isOpen:i,onClose:()=>o(!1)}),A.jsx("a",{href:m8r,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center h-7 w-7 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-neutral-700/50",children:A.jsx(Xot,{className:"h-4 w-4 text-neutral-500 dark:text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition-colors"})}),A.jsxs("div",{className:"relative flex items-center gap-1 cursor-default",onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[A.jsx("span",{className:"text-[11px] font-medium text-neutral-500 dark:text-neutral-500 tabular-nums",children:t.version||"..."}),A.jsx("div",{className:"flex items-center justify-center h-4 w-4 rounded-sm",title:e(`app.region.${u?"international":"china"}`),children:A.jsx(nz,{className:Yt("h-3 w-3 transition-colors",u?"text-indigo-400/60 dark:text-indigo-500/60":"text-emerald-400/60 dark:text-emerald-500/60")})}),A.jsx(Fr,{children:n&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.15},className:"absolute -top-12 left-1/2 -translate-x-1/2 whitespace-nowrap rounded-lg bg-neutral-900 px-3 py-1.5 text-xs text-white shadow-lg dark:bg-neutral-100 dark:text-neutral-900",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("span",{className:"font-medium",children:e(`app.region.${u?"international":"china"}`)}),A.jsx("span",{className:"text-neutral-400 dark:text-neutral-500",children:"•"}),A.jsx("span",{className:"text-neutral-300 dark:text-neutral-600",children:t.versionName||t.version})]}),A.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 border-4 border-transparent border-t-neutral-900 dark:border-t-neutral-100"})]})})]})]})}const XNt={free:{bg:"bg-neutral-100/80 dark:bg-neutral-800/80",text:"text-neutral-600 dark:text-neutral-400",border:"border-neutral-200/50 dark:border-neutral-700/50",icon:Gte},standard:{bg:"bg-blue-50/80 dark:bg-blue-950/40",text:"text-blue-600 dark:text-blue-400",border:"border-blue-200/50 dark:border-blue-800/50",icon:Ute},professional:{bg:"bg-purple-50/80 dark:bg-purple-950/40",text:"text-purple-600 dark:text-purple-400",border:"border-purple-200/50 dark:border-purple-800/50",icon:jte},ultra:{bg:"bg-amber-100/90 dark:bg-amber-950/40",text:"text-amber-600 dark:text-amber-400",border:"border-amber-300/70 dark:border-amber-800/50",icon:T1}};function JNt(t){return t<1024*1024?`${(t/1024).toFixed(0)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function h8r({visible:t,anchorRef:e,usage:n,daysLeft:r,roleName:i,isExpired:o,isUrgent:l,isWarning:u,respondingCount:d,chatLimit:p,hasOverQuota:m}){const g=e.current?.getBoundingClientRect(),h=t&&n&&g;return zi.createPortal(A.jsx(Fr,{children:h&&A.jsxs(Ct.div,{initial:{opacity:0,y:8,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.95},transition:{duration:.2,ease:"easeOut"},style:{position:"fixed",bottom:window.innerHeight-g.top+8,right:window.innerWidth-g.right},className:"z-[60]",children:[A.jsx("div",{className:Yt("relative flex flex-col gap-1.5 min-w-[180px] rounded-2xl px-4 py-3 text-xs shadow-2xl","bg-white/90 text-neutral-900 backdrop-blur-lg","border border-neutral-200/60","dark:bg-white/5 dark:text-white","dark:border-white/[0.08]"),children:A.jsxs("div",{className:"flex flex-col gap-1.5",children:[r!==null&&i!=="free"&&A.jsxs("div",{className:"flex flex-col gap-1 pb-1.5 mb-0.5 border-b border-neutral-200/40 dark:border-neutral-700/40",children:[A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Expires"}),A.jsx("span",{className:Yt(o&&"text-red-500 dark:text-red-400",l&&"text-red-500 dark:text-red-400",u&&"text-amber-500 dark:text-amber-400"),children:o?"Expired":r===0?"Today":`${r} day${r===1?"":"s"}`})]}),!o&&A.jsx("div",{className:"h-1 rounded-full bg-neutral-200 dark:bg-neutral-700/50 overflow-hidden",children:A.jsx("div",{className:Yt("h-full rounded-full transition-all",l&&"bg-red-500",u&&"bg-amber-500",!l&&!u&&"bg-emerald-500"),style:{width:`${Math.min(100,Math.max(2,r/30*100))}%`}})})]}),A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Storage"}),A.jsxs("span",{className:"font-medium",children:[JNt(n.storage.used_bytes)," /"," ",JNt(n.storage.limit_bytes)]})]}),d>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Chats"}),A.jsxs("span",{className:"font-medium",children:[d," / ",p||"∞"]})]}),n.sandboxes.limit>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Sandboxes"}),A.jsxs("span",{className:"font-medium",children:[n.sandboxes.used," / ",n.sandboxes.limit]})]}),n.scheduled_tasks?.limit>0&&A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Tasks"}),A.jsxs("span",{className:"font-medium",children:[n.scheduled_tasks.used," / ",n.scheduled_tasks.limit]})]}),A.jsxs("div",{className:"flex justify-between gap-4",children:[A.jsx("span",{className:"text-neutral-500 dark:text-neutral-400",children:"Files"}),A.jsxs("span",{className:"font-medium",children:[n.files.used," / ",n.files.limit]})]}),m&&A.jsx("div",{className:"text-red-500 dark:text-red-400 text-[10px] mt-0.5 font-semibold",children:"Quota exceeded"})]})}),A.jsx("div",{className:"absolute -bottom-[5px] right-4 h-2.5 w-2.5 rotate-45 bg-white/90 dark:bg-white/5 backdrop-blur-lg border-b border-r border-neutral-200/60 dark:border-white/[0.06]"})]})}),document.body)}function f8r(){const{t}=En(),e=DO(),n=BO(),r=Un(B=>B.respondingChannelIds.size),[i,o]=T.useState(!1),[l,u]=T.useState(!1),d=T.useRef(null);if(!e||e.subQuery.isLoading)return null;const{subQuery:p,usageQuery:m,roleName:g}=e,h=t(`subscription.plan.${g}`),f=p.data?.subscription?.expires_at,b=p.data?.can_claim_credits??!1,y=XNt[g]??XNt.free,v=g==="free",_=!v&&f?new Date(f)<new Date:!1,w=!v&&f?Math.max(0,Math.ceil((new Date(f).getTime()-Date.now())/(1e3*60*60*24))):null,x=w!==null&&w<=3&&!_,k=w!==null&&w<=7&&!x&&!_,C=m.data,E=C?.chats.limit??0,S=C&&(E>0&&r>E||C.storage.usage_percentage>100),I=y.icon;return A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"relative",ref:d,children:A.jsxs(Ct.button,{whileHover:{scale:1.03},whileTap:{scale:.97},onClick:()=>o(!0),onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:Yt("flex items-center gap-1.5 px-2.5 py-1 rounded-lg transition-colors border text-xs font-medium",y.bg,y.text,y.border,_&&"opacity-60",S&&"ring-1 ring-red-400/50"),children:[A.jsx(I,{className:"size-3.5"}),A.jsx("span",{children:h}),_&&A.jsx("span",{className:"text-[10px] text-red-500 dark:text-red-400 font-semibold",children:"expired"}),b&&!_&&A.jsxs("span",{className:"absolute -top-1 -right-1 flex h-2.5 w-2.5",children:[A.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-red-400 opacity-75"}),A.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-red-500"})]})]})}),A.jsx(h8r,{visible:l&&!!C,anchorRef:d,usage:C??null,daysLeft:w,roleName:g,isExpired:_,isUrgent:x,isWarning:k,respondingCount:r,chatLimit:E,hasOverQuota:!!S}),n&&A.jsx(NO,{isOpen:i,onClose:()=>o(!1)})]})}function A8r({activePanel:t,onPanelChange:e,className:n}){const{t:r}=En(),i=ah(),o=sy(1/0),l=YBe(),[u,d]=T.useState(!1),p=Un(f=>f.dockMinimized),m=i.isAuthenticated||!!i.token,g=[{id:"chat",icon:Wb,label:r("app.activityBar.chat"),panel:"chat"},{id:"knowledge",icon:V1,label:r("app.activityBar.knowledge"),panel:"knowledge"},{id:"skills",icon:zI,label:r("app.activityBar.skills","Skills"),panel:"skills"},{id:"memory",icon:L2e,label:r("app.activityBar.memory"),panel:"memory"},{id:"sandbox",icon:Sf,label:r("app.activityBar.sandbox","Sandbox"),panel:"sandbox"},{id:"runner",icon:pU,label:r("app.activityBar.runner"),panel:"runner"},{id:"tasks",icon:W1,label:r("app.activityBar.tasks","Tasks"),panel:"tasks"},{id:"marketplace",icon:xo,label:r("app.activityBar.community"),panel:"marketplace"}],h=T.useCallback(f=>{f.panel&&e(f.panel),f.onClick?.()},[e]);return p?null:A.jsxs(A.Fragment,{children:[A.jsx("div",{className:Yt("fixed bottom-0 left-0 z-50 pb-2",n),style:{paddingLeft:Rm,paddingRight:Rm},children:A.jsx("div",{className:Yt("h-14 rounded-2xl px-4","bg-white/80 dark:bg-neutral-900/60","backdrop-blur-2xl","border border-neutral-200/50 dark:border-neutral-700/50"),style:{width:`calc(100vw - ${Rm*2}px)`,boxShadow:"0 8px 32px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.12)"},children:A.jsxs("div",{className:"flex h-full items-center",children:[A.jsx("div",{className:"shrink-0",children:A.jsx(p8r,{compact:!0})}),A.jsxs("div",{className:"flex items-center gap-3",children:[A.jsx("div",{className:"h-8 w-px bg-neutral-300/80 dark:bg-neutral-600/30 ml-3"}),A.jsx("div",{className:"flex items-end gap-1.5",onMouseMove:f=>o.set(f.pageX),onMouseLeave:()=>o.set(1/0),children:g.map(f=>A.jsx(d8r,{mouseX:o,item:f,isActive:f.panel===t,onClick:()=>h(f)},f.id))})]}),A.jsx("div",{className:"flex-1"}),A.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[A.jsx(g8r,{}),A.jsx("div",{className:"h-6 w-px bg-neutral-300/80 dark:bg-neutral-600/30"}),l&&m&&A.jsx(Ct.button,{whileHover:{scale:1.1},whileTap:{scale:.95},onClick:()=>d(!0),className:"relative flex items-center justify-center h-8 w-8 rounded-lg text-amber-600 transition-colors hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300",title:r("app.toolbar.checkIn"),children:A.jsx(vR,{className:"h-5 w-5"})}),A.jsx("div",{className:"h-6 w-px bg-neutral-300/80 dark:bg-neutral-600/30"}),A.jsx(f8r,{}),A.jsx(ZNt,{})]})]})})}),l&&A.jsx(TNe,{isOpen:u,onClose:()=>d(!1)})]})}const b8r=ph("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[box-shadow,_color,_background-color,_border-color,_outline-color,_text-decoration-color,_fill,_stroke] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",accent:"bg-accent text-accent-foreground shadow-xs hover:bg-accent/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8 rounded-md","icon-lg":"size-10 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),[y8r,v8r]=QA("RippleButtonContext");function _8r({ref:t,onClick:e,hoverScale:n=1.05,tapScale:r=.95,asChild:i=!1,style:o,...l}){const[u,d]=ee.useState([]),p=ee.useRef(null);ee.useImperativeHandle(t,()=>p.current);const m=ee.useCallback(f=>{const b=p.current;if(!b)return;const y=b.getBoundingClientRect(),v=f.clientX-y.left,_=f.clientY-y.top,w={id:Date.now(),x:v,y:_};d(x=>[...x,w]),setTimeout(()=>{d(x=>x.filter(k=>k.id!==w.id))},600)},[]),g=ee.useCallback(f=>{m(f),e&&e(f)},[m,e]),h=i?G1:Ct.button;return A.jsx(y8r,{value:{ripples:u,setRipples:d},children:A.jsx(h,{ref:p,"data-slot":"ripple-button",onClick:g,whileTap:{scale:r},whileHover:{scale:n},style:{position:"relative",overflow:"hidden",...o},...l})})}function w8r({color:t="var(--ripple-button-ripple-color)",scale:e=10,transition:n={duration:.6,ease:"easeOut"},asChild:r=!1,style:i,...o}){const{ripples:l}=v8r(),u=r?G1:Ct.span;return l.map(d=>A.jsx(u,{initial:{scale:0,opacity:.5},animate:{scale:e,opacity:0},transition:n,style:{position:"absolute",borderRadius:"50%",pointerEvents:"none",width:"20px",height:"20px",backgroundColor:t,top:d.y-10,left:d.x-10,...i},...o},d.id))}const x8r={default:"[--ripple-button-ripple-color:var(--primary-foreground)]",accent:"[--ripple-button-ripple-color:var(--accent-foreground)]",destructive:"[--ripple-button-ripple-color:var(--destructive-foreground)]",outline:"[--ripple-button-ripple-color:var(--foreground)]",secondary:"[--ripple-button-ripple-color:var(--secondary-foreground)]",ghost:"[--ripple-button-ripple-color:var(--foreground)]",link:"[--ripple-button-ripple-color:var(--primary-foreground)]"};function k8r({className:t,variant:e,size:n,...r}){return A.jsx(_8r,{className:Yt(b8r({variant:e,size:n,className:t}),x8r[e]),...r})}function E8r(t){return A.jsx(w8r,{...t})}const eRt=["adventurer","avataaars","bottts","fun-emoji","lorelei","micah","miniavs","notionists","open-peeps","personas","pixel-art","shapes","thumbs"],lG=(t,e,n)=>n?`${n}/xyzen/api/v1/avatar/${t}/svg?seed=${encodeURIComponent(e)}`:`https://api.dicebear.com/9.x/${t}/svg?seed=${e}`,C8r=t=>{const e=[];return eRt.forEach(n=>{for(let r=0;r<6;r++){const i=`${n}_${r}_preset`;e.push({url:lG(n,i,t),seed:i,style:n})}}),e},tRt=t=>{if(!t)return"";try{const e=new URL(t).searchParams.get("seed");return e?decodeURIComponent(e):""}catch{const e=t.match(/[?&]seed=([^&]*)/);return e?decodeURIComponent(e[1]):""}};function vRe({currentAvatar:t,onSelect:e,backendUrl:n}){const{t:r}=En(),[i,o]=T.useState("avataaars"),[l,u]=T.useState(()=>tRt(t)),[d,p]=T.useState(!1);T.useEffect(()=>{const _=tRt(t);u(_)},[t]);const[m,g]=T.useState(!1),f=T.useMemo(()=>C8r(n),[n]).filter(_=>_.style===i),b=T.useCallback(async()=>{g(!0),await new Promise(x=>setTimeout(x,300));const _=Math.random().toString(36).slice(2,10),w=lG(i,_,n);e(w),g(!1)},[i,e,n]),y=T.useCallback(async()=>{if(!l.trim())return;g(!0),await new Promise(w=>setTimeout(w,200));const _=lG(i,l.trim(),n);e(_),g(!1)},[i,l,e,n]),v=T.useCallback(async _=>{g(!0),await new Promise(w=>setTimeout(w,150)),e(_),g(!1)},[e]);return A.jsxs("div",{className:"flex gap-5",children:[A.jsx("div",{className:"flex shrink-0 items-start pt-6 px-2",children:A.jsxs(Ct.div,{className:"group relative",whileHover:{scale:1.05},transition:{type:"spring",stiffness:300},children:[A.jsx("div",{className:"absolute -inset-1 rounded-full bg-linear-to-tr from-indigo-500 via-purple-500 to-pink-500 opacity-40 blur-md transition-opacity duration-500 group-hover:opacity-70"}),A.jsx(Fr,{children:m&&A.jsx(Ct.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 z-10 flex items-center justify-center rounded-full bg-white/50 dark:bg-black/50",children:A.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-indigo-500 border-t-transparent"})})}),A.jsx("img",{src:t||lG("avataaars","default",n),alt:"Current avatar",className:"relative h-20 w-20 rounded-full border-[3px] border-white bg-white shadow-xl dark:border-neutral-700 dark:bg-neutral-800"}),t&&!m&&A.jsx(Ct.div,{initial:{scale:0},animate:{scale:1},className:"absolute -bottom-0.5 -right-0.5 flex h-6 w-6 items-center justify-center rounded-full border-2 border-white bg-green-500 shadow dark:border-neutral-800",children:A.jsx(Vs,{className:"h-3 w-3 text-white"})})]})}),A.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[A.jsxs("div",{className:"space-y-1.5",children:[A.jsx("label",{className:"pl-0.5 text-[13px] font-medium text-neutral-600 dark:text-neutral-400",children:r("agents.sessionSettings.avatar.style")}),A.jsx("div",{className:"custom-scrollbar -mx-1 flex max-h-16 flex-wrap gap-1.5 overflow-y-auto p-1",children:eRt.map(_=>A.jsx(Vi,{type:"button",variant:i===_?"default":"outline",size:"sm",className:Yt("h-7 rounded-full px-2.5 text-xs transition-all duration-300",i===_?"border-transparent bg-indigo-600 text-white shadow-md shadow-indigo-500/25 hover:bg-indigo-700":"border-neutral-200 text-neutral-600 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-400 dark:hover:bg-neutral-800"),onClick:()=>o(_),children:_},_))})]}),A.jsx("div",{className:"grid grid-cols-8 gap-2",children:f.map((_,w)=>A.jsx(Ct.button,{type:"button",whileHover:{scale:1.12},whileTap:{scale:.95},onClick:()=>v(_.url),className:Yt("aspect-square h-16 rounded-full overflow-hidden border-2 transition-colors duration-200 shadow-sm hover:shadow-lg",t===_.url?"border-indigo-500 ring-2 ring-indigo-200 dark:ring-indigo-900 shadow-indigo-500/30":"border-transparent hover:border-neutral-300 dark:hover:border-neutral-600 bg-neutral-50 dark:bg-neutral-800"),children:A.jsx("img",{src:_.url,alt:`Avatar option ${w+1}`,className:"h-full w-full object-cover"})},w))}),A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsxs(k8r,{type:"button",variant:"outline",onClick:b,disabled:m,className:"h-8 shrink-0 gap-1.5 px-3 text-xs font-medium",children:[A.jsx(xo,{className:"h-3.5 w-3.5 text-indigo-500"}),A.jsx("span",{className:"truncate",children:r(m?"agents.sessionSettings.avatar.loading":"agents.sessionSettings.avatar.random")}),A.jsx(E8r,{})]}),A.jsxs("button",{type:"button",onClick:()=>p(_=>!_),className:"flex items-center gap-1 rounded px-1.5 py-1 text-xs text-neutral-400 transition-colors hover:text-neutral-600 dark:hover:text-neutral-300",children:[r("agents.sessionSettings.avatar.advanced"),A.jsx(Tx,{className:Yt("h-3 w-3 transition-transform duration-200",d&&"rotate-180")})]})]}),A.jsx(Fr,{children:d&&A.jsx(Ct.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:A.jsxs("div",{className:"flex gap-2 p-1",children:[A.jsx("div",{className:"flex-1",children:A.jsx(Qi,{type:"text",placeholder:r("agents.sessionSettings.avatar.seedPlaceholder"),value:l,onChange:_=>u(_.target.value),onKeyDown:_=>_.key==="Enter"&&y(),className:"text-xs",wrapperClassName:"h-8"})}),A.jsx(Vi,{type:"button",size:"sm",onClick:y,disabled:!l.trim()||m,className:"h-8 px-3 text-xs transition-all hover:shadow-md",children:r("agents.sessionSettings.avatar.apply")})]})})})]})]})}function nRt({isOpen:t,onClose:e,onCreated:n,parentId:r}){const{t:i}=En(),{createAgent:o,isCreatingAgent:l,backendUrl:u,agents:d}=Un(Ws(x=>({createAgent:x.createAgent,isCreatingAgent:x.isCreatingAgent,backendUrl:x.backendUrl,agents:x.agents}))),[p,m]=T.useState({name:"",description:"",prompt:""}),[g,h]=T.useState(""),[f,b]=T.useState(!1);T.useEffect(()=>{if(t&&!g){const x=Math.random().toString(36).slice(2,10);h(lG("avataaars",x,u))}},[t,g,u]);const y=x=>{const{name:k,value:C}=x.target;m(E=>({...E,[k]:C}))},v=async x=>{if(x.preventDefault(),!f){if(!p.name){alert(i("agents.errors.nameRequired"));return}if(d.some(k=>k.name===p.name)){alert(i("agents.errors.nameDuplicate"));return}b(!0);try{const k=await o({...p,avatar:g,parent_id:r??void 0,mcp_server_ids:[],user_id:"temp",mcp_servers:[],created_at:new Date().toISOString(),updated_at:new Date().toISOString()});w(),k&&n&&n(k)}catch(k){console.error("Failed to create agent:",k),alert(i("agents.errors.createFailed"))}finally{b(!1)}}},_=f||l||!p.name,w=()=>{m({name:"",description:"",prompt:""}),h(""),e()};return A.jsx(Hc,{isOpen:t,onClose:w,size:"md",children:A.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[A.jsx("div",{className:"shrink-0 px-5 pt-5 pb-1 md:pt-2",children:A.jsx("h2",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:i("agents.createTitle")})}),A.jsxs("form",{onSubmit:v,className:"flex-1 overflow-y-auto custom-scrollbar px-5 pb-5 space-y-5",children:[A.jsx(vRe,{currentAvatar:g,onSelect:h,backendUrl:u}),A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsx(hi,{label:i("agents.fields.name.required"),required:!0,children:A.jsx(Qi,{name:"name",value:p.name,onChange:y,placeholder:i("agents.fields.name.placeholder"),required:!0})}),A.jsx(hi,{label:i("agents.fields.description.label"),children:A.jsx(Qi,{name:"description",value:p.description,onChange:y,placeholder:i("agents.fields.description.placeholder")})}),A.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:[A.jsx(qc,{type:"button",onClick:w,className:"inline-flex items-center gap-2 rounded-md bg-neutral-100 py-2 px-4 text-sm font-medium text-neutral-700 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-200 dark:hover:bg-neutral-700 transition-colors",children:i("agents.actions.cancel")}),A.jsx(qc,{type:"submit",disabled:_,className:Yt("inline-flex items-center gap-2 rounded-md py-2 px-4 text-sm font-medium transition-colors",_?"bg-neutral-400 text-white cursor-not-allowed":"bg-indigo-600 text-white hover:bg-indigo-500"),children:i(f||l?"agents.actions.creating":"agents.actions.create")})]})]})]})})}class S8r{listSecrets(){return nn.get("/xyzen/api/v1/payment-secrets")}createSecret(e){return nn.post("/xyzen/api/v1/payment-secrets",e)}updateSecret(e,n){return nn.put(`/xyzen/api/v1/payment-secrets/${e}`,n)}deleteSecret(e){return nn.delete(`/xyzen/api/v1/payment-secrets/${e}`)}getBinding(e){return nn.get(`/xyzen/api/v1/agents/${e}/payment-binding`)}upsertBinding(e,n){return nn.put(`/xyzen/api/v1/agents/${e}/payment-binding`,n)}deleteBinding(e){return nn.delete(`/xyzen/api/v1/agents/${e}/payment-binding`)}}const ck=new S8r;class I8r{async createKnowledgeSet(e){return nn.post("/xyzen/api/v1/knowledge-sets/",e)}async listKnowledgeSets(e=!1){return nn.get("/xyzen/api/v1/knowledge-sets/",{params:{include_deleted:e||void 0}})}async getKnowledgeSet(e){return nn.get(`/xyzen/api/v1/knowledge-sets/${e}`)}async updateKnowledgeSet(e,n){return nn.patch(`/xyzen/api/v1/knowledge-sets/${e}`,n)}async deleteKnowledgeSet(e,n=!1){return nn.delete(`/xyzen/api/v1/knowledge-sets/${e}`,void 0,{params:{hard_delete:n}})}async linkFileToKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/${n}`)}async unlinkFileFromKnowledgeSet(e,n){return nn.delete(`/xyzen/api/v1/knowledge-sets/${e}/files/${n}`)}async getFilesInKnowledgeSet(e){return nn.get(`/xyzen/api/v1/knowledge-sets/${e}/files`)}async bulkLinkFilesToKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/bulk-link`,{file_ids:n})}async bulkUnlinkFilesFromKnowledgeSet(e,n){return nn.post(`/xyzen/api/v1/knowledge-sets/${e}/files/bulk-unlink`,{file_ids:n})}}const Rh=new I8r;class T8r{async listSkills(){return nn.get("/xyzen/api/v1/skills/")}async listAgentSkills(e){return nn.get(`/xyzen/api/v1/agents/${e}/skills`)}async attachSkill(e,n){const r={skill_id:n};return nn.post(`/xyzen/api/v1/agents/${e}/skills`,r)}async detachSkill(e,n){return nn.delete(`/xyzen/api/v1/agents/${e}/skills/${n}`)}async parseSkill(e){return nn.post("/xyzen/api/v1/skills/parse",e)}async createSkill(e){return nn.post("/xyzen/api/v1/skills/",e)}async listSkillResources(e){return nn.get(`/xyzen/api/v1/skills/${e}/resources`)}async updateSkill(e,n){return nn.patch(`/xyzen/api/v1/skills/${e}`,n)}async deleteSkill(e){return nn.delete(`/xyzen/api/v1/skills/${e}`)}}const Lh=new T8r,rRt=["official","builtin:"];function aRt({open:t,onOpenChange:e,agentId:n,graphConfig:r,mcpServers:i=[],knowledgeSetId:o,tags:l,isPublished:u=!1,readme:d,onPublishSuccess:p}){const{t:m}=En(),[g,h]=T.useState(""),[f,b]=T.useState(d||""),[y,v]=T.useState(!0),[_,w]=T.useState("editable"),[x,k]=T.useState(l??[]),[C,E]=T.useState(""),[S,I]=T.useState([]),[B,N]=T.useState(o??null),[L,M]=T.useState([]),[R,D]=T.useState(new Set),[P,O]=T.useState(new Set),[F,$]=T.useState(""),[j,Q]=T.useState(null),z=Nir(),U=k2e(t),H=m("marketplace.realPerson.publishAgent");T.useEffect(()=>{if(t){const Z=(l??[]).filter(ne=>!rRt.some(ce=>ne===ce||ne.startsWith(ce)));k(Z)}},[t,l]);const te=T.useCallback(Z=>{const ne=Z.trim().toLowerCase();if(!ne||x.includes(ne)){E("");return}if(rRt.some(ce=>ne===ce||ne.startsWith(ce))){E("");return}k(ce=>[...ce,ne]),E("")},[x]),K=T.useCallback(Z=>{k(ne=>ne.filter(ce=>ce!==Z))},[]),ae=T.useCallback(Z=>{Z.key==="Enter"||Z.key===","?(Z.preventDefault(),te(C)):Z.key==="Backspace"&&!C&&x.length>0&&k(ne=>ne.slice(0,-1))},[te,C,x.length]);T.useEffect(()=>{if(!t)return;let Z=!1;$("");async function ne(){try{const[ce,oe,ue,me]=await Promise.all([Rh.listKnowledgeSets(),Lh.listAgentSkills(n),Lh.listSkills(),ck.getBinding(n)]);if(Z)return;I(ce),M(ue),Q(me);const fe=new Set(oe.map(Be=>Be.id));D(fe),O(new Set(fe)),N(o??null)}catch(ce){console.error("Failed to fetch publish modal data:",ce)}}return ne(),()=>{Z=!0}},[t,n,o]);const se=async(Z=!1)=>{if(g.trim()&&!(!Z&&!await U.ensureVerified()))try{const ne=await z.mutateAsync({agent_id:n,commit_message:g.trim(),is_published:y,readme:f.trim()||null,fork_mode:_,knowledge_set_id:B||null,skill_ids:P.size>0?Array.from(P):void 0,tags:x});p&&p(ne.marketplace_id),h(""),e(!1)}catch(ne){if(U.handleRequiredError(ne))return;console.error("Failed to publish agent:",ne)}},X=Z=>{O(ne=>{const ce=new Set(ne);return ce.has(Z)?ce.delete(Z):ce.add(Z),ce})},W=T.useMemo(()=>{const Z=F.trim().toLowerCase();if(!Z)return L;const ne=ue=>ue.name.toLowerCase().includes(Z)||ue.description?.toLowerCase().includes(Z)||ue.tags?.some(me=>me.toLowerCase().includes(Z)),ce=[],oe=[];for(const ue of L){if(P.has(ue.id)){ce.push(ue);continue}ne(ue)&&oe.push(ue)}return[...ce,...oe]},[L,P,F]),q=!!r&&Object.keys(r).length>0,Y=g.trim().length>0&&q;return A.jsxs(A.Fragment,{children:[A.jsxs(Hc,{isOpen:t,onClose:()=>e(!1),size:"xl",children:[A.jsxs("div",{className:"shrink-0 border-b border-neutral-200/60 px-5 pb-3 pt-5 dark:border-neutral-800/60",children:[A.jsx("h2",{className:"text-lg font-semibold text-neutral-900 dark:text-white",children:m(u?"marketplace.publish.titleUpdate":"marketplace.publish.title")}),A.jsx("p",{className:"mt-1 text-[13px] text-neutral-500 dark:text-neutral-400",children:m(u?"marketplace.publish.descriptionUpdate":"marketplace.publish.description")})]}),A.jsx("div",{className:"custom-scrollbar flex-1 overflow-y-auto",children:A.jsxs("div",{className:"space-y-6 px-5 py-5",children:[A.jsx(O2e,{status:U.statusQuery.data,isLoading:U.statusQuery.isLoading,actionLabel:H,onVerify:()=>U.setVerificationOpen(!0)}),(()=>{const Z=A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx(pu,{className:"h-4 w-4 shrink-0 text-neutral-400"}),A.jsxs("p",{className:"text-[13px] text-neutral-600 dark:text-neutral-400",children:[A.jsx("strong",{children:m("marketplace.publish.info.title")})," ",m("marketplace.publish.info.content")," ",A.jsx("strong",{children:m("marketplace.publish.info.note")})," ",m("marketplace.publish.info.noteContent")]})]}),ne=A.jsx(hi,{label:m("marketplace.publish.commitMessage.label"),required:!0,hint:m("marketplace.publish.commitMessage.charCount",{count:g.length}),children:A.jsx(Ih,{id:"commit-message",placeholder:m("marketplace.publish.commitMessage.placeholder"),value:g,onChange:rt=>h(rt.target.value),rows:3})}),ce=A.jsx(hi,{label:m("marketplace.publish.readme.label"),hint:m("marketplace.publish.readme.hint"),children:A.jsx(Ih,{id:"readme-editor",placeholder:m("marketplace.publish.readme.placeholder"),value:f,onChange:rt=>b(rt.target.value),rows:6,className:"font-mono"})}),oe=A.jsx(hi,{label:m("marketplace.publish.tags.label"),hint:m("marketplace.publish.tags.hint"),children:A.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 rounded-sm border border-neutral-200 bg-white px-2.5 py-2 transition-colors focus-within:border-indigo-400 focus-within:ring-2 focus-within:ring-indigo-500/20 dark:border-neutral-700 dark:bg-neutral-800",children:[x.map(rt=>A.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-indigo-50/80 px-2.5 py-0.5 text-xs font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",children:[rt,A.jsx("button",{type:"button",onClick:()=>K(rt),className:"ml-0.5 rounded-full p-0.5 transition-colors hover:bg-indigo-200/60 dark:hover:bg-indigo-800/40",children:A.jsx(Pl,{className:"h-3 w-3"})})]},rt)),A.jsx("input",{type:"text",value:C,onChange:rt=>E(rt.target.value),onKeyDown:ae,onBlur:()=>C.trim()&&te(C),placeholder:x.length===0?m("marketplace.publish.tags.placeholder"):"",className:"min-w-[80px] flex-1 border-none bg-transparent py-0.5 text-[13px] text-neutral-700 outline-none placeholder:text-neutral-400 dark:text-neutral-300 dark:placeholder:text-neutral-500"})]})}),ue=A.jsx(hi,{label:m("marketplace.publish.knowledgeBase.label"),hint:m("marketplace.publish.knowledgeBase.hint"),children:A.jsxs("select",{value:B??"",onChange:rt=>N(rt.target.value||null),className:"w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-[13px] text-neutral-700 transition-colors focus:border-indigo-400 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-300",children:[A.jsx("option",{value:"",children:m("marketplace.publish.knowledgeBase.none")}),S.map(rt=>A.jsxs("option",{value:rt.id,children:[rt.name," (",m("marketplace.publish.knowledgeBase.fileCount",{count:rt.file_count}),")"]},rt.id))]})}),me=A.jsx(hi,{label:m("marketplace.publish.skills.label"),hint:m("marketplace.publish.skills.hint"),children:L.length===0?A.jsx("p",{className:"text-xs text-neutral-400 dark:text-neutral-500",children:m("marketplace.publish.skills.empty")}):A.jsxs("div",{className:"space-y-1.5",children:[A.jsx(Qi,{value:F,onChange:rt=>$(rt.target.value),placeholder:m("marketplace.publish.skills.searchPlaceholder")}),W.length===0?A.jsx("p",{className:"rounded-lg bg-neutral-100/60 px-3 py-2.5 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:m("marketplace.publish.skills.noResults")}):W.map(rt=>A.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-lg bg-neutral-100/60 px-3 py-2.5 transition-colors hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]",children:[A.jsx("input",{type:"checkbox",checked:P.has(rt.id),onChange:()=>X(rt.id),className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"}),A.jsxs("div",{className:"min-w-0 flex-1",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:rt.name}),rt.scope==="builtin"&&A.jsx("span",{className:"rounded bg-indigo-50/80 px-1.5 py-0.5 text-[10px] font-medium text-indigo-600 dark:bg-indigo-900/30 dark:text-indigo-400",children:m("marketplace.publish.skills.builtin")}),R.has(rt.id)&&A.jsx("span",{className:"rounded bg-green-50/80 px-1.5 py-0.5 text-[10px] font-medium text-green-600 dark:bg-green-900/30 dark:text-green-400",children:m("marketplace.publish.skills.attached")})]}),rt.description&&A.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-neutral-500 dark:text-neutral-400",children:rt.description})]})]},rt.id))]})}),fe=A.jsx(hi,{label:m("marketplace.publish.mcpServers.label"),hint:m("marketplace.publish.mcpServers.hint"),children:i.length===0?A.jsx("p",{className:"text-xs text-neutral-400 dark:text-neutral-500",children:m("marketplace.publish.mcpServers.empty")}):A.jsx("div",{className:"space-y-1.5",children:i.map(rt=>A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-3 py-2.5 dark:bg-white/[0.04]",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:rt.name}),rt.description&&A.jsx("p",{className:"mt-0.5 text-xs text-neutral-500 dark:text-neutral-400 line-clamp-1",children:rt.description})]},rt.id))})}),Be=j?A.jsx(hi,{label:m("agents.payment.publishSummaryTitle"),hint:m("agents.payment.publishSummaryHint"),children:A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:j.provider.toUpperCase()}),A.jsx("span",{className:"rounded-full bg-green-50/80 px-2 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:j.enabled?m("agents.payment.enabled"):m("agents.payment.disabled")}),A.jsx("span",{className:"rounded-full bg-indigo-50/80 px-2 py-0.5 text-[10px] font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",children:j.required?m("agents.payment.required"):m("agents.payment.optional")}),A.jsx("span",{className:"rounded-full bg-neutral-200/80 px-2 py-0.5 text-[10px] font-medium text-neutral-700 dark:bg-white/[0.08] dark:text-neutral-300",children:j.status})]}),A.jsx("p",{className:"mt-2 text-xs text-neutral-500 dark:text-neutral-400",children:j.secret?.app_id_masked??m("agents.payment.unconfigured")}),A.jsx("p",{className:"mt-2 text-xs text-neutral-500 dark:text-neutral-400",children:j.tool_names.join(", ")})]})}):null,He=A.jsxs(od,{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3.5 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"space-y-0.5 pr-4",children:[A.jsx(Gc,{htmlFor:"publish-toggle",className:"cursor-pointer text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.publish.publishImmediately.label")}),A.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.publish.publishImmediately.description")})]}),A.jsx(l2e,{id:"publish-toggle",checked:y,onChange:v,className:`${y?"bg-indigo-500":"bg-neutral-300 dark:bg-neutral-600"} relative inline-flex h-[26px] w-[46px] shrink-0 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-indigo-500/40 focus:ring-offset-2`,children:A.jsx("span",{className:`${y?"translate-x-[22px]":"translate-x-[3px]"} inline-block h-5 w-5 transform rounded-full bg-white shadow-sm transition-transform`})})]}),Le=A.jsx(hi,{label:m("marketplace.publish.forkMode.label"),hint:m("marketplace.publish.forkMode.help"),children:A.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[A.jsxs("button",{type:"button",onClick:()=>w("editable"),className:`flex items-center gap-3 rounded-lg p-3 text-left transition-colors ${_==="editable"?"bg-green-50/80 ring-1 ring-green-500/30 dark:bg-green-900/15 dark:ring-green-500/20":"bg-neutral-100/60 hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]"}`,children:[A.jsx("div",{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${_==="editable"?"bg-green-500 text-white":"bg-neutral-200/70 text-neutral-500 dark:bg-neutral-700/70 dark:text-neutral-400"}`,children:A.jsx(M2e,{className:"h-4 w-4"})}),A.jsxs("div",{className:"flex-1 min-w-0",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.forkMode.editable")}),A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.forkMode.editableDescription")}),A.jsx("div",{className:"mt-1 text-[10px] font-medium text-green-600 dark:text-green-400",children:m("marketplace.forkMode.rewardRate",{rate:"30%"})})]})]}),A.jsxs("button",{type:"button",onClick:()=>w("locked"),className:`flex items-center gap-3 rounded-lg p-3 text-left transition-colors ${_==="locked"?"bg-amber-50/80 ring-1 ring-amber-500/30 dark:bg-amber-900/15 dark:ring-amber-500/20":"bg-neutral-100/60 hover:bg-neutral-100 dark:bg-white/[0.04] dark:hover:bg-white/[0.06]"}`,children:[A.jsx("div",{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg ${_==="locked"?"bg-amber-500 text-white":"bg-neutral-200/70 text-neutral-500 dark:bg-neutral-700/70 dark:text-neutral-400"}`,children:A.jsx(Yb,{className:"h-4 w-4"})}),A.jsxs("div",{className:"flex-1 min-w-0",children:[A.jsx("div",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:m("marketplace.forkMode.locked")}),A.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:m("marketplace.forkMode.lockedDescription")}),A.jsx("div",{className:"mt-1 text-[10px] font-medium text-amber-600 dark:text-amber-400",children:m("marketplace.forkMode.rewardRate",{rate:"3%"})})]})]})]})});return A.jsxs("div",{className:"space-y-6",children:[!q&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-red-50/80 px-4 py-3 dark:bg-red-950/30",children:[A.jsx(Fp,{className:"h-4 w-4 shrink-0 text-red-500 dark:text-red-400"}),A.jsx("p",{className:"text-[13px] text-red-700 dark:text-red-400",children:m("marketplace.publish.validation.noConfig")})]}),A.jsxs("div",{className:"space-y-6 md:hidden",children:[Z,ne,ce,oe,ue,me,fe,Be,He,OA("developerReward")&&Le]}),A.jsxs("div",{className:"hidden md:grid md:grid-cols-[55%_45%]",children:[A.jsxs("div",{className:"space-y-6 pr-5 border-r border-neutral-200/60 dark:border-neutral-800/60",children:[Z,ne,ce,oe]}),A.jsxs("div",{className:"space-y-6 pl-5",children:[ue,me,fe,Be,He,OA("developerReward")&&Le]})]}),z.isSuccess&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-green-50/80 px-4 py-3 dark:bg-green-950/30",children:[A.jsx(_l,{className:"h-4 w-4 shrink-0 text-green-500"}),A.jsx("p",{className:"text-[13px] text-green-700 dark:text-green-400",children:m(u?"marketplace.publish.success.updated":"marketplace.publish.success.published")})]}),z.isError&&A.jsxs("div",{className:"flex gap-2.5 rounded-lg bg-red-50/80 px-4 py-3 dark:bg-red-950/30",children:[A.jsx(Fp,{className:"h-4 w-4 shrink-0 text-red-500 dark:text-red-400"}),A.jsx("p",{className:"text-[13px] text-red-700 dark:text-red-400",children:z.error instanceof Error?z.error.message:m("marketplace.publish.error.default")})]})]})})()]})}),A.jsx("div",{className:"shrink-0 border-t border-neutral-200/60 px-5 py-4 dark:border-neutral-800/60",children:A.jsxs("div",{className:"flex justify-end gap-2.5",children:[A.jsx(qc,{onClick:()=>{h(""),e(!1)},disabled:z.isPending,className:"rounded-lg bg-neutral-100/80 px-4 py-2 text-[13px] font-medium text-neutral-700 transition-colors hover:bg-neutral-200/80 disabled:opacity-50 dark:bg-white/[0.06] dark:text-neutral-300 dark:hover:bg-white/[0.1]",children:m("marketplace.publish.actions.cancel")}),A.jsx(qc,{onClick:()=>{se()},disabled:!Y||z.isPending,className:"rounded-lg bg-indigo-500 px-4 py-2 text-[13px] font-semibold text-white transition-colors hover:bg-indigo-600 disabled:opacity-50 dark:bg-indigo-500 dark:hover:bg-indigo-400",children:z.isPending?m("marketplace.publish.actions.publishing"):m(u?"marketplace.publish.actions.update":y?"marketplace.publish.actions.publish":"marketplace.publish.actions.saveAsDraft")})]})})]}),A.jsx(Gae,{open:U.verificationOpen,onOpenChange:U.setVerificationOpen,actionLabel:H,onStatusChange:()=>{U.statusQuery.refetch()},onVerified:()=>{U.statusQuery.refetch(),se(!0)}})]})}const B8r=["create-alipay-payment-agent","query-alipay-payment","refund-alipay-payment","query-alipay-refund"],D8r=T.lazy(()=>Promise.resolve().then(()=>_Ea)),N8r=[{id:"profile",icon:P2e,labelKey:"profile"},{id:"automation",icon:xo,labelKey:"automation"},{id:"size",icon:dU,labelKey:"size"},{id:"workflow",icon:gh,labelKey:"workflow"},{id:"danger",icon:Fp,labelKey:"danger",color:"text-red-500"}];function R8r({currentW:t=1,currentH:e=1,onResize:n}){const[r,i]=T.useState(null);return A.jsxs("div",{className:"flex flex-col gap-6",children:[A.jsx("div",{className:"flex justify-center",children:A.jsx("div",{className:"grid grid-cols-3 gap-3",onMouseLeave:()=>i(null),children:Array.from({length:9}).map((o,l)=>{const u=l%3+1,d=Math.floor(l/3)+1,p=r&&u<=r.w&&d<=r.h,m=!r&&u<=t&&d<=e;return A.jsx(Ct.div,{whileHover:{scale:1.05},whileTap:{scale:.95},className:Yt("h-14 w-14 cursor-pointer rounded-sm border-2 transition-colors duration-200 shadow-sm",p||m?"border-indigo-500 bg-indigo-500/20 dark:border-indigo-400 dark:bg-indigo-400/20 shadow-indigo-500/30 shadow-lg":"border-neutral-200 bg-white hover:border-neutral-300 dark:border-neutral-700 dark:bg-neutral-800 dark:hover:border-neutral-600"),onMouseEnter:()=>i({w:u,h:d}),onClick:g=>{g.preventDefault(),g.stopPropagation(),n(u,d)}},l)})})}),A.jsx("div",{className:"text-center",children:A.jsx(Ct.span,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"inline-block px-5 py-2 rounded-full bg-neutral-100 dark:bg-neutral-800 text-base font-bold text-neutral-700 dark:text-neutral-200 shadow-sm border border-neutral-200 dark:border-neutral-700",children:r?`${r.w} × ${r.h}`:`${t} × ${e}`},r?`${r.w}x${r.h}`:`${t}x${e}`)})]})}function L8r({agent:t,currentAvatar:e,onAvatarChange:n,onClose:r}){const{t:i}=En(),o=Un(L=>L.backendUrl),{updateAgent:l,agents:u,openSettingsModal:d}=Un(Ws(L=>({updateAgent:L.updateAgent,agents:L.agents,openSettingsModal:L.openSettingsModal}))),p=t.original_source_id!=null,[m,g]=T.useState(t),[h,f]=T.useState(!1),[b,y]=T.useState(null),[v,_]=T.useState([]),[w,x]=T.useState(""),[k,C]=T.useState(!1),[E,S]=T.useState(!1);T.useEffect(()=>{g(t)},[t]),T.useEffect(()=>{let L=!1;async function M(){try{const[R,D]=await Promise.all([ck.getBinding(t.id),ck.listSecrets()]);if(L)return;y(R),_(D),x(R?.secret?.id??""),C(R?.enabled??!1),S(R?.required??!1)}catch(R){console.error("Failed to load agent payment binding:",R)}}return M(),()=>{L=!0}},[t.id]);const I=L=>{const{name:M,value:R}=L.target;g({...m,[M]:R})},B=async L=>{if(L.preventDefault(),!h){if(m.name!==t.name&&u.some(M=>M.id!==m.id&&M.name===m.name)){alert(i("agents.errors.nameDuplicate"));return}f(!0);try{if(await l({id:m.id,name:m.name,description:m.description}),!p&&b!=null&&!k&&!w)await ck.deleteBinding(m.id),y(null),x(""),C(!1),S(!1);else{if(!(!p&&(b!=null||k))){Nr.success(i("agents.payment.saveSuccess")),r();return}if(!w){Nr.error(i("agents.payment.noSecretsHint"));return}const D=await ck.upsertBinding(m.id,{enabled:k,required:k&&E,secret_id:w,tool_names:[...B8r]});y(D)}Nr.success(i("agents.payment.saveSuccess")),r()}catch(M){console.error("Failed to update agent:",M),Nr.error(M instanceof Error?M.message:i("agents.errors.updateFailed"))}finally{f(!1)}}},N=async()=>{if(b){f(!0);try{await ck.deleteBinding(m.id),y(null),x(""),C(!1),S(!1),Nr.success(i("agents.payment.deleteSuccess"))}catch(L){console.error("Failed to delete payment binding:",L),Nr.error(L instanceof Error?L.message:i("agents.payment.deleteFailed"))}finally{f(!1)}}};return A.jsxs("form",{onSubmit:B,className:"space-y-6 px-4",children:[A.jsx(vRe,{currentAvatar:e,onSelect:n,backendUrl:o}),A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.fields.name.label")}),A.jsx(Qi,{name:"name",value:m.name,onChange:I,placeholder:i("agents.fields.name.placeholder"),required:!0})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.fields.description.label")}),A.jsx(Qi,{name:"description",value:m.description,onChange:I,placeholder:i("agents.fields.description.placeholder")})]})]}),!p&&A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"border-t border-neutral-200 dark:border-neutral-700"}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-4 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[A.jsxs("div",{children:[A.jsx("p",{className:"text-[13px] font-medium text-neutral-900 dark:text-neutral-100",children:i("agents.payment.title")}),A.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:i("agents.payment.description")})]}),A.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A.jsx("span",{className:"rounded-full bg-neutral-200/80 px-2 py-0.5 text-[10px] font-medium text-neutral-700 dark:bg-white/[0.08] dark:text-neutral-300",children:b?.status??i("agents.payment.unconfigured")}),b?.required&&A.jsx("span",{className:"rounded-full bg-indigo-50/80 px-2 py-0.5 text-[10px] font-medium text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-300",children:i("agents.payment.required")})]})]}),b?.last_error&&A.jsx("p",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:b.last_error})]}),A.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[A.jsxs("label",{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx("span",{className:"text-[13px] font-medium text-neutral-800 dark:text-neutral-200",children:i("agents.payment.enabled")}),A.jsx("input",{type:"checkbox",checked:k,onChange:L=>{const M=L.target.checked;C(M),M||S(!1)},className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"})]}),A.jsxs("label",{className:"flex items-center justify-between rounded-lg bg-neutral-100/60 px-4 py-3 dark:bg-white/[0.04]",children:[A.jsx("span",{className:Yt("text-[13px] font-medium",k?"text-neutral-800 dark:text-neutral-200":"text-neutral-400 dark:text-neutral-500"),children:i("agents.payment.required")}),A.jsx("input",{type:"checkbox",checked:E,disabled:!k,onChange:L=>S(L.target.checked),className:"h-4 w-4 rounded border-neutral-300 text-indigo-500 focus:ring-indigo-500/40 dark:border-neutral-600"})]})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:i("agents.payment.secret")}),A.jsxs("select",{value:w,onChange:L=>x(L.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-[13px] text-neutral-900 focus:border-indigo-400 focus:outline-none focus:ring-2 focus:ring-indigo-400/20 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-100",children:[A.jsx("option",{value:"",children:i("agents.payment.secretPlaceholder")}),v.map(L=>A.jsx("option",{value:L.id,children:L.app_id_masked},L.id))]})]}),w&&A.jsx("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:v.find(L=>L.id===w)?.gateway}),k&&v.length===0&&A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-3 text-xs text-neutral-500 dark:bg-white/[0.04] dark:text-neutral-400",children:[A.jsx("p",{children:i("agents.payment.noSecretsHint")}),A.jsx("button",{type:"button",onClick:()=>d("payment"),className:"mt-2 text-xs font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-400",children:i("agents.payment.manageSecrets")})]}),b&&A.jsx("div",{className:"flex justify-end",children:A.jsx("button",{type:"button",onClick:()=>{N()},className:"rounded-lg bg-red-50/80 px-3 py-2 text-xs font-medium text-red-700 transition-colors hover:bg-red-100 dark:bg-red-950/30 dark:text-red-400 dark:hover:bg-red-950/50",children:i("agents.payment.delete")})})]})]}),A.jsx("div",{className:"flex justify-end gap-3 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:A.jsx(qc,{type:"submit",disabled:h,className:`inline-flex items-center gap-2 rounded-md py-2 px-4 text-sm font-medium transition-colors ${h?"bg-indigo-400 text-white cursor-not-allowed":"bg-indigo-600 text-white hover:bg-indigo-500"}`,children:i(h?"agents.actions.saving":"agents.actions.save")})})]})}const _Re="09:00",M8r=[{value:"0",label:"Sunday"},{value:"1",label:"Monday"},{value:"2",label:"Tuesday"},{value:"3",label:"Wednesday"},{value:"4",label:"Thursday"},{value:"5",label:"Friday"},{value:"6",label:"Saturday"}];function iRt(){return typeof Intl>"u"?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}function P8r(t){if(!t)return{mode:"daily",time:_Re,dayOfWeek:"1",cronExpression:"0 9 * * *"};const e=t.trim().split(/\s+/);if(e.length===5){const[n,r,i,o,l]=e;if(/^\d+$/.test(n)&&/^\d+$/.test(r)&&i==="*"&&o==="*"&&l==="*")return{mode:"daily",time:`${r.padStart(2,"0")}:${n.padStart(2,"0")}`,dayOfWeek:"1",cronExpression:t};if(/^\d+$/.test(n)&&/^\d+$/.test(r)&&i==="*"&&o==="*"&&/^\d+$/.test(l))return{mode:"weekly",time:`${r.padStart(2,"0")}:${n.padStart(2,"0")}`,dayOfWeek:l,cronExpression:t}}return{mode:"cron",time:_Re,dayOfWeek:"1",cronExpression:t}}function O8r(t,e,n,r){if(t==="cron")return r.trim();const[i="9",o="0"]=e.split(":"),l=String(Number(o||"0")),u=String(Number(i||"9"));return t==="weekly"?`${l} ${u} * * ${n}`:`${l} ${u} * * *`}function sRt(t){if(!t)return null;const e=new Date(t);return Number.isNaN(e.getTime())?t:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(e)}function F8r(){const{t}=En(),{autoExplore:e,autoExploreLoading:n,fetchAutoExplore:r,saveAutoExplore:i,toggleAutoExplore:o}=Un(Ws(E=>({autoExplore:E.autoExplore,autoExploreLoading:E.autoExploreLoading,fetchAutoExplore:E.fetchAutoExplore,saveAutoExplore:E.saveAutoExplore,toggleAutoExplore:E.toggleAutoExplore}))),[l,u]=T.useState("daily"),[d,p]=T.useState(_Re),[m,g]=T.useState("1"),[h,f]=T.useState("0 9 * * *"),[b,y]=T.useState(iRt()),[v,_]=T.useState("auto");T.useEffect(()=>{if(!e){r().catch(()=>{});return}const E=P8r(e.cron_expression);u(E.mode),p(E.time),g(E.dayOfWeek),f(E.cronExpression),y(e.timezone||iRt()),_(e.language||"auto")},[e,r]);const w=async()=>{const E=O8r(l,d,m,h);try{await i({cronExpression:E,timezone:b,language:v}),Nr.success(t("agents.rootAgent.autoExploreUpdated"))}catch(S){console.error("Failed to save auto-explore:",S),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},x=async()=>{try{await o(!1),Nr.success(t("agents.rootAgent.autoExploreDisabled"))}catch(E){console.error("Failed to disable auto-explore:",E),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},k=sRt(e?.next_run_at||null),C=sRt(e?.last_run_at||null);return A.jsxs("div",{className:"space-y-6 px-4",children:[A.jsxs("div",{className:"rounded-lg bg-neutral-100/60 px-4 py-4 dark:bg-white/[0.04]",children:[A.jsxs("div",{className:"flex items-center justify-between gap-3",children:[A.jsxs("div",{children:[A.jsx("p",{className:"text-[13px] font-medium text-neutral-800 dark:text-neutral-200",children:t("agents.rootAgent.autoExploreSchedule")}),A.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:t("agents.rootAgent.autoExploreScheduleHint")})]}),A.jsx("span",{className:Yt("rounded-sm px-2 py-1 text-xs font-medium",e?.enabled?"bg-amber-500/10 text-amber-700 dark:text-amber-300":"bg-neutral-200/80 text-neutral-600 dark:bg-white/[0.06] dark:text-neutral-400"),children:e?.enabled?t("agents.rootAgent.autoExploreEnabledState"):t("agents.rootAgent.autoExploreDisabledState")})]}),A.jsxs("div",{className:"mt-3 space-y-1 text-xs text-neutral-500 dark:text-neutral-400",children:[A.jsxs("p",{children:[t("agents.rootAgent.autoExploreTimezone"),": ",b]}),k&&A.jsxs("p",{children:[t("agents.rootAgent.autoExploreNextRun"),": ",k]}),C&&A.jsxs("p",{children:[t("agents.rootAgent.autoExploreLastRun"),": ",C]}),e?.last_error&&A.jsxs("p",{className:"text-red-600 dark:text-red-400",children:[t("agents.rootAgent.autoExploreLastError"),":"," ",e.last_error]})]})]}),A.jsxs("div",{className:"space-y-4",children:[A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreCadence")}),A.jsx("div",{className:"mt-2 grid grid-cols-3 gap-2",children:["daily","weekly","cron"].map(E=>A.jsx("button",{type:"button",onClick:()=>u(E),className:Yt("rounded-lg px-3 py-2 text-sm transition-colors",l===E?"bg-indigo-500 text-white":"bg-neutral-100 text-neutral-700 hover:bg-neutral-200 dark:bg-white/[0.04] dark:text-neutral-300 dark:hover:bg-white/[0.08]"),children:t(`agents.rootAgent.autoExploreCadence${E[0].toUpperCase()}${E.slice(1)}`)},E))})]}),l!=="cron"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreTime")}),A.jsx(Qi,{type:"time",value:d,onChange:E=>p(E.target.value)})]}),l==="weekly"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreWeekday")}),A.jsx("select",{value:m,onChange:E=>g(E.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-700 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200",children:M8r.map(E=>A.jsx("option",{value:E.value,children:t(`agents.rootAgent.autoExploreWeekday${E.label}`)},E.value))})]}),l==="cron"&&A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreCron")}),A.jsx(Qi,{value:h,onChange:E=>f(E.target.value),placeholder:"0 9 * * *"})]}),A.jsxs(od,{children:[A.jsx(Gc,{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t("agents.rootAgent.autoExploreLanguage")}),A.jsxs("select",{value:v,onChange:E=>_(E.target.value),className:"mt-2 w-full rounded-sm border border-neutral-200 bg-white px-3 py-2 text-sm text-neutral-700 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200",children:[A.jsx("option",{value:"auto",children:t("agents.rootAgent.autoExploreLanguageAuto")}),A.jsx("option",{value:"zh",children:"中文"}),A.jsx("option",{value:"en",children:"English"}),A.jsx("option",{value:"ja",children:"日本語"})]})]})]}),A.jsxs("div",{className:"flex justify-end gap-3 border-t border-neutral-200 pt-4 dark:border-neutral-700",children:[e?.enabled&&A.jsx(Vi,{type:"button",variant:"outline",disabled:n,onClick:x,children:t("agents.rootAgent.autoExploreDisableAction")}),A.jsx(Vi,{type:"button",disabled:n,onClick:w,children:e?.enabled?t("agents.rootAgent.autoExploreUpdateAction"):t("agents.rootAgent.autoExploreEnableAction")})]})]})}const wRe=({isOpen:t,onClose:e,agentName:n,agent:r,currentAvatar:i,currentGridSize:o,onAvatarChange:l,onGridSizeChange:u,onDelete:d})=>{const{t:p}=En(),m=Un(P=>P.backendUrl),g=Un(P=>P.rootAgentId),h=!!r&&!!g&&r.id===g,[f,b]=T.useState("profile"),[y,v]=T.useState(null),[_,w]=T.useState(!1),[x,k]=T.useState(!1),C=typeof window<"u"&&window.innerWidth<768,E=!!r,S=r?.config_visibility!=="hidden",I=r?.original_source_id!=null,B=T.useMemo(()=>N8r.filter(P=>!(P.id==="automation"&&!h||P.id==="workflow"&&(!E||!S)||P.id==="danger"&&!d)),[E,S,d]),N=P=>{C?v(P):b(P),w(!1)},L=()=>{v(null),w(!1)},M=P=>{switch(P){case"profile":return r?A.jsx(L8r,{agent:r,currentAvatar:i,onAvatarChange:l,onClose:e}):A.jsx(vRe,{currentAvatar:i,onSelect:l,backendUrl:m});case"automation":return A.jsx(F8r,{});case"size":return A.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-8",children:[A.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 mb-8 text-center max-w-64",children:p("agents.sessionSettings.size.description")}),A.jsx(R8r,{currentW:o?.w,currentH:o?.h,onResize:u})]});case"workflow":return r?A.jsx(T.Suspense,{children:A.jsx(D8r,{agent:r,onClose:e})}):null;case"danger":return A.jsx("div",{className:"flex flex-col items-center justify-center h-full py-8 space-y-6",children:_?A.jsxs(Ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"w-full max-w-sm rounded-2xl bg-red-50 dark:bg-red-900/10 p-6 space-y-4 border border-red-100 dark:border-red-900/20",children:[A.jsxs("div",{className:"text-center space-y-2",children:[A.jsx("h3",{className:"text-base font-semibold text-red-700 dark:text-red-300",children:p("agents.sessionSettings.danger.deleteConfirmTitle")}),A.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:p("agents.sessionSettings.danger.deleteConfirmMessage",{name:n})})]}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx(Vi,{variant:"outline",className:"flex-1 bg-white dark:bg-transparent border-red-200 dark:border-red-900/30 text-red-700 dark:text-red-300 hover:bg-red-100 dark:hover:bg-red-900/20",onClick:()=>w(!1),children:p("common.cancel")}),A.jsx(Vi,{variant:"destructive",className:"flex-1 shadow-lg shadow-red-500/20",onClick:()=>{d?.(),e()},children:p("common.delete")})]})]}):A.jsxs(A.Fragment,{children:[A.jsxs("div",{className:"text-center space-y-2",children:[A.jsx(Fp,{className:"w-12 h-12 mx-auto text-red-400"}),A.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 max-w-64",children:p("agents.sessionSettings.danger.description")})]}),d&&A.jsxs(Vi,{variant:"destructive",size:"lg",className:"h-11 px-6 gap-3 shadow-lg shadow-red-500/20",onClick:()=>w(!0),children:[A.jsx(wl,{className:"w-5 h-5"}),p("agents.sessionSettings.danger.deleteButton")]})]})});default:return null}},R=A.jsx("div",{className:"flex-1 min-w-0",children:A.jsx(Fr,{mode:"wait",children:y===null?A.jsx(Ct.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"space-y-2",children:B.map(P=>A.jsxs("button",{onClick:()=>N(P.id),className:Yt("w-full flex items-center gap-4 px-4 py-4 rounded-sm transition-all text-left","bg-neutral-50 dark:bg-neutral-800/50 hover:bg-neutral-100 dark:hover:bg-neutral-800",P.color),children:[A.jsx(P.icon,{className:"w-6 h-6 shrink-0"}),A.jsx("span",{className:"text-base font-medium",children:p(`agents.sessionSettings.tabs.${P.labelKey}`)})]},P.id))},"nav"):A.jsxs(Ct.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},children:[A.jsxs("button",{onClick:L,className:"flex items-center gap-2 text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 mb-4",children:[A.jsx(c_,{className:"w-4 h-4"}),p("settings.modal.back")]}),M(y)]},y)})}),D=A.jsxs(FP,{value:f,onValueChange:P=>{b(P),w(!1)},className:"flex flex-row gap-6",children:[A.jsx("div",{className:"w-44 shrink-0",children:A.jsx(QP,{className:"flex items-start flex-col w-full h-auto bg-neutral-50 dark:bg-neutral-900 rounded-sm p-1.5",children:B.map(P=>A.jsxs(Op,{value:P.id,className:Yt("w-44 justify-start gap-3 px-3 py-2.5 text-sm font-medium rounded-lg","data-[state=active]:bg-white data-[state=active]:shadow-sm dark:data-[state=active]:bg-neutral-800",P.id==="danger"&&"data-[state=active]:text-red-600 dark:data-[state=active]:text-red-400",P.color&&f!==P.id&&P.color),children:[A.jsx(P.icon,{className:"w-5 h-5 shrink-0"}),p(`agents.sessionSettings.tabs.${P.labelKey}`)]},P.id))})}),A.jsx("div",{className:"flex-1 min-w-0",children:A.jsx(lU,{children:B.map(P=>A.jsx(mh,{value:P.id,className:"h-full",children:M(P.id)},P.id))})})]});return A.jsxs(A.Fragment,{children:[A.jsx(Hc,{isOpen:t,onClose:e,size:"lg",children:A.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[A.jsx("div",{className:"shrink-0 px-5 pt-5 pb-1 md:pt-2",children:A.jsx("h2",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:p("agents.sessionSettings.title",{name:n})})}),A.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar px-5 pb-5",children:[A.jsxs("div",{className:"py-2",children:[A.jsx("div",{className:"md:hidden",children:R}),A.jsx("div",{className:"hidden md:block",children:D})]}),r&&!I&&!h&&A.jsx("div",{className:"mt-4 pt-4 border-t border-neutral-200 dark:border-neutral-700",children:A.jsxs(Vi,{type:"button",variant:"outline",onClick:()=>k(!0),disabled:!r.graph_config,className:"w-full gap-2 h-10 text-purple-700 border-purple-200 hover:bg-purple-50 dark:text-purple-300 dark:border-purple-800 dark:hover:bg-purple-900/20",title:r.graph_config?p("agents.actions.publish"):p("agents.actions.publishTooltip"),children:[A.jsx(xo,{className:"h-4 w-4"}),p("agents.actions.publish")]})})]})]})}),r&&!I&&!h&&A.jsx(aRt,{open:x,onOpenChange:k,agentId:r.id,agentName:r.name,agentDescription:r.description,graphConfig:r.graph_config,mcpServers:r.mcp_servers?.map(P=>({id:P.id,name:P.name,description:P.description||void 0})),knowledgeSetId:r.knowledge_set_id,tags:r.tags,onPublishSuccess:P=>{console.log("Agent published to marketplace:",P),k(!1)}})]})};function Q8r({isOpen:t,onClose:e,onConfirm:n,title:r,message:i,confirmLabel:o="Confirm",cancelLabel:l="Cancel",destructive:u=!0,className:d}){return A.jsx(BNe,{open:t,onOpenChange:p=>!p&&e(),children:A.jsxs(DNe,{className:Yt("space-y-4 border border-neutral-200/20 bg-white/95 shadow-2xl shadow-black/20 backdrop-blur-xl dark:border-neutral-700/30 dark:bg-neutral-900/95 dark:shadow-black/40","p-6 sm:p-6 rounded-sm",d),children:[A.jsx(NNe,{children:A.jsx(LNe,{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:r})}),A.jsxs("div",{className:"custom-scrollbar flex max-h-[60vh] items-start gap-4 overflow-y-auto",children:[A.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/30",children:A.jsx(Fp,{className:"h-6 w-6 text-red-600 dark:text-red-400","aria-hidden":"true"})}),A.jsx(MNe,{className:"whitespace-pre-line text-sm text-neutral-600 dark:text-neutral-400",children:i})]}),A.jsxs(RNe,{children:[A.jsx(ONe,{className:Yt("inline-flex items-center gap-2","font-semibold","dark:bg-neutral-800 dark:text-neutral-200 dark:hover:bg-neutral-700"),children:l}),A.jsx(PNe,{autoFocus:!0,onClick:async()=>{await n(),e()},className:Yt("inline-flex items-center gap-2 font-semibold",u?"bg-red-600 text-white shadow-inner shadow-white/10 hover:bg-red-500 dark:bg-red-500 dark:hover:bg-red-400":"bg-neutral-900 text-white hover:bg-neutral-800 dark:bg-neutral-100 dark:text-neutral-900 dark:hover:bg-neutral-200"),children:o})]})]})})}const Iy=ee.memo(Q8r);function oRt(){const{t}=En(),e=Un(i=>i.toggleAutoExplore),n=Un(i=>i.autoExploreLoading);return{handleToggle:T.useCallback(async i=>{if(!n)try{await e(i),Nr.success(t(i?"agents.rootAgent.autoExploreEnabled":"agents.rootAgent.autoExploreDisabled"))}catch(o){console.error("Failed to toggle auto-explore:",o),Nr.error(t("agents.rootAgent.autoExploreFailed"))}},[n,e,t]),loading:n}}function lRt(t,e){const n={};for(const r of t){const i=e[r.id];if(!i)continue;const o=n[i];(!o||r.updatedAt>o)&&(n[i]=r.updatedAt)}return n}function $8r({onClick:t}){const{t:e}=En();return A.jsxs(Ct.button,{onClick:t,initial:{opacity:0,y:10},animate:{opacity:1,y:0},whileHover:{scale:1.02},whileTap:{scale:.98},transition:{type:"spring",stiffness:400,damping:25},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg
576
576
  text-sm font-medium text-neutral-600 dark:text-neutral-400
577
577
  bg-white/60 dark:bg-neutral-800/60 backdrop-blur-sm
578
578
  border border-neutral-200/60 dark:border-neutral-700/60
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sciol/xyzen",
3
3
  "type": "module",
4
- "version": "1.9.88-beta.01fba8a",
4
+ "version": "1.9.88-beta.fb40704",
5
5
  "description": "A modern, lightweight, and extensible chat component for React.",
6
6
  "author": "Haohui <harveyque@outlook.com>",
7
7
  "license": "Apache-2.0",