@babtab/relay 0.1.0 → 0.2.0
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 +49 -0
- package/LICENSE +1 -12
- package/README.es.md +33 -18
- package/README.hi.md +33 -18
- package/README.ja.md +31 -19
- package/README.ko.md +32 -18
- package/README.md +27 -58
- package/README.pt-BR.md +33 -18
- package/README.zh-TW.md +37 -58
- package/SECURITY.md +13 -12
- package/dist/relay.cjs +348 -6
- package/package.json +6 -3
package/dist/relay.cjs
CHANGED
|
@@ -1,11 +1,353 @@
|
|
|
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 di=Object.create;var St=Object.defineProperty;var hi=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var mi=Object.getPrototypeOf,gi=Object.prototype.hasOwnProperty;var y=(e,t)=>()=>(e&&(t=e(e=0)),t);var T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),vt=(e,t)=>{for(var r in t)St(e,r,{get:t[r],enumerable:!0})},_i=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of pi(t))!gi.call(e,i)&&i!==r&&St(e,i,{get:()=>t[i],enumerable:!(n=hi(t,i))||n.enumerable});return e};var j=(e,t,r)=>(r=e!=null?di(mi(e)):{},_i(t||!e||!e.__esModule?St(r,"default",{value:e,enumerable:!0}):r,e));function x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ue(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(!x(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 Re=y(()=>{"use strict"});function $e(e){return de.find(t=>t.name===e)}var V,yi,Et,bi,de,Me=y(()=>{"use strict";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"}}},yi={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},Et={type:"array",description:"Postconditions to verify after dispatch.",items:yi},bi={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:Et,timeoutMs:{type:"number"}},required:["action"],additionalProperties:!0},de=[{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:Et},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:Et},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:bi},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"}]});var pr={};vt(pr,{extractBearer:()=>he,hasScope:()=>hr,tokenAllows:()=>pe});function he(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 hr(e,t){return e.includes("*")||e.includes(t)}function pe(e,t){return e?hr(e.scopes,t):!1}var me=y(()=>{"use strict"});var $=T((Do,_r)=>{"use strict";var mr=["nodebuffer","arraybuffer","fragments"],gr=typeof Blob<"u";gr&&mr.push("blob");_r.exports={BINARY_TYPES:mr,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:gr,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ge=T((Lo,Be)=>{"use strict";var{EMPTY_BUFFER:Si}=$(),wt=Buffer[Symbol.species];function vi(e,t){if(e.length===0)return Si;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 wt(r.buffer,r.byteOffset,n):r}function yr(e,t,r,n,i){for(let s=0;s<i;s++)r[n+s]=e[s]^t[s&3]}function br(e,t){for(let r=0;r<e.length;r++)e[r]^=t[r&3]}function Ei(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function xt(e){if(xt.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=new wt(e):ArrayBuffer.isView(e)?t=new wt(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),xt.readOnly=!1),t}Be.exports={concat:vi,mask:yr,toArrayBuffer:Ei,toBuffer:xt,unmask:br};if(!process.env.WS_NO_BUFFER_UTIL)try{let e=require("bufferutil");Be.exports.mask=function(t,r,n,i,s){s<48?yr(t,r,n,i,s):e.mask(t,r,n,i,s)},Be.exports.unmask=function(t,r){t.length<32?br(t,r):e.unmask(t,r)}}catch{}});var Er=T((Ro,vr)=>{"use strict";var Sr=Symbol("kDone"),Tt=Symbol("kRun"),kt=class{constructor(t){this[Sr]=()=>{this.pending--,this[Tt]()},this.concurrency=t||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[Tt]()}[Tt](){if(this.pending!==this.concurrency&&this.jobs.length){let t=this.jobs.shift();this.pending++,t(this[Sr])}}};vr.exports=kt});var ne=T(($o,kr)=>{"use strict";var _e=require("zlib"),wr=ge(),wi=Er(),{kStatusCode:xr}=$(),xi=Buffer[Symbol.species],Ti=Buffer.from([0,0,255,255]),je=Symbol("permessage-deflate"),M=Symbol("total-length"),te=Symbol("callback"),F=Symbol("buffers"),re=Symbol("error"),Ue,Ct=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,!Ue){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ue=new wi(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[te];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){Ue.add(i=>{this._decompress(t,r,(s,o)=>{i(),n(s,o)})})}compress(t,r,n){Ue.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"?_e.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=_e.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[je]=this,this._inflate[M]=0,this._inflate[F]=[],this._inflate.on("error",Ci),this._inflate.on("data",Tr)}this._inflate[te]=n,this._inflate.write(t),r&&this._inflate.write(Ti),this._inflate.flush(()=>{let s=this._inflate[re];if(s){this._inflate.close(),this._inflate=null,n(s);return}let o=wr.concat(this._inflate[F],this._inflate[M]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[M]=0,this._inflate[F]=[],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"?_e.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=_e.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[M]=0,this._deflate[F]=[],this._deflate.on("data",ki)}this._deflate[te]=n,this._deflate.write(t),this._deflate.flush(_e.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=wr.concat(this._deflate[F],this._deflate[M]);r&&(s=new xi(s.buffer,s.byteOffset,s.length-4)),this._deflate[te]=null,this._deflate[M]=0,this._deflate[F]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),n(null,s)})}};kr.exports=Ct;function ki(e){this[F].push(e),this[M]+=e.length}function Tr(e){if(this[M]+=e.length,this[je]._maxPayload<1||this[M]<=this[je]._maxPayload){this[F].push(e);return}this[re]=new RangeError("Max payload size exceeded"),this[re].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[re][xr]=1009,this.removeListener("data",Tr),this.reset()}function Ci(e){if(this[je]._inflate=null,this[re]){this[te](this[re]);return}e[xr]=1007,this[te](e)}});var ie=T((Mo,Fe)=>{"use strict";var{isUtf8:Cr}=require("buffer"),{hasBlob:Oi}=$(),Ai=[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 Ni(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function Ot(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 Pi(e){return Oi&&typeof e=="object"&&typeof e.arrayBuffer=="function"&&typeof e.type=="string"&&typeof e.stream=="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}Fe.exports={isBlob:Pi,isValidStatusCode:Ni,isValidUTF8:Ot,tokenChars:Ai};if(Cr)Fe.exports.isValidUTF8=function(e){return e.length<24?Ot(e):Cr(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let e=require("utf-8-validate");Fe.exports.isValidUTF8=function(t){return t.length<32?Ot(t):e(t)}}catch{}});var Dt=T((Bo,Lr)=>{"use strict";var{Writable:Ii}=require("stream"),Or=ne(),{BINARY_TYPES:Di,EMPTY_BUFFER:Ar,kStatusCode:Li,kWebSocket:Ri}=$(),{concat:At,toArrayBuffer:$i,unmask:Mi}=ge(),{isValidStatusCode:Bi,isValidUTF8:Nr}=ie(),We=Buffer[Symbol.species],A=0,Pr=1,Ir=2,Dr=3,Nt=4,Pt=5,qe=6,It=class extends Ii{constructor(t={}){super(),this._allowSynchronousEvents=t.allowSynchronousEvents!==void 0?t.allowSynchronousEvents:!0,this._binaryType=t.binaryType||Di[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[Ri]=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=A}_write(t,r,n){if(this._opcode===8&&this._state==A)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 We(n.buffer,n.byteOffset+t,n.length-t),new We(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 We(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 A:this.getInfo(t);break;case Pr:this.getPayloadLength16(t);break;case Ir:this.getPayloadLength64(t);break;case Dr:this.getMask();break;case Nt:this.getData(t);break;case Pt:case qe: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[Or.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=Pr:this._payloadLength===127?this._state=Ir: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=Dr:this._state=Nt}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Nt}getData(t){let r=Ar;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]&&Mi(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=Pt,this.decompress(r,t);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(t)}decompress(t,r){this._extensions[Or.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===A&&this.startLoop(r)})}dataMessage(t){if(!this._fin){this._state=A;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=At(n,r):this._binaryType==="arraybuffer"?i=$i(At(n,r)):this._binaryType==="blob"?i=new Blob(n):i=n,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=A):(this._state=qe,setImmediate(()=>{this.emit("message",i,!0),this._state=A,this.startLoop(t)}))}else{let i=At(n,r);if(!this._skipUTF8Validation&&!Nr(i)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(s);return}this._state===Pt||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=A):(this._state=qe,setImmediate(()=>{this.emit("message",i,!1),this._state=A,this.startLoop(t)}))}}controlMessage(t,r){if(this._opcode===8){if(t.length===0)this._loop=!1,this.emit("conclude",1005,Ar),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 We(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!Nr(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=A;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",t),this._state=A):(this._state=qe,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",t),this._state=A,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[Li]=i,o}};Lr.exports=It});var $t=T((jo,Mr)=>{"use strict";var{Duplex:Uo}=require("stream"),{randomFillSync:Ui}=require("crypto"),{types:{isUint8Array:ji}}=require("util"),Rr=ne(),{EMPTY_BUFFER:Fi,kWebSocket:Wi,NOOP:qi}=$(),{isBlob:se,isValidStatusCode:Gi}=ie(),{mask:$r,toBuffer:H}=ge(),N=Symbol("kByteLength"),Vi=Buffer.alloc(4),Ge=8*1024,z,oe=Ge,P=0,Hi=1,zi=2,Lt=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=P,this.onerror=qi,this[Wi]=void 0}static frame(t,r){let n,i=!1,s=2,o=!1;r.mask&&(n=r.maskBuffer||Vi,r.generateMask?r.generateMask(n):(oe===Ge&&(z===void 0&&(z=Buffer.alloc(Ge)),Ui(z,0,Ge),oe=0),n[0]=z[oe++],n[1]=z[oe++],n[2]=z[oe++],n[3]=z[oe++]),o=(n[0]|n[1]|n[2]|n[3])===0,s=6);let a;typeof t=="string"?(!r.mask||o)&&r[N]!==void 0?a=r[N]:(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?($r(t,n,c,s,a),[c]):($r(t,n,t,0,a),[c,t])):[c,t]}close(t,r,n,i){let s;if(t===void 0)s=Fi;else{if(typeof t!="number"||!Gi(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(ji(r))s.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[N]:s.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==P?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):se(t)?(i=t.size,s=!1):(t=H(t),i=t.length,s=H.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[N]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};se(t)?this._state!==P?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==P?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):se(t)?(i=t.size,s=!1):(t=H(t),i=t.length,s=H.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[N]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};se(t)?this._state!==P?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==P?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}send(t,r,n){let i=this._extensions[Rr.extensionName],s=r.binary?2:1,o=r.compress,a,l;typeof t=="string"?(a=Buffer.byteLength(t),l=!1):se(t)?(a=t.size,l=!1):(t=H(t),a=t.length,l=H.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={[N]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:s,readOnly:l,rsv1:o};se(t)?this._state!==P?this.enqueue([this.getBlobData,t,this._compress,c,n]):this.getBlobData(t,this._compress,c,n):this._state!==P?this.enqueue([this.dispatch,t,this._compress,c,n]):this.dispatch(t,this._compress,c,n)}getBlobData(t,r,n,i){this._bufferedBytes+=n[N],this._state=zi,t.arrayBuffer().then(s=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Rt,this,a,i);return}this._bufferedBytes-=n[N];let o=H(s);r?this.dispatch(o,r,n,i):(this._state=P,this.sendFrame(e.frame(o,n),i),this.dequeue())}).catch(s=>{process.nextTick(Ji,this,s,i)})}dispatch(t,r,n,i){if(!r){this.sendFrame(e.frame(t,n),i);return}let s=this._extensions[Rr.extensionName];this._bufferedBytes+=n[N],this._state=Hi,s.compress(t,n.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Rt(this,l,i);return}this._bufferedBytes-=n[N],this._state=P,n.readOnly=!1,this.sendFrame(e.frame(a,n),i),this.dequeue()})}dequeue(){for(;this._state===P&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[3][N],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][N],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)}};Mr.exports=Lt;function Rt(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 Ji(e,t,r){Rt(e,t,r),e.onerror(t)}});var Hr=T((Fo,Vr)=>{"use strict";var{kForOnEventAttribute:ye,kListener:Mt}=$(),Br=Symbol("kCode"),Ur=Symbol("kData"),jr=Symbol("kError"),Fr=Symbol("kMessage"),Wr=Symbol("kReason"),ae=Symbol("kTarget"),qr=Symbol("kType"),Gr=Symbol("kWasClean"),B=class{constructor(t){this[ae]=null,this[qr]=t}get target(){return this[ae]}get type(){return this[qr]}};Object.defineProperty(B.prototype,"target",{enumerable:!0});Object.defineProperty(B.prototype,"type",{enumerable:!0});var J=class extends B{constructor(t,r={}){super(t),this[Br]=r.code===void 0?0:r.code,this[Wr]=r.reason===void 0?"":r.reason,this[Gr]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Br]}get reason(){return this[Wr]}get wasClean(){return this[Gr]}};Object.defineProperty(J.prototype,"code",{enumerable:!0});Object.defineProperty(J.prototype,"reason",{enumerable:!0});Object.defineProperty(J.prototype,"wasClean",{enumerable:!0});var le=class extends B{constructor(t,r={}){super(t),this[jr]=r.error===void 0?null:r.error,this[Fr]=r.message===void 0?"":r.message}get error(){return this[jr]}get message(){return this[Fr]}};Object.defineProperty(le.prototype,"error",{enumerable:!0});Object.defineProperty(le.prototype,"message",{enumerable:!0});var be=class extends B{constructor(t,r={}){super(t),this[Ur]=r.data===void 0?null:r.data}get data(){return this[Ur]}};Object.defineProperty(be.prototype,"data",{enumerable:!0});var Ki={addEventListener(e,t,r={}){for(let i of this.listeners(e))if(!r[ye]&&i[Mt]===t&&!i[ye])return;let n;if(e==="message")n=function(s,o){let a=new be("message",{data:o?s:s.toString()});a[ae]=this,Ve(t,this,a)};else if(e==="close")n=function(s,o){let a=new J("close",{code:s,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[ae]=this,Ve(t,this,a)};else if(e==="error")n=function(s){let o=new le("error",{error:s,message:s.message});o[ae]=this,Ve(t,this,o)};else if(e==="open")n=function(){let s=new B("open");s[ae]=this,Ve(t,this,s)};else return;n[ye]=!!r[ye],n[Mt]=t,r.once?this.once(e,n):this.on(e,n)},removeEventListener(e,t){for(let r of this.listeners(e))if(r[Mt]===t&&!r[ye]){this.removeListener(e,r);break}}};Vr.exports={CloseEvent:J,ErrorEvent:le,Event:B,EventTarget:Ki,MessageEvent:be};function Ve(e,t,r){typeof e=="object"&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}});var He=T((Wo,zr)=>{"use strict";var{tokenChars:Se}=ie();function R(e,t,r){e[t]===void 0?e[t]=[r]:e[t].push(r)}function Yi(e){let t=Object.create(null),r=Object.create(null),n=!1,i=!1,s=!1,o,a,l=-1,c=-1,u=-1,d=0;for(;d<e.length;d++)if(c=e.charCodeAt(d),o===void 0)if(u===-1&&Se[c]===1)l===-1&&(l=d);else if(d!==0&&(c===32||c===9))u===-1&&l!==-1&&(u=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d);let h=e.slice(l,u);c===44?(R(t,h,r),r=Object.create(null)):o=h,l=u=-1}else throw new SyntaxError(`Unexpected character at index ${d}`);else if(a===void 0)if(u===-1&&Se[c]===1)l===-1&&(l=d);else if(c===32||c===9)u===-1&&l!==-1&&(u=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d),R(r,e.slice(l,u),!0),c===44&&(R(t,o,r),r=Object.create(null),o=void 0),l=u=-1}else if(c===61&&l!==-1&&u===-1)a=e.slice(l,d),l=u=-1;else throw new SyntaxError(`Unexpected character at index ${d}`);else if(i){if(Se[c]!==1)throw new SyntaxError(`Unexpected character at index ${d}`);l===-1?l=d:n||(n=!0),i=!1}else if(s)if(Se[c]===1)l===-1&&(l=d);else if(c===34&&l!==-1)s=!1,u=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(u===-1&&Se[c]===1)l===-1&&(l=d);else if(l!==-1&&(c===32||c===9))u===-1&&(u=d);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d);let h=e.slice(l,u);n&&(h=h.replace(/\\/g,""),n=!1),R(r,a,h),c===44&&(R(t,o,r),r=Object.create(null),o=void 0),a=void 0,l=u=-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");u===-1&&(u=d);let f=e.slice(l,u);return o===void 0?R(t,f,r):(a===void 0?R(r,f,!0):n?R(r,a,f.replace(/\\/g,"")):R(r,a,f),R(t,o,r)),t}function Zi(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(", ")}zr.exports={format:Zi,parse:Yi}});var Ye=T((Vo,on)=>{"use strict";var Xi=require("events"),Qi=require("https"),es=require("http"),Yr=require("net"),ts=require("tls"),{randomBytes:rs,createHash:ns}=require("crypto"),{Duplex:qo,Readable:Go}=require("stream"),{URL:Bt}=require("url"),W=ne(),is=Dt(),ss=$t(),{isBlob:os}=ie(),{BINARY_TYPES:Jr,CLOSE_TIMEOUT:as,EMPTY_BUFFER:ze,GUID:ls,kForOnEventAttribute:Ut,kListener:cs,kStatusCode:fs,kWebSocket:w,NOOP:Zr}=$(),{EventTarget:{addEventListener:us,removeEventListener:ds}}=Hr(),{format:hs,parse:ps}=He(),{toBuffer:ms}=ge(),Xr=Symbol("kAborted"),jt=[8,13],U=["CONNECTING","OPEN","CLOSING","CLOSED"],gs=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,b=class e extends Xi{constructor(t,r,n){super(),this._binaryType=Jr[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ze,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]),Qr(this,t,r,n)):(this._autoPong=n.autoPong,this._closeTimeout=n.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(t){Jr.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 is({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 ss(t,this._extensions,n.generateMask);this._receiver=i,this._sender=s,this._socket=t,i[w]=this,s[w]=this,t[w]=this,i.on("conclude",bs),i.on("drain",Ss),i.on("error",vs),i.on("message",Es),i.on("ping",ws),i.on("pong",xs),s.onerror=Ts,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",rn),t.on("data",Ke),t.on("end",nn),t.on("error",sn),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[W.extensionName]&&this._extensions[W.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){k(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())}),tn(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){Ft(this,t,n);return}r===void 0&&(r=!this._isServer),this._sender.ping(t||ze,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){Ft(this,t,n);return}r===void 0&&(r=!this._isServer),this._sender.pong(t||ze,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){Ft(this,t,n);return}let i={binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[W.extensionName]||(i.compress=!1),this._sender.send(t||ze,i,n)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){k(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=e.CLOSING,this._socket.destroy())}}};Object.defineProperty(b,"CONNECTING",{enumerable:!0,value:U.indexOf("CONNECTING")});Object.defineProperty(b.prototype,"CONNECTING",{enumerable:!0,value:U.indexOf("CONNECTING")});Object.defineProperty(b,"OPEN",{enumerable:!0,value:U.indexOf("OPEN")});Object.defineProperty(b.prototype,"OPEN",{enumerable:!0,value:U.indexOf("OPEN")});Object.defineProperty(b,"CLOSING",{enumerable:!0,value:U.indexOf("CLOSING")});Object.defineProperty(b.prototype,"CLOSING",{enumerable:!0,value:U.indexOf("CLOSING")});Object.defineProperty(b,"CLOSED",{enumerable:!0,value:U.indexOf("CLOSED")});Object.defineProperty(b.prototype,"CLOSED",{enumerable:!0,value:U.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(b.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(b.prototype,`on${e}`,{enumerable:!0,get(){for(let t of this.listeners(e))if(t[Ut])return t[cs];return null},set(t){for(let r of this.listeners(e))if(r[Ut]){this.removeListener(e,r);break}typeof t=="function"&&this.addEventListener(e,t,{[Ut]:!0})}})});b.prototype.addEventListener=us;b.prototype.removeEventListener=ds;on.exports=b;function Qr(e,t,r,n){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:as,protocolVersion:jt[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,!jt.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${jt.join(", ")})`);let s;if(t instanceof Bt)s=t;else try{s=new Bt(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;Je(e,m);return}let c=o?443:80,u=rs(16).toString("base64"),d=o?Qi.request:es.request,f=new Set,h;if(i.createConnection=i.createConnection||(o?ys:_s),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":u,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(h=new W({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=hs({[W.extensionName]:h.offer()})),r.length){for(let m of r){if(typeof m!="string"||!gs.test(m)||f.has(m))throw new SyntaxError("An invalid or duplicated subprotocol was specified");f.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",()=>{k(e,g,"Opening handshake has timed out")}),g.on("error",m=>{g===null||g[Xr]||(g=e._req=null,Je(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){k(e,g,"Maximum redirects exceeded");return}g.abort();let O;try{O=new Bt(S,t)}catch{let ee=new SyntaxError(`Invalid URL: ${S}`);Je(e,ee);return}Qr(e,O,r,n)}else e.emit("unexpected-response",g,m)||k(e,g,`Unexpected server response: ${m.statusCode}`)}),g.on("upgrade",(m,S,E)=>{if(e.emit("upgrade",m),e.readyState!==b.CONNECTING)return;g=e._req=null;let O=m.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){k(e,S,"Invalid Upgrade header");return}let G=ns("sha1").update(u+ls).digest("base64");if(m.headers["sec-websocket-accept"]!==G){k(e,S,"Invalid Sec-WebSocket-Accept header");return}let ee=m.headers["sec-websocket-protocol"],fe;if(ee!==void 0?f.size?f.has(ee)||(fe="Server sent an invalid subprotocol"):fe="Server sent a subprotocol but none was requested":f.size&&(fe="Server sent no subprotocol"),fe){k(e,S,fe);return}ee&&(e._protocol=ee);let ur=m.headers["sec-websocket-extensions"];if(ur!==void 0){if(!h){k(e,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let yt;try{yt=ps(ur)}catch{k(e,S,"Invalid Sec-WebSocket-Extensions header");return}let dr=Object.keys(yt);if(dr.length!==1||dr[0]!==W.extensionName){k(e,S,"Server indicated an extension that was not requested");return}try{h.accept(yt[W.extensionName])}catch{k(e,S,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[W.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 Je(e,t){e._readyState=b.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function _s(e){return e.path=e.socketPath,Yr.connect(e)}function ys(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=Yr.isIP(e.host)?"":e.host),ts.connect(e)}function k(e,t,r){e._readyState=b.CLOSING;let n=new Error(r);Error.captureStackTrace(n,k),t.setHeader?(t[Xr]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(Je,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function Ft(e,t,r){if(t){let n=os(t)?t.size:ms(t).length;e._socket?e._sender._bufferedBytes+=n:e._bufferedAmount+=n}if(r){let n=new Error(`WebSocket is not open: readyState ${e.readyState} (${U[e.readyState]})`);process.nextTick(r,n)}}function bs(e,t){let r=this[w];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,r._socket[w]!==void 0&&(r._socket.removeListener("data",Ke),process.nextTick(en,r._socket),e===1005?r.close():r.close(e,t))}function Ss(){let e=this[w];e.isPaused||e._socket.resume()}function vs(e){let t=this[w];t._socket[w]!==void 0&&(t._socket.removeListener("data",Ke),process.nextTick(en,t._socket),t.close(e[fs])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function Kr(){this[w].emitClose()}function Es(e,t){this[w].emit("message",e,t)}function ws(e){let t=this[w];t._autoPong&&t.pong(e,!this._isServer,Zr),t.emit("ping",e)}function xs(e){this[w].emit("pong",e)}function en(e){e.resume()}function Ts(e){let t=this[w];t.readyState!==b.CLOSED&&(t.readyState===b.OPEN&&(t._readyState=b.CLOSING,tn(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function tn(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),e._closeTimeout)}function rn(){let e=this[w];if(this.removeListener("close",rn),this.removeListener("data",Ke),this.removeListener("end",nn),e._readyState=b.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[w]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",Kr),e._receiver.on("finish",Kr))}function Ke(e){this[w]._receiver.write(e)||this.pause()}function nn(){let e=this[w];e._readyState=b.CLOSING,e._receiver.end(),this.end()}function sn(){let e=this[w];this.removeListener("error",sn),this.on("error",Zr),e&&(e._readyState=b.CLOSING,this.destroy())}});var fn=T((zo,cn)=>{"use strict";var Ho=Ye(),{Duplex:ks}=require("stream");function an(e){e.emit("close")}function Cs(){!this.destroyed&&this._writableState.finished&&this.destroy()}function ln(e){this.removeListener("error",ln),this.destroy(),this.listenerCount("error")===0&&this.emit("error",e)}function Os(e,t){let r=!0,n=new ks({...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(an,n);return}let o=!1;e.once("error",function(l){o=!0,s(l)}),e.once("close",function(){o||s(i),process.nextTick(an,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",ln),n}cn.exports=Os});var Wt=T((Jo,un)=>{"use strict";var{tokenChars:As}=ie();function Ns(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&&As[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}un.exports={parse:Ns}});var yn=T((Yo,_n)=>{"use strict";var Ps=require("events"),Ze=require("http"),{Duplex:Ko}=require("stream"),{createHash:Is}=require("crypto"),dn=He(),K=ne(),Ds=Wt(),Ls=Ye(),{CLOSE_TIMEOUT:Rs,GUID:$s,kWebSocket:Ms}=$(),Bs=/^[+/0-9A-Za-z]{22}==$/,hn=0,pn=1,gn=2,qt=class extends Ps{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:Rs,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Ls,...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=Ze.createServer((n,i)=>{let s=Ze.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=Us(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=hn}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===gn){t&&this.once("close",()=>{t(new Error("The server is not running"))}),process.nextTick(ve,this);return}if(t&&this.once("close",t),this._state!==pn)if(this._state=pn,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(ve,this):process.nextTick(ve,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ve(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",mn);let s=t.headers["sec-websocket-key"],o=t.headers.upgrade,a=+t.headers["sec-websocket-version"];if(t.method!=="GET"){Y(this,t,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){Y(this,t,r,400,"Invalid Upgrade header");return}if(s===void 0||!Bs.test(s)){Y(this,t,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){Y(this,t,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(t)){Ee(r,400);return}let l=t.headers["sec-websocket-protocol"],c=new Set;if(l!==void 0)try{c=Ds.parse(l)}catch{Y(this,t,r,400,"Invalid Sec-WebSocket-Protocol header");return}let u=t.headers["sec-websocket-extensions"],d={};if(this.options.perMessageDeflate&&u!==void 0){let f=new K({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let h=dn.parse(u);h[K.extensionName]&&(f.accept(h[K.extensionName]),d[K.extensionName]=f)}catch{Y(this,t,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let f={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(f,(h,g,m,S)=>{if(!h)return Ee(r,g||401,m,S);this.completeUpgrade(d,s,c,t,r,n,i)});return}if(!this.options.verifyClient(f))return Ee(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[Ms])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>hn)return Ee(s,503);let c=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Is("sha1").update(r+$s).digest("base64")}`],u=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}`),u._protocol=d)}if(t[K.extensionName]){let d=t[K.extensionName].params,f=dn.format({[K.extensionName]:[d]});c.push(`Sec-WebSocket-Extensions: ${f}`),u._extensions=t}this.emit("headers",c,i),s.write(c.concat(`\r
|
|
3
3
|
`).join(`\r
|
|
4
|
-
`)),
|
|
5
|
-
`+Object.keys(
|
|
4
|
+
`)),s.removeListener("error",mn),u.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(u),u.on("close",()=>{this.clients.delete(u),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ve,this)})),a(u,i)}};_n.exports=qt;function Us(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 ve(e){e._state=gn,e.emit("close")}function mn(){this.destroy()}function Ee(e,t,r,n){r=r||Ze.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} ${Ze.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
|
-
data: ${
|
|
8
|
+
`+r)}function Y(e,t,r,n,i,s){if(e.listenerCount("wsClientError")){let o=new Error(i);Error.captureStackTrace(o,Y),e.emit("wsClientError",o,r,t)}else Ee(r,n,i,s)}});var js,Fs,Ws,qs,Gs,Vs,Hs,Gt,bn=y(()=>{js=j(fn(),1),Fs=j(He(),1),Ws=j(ne(),1),qs=j(Dt(),1),Gs=j($t(),1),Vs=j(Wt(),1),Hs=j(Ye(),1),Gt=j(yn(),1)});function Sn(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}function Xe(e,t,r){return{id:e,kind:"response",error:{code:t,message:r}}}var ce=y(()=>{"use strict"});function En(e){return String(e?Math.floor(1e5+e()*9e5):(0,et.randomInt)(1e5,1e6))}var et,q,wn,Qe,xn=y(()=>{"use strict";et=require("node:crypto"),q=require("node:fs"),wn=require("node:path");ce();Qe=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,q.existsSync)(this.persistPath))try{let r=JSON.parse((0,q.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,q.mkdirSync)((0,wn.dirname)(this.persistPath),{recursive:!0}),(0,q.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=En(s),c=0;for(;this.sessions.has(l)&&c++<100;)l=En(s);if(this.sessions.has(l))throw Object.assign(new Error("RATE_LIMITED: code space exhausted"),{code:"RATE_LIMITED"});let u=String(r??"agent").slice(0,64)||"agent",d=(Array.isArray(n)?n:[]).map(String).slice(0,8),f={code:l,deviceId:t,clientName:u,scopes:d,createdAt:i,expiresAt:i+6e5,approved:!1};return this.sessions.set(l,f),this.lastRequestAt.set(t,i),f}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,et.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 tt,Tn=y(()=>{"use strict";ce();tt=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=Sn(),l={id:a,kind:"request",method:r,params:n,agentName:s?.agentName};return new Promise((c,u)=>{let d=setTimeout(()=>{this.pending.delete(a),u(Object.assign(new Error(`TIMEOUT waiting for device ${t}`),{code:"TIMEOUT"}))},i);d.unref?.(),this.pending.set(a,{deviceId:t,resolve:c,reject:u,timer:d});try{o(JSON.stringify(l))}catch(f){this.pending.delete(a),clearTimeout(d),u(f instanceof Error?f:new Error(String(f)))}})}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}}});function Xs(e){let t=new URL(e.url??"/","http://localhost");return e.method==="POST"&&t.pathname==="/mcp"}async function kn(e,t,r){if(!Xs(e))return!1;let n=r.pairings.verifyToken(he(e.headers.authorization)??"");if(!n)return I(t,e,null,{error:{code:-32001,message:"Unauthorized: invalid or missing pairing token"}},401);let i;try{i=await ue(e)}catch(o){return I(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 I(t,e,s.id??null,{error:{code:-32600,message:"Invalid JSON-RPC request"}},400);if(s.method==="initialize")return I(t,e,s.id??null,{result:{protocolVersion:Zs,capabilities:{tools:{}},serverInfo:{name:"babtab-relay",version:"0.2.0"}}});if(s.method.startsWith("notifications/"))return t.writeHead(202).end(),!0;if(s.method==="tools/list")return I(t,e,s.id??null,{result:{tools:de.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(!x(a))return I(t,e,s.id??null,{result:rt("Tool arguments must be an object")});let l=$e(o);if(!l)return I(t,e,s.id??null,{result:rt(`Unknown tool: ${o}`)});if(!pe(n,l.scope))return I(t,e,s.id??null,{result:rt(`Token lacks scope ${l.scope} for ${o}`)});try{let c=await r.registry.routeToDevice(n.deviceId,o,a,13e4,{agentName:n.clientName}),u=[];if(o==="browser_screenshot"&&x(c)&&typeof c.dataUrl=="string"){let h=/^data:(image\/(?:jpeg|png|webp));base64,([A-Za-z0-9+/=]+)$/.exec(c.dataUrl);h&&u.push({type:"image",mimeType:h[1],data:h[2]})}let d=Vt(c),f=JSON.stringify(d)??"null";return u.push({type:"text",text:f.length<=64e3?f:JSON.stringify({truncated:!0,originalLength:f.length,preview:f.slice(0,3e4)})}),I(t,e,s.id??null,{result:{content:u,...x(c)&&c.ok===!1?{isError:!0}:{}}})}catch(c){let u=c;return I(t,e,s.id??null,{result:rt(`${u.code??"DISCONNECTED"}: ${u.message}`,!0)})}}return I(t,e,s.id??null,{error:{code:-32601,message:`Method not found: ${s.method}`}},404)}function rt(e,t=!1){return{content:[{type:"text",text:e}],isError:!0,_meta:{retryable:t}}}function I(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
|
|
9
|
+
data: ${s}
|
|
10
10
|
|
|
11
|
-
`),!0):(
|
|
11
|
+
`),!0):(e.writeHead(i,{"content-type":"application/json","access-control-allow-origin":"*"}),e.end(s),!0)}function Vt(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Vt);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]=Vt(n)}return t}var Zs,Cn=y(()=>{"use strict";Re();me();Me();ce();Zs="2024-11-05"});function it(e={}){let t=new Qe({persistPath:e.tokenFile??process.env.BABTAB_TOKEN_FILE??"./data/relay-tokens.json"}),r=new tt,n,i=!1,s=new Map,o=new Map,a=(0,On.createServer)((f,h)=>{if(i){h.writeHead(503).end();return}eo(f,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 Gt.default({server:a,maxPayload:8*1024*1024});l.on("error",()=>{}),l.on("connection",(f,h)=>{if(f.on("error",()=>f.terminate()),i){f.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(()=>f.close(1008,"device authentication required"),5e3);S.unref(),f.once("close",()=>clearTimeout(S)),f.once("message",E=>{clearTimeout(S);let O;try{O=JSON.parse(String(E))}catch{f.close(1008,"invalid authentication");return}if(!x(O)||O.kind!=="authenticate"||!no(m,O.token)){f.close(1008,"invalid device credential");return}let G=s.get(m);s.set(m,f),to(f,m,t,r),G?.close(1008,"device reconnected"),f.once("close",()=>{s.get(m)===f&&s.delete(m)}),f.send(JSON.stringify({kind:"authenticated"}))})}else if(g.pathname==="/client"){let m=g.searchParams.get("token")??"";o.set(f,m),f.once("close",()=>o.delete(f)),ro(f,m,t,r)}else f.close(1008,"unknown path")});let c=setInterval(()=>{for(let f of l.clients){let h=o.get(f);if(h&&!t.verifyToken(h)){f.close(1008,"token expired or revoked");continue}if(f.isAlive===!1){f.terminate();continue}f.isAlive=!1,f.ping()}},2e4);c.unref?.(),l.on("connection",f=>{f.isAlive=!0,f.on("pong",()=>{f.isAlive=!0})});let u=e.port??0;t.onRevoke(f=>{for(let[h,g]of o)g===f&&h.close(1008,"token revoked")}),a.listen(u,e.host??"127.0.0.1");let d;return n={server:a,pairings:t,registry:r,close:()=>d??=new Promise((f,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,O)=>a.close(G=>G?O(G):E())),S=new Promise(E=>l.close(()=>E()));Promise.all([m,S]).then(()=>{clearTimeout(g),f()},E=>{clearTimeout(g),h(E)})})},n}async function eo(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,service:"babtab-relay",bridgeVersion:1,devices:r.registry.onlineDevices().length});return}if(e.method==="GET"&&n.pathname==="/client/status"){let s=r.pairings.verifyToken(he(e.headers.authorization)??"");if(!s){i(401,{error:"Unauthorized"});return}i(200,{deviceOnline:r.registry.isDeviceOnline(s.deviceId)});return}if(e.method==="POST"&&n.pathname==="/pairing/request"){let s=await ue(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 ue(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(()=>(me(),pr)),o=s(e.headers.authorization)??"",a=o?r.pairings.revokeToken(o):!1;i(200,{ok:a});return}await kn(e,t,r)||i(404,{error:"not found"})}function to(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(!An(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(Xe(a.id,"UNSUPPORTED_OPERATION",`Unknown device method ${a.method}`)))}}}),e.on("close",()=>n.unregisterDevice(t,i))}function ro(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(!An(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=$e(o.method);if(!l||!pe(a,l.scope)){e.send(JSON.stringify(Xe(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(Xe(o.id,c.code??"DISCONNECTED",c.message)))})})}function no(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,nt.createHash)("sha256").update(t).digest();return(0,nt.timingSafeEqual)(r,Buffer.from(e.slice(7),"hex"))}function An(e){return x(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||x(e.params)):e.kind==="response"&&(e.error===void 0||x(e.error)&&typeof e.error.code=="string"&&typeof e.error.message=="string"):!1}var nt,On,Ht=y(()=>{"use strict";nt=require("node:crypto");Re();Me();me();On=require("node:http");bn();ce();xn();Tn();me();Cn()});var In={};vt(In,{LocalBridge:()=>ot,parseBridgeArgs:()=>io,runStdio:()=>so});function io(e){let t="",r="agent",n=3e3;for(let i=0;i<e.length;i++){let s=e[i],o=e[++i];if(!o||o.startsWith("--"))throw new Error(`Missing value for ${s}`);if(s==="--device")t=o;else if(s==="--client")r=o;else if(s==="--port")n=Number(o);else throw new Error(`Unknown option: ${s}`)}if(!/^dev_v2_[a-f0-9]{64}$/.test(t))throw new Error("A valid --device is required. Copy setup from the Babtab extension.");if(!Number.isInteger(n)||n<1||n>65535)throw new Error("Invalid --port: expected 1-65535");if(!/^[a-z0-9-]{1,64}$/i.test(r))throw new Error("Invalid --client name");return{deviceId:t,clientName:r,port:n}}async function so(e,t=process.stdin,r=process.stdout){let n=new ot(e,d=>process.stderr.write(`[babtab] ${d}
|
|
12
|
+
`)),i=setInterval(()=>{n.tick()},2e3);n.tick();let s=(d,f)=>r.write(`${JSON.stringify({jsonrpc:"2.0",id:d,...f})}
|
|
13
|
+
`),o=!1,a=()=>{},l=async d=>{let f;try{f=JSON.parse(d)}catch{s(null,{error:{code:-32700,message:"Parse error"}});return}if(!x(f)||f.jsonrpc!=="2.0"||typeof f.method!="string"||f.id!==void 0&&typeof f.id!="string"&&typeof f.id!="number"){s(null,{error:{code:-32600,message:"Invalid Request"}});return}if(f.id!==void 0)if(f.method==="initialize")s(f.id,{result:{protocolVersion:"2024-11-05",capabilities:{tools:{}},serverInfo:{name:"babtab",version:"0.2.0"},instructions:"If browser tools report pairing is needed, ask the user to open Babtab in Chrome and approve the connection."}});else if(f.method==="ping")s(f.id,{result:{}});else if(f.method==="tools/list")s(f.id,{result:{tools:de.map(({name:h,description:g,inputSchema:m})=>({name:h,description:g,inputSchema:m}))}});else if(f.method==="tools/call"){let h=await n.call(f);o||s(f.id,h.error?{error:h.error}:{result:h.result})}else s(f.id,{error:{code:-32601,message:`Method not found: ${f.method}`}})},c="";t.setEncoding("utf8");let u=d=>{c+=d;let f;for(;(f=c.indexOf(`
|
|
14
|
+
`))!==-1;){let h=c.slice(0,f);if(c=c.slice(f+1),Buffer.byteLength(h)>1048576){t.destroy(new Error("MCP message too large"));return}h.trim()&&l(h)}Buffer.byteLength(c)>1048576&&t.destroy(new Error("MCP message too large"))};try{await new Promise(d=>{a=()=>d(),t.on("data",u),t.once("end",a),t.once("close",a),t.once("error",a),process.once("SIGTERM",a),process.once("SIGINT",a)})}finally{o=!0,clearInterval(i),t.off("data",u),t.off("end",a),t.off("close",a),t.off("error",a),process.off("SIGTERM",a),process.off("SIGINT",a),t.pause(),await n.close()}}var Nn,D,Pn,st,ot,Dn=y(()=>{"use strict";Nn=require("node:crypto"),D=require("node:fs"),Pn=require("node:os"),st=require("node:path");Ht();Re();Me();ce();ot=class{opts;log;owned;token="";pending;tickPromise;stopped=!1;relayReady=!1;abort=new AbortController;nextPairAt=0;dataDir;credentialPath;base;status="Open Babtab in Chrome and approve the connection.";constructor(t,r){this.opts=t,this.log=r,this.base=`http://127.0.0.1:${t.port}`,this.dataDir=t.dataDir??process.env.BABTAB_DATA_DIR??(0,st.join)((0,Pn.homedir)(),".babtab");let n=(0,Nn.createHash)("sha256").update(`${this.base}/${t.deviceId}/${t.clientName}`).digest("hex");this.credentialPath=(0,st.join)(this.dataDir,`client-${n}.json`);try{let i=JSON.parse((0,D.readFileSync)(this.credentialPath,"utf8"));x(i)&&typeof i.token=="string"&&(this.token=i.token)}catch{}}async request(t,r,n){let i=new AbortController,s=()=>i.abort(),o=setTimeout(s,t==="/mcp"?135e3:1500);this.abort.signal.addEventListener("abort",s,{once:!0}),this.abort.signal.aborted&&s();try{return await fetch(`${this.base}${t}`,{method:r===void 0?"GET":"POST",headers:{"content-type":"application/json",...n?{authorization:`Bearer ${n}`}:{}},...r===void 0?{}:{body:JSON.stringify(r)},signal:i.signal,redirect:"error"})}finally{clearTimeout(o),this.abort.signal.removeEventListener("abort",s)}}async ensureRelay(){try{let r=await this.request("/health"),n=await r.json().catch(()=>null);if(!r.ok||!x(n)||n.service!=="babtab-relay"||n.bridgeVersion!==1)throw new Error(`Port ${this.opts.port} is in use by another service or an older Babtab. Stop the old relay or choose another port in Advanced connection settings.`);return}catch(r){if(!(r instanceof TypeError)&&!(r instanceof Error&&r.name==="AbortError"))throw r}if(this.stopped)return;(0,D.mkdirSync)(this.dataDir,{recursive:!0,mode:448});let t=it({port:this.opts.port,tokenFile:(0,st.join)(this.dataDir,"relay-tokens.json")});try{await new Promise((r,n)=>{t.server.once("listening",r),t.server.once("error",n)}),this.owned=t}catch(r){throw await t.close().catch(()=>{}),r.code!=="EADDRINUSE"?r:new Error("Waiting for the local bridge to start\u2026")}}tick(){return this.tickPromise??=this.update().finally(()=>{this.tickPromise=void 0})}async update(){if(!this.stopped){this.relayReady=!1;try{if(await this.ensureRelay(),this.stopped)return;if(this.relayReady=!0,this.token){let n=await this.request("/client/status",void 0,this.token);if(n.status===401)this.token="";else{if(!n.ok)throw new Error(`Connection check failed: HTTP ${n.status}`);let i=await n.json();this.status=i.deviceOnline?"Connected":"Open Chrome and Babtab to reconnect your browser.";return}}if(this.pending&&Date.now()<this.pending.expiresAt){let n=await this.request("/pairing/claim",{code:this.pending.code}),i=await n.json();if(n.ok&&i.status==="approved"&&i.token){this.token=i.token,this.pending=void 0,(0,D.mkdirSync)(this.dataDir,{recursive:!0,mode:448});let s=`${this.credentialPath}.${process.pid}.tmp`;(0,D.writeFileSync)(s,JSON.stringify({token:this.token}),{mode:384}),(0,D.chmodSync)(s,384),(0,D.renameSync)(s,this.credentialPath),this.status="Connected",this.log("Browser paired. Babtab is ready.")}else i.status==="expired"&&(this.pending=void 0);return}if(Date.now()<this.nextPairAt)return;let t=await this.request("/pairing/request",{deviceId:this.opts.deviceId,clientName:this.opts.clientName,scopes:["browser:read","browser:act"]});if(this.nextPairAt=Date.now()+5e3,!t.ok)throw new Error(`Pairing failed: HTTP ${t.status}`);let r=await t.json();this.pending=r,this.status=`Open Babtab in Chrome and approve ${this.opts.clientName} (code ${r.code}).`,this.log(this.status)}catch(t){this.relayReady=!1;let r=t.message;this.status!==r&&this.log(r),this.status=r}}}async call(t){if(await this.tick(),!this.relayReady||!this.token)return{result:{isError:!0,content:[{type:"text",text:this.status}]}};try{let r=await this.request("/mcp",t,this.token);if(r.status===401)throw this.token="",this.tick(),new Error("Pairing expired or was revoked. Open Babtab and approve the new connection.");let n=await r.json();if(!x(n))throw new Error("Invalid response from Babtab");return n}catch(r){return{result:{isError:!0,content:[{type:"text",text:r.message}]}}}}async close(){this.stopped=!0,this.abort.abort(),await this.tickPromise,await this.owned?.close()}}});function at(){let e=(0,Rn.homedir)();return{platform:process.platform,home:e,appData:process.env.APPDATA??(0,v.join)(e,"AppData","Roaming"),localAppData:process.env.LOCALAPPDATA??(0,v.join)(e,"AppData","Local")}}function Ln(e,t){let r=t?"Code - Insiders":"Code";return e.platform==="win32"?(0,v.join)(e.appData,r,"User"):e.platform==="darwin"?(0,v.join)(e.home,"Library","Application Support",r,"User"):(0,v.join)(e.home,".config",r,"User")}function oo(e){return e.platform==="win32"?(0,v.join)(e.appData,"Claude","claude_desktop_config.json"):e.platform==="darwin"?(0,v.join)(e.home,"Library","Application Support","Claude","claude_desktop_config.json"):(0,v.join)(e.home,".config","Claude","claude_desktop_config.json")}function $n(e){let t=e.trim().toLowerCase();return we.find(r=>r.id===t||r.aliases.includes(t))}function lt(e,t){return{url:`${e}/mcp`,headers:{Authorization:`Bearer ${t}`}}}function zt(e,t){return{type:"http",...lt(e,t)}}function Jt(e,t){return{command:"npx",args:["-y","mcp-remote",`${e}/mcp`,"--allow-http","--header",`Authorization:Bearer ${t}`]}}function Mn(e,t,r){switch(e){case"copilot-http":return zt(t,r);case"stdio-remote":return Jt(t,r);case"http":default:return lt(t,r)}}function Bn(e,t){return`url = ${JSON.stringify(`${e}/mcp`)}
|
|
15
|
+
http_headers = { "Authorization" = ${JSON.stringify(`Bearer ${t}`)} }`}function Un(e,t){return`mcp_servers:
|
|
16
|
+
babtab:
|
|
17
|
+
url: "${e}/mcp"
|
|
18
|
+
headers:
|
|
19
|
+
Authorization: "Bearer ${t}"`}function jn(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 Rn,v,we,Kt=y(()=>{"use strict";Rn=require("node:os"),v=require("node:path");we=[{id:"cursor",label:"Cursor",aliases:[],paths:e=>[(0,v.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,v.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,v.join)(Ln(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,v.join)(Ln(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,v.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=>[oo(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,v.join)(e.home,".gemini","antigravity","mcp_config.json"),(0,v.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,v.join)(e.appData,"devin","mcp_config.json")]:[(0,v.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,v.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,v.join)(e.home,".hermes","config.yaml"),(0,v.join)(e.localAppData,"hermes","config.yaml")]:[(0,v.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 ao(e,t){let r=e.slice(0,t).split(/\r?\n/);return[r.length,r.pop().length+1]}function lo(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+=`
|
|
20
|
+
`,o===t&&(i+=" ".repeat(s+r+2),i+=`^
|
|
21
|
+
`))}return i}var p,X=y(()=>{p=class e extends Error{line;column;codeblock;constructor(t,r){let[n,i]=ao(r.toml,r.ptr),s=lo(r.toml,n,i);super(`Invalid TOML document: ${t}
|
|
22
|
+
|
|
23
|
+
${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 ct(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,u=0,d=r===120?2:r===117?4:8;for(let f=0;f<d;f++,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),u=u<<4|g}(u<0||u>1114111||u>=55296&&u<=57343)&&p.x("invalid unicode escape",e,c),o+=String.fromCodePoint(u),a=e.p--,l=0}else s&&(r===32||r===9)?l=2:(r===98?o+="\b":r===116?o+=" ":r===110?o+=`
|
|
24
|
+
`: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 Yt=y(()=>{X();});var co,xe,Zt=y(()=>{co=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,xe=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(co);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 C(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function Qt(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function ke(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?qn(e):Wn(e);return e.d++,i}return n===34||n===39?ct(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?ft(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?fo(e,n,t):e.s.charCodeAt(e.p+2)===58?uo(e,n,t):ft(e,e.p,n,0,t)}function ft(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||Qt(s=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!n){if(s===120)return Xt(e,t,16,i);if(s===98)return Xt(e,t,2,i);if(s===111)return Xt(e,t,8,i)}s===46?o=2:s===101||s===69?o=4:p.x("illegal leading zero",e,t)}else C(s)||p.x("invalid value",e,t);for(;++e.p<e.s.length&&(s=e.s.charCodeAt(e.p),!Qt(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)||(C(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):Fn(e,l,10,t)}function Xt(e,t,r,n){let i,s=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!Qt(i,n));)i===95?(s&1&&p.x("illegal underscore",e),s=3):C(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("_","")),Fn(e,o,r,t)}function Fn(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 fo(e,t,r){let n=e.p++,i;if(!C(t)||!C(e.s.charCodeAt(e.p++))||!C(e.s.charCodeAt(e.p++))||!C(e.s.charCodeAt(e.p++)))return ft(e,e.p=n,t,0,r);if(e.p+=5,C(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,!C(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let o=e.s.slice(n,e.p);return Te(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(;C(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 Te(e,o,1,i,n,"[+00:00]")}if(t===43||t===45){let o=e.s.slice(n,e.p+=6);return Te(e,o,1,i,n,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let s=e.s.slice(n,e.p);return Te(e,s,2,i,n)}function uo(e,t,r){let n=e.p;if(!C(t)||!C(e.s.charCodeAt(++e.p)))return ft(e,--e.p,t,0,r);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;C(e.s.charCodeAt(++e.p)););let i=e.s.slice(n,e.p);return Te(e,i,4,!1,n)}function Te(e,t,r,n,i,s){if(e.ld){let o=new xe(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 er=y(()=>{Yt();tr();X();Zt();});function ho(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 L(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;ho(e)}}var rr=y(()=>{X();});function ut(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(ct(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 Wn(e){let t=e.p++,r=Object.create(null),n=new Set,i;for(;e.p<e.s.length;){if(L(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,r;let s,o=r,a=!1,l=e.p,c=ut(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 f=s==="__proto__";if(e.uk&&(f||s==="constructor")){o=e.uk!==1&&p.x("document contains an unsafe property",e,l);break}!a&&f&&Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}a&&p.x("trying to redefine an already defined value",e,l),L(e,!0,!0);let u=ke(e,125);if(o&&typeof(o[s]=u)=="object"&&n.add(u),L(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 qn(e){let t=e.p++,r=[],n;for(;e.p<e.s.length;){if(L(e),(n=e.s.charCodeAt(e.p))===93)return e.p++,r;if(r.push(ke(e,93)),L(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 tr=y(()=>{Yt();er();rr();X();});function Gn(e,t,r,n,i){let s=r,o=n,a,l=!1,c;for(let u=0;u<t.length;u++){if(u){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[u],(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:u<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 Vn(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 Ce(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++,L(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 u=ut(r,93);c&&(e.charCodeAt(r.p)!==93&&p.x("expected end of table array declaration",r),r.p++);let d=Gn(r,u,n,i,c?2:1);d?(l=d[2],a=d[1]):(Vn(r,d,s),o=!0)}else{s=r.p;let c=ut(r),u=Gn(r,c,a,l,0);!u&&!o&&Vn(r,u,s),L(r,!0,!0);let d=ke(r,void 0);u&&!o&&(u[1][u[0]]=d)}L(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),L(r)}return n}var Hn=y(()=>{tr();er();rr();X();});function Oe(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 mo(e){for(let t=0;t<e.length;t++)if(Oe(e[t])!=="object")return!1;return e.length!=0}function Jn(e){return JSON.stringify(e).replaceAll("\x7F","\\u007f")}function go(e){return Jn(zn?e.toWellFormed():e)}function Kn(e){if(po.test(e))return e;if(zn&&!e.isWellFormed())throw new RangeError("key contains illegal lone surrogates");return Jn(e)}function nr(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 go(e);case"date":if(isNaN(e.getTime()))throw new TypeError("cannot serialize invalid date");return e.toISOString();case"object":return _o(e,r,n,i);case"array":return yo(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 _o(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+=Kn(a)+" = "+nr(e[a],Oe(e[a]),t-1,r,n)}return s+" }"}function yo(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+=nr(e[s],Oe(e[s]),t-1,r,n)}return i+" ]"}function bo(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&&`
|
|
25
|
+
`}[[${t}]]
|
|
26
|
+
`,s+=ir(0,e[o],t,r,n,i);return s}function ir(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 u=l[c];if(t[u]!==null&&t[u]!==void 0){let d=Oe(t[u]);if(d==="symbol"||d==="function")throw new TypeError(`cannot serialize values of type '${d}'`);let f=Kn(u);if(d==="array"&&mo(t[u]))a+=(a&&`
|
|
27
|
+
`)+bo(t[u],r?`${r}.${f}`:f,n-1,i,s);else if(d==="object"){let h=r?`${r}.${f}`:f;a+=(a&&`
|
|
28
|
+
`)+ir(h,t[u],h,n-1,i,s)}else o+=f,o+=" = ",o+=nr(t[u],d,n,i,s),o+=`
|
|
29
|
+
`}}return e&&(o||!a)&&(o=o?`[${e}]
|
|
30
|
+
${o}`:`[${e}]`),o&&a?`${o}
|
|
31
|
+
${a}`:o||a}function sr(e,{maxDepth:t=1e3,numbersAsFloat:r=!1,strictTemporal:n=!1}={}){if(Oe(e)!=="object")throw new TypeError("stringify can only be called with an object");let i=ir(0,e,"",t,r,n);return i[i.length-1]!==`
|
|
32
|
+
`?i+`
|
|
33
|
+
`:i}var po,zn,Yn=y(()=>{po=/^[a-z0-9-_]+$/i,zn=!!"".isWellFormed});var Zn=y(()=>{Hn();Yn();Zt();X();});function ht(e,t){let r=e.paths(t);if(r.length===0)return null;for(let n of r)try{if((0,_.statSync)((0,Ae.dirname)(n)).isDirectory())return n}catch{}return r[0]}function So(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]!==`
|
|
34
|
+
`;)r++;continue}if(s==="/"&&o==="*"){for(r+=2;r<e.length&&!(e[r]==="*"&&e[r+1]==="/");)e[r]===`
|
|
35
|
+
`&&(t+=`
|
|
36
|
+
`),r++;r+=2;continue}t+=s,r++}return t}function dt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ne(e){try{return(0,_.existsSync)(e)?((0,_.writeFileSync)(`${e}.bak`,(0,_.readFileSync)(e)),!0):!1}catch{return!1}}function pt(e){let{path:t,rootKey:r,serverName:n,entry:i}=e,s=(0,_.existsSync)(t),o={};if(s){let c=(0,_.readFileSync)(t,"utf8"),u;try{u=JSON.parse(c.trim()===""?"{}":So(c))}catch{throw new Error(`Existing config is not valid JSON: ${t}
|
|
37
|
+
Fix or rename it first (setup left it untouched).`)}if(!dt(u))throw new Error(`Existing config root must be an object: ${t} (left untouched).`);o=u;let d=o[r];if(d!==void 0&&!dt(d))throw new Error(`Existing "${r}" is not an object: ${t} (left untouched).`)}let a=dt(o[r])?o[r]:{};a[n]=i,o[r]=a,(0,_.mkdirSync)((0,Ae.dirname)(t),{recursive:!0});let l=s?Ne(t):!1;return(0,_.writeFileSync)(t,`${JSON.stringify(o,null,2)}
|
|
38
|
+
`,{mode:384}),{path:t,created:!s,backedUp:l}}function mt(e,t){let r=(0,_.existsSync)(e),n=r?Ce((0,_.readFileSync)(e,"utf8")):{},i=Ce(`${vo}
|
|
39
|
+
${t}
|
|
40
|
+
`);if(n.mcp_servers!==void 0&&!dt(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=sr(n);Ce(o),(0,_.mkdirSync)((0,Ae.dirname)(e),{recursive:!0});let a=r?Ne(e):!1;if(r&&!a)throw new Error(`Cannot back up ${e}; left untouched`);let l=`${e}.${(0,Xn.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 gt(e,t){let r=(0,_.existsSync)(e),n;if(!r)n=`${t}
|
|
41
|
+
`;else{let s=(0,_.readFileSync)(e,"utf8").split(`
|
|
42
|
+
`),o=s.findIndex(a=>/^mcp_servers\s*:\s*(#.*)?$/.test(a));if(o===-1){let a=s.length>0&&s[s.length-1].trim()!==""?`
|
|
43
|
+
`:"";n=`${s.join(`
|
|
44
|
+
`)}${a}
|
|
45
|
+
${t}
|
|
46
|
+
`}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(f=>/^\s*babtab\s*:\s*(#.*)?$/.test(f)),u=t.split(`
|
|
47
|
+
`).slice(1).join(`
|
|
48
|
+
`),d;if(c===-1)d=[...l,u];else{let f=l[c].match(/^\s*/)?.[0].length??2,h=c+1;for(;h<l.length&&(l[h].trim()===""||(l[h].match(/^\s*/)?.[0].length??0)>f);)h++;d=[...l.slice(0,c),u,...l.slice(h)]}n=[...s.slice(0,o+1),...d,...s.slice(a)].join(`
|
|
49
|
+
`),n.endsWith(`
|
|
50
|
+
`)||(n+=`
|
|
51
|
+
`)}}(0,_.mkdirSync)((0,Ae.dirname)(e),{recursive:!0});let i=r?Ne(e):!1;return(0,_.writeFileSync)(e,n,{mode:384}),{path:e,created:!r,backedUp:i}}var Xn,_,Ae,vo,or=y(()=>{"use strict";Zn();Xn=require("node:crypto"),_=require("node:fs"),Ae=require("node:path");vo="[mcp_servers.babtab]"});function wo(e,t,r){if(!/^dev_v2_[a-f0-9]{64}$/.test(e))throw new Error("Invalid device ID. Copy the command from the Babtab extension.");return{command:"npx",args:["-y",Eo,"stdio","--device",e,"--client",t,"--port",String(r)]}}function ei(e,t,r,n=at()){let i=wo(t,e.id,r),s=e.action;if(s.kind==="exec"){let o=["mcp","add","--transport","stdio","--scope","user","babtab","--",i.command,...i.args],a=(0,Qn.spawnSync)("claude",o,{stdio:"inherit",shell:process.platform==="win32"});if(a.error||a.status!==0)throw new Error("Could not add Babtab to Claude Code. Check that the claude CLI is installed; if babtab already exists, remove its old MCP entry and retry.")}else{let o=ht(e,n);if(!o)throw new Error(`Automatic setup is unavailable for ${e.label}`);s.kind==="json"?pt({path:o,rootKey:s.rootKey,serverName:"babtab",entry:{...i,...s.entry==="copilot-http"?{type:"stdio"}:{}}}):s.kind==="toml-codex"?mt(o,`command = ${JSON.stringify(i.command)}
|
|
52
|
+
args = ${JSON.stringify(i.args)}`):s.kind==="yaml-hermes"&>(o,`mcp_servers:
|
|
53
|
+
babtab:
|
|
54
|
+
command: ${JSON.stringify(i.command)}
|
|
55
|
+
args: ${JSON.stringify(i.args)}`),console.log(`Configured ${o} (existing settings preserved; backup created when replacing a file).`)}return console.log(`
|
|
56
|
+
${e.nextStep.replace(" (via mcp-remote bridge)","")}
|
|
57
|
+
Your AI tool starts Babtab automatically. Open Babtab in Chrome and approve the first connection.
|
|
58
|
+
Then ask: "Use babtab to observe the current tab".`),0}var Qn,Eo,ti=y(()=>{"use strict";Qn=require("node:child_process");Kt();or();Eo="@babtab/relay@0.2.0"});async function ri(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 Q(`Cannot reach relay at ${e}: ${String(s)}`)}let i={};try{i=await n.json()}catch{}return{status:n.status,json:i}}async function ar(e){let t;try{t=await fetch(`${e}/health`,{signal:AbortSignal.timeout(3e3)})}catch(n){throw new Q(`Cannot reach relay at ${e}/health: ${String(n)}`)}if(!t.ok)throw new Q(`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 ni(e,t,r){let{status:n,json:i}=await ri(`${e}/pairing/request`,{deviceId:t,clientName:r,scopes:["browser:read","browser:act"]},3e3);if(n===429)throw new Pe(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 ii(e,t,r={}){let n=r.intervalMs??2e3,i=r.timeoutMs??3e5,s=Date.now()+i;for(;;){let{json:o}=await ri(`${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 Ie("Pairing code expired \u2014 run the setup command again.");if(Date.now()>=s)throw new De("Timed out waiting for approval \u2014 run the setup command again.");await new Promise(l=>setTimeout(l,n))}}var Q,Pe,Ie,De,si=y(()=>{"use strict";Q=class extends Error{},Pe=class extends Error{},Ie=class extends Error{},De=class extends Error{}});var cr={};vt(cr,{DEFAULT_PORT:()=>Le,SERVER_NAME:()=>ai,VERIFY_SENTENCE:()=>_t,backupFile:()=>Ne,copilotJsonEntry:()=>zt,httpJsonEntry:()=>lt,listTargetCommands:()=>ci,parseSetupArgs:()=>li,runSetup:()=>To,setupHelp:()=>lr,stdioRemoteJsonEntry:()=>Jt});function li(e){let t={target:"",port:Number(process.env.PORT??Le),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 xo(e){let t=e.action.kind==="print"?"":" --device <deviceId>";return`npx -y @babtab/relay setup --target ${e.id} --port ${Le}${t}`}function lr(){return["babtab setup \u2014 configure your AI tool to start Babtab automatically","","Usage:"," npx -y @babtab/relay setup --target <id> --port <port> --device <deviceId>"," (Copy the exact line from the Babtab Side Panel \u2192 Other AI tools / install with a command; it has your port + device.)","","Targets:",we.map(t=>` ${t.id.padEnd(17)} ${t.label}`).join(`
|
|
59
|
+
`),"","Options:"," --target, -t <id> Harness to configure (required, see list above)",` --port, -p <n> Relay port (default ${Le}, or $PORT)`," --device, -d <id> Extension device id (from the Babtab extension)"," --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. Copy the setup command from the Babtab extension and run it once."," 2. Enable / reload MCP in your AI tool; it starts Babtab automatically."," 3. Open Babtab in Chrome and approve the first connection.",` 4. Ask: "${_t}".`," Remote --relay-url connections still require an already-running relay and pairing.",""].join(`
|
|
60
|
+
`)}function ci(){return we.map(e=>`# ${e.label}
|
|
61
|
+
${xo(e)}`).join(`
|
|
62
|
+
|
|
63
|
+
`)+`
|
|
64
|
+
`}function fi(e){return e===Le?"npx -y @babtab/relay":`PORT=${e} npx -y @babtab/relay`}async function To(e){let t;try{t=li(e)}catch(o){return console.error(`Error: ${o.message}
|
|
65
|
+
`),console.error(lr()),1}if(t.help)return console.log(lr()),0;if(t.listTargets)return console.log(ci()),0;let r=$n(t.target);if(!r)return console.error(`Error: unknown --target "${t.target}". Pick one of:
|
|
66
|
+
`),console.error(we.map(o=>` ${o.id}`).join(`
|
|
67
|
+
`)),1;let n=t.relayUrl??`http://127.0.0.1:${t.port}`;if(r.action.kind==="print")return ko(r,n,t);if(!t.deviceId)return console.error(`Error: --device is required.
|
|
68
|
+
Copy the full command from the Babtab Side Panel \u2192 Other AI tools / install with a command (it includes --device).`),1;if(!t.relayUrl)try{return ei(r,t.deviceId,t.port)}catch(o){return console.error(`Error: ${o.message}`),4}try{await ar(n)}catch(o){if(o instanceof Q)return console.error(`Error: relay is not reachable at ${n}.
|
|
69
|
+
Start it first in another terminal:
|
|
70
|
+
|
|
71
|
+
${fi(t.port)}
|
|
72
|
+
`),2;throw o}let i;try{let o=await ni(n,t.deviceId,r.id);if(!o.deviceOnline)return console.error(`Error: your Chrome is not connected to the relay.
|
|
73
|
+
Open Advanced connection settings and use Save & Connect first, then re-run this command.`),3;i=o.code}catch(o){return o instanceof Pe?(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 ii(n,i)}catch(o){return o instanceof Ie||o instanceof De?(console.error(`Error: ${o.message}`),3):(console.error(`Error: claim failed: ${o.message}`),3)}console.log("Approved \u2713");try{return Co(r,n,s)}catch(o){return console.error(`Error: ${o.message}`),4}}async function ko(e,t,r){if(e.action.kind!=="print")return 1;try{await ar(t)}catch{console.log(`Note: relay is not reachable at ${t} yet \u2014 start it with:
|
|
74
|
+
|
|
75
|
+
${fi(r.port)}
|
|
76
|
+
`)}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, choose Other AI tools \u2192 Manual to pair and copy a token."),console.log(` 2. Verify the relay with (replace <token>):
|
|
77
|
+
`),console.log(` ${jn(t,"<token>")}
|
|
78
|
+
`)):(console.log("Standard MCP (Streamable HTTP):"),console.log(` Endpoint: ${t}/mcp`),console.log(` Header: Authorization: Bearer <token>
|
|
79
|
+
`),console.log("Get a token: Side Panel \u2192 Other AI tools \u2192 Manual \u2192 Manual HTTP configuration (pairing runs automatically)."),console.log("Flow: initialize \u2192 tools/list \u2192 tools/call (JSON-RPC 2.0).")),0}function Co(e,t,r){let n=e.action;if(n.kind==="exec"){let l=n.argv(t,r),c=(0,oi.spawnSync)(l[0],l.slice(1),{stdio:"inherit",shell:process.platform==="win32"});if(c.error){let u=c.error.code==="ENOENT";return console.error(u?`The "${l[0]}" CLI was not found. Install it, then run:
|
|
80
|
+
|
|
81
|
+
${l.join(" ")}
|
|
82
|
+
`:`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(`
|
|
83
|
+
Configured ${e.label} \u2713`),console.log(e.nextStep),console.log(`Then ask: "${_t}".`),0)}let i=at(),s=ht(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=Mn(n.entry,t,r);({created:o,backedUp:a}=pt({path:s,rootKey:n.rootKey,serverName:ai,entry:l}))}else if(n.kind==="toml-codex")({created:o,backedUp:a}=mt(s,Bn(t,r)));else if(n.kind==="yaml-hermes")({created:o,backedUp:a}=gt(s,Un(t,r)));else return console.error(`Error: unsupported action for target "${e.id}".`),4;return console.log(`
|
|
84
|
+
Wrote ${s} ${o?"(created)":"(updated, babtab entry replaced)"} \u2713`),a&&console.log(`Backup: ${s}.bak`),console.log(e.nextStep),console.log(`Then ask: "${_t}".`),0}var oi,Le,ai,_t,fr=y(()=>{"use strict";oi=require("node:child_process");ti();Kt();or();si();Le=3e3,ai="babtab",_t="Use babtab to observe the current tab"});Ht();async function Oo(){let e=process.argv[2];if(e==="stdio"){let{runStdio:t,parseBridgeArgs:r}=await Promise.resolve().then(()=>(Dn(),In));await t(r(process.argv.slice(3)))}else if(e==="setup"){let{runSetup:t}=await Promise.resolve().then(()=>(fr(),cr));process.exitCode=await t(process.argv.slice(3))}else if(e==="help"||e==="--help"||e==="-h"){let{setupHelp:t}=await Promise.resolve().then(()=>(fr(),cr));console.log(`babtab-relay \u2014 local bridge between your AI agent and Chrome
|
|
85
|
+
|
|
86
|
+
Start the relay:
|
|
87
|
+
npx -y @babtab/relay (env: PORT=3000 BABTAB_TOKEN_FILE=./data/relay-tokens.json)
|
|
88
|
+
|
|
89
|
+
`+t())}else e!==void 0?(console.error(`Unknown command: ${e}
|
|
90
|
+
Run \`npx -y @babtab/relay help\` for usage.`),process.exitCode=1):Ao()}Oo().catch(e=>{console.error(`[babtab] ${e.message}`),process.exitCode=1});function Ao(){let e=Number(process.env.PORT??3e3),t=it({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)}
|
|
91
|
+
/*! Bundled license information:
|
|
92
|
+
|
|
93
|
+
smol-toml/dist/error.js:
|
|
94
|
+
(*!
|
|
95
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
96
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
97
|
+
*
|
|
98
|
+
* Redistribution and use in source and binary forms, with or without
|
|
99
|
+
* modification, are permitted provided that the following conditions are met:
|
|
100
|
+
*
|
|
101
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
102
|
+
* list of conditions and the following disclaimer.
|
|
103
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
104
|
+
* this list of conditions and the following disclaimer in the
|
|
105
|
+
* documentation and/or other materials provided with the distribution.
|
|
106
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
107
|
+
* may be used to endorse or promote products derived from this software without
|
|
108
|
+
* specific prior written permission.
|
|
109
|
+
*
|
|
110
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
111
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
112
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
113
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
114
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
115
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
116
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
117
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
118
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
119
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
120
|
+
*)
|
|
121
|
+
|
|
122
|
+
smol-toml/dist/primitive.js:
|
|
123
|
+
(*!
|
|
124
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
125
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
126
|
+
*
|
|
127
|
+
* Redistribution and use in source and binary forms, with or without
|
|
128
|
+
* modification, are permitted provided that the following conditions are met:
|
|
129
|
+
*
|
|
130
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
131
|
+
* list of conditions and the following disclaimer.
|
|
132
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
133
|
+
* this list of conditions and the following disclaimer in the
|
|
134
|
+
* documentation and/or other materials provided with the distribution.
|
|
135
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
136
|
+
* may be used to endorse or promote products derived from this software without
|
|
137
|
+
* specific prior written permission.
|
|
138
|
+
*
|
|
139
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
140
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
141
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
142
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
143
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
144
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
145
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
146
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
147
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
148
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
149
|
+
*)
|
|
150
|
+
|
|
151
|
+
smol-toml/dist/date.js:
|
|
152
|
+
(*!
|
|
153
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
154
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
155
|
+
*
|
|
156
|
+
* Redistribution and use in source and binary forms, with or without
|
|
157
|
+
* modification, are permitted provided that the following conditions are met:
|
|
158
|
+
*
|
|
159
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
160
|
+
* list of conditions and the following disclaimer.
|
|
161
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
162
|
+
* this list of conditions and the following disclaimer in the
|
|
163
|
+
* documentation and/or other materials provided with the distribution.
|
|
164
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
165
|
+
* may be used to endorse or promote products derived from this software without
|
|
166
|
+
* specific prior written permission.
|
|
167
|
+
*
|
|
168
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
169
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
170
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
171
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
172
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
173
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
174
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
175
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
176
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
177
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
178
|
+
*)
|
|
179
|
+
|
|
180
|
+
smol-toml/dist/extract.js:
|
|
181
|
+
(*!
|
|
182
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
183
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
184
|
+
*
|
|
185
|
+
* Redistribution and use in source and binary forms, with or without
|
|
186
|
+
* modification, are permitted provided that the following conditions are met:
|
|
187
|
+
*
|
|
188
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
189
|
+
* list of conditions and the following disclaimer.
|
|
190
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
191
|
+
* this list of conditions and the following disclaimer in the
|
|
192
|
+
* documentation and/or other materials provided with the distribution.
|
|
193
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
194
|
+
* may be used to endorse or promote products derived from this software without
|
|
195
|
+
* specific prior written permission.
|
|
196
|
+
*
|
|
197
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
198
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
199
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
200
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
201
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
202
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
203
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
204
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
205
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
206
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
207
|
+
*)
|
|
208
|
+
|
|
209
|
+
smol-toml/dist/util.js:
|
|
210
|
+
(*!
|
|
211
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
212
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
213
|
+
*
|
|
214
|
+
* Redistribution and use in source and binary forms, with or without
|
|
215
|
+
* modification, are permitted provided that the following conditions are met:
|
|
216
|
+
*
|
|
217
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
218
|
+
* list of conditions and the following disclaimer.
|
|
219
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
220
|
+
* this list of conditions and the following disclaimer in the
|
|
221
|
+
* documentation and/or other materials provided with the distribution.
|
|
222
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
223
|
+
* may be used to endorse or promote products derived from this software without
|
|
224
|
+
* specific prior written permission.
|
|
225
|
+
*
|
|
226
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
227
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
228
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
229
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
230
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
231
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
232
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
233
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
234
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
235
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
236
|
+
*)
|
|
237
|
+
|
|
238
|
+
smol-toml/dist/struct.js:
|
|
239
|
+
(*!
|
|
240
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
241
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
242
|
+
*
|
|
243
|
+
* Redistribution and use in source and binary forms, with or without
|
|
244
|
+
* modification, are permitted provided that the following conditions are met:
|
|
245
|
+
*
|
|
246
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
247
|
+
* list of conditions and the following disclaimer.
|
|
248
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
249
|
+
* this list of conditions and the following disclaimer in the
|
|
250
|
+
* documentation and/or other materials provided with the distribution.
|
|
251
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
252
|
+
* may be used to endorse or promote products derived from this software without
|
|
253
|
+
* specific prior written permission.
|
|
254
|
+
*
|
|
255
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
256
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
257
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
258
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
259
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
260
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
261
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
262
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
263
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
264
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
265
|
+
*)
|
|
266
|
+
|
|
267
|
+
smol-toml/dist/parse.js:
|
|
268
|
+
(*!
|
|
269
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
270
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
271
|
+
*
|
|
272
|
+
* Redistribution and use in source and binary forms, with or without
|
|
273
|
+
* modification, are permitted provided that the following conditions are met:
|
|
274
|
+
*
|
|
275
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
276
|
+
* list of conditions and the following disclaimer.
|
|
277
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
278
|
+
* this list of conditions and the following disclaimer in the
|
|
279
|
+
* documentation and/or other materials provided with the distribution.
|
|
280
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
281
|
+
* may be used to endorse or promote products derived from this software without
|
|
282
|
+
* specific prior written permission.
|
|
283
|
+
*
|
|
284
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
285
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
286
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
287
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
288
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
289
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
290
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
291
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
292
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
293
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
294
|
+
*)
|
|
295
|
+
|
|
296
|
+
smol-toml/dist/stringify.js:
|
|
297
|
+
(*!
|
|
298
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
299
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
300
|
+
*
|
|
301
|
+
* Redistribution and use in source and binary forms, with or without
|
|
302
|
+
* modification, are permitted provided that the following conditions are met:
|
|
303
|
+
*
|
|
304
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
305
|
+
* list of conditions and the following disclaimer.
|
|
306
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
307
|
+
* this list of conditions and the following disclaimer in the
|
|
308
|
+
* documentation and/or other materials provided with the distribution.
|
|
309
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
310
|
+
* may be used to endorse or promote products derived from this software without
|
|
311
|
+
* specific prior written permission.
|
|
312
|
+
*
|
|
313
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
314
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
315
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
316
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
317
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
318
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
319
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
320
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
321
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
322
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
323
|
+
*)
|
|
324
|
+
|
|
325
|
+
smol-toml/dist/index.js:
|
|
326
|
+
(*!
|
|
327
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
328
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
329
|
+
*
|
|
330
|
+
* Redistribution and use in source and binary forms, with or without
|
|
331
|
+
* modification, are permitted provided that the following conditions are met:
|
|
332
|
+
*
|
|
333
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
334
|
+
* list of conditions and the following disclaimer.
|
|
335
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
336
|
+
* this list of conditions and the following disclaimer in the
|
|
337
|
+
* documentation and/or other materials provided with the distribution.
|
|
338
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
339
|
+
* may be used to endorse or promote products derived from this software without
|
|
340
|
+
* specific prior written permission.
|
|
341
|
+
*
|
|
342
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
343
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
344
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
345
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
346
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
347
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
348
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
349
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
350
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
351
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
352
|
+
*)
|
|
353
|
+
*/
|