| 52 | `)}function zI6(){if(zM7)return;if(zM7=!0,wM7(),_I6){let q=OM7(),K=S$5(q);X8().mkdirSync(K),$j(q,_M7(),{encoding:"utf8",flush:!0}),N("Startup profiling report:"),N(_M7())}}function I$5(){return _I6}function OM7(){return C$5(c1(),"startup-perf",`${N8()}.txt`)}function wM7(){if(!YM7)return;let K=wE().getEntriesByType("mark");if(K.length===0)return;let _=new Map;for(let Y of K)_.set(Y.name,Y.startTime);let z={};for(let[Y,[$,A]]of Object.entries(x$5)){let O=_.get($),w=_.get(A);if(O!==void 0&&w!==void 0)z[`${Y}_ms`]=Math.round(w-O)}z.checkpoint_count=K.length,d("tengu_startup_perf",z)}var _I6,b$5=0.005,YM7,$M7,AM7,x$5,zM7=!1;var Cx=y(()=>{v8();k8();_8();m8();e7();Z98();l8();_I6=i6(process.env.CLAUDE_CODE_PROFILE_STARTUP),YM7=Math.random()<b$5,$M7=_I6||YM7,AM7=[],x$5={import_time:["cli_entry","main_tsx_imports_loaded"],init_time:["init_function_start","init_function_end"],settings_time:["eagerLoadSettings_start","eagerLoadSettings_end"],total_time:["cli_entry","main_after_run"]};if($M7)U4("profiler_initialized")});var Ic=m((a9$,MM7)=>{var HM7=["nodebuffer","arraybuffer","fragments"],JM7=typeof Blob<"u";if(JM7)HM7.push("blob");MM7.exports={BINARY_TYPES:HM7,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:JM7,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var YI6=m((s9$,G98)=>{var{EMPTY_BUFFER:u$5}=Ic(),bo8=Buffer[Symbol.species];function m$5(q,K){if(q.length===0)return u$5;if(q.length===1)return q[0];let _=Buffer.allocUnsafe(K),z=0;for(let Y=0;Y<q.length;Y++){let $=q[Y];_.set($,z),z+=$.length}if(z<K)return new bo8(_.buffer,_.byteOffset,z);return _}function XM7(q,K,_,z,Y){for(let $=0;$<Y;$++)_[z+$]=q[$]^K[$&3]}function PM7(q,K){for(let _=0;_<q.length;_++)q[_]^=K[_&3]}function p$5(q){if(q.length===q.buffer.byteLength)return q.buffer;return q.buffer.slice(q.byteOffset,q.byteOffset+q.length)}function xo8(q){if(xo8.readOnly=!0,Buffer.isBuffer(q))return q;let K;if(q instanceof ArrayBuffer)K=new bo8(q);else if(ArrayBuffer.isView(q))K=new bo8(q.buffer,q.byteOffset,q.byteLength);else K=Buffer.from(q),xo8.readOnly=!1;return K}G98.exports={concat:m$5,mask:XM7,toArrayBuffer:p$5,toBuffer:xo8,unmask:PM7};if(!process.env.WS_NO_BUFFER_UTIL)try{let q=(()=>{throw new Error("Cannot require module "+"bufferutil");})();G98.exports.mask=function(K,_,z,Y,$){if($<48)XM7(K,_,z,Y,$);else q.mask(K,_,z,Y,$)},G98.exports.unmask=function(K,_){if(K.length<32)PM7(K,_);else q.unmask(K,_)}}catch(q){}});var ZM7=m((t9$,fM7)=>{var WM7=Symbol("kDone"),Io8=Symbol("kRun");class DM7{constructor(q){this[WM7]=()=>{this.pending--,this[Io8]()},this.concurrency=q||1/0,this.jobs=[],this.pending=0}add(q){this.jobs.push(q),this[Io8]()}[Io8](){if(this.pending===this.concurrency)return;if(this.jobs.length){let q=this.jobs.shift();this.pending++,q(this[WM7])}}}fM7.exports=DM7});var AI6=m((e9$,VM7)=>{var $I6=U6("zlib"),GM7=YI6(),B$5=ZM7(),{kStatusCode:TM7}=Ic(),g$5=Buffer[Symbol.species],F$5=Buffer.from([0,0,255,255]),v98=Symbol("permessage-deflate"),uc=Symbol("total-length"),YP6=Symbol("callback"),at=Symbol("buffers"),$P6=Symbol("error"),T98;class vM7{constructor(q,K,_){if(this._maxPayload=_|0,this._options=q||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!K,this._deflate=null,this._inflate=null,this.params=null,!T98){let z=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;T98=new B$5(z)}}static get extensionName(){return"permessage-deflate"}offer(){let q={};if(this._options.serverNoContextTakeover)q.server_no_context_takeover=!0;if(this._options.clientNoContextTakeover)q.client_no_context_takeover=!0;if(this._options.serverMaxWindowBits)q.server_max_window_bits=this._options.serverMaxWindowBits;if(this._options.clientMaxWindowBits)q.client_max_window_bits=this._options.clientMaxWindowBits;else if(this._options.clientMaxWindowBits==null)q.client_max_window_bits=!0;return q}accept(q){return q=this.normalizeParams(q),this.params=this._isServer?this.acceptAsServer(q):this.acceptAsClient(q),this.params}cleanup(){if(this._inflate)this._inflate.close(),this._inflate=null;if(this._deflate){let q=this._deflate[YP6];if(this._deflate.close(),this._deflate=null,q)q(Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(q){let K=this._options,_=q.find((z)=>{if(K.serverNoContextTakeover===!1&&z.server_no_context_takeover||z.server_max_window_bits&&(K.serverMaxWindowBits===!1||typeof K.serverMaxWindowBits==="number"&&K.serverMaxWindowBits>z.server_max_window_bits)||typeof K.clientMaxWindowBits==="number"&&!z.client_max_window_bits)return!1;return!0});if(!_)throw Error("None of the extension offers can be accepted");if(K.serverNoContextTakeover)_.server_no_context_takeover=!0;if(K.clientNoContextTakeover)_.client_no_context_takeover=!0;if(typeof K.serverMaxWindowBits==="number")_.server_max_window_bits=K.serverMaxWindowBits;if(typeof K.clientMaxWindowBits==="number")_.client_max_window_bits=K.clientMaxWindowBits;else if(_.client_max_window_bits===!0||K.clientMaxWindowBits===!1)delete _.client_max_window_bits;return _}acceptAsClient(q){let K=q[0];if(this._options.clientNoContextTakeover===!1&&K.client_no_context_takeover)throw Error('Unexpected parameter "client_no_context_takeover"');if(!K.client_max_window_bits){if(typeof this._options.clientMaxWindowBits==="number")K.client_max_window_bits=this._options.clientMaxWindowBits}else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits==="number"&&K.client_max_window_bits>this._options.clientMaxWindowBits)throw Error('Unexpected or invalid parameter "client_max_window_bits"');return K}normalizeParams(q){return q.forEach((K)=>{Object.keys(K).forEach((_)=>{let z=K[_];if(z.length>1)throw Error(`Parameter "${_}" must have only a single value`);if(z=z[0],_==="client_max_window_bits"){if(z!==!0){let Y=+z;if(!Number.isInteger(Y)||Y<8||Y>15)throw TypeError(`Invalid value for parameter "${_}": ${z}`);z=Y}else if(!this._isServer)throw TypeError(`Invalid value for parameter "${_}": ${z}`)}else if(_==="server_max_window_bits"){let Y=+z;if(!Number.isInteger(Y)||Y<8||Y>15)throw TypeError(`Invalid value for parameter "${_}": ${z}`);z=Y}else if(_==="client_no_context_takeover"||_==="server_no_context_takeover"){if(z!==!0)throw TypeError(`Invalid value for parameter "${_}": ${z}`)}else throw Error(`Unknown parameter "${_}"`);K[_]=z})}),q}decompress(q,K,_){T98.add((z)=>{this._decompress(q,K,(Y,$)=>{z(),_(Y,$)})})}compress(q,K,_){T98.add((z)=>{this._compress(q,K,(Y,$)=>{z(),_(Y,$)})})}_decompress(q,K,_){let z=this._isServer?"client":"server";if(!this._inflate){let Y=`${z}_max_window_bits`,$=typeof this.params[Y]!=="number"?$I6.Z_DEFAULT_WINDOWBITS:this.params[Y];this._inflate=$I6.createInflateRaw({...this._options.zlibInflateOptions,windowBits:$}),this._inflate[v98]=this,this._inflate[uc]=0,this._inflate[at]=[],this._inflate.on("error",Q$5),this._inflate.on("data",kM7)}if(this._inflate[YP6]=_,this._inflate.write(q),K)this._inflate.write(F$5);this._inflate.flush(()=>{let Y=this._inflate[$P6];if(Y){this._inflate.close(),this._inflate=null,_(Y);return}let $=GM7.concat(this._inflate[at],this._inflate[uc]);if(this._inflate._readableState.endEmitted)this._inflate.close(),this._inflate=null;else if(this._inflate[uc]=0,this._inflate[at]=[],K&&this.params[`${z}_no_context_takeover`])this._inflate.reset();_(null,$)})}_compress(q,K,_){let z=this._isServer?"server":"client";if(!this._deflate){let Y=`${z}_max_window_bits`,$=typeof this.params[Y]!=="number"?$I6.Z_DEFAULT_WINDOWBITS:this.params[Y];this._deflate=$I6.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:$}),this._deflate[uc]=0,this._deflate[at]=[],this._deflate.on("data",U$5)}this._deflate[YP6]=_,this._deflate.write(q),this._deflate.flush($I6.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let Y=GM7.concat(this._deflate[at],this._deflate[uc]);if(K)Y=new g$5(Y.buffer,Y.byteOffset,Y.length-4);if(this._deflate[YP6]=null,this._deflate[uc]=0,this._deflate[at]=[],K&&this.params[`${z}_no_context_takeover`])this._deflate.reset();_(null,Y)})}}VM7.exports=vM7;function U$5(q){this[at].push(q),this[uc]+=q.length}function kM7(q){if(this[uc]+=q.length,this[v98]._maxPayload<1||this[uc]<=this[v98]._maxPayload){this[at].push(q);return}this[$P6]=RangeError("Max payload size exceeded"),this[$P6].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[$P6][TM7]=1009,this.removeListener("data",kM7),this.reset()}function Q$5(q){if(this[v98]._inflate=null,this[$P6]){this[YP6](this[$P6]);return}q[TM7]=1007,this[YP6](q)}});var AP6=m((q_$,k98)=>{var{isUtf8:NM7}=U6("buffer"),{hasBlob:d$5}=Ic(),c$5=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function l$5(q){return q>=1000&&q<=1014&&q!==1004&&q!==1005&&q!==1006||q>=3000&&q<=4999}function uo8(q){let K=q.length,_=0;while(_<K)if((q[_]&128)===0)_++;else if((q[_]&224)===192){if(_+1===K||(q[_+1]&192)!==128||(q[_]&254)===192)return!1;_+=2}else if((q[_]&240)===224){if(_+2>=K||(q[_+1]&192)!==128||(q[_+2]&192)!==128||q[_]===224&&(q[_+1]&224)===128||q[_]===237&&(q[_+1]&224)===160)return!1;_+=3}else if((q[_]&248)===240){if(_+3>=K||(q[_+1]&192)!==128||(q[_+2]&192)!==128||(q[_+3]&192)!==128||q[_]===240&&(q[_+1]&240)===128||q[_]===244&&q[_+1]>143||q[_]>244)return!1;_+=4}else return!1;return!0}function n$5(q){return d$5&&typeof q==="object"&&typeof q.arrayBuffer==="function"&&typeof q.type==="string"&&typeof q.stream==="function"&&(q[Symbol.toStringTag]==="Blob"||q[Symbol.toStringTag]==="File")}k98.exports={isBlob:n$5,isValidStatusCode:l$5,isValidUTF8:uo8,tokenChars:c$5};if(NM7)k98.exports.isValidUTF8=function(q){return q.length<24?uo8(q):NM7(q)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let q=(()=>{throw new Error("Cannot require module "+"utf-8-validate");})();k98.exports.isValidUTF8=function(K){return K.length<32?uo8(K):q(K)}}catch(q){}});var po8=m((K_$,hM7)=>{var{Writable:i$5}=U6("stream"),yM7=AI6(),{BINARY_TYPES:r$5,EMPTY_BUFFER:EM7,kStatusCode:o$5,kWebSocket:a$5}=Ic(),{concat:mo8,toArrayBuffer:s$5,unmask:t$5}=YI6(),{isValidStatusCode:e$5,isValidUTF8:LM7}=AP6(),V98=Buffer[Symbol.species];class RM7 extends i$5{constructor(q={}){super();this._allowSynchronousEvents=q.allowSynchronousEvents!==void 0?q.allowSynchronousEvents:!0,this._binaryType=q.binaryType||r$5[0],this._extensions=q.extensions||{},this._isServer=!!q.isServer,this._maxPayload=q.maxPayload|0,this._skipUTF8Validation=!!q.skipUTF8Validation,this[a$5]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=0}_write(q,K,_){if(this._opcode===8&&this._state==0)return _();this._bufferedBytes+=q.length,this._buffers.push(q),this.startLoop(_)}consume(q){if(this._bufferedBytes-=q,q===this._buffers[0].length)return this._buffers.shift();if(q<this._buffers[0].length){let _=this._buffers[0];return this._buffers[0]=new V98(_.buffer,_.byteOffset+q,_.length-q),new V98(_.buffer,_.byteOffset,q)}let K=Buffer.allocUnsafe(q);do{let _=this._buffers[0],z=K.length-q;if(q>=_.length)K.set(this._buffers.shift(),z);else K.set(new Uint8Array(_.buffer,_.byteOffset,q),z),this._buffers[0]=new V98(_.buffer,_.byteOffset+q,_.length-q);q-=_.length}while(q>0);return K}startLoop(q){this._loop=!0;do switch(this._state){case 0:this.getInfo(q);break;case 1:this.getPayloadLength16(q);break;case 2:this.getPayloadLength64(q);break;case 3:this.getMask();break;case 4:this.getData(q);break;case 5:case 6:this._loop=!1;return}while(this._loop);if(!this._errored)q()}getInfo(q){if(this._bufferedBytes<2){this._loop=!1;return}let K=this.consume(2);if((K[0]&48)!==0){let z=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");q(z);return}let _=(K[0]&64)===64;if(_&&!this._extensions[yM7.extensionName]){let z=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");q(z);return}if(this._fin=(K[0]&128)===128,this._opcode=K[0]&15,this._payloadLength=K[1]&127,this._opcode===0){if(_){let z=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");q(z);return}if(!this._fragmented){let z=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");q(z);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let z=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");q(z);return}this._compressed=_}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let z=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");q(z);return}if(_){let z=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");q(z);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let z=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");q(z);return}}else{let z=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");q(z);return}if(!this._fin&&!this._fragmented)this._fragmented=this._opcode;if(this._masked=(K[1]&128)===128,this._isServer){if(!this._masked){let z=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");q(z);return}}else if(this._masked){let z=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");q(z);return}if(this._payloadLength===126)this._state=1;else if(this._payloadLength===127)this._state=2;else this.haveLength(q)}getPayloadLength16(q){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(q)}getPayloadLength64(q){if(this._bufferedBytes<8){this._loop=!1;return}let K=this.consume(8),_=K.readUInt32BE(0);if(_>Math.pow(2,21)-1){let z=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");q(z);return}this._payloadLength=_*Math.pow(2,32)+K.readUInt32BE(4),this.haveLength(q)}haveLength(q){if(this._payloadLength&&this._opcode<8){if(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0){let K=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");q(K);return}}if(this._masked)this._state=3;else this._state=4}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=4}getData(q){let K=EM7;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}if(K=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0)t$5(K,this._mask)}if(this._opcode>7){this.controlMessage(K,q);return}if(this._compressed){this._state=5,this.decompress(K,q);return}if(K.length)this._messageLength=this._totalPayloadLength,this._fragments.push(K);this.dataMessage(q)}decompress(q,K){this._extensions[yM7.extensionName].decompress(q,this._fin,(z,Y)=>{if(z)return K(z);if(Y.length){if(this._messageLength+=Y.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let $=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");K($);return}this._fragments.push(Y)}if(this.dataMessage(K),this._state===0)this.startLoop(K)})}dataMessage(q){if(!this._fin){this._state=0;return}let K=this._messageLength,_=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let z;if(this._binaryType==="nodebuffer")z=mo8(_,K);else if(this._binaryType==="arraybuffer")z=s$5(mo8(_,K));else if(this._binaryType==="blob")z=new Blob(_);else z=_;if(this._allowSynchronousEvents)this.emit("message",z,!0),this._state=0;else this._state=6,setImmediate(()=>{this.emit("message",z,!0),this._state=0,this.startLoop(q)})}else{let z=mo8(_,K);if(!this._skipUTF8Validation&&!LM7(z)){let Y=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");q(Y);return}if(this._state===5||this._allowSynchronousEvents)this.emit("message",z,!1),this._state=0;else this._state=6,setImmediate(()=>{this.emit("message",z,!1),this._state=0,this.startLoop(q)})}}controlMessage(q,K){if(this._opcode===8){if(q.length===0)this._loop=!1,this.emit("conclude",1005,EM7),this.end();else{let _=q.readUInt16BE(0);if(!e$5(_)){let Y=this.createError(RangeError,`invalid status code ${_}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");K(Y);return}let z=new V98(q.buffer,q.byteOffset+2,q.length-2);if(!this._skipUTF8Validation&&!LM7(z)){let Y=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");K(Y);return}this._loop=!1,this.emit("conclude",_,z),this.end()}this._state=0;return}if(this._allowSynchronousEvents)this.emit(this._opcode===9?"ping":"pong",q),this._state=0;else this._state=6,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",q),this._state=0,this.startLoop(K)})}createError(q,K,_,z,Y){this._loop=!1,this._errored=!0;let $=new q(_?`Invalid WebSocket frame: ${K}`:K);return Error.captureStackTrace($,this.createError),$.code=Y,$[o$5]=z,$}}hM7.exports=RM7});var go8=m((z_$,bM7)=>{var{Duplex:__$}=U6("stream"),{randomFillSync:qA5}=U6("crypto"),SM7=AI6(),{EMPTY_BUFFER:KA5,kWebSocket:_A5,NOOP:zA5}=Ic(),{isBlob:OP6,isValidStatusCode:YA5}=AP6(),{mask:CM7,toBuffer:J96}=YI6(),_h=Symbol("kByteLength"),$A5=Buffer.alloc(4),M96,wP6=8192,bx=0,AA5=1,OA5=2;class st{constructor(q,K,_){if(this._extensions=K||{},_)this._generateMask=_,this._maskBuffer=Buffer.alloc(4);this._socket=q,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=bx,this.onerror=zA5,this[_A5]=void 0}static frame(q,K){let _,z=!1,Y=2,$=!1;if(K.mask){if(_=K.maskBuffer||$A5,K.generateMask)K.generateMask(_);else{if(wP6===8192){if(M96===void 0)M96=Buffer.alloc(8192);qA5(M96,0,8192),wP6=0}_[0]=M96[wP6++],_[1]=M96[wP6++],_[2]=M96[wP6++],_[3]=M96[wP6++]}$=(_[0]|_[1]|_[2]|_[3])===0,Y=6}let A;if(typeof q==="string")if((!K.mask||$)&&K[_h]!==void 0)A=K[_h];else q=Buffer.from(q),A=q.length;else A=q.length,z=K.mask&&K.readOnly&&!$;let O=A;if(A>=65536)Y+=8,O=127;else if(A>125)Y+=2,O=126;let w=Buffer.allocUnsafe(z?A+Y:Y);if(w[0]=K.fin?K.opcode|128:K.opcode,K.rsv1)w[0]|=64;if(w[1]=O,O===126)w.writeUInt16BE(A,2);else if(O===127)w[2]=w[3]=0,w.writeUIntBE(A,4,6);if(!K.mask)return[w,q];if(w[1]|=128,w[Y-4]=_[0],w[Y-3]=_[1],w[Y-2]=_[2],w[Y-1]=_[3],$)return[w,q];if(z)return CM7(q,_,w,Y,A),[w];return CM7(q,_,q,0,A),[w,q]}close(q,K,_,z){let Y;if(q===void 0)Y=KA5;else if(typeof q!=="number"||!YA5(q))throw TypeError("First argument must be a valid error code number");else if(K===void 0||!K.length)Y=Buffer.allocUnsafe(2),Y.writeUInt16BE(q,0);else{let A=Buffer.byteLength(K);if(A>123)throw RangeError("The message must not be greater than 123 bytes");if(Y=Buffer.allocUnsafe(2+A),Y.writeUInt16BE(q,0),typeof K==="string")Y.write(K,2);else Y.set(K,2)}let $={[_h]:Y.length,fin:!0,generateMask:this._generateMask,mask:_,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};if(this._state!==bx)this.enqueue([this.dispatch,Y,!1,$,z]);else this.sendFrame(st.frame(Y,$),z)}ping(q,K,_){let z,Y;if(typeof q==="string")z=Buffer.byteLength(q),Y=!1;else if(OP6(q))z=q.size,Y=!1;else q=J96(q),z=q.length,Y=J96.readOnly;if(z>125)throw RangeError("The data size must not be greater than 125 bytes");let $={[_h]:z,fin:!0,generateMask:this._generateMask,mask:K,maskBuffer:this._maskBuffer,opcode:9,readOnly:Y,rsv1:!1};if(OP6(q))if(this._state!==bx)this.enqueue([this.getBlobData,q,!1,$,_]);else this.getBlobData(q,!1,$,_);else if(this._state!==bx)this.enqueue([this.dispatch,q,!1,$,_]);else this.sendFrame(st.frame(q,$),_)}pong(q,K,_){let z,Y;if(typeof q==="string")z=Buffer.byteLength(q),Y=!1;else if(OP6(q))z=q.size,Y=!1;else q=J96(q),z=q.length,Y=J96.readOnly;if(z>125)throw RangeError("The data size must not be greater than 125 bytes");let $={[_h]:z,fin:!0,generateMask:this._generateMask,mask:K,maskBuffer:this._maskBuffer,opcode:10,readOnly:Y,rsv1:!1};if(OP6(q))if(this._state!==bx)this.enqueue([this.getBlobData,q,!1,$,_]);else this.getBlobData(q,!1,$,_);else if(this._state!==bx)this.enqueue([this.dispatch,q,!1,$,_]);else this.sendFrame(st.frame(q,$),_)}send(q,K,_){let z=this._extensions[SM7.extensionName],Y=K.binary?2:1,$=K.compress,A,O;if(typeof q==="string")A=Buffer.byteLength(q),O=!1;else if(OP6(q))A=q.size,O=!1;else q=J96(q),A=q.length,O=J96.readOnly;if(this._firstFragment){if(this._firstFragment=!1,$&&z&&z.params[z._isServer?"server_no_context_takeover":"client_no_context_takeover"])$=A>=z._threshold;this._compress=$}else $=!1,Y=0;if(K.fin)this._firstFragment=!0;let w={[_h]:A,fin:K.fin,generateMask:this._generateMask,mask:K.mask,maskBuffer:this._maskBuffer,opcode:Y,readOnly:O,rsv1:$};if(OP6(q))if(this._state!==bx)this.enqueue([this.getBlobData,q,this._compress,w,_]);else this.getBlobData(q,this._compress,w,_);else if(this._state!==bx)this.enqueue([this.dispatch,q,this._compress,w,_]);else this.dispatch(q,this._compress,w,_)}getBlobData(q,K,_,z){this._bufferedBytes+=_[_h],this._state=OA5,q.arrayBuffer().then((Y)=>{if(this._socket.destroyed){let A=Error("The socket was closed while the blob was being read");process.nextTick(Bo8,this,A,z);return}this._bufferedBytes-=_[_h];let $=J96(Y);if(!K)this._state=bx,this.sendFrame(st.frame($,_),z),this.dequeue();else this.dispatch($,K,_,z)}).catch((Y)=>{process.nextTick(wA5,this,Y,z)})}dispatch(q,K,_,z){if(!K){this.sendFrame(st.frame(q,_),z);return}let Y=this._extensions[SM7.extensionName];this._bufferedBytes+=_[_h],this._state=AA5,Y.compress(q,_.fin,($,A)=>{if(this._socket.destroyed){let O=Error("The socket was closed while data was being compressed");Bo8(this,O,z);return}this._bufferedBytes-=_[_h],this._state=bx,_.readOnly=!1,this.sendFrame(st.frame(A,_),z),this.dequeue()})}dequeue(){while(this._state===bx&&this._queue.length){let q=this._queue.shift();this._bufferedBytes-=q[3][_h],Reflect.apply(q[0],this,q.slice(1))}}enqueue(q){this._bufferedBytes+=q[3][_h],this._queue.push(q)}sendFrame(q,K){if(q.length===2)this._socket.cork(),this._socket.write(q[0]),this._socket.write(q[1],K),this._socket.uncork();else this._socket.write(q[0],K)}}bM7.exports=st;function Bo8(q,K,_){if(typeof _==="function")_(K);for(let z=0;z<q._queue.length;z++){let Y=q._queue[z],$=Y[Y.length-1];if(typeof $==="function")$(K)}}function wA5(q,K,_){Bo8(q,K,_),q.onerror(K)}});var UM7=m((Y_$,FM7)=>{var{kForOnEventAttribute:OI6,kListener:Fo8}=Ic(),xM7=Symbol("kCode"),IM7=Symbol("kData"),uM7=Symbol("kError"),mM7=Symbol("kMessage"),pM7=Symbol("kReason"),jP6=Symbol("kTarget"),BM7=Symbol("kType"),gM7=Symbol("kWasClean");class tt{constructor(q){this[jP6]=null,this[BM7]=q}get target(){return this[jP6]}get type(){return this[BM7]}}Object.defineProperty(tt.prototype,"target",{enumerable:!0});Object.defineProperty(tt.prototype,"type",{enumerable:!0});class HP6 extends tt{constructor(q,K={}){super(q);this[xM7]=K.code===void 0?0:K.code,this[pM7]=K.reason===void 0?"":K.reason,this[gM7]=K.wasClean===void 0?!1:K.wasClean}get code(){return this[xM7]}get reason(){return this[pM7]}get wasClean(){return this[gM7]}}Object.defineProperty(HP6.prototype,"code",{enumerable:!0});Object.defineProperty(HP6.prototype,"reason",{enumerable:!0});Object.defineProperty(HP6.prototype,"wasClean",{enumerable:!0});class wI6 extends tt{constructor(q,K={}){super(q);this[uM7]=K.error===void 0?null:K.error,this[mM7]=K.message===void 0?"":K.message}get error(){return this[uM7]}get message(){return this[mM7]}}Object.defineProperty(wI6.prototype,"error",{enumerable:!0});Object.defineProperty(wI6.prototype,"message",{enumerable:!0});class y98 extends tt{constructor(q,K={}){super(q);this[IM7]=K.data===void 0?null:K.data}get data(){return this[IM7]}}Object.defineProperty(y98.prototype,"data",{enumerable:!0});var jA5={addEventListener(q,K,_={}){for(let Y of this.listeners(q))if(!_[OI6]&&Y[Fo8]===K&&!Y[OI6])return;let z;if(q==="message")z=function($,A){let O=new y98("message",{data:A?$:$.toString()});O[jP6]=this,N98(K,this,O)};else if(q==="close")z=function($,A){let O=new HP6("close",{code:$,reason:A.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});O[jP6]=this,N98(K,this,O)};else if(q==="error")z=function($){let A=new wI6("error",{error:$,message:$.message});A[jP6]=this,N98(K,this,A)};else if(q==="open")z=function(){let $=new tt("open");$[jP6]=this,N98(K,this,$)};else return;if(z[OI6]=!!_[OI6],z[Fo8]=K,_.once)this.once(q,z);else this.on(q,z)},removeEventListener(q,K){for(let _ of this.listeners(q))if(_[Fo8]===K&&!_[OI6]){this.removeListener(q,_);break}}};FM7.exports={CloseEvent:HP6,ErrorEvent:wI6,Event:tt,EventTarget:jA5,MessageEvent:y98};function N98(q,K,_){if(typeof q==="object"&&q.handleEvent)q.handleEvent.call(q,_);else q.call(K,_)}});var Uo8=m(($_$,QM7)=>{var{tokenChars:jI6}=AP6();function AB(q,K,_){if(q[K]===void 0)q[K]=[_];else q[K].push(_)}function HA5(q){let K=Object.create(null),_=Object.create(null),z=!1,Y=!1,$=!1,A,O,w=-1,j=-1,H=-1,J=0;for(;J<q.length;J++)if(j=q.charCodeAt(J),A===void 0)if(H===-1&&jI6[j]===1){if(w===-1)w=J}else if(J!==0&&(j===32||j===9)){if(H===-1&&w!==-1)H=J}else if(j===59||j===44){if(w===-1)throw SyntaxError(`Unexpected character at index ${J}`);if(H===-1)H=J;let X=q.slice(w,H);if(j===44)AB(K,X,_),_=Object.create(null);else A=X;w=H=-1}else throw SyntaxError(`Unexpected character at index ${J}`);else if(O===void 0)if(H===-1&&jI6[j]===1){if(w===-1)w=J}else if(j===32||j===9){if(H===-1&&w!==-1)H=J}else if(j===59||j===44){if(w===-1)throw SyntaxError(`Unexpected character at index ${J}`);if(H===-1)H=J;if(AB(_,q.slice(w,H),!0),j===44)AB(K,A,_),_=Object.create(null),A=void 0;w=H=-1}else if(j===61&&w!==-1&&H===-1)O=q.slice(w,J),w=H=-1;else throw SyntaxError(`Unexpected character at index ${J}`);else if(Y){if(jI6[j]!==1)throw SyntaxError(`Unexpected character at index ${J}`);if(w===-1)w=J;else if(!z)z=!0;Y=!1}else if($)if(jI6[j]===1){if(w===-1)w=J}else if(j===34&&w!==-1)$=!1,H=J;else if(j===92)Y=!0;else throw SyntaxError(`Unexpected character at index ${J}`);else if(j===34&&q.charCodeAt(J-1)===61)$=!0;else if(H===-1&&jI6[j]===1){if(w===-1)w=J}else if(w!==-1&&(j===32||j===9)){if(H===-1)H=J}else if(j===59||j===44){if(w===-1)throw SyntaxError(`Unexpected character at index ${J}`);if(H===-1)H=J;let X=q.slice(w,H);if(z)X=X.replace(/\\/g,""),z=!1;if(AB(_,O,X),j===44)AB(K,A,_),_=Object.create(null),A=void 0;O=void 0,w=H=-1}else throw SyntaxError(`Unexpected character at index ${J}`);if(w===-1||$||j===32||j===9)throw SyntaxError("Unexpected end of input");if(H===-1)H=J;let M=q.slice(w,H);if(A===void 0)AB(K,M,_);else{if(O===void 0)AB(_,M,!0);else if(z)AB(_,O,M.replace(/\\/g,""));else AB(_,O,M);AB(K,A,_)}return K}function JA5(q){return Object.keys(q).map((K)=>{let _=q[K];if(!Array.isArray(_))_=[_];return _.map((z)=>{return[K].concat(Object.keys(z).map((Y)=>{let $=z[Y];if(!Array.isArray($))$=[$];return $.map((A)=>A===!0?Y:`${Y}=${A}`).join("; ")})).join("; ")}).join(", ")}).join(", ")}QM7.exports={format:JA5,parse:HA5}});var h98=m((w_$,qX7)=>{var MA5=U6("events"),XA5=U6("https"),PA5=U6("http"),lM7=U6("net"),WA5=U6("tls"),{randomBytes:DA5,createHash:fA5}=U6("crypto"),{Duplex:A_$,Readable:O_$}=U6("stream"),{URL:Qo8}=U6("url"),et=AI6(),ZA5=po8(),GA5=go8(),{isBlob:TA5}=AP6(),{BINARY_TYPES:dM7,EMPTY_BUFFER:E98,GUID:vA5,kForOnEventAttribute:do8,kListener:kA5,kStatusCode:VA5,kWebSocket:TW,NOOP:nM7}=Ic(),{EventTarget:{addEventListener:NA5,removeEventListener:yA5}}=UM7(),{format:EA5,parse:LA5}=Uo8(),{toBuffer:RA5}=YI6(),iM7=Symbol("kAborted"),co8=[8,13],mc=["CONNECTING","OPEN","CLOSING","CLOSED"],hA5=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class Z9 extends MA5{constructor(q,K,_){super();if(this._binaryType=dM7[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=E98,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=Z9.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,q!==null){if(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,K===void 0)K=[];else if(!Array.isArray(K))if(typeof K==="object"&&K!==null)_=K,K=[];else K=[K];rM7(this,q,K,_)}else this._autoPong=_.autoPong,this._isServer=!0}get binaryType(){return this._binaryType}set binaryType(q){if(!dM7.includes(q))return;if(this._binaryType=q,this._receiver)this._receiver._binaryType=q}get bufferedAmount(){if(!this._socket)return this._bufferedAmount;return this._socket._writableState.length+this._sender._bufferedBytes}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(q,K,_){let z=new ZA5({allowSynchronousEvents:_.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:_.maxPayload,skipUTF8Validation:_.skipUTF8Validation}),Y=new GA5(q,this._extensions,_.generateMask);if(this._receiver=z,this._sender=Y,this._socket=q,z[TW]=this,Y[TW]=this,q[TW]=this,z.on("conclude",bA5),z.on("drain",xA5),z.on("error",IA5),z.on("message",uA5),z.on("ping",mA5),z.on("pong",pA5),Y.onerror=BA5,q.setTimeout)q.setTimeout(0);if(q.setNoDelay)q.setNoDelay();if(K.length>0)q.unshift(K);q.on("close",sM7),q.on("data",R98),q.on("end",tM7),q.on("error",eM7),this._readyState=Z9.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=Z9.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}if(this._extensions[et.extensionName])this._extensions[et.extensionName].cleanup();this._receiver.removeAllListeners(),this._readyState=Z9.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(q,K){if(this.readyState===Z9.CLOSED)return;if(this.readyState===Z9.CONNECTING){jE(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===Z9.CLOSING){if(this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted))this._socket.end();return}this._readyState=Z9.CLOSING,this._sender.close(q,K,!this._isServer,(_)=>{if(_)return;if(this._closeFrameSent=!0,this._closeFrameReceived||this._receiver._writableState.errorEmitted)this._socket.end()}),aM7(this)}pause(){if(this.readyState===Z9.CONNECTING||this.readyState===Z9.CLOSED)return;this._paused=!0,this._socket.pause()}ping(q,K,_){if(this.readyState===Z9.CONNECTING)throw Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof q==="function")_=q,q=K=void 0;else if(typeof K==="function")_=K,K=void 0;if(typeof q==="number")q=q.toString();if(this.readyState!==Z9.OPEN){lo8(this,q,_);return}if(K===void 0)K=!this._isServer;this._sender.ping(q||E98,K,_)}pong(q,K,_){if(this.readyState===Z9.CONNECTING)throw Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof q==="function")_=q,q=K=void 0;else if(typeof K==="function")_=K,K=void 0;if(typeof q==="number")q=q.toString();if(this.readyState!==Z9.OPEN){lo8(this,q,_);return}if(K===void 0)K=!this._isServer;this._sender.pong(q||E98,K,_)}resume(){if(this.readyState===Z9.CONNECTING||this.readyState===Z9.CLOSED)return;if(this._paused=!1,!this._receiver._writableState.needDrain)this._socket.resume()}send(q,K,_){if(this.readyState===Z9.CONNECTING)throw Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof K==="function")_=K,K={};if(typeof q==="number")q=q.toString();if(this.readyState!==Z9.OPEN){lo8(this,q,_);return}let z={binary:typeof q!=="string",mask:!this._isServer,compress:!0,fin:!0,...K};if(!this._extensions[et.extensionName])z.compress=!1;this._sender.send(q||E98,z,_)}terminate(){if(this.readyState===Z9.CLOSED)return;if(this.readyState===Z9.CONNECTING){jE(this,this._req,"WebSocket was closed before the connection was established");return}if(this._socket)this._readyState=Z9.CLOSING,this._socket.destroy()}}Object.defineProperty(Z9,"CONNECTING",{enumerable:!0,value:mc.indexOf("CONNECTING")});Object.defineProperty(Z9.prototype,"CONNECTING",{enumerable:!0,value:mc.indexOf("CONNECTING")});Object.defineProperty(Z9,"OPEN",{enumerable:!0,value:mc.indexOf("OPEN")});Object.defineProperty(Z9.prototype,"OPEN",{enumerable:!0,value:mc.indexOf("OPEN")});Object.defineProperty(Z9,"CLOSING",{enumerable:!0,value:mc.indexOf("CLOSING")});Object.defineProperty(Z9.prototype,"CLOSING",{enumerable:!0,value:mc.indexOf("CLOSING")});Object.defineProperty(Z9,"CLOSED",{enumerable:!0,value:mc.indexOf("CLOSED")});Object.defineProperty(Z9.prototype,"CLOSED",{enumerable:!0,value:mc.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((q)=>{Object.defineProperty(Z9.prototype,q,{enumerable:!0})});["open","error","close","message"].forEach((q)=>{Object.defineProperty(Z9.prototype,`on${q}`,{enumerable:!0,get(){for(let K of this.listeners(q))if(K[do8])return K[kA5];return null},set(K){for(let _ of this.listeners(q))if(_[do8]){this.removeListener(q,_);break}if(typeof K!=="function")return;this.addEventListener(q,K,{[do8]:!0})}})});Z9.prototype.addEventListener=NA5;Z9.prototype.removeEventListener=yA5;qX7.exports=Z9;function rM7(q,K,_,z){let Y={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:co8[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...z,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(q._autoPong=Y.autoPong,!co8.includes(Y.protocolVersion))throw RangeError(`Unsupported protocol version: ${Y.protocolVersion} (supported versions: ${co8.join(", ")})`);let $;if(K instanceof Qo8)$=K;else try{$=new Qo8(K)}catch(W){throw SyntaxError(`Invalid URL: ${K}`)}if($.protocol==="http:")$.protocol="ws:";else if($.protocol==="https:")$.protocol="wss:";q._url=$.href;let A=$.protocol==="wss:",O=$.protocol==="ws+unix:",w;if($.protocol!=="ws:"&&!A&&!O)w=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;else if(O&&!$.pathname)w="The URL's pathname is empty";else if($.hash)w="The URL contains a fragment identifier";if(w){let W=SyntaxError(w);if(q._redirects===0)throw W;else{L98(q,W);return}}let j=A?443:80,H=DA5(16).toString("base64"),J=A?XA5.request:PA5.request,M=new Set,X;if(Y.createConnection=Y.createConnection||(A?CA5:SA5),Y.defaultPort=Y.defaultPort||j,Y.port=$.port||j,Y.host=$.hostname.startsWith("[")?$.hostname.slice(1,-1):$.hostname,Y.headers={...Y.headers,"Sec-WebSocket-Version":Y.protocolVersion,"Sec-WebSocket-Key":H,Connection:"Upgrade",Upgrade:"websocket"},Y.path=$.pathname+$.search,Y.timeout=Y.handshakeTimeout,Y.perMessageDeflate)X=new et(Y.perMessageDeflate!==!0?Y.perMessageDeflate:{},!1,Y.maxPayload),Y.headers["Sec-WebSocket-Extensions"]=EA5({[et.extensionName]:X.offer()});if(_.length){for(let W of _){if(typeof W!=="string"||!hA5.test(W)||M.has(W))throw SyntaxError("An invalid or duplicated subprotocol was specified");M.add(W)}Y.headers["Sec-WebSocket-Protocol"]=_.join(",")}if(Y.origin)if(Y.protocolVersion<13)Y.headers["Sec-WebSocket-Origin"]=Y.origin;else Y.headers.Origin=Y.origin;if($.username||$.password)Y.auth=`${$.username}:${$.password}`;if(O){let W=Y.path.split(":");Y.socketPath=W[0],Y.path=W[1]}let P;if(Y.followRedirects){if(q._redirects===0){q._originalIpc=O,q._originalSecure=A,q._originalHostOrSocketPath=O?Y.socketPath:$.host;let W=z&&z.headers;if(z={...z,headers:{}},W)for(let[D,f]of Object.entries(W))z.headers[D.toLowerCase()]=f}else if(q.listenerCount("redirect")===0){let W=O?q._originalIpc?Y.socketPath===q._originalHostOrSocketPath:!1:q._originalIpc?!1:$.host===q._originalHostOrSocketPath;if(!W||q._originalSecure&&!A){if(delete Y.headers.authorization,delete Y.headers.cookie,!W)delete Y.headers.host;Y.auth=void 0}}if(Y.auth&&!z.headers.authorization)z.headers.authorization="Basic "+Buffer.from(Y.auth).toString("base64");if(P=q._req=J(Y),q._redirects)q.emit("redirect",q.url,P)}else P=q._req=J(Y);if(Y.timeout)P.on("timeout",()=>{jE(q,P,"Opening handshake has timed out")});if(P.on("error",(W)=>{if(P===null||P[iM7])return;P=q._req=null,L98(q,W)}),P.on("response",(W)=>{let D=W.headers.location,f=W.statusCode;if(D&&Y.followRedirects&&f>=300&&f<400){if(++q._redirects>Y.maxRedirects){jE(q,P,"Maximum redirects exceeded");return}P.abort();let G;try{G=new Qo8(D,K)}catch(Z){let T=SyntaxError(`Invalid URL: ${D}`);L98(q,T);return}rM7(q,G,_,z)}else if(!q.emit("unexpected-response",P,W))jE(q,P,`Unexpected server response: ${W.statusCode}`)}),P.on("upgrade",(W,D,f)=>{if(q.emit("upgrade",W),q.readyState!==Z9.CONNECTING)return;P=q._req=null;let G=W.headers.upgrade;if(G===void 0||G.toLowerCase()!=="websocket"){jE(q,D,"Invalid Upgrade header");return}let Z=fA5("sha1").update(H+vA5).digest("base64");if(W.headers["sec-websocket-accept"]!==Z){jE(q,D,"Invalid Sec-WebSocket-Accept header");return}let T=W.headers["sec-websocket-protocol"],v;if(T!==void 0){if(!M.size)v="Server sent a subprotocol but none was requested";else if(!M.has(T))v="Server sent an invalid subprotocol"}else if(M.size)v="Server sent no subprotocol";if(v){jE(q,D,v);return}if(T)q._protocol=T;let V=W.headers["sec-websocket-extensions"];if(V!==void 0){if(!X){jE(q,D,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let E;try{E=LA5(V)}catch(R){jE(q,D,"Invalid Sec-WebSocket-Extensions header");return}let S=Object.keys(E);if(S.length!==1||S[0]!==et.extensionName){jE(q,D,"Server indicated an extension that was not requested");return}try{X.accept(E[et.extensionName])}catch(R){jE(q,D,"Invalid Sec-WebSocket-Extensions header");return}q._extensions[et.extensionName]=X}q.setSocket(D,f,{allowSynchronousEvents:Y.allowSynchronousEvents,generateMask:Y.generateMask,maxPayload:Y.maxPayload,skipUTF8Validation:Y.skipUTF8Validation})}),Y.finishRequest)Y.finishRequest(P,q);else P.end()}function L98(q,K){q._readyState=Z9.CLOSING,q._errorEmitted=!0,q.emit("error",K),q.emitClose()}function SA5(q){return q.path=q.socketPath,lM7.connect(q)}function CA5(q){if(q.path=void 0,!q.servername&&q.servername!=="")q.servername=lM7.isIP(q.host)?"":q.host;return WA5.connect(q)}function jE(q,K,_){q._readyState=Z9.CLOSING;let z=Error(_);if(Error.captureStackTrace(z,jE),K.setHeader){if(K[iM7]=!0,K.abort(),K.socket&&!K.socket.destroyed)K.socket.destroy();process.nextTick(L98,q,z)}else K.destroy(z),K.once("error",q.emit.bind(q,"error")),K.once("close",q.emitClose.bind(q))}function lo8(q,K,_){if(K){let z=TA5(K)?K.size:RA5(K).length;if(q._socket)q._sender._bufferedBytes+=z;else q._bufferedAmount+=z}if(_){let z=Error(`WebSocket is not open: readyState ${q.readyState} (${mc[q.readyState]})`);process.nextTick(_,z)}}function bA5(q,K){let _=this[TW];if(_._closeFrameReceived=!0,_._closeMessage=K,_._closeCode=q,_._socket[TW]===void 0)return;if(_._socket.removeListener("data",R98),process.nextTick(oM7,_._socket),q===1005)_.close();else _.close(q,K)}function xA5(){let q=this[TW];if(!q.isPaused)q._socket.resume()}function IA5(q){let K=this[TW];if(K._socket[TW]!==void 0)K._socket.removeListener("data",R98),process.nextTick(oM7,K._socket),K.close(q[VA5]);if(!K._errorEmitted)K._errorEmitted=!0,K.emit("error",q)}function cM7(){this[TW].emitClose()}function uA5(q,K){this[TW].emit("message",q,K)}function mA5(q){let K=this[TW];if(K._autoPong)K.pong(q,!this._isServer,nM7);K.emit("ping",q)}function pA5(q){this[TW].emit("pong",q)}function oM7(q){q.resume()}function BA5(q){let K=this[TW];if(K.readyState===Z9.CLOSED)return;if(K.readyState===Z9.OPEN)K._readyState=Z9.CLOSING,aM7(K);if(this._socket.end(),!K._errorEmitted)K._errorEmitted=!0,K.emit("error",q)}function aM7(q){q._closeTimer=setTimeout(q._socket.destroy.bind(q._socket),30000)}function sM7(){let q=this[TW];this.removeListener("close",sM7),this.removeListener("data",R98),this.removeListener("end",tM7),q._readyState=Z9.CLOSING;let K;if(!this._readableState.endEmitted&&!q._closeFrameReceived&&!q._receiver._writableState.errorEmitted&&(K=q._socket.read())!==null)q._receiver.write(K);if(q._receiver.end(),this[TW]=void 0,clearTimeout(q._closeTimer),q._receiver._writableState.finished||q._receiver._writableState.errorEmitted)q.emitClose();else q._receiver.on("error",cM7),q._receiver.on("finish",cM7)}function R98(q){if(!this[TW]._receiver.write(q))this.pause()}function tM7(){let q=this[TW];q._readyState=Z9.CLOSING,q._receiver.end(),this.end()}function eM7(){let q=this[TW];if(this.removeListener("error",eM7),this.on("error",nM7),q)q._readyState=Z9.CLOSING,this.destroy()}});var YX7=m((H_$,zX7)=>{var j_$=h98(),{Duplex:gA5}=U6("stream");function KX7(q){q.emit("close")}function FA5(){if(!this.destroyed&&this._writableState.finished)this.destroy()}function _X7(q){if(this.removeListener("error",_X7),this.destroy(),this.listenerCount("error")===0)this.emit("error",q)}function UA5(q,K){let _=!0,z=new gA5({...K,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return q.on("message",function($,A){let O=!A&&z._readableState.objectMode?$.toString():$;if(!z.push(O))q.pause()}),q.once("error",function($){if(z.destroyed)return;_=!1,z.destroy($)}),q.once("close",function(){if(z.destroyed)return;z.push(null)}),z._destroy=function(Y,$){if(q.readyState===q.CLOSED){$(Y),process.nextTick(KX7,z);return}let A=!1;if(q.once("error",function(w){A=!0,$(w)}),q.once("close",function(){if(!A)$(Y);process.nextTick(KX7,z)}),_)q.terminate()},z._final=function(Y){if(q.readyState===q.CONNECTING){q.once("open",function(){z._final(Y)});return}if(q._socket===null)return;if(q._socket._writableState.finished){if(Y(),z._readableState.endEmitted)z.destroy()}else q._socket.once("finish",function(){Y()}),q.close()},z._read=function(){if(q.isPaused)q.resume()},z._write=function(Y,$,A){if(q.readyState===q.CONNECTING){q.once("open",function(){z._write(Y,$,A)});return}q.send(Y,A)},z.on("end",FA5),z.on("error",_X7),z}zX7.exports=UA5});var AX7=m((J_$,$X7)=>{var{tokenChars:QA5}=AP6();function dA5(q){let K=new Set,_=-1,z=-1,Y=0;for(Y;Y<q.length;Y++){let A=q.charCodeAt(Y);if(z===-1&&QA5[A]===1){if(_===-1)_=Y}else if(Y!==0&&(A===32||A===9)){if(z===-1&&_!==-1)z=Y}else if(A===44){if(_===-1)throw SyntaxError(`Unexpected character at index ${Y}`);if(z===-1)z=Y;let O=q.slice(_,z);if(K.has(O))throw SyntaxError(`The "${O}" subprotocol is duplicated`);K.add(O),_=z=-1}else throw SyntaxError(`Unexpected character at index ${Y}`)}if(_===-1||z!==-1)throw SyntaxError("Unexpected end of input");let $=q.slice(_,Y);if(K.has($))throw SyntaxError(`The "${$}" subprotocol is duplicated`);return K.add($),K}$X7.exports={parse:dA5}});var JX7=m((X_$,HX7)=>{var cA5=U6("events"),S98=U6("http"),{Duplex:M_$}=U6("stream"),{createHash:lA5}=U6("crypto"),OX7=Uo8(),X96=AI6(),nA5=AX7(),iA5=h98(),{GUID:rA5,kWebSocket:oA5}=Ic(),aA5=/^[+/0-9A-Za-z]{22}==$/;class jX7 extends cA5{constructor(q,K){super();if(q={allowSynchronousEvents:!0,autoPong:!0,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:iA5,...q},q.port==null&&!q.server&&!q.noServer||q.port!=null&&(q.server||q.noServer)||q.server&&q.noServer)throw TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(q.port!=null)this._server=S98.createServer((_,z)=>{let Y=S98.STATUS_CODES[426];z.writeHead(426,{"Content-Length":Y.length,"Content-Type":"text/plain"}),z.end(Y)}),this._server.listen(q.port,q.host,q.backlog,K);else if(q.server)this._server=q.server;if(this._server){let _=this.emit.bind(this,"connection");this._removeListeners=sA5(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(z,Y,$)=>{this.handleUpgrade(z,Y,$,_)}})}if(q.perMessageDeflate===!0)q.perMessageDeflate={};if(q.clientTracking)this.clients=new Set,this._shouldEmitClose=!1;this.options=q,this._state=0}address(){if(this.options.noServer)throw Error('The server is operating in "noServer" mode');if(!this._server)return null;return this._server.address()}close(q){if(this._state===2){if(q)this.once("close",()=>{q(Error("The server is not running"))});process.nextTick(HI6,this);return}if(q)this.once("close",q);if(this._state===1)return;if(this._state=1,this.options.noServer||this.options.server){if(this._server)this._removeListeners(),this._removeListeners=this._server=null;if(this.clients)if(!this.clients.size)process.nextTick(HI6,this);else this._shouldEmitClose=!0;else process.nextTick(HI6,this)}else{let K=this._server;this._removeListeners(),this._removeListeners=this._server=null,K.close(()=>{HI6(this)})}}shouldHandle(q){if(this.options.path){let K=q.url.indexOf("?");if((K!==-1?q.url.slice(0,K):q.url)!==this.options.path)return!1}return!0}handleUpgrade(q,K,_,z){K.on("error",wX7);let Y=q.headers["sec-websocket-key"],$=q.headers.upgrade,A=+q.headers["sec-websocket-version"];if(q.method!=="GET"){P96(this,q,K,405,"Invalid HTTP method");return}if($===void 0||$.toLowerCase()!=="websocket"){P96(this,q,K,400,"Invalid Upgrade header");return}if(Y===void 0||!aA5.test(Y)){P96(this,q,K,400,"Missing or invalid Sec-WebSocket-Key header");return}if(A!==13&&A!==8){P96(this,q,K,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(q)){JI6(K,400);return}let O=q.headers["sec-websocket-protocol"],w=new Set;if(O!==void 0)try{w=nA5.parse(O)}catch(J){P96(this,q,K,400,"Invalid Sec-WebSocket-Protocol header");return}let j=q.headers["sec-websocket-extensions"],H={};if(this.options.perMessageDeflate&&j!==void 0){let J=new X96(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let M=OX7.parse(j);if(M[X96.extensionName])J.accept(M[X96.extensionName]),H[X96.extensionName]=J}catch(M){P96(this,q,K,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let J={origin:q.headers[`${A===8?"sec-websocket-origin":"origin"}`],secure:!!(q.socket.authorized||q.socket.encrypted),req:q};if(this.options.verifyClient.length===2){this.options.verifyClient(J,(M,X,P,W)=>{if(!M)return JI6(K,X||401,P,W);this.completeUpgrade(H,Y,w,q,K,_,z)});return}if(!this.options.verifyClient(J))return JI6(K,401)}this.completeUpgrade(H,Y,w,q,K,_,z)}completeUpgrade(q,K,_,z,Y,$,A){if(!Y.readable||!Y.writable)return Y.destroy();if(Y[oA5])throw Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return JI6(Y,503);let w=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${lA5("sha1").update(K+rA5).digest("base64")}`],j=new this.options.WebSocket(null,void 0,this.options);if(_.size){let H=this.options.handleProtocols?this.options.handleProtocols(_,z):_.values().next().value;if(H)w.push(`Sec-WebSocket-Protocol: ${H}`),j._protocol=H}if(q[X96.extensionName]){let H=q[X96.extensionName].params,J=OX7.format({[X96.extensionName]:[H]});w.push(`Sec-WebSocket-Extensions: ${J}`),j._extensions=q}if(this.emit("headers",w,z),Y.write(w.concat(`\r |