coze-bridge 0.1.33 → 0.1.34
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/index.js +67 -67
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,25 +5,25 @@ import { dirname as __coze_dirname } from 'node:path';
|
|
|
5
5
|
const require = __coze_createRequire(import.meta.url);
|
|
6
6
|
const __filename = __coze_fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __coze_dirname(__filename);
|
|
8
|
-
var
|
|
9
|
-
`,
|
|
10
|
-
`):
|
|
11
|
-
`)}function w(n){return{debug:(e,t)=>Ct("debug",n,e,t),info:(e,t)=>Ct("info",n,e,t),warn:(e,t)=>Ct("warn",n,e,t),error:(e,t)=>Ct("error",n,e,t),child:e=>w(`${n}.${e}`)}}var Ot,ds,ba,Na,us,k=K(()=>{"use strict";Ot={debug:10,info:20,warn:30,error:40},ds=(()=>{let n=process.env.COZE_BRIDGE_LOG_LEVEL;return n==="debug"||n==="info"||n==="warn"||n==="error"?n:"info"})(),ba=process.stdout,Na=process.stderr,us={}});import{homedir as Da}from"node:os";import{join as L}from"node:path";function T(n){let e=n??Da(),t=L(e,".coze"),r=L(t,"bridge"),s=L(r,"lib");return{cozeRoot:t,bridgeRoot:r,libDir:s,libEntry:L(s,"index.js"),pidFile:L(r,"bridge.pid"),portFile:L(r,"bridge.port"),tokenFile:L(r,"bridge.token"),logFile:L(r,"bridge.log"),installLock:L(r,"install.lock"),configFile:L(r,"config.json"),agentsRoot:L(t,"agents")}}function ae(n,e=T()){let t=L(e.agentsRoot,n);return{root:t,config:L(t,"config.json"),workspace:L(t,"workspace"),logs:L(t,"logs")}}var z=K(()=>{"use strict"});var Dt={};Mn(Dt,{AGENT_CONFIG_FILE_MODE:()=>bt,enforceAgentConfigMode:()=>Ba,loadAgentConfig:()=>q,persistAgentSessions:()=>Fn,persistAgentSkills:()=>Nt,saveAgentConfig:()=>X});import{chmod as La,stat as Ma}from"node:fs/promises";function q(n,e){return Le(ae(n,e).config)}function X(n,e){return Pt(ae(n.agentId,e).config,n,{mode:bt})}async function Ba(n,e){if(process.platform==="win32")return;let t=ae(n,e).config;try{let r=await Ma(t);if(!r.isFile())return;let s=r.mode&511;s!==bt&&(await La(t,bt),hs.warn("agent config mode auto-corrected to 0600",{path:t,from:s.toString(8)}))}catch(r){if(r.code==="ENOENT")return;hs.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:t,err:String(r)})}}async function Fn(n,e,t){let r=await q(n,t);r&&(r.sessions=Object.fromEntries(e),await X(r,t))}async function Nt(n,e,t){let r=await q(n,t);r&&(r.skills=e,await X(r,t))}var hs,bt,ge=K(()=>{"use strict";At();k();z();hs=w("agent-config"),bt=384});function Ol(){return gi||(gi=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function bl(){return pi||(pi=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}function Nl(n){let e=new Promise((t,r)=>{let s=()=>{n.removeEventListener("success",i),n.removeEventListener("error",o)},i=()=>{t(W(n.result)),s()},o=()=>{r(n.error),s()};n.addEventListener("success",i),n.addEventListener("error",o)});return e.then(t=>{t instanceof IDBCursor&&mi.set(t,n)}).catch(()=>{}),Zn.set(e,n),e}function Dl(n){if(Xn.has(n))return;let e=new Promise((t,r)=>{let s=()=>{n.removeEventListener("complete",i),n.removeEventListener("error",o),n.removeEventListener("abort",o)},i=()=>{t(),s()},o=()=>{r(n.error||new DOMException("AbortError","AbortError")),s()};n.addEventListener("complete",i),n.addEventListener("error",o),n.addEventListener("abort",o)});Xn.set(n,e)}function wi(n){Yn=n(Yn)}function Ll(n){return n===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...t){let r=n.call(gt(this),e,...t);return _i.set(r,e.sort?e.sort():[e]),W(r)}:bl().includes(n)?function(...e){return n.apply(gt(this),e),W(mi.get(this))}:function(...e){return W(n.apply(gt(this),e))}}function Ml(n){return typeof n=="function"?Ll(n):(n instanceof IDBTransaction&&Dl(n),Cl(n,Ol())?new Proxy(n,Yn):n)}function W(n){if(n instanceof IDBRequest)return Nl(n);if(Kn.has(n))return Kn.get(n);let e=Ml(n);return e!==n&&(Kn.set(n,e),Zn.set(e,n)),e}var Cl,gi,pi,mi,Xn,_i,Kn,Zn,Yn,gt,er=K(()=>{Cl=(n,e)=>e.some(t=>n instanceof t);mi=new WeakMap,Xn=new WeakMap,_i=new WeakMap,Kn=new WeakMap,Zn=new WeakMap;Yn={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return Xn.get(n);if(e==="objectStoreNames")return n.objectStoreNames||_i.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return W(n[e])},set(n,e,t){return n[e]=t,!0},has(n,e){return n instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in n}};gt=n=>Zn.get(n)});var Si={};Mn(Si,{deleteDB:()=>Fl,openDB:()=>Bl,unwrap:()=>gt,wrap:()=>W});function Bl(n,e,{blocked:t,upgrade:r,blocking:s,terminated:i}={}){let o=indexedDB.open(n,e),a=W(o);return r&&o.addEventListener("upgradeneeded",c=>{r(W(o.result),c.oldVersion,c.newVersion,W(o.transaction))}),t&&o.addEventListener("blocked",()=>t()),a.then(c=>{i&&c.addEventListener("close",()=>i()),s&&c.addEventListener("versionchange",()=>s())}).catch(()=>{}),a}function Fl(n,{blocked:e}={}){let t=indexedDB.deleteDatabase(n);return e&&t.addEventListener("blocked",()=>e()),W(t).then(()=>{})}function yi(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(tr.get(e))return tr.get(e);let t=e.replace(/FromIndex$/,""),r=e!==t,s=$l.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(s||Ul.includes(t)))return;let i=async function(o,...a){let c=this.transaction(o,s?"readwrite":"readonly"),l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[t](...a),s&&c.done]))[0]};return tr.set(e,i),i}var Ul,$l,tr,Ei=K(()=>{er();er();Ul=["get","getKey","getAll","getAllKeys","count"],$l=["put","add","delete","clear"],tr=new Map;wi(n=>({...n,get:(e,t,r)=>yi(e,t)||n.get(e,t,r),has:(e,t)=>!!yi(e,t)||n.has(e,t)}))});var le=$((wm,Ji)=>{"use strict";var Wi=["nodebuffer","arraybuffer","fragments"],ji=typeof Blob<"u";ji&&Wi.push("blob");Ji.exports={BINARY_TYPES:Wi,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ji,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var St=$((ym,cn)=>{"use strict";var{EMPTY_BUFFER:Gd}=le(),Ir=Buffer[Symbol.species];function Hd(n,e){if(n.length===0)return Gd;if(n.length===1)return n[0];let t=Buffer.allocUnsafe(e),r=0;for(let s=0;s<n.length;s++){let i=n[s];t.set(i,r),r+=i.length}return r<e?new Ir(t.buffer,t.byteOffset,r):t}function Vi(n,e,t,r,s){for(let i=0;i<s;i++)t[r+i]=n[i]^e[i&3]}function Qi(n,e){for(let t=0;t<n.length;t++)n[t]^=e[t&3]}function Wd(n){return n.length===n.buffer.byteLength?n.buffer:n.buffer.slice(n.byteOffset,n.byteOffset+n.length)}function xr(n){if(xr.readOnly=!0,Buffer.isBuffer(n))return n;let e;return n instanceof ArrayBuffer?e=new Ir(n):ArrayBuffer.isView(n)?e=new Ir(n.buffer,n.byteOffset,n.byteLength):(e=Buffer.from(n),xr.readOnly=!1),e}cn.exports={concat:Hd,mask:Vi,toArrayBuffer:Wd,toBuffer:xr,unmask:Qi};if(!process.env.WS_NO_BUFFER_UTIL)try{let n=A("bufferutil");cn.exports.mask=function(e,t,r,s,i){i<48?Vi(e,t,r,s,i):n.mask(e,t,r,s,i)},cn.exports.unmask=function(e,t){e.length<32?Qi(e,t):n.unmask(e,t)}}catch{}});var Yi=$((Sm,Xi)=>{"use strict";var Ki=Symbol("kDone"),Tr=Symbol("kRun"),Rr=class{constructor(e){this[Ki]=()=>{this.pending--,this[Tr]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Tr]()}[Tr](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ki])}}};Xi.exports=Rr});var Ve=$((Em,no)=>{"use strict";var Et=A("zlib"),Zi=St(),jd=Yi(),{kStatusCode:eo}=le(),Jd=Buffer[Symbol.species],Vd=Buffer.from([0,0,255,255]),dn=Symbol("permessage-deflate"),de=Symbol("total-length"),je=Symbol("callback"),ye=Symbol("buffers"),Je=Symbol("error"),ln,Pr=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!ln){let t=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ln=new jd(t)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[je];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let t=this._options,r=e.find(s=>!(t.serverNoContextTakeover===!1&&s.server_no_context_takeover||s.server_max_window_bits&&(t.serverMaxWindowBits===!1||typeof t.serverMaxWindowBits=="number"&&t.serverMaxWindowBits>s.server_max_window_bits)||typeof t.clientMaxWindowBits=="number"&&!s.client_max_window_bits));if(!r)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(r.server_no_context_takeover=!0),t.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof t.serverMaxWindowBits=="number"&&(r.server_max_window_bits=t.serverMaxWindowBits),typeof t.clientMaxWindowBits=="number"?r.client_max_window_bits=t.clientMaxWindowBits:(r.client_max_window_bits===!0||t.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(e){let t=e[0];if(this._options.clientNoContextTakeover===!1&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!t.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(t.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return t}normalizeParams(e){return e.forEach(t=>{Object.keys(t).forEach(r=>{let s=t[r];if(s.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(s=s[0],r==="client_max_window_bits"){if(s!==!0){let i=+s;if(!Number.isInteger(i)||i<8||i>15)throw new TypeError(`Invalid value for parameter "${r}": ${s}`);s=i}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${s}`)}else if(r==="server_max_window_bits"){let i=+s;if(!Number.isInteger(i)||i<8||i>15)throw new TypeError(`Invalid value for parameter "${r}": ${s}`);s=i}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(s!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${s}`)}else throw new Error(`Unknown parameter "${r}"`);t[r]=s})}),e}decompress(e,t,r){ln.add(s=>{this._decompress(e,t,(i,o)=>{s(),r(i,o)})})}compress(e,t,r){ln.add(s=>{this._compress(e,t,(i,o)=>{s(),r(i,o)})})}_decompress(e,t,r){let s=this._isServer?"client":"server";if(!this._inflate){let i=`${s}_max_window_bits`,o=typeof this.params[i]!="number"?Et.Z_DEFAULT_WINDOWBITS:this.params[i];this._inflate=Et.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[dn]=this,this._inflate[de]=0,this._inflate[ye]=[],this._inflate.on("error",Kd),this._inflate.on("data",to)}this._inflate[je]=r,this._inflate.write(e),t&&this._inflate.write(Vd),this._inflate.flush(()=>{let i=this._inflate[Je];if(i){this._inflate.close(),this._inflate=null,r(i);return}let o=Zi.concat(this._inflate[ye],this._inflate[de]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[de]=0,this._inflate[ye]=[],t&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),r(null,o)})}_compress(e,t,r){let s=this._isServer?"server":"client";if(!this._deflate){let i=`${s}_max_window_bits`,o=typeof this.params[i]!="number"?Et.Z_DEFAULT_WINDOWBITS:this.params[i];this._deflate=Et.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[de]=0,this._deflate[ye]=[],this._deflate.on("data",Qd)}this._deflate[je]=r,this._deflate.write(e),this._deflate.flush(Et.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let i=Zi.concat(this._deflate[ye],this._deflate[de]);t&&(i=new Jd(i.buffer,i.byteOffset,i.length-4)),this._deflate[je]=null,this._deflate[de]=0,this._deflate[ye]=[],t&&this.params[`${s}_no_context_takeover`]&&this._deflate.reset(),r(null,i)})}};no.exports=Pr;function Qd(n){this[ye].push(n),this[de]+=n.length}function to(n){if(this[de]+=n.length,this[dn]._maxPayload<1||this[de]<=this[dn]._maxPayload){this[ye].push(n);return}this[Je]=new RangeError("Max payload size exceeded"),this[Je].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Je][eo]=1009,this.removeListener("data",to),this.reset()}function Kd(n){if(this[dn]._inflate=null,this[Je]){this[je](this[Je]);return}n[eo]=1007,this[je](n)}});var Qe=$((vm,un)=>{"use strict";var{isUtf8:ro}=A("buffer"),{hasBlob:Xd}=le(),Yd=[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 Zd(n){return n>=1e3&&n<=1014&&n!==1004&&n!==1005&&n!==1006||n>=3e3&&n<=4999}function Ar(n){let e=n.length,t=0;for(;t<e;)if((n[t]&128)===0)t++;else if((n[t]&224)===192){if(t+1===e||(n[t+1]&192)!==128||(n[t]&254)===192)return!1;t+=2}else if((n[t]&240)===224){if(t+2>=e||(n[t+1]&192)!==128||(n[t+2]&192)!==128||n[t]===224&&(n[t+1]&224)===128||n[t]===237&&(n[t+1]&224)===160)return!1;t+=3}else if((n[t]&248)===240){if(t+3>=e||(n[t+1]&192)!==128||(n[t+2]&192)!==128||(n[t+3]&192)!==128||n[t]===240&&(n[t+1]&240)===128||n[t]===244&&n[t+1]>143||n[t]>244)return!1;t+=4}else return!1;return!0}function eu(n){return Xd&&typeof n=="object"&&typeof n.arrayBuffer=="function"&&typeof n.type=="string"&&typeof n.stream=="function"&&(n[Symbol.toStringTag]==="Blob"||n[Symbol.toStringTag]==="File")}un.exports={isBlob:eu,isValidStatusCode:Zd,isValidUTF8:Ar,tokenChars:Yd};if(ro)un.exports.isValidUTF8=function(n){return n.length<24?Ar(n):ro(n)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let n=A("utf-8-validate");un.exports.isValidUTF8=function(e){return e.length<32?Ar(e):n(e)}}catch{}});var Dr=$((km,uo)=>{"use strict";var{Writable:tu}=A("stream"),so=Ve(),{BINARY_TYPES:nu,EMPTY_BUFFER:io,kStatusCode:ru,kWebSocket:su}=le(),{concat:Cr,toArrayBuffer:iu,unmask:ou}=St(),{isValidStatusCode:au,isValidUTF8:oo}=Qe(),fn=Buffer[Symbol.species],J=0,ao=1,co=2,lo=3,Or=4,br=5,hn=6,Nr=class extends tu{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||nu[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[su]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=J}_write(e,t,r){if(this._opcode===8&&this._state==J)return r();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new fn(r.buffer,r.byteOffset+e,r.length-e),new fn(r.buffer,r.byteOffset,e)}let t=Buffer.allocUnsafe(e);do{let r=this._buffers[0],s=t.length-e;e>=r.length?t.set(this._buffers.shift(),s):(t.set(new Uint8Array(r.buffer,r.byteOffset,e),s),this._buffers[0]=new fn(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return t}startLoop(e){this._loop=!0;do switch(this._state){case J:this.getInfo(e);break;case ao:this.getPayloadLength16(e);break;case co:this.getPayloadLength64(e);break;case lo:this.getMask();break;case Or:this.getData(e);break;case br:case hn:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let t=this.consume(2);if((t[0]&48)!==0){let s=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(s);return}let r=(t[0]&64)===64;if(r&&!this._extensions[so.extensionName]){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._fin=(t[0]&128)===128,this._opcode=t[0]&15,this._payloadLength=t[1]&127,this._opcode===0){if(r){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(!this._fragmented){let s=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let s=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(s);return}if(r){let s=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(s);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let s=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(s);return}}else{let s=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(s);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(t[1]&128)===128,this._isServer){if(!this._masked){let s=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(s);return}}else if(this._masked){let s=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(s);return}this._payloadLength===126?this._state=ao:this._payloadLength===127?this._state=co:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let t=this.consume(8),r=t.readUInt32BE(0);if(r>Math.pow(2,21)-1){let s=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(s);return}this._payloadLength=r*Math.pow(2,32)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let t=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(t);return}this._masked?this._state=lo:this._state=Or}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Or}getData(e){let t=io;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}t=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&ou(t,this._mask)}if(this._opcode>7){this.controlMessage(t,e);return}if(this._compressed){this._state=br,this.decompress(t,e);return}t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}decompress(e,t){this._extensions[so.extensionName].decompress(e,this._fin,(s,i)=>{if(s)return t(s);if(i.length){if(this._messageLength+=i.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");t(o);return}this._fragments.push(i)}this.dataMessage(t),this._state===J&&this.startLoop(t)})}dataMessage(e){if(!this._fin){this._state=J;return}let t=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let s;this._binaryType==="nodebuffer"?s=Cr(r,t):this._binaryType==="arraybuffer"?s=iu(Cr(r,t)):this._binaryType==="blob"?s=new Blob(r):s=r,this._allowSynchronousEvents?(this.emit("message",s,!0),this._state=J):(this._state=hn,setImmediate(()=>{this.emit("message",s,!0),this._state=J,this.startLoop(e)}))}else{let s=Cr(r,t);if(!this._skipUTF8Validation&&!oo(s)){let i=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(i);return}this._state===br||this._allowSynchronousEvents?(this.emit("message",s,!1),this._state=J):(this._state=hn,setImmediate(()=>{this.emit("message",s,!1),this._state=J,this.startLoop(e)}))}}controlMessage(e,t){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,io),this.end();else{let r=e.readUInt16BE(0);if(!au(r)){let i=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");t(i);return}let s=new fn(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!oo(s)){let i=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");t(i);return}this._loop=!1,this.emit("conclude",r,s),this.end()}this._state=J;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=J):(this._state=hn,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=J,this.startLoop(t)}))}createError(e,t,r,s,i){this._loop=!1,this._errored=!0;let o=new e(r?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(o,this.createError),o.code=i,o[ru]=s,o}};uo.exports=Nr});var Br=$((xm,go)=>{"use strict";var{Duplex:Im}=A("stream"),{randomFillSync:cu}=A("crypto"),fo=Ve(),{EMPTY_BUFFER:lu,kWebSocket:du,NOOP:uu}=le(),{isBlob:Ke,isValidStatusCode:fu}=Qe(),{mask:ho,toBuffer:Pe}=St(),V=Symbol("kByteLength"),hu=Buffer.alloc(4),gn=8*1024,Ae,Xe=gn,Z=0,gu=1,pu=2,Lr=class n{constructor(e,t,r){this._extensions=t||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=Z,this.onerror=uu,this[du]=void 0}static frame(e,t){let r,s=!1,i=2,o=!1;t.mask&&(r=t.maskBuffer||hu,t.generateMask?t.generateMask(r):(Xe===gn&&(Ae===void 0&&(Ae=Buffer.alloc(gn)),cu(Ae,0,gn),Xe=0),r[0]=Ae[Xe++],r[1]=Ae[Xe++],r[2]=Ae[Xe++],r[3]=Ae[Xe++]),o=(r[0]|r[1]|r[2]|r[3])===0,i=6);let a;typeof e=="string"?(!t.mask||o)&&t[V]!==void 0?a=t[V]:(e=Buffer.from(e),a=e.length):(a=e.length,s=t.mask&&t.readOnly&&!o);let c=a;a>=65536?(i+=8,c=127):a>125&&(i+=2,c=126);let l=Buffer.allocUnsafe(s?a+i:i);return l[0]=t.fin?t.opcode|128:t.opcode,t.rsv1&&(l[0]|=64),l[1]=c,c===126?l.writeUInt16BE(a,2):c===127&&(l[2]=l[3]=0,l.writeUIntBE(a,4,6)),t.mask?(l[1]|=128,l[i-4]=r[0],l[i-3]=r[1],l[i-2]=r[2],l[i-1]=r[3],o?[l,e]:s?(ho(e,r,l,i,a),[l]):(ho(e,r,e,0,a),[l,e])):[l,e]}close(e,t,r,s){let i;if(e===void 0)i=lu;else{if(typeof e!="number"||!fu(e))throw new TypeError("First argument must be a valid error code number");if(t===void 0||!t.length)i=Buffer.allocUnsafe(2),i.writeUInt16BE(e,0);else{let a=Buffer.byteLength(t);if(a>123)throw new RangeError("The message must not be greater than 123 bytes");i=Buffer.allocUnsafe(2+a),i.writeUInt16BE(e,0),typeof t=="string"?i.write(t,2):i.set(t,2)}}let o={[V]:i.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Z?this.enqueue([this.dispatch,i,!1,o,s]):this.sendFrame(n.frame(i,o),s)}ping(e,t,r){let s,i;if(typeof e=="string"?(s=Buffer.byteLength(e),i=!1):Ke(e)?(s=e.size,i=!1):(e=Pe(e),s=e.length,i=Pe.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[V]:s,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};Ke(e)?this._state!==Z?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==Z?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(n.frame(e,o),r)}pong(e,t,r){let s,i;if(typeof e=="string"?(s=Buffer.byteLength(e),i=!1):Ke(e)?(s=e.size,i=!1):(e=Pe(e),s=e.length,i=Pe.readOnly),s>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[V]:s,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};Ke(e)?this._state!==Z?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==Z?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(n.frame(e,o),r)}send(e,t,r){let s=this._extensions[fo.extensionName],i=t.binary?2:1,o=t.compress,a,c;typeof e=="string"?(a=Buffer.byteLength(e),c=!1):Ke(e)?(a=e.size,c=!1):(e=Pe(e),a=e.length,c=Pe.readOnly),this._firstFragment?(this._firstFragment=!1,o&&s&&s.params[s._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=a>=s._threshold),this._compress=o):(o=!1,i=0),t.fin&&(this._firstFragment=!0);let l={[V]:a,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:i,readOnly:c,rsv1:o};Ke(e)?this._state!==Z?this.enqueue([this.getBlobData,e,this._compress,l,r]):this.getBlobData(e,this._compress,l,r):this._state!==Z?this.enqueue([this.dispatch,e,this._compress,l,r]):this.dispatch(e,this._compress,l,r)}getBlobData(e,t,r,s){this._bufferedBytes+=r[V],this._state=pu,e.arrayBuffer().then(i=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Mr,this,a,s);return}this._bufferedBytes-=r[V];let o=Pe(i);t?this.dispatch(o,t,r,s):(this._state=Z,this.sendFrame(n.frame(o,r),s),this.dequeue())}).catch(i=>{process.nextTick(mu,this,i,s)})}dispatch(e,t,r,s){if(!t){this.sendFrame(n.frame(e,r),s);return}let i=this._extensions[fo.extensionName];this._bufferedBytes+=r[V],this._state=gu,i.compress(e,r.fin,(o,a)=>{if(this._socket.destroyed){let c=new Error("The socket was closed while data was being compressed");Mr(this,c,s);return}this._bufferedBytes-=r[V],this._state=Z,r.readOnly=!1,this.sendFrame(n.frame(a,r),s),this.dequeue()})}dequeue(){for(;this._state===Z&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][V],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][V],this._queue.push(e)}sendFrame(e,t){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}};go.exports=Lr;function Mr(n,e,t){typeof t=="function"&&t(e);for(let r=0;r<n._queue.length;r++){let s=n._queue[r],i=s[s.length-1];typeof i=="function"&&i(e)}}function mu(n,e,t){Mr(n,e,t),n.onerror(e)}});var ko=$((Tm,vo)=>{"use strict";var{kForOnEventAttribute:vt,kListener:Fr}=le(),po=Symbol("kCode"),mo=Symbol("kData"),_o=Symbol("kError"),wo=Symbol("kMessage"),yo=Symbol("kReason"),Ye=Symbol("kTarget"),So=Symbol("kType"),Eo=Symbol("kWasClean"),ue=class{constructor(e){this[Ye]=null,this[So]=e}get target(){return this[Ye]}get type(){return this[So]}};Object.defineProperty(ue.prototype,"target",{enumerable:!0});Object.defineProperty(ue.prototype,"type",{enumerable:!0});var Ce=class extends ue{constructor(e,t={}){super(e),this[po]=t.code===void 0?0:t.code,this[yo]=t.reason===void 0?"":t.reason,this[Eo]=t.wasClean===void 0?!1:t.wasClean}get code(){return this[po]}get reason(){return this[yo]}get wasClean(){return this[Eo]}};Object.defineProperty(Ce.prototype,"code",{enumerable:!0});Object.defineProperty(Ce.prototype,"reason",{enumerable:!0});Object.defineProperty(Ce.prototype,"wasClean",{enumerable:!0});var Ze=class extends ue{constructor(e,t={}){super(e),this[_o]=t.error===void 0?null:t.error,this[wo]=t.message===void 0?"":t.message}get error(){return this[_o]}get message(){return this[wo]}};Object.defineProperty(Ze.prototype,"error",{enumerable:!0});Object.defineProperty(Ze.prototype,"message",{enumerable:!0});var kt=class extends ue{constructor(e,t={}){super(e),this[mo]=t.data===void 0?null:t.data}get data(){return this[mo]}};Object.defineProperty(kt.prototype,"data",{enumerable:!0});var _u={addEventListener(n,e,t={}){for(let s of this.listeners(n))if(!t[vt]&&s[Fr]===e&&!s[vt])return;let r;if(n==="message")r=function(i,o){let a=new kt("message",{data:o?i:i.toString()});a[Ye]=this,pn(e,this,a)};else if(n==="close")r=function(i,o){let a=new Ce("close",{code:i,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[Ye]=this,pn(e,this,a)};else if(n==="error")r=function(i){let o=new Ze("error",{error:i,message:i.message});o[Ye]=this,pn(e,this,o)};else if(n==="open")r=function(){let i=new ue("open");i[Ye]=this,pn(e,this,i)};else return;r[vt]=!!t[vt],r[Fr]=e,t.once?this.once(n,r):this.on(n,r)},removeEventListener(n,e){for(let t of this.listeners(n))if(t[Fr]===e&&!t[vt]){this.removeListener(n,t);break}}};vo.exports={CloseEvent:Ce,ErrorEvent:Ze,Event:ue,EventTarget:_u,MessageEvent:kt};function pn(n,e,t){typeof n=="object"&&n.handleEvent?n.handleEvent.call(n,t):n.call(e,t)}});var mn=$((Rm,Io)=>{"use strict";var{tokenChars:It}=Qe();function oe(n,e,t){n[e]===void 0?n[e]=[t]:n[e].push(t)}function wu(n){let e=Object.create(null),t=Object.create(null),r=!1,s=!1,i=!1,o,a,c=-1,l=-1,d=-1,f=0;for(;f<n.length;f++)if(l=n.charCodeAt(f),o===void 0)if(d===-1&&It[l]===1)c===-1&&(c=f);else if(f!==0&&(l===32||l===9))d===-1&&c!==-1&&(d=f);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${f}`);d===-1&&(d=f);let p=n.slice(c,d);l===44?(oe(e,p,t),t=Object.create(null)):o=p,c=d=-1}else throw new SyntaxError(`Unexpected character at index ${f}`);else if(a===void 0)if(d===-1&&It[l]===1)c===-1&&(c=f);else if(l===32||l===9)d===-1&&c!==-1&&(d=f);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${f}`);d===-1&&(d=f),oe(t,n.slice(c,d),!0),l===44&&(oe(e,o,t),t=Object.create(null),o=void 0),c=d=-1}else if(l===61&&c!==-1&&d===-1)a=n.slice(c,f),c=d=-1;else throw new SyntaxError(`Unexpected character at index ${f}`);else if(s){if(It[l]!==1)throw new SyntaxError(`Unexpected character at index ${f}`);c===-1?c=f:r||(r=!0),s=!1}else if(i)if(It[l]===1)c===-1&&(c=f);else if(l===34&&c!==-1)i=!1,d=f;else if(l===92)s=!0;else throw new SyntaxError(`Unexpected character at index ${f}`);else if(l===34&&n.charCodeAt(f-1)===61)i=!0;else if(d===-1&&It[l]===1)c===-1&&(c=f);else if(c!==-1&&(l===32||l===9))d===-1&&(d=f);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${f}`);d===-1&&(d=f);let p=n.slice(c,d);r&&(p=p.replace(/\\/g,""),r=!1),oe(t,a,p),l===44&&(oe(e,o,t),t=Object.create(null),o=void 0),a=void 0,c=d=-1}else throw new SyntaxError(`Unexpected character at index ${f}`);if(c===-1||i||l===32||l===9)throw new SyntaxError("Unexpected end of input");d===-1&&(d=f);let u=n.slice(c,d);return o===void 0?oe(e,u,t):(a===void 0?oe(t,u,!0):r?oe(t,a,u.replace(/\\/g,"")):oe(t,a,u),oe(e,o,t)),e}function yu(n){return Object.keys(n).map(e=>{let t=n[e];return Array.isArray(t)||(t=[t]),t.map(r=>[e].concat(Object.keys(r).map(s=>{let i=r[s];return Array.isArray(i)||(i=[i]),i.map(o=>o===!0?s:`${s}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Io.exports={format:yu,parse:wu}});var Sn=$((Cm,Mo)=>{"use strict";var Su=A("events"),Eu=A("https"),vu=A("http"),Ro=A("net"),ku=A("tls"),{randomBytes:Iu,createHash:xu}=A("crypto"),{Duplex:Pm,Readable:Am}=A("stream"),{URL:Ur}=A("url"),Se=Ve(),Tu=Dr(),Ru=Br(),{isBlob:Pu}=Qe(),{BINARY_TYPES:xo,CLOSE_TIMEOUT:Au,EMPTY_BUFFER:_n,GUID:Cu,kForOnEventAttribute:$r,kListener:Ou,kStatusCode:bu,kWebSocket:O,NOOP:Po}=le(),{EventTarget:{addEventListener:Nu,removeEventListener:Du}}=ko(),{format:Lu,parse:Mu}=mn(),{toBuffer:Bu}=St(),Ao=Symbol("kAborted"),zr=[8,13],fe=["CONNECTING","OPEN","CLOSING","CLOSED"],Fu=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,x=class n extends Su{constructor(e,t,r){super(),this._binaryType=xo[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=_n,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=n.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,t===void 0?t=[]:Array.isArray(t)||(typeof t=="object"&&t!==null?(r=t,t=[]):t=[t]),Co(this,e,t,r)):(this._autoPong=r.autoPong,this._closeTimeout=r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){xo.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,t,r){let s=new Tu({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),i=new Ru(e,this._extensions,r.generateMask);this._receiver=s,this._sender=i,this._socket=e,s[O]=this,i[O]=this,e[O]=this,s.on("conclude",zu),s.on("drain",qu),s.on("error",Gu),s.on("message",Hu),s.on("ping",Wu),s.on("pong",ju),i.onerror=Ju,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),t.length>0&&e.unshift(t),e.on("close",No),e.on("data",yn),e.on("end",Do),e.on("error",Lo),this._readyState=n.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=n.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[Se.extensionName]&&this._extensions[Se.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=n.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState!==n.CLOSED){if(this.readyState===n.CONNECTING){H(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===n.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=n.CLOSING,this._sender.close(e,t,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),bo(this)}}pause(){this.readyState===n.CONNECTING||this.readyState===n.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,t,r){if(this.readyState===n.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=t=void 0):typeof t=="function"&&(r=t,t=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==n.OPEN){qr(this,e,r);return}t===void 0&&(t=!this._isServer),this._sender.ping(e||_n,t,r)}pong(e,t,r){if(this.readyState===n.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=t=void 0):typeof t=="function"&&(r=t,t=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==n.OPEN){qr(this,e,r);return}t===void 0&&(t=!this._isServer),this._sender.pong(e||_n,t,r)}resume(){this.readyState===n.CONNECTING||this.readyState===n.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,t,r){if(this.readyState===n.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof t=="function"&&(r=t,t={}),typeof e=="number"&&(e=e.toString()),this.readyState!==n.OPEN){qr(this,e,r);return}let s={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...t};this._extensions[Se.extensionName]||(s.compress=!1),this._sender.send(e||_n,s,r)}terminate(){if(this.readyState!==n.CLOSED){if(this.readyState===n.CONNECTING){H(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=n.CLOSING,this._socket.destroy())}}};Object.defineProperty(x,"CONNECTING",{enumerable:!0,value:fe.indexOf("CONNECTING")});Object.defineProperty(x.prototype,"CONNECTING",{enumerable:!0,value:fe.indexOf("CONNECTING")});Object.defineProperty(x,"OPEN",{enumerable:!0,value:fe.indexOf("OPEN")});Object.defineProperty(x.prototype,"OPEN",{enumerable:!0,value:fe.indexOf("OPEN")});Object.defineProperty(x,"CLOSING",{enumerable:!0,value:fe.indexOf("CLOSING")});Object.defineProperty(x.prototype,"CLOSING",{enumerable:!0,value:fe.indexOf("CLOSING")});Object.defineProperty(x,"CLOSED",{enumerable:!0,value:fe.indexOf("CLOSED")});Object.defineProperty(x.prototype,"CLOSED",{enumerable:!0,value:fe.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(n=>{Object.defineProperty(x.prototype,n,{enumerable:!0})});["open","error","close","message"].forEach(n=>{Object.defineProperty(x.prototype,`on${n}`,{enumerable:!0,get(){for(let e of this.listeners(n))if(e[$r])return e[Ou];return null},set(e){for(let t of this.listeners(n))if(t[$r]){this.removeListener(n,t);break}typeof e=="function"&&this.addEventListener(n,e,{[$r]:!0})}})});x.prototype.addEventListener=Nu;x.prototype.removeEventListener=Du;Mo.exports=x;function Co(n,e,t,r){let s={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Au,protocolVersion:zr[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(n._autoPong=s.autoPong,n._closeTimeout=s.closeTimeout,!zr.includes(s.protocolVersion))throw new RangeError(`Unsupported protocol version: ${s.protocolVersion} (supported versions: ${zr.join(", ")})`);let i;if(e instanceof Ur)i=e;else try{i=new Ur(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}i.protocol==="http:"?i.protocol="ws:":i.protocol==="https:"&&(i.protocol="wss:"),n._url=i.href;let o=i.protocol==="wss:",a=i.protocol==="ws+unix:",c;if(i.protocol!=="ws:"&&!o&&!a?c=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:a&&!i.pathname?c="The URL's pathname is empty":i.hash&&(c="The URL contains a fragment identifier"),c){let _=new SyntaxError(c);if(n._redirects===0)throw _;wn(n,_);return}let l=o?443:80,d=Iu(16).toString("base64"),f=o?Eu.request:vu.request,u=new Set,p;if(s.createConnection=s.createConnection||(o?$u:Uu),s.defaultPort=s.defaultPort||l,s.port=i.port||l,s.host=i.hostname.startsWith("[")?i.hostname.slice(1,-1):i.hostname,s.headers={...s.headers,"Sec-WebSocket-Version":s.protocolVersion,"Sec-WebSocket-Key":d,Connection:"Upgrade",Upgrade:"websocket"},s.path=i.pathname+i.search,s.timeout=s.handshakeTimeout,s.perMessageDeflate&&(p=new Se({...s.perMessageDeflate,isServer:!1,maxPayload:s.maxPayload}),s.headers["Sec-WebSocket-Extensions"]=Lu({[Se.extensionName]:p.offer()})),t.length){for(let _ of t){if(typeof _!="string"||!Fu.test(_)||u.has(_))throw new SyntaxError("An invalid or duplicated subprotocol was specified");u.add(_)}s.headers["Sec-WebSocket-Protocol"]=t.join(",")}if(s.origin&&(s.protocolVersion<13?s.headers["Sec-WebSocket-Origin"]=s.origin:s.headers.Origin=s.origin),(i.username||i.password)&&(s.auth=`${i.username}:${i.password}`),a){let _=s.path.split(":");s.socketPath=_[0],s.path=_[1]}let m;if(s.followRedirects){if(n._redirects===0){n._originalIpc=a,n._originalSecure=o,n._originalHostOrSocketPath=a?s.socketPath:i.host;let _=r&&r.headers;if(r={...r,headers:{}},_)for(let[v,C]of Object.entries(_))r.headers[v.toLowerCase()]=C}else if(n.listenerCount("redirect")===0){let _=a?n._originalIpc?s.socketPath===n._originalHostOrSocketPath:!1:n._originalIpc?!1:i.host===n._originalHostOrSocketPath;(!_||n._originalSecure&&!o)&&(delete s.headers.authorization,delete s.headers.cookie,_||delete s.headers.host,s.auth=void 0)}s.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(s.auth).toString("base64")),m=n._req=f(s),n._redirects&&n.emit("redirect",n.url,m)}else m=n._req=f(s);s.timeout&&m.on("timeout",()=>{H(n,m,"Opening handshake has timed out")}),m.on("error",_=>{m===null||m[Ao]||(m=n._req=null,wn(n,_))}),m.on("response",_=>{let v=_.headers.location,C=_.statusCode;if(v&&s.followRedirects&&C>=300&&C<400){if(++n._redirects>s.maxRedirects){H(n,m,"Maximum redirects exceeded");return}m.abort();let F;try{F=new Ur(v,e)}catch{let P=new SyntaxError(`Invalid URL: ${v}`);wn(n,P);return}Co(n,F,t,r)}else n.emit("unexpected-response",m,_)||H(n,m,`Unexpected server response: ${_.statusCode}`)}),m.on("upgrade",(_,v,C)=>{if(n.emit("upgrade",_),n.readyState!==x.CONNECTING)return;m=n._req=null;let F=_.headers.upgrade;if(F===void 0||F.toLowerCase()!=="websocket"){H(n,v,"Invalid Upgrade header");return}let b=xu("sha1").update(d+Cu).digest("base64");if(_.headers["sec-websocket-accept"]!==b){H(n,v,"Invalid Sec-WebSocket-Accept header");return}let P=_.headers["sec-websocket-protocol"],g;if(P!==void 0?u.size?u.has(P)||(g="Server sent an invalid subprotocol"):g="Server sent a subprotocol but none was requested":u.size&&(g="Server sent no subprotocol"),g){H(n,v,g);return}P&&(n._protocol=P);let E=_.headers["sec-websocket-extensions"];if(E!==void 0){if(!p){H(n,v,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let I;try{I=Mu(E)}catch{H(n,v,"Invalid Sec-WebSocket-Extensions header");return}let Q=Object.keys(I);if(Q.length!==1||Q[0]!==Se.extensionName){H(n,v,"Server indicated an extension that was not requested");return}try{p.accept(I[Se.extensionName])}catch{H(n,v,"Invalid Sec-WebSocket-Extensions header");return}n._extensions[Se.extensionName]=p}n.setSocket(v,C,{allowSynchronousEvents:s.allowSynchronousEvents,generateMask:s.generateMask,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation})}),s.finishRequest?s.finishRequest(m,n):m.end()}function wn(n,e){n._readyState=x.CLOSING,n._errorEmitted=!0,n.emit("error",e),n.emitClose()}function Uu(n){return n.path=n.socketPath,Ro.connect(n)}function $u(n){return n.path=void 0,!n.servername&&n.servername!==""&&(n.servername=Ro.isIP(n.host)?"":n.host),ku.connect(n)}function H(n,e,t){n._readyState=x.CLOSING;let r=new Error(t);Error.captureStackTrace(r,H),e.setHeader?(e[Ao]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(wn,n,r)):(e.destroy(r),e.once("error",n.emit.bind(n,"error")),e.once("close",n.emitClose.bind(n)))}function qr(n,e,t){if(e){let r=Pu(e)?e.size:Bu(e).length;n._socket?n._sender._bufferedBytes+=r:n._bufferedAmount+=r}if(t){let r=new Error(`WebSocket is not open: readyState ${n.readyState} (${fe[n.readyState]})`);process.nextTick(t,r)}}function zu(n,e){let t=this[O];t._closeFrameReceived=!0,t._closeMessage=e,t._closeCode=n,t._socket[O]!==void 0&&(t._socket.removeListener("data",yn),process.nextTick(Oo,t._socket),n===1005?t.close():t.close(n,e))}function qu(){let n=this[O];n.isPaused||n._socket.resume()}function Gu(n){let e=this[O];e._socket[O]!==void 0&&(e._socket.removeListener("data",yn),process.nextTick(Oo,e._socket),e.close(n[bu])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",n))}function To(){this[O].emitClose()}function Hu(n,e){this[O].emit("message",n,e)}function Wu(n){let e=this[O];e._autoPong&&e.pong(n,!this._isServer,Po),e.emit("ping",n)}function ju(n){this[O].emit("pong",n)}function Oo(n){n.resume()}function Ju(n){let e=this[O];e.readyState!==x.CLOSED&&(e.readyState===x.OPEN&&(e._readyState=x.CLOSING,bo(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",n)))}function bo(n){n._closeTimer=setTimeout(n._socket.destroy.bind(n._socket),n._closeTimeout)}function No(){let n=this[O];if(this.removeListener("close",No),this.removeListener("data",yn),this.removeListener("end",Do),n._readyState=x.CLOSING,!this._readableState.endEmitted&&!n._closeFrameReceived&&!n._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);n._receiver.write(e)}n._receiver.end(),this[O]=void 0,clearTimeout(n._closeTimer),n._receiver._writableState.finished||n._receiver._writableState.errorEmitted?n.emitClose():(n._receiver.on("error",To),n._receiver.on("finish",To))}function yn(n){this[O]._receiver.write(n)||this.pause()}function Do(){let n=this[O];n._readyState=x.CLOSING,n._receiver.end(),this.end()}function Lo(){let n=this[O];this.removeListener("error",Lo),this.on("error",Po),n&&(n._readyState=x.CLOSING,this.destroy())}});var $o=$((bm,Uo)=>{"use strict";var Om=Sn(),{Duplex:Vu}=A("stream");function Bo(n){n.emit("close")}function Qu(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fo(n){this.removeListener("error",Fo),this.destroy(),this.listenerCount("error")===0&&this.emit("error",n)}function Ku(n,e){let t=!0,r=new Vu({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return n.on("message",function(i,o){let a=!o&&r._readableState.objectMode?i.toString():i;r.push(a)||n.pause()}),n.once("error",function(i){r.destroyed||(t=!1,r.destroy(i))}),n.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(s,i){if(n.readyState===n.CLOSED){i(s),process.nextTick(Bo,r);return}let o=!1;n.once("error",function(c){o=!0,i(c)}),n.once("close",function(){o||i(s),process.nextTick(Bo,r)}),t&&n.terminate()},r._final=function(s){if(n.readyState===n.CONNECTING){n.once("open",function(){r._final(s)});return}n._socket!==null&&(n._socket._writableState.finished?(s(),r._readableState.endEmitted&&r.destroy()):(n._socket.once("finish",function(){s()}),n.close()))},r._read=function(){n.isPaused&&n.resume()},r._write=function(s,i,o){if(n.readyState===n.CONNECTING){n.once("open",function(){r._write(s,i,o)});return}n.send(s,o)},r.on("end",Qu),r.on("error",Fo),r}Uo.exports=Ku});var Gr=$((Nm,zo)=>{"use strict";var{tokenChars:Xu}=Qe();function Yu(n){let e=new Set,t=-1,r=-1,s=0;for(s;s<n.length;s++){let o=n.charCodeAt(s);if(r===-1&&Xu[o]===1)t===-1&&(t=s);else if(s!==0&&(o===32||o===9))r===-1&&t!==-1&&(r=s);else if(o===44){if(t===-1)throw new SyntaxError(`Unexpected character at index ${s}`);r===-1&&(r=s);let a=n.slice(t,r);if(e.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);e.add(a),t=r=-1}else throw new SyntaxError(`Unexpected character at index ${s}`)}if(t===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let i=n.slice(t,s);if(e.has(i))throw new SyntaxError(`The "${i}" subprotocol is duplicated`);return e.add(i),e}zo.exports={parse:Yu}});var Vo=$((Lm,Jo)=>{"use strict";var Zu=A("events"),En=A("http"),{Duplex:Dm}=A("stream"),{createHash:ef}=A("crypto"),qo=mn(),Oe=Ve(),tf=Gr(),nf=Sn(),{CLOSE_TIMEOUT:rf,GUID:sf,kWebSocket:of}=le(),af=/^[+/0-9A-Za-z]{22}==$/,Go=0,Ho=1,jo=2,Hr=class extends Zu{constructor(e,t){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:rf,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:nf,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=En.createServer((r,s)=>{let i=En.STATUS_CODES[426];s.writeHead(426,{"Content-Length":i.length,"Content-Type":"text/plain"}),s.end(i)}),this._server.listen(e.port,e.host,e.backlog,t)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=cf(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(s,i,o)=>{this.handleUpgrade(s,i,o,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Go}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===jo){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(xt,this);return}if(e&&this.once("close",e),this._state!==Ho)if(this._state=Ho,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(xt,this):process.nextTick(xt,this);else{let t=this._server;this._removeListeners(),this._removeListeners=this._server=null,t.close(()=>{xt(this)})}}shouldHandle(e){if(this.options.path){let t=e.url.indexOf("?");if((t!==-1?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,r,s){t.on("error",Wo);let i=e.headers["sec-websocket-key"],o=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if(e.method!=="GET"){be(this,e,t,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){be(this,e,t,400,"Invalid Upgrade header");return}if(i===void 0||!af.test(i)){be(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){be(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Tt(t,400);return}let c=e.headers["sec-websocket-protocol"],l=new Set;if(c!==void 0)try{l=tf.parse(c)}catch{be(this,e,t,400,"Invalid Sec-WebSocket-Protocol header");return}let d=e.headers["sec-websocket-extensions"],f={};if(this.options.perMessageDeflate&&d!==void 0){let u=new Oe({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let p=qo.parse(d);p[Oe.extensionName]&&(u.accept(p[Oe.extensionName]),f[Oe.extensionName]=u)}catch{be(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let u={origin:e.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(u,(p,m,_,v)=>{if(!p)return Tt(t,m||401,_,v);this.completeUpgrade(f,i,l,e,t,r,s)});return}if(!this.options.verifyClient(u))return Tt(t,401)}this.completeUpgrade(f,i,l,e,t,r,s)}completeUpgrade(e,t,r,s,i,o,a){if(!i.readable||!i.writable)return i.destroy();if(i[of])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Go)return Tt(i,503);let l=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${ef("sha1").update(t+sf).digest("base64")}`],d=new this.options.WebSocket(null,void 0,this.options);if(r.size){let f=this.options.handleProtocols?this.options.handleProtocols(r,s):r.values().next().value;f&&(l.push(`Sec-WebSocket-Protocol: ${f}`),d._protocol=f)}if(e[Oe.extensionName]){let f=e[Oe.extensionName].params,u=qo.format({[Oe.extensionName]:[f]});l.push(`Sec-WebSocket-Extensions: ${u}`),d._extensions=e}this.emit("headers",l,s),i.write(l.concat(`\r
|
|
8
|
+
var k0=Object.create;var Sr=Object.defineProperty;var I0=Object.getOwnPropertyDescriptor;var P0=Object.getOwnPropertyNames;var D0=Object.getPrototypeOf,T0=Object.prototype.hasOwnProperty;var X=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var Me=(r,e)=>()=>(r&&(e=r(r=0)),e);var de=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Ks=(r,e)=>{for(var i in e)Sr(r,i,{get:e[i],enumerable:!0})},N0=(r,e,i,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of P0(e))!T0.call(r,c)&&c!==i&&Sr(r,c,{get:()=>e[c],enumerable:!(a=I0(e,c))||a.enumerable});return r};var Oe=(r,e,i)=>(i=r!=null?k0(D0(r)):{},N0(e||!r||!r.__esModule?Sr(i,"default",{value:r,enumerable:!0}):i,r));import{chmod as L0,mkdir as R0,readFile as B0,rename as Gs,writeFile as Hs}from"node:fs/promises";import{dirname as M0}from"node:path";async function gt(r){try{let e=await B0(r,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function on(r,e,i){await R0(M0(r),{recursive:!0});let a=`${JSON.stringify(e,null,2)}
|
|
9
|
+
`,c=`${r}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{i?.mode!==void 0?await Hs(c,a,{encoding:"utf8",mode:i.mode}):await Hs(c,a,"utf8"),await Gs(c,r),i?.mode!==void 0&&await L0(r,i.mode)}catch(u){await Gs(c,c).catch(()=>{});let{rm:f}=await import("node:fs/promises");throw await f(c,{force:!0}).catch(()=>{}),u}}var an=Me(()=>{"use strict"});function Js(r){return xn[js]<=xn[r]}function Cr(r){Ws={...r}}function cn(r,e,i,a){if(xn[r]<xn[js])return;let c=JSON.stringify({ts:new Date().toISOString(),level:r,module:e,msg:i,...Ws,...a});r==="error"||r==="warn"?z0.write(`${c}
|
|
10
|
+
`):O0.write(`${c}
|
|
11
|
+
`)}function N(r){return{debug:(e,i)=>cn("debug",r,e,i),info:(e,i)=>cn("info",r,e,i),warn:(e,i)=>cn("warn",r,e,i),error:(e,i)=>cn("error",r,e,i),child:e=>N(`${r}.${e}`)}}var xn,js,O0,z0,Ws,K=Me(()=>{"use strict";xn={debug:10,info:20,warn:30,error:40},js=(()=>{let r=process.env.COZE_BRIDGE_LOG_LEVEL;return r==="debug"||r==="info"||r==="warn"||r==="error"?r:"info"})(),O0=process.stdout,z0=process.stderr,Ws={}});import{homedir as q0}from"node:os";import{join as xe}from"node:path";function H(r){let e=r??q0(),i=xe(e,".coze"),a=xe(i,"bridge"),c=xe(a,"lib");return{cozeRoot:i,bridgeRoot:a,libDir:c,libEntry:xe(c,"index.js"),pidFile:xe(a,"bridge.pid"),portFile:xe(a,"bridge.port"),tokenFile:xe(a,"bridge.token"),logFile:xe(a,"bridge.log"),installLock:xe(a,"install.lock"),configFile:xe(a,"config.json"),agentsRoot:xe(i,"agents")}}function ze(r,e=H()){let i=xe(e.agentsRoot,r);return{root:i,config:xe(i,"config.json"),workspace:xe(i,"workspace"),logs:xe(i,"logs")}}var le=Me(()=>{"use strict"});var dn={};Ks(dn,{AGENT_CONFIG_FILE_MODE:()=>un,enforceAgentConfigMode:()=>K0,loadAgentConfig:()=>he,persistAgentSessions:()=>Er,persistAgentSkills:()=>fn,saveAgentConfig:()=>be});import{chmod as F0,stat as U0}from"node:fs/promises";function he(r,e){return gt(ze(r,e).config)}function be(r,e){return on(ze(r.agentId,e).config,r,{mode:un})}async function K0(r,e){if(process.platform==="win32")return;let i=ze(r,e).config;try{let a=await U0(i);if(!a.isFile())return;let c=a.mode&511;c!==un&&(await F0(i,un),Vs.warn("agent config mode auto-corrected to 0600",{path:i,from:c.toString(8)}))}catch(a){if(a.code==="ENOENT")return;Vs.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:i,err:String(a)})}}async function Er(r,e,i){let a=await he(r,i);a&&(a.sessions=Object.fromEntries(e),await be(a,i))}async function fn(r,e,i){let a=await he(r,i);a&&(a.skills=e,await be(a,i))}var Vs,un,Je=Me(()=>{"use strict";an();K();le();Vs=N("agent-config"),un=384});var io=de(Q=>{"use strict";var E=I;(function(r,e){let i=I,a=r();for(;;)try{if(-parseInt(i(1080))/1*(-parseInt(i(1722))/2)+parseInt(i(1401))/3*(-parseInt(i(1808))/4)+parseInt(i(1771))/5+-parseInt(i(1613))/6+-parseInt(i(645))/7*(-parseInt(i(996))/8)+-parseInt(i(1315))/9*(parseInt(i(738))/10)+parseInt(i(1100))/11*(-parseInt(i(624))/12)===e)break;a.push(a.shift())}catch{a.push(a.shift())}})(Gn,925396);var Mx=Object[E(1383)+E(1417)],Ox=Object[E(546)+E(1200)+E(1935)],eo=(r,e)=>function(){return r&&(e=(0,r[{FKEyF:function(u,f){return u(f)}}[E(543)](Ox,r)[0]])(r=0)),e},zx=(r,e)=>{for(var i in e)Mx(r,i,{get:e[i],enumerable:!0})};function qx(){return Xi||(Xi=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Fx(){let r=E;return Yi||(Yi=[IDBCursor[r(939)+"e"][r(1482)],IDBCursor[r(939)+"e"].continue,IDBCursor.prototype[r(1102)+r(1177)+"ey"]])}function Ux(r){let e=E,i={zghAW:e(554),AUwRE:function(c){return c()},cZtOa:function(c,u){return c(u)},HpNKb:function(c){return c()},JRLGL:"ZNjYJ",qMSLM:e(609),Xoeic:function(c,u){return c instanceof u}},a=new Promise((c,u)=>{let f=e,h={YRwPV:function(m,_){return i[I(1975)](m,_)},YBBZl:function(m){return i[I(1907)](m)}};if(i[f(1291)]!==i[f(962)]){let m=()=>{let v=f;r[v(1174)+v(1192)+v(1864)](i[v(735)],_),r[v(1174)+v(1192)+"ner"]("error",y)},_=()=>{let v=f;h[v(863)](c,Ne(r[v(573)])),m()},y=()=>{u(r[f(1063)]),i.AUwRE(m)};r[f(771)+"Listener"](i.zghAW,_),r[f(771)+f(1244)](f(1063),y)}else this._debug(f(1552),_0x3bef9a[f(1905)]),h[f(1362)](_0x934db2)});return a[e(1128)](c=>{let u=e;i[u(504)](c,IDBCursor)&&qr[u(1928)](c,r)})[e(1262)](()=>{}),Un[e(1928)](a,r),a}function Kx(r){let e=E,i={sbGAl:function(c,u){return c<=u},zkWhH:function(c,u){return c<u},sIzLF:function(c,u){return c+u},cIyPo:function(c,u){return c&u},qKcwz:function(c,u){return c>>u},LmTlK:function(c,u){return c|u},ShRCX:function(c,u){return c!==u},PkwfL:e(1350),NktAr:"qZSau",UELKL:"complete",lTKHz:"error",szynp:function(c){return c()},fQdhJ:function(c,u){return c(u)},BQwan:e(1707)+"or"};if(Fn[e(2023)](r))return;let a=new Promise((c,u)=>{let f=e,h=()=>{let y=I,v={SlFwm:function(S,A){return S>=A},jqDOY:function(S,A){return i[I(1246)](S,A)},VHNbx:function(S,A){return i[I(1896)](S,A)},aNWYI:function(S,A){return i.sIzLF(S,A)},gipjr:function(S,A){return S<A},Wegvp:function(S,A){return S|A},qMfxO:function(S,A){return i[I(1038)](S,A)},qiwSu:function(S,A){return i[I(647)](S,A)},CpJyF:function(S,A){return S|A},lGOjl:function(S,A){return S>>A},mPUYb:function(S,A){return i[I(1598)](S,A)}};if(i[y(1117)](i[y(1558)],i[y(788)]))r["removeEv"+y(1192)+y(1864)](i[y(620)],m),r["removeEventListe"+y(1864)](i[y(792)],_),r[y(1174)+y(1192)+y(1864)]("abort",_);else{let S=_0x2ff5d2[y(1344)+"At"](_0x533e5e);v.SlFwm(S,55296)&&v.jqDOY(S,56319)&&v[y(1623)](v[y(550)](_0x464d48,1),_0x2a8e62)&&(S=(S<<10)+_0x340ed8.charCodeAt(++_0x5c116b)-56613888),v[y(828)](S,128)?_0xd92972[_0x34d719++]=S:(v.VHNbx(S,2048)?_0x18cd10[_0x492001++]=v[y(1043)](v.qMfxO(v.qiwSu(S,6),31),192):(S<65536?_0x562391[_0x54d2cd++]=v.qMfxO(v[y(534)](S,12),15)|224:(_0x44d85b[_0x7dfb69++]=v.CpJyF(v[y(1829)](S>>18,7),240),_0x399673[_0x399bc9++]=v[y(1043)](v[y(534)](S,12)&63,128)),_0x45218a[_0x81e26a++]=v[y(1873)](S,6)&63|128),_0x5a6f69[_0x3aed07++]=v.mPUYb(v[y(1829)](63,S),128))}},m=()=>{i[I(480)](c),h()},_=()=>{let y=I;i.fQdhJ(u,r[y(1063)]||new DOMException(i[y(862)],i[y(862)])),i.szynp(h)};r[f(771)+f(1244)](i[f(620)],m),r[f(771)+f(1244)](i[f(792)],_),r["addEvent"+f(1244)](f(832),_)});Fn[e(1928)](r,a)}function Gx(r){Kn={HkuTg:function(i,a){return i(a)}}.HkuTg(r,Kn)}function Hx(r){let e=E,i={AqYyR:function(a,c){return a(c)},sZWXm:function(a,c){return a(c)},PiCdD:function(a,c){return a===c},CMXmR:function(a,c){return a in c},ZBznQ:function(a){return a()}};return i.PiCdD(r,IDBDatabase[e(939)+"e"][e(967)+"ion"])&&!i[e(1524)](e(1580)+"oreNames",IDBTransaction[e(939)+"e"])?function(a,...c){let u=e,f=r[u(1255)](Jt(this),a,...c);return zr[u(1928)](f,a[u(850)]?a.sort():[a]),Ne(f)}:i.ZBznQ(Fx)[e(1916)](r)?function(...a){let c=e;return r[c(1440)](i[c(1521)](Jt,this),a),i[c(1413)](Ne,qr[c(692)](this))}:function(...a){return Ne(r[e(1440)](Jt(this),a))}}function jx(r){let e=E,i={wvAgY:function(a,c){return a===c},hlDNb:e(1175),EHmUe:function(a,c){return a(c)},zkbJk:function(a,c){return a instanceof c},BaogW:function(a,c,u){return a(c,u)},Sryvw:function(a){return a()}};return i[e(938)](typeof r,i.hlDNb)?i[e(1591)](Hx,r):(i.zkbJk(r,IDBTransaction)&&Kx(r),i[e(1701)](to,r,i[e(1167)](qx))?new Proxy(r,Kn):r)}function Ne(r){let e=E,i={tVlgo:function(c,u){return c instanceof u},FRUXZ:function(c,u){return c(u)},WjPcm:function(c,u){return c(u)},LolIt:function(c,u){return c!==u}};if(i[e(1008)](r,IDBRequest))return i[e(816)](Ux,r);if(zn[e(2023)](r))return zn.get(r);let a=i[e(2030)](jx,r);return i[e(1741)](a,r)&&(zn[e(1928)](r,a),Un.set(a,r)),a}var to,Xi,Yi,qr,Fn,zr,zn,Un,Kn,Jt,$i=eo({"node_modules/idb/build/wrap-idb-value.js"(){let r=E,e={OZcGX:function(i,a,c){return i(a,c)},GFIIn:function(i,a,c){return i(a,c)},WdKMf:r(761),mfNAc:function(i,a){return i instanceof a},HwsqR:function(i,a){return i===a},rjLrq:r(1702),NcjrR:function(i,a){return i===a},aDcaq:r(759),qzsEw:r(1225),tLXpZ:function(i,a){return i===a},uQUWD:r(734),Lqrhu:"dwdGQ",VvfvW:function(i,a){return i(a)},SGJJq:function(i,a){return i<=a},mpfuf:function(i,a){return i>=a},LtPJM:function(i,a){return i<a},nbPJC:function(i,a){return i|a},dHOtg:function(i,a){return i<<a},YtWln:function(i,a){return i&a},yJgpn:function(i,a){return i<<a},sIjog:function(i,a){return i&a},pfCRB:function(i,a){return i-a},uXIKp:function(i,a){return i&a},vokIU:function(i,a){return i+a},FYbdw:function(i,a){return i>>a},xQXhF:function(i,a){return i===a},cGTqc:"Pinyg"};to=(i,a)=>a.some(c=>i instanceof c),qr=new WeakMap,Fn=new WeakMap,zr=new WeakMap,zn=new WeakMap,Un=new WeakMap,Kn={get(i,a,c){let u=r,f={hmwcc:function(h,m,_){return e.OZcGX(h,m,_)},DAECn:function(h,m,_){return e[I(551)](h,m,_)}};if(e[u(1359)]===u(1888))this[u(1737)]++;else{if(e[u(1380)](i,IDBTransaction)){if(e[u(708)](a,e[u(1784)]))return Fn.get(i);if(e.HwsqR(a,u(1580)+u(1806)))if(e[u(1714)](e[u(1987)],e[u(846)]))f[u(998)](_0x127d0d,_0x42eecf,66),f[u(1939)](_0x15c969,_0x4c4f8b,_0x5b05d9[u(805)]),f[u(1939)](_0x15b0dd,_0xa4c7a8,_0x508996);else return i[u(1580)+u(1806)]||zr[u(692)](i);if(e.tLXpZ(a,e.uQUWD)){if(e[u(1052)](e[u(1159)],u(1216)))return c[u(1580)+"oreNames"][1]?void 0:c["objectSt"+u(1382)](c.objectStoreNames[0]);_0x5b94c1[u(1209)]=_0x2f8113[u(1665)]().then(()=>(_0x25b432(),_0x5504fc)).then(function(h){return h})}}return e[u(1735)](Ne,i[a])}},set(i,a,c){return i[a]=c,!0},has(i,a){let c=r,u={WyllG:function(f,h){return e.SGJJq(f,h)},orCFz:function(f,h){return e[I(1047)](f,h)},bmDPO:function(f,h){return e[I(1631)](f,h)},moIje:function(f,h){return e[I(1639)](f,h)},RYeMY:function(f,h){return e[I(1890)](f,h)},PXnsu:function(f,h){return e[I(922)](f,h)},JDWbw:function(f,h){return e.LtPJM(f,h)},uPVVa:function(f,h){return f|h},HeImM:function(f,h){return e[I(1890)](f,h)},ngfkj:function(f,h){return e[I(807)](f,h)},KmHfB:function(f,h){return e.sIjog(f,h)},UgZoP:function(f,h){return e[I(1855)](f,h)},EzxDl:function(f,h){return e[I(1639)](f,h)},cROwr:function(f,h){return e[I(1330)](f,h)},ONgcg:function(f,h){return e[I(1890)](f,h)},ZeEoO:function(f,h){return e[I(1142)](f,h)},OZvvf:function(f,h){return f<<h},DGFni:function(f,h){return e[I(1583)](f,h)},ENQkx:function(f,h){return e[I(557)](f,h)}};if(i instanceof IDBTransaction&&(a===e[c(1784)]||e[c(1733)](a,e.uQUWD))){if(c(1014)!==e[c(857)])return!0;{let f=_0x525c68[_0x17b087++];if(u[c(1908)](f,127))_0x343084+=_0x173efc[c(1140)+"Code"](f);else if(u.orCFz(f,192)&&u[c(772)](f,224))_0x59554c+=_0x4bc67d[c(1140)+c(732)](u[c(1528)](u[c(1471)](u.PXnsu(31,f),6),63&_0x35c5d4[_0x389d67++]));else if(u[c(1630)](f,224)&&u.JDWbw(f,240))_0x4d67e4+=_0x3dbf65[c(1140)+c(732)](u[c(1455)](u[c(937)](u.PXnsu(15,f),12),u[c(545)](u.KmHfB(63,_0x4cf681[_0x3672bd++]),6))|u[c(689)](63,_0x40e3ac[_0x513374++]));else if(f>=240){let h=u[c(758)](u[c(1455)](u[c(1965)](u[c(1965)](u[c(1471)](u[c(721)](7,f),18),u[c(1376)](u[c(918)](63,_0x4e3bce[_0x5dff2++]),12)),u[c(1213)](63&_0x14e2c1[_0x35b601++],6)),u[c(851)](63,_0x44198f[_0x162f7b++])),65536);_0x2b2144+=_0x1da6a1[c(1140)+c(732)](u[c(1240)](55296,u[c(871)](h,10))),_0x5443f4+=_0x55ee16[c(1140)+c(732)](u[c(1240)](56320,u[c(721)](1023,h)))}}}return a in i}},Jt=i=>Un[r(692)](i)}}),no={};zx(no,{deleteDB:()=>Jx,openDB:()=>Wx,unwrap:()=>Jt,wrap:()=>Ne});function Wx(r,e,{blocked:i,upgrade:a,blocking:c,terminated:u}={}){let f=E,h={OxVns:function(y,v,S,A,D){return y(v,S,A,D)},hiIql:function(y,v){return y(v)},RjfAa:function(y,v){return y(v)},gBWEo:f(760),WrhZR:f(1309)+f(608),IDRbA:f(1910)+f(1201)},m=indexedDB[f(791)](r,e),_=h[f(2031)](Ne,m);return a&&m[f(771)+f(1244)](h[f(638)],y=>{let v=f;h[v(1745)](a,h[v(2031)](Ne,m.result),y[v(1815)+"on"],y.newVersion,h.RjfAa(Ne,m[v(967)+"ion"]))}),i&&m["addEvent"+f(1244)](f(1743),()=>i()),_.then(y=>{let v=f;u&&y[v(771)+v(1244)](h[v(1476)],()=>u()),c&&y[v(771)+v(1244)](h[v(948)],()=>c())}).catch(()=>{}),_}function Jx(r,{blocked:e}={}){let i=E,a={nVfoU:"blocked"},c=indexedDB[i(1800)+i(1676)](r);return e&&c[i(771)+"Listener"](a.nVfoU,()=>e()),Ne(c).then(()=>{})}function Zi(r,e){let i=E,a={GVgCv:function(m,_){return m<=_},daZba:i(1121)+"alled multiple times in "+i(978),ZbiLB:function(m,_){return m===_},QBvMr:function(m,_){return m+_},cibWB:i(586)+"e",DMLba:i(1658),vcKAW:function(m,_){return m instanceof _},sYTAr:function(m,_){return m in _},bbGlE:function(m,_){return m!==_},cGGYi:function(m,_){return m!==_},xEiJh:function(m,_){return m in _}};if(!(a[i(616)](r,IDBDatabase)&&!a[i(1813)](e,r)&&a[i(1243)](typeof e,"string")))return a[i(714)](i(1441),"BuUNM")?a.GVgCv(_0x292987,_0x306527)?_0x3cf342.reject(new _0x515be8(a.daZba)):(_0x10d648=_0x49feba,a.ZbiLB(_0x5542cf,_0x5e63d3[i(805)])?_0x282c52[i(1665)]():_0x31bd3b[_0x52e2b0][i(459)](_0x3907d7)(_0x390454,_0x3b7fbf[i(459)](null,a[i(1474)](_0x321a6e,1)))):void 0;if(qn[i(692)](e))return qn.get(e);let c=e.replace(/FromIndex$/,""),u=a.cGGYi(e,c),f=so.includes(c);if(!a.xEiJh(c,(u?IDBIndex:IDBObjectStore)[i(939)+"e"])||!(f||ro[i(1916)](c)))return;let h=async function(m,..._){let y=i,v=this[y(967)+"ion"](m,f?a[y(1019)]:a[y(640)]),S=v[y(734)];return u&&(S=S[y(585)](_.shift())),(await Promise.all([S[c](..._),f&&v[y(1702)]]))[0]};return qn[i(1928)](e,h),h}var ro,so,qn,Vx=eo({"node_modules/idb/build/index.js"(){let r=E,e={Sihwy:function(i){return i()},UzZGp:"get",ydnbE:r(1571),VkkCs:r(1254),PCEmK:r(1942)+"ys",VQLFn:r(1737),fpDNX:"put",fuyaB:r(1769),yjCmf:r(450),PFapU:"clear",EPhNB:function(i,a){return i(a)}};e[r(1593)]($i),$i(),ro=[e[r(1439)],e[r(1589)],e[r(1577)],e[r(1001)],e[r(1056)]],so=[e[r(1165)],e[r(1671)],e[r(1841)],e[r(700)]],qn=new Map,e[r(1242)](Gx,i=>({...i,get:(a,c,u)=>Zi(a,c)||i[r(692)](a,c,u),has:(a,c)=>!!Zi(a,c)||i[r(2023)](a,c)}))}}),Xx={idb:function(r){let e=E;r[e(1209)]=Promise.resolve()[e(1128)](()=>(Vx(),no))[e(1128)](function(i){return i})}},Qi={};function I(r,e){r=r-439;let i=Gn(),a=i[r];if(I.kTzjdV===void 0){var c=function(m){let _="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",y="",v="";for(let S=0,A,D,L=0;D=m.charAt(L++);~D&&(A=S%4?A*64+D:D,S++%4)?y+=String.fromCharCode(255&A>>(-2*S&6)):0)D=_.indexOf(D);for(let S=0,A=y.length;S<A;S++)v+="%"+("00"+y.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(v)};I.KxniYW=c,I.UKunGh={},I.kTzjdV=!0}let u=i[0],f=r+u,h=I.UKunGh[f];return h?a=h:(a=I.KxniYW(a),I.UKunGh[f]=a),a}function Te(r){let e=E,i={dtkby:e(929)+"4",VGXxB:function(h,m){return h!==m}},a=i.dtkby[e(1821)]("|"),c=0;for(;;){switch(a[c++]){case"0":var u=Qi[r];continue;case"1":if(i.VGXxB(void 0,u))return u[e(1209)];continue;case"2":Xx[r](f,f.exports,Te);continue;case"3":var f=Qi[r]={exports:{}};continue;case"4":return f[e(1209)]}break}}Te.d=(r,e)=>{let i=I;for(var a in e)Te.o(e,a)&&!Te.o(r,a)&&Object["definePr"+i(1417)](r,a,{enumerable:!0,get:e[a]})},(()=>{let r=E;Te.o=(e,i)=>Object[r(939)+"e"][r(1412)+r(1417)][r(1255)](e,i)})(),(()=>{let r={tXwnM:function(e,i){return e!=i},uMPFK:"undefined",UytxG:"Module"};Te.r=e=>{let i=I;r[i(1360)](r.uMPFK,typeof Symbol)&&Symbol[i(1654)+i(1504)]&&Object[i(1383)+"operty"](e,Symbol[i(1654)+i(1504)],{value:r[i(686)]}),Object[i(1383)+"operty"](e,"__esModule",{value:!0})}})();var Y={};function Gn(){let r=["ugT3zKW","Aw9Ul2PZB24","vePSCLm","CNnVCKzPBgu","tujHtM4","rKDSvKK","rxzLBNq","sg5oBvq","CwL2DfC","lcbTyxGGCMu","B25tDgfYDfi","Cxj5Axu","y2XVC2uSihC","z2v0s2v5","refcANe","mdaWmdaWmda","qxn4BKm","ugTzt2m","veLNrhG","vMTRq3m","tgf0Cw0","CufhsKC","B2jQzwn0u3q","BhrpDeS","wfzyu2m","DM9Rsvu","su1uA0y","DwPYsva","B0LuEuy","seDvBxG","ywnRtxnNswq","EwrUyKu","BwDJwhe","ruHTvwu","Effez0m","u2LOD3K","AKLLDNq","DMXStu0","D0jMBuS","q0foA2q","tg1uBeS","txjIwxu","z3nWA0W","B25nzxnZywC","AgLcr2i","uvHHrui","u2HlANK","D2PSyK8","AvPUvKK","tuzrzMK","wMv1u0u","ruPfrw8","ihrPBwvVDxq","rfzlrLi","yw5Hz2vY","ndmWmda4zwzqwMLX","Bez4s28","y2HLy2Tszwe","Dg9VigXHCMC","x3bYB3rVy28","A1n0yxr1C0m","B2znr0G","yNLL","ChrVCG","rgvjBxK","vKHoyNG","B3PSBKK","wLfhrvm","zwjsAhi","CgfNzxnOB3C","CgvYC2LZDgu","y3vYC29Yx2y","B3jdrNO","thrqsK0","x2LZtwLUAvq","CxPwDe8","EKvYzfu","rxjYB3jdB2q","teTtz2u","q0Xpu0ve","DwHxEhu","BMjqsKm","q3vZDg9Tq2W","yvnZzMC","B25VCgvU","ru5st3G","x2LZtwLUAvC","BIWGAg9ZDg4","CenVq1y","suH1wKy","BM93","zfvvDKC","yxv0B21HDgK","Bg9NsurozxC","x3DHAxq","x3jLy29UBMu","Dg9tDhjPBMC","x2LZv29YA2u","AenqsMC","r2r0z1G","CMvHzg9UBhK","EgDWuLu","swflt2q","ChbL","DvPoyKu","ENnOtKG","x2LUAxrqCM8","CMvZB2X2zq","yw51Ce1LC3m","x29Ut3bLBG","qwj4tNy","DNbMEgy","Ag9dDKy","zNv5yui","yM9KEq","sLHKuvi","n3W2Fdb8nhW","z3HdzK8","DgfIyxnL","s0PMBxC","qMHKAMi","zhvivuK","y1DyDhm","whfkvgG","v1DSAui","DhDgEwS","q0H2Cwm","sxv0BLK","zw5HyMXLuw8","BM5Ly3q","uhfnCNG","vuvlqvK","ugjrr00","zw1PDa","zw5NDgG","BMfTzq","veD3Efq","tentDMq","t2DiEhe","rwzWsuW","yxGGCMv0CMK","yvbwt3K","mNWW","qMfVz1C","zg9Uzq","Dw50","DwDNsgq","sM9UwgG","teDQvK4","qwjVCNrfCNi","qw1VDw50","twvfy0y","x2TLEvbHDgG","ELvNvNu","CMnryMW","y29UBMvJDgK","tMnQCLi","qKXPv20","zxnrt0u","vLrPqLy","DfDotw8","tvPpAK0","y2vZC0HHBMq","Aencz3a","mLjwBu51wq","CK9NB2S","zgvS","rfzzCK0","mxW0","B3jpBMXPBMu","C2v0u3rVCMe","uLjpuG","tLLMsNe","ywLVzwW","CgXAy0i","EffyAey","z2u6ia","vNzMDLC","D2L2qLi","y291BNq","zgrjrcWGzgu","C0nVDw50zxi","A2j5yNG","tg9Ssxq","BwvZC2fNzv8","yMXVy2TLza","u3P3suG","t3HwBNm","C3Dqvuq","C1PcEfa","z3vYy2O","tufxsM4","qNncr2m","wezTCxa","DfPOsvu","x194x21Zz18","zuz5ufi","x3bHDgHlzxK","qLzuA1G","qvPfr3i","vvHoEvO","EffVueG","vMDjy2C","AMLvs1u","ihzHBgLKihm","Cxr2Exe","B2HzrLa","rwnmtuK","DMLJzuLeig8","Bg9IywXty28","CM9YrxzLBNq","ywrK","CxPSA2y","ntC2nJuYnvnWuLjyAG","AxnAzxjV","vKXgzfu","AgvHzgvY","CgfYC2u","yw1LoIa","Dg9cExrLC0i","weLkr1C","zw5KCg9PBNq","wxrZBMe","DuTwEeW","rwvmvu8","uvfcseW","CMPmCNe","C3vIC3rYAw4","BgLTAxq","BezSDxnO","ve1wuKq","AxnszwfKEq","BMrWB2LUDca","qLH6s1C","zgv2AwnLx2K","C2v0y3vYC28","yMvjEvG","BvDzD04","u3rYyxrLz3K","CNrSzLC","zgf0yq","x3nLBMrby2S","zgvSzxrLrge","y3HUtNK","wwLnvgu","seXcwvq","CgLUz09Uy2u","tgP6AhK","B3jLtMfTzxm","q1bkvxG","mtqZmtGWBwPKwujV","x3nVy2TLDa","q2nZDNm","B2zMC2v0","rvDKweO","C1Luqxi","BeX2vhG","B2XKvMvYC2K","z0jzALO","DwPSBvK","ywDLu2HVDW","BwvKAwf0zwW","qLDgAeS","C3bSAxq","zfjuB3q","B25mAw5L","ywX3yxLZ","uxvLDwu","y3jLyxrLtwu","y29UBMvJDfm","u2vYDMLJzvC","Cu1MEe8","t2vLDMy","tNDpsKq","twXrDvy","Dg9oDw1Izxi","C0XPC3rLBMu","ENP4AxG","qNHAD3C","ugjvCLi","CgXLyxnLiha","DeLK","Bwf4twvZC2e","EwPdBwy","BeHHBMrSzxi","y2XLyxi","CKHWv1C","ChjVDg9JB2W","Ahrbq2C","DMfSDwvZ","BM9Uzv9UB24","zhv2EfO","sMDWwgG","vxnxC20","DMvUDa","y29UBMvJDca","uLvxAxK","CgzduKi","z2vY","ihrYEsbYzwm","x2LUAxrhBg8","ufbqq1C","AM9PBG","tLzVsfi","wxH5rKC","s01nBMi","BMvY","suXxqwi","x2rItMfTzq","x3jLywr5q2W","Cg9PBNrdB24","mxW0Fdb8m3W","v0zLDLC","Bxrwq0u","C0XSExu","BeDpAMW","Dw5KzwzPBMu","x2DLBMvYyxq","v3jmEKO","BwvZC2fNztO","wNnVrgq","qufsAfa","ExbL","CgLUz0XVC3m","y3vYC29Yx24","CMXLu2O","CMvJzxzPzwq","wNbbrve","DvvIrLO","y3ruAw1LB3u","yxrLz3C","ywWGy3vYC28","zeHpDgC","qvjetKm","Bg9N","x2n1CNnVCK4","Aw5N","u2DIqwS","EMTxAeG","rLDt","Bwu6ia","z2v0q3vYC28","rNrdrwS","CwTRyxm","sfnTD2C","EsbJBg9Zzwq","AfPvD3a","BwvZC2fNzq","r0Dvq3m","shbos2i","v3LSBeC","EKD0A3O","DxbNCMfKzw4","v01Yugu","t2LZAvG","r3n3s1O","s3vuqwi","C3nHz2vfDMu","Aw5JBhvKzxm","ignVzgu6ia","igzHAwWSig0","D0TXuNm","AxnmB25N","qNPXrhC","sxPjs2u","DMfSDwu","EKnArvG","yNvMzMvYzwq","Bwf4tg9ZC0m","wvvzwwe","C2v0","rhPhrK8","wgP1ELy","s21lALu","BMnhrhu","rLLQEhy","y3jzB2G","BwvZ","CMvTB3zLq2G","zNjVBuHHC2G","C3rYAw5N","reffq24","vMnRzhe","ruDks0i","z2v0qwXSs2u","x25HDMLNyxq","qw90zxi","thzktxa","t0XqAMi","AhjStwm","wKjVExC","BNzMq2e","s1zJs2W","wvfZq0G","BMDuAw1LCG","se9hqu4","D24GCMvHC28","Ew5pAeu","twfiwMW","y29Uy2f0","CMvXDwLYzwq","CNjVCK1LC3m","zMLUza","CgLUz0LUDgu","DxjS","yMzXuM0","BfrPBwvVDxq","rxP4rgW","Cw9isK0","y29UC3rYDwm","s0vgzK0","yK5QquK","ywXSB2nvBNm","zxnSBuW","yu5IAgu","DgvZDa","Dhj1y3rVCIa","y1P0t2e","uNHWDuG","u1bJA0S","y3jLyxrLrwW","tevcrK4","Eu5hue0","Dxj3vMe","C3rVCcbPBw0","aaaaaaaaaaa","x2HHBMrSzva","DKrREum","zxjFCw9Z","yurJyxe","zw50zwqGDhK","x21LC3nHz2u","D0ztwey","u2vXsuq","y3jLyxrLuMu","vMzbvhy","C3jJ","Bgz2vfq","CgLUz19VBMm","CNzHBfzHBhu","zwzfyuO","teDyy0G","sKrrsu0","y3vYCMvUDeK","DMvY","AKP5q3a","zxjFBxnNAwq","AKvvy3e","zxj2AwnL","DKHPquu","x2HHBMrSzu8","EvjLy29UBMu","ALzwC28","BfjzDxy","x29UugfNzu4","qNLLwuW","BhrPCgXLihq","DwztA20","DhnwBei","DK9tyuq","t2jQzwn0","icSG","twvZC2fNzuu","vxfhDvi","D3nZoI8V","AgfZ","C2vUzf9Hy2S","Aw1LCYbPBIa","tfLdrKy","CNnVCL9Uyw0","Cg9W","mNW0Fdf8mhW","v2Pqy20","AgLjCwW","z2DYDva","AxnrB1nnzxm","yKn0zNi","Bhv2rwK","sg1rr3e","wu1quu4","s29XDKq","t3nyqve","ywDLsgLKzq","shLAre4","tKvVvfO","z1rPBwvVDxq","y3jLyxrLq2W","zxmGCMvHy2G","zgvSzxrL","igzPzwXKoIa","s0jfrxe","AwXSihvZzsa","nxW0Fdf8m3W","yxbWzw5Kq2G","q0Xpu0LorW","CK5UBvO","C3rYAw5NAwy","yMLUza","zhjQz2y","x3jLBw92zvC","yK1ty08","Bg93","zgvIDwC","r3nUvKK","CK5kCg0","vuHIswW","zfHKv3u","vwz5Afa","tKDFrvjst1i","vg1LANO","B1HsDxq","svvuvfu","tKjvB0m","ENjQCKK","BgvY","yw1L","whvHuvC","ywv5AK0","C3P5BNa","zufJAW","DK9vDgy","B2nRzxrgywK","D1zoEhK","vxbKyxrLq28","B2zM","uNvmuNm","rgP0qu8","rKfcugm","tNrXwxy","vwL6AMS","zcbLCNjVCI4","Bwv0Ag9K","qvv6tNO","BwLXvuC","DxrVuMvJB24","uvPNBgS","r0L1vLm","D3b5AK4","wLnrBKW","CYbHBhjLywq","tuvtu0fhrv8","BMDRweq","wg9LAwm","Cwn0D2O","qMfcwha","tfvvz28","zxP4wuK","rhvXvM4","wNjXsw8","BgvKEwu","y0Pgugq","qMDev08","Dw5ZAwDUzwq","B2fK","EMHMzgC","ueLvuhm","z2v0u3rVCMe","qKz6y1K","x2LZtM9Kzq","surhA2S","wK9bDgq","rMHbBhC","y2HLy2TdDxi","wg53uvi","CNnVCL92ywW","ANnZD3u","vwn3Exi","y2XLyxjtDg8","tMvwrfe","sMHMwNK","D09ID0G","ueXeq1C","CwL3u3u","CMvZzxrfBMq","x29UrxjYB3i","BfLovwm","CgLgv0W","s0vjuxK","r1rNCLu","uNn0u2y","rejVyMS","rKTfEuy","r0jHreO","BMDMA2O","z2v0t3DUuhi","zhvdveW","rhHsy0e","ihbYB3rVy28","yu5xwuK","r0zjsw4","ANvKwxG","BM5kBLG","C3vJy2vZCW","yNL0zu9MzNm","zvvYBa","rLLIzhC","v3bvAKi","m3WYFdf8mhW","uvfVz2q","thzxru0","quXm","yxbbvve","vgDYsve","Dvfyruy","A2riq00","yNvYB2W","B3nLrxzLBNq","rK1qzxO","B2zMBgLUzq","ugPpyMG","qMPPwNm","CMvZDwX0","BfvUz1m","twH3AK0","Dg9iyxnO","ChvZAa","mxWWFdr8m3W","CNzHBa","BvblDeO","uxD3vMq","vxj2wM8","DxnLCKLW","v0jgy08","Aw5KzxG","CMvHzhDYAxq","CLzHBhvLCW","ihzHBgLKigq","quDms0i","DKfAq3e","rxfZsNe","AenSB3nLrxy","x2rLyNvN","yM9L","Aw50zwDLCIa","EgvxDfq","BMnVzgLUzW","ve1Xy3i","zwn0","D2fZq2XLyw4","tvPIq28","CMvUDevUzha","yNvMzMvY","CwvkDfK","DwfAquq","D09HC20","rLjHs2O","AgfUz2u","vK5Ouem","ugTJA2u","sxvLywm","r0DwEgq","tMHly0u","x2LUDgvYDMe","z0Tls3K","DMnlqvC","qMjoBw4","rNHRz3O","zw5fDMvUDa","vuvms0W","CMvWBgfJzq","rvLlDMy","y1Pnsxi","mty4Eg1QzMnv","vwvOvLa","x2LZqNjVD3m","Cg93","zgLZywjSzue","tufyx1jfvfi","wunqvvG","zxrxB3jRq2G","vuzoC0e","C2XPy2u","x2rPC2nVBM4","AKnfueO","vxHTBgW","sKHyBuO","sursyKe","C3P2qvO","re1myMe","yxKSig5LDhC","EM5srhC","q291BNq","ywnOzwqSihC","n1brzeXKDa","tKHnD0C","CuTJD3O","DgvTugC","BxnNsuq","AfPjsxK","x2fKzfDZtgK","AhDPAwO","CMXmBxa","rMrvrK0","CMvQzwn0","x29Uq2XVC2u","D05QDhG","Dfn6EKW","twnUqvO","B2nRzxrtDwm","zw9dC0G","AgvKtwf4uMu","r2TlB3i","tfD6s3e","uNPZt0q","yKn4vuO","ywXSzwqGBxu","z29PBMCGyxC","DwPhqxq","yLrMAxy","ELfdANy","x2vUzhbVAw4","wNDbC0S","C2DPza","ihrPBwvZ","zxjFAxnFywm","BKnJA2C","Dgv4Dc9WBge","zxjFCw9Zx2e","yM1MAhq","y2vvv3u","tfPfqvG","D3jPDgu","wvHYrNi","zw5JB2rPBMC","vxL0EeC","t1bftG","wM1lAvq","s21izKi","Eeztwgq","wNLntMC","z2v0","s1PHwLm","yNzNDhq","BNrbBMrvCgq","zMDeu0K","sefgqK4","B1zczuK","ugnYrMS","uezHCfu","z0n6wNq","yxv0BW","DhjPBq","EMn3qwq","zNjVBujPDhm","mhWZFdr8mxW","igXHCMDLCIa","shDZCvi","svnbDLy","AxnbCNjHEq","y29UBMvJDeu","wNz1Bfm","wMXUDMC","yMjhBeu","AgLuvfm","zvnZBfe","AwrI","qwHgwwu","zgjkDeW","zxjYtxnN","y1jpD3i","mNWXFdb8m3W","uMDIyLi","rK55BwC","DxLxr2u","EuzmEuq","wMHzzLa","EK9vCvm","ywXPzcb1CMW","DxPwwvy","sef0weq","q29Kzq","wNvrzeu","C3rVCMu","EMDOqvC","wMXpBvy","y2jZwNO","mZbgBNvktKO","rufytvG","DeLuu1m","zMLN","B25Uzwn0Aw4","Eezytxu","vwLAv0u","qvvlquW","ueHkBuO","zxq9DxrMltG","wezoCLm","mdaWma","zMLSDgvY","zgL3tNi","y011CMe","qNjPzgDL","yxrLq291BNq","AuXdDfG","zw50","BNL0tKe","vwDAB1a","BwPkEgy","y2XVC2u","ueLxwvu","whHYwMG","x3bPBMC","y0DMtue","rNjVBNrPzxi","D3HcCuC","BwL5uhK","quf1tvC","zNjVBNrPzxi","o2nOyxjZzxq","ywrKrxzLBNq","yM1eue8","rxLcyMW","C2vUza","tKDozeO","zMvY","zxjHDg9Y","yMLUyxj5","yLbYs1C","ExbfBwO","CMv0CNLdB3u","yxvYseS","ywnRpwzYB24","DgHyC0W","Cw9Zx18","AfbRvNm","rLbZCNe","tMT0qxi","BgXxEgy","x3vYBa","B3bLBG","BfrlshO","vMfAugy","uKXwveK","sLPmsuW","vwj2r20","v3zhDMu","vfb3Bhe","sxDStLK","AK9wyu0","zNjVBuj5Dgu","qKjtvem","whPewxi","uuTqzeW","BgvUz3rO","yw5Nzq","EuPNCg4","vgLTzw91Da","y3zsALy","zNDZxZeUmc4","DMzIuxu","rgLlwLm","B25fCNjVCG","tLLfwxq","DgfYz2v0","rLjvwfO","Dg9Y","EfzlzNO","AxnrB1nby2S","txfKqwe","wwrfr0O","BMCGzMfPBgu","Cgf5Bg9Hzeu","qwXXs3u","uvjVu3G","swfSD2K","y0rUs1m","z2LWANi","rfPAqNa","t1b4C20","y01gCvy","ywjVCNq","tNPRz3m","Aw9UvgLTzw8","Dw5RBM93BIa","x3bPBMDqB24","DxbKyxrLq3u","tg9NsurozxC","D3DQtLG","svLtrhG","zwnhzgK","Dvvhuvu","sgDAEMm","yvPOEuG","C2v0q3vYC28","CxPZrxC","zLjlr3C","EwjJCgi","AgvHzgvYCW","C29YDa","ufHUC3u","tM1nrxG","BxzgtLe","zxHTzgW","Euvvwg4","uejnCMG","y0DuCwm","zNP6DxO","BMrWB2LUDfq","sK9qEey","vfvkEMK","qLf3yw4","wvj3ufy","x2rLC3rYB3K","zxfYsgK","yw5ZzM9YBvq","Aw47y2HHCNm","svzwz1u","B255Axu","EMngBhe","ru5rA3G","vMDWtgW","yxbWBgLJyxq","AwXLtMfTzq","txHUB3y","CuPeEKy","vuHgvhm","uvfQuuC","weTMq04","yxnJCMLWDa","t1HdvMe","ywzL","zuXTC1u","yw5iruS","yMfSu2nVCgu","nxWY","BLnOwhG","t2nREKC","uNzhCe4","D21Qr1G","C2v0sxrLBq","B3rLDee","yxnZAwDU","C09JuMm","C1LjDgq","yxnL","B25dBg9Zzq","B25SAw5L","mNWZFdb8mxW","x2jPBMfYEvq","s0vIChe","x3bPBMDmB3m","q2rstvi","C2PYt1K","C0Lmwu4","zwnVBM5Ly3q","suvtx0vsuK8","uhHuu2q","Dhzkvuq","BwDovNa","B2LUDfjLywm","AMTzshO","s0XLwvG","BwfUDwfSihi","txrHAfG","s0Lmy3i","Ae1kBMO","wMvfB08","quTjs2W","qKHiBhK","swXjq0W","wxrxBg4","CMvHC29U","sKHOyxa","y09Wzw4","x2rYB3bhBg8","v0zvzLK","t1zAtxq","mhWXFdn8mNW","Cgf5Bg9Hza","x2nSzwfYugK","BMv3vMvYC2K","zuTXzNa","q1z4vLi","Ec1TC2CTy3u","wKXKEwG","sgvjBu0","D3zbz1K","ChjVDg90Exa","nxWXFdn8mG","vgzYrKu","v25YzxK","quznAw0","Cw5pthm","z2vtEw5J","BNrLCG","CePrz28","v3jOwLi","zNPZrNa","zM9YrwfJAa","x3DZ","AxLAwNa","wgXUwMS","zxf1ywXZ","CgfNzwHPzgu","t2fAsKm","ChLTrxi","BNDqu1y","C25Ivhm","qNv0Ceq","yxKSihrYEsa","Cu1tte0","v0rJBwK","EKLTqwK","CfzJrgC","De1HBMfNzxi","DhjHBNnHy3q","B3bLBIa","y1jLEMC","v3Pju0m","DhjPzxmGCMu","Cg9PBNrbBMq","AMvJDfn0B3i","seDNtha","vxDQBNy","ChrHBNK","t0DVC1a","ChjVy2vZCW","x2XPC3rLBMu","DgvmB2Djre4","C0Xf","ENLQA1y","DMrmzuW","yvfuCwq","zxjFywnRx20","v2vIu29JA2u","BwvY","x2LZsw5PDa","q1rzqw8","BNrfBMrWB2K","CgLUz1rPBwu","v0XYEfa","vgXvzMq","tgLrrxi","su5tvefova","mtm4mdG5ndrYuw9Qq3O","uhjtwLu","Ag13y2m","x2n1CNnVCKy","CwjTv2m","uenfBuS","Ee9oBxm","sKvgr0W","s0Tys2C","ywnRx2nVzgu","tK5jC2C","s0rLsM8","DfzSz28","CuDTALu","yxrHlcbKyxq","ywrKq291BNq","ywnRx2LK","Ewr0Auq","wMvywKG","rujHt1C","Bvz4AeK","y3jLyxrLrxi","CYbPBNn0yw4","y2LIv0i","ihn1y2nLC3m","EezdB08","rhHvuum","BwLUzW","z3bnuMK","z2v0q3vYCMu","AKLPufK","A2v0ignVBNm","C1nHvve","x21PBMLoyxy","EuzfzhC","r29izgC","x0rctMfTzq","uw9QA0e","D2LSBfjLy28","D29bt1K","v1vAsKS","ywDL","y0L5ug8","AfHouLm","yw1Lu3bHy2u","AwXK","Bwnby2u","v2vNDNa","qxPUDwC","uK9Rzw8","BgLZDgvUtMu","BxbMDwy","Bg9Nsurhzw4","z3f4seO","v0fiC1m","qLjzC0u","DeXyCfO","D0DsBvq","ser5u00","BgDVugW","vLfmrM4","uxHhqvK","s09tuvu","sevhsKm","vu9Zyue","zMPmB0G","t3HLsKm","zxjYB3i","CNj1t0u","EMXSs3e","CMvKDwnL","t1bftL9fuLi","DMTRww8","svzyB3a","t3vksuG","Ae9Wzw5fDMu","t3DWqwG","zMrrD0C","s1ftAwy","tvDWDLi","A1DdD2C","q3vZDg9Trxi","vK9Ty0u","Cu1Xvgq","mtm0mdKYouzZEvPcva","A1LPsgK","DxrMofDYAxq","y2X5CgW","uMvHzcbWyxm","svvPDuG","AefJA01LC3m","DxfVwLu","ANrzqM8","BMCGDxjSoIa","vuXiCui","B25szwnLAxy","wNrJBuC","BNvTyMvY","z2v0sxrLBq","wxfLA1G","ywLHDMq","s2npufa","DhzqDvu","DK1bvxK","mtC0otK3oxfmsej5rG","C3bSAwnL","y29UDgLUDwu","t0nsDK4","wMjyvMe","twDhBhm","uM1IAxq","zgLZCgf0y2G","DMvYC2LVBG","DwrLwwm","zcWGDw5RBM8","r05btuu","ELDyq3O","u0LhsMq","sLL5uwe","x3bYzwzPEa","EgvKt1G","u2Hsq1G","Dg9cExrLC0W","BLzxu08","vMzRr20","BMv4DcGPigm","CMTLCKDSB2i","y29Kzq","CMvWBgfJzui","yNL0zuXLBMC","CMvJB25Uzwm","CMvHzfvjBNq","DgHLBG","y21csfK","B3v0sw50zxi","qxnNz0m","Efrurw52","x3fVC0rc","y2HnyxHuCMK","x29WDgLVBNm","CMvZzxrdB3u","vMnNBwi","BgLUzw5V","tMPAEKm","zNjVBunOyxi","q2XJy1O","DvHjs3a","zw5HyMXLvhi","z2vjBMzVu3K","zMzLCG","ywnR","BLLxDMy","y2XVC2veqG","tg9JAW","z2fWy20","tePSC2G","DuznzgC","mhWZFdj8nxW","Dg9cExrLCW","s2rRwvK","uwDXDvK","B2nRzxq","rePWz1i","thfYAhu","DuXbwue","rvvjCfa","tvrjthq","Efzfr24","CMfTugfYyw0","zNbetLG","zMX1C2HfEha","u3j5DNC","zxLZru8","zM1WveO","vM5wBhG","DcbVzIbYyw4","t3bLBKv2zw4","DeLUDgvYy2u","CMvTB3zLrxy","zNvUy3rPB24","C3r0tui","uhjPBwfYEuS","CgXQq1m","rg5gqvO","Aw9U","tMfTzq","tg9Nsuq","wKr2Cgy","CMfUzg9T","D3jPDgvvAw4","BuHtswi","Aw5KzxHpzG","DvfxDwy","y3vYC29Y","swX5quC","v1f4BuO","zw50tgLZDgu","re9tEfK","zxH0zw5ZAw8","C2Pmvfu","AevYCM9Yrxy","y3jLyxrLt3a","v3jUreO","x3nLCuLK","B3bLCNr5tMe","zwvKzwq","BgLRDMS","zNjhzMq","ALDeAKe","vgfxCLy","B25tDg9Wsw0","AxjLza","rLjptLrjrvi","zxHWB3j0CW","qxfjEfm","wNrRquq","AgLNAa","t1P2DMy","x2rPC3bHDgm","wvLcC0y","zhDKr1e","EhztCu8","vMP0zxO","s1rrChi","B3vqs0m","A2v5","uMnIwNq","zv90Aw1LB3u","t3H4y3q","tfvmwuG","s1bTt0C","q2Dhs0K","DwvHvNu","ywnRDxbfBMq","DLDIt24","BenozxG","DfPfsey","t3Pvu3O","uMLJvu8","zw1LBNq","zsbHihn0CMK","CMfTzq","vu5Hs00","DwDkq0W","reDgBMK","sLvQC0u","rvbOtKi","wMjPtei","tgLZDgvUzxi","zMncAeK","C2jhqwW","C3vIyxjYyxK","B25LCNjVCG","y3vZDg9Tshq","DhjPzxm","vvrJAxa","y2PYyK0","vfjkr0G","z2v0qwXS","y2fSBa","re5LBu4","CIb0DhDjra","x1fVu01HBMe","rwPqD2i","r2zdD3q","zw5XDwv1zq","y2f0y2G","rMnoEw8","B01ZuvG","DhLWzq","jMPZy2fSBgi","AK9ftLq","B3jRig9MzMW","ChfqCK8","yKjuyu0","B3vUDa","vwXJDfy","rNrWr2i","rNvVDMy","x3DZsw5ZDge","rLrzq0y","r2DtvgC","y2HnyxHdB3u","qKnyAu0","s0nWtMK","tu1yC2S","wuLJwuK","tgHhtNm","s3HSEMK","BMnLq2XVC2u","rvjst1i","Aw5PDcbrB1m","Dhr3Awq","ugfgvKy","B25JBg9Zzq","sLjmr0W","AwXLx25HBwu","BwTTDKq","whnvshu","s21JEgW","uw9ntvm","DxLrq0u","rwTKt1a","x2zVCM1HDeu","sKv0ExC","y3vYCMvUDeu","EKjHAMm","AwDHDg9Yt24","C3rLBMvYCW","ywHvsMy","C2nYAxb0","zxH0ugf5Bg8","BKXUwKm","DMvYC2LVBMm","DgLTzw91DcW","BNPbzNO","vw5PBxbSzw0","mxW5Fdv8m3W","y0D6rK4","mJaYmty2muneyxztBG","suDQve4","zw5JB2rLrNi","ign1CNnVCIa","veffDeK","swDzA0O","B3LTDMi","AhfkBwK","EMzxzK8","zNjVBu51Bwi","ALPku1e","BwPMshe","ywrKt25L","yw5wuNy","Dxrjza","C0LQB2C","vgrxq1i","vKzfrfu","AvrlBxO","zhfirKC","lcbxzwjtB2m","vvjVs3i","Dev2zw50","EMjmq2C","y29UBMvJDa","tKfusvzfx0u","C0jf","uvHXzhC","FdH8mxW0Fdu","y2HHCKnVzgu","DNnIAgK","q29UzMLN","Ahr0Ca","DhDVCMTdAge","y3vYC29YlNm","r3LxyNa","Chv0","l3DZl3yY","vuHOAuq","y2LZBhe","zwL3yuK","uMjVDwy","C2fNzq","vMnHDey","v2rltwy","DfH3BK0","rLDRthO","wujcwMW","Cfjctuq","CM92AwrLige","zuvUsfq","Aw5KzxGGB3u","DK1AsM4","CvPrq3m","BLjhD3e","sLnptLa","B25ozxr3B3i","BwLZzq","wMPZu3m","Aufsywi","x2HHBMrSzvi","t05Ny2C","tej3Che","zhr0DNG","Bhm6ia","Bwzoqwm","wLbXBw4","B3jL","zgvMAw5Luhi","CfbLtMW","uw55t0y","DejUrNO","C2HPzNq","BgLRwei","ug9Hq3i","ihrVihjLDhi","ru1ywfG","uhzbEui","DcbSAw1PDa","rK1wExC","qNnrwgO","BgLUzq","DLLhuhC","Duzzy3K","Cwnlr0i","t2jKA24","mJDUtM1ysKC","DwL5EhG","Bfvjwgm","ANLjueq","zfDVCMTLCKC","zNjHBwvuExa","DgHHBIbSB2m","s1PyA00","zeTbvLm","sNr0r2i","Dg9mB3DLCKm","AgfZt3DUuhi","C1Pxwg0","Cgf5Bg9Hzfq","ANrXEuW","Aw5Iu0y","B3bLCNr5","x2nVBM5Ly3q","y0jPq1a","zMLSzw5HBwu","Dg9hzw5LCMe","CM92AwrLihy","vNvHvg8","thH4rNC","rNvZC3y","igfYCMf5yNu","Dgv4DfbHEwW","qMTwsfC","CMLLC0nVDw4","wLzdwKu","yvPIseW","yMLUyxj5vhK","rLHqsNa","BMPrAuK","DK93qM0","rKLmrv9ot1q","v1zUCMC","qK1Lzxy","vxPAr3a","yxbWBhK","qNvvtK0","uhj6Bxy","BLDXtum","u1nvq2W","C2vYuLO","y29SBM8","wKrAAM8","ywXty29Wzq","B3nLza","qwjmBve","wNjszMi","x29UtwvZC2e","CwD2veu","x2LUAxq","DvbwvMe","v1DruNi","B3bLBKrc","z2fwthe","AwzgzKC","B25TzxnZywC","Cgu6ia","u3PMwfi","CMvRCwe","rxDxzhG","rgvRy1u","uMvJB25Uzwm","C2v0zgi","vK1QqKG","re5HsgS","Ae1LC3nHz2u","uLLLtvK","ELPzr3G","ywDLrxzLBNq","uuj2txi","DwDKEhq","z0jxrw8","B25pCgvU","EhbRweq","Ef9MCM9UDgK","yxjYyxLIDwy","v2vPEgLUsLm","ywr2yw5Jzq","BMDLza","z2vrDwv1zuW","DLH6Bxi","BKXPBMu","r2nvEeq","DgLTzw91Da","C29wBNa","ALfjDuC","x2nSzwfYvgK","r2Hhrge","zvDnzvy","Axnby2TdBgu","BMrLEa","rK1VrNy","txfHueO","wM15rgK","zM9Yy2u","uNLrsui","rezovvO","tMrry0e","u2z0zeO","vgfN","EwHgzxi","x2nYzwf0zvm","Ec11C2uT","v2jou2K","zMzmAw5L","vunXB1C","qwXUDNq","CNfzAMq","B3nVy0S","DevKu0C","Eeffwve","twLZC2LUzYa","s0X3rMe","wKLqDuG","x2DLDeLUDgu","Bwf4uMv0CMK","qxfzEvi","yMrFzgLK","yNL0zxm","q01yBvi","A2v5CW","zu5os3a","C2vYDMvYvgK","Bw9jAMu","q09otKvdveK","u21jz2q","CMvHzhLtDge","AKvPwwG","x29UvgLTzw8","zv9ZDwnJzxm","ExzTrem","zgvJB2rLzey","Cvf2z1q","wefsvKK","yvrXB0u","u2TPCcbWyxm","BwLUAvbYB2C","z0zwqMS","z0rIs0m","BNruCMLLC0m","C2vYDMLJzq","x2n1CNnVCK0","ChDOu0q","Dufsz1a","B3jRzxjhBg8","DvPOrge","BwrIqKO","CMvJzwL2zwq","Aw5Lza","s21xA1C","yMfSrxzLBNq","ywnOzwq","sKTIt1K"];return Gn=function(){return r},Gn()}(()=>{let r=E,e={AhFYe:function(s,t){return s===t},LEBFN:r(1770),ahUJf:function(s,t){return s(t)},AFMim:function(s,t){return s+t},lUngS:function(s,t){return s*t},PLDCW:function(s,t){return s+t},SPckK:function(s,t,n){return s(t,n)},eiwaI:function(s,t){return s===t},Lmjjq:r(506),MaHZl:function(s,t){return s(t)},ybcpb:function(s,t){return s+t},fgDSI:r(749),UYhAa:"ffff",tCrhq:r(1573)+r(1573)+"0000000000000000",Uxmll:r(760),qeJtY:function(s,t){return s&t},bPrKW:function(s,t){return s(t)},aioel:function(s,t){return s&t},Iueac:function(s,t){return s<t},OgHxq:function(s,t){return s!==t},qivtW:function(s,t){return s-t},xQDgC:r(1234),TAEtI:function(s,t){return s-t},TMqcr:function(s,t){return s===t},ydtiD:function(s,t){return s<t},ZDZjo:r(538),cMura:function(s,t){return s!==t},ISAvV:function(s,t,n){return s(t,n)},ClccZ:function(s,t,n){return s(t,n)},DjtAO:function(s,t){return s(t)},UTcip:"uozaN",AsggC:function(s,t){return s>>>t},QXaEB:function(s,t,n){return s(t,n)},Vcgmb:function(s,t){return s(t)},HgZzc:function(s,t,n){return s(t,n)},ltOtK:r(1516)+r(1958)+r(451)+r(1221),ngkXD:r(1516)+r(1958)+r(451)+r(1923),URoKr:function(s,t,n){return s(t,n)},dRTot:function(s,t){return s(t)},sLlyu:r(1996)+r(1223)+"t",NmMEx:function(s,t,n){return s(t,n)},zrjrI:"ping_onc"+r(1534)+"s",SSUCl:r(554),zcwAd:function(s,t,n){return s(t,n)},fRKGw:function(s,t,n){return s(t,n)},qZQCs:function(s,t,n){return s(t,n)},AARhP:function(s,t){return s!==t},AGLKB:function(s,t){return s!==t},bCtfr:r(1087),RyQIB:function(s,t,n){return s(t,n)},AbLmQ:function(s){return s()},LGjVN:function(s,t){return s(t)},tZhIU:function(s,t){return s!==t},NjZzC:function(s,t,n){return s(t,n)},vHiAE:function(s,t){return s!==t},LUUgo:function(s,t,n){return s(t,n)},bNjAI:function(s,t,n){return s(t,n)},IYSDx:function(s,t,n){return s(t,n)},EjgLs:r(1308),Fussv:r(1718),JttGb:function(s,t){return s(t)},CqYOz:function(s,t){return s(t)},eWMeV:"QSggv",cBiCP:function(s,t){return s(t)},XzDYr:function(s,t){return s(t)},KPmOG:function(s,t){return s(t)},duCTL:function(s,t,n){return s(t,n)},WvGve:function(s,t){return s(t)},oITyF:function(s,t,n){return s(t,n)},rekqa:function(s,t){return s(t)},OCRvN:function(s,t,n){return s(t,n)},eEnHT:function(s,t,n){return s(t,n)},YIcYI:function(s,t){return s(t)},YdEGJ:r(1516)+"required"+r(451)+r(1991),ptany:function(s,t){return s===t},VnVlx:r(1516)+r(1958)+" field: "+r(1545),sjLTU:"Missing "+r(1958)+" field: "+r(493),UbvGm:function(s,t){return s(t)},JhfZy:function(s,t){return s+t},likvk:function(s,t){return s&t},UsWsm:function(s,t){return s(t)},PBMrh:function(s,t){return s+t},bBTaM:r(1312)+r(1988)+r(1461),ZhYfP:function(s,t){return s instanceof t},IcLLH:function(s,t){return s!==t},LKSge:function(s,t){return s===t},DOSxY:r(1394),ZeuSE:function(s,t){return s>>t},gCzZt:function(s,t){return s===t},CTYAo:function(s,t,n){return s(t,n)},BjiZs:r(495),YUqFb:r(827),RxpuH:function(s,t){return s>t},wFSXF:r(1540)+"t limit",JDQIM:function(s,t){return s>=t},luvEi:function(s,t){return s+t},JBVEf:r(1922),inbSF:function(s,t){return s>t},TJlrS:r(1084)+r(1393),qbmWc:function(s,t){return s+t},KuTAb:function(s,t){return s===t},KoqvD:function(s,t){return s===t},hCBgp:r(2021),Bhdjb:"MCHqP",BvicH:function(s,t,n){return s(t,n)},AKIKl:r(898),EfpIL:r(955),zfWfO:r(1627),EGJKB:function(s,t){return s>>t},ZPqmn:function(s,t){return s|t},Fxkgz:function(s,t){return s<t},Uwjnv:function(s,t){return s-t},GBaDJ:function(s,t){return s!==t},KdkYY:r(992),dttvx:r(1024),IbxUN:function(s,t){return s>=t},lLvTx:function(s,t){return s+t},hXNRS:function(s,t){return s<<t},KCpNi:function(s,t){return s&t},gFVBk:function(s,t){return s==t},jOVaM:function(s,t){return s>=t},uZhDa:function(s,t){return s+t},bMScO:function(s,t){return s+t},mjfHq:function(s,t){return s&t},rOgok:function(s,t){return s===t},vdLeL:"LxVjs",pwhSD:function(s,t){return s|t},DNemN:function(s,t){return s<<t},serRZ:function(s,t){return s&t},YxyFG:function(s,t){return s<<t},UEKAY:function(s,t){return s&t},gurcj:function(s,t){return s<t},NHMwG:function(s,t){return s<=t},oMsQX:function(s,t){return s===t},gDbKC:r(552),KmKjU:r(1846),VlqmA:function(s,t){return s==t},AbxNv:function(s,t){return s>=t},MMXsk:"HcVHx",burol:function(s,t){return s+t},KLwFa:function(s,t){return s+t},Alnvt:function(s,t){return s+t},BkVHW:function(s,t){return s!==t},aTqoE:function(s,t){return s&t},SIGJd:function(s,t){return s|t},xvSqO:function(s,t){return s|t},OXCVa:function(s,t){return s&t},eSslQ:function(s,t){return s<<t},jIevt:function(s,t){return s&t},sSaUQ:function(s,t){return s>t},FYjxv:function(s,t){return s+t},UHbIl:function(s,t){return s>>t},ZtcmG:function(s,t){return s<t},BXzKW:function(s,t){return s<t},OckzG:function(s,t){return s<<t},fzzuz:function(s,t){return s>>t},QwwVd:function(s,t){return s&t},fmpTJ:function(s,t){return s>>t},GkKor:function(s,t){return s|t},wwjNX:function(s,t){return s>>t},VaZPf:function(s,t){return s|t},CmNdE:function(s,t){return s&t},dqHFG:function(s,t){return s|t},VfATv:function(s,t,n){return s(t,n)},LCSvd:function(s,t,n){return s(t,n)},LQWdt:function(s,t){return s>>>t},QojkA:function(s,t){return s&t},FVaUT:function(s,t){return s>>>t},QKPdL:function(s,t){return s+t},LrHeB:function(s,t){return s&t},xedOX:r(1532),IutnY:r(1904),qMqTd:function(s,t){return s&t},ynOhE:function(s,t){return s&t},MBaNn:function(s,t){return s|t},Ytsna:function(s,t){return s&t},fdQwG:function(s,t){return s<t},AUzNz:function(s,t){return s>>>t},VOmcE:"2|10|6|1"+r(1313)+"4|7|0|1|8",EAXMX:function(s,t){return s<t},KEbpq:function(s,t){return s|t},VgpLl:function(s,t,n,o){return s(t,n,o)},pRBMD:function(s,t){return s&t},OVZMt:function(s,t){return s<<t},GNAME:function(s,t){return s|t},temPg:function(s,t){return s(t)},uFYcy:function(s,t){return s&t},KZXkM:function(s,t){return s<<t},uhWxu:function(s,t){return s===t},GoHdg:r(1276),nvfCa:function(s,t){return s(t)},pqPrO:function(s,t){return s&t},roDZc:function(s,t){return s&t},beIyX:function(s,t){return s(t)},VLFdU:function(s,t){return s&t},BFzcY:function(s,t){return s(t)},ncGDu:function(s,t){return s<<t},Ccsvs:function(s,t){return s&t},ZmKiT:function(s,t){return s&t},DxRcA:function(s,t){return s(t)},RgbbR:function(s,t){return s&t},SgbAk:function(s,t){return s(t)},Latqm:function(s,t){return s<<t},jmpUr:function(s,t){return s&t},Mxnov:function(s,t){return s>>>t},qgvTE:function(s,t){return s>>>t},ecGdi:function(s,t){return s>>>t},MAWJn:function(s,t){return s===t},Fuovf:function(s,t){return s<t},yNGPM:function(s,t){return s<t},jOENT:function(s,t){return s+t},KZaZS:function(s,t){return s!==t},lRYuv:function(s,t){return s|t},mcAce:function(s,t){return s|t},IPBmA:function(s,t){return s>>>t},IDGkk:function(s,t){return s|t},ZrqIo:function(s,t){return s&t},OuJIH:function(s,t){return s>>>t},PbQGM:function(s,t){return s!==t},OGosP:function(s,t){return s>>>t},njQiI:function(s,t){return s>>>t},UNaKM:function(s,t){return s>>>t},tBnFz:function(s,t){return s>>>t},LcUQV:function(s,t){return s!==t},SmIgd:function(s,t){return s|t},XKfCN:function(s,t){return s>>>t},dXdWu:function(s,t){return s+t},xyOTr:function(s,t){return s&t},NeVDQ:function(s,t){return s|t},UDEcN:"tHsLg",dKAVS:function(s,t){return s(t)},xVEGn:function(s,t){return s|t},JHXmJ:function(s,t){return s===t},aQTqd:function(s,t){return s===t},bSFOA:function(s,t){return s!==t},XxrZh:r(1109),hoCvF:r(1595),bCxUJ:function(s,t){return s|t},EaCpt:function(s,t){return s<<t},TGwxT:function(s,t){return s|t},zCZEX:function(s,t){return s<<t},tvJUD:function(s,t){return s<<t},aSsfg:function(s,t){return s<<t},zriqY:function(s,t){return s<<t},OisiX:function(s,t){return s<<t},vMZJn:function(s,t){return s|t},COrTt:function(s,t){return s<<t},cGfMA:function(s,t){return s|t},EWdXJ:function(s,t){return s<<t},QXqdw:function(s,t){return s>>>t},Jlztb:function(s,t){return s|t},anHEK:function(s,t){return s>>>t},EwWdx:function(s,t){return s>>>t},FWkLz:function(s,t){return s>>>t},snbTs:function(s,t){return s>=t},ZVCZE:function(s,t){return s<=t},WQxmJ:function(s,t){return s%t},vZzmU:function(s,t){return s/t},bvgtt:r(1478),ZuQdE:function(s,t){return s+t},UHFTs:function(s,t){return s>>>t},ZsoDd:function(s,t){return s>>>t},DzGFO:function(s,t){return s&t},JEtyw:function(s,t){return s&t},LvWEM:function(s,t){return s>>>t},Oxxct:function(s,t){return s>>>t},BbNmn:function(s,t){return s+t},QnyOF:function(s,t){return s+t},hCPJg:function(s,t){return s|t},xVKfz:function(s,t){return s<<t},xAEYQ:function(s,t){return s===t},JZLIL:function(s,t){return s===t},eNNKp:function(s,t){return s===t},EOhgE:function(s,t){return s+t},iARab:function(s,t){return s&t},wKqRs:function(s,t){return s>>>t},vIROr:function(s,t){return s>>>t},hZIIy:function(s,t){return s&t},KDeJo:function(s,t){return s&t},UHhiD:function(s,t){return s>>>t},cRezg:function(s,t){return s>>>t},OsXAQ:function(s,t){return s&t},OSAJQ:function(s,t){return s>>>t},UCqoW:function(s,t){return s>>>t},yFEdw:function(s,t){return s>>>t},DekcU:function(s,t){return s>>>t},ggruP:function(s,t){return s&t},TaWrV:r(1153)+r(1726),sYItd:"NATIVE_E"+r(1729),yFLyD:r(1067)+"OR",vOUtf:r(629)+r(907)+"R",FNymg:"CONNECTI"+r(470),ohYFP:r(502)+r(1286),jsswu:r(1498),hiBGb:r(1633),QRoSx:function(s,t){return s===t},VoQQP:"JNQUG",ecUZu:r(1995),aurHK:function(s,t){return s instanceof t},sdYKm:function(s,t){return s===t},YYBsF:r(1702),vWbOn:r(734),HLBYT:function(s,t){return s in t},VuaTo:function(s,t){return s!==t},YmGMk:r(1946),esQOE:r(1272),MZOjM:function(s,t){return s!==t},RLYOh:r(1186),NhKcE:"KVpDZ",YvpET:"CrTeo",zhfdg:r(1805),xQoPH:function(s,t){return s===t},ezxYI:function(s,t){return s==t},hPkVs:function(s,t){return s>t},QQjQG:function(s,t,n){return s(t,n)},eslmL:function(s,t,n){return s(t,n)},cGzFN:r(1620),LQoih:"going aw"+r(641)+r(1268)+"ine",thXsL:"btHfj",XlnZk:"LPRbG",IgYkJ:function(s,t){return s instanceof t},BWFhK:function(s,t){return s+t},xeWtT:"Unhandle"+r(492),sILYN:function(s,t){return s===t},TPwlq:function(s,t){return s===t},Lpeuy:r(1497),bgIyf:"BiCvk",LhGNs:r(1063),SftdJ:function(s,t){return s===t},AfhOp:r(1233),uARgP:function(s,t,n){return s(t,n)},urwVa:r(791),Rbouf:function(s,t,n){return s(t,n)},JgpXh:function(s,t,n){return s(t,n)},ROkeo:r(1596),OxeJC:function(s,t){return s===t},tsVlB:r(1176),TUJzi:r(1175),mgcXq:function(s){return s()},ZwAsK:r(1496),jCEPJ:r(1294),onyiu:function(s,t){return s||t},MFQfi:function(s,t){return s||t},IGjTN:function(s,t){return s!=t},lFxKo:r(1874)+"d",pJQgo:function(s,t){return s<=t},aZbHL:function(s,t){return s===t},NyxZa:function(s,t){return s&t},WrLzJ:function(s,t){return s+t},GsnVI:r(578)+r(886),WAHsS:function(s,t){return s+t},mPKtJ:function(s,t){return s+t},mtVCE:function(s,t){return s<<t},KEFfM:function(s,t){return s&t},AsxnC:function(s,t){return s&t},pljCS:function(s,t){return s|t},RsKme:function(s,t){return s&t},kJANx:function(s,t){return s|t},cjrbM:function(s,t){return s>>t},ZpAEQ:function(s,t){return s<t},OAefp:function(s,t){return s-t},EkdOP:function(s,t){return s>=t},WWQRr:function(s,t){return s<t},Ewkze:function(s,t){return s<<t},wGaze:function(s,t){return s&t},yHuAH:r(1302),XuaQW:r(1218),VcatF:function(s,t){return s-t},frGfd:function(s,t){return s|t},sZBxP:function(s,t){return s|t},IJBel:function(s,t){return s|t},ZvulS:function(s,t){return s<<t},DBobk:function(s,t){return s&t},rNnmZ:function(s,t){return s<<t},bTfiv:function(s,t){return s&t},UXNyZ:function(s,t){return s&t},Pkcke:function(s,t){return s>>t},PIUPs:function(s,t){return s|t},Wnrey:function(s,t){return s&t},QLyaQ:function(s,t){return s===t},FtCEk:r(454)+r(1700),JKbOY:function(s,t){return s|t},eoCsH:function(s,t){return s&t},YXrFr:function(s,t){return s&t},qJDzF:function(s,t){return s>>t},BBWOw:function(s,t){return s&t},PrSZU:function(s,t){return s>>t},lYNUc:function(s,t){return s+t},wmjGX:function(s,t){return s<<t},ZOAtd:function(s,t){return s>>t},sbtbE:function(s,t){return s|t},NYEYt:function(s,t){return s&t},FhAlw:function(s,t){return s-t},ZlOmV:function(s,t,n,o){return s(t,n,o)},uiyxx:r(1938),diwNr:function(s,t){return s instanceof t},ILWAb:r(873)+"ion/json",ledye:r(678)+r(867)+"et=utf-8",LJlsh:r(594),LBwpq:r(1661),HAFBN:r(1095),RcbZt:r(1902),kuadT:r(835)+r(923),eLmsU:function(s,t){return s+t},IHuZF:r(1306),aBbFR:r(1266)+r(783)+"tierJSONP",WBFcO:r(513),ebRhr:function(s,t){return s!==t},xFSXd:r(1905),CVxVR:function(s,t){return s!==t},PaALQ:"TUiKB",cZMIr:"gVZRJ",crYoh:r(717),PaFVF:function(s,t,n,o){return s(t,n,o)},znRDw:"WLWBU",McnAZ:function(s,t){return s>t},BLiWm:function(s,t){return s>t},XjuzV:r(1227),LvJMp:r(1744),aAluk:r(1802),pNqBD:r(571),aeyjM:r(1119),dbJtL:"tiwiO",KBEEq:"jaEVJ",Kmcxl:"ydKIo",mWYwN:r(1901),FcNyo:function(s,t){return s||t},vOwBm:function(s,t){return s||t},ZSQnL:function(s,t){return s||t},exmdl:function(s,t){return s>>t},KMMnb:function(s,t){return s>=t},rNSXk:r(1609),uUGQU:function(s,t){return s||t},fcBhI:function(s,t){return s||t},EjPwb:function(s,t,n){return s(t,n)},jJyCp:r(1659),WrnDJ:function(s,t){return s!=t},eKqfp:function(s,t){return s!=t},IwlNY:r(1287)+"DB failed",otetA:r(1742)+"id",jWDjA:function(s,t){return s(t)},tZEHF:"qNigg",vpfxf:r(1514),fzsFp:function(s,t){return s(t)},qtvyq:"GNhdt",rleSj:r(702),uKVxL:function(s,t){return s===t},ujGAt:r(490),vXzmr:r(1479)+r(679)+"ck",mgNVp:function(s,t,n,o){return s(t,n,o)},nShXx:r(1479)+r(676)+"k",lUIXc:r(1479)+r(985)+r(674),DVYrM:function(s,t){return s(t)},ByeYL:"SytpC",kbybx:function(s,t,n,o){return s(t,n,o)},WMrPe:"need_ack",Ucwyr:function(s,t,n,o){return s(t,n,o)},BMeev:"is_ack",KKXKg:function(s,t){return s!==t},wpyjN:r(1909),Nzkgs:r(1012),FRaKj:r(1005),MhwjM:function(s){return s()},qjluv:r(1552),kxfrL:function(s){return s()},wVNxy:function(s,t){return s(t)},qrlFr:r(873)+r(1559)+r(770)+"=utf-8",JOPxF:function(s,t,n,o){return s(t,n,o)},rNJpm:function(s){return s()},uduQh:function(s,t){return s+t},PoTrO:function(s,t){return s>>>t},BzqDw:function(s,t){return s+t},nnJnX:function(s,t){return s||t},yopLn:" > ",cmBHY:r(595)+r(1616)+"e",EyBbl:function(s,t){return s>=t},UOsaA:function(s,t){return s+t},tITSS:function(s,t){return s+t},IVVgU:function(s,t){return s>=t},DQkJZ:function(s,t){return s+t},zbLCg:function(s,t){return s&t},jEUcq:function(s,t){return s!==t},RLVTI:r(1760),duHUI:function(s,t){return s+t},JYyQa:function(s,t){return s<t},sjrOY:function(s,t){return s===t},Kxlzi:function(s,t){return s>>>t},ATavo:r(1869)+"2",aiavd:function(s,t,n,o){return s(t,n,o)},TIgDx:function(s,t){return s|t},HyZDN:function(s,t){return s<<t},miyPy:function(s,t){return s+t},HGUmx:function(s,t){return s+t},uFMdg:function(s,t){return s|t},rOoVd:function(s,t){return s|t},clypl:function(s,t){return s|t},FXPJp:function(s,t){return s<<t},hrlMc:function(s,t){return s(t)},ceUWu:r(657),cxnNy:r(755),twFyk:function(s,t){return s+t},uQXEF:function(s,t){return s&t},WFUfY:function(s,t){return s+t},MZbCo:function(s,t){return s&t},mhEPM:function(s,t){return s+t},apAUQ:function(s,t){return s&t},wGRmT:function(s,t){return s>>>t},rvfcb:function(s,t){return s&t},PHJmJ:function(s,t){return s+t},uZNbE:"sVfSc",PqMrx:"0|3|10|9"+r(1343)+"|6|7|2|11",CPJUx:function(s,t){return s>t},KLeYX:function(s,t,n,o){return s(t,n,o)},BFJap:function(s,t){return s>>>t},XFmqp:function(s,t){return s<t},JqYbS:function(s,t){return s<<t},IqsLg:function(s,t){return s||t},yvmDC:r(914)+r(906)+r(1894),zzTdq:function(s,t){return s(t)},qctwj:function(s,t){return s+t},TxyVK:function(s,t,n,o){return s(t,n,o)},zImAi:"service-name",KJLXl:r(1693),QgquY:function(s,t){return s(t)},bmfht:function(s,t){return s<t},NwOJD:function(s,t,n){return s(t,n)},gBYjZ:r(1436)+"_EXIST",wOasm:r(1882)+"ame",EqsJq:"allCurso"+r(587),oymvb:r(562),LaNkI:r(995),BRYsE:"CONTINUE",uaZAD:r(1605),MTILt:"bplWA",ShKjy:function(s,t){return s(t)},UFNsA:r(1793)+"r",BxZww:function(s,t){return s instanceof t},PPPCW:function(s,t){return s!=t},qcKGB:r(1069),iTKmz:function(s,t){return s===t},UrvZo:r(917),XXuQa:r(1161),BVUWV:r(1123),UfyhP:function(s,t,n,o){return s(t,n,o)},RstSf:r(1479)+r(2004),rtlfW:r(1479)+"er_ttl",IUiuH:"x-msg-qos",AlqKu:"x-msg-cu"+r(2027)+"e",QCyBX:function(s,t){return s(t)},GGUCs:function(s,t){return s>t},WUZJK:function(s){return s()},vYGPw:r(993),GswKZ:"BpcYv",jVVso:function(s){return s()},ButpD:function(s,t){return s===t},GcUxD:function(s,t){return s&&t},IlICL:function(s){return s()},DxUQC:function(s,t,n){return s(t,n)},rBYZt:function(s,t){return s!==t},Obdkn:function(s){return s()},qAGJG:function(s,t){return s<t},zGBBE:function(s,t){return s===t},OaZJC:function(s,t){return s!==t},NEoTZ:function(s,t){return s===t},KJfmw:r(1554),kdHCM:function(s){return s()},XIJGW:function(s){return s()},kbAqi:function(s,t,n){return s(t,n)},Tmejz:function(s,t){return s|t},cvRjV:function(s,t){return s<<t},ZyMNg:function(s,t){return s<<t},vKOTW:function(s,t){return s<<t},BsQXj:function(s,t){return s<<t},tvPuU:function(s,t){return s<<t},ujrIP:function(s,t){return s===t},uQWuf:r(1369),cMFqV:"always",BsBGc:function(s,t){return s!==t},NVoHR:r(1072),cCXhN:r(1150),gspkL:"NNFIB",fjLoH:function(s,t,n){return s(t,n)},Rmbit:function(s,t){return s!==t},wivBR:r(570),zOUqS:"pEoCy",vOSaD:function(s,t){return s!==t},lCNex:function(s,t,n){return s(t,n)},HAtXD:r(1468),KOSQU:"pbbp2",RMRQG:function(s,t){return s/t},ULHqB:function(s,t){return s==t},RvGpN:r(1838)+r(1422)+r(729),tSzzL:function(s,t){return s(t)},GWXaM:"please provide ws params"+r(1335)+r(1027)+r(1974)+"is undef"+r(1553),OPxsm:function(s,t){return s!==t},ZrRfb:r(1844),jZJSQ:r(1064),hiTTS:function(s,t,n){return s(t,n)},nCckg:r(1126)+"t",CCAxf:r(1982)+"ediately reconnect",rqYjd:function(s,t){return s!==t},sOcRc:function(s,t){return s!==t},uYIJh:function(s,t){return s(t)},mkmvD:function(s,t){return s(t)},YQsCH:r(1681),qQvgT:r(963),AZEGr:function(s,t){return s==t},NNIsg:"https:",zWXCz:"wss://",nzAfz:"ws://",ImUeg:r(1522),DZZBp:function(s,t){return s||t},TRJGH:r(1838)+"rovide b"+r(1738)+r(1766)+r(1257),DiKZS:function(s,t){return s==t},HOGAN:"web",ZtkAD:function(s,t){return s!==t},CANkd:r(1015),PXQzk:function(s,t){return s||t},RzsOD:function(s,t,n){return s(t,n)},xFCoO:function(s,t,n){return s(t,n)},JHhap:function(s,t){return s(t)},HoGaq:function(s,t){return s(t)},PatEG:r(994),IUTTU:r(1699),HwVau:r(1488),QoMMS:r(668)+r(961)+r(1126)+"ting ser"+r(2002),uzVYV:r(1310)+r(1857)+r(742)+"g",PkYOc:r(2024),FdUFM:r(2029)+"3",NGNdJ:r(899)+"4",nwPSV:function(s,t,n){return s(t,n)},osocK:r(1146),CHvqc:function(s,t){return s<t},HGgLp:r(653),yfSfE:r(1404),mdbBJ:function(s,t){return s+t},MeEcF:r(1674)+r(940),HmQGq:"close, w"+r(1018)+"ce not initialized",PvAyB:function(s,t){return s===t},MlQuV:r(1570)+r(501)+r(1903),KILcr:r(1093),iZnVI:function(s,t){return s instanceof t},NBUoC:function(s,t){return s(t)},PoaCr:function(s,t){return s||t},WpUjB:r(1838)+r(1364)+r(1762)+r(2006),ugJCL:function(s,t){return s(t)},uyQCE:r(525),TgrIQ:r(1849),RuLRs:"sent",vAZCq:function(s,t){return s<t},ZQGES:r(1261),OKgtd:function(s,t){return s!==t},QTeAC:r(929)+"4",dsWzC:function(s,t){return s|t},drjgf:function(s,t){return s|t},qryiu:function(s,t){return s<<t},GhGDa:function(s,t){return s<<t},nYWvf:function(s,t){return s!==t},FGlVI:r(965),mVxhI:function(s,t,n){return s(t,n)},KcOPP:r(1983),XFNrS:function(s,t){return s/t},BBSTC:function(s,t){return s!=t},ARDNC:"Window",gKKKy:function(s,t){return s===t},IaKOd:r(2018),EHHcm:function(s,t){return s!=t},VfkGm:function(s,t){return s===t},soVnp:"Dedicate"+r(1405)+r(1767)+"pe",zllKq:function(s,t){return s===t},llWxf:"SharedWo"+r(1122)+r(1448),vMAUy:r(1828)+r(1549)+r(885),WzISC:function(s,t){return s!=t},lfVaI:function(s,t){return s===t},MlsWG:r(1753)+r(785)};Te.r(Y),Te.d(Y,{FWS:()=>E0,CustomErrorEvent:()=>As,createCloseEvent:()=>ye,ReconnectEvent:()=>Es,createErrorEvent:()=>pe,decodedFrame:()=>ys,createOpenEvent:()=>Ns,CustomCloseEvent:()=>ks,createReconnectEvent:()=>gr,FrontierMessageEvent:()=>Ps,encodeFrame:()=>hr,createMessageEvent:()=>Ts,OpenEvent:()=>Ds,ErrorCode:()=>je,Event:()=>ut,MessageEvent:()=>Is});let i="";function a(s=""){let t=r;if(e.AhFYe(e[t(1979)],t(1081)))this[t(988)]=!0,this[t(1418)]();else{let o=""+Date[t(1648)](),x=i||(i=e.ahUJf(m,s)),l=Math[t(1184)]()[t(1654)](16)[t(633)](-6);return e[t(943)](e.AFMim(e.AFMim("02",o),x),l)}}function c(){let s=r;return e[s(943)](e[s(574)](1e4,Date.now()),Math.floor(1e4*Math.random()))}function u(s){let t=r;return e.PLDCW(e[t(1305)](Array,8).join("0"),e.SPckK(parseInt,s,10).toString(2))[t(633)](-8)}function f(s){let t=r;if(e[t(1355)](e.Lmjjq,"WKmTX"))this[t(1989)+t(1825)][t(1387)](),this[t(1989)+"Queue"].push(_0x1ba017);else return(e[t(1305)](Array,4)[t(1860)]("0")+e.SPckK(parseInt,s,2)[t(1654)](16))[t(633)](-4)}function h(s){let t=r,n=s[t(1821)](/\./).map(l=>u(l)),o=[];return o[0]=f(e[t(533)](n[0],n[1])),o[1]=e.MaHZl(f,e.ybcpb(n[2],n[3])),[e[t(696)],e[t(696)],"0000",e.fgDSI,e[t(696)],e.UYhAa,o[0],o[1]][t(1860)]("")}function m(s){let t=r,n=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[t(1973)](s),o=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[t(1973)](s);return n?h(s):o?e[t(1305)](_,s):e.tCrhq}function _(s){let t=r,n="",o=[],x=0,l=0,g=!0,p=e[t(696)];if(s[t(1187)]("::")>-1){let d=s[t(1821)]("::");for(let b=0;e.Iueac(b,d[t(805)]);b++){let k=d[b];if(k[t(1187)](":")>0){let T=k.split(":");g&&(x=T[t(805)]),l+=T.length;for(let R=0;e.Iueac(R,T.length);R++)if(e.OgHxq(4,T[R][t(805)])){let B=p[t(1785)+"g"](0,e[t(1566)](4,T[R][t(805)])),V=B[t(1957)](T[R]);o.push(V)}else o[t(577)](T[R]);g=!1}else if(e[t(1592)]!=="RicUO"){let T=this[t(1135)][t(1126)+t(1173)+t(1621)](_0x1c2302,_0x1b198a);this[t(1214)+t(592)+t(756)](e[t(1977)](_0x51c5c7,e[t(636)],{code:_0x1afb1d,reason:_0x22f5a3,wasClean:!0,willReconnect:T})),T&&this[t(1418)]()}else{if(e[t(1696)](4,k.length)){let T=p.substring(0,e[t(1566)](4,k.length)),R=T[t(1957)](k);o.push(R)}else o[t(577)](k);g&&(x+=1),l+=1,g=!1}}let w="";for(let b=0;e[t(611)](b,e[t(1319)](8,l));b++)w=w[t(1957)](p);for(let b=0;b<o.length;b++)e[t(598)](b,x)&&(n=n[t(1957)](w)),n=n[t(1957)](o[b]);return n}{let d=s[t(1821)](":");for(let w=0;e[t(1013)](w,d[t(805)]);w++)if(e[t(1447)]!==e[t(1447)])_0x3e7d47=e[t(1305)](_0x2b43fb,_0x436457),_0x2beaeb=e[t(604)](127,_0x650668),e[t(604)](128,_0x1f9271)&&(_0x419851=e[t(779)](_0x214c1b,_0x1c7cc1),_0x51aeb5|=e[t(1731)](127,_0x4d2a4b)<<7);else{let b=d[w];if(e[t(1696)](4,d[w][t(805)])){let k=p.substring(0,e.TAEtI(4,d[w][t(805)])),T=k[t(1957)](b);n=n[t(1957)](T)}else n=n[t(1957)](b)}return n}}function y(s,t){let n=r,o=s[n(1221)];e[n(752)](void 0,o)&&(e.ISAvV(J,t,10),e[n(1141)](Ce,t,o));let x=s[n(1923)];e.OgHxq(void 0,x)&&(J(t,18),Ce(t,x))}function v(s){let t=r,n={};e:for(;!e[t(488)](Re,s);)if(e[t(1251)]===e.UTcip){let o=z(s);switch(e[t(1131)](o,3)){case 0:break e;case 1:n.key=Se(s,e.bPrKW(z,s));break;case 2:n.value=e[t(1603)](Se,s,e[t(1137)](z,s));break;default:e[t(843)]($,s,e[t(604)](7,o))}}else this["maxLossC"+t(1271)]=_0x20809a,this[t(1737)]=0;if(e[t(1355)](void 0,n[t(1221)]))throw new Error(e[t(1581)]);if(n[t(1923)]===void 0)throw new Error(e[t(503)]);return n}function S(s){let t=r,n=Z();return e[t(1336)](A,s,n),e[t(1822)](j,n)}function A(s,t){let n=r,o={KEIQy:function(se,re){return se(re)},UehVP:e[n(1872)],GTgrU:function(se,re,Ee){return e[n(852)](se,re,Ee)},cJFPd:e[n(475)],nCtIX:e[n(1444)]},x=s[n(1991)];x!==void 0&&(e[n(852)](J,t,8),e[n(704)](Lt,t,x));let l=s[n(1182)];e.OgHxq(void 0,l)&&(J(t,16),e[n(847)](Lt,t,l));let g=s[n(1545)];g!==void 0&&(e[n(1368)](J,t,24),Lt(t,e[n(779)](oe,g)));let p=s[n(493)];p!==void 0&&(J(t,32),Lt(t,oe(p)));let d=s[n(849)];if(e[n(1879)](void 0,d))for(let se of d)if(e[n(589)](n(957),e[n(2034)])){e[n(1500)](J,t,42);let re=e[n(1450)](Z);y(se,re),e[n(852)](J,t,re.limit),e[n(709)](rn,t,re),e[n(1706)](P,re)}else{let re={uUbFZ:function(Ee,lt){return Ee(lt)},zUgVu:o.nCtIX,VTiBV:o[n(625)]};return new _0x4f4e98((Ee,lt)=>{let ce=n,ht={ouPKC:function(te,A0){return o[I(539)](te,A0)},KQSif:o[ce(625)]};this[ce(931)+"ngTimer"](),this[ce(836)+ce(447)+"Id"]=o[ce(540)](_0x30bf26,this[ce(763)][ce(459)](this),this._options[ce(1961)+"rval"]);let Mt=()=>{let te=ce;re[te(1886)](Ee,re[te(1711)]),this[te(486)]("ping_onc"+te(1534)+"s",Mt),this.off(re[te(1717)],nt)},nt=()=>{let te=ce;ht[te(1220)](lt,te(1488)),this.off(te(1996)+te(1534)+"s",Mt),this[te(486)](ht[te(1074)],nt)};this.on(o[ce(512)],Mt),this.on(o[ce(625)],nt),this[ce(763)]()})}let w=s[n(823)+n(597)];e[n(1752)](void 0,w)&&(J(t,50),e[n(1139)](Ce,t,w));let b=s[n(1414)+n(1880)];e[n(2007)](void 0,b)&&(e[n(507)](J,t,58),e.QXaEB(Ce,t,b));let k=s[n(930)];k!==void 0&&(e[n(1969)](J,t,66),J(t,k[n(805)]),e[n(847)](nn,t,k));let T=s.LogIDNew;e[n(2007)](void 0,T)&&(J(t,74),e[n(704)](Ce,t,T));let R=s["serverTi"+n(1023)];e.OgHxq(void 0,R)&&(e[n(840)](J,t,82),Ce(t,R));let B=s[n(649)];e.AARhP(void 0,B)&&(e[n(507)](J,t,90),Ce(t,B));let V=s[n(1406)+"e"];if(V!==void 0)if(e.EjgLs!==e[n(1425)])e[n(1368)](J,t,96),e.RyQIB(Lt,t,e[n(1410)](oe,V));else try{this[n(951)]&&this[n(951)][n(760)](_0x1774e6,_0x487fc3)}catch{}}function D(s){return e[r(1956)](L,e.CqYOz(U,s))}function L(s){let t=r;if(e[t(1493)]!==t(1673)){let n={};e:for(;!e[t(1419)](Re,s);){let o=z(s);switch(e[t(1131)](o,3)){case 0:break e;case 1:n[t(1991)]=e[t(847)](Be,s,!0);break;case 2:n[t(1182)]=e[t(852)](Be,s,!0);break;case 3:n[t(1545)]=e[t(803)](z,s);break;case 4:n[t(493)]=z(s);break;case 5:{let x=e[t(1410)](F,s);(n[t(849)]||(n[t(849)]=[]))[t(577)](e[t(1226)](v,s)),s.limit=x;break}case 6:n[t(823)+t(597)]=Se(s,e[t(1956)](z,s));break;case 7:n[t(1414)+"ype"]=e[t(547)](Se,s,e[t(797)](z,s));break;case 8:n[t(930)]=e[t(1586)](Nt,s,e[t(1463)](z,s));break;case 9:n[t(838)]=e[t(1103)](Se,s,e[t(488)](z,s));break;case 10:n[t(1527)+t(1023)]=e[t(1365)](Se,s,e[t(1226)](z,s));break;case 11:n.msgID=Se(s,e[t(779)](z,s));break;case 12:n[t(1406)+"e"]=e[t(1282)](z,s);break;default:e[t(843)]($,s,e[t(604)](7,o))}}if(e[t(598)](void 0,n[t(1991)]))throw new Error(e[t(821)]);if(e.ptany(void 0,n[t(1182)]))throw new Error(t(1516)+"required"+t(451)+t(1182));if(n[t(1545)]===void 0)throw new Error(e[t(1170)]);if(e[t(598)](void 0,n.method))throw new Error(e[t(1195)]);return n}else _0x27c7db(e[t(1444)]),this[t(486)](e[t(475)],_0x4b63f8),this[t(486)](e[t(1872)],_0x3afe26)}function F(s){let t=r,n=e[t(796)](z,s),o=s.limit;return s[t(1786)]=e[t(531)](s[t(1811)],n),o}function $(s,t){let n=r;switch(t){case 0:for(;e[n(1202)](128,e[n(1851)](fe,s)););break;case 2:e[n(1977)](ae,s,z(s));break;case 5:e.OCRvN(ae,s,4);break;case 1:e[n(840)](ae,s,8);break;default:throw new Error(e[n(856)](e[n(1270)],t))}}function oe(s){let t=r,n={slltM:function(o,x){return e[I(727)](o,x)},DNaHk:function(o,x){return o(x)},LxxFw:function(o,x){return e.IcLLH(o,x)}};if(e[t(1636)](e[t(1193)],e[t(1193)]))return s|=0,{low:s,high:e[t(1608)](s,31),unsigned:s>=0};{if(jwMFCB.slltM(_0x52769e,_0x19da11))return jwMFCB.DNaHk(_0x5e25ce,_0x53ec9a);if(_0x2fd5b4[t(2023)](_0xac5530))return _0x3790d0[t(692)](_0xf1f3ac);let o=jwMFCB[t(1469)](_0xdc3a2a,_0x359faa);return jwMFCB[t(1424)](o,_0x357619)&&(_0x5cf4b3[t(1928)](_0x25ee2b,o),_0x293ed3[t(1928)](o,_0x1db8cd)),o}}let ee=[];function Z(){let s=r,t=ee[s(2028)]();return t?(t[s(1811)]=t[s(1786)]=0,t):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(s){ee.push(s)}function U(s){return{bytes:s,offset:0,limit:s.length}}function j(s){let t=r,n=s.bytes,o=s[t(1786)];return e.gCzZt(n[t(805)],o)?n:n[t(1247)](0,o)}function ae(s,t){let n=r;if(e.TMqcr(e[n(572)],e.YUqFb)){if(this["_endpoin"+n(966)]?.[n(1615)+n(1134)+"es"]()){let x=this[n(672)+n(966)]?.[n(1025)+n(990)+"nt"]();this[n(1214)+n(592)+n(756)](e[n(709)](_0x34ba02,e[n(636)],{code:1006,reason:"connect "+x+(n(1610)+n(1567)+n(971)+n(1556)),wasClean:!0}))}else{let x=this[n(1135)][n(1126)+"tInterce"+n(1621)](_0x1df255,_0x5da055);this[n(1214)+n(592)+n(756)](e[n(989)](_0x3d4e5b,e.Uxmll,{code:_0x10cfcf,reason:_0x50f5e0,wasClean:!0,willReconnect:x})),x&&this[n(1418)]()}return}else{if(e[n(1976)](s.offset+t,s[n(1786)]))throw new Error(e[n(1990)]);s[n(1811)]+=t}}function Re(s){let t=r;return e[t(2e3)](s[t(1811)],s[t(1786)])}function we(s,t){let n=r,o=s[n(1523)],x=s[n(1811)],l=s[n(1786)],g=e[n(439)](x,t);if(e[n(1976)](g,o[n(805)]))if(e[n(701)](e.JBVEf,e.JBVEf)){let p=new Uint8Array(e[n(574)](2,g));p[n(1928)](o),s[n(1523)]=p}else return this._socket[n(1531)+"te"];return s.offset=g,e[n(1416)](g,l)&&(s[n(1786)]=g),x}function Qe(s,t){let n=r,o=s[n(1811)];if(e[n(439)](o,t)>s.limit)throw new Error(e[n(1560)]);return s[n(1811)]+=t,o}function Nt(s,t){let n=r,o=Qe(s,t);return s[n(1523)][n(1247)](o,e[n(1e3)](o,t))}function nn(s,t){let n=r,o={EeLUO:function(x,l){return x<l},YCPUX:function(x,l){return e[I(1914)](x,l)},TQius:function(x,l){return e[I(442)](x,l)}};if(e[n(718)](e[n(1721)],e[n(1678)])){let x=0,l=0;for(let g=0;o[n(1782)](g,_0x2b9733[n(805)]);++g)l=_0x3bb7b1[n(1344)+"At"](g),o[n(1782)](l,128)?x+=1:l<2048?x+=2:o[n(630)](64512&l,55296)&&o.TQius(64512&_0x5294f4.charCodeAt(g+1),56320)?(++g,x+=4):x+=3;return x}else{let x=e.BvicH(we,s,t[n(805)]);s.bytes[n(1928)](t,x)}}function Se(s,t){let n=r,o={ENROx:e[n(919)],dUUvG:e.EfpIL,KTQpr:e[n(1323)],kWCwg:function(w,b){return w|b},Zlnvg:function(w,b){return e[n(1941)](w,b)},IgJSv:function(w,b){return w&b},BVTkX:function(w,b){return e[n(1381)](w,b)},zzxix:function(w,b){return e[n(1202)](w,b)},WWliB:function(w,b){return e.Fxkgz(w,b)},BCXiM:function(w,b){return e.AARhP(w,b)},uLAYA:function(w,b){return e[n(975)](w,b)}},x=e.bNjAI(Qe,s,t),l=String[n(1140)+n(732)],g=s.bytes,p="\uFFFD",d="";for(let w=0;w<t;w++)if(e[n(544)](e[n(1155)],e[n(1378)])){let b=g[e[n(943)](w,x)],k,T,R,B;if(e[n(718)](e[n(1731)](128,b),0))d+=l(b);else if((224&b)===192)e.IbxUN(e[n(531)](w,1),t)?d+=p:(k=g[e[n(1814)](w,x)+1],e[n(1202)](192,k)!==128?d+=p:(B=e[n(1039)](e[n(1280)](31,b),6)|e.aioel(63,k),B<128?d+=p:(d+=e.Vcgmb(l,B),w++)));else if(e[n(1542)](240&b,224))e[n(800)](e[n(1550)](w,2),t)?d+=p:(k=g[e[n(462)](w+x,1)],T=g[e[n(462)](w,x)+2],e.OgHxq(e[n(1326)](k|T<<8,49344),32896)?d+=p:e.rOgok(e[n(983)],"JDvGA")?(this[n(626)+"er"]&&_0x1e2305["removeEv"+n(1192)+n(1864)](o[n(1643)],this["_handleO"+n(1486)]),this._isBrowser&&_0x17b5aa[n(1174)+"entListe"+n(1864)](n(570),this["_handleO"+n(1509)]),this[n(626)+"er"]&&_0x15178e[n(1174)+n(1192)+n(1864)](o[n(1649)],this._handlePageHide),this[n(626)+"er"]&&_0x44b983["removeEv"+n(1192)+n(1864)](o[n(1219)],this[n(1984)+"ageShow"])):(B=e[n(1547)](e[n(1256)](e[n(1445)](15,b),12),e.YxyFG(e[n(1689)](63,k),6))|63&T,e[n(1748)](B,2048)||e[n(800)](B,55296)&&e[n(646)](B,57343)?d+=p:e[n(1264)](e[n(1543)],e[n(1931)])?(_0x1a1714[_0x3adf7f++]=o[n(1076)](o[n(713)](_0x644869,12),224),_0x4e1f92[_0x38b7cf++]=o.kWCwg(o.IgJSv(o[n(713)](_0x214be9,6),63),128),_0x480188[_0x22a304++]=o[n(1756)](o[n(1835)](63,_0x3b003a),128)):(d+=e[n(1282)](l,B),w+=2)));else if(e.VlqmA(e[n(604)](248,b),240))if(e[n(1668)](e.PBMrh(w,3),t))d+=p;else if(e[n(701)](n(1966),e[n(1281)])){let V=_0x283209[n(1821)](":");_0x2ed17f&&(_0x50ebc6=V.length),_0x3da1ec+=V.length;for(let se=0;eAFzqK[n(1682)](se,V[n(805)]);se++)if(eAFzqK[n(1279)](4,V[se][n(805)])){let re=_0x1fde96[n(1785)+"g"](0,eAFzqK[n(1160)](4,V[se].length)),Ee=re[n(1957)](V[se]);_0x33dacd[n(577)](Ee)}else _0x37118f[n(577)](V[se]);_0x5163ae=!1}else k=g[e[n(567)](e[n(1517)](w,x),1)],T=g[e[n(1511)](e.ybcpb(w,x),2)],R=g[e[n(848)](w+x,3)],e[n(1428)](e[n(1539)](e.SIGJd(e[n(1217)](k,T<<8),R<<16),12632256),8421504)?d+=p:(B=e[n(1217)](e.pwhSD(e[n(1547)](e[n(1862)](e[n(881)](7,b),18),e.aioel(63,k)<<12),e[n(716)](e[n(1594)](63,T),6)),e.likvk(63,R)),e[n(1013)](B,65536)||e[n(1028)](B,1114111)?d+=p:(B-=65536,d+=l(e[n(1933)](e[n(467)](B,10),55296),(1023&B)+56320),w+=3));else d+=p}else this.off(_0x1e698c,_0x46abb0);return d}function Ce(s,t){let n=r,o=t[n(805)],x=0;for(let p=0;p<o;p++){let d=t[n(1344)+"At"](p);e[n(1668)](d,55296)&&e.NHMwG(d,56319)&&e.Fxkgz(p+1,o)&&(d=e[n(1566)](e[n(1256)](d,10)+t.charCodeAt(++p),56613888)),x+=e[n(1013)](d,128)?1:e[n(618)](d,2048)?2:d<65536?3:4}J(s,x);let l=e.IYSDx(we,s,x),g=s[n(1523)];for(let p=0;e[n(1092)](p,o);p++){let d=t[n(1344)+"At"](p);e.IbxUN(d,55296)&&e[n(646)](d,56319)&&e[n(1791)](e[n(1550)](p,1),o)&&(d=e[n(888)](d,10)+t[n(1344)+"At"](++p)-56613888),e.ydtiD(d,128)?g[l++]=d:(e[n(1748)](d,2048)?g[l++]=e[n(1381)](e[n(858)](d,6)&31,192):(e[n(1013)](d,65536)?g[l++]=e[n(581)](e[n(1169)](d,12),15)|224:(g[l++]=e[n(1547)](e[n(1326)](e[n(858)](d,18),7),240),g[l++]=e[n(663)](e.OXCVa(e.wwjNX(d,12),63),128)),g[l++]=e[n(793)](e.CmNdE(e[n(467)](d,6),63),128)),g[l++]=e[n(1334)](e[n(1539)](63,d),128))}}function rn(s,t){let n=r,o=e.VfATv(we,s,t[n(1786)]),x=s.bytes,l=t[n(1523)];for(let g=0,p=t[n(1786)];e[n(1748)](g,p);g++)x[g+o]=l[g]}function fe(s){return s[r(1523)][e.LCSvd(Qe,s,1)]}function sn(s,t){let n=r,o={UiZWE:function(x,l){return e.LQWdt(x,l)},MgGls:function(x,l){return x+l},aNbhe:function(x,l){return e[I(1445)](x,l)},XVXSc:function(x,l){return x&l},hwiij:function(x,l){return e[I(1033)](x,l)},IlyAG:function(x,l){return e[I(943)](x,l)},TdWCR:function(x,l){return e.FVaUT(x,l)},vsbhi:function(x,l){return e[I(804)](x,l)},qnOLs:function(x,l){return e.LrHeB(x,l)}};if(e[n(1116)]!==e[n(1685)]){let x=e[n(1500)](we,s,1);s.bytes[x]=t}else{let x=_0x4513c7.low,l=_0x217061.high;return _0x4adc33[_0xf9027]=o[n(744)](l,24),_0x536dd3[o[n(1105)](_0x3060d9,1)]=o[n(1972)](l>>>16,255),_0x2f56c6[o.MgGls(_0x3f8d90,2)]=o[n(1582)](l>>>8,255),_0x1f7918[_0x3c20c4+3]=o[n(652)](255,l),_0x183089[o[n(1105)](_0x3dfae3,4)]=x>>>24,_0x635e70[o[n(1190)](_0x130932,5)]=o[n(1582)](o[n(1331)](x,16),255),_0x355ac0[o[n(1345)](_0x3079ac,6)]=o[n(1972)](o.UiZWE(x,8),255),_0x471025[o[n(1105)](_0x6e7670,7)]=o[n(944)](255,x),_0x80912d+=8,_0xb026a2}}function z(s){let t=r,n=0,o=0,x;do x=e[t(1410)](fe,s),e[t(1748)](n,32)&&(o|=e[t(1079)](127,x)<<n),n+=7;while(e[t(1955)](128,x));return o}function J(s,t){let n=r;for(t>>>=0;e[n(800)](t,128);)sn(s,e[n(1562)](e[n(1780)](127,t),128)),t>>>=7;e[n(1695)](sn,s,t)}function Be(s,t){let n=r,o={XKlPW:e[n(1078)],QxGAY:function(d,w){return e[n(739)](d,w)},TMVRD:function(d,w){return e[n(901)](d,w)},gaVLq:function(d,w){return e[n(1028)](d,w)},DABjq:function(d,w,b,k){return e[n(872)](d,w,b,k)},KVcKl:function(d,w){return d>>>w},GGVxd:function(d,w){return e[n(581)](d,w)},eysEO:function(d,w){return e.SIGJd(d,w)},jkYHz:function(d,w){return e[n(1363)](d,w)},gxCfO:function(d,w){return e[n(1547)](d,w)},yEUXn:function(d,w){return e[n(618)](d,w)},cislq:function(d,w){return e[n(928)](d,w)},jIiPY:function(d,w){return e[n(581)](d,w)},BxdeA:function(d,w){return e.FVaUT(d,w)},ZDvpf:function(d,w){return d|w},CdRMR:function(d,w){return d|w},IwhWD:function(d,w){return e[n(1111)](d,w)}},x=0,l=0,g=0,p;if(p=e[n(648)](fe,s),x=e[n(1689)](127,p),e.uFYcy(128,p)&&(p=fe(s),x|=e[n(1408)](127&p,7),128&p))if(e.ptany(n(1088),n(1088))){if(p=e[n(1137)](fe,s),x|=e[n(1256)](e[n(581)](127,p),14),128&p)if(e[n(1638)](n(1276),e[n(1031)]))p=e[n(1949)](fe,s),x|=e.QwwVd(127,p)<<21,e[n(1269)](128,p)&&(p=e[n(1226)](fe,s),l=e.roDZc(127,p),128&p&&(p=e.beIyX(fe,s),l|=e[n(1862)](e[n(581)](127,p),7),e[n(1773)](128,p)&&(p=e[n(1851)](fe,s),l|=(127&p)<<14,e[n(1539)](128,p)&&(p=e[n(519)](fe,s),l|=e[n(1932)](e[n(1810)](127,p),21),e[n(688)](128,p)&&(p=e[n(548)](fe,s),g=127&p,e[n(723)](128,p)&&(p=e[n(1895)](fe,s),g|=e[n(1578)](e.jmpUr(127,p),7)))))));else{let d=0,w=_0x51d385,b=e[n(1933)](_0x6cb86,4);for(;e[n(1073)](w,b);){let{value:k,offset:T}=_0x436e5e(_0x2c5f76,w);w=T,d=e[n(494)](e[n(716)](d,8),0),d+=k}return{value:d,offset:b}}}else{let d=o.XKlPW[n(1821)]("|"),w=0;for(;;){switch(d[w++]){case"0":if(o[n(1057)](_0x45010d[_0x4dc774++],128))return{value:_0x48f308?_0x5c1255:o[n(1788)](0,_0x4aeb76),offset:_0x7bce97};continue;case"1":if(o[n(1458)](_0x4cbd24+=5,_0x1b30fd[n(805)]))throw _0x1c4d57=_0x40c7dc.length,o[n(1572)](_0x288fab,_0x4b2998,10,_0x50b625[n(805)]);continue;case"2":_0xdddb57=o[n(1950)](o[n(612)](127,_0x33d22f[_0x5ecbe9]),0);continue;case"3":_0x2d0cde=o[n(1168)](_0x22ef17,o[n(912)](127,_0x57187c[_0x3b62f3])<<21)>>>0;continue;case"4":if(_0x45a860[_0x2d994a++]<128)return{value:_0x3fa501?_0x14de6c:o[n(1675)](0,_0x242b9f),offset:_0x20752e};continue;case"5":if(o[n(855)](_0x5ba032[_0x2090c9++],128))return{value:_0x2ecf36?_0x3d9c42:0|_0x57d540,offset:_0x136591};continue;case"6":_0x491ecb=o[n(1168)](_0x7adcea,o.cislq(o[n(1026)](127,_0x1484f4[_0x293f14]),7))>>>0;continue;case"7":_0x313e60=o.BxdeA(o[n(1183)](_0x2d7802,o[n(1354)](o.jkYHz(15,_0x3af09c[_0x32a05e]),28)),0);continue;case"8":return{value:_0x46d4a9?_0x23cc45:o[n(903)](0,_0x272d1a),offset:_0x19c181};case"9":_0x1d2105=o[n(1950)](o.IwhWD(_0x5a532f,(127&_0x24c993[_0x59addd])<<14),0);continue;case"10":if(o[n(1057)](_0x117785[_0x291074++],128))return{value:_0x599333?_0x2a0493:o[n(1183)](0,_0x3096a5),offset:_0x1bcadf};continue;case"11":if(o.yEUXn(_0x43d0a3[_0x14fc7f++],128))return{value:_0x5410bb?_0x4ffc04:o.ZDvpf(0,_0x3d8cc2),offset:_0x22cfa4};continue}break}}return{low:x|l<<28,high:l>>>4|g<<24,unsigned:t}}function Lt(s,t){let n=r,o=e[n(875)](t[n(463)],0),x=e.pwhSD(e[n(1453)](t[n(463)],28),e[n(1039)](t[n(1212)],4))>>>0,l=e[n(841)](t[n(1212)],24),g=e.KoqvD(0,l)?e[n(1749)](0,x)?e[n(1274)](o,16384)?o<128?1:2:o<2097152?3:4:e.yNGPM(x,16384)?e[n(1748)](x,128)?5:6:e.Fuovf(x,2097152)?7:8:e[n(611)](l,128)?9:10,p=e[n(1139)](we,s,g),d=s.bytes;switch(g){case 10:d[e[n(1267)](p,9)]=e.Ytsna(l>>>7,1);case 9:d[p+8]=e.KZaZS(9,g)?e[n(2011)](128,l):e.CmNdE(127,l);case 8:d[p+7]=e[n(2007)](8,g)?e[n(1042)](e[n(841)](x,21),128):e.IPBmA(x,21)&127;case 7:d[e[n(531)](p,6)]=g!==7?e[n(521)](e[n(494)](x,14),128):e[n(510)](e[n(1070)](x,14),127);case 6:d[p+5]=e[n(1690)](6,g)?e[n(977)](x,7)|128:e[n(1434)](x,7)&127;case 5:d[e.qbmWc(p,4)]=g!==5?128|x:e.Ccsvs(127,x);case 4:d[e[n(533)](p,3)]=g!==4?e.VaZPf(e[n(1238)](o,21),128):e[n(1386)](o,21)&127;case 3:d[e[n(804)](p,2)]=e.LcUQV(3,g)?e[n(1530)](o>>>14,128):e[n(879)](o,14)&127;case 2:d[e[n(468)](p,1)]=e[n(693)](2,g)?e[n(1042)](o>>>7,128):e.xyOTr(e[n(494)](o,7),127);case 1:d[p]=e.LcUQV(1,g)?e[n(530)](128,o):127&o}}function ys(s){return D(s)}function hr(s){let t=r,n={opfSR:function(o,x,l){return o(x,l)}};if(e[t(1690)](e.UDEcN,"tHsLg"))n.opfSR(_0x3ff1af,_0x940c4a,this["_getInte"+t(1997)+"e"](_0x194363));else return e[t(1409)](S,s)}let bs=65536,Ma=e[r(1097)],xt=e[r(574)](bs,bs),vs=e[r(574)](xt,xt),Ss=e[r(748)](vs,2),He=String.prototype[r(1344)+"At"];class q{constructor(t,n,o){let x=r;this[x(1920)]=!0,this[x(463)]=e.xVEGn(0,t),this[x(1212)]=e[x(530)](0,n),this[x(514)]=!!o}static[r(1920)](t){let n=r,o={idHWp:n(1208)+">"};if(e[n(637)](n(1501),"DFNUZ"))return t&&e[n(984)](!0,t[n(1920)]);this[n(1135)].debug&&_0x30ba08[n(1892)][n(1440)](_0x2dcef5,[o.idHWp,..._0x9bf3ac])}static[r(705)](t,n,o){let x=r,l={jtqyL:function(g,p,d){return e[I(709)](g,p,d)},swPUD:function(g,p){return e.temPg(g,p)}};if(e.bSFOA(e[x(762)],e[x(1670)]))return new q(t,n,o);ybvkIz[x(1415)](_0x3eb33e,_0x55b925,96),ybvkIz[x(1415)](_0x3e4e68,_0x462123,ybvkIz[x(1746)](_0x5d6763,_0x36e409))}static fromBytes(t,n,o){let x=r;return o?q[x(801)+x(981)](t,n):q[x(801)+x(1341)](t,n)}static[r(801)+r(981)](t,n){let o=r;return new q(e[o(666)](e[o(1163)](t[0],t[1]<<8),e.EaCpt(t[2],16))|t[3]<<24,e.xVEGn(e[o(1694)](t[4]|e[o(1924)](t[5],8),e[o(909)](t[6],16)),e.aSsfg(t[7],24)),n)}static[r(801)+r(1341)](t,n){let o=r;return new q(e.KEbpq(e[o(1924)](t[4],24)|e.zriqY(t[5],16)|e.OisiX(t[6],8),t[7]),e[o(1694)](e[o(1367)](e[o(1530)](e[o(1641)](t[0],24),t[1]<<16),e.COrTt(t[2],8)),t[3]),n)}static[r(1937)](t){let n=r;return e[n(976)](t,Ma)?Cs:new q((e.pwhSD(e.cGfMA(He.call(t,0),He.call(t,1)<<8),e[n(1812)](He[n(1255)](t,2),16))|He[n(1255)](t,3)<<24)>>>0,e.QXqdw(e[n(1217)](e.Jlztb(He[n(1255)](t,4),He[n(1255)](t,5)<<8)|e.Latqm(He[n(1255)](t,6),16),He[n(1255)](t,7)<<24),0),!0)}[r(576)](){let t=r;return String["fromChar"+t(732)](e[t(1398)](255,this.low),e.ZrqIo(e[t(884)](this[t(463)],8),255),this[t(463)]>>>16&255,this.low>>>24,e[t(1033)](255,this[t(1212)]),e.QojkA(e[t(1464)](this[t(1212)],8),255),e[t(1361)](this[t(1212)],16)&255,e[t(1361)](this[t(1212)],24))}static[r(1324)+"er"](t,n=!0){let o=r;if(isNaN(t))return n?Oa:Cs;if(n){if(e[o(959)](t,vs))return qa}else{if(e[o(1430)](t,-Ss))return Fa;if(e[o(800)](e[o(856)](t,1),Ss))return za}return q[o(705)](e[o(1191)](t,xt)|0,e[o(1113)](e.vZzmU(t,xt),0),n)}[r(1833)](){let t=r;if(e[t(1879)](e[t(694)],e[t(694)]))_0x4bfab1[t(1672)][t(1936)+t(1041)](_0x4f250d);else return this[t(514)]?e[t(733)](e[t(574)](this[t(1212)]>>>0,xt),this[t(463)]>>>0):e.bMScO(e[t(574)](this[t(1212)],xt),e[t(877)](this[t(463)],0))}[r(1772)](){let t=r;return e[t(598)](0,this.high)&&this[t(463)]===0}add(t){let n=r;q[n(1920)](t)||(t=q[n(1324)+"er"](t));let o=e.ZsoDd(this.high,16),x=e.DzGFO(65535,this[n(1212)]),l=e[n(875)](this[n(463)],16),g=e[n(1300)](65535,this[n(463)]),p=e[n(561)](t[n(1212)],16),d=65535&t[n(1212)],w=e[n(1224)](t[n(463)],16),b=e[n(1955)](65535,t.low),k=0,T=0,R=0,B=0;return B+=e[n(617)](g,b),R+=e[n(1224)](B,16),B&=65535,R+=e[n(1385)](l,w),T+=e[n(1238)](R,16),R&=65535,T+=x+d,k+=e.ecGdi(T,16),T&=65535,k+=e[n(1e3)](o,p),k&=65535,q[n(705)](e[n(1042)](R<<16,B),e[n(1656)](e[n(818)](k,16),T),this[n(514)])}[r(954)](t){let n=r;return q[n(1920)](t)||(t=q.fromNumber(t)),this[n(514)]!==t.unsigned&&e.TMqcr(this[n(1212)]>>>31,1)&&e[n(1264)](e[n(879)](t[n(1212)],31),1)?!1:e[n(1515)](this[n(1212)],t[n(1212)])&&e[n(701)](this[n(463)],t[n(463)])}[r(1327)](){let t=r;return e[t(795)](-1,this[t(463)])&&e[t(976)](-1,this.high)?q[t(705)](0,0,this[t(514)]):e[t(1526)](-1,this[t(463)])?q[t(705)](0,e.EOhgE(this[t(1212)],1),this[t(514)]):q[t(705)](e[t(943)](this[t(463)],1),this[t(1212)],this[t(514)])}[r(1154)](t){return t?this[r(1118)+"E"]():this.toBytesBE()}toBytesLE(){let t=r,n=this.high,o=this[t(463)];return[e[t(1445)](255,o),e[t(1374)](e[t(1919)](o,8),255),e.vIROr(o,16)&255,o>>>24,e[t(650)](255,n),e[t(1007)](e[t(1342)](n,8),255),e[t(581)](e[t(1353)](n,16),255),e[t(969)](n,24)]}[r(1777)+"E"](){let t=r,n=this[t(1212)],o=this[t(463)];return[e[t(875)](n,24),e[t(443)](e.OSAJQ(n,16),255),e[t(1510)](n,8)&255,255&n,e[t(1238)](o,24),e[t(1030)](o,16)&255,e[t(1465)](o,8)&255,e[t(2032)](255,o)]}}let Cs=new q(0,0,!1),Oa=new q(0,0,!0),za=q[r(705)](-1,2147483647,!1),qa=q[r(705)](-1,-1,!0),Fa=q[r(705)](0,-2147483648,!1);var je=(function(s){let t=r,n=e[t(1205)][t(1821)]("|"),o=0;for(;;){switch(n[o++]){case"0":s[s[e[t(895)]]=5001]=t(1340)+t(1729);continue;case"1":s[s[e[t(726)]]=5005]=e[t(726)];continue;case"2":s[s[e[t(482)]]=5003]=t(629)+t(907)+"R";continue;case"3":s[s[e[t(724)]]=5002]="CONNECTI"+t(470);continue;case"4":return s;case"5":s[s[e[t(1764)]]=5004]=e[t(1764)];continue}break}})({});class ut{constructor(t){let n=r;this[n(1265)]=t,this[n(815)]=null}}class Es extends ut{constructor(t,n){let o=r;if(e[o(527)]!==e[o(1602)])super(t),this.message=n&&n[o(1905)]||null;else{let x=_0x1f5b71.substring(0,4-_0x43dade[_0x4d20fc][o(805)]),l=x.concat(_0x5ef7c0[_0x45209a]);_0x529d9c[o(577)](l)}}}class As extends ut{constructor(t,n){let o=r,x=(o(722)+"4|5|6").split("|"),l=0;for(;;){switch(x[l++]){case"0":this[o(1446)]=n&&n.colno||0;continue;case"1":this[o(1063)]=n&&n[o(1063)]||null;continue;case"2":super(t);continue;case"3":this[o(1420)]=n&&n[o(1420)]||"";continue;case"4":this.lineno=n&&n[o(1138)]||0;continue;case"5":this[o(1905)]=n&&n[o(1905)]||"";continue;case"6":this[o(1123)]=n&&n[o(1123)]||5001;continue}break}}}class ks extends ut{constructor(t,n){let o=r,x=(o(706)+"2")[o(1821)]("|"),l=0;for(;;){switch(x[l++]){case"0":super(t);continue;case"1":this[o(600)]=n&&n.wasClean||!1;continue;case"2":this[o(1034)+o(1687)]=n&&n[o(1034)+o(1687)]||!1;continue;case"3":this[o(1123)]=n&&n[o(1123)]||0;continue;case"4":this[o(923)]=n&&n[o(923)]||"";continue}break}}}class Is extends ut{constructor(t,n){let o=r;super(t),this[o(1798)]=n&&n[o(1798)]||null}}class Ps extends Is{constructor(t,n){let o=r;super(t),this[o(1798)]=n&&n.data||null,this[o(1905)]=n&&n.message||null}}class Ds extends ut{constructor(t,n){let o=r;super(t),this[o(1798)]=n&&n.data||null}}function pe(s,{message:t,code:n,error:o}){return new As(s,{message:t,code:n,error:o})}function ye(s,{code:t,reason:n,wasClean:o,willReconnect:x}){let l=r;return e[l(825)](e.VoQQP,e.ecUZu)?_0x242b81?this[l(1118)+"E"]():this[l(1777)+"E"]():new ks(s,{code:t,reason:n,wasClean:o,willReconnect:x})}function Ts(s,{data:t,message:n}){return new Ps(s,{data:t,message:n})}function Ns(s,{data:t}){return new Ds(s,{data:t})}function gr(s,{message:t}){let n=r;return e[n(1423)](e.YmGMk,e[n(1716)])?new Es(s,{message:t}):Ngmsny[n(782)](_0x5415ee,_0x5cbe65)&&(Ngmsny.sdYKm(_0x363b97,Ngmsny[n(1215)])||_0xe31fda===Ngmsny[n(1230)])?!0:Ngmsny[n(1803)](_0x462b3c,_0x17e517)}class Ls{constructor(t,n){let o=r;this[o(1779)+"s"]=t,this[o(1520)+"es"]=n,this[o(2001)+o(1495)]=0,this[o(1301)+o(859)+o(1429)+"t"]=0}[r(535)+r(1868)+r(741)](){let t=r;e[t(1719)](e.RLYOh,e[t(613)])?(this[t(2001)+"ndex"]=0,this[t(1301)+t(859)+t(1429)+"t"]=0):_0x5c6a9f[t(771)+t(1244)]("upgradeneeded",n=>{let o=t;_0x263f42(_0x2797ae(_0x515e17[o(573)]),n.oldVersion,n[o(932)+"on"],_0xe5f000(_0x35032c[o(967)+o(1180)]))})}resetTries(){let t=r;this[t(1301)+t(859)+t(1429)+"t"]=0}["getCurre"+r(990)+"nt"](){let t=r;return this[t(1779)+"s"][this[t(2001)+t(1495)]]}[r(1025)+r(990)+r(1544)+r(1271)](){let t=r;return this["currentE"+t(859)+t(1429)+"t"]}["checkRea"+r(1134)+"es"](){let t=r;return e.YvpET!==e[t(516)]?!!(this[t(2001)+t(1495)]>=this[t(1779)+"s"][t(805)]||e.eNNKp(this[t(2001)+"ndex"],e.Uwjnv(this[t(1779)+"s"][t(805)],1))&&e[t(1759)](this[t(1301)+t(859)+"riesCount"],this[t(1520)+"es"])):this[t(1133)]?.del(_0x2a8f8c)}[r(524)+r(602)+r(911)+r(662)+"tries"](){let t=r;return e[t(508)](this[t(2001)+"ndex"],this[t(1779)+"s"][t(805)])?!0:e[t(786)](this[t(1301)+"ndpointT"+t(1429)+"t"],this[t(1520)+"es"])}[r(1124)+"ackupEnd"+r(972)+r(485)+r(1703)](){let t=r;return this[t(1301)+t(859)+t(1429)+"t"]=1,this[t(2001)+t(1495)]++,this[t(1779)+"s"][this["currentI"+t(1495)]]}[r(1025)+r(990)+"ntAndUpd"+r(754)](){let t=r;return this[t(1301)+t(859)+"riesCount"]++,this.getCurrentEndpoint()}}let ft=(e.BBSTC(e.lFxKo,typeof globalThis)&&e.ButpD(e[r(1891)],globalThis[r(1967)+r(817)].name)||typeof window<"u"&&e[r(615)](e.ARDNC,window[r(1967)+r(817)][r(1693)]))&&e[r(1316)](e[r(1614)],typeof document),et=e.PPPCW(r(1874)+"d",typeof globalThis)&&(e[r(1431)](e[r(1660)],globalThis[r(1967)+"tor"][r(1693)])||e[r(637)]("Dedicate"+r(1405)+r(1767)+"pe",globalThis[r(1967)+"tor"][r(1693)]))&&e.lFxKo!=typeof tt,Rt=(e[r(1859)](e[r(1614)],typeof globalThis)&&e[r(1660)]===globalThis[r(1967)+r(817)][r(1693)]||e[r(1542)](e.lFxKo,typeof globalThis)||e[r(802)](e[r(1614)],typeof globalThis)&&!!globalThis[r(1481)+r(753)])&&e[r(802)](e[r(1614)],typeof wx),Bt=e.EHHcm(e.lFxKo,typeof globalThis)&&(e[r(1120)](e[r(1489)],globalThis[r(1967)+r(817)][r(1693)])||e[r(1065)](e[r(789)],globalThis[r(1967)+r(817)][r(1693)])||e[r(798)](e[r(1099)],globalThis["construc"+r(817)][r(1693)]))&&e[r(970)](e[r(1614)],typeof self),Ua=e[r(933)](e[r(1614)],typeof globalThis)&&e[r(1392)](e[r(1660)],globalThis["construc"+r(817)][r(1693)])&&r(1874)+"d"!=typeof global&&e.lfVaI(e[r(1660)],global[r(1967)+r(817)].name)&&e[r(970)](r(1874)+"d",typeof process)&&!!process[r(1108)];class pr{constructor(){let t=r;this[t(979)+"rs"]={}}emit(t,...n){let o=r,x={oXRut:function(l,g,p){return e[I(878)](l,g,p)},oVBeI:e.Uxmll,TfrFE:function(l,g,p){return e[I(1971)](l,g,p)},HnNmT:e[o(1314)],EYKvf:e.LQoih};if(e[o(784)]===e[o(953)]){if(this[o(931)+o(1952)](),this[o(1491)+o(987)](),this._removeWsListeners(),this[o(1275)+"nceClose"](1e3,_0x17e434),this._connectLock=!1,_0x1735f8&&this["_navigat"+o(1727)]()&&!this[o(1867)+o(1449)]){if(this["_endpoin"+o(966)]?.[o(1615)+o(1134)+"es"]()){let g=this[o(672)+o(966)]?.[o(1025)+o(990)+"nt"]();this["_dispatc"+o(592)+o(756)](x[o(472)](_0x1fede1,x.oVBeI,{code:1006,reason:"connect "+g+(o(1610)+o(1567)+o(971)+o(1556)),wasClean:!0}))}else{let g=this[o(1135)][o(1126)+"tInterce"+o(1621)](_0x10b174,_0x51115f);this[o(1214)+o(592)+o(756)](x[o(472)](_0x1c4c43,x[o(698)],{code:_0x4abee5,reason:_0x8d76f2,wasClean:!0,willReconnect:g})),g&&this[o(1418)]()}return}this["_navigat"+o(1727)]()||this[o(1867)+o(1449)]?this[o(1214)+o(592)+"ent"](x[o(941)](_0x341e29,x[o(698)],{code:_0x39524b,reason:x[o(1565)]})):this[o(1214)+o(592)+o(756)](x.oXRut(_0x194a1c,x[o(698)],{code:1006,reason:x[o(622)]})),this._ws=null,this[o(672)+o(966)]?.[o(535)+o(1868)+o(741)](),this[o(902)+o(1739)]?.[o(1136)+o(946)]()}else{let l=this[o(979)+"rs"][t];if(l)l[o(633)]()[o(950)](g=>g.fn[o(1440)](g.ctx,n));else if(e[o(1723)]("error",t)&&!this[o(1248)]){let g=n[o(805)]&&n[0];if(e[o(1320)](g,Error))throw g;let p=new Error(e[o(1820)](e[o(596)],g?e[o(1511)](" ("+g[o(1905)],")"):""));throw p.context=g,g}return this}}[r(486)](t,n){let o=r;if(e[o(905)](void 0,t))this[o(979)+"rs"]={};else if(e[o(798)](void 0,n))this[o(979)+"rs"][t]=null;else{let x=this._listeners[t];if(x)for(let l=0;e[o(1013)](l,x[o(805)]);)x[l].fn===n?x[o(1101)](l,1):++l}return this}on(t,n,o){let x=r;return(this[x(979)+"rs"][t]||(this[x(979)+"rs"][t]=[]))[x(577)]({fn:n,ctx:o||this}),this}}class Ka extends pr{[r(1299)+"rrorMess"+r(1037)](t){let n=r;return t.errMsg||t.errNo?(n(1877)+" "+(t[n(720)]||"")+n(1917)+(t.errNo||""))[n(703)]():JSON.stringify(t)}constructor(t,n,o){let x=r;super(),this[x(1809)]=null,Rt&&wx[x(1827)+x(1157)]&&(this._socket=wx["connectS"+x(1157)]({url:t,protocols:n,header:o,fail:this[x(1506)+"ocketFailHandler"][x(459)](this),success:this[x(1506)+"ocketSuc"+x(1720)+x(476)][x(459)](this)})),et&&tt[x(1827)+x(1157)]&&(this[x(1809)]=tt[x(1827)+x(1157)]({url:t,protocols:n,header:o,fail:this["_createS"+x(483)+x(1842)][x(459)](this),success:this["_createSocketSuc"+x(1720)+x(476)][x(459)](this)}))}["_createS"+r(660)+r(1720)+r(476)](){let t=r;if(e.Lpeuy===e.bgIyf)for(var n in _0x10012f)_0x365773.o(_0x159806,n)&&!_0x4b6a73.o(_0x1b0530,n)&&_0x49aeb8[t(1383)+t(1417)](_0x544b65,n,{enumerable:!0,get:_0x4b2079[n]});else Promise[t(1665)]()[t(1128)](()=>{let o=t;this[o(651)+o(1304)]()})}["_createS"+r(483)+"lHandler"](t){let n=r,o={anVRv:function(x,l){return x+l},GIuVS:e[n(1283)],HDySM:n(1459),DJxpx:function(x,l,g){return x(l,g)},AAuMW:function(x,l,g){return e[n(507)](x,l,g)},eqrHi:e.Uxmll};if(e.SftdJ(e.AfhOp,n(1233)))Promise.resolve()[n(1128)](()=>{let x=n,l={pLCkP:o[x(498)]};if(o[x(1054)]===x(1459)){let g=o.DJxpx(pe,x(1063),{message:this["_formatE"+x(1959)+x(1037)](t)});this[x(1691)](o[x(498)],g);let p=o[x(768)](ye,o[x(865)],{reason:this["_formatE"+x(1959)+"age"](t)});this[x(1691)](o[x(865)],p)}else{let g=_0x4848c4[x(603)].slice(_0x5ac8fb[x(555)+"et"],o[x(1328)](_0x2c4275[x(1125)+"th"],_0x1888b5[x(555)+"et"]));this[x(1809)]&&this[x(1809)][x(774)]({data:g,fail:p=>{let d=x;this[d(1691)](d(1063),_0x242175(l.pLCkP,{message:this["_formatE"+d(1959)+d(1037)](p)}))}})}});else return(this[n(979)+"rs"][_0x5bd3e0]||(this[n(979)+"rs"][_0x4472a5]=[]))[n(577)]({fn:_0x233325,ctx:_0x3f460b||this}),this}[r(651)+r(1304)](){let t=r;this._socket[t(1477)](n=>{let o=t;this[o(1691)](o(791),e[o(1548)](Ns,e[o(1981)],{...n,data:n.errMsg||""}))}),this[t(1809)][t(897)](n=>{let o=t;this[o(1691)](o(760),e[o(1356)](ye,e[o(636)],{...n}))}),this[t(1809)][t(1601)+"e"](n=>{this[t(1691)]("message",Ts("message",{...n}))}),this._socket[t(813)](n=>{let o=t;this[o(1691)](e.LhGNs,e[o(1850)](pe,o(1063),{...n,message:n[o(720)]||""}))})}[r(774)](t){let n=r,o={QZglk:function(x,l,g,p){return x(l,g,p)},Uizjk:e[n(1045)],cbsZz:e.LhGNs,xFXMu:function(x,l,g){return e[n(1971)](x,l,g)}};if(e[n(727)](t,Uint8Array)){let x=t[n(603)][n(633)](t.byteOffset,e[n(1e3)](t[n(1125)+"th"],t[n(555)+"et"]));this[n(1809)]&&this._socket[n(774)]({data:x,fail:l=>{let g=n,p={eFyPR:function(d,w,b,k){return o[I(497)](d,w,b,k)}};if(g(1596)!==o[g(491)])try{p[g(1754)](_0x4581c2,this,_0x3455fc,[_0x621a1f,_0x2f2d91,_0xf68488])}catch(d){let w=_0x546fcf(g(1063),{message:d[g(1905)],code:_0x1eadcd[g(1067)+"OR"],error:d});this[g(1214)+g(1196)+"ent"](w)}else this[g(1691)](o[g(737)],o[g(743)](pe,"error",{message:this[g(1299)+g(1959)+g(1037)](l)}))}})}else this[n(1809)]&&this[n(1809)][n(774)]({data:t,fail:x=>{let l=n;this[l(1691)](o[l(737)],pe(o[l(737)],{message:this[l(1299)+"rrorMessage"](x)}))}})}close(t,n){let o=r,x={JonXh:function(l,g){return e[I(804)](l,g)}};if(e[o(1062)](e[o(2016)],"MTJEn"))return _0x90e731[o(1185)+"t8"]?_0x70ff39[o(1185)+"t8"](_0x29238d,_0x4fd967):_0x17bd9a[_0x34a60b]=255&_0x4e8845,x[o(1705)](_0x47ce2e,1);this[o(1809)]&&this[o(1809)][o(760)]({code:t,reason:n})}[r(771)+r(1244)](t,n){this.on(t,n)}[r(1174)+r(1192)+r(1864)](t,n){this[r(486)](t,n)}get[r(1531)+"te"](){return this[r(1809)].readyState}get[r(1432)+"pe"](){return this[r(1809)].binaryType}set binaryType(t){}get[r(1962)](){let t=r;return e.gCzZt(e[t(673)],e[t(635)])?typeof _0x2b802c===Ngmsny[t(861)]?_0x4cdba8(_0x34b1bd):(Ngmsny[t(782)](_0x5ed5cd,_0xdc012d)&&_0x582ab2(_0x5344a5),_0x425d92(_0xb615f,Ngmsny[t(1590)](_0x574681))?new _0x1a412d(_0x3744dc,_0x221914):_0x406e13):this._socket.url}get[r(1845)](){let t=r;return this._socket[t(1845)]}get[r(1194)+"ns"](){let t=r;return this[t(1809)][t(1194)+"ns"]}get[r(1925)+r(1708)](){return 0}}function Ga(s,t){let n=r;if(t)return new t(s.url,s[n(1845)]);if(e[n(869)](Rt,et))return new Ka(s.url,s[n(1845)],s.headers);if(e[n(1607)](ft,Bt)&&e[n(1316)](e[n(1614)],typeof WebSocket)&&WebSocket)return new WebSocket(s[n(1962)],s.protocols)}function Ha(s){let t=r;return!!(s||Rt&&wx[t(1827)+t(1157)]||et&&tt.connectSocket||(ft||Bt)&&e[t(1614)]!=typeof WebSocket&&WebSocket)}function Rs(s,t,n){let o=r,x=-1;async function l(g){let p=I;return e[p(947)](g,x)?Promise[p(655)](new Error(p(1121)+p(667)+p(2014)+p(2025)+"process")):(x=g,e[p(1431)](g,n[p(805)])?Promise.resolve():n[g][p(459)](s)(t,l.bind(null,e.qbmWc(g,1))))}e[o(648)](l,0)}function Bs(s){let t=r,n=0,o=0;for(let x=0;e[t(618)](x,s[t(805)]);++x)o=s.charCodeAt(x),o<128?n+=1:e.ydtiD(o,2048)?n+=2:e[t(1723)](e.NyxZa(64512,o),55296)&&e[t(905)](e[t(1929)](64512,s[t(1344)+"At"](e[t(1876)](x,1))),56320)?(++x,n+=4):n+=3;return n}function Ms(s,t,n){let o=r;if(e.ZpAEQ(e.OAefp(n,t),1))return"";let x="";for(let l=t;e[o(611)](l,n);){let g=s[l++];if(g<=127)x+=String[o(1140)+"Code"](g);else if(e[o(1298)](g,192)&&e[o(1980)](g,224))x+=String[o(1140)+"Code"](e[o(1217)](e[o(1594)](31,g)<<6,63&s[l++]));else if(e[o(1668)](g,224)&&e[o(1456)](g,240))x+=String[o(1140)+o(732)](e.Ewkze(e.wGaze(15,g),12)|(63&s[l++])<<6|63&s[l++]);else if(e.AbxNv(g,240))if(e[o(1515)](e.yHuAH,e[o(478)])){let p=e[o(465)][o(1821)]("|"),d=0;for(;;){switch(p[d++]){case"0":++_0x3ce983;continue;case"1":_0x5837fd=e[o(1050)](e[o(580)](65536,e[o(1871)](e[o(1968)](1023,_0xc7b3fa),10)),e[o(1574)](1023,_0x3071ab));continue;case"2":_0x3a1960[_0x1e4b52++]=e[o(1689)](63,_0x586cee)|128;continue;case"3":_0xa7359a[_0x16f84f++]=e[o(1178)](e.RsKme(e[o(839)](_0x5cc7d4,12),63),128);continue;case"4":_0x58e023[_0x1077b4++]=e.kJANx(e.UHbIl(_0x43b9df,18),240);continue;case"5":_0x192743[_0x11aaad++]=e[o(1367)](e[o(1252)](_0x30086d,6)&63,128);continue}break}}else{let p=e[o(1358)](e[o(1203)](e[o(1747)](e.IJBel(e[o(712)](e[o(542)](7,g),18),e[o(457)](e[o(670)](63,s[l++]),12)),e[o(1812)](e[o(1758)](63,s[l++]),6)),e[o(1033)](63,s[l++])),65536);x+=String[o(1140)+o(732)](e.QKPdL(55296,e[o(610)](p,10))),x+=String[o(1140)+o(732)](e[o(943)](56320,1023&p))}}return x}function mr(s,t,n){let o=r,x=n,l,g;for(let p=0;p<s[o(805)];++p)if(l=s[o(1344)+"At"](p),e[o(1748)](l,128))t[n++]=l;else if(l<2048)t[n++]=e[o(517)](l>>6,192),t[n++]=e[o(1445)](63,l)|128;else if(e[o(825)](e[o(942)](64512,l),55296)&&e.QLyaQ(e[o(443)](64512,g=s.charCodeAt(e.jOENT(p,1))),56320)){let d=e[o(1900)][o(1821)]("|"),w=0;for(;;){switch(d[w++]){case"0":t[n++]=e[o(1557)](e[o(661)](63,l),128);continue;case"1":t[n++]=e[o(1547)](l>>18,240);continue;case"2":t[n++]=e[o(1656)](e[o(684)](e[o(876)](l,6),63),128);continue;case"3":t[n++]=e.frGfd(e.BBWOw(e[o(997)](l,12),63),128);continue;case"4":++p;continue;case"5":l=e[o(537)](e[o(1876)](65536,e[o(890)](e[o(1810)](1023,l),10)),1023&g);continue}break}}else t[n++]=e[o(793)](e[o(467)](l,12),224),t[n++]=e[o(521)](e.pqPrO(e[o(522)](l,6),63),128),t[n++]=e.sbtbE(e[o(814)](63,l),128);return e[o(523)](n,x)}async function Os(s){let t=r;if(t(1938)==typeof s){let n=new Uint8Array(e[t(1137)](Bs,s));return e[t(736)](mr,s,n,0),n}return e.IgYkJ(s,ArrayBuffer)?new Uint8Array(s):new Uint8Array(s[t(603)],s.byteOffset,s[t(1125)+"th"])}function ja(s){let t=r;try{return e[t(1402)]!=typeof s&&(e.aurHK(s,ArrayBuffer)||s[t(603)]&&e[t(751)](s[t(603)],ArrayBuffer))||e[t(1402)]!=typeof s?"":(JSON[t(1775)](s),e[t(1865)])}catch{return e[t(1542)](t(1938),typeof s)?e[t(511)]:""}}let Wa=(s,t)=>{let n=r;switch(s){case e[n(1151)]:case e[n(1377)]:return{[n(1507)+s]:1,"x-tt-env":t};default:return{}}};class Ja{constructor(t){let n=r;this[n(1926)+"ount"]=t,this[n(1737)]=0}[r(1011)](){let t=r;this[t(1737)]++}["checkRea"+r(1278)+"nt"](){let t=r;return this.count>=this["maxLossC"+t(1271)]}[r(1136)+r(946)](t=0){let n=r;this["maxLossC"+n(1271)]=t,this[n(1737)]=0}}async function Va(s){let t=r,n={GfCwt:e[t(697)],jAQfh:e[t(1222)],SzfXR:function(o,x){return e[t(1895)](o,x)},ZjsSs:e.kuadT,ypEmj:function(o,x){return e[t(883)](o,x)},DeImy:e[t(1647)],ofMGH:e.aBbFR,zcFlq:function(o,x){return e[t(693)](o,x)},hqJmi:e[t(584)],zshNH:function(o,x){return e[t(1062)](o,x)},qGmjU:t(745)};return new Promise(o=>{let x=t,l={xONms:n[x(1260)],baUqB:n.jAQfh,SsqSv:function(g,p){return n[x(1462)](g,p)},ntnBD:n[x(1373)],plZcB:function(g,p){return g(p)},uyWGe:function(g,p){return n[x(780)](g,p)},wObwH:function(g,p){return n[x(780)](g,p)}};if(!ft)return n[x(1462)](o,n[x(1373)]);try{let g=document[x(1978)+x(1235)](n[x(1622)]);window[x(769)+x(1370)]=p=>{let d=x;l[d(1002)]!==l.baUqB?(document[d(1672)][d(1936)+"ild"](g),window[d(769)+d(1370)]=void 0,l.SsqSv(o,p&&p.msg||l.ntnBD)):(this._isInit=!0,this._connect())},g.type="text/jav"+x(880),g[x(1994)]=n[x(780)](s[x(621)](/^ws/,x(1347)),n[x(1619)]);try{document.body[x(455)+x(1041)](g)}catch{if(n[x(870)](n[x(1322)],x(513)))return this[x(951)]?this[x(951)].readyState:this._options.automaticOpen?this[x(1529)+"NG"]:this[x(1637)];document[x(1672)][x(1936)+x(1041)](g)}}catch{if(n[x(1663)](n[x(1009)],n.qGmjU))window[x(769)+"JSONP"]=void 0,n[x(1462)](o,n.ZjsSs);else{let p=""+_0x27ce1a[x(1648)](),d=_0x21b93d||(_0x361eb8=rTkIek[x(1732)](_0x2ae3fd,_0xa7036a)),w=_0x1a5609[x(1184)]().toString(16)[x(633)](-6);return rTkIek[x(725)](rTkIek[x(532)](rTkIek.uyWGe("02",p),d),w)}}})}function We(s,t,n){let o=r;return!!s?.[o(1960)](x=>x[o(1221)]===t&&x[o(1923)]===n)}function dt(s,t){let n=r;if(e[n(1626)](n(811),"YINkz"))return s?.[n(1960)](o=>o[n(1221)]===t)?.[n(1923)];this[n(900)+n(1880)]=_0x965fe3,this[n(951)]&&(this[n(951)][n(1432)+"pe"]=_0x569c12)}let _r=null;async function Xa(){let s=r,t={BHHly:e[s(690)]};if(e[s(934)](e.PaALQ,e[s(623)]))return _r||(_r=Promise[s(1665)]()[s(1128)](Te.bind(Te,e[s(1934)]))),_r;this.emit(jwTTFv[s(920)],_0x2be358(s(1905),{..._0x13a231}))}class Ya extends pr{constructor(t,n){let o=r;super(),this[o(1866)]=t,this[o(1710)]=n,this[o(1133)]=void 0,this[o(1664)+o(1372)]=null}async[r(1457)](){await this._init()}async[r(1454)](){let t=r,n={PxTSd:function(o){return e[I(1590)](o)},Aznug:function(o,x,l,g){return e.PaFVF(o,x,l,g)}};if(e[t(642)]!==t(1388)){if(this[t(1133)])return;if(this[t(1664)+t(1372)])return this[t(1664)+t(1372)];try{let o=this._dbName,x=this[t(1710)];this[t(1664)+t(1372)]=(async()=>{let l=t,{openDB:g}=await n[l(908)](Xa);this._qosDB=await n[l(1044)](g,l(769)+"_"+o,1,{upgrade(p){p["createOb"+l(973)+"e"](o,{keyPath:x})}})})(),await this[t(1664)+t(1372)]}catch(o){console[t(1892)](o)}finally{this[t(1664)+t(1372)]=null}}else _0x5e424b[t(1665)]().then(()=>{this["_addWsLi"+t(1304)]()})}async get(t){let n=r;try{return await this[n(1454)](),this[n(1133)]?.[n(692)](this._dbName,t)}catch(o){if(e.OgHxq(e[n(1930)],n(1227))){let x=_0x22d4d9.bytes,l=_0x468d6c[n(1811)],g=_0x509c97.limit,p=l+_0x347428;if(e.McnAZ(p,x.length)){let d=new _0x378f02(2*p);d[n(1928)](x),_0x52b30f.bytes=d}return _0x24bd7a[n(1811)]=p,e[n(1715)](p,g)&&(_0x11da1f[n(1786)]=p),l}else console[n(1892)](o)}}async[r(1928)](t,n){let o=r;if(e[o(1696)](e[o(1945)],e.aAluk))return await this._init(),this[o(1133)]?.[o(1351)](this._dbName,t);{let x=e[o(1463)](_0x95ca25,_0x1161b7),l=_0x47153b.limit;return _0xfdba45[o(1786)]=e[o(1517)](_0x3bc7ec[o(1811)],x),l}}async[r(1724)](t){let n=r;if(e.pNqBD===e[n(479)])Ngmsny[n(1226)](_0x3be134,_0x161ef9.error),Ngmsny[n(1450)](_0x3e1859);else try{return await this._init(),this[n(1133)]?.[n(450)](this[n(1866)],t)}catch(o){console.log(o)}}async clear(){let t=r;try{return await this._init(),this[t(1133)]?.[t(1843)](this[t(1866)])}catch(n){console[t(1892)](n)}}async keys(){let t=r;if(e[t(1355)](e[t(719)],e[t(452)]))this[t(1133)]?.[t(760)](),this[t(1133)]=void 0;else return await this._init(),this[t(1133)]?.[t(1942)+"ys"](this[t(1866)])}async[r(1254)](){let t=r;return await this[t(1454)](),this._qosDB?.[t(1254)](this[t(1866)])}async[r(1148)](){let t=r;if(e[t(1295)]===e[t(1795)])return this[t(1133)][t(1843)]();try{this._qosDB?.[t(760)](),this[t(1133)]=void 0}catch(n){console[t(1892)](n)}}get[r(1789)](){let t=r;try{return!!this[t(1133)]}catch(n){return console[t(1892)](n),!1}}}class $a{constructor(t,n){let o=r;this[o(1032)]=t,this._pathKey=n,this[o(1133)]=localStorage}async openDB(){}get _prefix(){let t=r;return t(769)+"_"+this[t(1032)]}async get(t){let n=r,o=this[n(1133)].getItem(this[n(1115)]);return JSON.parse(e[n(1263)](o,"{}"))[t]}async set(t,n){let o=r,x=this[o(1133)][o(1094)](this[o(1115)]),l=JSON[o(1775)](e[o(1435)](x,"{}"));return l[n||t[this._pathKey]]=t,this._qosDB[o(891)](this[o(1115)],JSON[o(458)+"y"](l)),n||t[this._pathKey]}async del(t){let n=r,o=this[n(1133)][n(1094)](this[n(1115)]),x=JSON[n(1775)](e.ZSQnL(o,"{}"));return x[t]=void 0,this._qosDB.setItem(this[n(1115)],JSON[n(458)+"y"](x))}async[r(1843)](){let t=r;return e[t(1879)](t(441),e.rNSXk)?this[t(1133)].clear():(_0x36421d|=0,{low:_0x42ef82,high:e[t(854)](_0x368205,31),unsigned:e[t(1863)](_0x3dba83,0)})}async[r(1525)](){let t=r,n=this[t(1133)].getItem(this[t(1115)]),o=JSON.parse(e[t(842)](n,"{}"));return Object[t(1525)](o)}async[r(1254)](){let t=r,n=this[t(1133)][t(1094)](this[t(1115)]),o=JSON[t(1775)](n||"{}");return Object[t(1847)](o)}closeDB(){return Promise[r(1665)]()}get[r(1789)](){return!!this[r(1133)]}}class Za{constructor(t,n){let o=r;this[o(1032)]=t,this[o(1755)]=n,this._qosDB=et?tt:Rt?wx:null}async openDB(){}get[r(1115)](){let t=r;return t(769)+"_"+this[t(1032)]}async[r(692)](t){let n=r,o=this[n(1133)].getStorageSync(this[n(1115)]);return JSON[n(1775)](o||"{}")[t]}async[r(1928)](t,n){let o=r,x=this[o(1133)][o(518)+"geSync"](this[o(1115)]),l=JSON[o(1775)](e[o(1263)](x,"{}"));return l[n||t[this[o(1755)]]]=t,this[o(1133)][o(1728)+"geSync"](this._prefix,JSON[o(458)+"y"](l)),n||t[this[o(1755)]]}async del(t){let n=r,o=this._qosDB[n(518)+n(945)](this._prefix),x=JSON.parse(o||"{}");return x[t]=void 0,this[n(1133)]["setStora"+n(945)](this[n(1115)],JSON[n(458)+"y"](x))}async[r(1843)](){let t=r;return this._qosDB[t(529)+"rageSync"]()}async[r(1525)](){let t=r,n=this[t(1133)][t(518)+"geInfoSync"](this[t(1115)]),o=JSON[t(1775)](e.fcBhI(n,"{}"));return Object[t(1525)](o)}async[r(1254)](){let t=r,n=this._qosDB[t(518)+t(1144)+"nc"](this[t(1115)]),o=JSON[t(1775)](e[t(1263)](n,"{}"));return Object[t(1847)](o)}[r(1148)](){return Promise[r(1665)]()}get[r(1789)](){let t=r;if(e[t(589)](e[t(2003)],t(1659))){let n=_0x33ded4[t(1221)];e.ebRhr(void 0,n)&&(_0x3d5c55(_0x11116f,10),e[t(1969)](_0x2497de,_0x5a783a,n));let o=_0x1119fc.value;o!==void 0&&(e.EjPwb(_0x3f8038,_0x208d98,18),e[t(1993)](_0x2d4463,_0x10796c,o))}else return!!this._qosDB}}function zs(s,t){let n=r;if(e[n(869)](et,et))return new Za(s,t);if(e[n(500)](ft,Bt)&&e[n(1198)](e[n(1614)],typeof indexedDB))return new Ya(s,t);if((ft||Bt)&&e[n(933)](e[n(1614)],typeof localStorage))return new $a(s,t);throw new Error(e[n(799)])}class Qa{constructor(){let t=r;this[t(614)+t(1964)+"Id"]=null,this._interval=36e5,this._qosDB=e[t(1141)](zs,"qos",e[t(892)])}async[r(614)+r(1787)](){let t=r;e[t(1204)](clearInterval,this[t(614)+t(1964)+"Id"]),this[t(614)+t(1964)+"Id"]=setInterval(()=>{this["flushExp"+t(1207)]()},this[t(614)+"l"])}async[r(1457)](){let t=r,n={NYfJq:function(o,x){return e[I(1416)](o,x)}};if(e[t(1232)]!==e[t(1669)])await this[t(1133)][t(1457)]().then(()=>{this[t(614)+"lFlush"]()});else return this[t(2001)+t(1495)]==this[t(1779)+"s"][t(805)]?!0:QEWUHx[t(1730)](this[t(1301)+"ndpointT"+t(1429)+"t"],this[t(1520)+"es"])}async[r(1166)+r(1207)](){let t=r;(await this[t(1133)]?.[t(1254)]()||[])[t(750)](({timestamp:x})=>x<Date[t(1648)]()).forEach(x=>{let l=t;this[l(1133)]?.[l(1724)](x[l(1742)+"id"])})}async[r(1724)](t){let n=r;return this[n(1133)]?.[n(1724)](t)}async[r(1928)](t,n){let o=r;return this._qosDB?.[o(1928)]({message_id:t,timestamp:n})}async[r(692)](t){return this[r(1133)]?.get(t)}async[r(1148)](){let t=r;e[t(949)](clearInterval,this[t(614)+t(1964)+"Id"]),await this[t(1133)]?.closeDB()}get[r(1789)](){let t=r;if(e[t(1914)](e.qtvyq,e[t(1763)]))return this._qosDB?.[t(1789)];switch(_0x3e96af){case e[t(1151)]:case e[t(1377)]:return{[t(1507)+_0x390586]:1,"x-tt-env":_0x424aeb};default:return{}}}}function wr(s){let t=r,n={uggHd:function(o,x){return e[I(1749)](o,x)},LGXcH:function(o,x){return e[I(1914)](o,x)},saYaS:e[t(1883)],zErdU:t(1996)+t(1534)+"s",MqdAa:e[t(1444)],EMXXX:function(o,x,l){return o(x,l)},szvAZ:function(o,x){return e[t(1781)](o,x)},gllTp:e.LhGNs};if(e[t(669)]!==t(2026)){let o=!!this[t(1135)][t(1686)+"S"];if(!o)return{enabled:o,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let x=e[t(1289)](We,s.message[t(849)],"x_fronti"+t(1986),"2"),l=x&&e[t(1289)](We,s[t(1905)][t(849)],e[t(1485)],"1"),g=x&&e[t(910)](We,s[t(1905)].headers,e[t(887)],"1"),p=g?e[t(704)](dt,s.message.headers,e[t(1403)])?.[t(1821)](",")[t(750)](Boolean)||[]:[];return{enabled:o,isQoSMessage:x,isQoSAck:l,isAckCleanupMessage:g,ackMsgIds:p}}else{let{pingInterval:o,pingFrequency:x}=this._options;if((n[t(1704)]("hi",_0x59560b[t(1798)])&&n[t(1999)](t(1824),x)||n[t(1999)](n.saYaS,x))&&(this[t(931)+"ngTimer"](),this[t(1691)](n[t(1634)],n[t(820)]),this[t(836)+t(447)+"Id"]=n[t(1391)](_0x41fdb9,this._ping[t(459)](this),o)),n[t(639)]("hi",_0x465800[t(1798)]))return;try{_0x284696(this,_0x432cb8,[_0x3ac586,_0x3bc0a2,_0x360ab1,_0x56ec0d,_0x36cac9,_0x4d8caa])}catch(l){let g=n[t(1391)](_0x57b5ab,n.gllTp,{message:l[t(1905)],code:_0x2992f0[t(502)+t(1286)],error:l});this[t(1214)+t(1196)+t(756)](g)}}}async function qs(){let s=r;return this._QoSManager||(this[s(1258)+s(1856)]=new Qa),this[s(1258)+s(1856)][s(1789)]||await this["_QoSMana"+s(1856)][s(1457)](),this[s(1258)+"ger"]}async function e0(s,t){let n=r;if(e[n(718)](e[n(2013)],e[n(2013)])){let{enableAutoAck:o}=this._options,x=e[n(1740)](We,s[n(1905)].headers,e[n(1911)],"1"),l=e.Ucwyr(We,s[n(1905)][n(849)],e.BMeev,"1"),g=wr[n(1255)](this,s);if(o&&x)if(e[n(1004)](e[n(499)],e[n(499)]))Ngmsny[n(1725)](_0x52fc59,_0x173564(_0x24068f[n(573)])),Ngmsny[n(1590)](_0x21363b);else{let{SeqID:p,LogID:d,service:w,LogIDNew:b,method:k}=s[n(1905)];this[n(1799)]({SeqID:p,LogID:d,LogIDNew:b,service:w,method:k,headers:[{key:e[n(1438)],value:"1"},{key:e[n(833)],value:e[n(1245)](b,"")},{key:e[n(607)],value:"0"}]})}l&&!g.isQoSAck&&this["_dispatc"+n(1086)+n(1473)](s),e.MhwjM(t)}else return!0}async function t0(s,t){let n=r;this[n(593)](e.qjluv,s[n(1905)]),e.kxfrL(t)}async function n0(s,t){let n=r,o=e.DxRcA(ys,await e[n(484)](Os,s[n(1798)]));try{if(o[n(930)]instanceof Uint8Array){let x=this._options[n(823)+n(597)]instanceof Object?{force:!!this[n(1135)][n(823)+n(597)][n(1499)],encoding:this[n(1135)][n(823)+n(597)][n(685)]?this[n(1135)][n(823)+n(597)][n(685)].replace(/\s/g,"")[n(1411)+"ase"]():""}:{force:!1,encoding:this[n(1135)][n(823)+n(597)]?this[n(1135)]["payloadE"+n(597)].replace(/\s/g,"")["toLowerC"+n(896)]():""},l=o["payloadE"+n(597)]?o.payloadEncoding.replace(/\s/g,"")[n(1411)+"ase"]():"",g=e.ZhYfP(this._options["payloadT"+n(1880)],Object)?{force:!!this._options[n(1414)+n(1880)][n(1499)],type:this[n(1135)][n(1414)+"ype"].type?this._options["payloadT"+n(1880)][n(1265)][n(621)](/\s/g,"")["toLowerC"+n(896)]():""}:{force:!1,type:this[n(1135)]["payloadT"+n(1880)]?this[n(1135)][n(1414)+n(1880)][n(621)](/\s/g,"")[n(1411)+n(896)]():""},p=o[n(1414)+n(1880)]?o[n(1414)+n(1880)][n(621)](/\s/g,"")[n(1411)+n(896)]():"",d=g[n(1499)]?g[n(1265)]:p||g[n(1265)],w=x[n(1499)]?x[n(685)]:l||x.encoding,b=["text/pla"+n(867)+n(747),e[n(1865)],e.qrlFr,"string"],k=[n(1848)+"e",n(778)];this[n(1135)][n(1143)+n(866)+n(1307)+"ad"]&&b[n(1916)](d)&&(!w||k[n(1916)](w))?o[n(1427)+n(515)]=e[n(860)](Ms,o[n(930)],0,o[n(930)][n(1125)+"th"]):o[n(1427)+n(515)]=""}else o[n(1427)+n(515)]=""}catch(x){o[n(1427)+n(515)]="",console[n(1892)](x)}s[n(1905)]=o,e[n(466)](t)}function r0(s,t,n){let o={Przmv:function(d,w){return d>w},QbpER:function(d,w){return e.uduQh(d,w)},vDkyC:function(d,w){return e[I(531)](d,w)},woAOY:function(d,w){return e.mcAce(d,w)}},x=n||8192,l=e.PoTrO(x,1),g=null,p=x;return function(d){let w=I;if(d<1||o[w(1442)](d,l))return s(d);o.QbpER(p,d)>x&&(g=s(x),p=0);let b=t[w(1255)](g,p,p+=d);return 7&p&&(p=o[w(1985)](o[w(1035)](7,p),1)),b}}let s0=4294967295;function i0(s,t,n){let o=r;return e[o(1282)](RangeError,e[o(883)](e[o(1921)](o(1366)+o(1171)+o(1734),s)+o(2019)+e[o(553)](t,1),e.yopLn)+n)}function o0(s,t,n){let o=r;if(n>s0)throw new Error(e.cmBHY);let x=3;for(;e[o(773)](x,0);){let l=255&n;e[o(1289)](br,l,s,e[o(1060)](t,x)),n>>>=8,x--}return e[o(740)](t,4)}function a0(s,t){let n=r,o={WFevW:function(x,l){return x|l},YUYYa:function(x,l){return x<<l},RUWiy:function(x,l){return e[I(1968)](x,l)},jZKqo:function(x,l){return x&l},ujlmY:function(x,l){return e[I(1871)](x,l)},EcLMI:function(x,l){return e[I(1338)](x,l)},nKFHU:function(x,l){return e[I(739)](x,l)},nytNA:function(x,l){return e.KLwFa(x,l)}};if(e[n(2005)](n(1273),e[n(794)])){let x=0,l=t,g=e[n(1679)](t,4);for(;e[n(1114)](l,g);)if(e[n(904)](n(1158),n(1158))){let{value:p,offset:d}=yr(s,l);l=d,x=e[n(1284)](e[n(909)](x,8),0),x+=p}else{if(e[n(659)](_0x5d9685,_0xe183e6))throw new _0x5957f2(e[n(1129)]);let p=3;for(;e[n(868)](p,0);){let d=e[n(1758)](255,_0x1792a8);e[n(736)](_0x4dde5e,d,_0x10c872,_0x20e6ba+p),_0xcae2fd>>>=8,p--}return e.DQkJZ(_0x295365,4)}return{value:x,offset:g}}else _0x1d22ca=khXCyG[n(1870)](khXCyG[n(1870)](khXCyG[n(1870)](khXCyG[n(1927)](khXCyG[n(1854)](7,_0x36cfc6),18),khXCyG.YUYYa(khXCyG.jZKqo(63,_0x8b5f25),12)),khXCyG[n(1817)](63&_0x163e06,6)),khXCyG[n(1765)](63,_0x58cdfb)),khXCyG.nKFHU(_0x3d33fe,65536)||_0x509ef7>1114111?_0x3bdf2e+=_0x83b50c:(_0x444826-=65536,_0x4100ab+=_0x1083e9(khXCyG[n(757)](_0x412932>>10,55296),khXCyG.nytNA(khXCyG[n(1765)](1023,_0x52efff),56320)),_0x4314c5+=3)}function c0(s,t,n){let o=r,x=e.ATavo[o(1821)]("|"),l=0;for(;;){switch(x[l++]){case"0":if(t[o(1082)+"e"])return e[o(1679)](t[o(1082)+"e"](s,n),n);continue;case"1":if(!s)return n;continue;case"2":return e[o(531)](e[o(1096)](mr,s,t,n),n);case"3":if(t[o(683)])return t[o(683)](s,n)+n;continue;case"4":if(e[o(739)](s.length,40))return e[o(1267)](mr(s,t,n),n);continue}break}}function x0(s,t){let n=r,o=new q(e[n(1576)](e[n(901)](e[n(1812)](s[e.QKPdL(t,4)],24),e[n(445)](s[e[n(767)](t,5)],16))|e.tvJUD(s[t+6],8),s[e[n(1587)](t,7)]),e[n(1152)](e.rOoVd(e[n(1083)](s[e[n(462)](t,0)]<<24,e[n(1433)](s[t+1],16)),e[n(928)](s[e[n(567)](t,2)],8)),s[e.EOhgE(t,3)]),!0);return t+=8,{value:o,offset:e[n(856)](t,8)}}function u0(s,t,n){let o=r;if(e[o(1428)](e[o(681)],e[o(1801)])){let x=s[o(463)],l=s[o(1212)];return t[n]=l>>>24,t[e[o(1683)](n,1)]=e[o(565)](e[o(494)](l,16),255),t[e[o(927)](n,2)]=e[o(601)](l>>>8,255),t[e.mhEPM(n,3)]=e[o(563)](255,l),t[e[o(580)](n,4)]=e[o(1053)](x,24),t[n+5]=e[o(1224)](x,16)&255,t[e[o(462)](n,6)]=e[o(1202)](e[o(1386)](x,8),255),t[n+7]=255&x,n+=8,n}else _0x2e943a+=e[o(1947)](_0xc07568,_0x26982d),_0x2476e9+=2}function yr(s,t){let n=r;return s[n(1127)+"8"]?{value:s[n(1127)+"8"](t),offset:e.PBMrh(t,1)}:{value:e.rvfcb(255,s[t]),offset:e[n(746)](t,1)}}function br(s,t,n){let o=r;return t.writeUint8?t[o(1185)+"t8"](s,n):t[n]=255&s,e[o(1876)](n,1)}let f0=function(s){return new Uint8Array(s)},d0=typeof Buffer<"u"?Buffer[r(1970)+r(882)]:e[r(847)](r0,f0,Uint8Array.prototype.subarray);(()=>{let s=r,t={Juhdi:function(o,x){return e.IqsLg(o,x)},zZYGx:function(o,x){return e[I(1542)](o,x)},efEaJ:e[s(1402)],jiUKU:e[s(1535)]},n=4294967295;return function(o,x,l=!0){let g=s;if(e[g(1355)](e[g(1662)],"efZwW")){let{url:p}=t.Juhdi(_0xceed86,{}),d=_0x1f6fbc[g(710)](p)?p:t[g(1472)](t[g(1998)],typeof p)?[p]:[];_0x333b3c&&_0x3a6d66[g(893)](this[g(1135)],_0x599cad),d&&d[g(805)]?this[g(672)+g(966)]=new _0x2bc374(d,this[g(1135)][g(1520)+"es"]):this[g(672)+g(966)]?.[g(535)+g(1868)+g(741)](),this._pingLossCounter?.[g(1136)+g(946)](this[g(1135)]["pingLoss"+g(643)]),this[g(1867)+"osed"]=!1,this[g(951)]&&this[g(951)][g(1531)+"te"]!==this[g(1637)]?this["_disconn"+g(599)](1e3,t[g(1761)],!0):(this[g(988)]=!0,this._connect())}else{let p=e[g(1688)].split("|"),d=0;for(;;){switch(p[d++]){case"0":n=(127&o[x])>>>0;continue;case"1":if(e[g(1885)](o[x++],128))return{value:l?n:0|n,offset:x};continue;case"2":if(e[g(1807)](x+=5,o.length))throw x=o[g(805)],e[g(913)](i0,x,10,o[g(805)]);continue;case"3":if(e[g(1791)](o[x++],128))return{value:l?n:0|n,offset:x};continue;case"4":n=e.BFJap(e[g(1334)](n,e[g(1408)](e[g(565)](127,o[x]),21)),0);continue;case"5":if(e.XFmqp(o[x++],128))return{value:l?n:e[g(1334)](0,n),offset:x};continue;case"6":n=e[g(1878)](n|e.JqYbS(15&o[x],28),0);continue;case"7":if(e[g(1748)](o[x++],128))return{value:l?n:e[g(901)](0,n),offset:x};continue;case"8":n=e[g(877)](e[g(1083)](n,(127&o[x])<<14),0);continue;case"9":if(e[g(1013)](o[x++],128))return{value:l?n:e[g(901)](0,n),offset:x};continue;case"10":n=e.ZPqmn(n,e[g(1912)](127&o[x],7))>>>0;continue;case"11":return{value:l?n:0|n,offset:x}}break}}}})();let l0=16,vr=32;function h0(s){let t=r,n=0,o={};for(let x=0;e[t(1751)](x,s[t(805)]);x++)o[s[x][t(1882)+t(477)]]=e.zzTdq(Bs,s[x][t(1882)+t(477)]),n+=e[t(505)](14,o[s[x][t(1882)+t(477)]]);return[n,o]}function Fs(s,t,n){let o=r,x={yhFer:o(1349)+"ervice",QQogd:function(w,b,k,T){return e.TxyVK(w,b,k,T)},Oeevf:o(1774),PMABZ:o(1545),WbNSi:function(w,b,k,T){return e[o(1289)](w,b,k,T)},vaPQY:e[o(964)],rUevW:e.KJLXl,FMPez:"curvalue"},[l,g]=h0(s),p=e[o(1156)](d0,l),d=0;return s[o(950)](w=>{let b=o;console[b(1892)](x[b(1505)],w,w[b(1545)]),d=x[b(560)](br,0,p,d),console.log(x[b(1830)],d),d=x[b(560)](o0,p,d,w[b(1545)]||0),console.log(x.PMABZ,d),d=x[b(1508)](br,g[w[b(1882)+b(477)]],p,d),console[b(1892)](x.vaPQY,d),d=x[b(560)](c0,w.cursor_name,p,d),console[b(1892)](x.rUevW,d),d=x[b(560)](u0,q.fromNumber(w.cursor||t),p,d),console[b(1892)](x[b(569)],d)}),{frameType:vr,headers:[{key:o(1629)+o(1292),value:n}],payload:p}}function g0(s){let t=r,n=0,o=[];for(;e[t(680)](n,s[t(1125)+"th"]);){let{offset:x}=yr(s,n);n=x;let l={cursor_name:"",cursor:0,service:0},{value:g,offset:p}=a0(s,n);l.service=g,n=p;let{value:d,offset:w}=e[t(847)](yr,s,n);n=w,l[t(1882)+t(477)]=e[t(910)](Ms,s,n,n+d),n+=d;let{value:b,offset:k}=e[t(1831)](x0,s,n);l[t(1189)]=b[t(1833)](),n=k,o.push(l)}return o}function p0(){let s=r;return{frameType:vr,headers:[{key:s(1629)+s(1292),value:e[s(1816)]}],payload:void 0}}class m0{constructor(t,n,o){let x=r;this[x(1893)+x(1040)]=t,this[x(999)+"ileName"]=n,this["_message"+x(1796)]=o,this[x(1133)]=e[x(1500)](zs,this["_cursorN"+x(1040)],e[x(606)])}async openDB(){let t=r;await this[t(1133)][t(1457)]()}async[r(1899)+"rs"](){let t=r;if(!this[t(1133)][t(1789)])return;let n=this[t(1989)+"Strategy"],o=await this._qosDB[t(1254)]();switch(console[t(1892)](e[t(591)],o),n){case e[t(1321)]:return o&&o.length?Fs(o,0,this[t(999)+t(874)]):void 0;case e.LaNkI:return;case e[t(1051)]:return o&&o[t(805)]?e[t(910)](Fs,o,0,this._cursorFileName):p0()}}async[r(1928)](t,n,o){let x=r;if(e[x(605)]!==e[x(1162)])return console.log(x(1467),t,n,o),this[x(1133)][x(1928)]({cursor_name:t,cursor:n,service:o});this[x(1214)+x(1470)+x(1564)](_0x57ab37),_0x2c39d5[x(1928)](_0x1023f9,_0x208aae,_0x5cdaf1[x(1905)][x(1545)])}async[r(845)+"rs"](t){let n=r,o=e[n(1604)](g0,t);for(let x of o)console.log(e[n(632)],o),await this[n(1133)][n(1928)](x)}async[r(692)](t){let n=r;return(await this[n(1133)][n(692)](t))?.cursor}async[r(1148)](){let t=r;await this[t(1133)][t(1148)]()}[r(837)+r(1561)+"Name"](t){let n=r;this["_cursorF"+n(874)]=t}get isReady(){let t=r,n={wxBqG:function(o,x){return o!=x},rcQbl:t(1938),QkVea:function(o,x){return e[t(1836)](o,x)},WVnrg:function(o,x){return e.PPPCW(o,x)},AqIxS:e.ILWAb};return e[t(1399)]==="BrcuA"?XXXPfo[t(766)](XXXPfo[t(1712)],typeof _0x116412)&&(_0x3b3af3 instanceof _0x2720e2||_0x2a2773[t(603)]&&XXXPfo.QkVea(_0x5180d8.buffer,_0x46f0b5))||XXXPfo[t(1437)](XXXPfo.rcQbl,typeof _0x5aa2fe)?"":(_0x14f990.parse(_0x42dd61),XXXPfo[t(1210)]):this[t(1133)][t(1789)]}}let _0=e.MlsWG;async function Us(s){let t=r;if(!this[t(1135)][t(1686)+"S"])return null;let{aID:n,fpID:o,messageStrategy:x}=this[t(1135)],l=s||_0;try{return this[t(1546)+t(1612)]?s&&this["_cursorM"+t(1612)][t(837)+t(1561)+t(1181)](s):this["_cursorM"+t(1612)]=new m0(o+"_"+n+"_"+l,l,x),this[t(1546)+t(1612)][t(1789)]||await this[t(1546)+t(1612)][t(1457)](),this[t(1546)+t(1612)]}catch{return e[t(1333)](e[t(582)],e.XXuQa)?!!_0x3069b9?.[t(1960)](g=>g[t(1221)]===_0x562be4&&g.value===_0x4c6bd6):null}}async function w0(s,t){let n=r,o=We(s[n(1905)][n(849)],e.BVUWV,"-1"),x=e[n(469)](We,s.message[n(849)],"is_ack","1"),l=dt(s[n(1905)][n(849)],e[n(541)]),g=Number(dt(s[n(1905)][n(849)],e[n(1797)]))||0,p=wr[n(1255)](this,s),d=e[n(528)](We,s[n(1905)][n(849)],e[n(1085)],"2"),w=dt(s[n(1905)].headers,e[n(824)]),b=e.QCyBX(Number,e[n(1831)](dt,s[n(1905)][n(849)],n(935)+n(526)+"ue"));if(p[n(819)])return e[n(575)](t);let k=p[n(2033)+n(1357)]?await qs.call(this):null;if(e[n(1906)](s[n(1905)].service,0)&&x&&!o||e[n(786)](s[n(1905)][n(1545)],0)){if(l&&p["isQoSMes"+n(1357)]&&k)return!!!await k[n(692)](l)&&(this[n(1214)+n(1470)+n(1564)](s),await k[n(1928)](l,e.PBMrh(Date[n(1648)](),g))),e[n(1036)](t);if(d){let T=await Us[n(1255)](this);if(!T)return this[n(1214)+n(1470)+n(1564)](s),e[n(1036)](t);let R=await T[n(692)](w)??-1;if(R<b)e[n(1397)]===e[n(1913)]?(++_0x17fd12,_0x8dc285+=4):(this[n(1214)+n(1470)+n(1564)](s),T.set(w,b,s[n(1905)][n(1545)]));else throw new Error(n(1884)+" message"+n(1318)+b+(n(707)+n(1407)+n(1889)+"r ")+R);return e.kxfrL(t)}return this[n(1214)+n(1470)+n(1564)](s),e[n(2010)](t)}}async function y0(s,t){let n=r,o=wr[n(1255)](this,s);if(!o["isQoSMes"+n(1357)])return e.jVVso(t);let x=await qs[n(1255)](this);if(o[n(1494)+n(1666)+"age"]&&o[n(1588)+"s"][n(805)])for(let l of o[n(1588)+"s"])await x[n(1724)](l);e[n(2010)](t)}async function b0(s,t){let n=r,o=e[n(1503)](s[n(1905)].frameType,l0),x=e[n(960)](s.message[n(1406)+"e"],vr);if(e[n(1487)](!o,!x))return e[n(921)](t);let l=e[n(1022)](dt,s[n(1905)][n(849)],n(1629)+n(1292));if(!l)return t();let g=await Us[n(1255)](this,l);if(!g)return t();if(o){let p=await g[n(1899)+"rs"](),d={frameType:p?.[n(1406)+"e"],SeqID:q.fromNumber(this[n(1199)]++),LogID:q[n(1324)+"er"](this[n(1135)][n(1048)+n(777)]()),service:9e3,method:5,headers:p?.[n(849)],payload:p?.[n(930)]},w=e[n(1851)](S,d);this[n(951)]&&this._ws[n(1531)+"te"]&&this[n(951)][n(774)](w)}if(x){let p=s[n(1905)][n(930)];p&&g[n(845)+"rs"](p)}}let v0=async function(s,t){let n=r;this[n(988)]=!1,e[n(1409)](clearTimeout,this[n(1418)+n(834)+n(1329)]),e[n(1590)](t)},S0=async function(s,t){let n=r;if(!this[n(951)]||e.rBYZt(this._ws[n(1531)+"te"],this[n(687)]))return e[n(1400)](t);let{pingInterval:o}=this[n(1135)];this["_endpoin"+n(966)]?.["resetEnd"+n(1868)+n(741)]();for(let l=0;e[n(1579)](l,this["_message"+n(1825)][n(805)]);l++){let g=this[n(1989)+n(1825)][l];if(e.zGBBE(this[n(951)].readyState,this[n(687)])&&e[n(956)](null,g))if(e[n(446)](e.KJfmw,e[n(1677)]))this._ws&&this[n(951)][n(774)](g),this._messageQueue[l]=null;else{let p=this[n(1133)][n(1094)](this[n(1115)]),d=_0x4803eb.parse(e[n(1435)](p,"{}"));return _0x2c9588.values(d)}else break}this["_message"+n(1825)]=this["_message"+n(1825)][n(750)](l=>!!l),this[n(836)+n(447)+"Id"]=e[n(1586)](setTimeout,()=>this._ping(),o),this[n(1214)+"hOpenEvent"](s),this[n(626)+"er"]&&this[n(951)]&&(this._ws.binaryType=this[n(900)+n(1880)]);let x=this["_endpoin"+n(966)]?.[n(1025)+"ntEndpoint"]();this[n(593)](n(968)+x+n(1020)),e[n(566)](t)},C0=async function(s,t){let n=r,o=this["_endpoin"+n(966)]?.[n(1025)+"ntEndpoint"]();this._debug(n(968)+o),e[n(1778)](t)};class E0 extends pr{constructor(t){let n=r,o={GdtgX:function(x,l){return e[I(1585)](x,l)},JEFGL:e[n(1188)],gqxHJ:function(x,l,g,p){return e[n(528)](x,l,g,p)},ozlnI:function(x,l,g){return e.fRKGw(x,l,g)},Vckdq:e[n(1283)],Aoter:function(x,l,g){return e[n(1695)](x,l,g)},MWpvR:e[n(831)],lgoPl:e[n(1883)],USxQx:n(1996)+n(1534)+"s",nWqMC:function(x,l){return e[n(1750)](x,l)},ufSkm:e[n(1861)],ZbXVa:e.cCXhN,VatTe:function(x,l){return x===l},cWXts:e[n(1600)],jQIuG:function(x,l,g){return e[n(1061)](x,l,g)},zQCjv:function(x,l){return e[n(1106)](x,l)},ZIPuH:function(x,l){return e[n(1750)](x,l)},HEGJC:e[n(1736)],ZLdyh:e[n(636)],zyjkV:function(x,l){return e[n(1719)](x,l)},qkKly:e[n(728)],pPeNl:n(1783),fOAIx:n(1620),IMTkF:function(x,l){return e[n(2017)](x,l)},FABPc:function(x,l){return x(l)},pCoCV:function(x,l,g){return e[n(1231)](x,l,g)}};if(e[n(731)]===e[n(731)]){super(),this[n(1029)+"igatorOnline"]=!0,this[n(626)+"er"]=ft,this[n(520)]=Ua,this[n(1632)+"T"]=et,this[n(1644)+"X"]=Rt,this[n(1655)+"r"]=Bt,this[n(1989)+n(1825)]=[],this[n(672)+n(966)]=null,this[n(1867)+n(1449)]=!1,this["_binaryT"+n(1880)]=n(1480)+n(776),this[n(1418)+n(1149)]=!1,this["_connectionTimeo"+n(1329)]=null,this[n(1653)+n(1887)+"tId"]=null,this[n(836)+n(447)+"Id"]=null,this[n(1199)]=0,this[n(988)]=!1,this[n(790)]="",this[n(1258)+"ger"]=null,this[n(1546)+n(1612)]=null,this[n(902)+n(1739)]=null,this[n(1617)+"ls"]=e[n(1058)],this.CLOSED=3,this[n(1529)+"NG"]=0,this[n(687)]=1,this.CLOSING=2,this[n(1667)]=p=>{let d=n;try{if(o[d(1657)](o[d(1003)],o[d(1003)]))o[d(1049)](Rs,this,p,[v0,S0,C0]);else{let w=this[d(1133)][d(1094)](this[d(1115)]),b=_0x3cb3a4[d(1775)](w||"{}");return _0x1e0149.keys(b)}}catch(w){let b=o[d(1624)](pe,o[d(1940)],{message:w[d(1905)],code:je[d(1067)+"OR"],error:w});this["_dispatchErrorEv"+d(756)](b)}},this[n(1452)+"ge"]=async p=>{let d=n,w={GgSTg:function(T,R,B){return o[I(1944)](T,R,B)}},{pingInterval:b,pingFrequency:k}=this[d(1135)];if((p[d(1798)]==="hi"&&o.GdtgX(o[d(1075)],k)||o.GdtgX(o[d(1055)],k))&&(this[d(931)+d(1952)](),this[d(1691)](o.USxQx,d(554)),this[d(836)+"gTimeoutId"]=setTimeout(this[d(763)][d(459)](this),b)),!o[d(1657)]("hi",p[d(1798)]))try{if(o[d(1443)](o[d(2015)],o[d(1104)]))Rs(this,p,[n0,e0,y0,b0,w0,t0]);else{let T=w[d(1277)](_0x5c1a72,d(1063),{message:_0x11eb70.message,code:_0x2a3fca["MESSAGE_"+d(1286)],error:_0x131da9});this[d(1214)+d(1196)+"ent"](T)}}catch(T){if(o.VatTe(o[d(1680)],"NNFIB")){let R=o[d(1490)](pe,o[d(1940)],{message:T[d(1905)],code:je.MESSAGE_ERROR,error:T});this["_dispatc"+d(1196)+d(756)](R)}else _0x5b4c1d=d(2022),_0x55b7ef=_0x1fe72b[d(621)](/(^http)((?:[s]*:\/\/))/,""),_0x28d304=/(^ws)((?:[s]*:\/\/))/[d(1973)](_0x35e781)?_0x640622:""+_0x440281+_0x261af9}},this[n(536)]=p=>{let d=n,w=this[d(672)+d(966)]?.["checkRea"+d(1134)+"es"](),b=this[d(672)+d(966)]?.[d(1025)+d(990)+"nt"]();if(w&&!p[d(1905)]){let k=d(1853)+b+(d(1918)+d(1698)+d(449)+"ed");this[d(1214)+"hErrorEvent"](e.NjZzC(pe,e.LhGNs,{message:k,code:je[d(629)+"IES_ERROR"],error:p}));return}this._ws&&this[d(951)][d(1531)+"te"]===this[d(687)]&&this[d(634)+"ect"](),this[d(1214)+d(1196)+d(756)](e.kbAqi(pe,e[d(1283)],{message:p[d(1905)],code:je[d(1340)+d(1729)],error:p}))},this[n(656)]=async p=>{let d=n;this._clearTimer(),this["_clearPi"+d(1952)](),this[d(461)+"sListeners"](),this[d(951)]=null,this["_connect"+d(1149)]=!1;let w=this[d(672)+"tManager"]?.[d(1615)+"chMaxTries"]();if(!w&&this[d(1943)+d(1727)]()&&!this[d(1867)+d(1449)]){let b=this[d(672)+"tManager"]?.["getCurre"+d(990)+"nt"](),k=this[d(1135)][d(1126)+d(1173)+"ptor"](p.code,p.reason);this[d(1214)+"hCloseEvent"](o.Aoter(ye,o.ZLdyh,{code:1006,reason:p[d(923)]||"connecti"+d(822)+d(1110)+d(1954)+d(1645)+"ame: "+b,willReconnect:k})),k&&this[d(1418)]();return}if(o[d(982)](1e3,p[d(1123)])&&this[d(1867)+d(1449)])if(o.qkKly===o[d(1384)])this[d(1943)+d(1727)]()&&(!this[d(951)]||o[d(671)](this[d(951)].readyState,this[d(687)])||o[d(1518)](this._ws[d(1531)+"te"],this[d(1529)+"NG"]))&&this[d(2008)+"nLine"](),this[d(626)+"er"]&&_0x251614[d(771)+d(1244)](d(898),this["_handleO"+d(1486)]),this._isBrowser&&_0x3d04c4[d(771)+d(1244)](o[d(1059)],this[d(2008)+d(1509)]);else{this[d(1214)+d(592)+d(756)](o.jQIuG(ye,o[d(936)],{code:1e3,reason:o.fOAIx})),this[d(672)+"tManager"]?.[d(535)+"pointConfig"](),this[d(902)+d(1739)]?.[d(1136)+d(946)]();return}if(o[d(1584)](1e3,p[d(1123)])&&w){let b=this[d(672)+d(966)]?.["getCurre"+d(990)+"nt"](),k=p[d(923)];k||(k=await o[d(489)](Va,this[d(790)])),k=d(1713)+d(822)+"d, "+k+(", hostna"+d(1898))+b+(d(1567)+"tries re"+d(1556)),this["_dispatc"+d(592)+"ent"](o[d(1944)](ye,o[d(936)],{code:p.code,reason:k}));let T=d(1853)+b+(" fail, m"+d(1698)+"es reached");this[d(1214)+"hErrorEv"+d(756)](o[d(1646)](pe,d(1063),{message:T,code:je[d(629)+d(907)+"R"]})),this[d(672)+d(966)]?.["resetEnd"+d(1868)+d(741)](),this[d(902)+d(1739)]?.[d(1136)+"nter"]();return}if(p[d(1123)]!==1e3&&!p[d(923)]){let b=this[d(672)+d(966)]?.["getCurre"+d(990)+"nt"]();this[d(1214)+d(592)+d(756)](o[d(1944)](ye,o[d(936)],{code:p.code,reason:d(1713)+d(822)+"d, unkno"+d(1954)+d(1645)+d(1776)+b})),this._endpointManager?.[d(535)+d(1868)+d(741)](),this["_pingLos"+d(1739)]?.[d(1136)+d(946)]();return}this[d(1214)+d(592)+d(756)](p),this[d(672)+"tManager"]?.[d(535)+d(1868)+d(741)](),this["_pingLos"+d(1739)]?.[d(1136)+d(946)]()},this[n(1290)]=null,this[n(1248)]=null,this.onmessage=null,this.onopen=null,this[n(1568)+"econnect"]=null,this[n(1091)+n(481)]=null,this[n(1206)+n(1819)+"yReconnect"]=null,this[n(2008)+"nLine"]=this[n(2008)+"nLine"][n(459)](this),this[n(2008)+"ffLine"]=this[n(2008)+n(1509)][n(459)](this),this[n(1984)+"ageHide"]=this[n(1984)+n(444)][n(459)](this),this[n(1984)+"ageShow"]=this["_handleP"+n(1818)][n(459)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e.RMRQG(1,0),service:0,logIDGenerator:c,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[n(1883)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.BRYsE,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:x,ws:l}=t,g=Array[n(710)](x)?x:e[n(1090)](e.uiyxx,typeof x)?[x]:[];if(!g||g[n(805)]===0)throw new Error(e[n(889)]);if(!e[n(658)](Ha,l))throw new Error(e.GWXaM);if(Object[n(893)](this[n(1135)],t),this[n(672)+"tManager"]=new Ls(g,this[n(1135)].maxRetries),this[n(902)+n(1739)]=new Ja(this[n(1135)][n(1881)+n(643)]),this[n(1135)][n(1650)+n(925)])if(e[n(830)](e.ZrRfb,e[n(1451)])){let{SeqID:p,LogID:d,service:w,LogIDNew:b,method:k}=_0x748ae6.message;this[n(1799)]({SeqID:p,LogID:d,LogIDNew:b,service:w,method:k,headers:[{key:e[n(1438)],value:"1"},{key:e.Nzkgs,value:e[n(1245)](b,"")},{key:e[n(607)],value:"0"}]})}else this[n(988)]=!0,this[n(1418)]();if(this[n(1135)][n(1046)+"tworkChanged"]){if(e[n(934)](e[n(1325)],e[n(1325)]))return new _0x474ee2(e[n(471)](e[n(764)](e[n(1547)](_0xd5290d[0],e[n(809)](_0xc2477b[1],8)),_0xfe220f[2]<<16),e[n(691)](_0x227aa7[3],24)),e[n(663)](e[n(1111)](_0x56375f[4]|e.vKOTW(_0x506d4d[5],8),e[n(1395)](_0x5144a3[6],16)),e[n(1098)](_0x7db492[7],24)),_0xb15d20);this[n(1632)+"T"]||this[n(1644)+"X"]?this[n(2012)+n(631)+"ange"]():this._isBrowser&&this[n(1858)+n(1555)+n(1244)]()}}else this[n(1691)](n(760),_0x2743d4),this.onclose&&this[n(1290)](_0x3e6d5e)}[r(2008)+r(1486)](){let t=r;this[t(1135)][t(628)+t(496)+"nect"]||this[t(1867)+t(1449)]||this[t(1375)+t(906)]()}[r(2008)+r(1509)](){let t=r;this[t(864)+t(986)+"t"]();let n=e.hiTTS(gr,e[t(677)],{message:e.CCAxf});this[t(1206)+t(1819)+"yReconnect"]&&this[t(1206)+"mediatel"+t(2009)+"ct"](n)}[r(1858)+r(1555)+"Listener"](){let t=r;this._isBrowser&&window[t(771)+t(1244)](e.AKIKl,this["_handleO"+t(1486)]),this[t(626)+"er"]&&window[t(771)+t(1244)](e[t(1736)],this[t(2008)+t(1509)]),this[t(626)+"er"]&&window[t(771)+t(1244)](e[t(1697)],this["_handleP"+t(444)]),this._isBrowser&&window[t(771)+"Listener"](e[t(1323)],this[t(1984)+"ageShow"])}[r(926)+r(1555)+r(1244)](){let t=r;this[t(626)+"er"]&&window[t(1174)+t(1192)+"ner"]("online",this[t(2008)+t(1486)]),this[t(626)+"er"]&&window[t(1174)+t(1192)+"ner"](e.wivBR,this[t(2008)+"ffLine"]),this._isBrowser&&window["removeEv"+t(1192)+t(1864)](e[t(1697)],this["_handleP"+t(444)]),this._isBrowser&&window.removeEventListener(e[t(1323)],this[t(1984)+t(1818)])}["_handleP"+r(444)](t){let n=r;!t.persisted&&(this[n(626)+"er"]&&window.removeEventListener(e[n(1697)],this[n(1984)+"ageHide"]),this[n(626)+"er"]&&window[n(1174)+n(1192)+n(1864)](e[n(1323)],this[n(1984)+n(1818)]),this[n(760)]()),this[n(626)+"er"]&&window["removeEv"+n(1192)+n(1864)](e[n(919)],this[n(2008)+n(1486)]),this[n(626)+"er"]&&window[n(1174)+n(1192)+"ner"](e.wivBR,this["_handleO"+n(1509)])}[r(1984)+r(1818)](t){let n=r;t[n(1628)+"d"]&&(this[n(1943)+n(1727)]()&&(!this[n(951)]||e[n(1512)](this[n(951)].readyState,this[n(687)])||e[n(894)](this[n(951)][n(1531)+"te"],this[n(1529)+"NG"]))&&this[n(2008)+n(1486)](),this._isBrowser&&window[n(771)+n(1244)](e[n(919)],this[n(2008)+n(1486)]),this[n(626)+"er"]&&window["addEvent"+n(1244)](e[n(1736)],this["_handleO"+n(1509)]))}async[r(1875)+r(556)](t){let n=r,{fpID:o,deviceID:x,bddID:l,ttwID:g,accessKey:p,aID:d,customParams:w={},enableAutoAck:b,enableQoS:k,QoSLevel:T,env:R}=this[n(1135)],B,V,se;if(this[n(626)+"er"]||this[n(1644)+"X"]||this._isMiniTT){if(e[n(1951)]===e[n(1537)])return _0x33a5d1[n(1440)](Ngmsny.uYIJh(_0x3850ae,this),_0x5c0303),Ngmsny[n(1293)](_0x1afee6,_0x1ae7ec[n(692)](this));B=location&&e[n(1757)](e[n(1006)],location.protocol)?e[n(1112)]:e[n(1311)],V=t.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),se=/^wss(.*:\/\/)/[n(1973)](t)?t:""+B+V}else B=n(2022),V=t[n(621)](/(^http)((?:[s]*:\/\/))/,""),se=/(^ws)((?:[s]*:\/\/))/[n(1973)](V)?V:""+B+V;let re=l?e.ImUeg:g?n(1288):n(1792)+"d",Ee=l||g||x;if(e[n(829)](!Ee,!re))throw new Error(e[n(1253)]);let lt=e[n(812)](e.TUJzi,typeof w)?await e.AbLmQ(w):w,ce=R?Wa(R.xUseEnv,R[n(1132)]):{},ht=Object[n(893)]({device_platform:e[n(1953)],version_code:n(810)+"0",access_key:p,fpid:o,aid:d,[re]:Ee,xsack:b?1:0,xaack:b?1:0,xsqos:k?1:0,qos_level:k?T:void 0,qos_sdk_version:2,...ce},lt),Mt=Object.keys(ht)[n(1066)]((nt,te)=>ht[te]!==void 0?""+nt+(nt?"&":"?")+te+"="+ht[te]:nt,"");return se+n(1352)+Mt}async _connect(){let t=r;if(!(this[t(1418)+t(1149)]||this[t(1867)+t(1449)])){this["_connect"+t(1149)]=!0;try{let n=this["_endpoin"+t(966)]?.[t(524)+t(602)+t(911)+t(662)+t(1250)](),{timeoutInterval:o}=this[t(1135)];if(n){let l=this[t(672)+t(966)]?.[t(1025)+"ntEndpoint"](),g=this[t(672)+t(966)]?.[t(1124)+t(1229)+t(972)+"UpdateCo"+t(1703)](),p=this[t(672)+"tManager"]?.[t(1025)+t(990)+t(1544)+t(1271)]();if(g){let d=t(1853)+l+(t(1610)+", max re"+t(971)+t(644)+t(453)+"backup e"+t(1790))+g+(t(1390)+"y"),w=e[t(1141)](pe,e[t(1283)],{message:d,code:je[t(629)+t(907)+"R"]});this._debug(d),this[t(1214)+"hErrorEv"+t(756)](w),this[t(790)]=await this[t(1875)+t(556)](g),this[t(593)]("connect "+g+" "+p+t(675)),this[t(461)+t(1834)+"rs"]()}else{let d="connect "+l+(t(1610)+t(1567)+t(971)+t(1556));this[t(593)](d),this[t(1214)+t(1196)+"ent"](e[t(1548)](pe,e.LhGNs,{message:d,code:je[t(629)+t(907)+"R"]}));return}}else if(e[t(1211)](e[t(1597)],e.CANkd))this[t(1029)+t(1303)+t(1396)]=_0x1b75c3,_0x3796e1?this[t(2008)+t(1486)]():this[t(2008)+t(1509)]();else{let l=this["_endpoin"+t(966)]?.[t(1025)+t(990)+t(695)+t(754)](),g=this[t(672)+t(966)]?.[t(1025)+t(990)+"ntTriesC"+t(1271)]();this[t(790)]=await this[t(1875)+t(556)](e.PXQzk(l,"")),this[t(593)](t(1853)+l+" "+g+" times"),this._removeWsListeners()}if(this[t(988)])this[t(988)]=!1;else{let l=e[t(665)](gr,e.nCckg,{message:"start"});this["onStartR"+t(906)]&&this[t(1568)+t(906)](l)}let x=this[t(672)+t(966)]?.[t(1025)+t(990)+t(1544)+t(1271)]()||0;e[t(1416)](x,1)&&await this[t(1652)](e.Uwjnv(x,1)),this[t(593)]("connecti"+t(1089)+this[t(790)]+(t(549)+t(1379))+this._protocols),this[t(951)]=e[t(1141)](Ga,{url:this[t(790)],protocols:[this[t(1617)+"ls"]],headers:this[t(1135)][t(1541)+t(1164)+"s"][t(1249)+"tpHeader"]},this[t(1135)].ws),(this[t(626)+"er"]||this[t(1655)+"r"])&&this._ws&&(this[t(951)][t(1432)+"pe"]=this[t(900)+"ype"]),this[t(651)+t(1304)](),this[t(1418)+t(834)+"utId"]=e[t(1021)](setTimeout,this[t(1533)+"ut"].bind(this),o)}catch(n){throw this[t(1418)+t(1149)]=!1,n}}}["_clearTi"+r(987)](){let t=r;e[t(924)](clearTimeout,this["_connect"+t(834)+"utId"]),this["_connect"+t(834)+t(1329)]=null}[r(931)+r(1952)](){let t=r;e[t(1949)](clearTimeout,this[t(836)+t(447)+"Id"]),e.HoGaq(clearTimeout,this[t(1653)+t(1887)+t(1839)]),this[t(836)+t(447)+"Id"]=null,this[t(1653)+t(1887)+t(1839)]=null}_debug(...t){let n=r;e.cMura(e.PatEG,e.PatEG)?(e[n(1977)](_0x1f3f96,_0x572028,50),e[n(847)](_0x20a81f,_0x27e1b1,_0x1190a9)):this[n(1135)][n(464)]&&console[n(1892)][n(1440)](console,[n(1208)+">",...t])}[r(1519)+r(1997)+"e"](t){let n=r;if(e.ZtkAD(e[n(473)],e[n(473)]))return _0x3d73eb+=_0x429f51&&_0x24cdab[n(1125)+"th"]||0,_0x3cad61;{let{initReconnectInterval:o,maxReconnectInterval:x,reconnectIntervalGrowFactor:l}=this[n(1135)],g=e[n(574)](o,Math[n(627)](l,e[n(523)](t,1)));return g>x?x:g}}[r(763)](){let t=r;if(this[t(951)]&&e[t(701)](this[t(951)].readyState,this[t(1529)+"NG"])){this[t(931)+t(1952)](),this[t(836)+t(447)+"Id"]=e[t(715)](setTimeout,this[t(763)][t(459)](this),this._options[t(1961)+t(579)]);return}if(!this[t(951)]||e[t(1211)](this[t(951)].readyState,this[t(687)]))return void this[t(1375)+t(906)]();this[t(951)]&&this[t(951)][t(774)]("hi"),this["_reconnectTimeou"+t(1839)]=setTimeout(this[t(1375)+t(906)+t(808)][t(459)](this),this._options[t(991)+t(1130)+"val"])}[r(1375)+r(906)+"Timeout"](){let t=r;this._pingLossCounter?.addCount(),this[t(1691)](e[t(1872)],e.HwVau),this["_pingLos"+t(1739)]?.[t(1615)+"chMaxCount"]()?this[t(1375)+t(906)]():this[t(763)]()}[r(1943)+r(1727)](){let t=r;return this[t(1632)+"T"]||this[t(1644)+"X"]?this[t(1029)+t(1303)+t(1396)]:(this[t(626)+"er"]||this[t(1655)+"r"])&&this._options[t(1046)+t(1348)+t(1483)]?navigator[t(1823)]:!0}["_handleR"+r(906)](){let t=r;!this[t(1943)+t(1727)]()||this["_readyCl"+t(1449)]||(this[t(672)+t(966)]?.[t(535)+"pointCon"+t(741)](),this["_pingLos"+t(1739)]?.[t(1136)+t(946)](),this[t(951)]?this[t(634)+t(599)](1001,e[t(1296)],!0):this[t(1418)]())}[r(2012)+r(631)+r(806)](){let t=r,n={ZSUrv:function(o,x){return e[I(488)](o,x)},iyZZp:function(o,x){return e.tZhIU(o,x)}};this[t(1632)+"T"]?tt[t(1371)+"kStatusC"+t(608)](({isConnected:o})=>{let x=t;if(n[x(952)]("VujcL","VujcL")){let l={LWzKq:function(g,p){return OLHDYy.ZSUrv(g,p)}};return function(g,...p){let d=x,w=_0x4d27bb[d(1255)](l[d(664)](_0x5bbb5d,this),g,...p);return _0x1109f4[d(1928)](w,g.sort?g[d(850)]():[g]),l[d(664)](_0x32f367,w)}}else this["_miniNav"+x(1303)+x(1396)]=o,o?this["_handleO"+x(1486)]():this._handleOffLine()}):this[t(1644)+"X"]&&wx[t(1371)+t(1618)+"hange"](({isConnected:o})=>{let x=t;this[x(1029)+"igatorOn"+x(1396)]=o,o?this[x(2008)+"nLine"]():this["_handleO"+x(1509)]()})}[r(1652)](t){return new Promise(n=>{let o=I;e.kbAqi(setTimeout,n,this[o(1519)+o(1997)+"e"](t))})}[r(634)+"ect"](t=1e3,n="",o=!1){let x=r;this._ws&&this[x(864)+x(986)+"t"](t,n,o)}[r(1533)+"ut"](){let t=r,n=this[t(672)+t(966)]?.["getCurre"+t(990)+"nt"]();this[t(593)](t(1853)+n+t(1610)),this[t(634)+t(599)](1001,e[t(730)],!0)}[r(1799)](t){let n=r,o=e[n(1725)](hr,t);this[n(951)]&&e.JHXmJ(this[n(951)][n(1531)+"te"],this.OPEN)&&(this[n(951)]&&this[n(951)][n(774)](o),this[n(593)](e[n(1575)],t))}["_removeW"+r(1834)+"rs"](){let t=r,n=e[t(654)][t(1821)]("|"),o=0;for(;;){switch(n[o++]){case"0":this[t(951)]["removeEv"+t(1192)+t(1864)](e[t(690)],this._onMessage);continue;case"1":this[t(951)][t(1174)+"entListener"](e[t(636)],this._onClose);continue;case"2":if(!this._ws)return;continue;case"3":this._ws[t(1174)+t(1192)+t(1864)](e[t(1283)],this[t(536)]);continue;case"4":this._ws[t(1174)+t(1192)+t(1864)](e[t(1981)],this[t(1667)]);continue}break}}[r(651)+r(1304)](){let t=r,n=e[t(775)][t(1821)]("|"),o=0;for(;;){switch(n[o++]){case"0":this[t(951)][t(771)+t(1244)](e[t(636)],this._onClose);continue;case"1":this[t(951)][t(771)+t(1244)](e[t(690)],this[t(1452)+"ge"]);continue;case"2":if(!this[t(951)])return;continue;case"3":this._ws[t(771)+t(1244)](t(791),this[t(1667)]);continue;case"4":this[t(951)][t(771)+t(1244)](t(1063),this[t(536)]);continue}break}}[r(1275)+r(1285)](t=1e3,n=""){let o=r;try{this._ws&&this[o(951)][o(760)](t,n)}catch{}}[r(864)+r(986)+"t"](t=1e3,n="",o=!1){let x=r;if(this[x(931)+x(1952)](),this[x(1491)+x(987)](),this[x(461)+x(1834)+"rs"](),this[x(1275)+x(1285)](1e3,n),this._connectLock=!1,o&&this[x(1943)+x(1727)]()&&!this["_readyCl"+x(1449)]){if(this["_endpoin"+x(966)]?.[x(1615)+x(1134)+"es"]()){let g=this["_endpoin"+x(966)]?.[x(1025)+"ntEndpoint"]();this["_dispatchCloseEv"+x(756)](e[x(958)](ye,"close",{code:1006,reason:x(1853)+g+(x(1610)+x(1567)+x(971)+x(1556)),wasClean:!0}))}else{let g=this[x(1135)][x(1126)+x(1173)+"ptor"](t,n);this[x(1214)+x(592)+x(756)](e[x(1695)](ye,x(760),{code:t,reason:n,wasClean:!0,willReconnect:g})),g&&this[x(1418)]()}return}this[x(1943)+x(1727)]()||this[x(1867)+x(1449)]?this[x(1214)+x(592)+"ent"](e[x(1022)](ye,x(760),{code:t,reason:e.cGzFN})):this[x(1214)+"hCloseEv"+x(756)](e[x(1259)](ye,e[x(636)],{code:1006,reason:e.LQoih})),this[x(951)]=null,this[x(672)+x(966)]?.[x(535)+x(1868)+x(741)](),this[x(902)+"sCounter"]?.[x(1136)+x(946)]()}["_dispatc"+r(1071)+"nt"](t){let n=r;this[n(1691)](e[n(1981)],t),this.onopen&&this[n(1642)](t)}[r(1214)+"hMessage"+r(1564)](t){let n=r;this[n(1691)](e[n(690)],t),this[n(1460)+"e"]&&this[n(1460)+"e"](t)}["_dispatc"+r(1086)+r(1473)](t){let n=r;this[n(1691)](e[n(1513)],t),this[n(1091)+"eAck"]&&this[n(1091)+n(481)](t)}["_dispatc"+r(1196)+r(756)](t){let n=r;this[n(1691)](n(1063),t),this[n(1248)]&&this[n(1248)](t)}["_dispatc"+r(592)+r(756)](t){let n=r;this[n(1691)](e[n(636)],t),this[n(1290)]&&this[n(1290)](t)}get binaryType(){let t=r,n={Ialwi:t(559)+"4",ugdxt:function(o,x){return o+x},LZEAX:function(o,x){return e[t(1684)](o,x)},PHBMx:function(o,x,l,g){return e[t(910)](o,x,l,g)},VFEDU:function(o,x){return o+x}};if(e[t(1004)](t(1599),e[t(974)]))return this[t(951)]?this[t(951)].binaryType:this["_binaryT"+t(1880)];{let o=n[t(826)].split("|"),x=0;for(;;){switch(o[x++]){case"0":if(_0x568f7a.write)return fzrMAJ[t(1475)](_0x486963[t(683)](_0x2bf2e3,_0x5b05f8),_0xd7fe8a);continue;case"1":if(_0x1cff51[t(1082)+"e"])return fzrMAJ[t(1475)](_0x5cbedc[t(1082)+"e"](_0x2a8d7b,_0x114c0e),_0x7ccc61);continue;case"2":if(fzrMAJ[t(682)](_0x1ba2f2[t(805)],40))return fzrMAJ.ugdxt(fzrMAJ.PHBMx(_0x41aa4b,_0x26bc6a,_0xfc712c,_0x795699),_0x164f98);continue;case"3":if(!_0x438868)return _0x165d52;continue;case"4":return fzrMAJ[t(1332)](_0x578d5e(_0x3ee8da,_0x155938,_0x4e13a2),_0x498608)}break}}}set[r(1432)+"pe"](t){let n=r;this[n(900)+n(1880)]=t,this[n(951)]&&(this._ws[n(1432)+"pe"]=t)}get[r(781)+"nt"](){let t=r;return this["_endpoin"+t(966)]?.[t(1025)+t(990)+t(1544)+t(1271)]()||0}get[r(1925)+r(1708)](){let t=r,n={MtahX:function(x,l){return e[I(1551)](x,l)}},o=this[t(1989)+t(1825)][t(1066)]((x,l)=>{let g=t;if(e[g(1585)](g(1404),e.yfSfE))return x+=l&&l[g(1125)+"th"]||0,x;{let p=this[g(1989)+"Queue"][g(1066)]((d,w)=>(d+=w&&w.byteLength||0,d),0);return n[g(915)](p,this[g(951)]?this._ws[g(1925)+"Amount"]:0)}},0);return e[t(733)](o,this[t(951)]?this[t(951)][t(1925)+"Amount"]:0)}get[r(1194)+"ns"](){let t=r;return this[t(951)]?this[t(951)][t(1194)+"ns"]:""}get[r(1845)](){let t=r;return this[t(951)]?this[t(951)][t(1845)]:""}get[r(1531)+"te"](){let t=r;return t(844)==="ZpYyY"?this[t(1809)][t(1962)]:this[t(951)]?this[t(951)].readyState:this[t(1135)][t(1650)+t(925)]?this[t(1529)+"NG"]:this[t(1637)]}get[r(1962)](){let t=r;return this[t(951)]?this[t(951)][t(1962)]:this._url}[r(760)](t=1e3,n){let o=r,x=e[o(1709)][o(1821)]("|"),l=0;for(;;){switch(x[l++]){case"0":this[o(931)+"ngTimer"]();continue;case"1":if(!this[o(951)])return void this[o(593)](e[o(440)]);continue;case"2":this[o(864)+"WebSocket"](t,n);continue;case"3":if(e[o(1781)](this[o(951)][o(1531)+"te"],this[o(1637)])||e.PvAyB(this[o(951)][o(1531)+"te"],this[o(456)]))return void this[o(593)](e[o(1832)]);continue;case"4":this["_dropGlo"+o(1555)+o(1244)]();continue;case"5":this["_QoSMana"+o(1856)]?.[o(1148)]();continue;case"6":this[o(1491)+o(987)]();continue;case"7":this[o(1867)+o(1449)]=!0;continue}break}}async[r(774)](t,n){let o=r;if(e[o(1090)](null,t))throw new Error(o(1838)+o(1364)+o(588)+o(1010)+"a must b"+o(1236)+"ng or an"+o(1426)+o(1145));e[o(916)]==typeof t&&(t=JSON.stringify(t)),e[o(1198)](e[o(1402)],typeof t)&&!e[o(1606)](t,ArrayBuffer)&&!(t[o(603)]&&t[o(603)]instanceof ArrayBuffer)&&(t=JSON[o(458)+"y"](t));let x=await e[o(474)](Os,t),l=e[o(1794)](ja,t),{method:g=0,service:p=this[o(1135)][o(1545)],logID:d=this._options["logIDGen"+o(777)](),headers:w=this._options[o(849)],payloadEncoding:b=this[o(1135)][o(823)+o(597)],payloadType:k=this[o(1135)][o(1414)+o(1880)],logIDNew:T=this._options[o(1651)+o(1346)]["enableAu"+o(1421)+o(980)+"ew"]?a(this[o(1135)][o(1651)+o(1346)][o(583)]):""}=e[o(1389)](n,{});if(!p)throw new Error(e[o(558)]);let R={SeqID:q[o(1324)+"er"](this._seqId++),LogID:q[o(1324)+"er"](d),service:p,method:g,headers:w,payloadEncoding:e[o(782)](b,Object)?b[o(685)]?b.encoding:"":b,payloadType:e[o(1606)](k,Object)?k[o(1265)]?k[o(1265)]:l:k||l,payload:x,LogIDNew:T},B=e[o(1239)](hr,R);return this[o(951)]&&this._ws[o(1531)+"te"]===this[o(687)]?e[o(2005)](e[o(1297)],e[o(564)])?(this[o(951)]&&this._ws[o(774)](B),this[o(593)](e[o(487)],R)):this[o(1133)]?.[o(1724)](_0x51f63a[o(1742)+"id"]):e[o(590)](this["_message"+o(1825)][o(805)],this[o(1135)][o(1840)+o(1484)+o(1692)])?(this[o(1989)+"Queue"].push(B),this[o(593)](e[o(1625)],R)):(this[o(1989)+o(1825)][o(1387)](),this["_message"+o(1825)][o(577)](B)),{seqID:this[o(1199)],logID:d,logIDNew:T}}async[r(1126)+"t"](t){let n=r,{url:o}=e.FcNyo(t,{}),x=Array.isArray(o)?o:e[n(1757)](e[n(1402)],typeof o)?[o]:[];t&&Object[n(893)](this[n(1135)],t),x&&x[n(805)]?this[n(672)+n(966)]=new Ls(x,this[n(1135)].maxRetries):this[n(672)+n(966)]?.[n(535)+n(1868)+n(741)](),this[n(902)+n(1739)]?.resetCounter(this[n(1135)][n(1881)+n(643)]),this[n(1867)+"osed"]=!1,this[n(951)]&&e.OKgtd(this[n(951)][n(1531)+"te"],this.CLOSED)?this[n(634)+n(599)](1e3,e[n(1535)],!0):(this[n(988)]=!0,this[n(1418)]())}async[r(1339)](){let t=r;if(!this[t(1418)+t(1149)]){let n=e.QTeAC[t(1821)]("|"),o=0;for(;;){switch(n[o++]){case"0":this._endpointManager?.[t(535)+t(1868)+t(741)]();continue;case"1":this["_pingLos"+t(1739)]?.[t(1136)+"nter"]();continue;case"2":this[t(988)]=!0;continue;case"3":this["_readyCl"+t(1449)]=!1;continue;case"4":this._connect();continue}break}}}[r(771)+r(1244)](t,n){this.on(t,n)}[r(1107)+r(1564)](t){let n=r,{type:o}=t;this[n(1691)](o,t)}[r(1174)+r(1192)+r(1864)](t,n){let o=r,x={mvFNQ:function(l,g){return e[I(530)](l,g)},XkjQM:function(l,g){return l|g},bfqRm:function(l,g){return e[I(1433)](l,g)},DnFAZ:function(l,g){return e.dsWzC(l,g)},ZBoyw:function(l,g){return e[I(460)](l,g)},JUjsE:function(l,g){return l<<g},PcrFk:function(l,g){return e[I(1569)](l,g)},vkkYo:function(l,g){return e[I(1492)](l,g)}};if(e[o(1147)](e[o(1563)],o(965)))return new _0x3315d7(QSwHAW[o(853)](QSwHAW.XkjQM(QSwHAW[o(853)](QSwHAW[o(1963)](_0x4ac589[4],24),_0x96ae3[5]<<16),QSwHAW.bfqRm(_0x1bb430[6],8)),_0x24f9a8[7]),QSwHAW[o(853)](QSwHAW[o(1179)](QSwHAW[o(1948)](QSwHAW[o(1241)](_0x816b91[0],24),QSwHAW[o(699)](_0xb3874[1],16)),QSwHAW[o(1068)](_0x3c39d8[2],8)),_0x1df12d[3]),_0x55cc30);this[o(486)](t,n)}[r(1804)](){let t=r,n={ueaVu:function(o,x){return o(x)},XARVI:t(1488),NdQcA:e[t(475)],DuqVn:e.sLlyu,FPsrq:function(o,x){return e[t(519)](o,x)},ummEo:e.SSUCl,NrAqM:function(o,x,l){return e[t(1016)](o,x,l)}};return new Promise((o,x)=>{let l=t,g={IzdJF:function(w,b){return n[I(787)](w,b)},DVKFR:n.ummEo,eVuQF:l(1996)+"e_success",PbUrR:n[l(509)]};this[l(931)+l(1952)](),this[l(836)+l(447)+"Id"]=n.NrAqM(setTimeout,this[l(763)][l(459)](this),this[l(1135)][l(1961)+l(579)]);let p=()=>{let w=l;g.IzdJF(o,g[w(1611)]),this[w(486)](g.eVuQF,p),this[w(486)](g[w(1837)],d)},d=()=>{let w=l;n[w(1228)](x,n[w(1538)]),this[w(486)](n.NdQcA,p),this.off(n[w(509)],d)};this.on(n[l(1502)],p),this.on(n[l(509)],d),this._ping()})}}})(),Q[E(1640)+E(568)]=Y.CustomCloseEvent,Q[E(1077)+E(1768)]=Y["CustomEr"+E(1768)],Q[E(1635)+"e"]=Y[E(1635)+"e"],Q[E(1564)]=Y.Event,Q[E(1897)]=Y[E(1897)],Q[E(765)+E(2020)+E(1852)]=Y[E(765)+E(2020)+E(1852)],Q[E(2020)+"vent"]=Y[E(2020)+"vent"],Q[E(1172)+"t"]=Y[E(1172)+"t"],Q[E(1466)+E(1337)]=Y["Reconnec"+E(1337)],Q[E(448)+E(568)]=Y[E(448)+"oseEvent"],Q[E(1017)+E(1768)]=Y["createEr"+E(1768)],Q[E(1826)+E(1915)+"nt"]=Y[E(1826)+E(1915)+"nt"],Q[E(1197)+E(619)]=Y[E(1197)+E(619)],Q["createRe"+E(711)+E(1852)]=Y.createReconnectEvent,Q[E(1536)+"rame"]=Y["decodedF"+E(1237)],Q[E(1317)+E(477)]=Y[E(1317)+"ame"];for(On in Y)["CustomCl"+E(568),E(1077)+E(1768),E(1635)+"e","Event",E(1897),"Frontier"+E(2020)+E(1852),E(2020)+E(1852),"OpenEvent","Reconnec"+E(1337),E(448)+E(568),E(1017)+E(1768),E(1826)+E(1915)+"nt",E(1197)+"enEvent",E(1992)+"connectE"+E(1852),E(1536)+E(1237),E(1317)+E(477)][E(1187)](On)===-1&&(Q[On]=Y[On]);var On;Object[E(1383)+E(1417)](Q,"__esModule",{value:!0})});var Fe=de((vg,co)=>{"use strict";var oo=["nodebuffer","arraybuffer","fragments"],ao=typeof Blob<"u";ao&&oo.push("blob");co.exports={BINARY_TYPES:oo,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ao,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Vt=de((Sg,Hn)=>{"use strict";var{EMPTY_BUFFER:Yx}=Fe(),Fr=Buffer[Symbol.species];function $x(r,e){if(r.length===0)return Yx;if(r.length===1)return r[0];let i=Buffer.allocUnsafe(e),a=0;for(let c=0;c<r.length;c++){let u=r[c];i.set(u,a),a+=u.length}return a<e?new Fr(i.buffer,i.byteOffset,a):i}function xo(r,e,i,a,c){for(let u=0;u<c;u++)i[a+u]=r[u]^e[u&3]}function uo(r,e){for(let i=0;i<r.length;i++)r[i]^=e[i&3]}function Zx(r){return r.length===r.buffer.byteLength?r.buffer:r.buffer.slice(r.byteOffset,r.byteOffset+r.length)}function Ur(r){if(Ur.readOnly=!0,Buffer.isBuffer(r))return r;let e;return r instanceof ArrayBuffer?e=new Fr(r):ArrayBuffer.isView(r)?e=new Fr(r.buffer,r.byteOffset,r.byteLength):(e=Buffer.from(r),Ur.readOnly=!1),e}Hn.exports={concat:$x,mask:xo,toArrayBuffer:Zx,toBuffer:Ur,unmask:uo};if(!process.env.WS_NO_BUFFER_UTIL)try{let r=X("bufferutil");Hn.exports.mask=function(e,i,a,c,u){u<48?xo(e,i,a,c,u):r.mask(e,i,a,c,u)},Hn.exports.unmask=function(e,i){e.length<32?uo(e,i):r.unmask(e,i)}}catch{}});var ho=de((Cg,lo)=>{"use strict";var fo=Symbol("kDone"),Kr=Symbol("kRun"),Gr=class{constructor(e){this[fo]=()=>{this.pending--,this[Kr]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Kr]()}[Kr](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[fo])}}};lo.exports=Gr});var Et=de((Eg,_o)=>{"use strict";var Xt=X("zlib"),go=Vt(),Qx=ho(),{kStatusCode:po}=Fe(),eu=Buffer[Symbol.species],tu=Buffer.from([0,0,255,255]),Wn=Symbol("permessage-deflate"),Ue=Symbol("total-length"),St=Symbol("callback"),Ye=Symbol("buffers"),Ct=Symbol("error"),jn,Hr=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!jn){let i=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;jn=new Qx(i)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[St];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let i=this._options,a=e.find(c=>!(i.serverNoContextTakeover===!1&&c.server_no_context_takeover||c.server_max_window_bits&&(i.serverMaxWindowBits===!1||typeof i.serverMaxWindowBits=="number"&&i.serverMaxWindowBits>c.server_max_window_bits)||typeof i.clientMaxWindowBits=="number"&&!c.client_max_window_bits));if(!a)throw new Error("None of the extension offers can be accepted");return i.serverNoContextTakeover&&(a.server_no_context_takeover=!0),i.clientNoContextTakeover&&(a.client_no_context_takeover=!0),typeof i.serverMaxWindowBits=="number"&&(a.server_max_window_bits=i.serverMaxWindowBits),typeof i.clientMaxWindowBits=="number"?a.client_max_window_bits=i.clientMaxWindowBits:(a.client_max_window_bits===!0||i.clientMaxWindowBits===!1)&&delete a.client_max_window_bits,a}acceptAsClient(e){let i=e[0];if(this._options.clientNoContextTakeover===!1&&i.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!i.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(i.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&i.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return i}normalizeParams(e){return e.forEach(i=>{Object.keys(i).forEach(a=>{let c=i[a];if(c.length>1)throw new Error(`Parameter "${a}" must have only a single value`);if(c=c[0],a==="client_max_window_bits"){if(c!==!0){let u=+c;if(!Number.isInteger(u)||u<8||u>15)throw new TypeError(`Invalid value for parameter "${a}": ${c}`);c=u}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${a}": ${c}`)}else if(a==="server_max_window_bits"){let u=+c;if(!Number.isInteger(u)||u<8||u>15)throw new TypeError(`Invalid value for parameter "${a}": ${c}`);c=u}else if(a==="client_no_context_takeover"||a==="server_no_context_takeover"){if(c!==!0)throw new TypeError(`Invalid value for parameter "${a}": ${c}`)}else throw new Error(`Unknown parameter "${a}"`);i[a]=c})}),e}decompress(e,i,a){jn.add(c=>{this._decompress(e,i,(u,f)=>{c(),a(u,f)})})}compress(e,i,a){jn.add(c=>{this._compress(e,i,(u,f)=>{c(),a(u,f)})})}_decompress(e,i,a){let c=this._isServer?"client":"server";if(!this._inflate){let u=`${c}_max_window_bits`,f=typeof this.params[u]!="number"?Xt.Z_DEFAULT_WINDOWBITS:this.params[u];this._inflate=Xt.createInflateRaw({...this._options.zlibInflateOptions,windowBits:f}),this._inflate[Wn]=this,this._inflate[Ue]=0,this._inflate[Ye]=[],this._inflate.on("error",ru),this._inflate.on("data",mo)}this._inflate[St]=a,this._inflate.write(e),i&&this._inflate.write(tu),this._inflate.flush(()=>{let u=this._inflate[Ct];if(u){this._inflate.close(),this._inflate=null,a(u);return}let f=go.concat(this._inflate[Ye],this._inflate[Ue]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Ue]=0,this._inflate[Ye]=[],i&&this.params[`${c}_no_context_takeover`]&&this._inflate.reset()),a(null,f)})}_compress(e,i,a){let c=this._isServer?"server":"client";if(!this._deflate){let u=`${c}_max_window_bits`,f=typeof this.params[u]!="number"?Xt.Z_DEFAULT_WINDOWBITS:this.params[u];this._deflate=Xt.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:f}),this._deflate[Ue]=0,this._deflate[Ye]=[],this._deflate.on("data",nu)}this._deflate[St]=a,this._deflate.write(e),this._deflate.flush(Xt.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let u=go.concat(this._deflate[Ye],this._deflate[Ue]);i&&(u=new eu(u.buffer,u.byteOffset,u.length-4)),this._deflate[St]=null,this._deflate[Ue]=0,this._deflate[Ye]=[],i&&this.params[`${c}_no_context_takeover`]&&this._deflate.reset(),a(null,u)})}};_o.exports=Hr;function nu(r){this[Ye].push(r),this[Ue]+=r.length}function mo(r){if(this[Ue]+=r.length,this[Wn]._maxPayload<1||this[Ue]<=this[Wn]._maxPayload){this[Ye].push(r);return}this[Ct]=new RangeError("Max payload size exceeded"),this[Ct].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Ct][po]=1009,this.removeListener("data",mo),this.reset()}function ru(r){if(this[Wn]._inflate=null,this[Ct]){this[St](this[Ct]);return}r[po]=1007,this[St](r)}});var At=de((Ag,Jn)=>{"use strict";var{isUtf8:wo}=X("buffer"),{hasBlob:su}=Fe(),iu=[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 ou(r){return r>=1e3&&r<=1014&&r!==1004&&r!==1005&&r!==1006||r>=3e3&&r<=4999}function jr(r){let e=r.length,i=0;for(;i<e;)if((r[i]&128)===0)i++;else if((r[i]&224)===192){if(i+1===e||(r[i+1]&192)!==128||(r[i]&254)===192)return!1;i+=2}else if((r[i]&240)===224){if(i+2>=e||(r[i+1]&192)!==128||(r[i+2]&192)!==128||r[i]===224&&(r[i+1]&224)===128||r[i]===237&&(r[i+1]&224)===160)return!1;i+=3}else if((r[i]&248)===240){if(i+3>=e||(r[i+1]&192)!==128||(r[i+2]&192)!==128||(r[i+3]&192)!==128||r[i]===240&&(r[i+1]&240)===128||r[i]===244&&r[i+1]>143||r[i]>244)return!1;i+=4}else return!1;return!0}function au(r){return su&&typeof r=="object"&&typeof r.arrayBuffer=="function"&&typeof r.type=="string"&&typeof r.stream=="function"&&(r[Symbol.toStringTag]==="Blob"||r[Symbol.toStringTag]==="File")}Jn.exports={isBlob:au,isValidStatusCode:ou,isValidUTF8:jr,tokenChars:iu};if(wo)Jn.exports.isValidUTF8=function(r){return r.length<24?jr(r):wo(r)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let r=X("utf-8-validate");Jn.exports.isValidUTF8=function(e){return e.length<32?jr(e):r(e)}}catch{}});var Yr=de((kg,Ao)=>{"use strict";var{Writable:cu}=X("stream"),yo=Et(),{BINARY_TYPES:xu,EMPTY_BUFFER:bo,kStatusCode:uu,kWebSocket:fu}=Fe(),{concat:Wr,toArrayBuffer:du,unmask:lu}=Vt(),{isValidStatusCode:hu,isValidUTF8:vo}=At(),Vn=Buffer[Symbol.species],me=0,So=1,Co=2,Eo=3,Jr=4,Vr=5,Xn=6,Xr=class extends cu{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||xu[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[fu]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=me}_write(e,i,a){if(this._opcode===8&&this._state==me)return a();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(a)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let a=this._buffers[0];return this._buffers[0]=new Vn(a.buffer,a.byteOffset+e,a.length-e),new Vn(a.buffer,a.byteOffset,e)}let i=Buffer.allocUnsafe(e);do{let a=this._buffers[0],c=i.length-e;e>=a.length?i.set(this._buffers.shift(),c):(i.set(new Uint8Array(a.buffer,a.byteOffset,e),c),this._buffers[0]=new Vn(a.buffer,a.byteOffset+e,a.length-e)),e-=a.length}while(e>0);return i}startLoop(e){this._loop=!0;do switch(this._state){case me:this.getInfo(e);break;case So:this.getPayloadLength16(e);break;case Co:this.getPayloadLength64(e);break;case Eo:this.getMask();break;case Jr:this.getData(e);break;case Vr:case Xn:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let i=this.consume(2);if((i[0]&48)!==0){let c=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(c);return}let a=(i[0]&64)===64;if(a&&!this._extensions[yo.extensionName]){let c=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(c);return}if(this._fin=(i[0]&128)===128,this._opcode=i[0]&15,this._payloadLength=i[1]&127,this._opcode===0){if(a){let c=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(c);return}if(!this._fragmented){let c=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(c);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let c=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(c);return}this._compressed=a}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let c=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(c);return}if(a){let c=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(c);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let c=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(c);return}}else{let c=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(c);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(i[1]&128)===128,this._isServer){if(!this._masked){let c=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(c);return}}else if(this._masked){let c=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(c);return}this._payloadLength===126?this._state=So:this._payloadLength===127?this._state=Co:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let i=this.consume(8),a=i.readUInt32BE(0);if(a>Math.pow(2,21)-1){let c=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(c);return}this._payloadLength=a*Math.pow(2,32)+i.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let i=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(i);return}this._masked?this._state=Eo:this._state=Jr}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Jr}getData(e){let i=bo;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}i=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&lu(i,this._mask)}if(this._opcode>7){this.controlMessage(i,e);return}if(this._compressed){this._state=Vr,this.decompress(i,e);return}i.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(i)),this.dataMessage(e)}decompress(e,i){this._extensions[yo.extensionName].decompress(e,this._fin,(c,u)=>{if(c)return i(c);if(u.length){if(this._messageLength+=u.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let f=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");i(f);return}this._fragments.push(u)}this.dataMessage(i),this._state===me&&this.startLoop(i)})}dataMessage(e){if(!this._fin){this._state=me;return}let i=this._messageLength,a=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let c;this._binaryType==="nodebuffer"?c=Wr(a,i):this._binaryType==="arraybuffer"?c=du(Wr(a,i)):this._binaryType==="blob"?c=new Blob(a):c=a,this._allowSynchronousEvents?(this.emit("message",c,!0),this._state=me):(this._state=Xn,setImmediate(()=>{this.emit("message",c,!0),this._state=me,this.startLoop(e)}))}else{let c=Wr(a,i);if(!this._skipUTF8Validation&&!vo(c)){let u=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(u);return}this._state===Vr||this._allowSynchronousEvents?(this.emit("message",c,!1),this._state=me):(this._state=Xn,setImmediate(()=>{this.emit("message",c,!1),this._state=me,this.startLoop(e)}))}}controlMessage(e,i){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,bo),this.end();else{let a=e.readUInt16BE(0);if(!hu(a)){let u=this.createError(RangeError,`invalid status code ${a}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");i(u);return}let c=new Vn(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!vo(c)){let u=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");i(u);return}this._loop=!1,this.emit("conclude",a,c),this.end()}this._state=me;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=me):(this._state=Xn,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=me,this.startLoop(i)}))}createError(e,i,a,c,u){this._loop=!1,this._errored=!0;let f=new e(a?`Invalid WebSocket frame: ${i}`:i);return Error.captureStackTrace(f,this.createError),f.code=u,f[uu]=c,f}};Ao.exports=Xr});var Qr=de((Pg,Po)=>{"use strict";var{Duplex:Ig}=X("stream"),{randomFillSync:gu}=X("crypto"),ko=Et(),{EMPTY_BUFFER:pu,kWebSocket:mu,NOOP:_u}=Fe(),{isBlob:kt,isValidStatusCode:wu}=At(),{mask:Io,toBuffer:st}=Vt(),_e=Symbol("kByteLength"),yu=Buffer.alloc(4),Yn=8*1024,it,It=Yn,ve=0,bu=1,vu=2,$r=class r{constructor(e,i,a){this._extensions=i||{},a&&(this._generateMask=a,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=ve,this.onerror=_u,this[mu]=void 0}static frame(e,i){let a,c=!1,u=2,f=!1;i.mask&&(a=i.maskBuffer||yu,i.generateMask?i.generateMask(a):(It===Yn&&(it===void 0&&(it=Buffer.alloc(Yn)),gu(it,0,Yn),It=0),a[0]=it[It++],a[1]=it[It++],a[2]=it[It++],a[3]=it[It++]),f=(a[0]|a[1]|a[2]|a[3])===0,u=6);let h;typeof e=="string"?(!i.mask||f)&&i[_e]!==void 0?h=i[_e]:(e=Buffer.from(e),h=e.length):(h=e.length,c=i.mask&&i.readOnly&&!f);let m=h;h>=65536?(u+=8,m=127):h>125&&(u+=2,m=126);let _=Buffer.allocUnsafe(c?h+u:u);return _[0]=i.fin?i.opcode|128:i.opcode,i.rsv1&&(_[0]|=64),_[1]=m,m===126?_.writeUInt16BE(h,2):m===127&&(_[2]=_[3]=0,_.writeUIntBE(h,4,6)),i.mask?(_[1]|=128,_[u-4]=a[0],_[u-3]=a[1],_[u-2]=a[2],_[u-1]=a[3],f?[_,e]:c?(Io(e,a,_,u,h),[_]):(Io(e,a,e,0,h),[_,e])):[_,e]}close(e,i,a,c){let u;if(e===void 0)u=pu;else{if(typeof e!="number"||!wu(e))throw new TypeError("First argument must be a valid error code number");if(i===void 0||!i.length)u=Buffer.allocUnsafe(2),u.writeUInt16BE(e,0);else{let h=Buffer.byteLength(i);if(h>123)throw new RangeError("The message must not be greater than 123 bytes");u=Buffer.allocUnsafe(2+h),u.writeUInt16BE(e,0),typeof i=="string"?u.write(i,2):u.set(i,2)}}let f={[_e]:u.length,fin:!0,generateMask:this._generateMask,mask:a,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==ve?this.enqueue([this.dispatch,u,!1,f,c]):this.sendFrame(r.frame(u,f),c)}ping(e,i,a){let c,u;if(typeof e=="string"?(c=Buffer.byteLength(e),u=!1):kt(e)?(c=e.size,u=!1):(e=st(e),c=e.length,u=st.readOnly),c>125)throw new RangeError("The data size must not be greater than 125 bytes");let f={[_e]:c,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:9,readOnly:u,rsv1:!1};kt(e)?this._state!==ve?this.enqueue([this.getBlobData,e,!1,f,a]):this.getBlobData(e,!1,f,a):this._state!==ve?this.enqueue([this.dispatch,e,!1,f,a]):this.sendFrame(r.frame(e,f),a)}pong(e,i,a){let c,u;if(typeof e=="string"?(c=Buffer.byteLength(e),u=!1):kt(e)?(c=e.size,u=!1):(e=st(e),c=e.length,u=st.readOnly),c>125)throw new RangeError("The data size must not be greater than 125 bytes");let f={[_e]:c,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:10,readOnly:u,rsv1:!1};kt(e)?this._state!==ve?this.enqueue([this.getBlobData,e,!1,f,a]):this.getBlobData(e,!1,f,a):this._state!==ve?this.enqueue([this.dispatch,e,!1,f,a]):this.sendFrame(r.frame(e,f),a)}send(e,i,a){let c=this._extensions[ko.extensionName],u=i.binary?2:1,f=i.compress,h,m;typeof e=="string"?(h=Buffer.byteLength(e),m=!1):kt(e)?(h=e.size,m=!1):(e=st(e),h=e.length,m=st.readOnly),this._firstFragment?(this._firstFragment=!1,f&&c&&c.params[c._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(f=h>=c._threshold),this._compress=f):(f=!1,u=0),i.fin&&(this._firstFragment=!0);let _={[_e]:h,fin:i.fin,generateMask:this._generateMask,mask:i.mask,maskBuffer:this._maskBuffer,opcode:u,readOnly:m,rsv1:f};kt(e)?this._state!==ve?this.enqueue([this.getBlobData,e,this._compress,_,a]):this.getBlobData(e,this._compress,_,a):this._state!==ve?this.enqueue([this.dispatch,e,this._compress,_,a]):this.dispatch(e,this._compress,_,a)}getBlobData(e,i,a,c){this._bufferedBytes+=a[_e],this._state=vu,e.arrayBuffer().then(u=>{if(this._socket.destroyed){let h=new Error("The socket was closed while the blob was being read");process.nextTick(Zr,this,h,c);return}this._bufferedBytes-=a[_e];let f=st(u);i?this.dispatch(f,i,a,c):(this._state=ve,this.sendFrame(r.frame(f,a),c),this.dequeue())}).catch(u=>{process.nextTick(Su,this,u,c)})}dispatch(e,i,a,c){if(!i){this.sendFrame(r.frame(e,a),c);return}let u=this._extensions[ko.extensionName];this._bufferedBytes+=a[_e],this._state=bu,u.compress(e,a.fin,(f,h)=>{if(this._socket.destroyed){let m=new Error("The socket was closed while data was being compressed");Zr(this,m,c);return}this._bufferedBytes-=a[_e],this._state=ve,a.readOnly=!1,this.sendFrame(r.frame(h,a),c),this.dequeue()})}dequeue(){for(;this._state===ve&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][_e],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][_e],this._queue.push(e)}sendFrame(e,i){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],i),this._socket.uncork()):this._socket.write(e[0],i)}};Po.exports=$r;function Zr(r,e,i){typeof i=="function"&&i(e);for(let a=0;a<r._queue.length;a++){let c=r._queue[a],u=c[c.length-1];typeof u=="function"&&u(e)}}function Su(r,e,i){Zr(r,e,i),r.onerror(e)}});var zo=de((Dg,Oo)=>{"use strict";var{kForOnEventAttribute:Yt,kListener:es}=Fe(),Do=Symbol("kCode"),To=Symbol("kData"),No=Symbol("kError"),Lo=Symbol("kMessage"),Ro=Symbol("kReason"),Pt=Symbol("kTarget"),Bo=Symbol("kType"),Mo=Symbol("kWasClean"),Ke=class{constructor(e){this[Pt]=null,this[Bo]=e}get target(){return this[Pt]}get type(){return this[Bo]}};Object.defineProperty(Ke.prototype,"target",{enumerable:!0});Object.defineProperty(Ke.prototype,"type",{enumerable:!0});var ot=class extends Ke{constructor(e,i={}){super(e),this[Do]=i.code===void 0?0:i.code,this[Ro]=i.reason===void 0?"":i.reason,this[Mo]=i.wasClean===void 0?!1:i.wasClean}get code(){return this[Do]}get reason(){return this[Ro]}get wasClean(){return this[Mo]}};Object.defineProperty(ot.prototype,"code",{enumerable:!0});Object.defineProperty(ot.prototype,"reason",{enumerable:!0});Object.defineProperty(ot.prototype,"wasClean",{enumerable:!0});var Dt=class extends Ke{constructor(e,i={}){super(e),this[No]=i.error===void 0?null:i.error,this[Lo]=i.message===void 0?"":i.message}get error(){return this[No]}get message(){return this[Lo]}};Object.defineProperty(Dt.prototype,"error",{enumerable:!0});Object.defineProperty(Dt.prototype,"message",{enumerable:!0});var $t=class extends Ke{constructor(e,i={}){super(e),this[To]=i.data===void 0?null:i.data}get data(){return this[To]}};Object.defineProperty($t.prototype,"data",{enumerable:!0});var Cu={addEventListener(r,e,i={}){for(let c of this.listeners(r))if(!i[Yt]&&c[es]===e&&!c[Yt])return;let a;if(r==="message")a=function(u,f){let h=new $t("message",{data:f?u:u.toString()});h[Pt]=this,$n(e,this,h)};else if(r==="close")a=function(u,f){let h=new ot("close",{code:u,reason:f.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});h[Pt]=this,$n(e,this,h)};else if(r==="error")a=function(u){let f=new Dt("error",{error:u,message:u.message});f[Pt]=this,$n(e,this,f)};else if(r==="open")a=function(){let u=new Ke("open");u[Pt]=this,$n(e,this,u)};else return;a[Yt]=!!i[Yt],a[es]=e,i.once?this.once(r,a):this.on(r,a)},removeEventListener(r,e){for(let i of this.listeners(r))if(i[es]===e&&!i[Yt]){this.removeListener(r,i);break}}};Oo.exports={CloseEvent:ot,ErrorEvent:Dt,Event:Ke,EventTarget:Cu,MessageEvent:$t};function $n(r,e,i){typeof r=="object"&&r.handleEvent?r.handleEvent.call(r,i):r.call(e,i)}});var Zn=de((Tg,qo)=>{"use strict";var{tokenChars:Zt}=At();function Le(r,e,i){r[e]===void 0?r[e]=[i]:r[e].push(i)}function Eu(r){let e=Object.create(null),i=Object.create(null),a=!1,c=!1,u=!1,f,h,m=-1,_=-1,y=-1,v=0;for(;v<r.length;v++)if(_=r.charCodeAt(v),f===void 0)if(y===-1&&Zt[_]===1)m===-1&&(m=v);else if(v!==0&&(_===32||_===9))y===-1&&m!==-1&&(y=v);else if(_===59||_===44){if(m===-1)throw new SyntaxError(`Unexpected character at index ${v}`);y===-1&&(y=v);let A=r.slice(m,y);_===44?(Le(e,A,i),i=Object.create(null)):f=A,m=y=-1}else throw new SyntaxError(`Unexpected character at index ${v}`);else if(h===void 0)if(y===-1&&Zt[_]===1)m===-1&&(m=v);else if(_===32||_===9)y===-1&&m!==-1&&(y=v);else if(_===59||_===44){if(m===-1)throw new SyntaxError(`Unexpected character at index ${v}`);y===-1&&(y=v),Le(i,r.slice(m,y),!0),_===44&&(Le(e,f,i),i=Object.create(null),f=void 0),m=y=-1}else if(_===61&&m!==-1&&y===-1)h=r.slice(m,v),m=y=-1;else throw new SyntaxError(`Unexpected character at index ${v}`);else if(c){if(Zt[_]!==1)throw new SyntaxError(`Unexpected character at index ${v}`);m===-1?m=v:a||(a=!0),c=!1}else if(u)if(Zt[_]===1)m===-1&&(m=v);else if(_===34&&m!==-1)u=!1,y=v;else if(_===92)c=!0;else throw new SyntaxError(`Unexpected character at index ${v}`);else if(_===34&&r.charCodeAt(v-1)===61)u=!0;else if(y===-1&&Zt[_]===1)m===-1&&(m=v);else if(m!==-1&&(_===32||_===9))y===-1&&(y=v);else if(_===59||_===44){if(m===-1)throw new SyntaxError(`Unexpected character at index ${v}`);y===-1&&(y=v);let A=r.slice(m,y);a&&(A=A.replace(/\\/g,""),a=!1),Le(i,h,A),_===44&&(Le(e,f,i),i=Object.create(null),f=void 0),h=void 0,m=y=-1}else throw new SyntaxError(`Unexpected character at index ${v}`);if(m===-1||u||_===32||_===9)throw new SyntaxError("Unexpected end of input");y===-1&&(y=v);let S=r.slice(m,y);return f===void 0?Le(e,S,i):(h===void 0?Le(i,S,!0):a?Le(i,h,S.replace(/\\/g,"")):Le(i,h,S),Le(e,f,i)),e}function Au(r){return Object.keys(r).map(e=>{let i=r[e];return Array.isArray(i)||(i=[i]),i.map(a=>[e].concat(Object.keys(a).map(c=>{let u=a[c];return Array.isArray(u)||(u=[u]),u.map(f=>f===!0?c:`${c}=${f}`).join("; ")})).join("; ")).join(", ")}).join(", ")}qo.exports={format:Au,parse:Eu}});var nr=de((Rg,$o)=>{"use strict";var ku=X("events"),Iu=X("https"),Pu=X("http"),Ko=X("net"),Du=X("tls"),{randomBytes:Tu,createHash:Nu}=X("crypto"),{Duplex:Ng,Readable:Lg}=X("stream"),{URL:ts}=X("url"),$e=Et(),Lu=Yr(),Ru=Qr(),{isBlob:Bu}=At(),{BINARY_TYPES:Fo,CLOSE_TIMEOUT:Mu,EMPTY_BUFFER:Qn,GUID:Ou,kForOnEventAttribute:ns,kListener:zu,kStatusCode:qu,kWebSocket:ne,NOOP:Go}=Fe(),{EventTarget:{addEventListener:Fu,removeEventListener:Uu}}=zo(),{format:Ku,parse:Gu}=Zn(),{toBuffer:Hu}=Vt(),Ho=Symbol("kAborted"),rs=[8,13],Ge=["CONNECTING","OPEN","CLOSING","CLOSED"],ju=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,G=class r extends ku{constructor(e,i,a){super(),this._binaryType=Fo[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Qn,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=r.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,i===void 0?i=[]:Array.isArray(i)||(typeof i=="object"&&i!==null?(a=i,i=[]):i=[i]),jo(this,e,i,a)):(this._autoPong=a.autoPong,this._closeTimeout=a.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Fo.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,i,a){let c=new Lu({allowSynchronousEvents:a.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:a.maxPayload,skipUTF8Validation:a.skipUTF8Validation}),u=new Ru(e,this._extensions,a.generateMask);this._receiver=c,this._sender=u,this._socket=e,c[ne]=this,u[ne]=this,e[ne]=this,c.on("conclude",Vu),c.on("drain",Xu),c.on("error",Yu),c.on("message",$u),c.on("ping",Zu),c.on("pong",Qu),u.onerror=ef,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),i.length>0&&e.unshift(i),e.on("close",Vo),e.on("data",tr),e.on("end",Xo),e.on("error",Yo),this._readyState=r.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=r.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[$e.extensionName]&&this._extensions[$e.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=r.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,i){if(this.readyState!==r.CLOSED){if(this.readyState===r.CONNECTING){ge(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===r.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=r.CLOSING,this._sender.close(e,i,!this._isServer,a=>{a||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Jo(this)}}pause(){this.readyState===r.CONNECTING||this.readyState===r.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,i,a){if(this.readyState===r.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(a=e,e=i=void 0):typeof i=="function"&&(a=i,i=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==r.OPEN){ss(this,e,a);return}i===void 0&&(i=!this._isServer),this._sender.ping(e||Qn,i,a)}pong(e,i,a){if(this.readyState===r.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(a=e,e=i=void 0):typeof i=="function"&&(a=i,i=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==r.OPEN){ss(this,e,a);return}i===void 0&&(i=!this._isServer),this._sender.pong(e||Qn,i,a)}resume(){this.readyState===r.CONNECTING||this.readyState===r.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,i,a){if(this.readyState===r.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof i=="function"&&(a=i,i={}),typeof e=="number"&&(e=e.toString()),this.readyState!==r.OPEN){ss(this,e,a);return}let c={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...i};this._extensions[$e.extensionName]||(c.compress=!1),this._sender.send(e||Qn,c,a)}terminate(){if(this.readyState!==r.CLOSED){if(this.readyState===r.CONNECTING){ge(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=r.CLOSING,this._socket.destroy())}}};Object.defineProperty(G,"CONNECTING",{enumerable:!0,value:Ge.indexOf("CONNECTING")});Object.defineProperty(G.prototype,"CONNECTING",{enumerable:!0,value:Ge.indexOf("CONNECTING")});Object.defineProperty(G,"OPEN",{enumerable:!0,value:Ge.indexOf("OPEN")});Object.defineProperty(G.prototype,"OPEN",{enumerable:!0,value:Ge.indexOf("OPEN")});Object.defineProperty(G,"CLOSING",{enumerable:!0,value:Ge.indexOf("CLOSING")});Object.defineProperty(G.prototype,"CLOSING",{enumerable:!0,value:Ge.indexOf("CLOSING")});Object.defineProperty(G,"CLOSED",{enumerable:!0,value:Ge.indexOf("CLOSED")});Object.defineProperty(G.prototype,"CLOSED",{enumerable:!0,value:Ge.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(r=>{Object.defineProperty(G.prototype,r,{enumerable:!0})});["open","error","close","message"].forEach(r=>{Object.defineProperty(G.prototype,`on${r}`,{enumerable:!0,get(){for(let e of this.listeners(r))if(e[ns])return e[zu];return null},set(e){for(let i of this.listeners(r))if(i[ns]){this.removeListener(r,i);break}typeof e=="function"&&this.addEventListener(r,e,{[ns]:!0})}})});G.prototype.addEventListener=Fu;G.prototype.removeEventListener=Uu;$o.exports=G;function jo(r,e,i,a){let c={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Mu,protocolVersion:rs[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...a,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(r._autoPong=c.autoPong,r._closeTimeout=c.closeTimeout,!rs.includes(c.protocolVersion))throw new RangeError(`Unsupported protocol version: ${c.protocolVersion} (supported versions: ${rs.join(", ")})`);let u;if(e instanceof ts)u=e;else try{u=new ts(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}u.protocol==="http:"?u.protocol="ws:":u.protocol==="https:"&&(u.protocol="wss:"),r._url=u.href;let f=u.protocol==="wss:",h=u.protocol==="ws+unix:",m;if(u.protocol!=="ws:"&&!f&&!h?m=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:h&&!u.pathname?m="The URL's pathname is empty":u.hash&&(m="The URL contains a fragment identifier"),m){let L=new SyntaxError(m);if(r._redirects===0)throw L;er(r,L);return}let _=f?443:80,y=Tu(16).toString("base64"),v=f?Iu.request:Pu.request,S=new Set,A;if(c.createConnection=c.createConnection||(f?Ju:Wu),c.defaultPort=c.defaultPort||_,c.port=u.port||_,c.host=u.hostname.startsWith("[")?u.hostname.slice(1,-1):u.hostname,c.headers={...c.headers,"Sec-WebSocket-Version":c.protocolVersion,"Sec-WebSocket-Key":y,Connection:"Upgrade",Upgrade:"websocket"},c.path=u.pathname+u.search,c.timeout=c.handshakeTimeout,c.perMessageDeflate&&(A=new $e({...c.perMessageDeflate,isServer:!1,maxPayload:c.maxPayload}),c.headers["Sec-WebSocket-Extensions"]=Ku({[$e.extensionName]:A.offer()})),i.length){for(let L of i){if(typeof L!="string"||!ju.test(L)||S.has(L))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(L)}c.headers["Sec-WebSocket-Protocol"]=i.join(",")}if(c.origin&&(c.protocolVersion<13?c.headers["Sec-WebSocket-Origin"]=c.origin:c.headers.Origin=c.origin),(u.username||u.password)&&(c.auth=`${u.username}:${u.password}`),h){let L=c.path.split(":");c.socketPath=L[0],c.path=L[1]}let D;if(c.followRedirects){if(r._redirects===0){r._originalIpc=h,r._originalSecure=f,r._originalHostOrSocketPath=h?c.socketPath:u.host;let L=a&&a.headers;if(a={...a,headers:{}},L)for(let[F,$]of Object.entries(L))a.headers[F.toLowerCase()]=$}else if(r.listenerCount("redirect")===0){let L=h?r._originalIpc?c.socketPath===r._originalHostOrSocketPath:!1:r._originalIpc?!1:u.host===r._originalHostOrSocketPath;(!L||r._originalSecure&&!f)&&(delete c.headers.authorization,delete c.headers.cookie,L||delete c.headers.host,c.auth=void 0)}c.auth&&!a.headers.authorization&&(a.headers.authorization="Basic "+Buffer.from(c.auth).toString("base64")),D=r._req=v(c),r._redirects&&r.emit("redirect",r.url,D)}else D=r._req=v(c);c.timeout&&D.on("timeout",()=>{ge(r,D,"Opening handshake has timed out")}),D.on("error",L=>{D===null||D[Ho]||(D=r._req=null,er(r,L))}),D.on("response",L=>{let F=L.headers.location,$=L.statusCode;if(F&&c.followRedirects&&$>=300&&$<400){if(++r._redirects>c.maxRedirects){ge(r,D,"Maximum redirects exceeded");return}D.abort();let oe;try{oe=new ts(F,e)}catch{let Z=new SyntaxError(`Invalid URL: ${F}`);er(r,Z);return}jo(r,oe,i,a)}else r.emit("unexpected-response",D,L)||ge(r,D,`Unexpected server response: ${L.statusCode}`)}),D.on("upgrade",(L,F,$)=>{if(r.emit("upgrade",L),r.readyState!==G.CONNECTING)return;D=r._req=null;let oe=L.headers.upgrade;if(oe===void 0||oe.toLowerCase()!=="websocket"){ge(r,F,"Invalid Upgrade header");return}let ee=Nu("sha1").update(y+Ou).digest("base64");if(L.headers["sec-websocket-accept"]!==ee){ge(r,F,"Invalid Sec-WebSocket-Accept header");return}let Z=L.headers["sec-websocket-protocol"],P;if(Z!==void 0?S.size?S.has(Z)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":S.size&&(P="Server sent no subprotocol"),P){ge(r,F,P);return}Z&&(r._protocol=Z);let U=L.headers["sec-websocket-extensions"];if(U!==void 0){if(!A){ge(r,F,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let j;try{j=Gu(U)}catch{ge(r,F,"Invalid Sec-WebSocket-Extensions header");return}let ae=Object.keys(j);if(ae.length!==1||ae[0]!==$e.extensionName){ge(r,F,"Server indicated an extension that was not requested");return}try{A.accept(j[$e.extensionName])}catch{ge(r,F,"Invalid Sec-WebSocket-Extensions header");return}r._extensions[$e.extensionName]=A}r.setSocket(F,$,{allowSynchronousEvents:c.allowSynchronousEvents,generateMask:c.generateMask,maxPayload:c.maxPayload,skipUTF8Validation:c.skipUTF8Validation})}),c.finishRequest?c.finishRequest(D,r):D.end()}function er(r,e){r._readyState=G.CLOSING,r._errorEmitted=!0,r.emit("error",e),r.emitClose()}function Wu(r){return r.path=r.socketPath,Ko.connect(r)}function Ju(r){return r.path=void 0,!r.servername&&r.servername!==""&&(r.servername=Ko.isIP(r.host)?"":r.host),Du.connect(r)}function ge(r,e,i){r._readyState=G.CLOSING;let a=new Error(i);Error.captureStackTrace(a,ge),e.setHeader?(e[Ho]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(er,r,a)):(e.destroy(a),e.once("error",r.emit.bind(r,"error")),e.once("close",r.emitClose.bind(r)))}function ss(r,e,i){if(e){let a=Bu(e)?e.size:Hu(e).length;r._socket?r._sender._bufferedBytes+=a:r._bufferedAmount+=a}if(i){let a=new Error(`WebSocket is not open: readyState ${r.readyState} (${Ge[r.readyState]})`);process.nextTick(i,a)}}function Vu(r,e){let i=this[ne];i._closeFrameReceived=!0,i._closeMessage=e,i._closeCode=r,i._socket[ne]!==void 0&&(i._socket.removeListener("data",tr),process.nextTick(Wo,i._socket),r===1005?i.close():i.close(r,e))}function Xu(){let r=this[ne];r.isPaused||r._socket.resume()}function Yu(r){let e=this[ne];e._socket[ne]!==void 0&&(e._socket.removeListener("data",tr),process.nextTick(Wo,e._socket),e.close(r[qu])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",r))}function Uo(){this[ne].emitClose()}function $u(r,e){this[ne].emit("message",r,e)}function Zu(r){let e=this[ne];e._autoPong&&e.pong(r,!this._isServer,Go),e.emit("ping",r)}function Qu(r){this[ne].emit("pong",r)}function Wo(r){r.resume()}function ef(r){let e=this[ne];e.readyState!==G.CLOSED&&(e.readyState===G.OPEN&&(e._readyState=G.CLOSING,Jo(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",r)))}function Jo(r){r._closeTimer=setTimeout(r._socket.destroy.bind(r._socket),r._closeTimeout)}function Vo(){let r=this[ne];if(this.removeListener("close",Vo),this.removeListener("data",tr),this.removeListener("end",Xo),r._readyState=G.CLOSING,!this._readableState.endEmitted&&!r._closeFrameReceived&&!r._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);r._receiver.write(e)}r._receiver.end(),this[ne]=void 0,clearTimeout(r._closeTimer),r._receiver._writableState.finished||r._receiver._writableState.errorEmitted?r.emitClose():(r._receiver.on("error",Uo),r._receiver.on("finish",Uo))}function tr(r){this[ne]._receiver.write(r)||this.pause()}function Xo(){let r=this[ne];r._readyState=G.CLOSING,r._receiver.end(),this.end()}function Yo(){let r=this[ne];this.removeListener("error",Yo),this.on("error",Go),r&&(r._readyState=G.CLOSING,this.destroy())}});var ta=de((Mg,ea)=>{"use strict";var Bg=nr(),{Duplex:tf}=X("stream");function Zo(r){r.emit("close")}function nf(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Qo(r){this.removeListener("error",Qo),this.destroy(),this.listenerCount("error")===0&&this.emit("error",r)}function rf(r,e){let i=!0,a=new tf({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return r.on("message",function(u,f){let h=!f&&a._readableState.objectMode?u.toString():u;a.push(h)||r.pause()}),r.once("error",function(u){a.destroyed||(i=!1,a.destroy(u))}),r.once("close",function(){a.destroyed||a.push(null)}),a._destroy=function(c,u){if(r.readyState===r.CLOSED){u(c),process.nextTick(Zo,a);return}let f=!1;r.once("error",function(m){f=!0,u(m)}),r.once("close",function(){f||u(c),process.nextTick(Zo,a)}),i&&r.terminate()},a._final=function(c){if(r.readyState===r.CONNECTING){r.once("open",function(){a._final(c)});return}r._socket!==null&&(r._socket._writableState.finished?(c(),a._readableState.endEmitted&&a.destroy()):(r._socket.once("finish",function(){c()}),r.close()))},a._read=function(){r.isPaused&&r.resume()},a._write=function(c,u,f){if(r.readyState===r.CONNECTING){r.once("open",function(){a._write(c,u,f)});return}r.send(c,f)},a.on("end",nf),a.on("error",Qo),a}ea.exports=rf});var is=de((Og,na)=>{"use strict";var{tokenChars:sf}=At();function of(r){let e=new Set,i=-1,a=-1,c=0;for(c;c<r.length;c++){let f=r.charCodeAt(c);if(a===-1&&sf[f]===1)i===-1&&(i=c);else if(c!==0&&(f===32||f===9))a===-1&&i!==-1&&(a=c);else if(f===44){if(i===-1)throw new SyntaxError(`Unexpected character at index ${c}`);a===-1&&(a=c);let h=r.slice(i,a);if(e.has(h))throw new SyntaxError(`The "${h}" subprotocol is duplicated`);e.add(h),i=a=-1}else throw new SyntaxError(`Unexpected character at index ${c}`)}if(i===-1||a!==-1)throw new SyntaxError("Unexpected end of input");let u=r.slice(i,c);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);return e.add(u),e}na.exports={parse:of}});var xa=de((qg,ca)=>{"use strict";var af=X("events"),rr=X("http"),{Duplex:zg}=X("stream"),{createHash:cf}=X("crypto"),ra=Zn(),at=Et(),xf=is(),uf=nr(),{CLOSE_TIMEOUT:ff,GUID:df,kWebSocket:lf}=Fe(),hf=/^[+/0-9A-Za-z]{22}==$/,sa=0,ia=1,aa=2,os=class extends af{constructor(e,i){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:ff,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:uf,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=rr.createServer((a,c)=>{let u=rr.STATUS_CODES[426];c.writeHead(426,{"Content-Length":u.length,"Content-Type":"text/plain"}),c.end(u)}),this._server.listen(e.port,e.host,e.backlog,i)):e.server&&(this._server=e.server),this._server){let a=this.emit.bind(this,"connection");this._removeListeners=gf(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(c,u,f)=>{this.handleUpgrade(c,u,f,a)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=sa}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===aa){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Qt,this);return}if(e&&this.once("close",e),this._state!==ia)if(this._state=ia,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(Qt,this):process.nextTick(Qt,this);else{let i=this._server;this._removeListeners(),this._removeListeners=this._server=null,i.close(()=>{Qt(this)})}}shouldHandle(e){if(this.options.path){let i=e.url.indexOf("?");if((i!==-1?e.url.slice(0,i):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,i,a,c){i.on("error",oa);let u=e.headers["sec-websocket-key"],f=e.headers.upgrade,h=+e.headers["sec-websocket-version"];if(e.method!=="GET"){ct(this,e,i,405,"Invalid HTTP method");return}if(f===void 0||f.toLowerCase()!=="websocket"){ct(this,e,i,400,"Invalid Upgrade header");return}if(u===void 0||!hf.test(u)){ct(this,e,i,400,"Missing or invalid Sec-WebSocket-Key header");return}if(h!==13&&h!==8){ct(this,e,i,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){en(i,400);return}let m=e.headers["sec-websocket-protocol"],_=new Set;if(m!==void 0)try{_=xf.parse(m)}catch{ct(this,e,i,400,"Invalid Sec-WebSocket-Protocol header");return}let y=e.headers["sec-websocket-extensions"],v={};if(this.options.perMessageDeflate&&y!==void 0){let S=new at({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let A=ra.parse(y);A[at.extensionName]&&(S.accept(A[at.extensionName]),v[at.extensionName]=S)}catch{ct(this,e,i,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${h===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(A,D,L,F)=>{if(!A)return en(i,D||401,L,F);this.completeUpgrade(v,u,_,e,i,a,c)});return}if(!this.options.verifyClient(S))return en(i,401)}this.completeUpgrade(v,u,_,e,i,a,c)}completeUpgrade(e,i,a,c,u,f,h){if(!u.readable||!u.writable)return u.destroy();if(u[lf])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>sa)return en(u,503);let _=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${cf("sha1").update(i+df).digest("base64")}`],y=new this.options.WebSocket(null,void 0,this.options);if(a.size){let v=this.options.handleProtocols?this.options.handleProtocols(a,c):a.values().next().value;v&&(_.push(`Sec-WebSocket-Protocol: ${v}`),y._protocol=v)}if(e[at.extensionName]){let v=e[at.extensionName].params,S=ra.format({[at.extensionName]:[v]});_.push(`Sec-WebSocket-Extensions: ${S}`),y._extensions=e}this.emit("headers",_,c),u.write(_.concat(`\r
|
|
12
12
|
`).join(`\r
|
|
13
|
-
`)),
|
|
14
|
-
`+Object.keys(
|
|
13
|
+
`)),u.removeListener("error",oa),y.setSocket(u,f,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(y),y.on("close",()=>{this.clients.delete(y),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Qt,this)})),h(y,c)}};ca.exports=os;function gf(r,e){for(let i of Object.keys(e))r.on(i,e[i]);return function(){for(let a of Object.keys(e))r.removeListener(a,e[a])}}function Qt(r){r._state=aa,r.emit("close")}function oa(){this.destroy()}function en(r,e,i,a){i=i||rr.STATUS_CODES[e],a={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(i),...a},r.once("finish",r.destroy),r.end(`HTTP/1.1 ${e} ${rr.STATUS_CODES[e]}\r
|
|
14
|
+
`+Object.keys(a).map(c=>`${c}: ${a[c]}`).join(`\r
|
|
15
15
|
`)+`\r
|
|
16
16
|
\r
|
|
17
|
-
`+
|
|
17
|
+
`+i)}function ct(r,e,i,a,c,u){if(r.listenerCount("wsClientError")){let f=new Error(c);Error.captureStackTrace(f,ct),r.emit("wsClientError",f,i,e)}else en(i,a,c,u)}});import{spawn as Of}from"node:child_process";import{existsSync as zf,openSync as qf}from"node:fs";import{mkdir as Ff}from"node:fs/promises";import{dirname as Uf}from"node:path";import{fileURLToPath as Kf}from"node:url";function xs(r=H()){return zf(r.libEntry)?r.libEntry:Kf(new URL("../index.ts",import.meta.url))}async function Ca(r={}){let e=r.paths??H(),i=r.entryOverride??xs(e);await Ff(Uf(e.logFile),{recursive:!0});let a=qf(e.logFile,"a"),u=i.endsWith(".ts")?["--import","tsx/esm",i,"--daemon"]:[i,"--daemon"],f=Of(process.execPath,u,{detached:!0,stdio:["ignore",a,a],env:{...process.env,COZE_BRIDGE_DAEMON:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Gf.info("daemon spawned",{pid:f.pid,entry:i}),{pid:f.pid,entry:i}}var Gf,us=Me(()=>{"use strict";K();le();Gf=N("spawn-daemon")});import{spawn as $f}from"node:child_process";import{mkdir as Zf,unlink as Qf,writeFile as ed}from"node:fs/promises";import{dirname as td,join as nd}from"node:path";function xr(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Pa(r,e){return new Promise((i,a)=>{let c=$f(r,e,{stdio:["ignore","pipe","pipe"]}),u="";c.stderr?.on("data",f=>{u+=f.toString("utf8")}),c.on("error",a),c.on("close",f=>{f===0?i():a(new Error(`${r} ${e.join(" ")} exited ${f}: ${u.trim()}`))})})}var cr,ls,hs,Da=Me(()=>{"use strict";K();cr=N("supervisor.launchd"),ls="ai.coze.bridge",hs={platform:"darwin",renderConfig(r){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
18
18
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
19
19
|
<plist version="1.0">
|
|
20
20
|
<dict>
|
|
21
21
|
<key>Label</key>
|
|
22
|
-
<string>${
|
|
22
|
+
<string>${ls}</string>
|
|
23
23
|
<key>ProgramArguments</key>
|
|
24
24
|
<array>
|
|
25
|
-
<string>${
|
|
26
|
-
<string>${
|
|
25
|
+
<string>${xr(r.nodeBin)}</string>
|
|
26
|
+
<string>${xr(r.entry)}</string>
|
|
27
27
|
<string>--daemon</string>
|
|
28
28
|
</array>
|
|
29
29
|
<key>RunAtLoad</key>
|
|
@@ -33,68 +33,68 @@ var va=Object.create;var Ln=Object.defineProperty;var ka=Object.getOwnPropertyDe
|
|
|
33
33
|
<key>ThrottleInterval</key>
|
|
34
34
|
<integer>10</integer>
|
|
35
35
|
<key>StandardOutPath</key>
|
|
36
|
-
<string>${
|
|
36
|
+
<string>${xr(r.logFile)}</string>
|
|
37
37
|
<key>StandardErrorPath</key>
|
|
38
|
-
<string>${
|
|
38
|
+
<string>${xr(r.logFile)}</string>
|
|
39
39
|
</dict>
|
|
40
40
|
</plist>
|
|
41
|
-
`},configPath(
|
|
41
|
+
`},configPath(r){return nd(r.homeDir,"Library","LaunchAgents",`${ls}.plist`)},async install(r){let e=this.configPath(r);await Zf(td(e),{recursive:!0}),await ed(e,this.renderConfig(r),"utf8"),cr.info("plist written",{plistPath:e}),await Pa("launchctl",["load","-w",e]),cr.info("launchd job loaded",{label:ls})},async uninstall(r){let e=this.configPath(r);await Pa("launchctl",["unload","-w",e]).catch(i=>cr.warn("launchctl unload failed (ignored)",{err:String(i)})),await Qf(e).catch(i=>{if(i.code!=="ENOENT")throw i}),cr.info("launchd job removed",{plistPath:e})}}});import{spawn as rd}from"node:child_process";import{mkdir as sd,unlink as id,writeFile as od}from"node:fs/promises";import{dirname as ad,join as cd}from"node:path";function dr(r,e){return new Promise((i,a)=>{let c=rd(r,e,{stdio:["ignore","pipe","pipe"]}),u="";c.stderr?.on("data",f=>{u+=f.toString("utf8")}),c.on("error",a),c.on("close",f=>{f===0?i():a(new Error(`${r} ${e.join(" ")} exited ${f}: ${u.trim()}`))})})}var ur,fr,gs,Ta=Me(()=>{"use strict";K();ur=N("supervisor.systemd"),fr="coze-bridge.service",gs={platform:"linux",renderConfig(r){return`[Unit]
|
|
42
42
|
Description=Coze Bridge daemon
|
|
43
43
|
After=network.target
|
|
44
44
|
|
|
45
45
|
[Service]
|
|
46
46
|
Type=simple
|
|
47
|
-
ExecStart=${
|
|
47
|
+
ExecStart=${r.nodeBin} ${r.entry} --daemon
|
|
48
48
|
Restart=always
|
|
49
49
|
RestartSec=3
|
|
50
|
-
StandardOutput=append:${
|
|
51
|
-
StandardError=append:${
|
|
50
|
+
StandardOutput=append:${r.logFile}
|
|
51
|
+
StandardError=append:${r.logFile}
|
|
52
52
|
|
|
53
53
|
[Install]
|
|
54
54
|
WantedBy=default.target
|
|
55
|
-
`},configPath(
|
|
55
|
+
`},configPath(r){return cd(r.homeDir,".config","systemd","user",fr)},async install(r){let e=this.configPath(r);await sd(ad(e),{recursive:!0}),await od(e,this.renderConfig(r),"utf8"),ur.info("systemd unit written",{unitPath:e}),await dr("systemctl",["--user","daemon-reload"]),await dr("systemctl",["--user","enable","--now",fr]),ur.info("systemd unit enabled",{unitName:fr})},async uninstall(r){let e=this.configPath(r);await dr("systemctl",["--user","disable","--now",fr]).catch(i=>ur.warn("systemctl disable failed (ignored)",{err:String(i)})),await id(e).catch(i=>{if(i.code!=="ENOENT")throw i}),await dr("systemctl",["--user","daemon-reload"]).catch(()=>{}),ur.info("systemd unit removed",{unitPath:e})}}});import{spawn as xd}from"node:child_process";import{join as ud}from"node:path";function Na(r,e){return new Promise((i,a)=>{let c=xd(r,e,{stdio:["ignore","pipe","pipe"],shell:!1}),u="";c.stderr?.on("data",f=>{u+=f.toString("utf8")}),c.on("error",a),c.on("close",f=>{f===0?i():a(new Error(`${r} ${e.join(" ")} exited ${f}: ${u.trim()}`))})})}var ps,lr,ms,La=Me(()=>{"use strict";K();ps=N("supervisor.taskscheduler"),lr="CozeBridge",ms={platform:"win32",renderConfig(r){return`<?xml version="1.0" encoding="UTF-16"?>
|
|
56
56
|
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
57
57
|
<RegistrationInfo>
|
|
58
58
|
<Description>Coze Bridge daemon</Description>
|
|
59
59
|
</RegistrationInfo>
|
|
60
60
|
<Triggers>
|
|
61
61
|
<LogonTrigger>
|
|
62
|
-
<UserId>${
|
|
62
|
+
<UserId>${r.userName}</UserId>
|
|
63
63
|
</LogonTrigger>
|
|
64
64
|
</Triggers>
|
|
65
65
|
<Principals>
|
|
66
66
|
<Principal>
|
|
67
|
-
<UserId>${
|
|
67
|
+
<UserId>${r.userName}</UserId>
|
|
68
68
|
<LogonType>InteractiveToken</LogonType>
|
|
69
69
|
<RunLevel>LeastPrivilege</RunLevel>
|
|
70
70
|
</Principal>
|
|
71
71
|
</Principals>
|
|
72
72
|
<Actions>
|
|
73
73
|
<Exec>
|
|
74
|
-
<Command>${
|
|
75
|
-
<Arguments>"${
|
|
74
|
+
<Command>${r.nodeBin}</Command>
|
|
75
|
+
<Arguments>"${r.entry}" --daemon</Arguments>
|
|
76
76
|
</Exec>
|
|
77
77
|
</Actions>
|
|
78
78
|
</Task>
|
|
79
|
-
`},configPath(
|
|
79
|
+
`},configPath(r){return ud(r.homeDir,".coze","bridge","task.xml")},async install(r){let e=`"${r.nodeBin}" "${r.entry}" --daemon`;await Na("schtasks",["/Create","/SC","ONLOGON","/TN",lr,"/TR",e,"/RU",r.userName,"/F"]),ps.info("task scheduler entry created",{task:lr})},async uninstall(r){await Na("schtasks",["/Delete","/TN",lr,"/F"]).catch(e=>ps.warn("schtasks /Delete failed (ignored)",{err:String(e)})),ps.info("task scheduler entry removed",{task:lr})}}});var _s={};Ks(_s,{buildContext:()=>hd,getSupervisor:()=>ld,launchdSupervisor:()=>hs,systemdSupervisor:()=>gs,taskSchedulerSupervisor:()=>ms});import{homedir as fd,userInfo as dd}from"node:os";function ld(r=process.platform){switch(r){case"darwin":return hs;case"linux":return gs;case"win32":return ms;default:throw new Error(`unsupported platform for OS supervisor: ${r}`)}}function hd(){let r=H();return{nodeBin:process.execPath,entry:xs(r),logFile:r.logFile,homeDir:fd(),userName:dd().username}}var ws=Me(()=>{"use strict";le();us();Da();Ta();La()});Je();K();import{readdir as V0}from"node:fs/promises";import{mkdir as G0,writeFile as H0}from"node:fs/promises";import{join as j0}from"node:path";var W0={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function pt(r,e,i,a){await G0(r,{recursive:!0});let c=W0[e],u=j0(r,c),f=J0(e,i,a);return await H0(u,f,"utf8"),u}function J0(r,e,i){let a=`# Coze Agent: ${e}
|
|
80
80
|
|
|
81
|
-
> framework: \`${
|
|
81
|
+
> framework: \`${r}\`
|
|
82
82
|
|
|
83
|
-
`,
|
|
84
|
-
`)?
|
|
83
|
+
`,c=i?.trim()?i.endsWith(`
|
|
84
|
+
`)?i:`${i}
|
|
85
85
|
`:`_No instructions provided._
|
|
86
|
-
`;return`${
|
|
86
|
+
`;return`${a}---
|
|
87
87
|
|
|
88
|
-
${
|
|
89
|
-
`)}}function zn(n){return`coze-session-${n.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function As(n,e){if(!n.modelToken)return null;let t=n.model||ne,r=$n(e),s={baseUrl:`${Un}/v1`,api:"openai-completions",apiKey:n.modelToken,models:[{id:t,name:t,reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128e3,maxTokens:8192,api:"openai-completions"}]};return Object.keys(r).length>0&&(s.headers=r),s}function Cs(n,e){if(!n.modelToken)return[];let t=$n(e),r=[];for(let[s,i]of Object.entries(t))r.push("-c",`model_providers.coze.http_headers.${s}="${i}"`);return r}var M=w("agent-handlers"),bs=5*1024*1024,Za=1,ec=6,tc=new Set(["node_modules",".git",".coze","dist","build",".next"]),Ut=class{constructor(e){this.opts=e}opts;async listSkills(e){ce(e._meta,"_agent/listSkills");let t=Be(e._meta),r=await this.loadAgentCfg(t),s=r?.workspace??ae(t).workspace,i=r?.skills??[],o=[];for(let a of i){let c=re(s,a.relPath,"SKILL.md");await Ka(c).then(d=>d.isFile()).catch(()=>!1)&&o.push(oc(a))}return{skills:o}}async addSkills(e){ce(e._meta,"_agent/addSkills");let t=Be(e._meta),r=await this.requireAgentCfg(t),s=e.skills??[],i=[...r.skills??[]],o=new Map(i.map((c,l)=>[c.skillId,l])),a=[];for(let c of s){let l=await Gn({agentId:t,workspace:r.workspace,framework:r.framework,skill:c});Hn(i,o,l),a.push(c)}return await Nt(t,i),await this.reloadAgentSessions(t,"skills-added"),{installedSkills:a}}async removeSkills(e){ce(e._meta,"_agent/removeSkills");let t=Be(e._meta),r=await this.requireAgentCfg(t),s=new Set(e.skillIds??[]),i=r.skills??[],o=[];for(let a of i){if(!s.has(a.skillId)){o.push(a);continue}let c=re(r.workspace,a.relPath);await Qa(c,{recursive:!0,force:!0}),M.info("skill removed",{agentId:t,skillId:a.skillId,relPath:a.relPath})}return await Nt(t,o),await this.reloadAgentSessions(t,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,t){return this.reloadAgentSessions(e,t)}async reloadAgentSessions(e,t){let r=this.opts.agents.get(e);if(r&&r.framework!=="codex"){for(let[s,i]of r.sessions)if(!(!i.downstream||!i.acpSessionId)){i.loadingSession=!0;try{await i.downstream.sessionLoad({sessionId:i.acpSessionId,cwd:r.workspace}),M.info("session reloaded",{reason:t,agentId:e,framework:r.framework,cloudId:s,acpId:i.acpSessionId})}catch(o){M.warn("session reload failed",{reason:t,agentId:e,framework:r.framework,cloudId:s,acpId:i.acpSessionId,err:String(o)})}finally{i.loadingSession=!1}}}}async updateAgent(e){if(!e.cozeIdentity?.trim())return M.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let t=e.agentId,r=await q(t);if(!r)throw new h("AGENT_NOT_FOUND",`agent not found: ${t}`);return r.cozeIdentity===e.cozeIdentity?(M.info("_agent/update: cozeIdentity unchanged, noop",{agentId:t}),{ok:!0}):(r.cozeIdentity=e.cozeIdentity,await X(r),await Me(r.workspace,r.framework,t,e.cozeIdentity),M.info("_agent/update: cozeIdentity rewritten",{agentId:t,framework:r.framework}),await this.reloadAgentSessions(t,"identity-changed"),{ok:!0})}async disconnectAgent(e){let t=e.agentId;if(!t)throw new h("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let r=await q(t);return r?(r.disconnectedAt=Date.now(),r.disconnectReason=e.reason??"",await X(r),M.info("agent disconnected",{agentId:t,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(t,e.reason??"disconnect"),{ok:!0}):(M.warn("_agent/disconnect: agent not found, ignoring",{agentId:t}),{ok:!0})}async switchModel(e){if(ce(e._meta,"_agent/switchModel"),!e.agentId)throw new h("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let t=e.model?.trim()?e.model:ne,r=await q(e.agentId);if(!r)throw new h("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);r.model=t,await X(r),M.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:t,reason:e.reason??""});let s=this.opts.agents.get(e.agentId);if(!s)return M.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};s.model=t;let i=[];for(let[o,a]of s.allSessionQueues())i.push(a.enqueue(async()=>{let c=s.sessions.get(o);c?.downstream&&(await c.downstream.stop(`switchModel: ${t}`).catch(()=>{}),c.downstream=void 0)}));return await Promise.all(i),M.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:t,cloudSessions:i.length}),{ok:!0}}async resetAgent(e){if(ce(e._meta,te.RESET),!e.agentId)throw new h("IPC_BAD_REQUEST",`${te.RESET}: missing agentId`);return await this.runDetailSync(e.agentId,te.RESET,e.reason),{ok:!0}}async repairAgent(e){if(ce(e._meta,te.REPAIR),!e.agentId)throw new h("IPC_BAD_REQUEST",`${te.REPAIR}: missing agentId`);let t=await this.loadAgentCfg(e.agentId);if(t&&t.framework!=="openclaw")throw new h("IPC_BAD_REQUEST",`${te.REPAIR} only allowed for openclaw, got ${t.framework}`);if(t&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,t.workspace)}catch(r){M.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(r)})}return await this.runDetailSync(e.agentId,te.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,t,r){if(!this.opts.detailSyncer){M.warn("detailSyncer not wired, skipping sync",{method:t,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(s){M.warn("detail sync failed (ignored)",{method:t,agentId:e,reason:r,err:String(s)})}}async getFileTree(e){ce(e._meta,"_agent/getFileTree");let t=e._meta,r=Be(t),s=await this.resolveWorkspace(r),i=e.filePath??"",o=this.safeJoin(s,i),a=await qn(o).catch(()=>null);if(!a)throw new h("IPC_BAD_REQUEST",`path not found: ${i}`);if(a.isSymbolicLink())throw new h("IPC_BAD_REQUEST",`symlink not allowed: ${i}`);let c=fc(e.depth);return a.isDirectory()?{tree:await Bs(s,o,i,c)}:{tree:[{name:hc(i),path:Fs(i||"."),isDir:!1,size:a.size,modifiedAt:Math.floor(a.mtimeMs)}]}}async getFileContent(e){ce(e._meta,"_agent/getFileContent");let t=Be(e._meta),r=await this.resolveWorkspace(t);if(!e.filePath)throw new h("IPC_BAD_REQUEST","filePath required");let s=this.safeJoin(r,e.filePath),i=await qn(s).catch(()=>null);if(!i||!i.isFile())throw new h("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(i.isSymbolicLink())throw new h("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(i.size>bs)throw new h("IPC_BAD_REQUEST",`file too large: ${i.size} bytes (max ${bs})`);let o=await Ds(s);return o.includes(0)?{content:o.toString("base64"),encoding:"base64",size:i.size}:{content:o.toString("utf8"),encoding:"utf-8",size:i.size}}async resolveWorkspace(e){let t=this.opts.agents.get(e);return t?t.workspace:(await q(e).catch(()=>null))?.workspace??ae(e).workspace}safeJoin(e,t){let r=Ya(e,t||"."),s=Ls(e,r);if(s.startsWith("..")||s===".."||s.startsWith(`..${Ms}`))throw new h("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return r}loadAgentCfg(e){return q(e)}async requireAgentCfg(e){let t=await this.loadAgentCfg(e);if(!t)throw new h("AGENT_NOT_FOUND",`no config for agent: ${e}`);return t}};function nc(n){let e=st(n.trim()).replace(/^-+|-+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new h("IPC_BAD_REQUEST",`invalid skill name: ${n}`);return e}function rc(n){return n==="claude-code"?re(".claude","skills"):re(".agents","skills")}var sc=3e4,ic=50*1024*1024,$t=3e4;async function Gn(n){let{agentId:e,workspace:t,framework:r,skill:s}=n;if(!s.skillName)throw new h("IPC_BAD_REQUEST","skill missing skillName");let i=typeof s.content=="string"&&s.content.length>0,o=typeof s.downloadUrl=="string"&&s.downloadUrl.length>0;if(!i&&!o)throw new h("IPC_BAD_REQUEST",`skill ${s.skillId} missing both content and downloadUrl`);let a=nc(s.skillName),c=rc(r),l=re(c,a),d=re(t,l);if(await Ja(d,{recursive:!0}),i){let u=Buffer.from(s.content,"utf8");it(u.length),await Os(re(d,"SKILL.md"),u,"utf8")}else{let u=await ac(s.downloadUrl);lc(u)?await dc(u,d):await Os(re(d,"SKILL.md"),u.toString("utf8"),"utf8")}let f={skillId:s.skillId,skillName:s.skillName,relPath:l,installedAt:Date.now(),...s.description?{description:s.description}:{},...s.icon?{icon:s.icon}:{},...s.version?{version:s.version}:{},...s.downloadUrl?{downloadUrl:s.downloadUrl}:{},...s.config?{config:s.config}:{},...s.builtin?{builtin:s.builtin}:{}};return M.info("skill installed",{agentId:e,skillId:s.skillId,skillName:s.skillName,relPath:l,source:i?"content":"downloadUrl"}),f}function Hn(n,e,t){let r=e.get(t.skillId);if(r!==void 0){n[r]=t;return}e.set(t.skillId,n.length),n.push(t)}function oc(n){return{skillId:n.skillId,skillName:n.skillName,...n.description?{description:n.description}:{},...n.icon?{icon:n.icon}:{},...n.version?{version:n.version}:{},...n.config?{config:n.config}:{},...n.builtin?{builtin:n.builtin}:{}}}async function ac(n){if(!n)throw new h("IPC_BAD_REQUEST","skill missing downloadUrl");if(n.startsWith("data:")){let e=Math.floor(n.length*3/4);it(e);let t=cc(n);return it(t.length),t}if(n.startsWith("file:")){let e=new URL(n).pathname,t=await Ds(e);return it(t.length),t}if(n.startsWith("http://")||n.startsWith("https://")){let e=new AbortController,t=setTimeout(()=>e.abort(),sc);try{let r=await fetch(n,{signal:e.signal});if(!r.ok)throw new h("IPC_BAD_REQUEST",`fetch skill failed HTTP ${r.status} ${n}`);let s=await r.arrayBuffer();return it(s.byteLength),Buffer.from(s)}finally{clearTimeout(t)}}throw new h("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${n.slice(0,80)}`)}function it(n){if(n>ic)throw new h("IPC_BAD_REQUEST",`skill too large: ${n} bytes`)}function cc(n){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(n);if(!e)throw new h("IPC_BAD_REQUEST","bad data URL");let t=!!e[2],r=e[3]??"";return t?Buffer.from(r,"base64"):Buffer.from(decodeURIComponent(r),"utf8")}function lc(n){return n.length>=2&&n[0]===31&&n[1]===139}async function dc(n,e){await uc(n),await new Promise((t,r)=>{let s=Ns("tar",["-xzf","-","-C",e,"--strip-components=1","--no-same-owner"],{stdio:["pipe","pipe","pipe"]}),i="";s.stderr?.on("data",a=>{i+=String(a)});let o=setTimeout(()=>{s.kill("SIGKILL"),r(new h("IPC_BAD_REQUEST",`tar extract timeout (${$t}ms)`))},$t);s.on("error",a=>{clearTimeout(o),r(new h("IPC_BAD_REQUEST",`tar spawn failed: ${a.message}`,{cause:a}))}),s.on("exit",a=>{clearTimeout(o),a===0?t():r(new h("IPC_BAD_REQUEST",`tar exit ${a}${i?`: ${i.trim().slice(0,200)}`:""}`))}),s.stdin?.end(n)})}async function uc(n){let e=await new Promise((t,r)=>{let s=Ns("tar",["-tzvf","-"],{stdio:["pipe","pipe","pipe"]}),i="",o="";s.stdout?.on("data",c=>{i+=String(c)}),s.stderr?.on("data",c=>{o+=String(c)});let a=setTimeout(()=>{s.kill("SIGKILL"),r(new h("IPC_BAD_REQUEST",`tar list timeout (${$t}ms)`))},$t);s.on("error",c=>{clearTimeout(a),r(new h("IPC_BAD_REQUEST",`tar list spawn failed: ${c.message}`))}),s.on("exit",c=>{clearTimeout(a),c===0?t(i):r(new h("IPC_BAD_REQUEST",`tar list exit ${c}${o?`: ${o.trim().slice(0,200)}`:""}`))}),s.stdin?.end(n)});for(let t of e.split(`
|
|
90
|
-
`)){let
|
|
91
|
-
`)[0]?.trim()||void 0}catch{return}}async function
|
|
92
|
-
`}var
|
|
93
|
-
`);this.buffer=t.pop()??"";let r=[];for(let s of t){let i=s.replace(/\r$/,"").trim();if(i)try{r.push(JSON.parse(i))}catch(o){this.onError?.({line:i,error:o})}}return r}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(t){return this.onError?.({line:e,error:t}),[]}}};var Js={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission",initialize:"initialize"},Dg=Object.fromEntries(Object.entries(Js).map(([n,e])=>[e,n])),Ic={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"agent.pair":[],initialize:[]},Ue=class{seq=0;next(e,t){this.seq+=1;let r=Js[e]??xc(e),s=Ic[r]??[],i=[r,String(this.seq)];if(s.length>0){let o=s.map(c=>js(t?.[c]??"")),a=Tc(o).join(":");a&&i.push(a)}else t&&Object.values(t).some(o=>o)&&i.push(Object.values(t).filter(Boolean).map(o=>js(String(o))).join(":"));return i.join("_")}reset(){this.seq=0}};function xc(n){return n.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function js(n){return n.replace(/[:_\s]+/g,"-")}function Tc(n){let e=n.length;for(;e>0&&!n[e-1];)e-=1;return n.slice(0,e)}k();var Pc=3e4,Ac=50,Cc=20,Vs=500;function Oc(n){try{let e=JSON.stringify(n);return e===void 0||e.length<=Vs?n:`${e.slice(0,Vs)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Qs(n,e){if(!(typeof n!="number"||n<=0))try{process.platform==="win32"?process.kill(n,e):process.kill(-n,e)}catch{}}var pe=class{constructor(e){this.opts=e;this.log=w(`downstream.${this.constructor.name}`),this.decoder=new Qt({onError:t=>this.log.warn("decode line failed",{line:t.line})})}opts;child;decoder;pending=new Map;idAllocator=new Ue;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new h("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",t=Rc(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:{...this.sanitizeEnv(process.env),...this.opts.env},stdio:["pipe","pipe","pipe"],detached:e});this.child=t,t.stdout?.setEncoding("utf8"),t.stdout?.on("data",r=>{for(let s of this.decoder.push(r))this.dispatch(s)}),t.stderr?.setEncoding("utf8"),t.stderr?.on("data",r=>{let s=r.trimEnd();this.stderrRing.push(s),this.stderrRing.length>Ac&&this.stderrRing.shift(),this.log.debug("stderr",{text:s})}),t.on("exit",(r,s)=>{this.stopped=!0,(r!==0||s!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:r,signal:s,recentStderr:this.stderrRing.slice(-Cc)}),this.failAllPending(new h("AGENT_PROTOCOL_ERROR",`agent exited (${r}/${s})`));for(let o of this.exitHandlers)o(r,s)}),t.on("error",r=>{this.log.error("child error",{err:String(r)}),this.failAllPending(new h("AGENT_SPAWN_FAILED",String(r),{cause:r}))}),this.log.info("downstream started",{command:this.opts.command,pid:t.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.log.info("downstream stopping",{reason:e});let t=this.child,r=new Promise(i=>t.once("exit",()=>i()));Qs(t.pid,"SIGTERM");let s=setTimeout(()=>{t.killed||Qs(t.pid,"SIGKILL")},5e3);try{await r}finally{clearTimeout(s)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e){return this.call("session/prompt",e,0)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(jt("session/cancel",e))}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,t){if(!(!this.child||this.stopped))try{this.writeFrame(Fe(e,t))}catch(r){this.log.warn("respondAgentRequest write failed",{id:e,err:String(r)})}}respondAgentRequestError(e,t){if(!(!this.child||this.stopped))try{this.writeFrame(ve(e,t))}catch(r){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(r)})}}onExit(e){this.exitHandlers.push(e)}call(e,t,r=Pc){if(!this.child||this.stopped)return Promise.reject(new h("AGENT_PROTOCOL_ERROR","downstream not started"));let s=this.idAllocator.next(e),i=ct(s,e,t),o=r>0&&Number.isFinite(r);return new Promise((a,c)=>{let l=o?setTimeout(()=>{this.pending.delete(s),c(new h("AGENT_TIMEOUT",`${e} timed out after ${r}ms`))},r):null;this.pending.set(s,{resolve:a,reject:c,timer:l,method:e});try{this.writeFrame(i)}catch(d){l&&clearTimeout(l),this.pending.delete(s),c(d)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new h("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Ws(e))}dispatch(e){if(Vt(e)){let t=e.id!==null?this.pending.get(e.id):void 0;if(!t){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),t.timer&&clearTimeout(t.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:t.method,code:e.error.code,message:e.error.message,data:e.error.data}),t.reject(Hs(e.error))):(this.log.info("downstream returned result",{id:e.id,method:t.method,result:Oc(e.result)}),t.resolve(e.result));return}if(Gs(e)){if(e.method==="session/update")for(let t of this.updateHandlers)Promise.resolve(t(e.params)).catch(r=>this.log.warn("update handler failed",{err:String(r)}));else this.log.debug("unknown notification",{method:e.method});return}if(qs(e)){let t=e;this.handleAgentRequest(t).catch(r=>this.log.error("agent request handler failed",{method:t.method,err:String(r)}))}}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(ve(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}for(let t of this.agentRequestHandlers)try{await t(e)}catch(r){this.log.error("agentRequestHandler threw",{method:e.method,err:String(r)});try{this.writeFrame(ve(e.id,lt(r)))}catch{}}}failAllPending(e){for(let t of this.pending.values())t.timer&&clearTimeout(t.timer),t.reject(e);this.pending.clear()}};var bc="@agentclientprotocol/claude-agent-acp@latest";function Nc(n){let e={};for(let[t,r]of Object.entries(n))r!==void 0&&(t.startsWith("CLAUDE")||t==="AI_AGENT"||t==="BAGGAGE"||(e[t]=r));return e}var Kt=class extends pe{framework="claude-code";constructor(e){let t=Wt("claude-code"),[r,s]=t?[t,[]]:["npx",["-y",bc]],i=e.command??r,o=e.args??s,a={command:i,args:o,cwd:e.cwd,...e.env?{env:e.env}:{}};super(a)}sanitizeEnv(e){return Nc(e)}};import{mkdtempSync as Dc,rmSync as Lc}from"node:fs";import{tmpdir as Mc}from"node:os";import{join as Bc}from"node:path";var Fc="@zed-industries/codex-acp@latest",Xt=class extends pe{framework="codex";authMethodId;codexHomeDir;constructor(e){let t=Wt("codex"),[r,s]=t?[t,[]]:["npx",["-y",Fc]],i=e.command??r,o=e.args??s,a=e.extraArgs?[...o,...e.extraArgs]:o,c=e.isolateCodexHome?Dc(Bc(Mc(),"coze-bridge-codex-home-")):void 0,l=c?{...e.env??{},CODEX_HOME:c}:e.env,d={command:i,args:a,cwd:e.cwd,...l?{env:l}:{}};super(d),this.authMethodId=e.authMethodId,this.codexHomeDir=c}async initialize(e){let t=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),t}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Lc(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var dt=class extends pe{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let t=e.sessionName??"default",r=["acp","--session",`agent:${e.agentId}:${t}`];e.gatewayToken&&r.push("--token",e.gatewayToken);let s={command:e.command,args:r,cwd:e.cwd,...e.env?{env:e.env}:{}};super(s),this.agentId=e.agentId,this.sessionName=t,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.sessionPrompt({sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]}))}get acpSessionName(){return this.sessionName}};k();z();var $e=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((t,r)=>{this.slots.push({task:e,resolve:t,reject:r}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let t=await e.task();e.resolve(t)}catch(t){e.reject(t)}}}finally{this.running=!1}}}};var Yt=class{agentId;framework;workspace;deployType;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local"}getSessionQueue(e){let t=this.sessionQueues.get(e);return t||(t=new $e,this.sessionQueues.set(e,t)),t}allSessionQueues(){return this.sessionQueues.entries()}async dispose(e){this.status="stopped";let t=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let r of this.sessionQueues.values())r.dispose(t);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let t=[];for(let[,r]of this.sessions)ut(r),r.downstream&&(t.push(r.downstream.stop(e).catch(()=>{})),r.downstream=void 0);await Promise.all(t),this.activeTriggers.clear()}};function ut(n){n.idleTimer&&(clearTimeout(n.idleTimer),n.idleTimer=void 0)}import{spawn as Uc}from"node:child_process";import{homedir as $c}from"node:os";import{join as zc}from"node:path";At();k();async function Ys(){let n=zc($c(),".openclaw/openclaw.json");return(await Le(n))?.gateway?.auth?.token??""}var Ks=w("openclaw.config"),qc=[0,5e3,5e3],Xs="models.providers.",Zt="agents.defaults.models",en=class{command;env;retryDelaysMs;queue=new $e;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??qc}async withRetry(e,t){let r;for(let s=0;s<this.retryDelaysMs.length;s++){let i=this.retryDelaysMs[s]??0;i>0&&await new Promise(o=>setTimeout(o,i));try{return await t()}catch(o){r=o,Ks.warn("openclaw cli failed, will retry",{label:e,attempt:s+1,err:String(o)})}}throw new h("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${r?.message??"unknown"}`)}runCli(e){return new Promise((t,r)=>{let s=Uc(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),i="";s.stderr?.on("data",o=>{i+=o.toString("utf8")}),s.on("error",r),s.on("close",o=>{o===0?t():r(new Error(`exit ${o}: ${i.trim().slice(0,500)}`))})})}async runCliTolerant(e,t){try{await this.runCli(e)}catch(r){let s=String(r);if(t.some(i=>s.includes(i)))return;throw r}}async bestEffortUnset(e,t){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",t])))}catch(r){Ks.warn(`${e} failed (best-effort)`,{configPath:t,err:String(r)})}}ensureProvider(e,t){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${Xs}${e}`,JSON.stringify(t),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${Xs}${e}`)}addModelToAllowlist(e,t){let r={[e]:t?{alias:t}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Zt}[${e}]`,()=>this.runCli(["config","set",Zt,JSON.stringify(r),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Zt}[${e}]`,`${Zt}.${e}`)}ensureAgent(e,t,r){let s=["agents","add",e,"--workspace",t,"--non-interactive"];return r&&s.push("--model",r),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(s,["already exists","already registered"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var se=w("agent-manager"),Hc=(n,e,t,r,s,i,o)=>{switch(n){case"claude-code":{let a=s?{...xs(s),...Ps(s,o)}:void 0;return new Kt({cwd:t,...a&&Object.keys(a).length>0?{env:a}:{}})}case"codex":{let a=s?[...Ts(s),...Cs(s,o)]:[],c=s?Rs(s):void 0,l=!!s;return new Xt({cwd:t,...a.length>0?{extraArgs:a}:{},...c&&Object.keys(c).length>0?{env:c}:{},...l?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new dt({command:e,cwd:t,agentId:r,...i?{sessionName:st(i)}:{}})}};function Zs(n){return n==="claude-code"||n==="codex"}var Wc={path:"",version:"cloud-deployed"},jc={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Jc=6e4,tn=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Hc,this.createTimeoutMs=e.createTimeoutMs??Jc}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new h("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=new en({command:e.path})}return this.openclawConfigCache}async createAgent(e){if(!e.agentId)throw new h("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new h("IPC_BAD_REQUEST","framework required");let t=rt(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let r=this.registry.get(e.agentId);if(r){if(r.framework!==e.framework)throw new h("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${r.framework})`);if(r.status==="error")se.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await r.dispose("rebuild after error").catch(u=>se.warn("dispose stale agent failed (ignored)",{err:String(u)})),this.registry.unregister(e.agentId);else return se.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:r.agentId,workspace:r.workspace,framework:r.framework}}if(!t&&!this.config.frameworksCache?.[e.framework])throw new h("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);t&&Zs(e.framework)&&await zs(e.framework);let i=ae(e.agentId,this.paths),o=e.workspace??i.workspace,a=rt(e._meta),c=new AbortController,l=setTimeout(()=>c.abort(new h("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),d,f=!1;try{let u=()=>{if(c.signal.aborted)throw c.signal.reason instanceof Error?c.signal.reason:new h("AGENT_TIMEOUT","_agent/create aborted")};await jn(i.root,{recursive:!0}),await jn(o,{recursive:!0}),await jn(i.logs,{recursive:!0}),u(),await Me(o,e.framework,e.agentId,e.cozeIdentity),u();let p=await q(e.agentId,this.paths).catch(()=>null),m=ks({model:e.model??p?.model});if(d=new Yt({agentId:e.agentId,framework:e.framework,workspace:o,model:m.model??ne,deployType:a}),d.status="ok",p?.sessions){for(let[F,b]of Object.entries(p.sessions))d.sessions.set(F,{acpSessionId:b.acpSessionId,modelToken:b.modelToken,tokenGeneratedAt:b.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let C=Object.keys(p.sessions).length;C>0&&se.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:C})}this.registry.register(d),f=!0;let _={agentId:e.agentId,framework:e.framework,workspace:o,cozeIdentity:e.cozeIdentity,createdAt:p?.createdAt??Date.now(),sessions:p?.sessions??{},model:m.model};a==="cloud"&&(_.deployType="cloud"),p?.skills&&(_.skills=p.skills),p?.agentName&&(_.agentName=p.agentName),p?.description&&(_.description=p.description),e.framework==="openclaw"&&(this.config.frameworksCache?.openclaw?.path?await this.getOpenclawConfig().ensureAgent(e.agentId,o):se.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let v=e.initialSkills??[];if(v.length>0){let C=[..._.skills??[]],F=new Map(C.map((P,g)=>[P.skillId,g])),b=0;for(let P of v)try{let g=await Gn({agentId:e.agentId,workspace:o,framework:e.framework,skill:P});Hn(C,F,g),b++}catch(g){se.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:P.skillId,skillName:P.skillName,err:String(g)})}b>0&&(_.skills=C,se.info("initialSkills installed",{agentId:e.agentId,installed:b,requested:v.length}))}return await X(_,this.paths),se.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:a}),{ok:!0,agentId:e.agentId,workspace:o,framework:e.framework}}catch(u){throw se.error("agent create failed, rolling back",{agentId:e.agentId,err:String(u)}),f&&d&&(await d.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Gc(i.root,{recursive:!0,force:!0}).catch(p=>se.warn("rm agent dir failed (ignored)",{err:String(p)})),u instanceof h?u:new h("AGENT_SPAWN_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}async spawnSessionDownstream(e,t,r,s){let o=this.config.frameworksCache?.[e.framework];if(!o)if(e.deployType==="cloud"&&Zs(e.framework))o=Wc;else throw new h("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);let a=e.deployType==="cloud"?{model:e.model,modelToken:t}:void 0,c;e.framework==="openclaw"?c=await this.buildOpenclawDownstream({session:e,modelConfig:a,cloudSessionId:r,cozeEnv:s,command:o.path}):c=this.factory(e.framework,o.path,e.workspace,e.agentId,a,r,s);try{return await c.start(),await c.initialize(jc),c}catch(l){throw await c.stop("spawnSessionDownstream failed").catch(()=>{}),l instanceof h?l:new h("AGENT_SPAWN_FAILED",l instanceof Error?l.message:String(l),{cause:l})}}async buildOpenclawDownstream(e){let{session:t,modelConfig:r,cloudSessionId:s,cozeEnv:i,command:o}=e,a=st(s),c=await Ys(),l=r?As(r,i):null,d;if(l){let f=zn(s),p=l.models[0]?.id??ne,m=`${f}/${p}`;if(!this.ensuredProviders.has(m)){let _=this.getOpenclawConfig();await _.ensureProvider(f,l),await _.addModelToAllowlist(m),this.ensuredProviders.add(m)}d=m}return new dt({command:o,cwd:t.workspace,agentId:t.agentId,sessionName:a,...c?{gatewayToken:c}:{},...d?{slashModelOnStart:d}:{}})}async openclawRepair(e,t){let r=this.getOpenclawConfig();await r.deleteAgent(e),await r.ensureAgent(e,t)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let t=this.openclawConfigCache;for(let r of e.sessions.keys()){let s=zn(r),i=`${s}/${e.model}`;this.ensuredProviders.delete(i),await t.removeProvider(s),await t.removeModelFromAllowlist(i)}}};k();import{execFile as Vc}from"node:child_process";import{promisify as Qc}from"node:util";var Kc=Qc(Vc),me=w("coze-cli-installer"),ei="@coze/cli@0.1.3-alpha.89c42a",ti="https://bnpm.byted.org",Xc="coze",Yc=5e3,Zc=9e4,ni=1e4,ft=null,Jn=!1;async function ri(n,e={}){if(Jn)return;if(ft)return ft;let t=e.exec??Kc;return ft=(async()=>{try{let r=await el(Xc,t);if(r){me.info("coze-cli already on PATH, skip install + config + auth",{path:r}),Jn=!0;return}me.info("coze-cli install start",{package:ei,registry:ti});try{await t("npm",["i","-g",ei,"--registry",ti],{timeout:Zc,maxBuffer:10*1024*1024}),me.info("coze-cli install ok")}catch(s){me.warn("coze-cli install failed (skip subsequent steps)",{err:String(s)});return}if(n.env)try{await t("coze",["config","set","xTTEnv",n.env],{timeout:ni}),me.info("coze config set xTTEnv ok",{env:n.env})}catch(s){me.warn("coze config set failed (continue to auth login)",{err:String(s)})}try{await t("coze",["auth","login","--token",n.patToken],{timeout:ni}),me.info("coze auth login ok")}catch(s){me.warn("coze auth login failed",{err:String(s)});return}Jn=!0}finally{ft=null}})(),ft}async function el(n,e){let t=process.platform==="win32"?"where":"which";try{let{stdout:r}=await e(t,[n],{timeout:Yc});return r.split(`
|
|
94
|
-
`)[0]?.trim()||void 0}catch{return}}
|
|
95
|
-
`),
|
|
96
|
-
`)}return li.info("fs/read_text_file ok",{path:t,size:s.length}),{content:s}}async function fi(n,e){if(typeof n!="string"||n.length===0)throw new h("IPC_BAD_REQUEST","path must be a non-empty string");let[t,r]=await Promise.all([ci(ai(e)),ci(ai(n))]),s=ml(t,r);if(s.startsWith("..")||s===".."||s.startsWith(`..${_l}`))throw new h("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return r}async function ci(n){let e=[],t=n;for(;t!==Vn(t);)try{let r=await fl(t);return e.length?pl(r,...e.reverse()):r}catch{e.push(gl(t)),t=Vn(t)}return n}ge();k();var S=w("core"),yl=3e4,Sl=3e4,rn=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Ue;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=oi(e.bridgeConfig)}registerExtension(e,t){this.extensions[e]=t}getCozeEnv(){return this.currentCozeEnv}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),await this.upstream.start(),S.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){S.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(t=>t.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),S.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let t of this.registerHandlers)try{t(e.agentId)}catch(r){S.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(r)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&S.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,t,r){let s=r.downstream;s&&(s.onUpdate(i=>{r.loadingSession||this.forwardUpdate(e,i)}),s.onAgentRequest(i=>{this.handleAgentRequest(e,s,i)}),s.onExit((i,o)=>{S.info("session runtime exited",{agentId:e.agentId,cloudId:t,code:i,signal:o}),ut(r),r.downstream=void 0,r.acpSessionId&&e.activeTriggers.delete(r.acpSessionId)}))}async handleFrame(e){if(Vt(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let t="id"in e&&e.id!==void 0?e.id:null,r=e.params?._meta?.cozeEnv;r&&(this.currentCozeEnv=r);try{if(e.method.startsWith("_agent/")){let s=this.extensions[e.method];if(!s){t!==null?await this.sendError(t,R.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):S.warn("drop notification: extension not registered",{method:e.method});return}let i=await s(e,this);t!==null&&await this.upstream.send(Fe(t,i));return}if(e.method.startsWith("session/")){let s=await this.routeSessionMethod(e);t!==null&&await this.upstream.send(Fe(t,s));return}if(e.method==="initialize"){t!==null&&await this.upstream.send(Fe(t,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}t!==null?await this.sendError(t,R.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):S.warn("drop unknown notification",{method:e.method})}catch(s){S.error("handleFrame failed",{method:e.method,err:String(s)}),t!==null&&await this.upstream.send(ve(t,lt(s)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new h("IPC_BAD_REQUEST",`${e.method} requires params`);let t=e.params,r=t._meta?.cozeAgentId;if(!r)throw new h("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let s=this.agents.get(r);if(!s)throw this.disconnectedAgents.has(r)?new h("AGENT_DISCONNECTED",`agent ${r} has been disconnected; cloud must _agent/create to revive`):new h("AGENT_NOT_FOUND",`agent not found: ${r}`);let i=typeof t.sessionId=="string"?t.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!i)return this.dispatchSessionCall(s,e.method,t);let o=Date.now(),a=!1;try{let c=await s.getSessionQueue(i).enqueue(()=>this.dispatchSessionCall(s,e.method,t));return a=!0,c}finally{S.info("session call done",{agentId:s.agentId,method:e.method,durationMs:Date.now()-o,ok:a})}}async dispatchSessionCall(e,t,r){e.lastActiveAt=Date.now();let{stripped:s}=gs(r);switch(t){case"session/new":{let i=El();return S.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:i}),{sessionId:i}}case"session/load":{let i=s;return S.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:i.sessionId}),{}}case"session/prompt":{let i=s,o=i.sessionId;if(!o)throw new h("IPC_BAD_REQUEST","session/prompt: missing sessionId");let a=await this.ensureRuntime(e,o);if(a.replySeq=0,await this.ensureDownstream(e,o,a),!a.downstream||!a.acpSessionId)throw new h("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let c=r._meta?.cozeTriggerMsgId;c?e.activeTriggers.set(a.acpSessionId,c):e.activeTriggers.delete(a.acpSessionId);try{let l=await a.downstream.sessionPrompt({...i,sessionId:a.acpSessionId});return a.lastActiveAt=Date.now(),l}finally{e.activeTriggers.delete(a.acpSessionId),a.downstream?.isAlive()&&this.armIdleTimer(e,o,a)}}case"session/cancel":{let o=s.sessionId;if(!o)throw new h("IPC_BAD_REQUEST","session/cancel: missing sessionId");let a=e.sessions.get(o);return a?.downstream?.isAlive()&&a.acpSessionId&&await a.downstream.sessionCancel({sessionId:a.acpSessionId}),{ok:!0}}default:throw new h("IPC_BAD_REQUEST",`session method not supported: ${t}`)}}async ensureRuntime(e,t){let r=e.sessions.get(t);if(r)return r;let i={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,t):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(t,i),await this.persistSessionMapping(e),i}async requestSessionToken(e,t){let r={sessionId:t,_meta:{cozeAgentId:e}};try{let s=await this.sendRequest(te.GEN_MODEL_TOKEN,r,Sl);if(!s?.modelToken)throw new h("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${t})`);return s.modelToken}catch(s){throw s instanceof h&&s.code==="MODEL_TOKEN_GEN_FAILED"?s:new h("MODEL_TOKEN_GEN_FAILED",s instanceof Error?s.message:String(s),{cause:s})}}async ensureDownstream(e,t,r){if(ut(r),r.downstream?.isAlive())return;if(!this.sessionSpawner)throw new h("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let s=await this.sessionSpawner(e,r.modelToken,t,this.currentCozeEnv);if(r.downstream=s,this.attachRuntimeHooks(e,t,r),r.acpSessionId){r.loadingSession=!0;try{await s.sessionLoad({sessionId:r.acpSessionId,cwd:e.workspace}),S.info("session restored via session/load",{agentId:e.agentId,cloudId:t,acpId:r.acpSessionId})}catch(i){S.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:t,acpId:r.acpSessionId,err:String(i)}),r.acpSessionId=void 0;let o=await s.sessionNew({cwd:e.workspace});r.acpSessionId=o.sessionId,await this.persistSessionMapping(e)}finally{r.loadingSession=!1}}else{let i=await s.sessionNew({cwd:e.workspace});r.acpSessionId=i.sessionId,await this.persistSessionMapping(e)}s.afterSessionEstablished&&r.acpSessionId&&await s.afterSessionEstablished(r.acpSessionId)}armIdleTimer(e,t,r){if(ut(r),this.isRuntimeBusy(e,r)){S.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:t});return}r.idleTimer=setTimeout(()=>{if(r.idleTimer=void 0,this.isRuntimeBusy(e,r)){S.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:t}),this.armIdleTimer(e,t,r);return}S.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:t});let s=r.downstream;r.downstream=void 0,r.acpSessionId&&e.activeTriggers.delete(r.acpSessionId),s&&s.stop("idle timeout").catch(i=>S.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:t,err:String(i)}))},this.sessionIdleTimeoutMs),r.idleTimer.unref?.()}isRuntimeBusy(e,t){if(t.acpSessionId&&e.activeTriggers.has(t.acpSessionId))return!0;let r=t.downstream;if(!r)return!1;for(let s of this.pendingUpstream.values())if(s.downstream===r)return!0;return!1}forwardUpdate(e,t){let r=t.sessionId,s=this.reverseSessionId(e,r);if(!s){S.debug("drop update for unknown session",{agentId:e.agentId,acpId:r});return}let i=e.sessions.get(s);if(!i){S.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:s});return}if(vl(t)){S.debug("drop codex metadata-warn chunk",{agentId:e.agentId,acpId:r});return}let o={cozeAgentId:e.agentId,cozeReplySeqID:++i.replySeq},a=e.activeTriggers.get(r);a&&(o.cozeTriggerMsgId=a),this.upstream.send(jt("session/update",{...t,sessionId:s,_meta:o})).catch(c=>S.warn("forward update failed",{agentId:e.agentId,err:String(c)}))}handleAgentRequest(e,t,r){if(r.method==="session/request_permission"){this.forwardPermissionRequest(e,t,r);return}if(r.method==="fs/write_text_file"||r.method==="fs/read_text_file"){this.handleFsRpcRequest(e,t,r);return}S.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:r.method}),t.respondAgentRequestError(r.id,{code:R.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${r.method}`})}async handleFsRpcRequest(e,t,r){try{let s=e.workspace;if(r.method==="fs/write_text_file"){let i=r.params??{},o=await di(i,s);t.respondAgentRequest(r.id,o)}else{let i=r.params??{},o=await ui(i,s);t.respondAgentRequest(r.id,o)}}catch(s){S.warn("fs rpc handler failed",{agentId:e.agentId,method:r.method,err:String(s)}),t.respondAgentRequestError(r.id,lt(s))}}forwardPermissionRequest(e,t,r){let s=this.upstreamIds.next("session/request_permission"),i=r.params??{},a=i.sessionId,c=a?e.activeTriggers.get(a):void 0,l={cozeAgentId:e.agentId};c&&(l.cozeTriggerMsgId=c);let d=a?this.reverseSessionId(e,a):void 0,f={...i,...d?{sessionId:d}:{},_meta:l};this.pendingUpstream.set(s,{agentRequestId:r.id,agentId:e.agentId,downstream:t,method:r.method}),S.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:s,acpSessionId:a,cloudSessionId:d,toolCallId:i.toolCall?.toolCallId,options:i.options?.map(u=>({optionId:u.optionId,kind:u.kind,name:u.name}))}),this.upstream.send(ct(s,"session/request_permission",f)).catch(u=>{this.pendingUpstream.delete(s),S.error("forward permission request failed",{agentId:e.agentId,err:String(u)}),t.respondAgentRequestError(r.id,{code:R.INTERNAL_ERROR,message:`upstream send failed: ${String(u)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let t=this.pendingUpstream.get(e.id);if(t){this.pendingUpstream.delete(e.id),e.error?(S.info("upstream \u2192 permission response (error)",{agentId:t.agentId,upstreamId:e.id,method:t.method,error:e.error}),t.downstream.respondAgentRequestError(t.agentRequestId,e.error)):(S.info("upstream \u2192 permission response (result)",{agentId:t.agentId,upstreamId:e.id,method:t.method,result:e.result}),t.downstream.respondAgentRequest(t.agentRequestId,e.result));return}let r=this.pendingBridge.get(e.id);if(r){this.pendingBridge.delete(e.id),clearTimeout(r.timer),e.error?r.reject(new Jt(e.error)):r.resolve(e.result);return}S.debug("orphan upstream response (no pending)",{id:e.id})}sendRequest(e,t,r=yl){let s=this.upstreamIds.next(e);return new Promise((i,o)=>{let a=setTimeout(()=>{this.pendingBridge.delete(s),o(new h("AGENT_TIMEOUT",`${e} timed out after ${r}ms`))},r);this.pendingBridge.set(s,{method:e,resolve:i,reject:o,timer:a}),this.upstream.send(ct(s,e,t)).catch(c=>{let l=this.pendingBridge.get(s);l&&(clearTimeout(l.timer),this.pendingBridge.delete(s)),o(c)})})}async persistSessionMapping(e){if(this.paths)try{let t=new Map;for(let[r,s]of e.sessions){let i={modelToken:s.modelToken,tokenGeneratedAt:s.tokenGeneratedAt};s.acpSessionId&&(i.acpSessionId=s.acpSessionId),t.set(r,i)}await Fn(e.agentId,t,this.paths)}catch(t){S.warn("persist session mapping failed",{agentId:e.agentId,err:String(t)})}}reverseSessionId(e,t){for(let[r,s]of e.sessions.entries())if(s.acpSessionId===t)return r}sendError(e,t,r){return this.upstream.send(ve(e,{code:t,message:r}))}};function El(){return wl(16).toString("hex")}function vl(n){let e=n.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let t=e.content;if(!t||typeof t!="object")return!1;let r=t;return r.type!=="text"||typeof r.text!="string"?!1:r.text.startsWith("Model metadata for `")}k();z();import{randomBytes as kl}from"node:crypto";import{chmod as Il,mkdir as xl,writeFile as hi}from"node:fs/promises";import{createServer as Tl}from"node:http";import{dirname as Rl}from"node:path";var Pl=1e6,Qn=w("ipc"),sn=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(t=>[`${t.method} ${t.path}`,t])),this.paths=e.paths??T()}async start(){this.token=kl(32).toString("hex");let e=Tl((r,s)=>{this.dispatch(r,s)});this.server=e,await new Promise((r,s)=>{e.once("error",s),e.listen(0,"127.0.0.1",()=>r())});let t=e.address();if(!t||typeof t!="object")throw new Error("failed to obtain IPC port");return this.port=t.port,await this.persistAuthFiles(),Qn.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((t,r)=>{e.close(s=>s?r(s):t())}),this.server=null)}async persistAuthFiles(){await xl(Rl(this.paths.portFile),{recursive:!0}),await hi(this.paths.portFile,String(this.port),"utf8"),await hi(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await Il(this.paths.tokenFile,384)}catch(e){Qn.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,t){if(e.headers.authorization!==`Bearer ${this.token}`){ht(t,401,{error:"unauthorized"});return}let s=`${e.method} ${(e.url??"").split("?")[0]}`,i=this.routes.get(s);if(!i){ht(t,404,{error:"not found"});return}let o=null;if(e.method==="POST")try{o=await Al(e)}catch(a){ht(t,400,{error:"invalid json",detail:String(a)});return}try{let a=await i.handler(o,e);ht(t,200,a??{ok:!0})}catch(a){Qn.error("IPC handler failed",{key:s,err:String(a)}),ht(t,500,{error:a instanceof Error?a.message:String(a)})}}};function ht(n,e,t){n.statusCode=e,n.setHeader("content-type","application/json"),n.end(JSON.stringify(t))}async function Al(n){let e=[],t=0;for await(let s of n){let i=s;if(t+=i.length,t>Pl)throw new Error("body too large");e.push(i)}let r=Buffer.concat(e).toString("utf8");return r?JSON.parse(r):null}var vi="";function zl(n=""){let t=`${Date.now()}`,r=vi||(vi=Wl(n)),s=Math.random().toString(16).slice(-6);return"02"+t+r+s}function ql(){return 1e4*Date.now()+Math.floor(1e4*Math.random())}function Gl(n){return(Array(8).join("0")+parseInt(n,10).toString(2)).slice(-8)}function ki(n){return(Array(4).join("0")+parseInt(n,2).toString(16)).slice(-4)}function Hl(n){let e=n.split(/\./).map(s=>Gl(s)),t=[];return t[0]=ki(e[0]+e[1]),t[1]=ki(e[2]+e[3]),["0000","0000","0000","0000","0000","ffff",t[0],t[1]].join("")}function Wl(n){let e=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(n),t=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(n);return e?Hl(n):t?jl(n):"00000000000000000000000000000000"}function jl(n){let e="",t=[],r=0,s=0,i=!0,o="0000";if(n.indexOf("::")>-1){let a=n.split("::");for(let l=0;l<a.length;l++){let d=a[l];if(d.indexOf(":")>0){let f=d.split(":");i&&(r=f.length),s+=f.length;for(let u=0;u<f.length;u++)if(f[u].length!==4){let m=o.substring(0,4-f[u].length).concat(f[u]);t.push(m)}else t.push(f[u]);i=!1}else{if(d.length!==4){let u=o.substring(0,4-d.length).concat(d);t.push(u)}else t.push(d);i&&(r+=1),s+=1,i=!1}}let c="";for(let l=0;l<8-s;l++)c=c.concat(o);for(let l=0;l<t.length;l++)l===r&&(e=e.concat(c)),e=e.concat(t[l]);return e}{let a=n.split(":");for(let c=0;c<a.length;c++){let l=a[c];if(a[c].length!==4){let f=o.substring(0,4-a[c].length).concat(l);e=e.concat(f)}else e=e.concat(l)}return e}}function Jl(n,e){let t=n.key;t!==void 0&&(N(e,10),xe(e,t));let r=n.value;r!==void 0&&(N(e,18),xe(e,r))}function Vl(n){let e={};e:for(;!Bi(n);){let t=B(n);switch(t>>>3){case 0:break e;case 1:e.key=Ie(n,B(n));break;case 2:e.value=Ie(n,B(n));break;default:Di(n,7&t)}}if(e.key===void 0)throw new Error("Missing required field: key");if(e.value===void 0)throw new Error("Missing required field: value");return e}function Ni(n){let e=Mi();return Ql(n,e),td(e)}function Ql(n,e){let t=n.SeqID;t!==void 0&&(N(e,8),pt(e,t));let r=n.LogID;r!==void 0&&(N(e,16),pt(e,r));let s=n.service;s!==void 0&&(N(e,24),pt(e,nr(s)));let i=n.method;i!==void 0&&(N(e,32),pt(e,nr(i)));let o=n.headers;if(o!==void 0)for(let m of o){N(e,42);let _=Mi();Jl(m,_),N(e,_.limit),sd(e,_),Zl(_)}let a=n.payloadEncoding;a!==void 0&&(N(e,50),xe(e,a));let c=n.payloadType;c!==void 0&&(N(e,58),xe(e,c));let l=n.payload;l!==void 0&&(N(e,66),N(e,l.length),rd(e,l));let d=n.LogIDNew;d!==void 0&&(N(e,74),xe(e,d));let f=n.serverTiming;f!==void 0&&(N(e,82),xe(e,f));let u=n.msgID;u!==void 0&&(N(e,90),xe(e,u));let p=n.frameType;p!==void 0&&(N(e,96),pt(e,nr(p)))}function Kl(n){return Xl(ed(n))}function Xl(n){let e={};e:for(;!Bi(n);){let t=B(n);switch(t>>>3){case 0:break e;case 1:e.SeqID=xi(n,!0);break;case 2:e.LogID=xi(n,!0);break;case 3:e.service=B(n);break;case 4:e.method=B(n);break;case 5:{let r=Yl(n);(e.headers||(e.headers=[])).push(Vl(n)),n.limit=r;break}case 6:e.payloadEncoding=Ie(n,B(n));break;case 7:e.payloadType=Ie(n,B(n));break;case 8:e.payload=nd(n,B(n));break;case 9:e.LogIDNew=Ie(n,B(n));break;case 10:e.serverTiming=Ie(n,B(n));break;case 11:e.msgID=Ie(n,B(n));break;case 12:e.frameType=B(n);break;default:Di(n,7&t)}}if(e.SeqID===void 0)throw new Error("Missing required field: SeqID");if(e.LogID===void 0)throw new Error("Missing required field: LogID");if(e.service===void 0)throw new Error("Missing required field: service");if(e.method===void 0)throw new Error("Missing required field: method");return e}function Yl(n){let e=B(n),t=n.limit;return n.limit=n.offset+e,t}function Di(n,e){switch(e){case 0:for(;128&j(n););break;case 2:rr(n,B(n));break;case 5:rr(n,4);break;case 1:rr(n,8);break;default:throw new Error("Unimplemented type: "+e)}}function nr(n){return n|=0,{low:n,high:n>>31,unsigned:n>=0}}var Li=[];function Mi(){let n=Li.pop();return n?(n.offset=n.limit=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function Zl(n){Li.push(n)}function ed(n){return{bytes:n,offset:0,limit:n.length}}function td(n){let e=n.bytes,t=n.limit;return e.length===t?e:e.subarray(0,t)}function rr(n,e){if(n.offset+e>n.limit)throw new Error("Skip past limit");n.offset+=e}function Bi(n){return n.offset>=n.limit}function wt(n,e){let t=n.bytes,r=n.offset,s=n.limit,i=r+e;if(i>t.length){let o=new Uint8Array(2*i);o.set(t),n.bytes=o}return n.offset=i,i>s&&(n.limit=i),r}function Er(n,e){let t=n.offset;if(t+e>n.limit)throw new Error("Read past limit");return n.offset+=e,t}function nd(n,e){let t=Er(n,e);return n.bytes.subarray(t,t+e)}function rd(n,e){let t=wt(n,e.length);n.bytes.set(e,t)}function Ie(n,e){let t=Er(n,e),r=String.fromCharCode,s=n.bytes,i="\uFFFD",o="";for(let a=0;a<e;a++){let c=s[a+t],l,d,f,u;(128&c)===0?o+=r(c):(224&c)===192?a+1>=e?o+=i:(l=s[a+t+1],(192&l)!==128?o+=i:(u=(31&c)<<6|63&l,u<128?o+=i:(o+=r(u),a++))):(240&c)==224?a+2>=e?o+=i:(l=s[a+t+1],d=s[a+t+2],((l|d<<8)&49344)!==32896?o+=i:(u=(15&c)<<12|(63&l)<<6|63&d,u<2048||u>=55296&&u<=57343?o+=i:(o+=r(u),a+=2))):(248&c)==240?a+3>=e?o+=i:(l=s[a+t+1],d=s[a+t+2],f=s[a+t+3],((l|d<<8|f<<16)&12632256)!==8421504?o+=i:(u=(7&c)<<18|(63&l)<<12|(63&d)<<6|63&f,u<65536||u>1114111?o+=i:(u-=65536,o+=r((u>>10)+55296,(1023&u)+56320),a+=3))):o+=i}return o}function xe(n,e){let t=e.length,r=0;for(let o=0;o<t;o++){let a=e.charCodeAt(o);a>=55296&&a<=56319&&o+1<t&&(a=(a<<10)+e.charCodeAt(++o)-56613888),r+=a<128?1:a<2048?2:a<65536?3:4}N(n,r);let s=wt(n,r),i=n.bytes;for(let o=0;o<t;o++){let a=e.charCodeAt(o);a>=55296&&a<=56319&&o+1<t&&(a=(a<<10)+e.charCodeAt(++o)-56613888),a<128?i[s++]=a:(a<2048?i[s++]=a>>6&31|192:(a<65536?i[s++]=a>>12&15|224:(i[s++]=a>>18&7|240,i[s++]=a>>12&63|128),i[s++]=a>>6&63|128),i[s++]=63&a|128)}}function sd(n,e){let t=wt(n,e.limit),r=n.bytes,s=e.bytes;for(let i=0,o=e.limit;i<o;i++)r[i+t]=s[i]}function j(n){return n.bytes[Er(n,1)]}function Ii(n,e){let t=wt(n,1);n.bytes[t]=e}function B(n){let e=0,t=0,r;do r=j(n),e<32&&(t|=(127&r)<<e),e+=7;while(128&r);return t}function N(n,e){for(e>>>=0;e>=128;)Ii(n,127&e|128),e>>>=7;Ii(n,e)}function xi(n,e){let t=0,r=0,s=0,i;return i=j(n),t=127&i,128&i&&(i=j(n),t|=(127&i)<<7,128&i&&(i=j(n),t|=(127&i)<<14,128&i&&(i=j(n),t|=(127&i)<<21,128&i&&(i=j(n),r=127&i,128&i&&(i=j(n),r|=(127&i)<<7,128&i&&(i=j(n),r|=(127&i)<<14,128&i&&(i=j(n),r|=(127&i)<<21,128&i&&(i=j(n),s=127&i,128&i&&(i=j(n),s|=(127&i)<<7))))))))),{low:t|r<<28,high:r>>>4|s<<24,unsigned:e}}function pt(n,e){let t=e.low>>>0,r=(e.low>>>28|e.high<<4)>>>0,s=e.high>>>24,i=s===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:s<128?9:10,o=wt(n,i),a=n.bytes;switch(i){case 10:a[o+9]=s>>>7&1;case 9:a[o+8]=i!==9?128|s:127&s;case 8:a[o+7]=i!==8?r>>>21|128:r>>>21&127;case 7:a[o+6]=i!==7?r>>>14|128:r>>>14&127;case 6:a[o+5]=i!==6?r>>>7|128:r>>>7&127;case 5:a[o+4]=i!==5?128|r:127&r;case 4:a[o+3]=i!==4?t>>>21|128:t>>>21&127;case 3:a[o+2]=i!==3?t>>>14|128:t>>>14&127;case 2:a[o+1]=i!==2?t>>>7|128:t>>>7&127;case 1:a[o]=i!==1?128|t:127&t}}function id(n){return Kl(n)}function Ti(n){return Ni(n)}var Ri=65536,od="\0\0\0\0\0\0\0\0",Ge=Ri*Ri,Fi=Ge*Ge,Pi=Fi/2,_e=String.prototype.charCodeAt,G=class n{constructor(e,t,r){this.isLong=!0,this.low=0|e,this.high=0|t,this.unsigned=!!r}static isLong(e){return e&&e.isLong===!0}static fromBits(e,t,r){return new n(e,t,r)}static fromBytes(e,t,r){return r?n.fromBytesLE(e,t):n.fromBytesBE(e,t)}static fromBytesLE(e,t){return new n(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)}static fromBytesBE(e,t){return new n(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)}static fromHash(e){return e===od?Ai:new n((_e.call(e,0)|_e.call(e,1)<<8|_e.call(e,2)<<16|_e.call(e,3)<<24)>>>0,(_e.call(e,4)|_e.call(e,5)<<8|_e.call(e,6)<<16|_e.call(e,7)<<24)>>>0,!0)}toHash(){return String.fromCharCode(255&this.low,this.low>>>8&255,this.low>>>16&255,this.low>>>24,255&this.high,this.high>>>8&255,this.high>>>16&255,this.high>>>24)}static fromNumber(e,t=!0){if(isNaN(e))return t?ad:Ai;if(t){if(e>=Fi)return ld}else{if(e<=-Pi)return dd;if(e+1>=Pi)return cd}return n.fromBits(e%Ge|0,e/Ge|0,t)}toNumber(){return this.unsigned?(this.high>>>0)*Ge+(this.low>>>0):this.high*Ge+(this.low>>>0)}isZero(){return this.high===0&&this.low===0}add(e){n.isLong(e)||(e=n.fromNumber(e));let t=this.high>>>16,r=65535&this.high,s=this.low>>>16,i=65535&this.low,o=e.high>>>16,a=65535&e.high,c=e.low>>>16,l=65535&e.low,d=0,f=0,u=0,p=0;return p+=i+l,u+=p>>>16,p&=65535,u+=s+c,f+=u>>>16,u&=65535,f+=r+a,d+=f>>>16,f&=65535,d+=t+o,d&=65535,n.fromBits(u<<16|p,d<<16|f,this.unsigned)}equals(e){return n.isLong(e)||(e=n.fromNumber(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low}addOne(){return this.low===-1&&this.high===-1?n.fromBits(0,0,this.unsigned):this.low===-1?n.fromBits(0,this.high+1,this.unsigned):n.fromBits(this.low+1,this.high,this.unsigned)}toBytes(e){return e?this.toBytesLE():this.toBytesBE()}toBytesLE(){let e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]}toBytesBE(){let e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]}},Ai=new G(0,0,!1),ad=new G(0,0,!0),cd=G.fromBits(-1,2147483647,!1),ld=G.fromBits(-1,-1,!0),dd=G.fromBits(0,-2147483648,!1),ke=(function(n){return n[n.NATIVE_ERROR=5001]="NATIVE_ERROR",n[n.CONNECTING_ERROR=5002]="CONNECTING_ERROR",n[n.MAX_RETRIES_ERROR=5003]="MAX_RETRIES_ERROR",n[n.MESSAGE_ERROR=5004]="MESSAGE_ERROR",n[n.OPEN_ERROR=5005]="OPEN_ERROR",n})({}),Te=class{constructor(e){this.type=e,this.target=null}},ir=class extends Te{constructor(e,t){super(e),this.message=t&&t.message||null}},or=class extends Te{constructor(e,t){super(e),this.error=t&&t.error||null,this.colno=t&&t.colno||0,this.filename=t&&t.filename||"",this.lineno=t&&t.lineno||0,this.message=t&&t.message||"",this.code=t&&t.code||5001}},ar=class extends Te{constructor(e,t){super(e),this.code=t&&t.code||0,this.reason=t&&t.reason||"",this.wasClean=t&&t.wasClean||!1,this.willReconnect=t&&t.willReconnect||!1}},cr=class extends Te{constructor(e,t){super(e),this.data=t&&t.data||null}},lr=class extends cr{constructor(e,t){super(e),this.data=t&&t.data||null,this.message=t&&t.message||null}},dr=class extends Te{constructor(e,t){super(e),this.data=t&&t.data||null}};function Y(n,{message:e,code:t,error:r}){return new or(n,{message:e,code:t,error:r})}function ie(n,{code:e,reason:t,wasClean:r,willReconnect:s}){return new ar(n,{code:e,reason:t,wasClean:r,willReconnect:s})}function ud(n,{data:e,message:t}){return new lr(n,{data:e,message:t})}function fd(n,{data:e}){return new dr(n,{data:e})}function Ci(n,{message:e}){return new ir(n,{message:e})}var on=class{constructor(e,t){this.endpoints=e,this.maxRetries=t,this.currentIndex=0,this.currentEndpointTriesCount=0}resetEndpointConfig(){this.currentIndex=0,this.currentEndpointTriesCount=0}resetTries(){this.currentEndpointTriesCount=0}getCurrentEndpoint(){return this.endpoints[this.currentIndex]}getCurrentEndpointTriesCount(){return this.currentEndpointTriesCount}checkReachMaxTries(){return this.currentIndex>=this.endpoints.length||this.currentIndex===this.endpoints.length-1&&this.currentEndpointTriesCount===this.maxRetries}checkCurrentEndpointReachedMaxRetries(){return this.currentIndex==this.endpoints.length?!0:this.currentEndpointTriesCount>this.maxRetries}replaceBackupEndpointAndUpdateCount(){return this.currentEndpointTriesCount=1,this.currentIndex++,this.endpoints[this.currentIndex]}getCurrentEndpointAndUpdateCount(){return this.currentEndpointTriesCount++,this.getCurrentEndpoint()}},We=(typeof globalThis<"u"&&globalThis.constructor.name==="Window"||typeof window<"u"&&window.constructor.name==="Window")&&typeof document<"u",Re=typeof globalThis<"u"&&(globalThis.constructor.name==="Object"||globalThis.constructor.name==="DedicatedWorkerGlobalScope")&&typeof tt<"u",yt=(typeof globalThis<"u"&&globalThis.constructor.name==="Object"||typeof globalThis>"u"||typeof globalThis<"u"&&!!globalThis.WeixinJSBridge)&&typeof wx<"u",mt=typeof globalThis<"u"&&(globalThis.constructor.name==="DedicatedWorkerGlobalScope"||globalThis.constructor.name==="SharedWorkerGlobalScope"||globalThis.constructor.name==="ServiceWorkerGlobalScope")&&typeof self<"u",hd=typeof globalThis<"u"&&globalThis.constructor.name==="Object"&&typeof global<"u"&&global.constructor.name==="Object"&&typeof process<"u"&&!!process.version,_t=class{constructor(){this._listeners={}}emit(e,...t){let r=this._listeners[e];if(r)r.slice().forEach(s=>s.fn.apply(s.ctx,t));else if(e==="error"&&!this.onerror){let s=t.length&&t[0];if(s instanceof Error)throw s;let i=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw i.context=s,s}return this}off(e,t){if(e===void 0)this._listeners={};else if(t===void 0)this._listeners[e]=null;else{let r=this._listeners[e];if(r)for(let s=0;s<r.length;)r[s].fn===t?r.splice(s,1):++s}return this}on(e,t,r){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:r||this}),this}},ur=class extends _t{_formatErrorMessage(e){return e.errMsg||e.errNo?`message: ${e.errMsg||""} code: ${e.errNo||""}`.trim():JSON.stringify(e)}constructor(e,t,r){super(),this._socket=null,yt&&wx.connectSocket&&(this._socket=wx.connectSocket({url:e,protocols:t,header:r,fail:this._createSocketFailHandler.bind(this),success:this._createSocketSuccessHandler.bind(this)})),Re&&tt.connectSocket&&(this._socket=tt.connectSocket({url:e,protocols:t,header:r,fail:this._createSocketFailHandler.bind(this),success:this._createSocketSuccessHandler.bind(this)}))}_createSocketSuccessHandler(){Promise.resolve().then(()=>{this._addWsListeners()})}_createSocketFailHandler(e){Promise.resolve().then(()=>{let t=Y("error",{message:this._formatErrorMessage(e)});this.emit("error",t);let r=ie("close",{reason:this._formatErrorMessage(e)});this.emit("close",r)})}_addWsListeners(){this._socket.onOpen(e=>{this.emit("open",fd("open",{...e,data:e.errMsg||""}))}),this._socket.onClose(e=>{this.emit("close",ie("close",{...e}))}),this._socket.onMessage(e=>{this.emit("message",ud("message",{...e}))}),this._socket.onError(e=>{this.emit("error",Y("error",{...e,message:e.errMsg||""}))})}send(e){if(e instanceof Uint8Array){let t=e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset);this._socket&&this._socket.send({data:t,fail:r=>{this.emit("error",Y("error",{message:this._formatErrorMessage(r)}))}})}else this._socket&&this._socket.send({data:e,fail:t=>{this.emit("error",Y("error",{message:this._formatErrorMessage(t)}))}})}close(e,t){this._socket&&this._socket.close({code:e,reason:t})}addEventListener(e,t){this.on(e,t)}removeEventListener(e,t){this.off(e,t)}get readyState(){return this._socket.readyState}get binaryType(){return this._socket.binaryType}set binaryType(e){}get url(){return this._socket.url}get protocol(){return this._socket.protocol}get extensions(){return this._socket.extensions}get bufferedAmount(){return 0}};function gd(n,e){if(e)return new e(n.url,n.protocol);if(yt||Re)return new ur(n.url,n.protocol,n.headers);if((We||mt)&&typeof WebSocket<"u"&&WebSocket)return new WebSocket(n.url,n.protocols)}function pd(n){return!!(n||yt&&wx.connectSocket||Re&&tt.connectSocket||(We||mt)&&typeof WebSocket<"u"&&WebSocket)}function Oi(n,e,t){let r=-1;async function s(i){return i<=r?Promise.reject(new Error("next() called multiple times in process")):(r=i,i===t.length?Promise.resolve():t[i].bind(n)(e,s.bind(null,i+1)))}s(0)}function Ui(n){let e=0,t=0;for(let r=0;r<n.length;++r)t=n.charCodeAt(r),t<128?e+=1:t<2048?e+=2:(64512&t)===55296&&(64512&n.charCodeAt(r+1))===56320?(++r,e+=4):e+=3;return e}function $i(n,e,t){if(t-e<1)return"";let r="";for(let s=e;s<t;){let i=n[s++];if(i<=127)r+=String.fromCharCode(i);else if(i>=192&&i<224)r+=String.fromCharCode((31&i)<<6|63&n[s++]);else if(i>=224&&i<240)r+=String.fromCharCode((15&i)<<12|(63&n[s++])<<6|63&n[s++]);else if(i>=240){let o=((7&i)<<18|(63&n[s++])<<12|(63&n[s++])<<6|63&n[s++])-65536;r+=String.fromCharCode(55296+(o>>10)),r+=String.fromCharCode(56320+(1023&o))}}return r}function fr(n,e,t){let r=t,s,i;for(let o=0;o<n.length;++o)s=n.charCodeAt(o),s<128?e[t++]=s:s<2048?(e[t++]=s>>6|192,e[t++]=63&s|128):(64512&s)===55296&&(64512&(i=n.charCodeAt(o+1)))===56320?(s=65536+((1023&s)<<10)+(1023&i),++o,e[t++]=s>>18|240,e[t++]=s>>12&63|128,e[t++]=s>>6&63|128,e[t++]=63&s|128):(e[t++]=s>>12|224,e[t++]=s>>6&63|128,e[t++]=63&s|128);return t-r}async function zi(n){if(typeof n=="string"){let e=new Uint8Array(Ui(n));return fr(n,e,0),e}return n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}function md(n){try{return typeof n!="string"&&(n instanceof ArrayBuffer||n.buffer&&n.buffer instanceof ArrayBuffer)||typeof n!="string"?"":(JSON.parse(n),"application/json")}catch{return typeof n=="string"?"text/plain;charset=utf-8":""}}var _d=(n,e)=>{switch(n){case"boe":case"ppe":return{[`x-use-${n}`]:1,"x-tt-env":e};default:return{}}},hr=class{constructor(e){this.maxLossCount=e,this.count=0}addCount(){this.count++}checkReachMaxCount(){return this.count>=this.maxLossCount}resetCounter(e=0){this.maxLossCount=e,this.count=0}};async function wd(n){return new Promise(e=>{if(!We)return e("unknown reason");try{let t=document.createElement("script");window.frontierJSONP=r=>{document.body.removeChild(t),window.frontierJSONP=void 0,e(r&&r.msg||"unknown reason")},t.type="text/javascript",t.src=n.replace(/^ws/,"http")+"&jscallback=frontierJSONP";try{document.body.appendChild(t)}catch{document.body.removeChild(t)}}catch{window.frontierJSONP=void 0,e("unknown reason")}})}function we(n,e,t){return!!n?.find(r=>r.key===e&&r.value===t)}function He(n,e){return n?.find(t=>t.key===e)?.value}var sr=null;async function yd(){return sr||(sr=Promise.resolve().then(()=>(Ei(),Si))),sr}var gr=class extends _t{constructor(e,t){super(),this._dbName=e,this._keyPath=t,this._qosDB=void 0,this._initPromise=null}async openDB(){await this._init()}async _init(){if(!this._qosDB){if(this._initPromise)return this._initPromise;try{let e=this._dbName,t=this._keyPath;this._initPromise=(async()=>{let{openDB:r}=await yd();this._qosDB=await r(`frontier_${e}`,1,{upgrade(s){s.createObjectStore(e,{keyPath:t})}})})(),await this._initPromise}catch(e){console.log(e)}finally{this._initPromise=null}}}async get(e){try{return await this._init(),this._qosDB?.get(this._dbName,e)}catch(t){console.log(t)}}async set(e,t){return await this._init(),this._qosDB?.put(this._dbName,e)}async del(e){try{return await this._init(),this._qosDB?.delete(this._dbName,e)}catch(t){console.log(t)}}async clear(){try{return await this._init(),this._qosDB?.clear(this._dbName)}catch(e){console.log(e)}}async keys(){return await this._init(),this._qosDB?.getAllKeys(this._dbName)}async getAll(){return await this._init(),this._qosDB?.getAll(this._dbName)}async closeDB(){try{this._qosDB?.close(),this._qosDB=void 0}catch(e){console.log(e)}}get isReady(){try{return!!this._qosDB}catch(e){return console.log(e),!1}}},pr=class{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=localStorage}async openDB(){}get _prefix(){return`frontier_${this._DBName}`}async get(e){let t=this._qosDB.getItem(this._prefix);return JSON.parse(t||"{}")[e]}async set(e,t){let r=this._qosDB.getItem(this._prefix),s=JSON.parse(r||"{}");return s[t||e[this._pathKey]]=e,this._qosDB.setItem(this._prefix,JSON.stringify(s)),t||e[this._pathKey]}async del(e){let t=this._qosDB.getItem(this._prefix),r=JSON.parse(t||"{}");return r[e]=void 0,this._qosDB.setItem(this._prefix,JSON.stringify(r))}async clear(){return this._qosDB.clear()}async keys(){let e=this._qosDB.getItem(this._prefix),t=JSON.parse(e||"{}");return Object.keys(t)}async getAll(){let e=this._qosDB.getItem(this._prefix),t=JSON.parse(e||"{}");return Object.values(t)}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}},mr=class{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=Re?tt:yt?wx:null}async openDB(){}get _prefix(){return`frontier_${this._DBName}`}async get(e){let t=this._qosDB.getStorageSync(this._prefix);return JSON.parse(t||"{}")[e]}async set(e,t){let r=this._qosDB.getStorageSync(this._prefix),s=JSON.parse(r||"{}");return s[t||e[this._pathKey]]=e,this._qosDB.setStorageSync(this._prefix,JSON.stringify(s)),t||e[this._pathKey]}async del(e){let t=this._qosDB.getStorageSync(this._prefix),r=JSON.parse(t||"{}");return r[e]=void 0,this._qosDB.setStorageSync(this._prefix,JSON.stringify(r))}async clear(){return this._qosDB.clearStorageSync()}async keys(){let e=this._qosDB.getStorageInfoSync(this._prefix),t=JSON.parse(e||"{}");return Object.keys(t)}async getAll(){let e=this._qosDB.getStorageInfoSync(this._prefix),t=JSON.parse(e||"{}");return Object.values(t)}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}};function qi(n,e){if(Re||Re)return new mr(n,e);if((We||mt)&&typeof indexedDB<"u")return new gr(n,e);if((We||mt)&&typeof localStorage<"u")return new pr(n,e);throw new Error("init QoSDB failed")}var _r=class{constructor(){this._intervalTimeoutId=null,this._interval=36e5,this._qosDB=qi("qos","message_id")}async _intervalFlush(){clearInterval(this._intervalTimeoutId),this._intervalTimeoutId=setInterval(()=>{this.flushExpired()},this._interval)}async openDB(){await this._qosDB.openDB().then(()=>{this._intervalFlush()})}async flushExpired(){(await this._qosDB?.getAll()||[]).filter(({timestamp:r})=>r<Date.now()).forEach(r=>{this._qosDB?.del(r.message_id)})}async del(e){return this._qosDB?.del(e)}async set(e,t){return this._qosDB?.set({message_id:e,timestamp:t})}async get(e){return this._qosDB?.get(e)}async closeDB(){clearInterval(this._intervalTimeoutId),await this._qosDB?.closeDB()}get isReady(){return this._qosDB?.isReady}};function vr(n){let e=!!this._options.enableQoS;if(!e)return{enabled:e,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let t=we(n.message.headers,"x_frontier_qos","2"),r=t&&we(n.message.headers,"x_frontier_qos_ack","1"),s=t&&we(n.message.headers,"x_frontier_is_ack","1"),i=s?He(n.message.headers,"x_frontier_ack_msgid")?.split(",").filter(Boolean)||[]:[];return{enabled:e,isQoSMessage:t,isQoSAck:r,isAckCleanupMessage:s,ackMsgIds:i}}async function Gi(){return this._QoSManager||(this._QoSManager=new _r),this._QoSManager.isReady||await this._QoSManager.openDB(),this._QoSManager}async function Sd(n,e){let{enableAutoAck:t}=this._options,r=we(n.message.headers,"need_ack","1"),s=we(n.message.headers,"is_ack","1"),i=vr.call(this,n);if(t&&r){let{SeqID:o,LogID:a,service:c,LogIDNew:l,method:d}=n.message;this._sendAck({SeqID:o,LogID:a,LogIDNew:l,service:c,method:d,headers:[{key:"is_ack",value:"1"},{key:"ack_id",value:l||""},{key:"ack_code",value:"0"}]})}s&&!i.isQoSAck&&this._dispatchAckMessageEvent(n),e()}async function Ed(n,e){this._debug("received",n.message),e()}async function vd(n,e){let t=id(await zi(n.data));try{if(t.payload instanceof Uint8Array){let r=this._options.payloadEncoding instanceof Object?{force:!!this._options.payloadEncoding.force,encoding:this._options.payloadEncoding.encoding?this._options.payloadEncoding.encoding.replace(/\s/g,"").toLowerCase():""}:{force:!1,encoding:this._options.payloadEncoding?this._options.payloadEncoding.replace(/\s/g,"").toLowerCase():""},s=t.payloadEncoding?t.payloadEncoding.replace(/\s/g,"").toLowerCase():"",i=this._options.payloadType instanceof Object?{force:!!this._options.payloadType.force,type:this._options.payloadType.type?this._options.payloadType.type.replace(/\s/g,"").toLowerCase():""}:{force:!1,type:this._options.payloadType?this._options.payloadType.replace(/\s/g,"").toLowerCase():""},o=t.payloadType?t.payloadType.replace(/\s/g,"").toLowerCase():"",a=i.force?i.type:o||i.type,c=r.force?r.encoding:s||r.encoding,l=["text/plain;charset=utf-8","application/json","application/json;charset=utf-8","string"],d=["none_none","binary"];this._options.enableTransformTextPayload&&l.includes(a)&&(!c||d.includes(c))?t.textPayload=$i(t.payload,0,t.payload.byteLength):t.textPayload=""}else t.textPayload=""}catch(r){t.textPayload="",console.log(r)}n.message=t,e()}function kd(n,e,t){let r=t||8192,s=r>>>1,i=null,o=r;return function(a){if(a<1||a>s)return n(a);o+a>r&&(i=n(r),o=0);let c=e.call(i,o,o+=a);return 7&o&&(o=(7|o)+1),c}}var Id=4294967295;function xd(n,e,t){if(t>Id)throw new Error("integer too large");let r=3;for(;r>=0;){let s=255&t;yr(s,n,e+r),t>>>=8,r--}return e+4}function Td(n,e){let t=0,r=e,s=e+4;for(;r<s;){let{value:i,offset:o}=wr(n,r);r=o,t=t<<8>>>0,t+=i}return{value:t,offset:s}}function Rd(n,e,t){return n?n.length<40?fr(n,e,t)+t:e.utf8Write?e.utf8Write(n,t)+t:e.write?e.write(n,t)+t:fr(n,e,t)+t:t}function Pd(n,e){let t=new G(n[e+4]<<24|n[e+5]<<16|n[e+6]<<8|n[e+7],n[e+0]<<24|n[e+1]<<16|n[e+2]<<8|n[e+3],!0);return e+=8,{value:t,offset:e+8}}function Ad(n,e,t){let r=n.low,s=n.high;return e[t]=s>>>24,e[t+1]=s>>>16&255,e[t+2]=s>>>8&255,e[t+3]=255&s,e[t+4]=r>>>24,e[t+5]=r>>>16&255,e[t+6]=r>>>8&255,e[t+7]=255&r,t+=8,t}function wr(n,e){return n.readUInt8?{value:n.readUInt8(e),offset:e+1}:{value:255&n[e],offset:e+1}}function yr(n,e,t){return e.writeUint8?e.writeUint8(n,t):e[t]=255&n,t+1}var Cd=function(n){return new Uint8Array(n)},Od=typeof Buffer<"u"?Buffer.allocUnsafe:kd(Cd,Uint8Array.prototype.subarray),bd=16,kr=32;function Nd(n){let e=0,t={};for(let r=0;r<n.length;r++)t[n[r].cursor_name]=Ui(n[r].cursor_name),e+=14+t[n[r].cursor_name];return[e,t]}function bi(n,e,t){let[r,s]=Nd(n),i=Od(r),o=0;return n.forEach(a=>{console.log("cursor.service",a,a.service),o=yr(0,i,o),console.log("header",o),o=xd(i,o,a.service||0),console.log("service",o),o=yr(s[a.cursor_name],i,o),console.log("service-name",o),o=Rd(a.cursor_name,i,o),console.log("name",o),o=Ad(G.fromNumber(a.cursor||e),i,o),console.log("curvalue",o)}),{frameType:kr,headers:[{key:"cursor_file_name",value:t}],payload:i}}function Dd(n){let e=0,t=[];for(;e<n.byteLength;){let{offset:r}=wr(n,e);e=r;let s={cursor_name:"",cursor:0,service:0},{value:i,offset:o}=Td(n,e);s.service=i,e=o;let{value:a,offset:c}=wr(n,e);e=c,s.cursor_name=$i(n,e,e+a),e+=a;let{value:l,offset:d}=Pd(n,e);s.cursor=l.toNumber(),e=d,t.push(s)}return t}function Ld(){return{frameType:kr,headers:[{key:"cursor_file_name",value:"FILE_NOT_EXIST"}],payload:void 0}}var Sr=class{constructor(e,t,r){this._cursorNameSpace=e,this._cursorFileName=t,this._messageStrategy=r,this._qosDB=qi(this._cursorNameSpace,"cursor_name")}async openDB(){await this._qosDB.openDB()}async getCursors(){if(!this._qosDB.isReady)return;let e=this._messageStrategy,t=await this._qosDB.getAll();switch(console.log("allCursorValues",t),e){case"ALL":return t&&t.length?bi(t,0,this._cursorFileName):void 0;case"INSTANT":return;case"CONTINUE":return t&&t.length?bi(t,0,this._cursorFileName):Ld()}}async set(e,t,r){return console.log("setdb",e,t,r),this._qosDB.set({cursor_name:e,cursor:t,service:r})}async setCursors(e){let t=Dd(e);for(let r of t)console.log("setcursor",t),await this._qosDB.set(r)}async get(e){return(await this._qosDB.get(e))?.cursor}async closeDB(){await this._qosDB.closeDB()}updateCursorFileName(e){this._cursorFileName=e}get isReady(){return this._qosDB.isReady}},Md="__x_msg_qos__";async function Hi(n){if(!this._options.enableQoS)return null;let{aID:e,fpID:t,messageStrategy:r}=this._options,s=n||Md;try{return this._cursorManager?n&&this._cursorManager.updateCursorFileName(n):this._cursorManager=new Sr(`${t}_${e}_${s}`,s,r),this._cursorManager.isReady||await this._cursorManager.openDB(),this._cursorManager}catch{return null}}async function Bd(n,e){let t=we(n.message.headers,"code","-1"),r=we(n.message.headers,"is_ack","1"),s=He(n.message.headers,"x_frontier_msgid"),i=Number(He(n.message.headers,"x_frontier_ttl"))||0,o=vr.call(this,n),a=we(n.message.headers,"x-msg-qos","2"),c=He(n.message.headers,"x-msg-cursor_name"),l=Number(He(n.message.headers,"x-msg-cursor_value"));if(o.isQoSAck)return e();let d=o.isQoSMessage?await Gi.call(this):null;if(n.message.service>0&&r&&!t||n.message.service>0){if(s&&o.isQoSMessage&&d)return await d.get(s)||(this._dispatchMessageEvent(n),await d.set(s,Date.now()+i)),e();if(a){let f=await Hi.call(this);if(!f)return this._dispatchMessageEvent(n),e();let u=await f.get(c)??-1;if(u<l)this._dispatchMessageEvent(n),f.set(c,l,n.message.service);else throw new Error(`recevied message cursor ${l} larger than local cursor ${u}`);return e()}return this._dispatchMessageEvent(n),e()}}async function Fd(n,e){let t=vr.call(this,n);if(!t.isQoSMessage)return e();let r=await Gi.call(this);if(t.isAckCleanupMessage&&t.ackMsgIds.length)for(let s of t.ackMsgIds)await r.del(s);e()}async function Ud(n,e){let t=n.message.frameType===bd,r=n.message.frameType===kr;if(!t&&!r)return e();let s=He(n.message.headers,"cursor_file_name");if(!s)return e();let i=await Hi.call(this,s);if(!i)return e();if(t){let o=await i.getCursors(),a={frameType:o?.frameType,SeqID:G.fromNumber(this._seqId++),LogID:G.fromNumber(this._options.logIDGenerator()),service:9e3,method:5,headers:o?.headers,payload:o?.payload},c=Ni(a);this._ws&&this._ws.readyState&&this._ws.send(c)}if(r){let o=n.message.payload;o&&i.setCursors(o)}}var $d=async function(n,e){this._isInit=!1,clearTimeout(this._connectionTimeoutId),e()},zd=async function(n,e){let t=this._endpointManager?.getCurrentEndpoint();this._debug(`open ${t}`),e()},qd=async function(n,e){if(!this._ws||this._ws.readyState!==this.OPEN)return e();let{pingInterval:t}=this._options;this._endpointManager?.resetEndpointConfig();for(let s=0;s<this._messageQueue.length;s++){let i=this._messageQueue[s];if(this._ws.readyState===this.OPEN&&i!==null)this._ws&&this._ws.send(i),this._messageQueue[s]=null;else break}this._messageQueue=this._messageQueue.filter(s=>!!s),this._pingPongTimeoutId=setTimeout(()=>this._ping(),t),this._dispatchOpenEvent(n),this._isBrowser&&this._ws&&(this._ws.binaryType=this._binaryType);let r=this._endpointManager?.getCurrentEndpoint();this._debug(`open ${r} success`),e()},an=class extends _t{constructor(e){super(),this._miniNavigatorOnline=!0,this._isBrowser=We,this._isNode=hd,this._isMiniTT=Re,this._isMiniWX=yt,this._isWorker=mt,this._messageQueue=[],this._endpointManager=null,this._readyClosed=!1,this._binaryType="arraybuffer",this._connectLock=!1,this._connectionTimeoutId=null,this._reconnectTimeoutId=null,this._pingPongTimeoutId=null,this._seqId=0,this._isInit=!1,this._url="",this._QoSManager=null,this._cursorManager=null,this._pingLossCounter=null,this._protocols="pbbp2",this.CLOSED=3,this.CONNECTING=0,this.OPEN=1,this.CLOSING=2,this._onOpen=i=>{try{Oi(this,i,[$d,qd,zd])}catch(o){let a=Y("error",{message:o.message,code:ke.OPEN_ERROR,error:o});this._dispatchErrorEvent(a)}},this._onMessage=async i=>{let{pingInterval:o,pingFrequency:a}=this._options;if((i.data==="hi"&&a==="always"||a==="auto")&&(this._clearPingTimer(),this.emit("ping_once_success","success"),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),o)),i.data!=="hi")try{Oi(this,i,[vd,Sd,Fd,Ud,Bd,Ed])}catch(c){let l=Y("error",{message:c.message,code:ke.MESSAGE_ERROR,error:c});this._dispatchErrorEvent(l)}},this._onError=i=>{let o=this._endpointManager?.checkReachMaxTries(),a=this._endpointManager?.getCurrentEndpoint();if(o&&!i.message){let c=`connect ${a} fail, max retries reached`;this._dispatchErrorEvent(Y("error",{message:c,code:ke.MAX_RETRIES_ERROR,error:i}));return}this._ws&&this._ws.readyState===this.OPEN&&this._disconnect(),this._dispatchErrorEvent(Y("error",{message:i.message,code:ke.NATIVE_ERROR,error:i}))},this._onClose=async i=>{this._clearTimer(),this._clearPingTimer(),this._removeWsListeners(),this._ws=null,this._connectLock=!1;let o=this._endpointManager?.checkReachMaxTries();if(!o&&this._navigatorOnline()&&!this._readyClosed){let a=this._endpointManager?.getCurrentEndpoint(),c=this._options.reconnectInterceptor(i.code,i.reason);this._dispatchCloseEvent(ie("close",{code:1006,reason:i.reason||`connecting failed, unknown reason, hostname: ${a}`,willReconnect:c})),c&&this._connect();return}if(i.code!==1e3&&this._readyClosed){this._dispatchCloseEvent(ie("close",{code:1e3,reason:"bye"})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}if(i.code!==1e3&&o){let a=this._endpointManager?.getCurrentEndpoint(),c=i.reason;c||(c=await wd(this._url)),c=`connecting failed, ${c}, hostname: ${a}, max retries reached`,this._dispatchCloseEvent(ie("close",{code:i.code,reason:c}));let l=`connect ${a} fail, max retries reached`;this._dispatchErrorEvent(Y("error",{message:l,code:ke.MAX_RETRIES_ERROR})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}if(i.code!==1e3&&!i.reason){let a=this._endpointManager?.getCurrentEndpoint();this._dispatchCloseEvent(ie("close",{code:i.code,reason:`connecting failed, unknown reason, hostname: ${a}`})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}this._dispatchCloseEvent(i),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter()},this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this.onStartReconnect=null,this.onReceiveAck=null,this.onStopImmediatelyReconnect=null,this._handleOnLine=this._handleOnLine.bind(this),this._handleOffLine=this._handleOffLine.bind(this),this._handlePageHide=this._handlePageHide.bind(this),this._handlePageShow=this._handlePageShow.bind(this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:1/0,service:0,logIDGenerator:ql,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:"auto",pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:"CONTINUE",env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:t,ws:r}=e,s=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(!s||s.length===0)throw new Error("please provide valid url");if(!pd(r))throw new Error("please provide ws params, WebSocket constructor is undefined");Object.assign(this._options,e),this._endpointManager=new on(s,this._options.maxRetries),this._pingLossCounter=new hr(this._options.pingLossCount),this._options.automaticOpen&&(this._isInit=!0,this._connect()),this._options.listenNetworkChanged&&(this._isMiniTT||this._isMiniWX?this._onPageNetWorkChange():this._isBrowser&&this._initGlobalEventListener())}_handleOnLine(){this._options.disableAutoReconnect||this._readyClosed||this._handleReconnect()}_handleOffLine(){this._destroyWebSocket();let e=Ci("reconnect",{message:"stop immediately reconnect"});this.onStopImmediatelyReconnect&&this.onStopImmediatelyReconnect(e)}_initGlobalEventListener(){this._isBrowser&&window.addEventListener("online",this._handleOnLine),this._isBrowser&&window.addEventListener("offline",this._handleOffLine),this._isBrowser&&window.addEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.addEventListener("pageshow",this._handlePageShow)}_dropGlobalEventListener(){this._isBrowser&&window.removeEventListener("online",this._handleOnLine),this._isBrowser&&window.removeEventListener("offline",this._handleOffLine),this._isBrowser&&window.removeEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.removeEventListener("pageshow",this._handlePageShow)}_handlePageHide(e){e.persisted||(this._isBrowser&&window.removeEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.removeEventListener("pageshow",this._handlePageShow),this.close()),this._isBrowser&&window.removeEventListener("online",this._handleOnLine),this._isBrowser&&window.removeEventListener("offline",this._handleOffLine)}_handlePageShow(e){e.persisted&&(this._navigatorOnline()&&(!this._ws||this._ws.readyState!==this.OPEN||this._ws.readyState!==this.CONNECTING)&&this._handleOnLine(),this._isBrowser&&window.addEventListener("online",this._handleOnLine),this._isBrowser&&window.addEventListener("offline",this._handleOffLine))}async _generateUrl(e){let{fpID:t,deviceID:r,bddID:s,ttwID:i,accessKey:o,aID:a,customParams:c={},enableAutoAck:l,enableQoS:d,QoSLevel:f,env:u}=this._options,p,m,_;this._isBrowser||this._isMiniWX||this._isMiniTT?(p=location&&location.protocol=="https:"?"wss://":"ws://",m=e.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),_=/^wss(.*:\/\/)/.test(e)?e:`${p}${m}`):(p="wss://",m=e.replace(/(^http)((?:[s]*:\/\/))/,""),_=/(^ws)((?:[s]*:\/\/))/.test(m)?m:`${p}${m}`);let v=s?"bd_did":i?"ttwid":"device_id",C=s||i||r;if(!C||!v)throw new Error("please provide bddID, deviceID or ttwID");let F=typeof c=="function"?await c():c,b=u?_d(u.xUseEnv,u.xTTEnv):{},P=Object.assign({device_platform:"web",version_code:"fws_1.0.0",access_key:o,fpid:t,aid:a,[v]:C,xsack:l?1:0,xaack:l?1:0,xsqos:d?1:0,qos_level:d?f:void 0,qos_sdk_version:2,...b},F),g=Object.keys(P).reduce((E,I)=>P[I]!==void 0?`${E}${E?"&":"?"}${I}=${P[I]}`:E,"");return`${_}/ws/v2${g}`}async _connect(){if(!(this._connectLock||this._readyClosed)){this._connectLock=!0;try{let e=this._endpointManager?.checkCurrentEndpointReachedMaxRetries(),{timeoutInterval:t}=this._options;if(e){let s=this._endpointManager?.getCurrentEndpoint(),i=this._endpointManager?.replaceBackupEndpointAndUpdateCount(),o=this._endpointManager?.getCurrentEndpointTriesCount();if(i){let a=`connect ${s} timeout, max retries reached, will use backup endpoint ${i} to retry`,c=Y("error",{message:a,code:ke.MAX_RETRIES_ERROR});this._debug(a),this._dispatchErrorEvent(c),this._url=await this._generateUrl(i),this._debug(`connect ${i} ${o} times`),this._removeWsListeners()}else{let a=`connect ${s} timeout, max retries reached`;this._debug(a),this._dispatchErrorEvent(Y("error",{message:a,code:ke.MAX_RETRIES_ERROR}));return}}else{let s=this._endpointManager?.getCurrentEndpointAndUpdateCount(),i=this._endpointManager?.getCurrentEndpointTriesCount();this._url=await this._generateUrl(s||""),this._debug(`connect ${s} ${i} times`),this._removeWsListeners()}if(this._isInit)this._isInit=!1;else{let s=Ci("reconnect",{message:"start"});this.onStartReconnect&&this.onStartReconnect(s)}let r=this._endpointManager?.getCurrentEndpointTriesCount()||0;r>1&&await this._wait(r-1),this._debug(`connecting url: ${this._url} protocols: ${this._protocols}`),this._ws=gd({url:this._url,protocols:[this._protocols],headers:this._options.miniProgramParams.customHttpHeader},this._options.ws),(this._isBrowser||this._isWorker)&&this._ws&&(this._ws.binaryType=this._binaryType),this._addWsListeners(),this._connectionTimeoutId=setTimeout(this._onTimeout.bind(this),t)}catch(e){throw this._connectLock=!1,e}}}_clearTimer(){clearTimeout(this._connectionTimeoutId),this._connectionTimeoutId=null}_clearPingTimer(){clearTimeout(this._pingPongTimeoutId),clearTimeout(this._reconnectTimeoutId),this._pingPongTimeoutId=null,this._reconnectTimeoutId=null}_debug(...e){this._options.debug&&console.log.apply(console,["FRONTIER>",...e])}_getIntervalValue(e){let{initReconnectInterval:t,maxReconnectInterval:r,reconnectIntervalGrowFactor:s}=this._options,i=t*Math.pow(s,e-1);return i>r?r:i}_ping(){if(this._ws&&this._ws.readyState===this.CONNECTING){this._clearPingTimer(),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),this._options.pingInterval);return}if(!this._ws||this._ws.readyState!==this.OPEN)return void this._handleReconnect();this._ws&&this._ws.send("hi"),this._reconnectTimeoutId=setTimeout(this._handleReconnectTimeout.bind(this),this._options.pingTimeoutInterval)}_handleReconnectTimeout(){this._pingLossCounter?.addCount(),this.emit("ping_once_timeout","timeout"),this._pingLossCounter?.checkReachMaxCount()?this._handleReconnect():this._ping()}_navigatorOnline(){return this._isMiniTT||this._isMiniWX?this._miniNavigatorOnline:(this._isBrowser||this._isWorker)&&this._options.listenNetworkChanged?navigator.onLine:!0}_handleReconnect(){!this._navigatorOnline()||this._readyClosed||(this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter(),this._ws?this._disconnect(1001,"going away, try reconnecting server",!0):this._connect())}_onPageNetWorkChange(){this._isMiniTT?tt.onNetworkStatusChange(({isConnected:e})=>{this._miniNavigatorOnline=e,e?this._handleOnLine():this._handleOffLine()}):this._isMiniWX&&wx.onNetworkStatusChange(({isConnected:e})=>{this._miniNavigatorOnline=e,e?this._handleOnLine():this._handleOffLine()})}_wait(e){return new Promise(t=>{setTimeout(t,this._getIntervalValue(e))})}_disconnect(e=1e3,t="",r=!1){this._ws&&this._destroyWebSocket(e,t,r)}_onTimeout(){let e=this._endpointManager?.getCurrentEndpoint();this._debug(`connect ${e} timeout`),this._disconnect(1001,"timeout, try reconnecting",!0)}_sendAck(e){let t=Ti(e);this._ws&&this._ws.readyState===this.OPEN&&(this._ws&&this._ws.send(t),this._debug("send_ack",e))}_removeWsListeners(){this._ws&&(this._ws.removeEventListener("open",this._onOpen),this._ws.removeEventListener("close",this._onClose),this._ws.removeEventListener("message",this._onMessage),this._ws.removeEventListener("error",this._onError))}_addWsListeners(){this._ws&&(this._ws.addEventListener("open",this._onOpen),this._ws.addEventListener("close",this._onClose),this._ws.addEventListener("message",this._onMessage),this._ws.addEventListener("error",this._onError))}_wsInstanceClose(e=1e3,t=""){try{this._ws&&this._ws.close(e,t)}catch{}}_destroyWebSocket(e=1e3,t="",r=!1){if(this._clearPingTimer(),this._clearTimer(),this._removeWsListeners(),this._wsInstanceClose(1e3,t),this._connectLock=!1,r&&this._navigatorOnline()&&!this._readyClosed){if(this._endpointManager?.checkReachMaxTries()){let i=this._endpointManager?.getCurrentEndpoint();this._dispatchCloseEvent(ie("close",{code:1006,reason:`connect ${i} timeout, max retries reached`,wasClean:!0}))}else{let i=this._options.reconnectInterceptor(e,t);this._dispatchCloseEvent(ie("close",{code:e,reason:t,wasClean:!0,willReconnect:i})),i&&this._connect()}return}this._navigatorOnline()||this._readyClosed?this._dispatchCloseEvent(ie("close",{code:e,reason:"bye"})):this._dispatchCloseEvent(ie("close",{code:1006,reason:"going away, network offline"})),this._ws=null,this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter()}_dispatchOpenEvent(e){this.emit("open",e),this.onopen&&this.onopen(e)}_dispatchMessageEvent(e){this.emit("message",e),this.onmessage&&this.onmessage(e)}_dispatchAckMessageEvent(e){this.emit("ack",e),this.onReceiveAck&&this.onReceiveAck(e)}_dispatchErrorEvent(e){this.emit("error",e),this.onerror&&this.onerror(e)}_dispatchCloseEvent(e){this.emit("close",e),this.onclose&&this.onclose(e)}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return this._endpointManager?.getCurrentEndpointTriesCount()||0}get bufferedAmount(){return this._messageQueue.reduce((t,r)=>(t+=r&&r.byteLength||0,t),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.automaticOpen?this.CONNECTING:this.CLOSED}get url(){return this._ws?this._ws.url:this._url}close(e=1e3,t){if(this._readyClosed=!0,this._clearTimer(),this._clearPingTimer(),this._dropGlobalEventListener(),this._QoSManager?.closeDB(),!this._ws)return void this._debug("close, ws instance not initialized");if(this._ws.readyState===this.CLOSED||this._ws.readyState===this.CLOSING)return void this._debug("close, ws already closed");this._destroyWebSocket(e,t)}async send(e,t){if(e==null)throw new Error("please provide a valid data, data must be a string or an arraybuffer");typeof e=="number"&&(e=JSON.stringify(e)),typeof e!="string"&&!(e instanceof ArrayBuffer)&&!(e.buffer&&e.buffer instanceof ArrayBuffer)&&(e=JSON.stringify(e));let r=await zi(e),s=md(e),{method:i=0,service:o=this._options.service,logID:a=this._options.logIDGenerator(),headers:c=this._options.headers,payloadEncoding:l=this._options.payloadEncoding,payloadType:d=this._options.payloadType,logIDNew:f=this._options.logIDNewConfig.enableAutoGenerateLogIDNew?zl(this._options.logIDNewConfig.userIp):""}=t||{};if(!o)throw new Error("please provide a valid service");let u={SeqID:G.fromNumber(this._seqId++),LogID:G.fromNumber(a),service:o,method:i,headers:c,payloadEncoding:l instanceof Object?l.encoding?l.encoding:"":l,payloadType:d instanceof Object?d.type?d.type:s:d||s,payload:r,LogIDNew:f},p=Ti(u);return this._ws&&this._ws.readyState===this.OPEN?(this._ws&&this._ws.send(p),this._debug("sent",u)):this._messageQueue.length<this._options.maxMessageQueueLength?(this._messageQueue.push(p),this._debug("enqueue",u)):(this._messageQueue.shift(),this._messageQueue.push(p)),{seqID:this._seqId,logID:a,logIDNew:f}}async reconnect(e){let{url:t}=e||{},r=Array.isArray(t)?t:typeof t=="string"?[t]:[];e&&Object.assign(this._options,e),r&&r.length?this._endpointManager=new on(r,this._options.maxRetries):this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter(this._options.pingLossCount),this._readyClosed=!1,this._ws&&this._ws.readyState!==this.CLOSED?this._disconnect(1e3,"manual reconnecting",!0):(this._isInit=!0,this._connect())}async connect(){this._connectLock||(this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter(),this._readyClosed=!1,this._isInit=!0,this._connect())}addEventListener(e,t){this.on(e,t)}dispatchEvent(e){let{type:t}=e;this.emit(t,e)}removeEventListener(e,t){this.off(e,t)}pingOnce(){return new Promise((e,t)=>{this._clearPingTimer(),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),this._options.pingInterval);let r=()=>{e("success"),this.off("ping_once_success",r),this.off("ping_once_timeout",s)},s=()=>{t("timeout"),this.off("ping_once_success",r),this.off("ping_once_timeout",s)};this.on("ping_once_success",r),this.on("ping_once_timeout",s),this._ping()})}};var lf=he($o(),1),df=he(mn(),1),uf=he(Ve(),1),ff=he(Dr(),1),hf=he(Br(),1),gf=he(Gr(),1),Qo=he(Sn(),1),pf=he(Vo(),1);var Ko=Qo.default;k();var D=w("upstream.frontier"),Yo="application/json",Zo="none",vn=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandler=null;opened=!1;openCount=0;async start(){if(this.fws){D.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:_s,...Bt(this.opts.ppeOverride)};class t extends Ko{constructor(a){super(a,ms,{headers:e})}send(a,...c){if(fs("debug"))try{let l;typeof a=="string"?l=Buffer.from(a,"utf8"):a instanceof Buffer?l=a:a instanceof ArrayBuffer?l=new Uint8Array(a):ArrayBuffer.isView(a)?l=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):l=new Uint8Array(0);let d=Buffer.from(l.slice(0,128)).toString("hex");D.debug("WS raw frame out",{bytes:l.byteLength,headHex:d})}catch(l){D.warn("WS raw frame dump failed",{err:String(l)})}super.send(a,...c)}}let r=Ss(this.opts.urlOverride),s={url:r,ws:t,fpID:ps,aID:Mt,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Yo,force:!0},payloadEncoding:{encoding:Zo,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,debug:this.opts.debug??!1},i=new an(s);i.onopen=()=>{this.opened=!0,this.openCount+=1;let o=this.openCount===1;D.info("frontier opened",{url:r,remoteDeviceId:this.opts.handshake.deviceId,initial:o,openCount:this.openCount}),this.connectHandler&&Promise.resolve(this.connectHandler({initial:o})).catch(a=>D.warn("onConnect handler threw (ignored)",{err:String(a)}))},i.onclose=o=>{this.opened=!1,D.info("frontier closed",{code:o.code,reason:o.reason,willReconnect:o.willReconnect})},i.onerror=o=>{D.warn("frontier error",{code:o.code,msg:o.message})},i.onmessage=o=>this.handleMessage(o),this.fws=i,await i.connect()}async stop(e){let t=this.fws;if(t){this.fws=null,this.opened=!1;try{t.close(1e3,e??"bridge shutdown")}catch(r){D.warn("frontier close threw (ignored)",{err:String(r)})}}}async send(e){let t=this.fws;if(!t)throw new h("UPSTREAM_DISCONNECTED","frontier upstream not started");let r=JSON.stringify(e),s=e;ea(s)||D.info("frontier frame out",{method:s.method,jsonrpcId:s.id,size:r.length});try{await t.send(r,{service:33555712,method:1,payloadType:Yo,payloadEncoding:Zo})}catch(o){throw D.warn("frontier frame send failed",{method:s.method,jsonrpcId:s.id,err:String(o)}),new h("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(o)}`,{cause:o})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandler=e}isConnected(){return this.opened&&this.fws?.readyState===1}handleMessage(e){let t=e.message?.service;if(t!==33555712){D.debug("drop non-adapter frontier frame",{service:t});return}let r=yf(e);if(!r){D.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){D.debug("frame received but no onFrame handler",{size:r.length});return}let s;try{s=JSON.parse(r)}catch(o){D.warn("frontier message JSON parse failed",{err:String(o),head:r.slice(0,80)});return}let i=s;ea(i)||D.info("frontier frame in",{logid:wf(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:i.id,method:i.method,body:_f(r)}),Promise.resolve(this.handler(s)).catch(o=>D.warn("frontier frame handler threw",{err:String(o)}))}};function ea(n){return n.method==="_agent/health"?!0:typeof n.id=="string"&&n.id.startsWith("agent.health_")}var ta=2e3;function _f(n){return n.length<=ta?n:`${n.slice(0,ta)}...<truncated, total ${n.length} chars>`}function wf(n){return n?n.high===0?String(n.low>>>0):`${n.high.toString(16)}${(n.low>>>0).toString(16).padStart(8,"0")}`:""}function yf(n){let e=n.message;if(e?.textPayload)return e.textPayload;let t=e?.payload;if(!t)return null;try{return Buffer.from(t).toString("utf8")}catch{return null}}k();var Wr=w("upstream.switchable"),kn=class{inner;handler=null;connectHandler=null;constructor(e){this.inner=e}async swap(e,t){if(this.inner===e)return;Wr.info("swap upstream",{reason:t});let r=this.inner;this.inner=e,this.handler&&e.onFrame(this.handler),this.connectHandler&&e.onConnect&&e.onConnect(this.connectHandler);try{await e.start()}catch(s){throw Wr.error("swap target start failed, reverting",{err:String(s)}),this.inner=r,s}await r.stop(t??"swapped").catch(s=>Wr.warn("previous upstream stop threw (ignored)",{err:String(s)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandler=e,this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};k();var jr=w("upstream"),Rt=class{handler=null;async start(){jr.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){jr.info("NoopUpstream stopped",{reason:e})}async send(e){jr.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};k();z();k();z();import{execSync as Sf}from"node:child_process";import{readFileSync as na,unlinkSync as Ef}from"node:fs";import{mkdir as vf,readFile as ra,unlink as sa,writeFile as kf}from"node:fs/promises";import{dirname as If}from"node:path";var xf=w("single-instance"),In=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??T().pidFile,e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();return e!==null&&this.isAlive(e)?{kind:"already-running",pid:e}:(e!==null&&(xf.warn("removing stale pid file",{stalePid:e}),await sa(this.pidFile).catch(()=>{})),await vf(If(this.pidFile),{recursive:!0}),await kf(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await ra(this.pidFile,"utf8")).trim()===String(process.pid)&&await sa(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await ra(this.pidFile,"utf8"),t=Number.parseInt(e.trim(),10);return Number.isFinite(t)&&t>0?t:null}catch(e){if(e.code==="ENOENT")return null;throw e}}isAlive(e){try{process.kill(e,0)}catch(t){return t.code==="EPERM"}return this.matchesDaemonTitle(e)}matchesDaemonTitle(e){try{let t=na(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(t.includes("coze-bridge-daemon")||t.includes("lib/index.js"))}catch{}try{let t=Sf(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return t.trim()?t.includes("coze-bridge-daemon")||t.includes("lib/index.js"):!1}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{na(this.pidFile,"utf8").trim()===String(process.pid)&&Ef(this.pidFile)}catch{}})}};var y=w("daemon"),Tf="coze-bridge-daemon";async function aa(){let n=new In({processTitle:Tf}),e=await n.acquire();if(e.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${e.pid})`);let t=await nn(),r=t??{};Bn({pid:process.pid}),y.info(t?"loaded bridge config":"initialized bridge config");try{let g=new ze;r.frameworksCache=await g.detectAll(),y.info("refreshed frameworks_cache",{detected:Object.keys(r.frameworksCache)})}catch(g){y.warn("framework detection failed",{err:String(g)})}await qe(r);let s=new kn(new Rt),i=T(),o=null,a=new rn({upstream:s,paths:i,bridgeConfig:r,sessionSpawner:async(g,E,I,Q)=>{if(!o)throw new Error("agentManager not ready");return o.spawnSessionDownstream(g,E,I,Q)}});await Pf(i,a);let c=new tn({paths:i,config:r,registry:a});o=c;let l,d,f=null,u=null;a.registerExtension("_agent/create",async g=>c.createAgent(g.params)),a.registerExtension("_agent/health",async()=>({ok:!0}));let p={},m=new Ut({agents:a.agents,disposeAndMarkDisconnected:async(g,E)=>{let I=a.agents.get(g);I&&(await c.cleanupOpenclawSessionProviders(I).catch(Q=>y.warn("cleanup openclaw providers failed (ignored)",{agentId:g,err:String(Q)})),await I.dispose(`disconnect: ${E}`).catch(Q=>y.warn("dispose during disconnect failed (ignored)",{agentId:g,err:String(Q)})),I.status="disconnected",a.unregister(g)),a.disconnectedAgents.add(g)},detailSyncer:async g=>{if(!p.ref)throw new Error("agent-detail-sync not initialized yet");await p.ref.syncOne(g)},openclawRepair:async(g,E)=>{await c.openclawRepair(g,E)}});a.registerExtension("_agent/listSkills",g=>m.listSkills(g.params)),a.registerExtension("_agent/addSkills",g=>m.addSkills(g.params)),a.registerExtension("_agent/removeSkills",g=>m.removeSkills(g.params)),a.registerExtension("_agent/getFileTree",g=>m.getFileTree(g.params)),a.registerExtension("_agent/getFileContent",g=>m.getFileContent(g.params)),a.registerExtension("_agent/update",g=>m.updateAgent(g.params)),a.registerExtension("_agent/disconnect",g=>m.disconnectAgent(g.params)),a.registerExtension("_agent/switchModel",g=>m.switchModel(g.params)),a.registerExtension("_agent/reset",g=>m.resetAgent(g.params)),a.registerExtension("_agent/repair",g=>m.repairAgent(g.params));let _=new Lt({paths:i,handlers:m,sendDetail:g=>a.sendRequest("_agent/detail",g)});p.ref=_,s.onConnect(({initial:g})=>{y.info("frontier upstream connected, triggering detail sync",{initial:g}),_.syncAll(g?"initial-connect":"reconnect").catch(E=>y.warn("detail sync top-level error (ignored)",{err:String(E)}))});let v=new sn({paths:i,routes:[{method:"GET",path:"/status",handler:async()=>({running:!0,pid:process.pid,agents:[...a.agents.keys()],deviceId:f??"",frameworksCache:r.frameworksCache??{}})},{method:"POST",path:"/pair",handler:async g=>{let E=g,I=E?.privatecode,Q=E?.pairing_code;if(!I||!Q)throw new h("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ne=Ft(E.env),nt=E.handshake_url,bn=E.frontier_url,Nn=Rf(E.env,nt,bn),ss=!!l&&l!==I,is=d!==void 0&&d!==Nn,os=ss||is;if(os){y.warn("pair config switched, resetting agents",{pcChanged:ss,envChanged:is,previousPc:l?ia(l):"",nextPc:ia(I),previousEnvKey:d??"",nextEnvKey:Nn});for(let U of[...a.agents.values()])await U.dispose("pair config switch").catch(()=>{}),a.agents.delete(U.agentId);await s.swap(new Rt,"pair switch").catch(()=>{})}let as=await vs({privatecode:I,...nt?{endpoint:nt}:{},ppeOverride:Ne});f=as.deviceId,Bn({deviceId:f,pid:process.pid}),ri({patToken:I,env:E.env}).catch(U=>y.warn("coze-cli setup error (ignored)",{err:String(U)}));let Sa=new vn({handshake:as,privatecode:I,...bn?{urlOverride:bn}:{},ppeOverride:Ne});await s.swap(Sa,"pair");try{let U=new ze;r.frameworksCache=await U.detectAll(),await qe(r),y.info("frameworks_cache refreshed before pair",{detected:Object.keys(r.frameworksCache)})}catch(U){y.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(U)})}let Ea=Object.keys(r.frameworksCache??{});try{let U=await a.sendRequest("_agent/pair",{pairCode:Q,patToken:I,frameworks:Ea,_meta:{cozeDeviceId:f}});y.info("_agent/pair ok",{pairResult:U}),l=I,d=Nn,u||(u=new qt({core:a,getDeviceId:()=>f??""})),u.start(),os&&oa(i,c).catch(De=>y.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Dn;return E.agent_id&&(Dn=await Af(E.agent_id,i,c,De=>a.sendRequest("_agent/detail",De)).catch(De=>(y.error("--agent-id ensureAgent failed",{agentId:E.agent_id,err:String(De)}),{ok:!1,agentId:E.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...Dn?{agent:Dn}:{}}}catch(U){return y.error("_agent/pair failed",{err:String(U)}),{ok:!1,note:`pair failed: ${String(U)}`}}}},{method:"POST",path:"/_agent/create",handler:async g=>{let E=g;return{ok:!0,result:await c.createAgent(E)}}},{method:"POST",path:"/refresh",handler:async()=>{y.info("IPC /refresh: re-detecting frameworks");let g=new ze;return r.frameworksCache=await g.detectAll(),await qe(r),{ok:!0,frameworks:r.frameworksCache}}},{method:"POST",path:"/shutdown",handler:async()=>(y.info("IPC /shutdown received"),setImmediate(()=>{P.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:C,token:F}=await v.start();await a.start(),oa(i,c).catch(g=>y.warn("auto-revive top-level error (ignored)",{err:String(g)}));let b=null,P={port:C,token:F,core:a,ipc:v,shutdown(g){return b||(y.info("daemon shutdown",{reason:g}),b=(async()=>{u?.stop(),await a.stop(g),await v.stop(),await n.release()})(),b)}};for(let g of["SIGTERM","SIGINT"])process.on(g,()=>{P.shutdown(g).then(()=>process.exit(0))});return y.info("daemon ready",{port:C,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(r.frameworksCache??{}),libVersion:r.libVersion??"dev"}),P}function ia(n){return n.length<=8?"***":`${n.slice(0,4)}***${n.slice(-4)}`}function Rf(n,e,t){return`${n??""}|${e??""}|${t??""}`}async function Pf(n,e){let{readdir:t}=await import("node:fs/promises"),r;try{r=await t(n.agentsRoot)}catch{return}let{loadAgentConfig:s,enforceAgentConfigMode:i}=await Promise.resolve().then(()=>(ge(),Dt));for(let o of r){await i(o,n).catch(a=>y.warn("enforceAgentConfigMode failed (ignored)",{agentId:o,err:String(a)}));try{let a=await s(o,n);a?.disconnectedAt&&(e.disconnectedAgents.add(o),y.info("agent marked disconnected on startup",{agentId:o,disconnectedAt:a.disconnectedAt,reason:a.disconnectReason??""}))}catch(a){y.warn("failed to load agent config on startup, skipping",{agentId:o,err:String(a)})}}}async function Af(n,e,t,r){let{loadAgentConfig:s}=await Promise.resolve().then(()=>(ge(),Dt)),i=await s(n,e);if(i){y.info("--agent-id: local config found, reconnecting",{agentId:n,framework:i.framework,hadDisconnect:!!i.disconnectedAt});let l={agentId:i.agentId,framework:i.framework,...i.cozeIdentity?{cozeIdentity:i.cozeIdentity}:{},...i.model?{model:i.model}:{}};return await t.createAgent(l),{ok:!0,agentId:n,note:i.disconnectedAt?"revived from local config":"connected from local config"}}y.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:n});let o=await r({_meta:{cozeAgentId:n}});if(!o.framework)throw new h("AGENT_NOT_FOUND",`agent ${n} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let a={agentId:o.agentId,framework:o.framework,...o.cozeIdentity?{cozeIdentity:o.cozeIdentity}:{},...o.model?{model:o.model}:{},...o.deployType?{_meta:{cozeDeployType:o.deployType}}:{}};await t.createAgent(a);let c=o.deployType==="cloud"&&o.framework==="openclaw";return{ok:!0,agentId:n,note:c?"cloud agent acknowledged":"created from cloud detail"}}async function oa(n,e){let{readdir:t}=await import("node:fs/promises"),r;try{r=await t(n.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(r.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:s}=await Promise.resolve().then(()=>(ge(),Dt));y.info("auto-revive: scanning local agents on startup",{count:r.length});let i=0,o=0;for(let a of r){let c;try{c=await s(a,n)}catch(l){y.warn("auto-revive: load config failed (skipping)",{agentId:a,err:String(l)}),o+=1;continue}if(!c){o+=1;continue}if(c.disconnectedAt){y.info("auto-revive: skip disconnected agent",{agentId:a,disconnectedAt:c.disconnectedAt}),o+=1;continue}try{y.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:a,framework:c.framework}),await e.createAgent({agentId:c.agentId,framework:c.framework,...c.cozeIdentity?{cozeIdentity:c.cozeIdentity}:{},...c.model?{model:c.model}:{},...c.deployType?{_meta:{cozeDeployType:c.deployType}}:{}}),i+=1}catch(l){y.warn("auto-revive: createAgent failed (skipping)",{agentId:a,framework:c.framework,err:String(l)}),o+=1}}return y.info("auto-revive: done",{revived:i,skipped:o,total:r.length}),{revived:i,skipped:o,total:r.length}}Vr();z();import{readFile as la}from"node:fs/promises";var Ee=class{paths;constructor(e){this.paths=e??T()}async probe(e=1e3){let t=await this.readAuth();if(!t)return{kind:"not-running"};try{let r=await this.fetch(t,{method:"GET",path:"/status",timeoutMs:e});return r.status===200?{kind:"connected",...t}:{kind:"stale",reason:`unexpected status ${r.status}`}}catch(r){return{kind:"stale",reason:Ff(r)}}}async request(e){let t=await this.readAuth();if(!t)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(t,e)}async readAuth(){try{let[e,t]=await Promise.all([la(this.paths.portFile,"utf8"),la(this.paths.tokenFile,"utf8")]),r=Number.parseInt(e.trim(),10),s=t.trim();return!Number.isFinite(r)||r<=0||!s?null:{port:r,token:s}}catch(e){if(e.code==="ENOENT")return null;throw e}}async fetch(e,t){let r=t.body!==void 0,s={Authorization:`Bearer ${e.token}`};r&&(s["content-type"]="application/json");let i=new AbortController,o=setTimeout(()=>i.abort(),t.timeoutMs??5e3);try{let a=await fetch(`http://127.0.0.1:${e.port}${t.path}`,{method:t.method,headers:s,body:r?JSON.stringify(t.body):void 0,signal:i.signal}),c=await a.text();return{status:a.status,body:Bf(c)}}finally{clearTimeout(o)}}};function Bf(n){if(!n)return null;try{return JSON.parse(n)}catch{return n}}function Ff(n){return n instanceof Error?n.message:String(n)}k();z();import{copyFile as da,mkdir as Uf,readFile as Qr,writeFile as $f}from"node:fs/promises";import{dirname as zf,resolve as Kr,sep as xn}from"node:path";import{fileURLToPath as qf}from"node:url";k();z();var ua=w("dist-install");function Gf(n){let e=qf(n),t=zf(e),r=`${xn}src${xn}`;if(t.includes(r)||t.endsWith(`${xn}src${xn}cli`))return null;let s=Kr(t,"index.js"),i=Kr(t,"..","package.json");return{dist:s,pkgJson:i}}async function fa(n={}){let e=n.paths??T(),t=Gf(import.meta.url),r=n.sourceDist??t?.dist,s=n.sourcePackageJson??t?.pkgJson;if(!r||!s)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};let i;try{i=JSON.parse(await Qr(s,"utf8")).version??"unknown"}catch(f){return ua.warn("cannot read source package.json,skip dist install",{err:String(f)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(f)}`}}let o=await nn(e.configFile)??{},a=o.libVersion;if(a===i)try{return await Qr(e.libEntry),{kind:"already-current",libVersion:i}}catch{}await Uf(e.libDir,{recursive:!0}),await da(r,e.libEntry),await da(`${r}.map`,`${e.libEntry}.map`).catch(()=>{});let c=Kr(e.libDir,"package.json"),l=`${JSON.stringify({type:"module"},null,2)}
|
|
97
|
-
`;return await
|
|
88
|
+
${c}`}var Ae=N("agent-detail-sync"),ln=class{constructor(e){this.opts=e}opts;async syncAll(e){let i=this.opts.paths.agentsRoot,a;try{a=await V0(i)}catch(c){Ae.info("agents dir not found, skip detail sync",{root:i,err:String(c)});return}Ae.info("starting detail sync",{reason:e,count:a.length});for(let c of a)try{await this.syncOne(c)}catch(u){Ae.warn("detail sync failed for agent, skipping",{agentId:c,err:String(u)})}Ae.info("detail sync done",{reason:e})}async syncOne(e){let i=await he(e,this.opts.paths);if(!i){Ae.info("detail sync: agent config missing, skip",{agentId:e});return}let a;try{a=await this.opts.sendDetail({_meta:{cozeAgentId:e}})}catch(f){Ae.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});return}if(a.agentId&&a.agentId!==e){Ae.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:a.agentId});return}let c=!1,u=!1;if(a.agentName&&a.agentName!==i.agentName&&(i.agentName=a.agentName,c=!0),a.description!==void 0&&a.description!==i.description&&(i.description=a.description,c=!0),a.cozeIdentity&&a.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=a.cozeIdentity,c=!0,u=!0),a.deployType&&Ae.info("detail.deployType",{agentId:e,deployType:a.deployType}),!c){Ae.debug("detail sync: no diff",{agentId:e});return}await be(i,this.opts.paths),Ae.info("detail sync: config updated",{agentId:e,identityChanged:u,agentName:i.agentName}),u&&(await pt(i.workspace,i.framework,e,i.cozeIdentity),await this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};Je();import{spawn as hi}from"node:child_process";import{lstat as Pr,mkdir as Z0,readFile as gi,readdir as Q0,rm as ec,stat as tc,writeFile as di}from"node:fs/promises";import{join as Pe,normalize as nc,relative as pi,resolve as rc,sep as mi}from"node:path";var ke={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",DELETE:"_agent/delete"};function Ot(r){return r?.cozeDeployType==="cloud"?"cloud":"local"}function Xs(r){let{_meta:e,...i}=r;return{stripped:i,meta:e}}function mt(r){if(!r?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return r.cozeAgentId}var C=class extends Error{code;retriable;cause;constructor(e,i,a){super(i),this.name="BridgeError",this.code=e,this.retriable=a?.retriable??!1,a?.cause!==void 0&&(this.cause=a.cause)}};K();le();function qe(r,e){if(Ot(r)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}K();var hn="1008033",Ys="1289";var $s="pbbp2",Zs="https://www.coze.cn",Qs="/api/coze_claw/resource/get_frontier_key",X0="https://www.coze.cn",Y0="wss://frontier.coze.cn";function ei(r){return r??process.env.COZE_BRIDGE_HANDSHAKE_URL??X0}function ti(r){return r??process.env.COZE_BRIDGE_FRONTIER_URL??Y0}function gn(r){let e={},i=r?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,a=r?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return i&&(e["x-tt-env"]=i),a&&(e["x-use-ppe"]=a),e}function pn(r){return r?r.startsWith("boe_")?{ttEnv:r}:{ttEnv:r,usePpe:"1"}:{}}var ni=N("handshake");async function ri(r){let e=ei(r.endpoint),i=r.timeoutMs??1e4,a=`${$0(e)}${Qs}?aid=${encodeURIComponent(hn)}`,c={Authorization:`Bearer ${r.privatecode}`,Accept:"application/json",...gn(r.ppeOverride)},u=new AbortController,f=setTimeout(()=>u.abort(),i);ni.info("frontier key handshake",{base:e});try{let h=await fetch(a,{method:"GET",headers:c,signal:u.signal}),m=h.headers.get("x-tt-logid")??"",_=h.headers.get("x-tt-trace-id")??"";if(!h.ok){let A=await h.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${h.status} logid=${m}: ${A.slice(0,200)}`)}let y=await h.json();if(y.code!==void 0&&y.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${y.code} msg=${y.msg??"-"} logid=${m}`);let v=y.data?.access_key,S=y.data?.device_id;if(!v||!S)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id logid=${m}: ${JSON.stringify(y)}`);return ni.info("handshake ok",{remoteDeviceId:S,logid:m,traceId:_}),{accessKey:v,deviceId:S}}catch(h){throw h instanceof C?h:h.name==="AbortError"?new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${i}ms)`):new C("UPSTREAM_HANDSHAKE_FAILED",String(h),{cause:h})}finally{clearTimeout(f)}}function $0(r){return r.endsWith("/")?r.slice(0,-1):r}var Ar="https://llm-gateway.coze.cn",Ie="auto";function si(r){return{model:r.model??Ie,...r.modelToken?{modelToken:r.modelToken}:{}}}function ii(r){return!r||r===Ie}function oi(r){let e={};return r.modelToken?(e.ANTHROPIC_BASE_URL=Ar,e.ANTHROPIC_AUTH_TOKEN=r.modelToken,e.ANTHROPIC_MODEL=r.model||Ie):ii(r.model)||(e.ANTHROPIC_MODEL=r.model),e}function ai(r){let e=[];return r.modelToken?e.push("-c",`model="${r.model||Ie}"`):ii(r.model)||e.push("-c",`model="${r.model}"`),r.modelToken&&(e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Ar}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"')),e}function ci(r){return r.modelToken?{OPENAI_API_KEY:r.modelToken}:{}}function kr(r){let{ttEnv:e,usePpe:i}=pn(r),a={};return e&&(a["x-tt-env"]=e),i&&(a["x-use-ppe"]=i),a}function xi(r,e){if(!r.modelToken)return{};let i=kr(e);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,u])=>`${c}:${u}`).join(`
|
|
89
|
+
`)}}function Ir(r){return`coze-session-${r.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function ui(r,e){if(!r.modelToken)return null;let i=r.model||Ie,a=kr(e),c={baseUrl:`${Ar}/v1`,api:"openai-completions",apiKey:r.modelToken,models:[{id:i,name:i,reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128e3,maxTokens:8192,api:"openai-completions"}]};return Object.keys(a).length>0&&(c.headers=a),c}function fi(r,e){if(!r.modelToken)return[];let i=kr(e),a=[];for(let[c,u]of Object.entries(i))a.push("-c",`model_providers.coze.http_headers.${c}="${u}"`);return a}var ue=N("agent-handlers"),li=5*1024*1024,sc=1,ic=6,oc=new Set(["node_modules",".git",".coze","dist","build",".next"]),mn=class{constructor(e){this.opts=e}opts;async listSkills(e){qe(e._meta,"_agent/listSkills");let i=mt(e._meta),a=await this.loadAgentCfg(i),c=a?.workspace??ze(i).workspace,u=a?.skills??[],f=[];for(let h of u){let m=Pe(c,h.relPath,"SKILL.md");await tc(m).then(y=>y.isFile()).catch(()=>!1)&&f.push(fc(h))}return{skills:f}}async addSkills(e){qe(e._meta,"_agent/addSkills");let i=mt(e._meta),a=await this.requireAgentCfg(i),c=e.skills??[],u=[...a.skills??[]],f=new Map(u.map((m,_)=>[m.skillId,_])),h=[];for(let m of c){let _=await Dr({agentId:i,workspace:a.workspace,framework:a.framework,skill:m});Tr(u,f,_),h.push(m)}return await fn(i,u),await this.reloadAgentSessions(i,"skills-added"),{installedSkills:h}}async removeSkills(e){qe(e._meta,"_agent/removeSkills");let i=mt(e._meta),a=await this.requireAgentCfg(i),c=new Set(e.skillIds??[]),u=a.skills??[],f=[];for(let h of u){if(!c.has(h.skillId)){f.push(h);continue}let m=Pe(a.workspace,h.relPath);await ec(m,{recursive:!0,force:!0}),ue.info("skill removed",{agentId:i,skillId:h.skillId,relPath:h.relPath})}return await fn(i,f),await this.reloadAgentSessions(i,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,i){return this.reloadAgentSessions(e,i)}async reloadAgentSessions(e,i){let a=this.opts.agents.get(e);if(a&&a.framework!=="codex"){for(let[c,u]of a.sessions)if(!(!u.downstream||!u.acpSessionId)){u.loadingSession=!0;try{await u.downstream.sessionLoad({sessionId:u.acpSessionId,cwd:a.workspace}),ue.info("session reloaded",{reason:i,agentId:e,framework:a.framework,cloudId:c,acpId:u.acpSessionId})}catch(f){ue.warn("session reload failed",{reason:i,agentId:e,framework:a.framework,cloudId:c,acpId:u.acpSessionId,err:String(f)})}finally{u.loadingSession=!1}}}}async updateAgent(e){if(!e.cozeIdentity?.trim())return ue.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let i=e.agentId,a=await he(i);if(!a)throw new C("AGENT_NOT_FOUND",`agent not found: ${i}`);return a.cozeIdentity===e.cozeIdentity?(ue.info("_agent/update: cozeIdentity unchanged, noop",{agentId:i}),{ok:!0}):(a.cozeIdentity=e.cozeIdentity,await be(a),await pt(a.workspace,a.framework,i,e.cozeIdentity),ue.info("_agent/update: cozeIdentity rewritten",{agentId:i,framework:a.framework}),await this.reloadAgentSessions(i,"identity-changed"),{ok:!0})}async disconnectAgent(e){let i=e.agentId;if(!i)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let a=await he(i);return a?(a.disconnectedAt=Date.now(),a.disconnectReason=e.reason??"",await be(a),ue.info("agent disconnected",{agentId:i,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(i,e.reason??"disconnect"),{ok:!0}):(ue.warn("_agent/disconnect: agent not found, ignoring",{agentId:i}),{ok:!0})}async switchModel(e){if(qe(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let i=e.model?.trim()?e.model:Ie,a=await he(e.agentId);if(!a)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);a.model=i,await be(a),ue.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:i,reason:e.reason??""});let c=this.opts.agents.get(e.agentId);if(!c)return ue.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};c.model=i;let u=[];for(let[f,h]of c.allSessionQueues())u.push(h.enqueue(async()=>{let m=c.sessions.get(f);m?.downstream&&(await m.downstream.stop(`switchModel: ${i}`).catch(()=>{}),m.downstream=void 0)}));return await Promise.all(u),ue.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:i,cloudSessions:u.length}),{ok:!0}}async resetAgent(e){if(qe(e._meta,ke.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${ke.RESET}: missing agentId`);return await this.runDetailSync(e.agentId,ke.RESET,e.reason),{ok:!0}}async repairAgent(e){if(qe(e._meta,ke.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${ke.REPAIR}: missing agentId`);let i=await this.loadAgentCfg(e.agentId);if(i&&i.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${ke.REPAIR} only allowed for openclaw, got ${i.framework}`);if(i&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,i.workspace)}catch(a){ue.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(a)})}return await this.runDetailSync(e.agentId,ke.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,i,a){if(!this.opts.detailSyncer){ue.warn("detailSyncer not wired, skipping sync",{method:i,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(c){ue.warn("detail sync failed (ignored)",{method:i,agentId:e,reason:a,err:String(c)})}}async getFileTree(e){qe(e._meta,"_agent/getFileTree");let i=e._meta,a=mt(i),c=await this.resolveWorkspace(a),u=e.filePath??"",f=this.safeJoin(c,u),h=await Pr(f).catch(()=>null);if(!h)throw new C("IPC_BAD_REQUEST",`path not found: ${u}`);if(h.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${u}`);let m=mc(e.depth);return h.isDirectory()?{tree:await _i(c,f,u,m)}:{tree:[{name:_c(u),path:wi(u||"."),isDir:!1,size:h.size,modifiedAt:Math.floor(h.mtimeMs)}]}}async getFileContent(e){qe(e._meta,"_agent/getFileContent");let i=mt(e._meta),a=await this.resolveWorkspace(i);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let c=this.safeJoin(a,e.filePath),u=await Pr(c).catch(()=>null);if(!u||!u.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(u.size>li)throw new C("IPC_BAD_REQUEST",`file too large: ${u.size} bytes (max ${li})`);let f=await gi(c);return f.includes(0)?{content:f.toString("base64"),encoding:"base64",size:u.size}:{content:f.toString("utf8"),encoding:"utf-8",size:u.size}}async resolveWorkspace(e){let i=this.opts.agents.get(e);return i?i.workspace:(await he(e).catch(()=>null))?.workspace??ze(e).workspace}safeJoin(e,i){let a=rc(e,i||"."),c=pi(e,a);if(c.startsWith("..")||c===".."||c.startsWith(`..${mi}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${i}`);return a}loadAgentCfg(e){return he(e)}async requireAgentCfg(e){let i=await this.loadAgentCfg(e);if(!i)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return i}};function ac(r){let e=r.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${r}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${r}`);return e}function cc(r){return r==="claude-code"?Pe(".claude","skills"):Pe(".agents","skills")}var xc=3e4,uc=50*1024*1024,_n=3e4;async function Dr(r){let{agentId:e,workspace:i,framework:a,skill:c}=r;if(!c.skillName)throw new C("IPC_BAD_REQUEST","skill missing skillName");let u=typeof c.content=="string"&&c.content.length>0,f=typeof c.downloadUrl=="string"&&c.downloadUrl.length>0;if(!u&&!f)throw new C("IPC_BAD_REQUEST",`skill ${c.skillId} missing both content and downloadUrl`);let h=ac(c.skillName),m=cc(a),_=Pe(m,h),y=Pe(i,_);if(await Z0(y,{recursive:!0}),u){let S=Buffer.from(c.content,"utf8");zt(S.length),await di(Pe(y,"SKILL.md"),S,"utf8")}else{let S=await dc(c.downloadUrl);hc(S)?await gc(S,y):await di(Pe(y,"SKILL.md"),S.toString("utf8"),"utf8")}let v={skillId:c.skillId,skillName:c.skillName,relPath:_,installedAt:Date.now(),...c.description?{description:c.description}:{},...c.icon?{icon:c.icon}:{},...c.version?{version:c.version}:{},...c.downloadUrl?{downloadUrl:c.downloadUrl}:{},...c.config?{config:c.config}:{},...c.builtin?{builtin:c.builtin}:{}};return ue.info("skill installed",{agentId:e,skillId:c.skillId,skillName:c.skillName,relPath:_,source:u?"content":"downloadUrl"}),v}function Tr(r,e,i){let a=e.get(i.skillId);if(a!==void 0){r[a]=i;return}e.set(i.skillId,r.length),r.push(i)}function fc(r){return{skillId:r.skillId,skillName:r.skillName,...r.description?{description:r.description}:{},...r.icon?{icon:r.icon}:{},...r.version?{version:r.version}:{},...r.config?{config:r.config}:{},...r.builtin?{builtin:r.builtin}:{}}}async function dc(r){if(!r)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(r.startsWith("data:")){let e=Math.floor(r.length*3/4);zt(e);let i=lc(r);return zt(i.length),i}if(r.startsWith("file:")){let e=new URL(r).pathname,i=await gi(e);return zt(i.length),i}if(r.startsWith("http://")||r.startsWith("https://")){let e=new AbortController,i=setTimeout(()=>e.abort(),xc);try{let a=await fetch(r,{signal:e.signal});if(!a.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${a.status} ${r}`);let c=await a.arrayBuffer();return zt(c.byteLength),Buffer.from(c)}finally{clearTimeout(i)}}throw new C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${r.slice(0,80)}`)}function zt(r){if(r>uc)throw new C("IPC_BAD_REQUEST",`skill too large: ${r} bytes`)}function lc(r){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(r);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let i=!!e[2],a=e[3]??"";return i?Buffer.from(a,"base64"):Buffer.from(decodeURIComponent(a),"utf8")}function hc(r){return r.length>=2&&r[0]===31&&r[1]===139}async function gc(r,e){await pc(r),await new Promise((i,a)=>{let c=hi("tar",["-xzf","-","-C",e,"--strip-components=1","--no-same-owner"],{stdio:["pipe","pipe","pipe"]}),u="";c.stderr?.on("data",h=>{u+=String(h)});let f=setTimeout(()=>{c.kill("SIGKILL"),a(new C("IPC_BAD_REQUEST",`tar extract timeout (${_n}ms)`))},_n);c.on("error",h=>{clearTimeout(f),a(new C("IPC_BAD_REQUEST",`tar spawn failed: ${h.message}`,{cause:h}))}),c.on("exit",h=>{clearTimeout(f),h===0?i():a(new C("IPC_BAD_REQUEST",`tar exit ${h}${u?`: ${u.trim().slice(0,200)}`:""}`))}),c.stdin?.end(r)})}async function pc(r){let e=await new Promise((i,a)=>{let c=hi("tar",["-tzvf","-"],{stdio:["pipe","pipe","pipe"]}),u="",f="";c.stdout?.on("data",m=>{u+=String(m)}),c.stderr?.on("data",m=>{f+=String(m)});let h=setTimeout(()=>{c.kill("SIGKILL"),a(new C("IPC_BAD_REQUEST",`tar list timeout (${_n}ms)`))},_n);c.on("error",m=>{clearTimeout(h),a(new C("IPC_BAD_REQUEST",`tar list spawn failed: ${m.message}`))}),c.on("exit",m=>{clearTimeout(h),m===0?i(u):a(new C("IPC_BAD_REQUEST",`tar list exit ${m}${f?`: ${f.trim().slice(0,200)}`:""}`))}),c.stdin?.end(r)});for(let i of e.split(`
|
|
90
|
+
`)){let a=i.trim();if(!a)continue;let c=a.charCodeAt(0);if(c!==45&&c!==100)throw new C("IPC_BAD_REQUEST",`tar entry kind '${a[0]}' not allowed (symlink/hardlink/special): ${a.slice(0,100)}`);let f=(a.match(/\s(\S.*)$/)?.[1]??"").split(" -> ")[0]?.trim()??"";if(!f)continue;if(f.startsWith("/"))throw new C("IPC_BAD_REQUEST",`tar entry absolute path: ${f}`);if(f.split(/[/\\]/).some(m=>m===".."))throw new C("IPC_BAD_REQUEST",`tar entry contains '..': ${f}`)}}async function _i(r,e,i,a){if(a<=0)return[];let c;try{c=await Q0(e,{withFileTypes:!0})}catch{return[]}let u=[];for(let f of c){if(oc.has(f.name)||f.isSymbolicLink())continue;let h=Pe(e,f.name),m=nc(Pe(i,f.name)),_=null;try{_=await Pr(h)}catch{continue}if(_.isSymbolicLink())continue;let y={name:f.name,path:wi(pi(r,h)),isDir:_.isDirectory(),size:_.size,modifiedAt:Math.floor(_.mtimeMs)};_.isDirectory()&&a>1&&(y.children=await _i(r,h,m,a-1)),u.push(y)}return u.sort((f,h)=>f.isDir!==h.isDir?f.isDir?-1:1:f.name.localeCompare(h.name)),u}function mc(r){return!r||r<=0?sc:Math.min(r,ic)}function _c(r){if(!r||r==="."||r==="/")return".";let e=r.split(/[/\\]/);return e[e.length-1]||"."}function wi(r){return r.split(mi).join("/")}K();import{readFileSync as yl}from"node:fs";import{dirname as vl,join as Sl}from"node:path";import{fileURLToPath as El}from"node:url";var wn="0.1.34";var qt=N("agent-health-reporter"),wc=1e4,yn=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??wc}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),qt.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),qt.info("heartbeat stopped"))}async tick(){if(this.inFlight){qt.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){qt.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let i=[];for(let c of this.opts.core.agents.values()){let u=yc(c);u&&i.push({agentId:c.agentId,status:u})}if(i.length===0)return;let a={agents:i,bridgeVersion:wn,_meta:{cozeDeviceId:e}};try{await this.opts.core.sendRequest("_agent/health",a)}catch(c){qt.warn("heartbeat batch send failed",{count:i.length,err:String(c)})}}finally{this.inFlight=!1}}};function yc(r){return r.status==="error"?"error":r.activeTriggers.size>0?"busy":r.status==="ok"?"online":null}Je();import{mkdir as Rr,rm as Vc}from"node:fs/promises";K();import{execFile as bc}from"node:child_process";import{promisify as vc}from"node:util";var bi=vc(bc),Ft=N("agents.acp-installer"),Sc={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Cc=5e4,Ec=5e3,Ac=5*6e4,vn=new Map,bn=new Map,Nr=new Map;async function yi(r){let e=process.platform==="win32"?"where":"which";try{let{stdout:i}=await bi(e,[r],{timeout:Ec});return i.split(`
|
|
91
|
+
`)[0]?.trim()||void 0}catch{return}}async function kc(r){Ft.info("npm install -g start",{npmPackage:r}),await bi("npm",["install","-g",`${r}@latest`],{timeout:Cc,maxBuffer:10*1024*1024}),Ft.info("npm install -g done",{npmPackage:r})}async function vi(r){let e=Sc[r];if(!e)return;let i=vn.get(r);if(i)return i;let a=bn.get(r);if(a&&Date.now()-a<Ac)return;let c=Nr.get(r);if(c)return c;let u=(async()=>{let f=await yi(e.binary);if(f)return vn.set(r,f),Ft.info("acp wrapper found on PATH",{binary:e.binary,path:f}),f;try{await kc(e.npmPackage)}catch(m){Ft.warn("acp wrapper install failed (will fallback to npx)",{npmPackage:e.npmPackage,err:String(m)}),bn.set(r,Date.now());return}let h=await yi(e.binary);if(!h){Ft.warn("acp wrapper installed but binary not found on PATH",{binary:e.binary}),bn.set(r,Date.now());return}return vn.set(r,h),bn.delete(r),h})().finally(()=>{Nr.delete(r)});return Nr.set(r,u),u}function Sn(r){return vn.get(r)}import{spawn as Nc}from"node:child_process";function Ut(r,e,i){return i===void 0?{jsonrpc:"2.0",id:r,method:e}:{jsonrpc:"2.0",id:r,method:e,params:i}}function Cn(r,e){return e===void 0?{jsonrpc:"2.0",method:r}:{jsonrpc:"2.0",method:r,params:e}}function _t(r,e){return{jsonrpc:"2.0",id:r,result:e}}function rt(r,e){return{jsonrpc:"2.0",id:r,error:e}}var En=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},W={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009};function Si(r){return"method"in r&&"id"in r&&r.id!==void 0}function Ci(r){return"method"in r&&!("id"in r)}function An(r){return!("method"in r)&&"id"in r}var Ic={AGENT_NOT_FOUND:W.AGENT_NOT_FOUND,AGENT_BUSY:W.AGENT_BUSY,AGENT_DISCONNECTED:W.AGENT_DISCONNECTED,AGENT_TIMEOUT:W.AGENT_TIMEOUT,AGENT_SPAWN_FAILED:W.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:W.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:W.INTERNAL_ERROR,BRIDGE_INTERNAL:W.INTERNAL_ERROR,IPC_AUTH_FAILED:W.INTERNAL_ERROR,IPC_BAD_REQUEST:W.INVALID_REQUEST,MODEL_TOKEN_GEN_FAILED:W.MODEL_TOKEN_GEN_FAILED,OPERATION_NOT_ALLOWED_FOR_LOCAL:W.OPERATION_NOT_ALLOWED_FOR_LOCAL,UPSTREAM_DISCONNECTED:W.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:W.INTERNAL_ERROR};function Kt(r){return r instanceof C?{code:Ic[r.code]??W.INTERNAL_ERROR,message:r.message,data:{bridgeCode:r.code,retriable:r.retriable}}:{code:W.INTERNAL_ERROR,message:r instanceof Error?r.message:String(r)}}function Ei(r){let e=r.data,i=e?.bridgeCode??"AGENT_PROTOCOL_ERROR";return new C(i,r.message,{retriable:e?.retriable??!1,cause:r.data})}function Ai(r){return`${JSON.stringify(r)}
|
|
92
|
+
`}var kn=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){this.buffer+=typeof e=="string"?e:e.toString("utf8");let i=this.buffer.split(`
|
|
93
|
+
`);this.buffer=i.pop()??"";let a=[];for(let c of i){let u=c.replace(/\r$/,"").trim();if(u)try{a.push(JSON.parse(u))}catch(f){this.onError?.({line:u,error:f})}}return a}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(i){return this.onError?.({line:e,error:i}),[]}}};var Ii={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission",initialize:"initialize"},Fl=Object.fromEntries(Object.entries(Ii).map(([r,e])=>[e,r])),Pc={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"agent.pair":[],initialize:[]},wt=class{seq=0;next(e,i){this.seq+=1;let a=Ii[e]??Dc(e),c=Pc[a]??[],u=[a,String(this.seq)];if(c.length>0){let f=c.map(m=>ki(i?.[m]??"")),h=Tc(f).join(":");h&&u.push(h)}else i&&Object.values(i).some(f=>f)&&u.push(Object.values(i).filter(Boolean).map(f=>ki(String(f))).join(":"));return u.join("_")}reset(){this.seq=0}};function Dc(r){return r.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function ki(r){return r.replace(/[:_\s]+/g,"-")}function Tc(r){let e=r.length;for(;e>0&&!r[e-1];)e-=1;return r.slice(0,e)}K();var Lc=3e4,Rc=50,Bc=20,Pi=500;function Mc(r){try{let e=JSON.stringify(r);return e===void 0||e.length<=Pi?r:`${e.slice(0,Pi)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Di(r,e){if(!(typeof r!="number"||r<=0))try{process.platform==="win32"?process.kill(r,e):process.kill(-r,e)}catch{}}var Ve=class{constructor(e){this.opts=e;this.log=N(`downstream.${this.constructor.name}`),this.decoder=new kn({onError:i=>this.log.warn("decode line failed",{line:i.line})})}opts;child;decoder;pending=new Map;idAllocator=new wt;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",i=Nc(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:{...this.sanitizeEnv(process.env),...this.opts.env},stdio:["pipe","pipe","pipe"],detached:e});this.child=i,i.stdout?.setEncoding("utf8"),i.stdout?.on("data",a=>{for(let c of this.decoder.push(a))this.dispatch(c)}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",a=>{let c=a.trimEnd();this.stderrRing.push(c),this.stderrRing.length>Rc&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.on("exit",(a,c)=>{this.stopped=!0,(a!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:a,signal:c,recentStderr:this.stderrRing.slice(-Bc)}),this.failAllPending(new C("AGENT_PROTOCOL_ERROR",`agent exited (${a}/${c})`));for(let f of this.exitHandlers)f(a,c)}),i.on("error",a=>{this.log.error("child error",{err:String(a)}),this.failAllPending(new C("AGENT_SPAWN_FAILED",String(a),{cause:a}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.log.info("downstream stopping",{reason:e});let i=this.child,a=new Promise(u=>i.once("exit",()=>u()));Di(i.pid,"SIGTERM");let c=setTimeout(()=>{i.killed||Di(i.pid,"SIGKILL")},5e3);try{await a}finally{clearTimeout(c)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e){return this.call("session/prompt",e,0)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Cn("session/cancel",e))}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,i){if(!(!this.child||this.stopped))try{this.writeFrame(_t(e,i))}catch(a){this.log.warn("respondAgentRequest write failed",{id:e,err:String(a)})}}respondAgentRequestError(e,i){if(!(!this.child||this.stopped))try{this.writeFrame(rt(e,i))}catch(a){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(a)})}}onExit(e){this.exitHandlers.push(e)}call(e,i,a=Lc){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),u=Ut(c,e,i),f=a>0&&Number.isFinite(a);return new Promise((h,m)=>{let _=f?setTimeout(()=>{this.pending.delete(c),m(new C("AGENT_TIMEOUT",`${e} timed out after ${a}ms`))},a):null;this.pending.set(c,{resolve:h,reject:m,timer:_,method:e});try{this.writeFrame(u)}catch(y){_&&clearTimeout(_),this.pending.delete(c),m(y)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Ai(e))}dispatch(e){if(An(e)){let i=e.id!==null?this.pending.get(e.id):void 0;if(!i){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),i.timer&&clearTimeout(i.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:i.method,code:e.error.code,message:e.error.message,data:e.error.data}),i.reject(Ei(e.error))):(this.log.info("downstream returned result",{id:e.id,method:i.method,result:Mc(e.result)}),i.resolve(e.result));return}if(Ci(e)){if(e.method==="session/update")for(let i of this.updateHandlers)Promise.resolve(i(e.params)).catch(a=>this.log.warn("update handler failed",{err:String(a)}));else this.log.debug("unknown notification",{method:e.method});return}if(Si(e)){let i=e;this.handleAgentRequest(i).catch(a=>this.log.error("agent request handler failed",{method:i.method,err:String(a)}))}}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(rt(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}for(let i of this.agentRequestHandlers)try{await i(e)}catch(a){this.log.error("agentRequestHandler threw",{method:e.method,err:String(a)});try{this.writeFrame(rt(e.id,Kt(a)))}catch{}}}failAllPending(e){for(let i of this.pending.values())i.timer&&clearTimeout(i.timer),i.reject(e);this.pending.clear()}};var Oc="@agentclientprotocol/claude-agent-acp@latest";function zc(r){let e={};for(let[i,a]of Object.entries(r))a!==void 0&&(i.startsWith("CLAUDE")||i==="AI_AGENT"||i==="BAGGAGE"||(e[i]=a));return e}var In=class extends Ve{framework="claude-code";constructor(e){let i=Sn("claude-code"),[a,c]=i?[i,[]]:["npx",["-y",Oc]],u=e.command??a,f=e.args??c,h={command:u,args:f,cwd:e.cwd,...e.env?{env:e.env}:{}};super(h)}sanitizeEnv(e){return zc(e)}};import{mkdtempSync as qc,rmSync as Fc}from"node:fs";import{tmpdir as Uc}from"node:os";import{join as Kc}from"node:path";var Gc="@zed-industries/codex-acp@latest",Pn=class extends Ve{framework="codex";authMethodId;codexHomeDir;constructor(e){let i=Sn("codex"),[a,c]=i?[i,[]]:["npx",["-y",Gc]],u=e.command??a,f=e.args??c,h=e.extraArgs?[...f,...e.extraArgs]:f,m=e.isolateCodexHome?qc(Kc(Uc(),"coze-bridge-codex-home-")):void 0,_=m?{...e.env??{},CODEX_HOME:m}:e.env,y={command:u,args:h,cwd:e.cwd,..._?{env:_}:{}};super(y),this.authMethodId=e.authMethodId,this.codexHomeDir=m}async initialize(e){let i=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),i}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Fc(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var Gt=class extends Ve{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let i=e.sessionName??"default",a=["acp","--session",`agent:${e.agentId}:${i}`];e.gatewayToken&&a.push("--token",e.gatewayToken);let c={command:e.command,args:a,cwd:e.cwd,...e.env?{env:e.env}:{}};super(c),this.agentId=e.agentId,this.sessionName=i,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.sessionPrompt({sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]}))}get acpSessionName(){return this.sessionName}};K();le();function Lr(r){return r.replace(/[^A-Za-z0-9._-]+/g,"-")}var yt=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((i,a)=>{this.slots.push({task:e,resolve:i,reject:a}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let i=await e.task();e.resolve(i)}catch(i){e.reject(i)}}}finally{this.running=!1}}}};var Dn=class{agentId;framework;workspace;deployType;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local"}getSessionQueue(e){let i=this.sessionQueues.get(e);return i||(i=new yt,this.sessionQueues.set(e,i)),i}allSessionQueues(){return this.sessionQueues.entries()}async dispose(e){this.status="stopped";let i=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let a of this.sessionQueues.values())a.dispose(i);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let i=[];for(let[,a]of this.sessions)Ht(a),a.downstream&&(i.push(a.downstream.stop(e).catch(()=>{})),a.downstream=void 0);await Promise.all(i),this.activeTriggers.clear()}};function Ht(r){r.idleTimer&&(clearTimeout(r.idleTimer),r.idleTimer=void 0)}import{spawn as Hc}from"node:child_process";import{homedir as jc}from"node:os";import{join as Wc}from"node:path";an();K();async function Li(){let r=Wc(jc(),".openclaw/openclaw.json");return(await gt(r))?.gateway?.auth?.token??""}var Ti=N("openclaw.config"),Jc=[0,5e3,5e3],Ni="models.providers.",Tn="agents.defaults.models",Nn=class{command;env;retryDelaysMs;queue=new yt;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Jc}async withRetry(e,i){let a;for(let c=0;c<this.retryDelaysMs.length;c++){let u=this.retryDelaysMs[c]??0;u>0&&await new Promise(f=>setTimeout(f,u));try{return await i()}catch(f){a=f,Ti.warn("openclaw cli failed, will retry",{label:e,attempt:c+1,err:String(f)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${a?.message??"unknown"}`)}runCli(e){return new Promise((i,a)=>{let c=Hc(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),u="";c.stderr?.on("data",f=>{u+=f.toString("utf8")}),c.on("error",a),c.on("close",f=>{f===0?i():a(new Error(`exit ${f}: ${u.trim().slice(0,500)}`))})})}async runCliTolerant(e,i){try{await this.runCli(e)}catch(a){let c=String(a);if(i.some(u=>c.includes(u)))return;throw a}}async bestEffortUnset(e,i){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",i])))}catch(a){Ti.warn(`${e} failed (best-effort)`,{configPath:i,err:String(a)})}}ensureProvider(e,i){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${Ni}${e}`,JSON.stringify(i),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${Ni}${e}`)}addModelToAllowlist(e,i){let a={[e]:i?{alias:i}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Tn}[${e}]`,()=>this.runCli(["config","set",Tn,JSON.stringify(a),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Tn}[${e}]`,`${Tn}.${e}`)}ensureAgent(e,i,a){let c=["agents","add",e,"--workspace",i,"--non-interactive"];return a&&c.push("--model",a),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(c,["already exists","already registered"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var De=N("agent-manager"),Xc=(r,e,i,a,c,u,f)=>{switch(r){case"claude-code":{let h=c?{...oi(c),...xi(c,f)}:void 0;return new In({cwd:i,...h&&Object.keys(h).length>0?{env:h}:{}})}case"codex":{let h=c?[...ai(c),...fi(c,f)]:[],m=c?ci(c):void 0,_=!!c;return new Pn({cwd:i,...h.length>0?{extraArgs:h}:{},...m&&Object.keys(m).length>0?{env:m}:{},..._?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Gt({command:e,cwd:i,agentId:a,...u?{sessionName:Lr(u)}:{}})}};function Ri(r){return r==="claude-code"||r==="codex"}var Yc={path:"",version:"cloud-deployed"},$c={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Zc=6e4,Ln=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Xc,this.createTimeoutMs=e.createTimeoutMs??Zc}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=new Nn({command:e.path})}return this.openclawConfigCache}async createAgent(e){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=Ot(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let a=this.registry.get(e.agentId);if(a){if(a.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${a.framework})`);if(a.status==="error")De.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await a.dispose("rebuild after error").catch(S=>De.warn("dispose stale agent failed (ignored)",{err:String(S)})),this.registry.unregister(e.agentId);else return De.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:a.agentId,workspace:a.workspace,framework:a.framework}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);i&&Ri(e.framework)&&await vi(e.framework);let u=ze(e.agentId,this.paths),f=e.workspace??u.workspace,h=Ot(e._meta),m=new AbortController,_=setTimeout(()=>m.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),y,v=!1;try{let S=()=>{if(m.signal.aborted)throw m.signal.reason instanceof Error?m.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await Rr(u.root,{recursive:!0}),await Rr(f,{recursive:!0}),await Rr(u.logs,{recursive:!0}),S(),await pt(f,e.framework,e.agentId,e.cozeIdentity),S();let A=await he(e.agentId,this.paths).catch(()=>null),D=si({model:e.model??A?.model});if(y=new Dn({agentId:e.agentId,framework:e.framework,workspace:f,model:D.model??Ie,deployType:h}),y.status="ok",A?.sessions){for(let[oe,ee]of Object.entries(A.sessions))y.sessions.set(oe,{acpSessionId:ee.acpSessionId,modelToken:ee.modelToken,tokenGeneratedAt:ee.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let $=Object.keys(A.sessions).length;$>0&&De.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:$})}this.registry.register(y),v=!0;let L={agentId:e.agentId,framework:e.framework,workspace:f,cozeIdentity:e.cozeIdentity,createdAt:A?.createdAt??Date.now(),sessions:A?.sessions??{},model:D.model};h==="cloud"&&(L.deployType="cloud"),A?.skills&&(L.skills=A.skills),A?.agentName&&(L.agentName=A.agentName),A?.description&&(L.description=A.description),e.framework==="openclaw"&&(this.config.frameworksCache?.openclaw?.path?await this.getOpenclawConfig().ensureAgent(e.agentId,f):De.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let F=e.initialSkills??[];if(F.length>0){let $=[...L.skills??[]],oe=new Map($.map((Z,P)=>[Z.skillId,P])),ee=0;for(let Z of F)try{let P=await Dr({agentId:e.agentId,workspace:f,framework:e.framework,skill:Z});Tr($,oe,P),ee++}catch(P){De.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:Z.skillId,skillName:Z.skillName,err:String(P)})}ee>0&&(L.skills=$,De.info("initialSkills installed",{agentId:e.agentId,installed:ee,requested:F.length}))}return await be(L,this.paths),De.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:h}),{ok:!0,agentId:e.agentId,workspace:f,framework:e.framework}}catch(S){throw De.error("agent create failed, rolling back",{agentId:e.agentId,err:String(S)}),v&&y&&(await y.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Vc(u.root,{recursive:!0,force:!0}).catch(A=>De.warn("rm agent dir failed (ignored)",{err:String(A)})),S instanceof C?S:new C("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(_)}}async spawnSessionDownstream(e,i,a,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&Ri(e.framework))f=Yc;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);let h=e.deployType==="cloud"?{model:e.model,modelToken:i}:void 0,m;e.framework==="openclaw"?m=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:a,cozeEnv:c,command:f.path}):m=this.factory(e.framework,f.path,e.workspace,e.agentId,h,a,c);try{return await m.start(),await m.initialize($c),m}catch(_){throw await m.stop("spawnSessionDownstream failed").catch(()=>{}),_ instanceof C?_:new C("AGENT_SPAWN_FAILED",_ instanceof Error?_.message:String(_),{cause:_})}}async buildOpenclawDownstream(e){let{session:i,modelConfig:a,cloudSessionId:c,cozeEnv:u,command:f}=e,h=Lr(c),m=await Li(),_=a?ui(a,u):null,y;if(_){let v=Ir(c),A=_.models[0]?.id??Ie,D=`${v}/${A}`;if(!this.ensuredProviders.has(D)){let L=this.getOpenclawConfig();await L.ensureProvider(v,_),await L.addModelToAllowlist(D),this.ensuredProviders.add(D)}y=D}return new Gt({command:f,cwd:i.workspace,agentId:i.agentId,sessionName:h,...m?{gatewayToken:m}:{},...y?{slashModelOnStart:y}:{}})}async openclawRepair(e,i){let a=this.getOpenclawConfig();await a.deleteAgent(e),await a.ensureAgent(e,i)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache;for(let a of e.sessions.keys()){let c=Ir(a),u=`${c}/${e.model}`;this.ensuredProviders.delete(u),await i.removeProvider(c),await i.removeModelFromAllowlist(u)}}};K();import{execFile as Qc}from"node:child_process";import{promisify as ex}from"node:util";var tx=ex(Qc),Xe=N("coze-cli-installer"),Bi="@coze/cli@0.1.3-alpha.89c42a",Mi="https://bnpm.byted.org",nx="coze",rx=5e3,sx=9e4,Oi=1e4,jt=null,Br=!1;async function zi(r,e={}){if(Br)return;if(jt)return jt;let i=e.exec??tx;return jt=(async()=>{try{let a=await ix(nx,i);if(a){Xe.info("coze-cli already on PATH, skip install + config + auth",{path:a}),Br=!0;return}Xe.info("coze-cli install start",{package:Bi,registry:Mi});try{await i("npm",["i","-g",Bi,"--registry",Mi],{timeout:sx,maxBuffer:10*1024*1024}),Xe.info("coze-cli install ok")}catch(c){Xe.warn("coze-cli install failed (skip subsequent steps)",{err:String(c)});return}if(r.env)try{await i("coze",["config","set","xTTEnv",r.env],{timeout:Oi}),Xe.info("coze config set xTTEnv ok",{env:r.env})}catch(c){Xe.warn("coze config set failed (continue to auth login)",{err:String(c)})}try{await i("coze",["auth","login","--token",r.patToken],{timeout:Oi}),Xe.info("coze auth login ok")}catch(c){Xe.warn("coze auth login failed",{err:String(c)});return}Br=!0}finally{jt=null}})(),jt}async function ix(r,e){let i=process.platform==="win32"?"where":"which";try{let{stdout:a}=await e(i,[r],{timeout:rx});return a.split(`
|
|
94
|
+
`)[0]?.trim()||void 0}catch{return}}K();import{spawn as ox}from"node:child_process";import{constants as qi,access as ax}from"node:fs/promises";import{delimiter as cx,join as xx}from"node:path";var ux=N("framework-detector"),Fi={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},fx=[".exe",".cmd",".bat",".ps1"],bt=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??ox,access:e.access??ax}}async detect(e){let i=Fi[e],a=await this.which(i);if(!a)return ux.debug("framework binary not found",{framework:e,bin:i}),null;let c=await this.probeVersion(a);return{path:a,version:c}}async detectAll(){let e=await Promise.all(Object.keys(Fi).map(async a=>[a,await this.detect(a)])),i={};for(let[a,c]of e)c&&(i[a]=c);return i}async which(e){let i=this.env.pathEnv.split(cx).filter(Boolean),a=this.env.platform==="win32"?["",...fx]:[""];for(let c of i)for(let u of a){let f=xx(c,e+u);if(await this.isExecutable(f))return f}return null}async isExecutable(e){try{let i=this.env.platform==="win32"?qi.F_OK:qi.X_OK;return await this.env.access(e,i),!0}catch{return!1}}async probeVersion(e){return new Promise(i=>{let a="",c=!1,u,f=h=>{c||(c=!0,u&&clearTimeout(u),i(h.trim()||"unknown"))};try{let h=this.env.spawn(e,["--version"],{stdio:["ignore","pipe","pipe"]});u=setTimeout(()=>{h.kill("SIGKILL"),f("unknown")},5e3),h.stdout?.on("data",m=>{a+=m.toString("utf8")}),h.on("error",()=>f("unknown")),h.on("close",()=>{let m=lx(a).split(/\r?\n/)[0]??"";f(m)})}catch{f("unknown")}})}},dx=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function lx(r){return r.replace(dx,"")}an();le();var hx=10*6e4;function Ui(r){let e=r?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?hx:e}function Rn(r){return gt(r??H().configFile)}function vt(r,e){return on(e??H().configFile,r)}import{randomBytes as Cx}from"node:crypto";import{mkdir as gx,readFile as px,realpath as mx,writeFile as _x}from"node:fs/promises";import{basename as yx,dirname as Mr,join as bx,relative as vx,resolve as Ki,sep as Sx}from"node:path";K();var Hi=N("fs-rpc");async function ji(r,e){let i=await Ji(r.path,e);return await gx(Mr(i),{recursive:!0}),await _x(i,r.content,"utf8"),Hi.info("fs/write_text_file ok",{path:i,size:r.content.length}),null}async function Wi(r,e){let i=await Ji(r.path,e),a=await px(i,"utf8"),c=a;if(typeof r.line=="number"||typeof r.limit=="number"){let u=a.split(`
|
|
95
|
+
`),f=Math.max(0,(r.line??1)-1),h=typeof r.limit=="number"?f+r.limit:void 0;c=u.slice(f,h).join(`
|
|
96
|
+
`)}return Hi.info("fs/read_text_file ok",{path:i,size:c.length}),{content:c}}async function Ji(r,e){if(typeof r!="string"||r.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[i,a]=await Promise.all([Gi(Ki(e)),Gi(Ki(r))]),c=vx(i,a);if(c.startsWith("..")||c===".."||c.startsWith(`..${Sx}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return a}async function Gi(r){let e=[],i=r;for(;i!==Mr(i);)try{let a=await mx(i);return e.length?bx(a,...e.reverse()):a}catch{e.push(yx(i)),i=Mr(i)}return r}Je();K();var O=N("core"),Ex=3e4,Ax=3e4,Bn=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new wt;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=Ui(e.bridgeConfig)}registerExtension(e,i){this.extensions[e]=i}getCozeEnv(){return this.currentCozeEnv}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),await this.upstream.start(),O.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){O.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(i=>i.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),O.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let i of this.registerHandlers)try{i(e.agentId)}catch(a){O.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(a)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&O.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,i,a){let c=a.downstream;c&&(c.onUpdate(u=>{a.loadingSession||this.forwardUpdate(e,u)}),c.onAgentRequest(u=>{this.handleAgentRequest(e,c,u)}),c.onExit((u,f)=>{O.info("session runtime exited",{agentId:e.agentId,cloudId:i,code:u,signal:f}),Ht(a),a.downstream=void 0,a.acpSessionId&&e.activeTriggers.delete(a.acpSessionId)}))}async handleFrame(e){if(An(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let i="id"in e&&e.id!==void 0?e.id:null,a=e.params?._meta?.cozeEnv;a&&(this.currentCozeEnv=a);try{if(e.method.startsWith("_agent/")){let c=this.extensions[e.method];if(!c){i!==null?await this.sendError(i,W.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):O.warn("drop notification: extension not registered",{method:e.method});return}let u=await c(e,this);i!==null&&await this.upstream.send(_t(i,u));return}if(e.method.startsWith("session/")){let c=await this.routeSessionMethod(e);i!==null&&await this.upstream.send(_t(i,c));return}if(e.method==="initialize"){i!==null&&await this.upstream.send(_t(i,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}i!==null?await this.sendError(i,W.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):O.warn("drop unknown notification",{method:e.method})}catch(c){O.error("handleFrame failed",{method:e.method,err:String(c)}),i!==null&&await this.upstream.send(rt(i,Kt(c)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let i=e.params,a=i._meta?.cozeAgentId;if(!a)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let c=this.agents.get(a);if(!c)throw this.disconnectedAgents.has(a)?new C("AGENT_DISCONNECTED",`agent ${a} has been disconnected; cloud must _agent/create to revive`):new C("AGENT_NOT_FOUND",`agent not found: ${a}`);let u=typeof i.sessionId=="string"?i.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!u)return this.dispatchSessionCall(c,e.method,i);let f=Date.now(),h=!1;try{let m=await c.getSessionQueue(u).enqueue(()=>this.dispatchSessionCall(c,e.method,i));return h=!0,m}finally{O.info("session call done",{agentId:c.agentId,method:e.method,durationMs:Date.now()-f,ok:h})}}async dispatchSessionCall(e,i,a){e.lastActiveAt=Date.now();let{stripped:c}=Xs(a);switch(i){case"session/new":{let u=kx();return O.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:u}),{sessionId:u}}case"session/load":{let u=c;return O.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:u.sessionId}),{}}case"session/prompt":{let u=c,f=u.sessionId;if(!f)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let h=await this.ensureRuntime(e,f);if(h.replySeq=0,await this.ensureDownstream(e,f,h),!h.downstream||!h.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let m=a._meta?.cozeTriggerMsgId;m?e.activeTriggers.set(h.acpSessionId,m):e.activeTriggers.delete(h.acpSessionId);try{let _=await h.downstream.sessionPrompt({...u,sessionId:h.acpSessionId});return h.lastActiveAt=Date.now(),_}finally{e.activeTriggers.delete(h.acpSessionId),h.downstream?.isAlive()&&this.armIdleTimer(e,f,h)}}case"session/cancel":{let f=c.sessionId;if(!f)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let h=e.sessions.get(f);return h?.downstream?.isAlive()&&h.acpSessionId&&await h.downstream.sessionCancel({sessionId:h.acpSessionId}),{ok:!0}}default:throw new C("IPC_BAD_REQUEST",`session method not supported: ${i}`)}}async ensureRuntime(e,i){let a=e.sessions.get(i);if(a)return a;let u={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,i):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(i,u),await this.persistSessionMapping(e),u}async requestSessionToken(e,i){let a={sessionId:i,_meta:{cozeAgentId:e}};try{let c=await this.sendRequest(ke.GEN_MODEL_TOKEN,a,Ax);if(!c?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${i})`);return c.modelToken}catch(c){throw c instanceof C&&c.code==="MODEL_TOKEN_GEN_FAILED"?c:new C("MODEL_TOKEN_GEN_FAILED",c instanceof Error?c.message:String(c),{cause:c})}}async ensureDownstream(e,i,a){if(Ht(a),a.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let c=await this.sessionSpawner(e,a.modelToken,i,this.currentCozeEnv);if(a.downstream=c,this.attachRuntimeHooks(e,i,a),a.acpSessionId){a.loadingSession=!0;try{await c.sessionLoad({sessionId:a.acpSessionId,cwd:e.workspace}),O.info("session restored via session/load",{agentId:e.agentId,cloudId:i,acpId:a.acpSessionId})}catch(u){O.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:i,acpId:a.acpSessionId,err:String(u)}),a.acpSessionId=void 0;let f=await c.sessionNew({cwd:e.workspace});a.acpSessionId=f.sessionId,await this.persistSessionMapping(e)}finally{a.loadingSession=!1}}else{let u=await c.sessionNew({cwd:e.workspace});a.acpSessionId=u.sessionId,await this.persistSessionMapping(e)}c.afterSessionEstablished&&a.acpSessionId&&await c.afterSessionEstablished(a.acpSessionId)}armIdleTimer(e,i,a){if(Ht(a),this.isRuntimeBusy(e,a)){O.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:i});return}a.idleTimer=setTimeout(()=>{if(a.idleTimer=void 0,this.isRuntimeBusy(e,a)){O.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:i}),this.armIdleTimer(e,i,a);return}O.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:i});let c=a.downstream;a.downstream=void 0,a.acpSessionId&&e.activeTriggers.delete(a.acpSessionId),c&&c.stop("idle timeout").catch(u=>O.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:i,err:String(u)}))},this.sessionIdleTimeoutMs),a.idleTimer.unref?.()}isRuntimeBusy(e,i){if(i.acpSessionId&&e.activeTriggers.has(i.acpSessionId))return!0;let a=i.downstream;if(!a)return!1;for(let c of this.pendingUpstream.values())if(c.downstream===a)return!0;return!1}forwardUpdate(e,i){let a=i.sessionId,c=this.reverseSessionId(e,a);if(!c){O.debug("drop update for unknown session",{agentId:e.agentId,acpId:a});return}let u=e.sessions.get(c);if(!u){O.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:c});return}if(Ix(i)){O.debug("drop codex metadata-warn chunk",{agentId:e.agentId,acpId:a});return}let f={cozeAgentId:e.agentId,cozeReplySeqID:++u.replySeq},h=e.activeTriggers.get(a);h&&(f.cozeTriggerMsgId=h),this.upstream.send(Cn("session/update",{...i,sessionId:c,_meta:f})).catch(m=>O.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,i,a){if(a.method==="session/request_permission"){this.forwardPermissionRequest(e,i,a);return}if(a.method==="fs/write_text_file"||a.method==="fs/read_text_file"){this.handleFsRpcRequest(e,i,a);return}O.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:a.method}),i.respondAgentRequestError(a.id,{code:W.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${a.method}`})}async handleFsRpcRequest(e,i,a){try{let c=e.workspace;if(a.method==="fs/write_text_file"){let u=a.params??{},f=await ji(u,c);i.respondAgentRequest(a.id,f)}else{let u=a.params??{},f=await Wi(u,c);i.respondAgentRequest(a.id,f)}}catch(c){O.warn("fs rpc handler failed",{agentId:e.agentId,method:a.method,err:String(c)}),i.respondAgentRequestError(a.id,Kt(c))}}forwardPermissionRequest(e,i,a){let c=this.upstreamIds.next("session/request_permission"),u=a.params??{},h=u.sessionId,m=h?e.activeTriggers.get(h):void 0,_={cozeAgentId:e.agentId};m&&(_.cozeTriggerMsgId=m);let y=h?this.reverseSessionId(e,h):void 0,v={...u,...y?{sessionId:y}:{},_meta:_};this.pendingUpstream.set(c,{agentRequestId:a.id,agentId:e.agentId,downstream:i,method:a.method}),O.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:c,acpSessionId:h,cloudSessionId:y,toolCallId:u.toolCall?.toolCallId,options:u.options?.map(S=>({optionId:S.optionId,kind:S.kind,name:S.name}))}),this.upstream.send(Ut(c,"session/request_permission",v)).catch(S=>{this.pendingUpstream.delete(c),O.error("forward permission request failed",{agentId:e.agentId,err:String(S)}),i.respondAgentRequestError(a.id,{code:W.INTERNAL_ERROR,message:`upstream send failed: ${String(S)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let i=this.pendingUpstream.get(e.id);if(i){this.pendingUpstream.delete(e.id),e.error?(O.info("upstream \u2192 permission response (error)",{agentId:i.agentId,upstreamId:e.id,method:i.method,error:e.error}),i.downstream.respondAgentRequestError(i.agentRequestId,e.error)):(O.info("upstream \u2192 permission response (result)",{agentId:i.agentId,upstreamId:e.id,method:i.method,result:e.result}),i.downstream.respondAgentRequest(i.agentRequestId,e.result));return}let a=this.pendingBridge.get(e.id);if(a){this.pendingBridge.delete(e.id),clearTimeout(a.timer),e.error?a.reject(new En(e.error)):a.resolve(e.result);return}O.debug("orphan upstream response (no pending)",{id:e.id})}sendRequest(e,i,a=Ex){let c=this.upstreamIds.next(e);return new Promise((u,f)=>{let h=setTimeout(()=>{this.pendingBridge.delete(c),f(new C("AGENT_TIMEOUT",`${e} timed out after ${a}ms`))},a);this.pendingBridge.set(c,{method:e,resolve:u,reject:f,timer:h}),this.upstream.send(Ut(c,e,i)).catch(m=>{let _=this.pendingBridge.get(c);_&&(clearTimeout(_.timer),this.pendingBridge.delete(c)),f(m)})})}async persistSessionMapping(e){if(this.paths)try{let i=new Map;for(let[a,c]of e.sessions){let u={modelToken:c.modelToken,tokenGeneratedAt:c.tokenGeneratedAt};c.acpSessionId&&(u.acpSessionId=c.acpSessionId),i.set(a,u)}await Er(e.agentId,i,this.paths)}catch(i){O.warn("persist session mapping failed",{agentId:e.agentId,err:String(i)})}}reverseSessionId(e,i){for(let[a,c]of e.sessions.entries())if(c.acpSessionId===i)return a}sendError(e,i,a){return this.upstream.send(rt(e,{code:i,message:a}))}};function kx(){return Cx(16).toString("hex")}function Ix(r){let e=r.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let i=e.content;if(!i||typeof i!="object")return!1;let a=i;return a.type!=="text"||typeof a.text!="string"?!1:a.text.startsWith("Model metadata for `")}K();le();import{randomBytes as Px}from"node:crypto";import{chmod as Dx,mkdir as Tx,writeFile as Vi}from"node:fs/promises";import{createServer as Nx}from"node:http";import{dirname as Lx}from"node:path";var Rx=1e6,Or=N("ipc"),Mn=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(i=>[`${i.method} ${i.path}`,i])),this.paths=e.paths??H()}async start(){this.token=Px(32).toString("hex");let e=Nx((a,c)=>{this.dispatch(a,c)});this.server=e,await new Promise((a,c)=>{e.once("error",c),e.listen(0,"127.0.0.1",()=>a())});let i=e.address();if(!i||typeof i!="object")throw new Error("failed to obtain IPC port");return this.port=i.port,await this.persistAuthFiles(),Or.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((i,a)=>{e.close(c=>c?a(c):i())}),this.server=null)}async persistAuthFiles(){await Tx(Lx(this.paths.portFile),{recursive:!0}),await Vi(this.paths.portFile,String(this.port),"utf8"),await Vi(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await Dx(this.paths.tokenFile,384)}catch(e){Or.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,i){if(e.headers.authorization!==`Bearer ${this.token}`){Wt(i,401,{error:"unauthorized"});return}let c=`${e.method} ${(e.url??"").split("?")[0]}`,u=this.routes.get(c);if(!u){Wt(i,404,{error:"not found"});return}let f=null;if(e.method==="POST")try{f=await Bx(e)}catch(h){Wt(i,400,{error:"invalid json",detail:String(h)});return}try{let h=await u.handler(f,e);Wt(i,200,h??{ok:!0})}catch(h){Or.error("IPC handler failed",{key:c,err:String(h)}),Wt(i,500,{error:h instanceof Error?h.message:String(h)})}}};function Wt(r,e,i){r.statusCode=e,r.setHeader("content-type","application/json"),r.end(JSON.stringify(i))}async function Bx(r){let e=[],i=0;for await(let c of r){let u=c;if(i+=u.length,i>Rx)throw new Error("body too large");e.push(u)}let a=Buffer.concat(e).toString("utf8");return a?JSON.parse(a):null}var ma=Oe(io(),1);var pf=Oe(ta(),1),mf=Oe(Zn(),1),_f=Oe(Et(),1),wf=Oe(Yr(),1),yf=Oe(Qr(),1),bf=Oe(is(),1),ua=Oe(nr(),1),vf=Oe(xa(),1);var fa=ua.default;K();var ie=N("upstream.frontier"),la="application/json",ha="none",sr=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandler=null;opened=!1;openCount=0;async start(){if(this.fws){ie.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Zs,...gn(this.opts.ppeOverride)};class i extends fa{constructor(h){super(h,$s,{headers:e})}send(h,...m){if(Js("debug"))try{let _;typeof h=="string"?_=Buffer.from(h,"utf8"):h instanceof Buffer?_=h:h instanceof ArrayBuffer?_=new Uint8Array(h):ArrayBuffer.isView(h)?_=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):_=new Uint8Array(0);let y=Buffer.from(_.slice(0,128)).toString("hex");ie.debug("WS raw frame out",{bytes:_.byteLength,headHex:y})}catch(_){ie.warn("WS raw frame dump failed",{err:String(_)})}super.send(h,...m)}}let a=ti(this.opts.urlOverride),c={url:a,ws:i,fpID:Ys,aID:hn,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:la,force:!0},payloadEncoding:{encoding:ha,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,debug:this.opts.debug??!1},u=new ma.FWS(c);u.onopen=()=>{this.opened=!0,this.openCount+=1;let f=this.openCount===1;ie.info("frontier opened",{url:a,remoteDeviceId:this.opts.handshake.deviceId,initial:f,openCount:this.openCount}),this.connectHandler&&Promise.resolve(this.connectHandler({initial:f})).catch(h=>ie.warn("onConnect handler threw (ignored)",{err:String(h)}))},u.onclose=f=>{this.opened=!1,ie.info("frontier closed",{code:f.code,reason:f.reason,willReconnect:f.willReconnect})},u.onerror=f=>{ie.warn("frontier error",{code:f.code,msg:f.message})},u.onmessage=f=>this.handleMessage(f),this.fws=u,await u.connect()}async stop(e){let i=this.fws;if(i){this.fws=null,this.opened=!1;try{i.close(1e3,e??"bridge shutdown")}catch(a){ie.warn("frontier close threw (ignored)",{err:String(a)})}}}async send(e){let i=this.fws;if(!i)throw new C("UPSTREAM_DISCONNECTED","frontier upstream not started");let a=JSON.stringify(e),c=e;ga(c)||ie.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:a.length});try{await i.send(a,{service:33555712,method:1,payloadType:la,payloadEncoding:ha})}catch(f){throw ie.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandler=e}isConnected(){return this.opened&&this.fws?.readyState===1}handleMessage(e){let i=e.message?.service;if(i!==33555712){ie.debug("drop non-adapter frontier frame",{service:i});return}let a=Af(e);if(!a){ie.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){ie.debug("frame received but no onFrame handler",{size:a.length});return}let c;try{c=JSON.parse(a)}catch(f){ie.warn("frontier message JSON parse failed",{err:String(f),head:a.slice(0,80)});return}let u=c;ga(u)||ie.info("frontier frame in",{logid:Ef(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:u.id,method:u.method,body:Cf(a)}),Promise.resolve(this.handler(c)).catch(f=>ie.warn("frontier frame handler threw",{err:String(f)}))}};function ga(r){return r.method==="_agent/health"?!0:typeof r.id=="string"&&r.id.startsWith("agent.health_")}var pa=2e3;function Cf(r){return r.length<=pa?r:`${r.slice(0,pa)}...<truncated, total ${r.length} chars>`}function Ef(r){return r?r.high===0?String(r.low>>>0):`${r.high.toString(16)}${(r.low>>>0).toString(16).padStart(8,"0")}`:""}function Af(r){let e=r.message;if(e?.textPayload)return e.textPayload;let i=e?.payload;if(!i)return null;try{return Buffer.from(i).toString("utf8")}catch{return null}}K();var as=N("upstream.switchable"),ir=class{inner;handler=null;connectHandler=null;constructor(e){this.inner=e}async swap(e,i){if(this.inner===e)return;as.info("swap upstream",{reason:i});let a=this.inner;this.inner=e,this.handler&&e.onFrame(this.handler),this.connectHandler&&e.onConnect&&e.onConnect(this.connectHandler);try{await e.start()}catch(c){throw as.error("swap target start failed, reverting",{err:String(c)}),this.inner=a,c}await a.stop(i??"swapped").catch(c=>as.warn("previous upstream stop threw (ignored)",{err:String(c)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandler=e,this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};K();var cs=N("upstream"),tn=class{handler=null;async start(){cs.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){cs.info("NoopUpstream stopped",{reason:e})}async send(e){cs.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};K();le();K();le();import{execSync as kf}from"node:child_process";import{readFileSync as _a,unlinkSync as If}from"node:fs";import{mkdir as Pf,readFile as wa,unlink as ya,writeFile as Df}from"node:fs/promises";import{dirname as Tf}from"node:path";var Nf=N("single-instance"),or=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??H().pidFile,e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();return e!==null&&this.isAlive(e)?{kind:"already-running",pid:e}:(e!==null&&(Nf.warn("removing stale pid file",{stalePid:e}),await ya(this.pidFile).catch(()=>{})),await Pf(Tf(this.pidFile),{recursive:!0}),await Df(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await wa(this.pidFile,"utf8")).trim()===String(process.pid)&&await ya(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await wa(this.pidFile,"utf8"),i=Number.parseInt(e.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(e){if(e.code==="ENOENT")return null;throw e}}isAlive(e){try{process.kill(e,0)}catch(i){return i.code==="EPERM"}return this.matchesDaemonTitle(e)}matchesDaemonTitle(e){try{let i=_a(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(i.includes("coze-bridge-daemon")||i.includes("lib/index.js"))}catch{}try{let i=kf(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return i.trim()?i.includes("coze-bridge-daemon")||i.includes("lib/index.js"):!1}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{_a(this.pidFile,"utf8").trim()===String(process.pid)&&If(this.pidFile)}catch{}})}};var M=N("daemon"),Lf="coze-bridge-daemon";async function Sa(){let r=new or({processTitle:Lf}),e=await r.acquire();if(e.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${e.pid})`);let i=await Rn(),a=i??{};Cr({pid:process.pid}),M.info(i?"loaded bridge config":"initialized bridge config");try{let P=new bt;a.frameworksCache=await P.detectAll(),M.info("refreshed frameworks_cache",{detected:Object.keys(a.frameworksCache)})}catch(P){M.warn("framework detection failed",{err:String(P)})}await vt(a);let c=new ir(new tn),u=H(),f=null,h=new Bn({upstream:c,paths:u,bridgeConfig:a,sessionSpawner:async(P,U,j,ae)=>{if(!f)throw new Error("agentManager not ready");return f.spawnSessionDownstream(P,U,j,ae)}});await Bf(u,h);let m=new Ln({paths:u,config:a,registry:h});f=m;let _,y,v=null,S=null;h.registerExtension("_agent/create",async P=>m.createAgent(P.params)),h.registerExtension("_agent/health",async()=>({ok:!0}));let A={},D=new mn({agents:h.agents,disposeAndMarkDisconnected:async(P,U)=>{let j=h.agents.get(P);j&&(await m.cleanupOpenclawSessionProviders(j).catch(ae=>M.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(ae)})),await j.dispose(`disconnect: ${U}`).catch(ae=>M.warn("dispose during disconnect failed (ignored)",{agentId:P,err:String(ae)})),j.status="disconnected",h.unregister(P)),h.disconnectedAgents.add(P)},detailSyncer:async P=>{if(!A.ref)throw new Error("agent-detail-sync not initialized yet");await A.ref.syncOne(P)},openclawRepair:async(P,U)=>{await m.openclawRepair(P,U)}});h.registerExtension("_agent/listSkills",P=>D.listSkills(P.params)),h.registerExtension("_agent/addSkills",P=>D.addSkills(P.params)),h.registerExtension("_agent/removeSkills",P=>D.removeSkills(P.params)),h.registerExtension("_agent/getFileTree",P=>D.getFileTree(P.params)),h.registerExtension("_agent/getFileContent",P=>D.getFileContent(P.params)),h.registerExtension("_agent/update",P=>D.updateAgent(P.params)),h.registerExtension("_agent/disconnect",P=>D.disconnectAgent(P.params)),h.registerExtension("_agent/switchModel",P=>D.switchModel(P.params)),h.registerExtension("_agent/reset",P=>D.resetAgent(P.params)),h.registerExtension("_agent/repair",P=>D.repairAgent(P.params));let L=new ln({paths:u,handlers:D,sendDetail:P=>h.sendRequest("_agent/detail",P)});A.ref=L,c.onConnect(({initial:P})=>{M.info("frontier upstream connected, triggering detail sync",{initial:P}),L.syncAll(P?"initial-connect":"reconnect").catch(U=>M.warn("detail sync top-level error (ignored)",{err:String(U)}))});let F=new Mn({paths:u,routes:[{method:"GET",path:"/status",handler:async()=>({running:!0,pid:process.pid,agents:[...h.agents.keys()],deviceId:v??"",frameworksCache:a.frameworksCache??{}})},{method:"POST",path:"/pair",handler:async P=>{let U=P,j=U?.privatecode,ae=U?.pairing_code;if(!j||!ae)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Re=pn(U.env),we=U.handshake_url,Qe=U.frontier_url,Nt=Rf(U.env,we,Qe),nn=!!_&&_!==j,Se=y!==void 0&&y!==Nt,Ce=nn||Se;if(Ce){M.warn("pair config switched, resetting agents",{pcChanged:nn,envChanged:Se,previousPc:_?ba(_):"",nextPc:ba(j),previousEnvKey:y??"",nextEnvKey:Nt});for(let z of[...h.agents.values()])await z.dispose("pair config switch").catch(()=>{}),h.agents.delete(z.agentId);await c.swap(new tn,"pair switch").catch(()=>{})}let rn=await ri({privatecode:j,...we?{endpoint:we}:{},ppeOverride:Re});v=rn.deviceId,Cr({deviceId:v,pid:process.pid}),zi({patToken:j,env:U.env}).catch(z=>M.warn("coze-cli setup error (ignored)",{err:String(z)}));let fe=new sr({handshake:rn,privatecode:j,...Qe?{urlOverride:Qe}:{},ppeOverride:Re});await c.swap(fe,"pair");try{let z=new bt;a.frameworksCache=await z.detectAll(),await vt(a),M.info("frameworks_cache refreshed before pair",{detected:Object.keys(a.frameworksCache)})}catch(z){M.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(z)})}let sn=Object.keys(a.frameworksCache??{});try{let z=await h.sendRequest("_agent/pair",{pairCode:ae,patToken:j,frameworks:sn,_meta:{cozeDeviceId:v}});M.info("_agent/pair ok",{pairResult:z}),_=j,y=Nt,S||(S=new yn({core:h,getDeviceId:()=>v??""})),S.start(),Ce&&va(u,m).catch(Be=>M.warn("post-pair-switch auto-revive error (ignored)",{err:String(Be)}));let J;return U.agent_id&&(J=await Mf(U.agent_id,u,m,Be=>h.sendRequest("_agent/detail",Be)).catch(Be=>(M.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(Be)}),{ok:!1,agentId:U.agent_id??"",note:String(Be)}))),{ok:!0,note:"paired with cloud",...J?{agent:J}:{}}}catch(z){return M.error("_agent/pair failed",{err:String(z)}),{ok:!1,note:`pair failed: ${String(z)}`}}}},{method:"POST",path:"/_agent/create",handler:async P=>{let U=P;return{ok:!0,result:await m.createAgent(U)}}},{method:"POST",path:"/refresh",handler:async()=>{M.info("IPC /refresh: re-detecting frameworks");let P=new bt;return a.frameworksCache=await P.detectAll(),await vt(a),{ok:!0,frameworks:a.frameworksCache}}},{method:"POST",path:"/shutdown",handler:async()=>(M.info("IPC /shutdown received"),setImmediate(()=>{Z.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:$,token:oe}=await F.start();await h.start(),va(u,m).catch(P=>M.warn("auto-revive top-level error (ignored)",{err:String(P)}));let ee=null,Z={port:$,token:oe,core:h,ipc:F,shutdown(P){return ee||(M.info("daemon shutdown",{reason:P}),ee=(async()=>{S?.stop(),await h.stop(P),await F.stop(),await r.release()})(),ee)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{Z.shutdown(P).then(()=>process.exit(0))});return M.info("daemon ready",{port:$,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(a.frameworksCache??{}),libVersion:a.libVersion??"dev"}),Z}function ba(r){return r.length<=8?"***":`${r.slice(0,4)}***${r.slice(-4)}`}function Rf(r,e,i){return`${r??""}|${e??""}|${i??""}`}async function Bf(r,e){let{readdir:i}=await import("node:fs/promises"),a;try{a=await i(r.agentsRoot)}catch{return}let{loadAgentConfig:c,enforceAgentConfigMode:u}=await Promise.resolve().then(()=>(Je(),dn));for(let f of a){await u(f,r).catch(h=>M.warn("enforceAgentConfigMode failed (ignored)",{agentId:f,err:String(h)}));try{let h=await c(f,r);h?.disconnectedAt&&(e.disconnectedAgents.add(f),M.info("agent marked disconnected on startup",{agentId:f,disconnectedAt:h.disconnectedAt,reason:h.disconnectReason??""}))}catch(h){M.warn("failed to load agent config on startup, skipping",{agentId:f,err:String(h)})}}}async function Mf(r,e,i,a){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(Je(),dn)),u=await c(r,e);if(u){M.info("--agent-id: local config found, reconnecting",{agentId:r,framework:u.framework,hadDisconnect:!!u.disconnectedAt});let _={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{}};return await i.createAgent(_),{ok:!0,agentId:r,note:u.disconnectedAt?"revived from local config":"connected from local config"}}M.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:r});let f=await a({_meta:{cozeAgentId:r}});if(!f.framework)throw new C("AGENT_NOT_FOUND",`agent ${r} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let h={agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await i.createAgent(h);let m=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:r,note:m?"cloud agent acknowledged":"created from cloud detail"}}async function va(r,e){let{readdir:i}=await import("node:fs/promises"),a;try{a=await i(r.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(a.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:c}=await Promise.resolve().then(()=>(Je(),dn));M.info("auto-revive: scanning local agents on startup",{count:a.length});let u=0,f=0;for(let h of a){let m;try{m=await c(h,r)}catch(_){M.warn("auto-revive: load config failed (skipping)",{agentId:h,err:String(_)}),f+=1;continue}if(!m){f+=1;continue}if(m.disconnectedAt){M.info("auto-revive: skip disconnected agent",{agentId:h,disconnectedAt:m.disconnectedAt}),f+=1;continue}try{M.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:h,framework:m.framework}),await e.createAgent({agentId:m.agentId,framework:m.framework,...m.cozeIdentity?{cozeIdentity:m.cozeIdentity}:{},...m.model?{model:m.model}:{},...m.deployType?{_meta:{cozeDeployType:m.deployType}}:{}}),u+=1}catch(_){M.warn("auto-revive: createAgent failed (skipping)",{agentId:h,framework:m.framework,err:String(_)}),f+=1}}return M.info("auto-revive: done",{revived:u,skipped:f,total:a.length}),{revived:u,skipped:f,total:a.length}}us();le();import{readFile as Ea}from"node:fs/promises";var Ze=class{paths;constructor(e){this.paths=e??H()}async probe(e=1e3){let i=await this.readAuth();if(!i)return{kind:"not-running"};try{let a=await this.fetch(i,{method:"GET",path:"/status",timeoutMs:e});return a.status===200?{kind:"connected",...i}:{kind:"stale",reason:`unexpected status ${a.status}`}}catch(a){return{kind:"stale",reason:jf(a)}}}async request(e){let i=await this.readAuth();if(!i)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(i,e)}async readAuth(){try{let[e,i]=await Promise.all([Ea(this.paths.portFile,"utf8"),Ea(this.paths.tokenFile,"utf8")]),a=Number.parseInt(e.trim(),10),c=i.trim();return!Number.isFinite(a)||a<=0||!c?null:{port:a,token:c}}catch(e){if(e.code==="ENOENT")return null;throw e}}async fetch(e,i){let a=i.body!==void 0,c={Authorization:`Bearer ${e.token}`};a&&(c["content-type"]="application/json");let u=new AbortController,f=setTimeout(()=>u.abort(),i.timeoutMs??5e3);try{let h=await fetch(`http://127.0.0.1:${e.port}${i.path}`,{method:i.method,headers:c,body:a?JSON.stringify(i.body):void 0,signal:u.signal}),m=await h.text();return{status:h.status,body:Hf(m)}}finally{clearTimeout(f)}}};function Hf(r){if(!r)return null;try{return JSON.parse(r)}catch{return r}}function jf(r){return r instanceof Error?r.message:String(r)}K();le();import{copyFile as Aa,mkdir as Wf,readFile as fs,writeFile as Jf}from"node:fs/promises";import{dirname as Vf,resolve as ds,sep as ar}from"node:path";import{fileURLToPath as Xf}from"node:url";K();le();var ka=N("dist-install");function Yf(r){let e=Xf(r),i=Vf(e),a=`${ar}src${ar}`;if(i.includes(a)||i.endsWith(`${ar}src${ar}cli`))return null;let c=ds(i,"index.js"),u=ds(i,"..","package.json");return{dist:c,pkgJson:u}}async function Ia(r={}){let e=r.paths??H(),i=Yf(import.meta.url),a=r.sourceDist??i?.dist,c=r.sourcePackageJson??i?.pkgJson;if(!a||!c)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};let u;try{u=JSON.parse(await fs(c,"utf8")).version??"unknown"}catch(v){return ka.warn("cannot read source package.json,skip dist install",{err:String(v)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(v)}`}}let f=await Rn(e.configFile)??{},h=f.libVersion;if(h===u)try{return await fs(e.libEntry),{kind:"already-current",libVersion:u}}catch{}await Wf(e.libDir,{recursive:!0}),await Aa(a,e.libEntry),await Aa(`${a}.map`,`${e.libEntry}.map`).catch(()=>{});let m=ds(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
|
|
97
|
+
`;return await fs(m,"utf8").catch(()=>null)!==_&&await Jf(m,_),f.libVersion=u,await vt(f,e.configFile),ka.info("dist installed",{libEntry:e.libEntry,fromVersion:h,toVersion:u}),h?{kind:"version-changed",fromVersion:h,toVersion:u,libEntry:e.libEntry}:{kind:"first-install",libVersion:u,libEntry:e.libEntry}}var gd=N("cli");function Tt(r,e){let i=[],a;for(let c=0;c<r.length;c++){let u=r[c];if(u===e){a=r[c+1],c+=1;continue}if(u.startsWith(`${e}=`)){a=u.slice(e.length+1);continue}i.push(u)}return{value:a,rest:i}}function pd(r){let e=r.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e.includes("--status"))return{mode:"status"};if(e.includes("--stop"))return{mode:"stop"};if(e.includes("--refresh"))return{mode:"refresh"};if(e.includes("--uninstall"))return{mode:"uninstall"};if(e.includes("--install-service"))return{mode:"install-service"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let i=e,{value:a,rest:c}=Tt(i,"--pat-token");i=c;let{value:u,rest:f}=Tt(i,"--pair-code");i=f;let{value:h,rest:m}=Tt(i,"--env");i=m;let{value:_,rest:y}=Tt(i,"--handshake-url");i=y;let{value:v,rest:S}=Tt(i,"--frontier-url");i=S;let{value:A}=Tt(i,"--agent-id");if(!a||!u)return{mode:"help"};let D={mode:"pair",privatecode:a,pairingCode:u};return h&&(D.env=h),_&&(D.handshakeUrl=_),v&&(D.frontierUrl=v),A&&(D.agentId=A),D}var md=`
|
|
98
98
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
99
99
|
|
|
100
100
|
Usage:
|
|
@@ -122,36 +122,36 @@ Auto-connect agent (optional):
|
|
|
122
122
|
|
|
123
123
|
Internal:
|
|
124
124
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
125
|
-
`.trimStart();async function
|
|
126
|
-
`),0;case"daemon":{try{await
|
|
127
|
-
`),1;if(
|
|
128
|
-
`),1;let
|
|
129
|
-
${JSON.stringify(
|
|
130
|
-
`),0}async function
|
|
131
|
-
`),0;if(
|
|
132
|
-
`),0;try{return await
|
|
133
|
-
`),0}catch(
|
|
134
|
-
`),1}}async function
|
|
135
|
-
`),1;try{let
|
|
136
|
-
${JSON.stringify(
|
|
137
|
-
`),0):(process.stderr.write(`coze-bridge: refresh failed: ${JSON.stringify(
|
|
138
|
-
`),1)}catch(
|
|
139
|
-
`),1}}async function
|
|
140
|
-
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(
|
|
141
|
-
`)}await new Promise(
|
|
142
|
-
`)}catch(
|
|
143
|
-
`)}let r
|
|
144
|
-
`)}catch(
|
|
125
|
+
`.trimStart();async function Ra(r=process.argv,e={}){let i=pd(r);switch(i.mode){case"help":return process.stdout.write(md),0;case"version":return process.stdout.write(`${wn}
|
|
126
|
+
`),0;case"daemon":{try{await Sa()}catch(a){return gd.error("daemon start failed",{err:String(a)}),1}return new Promise(()=>{})}case"status":return _d(e);case"stop":return wd(e);case"refresh":return yd(e);case"uninstall":return bd(e);case"install-service":return vd();case"pair":{let a={};return i.env&&(a.env=i.env),i.handshakeUrl&&(a.handshakeUrl=i.handshakeUrl),i.frontierUrl&&(a.frontierUrl=i.frontierUrl),Sd(i.privatecode,i.pairingCode,e,a,i.agentId)}}}async function Ba(r){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(r.pidFile).catch(()=>{}),e(r.portFile).catch(()=>{}),e(r.tokenFile).catch(()=>{})])}async function _d(r){let e=r.paths??H(),i=new Ze(e),a=await i.probe();if(a.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
127
|
+
`),1;if(a.kind==="stale")return await Ba(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
128
|
+
`),1;let c=await i.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
129
|
+
${JSON.stringify(c.body,null,2)}
|
|
130
|
+
`),0}async function wd(r){let e=r.paths??H(),i=new Ze(e),a=await i.probe();if(a.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
131
|
+
`),0;if(a.kind==="stale")return await Ba(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
132
|
+
`),0;try{return await i.request({method:"POST",path:"/shutdown"}),process.stdout.write(`coze-bridge: stopped
|
|
133
|
+
`),0}catch(c){return process.stdout.write(`coze-bridge: stop failed: ${String(c)}
|
|
134
|
+
`),1}}async function yd(r){let e=new Ze(r.paths);if((await e.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
135
|
+
`),1;try{let a=await e.request({method:"POST",path:"/refresh"});return a.status===200?(process.stdout.write(`coze-bridge: refreshed
|
|
136
|
+
${JSON.stringify(a.body,null,2)}
|
|
137
|
+
`),0):(process.stderr.write(`coze-bridge: refresh failed: ${JSON.stringify(a.body)}
|
|
138
|
+
`),1)}catch(a){return process.stderr.write(`coze-bridge: refresh failed: ${String(a)}
|
|
139
|
+
`),1}}async function bd(r){let e=new Ze(r.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
140
|
+
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(u){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(u)}
|
|
141
|
+
`)}await new Promise(u=>setTimeout(u,500))}if(!r.skipSupervisor)try{let{getSupervisor:u,buildContext:f}=await Promise.resolve().then(()=>(ws(),_s)),h=u();await h.uninstall(f()),process.stdout.write(`coze-bridge: ${h.platform} supervisor unregistered
|
|
142
|
+
`)}catch(u){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(u)}
|
|
143
|
+
`)}let a=r.paths??H(),{rm:c}=await import("node:fs/promises");try{await c(a.cozeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${a.cozeRoot}
|
|
144
|
+
`)}catch(u){return process.stderr.write(`coze-bridge: remove failed: ${String(u)}
|
|
145
145
|
`),1}return process.stdout.write(`coze-bridge: uninstalled
|
|
146
|
-
`),0}async function
|
|
147
|
-
`),await
|
|
148
|
-
`),0}catch(
|
|
149
|
-
`),1}}async function
|
|
150
|
-
`),(await
|
|
151
|
-
`)}let
|
|
152
|
-
`),await
|
|
153
|
-
`),1;let
|
|
154
|
-
`),0):(process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(
|
|
155
|
-
`),1)}catch(
|
|
156
|
-
`),1}}async function
|
|
146
|
+
`),0}async function vd(){try{let{getSupervisor:r,buildContext:e}=await Promise.resolve().then(()=>(ws(),_s)),i=r(),a=e();return process.stdout.write(`coze-bridge: installing ${i.platform} supervisor...
|
|
147
|
+
`),await i.install(a),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
148
|
+
`),0}catch(r){return process.stderr.write(`coze-bridge: --install-service failed: ${String(r)}
|
|
149
|
+
`),1}}async function Sd(r,e,i,a={},c){let u=new Ze(i.paths),f=i.spawnDaemon??Ca;if(!i.skipDistInstall){let _=await Ia({paths:i.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
|
|
150
|
+
`),(await u.probe()).kind==="connected"&&(await u.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(v=>setTimeout(v,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
|
|
151
|
+
`)}let h=await u.probe();if(h.kind!=="connected"&&(process.stdout.write(`coze-bridge: starting daemon...
|
|
152
|
+
`),await f({paths:i.paths}),h=await Cd(u,i.waitTimeoutMs??1e4,i.sleep??Ed),h.kind!=="connected"))return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
|
|
153
|
+
`),1;let m={privatecode:r,pairing_code:e};a.env&&(m.env=a.env),a.handshakeUrl&&(m.handshake_url=a.handshakeUrl),a.frontierUrl&&(m.frontier_url=a.frontierUrl),c&&(m.agent_id=c);try{let _=await u.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});return _.status===200&&_.body?.ok?(process.stdout.write(`coze-bridge: paired (${_.body.note??"ok"})
|
|
154
|
+
`),0):(process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
|
|
155
|
+
`),1)}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
|
|
156
|
+
`),1}}async function Cd(r,e,i){let a=Date.now()+e;for(;Date.now()<a;){let c=await r.probe(500);if(c.kind==="connected")return c;await i(200)}return r.probe(500)}function Ed(r){return new Promise(e=>setTimeout(e,r))}Ra(process.argv).then(r=>process.exit(r),r=>{process.stderr.write(`fatal: ${r instanceof Error?r.stack??r.message:String(r)}
|
|
157
157
|
`),process.exit(1)});
|