@checksum-ai/runtime 4.1.1-beta.8 → 4.1.1-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/.env +1 -1
  2. package/cli.js +1 -1
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/.env CHANGED
@@ -1 +1 @@
1
- CHECKSUM_RUNTIME_BUILD_TIME=2026-05-29T09:25:48.226Z
1
+ CHECKSUM_RUNTIME_BUILD_TIME=2026-05-29T16:43:50.142Z
package/cli.js CHANGED
@@ -732,7 +732,7 @@ Details: ${ae.message}`),mir(ae)&&(he=`${he}
732
732
  ${Qke.prettifyError(ae)}`),new v_e(he,JSON.stringify(n))}else{let ae=qm(u,this.schema);if(!ae.valid){let he="Received tool input did not match expected schema";throw this.verboseParsingErrors&&(he=`${he}
733
733
  Details: ${ae.errors.map(ft=>`${ft.keywordLocation}: ${ft.error}`).join(`
734
734
  `)}`),new v_e(he,JSON.stringify(n))}_=u}let h=i3e(s),b=D5.configure(h.callbacks,this.callbacks,h.tags||c,this.tags,h.metadata,this.metadata,{verbose:this.verbose}),S;DV(n)&&(S=n.id),!S&&uKt(h)&&(S=h.toolCall.id);let k=await(b==null?void 0:b.handleToolStart(this.toJSON(),typeof n=="string"?n:JSON.stringify(n),h.runId,void 0,void 0,void 0,h.runName,S));delete h.runId;let B;try{let ae=await this._call(_,k,h);B=Ppt(ae)?await msr(ae,async he=>{try{await(k==null?void 0:k.handleToolEvent(he))}catch(ft){await(k==null?void 0:k.handleToolError(ft))}}):ae}catch(ae){throw await(k==null?void 0:k.handleToolError(ae)),ae}let G,j;if(this.responseFormat==="content_and_artifact")if(Array.isArray(B)&&B.length===2)[G,j]=B;else throw new Error(`Tool response format is "content_and_artifact" but the output was not a two-tuple.
735
- Result: ${JSON.stringify(B)}`);else G=B;let ie=D6n({content:G,artifact:j,toolCallId:S,name:this.name,metadata:this.metadata});return await(k==null?void 0:k.handleToolEnd(ie)),ie}},t(Lte,"StructuredTool"),Lte),Qte,I6n=(Qte=class extends jar{schema=ol.object({input:ol.string().optional()}).transform(n=>n.input);constructor(n){super(n)}call(n,s){let c=typeof n=="string"||n==null?{input:n}:n;return super.call(c,s)}},t(Qte,"Tool"),Qte),Ute,T6n=(Ute=class extends I6n{static lc_name(){return"DynamicTool"}name;description;func;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect}async call(n,s){let c=i3e(s);return c.runName===void 0&&(c.runName=this.name),super.call(n,c)}_call(n,s,c){return this.func(n,s,c)}},t(Ute,"DynamicTool"),Ute),jte,k6n=(jte=class extends jar{static lc_name(){return"DynamicStructuredTool"}description;func;schema;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect,this.schema=n.schema}async call(n,s,c){let u=i3e(s);return u.runName===void 0&&(u.runName=this.name),super.call(n,u,c)}_call(n,s,c){return this.func(n,s,c)}},t(jte,"DynamicStructuredTool"),jte);function Ddt(i,n){var h;let s=Z3e(n.schema),c=Rme(n.schema);if(!n.schema||s||c)return new T6n({...n,description:n.description??((h=n.schema)==null?void 0:h.description)??`${n.name} tool`,func:t(async(b,S,k)=>new Promise((B,G)=>{let j=W1(k,{callbacks:S==null?void 0:S.getChild()});_v.runWithConfig(mw(j),async()=>{try{B(i(b,j))}catch(ie){G(ie)}})}),"func")});let u=n.schema,_=n.description??n.schema.description??`${n.name} tool`;return new k6n({...n,description:_,schema:u,func:t(async(b,S,k)=>new Promise((B,G)=>{let j,ie=t(()=>{k!=null&&k.signal&&j&&k.signal.removeEventListener("abort",j)},"cleanup");k!=null&&k.signal&&(j=t(()=>{ie(),G(pM(k.signal))},"listener"),k.signal.addEventListener("abort",j,{once:!0}));let ae=W1(k,{callbacks:S==null?void 0:S.getChild()});_v.runWithConfig(mw(ae),async()=>{var he;try{let ft=await i(b,ae);if(Ppt(ft)){B(ft);return}if((he=k==null?void 0:k.signal)!=null&&he.aborted){ie();return}ie(),B(ft)}catch(ft){ie(),G(ft)}})}),"func")})}t(Ddt,"tool");function D6n(i){let{content:n,artifact:s,toolCallId:c,metadata:u}=i;return c&&!jKt(n)?typeof n=="string"||Array.isArray(n)&&n.every(_=>typeof _=="object")?new c8e({status:"success",content:n,artifact:s,tool_call_id:c,name:i.name,metadata:u}):new c8e({status:"success",content:N6n(n),artifact:s,tool_call_id:c,name:i.name,metadata:u}):n}t(D6n,"_formatToolOutput");function N6n(i){try{return JSON.stringify(i)??""}catch{return`${i}`}}t(N6n,"_stringify");var sP=class sP{constructor(){this.toolsMap={}}get addTool(){return this._addTool||(this._addTool=this.buildAddToolFacade()),this._addTool}getToolNames(){return Object.keys(this.toolRecord.names)}get tools(){return this.toolsMap}buildAddToolFacade(){let n={},s=this.toolRecord.tools;for(let c of Object.keys(s))n[c]=u=>this._addSingleTool(c,u);return n}static describeTool(n,s){if(n instanceof ol.ZodObject){let c={},u=n.shape;for(let _ of Object.keys(u)){let h=u[_],b=s==null?void 0:s[_];typeof b=="string"?c[_]=h.describe(b):b&&typeof b=="object"?c[_]=sP.describeTool(h,b):c[_]=h}return ol.object(c).strict()}if(n instanceof ol.ZodArray){let c=n.element;return s&&typeof s=="object"&&s.element?ol.array(sP.describeTool(c,s.element)):n}return n instanceof ol.ZodOptional?sP.describeTool(n.unwrap(),s).optional():n instanceof ol.ZodNullable?sP.describeTool(n.unwrap(),s).nullable():typeof s=="string"?n.describe(s):n}_addSingleTool(n,s){let c=s.name??String(n),_=this.toolRecord.tools[n]._create({...s,name:c,params:s.params,handler:s.handler}),h=this.toolRecord.tools[n],b=sP.describeTool(h,s.params),k=Ddt(t(async B=>{let G=b.parse(B);return s.handler(G)},"validatedHandler"),{name:_.name,description:_.description,schema:b});return this.toolsMap[n]=k,k}_buildOne(n,s){return this._addSingleTool(n,{...s,name:String(n)})}static buildTool(n,s,c){let u=String(s),h=n.tools[s]._create({name:u,description:"",handler:c,params:{}}),b=n.tools[s],S=sP.describeTool(b,{});return Ddt(t(async G=>{let j=S.parse(G);return c(j)},"validatedHandler"),{name:h.name,description:h.description,schema:S})}};t(sP,"AbstractToolContainer");var Q5=sP;var jke=class jke{constructor(n,s){this.version=n;let c={};for(let _ in s)c[_]=_;this.names=c;let u={};for(let _ in s){let h=s[_];Object.defineProperty(h,"name",{value:_,configurable:!1,enumerable:!0,writable:!1}),h._create=(b=>S=>{let k=S.name??b;return{...S,name:k}})(_),u[_]=h}this.tools=u}static create(n,s){return new jke(n,s)}};t(jke,"ToolProtocol");var Uke=jke;var Gh=Uke.create("v1",{readFile:ol.object({path:ol.string()}),getState:ol.object({thought:ol.string(),pageId:ol.string().optional(),includeAllPages:ol.boolean().optional()}),invokeCode:ol.object({code:ol.string().refine(i=>{let n=i.trim();return n.includes("page.getByChecksumId(")||n.includes("page.getByChecksumId(")||n.startsWith("const ")||n.startsWith("let ")||n.startsWith("var ")||n.includes("=")||n.includes("variableStore.")},{message:"Code should use page.getByChecksumId() for element targeting, or be explicit variable assignments/function calls"}),thought:ol.string(),pageId:ol.string().optional()}),wait:ol.object({time:ol.number().optional()}),scroll:ol.object({checksumId:ol.string(),thought:ol.string()}),final_result:ol.object({result:ol.enum(["pass","fail"]),thought:ol.string(),visualAnalysis:ol.string().optional()}),getElementScreenshot:ol.object({checksumId:ol.string(),thought:ol.string()}),listPages:ol.object({thought:ol.string().optional()}),switchPage:ol.object({pageId:ol.string(),thought:ol.string().optional()}),analyze:ol.object({previousImmediateSteps:ol.string(),currentFailingStep:ol.string(),nextImmediateSteps:ol.string(),testStepToStopAt:ol.string()}),think:ol.object({thought:ol.string()})});var Hdt=Da(zar(),1);var HT=Object.create(null);HT.open="0";HT.close="1";HT.ping="2";HT.pong="3";HT.message="4";HT.upgrade="5";HT.noop="6";var Vme=Object.create(null);Object.keys(HT).forEach(i=>{Vme[HT[i]]=i});var zme={type:"error",data:"parser error"};var $me=t(({type:i,data:n},s,c)=>n instanceof ArrayBuffer||ArrayBuffer.isView(n)?c(s?n:"b"+$ar(n,!0).toString("base64")):c(HT[i]+(n||"")),"encodePacket"),$ar=t((i,n)=>Buffer.isBuffer(i)||i instanceof Uint8Array&&!n?i:i instanceof ArrayBuffer?Buffer.from(i):Buffer.from(i.buffer,i.byteOffset,i.byteLength),"toBuffer"),Pdt;function War(i,n){if(i.data instanceof ArrayBuffer||ArrayBuffer.isView(i.data))return n($ar(i.data,!1));$me(i,!0,s=>{Pdt||(Pdt=new TextEncoder),n(Pdt.encode(s))})}t(War,"encodePacketToBinary");var Wme=t((i,n)=>{if(typeof i!="string")return{type:"message",data:qar(i,n)};let s=i.charAt(0);if(s==="b"){let c=Buffer.from(i.substring(1),"base64");return{type:"message",data:qar(c,n)}}return Vme[s]?i.length>1?{type:Vme[s],data:i.substring(1)}:{type:Vme[s]}:zme},"decodePacket"),qar=t((i,n)=>{switch(n){case"arraybuffer":return i instanceof ArrayBuffer?i:Buffer.isBuffer(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i.buffer;case"nodebuffer":default:return Buffer.isBuffer(i)?i:Buffer.from(i)}},"mapBinary");var Har="",Gar=t((i,n)=>{let s=i.length,c=new Array(s),u=0;i.forEach((_,h)=>{$me(_,!1,b=>{c[h]=b,++u===s&&n(c.join(Har))})})},"encodePayload"),Yar=t((i,n)=>{let s=i.split(Har),c=[];for(let u=0;u<s.length;u++){let _=Wme(s[u],n);if(c.push(_),_.type==="error")break}return c},"decodePayload");function Zar(){return new TransformStream({transform(i,n){War(i,s=>{let c=s.length,u;if(c<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,c);else if(c<65536){u=new Uint8Array(3);let _=new DataView(u.buffer);_.setUint8(0,126),_.setUint16(1,c)}else{u=new Uint8Array(9);let _=new DataView(u.buffer);_.setUint8(0,127),_.setBigUint64(1,BigInt(c))}i.data&&typeof i.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(s)})}})}t(Zar,"createPacketEncoderStream");var Fdt;function Jke(i){return i.reduce((n,s)=>n+s.length,0)}t(Jke,"totalLength");function Vke(i,n){if(i[0].length===n)return i.shift();let s=new Uint8Array(n),c=0;for(let u=0;u<n;u++)s[u]=i[0][c++],c===i[0].length&&(i.shift(),c=0);return i.length&&c<i[0].length&&(i[0]=i[0].slice(c)),s}t(Vke,"concatChunks");function Kar(i,n){Fdt||(Fdt=new TextDecoder);let s=[],c=0,u=-1,_=!1;return new TransformStream({transform(h,b){for(s.push(h);;){if(c===0){if(Jke(s)<1)break;let S=Vke(s,1);_=(S[0]&128)===128,u=S[0]&127,u<126?c=3:u===126?c=1:c=2}else if(c===1){if(Jke(s)<2)break;let S=Vke(s,2);u=new DataView(S.buffer,S.byteOffset,S.length).getUint16(0),c=3}else if(c===2){if(Jke(s)<8)break;let S=Vke(s,8),k=new DataView(S.buffer,S.byteOffset,S.length),B=k.getUint32(0);if(B>Math.pow(2,21)-1){b.enqueue(zme);break}u=B*Math.pow(2,32)+k.getUint32(4),c=3}else{if(Jke(s)<u)break;let S=Vke(s,u);b.enqueue(Wme(_?S:Fdt.decode(S),n)),c=0}if(u===0||u>i){b.enqueue(zme);break}}}})}t(Kar,"createPacketDecoderStream");var Bdt=4;var mor=Da(Cz(),1);var aP=process.nextTick,Kb=global,eor="nodebuffer";function tor(){return new Rdt}t(tor,"createCookieJar");function R6n(i){let n=i.split("; "),s=n[0].indexOf("=");if(s===-1)return;let c=n[0].substring(0,s).trim();if(!c.length)return;let u=n[0].substring(s+1).trim();u.charCodeAt(0)===34&&(u=u.slice(1,-1));let _={name:c,value:u};for(let h=1;h<n.length;h++){let b=n[h].split("=");if(b.length!==2)continue;let S=b[0].trim(),k=b[1].trim();switch(S){case"Expires":_.expires=new Date(k);break;case"Max-Age":let B=new Date;B.setUTCSeconds(B.getUTCSeconds()+parseInt(k,10)),_.expires=B;break;default:}}return _}t(R6n,"parse");var Odt=class Odt{constructor(){this._cookies=new Map}parseCookies(n){n&&n.forEach(s=>{let c=R6n(s);c&&this._cookies.set(c.name,c)})}get cookies(){let n=Date.now();return this._cookies.forEach((s,c)=>{var u;((u=s.expires)===null||u===void 0?void 0:u.getTime())<n&&this._cookies.delete(c)}),this._cookies.entries()}addCookies(n){let s=[];for(let[c,u]of this.cookies)s.push(`${c}=${u.value}`);s.length&&(n.setDisableHeaderCheck(!0),n.setRequestHeader("cookie",s.join("; ")))}appendCookies(n){for(let[s,c]of this.cookies)n.append("cookie",`${s}=${c.value}`)}};t(Odt,"CookieJar");var Rdt=Odt;function zke(i,...n){return n.reduce((s,c)=>(i.hasOwnProperty(c)&&(s[c]=i[c]),s),{})}t(zke,"pick");var O6n=Kb.setTimeout,M6n=Kb.clearTimeout;function oP(i,n){n.useNativeTimers?(i.setTimeoutFn=O6n.bind(Kb),i.clearTimeoutFn=M6n.bind(Kb)):(i.setTimeoutFn=Kb.setTimeout.bind(Kb),i.clearTimeoutFn=Kb.clearTimeout.bind(Kb))}t(oP,"installTimerFunctions");var L6n=1.33;function ror(i){return typeof i=="string"?Q6n(i):Math.ceil((i.byteLength||i.size)*L6n)}t(ror,"byteLength");function Q6n(i){let n=0,s=0;for(let c=0,u=i.length;c<u;c++)n=i.charCodeAt(c),n<128?s+=1:n<2048?s+=2:n<55296||n>=57344?s+=3:(c++,s+=4);return s}t(Q6n,"utf8Length");function $ke(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}t($ke,"randomString");function nor(i){let n="";for(let s in i)i.hasOwnProperty(s)&&(n.length&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(i[s]));return n}t(nor,"encode");function ior(i){let n={},s=i.split("&");for(let c=0,u=s.length;c<u;c++){let _=s[c].split("=");n[decodeURIComponent(_[0])]=decodeURIComponent(_[1])}return n}t(ior,"decode");var hor=Da(wz(),1);var cCn=(0,hor.default)("engine.io-client:transport"),Vdt=class Vdt extends Error{constructor(n,s,c){super(n),this.description=s,this.context=c,this.type="TransportError"}};t(Vdt,"TransportError");var Yke=Vdt,zdt=class zdt extends mor.Emitter{constructor(n){super(),this.writable=!1,oP(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,s,c){return super.emitReserved("error",new Yke(n,s,c)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(n){this.readyState==="open"?this.write(n):cCn("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(n){let s=Wme(n,this.socket.binaryType);this.onPacket(s)}onPacket(n){super.emitReserved("packet",n)}onClose(n){this.readyState="closed",super.emitReserved("close",n)}pause(n){}createUri(n,s={}){return n+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){let n=this.opts.hostname;return n.indexOf(":")===-1?n:"["+n+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(n){let s=nor(n);return s.length?"?"+s:""}};t(zdt,"Transport");var cP=zdt;var gor=Da(wz(),1);var GT=(0,gor.default)("engine.io-client:polling"),$dt=class $dt extends cP{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(n){this.readyState="pausing";let s=t(()=>{GT("paused"),this.readyState="paused",n()},"pause");if(this._polling||!this.writable){let c=0;this._polling&&(GT("we are currently polling - waiting to pause"),c++,this.once("pollComplete",function(){GT("pre-pause polling complete"),--c||s()})),this.writable||(GT("we are currently writing - waiting to pause"),c++,this.once("drain",function(){GT("pre-pause writing complete"),--c||s()}))}else s()}_poll(){GT("polling"),this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){GT("polling got data %s",n);let s=t(c=>{if(this.readyState==="opening"&&c.type==="open"&&this.onOpen(),c.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(c)},"callback");Yar(n,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this._poll():GT('ignoring poll - transport state "%s"',this.readyState))}doClose(){let n=t(()=>{GT("writing close packet"),this.write([{type:"close"}])},"close");this.readyState==="open"?(GT("transport open - closing"),n()):(GT("transport not open - deferring close"),this.once("open",n))}write(n){this.writable=!1,Gar(n,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let n=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=$ke()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(n,s)}};t($dt,"Polling");var qme=$dt;var bor=Da(Cz(),1);var yor=!1;try{yor=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Aor=yor;var Eor=Da(wz(),1);var Wdt=(0,Eor.default)("engine.io-client:polling");function lCn(){}t(lCn,"empty");var qdt=class qdt extends qme{constructor(n){if(super(n),typeof location<"u"){let s=location.protocol==="https:",c=location.port;c||(c=s?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||c!==n.port}}doWrite(n,s){let c=this.request({method:"POST",data:n});c.on("success",s),c.on("error",(u,_)=>{this.onError("xhr post error",u,_)})}doPoll(){Wdt("xhr poll");let n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(s,c)=>{this.onError("xhr poll error",s,c)}),this.pollXhr=n}};t(qdt,"BaseXHR");var Zke=qdt,Wte=class Wte extends bor.Emitter{constructor(n,s,c){super(),this.createRequest=n,oP(this,c),this._opts=c,this._method=c.method||"GET",this._uri=s,this._data=c.data!==void 0?c.data:null,this._create()}_create(){var n;let s=zke(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;let c=this._xhr=this.createRequest(s);try{Wdt("xhr open %s: %s",this._method,this._uri),c.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){c.setDisableHeaderCheck&&c.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&c.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{c.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{c.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(c),"withCredentials"in c&&(c.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(c.timeout=this._opts.requestTimeout),c.onreadystatechange=()=>{var u;c.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(c.getResponseHeader("set-cookie"))),c.readyState===4&&(c.status===200||c.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof c.status=="number"?c.status:0)},0))},Wdt("xhr data %s",this._data),c.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=Wte.requestsCount++,Wte.requests[this._index]=this)}_onError(n){this.emitReserved("error",n,this._xhr),this._cleanup(!0)}_cleanup(n){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=lCn,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Wte.requests[this._index],this._xhr=null}}_onLoad(){let n=this._xhr.responseText;n!==null&&(this.emitReserved("data",n),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};t(Wte,"Request");var lP=Wte;lP.requestsCount=0;lP.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",vor);else if(typeof addEventListener=="function"){let i="onpagehide"in Kb?"pagehide":"unload";addEventListener(i,vor,!1)}}function vor(){for(let i in lP.requests)lP.requests.hasOwnProperty(i)&&lP.requests[i].abort()}t(vor,"unloadHandler");var Qoi=function(){let i=uCn({xdomain:!1});return i&&i.responseType!==null}();function uCn(i){let n=i.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||Aor))return new XMLHttpRequest}catch{}if(!n)try{return new Kb[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}t(uCn,"newRequest");var fCn=Hdt.default||Hdt,Gdt=class Gdt extends Zke{request(n={}){var s;return Object.assign(n,{xd:this.xd,cookieJar:(s=this.socket)===null||s===void 0?void 0:s._cookieJar},this.opts),new lP(c=>new fCn(c),this.uri(),n)}};t(Gdt,"XHR");var qte=Gdt;var b4n=Da(wor(),1),E4n=Da(l_t(),1),x4n=Da(f_t(),1),S_t=Da(E_t(),1),C4n=Da(xcr(),1);var Ccr=Da(wz(),1);var w4n=(0,Ccr.default)("engine.io-client:websocket"),I4n=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",w_t=class w_t extends cP{get name(){return"websocket"}doOpen(){let n=this.uri(),s=this.opts.protocols,c=I4n?{}:zke(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(c.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,s,c)}catch(u){return this.emitReserved("error",u)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=n=>this.onClose({description:"websocket connection closed",context:n}),this.ws.onmessage=n=>this.onData(n.data),this.ws.onerror=n=>this.onError("websocket error",n)}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;$me(c,this.supportsBinary,_=>{try{this.doWrite(c,_)}catch{w4n("websocket closed before onclose event")}u&&aP(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let n=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=$ke()),this.supportsBinary||(s.b64=1),this.createUri(n,s)}};t(w_t,"BaseWS");var f5e=w_t,Sci=Kb.WebSocket||Kb.MozWebSocket;var I_t=class I_t extends f5e{createSocket(n,s,c){var u;if(!((u=this.socket)===null||u===void 0)&&u._cookieJar){c.headers=c.headers||{},c.headers.cookie=typeof c.headers.cookie=="string"?[c.headers.cookie]:c.headers.cookie||[];for(let[_,h]of this.socket._cookieJar.cookies)c.headers.cookie.push(`${_}=${h.value}`)}return new S_t.default(n,s,c)}doWrite(n,s){let c={};n.options&&(c.compress=n.options.compress),this.opts.perMessageDeflate&&(typeof s=="string"?Buffer.byteLength(s):s.length)<this.opts.perMessageDeflate.threshold&&(c.compress=!1),this.ws.send(s,c)}};t(I_t,"WS");var Kte=I_t;var Scr=Da(wz(),1);var ihe=(0,Scr.default)("engine.io-client:webtransport"),T_t=class T_t extends cP{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(n){return this.emitReserved("error",n)}this._transport.closed.then(()=>{ihe("transport closed gracefully"),this.onClose()}).catch(n=>{ihe("transport closed due to %s",n),this.onError("webtransport error",n)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(n=>{let s=Kar(Number.MAX_SAFE_INTEGER,this.socket.binaryType),c=n.readable.pipeThrough(s).getReader(),u=Zar();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();let _=t(()=>{c.read().then(({done:b,value:S})=>{if(b){ihe("session is closed");return}ihe("received chunk: %o",S),this.onPacket(S),_()}).catch(b=>{ihe("an error occurred while reading: %s",b)})},"read");_();let h={type:"open"};this.query.sid&&(h.data=`{"sid":"${this.query.sid}"}`),this._writer.write(h).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;this._writer.write(c).then(()=>{u&&aP(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}};t(T_t,"WT");var Xte=T_t;var k_t={websocket:Kte,webtransport:Xte,polling:qte};var T4n=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,k4n=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ere(i){if(i.length>8e3)throw"URI too long";let n=i,s=i.indexOf("["),c=i.indexOf("]");s!=-1&&c!=-1&&(i=i.substring(0,s)+i.substring(s,c).replace(/:/g,";")+i.substring(c,i.length));let u=T4n.exec(i||""),_={},h=14;for(;h--;)_[k4n[h]]=u[h]||"";return s!=-1&&c!=-1&&(_.source=n,_.host=_.host.substring(1,_.host.length-1).replace(/;/g,":"),_.authority=_.authority.replace("[","").replace("]","").replace(/;/g,":"),_.ipv6uri=!0),_.pathNames=D4n(_,_.path),_.queryKey=N4n(_,_.query),_}t(ere,"parse");function D4n(i,n){let s=/\/{2,9}/g,c=n.replace(s,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&c.splice(0,1),n.slice(-1)=="/"&&c.splice(c.length-1,1),c}t(D4n,"pathNames");function N4n(i,n){let s={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,u,_){u&&(s[u]=_)}),s}t(N4n,"queryKey");var wcr=Da(Cz(),1);var Icr=Da(wz(),1);var W_=(0,Icr.default)("engine.io-client:socket"),D_t=typeof addEventListener=="function"&&typeof removeEventListener=="function",she=[];D_t&&addEventListener("offline",()=>{W_("closing %d connection(s) because the network was lost",she.length),she.forEach(i=>i())},!1);var tre=class tre extends wcr.Emitter{constructor(n,s){if(super(),this.binaryType=eor,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,n&&typeof n=="object"&&(s=n,n=null),n){let c=ere(n);s.hostname=c.host,s.secure=c.protocol==="https"||c.protocol==="wss",s.port=c.port,c.query&&(s.query=c.query)}else s.host&&(s.hostname=ere(s.host).host);oP(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(c=>{let u=c.prototype.name;this.transports.push(u),this._transportsByName[u]=c}),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},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=ior(this.opts.query)),D_t&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(W_("adding listener for the 'offline' event"),this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},she.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=tor()),this._open()}createTransport(n){W_('creating transport "%s"',n);let s=Object.assign({},this.opts.query);s.EIO=Bdt,s.transport=n,this.id&&(s.sid=this.id);let c=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[n]);return W_("options: %j",c),new this._transportsByName[n](c)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let n=this.opts.rememberUpgrade&&tre.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let s=this.createTransport(n);s.open(),this.setTransport(s)}setTransport(n){W_("setting transport %s",n.name),this.transport&&(W_("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=n,n.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){W_("socket open"),this.readyState="open",tre.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(W_('socket receive: type "%s", data "%s"',n.type,n.data),this.emitReserved("packet",n),this.emitReserved("heartbeat"),n.type){case"open":this.onHandshake(JSON.parse(n.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let s=new Error("server error");s.code=n.data,this._onError(s);break;case"message":this.emitReserved("data",n.data),this.emitReserved("message",n.data);break}else W_('packet received with socket readyState "%s"',this.readyState)}onHandshake(n){this.emitReserved("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this._pingInterval=n.pingInterval,this._pingTimeout=n.pingTimeout,this._maxPayload=n.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let n=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+n,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},n),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){let n=this._getWritablePackets();W_("flushing %d packets in socket",n.length),this.transport.send(n),this._prevBufferLen=n.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let c=0;c<this.writeBuffer.length;c++){let u=this.writeBuffer[c].data;if(u&&(s+=ror(u)),c>0&&s>this._maxPayload)return W_("only send %d out of %d packets",c,this.writeBuffer.length),this.writeBuffer.slice(0,c);s+=2}return W_("payload size is %d (max: %d)",s,this._maxPayload),this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let n=Date.now()>this._pingTimeoutTime;return n&&(W_("throttled timer detected, scheduling connection close"),this._pingTimeoutTime=0,aP(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,s,c){return this._sendPacket("message",n,s,c),this}send(n,s,c){return this._sendPacket("message",n,s,c),this}_sendPacket(n,s,c,u){if(typeof s=="function"&&(u=s,s=void 0),typeof c=="function"&&(u=c,c=null),this.readyState==="closing"||this.readyState==="closed")return;c=c||{},c.compress=c.compress!==!1;let _={type:n,data:s,options:c};this.emitReserved("packetCreate",_),this.writeBuffer.push(_),u&&this.once("flush",u),this.flush()}close(){let n=t(()=>{this._onClose("forced close"),W_("socket closing - telling transport to close"),this.transport.close()},"close"),s=t(()=>{this.off("upgrade",s),this.off("upgradeError",s),n()},"cleanupAndClose"),c=t(()=>{this.once("upgrade",s),this.once("upgradeError",s)},"waitForUpgrade");return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?c():n()}):this.upgrading?c():n()),this}_onError(n){if(W_("socket error %j",n),tre.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return W_("trying next transport"),this.transports.shift(),this._open();this.emitReserved("error",n),this._onClose("transport error",n)}_onClose(n,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(W_('socket close with reason: "%s"',n),this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),D_t&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let c=she.indexOf(this._offlineEventListener);c!==-1&&(W_("removing listener for the 'offline' event"),she.splice(c,1))}this.readyState="closed",this.id=null,this.emitReserved("close",n,s),this.writeBuffer=[],this._prevBufferLen=0}}};t(tre,"SocketWithoutUpgrade");var Nz=tre;Nz.protocol=Bdt;var N_t=class N_t extends Nz{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade){W_("starting upgrade probes");for(let n=0;n<this._upgrades.length;n++)this._probe(this._upgrades[n])}}_probe(n){W_('probing transport "%s"',n);let s=this.createTransport(n),c=!1;Nz.priorWebsocketSuccess=!1;let u=t(()=>{c||(W_('probe transport "%s" opened',n),s.send([{type:"ping",data:"probe"}]),s.once("packet",G=>{if(!c)if(G.type==="pong"&&G.data==="probe"){if(W_('probe transport "%s" pong',n),this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;Nz.priorWebsocketSuccess=s.name==="websocket",W_('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{c||this.readyState!=="closed"&&(W_("changing transport and sending upgrade packet"),B(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{W_('probe transport "%s" failed',n);let j=new Error("probe error");j.transport=s.name,this.emitReserved("upgradeError",j)}}))},"onTransportOpen");function _(){c||(c=!0,B(),s.close(),s=null)}t(_,"freezeTransport");let h=t(G=>{let j=new Error("probe error: "+G);j.transport=s.name,_(),W_('probe transport "%s" failed because of error: %s',n,G),this.emitReserved("upgradeError",j)},"onerror");function b(){h("transport closed")}t(b,"onTransportClose");function S(){h("socket closed")}t(S,"onclose");function k(G){s&&G.name!==s.name&&(W_('"%s" works - aborting "%s"',G.name,s.name),_())}t(k,"onupgrade");let B=t(()=>{s.removeListener("open",u),s.removeListener("error",h),s.removeListener("close",b),this.off("close",S),this.off("upgrading",k)},"cleanup");s.once("open",u),s.once("error",h),s.once("close",b),this.once("close",S),this.once("upgrading",k),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{c||s.open()},200):s.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){let s=[];for(let c=0;c<n.length;c++)~this.transports.indexOf(n[c])&&s.push(n[c]);return s}};t(N_t,"SocketWithUpgrade");var p5e=N_t,P_t=class P_t extends p5e{constructor(n,s={}){let c=typeof n=="object"?n:s;(!c.transports||c.transports&&typeof c.transports[0]=="string")&&(c.transports=(c.transports||["polling","websocket","webtransport"]).map(u=>k_t[u]).filter(u=>!!u)),super(n,c)}};t(P_t,"Socket");var rre=P_t;var eli=rre.protocol;var Fcr=Da(nre(),1);var Pcr=(0,Fcr.default)("socket.io-client:url");function Bcr(i,n="",s){let c=i;s=s||typeof location<"u"&&location,i==null&&(i=s.protocol+"//"+s.host),typeof i=="string"&&(i.charAt(0)==="/"&&(i.charAt(1)==="/"?i=s.protocol+i:i=s.host+i),/^(https?|wss?):\/\//.test(i)||(Pcr("protocol-less url %s",i),typeof s<"u"?i=s.protocol+"//"+i:i="https://"+i),Pcr("parse %s",i),c=ere(i)),c.port||(/^(http|ws)$/.test(c.protocol)?c.port="80":/^(http|ws)s$/.test(c.protocol)&&(c.port="443")),c.path=c.path||"/";let _=c.host.indexOf(":")!==-1?"["+c.host+"]":c.host;return c.id=c.protocol+"://"+_+":"+c.port+n,c.href=c.protocol+"://"+_+(s&&s.port===c.port?"":":"+c.port),c}t(Bcr,"url");var j_t={};Ck(j_t,{Decoder:()=>Q_t,Encoder:()=>L_t,PacketType:()=>ju,isPacketValid:()=>nSn,protocol:()=>jcr});var Lcr=Da(Cz(),1);var Y4n=typeof ArrayBuffer=="function",Z4n=t(i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i.buffer instanceof ArrayBuffer,"isView"),Rcr=Object.prototype.toString,K4n=typeof Blob=="function"||typeof Blob<"u"&&Rcr.call(Blob)==="[object BlobConstructor]",X4n=typeof File=="function"||typeof File<"u"&&Rcr.call(File)==="[object FileConstructor]";function ohe(i){return Y4n&&(i instanceof ArrayBuffer||Z4n(i))||K4n&&i instanceof Blob||X4n&&i instanceof File}t(ohe,"isBinary");function ahe(i,n){if(!i||typeof i!="object")return!1;if(Array.isArray(i)){for(let s=0,c=i.length;s<c;s++)if(ahe(i[s]))return!0;return!1}if(ohe(i))return!0;if(i.toJSON&&typeof i.toJSON=="function"&&arguments.length===1)return ahe(i.toJSON(),!0);for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)&&ahe(i[s]))return!0;return!1}t(ahe,"hasBinary");function Ocr(i){let n=[],s=i.data,c=i;return c.data=R_t(s,n),c.attachments=n.length,{packet:c,buffers:n}}t(Ocr,"deconstructPacket");function R_t(i,n){if(!i)return i;if(ohe(i)){let s={_placeholder:!0,num:n.length};return n.push(i),s}else if(Array.isArray(i)){let s=new Array(i.length);for(let c=0;c<i.length;c++)s[c]=R_t(i[c],n);return s}else if(typeof i=="object"&&!(i instanceof Date)){let s={};for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&(s[c]=R_t(i[c],n));return s}return i}t(R_t,"_deconstructPacket");function Mcr(i,n){return i.data=O_t(i.data,n),delete i.attachments,i}t(Mcr,"reconstructPacket");function O_t(i,n){if(!i)return i;if(i&&i._placeholder===!0){if(typeof i.num=="number"&&i.num>=0&&i.num<n.length)return n[i.num];throw new Error("illegal attachments")}else if(Array.isArray(i))for(let s=0;s<i.length;s++)i[s]=O_t(i[s],n);else if(typeof i=="object")for(let s in i)Object.prototype.hasOwnProperty.call(i,s)&&(i[s]=O_t(i[s],n));return i}t(O_t,"_reconstructPacket");var Qcr=Da(nre(),1);var M_t=(0,Qcr.default)("socket.io-parser"),Ucr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],jcr=5,ju;(function(i){i[i.CONNECT=0]="CONNECT",i[i.DISCONNECT=1]="DISCONNECT",i[i.EVENT=2]="EVENT",i[i.ACK=3]="ACK",i[i.CONNECT_ERROR=4]="CONNECT_ERROR",i[i.BINARY_EVENT=5]="BINARY_EVENT",i[i.BINARY_ACK=6]="BINARY_ACK"})(ju||(ju={}));var J_t=class J_t{constructor(n){this.replacer=n}encode(n){return M_t("encoding packet %j",n),(n.type===ju.EVENT||n.type===ju.ACK)&&ahe(n)?this.encodeAsBinary({type:n.type===ju.EVENT?ju.BINARY_EVENT:ju.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let s=""+n.type;return(n.type===ju.BINARY_EVENT||n.type===ju.BINARY_ACK)&&(s+=n.attachments+"-"),n.nsp&&n.nsp!=="/"&&(s+=n.nsp+","),n.id!=null&&(s+=n.id),n.data!=null&&(s+=JSON.stringify(n.data,this.replacer)),M_t("encoded %j as %s",n,s),s}encodeAsBinary(n){let s=Ocr(n),c=this.encodeAsString(s.packet),u=s.buffers;return u.unshift(c),u}};t(J_t,"Encoder");var L_t=J_t,g5e=class g5e extends Lcr.Emitter{constructor(n){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof n=="function"?{reviver:n}:n)}add(n){let s;if(typeof n=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(n);let c=s.type===ju.BINARY_EVENT;c||s.type===ju.BINARY_ACK?(s.type=c?ju.EVENT:ju.ACK,this.reconstructor=new U_t(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(ohe(n)||n.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(n),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+n)}decodeString(n){let s=0,c={type:Number(n.charAt(0))};if(ju[c.type]===void 0)throw new Error("unknown packet type "+c.type);if(c.type===ju.BINARY_EVENT||c.type===ju.BINARY_ACK){let _=s+1;for(;n.charAt(++s)!=="-"&&s!=n.length;);let h=n.substring(_,s);if(h!=Number(h)||n.charAt(s)!=="-")throw new Error("Illegal attachments");let b=Number(h);if(!Jcr(b)||b<0)throw new Error("Illegal attachments");if(b>this.opts.maxAttachments)throw new Error("too many attachments");c.attachments=b}if(n.charAt(s+1)==="/"){let _=s+1;for(;++s&&!(n.charAt(s)===","||s===n.length););c.nsp=n.substring(_,s)}else c.nsp="/";let u=n.charAt(s+1);if(u!==""&&Number(u)==u){let _=s+1;for(;++s;){let h=n.charAt(s);if(h==null||Number(h)!=h){--s;break}if(s===n.length)break}c.id=Number(n.substring(_,s+1))}if(n.charAt(++s)){let _=this.tryParse(n.substr(s));if(g5e.isPayloadValid(c.type,_))c.data=_;else throw new Error("invalid payload")}return M_t("decoded %s as %j",n,c),c}tryParse(n){try{return JSON.parse(n,this.opts.reviver)}catch{return!1}}static isPayloadValid(n,s){switch(n){case ju.CONNECT:return h5e(s);case ju.DISCONNECT:return s===void 0;case ju.CONNECT_ERROR:return typeof s=="string"||h5e(s);case ju.EVENT:case ju.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Ucr.indexOf(s[0])===-1);case ju.ACK:case ju.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}};t(g5e,"Decoder");var Q_t=g5e,V_t=class V_t{constructor(n){this.packet=n,this.buffers=[],this.reconPack=n}takeBinaryData(n){if(this.buffers.push(n),this.buffers.length===this.reconPack.attachments){let s=Mcr(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};t(V_t,"BinaryReconstructor");var U_t=V_t;function eSn(i){return typeof i=="string"}t(eSn,"isNamespaceValid");var Jcr=Number.isInteger||function(i){return typeof i=="number"&&isFinite(i)&&Math.floor(i)===i};function tSn(i){return i===void 0||Jcr(i)}t(tSn,"isAckIdValid");function h5e(i){return Object.prototype.toString.call(i)==="[object Object]"}t(h5e,"isObject");function rSn(i,n){switch(i){case ju.CONNECT:return n===void 0||h5e(n);case ju.DISCONNECT:return n===void 0;case ju.EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&Ucr.indexOf(n[0])===-1);case ju.ACK:return Array.isArray(n);case ju.CONNECT_ERROR:return typeof n=="string"||h5e(n);default:return!1}}t(rSn,"isDataValid");function nSn(i){return eSn(i.nsp)&&tSn(i.id)&&rSn(i.type,i.data)}t(nSn,"isPacketValid");function IC(i,n,s){return i.on(n,s),t(function(){i.off(n,s)},"subDestroy")}t(IC,"on");var Vcr=Da(Cz(),1),zcr=Da(nre(),1);var t1=(0,zcr.default)("socket.io-client:socket"),iSn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),z_t=class z_t extends Vcr.Emitter{constructor(n,s,c){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=n,this.nsp=s,c&&c.auth&&(this.auth=c.auth),this._opts=Object.assign({},c),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let n=this.io;this.subs=[IC(n,"open",this.onopen.bind(this)),IC(n,"packet",this.onpacket.bind(this)),IC(n,"error",this.onerror.bind(this)),IC(n,"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(...n){return n.unshift("message"),this.emit.apply(this,n),this}emit(n,...s){var c,u,_;if(iSn.hasOwnProperty(n))throw new Error('"'+n.toString()+'" is a reserved event name');if(s.unshift(n),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;let h={type:ju.EVENT,data:s};if(h.options={},h.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){let B=this.ids++;t1("emitting packet with ack id %d",B);let G=s.pop();this._registerAckCallback(B,G),h.id=B}let b=(u=(c=this.io.engine)===null||c===void 0?void 0:c.transport)===null||u===void 0?void 0:u.writable,S=this.connected&&!(!((_=this.io.engine)===null||_===void 0)&&_._hasPingExpired());return this.flags.volatile&&!b?t1("discard packet as the transport is not currently writable"):S?(this.notifyOutgoingListeners(h),this.packet(h)):this.sendBuffer.push(h),this.flags={},this}_registerAckCallback(n,s){var c;let u=(c=this.flags.timeout)!==null&&c!==void 0?c:this._opts.ackTimeout;if(u===void 0){this.acks[n]=s;return}let _=this.io.setTimeoutFn(()=>{delete this.acks[n];for(let b=0;b<this.sendBuffer.length;b++)this.sendBuffer[b].id===n&&(t1("removing packet with ack id %d from the buffer",n),this.sendBuffer.splice(b,1));t1("event with ack id %d has timed out after %d ms",n,u),s.call(this,new Error("operation has timed out"))},u),h=t((...b)=>{this.io.clearTimeoutFn(_),s.apply(this,b)},"fn");h.withError=!0,this.acks[n]=h}emitWithAck(n,...s){return new Promise((c,u)=>{let _=t((h,b)=>h?u(h):c(b),"fn");_.withError=!0,s.push(_),this.emit(n,...s)})}_addToQueue(n){let s;typeof n[n.length-1]=="function"&&(s=n.pop());let c={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,..._)=>c!==this._queue[0]?t1("packet [%d] already acknowledged",c.id):(u!==null?c.tryCount>this._opts.retries&&(t1("packet [%d] is discarded after %d tries",c.id,c.tryCount),this._queue.shift(),s&&s(u)):(t1("packet [%d] was successfully sent",c.id),this._queue.shift(),s&&s(null,..._)),c.pending=!1,this._drainQueue())),this._queue.push(c),this._drainQueue()}_drainQueue(n=!1){if(t1("draining queue"),!this.connected||this._queue.length===0)return;let s=this._queue[0];if(s.pending&&!n){t1("packet [%d] has already been sent and is waiting for an ack",s.id);return}s.pending=!0,s.tryCount++,t1("sending packet [%d] (try n\xB0%d)",s.id,s.tryCount),this.flags=s.flags,this.emit.apply(this,s.args)}packet(n){n.nsp=this.nsp,this.io._packet(n)}onopen(){t1("transport is open - connecting"),typeof this.auth=="function"?this.auth(n=>{this._sendConnectPacket(n)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(n){this.packet({type:ju.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},n):n})}onerror(n){this.connected||this.emitReserved("connect_error",n)}onclose(n,s){t1("close (%s)",n),this.connected=!1,delete this.id,this.emitReserved("disconnect",n,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(n=>{if(!this.sendBuffer.some(c=>String(c.id)===n)){let c=this.acks[n];delete this.acks[n],c.withError&&c.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case ju.CONNECT:n.data&&n.data.sid?this.onconnect(n.data.sid,n.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 ju.EVENT:case ju.BINARY_EVENT:this.onevent(n);break;case ju.ACK:case ju.BINARY_ACK:this.onack(n);break;case ju.DISCONNECT:this.ondisconnect();break;case ju.CONNECT_ERROR:this.destroy();let c=new Error(n.data.message);c.data=n.data.data,this.emitReserved("connect_error",c);break}}onevent(n){let s=n.data||[];t1("emitting event %j",s),n.id!=null&&(t1("attaching ack callback to event"),s.push(this.ack(n.id))),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(n){if(this._anyListeners&&this._anyListeners.length){let s=this._anyListeners.slice();for(let c of s)c.apply(this,n)}super.emit.apply(this,n),this._pid&&n.length&&typeof n[n.length-1]=="string"&&(this._lastOffset=n[n.length-1])}ack(n){let s=this,c=!1;return function(...u){c||(c=!0,t1("sending ack %j",u),s.packet({type:ju.ACK,id:n,data:u}))}}onack(n){let s=this.acks[n.id];if(typeof s!="function"){t1("bad ack %s",n.id);return}delete this.acks[n.id],t1("calling ack %s with %j",n.id,n.data),s.withError&&n.data.unshift(null),s.apply(this,n.data)}onconnect(n,s){t1("socket connected with id %s",n),this.id=n,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(n=>this.emitEvent(n)),this.receiveBuffer=[],this.sendBuffer.forEach(n=>{this.notifyOutgoingListeners(n),this.packet(n)}),this.sendBuffer=[]}ondisconnect(){t1("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(n=>n()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&(t1("performing disconnect (%s)",this.nsp),this.packet({type:ju.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(n){return this.flags.compress=n,this}get volatile(){return this.flags.volatile=!0,this}timeout(n){return this.flags.timeout=n,this}onAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(n),this}prependAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(n),this}offAny(n){if(!this._anyListeners)return this;if(n){let s=this._anyListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(n),this}prependAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(n),this}offAnyOutgoing(n){if(!this._anyOutgoingListeners)return this;if(n){let s=this._anyOutgoingListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(n){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let s=this._anyOutgoingListeners.slice();for(let c of s)c.apply(this,n.data)}}};t(z_t,"Socket");var ire=z_t;function Pz(i){i=i||{},this.ms=i.min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}t(Pz,"Backoff");Pz.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),s=Math.floor(n*this.jitter*i);i=Math.floor(n*10)&1?i+s:i-s}return Math.min(i,this.max)|0};Pz.prototype.reset=function(){this.attempts=0};Pz.prototype.setMin=function(i){this.ms=i};Pz.prototype.setMax=function(i){this.max=i};Pz.prototype.setJitter=function(i){this.jitter=i};var $cr=Da(Cz(),1),Wcr=Da(nre(),1);var o2=(0,Wcr.default)("socket.io-client:manager"),$_t=class $_t extends $cr.Emitter{constructor(n,s){var c;super(),this.nsps={},this.subs=[],n&&typeof n=="object"&&(s=n,n=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,oP(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((c=s.randomizationFactor)!==null&&c!==void 0?c:.5),this.backoff=new Pz({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=n;let u=s.parser||j_t;this.encoder=new u.Encoder,this.decoder=new u.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(n){return arguments.length?(this._reconnection=!!n,n||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(n){return n===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=n,this)}reconnectionDelay(n){var s;return n===void 0?this._reconnectionDelay:(this._reconnectionDelay=n,(s=this.backoff)===null||s===void 0||s.setMin(n),this)}randomizationFactor(n){var s;return n===void 0?this._randomizationFactor:(this._randomizationFactor=n,(s=this.backoff)===null||s===void 0||s.setJitter(n),this)}reconnectionDelayMax(n){var s;return n===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=n,(s=this.backoff)===null||s===void 0||s.setMax(n),this)}timeout(n){return arguments.length?(this._timeout=n,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(n){if(o2("readyState %s",this._readyState),~this._readyState.indexOf("open"))return this;o2("opening %s",this.uri),this.engine=new rre(this.uri,this.opts);let s=this.engine,c=this;this._readyState="opening",this.skipReconnect=!1;let u=IC(s,"open",function(){c.onopen(),n&&n()}),_=t(b=>{o2("error"),this.cleanup(),this._readyState="closed",this.emitReserved("error",b),n?n(b):this.maybeReconnectOnOpen()},"onError"),h=IC(s,"error",_);if(this._timeout!==!1){let b=this._timeout;o2("connect attempt will timeout after %d",b);let S=this.setTimeoutFn(()=>{o2("connect attempt timed out after %d",b),u(),_(new Error("timeout")),s.close()},b);this.opts.autoUnref&&S.unref(),this.subs.push(()=>{this.clearTimeoutFn(S)})}return this.subs.push(u),this.subs.push(h),this}connect(n){return this.open(n)}onopen(){o2("open"),this.cleanup(),this._readyState="open",this.emitReserved("open");let n=this.engine;this.subs.push(IC(n,"ping",this.onping.bind(this)),IC(n,"data",this.ondata.bind(this)),IC(n,"error",this.onerror.bind(this)),IC(n,"close",this.onclose.bind(this)),IC(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(n){try{this.decoder.add(n)}catch(s){this.onclose("parse error",s)}}ondecoded(n){aP(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){o2("error",n),this.emitReserved("error",n)}socket(n,s){let c=this.nsps[n];return c?this._autoConnect&&!c.active&&c.connect():(c=new ire(this,n,s),this.nsps[n]=c),c}_destroy(n){let s=Object.keys(this.nsps);for(let c of s)if(this.nsps[c].active){o2("socket %s is still active, skipping close",c);return}this._close()}_packet(n){o2("writing packet %j",n);let s=this.encoder.encode(n);for(let c=0;c<s.length;c++)this.engine.write(s[c],n.options)}cleanup(){o2("cleanup"),this.subs.forEach(n=>n()),this.subs.length=0,this.decoder.destroy()}_close(){o2("disconnect"),this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(n,s){var c;o2("closed due to %s",n),this.cleanup(),(c=this.engine)===null||c===void 0||c.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",n,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let n=this;if(this.backoff.attempts>=this._reconnectionAttempts)o2("reconnect failed"),this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let s=this.backoff.duration();o2("will wait %dms before reconnect attempt",s),this._reconnecting=!0;let c=this.setTimeoutFn(()=>{n.skipReconnect||(o2("attempting reconnect"),this.emitReserved("reconnect_attempt",n.backoff.attempts),!n.skipReconnect&&n.open(u=>{u?(o2("reconnect attempt error"),n._reconnecting=!1,n.reconnect(),this.emitReserved("reconnect_error",u)):(o2("reconnect success"),n.onreconnect())}))},s);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}}onreconnect(){let n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}};t($_t,"Manager");var sre=$_t;var Hcr=Da(nre(),1);var qcr=(0,Hcr.default)("socket.io-client"),che={};function lhe(i,n){typeof i=="object"&&(n=i,i=void 0),n=n||{};let s=Bcr(i,n.path||"/socket.io"),c=s.source,u=s.id,_=s.path,h=che[u]&&_ in che[u].nsps,b=n.forceNew||n["force new connection"]||n.multiplex===!1||h,S;return b?(qcr("ignoring socket cache for %s",c),S=new sre(c,n)):(che[u]||(qcr("new io instance for %s",c),che[u]=new sre(c,n)),S=che[u]),s.query&&!n.query&&(n.query=s.queryKey),S.socket(s.path,n)}t(lhe,"lookup");Object.assign(lhe,{Manager:sre,Socket:ire,io:lhe,connect:lhe});var y5e={URL:"http://localhost:3000",NAMESPACE:"auto-recovery",RECONNECTION_ATTEMPTS:5,RECONNECTION_DELAY:1e3},W_t=class W_t{constructor(n={}){this.socket=null;this.connectionState="disconnected";this.connectionPromise=null;this.resolution=null;this.options=n,this.url=n.url||y5e.URL,this.namespace=n.namespace||y5e.NAMESPACE,this.initializationPromise=this.createInitializationPromise()}createInitializationPromise(){return new Promise((n,s)=>{this.resolveInitialization=c=>n(c),this.rejectInitialization=c=>s(c)}).then(n=>(this.resolution=n,this.log("\u2705 Client initialization successful"),n),n=>{throw this.resolution=n,this.logError("\u274C Client initialization failed:",n),n}).finally(()=>{this.disconnect()})}defineHandlers(n){return n}async startSession(n,s,c){try{if(await this.connect(),this.emit(n,s,u=>{this.resolveInitialization(u)}),c&&c>0){let u=new Promise((_,h)=>{setTimeout(()=>{h(new Error(`Session initialization timed out after ${c}ms`))},c)});return Promise.race([this.initializationPromise,u])}return this.initializationPromise}catch(u){throw this.logError("\u274C Failed to start session:",u),this.rejectInitialization(u),u}}isConnected(){var n;return((n=this.socket)==null?void 0:n.connected)||!1}getConnectionState(){return this.connectionState}success(n){return{success:!0,data:n}}error(n){return{success:!1,error:n}}log(n,...s){this.options.verbose&&console.log(`[${this.namespace}] ${n}`,...s)}logError(n,...s){this.options.verbose&&console.error(`[${this.namespace}] ${n}`,...s)}async connect(){var n;if(this.connectionPromise)return this.connectionPromise;if(this.connectionState==="connected"&&((n=this.socket)!=null&&n.connected))return Promise.resolve();this.connectionState="connecting",this.connectionPromise=this.establishConnection();try{await this.connectionPromise,this.connectionState="connected"}catch(s){throw this.connectionState="disconnected",this.connectionPromise=null,s}return this.connectionPromise}establishConnection(){return new Promise((n,s)=>{let c=!1;try{let u=`${this.url}/${this.namespace}`;this.log(`\u{1F517} Connecting to socket at: ${u}`),this.socket=lhe(u,{autoConnect:!0,reconnection:!0,reconnectionAttempts:y5e.RECONNECTION_ATTEMPTS,reconnectionDelay:y5e.RECONNECTION_DELAY,...this.options.path&&{path:this.options.path}}),this.setupConnectionHandlers(n,s,c)}catch(u){this.logError("\u274C Failed to create socket connection:",u),c||s(u)}})}setupConnectionHandlers(n,s,c){if(!this.socket)return;let u={resolve:n,reject:s,connectionResolved:c};this.socket.on("connect",()=>this.handleConnect(u)),this.socket.on("reconnect",()=>this.handleReconnect()),this.socket.on("connect_error",_=>this.handleConnectError(_,u)),this.socket.on("disconnect",_=>this.handleDisconnect(_,u)),this.socket.io.on("reconnect_attempt",_=>this.handleReconnectAttempt(_)),this.socket.io.on("reconnect_error",_=>this.handleReconnectError(_)),this.socket.io.on("reconnect_failed",()=>this.handleReconnectFailed(u))}handleConnect(n){this.log("\u2705 Connected to socket"),this.connectionState="connected",this.setupEventHandlers(),n.connectionResolved||(n.connectionResolved=!0,n.resolve())}handleReconnect(){this.log("\u2705 Reconnected to socket"),this.connectionState="connected"}handleConnectError(n,s){var c;this.logError("\u274C Connection error:",n),this.connectionState="disconnected",!s.connectionResolved&&((c=this.socket)==null?void 0:c.disconnected)!==!1&&(s.connectionResolved=!0,s.reject(n))}handleDisconnect(n,s){this.log("\u{1F50C} Disconnected from socket:",n),this.connectionState="disconnected";let c=new Error(`Socket disconnected: ${n}`),u=!1;this.resolution===null&&n==="io server disconnect"&&(this.rejectInitialization(c),u=!0),!s.connectionResolved&&(n==="io server disconnect"||n==="transport close")&&(s.connectionResolved=!0,s.reject(c)),!u&&this.resolution===null&&this.connectionState==="disconnected"&&this.rejectInitialization(c)}handleReconnectAttempt(n){this.log(`\u{1F504} Reconnection attempt #${n}`),this.connectionState="reconnecting"}handleReconnectError(n){this.logError("\u274C Reconnection attempt failed:",n)}handleReconnectFailed(n){this.logError("\u274C All reconnection attempts failed"),this.connectionState="disconnected",this.resolution===null&&this.rejectInitialization("All reconnection attempts failed"),n.connectionResolved||(n.connectionResolved=!0,n.reject(new Error("All reconnection attempts failed")))}setupEventHandlers(){if(!this.socket){this.logError("\u274C Cannot setup event handlers: socket is null");return}this.log("\u2705 Setting up event handlers"),this.socket.on("__call",this.handleGatewayCall.bind(this))}async handleGatewayCall(n,s){this.log(`\u{1F4E5} Gateway called method: ${n.key} with args:`,n.args);try{let c=this.validateGatewayCall(n);if(c){s(c);return}let u=this.handlers[n.key];if(!u){let h=`No handler registered for method: ${n.key}`;this.logError(`\u274C ${h}`),s(this.error(h));return}let _=await u(...n.args);s(this.success(_))}catch(c){this.logError("\u274C Error handling gateway call:",c),s(this.error(c.message||"Unknown error occurred"))}}validateGatewayCall(n){return n.key?Array.isArray(n.args)?null:(this.logError("\u274C Received call with invalid args"),this.error("Args must be an array")):(this.logError("\u274C Received call with undefined key"),this.error("Key is undefined"))}emit(n,s,c){if(!this.socket){this.logError("\u274C Cannot emit: socket is null");return}this.log(`\u{1F4E4} Emitting event: ${n}`),this.socket.emit(n,s,u=>{c(u)})}disconnect(){this.connectionState!=="shutting_down"&&(this.connectionState="shutting_down",this.log("\u{1F50C} Initiating disconnect"),this.socket&&(this.socket.disconnect(),this.socket=null),this.connectionPromise=null,this.connectionState="disconnected",this.log("\u2705 Disconnected successfully"))}};t(W_t,"AbstractClient");var A5e=W_t;var Gcr,Ycr,Zcr,Kcr,Xcr,elr,tlr,rlr,b5e=class b5e extends(rlr=A5e,tlr=Gh.names.getState,elr=Gh.names.invokeCode,Xcr=Gh.names.final_result,Kcr=Gh.names.wait,Zcr=Gh.names.getElementScreenshot,Ycr=Gh.names.listPages,Gcr=Gh.names.switchPage,rlr){constructor(s,c){super({verbose:gc.testRun.autoRecovery.verboseConsoleLog,url:c.config.apiURL,namespace:"auto-recovery",path:"/auto-recovery/socket.io"});this.utils=s;this.initData=c;this.stepsThoughts=[];this.handlers=this.defineHandlers({callLangChainTool:t(async(s,c)=>{if(!this[s])throw new Error(`Tool ${s} not found`);return c.thought&&this.stepsThoughts.push(c.thought),await this[s].invoke(c)},"callLangChainTool"),getStatus:t(async s=>({sessionId:s,status:"active",data:{message:"Status retrieved successfully"}}),"getStatus")});this[tlr]=Q5.buildTool(Gh,Gh.names.getState,async s=>this.getStateHandler(s));this[elr]=Q5.buildTool(Gh,Gh.names.invokeCode,async s=>this.invokeCodeHandler(s));this[Xcr]=Q5.buildTool(Gh,Gh.names.final_result,async s=>this.finalResultHandler(s));this[Kcr]=Q5.buildTool(Gh,Gh.names.wait,async s=>this.waitHandler(s));this[Zcr]=Q5.buildTool(Gh,Gh.names.getElementScreenshot,async s=>this.getElementScreenshotHandler(s));this[Ycr]=Q5.buildTool(Gh,Gh.names.listPages,async s=>this.listPagesHandler(s));this[Gcr]=Q5.buildTool(Gh,Gh.names.switchPage,async s=>this.switchPageHandler(s))}async init(){let s={...this.initData,version:Gh.version};return await this.startSession("initialize",s).catch(c=>{this.utils.analytics.ARError({error:c.message});let u="Auto-Recovery attempt finished unsuccessfully";return this.utils.createChecksumStep({title:u,withError:!0}),this.utils.addAutoRecoveryErrorToReport(u,!1),{finalThought:u,stepsThoughts:[],result:"failed"}})}static async build(s){let c=await s.buildFallbackData();return new b5e(s,c)}async invokeCodeHandler(s){let c,u=this.utils.activePageGuid,_=s.pageId&&s.pageId!==u;return await this.utils.runConditionallyWithinStep(!0,s.thought||"Invoke Code",async()=>{try{_&&await this.utils.setActivePage(s.pageId);let h=await this.utils.invokeCode(s.code);this.utils.createChecksumStep({title:"Code Invoked Successfully"}),c={success:!0,invokeCodeResult:`invokeCodeResult: ${h.result}`,appState:(await this.utils.buildFallbackData()).applicationState,actionEffects:h.effects}}catch(h){c={success:!1,invokeCodeResult:`Error while invoking code: ${h}`,appState:(await this.utils.buildFallbackData()).applicationState}}finally{if(_&&u)try{await this.utils.setActivePage(u)}catch(h){console.warn("Failed to switch back to original page:",h)}}}),c}async getStateHandler(s){return this.utils.createChecksumStep({title:s.thought}),this.utils.analytics.ARGetState(s.thought),{success:!0,appState:await this.utils.captureApplicationState(s.pageId,s.includeAllPages)}}async finalResultHandler(s){let c=s.result==="pass",u=this.initData.type==="assertion"?c?"soft_assertion":"hard_assertion":c?"finish":"failed",_={finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts};await Promise.resolve(),this.resolveInitialization(_);try{this.utils.analytics.ARFinalResult({finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts})}catch(h){console.warn("Failed to record auto-recovery final-result analytics:",h)}try{this.utils.addAutoRecoveryErrorToReport(s.thought,c)}catch(h){console.warn("Failed to add auto-recovery result to report:",h)}}async getElementScreenshotHandler(s){return{success:!0,screenshot:await this.utils.getScreenshotForElement(s.checksumId)}}async waitHandler(s){await new Promise(u=>setTimeout(u,s.time||5e3));let c=await this.utils.buildFallbackData();return{success:!0,waitResult:`waited for ${s.time} seconds, the current HTML of the application after the wait is: ${c.applicationState.reducedHTML}`}}async listPagesHandler(s){s.thought&&this.utils.createChecksumStep({title:s.thought});let c=await this.utils.pageInteractor.getTabsInfo(),u=c.map((h,b)=>`${b+1}. ${h.title||"Untitled"} (${h.url})
735
+ Result: ${JSON.stringify(B)}`);else G=B;let ie=D6n({content:G,artifact:j,toolCallId:S,name:this.name,metadata:this.metadata});return await(k==null?void 0:k.handleToolEnd(ie)),ie}},t(Lte,"StructuredTool"),Lte),Qte,I6n=(Qte=class extends jar{schema=ol.object({input:ol.string().optional()}).transform(n=>n.input);constructor(n){super(n)}call(n,s){let c=typeof n=="string"||n==null?{input:n}:n;return super.call(c,s)}},t(Qte,"Tool"),Qte),Ute,T6n=(Ute=class extends I6n{static lc_name(){return"DynamicTool"}name;description;func;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect}async call(n,s){let c=i3e(s);return c.runName===void 0&&(c.runName=this.name),super.call(n,c)}_call(n,s,c){return this.func(n,s,c)}},t(Ute,"DynamicTool"),Ute),jte,k6n=(jte=class extends jar{static lc_name(){return"DynamicStructuredTool"}description;func;schema;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect,this.schema=n.schema}async call(n,s,c){let u=i3e(s);return u.runName===void 0&&(u.runName=this.name),super.call(n,u,c)}_call(n,s,c){return this.func(n,s,c)}},t(jte,"DynamicStructuredTool"),jte);function Ddt(i,n){var h;let s=Z3e(n.schema),c=Rme(n.schema);if(!n.schema||s||c)return new T6n({...n,description:n.description??((h=n.schema)==null?void 0:h.description)??`${n.name} tool`,func:t(async(b,S,k)=>new Promise((B,G)=>{let j=W1(k,{callbacks:S==null?void 0:S.getChild()});_v.runWithConfig(mw(j),async()=>{try{B(i(b,j))}catch(ie){G(ie)}})}),"func")});let u=n.schema,_=n.description??n.schema.description??`${n.name} tool`;return new k6n({...n,description:_,schema:u,func:t(async(b,S,k)=>new Promise((B,G)=>{let j,ie=t(()=>{k!=null&&k.signal&&j&&k.signal.removeEventListener("abort",j)},"cleanup");k!=null&&k.signal&&(j=t(()=>{ie(),G(pM(k.signal))},"listener"),k.signal.addEventListener("abort",j,{once:!0}));let ae=W1(k,{callbacks:S==null?void 0:S.getChild()});_v.runWithConfig(mw(ae),async()=>{var he;try{let ft=await i(b,ae);if(Ppt(ft)){B(ft);return}if((he=k==null?void 0:k.signal)!=null&&he.aborted){ie();return}ie(),B(ft)}catch(ft){ie(),G(ft)}})}),"func")})}t(Ddt,"tool");function D6n(i){let{content:n,artifact:s,toolCallId:c,metadata:u}=i;return c&&!jKt(n)?typeof n=="string"||Array.isArray(n)&&n.every(_=>typeof _=="object")?new c8e({status:"success",content:n,artifact:s,tool_call_id:c,name:i.name,metadata:u}):new c8e({status:"success",content:N6n(n),artifact:s,tool_call_id:c,name:i.name,metadata:u}):n}t(D6n,"_formatToolOutput");function N6n(i){try{return JSON.stringify(i)??""}catch{return`${i}`}}t(N6n,"_stringify");var sP=class sP{constructor(){this.toolsMap={}}get addTool(){return this._addTool||(this._addTool=this.buildAddToolFacade()),this._addTool}getToolNames(){return Object.keys(this.toolRecord.names)}get tools(){return this.toolsMap}buildAddToolFacade(){let n={},s=this.toolRecord.tools;for(let c of Object.keys(s))n[c]=u=>this._addSingleTool(c,u);return n}static describeTool(n,s){if(n instanceof ol.ZodObject){let c={},u=n.shape;for(let _ of Object.keys(u)){let h=u[_],b=s==null?void 0:s[_];typeof b=="string"?c[_]=h.describe(b):b&&typeof b=="object"?c[_]=sP.describeTool(h,b):c[_]=h}return ol.object(c).strict()}if(n instanceof ol.ZodArray){let c=n.element;return s&&typeof s=="object"&&s.element?ol.array(sP.describeTool(c,s.element)):n}return n instanceof ol.ZodOptional?sP.describeTool(n.unwrap(),s).optional():n instanceof ol.ZodNullable?sP.describeTool(n.unwrap(),s).nullable():typeof s=="string"?n.describe(s):n}_addSingleTool(n,s){let c=s.name??String(n),_=this.toolRecord.tools[n]._create({...s,name:c,params:s.params,handler:s.handler}),h=this.toolRecord.tools[n],b=sP.describeTool(h,s.params),k=Ddt(t(async B=>{let G=b.parse(B);return s.handler(G)},"validatedHandler"),{name:_.name,description:_.description,schema:b});return this.toolsMap[n]=k,k}_buildOne(n,s){return this._addSingleTool(n,{...s,name:String(n)})}static buildTool(n,s,c){let u=String(s),h=n.tools[s]._create({name:u,description:"",handler:c,params:{}}),b=n.tools[s],S=sP.describeTool(b,{});return Ddt(t(async G=>{let j=S.parse(G);return c(j)},"validatedHandler"),{name:h.name,description:h.description,schema:S})}};t(sP,"AbstractToolContainer");var Q5=sP;var jke=class jke{constructor(n,s){this.version=n;let c={};for(let _ in s)c[_]=_;this.names=c;let u={};for(let _ in s){let h=s[_];Object.defineProperty(h,"name",{value:_,configurable:!1,enumerable:!0,writable:!1}),h._create=(b=>S=>{let k=S.name??b;return{...S,name:k}})(_),u[_]=h}this.tools=u}static create(n,s){return new jke(n,s)}};t(jke,"ToolProtocol");var Uke=jke;var Gh=Uke.create("v1",{readFile:ol.object({path:ol.string()}),getState:ol.object({thought:ol.string(),pageId:ol.string().optional(),includeAllPages:ol.boolean().optional()}),invokeCode:ol.object({code:ol.string().refine(i=>{let n=i.trim();return n.includes("page.getByChecksumId(")||n.includes("page.getByChecksumId(")||n.startsWith("const ")||n.startsWith("let ")||n.startsWith("var ")||n.includes("=")||n.includes("variableStore.")},{message:"Code should use page.getByChecksumId() for element targeting, or be explicit variable assignments/function calls"}),thought:ol.string(),pageId:ol.string().optional()}),wait:ol.object({time:ol.number().optional()}),scroll:ol.object({checksumId:ol.string(),thought:ol.string()}),final_result:ol.object({result:ol.enum(["pass","fail"]),thought:ol.string(),visualAnalysis:ol.string().optional()}),getElementScreenshot:ol.object({checksumId:ol.string(),thought:ol.string()}),listPages:ol.object({thought:ol.string().optional()}),switchPage:ol.object({pageId:ol.string(),thought:ol.string().optional()}),analyze:ol.object({previousImmediateSteps:ol.string(),currentFailingStep:ol.string(),nextImmediateSteps:ol.string(),testStepToStopAt:ol.string()}),think:ol.object({thought:ol.string()})});var Hdt=Da(zar(),1);var HT=Object.create(null);HT.open="0";HT.close="1";HT.ping="2";HT.pong="3";HT.message="4";HT.upgrade="5";HT.noop="6";var Vme=Object.create(null);Object.keys(HT).forEach(i=>{Vme[HT[i]]=i});var zme={type:"error",data:"parser error"};var $me=t(({type:i,data:n},s,c)=>n instanceof ArrayBuffer||ArrayBuffer.isView(n)?c(s?n:"b"+$ar(n,!0).toString("base64")):c(HT[i]+(n||"")),"encodePacket"),$ar=t((i,n)=>Buffer.isBuffer(i)||i instanceof Uint8Array&&!n?i:i instanceof ArrayBuffer?Buffer.from(i):Buffer.from(i.buffer,i.byteOffset,i.byteLength),"toBuffer"),Pdt;function War(i,n){if(i.data instanceof ArrayBuffer||ArrayBuffer.isView(i.data))return n($ar(i.data,!1));$me(i,!0,s=>{Pdt||(Pdt=new TextEncoder),n(Pdt.encode(s))})}t(War,"encodePacketToBinary");var Wme=t((i,n)=>{if(typeof i!="string")return{type:"message",data:qar(i,n)};let s=i.charAt(0);if(s==="b"){let c=Buffer.from(i.substring(1),"base64");return{type:"message",data:qar(c,n)}}return Vme[s]?i.length>1?{type:Vme[s],data:i.substring(1)}:{type:Vme[s]}:zme},"decodePacket"),qar=t((i,n)=>{switch(n){case"arraybuffer":return i instanceof ArrayBuffer?i:Buffer.isBuffer(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i.buffer;case"nodebuffer":default:return Buffer.isBuffer(i)?i:Buffer.from(i)}},"mapBinary");var Har="",Gar=t((i,n)=>{let s=i.length,c=new Array(s),u=0;i.forEach((_,h)=>{$me(_,!1,b=>{c[h]=b,++u===s&&n(c.join(Har))})})},"encodePayload"),Yar=t((i,n)=>{let s=i.split(Har),c=[];for(let u=0;u<s.length;u++){let _=Wme(s[u],n);if(c.push(_),_.type==="error")break}return c},"decodePayload");function Zar(){return new TransformStream({transform(i,n){War(i,s=>{let c=s.length,u;if(c<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,c);else if(c<65536){u=new Uint8Array(3);let _=new DataView(u.buffer);_.setUint8(0,126),_.setUint16(1,c)}else{u=new Uint8Array(9);let _=new DataView(u.buffer);_.setUint8(0,127),_.setBigUint64(1,BigInt(c))}i.data&&typeof i.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(s)})}})}t(Zar,"createPacketEncoderStream");var Fdt;function Jke(i){return i.reduce((n,s)=>n+s.length,0)}t(Jke,"totalLength");function Vke(i,n){if(i[0].length===n)return i.shift();let s=new Uint8Array(n),c=0;for(let u=0;u<n;u++)s[u]=i[0][c++],c===i[0].length&&(i.shift(),c=0);return i.length&&c<i[0].length&&(i[0]=i[0].slice(c)),s}t(Vke,"concatChunks");function Kar(i,n){Fdt||(Fdt=new TextDecoder);let s=[],c=0,u=-1,_=!1;return new TransformStream({transform(h,b){for(s.push(h);;){if(c===0){if(Jke(s)<1)break;let S=Vke(s,1);_=(S[0]&128)===128,u=S[0]&127,u<126?c=3:u===126?c=1:c=2}else if(c===1){if(Jke(s)<2)break;let S=Vke(s,2);u=new DataView(S.buffer,S.byteOffset,S.length).getUint16(0),c=3}else if(c===2){if(Jke(s)<8)break;let S=Vke(s,8),k=new DataView(S.buffer,S.byteOffset,S.length),B=k.getUint32(0);if(B>Math.pow(2,21)-1){b.enqueue(zme);break}u=B*Math.pow(2,32)+k.getUint32(4),c=3}else{if(Jke(s)<u)break;let S=Vke(s,u);b.enqueue(Wme(_?S:Fdt.decode(S),n)),c=0}if(u===0||u>i){b.enqueue(zme);break}}}})}t(Kar,"createPacketDecoderStream");var Bdt=4;var mor=Da(Cz(),1);var aP=process.nextTick,Kb=global,eor="nodebuffer";function tor(){return new Rdt}t(tor,"createCookieJar");function R6n(i){let n=i.split("; "),s=n[0].indexOf("=");if(s===-1)return;let c=n[0].substring(0,s).trim();if(!c.length)return;let u=n[0].substring(s+1).trim();u.charCodeAt(0)===34&&(u=u.slice(1,-1));let _={name:c,value:u};for(let h=1;h<n.length;h++){let b=n[h].split("=");if(b.length!==2)continue;let S=b[0].trim(),k=b[1].trim();switch(S){case"Expires":_.expires=new Date(k);break;case"Max-Age":let B=new Date;B.setUTCSeconds(B.getUTCSeconds()+parseInt(k,10)),_.expires=B;break;default:}}return _}t(R6n,"parse");var Odt=class Odt{constructor(){this._cookies=new Map}parseCookies(n){n&&n.forEach(s=>{let c=R6n(s);c&&this._cookies.set(c.name,c)})}get cookies(){let n=Date.now();return this._cookies.forEach((s,c)=>{var u;((u=s.expires)===null||u===void 0?void 0:u.getTime())<n&&this._cookies.delete(c)}),this._cookies.entries()}addCookies(n){let s=[];for(let[c,u]of this.cookies)s.push(`${c}=${u.value}`);s.length&&(n.setDisableHeaderCheck(!0),n.setRequestHeader("cookie",s.join("; ")))}appendCookies(n){for(let[s,c]of this.cookies)n.append("cookie",`${s}=${c.value}`)}};t(Odt,"CookieJar");var Rdt=Odt;function zke(i,...n){return n.reduce((s,c)=>(i.hasOwnProperty(c)&&(s[c]=i[c]),s),{})}t(zke,"pick");var O6n=Kb.setTimeout,M6n=Kb.clearTimeout;function oP(i,n){n.useNativeTimers?(i.setTimeoutFn=O6n.bind(Kb),i.clearTimeoutFn=M6n.bind(Kb)):(i.setTimeoutFn=Kb.setTimeout.bind(Kb),i.clearTimeoutFn=Kb.clearTimeout.bind(Kb))}t(oP,"installTimerFunctions");var L6n=1.33;function ror(i){return typeof i=="string"?Q6n(i):Math.ceil((i.byteLength||i.size)*L6n)}t(ror,"byteLength");function Q6n(i){let n=0,s=0;for(let c=0,u=i.length;c<u;c++)n=i.charCodeAt(c),n<128?s+=1:n<2048?s+=2:n<55296||n>=57344?s+=3:(c++,s+=4);return s}t(Q6n,"utf8Length");function $ke(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}t($ke,"randomString");function nor(i){let n="";for(let s in i)i.hasOwnProperty(s)&&(n.length&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(i[s]));return n}t(nor,"encode");function ior(i){let n={},s=i.split("&");for(let c=0,u=s.length;c<u;c++){let _=s[c].split("=");n[decodeURIComponent(_[0])]=decodeURIComponent(_[1])}return n}t(ior,"decode");var hor=Da(wz(),1);var cCn=(0,hor.default)("engine.io-client:transport"),Vdt=class Vdt extends Error{constructor(n,s,c){super(n),this.description=s,this.context=c,this.type="TransportError"}};t(Vdt,"TransportError");var Yke=Vdt,zdt=class zdt extends mor.Emitter{constructor(n){super(),this.writable=!1,oP(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,s,c){return super.emitReserved("error",new Yke(n,s,c)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(n){this.readyState==="open"?this.write(n):cCn("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(n){let s=Wme(n,this.socket.binaryType);this.onPacket(s)}onPacket(n){super.emitReserved("packet",n)}onClose(n){this.readyState="closed",super.emitReserved("close",n)}pause(n){}createUri(n,s={}){return n+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){let n=this.opts.hostname;return n.indexOf(":")===-1?n:"["+n+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(n){let s=nor(n);return s.length?"?"+s:""}};t(zdt,"Transport");var cP=zdt;var gor=Da(wz(),1);var GT=(0,gor.default)("engine.io-client:polling"),$dt=class $dt extends cP{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(n){this.readyState="pausing";let s=t(()=>{GT("paused"),this.readyState="paused",n()},"pause");if(this._polling||!this.writable){let c=0;this._polling&&(GT("we are currently polling - waiting to pause"),c++,this.once("pollComplete",function(){GT("pre-pause polling complete"),--c||s()})),this.writable||(GT("we are currently writing - waiting to pause"),c++,this.once("drain",function(){GT("pre-pause writing complete"),--c||s()}))}else s()}_poll(){GT("polling"),this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){GT("polling got data %s",n);let s=t(c=>{if(this.readyState==="opening"&&c.type==="open"&&this.onOpen(),c.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(c)},"callback");Yar(n,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this._poll():GT('ignoring poll - transport state "%s"',this.readyState))}doClose(){let n=t(()=>{GT("writing close packet"),this.write([{type:"close"}])},"close");this.readyState==="open"?(GT("transport open - closing"),n()):(GT("transport not open - deferring close"),this.once("open",n))}write(n){this.writable=!1,Gar(n,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let n=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=$ke()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(n,s)}};t($dt,"Polling");var qme=$dt;var bor=Da(Cz(),1);var yor=!1;try{yor=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Aor=yor;var Eor=Da(wz(),1);var Wdt=(0,Eor.default)("engine.io-client:polling");function lCn(){}t(lCn,"empty");var qdt=class qdt extends qme{constructor(n){if(super(n),typeof location<"u"){let s=location.protocol==="https:",c=location.port;c||(c=s?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||c!==n.port}}doWrite(n,s){let c=this.request({method:"POST",data:n});c.on("success",s),c.on("error",(u,_)=>{this.onError("xhr post error",u,_)})}doPoll(){Wdt("xhr poll");let n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(s,c)=>{this.onError("xhr poll error",s,c)}),this.pollXhr=n}};t(qdt,"BaseXHR");var Zke=qdt,Wte=class Wte extends bor.Emitter{constructor(n,s,c){super(),this.createRequest=n,oP(this,c),this._opts=c,this._method=c.method||"GET",this._uri=s,this._data=c.data!==void 0?c.data:null,this._create()}_create(){var n;let s=zke(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;let c=this._xhr=this.createRequest(s);try{Wdt("xhr open %s: %s",this._method,this._uri),c.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){c.setDisableHeaderCheck&&c.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&c.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{c.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{c.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(c),"withCredentials"in c&&(c.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(c.timeout=this._opts.requestTimeout),c.onreadystatechange=()=>{var u;c.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(c.getResponseHeader("set-cookie"))),c.readyState===4&&(c.status===200||c.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof c.status=="number"?c.status:0)},0))},Wdt("xhr data %s",this._data),c.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=Wte.requestsCount++,Wte.requests[this._index]=this)}_onError(n){this.emitReserved("error",n,this._xhr),this._cleanup(!0)}_cleanup(n){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=lCn,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Wte.requests[this._index],this._xhr=null}}_onLoad(){let n=this._xhr.responseText;n!==null&&(this.emitReserved("data",n),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};t(Wte,"Request");var lP=Wte;lP.requestsCount=0;lP.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",vor);else if(typeof addEventListener=="function"){let i="onpagehide"in Kb?"pagehide":"unload";addEventListener(i,vor,!1)}}function vor(){for(let i in lP.requests)lP.requests.hasOwnProperty(i)&&lP.requests[i].abort()}t(vor,"unloadHandler");var Qoi=function(){let i=uCn({xdomain:!1});return i&&i.responseType!==null}();function uCn(i){let n=i.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||Aor))return new XMLHttpRequest}catch{}if(!n)try{return new Kb[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}t(uCn,"newRequest");var fCn=Hdt.default||Hdt,Gdt=class Gdt extends Zke{request(n={}){var s;return Object.assign(n,{xd:this.xd,cookieJar:(s=this.socket)===null||s===void 0?void 0:s._cookieJar},this.opts),new lP(c=>new fCn(c),this.uri(),n)}};t(Gdt,"XHR");var qte=Gdt;var b4n=Da(wor(),1),E4n=Da(l_t(),1),x4n=Da(f_t(),1),S_t=Da(E_t(),1),C4n=Da(xcr(),1);var Ccr=Da(wz(),1);var w4n=(0,Ccr.default)("engine.io-client:websocket"),I4n=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",w_t=class w_t extends cP{get name(){return"websocket"}doOpen(){let n=this.uri(),s=this.opts.protocols,c=I4n?{}:zke(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(c.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,s,c)}catch(u){return this.emitReserved("error",u)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=n=>this.onClose({description:"websocket connection closed",context:n}),this.ws.onmessage=n=>this.onData(n.data),this.ws.onerror=n=>this.onError("websocket error",n)}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;$me(c,this.supportsBinary,_=>{try{this.doWrite(c,_)}catch{w4n("websocket closed before onclose event")}u&&aP(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let n=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=$ke()),this.supportsBinary||(s.b64=1),this.createUri(n,s)}};t(w_t,"BaseWS");var f5e=w_t,Sci=Kb.WebSocket||Kb.MozWebSocket;var I_t=class I_t extends f5e{createSocket(n,s,c){var u;if(!((u=this.socket)===null||u===void 0)&&u._cookieJar){c.headers=c.headers||{},c.headers.cookie=typeof c.headers.cookie=="string"?[c.headers.cookie]:c.headers.cookie||[];for(let[_,h]of this.socket._cookieJar.cookies)c.headers.cookie.push(`${_}=${h.value}`)}return new S_t.default(n,s,c)}doWrite(n,s){let c={};n.options&&(c.compress=n.options.compress),this.opts.perMessageDeflate&&(typeof s=="string"?Buffer.byteLength(s):s.length)<this.opts.perMessageDeflate.threshold&&(c.compress=!1),this.ws.send(s,c)}};t(I_t,"WS");var Kte=I_t;var Scr=Da(wz(),1);var ihe=(0,Scr.default)("engine.io-client:webtransport"),T_t=class T_t extends cP{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(n){return this.emitReserved("error",n)}this._transport.closed.then(()=>{ihe("transport closed gracefully"),this.onClose()}).catch(n=>{ihe("transport closed due to %s",n),this.onError("webtransport error",n)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(n=>{let s=Kar(Number.MAX_SAFE_INTEGER,this.socket.binaryType),c=n.readable.pipeThrough(s).getReader(),u=Zar();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();let _=t(()=>{c.read().then(({done:b,value:S})=>{if(b){ihe("session is closed");return}ihe("received chunk: %o",S),this.onPacket(S),_()}).catch(b=>{ihe("an error occurred while reading: %s",b)})},"read");_();let h={type:"open"};this.query.sid&&(h.data=`{"sid":"${this.query.sid}"}`),this._writer.write(h).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;this._writer.write(c).then(()=>{u&&aP(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}};t(T_t,"WT");var Xte=T_t;var k_t={websocket:Kte,webtransport:Xte,polling:qte};var T4n=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,k4n=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ere(i){if(i.length>8e3)throw"URI too long";let n=i,s=i.indexOf("["),c=i.indexOf("]");s!=-1&&c!=-1&&(i=i.substring(0,s)+i.substring(s,c).replace(/:/g,";")+i.substring(c,i.length));let u=T4n.exec(i||""),_={},h=14;for(;h--;)_[k4n[h]]=u[h]||"";return s!=-1&&c!=-1&&(_.source=n,_.host=_.host.substring(1,_.host.length-1).replace(/;/g,":"),_.authority=_.authority.replace("[","").replace("]","").replace(/;/g,":"),_.ipv6uri=!0),_.pathNames=D4n(_,_.path),_.queryKey=N4n(_,_.query),_}t(ere,"parse");function D4n(i,n){let s=/\/{2,9}/g,c=n.replace(s,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&c.splice(0,1),n.slice(-1)=="/"&&c.splice(c.length-1,1),c}t(D4n,"pathNames");function N4n(i,n){let s={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,u,_){u&&(s[u]=_)}),s}t(N4n,"queryKey");var wcr=Da(Cz(),1);var Icr=Da(wz(),1);var W_=(0,Icr.default)("engine.io-client:socket"),D_t=typeof addEventListener=="function"&&typeof removeEventListener=="function",she=[];D_t&&addEventListener("offline",()=>{W_("closing %d connection(s) because the network was lost",she.length),she.forEach(i=>i())},!1);var tre=class tre extends wcr.Emitter{constructor(n,s){if(super(),this.binaryType=eor,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,n&&typeof n=="object"&&(s=n,n=null),n){let c=ere(n);s.hostname=c.host,s.secure=c.protocol==="https"||c.protocol==="wss",s.port=c.port,c.query&&(s.query=c.query)}else s.host&&(s.hostname=ere(s.host).host);oP(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(c=>{let u=c.prototype.name;this.transports.push(u),this._transportsByName[u]=c}),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},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=ior(this.opts.query)),D_t&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(W_("adding listener for the 'offline' event"),this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},she.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=tor()),this._open()}createTransport(n){W_('creating transport "%s"',n);let s=Object.assign({},this.opts.query);s.EIO=Bdt,s.transport=n,this.id&&(s.sid=this.id);let c=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[n]);return W_("options: %j",c),new this._transportsByName[n](c)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let n=this.opts.rememberUpgrade&&tre.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let s=this.createTransport(n);s.open(),this.setTransport(s)}setTransport(n){W_("setting transport %s",n.name),this.transport&&(W_("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=n,n.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){W_("socket open"),this.readyState="open",tre.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(W_('socket receive: type "%s", data "%s"',n.type,n.data),this.emitReserved("packet",n),this.emitReserved("heartbeat"),n.type){case"open":this.onHandshake(JSON.parse(n.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let s=new Error("server error");s.code=n.data,this._onError(s);break;case"message":this.emitReserved("data",n.data),this.emitReserved("message",n.data);break}else W_('packet received with socket readyState "%s"',this.readyState)}onHandshake(n){this.emitReserved("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this._pingInterval=n.pingInterval,this._pingTimeout=n.pingTimeout,this._maxPayload=n.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let n=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+n,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},n),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){let n=this._getWritablePackets();W_("flushing %d packets in socket",n.length),this.transport.send(n),this._prevBufferLen=n.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let c=0;c<this.writeBuffer.length;c++){let u=this.writeBuffer[c].data;if(u&&(s+=ror(u)),c>0&&s>this._maxPayload)return W_("only send %d out of %d packets",c,this.writeBuffer.length),this.writeBuffer.slice(0,c);s+=2}return W_("payload size is %d (max: %d)",s,this._maxPayload),this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let n=Date.now()>this._pingTimeoutTime;return n&&(W_("throttled timer detected, scheduling connection close"),this._pingTimeoutTime=0,aP(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,s,c){return this._sendPacket("message",n,s,c),this}send(n,s,c){return this._sendPacket("message",n,s,c),this}_sendPacket(n,s,c,u){if(typeof s=="function"&&(u=s,s=void 0),typeof c=="function"&&(u=c,c=null),this.readyState==="closing"||this.readyState==="closed")return;c=c||{},c.compress=c.compress!==!1;let _={type:n,data:s,options:c};this.emitReserved("packetCreate",_),this.writeBuffer.push(_),u&&this.once("flush",u),this.flush()}close(){let n=t(()=>{this._onClose("forced close"),W_("socket closing - telling transport to close"),this.transport.close()},"close"),s=t(()=>{this.off("upgrade",s),this.off("upgradeError",s),n()},"cleanupAndClose"),c=t(()=>{this.once("upgrade",s),this.once("upgradeError",s)},"waitForUpgrade");return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?c():n()}):this.upgrading?c():n()),this}_onError(n){if(W_("socket error %j",n),tre.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return W_("trying next transport"),this.transports.shift(),this._open();this.emitReserved("error",n),this._onClose("transport error",n)}_onClose(n,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(W_('socket close with reason: "%s"',n),this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),D_t&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let c=she.indexOf(this._offlineEventListener);c!==-1&&(W_("removing listener for the 'offline' event"),she.splice(c,1))}this.readyState="closed",this.id=null,this.emitReserved("close",n,s),this.writeBuffer=[],this._prevBufferLen=0}}};t(tre,"SocketWithoutUpgrade");var Nz=tre;Nz.protocol=Bdt;var N_t=class N_t extends Nz{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade){W_("starting upgrade probes");for(let n=0;n<this._upgrades.length;n++)this._probe(this._upgrades[n])}}_probe(n){W_('probing transport "%s"',n);let s=this.createTransport(n),c=!1;Nz.priorWebsocketSuccess=!1;let u=t(()=>{c||(W_('probe transport "%s" opened',n),s.send([{type:"ping",data:"probe"}]),s.once("packet",G=>{if(!c)if(G.type==="pong"&&G.data==="probe"){if(W_('probe transport "%s" pong',n),this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;Nz.priorWebsocketSuccess=s.name==="websocket",W_('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{c||this.readyState!=="closed"&&(W_("changing transport and sending upgrade packet"),B(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{W_('probe transport "%s" failed',n);let j=new Error("probe error");j.transport=s.name,this.emitReserved("upgradeError",j)}}))},"onTransportOpen");function _(){c||(c=!0,B(),s.close(),s=null)}t(_,"freezeTransport");let h=t(G=>{let j=new Error("probe error: "+G);j.transport=s.name,_(),W_('probe transport "%s" failed because of error: %s',n,G),this.emitReserved("upgradeError",j)},"onerror");function b(){h("transport closed")}t(b,"onTransportClose");function S(){h("socket closed")}t(S,"onclose");function k(G){s&&G.name!==s.name&&(W_('"%s" works - aborting "%s"',G.name,s.name),_())}t(k,"onupgrade");let B=t(()=>{s.removeListener("open",u),s.removeListener("error",h),s.removeListener("close",b),this.off("close",S),this.off("upgrading",k)},"cleanup");s.once("open",u),s.once("error",h),s.once("close",b),this.once("close",S),this.once("upgrading",k),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{c||s.open()},200):s.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){let s=[];for(let c=0;c<n.length;c++)~this.transports.indexOf(n[c])&&s.push(n[c]);return s}};t(N_t,"SocketWithUpgrade");var p5e=N_t,P_t=class P_t extends p5e{constructor(n,s={}){let c=typeof n=="object"?n:s;(!c.transports||c.transports&&typeof c.transports[0]=="string")&&(c.transports=(c.transports||["polling","websocket","webtransport"]).map(u=>k_t[u]).filter(u=>!!u)),super(n,c)}};t(P_t,"Socket");var rre=P_t;var eli=rre.protocol;var Fcr=Da(nre(),1);var Pcr=(0,Fcr.default)("socket.io-client:url");function Bcr(i,n="",s){let c=i;s=s||typeof location<"u"&&location,i==null&&(i=s.protocol+"//"+s.host),typeof i=="string"&&(i.charAt(0)==="/"&&(i.charAt(1)==="/"?i=s.protocol+i:i=s.host+i),/^(https?|wss?):\/\//.test(i)||(Pcr("protocol-less url %s",i),typeof s<"u"?i=s.protocol+"//"+i:i="https://"+i),Pcr("parse %s",i),c=ere(i)),c.port||(/^(http|ws)$/.test(c.protocol)?c.port="80":/^(http|ws)s$/.test(c.protocol)&&(c.port="443")),c.path=c.path||"/";let _=c.host.indexOf(":")!==-1?"["+c.host+"]":c.host;return c.id=c.protocol+"://"+_+":"+c.port+n,c.href=c.protocol+"://"+_+(s&&s.port===c.port?"":":"+c.port),c}t(Bcr,"url");var j_t={};Ck(j_t,{Decoder:()=>Q_t,Encoder:()=>L_t,PacketType:()=>ju,isPacketValid:()=>nSn,protocol:()=>jcr});var Lcr=Da(Cz(),1);var Y4n=typeof ArrayBuffer=="function",Z4n=t(i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i.buffer instanceof ArrayBuffer,"isView"),Rcr=Object.prototype.toString,K4n=typeof Blob=="function"||typeof Blob<"u"&&Rcr.call(Blob)==="[object BlobConstructor]",X4n=typeof File=="function"||typeof File<"u"&&Rcr.call(File)==="[object FileConstructor]";function ohe(i){return Y4n&&(i instanceof ArrayBuffer||Z4n(i))||K4n&&i instanceof Blob||X4n&&i instanceof File}t(ohe,"isBinary");function ahe(i,n){if(!i||typeof i!="object")return!1;if(Array.isArray(i)){for(let s=0,c=i.length;s<c;s++)if(ahe(i[s]))return!0;return!1}if(ohe(i))return!0;if(i.toJSON&&typeof i.toJSON=="function"&&arguments.length===1)return ahe(i.toJSON(),!0);for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)&&ahe(i[s]))return!0;return!1}t(ahe,"hasBinary");function Ocr(i){let n=[],s=i.data,c=i;return c.data=R_t(s,n),c.attachments=n.length,{packet:c,buffers:n}}t(Ocr,"deconstructPacket");function R_t(i,n){if(!i)return i;if(ohe(i)){let s={_placeholder:!0,num:n.length};return n.push(i),s}else if(Array.isArray(i)){let s=new Array(i.length);for(let c=0;c<i.length;c++)s[c]=R_t(i[c],n);return s}else if(typeof i=="object"&&!(i instanceof Date)){let s={};for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&(s[c]=R_t(i[c],n));return s}return i}t(R_t,"_deconstructPacket");function Mcr(i,n){return i.data=O_t(i.data,n),delete i.attachments,i}t(Mcr,"reconstructPacket");function O_t(i,n){if(!i)return i;if(i&&i._placeholder===!0){if(typeof i.num=="number"&&i.num>=0&&i.num<n.length)return n[i.num];throw new Error("illegal attachments")}else if(Array.isArray(i))for(let s=0;s<i.length;s++)i[s]=O_t(i[s],n);else if(typeof i=="object")for(let s in i)Object.prototype.hasOwnProperty.call(i,s)&&(i[s]=O_t(i[s],n));return i}t(O_t,"_reconstructPacket");var Qcr=Da(nre(),1);var M_t=(0,Qcr.default)("socket.io-parser"),Ucr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],jcr=5,ju;(function(i){i[i.CONNECT=0]="CONNECT",i[i.DISCONNECT=1]="DISCONNECT",i[i.EVENT=2]="EVENT",i[i.ACK=3]="ACK",i[i.CONNECT_ERROR=4]="CONNECT_ERROR",i[i.BINARY_EVENT=5]="BINARY_EVENT",i[i.BINARY_ACK=6]="BINARY_ACK"})(ju||(ju={}));var J_t=class J_t{constructor(n){this.replacer=n}encode(n){return M_t("encoding packet %j",n),(n.type===ju.EVENT||n.type===ju.ACK)&&ahe(n)?this.encodeAsBinary({type:n.type===ju.EVENT?ju.BINARY_EVENT:ju.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let s=""+n.type;return(n.type===ju.BINARY_EVENT||n.type===ju.BINARY_ACK)&&(s+=n.attachments+"-"),n.nsp&&n.nsp!=="/"&&(s+=n.nsp+","),n.id!=null&&(s+=n.id),n.data!=null&&(s+=JSON.stringify(n.data,this.replacer)),M_t("encoded %j as %s",n,s),s}encodeAsBinary(n){let s=Ocr(n),c=this.encodeAsString(s.packet),u=s.buffers;return u.unshift(c),u}};t(J_t,"Encoder");var L_t=J_t,g5e=class g5e extends Lcr.Emitter{constructor(n){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof n=="function"?{reviver:n}:n)}add(n){let s;if(typeof n=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(n);let c=s.type===ju.BINARY_EVENT;c||s.type===ju.BINARY_ACK?(s.type=c?ju.EVENT:ju.ACK,this.reconstructor=new U_t(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(ohe(n)||n.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(n),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+n)}decodeString(n){let s=0,c={type:Number(n.charAt(0))};if(ju[c.type]===void 0)throw new Error("unknown packet type "+c.type);if(c.type===ju.BINARY_EVENT||c.type===ju.BINARY_ACK){let _=s+1;for(;n.charAt(++s)!=="-"&&s!=n.length;);let h=n.substring(_,s);if(h!=Number(h)||n.charAt(s)!=="-")throw new Error("Illegal attachments");let b=Number(h);if(!Jcr(b)||b<0)throw new Error("Illegal attachments");if(b>this.opts.maxAttachments)throw new Error("too many attachments");c.attachments=b}if(n.charAt(s+1)==="/"){let _=s+1;for(;++s&&!(n.charAt(s)===","||s===n.length););c.nsp=n.substring(_,s)}else c.nsp="/";let u=n.charAt(s+1);if(u!==""&&Number(u)==u){let _=s+1;for(;++s;){let h=n.charAt(s);if(h==null||Number(h)!=h){--s;break}if(s===n.length)break}c.id=Number(n.substring(_,s+1))}if(n.charAt(++s)){let _=this.tryParse(n.substr(s));if(g5e.isPayloadValid(c.type,_))c.data=_;else throw new Error("invalid payload")}return M_t("decoded %s as %j",n,c),c}tryParse(n){try{return JSON.parse(n,this.opts.reviver)}catch{return!1}}static isPayloadValid(n,s){switch(n){case ju.CONNECT:return h5e(s);case ju.DISCONNECT:return s===void 0;case ju.CONNECT_ERROR:return typeof s=="string"||h5e(s);case ju.EVENT:case ju.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Ucr.indexOf(s[0])===-1);case ju.ACK:case ju.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}};t(g5e,"Decoder");var Q_t=g5e,V_t=class V_t{constructor(n){this.packet=n,this.buffers=[],this.reconPack=n}takeBinaryData(n){if(this.buffers.push(n),this.buffers.length===this.reconPack.attachments){let s=Mcr(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};t(V_t,"BinaryReconstructor");var U_t=V_t;function eSn(i){return typeof i=="string"}t(eSn,"isNamespaceValid");var Jcr=Number.isInteger||function(i){return typeof i=="number"&&isFinite(i)&&Math.floor(i)===i};function tSn(i){return i===void 0||Jcr(i)}t(tSn,"isAckIdValid");function h5e(i){return Object.prototype.toString.call(i)==="[object Object]"}t(h5e,"isObject");function rSn(i,n){switch(i){case ju.CONNECT:return n===void 0||h5e(n);case ju.DISCONNECT:return n===void 0;case ju.EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&Ucr.indexOf(n[0])===-1);case ju.ACK:return Array.isArray(n);case ju.CONNECT_ERROR:return typeof n=="string"||h5e(n);default:return!1}}t(rSn,"isDataValid");function nSn(i){return eSn(i.nsp)&&tSn(i.id)&&rSn(i.type,i.data)}t(nSn,"isPacketValid");function IC(i,n,s){return i.on(n,s),t(function(){i.off(n,s)},"subDestroy")}t(IC,"on");var Vcr=Da(Cz(),1),zcr=Da(nre(),1);var t1=(0,zcr.default)("socket.io-client:socket"),iSn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),z_t=class z_t extends Vcr.Emitter{constructor(n,s,c){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=n,this.nsp=s,c&&c.auth&&(this.auth=c.auth),this._opts=Object.assign({},c),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let n=this.io;this.subs=[IC(n,"open",this.onopen.bind(this)),IC(n,"packet",this.onpacket.bind(this)),IC(n,"error",this.onerror.bind(this)),IC(n,"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(...n){return n.unshift("message"),this.emit.apply(this,n),this}emit(n,...s){var c,u,_;if(iSn.hasOwnProperty(n))throw new Error('"'+n.toString()+'" is a reserved event name');if(s.unshift(n),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;let h={type:ju.EVENT,data:s};if(h.options={},h.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){let B=this.ids++;t1("emitting packet with ack id %d",B);let G=s.pop();this._registerAckCallback(B,G),h.id=B}let b=(u=(c=this.io.engine)===null||c===void 0?void 0:c.transport)===null||u===void 0?void 0:u.writable,S=this.connected&&!(!((_=this.io.engine)===null||_===void 0)&&_._hasPingExpired());return this.flags.volatile&&!b?t1("discard packet as the transport is not currently writable"):S?(this.notifyOutgoingListeners(h),this.packet(h)):this.sendBuffer.push(h),this.flags={},this}_registerAckCallback(n,s){var c;let u=(c=this.flags.timeout)!==null&&c!==void 0?c:this._opts.ackTimeout;if(u===void 0){this.acks[n]=s;return}let _=this.io.setTimeoutFn(()=>{delete this.acks[n];for(let b=0;b<this.sendBuffer.length;b++)this.sendBuffer[b].id===n&&(t1("removing packet with ack id %d from the buffer",n),this.sendBuffer.splice(b,1));t1("event with ack id %d has timed out after %d ms",n,u),s.call(this,new Error("operation has timed out"))},u),h=t((...b)=>{this.io.clearTimeoutFn(_),s.apply(this,b)},"fn");h.withError=!0,this.acks[n]=h}emitWithAck(n,...s){return new Promise((c,u)=>{let _=t((h,b)=>h?u(h):c(b),"fn");_.withError=!0,s.push(_),this.emit(n,...s)})}_addToQueue(n){let s;typeof n[n.length-1]=="function"&&(s=n.pop());let c={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,..._)=>c!==this._queue[0]?t1("packet [%d] already acknowledged",c.id):(u!==null?c.tryCount>this._opts.retries&&(t1("packet [%d] is discarded after %d tries",c.id,c.tryCount),this._queue.shift(),s&&s(u)):(t1("packet [%d] was successfully sent",c.id),this._queue.shift(),s&&s(null,..._)),c.pending=!1,this._drainQueue())),this._queue.push(c),this._drainQueue()}_drainQueue(n=!1){if(t1("draining queue"),!this.connected||this._queue.length===0)return;let s=this._queue[0];if(s.pending&&!n){t1("packet [%d] has already been sent and is waiting for an ack",s.id);return}s.pending=!0,s.tryCount++,t1("sending packet [%d] (try n\xB0%d)",s.id,s.tryCount),this.flags=s.flags,this.emit.apply(this,s.args)}packet(n){n.nsp=this.nsp,this.io._packet(n)}onopen(){t1("transport is open - connecting"),typeof this.auth=="function"?this.auth(n=>{this._sendConnectPacket(n)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(n){this.packet({type:ju.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},n):n})}onerror(n){this.connected||this.emitReserved("connect_error",n)}onclose(n,s){t1("close (%s)",n),this.connected=!1,delete this.id,this.emitReserved("disconnect",n,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(n=>{if(!this.sendBuffer.some(c=>String(c.id)===n)){let c=this.acks[n];delete this.acks[n],c.withError&&c.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case ju.CONNECT:n.data&&n.data.sid?this.onconnect(n.data.sid,n.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 ju.EVENT:case ju.BINARY_EVENT:this.onevent(n);break;case ju.ACK:case ju.BINARY_ACK:this.onack(n);break;case ju.DISCONNECT:this.ondisconnect();break;case ju.CONNECT_ERROR:this.destroy();let c=new Error(n.data.message);c.data=n.data.data,this.emitReserved("connect_error",c);break}}onevent(n){let s=n.data||[];t1("emitting event %j",s),n.id!=null&&(t1("attaching ack callback to event"),s.push(this.ack(n.id))),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(n){if(this._anyListeners&&this._anyListeners.length){let s=this._anyListeners.slice();for(let c of s)c.apply(this,n)}super.emit.apply(this,n),this._pid&&n.length&&typeof n[n.length-1]=="string"&&(this._lastOffset=n[n.length-1])}ack(n){let s=this,c=!1;return function(...u){c||(c=!0,t1("sending ack %j",u),s.packet({type:ju.ACK,id:n,data:u}))}}onack(n){let s=this.acks[n.id];if(typeof s!="function"){t1("bad ack %s",n.id);return}delete this.acks[n.id],t1("calling ack %s with %j",n.id,n.data),s.withError&&n.data.unshift(null),s.apply(this,n.data)}onconnect(n,s){t1("socket connected with id %s",n),this.id=n,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(n=>this.emitEvent(n)),this.receiveBuffer=[],this.sendBuffer.forEach(n=>{this.notifyOutgoingListeners(n),this.packet(n)}),this.sendBuffer=[]}ondisconnect(){t1("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(n=>n()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&(t1("performing disconnect (%s)",this.nsp),this.packet({type:ju.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(n){return this.flags.compress=n,this}get volatile(){return this.flags.volatile=!0,this}timeout(n){return this.flags.timeout=n,this}onAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(n),this}prependAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(n),this}offAny(n){if(!this._anyListeners)return this;if(n){let s=this._anyListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(n),this}prependAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(n),this}offAnyOutgoing(n){if(!this._anyOutgoingListeners)return this;if(n){let s=this._anyOutgoingListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(n){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let s=this._anyOutgoingListeners.slice();for(let c of s)c.apply(this,n.data)}}};t(z_t,"Socket");var ire=z_t;function Pz(i){i=i||{},this.ms=i.min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}t(Pz,"Backoff");Pz.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),s=Math.floor(n*this.jitter*i);i=Math.floor(n*10)&1?i+s:i-s}return Math.min(i,this.max)|0};Pz.prototype.reset=function(){this.attempts=0};Pz.prototype.setMin=function(i){this.ms=i};Pz.prototype.setMax=function(i){this.max=i};Pz.prototype.setJitter=function(i){this.jitter=i};var $cr=Da(Cz(),1),Wcr=Da(nre(),1);var o2=(0,Wcr.default)("socket.io-client:manager"),$_t=class $_t extends $cr.Emitter{constructor(n,s){var c;super(),this.nsps={},this.subs=[],n&&typeof n=="object"&&(s=n,n=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,oP(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((c=s.randomizationFactor)!==null&&c!==void 0?c:.5),this.backoff=new Pz({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=n;let u=s.parser||j_t;this.encoder=new u.Encoder,this.decoder=new u.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(n){return arguments.length?(this._reconnection=!!n,n||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(n){return n===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=n,this)}reconnectionDelay(n){var s;return n===void 0?this._reconnectionDelay:(this._reconnectionDelay=n,(s=this.backoff)===null||s===void 0||s.setMin(n),this)}randomizationFactor(n){var s;return n===void 0?this._randomizationFactor:(this._randomizationFactor=n,(s=this.backoff)===null||s===void 0||s.setJitter(n),this)}reconnectionDelayMax(n){var s;return n===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=n,(s=this.backoff)===null||s===void 0||s.setMax(n),this)}timeout(n){return arguments.length?(this._timeout=n,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(n){if(o2("readyState %s",this._readyState),~this._readyState.indexOf("open"))return this;o2("opening %s",this.uri),this.engine=new rre(this.uri,this.opts);let s=this.engine,c=this;this._readyState="opening",this.skipReconnect=!1;let u=IC(s,"open",function(){c.onopen(),n&&n()}),_=t(b=>{o2("error"),this.cleanup(),this._readyState="closed",this.emitReserved("error",b),n?n(b):this.maybeReconnectOnOpen()},"onError"),h=IC(s,"error",_);if(this._timeout!==!1){let b=this._timeout;o2("connect attempt will timeout after %d",b);let S=this.setTimeoutFn(()=>{o2("connect attempt timed out after %d",b),u(),_(new Error("timeout")),s.close()},b);this.opts.autoUnref&&S.unref(),this.subs.push(()=>{this.clearTimeoutFn(S)})}return this.subs.push(u),this.subs.push(h),this}connect(n){return this.open(n)}onopen(){o2("open"),this.cleanup(),this._readyState="open",this.emitReserved("open");let n=this.engine;this.subs.push(IC(n,"ping",this.onping.bind(this)),IC(n,"data",this.ondata.bind(this)),IC(n,"error",this.onerror.bind(this)),IC(n,"close",this.onclose.bind(this)),IC(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(n){try{this.decoder.add(n)}catch(s){this.onclose("parse error",s)}}ondecoded(n){aP(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){o2("error",n),this.emitReserved("error",n)}socket(n,s){let c=this.nsps[n];return c?this._autoConnect&&!c.active&&c.connect():(c=new ire(this,n,s),this.nsps[n]=c),c}_destroy(n){let s=Object.keys(this.nsps);for(let c of s)if(this.nsps[c].active){o2("socket %s is still active, skipping close",c);return}this._close()}_packet(n){o2("writing packet %j",n);let s=this.encoder.encode(n);for(let c=0;c<s.length;c++)this.engine.write(s[c],n.options)}cleanup(){o2("cleanup"),this.subs.forEach(n=>n()),this.subs.length=0,this.decoder.destroy()}_close(){o2("disconnect"),this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(n,s){var c;o2("closed due to %s",n),this.cleanup(),(c=this.engine)===null||c===void 0||c.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",n,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let n=this;if(this.backoff.attempts>=this._reconnectionAttempts)o2("reconnect failed"),this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let s=this.backoff.duration();o2("will wait %dms before reconnect attempt",s),this._reconnecting=!0;let c=this.setTimeoutFn(()=>{n.skipReconnect||(o2("attempting reconnect"),this.emitReserved("reconnect_attempt",n.backoff.attempts),!n.skipReconnect&&n.open(u=>{u?(o2("reconnect attempt error"),n._reconnecting=!1,n.reconnect(),this.emitReserved("reconnect_error",u)):(o2("reconnect success"),n.onreconnect())}))},s);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}}onreconnect(){let n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}};t($_t,"Manager");var sre=$_t;var Hcr=Da(nre(),1);var qcr=(0,Hcr.default)("socket.io-client"),che={};function lhe(i,n){typeof i=="object"&&(n=i,i=void 0),n=n||{};let s=Bcr(i,n.path||"/socket.io"),c=s.source,u=s.id,_=s.path,h=che[u]&&_ in che[u].nsps,b=n.forceNew||n["force new connection"]||n.multiplex===!1||h,S;return b?(qcr("ignoring socket cache for %s",c),S=new sre(c,n)):(che[u]||(qcr("new io instance for %s",c),che[u]=new sre(c,n)),S=che[u]),s.query&&!n.query&&(n.query=s.queryKey),S.socket(s.path,n)}t(lhe,"lookup");Object.assign(lhe,{Manager:sre,Socket:ire,io:lhe,connect:lhe});var y5e={URL:"http://localhost:3000",NAMESPACE:"auto-recovery",RECONNECTION_ATTEMPTS:5,RECONNECTION_DELAY:1e3},W_t=class W_t{constructor(n={}){this.socket=null;this.connectionState="disconnected";this.connectionPromise=null;this.resolution=null;this.options=n,this.url=n.url||y5e.URL,this.namespace=n.namespace||y5e.NAMESPACE,this.initializationPromise=this.createInitializationPromise()}createInitializationPromise(){return new Promise((n,s)=>{this.resolveInitialization=c=>n(c),this.rejectInitialization=c=>s(c)}).then(n=>(this.resolution=n,this.log("\u2705 Client initialization successful"),n),n=>{throw this.resolution=n,this.logError("\u274C Client initialization failed:",n),n}).finally(()=>{this.disconnect()})}defineHandlers(n){return n}async startSession(n,s,c){try{if(await this.connect(),this.emit(n,s,u=>{this.resolveInitialization(u)}),c&&c>0){let u=new Promise((_,h)=>{setTimeout(()=>{h(new Error(`Session initialization timed out after ${c}ms`))},c)});return Promise.race([this.initializationPromise,u])}return this.initializationPromise}catch(u){throw this.logError("\u274C Failed to start session:",u),this.rejectInitialization(u),u}}isConnected(){var n;return((n=this.socket)==null?void 0:n.connected)||!1}getConnectionState(){return this.connectionState}success(n){return{success:!0,data:n}}error(n){return{success:!1,error:n}}log(n,...s){this.options.verbose&&console.log(`[${this.namespace}] ${n}`,...s)}logError(n,...s){this.options.verbose&&console.error(`[${this.namespace}] ${n}`,...s)}async connect(){var n;if(this.connectionPromise)return this.connectionPromise;if(this.connectionState==="connected"&&((n=this.socket)!=null&&n.connected))return Promise.resolve();this.connectionState="connecting",this.connectionPromise=this.establishConnection();try{await this.connectionPromise,this.connectionState="connected"}catch(s){throw this.connectionState="disconnected",this.connectionPromise=null,s}return this.connectionPromise}establishConnection(){return new Promise((n,s)=>{let c=!1;try{let u=`${this.url}/${this.namespace}`;this.log(`\u{1F517} Connecting to socket at: ${u}`),this.socket=lhe(u,{autoConnect:!0,reconnection:!0,reconnectionAttempts:y5e.RECONNECTION_ATTEMPTS,reconnectionDelay:y5e.RECONNECTION_DELAY,...this.options.path&&{path:this.options.path}}),this.setupConnectionHandlers(n,s,c)}catch(u){this.logError("\u274C Failed to create socket connection:",u),c||s(u)}})}setupConnectionHandlers(n,s,c){if(!this.socket)return;let u={resolve:n,reject:s,connectionResolved:c};this.socket.on("connect",()=>this.handleConnect(u)),this.socket.on("reconnect",()=>this.handleReconnect()),this.socket.on("connect_error",_=>this.handleConnectError(_,u)),this.socket.on("disconnect",_=>this.handleDisconnect(_,u)),this.socket.io.on("reconnect_attempt",_=>this.handleReconnectAttempt(_)),this.socket.io.on("reconnect_error",_=>this.handleReconnectError(_)),this.socket.io.on("reconnect_failed",()=>this.handleReconnectFailed(u))}handleConnect(n){this.log("\u2705 Connected to socket"),this.connectionState="connected",this.setupEventHandlers(),n.connectionResolved||(n.connectionResolved=!0,n.resolve())}handleReconnect(){this.log("\u2705 Reconnected to socket"),this.connectionState="connected"}handleConnectError(n,s){var c;this.logError("\u274C Connection error:",n),this.connectionState="disconnected",!s.connectionResolved&&((c=this.socket)==null?void 0:c.disconnected)!==!1&&(s.connectionResolved=!0,s.reject(n))}handleDisconnect(n,s){this.log("\u{1F50C} Disconnected from socket:",n),this.connectionState="disconnected";let c=new Error(`Socket disconnected: ${n}`),u=!1;this.resolution===null&&n==="io server disconnect"&&(this.rejectInitialization(c),u=!0),!s.connectionResolved&&(n==="io server disconnect"||n==="transport close")&&(s.connectionResolved=!0,s.reject(c)),!u&&this.resolution===null&&this.connectionState==="disconnected"&&this.rejectInitialization(c)}handleReconnectAttempt(n){this.log(`\u{1F504} Reconnection attempt #${n}`),this.connectionState="reconnecting"}handleReconnectError(n){this.logError("\u274C Reconnection attempt failed:",n)}handleReconnectFailed(n){this.logError("\u274C All reconnection attempts failed"),this.connectionState="disconnected",this.resolution===null&&this.rejectInitialization("All reconnection attempts failed"),n.connectionResolved||(n.connectionResolved=!0,n.reject(new Error("All reconnection attempts failed")))}setupEventHandlers(){if(!this.socket){this.logError("\u274C Cannot setup event handlers: socket is null");return}this.log("\u2705 Setting up event handlers"),this.socket.on("__call",this.handleGatewayCall.bind(this))}async handleGatewayCall(n,s){this.log(`\u{1F4E5} Gateway called method: ${n.key} with args:`,n.args);try{let c=this.validateGatewayCall(n);if(c){s(c);return}let u=this.handlers[n.key];if(!u){let h=`No handler registered for method: ${n.key}`;this.logError(`\u274C ${h}`),s(this.error(h));return}let _=await u(...n.args);s(this.success(_))}catch(c){this.logError("\u274C Error handling gateway call:",c),s(this.error(c.message||"Unknown error occurred"))}}validateGatewayCall(n){return n.key?Array.isArray(n.args)?null:(this.logError("\u274C Received call with invalid args"),this.error("Args must be an array")):(this.logError("\u274C Received call with undefined key"),this.error("Key is undefined"))}emit(n,s,c){if(!this.socket){this.logError("\u274C Cannot emit: socket is null");return}this.log(`\u{1F4E4} Emitting event: ${n}`),this.socket.emit(n,s,u=>{c(u)})}disconnect(){this.connectionState!=="shutting_down"&&(this.connectionState="shutting_down",this.log("\u{1F50C} Initiating disconnect"),this.socket&&(this.socket.disconnect(),this.socket=null),this.connectionPromise=null,this.connectionState="disconnected",this.log("\u2705 Disconnected successfully"))}};t(W_t,"AbstractClient");var A5e=W_t;var Gcr,Ycr,Zcr,Kcr,Xcr,elr,tlr,rlr,b5e=class b5e extends(rlr=A5e,tlr=Gh.names.getState,elr=Gh.names.invokeCode,Xcr=Gh.names.final_result,Kcr=Gh.names.wait,Zcr=Gh.names.getElementScreenshot,Ycr=Gh.names.listPages,Gcr=Gh.names.switchPage,rlr){constructor(s,c){super({verbose:gc.testRun.autoRecovery.verboseConsoleLog,url:c.config.apiURL,namespace:"auto-recovery",path:"/auto-recovery/socket.io"});this.utils=s;this.initData=c;this.stepsThoughts=[];this.handlers=this.defineHandlers({callLangChainTool:t(async(s,c)=>{if(!this[s])throw new Error(`Tool ${s} not found`);return c.thought&&this.stepsThoughts.push(c.thought),await this[s].invoke(c)},"callLangChainTool"),getStatus:t(async s=>({sessionId:s,status:"active",data:{message:"Status retrieved successfully"}}),"getStatus")});this[tlr]=Q5.buildTool(Gh,Gh.names.getState,async s=>this.getStateHandler(s));this[elr]=Q5.buildTool(Gh,Gh.names.invokeCode,async s=>this.invokeCodeHandler(s));this[Xcr]=Q5.buildTool(Gh,Gh.names.final_result,async s=>this.finalResultHandler(s));this[Kcr]=Q5.buildTool(Gh,Gh.names.wait,async s=>this.waitHandler(s));this[Zcr]=Q5.buildTool(Gh,Gh.names.getElementScreenshot,async s=>this.getElementScreenshotHandler(s));this[Ycr]=Q5.buildTool(Gh,Gh.names.listPages,async s=>this.listPagesHandler(s));this[Gcr]=Q5.buildTool(Gh,Gh.names.switchPage,async s=>this.switchPageHandler(s))}async init(){let s={...this.initData,version:Gh.version};return await this.startSession("initialize",s).catch(c=>{this.utils.analytics.ARError({error:c.message});let u="Auto-Recovery attempt finished unsuccessfully";return this.utils.createChecksumStep({title:u,withError:!0}),this.utils.addAutoRecoveryErrorToReport(u,!1),{finalThought:u,stepsThoughts:[],result:"failed"}})}static async build(s){let c=await s.buildFallbackData();return new b5e(s,c)}async invokeCodeHandler(s){let c,u=this.utils.activePageGuid,h=!!(s.pageId&&s.pageId!==u?await this.utils.getPageById(s.pageId):void 0);return await this.utils.runConditionallyWithinStep(!0,s.thought||"Invoke Code",async()=>{try{h&&await this.utils.setActivePage(s.pageId);let b=await this.utils.invokeCode(s.code);this.utils.createChecksumStep({title:"Code Invoked Successfully"}),c={success:!0,invokeCodeResult:`invokeCodeResult: ${b.result}`,appState:(await this.utils.buildFallbackData()).applicationState,actionEffects:b.effects}}catch(b){c={success:!1,invokeCodeResult:`Error while invoking code: ${b}`,appState:(await this.utils.buildFallbackData()).applicationState}}finally{if(h&&u)try{await this.utils.setActivePage(u)}catch(b){console.warn("Failed to switch back to original page:",b)}}}),c}async getStateHandler(s){return this.utils.createChecksumStep({title:s.thought}),this.utils.analytics.ARGetState(s.thought),{success:!0,appState:await this.utils.captureApplicationState(s.pageId,s.includeAllPages)}}async finalResultHandler(s){let c=s.result==="pass",u=this.initData.type==="assertion"?c?"soft_assertion":"hard_assertion":c?"finish":"failed",_={finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts};await Promise.resolve(),this.resolveInitialization(_);try{this.utils.analytics.ARFinalResult({finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts})}catch(h){console.warn("Failed to record auto-recovery final-result analytics:",h)}try{this.utils.addAutoRecoveryErrorToReport(s.thought,c)}catch(h){console.warn("Failed to add auto-recovery result to report:",h)}}async getElementScreenshotHandler(s){return{success:!0,screenshot:await this.utils.getScreenshotForElement(s.checksumId)}}async waitHandler(s){await new Promise(u=>setTimeout(u,s.time||5e3));let c=await this.utils.buildFallbackData();return{success:!0,waitResult:`waited for ${s.time} seconds, the current HTML of the application after the wait is: ${c.applicationState.reducedHTML}`}}async listPagesHandler(s){s.thought&&this.utils.createChecksumStep({title:s.thought});let c=await this.utils.pageInteractor.getTabsInfo(),u=c.map((h,b)=>`${b+1}. ${h.title||"Untitled"} (${h.url})
736
736
  - Page ID: ${h.id}
737
737
  - Active: ${h.active?"Yes":"No"}
738
738
  - New: ${h.new?"Yes":"No"}${h.lastAction?`
package/index.js CHANGED
@@ -743,7 +743,7 @@ Details: ${ue.message}`),GKt(ue)&&(Se=`${Se}
743
743
  ${vke.prettifyError(ue)}`),new Cpe(Se,JSON.stringify(n))}else{let ue=Mm(u,this.schema);if(!ue.valid){let Se="Received tool input did not match expected schema";throw this.verboseParsingErrors&&(Se=`${Se}
744
744
  Details: ${ue.errors.map(Ct=>`${Ct.keywordLocation}: ${Ct.error}`).join(`
745
745
  `)}`),new Cpe(Se,JSON.stringify(n))}_=u}let g=QTe(s),E=W8.configure(g.callbacks,this.callbacks,g.tags||c,this.tags,g.metadata,this.metadata,{verbose:this.verbose}),x;EJ(n)&&(x=n.id),!x&&zqt(g)&&(x=g.toolCall.id);let P=await(E==null?void 0:E.handleToolStart(this.toJSON(),typeof n=="string"?n:JSON.stringify(n),g.runId,void 0,void 0,void 0,g.runName,x));delete g.runId;let M;try{let ue=await this._call(_,P,g);M=slt(ue)?await GXt(ue,async Se=>{try{await(P==null?void 0:P.handleToolEvent(Se))}catch(Ct){await(P==null?void 0:P.handleToolError(Ct))}}):ue}catch(ue){throw await(P==null?void 0:P.handleToolError(ue)),ue}let X,W;if(this.responseFormat==="content_and_artifact")if(Array.isArray(M)&&M.length===2)[X,W]=M;else throw new Error(`Tool response format is "content_and_artifact" but the output was not a two-tuple.
746
- Result: ${JSON.stringify(M)}`);else X=M;let ce=i0n({content:X,artifact:W,toolCallId:x,name:this.name,metadata:this.metadata});return await(P==null?void 0:P.handleToolEnd(ce)),ce}},t(fee,"StructuredTool"),fee),pee,t0n=(pee=class extends vtr{schema=il.object({input:il.string().optional()}).transform(n=>n.input);constructor(n){super(n)}call(n,s){let c=typeof n=="string"||n==null?{input:n}:n;return super.call(c,s)}},t(pee,"Tool"),pee),dee,r0n=(dee=class extends t0n{static lc_name(){return"DynamicTool"}name;description;func;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect}async call(n,s){let c=QTe(s);return c.runName===void 0&&(c.runName=this.name),super.call(n,c)}_call(n,s,c){return this.func(n,s,c)}},t(dee,"DynamicTool"),dee),_ee,n0n=(_ee=class extends vtr{static lc_name(){return"DynamicStructuredTool"}description;func;schema;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect,this.schema=n.schema}async call(n,s,c){let u=QTe(s);return u.runName===void 0&&(u.runName=this.name),super.call(n,u,c)}_call(n,s,c){return this.func(n,s,c)}},t(_ee,"DynamicStructuredTool"),_ee);function nut(i,n){var g;let s=Pxe(n.schema),c=Lde(n.schema);if(!n.schema||s||c)return new r0n({...n,description:n.description??((g=n.schema)==null?void 0:g.description)??`${n.name} tool`,func:t(async(E,x,P)=>new Promise((M,X)=>{let W=w0(P,{callbacks:x==null?void 0:x.getChild()});Vv.runWithConfig(Ow(W),async()=>{try{M(i(E,W))}catch(ce){X(ce)}})}),"func")});let u=n.schema,_=n.description??n.schema.description??`${n.name} tool`;return new n0n({...n,description:_,schema:u,func:t(async(E,x,P)=>new Promise((M,X)=>{let W,ce=t(()=>{P!=null&&P.signal&&W&&P.signal.removeEventListener("abort",W)},"cleanup");P!=null&&P.signal&&(W=t(()=>{ce(),X(hO(P.signal))},"listener"),P.signal.addEventListener("abort",W,{once:!0}));let ue=w0(P,{callbacks:x==null?void 0:x.getChild()});Vv.runWithConfig(Ow(ue),async()=>{var Se;try{let Ct=await i(E,ue);if(slt(Ct)){M(Ct);return}if((Se=P==null?void 0:P.signal)!=null&&Se.aborted){ce();return}ce(),M(Ct)}catch(Ct){ce(),X(Ct)}})}),"func")})}t(nut,"tool");function i0n(i){let{content:n,artifact:s,toolCallId:c,metadata:u}=i;return c&&!bHt(n)?typeof n=="string"||Array.isArray(n)&&n.every(_=>typeof _=="object")?new VIe({status:"success",content:n,artifact:s,tool_call_id:c,name:i.name,metadata:u}):new VIe({status:"success",content:s0n(n),artifact:s,tool_call_id:c,name:i.name,metadata:u}):n}t(i0n,"_formatToolOutput");function s0n(i){try{return JSON.stringify(i)??""}catch{return`${i}`}}t(s0n,"_stringify");var dN=class dN{constructor(){this.toolsMap={}}get addTool(){return this._addTool||(this._addTool=this.buildAddToolFacade()),this._addTool}getToolNames(){return Object.keys(this.toolRecord.names)}get tools(){return this.toolsMap}buildAddToolFacade(){let n={},s=this.toolRecord.tools;for(let c of Object.keys(s))n[c]=u=>this._addSingleTool(c,u);return n}static describeTool(n,s){if(n instanceof il.ZodObject){let c={},u=n.shape;for(let _ of Object.keys(u)){let g=u[_],E=s==null?void 0:s[_];typeof E=="string"?c[_]=g.describe(E):E&&typeof E=="object"?c[_]=dN.describeTool(g,E):c[_]=g}return il.object(c).strict()}if(n instanceof il.ZodArray){let c=n.element;return s&&typeof s=="object"&&s.element?il.array(dN.describeTool(c,s.element)):n}return n instanceof il.ZodOptional?dN.describeTool(n.unwrap(),s).optional():n instanceof il.ZodNullable?dN.describeTool(n.unwrap(),s).nullable():typeof s=="string"?n.describe(s):n}_addSingleTool(n,s){let c=s.name??String(n),_=this.toolRecord.tools[n]._create({...s,name:c,params:s.params,handler:s.handler}),g=this.toolRecord.tools[n],E=dN.describeTool(g,s.params),P=nut(t(async M=>{let X=E.parse(M);return s.handler(X)},"validatedHandler"),{name:_.name,description:_.description,schema:E});return this.toolsMap[n]=P,P}_buildOne(n,s){return this._addSingleTool(n,{...s,name:String(n)})}static buildTool(n,s,c){let u=String(s),g=n.tools[s]._create({name:u,description:"",handler:c,params:{}}),E=n.tools[s],x=dN.describeTool(E,{});return nut(t(async X=>{let W=x.parse(X);return c(W)},"validatedHandler"),{name:g.name,description:g.description,schema:x})}};t(dN,"AbstractToolContainer");var e5=dN;var Eke=class Eke{constructor(n,s){this.version=n;let c={};for(let _ in s)c[_]=_;this.names=c;let u={};for(let _ in s){let g=s[_];Object.defineProperty(g,"name",{value:_,configurable:!1,enumerable:!0,writable:!1}),g._create=(E=>x=>{let P=x.name??E;return{...x,name:P}})(_),u[_]=g}this.tools=u}static create(n,s){return new Eke(n,s)}};t(Eke,"ToolProtocol");var bke=Eke;var Oh=bke.create("v1",{readFile:il.object({path:il.string()}),getState:il.object({thought:il.string(),pageId:il.string().optional(),includeAllPages:il.boolean().optional()}),invokeCode:il.object({code:il.string().refine(i=>{let n=i.trim();return n.includes("page.getByChecksumId(")||n.includes("page.getByChecksumId(")||n.startsWith("const ")||n.startsWith("let ")||n.startsWith("var ")||n.includes("=")||n.includes("variableStore.")},{message:"Code should use page.getByChecksumId() for element targeting, or be explicit variable assignments/function calls"}),thought:il.string(),pageId:il.string().optional()}),wait:il.object({time:il.number().optional()}),scroll:il.object({checksumId:il.string(),thought:il.string()}),final_result:il.object({result:il.enum(["pass","fail"]),thought:il.string(),visualAnalysis:il.string().optional()}),getElementScreenshot:il.object({checksumId:il.string(),thought:il.string()}),listPages:il.object({thought:il.string().optional()}),switchPage:il.object({pageId:il.string(),thought:il.string().optional()}),analyze:il.object({previousImmediateSteps:il.string(),currentFailingStep:il.string(),nextImmediateSteps:il.string(),testStepToStopAt:il.string()}),think:il.object({thought:il.string()})});var but=uc(Ctr(),1);var mx=Object.create(null);mx.open="0";mx.close="1";mx.ping="2";mx.pong="3";mx.message="4";mx.upgrade="5";mx.noop="6";var qde=Object.create(null);Object.keys(mx).forEach(i=>{qde[mx[i]]=i});var Hde={type:"error",data:"parser error"};var $de=t(({type:i,data:n},s,c)=>n instanceof ArrayBuffer||ArrayBuffer.isView(n)?c(s?n:"b"+Str(n,!0).toString("base64")):c(mx[i]+(n||"")),"encodePacket"),Str=t((i,n)=>Buffer.isBuffer(i)||i instanceof Uint8Array&&!n?i:i instanceof ArrayBuffer?Buffer.from(i):Buffer.from(i.buffer,i.byteOffset,i.byteLength),"toBuffer"),sut;function wtr(i,n){if(i.data instanceof ArrayBuffer||ArrayBuffer.isView(i.data))return n(Str(i.data,!1));$de(i,!0,s=>{sut||(sut=new TextEncoder),n(sut.encode(s))})}t(wtr,"encodePacketToBinary");var Gde=t((i,n)=>{if(typeof i!="string")return{type:"message",data:Itr(i,n)};let s=i.charAt(0);if(s==="b"){let c=Buffer.from(i.substring(1),"base64");return{type:"message",data:Itr(c,n)}}return qde[s]?i.length>1?{type:qde[s],data:i.substring(1)}:{type:qde[s]}:Hde},"decodePacket"),Itr=t((i,n)=>{switch(n){case"arraybuffer":return i instanceof ArrayBuffer?i:Buffer.isBuffer(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i.buffer;case"nodebuffer":default:return Buffer.isBuffer(i)?i:Buffer.from(i)}},"mapBinary");var Ttr="",xtr=t((i,n)=>{let s=i.length,c=new Array(s),u=0;i.forEach((_,g)=>{$de(_,!1,E=>{c[g]=E,++u===s&&n(c.join(Ttr))})})},"encodePayload"),ktr=t((i,n)=>{let s=i.split(Ttr),c=[];for(let u=0;u<s.length;u++){let _=Gde(s[u],n);if(c.push(_),_.type==="error")break}return c},"decodePayload");function Dtr(){return new TransformStream({transform(i,n){wtr(i,s=>{let c=s.length,u;if(c<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,c);else if(c<65536){u=new Uint8Array(3);let _=new DataView(u.buffer);_.setUint8(0,126),_.setUint16(1,c)}else{u=new Uint8Array(9);let _=new DataView(u.buffer);_.setUint8(0,127),_.setBigUint64(1,BigInt(c))}i.data&&typeof i.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(s)})}})}t(Dtr,"createPacketEncoderStream");var aut;function Cke(i){return i.reduce((n,s)=>n+s.length,0)}t(Cke,"totalLength");function Ske(i,n){if(i[0].length===n)return i.shift();let s=new Uint8Array(n),c=0;for(let u=0;u<n;u++)s[u]=i[0][c++],c===i[0].length&&(i.shift(),c=0);return i.length&&c<i[0].length&&(i[0]=i[0].slice(c)),s}t(Ske,"concatChunks");function Ntr(i,n){aut||(aut=new TextDecoder);let s=[],c=0,u=-1,_=!1;return new TransformStream({transform(g,E){for(s.push(g);;){if(c===0){if(Cke(s)<1)break;let x=Ske(s,1);_=(x[0]&128)===128,u=x[0]&127,u<126?c=3:u===126?c=1:c=2}else if(c===1){if(Cke(s)<2)break;let x=Ske(s,2);u=new DataView(x.buffer,x.byteOffset,x.length).getUint16(0),c=3}else if(c===2){if(Cke(s)<8)break;let x=Ske(s,8),P=new DataView(x.buffer,x.byteOffset,x.length),M=P.getUint32(0);if(M>Math.pow(2,21)-1){E.enqueue(Hde);break}u=M*Math.pow(2,32)+P.getUint32(4),c=3}else{if(Cke(s)<u)break;let x=Ske(s,u);E.enqueue(Gde(_?x:aut.decode(x),n)),c=0}if(u===0||u>i){E.enqueue(Hde);break}}}})}t(Ntr,"createPacketDecoderStream");var out=4;var Htr=uc(hV(),1);var _N=process.nextTick,Ib=global,Btr="nodebuffer";function Ftr(){return new cut}t(Ftr,"createCookieJar");function l0n(i){let n=i.split("; "),s=n[0].indexOf("=");if(s===-1)return;let c=n[0].substring(0,s).trim();if(!c.length)return;let u=n[0].substring(s+1).trim();u.charCodeAt(0)===34&&(u=u.slice(1,-1));let _={name:c,value:u};for(let g=1;g<n.length;g++){let E=n[g].split("=");if(E.length!==2)continue;let x=E[0].trim(),P=E[1].trim();switch(x){case"Expires":_.expires=new Date(P);break;case"Max-Age":let M=new Date;M.setUTCSeconds(M.getUTCSeconds()+parseInt(P,10)),_.expires=M;break;default:}}return _}t(l0n,"parse");var lut=class lut{constructor(){this._cookies=new Map}parseCookies(n){n&&n.forEach(s=>{let c=l0n(s);c&&this._cookies.set(c.name,c)})}get cookies(){let n=Date.now();return this._cookies.forEach((s,c)=>{var u;((u=s.expires)===null||u===void 0?void 0:u.getTime())<n&&this._cookies.delete(c)}),this._cookies.entries()}addCookies(n){let s=[];for(let[c,u]of this.cookies)s.push(`${c}=${u.value}`);s.length&&(n.setDisableHeaderCheck(!0),n.setRequestHeader("cookie",s.join("; ")))}appendCookies(n){for(let[s,c]of this.cookies)n.append("cookie",`${s}=${c.value}`)}};t(lut,"CookieJar");var cut=lut;function wke(i,...n){return n.reduce((s,c)=>(i.hasOwnProperty(c)&&(s[c]=i[c]),s),{})}t(wke,"pick");var u0n=Ib.setTimeout,f0n=Ib.clearTimeout;function mN(i,n){n.useNativeTimers?(i.setTimeoutFn=u0n.bind(Ib),i.clearTimeoutFn=f0n.bind(Ib)):(i.setTimeoutFn=Ib.setTimeout.bind(Ib),i.clearTimeoutFn=Ib.clearTimeout.bind(Ib))}t(mN,"installTimerFunctions");var p0n=1.33;function Rtr(i){return typeof i=="string"?d0n(i):Math.ceil((i.byteLength||i.size)*p0n)}t(Rtr,"byteLength");function d0n(i){let n=0,s=0;for(let c=0,u=i.length;c<u;c++)n=i.charCodeAt(c),n<128?s+=1:n<2048?s+=2:n<55296||n>=57344?s+=3:(c++,s+=4);return s}t(d0n,"utf8Length");function Ike(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}t(Ike,"randomString");function Otr(i){let n="";for(let s in i)i.hasOwnProperty(s)&&(n.length&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(i[s]));return n}t(Otr,"encode");function Mtr(i){let n={},s=i.split("&");for(let c=0,u=s.length;c<u;c++){let _=s[c].split("=");n[decodeURIComponent(_[0])]=decodeURIComponent(_[1])}return n}t(Mtr,"decode");var $tr=uc(AV(),1);var O0n=(0,$tr.default)("engine.io-client:transport"),hut=class hut extends Error{constructor(n,s,c){super(n),this.description=s,this.context=c,this.type="TransportError"}};t(hut,"TransportError");var Nke=hut,gut=class gut extends Htr.Emitter{constructor(n){super(),this.writable=!1,mN(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,s,c){return super.emitReserved("error",new Nke(n,s,c)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(n){this.readyState==="open"?this.write(n):O0n("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(n){let s=Gde(n,this.socket.binaryType);this.onPacket(s)}onPacket(n){super.emitReserved("packet",n)}onClose(n){this.readyState="closed",super.emitReserved("close",n)}pause(n){}createUri(n,s={}){return n+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){let n=this.opts.hostname;return n.indexOf(":")===-1?n:"["+n+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(n){let s=Otr(n);return s.length?"?"+s:""}};t(gut,"Transport");var hN=gut;var Gtr=uc(AV(),1);var hx=(0,Gtr.default)("engine.io-client:polling"),Aut=class Aut extends hN{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(n){this.readyState="pausing";let s=t(()=>{hx("paused"),this.readyState="paused",n()},"pause");if(this._polling||!this.writable){let c=0;this._polling&&(hx("we are currently polling - waiting to pause"),c++,this.once("pollComplete",function(){hx("pre-pause polling complete"),--c||s()})),this.writable||(hx("we are currently writing - waiting to pause"),c++,this.once("drain",function(){hx("pre-pause writing complete"),--c||s()}))}else s()}_poll(){hx("polling"),this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){hx("polling got data %s",n);let s=t(c=>{if(this.readyState==="opening"&&c.type==="open"&&this.onOpen(),c.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(c)},"callback");ktr(n,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this._poll():hx('ignoring poll - transport state "%s"',this.readyState))}doClose(){let n=t(()=>{hx("writing close packet"),this.write([{type:"close"}])},"close");this.readyState==="open"?(hx("transport open - closing"),n()):(hx("transport not open - deferring close"),this.once("open",n))}write(n){this.writable=!1,xtr(n,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let n=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=Ike()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(n,s)}};t(Aut,"Polling");var Yde=Aut;var Xtr=uc(hV(),1);var Ytr=!1;try{Ytr=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Ztr=Ytr;var err=uc(AV(),1);var yut=(0,err.default)("engine.io-client:polling");function M0n(){}t(M0n,"empty");var vut=class vut extends Yde{constructor(n){if(super(n),typeof location<"u"){let s=location.protocol==="https:",c=location.port;c||(c=s?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||c!==n.port}}doWrite(n,s){let c=this.request({method:"POST",data:n});c.on("success",s),c.on("error",(u,_)=>{this.onError("xhr post error",u,_)})}doPoll(){yut("xhr poll");let n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(s,c)=>{this.onError("xhr poll error",s,c)}),this.pollXhr=n}};t(vut,"BaseXHR");var Pke=vut,yee=class yee extends Xtr.Emitter{constructor(n,s,c){super(),this.createRequest=n,mN(this,c),this._opts=c,this._method=c.method||"GET",this._uri=s,this._data=c.data!==void 0?c.data:null,this._create()}_create(){var n;let s=wke(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;let c=this._xhr=this.createRequest(s);try{yut("xhr open %s: %s",this._method,this._uri),c.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){c.setDisableHeaderCheck&&c.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&c.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{c.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{c.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(c),"withCredentials"in c&&(c.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(c.timeout=this._opts.requestTimeout),c.onreadystatechange=()=>{var u;c.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(c.getResponseHeader("set-cookie"))),c.readyState===4&&(c.status===200||c.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof c.status=="number"?c.status:0)},0))},yut("xhr data %s",this._data),c.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=yee.requestsCount++,yee.requests[this._index]=this)}_onError(n){this.emitReserved("error",n,this._xhr),this._cleanup(!0)}_cleanup(n){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=M0n,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete yee.requests[this._index],this._xhr=null}}_onLoad(){let n=this._xhr.responseText;n!==null&&(this.emitReserved("data",n),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};t(yee,"Request");var gN=yee;gN.requestsCount=0;gN.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Ktr);else if(typeof addEventListener=="function"){let i="onpagehide"in Ib?"pagehide":"unload";addEventListener(i,Ktr,!1)}}function Ktr(){for(let i in gN.requests)gN.requests.hasOwnProperty(i)&&gN.requests[i].abort()}t(Ktr,"unloadHandler");var $Yn=function(){let i=L0n({xdomain:!1});return i&&i.responseType!==null}();function L0n(i){let n=i.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||Ztr))return new XMLHttpRequest}catch{}if(!n)try{return new Ib[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}t(L0n,"newRequest");var Q0n=but.default||but,Eut=class Eut extends Pke{request(n={}){var s;return Object.assign(n,{xd:this.xd,cookieJar:(s=this.socket)===null||s===void 0?void 0:s._cookieJar},this.opts),new gN(c=>new Q0n(c),this.uri(),n)}};t(Eut,"XHR");var vee=Eut;var GAn=uc(irr(),1),YAn=uc(Out(),1),ZAn=uc(Lut(),1),Kut=uc(Gut(),1),KAn=uc(tnr(),1);var rnr=uc(AV(),1);var eyn=(0,rnr.default)("engine.io-client:websocket"),tyn=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Xut=class Xut extends hN{get name(){return"websocket"}doOpen(){let n=this.uri(),s=this.opts.protocols,c=tyn?{}:wke(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(c.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,s,c)}catch(u){return this.emitReserved("error",u)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=n=>this.onClose({description:"websocket connection closed",context:n}),this.ws.onmessage=n=>this.onData(n.data),this.ws.onerror=n=>this.onError("websocket error",n)}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;$de(c,this.supportsBinary,_=>{try{this.doWrite(c,_)}catch{eyn("websocket closed before onclose event")}u&&_N(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let n=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=Ike()),this.supportsBinary||(s.b64=1),this.createUri(n,s)}};t(Xut,"BaseWS");var qke=Xut,FZn=Ib.WebSocket||Ib.MozWebSocket;var eft=class eft extends qke{createSocket(n,s,c){var u;if(!((u=this.socket)===null||u===void 0)&&u._cookieJar){c.headers=c.headers||{},c.headers.cookie=typeof c.headers.cookie=="string"?[c.headers.cookie]:c.headers.cookie||[];for(let[_,g]of this.socket._cookieJar.cookies)c.headers.cookie.push(`${_}=${g.value}`)}return new Kut.default(n,s,c)}doWrite(n,s){let c={};n.options&&(c.compress=n.options.compress),this.opts.perMessageDeflate&&(typeof s=="string"?Buffer.byteLength(s):s.length)<this.opts.perMessageDeflate.threshold&&(c.compress=!1),this.ws.send(s,c)}};t(eft,"WS");var wee=eft;var nnr=uc(AV(),1);var o_e=(0,nnr.default)("engine.io-client:webtransport"),tft=class tft extends hN{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(n){return this.emitReserved("error",n)}this._transport.closed.then(()=>{o_e("transport closed gracefully"),this.onClose()}).catch(n=>{o_e("transport closed due to %s",n),this.onError("webtransport error",n)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(n=>{let s=Ntr(Number.MAX_SAFE_INTEGER,this.socket.binaryType),c=n.readable.pipeThrough(s).getReader(),u=Dtr();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();let _=t(()=>{c.read().then(({done:E,value:x})=>{if(E){o_e("session is closed");return}o_e("received chunk: %o",x),this.onPacket(x),_()}).catch(E=>{o_e("an error occurred while reading: %s",E)})},"read");_();let g={type:"open"};this.query.sid&&(g.data=`{"sid":"${this.query.sid}"}`),this._writer.write(g).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;this._writer.write(c).then(()=>{u&&_N(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}};t(tft,"WT");var Iee=tft;var rft={websocket:wee,webtransport:Iee,polling:vee};var ryn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,nyn=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Tee(i){if(i.length>8e3)throw"URI too long";let n=i,s=i.indexOf("["),c=i.indexOf("]");s!=-1&&c!=-1&&(i=i.substring(0,s)+i.substring(s,c).replace(/:/g,";")+i.substring(c,i.length));let u=ryn.exec(i||""),_={},g=14;for(;g--;)_[nyn[g]]=u[g]||"";return s!=-1&&c!=-1&&(_.source=n,_.host=_.host.substring(1,_.host.length-1).replace(/;/g,":"),_.authority=_.authority.replace("[","").replace("]","").replace(/;/g,":"),_.ipv6uri=!0),_.pathNames=iyn(_,_.path),_.queryKey=syn(_,_.query),_}t(Tee,"parse");function iyn(i,n){let s=/\/{2,9}/g,c=n.replace(s,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&c.splice(0,1),n.slice(-1)=="/"&&c.splice(c.length-1,1),c}t(iyn,"pathNames");function syn(i,n){let s={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,u,_){u&&(s[u]=_)}),s}t(syn,"queryKey");var inr=uc(hV(),1);var snr=uc(AV(),1);var M_=(0,snr.default)("engine.io-client:socket"),nft=typeof addEventListener=="function"&&typeof removeEventListener=="function",c_e=[];nft&&addEventListener("offline",()=>{M_("closing %d connection(s) because the network was lost",c_e.length),c_e.forEach(i=>i())},!1);var xee=class xee extends inr.Emitter{constructor(n,s){if(super(),this.binaryType=Btr,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,n&&typeof n=="object"&&(s=n,n=null),n){let c=Tee(n);s.hostname=c.host,s.secure=c.protocol==="https"||c.protocol==="wss",s.port=c.port,c.query&&(s.query=c.query)}else s.host&&(s.hostname=Tee(s.host).host);mN(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(c=>{let u=c.prototype.name;this.transports.push(u),this._transportsByName[u]=c}),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},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Mtr(this.opts.query)),nft&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(M_("adding listener for the 'offline' event"),this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},c_e.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=Ftr()),this._open()}createTransport(n){M_('creating transport "%s"',n);let s=Object.assign({},this.opts.query);s.EIO=out,s.transport=n,this.id&&(s.sid=this.id);let c=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[n]);return M_("options: %j",c),new this._transportsByName[n](c)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let n=this.opts.rememberUpgrade&&xee.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let s=this.createTransport(n);s.open(),this.setTransport(s)}setTransport(n){M_("setting transport %s",n.name),this.transport&&(M_("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=n,n.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){M_("socket open"),this.readyState="open",xee.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(M_('socket receive: type "%s", data "%s"',n.type,n.data),this.emitReserved("packet",n),this.emitReserved("heartbeat"),n.type){case"open":this.onHandshake(JSON.parse(n.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let s=new Error("server error");s.code=n.data,this._onError(s);break;case"message":this.emitReserved("data",n.data),this.emitReserved("message",n.data);break}else M_('packet received with socket readyState "%s"',this.readyState)}onHandshake(n){this.emitReserved("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this._pingInterval=n.pingInterval,this._pingTimeout=n.pingTimeout,this._maxPayload=n.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let n=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+n,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},n),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){let n=this._getWritablePackets();M_("flushing %d packets in socket",n.length),this.transport.send(n),this._prevBufferLen=n.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let c=0;c<this.writeBuffer.length;c++){let u=this.writeBuffer[c].data;if(u&&(s+=Rtr(u)),c>0&&s>this._maxPayload)return M_("only send %d out of %d packets",c,this.writeBuffer.length),this.writeBuffer.slice(0,c);s+=2}return M_("payload size is %d (max: %d)",s,this._maxPayload),this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let n=Date.now()>this._pingTimeoutTime;return n&&(M_("throttled timer detected, scheduling connection close"),this._pingTimeoutTime=0,_N(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,s,c){return this._sendPacket("message",n,s,c),this}send(n,s,c){return this._sendPacket("message",n,s,c),this}_sendPacket(n,s,c,u){if(typeof s=="function"&&(u=s,s=void 0),typeof c=="function"&&(u=c,c=null),this.readyState==="closing"||this.readyState==="closed")return;c=c||{},c.compress=c.compress!==!1;let _={type:n,data:s,options:c};this.emitReserved("packetCreate",_),this.writeBuffer.push(_),u&&this.once("flush",u),this.flush()}close(){let n=t(()=>{this._onClose("forced close"),M_("socket closing - telling transport to close"),this.transport.close()},"close"),s=t(()=>{this.off("upgrade",s),this.off("upgradeError",s),n()},"cleanupAndClose"),c=t(()=>{this.once("upgrade",s),this.once("upgradeError",s)},"waitForUpgrade");return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?c():n()}):this.upgrading?c():n()),this}_onError(n){if(M_("socket error %j",n),xee.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return M_("trying next transport"),this.transports.shift(),this._open();this.emitReserved("error",n),this._onClose("transport error",n)}_onClose(n,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(M_('socket close with reason: "%s"',n),this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),nft&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let c=c_e.indexOf(this._offlineEventListener);c!==-1&&(M_("removing listener for the 'offline' event"),c_e.splice(c,1))}this.readyState="closed",this.id=null,this.emitReserved("close",n,s),this.writeBuffer=[],this._prevBufferLen=0}}};t(xee,"SocketWithoutUpgrade");var CV=xee;CV.protocol=out;var ift=class ift extends CV{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade){M_("starting upgrade probes");for(let n=0;n<this._upgrades.length;n++)this._probe(this._upgrades[n])}}_probe(n){M_('probing transport "%s"',n);let s=this.createTransport(n),c=!1;CV.priorWebsocketSuccess=!1;let u=t(()=>{c||(M_('probe transport "%s" opened',n),s.send([{type:"ping",data:"probe"}]),s.once("packet",X=>{if(!c)if(X.type==="pong"&&X.data==="probe"){if(M_('probe transport "%s" pong',n),this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;CV.priorWebsocketSuccess=s.name==="websocket",M_('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{c||this.readyState!=="closed"&&(M_("changing transport and sending upgrade packet"),M(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{M_('probe transport "%s" failed',n);let W=new Error("probe error");W.transport=s.name,this.emitReserved("upgradeError",W)}}))},"onTransportOpen");function _(){c||(c=!0,M(),s.close(),s=null)}t(_,"freezeTransport");let g=t(X=>{let W=new Error("probe error: "+X);W.transport=s.name,_(),M_('probe transport "%s" failed because of error: %s',n,X),this.emitReserved("upgradeError",W)},"onerror");function E(){g("transport closed")}t(E,"onTransportClose");function x(){g("socket closed")}t(x,"onclose");function P(X){s&&X.name!==s.name&&(M_('"%s" works - aborting "%s"',X.name,s.name),_())}t(P,"onupgrade");let M=t(()=>{s.removeListener("open",u),s.removeListener("error",g),s.removeListener("close",E),this.off("close",x),this.off("upgrading",P)},"cleanup");s.once("open",u),s.once("error",g),s.once("close",E),this.once("close",x),this.once("upgrading",P),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{c||s.open()},200):s.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){let s=[];for(let c=0;c<n.length;c++)~this.transports.indexOf(n[c])&&s.push(n[c]);return s}};t(ift,"SocketWithUpgrade");var Hke=ift,sft=class sft extends Hke{constructor(n,s={}){let c=typeof n=="object"?n:s;(!c.transports||c.transports&&typeof c.transports[0]=="string")&&(c.transports=(c.transports||["polling","websocket","webtransport"]).map(u=>rft[u]).filter(u=>!!u)),super(n,c)}};t(sft,"Socket");var kee=sft;var lKn=kee.protocol;var fnr=uc(DO(),1);var unr=(0,fnr.default)("socket.io-client:url");function pnr(i,n="",s){let c=i;s=s||typeof location<"u"&&location,i==null&&(i=s.protocol+"//"+s.host),typeof i=="string"&&(i.charAt(0)==="/"&&(i.charAt(1)==="/"?i=s.protocol+i:i=s.host+i),/^(https?|wss?):\/\//.test(i)||(unr("protocol-less url %s",i),typeof s<"u"?i=s.protocol+"//"+i:i="https://"+i),unr("parse %s",i),c=Tee(i)),c.port||(/^(http|ws)$/.test(c.protocol)?c.port="80":/^(http|ws)s$/.test(c.protocol)&&(c.port="443")),c.path=c.path||"/";let _=c.host.indexOf(":")!==-1?"["+c.host+"]":c.host;return c.id=c.protocol+"://"+_+":"+c.port+n,c.href=c.protocol+"://"+_+(s&&s.port===c.port?"":":"+c.port),c}t(pnr,"url");var _ft={};OT(_ft,{Decoder:()=>pft,Encoder:()=>fft,PacketType:()=>Mu,isPacketValid:()=>Nyn,protocol:()=>ynr});var hnr=uc(hV(),1);var Syn=typeof ArrayBuffer=="function",wyn=t(i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i.buffer instanceof ArrayBuffer,"isView"),dnr=Object.prototype.toString,Iyn=typeof Blob=="function"||typeof Blob<"u"&&dnr.call(Blob)==="[object BlobConstructor]",Tyn=typeof File=="function"||typeof File<"u"&&dnr.call(File)==="[object FileConstructor]";function u_e(i){return Syn&&(i instanceof ArrayBuffer||wyn(i))||Iyn&&i instanceof Blob||Tyn&&i instanceof File}t(u_e,"isBinary");function l_e(i,n){if(!i||typeof i!="object")return!1;if(Array.isArray(i)){for(let s=0,c=i.length;s<c;s++)if(l_e(i[s]))return!0;return!1}if(u_e(i))return!0;if(i.toJSON&&typeof i.toJSON=="function"&&arguments.length===1)return l_e(i.toJSON(),!0);for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)&&l_e(i[s]))return!0;return!1}t(l_e,"hasBinary");function _nr(i){let n=[],s=i.data,c=i;return c.data=cft(s,n),c.attachments=n.length,{packet:c,buffers:n}}t(_nr,"deconstructPacket");function cft(i,n){if(!i)return i;if(u_e(i)){let s={_placeholder:!0,num:n.length};return n.push(i),s}else if(Array.isArray(i)){let s=new Array(i.length);for(let c=0;c<i.length;c++)s[c]=cft(i[c],n);return s}else if(typeof i=="object"&&!(i instanceof Date)){let s={};for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&(s[c]=cft(i[c],n));return s}return i}t(cft,"_deconstructPacket");function mnr(i,n){return i.data=lft(i.data,n),delete i.attachments,i}t(mnr,"reconstructPacket");function lft(i,n){if(!i)return i;if(i&&i._placeholder===!0){if(typeof i.num=="number"&&i.num>=0&&i.num<n.length)return n[i.num];throw new Error("illegal attachments")}else if(Array.isArray(i))for(let s=0;s<i.length;s++)i[s]=lft(i[s],n);else if(typeof i=="object")for(let s in i)Object.prototype.hasOwnProperty.call(i,s)&&(i[s]=lft(i[s],n));return i}t(lft,"_reconstructPacket");var gnr=uc(DO(),1);var uft=(0,gnr.default)("socket.io-parser"),Anr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ynr=5,Mu;(function(i){i[i.CONNECT=0]="CONNECT",i[i.DISCONNECT=1]="DISCONNECT",i[i.EVENT=2]="EVENT",i[i.ACK=3]="ACK",i[i.CONNECT_ERROR=4]="CONNECT_ERROR",i[i.BINARY_EVENT=5]="BINARY_EVENT",i[i.BINARY_ACK=6]="BINARY_ACK"})(Mu||(Mu={}));var mft=class mft{constructor(n){this.replacer=n}encode(n){return uft("encoding packet %j",n),(n.type===Mu.EVENT||n.type===Mu.ACK)&&l_e(n)?this.encodeAsBinary({type:n.type===Mu.EVENT?Mu.BINARY_EVENT:Mu.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let s=""+n.type;return(n.type===Mu.BINARY_EVENT||n.type===Mu.BINARY_ACK)&&(s+=n.attachments+"-"),n.nsp&&n.nsp!=="/"&&(s+=n.nsp+","),n.id!=null&&(s+=n.id),n.data!=null&&(s+=JSON.stringify(n.data,this.replacer)),uft("encoded %j as %s",n,s),s}encodeAsBinary(n){let s=_nr(n),c=this.encodeAsString(s.packet),u=s.buffers;return u.unshift(c),u}};t(mft,"Encoder");var fft=mft,Kke=class Kke extends hnr.Emitter{constructor(n){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof n=="function"?{reviver:n}:n)}add(n){let s;if(typeof n=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(n);let c=s.type===Mu.BINARY_EVENT;c||s.type===Mu.BINARY_ACK?(s.type=c?Mu.EVENT:Mu.ACK,this.reconstructor=new dft(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(u_e(n)||n.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(n),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+n)}decodeString(n){let s=0,c={type:Number(n.charAt(0))};if(Mu[c.type]===void 0)throw new Error("unknown packet type "+c.type);if(c.type===Mu.BINARY_EVENT||c.type===Mu.BINARY_ACK){let _=s+1;for(;n.charAt(++s)!=="-"&&s!=n.length;);let g=n.substring(_,s);if(g!=Number(g)||n.charAt(s)!=="-")throw new Error("Illegal attachments");let E=Number(g);if(!vnr(E)||E<0)throw new Error("Illegal attachments");if(E>this.opts.maxAttachments)throw new Error("too many attachments");c.attachments=E}if(n.charAt(s+1)==="/"){let _=s+1;for(;++s&&!(n.charAt(s)===","||s===n.length););c.nsp=n.substring(_,s)}else c.nsp="/";let u=n.charAt(s+1);if(u!==""&&Number(u)==u){let _=s+1;for(;++s;){let g=n.charAt(s);if(g==null||Number(g)!=g){--s;break}if(s===n.length)break}c.id=Number(n.substring(_,s+1))}if(n.charAt(++s)){let _=this.tryParse(n.substr(s));if(Kke.isPayloadValid(c.type,_))c.data=_;else throw new Error("invalid payload")}return uft("decoded %s as %j",n,c),c}tryParse(n){try{return JSON.parse(n,this.opts.reviver)}catch{return!1}}static isPayloadValid(n,s){switch(n){case Mu.CONNECT:return Zke(s);case Mu.DISCONNECT:return s===void 0;case Mu.CONNECT_ERROR:return typeof s=="string"||Zke(s);case Mu.EVENT:case Mu.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Anr.indexOf(s[0])===-1);case Mu.ACK:case Mu.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}};t(Kke,"Decoder");var pft=Kke,hft=class hft{constructor(n){this.packet=n,this.buffers=[],this.reconPack=n}takeBinaryData(n){if(this.buffers.push(n),this.buffers.length===this.reconPack.attachments){let s=mnr(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};t(hft,"BinaryReconstructor");var dft=hft;function xyn(i){return typeof i=="string"}t(xyn,"isNamespaceValid");var vnr=Number.isInteger||function(i){return typeof i=="number"&&isFinite(i)&&Math.floor(i)===i};function kyn(i){return i===void 0||vnr(i)}t(kyn,"isAckIdValid");function Zke(i){return Object.prototype.toString.call(i)==="[object Object]"}t(Zke,"isObject");function Dyn(i,n){switch(i){case Mu.CONNECT:return n===void 0||Zke(n);case Mu.DISCONNECT:return n===void 0;case Mu.EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&Anr.indexOf(n[0])===-1);case Mu.ACK:return Array.isArray(n);case Mu.CONNECT_ERROR:return typeof n=="string"||Zke(n);default:return!1}}t(Dyn,"isDataValid");function Nyn(i){return xyn(i.nsp)&&kyn(i.id)&&Dyn(i.type,i.data)}t(Nyn,"isPacketValid");function ZS(i,n,s){return i.on(n,s),t(function(){i.off(n,s)},"subDestroy")}t(ZS,"on");var bnr=uc(hV(),1),Enr=uc(DO(),1);var R1=(0,Enr.default)("socket.io-client:socket"),Pyn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),gft=class gft extends bnr.Emitter{constructor(n,s,c){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=n,this.nsp=s,c&&c.auth&&(this.auth=c.auth),this._opts=Object.assign({},c),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let n=this.io;this.subs=[ZS(n,"open",this.onopen.bind(this)),ZS(n,"packet",this.onpacket.bind(this)),ZS(n,"error",this.onerror.bind(this)),ZS(n,"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(...n){return n.unshift("message"),this.emit.apply(this,n),this}emit(n,...s){var c,u,_;if(Pyn.hasOwnProperty(n))throw new Error('"'+n.toString()+'" is a reserved event name');if(s.unshift(n),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;let g={type:Mu.EVENT,data:s};if(g.options={},g.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){let M=this.ids++;R1("emitting packet with ack id %d",M);let X=s.pop();this._registerAckCallback(M,X),g.id=M}let E=(u=(c=this.io.engine)===null||c===void 0?void 0:c.transport)===null||u===void 0?void 0:u.writable,x=this.connected&&!(!((_=this.io.engine)===null||_===void 0)&&_._hasPingExpired());return this.flags.volatile&&!E?R1("discard packet as the transport is not currently writable"):x?(this.notifyOutgoingListeners(g),this.packet(g)):this.sendBuffer.push(g),this.flags={},this}_registerAckCallback(n,s){var c;let u=(c=this.flags.timeout)!==null&&c!==void 0?c:this._opts.ackTimeout;if(u===void 0){this.acks[n]=s;return}let _=this.io.setTimeoutFn(()=>{delete this.acks[n];for(let E=0;E<this.sendBuffer.length;E++)this.sendBuffer[E].id===n&&(R1("removing packet with ack id %d from the buffer",n),this.sendBuffer.splice(E,1));R1("event with ack id %d has timed out after %d ms",n,u),s.call(this,new Error("operation has timed out"))},u),g=t((...E)=>{this.io.clearTimeoutFn(_),s.apply(this,E)},"fn");g.withError=!0,this.acks[n]=g}emitWithAck(n,...s){return new Promise((c,u)=>{let _=t((g,E)=>g?u(g):c(E),"fn");_.withError=!0,s.push(_),this.emit(n,...s)})}_addToQueue(n){let s;typeof n[n.length-1]=="function"&&(s=n.pop());let c={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,..._)=>c!==this._queue[0]?R1("packet [%d] already acknowledged",c.id):(u!==null?c.tryCount>this._opts.retries&&(R1("packet [%d] is discarded after %d tries",c.id,c.tryCount),this._queue.shift(),s&&s(u)):(R1("packet [%d] was successfully sent",c.id),this._queue.shift(),s&&s(null,..._)),c.pending=!1,this._drainQueue())),this._queue.push(c),this._drainQueue()}_drainQueue(n=!1){if(R1("draining queue"),!this.connected||this._queue.length===0)return;let s=this._queue[0];if(s.pending&&!n){R1("packet [%d] has already been sent and is waiting for an ack",s.id);return}s.pending=!0,s.tryCount++,R1("sending packet [%d] (try n\xB0%d)",s.id,s.tryCount),this.flags=s.flags,this.emit.apply(this,s.args)}packet(n){n.nsp=this.nsp,this.io._packet(n)}onopen(){R1("transport is open - connecting"),typeof this.auth=="function"?this.auth(n=>{this._sendConnectPacket(n)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(n){this.packet({type:Mu.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},n):n})}onerror(n){this.connected||this.emitReserved("connect_error",n)}onclose(n,s){R1("close (%s)",n),this.connected=!1,delete this.id,this.emitReserved("disconnect",n,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(n=>{if(!this.sendBuffer.some(c=>String(c.id)===n)){let c=this.acks[n];delete this.acks[n],c.withError&&c.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case Mu.CONNECT:n.data&&n.data.sid?this.onconnect(n.data.sid,n.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 Mu.EVENT:case Mu.BINARY_EVENT:this.onevent(n);break;case Mu.ACK:case Mu.BINARY_ACK:this.onack(n);break;case Mu.DISCONNECT:this.ondisconnect();break;case Mu.CONNECT_ERROR:this.destroy();let c=new Error(n.data.message);c.data=n.data.data,this.emitReserved("connect_error",c);break}}onevent(n){let s=n.data||[];R1("emitting event %j",s),n.id!=null&&(R1("attaching ack callback to event"),s.push(this.ack(n.id))),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(n){if(this._anyListeners&&this._anyListeners.length){let s=this._anyListeners.slice();for(let c of s)c.apply(this,n)}super.emit.apply(this,n),this._pid&&n.length&&typeof n[n.length-1]=="string"&&(this._lastOffset=n[n.length-1])}ack(n){let s=this,c=!1;return function(...u){c||(c=!0,R1("sending ack %j",u),s.packet({type:Mu.ACK,id:n,data:u}))}}onack(n){let s=this.acks[n.id];if(typeof s!="function"){R1("bad ack %s",n.id);return}delete this.acks[n.id],R1("calling ack %s with %j",n.id,n.data),s.withError&&n.data.unshift(null),s.apply(this,n.data)}onconnect(n,s){R1("socket connected with id %s",n),this.id=n,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(n=>this.emitEvent(n)),this.receiveBuffer=[],this.sendBuffer.forEach(n=>{this.notifyOutgoingListeners(n),this.packet(n)}),this.sendBuffer=[]}ondisconnect(){R1("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(n=>n()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&(R1("performing disconnect (%s)",this.nsp),this.packet({type:Mu.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(n){return this.flags.compress=n,this}get volatile(){return this.flags.volatile=!0,this}timeout(n){return this.flags.timeout=n,this}onAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(n),this}prependAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(n),this}offAny(n){if(!this._anyListeners)return this;if(n){let s=this._anyListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(n),this}prependAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(n),this}offAnyOutgoing(n){if(!this._anyOutgoingListeners)return this;if(n){let s=this._anyOutgoingListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(n){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let s=this._anyOutgoingListeners.slice();for(let c of s)c.apply(this,n.data)}}};t(gft,"Socket");var Dee=gft;function SV(i){i=i||{},this.ms=i.min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}t(SV,"Backoff");SV.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),s=Math.floor(n*this.jitter*i);i=Math.floor(n*10)&1?i+s:i-s}return Math.min(i,this.max)|0};SV.prototype.reset=function(){this.attempts=0};SV.prototype.setMin=function(i){this.ms=i};SV.prototype.setMax=function(i){this.max=i};SV.prototype.setJitter=function(i){this.jitter=i};var Cnr=uc(hV(),1),Snr=uc(DO(),1);var Ly=(0,Snr.default)("socket.io-client:manager"),Aft=class Aft extends Cnr.Emitter{constructor(n,s){var c;super(),this.nsps={},this.subs=[],n&&typeof n=="object"&&(s=n,n=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,mN(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((c=s.randomizationFactor)!==null&&c!==void 0?c:.5),this.backoff=new SV({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=n;let u=s.parser||_ft;this.encoder=new u.Encoder,this.decoder=new u.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(n){return arguments.length?(this._reconnection=!!n,n||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(n){return n===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=n,this)}reconnectionDelay(n){var s;return n===void 0?this._reconnectionDelay:(this._reconnectionDelay=n,(s=this.backoff)===null||s===void 0||s.setMin(n),this)}randomizationFactor(n){var s;return n===void 0?this._randomizationFactor:(this._randomizationFactor=n,(s=this.backoff)===null||s===void 0||s.setJitter(n),this)}reconnectionDelayMax(n){var s;return n===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=n,(s=this.backoff)===null||s===void 0||s.setMax(n),this)}timeout(n){return arguments.length?(this._timeout=n,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(n){if(Ly("readyState %s",this._readyState),~this._readyState.indexOf("open"))return this;Ly("opening %s",this.uri),this.engine=new kee(this.uri,this.opts);let s=this.engine,c=this;this._readyState="opening",this.skipReconnect=!1;let u=ZS(s,"open",function(){c.onopen(),n&&n()}),_=t(E=>{Ly("error"),this.cleanup(),this._readyState="closed",this.emitReserved("error",E),n?n(E):this.maybeReconnectOnOpen()},"onError"),g=ZS(s,"error",_);if(this._timeout!==!1){let E=this._timeout;Ly("connect attempt will timeout after %d",E);let x=this.setTimeoutFn(()=>{Ly("connect attempt timed out after %d",E),u(),_(new Error("timeout")),s.close()},E);this.opts.autoUnref&&x.unref(),this.subs.push(()=>{this.clearTimeoutFn(x)})}return this.subs.push(u),this.subs.push(g),this}connect(n){return this.open(n)}onopen(){Ly("open"),this.cleanup(),this._readyState="open",this.emitReserved("open");let n=this.engine;this.subs.push(ZS(n,"ping",this.onping.bind(this)),ZS(n,"data",this.ondata.bind(this)),ZS(n,"error",this.onerror.bind(this)),ZS(n,"close",this.onclose.bind(this)),ZS(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(n){try{this.decoder.add(n)}catch(s){this.onclose("parse error",s)}}ondecoded(n){_N(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){Ly("error",n),this.emitReserved("error",n)}socket(n,s){let c=this.nsps[n];return c?this._autoConnect&&!c.active&&c.connect():(c=new Dee(this,n,s),this.nsps[n]=c),c}_destroy(n){let s=Object.keys(this.nsps);for(let c of s)if(this.nsps[c].active){Ly("socket %s is still active, skipping close",c);return}this._close()}_packet(n){Ly("writing packet %j",n);let s=this.encoder.encode(n);for(let c=0;c<s.length;c++)this.engine.write(s[c],n.options)}cleanup(){Ly("cleanup"),this.subs.forEach(n=>n()),this.subs.length=0,this.decoder.destroy()}_close(){Ly("disconnect"),this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(n,s){var c;Ly("closed due to %s",n),this.cleanup(),(c=this.engine)===null||c===void 0||c.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",n,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let n=this;if(this.backoff.attempts>=this._reconnectionAttempts)Ly("reconnect failed"),this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let s=this.backoff.duration();Ly("will wait %dms before reconnect attempt",s),this._reconnecting=!0;let c=this.setTimeoutFn(()=>{n.skipReconnect||(Ly("attempting reconnect"),this.emitReserved("reconnect_attempt",n.backoff.attempts),!n.skipReconnect&&n.open(u=>{u?(Ly("reconnect attempt error"),n._reconnecting=!1,n.reconnect(),this.emitReserved("reconnect_error",u)):(Ly("reconnect success"),n.onreconnect())}))},s);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}}onreconnect(){let n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}};t(Aft,"Manager");var Nee=Aft;var Inr=uc(DO(),1);var wnr=(0,Inr.default)("socket.io-client"),f_e={};function p_e(i,n){typeof i=="object"&&(n=i,i=void 0),n=n||{};let s=pnr(i,n.path||"/socket.io"),c=s.source,u=s.id,_=s.path,g=f_e[u]&&_ in f_e[u].nsps,E=n.forceNew||n["force new connection"]||n.multiplex===!1||g,x;return E?(wnr("ignoring socket cache for %s",c),x=new Nee(c,n)):(f_e[u]||(wnr("new io instance for %s",c),f_e[u]=new Nee(c,n)),x=f_e[u]),s.query&&!n.query&&(n.query=s.queryKey),x.socket(s.path,n)}t(p_e,"lookup");Object.assign(p_e,{Manager:Nee,Socket:Dee,io:p_e,connect:p_e});var Xke={URL:"http://localhost:3000",NAMESPACE:"auto-recovery",RECONNECTION_ATTEMPTS:5,RECONNECTION_DELAY:1e3},yft=class yft{constructor(n={}){this.socket=null;this.connectionState="disconnected";this.connectionPromise=null;this.resolution=null;this.options=n,this.url=n.url||Xke.URL,this.namespace=n.namespace||Xke.NAMESPACE,this.initializationPromise=this.createInitializationPromise()}createInitializationPromise(){return new Promise((n,s)=>{this.resolveInitialization=c=>n(c),this.rejectInitialization=c=>s(c)}).then(n=>(this.resolution=n,this.log("\u2705 Client initialization successful"),n),n=>{throw this.resolution=n,this.logError("\u274C Client initialization failed:",n),n}).finally(()=>{this.disconnect()})}defineHandlers(n){return n}async startSession(n,s,c){try{if(await this.connect(),this.emit(n,s,u=>{this.resolveInitialization(u)}),c&&c>0){let u=new Promise((_,g)=>{setTimeout(()=>{g(new Error(`Session initialization timed out after ${c}ms`))},c)});return Promise.race([this.initializationPromise,u])}return this.initializationPromise}catch(u){throw this.logError("\u274C Failed to start session:",u),this.rejectInitialization(u),u}}isConnected(){var n;return((n=this.socket)==null?void 0:n.connected)||!1}getConnectionState(){return this.connectionState}success(n){return{success:!0,data:n}}error(n){return{success:!1,error:n}}log(n,...s){this.options.verbose&&console.log(`[${this.namespace}] ${n}`,...s)}logError(n,...s){this.options.verbose&&console.error(`[${this.namespace}] ${n}`,...s)}async connect(){var n;if(this.connectionPromise)return this.connectionPromise;if(this.connectionState==="connected"&&((n=this.socket)!=null&&n.connected))return Promise.resolve();this.connectionState="connecting",this.connectionPromise=this.establishConnection();try{await this.connectionPromise,this.connectionState="connected"}catch(s){throw this.connectionState="disconnected",this.connectionPromise=null,s}return this.connectionPromise}establishConnection(){return new Promise((n,s)=>{let c=!1;try{let u=`${this.url}/${this.namespace}`;this.log(`\u{1F517} Connecting to socket at: ${u}`),this.socket=p_e(u,{autoConnect:!0,reconnection:!0,reconnectionAttempts:Xke.RECONNECTION_ATTEMPTS,reconnectionDelay:Xke.RECONNECTION_DELAY,...this.options.path&&{path:this.options.path}}),this.setupConnectionHandlers(n,s,c)}catch(u){this.logError("\u274C Failed to create socket connection:",u),c||s(u)}})}setupConnectionHandlers(n,s,c){if(!this.socket)return;let u={resolve:n,reject:s,connectionResolved:c};this.socket.on("connect",()=>this.handleConnect(u)),this.socket.on("reconnect",()=>this.handleReconnect()),this.socket.on("connect_error",_=>this.handleConnectError(_,u)),this.socket.on("disconnect",_=>this.handleDisconnect(_,u)),this.socket.io.on("reconnect_attempt",_=>this.handleReconnectAttempt(_)),this.socket.io.on("reconnect_error",_=>this.handleReconnectError(_)),this.socket.io.on("reconnect_failed",()=>this.handleReconnectFailed(u))}handleConnect(n){this.log("\u2705 Connected to socket"),this.connectionState="connected",this.setupEventHandlers(),n.connectionResolved||(n.connectionResolved=!0,n.resolve())}handleReconnect(){this.log("\u2705 Reconnected to socket"),this.connectionState="connected"}handleConnectError(n,s){var c;this.logError("\u274C Connection error:",n),this.connectionState="disconnected",!s.connectionResolved&&((c=this.socket)==null?void 0:c.disconnected)!==!1&&(s.connectionResolved=!0,s.reject(n))}handleDisconnect(n,s){this.log("\u{1F50C} Disconnected from socket:",n),this.connectionState="disconnected";let c=new Error(`Socket disconnected: ${n}`),u=!1;this.resolution===null&&n==="io server disconnect"&&(this.rejectInitialization(c),u=!0),!s.connectionResolved&&(n==="io server disconnect"||n==="transport close")&&(s.connectionResolved=!0,s.reject(c)),!u&&this.resolution===null&&this.connectionState==="disconnected"&&this.rejectInitialization(c)}handleReconnectAttempt(n){this.log(`\u{1F504} Reconnection attempt #${n}`),this.connectionState="reconnecting"}handleReconnectError(n){this.logError("\u274C Reconnection attempt failed:",n)}handleReconnectFailed(n){this.logError("\u274C All reconnection attempts failed"),this.connectionState="disconnected",this.resolution===null&&this.rejectInitialization("All reconnection attempts failed"),n.connectionResolved||(n.connectionResolved=!0,n.reject(new Error("All reconnection attempts failed")))}setupEventHandlers(){if(!this.socket){this.logError("\u274C Cannot setup event handlers: socket is null");return}this.log("\u2705 Setting up event handlers"),this.socket.on("__call",this.handleGatewayCall.bind(this))}async handleGatewayCall(n,s){this.log(`\u{1F4E5} Gateway called method: ${n.key} with args:`,n.args);try{let c=this.validateGatewayCall(n);if(c){s(c);return}let u=this.handlers[n.key];if(!u){let g=`No handler registered for method: ${n.key}`;this.logError(`\u274C ${g}`),s(this.error(g));return}let _=await u(...n.args);s(this.success(_))}catch(c){this.logError("\u274C Error handling gateway call:",c),s(this.error(c.message||"Unknown error occurred"))}}validateGatewayCall(n){return n.key?Array.isArray(n.args)?null:(this.logError("\u274C Received call with invalid args"),this.error("Args must be an array")):(this.logError("\u274C Received call with undefined key"),this.error("Key is undefined"))}emit(n,s,c){if(!this.socket){this.logError("\u274C Cannot emit: socket is null");return}this.log(`\u{1F4E4} Emitting event: ${n}`),this.socket.emit(n,s,u=>{c(u)})}disconnect(){this.connectionState!=="shutting_down"&&(this.connectionState="shutting_down",this.log("\u{1F50C} Initiating disconnect"),this.socket&&(this.socket.disconnect(),this.socket=null),this.connectionPromise=null,this.connectionState="disconnected",this.log("\u2705 Disconnected successfully"))}};t(yft,"AbstractClient");var e3e=yft;var Tnr,xnr,knr,Dnr,Nnr,Pnr,Bnr,Fnr,r3e=class r3e extends(Fnr=e3e,Bnr=Oh.names.getState,Pnr=Oh.names.invokeCode,Nnr=Oh.names.final_result,Dnr=Oh.names.wait,knr=Oh.names.getElementScreenshot,xnr=Oh.names.listPages,Tnr=Oh.names.switchPage,Fnr){constructor(s,c){super({verbose:Yu.testRun.autoRecovery.verboseConsoleLog,url:c.config.apiURL,namespace:"auto-recovery",path:"/auto-recovery/socket.io"});this.utils=s;this.initData=c;this.stepsThoughts=[];this.handlers=this.defineHandlers({callLangChainTool:t(async(s,c)=>{if(!this[s])throw new Error(`Tool ${s} not found`);return c.thought&&this.stepsThoughts.push(c.thought),await this[s].invoke(c)},"callLangChainTool"),getStatus:t(async s=>({sessionId:s,status:"active",data:{message:"Status retrieved successfully"}}),"getStatus")});this[Bnr]=e5.buildTool(Oh,Oh.names.getState,async s=>this.getStateHandler(s));this[Pnr]=e5.buildTool(Oh,Oh.names.invokeCode,async s=>this.invokeCodeHandler(s));this[Nnr]=e5.buildTool(Oh,Oh.names.final_result,async s=>this.finalResultHandler(s));this[Dnr]=e5.buildTool(Oh,Oh.names.wait,async s=>this.waitHandler(s));this[knr]=e5.buildTool(Oh,Oh.names.getElementScreenshot,async s=>this.getElementScreenshotHandler(s));this[xnr]=e5.buildTool(Oh,Oh.names.listPages,async s=>this.listPagesHandler(s));this[Tnr]=e5.buildTool(Oh,Oh.names.switchPage,async s=>this.switchPageHandler(s))}async init(){let s={...this.initData,version:Oh.version};return await this.startSession("initialize",s).catch(c=>{this.utils.analytics.ARError({error:c.message});let u="Auto-Recovery attempt finished unsuccessfully";return this.utils.createChecksumStep({title:u,withError:!0}),this.utils.addAutoRecoveryErrorToReport(u,!1),{finalThought:u,stepsThoughts:[],result:"failed"}})}static async build(s){let c=await s.buildFallbackData();return new r3e(s,c)}async invokeCodeHandler(s){let c,u=this.utils.activePageGuid,_=s.pageId&&s.pageId!==u;return await this.utils.runConditionallyWithinStep(!0,s.thought||"Invoke Code",async()=>{try{_&&await this.utils.setActivePage(s.pageId);let g=await this.utils.invokeCode(s.code);this.utils.createChecksumStep({title:"Code Invoked Successfully"}),c={success:!0,invokeCodeResult:`invokeCodeResult: ${g.result}`,appState:(await this.utils.buildFallbackData()).applicationState,actionEffects:g.effects}}catch(g){c={success:!1,invokeCodeResult:`Error while invoking code: ${g}`,appState:(await this.utils.buildFallbackData()).applicationState}}finally{if(_&&u)try{await this.utils.setActivePage(u)}catch(g){console.warn("Failed to switch back to original page:",g)}}}),c}async getStateHandler(s){return this.utils.createChecksumStep({title:s.thought}),this.utils.analytics.ARGetState(s.thought),{success:!0,appState:await this.utils.captureApplicationState(s.pageId,s.includeAllPages)}}async finalResultHandler(s){let c=s.result==="pass",u=this.initData.type==="assertion"?c?"soft_assertion":"hard_assertion":c?"finish":"failed",_={finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts};await Promise.resolve(),this.resolveInitialization(_);try{this.utils.analytics.ARFinalResult({finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts})}catch(g){console.warn("Failed to record auto-recovery final-result analytics:",g)}try{this.utils.addAutoRecoveryErrorToReport(s.thought,c)}catch(g){console.warn("Failed to add auto-recovery result to report:",g)}}async getElementScreenshotHandler(s){return{success:!0,screenshot:await this.utils.getScreenshotForElement(s.checksumId)}}async waitHandler(s){await new Promise(u=>setTimeout(u,s.time||5e3));let c=await this.utils.buildFallbackData();return{success:!0,waitResult:`waited for ${s.time} seconds, the current HTML of the application after the wait is: ${c.applicationState.reducedHTML}`}}async listPagesHandler(s){s.thought&&this.utils.createChecksumStep({title:s.thought});let c=await this.utils.pageInteractor.getTabsInfo(),u=c.map((g,E)=>`${E+1}. ${g.title||"Untitled"} (${g.url})
746
+ Result: ${JSON.stringify(M)}`);else X=M;let ce=i0n({content:X,artifact:W,toolCallId:x,name:this.name,metadata:this.metadata});return await(P==null?void 0:P.handleToolEnd(ce)),ce}},t(fee,"StructuredTool"),fee),pee,t0n=(pee=class extends vtr{schema=il.object({input:il.string().optional()}).transform(n=>n.input);constructor(n){super(n)}call(n,s){let c=typeof n=="string"||n==null?{input:n}:n;return super.call(c,s)}},t(pee,"Tool"),pee),dee,r0n=(dee=class extends t0n{static lc_name(){return"DynamicTool"}name;description;func;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect}async call(n,s){let c=QTe(s);return c.runName===void 0&&(c.runName=this.name),super.call(n,c)}_call(n,s,c){return this.func(n,s,c)}},t(dee,"DynamicTool"),dee),_ee,n0n=(_ee=class extends vtr{static lc_name(){return"DynamicStructuredTool"}description;func;schema;constructor(n){super(n),this.name=n.name,this.description=n.description,this.func=n.func,this.returnDirect=n.returnDirect??this.returnDirect,this.schema=n.schema}async call(n,s,c){let u=QTe(s);return u.runName===void 0&&(u.runName=this.name),super.call(n,u,c)}_call(n,s,c){return this.func(n,s,c)}},t(_ee,"DynamicStructuredTool"),_ee);function nut(i,n){var g;let s=Pxe(n.schema),c=Lde(n.schema);if(!n.schema||s||c)return new r0n({...n,description:n.description??((g=n.schema)==null?void 0:g.description)??`${n.name} tool`,func:t(async(E,x,P)=>new Promise((M,X)=>{let W=w0(P,{callbacks:x==null?void 0:x.getChild()});Vv.runWithConfig(Ow(W),async()=>{try{M(i(E,W))}catch(ce){X(ce)}})}),"func")});let u=n.schema,_=n.description??n.schema.description??`${n.name} tool`;return new n0n({...n,description:_,schema:u,func:t(async(E,x,P)=>new Promise((M,X)=>{let W,ce=t(()=>{P!=null&&P.signal&&W&&P.signal.removeEventListener("abort",W)},"cleanup");P!=null&&P.signal&&(W=t(()=>{ce(),X(hO(P.signal))},"listener"),P.signal.addEventListener("abort",W,{once:!0}));let ue=w0(P,{callbacks:x==null?void 0:x.getChild()});Vv.runWithConfig(Ow(ue),async()=>{var Se;try{let Ct=await i(E,ue);if(slt(Ct)){M(Ct);return}if((Se=P==null?void 0:P.signal)!=null&&Se.aborted){ce();return}ce(),M(Ct)}catch(Ct){ce(),X(Ct)}})}),"func")})}t(nut,"tool");function i0n(i){let{content:n,artifact:s,toolCallId:c,metadata:u}=i;return c&&!bHt(n)?typeof n=="string"||Array.isArray(n)&&n.every(_=>typeof _=="object")?new VIe({status:"success",content:n,artifact:s,tool_call_id:c,name:i.name,metadata:u}):new VIe({status:"success",content:s0n(n),artifact:s,tool_call_id:c,name:i.name,metadata:u}):n}t(i0n,"_formatToolOutput");function s0n(i){try{return JSON.stringify(i)??""}catch{return`${i}`}}t(s0n,"_stringify");var dN=class dN{constructor(){this.toolsMap={}}get addTool(){return this._addTool||(this._addTool=this.buildAddToolFacade()),this._addTool}getToolNames(){return Object.keys(this.toolRecord.names)}get tools(){return this.toolsMap}buildAddToolFacade(){let n={},s=this.toolRecord.tools;for(let c of Object.keys(s))n[c]=u=>this._addSingleTool(c,u);return n}static describeTool(n,s){if(n instanceof il.ZodObject){let c={},u=n.shape;for(let _ of Object.keys(u)){let g=u[_],E=s==null?void 0:s[_];typeof E=="string"?c[_]=g.describe(E):E&&typeof E=="object"?c[_]=dN.describeTool(g,E):c[_]=g}return il.object(c).strict()}if(n instanceof il.ZodArray){let c=n.element;return s&&typeof s=="object"&&s.element?il.array(dN.describeTool(c,s.element)):n}return n instanceof il.ZodOptional?dN.describeTool(n.unwrap(),s).optional():n instanceof il.ZodNullable?dN.describeTool(n.unwrap(),s).nullable():typeof s=="string"?n.describe(s):n}_addSingleTool(n,s){let c=s.name??String(n),_=this.toolRecord.tools[n]._create({...s,name:c,params:s.params,handler:s.handler}),g=this.toolRecord.tools[n],E=dN.describeTool(g,s.params),P=nut(t(async M=>{let X=E.parse(M);return s.handler(X)},"validatedHandler"),{name:_.name,description:_.description,schema:E});return this.toolsMap[n]=P,P}_buildOne(n,s){return this._addSingleTool(n,{...s,name:String(n)})}static buildTool(n,s,c){let u=String(s),g=n.tools[s]._create({name:u,description:"",handler:c,params:{}}),E=n.tools[s],x=dN.describeTool(E,{});return nut(t(async X=>{let W=x.parse(X);return c(W)},"validatedHandler"),{name:g.name,description:g.description,schema:x})}};t(dN,"AbstractToolContainer");var e5=dN;var Eke=class Eke{constructor(n,s){this.version=n;let c={};for(let _ in s)c[_]=_;this.names=c;let u={};for(let _ in s){let g=s[_];Object.defineProperty(g,"name",{value:_,configurable:!1,enumerable:!0,writable:!1}),g._create=(E=>x=>{let P=x.name??E;return{...x,name:P}})(_),u[_]=g}this.tools=u}static create(n,s){return new Eke(n,s)}};t(Eke,"ToolProtocol");var bke=Eke;var Oh=bke.create("v1",{readFile:il.object({path:il.string()}),getState:il.object({thought:il.string(),pageId:il.string().optional(),includeAllPages:il.boolean().optional()}),invokeCode:il.object({code:il.string().refine(i=>{let n=i.trim();return n.includes("page.getByChecksumId(")||n.includes("page.getByChecksumId(")||n.startsWith("const ")||n.startsWith("let ")||n.startsWith("var ")||n.includes("=")||n.includes("variableStore.")},{message:"Code should use page.getByChecksumId() for element targeting, or be explicit variable assignments/function calls"}),thought:il.string(),pageId:il.string().optional()}),wait:il.object({time:il.number().optional()}),scroll:il.object({checksumId:il.string(),thought:il.string()}),final_result:il.object({result:il.enum(["pass","fail"]),thought:il.string(),visualAnalysis:il.string().optional()}),getElementScreenshot:il.object({checksumId:il.string(),thought:il.string()}),listPages:il.object({thought:il.string().optional()}),switchPage:il.object({pageId:il.string(),thought:il.string().optional()}),analyze:il.object({previousImmediateSteps:il.string(),currentFailingStep:il.string(),nextImmediateSteps:il.string(),testStepToStopAt:il.string()}),think:il.object({thought:il.string()})});var but=uc(Ctr(),1);var mx=Object.create(null);mx.open="0";mx.close="1";mx.ping="2";mx.pong="3";mx.message="4";mx.upgrade="5";mx.noop="6";var qde=Object.create(null);Object.keys(mx).forEach(i=>{qde[mx[i]]=i});var Hde={type:"error",data:"parser error"};var $de=t(({type:i,data:n},s,c)=>n instanceof ArrayBuffer||ArrayBuffer.isView(n)?c(s?n:"b"+Str(n,!0).toString("base64")):c(mx[i]+(n||"")),"encodePacket"),Str=t((i,n)=>Buffer.isBuffer(i)||i instanceof Uint8Array&&!n?i:i instanceof ArrayBuffer?Buffer.from(i):Buffer.from(i.buffer,i.byteOffset,i.byteLength),"toBuffer"),sut;function wtr(i,n){if(i.data instanceof ArrayBuffer||ArrayBuffer.isView(i.data))return n(Str(i.data,!1));$de(i,!0,s=>{sut||(sut=new TextEncoder),n(sut.encode(s))})}t(wtr,"encodePacketToBinary");var Gde=t((i,n)=>{if(typeof i!="string")return{type:"message",data:Itr(i,n)};let s=i.charAt(0);if(s==="b"){let c=Buffer.from(i.substring(1),"base64");return{type:"message",data:Itr(c,n)}}return qde[s]?i.length>1?{type:qde[s],data:i.substring(1)}:{type:qde[s]}:Hde},"decodePacket"),Itr=t((i,n)=>{switch(n){case"arraybuffer":return i instanceof ArrayBuffer?i:Buffer.isBuffer(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i.buffer;case"nodebuffer":default:return Buffer.isBuffer(i)?i:Buffer.from(i)}},"mapBinary");var Ttr="",xtr=t((i,n)=>{let s=i.length,c=new Array(s),u=0;i.forEach((_,g)=>{$de(_,!1,E=>{c[g]=E,++u===s&&n(c.join(Ttr))})})},"encodePayload"),ktr=t((i,n)=>{let s=i.split(Ttr),c=[];for(let u=0;u<s.length;u++){let _=Gde(s[u],n);if(c.push(_),_.type==="error")break}return c},"decodePayload");function Dtr(){return new TransformStream({transform(i,n){wtr(i,s=>{let c=s.length,u;if(c<126)u=new Uint8Array(1),new DataView(u.buffer).setUint8(0,c);else if(c<65536){u=new Uint8Array(3);let _=new DataView(u.buffer);_.setUint8(0,126),_.setUint16(1,c)}else{u=new Uint8Array(9);let _=new DataView(u.buffer);_.setUint8(0,127),_.setBigUint64(1,BigInt(c))}i.data&&typeof i.data!="string"&&(u[0]|=128),n.enqueue(u),n.enqueue(s)})}})}t(Dtr,"createPacketEncoderStream");var aut;function Cke(i){return i.reduce((n,s)=>n+s.length,0)}t(Cke,"totalLength");function Ske(i,n){if(i[0].length===n)return i.shift();let s=new Uint8Array(n),c=0;for(let u=0;u<n;u++)s[u]=i[0][c++],c===i[0].length&&(i.shift(),c=0);return i.length&&c<i[0].length&&(i[0]=i[0].slice(c)),s}t(Ske,"concatChunks");function Ntr(i,n){aut||(aut=new TextDecoder);let s=[],c=0,u=-1,_=!1;return new TransformStream({transform(g,E){for(s.push(g);;){if(c===0){if(Cke(s)<1)break;let x=Ske(s,1);_=(x[0]&128)===128,u=x[0]&127,u<126?c=3:u===126?c=1:c=2}else if(c===1){if(Cke(s)<2)break;let x=Ske(s,2);u=new DataView(x.buffer,x.byteOffset,x.length).getUint16(0),c=3}else if(c===2){if(Cke(s)<8)break;let x=Ske(s,8),P=new DataView(x.buffer,x.byteOffset,x.length),M=P.getUint32(0);if(M>Math.pow(2,21)-1){E.enqueue(Hde);break}u=M*Math.pow(2,32)+P.getUint32(4),c=3}else{if(Cke(s)<u)break;let x=Ske(s,u);E.enqueue(Gde(_?x:aut.decode(x),n)),c=0}if(u===0||u>i){E.enqueue(Hde);break}}}})}t(Ntr,"createPacketDecoderStream");var out=4;var Htr=uc(hV(),1);var _N=process.nextTick,Ib=global,Btr="nodebuffer";function Ftr(){return new cut}t(Ftr,"createCookieJar");function l0n(i){let n=i.split("; "),s=n[0].indexOf("=");if(s===-1)return;let c=n[0].substring(0,s).trim();if(!c.length)return;let u=n[0].substring(s+1).trim();u.charCodeAt(0)===34&&(u=u.slice(1,-1));let _={name:c,value:u};for(let g=1;g<n.length;g++){let E=n[g].split("=");if(E.length!==2)continue;let x=E[0].trim(),P=E[1].trim();switch(x){case"Expires":_.expires=new Date(P);break;case"Max-Age":let M=new Date;M.setUTCSeconds(M.getUTCSeconds()+parseInt(P,10)),_.expires=M;break;default:}}return _}t(l0n,"parse");var lut=class lut{constructor(){this._cookies=new Map}parseCookies(n){n&&n.forEach(s=>{let c=l0n(s);c&&this._cookies.set(c.name,c)})}get cookies(){let n=Date.now();return this._cookies.forEach((s,c)=>{var u;((u=s.expires)===null||u===void 0?void 0:u.getTime())<n&&this._cookies.delete(c)}),this._cookies.entries()}addCookies(n){let s=[];for(let[c,u]of this.cookies)s.push(`${c}=${u.value}`);s.length&&(n.setDisableHeaderCheck(!0),n.setRequestHeader("cookie",s.join("; ")))}appendCookies(n){for(let[s,c]of this.cookies)n.append("cookie",`${s}=${c.value}`)}};t(lut,"CookieJar");var cut=lut;function wke(i,...n){return n.reduce((s,c)=>(i.hasOwnProperty(c)&&(s[c]=i[c]),s),{})}t(wke,"pick");var u0n=Ib.setTimeout,f0n=Ib.clearTimeout;function mN(i,n){n.useNativeTimers?(i.setTimeoutFn=u0n.bind(Ib),i.clearTimeoutFn=f0n.bind(Ib)):(i.setTimeoutFn=Ib.setTimeout.bind(Ib),i.clearTimeoutFn=Ib.clearTimeout.bind(Ib))}t(mN,"installTimerFunctions");var p0n=1.33;function Rtr(i){return typeof i=="string"?d0n(i):Math.ceil((i.byteLength||i.size)*p0n)}t(Rtr,"byteLength");function d0n(i){let n=0,s=0;for(let c=0,u=i.length;c<u;c++)n=i.charCodeAt(c),n<128?s+=1:n<2048?s+=2:n<55296||n>=57344?s+=3:(c++,s+=4);return s}t(d0n,"utf8Length");function Ike(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}t(Ike,"randomString");function Otr(i){let n="";for(let s in i)i.hasOwnProperty(s)&&(n.length&&(n+="&"),n+=encodeURIComponent(s)+"="+encodeURIComponent(i[s]));return n}t(Otr,"encode");function Mtr(i){let n={},s=i.split("&");for(let c=0,u=s.length;c<u;c++){let _=s[c].split("=");n[decodeURIComponent(_[0])]=decodeURIComponent(_[1])}return n}t(Mtr,"decode");var $tr=uc(AV(),1);var O0n=(0,$tr.default)("engine.io-client:transport"),hut=class hut extends Error{constructor(n,s,c){super(n),this.description=s,this.context=c,this.type="TransportError"}};t(hut,"TransportError");var Nke=hut,gut=class gut extends Htr.Emitter{constructor(n){super(),this.writable=!1,mN(this,n),this.opts=n,this.query=n.query,this.socket=n.socket,this.supportsBinary=!n.forceBase64}onError(n,s,c){return super.emitReserved("error",new Nke(n,s,c)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(n){this.readyState==="open"?this.write(n):O0n("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(n){let s=Gde(n,this.socket.binaryType);this.onPacket(s)}onPacket(n){super.emitReserved("packet",n)}onClose(n){this.readyState="closed",super.emitReserved("close",n)}pause(n){}createUri(n,s={}){return n+"://"+this._hostname()+this._port()+this.opts.path+this._query(s)}_hostname(){let n=this.opts.hostname;return n.indexOf(":")===-1?n:"["+n+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(n){let s=Otr(n);return s.length?"?"+s:""}};t(gut,"Transport");var hN=gut;var Gtr=uc(AV(),1);var hx=(0,Gtr.default)("engine.io-client:polling"),Aut=class Aut extends hN{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(n){this.readyState="pausing";let s=t(()=>{hx("paused"),this.readyState="paused",n()},"pause");if(this._polling||!this.writable){let c=0;this._polling&&(hx("we are currently polling - waiting to pause"),c++,this.once("pollComplete",function(){hx("pre-pause polling complete"),--c||s()})),this.writable||(hx("we are currently writing - waiting to pause"),c++,this.once("drain",function(){hx("pre-pause writing complete"),--c||s()}))}else s()}_poll(){hx("polling"),this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(n){hx("polling got data %s",n);let s=t(c=>{if(this.readyState==="opening"&&c.type==="open"&&this.onOpen(),c.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(c)},"callback");ktr(n,this.socket.binaryType).forEach(s),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this._poll():hx('ignoring poll - transport state "%s"',this.readyState))}doClose(){let n=t(()=>{hx("writing close packet"),this.write([{type:"close"}])},"close");this.readyState==="open"?(hx("transport open - closing"),n()):(hx("transport not open - deferring close"),this.once("open",n))}write(n){this.writable=!1,xtr(n,s=>{this.doWrite(s,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let n=this.opts.secure?"https":"http",s=this.query||{};return this.opts.timestampRequests!==!1&&(s[this.opts.timestampParam]=Ike()),!this.supportsBinary&&!s.sid&&(s.b64=1),this.createUri(n,s)}};t(Aut,"Polling");var Yde=Aut;var Xtr=uc(hV(),1);var Ytr=!1;try{Ytr=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Ztr=Ytr;var err=uc(AV(),1);var yut=(0,err.default)("engine.io-client:polling");function M0n(){}t(M0n,"empty");var vut=class vut extends Yde{constructor(n){if(super(n),typeof location<"u"){let s=location.protocol==="https:",c=location.port;c||(c=s?"443":"80"),this.xd=typeof location<"u"&&n.hostname!==location.hostname||c!==n.port}}doWrite(n,s){let c=this.request({method:"POST",data:n});c.on("success",s),c.on("error",(u,_)=>{this.onError("xhr post error",u,_)})}doPoll(){yut("xhr poll");let n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(s,c)=>{this.onError("xhr poll error",s,c)}),this.pollXhr=n}};t(vut,"BaseXHR");var Pke=vut,yee=class yee extends Xtr.Emitter{constructor(n,s,c){super(),this.createRequest=n,mN(this,c),this._opts=c,this._method=c.method||"GET",this._uri=s,this._data=c.data!==void 0?c.data:null,this._create()}_create(){var n;let s=wke(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");s.xdomain=!!this._opts.xd;let c=this._xhr=this.createRequest(s);try{yut("xhr open %s: %s",this._method,this._uri),c.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){c.setDisableHeaderCheck&&c.setDisableHeaderCheck(!0);for(let u in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(u)&&c.setRequestHeader(u,this._opts.extraHeaders[u])}}catch{}if(this._method==="POST")try{c.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{c.setRequestHeader("Accept","*/*")}catch{}(n=this._opts.cookieJar)===null||n===void 0||n.addCookies(c),"withCredentials"in c&&(c.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(c.timeout=this._opts.requestTimeout),c.onreadystatechange=()=>{var u;c.readyState===3&&((u=this._opts.cookieJar)===null||u===void 0||u.parseCookies(c.getResponseHeader("set-cookie"))),c.readyState===4&&(c.status===200||c.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof c.status=="number"?c.status:0)},0))},yut("xhr data %s",this._data),c.send(this._data)}catch(u){this.setTimeoutFn(()=>{this._onError(u)},0);return}typeof document<"u"&&(this._index=yee.requestsCount++,yee.requests[this._index]=this)}_onError(n){this.emitReserved("error",n,this._xhr),this._cleanup(!0)}_cleanup(n){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=M0n,n)try{this._xhr.abort()}catch{}typeof document<"u"&&delete yee.requests[this._index],this._xhr=null}}_onLoad(){let n=this._xhr.responseText;n!==null&&(this.emitReserved("data",n),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};t(yee,"Request");var gN=yee;gN.requestsCount=0;gN.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Ktr);else if(typeof addEventListener=="function"){let i="onpagehide"in Ib?"pagehide":"unload";addEventListener(i,Ktr,!1)}}function Ktr(){for(let i in gN.requests)gN.requests.hasOwnProperty(i)&&gN.requests[i].abort()}t(Ktr,"unloadHandler");var $Yn=function(){let i=L0n({xdomain:!1});return i&&i.responseType!==null}();function L0n(i){let n=i.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!n||Ztr))return new XMLHttpRequest}catch{}if(!n)try{return new Ib[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}t(L0n,"newRequest");var Q0n=but.default||but,Eut=class Eut extends Pke{request(n={}){var s;return Object.assign(n,{xd:this.xd,cookieJar:(s=this.socket)===null||s===void 0?void 0:s._cookieJar},this.opts),new gN(c=>new Q0n(c),this.uri(),n)}};t(Eut,"XHR");var vee=Eut;var GAn=uc(irr(),1),YAn=uc(Out(),1),ZAn=uc(Lut(),1),Kut=uc(Gut(),1),KAn=uc(tnr(),1);var rnr=uc(AV(),1);var eyn=(0,rnr.default)("engine.io-client:websocket"),tyn=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Xut=class Xut extends hN{get name(){return"websocket"}doOpen(){let n=this.uri(),s=this.opts.protocols,c=tyn?{}:wke(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(c.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(n,s,c)}catch(u){return this.emitReserved("error",u)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=n=>this.onClose({description:"websocket connection closed",context:n}),this.ws.onmessage=n=>this.onData(n.data),this.ws.onerror=n=>this.onError("websocket error",n)}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;$de(c,this.supportsBinary,_=>{try{this.doWrite(c,_)}catch{eyn("websocket closed before onclose event")}u&&_N(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let n=this.opts.secure?"wss":"ws",s=this.query||{};return this.opts.timestampRequests&&(s[this.opts.timestampParam]=Ike()),this.supportsBinary||(s.b64=1),this.createUri(n,s)}};t(Xut,"BaseWS");var qke=Xut,FZn=Ib.WebSocket||Ib.MozWebSocket;var eft=class eft extends qke{createSocket(n,s,c){var u;if(!((u=this.socket)===null||u===void 0)&&u._cookieJar){c.headers=c.headers||{},c.headers.cookie=typeof c.headers.cookie=="string"?[c.headers.cookie]:c.headers.cookie||[];for(let[_,g]of this.socket._cookieJar.cookies)c.headers.cookie.push(`${_}=${g.value}`)}return new Kut.default(n,s,c)}doWrite(n,s){let c={};n.options&&(c.compress=n.options.compress),this.opts.perMessageDeflate&&(typeof s=="string"?Buffer.byteLength(s):s.length)<this.opts.perMessageDeflate.threshold&&(c.compress=!1),this.ws.send(s,c)}};t(eft,"WS");var wee=eft;var nnr=uc(AV(),1);var o_e=(0,nnr.default)("engine.io-client:webtransport"),tft=class tft extends hN{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(n){return this.emitReserved("error",n)}this._transport.closed.then(()=>{o_e("transport closed gracefully"),this.onClose()}).catch(n=>{o_e("transport closed due to %s",n),this.onError("webtransport error",n)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(n=>{let s=Ntr(Number.MAX_SAFE_INTEGER,this.socket.binaryType),c=n.readable.pipeThrough(s).getReader(),u=Dtr();u.readable.pipeTo(n.writable),this._writer=u.writable.getWriter();let _=t(()=>{c.read().then(({done:E,value:x})=>{if(E){o_e("session is closed");return}o_e("received chunk: %o",x),this.onPacket(x),_()}).catch(E=>{o_e("an error occurred while reading: %s",E)})},"read");_();let g={type:"open"};this.query.sid&&(g.data=`{"sid":"${this.query.sid}"}`),this._writer.write(g).then(()=>this.onOpen())})})}write(n){this.writable=!1;for(let s=0;s<n.length;s++){let c=n[s],u=s===n.length-1;this._writer.write(c).then(()=>{u&&_N(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this._transport)===null||n===void 0||n.close()}};t(tft,"WT");var Iee=tft;var rft={websocket:wee,webtransport:Iee,polling:vee};var ryn=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,nyn=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Tee(i){if(i.length>8e3)throw"URI too long";let n=i,s=i.indexOf("["),c=i.indexOf("]");s!=-1&&c!=-1&&(i=i.substring(0,s)+i.substring(s,c).replace(/:/g,";")+i.substring(c,i.length));let u=ryn.exec(i||""),_={},g=14;for(;g--;)_[nyn[g]]=u[g]||"";return s!=-1&&c!=-1&&(_.source=n,_.host=_.host.substring(1,_.host.length-1).replace(/;/g,":"),_.authority=_.authority.replace("[","").replace("]","").replace(/;/g,":"),_.ipv6uri=!0),_.pathNames=iyn(_,_.path),_.queryKey=syn(_,_.query),_}t(Tee,"parse");function iyn(i,n){let s=/\/{2,9}/g,c=n.replace(s,"/").split("/");return(n.slice(0,1)=="/"||n.length===0)&&c.splice(0,1),n.slice(-1)=="/"&&c.splice(c.length-1,1),c}t(iyn,"pathNames");function syn(i,n){let s={};return n.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,u,_){u&&(s[u]=_)}),s}t(syn,"queryKey");var inr=uc(hV(),1);var snr=uc(AV(),1);var M_=(0,snr.default)("engine.io-client:socket"),nft=typeof addEventListener=="function"&&typeof removeEventListener=="function",c_e=[];nft&&addEventListener("offline",()=>{M_("closing %d connection(s) because the network was lost",c_e.length),c_e.forEach(i=>i())},!1);var xee=class xee extends inr.Emitter{constructor(n,s){if(super(),this.binaryType=Btr,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,n&&typeof n=="object"&&(s=n,n=null),n){let c=Tee(n);s.hostname=c.host,s.secure=c.protocol==="https"||c.protocol==="wss",s.port=c.port,c.query&&(s.query=c.query)}else s.host&&(s.hostname=Tee(s.host).host);mN(this,s),this.secure=s.secure!=null?s.secure:typeof location<"u"&&location.protocol==="https:",s.hostname&&!s.port&&(s.port=this.secure?"443":"80"),this.hostname=s.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=s.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},s.transports.forEach(c=>{let u=c.prototype.name;this.transports.push(u),this._transportsByName[u]=c}),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},s),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Mtr(this.opts.query)),nft&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(M_("adding listener for the 'offline' event"),this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},c_e.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=Ftr()),this._open()}createTransport(n){M_('creating transport "%s"',n);let s=Object.assign({},this.opts.query);s.EIO=out,s.transport=n,this.id&&(s.sid=this.id);let c=Object.assign({},this.opts,{query:s,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[n]);return M_("options: %j",c),new this._transportsByName[n](c)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let n=this.opts.rememberUpgrade&&xee.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let s=this.createTransport(n);s.open(),this.setTransport(s)}setTransport(n){M_("setting transport %s",n.name),this.transport&&(M_("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=n,n.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",s=>this._onClose("transport close",s))}onOpen(){M_("socket open"),this.readyState="open",xee.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(M_('socket receive: type "%s", data "%s"',n.type,n.data),this.emitReserved("packet",n),this.emitReserved("heartbeat"),n.type){case"open":this.onHandshake(JSON.parse(n.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let s=new Error("server error");s.code=n.data,this._onError(s);break;case"message":this.emitReserved("data",n.data),this.emitReserved("message",n.data);break}else M_('packet received with socket readyState "%s"',this.readyState)}onHandshake(n){this.emitReserved("handshake",n),this.id=n.sid,this.transport.query.sid=n.sid,this._pingInterval=n.pingInterval,this._pingTimeout=n.pingTimeout,this._maxPayload=n.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let n=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+n,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},n),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){let n=this._getWritablePackets();M_("flushing %d packets in socket",n.length),this.transport.send(n),this._prevBufferLen=n.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let s=1;for(let c=0;c<this.writeBuffer.length;c++){let u=this.writeBuffer[c].data;if(u&&(s+=Rtr(u)),c>0&&s>this._maxPayload)return M_("only send %d out of %d packets",c,this.writeBuffer.length),this.writeBuffer.slice(0,c);s+=2}return M_("payload size is %d (max: %d)",s,this._maxPayload),this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let n=Date.now()>this._pingTimeoutTime;return n&&(M_("throttled timer detected, scheduling connection close"),this._pingTimeoutTime=0,_N(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),n}write(n,s,c){return this._sendPacket("message",n,s,c),this}send(n,s,c){return this._sendPacket("message",n,s,c),this}_sendPacket(n,s,c,u){if(typeof s=="function"&&(u=s,s=void 0),typeof c=="function"&&(u=c,c=null),this.readyState==="closing"||this.readyState==="closed")return;c=c||{},c.compress=c.compress!==!1;let _={type:n,data:s,options:c};this.emitReserved("packetCreate",_),this.writeBuffer.push(_),u&&this.once("flush",u),this.flush()}close(){let n=t(()=>{this._onClose("forced close"),M_("socket closing - telling transport to close"),this.transport.close()},"close"),s=t(()=>{this.off("upgrade",s),this.off("upgradeError",s),n()},"cleanupAndClose"),c=t(()=>{this.once("upgrade",s),this.once("upgradeError",s)},"waitForUpgrade");return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?c():n()}):this.upgrading?c():n()),this}_onError(n){if(M_("socket error %j",n),xee.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return M_("trying next transport"),this.transports.shift(),this._open();this.emitReserved("error",n),this._onClose("transport error",n)}_onClose(n,s){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(M_('socket close with reason: "%s"',n),this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),nft&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let c=c_e.indexOf(this._offlineEventListener);c!==-1&&(M_("removing listener for the 'offline' event"),c_e.splice(c,1))}this.readyState="closed",this.id=null,this.emitReserved("close",n,s),this.writeBuffer=[],this._prevBufferLen=0}}};t(xee,"SocketWithoutUpgrade");var CV=xee;CV.protocol=out;var ift=class ift extends CV{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade){M_("starting upgrade probes");for(let n=0;n<this._upgrades.length;n++)this._probe(this._upgrades[n])}}_probe(n){M_('probing transport "%s"',n);let s=this.createTransport(n),c=!1;CV.priorWebsocketSuccess=!1;let u=t(()=>{c||(M_('probe transport "%s" opened',n),s.send([{type:"ping",data:"probe"}]),s.once("packet",X=>{if(!c)if(X.type==="pong"&&X.data==="probe"){if(M_('probe transport "%s" pong',n),this.upgrading=!0,this.emitReserved("upgrading",s),!s)return;CV.priorWebsocketSuccess=s.name==="websocket",M_('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{c||this.readyState!=="closed"&&(M_("changing transport and sending upgrade packet"),M(),this.setTransport(s),s.send([{type:"upgrade"}]),this.emitReserved("upgrade",s),s=null,this.upgrading=!1,this.flush())})}else{M_('probe transport "%s" failed',n);let W=new Error("probe error");W.transport=s.name,this.emitReserved("upgradeError",W)}}))},"onTransportOpen");function _(){c||(c=!0,M(),s.close(),s=null)}t(_,"freezeTransport");let g=t(X=>{let W=new Error("probe error: "+X);W.transport=s.name,_(),M_('probe transport "%s" failed because of error: %s',n,X),this.emitReserved("upgradeError",W)},"onerror");function E(){g("transport closed")}t(E,"onTransportClose");function x(){g("socket closed")}t(x,"onclose");function P(X){s&&X.name!==s.name&&(M_('"%s" works - aborting "%s"',X.name,s.name),_())}t(P,"onupgrade");let M=t(()=>{s.removeListener("open",u),s.removeListener("error",g),s.removeListener("close",E),this.off("close",x),this.off("upgrading",P)},"cleanup");s.once("open",u),s.once("error",g),s.once("close",E),this.once("close",x),this.once("upgrading",P),this._upgrades.indexOf("webtransport")!==-1&&n!=="webtransport"?this.setTimeoutFn(()=>{c||s.open()},200):s.open()}onHandshake(n){this._upgrades=this._filterUpgrades(n.upgrades),super.onHandshake(n)}_filterUpgrades(n){let s=[];for(let c=0;c<n.length;c++)~this.transports.indexOf(n[c])&&s.push(n[c]);return s}};t(ift,"SocketWithUpgrade");var Hke=ift,sft=class sft extends Hke{constructor(n,s={}){let c=typeof n=="object"?n:s;(!c.transports||c.transports&&typeof c.transports[0]=="string")&&(c.transports=(c.transports||["polling","websocket","webtransport"]).map(u=>rft[u]).filter(u=>!!u)),super(n,c)}};t(sft,"Socket");var kee=sft;var lKn=kee.protocol;var fnr=uc(DO(),1);var unr=(0,fnr.default)("socket.io-client:url");function pnr(i,n="",s){let c=i;s=s||typeof location<"u"&&location,i==null&&(i=s.protocol+"//"+s.host),typeof i=="string"&&(i.charAt(0)==="/"&&(i.charAt(1)==="/"?i=s.protocol+i:i=s.host+i),/^(https?|wss?):\/\//.test(i)||(unr("protocol-less url %s",i),typeof s<"u"?i=s.protocol+"//"+i:i="https://"+i),unr("parse %s",i),c=Tee(i)),c.port||(/^(http|ws)$/.test(c.protocol)?c.port="80":/^(http|ws)s$/.test(c.protocol)&&(c.port="443")),c.path=c.path||"/";let _=c.host.indexOf(":")!==-1?"["+c.host+"]":c.host;return c.id=c.protocol+"://"+_+":"+c.port+n,c.href=c.protocol+"://"+_+(s&&s.port===c.port?"":":"+c.port),c}t(pnr,"url");var _ft={};OT(_ft,{Decoder:()=>pft,Encoder:()=>fft,PacketType:()=>Mu,isPacketValid:()=>Nyn,protocol:()=>ynr});var hnr=uc(hV(),1);var Syn=typeof ArrayBuffer=="function",wyn=t(i=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(i):i.buffer instanceof ArrayBuffer,"isView"),dnr=Object.prototype.toString,Iyn=typeof Blob=="function"||typeof Blob<"u"&&dnr.call(Blob)==="[object BlobConstructor]",Tyn=typeof File=="function"||typeof File<"u"&&dnr.call(File)==="[object FileConstructor]";function u_e(i){return Syn&&(i instanceof ArrayBuffer||wyn(i))||Iyn&&i instanceof Blob||Tyn&&i instanceof File}t(u_e,"isBinary");function l_e(i,n){if(!i||typeof i!="object")return!1;if(Array.isArray(i)){for(let s=0,c=i.length;s<c;s++)if(l_e(i[s]))return!0;return!1}if(u_e(i))return!0;if(i.toJSON&&typeof i.toJSON=="function"&&arguments.length===1)return l_e(i.toJSON(),!0);for(let s in i)if(Object.prototype.hasOwnProperty.call(i,s)&&l_e(i[s]))return!0;return!1}t(l_e,"hasBinary");function _nr(i){let n=[],s=i.data,c=i;return c.data=cft(s,n),c.attachments=n.length,{packet:c,buffers:n}}t(_nr,"deconstructPacket");function cft(i,n){if(!i)return i;if(u_e(i)){let s={_placeholder:!0,num:n.length};return n.push(i),s}else if(Array.isArray(i)){let s=new Array(i.length);for(let c=0;c<i.length;c++)s[c]=cft(i[c],n);return s}else if(typeof i=="object"&&!(i instanceof Date)){let s={};for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&(s[c]=cft(i[c],n));return s}return i}t(cft,"_deconstructPacket");function mnr(i,n){return i.data=lft(i.data,n),delete i.attachments,i}t(mnr,"reconstructPacket");function lft(i,n){if(!i)return i;if(i&&i._placeholder===!0){if(typeof i.num=="number"&&i.num>=0&&i.num<n.length)return n[i.num];throw new Error("illegal attachments")}else if(Array.isArray(i))for(let s=0;s<i.length;s++)i[s]=lft(i[s],n);else if(typeof i=="object")for(let s in i)Object.prototype.hasOwnProperty.call(i,s)&&(i[s]=lft(i[s],n));return i}t(lft,"_reconstructPacket");var gnr=uc(DO(),1);var uft=(0,gnr.default)("socket.io-parser"),Anr=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ynr=5,Mu;(function(i){i[i.CONNECT=0]="CONNECT",i[i.DISCONNECT=1]="DISCONNECT",i[i.EVENT=2]="EVENT",i[i.ACK=3]="ACK",i[i.CONNECT_ERROR=4]="CONNECT_ERROR",i[i.BINARY_EVENT=5]="BINARY_EVENT",i[i.BINARY_ACK=6]="BINARY_ACK"})(Mu||(Mu={}));var mft=class mft{constructor(n){this.replacer=n}encode(n){return uft("encoding packet %j",n),(n.type===Mu.EVENT||n.type===Mu.ACK)&&l_e(n)?this.encodeAsBinary({type:n.type===Mu.EVENT?Mu.BINARY_EVENT:Mu.BINARY_ACK,nsp:n.nsp,data:n.data,id:n.id}):[this.encodeAsString(n)]}encodeAsString(n){let s=""+n.type;return(n.type===Mu.BINARY_EVENT||n.type===Mu.BINARY_ACK)&&(s+=n.attachments+"-"),n.nsp&&n.nsp!=="/"&&(s+=n.nsp+","),n.id!=null&&(s+=n.id),n.data!=null&&(s+=JSON.stringify(n.data,this.replacer)),uft("encoded %j as %s",n,s),s}encodeAsBinary(n){let s=_nr(n),c=this.encodeAsString(s.packet),u=s.buffers;return u.unshift(c),u}};t(mft,"Encoder");var fft=mft,Kke=class Kke extends hnr.Emitter{constructor(n){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof n=="function"?{reviver:n}:n)}add(n){let s;if(typeof n=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");s=this.decodeString(n);let c=s.type===Mu.BINARY_EVENT;c||s.type===Mu.BINARY_ACK?(s.type=c?Mu.EVENT:Mu.ACK,this.reconstructor=new dft(s),s.attachments===0&&super.emitReserved("decoded",s)):super.emitReserved("decoded",s)}else if(u_e(n)||n.base64)if(this.reconstructor)s=this.reconstructor.takeBinaryData(n),s&&(this.reconstructor=null,super.emitReserved("decoded",s));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+n)}decodeString(n){let s=0,c={type:Number(n.charAt(0))};if(Mu[c.type]===void 0)throw new Error("unknown packet type "+c.type);if(c.type===Mu.BINARY_EVENT||c.type===Mu.BINARY_ACK){let _=s+1;for(;n.charAt(++s)!=="-"&&s!=n.length;);let g=n.substring(_,s);if(g!=Number(g)||n.charAt(s)!=="-")throw new Error("Illegal attachments");let E=Number(g);if(!vnr(E)||E<0)throw new Error("Illegal attachments");if(E>this.opts.maxAttachments)throw new Error("too many attachments");c.attachments=E}if(n.charAt(s+1)==="/"){let _=s+1;for(;++s&&!(n.charAt(s)===","||s===n.length););c.nsp=n.substring(_,s)}else c.nsp="/";let u=n.charAt(s+1);if(u!==""&&Number(u)==u){let _=s+1;for(;++s;){let g=n.charAt(s);if(g==null||Number(g)!=g){--s;break}if(s===n.length)break}c.id=Number(n.substring(_,s+1))}if(n.charAt(++s)){let _=this.tryParse(n.substr(s));if(Kke.isPayloadValid(c.type,_))c.data=_;else throw new Error("invalid payload")}return uft("decoded %s as %j",n,c),c}tryParse(n){try{return JSON.parse(n,this.opts.reviver)}catch{return!1}}static isPayloadValid(n,s){switch(n){case Mu.CONNECT:return Zke(s);case Mu.DISCONNECT:return s===void 0;case Mu.CONNECT_ERROR:return typeof s=="string"||Zke(s);case Mu.EVENT:case Mu.BINARY_EVENT:return Array.isArray(s)&&(typeof s[0]=="number"||typeof s[0]=="string"&&Anr.indexOf(s[0])===-1);case Mu.ACK:case Mu.BINARY_ACK:return Array.isArray(s)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}};t(Kke,"Decoder");var pft=Kke,hft=class hft{constructor(n){this.packet=n,this.buffers=[],this.reconPack=n}takeBinaryData(n){if(this.buffers.push(n),this.buffers.length===this.reconPack.attachments){let s=mnr(this.reconPack,this.buffers);return this.finishedReconstruction(),s}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};t(hft,"BinaryReconstructor");var dft=hft;function xyn(i){return typeof i=="string"}t(xyn,"isNamespaceValid");var vnr=Number.isInteger||function(i){return typeof i=="number"&&isFinite(i)&&Math.floor(i)===i};function kyn(i){return i===void 0||vnr(i)}t(kyn,"isAckIdValid");function Zke(i){return Object.prototype.toString.call(i)==="[object Object]"}t(Zke,"isObject");function Dyn(i,n){switch(i){case Mu.CONNECT:return n===void 0||Zke(n);case Mu.DISCONNECT:return n===void 0;case Mu.EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&Anr.indexOf(n[0])===-1);case Mu.ACK:return Array.isArray(n);case Mu.CONNECT_ERROR:return typeof n=="string"||Zke(n);default:return!1}}t(Dyn,"isDataValid");function Nyn(i){return xyn(i.nsp)&&kyn(i.id)&&Dyn(i.type,i.data)}t(Nyn,"isPacketValid");function ZS(i,n,s){return i.on(n,s),t(function(){i.off(n,s)},"subDestroy")}t(ZS,"on");var bnr=uc(hV(),1),Enr=uc(DO(),1);var R1=(0,Enr.default)("socket.io-client:socket"),Pyn=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),gft=class gft extends bnr.Emitter{constructor(n,s,c){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=n,this.nsp=s,c&&c.auth&&(this.auth=c.auth),this._opts=Object.assign({},c),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let n=this.io;this.subs=[ZS(n,"open",this.onopen.bind(this)),ZS(n,"packet",this.onpacket.bind(this)),ZS(n,"error",this.onerror.bind(this)),ZS(n,"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(...n){return n.unshift("message"),this.emit.apply(this,n),this}emit(n,...s){var c,u,_;if(Pyn.hasOwnProperty(n))throw new Error('"'+n.toString()+'" is a reserved event name');if(s.unshift(n),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(s),this;let g={type:Mu.EVENT,data:s};if(g.options={},g.options.compress=this.flags.compress!==!1,typeof s[s.length-1]=="function"){let M=this.ids++;R1("emitting packet with ack id %d",M);let X=s.pop();this._registerAckCallback(M,X),g.id=M}let E=(u=(c=this.io.engine)===null||c===void 0?void 0:c.transport)===null||u===void 0?void 0:u.writable,x=this.connected&&!(!((_=this.io.engine)===null||_===void 0)&&_._hasPingExpired());return this.flags.volatile&&!E?R1("discard packet as the transport is not currently writable"):x?(this.notifyOutgoingListeners(g),this.packet(g)):this.sendBuffer.push(g),this.flags={},this}_registerAckCallback(n,s){var c;let u=(c=this.flags.timeout)!==null&&c!==void 0?c:this._opts.ackTimeout;if(u===void 0){this.acks[n]=s;return}let _=this.io.setTimeoutFn(()=>{delete this.acks[n];for(let E=0;E<this.sendBuffer.length;E++)this.sendBuffer[E].id===n&&(R1("removing packet with ack id %d from the buffer",n),this.sendBuffer.splice(E,1));R1("event with ack id %d has timed out after %d ms",n,u),s.call(this,new Error("operation has timed out"))},u),g=t((...E)=>{this.io.clearTimeoutFn(_),s.apply(this,E)},"fn");g.withError=!0,this.acks[n]=g}emitWithAck(n,...s){return new Promise((c,u)=>{let _=t((g,E)=>g?u(g):c(E),"fn");_.withError=!0,s.push(_),this.emit(n,...s)})}_addToQueue(n){let s;typeof n[n.length-1]=="function"&&(s=n.pop());let c={id:this._queueSeq++,tryCount:0,pending:!1,args:n,flags:Object.assign({fromQueue:!0},this.flags)};n.push((u,..._)=>c!==this._queue[0]?R1("packet [%d] already acknowledged",c.id):(u!==null?c.tryCount>this._opts.retries&&(R1("packet [%d] is discarded after %d tries",c.id,c.tryCount),this._queue.shift(),s&&s(u)):(R1("packet [%d] was successfully sent",c.id),this._queue.shift(),s&&s(null,..._)),c.pending=!1,this._drainQueue())),this._queue.push(c),this._drainQueue()}_drainQueue(n=!1){if(R1("draining queue"),!this.connected||this._queue.length===0)return;let s=this._queue[0];if(s.pending&&!n){R1("packet [%d] has already been sent and is waiting for an ack",s.id);return}s.pending=!0,s.tryCount++,R1("sending packet [%d] (try n\xB0%d)",s.id,s.tryCount),this.flags=s.flags,this.emit.apply(this,s.args)}packet(n){n.nsp=this.nsp,this.io._packet(n)}onopen(){R1("transport is open - connecting"),typeof this.auth=="function"?this.auth(n=>{this._sendConnectPacket(n)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(n){this.packet({type:Mu.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},n):n})}onerror(n){this.connected||this.emitReserved("connect_error",n)}onclose(n,s){R1("close (%s)",n),this.connected=!1,delete this.id,this.emitReserved("disconnect",n,s),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(n=>{if(!this.sendBuffer.some(c=>String(c.id)===n)){let c=this.acks[n];delete this.acks[n],c.withError&&c.call(this,new Error("socket has been disconnected"))}})}onpacket(n){if(n.nsp===this.nsp)switch(n.type){case Mu.CONNECT:n.data&&n.data.sid?this.onconnect(n.data.sid,n.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 Mu.EVENT:case Mu.BINARY_EVENT:this.onevent(n);break;case Mu.ACK:case Mu.BINARY_ACK:this.onack(n);break;case Mu.DISCONNECT:this.ondisconnect();break;case Mu.CONNECT_ERROR:this.destroy();let c=new Error(n.data.message);c.data=n.data.data,this.emitReserved("connect_error",c);break}}onevent(n){let s=n.data||[];R1("emitting event %j",s),n.id!=null&&(R1("attaching ack callback to event"),s.push(this.ack(n.id))),this.connected?this.emitEvent(s):this.receiveBuffer.push(Object.freeze(s))}emitEvent(n){if(this._anyListeners&&this._anyListeners.length){let s=this._anyListeners.slice();for(let c of s)c.apply(this,n)}super.emit.apply(this,n),this._pid&&n.length&&typeof n[n.length-1]=="string"&&(this._lastOffset=n[n.length-1])}ack(n){let s=this,c=!1;return function(...u){c||(c=!0,R1("sending ack %j",u),s.packet({type:Mu.ACK,id:n,data:u}))}}onack(n){let s=this.acks[n.id];if(typeof s!="function"){R1("bad ack %s",n.id);return}delete this.acks[n.id],R1("calling ack %s with %j",n.id,n.data),s.withError&&n.data.unshift(null),s.apply(this,n.data)}onconnect(n,s){R1("socket connected with id %s",n),this.id=n,this.recovered=s&&this._pid===s,this._pid=s,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(n=>this.emitEvent(n)),this.receiveBuffer=[],this.sendBuffer.forEach(n=>{this.notifyOutgoingListeners(n),this.packet(n)}),this.sendBuffer=[]}ondisconnect(){R1("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(n=>n()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&(R1("performing disconnect (%s)",this.nsp),this.packet({type:Mu.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(n){return this.flags.compress=n,this}get volatile(){return this.flags.volatile=!0,this}timeout(n){return this.flags.timeout=n,this}onAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(n),this}prependAny(n){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(n),this}offAny(n){if(!this._anyListeners)return this;if(n){let s=this._anyListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(n),this}prependAnyOutgoing(n){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(n),this}offAnyOutgoing(n){if(!this._anyOutgoingListeners)return this;if(n){let s=this._anyOutgoingListeners;for(let c=0;c<s.length;c++)if(n===s[c])return s.splice(c,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(n){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let s=this._anyOutgoingListeners.slice();for(let c of s)c.apply(this,n.data)}}};t(gft,"Socket");var Dee=gft;function SV(i){i=i||{},this.ms=i.min||100,this.max=i.max||1e4,this.factor=i.factor||2,this.jitter=i.jitter>0&&i.jitter<=1?i.jitter:0,this.attempts=0}t(SV,"Backoff");SV.prototype.duration=function(){var i=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var n=Math.random(),s=Math.floor(n*this.jitter*i);i=Math.floor(n*10)&1?i+s:i-s}return Math.min(i,this.max)|0};SV.prototype.reset=function(){this.attempts=0};SV.prototype.setMin=function(i){this.ms=i};SV.prototype.setMax=function(i){this.max=i};SV.prototype.setJitter=function(i){this.jitter=i};var Cnr=uc(hV(),1),Snr=uc(DO(),1);var Ly=(0,Snr.default)("socket.io-client:manager"),Aft=class Aft extends Cnr.Emitter{constructor(n,s){var c;super(),this.nsps={},this.subs=[],n&&typeof n=="object"&&(s=n,n=void 0),s=s||{},s.path=s.path||"/socket.io",this.opts=s,mN(this,s),this.reconnection(s.reconnection!==!1),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor((c=s.randomizationFactor)!==null&&c!==void 0?c:.5),this.backoff=new SV({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(s.timeout==null?2e4:s.timeout),this._readyState="closed",this.uri=n;let u=s.parser||_ft;this.encoder=new u.Encoder,this.decoder=new u.Decoder,this._autoConnect=s.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(n){return arguments.length?(this._reconnection=!!n,n||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(n){return n===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=n,this)}reconnectionDelay(n){var s;return n===void 0?this._reconnectionDelay:(this._reconnectionDelay=n,(s=this.backoff)===null||s===void 0||s.setMin(n),this)}randomizationFactor(n){var s;return n===void 0?this._randomizationFactor:(this._randomizationFactor=n,(s=this.backoff)===null||s===void 0||s.setJitter(n),this)}reconnectionDelayMax(n){var s;return n===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=n,(s=this.backoff)===null||s===void 0||s.setMax(n),this)}timeout(n){return arguments.length?(this._timeout=n,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(n){if(Ly("readyState %s",this._readyState),~this._readyState.indexOf("open"))return this;Ly("opening %s",this.uri),this.engine=new kee(this.uri,this.opts);let s=this.engine,c=this;this._readyState="opening",this.skipReconnect=!1;let u=ZS(s,"open",function(){c.onopen(),n&&n()}),_=t(E=>{Ly("error"),this.cleanup(),this._readyState="closed",this.emitReserved("error",E),n?n(E):this.maybeReconnectOnOpen()},"onError"),g=ZS(s,"error",_);if(this._timeout!==!1){let E=this._timeout;Ly("connect attempt will timeout after %d",E);let x=this.setTimeoutFn(()=>{Ly("connect attempt timed out after %d",E),u(),_(new Error("timeout")),s.close()},E);this.opts.autoUnref&&x.unref(),this.subs.push(()=>{this.clearTimeoutFn(x)})}return this.subs.push(u),this.subs.push(g),this}connect(n){return this.open(n)}onopen(){Ly("open"),this.cleanup(),this._readyState="open",this.emitReserved("open");let n=this.engine;this.subs.push(ZS(n,"ping",this.onping.bind(this)),ZS(n,"data",this.ondata.bind(this)),ZS(n,"error",this.onerror.bind(this)),ZS(n,"close",this.onclose.bind(this)),ZS(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(n){try{this.decoder.add(n)}catch(s){this.onclose("parse error",s)}}ondecoded(n){_N(()=>{this.emitReserved("packet",n)},this.setTimeoutFn)}onerror(n){Ly("error",n),this.emitReserved("error",n)}socket(n,s){let c=this.nsps[n];return c?this._autoConnect&&!c.active&&c.connect():(c=new Dee(this,n,s),this.nsps[n]=c),c}_destroy(n){let s=Object.keys(this.nsps);for(let c of s)if(this.nsps[c].active){Ly("socket %s is still active, skipping close",c);return}this._close()}_packet(n){Ly("writing packet %j",n);let s=this.encoder.encode(n);for(let c=0;c<s.length;c++)this.engine.write(s[c],n.options)}cleanup(){Ly("cleanup"),this.subs.forEach(n=>n()),this.subs.length=0,this.decoder.destroy()}_close(){Ly("disconnect"),this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(n,s){var c;Ly("closed due to %s",n),this.cleanup(),(c=this.engine)===null||c===void 0||c.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",n,s),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let n=this;if(this.backoff.attempts>=this._reconnectionAttempts)Ly("reconnect failed"),this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let s=this.backoff.duration();Ly("will wait %dms before reconnect attempt",s),this._reconnecting=!0;let c=this.setTimeoutFn(()=>{n.skipReconnect||(Ly("attempting reconnect"),this.emitReserved("reconnect_attempt",n.backoff.attempts),!n.skipReconnect&&n.open(u=>{u?(Ly("reconnect attempt error"),n._reconnecting=!1,n.reconnect(),this.emitReserved("reconnect_error",u)):(Ly("reconnect success"),n.onreconnect())}))},s);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}}onreconnect(){let n=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",n)}};t(Aft,"Manager");var Nee=Aft;var Inr=uc(DO(),1);var wnr=(0,Inr.default)("socket.io-client"),f_e={};function p_e(i,n){typeof i=="object"&&(n=i,i=void 0),n=n||{};let s=pnr(i,n.path||"/socket.io"),c=s.source,u=s.id,_=s.path,g=f_e[u]&&_ in f_e[u].nsps,E=n.forceNew||n["force new connection"]||n.multiplex===!1||g,x;return E?(wnr("ignoring socket cache for %s",c),x=new Nee(c,n)):(f_e[u]||(wnr("new io instance for %s",c),f_e[u]=new Nee(c,n)),x=f_e[u]),s.query&&!n.query&&(n.query=s.queryKey),x.socket(s.path,n)}t(p_e,"lookup");Object.assign(p_e,{Manager:Nee,Socket:Dee,io:p_e,connect:p_e});var Xke={URL:"http://localhost:3000",NAMESPACE:"auto-recovery",RECONNECTION_ATTEMPTS:5,RECONNECTION_DELAY:1e3},yft=class yft{constructor(n={}){this.socket=null;this.connectionState="disconnected";this.connectionPromise=null;this.resolution=null;this.options=n,this.url=n.url||Xke.URL,this.namespace=n.namespace||Xke.NAMESPACE,this.initializationPromise=this.createInitializationPromise()}createInitializationPromise(){return new Promise((n,s)=>{this.resolveInitialization=c=>n(c),this.rejectInitialization=c=>s(c)}).then(n=>(this.resolution=n,this.log("\u2705 Client initialization successful"),n),n=>{throw this.resolution=n,this.logError("\u274C Client initialization failed:",n),n}).finally(()=>{this.disconnect()})}defineHandlers(n){return n}async startSession(n,s,c){try{if(await this.connect(),this.emit(n,s,u=>{this.resolveInitialization(u)}),c&&c>0){let u=new Promise((_,g)=>{setTimeout(()=>{g(new Error(`Session initialization timed out after ${c}ms`))},c)});return Promise.race([this.initializationPromise,u])}return this.initializationPromise}catch(u){throw this.logError("\u274C Failed to start session:",u),this.rejectInitialization(u),u}}isConnected(){var n;return((n=this.socket)==null?void 0:n.connected)||!1}getConnectionState(){return this.connectionState}success(n){return{success:!0,data:n}}error(n){return{success:!1,error:n}}log(n,...s){this.options.verbose&&console.log(`[${this.namespace}] ${n}`,...s)}logError(n,...s){this.options.verbose&&console.error(`[${this.namespace}] ${n}`,...s)}async connect(){var n;if(this.connectionPromise)return this.connectionPromise;if(this.connectionState==="connected"&&((n=this.socket)!=null&&n.connected))return Promise.resolve();this.connectionState="connecting",this.connectionPromise=this.establishConnection();try{await this.connectionPromise,this.connectionState="connected"}catch(s){throw this.connectionState="disconnected",this.connectionPromise=null,s}return this.connectionPromise}establishConnection(){return new Promise((n,s)=>{let c=!1;try{let u=`${this.url}/${this.namespace}`;this.log(`\u{1F517} Connecting to socket at: ${u}`),this.socket=p_e(u,{autoConnect:!0,reconnection:!0,reconnectionAttempts:Xke.RECONNECTION_ATTEMPTS,reconnectionDelay:Xke.RECONNECTION_DELAY,...this.options.path&&{path:this.options.path}}),this.setupConnectionHandlers(n,s,c)}catch(u){this.logError("\u274C Failed to create socket connection:",u),c||s(u)}})}setupConnectionHandlers(n,s,c){if(!this.socket)return;let u={resolve:n,reject:s,connectionResolved:c};this.socket.on("connect",()=>this.handleConnect(u)),this.socket.on("reconnect",()=>this.handleReconnect()),this.socket.on("connect_error",_=>this.handleConnectError(_,u)),this.socket.on("disconnect",_=>this.handleDisconnect(_,u)),this.socket.io.on("reconnect_attempt",_=>this.handleReconnectAttempt(_)),this.socket.io.on("reconnect_error",_=>this.handleReconnectError(_)),this.socket.io.on("reconnect_failed",()=>this.handleReconnectFailed(u))}handleConnect(n){this.log("\u2705 Connected to socket"),this.connectionState="connected",this.setupEventHandlers(),n.connectionResolved||(n.connectionResolved=!0,n.resolve())}handleReconnect(){this.log("\u2705 Reconnected to socket"),this.connectionState="connected"}handleConnectError(n,s){var c;this.logError("\u274C Connection error:",n),this.connectionState="disconnected",!s.connectionResolved&&((c=this.socket)==null?void 0:c.disconnected)!==!1&&(s.connectionResolved=!0,s.reject(n))}handleDisconnect(n,s){this.log("\u{1F50C} Disconnected from socket:",n),this.connectionState="disconnected";let c=new Error(`Socket disconnected: ${n}`),u=!1;this.resolution===null&&n==="io server disconnect"&&(this.rejectInitialization(c),u=!0),!s.connectionResolved&&(n==="io server disconnect"||n==="transport close")&&(s.connectionResolved=!0,s.reject(c)),!u&&this.resolution===null&&this.connectionState==="disconnected"&&this.rejectInitialization(c)}handleReconnectAttempt(n){this.log(`\u{1F504} Reconnection attempt #${n}`),this.connectionState="reconnecting"}handleReconnectError(n){this.logError("\u274C Reconnection attempt failed:",n)}handleReconnectFailed(n){this.logError("\u274C All reconnection attempts failed"),this.connectionState="disconnected",this.resolution===null&&this.rejectInitialization("All reconnection attempts failed"),n.connectionResolved||(n.connectionResolved=!0,n.reject(new Error("All reconnection attempts failed")))}setupEventHandlers(){if(!this.socket){this.logError("\u274C Cannot setup event handlers: socket is null");return}this.log("\u2705 Setting up event handlers"),this.socket.on("__call",this.handleGatewayCall.bind(this))}async handleGatewayCall(n,s){this.log(`\u{1F4E5} Gateway called method: ${n.key} with args:`,n.args);try{let c=this.validateGatewayCall(n);if(c){s(c);return}let u=this.handlers[n.key];if(!u){let g=`No handler registered for method: ${n.key}`;this.logError(`\u274C ${g}`),s(this.error(g));return}let _=await u(...n.args);s(this.success(_))}catch(c){this.logError("\u274C Error handling gateway call:",c),s(this.error(c.message||"Unknown error occurred"))}}validateGatewayCall(n){return n.key?Array.isArray(n.args)?null:(this.logError("\u274C Received call with invalid args"),this.error("Args must be an array")):(this.logError("\u274C Received call with undefined key"),this.error("Key is undefined"))}emit(n,s,c){if(!this.socket){this.logError("\u274C Cannot emit: socket is null");return}this.log(`\u{1F4E4} Emitting event: ${n}`),this.socket.emit(n,s,u=>{c(u)})}disconnect(){this.connectionState!=="shutting_down"&&(this.connectionState="shutting_down",this.log("\u{1F50C} Initiating disconnect"),this.socket&&(this.socket.disconnect(),this.socket=null),this.connectionPromise=null,this.connectionState="disconnected",this.log("\u2705 Disconnected successfully"))}};t(yft,"AbstractClient");var e3e=yft;var Tnr,xnr,knr,Dnr,Nnr,Pnr,Bnr,Fnr,r3e=class r3e extends(Fnr=e3e,Bnr=Oh.names.getState,Pnr=Oh.names.invokeCode,Nnr=Oh.names.final_result,Dnr=Oh.names.wait,knr=Oh.names.getElementScreenshot,xnr=Oh.names.listPages,Tnr=Oh.names.switchPage,Fnr){constructor(s,c){super({verbose:Yu.testRun.autoRecovery.verboseConsoleLog,url:c.config.apiURL,namespace:"auto-recovery",path:"/auto-recovery/socket.io"});this.utils=s;this.initData=c;this.stepsThoughts=[];this.handlers=this.defineHandlers({callLangChainTool:t(async(s,c)=>{if(!this[s])throw new Error(`Tool ${s} not found`);return c.thought&&this.stepsThoughts.push(c.thought),await this[s].invoke(c)},"callLangChainTool"),getStatus:t(async s=>({sessionId:s,status:"active",data:{message:"Status retrieved successfully"}}),"getStatus")});this[Bnr]=e5.buildTool(Oh,Oh.names.getState,async s=>this.getStateHandler(s));this[Pnr]=e5.buildTool(Oh,Oh.names.invokeCode,async s=>this.invokeCodeHandler(s));this[Nnr]=e5.buildTool(Oh,Oh.names.final_result,async s=>this.finalResultHandler(s));this[Dnr]=e5.buildTool(Oh,Oh.names.wait,async s=>this.waitHandler(s));this[knr]=e5.buildTool(Oh,Oh.names.getElementScreenshot,async s=>this.getElementScreenshotHandler(s));this[xnr]=e5.buildTool(Oh,Oh.names.listPages,async s=>this.listPagesHandler(s));this[Tnr]=e5.buildTool(Oh,Oh.names.switchPage,async s=>this.switchPageHandler(s))}async init(){let s={...this.initData,version:Oh.version};return await this.startSession("initialize",s).catch(c=>{this.utils.analytics.ARError({error:c.message});let u="Auto-Recovery attempt finished unsuccessfully";return this.utils.createChecksumStep({title:u,withError:!0}),this.utils.addAutoRecoveryErrorToReport(u,!1),{finalThought:u,stepsThoughts:[],result:"failed"}})}static async build(s){let c=await s.buildFallbackData();return new r3e(s,c)}async invokeCodeHandler(s){let c,u=this.utils.activePageGuid,g=!!(s.pageId&&s.pageId!==u?await this.utils.getPageById(s.pageId):void 0);return await this.utils.runConditionallyWithinStep(!0,s.thought||"Invoke Code",async()=>{try{g&&await this.utils.setActivePage(s.pageId);let E=await this.utils.invokeCode(s.code);this.utils.createChecksumStep({title:"Code Invoked Successfully"}),c={success:!0,invokeCodeResult:`invokeCodeResult: ${E.result}`,appState:(await this.utils.buildFallbackData()).applicationState,actionEffects:E.effects}}catch(E){c={success:!1,invokeCodeResult:`Error while invoking code: ${E}`,appState:(await this.utils.buildFallbackData()).applicationState}}finally{if(g&&u)try{await this.utils.setActivePage(u)}catch(E){console.warn("Failed to switch back to original page:",E)}}}),c}async getStateHandler(s){return this.utils.createChecksumStep({title:s.thought}),this.utils.analytics.ARGetState(s.thought),{success:!0,appState:await this.utils.captureApplicationState(s.pageId,s.includeAllPages)}}async finalResultHandler(s){let c=s.result==="pass",u=this.initData.type==="assertion"?c?"soft_assertion":"hard_assertion":c?"finish":"failed",_={finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts};await Promise.resolve(),this.resolveInitialization(_);try{this.utils.analytics.ARFinalResult({finalThought:s.thought,result:u,stepsThoughts:this.stepsThoughts})}catch(g){console.warn("Failed to record auto-recovery final-result analytics:",g)}try{this.utils.addAutoRecoveryErrorToReport(s.thought,c)}catch(g){console.warn("Failed to add auto-recovery result to report:",g)}}async getElementScreenshotHandler(s){return{success:!0,screenshot:await this.utils.getScreenshotForElement(s.checksumId)}}async waitHandler(s){await new Promise(u=>setTimeout(u,s.time||5e3));let c=await this.utils.buildFallbackData();return{success:!0,waitResult:`waited for ${s.time} seconds, the current HTML of the application after the wait is: ${c.applicationState.reducedHTML}`}}async listPagesHandler(s){s.thought&&this.utils.createChecksumStep({title:s.thought});let c=await this.utils.pageInteractor.getTabsInfo(),u=c.map((g,E)=>`${E+1}. ${g.title||"Untitled"} (${g.url})
747
747
  - Page ID: ${g.id}
748
748
  - Active: ${g.active?"Yes":"No"}
749
749
  - New: ${g.new?"Yes":"No"}${g.lastAction?`
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "url": "https://github.com/checksum-ai/checksum-ai-monorepo/issues"
44
44
  },
45
45
  "homepage": "https://github.com/checksum-ai/checksum-ai-monorepo/tree/main/packages/runtime#readme",
46
- "version": "4.1.1-beta.8"
46
+ "version": "4.1.1-beta.9"
47
47
  }