@babtab/relay 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/relay.cjs CHANGED
@@ -1,328 +1,105 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var ui=Object.create;var wt=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),pr=(e,t)=>{for(var r in t)wt(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&&wt(e,i,{get:()=>t[i],enumerable:!(n=hi(t,i))||n.enumerable});return e};var j=(e,t,r)=>(r=e!=null?ui(mi(e)):{},_i(t||!e||!e.__esModule?wt(r,"default",{value:e,enumerable:!0}):r,e));function x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function de(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 Le(e){return ue.find(t=>t.name===e)}var F,yi,De,bi,ue,Me=y(()=>{"use strict";F={type:"object",description:"Semantic target: durable ref (@Hxxxx) or role/name/region query. On AMBIGUOUS_TARGET, next call MUST use a ranked candidate ref or add region/nth/near.",properties:{ref:{type:"string",description:"Durable handle from find/observe (@Hxxxx)."},role:{type:"string"},name:{type:"string",description:"Exact accessible name."},nameContains:{type:"string"},label:{type:"string"},region:{type:"string",description:"Semantic region id (main, dialog, navigation, \u2026)."},nth:{type:"number",description:"1-based ordinal among ranked matches (disambiguates duplicates)."},near:{type:"string",description:"Soft proximity hint (nearby heading text or region id)."}}},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","boolean"],description:"Boolean for checked; string for URL/value conditions."},query:F,regionId:{type:"string"}},required:["type"],additionalProperties:!0},De={type:"array",description:"Strongly recommended for click/navigate. Without expect, success is dispatch_only (not business success). Prefer url_matches / element_appeared / value_equals.",items:yi},bi={type:"object",description:"Single guarded action contract.",properties:{action:{type:"string",enum:["click","fill","select","press","scroll","navigate","back","forward","hover","open_tab","close_tab"]},target:F,value:{type:"string"},key:{type:"string"},url:{type:"string"},tab:{type:["number","string"],description:"P2 multi-tab: explicit tab id or a plan-local ref bound by tabRef. Omit to run on the plan's current tab."},tabRef:{type:"string",description:"P2 multi-tab: bind this step's tab to a ref name for later steps."},active:{type:"boolean",description:"open_tab: focus the new tab (default true)."},expect:De,timeoutMs:{type:"number"}},required:["action"],additionalProperties:!0},ue=[{name:"browser_observe",description:"Pull-mode digest: default to page_digest (regions+counts ~100 tokens). Drill via browser_find or region_digest. level=full requires explicit need \u2014 prefer find. Returns recommendedNext + overBudget when useful.",inputSchema:{type:"object",properties:{level:{type:"string",enum:["page_digest","region_digest","interactive","full"],description:"Default page_digest. Avoid full."},regionId:{type:"string"},includeRecentDiff:{type:"boolean"},limit:{type:"number",description:"Cap for interactive[] (default 30, max 120)."}}},scope:"browser:read"},{name:"browser_find",description:"Pull-mode lookup: matching elements as durable refs. Prefer over observe level=full. Use nth/near/region when labels collide. On AMBIGUOUS, ranked candidates include score+region \u2014 next act MUST use ref.",inputSchema:{type:"object",properties:{role:{type:"string"},name:{type:"string"},nameContains:{type:"string"},region:{type:"string"},nth:{type:"number",description:"1-based ordinal among ranked matches."},near:{type:"string",description:"Nearby heading / region hint."}}},scope:"browser:read"},{name:"browser_click",description:"Click a semantic target (guarded). Strongly recommend expect (url_matches / element_appeared; element_* are delta checks vs pre-click state). Without expect, result.verifiedMode=dispatch_only.",inputSchema:{type:"object",properties:{target:F,expect:De},required:["target"]},scope:"browser:act"},{name:"browser_fill",description:"Fill a field and verify the value. Prefer expect value_equals when possible.",inputSchema:{type:"object",properties:{target:F,value:{type:"string"},expect:De},required:["target","value"]},scope:"browser:act"},{name:"browser_select",description:"Choose a select option.",inputSchema:{type:"object",properties:{target:F,value:{type:"string"}},required:["target","value"]},scope:"browser:act"},{name:"browser_press",description:"Press a key on a target or the focused element. Prefer for canvas editors (Docs/Sheets) over clicking tiles.",inputSchema:{type:"object",properties:{target:F,key:{type:"string"}}},scope:"browser:act"},{name:"browser_scroll",description:"Scroll a target into view or scroll the page. Use before re-find on virtualized lists.",inputSchema:{type:"object",properties:{target:F,direction:{type:"string"}}},scope:"browser:act"},{name:"browser_navigate",description:"Navigate the controlled tab (site grant required). Strongly recommend expect url_matches (URI-decoded).",inputSchema:{type:"object",properties:{url:{type:"string"},expect:De},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_open_tab",description:"Open a new tab (http(s) only) and drive it. Refuses javascript:/file: URLs.",inputSchema:{type:"object",properties:{url:{type:"string"},active:{type:"boolean",description:"Focus the new tab (default true)."}},required:["url"]},scope:"browser:act"},{name:"browser_close_tab",description:"Close a tab this session controls (default: current). Refuses the last tab; refuses tabs not leased/controlled by this session.",inputSchema:{type:"object",properties:{tabId:{type:"number"}}},scope:"browser:act"},{name:"browser_assert",description:"QA assertion: structured pass/fail over live elements (exists/not_exists/text_contains/text_equals/count/visible/value_equals/checked). Never throws \u2014 failures return ok:false with actuals.",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["exists","not_exists","text_contains","text_equals","count","visible","value_equals","checked"]},target:F,expected:{type:["string","number","boolean"],description:"Required for text_*/value_equals/count; optional boolean (default true) for visible/checked; ignored otherwise."}},required:["kind","target"]},scope:"browser:read"},{name:"browser_screenshot",description:"Capture the visible tab (rate-limited fallback).",inputSchema:{type:"object",properties:{}},scope:"browser:read"},{name:"browser_extract",description:"Schema-first extract: pass fields[] to get only declared values as data (cheapest). Without fields, returns region text + article paragraphs (nav/header/footer excluded).",inputSchema:{type:"object",properties:{regionId:{type:"string"},maxRows:{type:"number"},fields:{type:"array",description:"Declared fields (max 20): [{name, role?, nameContains?, label?, region?, ref?, attr?: text|value|name}].",items:{type:"object",properties:{name:{type:"string"},role:{type:"string"},nameContains:{type:"string"},label:{type:"string"},region:{type:"string"},ref:{type:"string"},attr:{type:"string",enum:["text","value","name"]}},required:["name"]}}}},scope:"browser:read"},{name:"browser_wait",description:"Wait for a condition or timeout. urlMatches is URI-decoded (non-ASCII paths ok).",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. REQUIRED when \u22653 consecutive fill/click/select steps (forms, search\u2192result, login). Prefer over step-by-step tool spam.",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"}]});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 vi(e,t){return e.includes("*")||e.includes(t)}function $e(e,t){return e?vi(e.scopes,t):!1}var Be=y(()=>{"use strict"});var M=T((Lo,_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 pe=T((Mo,Ue)=>{"use strict";var{EMPTY_BUFFER:Si}=M(),Et=Buffer[Symbol.species];function wi(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 Et(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 Et(e):ArrayBuffer.isView(e)?t=new Et(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),xt.readOnly=!1),t}Ue.exports={concat:wi,mask:yr,toArrayBuffer:Ei,toBuffer:xt,unmask:br};if(!process.env.WS_NO_BUFFER_UTIL)try{let e=require("bufferutil");Ue.exports.mask=function(t,r,n,i,s){s<48?yr(t,r,n,i,s):e.mask(t,r,n,i,s)},Ue.exports.unmask=function(t,r){t.length<32?br(t,r):e.unmask(t,r)}}catch{}});var wr=T(($o,Sr)=>{"use strict";var vr=Symbol("kDone"),Tt=Symbol("kRun"),kt=class{constructor(t){this[vr]=()=>{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[vr])}}};Sr.exports=kt});var ne=T((Bo,kr)=>{"use strict";var me=require("zlib"),Er=pe(),xi=wr(),{kStatusCode:xr}=M(),Ti=Buffer[Symbol.species],ki=Buffer.from([0,0,255,255]),Fe=Symbol("permessage-deflate"),$=Symbol("total-length"),te=Symbol("callback"),W=Symbol("buffers"),re=Symbol("error"),je,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,!je){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;je=new xi(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){je.add(i=>{this._decompress(t,r,(s,o)=>{i(),n(s,o)})})}compress(t,r,n){je.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"?me.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=me.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[Fe]=this,this._inflate[$]=0,this._inflate[W]=[],this._inflate.on("error",Oi),this._inflate.on("data",Tr)}this._inflate[te]=n,this._inflate.write(t),r&&this._inflate.write(ki),this._inflate.flush(()=>{let s=this._inflate[re];if(s){this._inflate.close(),this._inflate=null,n(s);return}let o=Er.concat(this._inflate[W],this._inflate[$]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[$]=0,this._inflate[W]=[],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"?me.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=me.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[$]=0,this._deflate[W]=[],this._deflate.on("data",Ci)}this._deflate[te]=n,this._deflate.write(t),this._deflate.flush(me.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=Er.concat(this._deflate[W],this._deflate[$]);r&&(s=new Ti(s.buffer,s.byteOffset,s.length-4)),this._deflate[te]=null,this._deflate[$]=0,this._deflate[W]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),n(null,s)})}};kr.exports=Ct;function Ci(e){this[W].push(e),this[$]+=e.length}function Tr(e){if(this[$]+=e.length,this[Fe]._maxPayload<1||this[$]<=this[Fe]._maxPayload){this[W].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 Oi(e){if(this[Fe]._inflate=null,this[re]){this[te](this[re]);return}e[xr]=1007,this[te](e)}});var ie=T((Uo,We)=>{"use strict";var{isUtf8:Cr}=require("buffer"),{hasBlob:Ai}=M(),Pi=[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 Ii(e){return Ai&&typeof e=="object"&&typeof e.arrayBuffer=="function"&&typeof e.type=="string"&&typeof e.stream=="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}We.exports={isBlob:Ii,isValidStatusCode:Ni,isValidUTF8:Ot,tokenChars:Pi};if(Cr)We.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");We.exports.isValidUTF8=function(t){return t.length<32?Ot(t):e(t)}}catch{}});var Rt=T((jo,Dr)=>{"use strict";var{Writable:Ri}=require("stream"),Or=ne(),{BINARY_TYPES:Di,EMPTY_BUFFER:Ar,kStatusCode:Li,kWebSocket:Mi}=M(),{concat:At,toArrayBuffer:$i,unmask:Bi}=pe(),{isValidStatusCode:Ui,isValidUTF8:Pr}=ie(),qe=Buffer[Symbol.species],A=0,Nr=1,Ir=2,Rr=3,Pt=4,Nt=5,Ge=6,It=class extends Ri{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[Mi]=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 qe(n.buffer,n.byteOffset+t,n.length-t),new qe(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 qe(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 Nr:this.getPayloadLength16(t);break;case Ir:this.getPayloadLength64(t);break;case Rr:this.getMask();break;case Pt:this.getData(t);break;case Nt:case Ge: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=Nr: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=Rr:this._state=Pt}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Pt}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]&&Bi(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=Nt,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=Ge,setImmediate(()=>{this.emit("message",i,!0),this._state=A,this.startLoop(t)}))}else{let i=At(n,r);if(!this._skipUTF8Validation&&!Pr(i)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(s);return}this._state===Nt||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=A):(this._state=Ge,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(!Ui(n)){let s=this.createError(RangeError,`invalid status code ${n}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(s);return}let i=new qe(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!Pr(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=Ge,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}};Dr.exports=It});var Mt=T((Wo,$r)=>{"use strict";var{Duplex:Fo}=require("stream"),{randomFillSync:ji}=require("crypto"),{types:{isUint8Array:Fi}}=require("util"),Lr=ne(),{EMPTY_BUFFER:Wi,kWebSocket:qi,NOOP:Gi}=M(),{isBlob:se,isValidStatusCode:Vi}=ie(),{mask:Mr,toBuffer:H}=pe(),P=Symbol("kByteLength"),Hi=Buffer.alloc(4),Ve=8*1024,z,oe=Ve,N=0,zi=1,Ji=2,Dt=class e{constructor(t,r,n){this._extensions=r||{},n&&(this._generateMask=n,this._maskBuffer=Buffer.alloc(4)),this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=N,this.onerror=Gi,this[qi]=void 0}static frame(t,r){let n,i=!1,s=2,o=!1;r.mask&&(n=r.maskBuffer||Hi,r.generateMask?r.generateMask(n):(oe===Ve&&(z===void 0&&(z=Buffer.alloc(Ve)),ji(z,0,Ve),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[P]!==void 0?a=r[P]:(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?(Mr(t,n,c,s,a),[c]):(Mr(t,n,t,0,a),[c,t])):[c,t]}close(t,r,n,i){let s;if(t===void 0)s=Wi;else{if(typeof t!="number"||!Vi(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(Fi(r))s.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[P]:s.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==N?this.enqueue([this.dispatch,s,!1,o,i]):this.sendFrame(e.frame(s,o),i)}ping(t,r,n){let i,s;if(typeof t=="string"?(i=Buffer.byteLength(t),s=!1):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={[P]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};se(t)?this._state!==N?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==N?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}pong(t,r,n){let i,s;if(typeof t=="string"?(i=Buffer.byteLength(t),s=!1):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={[P]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};se(t)?this._state!==N?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==N?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}send(t,r,n){let i=this._extensions[Lr.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={[P]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:s,readOnly:l,rsv1:o};se(t)?this._state!==N?this.enqueue([this.getBlobData,t,this._compress,c,n]):this.getBlobData(t,this._compress,c,n):this._state!==N?this.enqueue([this.dispatch,t,this._compress,c,n]):this.dispatch(t,this._compress,c,n)}getBlobData(t,r,n,i){this._bufferedBytes+=n[P],this._state=Ji,t.arrayBuffer().then(s=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Lt,this,a,i);return}this._bufferedBytes-=n[P];let o=H(s);r?this.dispatch(o,r,n,i):(this._state=N,this.sendFrame(e.frame(o,n),i),this.dequeue())}).catch(s=>{process.nextTick(Ki,this,s,i)})}dispatch(t,r,n,i){if(!r){this.sendFrame(e.frame(t,n),i);return}let s=this._extensions[Lr.extensionName];this._bufferedBytes+=n[P],this._state=zi,s.compress(t,n.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Lt(this,l,i);return}this._bufferedBytes-=n[P],this._state=N,n.readOnly=!1,this.sendFrame(e.frame(a,n),i),this.dequeue()})}dequeue(){for(;this._state===N&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[3][P],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][P],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)}};$r.exports=Dt;function Lt(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 Ki(e,t,r){Lt(e,t,r),e.onerror(t)}});var Hr=T((qo,Vr)=>{"use strict";var{kForOnEventAttribute:ge,kListener:$t}=M(),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 _e=class extends B{constructor(t,r={}){super(t),this[Ur]=r.data===void 0?null:r.data}get data(){return this[Ur]}};Object.defineProperty(_e.prototype,"data",{enumerable:!0});var Yi={addEventListener(e,t,r={}){for(let i of this.listeners(e))if(!r[ge]&&i[$t]===t&&!i[ge])return;let n;if(e==="message")n=function(s,o){let a=new _e("message",{data:o?s:s.toString()});a[ae]=this,He(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,He(t,this,a)};else if(e==="error")n=function(s){let o=new le("error",{error:s,message:s.message});o[ae]=this,He(t,this,o)};else if(e==="open")n=function(){let s=new B("open");s[ae]=this,He(t,this,s)};else return;n[ge]=!!r[ge],n[$t]=t,r.once?this.once(e,n):this.on(e,n)},removeEventListener(e,t){for(let r of this.listeners(e))if(r[$t]===t&&!r[ge]){this.removeListener(e,r);break}}};Vr.exports={CloseEvent:J,ErrorEvent:le,Event:B,EventTarget:Yi,MessageEvent:_e};function He(e,t,r){typeof e=="object"&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}});var ze=T((Go,zr)=>{"use strict";var{tokenChars:ye}=ie();function L(e,t,r){e[t]===void 0?e[t]=[r]:e[t].push(r)}function Zi(e){let t=Object.create(null),r=Object.create(null),n=!1,i=!1,s=!1,o,a,l=-1,c=-1,d=-1,u=0;for(;u<e.length;u++)if(c=e.charCodeAt(u),o===void 0)if(d===-1&&ye[c]===1)l===-1&&(l=u);else if(u!==0&&(c===32||c===9))d===-1&&l!==-1&&(d=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);d===-1&&(d=u);let h=e.slice(l,d);c===44?(L(t,h,r),r=Object.create(null)):o=h,l=d=-1}else throw new SyntaxError(`Unexpected character at index ${u}`);else if(a===void 0)if(d===-1&&ye[c]===1)l===-1&&(l=u);else if(c===32||c===9)d===-1&&l!==-1&&(d=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);d===-1&&(d=u),L(r,e.slice(l,d),!0),c===44&&(L(t,o,r),r=Object.create(null),o=void 0),l=d=-1}else if(c===61&&l!==-1&&d===-1)a=e.slice(l,u),l=d=-1;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(i){if(ye[c]!==1)throw new SyntaxError(`Unexpected character at index ${u}`);l===-1?l=u:n||(n=!0),i=!1}else if(s)if(ye[c]===1)l===-1&&(l=u);else if(c===34&&l!==-1)s=!1,d=u;else if(c===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(c===34&&e.charCodeAt(u-1)===61)s=!0;else if(d===-1&&ye[c]===1)l===-1&&(l=u);else if(l!==-1&&(c===32||c===9))d===-1&&(d=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);d===-1&&(d=u);let h=e.slice(l,d);n&&(h=h.replace(/\\/g,""),n=!1),L(r,a,h),c===44&&(L(t,o,r),r=Object.create(null),o=void 0),a=void 0,l=d=-1}else throw new SyntaxError(`Unexpected character at index ${u}`);if(l===-1||s||c===32||c===9)throw new SyntaxError("Unexpected end of input");d===-1&&(d=u);let f=e.slice(l,d);return o===void 0?L(t,f,r):(a===void 0?L(r,f,!0):n?L(r,a,f.replace(/\\/g,"")):L(r,a,f),L(t,o,r)),t}function Xi(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:Xi,parse:Zi}});var Ze=T((zo,on)=>{"use strict";var Qi=require("events"),es=require("https"),ts=require("http"),Yr=require("net"),rs=require("tls"),{randomBytes:ns,createHash:is}=require("crypto"),{Duplex:Vo,Readable:Ho}=require("stream"),{URL:Bt}=require("url"),q=ne(),ss=Rt(),os=Mt(),{isBlob:as}=ie(),{BINARY_TYPES:Jr,CLOSE_TIMEOUT:ls,EMPTY_BUFFER:Je,GUID:cs,kForOnEventAttribute:Ut,kListener:fs,kStatusCode:ds,kWebSocket:E,NOOP:Zr}=M(),{EventTarget:{addEventListener:us,removeEventListener:hs}}=Hr(),{format:ps,parse:ms}=ze(),{toBuffer:gs}=pe(),Xr=Symbol("kAborted"),jt=[8,13],U=["CONNECTING","OPEN","CLOSING","CLOSED"],_s=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,v=class e extends Qi{constructor(t,r,n){super(),this._binaryType=Jr[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Je,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 ss({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 os(t,this._extensions,n.generateMask);this._receiver=i,this._sender=s,this._socket=t,i[E]=this,s[E]=this,t[E]=this,i.on("conclude",vs),i.on("drain",Ss),i.on("error",ws),i.on("message",Es),i.on("ping",xs),i.on("pong",Ts),s.onerror=ks,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",rn),t.on("data",Ye),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[q.extensionName]&&this._extensions[q.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||Je,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||Je,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[q.extensionName]||(i.compress=!1),this._sender.send(t||Je,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(v,"CONNECTING",{enumerable:!0,value:U.indexOf("CONNECTING")});Object.defineProperty(v.prototype,"CONNECTING",{enumerable:!0,value:U.indexOf("CONNECTING")});Object.defineProperty(v,"OPEN",{enumerable:!0,value:U.indexOf("OPEN")});Object.defineProperty(v.prototype,"OPEN",{enumerable:!0,value:U.indexOf("OPEN")});Object.defineProperty(v,"CLOSING",{enumerable:!0,value:U.indexOf("CLOSING")});Object.defineProperty(v.prototype,"CLOSING",{enumerable:!0,value:U.indexOf("CLOSING")});Object.defineProperty(v,"CLOSED",{enumerable:!0,value:U.indexOf("CLOSED")});Object.defineProperty(v.prototype,"CLOSED",{enumerable:!0,value:U.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(v.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(v.prototype,`on${e}`,{enumerable:!0,get(){for(let t of this.listeners(e))if(t[Ut])return t[fs];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})}})});v.prototype.addEventListener=us;v.prototype.removeEventListener=hs;on.exports=v;function Qr(e,t,r,n){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:ls,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;Ke(e,m);return}let c=o?443:80,d=ns(16).toString("base64"),u=o?es.request:ts.request,f=new Set,h;if(i.createConnection=i.createConnection||(o?bs:ys),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":d,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(h=new q({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=ps({[q.extensionName]:h.offer()})),r.length){for(let m of r){if(typeof m!="string"||!_s.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[_,w]of Object.entries(m))n.headers[_.toLowerCase()]=w}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=u(i),e._redirects&&e.emit("redirect",e.url,g)}else g=e._req=u(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,Ke(e,m))}),g.on("response",m=>{let _=m.headers.location,w=m.statusCode;if(_&&i.followRedirects&&w>=300&&w<400){if(++e._redirects>i.maxRedirects){k(e,g,"Maximum redirects exceeded");return}g.abort();let O;try{O=new Bt(_,t)}catch{let ee=new SyntaxError(`Invalid URL: ${_}`);Ke(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,_,w)=>{if(e.emit("upgrade",m),e.readyState!==v.CONNECTING)return;g=e._req=null;let O=m.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){k(e,_,"Invalid Upgrade header");return}let V=is("sha1").update(d+cs).digest("base64");if(m.headers["sec-websocket-accept"]!==V){k(e,_,"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,_,fe);return}ee&&(e._protocol=ee);let ur=m.headers["sec-websocket-extensions"];if(ur!==void 0){if(!h){k(e,_,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let vt;try{vt=ms(ur)}catch{k(e,_,"Invalid Sec-WebSocket-Extensions header");return}let hr=Object.keys(vt);if(hr.length!==1||hr[0]!==q.extensionName){k(e,_,"Server indicated an extension that was not requested");return}try{h.accept(vt[q.extensionName])}catch{k(e,_,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[q.extensionName]=h}e.setSocket(_,w,{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 Ke(e,t){e._readyState=v.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function ys(e){return e.path=e.socketPath,Yr.connect(e)}function bs(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=Yr.isIP(e.host)?"":e.host),rs.connect(e)}function k(e,t,r){e._readyState=v.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(Ke,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=as(t)?t.size:gs(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 vs(e,t){let r=this[E];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,r._socket[E]!==void 0&&(r._socket.removeListener("data",Ye),process.nextTick(en,r._socket),e===1005?r.close():r.close(e,t))}function Ss(){let e=this[E];e.isPaused||e._socket.resume()}function ws(e){let t=this[E];t._socket[E]!==void 0&&(t._socket.removeListener("data",Ye),process.nextTick(en,t._socket),t.close(e[ds])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function Kr(){this[E].emitClose()}function Es(e,t){this[E].emit("message",e,t)}function xs(e){let t=this[E];t._autoPong&&t.pong(e,!this._isServer,Zr),t.emit("ping",e)}function Ts(e){this[E].emit("pong",e)}function en(e){e.resume()}function ks(e){let t=this[E];t.readyState!==v.CLOSED&&(t.readyState===v.OPEN&&(t._readyState=v.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[E];if(this.removeListener("close",rn),this.removeListener("data",Ye),this.removeListener("end",nn),e._readyState=v.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[E]=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 Ye(e){this[E]._receiver.write(e)||this.pause()}function nn(){let e=this[E];e._readyState=v.CLOSING,e._receiver.end(),this.end()}function sn(){let e=this[E];this.removeListener("error",sn),this.on("error",Zr),e&&(e._readyState=v.CLOSING,this.destroy())}});var fn=T((Ko,cn)=>{"use strict";var Jo=Ze(),{Duplex:Cs}=require("stream");function an(e){e.emit("close")}function Os(){!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 As(e,t){let r=!0,n=new Cs({...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",Os),n.on("error",ln),n}cn.exports=As});var Wt=T((Yo,dn)=>{"use strict";var{tokenChars:Ps}=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&&Ps[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}dn.exports={parse:Ns}});var yn=T((Xo,_n)=>{"use strict";var Is=require("events"),Xe=require("http"),{Duplex:Zo}=require("stream"),{createHash:Rs}=require("crypto"),un=ze(),K=ne(),Ds=Wt(),Ls=Ze(),{CLOSE_TIMEOUT:Ms,GUID:$s,kWebSocket:Bs}=M(),Us=/^[+/0-9A-Za-z]{22}==$/,hn=0,pn=1,gn=2,qt=class extends Is{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:Ms,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=Xe.createServer((n,i)=>{let s=Xe.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=js(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(be,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(be,this):process.nextTick(be,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{be(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||!Us.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)){ve(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 d=t.headers["sec-websocket-extensions"],u={};if(this.options.perMessageDeflate&&d!==void 0){let f=new K({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let h=un.parse(d);h[K.extensionName]&&(f.accept(h[K.extensionName]),u[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,_)=>{if(!h)return ve(r,g||401,m,_);this.completeUpgrade(u,s,c,t,r,n,i)});return}if(!this.options.verifyClient(f))return ve(r,401)}this.completeUpgrade(u,s,c,t,r,n,i)}completeUpgrade(t,r,n,i,s,o,a){if(!s.readable||!s.writable)return s.destroy();if(s[Bs])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>hn)return ve(s,503);let c=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Rs("sha1").update(r+$s).digest("base64")}`],d=new this.options.WebSocket(null,void 0,this.options);if(n.size){let u=this.options.handleProtocols?this.options.handleProtocols(n,i):n.values().next().value;u&&(c.push(`Sec-WebSocket-Protocol: ${u}`),d._protocol=u)}if(t[K.extensionName]){let u=t[K.extensionName].params,f=un.format({[K.extensionName]:[u]});c.push(`Sec-WebSocket-Extensions: ${f}`),d._extensions=t}this.emit("headers",c,i),s.write(c.concat(`\r
2
+ "use strict";var Ti=Object.create;var kt=Object.defineProperty;var ki=Object.getOwnPropertyDescriptor;var Ci=Object.getOwnPropertyNames;var Oi=Object.getPrototypeOf,Ai=Object.prototype.hasOwnProperty;var y=(e,t,r)=>()=>{if(r)throw r[0];try{return e&&(t=e(e=0)),t}catch(n){throw r=[n],n}};var k=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},vr=(e,t)=>{for(var r in t)kt(e,r,{get:t[r],enumerable:!0})},Pi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ci(t))!Ai.call(e,i)&&i!==r&&kt(e,i,{get:()=>t[i],enumerable:!(n=ki(t,i))||n.enumerable});return e};var G=(e,t,r)=>(r=e!=null?Ti(Oi(e)):{},Pi(t||!e||!e.__esModule?kt(r,"default",{value:e,enumerable:!0}):r,e));function T(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function pe(e){return new Promise((t,r)=>{if(!/^application\/json\b/i.test(String(e.headers["content-type"]??""))){r(Object.assign(new Error("Content-Type must be application/json"),{status:415}));return}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(!T(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 Me=y(()=>{"use strict"});function Be(e){return me.find(t=>t.name===e)}var M,Ni,$e,z,J,Ii,me,Ue=y(()=>{"use strict";M={type:"object",description:"Semantic target: durable ref (@Hxxxx) or role/name/region query. On AMBIGUOUS_TARGET, next call MUST use a ranked candidate ref or add region/nth/near.",properties:{ref:{type:"string",description:"Durable handle from find/observe (@Hxxxx)."},role:{type:"string"},name:{type:"string",description:"Exact accessible name."},nameContains:{type:"string"},label:{type:"string"},placeholder:{type:"string"},text:{type:"string"},region:{type:"string",description:"Semantic region id (main, dialog, navigation, \u2026)."},nth:{type:"number",description:"1-based ordinal among ranked matches (disambiguates duplicates)."},near:{type:"string",description:"Soft proximity hint (nearby heading text or region id)."},attrs:{type:"object",description:"Stable attribute hints; when used alone, every attribute must match exactly.",additionalProperties:{type:"string"}}}},Ni={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","boolean"],description:"Boolean for checked; string for URL/value conditions."},query:M,regionId:{type:"string"}},required:["type"],additionalProperties:!0},$e={type:"array",description:"Strongly recommended for click/navigate. Without expect, success is dispatch_only (not business success). Prefer url_matches / element_appeared / value_equals.",items:Ni},z={type:"number",description:"OCC base: stateVersion from a prior observe/act. Stale-but-unrelated drift rebases; related drift fails closed with STATE_CONFLICT."},J={type:"string",description:"Idempotency key: retrying the same key replays the original receipt (ALREADY_APPLIED) instead of re-executing."},Ii={type:"object",description:"Single guarded action contract.",properties:{action:{type:"string",enum:["click","fill","select","press","scroll","navigate","back","forward","hover","open_tab","close_tab"]},target:M,value:{type:"string"},key:{type:"string"},url:{type:"string"},tab:{type:["number","string"],description:"P2 multi-tab: explicit tab id or a plan-local ref bound by tabRef. Omit to run on the plan's current tab."},tabRef:{type:"string",description:"P2 multi-tab: bind this step's tab to a ref name for later steps."},active:{type:"boolean",description:"open_tab: focus the new tab (default true)."},expect:$e,timeoutMs:{type:"number"},basedOn:z,operationId:J},required:["action"],additionalProperties:!0},me=[{name:"browser_observe",description:"Pull-mode digest: default to page_digest (regions+counts ~100 tokens). Drill via browser_find or region_digest. level=full requires explicit need \u2014 prefer find. Returns recommendedNext + overBudget when useful. Pass sinceVersion for handle-level deltas, maxTokens to trim listed elements when possible (required metadata may still exceed it), stateVersion flows back as the next basedOn.",inputSchema:{type:"object",properties:{level:{type:"string",enum:["page_digest","region_digest","interactive","full"],default:"page_digest",description:"Default page_digest. Avoid full."},regionId:{type:"string"},includeRecentDiff:{type:"boolean"},limit:{type:"number",description:"Cap for interactive[] (default 30, max 120)."},maxTokens:{type:"number",description:"Best-effort token budget: listed elements are cut best-first; required metadata may still exceed it. Check overBudget and estTokens."},sinceVersion:{type:"number",description:"Delta mode: also return handle-level changes since this stateVersion."},query:{type:"string",description:"Relevance hint: rank matching controls first under token pressure."}}},scope:"browser:read"},{name:"browser_find",description:"Pull-mode lookup: matching elements as durable refs. Prefer over observe level=full. Use nth/near/region when labels collide. On AMBIGUOUS, ranked candidates include score+region \u2014 next act MUST use ref.",inputSchema:{type:"object",properties:{role:{type:"string"},name:{type:"string"},nameContains:{type:"string"},label:{type:"string"},placeholder:{type:"string"},text:{type:"string"},region:{type:"string"},attrs:{type:"object",additionalProperties:{type:"string"}},nth:{type:"number",description:"1-based ordinal among ranked matches."},near:{type:"string",description:"Nearby heading / region hint."}}},scope:"browser:read"},{name:"browser_click",description:"Click a semantic target (guarded). Strongly recommend expect (url_matches / element_appeared; element_* are delta checks vs pre-click state). Without expect, result.verifiedMode=dispatch_only.",inputSchema:{type:"object",properties:{target:M,expect:$e,basedOn:z,operationId:J},required:["target"]},scope:"browser:act"},{name:"browser_fill",description:"Fill a field and verify the value. Prefer expect value_equals when possible.",inputSchema:{type:"object",properties:{target:M,value:{type:"string"},expect:$e,basedOn:z,operationId:J},required:["target","value"]},scope:"browser:act"},{name:"browser_select",description:"Choose a select option.",inputSchema:{type:"object",properties:{target:M,value:{type:"string"},basedOn:z,operationId:J},required:["target","value"]},scope:"browser:act"},{name:"browser_press",description:"Press a key on a target or the focused element. Prefer for canvas editors (Docs/Sheets) over clicking tiles.",inputSchema:{type:"object",properties:{target:M,key:{type:"string"},basedOn:z,operationId:J}},scope:"browser:act"},{name:"browser_scroll",description:"Scroll a target into view or scroll the page. Use before re-find on virtualized lists.",inputSchema:{type:"object",properties:{target:M,direction:{type:"string"},basedOn:z,operationId:J}},scope:"browser:act"},{name:"browser_navigate",description:"Navigate the controlled tab (site grant required). Strongly recommend expect url_matches (URI-decoded).",inputSchema:{type:"object",properties:{url:{type:"string"},expect:$e},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_open_tab",description:"Open a new tab (http(s) only) and drive it. Refuses javascript:/file: URLs.",inputSchema:{type:"object",properties:{url:{type:"string"},active:{type:"boolean",description:"Focus the new tab (default true)."}},required:["url"]},scope:"browser:act"},{name:"browser_close_tab",description:"Close a tab this session controls (default: current). Refuses the last tab; refuses tabs not leased/controlled by this session.",inputSchema:{type:"object",properties:{tabId:{type:"number"}}},scope:"browser:act"},{name:"browser_assert",description:"QA assertion: structured pass/fail over live elements (exists/not_exists/text_contains/text_equals/count/visible/value_equals/checked). Never throws \u2014 failures return ok:false with actuals.",inputSchema:{type:"object",properties:{kind:{type:"string",enum:["exists","not_exists","text_contains","text_equals","count","visible","value_equals","checked"]},target:M,expected:{type:["string","number","boolean"],description:"Required for text_*/value_equals/count; optional boolean (default true) for visible/checked; ignored otherwise."}},required:["kind","target"]},scope:"browser:read"},{name:"browser_screenshot",description:"Capture the visible tab (rate-limited fallback).",inputSchema:{type:"object",properties:{}},scope:"browser:read"},{name:"browser_extract",description:"Schema-first extract: pass fields[] to get only declared values as data (cheapest). Without fields, returns region text + article paragraphs (nav/header/footer excluded). where filters rows locally (e.g. 'price < 50').",inputSchema:{type:"object",properties:{regionId:{type:"string"},maxRows:{type:"number"},where:{type:"string",description:"Row predicate evaluated in-page: 'price < 50', 'text contains sale'. Only matches cross the wire."},fields:{type:"array",description:"Declared fields (max 20): [{name, role?, nameContains?, label?, region?, ref?, attr?: text|value|name}].",items:{type:"object",properties:{name:{type:"string"},role:{type:"string"},nameContains:{type:"string"},label:{type:"string"},region:{type:"string"},ref:{type:"string"},attr:{type:"string",enum:["text","value","name"]}},required:["name"]}}}},scope:"browser:read"},{name:"browser_wait",description:"Wait for a URL or semantic element to appear/disappear. Conditions are checked immediately and while waiting; urlMatches is URI-decoded (non-ASCII paths ok).",inputSchema:{type:"object",properties:{timeoutMs:{type:"number"},urlMatches:{type:"string"},elementAppeared:M,elementDisappeared:M}},scope:"browser:read"},{name:"browser_plan",description:"Guarded micro-plan: multiple verified steps, one decision. REQUIRED when \u22653 consecutive fill/click/select steps (forms, search\u2192result, login). Prefer over step-by-step tool spam.",inputSchema:{type:"object",properties:{steps:{type:"array",description:"Ordered guarded steps (1-25).",items:Ii},abortOn:{type:"array",description:"Abort conditions (defaults to all four).",items:{type:"string",enum:["navigation","ambiguous_target","permission_required","page_epoch_changed"]}},basedOn:z,operationId:J},required:["steps"]},scope:"browser:act"}]});function ge(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 Ri(e,t){return e.includes("*")||e.includes(t)}function je(e,t){return e?Ri(e.scopes,t):!1}var Fe=y(()=>{"use strict"});var j=k((Qo,xr)=>{"use strict";var wr=["nodebuffer","arraybuffer","fragments"],Er=typeof Blob<"u";Er&&wr.push("blob");xr.exports={BINARY_TYPES:wr,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Er,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var _e=k((ea,We)=>{"use strict";var{EMPTY_BUFFER:Di}=j(),Ct=Buffer[Symbol.species];function Li(e,t){if(e.length===0)return Di;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 Ct(r.buffer,r.byteOffset,n):r}function Tr(e,t,r,n,i){for(let s=0;s<i;s++)r[n+s]=e[s]^t[s&3]}function kr(e,t){for(let r=0;r<e.length;r++)e[r]^=t[r&3]}function Mi(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function Ot(e){if(Ot.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=new Ct(e):ArrayBuffer.isView(e)?t=new Ct(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),Ot.readOnly=!1),t}We.exports={concat:Li,mask:Tr,toArrayBuffer:Mi,toBuffer:Ot,unmask:kr};if(!process.env.WS_NO_BUFFER_UTIL)try{let e=require("bufferutil");We.exports.mask=function(t,r,n,i,s){s<48?Tr(t,r,n,i,s):e.mask(t,r,n,i,s)},We.exports.unmask=function(t,r){t.length<32?kr(t,r):e.unmask(t,r)}}catch{}});var Ar=k((ta,Or)=>{"use strict";var Cr=Symbol("kDone"),At=Symbol("kRun"),Pt=class{constructor(t){this[Cr]=()=>{this.pending--,this[At]()},this.concurrency=t||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[At]()}[At](){if(this.pending!==this.concurrency&&this.jobs.length){let t=this.jobs.shift();this.pending++,t(this[Cr])}}};Or.exports=Pt});var se=k((ra,Rr)=>{"use strict";var ye=require("zlib"),Pr=_e(),$i=Ar(),{kStatusCode:Nr}=j(),Bi=Buffer[Symbol.species],Ui=Buffer.from([0,0,255,255]),Ge=Symbol("permessage-deflate"),F=Symbol("total-length"),ne=Symbol("callback"),V=Symbol("buffers"),ie=Symbol("error"),qe,Nt=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,!qe){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;qe=new $i(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[ne];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){qe.add(i=>{this._decompress(t,r,(s,o)=>{i(),n(s,o)})})}compress(t,r,n){qe.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"?ye.Z_DEFAULT_WINDOWBITS:this.params[s];this._inflate=ye.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[Ge]=this,this._inflate[F]=0,this._inflate[V]=[],this._inflate.on("error",Fi),this._inflate.on("data",Ir)}this._inflate[ne]=n,this._inflate.write(t),r&&this._inflate.write(Ui),this._inflate.flush(()=>{let s=this._inflate[ie];if(s){this._inflate.close(),this._inflate=null,n(s);return}let o=Pr.concat(this._inflate[V],this._inflate[F]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[F]=0,this._inflate[V]=[],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"?ye.Z_DEFAULT_WINDOWBITS:this.params[s];this._deflate=ye.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[F]=0,this._deflate[V]=[],this._deflate.on("data",ji)}this._deflate[ne]=n,this._deflate.write(t),this._deflate.flush(ye.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let s=Pr.concat(this._deflate[V],this._deflate[F]);r&&(s=new Bi(s.buffer,s.byteOffset,s.length-4)),this._deflate[ne]=null,this._deflate[F]=0,this._deflate[V]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),n(null,s)})}};Rr.exports=Nt;function ji(e){this[V].push(e),this[F]+=e.length}function Ir(e){if(this[F]+=e.length,this[Ge]._maxPayload<1||this[F]<=this[Ge]._maxPayload){this[V].push(e);return}this[ie]=new RangeError("Max payload size exceeded"),this[ie].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[ie][Nr]=1009,this.removeListener("data",Ir),this.reset()}function Fi(e){if(this[Ge]._inflate=null,this[ie]){this[ne](this[ie]);return}e[Nr]=1007,this[ne](e)}});var oe=k((na,Ve)=>{"use strict";var{isUtf8:Dr}=require("buffer"),{hasBlob:Wi}=j(),qi=[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 Gi(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function It(e){let t=e.length,r=0;for(;r<t;)if((e[r]&128)===0)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 Vi(e){return Wi&&typeof e=="object"&&typeof e.arrayBuffer=="function"&&typeof e.type=="string"&&typeof e.stream=="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}Ve.exports={isBlob:Vi,isValidStatusCode:Gi,isValidUTF8:It,tokenChars:qi};if(Dr)Ve.exports.isValidUTF8=function(e){return e.length<24?It(e):Dr(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let e=require("utf-8-validate");Ve.exports.isValidUTF8=function(t){return t.length<32?It(t):e(t)}}catch{}});var $t=k((ia,Fr)=>{"use strict";var{Writable:Hi}=require("stream"),Lr=se(),{BINARY_TYPES:zi,EMPTY_BUFFER:Mr,kStatusCode:Ji,kWebSocket:Yi}=j(),{concat:Rt,toArrayBuffer:Ki,unmask:Zi}=_e(),{isValidStatusCode:Xi,isValidUTF8:$r}=oe(),He=Buffer[Symbol.species],A=0,Br=1,Ur=2,jr=3,Dt=4,Lt=5,ze=6,Mt=class extends Hi{constructor(t={}){super(),this._allowSynchronousEvents=t.allowSynchronousEvents!==void 0?t.allowSynchronousEvents:!0,this._binaryType=t.binaryType||zi[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[Yi]=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 He(n.buffer,n.byteOffset+t,n.length-t),new He(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 He(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 Br:this.getPayloadLength16(t);break;case Ur:this.getPayloadLength64(t);break;case jr:this.getMask();break;case Dt:this.getData(t);break;case Lt:case ze: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)!==0){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[Lr.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=Br:this._payloadLength===127?this._state=Ur: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=jr:this._state=Dt}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Dt}getData(t){let r=Mr;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])!==0&&Zi(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=Lt,this.decompress(r,t);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(t)}decompress(t,r){this._extensions[Lr.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=Rt(n,r):this._binaryType==="arraybuffer"?i=Ki(Rt(n,r)):this._binaryType==="blob"?i=new Blob(n):i=n,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=A):(this._state=ze,setImmediate(()=>{this.emit("message",i,!0),this._state=A,this.startLoop(t)}))}else{let i=Rt(n,r);if(!this._skipUTF8Validation&&!$r(i)){let s=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(s);return}this._state===Lt||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=A):(this._state=ze,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,Mr),this.end();else{let n=t.readUInt16BE(0);if(!Xi(n)){let s=this.createError(RangeError,`invalid status code ${n}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(s);return}let i=new He(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!$r(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=ze,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[Ji]=i,o}};Fr.exports=Mt});var jt=k((oa,Gr)=>{"use strict";var{Duplex:sa}=require("stream"),{randomFillSync:Qi}=require("crypto"),{types:{isUint8Array:es}}=require("util"),Wr=se(),{EMPTY_BUFFER:ts,kWebSocket:rs,NOOP:ns}=j(),{isBlob:ae,isValidStatusCode:is}=oe(),{mask:qr,toBuffer:Y}=_e(),P=Symbol("kByteLength"),ss=Buffer.alloc(4),Je=8*1024,K,le=Je,I=0,os=1,as=2,Bt=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=I,this.onerror=ns,this[rs]=void 0}static frame(t,r){let n,i=!1,s=2,o=!1;r.mask&&(n=r.maskBuffer||ss,r.generateMask?r.generateMask(n):(le===Je&&(K===void 0&&(K=Buffer.alloc(Je)),Qi(K,0,Je),le=0),n[0]=K[le++],n[1]=K[le++],n[2]=K[le++],n[3]=K[le++]),o=(n[0]|n[1]|n[2]|n[3])===0,s=6);let a;typeof t=="string"?(!r.mask||o)&&r[P]!==void 0?a=r[P]:(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?(qr(t,n,c,s,a),[c]):(qr(t,n,t,0,a),[c,t])):[c,t]}close(t,r,n,i){let s;if(t===void 0)s=ts;else{if(typeof t!="number"||!is(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(es(r))s.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[P]:s.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==I?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):ae(t)?(i=t.size,s=!1):(t=Y(t),i=t.length,s=Y.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[P]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};ae(t)?this._state!==I?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==I?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):ae(t)?(i=t.size,s=!1):(t=Y(t),i=t.length,s=Y.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[P]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};ae(t)?this._state!==I?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):this._state!==I?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}send(t,r,n){let i=this._extensions[Wr.extensionName],s=r.binary?2:1,o=r.compress,a,l;typeof t=="string"?(a=Buffer.byteLength(t),l=!1):ae(t)?(a=t.size,l=!1):(t=Y(t),a=t.length,l=Y.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={[P]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:s,readOnly:l,rsv1:o};ae(t)?this._state!==I?this.enqueue([this.getBlobData,t,this._compress,c,n]):this.getBlobData(t,this._compress,c,n):this._state!==I?this.enqueue([this.dispatch,t,this._compress,c,n]):this.dispatch(t,this._compress,c,n)}getBlobData(t,r,n,i){this._bufferedBytes+=n[P],this._state=as,t.arrayBuffer().then(s=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Ut,this,a,i);return}this._bufferedBytes-=n[P];let o=Y(s);r?this.dispatch(o,r,n,i):(this._state=I,this.sendFrame(e.frame(o,n),i),this.dequeue())}).catch(s=>{process.nextTick(ls,this,s,i)})}dispatch(t,r,n,i){if(!r){this.sendFrame(e.frame(t,n),i);return}let s=this._extensions[Wr.extensionName];this._bufferedBytes+=n[P],this._state=os,s.compress(t,n.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Ut(this,l,i);return}this._bufferedBytes-=n[P],this._state=I,n.readOnly=!1,this.sendFrame(e.frame(a,n),i),this.dequeue()})}dequeue(){for(;this._state===I&&this._queue.length;){let t=this._queue.shift();this._bufferedBytes-=t[3][P],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][P],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)}};Gr.exports=Bt;function Ut(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 ls(e,t,r){Ut(e,t,r),e.onerror(t)}});var Qr=k((aa,Xr)=>{"use strict";var{kForOnEventAttribute:be,kListener:Ft}=j(),Vr=Symbol("kCode"),Hr=Symbol("kData"),zr=Symbol("kError"),Jr=Symbol("kMessage"),Yr=Symbol("kReason"),ce=Symbol("kTarget"),Kr=Symbol("kType"),Zr=Symbol("kWasClean"),W=class{constructor(t){this[ce]=null,this[Kr]=t}get target(){return this[ce]}get type(){return this[Kr]}};Object.defineProperty(W.prototype,"target",{enumerable:!0});Object.defineProperty(W.prototype,"type",{enumerable:!0});var Z=class extends W{constructor(t,r={}){super(t),this[Vr]=r.code===void 0?0:r.code,this[Yr]=r.reason===void 0?"":r.reason,this[Zr]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Vr]}get reason(){return this[Yr]}get wasClean(){return this[Zr]}};Object.defineProperty(Z.prototype,"code",{enumerable:!0});Object.defineProperty(Z.prototype,"reason",{enumerable:!0});Object.defineProperty(Z.prototype,"wasClean",{enumerable:!0});var fe=class extends W{constructor(t,r={}){super(t),this[zr]=r.error===void 0?null:r.error,this[Jr]=r.message===void 0?"":r.message}get error(){return this[zr]}get message(){return this[Jr]}};Object.defineProperty(fe.prototype,"error",{enumerable:!0});Object.defineProperty(fe.prototype,"message",{enumerable:!0});var Se=class extends W{constructor(t,r={}){super(t),this[Hr]=r.data===void 0?null:r.data}get data(){return this[Hr]}};Object.defineProperty(Se.prototype,"data",{enumerable:!0});var cs={addEventListener(e,t,r={}){for(let i of this.listeners(e))if(!r[be]&&i[Ft]===t&&!i[be])return;let n;if(e==="message")n=function(s,o){let a=new Se("message",{data:o?s:s.toString()});a[ce]=this,Ye(t,this,a)};else if(e==="close")n=function(s,o){let a=new Z("close",{code:s,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[ce]=this,Ye(t,this,a)};else if(e==="error")n=function(s){let o=new fe("error",{error:s,message:s.message});o[ce]=this,Ye(t,this,o)};else if(e==="open")n=function(){let s=new W("open");s[ce]=this,Ye(t,this,s)};else return;n[be]=!!r[be],n[Ft]=t,r.once?this.once(e,n):this.on(e,n)},removeEventListener(e,t){for(let r of this.listeners(e))if(r[Ft]===t&&!r[be]){this.removeListener(e,r);break}}};Xr.exports={CloseEvent:Z,ErrorEvent:fe,Event:W,EventTarget:cs,MessageEvent:Se};function Ye(e,t,r){typeof e=="object"&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}});var Ke=k((la,en)=>{"use strict";var{tokenChars:ve}=oe();function $(e,t,r){e[t]===void 0?e[t]=[r]:e[t].push(r)}function fs(e){let t=Object.create(null),r=Object.create(null),n=!1,i=!1,s=!1,o,a,l=-1,c=-1,f=-1,u=0;for(;u<e.length;u++)if(c=e.charCodeAt(u),o===void 0)if(f===-1&&ve[c]===1)l===-1&&(l=u);else if(u!==0&&(c===32||c===9))f===-1&&l!==-1&&(f=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);f===-1&&(f=u);let d=e.slice(l,f);c===44?($(t,d,r),r=Object.create(null)):o=d,l=f=-1}else throw new SyntaxError(`Unexpected character at index ${u}`);else if(a===void 0)if(f===-1&&ve[c]===1)l===-1&&(l=u);else if(c===32||c===9)f===-1&&l!==-1&&(f=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);f===-1&&(f=u),$(r,e.slice(l,f),!0),c===44&&($(t,o,r),r=Object.create(null),o=void 0),l=f=-1}else if(c===61&&l!==-1&&f===-1)a=e.slice(l,u),l=f=-1;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(i){if(ve[c]!==1)throw new SyntaxError(`Unexpected character at index ${u}`);l===-1?l=u:n||(n=!0),i=!1}else if(s)if(ve[c]===1)l===-1&&(l=u);else if(c===34&&l!==-1)s=!1,f=u;else if(c===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${u}`);else if(c===34&&e.charCodeAt(u-1)===61)s=!0;else if(f===-1&&ve[c]===1)l===-1&&(l=u);else if(l!==-1&&(c===32||c===9))f===-1&&(f=u);else if(c===59||c===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${u}`);f===-1&&(f=u);let d=e.slice(l,f);n&&(d=d.replace(/\\/g,""),n=!1),$(r,a,d),c===44&&($(t,o,r),r=Object.create(null),o=void 0),a=void 0,l=f=-1}else throw new SyntaxError(`Unexpected character at index ${u}`);if(l===-1||s||c===32||c===9)throw new SyntaxError("Unexpected end of input");f===-1&&(f=u);let m=e.slice(l,f);return o===void 0?$(t,m,r):(a===void 0?$(r,m,!0):n?$(r,a,m.replace(/\\/g,"")):$(r,a,m),$(t,o,r)),t}function ds(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(", ")}en.exports={format:ds,parse:fs}});var et=k((da,hn)=>{"use strict";var us=require("events"),hs=require("https"),ps=require("http"),nn=require("net"),ms=require("tls"),{randomBytes:gs,createHash:_s}=require("crypto"),{Duplex:ca,Readable:fa}=require("stream"),{URL:Wt}=require("url"),H=se(),ys=$t(),bs=jt(),{isBlob:Ss}=oe(),{BINARY_TYPES:tn,CLOSE_TIMEOUT:vs,EMPTY_BUFFER:Ze,GUID:ws,kForOnEventAttribute:qt,kListener:Es,kStatusCode:xs,kWebSocket:x,NOOP:sn}=j(),{EventTarget:{addEventListener:Ts,removeEventListener:ks}}=Qr(),{format:Cs,parse:Os}=Ke(),{toBuffer:As}=_e(),on=Symbol("kAborted"),Gt=[8,13],q=["CONNECTING","OPEN","CLOSING","CLOSED"],Ps=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,S=class e extends us{constructor(t,r,n){super(),this._binaryType=tn[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]),an(this,t,r,n)):(this._autoPong=n.autoPong,this._closeTimeout=n.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(t){tn.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 ys({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 bs(t,this._extensions,n.generateMask);this._receiver=i,this._sender=s,this._socket=t,i[x]=this,s[x]=this,t[x]=this,i.on("conclude",Rs),i.on("drain",Ds),i.on("error",Ls),i.on("message",Ms),i.on("ping",$s),i.on("pong",Bs),s.onerror=Us,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",fn),t.on("data",Qe),t.on("end",dn),t.on("error",un),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[H.extensionName]&&this._extensions[H.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){C(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())}),cn(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){Vt(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){Vt(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){Vt(this,t,n);return}let i={binary:typeof t!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[H.extensionName]||(i.compress=!1),this._sender.send(t||Ze,i,n)}terminate(){if(this.readyState!==e.CLOSED){if(this.readyState===e.CONNECTING){C(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=e.CLOSING,this._socket.destroy())}}};Object.defineProperty(S,"CONNECTING",{enumerable:!0,value:q.indexOf("CONNECTING")});Object.defineProperty(S.prototype,"CONNECTING",{enumerable:!0,value:q.indexOf("CONNECTING")});Object.defineProperty(S,"OPEN",{enumerable:!0,value:q.indexOf("OPEN")});Object.defineProperty(S.prototype,"OPEN",{enumerable:!0,value:q.indexOf("OPEN")});Object.defineProperty(S,"CLOSING",{enumerable:!0,value:q.indexOf("CLOSING")});Object.defineProperty(S.prototype,"CLOSING",{enumerable:!0,value:q.indexOf("CLOSING")});Object.defineProperty(S,"CLOSED",{enumerable:!0,value:q.indexOf("CLOSED")});Object.defineProperty(S.prototype,"CLOSED",{enumerable:!0,value:q.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(e=>{Object.defineProperty(S.prototype,e,{enumerable:!0})});["open","error","close","message"].forEach(e=>{Object.defineProperty(S.prototype,`on${e}`,{enumerable:!0,get(){for(let t of this.listeners(e))if(t[qt])return t[Es];return null},set(t){for(let r of this.listeners(e))if(r[qt]){this.removeListener(e,r);break}typeof t=="function"&&this.addEventListener(e,t,{[qt]:!0})}})});S.prototype.addEventListener=Ts;S.prototype.removeEventListener=ks;hn.exports=S;function an(e,t,r,n){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:vs,protocolVersion:Gt[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,!Gt.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Gt.join(", ")})`);let s;if(t instanceof Wt)s=t;else try{s=new Wt(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 p=new SyntaxError(l);if(e._redirects===0)throw p;Xe(e,p);return}let c=o?443:80,f=gs(16).toString("base64"),u=o?hs.request:ps.request,m=new Set,d;if(i.createConnection=i.createConnection||(o?Is:Ns),i.defaultPort=i.defaultPort||c,i.port=s.port||c,i.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":f,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(d=new H({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=Cs({[H.extensionName]:d.offer()})),r.length){for(let p of r){if(typeof p!="string"||!Ps.test(p)||m.has(p))throw new SyntaxError("An invalid or duplicated subprotocol was specified");m.add(p)}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 p=i.path.split(":");i.socketPath=p[0],i.path=p[1]}let h;if(i.followRedirects){if(e._redirects===0){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:s.host;let p=n&&n.headers;if(n={...n,headers:{}},p)for(let[_,w]of Object.entries(p))n.headers[_.toLowerCase()]=w}else if(e.listenerCount("redirect")===0){let p=a?e._originalIpc?i.socketPath===e._originalHostOrSocketPath:!1:e._originalIpc?!1:s.host===e._originalHostOrSocketPath;(!p||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,p||delete i.headers.host,i.auth=void 0)}i.auth&&!n.headers.authorization&&(n.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),h=e._req=u(i),e._redirects&&e.emit("redirect",e.url,h)}else h=e._req=u(i);i.timeout&&h.on("timeout",()=>{C(e,h,"Opening handshake has timed out")}),h.on("error",p=>{h===null||h[on]||(h=e._req=null,Xe(e,p))}),h.on("response",p=>{let _=p.headers.location,w=p.statusCode;if(_&&i.followRedirects&&w>=300&&w<400){if(++e._redirects>i.maxRedirects){C(e,h,"Maximum redirects exceeded");return}h.abort();let E;try{E=new Wt(_,t)}catch{let N=new SyntaxError(`Invalid URL: ${_}`);Xe(e,N);return}an(e,E,r,n)}else e.emit("unexpected-response",h,p)||C(e,h,`Unexpected server response: ${p.statusCode}`)}),h.on("upgrade",(p,_,w)=>{if(e.emit("upgrade",p),e.readyState!==S.CONNECTING)return;h=e._req=null;let E=p.headers.upgrade;if(E===void 0||E.toLowerCase()!=="websocket"){C(e,_,"Invalid Upgrade header");return}let U=_s("sha1").update(f+ws).digest("base64");if(p.headers["sec-websocket-accept"]!==U){C(e,_,"Invalid Sec-WebSocket-Accept header");return}let N=p.headers["sec-websocket-protocol"],he;if(N!==void 0?m.size?m.has(N)||(he="Server sent an invalid subprotocol"):he="Server sent a subprotocol but none was requested":m.size&&(he="Server sent no subprotocol"),he){C(e,_,he);return}N&&(e._protocol=N);let br=p.headers["sec-websocket-extensions"];if(br!==void 0){if(!d){C(e,_,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let xt;try{xt=Os(br)}catch{C(e,_,"Invalid Sec-WebSocket-Extensions header");return}let Sr=Object.keys(xt);if(Sr.length!==1||Sr[0]!==H.extensionName){C(e,_,"Server indicated an extension that was not requested");return}try{d.accept(xt[H.extensionName])}catch{C(e,_,"Invalid Sec-WebSocket-Extensions header");return}e._extensions[H.extensionName]=d}e.setSocket(_,w,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(h,e):h.end()}function Xe(e,t){e._readyState=S.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function Ns(e){return e.path=e.socketPath,nn.connect(e)}function Is(e){return e.path=void 0,!e.servername&&e.servername!==""&&(e.servername=nn.isIP(e.host)?"":e.host),ms.connect(e)}function C(e,t,r){e._readyState=S.CLOSING;let n=new Error(r);Error.captureStackTrace(n,C),t.setHeader?(t[on]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(Xe,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function Vt(e,t,r){if(t){let n=Ss(t)?t.size:As(t).length;e._socket?e._sender._bufferedBytes+=n:e._bufferedAmount+=n}if(r){let n=new Error(`WebSocket is not open: readyState ${e.readyState} (${q[e.readyState]})`);process.nextTick(r,n)}}function Rs(e,t){let r=this[x];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,r._socket[x]!==void 0&&(r._socket.removeListener("data",Qe),process.nextTick(ln,r._socket),e===1005?r.close():r.close(e,t))}function Ds(){let e=this[x];e.isPaused||e._socket.resume()}function Ls(e){let t=this[x];t._socket[x]!==void 0&&(t._socket.removeListener("data",Qe),process.nextTick(ln,t._socket),t.close(e[xs])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function rn(){this[x].emitClose()}function Ms(e,t){this[x].emit("message",e,t)}function $s(e){let t=this[x];t._autoPong&&t.pong(e,!this._isServer,sn),t.emit("ping",e)}function Bs(e){this[x].emit("pong",e)}function ln(e){e.resume()}function Us(e){let t=this[x];t.readyState!==S.CLOSED&&(t.readyState===S.OPEN&&(t._readyState=S.CLOSING,cn(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function cn(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),e._closeTimeout)}function fn(){let e=this[x];if(this.removeListener("close",fn),this.removeListener("data",Qe),this.removeListener("end",dn),e._readyState=S.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[x]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",rn),e._receiver.on("finish",rn))}function Qe(e){this[x]._receiver.write(e)||this.pause()}function dn(){let e=this[x];e._readyState=S.CLOSING,e._receiver.end(),this.end()}function un(){let e=this[x];this.removeListener("error",un),this.on("error",sn),e&&(e._readyState=S.CLOSING,this.destroy())}});var _n=k((ha,gn)=>{"use strict";var ua=et(),{Duplex:js}=require("stream");function pn(e){e.emit("close")}function Fs(){!this.destroyed&&this._writableState.finished&&this.destroy()}function mn(e){this.removeListener("error",mn),this.destroy(),this.listenerCount("error")===0&&this.emit("error",e)}function Ws(e,t){let r=!0,n=new js({...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(pn,n);return}let o=!1;e.once("error",function(l){o=!0,s(l)}),e.once("close",function(){o||s(i),process.nextTick(pn,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",Fs),n.on("error",mn),n}gn.exports=Ws});var Ht=k((pa,yn)=>{"use strict";var{tokenChars:qs}=oe();function Gs(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&&qs[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}yn.exports={parse:Gs}});var Tn=k((ga,xn)=>{"use strict";var Vs=require("events"),tt=require("http"),{Duplex:ma}=require("stream"),{createHash:Hs}=require("crypto"),bn=Ke(),X=se(),zs=Ht(),Js=et(),{CLOSE_TIMEOUT:Ys,GUID:Ks,kWebSocket:Zs}=j(),Xs=/^[+/0-9A-Za-z]{22}==$/,Sn=0,vn=1,En=2,zt=class extends Vs{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:Ys,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Js,...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=tt.createServer((n,i)=>{let s=tt.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=Qs(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=Sn}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(t){if(this._state===En){t&&this.once("close",()=>{t(new Error("The server is not running"))}),process.nextTick(we,this);return}if(t&&this.once("close",t),this._state!==vn)if(this._state=vn,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(we,this):process.nextTick(we,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{we(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",wn);let s=t.headers["sec-websocket-key"],o=t.headers.upgrade,a=+t.headers["sec-websocket-version"];if(t.method!=="GET"){Q(this,t,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){Q(this,t,r,400,"Invalid Upgrade header");return}if(s===void 0||!Xs.test(s)){Q(this,t,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){Q(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=zs.parse(l)}catch{Q(this,t,r,400,"Invalid Sec-WebSocket-Protocol header");return}let f=t.headers["sec-websocket-extensions"],u={};if(this.options.perMessageDeflate&&f!==void 0){let m=new X({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let d=bn.parse(f);d[X.extensionName]&&(m.accept(d[X.extensionName]),u[X.extensionName]=m)}catch{Q(this,t,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let m={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(m,(d,h,p,_)=>{if(!d)return Ee(r,h||401,p,_);this.completeUpgrade(u,s,c,t,r,n,i)});return}if(!this.options.verifyClient(m))return Ee(r,401)}this.completeUpgrade(u,s,c,t,r,n,i)}completeUpgrade(t,r,n,i,s,o,a){if(!s.readable||!s.writable)return s.destroy();if(s[Zs])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Sn)return Ee(s,503);let c=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Hs("sha1").update(r+Ks).digest("base64")}`],f=new this.options.WebSocket(null,void 0,this.options);if(n.size){let u=this.options.handleProtocols?this.options.handleProtocols(n,i):n.values().next().value;u&&(c.push(`Sec-WebSocket-Protocol: ${u}`),f._protocol=u)}if(t[X.extensionName]){let u=t[X.extensionName].params,m=bn.format({[X.extensionName]:[u]});c.push(`Sec-WebSocket-Extensions: ${m}`),f._extensions=t}this.emit("headers",c,i),s.write(c.concat(`\r
3
3
  `).join(`\r
4
- `)),s.removeListener("error",mn),d.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(d),d.on("close",()=>{this.clients.delete(d),this._shouldEmitClose&&!this.clients.size&&process.nextTick(be,this)})),a(d,i)}};_n.exports=qt;function js(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 be(e){e._state=gn,e.emit("close")}function mn(){this.destroy()}function ve(e,t,r,n){r=r||Xe.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} ${Xe.STATUS_CODES[t]}\r
4
+ `)),s.removeListener("error",wn),f.setSocket(s,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(f),f.on("close",()=>{this.clients.delete(f),this._shouldEmitClose&&!this.clients.size&&process.nextTick(we,this)})),a(f,i)}};xn.exports=zt;function Qs(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 we(e){e._state=En,e.emit("close")}function wn(){this.destroy()}function Ee(e,t,r,n){r=r||tt.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} ${tt.STATUS_CODES[t]}\r
5
5
  `+Object.keys(n).map(i=>`${i}: ${n[i]}`).join(`\r
6
6
  `)+`\r
7
7
  \r
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 ve(r,n,i,s)}});var Fs,Ws,qs,Gs,Vs,Hs,zs,Gt,bn=y(()=>{Fs=j(fn(),1),Ws=j(ze(),1),qs=j(ne(),1),Gs=j(Rt(),1),Vs=j(Mt(),1),Hs=j(Wt(),1),zs=j(Ze(),1),Gt=j(yn(),1)});function vn(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}function Qe(e,t,r){return{id:e,kind:"response",error:{code:t,message:r}}}var ce=y(()=>{"use strict"});function wn(e){return String(e?Math.floor(1e5+e()*9e5):(0,tt.randomInt)(1e5,1e6))}var tt,G,En,et,xn=y(()=>{"use strict";tt=require("node:crypto"),G=require("node:fs"),En=require("node:path");ce();et=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,G.existsSync)(this.persistPath))try{let r=JSON.parse((0,G.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,G.mkdirSync)((0,En.dirname)(this.persistPath),{recursive:!0}),(0,G.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=wn(s),c=0;for(;this.sessions.has(l)&&c++<100;)l=wn(s);if(this.sessions.has(l))throw Object.assign(new Error("RATE_LIMITED: code space exhausted"),{code:"RATE_LIMITED"});let d=String(r??"agent").slice(0,64)||"agent",u=(Array.isArray(n)?n:[]).map(String).slice(0,8),f={code:l,deviceId:t,clientName:d,scopes:u,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,tt.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);if(!n||n.expiresAt<=r)return{status:"expired"};if(n.approved&&n.token){let i=n.token;return this.sessions.delete(t),{status:"approved",token:i}}return{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 rt,Tn=y(()=>{"use strict";ce();rt=class{onTiming;now;constructor(t,r=()=>performance.now()){this.onTiming=t,this.now=r}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=vn(),l={id:a,kind:"request",method:r,params:n,agentName:s?.agentName},c=this.now(),d=0,u="error";return new Promise((f,h)=>{let g=setTimeout(()=>{this.pending.delete(a),h(Object.assign(new Error(`TIMEOUT waiting for device ${t}`),{code:"TIMEOUT"}))},i);this.pending.set(a,{deviceId:t,resolve:f,reject:h,timer:g});let m=this.now();try{o(JSON.stringify(l))}catch(_){this.pending.delete(a),clearTimeout(g),h(_ instanceof Error?_:new Error(String(_)))}finally{d=Math.max(0,this.now()-m)}}).then(f=>(u="response",f)).finally(()=>{try{this.onTiming?.({method:/^browser_[a-z_]{1,40}$/.test(r)?r:"other",outcome:u,sendMs:d,roundTripMs:Math.max(0,this.now()-c)})}catch{}})}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}}});var nt,Vt=y(()=>{"use strict";nt=["Babtab is a pull-mode browser runtime: observe digests, find refs, act with verification.","SOP:","1) Start with browser_observe level=page_digest (~100 tokens). Avoid level=full unless explicitly required.","2) Prefer browser_find (role/name/region/nth) over interactive dumps; act with returned refs.","3) If a flow needs \u22653 consecutive fill/click/select steps, MUST call browser_plan (one decision, many verified steps).","4) Always pass expect postconditions: URL conditions for navigate; relevant URL/element/value conditions for actions. Success without expect is dispatch_only \u2014 not business success.","5) On AMBIGUOUS_TARGET: pick a ranked candidate by ref, or refine with region/nth/near. Do not guess.","6) After an action error (including STALE_TARGET), observe the current URL and expected state before retrying: the action may already have succeeded. If still needed, re-find the target; do not click lookalike candidates.","7) Virtualized lists (Gmail/Slack/feeds): scroll, re-find, then act. Canvas sites (Docs/Figma): prefer menus/dialogs/press \u2014 never canvas tiles.","Gmail: verify the submitted search URL and loaded results before interpreting count:0. is:unread means current unread state, not never opened. Re-find row checkboxes after list changes; use expect checked=true to confirm selection. For delete, require a relevant new confirmation or disappearance of a unique previously present row; an inbox badge alone is not proof. Never retry a dispatched destructive click without checking its outcome.","8) Navigate verifies URL conditions only. Use browser_wait/browser_assert for content readiness, then browser_extract. Empty paragraphs do not prove an empty article; inspect page state. Check truncated before summarizing extracted text.","Pairing: if tools report pairing is needed, ask the user to open Babtab in Chrome and approve the connection."].join(" ")});function Qs(e){let t=new URL(e.url??"/","http://localhost");return e.method==="POST"&&t.pathname==="/mcp"}async function kn(e,t,r){if(!Qs(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 de(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:Xs,capabilities:{tools:{}},serverInfo:{name:"babtab-relay",version:"0.3.0"},instructions:nt}});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:ue.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:it("Tool arguments must be an object")});let l=Le(o);if(!l)return I(t,e,s.id??null,{result:it(`Unknown tool: ${o}`)});if(!$e(n,l.scope))return I(t,e,s.id??null,{result:it(`Token lacks scope ${l.scope} for ${o}`)});try{let c=await r.registry.routeToDevice(n.deviceId,o,a,13e4,{agentName:n.clientName}),d=[];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&&d.push({type:"image",mimeType:h[1],data:h[2]})}let u=Ht(c),f=JSON.stringify(u)??"null";return d.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:d,...x(c)&&c.ok===!1?{isError:!0}:{}}})}catch(c){let d=c;return I(t,e,s.id??null,{result:it(`${d.code??"DISCONNECTED"}: ${d.message}`,!0)})}}return I(t,e,s.id??null,{error:{code:-32601,message:`Method not found: ${s.method}`}},404)}function it(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
8
+ `+r)}function Q(e,t,r,n,i,s){if(e.listenerCount("wsClientError")){let o=new Error(i);Error.captureStackTrace(o,Q),e.emit("wsClientError",o,r,t)}else Ee(r,n,i,s)}});var eo,to,ro,no,io,so,oo,Jt,kn=y(()=>{eo=G(_n(),1),to=G(Ke(),1),ro=G(se(),1),no=G($t(),1),io=G(jt(),1),so=G(Ht(),1),oo=G(et(),1),Jt=G(Tn(),1)});function Cn(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}function rt(e,t,r){return{id:e,kind:"response",error:{code:t,message:r}}}var de=y(()=>{"use strict"});function Nn(e){return String(e?Math.floor(1e5+e()*9e5):(0,it.randomInt)(1e5,1e6))}var it,B,In,Pn,fo,uo,ho,nt,Rn=y(()=>{"use strict";it=require("node:crypto"),B=require("node:fs"),In=require("node:path");de();Pn=6e4,fo=10,uo=4096,ho=6e4;nt=class{sessions=new Map;tokens=new Map;lastRequestAt=new Map;claimFailures=new Map;lastClaimPruneAt=0;nextTokenPruneAt=0;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,B.existsSync)(this.persistPath))try{let r=JSON.parse((0,B.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,B.mkdirSync)((0,In.dirname)(this.persistPath),{recursive:!0});let t=`${this.persistPath}.${process.pid}.tmp`;(0,B.writeFileSync)(t,JSON.stringify([...this.tokens.values()]),{mode:384}),(0,B.renameSync)(t,this.persistPath)}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(d=>d.deviceId===t&&!d.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=Nn(s),c=0;for(;this.sessions.has(l)&&c++<100;)l=Nn(s);if(this.sessions.has(l))throw Object.assign(new Error("RATE_LIMITED: code space exhausted"),{code:"RATE_LIMITED"});let f=String(r??"agent").slice(0,64)||"agent",u=(Array.isArray(n)?n:[]).map(String).slice(0,8),m={code:l,deviceId:t,clientName:f,scopes:u,createdAt:i,expiresAt:i+6e5,approved:!1};return this.sessions.set(l,m),this.lastRequestAt.set(t,i),m}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,it.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(),n){this.pruneClaimFailures(r);let i=this.sessions.get(t);if(!i||i.expiresAt<=r)return n&&this.noteClaimFailure(n,r)?{status:"expired",rateLimited:!0}:{status:"expired"};if(i.approved&&i.token){let s=i.token;return this.sessions.delete(t),{status:"approved",token:s}}return{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);for(let[r,n]of this.lastRequestAt)t>=n&&t-n>=5e3&&this.lastRequestAt.delete(r);if(this.pruneClaimFailures(t),t>=this.nextTokenPruneAt){this.nextTokenPruneAt=t+ho;let r=!1;for(let[n,i]of this.tokens)i.expiresAt<=t&&(this.tokens.delete(n),r=!0);r&&this.persist()}}noteClaimFailure(t,r){let n=this.claimFailures.get(t);if(!n||r<n.startedAt||r-n.startedAt>=Pn){if(n={startedAt:r,count:0},this.claimFailures.delete(t),this.claimFailures.size>=uo){let i=this.claimFailures.keys().next().value;i!==void 0&&this.claimFailures.delete(i)}this.claimFailures.set(t,n)}return n.count>=fo?!0:(n.count++,!1)}pruneClaimFailures(t){if(!(t>=this.lastClaimPruneAt&&t-this.lastClaimPruneAt<1e4)){this.lastClaimPruneAt=t;for(let[r,n]of this.claimFailures)(t<n.startedAt||t-n.startedAt>=Pn)&&this.claimFailures.delete(r)}}}});var Dn,st,Ln=y(()=>{"use strict";de();Dn=100,st=class{onTiming;now;constructor(t,r=()=>performance.now()){this.onTiming=t,this.now=r}devices=new Map;pending=new Map;pendingByDevice=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),this.adjustPendingCount(t,-1),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=this.pendingCountForDevice(t);if(a>=Dn)return Promise.reject(Object.assign(new Error(`RATE_LIMITED: ${a} in-flight requests for device ${t} (cap ${Dn}) \u2014 back off and retry; the extension is still healthy`),{code:"RATE_LIMITED"}));let l=Cn(),c={id:l,kind:"request",method:r,params:n,agentName:s?.agentName},f=this.now(),u=0,m="error";return new Promise((d,h)=>{let p=setTimeout(()=>{let w=this.pending.get(l);w&&(this.pending.delete(l),this.adjustPendingCount(w.deviceId,-1)),h(Object.assign(new Error(`TIMEOUT waiting for device ${t}`),{code:"TIMEOUT"}))},i);this.pending.set(l,{deviceId:t,resolve:d,reject:h,timer:p}),this.adjustPendingCount(t,1);let _=this.now();try{o(JSON.stringify(c))}catch(w){this.pending.delete(l)&&this.adjustPendingCount(t,-1),clearTimeout(p),h(w instanceof Error?w:new Error(String(w)))}finally{u=Math.max(0,this.now()-_)}}).then(d=>(m="response",d)).finally(()=>{try{this.onTiming?.({method:/^browser_[a-z_]{1,40}$/.test(r)?r:"other",outcome:m,sendMs:u,roundTripMs:Math.max(0,this.now()-f)})}catch{}})}settleResponse(t,r){let n=this.pending.get(t.id);return!n||r!==void 0&&n.deviceId!==r?!1:(this.pending.delete(t.id),this.adjustPendingCount(n.deviceId,-1),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}pendingCountForDevice(t){return this.pendingByDevice.get(t)??0}adjustPendingCount(t,r){let n=(this.pendingByDevice.get(t)??0)+r;n<=0?this.pendingByDevice.delete(t):this.pendingByDevice.set(t,n)}}});var ot,Yt=y(()=>{"use strict";ot=["Babtab is a pull-mode browser runtime: observe digests, find refs, act with verification.","SOP:","1) Start with browser_observe level=page_digest (~100 tokens). Avoid level=full unless explicitly required.","2) Prefer browser_find (role/name/region/nth) over interactive dumps; act with returned refs.","3) If a flow needs \u22653 consecutive fill/click/select steps, MUST call browser_plan (one decision, many verified steps).","4) Always pass expect postconditions: URL conditions for navigate; relevant URL/element/value conditions for actions. Success without expect is dispatch_only \u2014 not business success.","5) On AMBIGUOUS_TARGET: pick a ranked candidate by ref, or refine with region/nth/near. Do not guess.","6) After an action error (including STALE_TARGET), observe the current URL and expected state before retrying: the action may already have succeeded. If still needed, re-find the target; do not click lookalike candidates.","7) Virtualized lists (Gmail/Slack/feeds): scroll, re-find, then act. Canvas sites (Docs/Figma): prefer menus/dialogs/press \u2014 never canvas tiles.","Gmail: verify the submitted search URL and loaded results before interpreting count:0. is:unread means current unread state, not never opened. Re-find row checkboxes after list changes; use expect checked=true to confirm selection. For delete, require a relevant new confirmation or disappearance of a unique previously present row; an inbox badge alone is not proof. Never retry a dispatched destructive click without checking its outcome.","8) Navigate verifies URL conditions only. Use browser_wait/browser_assert for content readiness, then browser_extract. Empty paragraphs do not prove an empty article; inspect page state. Check truncated before summarizing extracted text.","Pairing: if tools report pairing is needed, ask the user to open Babtab in Chrome and approve the connection.","Startup: Babtab needs Node 20+ / npx on the AI tool PATH; port-held or PATH errors mean fix the environment then reload MCP \u2014 never skip browser approval."].join(" ")});var ue,at=y(()=>{"use strict";ue="0.3.2"});function mo(e){let t=new URL(e.url??"/","http://localhost");return e.method==="POST"&&t.pathname==="/mcp"}async function Mn(e,t,r){if(!mo(e))return!1;let n=r.pairings.verifyToken(ge(e.headers.authorization)??"");if(!n)return R(t,e,null,{error:{code:-32001,message:"Unauthorized: invalid or missing pairing token"}},401);let i;try{i=await pe(e)}catch(o){return R(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 R(t,e,s.id??null,{error:{code:-32600,message:"Invalid JSON-RPC request"}},400);if(s.method==="initialize")return R(t,e,s.id??null,{result:{protocolVersion:po,capabilities:{tools:{}},serverInfo:{name:"babtab-relay",version:ue},instructions:ot}});if(s.method.startsWith("notifications/"))return t.writeHead(202).end(),!0;if(s.method==="tools/list")return R(t,e,s.id??null,{result:{tools:me.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(!T(a))return R(t,e,s.id??null,{result:lt("Tool arguments must be an object")});let l=Be(o);if(!l)return R(t,e,s.id??null,{result:lt(`Unknown tool: ${o}`)});if(!je(n,l.scope))return R(t,e,s.id??null,{result:lt(`Token lacks scope ${l.scope} for ${o}`)});try{let c=await r.registry.routeToDevice(n.deviceId,o,a,13e4,{agentName:n.clientName}),f=[];if(o==="browser_screenshot"&&T(c)&&typeof c.dataUrl=="string"){let d=/^data:(image\/(?:jpeg|png|webp));base64,([A-Za-z0-9+/=]+)$/.exec(c.dataUrl);d&&f.push({type:"image",mimeType:d[1],data:d[2]})}let u=Kt(c),m=JSON.stringify(u)??"null";return f.push({type:"text",text:m.length<=64e3?m:JSON.stringify({truncated:!0,originalLength:m.length,preview:m.slice(0,3e4)})}),R(t,e,s.id??null,{result:{content:f,...T(c)&&c.ok===!1?{isError:!0}:{}}})}catch(c){let f=c;return R(t,e,s.id??null,{result:lt(`${f.code??"DISCONNECTED"}: ${f.message}`,!0)})}}return R(t,e,s.id??null,{error:{code:-32601,message:`Method not found: ${s.method}`}},404)}function lt(e,t=!1){return{content:[{type:"text",text:e}],isError:!0,_meta:{retryable:t}}}function R(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
9
  data: ${s}
10
10
 
11
- `),!0):(e.writeHead(i,{"content-type":"application/json","access-control-allow-origin":"*"}),e.end(s),!0)}function Ht(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ht);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]=Ht(n)}return t}var Xs,Cn=y(()=>{"use strict";Re();Be();Me();Vt();ce();Xs="2024-11-05"});function ot(e={}){let t=new et({persistPath:e.tokenFile??process.env.BABTAB_TOKEN_FILE??"./data/relay-tokens.json"}),r=new rt(process.env.BABTAB_PERF==="1"?f=>process.stderr.write(`${JSON.stringify({type:"babtab:relay-timing",...f})}
12
- `):void 0),n,i=!1,s=new Map,o=new Map,a=(0,On.createServer)((f,h)=>{if(i){h.writeHead(503).end();return}to(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")??"",_=setTimeout(()=>f.close(1008,"device authentication required"),5e3);_.unref(),f.once("close",()=>clearTimeout(_)),f.once("message",w=>{clearTimeout(_);let O;try{O=JSON.parse(String(w))}catch{f.close(1008,"invalid authentication");return}if(!x(O)||O.kind!=="authenticate"||!io(m,O.token)){f.close(1008,"invalid device credential");return}let V=s.get(m);s.set(m,f),ro(f,m,t,r),V?.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)),no(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 d=e.port??0;t.onRevoke(f=>{for(let[h,g]of o)g===f&&h.close(1008,"token revoked")}),a.listen(d,e.host??"127.0.0.1");let u;return n={server:a,pairings:t,registry:r,close:()=>u??=new Promise((f,h)=>{i=!0,clearInterval(c);for(let w of r.onlineDevices())r.failPendingForDevice(w);for(let w of l.clients)w.close(1001,"relay shutting down");let g=setTimeout(()=>{for(let w of l.clients)w.terminate();a.closeAllConnections()},1e3),m=new Promise((w,O)=>a.close(V=>V?O(V):w())),_=new Promise(w=>l.close(()=>w()));Promise.all([m,_]).then(()=>{clearTimeout(g),f()},w=>{clearTimeout(g),h(w)})})},n}async function to(e,t,r){let n=new URL(e.url??"/","http://localhost"),i=e.headers.origin??"",s=/^chrome-extension:\/\/[a-z]{32}$/.test(i)?i:null;if(e.method==="OPTIONS"){let a={"access-control-allow-methods":"GET, POST, OPTIONS","access-control-allow-headers":"content-type, authorization"};s&&(a["access-control-allow-origin"]=s),t.writeHead(204,a),t.end();return}let o=(a,l)=>{let c={"content-type":"application/json"};s&&(c["access-control-allow-origin"]=s),t.writeHead(a,c),t.end(JSON.stringify(l))};if(e.method==="GET"&&n.pathname==="/health"){o(200,{ok:!0,service:"babtab-relay",bridgeVersion:1,devices:r.registry.onlineDevices().length});return}if(e.method==="GET"&&n.pathname==="/client/status"){let a=r.pairings.verifyToken(he(e.headers.authorization)??"");if(!a){o(401,{error:"Unauthorized"});return}o(200,{deviceOnline:r.registry.isDeviceOnline(a.deviceId)});return}if(e.method==="POST"&&n.pathname==="/pairing/request"){let a=await de(e),l=String(a.deviceId??"").slice(0,128);if(!l){o(400,{error:"deviceId required"});return}let c=Array.isArray(a.scopes)?a.scopes.map(String).slice(0,8):["browser:read","browser:act"];try{let d=r.pairings.requestPairing(l,String(a.clientName??"agent"),c);o(200,{code:d.code,expiresAt:d.expiresAt,deviceOnline:r.registry.isDeviceOnline(l)})}catch(d){if(d.code==="RATE_LIMITED"){o(429,{error:d.message});return}throw d}return}if(e.method==="POST"&&n.pathname==="/pairing/claim"){let a=await de(e);o(200,r.pairings.claimPairing(String(a.code??"")));return}if(e.method==="POST"&&n.pathname==="/pairing/revoke"){let a=he(e.headers.authorization)??"",l=a?r.pairings.revokeToken(a):!1;o(200,{ok:l});return}await kn(e,t,r)||o(404,{error:"not found"})}function ro(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(Qe(a.id,"UNSUPPORTED_OPERATION",`Unknown device method ${a.method}`)))}}}),e.on("close",()=>n.unregisterDevice(t,i))}function no(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=Le(o.method);if(!l||!$e(a,l.scope)){e.send(JSON.stringify(Qe(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(Qe(o.id,c.code??"DISCONNECTED",c.message)))})})}function io(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,st.createHash)("sha256").update(t).digest();return(0,st.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 st,On,zt=y(()=>{"use strict";st=require("node:crypto");Re();Me();Be();On=require("node:http");bn();ce();xn();Tn();Be();Cn()});var In={};pr(In,{LocalBridge:()=>lt,parseBridgeArgs:()=>so,runStdio:()=>oo});function so(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 oo(e,t=process.stdin,r=process.stdout){let n=new lt(e,u=>process.stderr.write(`[babtab] ${u}
13
- `)),i=setInterval(()=>{n.tick()},2e3);n.tick();let s=(u,f)=>r.write(`${JSON.stringify({jsonrpc:"2.0",id:u,...f})}
14
- `),o=!1,a=()=>{},l=async u=>{let f;try{f=JSON.parse(u)}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.3.0"},instructions:nt}});else if(f.method==="ping")s(f.id,{result:{}});else if(f.method==="tools/list")s(f.id,{result:{tools:ue.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 d=u=>{c+=u;let f;for(;(f=c.indexOf(`
15
- `))!==-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(u=>{a=()=>u(),t.on("data",d),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",d),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 Pn,R,Nn,at,lt,Rn=y(()=>{"use strict";Pn=require("node:crypto"),R=require("node:fs"),Nn=require("node:os"),at=require("node:path");zt();Re();Me();Vt();ce();lt=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,at.join)((0,Nn.homedir)(),".babtab");let n=(0,Pn.createHash)("sha256").update(`${this.base}/${t.deviceId}/${t.clientName}`).digest("hex");this.credentialPath=(0,at.join)(this.dataDir,`client-${n}.json`);try{let i=JSON.parse((0,R.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,R.mkdirSync)(this.dataDir,{recursive:!0,mode:448});let t=ot({port:this.opts.port,tokenFile:(0,at.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,R.mkdirSync)(this.dataDir,{recursive:!0,mode:448});let s=`${this.credentialPath}.${process.pid}.tmp`;(0,R.writeFileSync)(s,JSON.stringify({token:this.token}),{mode:384}),(0,R.chmodSync)(s,384),(0,R.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 ct(){let e=(0,Ln.homedir)();return{platform:process.platform,home:e,appData:process.env.APPDATA??(0,S.join)(e,"AppData","Roaming"),localAppData:process.env.LOCALAPPDATA??(0,S.join)(e,"AppData","Local")}}function Dn(e,t){let r=t?"Code - Insiders":"Code";return e.platform==="win32"?(0,S.join)(e.appData,r,"User"):e.platform==="darwin"?(0,S.join)(e.home,"Library","Application Support",r,"User"):(0,S.join)(e.home,".config",r,"User")}function ao(e){return e.platform==="win32"?(0,S.join)(e.appData,"Claude","claude_desktop_config.json"):e.platform==="darwin"?(0,S.join)(e.home,"Library","Application Support","Claude","claude_desktop_config.json"):(0,S.join)(e.home,".config","Claude","claude_desktop_config.json")}function Mn(e){let t=e.trim().toLowerCase();return Se.find(r=>r.id===t||r.aliases.includes(t))}function ft(e,t){return{url:`${e}/mcp`,headers:{Authorization:`Bearer ${t}`}}}function Jt(e,t){return{type:"http",...ft(e,t)}}function Kt(e,t){return{command:"npx",args:["-y","mcp-remote",`${e}/mcp`,"--allow-http","--header",`Authorization:Bearer ${t}`]}}function $n(e,t,r){switch(e){case"copilot-http":return Jt(t,r);case"stdio-remote":return Kt(t,r);case"http":default:return ft(t,r)}}function Bn(e,t){return`url = ${JSON.stringify(`${e}/mcp`)}
16
- http_headers = { "Authorization" = ${JSON.stringify(`Bearer ${t}`)} }`}function Un(e,t){return`mcp_servers:
11
+ `),!0):(e.writeHead(i,{"content-type":"application/json","access-control-allow-origin":"*"}),e.end(s),!0)}function Kt(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Kt);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]=Kt(n)}return t}var po,$n=y(()=>{"use strict";Me();Fe();Ue();Yt();de();at();po="2024-11-05"});function Bn(e,t){if(!t)return!0;if(!e)return!1;let r=e.match(/^(\[[^\]]+\]|[^:]+)(?::\d+)?$/);return!!r&&jn.has(r[1].toLowerCase())}function ft(e={}){let t=new nt({persistPath:e.tokenFile??process.env.BABTAB_TOKEN_FILE??"./data/relay-tokens.json"}),r=new st(process.env.BABTAB_PERF==="1"?d=>process.stderr.write(`${JSON.stringify({type:"babtab:relay-timing",...d})}
12
+ `):void 0),n,i=!1,s=new Map,o=new Map,a=jn.has(e.host??"127.0.0.1"),l=(0,Un.createServer)((d,h)=>{if(i){h.writeHead(503).end();return}if(!Bn(d.headers.host,a)){h.writeHead(403,{"content-type":"application/json"}).end(JSON.stringify({error:"Forbidden host"}));return}_o(d,h,n).catch(p=>{h.headersSent||h.writeHead(p.status??500,{"content-type":"application/json"}),h.end(JSON.stringify({error:p.status?p.message:"Internal server error"}))})}),c=new Jt.default({server:l,maxPayload:8*1024*1024});c.on("error",()=>{}),c.on("connection",(d,h)=>{if(d.on("error",()=>d.terminate()),i){d.close(1001,"relay shutting down");return}if(!Bn(h.headers.host,a)){d.close(1008,"forbidden host");return}let p=new URL(h.url??"/","http://localhost");if(p.pathname==="/device"){let _=p.searchParams.get("deviceId")??"",w=setTimeout(()=>d.close(1008,"device authentication required"),5e3);w.unref(),d.once("close",()=>clearTimeout(w)),d.once("message",E=>{clearTimeout(w);let U;try{U=JSON.parse(String(E))}catch{d.close(1008,"invalid authentication");return}if(!T(U)||U.kind!=="authenticate"||!So(_,U.token)){d.close(1008,"invalid device credential");return}let N=s.get(_);s.set(_,d),yo(d,_,t,r),N?.close(1008,"device reconnected"),d.once("close",()=>{s.get(_)===d&&s.delete(_)}),d.send(JSON.stringify({kind:"authenticated"}))})}else if(p.pathname==="/client"){let _=p.searchParams.get("token")??"";o.set(d,_),d.once("close",()=>o.delete(d)),bo(d,_,t,r)}else d.close(1008,"unknown path")});let f=setInterval(()=>{for(let d of c.clients){let h=o.get(d);if(h&&!t.verifyToken(h)){d.close(1008,"token expired or revoked");continue}if(d.isAlive===!1){d.terminate();continue}d.isAlive=!1,d.ping()}},2e4);f.unref?.(),c.on("connection",d=>{d.isAlive=!0,d.on("pong",()=>{d.isAlive=!0})});let u=e.port??0;t.onRevoke(d=>{for(let[h,p]of o)p===d&&h.close(1008,"token revoked")}),l.listen(u,e.host??"127.0.0.1");let m;return n={server:l,pairings:t,registry:r,close:()=>m??=new Promise((d,h)=>{i=!0,clearInterval(f);for(let E of r.onlineDevices())r.failPendingForDevice(E);for(let E of c.clients)E.close(1001,"relay shutting down");let p=setTimeout(()=>{for(let E of c.clients)E.terminate();l.closeAllConnections()},1e3),_=new Promise((E,U)=>l.close(N=>N?U(N):E())),w=new Promise(E=>c.close(()=>E()));Promise.all([_,w]).then(()=>{clearTimeout(p),d()},E=>{clearTimeout(p),h(E)})})},n}async function _o(e,t,r){let n=new URL(e.url??"/","http://localhost"),i=e.headers.origin??"",s=/^chrome-extension:\/\/[a-z]{32}$/.test(i)?i:null;if(e.method==="OPTIONS"){let a={"access-control-allow-methods":"GET, POST, OPTIONS","access-control-allow-headers":"content-type, authorization"};s&&(a["access-control-allow-origin"]=s),t.writeHead(204,a),t.end();return}let o=(a,l)=>{let c={"content-type":"application/json"};s&&(c["access-control-allow-origin"]=s),t.writeHead(a,c),t.end(JSON.stringify(l))};if(e.method==="GET"&&n.pathname==="/health"){o(200,{ok:!0,service:"babtab-relay",bridgeVersion:1,devices:r.registry.onlineDevices().length});return}if(e.method==="GET"&&n.pathname==="/client/status"){let a=r.pairings.verifyToken(ge(e.headers.authorization)??"");if(!a){o(401,{error:"Unauthorized"});return}o(200,{deviceOnline:r.registry.isDeviceOnline(a.deviceId)});return}if(e.method==="POST"&&n.pathname==="/pairing/request"){let a=await pe(e),l=String(a.deviceId??"").slice(0,128);if(!l){o(400,{error:"deviceId required"});return}let c=Array.isArray(a.scopes)?a.scopes.map(String).slice(0,8):["browser:read","browser:act"];try{let f=r.pairings.requestPairing(l,String(a.clientName??"agent"),c);o(200,{code:f.code,expiresAt:f.expiresAt,deviceOnline:r.registry.isDeviceOnline(l)})}catch(f){if(f.code==="RATE_LIMITED"){o(429,{error:f.message});return}throw f}return}if(e.method==="POST"&&n.pathname==="/pairing/claim"){let a=await pe(e),l=r.pairings.claimPairing(String(a.code??""),Date.now(),e.socket.remoteAddress??"unknown");if(l.rateLimited){o(429,{error:"Too many invalid pairing code guesses; wait one minute and retry."});return}o(200,l);return}if(e.method==="POST"&&n.pathname==="/pairing/revoke"){let a=ge(e.headers.authorization)??"",l=a?r.pairings.revokeToken(a):!1;o(200,{ok:l});return}await Mn(e,t,r)||o(404,{error:"not found"})}function yo(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(!Fn(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"){if(a.kind==="ping"){i(JSON.stringify({kind:"pong"}));return}if(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(rt(a.id,"UNSUPPORTED_OPERATION",`Unknown device method ${a.method}`)))}}}}),e.on("close",()=>n.unregisterDevice(t,i))}function bo(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(!Fn(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=Be(o.method);if(!l||!je(a,l.scope)){e.send(JSON.stringify(rt(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(rt(o.id,c.code??"DISCONNECTED",c.message)))})})}function So(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,ct.createHash)("sha256").update(t).digest();return(0,ct.timingSafeEqual)(r,Buffer.from(e.slice(7),"hex"))}function Fn(e){return T(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||T(e.params)):e.kind==="response"&&(e.error===void 0||T(e.error)&&typeof e.error.code=="string"&&typeof e.error.message=="string"):!1}var ct,Un,jn,Zt=y(()=>{"use strict";ct=require("node:crypto");Me();Ue();Fe();Un=require("node:http");kn();de();Rn();Ln();Fe();$n();jn=new Set(["127.0.0.1","localhost","::1","[::1]"])});var Hn={};vr(Hn,{DEFAULT_START_GRACE_MS:()=>Xt,LocalBridge:()=>ut,parseBridgeArgs:()=>Eo,portConflictMessage:()=>Qt,runStdio:()=>xo,suggestAlternatePort:()=>Vn});function vo(){let e=process.env.BABTAB_START_GRACE_MS;if(e===void 0||e==="")return Xt;let t=Number(e);return Number.isFinite(t)&&t>=0?t:Xt}function Vn(e){return!Number.isInteger(e)||e<1||e>=65535?3001:e+1}function Qt(e,t){let r=Vn(e),n=process.platform==="win32"?`netstat -ano | findstr :${e}`:`lsof -iTCP:${e} -sTCP:LISTEN`;return t==="foreign"?`Port ${e} is in use by another service or an older Babtab. Stop the old process (${n}) or switch to port ${r} in Advanced connection settings, then re-add Babtab in your AI tool.`:`Port ${e} is held by a process that is not responding. Stop the frozen babtab-relay (a terminal job paused with Ctrl+Z often causes this; ${n}), reload MCP, or switch to port ${r} in Advanced connection settings and re-add Babtab.`}function Eo(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 xo(e,t=process.stdin,r=process.stdout){let n=new ut(e,d=>process.stderr.write(`[babtab] ${d}
13
+ `)),i,s=!0,o=()=>{s&&n.tick().finally(()=>{s&&(i=setTimeout(o,n.relayUp?2e3:500))})};o();let a=(d,h)=>r.write(`${JSON.stringify({jsonrpc:"2.0",id:d,...h})}
14
+ `),l=!1,c=()=>{},f=async d=>{let h;try{h=JSON.parse(d)}catch{a(null,{error:{code:-32700,message:"Parse error"}});return}if(!T(h)||h.jsonrpc!=="2.0"||typeof h.method!="string"||h.id!==void 0&&typeof h.id!="string"&&typeof h.id!="number"){a(null,{error:{code:-32600,message:"Invalid Request"}});return}if(h.id!==void 0)if(h.method==="initialize"){let p=T(h.params)?h.params.protocolVersion:void 0,_=typeof p=="string"&&Wn.includes(p)?p:Wn[0];a(h.id,{result:{protocolVersion:_,capabilities:{tools:{}},serverInfo:{name:"babtab",version:ue},instructions:ot}})}else if(h.method==="ping")a(h.id,{result:{}});else if(h.method==="tools/list")a(h.id,{result:{tools:me.map(({name:p,description:_,inputSchema:w})=>({name:p,description:_,inputSchema:w}))}});else if(h.method==="tools/call"){let p=await n.call(h);l||a(h.id,p.error?{error:p.error}:{result:p.result})}else a(h.id,{error:{code:-32601,message:`Method not found: ${h.method}`}})},u="";t.setEncoding("utf8");let m=d=>{u+=d;let h;for(;(h=u.indexOf(`
15
+ `))!==-1;){let p=u.slice(0,h);if(u=u.slice(h+1),Buffer.byteLength(p)>1048576){t.destroy(new Error("MCP message too large"));return}p.trim()&&f(p)}Buffer.byteLength(u)>1048576&&t.destroy(new Error("MCP message too large"))};try{await new Promise(d=>{c=()=>d(),t.on("data",m),t.once("end",c),t.once("close",c),t.once("error",c),process.once("SIGTERM",c),process.once("SIGINT",c)})}finally{l=!0,s=!1,i&&clearTimeout(i),t.off("data",m),t.off("end",c),t.off("close",c),t.off("error",c),process.off("SIGTERM",c),process.off("SIGINT",c),t.pause(),await n.close()}}var qn,D,Gn,dt,Xt,wo,Wn,ut,zn=y(()=>{"use strict";qn=require("node:crypto"),D=require("node:fs"),Gn=require("node:os"),dt=require("node:path");Zt();Me();Ue();Yt();at();de();Xt=8e3;wo=1500,Wn=["2024-11-05","2025-03-26","2025-06-18"];ut=class{opts;log;owned;token="";pending;tickPromise;stopped=!1;relayReady=!1;lastOkAt=0;abort=new AbortController;nextPairAt=0;waitForRelaySince=0;dataDir;credentialPath;base;get relayUp(){return this.relayReady}get ready(){return this.relayReady&&!!this.token}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,dt.join)((0,Gn.homedir)(),".babtab");let n=(0,qn.createHash)("sha256").update(`${this.base}/${t.deviceId}/${t.clientName}`).digest("hex");this.credentialPath=(0,dt.join)(this.dataDir,`client-${n}.json`);try{let i=JSON.parse((0,D.readFileSync)(this.credentialPath,"utf8"));T(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||!T(n)||n.service!=="babtab-relay"||n.bridgeVersion!==1)throw new Error(Qt(this.opts.port,"foreign"));this.waitForRelaySince=0;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=ft({port:this.opts.port,tokenFile:(0,dt.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,this.waitForRelaySince=0}catch(r){throw await t.close().catch(()=>{}),r.code!=="EADDRINUSE"?r:(this.waitForRelaySince||(this.waitForRelaySince=Date.now()),Date.now()-this.waitForRelaySince<vo()?new Error("Waiting for the local bridge to start\u2026"):new Error(Qt(this.opts.port,"held")))}}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.",this.lastOkAt=Date.now();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(this.ready&&Date.now()-this.lastOkAt<wo||await this.tick(),!this.relayReady||!this.token)return{result:{isError:!0,content:[{type:"text",text:this.status}]}};try{let r=await this.requestMcp(t);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(!T(n))throw new Error("Invalid response from Babtab");return n}catch(r){return{result:{isError:!0,content:[{type:"text",text:r.message}]}}}}async requestMcp(t){try{return await this.request("/mcp",t,this.token)}catch(r){if((r.cause?.code??"")!=="ECONNREFUSED"||this.stopped)throw r;if(this.lastOkAt=0,await this.tick(),!this.relayReady||!this.token)throw new Error(this.status);return this.request("/mcp",t,this.token)}}async close(){this.stopped=!0,this.abort.abort(),await this.tickPromise,await this.owned?.close()}}});function ht(){let e=(0,Yn.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 Jn(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 To(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 Kn(e){let t=e.trim().toLowerCase();return xe.find(r=>r.id===t||r.aliases.includes(t))}function pt(e,t){return{url:`${e}/mcp`,headers:{Authorization:`Bearer ${t}`}}}function er(e,t){return{type:"http",...pt(e,t)}}function tr(e,t){return{command:"npx",args:["-y","mcp-remote",`${e}/mcp`,"--allow-http","--header",`Authorization:Bearer ${t}`]}}function Zn(e,t,r){switch(e){case"copilot-http":return er(t,r);case"stdio-remote":return tr(t,r);default:return pt(t,r)}}function Xn(e,t){return`url = ${JSON.stringify(`${e}/mcp`)}
16
+ http_headers = { "Authorization" = ${JSON.stringify(`Bearer ${t}`)} }`}function Qn(e,t){return`mcp_servers:
17
17
  babtab:
18
18
  url: "${e}/mcp"
19
19
  headers:
20
- 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 Ln,S,Se,Yt=y(()=>{"use strict";Ln=require("node:os"),S=require("node:path");Se=[{id:"cursor",label:"Cursor",aliases:[],paths:e=>[(0,S.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,S.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,S.join)(Dn(e,!1),"mcp.json")],action:{kind:"json",rootKey:"servers",entry:"copilot-http"},nextStep:"VS Code: reload window, then check MCP Servers view for babtab."},{id:"copilot-insiders",label:"Copilot (VS Code Insiders)",aliases:["vscode-insiders","code-insiders","insiders"],paths:e=>[(0,S.join)(Dn(e,!0),"mcp.json")],action:{kind:"json",rootKey:"servers",entry:"copilot-http"},nextStep:"VS Code Insiders: reload window, then check MCP Servers view for babtab."},{id:"codex",label:"Codex",aliases:[],paths:e=>[(0,S.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=>[ao(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,S.join)(e.home,".gemini","antigravity","mcp_config.json"),(0,S.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,S.join)(e.appData,"devin","mcp_config.json")]:[(0,S.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,S.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,S.join)(e.home,".hermes","config.yaml"),(0,S.join)(e.localAppData,"hermes","config.yaml")]:[(0,S.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 lo(e,t){let r=e.slice(0,t).split(/\r?\n/);return[r.length,r.pop().length+1]}function co(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
+ Authorization: "Bearer ${t}"`}function ei(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 Yn,v,xe,rr=y(()=>{"use strict";Yn=require("node:os"),v=require("node:path");xe=[{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)(Jn(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)(Jn(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=>[To(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 ko(e,t){let r=e.slice(0,t).split(/\r?\n/);return[r.length,r.pop().length+1]}function Co(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+=`
21
21
  `,o===t&&(i+=" ".repeat(s+r+2),i+=`^
22
- `))}return i}var p,X=y(()=>{p=class e extends Error{line;column;codeblock;constructor(t,r){let[n,i]=lo(r.toml,r.ptr),s=co(r.toml,n,i);super(`Invalid TOML document: ${t}
22
+ `))}return i}var g,te=y(()=>{g=class e extends Error{line;column;codeblock;constructor(t,r){let[n,i]=ko(r.toml,r.ptr),s=Co(r.toml,n,i);super(`Invalid TOML document: ${t}
23
23
 
24
- ${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 dt(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,d=0,u=r===120?2:r===117?4:8;for(let f=0;f<u;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),d=d<<4|g}(d<0||d>1114111||d>=55296&&d<=57343)&&p.x("invalid unicode escape",e,c),o+=String.fromCodePoint(d),a=e.p--,l=0}else s&&(r===32||r===9)?l=2:(r===98?o+="\b":r===116?o+=" ":r===110?o+=`
25
- `: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 Zt=y(()=>{X();});var fo,we,Xt=y(()=>{fo=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,we=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(fo);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 er(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function xe(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?dt(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?ut(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?uo(e,n,t):e.s.charCodeAt(e.p+2)===58?ho(e,n,t):ut(e,e.p,n,0,t)}function ut(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||er(s=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!n){if(s===120)return Qt(e,t,16,i);if(s===98)return Qt(e,t,2,i);if(s===111)return Qt(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),!er(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 Qt(e,t,r,n){let i,s=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!er(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 uo(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 ut(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 Ee(e,o,3,!1,n)}if(e.s.charCodeAt(e.p+=3)!==58&&p.x("invalid date-time: time part is malformed",e,n),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;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 Ee(e,o,1,i,n,"[+00:00]")}if(t===43||t===45){let o=e.s.slice(n,e.p+=6);return Ee(e,o,1,i,n,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let s=e.s.slice(n,e.p);return Ee(e,s,2,i,n)}function ho(e,t,r){let n=e.p;if(!C(t)||!C(e.s.charCodeAt(++e.p)))return ut(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 Ee(e,i,4,!1,n)}function Ee(e,t,r,n,i,s){if(e.ld){let o=new we(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 tr=y(()=>{Zt();rr();X();Xt();});function po(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 D(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;po(e)}}var nr=y(()=>{X();});function ht(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(dt(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(D(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,r;let s,o=r,a=!1,l=e.p,c=ht(e);for(let u=0;u<c.length;u++){u&&(o=a?o[s]:o[s]=Object.create(null)),s=c[u],(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),D(e,!0,!0);let d=xe(e,125);if(o&&typeof(o[s]=d)=="object"&&n.add(d),D(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(D(e),(n=e.s.charCodeAt(e.p))===93)return e.p++,r;if(r.push(xe(e,93)),D(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 rr=y(()=>{Zt();tr();nr();X();});function Gn(e,t,r,n,i){let s=r,o=n,a,l=!1,c;for(let d=0;d<t.length;d++){if(d){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 u=s.length-1;s=s[u],o=o[u].c}}if(a=t[d],(l=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!l){let u=a==="__proto__";if(e.uk&&(u||a==="constructor"))return!1;u&&(Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0})),o[a]={t:d<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 Te(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++,D(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 d=ht(r,93);c&&(e.charCodeAt(r.p)!==93&&p.x("expected end of table array declaration",r),r.p++);let u=Gn(r,d,n,i,c?2:1);u?(l=u[2],a=u[1]):(Vn(r,u,s),o=!0)}else{s=r.p;let c=ht(r),d=Gn(r,c,a,l,0);!d&&!o&&Vn(r,d,s),D(r,!0,!0);let u=xe(r,void 0);d&&!o&&(d[1][d[0]]=u)}D(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),D(r)}return n}var Hn=y(()=>{rr();tr();nr();X();});function ke(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 go(e){for(let t=0;t<e.length;t++)if(ke(e[t])!=="object")return!1;return e.length!=0}function Jn(e){return JSON.stringify(e).replaceAll("\x7F","\\u007f")}function _o(e){return Jn(zn?e.toWellFormed():e)}function Kn(e){if(mo.test(e))return e;if(zn&&!e.isWellFormed())throw new RangeError("key contains illegal lone surrogates");return Jn(e)}function ir(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 _o(e);case"date":if(isNaN(e.getTime()))throw new TypeError("cannot serialize invalid date");return e.toISOString();case"object":return yo(e,r,n,i);case"array":return bo(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 yo(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)+" = "+ir(e[a],ke(e[a]),t-1,r,n)}return s+" }"}function bo(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+=ir(e[s],ke(e[s]),t-1,r,n)}return i+" ]"}function vo(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&&`
24
+ ${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 mt(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)g.x("control characters are not allowed in strings",e);else if((!l||l===3)&&r===n&&(!s||e.s.charCodeAt(e.p+1)===n&&e.s.charCodeAt(e.p+2)===n)){if(s&&(e.s.charCodeAt(e.p+3)===n&&e.p++,e.s.charCodeAt(e.p+3)===n&&e.p++),!l){let c=e.s.slice(a,e.p);o=o?o+c:c}return e.p+=s?3:1,o}else if(!l)!i&&r===92&&(o+=e.s.slice(a,a=e.p),l=1);else if(l===1)if(r===120||r===117||r===85){let c=e.p++-1,f=0,u=r===120?2:r===117?4:8;for(let m=0;m<u;m++,e.p++){let d=e.s.charCodeAt(e.p),h=d>=48&&d<=57?d-48:d>=65&&d<=70?d-65+10:d>=97&&d<=102?d-97+10:-1;h<0&&g.x("invalid non-hex character in unicode escape",e),f=f<<4|h}(f<0||f>1114111||f>=55296&&f<=57343)&&g.x("invalid unicode escape",e,c),o+=String.fromCodePoint(f),a=e.p--,l=0}else s&&(r===32||r===9)?l=2:(r===98?o+="\b":r===116?o+=" ":r===110?o+=`
25
+ `:r===102?o+="\f":r===114?o+="\r":r===101?o+="\x1B":r===34?o+='"':r===92?o+="\\":g.x("unrecognised escape sequence",e),a=e.p+1,l=0);else r!==32&&r!==9&&(l===2&&g.x("invalid escape: only line-ending whitespace may be escaped",e,a),l=!i&&r===92?1:0,a=e.p);g.x("unfinished string",e,t)}var nr=y(()=>{te();});var Oo,Te,ir=y(()=>{Oo=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,Te=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(Oo);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 O(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function or(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function Ce(e,t){let r=e.p,n=e.s.charCodeAt(e.p);if(n===91||n===123){e.d--||g.x("document contains excessively nested structures. aborting.",e);let i=n===91?ni(e):ri(e);return e.d++,i}return n===34||n===39?mt(e):n===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&g.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)&&g.x("invalid value",e,r),e.p++,!1):n===43||n===45?gt(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?Ao(e,n,t):e.s.charCodeAt(e.p+2)===58?Po(e,n,t):gt(e,e.p,n,0,t)}function gt(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)&&g.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)&&g.x("invalid value",e,t),e.p++,NaN;if(s===48){if(++e.p>=e.s.length||or(s=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!n){if(s===120)return sr(e,t,16,i);if(s===98)return sr(e,t,2,i);if(s===111)return sr(e,t,8,i)}s===46?o=2:s===101||s===69?o=4:g.x("illegal leading zero",e,t)}else O(s)||g.x("invalid value",e,t);for(;++e.p<e.s.length&&(s=e.s.charCodeAt(e.p),!or(s,i));)o||(o=1),s===95?(o&1||g.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)||(O(s)?o>9?o-=11:o&1||o++:g.x("illegal character in numeric literal",e));if(!o){let c=(r-48)*(n||1);return e.bi===!0?BigInt(c):c}o&1||g.x("unfinished numeric value",e,t);let l=e.s.slice(t,e.p);return a&&(l=l.replaceAll("_","")),o>1?parseFloat(l):ti(e,l,10,t)}function sr(e,t,r,n){let i,s=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!or(i,n));)i===95?(s&1&&g.x("illegal underscore",e),s=3):O(i,r)?s&1&&s--:g.x("illegal character in numeric literal",e);s&1&&g.x("unfinished numeric value",e);let o=e.s.slice(t+2,e.p);return s&&(o=o.replaceAll("_","")),ti(e,o,r,t)}function ti(e,t,r,n){if(e.bi!==!0)e:{let i=parseInt(t,r);if(!Number.isSafeInteger(i)){if(e.bi)break e;g.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 Ao(e,t,r){let n=e.p++,i;if(!O(t)||!O(e.s.charCodeAt(e.p++))||!O(e.s.charCodeAt(e.p++))||!O(e.s.charCodeAt(e.p++)))return gt(e,e.p=n,t,0,r);if(e.p+=5,O(e.s.charCodeAt(e.p++))||g.x("invalid date-time: date part is malformed",e,n),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(i=!0,!O(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let o=e.s.slice(n,e.p);return ke(e,o,3,!1,n)}if(e.s.charCodeAt(e.p+=3)!==58&&g.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(;O(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 ke(e,o,1,i,n,"[+00:00]")}if(t===43||t===45){let o=e.s.slice(n,e.p+=6);return ke(e,o,1,i,n,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let s=e.s.slice(n,e.p);return ke(e,s,2,i,n)}function Po(e,t,r){let n=e.p;if(!O(t)||!O(e.s.charCodeAt(++e.p)))return gt(e,--e.p,t,0,r);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;O(e.s.charCodeAt(++e.p)););let i=e.s.slice(n,e.p);return ke(e,i,4,!1,n)}function ke(e,t,r,n,i,s){if(e.ld){let o=new Te(t,r,n);return o.isValid()||g.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){g.x(o instanceof Error?o.message:""+o,e,i)}}var ar=y(()=>{nr();lr();te();ir();});function No(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)&&g.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;No(e)}}var cr=y(()=>{te();});function _t(e,t=61){let r,n=0,i=[],s,o=e.s.charCodeAt(r=e.p);do{if(o===t)return n||g.x("unexpected end of key",e),n===1&&i.push(e.s.slice(s,e.p)),e.p++,i;o===46?(n||g.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)&&g.x("illegal quoted key: multiline strings are not allowed",e),i.push(mt(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?g.x("illegal character in key",e):n||(n=1,s=e.p)}while(o=e.s.charCodeAt(++e.p));g.x("incomplete key-value: cannot find end of key",e,r)}function ri(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=_t(e);for(let u=0;u<c.length;u++){u&&(o=a?o[s]:o[s]=Object.create(null)),s=c[u],(a=Object.hasOwn(o,s))&&(typeof o[s]!="object"||n.has(o[s]))&&g.x("trying to redefine an already defined value",e,l);let m=s==="__proto__";if(e.uk&&(m||s==="constructor")){o=e.uk!==1&&g.x("document contains an unsafe property",e,l);break}!a&&m&&Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})}a&&g.x("trying to redefine an already defined value",e,l),L(e,!0,!0);let f=Ce(e,125);if(o&&typeof(o[s]=f)=="object"&&n.add(f),L(e),(i=e.s.charCodeAt(e.p++))===125)return r;i!==44&&g.x("expected comma or end of structure",e,e.p-1)}g.x("unfinished table",e,t)}function ni(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(Ce(e,93)),L(e),(n=e.s.charCodeAt(e.p++))===93)return r;n!==44&&g.x("expected comma or end of structure",e,e.p-1)}g.x("unfinished array",e,t)}var lr=y(()=>{nr();ar();cr();te();});function ii(e,t,r,n,i){let s=r,o=n,a,l=!1,c;for(let f=0;f<t.length;f++){if(f){if(s=l?s[a]:s[a]=Object.create(null),o=(c=o[a]).c,i===0&&(c.t===1||c.t===2))return null;if(c.t===2){let u=s.length-1;s=s[u],o=o[u].c}}if(a=t[f],(l=Object.hasOwn(s,a))&&o[a]?.t===0&&o[a]?.d)return null;if(!l){let u=a==="__proto__";if(e.uk&&(u||a==="constructor"))return!1;u&&(Object.defineProperty(s,a,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,a,{enumerable:!0,configurable:!0,writable:!0})),o[a]={t:f<t.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(c=o[a],c.t!==i&&!(i===1&&c.t===3)||(i===2&&(c.d||(c.d=!0,s[a]=[]),s[a].push(s=Object.create(null)),c.c[c.i++]=c={t:1,d:!1,i:0,c:Object.create(null)}),c.d))return null;if(c.d=!0,i===1)s=l?s[a]:s[a]=Object.create(null);else if(i===0&&l)return null;return[a,s,c.c]}function si(e,t,r){(t===null||e.uk===2)&&g.x(t===null?"trying to redefine an already defined table or value":"document contains an unsafe property",e,r)}function Oe(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 f=_t(r,93);c&&(e.charCodeAt(r.p)!==93&&g.x("expected end of table array declaration",r),r.p++);let u=ii(r,f,n,i,c?2:1);u?(l=u[2],a=u[1]):(si(r,u,s),o=!0)}else{s=r.p;let c=_t(r),f=ii(r,c,a,l,0);!f&&!o&&si(r,f,s),L(r,!0,!0);let u=Ce(r,void 0);f&&!o&&(f[1][f[0]]=u)}L(r,!0),r.p<e.length&&(s=e.charCodeAt(r.p))!==10&&(s!==13||e.charCodeAt(r.p+1)!==10)&&g.x("each key-value declaration must be followed by an end-of-line",r),L(r)}return n}var oi=y(()=>{lr();ar();cr();te();});function Ae(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 Ro(e){for(let t=0;t<e.length;t++)if(Ae(e[t])!=="object")return!1;return e.length!=0}function li(e){return JSON.stringify(e).replaceAll("\x7F","\\u007f")}function Do(e){return li(ai?e.toWellFormed():e)}function ci(e){if(Io.test(e))return e;if(ai&&!e.isWellFormed())throw new RangeError("key contains illegal lone surrogates");return li(e)}function fr(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 Do(e);case"date":if(isNaN(e.getTime()))throw new TypeError("cannot serialize invalid date");return e.toISOString();case"object":return Lo(e,r,n,i);case"array":return Mo(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 Lo(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+=ci(a)+" = "+fr(e[a],Ae(e[a]),t-1,r,n)}return s+" }"}function Mo(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+=fr(e[s],Ae(e[s]),t-1,r,n)}return i+" ]"}function $o(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&&`
26
26
  `}[[${t}]]
27
- `,s+=sr(0,e[o],t,r,n,i);return s}function sr(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 d=l[c];if(t[d]!==null&&t[d]!==void 0){let u=ke(t[d]);if(u==="symbol"||u==="function")throw new TypeError(`cannot serialize values of type '${u}'`);let f=Kn(d);if(u==="array"&&go(t[d]))a+=(a&&`
28
- `)+vo(t[d],r?`${r}.${f}`:f,n-1,i,s);else if(u==="object"){let h=r?`${r}.${f}`:f;a+=(a&&`
29
- `)+sr(h,t[d],h,n-1,i,s)}else o+=f,o+=" = ",o+=ir(t[d],u,n,i,s),o+=`
27
+ `,s+=dr(0,e[o],t,r,n,i);return s}function dr(e,t,r,n,i,s){if(n===0)throw new Error("Could not stringify the object: maximum object depth exceeded");let o="",a="",l=Object.keys(t);for(let c=0;c<l.length;c++){let f=l[c];if(t[f]!==null&&t[f]!==void 0){let u=Ae(t[f]);if(u==="symbol"||u==="function")throw new TypeError(`cannot serialize values of type '${u}'`);let m=ci(f);if(u==="array"&&Ro(t[f]))a+=(a&&`
28
+ `)+$o(t[f],r?`${r}.${m}`:m,n-1,i,s);else if(u==="object"){let d=r?`${r}.${m}`:m;a+=(a&&`
29
+ `)+dr(d,t[f],d,n-1,i,s)}else o+=m,o+=" = ",o+=fr(t[f],u,n,i,s),o+=`
30
30
  `}}return e&&(o||!a)&&(o=o?`[${e}]
31
31
  ${o}`:`[${e}]`),o&&a?`${o}
32
- ${a}`:o||a}function or(e,{maxDepth:t=1e3,numbersAsFloat:r=!1,strictTemporal:n=!1}={}){if(ke(e)!=="object")throw new TypeError("stringify can only be called with an object");let i=sr(0,e,"",t,r,n);return i[i.length-1]!==`
32
+ ${a}`:o||a}function ur(e,{maxDepth:t=1e3,numbersAsFloat:r=!1,strictTemporal:n=!1}={}){if(Ae(e)!=="object")throw new TypeError("stringify can only be called with an object");let i=dr(0,e,"",t,r,n);return i[i.length-1]!==`
33
33
  `?i+`
34
- `:i}var mo,zn,Yn=y(()=>{mo=/^[a-z0-9-_]+$/i,zn=!!"".isWellFormed});var Zn=y(()=>{Hn();Yn();Xt();X();});function mt(e,t){let r=e.paths(t);if(r.length===0)return null;for(let n of r)try{if((0,b.statSync)((0,Ce.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
+ `:i}var Io,ai,fi=y(()=>{Io=/^[a-z0-9-_]+$/i,ai=!!"".isWellFormed});var di=y(()=>{oi();fi();ir();te();});function bt(e,t){let r=e.paths(t);if(r.length===0)return null;for(let n of r)try{if((0,b.statSync)((0,Pe.dirname)(n)).isDirectory())return n}catch{}return r[0]}function Bo(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]!==`
35
35
  `;)r++;continue}if(s==="/"&&o==="*"){for(r+=2;r<e.length&&!(e[r]==="*"&&e[r+1]==="/");)e[r]===`
36
36
  `&&(t+=`
37
- `),r++;r+=2;continue}t+=s,r++}return t}function pt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Oe(e){try{return(0,b.existsSync)(e)?((0,b.writeFileSync)(`${e}.bak`,(0,b.readFileSync)(e)),!0):!1}catch{return!1}}function gt(e){let{path:t,rootKey:r,serverName:n,entry:i}=e,s=(0,b.existsSync)(t),o={};if(s){let c=(0,b.readFileSync)(t,"utf8"),d;try{d=JSON.parse(c.trim()===""?"{}":So(c))}catch{throw new Error(`Existing config is not valid JSON: ${t}
38
- Fix or rename it first (setup left it untouched).`)}if(!pt(d))throw new Error(`Existing config root must be an object: ${t} (left untouched).`);o=d;let u=o[r];if(u!==void 0&&!pt(u))throw new Error(`Existing "${r}" is not an object: ${t} (left untouched).`)}let a=pt(o[r])?o[r]:{};a[n]=i,o[r]=a,(0,b.mkdirSync)((0,Ce.dirname)(t),{recursive:!0});let l=s?Oe(t):!1;return(0,b.writeFileSync)(t,`${JSON.stringify(o,null,2)}
39
- `,{mode:384}),{path:t,created:!s,backedUp:l}}function _t(e,t){let r=(0,b.existsSync)(e),n=r?Te((0,b.readFileSync)(e,"utf8")):{},i=Te(`${wo}
37
+ `),r++;r+=2;continue}t+=s,r++}return t}function yt(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ne(e){try{return(0,b.existsSync)(e)?((0,b.writeFileSync)(`${e}.bak`,(0,b.readFileSync)(e)),!0):!1}catch{return!1}}function St(e){let{path:t,rootKey:r,serverName:n,entry:i}=e,s=(0,b.existsSync)(t),o={};if(s){let c=(0,b.readFileSync)(t,"utf8"),f;try{f=JSON.parse(c.trim()===""?"{}":Bo(c))}catch{throw new Error(`Existing config is not valid JSON: ${t}
38
+ Fix or rename it first (setup left it untouched).`)}if(!yt(f))throw new Error(`Existing config root must be an object: ${t} (left untouched).`);o=f;let u=o[r];if(u!==void 0&&!yt(u))throw new Error(`Existing "${r}" is not an object: ${t} (left untouched).`)}let a=yt(o[r])?o[r]:{};a[n]=i,o[r]=a,(0,b.mkdirSync)((0,Pe.dirname)(t),{recursive:!0});let l=s?Ne(t):!1;return(0,b.writeFileSync)(t,`${JSON.stringify(o,null,2)}
39
+ `,{mode:384}),{path:t,created:!s,backedUp:l}}function vt(e,t){let r=(0,b.existsSync)(e),n=r?Oe((0,b.readFileSync)(e,"utf8")):{},i=Oe(`${Uo}
40
40
  ${t}
41
- `);if(n.mcp_servers!==void 0&&!pt(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=or(n);Te(o),(0,b.mkdirSync)((0,Ce.dirname)(e),{recursive:!0});let a=r?Oe(e):!1;if(r&&!a)throw new Error(`Cannot back up ${e}; left untouched`);let l=`${e}.${(0,Xn.randomUUID)()}.tmp`;try{(0,b.writeFileSync)(l,o,{mode:384,flag:"wx"}),(0,b.renameSync)(l,e)}finally{(0,b.rmSync)(l,{force:!0})}return{path:e,created:!r,backedUp:a}}function yt(e,t){let r=(0,b.existsSync)(e),n;if(!r)n=`${t}
41
+ `);if(n.mcp_servers!==void 0&&!yt(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=ur(n);Oe(o),(0,b.mkdirSync)((0,Pe.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,ui.randomUUID)()}.tmp`;try{(0,b.writeFileSync)(l,o,{mode:384,flag:"wx"}),(0,b.renameSync)(l,e)}finally{(0,b.rmSync)(l,{force:!0})}return{path:e,created:!r,backedUp:a}}function wt(e,t){let r=(0,b.existsSync)(e),n;if(!r)n=`${t}
42
42
  `;else{let s=(0,b.readFileSync)(e,"utf8").split(`
43
43
  `),o=s.findIndex(a=>/^mcp_servers\s*:\s*(#.*)?$/.test(a));if(o===-1){let a=s.length>0&&s[s.length-1].trim()!==""?`
44
44
  `:"";n=`${s.join(`
45
45
  `)}${a}
46
46
  ${t}
47
- `}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)),d=t.split(`
47
+ `}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(m=>/^\s*babtab\s*:\s*(#.*)?$/.test(m)),f=t.split(`
48
48
  `).slice(1).join(`
49
- `),u;if(c===-1)u=[...l,d];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++;u=[...l.slice(0,c),d,...l.slice(h)]}n=[...s.slice(0,o+1),...u,...s.slice(a)].join(`
49
+ `),u;if(c===-1)u=[...l,f];else{let m=l[c].match(/^\s*/)?.[0].length??2,d=c+1;for(;d<l.length&&(l[d].trim()===""||(l[d].match(/^\s*/)?.[0].length??0)>m);)d++;u=[...l.slice(0,c),f,...l.slice(d)]}n=[...s.slice(0,o+1),...u,...s.slice(a)].join(`
50
50
  `),n.endsWith(`
51
51
  `)||(n+=`
52
- `)}}(0,b.mkdirSync)((0,Ce.dirname)(e),{recursive:!0});let i=r?Oe(e):!1;return(0,b.writeFileSync)(e,n,{mode:384}),{path:e,created:!r,backedUp:i}}var Xn,b,Ce,wo,ar=y(()=>{"use strict";Zn();Xn=require("node:crypto"),b=require("node:fs"),Ce=require("node:path");wo="[mcp_servers.babtab]"});function xo(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=ct()){let i=xo(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=mt(e,n);if(!o)throw new Error(`Automatic setup is unavailable for ${e.label}`);s.kind==="json"?gt({path:o,rootKey:s.rootKey,serverName:"babtab",entry:{...i,...s.entry==="copilot-http"?{type:"stdio"}:{}}}):s.kind==="toml-codex"?_t(o,`command = ${JSON.stringify(i.command)}
53
- args = ${JSON.stringify(i.args)}`):s.kind==="yaml-hermes"&&yt(o,`mcp_servers:
52
+ `)}}(0,b.mkdirSync)((0,Pe.dirname)(e),{recursive:!0});let i=r?Ne(e):!1;return(0,b.writeFileSync)(e,n,{mode:384}),{path:e,created:!r,backedUp:i}}var ui,b,Pe,Uo,hr=y(()=>{"use strict";di();ui=require("node:crypto"),b=require("node:fs"),Pe=require("node:path");Uo="[mcp_servers.babtab]"});function Wo(e,t,r,n=process.platform==="win32"){if(!/^dev_v2_[a-f0-9]{64}$/.test(e))throw new Error("Invalid device ID. Copy the command from the Babtab extension.");let i=["-y","--prefer-offline",Fo,"stdio","--device",e,"--client",t,"--port",String(r)];return n?{command:"cmd",args:["/c","npx",...i]}:{command:"npx",args:i}}function hi(e,t,r,n=ht()){let i=Wo(t,e.id,r),s=e.action;if(s.kind==="exec"){(0,pr.spawnSync)("claude",["mcp","remove","babtab","--scope","user"],{stdio:"ignore",shell:process.platform==="win32"});let o=["mcp","add","--transport","stdio","--scope","user","babtab","--",i.command,...i.args],a=(0,pr.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 it still fails, run `claude mcp remove babtab` and retry.")}else{let o=bt(e,n);if(!o)throw new Error(`Automatic setup is unavailable for ${e.label}`);s.kind==="json"?St({path:o,rootKey:s.rootKey,serverName:"babtab",entry:{...i,...s.entry==="copilot-http"?{type:"stdio"}:{}}}):s.kind==="toml-codex"?vt(o,`command = ${JSON.stringify(i.command)}
53
+ args = ${JSON.stringify(i.args)}
54
+ startup_timeout_sec = ${jo}`):s.kind==="yaml-hermes"&&wt(o,`mcp_servers:
54
55
  babtab:
55
56
  command: ${JSON.stringify(i.command)}
56
57
  args: ${JSON.stringify(i.args)}`),console.log(`Configured ${o} (existing settings preserved; backup created when replacing a file).`)}return console.log(`
57
58
  ${e.nextStep.replace(" (via mcp-remote bridge)","")}
58
59
  Your AI tool starts Babtab automatically. Open Babtab in Chrome and approve the first connection.
59
- Then ask: "Use babtab to observe the current tab".`),0}var Qn,Eo,ti=y(()=>{"use strict";Qn=require("node:child_process");Yt();ar();Eo="@babtab/relay@0.3.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 lr(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 Ae(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 Pe("Pairing code expired \u2014 run the setup command again.");if(Date.now()>=s)throw new Ne("Timed out waiting for approval \u2014 run the setup command again.");await new Promise(l=>setTimeout(l,n))}}var Q,Ae,Pe,Ne,si=y(()=>{"use strict";Q=class extends Error{},Ae=class extends Error{},Pe=class extends Error{},Ne=class extends Error{}});var fr={};pr(fr,{DEFAULT_PORT:()=>Ie,SERVER_NAME:()=>ai,VERIFY_SENTENCE:()=>bt,backupFile:()=>Oe,copilotJsonEntry:()=>Jt,httpJsonEntry:()=>ft,listTargetCommands:()=>ci,parseSetupArgs:()=>li,runSetup:()=>ko,setupHelp:()=>cr,stdioRemoteJsonEntry:()=>Kt});function li(e){let t={target:"",port:Number(process.env.PORT??Ie),relayUrl:null,deviceId:null,help:!1,listTargets:!1},r=(n,i)=>{let s=e[n];if(s===void 0||s==="")throw new Error(`Missing value for ${i}`);return s};for(let n=0;n<e.length;n++){let i=e[n],[s,o]=i.includes("=")?i.split("=",2):[i,void 0],a=l=>o??r(++n,l);switch(s){case"--target":case"-t":t.target=a("--target");break;case"--port":case"-p":{let l=Number(a("--port"));if(!Number.isInteger(l)||l<1||l>65535)throw new Error("Invalid --port: expected 1-65535");t.port=l;break}case"--device":case"-d":t.deviceId=a("--device");break;case"--relay-url":t.relayUrl=a("--relay-url").replace(/\/+$/,"");break;case"--list-targets":case"--list":t.listTargets=!0;break;case"--help":case"-h":t.help=!0;break;default:throw new Error(`Unknown option: ${i} (see --help)`)}}if(!Number.isInteger(t.port)||t.port<1||t.port>65535)throw new Error(`Invalid PORT: expected 1-65535 (got ${process.env.PORT})`);return t}function To(e){let t=e.action.kind==="print"?"":" --device <deviceId>";return`npx -y @babtab/relay setup --target ${e.id} --port ${Ie}${t}`}function cr(){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:",Se.map(t=>` ${t.id.padEnd(17)} ${t.label}`).join(`
60
- `),"","Options:"," --target, -t <id> Harness to configure (required, see list above)",` --port, -p <n> Relay port (default ${Ie}, 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: "${bt}".`," Remote --relay-url connections still require an already-running relay and pairing.",""].join(`
61
- `)}function ci(){return Se.map(e=>`# ${e.label}
62
- ${To(e)}`).join(`
60
+ Then ask: "Use babtab to observe the current tab".`),0}var pr,jo,Fo,pi=y(()=>{"use strict";pr=require("node:child_process");rr();hr();at();jo=60,Fo=`@babtab/relay@${ue}`});async function mi(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 re(`Cannot reach relay at ${e}: ${String(s)}`)}let i={};try{i=await n.json()}catch{}return{status:n.status,json:i}}async function mr(e){let t;try{t=await fetch(`${e}/health`,{signal:AbortSignal.timeout(3e3)})}catch(n){throw new re(`Cannot reach relay at ${e}/health: ${String(n)}`)}if(!t.ok)throw new re(`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 gi(e,t,r){let{status:n,json:i}=await mi(`${e}/pairing/request`,{deviceId:t,clientName:r,scopes:["browser:read","browser:act"]},3e3);if(n===429)throw new Ie(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 _i(e,t,r={}){let n=r.intervalMs??2e3,i=r.timeoutMs??3e5,s=Date.now()+i;for(;;){let{json:o}=await mi(`${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 Re("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 re,Ie,Re,De,yi=y(()=>{"use strict";re=class extends Error{},Ie=class extends Error{},Re=class extends Error{},De=class extends Error{}});var _r={};vr(_r,{DEFAULT_PORT:()=>Le,SERVER_NAME:()=>Si,VERIFY_SENTENCE:()=>Et,backupFile:()=>Ne,copilotJsonEntry:()=>er,httpJsonEntry:()=>pt,listTargetCommands:()=>wi,parseSetupArgs:()=>vi,runSetup:()=>Go,setupHelp:()=>gr,stdioRemoteJsonEntry:()=>tr});function vi(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 qo(e){let t=e.action.kind==="print"?"":" --device <deviceId>";return`npx -y @babtab/relay setup --target ${e.id} --port ${Le}${t}`}function gr(){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:",xe.map(t=>` ${t.id.padEnd(17)} ${t.label}`).join(`
61
+ `),"","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: "${Et}".`," Remote --relay-url connections still require an already-running relay and pairing.",""].join(`
62
+ `)}function wi(){return xe.map(e=>`# ${e.label}
63
+ ${qo(e)}`).join(`
63
64
 
64
65
  `)+`
65
- `}function fi(e){return e===Ie?"npx -y @babtab/relay":`PORT=${e} npx -y @babtab/relay`}async function ko(e){let t;try{t=li(e)}catch(o){return console.error(`Error: ${o.message}
66
- `),console.error(cr()),1}if(t.help)return console.log(cr()),0;if(t.listTargets)return console.log(ci()),0;let r=Mn(t.target);if(!r)return console.error(`Error: unknown --target "${t.target}". Pick one of:
67
- `),console.error(Se.map(o=>` ${o.id}`).join(`
68
- `)),1;let n=t.relayUrl??`http://127.0.0.1:${t.port}`;if(r.action.kind==="print")return Co(r,n,t);if(!t.deviceId)return console.error(`Error: --device is required.
69
- 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 lr(n)}catch(o){if(o instanceof Q)return console.error(`Error: relay is not reachable at ${n}.
66
+ `}function Ei(e){return e===Le?"npx -y @babtab/relay":`PORT=${e} npx -y @babtab/relay`}async function Go(e){let t;try{t=vi(e)}catch(o){return console.error(`Error: ${o.message}
67
+ `),console.error(gr()),1}if(t.help)return console.log(gr()),0;if(t.listTargets)return console.log(wi()),0;let r=Kn(t.target);if(!r)return console.error(`Error: unknown --target "${t.target}". Pick one of:
68
+ `),console.error(xe.map(o=>` ${o.id}`).join(`
69
+ `)),1;let n=t.relayUrl??`http://127.0.0.1:${t.port}`;if(r.action.kind==="print")return Vo(r,n,t);if(!t.deviceId)return console.error(`Error: --device is required.
70
+ 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 hi(r,t.deviceId,t.port)}catch(o){return console.error(`Error: ${o.message}`),4}try{await mr(n)}catch(o){if(o instanceof re)return console.error(`Error: relay is not reachable at ${n}.
70
71
  Start it first in another terminal:
71
72
 
72
- ${fi(t.port)}
73
- `),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.
74
- Open Advanced connection settings and use Save & Connect first, then re-run this command.`),3;i=o.code}catch(o){return o instanceof Ae?(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 Pe||o instanceof Ne?(console.error(`Error: ${o.message}`),3):(console.error(`Error: claim failed: ${o.message}`),3)}console.log("Approved \u2713");try{return Oo(r,n,s)}catch(o){return console.error(`Error: ${o.message}`),4}}async function Co(e,t,r){if(e.action.kind!=="print")return 1;try{await lr(t)}catch{console.log(`Note: relay is not reachable at ${t} yet \u2014 start it with:
73
+ ${Ei(t.port)}
74
+ `),2;throw o}let i;try{let o=await gi(n,t.deviceId,r.id);if(!o.deviceOnline)return console.error(`Error: your Chrome is not connected to the relay.
75
+ Open Advanced connection settings and use Save & Connect first, then re-run this command.`),3;i=o.code}catch(o){return o instanceof Ie?(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 _i(n,i)}catch(o){return o instanceof Re||o instanceof De?(console.error(`Error: ${o.message}`),3):(console.error(`Error: claim failed: ${o.message}`),3)}console.log("Approved \u2713");try{return Ho(r,n,s)}catch(o){return console.error(`Error: ${o.message}`),4}}async function Vo(e,t,r){if(e.action.kind!=="print")return 1;try{await mr(t)}catch{console.log(`Note: relay is not reachable at ${t} yet \u2014 start it with:
75
76
 
76
- ${fi(r.port)}
77
+ ${Ei(r.port)}
77
78
  `)}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>):
78
- `),console.log(` ${jn(t,"<token>")}
79
+ `),console.log(` ${ei(t,"<token>")}
79
80
  `)):(console.log("Standard MCP (Streamable HTTP):"),console.log(` Endpoint: ${t}/mcp`),console.log(` Header: Authorization: Bearer <token>
80
- `),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 Oo(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 d=c.error.code==="ENOENT";return console.error(d?`The "${l[0]}" CLI was not found. Install it, then run:
81
+ `),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 Ho(e,t,r){let n=e.action;if(n.kind==="exec"){let l=n.argv(t,r),c=(0,bi.spawnSync)(l[0],l.slice(1),{stdio:"inherit",shell:process.platform==="win32"});if(c.error){let f=c.error.code==="ENOENT";return console.error(f?`The "${l[0]}" CLI was not found. Install it, then run:
81
82
 
82
83
  ${l.join(" ")}
83
84
  `:`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(`
84
- Configured ${e.label} \u2713`),console.log(e.nextStep),console.log(`Then ask: "${bt}".`),0)}let i=ct(),s=mt(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=$n(n.entry,t,r);({created:o,backedUp:a}=gt({path:s,rootKey:n.rootKey,serverName:ai,entry:l}))}else if(n.kind==="toml-codex")({created:o,backedUp:a}=_t(s,Bn(t,r)));else if(n.kind==="yaml-hermes")({created:o,backedUp:a}=yt(s,Un(t,r)));else return console.error(`Error: unsupported action for target "${e.id}".`),4;return console.log(`
85
- Wrote ${s} ${o?"(created)":"(updated, babtab entry replaced)"} \u2713`),a&&console.log(`Backup: ${s}.bak`),console.log(e.nextStep),console.log(`Then ask: "${bt}".`),0}var oi,Ie,ai,bt,dr=y(()=>{"use strict";oi=require("node:child_process");ti();Yt();ar();si();Ie=3e3,ai="babtab",bt="Use babtab to observe the current tab"});zt();async function Ao(){let e=process.argv[2];if(e==="stdio"){let{runStdio:t,parseBridgeArgs:r}=await Promise.resolve().then(()=>(Rn(),In));await t(r(process.argv.slice(3)))}else if(e==="setup"){let{runSetup:t}=await Promise.resolve().then(()=>(dr(),fr));process.exitCode=await t(process.argv.slice(3))}else if(e==="help"||e==="--help"||e==="-h"){let{setupHelp:t}=await Promise.resolve().then(()=>(dr(),fr));console.log(`babtab-relay \u2014 local bridge between your AI agent and Chrome
85
+ Configured ${e.label} \u2713`),console.log(e.nextStep),console.log(`Then ask: "${Et}".`),0)}let i=ht(),s=bt(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=Zn(n.entry,t,r);({created:o,backedUp:a}=St({path:s,rootKey:n.rootKey,serverName:Si,entry:l}))}else if(n.kind==="toml-codex")({created:o,backedUp:a}=vt(s,Xn(t,r)));else if(n.kind==="yaml-hermes")({created:o,backedUp:a}=wt(s,Qn(t,r)));else return console.error(`Error: unsupported action for target "${e.id}".`),4;return console.log(`
86
+ Wrote ${s} ${o?"(created)":"(updated, babtab entry replaced)"} \u2713`),a&&console.log(`Backup: ${s}.bak`),console.log(e.nextStep),console.log(`Then ask: "${Et}".`),0}var bi,Le,Si,Et,yr=y(()=>{"use strict";bi=require("node:child_process");pi();rr();hr();yi();Le=3e3,Si="babtab",Et="Use babtab to observe the current tab"});Zt();async function zo(){let e=process.argv[2];if(e==="stdio"){let{runStdio:t,parseBridgeArgs:r}=await Promise.resolve().then(()=>(zn(),Hn));await t(r(process.argv.slice(3)))}else if(e==="setup"){let{runSetup:t}=await Promise.resolve().then(()=>(yr(),_r));process.exitCode=await t(process.argv.slice(3))}else if(e==="help"||e==="--help"||e==="-h"){let{setupHelp:t}=await Promise.resolve().then(()=>(yr(),_r));console.log(`babtab-relay \u2014 local bridge between your AI agent and Chrome
86
87
 
87
88
  Start the relay:
88
89
  npx -y @babtab/relay (env: PORT=3000 BABTAB_TOKEN_FILE=./data/relay-tokens.json)
89
90
 
90
91
  `+t())}else e!==void 0?(console.error(`Unknown command: ${e}
91
- Run \`npx -y @babtab/relay help\` for usage.`),process.exitCode=1):Po()}Ao().catch(e=>{console.error(`[babtab] ${e.message}`),process.exitCode=1});function Po(){let e=Number(process.env.PORT??3e3),t=ot({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)}
92
+ Run \`npx -y @babtab/relay help\` for usage.`),process.exitCode=1):Jo()}zo().catch(e=>{console.error(`[babtab] ${e.message}`),process.exitCode=1});function Jo(){let e=Number(process.env.PORT??3e3),t=ft({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)}
92
93
  /*! Bundled license information:
93
94
 
94
95
  smol-toml/dist/error.js:
95
- (*!
96
- * Copyright (c) Squirrel Chat et al., All rights reserved.
97
- * SPDX-License-Identifier: BSD-3-Clause
98
- *
99
- * Redistribution and use in source and binary forms, with or without
100
- * modification, are permitted provided that the following conditions are met:
101
- *
102
- * 1. Redistributions of source code must retain the above copyright notice, this
103
- * list of conditions and the following disclaimer.
104
- * 2. Redistributions in binary form must reproduce the above copyright notice,
105
- * this list of conditions and the following disclaimer in the
106
- * documentation and/or other materials provided with the distribution.
107
- * 3. Neither the name of the copyright holder nor the names of its contributors
108
- * may be used to endorse or promote products derived from this software without
109
- * specific prior written permission.
110
- *
111
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
112
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
113
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
114
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
115
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
116
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
117
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
118
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
119
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
120
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121
- *)
122
-
123
96
  smol-toml/dist/primitive.js:
124
- (*!
125
- * Copyright (c) Squirrel Chat et al., All rights reserved.
126
- * SPDX-License-Identifier: BSD-3-Clause
127
- *
128
- * Redistribution and use in source and binary forms, with or without
129
- * modification, are permitted provided that the following conditions are met:
130
- *
131
- * 1. Redistributions of source code must retain the above copyright notice, this
132
- * list of conditions and the following disclaimer.
133
- * 2. Redistributions in binary form must reproduce the above copyright notice,
134
- * this list of conditions and the following disclaimer in the
135
- * documentation and/or other materials provided with the distribution.
136
- * 3. Neither the name of the copyright holder nor the names of its contributors
137
- * may be used to endorse or promote products derived from this software without
138
- * specific prior written permission.
139
- *
140
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
141
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
142
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
143
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
144
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
145
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
146
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
147
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
148
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
149
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150
- *)
151
-
152
97
  smol-toml/dist/date.js:
153
- (*!
154
- * Copyright (c) Squirrel Chat et al., All rights reserved.
155
- * SPDX-License-Identifier: BSD-3-Clause
156
- *
157
- * Redistribution and use in source and binary forms, with or without
158
- * modification, are permitted provided that the following conditions are met:
159
- *
160
- * 1. Redistributions of source code must retain the above copyright notice, this
161
- * list of conditions and the following disclaimer.
162
- * 2. Redistributions in binary form must reproduce the above copyright notice,
163
- * this list of conditions and the following disclaimer in the
164
- * documentation and/or other materials provided with the distribution.
165
- * 3. Neither the name of the copyright holder nor the names of its contributors
166
- * may be used to endorse or promote products derived from this software without
167
- * specific prior written permission.
168
- *
169
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
170
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
171
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
172
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
173
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
174
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
175
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
176
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
177
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
178
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
179
- *)
180
-
181
98
  smol-toml/dist/extract.js:
182
- (*!
183
- * Copyright (c) Squirrel Chat et al., All rights reserved.
184
- * SPDX-License-Identifier: BSD-3-Clause
185
- *
186
- * Redistribution and use in source and binary forms, with or without
187
- * modification, are permitted provided that the following conditions are met:
188
- *
189
- * 1. Redistributions of source code must retain the above copyright notice, this
190
- * list of conditions and the following disclaimer.
191
- * 2. Redistributions in binary form must reproduce the above copyright notice,
192
- * this list of conditions and the following disclaimer in the
193
- * documentation and/or other materials provided with the distribution.
194
- * 3. Neither the name of the copyright holder nor the names of its contributors
195
- * may be used to endorse or promote products derived from this software without
196
- * specific prior written permission.
197
- *
198
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
199
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
200
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
201
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
202
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
203
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
204
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
205
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
206
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
207
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
208
- *)
209
-
210
99
  smol-toml/dist/util.js:
211
- (*!
212
- * Copyright (c) Squirrel Chat et al., All rights reserved.
213
- * SPDX-License-Identifier: BSD-3-Clause
214
- *
215
- * Redistribution and use in source and binary forms, with or without
216
- * modification, are permitted provided that the following conditions are met:
217
- *
218
- * 1. Redistributions of source code must retain the above copyright notice, this
219
- * list of conditions and the following disclaimer.
220
- * 2. Redistributions in binary form must reproduce the above copyright notice,
221
- * this list of conditions and the following disclaimer in the
222
- * documentation and/or other materials provided with the distribution.
223
- * 3. Neither the name of the copyright holder nor the names of its contributors
224
- * may be used to endorse or promote products derived from this software without
225
- * specific prior written permission.
226
- *
227
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
228
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
229
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
230
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
231
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
233
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
234
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
235
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
236
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237
- *)
238
-
239
100
  smol-toml/dist/struct.js:
240
- (*!
241
- * Copyright (c) Squirrel Chat et al., All rights reserved.
242
- * SPDX-License-Identifier: BSD-3-Clause
243
- *
244
- * Redistribution and use in source and binary forms, with or without
245
- * modification, are permitted provided that the following conditions are met:
246
- *
247
- * 1. Redistributions of source code must retain the above copyright notice, this
248
- * list of conditions and the following disclaimer.
249
- * 2. Redistributions in binary form must reproduce the above copyright notice,
250
- * this list of conditions and the following disclaimer in the
251
- * documentation and/or other materials provided with the distribution.
252
- * 3. Neither the name of the copyright holder nor the names of its contributors
253
- * may be used to endorse or promote products derived from this software without
254
- * specific prior written permission.
255
- *
256
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
257
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
258
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
259
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
260
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
262
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
263
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
264
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266
- *)
267
-
268
101
  smol-toml/dist/parse.js:
269
- (*!
270
- * Copyright (c) Squirrel Chat et al., All rights reserved.
271
- * SPDX-License-Identifier: BSD-3-Clause
272
- *
273
- * Redistribution and use in source and binary forms, with or without
274
- * modification, are permitted provided that the following conditions are met:
275
- *
276
- * 1. Redistributions of source code must retain the above copyright notice, this
277
- * list of conditions and the following disclaimer.
278
- * 2. Redistributions in binary form must reproduce the above copyright notice,
279
- * this list of conditions and the following disclaimer in the
280
- * documentation and/or other materials provided with the distribution.
281
- * 3. Neither the name of the copyright holder nor the names of its contributors
282
- * may be used to endorse or promote products derived from this software without
283
- * specific prior written permission.
284
- *
285
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
286
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
287
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
288
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
289
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
290
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
291
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
292
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
294
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295
- *)
296
-
297
102
  smol-toml/dist/stringify.js:
298
- (*!
299
- * Copyright (c) Squirrel Chat et al., All rights reserved.
300
- * SPDX-License-Identifier: BSD-3-Clause
301
- *
302
- * Redistribution and use in source and binary forms, with or without
303
- * modification, are permitted provided that the following conditions are met:
304
- *
305
- * 1. Redistributions of source code must retain the above copyright notice, this
306
- * list of conditions and the following disclaimer.
307
- * 2. Redistributions in binary form must reproduce the above copyright notice,
308
- * this list of conditions and the following disclaimer in the
309
- * documentation and/or other materials provided with the distribution.
310
- * 3. Neither the name of the copyright holder nor the names of its contributors
311
- * may be used to endorse or promote products derived from this software without
312
- * specific prior written permission.
313
- *
314
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
315
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
316
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
317
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
318
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
319
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
320
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
321
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
322
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
323
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
324
- *)
325
-
326
103
  smol-toml/dist/index.js:
327
104
  (*!
328
105
  * Copyright (c) Squirrel Chat et al., All rights reserved.