@babtab/relay 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +1 -12
- package/README.es.md +27 -18
- package/README.hi.md +27 -18
- package/README.ja.md +25 -19
- package/README.ko.md +26 -18
- package/README.md +30 -19
- package/README.pt-BR.md +27 -18
- package/README.zh-TW.md +28 -19
- package/SECURITY.md +13 -12
- package/dist/relay.cjs +338 -6
- package/package.json +6 -3
package/dist/relay.cjs
CHANGED
|
@@ -1,11 +1,343 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var mr=Object.create;var Qe=Object.defineProperty;var gr=Object.getOwnPropertyDescriptor;var yr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var S=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Er=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yr(e))!xr.call(t,i)&&i!==r&&Qe(t,i,{get:()=>e[i],enumerable:!(s=gr(e,i))||s.enumerable});return t};var P=(t,e,r)=>(r=t!=null?mr(Sr(t)):{},Er(e||!t||!t.__esModule?Qe(r,"default",{value:t,enumerable:!0}):r,t));var T=S((oi,rt)=>{"use strict";var et=["nodebuffer","arraybuffer","fragments"],tt=typeof Blob<"u";tt&&et.push("blob");rt.exports={BINARY_TYPES:et,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:tt,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var X=S((ai,ne)=>{"use strict";var{EMPTY_BUFFER:br}=T(),ve=Buffer[Symbol.species];function vr(t,e){if(t.length===0)return br;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),s=0;for(let i=0;i<t.length;i++){let n=t[i];r.set(n,s),s+=n.length}return s<e?new ve(r.buffer,r.byteOffset,s):r}function st(t,e,r,s,i){for(let n=0;n<i;n++)r[s+n]=t[n]^e[n&3]}function it(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function wr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function we(t){if(we.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ve(t):ArrayBuffer.isView(t)?e=new ve(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),we.readOnly=!1),e}ne.exports={concat:vr,mask:st,toArrayBuffer:wr,toBuffer:we,unmask:it};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=require("bufferutil");ne.exports.mask=function(e,r,s,i,n){n<48?st(e,r,s,i,n):t.mask(e,r,s,i,n)},ne.exports.unmask=function(e,r){e.length<32?it(e,r):t.unmask(e,r)}}catch{}});var at=S((ci,ot)=>{"use strict";var nt=Symbol("kDone"),Te=Symbol("kRun"),Oe=class{constructor(e){this[nt]=()=>{this.pending--,this[Te]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Te]()}[Te](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[nt])}}};ot.exports=Oe});var G=S((li,ht)=>{"use strict";var Z=require("zlib"),ct=X(),Tr=at(),{kStatusCode:lt}=T(),Or=Buffer[Symbol.species],kr=Buffer.from([0,0,255,255]),ae=Symbol("permessage-deflate"),O=Symbol("total-length"),j=Symbol("callback"),L=Symbol("buffers"),$=Symbol("error"),oe,ke=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!oe){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;oe=new Tr(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[j];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,s=e.find(i=>!(r.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>i.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&(typeof i.client_max_window_bits=="number"?r.clientMaxWindowBits>i.client_max_window_bits:!i.client_max_window_bits)));if(!s)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(s.server_no_context_takeover=!0),r.clientNoContextTakeover&&(s.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(s.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?s.client_max_window_bits=r.clientMaxWindowBits:(s.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete s.client_max_window_bits,s}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(s=>{let i=r[s];if(i.length>1)throw new Error(`Parameter "${s}" must have only a single value`);if(i=i[0],s==="client_max_window_bits"){if(i!==!0){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${s}": ${i}`);i=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${s}": ${i}`)}else if(s==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${s}": ${i}`);i=n}else if(s==="client_no_context_takeover"||s==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${s}": ${i}`)}else throw new Error(`Unknown parameter "${s}"`);r[s]=i})}),e}decompress(e,r,s){oe.add(i=>{this._decompress(e,r,(n,o)=>{i(),s(n,o)})})}compress(e,r,s){oe.add(i=>{this._compress(e,r,(n,o)=>{i(),s(n,o)})})}_decompress(e,r,s){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=Z.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[ae]=this,this._inflate[O]=0,this._inflate[L]=[],this._inflate.on("error",Cr),this._inflate.on("data",ft)}this._inflate[j]=s,this._inflate.write(e),r&&this._inflate.write(kr),this._inflate.flush(()=>{let n=this._inflate[$];if(n){this._inflate.close(),this._inflate=null,s(n);return}let o=ct.concat(this._inflate[L],this._inflate[O]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[O]=0,this._inflate[L]=[],r&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),s(null,o)})}_compress(e,r,s){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=Z.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[O]=0,this._deflate[L]=[],this._deflate.on("data",Nr)}this._deflate[j]=s,this._deflate.write(e),this._deflate.flush(Z.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=ct.concat(this._deflate[L],this._deflate[O]);r&&(n=new Or(n.buffer,n.byteOffset,n.length-4)),this._deflate[j]=null,this._deflate[O]=0,this._deflate[L]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),s(null,n)})}};ht.exports=ke;function Nr(t){this[L].push(t),this[O]+=t.length}function ft(t){if(this[O]+=t.length,this[ae]._maxPayload<1||this[O]<=this[ae]._maxPayload){this[L].push(t);return}this[$]=new RangeError("Max payload size exceeded"),this[$].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[$][lt]=1009,this.removeListener("data",ft),this.reset()}function Cr(t){if(this[ae]._inflate=null,this[$]){this[j](this[$]);return}t[lt]=1007,this[j](t)}});var q=S((fi,ce)=>{"use strict";var{isUtf8:ut}=require("buffer"),{hasBlob:Pr}=T(),Lr=[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 Rr(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Ne(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function Br(t){return Pr&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}ce.exports={isBlob:Br,isValidStatusCode:Rr,isValidUTF8:Ne,tokenChars:Lr};if(ut)ce.exports.isValidUTF8=function(t){return t.length<24?Ne(t):ut(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=require("utf-8-validate");ce.exports.isValidUTF8=function(e){return e.length<32?Ne(e):t(e)}}catch{}});var Be=S((hi,St)=>{"use strict";var{Writable:Ir}=require("stream"),dt=G(),{BINARY_TYPES:Dr,EMPTY_BUFFER:pt,kStatusCode:Ur,kWebSocket:Ar}=T(),{concat:Ce,toArrayBuffer:Mr,unmask:Fr}=X(),{isValidStatusCode:Wr,isValidUTF8:_t}=q(),le=Buffer[Symbol.species],E=0,mt=1,gt=2,yt=3,Pe=4,Le=5,fe=6,Re=class extends Ir{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Dr[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Ar]=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._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=E}_write(e,r,s){if(this._opcode===8&&this._state==E)return s();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){s(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let s=this._buffers[0];return this._buffers[0]=new le(s.buffer,s.byteOffset+e,s.length-e),new le(s.buffer,s.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let s=this._buffers[0],i=r.length-e;e>=s.length?r.set(this._buffers.shift(),i):(r.set(new Uint8Array(s.buffer,s.byteOffset,e),i),this._buffers[0]=new le(s.buffer,s.byteOffset+e,s.length-e)),e-=s.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case E:this.getInfo(e);break;case mt:this.getPayloadLength16(e);break;case gt:this.getPayloadLength64(e);break;case yt:this.getMask();break;case Pe:this.getData(e);break;case Le:case fe:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let s=(r[0]&64)===64;if(s&&!this._extensions[dt.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(s){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=s}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(s){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=mt:this._payloadLength===127?this._state=gt:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),s=r.readUInt32BE(0);if(s>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=s*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=yt:this._state=Pe}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Pe}getData(e){let r=pt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&Fr(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._maxFragments>0&&++this._numFragments>this._maxFragments){let s=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(s);return}if(this._compressed){this._state=Le,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[dt.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return r(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n)}this.dataMessage(r),this._state===E&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=E;return}let r=this._messageLength,s=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=Ce(s,r):this._binaryType==="arraybuffer"?i=Mr(Ce(s,r)):this._binaryType==="blob"?i=new Blob(s):i=s,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=E):(this._state=fe,setImmediate(()=>{this.emit("message",i,!0),this._state=E,this.startLoop(e)}))}else{let i=Ce(s,r);if(!this._skipUTF8Validation&&!_t(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Le||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=E):(this._state=fe,setImmediate(()=>{this.emit("message",i,!1),this._state=E,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,pt),this.end();else{let s=e.readUInt16BE(0);if(!Wr(s)){let n=this.createError(RangeError,`invalid status code ${s}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let i=new le(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!_t(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=!1,this.emit("conclude",s,i),this.end()}this._state=E;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=E):(this._state=fe,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=E,this.startLoop(r)}))}createError(e,r,s,i,n){this._loop=!1,this._errored=!0;let o=new e(s?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[Ur]=i,o}};St.exports=Re});var Ue=S((di,bt)=>{"use strict";var{Duplex:ui}=require("stream"),{randomFillSync:jr}=require("crypto"),{types:{isUint8Array:$r}}=require("util"),xt=G(),{EMPTY_BUFFER:Gr,kWebSocket:qr,NOOP:Vr}=T(),{isBlob:V,isValidStatusCode:Hr}=q(),{mask:Et,toBuffer:I}=X(),b=Symbol("kByteLength"),zr=Buffer.alloc(4),he=8*1024,D,H=he,v=0,Jr=1,Yr=2,Ie=class t{constructor(e,r,s){this._extensions=r||{},s&&(this._generateMask=s,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=v,this.onerror=Vr,this[qr]=void 0}static frame(e,r){let s,i=!1,n=2,o=!1;r.mask&&(s=r.maskBuffer||zr,r.generateMask?r.generateMask(s):(H===he&&(D===void 0&&(D=Buffer.alloc(he)),jr(D,0,he),H=0),s[0]=D[H++],s[1]=D[H++],s[2]=D[H++],s[3]=D[H++]),o=(s[0]|s[1]|s[2]|s[3])===0,n=6);let c;typeof e=="string"?(!r.mask||o)&&r[b]!==void 0?c=r[b]:(e=Buffer.from(e),c=e.length):(c=e.length,i=r.mask&&r.readOnly&&!o);let a=c;c>=65536?(n+=8,a=127):c>125&&(n+=2,a=126);let l=Buffer.allocUnsafe(i?c+n:n);return l[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(l[0]|=64),l[1]=a,a===126?l.writeUInt16BE(c,2):a===127&&(l[2]=l[3]=0,l.writeUIntBE(c,4,6)),r.mask?(l[1]|=128,l[n-4]=s[0],l[n-3]=s[1],l[n-2]=s[2],l[n-1]=s[3],o?[l,e]:i?(Et(e,s,l,n,c),[l]):(Et(e,s,e,0,c),[l,e])):[l,e]}close(e,r,s,i){let n;if(e===void 0)n=Gr;else{if(typeof e!="number"||!Hr(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let c=Buffer.byteLength(r);if(c>123)throw new RangeError("The message must not be greater than 123 bytes");if(n=Buffer.allocUnsafe(2+c),n.writeUInt16BE(e,0),typeof r=="string")n.write(r,2);else if($r(r))n.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==v?this.enqueue([this.dispatch,n,!1,o,i]):this.sendFrame(t.frame(n,o),i)}ping(e,r,s){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):V(e)?(i=e.size,n=!1):(e=I(e),i=e.length,n=I.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};V(e)?this._state!==v?this.enqueue([this.getBlobData,e,!1,o,s]):this.getBlobData(e,!1,o,s):this._state!==v?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(t.frame(e,o),s)}pong(e,r,s){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):V(e)?(i=e.size,n=!1):(e=I(e),i=e.length,n=I.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};V(e)?this._state!==v?this.enqueue([this.getBlobData,e,!1,o,s]):this.getBlobData(e,!1,o,s):this._state!==v?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(t.frame(e,o),s)}send(e,r,s){let i=this._extensions[xt.extensionName],n=r.binary?2:1,o=r.compress,c,a;typeof e=="string"?(c=Buffer.byteLength(e),a=!1):V(e)?(c=e.size,a=!1):(e=I(e),c=e.length,a=I.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=c>=i._threshold),this._compress=o):(o=!1,n=0),r.fin&&(this._firstFragment=!0);let l={[b]:c,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:a,rsv1:o};V(e)?this._state!==v?this.enqueue([this.getBlobData,e,this._compress,l,s]):this.getBlobData(e,this._compress,l,s):this._state!==v?this.enqueue([this.dispatch,e,this._compress,l,s]):this.dispatch(e,this._compress,l,s)}getBlobData(e,r,s,i){this._bufferedBytes+=s[b],this._state=Yr,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let c=new Error("The socket was closed while the blob was being read");process.nextTick(De,this,c,i);return}this._bufferedBytes-=s[b];let o=I(n);r?this.dispatch(o,r,s,i):(this._state=v,this.sendFrame(t.frame(o,s),i),this.dequeue())}).catch(n=>{process.nextTick(Kr,this,n,i)})}dispatch(e,r,s,i){if(!r){this.sendFrame(t.frame(e,s),i);return}let n=this._extensions[xt.extensionName];this._bufferedBytes+=s[b],this._state=Jr,n.compress(e,s.fin,(o,c)=>{if(this._socket.destroyed){let a=new Error("The socket was closed while data was being compressed");De(this,a,i);return}this._bufferedBytes-=s[b],this._state=v,s.readOnly=!1,this.sendFrame(t.frame(c,s),i),this.dequeue()})}dequeue(){for(;this._state===v&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};bt.exports=Ie;function De(t,e,r){typeof r=="function"&&r(e);for(let s=0;s<t._queue.length;s++){let i=t._queue[s],n=i[i.length-1];typeof n=="function"&&n(e)}}function Kr(t,e,r){De(t,e,r),t.onerror(e)}});var Lt=S((pi,Pt)=>{"use strict";var{kForOnEventAttribute:Q,kListener:Ae}=T(),vt=Symbol("kCode"),wt=Symbol("kData"),Tt=Symbol("kError"),Ot=Symbol("kMessage"),kt=Symbol("kReason"),z=Symbol("kTarget"),Nt=Symbol("kType"),Ct=Symbol("kWasClean"),k=class{constructor(e){this[z]=null,this[Nt]=e}get target(){return this[z]}get type(){return this[Nt]}};Object.defineProperty(k.prototype,"target",{enumerable:!0});Object.defineProperty(k.prototype,"type",{enumerable:!0});var U=class extends k{constructor(e,r={}){super(e),this[vt]=r.code===void 0?0:r.code,this[kt]=r.reason===void 0?"":r.reason,this[Ct]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[vt]}get reason(){return this[kt]}get wasClean(){return this[Ct]}};Object.defineProperty(U.prototype,"code",{enumerable:!0});Object.defineProperty(U.prototype,"reason",{enumerable:!0});Object.defineProperty(U.prototype,"wasClean",{enumerable:!0});var J=class extends k{constructor(e,r={}){super(e),this[Tt]=r.error===void 0?null:r.error,this[Ot]=r.message===void 0?"":r.message}get error(){return this[Tt]}get message(){return this[Ot]}};Object.defineProperty(J.prototype,"error",{enumerable:!0});Object.defineProperty(J.prototype,"message",{enumerable:!0});var ee=class extends k{constructor(e,r={}){super(e),this[wt]=r.data===void 0?null:r.data}get data(){return this[wt]}};Object.defineProperty(ee.prototype,"data",{enumerable:!0});var Xr={addEventListener(t,e,r={}){for(let i of this.listeners(t))if(!r[Q]&&i[Ae]===e&&!i[Q])return;let s;if(t==="message")s=function(n,o){let c=new ee("message",{data:o?n:n.toString()});c[z]=this,ue(e,this,c)};else if(t==="close")s=function(n,o){let c=new U("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});c[z]=this,ue(e,this,c)};else if(t==="error")s=function(n){let o=new J("error",{error:n,message:n.message});o[z]=this,ue(e,this,o)};else if(t==="open")s=function(){let n=new k("open");n[z]=this,ue(e,this,n)};else return;s[Q]=!!r[Q],s[Ae]=e,r.once?this.once(t,s):this.on(t,s)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ae]===e&&!r[Q]){this.removeListener(t,r);break}}};Pt.exports={CloseEvent:U,ErrorEvent:J,Event:k,EventTarget:Xr,MessageEvent:ee};function ue(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var de=S((_i,Rt)=>{"use strict";var{tokenChars:te}=q();function w(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Zr(t){let e=Object.create(null),r=Object.create(null),s=!1,i=!1,n=!1,o,c,a=-1,l=-1,f=-1,h=0;for(;h<t.length;h++)if(l=t.charCodeAt(h),o===void 0)if(f===-1&&te[l]===1)a===-1&&(a=h);else if(h!==0&&(l===32||l===9))f===-1&&a!==-1&&(f=h);else if(l===59||l===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${h}`);f===-1&&(f=h);let m=t.slice(a,f);l===44?(w(e,m,r),r=Object.create(null)):o=m,a=f=-1}else throw new SyntaxError(`Unexpected character at index ${h}`);else if(c===void 0)if(f===-1&&te[l]===1)a===-1&&(a=h);else if(l===32||l===9)f===-1&&a!==-1&&(f=h);else if(l===59||l===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${h}`);f===-1&&(f=h),w(r,t.slice(a,f),!0),l===44&&(w(e,o,r),r=Object.create(null),o=void 0),a=f=-1}else if(l===61&&a!==-1&&f===-1)c=t.slice(a,h),a=f=-1;else throw new SyntaxError(`Unexpected character at index ${h}`);else if(i){if(te[l]!==1)throw new SyntaxError(`Unexpected character at index ${h}`);a===-1?a=h:s||(s=!0),i=!1}else if(n)if(te[l]===1)a===-1&&(a=h);else if(l===34&&a!==-1)n=!1,f=h;else if(l===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${h}`);else if(l===34&&t.charCodeAt(h-1)===61)n=!0;else if(f===-1&&te[l]===1)a===-1&&(a=h);else if(a!==-1&&(l===32||l===9))f===-1&&(f=h);else if(l===59||l===44){if(a===-1)throw new SyntaxError(`Unexpected character at index ${h}`);f===-1&&(f=h);let m=t.slice(a,f);s&&(m=m.replace(/\\/g,""),s=!1),w(r,c,m),l===44&&(w(e,o,r),r=Object.create(null),o=void 0),c=void 0,a=f=-1}else throw new SyntaxError(`Unexpected character at index ${h}`);if(a===-1||n||l===32||l===9)throw new SyntaxError("Unexpected end of input");f===-1&&(f=h);let d=t.slice(a,f);return o===void 0?w(e,d,r):(c===void 0?w(r,d,!0):s?w(r,c,d.replace(/\\/g,"")):w(r,c,d),w(e,o,r)),e}function Qr(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(s=>[e].concat(Object.keys(s).map(i=>{let n=s[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Rt.exports={format:Qr,parse:Zr}});var ge=S((yi,qt)=>{"use strict";var es=require("events"),ts=require("https"),rs=require("http"),Dt=require("net"),ss=require("tls"),{randomBytes:is,createHash:ns}=require("crypto"),{Duplex:mi,Readable:gi}=require("stream"),{URL:Me}=require("url"),R=G(),os=Be(),as=Ue(),{isBlob:cs}=q(),{BINARY_TYPES:Bt,CLOSE_TIMEOUT:ls,EMPTY_BUFFER:pe,GUID:fs,kForOnEventAttribute:Fe,kListener:hs,kStatusCode:us,kWebSocket:g,NOOP:Ut}=T(),{EventTarget:{addEventListener:ds,removeEventListener:ps}}=Lt(),{format:_s,parse:ms}=de(),{toBuffer:gs}=X(),At=Symbol("kAborted"),We=[8,13],N=["CONNECTING","OPEN","CLOSING","CLOSED"],ys=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,p=class t extends es{constructor(e,r,s){super(),this._binaryType=Bt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=pe,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(s=r,r=[]):r=[r]),Mt(this,e,r,s)):(this._autoPong=s.autoPong,this._closeTimeout=s.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Bt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}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(e,r,s){let i=new os({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:s.maxBufferedChunks,maxFragments:s.maxFragments,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation}),n=new as(e,this._extensions,s.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[g]=this,n[g]=this,e[g]=this,i.on("conclude",Es),i.on("drain",bs),i.on("error",vs),i.on("message",ws),i.on("ping",Ts),i.on("pong",Os),n.onerror=ks,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",jt),e.on("data",me),e.on("end",$t),e.on("error",Gt),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[R.extensionName]&&this._extensions[R.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,s=>{s||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Wt(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){je(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||pe,r,s)}pong(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){je(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||pe,r,s)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(s=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){je(this,e,s);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[R.extensionName]||(i.compress=!1),this._sender.send(e||pe,i,s)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){x(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(p,"CONNECTING",{enumerable:!0,value:N.indexOf("CONNECTING")});Object.defineProperty(p.prototype,"CONNECTING",{enumerable:!0,value:N.indexOf("CONNECTING")});Object.defineProperty(p,"OPEN",{enumerable:!0,value:N.indexOf("OPEN")});Object.defineProperty(p.prototype,"OPEN",{enumerable:!0,value:N.indexOf("OPEN")});Object.defineProperty(p,"CLOSING",{enumerable:!0,value:N.indexOf("CLOSING")});Object.defineProperty(p.prototype,"CLOSING",{enumerable:!0,value:N.indexOf("CLOSING")});Object.defineProperty(p,"CLOSED",{enumerable:!0,value:N.indexOf("CLOSED")});Object.defineProperty(p.prototype,"CLOSED",{enumerable:!0,value:N.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(p.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(p.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Fe])return e[hs];return null},set(e){for(let r of this.listeners(t))if(r[Fe]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Fe]:!0})}})});p.prototype.addEventListener=ds;p.prototype.removeEventListener=ps;qt.exports=p;function Mt(t,e,r,s){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:ls,protocolVersion:We[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...s,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,t._closeTimeout=i.closeTimeout,!We.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${We.join(", ")})`);let n;if(e instanceof Me)n=e;else try{n=new Me(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",c=n.protocol==="ws+unix:",a;if(n.protocol!=="ws:"&&!o&&!c?a=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:c&&!n.pathname?a="The URL's pathname is empty":n.hash&&(a="The URL contains a fragment identifier"),a){let u=new SyntaxError(a);if(t._redirects===0)throw u;_e(t,u);return}let l=o?443:80,f=is(16).toString("base64"),h=o?ts.request:rs.request,d=new Set,m;if(i.createConnection=i.createConnection||(o?xs:Ss),i.defaultPort=i.defaultPort||l,i.port=n.port||l,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":f,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(m=new R({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=_s({[R.extensionName]:m.offer()})),r.length){for(let u of r){if(typeof u!="string"||!ys.test(u)||d.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");d.add(u)}i.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),c){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1]}let _;if(i.followRedirects){if(t._redirects===0){t._originalIpc=c,t._originalSecure=o,t._originalHostOrSocketPath=c?i.socketPath:n.host;let u=s&&s.headers;if(s={...s,headers:{}},u)for(let[y,F]of Object.entries(u))s.headers[y.toLowerCase()]=F}else if(t.listenerCount("redirect")===0){let u=c?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0)}i.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),_=t._req=h(i),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=h(i);i.timeout&&_.on("timeout",()=>{x(t,_,"Opening handshake has timed out")}),_.on("error",u=>{_===null||_[At]||(_=t._req=null,_e(t,u))}),_.on("response",u=>{let y=u.headers.location,F=u.statusCode;if(y&&i.followRedirects&&F>=300&&F<400){if(++t._redirects>i.maxRedirects){x(t,_,"Maximum redirects exceeded");return}_.abort();let Y;try{Y=new Me(y,e)}catch{let W=new SyntaxError(`Invalid URL: ${y}`);_e(t,W);return}Mt(t,Y,r,s)}else t.emit("unexpected-response",_,u)||x(t,_,`Unexpected server response: ${u.statusCode}`)}),_.on("upgrade",(u,y,F)=>{if(t.emit("upgrade",u),t.readyState!==p.CONNECTING)return;_=t._req=null;let Y=u.headers.upgrade;if(Y===void 0||Y.toLowerCase()!=="websocket"){x(t,y,"Invalid Upgrade header");return}let Ke=ns("sha1").update(f+fs).digest("base64");if(u.headers["sec-websocket-accept"]!==Ke){x(t,y,"Invalid Sec-WebSocket-Accept header");return}let W=u.headers["sec-websocket-protocol"],K;if(W!==void 0?d.size?d.has(W)||(K="Server sent an invalid subprotocol"):K="Server sent a subprotocol but none was requested":d.size&&(K="Server sent no subprotocol"),K){x(t,y,K);return}W&&(t._protocol=W);let Xe=u.headers["sec-websocket-extensions"];if(Xe!==void 0){if(!m){x(t,y,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let Ee;try{Ee=ms(Xe)}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}let Ze=Object.keys(Ee);if(Ze.length!==1||Ze[0]!==R.extensionName){x(t,y,"Server indicated an extension that was not requested");return}try{m.accept(Ee[R.extensionName])}catch{x(t,y,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[R.extensionName]=m}t.setSocket(y,F,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(_,t):_.end()}function _e(t,e){t._readyState=p.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ss(t){return t.path=t.socketPath,Dt.connect(t)}function xs(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Dt.isIP(t.host)?"":t.host),ss.connect(t)}function x(t,e,r){t._readyState=p.CLOSING;let s=new Error(r);Error.captureStackTrace(s,x),e.setHeader?(e[At]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(_e,t,s)):(e.destroy(s),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function je(t,e,r){if(e){let s=cs(e)?e.size:gs(e).length;t._socket?t._sender._bufferedBytes+=s:t._bufferedAmount+=s}if(r){let s=new Error(`WebSocket is not open: readyState ${t.readyState} (${N[t.readyState]})`);process.nextTick(r,s)}}function Es(t,e){let r=this[g];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[g]!==void 0&&(r._socket.removeListener("data",me),process.nextTick(Ft,r._socket),t===1005?r.close():r.close(t,e))}function bs(){let t=this[g];t.isPaused||t._socket.resume()}function vs(t){let e=this[g];e._socket[g]!==void 0&&(e._socket.removeListener("data",me),process.nextTick(Ft,e._socket),e.close(t[us])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function It(){this[g].emitClose()}function ws(t,e){this[g].emit("message",t,e)}function Ts(t){let e=this[g];e._autoPong&&e.pong(t,!this._isServer,Ut),e.emit("ping",t)}function Os(t){this[g].emit("pong",t)}function Ft(t){t.resume()}function ks(t){let e=this[g];e.readyState!==p.CLOSED&&(e.readyState===p.OPEN&&(e._readyState=p.CLOSING,Wt(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Wt(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function jt(){let t=this[g];if(this.removeListener("close",jt),this.removeListener("data",me),this.removeListener("end",$t),t._readyState=p.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[g]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",It),t._receiver.on("finish",It))}function me(t){this[g]._receiver.write(t)||this.pause()}function $t(){let t=this[g];t._readyState=p.CLOSING,t._receiver.end(),this.end()}function Gt(){let t=this[g];this.removeListener("error",Gt),this.on("error",Ut),t&&(t._readyState=p.CLOSING,this.destroy())}});var Jt=S((xi,zt)=>{"use strict";var Si=ge(),{Duplex:Ns}=require("stream");function Vt(t){t.emit("close")}function Cs(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Ht(t){this.removeListener("error",Ht),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Ps(t,e){let r=!0,s=new Ns({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let c=!o&&s._readableState.objectMode?n.toString():n;s.push(c)||t.pause()}),t.once("error",function(n){s.destroyed||(r=!1,s.destroy(n))}),t.once("close",function(){s.destroyed||s.push(null)}),s._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(Vt,s);return}let o=!1;t.once("error",function(a){o=!0,n(a)}),t.once("close",function(){o||n(i),process.nextTick(Vt,s)}),r&&t.terminate()},s._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){s._final(i)});return}t._socket!==null&&(t._socket._writableState.finished?(i(),s._readableState.endEmitted&&s.destroy()):(t._socket.once("finish",function(){i()}),t.close()))},s._read=function(){t.isPaused&&t.resume()},s._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){s._write(i,n,o)});return}t.send(i,o)},s.on("end",Cs),s.on("error",Ht),s}zt.exports=Ps});var $e=S((Ei,Yt)=>{"use strict";var{tokenChars:Ls}=q();function Rs(t){let e=new Set,r=-1,s=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(s===-1&&Ls[o]===1)r===-1&&(r=i);else if(i!==0&&(o===32||o===9))s===-1&&r!==-1&&(s=i);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${i}`);s===-1&&(s=i);let c=t.slice(r,s);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);e.add(c),r=s=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(r===-1||s!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Yt.exports={parse:Rs}});var rr=S((vi,tr)=>{"use strict";var Bs=require("events"),ye=require("http"),{Duplex:bi}=require("stream"),{createHash:Is}=require("crypto"),Kt=de(),A=G(),Ds=$e(),Us=ge(),{CLOSE_TIMEOUT:As,GUID:Ms,kWebSocket:Fs}=T(),Ws=/^[+/0-9A-Za-z]{22}==$/,Xt=0,Zt=1,er=2,Ge=class extends Bs{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:256*1024,maxFragments:16*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:As,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Us,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ye.createServer((s,i)=>{let n=ye.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let s=this.emit.bind(this,"connection");this._removeListeners=js(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,s)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Xt}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===er){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(re,this);return}if(e&&this.once("close",e),this._state!==Zt)if(this._state=Zt,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(re,this):process.nextTick(re,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{re(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,s,i){r.on("error",Qt);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,c=+e.headers["sec-websocket-version"];if(e.method!=="GET"){M(this,e,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){M(this,e,r,400,"Invalid Upgrade header");return}if(n===void 0||!Ws.test(n)){M(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(c!==13&&c!==8){M(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){se(r,400);return}let a=e.headers["sec-websocket-protocol"],l=new Set;if(a!==void 0)try{l=Ds.parse(a)}catch{M(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let f=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&f!==void 0){let d=new A({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let m=Kt.parse(f);m[A.extensionName]&&(d.accept(m[A.extensionName]),h[A.extensionName]=d)}catch{M(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let d={origin:e.headers[`${c===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(d,(m,_,u,y)=>{if(!m)return se(r,_||401,u,y);this.completeUpgrade(h,n,l,e,r,s,i)});return}if(!this.options.verifyClient(d))return se(r,401)}this.completeUpgrade(h,n,l,e,r,s,i)}completeUpgrade(e,r,s,i,n,o,c){if(!n.readable||!n.writable)return n.destroy();if(n[Fs])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Xt)return se(n,503);let l=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Is("sha1").update(r+Ms).digest("base64")}`],f=new this.options.WebSocket(null,void 0,this.options);if(s.size){let h=this.options.handleProtocols?this.options.handleProtocols(s,i):s.values().next().value;h&&(l.push(`Sec-WebSocket-Protocol: ${h}`),f._protocol=h)}if(e[A.extensionName]){let h=e[A.extensionName].params,d=Kt.format({[A.extensionName]:[h]});l.push(`Sec-WebSocket-Extensions: ${d}`),f._extensions=e}this.emit("headers",l,i),n.write(l.concat(`\r
|
|
2
|
+
"use strict";var Jn=Object.create;var at=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var Yn=Object.getOwnPropertyNames;var Zn=Object.getPrototypeOf,Xn=Object.prototype.hasOwnProperty;var x=(e,t)=>()=>(e&&(t=e(e=0)),t);var w=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Zt=(e,t)=>{for(var r in t)at(e,r,{get:t[r],enumerable:!0})},Qn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Yn(t))!Xn.call(e,i)&&i!==r&&at(e,i,{get:()=>t[i],enumerable:!(n=Kn(t,i))||n.enumerable});return e};var U=(e,t,r)=>(r=e!=null?Jn(Zn(e)):{},Qn(t||!e||!e.__esModule?at(r,"default",{value:e,enumerable:!0}):r,e));var Qt={};Zt(Qt,{extractBearer:()=>Ie,hasScope:()=>Xt,tokenAllows:()=>ce});function Ie(e){let t=Array.isArray(e)?e[0]:e;if(!t)return null;let r=/^Bearer\s+(.+)$/i.exec(t.trim());return r?r[1].trim():null}function Xt(e,t){return e.includes("*")||e.includes(t)}function ce(e,t){return e?Xt(e.scopes,t):!1}var fe=x(()=>{"use strict"});var R=w((fo,rr)=>{"use strict";var er=["nodebuffer","arraybuffer","fragments"],tr=typeof Blob<"u";tr&&er.push("blob");rr.exports={BINARY_TYPES:er,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:tr,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ue=w((uo,Le)=>{"use strict";var{EMPTY_BUFFER:ri}=R(),ft=Buffer[Symbol.species];function ni(e,t){if(e.length===0)return ri;if(e.length===1)return e[0];let r=Buffer.allocUnsafe(t),n=0;for(let i=0;i<e.length;i++){let s=e[i];r.set(s,n),n+=s.length}return n<t?new ft(r.buffer,r.byteOffset,n):r}function nr(e,t,r,n,i){for(let s=0;s<i;s++)r[n+s]=e[s]^t[s&3]}function ir(e,t){for(let r=0;r<e.length;r++)e[r]^=t[r&3]}function ii(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function ut(e){if(ut.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=new ft(e):ArrayBuffer.isView(e)?t=new ft(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),ut.readOnly=!1),t}Le.exports={concat:ni,mask:nr,toArrayBuffer:ii,toBuffer:ut,unmask:ir};if(!process.env.WS_NO_BUFFER_UTIL)try{let e=require("bufferutil");Le.exports.mask=function(t,r,n,i,s){s<48?nr(t,r,n,i,s):e.mask(t,r,n,i,s)},Le.exports.unmask=function(t,r){t.length<32?ir(t,r):e.unmask(t,r)}}catch{}});var ar=w((ho,or)=>{"use strict";var sr=Symbol("kDone"),dt=Symbol("kRun"),ht=class{constructor(t){this[sr]=()=>{this.pending--,this[dt]()},this.concurrency=t||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[dt]()}[dt](){if(this.pending!==this.concurrency&&this.jobs.length){let t=this.jobs.shift();this.pending++,t(this[sr])}}};or.exports=ht});var te=w((po,ur)=>{"use strict";var de=require("zlib"),lr=ue(),si=ar(),{kStatusCode:cr}=R(),oi=Buffer[Symbol.species],ai=Buffer.from([0,0,255,255]),Re=Symbol("permessage-deflate"),M=Symbol("total-length"),Q=Symbol("callback"),j=Symbol("buffers"),ee=Symbol("error"),De,pt=class{constructor(t){if(this._options=t||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!De){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;De=new si(r)}}static get extensionName(){return"permessage-deflate"}offer(){let t={};return this._options.serverNoContextTakeover&&(t.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(t.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(t.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?t.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(t.client_max_window_bits=!0),t}accept(t){return t=this.normalizeParams(t),this.params=this._isServer?this.acceptAsServer(t):this.acceptAsClient(t),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let t=this._deflate[Q];this._deflate.close(),this._deflate=null,t&&t(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(t){let r=this._options,n=t.find(i=>!(r.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>i.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&(typeof i.client_max_window_bits=="number"?r.clientMaxWindowBits>i.client_max_window_bits:!i.client_max_window_bits)));if(!n)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(n.server_no_context_takeover=!0),r.clientNoContextTakeover&&(n.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(n.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?n.client_max_window_bits=r.clientMaxWindowBits:(n.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete n.client_max_window_bits,n}acceptAsClient(t){let r=t[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(t){return t.forEach(r=>{Object.keys(r).forEach(n=>{let i=r[n];if(i.length>1)throw new Error(`Parameter "${n}" must have only a single value`);if(i=i[0],n==="client_max_window_bits"){if(i!==!0){let s=+i;if(!Number.isInteger(s)||s<8||s>15)throw new TypeError(`Invalid value for parameter "${n}": ${i}`);i=s}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${n}": ${i}`)}else if(n==="server_max_window_bits"){let s=+i;if(!Number.isInteger(s)||s<8||s>15)throw new TypeError(`Invalid value for parameter "${n}": ${i}`);i=s}else if(n==="client_no_context_takeover"||n==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${n}": ${i}`)}else throw new Error(`Unknown parameter "${n}"`);r[n]=i})}),t}decompress(t,r,n){De.add(i=>{this._decompress(t,r,(s,o)=>{i(),n(s,o)})})}compress(t,r,n){De.add(i=>{this._compress(t,r,(s,o)=>{i(),n(s,o)})})}_decompress(t,r,n){let i=this._isServer?"client":"server";if(!this._inflate){let s=`${i}_max_window_bits`,o=typeof this.params[s]!="number"?de.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=de.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[Re]=this,this._inflate[M]=0,this._inflate[j]=[],this._inflate.on("error",ci),this._inflate.on("data",fr)}this._inflate[Q]=n,this._inflate.write(t),r&&this._inflate.write(ai),this._inflate.flush(()=>{let s=this._inflate[ee];if(s){this._inflate.close(),this._inflate=null,n(s);return}let o=lr.concat(this._inflate[j],this._inflate[M]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[M]=0,this._inflate[j]=[],r&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),n(null,o)})}_compress(t,r,n){let i=this._isServer?"server":"client";if(!this._deflate){let s=`${i}_max_window_bits`,o=typeof this.params[s]!="number"?de.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=de.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[M]=0,this._deflate[j]=[],this._deflate.on("data",li)}this._deflate[Q]=n,this._deflate.write(t),this._deflate.flush(de.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=lr.concat(this._deflate[j],this._deflate[M]);r&&(s=new oi(s.buffer,s.byteOffset,s.length-4)),this._deflate[Q]=null,this._deflate[M]=0,this._deflate[j]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),n(null,s)})}};ur.exports=pt;function li(e){this[j].push(e),this[M]+=e.length}function fr(e){if(this[M]+=e.length,this[Re]._maxPayload<1||this[M]<=this[Re]._maxPayload){this[j].push(e);return}this[ee]=new RangeError("Max payload size exceeded"),this[ee].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[ee][cr]=1009,this.removeListener("data",fr),this.reset()}function ci(e){if(this[Re]._inflate=null,this[ee]){this[Q](this[ee]);return}e[cr]=1007,this[Q](e)}});var re=w((mo,Me)=>{"use strict";var{isUtf8:dr}=require("buffer"),{hasBlob:fi}=R(),ui=[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 di(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function mt(e){let t=e.length,r=0;for(;r<t;)if(!(e[r]&128))r++;else if((e[r]&224)===192){if(r+1===t||(e[r+1]&192)!==128||(e[r]&254)===192)return!1;r+=2}else if((e[r]&240)===224){if(r+2>=t||(e[r+1]&192)!==128||(e[r+2]&192)!==128||e[r]===224&&(e[r+1]&224)===128||e[r]===237&&(e[r+1]&224)===160)return!1;r+=3}else if((e[r]&248)===240){if(r+3>=t||(e[r+1]&192)!==128||(e[r+2]&192)!==128||(e[r+3]&192)!==128||e[r]===240&&(e[r+1]&240)===128||e[r]===244&&e[r+1]>143||e[r]>244)return!1;r+=4}else return!1;return!0}function hi(e){return fi&&typeof e=="object"&&typeof e.arrayBuffer=="function"&&typeof e.type=="string"&&typeof e.stream=="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}Me.exports={isBlob:hi,isValidStatusCode:di,isValidUTF8:mt,tokenChars:ui};if(dr)Me.exports.isValidUTF8=function(e){return e.length<24?mt(e):dr(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let e=require("utf-8-validate");Me.exports.isValidUTF8=function(t){return t.length<32?mt(t):e(t)}}catch{}});var bt=w((go,Sr)=>{"use strict";var{Writable:pi}=require("stream"),hr=te(),{BINARY_TYPES:mi,EMPTY_BUFFER:pr,kStatusCode:gi,kWebSocket:_i}=R(),{concat:gt,toArrayBuffer:yi,unmask:Si}=ue(),{isValidStatusCode:bi,isValidUTF8:mr}=re(),$e=Buffer[Symbol.species],O=0,gr=1,_r=2,yr=3,_t=4,yt=5,Be=6,St=class extends pi{constructor(t={}){super(),this._allowSynchronousEvents=t.allowSynchronousEvents!==void 0?t.allowSynchronousEvents:!0,this._binaryType=t.binaryType||mi[0],this._extensions=t.extensions||{},this._isServer=!!t.isServer,this._maxBufferedChunks=t.maxBufferedChunks|0,this._maxFragments=t.maxFragments|0,this._maxPayload=t.maxPayload|0,this._skipUTF8Validation=!!t.skipUTF8Validation,this[_i]=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._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=O}_write(t,r,n){if(this._opcode===8&&this._state==O)return n();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){n(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=t.length,this._buffers.push(t),this.startLoop(n)}consume(t){if(this._bufferedBytes-=t,t===this._buffers[0].length)return this._buffers.shift();if(t<this._buffers[0].length){let n=this._buffers[0];return this._buffers[0]=new $e(n.buffer,n.byteOffset+t,n.length-t),new $e(n.buffer,n.byteOffset,t)}let r=Buffer.allocUnsafe(t);do{let n=this._buffers[0],i=r.length-t;t>=n.length?r.set(this._buffers.shift(),i):(r.set(new Uint8Array(n.buffer,n.byteOffset,t),i),this._buffers[0]=new $e(n.buffer,n.byteOffset+t,n.length-t)),t-=n.length}while(t>0);return r}startLoop(t){this._loop=!0;do switch(this._state){case O:this.getInfo(t);break;case gr:this.getPayloadLength16(t);break;case _r:this.getPayloadLength64(t);break;case yr:this.getMask();break;case _t:this.getData(t);break;case yt:case Be:this._loop=!1;return}while(this._loop);this._errored||t()}getInfo(t){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");t(i);return}let n=(r[0]&64)===64;if(n&&!this._extensions[hr.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(n){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}this._compressed=n}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");t(i);return}if(n){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");t(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");t(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");t(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");t(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");t(i);return}this._payloadLength===126?this._state=gr:this._payloadLength===127?this._state=_r:this.haveLength(t)}getPayloadLength16(t){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(t)}getPayloadLength64(t){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),n=r.readUInt32BE(0);if(n>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");t(i);return}this._payloadLength=n*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(t)}haveLength(t){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");t(r);return}this._masked?this._state=yr:this._state=_t}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=_t}getData(t){let r=pr;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&Si(r,this._mask)}if(this._opcode>7){this.controlMessage(r,t);return}if(this._maxFragments>0&&++this._numFragments>this._maxFragments){let n=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");t(n);return}if(this._compressed){this._state=yt,this.decompress(r,t);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(t)}decompress(t,r){this._extensions[hr.extensionName].decompress(t,this._fin,(i,s)=>{if(i)return r(i);if(s.length){if(this._messageLength+=s.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(s)}this.dataMessage(r),this._state===O&&this.startLoop(r)})}dataMessage(t){if(!this._fin){this._state=O;return}let r=this._messageLength,n=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=gt(n,r):this._binaryType==="arraybuffer"?i=yi(gt(n,r)):this._binaryType==="blob"?i=new Blob(n):i=n,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=O):(this._state=Be,setImmediate(()=>{this.emit("message",i,!0),this._state=O,this.startLoop(t)}))}else{let i=gt(n,r);if(!this._skipUTF8Validation&&!mr(i)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(s);return}this._state===yt||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=O):(this._state=Be,setImmediate(()=>{this.emit("message",i,!1),this._state=O,this.startLoop(t)}))}}controlMessage(t,r){if(this._opcode===8){if(t.length===0)this._loop=!1,this.emit("conclude",1005,pr),this.end();else{let n=t.readUInt16BE(0);if(!bi(n)){let s=this.createError(RangeError,`invalid status code ${n}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(s);return}let i=new $e(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!mr(i)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(s);return}this._loop=!1,this.emit("conclude",n,i),this.end()}this._state=O;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",t),this._state=O):(this._state=Be,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",t),this._state=O,this.startLoop(r)}))}createError(t,r,n,i,s){this._loop=!1,this._errored=!0;let o=new t(n?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=s,o[gi]=i,o}};Sr.exports=St});var xt=w((yo,vr)=>{"use strict";var{Duplex:_o}=require("stream"),{randomFillSync:Ei}=require("crypto"),{types:{isUint8Array:vi}}=require("util"),br=te(),{EMPTY_BUFFER:xi,kWebSocket:wi,NOOP:Ti}=R(),{isBlob:ne,isValidStatusCode:ki}=re(),{mask:Er,toBuffer:G}=ue(),A=Symbol("kByteLength"),Ci=Buffer.alloc(4),Ue=8*1024,H,ie=Ue,N=0,Oi=1,Ai=2,Et=class e{constructor(t,r,n){this._extensions=r||{},n&&(this._generateMask=n,this._maskBuffer=Buffer.alloc(4)),this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=N,this.onerror=Ti,this[wi]=void 0}static frame(t,r){let n,i=!1,s=2,o=!1;r.mask&&(n=r.maskBuffer||Ci,r.generateMask?r.generateMask(n):(ie===Ue&&(H===void 0&&(H=Buffer.alloc(Ue)),Ei(H,0,Ue),ie=0),n[0]=H[ie++],n[1]=H[ie++],n[2]=H[ie++],n[3]=H[ie++]),o=(n[0]|n[1]|n[2]|n[3])===0,s=6);let a;typeof t=="string"?(!r.mask||o)&&r[A]!==void 0?a=r[A]:(t=Buffer.from(t),a=t.length):(a=t.length,i=r.mask&&r.readOnly&&!o);let l=a;a>=65536?(s+=8,l=127):a>125&&(s+=2,l=126);let c=Buffer.allocUnsafe(i?a+s:s);return c[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(c[0]|=64),c[1]=l,l===126?c.writeUInt16BE(a,2):l===127&&(c[2]=c[3]=0,c.writeUIntBE(a,4,6)),r.mask?(c[1]|=128,c[s-4]=n[0],c[s-3]=n[1],c[s-2]=n[2],c[s-1]=n[3],o?[c,t]:i?(Er(t,n,c,s,a),[c]):(Er(t,n,t,0,a),[c,t])):[c,t]}close(t,r,n,i){let s;if(t===void 0)s=xi;else{if(typeof t!="number"||!ki(t))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0);else{let a=Buffer.byteLength(r);if(a>123)throw new RangeError("The message must not be greater than 123 bytes");if(s=Buffer.allocUnsafe(2+a),s.writeUInt16BE(t,0),typeof r=="string")s.write(r,2);else if(vi(r))s.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[A]:s.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==N?this.enqueue([this.dispatch,s,!1,o,i]):this.sendFrame(e.frame(s,o),i)}ping(t,r,n){let i,s;if(typeof t=="string"?(i=Buffer.byteLength(t),s=!1):ne(t)?(i=t.size,s=!1):(t=G(t),i=t.length,s=G.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[A]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};ne(t)?this._state!==N?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==N?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}pong(t,r,n){let i,s;if(typeof t=="string"?(i=Buffer.byteLength(t),s=!1):ne(t)?(i=t.size,s=!1):(t=G(t),i=t.length,s=G.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[A]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};ne(t)?this._state!==N?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==N?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}send(t,r,n){let i=this._extensions[br.extensionName],s=r.binary?2:1,o=r.compress,a,l;typeof t=="string"?(a=Buffer.byteLength(t),l=!1):ne(t)?(a=t.size,l=!1):(t=G(t),a=t.length,l=G.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=a>=i._threshold),this._compress=o):(o=!1,s=0),r.fin&&(this._firstFragment=!0);let c={[A]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:s,readOnly:l,rsv1:o};ne(t)?this._state!==N?this.enqueue([this.getBlobData,t,this._compress,c,n]):this.getBlobData(t,this._compress,c,n):this._state!==N?this.enqueue([this.dispatch,t,this._compress,c,n]):this.dispatch(t,this._compress,c,n)}getBlobData(t,r,n,i){this._bufferedBytes+=n[A],this._state=Ai,t.arrayBuffer().then(s=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(vt,this,a,i);return}this._bufferedBytes-=n[A];let o=G(s);r?this.dispatch(o,r,n,i):(this._state=N,this.sendFrame(e.frame(o,n),i),this.dequeue())}).catch(s=>{process.nextTick(Ni,this,s,i)})}dispatch(t,r,n,i){if(!r){this.sendFrame(e.frame(t,n),i);return}let s=this._extensions[br.extensionName];this._bufferedBytes+=n[A],this._state=Oi,s.compress(t,n.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");vt(this,l,i);return}this._bufferedBytes-=n[A],this._state=N,n.readOnly=!1,this.sendFrame(e.frame(a,n),i),this.dequeue()})}dequeue(){for(;this._state===N&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[3][A],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][A],this._queue.push(t)}sendFrame(t,r){t.length===2?(this._socket.cork(),this._socket.write(t[0]),this._socket.write(t[1],r),this._socket.uncork()):this._socket.write(t[0],r)}};vr.exports=Et;function vt(e,t,r){typeof r=="function"&&r(t);for(let n=0;n<e._queue.length;n++){let i=e._queue[n],s=i[i.length-1];typeof s=="function"&&s(t)}}function Ni(e,t,r){vt(e,t,r),e.onerror(t)}});var Pr=w((So,Nr)=>{"use strict";var{kForOnEventAttribute:he,kListener:wt}=R(),xr=Symbol("kCode"),wr=Symbol("kData"),Tr=Symbol("kError"),kr=Symbol("kMessage"),Cr=Symbol("kReason"),se=Symbol("kTarget"),Or=Symbol("kType"),Ar=Symbol("kWasClean"),$=class{constructor(t){this[se]=null,this[Or]=t}get target(){return this[se]}get type(){return this[Or]}};Object.defineProperty($.prototype,"target",{enumerable:!0});Object.defineProperty($.prototype,"type",{enumerable:!0});var z=class extends ${constructor(t,r={}){super(t),this[xr]=r.code===void 0?0:r.code,this[Cr]=r.reason===void 0?"":r.reason,this[Ar]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[xr]}get reason(){return this[Cr]}get wasClean(){return this[Ar]}};Object.defineProperty(z.prototype,"code",{enumerable:!0});Object.defineProperty(z.prototype,"reason",{enumerable:!0});Object.defineProperty(z.prototype,"wasClean",{enumerable:!0});var oe=class extends ${constructor(t,r={}){super(t),this[Tr]=r.error===void 0?null:r.error,this[kr]=r.message===void 0?"":r.message}get error(){return this[Tr]}get message(){return this[kr]}};Object.defineProperty(oe.prototype,"error",{enumerable:!0});Object.defineProperty(oe.prototype,"message",{enumerable:!0});var pe=class extends ${constructor(t,r={}){super(t),this[wr]=r.data===void 0?null:r.data}get data(){return this[wr]}};Object.defineProperty(pe.prototype,"data",{enumerable:!0});var Pi={addEventListener(e,t,r={}){for(let i of this.listeners(e))if(!r[he]&&i[wt]===t&&!i[he])return;let n;if(e==="message")n=function(s,o){let a=new pe("message",{data:o?s:s.toString()});a[se]=this,je(t,this,a)};else if(e==="close")n=function(s,o){let a=new z("close",{code:s,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[se]=this,je(t,this,a)};else if(e==="error")n=function(s){let o=new oe("error",{error:s,message:s.message});o[se]=this,je(t,this,o)};else if(e==="open")n=function(){let s=new $("open");s[se]=this,je(t,this,s)};else return;n[he]=!!r[he],n[wt]=t,r.once?this.once(e,n):this.on(e,n)},removeEventListener(e,t){for(let r of this.listeners(e))if(r[wt]===t&&!r[he]){this.removeListener(e,r);break}}};Nr.exports={CloseEvent:z,ErrorEvent:oe,Event:$,EventTarget:Pi,MessageEvent:pe};function je(e,t,r){typeof e=="object"&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}});var Fe=w((bo,Ir)=>{"use strict";var{tokenChars:me}=re();function D(e,t,r){e[t]===void 0?e[t]=[r]:e[t].push(r)}function Ii(e){let t=Object.create(null),r=Object.create(null),n=!1,i=!1,s=!1,o,a,l=-1,c=-1,f=-1,d=0;for(;d<e.length;d++)if(c=e.charCodeAt(d),o===void 0)if(f===-1&&me[c]===1)l===-1&&(l=d);else if(d!==0&&(c===32||c===9))f===-1&&l!==-1&&(f=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);f===-1&&(f=d);let h=e.slice(l,f);c===44?(D(t,h,r),r=Object.create(null)):o=h,l=f=-1}else throw new SyntaxError(`Unexpected character at index ${d}`);else if(a===void 0)if(f===-1&&me[c]===1)l===-1&&(l=d);else if(c===32||c===9)f===-1&&l!==-1&&(f=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);f===-1&&(f=d),D(r,e.slice(l,f),!0),c===44&&(D(t,o,r),r=Object.create(null),o=void 0),l=f=-1}else if(c===61&&l!==-1&&f===-1)a=e.slice(l,d),l=f=-1;else throw new SyntaxError(`Unexpected character at index ${d}`);else if(i){if(me[c]!==1)throw new SyntaxError(`Unexpected character at index ${d}`);l===-1?l=d:n||(n=!0),i=!1}else if(s)if(me[c]===1)l===-1&&(l=d);else if(c===34&&l!==-1)s=!1,f=d;else if(c===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${d}`);else if(c===34&&e.charCodeAt(d-1)===61)s=!0;else if(f===-1&&me[c]===1)l===-1&&(l=d);else if(l!==-1&&(c===32||c===9))f===-1&&(f=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);f===-1&&(f=d);let h=e.slice(l,f);n&&(h=h.replace(/\\/g,""),n=!1),D(r,a,h),c===44&&(D(t,o,r),r=Object.create(null),o=void 0),a=void 0,l=f=-1}else throw new SyntaxError(`Unexpected character at index ${d}`);if(l===-1||s||c===32||c===9)throw new SyntaxError("Unexpected end of input");f===-1&&(f=d);let u=e.slice(l,f);return o===void 0?D(t,u,r):(a===void 0?D(r,u,!0):n?D(r,a,u.replace(/\\/g,"")):D(r,a,u),D(t,o,r)),t}function Li(e){return Object.keys(e).map(t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map(n=>[t].concat(Object.keys(n).map(i=>{let s=n[i];return Array.isArray(s)||(s=[s]),s.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Ir.exports={format:Li,parse:Ii}});var Ge=w((xo,Vr)=>{"use strict";var Di=require("events"),Ri=require("https"),Mi=require("http"),Rr=require("net"),$i=require("tls"),{randomBytes:Bi,createHash:Ui}=require("crypto"),{Duplex:Eo,Readable:vo}=require("stream"),{URL:Tt}=require("url"),F=te(),ji=bt(),Fi=xt(),{isBlob:Wi}=re(),{BINARY_TYPES:Lr,CLOSE_TIMEOUT:qi,EMPTY_BUFFER:We,GUID:Vi,kForOnEventAttribute:kt,kListener:Gi,kStatusCode:Hi,kWebSocket:v,NOOP:Mr}=R(),{EventTarget:{addEventListener:zi,removeEventListener:Ji}}=Pr(),{format:Ki,parse:Yi}=Fe(),{toBuffer:Zi}=ue(),$r=Symbol("kAborted"),Ct=[8,13],B=["CONNECTING","OPEN","CLOSING","CLOSED"],Xi=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,y=class e extends Di{constructor(t,r,n){super(),this._binaryType=Lr[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=We,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,t!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(n=r,r=[]):r=[r]),Br(this,t,r,n)):(this._autoPong=n.autoPong,this._closeTimeout=n.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(t){Lr.includes(t)&&(this._binaryType=t,this._receiver&&(this._receiver._binaryType=t))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}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(t,r,n){let i=new ji({allowSynchronousEvents:n.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:n.maxBufferedChunks,maxFragments:n.maxFragments,maxPayload:n.maxPayload,skipUTF8Validation:n.skipUTF8Validation}),s=new Fi(t,this._extensions,n.generateMask);this._receiver=i,this._sender=s,this._socket=t,i[v]=this,s[v]=this,t[v]=this,i.on("conclude",ts),i.on("drain",rs),i.on("error",ns),i.on("message",is),i.on("ping",ss),i.on("pong",os),s.onerror=as,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",Fr),t.on("data",Ve),t.on("end",Wr),t.on("error",qr),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[F.extensionName]&&this._extensions[F.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,r){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){T(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===e.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=e.CLOSING,this._sender.close(t,r,!this._isServer,n=>{n||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),jr(this)}}pause(){this.readyState===e.CONNECTING||this.readyState===e.CLOSED||(this._paused=!0,this._socket.pause())}ping(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(n=t,t=r=void 0):typeof r=="function"&&(n=r,r=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){Ot(this,t,n);return}r===void 0&&(r=!this._isServer),this._sender.ping(t||We,r,n)}pong(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"?(n=t,t=r=void 0):typeof r=="function"&&(n=r,r=void 0),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){Ot(this,t,n);return}r===void 0&&(r=!this._isServer),this._sender.pong(t||We,r,n)}resume(){this.readyState===e.CONNECTING||this.readyState===e.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(n=r,r={}),typeof t=="number"&&(t=t.toString()),this.readyState!==e.OPEN){Ot(this,t,n);return}let i={binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[F.extensionName]||(i.compress=!1),this._sender.send(t||We,i,n)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){T(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=e.CLOSING,this._socket.destroy())}}};Object.defineProperty(y,"CONNECTING",{enumerable:!0,value:B.indexOf("CONNECTING")});Object.defineProperty(y.prototype,"CONNECTING",{enumerable:!0,value:B.indexOf("CONNECTING")});Object.defineProperty(y,"OPEN",{enumerable:!0,value:B.indexOf("OPEN")});Object.defineProperty(y.prototype,"OPEN",{enumerable:!0,value:B.indexOf("OPEN")});Object.defineProperty(y,"CLOSING",{enumerable:!0,value:B.indexOf("CLOSING")});Object.defineProperty(y.prototype,"CLOSING",{enumerable:!0,value:B.indexOf("CLOSING")});Object.defineProperty(y,"CLOSED",{enumerable:!0,value:B.indexOf("CLOSED")});Object.defineProperty(y.prototype,"CLOSED",{enumerable:!0,value:B.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(y.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(y.prototype,`on${e}`,{enumerable:!0,get(){for(let t of this.listeners(e))if(t[kt])return t[Gi];return null},set(t){for(let r of this.listeners(e))if(r[kt]){this.removeListener(e,r);break}typeof t=="function"&&this.addEventListener(e,t,{[kt]:!0})}})});y.prototype.addEventListener=zi;y.prototype.removeEventListener=Ji;Vr.exports=y;function Br(e,t,r,n){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:qi,protocolVersion:Ct[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...n,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,e._closeTimeout=i.closeTimeout,!Ct.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Ct.join(", ")})`);let s;if(t instanceof Tt)s=t;else try{s=new Tt(t)}catch{throw new SyntaxError(`Invalid URL: ${t}`)}s.protocol==="http:"?s.protocol="ws:":s.protocol==="https:"&&(s.protocol="wss:"),e._url=s.href;let o=s.protocol==="wss:",a=s.protocol==="ws+unix:",l;if(s.protocol!=="ws:"&&!o&&!a?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:a&&!s.pathname?l="The URL's pathname is empty":s.hash&&(l="The URL contains a fragment identifier"),l){let m=new SyntaxError(l);if(e._redirects===0)throw m;qe(e,m);return}let c=o?443:80,f=Bi(16).toString("base64"),d=o?Ri.request:Mi.request,u=new Set,h;if(i.createConnection=i.createConnection||(o?es:Qi),i.defaultPort=i.defaultPort||c,i.port=s.port||c,i.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":f,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(h=new F({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=Ki({[F.extensionName]:h.offer()})),r.length){for(let m of r){if(typeof m!="string"||!Xi.test(m)||u.has(m))throw new SyntaxError("An invalid or duplicated subprotocol was specified");u.add(m)}i.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(s.username||s.password)&&(i.auth=`${s.username}:${s.password}`),a){let m=i.path.split(":");i.socketPath=m[0],i.path=m[1]}let g;if(i.followRedirects){if(e._redirects===0){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:s.host;let m=n&&n.headers;if(n={...n,headers:{}},m)for(let[S,E]of Object.entries(m))n.headers[S.toLowerCase()]=E}else if(e.listenerCount("redirect")===0){let m=a?e._originalIpc?i.socketPath===e._originalHostOrSocketPath:!1:e._originalIpc?!1:s.host===e._originalHostOrSocketPath;(!m||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,m||delete i.headers.host,i.auth=void 0)}i.auth&&!n.headers.authorization&&(n.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),g=e._req=d(i),e._redirects&&e.emit("redirect",e.url,g)}else g=e._req=d(i);i.timeout&&g.on("timeout",()=>{T(e,g,"Opening handshake has timed out")}),g.on("error",m=>{g===null||g[$r]||(g=e._req=null,qe(e,m))}),g.on("response",m=>{let S=m.headers.location,E=m.statusCode;if(S&&i.followRedirects&&E>=300&&E<400){if(++e._redirects>i.maxRedirects){T(e,g,"Maximum redirects exceeded");return}g.abort();let C;try{C=new Tt(S,t)}catch{let X=new SyntaxError(`Invalid URL: ${S}`);qe(e,X);return}Br(e,C,r,n)}else e.emit("unexpected-response",g,m)||T(e,g,`Unexpected server response: ${m.statusCode}`)}),g.on("upgrade",(m,S,E)=>{if(e.emit("upgrade",m),e.readyState!==y.CONNECTING)return;g=e._req=null;let C=m.headers.upgrade;if(C===void 0||C.toLowerCase()!=="websocket"){T(e,S,"Invalid Upgrade header");return}let q=Ui("sha1").update(f+Vi).digest("base64");if(m.headers["sec-websocket-accept"]!==q){T(e,S,"Invalid Sec-WebSocket-Accept header");return}let X=m.headers["sec-websocket-protocol"],ae;if(X!==void 0?u.size?u.has(X)||(ae="Server sent an invalid subprotocol"):ae="Server sent a subprotocol but none was requested":u.size&&(ae="Server sent no subprotocol"),ae){T(e,S,ae);return}X&&(e._protocol=X);let Kt=m.headers["sec-websocket-extensions"];if(Kt!==void 0){if(!h){T(e,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let st;try{st=Yi(Kt)}catch{T(e,S,"Invalid Sec-WebSocket-Extensions header");return}let Yt=Object.keys(st);if(Yt.length!==1||Yt[0]!==F.extensionName){T(e,S,"Server indicated an extension that was not requested");return}try{h.accept(st[F.extensionName])}catch{T(e,S,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[F.extensionName]=h}e.setSocket(S,E,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(g,e):g.end()}function qe(e,t){e._readyState=y.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function Qi(e){return e.path=e.socketPath,Rr.connect(e)}function es(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=Rr.isIP(e.host)?"":e.host),$i.connect(e)}function T(e,t,r){e._readyState=y.CLOSING;let n=new Error(r);Error.captureStackTrace(n,T),t.setHeader?(t[$r]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(qe,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function Ot(e,t,r){if(t){let n=Wi(t)?t.size:Zi(t).length;e._socket?e._sender._bufferedBytes+=n:e._bufferedAmount+=n}if(r){let n=new Error(`WebSocket is not open: readyState ${e.readyState} (${B[e.readyState]})`);process.nextTick(r,n)}}function ts(e,t){let r=this[v];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,r._socket[v]!==void 0&&(r._socket.removeListener("data",Ve),process.nextTick(Ur,r._socket),e===1005?r.close():r.close(e,t))}function rs(){let e=this[v];e.isPaused||e._socket.resume()}function ns(e){let t=this[v];t._socket[v]!==void 0&&(t._socket.removeListener("data",Ve),process.nextTick(Ur,t._socket),t.close(e[Hi])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function Dr(){this[v].emitClose()}function is(e,t){this[v].emit("message",e,t)}function ss(e){let t=this[v];t._autoPong&&t.pong(e,!this._isServer,Mr),t.emit("ping",e)}function os(e){this[v].emit("pong",e)}function Ur(e){e.resume()}function as(e){let t=this[v];t.readyState!==y.CLOSED&&(t.readyState===y.OPEN&&(t._readyState=y.CLOSING,jr(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function jr(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),e._closeTimeout)}function Fr(){let e=this[v];if(this.removeListener("close",Fr),this.removeListener("data",Ve),this.removeListener("end",Wr),e._readyState=y.CLOSING,!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&this._readableState.length!==0){let t=this.read(this._readableState.length);e._receiver.write(t)}e._receiver.end(),this[v]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",Dr),e._receiver.on("finish",Dr))}function Ve(e){this[v]._receiver.write(e)||this.pause()}function Wr(){let e=this[v];e._readyState=y.CLOSING,e._receiver.end(),this.end()}function qr(){let e=this[v];this.removeListener("error",qr),this.on("error",Mr),e&&(e._readyState=y.CLOSING,this.destroy())}});var Jr=w((To,zr)=>{"use strict";var wo=Ge(),{Duplex:ls}=require("stream");function Gr(e){e.emit("close")}function cs(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Hr(e){this.removeListener("error",Hr),this.destroy(),this.listenerCount("error")===0&&this.emit("error",e)}function fs(e,t){let r=!0,n=new ls({...t,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return e.on("message",function(s,o){let a=!o&&n._readableState.objectMode?s.toString():s;n.push(a)||e.pause()}),e.once("error",function(s){n.destroyed||(r=!1,n.destroy(s))}),e.once("close",function(){n.destroyed||n.push(null)}),n._destroy=function(i,s){if(e.readyState===e.CLOSED){s(i),process.nextTick(Gr,n);return}let o=!1;e.once("error",function(l){o=!0,s(l)}),e.once("close",function(){o||s(i),process.nextTick(Gr,n)}),r&&e.terminate()},n._final=function(i){if(e.readyState===e.CONNECTING){e.once("open",function(){n._final(i)});return}e._socket!==null&&(e._socket._writableState.finished?(i(),n._readableState.endEmitted&&n.destroy()):(e._socket.once("finish",function(){i()}),e.close()))},n._read=function(){e.isPaused&&e.resume()},n._write=function(i,s,o){if(e.readyState===e.CONNECTING){e.once("open",function(){n._write(i,s,o)});return}e.send(i,o)},n.on("end",cs),n.on("error",Hr),n}zr.exports=fs});var At=w((ko,Kr)=>{"use strict";var{tokenChars:us}=re();function ds(e){let t=new Set,r=-1,n=-1,i=0;for(i;i<e.length;i++){let o=e.charCodeAt(i);if(n===-1&&us[o]===1)r===-1&&(r=i);else if(i!==0&&(o===32||o===9))n===-1&&r!==-1&&(n=i);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${i}`);n===-1&&(n=i);let a=e.slice(r,n);if(t.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);t.add(a),r=n=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(r===-1||n!==-1)throw new SyntaxError("Unexpected end of input");let s=e.slice(r,i);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);return t.add(s),t}Kr.exports={parse:ds}});var rn=w((Oo,tn)=>{"use strict";var hs=require("events"),He=require("http"),{Duplex:Co}=require("stream"),{createHash:ps}=require("crypto"),Yr=Fe(),J=te(),ms=At(),gs=Ge(),{CLOSE_TIMEOUT:_s,GUID:ys,kWebSocket:Ss}=R(),bs=/^[+/0-9A-Za-z]{22}==$/,Zr=0,Xr=1,en=2,Nt=class extends hs{constructor(t,r){if(super(),t={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:256*1024,maxFragments:16*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:_s,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:gs,...t},t.port==null&&!t.server&&!t.noServer||t.port!=null&&(t.server||t.noServer)||t.server&&t.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(t.port!=null?(this._server=He.createServer((n,i)=>{let s=He.STATUS_CODES[426];i.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"}),i.end(s)}),this._server.listen(t.port,t.host,t.backlog,r)):t.server&&(this._server=t.server),this._server){let n=this.emit.bind(this,"connection");this._removeListeners=Es(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,s,o)=>{this.handleUpgrade(i,s,o,n)}})}t.perMessageDeflate===!0&&(t.perMessageDeflate={}),t.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=t,this._state=Zr}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(t){if(this._state===en){t&&this.once("close",()=>{t(new Error("The server is not running"))}),process.nextTick(ge,this);return}if(t&&this.once("close",t),this._state!==Xr)if(this._state=Xr,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(ge,this):process.nextTick(ge,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ge(this)})}}shouldHandle(t){if(this.options.path){let r=t.url.indexOf("?");if((r!==-1?t.url.slice(0,r):t.url)!==this.options.path)return!1}return!0}handleUpgrade(t,r,n,i){r.on("error",Qr);let s=t.headers["sec-websocket-key"],o=t.headers.upgrade,a=+t.headers["sec-websocket-version"];if(t.method!=="GET"){K(this,t,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){K(this,t,r,400,"Invalid Upgrade header");return}if(s===void 0||!bs.test(s)){K(this,t,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){K(this,t,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(t)){_e(r,400);return}let l=t.headers["sec-websocket-protocol"],c=new Set;if(l!==void 0)try{c=ms.parse(l)}catch{K(this,t,r,400,"Invalid Sec-WebSocket-Protocol header");return}let f=t.headers["sec-websocket-extensions"],d={};if(this.options.perMessageDeflate&&f!==void 0){let u=new J({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let h=Yr.parse(f);h[J.extensionName]&&(u.accept(h[J.extensionName]),d[J.extensionName]=u)}catch{K(this,t,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let u={origin:t.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(t.socket.authorized||t.socket.encrypted),req:t};if(this.options.verifyClient.length===2){this.options.verifyClient(u,(h,g,m,S)=>{if(!h)return _e(r,g||401,m,S);this.completeUpgrade(d,s,c,t,r,n,i)});return}if(!this.options.verifyClient(u))return _e(r,401)}this.completeUpgrade(d,s,c,t,r,n,i)}completeUpgrade(t,r,n,i,s,o,a){if(!s.readable||!s.writable)return s.destroy();if(s[Ss])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Zr)return _e(s,503);let c=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${ps("sha1").update(r+ys).digest("base64")}`],f=new this.options.WebSocket(null,void 0,this.options);if(n.size){let d=this.options.handleProtocols?this.options.handleProtocols(n,i):n.values().next().value;d&&(c.push(`Sec-WebSocket-Protocol: ${d}`),f._protocol=d)}if(t[J.extensionName]){let d=t[J.extensionName].params,u=Yr.format({[J.extensionName]:[d]});c.push(`Sec-WebSocket-Extensions: ${u}`),f._extensions=t}this.emit("headers",c,i),s.write(c.concat(`\r
|
|
3
3
|
`).join(`\r
|
|
4
|
-
`)),
|
|
5
|
-
`+Object.keys(
|
|
4
|
+
`)),s.removeListener("error",Qr),f.setSocket(s,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(f),f.on("close",()=>{this.clients.delete(f),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ge,this)})),a(f,i)}};tn.exports=Nt;function Es(e,t){for(let r of Object.keys(t))e.on(r,t[r]);return function(){for(let n of Object.keys(t))e.removeListener(n,t[n])}}function ge(e){e._state=en,e.emit("close")}function Qr(){this.destroy()}function _e(e,t,r,n){r=r||He.STATUS_CODES[t],n={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...n},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${He.STATUS_CODES[t]}\r
|
|
5
|
+
`+Object.keys(n).map(i=>`${i}: ${n[i]}`).join(`\r
|
|
6
6
|
`)+`\r
|
|
7
7
|
\r
|
|
8
|
-
`+r)}function
|
|
9
|
-
|
|
8
|
+
`+r)}function K(e,t,r,n,i,s){if(e.listenerCount("wsClientError")){let o=new Error(i);Error.captureStackTrace(o,K),e.emit("wsClientError",o,r,t)}else _e(r,n,i,s)}});function pn(){let e=(0,hn.homedir)();return{platform:process.platform,home:e,appData:process.env.APPDATA??(0,b.join)(e,"AppData","Roaming"),localAppData:process.env.LOCALAPPDATA??(0,b.join)(e,"AppData","Local")}}function dn(e,t){let r=t?"Code - Insiders":"Code";return e.platform==="win32"?(0,b.join)(e.appData,r,"User"):e.platform==="darwin"?(0,b.join)(e.home,"Library","Application Support",r,"User"):(0,b.join)(e.home,".config",r,"User")}function js(e){return e.platform==="win32"?(0,b.join)(e.appData,"Claude","claude_desktop_config.json"):e.platform==="darwin"?(0,b.join)(e.home,"Library","Application Support","Claude","claude_desktop_config.json"):(0,b.join)(e.home,".config","Claude","claude_desktop_config.json")}function mn(e){let t=e.trim().toLowerCase();return Se.find(r=>r.id===t||r.aliases.includes(t))}function Qe(e,t){return{url:`${e}/mcp`,headers:{Authorization:`Bearer ${t}`}}}function Lt(e,t){return{type:"http",...Qe(e,t)}}function Dt(e,t){return{command:"npx",args:["-y","mcp-remote",`${e}/mcp`,"--allow-http","--header",`Authorization:Bearer ${t}`]}}function gn(e,t,r){switch(e){case"copilot-http":return Lt(t,r);case"stdio-remote":return Dt(t,r);case"http":default:return Qe(t,r)}}function _n(e,t){return`url = ${JSON.stringify(`${e}/mcp`)}
|
|
9
|
+
http_headers = { "Authorization" = ${JSON.stringify(`Bearer ${t}`)} }`}function yn(e,t){return`mcp_servers:
|
|
10
|
+
babtab:
|
|
11
|
+
url: "${e}/mcp"
|
|
12
|
+
headers:
|
|
13
|
+
Authorization: "Bearer ${t}"`}function Sn(e,t){return`curl -s ${e}/mcp -H "Authorization: Bearer ${t}" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"browser_observe","arguments":{}}}'`}var hn,b,Se,bn=x(()=>{"use strict";hn=require("node:os"),b=require("node:path");Se=[{id:"cursor",label:"Cursor",aliases:[],paths:e=>[(0,b.join)(e.home,".cursor","mcp.json")],action:{kind:"json",rootKey:"mcpServers",entry:"http"},nextStep:"Cursor: Settings \u2192 MCP \u2192 enable babtab (or restart Cursor)."},{id:"claude-code",label:"Claude Code",aliases:["claudecode"],paths:()=>[],action:{kind:"exec",argv:(e,t)=>["claude","mcp","add","--transport","http","babtab",`${e}/mcp`,"--header",`Authorization: Bearer ${t}`]},nextStep:"Verify with: claude mcp list"},{id:"windsurf",label:"Windsurf",aliases:[],paths:e=>[(0,b.join)(e.home,".codeium","windsurf","mcp_config.json")],action:{kind:"json",rootKey:"mcpServers",entry:"http"},nextStep:"Restart Windsurf (or reload MCP servers) to pick up babtab."},{id:"copilot",label:"Copilot (VS Code)",aliases:["vscode","code"],paths:e=>[(0,b.join)(dn(e,!1),"mcp.json")],action:{kind:"json",rootKey:"servers",entry:"copilot-http"},nextStep:"VS Code: reload window, then check MCP Servers view for babtab."},{id:"copilot-insiders",label:"Copilot (VS Code Insiders)",aliases:["vscode-insiders","code-insiders","insiders"],paths:e=>[(0,b.join)(dn(e,!0),"mcp.json")],action:{kind:"json",rootKey:"servers",entry:"copilot-http"},nextStep:"VS Code Insiders: reload window, then check MCP Servers view for babtab."},{id:"codex",label:"Codex",aliases:[],paths:e=>[(0,b.join)(e.home,".codex","config.toml")],action:{kind:"toml-codex"},nextStep:"Restart Codex to load the babtab server."},{id:"pi",label:"Pi",aliases:[],paths:()=>[],action:{kind:"print",what:"curl"},nextStep:"Pi has no native MCP \u2014 use the curl line above to verify (Pi bridge addon in progress)."},{id:"claude-desktop",label:"Claude Desktop",aliases:["claude","claude_desktop"],paths:e=>[js(e)],action:{kind:"json",rootKey:"mcpServers",entry:"stdio-remote"},nextStep:"Restart Claude Desktop to load babtab (via mcp-remote bridge)."},{id:"antigravity",label:"Antigravity",aliases:[],paths:e=>[(0,b.join)(e.home,".gemini","antigravity","mcp_config.json"),(0,b.join)(e.home,".gemini","config","mcp_config.json")],action:{kind:"json",rootKey:"mcpServers",entry:"stdio-remote"},nextStep:"Restart Antigravity (or Agent panel \u22EF \u2192 Manage MCP Servers \u2192 reload)."},{id:"devin",label:"Devin CLI",aliases:["devin-desktop","devin_desktop"],paths:e=>e.platform==="win32"?[(0,b.join)(e.appData,"devin","mcp_config.json")]:[(0,b.join)(e.home,".config","devin","mcp_config.json")],action:{kind:"json",rootKey:"mcpServers",entry:"http"},nextStep:"Restart Devin to load the babtab server."},{id:"kimi",label:"Kimi",aliases:["kimi-code","kimi-work","kimi_code"],paths:e=>[(0,b.join)(e.home,".kimi-code","mcp.json")],action:{kind:"json",rootKey:"mcpServers",entry:"http"},nextStep:"Restart Kimi to load the babtab server."},{id:"hermes",label:"Hermes",aliases:["hermes-desktop","hermes_desktop"],paths:e=>e.platform==="win32"?[(0,b.join)(e.home,".hermes","config.yaml"),(0,b.join)(e.localAppData,"hermes","config.yaml")]:[(0,b.join)(e.home,".hermes","config.yaml")],action:{kind:"yaml-hermes"},nextStep:"Restart Hermes to load the babtab server."},{id:"manual",label:"Manual / Other",aliases:["other","generic"],paths:()=>[],action:{kind:"print",what:"manual"},nextStep:"Paste the endpoint + header into your harness MCP settings."}]});function Fs(e,t){let r=e.slice(0,t).split(/\r?\n/);return[r.length,r.pop().length+1]}function Ws(e,t,r){let n=e.split(/\r?\n/),i="",s=(Math.log10(t+1)|0)+1;for(let o=t-1;o<=t+1;o++){let a=n[o-1];a&&(i+=o.toString().padEnd(s," "),i+=": ",i+=a,i+=`
|
|
14
|
+
`,o===t&&(i+=" ".repeat(s+r+2),i+=`^
|
|
15
|
+
`))}return i}var p,Y=x(()=>{p=class e extends Error{line;column;codeblock;constructor(t,r){let[n,i]=Fs(r.toml,r.ptr),s=Ws(r.toml,n,i);super(`Invalid TOML document: ${t}
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
${s}`,r),this.line=n,this.column=i,this.codeblock=s}static x(t,r,n){throw new e(t,{toml:r.s,ptr:n??r.p})}}});function et(e){let t=e.p,r=e.s.charCodeAt(e.p++),n=r,i=r===39,s=r===e.s.charCodeAt(e.p)&&r===e.s.charCodeAt(e.p+1);s&&((r=e.s.charCodeAt(e.p+=2))===10?e.p++:r===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let o="",a=e.p,l=0;for(;e.p<e.s.length;e.p++)if(r=e.s.charCodeAt(e.p),s&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10))l=l&&3;else if(r<32&&r!==9||r===127)p.x("control characters are not allowed in strings",e);else if((!l||l===3)&&r===n&&(!s||e.s.charCodeAt(e.p+1)===n&&e.s.charCodeAt(e.p+2)===n)){if(s&&(e.s.charCodeAt(e.p+3)===n&&e.p++,e.s.charCodeAt(e.p+3)===n&&e.p++),!l){let c=e.s.slice(a,e.p);o=o?o+c:c}return e.p+=s?3:1,o}else if(!l)!i&&r===92&&(o+=e.s.slice(a,a=e.p),l=1);else if(l===1)if(r===120||r===117||r===85){let c=e.p++-1,f=0,d=r===120?2:r===117?4:8;for(let u=0;u<d;u++,e.p++){let h=e.s.charCodeAt(e.p),g=h>=48&&h<=57?h-48:h>=65&&h<=70?h-65+10:h>=97&&h<=102?h-97+10:-1;g<0&&p.x("invalid non-hex character in unicode escape",e),f=f<<4|g}(f<0||f>1114111||f>=55296&&f<=57343)&&p.x("invalid unicode escape",e,c),o+=String.fromCodePoint(f),a=e.p--,l=0}else s&&(r===32||r===9)?l=2:(r===98?o+="\b":r===116?o+=" ":r===110?o+=`
|
|
18
|
+
`:r===102?o+="\f":r===114?o+="\r":r===101?o+="\x1B":r===34?o+='"':r===92?o+="\\":p.x("unrecognised escape sequence",e),a=e.p+1,l=0);else r!==32&&r!==9&&(l===2&&p.x("invalid escape: only line-ending whitespace may be escaped",e,a),l=!i&&r===92?1:0,a=e.p);p.x("unfinished string",e,t)}var Rt=x(()=>{Y();});var qs,be,Mt=x(()=>{qs=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,be=class e extends Date{#t=!1;#r=!1;#e=null;constructor(t,r,n){let i=!0,s=!0,o="Z",a;if(typeof t=="string")if(r)e:{if(r<3){if(+t.slice(11,13)>23){t="";break e}r===2?(o=null,t+="Z"):(a=t.charCodeAt(t.length-1))!==90&&a!==122&&(o=t.slice(t.length-6)),n&&(t=t.slice(0,10)+"T"+t.slice(11))}else r===4&&(t=+t.slice(0,2)>23?"":`0000-01-01T${t}Z`);i=r!==4,s=r!==3}else{let l=t.match(qs);l?(l[1]||(i=!1,t=`0000-01-01T${t}`),s=!!l[2],s&&t[10]===" "&&(t=t.replace(" ","T")),l[2]&&+l[2]>23?t="":(o=l[3]||null,!o&&s&&(t+="Z"))):t=""}super(t),isNaN(this.getTime())||(this.#t=i,this.#r=s,this.#e=o)}isDateTime(){return this.#t&&this.#r}isLocal(){return!this.#t||!this.#r||!this.#e}isDate(){return this.#t&&!this.#r}isTime(){return this.#r&&!this.#t}isValid(){return this.#t||this.#r}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#e===null)return t.slice(0,-1);if(this.#e==="Z"||this.#e==="z")return t;let r=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return r=this.#e[0]==="-"?r:-r,new Date(this.getTime()-r*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(t,r="Z"){let n=new e(t);return n.#e=r,n}static wrapAsLocalDateTime(t){let r=new e(t);return r.#e=null,r}static wrapAsLocalDate(t){let r=new e(t);return r.#r=!1,r.#e=null,r}static wrapAsLocalTime(t){let r=new e(t);return r.#t=!1,r.#e=null,r}}});function k(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function Bt(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function ve(e,t){let r=e.p,n=e.s.charCodeAt(e.p);if(n===91||n===123){e.d--||p.x("document contains excessively nested structures. aborting.",e);let i=n===91?xn(e):vn(e);return e.d++,i}return n===34||n===39?et(e):n===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&p.x("invalid value",e,r),e.p++,!0):n===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&p.x("invalid value",e,r),e.p++,!1):n===43||n===45?tt(e,e.p,e.s.charCodeAt(++e.p),44-n,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?Vs(e,n,t):e.s.charCodeAt(e.p+2)===58?Gs(e,n,t):tt(e,e.p,n,0,t)}function tt(e,t,r,n,i){let s=r,o=0,a=!1;if(s===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&p.x("invalid value",e,t),e.p++,(n||1)/0;if(s===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&p.x("invalid value",e,t),e.p++,NaN;if(s===48){if(++e.p>=e.s.length||Bt(s=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!n){if(s===120)return $t(e,t,16,i);if(s===98)return $t(e,t,2,i);if(s===111)return $t(e,t,8,i)}s===46?o=2:s===101||s===69?o=4:p.x("illegal leading zero",e,t)}else k(s)||p.x("invalid value",e,t);for(;++e.p<e.s.length&&(s=e.s.charCodeAt(e.p),!Bt(s,i));)o||(o=1),s===95?(o&1||p.x("illegal underscore",e),o+=11,a=!0):o===1&&s===46?o=2:(o===1||o===3)&&(s===101||s===69)?o=4:o===4&&(s===43||s===45)||(k(s)?o>9?o-=11:o&1||o++:p.x("illegal character in numeric literal",e));if(!o){let c=(r-48)*(n||1);return e.bi===!0?BigInt(c):c}o&1||p.x("unfinished numeric value",e,t);let l=e.s.slice(t,e.p);return a&&(l=l.replaceAll("_","")),o>1?parseFloat(l):En(e,l,10,t)}function $t(e,t,r,n){let i,s=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!Bt(i,n));)i===95?(s&1&&p.x("illegal underscore",e),s=3):k(i,r)?s&1&&s--:p.x("illegal character in numeric literal",e);s&1&&p.x("unfinished numeric value",e);let o=e.s.slice(t+2,e.p);return s&&(o=o.replaceAll("_","")),En(e,o,r,t)}function En(e,t,r,n){if(e.bi!==!0)e:{let i=parseInt(t,r);if(!Number.isSafeInteger(i)){if(e.bi)break e;p.x("integer value cannot be represented losslessly",e,n)}return i}return BigInt(r===10?t:(r===2?"0b":r===8?"0o":"0x")+t)}function Vs(e,t,r){let n=e.p++,i;if(!k(t)||!k(e.s.charCodeAt(e.p++))||!k(e.s.charCodeAt(e.p++))||!k(e.s.charCodeAt(e.p++)))return tt(e,e.p=n,t,0,r);if(e.p+=5,k(e.s.charCodeAt(e.p++))||p.x("invalid date-time: date part is malformed",e,n),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(i=!0,!k(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let o=e.s.slice(n,e.p);return Ee(e,o,3,!1,n)}if(e.s.charCodeAt(e.p+=3)!==58&&p.x("invalid date-time: time part is malformed",e,n),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;k(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122){let o=e.s.slice(n,++e.p);return Ee(e,o,1,i,n,"[+00:00]")}if(t===43||t===45){let o=e.s.slice(n,e.p+=6);return Ee(e,o,1,i,n,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let s=e.s.slice(n,e.p);return Ee(e,s,2,i,n)}function Gs(e,t,r){let n=e.p;if(!k(t)||!k(e.s.charCodeAt(++e.p)))return tt(e,--e.p,t,0,r);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;k(e.s.charCodeAt(++e.p)););let i=e.s.slice(n,e.p);return Ee(e,i,4,!1,n)}function Ee(e,t,r,n,i,s){if(e.ld){let o=new be(t,r,n);return o.isValid()||p.x("invalid date",e,i),o}try{switch(s&&(t+=s),r){case 1:return Temporal.ZonedDateTime.from(t);case 2:return Temporal.PlainDateTime.from(t);case 3:return Temporal.PlainDate.from(t);case 4:return Temporal.PlainTime.from(t)}}catch(o){p.x(o instanceof Error?o.message:""+o,e,i)}}var Ut=x(()=>{Rt();jt();Y();Mt();});function Hs(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&p.x("control characters are not allowed in comments",e)}}function I(e,t,r){let n;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((n=e.s.charCodeAt(e.p))===32||n===9||!t&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(r||n!==35)break;Hs(e)}}var Ft=x(()=>{Y();});function rt(e,t=61){let r,n=0,i=[],s,o=e.s.charCodeAt(r=e.p);do{if(o===t)return n||p.x("unexpected end of key",e),n===1&&i.push(e.s.slice(s,e.p)),e.p++,i;o===46?(n||p.x("illegal empty bare key",e),n===1&&i.push(e.s.slice(s,e.p)),n=0):!n&&(o===34||o===39)?(o===e.s.charCodeAt(e.p+1)&&o===e.s.charCodeAt(e.p+2)&&p.x("illegal quoted key: multiline strings are not allowed",e),i.push(et(e)),n=2,e.p--):o===32||o===9?n===1&&(i.push(e.s.slice(s,e.p)),n=2):n===2||o<48&&o!==45||o>57&&o<65||o>90&&o<97&&o!==95||o>122?p.x("illegal character in key",e):n||(n=1,s=e.p)}while(o=e.s.charCodeAt(++e.p));p.x("incomplete key-value: cannot find end of key",e,r)}function vn(e){let t=e.p++,r=Object.create(null),n=new Set,i;for(;e.p<e.s.length;){if(I(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,r;let s,o=r,a=!1,l=e.p,c=rt(e);for(let d=0;d<c.length;d++){d&&(o=a?o[s]:o[s]=Object.create(null)),s=c[d],(a=Object.hasOwn(o,s))&&(typeof o[s]!="object"||n.has(o[s]))&&p.x("trying to redefine an already defined value",e,l);let u=s==="__proto__";if(e.uk&&(u||s==="constructor")){o=e.uk!==1&&p.x("document contains an unsafe property",e,l);break}!a&&u&&Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}a&&p.x("trying to redefine an already defined value",e,l),I(e,!0,!0);let f=ve(e,125);if(o&&typeof(o[s]=f)=="object"&&n.add(f),I(e),(i=e.s.charCodeAt(e.p++))===125)return r;i!==44&&p.x("expected comma or end of structure",e,e.p-1)}p.x("unfinished table",e,t)}function xn(e){let t=e.p++,r=[],n;for(;e.p<e.s.length;){if(I(e),(n=e.s.charCodeAt(e.p))===93)return e.p++,r;if(r.push(ve(e,93)),I(e),(n=e.s.charCodeAt(e.p++))===93)return r;n!==44&&p.x("expected comma or end of structure",e,e.p-1)}p.x("unfinished array",e,t)}var jt=x(()=>{Rt();Ut();Ft();Y();});function wn(e,t,r,n,i){let s=r,o=n,a,l=!1,c;for(let f=0;f<t.length;f++){if(f){if(s=l?s[a]:s[a]=Object.create(null),o=(c=o[a]).c,i===0&&(c.t===1||c.t===2))return null;if(c.t===2){let d=s.length-1;s=s[d],o=o[d].c}}if(a=t[f],(l=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!l){let d=a==="__proto__";if(e.uk&&(d||a==="constructor"))return!1;d&&(Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0})),o[a]={t:f<t.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(c=o[a],c.t!==i&&!(i===1&&c.t===3)||(i===2&&(c.d||(c.d=!0,s[a]=[]),s[a].push(s=Object.create(null)),c.c[c.i++]=c={t:1,d:!1,i:0,c:Object.create(null)}),c.d))return null;if(c.d=!0,i===1)s=l?s[a]:s[a]=Object.create(null);else if(i===0&&l)return null;return[a,s,c.c]}function Tn(e,t,r){(t===null||e.uk===2)&&p.x(t===null?"trying to redefine an already defined table or value":"document contains an unsafe property",e,r)}function xe(e,t={}){let r={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour==="throw"?2:t.unsafeKeyBehaviour==="drop"?1:0},n=Object.create(null),i=Object.create(null),s,o=!1,a=n,l=i;for(e.charCodeAt(0)===65279&&r.p++,I(r);r.p<e.length;){if(e.charCodeAt(r.p)===91){let c=e.charCodeAt(++r.p)===91;s=r.p+=+c,o=!1;let f=rt(r,93);c&&(e.charCodeAt(r.p)!==93&&p.x("expected end of table array declaration",r),r.p++);let d=wn(r,f,n,i,c?2:1);d?(l=d[2],a=d[1]):(Tn(r,d,s),o=!0)}else{s=r.p;let c=rt(r),f=wn(r,c,a,l,0);!f&&!o&&Tn(r,f,s),I(r,!0,!0);let d=ve(r,void 0);f&&!o&&(f[1][f[0]]=d)}I(r,!0),r.p<e.length&&(s=e.charCodeAt(r.p))!==10&&(s!==13||e.charCodeAt(r.p+1)!==10)&&p.x("each key-value declaration must be followed by an end-of-line",r),I(r)}return n}var kn=x(()=>{jt();Ut();Ft();Y();});function we(e){let t=typeof e;if(t==="object"){if(Array.isArray(e))return"array";if(typeof e.getUTCDate=="function"&&e instanceof Date)return"date";if(globalThis.Temporal){if(e.until){if(e instanceof Temporal.ZonedDateTime)return"temporal/tz+uc";if(e instanceof Temporal.PlainDateTime||e instanceof Temporal.PlainDate)return"temporal/uc";if(e instanceof Temporal.PlainTime||e instanceof Temporal.Instant)return"temporal";if(e instanceof Temporal.PlainYearMonth)return"temporal/x"}else if(e.toPlainDate&&e instanceof Temporal.PlainMonthDay||e.negated&&e instanceof Temporal.Duration)return"temporal/x"}}return t}function Js(e){for(let t=0;t<e.length;t++)if(we(e[t])!=="object")return!1;return e.length!=0}function On(e){return JSON.stringify(e).replaceAll("\x7F","\\u007f")}function Ks(e){return On(Cn?e.toWellFormed():e)}function An(e){if(zs.test(e))return e;if(Cn&&!e.isWellFormed())throw new RangeError("key contains illegal lone surrogates");return On(e)}function Wt(e,t,r,n,i){if(r===0)throw new Error("Could not stringify the object: maximum object depth exceeded");switch(t){case"number":if(isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Number.isInteger(e)&&(n||!Number.isSafeInteger(e)))return e.toFixed(1);case"bigint":case"boolean":case"temporal":return e.toString();case"string":return Ks(e);case"date":if(isNaN(e.getTime()))throw new TypeError("cannot serialize invalid date");return e.toISOString();case"object":return Ys(e,r,n,i);case"array":return Zs(e,r,n,i);case"temporal/tz+uc":if(i){let s=e.timeZoneId,o=s.charCodeAt(0);if(o!==43&&o!==45&&(o!==85&&o!==71&&o!==90&&o!==69||s!=="UTC"&&s!=="UCT"&&s!=="Universal"&&s!=="Zulu"&&!s.startsWith("GMT")&&s!=="Greenwich"&&!s.startsWith("Etc/")))throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode")}case"temporal/uc":if(i&&e.calendarId!=="iso8601")throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");return e.toString({calendarName:"never",timeZoneName:"never"});case"temporal/x":throw new TypeError("Unsupported "+e[Symbol.toStringTag])}}function Ys(e,t,r,n){let i=Object.keys(e);if(i.length===0)return"{}";let s="{ ";for(let o=0;o<i.length;o++){let a=i[o];o&&(s+=", "),s+=An(a)+" = "+Wt(e[a],we(e[a]),t-1,r,n)}return s+" }"}function Zs(e,t,r,n){if(e.length===0)return"[]";let i="[ ";for(let s=0;s<e.length;s++){if(s&&(i+=", "),e[s]===null||e[s]===void 0)throw new TypeError("arrays cannot contain null or undefined values");i+=Wt(e[s],we(e[s]),t-1,r,n)}return i+" ]"}function Xs(e,t,r,n,i){if(r===0)throw new Error("Could not stringify the object: maximum object depth exceeded");let s="";for(let o=0;o<e.length;o++)s+=`${s&&`
|
|
19
|
+
`}[[${t}]]
|
|
20
|
+
`,s+=qt(0,e[o],t,r,n,i);return s}function qt(e,t,r,n,i,s){if(n===0)throw new Error("Could not stringify the object: maximum object depth exceeded");let o="",a="",l=Object.keys(t);for(let c=0;c<l.length;c++){let f=l[c];if(t[f]!==null&&t[f]!==void 0){let d=we(t[f]);if(d==="symbol"||d==="function")throw new TypeError(`cannot serialize values of type '${d}'`);let u=An(f);if(d==="array"&&Js(t[f]))a+=(a&&`
|
|
21
|
+
`)+Xs(t[f],r?`${r}.${u}`:u,n-1,i,s);else if(d==="object"){let h=r?`${r}.${u}`:u;a+=(a&&`
|
|
22
|
+
`)+qt(h,t[f],h,n-1,i,s)}else o+=u,o+=" = ",o+=Wt(t[f],d,n,i,s),o+=`
|
|
23
|
+
`}}return e&&(o||!a)&&(o=o?`[${e}]
|
|
24
|
+
${o}`:`[${e}]`),o&&a?`${o}
|
|
25
|
+
${a}`:o||a}function Vt(e,{maxDepth:t=1e3,numbersAsFloat:r=!1,strictTemporal:n=!1}={}){if(we(e)!=="object")throw new TypeError("stringify can only be called with an object");let i=qt(0,e,"",t,r,n);return i[i.length-1]!==`
|
|
26
|
+
`?i+`
|
|
27
|
+
`:i}var zs,Cn,Nn=x(()=>{zs=/^[a-z0-9-_]+$/i,Cn=!!"".isWellFormed});var Pn=x(()=>{kn();Nn();Mt();Y();});function Ln(e,t){let r=e.paths(t);if(r.length===0)return null;for(let n of r)try{if((0,_.statSync)((0,Te.dirname)(n)).isDirectory())return n}catch{}return r[0]}function Qs(e){let t="",r=0,n=!1,i=!1;for(;r<e.length;){let s=e[r],o=e[r+1];if(n){t+=s,i?i=!1:s==="\\"?i=!0:s==='"'&&(n=!1),r++;continue}if(s==='"'){n=!0,t+=s,r++;continue}if(s==="/"&&o==="/"){for(;r<e.length&&e[r]!==`
|
|
28
|
+
`;)r++;continue}if(s==="/"&&o==="*"){for(r+=2;r<e.length&&!(e[r]==="*"&&e[r+1]==="/");)e[r]===`
|
|
29
|
+
`&&(t+=`
|
|
30
|
+
`),r++;r+=2;continue}t+=s,r++}return t}function nt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ke(e){try{return(0,_.existsSync)(e)?((0,_.writeFileSync)(`${e}.bak`,(0,_.readFileSync)(e)),!0):!1}catch{return!1}}function Dn(e){let{path:t,rootKey:r,serverName:n,entry:i}=e,s=(0,_.existsSync)(t),o={};if(s){let c=(0,_.readFileSync)(t,"utf8"),f;try{f=JSON.parse(c.trim()===""?"{}":Qs(c))}catch{throw new Error(`Existing config is not valid JSON: ${t}
|
|
31
|
+
Fix or rename it first (setup left it untouched).`)}if(!nt(f))throw new Error(`Existing config root must be an object: ${t} (left untouched).`);o=f;let d=o[r];if(d!==void 0&&!nt(d))throw new Error(`Existing "${r}" is not an object: ${t} (left untouched).`)}let a=nt(o[r])?o[r]:{};a[n]=i,o[r]=a,(0,_.mkdirSync)((0,Te.dirname)(t),{recursive:!0});let l=s?ke(t):!1;return(0,_.writeFileSync)(t,`${JSON.stringify(o,null,2)}
|
|
32
|
+
`,{mode:384}),{path:t,created:!s,backedUp:l}}function Rn(e,t){let r=(0,_.existsSync)(e),n=r?xe((0,_.readFileSync)(e,"utf8")):{},i=xe(`${eo}
|
|
33
|
+
${t}
|
|
34
|
+
`);if(n.mcp_servers!==void 0&&!nt(n.mcp_servers))throw new Error("Existing mcp_servers must be a table (left untouched)");let s=n.mcp_servers??{};s.babtab=i.mcp_servers.babtab,n.mcp_servers=s;let o=Vt(n);xe(o),(0,_.mkdirSync)((0,Te.dirname)(e),{recursive:!0});let a=r?ke(e):!1;if(r&&!a)throw new Error(`Cannot back up ${e}; left untouched`);let l=`${e}.${(0,In.randomUUID)()}.tmp`;try{(0,_.writeFileSync)(l,o,{mode:384,flag:"wx"}),(0,_.renameSync)(l,e)}finally{(0,_.rmSync)(l,{force:!0})}return{path:e,created:!r,backedUp:a}}function Mn(e,t){let r=(0,_.existsSync)(e),n;if(!r)n=`${t}
|
|
35
|
+
`;else{let s=(0,_.readFileSync)(e,"utf8").split(`
|
|
36
|
+
`),o=s.findIndex(a=>/^mcp_servers\s*:\s*(#.*)?$/.test(a));if(o===-1){let a=s.length>0&&s[s.length-1].trim()!==""?`
|
|
37
|
+
`:"";n=`${s.join(`
|
|
38
|
+
`)}${a}
|
|
39
|
+
${t}
|
|
40
|
+
`}else{let a=o+1;for(;a<s.length&&(s[a].trim()===""||/^\s+/.test(s[a]));)a++;let l=s.slice(o+1,a),c=l.findIndex(u=>/^\s*babtab\s*:\s*(#.*)?$/.test(u)),f=t.split(`
|
|
41
|
+
`).slice(1).join(`
|
|
42
|
+
`),d;if(c===-1)d=[...l,f];else{let u=l[c].match(/^\s*/)?.[0].length??2,h=c+1;for(;h<l.length&&(l[h].trim()===""||(l[h].match(/^\s*/)?.[0].length??0)>u);)h++;d=[...l.slice(0,c),f,...l.slice(h)]}n=[...s.slice(0,o+1),...d,...s.slice(a)].join(`
|
|
43
|
+
`),n.endsWith(`
|
|
44
|
+
`)||(n+=`
|
|
45
|
+
`)}}(0,_.mkdirSync)((0,Te.dirname)(e),{recursive:!0});let i=r?ke(e):!1;return(0,_.writeFileSync)(e,n,{mode:384}),{path:e,created:!r,backedUp:i}}var In,_,Te,eo,$n=x(()=>{"use strict";Pn();In=require("node:crypto"),_=require("node:fs"),Te=require("node:path");eo="[mcp_servers.babtab]"});async function Bn(e,t,r){let n;try{n=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t),signal:AbortSignal.timeout(r)})}catch(s){throw new Z(`Cannot reach relay at ${e}: ${String(s)}`)}let i={};try{i=await n.json()}catch{}return{status:n.status,json:i}}async function Gt(e){let t;try{t=await fetch(`${e}/health`,{signal:AbortSignal.timeout(3e3)})}catch(n){throw new Z(`Cannot reach relay at ${e}/health: ${String(n)}`)}if(!t.ok)throw new Z(`Relay health check failed: HTTP ${t.status}`);let r=await t.json();return{ok:r.ok===!0,devices:typeof r.devices=="number"?r.devices:0}}async function Un(e,t,r){let{status:n,json:i}=await Bn(`${e}/pairing/request`,{deviceId:t,clientName:r,scopes:["browser:read","browser:act"]},3e3);if(n===429)throw new Ce(String(i.error??"rate limited, wait and retry"));if(n!==200||typeof i.code!="string")throw new Error(`Pairing request failed: HTTP ${n} ${String(i.error??"")}`.trim());return{code:i.code,expiresAt:typeof i.expiresAt=="number"?i.expiresAt:0,deviceOnline:i.deviceOnline===!0}}async function jn(e,t,r={}){let n=r.intervalMs??2e3,i=r.timeoutMs??3e5,s=Date.now()+i;for(;;){let{json:o}=await Bn(`${e}/pairing/claim`,{code:t},3e3),a=String(o.status??"");if(a==="approved"&&typeof o.token=="string")return o.token;if(a==="expired")throw new Oe("Pairing code expired \u2014 run the setup command again.");if(Date.now()>=s)throw new Ae("Timed out waiting for approval \u2014 run the setup command again.");await new Promise(l=>setTimeout(l,n))}}var Z,Ce,Oe,Ae,Fn=x(()=>{"use strict";Z=class extends Error{},Ce=class extends Error{},Oe=class extends Error{},Ae=class extends Error{}});var zt={};Zt(zt,{DEFAULT_PORT:()=>Ne,SERVER_NAME:()=>qn,VERIFY_SENTENCE:()=>it,backupFile:()=>ke,copilotJsonEntry:()=>Lt,httpJsonEntry:()=>Qe,listTargetCommands:()=>Gn,parseSetupArgs:()=>Vn,runSetup:()=>ro,setupHelp:()=>Ht,stdioRemoteJsonEntry:()=>Dt});function Vn(e){let t={target:"",port:Number(process.env.PORT??Ne),relayUrl:null,deviceId:null,help:!1,listTargets:!1},r=(n,i)=>{let s=e[n];if(s===void 0||s==="")throw new Error(`Missing value for ${i}`);return s};for(let n=0;n<e.length;n++){let i=e[n],[s,o]=i.includes("=")?i.split("=",2):[i,void 0],a=l=>o??r(++n,l);switch(s){case"--target":case"-t":t.target=a("--target");break;case"--port":case"-p":{let l=Number(a("--port"));if(!Number.isInteger(l)||l<1||l>65535)throw new Error("Invalid --port: expected 1-65535");t.port=l;break}case"--device":case"-d":t.deviceId=a("--device");break;case"--relay-url":t.relayUrl=a("--relay-url").replace(/\/+$/,"");break;case"--list-targets":case"--list":t.listTargets=!0;break;case"--help":case"-h":t.help=!0;break;default:throw new Error(`Unknown option: ${i} (see --help)`)}}if(!Number.isInteger(t.port)||t.port<1||t.port>65535)throw new Error(`Invalid PORT: expected 1-65535 (got ${process.env.PORT})`);return t}function to(e){let t=e.action.kind==="print"?"":" --device <deviceId>";return`npx -y @babtab/relay setup --target ${e.id} --port ${Ne}${t}`}function Ht(){return["babtab setup \u2014 pair + write your harness MCP config in one step","","Usage:"," npx -y @babtab/relay setup --target <id> --port <port> --device <deviceId>"," (Copy the exact line from the Babtab Side Panel \u2192 Step 2; it has your port + device.)","","Targets:",Se.map(t=>` ${t.id.padEnd(17)} ${t.label}`).join(`
|
|
46
|
+
`),"","Options:"," --target, -t <id> Harness to configure (required, see list above)",` --port, -p <n> Relay port (default ${Ne}, or $PORT)`," --device, -d <id> Extension device id (from Side Panel Step 2)"," --relay-url <url> Override http base for a remote relay (VPS), e.g. https://relay.example.com:3000"," --list-targets Print one ready-to-paste command per target and exit"," --help, -h Show this help","","Flow:"," 1. Make sure the relay is running: npx -y @babtab/relay"," 2. Finish Side Panel Step 1 (Save & Connect) so your Chrome is online."," 3. Run the Step 2 command, approve the 6-digit code in the Side Panel.",` 4. Reload MCP in your harness, then ask: "${it}".`,""].join(`
|
|
47
|
+
`)}function Gn(){return Se.map(e=>`# ${e.label}
|
|
48
|
+
${to(e)}`).join(`
|
|
49
|
+
|
|
50
|
+
`)+`
|
|
51
|
+
`}function Hn(e){return e===Ne?"npx -y @babtab/relay":`PORT=${e} npx -y @babtab/relay`}async function ro(e){let t;try{t=Vn(e)}catch(o){return console.error(`Error: ${o.message}
|
|
52
|
+
`),console.error(Ht()),1}if(t.help)return console.log(Ht()),0;if(t.listTargets)return console.log(Gn()),0;let r=mn(t.target);if(!r)return console.error(`Error: unknown --target "${t.target}". Pick one of:
|
|
53
|
+
`),console.error(Se.map(o=>` ${o.id}`).join(`
|
|
54
|
+
`)),1;let n=t.relayUrl??`http://127.0.0.1:${t.port}`;if(r.action.kind==="print")return no(r,n,t);if(!t.deviceId)return console.error(`Error: --device is required.
|
|
55
|
+
Copy the full command from the Babtab Side Panel \u2192 Step 2 (it includes --device).`),1;try{await Gt(n)}catch(o){if(o instanceof Z)return console.error(`Error: relay is not reachable at ${n}.
|
|
56
|
+
Start it first in another terminal:
|
|
57
|
+
|
|
58
|
+
${Hn(t.port)}
|
|
59
|
+
`),2;throw o}let i;try{let o=await Un(n,t.deviceId,r.id);if(!o.deviceOnline)return console.error(`Error: your Chrome is not connected to the relay.
|
|
60
|
+
Finish Side Panel Step 1 (Save & Connect) first, then re-run this command.`),3;i=o.code}catch(o){return o instanceof Ce?(console.error(`Error: ${o.message}. Wait a few seconds and re-run.`),3):(console.error(`Error: pairing request failed: ${o.message}`),3)}console.log(""),console.log(`Pairing code: ${i}`),console.log("Approve it in the Babtab Side Panel (a pairing banner appears at the top)."),console.log("Waiting for approval\u2026");let s;try{s=await jn(n,i)}catch(o){return o instanceof Oe||o instanceof Ae?(console.error(`Error: ${o.message}`),3):(console.error(`Error: claim failed: ${o.message}`),3)}console.log("Approved \u2713");try{return io(r,n,s)}catch(o){return console.error(`Error: ${o.message}`),4}}async function no(e,t,r){if(e.action.kind!=="print")return 1;try{await Gt(t)}catch{console.log(`Note: relay is not reachable at ${t} yet \u2014 start it with:
|
|
61
|
+
|
|
62
|
+
${Hn(r.port)}
|
|
63
|
+
`)}return e.action.what==="curl"?(console.log("Pi has no native MCP support. You need a token first:"),console.log(" 1. In the Side Panel, use Step 2 \u2192 Manual to pair and copy a token."),console.log(` 2. Verify the relay with (replace <token>):
|
|
64
|
+
`),console.log(` ${Sn(t,"<token>")}
|
|
65
|
+
`)):(console.log("Standard MCP (Streamable HTTP):"),console.log(` Endpoint: ${t}/mcp`),console.log(` Header: Authorization: Bearer <token>
|
|
66
|
+
`),console.log("Get a token: Side Panel \u2192 Step 2 \u2192 Manual \u2192 Copy config (pairing runs automatically)."),console.log("Flow: initialize \u2192 tools/list \u2192 tools/call (JSON-RPC 2.0).")),0}function io(e,t,r){let n=e.action;if(n.kind==="exec"){let l=n.argv(t,r),c=(0,Wn.spawnSync)(l[0],l.slice(1),{stdio:"inherit",shell:process.platform==="win32"});if(c.error){let f=c.error.code==="ENOENT";return console.error(f?`The "${l[0]}" CLI was not found. Install it, then run:
|
|
67
|
+
|
|
68
|
+
${l.join(" ")}
|
|
69
|
+
`:`Failed to run "${l[0]}": ${c.error.message}`),4}return c.status!==0?(console.error(`"${l[0]}" exited with code ${c.status}. Re-run the setup command to retry.`),4):(console.log(`
|
|
70
|
+
Configured ${e.label} \u2713`),console.log(e.nextStep),console.log(`Then ask: "${it}".`),0)}let i=pn(),s=Ln(e,i);if(!s)return console.error(`Error: no config path for target "${e.id}".`),4;let o,a;if(n.kind==="json"){let l=gn(n.entry,t,r);({created:o,backedUp:a}=Dn({path:s,rootKey:n.rootKey,serverName:qn,entry:l}))}else if(n.kind==="toml-codex")({created:o,backedUp:a}=Rn(s,_n(t,r)));else if(n.kind==="yaml-hermes")({created:o,backedUp:a}=Mn(s,yn(t,r)));else return console.error(`Error: unsupported action for target "${e.id}".`),4;return console.log(`
|
|
71
|
+
Wrote ${s} ${o?"(created)":"(updated, babtab entry replaced)"} \u2713`),a&&console.log(`Backup: ${s}.bak`),console.log(e.nextStep),console.log(`Then ask: "${it}".`),0}var Wn,Ne,qn,it,Jt=x(()=>{"use strict";Wn=require("node:child_process");bn();$n();Fn();Ne=3e3,qn="babtab",it="Use babtab to observe the current tab"});var Xe=require("node:crypto");function L(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function le(e){return new Promise((t,r)=>{let n=0,i=[],s=!1,o=(a,l)=>{s||(s=!0,i.length=0,r(Object.assign(new Error(l),{status:a})))};e.on("data",a=>{if(s)return;let l=Buffer.isBuffer(a)?a:Buffer.from(a);if(n+=l.length,n>256e3){o(413,"body too large");return}i.push(l)}),e.on("end",()=>{if(!s)try{let a=JSON.parse(Buffer.concat(i).toString("utf8")||"{}");if(!L(a)){o(400,"JSON body must be an object");return}s=!0,t(a)}catch{o(400,"Invalid JSON")}}),e.on("error",()=>o(400,"Request interrupted")),e.on("close",()=>{s||o(400,"Request interrupted")})})}var V={type:"object",description:"Semantic target: durable ref (@Hxxxx) or role/name/region query.",properties:{ref:{type:"string"},role:{type:"string"},name:{type:"string"},nameContains:{type:"string"},label:{type:"string"},region:{type:"string"}}},ei={type:"object",description:"Postcondition to verify after dispatch (url_changed, url_matches, element_appeared, element_disappeared, value_equals, value_changed, navigation_completed, etc.).",properties:{type:{type:"string",enum:["url_changed","url_matches","element_appeared","element_disappeared","value_equals","value_changed","checked","selection_changed","title_changed","navigation_completed","region_changed"]},value:{type:"string"},query:V,regionId:{type:"string"}},required:["type"],additionalProperties:!0},lt={type:"array",description:"Postconditions to verify after dispatch.",items:ei},ti={type:"object",description:"Single guarded action contract.",properties:{action:{type:"string",enum:["click","fill","select","press","scroll","navigate","back","forward","hover"]},target:V,value:{type:"string"},key:{type:"string"},url:{type:"string"},expect:lt,timeoutMs:{type:"number"}},required:["action"],additionalProperties:!0},ct=[{name:"browser_observe",description:"Compact page/region digest of the controlled tab.",inputSchema:{type:"object",properties:{level:{type:"string"},regionId:{type:"string"},includeRecentDiff:{type:"boolean"}}},scope:"browser:read"},{name:"browser_find",description:"Fast semantic lookup returning durable refs.",inputSchema:{type:"object",properties:{role:{type:"string"},name:{type:"string"},nameContains:{type:"string"},region:{type:"string"}}},scope:"browser:read"},{name:"browser_click",description:"Click a semantic target (guarded, verified).",inputSchema:{type:"object",properties:{target:V,expect:lt},required:["target"]},scope:"browser:act"},{name:"browser_fill",description:"Fill a field and verify the value.",inputSchema:{type:"object",properties:{target:V,value:{type:"string"},expect:lt},required:["target","value"]},scope:"browser:act"},{name:"browser_select",description:"Choose a select option.",inputSchema:{type:"object",properties:{target:V,value:{type:"string"}},required:["target","value"]},scope:"browser:act"},{name:"browser_press",description:"Press a key on a target or the focused element.",inputSchema:{type:"object",properties:{target:V,key:{type:"string"}}},scope:"browser:act"},{name:"browser_scroll",description:"Scroll a target into view or scroll the page.",inputSchema:{type:"object",properties:{target:V,direction:{type:"string"}}},scope:"browser:act"},{name:"browser_navigate",description:"Navigate the controlled tab (site grant required).",inputSchema:{type:"object",properties:{url:{type:"string"}},required:["url"]},scope:"browser:act"},{name:"browser_back",description:"Tab history back.",inputSchema:{type:"object",properties:{}},scope:"browser:act"},{name:"browser_forward",description:"Tab history forward.",inputSchema:{type:"object",properties:{}},scope:"browser:act"},{name:"browser_tabs",description:"List open tabs.",inputSchema:{type:"object",properties:{}},scope:"browser:read"},{name:"browser_switch_tab",description:"Switch control to another tab.",inputSchema:{type:"object",properties:{tabId:{type:"number"}},required:["tabId"]},scope:"browser:act"},{name:"browser_screenshot",description:"Capture the visible tab (rate-limited fallback).",inputSchema:{type:"object",properties:{}},scope:"browser:read"},{name:"browser_extract",description:"Extract text/table data plus article body paragraphs (passwords never returned).",inputSchema:{type:"object",properties:{regionId:{type:"string"},maxRows:{type:"number"}}},scope:"browser:read"},{name:"browser_wait",description:"Wait for a condition or timeout.",inputSchema:{type:"object",properties:{timeoutMs:{type:"number"},urlMatches:{type:"string"}}},scope:"browser:read"},{name:"browser_plan",description:"Guarded micro-plan: multiple verified steps, one decision.",inputSchema:{type:"object",properties:{steps:{type:"array",description:"Ordered guarded steps (1-25).",items:ti},abortOn:{type:"array",description:"Abort conditions (defaults to all four).",items:{type:"string",enum:["navigation","ambiguous_target","permission_required","page_epoch_changed"]}}},required:["steps"]},scope:"browser:act"}];function Pe(e){return ct.find(t=>t.name===e)}fe();var cn=require("node:http");var vs=U(Jr(),1),xs=U(Fe(),1),ws=U(te(),1),Ts=U(bt(),1),ks=U(xt(),1),Cs=U(At(),1),Os=U(Ge(),1),Pt=U(rn(),1);function nn(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}function ze(e,t,r){return{id:e,kind:"response",error:{code:t,message:r}}}var Ke=require("node:crypto"),W=require("node:fs"),an=require("node:path");function on(e){return String(e?Math.floor(1e5+e()*9e5):(0,Ke.randomInt)(1e5,1e6))}var Je=class{sessions=new Map;tokens=new Map;lastRequestAt=new Map;persistPath;revokeListeners=new Set;onRevoke(t){this.revokeListeners.add(t)}revoked(t){for(let r of this.revokeListeners)r(t)}constructor(t={}){if(this.persistPath=t.persistPath,this.persistPath&&(0,W.existsSync)(this.persistPath))try{let r=JSON.parse((0,W.readFileSync)(this.persistPath,"utf8")),n=Date.now();for(let i of r){if(!i?.token||!i?.deviceId)continue;let s=typeof i.expiresAt=="number"?i.expiresAt:i.createdAt+7776e6;s<=n||this.tokens.set(i.token,{...i,expiresAt:s})}}catch{}}persist(){if(this.persistPath)try{(0,W.mkdirSync)((0,an.dirname)(this.persistPath),{recursive:!0}),(0,W.writeFileSync)(this.persistPath,JSON.stringify([...this.tokens.values()]),{mode:384})}catch{}}requestPairing(t,r,n,i=Date.now(),s){this.scrub(i);let o=this.lastRequestAt.get(t);if(o!==void 0&&i>=o&&i-o<5e3)throw Object.assign(new Error("RATE_LIMITED: pairing requested too soon"),{code:"RATE_LIMITED"});if([...this.sessions.values()].filter(h=>h.deviceId===t&&!h.approved).length>=5)throw Object.assign(new Error("RATE_LIMITED: too many pending pairings for device"),{code:"RATE_LIMITED"});if(this.sessions.size>=100)throw Object.assign(new Error("RATE_LIMITED: pairing store full"),{code:"RATE_LIMITED"});let l=on(s),c=0;for(;this.sessions.has(l)&&c++<100;)l=on(s);if(this.sessions.has(l))throw Object.assign(new Error("RATE_LIMITED: code space exhausted"),{code:"RATE_LIMITED"});let f=String(r??"agent").slice(0,64)||"agent",d=(Array.isArray(n)?n:[]).map(String).slice(0,8),u={code:l,deviceId:t,clientName:f,scopes:d,createdAt:i,expiresAt:i+6e5,approved:!1};return this.sessions.set(l,u),this.lastRequestAt.set(t,i),u}approvePairing(t,r,n=Date.now()){let i=this.sessions.get(t);if(!i||i.deviceId!==r||i.expiresAt<=n)return null;if(i.approved&&i.token){let o=this.tokens.get(i.token);if(o&&o.expiresAt>n)return i.token}let s=(0,Ke.randomBytes)(24).toString("hex");return i.approved=!0,i.token=s,this.tokens.set(s,{token:s,deviceId:i.deviceId,clientName:i.clientName,scopes:i.scopes,createdAt:n,expiresAt:n+7776e6}),this.persist(),s}claimPairing(t,r=Date.now()){let n=this.sessions.get(t);return!n||n.expiresAt<=r?{status:"expired"}:n.approved&&n.token?{status:"approved",token:n.token}:{status:"pending"}}verifyToken(t,r=Date.now()){let n=this.tokens.get(t);return n?n.expiresAt<=r?(this.tokens.delete(t),this.persist(),null):n:null}revokeToken(t){let r=this.tokens.delete(t);return r&&(this.persist(),this.revoked(t)),r}revokeDevice(t){let r=0;for(let[n,i]of this.tokens)i.deviceId===t&&(this.tokens.delete(n),this.revoked(n),r++);return r>0&&this.persist(),r}pendingForDevice(t,r=Date.now()){return this.scrub(r),[...this.sessions.values()].filter(n=>n.deviceId===t&&!n.approved&&n.expiresAt>r)}scrub(t){for(let[r,n]of this.sessions)n.expiresAt<=t&&this.sessions.delete(r)}};var Ye=class{devices=new Map;pending=new Map;registerDevice(t,r){let n=this.devices.get(t)??null;return this.devices.set(t,r),n&&n!==r?n:null}unregisterDevice(t,r){(!r||this.devices.get(t)===r)&&(this.devices.delete(t),this.failPendingForDevice(t,new Error(`DISCONNECTED: device ${t} offline`)))}failPendingForDevice(t,r){let n=0;for(let[i,s]of this.pending){if(s.deviceId!==t)continue;this.pending.delete(i),clearTimeout(s.timer);let o=r??new Error(`DISCONNECTED: device ${t} offline`);o.code??="DISCONNECTED",s.reject(o),n++}return n}isCurrentDevice(t,r){return this.devices.get(t)===r}isDeviceOnline(t){return this.devices.has(t)}onlineDevices(){return[...this.devices.keys()]}routeToDevice(t,r,n,i=13e4,s){let o=this.devices.get(t);if(!o)return Promise.reject(Object.assign(new Error(`DISCONNECTED: device ${t} offline`),{code:"DISCONNECTED"}));let a=nn(),l={id:a,kind:"request",method:r,params:n,agentName:s?.agentName};return new Promise((c,f)=>{let d=setTimeout(()=>{this.pending.delete(a),f(Object.assign(new Error(`TIMEOUT waiting for device ${t}`),{code:"TIMEOUT"}))},i);d.unref?.(),this.pending.set(a,{deviceId:t,resolve:c,reject:f,timer:d});try{o(JSON.stringify(l))}catch(u){this.pending.delete(a),clearTimeout(d),f(u instanceof Error?u:new Error(String(u)))}})}settleResponse(t,r){let n=this.pending.get(t.id);return!n||r!==void 0&&n.deviceId!==r?!1:(this.pending.delete(t.id),clearTimeout(n.timer),t.error?n.reject(Object.assign(new Error(`${t.error.code}: ${t.error.message}`),{code:t.error.code})):n.resolve(t.result),!0)}pendingCount(){return this.pending.size}};fe();fe();var Ls="2024-11-05";function Ds(e){let t=new URL(e.url??"/","http://localhost");return e.method==="POST"&&t.pathname==="/mcp"}async function ln(e,t,r){if(!Ds(e))return!1;let n=r.pairings.verifyToken(Ie(e.headers.authorization)??"");if(!n)return P(t,e,null,{error:{code:-32001,message:"Unauthorized: invalid or missing pairing token"}},401);let i;try{i=await le(e)}catch(o){return P(t,e,null,{error:{code:-32600,message:o.message}},o.status??400)}let s=i;if(s.jsonrpc!=="2.0"||typeof s.method!="string")return P(t,e,s.id??null,{error:{code:-32600,message:"Invalid JSON-RPC request"}},400);if(s.method==="initialize")return P(t,e,s.id??null,{result:{protocolVersion:Ls,capabilities:{tools:{}},serverInfo:{name:"babtab-relay",version:"0.1.1"}}});if(s.method.startsWith("notifications/"))return t.writeHead(202).end(),!0;if(s.method==="tools/list")return P(t,e,s.id??null,{result:{tools:ct.map(o=>({name:o.name,description:o.description,inputSchema:o.inputSchema}))}});if(s.method==="tools/call"){let o=String(s.params?.name??""),a=s.params?.arguments??{};if(!L(a))return P(t,e,s.id??null,{result:Ze("Tool arguments must be an object")});let l=Pe(o);if(!l)return P(t,e,s.id??null,{result:Ze(`Unknown tool: ${o}`)});if(!ce(n,l.scope))return P(t,e,s.id??null,{result:Ze(`Token lacks scope ${l.scope} for ${o}`)});try{let c=await r.registry.routeToDevice(n.deviceId,o,a,13e4,{agentName:n.clientName}),f=[];if(o==="browser_screenshot"&&L(c)&&typeof c.dataUrl=="string"){let h=/^data:(image\/(?:jpeg|png|webp));base64,([A-Za-z0-9+/=]+)$/.exec(c.dataUrl);h&&f.push({type:"image",mimeType:h[1],data:h[2]})}let d=It(c),u=JSON.stringify(d)??"null";return f.push({type:"text",text:u.length<=64e3?u:JSON.stringify({truncated:!0,originalLength:u.length,preview:u.slice(0,3e4)})}),P(t,e,s.id??null,{result:{content:f,...L(c)&&c.ok===!1?{isError:!0}:{}}})}catch(c){let f=c;return P(t,e,s.id??null,{result:Ze(`${f.code??"DISCONNECTED"}: ${f.message}`,!0)})}}return P(t,e,s.id??null,{error:{code:-32601,message:`Method not found: ${s.method}`}},404)}function Ze(e,t=!1){return{content:[{type:"text",text:e}],isError:!0,_meta:{retryable:t}}}function P(e,t,r,n,i=200){let s=JSON.stringify({jsonrpc:"2.0",id:r,...n});return String(t.headers.accept??"application/json").includes("text/event-stream")?(e.writeHead(i,{"content-type":"text/event-stream","cache-control":"no-cache","access-control-allow-origin":"*"}),e.end(`event: message
|
|
72
|
+
data: ${s}
|
|
73
|
+
|
|
74
|
+
`),!0):(e.writeHead(i,{"content-type":"application/json","access-control-allow-origin":"*"}),e.end(s),!0)}function It(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(It);let t={};for(let[r,n]of Object.entries(e)){if((r==="dataUrl"||r==="dataURL")&&typeof n=="string"&&n.length>8e3){t[r]=`[truncated ${r}: ${n.length} chars, image data omitted from text]`,t[`${r}Truncated`]=!0,t[`${r}Length`]=n.length;continue}t[r]=It(n)}return t}function fn(e={}){let t=new Je({persistPath:e.tokenFile??process.env.BABTAB_TOKEN_FILE??"./data/relay-tokens.json"}),r=new Ye,n,i=!1,s=new Map,o=new Map,a=(0,cn.createServer)((u,h)=>{if(i){h.writeHead(503).end();return}Ms(u,h,n).catch(g=>{h.headersSent||h.writeHead(g.status??500,{"content-type":"application/json"}),h.end(JSON.stringify({error:g.status?g.message:"Internal server error"}))})}),l=new Pt.default({server:a,maxPayload:8*1024*1024});l.on("connection",(u,h)=>{if(u.on("error",()=>u.terminate()),i){u.close(1001,"relay shutting down");return}let g=new URL(h.url??"/","http://localhost");if(g.pathname==="/device"){let m=g.searchParams.get("deviceId")??"",S=setTimeout(()=>u.close(1008,"device authentication required"),5e3);S.unref(),u.once("close",()=>clearTimeout(S)),u.once("message",E=>{clearTimeout(S);let C;try{C=JSON.parse(String(E))}catch{u.close(1008,"invalid authentication");return}if(!L(C)||C.kind!=="authenticate"||!Us(m,C.token)){u.close(1008,"invalid device credential");return}let q=s.get(m);s.set(m,u),$s(u,m,t,r),q?.close(1008,"device reconnected"),u.once("close",()=>{s.get(m)===u&&s.delete(m)}),u.send(JSON.stringify({kind:"authenticated"}))})}else if(g.pathname==="/client"){let m=g.searchParams.get("token")??"";o.set(u,m),u.once("close",()=>o.delete(u)),Bs(u,m,t,r)}else u.close(1008,"unknown path")});let c=setInterval(()=>{for(let u of l.clients){let h=o.get(u);if(h&&!t.verifyToken(h)){u.close(1008,"token expired or revoked");continue}if(u.isAlive===!1){u.terminate();continue}u.isAlive=!1,u.ping()}},2e4);c.unref?.(),l.on("connection",u=>{u.isAlive=!0,u.on("pong",()=>{u.isAlive=!0})});let f=e.port??0;t.onRevoke(u=>{for(let[h,g]of o)g===u&&h.close(1008,"token revoked")}),a.listen(f,e.host??"127.0.0.1");let d;return n={server:a,pairings:t,registry:r,close:()=>d??=new Promise((u,h)=>{i=!0,clearInterval(c);for(let E of r.onlineDevices())r.failPendingForDevice(E);for(let E of l.clients)E.close(1001,"relay shutting down");let g=setTimeout(()=>{for(let E of l.clients)E.terminate();a.closeAllConnections()},1e3),m=new Promise((E,C)=>a.close(q=>q?C(q):E())),S=new Promise(E=>l.close(()=>E()));Promise.all([m,S]).then(()=>{clearTimeout(g),u()},E=>{clearTimeout(g),h(E)})})},n}async function Ms(e,t,r){let n=new URL(e.url??"/","http://localhost");if(e.method==="OPTIONS"){t.writeHead(204,{"access-control-allow-origin":"*","access-control-allow-methods":"GET, POST, OPTIONS","access-control-allow-headers":"content-type, authorization"}),t.end();return}let i=(s,o)=>{t.writeHead(s,{"content-type":"application/json","access-control-allow-origin":"*"}),t.end(JSON.stringify(o))};if(e.method==="GET"&&n.pathname==="/health"){i(200,{ok:!0,devices:r.registry.onlineDevices().length});return}if(e.method==="POST"&&n.pathname==="/pairing/request"){let s=await le(e),o=String(s.deviceId??"").slice(0,128);if(!o){i(400,{error:"deviceId required"});return}let a=Array.isArray(s.scopes)?s.scopes.map(String).slice(0,8):["browser:read","browser:act"];try{let l=r.pairings.requestPairing(o,String(s.clientName??"agent"),a);i(200,{code:l.code,expiresAt:l.expiresAt,deviceOnline:r.registry.isDeviceOnline(o)})}catch(l){if(l.code==="RATE_LIMITED"){i(429,{error:l.message});return}throw l}return}if(e.method==="POST"&&n.pathname==="/pairing/claim"){let s=await le(e);i(200,r.pairings.claimPairing(String(s.code??"")));return}if(e.method==="POST"&&n.pathname==="/pairing/revoke"){let{extractBearer:s}=await Promise.resolve().then(()=>(fe(),Qt)),o=s(e.headers.authorization)??"",a=o?r.pairings.revokeToken(o):!1;i(200,{ok:a});return}await ln(e,t,r)||i(404,{error:"not found"})}function $s(e,t,r,n){if(!t){e.close(1008,"deviceId required");return}let i=o=>{e.readyState===e.OPEN&&e.send(o)};n.registerDevice(t,i)&&n.failPendingForDevice(t),e.on("message",o=>{let a;try{a=JSON.parse(String(o))}catch{return}if(!un(a)){e.close(1008,"invalid envelope");return}if(n.isCurrentDevice(t,i)){if(a.kind==="response"){n.settleResponse(a,t);return}if(a.kind!=="pong"&&a.kind==="request"&&a.id){if(a.method==="pairing:pending"){let l=r.pendingForDevice(t).map(c=>({code:c.code,clientName:c.clientName,scopes:c.scopes,createdAt:c.createdAt,expiresAt:c.expiresAt}));e.send(JSON.stringify({id:a.id,kind:"response",result:l}));return}if(a.method==="pairing:approve"){let l=String(a.params?.code??""),c=r.approvePairing(l,t)!=null;e.send(JSON.stringify({id:a.id,kind:"response",result:{ok:c}}));return}if(a.method==="pairing:revoke-device"){let l=r.revokeDevice(t);e.send(JSON.stringify({id:a.id,kind:"response",result:{revoked:l}}));return}e.send(JSON.stringify(ze(a.id,"UNSUPPORTED_OPERATION",`Unknown device method ${a.method}`)))}}}),e.on("close",()=>n.unregisterDevice(t,i))}function Bs(e,t,r,n){let i=r.verifyToken(t);if(!i){e.close(1008,"invalid token");return}e.on("message",s=>{let o;try{o=JSON.parse(String(s))}catch{return}if(!un(o)){e.close(1008,"invalid envelope");return}if(o.kind!=="request"||!o.method)return;let a=r.verifyToken(t);if(!a){e.close(1008,"token expired or revoked");return}let l=Pe(o.method);if(!l||!ce(a,l.scope)){e.send(JSON.stringify(ze(o.id,"USER_REJECTED","Unknown tool or insufficient scope")));return}n.routeToDevice(i.deviceId,o.method,o.params,13e4,{agentName:i.clientName}).then(c=>{e.readyState===e.OPEN&&e.send(JSON.stringify({id:o.id,kind:"response",result:c}))}).catch(c=>{e.readyState===e.OPEN&&e.send(JSON.stringify(ze(o.id,c.code??"DISCONNECTED",c.message)))})})}function Us(e,t){if(!/^dev_v2_[a-f0-9]{64}$/.test(e)||typeof t!="string"||!/^[a-f0-9]{64}$/.test(t))return!1;let r=(0,Xe.createHash)("sha256").update(t).digest();return(0,Xe.timingSafeEqual)(r,Buffer.from(e.slice(7),"hex"))}function un(e){return L(e)?e.kind==="ping"||e.kind==="pong"?!0:typeof e.id!="string"||e.id.length>256?!1:e.kind==="request"?typeof e.method=="string"&&(e.params===void 0||L(e.params)):e.kind==="response"&&(e.error===void 0||L(e.error)&&typeof e.error.code=="string"&&typeof e.error.message=="string"):!1}async function so(){let e=process.argv[2];if(e==="setup"){let{runSetup:t}=await Promise.resolve().then(()=>(Jt(),zt));process.exitCode=await t(process.argv.slice(3))}else if(e==="help"||e==="--help"||e==="-h"){let{setupHelp:t}=await Promise.resolve().then(()=>(Jt(),zt));console.log(`babtab-relay \u2014 local bridge between your AI agent and Chrome
|
|
75
|
+
|
|
76
|
+
Start the relay:
|
|
77
|
+
npx -y @babtab/relay (env: PORT=3000 BABTAB_TOKEN_FILE=./data/relay-tokens.json)
|
|
78
|
+
|
|
79
|
+
`+t())}else e!==void 0?(console.error(`Unknown command: ${e}
|
|
80
|
+
Run \`npx -y @babtab/relay help\` for usage.`),process.exitCode=1):oo()}so();function oo(){let e=Number(process.env.PORT??3e3),t=fn({port:e,host:process.env.HOST??"127.0.0.1"});t.server.on("listening",()=>{let n=t.server.address(),i=typeof n=="object"&&n?n.port:e;console.log(`[babtab-relay] listening on http://${process.env.HOST??"127.0.0.1"}:${i}`),console.log("[babtab-relay] health: GET /health \xB7 mcp: POST /mcp"),console.log(`[babtab-relay] Side Panel \u2192 Relay URL = ws://127.0.0.1:${i} \u2192 Save & Connect`)});let r=()=>{t.close().then(()=>process.exit(0))};process.on("SIGINT",r),process.on("SIGTERM",r)}
|
|
81
|
+
/*! Bundled license information:
|
|
82
|
+
|
|
83
|
+
smol-toml/dist/error.js:
|
|
84
|
+
(*!
|
|
85
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
86
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
87
|
+
*
|
|
88
|
+
* Redistribution and use in source and binary forms, with or without
|
|
89
|
+
* modification, are permitted provided that the following conditions are met:
|
|
90
|
+
*
|
|
91
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
92
|
+
* list of conditions and the following disclaimer.
|
|
93
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
94
|
+
* this list of conditions and the following disclaimer in the
|
|
95
|
+
* documentation and/or other materials provided with the distribution.
|
|
96
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
97
|
+
* may be used to endorse or promote products derived from this software without
|
|
98
|
+
* specific prior written permission.
|
|
99
|
+
*
|
|
100
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
101
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
102
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
103
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
104
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
105
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
106
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
107
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
108
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
109
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
110
|
+
*)
|
|
111
|
+
|
|
112
|
+
smol-toml/dist/primitive.js:
|
|
113
|
+
(*!
|
|
114
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
115
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
116
|
+
*
|
|
117
|
+
* Redistribution and use in source and binary forms, with or without
|
|
118
|
+
* modification, are permitted provided that the following conditions are met:
|
|
119
|
+
*
|
|
120
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
121
|
+
* list of conditions and the following disclaimer.
|
|
122
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
123
|
+
* this list of conditions and the following disclaimer in the
|
|
124
|
+
* documentation and/or other materials provided with the distribution.
|
|
125
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
126
|
+
* may be used to endorse or promote products derived from this software without
|
|
127
|
+
* specific prior written permission.
|
|
128
|
+
*
|
|
129
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
130
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
131
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
132
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
133
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
134
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
135
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
136
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
137
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
138
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
139
|
+
*)
|
|
140
|
+
|
|
141
|
+
smol-toml/dist/date.js:
|
|
142
|
+
(*!
|
|
143
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
144
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
145
|
+
*
|
|
146
|
+
* Redistribution and use in source and binary forms, with or without
|
|
147
|
+
* modification, are permitted provided that the following conditions are met:
|
|
148
|
+
*
|
|
149
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
150
|
+
* list of conditions and the following disclaimer.
|
|
151
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
152
|
+
* this list of conditions and the following disclaimer in the
|
|
153
|
+
* documentation and/or other materials provided with the distribution.
|
|
154
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
155
|
+
* may be used to endorse or promote products derived from this software without
|
|
156
|
+
* specific prior written permission.
|
|
157
|
+
*
|
|
158
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
159
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
160
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
161
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
162
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
163
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
164
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
165
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
166
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
167
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
168
|
+
*)
|
|
169
|
+
|
|
170
|
+
smol-toml/dist/extract.js:
|
|
171
|
+
(*!
|
|
172
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
173
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
174
|
+
*
|
|
175
|
+
* Redistribution and use in source and binary forms, with or without
|
|
176
|
+
* modification, are permitted provided that the following conditions are met:
|
|
177
|
+
*
|
|
178
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
179
|
+
* list of conditions and the following disclaimer.
|
|
180
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
181
|
+
* this list of conditions and the following disclaimer in the
|
|
182
|
+
* documentation and/or other materials provided with the distribution.
|
|
183
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
184
|
+
* may be used to endorse or promote products derived from this software without
|
|
185
|
+
* specific prior written permission.
|
|
186
|
+
*
|
|
187
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
188
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
189
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
190
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
191
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
192
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
193
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
194
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
195
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
196
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
197
|
+
*)
|
|
198
|
+
|
|
199
|
+
smol-toml/dist/util.js:
|
|
200
|
+
(*!
|
|
201
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
202
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
203
|
+
*
|
|
204
|
+
* Redistribution and use in source and binary forms, with or without
|
|
205
|
+
* modification, are permitted provided that the following conditions are met:
|
|
206
|
+
*
|
|
207
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
208
|
+
* list of conditions and the following disclaimer.
|
|
209
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
210
|
+
* this list of conditions and the following disclaimer in the
|
|
211
|
+
* documentation and/or other materials provided with the distribution.
|
|
212
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
213
|
+
* may be used to endorse or promote products derived from this software without
|
|
214
|
+
* specific prior written permission.
|
|
215
|
+
*
|
|
216
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
217
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
218
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
219
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
220
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
221
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
222
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
223
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
224
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
225
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
226
|
+
*)
|
|
227
|
+
|
|
228
|
+
smol-toml/dist/struct.js:
|
|
229
|
+
(*!
|
|
230
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
231
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
232
|
+
*
|
|
233
|
+
* Redistribution and use in source and binary forms, with or without
|
|
234
|
+
* modification, are permitted provided that the following conditions are met:
|
|
235
|
+
*
|
|
236
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
237
|
+
* list of conditions and the following disclaimer.
|
|
238
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
239
|
+
* this list of conditions and the following disclaimer in the
|
|
240
|
+
* documentation and/or other materials provided with the distribution.
|
|
241
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
242
|
+
* may be used to endorse or promote products derived from this software without
|
|
243
|
+
* specific prior written permission.
|
|
244
|
+
*
|
|
245
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
246
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
247
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
248
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
249
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
250
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
251
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
252
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
253
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
254
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
255
|
+
*)
|
|
256
|
+
|
|
257
|
+
smol-toml/dist/parse.js:
|
|
258
|
+
(*!
|
|
259
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
260
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
261
|
+
*
|
|
262
|
+
* Redistribution and use in source and binary forms, with or without
|
|
263
|
+
* modification, are permitted provided that the following conditions are met:
|
|
264
|
+
*
|
|
265
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
266
|
+
* list of conditions and the following disclaimer.
|
|
267
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
268
|
+
* this list of conditions and the following disclaimer in the
|
|
269
|
+
* documentation and/or other materials provided with the distribution.
|
|
270
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
271
|
+
* may be used to endorse or promote products derived from this software without
|
|
272
|
+
* specific prior written permission.
|
|
273
|
+
*
|
|
274
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
275
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
276
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
277
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
278
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
279
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
280
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
281
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
282
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
283
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
284
|
+
*)
|
|
285
|
+
|
|
286
|
+
smol-toml/dist/stringify.js:
|
|
287
|
+
(*!
|
|
288
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
289
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
290
|
+
*
|
|
291
|
+
* Redistribution and use in source and binary forms, with or without
|
|
292
|
+
* modification, are permitted provided that the following conditions are met:
|
|
293
|
+
*
|
|
294
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
295
|
+
* list of conditions and the following disclaimer.
|
|
296
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
297
|
+
* this list of conditions and the following disclaimer in the
|
|
298
|
+
* documentation and/or other materials provided with the distribution.
|
|
299
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
300
|
+
* may be used to endorse or promote products derived from this software without
|
|
301
|
+
* specific prior written permission.
|
|
302
|
+
*
|
|
303
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
304
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
305
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
306
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
307
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
308
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
309
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
310
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
311
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
312
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
313
|
+
*)
|
|
314
|
+
|
|
315
|
+
smol-toml/dist/index.js:
|
|
316
|
+
(*!
|
|
317
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
318
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
319
|
+
*
|
|
320
|
+
* Redistribution and use in source and binary forms, with or without
|
|
321
|
+
* modification, are permitted provided that the following conditions are met:
|
|
322
|
+
*
|
|
323
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
324
|
+
* list of conditions and the following disclaimer.
|
|
325
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
326
|
+
* this list of conditions and the following disclaimer in the
|
|
327
|
+
* documentation and/or other materials provided with the distribution.
|
|
328
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
329
|
+
* may be used to endorse or promote products derived from this software without
|
|
330
|
+
* specific prior written permission.
|
|
331
|
+
*
|
|
332
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
333
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
334
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
335
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
336
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
337
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
338
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
339
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
340
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
341
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
342
|
+
*)
|
|
343
|
+
*/
|