coze-bridge 0.1.98-alpha.2 → 0.1.98-alpha.4

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -79
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,34 +5,34 @@ 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 Dp=Object.create;var fa=Object.defineProperty;var kp=Object.getOwnPropertyDescriptor;var Op=Object.getOwnPropertyNames;var Pp=Object.getPrototypeOf,Lp=Object.prototype.hasOwnProperty;var de=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ke=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ua=(t,e)=>{for(var r in e)fa(t,r,{get:e[r],enumerable:!0})},Np=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Op(e))!Lp.call(t,o)&&o!==r&&fa(t,o,{get:()=>e[o],enumerable:!(i=kp(e,o))||i.enumerable});return t};var bt=(t,e,r)=>(r=t!=null?Dp(Pp(t)):{},Np(e||!t||!t.__esModule?fa(r,"default",{value:t,enumerable:!0}):r,t));function Mt(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Vi=Ke(()=>{"use strict"});import{createWriteStream as Mp,mkdirSync as Bp,readdirSync as zp,unlinkSync as Fp}from"node:fs";import{join as Xd}from"node:path";function Sn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function Jn(t,e){return`${t}-${e}.log`}function ha(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function Up(t,e,r){let i=c=>{let[d,f,h]=c.split("-").map(Number);return Date.UTC(d??0,(f??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Ji(t,e,r,i){let o;try{o=zp(t)}catch{return}for(let c of o){let d=ha(c,e);if(d&&Up(d,r,i))try{Fp(Xd(t,c))}catch{}}}var jr,xa=Ke(()=>{"use strict";jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Sn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{Bp(this.dir,{recursive:!0});let r=Mp(Xd(this.dir,Jn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var Op=Object.create;var ha=Object.defineProperty;var Pp=Object.getOwnPropertyDescriptor;var Lp=Object.getOwnPropertyNames;var Np=Object.getPrototypeOf,Mp=Object.prototype.hasOwnProperty;var de=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Je=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),xa=(t,e)=>{for(var r in e)ha(t,r,{get:e[r],enumerable:!0})},Bp=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Lp(e))!Mp.call(t,o)&&o!==r&&ha(t,o,{get:()=>e[o],enumerable:!(i=Pp(e,o))||i.enumerable});return t};var It=(t,e,r)=>(r=t!=null?Op(Np(t)):{},Bp(e||!t||!t.__esModule?ha(r,"default",{value:t,enumerable:!0}):r,t));function Ft(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Yi=Je(()=>{"use strict"});import{createWriteStream as zp,mkdirSync as Fp,readdirSync as Up,unlinkSync as Gp}from"node:fs";import{join as Qd}from"node:path";function An(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function Xn(t,e){return`${t}-${e}.log`}function pa(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function Hp(t,e,r){let i=c=>{let[l,f,h]=c.split("-").map(Number);return Date.UTC(l??0,(f??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Xi(t,e,r,i){let o;try{o=Up(t)}catch{return}for(let c of o){let l=pa(c,e);if(l&&Hp(l,r,i))try{Gp(Qd(t,c))}catch{}}}var jr,ga=Je(()=>{"use strict";jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>An(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{Fp(this.dir,{recursive:!0});let r=zp(Qd(this.dir,Xn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
9
9
  `)),this.stream=r}catch(r){process.stderr.write(`[log-sink] rotate failed: ${String(r)}
10
- `),this.stream=void 0;return}this.currentDate!==void 0&&Ji(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as Gp,mkdirSync as jp}from"node:fs";import{join as Hp}from"node:path";function el(t){let e=t.retentionDays??$p,r=t.clock??(()=>Sn(new Date));Xi={bridgeSink:new jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();Ji(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])Ji(t.agentLogsDir(o),"agent",i,e)}function Kp(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function tl(t){pa=t}function nl(t){return Yn[pa]<=Yn[t]}function rl(t,e){let r=Yn[t];return r===void 0?!0:r>=Yn[e]}function Qi(t){Qd={...t}}function il(t){let e=(f,h=2)=>String(f).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Sn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function Hr(t,e,r,i,o){try{let c=`${JSON.stringify({ts:il(new Date),level:e,module:r,msg:i,...o})}
11
- `;jp(t,{recursive:!0}),Gp(Hp(t,Jn("bridge",Sn(new Date))),c)}catch{}}function Zp(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function Yi(t,e,r,i,o){if(Yn[t]<Yn[pa])return;let c=`${JSON.stringify({ts:il(new Date),level:t,module:e,msg:r,...Qd,...i})}
12
- `;if(Xi){let d=Zp(o,i),f=d?Kp(Xi,d):Xi.bridgeSink;try{f.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Wp.write(c):qp.write(c)}function G(t,e){return{debug:(r,i)=>Yi("debug",t,r,i,e),info:(r,i)=>Yi("info",t,r,i,e),warn:(r,i)=>Yi("warn",t,r,i,e),error:(r,i)=>Yi("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var Yn,pa,qp,Wp,Qd,$p,Xi,ne=Ke(()=>{"use strict";Vi();xa();Yn={debug:10,info:20,warn:30,error:40},pa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),qp=process.stdout,Wp=process.stderr,Qd={},$p=Mt("COZE_BRIDGE_LOG_RETENTION_DAYS",30),Xi=null});var T,qe=Ke(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var cl={};ua(cl,{ACP_WRAPPER_NPM_PACKAGES:()=>Wr,_resetAcpInstallerForTests:()=>eg,_setBinaryPathCacheForTests:()=>tg,buildAcpSpawn:()=>$r,ensureAcpInstalled:()=>Xn,getAcpBinaryPath:()=>es,pickWhichLine:()=>wa,probeAcpVersion:()=>Qp,resolveAcpCommand:()=>al});import{readFileSync as sl}from"node:fs";import{createRequire as Vp}from"node:module";import{dirname as Jp,resolve as Yp}from"node:path";function wa(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function Xp(t){let e=ol.resolve(`${t.npmPackage}/package.json`),r=Jp(e),i=JSON.parse(sl(e,"utf8")),o=typeof i.bin=="string"?i.bin:i.bin?.[t.binary];if(!o)throw new Error(`${t.npmPackage} package.json \u7F3A bin[${t.binary}]`);return Yp(r,o)}async function Xn(t,e){let r=ma[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=qr.get(t);if(i)return i;try{let o=Xp(r);return qr.set(t,o),ga.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw ga.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
- `),{cause:o})}}async function Qp(t){let e=ma[t];if(e)try{let r=ol.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(sl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){ga.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function es(t){return qr.get(t)}function al(t,e){if(e)return e;let r=es(t);if(!r)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function $r(t,e,r){if(e)return{command:e,args:[...r]};let i=al(t);return{command:process.execPath,args:[i,...r]}}function eg(){qr.clear()}function tg(t,e){qr.set(t,e)}var ga,ma,Wr,ol,qr,en=Ke(()=>{"use strict";qe();ne();ga=G("agents.acp-installer"),ma={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Wr=Object.values(ma).filter(t=>t!==void 0).map(t=>t.npmPackage),ol=Vp(import.meta.url),qr=new Map});import{chmod as rg,mkdir as ig,readFile as sg,rename as fl,writeFile as ul}from"node:fs/promises";import{dirname as og}from"node:path";async function Qn(t){try{let e=await sg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function er(t,e,r){await ig(og(t),{recursive:!0});let i=`${JSON.stringify(e,null,2)}
14
- `,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await ul(o,i,{encoding:"utf8",mode:r.mode}):await ul(o,i,"utf8"),await fl(o,t),r?.mode!==void 0&&await rg(t,r.mode)}catch(c){await fl(o,o).catch(()=>{});let{rm:d}=await import("node:fs/promises");throw await d(o,{force:!0}).catch(()=>{}),c}}var Kr=Ke(()=>{"use strict"});import{promises as hl,readdirSync as ag}from"node:fs";import{homedir as cg}from"node:os";import{sep as dg,join as Ae,resolve as xl}from"node:path";function Y(t){let e=t??cg(),r=Ae(e,".coze"),i=Ae(r,"bridge"),o=Ae(i,"lib"),c=Ae(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ae(o,"index.js"),binDir:Ae(i,"bin"),pidFile:Ae(i,"bridge.pid"),portFile:Ae(i,"bridge.port"),tokenFile:Ae(i,"bridge.token"),patTokenFile:Ae(i,"pat-token"),agentEnvFile:Ae(i,"agent-env.json"),logFile:Ae(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ae(c,"daemon-stdio.log"),installLock:Ae(i,"install.lock"),configFile:Ae(i,"config.json"),agentsRoot:Ae(r,"agents")}}function Ze(t,e=Y()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function ts(t=Y()){try{return ag(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Zr(t,e){let r=await hl.realpath(xl(t)).catch(()=>null);if(!r)return!1;let i=await hl.realpath(xl(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?r.toLowerCase():r,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+dg)}var ke=Ke(()=>{"use strict"});var is={};ua(is,{AGENT_CONFIG_FILE_MODE:()=>ns,enforceAgentConfigMode:()=>ug,loadAgentConfig:()=>Ge,persistAgentSessions:()=>Vr,persistAgentSkills:()=>rs,saveAgentConfig:()=>Ve});import{chmod as lg,stat as fg}from"node:fs/promises";function Ge(t,e){return Qn(Ze(t,e).config)}function Ve(t,e){return er(Ze(t.agentId,e).config,t,{mode:ns})}async function ug(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await fg(r);if(!i.isFile())return;let o=i.mode&511;o!==ns&&(await lg(r,ns),pl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;pl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Vr(t,e,r){let i=await Ge(t,r);i&&(i.sessions=Object.fromEntries(e),await Ve(i,r))}async function rs(t,e,r){let i=await Ge(t,r);i&&(i.skills=e,await Ve(i,r))}var pl,ns,tn=Ke(()=>{"use strict";Kr();ne();ke();pl=G("agent-config"),ns=384});var _a=se((NS,yl)=>{yl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var os=se(El=>{var _l={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function mg(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(_l))El[t]=mg(_l[t])});var Al=se((BS,Il)=>{var wg=de("fs"),Oe=de("path"),bl=_a(),yg=os(),_g=typeof process=="object"&&process.platform==="win32",vl=t=>typeof t=="object"&&t!==null,Sl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=wg,vl(t)&&vl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Il.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(f){if(f.message&&f.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw f}if(d&&d.isFile())throw yg.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ee.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Oe.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var f;try{f=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),f=o.fs.openSync(t,"w",438)}if(f)try{o.fs.writeSync(f,e,0,e.length,0)}finally{o.fs.closeSync(f)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(f,h){if(d&&h.isDirectory())return o(!1);var x=Oe.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),c.fs.open(t,"w",438,function(g,A){g?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(w,E){c.fs.write(E,e,0,e.length,0,function(){c.fs.close(E,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):A?c.fs.write(A,e,0,e.length,0,function(){c.fs.close(A,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(f){let h=Oe.join(i,f),x=e.fs.statSync(h);(!o||o.test(h))&&d.push(Oe.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(h,o,c)))}),d}return r(t,void 0,!0)};Ee.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(f){f=Oe.join(t,f),r.fs.stat(f,function(h,x){if(h)return e(h);x&&(i.push(Oe.normalize(f)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(f,function(m,g){if(m)return e(m);i=i.concat(g),--d||e(null,i)}):--d||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Sl[(t^e)&255]^t>>>8};Ee.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ee.crc32update(r,t[i++]);return~r>>>0};Ee.methodToString=function(t){switch(t){case bl.STORED:return"STORED ("+t+")";case bl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Oe.normalize(Oe.join(t,r.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=_g;Ee.crcTable=Sl});var Rl=se((zS,Tl)=>{var Eg=de("path");Tl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=Eg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Dl=se((FS,Cl)=>{Cl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var rr=se((US,nr)=>{nr.exports=Al();nr.exports.Constants=_a();nr.exports.Errors=os();nr.exports.FileAttr=Rl();nr.exports.decoder=Dl()});var Ol=se((GS,kl)=>{var nn=rr(),F=nn.Constants;kl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,f=0,h=0,x=0,m=0,g=0,A=0,w=0,E=0;t|=nn.isWin?2560:768,r|=F.FLG_EFS;let I={extraLen:0},S=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,P=y=>Math.max(0,y)&255;return o=nn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&F.FLG_EFS)>0},set flags_efs(y){y?r|=F.FLG_EFS:r&=~F.FLG_EFS},get flags_desc(){return(r&F.FLG_DESC)>0},set flags_desc(y){y?r|=F.FLG_DESC:r&=~F.FLG_DESC},get method(){return i},set method(y){switch(y){case F.STORED:this.version=10;case F.DEFLATED:default:this.version=20}i=y},get time(){return nn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=nn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=S(y)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(y){c=S(y)},get compressedSize(){return d},set compressedSize(y){d=S(y)},get size(){return f},set size(y){f=S(y)},get fileNameLength(){return h},set fileNameLength(y){h=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return m},set commentLength(y){m=y},get diskNumStart(){return g},set diskNumStart(y){g=S(y)},get inAttr(){return A},set inAttr(y){A=S(y)},get attr(){return w},set attr(y){w=S(y)},get fileAttr(){return(w||0)>>16&4095},get offset(){return E},set offset(y){E=S(y)},get encrypted(){return(r&F.FLG_ENC)===F.FLG_ENC},get centralHeaderSize(){return F.CENHDR+h+x+m},get realDataOffset(){return E+F.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(E,E+F.LOCHDR);if(C.readUInt32LE(0)!==F.LOCSIG)throw nn.Errors.INVALID_LOC();I.version=C.readUInt16LE(F.LOCVER),I.flags=C.readUInt16LE(F.LOCFLG),I.flags_desc=(I.flags&F.FLG_DESC)>0,I.method=C.readUInt16LE(F.LOCHOW),I.time=C.readUInt32LE(F.LOCTIM),I.crc=C.readUInt32LE(F.LOCCRC),I.compressedSize=C.readUInt32LE(F.LOCSIZ),I.size=C.readUInt32LE(F.LOCLEN),I.fnameLen=C.readUInt16LE(F.LOCNAM),I.extraLen=C.readUInt16LE(F.LOCEXT);let D=E+F.LOCHDR+I.fnameLen,N=D+I.extraLen;return y.slice(D,N)},loadFromBinary:function(y){if(y.length!==F.CENHDR||y.readUInt32LE(0)!==F.CENSIG)throw nn.Errors.INVALID_CEN();t=y.readUInt16LE(F.CENVEM),e=y.readUInt16LE(F.CENVER),r=y.readUInt16LE(F.CENFLG),i=y.readUInt16LE(F.CENHOW),o=y.readUInt32LE(F.CENTIM),c=y.readUInt32LE(F.CENCRC),d=y.readUInt32LE(F.CENSIZ),f=y.readUInt32LE(F.CENLEN),h=y.readUInt16LE(F.CENNAM),x=y.readUInt16LE(F.CENEXT),m=y.readUInt16LE(F.CENCOM),g=y.readUInt16LE(F.CENDSK),A=y.readUInt16LE(F.CENATT),w=y.readUInt32LE(F.CENATX),E=y.readUInt32LE(F.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(F.LOCHDR);return y.writeUInt32LE(F.LOCSIG,0),y.writeUInt16LE(e,F.LOCVER),y.writeUInt16LE(r,F.LOCFLG),y.writeUInt16LE(i,F.LOCHOW),y.writeUInt32LE(o,F.LOCTIM),y.writeUInt32LE(c,F.LOCCRC),y.writeUInt32LE(d,F.LOCSIZ),y.writeUInt32LE(f,F.LOCLEN),y.writeUInt16LE(h,F.LOCNAM),y.writeUInt16LE(I.extraLen,F.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(F.CENHDR+h+x+m);return y.writeUInt32LE(F.CENSIG,0),y.writeUInt16LE(t,F.CENVEM),y.writeUInt16LE(e,F.CENVER),y.writeUInt16LE(r,F.CENFLG),y.writeUInt16LE(i,F.CENHOW),y.writeUInt32LE(o,F.CENTIM),y.writeUInt32LE(c,F.CENCRC),y.writeUInt32LE(d,F.CENSIZ),y.writeUInt32LE(f,F.CENLEN),y.writeUInt16LE(h,F.CENNAM),y.writeUInt16LE(x,F.CENEXT),y.writeUInt16LE(m,F.CENCOM),y.writeUInt16LE(g,F.CENDSK),y.writeUInt16LE(A,F.CENATT),y.writeUInt32LE(w,F.CENATX),y.writeUInt32LE(E,F.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:nn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(f),fileNameLength:y(h),extraLength:y(x),commentLength:y(m),diskNumStart:g,inAttr:A,attr:w,offset:E,centralHeaderSize:y(F.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ll=se((jS,Pl)=>{var ir=rr(),me=ir.Constants;Pl.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return me.ENDHDR+o},loadFromBinary:function(c){if((c.length!==me.ENDHDR||c.readUInt32LE(0)!==me.ENDSIG)&&(c.length<me.ZIP64HDR||c.readUInt32LE(0)!==me.ZIP64SIG))throw ir.Errors.INVALID_END();c.readUInt32LE(0)===me.ENDSIG?(t=c.readUInt16LE(me.ENDSUB),e=c.readUInt16LE(me.ENDTOT),r=c.readUInt32LE(me.ENDSIZ),i=c.readUInt32LE(me.ENDOFF),o=c.readUInt16LE(me.ENDCOM)):(t=ir.readBigUInt64LE(c,me.ZIP64SUB),e=ir.readBigUInt64LE(c,me.ZIP64TOT),r=ir.readBigUInt64LE(c,me.ZIP64SIZE),i=ir.readBigUInt64LE(c,me.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(me.ENDHDR+o);return c.writeUInt32LE(me.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,me.ENDSUB),c.writeUInt16LE(e,me.ENDTOT),c.writeUInt32LE(r,me.ENDSIZ),c.writeUInt32LE(i,me.ENDOFF),c.writeUInt16LE(o,me.ENDCOM),c.fill(" ",me.ENDHDR),c},toJSON:function(){let c=function(d,f){let h=d.toString(16).toUpperCase();for(;h.length<f;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ba=se(Ea=>{Ea.EntryHeader=Ol();Ea.MainHeader=Ll()});var Ml=se((qS,Nl)=>{Nl.exports=function(t){var e=de("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(f){c.push(f),d+=f.length}),o.on("end",function(){var f=Buffer.alloc(d),h=0;f.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(f,h),h+=m.length}i&&i(f)}),o.end(t)}}}});var zl=se((WS,Bl)=>{var bg=+(process.versions?process.versions.node:"").split(".")[0]||0;Bl.exports=function(t,e){var r=de("zlib");let i=bg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],f=0;c.on("data",function(h){d.push(h),f+=h.length}),c.on("end",function(){var h=Buffer.alloc(f),x=0;h.fill(0);for(var m=0;m<d.length;m++){var g=d[m];g.copy(h,x),x+=g.length}o&&o(h)}),c.end(t)}}}});var Hl=se(($S,jl)=>{"use strict";var{randomFillSync:Fl}=de("crypto"),vg=os(),Sg=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),Gl=(t,e)=>Math.imul(t,e)>>>0,Ul=(t,e)=>Sg[(t^e)&255]^t>>>8,Jr=()=>typeof Fl=="function"?Fl(Buffer.alloc(12)):Jr.node();Jr.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var as={genSalt:Jr};function cs(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let r=0;r<e.length;r++)this.updateKeys(e[r])}cs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Ul(e[0],t),e[1]+=e[0]&255,e[1]=Gl(e[1],134775813)+1,e[2]=Ul(e[2],e[1]>>>24),t};cs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Gl(t,t^1)>>8&255};function Ig(t){let e=new cs(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function Ag(t){let e=new cs(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function Tg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Ig(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw vg.WRONG_PASSWORD();return i(t.slice(12))}function Rg(t){Buffer.isBuffer(t)&&t.length>=12?as.genSalt=function(){return t.slice(0,12)}:t==="node"?as.genSalt=Jr.node:as.genSalt=Jr}function Cg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Ag(r),c=as.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}jl.exports={decrypt:Tg,encrypt:Cg,_salter:Rg}});var ql=se(ds=>{ds.Deflater=Ml();ds.Inflater=zl();ds.ZipCrypto=Hl()});var Sa=se((ZS,Wl)=>{var oe=rr(),Dg=ba(),be=oe.Constants,va=ql();Wl.exports=function(t,e){var r=new Dg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,f=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let m=t,g=typeof m.decoder=="object"?m.decoder:oe.decoder;x=g.hasOwnProperty("efs")?g.efs:!1;function A(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function w(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let C={},D=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(D)==be.LOCSIG||e.readUInt32LE(D)==be.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(D)==be.EXTSIG)C.crc=e.readUInt32LE(D+be.EXTCRC),C.compressedSize=e.readUInt32LE(D+be.EXTSIZ),C.size=e.readUInt32LE(D+be.EXTLEN);else if(e.readUInt16LE(D+12)===19280)C.crc=e.readUInt32LE(D+be.EXTCRC-4),C.compressedSize=e.readUInt32LE(D+be.EXTSIZ-4),C.size=e.readUInt32LE(D+be.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==C.crc)return!1}return!0}function E(y,C,D){if(typeof C>"u"&&typeof y=="string"&&(D=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),oe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var N=A();if(N.length===0)return y&&C&&C(N),N;if(r.encrypted){if(typeof D!="string"&&!Buffer.isBuffer(D))throw oe.Errors.INVALID_PASS_PARAM();N=va.ZipCrypto.decrypt(N,r,D)}var M=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(N.copy(M),w(M))return y&&C&&C(M),M;throw y&&C&&C(M,oe.Errors.BAD_CRC()),oe.Errors.BAD_CRC();case oe.Constants.DEFLATED:var K=new va.Inflater(N,r.size);if(y)K.inflateAsync(function(Z){Z.copy(Z,0),C&&(w(Z)?C(Z):C(Z,oe.Errors.BAD_CRC()))});else{if(K.inflate(M).copy(M,0),!w(M))throw oe.Errors.BAD_CRC(`"${g.decode(i)}"`);return M}break;default:throw y&&C&&C(Buffer.alloc(0),oe.Errors.UNKNOWN_METHOD()),oe.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(A()),A();if(d.length&&!c){var D;switch(r.method){case oe.Constants.STORED:return r.compressedSize=r.size,D=Buffer.alloc(d.length),d.copy(D),y&&C&&C(D),D;default:case oe.Constants.DEFLATED:var N=new va.Deflater(d);if(y)N.deflateAsync(function(K){D=Buffer.alloc(K.length),r.compressedSize=K.length,K.copy(D),C&&C(D)});else{var M=N.deflate();return r.compressedSize=M.length,M}N=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function S(y,C){return oe.readBigUInt64LE(y,C)}function R(y){try{for(var C=0,D,N,M;C+4<y.length;)D=y.readUInt16LE(C),C+=2,N=y.readUInt16LE(C),C+=2,M=y.slice(C,C+N),C+=N,be.ID_ZIP64===D&&P(M)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(y){var C,D,N,M;y.length>=be.EF_ZIP64_SCOMP&&(C=S(y,be.EF_ZIP64_SUNCOMP),r.size===be.EF_ZIP64_OR_32&&(r.size=C)),y.length>=be.EF_ZIP64_RHO&&(D=S(y,be.EF_ZIP64_SCOMP),r.compressedSize===be.EF_ZIP64_OR_32&&(r.compressedSize=D)),y.length>=be.EF_ZIP64_DSN&&(N=S(y,be.EF_ZIP64_RHO),r.offset===be.EF_ZIP64_OR_32&&(r.offset=N)),y.length>=be.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(be.EF_ZIP64_DSN),r.diskNumStart===be.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return g.decode(i)},get rawEntryName(){return i},set entryName(y){i=oe.toBuffer(y,g.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return f},set extra(y){f=y,r.extraLength=y.length,R(y)},get comment(){return g.decode(o)},set comment(y){if(o=oe.toBuffer(y,g.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=g.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=oe.toBuffer(y,oe.decoder.encode),!c&&d.length?(r.size=d.length,r.method=oe.Constants.DEFLATED,r.crc=oe.crc32(y),r.changed=!0):r.method=oe.Constants.STORED},getData:function(y){return r.changed?d:E(!1,null,y)},getDataAsync:function(y,C){r.changed?y(d):E(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=f.length;var y=r.centralHeaderToBinary(),C=oe.Constants.CENHDR;return i.copy(y,C),C+=i.length,f.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let C=r.localHeaderToBinary(),D=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(D,y),y+=C.length,i.copy(D,y),y+=i.length,h.copy(D,y),y+=h.length,D},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Zl=se((VS,Kl)=>{var $l=Sa(),kg=ba(),je=rr();Kl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new kg.MainHeader,d=!1,f=null;let h=new Set,x=e,{noSort:m,decoder:g}=x;t?E(x.readEntries):d=!0;function A(){let S=new Set;for(let R of Object.keys(i)){let P=R.split("/");if(P.pop(),!!P.length)for(let y=0;y<P.length;y++){let C=P.slice(0,y+1).join("/")+"/";S.add(C)}}for(let R of S)if(!(R in i)){let P=new $l(x);P.entryName=R,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,h.add(P)}}function w(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var S=c.offset,R=0;R<r.length;R++){var P=S,y=new $l(x,t);y.header=t.slice(P,P+=je.Constants.CENHDR),y.entryName=t.slice(P,P+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(P,P+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(P,P+y.header.commentLength)),S+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}h.clear(),A()}function E(S){var R=t.length-je.Constants.ENDHDR,P=Math.max(0,R-65535),y=P,C=t.length,D=-1,N=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===je.Constants.ENDSIG){D=R,N=R,C=R+je.Constants.ENDHDR,y=R-je.Constants.END64HDR;continue}if(t.readUInt32LE(R)===je.Constants.END64SIG){y=P;continue}if(t.readUInt32LE(R)===je.Constants.ZIP64SIG){D=R,C=R+je.readBigUInt64LE(t,R+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(D==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(D,C)),c.commentLength&&(o=t.slice(N+je.Constants.ENDHDR)),S&&w()}function I(){r.length>1&&!m&&r.sort((S,R)=>S.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return d||w(),r.filter(S=>!h.has(S))},get comment(){return g.decode(o)},set comment(S){o=je.toBuffer(S,g.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(S){this.entries.forEach(S)},getEntry:function(S){return d||w(),i[S]||null},setEntry:function(S){d||w(),r.push(S),i[S.entryName]=S,c.totalEntries=r.length},deleteFile:function(S,R=!0){d||w();let P=i[S];this.getEntryChildren(P,R).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(S){d||w();let R=i[S],P=r.indexOf(R);P>=0&&(r.splice(P,1),delete i[S],c.totalEntries=r.length)},getEntryChildren:function(S,R=!0){if(d||w(),typeof S=="object")if(S.isDirectory&&R){let P=[],y=S.entryName;for(let C of r)C.entryName.startsWith(y)&&P.push(C);return P}else return[S];return[]},getChildCount:function(S){if(S&&S.isDirectory){let R=this.getEntryChildren(S);return R.includes(S)?R.length-1:R.length}return 0},compressToBuffer:function(){d||w(),I();let S=[],R=[],P=0,y=0;c.size=0,c.offset=0;let C=0;for(let M of this.entries){let K=M.getCompressedData();M.header.offset=y;let Z=M.packLocalHeader(),te=Z.length+K.length;y+=te,S.push(Z),S.push(K);let X=M.packCentralHeader();R.push(X),c.size+=X.length,P+=te+X.length,C++}P+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let D=Buffer.alloc(P);for(let M of S)M.copy(D,y),y+=M.length;for(let M of R)M.copy(D,y),y+=M.length;let N=c.toBinary();return o&&o.copy(N,je.Constants.ENDHDR),N.copy(D,y),t=D,d=!1,D},toAsyncBuffer:function(S,R,P,y){try{d||w(),I();let C=[],D=[],N=0,M=0,K=0;c.size=0,c.offset=0;let Z=function(te){if(te.length>0){let X=te.shift(),_e=X.entryName+X.extra.toString();P&&P(_e),X.getCompressedDataAsync(function(he){y&&y(_e),X.header.offset=M;let O=X.packLocalHeader(),j=O.length+he.length;M+=j,C.push(O),C.push(he);let W=X.packCentralHeader();D.push(W),c.size+=W.length,N+=j+W.length,K++,Z(te)})}else{N+=c.mainHeaderSize,c.offset=M,c.totalEntries=K,M=0;let X=Buffer.alloc(N);C.forEach(function(he){he.copy(X,M),M+=he.length}),D.forEach(function(he){he.copy(X,M),M+=he.length});let _e=c.toBinary();o&&o.copy(_e,je.Constants.ENDHDR),_e.copy(X,M),t=X,d=!1,S(X)}};Z(Array.from(this.entries))}catch(C){R(C)}}}}});var Yl=se((JS,Jl)=>{var ye=rr(),we=de("path"),Og=Sa(),Pg=Zl(),In=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),Vl=(...t)=>ye.findLast(t,e=>typeof e=="string"),Lg=(...t)=>ye.findLast(t,e=>typeof e=="function"),Ng={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};Jl.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Ng);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new Pg(r,i),{canonical:d,sanitize:f,zipnamefix:h}=ye;function x(w){if(w&&c){var E;if(typeof w=="string"&&(E=c.getEntry(we.posix.normalize(w))),typeof w=="object"&&typeof w.entryName<"u"&&typeof w.header<"u"&&(E=c.getEntry(w.entryName)),E)return E}return null}function m(w){let{join:E,normalize:I,sep:S}=we.posix;return E(we.isAbsolute(w)?"/":".",I(S+w.split("\\").join(S)+S))}function g(w){return w instanceof RegExp?(function(E){return function(I){return E.test(I)}})(w):typeof w!="function"?()=>!0:w}let A=(w,E)=>{let I=E.slice(-1);return I=I===o.sep?o.sep:"",we.relative(w,E)+I};return{readFile:function(w,E){var I=x(w);return I&&I.getData(E)||null},childCount:function(w){let E=x(w);if(E)return c.getChildCount(E)},readFileAsync:function(w,E){var I=x(w);I?I.getDataAsync(E):E(null,"getEntry failed for:"+w)},readAsText:function(w,E){var I=x(w);if(I){var S=I.getData();if(S&&S.length)return S.toString(E||"utf8")}return""},readAsTextAsync:function(w,E,I){var S=x(w);S?S.getDataAsync(function(R,P){if(P){E(R,P);return}R&&R.length?E(R.toString(I||"utf8")):E("")}):E("")},deleteFile:function(w,E=!0){var I=x(w);I&&c.deleteFile(I.entryName,E)},deleteEntry:function(w){var E=x(w);E&&c.deleteEntry(E.entryName)},addZipComment:function(w){c.comment=w},getZipComment:function(){return c.comment||""},addZipEntryComment:function(w,E){var I=x(w);I&&(I.comment=E)},getZipEntryComment:function(w){var E=x(w);return E&&E.comment||""},updateFile:function(w,E){var I=x(w);I&&I.setData(E)},addLocalFile:function(w,E,I,S){if(o.fs.existsSync(w)){E=E?m(E):"";let R=we.win32.basename(we.win32.normalize(w));E+=I||R;let P=o.fs.statSync(w),y=P.isFile()?o.fs.readFileSync(w):Buffer.alloc(0);P.isDirectory()&&(E+=o.sep),this.addFile(E,y,S,P)}else throw ye.Errors.FILE_NOT_FOUND(w)},addLocalFileAsync:function(w,E){w=typeof w=="object"?w:{localPath:w};let I=we.resolve(w.localPath),{comment:S}=w,{zipPath:R,zipName:P}=w,y=this;o.fs.stat(I,function(C,D){if(C)return E(C,!1);R=R?m(R):"";let N=we.win32.basename(we.win32.normalize(I));if(R+=P||N,D.isFile())o.fs.readFile(I,function(M,K){return M?E(M,!1):(y.addFile(R,K,S,D),setImmediate(E,void 0,!0))});else if(D.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),S,D),setImmediate(E,void 0,!0)})},addLocalFolder:function(w,E,I){if(I=g(I),E=E?m(E):"",w=we.normalize(w),o.fs.existsSync(w)){let S=o.findFiles(w),R=this;if(S.length)for(let P of S){let y=we.join(E,A(w,P));I(y)&&R.addLocalFile(P,we.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(w)},addLocalFolderAsync:function(w,E,I,S){S=g(S),I=I?m(I):"",w=we.normalize(w);var R=this;o.fs.open(w,"r",function(P){if(P&&P.code==="ENOENT")E(void 0,ye.Errors.FILE_NOT_FOUND(w));else if(P)E(void 0,P);else{var y=o.findFiles(w),C=-1,D=function(){if(C+=1,C<y.length){var N=y[C],M=A(w,N).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),S(M)?o.fs.stat(N,function(K,Z){K&&E(void 0,K),Z.isFile()?o.fs.readFile(N,function(te,X){te?E(void 0,te):(R.addFile(I+M,X,"",Z),D())}):(R.addFile(I+M+"/",Buffer.alloc(0),"",Z),D())}):process.nextTick(()=>{D()})}else E(!0,void 0)};D()}})},addLocalFolderAsync2:function(w,E){let I=this;w=typeof w=="object"?w:{localPath:w},localPath=we.resolve(m(w.localPath));let{zipPath:S,filter:R,namefix:P}=w;R instanceof RegExp?R=(function(D){return function(N){return D.test(N)}})(R):typeof R!="function"&&(R=function(){return!0}),S=S?m(S):"",P=="latin1"&&(P=D=>D.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=D=>D);let y=D=>we.join(S,P(A(localPath,D))),C=D=>we.win32.basename(we.win32.normalize(P(D)));o.fs.open(localPath,"r",function(D){D&&D.code==="ENOENT"?E(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):D?E(void 0,D):o.findFilesAsync(localPath,function(N,M){if(N)return E(N);M=M.filter(K=>R(y(K))),M.length||E(void 0,!1),setImmediate(M.reverse().reduce(function(K,Z){return function(te,X){if(te||X===!1)return setImmediate(K,te,!1);I.addLocalFileAsync({localPath:Z,zipPath:we.dirname(y(Z)),zipName:C(Z)},K)}},E))})})},addLocalFolderPromise:function(w,E){return new Promise((I,S)=>{this.addLocalFolderAsync2(Object.assign({localPath:w},E),(R,P)=>{R&&S(R),P&&I(this)})})},addFile:function(w,E,I,S){w=h(w);let R=x(w),P=R!=null;P||(R=new Og(i),R.entryName=w),R.comment=I||"";let y=typeof S=="object"&&S instanceof o.fs.Stats;y&&(R.header.time=S.mtime);var C=R.isDirectory?16:0;let D=R.isDirectory?16384:32768;return y?D|=4095&S.mode:typeof S=="number"?D|=4095&S:D|=R.isDirectory?493:420,C=(C|D<<16)>>>0,R.attr=C,R.setData(E),P||c.setEntry(R),R},getEntries:function(w){return c.password=w,c?c.entries:[]},getEntry:function(w){return x(w)},getEntryCount:function(){return c.getEntryCount()},forEach:function(w){return c.forEach(w)},extractEntryTo:function(w,E,I,S,R,P){S=In(!1,S),R=In(!1,R),I=In(!0,I),P=Vl(R,P);var y=x(w);if(!y)throw ye.Errors.NO_ENTRY();var C=d(y.entryName),D=f(E,P&&!y.isDirectory?P:I?C:we.basename(C));if(y.isDirectory){var N=c.getEntryChildren(y);return N.forEach(function(Z){if(Z.isDirectory)return;var te=Z.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var X=d(Z.entryName),_e=f(E,I?X:we.basename(X));let he=R?Z.header.fileAttr:void 0;o.writeFileTo(_e,te,S,he)}),!0}var M=y.getData(c.password);if(!M)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(D)&&!S)throw ye.Errors.CANT_OVERRIDE();let K=R?w.header.fileAttr:void 0;return o.writeFileTo(D,M,S,K),!0},test:function(w){if(!c)return!1;for(var E in c.entries)try{if(E.isDirectory)continue;var I=c.entries[E].getData(w);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(w,E,I,S){if(I=In(!1,I),S=Vl(I,S),E=In(!1,E),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var P=f(w,d(R.entryName));if(R.isDirectory){o.makeDir(P);return}var y=R.getData(S);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let C=I?R.header.fileAttr:void 0;o.writeFileTo(P,y,E,C);try{o.fs.utimesSync(P,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(w,E,I,S){if(S=Lg(E,I,S),I=In(!1,I),E=In(!1,E),!S)return new Promise((D,N)=>{this.extractAllToAsync(w,E,I,function(M){M?N(M):D(this)})});if(!c){S(ye.Errors.NO_ZIP());return}w=we.resolve(w);let R=D=>f(w,we.normalize(d(D.entryName))),P=(D,N)=>new Error(D+': "'+N+'"'),y=[],C=[];c.entries.forEach(D=>{D.isDirectory?y.push(D):C.push(D)});for(let D of y){let N=R(D),M=I?D.header.fileAttr:void 0;try{o.makeDir(N),M&&o.fs.chmodSync(N,M),o.fs.utimesSync(N,D.header.time,D.header.time)}catch{S(P("Unable to create folder",N))}}C.reverse().reduce(function(D,N){return function(M){if(M)D(M);else{let K=we.normalize(d(N.entryName)),Z=f(w,K);N.getDataAsync(function(te,X){if(X)D(X);else if(!te)D(ye.Errors.CANT_EXTRACT_FILE());else{let _e=I?N.header.fileAttr:void 0;o.writeFileToAsync(Z,te,E,_e,function(he){he||D(P("Unable to write file",Z)),o.fs.utimes(Z,N.header.time,N.header.time,function(O){O?D(P("Unable to set times",Z)):D()})})}})}}},S)()},writeZip:function(w,E){if(arguments.length===1&&typeof w=="function"&&(E=w,w=""),!w&&i.filename&&(w=i.filename),!!w){var I=c.compressToBuffer();if(I){var S=o.writeFileTo(w,I,!0);typeof E=="function"&&E(S?null:new Error("failed"),"")}}},writeZipPromise:function(w,E){let{overwrite:I,perm:S}=Object.assign({overwrite:!0},E);return new Promise((R,P)=>{!w&&i.filename&&(w=i.filename),w||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=D=>D?R(D):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(w,y,I,S,C)},P)})},toBufferPromise:function(){return new Promise((w,E)=>{c.toAsyncBuffer(w,E)})},toBuffer:function(w,E,I,S){return typeof w=="function"?(c.toAsyncBuffer(w,E,I,S),null):c.compressToBuffer()}}}});import{execFile as Iy,spawn as Ay,spawnSync as dA}from"node:child_process";import{promisify as Ty}from"node:util";function Cy(t){if(process.platform!=="win32")return!1;if($u.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace($u,"").toLowerCase();return Ry.has(r)}function Ku(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return Cy(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return Ay(t,e,Ku(t,r))}function Zu(t,e=[],r={}){return Dy(t,e,Ku(t,r))}var Ry,$u,Dy,wn=Ke(()=>{"use strict";Ry=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),$u=/\.(cmd|bat|ps1)$/i;Dy=Ty(Iy)});var H0=se(Se=>{"use strict";var L=ee;(function(t,e){let r=ee,i=t();for(;;)try{if(parseInt(r(335))/1+parseInt(r(264))/2*(parseInt(r(1484))/3)+parseInt(r(1239))/4*(-parseInt(r(803))/5)+parseInt(r(385))/6*(-parseInt(r(270))/7)+-parseInt(r(813))/8+parseInt(r(770))/9+-parseInt(r(1589))/10===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(wo,708940);var gE=Object[L(681)+L(1281)],mE=Object[L(1539)+L(872)+"mes"],z0=(t,e)=>function(){return t&&(e=(0,t[{fRpIf:function(o,c){return o(c)}}.fRpIf(mE,t)[0]])(t=0)),e},wE=(t,e)=>{for(var r in e)gE(t,r,{get:e[r],enumerable:!0})};function yE(){return P0||(P0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function _E(){let t=L;return L0||(L0=[IDBCursor[t(1201)+"e"].advance,IDBCursor.prototype[t(1187)],IDBCursor.prototype["continue"+t(509)+"ey"]])}function EE(t){let e=L,r={oKGOZ:e(773)+e(802)+e(908),wBLey:function(o,c){return o===c},EQevf:e(730),vTbch:function(o,c){return o(c)},zRdOb:function(o,c){return o(c)},EZpmr:function(o){return o()},hnnWc:function(o,c){return o(c)},jEMAt:function(o,c){return o!==c},IUQtR:e(277),ftQFG:e(1116),HaAkb:e(435),rapSq:e(1186)},i=new Promise((o,c)=>{let d=e,f={NYrBP:function(g,A){return r[ee(1137)](g,A)},GpOZb:function(g,A){return r.jEMAt(g,A)},zaABj:r[d(934)],RGHuv:r.ftQFG,kdzcJ:r[d(1190)],TDsif:r[d(359)],UQDcS:function(g){return g()}},h=()=>{let g=d,A={RsUfp:function(w,E){return f[ee(1609)](w,E)}};if(f[g(696)](f[g(393)],f[g(1048)]))t[g(755)+g(798)+g(1499)](f[g(369)],x),t[g(755)+g(798)+g(1499)](f[g(975)],m);else return A.RsUfp(_0x17376d,A[g(956)](_0x4976fd,_0x4fba82))},x=()=>{let g=d,A={toToX:function(w,E){return w instanceof E},TrPiI:r.oKGOZ,gDKym:g(498)+"ion/json",EFyGO:g(367),UpGNd:g(637)};if(r[g(1580)](r.EQevf,r.EQevf))r[g(1526)](o,r[g(575)](Pt,t.result)),r[g(950)](h);else if(_0x359a2a[g(659)]instanceof _0x2bae60){let w=this[g(506)][g(979)+g(350)]instanceof _0x2791f2?{force:!!this[g(506)][g(979)+g(350)][g(1058)],encoding:this[g(506)]["payloadE"+g(350)][g(341)]?this[g(506)][g(979)+g(350)][g(341)][g(398)](/\s/g,"")[g(1565)+"ase"]():""}:{force:!1,encoding:this[g(506)][g(979)+g(350)]?this[g(506)][g(979)+g(350)][g(398)](/\s/g,"")[g(1565)+g(1348)]():""},E=_0x38accc[g(979)+g(350)]?_0x5dff9e.payloadEncoding.replace(/\s/g,"")[g(1565)+g(1348)]():"",I=A[g(599)](this[g(506)][g(518)+"ype"],_0x2473a3)?{force:!!this[g(506)][g(518)+g(1517)][g(1058)],type:this[g(506)][g(518)+g(1517)][g(819)]?this[g(506)][g(518)+g(1517)][g(819)][g(398)](/\s/g,"")["toLowerC"+g(1348)]():""}:{force:!1,type:this[g(506)][g(518)+g(1517)]?this[g(506)][g(518)+g(1517)].replace(/\s/g,"")["toLowerC"+g(1348)]():""},S=_0x3a7d0f[g(518)+g(1517)]?_0x523aa2["payloadT"+g(1517)][g(398)](/\s/g,"")[g(1565)+"ase"]():"",R=I[g(1058)]?I.type:S||I.type,P=w[g(1058)]?w[g(341)]:E||w[g(341)],y=[A[g(401)],A[g(505)],g(498)+g(1264)+g(809)+g(968),A[g(1362)]],C=["none_none",A.UpGNd];this[g(506)][g(628)+"ansformT"+g(823)+"ad"]&&y[g(1579)](R)&&(!P||C[g(1579)](P))?_0x4d7210[g(878)+g(507)]=_0x4ac20d(_0x3f1183[g(659)],0,_0x2fc215[g(659)][g(1453)+"th"]):_0x46a243[g(878)+g(507)]=""}else _0x2cd6ad[g(878)+g(507)]=""},m=()=>{let g=d;c(t[g(1186)]),f[g(1411)](h)};t["addEvent"+d(1012)](d(435),x),t[d(1330)+d(1012)](r[d(359)],m)});return i[e(538)](o=>{let c=e;o instanceof IDBCursor&&Jc[c(591)](o,t)}).catch(()=>{}),_o[e(591)](i,t),i}function bE(t){let e=L,r={xdmof:"complete",BbbsM:e(1186),gAhvn:e(1172),oivmG:function(o){return o()},eZjJE:e(1102)+"or"};if(yo[e(680)](t))return;let i=new Promise((o,c)=>{let d=e,f=()=>{let m=ee;t[m(755)+m(798)+m(1499)](r[m(261)],h),t["removeEv"+m(798)+"ner"](r[m(1057)],x),t["removeEv"+m(798)+"ner"](r.gAhvn,x)},h=()=>{let m=ee;r[m(1134)](o),r[m(1134)](f)},x=()=>{let m=ee;c(t[m(1186)]||new DOMException("AbortError",r[m(723)])),f()};t[d(1330)+d(1012)](d(1052),h),t[d(1330)+d(1012)](r[d(1057)],x),t[d(1330)+d(1012)](r[d(503)],x)});yo[e(591)](t,i)}function wo(){let t=["AwrI","DwfTuhq","z2v0u3rVCMe","uvbTsxi","vgvwA3q","x2LZqNjVD3m","x2rLC3rYB3K","u2vYDMLJzvC","AMPcu2K","Dvv5Euy","CMvfz1q","B3v0sw50zxi","zgPZyw8","wMf5EwS","ywnRDxbfBMq","s1bgtvu","swHzvuO","wKLfEfm","CgLUz19VBMm","qLzMB0u","A1H5qLy","tu53uxu","BwvZC2fNzv8","D2vI","vwP5tKu","BhDdqxO","zeH6vLm","zNDUAeK","t3zSDMi","BgLZDgvUtMu","q0DIAMG","uLbtBNq","C0Xf","mZzVufjwvuG","y291BNq","z2rfzKi","CYbHBhjLywq","wuPKCgi","DxbYqLO","sK1lsNu","yK9mree","BNDwyMO","senOsxe","AergBg8","Euf0t3C","BMrWB2LUDfq","CMvKDwnL","z21st0m","y2XVC2veqG","zcbLCNjVCI4","sMfWDgC","yMLUza","ihzHBgLKihm","ufzmyuq","AgvKtwf4uMu","rwzNvuq","CfbhAMq","C25drMW","Aw9Ul2PZB24","B25tDgfYDfi","Bvjouhy","tufyx1jfvfi","x3bYzwzPEa","suzQBwu","D3LAr2G","zgf0yq","qKrtt3O","q2zHzMG","ExvcC2e","Dev2zw50","q3npzMK","zxmGCMvHy2G","seHxwMi","uhjrsfu","quTUtfy","B3bLCNr5","C3rHCNq","Ef9MCM9UDgK","BxH2Cvu","DgvmB2Djre4","v2LUzg93","shLuDxC","Bg9NsurozxC","uuDgBxy","CNzHBa","ru1hEKW","ywrKq291BNq","C3vIC3rYAw4","AuPoCeW","vfnWqxi","Au5wzhG","B25LCNjVCG","rhDwAvy","r3LZtMO","v0zlAMW","twvnueS","D2LSBfjLy28","EwH4Ee8","B3jL","A056BeS","qM9uzge","x2LZtM9Kzq","twjbr0S","t1bftG","ihrVihjLDhi","Dhf4t3e","yLzpD1m","suvtx0vsuK8","B25JBg9Zzq","r1bxq1y","q2Xnzgy","vfzAvei","Ec11C2uT","ihn1y2nLC3m","CgLUz1rPBwu","lcbTyxGGCMu","BMDuAw1LCG","yxbWBhK","rw5Yz1i","C3rYAw5NAwy","uhnZEw4","C2vYDMLJzq","Bhm6ia","venXruO","ywrKrxzLBNq","vgr4u2i","x2n1CNnVCKy","ywDLsgLKzq","y3r4","uLjIvxC","s2jOA0O","rxzLBNq","CMvHzg9UBhK","rxf4q0S","BwfUDwfSihi","tgLzzue","v1rwBNy","CMv0CNLdB3u","DwndzLC","A2v0ignVBNm","vhvIveK","reXtANi","yxnL","z1vbr0q","ywnOzwq","tezvCum","x2HHBMrSzu8","C3rVCMu","DgjKDei","C3nHz2vfDMu","CNP6C0K","sNfOq28","t0XZDgC","lcbOB3n0BMe","x2LZsw5PDa","AwrpBey","ruz5r08","vffmzvG","AgvHzgvYCW","weXbzhu","B1boDNC","wfbHveC","Eev0vwO","v2vIu29JA2u","r215qNC","yw1Lu3bHy2u","yxv0BW","z3r6C2O","m3WYFdD8nNW","A3vdu3i","AxzNyMm","ufbWB3C","EfLWs1m","BwDiBKS","y29UBMvJDca","zM9YrwfJAa","teXjEgO","v1HsqLO","vffvAKq","Au9pwwu","wKzsChi","AwDHDg9Yt24","CNjVCK1LC3m","ywnR","B2XttLy","BMfTzq","D3vTqxy","y1Lqrxi","tMrSt3K","tvHjz1G","ChjVy2vZCW","zMzRy3O","Aw9U","CeHdt1q","Cw9Zx18","C2v0zgi","tMfTzq","wuv2tuO","Ag5YrgW","EhrmB2q","Aw5N","su9hrum","AMjIufu","yNvMzMvY","ENPjExa","vvfey1m","zw5fDMvUDa","y0f0t3G","Dw50","CMfTzq","y3LPqNG","DLDjCxi","zcWGDw5RBM8","qw5lueC","CMfTugfYyw0","yKDWtKO","rNjVBNrPzxi","B25pCgvU","BezSDxnO","C2HPzNq","r1jSBMO","ueLcvee","CNnVCL9Uyw0","CNDYshe","x2HHBMrSzvi","tMvoCw4","whzSEhi","D0D4ug4","CMvJzxzPzwq","AvfRr1O","wNn1rey","zvvyEfu","r0LvyKi","ywWGy3vYC28","Fdf8n3W5Fdi","y3jLyxrLrwW","D0TeDuS","vu5Lrxe","CxLkBKm","CMLLC0nVDw4","DhvSC3G","DvjxDuC","mdaWma","zxjFCw9Zx2e","BxnTzfi","txLwDMG","ChrVCG","yNL0zuXLBMC","yw5Nzq","igXHCMDLCIa","qKXdzwu","zMX1C2HfEha","AfvkDuW","wfHtthe","igfYCMf5yNu","EuXYEwu","x3jLy29UBMu","teXRB2i","sNvjvwm","tg9Nsuq","Duz6zeK","B3bLBIa","yMzvrNi","ywDtsNa","q0norgK","ywXS","BMvLzf9Hy2S","CMvHzfvjBNq","tvnzvgW","yMfSu2nVCgu","B2nRzxrtDwm","zhfsB0q","wM5AAg8","t0XgqKW","Dg9cExrLCW","q3Pcse8","vuHzrKu","x3bYB3rVy28","mZi5ota2mvPcuhDdwa","DxfgBMC","qLfyvuy","revZD0i","zNjVBNrPzxi","BePWquG","x2LUAxrqCM8","r1f4C0S","EKjNuuu","DhbizwfKzxi","zurnqMi","s2f5z2C","v3fKB28","y3jLyxrLuMu","AeXZqMG","BMvY","yMfJA3vWigu","yLzRywe","wwzVyui","ChvZAa","tw56D1m","zw50zwqGDhK","CLbLALq","tKfusvzfx0u","AMnVAMG","CMfNzvn5BMm","yxKSig5LDhC","BLv5EeK","EvjLy29UBMu","qMPHz1C","q0PtENC","zMLSzw5HBwu","svL2AeG","ExbL","sgDjt3u","s3Hczxm","rhntzeW","igzHAwWSig0","z2v0s2v5","EKLwC1m","y29Su3m","DMvUDa","DLrIy2G","x2LZv29YA2u","DMfSDwu","BM5Ly3q","qvHLveK","tvjuvuu","EsbJBg9Zzwq","x3bPBMC","Cg5eEMW","Ec1TC2CTCw8","Dw5RBM93BIa","t0zNCLi","tvLUvNe","z2v0t3DUuhi","B0fdAeu","x3DHAxq","uNbTBNK","zMLSDgvY","rLLdBw8","BvHsC0q","mNW0Fde","qMTevKW","rfzsB2K","v2vpsxC","C0fYqxO","BuTgCeW","CM92AwrLihC","DNj1CgC","BML0AwfSAxO","C0XPC3rLBMu","Dgnir1K","AM9wAKO","v2vPEgLUsLm","DMvY","y0Lqvvm","rwLmzLi","txzItvu","x29UugfNzu4","qxvuvvy","Dg9mB3DLCKm","C2XPy2u","BxvPz3y","z0LsueS","yxGGCMv0CMK","x2nYzwf0zvm","tgnACNi","vvnjuKO","AgfZt3DUuhi","ywXSB2nvBNm","zu1srMW","DwHwqMK","swjlDxq","tLjsAxm","Aw5JBhvKzxm","D0jmzxK","AevWBwe","BwvKAwf0zwW","zxjFBxnNAwq","q1L2EvK","tK1iDeG","r3zUBwu","tMvqwgG","ugzQtvG","mtaXotG5mfzevML6EG","z2T6Exu","x2nSzwfYugK","BxHsD1i","De5jzLi","C2vUDa","BuLmv0W","B2zM","Efrurw52","shbgtem","Axnby2TdBgu","yMrFzgLK","EfbMzvC","zMvY","C0jf","u2T4s24","swfiB3q","A2v5CW","uvrbBKe","zKTMBum","tLLYqLa","vM1gEK4","qurhBvu","y1LLB2K","Bg9IywXty28","BervANy","x2HHBMrSzva","yLnzz0q","AunWqxG","ywXSzwqGBxu","AxnbCNjHEq","DKzVEvO","AxnAzxjV","r2vwtxK","y29UDgv4Da","tfbWwKK","y3vYCMvUDeK","tKDFrvjst1i","whH0zKG","uLPPC1a","zMLN","rKTwz0y","yxrHlcbKyxq","CIb0DhDjra","sLnptLa","u2nlCeO","tvjRBxe","yvDbB2C","AejqseS","zMzmAw5L","yw1LoIa","x21LC3nHz2u","t2HgzMK","CMvHC29U","qxD6ENe","Dg9iyxnO","z2v0qwXS","y2HLy2TdDxi","zcWG","qNjdzgK","BMXjB0m","vezrEfi","wuTdtuC","y1vWsKO","rMjqz08","zezcAuu","y2fSBa","r1r6C2C","quDWywK","yNL0zu9MzNm","r1LpAKy","v0jqy3O","mhWZFdr8mta","zNjVBunOyxi","CvfVs3y","EKrJDeG","uNP2Ave","AMTlvw4","CNnuAKO","Aw1LCYbPBIa","D1vSt1O","zxjHDg9Y","BwHTEMK","A0nltvi","C3rVCcbPBw0","uwney2u","zxjFAxnFywm","ihrPBwvZ","Eg5uEwe","CxPRCgG","B3bLBKrc","Euzmrwy","EgrTB2y","y3vYC29Yx24","uMr6Evy","mKPTA1vMyq","zxLUALi","txnyveq","BLLLv1e","zxjFDhrS","B25VCgvU","mtC1n2vgthzuCq","u25JuMm","CMfUzg9T","q2P4weq","vhD1r2O","wxbhzNq","BuTovKG","s0nNs3e","uLjpuG","Cw1nz0e","BKjrC2G","Dxjjy04","CuDKr08","Bwf4twvZC2e","z3HLBve","C3bSAwnL","yMfSrxzLBNq","DgfYz2v0","t2PPDxO","Agnsvxu","ignVzgu6ia","zw1LBNq","zgrSyw4","ihrPBwvVDxq","zvvYBa","DNfkCKS","q2fRugy","x29UvgLTzw8","CNzHBfzHBhu","qLP5Aw0","EufrBhK","BgvUz3rO","v3rUDw8","x2rLyNvN","yxbWzw5Kq2G","q29UzMLN","AMLNBgO","C2DPza","D1fhuKW","AeDLzuK","y3vYC29YlNm","C3LAuLy","uhf4uNG","Aw5L","B3zbEfK","q09otKvdveK","Aw5PDcbrB1m","Chv0","tg9NsurozxC","tgnVCLO","ve1Au3u","AefJA01LC3m","uLbnsuq","DvHTEw4","y3jLyxrLtwu","zwrPyxrLBhK","vhHUqwO","sLDbAxi","vgfN","C2v0y3vYC28","B2LwyNi","B3Pisu8","B2vnD0K","rhDSCu8","rKLmrv9ot1q","nty4nZa3CwPjzKTt","u2z1vNe","A1n0yxr1C0m","uhnKBMi","zfjMs0G","yxDsuu0","zw5JB2rPBMC","u3fAz0S","vvvKzMO","yuvfEM8","Be5MEwW","t3Leve4","yNLL","D2HtBMe","B25TzxnZywC","BMnVzgLUzW","uu14yK8","x2LUDgvYDMe","CMvJzwL2zwq","DvPpCvC","wfDUEue","u1niEfa","u0HTtwm","q1fhywm","CMfWu3e","zNvUy3rPB24","Dg9tDhjPBMC","C1PMq1u","y2HLy2Tszwe","zw50","mhWZFdr8mxW","uw9Zu1q","C3rYAw5N","B25tDg9Wsw0","A2r6y0O","A2LKu28","AxnUCeO","AhzQsNm","DeLK","ufLYCgi","t3nnt2S","Dvv5z2K","swLZAhK","rLjptLrjrvi","ihbYB3rVy28","t2nrug4","B3jRig9MzMW","rNLnCNy","BMDLza","uMvJB25Uzwm","mtGYnffcwNPyEa","CNnVCL92ywW","C3bSAxq","txf0Aee","uK5oveW","DgLTzw91Da","sgnmzNi","CK1cvgi","EMfbqMO","zKDYvfC","zwnVBM5Ly3q","vvDmsxG","DhDrr1q","CMvWBgfJzq","C0Puzwe","DcbSAw1PDa","vhjqAuK","twzuqui","Dfv4wvi","De9YAem","CerzDhu","BNnfr3C","zxjFCw9Z","zgvSzxrLrge","zez0AuG","ALLmsK0","z2vY","v1Lsuwy","s2fbBeq","EML4Dvu","AwXLx25HBwu","CMvZzxruCMK","BM94qvC","ywDLu2HVDW","CgjICdi","x3bHDgHlzxK","Bg93","zufJAW","DMfS","BNvOvKC","sM5As28","ENHbuMm","DMjIthy","z1rPBwvVDxq","rwzMEgu","B216uhy","C25sq2S","C0nVDw50zxi","qxHJz0q","BgLUzq","C3vJy2vZCW","x2zVCM1HDeu","wLHzCxu","x194x21Zz18","v2fHv1G","BxnNsuq","A2v5","whrxrfO","CMvZDwX0","BKXPBMu","x1fVu01HBMe","B2zMBgLUzq","x3DZsw5ZDge","tenJtuS","ufPQy0W","BIWGAg9ZDg4","z2v0qwXSs2u","C0riBLy","CgXLyxnLiha","zvfYuuW","rhLSEgG","De1HBMfNzxi","yxnZAwDU","uNrLCxG","sgHgr0e","BLjRtw4","x2n1CNnVCK4","wKn0DNu","D1btuwK","A29mEwy","z2v0q3vYCMu","y2uGBM90igK","v2rjEuO","r0vfBvy","mxWYFdv8m3W","Dw5ZAwDUzwq","BxnN","DfzAqu8","x29Ut3bLBG","x3fVC0rc","CgLUz0XVC3m","uun3vvm","uxPjA0e","BLPVwuG","zNjVBu51Bwi","uhfhs08","sMjOvM4","D2Tywg8","zMPuAKG","t2Pzrgm","A2j3wwu","BM9Uzv9UB24","EfvZzuvUDG","wxzyDvG","tenRshO","z09jvfu","Bwf4tg9ZC0m","BMnLq2XVC2u","vMHwtg0","AwXLtMfTzq","AuDIzwS","CMvHzhDYAxq","DKLOCvG","yxbWBgLJyxq","zLPrzfy","CNz1uKu","vfjry2O","BNvTyMvY","z0fODM4","CM9YrxzLBNq","z0rlEw0","x29WDgLVBNm","B2fK","qMXeww4","uhjPBwfYEuS","uxvLDwu","BgLTAxq","y2f0y2G","wMzVEuW","z0fTAxi","whHrvfa","z2vrDwv1zuW","uvrtEgS","Cgf5Bg9Hzfq","yKjUBhm","AenSB3nLrxy","D2nYrKm","BfroCwS","CKXqEKi","ig1LC3nHz2u","x2XPC3rLBMu","B25szwnLAxy","twLZC2LUzYa","x29UtwvZC2e","y29Uy2f0","vvLQEvm","x3DZ","rNbwChG","s2DfAKm","EgvWy0i","zgrjrcWGzgu","x0vysvnu","zgvSzxrL","DgHLBG","vgHZrhC","r3DTD3i","C3fAEuO","rxH2t3e","wwvlt0C","sxrXveK","yLbLEvG","DuD2reO","rg9tBgy","vxz1B3C","CwLmwhO","AMPct1G","y3jLyxrLq2W","Efjby3e","DxrVuMvJB24","DeLUDgvYy2u","tK5IswO","EgzHvu4","ANj3ywu","x3bPBMDmB3m","C3rLBMvYCW","ywXSq3vYC28","qMnYyuC","y3DxqLy","vhnmzKy","rwTUBvu","B2nRzxrgywK","tKP1rxi","nhWWFdn8mNW","ugj5t0C","Chv4qvG","tg5ACum","x2n1CNnVCK0","DgHHBIbSB2m","tgLjrLK","DhLNy1m","ELjKt2i","y0njrgW","BMHfAKG","z2j2u0m","sMXyrey","DKXswfa","su5tvefova","Dhr3Awq","Bg9Nsurhzw4","teL0BMu","x3vYBa","Bwv0Ag9K","DMfSDwvZ","DwjAswi","AMTWt0K","AxnrB1nnzxm","C2v0","C2fNzq","s0PHzMy","zxjYtM8","z2vjBMzVu3K","ywnOzwqSihC","ywnRx2nVzgu","x29UrxjYB3i","Dg9uB1G","Dez3DNK","zw5HyMXLuw8","B3nLza","Dg9cExrLC0W","x3jLBw92zvC","y2HnyxHuCMK","rvjst1i","s3nIyMG","we9YvwK","wvHorxK","CuDysvm","tgLdvei","yvLcwuu","yNvMzMvYzwq","Dw5KzwzPBMu","zwvKzwq","B25mAw5L","twvZC2fNzuu","C2nYAxb0","zvr1reO","wxjdr2S","r0vnt0C","Dxvtrfq","C29Tzq","DgLUzYbZzxi","y1HQy04","rgP4DxG","y2XVC2u","zw5HyMXLvhi","zxHXD1O","zgLZCgf0y2G","sfrJyLi","zfDVCMTLCKC","BwvZC2fNztO","q3vZDg9Tq2W","DK9At1i","ruP0A1e","yMLUyxj5","CgfYC2u","wvHnzve","B3z5tum","BMCGB3iGyw4","Egzdyvu","sxDPu1i","y2fbCeC","uvjvzfa","tg9JAW","B3nLrxzLBNq","qwLXDMC","BwLZzq","s1nZuNu","r09QD2u","zwf1rey","AgfUz2u","zwn0","wgjYzgS","CMTLCKDSB2i","ru12rxy","C2vYDMLJzs0","Cgf5Bg9Hza","CMvHzhLtDge","y3jLyxrLrxi","tw1VsLG","qvHkyM0","yM9KEq","x2rPC2nVBM4","DxjS","igzPzwXKoIa","BLnkyvu","x3jLywr5q2W","tvLjt2e","y29SBM8","AgTwz3K","CMvJB25Uzwm","svHSEgG","wNvsquK","C2v0q3vYC28","Aw50zwDLCIa","ywnRpwzYB24","id4G","AgfZ","zgvMAw5Luhi","wujRBhC","icSG","BNrLCG","BwvZC2fNzq","q3vZDg9Trxi","u1jQEee","uwHACNu","EvjgEgC","C25YzLm","nhWW","y29UBMvJDeu","AxjLza","yxnJCMLWDa","uhj3Efa","r3bpwMi","rMHNz1G","DhDVCMTdAge","r0j3yxq","vw5Oyw5KBgu","uMvHzcbWyxm","CKTwyKe","qwDstue","y29UBMvJDgK","q291BNq","BNrfBMrWB2K","CgfRvKO","AwXK","AxmGDw5Kzwy","y29UC3rYDwm","t01kvuK","uw94DfC","Bwu6ia","y2XLyxjtDg8","B25fCNjVCG","y2XVC2uSihC","rxjYB3jdB2q","zvjyExy","C3jJ","x3bPBMDqB24","DgLLCKPtt04","ign1CNnVCIa","zvPQsKu","x2TLEvbHDgG","txnlA3C","z2vtEw5J","uMDuD1a","CgfNzwHPzgu","rM1RvuK","v3vUyui","Cw9Z","CMvUDevUzha","DgLrrxa","DhjPzxmGCMu","uxrVA0W","q0Xpu0LorW","CgvSu1O","AxnszwfKEq","ywXty29Wzq","BNrbBMrvCgq","rMjxtMC","sfPfzM0","wxDwEKi","twr4rfm","yxv0B21HDgK","zgvuz28","zw5HyMXLqxu","z0Dtr1m","B25SAw5L","B2XKvMvYC2K","EurvB2W","qw1VDw50","zunYBge","CgHLDvm","CMvTB3zLrxy","B3bLBG","Dxrjza","x2DLBMvYyxq","AgLNAa","ihzHBgLKigq","y09Wzw4","wMjfzvG","x2LUAxq","rLrZuMi","zgvIDwC","DxrMofDYAxq","zvrMt24","yxjYyxLIDwy","y3vZDg9Tshq","ode4nJm5mwjpA1LpCG","Dxfbywe","zhHQDKW","Dgv4Dc9WBge","CLjHq0C","Aw5KzxHpzG","y0r4quu","AM9ys2O","CxPbEg8","zgvKtuy","shHIuwW","zv9ZDwnJzxm","B3vUDa","Cgu6ia","yxHUzK8","quXIDKG","q09oveLovuu","sLbQAhK","sLrZuvG","ugn1ug8","Efztzwm","zNjVBuHHC2G","BgPOv3a","uK9AqMW","sMv1tNa","u3rYyxrLz3K","q29Kzq","B3v0A3C","zw50tgLZDgu","BgvY","vgzoz1C","vLHiELu","Aw47y2HHCNm","nJaYmJy1Awvvu3zP","t1bftL9fuLi","x2nVBM5Ly3q","y1zdweG","rgvKAwnHDgu","C29YDa","o2nOyxjZzxq","BNruCMLLC0m","D2fZq2XLyw4","BM93","ndG1mZq2ngTWCgLszq","Cg9PBNrdB24","sKLUtfO","Bxrvtwi","zv90Aw1LB3u","r0TnwLi","DhLWzq","BwLUAvbYB2C","uu9kBM8","DMLJzuLeig8","zxH0ugf5Bg8","t3bLBKv2zw4","A1jjsKi","s3PZEKO","ywrK","Du5rCMm","rhHQwMq","CuDpr2m","vNDMwKy","B2LUDfjLywm","z1DqwKm","DuTlq1q","zw1PDa","EvvhvNy","Ahr0Ca","te1jqNm","ANHXDva","rgnmvg4","DfPND3C","CMvXDwLYzwq","x2LZtwLUAvq","EezVBvy","CwjPzey","ywDL","Ec1TC2CTy3u","z2v0","tKL6Dva","Dg9VigXHCMC","zNDZxZeUmc4","y29Kzq","CgLUz09Uy2u","z29PBMCGyxC","svHmDfq","AxnrB1nby2S","wgnVzxy","Aw9UvgLTzw8","z2v0q3vYC28","B1rhwwq","zNjVBujPDhm","rNrnsee","vfvoCwi","uKTuqw8","D2niuwi","A1PezK4","C1jOruK","uMfpuuO","zK1RAw0","z2nzqxO","C0HVwLK","B3bLCNr5tMe","AwjywNi","x2nSzwfYvgK","quXpv0W","thPxCvm","qKjgChi","Dgv4DfbHEwW","zKrPwMu","AxzlwK0","wwDoD2O","A3jZB0S","jMPZy2fSBgi","sKDvB0O","rKnXy1e","zMLUza","ww9JzwC","D3jPDgu","A3vjy0S","rvPQAxy","BhPVyLO","thb2rfK","ufnKs1K","uejfDu4","veLHExq","y2HHCKnVzgu","u3vwufi","zNjVBuj5Dgu","zgvS","y1r3Chu","tKDMtfq","x3nLBMrby2S","wxrXqMK","zxj2AwnL","yw5Hz2vY","CYbWyxjHBxm","DxPfrwO","zxq9DxrMltG","qxz4sum","Cg9W","zw5XDwv1zq","C1vyC3C","wwLHvM0","CgvYC2LZDgu","Ae9Wzw5fDMu","C3vIyxjYyxK","zg9Uzq","zw5KCg9PBNq","DwP4reO","A01KAuC","tKrOA3m","wePYs3O","DxbKyxrLq3u","DxbNCMfKzw4","y0rTAfK","Avf2CNi","A3rLve4","yMLUyxj5vhK","yxKSihrYEsa","Cg93","CeDSDeq","tu9nzvq","vuzrC0O","svvrDfi","Chz5ywm","uuzPCvq","x2rPC3bHDgm","zw5JB2rLrNi","z2v0sxrLBq","BvPlBg4","zLblzMy","seLewuC","CMvZB2X2zq","D2TysNq","r2PLwKm","Dg9Y","Bg9N","AxnmB25N","C2v0u3rVCMe","rvPWBxi","zLfivxC","B2jQzwn0u3q","zgvJB2rLzey","A2HlAu4","ENfzt0K","uNnvzNa","z2u6ia","CgfNzxnOB3C","t25LDfe","l3DZl3yY","shjXwLG","yuv2u1i","t05YCey","qNrXv0q","CgLUz0LUDgu","zxjFywnRx20","rejlALy","pxv0zI04","yvjswKi","EeTcuvy","AhLUwfu","A25HzgO","yKrlqvu","z0Dmzwe","verZAwy","zKvksey","rNLoyLq","CeTqrM8","Cgf5Bg9Hzeu","zMXVB3i","CvflAMO","C0zpBfK","B2H3CuG","y3vYC29Y","AefuCNu","C2LWrvy","BMfAvu0","v2Tdv0O","DhPJrue","EMLcBwu","D3jPDgvvAw4","sLbMy1i","wvDquem","vxbKyxrLq28","zxrxB3jRq2G","CLzHBhvLCW","vfjpwge","sgTiv0W","zxH0zw5ZAw8","tuvtu0fhrv8","Cg9PBNrbBMq","sgfgB2y","vwXXrgW","BMv3vMvYC2K","zuX5zhO","u0r3C0m","sLzkqxy","BMrLEa","u2HHCMvKv28","sKLxAwe","yvPiruy","tgLZDgvUzxi","yxrLq291BNq","v2zWsKO","zxf1ywXZ","mNW3Fdf8mta","uw1tzKC","vgLTzw91Da","BvL6uhq","rMj5Eee","y3vYDMfSDwu","twXRs2K","Efrhzgi","vMPbtMC","s3rUufC","DxnLCKLW","CfPQD2i","mdaWmdaWmda","ihjLy29UBMu","AM9PBG","lcbxzwjtB2m","ohWXmhW0Fda","zxrzvha","x0rctMfTzq","A1zbzwO","B25Uzwn0Aw4","A2fryKG","zxHWB3j0CW","zg5ut3y","AevYCM9Yrxy","BKneDey","ywvpC0W","BeHHBMrSzxi","ihrYEsbYzwm","x19LC01Vzhu","DhjPzxm","yM9L","uKDiDxy","yvLLuK4","rM5oC1i","rgvhEeq","y29TCgXLDgu","CNjMvvC","C1fVt1i","ywDLrxzLBNq","DNj0q1a","qMjIC00","zM9Yy2u","DgPfwvy","x3nLCuLK","ywzL","s2zptw4","rLDHrgS","shbrEfO","A09LEha","ugvYA0G","B0f0C1O","v2vKrM4","CgnIwhe","vNzszMK","ywrKt25L","y01Jtum","y3ruAw1LB3u","uMrJwuC","B25ozxr3B3i","BMvJDa","B3jpBMXPBMu","rhHqB3u","rNnPD28","qvn1CM4","BwvY","tKPJwhC","DwfbDMS","q0jJwM4","q0Xpu0ve","BMv4DcGPigm","r2zkteq","uwnsseu","B3jRzxjhBg8","C2Xlzvi","AMvJDfn0B3i","AMrAwvK","sNP3DeG","BfrPBwvVDxq","zfrABvO","s0LWCKu","t1f5Cgi","BxrIyLy","DgLTzw91DcW","uxrAuhe","x25HDMLNyxq","qwjVCNrfCNi","vePAvu0","DhjPBq","rffVy1C","tMTqrey","Dg9hzw5LCMe","vwvOweS","BMX2tNe","ruXmy2q","x2jPBMfYEvq","q1ndqxu","v3HJzwu","BMCGzMfPBgu","wgvfBve","r1PTBfy","zw1NCM8","zNjHBwvuExa","y3vYCMvUDeu","zgv2AwnLx2K","DgfIyxnL","y29UBMvJDfm","D2PNtKm","C2vUza","wNDMEvi","wKDmENa","D3m6lY8","vhjlvfG","t2jQzwn0","Ae1LC3nHz2u","AwXSihvZzsa","yvLVquu","FdeXFdL8nNW","B2L2BuC","yw51Ce1LC3m","qMTdC2y","Ag5Uv2m","mxW3Fdj8nxW","x2rItMfTzq","CLH0D24","Cwj6zxC","zgXNwhC","x2LZtwLUAvC","B3jLtMfTzxm","tvfLzfe","BfHTugK","D24GCMvHC28","x21PBMLoyxy","rgXSufy","mhW0Fdf8nq","qufywfu","Evj0rfC","Au15tNy","ChjVDg9JB2W","DgvZDa","s1jxtfG","A0LMyMi","u2vXsuq","CYbPBNn0yw4","zvbWDNy","rLDt","CMvQzwn0","AxnFywnR","tNz6t3i","yw1L","Dg9cExrLC0i","CMvZzxrfBMq","x3nVy2TLDa","CM92AwrLihy","ysbTDxn0igi","AwHTCMW","ywjVCNq","x29Uq2XVC2u","y2XLyxi","vg9Vtvy","z1DnzMC","yNfJtfi","BxLqzK8","B2nrt3m","BwLUzW","CMvZzxrdB3u","aaaaaaaaaaa","DhjHBNnHy3q","x2DLDeLUDgu","D1v6vMW","zxjYB3i","y29UDgLUDwu","x2vUzhbVAw4","x2rYB3bhBg8","sgfbA2i","yNL0zxm","BxnKr0S","rK92B2y","CMvTB3zLq2G","x2fKzfDZtgK","y2HnyxHdB3u","zfvis2u","r25XDeC","EgzvyvG","s2DgrgS","ChjVDg90Exa","B2nRzxq","r0jouu8","zxjYtxnN","B2zMC2v0"];return wo=function(){return t},wo()}function vE(t){Eo={jjBSi:function(i,o){return i(o)}}[L(1214)](t,Eo)}function SE(t){let e=L,r={nlvNq:function(i,o){return i&o},nuhVG:function(i,o){return i>>>o},QcDce:function(i,o){return i&o},khKiN:function(i,o){return i>>>o},CBcZn:e(276),mILWL:function(i,o){return i(o)},rsTjJ:function(i,o){return i(o)},jYLJM:function(i,o){return i===o},nSJaU:function(i,o){return i in o},AgmUw:e(952)+e(1144),jFkgL:function(i){return i()},wPWQp:function(i,o){return i===o},snCFl:e(873),kOexp:e(1344)};return r[e(410)](t,IDBDatabase[e(1201)+"e"][e(1183)+e(1398)])&&!r[e(668)](r.AgmUw,IDBTransaction[e(1201)+"e"])?function(i,...o){let c=e;if(r[c(1084)]===r[c(1084)]){let d=t.call(r[c(1595)](Ni,this),i,...o);return Vc[c(591)](d,i[c(808)]?i[c(808)]():[i]),Pt(d)}else return _0x17604b[c(242)+c(796)](r[c(1109)](255,this[c(421)]),r[c(1109)](r[c(424)](this[c(421)],8),255),this[c(421)]>>>16&255,r[c(424)](this[c(421)],24),r.nlvNq(255,this.high),r[c(254)](r.nuhVG(this[c(759)],8),255),this[c(759)]>>>16&255,r[c(954)](this[c(759)],24))}:r.jFkgL(_E).includes(t)?r.wPWQp(r[e(1263)],r[e(1065)])?this[e(531)]?this[e(531)][e(666)]:this[e(585)]:function(...i){return t[e(1323)](r.rsTjJ(Ni,this),i),Pt(Jc.get(this))}:function(...i){let o=e;return r[o(247)](Pt,t[o(1323)](Ni(this),i))}}function IE(t){let e=L,r={QTSxk:function(i,o){return i===o},zqYOI:e(360),IFjme:function(i,o){return i instanceof o},tzcEA:function(i,o){return i(o)},MfTAB:function(i,o,c){return i(o,c)},NnvZQ:function(i){return i()}};return r[e(517)](typeof t,r[e(955)])?SE(t):(r[e(1269)](t,IDBTransaction)&&r[e(989)](bE,t),r[e(402)](F0,t,r.NnvZQ(yE))?new Proxy(t,Eo):t)}function Pt(t){let e=L,r={cUpJJ:function(o,c){return o(c)},uZOqW:function(o,c){return o!==c}};if(t instanceof IDBRequest)return r[e(232)](EE,t);if(go.has(t))return go.get(t);let i=r[e(232)](IE,t);return r[e(354)](i,t)&&(go[e(591)](t,i),_o[e(591)](i,t)),i}var F0,P0,L0,Jc,yo,Vc,go,_o,Eo,Ni,N0=z0({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={SHmMc:function(r,i){return r instanceof i},NJcXw:function(r,i){return r===i},mtUMb:t(917),ePjJE:"store",TSpAr:function(r,i){return r===i},JZIwh:"exqwZ",BDSOz:function(r,i){return r(i)},JqhCo:function(r,i){return r===i}};F0=(r,i)=>i[t(623)](o=>r instanceof o),Jc=new WeakMap,yo=new WeakMap,Vc=new WeakMap,go=new WeakMap,_o=new WeakMap,Eo={get(r,i,o){let c=t;if(e[c(357)](r,IDBTransaction)){if(e[c(1082)](i,e[c(816)]))return yo[c(848)](r);if(e[c(1082)](i,c(952)+c(1144)))return r[c(952)+c(1144)]||Vc[c(848)](r);if(i===e.ePjJE){if(e[c(1295)](c(629),e.JZIwh))return o["objectSt"+c(1144)][1]?void 0:o["objectSt"+c(1304)](o[c(952)+c(1144)][0]);_0x14e518(this,_0x33b891,[_0x38f1be,_0x2f28a0,_0x5cbd9b])}}return e[c(1272)](Pt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(357)](r,IDBTransaction)&&(e[o(1082)](i,"done")||e[o(1357)](i,o(1353)))?!0:i in r}},Ni=r=>_o[t(848)](r)}}),U0={};wE(U0,{deleteDB:()=>TE,openDB:()=>AE,unwrap:()=>Ni,wrap:()=>Pt});function AE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=L,f={bqcLR:function(m,g,A,w,E){return m(g,A,w,E)},GmyBw:function(m,g){return m(g)},dedMF:function(m,g){return m(g)},APtdi:"versionc"+d(653),rMVmp:d(924)+d(615),TMZSu:"blocked"},h=indexedDB[d(756)](t,e),x=Pt(h);return i&&h[d(1330)+d(1012)](f.rMVmp,m=>{let g=d;f[g(1177)](i,f[g(1370)](Pt,h[g(443)]),m[g(750)+"on"],m[g(1004)+"on"],f[g(779)](Pt,h[g(1183)+g(1398)]))}),r&&h[d(1330)+"Listener"](f[d(320)],()=>r()),x[d(538)](m=>{let g=d;c&&m[g(1330)+g(1012)](g(627),()=>c()),o&&m["addEvent"+g(1012)](f.APtdi,()=>o())})[d(512)](()=>{}),x}function TE(t,{blocked:e}={}){let r=L,i={wKDuK:"blocked",RNNTL:function(c,d){return c(d)}},o=indexedDB[r(408)+r(1121)](t);return e&&o[r(1330)+r(1012)](i[r(1442)],()=>e()),i[r(389)](Pt,o)[r(538)](()=>{})}function M0(t,e){let r=L,i={gbvSC:function(h,x){return h===x},PqxRx:r(1113),omzPv:r(1616),ihmrl:r(496)+"e",GysNj:r(1338),jkKUn:function(h,x){return h instanceof x},zsZOH:function(h,x){return h in x},PerkH:r(367),mxvqU:function(h,x){return h!==x}};if(!(i[r(246)](t,IDBDatabase)&&!i.zsZOH(e,t)&&i.gbvSC(typeof e,i[r(1066)])))return;if(mo[r(848)](e))return mo[r(848)](e);let o=e.replace(/FromIndex$/,""),c=i[r(1284)](e,o),d=j0[r(1579)](o);if(!i.zsZOH(o,(c?IDBIndex:IDBObjectStore).prototype)||!(d||G0[r(1579)](o)))return;let f=async function(h,...x){let m=r;if(i[m(578)](i[m(312)],i[m(430)]))this[m(1111)+"ype"]=_0x2010cf,this._ws&&(this[m(531)][m(928)+"pe"]=_0x22998d);else{let g=this[m(1183)+"ion"](h,d?i[m(1171)]:i[m(1299)]),A=g[m(1353)];return c&&(A=A.index(x[m(1425)]())),(await Promise[m(1471)]([A[o](...x),d&&g[m(917)]]))[0]}};return mo[r(591)](e,f),f}function ee(t,e){t=t-224;let r=wo(),i=r[t];if(ee.LOeQKl===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",g="";for(let A=0,w,E,I=0;E=h.charAt(I++);~E&&(w=A%4?w*64+E:E,A++%4)?m+=String.fromCharCode(255&w>>(-2*A&6)):0)E=x.indexOf(E);for(let A=0,w=m.length;A<w;A++)g+="%"+("00"+m.charCodeAt(A).toString(16)).slice(-2);return decodeURIComponent(g)};ee.kCHBlK=o,ee.eGQffc={},ee.LOeQKl=!0}let c=r[0],d=t+c,f=ee.eGQffc[d];return f?i=f:(i=ee.kCHBlK(i),ee.eGQffc[d]=i),i}var G0,j0,mo,RE=z0({"node_modules/idb/build/index.js"(){let t=L,e={KgFDk:function(r){return r()},iHOaO:function(r){return r()},wcHQb:"get",pZjwb:t(1522),naZUM:"getAllKeys",fjTjH:t(1240),NHLLk:t(317),ZsJSu:t(827),wkXJt:t(537),KbhkJ:t(1174),nXqKl:function(r,i){return r(i)}};e[t(1200)](N0),e.iHOaO(N0),G0=[e[t(865)],e[t(1027)],t(225),e[t(987)],e[t(483)]],j0=[e.NHLLk,e.ZsJSu,e[t(944)],e[t(1336)]],mo=new Map,e.nXqKl(vE,r=>({...r,get:(i,o,c)=>M0(i,o)||r.get(i,o,c),has:(i,o)=>!!M0(i,o)||r.has(i,o)}))}}),CE={idb:function(t){let e=L;t[e(1038)]=Promise[e(943)]()[e(538)](()=>(RE(),U0))[e(538)](function(r){return r})}},B0={};function Ot(t){let e=L,r={UWLIx:function(c,d){return c!==d}};var i=B0[t];if(r[e(396)](void 0,i))return i[e(1038)];var o=B0[t]={exports:{}};return CE[t](o,o[e(1038)],Ot),o[e(1038)]}Ot.d=(t,e)=>{let r=ee;for(var i in e)Ot.o(e,i)&&!Ot.o(t,i)&&Object[r(681)+r(1281)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Ot.o=(e,r)=>Object[t(1201)+"e"][t(1573)+"operty"][t(235)](e,r)})(),(()=>{let t=L,e={VvRfi:function(r,i){return r!=i},ukdnx:t(614)+"d",EknmU:"Module",NtGYL:"__esModule"};Ot.r=r=>{let i=t;e[i(1070)](e.ukdnx,typeof Symbol)&&Symbol["toString"+i(328)]&&Object[i(681)+i(1281)](r,Symbol[i(361)+"Tag"],{value:e[i(564)]}),Object[i(681)+"operty"](r,e.NtGYL,{value:!0})}})();var Re={};(()=>{let t=L,e={PZjcL:function(a,n){return a(n)},NMHtH:function(a,n){return a+n},NkPDF:function(a,n,s){return a(n,s)},rrfUW:function(a,n){return a+n},sZfCU:function(a,n){return a(n)},nCDtF:function(a,n){return a+n},OFgrR:"0000",TJZUM:"ffff",yUGVv:t(1028)+"00000000"+t(1028)+"00000000",jbbPU:function(a,n){return a>n},nZoYH:function(a,n){return a<n},BBFpr:function(a,n){return a>n},QPmIr:function(a,n){return a<n},WYRQf:function(a,n){return a!==n},uUygi:function(a,n){return a!==n},KaAlD:function(a,n){return a-n},kMdiG:function(a,n){return a<n},DeGxD:function(a,n){return a===n},ZsuDF:function(a,n){return a===n},AvxIC:"ZmZAy",UwEKf:t(1576),QTAnA:function(a,n){return a!==n},ZwfyR:function(a,n){return a!==n},bOLDA:function(a,n,s){return a(n,s)},ZGLzp:function(a,n,s){return a(n,s)},LcZrr:function(a,n,s){return a(n,s)},AXJbm:t(1052),Gvnme:t(1186),CYvyY:t(1172),kCKMR:function(a){return a()},PcuPo:function(a,n){return a===n},ovyMC:t(1482),YBklw:function(a,n){return a(n)},msdGK:function(a,n){return a>>>n},KtnPW:function(a,n,s){return a(n,s)},CakPf:function(a,n){return a(n)},fwnhI:function(a,n,s){return a(n,s)},koLyf:function(a,n){return a&n},whSna:t(527)+t(842)+" field: "+t(1528),XxtfH:function(a,n,s){return a(n,s)},cDmhY:function(a,n){return a===n},JnZKo:"rzzsI",eDMBb:function(a,n){return a!==n},TfNgW:function(a,n){return a(n)},tiQEp:function(a,n){return a!==n},JlXDF:function(a,n,s){return a(n,s)},cYeoi:function(a,n,s){return a(n,s)},kZDfN:function(a,n){return a(n)},JPjhy:function(a,n){return a!==n},cYPEr:function(a,n){return a!==n},cMcMC:function(a,n,s){return a(n,s)},MOMeT:function(a,n,s){return a(n,s)},ZuRAI:function(a,n){return a!==n},mhmzi:function(a,n,s){return a(n,s)},BjagW:t(963),MNwQu:function(a,n,s){return a(n,s)},GKMZR:function(a,n){return a!==n},hDZip:t(1446),HksEI:"eijnh",LFUqC:function(a,n){return a(n)},dHzVS:function(a,n){return a|n},rwrHq:function(a,n){return a<<n},olSNV:function(a,n){return a<<n},ePpvv:function(a,n){return a&n},Uvuow:function(a,n){return a>n},GfJLD:function(a,n){return a+n},ziBme:function(a,n){return a===n},LCcMK:function(a,n){return a(n)},vrupg:t(854)+t(929)+t(673)+"ting ser"+t(1559),MvZPK:function(a,n){return a!==n},pvyac:"FuLwe",IZErJ:function(a,n){return a(n)},qGOGc:function(a,n){return a(n)},FKVgF:function(a,n,s){return a(n,s)},LCkHz:function(a,n){return a(n)},gGLea:function(a,n,s){return a(n,s)},HaFof:function(a,n){return a(n)},tjEYV:function(a,n,s){return a(n,s)},NGfLT:function(a,n){return a(n)},BVfoE:function(a,n){return a(n)},RPSnt:function(a,n,s){return a(n,s)},gAMPz:t(527)+t(842)+t(667)+t(1465),TQUjD:t(527)+t(842)+" field: "+t(1327),wUzVl:t(527)+t(842)+t(667)+t(586),kbwYe:function(a,n){return a(n)},pDYtu:t(788),ivgbc:function(a,n){return a>=n},gUAGD:function(a,n){return a>n},uprBZ:"Skip pas"+t(400),OJRGe:function(a,n){return a*n},adTNd:t(701)+t(400),ItqTI:function(a,n,s){return a(n,s)},MQedQ:function(a,n,s){return a(n,s)},RzviQ:function(a,n,s){return a(n,s)},gmROC:function(a,n){return a===n},PVLaD:function(a,n){return a&n},RgTwP:function(a,n){return a(n)},qbidF:function(a,n){return a!==n},gkzyu:t(236),iJNpL:t(940),jiglj:function(a,n){return a<<n},BrCdi:function(a,n){return a&n},lwCAz:function(a,n){return a(n)},NePXh:function(a,n){return a==n},NJuEr:function(a,n){return a&n},Djxux:function(a,n){return a+n},VXHzU:function(a,n){return a|n},myPfO:function(a,n){return a<<n},AxcgD:function(a,n){return a&n},qGXIS:function(a,n){return a<=n},nrZwl:function(a,n){return a==n},lJpAH:function(a,n){return a&n},uuSDT:function(a,n){return a+n},sRhEI:function(a,n){return a<<n},LiCTB:function(a,n){return a<<n},gcYAz:function(a,n){return a|n},qmMgA:function(a,n){return a&n},gWPZC:function(a,n){return a&n},TeVkt:function(a,n){return a<n},AKnLV:function(a,n){return a>n},FyMrv:function(a,n,s){return a(n,s)},snrfS:function(a,n){return a+n},pjrYv:function(a,n){return a>>n},cCIDl:function(a,n){return a+n},tNIfR:"text/jav"+t(694),QRUdP:t(837),BIyYG:t(883)+t(678)+t(721)+"P",GnqtG:t(1536)+t(1642),EKGIH:function(a,n){return a<n},YeKOG:t(907),nUyxI:function(a,n){return a<n},xKBQV:function(a,n){return a+n},uqFng:function(a,n){return a<n},MSYTl:function(a,n,s){return a(n,s)},tOrhC:function(a,n){return a>=n},CQGac:function(a,n){return a<n},GYzAd:function(a,n){return a+n},HpFLC:function(a,n){return a-n},IOGEC:function(a,n){return a<n},eTfOn:function(a,n){return a&n},HhFGA:function(a,n){return a<n},TwuGj:function(a,n){return a|n},jkpOI:function(a,n){return a&n},eLydz:"Tscfc",SqZgK:function(a,n){return a|n},BlDYn:function(a,n){return a>>n},kNYPF:function(a,n){return a&n},hLsBh:function(a,n){return a>>n},ZCtvu:function(a,n){return a|n},mtbbV:t(1282),fMkim:t(563),zBgQE:function(a,n){return a(n)},HZEfm:function(a,n){return a<n},yuBsa:function(a,n){return a&n},hBPHK:function(a,n){return a(n)},jyrRD:function(a,n){return a>=n},celQr:function(a,n){return a===n},Cfafh:t(1435),MbAGK:function(a,n,s){return a(n,s)},JPfcR:function(a,n){return a&n},uUyyF:function(a,n){return a===n},BtqWD:"krBDI",tqxOq:function(a,n){return a&n},vLRXP:function(a,n){return a&n},CzBHO:function(a,n){return a(n)},ZnZho:function(a,n){return a&n},CJSzw:function(a,n){return a&n},hEpma:function(a,n){return a===n},wcrFC:"fqHob",nwVbj:function(a,n){return a&n},FYCmo:function(a,n){return a&n},Ovlvb:function(a,n){return a&n},GeVMy:function(a,n){return a>>>n},ljhWp:function(a,n){return a<<n},VhRso:function(a,n){return a|n},HIDYG:function(a,n){return a>>>n},Dylxh:function(a,n){return a<n},sUXsw:function(a,n){return a<n},ypMeK:function(a,n){return a<n},IwiSR:function(a,n){return a<n},RZisP:function(a,n){return a+n},tuvpX:function(a,n){return a&n},AnKPG:function(a,n){return a!==n},kVAej:function(a,n){return a|n},ueSse:function(a,n){return a&n},ADGmU:function(a,n){return a>>>n},emgro:function(a,n){return a+n},uqAaa:function(a,n){return a|n},pnDzl:function(a,n){return a>>>n},EJtkQ:function(a,n){return a&n},yAQly:function(a,n){return a!==n},kIfbb:function(a,n){return a>>>n},dFtiH:function(a,n){return a>>>n},wGxPn:function(a,n){return a+n},EqxCK:function(a,n){return a|n},wjgNC:function(a,n){return a|n},gGSGS:function(a,n){return a&n},LiIFY:function(a,n){return a>>>n},BQXUF:function(a,n){return a!==n},vWIqr:function(a,n){return a|n},IbKut:function(a,n){return a>>>n},xRAcq:function(a,n){return a>>>n},XLAdu:function(a,n){return a|n},dYJDT:function(a,n){return a===n},LnZqC:function(a,n){return a|n},WlfCk:function(a,n){return a<<n},RPMID:function(a,n){return a<<n},mRNPv:function(a,n){return a|n},GYOjF:function(a,n){return a|n},PrwxP:function(a,n){return a|n},vGxjD:function(a,n){return a<<n},OsMOk:function(a,n){return a<<n},HHWZb:function(a,n){return a<<n},lDUjv:function(a,n){return a<<n},Fsiwo:function(a,n){return a<<n},YEvMJ:function(a,n){return a|n},GOjwe:function(a,n){return a<<n},nlIoC:function(a,n){return a>>>n},VeFrC:function(a,n){return a<<n},CjxXD:function(a,n){return a<<n},dUHKe:function(a,n){return a===n},CGbjh:t(1176),bVOwS:function(a,n){return a&n},HTcbR:function(a,n){return a>>>n},FtMHA:function(a,n){return a>>>n},KgEjC:function(a,n){return a>>>n},UehXK:function(a,n){return a>=n},ubZIb:function(a,n){return a+n},SdChX:function(a,n){return a%n},LLkob:function(a,n){return a/n},SkxKn:function(a,n){return a+n},QPTrW:function(a,n){return a>>>n},aYoAE:function(a,n){return a+n},FNFLG:function(a,n){return a*n},JuIUc:function(a,n){return a===n},RaOQJ:function(a,n){return a&n},NdlOy:function(a,n){return a+n},tbdtB:function(a,n){return a+n},DEswB:function(a,n){return a<<n},PqGKO:function(a,n){return a===n},qGdGO:function(a,n){return a>>>n},BkDVL:function(a,n){return a===n},rMBTb:function(a,n){return a+n},xYpKS:function(a,n){return a&n},uamPt:function(a,n){return a>>>n},HChIq:function(a,n){return a>>>n},OjYDc:function(a,n){return a>>>n},NNbIj:t(469)+t(691),sFOlY:t(1507)+t(278),Xvlxr:t(315)+t(1626),iGbek:t(1e3)+"ERROR",rLPzB:"OPEN_ERROR",aeOsL:"MAX_RETR"+t(1313)+"R",xVSec:t(515),mXRsD:t(1206),FmkUI:function(a,n){return a===n},hvjJs:"hEiMV",OnetQ:t(849),wwJRO:t(333),pPGjd:function(a,n){return a>=n},Gwmwr:t(1298),wOwmJ:t(700)+t(1255),JInLZ:function(a,n){return a+n},FhggX:function(a,n){return a===n},sqZyJ:t(231),gEPIb:function(a,n,s){return a(n,s)},jrwae:"close",fQHUw:t(756),TxnAj:function(a,n,s){return a(n,s)},YfoaB:function(a,n){return a!==n},oTGYd:t(1156),eTuDJ:function(a,n,s){return a(n,s)},CSCAu:function(a,n,s){return a(n,s)},pcbXq:function(a,n){return a instanceof n},WfpJJ:"ZvewY",joXKj:t(1083),Wtnuo:t(725),vqJrK:t(1468),lWurA:function(a,n){return a-n},MvbMU:"DxjZd",jxquP:function(a,n){return a||n},BLCee:function(a,n){return a||n},HrqZX:function(a,n){return a!=n},vIhqX:t(614)+"d",isnpJ:function(a,n){return a===n},dRfKH:t(1006),rXtwn:"2|1|3|0|4",DxPou:function(a,n){return a<=n},DVRoi:function(a,n){return a(n)},MYIOa:function(a,n){return a<n},gTQHB:function(a,n){return a===n},USIRJ:function(a,n){return a+n},gtzsj:function(a,n){return a<n},ALbvH:function(a,n){return a<n},OhFfi:function(a,n){return a===n},Ojiuz:t(1276),OyDTN:"fVtzl",oAtsZ:function(a,n){return a<=n},JWZZS:function(a,n){return a>=n},YWPPC:function(a,n){return a&n},wUlOZ:function(a,n){return a&n},sWnFp:function(a,n){return a>=n},IOCcl:function(a,n){return a|n},cyiBx:function(a,n){return a|n},fNWkz:function(a,n){return a<<n},Japtg:function(a,n){return a+n},OMJUI:function(a,n){return a>>n},cVCXH:function(a,n){return a<n},fDiZe:function(a,n){return a|n},Csniy:function(a,n){return a&n},TIayt:function(a,n){return a+n},FTsRb:function(a,n){return a&n},SRjxA:function(a,n){return a&n},xEtUj:function(a,n){return a|n},yDUol:function(a,n){return a|n},KPFMU:function(a,n){return a|n},kidSo:function(a,n){return a&n},SncRc:function(a,n){return a>>n},DsSdL:function(a,n){return a|n},GPWCV:function(a,n){return a-n},JVJAv:function(a,n){return a instanceof n},yRtDW:t(367),Wqdoo:"applicat"+t(1264),dxjvL:"text/pla"+t(802)+t(908),bDKAU:t(1347),WFKjl:"pfQZb",EZjiv:t(1047),TFQxR:"ppe",TVoyG:function(a,n){return a>=n},XtWDZ:t(618),EMvEv:function(a,n){return a+n},LMIBs:function(a,n){return a(n)},jTrBK:t(1102)+"or",NeNqn:function(a){return a()},ffkcz:function(a,n){return a===n},yFLEf:t(794),qyJnC:"blocked",ohwqH:t(1504),FRrJj:t(241)+t(1133)+t(1138)+"8",dsyzA:function(a,n){return a>>>n},XOrUi:function(a,n){return a&n},WkCWJ:function(a,n){return a<n},YtqBi:function(a,n){return a|n},AXeTI:function(a,n){return a|n},UKrgs:function(a,n){return a>>>n},xwABW:function(a,n,s,l){return a(n,s,l)},xfCaU:function(a,n){return a|n},wumAv:function(a,n){return a&n},MsXTD:function(a,n){return a|n},qQoKv:function(a,n){return a===n},LLIxj:t(1542),YrCGk:function(a,n){return a!==n},pheuS:t(945),Awzzq:"CUWhf",TVZTB:function(a,n){return a!==n},TUNqb:t(1426),PPpow:t(1175),SfuVq:t(292),hATru:function(a,n){return a||n},outkw:function(a,n){return a!==n},pKPFo:"jcojh",mxRwR:function(a,n){return a||n},khdBW:function(a,n){return a||n},oiVbr:function(a,n){return a!==n},PYrpb:t(1340)+t(395)+"ing",GEEmV:function(a,n){return a||n},jZhCA:t(501),xycTs:function(a,n){return a||n},aWAog:function(a,n){return a!=n},UJHLZ:function(a,n){return a||n},agSJp:t(316)+"DB failed",ClMdf:function(a,n,s){return a(n,s)},wAODF:t(731),awRQM:t(1228)+"id",UQLeH:function(a,n){return a(n)},QGFmv:function(a,n,s){return a(n,s)},urIcN:function(a,n){return a||n},VwfZF:function(a,n){return a!=n},RHSZY:t(562),WedFn:"VfWnz",tPVQb:function(a,n,s,l){return a(n,s,l)},bBnls:t(1283)+t(1449)+"ck",rKVbA:function(a,n,s,l){return a(n,s,l)},ovAxY:t(1283)+t(255)+"k",DcLTn:t(1283)+t(966)+t(307),pbomt:function(a,n,s,l){return a(n,s,l)},dYLMR:t(1472),aYBYE:"is_ack",NDhks:function(a,n){return a&&n},AwQiW:t(597),dTZmZ:function(a){return a()},QtZPq:function(a,n){return a instanceof n},KfOMn:function(a,n){return a instanceof n},GBwat:t(498)+t(1264)+";charset"+t(968),PIBTA:t(486)+"e",syZRV:t(637),xTGdb:function(a){return a()},FbyxA:function(a,n){return a<n},hUJuL:function(a,n){return a>n},EnrgR:function(a,n){return a+n},LiYeA:function(a,n){return a|n},DMZml:function(a,n){return a(n)},nsEGw:function(a,n){return a+n},Rcljb:function(a,n){return a+n},iQvrr:function(a,n){return a+n},kRIJB:"index out of ran"+t(957),Zayyk:t(677)+t(850)+"e",TdxSb:function(a,n,s,l){return a(n,s,l)},ocQOs:function(a,n){return a+n},KMdsV:function(a,n,s){return a(n,s)},AownE:function(a,n){return a<<n},MmoJX:function(a,n){return a<n},mKFpL:t(1224)+t(781)+"s",ZbEeX:function(a,n){return a!==n},QcRHE:"PbyOG",etYTp:function(a,n){return a|n},wkXXo:function(a,n){return a|n},DSXzN:function(a,n){return a|n},xnTya:function(a,n){return a<<n},YXMeQ:function(a,n){return a+n},hnrDl:function(a,n){return a<<n},NRRis:function(a,n){return a+n},KxBes:function(a,n){return a|n},NvzOr:function(a,n){return a|n},FptpX:function(a,n){return a+n},HkHWL:function(a,n){return a&n},YiaVm:function(a,n){return a&n},ALOWL:function(a,n){return a>>>n},fmIAX:function(a,n){return a+n},adhmB:function(a,n){return a&n},MeMPK:function(a,n){return a+n},lDzIg:function(a,n){return a>>>n},QMxbO:function(a,n){return a&n},uFzdI:function(a,n){return a>>>n},mYzPt:function(a,n){return a>>>n},fGrTW:function(a,n){return a+n},Effxe:function(a,n){return a&n},BZyim:function(a,n){return a+n},ozHIO:function(a,n){return a(n)},huWau:function(a,n){return a+n},XJrKz:t(431),eynjR:function(a,n){return a&n},LcorZ:function(a,n){return a&n},FbPgO:function(a,n){return a>>>n},KzszJ:function(a,n){return a|n},knadj:function(a,n){return a<n},Kaygg:function(a,n){return a>>>n},uXmyn:function(a,n){return a<n},yqtjX:function(a,n,s,l){return a(n,s,l)},Ksbbh:t(1327),GBNQO:function(a,n,s,l){return a(n,s,l)},eCrla:t(1021),aEvSR:"header",JbhVn:function(a,n,s,l){return a(n,s,l)},kaQbH:t(1391),CCNDi:t(310)+t(904),fKfmC:t(658)+t(1391),krsoK:function(a,n,s,l){return a(n,s,l)},LpvDY:function(a,n){return a(n)},oPNvw:function(a,n){return a(n)},ASurn:"cursor_f"+t(415),BoTda:function(a,n){return a<n},ooGiA:t(309),UlqDl:function(a,n,s){return a(n,s)},MqthA:function(a,n,s){return a(n,s)},zixuU:function(a,n){return a+n},tpcuC:t(334)+t(536),WaaWX:t(560)+t(996),nhEjH:"ALL",TCqEJ:t(581),cAtOx:function(a,n,s,l){return a(n,s,l)},YJdpb:function(a,n){return a(n)},GIUbB:function(a,n){return a!==n},nBQsh:"hzoqp",uKKCT:t(1216),RKTAo:t(1401),RdzyV:function(a,n){return a(n)},oeMwI:function(a,n){return a===n},aRRZB:"tryaQ",kXyBV:t(329)+"r",slKeR:function(a,n){return a||n},lTNqk:function(a,n){return a===n},WvZBg:t(1287),JWAir:t(852),msmdR:function(a,n,s){return a(n,s)},xfaUN:t(1283)+t(1583),uGvDJ:function(a,n,s,l){return a(n,s,l)},QzIkA:function(a){return a()},zDctH:"URuxO",GQxsK:t(458),YgNwj:function(a){return a()},jdZYY:function(a){return a()},OLstg:function(a){return a()},OBHBx:function(a){return a()},FnNsR:function(a,n){return a!==n},gdEfB:function(a){return a()},wzEOf:function(a,n){return a<n},IaHot:function(a,n,s){return a(n,s)},FWaDk:t(1395),lXmPi:function(a,n){return a!==n},ZfoyL:function(a,n){return a>=n},VjANg:function(a,n){return a===n},xepcB:t(1372),jhytV:t(435),UUdfj:t(426),bVkaa:t(1421),FyNbT:function(a,n,s){return a(n,s)},pGltD:t(673)+"t",OHnub:function(a,n){return a!==n},iCpAx:t(472),PGyBl:function(a,n){return a!==n},MRkmq:t(347),rvuRE:function(a,n){return a(n)},DoSlf:t(768)+t(1602),caApG:t(419),AgRMA:t(786),noxAW:t(453)+t(1169)+"alid url",qzAxo:t(453)+t(1552)+t(906)+t(1031)+t(1345)+"tructor "+t(709)+"ined",wQGRL:function(a,n,s){return a(n,s)},ZXYqu:t(253)+t(325)+t(1029)+"ct",LItne:t(749),OQypb:t(446),EMGzL:t(728),yRFxg:"pageshow",aYeRN:function(a,n){return a===n},QhZru:t(1459),gIRPK:function(a,n){return a!==n},kuIcK:"https:",kNzlK:"wss://",LzWqS:t(1127),AtpSu:t(1600),KSsRu:t(582),HgIOu:t(1120)+"d",ZZSbr:t(453)+"rovide b"+t(535)+t(822)+t(1632),YvXuX:t(360),pHCOT:t(1229),JzwtH:t(851)+"0",WdIyJ:function(a,n){return a||n},yAtOw:function(a,n,s){return a(n,s)},Xcoev:function(a,n){return a(n)},nYeWQ:"bfwXF",jxVgt:t(344),ZIExS:t(378)+">",IXLtT:t(936),YXNEy:function(a,n){return a>n},DBKjV:t(1224)+"e_timeout",XWnyA:t(390),ukORz:t(716)+t(1242)+"y closed",cXjcN:t(716)+t(1159)+t(466)+t(1554)+"ed",MYnVq:function(a,n){return a===n},TExhb:t(1296),LhnUM:t(1379),joVjJ:function(a,n){return a(n)},Dokad:t(1385),WeOIw:t(1099)+t(1044)+t(1036)+"g",Pssyn:function(a,n){return a(n)},qiLXz:function(a,n){return a===n},IhYUJ:"send_ack",DQocW:t(365)+"2",dFBiE:t(685),eUXxU:function(a,n,s){return a(n,s)},QmSfG:t(854)+t(1510)+t(381)+t(313),ivKZM:function(a,n){return a!==n},xPfeW:t(1550),IXlxh:function(a,n){return a+n},NXmtb:function(a,n,s){return a(n,s)},pakVJ:t(454),ExvOq:function(a,n){return a===n},eRXyv:t(463),SPFDz:function(a,n){return a==n},tnUaS:t(453)+"rovide a"+t(760)+t(1631)+t(1170)+"e a stri"+t(641)+t(1460)+"ffer",TubTI:function(a,n){return a==n},CgYfa:t(502),xYzIZ:function(a,n){return a instanceof n},BcraG:function(a,n){return a(n)},AuTUV:function(a,n){return a(n)},ujxDJ:function(a,n){return a(n)},qQKjj:t(453)+"rovide a"+t(1258)+t(904),FbWNg:function(a,n){return a instanceof n},xtLod:function(a,n){return a instanceof n},OLFBL:t(1594),LAXrt:t(911),iMyNv:function(a,n){return a==n},VhVLm:"KYaqz",kteTN:t(569),qzLmK:function(a,n){return a!==n},djsao:t(397),HxbQl:t(1011),WXRBZ:function(a,n,s){return a(n,s)},FOvof:t(1182),GEMOG:function(a,n){return a*n},FpVpx:function(a,n){return a*n},vbbLv:function(a,n){return a!=n},LGNje:function(a,n){return a===n},QOJno:t(1286),JGUoJ:"Object",hcRUu:t(807)+t(632)+t(1613)+"pe",OowNQ:function(a,n){return a===n},KJaff:function(a,n){return a!=n},vFoyZ:t(1009)+t(656)+t(739),UYjyS:function(a,n){return a===n},VmFzN:t(1213)+t(1089)+t(1475),sHoZY:function(a,n){return a===n},lGFhW:function(a,n){return a===n},WfDjP:function(a,n){return a!=n},ZFRpr:function(a,n){return a!=n},MyVvh:t(438)+t(1400)};Ot.r(Re),Ot.d(Re,{FWS:()=>Ap,CustomErrorEvent:()=>Ld,createCloseEvent:()=>ft,ReconnectEvent:()=>Pd,createErrorEvent:()=>rt,decodedFrame:()=>Vt,createOpenEvent:()=>Ud,CustomCloseEvent:()=>Nd,createReconnectEvent:()=>ea,FrontierMessageEvent:()=>Bd,encodeFrame:()=>Nt,createMessageEvent:()=>Fd,OpenEvent:()=>zd,ErrorCode:()=>Yt,Event:()=>Kn,MessageEvent:()=>Md});let r="";function i(a=""){let n=t,s="02",l=""+Date.now(),u=r||(r=e[n(449)](h,a)),_=Math[n(272)]().toString(16)[n(1566)](-6);return e[n(1585)](s,l)+u+_}function o(){let a=t;return e[a(1585)](1e4*Date[a(812)](),Math[a(980)](1e4*Math[a(272)]()))}function c(a){let n=t;return e[n(1585)](e[n(449)](Array,8).join("0"),e[n(1106)](parseInt,a,10).toString(2))[n(1566)](-8)}function d(a){let n=t;return e[n(1053)](Array(4)[n(1030)]("0"),parseInt(a,2)[n(361)](16))[n(1566)](-4)}function f(a){let n=t,s=a[n(387)](/\./).map(_=>c(_)),l=[];return l[0]=e.sZfCU(d,s[0]+s[1]),l[1]=e.PZjcL(d,e[n(1041)](s[2],s[3])),[e[n(1537)],e[n(1537)],n(1448),"0000",e[n(1537)],e[n(1103)],l[0],l[1]][n(1030)]("")}function h(a){let n=t,s=/(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}/[n(1155)](a),l=/(([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]))/[n(1155)](a);return s?e[n(362)](f,a):l?x(a):e[n(836)]}function x(a){let n=t,s="",l=[],u=0,_=0,v=!0,b=e[n(1537)];if(e[n(1408)](a[n(775)]("::"),-1)){let p=a[n(387)]("::");for(let B=0;e[n(478)](B,p.length);B++){let z=p[B];if(e[n(877)](z[n(775)](":"),0)){let U=z[n(387)](":");v&&(u=U[n(301)]),_+=U[n(301)];for(let H=0;e[n(1209)](H,U[n(301)]);H++)if(e[n(412)](4,U[H][n(301)])){let V=b.substring(0,4-U[H][n(301)]),it=V[n(529)](U[H]);l[n(1503)](it)}else l[n(1503)](U[H]);v=!1}else{if(e[n(376)](4,z.length)){let U=b[n(1293)+"g"](0,e[n(413)](4,z.length)),H=U.concat(z);l[n(1503)](H)}else l[n(1503)](z);v&&(u+=1),_+=1,v=!1}}let k="";for(let B=0;e[n(920)](B,e[n(413)](8,_));B++)k=k.concat(b);for(let B=0;e.QPmIr(B,l[n(301)]);B++)e.DeGxD(B,u)&&(s=s.concat(k)),s=s[n(529)](l[B]);return s}if(e[n(1436)](e[n(909)],e.UwEKf))this[n(474)]?.[n(627)](),this[n(474)]=void 0;else{let p=a[n(387)](":");for(let k=0;k<p.length;k++){let B=p[k];if(e[n(1607)](4,p[k][n(301)])){let z=b[n(1293)+"g"](0,4-p[k][n(301)]),U=z[n(529)](B);s=s.concat(U)}else s=s[n(529)](B)}return s}}function m(a,n){let s=t,l=a[s(441)];e[s(1125)](void 0,l)&&(e[s(1246)](fe,n,10),e[s(1126)](j,n,l));let u=a[s(1528)];u!==void 0&&(e[s(1571)](fe,n,18),j(n,u))}function g(a){let n=t,s={WTVnv:function(l,u){return e[ee(362)](l,u)},UNeEq:n(1102)+"or"};if(e[n(789)](n(1482),e[n(640)])){let l={};e:for(;!Z(a);){let u=e[n(682)](le,a);switch(e[n(1192)](u,3)){case 0:break e;case 1:l[n(441)]=e[n(1025)](O,a,e[n(296)](le,a));break;case 2:l[n(1528)]=e.fwnhI(O,a,e[n(362)](le,a));break;default:R(a,e[n(464)](7,u))}}if(l[n(441)]===void 0)throw new Error(n(527)+n(842)+n(667)+n(441));if(e[n(1436)](void 0,l[n(1528)]))throw new Error(e[n(348)]);return l}else return this[n(1119)+n(1251)+n(1445)+"t"]=1,this[n(1625)+n(1008)]++,this.endpoints[this[n(1625)+n(1008)]]}function A(a){let n=e.kCKMR(C);return w(a,n),e.sZfCU(M,n)}function w(a,n){let s=t;if(e.cDmhY(s(1356),e[s(425)])){let l=a[s(1158)];l!==void 0&&(fe(n,8),e[s(1025)](lt,n,l));let u=a[s(1465)];e[s(1494)](void 0,u)&&(e.ZGLzp(fe,n,16),e[s(1126)](lt,n,u));let _=a.service;e[s(412)](void 0,_)&&(e[s(1025)](fe,n,24),lt(n,e.TfNgW(P,_)));let v=a[s(586)];e.tiQEp(void 0,v)&&(e[s(579)](fe,n,32),lt(n,P(v)));let b=a.headers;if(e[s(1607)](void 0,b))for(let it of b){e[s(1612)](fe,n,42);let Qt=C();e.JlXDF(m,it,Qt),e[s(1627)](fe,n,Qt.limit),W(n,Qt),e[s(866)](D,Qt)}let p=a.payloadEncoding;e[s(787)](void 0,p)&&(e[s(1126)](fe,n,50),e[s(1246)](j,n,p));let k=a[s(518)+s(1517)];e[s(1393)](void 0,k)&&(e.cMcMC(fe,n,58),e[s(932)](j,n,k));let B=a[s(659)];e[s(675)](void 0,B)&&(fe(n,66),e[s(251)](fe,n,B[s(301)]),e[s(579)](he,n,B));let z=a[s(318)];e[s(1393)](void 0,z)&&(e[s(1393)](e[s(1513)],e[s(1513)])?(this[s(531)]&&this[s(531)].send(_0x40d242),this[s(1640)+s(510)][_0x51699f]=null):(fe(n,74),e[s(1227)](j,n,z)));let U=a["serverTi"+s(1180)];e.ZwfyR(void 0,U)&&(fe(n,82),j(n,U));let H=a.msgID;e.WYRQf(void 0,H)&&(e[s(1126)](fe,n,90),e[s(1612)](j,n,H));let V=a[s(1118)+"e"];if(e.JPjhy(void 0,V))if(e[s(818)](e.hDZip,e.HksEI))e.XxtfH(fe,n,96),e.cMcMC(lt,n,e.LFUqC(P,V));else{let it=this[s(1188)+s(456)]?.[s(465)+"ntEndpoint"]();this[s(303)](s(1467)+it),_0x39eb39()}}else{let l=e.XxtfH(_0x246ff4,e[s(1586)],{message:_0xe835f8[s(685)],code:_0x134b69[s(804)+"OR"],error:_0x57da8f});this["_dispatc"+s(1040)+s(364)](l)}}function E(a){let n=t;if(e.ziBme(n(1136),n(1096)))_0x50b5c3=e[n(1232)](e[n(1232)](e[n(1232)](e[n(1429)](7&_0xe82194,18),e[n(1390)](e.ePpvv(63,_0x13551f),12)),e[n(1390)](e.ePpvv(63,_0x47be1e),6)),63&_0x3b955f),_0x3ba4f1<65536||e[n(548)](_0x15efc5,1114111)?_0x55a411+=_0x5a995e:(_0x2df351-=65536,_0x488e6c+=e[n(1627)](_0x4650cc,(_0x2457b4>>10)+55296,e[n(1087)](e.koLyf(1023,_0x22d95d),56320)),_0x4ca85f+=3);else return e.LCcMK(I,e.YBklw(N,a))}function I(a){let n=t,s={};e:for(;!e[n(866)](Z,a);)if(e.MvZPK(n(844),e[n(935)])){let l=e[n(1351)](le,a);switch(e[n(1192)](l,3)){case 0:break e;case 1:s[n(1158)]=e[n(1126)](Et,a,!0);break;case 2:s[n(1465)]=Et(a,!0);break;case 3:s[n(1327)]=e.IZErJ(le,a);break;case 4:s[n(586)]=e[n(362)](le,a);break;case 5:{let u=e.qGOGc(S,a);(s[n(1364)]||(s.headers=[]))[n(1503)](g(a)),a.limit=u;break}case 6:s[n(979)+n(350)]=e[n(1612)](O,a,le(a));break;case 7:s[n(518)+n(1517)]=e[n(1630)](O,a,e[n(489)](le,a));break;case 8:s[n(659)]=_e(a,le(a));break;case 9:s.LogIDNew=e[n(974)](O,a,e.HaFof(le,a));break;case 10:s["serverTi"+n(1180)]=e[n(1059)](O,a,e[n(362)](le,a));break;case 11:s[n(440)]=O(a,e[n(901)](le,a));break;case 12:s[n(1118)+"e"]=e[n(1225)](le,a);break;default:e[n(1237)](R,a,7&l)}}else{if(!this[n(1101)+"orOnline"]()||this[n(669)+"osed"])return;this[n(1188)+n(456)]?.[n(1167)+n(814)+"fig"](),this[n(558)+"sCounter"]?.["resetCou"+n(684)](),this._ws?this[n(665)+"ect"](1001,e[n(1553)],!0):this[n(805)]()}if(e[n(1051)](void 0,s[n(1158)]))throw new Error("Missing "+n(842)+n(667)+n(1158));if(e[n(990)](void 0,s[n(1465)]))throw new Error(e.gAMPz);if(e.DeGxD(void 0,s[n(1327)]))throw new Error(e[n(1384)]);if(e[n(990)](void 0,s[n(586)]))throw new Error(e[n(1185)]);return s}function S(a){let n=t,s=e[n(1351)](le,a),l=a[n(511)];return a.limit=e[n(1041)](a.offset,s),l}function R(a,n){let s=t;switch(n){case 0:for(;e[s(464)](128,ie(a)););break;case 2:e.cMcMC(K,a,e[s(485)](le,a));break;case 5:K(a,4);break;case 1:K(a,8);break;default:throw new Error(e[s(1585)]("Unimplem"+s(1505)+s(783),n))}}function P(a){let n=t;return e[n(405)]!==e[n(405)]?this[n(531)]?this[n(531)].protocol:"":(a|=0,{low:a,high:a>>31,unsigned:e[n(1376)](a,0)})}let y=[];function C(){let a=t,n=y[a(910)]();return n?(n[a(1205)]=n[a(511)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function D(a){y[t(1503)](a)}function N(a){return{bytes:a,offset:0,limit:a[t(301)]}}function M(a){let n=t,s=a[n(1191)],l=a[n(511)];return s[n(301)]===l?s:s.subarray(0,l)}function K(a,n){let s=t;if(e[s(1349)](e[s(1585)](a.offset,n),a.limit))throw new Error(e[s(1244)]);a[s(1205)]+=n}function Z(a){let n=t;return a[n(1205)]>=a[n(511)]}function te(a,n){let s=t,l=a[s(1191)],u=a[s(1205)],_=a.limit,v=u+n;if(v>l[s(301)]){let b=new Uint8Array(e.OJRGe(2,v));b.set(l),a[s(1191)]=b}return a[s(1205)]=v,v>_&&(a[s(511)]=v),u}function X(a,n){let s=t,l=a[s(1205)];if(l+n>a[s(511)])throw new Error(e.adTNd);return a[s(1205)]+=n,l}function _e(a,n){let s=t,l=X(a,n);return a[s(1191)][s(916)](l,l+n)}function he(a,n){let s=t,l=e[s(544)](te,a,n.length);a[s(1191)][s(591)](n,l)}function O(a,n){let s=t,l={gxemQ:function(k,B,z){return e[ee(1145)](k,B,z)}},u=e[s(245)](X,a,n),_=String[s(242)+s(796)],v=a[s(1191)],b="\uFFFD",p="";for(let k=0;e[s(478)](k,n);k++){let B=v[k+u],z,U,H,V;e[s(1253)](e[s(1259)](128,B),0)?p+=e[s(727)](_,B):e[s(925)](e[s(1259)](224,B),192)?e[s(1376)](k+1,n)?p+=b:(z=v[e[s(1087)](k,u)+1],e[s(1125)](e[s(1160)](192,z),128)?p+=b:e[s(845)](e[s(1590)],e[s(1294)])?(V=e[s(306)](e[s(1160)](31,B),6)|e[s(228)](63,z),e[s(478)](V,128)?p+=b:(p+=e[s(1231)](_,V),k++)):(dMApqa[s(284)](_0x2685e9,_0x2a32e3,8),dMApqa[s(284)](_0x38ea73,_0x115380,_0x533deb))):e[s(1587)](e[s(566)](240,B),224)?k+2>=n?p+=b:(z=v[e[s(1585)](k,u)+1],U=v[e[s(626)](e[s(1087)](k,u),2)],e[s(1393)](e.dHzVS(z,U<<8)&49344,32896)?p+=b:(V=e[s(801)](e[s(801)]((15&B)<<12,e.myPfO(63&z,6)),e[s(433)](63,U)),e.QPmIr(V,2048)||e[s(1376)](V,55296)&&e[s(610)](V,57343)?p+=b:(p+=_(V),k+=2))):e.nrZwl(e[s(1489)](248,B),240)?e[s(1376)](e[s(1087)](k,3),n)?p+=b:(z=v[e[s(622)](e[s(626)](k,u),1)],U=v[e[s(1087)](k,u)+2],H=v[e[s(1585)](k+u,3)],e[s(464)](e[s(801)](z|e[s(867)](U,8),e[s(611)](H,16)),12632256)!==8421504?p+=b:(V=e[s(870)](e[s(1390)](7&B,18)|(63&z)<<12|e[s(611)](e[s(279)](63,U),6),e[s(833)](63,H)),e[s(1210)](V,65536)||e[s(1280)](V,1114111)?p+=b:(V-=65536,p+=e[s(382)](_,e[s(690)](e.pjrYv(V,10),55296),e.cCIDl(1023&V,56320)),k+=3))):p+=b}return p}function j(a,n){let s=t,l={qbzew:function(p,k){return e[ee(1225)](p,k)},zIVsS:e.GnqtG},u=n.length,_=0;for(let p=0;e.EKGIH(p,u);p++)if(e.DeGxD(e[s(543)],e.YeKOG)){let k=n.charCodeAt(p);e[s(1376)](k,55296)&&e[s(610)](k,56319)&&e[s(1511)](e[s(970)](p,1),u)&&(k=e[s(690)](k<<10,n.charCodeAt(++p))-56613888),_+=k<128?1:k<2048?2:e[s(1485)](k,65536)?3:4}else this.endpoints=_0x3172b2,this.maxRetries=_0x56d4cd,this[s(1625)+s(1008)]=0,this[s(1119)+s(1251)+s(1445)+"t"]=0;e[s(1474)](fe,a,_);let v=e[s(1474)](te,a,_),b=a[s(1191)];for(let p=0;p<u;p++){let k=n[s(896)+"At"](p);if(e[s(404)](k,55296)&&e[s(610)](k,56319)&&e[s(358)](e.GYzAd(p,1),u)&&(k=e[s(1598)](e[s(1053)](e[s(1390)](k,10),n[s(896)+"At"](++p)),56613888)),k<128)b[v++]=k;else{if(e[s(1407)](k,2048))b[v++]=e[s(801)](e.eTfOn(k>>6,31),192);else{if(e[s(459)](k,65536))b[v++]=e[s(274)](e[s(589)](k>>12,15),224);else if(e[s(1005)]!=="Tscfc"){let B=_0x6d37e7[s(1441)+s(291)](s(618));_0x439007[s(1488)+s(1633)]=z=>{let U=s;_0x71bc17[U(664)]["removeCh"+U(708)](B),_0x2d9025[U(1488)+U(1633)]=void 0,l[U(1141)](_0x1d68b6,z&&z[U(471)]||l[U(1523)])},B.type=e[s(1593)],B[s(719)]=_0x2d121d[s(398)](/^ws/,e.QRUdP)+e.BIyYG;try{_0x33638a[s(664)][s(304)+s(708)](B)}catch{_0x29cc1f[s(664)][s(1194)+s(708)](B)}}else b[v++]=e.SqZgK(e.lJpAH(k>>18,7),240),b[v++]=e[s(1232)](e[s(508)](k,12)&63,128);b[v++]=e.kNYPF(e[s(1498)](k,6),63)|128}b[v++]=e[s(462)](e[s(1259)](63,k),128)}}}function W(a,n){let s=t,l=te(a,n[s(511)]),u=a[s(1191)],_=n[s(1191)];for(let v=0,b=n.limit;e.nZoYH(v,b);v++)u[v+l]=_[v]}function ie(a){let n=t;return a[n(1191)][e[n(1233)](X,a,1)]}function $e(a,n){let s=t,l=e[s(1059)](te,a,1);a.bytes[l]=n}function le(a){let n=t,s={XeEmQ:function(l,u,_){return e.MNwQu(l,u,_)},ROZBl:e[n(1098)]};if(e[n(1051)](n(563),e[n(869)])){let l=0,u=0,_;do _=e[n(1492)](ie,a),e.HZEfm(l,32)&&(u|=e[n(611)](e[n(1274)](127,_),l)),l+=7;while(e.AxcgD(128,_));return u}else{let l=s[n(1115)](_0x4747fd,n(673)+"t",{message:s[n(793)]});this[n(1265)+n(395)]&&this[n(1265)+n(395)](l)}}function fe(a,n){let s=t,l={uRWuG:function(u,_){return e[ee(1637)](u,_)},Iishy:s(1536)+"reason"};for(n>>>=0;e.jyrRD(n,128);)e.celQr(e[s(1273)],e.Cfafh)?(e[s(1308)]($e,a,127&n|128),n>>>=7):(_0x10731c[s(1488)+s(1633)]=void 0,l[s(1447)](_0x245a1a,l[s(377)]));$e(a,n)}function Et(a,n){let s=t,l={cIPUS:function(u,_){return u<<_},jriAn:function(u,_){return e[ee(992)](u,_)}};if(e[s(1215)](e[s(964)],s(1245))){let u=_0x4dff75[s(685)][s(659)];u&&_0x3d0fe7[s(676)+"rs"](u)}else{let u=0,_=0,v=0,b;return b=e[s(296)](ie,a),u=e[s(464)](127,b),128&b&&(b=e[s(830)](ie,a),u|=e[s(833)](127,b)<<7,128&b&&(b=e[s(362)](ie,a),u|=e[s(306)](e[s(1311)](127,b),14),e[s(580)](128,b)&&(b=e[s(1481)](ie,a),u|=e[s(306)](127&b,21),e.ZnZho(128,b)&&(b=e[s(800)](ie,a),_=127&b,e[s(1274)](128,b)&&(b=ie(a),_|=(127&b)<<7,e[s(1514)](128,b)&&(b=ie(a),_|=e[s(1178)](127&b,14),128&b&&(e[s(1581)](e[s(521)],e[s(521)])?(b=ie(a),_|=e[s(611)](e[s(1478)](127,b),21),e[s(1247)](128,b)&&(b=e[s(449)](ie,a),v=e[s(1544)](127,b),128&b&&(b=e[s(1492)](ie,a),v|=e[s(1178)](e[s(1234)](127,b),7)))):(_0xe02660=_0x328604(_0x4f2ba2),_0x39309c|=l[s(1560)](l.jriAn(127,_0x4bc60d),7))))))))),{low:e[s(342)](u,e.olSNV(_,28)),high:e[s(1232)](e.GeVMy(_,4),e[s(792)](v,24)),unsigned:n}}}function lt(a,n){let s=t,l=n[s(421)]>>>0,u=e.GeVMy(e.VhRso(e[s(942)](n[s(421)],28),e[s(867)](n[s(759)],4)),0),_=n[s(759)]>>>24,v=_===0?u===0?e[s(455)](l,16384)?e[s(912)](l,128)?1:2:e.TeVkt(l,2097152)?3:4:e.ypMeK(u,16384)?u<128?5:6:e[s(643)](u,2097152)?7:8:e[s(742)](_,128)?9:10,b=te(a,v),p=a[s(1191)];switch(v){case 10:p[e.RZisP(b,9)]=e.tuvpX(e[s(1622)](_,7),1);case 9:p[b+8]=e[s(1419)](9,v)?e.kVAej(128,_):e.ueSse(127,_);case 8:p[b+7]=e.cYPEr(8,v)?e.VXHzU(e[s(942)](u,21),128):e.qmMgA(e[s(1611)](u,21),127);case 7:p[e[s(1117)](b,6)]=e[s(733)](7,v)?e.uqAaa(e.pnDzl(u,14),128):e[s(636)](e[s(1611)](u,14),127);case 6:p[b+5]=e.yAQly(6,v)?e.kVAej(e[s(1157)](u,7),128):e[s(228)](e.dFtiH(u,7),127);case 5:p[e[s(1433)](b,4)]=e[s(1125)](5,v)?e[s(1339)](128,u):e[s(1311)](127,u);case 4:p[e[s(1041)](b,3)]=e.qbidF(4,v)?e[s(1123)](e.kIfbb(l,21),128):e[s(748)](e.LiIFY(l,21),127);case 3:p[b+2]=e[s(1486)](3,v)?e.vWIqr(e[s(573)](l,14),128):e[s(1489)](e[s(1577)](l,14),127);case 2:p[b+1]=e[s(1607)](2,v)?e[s(870)](e.dFtiH(l,7),128):e[s(1234)](e[s(552)](l,7),127);case 1:p[b]=v!==1?e.VXHzU(128,l):e[s(992)](127,l)}}function Vt(a){return E(a)}function Nt(a){return e[t(830)](A,a)}let Jt=65536,Fr=e[t(1193)],ge=e[t(621)](Jt,Jt),Ie=e[t(532)](ge,ge),$n=e.LLkob(Ie,2),De=String[t(1201)+"e"][t(896)+"At"];class ce{constructor(n,s,l){let u=t;this[u(948)]=!0,this[u(421)]=e[u(1365)](0,n),this[u(759)]=e[u(1365)](0,s),this[u(470)]=!!l}static isLong(n){let s=t;return n&&e.dYJDT(!0,n[s(948)])}static[t(861)](n,s,l){return new ce(n,s,l)}static fromBytes(n,s,l){let u=t;return l?ce[u(898)+u(1238)](n,s):ce[u(898)+u(1603)](n,s)}static[t(898)+t(1238)](n,s){let l=t;return new ce(e.VXHzU(e[l(570)](n[0],e.WlfCk(n[1],8)),e.sRhEI(n[2],16))|e[l(322)](n[3],24),e[l(1266)](e[l(239)](e[l(870)](n[4],e.LiCTB(n[5],8)),n[6]<<16),n[7]<<24),s)}static["fromByte"+t(1603)](n,s){let l=t;return new ce(e[l(695)](e[l(342)](n[4]<<24,e.vGxjD(n[5],16)),e[l(375)](n[6],8))|n[7],e.SqZgK(e[l(1232)](e[l(1278)](n[0],24)|e[l(1614)](n[1],16),e[l(1079)](n[2],8)),n[3]),s)}static[t(791)](n){let s=t;return e[s(1581)](n,Fr)?Od:new ce(e[s(409)](e.ZCtvu(e[s(1403)](e.XLAdu(De.call(n,0),e[s(651)](De[s(235)](n,1),8)),De[s(235)](n,2)<<16),De.call(n,3)<<24),0),e[s(229)](e[s(239)](De.call(n,4)|e.VeFrC(De.call(n,5),8)|e[s(306)](De[s(235)](n,6),16),e[s(273)](De[s(235)](n,7),24)),0),!0)}[t(224)](){let n=t;return e.dUHKe(e[n(1236)],n(1575))?!!this[n(474)]:String[n(242)+n(796)](e[n(767)](255,this[n(421)]),e[n(1312)](e[n(1577)](this[n(421)],8),255),e.nwVbj(e[n(552)](this[n(421)],16),255),this[n(421)]>>>24,e[n(433)](255,this[n(759)]),e[n(748)](e[n(631)](this[n(759)],8),255),e[n(862)](this[n(759)],16)&255,e[n(533)](this[n(759)],24))}static[t(479)+"er"](n,s=!0){let l=t;if(isNaN(n))return s?zx:Od;if(s){if(e[l(1108)](n,Ie))return Ux}else{if(e[l(610)](n,-$n))return Gx;if(e.ubZIb(n,1)>=$n)return Fx}return ce.fromBits(e[l(1365)](e.SdChX(n,ge),0),e.EqxCK(e[l(1463)](n,ge),0),s)}toNumber(){let n=t;return this[n(470)]?e[n(1604)](e.OJRGe(e.QPTrW(this[n(759)],0),ge),this[n(421)]>>>0):e[n(1132)](e.FNFLG(this[n(759)],ge),this[n(421)]>>>0)}[t(1621)](){let n=t;return e[n(1253)](0,this[n(759)])&&e[n(1464)](0,this[n(421)])}[t(827)](n){let s=t;ce[s(948)](n)||(n=ce.fromNumber(n));let l=e[s(1622)](this[s(759)],16),u=e.ZnZho(65535,this.high),_=this[s(421)]>>>16,v=e.RaOQJ(65535,this[s(421)]),b=e[s(1534)](n[s(759)],16),p=e[s(589)](65535,n.high),k=e[s(533)](n[s(421)],16),B=e[s(433)](65535,n[s(421)]),z=0,U=0,H=0,V=0;return V+=v+B,H+=V>>>16,V&=65535,H+=e[s(1394)](_,k),U+=e[s(942)](H,16),H&=65535,U+=e[s(1354)](u,p),z+=e.HIDYG(U,16),U&=65535,z+=e.wGxPn(l,b),z&=65535,ce.fromBits(e[s(771)](e[s(1487)](H,16),V),z<<16|U,this[s(470)])}[t(1015)](n){let s=t;return ce[s(948)](n)||(n=ce.fromNumber(n)),e[s(412)](this[s(470)],n[s(470)])&&e[s(480)](e.qGdGO(this[s(759)],31),1)&&e[s(229)](n.high,31)===1?!1:e[s(1197)](this[s(759)],n[s(759)])&&e[s(1547)](this[s(421)],n[s(421)])}[t(1071)](){let n=t;return this.low===-1&&e[n(1581)](-1,this[n(759)])?ce[n(861)](0,0,this[n(470)]):this[n(421)]===-1?ce[n(861)](0,e[n(588)](this[n(759)],1),this[n(470)]):ce.fromBits(e[n(392)](this[n(421)],1),this[n(759)],this.unsigned)}[t(1480)](n){let s=t;return n?this[s(603)+"E"]():this[s(1166)+"E"]()}[t(603)+"E"](){let n=t,s=this[n(759)],l=this[n(421)];return[e.ZnZho(255,l),l>>>8&255,e[n(1378)](e[n(942)](l,16),255),e[n(1207)](l,24),e[n(868)](255,s),e.ePpvv(e.QPTrW(s,8),255),e.KgEjC(s,16)&255,e[n(573)](s,24)]}[t(1166)+"E"](){let n=t,s=this.high,l=this.low;return[e[n(631)](s,24),e[n(1274)](e.HChIq(s,16),255),s>>>8&255,e[n(833)](255,s),e[n(484)](l,24),e.QPTrW(l,16)&255,e[n(282)](l,8)&255,e.PVLaD(255,l)]}}let Od=new ce(0,0,!1),zx=new ce(0,0,!0),Fx=ce[t(861)](-1,2147483647,!1),Ux=ce.fromBits(-1,-1,!0),Gx=ce.fromBits(0,-2147483648,!1);var Yt=(function(a){let n=t,s=e[n(555)][n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":return a;case"1":a[a[e[n(982)]]=5001]=e[n(982)];continue;case"2":a[a[e[n(1432)]]=5002]=e[n(1432)];continue;case"3":a[a[e[n(495)]]=5004]=e[n(495)];continue;case"4":a[a[e[n(523)]]=5005]=e[n(523)];continue;case"5":a[a[e[n(1042)]]=5003]=e[n(1042)];continue}break}})({});class Kn{constructor(n){let s=t;this[s(819)]=n,this[s(287)]=null}}class Pd extends Kn{constructor(n,s){let l=t;super(n),this[l(685)]=s&&s[l(685)]||null}}class Ld extends Kn{constructor(n,s){let l=t,u=("3|6|5|0|"+l(1546))[l(387)]("|"),_=0;for(;;){switch(u[_++]){case"0":this[l(1515)]=s&&s[l(1515)]||"";continue;case"1":this[l(852)]=s&&s[l(852)]||5001;continue;case"2":this.lineno=s&&s.lineno||0;continue;case"3":super(n);continue;case"4":this[l(685)]=s&&s[l(685)]||"";continue;case"5":this[l(671)]=s&&s[l(671)]||0;continue;case"6":this[l(1186)]=s&&s[l(1186)]||null;continue}break}}}class Nd extends Kn{constructor(n,s){let l=t;super(n),this.code=s&&s[l(852)]||0,this[l(1642)]=s&&s.reason||"",this[l(811)]=s&&s[l(811)]||!1,this[l(1302)+"nnect"]=s&&s["willReco"+l(1529)]||!1}}class Md extends Kn{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s[l(1271)]||null}}class Bd extends Md{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s.data||null,this.message=s&&s[l(685)]||null}}class zd extends Kn{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s[l(1271)]||null}}function rt(a,{message:n,code:s,error:l}){let u=t;return e[u(790)]!==e[u(790)]?this[u(1168)][u(999)+"ns"]:new Ld(a,{message:n,code:s,error:l})}function ft(a,{code:n,reason:s,wasClean:l,willReconnect:u}){return new Nd(a,{code:n,reason:s,wasClean:l,willReconnect:u})}function Fd(a,{data:n,message:s}){return new Bd(a,{data:n,message:s})}function Ud(a,{data:n}){let s=t,l={YpGft:e[s(1545)]};return e[s(729)](e[s(372)],e[s(959)])?(_0x221990||(_0x12d77d=_0x3e9622[s(943)]().then(_0x3e8a59[s(1257)](_0x3080de,l[s(275)]))),_0x1e6141):new zd(a,{data:n})}function ea(a,{message:n}){return new Pd(a,{message:n})}class Gd{constructor(n,s){let l=t;this.endpoints=n,this.maxRetries=s,this[l(1625)+l(1008)]=0,this["currentE"+l(1251)+"riesCount"]=0}[t(1167)+"pointCon"+t(1629)](){let n=t;this[n(1625)+"ndex"]=0,this[n(1119)+n(1251)+n(1445)+"t"]=0}[t(416)+"es"](){let n=t;this[n(1119)+"ndpointT"+n(1445)+"t"]=0}[t(465)+t(706)+"nt"](){let n=t;return e[n(300)](e.wwJRO,n(399))?this[n(918)+"s"][this["currentI"+n(1008)]]:!!_0x3b71c9?.[n(886)](s=>s[n(441)]===_0x21a036&&s.value===_0x229264)}["getCurre"+t(706)+t(810)+t(782)](){let n=t;return this["currentE"+n(1251)+n(1445)+"t"]}[t(363)+t(605)+"es"](){let n=t;return!!(e[n(1262)](this[n(1625)+"ndex"],this[n(918)+"s"][n(301)])||e[n(1436)](this["currentI"+n(1008)],e[n(413)](this[n(918)+"s"][n(301)],1))&&this["currentE"+n(1251)+n(1445)+"t"]===this.maxRetries)}["checkCurrentEndp"+t(832)+t(1260)+"tries"](){let n=t;return e[n(1587)](this[n(1625)+n(1008)],this[n(918)+"s"][n(301)])?!0:this[n(1119)+n(1251)+"riesCount"]>this.maxRetries}["replaceB"+t(1220)+t(1001)+t(994)+t(1414)](){let n=t;return this[n(1119)+"ndpointT"+n(1445)+"t"]=1,this[n(1625)+"ndex"]++,this[n(918)+"s"][this[n(1625)+n(1008)]]}[t(465)+t(706)+"ntAndUpd"+t(1013)](){let n=t;return this["currentE"+n(1251)+n(1445)+"t"]++,this[n(465)+n(706)+"nt"]()}}let Zn=(e[t(831)](e[t(497)],typeof globalThis)&&e[t(1049)](t(1286),globalThis[t(710)+t(946)][t(1391)])||e[t(427)](t(614)+"d",typeof window)&&e.LGNje(e[t(821)],window[t(710)+"tor"].name))&&e[t(427)](t(614)+"d",typeof document),vn=e[t(1636)](t(614)+"d",typeof globalThis)&&(e[t(884)]===globalThis[t(710)+t(946)][t(1391)]||e.hcRUu===globalThis[t(710)+t(946)][t(1391)])&&e.vbbLv(e.vIhqX,typeof tt),Ur=(e.HrqZX(t(614)+"d",typeof globalThis)&&e.OowNQ(e[t(884)],globalThis[t(710)+t(946)][t(1391)])||e[t(497)]==typeof globalThis||e[t(497)]!=typeof globalThis&&!!globalThis[t(1558)+"Bridge"])&&e[t(593)](t(614)+"d",typeof wx),Gr=e[t(497)]!=typeof globalThis&&(e[t(289)]===globalThis[t(710)+t(946)][t(1391)]||e[t(480)](e[t(1620)],globalThis[t(710)+t(946)].name)||e[t(530)](e[t(1610)],globalThis["construc"+t(946)][t(1391)]))&&e.vIhqX!=typeof self,jx=e[t(497)]!=typeof globalThis&&e[t(871)](e.JGUoJ,globalThis[t(710)+t(946)].name)&&e.VwfZF(t(614)+"d",typeof global)&&e.lGFhW(t(1129),global[t(710)+t(946)][t(1391)])&&e.WfDjP(e.vIhqX,typeof process)&&!!process.version;class ta{constructor(){let n=t;this[n(525)+"rs"]={}}[t(835)](n,...s){let l=t,u=this[l(525)+"rs"][n];if(u)u[l(1566)]()[l(1381)](_=>_.fn[l(1323)](_[l(1334)],s));else if(e[l(789)](e[l(1586)],n)&&!this[l(1297)])if(l(746)===e[l(540)])_0x44812d[l(591)](_0x45fb10,_0x5c944f),_0x6a63bb[l(591)](_0xcef34c,_0x3587a0);else{let _=s.length&&s[0];if(_ instanceof Error)throw _;let v=new Error(e[l(1433)](e.wOwmJ,_?e.NMHtH(e[l(815)](" (",_[l(685)]),")"):""));throw v[l(1623)]=_,_}return this}[t(1596)](n,s){let l=t;if(n===void 0)this._listeners={};else if(e[l(697)](void 0,s))this._listeners[n]=null;else{let u=this[l(525)+"rs"][n];if(u)for(let _=0;e[l(1511)](_,u.length);)e[l(990)](u[_].fn,s)?u[l(285)](_,1):++_}return this}on(n,s,l){let u=t;if(e[u(1125)](e.sqZyJ,e[u(541)])){let _=e[u(1627)](_0x3e2a1b,_0x228ca2,1);_0x55db8d[u(1191)][_]=_0x18cb0d}else return(this[u(525)+"rs"][n]||(this[u(525)+"rs"][n]=[]))[u(1503)]({fn:s,ctx:l||this}),this}}class Hx extends ta{[t(436)+t(1388)+t(846)](n){let s=t;return n[s(1204)]||n.errNo?(s(633)+" "+(n[s(1204)]||"")+s(290)+(n[s(594)]||""))[s(1104)]():JSON.stringify(n)}constructor(n,s,l){let u=t;super(),this[u(1168)]=null,Ur&&wx[u(1122)+u(1202)]&&(this._socket=wx["connectS"+u(1202)]({url:n,protocols:s,header:l,fail:this["_createS"+u(565)+u(1043)].bind(this),success:this[u(1570)+"ocketSuccessHandler"][u(1257)](this)})),vn&&tt["connectS"+u(1202)]&&(this[u(1168)]=tt[u(1122)+u(1202)]({url:n,protocols:s,header:l,fail:this[u(1570)+"ocketFai"+u(1043)][u(1257)](this),success:this[u(1570)+u(1476)+"cessHand"+u(799)][u(1257)](this)}))}[t(1570)+"ocketSuccessHandler"](){let n=t;Promise[n(943)]()[n(538)](()=>{this["_addWsLi"+n(559)]()})}[t(1570)+"ocketFai"+t(1043)](n){let s=t;Promise[s(943)]()[s(538)](()=>{let l=s,u=e[l(1474)](rt,e[l(1586)],{message:this["_formatE"+l(1388)+l(846)](n)});this[l(835)](l(1186),u);let _=e.gEPIb(ft,e[l(557)],{reason:this[l(436)+"rrorMess"+l(846)](n)});this[l(835)](e[l(557)],_)})}[t(1195)+t(559)](){let n=t,s={jjBOX:e[n(951)],OcQPn:function(l,u,_){return e[n(326)](l,u,_)},tcHGY:e.jrwae,NiQuA:function(l,u){return e.hLsBh(l,u)},uSOhd:function(l,u){return e[n(1502)](l,u)},uNQrc:e[n(860)],lzobZ:n(685),MlkKi:e[n(1586)],nAFaO:function(l,u,_){return e[n(619)](l,u,_)}};this[n(1168)][n(1423)](l=>{let u=n;this[u(835)](s[u(550)],s[u(380)](Ud,s[u(550)],{...l,data:l[u(1204)]||""}))}),this._socket.onClose(l=>{let u=n;this[u(835)](s[u(1556)],ft(u(627),{...l}))}),this[n(1168)].onMessage(l=>{let u=n,_={lajgZ:function(v,b){return s.NiQuA(v,b)}};if(s.uSOhd(s[u(828)],u(1156)))return _0x5d10ad|=0,{low:_0x45bac7,high:ccqyQB.lajgZ(_0x1aca4d,31),unsigned:_0x1101f0>=0};this[u(835)](s[u(891)],s[u(380)](Fd,s[u(891)],{...l}))}),this._socket[n(715)](l=>{let u=n;this[u(835)](s[u(1022)],s.nAFaO(rt,s[u(1022)],{...l,message:l[u(1204)]||""}))})}[t(1124)](n){let s=t,l={fEJHF:"error"};if(e.pcbXq(n,Uint8Array)){let u=n[s(1409)][s(1566)](n[s(238)+"et"],e[s(626)](n.byteLength,n[s(238)+"et"]));this[s(1168)]&&this[s(1168)][s(1124)]({data:u,fail:_=>{let v=s;this[v(835)]("error",rt(l[v(976)],{message:this["_formatE"+v(1388)+v(846)](_)}))}})}else this[s(1168)]&&this._socket[s(1124)]({data:n,fail:u=>{let _=s;this[_(835)]("error",e[_(1112)](rt,e.Gvnme,{message:this[_(436)+_(1388)+_(846)](u)}))}})}[t(627)](n,s){let l=t;e.FhggX(e[l(1014)],e[l(777)])?_0x3dbe74.log(_0x88cfcc):this._socket&&this._socket[l(627)]({code:n,reason:s})}["addEvent"+t(1012)](n,s){this.on(n,s)}[t(755)+t(798)+t(1499)](n,s){this[t(1596)](n,s)}get readyState(){let n=t,s={kuCSr:function(l,u){return e[ee(1002)](l,u)},AGpai:function(l,u){return e[ee(1637)](l,u)}};if(e.Wtnuo!==e[n(302)]){let l=_0x38de39[n(235)](qwonXx[n(1375)](_0x5067be,this),_0x449541,..._0x2fb56c);return _0x1e9b72.set(l,_0x3b3eed.sort?_0x909e41[n(808)]():[_0x3abdd7]),qwonXx[n(237)](_0x2cd2a5,l)}else return this[n(1168)][n(660)+"te"]}get binaryType(){let n=t;if(e[n(295)]===e.vqJrK)return this[n(1168)][n(928)+"pe"];{let s=e.kCKMR(_0x276ff0);return e[n(1145)](_0x3ce27b,_0x40e371,s),e[n(489)](_0x1161a6,s)}}set binaryType(n){}get[t(666)](){let n=t;return this._socket[n(666)]}get[t(1154)](){let n=t;return this[n(1168)][n(1154)]}get[t(999)+"ns"](){return this[t(1168)].extensions}get[t(613)+"Amount"](){return 0}}function qx(a,n){let s=t;if(e[s(1502)](s(829),e[s(1562)])){if(e[s(376)](4,_0x47dabe[s(301)])){let l=_0x32b28f[s(1293)+"g"](0,e.lWurA(4,_0x72da9e[s(301)])),u=l.concat(_0x4e044c);_0x122ea2[s(1503)](u)}else _0x30f77b[s(1503)](_0x381caf);_0x16ae03&&(_0x1957b2+=1),_0x9dcf3e+=1,_0x2236d0=!1}else{if(n)return new n(a[s(666)],a[s(1154)]);if(e[s(839)](Ur,vn))return new Hx(a[s(666)],a[s(1154)],a[s(1364)]);if(e[s(1456)](Zn,Gr)&&e[s(961)](e.vIhqX,typeof WebSocket)&&WebSocket)return new WebSocket(a[s(666)],a[s(1154)+"s"])}}function Wx(a){let n=t;if(e[n(371)](e[n(339)],e[n(339)])){let s=e[n(1140)][n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":if(e[n(839)](Zn,Gr)&&e[n(961)](e[n(497)],typeof WebSocket)&&WebSocket)return!0;continue;case"1":if(Ur&&wx[n(1122)+n(1202)])return!0;continue;case"2":if(a)return!0;continue;case"3":if(vn&&tt[n(1122)+"ocket"])return!0;continue;case"4":return!1}break}}else return this[n(1168)][n(928)+"pe"]}function jd(a,n,s){let l=t,u={cDxAE:function(b,p){return e[ee(1078)](b,p)},dOItJ:l(1086)+l(1618)+"ltiple t"+l(248)+l(1396),FCqcQ:function(b,p){return e[l(1581)](b,p)},bPeyX:function(b,p){return b+p}},_=-1;async function v(b){let p=l;return u[p(776)](b,_)?Promise[p(1162)](new Error(u.dOItJ)):(_=b,u[p(885)](b,s[p(301)])?Promise[p(943)]():s[b][p(1257)](a)(n,v[p(1257)](null,u[p(545)](b,1))))}e[l(1548)](v,0)}function Hd(a){let n=t,s=0,l=0;for(let u=0;e[n(670)](u,a[n(301)]);++u)l=a[n(896)+"At"](u),e[n(1485)](l,128)?s+=1:e.ypMeK(l,2048)?s+=2:e.gTQHB(e[n(464)](64512,l),55296)&&e[n(729)](e[n(868)](64512,a[n(896)+"At"](e[n(1572)](u,1))),56320)?(++u,s+=4):s+=3;return s}function qd(a,n,s){let l=t;if(e[l(1373)](e.HpFLC(s,n),1))return"";let u="";for(let _=n;e[l(785)](_,s);)if(e.OhFfi(e[l(288)],e[l(346)]))this[l(819)]=_0x63d855,this[l(287)]=null;else{let v=a[_++];if(e[l(1067)](v,127))u+=String[l(242)+l(796)](v);else if(e.JWZZS(v,192)&&v<224)u+=String[l(242)+l(796)](e[l(1178)](e[l(1489)](31,v),6)|e[l(993)](63,a[_++]));else if(v>=224&&v<240)u+=String[l(242)+"Code"](e[l(1266)](e[l(1429)](e[l(464)](15,v),12),e[l(1429)](63&a[_++],6))|e[l(249)](63,a[_++]));else if(e.sWnFp(v,240)){let b=e.IOCcl(e[l(1416)]((7&v)<<18,e.fNWkz(63&a[_++],12))|e[l(375)](e[l(1259)](63,a[_++]),6),63&a[_++])-65536;u+=String[l(242)+l(796)](e[l(1256)](55296,e[l(711)](b,10))),u+=String[l(242)+l(796)](e.SkxKn(56320,e.gWPZC(1023,b)))}}return u}function na(a,n,s){let l=t,u=s,_,v;for(let b=0;e[l(806)](b,a[l(301)]);++b)_=a.charCodeAt(b),_<128?n[s++]=_:_<2048?(n[s++]=e[l(508)](_,6)|192,n[s++]=e[l(879)](63&_,128)):e[l(1641)](e.Csniy(64512,_),55296)&&e[l(480)](e.Ovlvb(64512,v=a[l(896)+"At"](e[l(895)](b,1))),56320)?(_=e.TIayt(65536,e.myPfO(e[l(764)](1023,_),10))+e[l(687)](1023,v),++b,n[s++]=e[l(1416)](e[l(711)](_,18),240),n[s++]=e[l(508)](_,12)&63|128,n[s++]=e[l(1368)](e[l(1378)](e.BlDYn(_,6),63),128),n[s++]=e[l(751)](e.vLRXP(63,_),128)):(n[s++]=e[l(1221)](e[l(508)](_,12),224),n[s++]=e[l(1266)](e[l(370)](e[l(271)](_,6),63),128),n[s++]=e[l(1520)](e.yuBsa(63,_),128));return e[l(1315)](s,u)}async function Wd(a){let n=t;if(e[n(1587)]("string",typeof a)){let s=new Uint8Array(Hd(a));return na(a,s,0),s}return e[n(1069)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1409)],a[n(238)+"et"],a[n(1453)+"th"])}function $x(a){let n=t;try{return n(367)!=typeof a&&(e.JVJAv(a,ArrayBuffer)||a[n(1409)]&&e[n(1069)](a[n(1409)],ArrayBuffer))||e[n(1152)]!=typeof a?"":(JSON[n(638)](a),e[n(1496)])}catch{return e[n(1152)]==typeof a?e[n(772)]:""}}let Kx=(a,n)=>{let s=t;if(e[s(787)](e[s(973)],e[s(1300)]))switch(a){case e[s(890)]:case e[s(230)]:return{[s(1318)+a]:1,"x-tt-env":n};default:return{}}else Se[s(531)]&&Se[s(531)][s(627)](_0x6de4c5,_0x31854a)};class Zx{constructor(n){let s=t;this[s(491)+s(782)]=n,this[s(1240)]=0}addCount(){let n=t;this[n(1240)]++}[t(363)+t(1196)+"nt"](){let n=t;return e.TVoyG(this.count,this[n(491)+n(782)])}[t(1181)+t(684)](n=0){let s=t;this[s(491)+s(782)]=n,this.count=0}}async function Vx(a){let n=t,s={SPIku:function(l,u){return l(u)},Aiqvg:e[n(1198)],cTwpu:e[n(442)],QpzHA:e[n(1593)],RRbUw:function(l,u){return e[n(657)](l,u)},tZgww:e[n(645)],vrtCP:function(l,u){return e[n(838)](l,u)},wyZGh:e.jTrBK,yLrye:function(l){return e.NeNqn(l)}};if(e[n(1397)](e[n(260)],e[n(260)]))return new Promise(l=>{let u=n,_={hynXU:function(v,b){return s.SPIku(v,b)},nZNXA:u(1536)+u(1642)};if(!Zn)return l(s[u(648)]);try{let v=document[u(1441)+u(291)](s[u(900)]);window[u(1488)+"JSONP"]=b=>{let p=u;document[p(664)][p(1194)+"ild"](v),window[p(1488)+p(1633)]=void 0,_[p(971)](l,b&&b[p(471)]||_.nZNXA)},v[u(819)]=s.QpzHA,v[u(719)]=s[u(1335)](a.replace(/^ws/,s[u(841)]),u(883)+"ack=fron"+u(721)+"P");try{document[u(664)][u(304)+u(708)](v)}catch{document[u(664)]["removeCh"+u(708)](v)}}catch{window[u(1488)+u(1633)]=void 0,l(s[u(648)])}});eAdcWC[n(1056)](_0x2de9c8,_0x3e995d.error||new _0x27937a(eAdcWC[n(1270)],eAdcWC[n(1270)])),eAdcWC[n(1461)](_0x494156)}function Xt(a,n,s){let l=t;return!!a?.[l(886)](u=>u[l(441)]===n&&u[l(1528)]===s)}function Vn(a,n){let s=t;return a?.[s(886)](l=>l.key===n)?.[s(1528)]}let ra=null;async function Jx(){let a=t;return ra||(ra=Promise.resolve().then(Ot[a(1257)](Ot,a(1206)))),ra}class Yx extends ta{constructor(n,s){let l=t;super(),this[l(1139)]=n,this[l(724)]=s,this[l(474)]=void 0,this[l(1490)+l(649)]=null}async[t(259)](){await this[t(763)]()}async _init(){let n=t,s={idOlF:function(l){return e[ee(1431)](l)},kBltD:function(l,u,_,v){return l(u,_,v)}};if(!this._qosDB){if(this["_initPro"+n(649)])return this["_initPro"+n(649)];try{let l=this[n(1139)],u=this._keyPath;this[n(1490)+n(649)]=(async()=>{let _=n,{openDB:v}=await s[_(1361)](Jx);this._qosDB=await s.kBltD(v,"frontier_"+l,1,{upgrade(b){b["createOb"+_(1091)+"e"](l,{keyPath:u})}})})(),await this[n(1490)+n(649)]}catch(l){console[n(947)](l)}finally{this["_initPro"+n(649)]=null}}}async[t(848)](n){let s=t;try{return await this._init(),this._qosDB?.[s(848)](this._dbName,n)}catch(l){console[s(947)](l)}}async set(n,s){let l=t;return await this._init(),this._qosDB?.put(this[l(1139)],n)}async[t(899)](n){let s=t,l={QCwUS:e[s(1444)],sQoOR:function(u,_){return u(_)}};try{if(e[s(983)]!==e[s(983)]){let u=_0x195d0e["deleteDa"+s(1121)](_0x43e979);return _0x196ab6&&u[s(1330)+s(1012)](yXYond[s(476)],()=>_0x334c2e()),yXYond[s(1054)](_0x2204ab,u)[s(538)](()=>{})}else return await this[s(763)](),this._qosDB?.[s(537)](this[s(1139)],n)}catch(u){console[s(947)](u)}}async[t(1174)](){let n=t;if(e[n(243)](n(1128),e[n(1382)]))this[n(937)+n(1130)+n(1337)](_0x42508e),_0x21c640.set(_0x3a389f,_0x2a75ac,_0x2bc900[n(685)][n(1327)]);else try{if(e[n(620)](e[n(754)],e[n(1643)]))return await this._init(),this[n(474)]?.[n(1174)](this[n(1139)]);{let s=e.FRrJj[n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":_0x2767b4=e.dsyzA(e[n(608)](127,_0x32385b[_0x32cfa9]),0);continue;case"1":if(e[n(988)](_0x3e2eee[_0x436500++],128))return{value:_0x219fd6?_0x434a08:e[n(903)](0,_0x356a56),offset:_0x28f1c7};continue;case"2":if(_0xb1b066[_0x453718++]<128)return{value:_0x545f30?_0x306ff4:e[n(1530)](0,_0x25037a),offset:_0x26dbcb};continue;case"3":if(e[n(912)](_0x1edb9a[_0x4e2fb6++],128))return{value:_0x43e207?_0x469f43:0|_0x37d0e1,offset:_0xbf3ffd};continue;case"4":_0xd10bb4=e.UKrgs(e[n(1035)](_0x23e205,e[n(1079)](127&_0x11be0f[_0x91e842],7)),0);continue;case"5":if((_0x1dbdb9+=5)>_0x4830f9[n(301)])throw _0xb4d09d=_0x9fa8be.length,e.xwABW(_0x309e14,_0x1edc6e,10,_0x4b9809[n(301)]);continue;case"6":_0x429c9d=e.dsyzA(_0x1eb1ac|e[n(1278)](e.kNYPF(127,_0x5bf7c1[_0x2520e3]),21),0);continue;case"7":_0x2a2ed7=e.dsyzA(e[n(642)](_0x20a56b,e.fNWkz(e[n(1392)](15,_0xbef3bc[_0x2ee795]),28)),0);continue;case"8":return{value:_0x4b3cc4?_0x31eccb:e[n(239)](0,_0x33d6dd),offset:_0x45edd7};case"9":if(_0xdeab0b[_0x3b341b++]<128)return{value:_0x161243?_0x3cf6e5:0|_0x48d9f7,offset:_0xeaae};continue;case"10":if(e[n(643)](_0x284192[_0x3d3fb3++],128))return{value:_0x3402ea?_0x1fc7c4:e[n(266)](0,_0x100a7a),offset:_0x1c822d};continue;case"11":_0x3e6155=(_0x4670de|e.xYpKS(127,_0x4b1460[_0x12a907])<<14)>>>0;continue}break}}}catch(s){e[n(1317)](e[n(863)],e[n(863)])?(e[n(1072)](_0x52d251,_0x377c73,10),e[n(1233)](_0x34018f,_0x4aeef3,_0x679f4a)):console[n(947)](s)}}async[t(1606)](){let n=t;return await this[n(763)](),this._qosDB?.[n(451)+"ys"](this[n(1139)])}async getAll(){let n=t;return await this[n(763)](),this[n(474)]?.[n(225)](this[n(1139)])}async closeDB(){let n=t;try{this[n(474)]?.[n(627)](),this[n(474)]=void 0}catch(s){console[n(947)](s)}}get[t(738)](){let n=t;try{return!!this[n(474)]}catch(s){return console[n(947)](s),!1}}}class Xx{constructor(n,s){let l=t;this[l(1034)]=n,this[l(420)]=s,this[l(474)]=localStorage}async[t(259)](){}get[t(1268)](){return"frontier_"+this[t(1034)]}async[t(848)](n){let s=t,l={TyTkf:function(u,_){return u(_)}};if(e[s(1377)]!==s(514)){let u=this[s(474)][s(939)](this[s(1268)]);return JSON[s(638)](e[s(1456)](u,"{}"))[n]}else OBLuID.TyTkf(_0x8cc5c2,_0x9e935d.error),_0x28850f()}async[t(591)](n,s){let l=t;if(l(292)===e[l(336)]){let u=this[l(474)].getItem(this[l(1268)]),_=JSON[l(638)](e.hATru(u,"{}"));return _[s||n[this._pathKey]]=n,this._qosDB.setItem(this._prefix,JSON[l(1325)+"y"](_)),s||n[this._pathKey]}else{let u=e.MSYTl(_0x3a5ac1,e[l(1586)],{message:_0x484230[l(685)],code:_0x10b3de.MESSAGE_ERROR,error:_0x41a4d9});this[l(937)+l(1040)+l(364)](u)}}async[t(899)](n){let s=t,l=this[s(474)][s(939)](this[s(1268)]),u=JSON.parse(l||"{}");return u[n]=void 0,this._qosDB.setItem(this[s(1268)],JSON[s(1325)+"y"](u))}async[t(1174)](){return this[t(474)].clear()}async[t(1606)](){let n=t;if(e[n(797)](e[n(978)],n(1508)))return _0x451fff?this[n(603)+"E"]():this[n(1166)+"E"]();{let s=this._qosDB[n(939)](this[n(1268)]),l=JSON[n(638)](e[n(1592)](s,"{}"));return Object[n(1606)](l)}}async[t(225)](){let n=t,s=this._qosDB[n(939)](this[n(1268)]),l=JSON[n(638)](e[n(985)](s,"{}"));return Object[n(587)](l)}closeDB(){let n=t,s={ScKpJ:function(l,u){return e.khdBW(l,u)},RdcYG:function(l,u){return l==u},PSdKY:e.yRtDW,UjyNE:function(l,u){return e[ee(330)](l,u)},pelSZ:e[n(374)]};if(e.ZsuDF(n(1516),n(1516)))return Promise[n(943)]();{let{url:l}=s[n(1634)](_0x57c1b5,{}),u=_0x557daa.isArray(l)?l:s[n(1074)](s[n(893)],typeof l)?[l]:[];_0x1d7562&&_0x4cfb23.assign(this[n(506)],_0x575534),u&&u.length?this[n(1188)+"tManager"]=new _0x2cd93f(u,this._options.maxRetries):this[n(1188)+"tManager"]?.[n(1167)+n(814)+"fig"](),this[n(558)+n(432)]?.["resetCou"+n(684)](this[n(506)][n(475)+n(705)]),this[n(669)+n(602)]=!1,this[n(531)]&&s[n(1230)](this[n(531)][n(660)+"te"],this[n(1085)])?this[n(665)+n(654)](1e3,s[n(737)],!0):(this[n(1360)]=!0,this._connect())}}get[t(738)](){return!!this[t(474)]}}class Qx{constructor(n,s){let l=t;this._DBName=n,this[l(420)]=s,this._qosDB=vn?tt:Ur?wx:null}async[t(259)](){}get[t(1268)](){let n=t;return n(1488)+"_"+this[n(1034)]}async[t(848)](n){let s=t,l=this[s(474)][s(1208)+s(726)](this[s(1268)]);return JSON[s(638)](l||"{}")[n]}async[t(591)](n,s){let l=t,u=this[l(474)].getStorageSync(this[l(1268)]),_=JSON.parse(u||"{}");return _[s||n[this[l(420)]]]=n,this[l(474)][l(949)+"geSync"](this[l(1268)],JSON[l(1325)+"y"](_)),s||n[this[l(420)]]}async[t(899)](n){let s=t,l=this[s(474)][s(1208)+s(726)](this[s(1268)]),u=JSON.parse(e[s(1456)](l,"{}"));return u[n]=void 0,this[s(474)][s(949)+s(726)](this[s(1268)],JSON[s(1325)+"y"](u))}async clear(){let n=t;return this[n(474)][n(714)+n(1509)]()}async keys(){let n=t,s=this._qosDB[n(1208)+"geInfoSync"](this[n(1268)]),l=JSON[n(638)](e[n(468)](s,"{}"));return Object[n(1606)](l)}async[t(225)](){let n=t;if(e[n(697)](n(501),e.jZhCA)){let s=this[n(474)]["getStora"+n(595)+"nc"](this._prefix),l=JSON.parse(e.jxquP(s,"{}"));return Object.values(l)}else{if(!this[n(531)])return;this[n(1212)+n(1369)+"t"](_0x8b2389,_0x2364ab,_0x425757)}}[t(1254)](){return Promise.resolve()}get[t(738)](){return!!this[t(474)]}}function $d(a,n){let s=t;if(e.xycTs(vn,vn))return new Qx(a,n);if((Zn||Gr)&&e[s(1636)](e[s(497)],typeof indexedDB))return new Yx(a,n);if(e.UJHLZ(Zn,Gr)&&s(614)+"d"!=typeof localStorage)return new Xx(a,n);throw new Error(e[s(1469)])}class ep{constructor(){let n=t;this[n(352)+"lTimeoutId"]=null,this._interval=36e5,this._qosDB=e[n(1316)]($d,e.wAODF,e[n(340)])}async["_interva"+t(1424)](){let n=t;e.UQLeH(clearInterval,this._intervalTimeoutId),this[n(352)+n(1094)+"Id"]=e[n(1289)](setInterval,()=>{let s=n;this[s(1457)+s(693)]()},this._interval)}async[t(259)](){let n=t;await this._qosDB.openDB()[n(538)](()=>{this[n(352)+"lFlush"]()})}async["flushExp"+t(693)](){let n=t;(await this[n(474)]?.getAll()||[])[n(1543)](({timestamp:u})=>u<Date.now())[n(1381)](u=>{let _=n;this[_(474)]?.[_(899)](u[_(1228)+"id"])})}async[t(899)](n){let s=t;return this._qosDB?.[s(899)](n)}async[t(591)](n,s){let l=t;return this[l(474)]?.[l(591)]({message_id:n,timestamp:s})}async[t(848)](n){let s=t;return this[s(474)]?.[s(848)](n)}async[t(1254)](){let n=t;e[n(727)](clearInterval,this[n(352)+n(1094)+"Id"]),await this[n(474)]?.[n(1254)]()}get isReady(){let n=t,s={PfjMX:function(l,u){return e[ee(839)](l,u)},LfTIt:function(l,u){return e.urIcN(l,u)},muigv:function(l,u){return e[ee(831)](l,u)},TROXa:e[n(497)]};if(e[n(300)](e.RHSZY,e[n(1068)]))return this[n(474)]?.[n(738)];if(_0x515762)return new _0x19e855(_0x5d513a[n(666)],_0xc757bd[n(1154)]);if(wWeGnK[n(1588)](_0x13bccd,_0x3b79ab))return new _0x2e3deb(_0x10255a[n(666)],_0x1fba96[n(1154)],_0x1f9fde[n(1364)]);if(wWeGnK.LfTIt(_0x163b86,_0x586b31)&&wWeGnK[n(1567)](wWeGnK[n(997)],typeof _0x53c878)&&_0x24ea09)return new _0x3e3bf1(_0x355798[n(666)],_0x292bba[n(1154)+"s"])}}function ia(a){let n=t,s=!!this[n(506)][n(601)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=Xt(a[n(685)][n(1364)],n(1283)+n(407),"2"),u=l&&e.tPVQb(Xt,a.message[n(1364)],e[n(519)],"1"),_=l&&e[n(702)](Xt,a[n(685)][n(1364)],e[n(314)],"1"),v=_?e.ItqTI(Vn,a[n(685)][n(1364)],e[n(840)])?.[n(387)](",")[n(1543)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:u,isAckCleanupMessage:_,ackMsgIds:v}}async function Kd(){let a=t;return this._QoSManager||(this["_QoSMana"+a(411)]=new ep),this[a(445)+"ger"][a(738)]||await this["_QoSMana"+a(411)][a(259)](),this[a(445)+a(411)]}async function tp(a,n){let s=t,{enableAutoAck:l}=this[s(506)],u=e.pbomt(Xt,a[s(685)][s(1364)],e.dYLMR,"1"),_=e[s(702)](Xt,a[s(685)][s(1364)],e.aYBYE,"1"),v=ia[s(235)](this,a);if(e[s(921)](l,u)){let{SeqID:b,LogID:p,service:k,LogIDNew:B,method:z}=a[s(685)];this[s(902)]({SeqID:b,LogID:p,LogIDNew:B,service:k,method:z,headers:[{key:e[s(612)],value:"1"},{key:"ack_id",value:B||""},{key:e.AwQiW,value:"0"}]})}_&&!v[s(856)]&&this[s(937)+s(321)+s(1055)](a),e[s(1095)](n)}async function np(a,n){let s=t;this[s(303)](s(353),a[s(685)]),e[s(1095)](n)}async function rp(a,n){let s=t,l=Vt(await e[s(682)](Wd,a[s(1271)]));try{if(e[s(1069)](l[s(659)],Uint8Array)){let u=e[s(1100)](this[s(506)]["payloadE"+s(350)],Object)?{force:!!this[s(506)]["payloadE"+s(350)][s(1058)],encoding:this[s(506)][s(979)+"ncoding"][s(341)]?this._options[s(979)+s(350)].encoding[s(398)](/\s/g,"")[s(1565)+s(1348)]():""}:{force:!1,encoding:this[s(506)][s(979)+s(350)]?this[s(506)].payloadEncoding[s(398)](/\s/g,"")[s(1565)+"ase"]():""},_=l[s(979)+s(350)]?l.payloadEncoding.replace(/\s/g,"")[s(1565)+"ase"]():"",v=e[s(1062)](this._options[s(518)+s(1517)],Object)?{force:!!this[s(506)][s(518)+s(1517)][s(1058)],type:this[s(506)][s(518)+"ype"].type?this._options["payloadT"+s(1517)][s(819)][s(398)](/\s/g,"")[s(1565)+s(1348)]():""}:{force:!1,type:this[s(506)].payloadType?this._options[s(518)+"ype"][s(398)](/\s/g,"")[s(1565)+"ase"]():""},b=l["payloadT"+s(1517)]?l[s(518)+"ype"][s(398)](/\s/g,"")["toLowerC"+s(1348)]():"",p=v[s(1058)]?v.type:b||v.type,k=u[s(1058)]?u.encoding:_||u.encoding,B=[e[s(772)],e[s(1496)],e[s(699)],e[s(1152)]],z=[e[s(1427)],e[s(311)]];this[s(506)]["enableTransformT"+s(823)+"ad"]&&B[s(1579)](p)&&(!k||z[s(1579)](k))?l[s(878)+s(507)]=qd(l[s(659)],0,l[s(659)].byteLength):l[s(878)+s(507)]=""}else l[s(878)+s(507)]=""}catch(u){l[s(878)+s(507)]="",console[s(947)](u)}a[s(685)]=l,e[s(1023)](n)}function ip(a,n,s){let l=s||8192,u=l>>>1,_=null,v=l;return function(b){let p=ee;if(e[p(1020)](b,1)||e[p(1458)](b,u))return a(b);e.NdlOy(v,b)>l&&(_=e[p(1231)](a,l),v=0);let k=n.call(_,v,v+=b);return 7&v&&(v=e[p(1324)](e[p(1341)](7,v),1)),k}}let sp=4294967295;function op(a,n,s){let l=t;return e.DMZml(RangeError,e[l(406)](e.Rcljb(e[l(1628)](e.snrfS(e[l(926)](e[l(825)],a),l(683)),e[l(281)](n,1)),l(679)),s))}function ap(a,n,s){let l=t;if(s>sp)throw new Error(e[l(1219)]);let u=3;for(;e[l(404)](u,0);){let _=e.tuvpX(255,s);e[l(1331)](oa,_,a,e[l(1179)](n,u)),s>>>=8,u--}return n+4}function cp(a,n){let s=t,l=0,u=n,_=n+4;for(;e[s(912)](u,_);){let{value:v,offset:b}=e.KMdsV(sa,a,u);u=b,l=e[s(1611)](e.AownE(l,8),0),l+=v}return{value:l,offset:_}}function dp(a,n,s){let l=t;return a?e[l(662)](a[l(301)],40)?e[l(576)](e.TdxSb(na,a,n,s),s):n[l(766)+"e"]?e.NMHtH(n[l(766)+"e"](a,s),s):n[l(888)]?n[l(888)](a,s)+s:e[l(576)](na(a,n,s),s):s}function lp(a,n){let s=t;if(e[s(762)](s(568),e[s(1088)]))e.LMIBs(_0x5bee3a,s(390)),this[s(1596)](e[s(1551)],_0x403199),this[s(1596)](s(1224)+s(817)+"t",_0x2e5ef2);else{let l=new ce(e[s(1033)](e[s(482)](e.DSXzN(e[s(257)](a[e[s(639)](n,4)],24),a[n+5]<<16),e[s(1404)](a[e[s(1041)](n,6)],8)),a[e[s(1578)](n,7)]),e[s(1519)](e[s(1164)](e[s(1164)](a[e.FptpX(n,0)]<<24,e[s(257)](a[e.NRRis(n,1)],16)),a[n+2]<<8),a[n+3]),!0);return n+=8,{value:l,offset:e.GYzAd(n,8)}}}function fp(a,n,s){let l=t,u=a.low,_=a[l(759)];return n[s]=e[l(1248)](_,24),n[e.Japtg(s,1)]=e[l(998)](_>>>16,255),n[s+2]=e[l(913)](e[l(875)](_,8),255),n[e.fmIAX(s,3)]=e.adhmB(255,_),n[e[l(1301)](s,4)]=e.lDzIg(u,24),n[e.NdlOy(s,5)]=e[l(351)](e[l(1466)](u,16),255),n[s+6]=e[l(1019)](u,8)&255,n[s+7]=255&u,s+=8,s}function sa(a,n){let s=t;return a[s(1473)+"8"]?{value:a[s(1473)+"8"](n),offset:e[s(394)](n,1)}:{value:e[s(429)](255,a[n]),offset:e.xKBQV(n,1)}}function oa(a,n,s){let l=t;if(e[l(1051)]("snRCk",e[l(922)]))return n[l(991)+"t8"]?n.writeUint8(a,s):n[s]=e[l(265)](255,a),e[l(394)](s,1);{let u=_0x4f790f[l(387)](/\./).map(b=>_0x596d87(b)),_=[];return _[0]=e[l(901)](_0x541fa6,e[l(299)](u[0],u[1])),_[1]=e[l(331)](_0x26f76a,e.huWau(u[2],u[3])),[e[l(1537)],l(1448),e[l(1537)],e[l(1537)],e.OFgrR,e[l(1103)],_[0],_[1]][l(1030)]("")}}let up=function(a){return new Uint8Array(a)},hp=e[t(1386)](t(614)+"d",typeof Buffer)?Buffer[t(1574)+t(1061)]:e[t(382)](ip,up,Uint8Array[t(1201)+"e"].subarray);(()=>{let a=t,n={sipEV:"8|0|9|5|"+a(1016)+"|6|11|3|4",SuVPR:function(l,u){return e[a(1485)](l,u)},AAXXU:function(l,u){return e[a(751)](l,u)},colSs:function(l,u){return l|u},MdxDS:function(l,u){return e[a(319)](l,u)},OfkyH:function(l,u){return e.FbPgO(l,u)},fPKff:function(l,u){return e[a(1278)](l,u)},lNfyl:function(l,u){return e[a(877)](l,u)},TfAgh:function(l,u,_,v){return l(u,_,v)},YwVzB:function(l,u){return e[a(826)](l,u)},MRTUE:function(l,u){return e[a(972)](l,u)},xfUaX:function(l,u){return e[a(1495)](l,u)},kCvgu:function(l,u){return e[a(228)](l,u)},gOITU:function(l,u){return e[a(233)](l,u)},ELLcd:function(l,u){return l<<u},Psdnb:function(l,u){return e[a(323)](l,u)},PUfSc:function(l,u){return e[a(1417)](l,u)}},s=4294967295;return function(l,u,_=!0){let v=a,b=n[v(986)][v(387)]("|"),p=0;for(;;){switch(b[p++]){case"0":if(n[v(897)](l[u++],128))return{value:_?s:n[v(1151)](0,s),offset:u};continue;case"1":s=n[v(1524)](s,n[v(744)](127,l[u])<<21)>>>0;continue;case"2":s=n.OfkyH(n[v(1524)](s,n[v(941)](n[v(744)](127,l[u]),14)),0);continue;case"3":if(n[v(345)](u+=5,l.length))throw u=l.length,n.TfAgh(op,u,10,l[v(301)]);continue;case"4":return{value:_?s:n.YwVzB(0,s),offset:u};case"5":if(n[v(1531)](l[u++],128))return{value:_?s:n[v(1151)](0,s),offset:u};continue;case"6":s=n[v(1199)](s|n[v(744)](15,l[u])<<28,0);continue;case"7":if(l[u++]<128)return{value:_?s:n[v(1524)](0,s),offset:u};continue;case"8":s=n[v(1199)](n.kCvgu(127,l[u]),0);continue;case"9":s=n[v(490)](n[v(743)](s,n[v(1110)](127&l[u],7)),0);continue;case"10":if(n[v(338)](l[u++],128))return{value:_?s:n.PUfSc(0,s),offset:u};continue;case"11":if(n[v(338)](l[u++],128))return{value:_?s:0|s,offset:u};continue}break}}})();let xp=16,aa=32;function pp(a){let n=t,s=0,l={};for(let u=0;u<a[n(301)];u++)l[a[u][n(262)+n(1165)]]=e[n(682)](Hd,a[u][n(262)+n(1165)]),s+=e[n(622)](14,l[a[u][n(262)+n(1165)]]);return[s,l]}function Zd(a,n,s){let l=t,[u,_]=e[l(892)](pp,a),v=e[l(1366)](hp,u),b=0;return a[l(1381)](p=>{let k=l,B=(k(1032)+k(1440)+"|6|5|3")[k(387)]("|"),z=0;for(;;){switch(B[z++]){case"0":b=e.yqtjX(ap,v,b,p.service||0);continue;case"1":console.log(e[k(607)],b);continue;case"2":b=e[k(1203)](dp,p[k(262)+k(1165)],v,b);continue;case"3":console[k(947)](e[k(753)],b);continue;case"4":console[k(947)](e[k(962)],b);continue;case"5":b=e[k(481)](fp,ce.fromNumber(p[k(984)]||n),v,b);continue;case"6":console[k(947)](e[k(1037)],b);continue;case"7":b=oa(_[p[k(262)+k(1165)]],v,b);continue;case"8":console.log(e[k(1470)],p,p[k(1327)]);continue;case"9":console[k(947)](e[k(1608)],b);continue;case"10":b=e[k(882)](oa,0,v,b);continue}break}}),{frameType:aa,headers:[{key:e[l(1080)],value:s}],payload:v}}function gp(a){let n=t,s=0,l=[];for(;e[n(1306)](s,a.byteLength);)if(e.ooGiA!==e.ooGiA)_0x2b75af[n(947)](_0x27c59d);else{let{offset:u}=e[n(1003)](sa,a,s);s=u;let _={cursor_name:"",cursor:0,service:0},{value:v,offset:b}=e[n(619)](cp,a,s);_.service=v,s=b;let{value:p,offset:k}=e[n(388)](sa,a,s);s=k,_[n(262)+n(1165)]=qd(a,s,e[n(414)](s,p)),s+=p;let{value:B,offset:z}=lp(a,s);_[n(984)]=B.toNumber(),s=z,l.push(_)}return l}function mp(){return{frameType:aa,headers:[{key:e.ASurn,value:e.tpcuC}],payload:void 0}}class wp{constructor(n,s,l){let u=t;this[u(461)+u(1371)]=n,this["_cursorF"+u(494)]=s,this[u(1640)+u(795)]=l,this[u(474)]=$d(this[u(461)+u(1371)],u(262)+"ame")}async openDB(){let n=t;await this[n(474)][n(259)]()}async[t(859)+"rs"](){let n=t;if(!this._qosDB[n(738)])return;let s=this[n(1640)+n(795)],l=await this[n(474)].getAll();switch(console[n(947)](e[n(439)],l),s){case e[n(577)]:return l&&l.length?e.pbomt(Zd,l,0,this[n(1332)+"ileName"]):void 0;case e[n(1329)]:return;case"CONTINUE":return l&&l.length?e[n(1413)](Zd,l,0,this[n(1332)+n(494)]):mp()}}async[t(591)](n,s,l){let u=t;if(e[u(1438)](e[u(280)],e[u(834)]))return console[u(947)](e[u(864)],n,s,l),this[u(474)][u(591)]({cursor_name:n,cursor:s,service:l});vOqfzw.YJdpb(_0x4aa7fc,vOqfzw[u(682)](_0x4df379,_0x3c4ebe[u(443)])),_0xea20a2()}async[t(676)+"rs"](n){let s=t,l=e[s(263)](gp,n);for(let u of l)e[s(332)](s(1624),e[s(969)])?(this[s(1148)+s(1387)+s(434)]=_0x2a122b,_0x5abf3f?this[s(1352)+s(444)]():this._handleOffLine()):(console.log(e[s(1226)],l),await this[s(474)][s(591)](u))}async[t(848)](n){let s=t;return(await this._qosDB.get(n))?.[s(984)]}async closeDB(){let n=t;await this[n(474)][n(1254)]()}[t(923)+"rsorFile"+t(1402)](n){let s=t;this[s(1332)+"ileName"]=n}get[t(738)](){return this[t(474)].isReady}}let yp=e[t(1451)];async function Vd(a){let n=t;if(!this[n(506)][n(601)+"S"])return null;let{aID:s,fpID:l,messageStrategy:u}=this._options,_=e.slKeR(a,yp);try{return this[n(571)+n(905)]?a&&this["_cursorM"+n(905)][n(923)+"rsorFileName"](a):this[n(571)+n(905)]=new wp(l+"_"+s+"_"+_,_,u),this[n(571)+n(905)][n(738)]||await this[n(571)+"anager"][n(259)](),this[n(571)+n(905)]}catch{return null}}async function _p(a,n){let s=t,l={QtokL:function(u,_,v,b,p){return u(_,v,b,p)}};if(e[s(522)](s(1287),e.WvZBg)){let u=e[s(481)](Xt,a[s(685)][s(1364)],e[s(327)],"-1"),_=e.pbomt(Xt,a[s(685)][s(1364)],s(1163),"1"),v=e[s(1450)](Vn,a[s(685)][s(1364)],e[s(556)]),b=Number(Vn(a.message[s(1364)],s(1283)+s(268)))||0,p=ia[s(235)](this,a),k=e[s(546)](Xt,a[s(685)].headers,s(1535)+"s","2"),B=Vn(a[s(685)].headers,"x-msg-cu"+s(1428)+"e"),z=e[s(448)](Number,e[s(932)](Vn,a.message[s(1364)],s(847)+s(386)+"ue"));if(p[s(856)])return n();let U=p[s(590)+s(592)]?await Kd[s(235)](this):null;if(a[s(685)][s(1327)]>0&&_&&!u||a[s(685)][s(1327)]>0){if(v&&p[s(590)+s(592)]&&U)return!!!await U[s(848)](v)&&(this[s(937)+s(1130)+"Event"](a),await U[s(591)](v,Date[s(812)]()+b)),e[s(477)](n);if(k){let H=await Vd[s(235)](this);if(!H)return this[s(937)+s(1130)+s(1337)](a),n();let V=await H[s(848)](B)??-1;if(V<z)if(e[s(244)]!==e[s(1491)])this[s(937)+"hMessageEvent"](a),H[s(591)](B,z,a[s(685)].service);else return null;else throw new Error(s(1434)+s(524)+s(722)+z+(s(1455)+s(572)+s(1439)+"r ")+V);return e[s(881)](n)}return this[s(937)+"hMessage"+s(1337)](a),e[s(1092)](n)}}else vVvxGc[s(735)](_0x58169a,_0x2d94d0(_0x52ac9e[s(443)]),_0x59f7da[s(750)+"on"],_0x79c338[s(1004)+"on"],_0x28f79e(_0xb1684f[s(1183)+s(1398)]))}async function Ep(a,n){let s=t,l=ia.call(this,a);if(!l[s(590)+s(592)])return e[s(1358)](n);let u=await Kd[s(235)](this);if(l[s(1599)+s(1135)+s(846)]&&l.ackMsgIds[s(301)])for(let _ of l.ackMsgIds)await u[s(899)](_);e.xTGdb(n)}async function bp(a,n){let s=t,l=a[s(685)][s(1118)+"e"]===xp,u=e[s(1547)](a.message[s(1118)+"e"],aa);if(!l&&!u)return n();let _=e[s(1571)](Vn,a[s(685)][s(1364)],e[s(1080)]);if(!_)return n();let v=await Vd[s(235)](this,_);if(!v)return e[s(1431)](n);if(l){let b=await v[s(859)+"rs"](),p={frameType:b?.[s(1118)+"e"],SeqID:ce[s(479)+"er"](this[s(1060)]++),LogID:ce[s(479)+"er"](this[s(506)][s(583)+s(250)]()),service:9e3,method:5,headers:b?.headers,payload:b?.[s(659)]},k=A(p);this[s(531)]&&this[s(531)][s(660)+"te"]&&this[s(531)][s(1124)](k)}if(u){let b=a[s(685)][s(659)];b&&v.setCursors(b)}}let vp=async function(a,n){let s=t;this._isInit=!1,e[s(1243)](clearTimeout,this[s(805)+"ionTimeo"+s(757)]),e.OBHBx(n)},Sp=async function(a,n){let s=t;if(!this[s(531)]||e[s(1050)](this[s(531)][s(660)+"te"],this[s(1309)]))return e[s(1241)](n);let{pingInterval:l}=this[s(506)];this[s(1188)+s(456)]?.[s(1167)+s(814)+s(1629)]();for(let _=0;e.wzEOf(_,this[s(1640)+"Queue"][s(301)]);_++){let v=this[s(1640)+s(510)][_];if(this[s(531)].readyState===this[s(1309)]&&v!==null)this[s(531)]&&this._ws[s(1124)](v),this[s(1640)+s(510)][_]=null;else break}this[s(1640)+"Queue"]=this[s(1640)+s(510)][s(1543)](_=>!!_),this["_pingPon"+s(428)+"Id"]=e[s(1605)](setTimeout,()=>this[s(1533)](),l),this[s(937)+s(915)+"nt"](a),this[s(1211)+"er"]&&this._ws&&(this[s(531)][s(928)+"pe"]=this[s(1111)+s(1517)]);let u=this[s(1188)+"tManager"]?.["getCurre"+s(706)+"nt"]();this[s(303)]("open "+u+s(1319)),e[s(252)](n)},Ip=async function(a,n){let s=t,l=this[s(1188)+s(456)]?.["getCurre"+s(706)+"nt"]();this[s(303)](s(1467)+l),e.OBHBx(n)};class Ap extends ta{constructor(n){let s=t,l={HpQxZ:function(b,p,k){return e[ee(544)](b,p,k)},dnTOv:function(b,p){return e.PGyBl(b,p)},zzIyp:e[s(557)],nRkMn:e.MRkmq,oAChE:function(b,p){return e[s(1419)](b,p)},hDFlo:function(b,p){return e[s(500)](b,p)},Yoceg:s(1186),hkVgy:function(b,p){return b!==p}};super(),this[s(1148)+s(1387)+"line"]=!0,this[s(1211)+"er"]=Zn,this[s(1307)]=jx,this._isMiniTT=vn,this[s(1143)+"X"]=Ur,this[s(1527)+"r"]=Gr,this[s(1640)+s(510)]=[],this[s(1188)+"tManager"]=null,this[s(669)+s(602)]=!1,this[s(1111)+"ype"]=e[s(547)],this["_connect"+s(646)]=!1,this._connectionTimeoutId=null,this[s(1462)+s(1073)+s(373)]=null,this[s(720)+s(428)+"Id"]=null,this._seqId=0,this[s(1360)]=!1,this[s(585)]="",this[s(445)+s(411)]=null,this[s(571)+s(905)]=null,this[s(558)+s(432)]=null,this._protocols=e[s(644)],this.CLOSED=3,this[s(315)+"NG"]=0,this[s(1309)]=1,this[s(736)]=2,this[s(473)]=b=>{let p=s,k={EfgUD:e[p(1152)],WBPcz:function(z,U){return e[p(1100)](z,U)},ThsDw:e.Wqdoo};if(p(894)!==e[p(1063)])try{if(e[p(1146)](p(574),p(1561)))e.cAtOx(jd,this,b,[vp,Sp,Ip]);else for(var B in _0x192430)_0x15684b.o(_0x2f0c18,B)&&!_0x460309.o(_0x1bed93,B)&&_0x5871e4[p(681)+p(1281)](_0xdfc01,B,{enumerable:!0,get:_0x43b6be[B]})}catch(z){let U=e[p(1605)](rt,e[p(1586)],{message:z[p(685)],code:Yt[p(804)+"OR"],error:z});this[p(937)+p(1040)+"ent"](U)}else return sVksSO[p(1261)]!=typeof _0x49e875&&(sVksSO[p(240)](_0x514385,_0x1151eb)||_0x434dd2.buffer&&_0x25a48d[p(1409)]instanceof _0x1893be)||sVksSO[p(1261)]!=typeof _0x49c492?"":(_0x1605c5.parse(_0x368597),sVksSO[p(539)])},this[s(528)+"ge"]=async b=>{let p=s,k={axnfO:function(U,H){return e[ee(513)](U,H)},JIWia:function(U,H){return U<=H},yhxxO:function(U,H){return U-H},elVKq:function(U,H){return e[ee(1585)](U,H)},tOAds:function(U,H){return U<<H},rRaCG:function(U,H){return e[ee(455)](U,H)}},{pingInterval:B,pingFrequency:z}=this[p(506)];if((e[p(1024)]("hi",b[p(1271)])&&e[p(789)]("always",z)||e[p(534)]===z)&&(this[p(1591)+p(1322)](),this[p(835)](e[p(1551)],e.jhytV),this[p(720)+p(428)+"Id"]=setTimeout(this[p(1533)].bind(this),B)),!e[p(1215)]("hi",b[p(1271)]))try{e[p(343)]!=="glxIY"?e[p(546)](jd,this,b,[rp,tp,Ep,bp,_p,np]):(this[p(1034)]=_0xb9c572,this[p(420)]=_0x5283db,this._qosDB=_0x40b661)}catch(U){if(e[p(1501)]!==e[p(1501)]){let H=_0x4c7a93[p(896)+"At"](_0x233e7d);GPclim[p(784)](H,55296)&&GPclim[p(1010)](H,56319)&&_0x104d8c+1<_0x5c6c69&&(H=GPclim[p(1303)](GPclim.elVKq(GPclim.tOAds(H,10),_0x2b7d8f[p(896)+"At"](++_0x51debd)),56613888)),_0x3e9c1f+=H<128?1:GPclim[p(774)](H,2048)?2:GPclim[p(774)](H,65536)?3:4}else{let H=rt(e[p(1586)],{message:U.message,code:Yt[p(1e3)+p(606)],error:U});this[p(937)+p(1040)+p(364)](H)}}},this[s(598)]=b=>{let p=s,k={dqRoD:function(B,z,U){return e[ee(977)](B,z,U)},Xbrdk:e[p(931)],TQLeX:"stop imm"+p(325)+p(1029)+"ct"};if(e.OHnub(p(472),e[p(1617)])){this[p(1212)+p(1369)+"t"]();let B=k[p(1477)](_0x4e9d55,k[p(655)],{message:k[p(1363)]});this[p(368)+p(1582)+p(1512)+"ct"]&&this["onStopIm"+p(1582)+p(1512)+"ct"](B)}else{let B=this[p(1188)+p(456)]?.[p(363)+p(605)+"es"](),z=this[p(1188)+p(456)]?.[p(465)+"ntEndpoint"]();if(B&&!b[p(685)]){let U=p(1380)+z+(" fail, max retri"+p(1277)+"ed");this[p(937)+p(1040)+p(364)](e[p(1630)](rt,p(1186),{message:U,code:Yt[p(1267)+p(1313)+"R"],error:b}));return}this[p(531)]&&e[p(1197)](this[p(531)][p(660)+"te"],this.OPEN)&&this[p(665)+p(654)](),this[p(937)+"hErrorEvent"](rt(e[p(1586)],{message:b[p(685)],code:Yt[p(1507)+p(278)],error:b}))}},this._onClose=async b=>{let p=s;this._clearTimer(),this[p(1591)+p(1322)](),this[p(604)+p(1555)+"rs"](),this[p(531)]=null,this["_connect"+p(646)]=!1;let k=this[p(1188)+"tManager"]?.["checkRea"+p(605)+"es"]();if(!k&&this["_navigat"+p(1077)]()&&!this[p(669)+p(602)]){let B=this._endpointManager?.[p(465)+"ntEndpoint"](),z=this[p(506)][p(673)+p(554)+p(1452)](b[p(852)],b[p(1642)]);this[p(937)+p(520)+p(364)](l.HpQxZ(ft,p(627),{code:1006,reason:b[p(1642)]||p(704)+p(1114)+p(1418)+"wn reaso"+p(450)+p(1639)+B,willReconnect:z})),z&&this._connect();return}if(l[p(1039)](1e3,b[p(852)])&&this[p(669)+p(602)]){this[p(937)+p(520)+"ent"](ft(l.zzIyp,{code:1e3,reason:l[p(460)]})),this[p(1188)+p(456)]?.[p(1167)+p(814)+p(1629)](),this[p(558)+p(432)]?.[p(1181)+p(684)]();return}if(l[p(1540)](1e3,b.code)&&k){let B=this[p(1188)+"tManager"]?.[p(465)+p(706)+"nt"](),z=b.reason;z||(z=await l[p(1249)](Vx,this[p(585)])),z=p(704)+p(1114)+p(227)+z+(p(1359)+p(713))+B+(p(1321)+p(734)+"ached"),this[p(937)+p(520)+"ent"](ft(l[p(1410)],{code:b[p(852)],reason:z}));let U=p(1380)+B+(p(1521)+p(1569)+p(1277)+"ed");this[p(937)+p(1040)+p(364)](rt(l[p(887)],{message:U,code:Yt[p(1267)+p(1313)+"R"]})),this[p(1188)+p(456)]?.["resetEnd"+p(814)+p(1629)](),this[p(558)+"sCounter"]?.[p(1181)+p(684)]();return}if(l[p(672)](1e3,b[p(852)])&&!b[p(1642)]){let B=this[p(1188)+p(456)]?.[p(465)+p(706)+"nt"]();this[p(937)+p(520)+p(364)](l[p(1064)](ft,l.zzIyp,{code:b.code,reason:"connecti"+p(1114)+"d, unkno"+p(1147)+p(450)+"ame: "+B})),this[p(1188)+p(456)]?.[p(1167)+p(814)+p(1629)](),this[p(558)+p(432)]?.[p(1181)+p(684)]();return}this[p(937)+"hCloseEv"+p(364)](b),this[p(1188)+p(456)]?.[p(1167)+p(814)+"fig"](),this["_pingLos"+p(432)]?.[p(1181)+p(684)]()},this[s(1314)]=null,this[s(1297)]=null,this[s(349)+"e"]=null,this[s(269)]=null,this[s(1265)+s(395)]=null,this[s(526)+"eAck"]=null,this[s(368)+"mediatel"+s(1512)+"ct"]=null,this[s(1352)+s(444)]=this[s(1352)+"nLine"].bind(this),this[s(1352)+s(1638)]=this[s(1352)+s(1638)][s(1257)](this),this[s(1615)+"ageHide"]=this[s(1615)+s(1333)][s(1257)](this),this[s(1615)+s(418)]=this[s(1615)+s(418)][s(1257)](this),this[s(506)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1463)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(1372),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(703)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:u,ws:_}=n,v=Array[s(1619)](u)?u:e[s(1152)]==typeof u?[u]:[];if(!v||v[s(301)]===0)throw new Error(e[s(417)]);if(!e[s(448)](Wx,_))throw new Error(e[s(778)]);Object.assign(this[s(506)],n),this[s(1188)+s(456)]=new Gd(v,this[s(506)].maxRetries),this[s(558)+"sCounter"]=new Zx(this[s(506)]["pingLoss"+s(705)]),this._options[s(745)+s(761)]&&(this[s(1360)]=!0,this[s(805)]()),this._options[s(1235)+s(698)+"nged"]&&(this[s(843)+"T"]||this[s(1143)+"X"]?this[s(1563)+s(995)+s(1454)]():this[s(1211)+"er"]&&this["_initGlobalEvent"+s(1012)]())}[t(1352)+t(444)](){let n=t;this[n(506)]["disableA"+n(553)+n(1076)]||this[n(669)+n(602)]||this[n(1430)+n(395)]()}[t(1352)+t(1638)](){let n=t;this[n(1212)+n(1369)+"t"]();let s=e[n(308)](ea,n(673)+"t",{message:e[n(437)]});this[n(368)+n(1582)+n(1512)+"ct"]&&this[n(368)+"mediatel"+n(1512)+"ct"](s)}["_initGlo"+t(286)+t(1012)](){let n=t;this._isBrowser&&window[n(1330)+"Listener"](e.LItne,this[n(1352)+n(444)]),this._isBrowser&&window[n(1330)+n(1012)](e[n(1097)],this[n(1352)+n(1638)]),this[n(1211)+"er"]&&window[n(1330)+"Listener"](e[n(1291)],this[n(1615)+n(1333)]),this[n(1211)+"er"]&&window[n(1330)+n(1012)](e[n(689)],this[n(1615)+n(418)])}["_dropGlo"+t(286)+"Listener"](){let n=t;this._isBrowser&&window[n(755)+n(798)+n(1499)](e.LItne,this[n(1352)+"nLine"]),this[n(1211)+"er"]&&window[n(755)+n(798)+n(1499)](n(446),this[n(1352)+n(1638)]),this[n(1211)+"er"]&&window[n(755)+"entListe"+n(1499)](e.EMGzL,this[n(1615)+"ageHide"]),this[n(1211)+"er"]&&window[n(755)+n(798)+n(1499)](e.yRFxg,this[n(1615)+"ageShow"])}[t(1615)+t(1333)](n){let s=t;!n[s(914)+"d"]&&(this[s(1211)+"er"]&&window[s(755)+s(798)+s(1499)]("pagehide",this[s(1615)+"ageHide"]),this[s(1211)+"er"]&&window["removeEv"+s(798)+s(1499)](s(958),this[s(1615)+s(418)]),this.close()),this[s(1211)+"er"]&&window[s(755)+"entListe"+s(1499)](e.LItne,this[s(1352)+s(444)]),this[s(1211)+"er"]&&window["removeEv"+s(798)+"ner"](e[s(1097)],this[s(1352)+s(1638)])}[t(1615)+"ageShow"](n){let s=t;e.aYeRN(e[s(688)],e.QhZru)?n[s(914)+"d"]&&(this[s(1101)+"orOnline"]()&&(!this[s(531)]||e[s(1568)](this._ws[s(660)+"te"],this[s(1309)])||e[s(675)](this[s(531)].readyState,this[s(315)+"NG"]))&&this._handleOnLine(),this[s(1211)+"er"]&&window[s(1330)+s(1012)](e[s(584)],this[s(1352)+s(444)]),this[s(1211)+"er"]&&window[s(1330)+s(1012)](e[s(1097)],this[s(1352)+s(1638)])):this[s(1596)](_0x325bbf,_0xf4092f)}async["_generat"+t(294)](n){let s=t,{fpID:l,deviceID:u,bddID:_,ttwID:v,accessKey:b,aID:p,customParams:k={},enableAutoAck:B,enableQoS:z,QoSLevel:U,env:H}=this[s(506)],V,it,Qt;this[s(1211)+"er"]||this[s(1143)+"X"]||this[s(843)+"T"]?(V=location&&e.NePXh(e[s(889)],location[s(1154)])?e[s(1305)]:e[s(876)],it=n[s(398)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Qt=/^wss(.*:\/\/)/[s(1155)](n)?n:""+V+it):(V=e[s(1305)],it=n.replace(/(^http)((?:[s]*:\/\/))/,""),Qt=/(^ws)((?:[s]*:\/\/))/[s(1155)](it)?it:""+V+it);let Jd=_?e.AtpSu:v?e[s(650)]:e[s(1518)],Yd=_||v||u;if(e[s(1592)](!Yd,!Jd))throw new Error(e.ZZSbr);let Tp=e[s(1587)](e[s(488)],typeof k)?await k():k,Rp=H?e[s(308)](Kx,H[s(487)],H[s(1597)]):{},ca=Object.assign({device_platform:e[s(1399)],version_code:e[s(1093)],access_key:b,fpid:l,aid:p,[Jd]:Yd,xsack:B?1:0,xaack:B?1:0,xsqos:z?1:0,qos_level:z?U:void 0,qos_sdk_version:2,...Rp},Tp),Cp=Object[s(1606)](ca)[s(1252)]((da,la)=>ca[la]!==void 0?""+da+(da?"&":"?")+la+"="+ca[la]:da,"");return Qt+s(960)+Cp}async[t(805)](){let n=t;if(!(this[n(805)+"Lock"]||this._readyClosed)){this[n(805)+n(646)]=!0;try{let s=this[n(1188)+"tManager"]?.[n(226)+n(732)+n(832)+n(1260)+n(1046)](),{timeoutInterval:l}=this[n(506)];if(s){let _=this["_endpoin"+n(456)]?.[n(465)+"ntEndpoint"](),v=this[n(1188)+"tManager"]?.["replaceB"+n(1220)+"pointAnd"+n(994)+"unt"](),b=this["_endpoin"+n(456)]?.[n(465)+n(706)+n(810)+n(782)]();if(v){let p=n(1380)+_+(n(293)+n(1321)+n(734)+n(596)+n(1131)+n(1500)+"ndpoint ")+v+(n(1310)+"y"),k=rt("error",{message:p,code:Yt[n(1267)+n(1313)+"R"]});this[n(303)](p),this["_dispatc"+n(1040)+n(364)](k),this._url=await this[n(758)+n(294)](v),this._debug(n(1380)+v+" "+b+n(256)),this[n(604)+n(1555)+"rs"]()}else{let p=n(1380)+_+(n(293)+n(1321)+n(734)+n(1350));this[n(303)](p),this[n(937)+n(1040)+"ent"](rt(n(1186),{message:p,code:Yt[n(1267)+"IES_ERROR"]}));return}}else{let _=this._endpointManager?.[n(465)+"ntEndpoi"+n(740)+n(1013)](),v=this[n(1188)+n(456)]?.[n(465)+n(706)+n(810)+n(782)]();this[n(585)]=await this[n(758)+n(294)](e[n(467)](_,"")),this[n(303)](n(1380)+_+" "+v+n(256)),this["_removeW"+n(1555)+"rs"]()}if(this[n(1360)])this._isInit=!1;else{let _=e[n(544)](ea,e[n(931)],{message:e[n(1098)]});this[n(1265)+"econnect"]&&this[n(1265)+n(395)](_)}let u=this[n(1188)+n(456)]?.[n(465)+n(706)+"ntTriesC"+n(782)]()||0;e[n(1458)](u,1)&&await this[n(1541)](e[n(1315)](u,1)),this[n(303)](n(704)+"ng url: "+this[n(585)]+(n(379)+n(1328))+this[n(1483)+"ls"]),this[n(531)]=e[n(1250)](qx,{url:this[n(585)],protocols:[this._protocols],headers:this[n(506)][n(820)+n(1420)+"s"][n(769)+n(1493)]},this[n(506)].ws),(this._isBrowser||this[n(1527)+"r"])&&this[n(531)]&&(this[n(531)][n(928)+"pe"]=this[n(1111)+"ype"]),this[n(1195)+n(559)](),this["_connect"+n(858)+n(757)]=e[n(1072)](setTimeout,this._onTimeout[n(1257)](this),l)}catch(s){throw this[n(805)+"Lock"]=!1,s}}}[t(874)+t(1081)](){let n=t;e[n(857)](clearTimeout,this[n(805)+n(858)+"utId"]),this[n(805)+n(858)+n(757)]=null}[t(1591)+t(1322)](){let n=t;e[n(1492)](clearTimeout,this[n(720)+"gTimeoutId"]),clearTimeout(this[n(1462)+n(1073)+n(373)]),this[n(720)+"gTimeoutId"]=null,this[n(1462)+n(1073)+n(373)]=null}[t(303)](...n){let s=t,l={rPejT:e[s(488)],MfLCe:function(u,_){return e[s(1007)](u,_)},tFwvy:function(u,_){return u(_)},fZQdV:function(u,_,v){return u(_,v)}};if(e[s(267)]===e.jxVgt)return typeof _0x304c8e===ZHWfqT[s(1506)]?_0x10aab1(_0x145224):(ZHWfqT.MfLCe(_0x9220a2,_0x41b20a)&&ZHWfqT[s(600)](_0x421a4a,_0x2c3bdb),ZHWfqT[s(499)](_0x41474c,_0x3d52f1,_0x56e414())?new _0x35cb14(_0xf75b56,_0x4cdff9):_0x2ffdc9);this[s(506)][s(765)]&&console[s(947)][s(1323)](console,[e[s(1223)],...n])}_getIntervalValue(n){let s=t;if(e[s(1436)](e[s(855)],s(366)))try{this[s(474)]?.[s(627)](),this[s(474)]=void 0}catch(l){_0x1b130a[s(947)](l)}else{let{initReconnectInterval:l,maxReconnectInterval:u,reconnectIntervalGrowFactor:_}=this._options,v=e.OJRGe(l,Math[s(930)](_,n-1));return e[s(609)](v,u)?u:v}}_ping(){let n=t;if(this._ws&&e[n(522)](this._ws.readyState,this[n(315)+"NG"])){this[n(1591)+"ngTimer"](),this[n(720)+"gTimeoutId"]=e.KMdsV(setTimeout,this._ping[n(1257)](this),this[n(506)][n(965)+n(1290)]);return}if(!this[n(531)]||e[n(300)](this._ws.readyState,this[n(1309)]))return void this[n(1430)+n(395)]();this._ws&&this[n(531)][n(1124)]("hi"),this[n(1462)+n(1073)+n(373)]=setTimeout(this["_handleR"+n(395)+n(1018)][n(1257)](this),this[n(506)][n(1320)+n(1217)+"val"])}[t(1430)+t(395)+t(1018)](){let n=t;this[n(558)+"sCounter"]?.[n(1292)](),this[n(835)](e[n(967)],e.XWnyA),this[n(558)+n(432)]?.[n(363)+n(1196)+"nt"]()?this[n(1430)+n(395)]():this._ping()}["_navigat"+t(1077)](){let n=t;return this[n(843)+"T"]||this[n(1143)+"X"]?this[n(1148)+n(1387)+n(434)]:(this[n(1211)+"er"]||this[n(1527)+"r"])&&this[n(506)][n(1235)+n(698)+n(383)]?navigator[n(616)]:!0}_handleReconnect(){let n=t,s={tUxYR:n(1374)+n(1150),vOZOR:function(l,u){return e[n(1397)](l,u)},sDHnV:e.ukORz,uyHqN:e[n(625)]};if(e[n(1538)](e.TExhb,e.LhnUM)){let l=s[n(403)][n(387)]("|"),u=0;for(;;){switch(l[u++]){case"0":this._QoSManager?.[n(1254)]();continue;case"1":if(s[n(635)](this[n(531)][n(660)+"te"],this[n(1085)])||s.vOZOR(this[n(531)][n(660)+"te"],this[n(736)]))return void this[n(303)](s[n(452)]);continue;case"2":this[n(874)+n(1081)]();continue;case"3":this[n(669)+n(602)]=!0;continue;case"4":if(!this[n(531)])return void this[n(303)](s.uyHqN);continue;case"5":this[n(1212)+n(1369)+"t"](_0x22b238,_0x52186b);continue;case"6":this["_dropGlo"+n(286)+n(1012)]();continue;case"7":this[n(1591)+n(1322)]();continue}break}}else{if(!this["_navigat"+n(1077)]()||this[n(669)+"osed"])return;this._endpointManager?.[n(1167)+n(814)+"fig"](),this["_pingLos"+n(432)]?.[n(1181)+n(684)](),this[n(531)]?this[n(665)+"ect"](1001,n(854)+"ay, try "+n(673)+n(624)+n(1559),!0):this._connect()}}[t(1563)+t(995)+"ange"](){let n=t,s={UFQsJ:e.yRtDW,QoxtW:function(l,u){return e[ee(1557)](l,u)}};if(e.Dokad!==n(1367))this[n(843)+"T"]?tt[n(1075)+n(337)+n(653)](({isConnected:l})=>{let u=n;this[u(1148)+u(1387)+u(434)]=l,l?this["_handleO"+u(444)]():this[u(1352)+u(1638)]()}):this[n(1143)+"X"]&&wx[n(1075)+"kStatusChange"](({isConnected:l})=>{let u=n;this["_miniNav"+u(1387)+u(434)]=l,l?this[u(1352)+u(444)]():this[u(1352)+u(1638)]()});else{if(bFYqQS[n(933)]==typeof _0x2ed1e7){let l=new _0x552e1f(bFYqQS[n(712)](_0x4d881a,_0x11b982));return _0x25ae12(_0x301b19,l,0),l}return _0x53440a instanceof _0x2c4935?new _0x69b92b(_0x1fffac):new _0x4b92e1(_0x44696f[n(1409)],_0x9cc31a[n(238)+"et"],_0x559411[n(1453)+"th"])}}_wait(n){let s={DllPV:function(l,u,_){return l(u,_)}};return new Promise(l=>{let u=ee;s[u(1149)](setTimeout,l,this[u(1184)+u(298)+"e"](n))})}["_disconn"+t(654)](n=1e3,s="",l=!1){let u=t;this[u(531)]&&this[u(1212)+u(1369)+"t"](n,s,l)}[t(297)+"ut"](){let n=t,s=this[n(1188)+n(456)]?.[n(465)+n(706)+"nt"]();this[n(303)](n(1380)+s+n(293)),this[n(665)+n(654)](1001,e[n(1549)],!0)}[t(902)](n){let s=t,l=e[s(1326)](Nt,n);this[s(531)]&&e[s(549)](this[s(531)][s(660)+"te"],this[s(1309)])&&(this[s(531)]&&this[s(531)][s(1124)](l),this[s(303)](e[s(1222)],n))}[t(604)+"sListeners"](){let n=t,s=(n(567)+"1")[n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(531)]["removeEv"+n(798)+"ner"](e[n(951)],this[n(473)]);continue;case"1":this._ws[n(755)+n(798)+n(1499)]("error",this[n(598)]);continue;case"2":this._ws[n(755)+n(798)+n(1499)]("message",this[n(528)+"ge"]);continue;case"3":this[n(531)][n(755)+n(798)+"ner"](e[n(557)],this._onClose);continue;case"4":if(!this[n(531)])return;continue}break}}[t(1195)+t(559)](){let n=t,s=e[n(1105)].split("|"),l=0;for(;;){switch(s[l++]){case"0":if(!this[n(531)])return;continue;case"1":this._ws[n(1330)+n(1012)](e[n(234)],this[n(528)+"ge"]);continue;case"2":this._ws.addEventListener(e[n(1586)],this[n(598)]);continue;case"3":this[n(531)][n(1330)+n(1012)](e[n(951)],this[n(473)]);continue;case"4":this[n(531)][n(1330)+n(1012)]("close",this[n(1173)]);continue}break}}["_wsInsta"+t(492)](n=1e3,s=""){let l=t;try{this._ws&&this[l(531)][l(627)](n,s)}catch{}}[t(1212)+t(1369)+"t"](n=1e3,s="",l=!1){let u=t;if(this["_clearPi"+u(1322)](),this._clearTimer(),this[u(604)+u(1555)+"rs"](),this[u(447)+"nceClose"](1e3,s),this[u(805)+u(646)]=!1,l&&this[u(1101)+"orOnline"]()&&!this._readyClosed){if(this[u(1188)+"tManager"]?.[u(363)+"chMaxTries"]()){let v=this._endpointManager?.[u(465)+u(706)+"nt"]();this[u(937)+u(520)+u(364)](e[u(1106)](ft,e[u(557)],{code:1006,reason:u(1380)+v+(u(293)+u(1321)+u(734)+u(1350)),wasClean:!0}))}else{let v=this[u(506)][u(673)+"tInterce"+u(1452)](n,s);this["_dispatc"+u(520)+"ent"](ft(u(627),{code:n,reason:s,wasClean:!0,willReconnect:v})),v&&this[u(805)]()}return}this[u(1101)+u(1077)]()||this[u(669)+u(602)]?this[u(937)+u(520)+u(364)](e[u(1437)](ft,e[u(557)],{code:n,reason:e[u(1635)]})):this["_dispatchCloseEv"+u(364)](e[u(1450)](ft,e.jrwae,{code:1006,reason:e[u(1017)]})),this._ws=null,this[u(1188)+u(456)]?.["resetEndpointCon"+u(1629)](),this[u(558)+u(432)]?.[u(1181)+u(684)]()}_dispatchOpenEvent(n){let s=t;this[s(835)](e[s(951)],n),this[s(269)]&&this.onopen(n)}[t(937)+t(1130)+"Event"](n){let s=t;this[s(835)](e[s(234)],n),this[s(349)+"e"]&&this.onmessage(n)}[t(937)+t(321)+t(1055)](n){let s=t;this[s(835)](s(1389),n),this[s(526)+s(422)]&&this[s(526)+s(422)](n)}["_dispatc"+t(1040)+t(364)](n){let s=t;this[s(835)](e.Gvnme,n),this[s(1297)]&&this[s(1297)](n)}["_dispatc"+t(520)+t(364)](n){let s=t;this[s(835)](e.jrwae,n),this[s(1314)]&&this.onclose(n)}get binaryType(){let n=t;return this[n(531)]?this._ws[n(928)+"pe"]:this[n(1111)+n(1517)]}set[t(928)+"pe"](n){let s=t;this[s(1111)+s(1517)]=n,this[s(531)]&&(this[s(531)][s(928)+"pe"]=n)}get[t(1343)+"nt"](){let n=t;return e[n(880)]("ieDSC",e[n(1601)])?this["_endpoin"+n(456)]?.[n(465)+n(706)+"ntTriesC"+n(782)]()||0:this[n(474)]?.[n(738)]}get[t(613)+"Amount"](){let n=t,s=this[n(1640)+n(510)].reduce((l,u)=>(l+=u&&u[n(1453)+"th"]||0,l),0);return e[n(674)](s,this[n(531)]?this[n(531)][n(613)+n(752)]:0)}get[t(999)+"ns"](){let n=t;return this._ws?this[n(531)][n(999)+"ns"]:""}get[t(1154)](){let n=t;return this[n(531)]?this[n(531)][n(1154)]:""}get[t(660)+"te"](){let n=t;if(e[n(707)]!==e[n(707)]){let s=e.ZGLzp(_0x304bbd,e[n(1586)],{message:this[n(436)+n(1388)+n(846)](_0x237dac)});this[n(835)](n(1186),s);let l=e.NXmtb(_0x2d0d86,e[n(557)],{reason:this[n(436)+n(1388)+n(846)](_0x1608a2)});this[n(835)]("close",l)}else return this[n(531)]?this[n(531)][n(660)+"te"]:this[n(506)].automaticOpen?this[n(315)+"NG"]:this[n(1085)]}get[t(666)](){let n=t;if(e[n(542)]("ErVop",e[n(718)]))e[n(1571)](_0x37cfbf,_0x177ed5,58),_0x4fcf74(_0x1d9685,_0x4d19f4);else return this[n(531)]?this._ws[n(666)]:this._url}[t(627)](n=1e3,s){let l=t,u="2|5|1|3|0|6|7|4"[l(387)]("|"),_=0;for(;;){switch(u[_++]){case"0":this[l(445)+l(411)]?.[l(1254)]();continue;case"1":this[l(1591)+"ngTimer"]();continue;case"2":this[l(669)+"osed"]=!0;continue;case"3":this[l(1189)+l(286)+l(1012)]();continue;case"4":this[l(1212)+l(1369)+"t"](n,s);continue;case"5":this[l(874)+"mer"]();continue;case"6":if(!this._ws)return void this[l(303)](e.cXjcN);continue;case"7":if(this[l(531)][l(660)+"te"]===this[l(1085)]||e.ffkcz(this[l(531)][l(660)+"te"],this.CLOSING))return void this[l(303)]("close, w"+l(1242)+l(1532));continue}break}}async[t(1124)](n,s){let l=t;if(e.SPFDz(null,n))throw new Error(e.tnUaS);e[l(1346)](e.CgYfa,typeof n)&&(n=JSON[l(1325)+"y"](n)),e[l(1636)](e[l(1152)],typeof n)&&!e[l(1007)](n,ArrayBuffer)&&!(n[l(1409)]&&e.xYzIZ(n[l(1409)],ArrayBuffer))&&(n=JSON[l(1325)+"y"](n));let u=await e[l(561)](Wd,n),_=e[l(1564)]($x,n),{method:v=0,service:b=this._options[l(1327)],logID:p=this[l(506)].logIDGenerator(),headers:k=this._options.headers,payloadEncoding:B=this[l(506)].payloadEncoding,payloadType:z=this[l(506)][l(518)+l(1517)],logIDNew:U=this[l(506)]["logIDNew"+l(305)][l(747)+l(1107)+l(1285)+"ew"]?e[l(919)](i,this._options[l(1288)+"Config"][l(1026)]):""}=e[l(1090)](s,{});if(!b)throw new Error(e[l(981)]);let H={SeqID:ce[l(479)+"er"](this._seqId++),LogID:ce[l(479)+"er"](p),service:b,method:v,headers:k,payloadEncoding:e[l(741)](B,Object)?B.encoding?B[l(341)]:"":B,payloadType:e[l(1405)](z,Object)?z[l(819)]?z[l(819)]:_:z||_,payload:u,LogIDNew:U},V=e.NGfLT(Nt,H);return this[l(531)]&&e[l(480)](this[l(531)][l(660)+"te"],this[l(1309)])?(this[l(531)]&&this._ws[l(1124)](V),this[l(303)](e[l(1479)],H)):this[l(1640)+"Queue"].length<this[l(506)][l(283)+l(516)+"ength"]?(this["_message"+l(510)][l(1503)](V),this._debug(e.LAXrt,H)):(this["_message"+l(510)][l(1425)](),this[l(1640)+l(510)][l(1503)](V)),{seqID:this[l(1060)],logID:p,logIDNew:U}}async[t(673)+"t"](n){let s=t,{url:l}=e[s(1090)](n,{}),u=Array.isArray(l)?l:e[s(1153)](e[s(1152)],typeof l)?[l]:[];n&&Object[s(457)](this._options,n),u&&u[s(301)]?this[s(1188)+s(456)]=new Gd(u,this[s(506)].maxRetries):this[s(1188)+s(456)]?.["resetEnd"+s(814)+s(1629)](),this._pingLossCounter?.[s(1181)+s(684)](this._options[s(475)+s(705)]),this[s(669)+s(602)]=!1,this[s(531)]&&this[s(531)][s(660)+"te"]!==this[s(1085)]?this[s(665)+"ect"](1e3,"manual r"+s(395)+s(1406),!0):(this._isInit=!0,this[s(805)]())}async connect(){let n=t;if(!this[n(805)+n(646)])if(e.GIUbB(e[n(493)],e[n(927)]))this[n(1188)+"tManager"]?.[n(1167)+n(814)+n(1629)](),this["_pingLos"+n(432)]?.["resetCou"+n(684)](),this[n(669)+n(602)]=!1,this._isInit=!0,this[n(805)]();else return}[t(1330)+"Listener"](n,s){let l=t;if(e[l(1464)](e[l(1218)],e[l(1218)]))this.on(n,s);else{if(this[l(531)]&&this[l(531)][l(660)+"te"]===this[l(315)+"NG"]){this[l(1591)+l(1322)](),this["_pingPon"+l(428)+"Id"]=e.ItqTI(_0x1e1aa7,this._ping[l(1257)](this),this[l(506)][l(965)+l(1290)]);return}if(!this[l(531)]||e.qzLmK(this[l(531)][l(660)+"te"],this.OPEN))return void this[l(1430)+"econnect"]();this[l(531)]&&this._ws[l(1124)]("hi"),this[l(1462)+l(1073)+l(373)]=e[l(251)](_0x1eb745,this[l(1430)+l(395)+"Timeout"][l(1257)](this),this[l(506)][l(1320)+"outInter"+l(423)])}}[t(630)+"Event"](n){let s=t,{type:l}=n;this[s(835)](l,n)}[t(755)+"entListe"+t(1499)](n,s){let l=t;e.ivKZM(e[l(780)],e[l(780)])?(this[l(835)](l(1186),_0x3285e9),this.onerror&&this[l(1297)](_0x435d8c)):this[l(1596)](n,s)}[t(853)](){return new Promise((n,s)=>{let l=ee,u={PrQHU:function(b,p){return e.BcraG(b,p)},llZCI:l(435),qzkph:e[l(1551)],wovTZ:e[l(967)],SSHxP:e[l(355)]};this[l(1591)+"ngTimer"](),this[l(720)+l(428)+"Id"]=e[l(1383)](setTimeout,this[l(1533)][l(1257)](this),this[l(506)][l(965)+l(1290)]);let _=()=>{let b=l;u[b(1279)](n,u.llZCI),this[b(1596)](u[b(258)],_),this.off(u.wovTZ,v)},v=()=>{let b=l;u[b(1279)](s,u[b(356)]),this[b(1596)](b(1224)+"e_success",_),this[b(1596)](u.wovTZ,v)};this.on(e.mKFpL,_),this.on(e[l(967)],v),this[l(1533)]()})}}})(),Se[L(634)+L(647)]=Re[L(634)+L(647)],Se[L(686)+L(504)]=Re[L(686)+L(504)],Se[L(717)+"e"]=Re[L(717)+"e"],Se[L(1337)]=Re[L(1337)],Se.FWS=Re[L(1161)],Se[L(1422)+L(617)+L(1525)]=Re[L(1422)+"MessageE"+L(1525)],Se["MessageE"+L(1525)]=Re[L(617)+L(1525)],Se[L(824)+"t"]=Re[L(824)+"t"],Se[L(384)+"tEvent"]=Re.ReconnectEvent,Se[L(551)+L(647)]=Re.createCloseEvent,Se[L(661)+L(504)]=Re[L(661)+L(504)],Se[L(324)+L(1355)+"nt"]=Re[L(324)+L(1355)+"nt"],Se["createOp"+L(1412)]=Re["createOp"+L(1412)],Se[L(1497)+L(692)+L(1525)]=Re["createReconnectE"+L(1525)],Se.decodedFrame=Re[L(953)+L(1415)],Se[L(938)+L(1165)]=Re["encodeFr"+L(1165)];for(po in Re)[L(634)+L(647),L(686)+"rorEvent",L(717)+"e","Event",L(1161),L(1422)+L(617)+"vent",L(617)+L(1525),L(824)+"t",L(384)+L(1275),"createCl"+L(647),L(661)+"rorEvent",L(324)+L(1355)+"nt","createOp"+L(1412),L(1497)+L(692)+L(1525),L(953)+"rame","encodeFr"+L(1165)][L(775)](po)===-1&&(Se[po]=Re[po]);var po;Object[L(681)+L(1281)](Se,L(1045)+"le",{value:!0})});var qt=se((NR,$0)=>{"use strict";var q0=["nodebuffer","arraybuffer","fragments"],W0=typeof Blob<"u";W0&&q0.push("blob");$0.exports={BINARY_TYPES:q0,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:W0,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Mi=se((MR,bo)=>{"use strict";var{EMPTY_BUFFER:DE}=qt(),Yc=Buffer[Symbol.species];function kE(t,e){if(t.length===0)return DE;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new Yc(r.buffer,r.byteOffset,i):r}function K0(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Z0(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function OE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Xc(t){if(Xc.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Yc(t):ArrayBuffer.isView(t)?e=new Yc(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Xc.readOnly=!1),e}bo.exports={concat:kE,mask:K0,toArrayBuffer:OE,toBuffer:Xc,unmask:Z0};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");bo.exports.mask=function(e,r,i,o,c){c<48?K0(e,r,i,o,c):t.mask(e,r,i,o,c)},bo.exports.unmask=function(e,r){e.length<32?Z0(e,r):t.unmask(e,r)}}catch{}});var Y0=se((BR,J0)=>{"use strict";var V0=Symbol("kDone"),Qc=Symbol("kRun"),ed=class{constructor(e){this[V0]=()=>{this.pending--,this[Qc]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Qc]()}[Qc](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[V0])}}};J0.exports=ed});var Rr=se((zR,th)=>{"use strict";var Bi=de("zlib"),X0=Mi(),PE=Y0(),{kStatusCode:Q0}=qt(),LE=Buffer[Symbol.species],NE=Buffer.from([0,0,255,255]),So=Symbol("permessage-deflate"),Wt=Symbol("total-length"),Ar=Symbol("callback"),_n=Symbol("buffers"),Tr=Symbol("error"),vo,td=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,!vo){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;vo=new PE(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Ar];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){vo.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){vo.add(o=>{this._compress(e,r,(c,d)=>{o(),i(c,d)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Bi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Bi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[So]=this,this._inflate[Wt]=0,this._inflate[_n]=[],this._inflate.on("error",BE),this._inflate.on("data",eh)}this._inflate[Ar]=i,this._inflate.write(e),r&&this._inflate.write(NE),this._inflate.flush(()=>{let c=this._inflate[Tr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=X0.concat(this._inflate[_n],this._inflate[Wt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Wt]=0,this._inflate[_n]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Bi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Bi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Wt]=0,this._deflate[_n]=[],this._deflate.on("data",ME)}this._deflate[Ar]=i,this._deflate.write(e),this._deflate.flush(Bi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=X0.concat(this._deflate[_n],this._deflate[Wt]);r&&(c=new LE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Ar]=null,this._deflate[Wt]=0,this._deflate[_n]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};th.exports=td;function ME(t){this[_n].push(t),this[Wt]+=t.length}function eh(t){if(this[Wt]+=t.length,this[So]._maxPayload<1||this[Wt]<=this[So]._maxPayload){this[_n].push(t);return}this[Tr]=new RangeError("Max payload size exceeded"),this[Tr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Tr][Q0]=1009,this.removeListener("data",eh),this.reset()}function BE(t){if(this[So]._inflate=null,this[Tr]){this[Ar](this[Tr]);return}t[Q0]=1007,this[Ar](t)}});var Cr=se((FR,Io)=>{"use strict";var{isUtf8:nh}=de("buffer"),{hasBlob:zE}=qt(),FE=[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 UE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function nd(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function GE(t){return zE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Io.exports={isBlob:GE,isValidStatusCode:UE,isValidUTF8:nd,tokenChars:FE};if(nh)Io.exports.isValidUTF8=function(t){return t.length<24?nd(t):nh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");Io.exports.isValidUTF8=function(e){return e.length<32?nd(e):t(e)}}catch{}});var ad=se((UR,dh)=>{"use strict";var{Writable:jE}=de("stream"),rh=Rr(),{BINARY_TYPES:HE,EMPTY_BUFFER:ih,kStatusCode:qE,kWebSocket:WE}=qt(),{concat:rd,toArrayBuffer:$E,unmask:KE}=Mi(),{isValidStatusCode:ZE,isValidUTF8:sh}=Cr(),Ao=Buffer[Symbol.species],ct=0,oh=1,ah=2,ch=3,id=4,sd=5,To=6,od=class extends jE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||HE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[WE]=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=ct}_write(e,r,i){if(this._opcode===8&&this._state==ct)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Ao(i.buffer,i.byteOffset+e,i.length-e),new Ao(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Ao(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case ct:this.getInfo(e);break;case oh:this.getPayloadLength16(e);break;case ah:this.getPayloadLength64(e);break;case ch:this.getMask();break;case id:this.getData(e);break;case sd:case To:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[rh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=oh:this._payloadLength===127?this._state=ah:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=ch:this._state=id}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=id}getData(e){let r=ih;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&KE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=sd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[rh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===ct&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ct;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=rd(i,r):this._binaryType==="arraybuffer"?o=$E(rd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ct):(this._state=To,setImmediate(()=>{this.emit("message",o,!0),this._state=ct,this.startLoop(e)}))}else{let o=rd(i,r);if(!this._skipUTF8Validation&&!sh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===sd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ct):(this._state=To,setImmediate(()=>{this.emit("message",o,!1),this._state=ct,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,ih),this.end();else{let i=e.readUInt16BE(0);if(!ZE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Ao(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!sh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ct;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ct):(this._state=To,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ct,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(d,this.createError),d.code=c,d[qE]=o,d}};dh.exports=od});var ld=se((jR,uh)=>{"use strict";var{Duplex:GR}=de("stream"),{randomFillSync:VE}=de("crypto"),lh=Rr(),{EMPTY_BUFFER:JE,kWebSocket:YE,NOOP:XE}=qt(),{isBlob:Dr,isValidStatusCode:QE}=Cr(),{mask:fh,toBuffer:Un}=Mi(),dt=Symbol("kByteLength"),eb=Buffer.alloc(4),Ro=8*1024,Gn,kr=Ro,_t=0,tb=1,nb=2,cd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=_t,this.onerror=XE,this[YE]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||eb,r.generateMask?r.generateMask(i):(kr===Ro&&(Gn===void 0&&(Gn=Buffer.alloc(Ro)),VE(Gn,0,Ro),kr=0),i[0]=Gn[kr++],i[1]=Gn[kr++],i[2]=Gn[kr++],i[3]=Gn[kr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let f;typeof e=="string"?(!r.mask||d)&&r[dt]!==void 0?f=r[dt]:(e=Buffer.from(e),f=e.length):(f=e.length,o=r.mask&&r.readOnly&&!d);let h=f;f>=65536?(c+=8,h=127):f>125&&(c+=2,h=126);let x=Buffer.allocUnsafe(o?f+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=h,h===126?x.writeUInt16BE(f,2):h===127&&(x[2]=x[3]=0,x.writeUIntBE(f,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(fh(e,i,x,c,f),[x]):(fh(e,i,e,0,f),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=JE;else{if(typeof e!="number"||!QE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+f),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let d={[dt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==_t?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Dr(e)?(o=e.size,c=!1):(e=Un(e),o=e.length,c=Un.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==_t?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Dr(e)?(o=e.size,c=!1):(e=Un(e),o=e.length,c=Un.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==_t?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[lh.extensionName],c=r.binary?2:1,d=r.compress,f,h;typeof e=="string"?(f=Buffer.byteLength(e),h=!1):Dr(e)?(f=e.size,h=!1):(e=Un(e),f=e.length,h=Un.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=f>=o._threshold),this._compress=d):(d=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[dt]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:d};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==_t?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[dt],this._state=nb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(dd,this,f,o);return}this._bufferedBytes-=i[dt];let d=Un(c);r?this.dispatch(d,r,i,o):(this._state=_t,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(rb,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[lh.extensionName];this._bufferedBytes+=i[dt],this._state=tb,c.compress(e,i.fin,(d,f)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");dd(this,h,o);return}this._bufferedBytes-=i[dt],this._state=_t,i.readOnly=!1,this.sendFrame(t.frame(f,i),o),this.dequeue()})}dequeue(){for(;this._state===_t&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][dt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][dt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};uh.exports=cd;function dd(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function rb(t,e,r){dd(t,e,r),t.onerror(e)}});var Eh=se((HR,_h)=>{"use strict";var{kForOnEventAttribute:zi,kListener:fd}=qt(),hh=Symbol("kCode"),xh=Symbol("kData"),ph=Symbol("kError"),gh=Symbol("kMessage"),mh=Symbol("kReason"),Or=Symbol("kTarget"),wh=Symbol("kType"),yh=Symbol("kWasClean"),$t=class{constructor(e){this[Or]=null,this[wh]=e}get target(){return this[Or]}get type(){return this[wh]}};Object.defineProperty($t.prototype,"target",{enumerable:!0});Object.defineProperty($t.prototype,"type",{enumerable:!0});var jn=class extends $t{constructor(e,r={}){super(e),this[hh]=r.code===void 0?0:r.code,this[mh]=r.reason===void 0?"":r.reason,this[yh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[hh]}get reason(){return this[mh]}get wasClean(){return this[yh]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Pr=class extends $t{constructor(e,r={}){super(e),this[ph]=r.error===void 0?null:r.error,this[gh]=r.message===void 0?"":r.message}get error(){return this[ph]}get message(){return this[gh]}};Object.defineProperty(Pr.prototype,"error",{enumerable:!0});Object.defineProperty(Pr.prototype,"message",{enumerable:!0});var Fi=class extends $t{constructor(e,r={}){super(e),this[xh]=r.data===void 0?null:r.data}get data(){return this[xh]}};Object.defineProperty(Fi.prototype,"data",{enumerable:!0});var ib={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[zi]&&o[fd]===e&&!o[zi])return;let i;if(t==="message")i=function(c,d){let f=new Fi("message",{data:d?c:c.toString()});f[Or]=this,Co(e,this,f)};else if(t==="close")i=function(c,d){let f=new jn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[Or]=this,Co(e,this,f)};else if(t==="error")i=function(c){let d=new Pr("error",{error:c,message:c.message});d[Or]=this,Co(e,this,d)};else if(t==="open")i=function(){let c=new $t("open");c[Or]=this,Co(e,this,c)};else return;i[zi]=!!r[zi],i[fd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[fd]===e&&!r[zi]){this.removeListener(t,r);break}}};_h.exports={CloseEvent:jn,ErrorEvent:Pr,Event:$t,EventTarget:ib,MessageEvent:Fi};function Co(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Do=se((qR,bh)=>{"use strict";var{tokenChars:Ui}=Cr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function sb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,f,h=-1,x=-1,m=-1,g=0;for(;g<t.length;g++)if(x=t.charCodeAt(g),d===void 0)if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(g!==0&&(x===32||x===9))m===-1&&h!==-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g);let w=t.slice(h,m);x===44?(Lt(e,w,r),r=Object.create(null)):d=w,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${g}`);else if(f===void 0)if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(x===32||x===9)m===-1&&h!==-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g),Lt(r,t.slice(h,m),!0),x===44&&(Lt(e,d,r),r=Object.create(null),d=void 0),h=m=-1}else if(x===61&&h!==-1&&m===-1)f=t.slice(h,g),h=m=-1;else throw new SyntaxError(`Unexpected character at index ${g}`);else if(o){if(Ui[x]!==1)throw new SyntaxError(`Unexpected character at index ${g}`);h===-1?h=g:i||(i=!0),o=!1}else if(c)if(Ui[x]===1)h===-1&&(h=g);else if(x===34&&h!==-1)c=!1,m=g;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${g}`);else if(x===34&&t.charCodeAt(g-1)===61)c=!0;else if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(h!==-1&&(x===32||x===9))m===-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g);let w=t.slice(h,m);i&&(w=w.replace(/\\/g,""),i=!1),Lt(r,f,w),x===44&&(Lt(e,d,r),r=Object.create(null),d=void 0),f=void 0,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${g}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=g);let A=t.slice(h,m);return d===void 0?Lt(e,A,r):(f===void 0?Lt(r,A,!0):i?Lt(r,f,A.replace(/\\/g,"")):Lt(r,f,A),Lt(e,d,r)),e}function ob(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}bh.exports={format:ob,parse:sb}});var Lo=se((KR,Lh)=>{"use strict";var ab=de("events"),cb=de("https"),db=de("http"),Ih=de("net"),lb=de("tls"),{randomBytes:fb,createHash:ub}=de("crypto"),{Duplex:WR,Readable:$R}=de("stream"),{URL:ud}=de("url"),En=Rr(),hb=ad(),xb=ld(),{isBlob:pb}=Cr(),{BINARY_TYPES:vh,CLOSE_TIMEOUT:gb,EMPTY_BUFFER:ko,GUID:mb,kForOnEventAttribute:hd,kListener:wb,kStatusCode:yb,kWebSocket:Fe,NOOP:Ah}=qt(),{EventTarget:{addEventListener:_b,removeEventListener:Eb}}=Eh(),{format:bb,parse:vb}=Do(),{toBuffer:Sb}=Mi(),Th=Symbol("kAborted"),xd=[8,13],Kt=["CONNECTING","OPEN","CLOSING","CLOSED"],Ib=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends ab{constructor(e,r,i){super(),this._binaryType=vh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ko,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Rh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){vh.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let o=new hb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new xb(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Fe]=this,c[Fe]=this,e[Fe]=this,o.on("conclude",Rb),o.on("drain",Cb),o.on("error",Db),o.on("message",kb),o.on("ping",Ob),o.on("pong",Pb),c.onerror=Lb,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",kh),e.on("data",Po),e.on("end",Oh),e.on("error",Ph),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[En.extensionName]&&this._extensions[En.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){nt(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Dh(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){pd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ko,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){pd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ko,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){pd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[En.extensionName]||(o.compress=!1),this._sender.send(e||ko,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){nt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(pe,"CONNECTING",{enumerable:!0,value:Kt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Kt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Kt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Kt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Kt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Kt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Kt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Kt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(pe.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(pe.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[hd])return e[wb];return null},set(e){for(let r of this.listeners(t))if(r[hd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[hd]:!0})}})});pe.prototype.addEventListener=_b;pe.prototype.removeEventListener=Eb;Lh.exports=pe;function Rh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:gb,protocolVersion:xd[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!xd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${xd.join(", ")})`);let c;if(e instanceof ud)c=e;else try{c=new ud(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",f=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!d&&!f?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;Oo(t,I);return}let x=d?443:80,m=fb(16).toString("base64"),g=d?cb.request:db.request,A=new Set,w;if(o.createConnection=o.createConnection||(d?Tb:Ab),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(w=new En({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=bb({[En.extensionName]:w.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Ib.test(I)||A.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");A.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),f){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let E;if(o.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=d,t._originalHostOrSocketPath=f?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[S,R]of Object.entries(I))i.headers[S.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=f?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),E=t._req=g(o),t._redirects&&t.emit("redirect",t.url,E)}else E=t._req=g(o);o.timeout&&E.on("timeout",()=>{nt(t,E,"Opening handshake has timed out")}),E.on("error",I=>{E===null||E[Th]||(E=t._req=null,Oo(t,I))}),E.on("response",I=>{let S=I.headers.location,R=I.statusCode;if(S&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){nt(t,E,"Maximum redirects exceeded");return}E.abort();let P;try{P=new ud(S,e)}catch{let C=new SyntaxError(`Invalid URL: ${S}`);Oo(t,C);return}Rh(t,P,r,i)}else t.emit("unexpected-response",E,I)||nt(t,E,`Unexpected server response: ${I.statusCode}`)}),E.on("upgrade",(I,S,R)=>{if(t.emit("upgrade",I),t.readyState!==pe.CONNECTING)return;E=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){nt(t,S,"Invalid Upgrade header");return}let y=ub("sha1").update(m+mb).digest("base64");if(I.headers["sec-websocket-accept"]!==y){nt(t,S,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],D;if(C!==void 0?A.size?A.has(C)||(D="Server sent an invalid subprotocol"):D="Server sent a subprotocol but none was requested":A.size&&(D="Server sent no subprotocol"),D){nt(t,S,D);return}C&&(t._protocol=C);let N=I.headers["sec-websocket-extensions"];if(N!==void 0){if(!w){nt(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=vb(N)}catch{nt(t,S,"Invalid Sec-WebSocket-Extensions header");return}let K=Object.keys(M);if(K.length!==1||K[0]!==En.extensionName){nt(t,S,"Server indicated an extension that was not requested");return}try{w.accept(M[En.extensionName])}catch{nt(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[En.extensionName]=w}t.setSocket(S,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(E,t):E.end()}function Oo(t,e){t._readyState=pe.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ab(t){return t.path=t.socketPath,Ih.connect(t)}function Tb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Ih.isIP(t.host)?"":t.host),lb.connect(t)}function nt(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,nt),e.setHeader?(e[Th]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Oo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function pd(t,e,r){if(e){let i=pb(e)?e.size:Sb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Kt[t.readyState]})`);process.nextTick(r,i)}}function Rb(t,e){let r=this[Fe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Fe]!==void 0&&(r._socket.removeListener("data",Po),process.nextTick(Ch,r._socket),t===1005?r.close():r.close(t,e))}function Cb(){let t=this[Fe];t.isPaused||t._socket.resume()}function Db(t){let e=this[Fe];e._socket[Fe]!==void 0&&(e._socket.removeListener("data",Po),process.nextTick(Ch,e._socket),e.close(t[yb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Sh(){this[Fe].emitClose()}function kb(t,e){this[Fe].emit("message",t,e)}function Ob(t){let e=this[Fe];e._autoPong&&e.pong(t,!this._isServer,Ah),e.emit("ping",t)}function Pb(t){this[Fe].emit("pong",t)}function Ch(t){t.resume()}function Lb(t){let e=this[Fe];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,Dh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Dh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function kh(){let t=this[Fe];if(this.removeListener("close",kh),this.removeListener("data",Po),this.removeListener("end",Oh),t._readyState=pe.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Fe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Sh),t._receiver.on("finish",Sh))}function Po(t){this[Fe]._receiver.write(t)||this.pause()}function Oh(){let t=this[Fe];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function Ph(){let t=this[Fe];this.removeListener("error",Ph),this.on("error",Ah),t&&(t._readyState=pe.CLOSING,this.destroy())}});var zh=se((VR,Bh)=>{"use strict";var ZR=Lo(),{Duplex:Nb}=de("stream");function Nh(t){t.emit("close")}function Mb(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Mh(t){this.removeListener("error",Mh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Bb(t,e){let r=!0,i=new Nb({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let f=!d&&i._readableState.objectMode?c.toString():c;i.push(f)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Nh,i);return}let d=!1;t.once("error",function(h){d=!0,c(h)}),t.once("close",function(){d||c(o),process.nextTick(Nh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",Mb),i.on("error",Mh),i}Bh.exports=Bb});var gd=se((JR,Fh)=>{"use strict";var{tokenChars:zb}=Cr();function Fb(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&zb[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Fh.exports={parse:Fb}});var $h=se((XR,Wh)=>{"use strict";var Ub=de("events"),No=de("http"),{Duplex:YR}=de("stream"),{createHash:Gb}=de("crypto"),Uh=Do(),Hn=Rr(),jb=gd(),Hb=Lo(),{CLOSE_TIMEOUT:qb,GUID:Wb,kWebSocket:$b}=qt(),Kb=/^[+/0-9A-Za-z]{22}==$/,Gh=0,jh=1,qh=2,md=class extends Ub{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:qb,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Hb,...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=No.createServer((i,o)=>{let c=No.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Zb(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Gh}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===qh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Gi,this);return}if(e&&this.once("close",e),this._state!==jh)if(this._state=jh,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(Gi,this):process.nextTick(Gi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Gi(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",Hh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){qn(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){qn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!Kb.test(c)){qn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){qn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ji(r,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=jb.parse(h)}catch{qn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],g={};if(this.options.perMessageDeflate&&m!==void 0){let A=new Hn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let w=Uh.parse(m);w[Hn.extensionName]&&(A.accept(w[Hn.extensionName]),g[Hn.extensionName]=A)}catch{qn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let A={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(A,(w,E,I,S)=>{if(!w)return ji(r,E||401,I,S);this.completeUpgrade(g,c,x,e,r,i,o)});return}if(!this.options.verifyClient(A))return ji(r,401)}this.completeUpgrade(g,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,f){if(!c.readable||!c.writable)return c.destroy();if(c[$b])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Gh)return ji(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Gb("sha1").update(r+Wb).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let g=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;g&&(x.push(`Sec-WebSocket-Protocol: ${g}`),m._protocol=g)}if(e[Hn.extensionName]){let g=e[Hn.extensionName].params,A=Uh.format({[Hn.extensionName]:[g]});x.push(`Sec-WebSocket-Extensions: ${A}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&Xi(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as qp,mkdirSync as jp}from"node:fs";import{join as Wp}from"node:path";function tl(t){let e=t.retentionDays??Vp,r=t.clock??(()=>An(new Date));es={bridgeSink:new jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();Xi(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])Xi(t.agentLogsDir(o),"agent",i,e)}function Jp(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function nl(t){ma=t}function rl(t){return Qn[ma]<=Qn[t]}function il(t,e){let r=Qn[t];return r===void 0?!0:r>=Qn[e]}function ts(t){el={...t}}function sl(t){let e=(f,h=2)=>String(f).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${An(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function Wr(t,e,r,i,o){try{let c=`${JSON.stringify({ts:sl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;jp(t,{recursive:!0}),qp(Wp(t,Xn("bridge",An(new Date))),c)}catch{}}function Zp(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function Qi(t,e,r,i,o){if(Qn[t]<Qn[ma])return;let c=`${JSON.stringify({ts:sl(new Date),level:t,module:e,msg:r,...el,...i})}
12
+ `;if(es){let l=Zp(o,i),f=l?Jp(es,l):es.bridgeSink;try{f.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?$p.write(c):Kp.write(c)}function G(t,e){return{debug:(r,i)=>Qi("debug",t,r,i,e),info:(r,i)=>Qi("info",t,r,i,e),warn:(r,i)=>Qi("warn",t,r,i,e),error:(r,i)=>Qi("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var Qn,ma,Kp,$p,el,Vp,es,ne=Je(()=>{"use strict";Yi();ga();Qn={debug:10,info:20,warn:30,error:40},ma=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Kp=process.stdout,$p=process.stderr,el={},Vp=Ft("COZE_BRIDGE_LOG_RETENTION_DAYS",30),es=null});var D,Ke=Je(()=>{"use strict";D=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var dl={};xa(dl,{ACP_WRAPPER_NPM_PACKAGES:()=>$r,_resetAcpInstallerForTests:()=>ng,_setBinaryPathCacheForTests:()=>rg,buildAcpSpawn:()=>Vr,ensureAcpInstalled:()=>er,getAcpBinaryPath:()=>ns,pickWhichLine:()=>ya,probeAcpVersion:()=>tg,resolveAcpCommand:()=>cl});import{readFileSync as ol}from"node:fs";import{createRequire as Yp}from"node:module";import{dirname as Xp,resolve as Qp}from"node:path";function ya(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function eg(t){let e=al.resolve(`${t.npmPackage}/package.json`),r=Xp(e),i=JSON.parse(ol(e,"utf8")),o=typeof i.bin=="string"?i.bin:i.bin?.[t.binary];if(!o)throw new Error(`${t.npmPackage} package.json \u7F3A bin[${t.binary}]`);return Qp(r,o)}async function er(t,e){let r=_a[t];if(!r)throw new D("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Kr.get(t);if(i)return i;try{let o=eg(r);return Kr.set(t,o),wa.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw wa.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new D("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
+ `),{cause:o})}}async function tg(t){let e=_a[t];if(e)try{let r=al.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(ol(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){wa.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function ns(t){return Kr.get(t)}function cl(t,e){if(e)return e;let r=ns(t);if(!r)throw new D("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Vr(t,e,r){if(e)return{command:e,args:[...r]};let i=cl(t);return{command:process.execPath,args:[i,...r]}}function ng(){Kr.clear()}function rg(t,e){Kr.set(t,e)}var wa,_a,$r,al,Kr,nn=Je(()=>{"use strict";Ke();ne();wa=G("agents.acp-installer"),_a={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},$r=Object.values(_a).filter(t=>t!==void 0).map(t=>t.npmPackage),al=Yp(import.meta.url),Kr=new Map});import{chmod as sg,mkdir as og,readFile as ag,rename as fl,writeFile as hl}from"node:fs/promises";import{dirname as cg}from"node:path";async function tr(t){try{let e=await ag(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function nr(t,e,r){await og(cg(t),{recursive:!0});let i=`${JSON.stringify(e,null,2)}
14
+ `,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await hl(o,i,{encoding:"utf8",mode:r.mode}):await hl(o,i,"utf8"),await fl(o,t),r?.mode!==void 0&&await sg(t,r.mode)}catch(c){await fl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Jr=Je(()=>{"use strict"});import{promises as xl,readdirSync as dg}from"node:fs";import{homedir as lg}from"node:os";import{sep as ug,join as Ie,resolve as pl}from"node:path";function X(t){let e=t??lg(),r=Ie(e,".coze"),i=Ie(r,"bridge"),o=Ie(i,"lib"),c=Ie(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ie(o,"index.js"),binDir:Ie(i,"bin"),pidFile:Ie(i,"bridge.pid"),portFile:Ie(i,"bridge.port"),tokenFile:Ie(i,"bridge.token"),patTokenFile:Ie(i,"pat-token"),agentEnvFile:Ie(i,"agent-env.json"),logFile:Ie(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ie(c,"daemon-stdio.log"),installLock:Ie(i,"install.lock"),configFile:Ie(i,"config.json"),agentsRoot:Ie(r,"agents")}}function Ze(t,e=X()){let r=Ie(e.agentsRoot,t);return{root:r,config:Ie(r,"config.json"),workspace:Ie(r,"workspace"),logs:Ie(r,"logs")}}function rs(t=X()){try{return dg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Zr(t,e){let r=await xl.realpath(pl(t)).catch(()=>null);if(!r)return!1;let i=await xl.realpath(pl(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?r.toLowerCase():r,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+ug)}var Ce=Je(()=>{"use strict"});var os={};xa(os,{AGENT_CONFIG_FILE_MODE:()=>is,enforceAgentConfigMode:()=>xg,loadAgentConfig:()=>qe,persistAgentSessions:()=>Yr,persistAgentSkills:()=>ss,saveAgentConfig:()=>Ye});import{chmod as fg,stat as hg}from"node:fs/promises";function qe(t,e){return tr(Ze(t,e).config)}function Ye(t,e){return nr(Ze(t.agentId,e).config,t,{mode:is})}async function xg(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await hg(r);if(!i.isFile())return;let o=i.mode&511;o!==is&&(await fg(r,is),gl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;gl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Yr(t,e,r){let i=await qe(t,r);i&&(i.sessions=Object.fromEntries(e),await Ye(i,r))}async function ss(t,e,r){let i=await qe(t,r);i&&(i.skills=e,await Ye(i,r))}var gl,is,rn=Je(()=>{"use strict";Jr();ne();Ce();gl=G("agent-config"),is=384});var Ea=se((zS,yl)=>{yl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var cs=se(El=>{var bl={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function _g(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(bl))El[t]=_g(bl[t])});var Tl=se((US,Al)=>{var yg=de("fs"),ke=de("path"),vl=Ea(),bg=cs(),Eg=typeof process=="object"&&process.platform==="win32",Sl=t=>typeof t=="object"&&t!==null,Il=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function be(t){this.sep=ke.sep,this.fs=yg,Sl(t)&&Sl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Al.exports=be;be.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(f){if(f.message&&f.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw f}if(l&&l.isFile())throw bg.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};be.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=ke.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var f;try{f=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),f=o.fs.openSync(t,"w",438)}if(f)try{o.fs.writeSync(f,e,0,e.length,0)}finally{o.fs.closeSync(f)}return o.fs.chmodSync(t,i||438),!0};be.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(f,h){if(l&&h.isDirectory())return o(!1);var p=ke.dirname(t);c.fs.exists(p,function(w){w||c.makeDir(p),c.fs.open(t,"w",438,function(E,T){E?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):T?c.fs.write(T,e,0,e.length,0,function(){c.fs.close(T,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};be.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(f){let h=ke.join(i,f),p=e.fs.statSync(h);(!o||o.test(h))&&l.push(ke.normalize(h)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(h,o,c)))}),l}return r(t,void 0,!0)};be.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(f){f=ke.join(t,f),r.fs.stat(f,function(h,p){if(h)return e(h);p&&(i.push(ke.normalize(f)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(f,function(w,E){if(w)return e(w);i=i.concat(E),--l||e(null,i)}):--l||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Il[(t^e)&255]^t>>>8};be.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=be.crc32update(r,t[i++]);return~r>>>0};be.methodToString=function(t){switch(t){case vl.STORED:return"STORED ("+t+")";case vl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=ke.posix.normalize("/"+t.split("\\").join("/"));return ke.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=ke.posix.normalize("/"+t.split("\\").join("/"));return ke.posix.join(".",e)};be.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};be.sanitize=function(t,e){t=ke.resolve(ke.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=ke.normalize(ke.join(t,r.slice(i,o).join(ke.sep)));if(c.indexOf(t)===0)return c}return ke.normalize(ke.join(t,ke.basename(e)))};be.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};be.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};be.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};be.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};be.isWin=Eg;be.crcTable=Il});var Rl=se((GS,Dl)=>{var vg=de("path");Dl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=vg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var kl=se((HS,Cl)=>{Cl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var sr=se((qS,ir)=>{ir.exports=Tl();ir.exports.Constants=Ea();ir.exports.Errors=cs();ir.exports.FileAttr=Rl();ir.exports.decoder=kl()});var Pl=se((jS,Ol)=>{var sn=sr(),U=sn.Constants;Ol.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,f=0,h=0,p=0,w=0,E=0,T=0,_=0,v=0;t|=sn.isWin?2560:768,r|=U.FLG_EFS;let I={extraLen:0},S=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,L=y=>Math.max(0,y)&255;return o=sn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&U.FLG_EFS)>0},set flags_efs(y){y?r|=U.FLG_EFS:r&=~U.FLG_EFS},get flags_desc(){return(r&U.FLG_DESC)>0},set flags_desc(y){y?r|=U.FLG_DESC:r&=~U.FLG_DESC},get method(){return i},set method(y){switch(y){case U.STORED:this.version=10;case U.DEFLATED:default:this.version=20}i=y},get time(){return sn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=sn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=S(y)},get timeHighByte(){return L(o>>>8)},get crc(){return c},set crc(y){c=S(y)},get compressedSize(){return l},set compressedSize(y){l=S(y)},get size(){return f},set size(y){f=S(y)},get fileNameLength(){return h},set fileNameLength(y){h=y},get extraLength(){return p},set extraLength(y){p=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return w},set commentLength(y){w=y},get diskNumStart(){return E},set diskNumStart(y){E=S(y)},get inAttr(){return T},set inAttr(y){T=S(y)},get attr(){return _},set attr(y){_=S(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return v},set offset(y){v=S(y)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+h+p+w},get realDataOffset(){return v+U.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(v,v+U.LOCHDR);if(C.readUInt32LE(0)!==U.LOCSIG)throw sn.Errors.INVALID_LOC();I.version=C.readUInt16LE(U.LOCVER),I.flags=C.readUInt16LE(U.LOCFLG),I.flags_desc=(I.flags&U.FLG_DESC)>0,I.method=C.readUInt16LE(U.LOCHOW),I.time=C.readUInt32LE(U.LOCTIM),I.crc=C.readUInt32LE(U.LOCCRC),I.compressedSize=C.readUInt32LE(U.LOCSIZ),I.size=C.readUInt32LE(U.LOCLEN),I.fnameLen=C.readUInt16LE(U.LOCNAM),I.extraLen=C.readUInt16LE(U.LOCEXT);let O=v+U.LOCHDR+I.fnameLen,B=O+I.extraLen;return y.slice(O,B)},loadFromBinary:function(y){if(y.length!==U.CENHDR||y.readUInt32LE(0)!==U.CENSIG)throw sn.Errors.INVALID_CEN();t=y.readUInt16LE(U.CENVEM),e=y.readUInt16LE(U.CENVER),r=y.readUInt16LE(U.CENFLG),i=y.readUInt16LE(U.CENHOW),o=y.readUInt32LE(U.CENTIM),c=y.readUInt32LE(U.CENCRC),l=y.readUInt32LE(U.CENSIZ),f=y.readUInt32LE(U.CENLEN),h=y.readUInt16LE(U.CENNAM),p=y.readUInt16LE(U.CENEXT),w=y.readUInt16LE(U.CENCOM),E=y.readUInt16LE(U.CENDSK),T=y.readUInt16LE(U.CENATT),_=y.readUInt32LE(U.CENATX),v=y.readUInt32LE(U.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(U.LOCHDR);return y.writeUInt32LE(U.LOCSIG,0),y.writeUInt16LE(e,U.LOCVER),y.writeUInt16LE(r,U.LOCFLG),y.writeUInt16LE(i,U.LOCHOW),y.writeUInt32LE(o,U.LOCTIM),y.writeUInt32LE(c,U.LOCCRC),y.writeUInt32LE(l,U.LOCSIZ),y.writeUInt32LE(f,U.LOCLEN),y.writeUInt16LE(h,U.LOCNAM),y.writeUInt16LE(I.extraLen,U.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(U.CENHDR+h+p+w);return y.writeUInt32LE(U.CENSIG,0),y.writeUInt16LE(t,U.CENVEM),y.writeUInt16LE(e,U.CENVER),y.writeUInt16LE(r,U.CENFLG),y.writeUInt16LE(i,U.CENHOW),y.writeUInt32LE(o,U.CENTIM),y.writeUInt32LE(c,U.CENCRC),y.writeUInt32LE(l,U.CENSIZ),y.writeUInt32LE(f,U.CENLEN),y.writeUInt16LE(h,U.CENNAM),y.writeUInt16LE(p,U.CENEXT),y.writeUInt16LE(w,U.CENCOM),y.writeUInt16LE(E,U.CENDSK),y.writeUInt16LE(T,U.CENATT),y.writeUInt32LE(_,U.CENATX),y.writeUInt32LE(v,U.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:sn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(f),fileNameLength:y(h),extraLength:y(p),commentLength:y(w),diskNumStart:E,inAttr:T,attr:_,offset:v,centralHeaderSize:y(U.CENHDR+h+p+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Nl=se((WS,Ll)=>{var or=sr(),me=or.Constants;Ll.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return me.ENDHDR+o},loadFromBinary:function(c){if((c.length!==me.ENDHDR||c.readUInt32LE(0)!==me.ENDSIG)&&(c.length<me.ZIP64HDR||c.readUInt32LE(0)!==me.ZIP64SIG))throw or.Errors.INVALID_END();c.readUInt32LE(0)===me.ENDSIG?(t=c.readUInt16LE(me.ENDSUB),e=c.readUInt16LE(me.ENDTOT),r=c.readUInt32LE(me.ENDSIZ),i=c.readUInt32LE(me.ENDOFF),o=c.readUInt16LE(me.ENDCOM)):(t=or.readBigUInt64LE(c,me.ZIP64SUB),e=or.readBigUInt64LE(c,me.ZIP64TOT),r=or.readBigUInt64LE(c,me.ZIP64SIZE),i=or.readBigUInt64LE(c,me.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(me.ENDHDR+o);return c.writeUInt32LE(me.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,me.ENDSUB),c.writeUInt16LE(e,me.ENDTOT),c.writeUInt32LE(r,me.ENDSIZ),c.writeUInt32LE(i,me.ENDOFF),c.writeUInt16LE(o,me.ENDCOM),c.fill(" ",me.ENDHDR),c},toJSON:function(){let c=function(l,f){let h=l.toString(16).toUpperCase();for(;h.length<f;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Sa=se(va=>{va.EntryHeader=Pl();va.MainHeader=Nl()});var Bl=se(($S,Ml)=>{Ml.exports=function(t){var e=de("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(f){c.push(f),l+=f.length}),o.on("end",function(){var f=Buffer.alloc(l),h=0;f.fill(0);for(var p=0;p<c.length;p++){var w=c[p];w.copy(f,h),h+=w.length}i&&i(f)}),o.end(t)}}}});var Fl=se((VS,zl)=>{var Sg=+(process.versions?process.versions.node:"").split(".")[0]||0;zl.exports=function(t,e){var r=de("zlib");let i=Sg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],f=0;c.on("data",function(h){l.push(h),f+=h.length}),c.on("end",function(){var h=Buffer.alloc(f),p=0;h.fill(0);for(var w=0;w<l.length;w++){var E=l[w];E.copy(h,p),p+=E.length}o&&o(h)}),c.end(t)}}}});var jl=se((JS,ql)=>{"use strict";var{randomFillSync:Ul}=de("crypto"),Ig=cs(),Ag=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),Hl=(t,e)=>Math.imul(t,e)>>>0,Gl=(t,e)=>Ag[(t^e)&255]^t>>>8,Xr=()=>typeof Ul=="function"?Ul(Buffer.alloc(12)):Xr.node();Xr.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var ds={genSalt:Xr};function ls(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let r=0;r<e.length;r++)this.updateKeys(e[r])}ls.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Gl(e[0],t),e[1]+=e[0]&255,e[1]=Hl(e[1],134775813)+1,e[2]=Gl(e[2],e[1]>>>24),t};ls.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Hl(t,t^1)>>8&255};function Tg(t){let e=new ls(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function Dg(t){let e=new ls(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function Rg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Tg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Ig.WRONG_PASSWORD();return i(t.slice(12))}function Cg(t){Buffer.isBuffer(t)&&t.length>=12?ds.genSalt=function(){return t.slice(0,12)}:t==="node"?ds.genSalt=Xr.node:ds.genSalt=Xr}function kg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Dg(r),c=ds.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}ql.exports={decrypt:Rg,encrypt:kg,_salter:Cg}});var Wl=se(us=>{us.Deflater=Bl();us.Inflater=Fl();us.ZipCrypto=jl()});var Aa=se((YS,Kl)=>{var oe=sr(),Og=Sa(),Ee=oe.Constants,Ia=Wl();Kl.exports=function(t,e){var r=new Og.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,f=Buffer.alloc(0),h=Buffer.alloc(0),p=!0;let w=t,E=typeof w.decoder=="object"?w.decoder:oe.decoder;p=E.hasOwnProperty("efs")?E.efs:!1;function T(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let C={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==Ee.LOCSIG||e.readUInt32LE(O)==Ee.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==Ee.EXTSIG)C.crc=e.readUInt32LE(O+Ee.EXTCRC),C.compressedSize=e.readUInt32LE(O+Ee.EXTSIZ),C.size=e.readUInt32LE(O+Ee.EXTLEN);else if(e.readUInt16LE(O+12)===19280)C.crc=e.readUInt32LE(O+Ee.EXTCRC-4),C.compressedSize=e.readUInt32LE(O+Ee.EXTSIZ-4),C.size=e.readUInt32LE(O+Ee.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==C.crc)return!1}return!0}function v(y,C,O){if(typeof C>"u"&&typeof y=="string"&&(O=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),oe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=T();if(B.length===0)return y&&C&&C(B),B;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw oe.Errors.INVALID_PASS_PARAM();B=Ia.ZipCrypto.decrypt(B,r,O)}var F=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(B.copy(F),_(F))return y&&C&&C(F),F;throw y&&C&&C(F,oe.Errors.BAD_CRC()),oe.Errors.BAD_CRC();case oe.Constants.DEFLATED:var V=new Ia.Inflater(B,r.size);if(y)V.inflateAsync(function(J){J.copy(J,0),C&&(_(J)?C(J):C(J,oe.Errors.BAD_CRC()))});else{if(V.inflate(F).copy(F,0),!_(F))throw oe.Errors.BAD_CRC(`"${E.decode(i)}"`);return F}break;default:throw y&&C&&C(Buffer.alloc(0),oe.Errors.UNKNOWN_METHOD()),oe.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&C&&C(T()),T();if(l.length&&!c){var O;switch(r.method){case oe.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(l.length),l.copy(O),y&&C&&C(O),O;default:case oe.Constants.DEFLATED:var B=new Ia.Deflater(l);if(y)B.deflateAsync(function(V){O=Buffer.alloc(V.length),r.compressedSize=V.length,V.copy(O),C&&C(O)});else{var F=B.deflate();return r.compressedSize=F.length,F}B=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function S(y,C){return oe.readBigUInt64LE(y,C)}function R(y){try{for(var C=0,O,B,F;C+4<y.length;)O=y.readUInt16LE(C),C+=2,B=y.readUInt16LE(C),C+=2,F=y.slice(C,C+B),C+=B,Ee.ID_ZIP64===O&&L(F)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function L(y){var C,O,B,F;y.length>=Ee.EF_ZIP64_SCOMP&&(C=S(y,Ee.EF_ZIP64_SUNCOMP),r.size===Ee.EF_ZIP64_OR_32&&(r.size=C)),y.length>=Ee.EF_ZIP64_RHO&&(O=S(y,Ee.EF_ZIP64_SCOMP),r.compressedSize===Ee.EF_ZIP64_OR_32&&(r.compressedSize=O)),y.length>=Ee.EF_ZIP64_DSN&&(B=S(y,Ee.EF_ZIP64_RHO),r.offset===Ee.EF_ZIP64_OR_32&&(r.offset=B)),y.length>=Ee.EF_ZIP64_DSN+4&&(F=y.readUInt32LE(Ee.EF_ZIP64_DSN),r.diskNumStart===Ee.EF_ZIP64_OR_16&&(r.diskNumStart=F))}return{get entryName(){return E.decode(i)},get rawEntryName(){return i},set entryName(y){i=oe.toBuffer(y,E.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return f},set extra(y){f=y,r.extraLength=y.length,R(y)},get comment(){return E.decode(o)},set comment(y){if(o=oe.toBuffer(y,E.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=E.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){l=oe.toBuffer(y,oe.decoder.encode),!c&&l.length?(r.size=l.length,r.method=oe.Constants.DEFLATED,r.crc=oe.crc32(y),r.changed=!0):r.method=oe.Constants.STORED},getData:function(y){return r.changed?l:v(!1,null,y)},getDataAsync:function(y,C){r.changed?y(l):v(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=f.length;var y=r.centralHeaderToBinary(),C=oe.Constants.CENHDR;return i.copy(y,C),C+=i.length,f.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let C=r.localHeaderToBinary(),O=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(O,y),y+=C.length,i.copy(O,y),y+=i.length,h.copy(O,y),y+=h.length,O},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Jl=se((XS,Vl)=>{var $l=Aa(),Pg=Sa(),je=sr();Vl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Pg.MainHeader,l=!1,f=null;let h=new Set,p=e,{noSort:w,decoder:E}=p;t?v(p.readEntries):l=!0;function T(){let S=new Set;for(let R of Object.keys(i)){let L=R.split("/");if(L.pop(),!!L.length)for(let y=0;y<L.length;y++){let C=L.slice(0,y+1).join("/")+"/";S.add(C)}}for(let R of S)if(!(R in i)){let L=new $l(p);L.entryName=R,L.attr=16,L.temporary=!0,r.push(L),i[L.entryName]=L,h.add(L)}}function _(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var S=c.offset,R=0;R<r.length;R++){var L=S,y=new $l(p,t);y.header=t.slice(L,L+=je.Constants.CENHDR),y.entryName=t.slice(L,L+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(L,L+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(L,L+y.header.commentLength)),S+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}h.clear(),T()}function v(S){var R=t.length-je.Constants.ENDHDR,L=Math.max(0,R-65535),y=L,C=t.length,O=-1,B=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(L=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===je.Constants.ENDSIG){O=R,B=R,C=R+je.Constants.ENDHDR,y=R-je.Constants.END64HDR;continue}if(t.readUInt32LE(R)===je.Constants.END64SIG){y=L;continue}if(t.readUInt32LE(R)===je.Constants.ZIP64SIG){O=R,C=R+je.readBigUInt64LE(t,R+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(O==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,C)),c.commentLength&&(o=t.slice(B+je.Constants.ENDHDR)),S&&_()}function I(){r.length>1&&!w&&r.sort((S,R)=>S.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||_(),r.filter(S=>!h.has(S))},get comment(){return E.decode(o)},set comment(S){o=je.toBuffer(S,E.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(S){this.entries.forEach(S)},getEntry:function(S){return l||_(),i[S]||null},setEntry:function(S){l||_(),r.push(S),i[S.entryName]=S,c.totalEntries=r.length},deleteFile:function(S,R=!0){l||_();let L=i[S];this.getEntryChildren(L,R).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(S){l||_();let R=i[S],L=r.indexOf(R);L>=0&&(r.splice(L,1),delete i[S],c.totalEntries=r.length)},getEntryChildren:function(S,R=!0){if(l||_(),typeof S=="object")if(S.isDirectory&&R){let L=[],y=S.entryName;for(let C of r)C.entryName.startsWith(y)&&L.push(C);return L}else return[S];return[]},getChildCount:function(S){if(S&&S.isDirectory){let R=this.getEntryChildren(S);return R.includes(S)?R.length-1:R.length}return 0},compressToBuffer:function(){l||_(),I();let S=[],R=[],L=0,y=0;c.size=0,c.offset=0;let C=0;for(let F of this.entries){let V=F.getCompressedData();F.header.offset=y;let J=F.packLocalHeader(),te=J.length+V.length;y+=te,S.push(J),S.push(V);let Q=F.packCentralHeader();R.push(Q),c.size+=Q.length,L+=te+Q.length,C++}L+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let O=Buffer.alloc(L);for(let F of S)F.copy(O,y),y+=F.length;for(let F of R)F.copy(O,y),y+=F.length;let B=c.toBinary();return o&&o.copy(B,je.Constants.ENDHDR),B.copy(O,y),t=O,l=!1,O},toAsyncBuffer:function(S,R,L,y){try{l||_(),I();let C=[],O=[],B=0,F=0,V=0;c.size=0,c.offset=0;let J=function(te){if(te.length>0){let Q=te.shift(),ye=Q.entryName+Q.extra.toString();L&&L(ye),Q.getCompressedDataAsync(function(he){y&&y(ye),Q.header.offset=F;let P=Q.packLocalHeader(),H=P.length+he.length;F+=H,C.push(P),C.push(he);let K=Q.packCentralHeader();O.push(K),c.size+=K.length,B+=H+K.length,V++,J(te)})}else{B+=c.mainHeaderSize,c.offset=F,c.totalEntries=V,F=0;let Q=Buffer.alloc(B);C.forEach(function(he){he.copy(Q,F),F+=he.length}),O.forEach(function(he){he.copy(Q,F),F+=he.length});let ye=c.toBinary();o&&o.copy(ye,je.Constants.ENDHDR),ye.copy(Q,F),t=Q,l=!1,S(Q)}};J(Array.from(this.entries))}catch(C){R(C)}}}}});var Xl=se((QS,Yl)=>{var _e=sr(),we=de("path"),Lg=Aa(),Ng=Jl(),Tn=(...t)=>_e.findLast(t,e=>typeof e=="boolean"),Zl=(...t)=>_e.findLast(t,e=>typeof e=="string"),Mg=(...t)=>_e.findLast(t,e=>typeof e=="function"),Bg={noSort:!1,readEntries:!1,method:_e.Constants.NONE,fs:null};Yl.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Bg);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=_e.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new _e(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=_e.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=_e.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw _e.Errors.INVALID_FILENAME();let c=new Ng(r,i),{canonical:l,sanitize:f,zipnamefix:h}=_e;function p(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(we.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function w(_){let{join:v,normalize:I,sep:S}=we.posix;return v(we.isAbsolute(_)?"/":".",I(S+_.split("\\").join(S)+S))}function E(_){return _ instanceof RegExp?(function(v){return function(I){return v.test(I)}})(_):typeof _!="function"?()=>!0:_}let T=(_,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",we.relative(_,v)+I};return{readFile:function(_,v){var I=p(_);return I&&I.getData(v)||null},childCount:function(_){let v=p(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var I=p(_);I?I.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var I=p(_);if(I){var S=I.getData();if(S&&S.length)return S.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,I){var S=p(_);S?S.getDataAsync(function(R,L){if(L){v(R,L);return}R&&R.length?v(R.toString(I||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var I=p(_);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(_){var v=p(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var I=p(_);I&&(I.comment=v)},getZipEntryComment:function(_){var v=p(_);return v&&v.comment||""},updateFile:function(_,v){var I=p(_);I&&I.setData(v)},addLocalFile:function(_,v,I,S){if(o.fs.existsSync(_)){v=v?w(v):"";let R=we.win32.basename(we.win32.normalize(_));v+=I||R;let L=o.fs.statSync(_),y=L.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);L.isDirectory()&&(v+=o.sep),this.addFile(v,y,S,L)}else throw _e.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let I=we.resolve(_.localPath),{comment:S}=_,{zipPath:R,zipName:L}=_,y=this;o.fs.stat(I,function(C,O){if(C)return v(C,!1);R=R?w(R):"";let B=we.win32.basename(we.win32.normalize(I));if(R+=L||B,O.isFile())o.fs.readFile(I,function(F,V){return F?v(F,!1):(y.addFile(R,V,S,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),S,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,I){if(I=E(I),v=v?w(v):"",_=we.normalize(_),o.fs.existsSync(_)){let S=o.findFiles(_),R=this;if(S.length)for(let L of S){let y=we.join(v,T(_,L));I(y)&&R.addLocalFile(L,we.dirname(y))}}else throw _e.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,I,S){S=E(S),I=I?w(I):"",_=we.normalize(_);var R=this;o.fs.open(_,"r",function(L){if(L&&L.code==="ENOENT")v(void 0,_e.Errors.FILE_NOT_FOUND(_));else if(L)v(void 0,L);else{var y=o.findFiles(_),C=-1,O=function(){if(C+=1,C<y.length){var B=y[C],F=T(_,B).split("\\").join("/");F=F.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),S(F)?o.fs.stat(B,function(V,J){V&&v(void 0,V),J.isFile()?o.fs.readFile(B,function(te,Q){te?v(void 0,te):(R.addFile(I+F,Q,"",J),O())}):(R.addFile(I+F+"/",Buffer.alloc(0),"",J),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(_,v){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=we.resolve(w(_.localPath));let{zipPath:S,filter:R,namefix:L}=_;R instanceof RegExp?R=(function(O){return function(B){return O.test(B)}})(R):typeof R!="function"&&(R=function(){return!0}),S=S?w(S):"",L=="latin1"&&(L=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof L!="function"&&(L=O=>O);let y=O=>we.join(S,L(T(localPath,O))),C=O=>we.win32.basename(we.win32.normalize(L(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,_e.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(B,F){if(B)return v(B);F=F.filter(V=>R(y(V))),F.length||v(void 0,!1),setImmediate(F.reverse().reduce(function(V,J){return function(te,Q){if(te||Q===!1)return setImmediate(V,te,!1);I.addLocalFileAsync({localPath:J,zipPath:we.dirname(y(J)),zipName:C(J)},V)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((I,S)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(R,L)=>{R&&S(R),L&&I(this)})})},addFile:function(_,v,I,S){_=h(_);let R=p(_),L=R!=null;L||(R=new Lg(i),R.entryName=_),R.comment=I||"";let y=typeof S=="object"&&S instanceof o.fs.Stats;y&&(R.header.time=S.mtime);var C=R.isDirectory?16:0;let O=R.isDirectory?16384:32768;return y?O|=4095&S.mode:typeof S=="number"?O|=4095&S:O|=R.isDirectory?493:420,C=(C|O<<16)>>>0,R.attr=C,R.setData(v),L||c.setEntry(R),R},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return p(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,I,S,R,L){S=Tn(!1,S),R=Tn(!1,R),I=Tn(!0,I),L=Zl(R,L);var y=p(_);if(!y)throw _e.Errors.NO_ENTRY();var C=l(y.entryName),O=f(v,L&&!y.isDirectory?L:I?C:we.basename(C));if(y.isDirectory){var B=c.getEntryChildren(y);return B.forEach(function(J){if(J.isDirectory)return;var te=J.getData();if(!te)throw _e.Errors.CANT_EXTRACT_FILE();var Q=l(J.entryName),ye=f(v,I?Q:we.basename(Q));let he=R?J.header.fileAttr:void 0;o.writeFileTo(ye,te,S,he)}),!0}var F=y.getData(c.password);if(!F)throw _e.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!S)throw _e.Errors.CANT_OVERRIDE();let V=R?_.header.fileAttr:void 0;return o.writeFileTo(O,F,S,V),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,v,I,S){if(I=Tn(!1,I),S=Zl(I,S),v=Tn(!1,v),!c)throw _e.Errors.NO_ZIP();c.entries.forEach(function(R){var L=f(_,l(R.entryName));if(R.isDirectory){o.makeDir(L);return}var y=R.getData(S);if(!y)throw _e.Errors.CANT_EXTRACT_FILE();let C=I?R.header.fileAttr:void 0;o.writeFileTo(L,y,v,C);try{o.fs.utimesSync(L,R.header.time,R.header.time)}catch{throw _e.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,I,S){if(S=Mg(v,I,S),I=Tn(!1,I),v=Tn(!1,v),!S)return new Promise((O,B)=>{this.extractAllToAsync(_,v,I,function(F){F?B(F):O(this)})});if(!c){S(_e.Errors.NO_ZIP());return}_=we.resolve(_);let R=O=>f(_,we.normalize(l(O.entryName))),L=(O,B)=>new Error(O+': "'+B+'"'),y=[],C=[];c.entries.forEach(O=>{O.isDirectory?y.push(O):C.push(O)});for(let O of y){let B=R(O),F=I?O.header.fileAttr:void 0;try{o.makeDir(B),F&&o.fs.chmodSync(B,F),o.fs.utimesSync(B,O.header.time,O.header.time)}catch{S(L("Unable to create folder",B))}}C.reverse().reduce(function(O,B){return function(F){if(F)O(F);else{let V=we.normalize(l(B.entryName)),J=f(_,V);B.getDataAsync(function(te,Q){if(Q)O(Q);else if(!te)O(_e.Errors.CANT_EXTRACT_FILE());else{let ye=I?B.header.fileAttr:void 0;o.writeFileToAsync(J,te,v,ye,function(he){he||O(L("Unable to write file",J)),o.fs.utimes(J,B.header.time,B.header.time,function(P){P?O(L("Unable to set times",J)):O()})})}})}}},S)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var S=o.writeFileTo(_,I,!0);typeof v=="function"&&v(S?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:I,perm:S}=Object.assign({overwrite:!0},v);return new Promise((R,L)=>{!_&&i.filename&&(_=i.filename),_||L("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=O=>O?R(O):L("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,S,C)},L)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,I,S){return typeof _=="function"?(c.toAsyncBuffer(_,v,I,S),null):c.compressToBuffer()}}}});import{execFile as T_,spawn as D_,spawnSync as fA}from"node:child_process";import{promisify as R_}from"node:util";function k_(t){if(process.platform!=="win32")return!1;if(K0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(K0,"").toLowerCase();return C_.has(r)}function $0(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return k_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function lt(t,e=[],r={}){return D_(t,e,$0(t,r))}function V0(t,e=[],r={}){return O_(t,e,$0(t,r))}var C_,K0,O_,yn=Je(()=>{"use strict";C_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),K0=/\.(cmd|bat|ps1)$/i;O_=R_(T_)});var Kf=se(Le=>{"use strict";var M=q;(function(t,e){let r=q,i=t();for(;;)try{if(-parseInt(r(1308))/1+parseInt(r(521))/2*(parseInt(r(1025))/3)+-parseInt(r(798))/4+parseInt(r(910))/5+parseInt(r(1092))/6*(parseInt(r(721))/7)+-parseInt(r(707))/8*(-parseInt(r(586))/9)+-parseInt(r(735))/10*(parseInt(r(1085))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(vo,941319);var _b=Object[M(1548)+M(1609)],yb=Object["getOwnPr"+M(1093)+"mes"],Gf=(t,e)=>function(){return t&&(e=(0,t[{UQxAm:function(c,l){return c(l)}}[M(623)](yb,t)[0]])(t=0)),e},bb=(t,e)=>{let r=M,i={yBxzK:function(c,l,f,h){return c(l,f,h)}};for(var o in e)i[r(738)](_b,t,o,{get:e[o],enumerable:!0})};function Eb(){return Mf||(Mf=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function vb(){let t=M;return Bf||(Bf=[IDBCursor.prototype.advance,IDBCursor[t(1691)+"e"][t(853)],IDBCursor.prototype[t(853)+"PrimaryKey"]])}function Sb(t){let e=M,r={ncdrr:e(616),vfGJQ:e(627),zxzVe:function(o,c){return o(c)},JoCKr:function(o){return o()},YPoKx:function(o,c){return o(c)},ePInu:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,f={FvXvd:function(E,T){return r[q(1577)](E,T)},GbNgP:function(E){return r[q(764)](E)}},h=()=>{let E=q;t[E(985)+"entListe"+E(1382)](r.ncdrr,p),t[E(985)+E(1801)+E(1382)](r[E(766)],w)},p=()=>{let E=q;r.zxzVe(o,r.zxzVe(Mt,t[E(1104)])),r[E(764)](h)},w=()=>{f[q(1435)](c,t.error),f.GbNgP(h)};t.addEventListener(r.ncdrr,p),t["addEvent"+l(1223)](l(627),w)});return i[e(814)](o=>{let c=e;r[c(1543)](o,IDBCursor)&&Xc[c(1713)](o,t)})[e(1009)](()=>{}),bo[e(1713)](i,t),i}function Ib(t){let e=M,r={YwheK:function(o,c){return o<c},HQGcj:function(o,c){return o===c},Kwcat:function(o,c){return o&c},aHGtI:function(o,c){return o+c},ONQES:e(1150),rVMDM:e(627),OVvdQ:e(397),oeXXb:"OZGdv",eQXZF:function(o,c){return o(c)},dlyaL:function(o){return o()},KdXPu:function(o,c){return o===c},zXIqh:e(1026),ozsWX:e(1623)};if(yo[e(909)](t))return;let i=new Promise((o,c)=>{let l=e,f={cnyZr:function(h,p){return r[q(1811)](h,p)},fbTuu:"AbortError",DLgiT:function(h){return r.dlyaL(h)}};if(r[l(498)](r[l(1697)],r[l(806)]))_0x50845f=_0x3a6513.charCodeAt(_0x1ddb09),r[l(885)](_0x20dd2a,128)?_0x3a35bf+=1:r[l(885)](_0x55fa92,2048)?_0x2c2fdd+=2:r[l(901)](r[l(1712)](64512,_0x45d2dd),55296)&&r[l(901)](64512&_0x8e06c6[l(687)+"At"](r[l(1786)](_0xaf287c,1)),56320)?(++_0x595040,_0x4547b5+=4):_0x1d5ce5+=3;else{let h=()=>{let E=l;t[E(985)+E(1801)+"ner"](r[E(1805)],p),t[E(985)+"entListener"](r.rVMDM,w),t[E(985)+E(1801)+E(1382)](r[E(399)],w)},p=()=>{let E=l;if(r[E(901)](r[E(758)],E(651)))o(),h();else return this[E(1676)]?.[E(596)]},w=()=>{let E=l;f[E(580)](c,t[E(627)]||new DOMException(f[E(1309)],"AbortError")),f.DLgiT(h)};t[l(1073)+l(1223)](r[l(1805)],p),t[l(1073)+l(1223)]("error",w),t["addEvent"+l(1223)](l(397),w)}});yo[e(1713)](t,i)}function Ab(t){Eo={RWhKC:function(i,o){return i(o)}}[M(320)](t,Eo)}function Tb(t){let e=M,r={bTizW:function(i,o){return i(o)},iIrrk:function(i,o){return i&o},qkftT:function(i,o){return i(o)},IIpYm:function(i,o){return i&o},jTvBy:function(i,o){return i&o},ozGmd:function(i,o){return i(o)},PczlE:function(i,o){return i===o},jBfxM:e(1101),SAELE:function(i,o){return i in o},dgSqr:e(328)+"oreNames",OOOYA:function(i){return i()}};return r.PczlE(t,IDBDatabase[e(1691)+"e"]["transact"+e(330)])&&!r[e(362)](r[e(614)],IDBTransaction[e(1691)+"e"])?function(i,...o){let c=e;if(r[c(535)](r.jBfxM,r[c(1600)])){let l=t[c(332)](r[c(964)](Bi,this),i,...o);return Yc.set(l,i[c(1235)]?i[c(1235)]():[i]),r[c(672)](Mt,l)}else _0x1dbf81=r[c(964)](_0x530cb8,_0x3777ea),_0x6932fc|=r.iIrrk(127,_0x588fd1)<<14,r.iIrrk(128,_0x4fb6c9)&&(_0x1f940a=r[c(1365)](_0x4d292e,_0x4dbf8b),_0x2a42f6|=r[c(1533)](127,_0x2015e8)<<21,r[c(1533)](128,_0x1e47ae)&&(_0x39429c=r[c(1365)](_0x4a0381,_0x33333e),_0x5175ef=r.jTvBy(127,_0x3455b4),128&_0x505766&&(_0x2600e8=r.ozGmd(_0x3d01d,_0x377b95),_0x110201|=(127&_0x1d1b58)<<7)))}:r[e(802)](vb).includes(t)?function(...i){let o=e;return t[o(1633)](Bi(this),i),Mt(Xc[o(1232)](this))}:function(...i){let o=e;return Mt(t[o(1633)](r[o(964)](Bi,this),i))}}function Db(t){let e=M,r={FxrOm:e(757),TzFly:function(i,o){return i(o)},Mvnva:function(i,o,c){return i(o,c)},bbnpX:function(i){return i()}};return typeof t===r[e(556)]?r[e(1350)](Tb,t):(t instanceof IDBTransaction&&r.TzFly(Ib,t),r[e(638)](Hf,t,r[e(494)](Eb))?new Proxy(t,Eo):t)}function Mt(t){let e=M,r={woaXp:function(o,c){return o instanceof c},vnYIF:function(o,c){return o(c)}};if(r[e(1594)](t,IDBRequest))return r[e(1371)](Sb,t);if(wo[e(909)](t))return wo.get(t);let i=r[e(1371)](Db,t);return i!==t&&(wo[e(1713)](t,i),bo.set(i,t)),i}var Hf,Mf,Bf,Xc,yo,Yc,wo,bo,Eo,Bi,zf=Gf({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={iUGpH:function(r,i){return r>=i},dBcKo:function(r,i){return r===i},tIytG:function(r,i){return r-i},lixOV:function(r,i){return r!==i},owOtY:t(935),kGpwd:function(r,i){return r instanceof i},nsyKu:function(r,i){return r===i},tcVZf:t(961),Oadfa:function(r,i){return r===i},octkh:t(328)+t(1476),pDQsz:t(1074),nrkLu:function(r,i){return r instanceof i},hvpdD:function(r,i){return r===i},HZAXP:function(r,i){return r in i}};Hf=(r,i)=>i[t(514)](o=>r instanceof o),Xc=new WeakMap,yo=new WeakMap,Yc=new WeakMap,wo=new WeakMap,bo=new WeakMap,Eo={get(r,i,o){let c=t;if(e[c(333)](e[c(620)],e.owOtY))return!!(e[c(725)](this["currentI"+c(532)],this[c(1339)+"s"][c(1282)])||e[c(326)](this.currentIndex,e[c(639)](this[c(1339)+"s"].length,1))&&e[c(326)](this[c(1551)+"ndpointT"+c(998)+"t"],this.maxRetries));if(e.kGpwd(r,IDBTransaction)){if(e.nsyKu(i,e[c(1807)]))return yo[c(1232)](r);if(e[c(1472)](i,e[c(1091)]))return r[c(328)+c(1476)]||Yc[c(1232)](r);if(i===e[c(1439)])return o[c(328)+c(1476)][1]?void 0:o["objectSt"+c(1457)](o[c(328)+"oreNames"][0])}return Mt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e.nrkLu(r,IDBTransaction)&&(e[o(1340)](i,e.tcVZf)||i===e[o(1439)])?!0:e[o(1134)](i,r)}},Bi=r=>bo[t(1232)](r)}}),qf={};bb(qf,{deleteDB:()=>Cb,openDB:()=>Rb,unwrap:()=>Bi,wrap:()=>Mt});function Rb(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=M,f={puypG:function(w,E,T,_,v){return w(E,T,_,v)},mbTzl:function(w,E){return w(E)},LHvvU:l(316),HwGWH:"upgradeneeded",zDbtG:l(1186)},h=indexedDB[l(772)](t,e),p=f[l(1192)](Mt,h);return i&&h[l(1073)+"Listener"](f[l(563)],w=>{let E=l;f[E(497)](i,f[E(1192)](Mt,h[E(1104)]),w.oldVersion,w.newVersion,Mt(h[E(1671)+E(330)]))}),r&&h["addEvent"+l(1223)](f[l(475)],()=>r()),p[l(814)](w=>{let E=l;c&&w["addEvent"+E(1223)](f[E(891)],()=>c()),o&&w[E(1073)+E(1223)](E(446)+E(605),()=>o())}).catch(()=>{}),p}function Cb(t,{blocked:e}={}){let r=M,i={jVFNj:r(1186),NZNaj:function(c,l){return c(l)}},o=indexedDB[r(1084)+"tabase"](t);return e&&o["addEvent"+r(1223)](i[r(760)],()=>e()),i[r(1537)](Mt,o)[r(814)](()=>{})}function Ff(t,e){let r=M,i={FLmOQ:r(1208)+r(1710),OwOYF:"get",osOvL:r(857),CWMDi:"getAllKeys",BQlCh:"count",KVppj:function(h){return h()},TeiHC:r(1605),gQWVb:function(h){return h()},yUBab:function(h,p){return h(p)},xHzLy:function(h,p){return h===p},Byuiy:r(926),uicwU:r(1761),bxdwb:function(h,p){return h instanceof p},AVhpS:"string",meZXD:function(h,p){return h!==p},UFPkh:function(h,p){return h in p}};if(!(i[r(716)](t,IDBDatabase)&&!(e in t)&&i[r(728)](typeof e,i[r(348)])))return;if(_o[r(1232)](e))return _o[r(1232)](e);let o=e.replace(/FromIndex$/,""),c=i[r(1787)](e,o),l=Wf.includes(o);if(!i[r(1076)](o,(c?IDBIndex:IDBObjectStore)[r(1691)+"e"])||!(l||jf[r(643)](o)))return;let f=async function(h,...p){let w=r;if(i[w(728)](i.Byuiy,"mQzQT")){let E=this[w(1671)+w(330)](h,l?w(1637)+"e":i[w(1241)]),T=E[w(1074)];return c&&(T=T[w(698)](p[w(972)]())),(await Promise[w(675)]([T[o](...p),l&&E[w(961)]]))[0]}else{let E=i[w(1816)].split("|"),T=0;for(;;){switch(E[T++]){case"0":_0x384724=new _0x3a0fea;continue;case"1":_0x2db1b5=[i[w(625)],i[w(733)],w(938),i.CWMDi,i[w(1171)]];continue;case"2":i[w(876)](_0x2acdee);continue;case"3":_0x2b94e3=[w(1006),"add",i[w(1800)],w(1640)];continue;case"4":i[w(1131)](_0x3bdd36);continue;case"5":i[w(1770)](_0x5bf14f,_=>({..._,get:(v,I,S)=>_0x59571c(v,I)||_[w(1232)](v,I,S),has:(v,I)=>!!_0x54c44f(v,I)||_.has(v,I)}));continue}break}}};return _o.set(e,f),f}var jf,Wf,_o,kb=Gf({"node_modules/idb/build/index.js"(){let t=M,e={KUgDu:"4|5|3|2|"+t(671),pBRsh:function(o,c){return o(c)},UIwTp:t(1006),hhoFY:"delete",FvWjq:"clear",duqkp:"get",nOqmd:t(938),CtrDi:t(1392)+"ys",CIydF:t(1496),xWYhD:function(o){return o()}},r=e[t(704)][t(1194)]("|"),i=0;for(;;){switch(r[i++]){case"0":e[t(1758)](Ab,o=>({...o,get:(c,l,f)=>Ff(c,l)||o[t(1232)](c,l,f),has:(c,l)=>!!Ff(c,l)||o.has(c,l)}));continue;case"1":_o=new Map;continue;case"2":Wf=[e[t(944)],t(726),e[t(823)],e[t(1098)]];continue;case"3":jf=[e[t(1018)],t(857),e[t(541)],e[t(1048)],e[t(1396)]];continue;case"4":e.xWYhD(zf);continue;case"5":e.xWYhD(zf);continue}break}}}),Ob={idb:function(t){let e=M;t[e(1734)]=Promise.resolve().then(()=>(kb(),qf))[e(814)](function(r){return r})}},Uf={};function Nt(t){let e=M,r={nsXgi:function(c,l){return c!==l}};var i=Uf[t];if(r[e(1778)](void 0,i))return i[e(1734)];var o=Uf[t]={exports:{}};return Ob[t](o,o.exports,Nt),o[e(1734)]}Nt.d=(t,e)=>{let r=q;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(1548)+"operty"](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;Nt.o=(e,r)=>Object[t(1691)+"e"][t(587)+t(1609)][t(332)](e,r)})(),(()=>{let t=M,e={ROFio:function(r,i){return r!=i},puCKJ:t(1539),BdsRU:t(838)+"le"};Nt.r=r=>{let i=t;e.ROFio("undefined",typeof Symbol)&&Symbol[i(824)+i(1448)]&&Object[i(1548)+i(1609)](r,Symbol["toString"+i(1448)],{value:e[i(1314)]}),Object[i(1548)+i(1609)](r,e[i(1299)],{value:!0})}})();var Te={};(()=>{let t=M,e={aQuHq:function(a,n){return a(n)},OIUxZ:function(a,n){return a+n},amMGq:function(a,n){return a+n},rEYBF:function(a,n){return a*n},nrFHu:function(a,n,s){return a(n,s)},mvxig:function(a,n){return a+n},prZrM:function(a,n){return a(n)},cEfnR:function(a,n){return a+n},WlDEf:t(1553),ptCFF:t(1203)+t(1203)+t(1203)+t(1203),QYsBB:function(a,n){return a||n},KvprO:function(a,n){return a>n},Idegl:function(a,n){return a<n},HooIb:function(a,n){return a!==n},rtUiR:t(1564),ygLzZ:function(a,n){return a<n},KnNLz:function(a,n){return a-n},EMNEr:function(a,n){return a!==n},rKnJu:function(a,n){return a-n},WAgTq:function(a,n){return a<n},xPsmF:function(a,n){return a<n},xlJmu:function(a,n){return a===n},USOOe:function(a,n){return a<n},THJXJ:"cjnsU",QhKYL:function(a,n){return a+n},LqGnr:function(a,n){return a(n)},aARpQ:function(a,n){return a&n},uIUSz:function(a,n){return a>>>n},aTOUy:function(a,n){return a!==n},mLfLf:t(1527),lFtBU:t(337),OezXs:function(a,n,s){return a(n,s)},tofOQ:function(a,n){return a===n},cEnvV:t(1230),cjqtA:function(a,n){return a(n)},NfoFp:function(a,n){return a>>>n},qOnsb:function(a,n,s){return a(n,s)},BmUoD:function(a,n,s){return a(n,s)},woRcW:function(a,n,s){return a(n,s)},DxCUB:"Missing "+t(1307)+t(1571)+"key",OuGpi:"Missing "+t(1307)+t(1571)+t(1659),HQrsE:function(a){return a()},DCRQt:function(a,n,s){return a(n,s)},FqiFt:function(a,n){return a(n)},cJMGh:t(627),HHKzP:function(a,n,s){return a(n,s)},afLWu:"GNRgU",kstLE:function(a,n,s){return a(n,s)},FnKwN:function(a,n,s){return a(n,s)},zVCJO:t(465),LYfEU:function(a,n,s){return a(n,s)},sqcaS:function(a,n){return a(n)},kGBbe:function(a,n,s){return a(n,s)},aqIeM:function(a,n){return a!==n},xOBtA:function(a,n,s){return a(n,s)},JRHNu:function(a,n,s){return a(n,s)},pHwhD:function(a,n){return a!==n},EtlBH:"rfEnJ",VnAKz:t(1426),lVTEv:function(a,n,s){return a(n,s)},eSpbT:function(a,n,s){return a(n,s)},oYDiL:function(a,n){return a(n)},XyURO:function(a,n){return a(n)},wXjWT:function(a,n){return a(n)},hqOEI:function(a,n){return a(n)},yQuhY:function(a,n){return a!==n},CtJlu:t(1300),uzXqU:function(a,n){return a(n)},iSvlh:function(a,n){return a(n)},Qxhtu:function(a,n,s){return a(n,s)},PpGxt:function(a,n){return a(n)},PhopT:function(a,n){return a(n)},QUMiI:function(a,n,s){return a(n,s)},RIMZA:t(496)+t(1307)+t(1571)+t(828),HFNbT:function(a,n){return a===n},FQQVO:"Missing required"+t(1571)+t(1004),YSPqd:function(a,n){return a===n},PPoSw:function(a,n){return a+n},xiRmb:function(a,n){return a&n},EPucD:function(a,n,s){return a(n,s)},bVODI:function(a,n,s){return a(n,s)},rngYQ:function(a,n){return a+n},uXnnT:t(1489)+"ented ty"+t(1674),mkbia:function(a,n){return a>>n},ogybM:function(a,n){return a>=n},PoPvj:t(1401)+"or",MnDwa:"cGtwi",aDqKN:function(a,n){return a===n},cjlxR:t(323)+t(1325),yBJLy:function(a,n){return a+n},wTUZQ:function(a,n){return a>n},WWXOp:t(641)+"alled multiple t"+t(472)+"process",drfuE:function(a,n){return a+n},tedyG:function(a,n){return a!==n},htAce:t(457),ddNch:t(1617),xkPnu:function(a,n){return a+n},fIVrf:t(1449)+t(1325),svltV:function(a,n){return a+n},wLKVv:t(1199)+"e_success",cmtcd:"timeout",zKxwB:t(1199)+"e_timeout",pwkqE:"3|7|2|4|11|8|6|0|1|5|10|9",uofwF:function(a,n){return a|n},RUplk:function(a,n){return a>>>n},pmmGs:function(a,n){return a<<n},jHcAV:function(a,n){return a&n},UrvJH:function(a,n){return a|n},Fcygm:function(a,n){return a>n},Djkto:function(a,n){return a!==n},sZDjF:"CoLqa",WdoZV:"ZwtvE",vwpOx:function(a,n){return a+n},buXik:function(a,n){return a===n},loYPO:function(a,n){return a(n)},ILlcg:function(a,n){return a&n},OQfwu:function(a,n){return a+n},bmAri:function(a,n){return a+n},IKvaS:function(a,n){return a+n},sHutX:function(a,n){return a+n},eknQq:function(a,n){return a|n},xRLaf:function(a,n){return a<<n},ZwxiO:function(a,n){return a<n},RmLCo:function(a,n){return a<=n},DFNPN:function(a,n){return a==n},ToqEH:function(a,n){return a>=n},BwWso:function(a,n){return a+n},kiiFH:function(a,n){return a+n},Apoxy:function(a,n){return a!==n},rFhCc:function(a,n){return a|n},PSnbB:function(a,n){return a|n},MTBTO:function(a,n){return a<<n},fXYGZ:function(a,n){return a|n},MXzFD:function(a,n){return a|n},AbTte:function(a,n){return a&n},pcJvI:function(a,n){return a&n},RDDYX:function(a,n){return a+n},QJpjM:function(a,n){return a+n},kvjTc:function(a,n){return a||n},HiTgn:function(a,n){return a===n},aLZzg:t(1461),FmVFj:function(a,n){return a<n},BeGMJ:function(a,n){return a-n},bpRlI:function(a,n){return a<n},rUjWj:function(a,n){return a<n},QGWGF:function(a,n){return a<n},lxYGx:function(a,n,s){return a(n,s)},FmfZs:function(a,n){return a<=n},CRUFi:function(a,n){return a<n},Bdpou:function(a,n){return a+n},dFfzb:function(a,n){return a<n},wPnwW:function(a,n){return a&n},rejYW:function(a,n){return a&n},FwCGx:function(a,n){return a&n},IDYIG:function(a,n){return a|n},bHoiK:function(a,n){return a&n},kzPqU:function(a,n){return a|n},PkGNO:function(a,n,s){return a(n,s)},mMDph:function(a,n){return a===n},xqKUk:"send_ack",AzGeU:t(1692),EqPyt:t(965),HEkhu:function(a,n){return a<n},xiXQP:function(a,n){return a<<n},rVUmd:function(a,n){return a|n},jbZSZ:t(1828),SFQOw:function(a,n){return a&n},exNpL:function(a,n){return a!==n},VhSwY:t(974),GqcaJ:function(a,n){return a<<n},uRsSH:function(a,n){return a(n)},MINzz:function(a,n){return a&n},TBjld:function(a,n){return a<<n},emTlC:function(a,n){return a(n)},SUwkw:function(a,n){return a&n},RevgH:function(a,n){return a<<n},nRdTH:"nCuBT",jkmTh:function(a,n){return a&n},NyJAI:function(a,n){return a(n)},vdquZ:function(a,n){return a|n},bSVKl:function(a,n){return a<<n},bIEKg:function(a,n){return a|n},bVTzb:function(a,n){return a<<n},nsupv:function(a,n){return a<n},Gkubs:function(a,n){return a<n},oMSMJ:function(a,n){return a<n},kIrUv:function(a,n){return a+n},INOpf:function(a,n){return a+n},xuxAr:function(a,n){return a!==n},culCd:function(a,n){return a+n},DUDNh:function(a,n){return a|n},VuubY:function(a,n){return a>>>n},bVlXN:function(a,n){return a!==n},LDnsk:function(a,n){return a&n},XxikE:function(a,n){return a>>>n},QcWMr:function(a,n){return a|n},ujcAZ:function(a,n){return a+n},aqsgX:function(a,n){return a|n},kfaQT:function(a,n){return a>>>n},oWKmj:function(a,n){return a|n},PUGTe:function(a,n){return a&n},JrNxn:function(a,n){return a|n},XIOaL:function(a,n){return a|n},Ipcvy:function(a,n){return a|n},tHTsm:function(a,n){return a===n},btkaj:"DiQNu",Aiofg:function(a,n){return a<<n},KCLuu:function(a,n){return a|n},hjUZX:function(a,n){return a|n},OxwUg:function(a,n){return a<<n},WqPPC:function(a,n){return a<<n},lwZIF:function(a,n){return a(n)},ejlQp:function(a,n){return a===n},mnowR:t(1792),aierI:t(684),vFcEc:function(a,n){return a|n},AJzyp:function(a,n){return a|n},hCCTr:function(a,n){return a<<n},fsoqY:function(a,n){return a|n},moEne:function(a,n){return a<<n},zGSXh:function(a,n){return a|n},IvGKg:function(a,n){return a|n},PXPhJ:function(a,n){return a<<n},TkSuA:function(a,n){return a<<n},lNQVL:function(a,n){return a<<n},ArdDF:function(a,n){return a&n},GxwmE:function(a,n){return a&n},OYhTa:function(a,n){return a>>>n},gtYUT:function(a,n){return a>>>n},QXJlB:function(a,n){return a&n},GzqbB:function(a,n){return a&n},ebnnU:function(a,n){return a>>>n},NiLgo:function(a,n){return a>>>n},fuMGj:function(a,n){return a>=n},mMsjz:function(a,n){return a+n},jhDUz:function(a,n){return a/n},ozlFK:function(a,n){return a+n},jdZUF:function(a,n){return a*n},FbGIg:function(a,n){return a+n},xilHS:function(a,n){return a>>>n},yMCyI:function(a,n){return a&n},JhisM:function(a,n){return a>>>n},gxyBO:function(a,n){return a&n},TdXMZ:function(a,n){return a!==n},vmZWb:function(a,n){return a===n},BvpJc:function(a,n){return a===n},IYsEk:function(a,n){return a===n},IGKlp:function(a,n){return a===n},rpICs:function(a,n){return a+n},xWufh:function(a,n){return a||n},IpblI:function(a,n){return a!=n},iJUaI:t(640)+"d",BlupC:t(479),GBVGe:t(1491),TVFtC:function(a,n){return a&n},JVlOL:function(a,n){return a>>>n},YdKde:function(a,n){return a>>>n},fEEYy:function(a,n){return a>>>n},fKSPL:function(a,n){return a&n},ZxkGE:function(a,n){return a&n},LsirA:function(a,n){return a&n},OpvOm:function(a,n){return a>>>n},UnWrX:function(a,n){return a>>>n},LVLsx:function(a,n){return a&n},CaMgd:function(a,n){return a>>>n},CTgtl:function(a,n){return a>>>n},yogGH:function(a,n){return a&n},tiBhT:"NATIVE_E"+t(755),Khriq:"MAX_RETR"+t(811)+"R",GJhxv:t(722)+t(415),BjHrB:t(667)+"OR",ruliZ:t(862)+t(702),dzEXc:function(a,n,s,d){return a(n,s,d)},DtnQZ:function(a,n){return a+n},bnCnm:function(a,n){return a===n},uNxPK:t(401),vtHXt:"lMqHI",fWnJC:"jCUcR",pGuct:t(1287),WjHRM:t(1057),Rtpai:t(1341),IXDDQ:function(a,n,s){return a(n,s)},Mmdgl:t(703),qMlyl:function(a,n){return a===n},MgRqK:t(426),qihBz:function(a,n){return a===n},mVHBE:function(a,n){return a==n},IxHnV:t(1493),GYOnW:function(a,n){return a==n},pWVjx:t(783),oWMye:function(a,n){return a+n},GWiYw:t(1507),YKdGN:function(a,n){return a||n},lgMAM:" > ",qLPQr:t(313),lJrIM:function(a,n){return a+n},kzvHF:function(a,n){return a+n},WFNtD:function(a,n){return a===n},lOtbE:function(a,n){return a===n},ByNep:t(316),kpuhB:t(1163),ubfae:t(1570),fFrbY:t(772),upjHx:function(a,n){return a!==n},qubhV:"UVHhX",cYRAj:function(a,n){return a instanceof n},hpjQi:function(a,n){return a!==n},VrFoM:"fCUoI",DawtN:t(960)+"1",hnkPW:function(a,n){return a===n},QsiNm:function(a,n){return a+n},UBIBq:function(a,n){return a+n},bhxXn:function(a,n){return a<=n},uLiUc:function(a,n){return a|n},FUiYS:function(a,n){return a&n},ompGy:function(a,n){return a&n},kENIe:function(a,n){return a>=n},ESWDn:function(a,n){return a-n},VUWFQ:function(a,n){return a|n},TVyuZ:function(a,n){return a>>n},tzTkk:function(a,n){return a&n},IBQhH:function(a,n){return a<n},XajiI:function(a,n){return a!==n},LFJbB:function(a,n){return a<n},vaZmv:function(a,n){return a|n},DcMzI:t(488)+t(456),ervRq:function(a,n){return a&n},ZNyjV:function(a,n){return a>>n},YRQJX:function(a,n){return a>>n},jIkTI:function(a,n){return a|n},hJXNV:function(a,n){return a>>n},PrEYF:function(a,n){return a-n},znjXL:function(a,n){return a==n},afTZo:function(a,n,s,d){return a(n,s,d)},eIDKL:function(a,n){return a instanceof n},rPtiE:function(a,n){return a|n},tNUXm:function(a,n){return a&n},vaCvq:function(a,n){return a<n},KFRgH:function(a,n){return a(n)},nTDwb:function(a,n){return a!=n},emeME:t(531),TYIDu:function(a,n){return a instanceof n},UhChe:function(a,n){return a!=n},GrlmM:function(a,n){return a!==n},ucsaa:t(1732),EIuRQ:t(666)+"in;chars"+t(778),grJuB:t(1467),UoTeN:t(1238),KhjaP:t(573),DHrYx:t(616),wGpDW:function(a,n){return a===n},EePjs:function(a,n,s){return a(n,s)},XNRar:t(840),kVLqJ:t(1421)+t(431),CTcZw:function(a,n,s){return a(n,s)},cXggL:t(754)+"ascript",tlYCp:t(544),tftuA:t(1590)+t(461)+t(1157)+"P",bRaEk:t(889),Rlili:t(668),ptsVK:function(a){return a()},AjWsi:t(769),sXFlb:t(847),ZRcrW:"offline",xJgcQ:t(1540),JGdta:"mlFEy",QswfL:function(a,n){return a!==n},DzvTG:t(1766),BMgpu:t(1611),RNfjs:function(a,n){return a===n},iqdaP:t(452),ZRUAH:t(1255),ElBiQ:function(a,n){return a instanceof n},wHVnP:t(1245)+t(1175),TboWf:t(1746)+"e",YfxPO:t(360),flMnl:t(1606),TUuqn:function(a,n){return a(n)},wuSqF:function(a,n){return a<n},TSDzv:function(a,n){return a<<n},QfgIv:function(a,n){return a&n},lfQgd:t(711),eRVRy:"oEJFF",XvjrU:function(a,n){return a(n)},hEiDM:t(945)+t(1336),qdgac:t(490)+t(613)+t(951),rBYrh:"cursor.service",MzcEP:function(a,n,s,d){return a(n,s,d)},iZIDN:function(a,n,s,d){return a(n,s,d)},wDNJI:t(1172),MPgXJ:"header",JUxFL:t(1302)+t(955),VnmrE:function(a,n,s,d){return a(n,s,d)},Llljb:t(1703),eAUZc:t(1373),UzXJR:"nDbse",rsNgS:function(a,n){return a||n},FIDsB:function(a,n){return a||n},RcRjr:function(a,n){return a||n},zWZXB:function(a,n){return a||n},pxoxv:function(a,n){return a===n},ODaEp:t(922),iPYTH:t(1403),aWqRS:function(a,n){return a||n},oYcck:function(a,n){return a||n},zaKzL:t(344)+t(345)+"d",swnbC:function(a,n){return a===n},VWbEE:t(1065),hiUmm:"message_id",zlbiW:function(a,n){return a&n},MwoFJ:function(a,n){return a&n},gXlyQ:function(a,n){return a>>>n},bmRIE:function(a,n){return a&n},KJdVQ:function(a,n){return a>>>n},dDFFN:function(a,n){return a>>>n},hONbF:t(1118),hoZWk:"BOvGW",GNgPj:function(a,n,s){return a(n,s)},SDIcf:function(a,n){return a(n)},vomrY:function(a,n){return a(n)},pryGN:function(a,n,s,d){return a(n,s,d)},euljQ:function(a,n,s,d){return a(n,s,d)},MRcoh:"x_fronti"+t(489)+"ck",HWLMP:t(396)+t(504)+"k",ubIyw:function(a,n,s){return a(n,s)},DFwyD:function(a,n){return a&&n},DUYzn:t(894),Dfoqn:function(a,n){return a||n},iAHVH:t(1824),jLrxP:t(378),owIVK:function(a,n,s){return a(n,s)},PgchB:t(1738),xXJpT:t(1503),huzhq:function(a,n){return a(n)},NTTqO:t(1735),vcFQg:t(1458),NLNpd:function(a,n){return a instanceof n},cELOc:function(a,n){return a instanceof n},DLdcd:function(a,n){return a instanceof n},FIHCp:function(a,n){return a>n},UupZm:function(a,n){return a(n)},dZrxy:function(a,n){return a>n},LhewE:function(a,n){return a+n},zlRJa:function(a,n){return a(n)},zgUZT:function(a,n){return a+n},smJaz:function(a,n){return a+n},fkvFi:function(a,n){return a>=n},ImIgs:function(a,n,s,d){return a(n,s,d)},uOvXr:function(a,n){return a+n},wIKVY:function(a,n){return a+n},pYSaA:function(a,n){return a<<n},SIrPW:t(1148)+"3",wIifx:function(a,n){return a+n},RFcOM:function(a,n){return a+n},lORbS:function(a,n){return a|n},PSfqq:function(a,n){return a<<n},hjvSX:function(a,n){return a<<n},hebRv:function(a,n){return a<<n},BLkYd:function(a,n){return a+n},OPrNl:function(a,n){return a+n},cYdfV:function(a,n){return a&n},sZmkF:function(a,n){return a>>>n},cxzZn:function(a,n){return a&n},hHeXT:function(a,n){return a+n},YyGLi:function(a,n){return a>>>n},qIqmW:function(a,n){return a+n},Zjtih:function(a,n){return a+n},UhZAv:function(a,n){return a+n},bIyzy:function(a,n){return a&n},FdvVt:function(a,n){return a+n},qVEDu:t(1245)+t(1175)+t(993)+t(572),TWItm:function(a,n,s,d){return a(n,s,d)},pZNlk:function(a,n){return a===n},xjfrH:t(1002),HxjUA:t(1635),Xyukh:t(1132)+t(1069)+t(1187)+"4",fHJnN:function(a,n){return a>>>n},lJgHZ:function(a,n){return a|n},fOXZa:function(a,n){return a>>>n},KZFaH:function(a,n){return a&n},Hanql:function(a,n){return a>n},xOvmQ:function(a,n){return a>>>n},YbusG:function(a,n){return a&n},unBSd:function(a,n){return a<n},jEDod:function(a,n,s){return a(n,s)},RBrem:t(992),RhBkv:t(350),HPQoz:function(a,n,s,d){return a(n,s,d)},kGjjY:t(955),XqwpC:t(1720),cBpaW:function(a,n){return a(n)},QdNVi:function(a,n){return a<n},JEHEY:function(a,n,s){return a(n,s)},OMklI:function(a,n,s){return a(n,s)},PvFzL:function(a,n){return a+n},NLywz:t(1603)+t(1568),TihJI:function(a,n,s){return a(n,s)},XHILn:t(800),jDAmr:t(861),uMSwy:function(a){return a()},fpcRc:t(1071),hLGpJ:t(526),InLDY:t(513),VAahq:function(a,n){return a||n},pUNxV:function(a){return a()},kIdbp:t(1189),fHpSx:t(510),wmCnn:t(912)+"r",hnEah:t(846),KeomC:function(a,n){return a*n},eLrud:function(a,n){return a-n},SzIFM:t(821),WhUug:t(1793),JPchH:function(a,n,s){return a(n,s)},ovzwJ:t(396)+t(1055),GZeDL:function(a,n){return a(n)},zZEZy:t(396)+t(762),sPoPH:function(a,n,s,d){return a(n,s,d)},SDcaa:t(1395)+"s",TKJMl:function(a,n,s){return a(n,s)},Wrbky:t(1243)+t(1375)+"e",ZLCYb:function(a,n){return a(n)},MfIhz:function(a){return a()},opvdT:function(a,n){return a>n},PZLUb:function(a,n){return a+n},fscaX:function(a,n){return a!==n},wyRhz:function(a){return a()},mVjCn:function(a){return a()},drqXK:function(a){return a()},QDcno:function(a){return a()},XshfC:function(a,n){return a===n},HeNgs:function(a){return a()},ghlzI:function(a,n,s){return a(n,s)},QSqtW:function(a){return a()},jDOvB:function(a){return a()},nuJcX:function(a,n,s){return a(n,s)},hwPqZ:function(a,n,s,d){return a(n,s,d)},JixNZ:function(a,n){return a===n},neEdd:function(a,n){return a===n},fpRVH:function(a,n,s,d){return a(n,s,d)},fryXd:function(a,n){return a!==n},BZhLr:"YHFxg",yffjr:function(a,n,s){return a(n,s)},DErRw:function(a,n){return a===n},TQHyI:function(a,n,s){return a(n,s)},gERxX:function(a,n,s){return a(n,s)},CTVTE:function(a,n,s){return a(n,s)},KUtUJ:"pbbp2",KQnaW:function(a,n){return a/n},KaPrc:t(1443),WLvKq:function(a,n){return a==n},BrFHe:t(871)+"rovide ws params, WebSoc"+t(786)+t(1399)+t(1231)+"ined",WAcVq:function(a,n,s){return a(n,s)},Ojfnh:t(691)+"t",trkjs:t(1050)+"ediately"+t(418)+"ct",GJLXB:"pageshow",CKLVw:"NRXrW",HwIgF:"ws://",Jytdi:t(652),RiGSz:t(1113)+"d",NEmCc:t(871)+"rovide b"+t(525)+t(591)+"r ttwID",SPcTO:function(a,n){return a==n},hvyaA:"web",PwotS:t(1771)+"0",sYgpv:function(a,n){return a<n},KvKHN:function(a,n){return a>n},UHgGF:function(a,n){return a+n},vEKJH:function(a,n){return a&n},eDPHD:function(a,n){return a|n},gwYhS:function(a,n){return a&n},lufsN:function(a,n){return a&n},tNUZZ:function(a,n){return a>n},dNCJX:t(1582),vrIoN:function(a,n){return a||n},IySYv:t(719),PhhjY:function(a,n,s){return a(n,s)},aSYxq:function(a,n){return a>n},AoHdp:function(a,n,s){return a(n,s)},ucFeF:function(a,n){return a(n)},LaEOF:t(975)+">",GTIvI:function(a,n){return a*n},wuGsI:function(a,n){return a-n},bdOLQ:function(a,n){return a>n},trFAW:function(a,n,s){return a(n,s)},CdczU:"going aw"+t(339)+"reconnec"+t(435)+t(1782),ppkkZ:function(a,n){return a<<n},CMBDP:function(a,n){return a&n},bLrdT:"bczct",WYHTd:function(a,n,s){return a(n,s)},zVQCP:t(562)+t(953)+t(1755)+"g",YKTcO:t(574),carBb:function(a,n){return a(n)},oInzL:function(a,n){return a===n},gbzzw:t(801),qgAig:t(1532),wzBDQ:t(1280)+"1",qrIYu:"ImNrB",rmpLa:t(693),pINDE:function(a,n,s){return a(n,s)},Dvreb:"bye",CCBir:t(1470)+t(1839)+t(1260)+t(366),EnshK:"1|3|4|2|0",VZvSD:"RUkrJ",ogLcR:function(a,n){return a+n},Pbhum:function(a,n){return a instanceof n},LCbdK:function(a,n){return a+n},MxHeL:function(a,n){return a!==n},yplhs:t(437),PyLIv:"mJeYh",EkwaE:t(1321)+"s instan"+t(1185)+"nitialized",deQbk:function(a,n){return a===n},pqQZH:function(a,n){return a+n},OwoYV:function(a,n,s){return a(n,s)},wIfgz:"please p"+t(1825)+t(1584)+t(346)+t(1776)+t(352)+t(543)+t(334)+t(1514),vKUrf:t(789),bIuyY:function(a,n){return a!=n},nxqeg:function(a,n){return a||n},BsYxu:t(871)+t(1825)+t(709)+t(1598),GoONv:function(a,n){return a===n},xOODc:t(1595),zGQCp:t(1492),SZymM:t(617),nlRHD:function(a,n){return a||n},SQThW:t(449)+t(835)+t(1019),RZcht:function(a){return a()},alqfM:t(633),ihRTP:t(1541),aluav:function(a,n){return a(n)},CNswc:t(732),YtHCL:function(a,n){return a===n},dZniN:function(a,n){return a===n},ghJBT:"Object",gkIJi:function(a,n){return a===n},gMVNu:t(1253)+t(367)+t(929)+"pe",HDQjX:function(a,n){return a!=n},icnia:function(a,n){return a===n},rcxQI:function(a,n){return a==n},JcYFz:function(a,n){return a!=n},mfgbj:function(a,n){return a!=n},fOAcd:function(a,n){return a===n},mNjgR:"SharedWorkerGlob"+t(1128),pCNRI:"ServiceW"+t(1100)+"balScope",ybINL:function(a,n){return a===n},gruwK:function(a,n){return a!=n},jrzvE:t(1222)+"qos__"};Nt.r(Te),Nt.d(Te,{FWS:()=>Rp,CustomErrorEvent:()=>Md,createCloseEvent:()=>xt,ReconnectEvent:()=>Nd,createErrorEvent:()=>ot,decodedFrame:()=>Xt,createOpenEvent:()=>Hd,CustomCloseEvent:()=>Bd,createReconnectEvent:()=>na,FrontierMessageEvent:()=>Fd,encodeFrame:()=>zt,createMessageEvent:()=>Gd,OpenEvent:()=>Ud,ErrorCode:()=>en,Event:()=>Jn,MessageEvent:()=>zd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(1521)](),u=r||(r=e[n(1701)](h,a)),x=Math[n(819)]()[n(824)](16)[n(559)](-6);return e[n(1210)](e[n(1210)](s+d,u),x)}function o(){let a=t;return e[a(767)](1e4*Date[a(1521)](),Math[a(713)](e[a(536)](1e4,Math[a(819)]())))}function c(a){let n=t;return e.amMGq(Array(8).join("0"),e.nrFHu(parseInt,a,10)[n(824)](2))[n(559)](-8)}function l(a){let n=t;return e[n(611)](Array(4)[n(1799)]("0"),e[n(1147)](parseInt,a,2)[n(824)](16))[n(559)](-4)}function f(a){let n=t,s=a[n(1194)](/\./)[n(727)](x=>c(x)),d=[];return d[0]=e.prZrM(l,e[n(528)](s[0],s[1])),d[1]=e.aQuHq(l,s[2]+s[3]),[e[n(1228)],e[n(1228)],n(1553),e[n(1228)],e.WlDEf,n(550),d[0],d[1]][n(1799)]("")}function h(a){let n=t,s=/(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(a),d=/(([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]))/[n(1466)](a);return s?f(a):d?e[n(1366)](p,a):e[n(849)]}function p(a){let n=t,s="",d=[],u=0,x=0,m=!0,b="0000";if(e[n(518)](a[n(958)]("::"),-1)){let g=a[n(1194)]("::");for(let k=0;e[n(1648)](k,g[n(1282)]);k++)if(e[n(1153)](n(1653),e[n(445)])){let N=g[k];if(e.KvprO(N[n(958)](":"),0)){let z=N.split(":");m&&(u=z[n(1282)]),x+=z[n(1282)];for(let Z=0;e.ygLzZ(Z,z[n(1282)]);Z++)if(e[n(1153)](4,z[Z][n(1282)])){let W=b[n(1544)+"g"](0,e[n(571)](4,z[Z].length)),Ge=W[n(657)](z[Z]);d.push(Ge)}else d[n(1524)](z[Z]);m=!1}else{if(e[n(1482)](4,N.length)){let z=b[n(1544)+"g"](0,e.rKnJu(4,N[n(1282)])),Z=z[n(657)](N);d[n(1524)](Z)}else d[n(1524)](N);m&&(u+=1),x+=1,m=!1}}else this[n(1519)+"ileName"]=_0x2ab3de;let A="";for(let k=0;e[n(1096)](k,8-x);k++)A=A[n(657)](b);for(let k=0;e[n(601)](k,d[n(1282)]);k++)e[n(1400)](k,u)?(s=s.concat(A),s=s[n(657)](d[k])):s=s.concat(d[k]);return s}{let g=a[n(1194)](":");for(let A=0;e[n(503)](A,g[n(1282)]);A++){let k=g[A];if(e[n(1153)](4,g[A][n(1282)]))if(e.xlJmu("cjnsU",e.THJXJ)){let N=b[n(1544)+"g"](0,e[n(1319)](4,g[A][n(1282)])),z=N.concat(k);s=s[n(657)](z)}else{let N=this[n(1676)][n(848)+"geSync"](this._prefix),z=_0x590319[n(1818)](e[n(454)](N,"{}"));return z[_0x23054e||_0x166804[this._pathKey]]=_0x3ba936,this._qosDB[n(1477)+"geSync"](this[n(807)],_0x3b34f4[n(1741)+"y"](z)),_0x4b365c||_0x1070ca[this._pathKey]}else s=s[n(657)](k)}return s}}function w(a,n){let s=t,d={tNsnt:function(m,b){return e[q(518)](m,b)},CptOc:function(m,b){return e.QhKYL(m,b)},EWLiO:function(m,b){return e.LqGnr(m,b)},JQVts:function(m,b){return e[q(1651)](m,b)},PSiSB:function(m,b){return m|b},yjvWW:function(m,b){return e[q(1237)](m,b)}},u=a[s(1483)];if(e[s(1379)](void 0,u))if(e[s(1482)](e[s(1170)],e.lFtBU))e[s(1242)](ue,n,10),e[s(1147)](H,n,u);else{let m=_0x16e096||8192,b=d[s(1217)](m,1),g=null,A=m;return function(k){let N=s;if(k<1||d[N(1047)](k,b))return _0x5906c2(k);d[N(1047)](d[N(439)](A,k),m)&&(g=d[N(1279)](_0x257613,m),A=0);let z=_0x150240[N(332)](g,A,A+=k);return d.JQVts(7,A)&&(A=d[N(1756)](7,A)+1),z}}let x=a[s(1659)];x!==void 0&&(e.OezXs(ue,n,18),e[s(1147)](H,n,x))}function E(a){let n=t,s={};e:for(;!e[n(1366)](J,a);)if(e[n(1251)](e[n(393)],e[n(393)])){let d=e[n(1233)](le,a);switch(e[n(584)](d,3)){case 0:break e;case 1:s[n(1483)]=e[n(1089)](P,a,e[n(1701)](le,a));break;case 2:s[n(1659)]=e[n(1275)](P,a,le(a));break;default:e[n(386)](R,a,7&d)}}else this[n(1229)+"T"]||this._isMiniWX?this[n(1601)+n(908)+n(1349)]():this[n(832)+"er"]&&this["_initGlo"+n(1531)+"Listener"]();if(e[n(1400)](void 0,s[n(1483)]))throw new Error(e[n(1597)]);if(s.value===void 0)throw new Error(e[n(524)]);return s}function T(a){let n=t,s=e.HQrsE(C);return e[n(973)](_,a,s),e[n(1335)](F,s)}function _(a,n){let s=t,d={VwoeX:function(He,Qe,at){return He(Qe,at)},oTAmZ:e[s(481)]},u=a[s(828)];u!==void 0&&(e[s(1147)](ue,n,8),e.BmUoD(ht,n,u));let x=a[s(1004)];x!==void 0&&(e[s(870)](ue,n,16),ht(n,x));let m=a[s(1172)];e[s(1379)](void 0,m)&&(s(1317)!==e[s(869)]?_0x13c780.exports=_0x459bc0[s(1155)]()[s(814)](()=>(_0x4ece2e(),_0x1b2d92))[s(814)](function(He){return He}):(e[s(1427)](ue,n,24),e[s(1434)](ht,n,e[s(1233)](L,m))));let b=a[s(533)];e[s(1153)](void 0,b)&&(ue(n,32),e.DCRQt(ht,n,e[s(1366)](L,b)));let g=a[s(659)];if(e[s(1379)](void 0,g))for(let He of g){if(e[s(1482)](s(465),e.zVCJO))return;{e[s(973)](ue,n,42);let Qe=C();e[s(870)](w,He,Qe),ue(n,Qe[s(486)]),e[s(506)](K,n,Qe),e[s(1693)](O,Qe)}}let A=a[s(487)+"ncoding"];e[s(1482)](void 0,A)&&(e.kGBbe(ue,n,50),e[s(1434)](H,n,A));let k=a[s(1621)+s(810)];e[s(1379)](void 0,k)&&(ue(n,58),H(n,k));let N=a[s(583)];e[s(1678)](void 0,N)&&(e[s(1412)](ue,n,66),ue(n,N.length),e.qOnsb(he,n,N));let z=a[s(1008)];e[s(1678)](void 0,z)&&(e[s(1209)](ue,n,74),e[s(1797)](H,n,z));let Z=a[s(1362)+s(1044)];if(e[s(1386)](void 0,Z))if(e[s(1482)](e[s(646)],e[s(482)]))e[s(1797)](ue,n,82),H(n,Z);else{let He=s(1630)+_0x32a3b1+(s(705)+s(1583)+"es reached");this._dispatchErrorEvent(d[s(1608)](_0x43a7d0,d[s(863)],{message:He,code:_0xcefec1[s(1552)+s(811)+"R"],error:_0x391dcb}));return}let W=a[s(1723)];e[s(1386)](void 0,W)&&(e[s(1670)](ue,n,90),e[s(1147)](H,n,W));let Ge=a[s(411)+"e"];e[s(1379)](void 0,Ge)&&(ue(n,96),e.eSpbT(ht,n,L(Ge)))}function v(a){let n=t;return e[n(1440)](I,e[n(1733)](B,a))}function I(a){let n=t,s={XlmGn:"enqueue"},d={};e:for(;!e.wXjWT(J,a);){let u=e[n(1693)](le,a);switch(e[n(1237)](u,3)){case 0:break e;case 1:d[n(828)]=St(a,!0);break;case 2:d.LogID=St(a,!0);break;case 3:d[n(1172)]=e[n(398)](le,a);break;case 4:d[n(533)]=le(a);break;case 5:if(e[n(1672)](e[n(851)],e.CtJlu))this[n(1315)+n(427)].push(_0x1c1edb),this._debug(s[n(1522)],_0x17e06e);else{let x=S(a);(d.headers||(d[n(659)]=[])).push(e[n(1567)](E,a)),a[n(486)]=x;break}case 6:d["payloadE"+n(1304)]=e[n(1412)](P,a,le(a));break;case 7:d[n(1621)+n(810)]=e[n(870)](P,a,e[n(903)](le,a));break;case 8:d[n(583)]=e.woRcW(ye,a,e[n(1693)](le,a));break;case 9:d[n(1008)]=e[n(1209)](P,a,e[n(1567)](le,a));break;case 10:d[n(1362)+n(1044)]=e[n(1028)](P,a,e.PpGxt(le,a));break;case 11:d.msgID=e.qOnsb(P,a,le(a));break;case 12:d[n(411)+"e"]=e[n(1769)](le,a);break;default:e[n(331)](R,a,7&u)}}if(d[n(828)]===void 0)throw new Error(e[n(1819)]);if(e[n(1248)](void 0,d.LogID))throw new Error(e.FQQVO);if(e[n(1251)](void 0,d[n(1172)]))throw new Error(n(496)+n(1307)+n(1571)+n(1172));if(e[n(1607)](void 0,d.method))throw new Error(n(496)+n(1307)+n(1571)+n(533));return d}function S(a){let n=t,s=e[n(1440)](le,a),d=a.limit;return a[n(486)]=e[n(1329)](a[n(1124)],s),d}function R(a,n){let s=t;switch(n){case 0:for(;e[s(1133)](128,e[s(553)](ie,a)););break;case 2:e[s(1322)](V,a,le(a));break;case 5:e[s(977)](V,a,4);break;case 1:e[s(1690)](V,a,8);break;default:throw new Error(e[s(952)](e[s(1614)],n))}}function L(a){return a|=0,{low:a,high:e.mkbia(a,31),unsigned:e.ogybM(a,0)}}let y=[];function C(){let a=t,n=y.pop();return n?(n[a(1124)]=n[a(486)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){let n=t;e[n(1386)](n(937),e[n(392)])?(pljtei[n(903)](_0x7705e3,_0x206a09[n(627)]||new _0x6768d5(n(1401)+"or",pljtei.PoPvj)),pljtei.HQrsE(_0x563009)):y.push(a)}function B(a){return{bytes:a,offset:0,limit:a[t(1282)]}}function F(a){let n=t,s=a.bytes,d=a[n(486)];return e.aDqKN(s[n(1282)],d)?s:s[n(1183)](0,d)}function V(a,n){let s=t;if(e[s(518)](e.OIUxZ(a.offset,n),a[s(486)]))throw new Error(e.cjlxR);a.offset+=n}function J(a){let n=t;return e[n(986)](a.offset,a[n(486)])}function te(a,n){let s=t,d=a[s(890)],u=a[s(1124)],x=a[s(486)],m=e[s(1806)](u,n);if(e[s(606)](m,d.length)){let b=new Uint8Array(e[s(536)](2,m));b[s(1713)](d),a[s(890)]=b}return a.offset=m,m>x&&(a[s(486)]=m),u}function Q(a,n){let s=t,d={CGJCo:function(u,x){return u<=x},evzZC:e[s(1798)],pTxlh:function(u,x){return e[s(809)](u,x)},inDQV:function(u,x){return e[s(1438)](u,x)}};if(e[s(1545)](e[s(1788)],e.ddNch)){let u=a[s(1124)];if(e[s(606)](e[s(1743)](u,n),a[s(486)]))throw new Error(e[s(1330)]);return a[s(1124)]+=n,u}else return d[s(1775)](_0x3be271,_0x3bd766)?_0x2d6e79[s(642)](new _0x2121ee(d[s(1834)])):(_0x28d4df=_0x501023,d[s(1225)](_0x1eb1f9,_0x505220[s(1282)])?_0xe9eaa5[s(1155)]():_0x42a1a3[_0x4d7590][s(1504)](_0x29c6df)(_0x811415,_0x10a821[s(1504)](null,d[s(1830)](_0x5ac229,1))))}function ye(a,n){let s=t,d=e[s(977)](Q,a,n);return a[s(890)][s(1183)](d,e[s(1822)](d,n))}function he(a,n){let s=t,d=e[s(973)](te,a,n[s(1282)]);a[s(890)].set(n,d)}function P(a,n){let s=t,d={QPlva:function(u,x,m){return e[q(1209)](u,x,m)},vmpwX:e[s(1569)],VNxVP:e[s(1773)],yKdmy:e[s(407)],uyIyR:function(u,x){return e[s(1620)](u,x)},YwPAr:function(u,x){return e.RUplk(u,x)},RYmAP:function(u,x){return u|x},paTYf:function(u,x){return e.pmmGs(u,x)},rpgzP:function(u,x){return e[s(1133)](u,x)},OAGOe:function(u,x){return u|x},FkhKp:function(u,x){return e.jHcAV(u,x)},ipzmf:function(u,x){return u<x},CETip:function(u,x){return e[s(1620)](u,x)},COqgJ:function(u,x){return e.xPsmF(u,x)},YrjqN:function(u,x){return e[s(1357)](u,x)},KiGPD:function(u,x){return e[s(1699)](u,x)}};if(e[s(1257)](s(1391),e.sZDjF)){let u={LByfL:function(x,m){return x(m)},RJxvN:e[s(1569)],LSrox:function(x,m){return e[s(1440)](x,m)},geSum:e.cmtcd};return new _0x5b0911((x,m)=>{let b=s;this[b(756)+"ngTimer"](),this[b(1327)+b(784)+"Id"]=d[b(1604)](_0x420490,this[b(1474)][b(1504)](this),this[b(1110)][b(948)+"rval"]);let g=()=>{let k=b;u[k(1107)](x,k(616)),this.off(u[k(842)],g),this[k(867)](k(1199)+k(827)+"t",A)},A=()=>{let k=b;u[k(1481)](m,u[k(1683)]),this[k(867)](k(1199)+k(1656)+"s",g),this[k(867)](k(1199)+k(827)+"t",A)};this.on(d.vmpwX,g),this.on(d[b(917)],A),this._ping()})}else{let u=e[s(1434)](Q,a,n),x=String[s(715)+s(1420)],m=a[s(890)],b="\uFFFD",g="";for(let A=0;A<n;A++)if(e.HooIb(e[s(845)],e[s(845)])){let k=4294967295;return function(N,z,Z=!0){let W=s,Ge=d.yKdmy.split("|"),He=0;for(;;){switch(Ge[He++]){case"0":if(N[z++]<128)return{value:Z?k:d[W(356)](0,k),offset:z};continue;case"1":k=d[W(447)](d[W(1059)](k,d[W(989)](d.rpgzP(15,N[z]),28)),0);continue;case"2":k=d[W(1115)](k,d.paTYf(d[W(653)](127,N[z]),7))>>>0;continue;case"3":k=d[W(447)](d[W(653)](127,N[z]),0);continue;case"4":if(N[z++]<128)return{value:Z?k:0|k,offset:z};continue;case"5":if(N[z++]<128)return{value:Z?k:d[W(1059)](0,k),offset:z};continue;case"6":k=(k|d[W(989)](d[W(1123)](127,N[z]),21))>>>0;continue;case"7":if(d[W(886)](N[z++],128))return{value:Z?k:d.CETip(0,k),offset:z};continue;case"8":if(d.COqgJ(N[z++],128))return{value:Z?k:d[W(1490)](0,k),offset:z};continue;case"9":return{value:Z?k:0|k,offset:z};case"10":if(d[W(771)](z+=5,N[W(1282)]))throw z=N[W(1282)],_0x5193d3(z,10,N[W(1282)]);continue;case"11":k=d[W(447)](k|(127&N[z])<<14,0);continue}break}}}else{let k=m[e.vwpOx(A,u)],N,z,Z,W;e[s(1607)](e[s(906)](128,k),0)?g+=x(k):e[s(357)](224&k,192)?e[s(986)](e[s(611)](A,1),n)?g+=b:(N=m[e.QhKYL(e[s(1202)](A,u),1)],e[s(1678)](e[s(1651)](192,N),128)?g+=b:(W=e.pmmGs(31&k,6)|e.jHcAV(63,N),W<128?g+=b:(g+=e.loYPO(x,W),A++))):e[s(1045)](240,k)==224?e.ogybM(e[s(1262)](A,2),n)?g+=b:(N=m[e[s(552)](e[s(1210)](A,u),1)],z=m[e[s(626)](e[s(412)](A,u),2)],e.Djkto(e[s(1357)](N,z<<8)&49344,32896)?g+=b:(W=e[s(1730)](e.pmmGs(e[s(1651)](15,k),12)|e[s(1429)](e[s(1133)](63,N),6),e[s(1045)](63,z)),e.ZwxiO(W,2048)||e[s(986)](W,55296)&&e[s(900)](W,57343)?g+=b:(g+=e[s(1733)](x,W),A+=2))):e[s(1423)](248&k,240)?e[s(467)](e[s(1438)](A,3),n)?g+=b:(N=m[e[s(1202)](e.cEfnR(A,u),1)],z=m[e[s(1374)](e[s(1438)](A,u),2)],Z=m[e.kiiFH(A+u,3)],e.Apoxy(e[s(906)](e.rFhCc(e.PSnbB(N,e[s(956)](z,8)),e[s(1064)](Z,16)),12632256),8421504)?g+=b:(W=e.UrvJH(e.fXYGZ(e[s(484)](e[s(956)](e[s(589)](7,k),18),e[s(1429)](e[s(906)](63,N),12)),e.MTBTO(63&z,6)),e[s(880)](63,Z)),e[s(503)](W,65536)||W>1114111?g+=b:(W-=65536,g+=x(e[s(692)](W>>10,55296),e[s(1419)](1023&W,56320)),A+=3))):g+=b}return g}}function H(a,n){let s=t;if(e.HiTgn("uPciR",e[s(568)])){let d=this[s(1676)].getItem(this._prefix),u=_0x1319fc[s(1818)](e.kvjTc(d,"{}"));return _0x4a192c.keys(u)}else{let d=n[s(1282)],u=0;for(let b=0;e[s(503)](b,d);b++){let g=n[s(687)+"At"](b);g>=55296&&e[s(900)](g,56319)&&e[s(999)](e.mvxig(b,1),d)&&(g=e[s(1291)](e.pmmGs(g,10)+n[s(687)+"At"](++b),56613888)),u+=e[s(1240)](g,128)?1:e.rUjWj(g,2048)?2:e.QGWGF(g,65536)?3:4}e.lxYGx(ue,a,u);let x=e.woRcW(te,a,u),m=a[s(890)];for(let b=0;b<d;b++){let g=n[s(687)+"At"](b);e[s(467)](g,55296)&&e.FmfZs(g,56319)&&e[s(1398)](b+1,d)&&(g=e[s(571)](e[s(782)](e[s(956)](g,10),n[s(687)+"At"](++b)),56613888)),e[s(1193)](g,128)?m[x++]=g:(g<2048?m[x++]=e.wPnwW(e[s(1442)](g,6),31)|192:(e[s(1648)](g,65536)?m[x++]=e[s(484)](e[s(1268)](e[s(1442)](g,12),15),224):(m[x++]=e.FwCGx(g>>18,7)|240,m[x++]=e[s(1515)](e[s(700)](e[s(1442)](g,12),63),128)),m[x++]=e.MXzFD(e.rejYW(e[s(1442)](g,6),63),128)),m[x++]=e[s(1650)](e.jHcAV(63,g),128))}}}function K(a,n){let s=t,d=e[s(1010)](te,a,n[s(486)]),u=a[s(890)],x=n.bytes;for(let m=0,b=n[s(486)];e[s(1240)](m,b);m++)u[m+d]=x[m]}function ie(a){let n=t;if(e[n(1678)](e[n(1286)],e[n(1052)]))return a[n(890)][e[n(977)](Q,a,1)];{let s=_0x200154(_0x27266e);this[n(1745)]&&e[n(1151)](this[n(1745)][n(1152)+"te"],this.OPEN)&&(this._ws&&this[n(1745)][n(1619)](s),this._debug(e[n(677)],_0x12dda6))}}function Ve(a,n){let s=te(a,1);a.bytes[s]=n}function le(a){let n=t,s=0,d=0,u;do u=e[n(1662)](ie,a),e.HEkhu(s,32)&&(d|=e[n(780)](e[n(700)](127,u),s)),s+=7;while(128&u);return d}function ue(a,n){let s=t;for(n>>>=0;n>=128;)e[s(1010)](Ve,a,e[s(1264)](e[s(1045)](127,n),128)),n>>>=7;e[s(1322)](Ve,a,n)}function St(a,n){let s=t,d=0,u=0,x=0,m;return m=e[s(1733)](ie,a),d=e.FwCGx(127,m),e[s(1256)](128,m)&&(e.exNpL(s(974),e.VhSwY)?(e.LYfEU(_0x403b62,_0xae38a,16),_0x3fe2d4(_0x440b27,_0x48f314)):(m=e.oYDiL(ie,a),d|=e[s(1037)](127&m,7),128&m&&(m=e.uRsSH(ie,a),d|=e[s(1127)](127,m)<<14,128&m&&(m=ie(a),d|=e.TBjld(127&m,21),e[s(1133)](128,m)&&(m=e[s(895)](ie,a),u=e.AbTte(127,m),e[s(897)](128,m)&&(m=ie(a),u|=e.RevgH(e[s(1127)](127,m),7),e[s(589)](128,m)&&(e[s(809)](e.nRdTH,s(1833))?(m=ie(a),u|=(127&m)<<14,e[s(1062)](128,m)&&(m=e[s(1628)](ie,a),u|=e[s(1045)](127,m)<<21,e.bHoiK(128,m)&&(m=e[s(1440)](ie,a),x=127&m,e.jkmTh(128,m)&&(m=ie(a),x|=(127&m)<<7)))):(this[s(1560)](e[s(1726)],_0x5e8d3e),this[s(1724)+s(522)]&&this.onReceiveAck(_0x38e84d))))))))),{low:e[s(1088)](d,e[s(1064)](u,28)),high:e[s(1264)](e[s(584)](u,4),e[s(1572)](x,24)),unsigned:n}}function ht(a,n){let s=t,d=n[s(595)]>>>0,u=e[s(1237)](e[s(1013)](e[s(478)](n[s(595)],28),e[s(983)](n.high,4)),0),x=e[s(584)](n[s(466)],24),m=e[s(1151)](0,x)?e[s(1607)](0,u)?e[s(410)](d,16384)?d<128?1:2:e.Gkubs(d,2097152)?3:4:e[s(601)](u,16384)?u<128?5:6:e[s(1381)](u,2097152)?7:8:e[s(1381)](x,128)?9:10,b=te(a,m),g=a.bytes;switch(m){case 10:g[e[s(1501)](b,9)]=e[s(700)](e.NfoFp(x,7),1);case 9:g[e.INOpf(b,8)]=e[s(1017)](9,m)?128|x:127&x;case 8:g[e.culCd(b,7)]=m!==8?e[s(1740)](e[s(478)](u,21),128):e.ILlcg(e[s(1586)](u,21),127);case 7:g[b+6]=e.bVlXN(7,m)?u>>>14|128:e[s(1035)](e[s(915)](u,14),127);case 6:g[b+5]=m!==6?e[s(773)](e.XxikE(u,7),128):e[s(1035)](u>>>7,127);case 5:g[e[s(527)](b,4)]=e[s(1257)](5,m)?128|u:127&u;case 4:g[e[s(412)](b,3)]=e[s(1672)](4,m)?e[s(355)](e[s(1586)](d,21),128):e[s(679)](e[s(584)](d,21),127);case 3:g[e[s(527)](b,2)]=m!==3?e[s(1169)](d,14)|128:e[s(1169)](d,14)&127;case 2:g[e[s(1822)](b,1)]=e[s(1379)](2,m)?e[s(759)](d>>>7,128):e[s(1841)](d>>>7,127);case 1:g[b]=m!==1?e[s(699)](128,d):e[s(1035)](127,d)}}function Xt(a){return v(a)}function zt(a){return e.hqOEI(T,a)}let Qt=65536,Gr=e[t(1463)],ge=Qt*Qt,Se=ge*ge,Vn=Se/2,Re=String[t(1691)+"e"][t(687)+"At"];class ce{constructor(n,s,d){let u=t;this[u(690)]=!0,this[u(595)]=e[u(1337)](0,n),this[u(466)]=e[u(1432)](0,s),this[u(882)]=!!d}static[t(690)](n){return n&&e[t(1191)](!0,n.isLong)}static[t(632)](n,s,d){return new ce(n,s,d)}static fromBytes(n,s,d){let u=t;if(e[u(1631)](e.btkaj,u(1561)))this[u(547)]=!0,this[u(1529)]();else return d?ce[u(1168)+u(660)](n,s):ce["fromByte"+u(753)](n,s)}static[t(1168)+t(660)](n,s){let d=t;return new ce(e[d(773)](e.uofwF(e.PSnbB(n[0],e[d(588)](n[1],8)),n[2]<<16),e[d(943)](n[3],24)),e[d(1730)](e[d(1657)](e[d(788)](n[4],n[5]<<8),e[d(921)](n[6],16)),e[d(1591)](n[7],24)),s)}static[t(1168)+t(753)](n,s){let d=t,u={bHJnK:function(x,m){return e[q(940)](x,m)}};return e.ejlQp(e[d(317)],e[d(1301)])?function(x,...m){let b=d,g=_0x515633[b(332)](txpmjW[b(1498)](_0x44b621,this),x,...m);return _0x2ef205[b(1713)](g,x[b(1235)]?x[b(1235)]():[x]),txpmjW.bHJnK(_0x572643,g)}:new ce(e[d(836)](e[d(355)](e.AJzyp(e[d(1530)](n[4],24),e.xiXQP(n[5],16)),n[6]<<8),n[7]),e[d(1080)](e.fsoqY(e[d(759)](e[d(1717)](n[0],24),e.pmmGs(n[1],16)),n[2]<<8),n[3]),s)}static[t(1388)](n){let s=t;return e.ejlQp(n,Gr)?Ld:new ce(e[s(915)](e[s(433)](e[s(968)](Re[s(332)](n,0)|e.PXPhJ(Re[s(332)](n,1),8),Re[s(332)](n,2)<<16),e[s(792)](Re[s(332)](n,3),24)),0),e[s(968)](e.QcWMr(e[s(484)](Re.call(n,4),e[s(1064)](Re.call(n,5),8)),e[s(1810)](Re.call(n,6),16)),Re[s(332)](n,7)<<24)>>>0,!0)}[t(1211)](){let n=t;return String[n(715)+n(1420)](e.ArdDF(255,this[n(595)]),e.SFQOw(e[n(1169)](this[n(595)],8),255),e[n(324)](e[n(833)](this.low,16),255),e[n(1444)](this.low,24),e.QXJlB(255,this[n(466)]),e[n(1528)](e[n(448)](this.high,8),255),e[n(785)](this[n(466)],16)&255,this.high>>>24)}static[t(1682)+"er"](n,s=!0){let d=t;if(e[d(1294)](isNaN,n))return s?Gx:Ld;if(s){if(e[d(592)](n,Se))return qx}else{if(e[d(900)](n,-Vn))return jx;if(e[d(1464)](n,1)>=Vn)return Hx}return ce.fromBits(e[d(759)](n%ge,0),e.jhDUz(n,ge)|0,s)}[t(730)](){let n=t;return this[n(882)]?e.ozlFK(e[n(969)](e.ebnnU(this.high,0),ge),e[n(1237)](this[n(595)],0)):e[n(1389)](e[n(969)](this[n(466)],ge),this[n(595)]>>>0)}[t(1714)](){let n=t;return e[n(1248)](0,this[n(466)])&&this.low===0}[t(726)](n){let s=t;ce[s(690)](n)||(n=ce.fromNumber(n));let d=e[s(342)](this[s(466)],16),u=e[s(1425)](65535,this[s(466)]),x=this[s(595)]>>>16,m=e.bHoiK(65535,this.low),b=e.JhisM(n[s(466)],16),g=e.ArdDF(65535,n.high),A=e[s(915)](n[s(595)],16),k=e[s(1820)](65535,n[s(595)]),N=0,z=0,Z=0,W=0;return W+=e[s(1438)](m,k),Z+=e[s(1586)](W,16),W&=65535,Z+=x+A,z+=e[s(478)](Z,16),Z&=65535,z+=e[s(1156)](u,g),N+=e[s(776)](z,16),z&=65535,N+=e[s(979)](d,b),N&=65535,ce[s(632)](e[s(788)](Z<<16,W),e[s(1264)](e[s(1530)](N,16),z),this[s(882)])}equals(n){let s=t;return ce.isLong(n)||(n=ce.fromNumber(n)),e[s(1580)](this.unsigned,n[s(882)])&&e[s(1658)](e.gtYUT(this[s(466)],31),1)&&e[s(1534)](n[s(466)]>>>31,1)?!1:this.high===n[s(466)]&&e[s(1644)](this.low,n[s(595)])}[t(537)](){let n=t;return e.IGKlp(-1,this[n(595)])&&this[n(466)]===-1?ce.fromBits(0,0,this.unsigned):this[n(595)]===-1?ce[n(632)](0,e[n(1501)](this[n(466)],1),this[n(882)]):ce[n(632)](e[n(570)](this[n(595)],1),this.high,this.unsigned)}toBytes(n){let s=t;if(e[s(1257)](e[s(1704)],e[s(551)]))return n?this.toBytesLE():this[s(1613)+"E"]();if(_0x53e5b8)return new _0x27b25d(_0x610f21[s(791)],_0x377a04[s(1664)]);if(e[s(650)](_0x272245,_0x10eb31))return new _0x400f0a(_0x59ba4e[s(791)],_0x1528e6.protocol,_0x562b87[s(659)]);if((_0x40f5ed||_0x19143f)&&e[s(1188)](e[s(1293)],typeof _0x2b2d1c)&&_0x4fbb78)return new _0x14961b(_0x1c6141[s(791)],_0x5b4f22[s(1664)+"s"])}[t(1234)+"E"](){let n=t,s=this.high,d=this[n(595)];return[e[n(564)](255,d),e[n(380)](d,8)&255,e[n(1268)](e[n(1135)](d,16),255),e[n(665)](d,24),e[n(413)](255,s),e[n(1510)](e[n(1444)](s,8),255),e.LsirA(e.OpvOm(s,16),255),s>>>24]}[t(1613)+"E"](){let n=t;if(e.vmZWb(n(1343),n(1343))){let s=this[n(466)],d=this[n(595)];return[s>>>24,e[n(1528)](e[n(1410)](s,16),255),e[n(1355)](e.fEEYy(s,8),255),e[n(1277)](255,s),e[n(1247)](d,24),e[n(906)](e[n(1390)](d,16),255),e[n(906)](e[n(785)](d,8),255),e.yogGH(255,d)]}else{let d=""+_0x25df02[n(1521)](),u=_0x4b236d||(_0x332e75=_0x477a89(_0x2e4148)),x=_0x94e60a.random()[n(824)](16)[n(559)](-6);return e[n(1501)](e.RDDYX("02"+d,u),x)}}}let Ld=new ce(0,0,!1),Gx=new ce(0,0,!0),Hx=ce[t(632)](-1,2147483647,!1),qx=ce[t(632)](-1,-1,!0),jx=ce[t(632)](0,-2147483648,!1);var en=(function(a){let n=t;return a[a[n(1468)+n(755)]=5001]=e[n(1173)],a[a[n(492)+n(781)]=5002]=n(492)+n(781),a[a[e[n(1575)]]=5003]=e.Khriq,a[a[e[n(1015)]]=5004]=n(722)+n(415),a[a[n(667)+"OR"]=5005]=e.BjHrB,a})({});class Jn{constructor(n){let s=t;this[s(1083)]=n,this[s(970)]=null}}class Nd extends Jn{constructor(n,s){let d=t;super(n),this[d(1570)]=s&&s[d(1570)]||null}}class Md extends Jn{constructor(n,s){let d=t,u=e[d(1812)][d(1194)]("|"),x=0;for(;;){switch(u[x++]){case"0":this.code=s&&s[d(1793)]||5001;continue;case"1":this.colno=s&&s[d(817)]||0;continue;case"2":this.error=s&&s[d(627)]||null;continue;case"3":this[d(561)]=s&&s[d(561)]||0;continue;case"4":super(n);continue;case"5":this[d(1162)]=s&&s[d(1162)]||"";continue;case"6":this[d(1570)]=s&&s[d(1570)]||"";continue}break}}}class Bd extends Jn{constructor(n,s){let d=t;super(n),this.code=s&&s[d(1793)]||0,this[d(431)]=s&&s[d(431)]||"",this[d(1844)]=s&&s[d(1844)]||!1,this[d(1804)+d(1218)]=s&&s[d(1804)+d(1218)]||!1}}class zd extends Jn{constructor(n,s){let d=t,u={chHmv:function(x,m,b){return x(m,b)},jRnMF:function(x,m,b){return x(m,b)},ecxyY:function(x,m,b,g){return e[q(656)](x,m,b,g)},RsVwd:function(x,m){return e[q(582)](x,m)}};if(e[d(634)](e[d(1486)],e[d(888)])){let{offset:x}=u[d(714)](_0x53f32e,_0x4cefa7,_0x4aca90);_0x56e15c=x;let m={cursor_name:"",cursor:0,service:0},{value:b,offset:g}=u[d(714)](_0x30e016,_0x225ae3,_0x5a5b22);m[d(1172)]=b,_0x4a7add=g;let{value:A,offset:k}=u[d(1517)](_0x179b54,_0x3c82ba,_0x1e9f58);_0x27333b=k,m[d(1502)+d(1056)]=u[d(911)](_0x26278a,_0x23c7c2,_0x54f7e2,u[d(1261)](_0x334564,A)),_0x4bda26+=A;let{value:N,offset:z}=u[d(1517)](_0x280e74,_0x173f45,_0x31b516);m.cursor=N[d(730)](),_0x594989=z,_0x5ba326[d(1524)](m)}else super(n),this[d(329)]=s&&s[d(329)]||null}}class Fd extends zd{constructor(n,s){let d=t;super(n),this[d(329)]=s&&s[d(329)]||null,this[d(1570)]=s&&s.message||null}}class Ud extends Jn{constructor(n,s){let d=t;super(n),this[d(329)]=s&&s[d(329)]||null}}function ot(a,{message:n,code:s,error:d}){return e[t(619)]===e.fWnJC?new Md(a,{message:n,code:s,error:d}):new _0x6a5c6c(_0x1d6317,{message:_0x568ce2})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:u}){return new Bd(a,{code:n,reason:s,wasClean:d,willReconnect:u})}function Gd(a,{data:n,message:s}){let d=t;return e.Apoxy(e[d(1837)],e[d(1837)])?(_0x50b309||(_0x4cd9f4=_0x5daa0f[d(1155)]().then(_0x22477c[d(1504)](_0x1f5a62,e[d(717)]))),_0x93ee79):new Fd(a,{data:n,message:s})}function Hd(a,{data:n}){return new Ud(a,{data:n})}function na(a,{message:n}){return new Nd(a,{message:n})}class qd{constructor(n,s){let d=t;e[d(390)]===d(516)?this["currentEndpointT"+d(998)+"t"]=0:(this[d(1339)+"s"]=n,this[d(1116)+"es"]=s,this[d(1033)+d(532)]=0,this[d(1551)+d(594)+d(998)+"t"]=0)}[t(1459)+t(493)+t(480)](){let n=t;if(e.qMlyl(e[n(368)],e[n(368)]))this[n(1033)+n(532)]=0,this[n(1551)+n(594)+n(998)+"t"]=0;else{let s=e[n(443)](_0x92835,"reconnect",{message:e[n(898)]});this[n(661)+n(835)]&&this[n(661)+"econnect"](s)}}[t(1694)+"es"](){let n=t;this[n(1551)+n(594)+"riesCount"]=0}[t(546)+t(768)+"nt"](){let n=t;return this[n(1339)+"s"][this[n(1033)+n(532)]]}["getCurrentEndpointTriesC"+t(1246)](){let n=t;return this[n(1551)+n(594)+"riesCount"]}[t(508)+t(1542)+"es"](){let n=t;return!!(this[n(1033)+n(532)]>=this.endpoints[n(1282)]||this[n(1033)+n(532)]===e[n(571)](this[n(1339)+"s"][n(1282)],1)&&e[n(1016)](this[n(1551)+n(594)+"riesCount"],this[n(1116)+"es"]))}[t(1003)+t(1353)+t(877)+"hedMaxRetries"](){let n=t;return e[n(761)]===e[n(761)]?e[n(858)](this["currentI"+n(532)],this[n(1339)+"s"].length)?!0:e[n(1699)](this[n(1551)+n(594)+n(998)+"t"],this.maxRetries):e[n(843)](this[n(1033)+n(532)],this[n(1339)+"s"][n(1282)])?!0:e[n(606)](this[n(1551)+n(594)+n(998)+"t"],this.maxRetries)}[t(742)+"ackupEnd"+t(1484)+t(1178)+t(1433)](){let n=t,s={IhUnK:function(d,u,x,m){return d(u,x,m)},RuFdP:function(d,u){return e[q(979)](d,u)}};if(e[n(1813)]!==e[n(1813)]){let d=255&_0x156b0e;s[n(1494)](_0x1cf380,d,_0x3db711,s[n(874)](_0x41b4c7,_0x39a43f)),_0x2a80f8>>>=8,_0x541d94--}else return this["currentE"+n(594)+n(998)+"t"]=1,this[n(1033)+"ndex"]++,this[n(1339)+"s"][this[n(1033)+n(532)]]}[t(546)+t(768)+t(1252)+"ateCount"](){let n=t;return this["currentE"+n(594)+n(998)+"t"]++,this.getCurrentEndpoint()}}let Zn=(e[t(697)](e[t(1293)],typeof globalThis)&&e[t(1011)](t(1324),globalThis[t(913)+t(1705)][t(955)])||e[t(1188)](e[t(1293)],typeof window)&&e[t(1011)]("Window",window[t(913)+"tor"][t(955)]))&&e[t(1188)](e.iJUaI,typeof document),In=e[t(1293)]!=typeof globalThis&&(e.dZniN(e.ghJBT,globalThis[t(913)+t(1705)].name)||e[t(1626)](e[t(837)],globalThis[t(913)+t(1705)][t(955)]))&&e.IpblI(e.iJUaI,typeof tt),Hr=(e[t(1831)]("undefined",typeof globalThis)&&e[t(1509)](e.ghJBT,globalThis[t(913)+t(1705)].name)||e[t(515)](e[t(1293)],typeof globalThis)||e.IpblI(e[t(1293)],typeof globalThis)&&!!globalThis[t(1213)+t(1348)])&&e[t(1075)](t(640)+"d",typeof wx),qr=e[t(425)]("undefined",typeof globalThis)&&(e.fOAcd(e[t(837)],globalThis[t(913)+"tor"][t(955)])||e[t(1072)](e.mNjgR,globalThis[t(913)+t(1705)][t(955)])||e.ejlQp(e[t(1654)],globalThis[t(913)+"tor"][t(955)]))&&t(640)+"d"!=typeof self,Wx=e[t(1293)]!=typeof globalThis&&e[t(1456)]===globalThis[t(913)+t(1705)][t(955)]&&t(640)+"d"!=typeof global&&e[t(1263)](t(907),global[t(913)+"tor"][t(955)])&&e[t(1126)](e[t(1293)],typeof process)&&!!process.version;class ra{constructor(){let n=t,s={mNuVT:function(d,u){return e[q(1733)](d,u)},QAAmT:function(d,u){return e[q(1311)](d,u)},yvlCH:function(d,u){return d+u},vaYgm:function(d,u){return e[q(527)](d,u)},zCAQy:function(d,u){return e[q(1438)](d,u)},igHjx:n(896)+n(1462)+n(928),MNCve:e[n(1665)],RtPMN:function(d,u){return e.YKdGN(d,u)},xbpsT:e[n(593)]};if(e[n(1191)](n(313),e[n(1803)]))this[n(1624)+"rs"]={};else return s.mNuVT(_0x394320,s[n(1206)](s[n(1215)](s[n(1669)](s[n(1122)](s.igHjx,_0x4b70fa),s[n(1750)]),s[n(932)](_0x1fbb9c,1))+s.xbpsT,_0x21aa5b))}emit(n,...s){let d=t,u=this[d(1624)+"rs"][n];if(u)u[d(559)]()[d(610)](x=>x.fn[d(1633)](x[d(1125)],s));else if(e[d(1534)](e.cJMGh,n)&&!this.onerror){let x=s[d(1282)]&&s[0];if(x instanceof Error)throw x;let m=new Error(e[d(581)](d(1161)+d(1447),x?e.kzvHF(" ("+x[d(1570)],")"):""));throw m[d(815)]=x,x}return this}[t(867)](n,s){let d=t;if(e[d(1070)](void 0,n))this[d(1624)+"rs"]={};else if(e[d(357)](void 0,s))this[d(1624)+"rs"][n]=null;else{let u=this[d(1624)+"rs"][n];if(u)for(let x=0;x<u.length;)e.lOtbE(u[x].fn,s)?u.splice(x,1):++x}return this}on(n,s,d){let u=t;return(this[u(1624)+"rs"][n]||(this._listeners[n]=[]))[u(1524)]({fn:s,ctx:d||this}),this}}class Kx extends ra{[t(347)+t(991)+t(1645)](n){let s=t;return n.errMsg||n[s(395)]?(s(1368)+" "+(n[s(1636)]||"")+" code: "+(n[s(395)]||""))[s(674)]():JSON[s(1741)+"y"](n)}constructor(n,s,d){let u=t;super(),this._socket=null,Hr&&wx[u(1596)+u(1095)]&&(this[u(1687)]=wx[u(1596)+u(1095)]({url:n,protocols:s,header:d,fail:this["_createS"+u(770)+"lHandler"].bind(this),success:this["_createS"+u(379)+u(549)+u(740)][u(1504)](this)})),In&&tt[u(1596)+u(1095)]&&(this[u(1687)]=tt["connectS"+u(1095)]({url:n,protocols:s,header:d,fail:this["_createS"+u(770)+u(1686)][u(1504)](this),success:this["_createS"+u(379)+u(549)+"ler"].bind(this)}))}[t(790)+"ocketSuc"+t(549)+t(740)](){let n=t;Promise.resolve()[n(814)](()=>{let s=n;if(e[s(809)](s(1030),s(468)))try{return!!this._qosDB}catch(d){return _0x361618.log(d),!1}else this[s(1566)+"steners"]()})}[t(790)+"ocketFai"+t(1686)](n){let s=t,d={WhAPk:function(u,x,m){return e[q(1797)](u,x,m)},MBguN:e[s(481)],NjEVU:e[s(1709)]};Promise[s(1155)]()[s(814)](()=>{let u=s,x=d[u(1416)](ot,d.MBguN,{message:this[u(347)+u(991)+"age"](n)});this[u(1560)](d[u(575)],x);let m=d.WhAPk(xt,d[u(957)],{reason:this[u(347)+"rrorMess"+u(1645)](n)});this[u(1560)](d.NjEVU,m)})}[t(1566)+t(1164)](){let n=t,s={xyuIg:e[n(662)],CsjwI:function(d,u,x){return e[n(1322)](d,u,x)},zeGfN:e[n(1709)],ztuSz:function(d,u,x){return d(u,x)},wutBe:e[n(481)],wJjCC:function(d,u,x){return d(u,x)}};if(e.upjHx(e[n(1744)],e.qubhV)){let d={pacva:function(u,x){return u(x)}};return function(...u){let x=n;return _0x45eaaf[x(1633)](d[x(1695)](_0x21ebd2,this),u),d.pacva(_0x408c09,_0x37ccfb[x(1232)](this))}}else this._socket.onOpen(d=>{let u=n;this[u(1560)](s.xyuIg,s[u(409)](Hd,s[u(1114)],{...d,data:d[u(1636)]||""}))}),this._socket[n(545)](d=>{let u=n;this[u(1560)](s.zeGfN,s[u(579)](xt,s.zeGfN,{...d}))}),this._socket[n(1759)+"e"](d=>{let u=n,x={tsDXQ:e[u(481)]};e[u(1072)](e[u(1383)],e.kpuhB)?this[u(1560)](e[u(1358)],e[u(1412)](Gd,e[u(1358)],{...d})):(_0x1caa60["removeEv"+u(1801)+u(1382)]("success",_0x519696),_0x31ca33[u(985)+"entListener"](rcVxDK[u(731)],_0xb7f3d9))}),this[n(1687)].onError(d=>{let u=n;this[u(1560)](s[u(408)],s[u(1722)](ot,s[u(408)],{...d,message:d[u(1636)]||""}))})}[t(1619)](n){let s=t,d={SyMTU:e.cJMGh};if(e[s(1397)](n,Uint8Array)){if(s(1721)==="tpHoF")return new _0x367907(u=>{let x=s;_0x2ee8fc(u,this[x(658)+x(1303)+"e"](_0x438b30))});{let u=n[s(1380)][s(559)](n.byteOffset,e[s(1311)](n.byteLength,n[s(966)+"et"]));this[s(1687)]&&this[s(1687)][s(1619)]({data:u,fail:x=>{let m=s;this[m(1560)](d[m(1385)],ot(m(627),{message:this[m(347)+m(991)+m(1645)](x)}))}})}}else this[s(1687)]&&this[s(1687)].send({data:n,fail:u=>{let x=s;this[x(1560)]("error",e.nrFHu(ot,e[x(481)],{message:this[x(347)+x(991)+x(1645)](u)}))}})}[t(316)](n,s){let d=t;this[d(1687)]&&this[d(1687)][d(316)]({code:n,reason:s})}[t(1073)+"Listener"](n,s){let d=t,u={Thblv:function(x,m){return e[q(1631)](x,m)},maZTF:function(x,m){return e[q(1319)](x,m)}};if(e[d(931)](e[d(1377)],e[d(1377)])){let x=_0x4ed03f[_0x392ccf];if(iIMrvT[d(1754)](4,_0x1ff431[_0x55cf24][d(1282)])){let m=_0x70415f[d(1544)+"g"](0,iIMrvT[d(899)](4,_0xe09b7b[_0x587dde][d(1282)])),b=m[d(657)](x);_0x565630=_0x409305[d(657)](b)}else _0x4721e0=_0x56b3f0.concat(x)}else this.on(n,s)}["removeEv"+t(1801)+t(1382)](n,s){this[t(867)](n,s)}get readyState(){return this[t(1687)].readyState}get[t(450)+"pe"](){let n=t;return this[n(1687)][n(450)+"pe"]}set[t(450)+"pe"](n){}get[t(791)](){let n=t;return this[n(1687)][n(791)]}get[t(1664)](){let n=t;return this._socket[n(1664)]}get[t(1576)+"ns"](){let n=t;return this[n(1687)][n(1576)+"ns"]}get[t(1090)+t(995)](){return 0}}function $x(a,n){let s=t;if(n)return new n(a[s(791)],a.protocol);if(e.xWufh(Hr,In))return new Kx(a[s(791)],a[s(1664)],a[s(659)]);if(e[s(1589)](Zn,qr)&&e.IpblI(e[s(1293)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(791)],a[s(1664)+"s"])}function Vx(a){let n=t,s=e[n(1174)][n(1194)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(a)return!0;continue;case"1":return!1;case"2":if(Hr&&wx[n(1596)+n(1095)])return!0;continue;case"3":if(In&&tt[n(1596)+n(1095)])return!0;continue;case"4":if((Zn||qr)&&e.IpblI("undefined",typeof WebSocket)&&WebSocket)return!0;continue}break}}function jd(a,n,s){let d=-1;async function u(x){let m=q;return e[m(900)](x,d)?Promise[m(642)](new Error(m(641)+"alled mu"+m(1207)+m(472)+m(462))):(d=x,e[m(1323)](x,s[m(1282)])?Promise.resolve():s[x][m(1504)](a)(n,u[m(1504)](null,e[m(403)](x,1))))}u(0)}function Wd(a){let n=t,s=0,d=0;for(let u=0;e[n(1182)](u,a[n(1282)]);++u)d=a[n(687)+"At"](u),e[n(1182)](d,128)?s+=1:e[n(1067)](d,2048)?s+=2:e.IGKlp(64512&d,55296)&&(64512&a[n(687)+"At"](e[n(1378)](u,1)))===56320?(++u,s+=4):s+=3;return s}function Kd(a,n,s){let d=t;if(e.nsupv(s-n,1))return"";let u="";for(let x=n;x<s;){let m=a[x++];if(e[d(803)](m,127))u+=String[d(715)+d(1420)](m);else if(e.ogybM(m,192)&&m<224)u+=String[d(715)+d(1420)](e[d(1578)](e[d(1405)](31,m)<<6,e.ompGy(63,a[x++])));else if(e[d(1345)](m,224)&&m<240)u+=String[d(715)+d(1420)](e[d(433)](e.UrvJH(e[d(739)](15,m)<<12,(63&a[x++])<<6),e[d(499)](63,a[x++])));else if(e[d(1345)](m,240)){let b=e[d(1772)](e[d(1292)](e[d(444)](e[d(421)]((7&m)<<18,e.ZxkGE(63,a[x++])<<12),e[d(523)](e[d(1277)](63,a[x++]),6)),e[d(324)](63,a[x++])),65536);u+=String[d(715)+d(1420)](55296+e[d(1023)](b,10)),u+=String[d(715)+d(1420)](e[d(626)](56320,e[d(904)](1023,b)))}}return u}function ia(a,n,s){let d=t,u=s,x,m;for(let A=0;e[d(1661)](A,a[d(1282)]);++A)if(e[d(1668)](d(808),"DGyYg"))if(x=a[d(687)+"At"](A),e[d(1736)](x,128))n[s++]=x;else if(e[d(1648)](x,2048))n[s++]=e[d(699)](e[d(1023)](x,6),192),n[s++]=e.vaZmv(e[d(1651)](63,x),128);else if(e[d(1651)](64512,x)===55296&&e.mMDph(e[d(324)](64512,m=a.charCodeAt(A+1)),56320)){let k=e[d(1136)][d(1194)]("|"),N=0;for(;;){switch(k[N++]){case"0":x=e[d(582)](e[d(528)](65536,e[d(1133)](1023,x)<<10),1023&m);continue;case"1":n[s++]=e[d(1292)](e[d(936)](63,x),128);continue;case"2":n[s++]=x>>18|240;continue;case"3":n[s++]=e[d(1841)](e[d(1204)](x,12),63)|128;continue;case"4":++A;continue;case"5":n[s++]=e[d(1817)](x>>6,63)|128;continue}break}}else n[s++]=e.YRQJX(x,12)|224,n[s++]=e[d(855)](e[d(879)](x,6)&63,128),n[s++]=63&x|128;else{let k=(d(1505)+"1")[d(1194)]("|"),N=0;for(;;){switch(k[N++]){case"0":var b=_0x177c46[_0x3a5a44]={exports:{}};continue;case"1":return b[d(1734)];case"2":if(g!==void 0)return g[d(1734)];continue;case"3":var g=_0x413129[_0x69a936];continue;case"4":_0x37d541[_0x1dba24](b,b[d(1734)],_0x41a0c4);continue}break}}return e[d(820)](s,u)}async function $d(a){let n=t;if(e[n(1284)]("string",typeof a)){let s=new Uint8Array(Wd(a));return e[n(1622)](ia,a,s,0),s}return e[n(1273)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1380)],a.byteOffset,a[n(455)+"th"])}function Jx(a){let n=t,s={rIGOe:function(d,u){return e[q(1165)](d,u)},CtTzx:function(d,u){return e.xRLaf(d,u)},VEJiJ:function(d,u){return e[q(1176)](d,u)},aiWgb:function(d,u){return e[q(990)](d,u)},zEThi:function(d,u){return e[q(736)](d,u)}};try{return e.nTDwb(e[n(712)],typeof a)&&(e.cYRAj(a,ArrayBuffer)||a[n(1380)]&&e[n(622)](a[n(1380)],ArrayBuffer))||e[n(1143)](n(531),typeof a)?"":(JSON[n(1818)](a),n(1245)+"ion/json")}catch{if(e[n(1276)](e[n(615)],e[n(615)]))_0x4652f6=yFoWsi.rIGOe(yFoWsi[n(618)](yFoWsi[n(1794)](31,_0x78f83),6),yFoWsi[n(1794)](63,_0x2f3a72)),yFoWsi[n(1666)](_0x53ac62,128)?_0x3557df+=_0xea2a91:(_0x1f6d14+=yFoWsi[n(1508)](_0xfe68af,_0x22174a),_0x3d7368++);else return e[n(1423)](e.emeME,typeof a)?e.EIuRQ:""}}let Zx=(a,n)=>{let s=t;switch(a){case e[s(1102)]:case e[s(318)]:return{[s(916)+a]:1,"x-tt-env":n};default:return{}}};class Yx{constructor(n){let s=t;this[s(1523)+s(1246)]=n,this[s(1496)]=0}[t(878)](){let n=t,s={AXkah:function(d,u){return e[q(1248)](d,u)},eUOuX:e[n(312)],EEDSM:e[n(1569)],MDPjX:e[n(1573)],fqxhs:function(d,u,x){return e[n(1010)](d,u,x)},OtMxQ:function(d,u){return e.wGpDW(d,u)},WnagZ:function(d,u,x,m){return d(u,x,m)},yTBgl:function(d,u,x){return e[n(881)](d,u,x)},uvPwn:"error"};if(e.qMlyl(e[n(325)],n(840)))this[n(1496)]++;else{let{pingInterval:d,pingFrequency:u}=this[n(1110)];if((s.AXkah("hi",_0x166b4d[n(329)])&&s[n(1351)]===u||s[n(387)](n(1443),u))&&(this[n(756)+n(745)](),this[n(1560)](s[n(1700)],s[n(377)]),this[n(1327)+n(784)+"Id"]=s[n(1014)](_0x48fee2,this[n(1474)][n(1504)](this),d)),s[n(920)]("hi",_0x5e184f[n(329)]))return;try{s[n(1333)](_0x394796,this,_0x1ab7ac,[_0x1eb14c,_0x1f03c5,_0x4f137a,_0x3ae974,_0x262489,_0x53df3a])}catch(x){let m=s.yTBgl(_0x20ebbb,s[n(1731)],{message:x.message,code:_0x259cb9[n(722)+n(415)],error:x});this[n(576)+n(416)+n(1765)](m)}}}[t(508)+t(1285)+"nt"](){let n=t;return this[n(1496)]>=this["maxLossC"+n(1246)]}[t(918)+t(1e3)](n=0){let s=t;this[s(1523)+s(1246)]=n,this[s(1496)]=0}}async function Xx(a){let n=t,s={UYPzA:function(d,u){return e[q(1628)](d,u)},TDSpv:e.kVLqJ,GNSIZ:function(d,u,x){return e[q(1451)](d,u,x)},kGors:function(d,u){return e.PpGxt(d,u)},jTVqS:e.cXggL,XHXCp:e.tlYCp,uCzxy:e[n(1460)],DYRBK:e[n(359)],gUgxa:n(996),UKpeX:function(d,u){return e[n(1379)](d,u)},reVUx:e[n(1359)]};return new Promise(d=>{let u=n;if(!Zn)return d(u(1421)+u(431));try{let x=document[u(388)+u(1250)](u(428));window[u(1361)+u(1823)]=m=>{let b=u;document[b(1049)][b(959)+"ild"](x),window[b(1361)+b(1823)]=void 0,s[b(708)](d,m&&m.msg||s.TDSpv)},x[u(1083)]=s[u(872)],x[u(1320)]=a[u(1465)](/^ws/,s[u(1271)])+s[u(1012)];try{document.body[u(1538)+u(647)](x)}catch{s[u(852)]!==s[u(451)]?document.body.removeChild(x):(_0xafacc2(_0x4559c8,24),UYacXh[u(624)](_0x407732,_0x15ee85,UYacXh.kGors(_0x3a9578,_0x34b0d6)))}}catch{if(s.UKpeX("RJyQY",s[u(608)]))window.frontierJSONP=void 0,s[u(708)](d,"unknown "+u(431));else return!!this[u(1676)]}})}function tn(a,n,s){let d=t;return!!a?.[d(1120)](u=>u[d(1483)]===n&&u[d(1659)]===s)}function Yn(a,n){let s=t;return a?.[s(1120)](d=>d[s(1483)]===n)?.[s(1659)]}let sa=null;async function Qx(){let a=t;return sa||(sa=Promise[a(1155)]()[a(814)](Nt[a(1504)](Nt,"idb"))),sa}class ep extends ra{constructor(n,s){let d=t;super(),this._dbName=n,this._keyPath=s,this._qosDB=void 0,this[d(1418)+d(1749)]=null}async[t(648)](){await this[t(649)]()}async[t(649)](){let n=t,s={hnmLs:e[n(654)],DCNjc:e.sXFlb,orUch:e.ZRcrW};if(!this[n(1676)]){if(this._initPromise)return this[n(1418)+n(1749)];try{if(e[n(1386)](e[n(1478)],e[n(391)])){let d=this[n(1424)],u=this[n(1249)];this[n(1418)+n(1749)]=(async()=>{let x=n,{openDB:m}=await e[x(1205)](Qx);this[x(1676)]=await e[x(656)](m,x(1361)+"_"+d,1,{upgrade(b){b[x(557)+"jectStore"](d,{keyPath:u})}})})(),await this[n(1418)+n(1749)]}else!_0x5c7391[n(1441)+"d"]&&(this[n(832)+"er"]&&_0x5a83a7[n(985)+n(1801)+n(1382)](s[n(438)],this[n(1042)+n(361)]),this[n(832)+"er"]&&_0x296bea[n(985)+"entListe"+n(1382)](n(923),this[n(1042)+n(1473)]),this[n(316)]()),this._isBrowser&&_0x24e814[n(985)+"entListe"+n(1382)](s.DCNjc,this["_handleO"+n(1370)]),this[n(832)+"er"]&&_0x1a4795["removeEv"+n(1801)+n(1382)](s[n(818)],this[n(1809)+n(829)])}catch(d){console[n(1634)](d)}finally{this["_initPro"+n(1749)]=null}}}async[t(1232)](n){let s=t;try{return await this[s(649)](),this[s(1676)]?.get(this._dbName,n)}catch(d){console.log(d)}}async set(n,s){let d=t;if(e.yQuhY(e.DzvTG,e[d(748)])){let u=_0x248819[d(1194)](":");for(let x=0;e[d(353)](x,u[d(1282)]);x++){let m=u[x];if(e[d(706)](4,u[x].length)){let b=_0x2d5415[d(1544)+"g"](0,e[d(1319)](4,u[x][d(1282)])),g=b[d(657)](m);_0x14a16e=_0x209ff6[d(657)](g)}else _0x113ad8=_0x5d5bcc[d(657)](m)}return _0x5c4079}else return await this[d(649)](),this[d(1676)]?.[d(1006)](this[d(1424)],n)}async[t(1227)](n){let s=t;try{return await this._init(),this[s(1676)]?.[s(1605)](this[s(1424)],n)}catch(d){console[s(1634)](d)}}async clear(){let n=t,s={uXzBJ:function(d,u,x){return e[q(1427)](d,u,x)}};if(e[n(1558)]==="rWRMj")try{return await this[n(649)](),this._qosDB?.[n(1640)](this[n(1424)])}catch(d){if(e.RNfjs(e[n(701)],e[n(1757)])){let u=LGtARG[n(1108)](_0x6e015a,_0x51d64e,1);_0x1fbb1c[n(890)][u]=_0x2716aa}else console[n(1634)](d)}else this["_interva"+n(683)]()}async[t(1146)](){let n=t;return await this[n(649)](),this._qosDB?.[n(1392)+"ys"](this[n(1424)])}async getAll(){let n=t;return await this[n(649)](),this[n(1676)]?.[n(938)](this[n(1424)])}async closeDB(){let n=t;try{this[n(1676)]?.close(),this[n(1676)]=void 0}catch(s){console.log(s)}}get[t(596)](){let n=t;try{return!!this[n(1676)]}catch(s){return console[n(1634)](s),!1}}}class tp{constructor(n,s){let d=t;if(e[d(634)](e[d(902)],e.flMnl))this[d(1407)]=n,this[d(799)]=s,this[d(1676)]=localStorage;else{let u=e.ElBiQ(this[d(1110)][d(487)+"ncoding"],_0x5342f4)?{force:!!this[d(1110)][d(487)+d(1304)][d(1455)],encoding:this[d(1110)][d(487)+d(1304)].encoding?this._options[d(487)+d(1304)][d(327)][d(1465)](/\s/g,"")[d(1007)+d(517)]():""}:{force:!1,encoding:this[d(1110)][d(487)+d(1304)]?this[d(1110)][d(487)+d(1304)][d(1465)](/\s/g,"")["toLowerC"+d(517)]():""},x=_0x17719c["payloadE"+d(1304)]?_0x4dbf42[d(487)+"ncoding"][d(1465)](/\s/g,"")[d(1007)+d(517)]():"",m=e[d(1273)](this[d(1110)][d(1621)+d(810)],_0x4c99bc)?{force:!!this._options[d(1621)+d(810)][d(1455)],type:this[d(1110)][d(1621)+d(810)][d(1083)]?this[d(1110)][d(1621)+"ype"][d(1083)][d(1465)](/\s/g,"")[d(1007)+d(517)]():""}:{force:!1,type:this[d(1110)][d(1621)+d(810)]?this[d(1110)][d(1621)+d(810)][d(1465)](/\s/g,"")[d(1007)+d(517)]():""},b=_0x272572[d(1621)+d(810)]?_0x111b06["payloadT"+d(810)].replace(/\s/g,"")[d(1007)+"ase"]():"",g=m.force?m[d(1083)]:b||m[d(1083)],A=u[d(1455)]?u.encoding:x||u[d(327)],k=[e.EIuRQ,e.wHVnP,"applicat"+d(1175)+d(993)+d(572),d(531)],N=[e[d(1274)],e[d(1190)]];this[d(1110)][d(1384)+d(419)+d(825)+"ad"]&&k[d(643)](g)&&(!A||N.includes(A))?_0x5d846e[d(805)+d(1332)]=e[d(656)](_0x46412a,_0x129fe3[d(583)],0,_0x29beda[d(583)].byteLength):_0xf7bf8c[d(805)+d(1332)]=""}}async[t(648)](){}get[t(807)](){let n=t;return n(1361)+"_"+this[n(1407)]}async[t(1232)](n){let s=t,d={oyZSr:function(u,x){return e[q(1680)](u,x)},GlZLb:function(u,x){return e.wuSqF(u,x)},GSBon:function(u,x){return e[q(1781)](u,x)},qWEOl:function(u,x){return e[q(354)](u,x)}};if(e[s(1312)]===e[s(1422)]){let u=0,x=0,m;do m=gDyNRl[s(1195)](_0x3cebfd,_0x39314f),gDyNRl[s(743)](u,32)&&(x|=gDyNRl[s(673)](127&m,u)),u+=7;while(gDyNRl.qWEOl(128,m));return x}else{let u=this[s(1676)][s(737)](this[s(807)]);return JSON.parse(u||"{}")[n]}}async[t(1713)](n,s){let d=t,u={XiRfq:e[d(1450)],MVXHm:d(1720),hUDTH:e[d(1495)],UysdE:function(x,m,b,g){return e.afTZo(x,m,b,g)},TPnif:function(x,m,b,g){return e[d(1046)](x,m,b,g)},kWfSU:function(x,m,b,g){return e[d(1610)](x,m,b,g)},XtXQx:e[d(749)],HYxzj:e[d(1236)],NVaNV:e[d(1063)],VlNwp:function(x,m,b,g){return e[d(1296)](x,m,b,g)}};if(e.Llljb===e.eAUZc){let[x,m]=e.XvjrU(_0x4f9d9b,_0x3680e4),b=_0xe74823(x),g=0;return _0x27b3e7[d(610)](A=>{let k=d,N=u[k(1500)][k(1194)]("|"),z=0;for(;;){switch(N[z++]){case"0":_0x3c65e6.log(u.MVXHm,g);continue;case"1":_0xbf05e[k(1634)](u[k(1555)],A,A.service);continue;case"2":_0xc490e3[k(1634)](k(955),g);continue;case"3":g=u[k(1784)](_0x36fcb4,_0x26aad9[k(1682)+"er"](A.cursor||_0x3acaf3),b,g);continue;case"4":g=u[k(1547)](_0x3499e7,A.cursor_name,b,g);continue;case"5":g=u[k(1784)](_0x24ffb8,0,b,g);continue;case"6":g=u.kWfSU(_0x585161,b,g,A[k(1172)]||0);continue;case"7":_0x40b414[k(1634)](u[k(947)],g);continue;case"8":_0x56e3ce[k(1634)](u[k(405)],g);continue;case"9":_0x3debfb[k(1634)](u.NVaNV,g);continue;case"10":g=u.VlNwp(_0x3c3c8b,m[A[k(1502)+"ame"]],b,g);continue}break}}),{frameType:_0x557da7,headers:[{key:e[d(1511)],value:_0x3810a6}],payload:b}}else{let x=this[d(1676)][d(737)](this[d(807)]),m=JSON.parse(x||"{}");return m[s||n[this._pathKey]]=n,this[d(1676)][d(343)](this[d(807)],JSON[d(1741)+"y"](m)),s||n[this[d(799)]]}}async[t(1227)](n){let s=t;if(e[s(892)](s(934),e[s(501)]))this[s(1745)]&&this[s(1745)][s(1619)](_0xd7eaab),this._debug(e[s(677)],_0x26918a);else{let d=this[s(1676)].getItem(this[s(807)]),u=JSON[s(1818)](e[s(1535)](d,"{}"));return u[n]=void 0,this[s(1676)][s(343)](this[s(807)],JSON[s(1741)+"y"](u))}}async[t(1640)](){let n=t;return this[n(1676)][n(1640)]()}async[t(1146)](){let n=t,s=this[n(1676)][n(737)](this._prefix),d=JSON[n(1818)](e[n(442)](s,"{}"));return Object[n(1146)](d)}async[t(938)](){let n=t,s=this[n(1676)][n(737)](this[n(807)]),d=JSON[n(1818)](e.RcRjr(s,"{}"));return Object.values(d)}closeDB(){return Promise.resolve()}get[t(596)](){return!!this[t(1676)]}}class np{constructor(n,s){let d=t;this[d(1407)]=n,this[d(799)]=s,this[d(1676)]=In?tt:Hr?wx:null}async[t(648)](){}get[t(807)](){let n=t;return n(1361)+"_"+this[n(1407)]}async[t(1232)](n){let s=t,d=this[s(1676)][s(848)+s(470)](this._prefix);return JSON[s(1818)](e[s(971)](d,"{}"))[n]}async[t(1713)](n,s){let d=t,u=this[d(1676)][d(848)+d(470)](this[d(807)]),x=JSON[d(1818)](e[d(1589)](u,"{}"));return x[s||n[this[d(799)]]]=n,this[d(1676)].setStorageSync(this[d(807)],JSON[d(1741)+"y"](x)),s||n[this[d(799)]]}async[t(1227)](n){let s=t,d=this._qosDB[s(848)+"geSync"](this[s(807)]),u=JSON[s(1818)](d||"{}");return u[n]=void 0,this._qosDB[s(1477)+"geSync"](this[s(807)],JSON[s(1741)+"y"](u))}async clear(){let n=t;return this._qosDB[n(682)+n(1708)]()}async keys(){let n=t,s=this[n(1676)][n(848)+n(1506)+"nc"](this[n(807)]),d=JSON[n(1818)](s||"{}");return Object[n(1146)](d)}async[t(938)](){let n=t,s=this[n(1676)][n(848)+n(1506)+"nc"](this[n(807)]),d=JSON[n(1818)](e.RcRjr(s,"{}"));return Object.values(d)}closeDB(){return Promise[t(1155)]()}get[t(596)](){let n=t;if(e[n(463)](e[n(865)],e[n(628)]))this.type=_0x4085ab,this.target=null;else return!!this[n(1676)]}}function Vd(a,n){let s=t;if(In||In)return new np(a,n);if(e[s(1081)](Zn,qr)&&e[s(1297)](e[s(1293)],typeof indexedDB))return new ep(a,n);if(e[s(1364)](Zn,qr)&&e[s(1188)](e[s(1293)],typeof localStorage))return new tp(a,n);throw new Error(e.zaKzL)}class rp{constructor(){let n=t;if(e.swnbC(e.VWbEE,e[n(1718)]))this[n(976)+n(458)+"Id"]=null,this[n(976)+"l"]=36e5,this[n(1676)]=Vd("qos",e[n(590)]);else return this._ws?this._ws.protocol:""}async["_interva"+t(683)](){let n=t;if(e[n(1379)](e[n(1254)],e[n(795)]))clearInterval(this[n(976)+"lTimeoutId"]),this[n(976)+n(458)+"Id"]=e[n(602)](setInterval,()=>{let s=n;this[s(1550)+s(1220)]()},this[n(976)+"l"]);else return _0x419d0d[n(715)+n(1420)](255&this[n(595)],e[n(831)](this.low>>>8,255),e[n(1212)](e.JhisM(this.low,16),255),e[n(394)](this[n(595)],24),255&this[n(466)],e[n(365)](e[n(584)](this[n(466)],8),255),e[n(897)](e.KJdVQ(this[n(466)],16),255),e.dDFFN(this[n(466)],24))}async[t(648)](){let n=t;await this[n(1676)][n(648)]()[n(814)](()=>{let s=n;this[s(976)+s(683)]()})}async[t(1550)+t(1220)](){let n=t;if(e[n(1808)](n(741),n(1469))){let s=e[n(1205)](_0x4438b4);return e[n(977)](_0xe1a2e8,_0x102c7d,s),e[n(797)](_0x174ad7,s)}else(await this._qosDB?.getAll()||[])[n(747)](({timestamp:u})=>u<Date[n(1521)]())[n(610)](u=>{let x=n;this[x(1676)]?.[x(1227)](u.message_id)})}async[t(1227)](n){let s=t;return this[s(1676)]?.[s(1227)](n)}async[t(1713)](n,s){let d=t;return this[d(1676)]?.[d(1713)]({message_id:n,timestamp:s})}async[t(1232)](n){let s=t;return this[s(1676)]?.[s(1232)](n)}async[t(429)](){let n=t;e[n(520)](clearInterval,this["_interva"+n(458)+"Id"]),await this[n(1676)]?.[n(429)]()}get[t(596)](){let n=t;return this[n(1676)]?.[n(596)]}}function oa(a){let n=t,s=!!this[n(1110)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(1602)](tn,a[n(1570)].headers,n(396)+"er_qos","2"),u=d&&e[n(1051)](tn,a[n(1570)][n(659)],e[n(1445)],"1"),x=d&&tn(a.message[n(659)],e[n(1739)],"1"),m=x?e[n(1244)](Yn,a[n(1570)].headers,"x_fronti"+n(1838)+"sgid")?.split(",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:u,isAckCleanupMessage:x,ackMsgIds:m}}async function Jd(){let a=t;return this["_QoSMana"+a(1783)]||(this[a(1032)+"ger"]=new rp),this["_QoSMana"+a(1783)][a(596)]||await this[a(1032)+a(1783)][a(648)](),this[a(1032)+a(1783)]}async function ip(a,n){let s=t,{enableAutoAck:d}=this[s(1110)],u=e[s(1602)](tn,a[s(1570)][s(659)],s(526),"1"),x=tn(a[s(1570)][s(659)],"is_ack","1"),m=oa[s(332)](this,a);if(e[s(1224)](d,u)){let{SeqID:b,LogID:g,service:A,LogIDNew:k,method:N}=a[s(1570)];this[s(440)]({SeqID:b,LogID:g,LogIDNew:k,service:A,method:N,headers:[{key:e[s(1815)],value:"1"},{key:s(513),value:e[s(1372)](k,"")},{key:e.iAHVH,value:"0"}]})}x&&!m[s(1475)]&&this[s(576)+s(578)+s(1677)](a),e[s(1205)](n)}async function sp(a,n){let s=t;this[s(1363)](e[s(978)],a[s(1570)]),e[s(1205)](n)}async function op(a,n){let s=t,d={kksWn:function(u,x,m){return e.owIVK(u,x,m)},KtYOb:e.ByNep};if(e[s(982)](e[s(1409)],e[s(505)]))d[s(400)](_0x1fd7fb,_0x579940,this["_getInte"+s(1303)+"e"](_0x367eb2));else{let u=e[s(1685)](Xt,await $d(a[s(329)]));try{if(e[s(1777)]!==e[s(1684)])if(e[s(1326)](u[s(583)],Uint8Array)){let x=e[s(1265)](this._options.payloadEncoding,Object)?{force:!!this[s(1110)][s(487)+"ncoding"][s(1455)],encoding:this[s(1110)][s(487)+"ncoding"][s(327)]?this[s(1110)][s(487)+s(1304)].encoding[s(1465)](/\s/g,"")[s(1007)+s(517)]():""}:{force:!1,encoding:this._options[s(487)+"ncoding"]?this[s(1110)]["payloadE"+s(1304)][s(1465)](/\s/g,"")[s(1007)+s(517)]():""},m=u[s(487)+"ncoding"]?u[s(487)+"ncoding"][s(1465)](/\s/g,"")[s(1007)+s(517)]():"",b=e[s(1068)](this[s(1110)][s(1621)+s(810)],Object)?{force:!!this[s(1110)].payloadType[s(1455)],type:this._options[s(1621)+s(810)][s(1083)]?this[s(1110)][s(1621)+"ype"].type[s(1465)](/\s/g,"")[s(1007)+s(517)]():""}:{force:!1,type:this._options[s(1621)+s(810)]?this[s(1110)][s(1621)+s(810)][s(1465)](/\s/g,"")["toLowerC"+s(517)]():""},g=u[s(1621)+"ype"]?u[s(1621)+"ype"][s(1465)](/\s/g,"")[s(1007)+s(517)]():"",A=b[s(1455)]?b.type:g||b.type,k=x.force?x[s(327)]:m||x.encoding,N=[e.EIuRQ,e[s(1479)],s(1245)+s(1175)+";charset"+s(572),e.emeME],z=[e[s(1274)],e[s(1190)]];this[s(1110)][s(1384)+s(419)+s(825)+"ad"]&&N[s(643)](A)&&(!k||z[s(643)](k))?u.textPayload=e.dzEXc(Kd,u[s(583)],0,u[s(583)].byteLength):u[s(805)+s(1332)]=""}else u["textPayl"+s(1332)]="";else this[s(1560)](lJvIFX[s(1679)],lJvIFX[s(400)](_0x42286b,lJvIFX[s(1679)],{..._0x1a1ac3}))}catch(x){u.textPayload="",console[s(1634)](x)}a[s(1570)]=u,n()}}function ap(a,n,s){let d=t,u=e[d(454)](s,8192),x=u>>>1,m=null,b=u;return function(g){let A=d;if(e.oMSMJ(g,1)||e[A(1087)](g,x))return e[A(1166)](a,g);e[A(1698)](e.LhewE(b,g),u)&&(m=e[A(797)](a,u),b=0);let k=n[A(332)](m,b,b+=g);return 7&b&&(b=e[A(979)](e[A(644)](7,b),1)),k}}let cp=4294967295;function dp(a,n,s){let d=t;return e.zlRJa(RangeError,e[d(585)](e.zgUZT(e[d(678)]("index out of ran"+d(928),a),e[d(1665)]),e.aWqRS(n,1))+e[d(593)]+s)}function lp(a,n,s){let d=t;if(s>cp)throw new Error(d(1031)+d(1752)+"e");let u=3;for(;e[d(1036)](u,0);){let x=255&s;e.ImIgs(ca,x,a,n+u),s>>>=8,u--}return e.uOvXr(n,4)}function up(a,n){let s=t,d=0,u=n,x=e.wIKVY(n,4);for(;u<x;){let{value:m,offset:b}=aa(a,u);u=b,d=e.UnWrX(e[s(607)](d,8),0),d+=m}return{value:d,offset:x}}function fp(a,n,s){let d=t,u=e.SIrPW[d(1194)]("|"),x=0;for(;;){switch(u[x++]){case"0":if(!a)return s;continue;case"1":if(a[d(1282)]<40)return ia(a,n,s)+s;continue;case"2":if(n[d(1267)+"e"])return e[d(383)](n[d(1267)+"e"](a,s),s);continue;case"3":return e.RFcOM(ia(a,n,s),s);case"4":if(n[d(1588)])return e[d(585)](n.write(a,s),s);continue}break}}function hp(a,n){let s=t,d=new ce(e[s(433)](e[s(1394)](e.kzPqU(a[e[s(322)](n,4)]<<24,e[s(1027)](a[e[s(1331)](n,5)],16)),e[s(599)](a[n+6],8)),a[e[s(1378)](n,7)]),e[s(836)](e[s(1429)](a[e.rpICs(n,0)],24)|e[s(1454)](a[e.QhKYL(n,1)],16)|e.PSfqq(a[e[s(1138)](n,2)],8),a[n+3]),!0);return n+=8,{value:d,offset:e[s(946)](n,8)}}function xp(a,n,s){let d=t,u=a.low,x=a[d(466)];return n[s]=e[d(833)](x,24),n[e[d(1311)](s,1)]=e[d(432)](e[d(1247)](x,16),255),n[e.INOpf(s,2)]=e[d(873)](x,8)&255,n[s+3]=e[d(598)](255,x),n[e.hHeXT(s,4)]=e[d(1520)](u,24),n[s+5]=e.jHcAV(u>>>16,255),n[e.qIqmW(s,6)]=e[d(1062)](e.YdKde(u,8),255),n[e.Zjtih(s,7)]=e.fKSPL(255,u),s+=8,s}function aa(a,n){let s=t;return a[s(1711)+"8"]?{value:a[s(1711)+"8"](n),offset:e[s(744)](n,1)}:{value:e[s(1268)](255,a[n]),offset:e.culCd(n,1)}}function ca(a,n,s){let d=t;return n.writeUint8?n[d(1643)+"t8"](a,s):n[s]=e[d(1387)](255,a),e[d(1471)](s,1)}let pp=function(a){let n=t;if(e[n(1086)](e.xjfrH,e[n(1497)]))if(_0x132165.payload instanceof _0x502dad){let s=this[n(1110)][n(487)+n(1304)]instanceof _0x5695eb?{force:!!this._options[n(487)+n(1304)][n(1455)],encoding:this[n(1110)][n(487)+n(1304)][n(327)]?this[n(1110)][n(487)+n(1304)][n(327)][n(1465)](/\s/g,"").toLowerCase():""}:{force:!1,encoding:this[n(1110)][n(487)+n(1304)]?this[n(1110)][n(487)+"ncoding"][n(1465)](/\s/g,"")["toLowerC"+n(517)]():""},d=_0x10516a[n(487)+n(1304)]?_0x3080d7[n(487)+n(1304)][n(1465)](/\s/g,"")[n(1007)+n(517)]():"",u=e[n(1278)](this[n(1110)][n(1621)+n(810)],_0x1588e8)?{force:!!this[n(1110)][n(1621)+n(810)].force,type:this[n(1110)][n(1621)+n(810)].type?this[n(1110)][n(1621)+"ype"][n(1083)][n(1465)](/\s/g,"")[n(1007)+"ase"]():""}:{force:!1,type:this._options[n(1621)+"ype"]?this[n(1110)]["payloadT"+n(810)][n(1465)](/\s/g,"")[n(1007)+n(517)]():""},x=_0x205e96[n(1621)+n(810)]?_0x511894[n(1621)+n(810)][n(1465)](/\s/g,"")[n(1007)+n(517)]():"",m=u[n(1455)]?u[n(1083)]:x||u[n(1083)],b=s[n(1455)]?s[n(327)]:d||s[n(327)],g=[e[n(689)],e[n(1479)],e[n(1066)],e[n(712)]],A=[e[n(1274)],e[n(1190)]];this[n(1110)][n(1384)+n(419)+n(825)+"ad"]&&g[n(643)](m)&&(!b||A[n(643)](b))?_0xf95d35[n(805)+n(1332)]=e.TWItm(_0x5d82a9,_0x316885.payload,0,_0xfd7a32[n(583)][n(455)+"th"]):_0x543cc3[n(805)+n(1332)]=""}else _0xb614a6[n(805)+n(1332)]="";else return new Uint8Array(a)},gp=e[t(1293)]!=typeof Buffer?Buffer[t(988)+t(1652)]:e.TQHyI(ap,pp,Uint8Array.prototype[t(1183)]);(()=>{let a=t,n={RlNwR:e[a(1585)],WpkGd:function(d,u){return e.oMSMJ(d,u)},slMlK:function(d,u){return d<<u},byIsA:function(d,u){return d&u},wBwns:function(d,u){return e[a(655)](d,u)},GquOK:function(d,u){return e.lJgHZ(d,u)},TSGtW:function(d,u){return d|u},GiVOF:function(d,u){return e[a(664)](d,u)},LNDhI:function(d,u){return e[a(502)](d,u)},lUXDV:function(d,u){return e[a(376)](d,u)},HFEuH:function(d,u){return e[a(434)](d,u)},VdbaR:function(d,u){return e[a(1515)](d,u)},BwtDO:function(d,u){return e[a(1763)](d,u)},yrzfT:function(d,u){return e[a(436)](d,u)},TgNQP:function(d,u){return e[a(1657)](d,u)},gEstK:function(d,u){return e[a(921)](d,u)},eBQlT:function(d,u){return e.YbusG(d,u)},xTrmQ:function(d,u){return e[a(773)](d,u)}},s=4294967295;return function(d,u,x=!0){let m=a,b=n[m(569)][m(1194)]("|"),g=0;for(;;){switch(b[g++]){case"0":if(n.WpkGd(d[u++],128))return{value:x?s:0|s,offset:u};continue;case"1":s=(s|n.slMlK(n[m(340)](127,d[u]),7))>>>0;continue;case"2":s=n.wBwns(n.GquOK(s,n[m(340)](15,d[u])<<28),0);continue;case"3":if(n[m(941)](d[u++],128))return{value:x?s:0|s,offset:u};continue;case"4":return{value:x?s:n.GquOK(0,s),offset:u};case"5":if(n[m(941)](d[u++],128))return{value:x?s:n[m(980)](0,s),offset:u};continue;case"6":s=n[m(420)](n[m(1791)](127,d[u]),0);continue;case"7":if(n.lUXDV(u+=5,d[m(1282)]))throw u=d.length,dp(u,10,d[m(1282)]);continue;case"8":if(n[m(1053)](d[u++],128))return{value:x?s:n[m(883)](0,s),offset:u};continue;case"9":s=n[m(1768)](n[m(1239)](s,n[m(485)](127&d[u],14)),0);continue;case"10":s=n[m(1821)](n.TgNQP(s,n.gEstK(n[m(914)](127,d[u]),21)),0);continue;case"11":if(d[u++]<128)return{value:x?s:n[m(729)](0,s),offset:u};continue}break}}})();let mp=16,da=32;function wp(a){let n=t,s=0,d={};for(let u=0;e[n(868)](u,a[n(1282)]);u++)d[a[u][n(1502)+n(1056)]]=e.XyURO(Wd,a[u][n(1502)+n(1056)]),s+=e[n(767)](14,d[a[u][n(1502)+n(1056)]]);return[s,d]}function Zd(a,n,s){let d=t,[u,x]=e[d(752)](wp,a),m=e[d(1733)](gp,u),b=0;return a[d(610)](g=>{let A=d,k={IIjeY:function(N,z,Z){return e.jEDod(N,z,Z)},FaSrZ:function(N,z){return e[q(1292)](N,z)},khhBh:function(N,z){return N&z}};e[A(1024)]!==e[A(384)]?(console[A(1634)](e[A(1495)],g,g[A(1172)]),b=ca(0,m,b),console[A(1634)](e[A(1236)],b),b=e[A(1610)](lp,m,b,g[A(1172)]||0),console[A(1634)](e[A(749)],b),b=e[A(1318)](ca,x[g["cursor_n"+A(1056)]],m,b),console[A(1634)](e[A(1063)],b),b=e[A(656)](fp,g["cursor_n"+A(1056)],m,b),console.log(e[A(1402)],b),b=e[A(1318)](xp,ce[A(1682)+"er"](g[A(406)]||n),m,b),console[A(1634)](e[A(1437)],b)):(vKdIKU[A(471)](_0xae771e,_0x28662b,vKdIKU[A(422)](vKdIKU[A(994)](127,_0xd735e5),128)),_0x399750>>>=7)}),{frameType:da,headers:[{key:e[d(1511)],value:s}],payload:m}}function _p(a){let n=t,s=0,d=[];for(;e.QdNVi(s,a[n(455)+"th"]);){let{offset:u}=e[n(529)](aa,a,s);s=u;let x={cursor_name:"",cursor:0,service:0},{value:m,offset:b}=up(a,s);x[n(1172)]=m,s=b;let{value:g,offset:A}=e[n(1221)](aa,a,s);s=A,x["cursor_n"+n(1056)]=e.euljQ(Kd,a,s,e[n(1259)](s,g)),s+=g;let{value:k,offset:N}=e[n(1142)](hp,a,s);x[n(406)]=k[n(730)](),s=N,d[n(1524)](x)}return d}function yp(){let a=t;return{frameType:da,headers:[{key:e[a(1511)],value:e[a(1058)]}],payload:void 0}}class bp{constructor(n,s,d){let u=t;this[u(1579)+"ameSpace"]=n,this[u(1519)+u(519)]=s,this[u(1315)+u(887)]=d,this[u(1676)]=e[u(787)](Vd,this[u(1579)+u(981)],u(1502)+"ame")}async openDB(){let n=t;await this[n(1676)][n(648)]()}async getCursors(){let n=t;if(!this._qosDB[n(596)])return;let s=this[n(1315)+n(887)],d=await this[n(1676)][n(938)]();switch(console[n(1634)]("allCurso"+n(512),d),s){case e[n(1038)]:return d&&d[n(1282)]?e[n(1602)](Zd,d,0,this._cursorFileName):void 0;case n(629):return;case e[n(1149)]:return d&&d[n(1282)]?e[n(1046)](Zd,d,0,this[n(1519)+"ileName"]):e[n(1446)](yp)}}async[t(1713)](n,s,d){let u=t;return console[u(1634)](e[u(1200)],n,s,d),this[u(1676)].set({cursor_name:n,cursor:s,service:d})}async[t(866)+"rs"](n){let s=t,d=e[s(1233)](_p,n);for(let u of d)if(e[s(539)]===e[s(1180)]){let{enableAutoAck:x}=this[s(1110)],m=e.pryGN(_0xf51cb8,_0x1a488a[s(1570)].headers,e[s(1632)],"1"),b=_0xea3c6d(_0x53dd16.message[s(659)],"is_ack","1"),g=_0x1e1514[s(332)](this,_0xc43eb8);if(e[s(1224)](x,m)){let{SeqID:A,LogID:k,service:N,LogIDNew:z,method:Z}=_0x5627c1.message;this[s(440)]({SeqID:A,LogID:k,LogIDNew:z,service:N,method:Z,headers:[{key:e[s(1815)],value:"1"},{key:e[s(930)],value:e[s(1728)](z,"")},{key:"ack_code",value:"0"}]})}b&&!g[s(1475)]&&this["_dispatc"+s(578)+s(1677)](_0x29b64f),e.pUNxV(_0x3046bc)}else console[s(1634)](e[s(1725)],d),await this._qosDB[s(1713)](u)}async[t(1232)](n){let s=t;if(e[s(1400)](s(1706),e[s(321)]))_0x474f33=_0x51eef4[s(657)](_0x5f3074),_0x437a27=_0x395fea.concat(_0x965201[_0x40e32a]);else return(await this._qosDB[s(1232)](n))?.cursor}async[t(429)](){let n=t;await this._qosDB[n(429)]()}updateCursorFileName(n){let s=t;this[s(1519)+s(519)]=n}get isReady(){let n=t;return this[n(1676)][n(596)]}}let Ep=e[t(1140)];async function Yd(a){let n=t;if(!this[n(1110)][n(924)+"S"])return null;let{aID:s,fpID:d,messageStrategy:u}=this[n(1110)],x=a||Ep;try{return this[n(1742)+n(1079)]?a&&this[n(1742)+n(1079)][n(905)+"rsorFile"+n(509)](a):this[n(1742)+n(1079)]=new bp(d+"_"+s+"_"+x,x,u),this["_cursorM"+n(1079)].isReady||await this[n(1742)+n(1079)][n(648)](),this[n(1742)+n(1079)]}catch{return null}}async function vp(a,n){let s=t,d={ZfLiG:function(u,x){return e.KeomC(u,x)},qepAe:function(u,x){return e.eLrud(u,x)},rZaDn:function(u,x){return u>x}};if(e[s(1667)]===e.SzIFM){let u=e[s(656)](tn,a[s(1570)][s(659)],e[s(597)],"-1"),x=tn(a[s(1570)][s(659)],e[s(1815)],"1"),m=e[s(469)](Yn,a[s(1570)].headers,e[s(1022)]),b=e[s(1184)](Number,Yn(a[s(1570)][s(659)],e[s(1485)]))||0,g=oa.call(this,a),A=e[s(1518)](tn,a.message[s(659)],e[s(1618)],"2"),k=e[s(750)](Yn,a[s(1570)][s(659)],e.Wrbky),N=e[s(950)](Number,Yn(a[s(1570)][s(659)],s(1243)+"rsor_value"));if(g.isQoSAck)return e.MfIhz(n);let z=g[s(1097)+"sage"]?await Jd[s(332)](this):null;if(e[s(1393)](a[s(1570)][s(1172)],0)&&x&&!u||e.wTUZQ(a[s(1570)][s(1172)],0)){if(m&&g["isQoSMes"+s(1762)]&&z)return!!!await z.get(m)&&(this["_dispatc"+s(720)+s(1145)](a),await z.set(m,e.PZLUb(Date[s(1521)](),b))),n();if(A){let Z=await Yd[s(332)](this);if(!Z)return e[s(1499)](s(1655),s(1616))?(this[s(576)+s(720)+s(1145)](a),e[s(1205)](n)):this[s(1551)+s(594)+"riesCount"];let W=await Z[s(1232)](k)??-1;if(e[s(410)](W,N))this[s(576)+s(720)+s(1145)](a),Z[s(1713)](k,N,a[s(1570)][s(1172)]);else throw new Error(s(834)+s(1563)+s(460)+N+(s(779)+s(734)+s(1592)+"r ")+W);return e[s(374)](n)}return this[s(576)+s(720)+s(1145)](a),e[s(1117)](n)}}else{let{initReconnectInterval:u,maxReconnectInterval:x,reconnectIntervalGrowFactor:m}=this[s(1110)],b=d[s(681)](u,_0x2e5e4f[s(1158)](m,d[s(1061)](_0x3f6a65,1)));return d[s(1039)](b,x)?x:b}}async function Sp(a,n){let s=t,d=oa[s(332)](this,a);if(!d["isQoSMes"+s(1762)])return e[s(603)](n);let u=await Jd[s(332)](this);if(d["isAckCle"+s(319)+s(1645)]&&d[s(1826)+"s"][s(1282)])for(let x of d[s(1826)+"s"])await u.del(x);e[s(1313)](n)}async function Ip(a,n){let s=t,d=e.XshfC(a[s(1570)][s(411)+"e"],mp),u=a[s(1570)][s(411)+"e"]===da;if(e[s(1224)](!d,!u))return e[s(1139)](n);let x=e[s(1430)](Yn,a[s(1570)][s(659)],e[s(1511)]);if(!x)return n();let m=await Yd[s(332)](this,x);if(!m)return e.ptsVK(n);if(d){let b=await m[s(1627)+"rs"](),g={frameType:b?.[s(411)+"e"],SeqID:ce[s(1682)+"er"](this[s(1827)]++),LogID:ce[s(1682)+"er"](this._options[s(1574)+"erator"]()),service:9e3,method:5,headers:b?.[s(659)],payload:b?.[s(583)]},A=e[s(797)](T,g);this[s(1745)]&&this[s(1745)][s(1152)+"te"]&&this[s(1745)].send(A)}if(u){let b=a.message[s(583)];b&&m[s(866)+"rs"](b)}}let Ap=async function(a,n){let s=t;this[s(547)]=!1,clearTimeout(this[s(1529)+s(1512)+s(1121)]),e[s(1715)](n)},Tp=async function(a,n){let s=t;if(!this[s(1745)]||e[s(1545)](this[s(1745)][s(1152)+"te"],this[s(841)]))return e[s(1214)](n);let{pingInterval:d}=this[s(1110)];this[s(1111)+s(1346)]?.[s(1459)+s(493)+"fig"]();for(let x=0;e[s(500)](x,this[s(1315)+"Queue"][s(1282)]);x++){let m=this[s(1315)+s(427)][x];if(e[s(1808)](this[s(1745)][s(1152)+"te"],this[s(841)])&&m!==null)this[s(1745)]&&this[s(1745)][s(1619)](m),this[s(1315)+s(427)][x]=null;else break}this[s(1315)+s(427)]=this[s(1315)+"Queue"].filter(x=>!!x),this._pingPongTimeoutId=e.nuJcX(setTimeout,()=>this[s(1474)](),d),this._dispatchOpenEvent(a),this[s(832)+"er"]&&this[s(1745)]&&(this._ws[s(450)+"pe"]=this[s(1159)+s(810)]);let u=this[s(1111)+s(1346)]?.["getCurre"+s(768)+"nt"]();this[s(1363)]("open "+u+" success"),e[s(1625)](n)},Dp=async function(a,n){let s=t,d=this[s(1111)+"tManager"]?.["getCurre"+s(768)+"nt"]();this[s(1363)](s(417)+d),e[s(1625)](n)};class Rp extends ra{constructor(n){let s=t,d={wOavL:e[s(1358)],fwBqr:function(b,g,A){return e[s(1310)](b,g,A)},IxwSe:function(b,g,A){return e[s(860)](b,g,A)},NZaWy:function(b,g){return e[s(1017)](b,g)},EVsHb:function(b,g,A){return e[s(1647)](b,g,A)},hEFVp:e[s(1709)],zGecR:function(b,g){return e[s(1366)](b,g)},kpXcC:e[s(481)],cyDlr:function(b,g){return b!==g}};super(),this["_miniNav"+s(1814)+"line"]=!0,this._isBrowser=Zn,this[s(1404)]=Wx,this._isMiniTT=In,this._isMiniWX=Hr,this._isWorker=qr,this[s(1315)+s(427)]=[],this["_endpoin"+s(1346)]=null,this[s(1226)+s(696)]=!1,this._binaryType=s(1219)+s(338),this["_connect"+s(1802)]=!1,this["_connect"+s(1512)+s(1121)]=null,this["_reconne"+s(459)+s(612)]=null,this[s(1327)+s(784)+"Id"]=null,this[s(1827)]=0,this._isInit=!1,this[s(1639)]="",this["_QoSMana"+s(1783)]=null,this[s(1742)+s(1079)]=null,this[s(777)+s(963)]=null,this[s(812)+"ls"]=e[s(375)],this[s(1487)]=3,this[s(492)+"NG"]=0,this[s(841)]=1,this.CLOSING=2,this[s(1020)]=b=>{let g=s;try{e[g(1554)](jd,this,b,[Ap,Tp,Dp])}catch(A){let k=e[g(1089)](ot,g(627),{message:A.message,code:en[g(667)+"OR"],error:A});this[g(576)+g(416)+g(1765)](k)}},this._onMessage=async b=>{let g=s,{pingInterval:A,pingFrequency:k}=this._options;if((b[g(329)]==="hi"&&e.pxoxv(g(573),k)||e.JixNZ("auto",k))&&(this[g(756)+g(745)](),this[g(1560)](e.wLKVv,g(616)),this[g(1327)+g(784)+"Id"]=e[g(750)](setTimeout,this[g(1474)][g(1504)](this),A)),!e.neEdd("hi",b[g(329)]))try{e[g(1796)](jd,this,b,[op,ip,Sp,Ip,vp,sp])}catch(N){let z=ot(g(627),{message:N.message,code:en.MESSAGE_ERROR,error:N});this[g(576)+"hErrorEv"+g(1765)](z)}},this[s(1415)]=b=>{let g=s,A=this[g(1111)+"tManager"]?.[g(508)+g(1542)+"es"](),k=this[g(1111)+g(1346)]?.[g(546)+"ntEndpoint"]();if(A&&!b[g(1570)])if(e[g(372)](e[g(534)],e.BZhLr))this[g(1560)](RvpuiP.wOavL,RvpuiP.fwBqr(_0x5bb2df,RvpuiP[g(670)],{..._0x36fec0}));else{let N=g(1630)+k+(g(705)+g(1583)+g(1779)+"ed");this[g(576)+"hErrorEv"+g(1765)](e.yffjr(ot,e.cJMGh,{message:N,code:en[g(1552)+g(811)+"R"],error:b}));return}this[g(1745)]&&e.DErRw(this[g(1745)][g(1152)+"te"],this.OPEN)&&this["_disconn"+g(1043)](),this["_dispatchErrorEv"+g(1765)](e[g(1322)](ot,g(627),{message:b.message,code:en["NATIVE_E"+g(755)],error:b}))},this[s(315)]=async b=>{let g=s;this["_clearTi"+g(1413)](),this[g(756)+g(745)](),this["_removeW"+g(1198)+"rs"](),this._ws=null,this[g(1529)+"Lock"]=!1;let A=this[g(1111)+g(1346)]?.[g(508)+"chMaxTries"]();if(!A&&this[g(875)+g(1288)]()&&!this[g(1226)+g(696)]){let k=this[g(1111)+g(1346)]?.[g(546)+g(768)+"nt"](),N=this[g(1110)][g(691)+g(793)+g(864)](b[g(1793)],b[g(431)]);this[g(576)+g(1516)+"ent"](d[g(933)](xt,g(316),{code:1006,reason:b[g(431)]||"connecting faile"+g(1629)+g(1001)+g(1795)+g(1408)+k,willReconnect:N})),N&&this[g(1529)]();return}if(d[g(335)](1e3,b[g(1793)])&&this[g(1226)+g(696)]){this[g(576)+g(1516)+g(1765)](d[g(538)](xt,d.hEFVp,{code:1e3,reason:g(718)})),this[g(1111)+g(1346)]?.[g(1459)+g(493)+g(480)](),this[g(777)+g(963)]?.[g(918)+"nter"]();return}if(d.NZaWy(1e3,b[g(1793)])&&A){let k=this[g(1111)+g(1346)]?.[g(546)+g(768)+"nt"](),N=b[g(431)];N||(N=await d.zGecR(Xx,this._url)),N="connecti"+g(984)+g(1428)+N+(g(540)+g(1593))+k+(", max re"+g(695)+g(1417)),this[g(576)+g(1516)+"ent"](xt(g(316),{code:b[g(1793)],reason:N}));let z=g(1630)+k+(" fail, m"+g(1583)+g(1779)+"ed");this[g(576)+g(416)+g(1765)](d[g(933)](ot,d.kpXcC,{message:z,code:en[g(1552)+g(811)+"R"]})),this[g(1111)+"tManager"]?.[g(1459)+g(493)+"fig"](),this._pingLossCounter?.[g(918)+"nter"]();return}if(d[g(1290)](1e3,b[g(1793)])&&!b[g(431)]){let k=this[g(1111)+g(1346)]?.[g(546)+"ntEndpoint"]();this[g(576)+g(1516)+"ent"](d[g(1719)](xt,d[g(1306)],{code:b[g(1793)],reason:g(1334)+g(984)+g(1629)+g(1001)+g(1795)+g(1408)+k})),this[g(1111)+g(1346)]?.[g(1459)+g(493)+g(480)](),this[g(777)+g(963)]?.[g(918)+g(1e3)]();return}this[g(576)+g(1516)+g(1765)](b),this[g(1111)+g(1346)]?.[g(1459)+g(493)+g(480)](),this[g(777)+g(963)]?.["resetCou"+g(1e3)]()},this[s(491)]=null,this[s(1338)]=null,this[s(1179)+"e"]=null,this[s(1480)]=null,this["onStartR"+s(835)]=null,this["onReceiv"+s(522)]=null,this[s(949)+"mediatel"+s(389)+"ct"]=null,this[s(1809)+s(1370)]=this[s(1809)+s(1370)][s(1504)](this),this[s(1809)+s(829)]=this[s(1809)+s(829)][s(1504)](this),this[s(1042)+s(361)]=this[s(1042)+"ageHide"].bind(this),this[s(1042)+s(1473)]=this[s(1042)+s(1473)].bind(this),this[s(1110)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1681)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(1748)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1149)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:u,ws:x}=n,m=Array[s(635)](u)?u:e[s(1675)](e[s(712)],typeof u)?[u]:[];if(!m||e.xlJmu(0,m.length))throw new Error(s(871)+s(925)+"alid url");if(!e[s(1166)](Vx,x))throw new Error(e[s(1688)]);Object.assign(this[s(1110)],n),this[s(1111)+s(1346)]=new qd(m,this._options.maxRetries),this["_pingLos"+s(963)]=new Yx(this._options[s(765)+"Count"]),this[s(1110)]["automati"+s(1029)]&&(this[s(547)]=!0,this[s(1529)]()),this[s(1110)][s(1488)+"tworkChanged"]&&(this[s(1229)+"T"]||this[s(1707)+"X"]?this[s(1601)+s(908)+s(1349)]():this[s(832)+"er"]&&this[s(1663)+s(1531)+s(1223)]())}[t(1809)+t(1370)](){let n=t;this[n(1110)][n(1144)+n(1829)+n(477)]||this[n(1226)+n(696)]||this[n(1843)+"econnect"]()}[t(1809)+t(829)](){let n=t;this[n(542)+"WebSocket"]();let s=e[n(507)](na,e.Ojfnh,{message:e[n(424)]});this["onStopImmediatel"+n(389)+"ct"]&&this[n(949)+n(1360)+n(389)+"ct"](s)}[t(1663)+"balEvent"+t(1223)](){let n=t;this[n(832)+"er"]&&window["addEvent"+n(1223)](n(847),this[n(1809)+n(1370)]),this[n(832)+"er"]&&window[n(1073)+n(1223)](e.ZRcrW,this[n(1809)+n(829)]),this._isBrowser&&window[n(1073)+n(1223)](n(769),this[n(1042)+n(361)]),this._isBrowser&&window[n(1073)+n(1223)](e[n(1354)],this[n(1042)+"ageShow"])}[t(1328)+t(1531)+t(1223)](){let n=t;this[n(832)+"er"]&&window["removeEv"+n(1801)+"ner"](e[n(548)],this[n(1809)+n(1370)]),this[n(832)+"er"]&&window[n(985)+n(1801)+"ner"](n(710),this[n(1809)+"ffLine"]),this[n(832)+"er"]&&window[n(985)+n(1801)+n(1382)](n(769),this[n(1042)+n(361)]),this._isBrowser&&window[n(985)+n(1801)+n(1382)](e[n(1354)],this[n(1042)+n(1473)])}["_handleP"+t(361)](n){let s=t;!n.persisted&&(this[s(832)+"er"]&&window[s(985)+s(1801)+"ner"](e[s(654)],this[s(1042)+s(361)]),this[s(832)+"er"]&&window[s(985)+s(1801)+s(1382)](e[s(1354)],this["_handleP"+s(1473)]),this.close()),this._isBrowser&&window["removeEv"+s(1801)+s(1382)](e[s(548)],this[s(1809)+s(1370)]),this[s(832)+"er"]&&window[s(985)+s(1801)+s(1382)](s(710),this[s(1809)+s(829)])}["_handleP"+t(1473)](n){let s=t;n[s(1441)+"d"]&&(this[s(875)+s(1288)]()&&(!this[s(1745)]||this[s(1745)].readyState!==this[s(841)]||e[s(1017)](this[s(1745)][s(1152)+"te"],this[s(492)+"NG"]))&&this[s(1809)+s(1370)](),this[s(832)+"er"]&&window[s(1073)+s(1223)](e.sXFlb,this["_handleO"+s(1370)]),this[s(832)+"er"]&&window[s(1073)+s(1223)]("offline",this[s(1809)+"ffLine"]))}async[t(621)+t(826)](n){let s=t,{fpID:d,deviceID:u,bddID:x,ttwID:m,accessKey:b,aID:g,customParams:A={},enableAutoAck:k,enableQoS:N,QoSLevel:z,env:Z}=this[s(1110)],W,Ge,He;this[s(832)+"er"]||this[s(1707)+"X"]||this._isMiniTT?e.XajiI(s(954),e[s(1129)])?(W=location&&s(850)==location[s(1664)]?s(1525):e[s(669)],Ge=n[s(1465)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),He=/^wss(.*:\/\/)/[s(1466)](n)?n:""+W+Ge):this[s(1496)]++:(W="wss://",Ge=n[s(1465)](/(^http)((?:[s]*:\/\/))/,""),He=/(^ws)((?:[s]*:\/\/))/.test(Ge)?Ge:""+W+Ge);let Qe=x?"bd_did":m?e[s(530)]:e[s(1316)],at=x||m||u;if(!at||!Qe)throw new Error(e.NEmCc);let Xd=e.SPcTO(s(757),typeof A)?await e[s(1197)](A):A,Cp=Z?e[s(1310)](Zx,Z[s(560)],Z.xTTEnv):{},la=Object[s(1106)]({device_platform:e[s(600)],version_code:e[s(794)],access_key:b,fpid:d,aid:g,[Qe]:at,xsack:k?1:0,xaack:k?1:0,xsqos:N?1:0,qos_level:N?z:void 0,qos_sdk_version:2,...Cp},Xd),kp=Object[s(1146)](la).reduce((ua,fa)=>la[fa]!==void 0?""+ua+(ua?"&":"?")+fa+"="+la[fa]:ua,"");return He+s(483)+kp}async[t(1529)](){let n=t,s={nepza:function(d,u){return d|u},Oruhq:function(d,u){return e[q(1840)](d,u)},cVHmI:function(d,u){return e[q(1342)](d,u)},UMOQQ:function(d,u){return d<<u},nOaTA:function(d,u){return d&u},OOytT:function(d,u){return e[q(1082)](d,u)},ajYUu:function(d,u){return d<u},Kvmjq:function(d,u){return e[q(1356)](d,u)},xCRXe:function(d,u){return d+u}};if(!(this["_connect"+n(1802)]||this[n(1226)+n(696)])){this[n(1529)+"Lock"]=!0;try{let d=this[n(1111)+n(1346)]?.[n(1003)+"rentEndp"+n(877)+n(1453)+"tries"](),{timeoutInterval:u}=this[n(1110)];if(d)if(e.mMDph(e[n(371)],e[n(371)])){let m=this[n(1111)+n(1346)]?.[n(546)+n(768)+"nt"](),b=this[n(1111)+"tManager"]?.["replaceB"+n(1258)+"pointAndUpdateCount"](),g=this[n(1111)+n(1346)]?.[n(546)+n(768)+"ntTriesCount"]();if(b){let A="connect "+m+(n(1737)+n(1612)+"tries re"+n(1599)+n(1615)+"backup e"+n(1099))+b+(n(1836)+"y"),k=ot(n(627),{message:A,code:en[n(1552)+"IES_ERROR"]});this[n(1363)](A),this[n(576)+n(416)+n(1765)](k),this[n(1639)]=await this[n(621)+"eUrl"](b),this[n(1363)](n(1630)+b+" "+g+n(1641)),this["_removeW"+n(1198)+"rs"]()}else{let A="connect "+m+(n(1737)+", max retries re"+n(1417));this._debug(A),this[n(576)+n(416)+n(1765)](ot(e[n(481)],{message:A,code:en[n(1552)+n(811)+"R"]}));return}}else{if(e[n(680)](_0x279939,1)||e[n(1767)](_0xa0f6de,_0x12c3e2))return e.LqGnr(_0x41ab1e,_0x5b3086);e.UHgGF(_0x195aa8,_0x4a4d3d)>_0x11dd98&&(_0x356aa=e.NyJAI(_0x39b3d1,_0x540c2b),_0x596535=0);let m=_0x2dc0d6[n(332)](_0x409caa,_0x421fcc,_0x5ff1d6+=_0x5c33bf);return e[n(1201)](7,_0xb3e84e)&&(_0x4a0450=e[n(1112)](e[n(1264)](7,_0x179b0b),1)),m}else{let m=this[n(1111)+n(1346)]?.[n(546)+n(768)+n(1252)+n(373)](),b=this[n(1111)+n(1346)]?.["getCurrentEndpoi"+n(839)+n(1246)]();this[n(1639)]=await this["_generat"+n(826)](e[n(1376)](m,"")),this._debug(n(1630)+m+" "+b+n(1641)),this[n(402)+n(1198)+"rs"]()}if(this[n(547)])this._isInit=!1;else if(n(719)!==e[n(1832)])_0x57ae7d=vyhZEl[n(414)](vyhZEl.nepza(vyhZEl[n(1747)](vyhZEl.cVHmI(7,_0x573293)<<18,vyhZEl[n(1103)](vyhZEl.nOaTA(63,_0x41529e),12)),vyhZEl[n(1103)](vyhZEl.OOytT(63,_0xe24d80),6)),vyhZEl[n(1581)](63,_0x3bfe49)),vyhZEl[n(1689)](_0x4d87a6,65536)||vyhZEl[n(751)](_0xa4748e,1114111)?_0x1ab539+=_0x167660:(_0x323088-=65536,_0x24151e+=_0x455ef6((_0x4210d4>>10)+55296,vyhZEl.xCRXe(vyhZEl[n(856)](1023,_0xe0283d),56320)),_0x40912b+=3);else{let m=e.PhhjY(na,e[n(473)],{message:e[n(898)]});this[n(661)+n(835)]&&this[n(661)+n(835)](m)}let x=this[n(1111)+n(1346)]?.[n(546)+n(768)+n(839)+n(1246)]()||0;e[n(1587)](x,1)&&await this[n(893)](e[n(1772)](x,1)),this._debug(n(1334)+n(495)+this[n(1639)]+(n(1790)+n(1021))+this[n(812)+"ls"]),this._ws=$x({url:this[n(1639)],protocols:[this[n(812)+"ls"]],headers:this[n(1110)][n(1281)+"ramParams"][n(1414)+n(1305)]},this._options.ws),(this._isBrowser||this[n(1751)+"r"])&&this[n(1745)]&&(this._ws.binaryType=this[n(1159)+n(810)]),this["_addWsLi"+n(1164)](),this[n(1529)+"ionTimeoutId"]=e.AoHdp(setTimeout,this[n(1702)+"ut"][n(1504)](this),u)}catch(d){throw this["_connect"+n(1802)]=!1,d}}}[t(1727)+t(1413)](){let n=t;clearTimeout(this[n(1529)+n(1512)+"utId"]),this[n(1529)+n(1512)+n(1121)]=null}["_clearPi"+t(745)](){let n=t;clearTimeout(this[n(1327)+n(784)+"Id"]),e[n(1562)](clearTimeout,this["_reconne"+n(459)+n(612)]),this["_pingPon"+n(784)+"Id"]=null,this[n(1367)+n(459)+n(612)]=null}[t(1363)](...n){let s=t;this[s(1110)][s(967)]&&console[s(1634)][s(1633)](console,[e.LaEOF,...n])}[t(658)+t(1303)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:u,reconnectIntervalGrowFactor:x}=this[s(1110)],m=e[s(637)](d,Math[s(1158)](x,e[s(1160)](n,1)));return e[s(1105)](m,u)?u:m}_ping(){let n=t;if(this[n(1745)]&&this[n(1745)][n(1152)+"te"]===this[n(492)+"NG"]){this._clearPingTimer(),this[n(1327)+n(784)+"Id"]=setTimeout(this[n(1474)].bind(this),this[n(1110)]["pingInte"+n(631)]);return}if(!this[n(1745)]||this._ws.readyState!==this[n(841)])return void this[n(1843)+n(835)]();this[n(1745)]&&this[n(1745)].send("hi"),this["_reconnectTimeou"+n(612)]=e[n(1696)](setTimeout,this[n(1843)+"econnect"+n(663)][n(1504)](this),this[n(1110)][n(1270)+n(816)+n(364)])}[t(1843)+"econnect"+t(663)](){let n=t;this[n(777)+n(963)]?.[n(878)](),this[n(1560)](e[n(1773)],"timeout"),this[n(777)+"sCounter"]?.[n(508)+n(1285)+"nt"]()?this._handleReconnect():this[n(1474)]()}[t(875)+t(1288)](){let n=t;return this[n(1229)+"T"]||this[n(1707)+"X"]?this[n(336)+n(1814)+n(1352)]:(this[n(832)+"er"]||this[n(1751)+"r"])&&this[n(1110)]["listenNe"+n(1835)+n(1642)]?navigator.onLine:!0}[t(1843)+t(835)](){let n=t;!this[n(875)+n(1288)]()||this._readyClosed||(this._endpointManager?.["resetEnd"+n(493)+n(480)](),this[n(777)+n(963)]?.resetCounter(),this._ws?this["_disconn"+n(1043)](1001,e[n(1077)],!0):this[n(1529)]())}[t(1601)+t(908)+t(1349)](){let n=t,s={JbOaQ:function(d,u){return e[q(987)](d,u)},PvOMe:function(d,u){return e[q(919)](d,u)},yxWFO:function(d,u){return d!==u},nMnQG:e[n(382)],aiazV:n(1199)+"e_success",xjPxi:e[n(1773)],KrhLC:function(d,u,x){return e[n(1690)](d,u,x)},aTGQD:function(d,u){return e.hnkPW(d,u)},wPBlK:n(630)};this._isMiniTT?tt[n(1764)+n(1513)+n(605)](({isConnected:d})=>{let u=n,x={wMTfb:function(m,b){return m(b)},XusvI:function(m,b){return s[q(604)](m,b)},azQAX:function(m,b){return s[q(370)](m,b)}};s[u(1716)](s[u(1729)],s[u(1729)])?(_0x3c8eda=JKeGXq[u(1177)](_0x2737a4,_0x95a137),_0x20c704<32&&(_0x481d4b|=JKeGXq[u(1344)](JKeGXq[u(859)](127,_0x158139),_0x54611c)),_0x3c490c+=7):(this[u(336)+"igatorOn"+u(1352)]=d,d?this._handleOnLine():this[u(1809)+u(829)]())}):this._isMiniWX&&wx[n(1764)+n(1513)+n(605)](({isConnected:d})=>{let u=n,x={dPbwM:s[u(1411)],rruWu:s[u(676)],eFvwT:u(723),PjDXV:function(m,b,g){return s[u(796)](m,b,g)}};if(s[u(1054)]("HJlSx",s[u(1266)]))this[u(336)+u(1814)+u(1352)]=d,d?this["_handleO"+u(1370)]():this[u(1809)+"ffLine"]();else{let m={lwlQl:u(616),yRHLd:x.dPbwM,HFJEM:x[u(476)],wdhPz:x.eFvwT};this[u(756)+"ngTimer"](),this[u(1327)+u(784)+"Id"]=x[u(609)](_0x739d1c,this[u(1474)][u(1504)](this),this[u(1110)]["pingInte"+u(631)]);let b=()=>{let A=u;_0xf99876(m[A(351)]),this[A(867)](m[A(566)],b),this.off(m[A(1660)],g)},g=()=>{let A=u;_0x546299(m[A(1369)]),this[A(867)](m[A(566)],b),this.off(m[A(1660)],g)};this.on(x[u(1565)],b),this.on(x[u(476)],g),this._ping()}})}[t(893)](n){let s={ZZuDM:function(d,u,x){return e[q(1431)](d,u,x)}};return new Promise(d=>{let u=q;s.ZZuDM(setTimeout,d,this[u(658)+"rvalValue"](n))})}[t(1526)+"ect"](n=1e3,s="",d=!1){let u=t;this._ws&&this["_destroy"+u(854)+"t"](n,s,d)}[t(1702)+"ut"](){let n=t,s=this[n(1111)+"tManager"]?.[n(546)+n(768)+"nt"]();this[n(1363)](n(1630)+s+n(1737)),this._disconnect(1001,e[n(1557)],!0)}_sendAck(n){let s=t;if(e[s(554)]===e[s(554)]){let d=e[s(1559)](zt,n);if(this[s(1745)]&&e[s(314)](this._ws[s(1152)+"te"],this.OPEN))if(e[s(1406)]!==e[s(430)])this[s(1745)]&&this._ws[s(1619)](d),this[s(1363)]("send_ack",n);else return null}else this.emit(e[s(481)],e[s(1451)](_0x38fe6c,e[s(481)],{message:this["_formatE"+s(991)+s(1645)](_0x51b102)}))}[t(402)+t(1198)+"rs"](){let n=t,s=e[n(1638)][n(1194)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1745)]["removeEv"+n(1801)+n(1382)](e[n(1709)],this[n(315)]);continue;case"1":this[n(1745)]["removeEventListe"+n(1382)](e[n(481)],this[n(1415)]);continue;case"2":if(!this._ws)return;continue;case"3":this[n(1745)][n(985)+"entListe"+n(1382)](e[n(662)],this[n(1020)]);continue;case"4":this[n(1745)]["removeEv"+n(1801)+"ner"](e[n(1358)],this[n(1078)+"ge"]);continue}break}}_addWsListeners(){let n=t;this[n(1745)]&&(this[n(1745)][n(1073)+n(1223)](e[n(662)],this._onOpen),this[n(1745)][n(1073)+n(1223)](e[n(1709)],this[n(315)]),this._ws[n(1073)+n(1223)](e[n(1358)],this[n(1078)+"ge"]),this[n(1745)][n(1073)+"Listener"](n(627),this[n(1415)]))}[t(1272)+t(1034)](n=1e3,s=""){let d=t;try{if(e[d(1154)]===e[d(1181)])for(var u in _0x287d17)_0x6cec7.o(_0x6d8b9c,u)&&!_0x1a6341.o(_0x28af7a,u)&&_0x553ae8[d(1548)+"operty"](_0x135a18,u,{enumerable:!0,get:_0x2f9926[u]});else this[d(1745)]&&this[d(1745)][d(316)](n,s)}catch{}}[t(542)+"WebSocket"](n=1e3,s="",d=!1){let u=t;if(this["_clearPi"+u(745)](),this[u(1727)+u(1413)](),this[u(402)+u(1198)+"rs"](),this[u(1272)+u(1034)](1e3,s),this[u(1529)+u(1802)]=!1,d&&this[u(875)+u(1288)]()&&!this[u(1226)+"osed"]){if(this[u(1111)+u(1346)]?.["checkRea"+u(1542)+"es"]()){let m=this[u(1111)+u(1346)]?.[u(546)+u(768)+"nt"]();this[u(576)+"hCloseEv"+u(1765)](e[u(529)](xt,e[u(1709)],{code:1006,reason:"connect "+m+(u(1737)+u(1612)+u(695)+u(1417)),wasClean:!0}))}else{let m=this[u(1110)][u(691)+u(793)+"ptor"](n,s);this[u(576)+u(1516)+u(1765)](e[u(443)](xt,e[u(1709)],{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[u(1529)]()}return}this[u(875)+u(1288)]()||this["_readyCl"+u(696)]?this[u(576)+"hCloseEv"+u(1765)](e.pINDE(xt,e[u(1709)],{code:n,reason:e[u(844)]})):this[u(576)+u(1516)+u(1765)](e[u(1221)](xt,e[u(1709)],{code:1006,reason:e[u(1556)]})),this._ws=null,this[u(1111)+u(1346)]?.[u(1459)+u(493)+u(480)](),this[u(777)+u(963)]?.[u(918)+"nter"]()}[t(576)+t(1646)+"nt"](n){let s=t;if(e.VZvSD===e[s(746)])this.emit(e[s(662)],n),this[s(1480)]&&this.onopen(n);else{let d=e.EnshK[s(1194)]("|"),u=0;for(;;){switch(d[u++]){case"0":this[s(1745)][s(1073)+s(1223)](e.cJMGh,this[s(1415)]);continue;case"1":if(!this[s(1745)])return;continue;case"2":this[s(1745)].addEventListener(e[s(1358)],this._onMessage);continue;case"3":this[s(1745)][s(1073)+s(1223)](e[s(662)],this[s(1020)]);continue;case"4":this._ws[s(1073)+s(1223)](s(316),this._onClose);continue}break}}}[t(576)+t(720)+t(1145)](n){let s=t;this[s(1560)]("message",n),this[s(1179)+"e"]&&this.onmessage(n)}[t(576)+t(578)+t(1677)](n){let s=t;this[s(1560)](e[s(1726)],n),this[s(1724)+s(522)]&&this[s(1724)+s(522)](n)}[t(576)+t(416)+t(1765)](n){let s=t;this.emit(e.cJMGh,n),this[s(1338)]&&this.onerror(n)}[t(576)+t(1516)+"ent"](n){let s=t;this[s(1560)](e[s(1709)],n),this.onclose&&this[s(491)](n)}get[t(450)+"pe"](){let n=t;return this[n(1745)]?this._ws[n(450)+"pe"]:this[n(1159)+"ype"]}set[t(450)+"pe"](n){let s=t;this[s(1159)+s(810)]=n,this[s(1745)]&&(this[s(1745)][s(450)+"pe"]=n)}get[t(1673)+"nt"](){let n=t;return this[n(1111)+"tManager"]?.[n(546)+n(768)+n(839)+n(1246)]()||0}get[t(1090)+t(995)](){let n=t,s=this[n(1315)+n(427)][n(349)]((d,u)=>(d+=u&&u.byteLength||0,d),0);return e[n(1119)](s,this[n(1745)]?this._ws[n(1090)+"Amount"]:0)}get[t(1576)+"ns"](){let n=t;return this[n(1745)]?this[n(1745)][n(1576)+"ns"]:""}get[t(1664)](){let n=t,s={qDhTm:function(d,u){return e[q(423)](d,u)},PCUvf:function(d,u){return e[q(694)](d,u)},MvQXe:n(1161)+n(1447)};if(e[n(830)](e[n(774)],e.PyLIv))return this[n(1745)]?this[n(1745)][n(1664)]:"";{let d=_0x1b9115[n(1282)]&&_0x91b9be[0];if(BNFFtw[n(942)](d,_0x2a9d74))throw d;let u=new _0x31e1a4(BNFFtw[n(636)](BNFFtw[n(1283)],d?BNFFtw.PCUvf(" ("+d[n(1570)],")"):""));throw u[n(815)]=d,d}}get readyState(){let n=t;return this[n(1745)]?this._ws[n(1152)+"te"]:this[n(1110)][n(404)+n(1029)]?this.CONNECTING:this[n(1487)]}get url(){let n=t;return this[n(1745)]?this[n(1745)][n(791)]:this[n(1639)]}close(n=1e3,s){let d=t;if(this[d(1226)+"osed"]=!0,this[d(1727)+d(1413)](),this[d(756)+"ngTimer"](),this[d(1328)+d(1531)+d(1223)](),this[d(1032)+"ger"]?.[d(429)](),!this._ws)return void this._debug(e.EkwaE);if(e[d(1216)](this._ws[d(1152)+"te"],this[d(1487)])||e[d(1151)](this[d(1745)][d(1152)+"te"],this[d(1536)]))return void this[d(1363)](d(1321)+"s already closed");this[d(542)+"WebSocket"](n,s)}async send(n,s){let d=t,u={RfrgV:e.cJMGh,goaSr:function(He,Qe,at){return e[q(1780)](He,Qe,at)}};if(e.DFNPN(null,n))throw new Error(e[d(1005)]);e[d(1284)](e.vKUrf,typeof n)&&(n=JSON.stringify(n)),e[d(697)](e.emeME,typeof n)&&!e.TYIDu(n,ArrayBuffer)&&!(n[d(1380)]&&e[d(423)](n[d(1380)],ArrayBuffer))&&(n=JSON.stringify(n));let x=await e[d(950)]($d,n),m=e.cBpaW(Jx,n),{method:b=0,service:g=this._options[d(1172)],logID:A=this._options[d(1574)+d(927)](),headers:k=this[d(1110)][d(659)],payloadEncoding:N=this[d(1110)][d(487)+d(1304)],payloadType:z=this[d(1110)][d(1621)+d(810)],logIDNew:Z=this[d(1110)][d(381)+d(1109)][d(453)+"toGenera"+d(1452)+"ew"]?e.ucFeF(i,this[d(1110)][d(381)+"Config"][d(775)]):""}=e[d(997)](s,{});if(!g)throw new Error(e[d(686)]);let W={SeqID:ce[d(1682)+"er"](this._seqId++),LogID:ce[d(1682)+"er"](A),service:g,method:b,headers:k,payloadEncoding:e[d(1068)](N,Object)?N[d(327)]?N[d(327)]:"":N,payloadType:e[d(1273)](z,Object)?z[d(1083)]?z[d(1083)]:m:z||m,payload:x,LogIDNew:Z},Ge=zt(W);if(this[d(1745)]&&e[d(645)](this[d(1745)][d(1152)+"te"],this[d(841)]))this[d(1745)]&&this[d(1745)][d(1619)](Ge),this[d(1363)](e[d(474)],W);else if(this["_message"+d(427)][d(1282)]<this[d(1110)][d(1137)+d(1196)+d(763)])this[d(1315)+d(427)].push(Ge),this[d(1363)](e.zGQCp,W);else if(e[d(804)]!=="bEMiE"){let He=_0x21ad65.buffer[d(559)](_0x2df123[d(966)+"et"],e[d(567)](_0x2b8a6c[d(455)+"th"],_0x47c116[d(966)+"et"]));this[d(1687)]&&this[d(1687)][d(1619)]({data:He,fail:Qe=>{let at=d;this.emit(orMTOo[at(385)],orMTOo[at(1041)](_0x2f92a0,"error",{message:this[at(347)+at(991)+at(1645)](Qe)}))}})}else this[d(1315)+d(427)].shift(),this[d(1315)+"Queue"][d(1524)](Ge);return{seqID:this[d(1827)],logID:A,logIDNew:Z}}async[t(691)+"t"](n){let s=t,{url:d}=e[s(884)](n,{}),u=Array.isArray(d)?d:e[s(712)]==typeof d?[d]:[];n&&Object.assign(this[s(1110)],n),u&&u.length?this[s(1111)+s(1346)]=new qd(u,this._options.maxRetries):this[s(1111)+"tManager"]?.[s(1459)+s(493)+s(480)](),this[s(777)+s(963)]?.["resetCou"+s(1e3)](this[s(1110)][s(765)+s(1842)]),this[s(1226)+s(696)]=!1,this[s(1745)]&&e[s(1631)](this[s(1745)][s(1152)+"te"],this[s(1487)])?this[s(1526)+s(1043)](1e3,e.SQThW,!0):(this[s(547)]=!0,this[s(1529)]())}async connect(){let n=t;!this[n(1529)+"Lock"]&&(e[n(1649)](e.alqfM,"tMRVt")?(_0x4bd116(),pljtei[n(1789)](_0x25d34c)):(this[n(1111)+n(1346)]?.["resetEnd"+n(493)+n(480)](),this["_pingLos"+n(963)]?.[n(918)+n(1e3)](),this["_readyCl"+n(696)]=!1,this._isInit=!0,this[n(1529)]()))}addEventListener(n,s){this.on(n,s)}[t(441)+t(1145)](n){let{type:s}=n;this.emit(s,n)}[t(985)+t(1801)+t(1382)](n,s){let d=t,u={CbUsN:function(x,m){return e[q(520)](x,m)},LMnfU:function(x){return e.QDcno(x)}};if(e.ihRTP!==d(565))this[d(867)](n,s);else{let x={ebQkn:d(616),PKokf:pljtei[d(481)]},m=()=>{let A=d;_0x467336[A(985)+"entListe"+A(1382)](x[A(962)],b),_0x5782ba[A(985)+A(1801)+"ner"](x[A(1141)],g)},b=()=>{let A=d;DpZyGL.CbUsN(_0x5e0b17,DpZyGL[A(1753)](_0x1e8505,_0x53e22c[A(1104)])),DpZyGL[A(1295)](m)},g=()=>{let A=d;_0x64cb7a(_0x1cc2f8[A(627)]),DpZyGL[A(1295)](m)};_0x173dff[d(1073)+d(1223)](pljtei.DHrYx,b),_0x39378c[d(1073)+"Listener"](pljtei[d(481)],g)}}[t(1060)](){let n=t,s={vzyQD:function(d,u){return e.aluav(d,u)},saEpp:e[n(1573)],IuYpj:e[n(1569)],sFXke:e[n(1773)],wOFKG:function(d,u){return e[n(903)](d,u)},nVKay:e[n(939)],LOXgN:function(d,u,x){return e[n(602)](d,u,x)}};return new Promise((d,u)=>{let x=n;this[x(756)+x(745)](),this["_pingPon"+x(784)+"Id"]=s.LOXgN(setTimeout,this[x(1474)].bind(this),this._options[x(948)+x(631)]);let m=()=>{let g=x;s[g(1130)](d,s[g(688)]),this[g(867)](s[g(1347)],m),this[g(867)](s[g(1269)],b)},b=()=>{let g=x;s[g(1094)](u,s[g(1436)]),this.off(s.IuYpj,m),this[g(867)]("ping_onc"+g(827)+"t",b)};this.on(s.IuYpj,m),this.on(s[x(1269)],b),this[x(1474)]()})}}})(),Le["CustomCl"+M(724)]=Te[M(1167)+M(724)],Le["CustomEr"+M(511)]=Te["CustomEr"+M(511)],Le[M(685)+"e"]=Te.ErrorCode,Le[M(1145)]=Te[M(1145)],Le[M(1549)]=Te[M(1549)],Le[M(1785)+M(1298)+M(1774)]=Te[M(1785)+M(1298)+M(1774)],Le[M(1298)+"vent"]=Te["MessageE"+M(1774)],Le[M(369)+"t"]=Te[M(369)+"t"],Le.ReconnectEvent=Te[M(341)+"tEvent"],Le[M(1760)+M(724)]=Te[M(1760)+"oseEvent"],Le["createEr"+M(511)]=Te[M(577)+"rorEvent"],Le["createMe"+M(464)+"nt"]=Te[M(558)+M(464)+"nt"],Le[M(363)+M(813)]=Te[M(363)+"enEvent"],Le["createRe"+M(1040)+"vent"]=Te["createRe"+M(1040)+M(1774)],Le["decodedF"+M(822)]=Te[M(555)+"rame"],Le[M(358)+M(1056)]=Te[M(358)+"ame"];for(mo in Te)[M(1167)+M(724),M(1546)+M(511),"ErrorCode",M(1145),M(1549),M(1785)+M(1298)+M(1774),M(1298)+M(1774),M(369)+"t",M(341)+"tEvent",M(1760)+M(724),"createErrorEvent",M(558)+M(464)+"nt",M(363)+M(813),M(1289)+M(1040)+M(1774),M(555)+M(822),M(358)+M(1056)][M(958)](mo)===-1&&(Le[mo]=Te[mo]);var mo;function q(t,e){t=t-312;let r=vo(),i=r[t];if(q.OOJsJp===void 0){var o=function(h){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",E="";for(let T=0,_,v,I=0;v=h.charAt(I++);~v&&(_=T%4?_*64+v:v,T++%4)?w+=String.fromCharCode(255&_>>(-2*T&6)):0)v=p.indexOf(v);for(let T=0,_=w.length;T<_;T++)E+="%"+("00"+w.charCodeAt(T).toString(16)).slice(-2);return decodeURIComponent(E)};q.ovUMhI=o,q.ozXEmm={},q.OOJsJp=!0}let c=r[0],l=t+c,f=q.ozXEmm[l];return f?i=f:(i=q.ovUMhI(i),q.ozXEmm[l]=i),i}Object[M(1548)+M(1609)](Le,"__esModule",{value:!0});function vo(){let t=["ywLxz2i","u3PjrK0","wgfQAuK","DMfzz20","Bfzurxy","DhjHBNnHy3q","Evf1AfK","CMv0CNLdB3u","Cgu6ia","v0X2s3e","x3fVC0rc","ywDLrxzLBNq","yxfjzu0","s3rzt2i","vfv1Cw4","s1fUyvC","zNjVBu51Bwi","z2vtDw0","DMnguwC","Ahv6Ahe","BeHHBMrSzxi","x3nVy2TLDa","qNjgsgu","ywPzvxu","yLzpreK","ChjVDg90Exa","rxD2Cxq","C3fJyvm","CMvZzxruCMK","CgfJDMe","DhjgqvC","ELHjCwG","zfPYEhK","rMn5z20","ruveu00","yvf1she","x29UvgLTzw8","qxzzAgO","qMX1Cem","Dg9Y","wePdAMG","x2LZtwLUAvC","CMfNzvn5BMm","qNLozxa","mhW1","CMvHzfvjBNq","s3DJyxq","C2v0","AxnAzxjV","uvnXDfC","ExHxrK8","Bw9fBMu","vLDIruu","zNDcCxi","y3vYDMfSDwu","y2rVCLy","D0PQq0m","BxnNsuq","B25szwnLAxy","D21dBM4","AMjAu1O","x2nSzwfYvgK","vKfHAhe","BK1UuuC","zwTUuxe","DxzqD24","qxDWywe","whLvuK8","zxHWB3j0CW","s2rWsLu","tezkyKi","ihrPBwvVDxq","tLDqy0m","sfDmtva","rfvetMG","C3rYAw5NAwy","x2n1CNnVCK0","EgTqBNu","CxvIAfy","x3DZ","BM9Uzv9UB24","t3j1Ahe","s2fqCMm","BwLZzq","tu5dDMu","x2LZv29YA2u","Dg9VigXHCMC","q2jvC04","vgHIBhy","B25Uzwn0Aw4","ufnPu0i","wLjvquG","CejsC2G","B25nzxnZywC","y3jLyxrLq2W","CMvHzg9UBhK","C2fNzq","s0PKvLe","B25ozxr3B3i","zw50","DLn3v1q","s3zlse4","qND0re8","ugHVCfq","Evvcywi","zNDZxZeUmc4","rvnxrg4","EKT4D0i","DMvUDa","q0Dkq28","ysbTDxn0igi","tLruCu8","BNnyz2K","zxmGCMvHy2G","t3DVwvy","vfneENy","DMvY","z2vY","vxLZzeu","rNjVBNrPzxi","yuHhDeK","BwvAweq","Ahrby2u","uLPJAhq","ihbYB3rVy28","te5eAeK","EK9iu2e","y29Kzq","vKvkAuO","BIWGAg9ZDg4","zNbsvKG","A0DcyMu","v1Dyt3a","AM9PBG","vgvPsem","zw50tgLZDgu","tg9JAW","CuXquxi","D2LSBfjLy28","t05rrvm","EujkthK","DgnwwMy","zwPSuxa","x2HHBMrSzu8","Be5rvKW","zvfywKy","CNvSAvO","CfDwANG","AwDHDg9Yt24","rfvzEM4","rKXTt1e","rNDdr3G","CgfYC2u","uKLnwKe","z3H5qK8","Exj6zLq","C3zSDfy","sLnptLa","ywnRx2nVzgu","CM92AwrLige","ywnRtxnNswq","x3nLCuLK","ywnR","DxrVuMvJB24","Aw5euvy","serrALG","sxLtwxy","BKn1qLq","zxz6wKm","DhDVCMTdAge","ihrVihjLDhi","v2PiuK0","zxjFywnRx20","yxKSig5LDhC","zurqseq","ufvhvgu","q291BNq","x2HHBMrSzvi","D2fZq2XLyw4","s2HQyva","Avzotg8","B0LUEKW","x29Uq2XVC2u","y2XVC2u","Bw5VD1i","vw9uzu4","yw51Ce1LC3m","uLDOs0m","Ag5fywG","B3PSrKS","u2TPCcbWyxm","r3H3Buu","we5syxi","zejJs28","zw5JB2rPBMC","B2jQzwn0u3q","zgf0yq","Aw9U","uvvnAuK","y2fSBa","BgL4t1y","igfYCMf5yNu","tLPHv3K","x21PBMLoyxy","BK1Nvvq","zMvY","yxKSihrYEsa","yNLjC0e","uMvJB25Uzwm","EgLSsfm","C2v0sxrLBq","Aw5PDcbrB1m","reiGzMfPBgu","yxrHlcbKyxq","x2zVCM1HDeu","qvzOCfm","CMvKDwnL","D05Oq2i","BhDSuwW","zsbHihn0CMK","CLvQv2O","uwzNsxy","yxfZz1G","DxLjEvi","yNvyAwS","zw5JB2rLrNi","yLjHrwS","yMLUyxj5","ywDLsgLKzq","u0ffteu","y3jLyxrLt3a","DMfS","yM1ssuu","Aw5L","zfDVCMTLCKC","twDsCuS","t3bLBKv2zw4","uhzptwu","ze5dsLG","zNj5wgq","yxrLq291BNq","D3LsAhO","s1v0vuO","sgfUCwW","turqALG","CMvJzwL2zwq","B2nRzxrtDwm","sLzSt0W","Bg9NsurozxC","yKXYzfq","D0LPzNG","uMHcA3y","uMzYz1y","D29sy1C","qvHRywG","y3jLyxrLrwW","EvjLy29UBMu","uNrWywK","sKDKDge","tw5eD2e","y0vUDLy","z1HSEve","zxjYtM8","Ef9MCM9UDgK","ywjVCNq","AhfpruK","t1z2zfe","A2TZv24","CKTLsuC","x3jLBw92zvC","uxnPtM0","yxv0B21HDgK","sfL4EMO","y3vYC29Y","ChDRCuu","D3v0qMu","q3nQD0K","BNn1Chy","zNjHBwvuExa","C0H1DfG","zKTtueW","BMvWEMe","rvjst1i","AevYCM9Yrxy","B3bLBIa","ihjLy29UBMu","yw5ZzM9YBvq","r2Lwt0y","zLHzr1O","rMftCLO","ugjODw0","DhjRANm","BwzNyMO","sKP2BNy","uxvLDwu","C2nYAxb0","y2XVC2veqG","CwDbAwC","CMvHC29U","y1LKzLy","EKDtwgG","sevRAhu","DgLUzYbZzxi","Ee92Bve","thjkDKG","Ag5Tthm","q3b0t2m","x3nLBMrby2S","zgLZCgf0y2G","rKLeC0i","svHerfe","ufnUyKi","CNrvAvi","DMvYC2LVBMm","wxDqqxi","zwjUBLu","BwfUDwfSihi","yMLUyxj5vhK","z1vNEge","q0Dlvfm","zw5HyMXLqxu","uvLZqKi","yNL0zuXLBMC","nxWX","C0HeAve","BfrPBwvVDxq","y3ruAw1LB3u","ign1CNnVCIa","ywnRpwzYB24","ChjVy2vZCW","ChHVEhy","C3nHz2vfDMu","teLpAwu","AgLNAa","vg9XruG","AKLxqxm","sLbJAeG","z2vtEw5J","suLQzvK","Aw1LCYbPBIa","t2PMBMG","Ee9prgm","EKrIDeC","CNj1v3u","BMvJDa","uLvWBgS","ufjsC3y","zMLN","y0Pnr2G","vM5bs3O","l3DZl3yY","tvH6rKq","C2XnBeS","BgLTAxq","Cgf5Bg9Hzeu","mhW0Fdj8m3W","zxjFCw9Zx2e","mxW1FdH8nNW","B25JBg9Zzq","q09otKvdveK","Cg9PBNrdB24","yMjUCfG","BMCGDxjSoIa","twLZC2LUzYa","Chv5CeC","s2ryuhu","B21Wr3K","EwDmELO","vxPysLi","s1PgyuG","vvnpt2u","zxjFAxnFywm","EfHkCfq","tfLMrvu","v0fJvNe","y2HLy2Tszwe","tMfTzq","t0fvBMW","CM9YrxzLBNq","CLzHBhvLCW","ywnRx2LK","C29Tzq","CMn4uuK","vfPhrhC","yxnL","s3zWCK8","AwXLtMfTzq","DM9TCLK","mMjADK1gDq","zufJAW","uMv2z0G","t3vhCgK","zgrjrcWGzgu","BMvLzf9Hy2S","DwPJqvO","y0vMBLi","sKvirvK","sNL0zgK","C3rYAw5N","BMrLEa","Bwv0Ag9K","qLPOthi","ugn6Beu","CKvzqKy","ywrKt25L","rvzZsgi","A0LKyNa","lcbOB3n0BMe","BK9XBwq","x2rLC3rYB3K","BMCGB3iGyw4","Ahr0Ca","B25dBg9Zzq","z2v0q3vYCMu","x2LZsw5PDa","C1HgBgi","y2vZC0HHBMq","zMzMzG","r0jwr2u","yM1bCMK","uhbhEhq","wuTuy08","zgvJB2rLzey","rNHYt20","y3jLyxrLt2i","y3jLyxrLtwu","C2XPy2u","EfvZzuvUDG","BgLUzw5V","DgLTzw91DcW","shDhv0G","vfzgDem","yvnOqMy","Evjitgq","ChfrwKG","yuXAEMC","uMXoD1i","CNbjq3m","s25othO","pxv0zI04","ywX3yxLZ","rhnorge","tujNDu4","x2rPC3bHDgm","y3jLyxrLrxi","AefJA01LC3m","ENr1u3O","y255wNi","BePYsu0","rhrUuvO","Cgf5Bg9Hza","tMzVrNa","A3P2sey","mZzJrer6qLi","AgfZt3DUuhi","qwLVzMC","qwjuDgu","AgLvBw0","DMLJzuLeig8","zNvnr2O","BgDnqu0","BMrWB2LUDfq","Bg93","AxnszwfKEq","v2HvDwC","y3H6wM4","AgP2u1G","Ahz5yue","EfbZBuy","r05NugO","zhjXweS","sMjpyve","AgfUz2u","D1rvwLe","CfLtyue","CMvwvxG","ugPewfy","zM9YrwfJAa","Bxz4AwC","DeLK","n3WXmhW5Fdq","zgDtCxi","DwnZywe","C3vJy2vZCW","yKvnAuu","q3ruENG","zLDUsKm","B3DpDfK","x2DLBMvYyxq","vfLjrhu","vvf4qw0","r05tsvO","t3Dpwuy","suT2yvm","zxjYB3i","AvbzveG","su5tvefova","sePSu3G","CNzHBa","zNjVBujPDhm","De1svNq","yM5dBM0","AxnbCNjHEq","uenvDMy","r1rjDKK","txzUDMe","DeL5DeC","Dw5KzwzPBMu","BMv4DcGPigm","CMvQzwn0","Aw5JBhvKzxm","zNnVCvK","r29ptNy","rxrSqKG","AwXK","B3bLBKrc","x2LUAxq","EfD1zMG","t1Phzhy","Dhr3Awq","CNbNELa","qwPxC2K","zKHkBK4","zhPfwgm","y29Uy2f0","x2DLDeLUDgu","AgvHzgvYCW","C0Xf","B25tDgfYDfi","zKzYyLK","vgLTzw91Da","zK9ywMe","zKvfwxK","Dgv4Dc9WBge","t1bftL9fuLi","D3DPr2i","shDjz0y","D09HDKW","mxWW","B3PhBwq","r1ncB24","DhjPBq","ywXS","EgPqEgK","EhflvwS","C21kyxO","D1bUD1C","C1LNChy","wMzmAuC","y2XLyxjtDg8","BezSDxnO","tfbszeW","rxjYB3jdB2q","qNnzEhu","y2HHCKnVzgu","C2ffCha","ruL1uLe","AxnmB25N","CMvJB25Uzwm","uKrewvG","ruPkBeO","tenIzeS","DhjPzxmGCMu","B3nLza","yKL1EvK","Aw5KzxG","sNjoEg4","yKHVAuS","AxfKyva","m3W2Fda","C3rHCNq","s1vNrhu","igzHAwWSig0","uxn3zKW","mZqZnJG2nhjtzhrTza","vvLqEKe","ihzHBgLKihm","B2zMBgLUzq","tvjdu00","zw1Ltuu","zMXVB3i","y2HiBxy","zNjVBunOyxi","yNHKD2i","CeD1y3q","yNLL","DNvuv1q","Ae1LC3nHz2u","nta2ndqZn2jItxfctq","tuvtu0fhrv8","DgLTzw91Da","B3nLrxzLBNq","AvvhCeG","ywrK","BwfW","EeH6thK","EfrYBve","Dg9oDw1Izxi","Dhnewfe","aaaaaaaaaaa","B3npDKW","DgHHBIbSB2m","mJb6sMfmwM0","s0zsz0G","z2v0sxrLBq","Euj4EKS","qxjKrey","BgvY","rwPRCMe","CMvWBgfJzui","r2XAtgi","vwHAqxy","BMDuAw1LCG","vLP2u0q","zMLSDgvY","rhP2veC","D0rosKK","veTktwW","s3zTANe","y0jWyvC","C0jf","Dgv4Dc9Qyxy","uLjpuG","x2nSzwfYugK","zNvUy3rPB24","B2vywgi","B1DlBwO","ALzgtMO","sxHiBLy","zxjFDhrS","zw5NDgG","sM9ds3i","CgLUz0XVC3m","DMzhsLe","yw1nr3e","BNrfBMrWB2K","CgfNzwHPzgu","B2nRzxrgywK","s2Lhueq","B3bLBG","uwnxtxi","ExbSAhm","DxnLCKLW","sMHPC00","x3bPBMDmB3m","zxq9DxrMltG","igXHCMDLCIa","EgLyuva","tKDFrvjst1i","qMrWB3u","CvH0tLe","z1rPBwvVDxq","tMLmz28","A2v0ignVBNm","vgLOsKK","AgPvwLG","BNvTyMvY","x2nYzwf0zvm","DxjS","vgTtDue","DeLUDgvYy2u","uhDVDfm","Ag9Av2S","s3jOtem","u0rjy2y","mZC2mJa0nfHpq0Xdza","x3bHDgHlzxK","quXm","v2z3A28","t09pwue","yMH4wg4","u1P5Bu0","Dgv4DfbHEwW","B3PZv1G","x3bYzwzPEa","B0PNu20","yurXs04","ExbL","suvtx0vsuK8","x3bYB3rVy28","zw5fDMvUDa","DgHLBG","y29UDgv4Da","B3v0sw50zxi","y29SBM8","B3jvy2G","CMfUzg9T","uhjfwuy","ug9HBve","CMfTzq","AgHVrLK","Dg9tDhjPBMC","zxH0ugf5Bg8","zvvYBa","zv90Aw1LB3u","u2vXsuq","zMzmAw5L","txHizuW","EMXIAvC","x2LZqNjVD3m","t1LOvge","CMvJzxzPzwq","zwnVBM5Ly3q","DKzJrwm","z01wtNu","x19LC01Vzhu","BNruCMLLC0m","Bgjyr0G","t1bftG","uKP4DK4","BvziqKu","rhzYzwi","v2rVwLy","wxDPDuK","B25SAw5L","z2v0u3rVCMe","ChrdrKy","Ahr0Chm6","q3rkBhu","rfLsqKS","y29UDgLUDwu","v2vIu29JA2u","AKLRveK","BK9Hvee","z2v0s2v5","r1LpBLC","yxPrqvG","z0vsEfG","q09oveLovuu","nhWYFdf8nxW","B1rbBvO","ChrVCG","t0rHrxa","C2v0q3vYC28","B2zM","Dw5cu2q","ywzmv3u","seHlELa","CgXLyxnLiha","ALrwCvm","C1PTA0y","uNvgzfa","x25HDMLNyxq","s1zWCgO","B2LUDfjLywm","ywrKq291BNq","AePytLy","CgnkDKK","rwvqANm","Dw5ZAwDUzwq","vMrIyvi","BMXsseq","wxDOzuS","Axb6Bwy","u3rYyxrLz3K","DNriwhq","AvngAwi","yNL0zxm","teH2DLu","qxbVEhK","x3DHAxq","AxnFywnR","zw1uBem","Aw5KzxGGB3u","u1v3A3C","tw1Kz2W","BwfAvey","uM1mq28","sffhy2O","zMXnBMW","Avn2BgG","DhPuA2S","DxbKyxrLq3u","AKHJqvy","t2jQzwn0","zxrxB3jRq2G","AgfZ","nty4mtK0nvL5z3bRDG","zwn4EvK","C2v0y3vYC28","y29UC3rYDwm","zujrBfq","whHPA0u","Ec11C2uT","vK54vLa","CMvZzxrdB3u","q01crfa","t3rnEfe","t3H3vwC","tfz6txe","CgfNzxnOB3C","zw5HyMXLuw8","CM92AwrLihy","Bvf6uvq","zxjHDg9Y","z2u6ia","Bg9IywXty28","sw5mrfK","AhbQuwK","uNrqtu4","sxH3u2u","BKrIC2u","AhzIyM8","zxj2uNe","y0D0D2K","z2v0qwXS","y210y2q","BhDAsuy","v3bRr2q","CurOvg0","vejQBgq","vuL3vha","y3vYC29Yx2y","t1bYtMW","whryuxG","CgLUz0LUDgu","B25tDg9Wsw0","wKXdwwi","Fdj8m3WW","CM5Nwve","ihrYEsbYzwm","yvnArw0","BMfTzq","Cg1Tr3m","tMPfvLu","Aw5KzxHpzG","CMvTB3zLq2G","mhWYFdn8nhW","zg9Uzq","zwjrA24","C0nVDw50zxi","yLrPELC","q2neq0q","yNL0zu9MzNm","zgvIDwC","sxzhs2C","AMrAvuy","DgfYz2v0","ELDAwei","C2HPzNq","rensuxq","Cw1ssfC","rLjptLrjrvi","x2LUDgvYDMe","zvnWyLq","AKXYEfa","su5pCgy","vfnhDfC","yw1Lu3bHy2u","sgLuz24","yLzuEMi","BMCGzMfPBgu","CMvTB3zLrxy","B2D5yK0","ChbRA1O","ywXSB2nvBNm","Cgfuwwy","DMfdDNe","CNjVCK1LC3m","s0ftzNm","o2nOyxjZzxq","A2HOqMG","qw1VDw50","rLjHuva","BNHXzwC","CMLLC0nVDw4","rM1wrMO","BNrLCG","D24GCMvHC28","uunACvC","y2HLy2TdDxi","tg9Nsuq","D0LMz3O","Chv0","Dg9mB3DLCKm","tg9NsurozxC","y2f0y2G","ugThtK8","wxriq0W","Dun6EhK","yKLfs2C","zNf4Ahm","r0POEhy","CwLOqNO","Ehv4qxi","zhvXA3a","Aw5N","x29Ut3bLBG","Bhm6ia","B3z6D0O","vfz5DvO","uKjYzw0","mJC1mtq1mfHVCMzIvG","wMXyvLq","ufnMCxe","uxHODhu","y09Wzw4","uwryCfO","Aw50zwDLCIa","x1fVu01HBMe","y3vYCMvUDeK","BMnLq2XVC2u","terUC2S","zMT2rMK","r3fJyuO","weHjtg4","CLPHrg4","y29UBMvJDeu","z29Hu3i","x2HHBMrSzva","zwn0","BwLUzW","suXSy2C","txPJrva","De5ZBNq","q3rYrgK","yM9KEq","C3rVCcbPBw0","zxvSALe","rxfqExq","sezfDuG","yvrhuuq","zxjFBxnNAwq","yw1L","D09fANi","tKX5D3O","uLLTqva","CgLUz09Uy2u","CwvWqwu","AMTTvgG","sLv4rKW","tvrcve8","DevXBKC","Cvzfrhu","wND4Au8","reXKy2q","oxWXmxWXmhW","v0zoDeq","C2v0zgi","Cu1SEwW","ywrKrxzLBNq","C3rVCMu","sMnzrNO","vuzqA2G","q2rJELu","x29UtwvZC2e","yw5Hz2vY","CKzOq2m","yvDXuLm","BhvMC04","DhLWzq","zgvSzxrLrge","ndeZmdy1nfPKDKTXAq","CfPoBgS","rKLiq3a","DMrXDvO","Cu9UC2i","yNvMzMvYzwq","B2n0A2G","nMHuBK9NvG","B3bLCNr5tMe","D09gs0C","B2nRzxq","v0fNvhe","AxnrB1nnzxm","rNzxANe","BMrWB2LUDca","B3jRzxjhBg8","zvbIEgm","z3jkDui","vu1puve","CMvZDwX0","yMrptfe","yxnZAwDU","tej5zKW","DvH6qKO","q29UzMLN","x29WDgLVBNm","x2vUzhbVAw4","EMDvwLq","zgv2AwnLx2K","EhL1swC","t0fht2u","Bwf4uMv0CMK","BvzQq24","r0XzuvG","B2Dmy1i","zMLUza","Dxrjza","EKnbuxK","rMTOs3a","B2zMC2v0","y3r4","z3j1D0S","tuLoENO","ywXty29Wzq","q0TmvNC","DNP5uuq","z1fxvMi","nNWWFdf8nxW","EgLsBwi","sfPbwfa","wwrlzgu","rgnnEKK","Bwf4twvZC2e","qKXRwwq","sgvoz3m","ANj6DKu","ueTVA2y","B3DjvKS","vwHdAgu","zgLZywjSzue","rxzLBNq","A2v5CW","BNjgshu","mhWXFdj8nhW","AKrbBxi","y29TCgXLDgu","Bu1eCgG","CMvHzhLtDge","sg9Vswi","Cxjjwxu","CMvZB2X2zq","A2LPrKG","DgLLCKPtt04","Cg93","x2jPBMfYEvq","D3vhC0K","vw5Oyw5KBgu","zMLSzw5HBwu","zKPyq3K","C3rLBMvYCW","CLb0Auu","vxvWwM0","q3vZDg9Tq2W","zNjVBuj5Dgu","A2zHuvq","BuXMtgy","qLfSq2G","C2vYDMLJzq","DgLcAfq","rgf3De4","Aw9Ul2PZB24","De5vwg0","D01uzMi","vxbKyxrLq28","B25TzxnZywC","zKHWu3G","CM1Wtge","uuDxr0y","C3vIyxjYyxK","r1PLreW","y2uGBM90igK","yMXVy2TLza","m3WYFdH8n3W","sxbIBeK","CvPWBey","wwz4ue8","DeHuC20","BwjuEMW","zezMEMi","C3bSAxq","B3LAu3i","z2vrDwv1zuW","CfvoEfy","C0XPC3rLBMu","CgLUz19VBMm","zNbJuMm","DKvlsKG","DNDWt3G","mdaWmdaWmda","wK55ALy","ChrZvKS","uufbBvq","BhrPCgXLihq","nhWYFdf8m3W","sLjitNu","t0LvEfO","Dg9iyxnO","txDVrKO","v2vPEgLUsLm","AKrpDKi","ExzSq0G","zgvryMS","EwP2v1C","BM5Ly3q","yxjYyxLIDwy","AxjLza","t01RBeK","x194x21Zz18","tgLZDgvUzxi","rez3Euq","Cfr4BgG","x3jLywr5q2W","zgvS","v2Xerwy","x2LZtwLUAvq","uxDYqvm","AxmGDw5Kzwy","z2v0","y2PXDee","Dg9cExrLC0W","C29YDa","tvbNweO","DuLvu3O","ChbL","r3f1t0S","yNbsBeK","DwLJD1u","t2v6whm","Ec1TC2CTy3u","DwjjExC","yxbWBgLJyxq","B3vUDa","q2fnz2q","sezoyLq","x2TLEvbHDgG","zw1LBNq","Dg9Mt1e","BNrbBMrvCgq","rgvKAwnHDgu","Ae9oyKy","zgvgt20","u0zrt3C","rgPRDg8","ywnRDxbfBMq","uhzgEKW","B3jRig9MzMW","uNnwD2q","t1fMD3u","EwjjtKW","CLzvBwq","y0vmt2m","D1bcBeS","DxrMofDYAxq","CMvQwvC","C0zyA2u","CgLUz1rPBwu","weHyq3a","x3DZsw5ZDge","zuLes0W","vgjVv2y","qM1vB0q","r3jSBu0","uvHkBei","rwXcAve","rvDmAu8","mNWZFdb8nhW","BwLUAvbYB2C","BgvUz3rO","txzrwgu","EM5QweW","y2HnyxHdB3u","qxPhzvu","AwrI","B3jpBMXPBMu","y3jLyxrLuMu","y3LeBhi","qMvhtuO","vLvxrLe","AuPvyuK","DvjZu0G","te1UzLu","vM5TCKu","BLreD2i","twvZC2fNzuu","qMrZuLu","tgfdCvC","ywLLCKK","C2vYDMLJzs0","CNzHBfzHBhu","BMnVzgLUzW","DhbizwfKzxi","AevgvNa","CMvXDwLYzwq","mtG2mJyWnfviEMfJyW","zMjuDxu","vffiEuK","B1DnEwu","Bgzrz2q","uurJBM8","Chvds0O","x21LC3nHz2u","uMLhu3O","r05sz1u","sfbrB3O","CKTUsNu","C3jJ","y2XVC2uSihC","rvb1y0q","Ag5RufC","v2LUzg93","DcbSAw1PDa","tKXoCgq","x3bPBMDqB24","x2rYB3bhBg8","ufbVu3C","zKLwCMy","tgHLD0u","B2fK","v25Hz1O","y29UBMvJDgK","rNfPrNq","AwXLx25HBwu","weLpyuW","B25LCNjVCG","zw5KCg9PBNq","AhzWzeq","rMTHEuu","z3DzAfm","sunTz1m","whvZDKK","A0voswu","De1HBMfNzxi","sxvzCgO","qNjPzgDL","yw5Nzq","vhPgBhK","zvvpDvG","BgLUzq","CMvUDevUzha","r0Pmwei","tfzmC3G","De5vwLO","vxj2sKG","DwjMywu","uMXPBgK","BwvKAwf0zwW","zNjVBNrPzxi","C2vYDMvYvgK","x2rLyNvN","B1LJy2S","CwTMDfq","ChjACK0","x3jLy29UBMu","BwvZC2fNztO","D2rOuhO","BKXPBMu","DM5zsuy","rgzVCw4","s3LZAKW","qNDxC28","CNnVCL9Uyw0","DNjjB04","vNjgB00","vujjqNe","yvrpvxK","yNvMzMvY","B01ttuO","BMvY","A3b1Aei","zw5HyMXLvhi","u3Lnvfu","CeH3Aeq","yKL5ENK","zNjVBuHHC2G","rMjhswC","q1rNDgW","q29mCwe","z2v0qwXSs2u","B3b2zfq","Be9syLm","Ec1TC2CTCw8","q0L5zey","y1LsqwO","q1jvrMK","Dhj1y3rVCIa","EgXkBxu","qwjVCNrfCNi","A0DQALK","r1DtDeK","x2LZtM9Kzq","rLvPwvm","z2j6ENC","x0rctMfTzq","yw1LoIa","ugDJAei","vw5xCLG","ywLHELy","Ee9cDee","BwvY","y3vZDg9Tshq","x29UrxjYB3i","v2HbugS","ywnOzwq","x2LUAxrqCM8","uuPWAK0","q29Kzq","Dw5RBM93BIa","zvjwuNK","rezoue4","x2rItMfTzq","Eu1dEuK","t09uAhO","A3n0teu","zcWG","Efjmywy","z2HSEKK","v1Livgq","sxbJDNK","Dw50","rM5lD04","rNzyDMq","BLzlyxK","whf3Cem","zhjMDuu","CerrC3O","B1LeAuW","CgvYC2LZDgu","BwTIAwe","yxv0BW","z3rzvvq","tvjJB2G","Du1tD3K","zcbLCNjVCI4","vgfN","uMvHzcbWyxm","CwrNywm","q1rJwNC","DgvmB2Djre4","AgvKtwf4uMu","AgvIuNy","zM9Yy2u","z2HkqLq","B3jL","wwPKwuq","CMvZzxrfBMq","Dgz0Due","tNfryK0","DcbVzIbYyw4","q05ZD2m","Bu1ZANO","CMvWBgfJzq","DgvZDa","yM9L","tKfusvzfx0u","yuPOC1K","z29PBMCGyxC","rMr2vNq","t2fKzMe","ywDLu2HVDW","x3bPBMC","AxnrB1nby2S","B3jLtMfTzxm","C2v0u3rVCMe","EePNy1e","D0HwBLa","B25VCgvU","tfnYB3G","ru1orxi","A2v5","Cg9PBNrbBMq","ELPfwNK","Du54ueS","q0Xpu0ve","BgLZDgvUtMu","vw5PBxbSzw0","wxjQCu4","zuLqDMO","zw5XDwv1zq","wvb6vvC","swHvBKS","CKjzCMG","y291BNq","shHQvue","yKHkBKS","zNnJyvG","wgLszNe","A0LYvxy","y3vYC29Yx24","CxzoyKi","yMLUza","m3WYFdb8nhW","z2vjBMzVu3K","icSG","EKvuAgK","AwnUAwe","wNHRr0u","AevPre0","Aw9UvgLTzw8","A1n0yxr1C0m","zMzLCG","surzsuC","AenSB3nLrxy","ALjUtuy","C1bVueG","x2n1CNnVCKy","wxLhtgK","BM93","wgXTr24","Bwf4tg9ZC0m","ChvZAa","D3nZoI8V","x2rPC2nVBM4","y29ZDfG","r3PXyKi","x2nVBM5Ly3q","Aendvhi","yMfSrxzLBNq","qxnhshi","suLWww0","qNzWsMm","CNnoz1m","q0Xpu0LorW","tLPoywO","yxbWzw5Kq2G","tw9KDwXL","uuDlrge","v0ToqNC","y2HnyxHuCMK","zvbjBNu","C3vIC3rYAw4","DgvKEuC","q3vZDg9Trxi","vfbUAwy","zgvMAw5Luhi","rLDt","zMX1C2HfEha","y3vYCMvUDeu","tufyx1jfvfi","mdaWma","AhDqCvO","AfveveG","q0ncAxi","ELzrq1a","qK1NChu","y2fYqMi","zw1PDa","rgLrtNu","Dwngzuy","ig1LC3nHz2u","Cg5rD2u","zfbID00","x2fKzfDZtgK","DxPyCvu","x0vysvnu","D0XlvNy","BwvZC2fNzq","igzPzwXKoIa","yLnws2W","reHYwxG","Bg9Nsurhzw4","s2HYAxe","zxH0zw5ZAw8","wvbVs3G","DuXPvwm","x2n1CNnVCK4","vgrytvO","t095Dfq","u29btvi","yxGGCMv0CMK","ihzHBgLKigq","whL1A2G","vNv1yLK","yvnzEhe","D3jPDgu","A3zQvgm","jMPZy2fSBgi","v3fquem","ywWGy3vYC28","Bwu6ia","D29Hwha","C2vUDa","y29UBMvJDfm","rhHdvui","zxj2AwnL","ywnOzwqSihC","AKjMEe0","x29UugfNzu4","Chj5r04","rKLmrv9ot1q","uvbSDMe","zgvSzxrL","vNbODNi","wvnqCwq","vNDVzvG","B3bLCNr5","AvPjre4","CLDstwO","lcbTyxGGCMu","Dg9cExrLC0i","DvHUBLq","AwXSihvZzsa","ww9Muxe","BeLsCg4","u0rJywe","C2vUza","Dw9MD0y","Cgf5Bg9Hzfq","ywzuwM8","t29nALC","x2XPC3rLBMu","twzjAhO","z2TjsMK","z2v0q3vYC28","tNLkquK","zcWGDw5RBM8","y29UBMvJDca","zxHoCeW","AeXhCeO","yxbWBhK","Bg9N","u0vvtNa","zxjYtxnN","CMvHzhDYAxq","D3Pcrfe","x3vYBa","y2XLyxi","ihrPBwvZ","BMDLza","D3jPDgvvAw4","svLZrwS","ywDL","Ae9Wzw5fDMu","q1rwveu","swrLz2W","yLzSwe4","A3PqCvu","yufsCfe","ywzL","D1PIs3G","CenouKK","ywrWuLi","zv9ZDwnJzxm","s0nmDxu","DM1Av2i","DMfSDwu","sezkru0","sujrAeG","D1HQv1q","x2LUAxrhBg8","ChjVDg9JB2W","r1DPwxC"];return vo=function(){return t},vo()}});var $t=se((zD,Jf)=>{"use strict";var $f=["nodebuffer","arraybuffer","fragments"],Vf=typeof Blob<"u";Vf&&$f.push("blob");Jf.exports={BINARY_TYPES:$f,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Vf,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var zi=se((FD,So)=>{"use strict";var{EMPTY_BUFFER:Pb}=$t(),Qc=Buffer[Symbol.species];function Lb(t,e){if(t.length===0)return Pb;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new Qc(r.buffer,r.byteOffset,i):r}function Zf(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Yf(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function Nb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ed(t){if(ed.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Qc(t):ArrayBuffer.isView(t)?e=new Qc(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ed.readOnly=!1),e}So.exports={concat:Lb,mask:Zf,toArrayBuffer:Nb,toBuffer:ed,unmask:Yf};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");So.exports.mask=function(e,r,i,o,c){c<48?Zf(e,r,i,o,c):t.mask(e,r,i,o,c)},So.exports.unmask=function(e,r){e.length<32?Yf(e,r):t.unmask(e,r)}}catch{}});var eh=se((UD,Qf)=>{"use strict";var Xf=Symbol("kDone"),td=Symbol("kRun"),nd=class{constructor(e){this[Xf]=()=>{this.pending--,this[td]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[td]()}[td](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Xf])}}};Qf.exports=nd});var Cr=se((GD,ih)=>{"use strict";var Fi=de("zlib"),th=zi(),Mb=eh(),{kStatusCode:nh}=$t(),Bb=Buffer[Symbol.species],zb=Buffer.from([0,0,255,255]),Ao=Symbol("permessage-deflate"),Vt=Symbol("total-length"),Dr=Symbol("callback"),En=Symbol("buffers"),Rr=Symbol("error"),Io,rd=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,!Io){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Io=new Mb(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Dr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Io.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Io.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Fi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Fi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Ao]=this,this._inflate[Vt]=0,this._inflate[En]=[],this._inflate.on("error",Ub),this._inflate.on("data",rh)}this._inflate[Dr]=i,this._inflate.write(e),r&&this._inflate.write(zb),this._inflate.flush(()=>{let c=this._inflate[Rr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=th.concat(this._inflate[En],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[En]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Fi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Fi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[En]=[],this._deflate.on("data",Fb)}this._deflate[Dr]=i,this._deflate.write(e),this._deflate.flush(Fi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=th.concat(this._deflate[En],this._deflate[Vt]);r&&(c=new Bb(c.buffer,c.byteOffset,c.length-4)),this._deflate[Dr]=null,this._deflate[Vt]=0,this._deflate[En]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};ih.exports=rd;function Fb(t){this[En].push(t),this[Vt]+=t.length}function rh(t){if(this[Vt]+=t.length,this[Ao]._maxPayload<1||this[Vt]<=this[Ao]._maxPayload){this[En].push(t);return}this[Rr]=new RangeError("Max payload size exceeded"),this[Rr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Rr][nh]=1009,this.removeListener("data",rh),this.reset()}function Ub(t){if(this[Ao]._inflate=null,this[Rr]){this[Dr](this[Rr]);return}t[nh]=1007,this[Dr](t)}});var kr=se((HD,To)=>{"use strict";var{isUtf8:sh}=de("buffer"),{hasBlob:Gb}=$t(),Hb=[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 qb(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function id(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function jb(t){return Gb&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}To.exports={isBlob:jb,isValidStatusCode:qb,isValidUTF8:id,tokenChars:Hb};if(sh)To.exports.isValidUTF8=function(t){return t.length<24?id(t):sh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");To.exports.isValidUTF8=function(e){return e.length<32?id(e):t(e)}}catch{}});var dd=se((qD,fh)=>{"use strict";var{Writable:Wb}=de("stream"),oh=Cr(),{BINARY_TYPES:Kb,EMPTY_BUFFER:ah,kStatusCode:$b,kWebSocket:Vb}=$t(),{concat:sd,toArrayBuffer:Jb,unmask:Zb}=zi(),{isValidStatusCode:Yb,isValidUTF8:ch}=kr(),Do=Buffer[Symbol.species],ut=0,dh=1,lh=2,uh=3,od=4,ad=5,Ro=6,cd=class extends Wb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Kb[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Vb]=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=ut}_write(e,r,i){if(this._opcode===8&&this._state==ut)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Do(i.buffer,i.byteOffset+e,i.length-e),new Do(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Do(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case ut:this.getInfo(e);break;case dh:this.getPayloadLength16(e);break;case lh:this.getPayloadLength64(e);break;case uh:this.getMask();break;case od:this.getData(e);break;case ad:case Ro:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[oh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=dh:this._payloadLength===127?this._state=lh:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=uh:this._state=od}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=od}getData(e){let r=ah;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&Zb(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=ad,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[oh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===ut&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ut;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=sd(i,r):this._binaryType==="arraybuffer"?o=Jb(sd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!0),this._state=ut,this.startLoop(e)}))}else{let o=sd(i,r);if(!this._skipUTF8Validation&&!ch(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===ad||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!1),this._state=ut,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,ah),this.end();else{let i=e.readUInt16BE(0);if(!Yb(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Do(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ch(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ut;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ut,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[$b]=o,l}};fh.exports=cd});var fd=se((WD,ph)=>{"use strict";var{Duplex:jD}=de("stream"),{randomFillSync:Xb}=de("crypto"),hh=Cr(),{EMPTY_BUFFER:Qb,kWebSocket:eE,NOOP:tE}=$t(),{isBlob:Or,isValidStatusCode:nE}=kr(),{mask:xh,toBuffer:Hn}=zi(),ft=Symbol("kByteLength"),rE=Buffer.alloc(4),Co=8*1024,qn,Pr=Co,vt=0,iE=1,sE=2,ld=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=vt,this.onerror=tE,this[eE]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||rE,r.generateMask?r.generateMask(i):(Pr===Co&&(qn===void 0&&(qn=Buffer.alloc(Co)),Xb(qn,0,Co),Pr=0),i[0]=qn[Pr++],i[1]=qn[Pr++],i[2]=qn[Pr++],i[3]=qn[Pr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let f;typeof e=="string"?(!r.mask||l)&&r[ft]!==void 0?f=r[ft]:(e=Buffer.from(e),f=e.length):(f=e.length,o=r.mask&&r.readOnly&&!l);let h=f;f>=65536?(c+=8,h=127):f>125&&(c+=2,h=126);let p=Buffer.allocUnsafe(o?f+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=h,h===126?p.writeUInt16BE(f,2):h===127&&(p[2]=p[3]=0,p.writeUIntBE(f,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],l?[p,e]:o?(xh(e,i,p,c,f),[p]):(xh(e,i,e,0,f),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=Qb;else{if(typeof e!="number"||!nE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+f),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let l={[ft]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==vt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Or(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ft]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Or(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ft]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[hh.extensionName],c=r.binary?2:1,l=r.compress,f,h;typeof e=="string"?(f=Buffer.byteLength(e),h=!1):Or(e)?(f=e.size,h=!1):(e=Hn(e),f=e.length,h=Hn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=f>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[ft]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:l};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==vt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ft],this._state=sE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(ud,this,f,o);return}this._bufferedBytes-=i[ft];let l=Hn(c);r?this.dispatch(l,r,i,o):(this._state=vt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(oE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[hh.extensionName];this._bufferedBytes+=i[ft],this._state=iE,c.compress(e,i.fin,(l,f)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");ud(this,h,o);return}this._bufferedBytes-=i[ft],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(f,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ft],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ft],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};ph.exports=ld;function ud(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function oE(t,e,r){ud(t,e,r),t.onerror(e)}});var Sh=se((KD,vh)=>{"use strict";var{kForOnEventAttribute:Ui,kListener:hd}=$t(),gh=Symbol("kCode"),mh=Symbol("kData"),wh=Symbol("kError"),_h=Symbol("kMessage"),yh=Symbol("kReason"),Lr=Symbol("kTarget"),bh=Symbol("kType"),Eh=Symbol("kWasClean"),Jt=class{constructor(e){this[Lr]=null,this[bh]=e}get target(){return this[Lr]}get type(){return this[bh]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var jn=class extends Jt{constructor(e,r={}){super(e),this[gh]=r.code===void 0?0:r.code,this[yh]=r.reason===void 0?"":r.reason,this[Eh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[gh]}get reason(){return this[yh]}get wasClean(){return this[Eh]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Nr=class extends Jt{constructor(e,r={}){super(e),this[wh]=r.error===void 0?null:r.error,this[_h]=r.message===void 0?"":r.message}get error(){return this[wh]}get message(){return this[_h]}};Object.defineProperty(Nr.prototype,"error",{enumerable:!0});Object.defineProperty(Nr.prototype,"message",{enumerable:!0});var Gi=class extends Jt{constructor(e,r={}){super(e),this[mh]=r.data===void 0?null:r.data}get data(){return this[mh]}};Object.defineProperty(Gi.prototype,"data",{enumerable:!0});var aE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ui]&&o[hd]===e&&!o[Ui])return;let i;if(t==="message")i=function(c,l){let f=new Gi("message",{data:l?c:c.toString()});f[Lr]=this,ko(e,this,f)};else if(t==="close")i=function(c,l){let f=new jn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[Lr]=this,ko(e,this,f)};else if(t==="error")i=function(c){let l=new Nr("error",{error:c,message:c.message});l[Lr]=this,ko(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[Lr]=this,ko(e,this,c)};else return;i[Ui]=!!r[Ui],i[hd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[hd]===e&&!r[Ui]){this.removeListener(t,r);break}}};vh.exports={CloseEvent:jn,ErrorEvent:Nr,Event:Jt,EventTarget:aE,MessageEvent:Gi};function ko(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Oo=se(($D,Ih)=>{"use strict";var{tokenChars:Hi}=kr();function Bt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function cE(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,f,h=-1,p=-1,w=-1,E=0;for(;E<t.length;E++)if(p=t.charCodeAt(E),l===void 0)if(w===-1&&Hi[p]===1)h===-1&&(h=E);else if(E!==0&&(p===32||p===9))w===-1&&h!==-1&&(w=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);w===-1&&(w=E);let _=t.slice(h,w);p===44?(Bt(e,_,r),r=Object.create(null)):l=_,h=w=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);else if(f===void 0)if(w===-1&&Hi[p]===1)h===-1&&(h=E);else if(p===32||p===9)w===-1&&h!==-1&&(w=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);w===-1&&(w=E),Bt(r,t.slice(h,w),!0),p===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),h=w=-1}else if(p===61&&h!==-1&&w===-1)f=t.slice(h,E),h=w=-1;else throw new SyntaxError(`Unexpected character at index ${E}`);else if(o){if(Hi[p]!==1)throw new SyntaxError(`Unexpected character at index ${E}`);h===-1?h=E:i||(i=!0),o=!1}else if(c)if(Hi[p]===1)h===-1&&(h=E);else if(p===34&&h!==-1)c=!1,w=E;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${E}`);else if(p===34&&t.charCodeAt(E-1)===61)c=!0;else if(w===-1&&Hi[p]===1)h===-1&&(h=E);else if(h!==-1&&(p===32||p===9))w===-1&&(w=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);w===-1&&(w=E);let _=t.slice(h,w);i&&(_=_.replace(/\\/g,""),i=!1),Bt(r,f,_),p===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),f=void 0,h=w=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);if(h===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");w===-1&&(w=E);let T=t.slice(h,w);return l===void 0?Bt(e,T,r):(f===void 0?Bt(r,T,!0):i?Bt(r,f,T.replace(/\\/g,"")):Bt(r,f,T),Bt(e,l,r)),e}function dE(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Ih.exports={format:dE,parse:cE}});var Mo=se((ZD,Bh)=>{"use strict";var lE=de("events"),uE=de("https"),fE=de("http"),Dh=de("net"),hE=de("tls"),{randomBytes:xE,createHash:pE}=de("crypto"),{Duplex:VD,Readable:JD}=de("stream"),{URL:xd}=de("url"),vn=Cr(),gE=dd(),mE=fd(),{isBlob:wE}=kr(),{BINARY_TYPES:Ah,CLOSE_TIMEOUT:_E,EMPTY_BUFFER:Po,GUID:yE,kForOnEventAttribute:pd,kListener:bE,kStatusCode:EE,kWebSocket:Fe,NOOP:Rh}=$t(),{EventTarget:{addEventListener:vE,removeEventListener:SE}}=Sh(),{format:IE,parse:AE}=Oo(),{toBuffer:TE}=zi(),Ch=Symbol("kAborted"),gd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],DE=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends lE{constructor(e,r,i){super(),this._binaryType=Ah[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Po,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),kh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Ah.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,i){let o=new gE({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new mE(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Fe]=this,c[Fe]=this,e[Fe]=this,o.on("conclude",kE),o.on("drain",OE),o.on("error",PE),o.on("message",LE),o.on("ping",NE),o.on("pong",ME),c.onerror=BE,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Lh),e.on("data",No),e.on("end",Nh),e.on("error",Mh),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[vn.extensionName]&&this._extensions[vn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Ph(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){md(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Po,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){md(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Po,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){md(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[vn.extensionName]||(o.compress=!1),this._sender.send(e||Po,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(pe,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(pe.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(pe.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[pd])return e[bE];return null},set(e){for(let r of this.listeners(t))if(r[pd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[pd]:!0})}})});pe.prototype.addEventListener=vE;pe.prototype.removeEventListener=SE;Bh.exports=pe;function kh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:_E,protocolVersion:gd[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!gd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${gd.join(", ")})`);let c;if(e instanceof xd)c=e;else try{c=new xd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",f=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!l&&!f?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;Lo(t,I);return}let p=l?443:80,w=xE(16).toString("base64"),E=l?uE.request:fE.request,T=new Set,_;if(o.createConnection=o.createConnection||(l?CE:RE),o.defaultPort=o.defaultPort||p,o.port=c.port||p,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":w,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new vn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=IE({[vn.extensionName]:_.offer()})),r.length){for(let I of r){if(typeof I!="string"||!DE.test(I)||T.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");T.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),f){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=l,t._originalHostOrSocketPath=f?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[S,R]of Object.entries(I))i.headers[S.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=f?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=E(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=E(o);o.timeout&&v.on("timeout",()=>{st(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[Ch]||(v=t._req=null,Lo(t,I))}),v.on("response",I=>{let S=I.headers.location,R=I.statusCode;if(S&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){st(t,v,"Maximum redirects exceeded");return}v.abort();let L;try{L=new xd(S,e)}catch{let C=new SyntaxError(`Invalid URL: ${S}`);Lo(t,C);return}kh(t,L,r,i)}else t.emit("unexpected-response",v,I)||st(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,S,R)=>{if(t.emit("upgrade",I),t.readyState!==pe.CONNECTING)return;v=t._req=null;let L=I.headers.upgrade;if(L===void 0||L.toLowerCase()!=="websocket"){st(t,S,"Invalid Upgrade header");return}let y=pE("sha1").update(w+yE).digest("base64");if(I.headers["sec-websocket-accept"]!==y){st(t,S,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],O;if(C!==void 0?T.size?T.has(C)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":T.size&&(O="Server sent no subprotocol"),O){st(t,S,O);return}C&&(t._protocol=C);let B=I.headers["sec-websocket-extensions"];if(B!==void 0){if(!_){st(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let F;try{F=AE(B)}catch{st(t,S,"Invalid Sec-WebSocket-Extensions header");return}let V=Object.keys(F);if(V.length!==1||V[0]!==vn.extensionName){st(t,S,"Server indicated an extension that was not requested");return}try{_.accept(F[vn.extensionName])}catch{st(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[vn.extensionName]=_}t.setSocket(S,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Lo(t,e){t._readyState=pe.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function RE(t){return t.path=t.socketPath,Dh.connect(t)}function CE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Dh.isIP(t.host)?"":t.host),hE.connect(t)}function st(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,st),e.setHeader?(e[Ch]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Lo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function md(t,e,r){if(e){let i=wE(e)?e.size:TE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(r,i)}}function kE(t,e){let r=this[Fe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Fe]!==void 0&&(r._socket.removeListener("data",No),process.nextTick(Oh,r._socket),t===1005?r.close():r.close(t,e))}function OE(){let t=this[Fe];t.isPaused||t._socket.resume()}function PE(t){let e=this[Fe];e._socket[Fe]!==void 0&&(e._socket.removeListener("data",No),process.nextTick(Oh,e._socket),e.close(t[EE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Th(){this[Fe].emitClose()}function LE(t,e){this[Fe].emit("message",t,e)}function NE(t){let e=this[Fe];e._autoPong&&e.pong(t,!this._isServer,Rh),e.emit("ping",t)}function ME(t){this[Fe].emit("pong",t)}function Oh(t){t.resume()}function BE(t){let e=this[Fe];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,Ph(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Ph(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Lh(){let t=this[Fe];if(this.removeListener("close",Lh),this.removeListener("data",No),this.removeListener("end",Nh),t._readyState=pe.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Fe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Th),t._receiver.on("finish",Th))}function No(t){this[Fe]._receiver.write(t)||this.pause()}function Nh(){let t=this[Fe];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function Mh(){let t=this[Fe];this.removeListener("error",Mh),this.on("error",Rh),t&&(t._readyState=pe.CLOSING,this.destroy())}});var Gh=se((XD,Uh)=>{"use strict";var YD=Mo(),{Duplex:zE}=de("stream");function zh(t){t.emit("close")}function FE(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Fh(t){this.removeListener("error",Fh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function UE(t,e){let r=!0,i=new zE({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let f=!l&&i._readableState.objectMode?c.toString():c;i.push(f)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(zh,i);return}let l=!1;t.once("error",function(h){l=!0,c(h)}),t.once("close",function(){l||c(o),process.nextTick(zh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",FE),i.on("error",Fh),i}Uh.exports=UE});var wd=se((QD,Hh)=>{"use strict";var{tokenChars:GE}=kr();function HE(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&GE[l]===1)r===-1&&(r=o);else if(o!==0&&(l===32||l===9))i===-1&&r!==-1&&(i=o);else if(l===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Hh.exports={parse:HE}});var Jh=se((tR,Vh)=>{"use strict";var qE=de("events"),Bo=de("http"),{Duplex:eR}=de("stream"),{createHash:jE}=de("crypto"),qh=Oo(),Wn=Cr(),WE=wd(),KE=Mo(),{CLOSE_TIMEOUT:$E,GUID:VE,kWebSocket:JE}=$t(),ZE=/^[+/0-9A-Za-z]{22}==$/,jh=0,Wh=1,$h=2,_d=class extends qE{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:$E,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:KE,...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=Bo.createServer((i,o)=>{let c=Bo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=YE(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,l)=>{this.handleUpgrade(o,c,l,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=jh}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===$h){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(qi,this);return}if(e&&this.once("close",e),this._state!==Wh)if(this._state=Wh,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(qi,this):process.nextTick(qi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{qi(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",Kh);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Kn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Kn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!ZE.test(c)){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ji(r,400);return}let h=e.headers["sec-websocket-protocol"],p=new Set;if(h!==void 0)try{p=WE.parse(h)}catch{Kn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let w=e.headers["sec-websocket-extensions"],E={};if(this.options.perMessageDeflate&&w!==void 0){let T=new Wn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=qh.parse(w);_[Wn.extensionName]&&(T.accept(_[Wn.extensionName]),E[Wn.extensionName]=T)}catch{Kn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let T={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(T,(_,v,I,S)=>{if(!_)return ji(r,v||401,I,S);this.completeUpgrade(E,c,p,e,r,i,o)});return}if(!this.options.verifyClient(T))return ji(r,401)}this.completeUpgrade(E,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,f){if(!c.readable||!c.writable)return c.destroy();if(c[JE])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>jh)return ji(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${jE("sha1").update(r+VE).digest("base64")}`],w=new this.options.WebSocket(null,void 0,this.options);if(i.size){let E=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;E&&(p.push(`Sec-WebSocket-Protocol: ${E}`),w._protocol=E)}if(e[Wn.extensionName]){let E=e[Wn.extensionName].params,T=qh.format({[Wn.extensionName]:[E]});p.push(`Sec-WebSocket-Extensions: ${T}`),w._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",Hh),m.setSocket(c,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Gi,this)})),f(m,o)}};Wh.exports=md;function Zb(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function Gi(t){t._state=qh,t.emit("close")}function Hh(){this.destroy()}function ji(t,e,r,i){r=r||No.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${No.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",Kh),w.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(w),w.on("close",()=>{this.clients.delete(w),this._shouldEmitClose&&!this.clients.size&&process.nextTick(qi,this)})),f(w,o)}};Vh.exports=_d;function YE(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function qi(t){t._state=$h,t.emit("close")}function Kh(){this.destroy()}function ji(t,e,r,i){r=r||Bo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Bo.STATUS_CODES[e]}\r
17
17
  `+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
18
18
  `)+`\r
19
19
  \r
20
- `+r)}function qn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,qn),t.emit("wsClientError",d,r,e)}else ji(r,i,o,c)}});import{existsSync as w1,openSync as y1}from"node:fs";import{mkdir as _1}from"node:fs/promises";import{dirname as E1}from"node:path";import{fileURLToPath as b1}from"node:url";function S1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ed(t=Y()){return w1(t.libEntry)?t.libEntry:b1(new URL("../index.ts",import.meta.url))}async function ox(t={}){let e=t.paths??Y(),r=t.entryOverride??Ed(e),i=S1(e,process.env.COZE_BRIDGE_LOG_MODE);await _1(E1(i),{recursive:!0});let o=y1(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],f=at(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Wi]:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return v1.info("daemon spawned",{pid:f.pid,entry:r}),{pid:f.pid,entry:r}}var v1,Wi,Go=Ke(()=>{"use strict";wn();ne();ke();v1=G("spawn-daemon"),Wi="COZE_BRIDGE_DAEMON"});import{spawn as uv}from"node:child_process";import{mkdir as hv,unlink as xv,writeFile as pv}from"node:fs/promises";import{dirname as gv,join as mv}from"node:path";function Br(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function wv(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Br(r)}</key>
21
- <string>${Br(i)}</string>`).join(`
20
+ `+r)}function Kn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Kn),t.emit("wsClientError",l,r,e)}else ji(r,i,o,c)}});import{existsSync as bv,openSync as Ev}from"node:fs";import{mkdir as vv}from"node:fs/promises";import{dirname as Sv}from"node:path";import{fileURLToPath as Iv}from"node:url";function Tv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function vd(t=X()){return bv(t.libEntry)?t.libEntry:Iv(new URL("../index.ts",import.meta.url))}async function dx(t={}){let e=t.paths??X(),r=t.entryOverride??vd(e),i=Tv(e,process.env.COZE_BRIDGE_LOG_MODE);await vv(Sv(i),{recursive:!0});let o=Ev(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],f=lt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[$i]:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Av.info("daemon spawned",{pid:f.pid,entry:r}),{pid:f.pid,entry:r}}var Av,$i,qo=Je(()=>{"use strict";yn();ne();Ce();Av=G("spawn-daemon"),$i="COZE_BRIDGE_DAEMON"});import{spawn as p1}from"node:child_process";import{mkdir as g1,unlink as m1,writeFile as w1}from"node:fs/promises";import{dirname as _1,join as y1}from"node:path";function Fr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function b1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Fr(r)}</key>
21
+ <string>${Fr(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function yv(t,e){return new Promise((r,i)=>{let o=uv(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Mr,Ki,Zo,Rd,Sx=Ke(()=>{"use strict";ne();Mr=G("supervisor.launchd"),Ki="ai.coze.bridge",Zo=yv,Rd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function E1(t,e){return new Promise((r,i)=>{let o=p1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var zr,Ji,Zo,Cd,Tx=Je(()=>{"use strict";ne();zr=G("supervisor.launchd"),Ji="ai.coze.bridge",Zo=E1,Cd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
27
27
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
28
28
  <plist version="1.0">
29
29
  <dict>
30
30
  <key>Label</key>
31
- <string>${Ki}</string>
31
+ <string>${Ji}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Br(t.nodeBin)}</string>
35
- <string>${Br(t.entry)}</string>
34
+ <string>${Fr(t.nodeBin)}</string>
35
+ <string>${Fr(t.entry)}</string>
36
36
  <string>--daemon</string>
37
37
  </array>
38
38
  <key>RunAtLoad</key>
@@ -42,13 +42,13 @@ ${e}
42
42
  <key>ThrottleInterval</key>
43
43
  <integer>10</integer>
44
44
  <key>StandardOutPath</key>
45
- <string>${Br(t.logFile)}</string>
45
+ <string>${Fr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Br(t.logFile)}</string>${wv(t.env)}
47
+ <string>${Fr(t.logFile)}</string>${b1(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return mv(t.homeDir,"Library","LaunchAgents",`${Ki}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await hv(gv(i),{recursive:!0}),await pv(i,this.renderConfig(t),"utf8"),Mr.info("plist written",{plistPath:i,activate:r}),!r)return;await Zo("launchctl",["unload","-w",i]).catch(c=>Mr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Zo("launchctl",["load","-w",i]),Mr.info("launchd job loaded",{label:Ki});let o=process.getuid?.()??0;await Zo("launchctl",["kickstart","-k",`gui/${o}/${Ki}`]),Mr.info("launchd job kickstarted",{label:Ki,uid:o})},async uninstall(t){let e=this.configPath(t);await Zo("launchctl",["unload","-w",e]).catch(r=>Mr.warn("launchctl unload failed (ignored)",{err:String(r)})),await xv(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Mr.info("launchd job removed",{plistPath:e})}}});import{spawn as _v}from"node:child_process";import{mkdir as Ev,unlink as bv,writeFile as vv}from"node:fs/promises";import{dirname as Sv,join as Ix}from"node:path";function Jo(t,e){return t.isRoot?e:["--user",...e]}function Av(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function Yo(t,e){return new Promise((r,i)=>{let o=_v(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Vo,zr,Iv,Cd,Ax=Ke(()=>{"use strict";ne();Vo=G("supervisor.systemd"),zr="coze-bridge.service",Iv="/etc/systemd/system";Cd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return y1(t.homeDir,"Library","LaunchAgents",`${Ji}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await g1(_1(i),{recursive:!0}),await w1(i,this.renderConfig(t),"utf8"),zr.info("plist written",{plistPath:i,activate:r}),!r)return;await Zo("launchctl",["unload","-w",i]).catch(c=>zr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Zo("launchctl",["load","-w",i]),zr.info("launchd job loaded",{label:Ji});let o=process.getuid?.()??0;await Zo("launchctl",["kickstart","-k",`gui/${o}/${Ji}`]),zr.info("launchd job kickstarted",{label:Ji,uid:o})},async uninstall(t){let e=this.configPath(t);await Zo("launchctl",["unload","-w",e]).catch(r=>zr.warn("launchctl unload failed (ignored)",{err:String(r)})),await m1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),zr.info("launchd job removed",{plistPath:e})}}});import{spawn as v1}from"node:child_process";import{mkdir as S1,unlink as I1,writeFile as A1}from"node:fs/promises";import{dirname as T1,join as Dx}from"node:path";function Xo(t,e){return t.isRoot?e:["--user",...e]}function R1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function Qo(t,e){return new Promise((r,i)=>{let o=v1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Yo,Ur,D1,kd,Rx=Je(()=>{"use strict";ne();Yo=G("supervisor.systemd"),Ur="coze-bridge.service",D1="/etc/systemd/system";kd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
52
52
  Description=Coze Bridge daemon
53
53
  After=network.target
54
54
 
@@ -59,10 +59,10 @@ Restart=always
59
59
  RestartSec=3
60
60
  StandardOutput=append:${t.logFile}
61
61
  StandardError=append:${t.logFile}
62
- ${Av(t.env)}
62
+ ${R1(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?Ix(Iv,zr):Ix(t.homeDir,".config","systemd","user",zr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await Ev(Sv(i),{recursive:!0}),await vv(i,this.renderConfig(t),"utf8"),Vo.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await Yo("systemctl",Jo(t,["daemon-reload"])),await Yo("systemctl",Jo(t,r?["enable","--now",zr]:["enable",zr])),Vo.info("systemd unit enabled",{unitName:zr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await Yo("systemctl",Jo(t,["disable","--now",zr])).catch(r=>Vo.warn("systemctl disable failed (ignored)",{err:String(r)})),await bv(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await Yo("systemctl",Jo(t,["daemon-reload"])).catch(()=>{}),Vo.info("systemd unit removed",{unitPath:e})}}});import{spawn as Tv}from"node:child_process";import{join as Rv}from"node:path";function Tx(t,e){return new Promise((r,i)=>{let o=Tv(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Dd,Xo,kd,Rx=Ke(()=>{"use strict";ne();Dd=G("supervisor.taskscheduler"),Xo="CozeBridge",kd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?Dx(D1,Ur):Dx(t.homeDir,".config","systemd","user",Ur)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await S1(T1(i),{recursive:!0}),await A1(i,this.renderConfig(t),"utf8"),Yo.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await Qo("systemctl",Xo(t,["daemon-reload"])),await Qo("systemctl",Xo(t,r?["enable","--now",Ur]:["enable",Ur])),Yo.info("systemd unit enabled",{unitName:Ur,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await Qo("systemctl",Xo(t,["disable","--now",Ur])).catch(r=>Yo.warn("systemctl disable failed (ignored)",{err:String(r)})),await I1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await Qo("systemctl",Xo(t,["daemon-reload"])).catch(()=>{}),Yo.info("systemd unit removed",{unitPath:e})}}});import{spawn as C1}from"node:child_process";import{join as k1}from"node:path";function Cx(t,e){return new Promise((r,i)=>{let o=C1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Od,ea,Pd,kx=Je(()=>{"use strict";ne();Od=G("supervisor.taskscheduler"),ea="CozeBridge",Pd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
66
66
  <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
67
67
  <RegistrationInfo>
68
68
  <Description>Coze Bridge daemon</Description>
@@ -86,43 +86,43 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return Rv(t.homeDir,".coze","bridge","task.xml")},async install(t){let r=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await Tx("schtasks",["/Create","/SC","ONLOGON","/TN",Xo,"/TR",r,"/RU",t.userName,"/F"]),Dd.info("task scheduler entry created",{task:Xo,logFile:t.logFile})},async uninstall(t){await Tx("schtasks",["/Delete","/TN",Xo,"/F"]).catch(e=>Dd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Dd.info("task scheduler entry removed",{task:Xo})}}});var Cx={};ua(Cx,{buildContext:()=>Lv,getSupervisor:()=>kv,launchdSupervisor:()=>Rd,systemdSupervisor:()=>Cd,taskSchedulerSupervisor:()=>kd});import{homedir as Cv,userInfo as Dv}from"node:os";function kv(t=process.platform){switch(t){case"darwin":return Rd;case"linux":return Cd;case"win32":return kd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function Pv(){let t={};for(let e of Ov){let r=process.env[e];r&&(t[e]=r)}return t}function Lv(){let t=Y();return{nodeBin:process.execPath,entry:Ed(t),logFile:t.logFile,homeDir:Cv(),userName:Dv().username,isRoot:process.getuid?.()===0,env:Pv()}}var Ov,Dx=Ke(()=>{"use strict";ke();Go();Sx();Ax();Rx();Ov=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();en();var dl=G("acp-installer-warmup"),ng=["claude-code","codex"];async function ll(t={}){let e=t.ensure??Xn,i=(await Promise.allSettled(ng.map(async o=>{let c=await e(o);dl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&dl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}tn();ne();import{readdir as xg}from"node:fs/promises";import{mkdir as gl,writeFile as ml}from"node:fs/promises";import{join as ya}from"node:path";var hg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function tr(t,e,r){await gl(t,{recursive:!0});let i=hg[e],o=ya(t,i);return await ml(o,r??"","utf8"),o}async function wl(t){let e=ya(t,".claude");await gl(e,{recursive:!0});let r=ya(e,"settings.local.json"),i=JSON.stringify({permissions:{defaultMode:"bypassPermissions"},env:{CLAUDE_AUTOCOMPACT_PCT_OVERRIDE:"10"}},null,2);return await ml(r,i,"utf8"),r}var Ye=G("agent-detail-sync"),pg=6e4,gg=5*6e4,ss=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await xg(r)}catch(o){Ye.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ye.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Ge(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ye.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Ye.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Ye.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){Ye.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ye.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Ge(e,this.opts.paths);if(!i){Ye.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){Ye.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let h=this.retryQueue.get(e),x=h?Math.min(h.currentDelay*2,gg):pg;this.retryQueue.set(e,{dueAt:Date.now()+x,currentDelay:x});return}if(o.agentId&&o.agentId!==e){Ye.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;if(o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0),o.deployType&&Ye.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ye.debug("detail sync: no diff",{agentId:e});return}await Ve(i,this.opts.paths),Ye.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),d&&(await tr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Nu=bt(Yl(),1);import{lstat as Lc,mkdir as Nc,readFile as ku,readdir as Hw,rm as qw,stat as Ww,writeFile as Mc}from"node:fs/promises";import{dirname as $w,join as Ct,normalize as Kw,relative as Fc,resolve as Bc,sep as Ou}from"node:path";import{Readable as Pu}from"node:stream";import{pipeline as Lu}from"node:stream/promises";import zg from"events";import Je from"fs";import{EventEmitter as wc}from"node:events";import Pf from"node:stream";import{StringDecoder as Fg}from"node:string_decoder";import Mf from"node:path";import hr from"node:fs";import{dirname as Xg,parse as Qg}from"path";import{EventEmitter as am}from"events";import Qa from"assert";import{Buffer as Nn}from"buffer";import*as nf from"zlib";import cm from"zlib";import{posix as or}from"node:path";import{basename as Nm}from"node:path";import Bs from"fs";import At from"fs";import lf from"path";import{win32 as $m}from"node:path";import mf from"path";import Yf from"node:fs";import dw from"node:assert";import{randomBytes as Xf}from"node:crypto";import re from"node:fs";import Pe from"node:path";import Qf from"fs";import $s from"node:fs";import xi from"node:path";import et from"node:fs";import gw from"node:fs/promises";import Us from"node:path";import{join as lu}from"node:path";import Qe from"node:fs";import hu from"node:path";var Mg=Object.defineProperty,Bg=(t,e)=>{for(var r in e)Mg(t,r,{get:e[r],enumerable:!0})},Xl=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ug=t=>!!t&&typeof t=="object"&&(t instanceof zn||t instanceof Pf||Gg(t)||jg(t)),Gg=t=>!!t&&typeof t=="object"&&t instanceof wc&&typeof t.pipe=="function"&&t.pipe!==Pf.Writable.prototype.pipe,jg=t=>!!t&&typeof t=="object"&&t instanceof wc&&typeof t.write=="function"&&typeof t.end=="function",Bt=Symbol("EOF"),zt=Symbol("maybeEmitEnd"),rn=Symbol("emittedEnd"),ls=Symbol("emittingEnd"),Yr=Symbol("emittedError"),fs=Symbol("closed"),Ql=Symbol("read"),us=Symbol("flush"),ef=Symbol("flushChunk"),ut=Symbol("encoding"),sr=Symbol("decoder"),Ne=Symbol("flowing"),Xr=Symbol("paused"),lr=Symbol("resume"),Me=Symbol("buffer"),We=Symbol("pipes"),Be=Symbol("bufferLength"),Ia=Symbol("bufferPush"),hs=Symbol("bufferShift"),He=Symbol("objectMode"),ve=Symbol("destroyed"),Aa=Symbol("error"),Ta=Symbol("emitData"),tf=Symbol("emitEnd"),Ra=Symbol("emitEnd2"),vt=Symbol("async"),Ca=Symbol("abort"),xs=Symbol("aborted"),Qr=Symbol("signal"),An=Symbol("dataListeners"),Xe=Symbol("discarded"),ei=t=>Promise.resolve().then(t),Hg=t=>t(),qg=t=>t==="end"||t==="finish"||t==="prefinish",Wg=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,$g=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Lf=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[lr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Kg=class extends Lf{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Zg=t=>!!t.objectMode,Vg=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",zn=class extends wc{[Ne]=!1;[Xr]=!1;[We]=[];[Me]=[];[He];[ut];[vt];[sr];[Bt]=!1;[rn]=!1;[ls]=!1;[fs]=!1;[Yr]=null;[Be]=0;[ve]=!1;[Qr];[xs]=!1;[An]=0;[Xe]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Zg(e)?(this[He]=!0,this[ut]=null):Vg(e)?(this[ut]=e.encoding,this[He]=!1):(this[He]=!1,this[ut]=null),this[vt]=!!e.async,this[sr]=this[ut]?new Fg(this[ut]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[We]});let{signal:r}=e;r&&(this[Qr]=r,r.aborted?this[Ca]():r.addEventListener("abort",()=>this[Ca]()))}get bufferLength(){return this[Be]}get encoding(){return this[ut]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[He]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[vt]}set async(t){this[vt]=this[vt]||!!t}[Ca](){this[xs]=!0,this.emit("abort",this[Qr]?.reason),this.destroy(this[Qr]?.reason)}get aborted(){return this[xs]}set aborted(t){}write(t,e,r){if(this[xs])return!1;if(this[Bt])throw new Error("write after end");if(this[ve])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[vt]?ei:Hg;if(!this[He]&&!Buffer.isBuffer(t)){if($g(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Wg(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[He]?(this[Ne]&&this[Be]!==0&&this[us](!0),this[Ne]?this.emit("data",t):this[Ia](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):t.length?(typeof t=="string"&&!(e===this[ut]&&!this[sr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ut]&&(t=this[sr].write(t)),this[Ne]&&this[Be]!==0&&this[us](!0),this[Ne]?this.emit("data",t):this[Ia](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne])}read(t){if(this[ve])return null;if(this[Xe]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[zt](),null;this[He]&&(t=null),this[Me].length>1&&!this[He]&&(this[Me]=[this[ut]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[Ql](t||null,this[Me][0]);return this[zt](),e}[Ql](t,e){if(this[He])this[hs]();else{let r=e;t===r.length||t===null?this[hs]():typeof r=="string"?(this[Me][0]=r.slice(t),e=r.slice(0,t),this[Be]-=t):(this[Me][0]=r.subarray(t),e=r.subarray(0,t),this[Be]-=t)}return this.emit("data",e),!this[Me].length&&!this[Bt]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Bt]=!0,this.writable=!1,(this[Ne]||!this[Xr])&&this[zt](),this}[lr](){this[ve]||(!this[An]&&!this[We].length&&(this[Xe]=!0),this[Xr]=!1,this[Ne]=!0,this.emit("resume"),this[Me].length?this[us]():this[Bt]?this[zt]():this.emit("drain"))}resume(){return this[lr]()}pause(){this[Ne]=!1,this[Xr]=!0,this[Xe]=!1}get destroyed(){return this[ve]}get flowing(){return this[Ne]}get paused(){return this[Xr]}[Ia](t){this[He]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[hs](){return this[He]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[us](t=!1){do;while(this[ef](this[hs]())&&this[Me].length);!t&&!this[Me].length&&!this[Bt]&&this.emit("drain")}[ef](t){return this.emit("data",t),this[Ne]}pipe(t,e){if(this[ve])return t;this[Xe]=!1;let r=this[rn];return e=e||{},t===Xl.stdout||t===Xl.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[We].push(e.proxyErrors?new Kg(this,t,e):new Lf(this,t,e)),this[vt]?ei(()=>this[lr]()):this[lr]()),t}unpipe(t){let e=this[We].find(r=>r.dest===t);e&&(this[We].length===1?(this[Ne]&&this[An]===0&&(this[Ne]=!1),this[We]=[]):this[We].splice(this[We].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[Xe]=!1,this[An]++,!this[We].length&&!this[Ne]&&this[lr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(qg(t)&&this[rn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Yr]){let i=e;this[vt]?ei(()=>i.call(this,this[Yr])):i.call(this,this[Yr])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[An]=this.listeners("data").length,this[An]===0&&!this[Xe]&&!this[We].length&&(this[Ne]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[An]=0,!this[Xe]&&!this[We].length&&(this[Ne]=!1)),e}get emittedEnd(){return this[rn]}[zt](){!this[ls]&&!this[rn]&&!this[ve]&&this[Me].length===0&&this[Bt]&&(this[ls]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[fs]&&this.emit("close"),this[ls]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ve&&this[ve])return!1;if(t==="data")return!this[He]&&!r?!1:this[vt]?(ei(()=>this[Ta](r)),!0):this[Ta](r);if(t==="end")return this[tf]();if(t==="close"){if(this[fs]=!0,!this[rn]&&!this[ve])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Yr]=r,super.emit(Aa,r);let o=!this[Qr]||this.listeners("error").length?super.emit("error",r):!1;return this[zt](),o}else if(t==="resume"){let o=super.emit("resume");return this[zt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[zt](),i}[Ta](t){for(let r of this[We])r.dest.write(t)===!1&&this.pause();let e=this[Xe]?!1:super.emit("data",t);return this[zt](),e}[tf](){return this[rn]?!1:(this[rn]=!0,this.readable=!1,this[vt]?(ei(()=>this[Ra]()),!0):this[Ra]())}[Ra](){if(this[sr]){let e=this[sr].end();if(e){for(let r of this[We])r.dest.write(e);this[Xe]||super.emit("data",e)}}for(let e of this[We])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[He]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[He]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[He])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ut]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(ve,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[Xe]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Bt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",f),this.off(ve,h),e(),o(x)},d=x=>{this.off("error",c),this.off("end",f),this.off(ve,h),this.pause(),i({value:x,done:!!this[Bt]})},f=()=>{this.off("error",c),this.off("data",d),this.off(ve,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(ve,h),this.once("error",c),this.once("end",f),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Xe]=!1;let t=!1,e=()=>(this.pause(),this.off(Aa,e),this.off(ve,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Aa,e),this.once(ve,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[ve])return t?this.emit("error",t):this.emit(ve),this;this[ve]=!0,this[Xe]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[fs]&&e.close(),t?this.emit("error",t):this.emit(ve),this}static get isStream(){return Ug}},Jg=Je.writev,xn=Symbol("_autoClose"),gt=Symbol("_close"),ti=Symbol("_ended"),ae=Symbol("_fd"),Da=Symbol("_finished"),jt=Symbol("_flags"),ka=Symbol("_flush"),Ya=Symbol("_handleChunk"),Xa=Symbol("_makeBuf"),ui=Symbol("_mode"),ps=Symbol("_needDrain"),pr=Symbol("_onerror"),gr=Symbol("_onopen"),Oa=Symbol("_onread"),fr=Symbol("_onwrite"),pn=Symbol("_open"),pt=Symbol("_path"),dn=Symbol("_pos"),St=Symbol("_queue"),ur=Symbol("_read"),Pa=Symbol("_readSize"),Gt=Symbol("_reading"),ni=Symbol("_remain"),La=Symbol("_size"),Is=Symbol("_write"),Tn=Symbol("_writing"),As=Symbol("_defaultFlag"),Ln=Symbol("_errored"),yc=class extends zn{[Ln]=!1;[ae];[pt];[Pa];[Gt]=!1;[La];[ni];[xn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Ln]=!1,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[pt]=t,this[Pa]=e.readSize||16*1024*1024,this[Gt]=!1,this[La]=typeof e.size=="number"?e.size:1/0,this[ni]=this[La],this[xn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[ur]():this[pn]()}get fd(){return this[ae]}get path(){return this[pt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pn](){Je.open(this[pt],"r",(t,e)=>this[gr](t,e))}[gr](t,e){t?this[pr](t):(this[ae]=e,this.emit("open",e),this[ur]())}[Xa](){return Buffer.allocUnsafe(Math.min(this[Pa],this[ni]))}[ur](){if(!this[Gt]){this[Gt]=!0;let t=this[Xa]();if(t.length===0)return process.nextTick(()=>this[Oa](null,0,t));Je.read(this[ae],t,0,t.length,null,(e,r,i)=>this[Oa](e,r,i))}}[Oa](t,e,r){this[Gt]=!1,t?this[pr](t):this[Ya](e,r)&&this[ur]()}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[pr](t){this[Gt]=!0,this[gt](),this.emit("error",t)}[Ya](t,e){let r=!1;return this[ni]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ni]<=0)&&(r=!1,this[gt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ae]=="number"&&this[ur](),!1;case"error":return this[Ln]?!1:(this[Ln]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Yg=class extends yc{[pn](){let t=!0;try{this[gr](null,Je.openSync(this[pt],"r")),t=!1}finally{t&&this[gt]()}}[ur](){let t=!0;try{if(!this[Gt]){this[Gt]=!0;do{let e=this[Xa](),r=e.length===0?0:Je.readSync(this[ae],e,0,e.length,null);if(!this[Ya](r,e))break}while(!0);this[Gt]=!1}t=!1}finally{t&&this[gt]()}}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.closeSync(t),this.emit("close")}}},Gs=class extends zg{readable=!1;writable=!0;[Ln]=!1;[Tn]=!1;[ti]=!1;[St]=[];[ps]=!1;[pt];[ui];[xn];[ae];[As];[jt];[Da]=!1;[dn];constructor(t,e){e=e||{},super(e),this[pt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[ui]=e.mode===void 0?438:e.mode,this[dn]=typeof e.start=="number"?e.start:void 0,this[xn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[dn]!==void 0?"r+":"w";this[As]=e.flags===void 0,this[jt]=e.flags===void 0?r:e.flags,this[ae]===void 0&&this[pn]()}emit(t,...e){if(t==="error"){if(this[Ln])return!1;this[Ln]=!0}return super.emit(t,...e)}get fd(){return this[ae]}get path(){return this[pt]}[pr](t){this[gt](),this[Tn]=!0,this.emit("error",t)}[pn](){Je.open(this[pt],this[jt],this[ui],(t,e)=>this[gr](t,e))}[gr](t,e){this[As]&&this[jt]==="r+"&&t&&t.code==="ENOENT"?(this[jt]="w",this[pn]()):t?this[pr](t):(this[ae]=e,this.emit("open",e),this[Tn]||this[ka]())}end(t,e){return t&&this.write(t,e),this[ti]=!0,!this[Tn]&&!this[St].length&&typeof this[ae]=="number"&&this[fr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ti]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Tn]||this[St].length?(this[St].push(t),this[ps]=!0,!1):(this[Tn]=!0,this[Is](t),!0)}[Is](t){Je.write(this[ae],t,0,t.length,this[dn],(e,r)=>this[fr](e,r))}[fr](t,e){t?this[pr](t):(this[dn]!==void 0&&typeof e=="number"&&(this[dn]+=e),this[St].length?this[ka]():(this[Tn]=!1,this[ti]&&!this[Da]?(this[Da]=!0,this[gt](),this.emit("finish")):this[ps]&&(this[ps]=!1,this.emit("drain"))))}[ka](){if(this[St].length===0)this[ti]&&this[fr](null,0);else if(this[St].length===1)this[Is](this[St].pop());else{let t=this[St];this[St]=[],Jg(this[ae],t,this[dn],(e,r)=>this[fr](e,r))}}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Nf=class extends Gs{[pn](){let t;if(this[As]&&this[jt]==="r+")try{t=Je.openSync(this[pt],this[jt],this[ui])}catch(e){if(e?.code==="ENOENT")return this[jt]="w",this[pn]();throw e}else t=Je.openSync(this[pt],this[jt],this[ui]);this[gr](null,t)}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.closeSync(t),this.emit("close")}}[Is](t){let e=!0;try{this[fr](null,Je.writeSync(this[ae],t,0,t.length,this[dn])),e=!1}finally{if(e)try{this[gt]()}catch{}}}},em=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),tm=t=>!!t.sync&&!!t.file,nm=t=>!t.sync&&!!t.file,rm=t=>!!t.sync&&!t.file,im=t=>!t.sync&&!t.file,sm=t=>!!t.file,om=t=>em.get(t)||t,_c=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ei=(t,e,r,i,o)=>Object.assign((c=[],d,f)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(f=d,d=void 0),d=d?Array.from(d):[];let h=_c(c);if(o?.(h,d),tm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,d)}else if(nm(h)){let x=e(h,d);return f?x.then(()=>f(),f):x}else if(rm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,d)}else if(im(h)){if(typeof f=="function")throw new TypeError("callback only supported with file option");return i(h,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),dm=cm.constants||{ZLIB_VERNUM:4736},Rt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},dm)),lm=Nn.concat,rf=Object.getOwnPropertyDescriptor(Nn,"concat"),fm=t=>t,Na=rf?.writable===!0||rf?.set!==void 0?t=>{Nn.concat=t?fm:lm}:t=>{},Mn=Symbol("_superWrite"),gs=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Ma=Symbol("flushFlag"),Ec=class extends zn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof nf[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new nf[e](t)}catch(r){throw new gs(r,this.constructor)}this.#o=r=>{this.#e||(this.#e=!0,this.close(),this.emit("error",r))},this.#t?.on("error",r=>this.#o(new gs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return Qa(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Nn.alloc(0),{[Ma]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Mn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Nn.from(t,e)),this.#e)return;Qa(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Na(!0);let d;try{let h=typeof t[Ma]=="number"?t[Ma]:this.#r;d=this.#t._processChunk(t,h),Na(!1)}catch(h){Na(!1),this.#o(new gs(h,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new gs(h,this.write)));let f;if(d)if(Array.isArray(d)&&d.length>0){let h=d[0];f=this[Mn](Nn.from(h));for(let x=1;x<d.length;x++)f=this[Mn](d[x])}else f=this[Mn](Nn.from(d));return r&&r(),f}},Bf=class extends Ec{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Rt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Rt.Z_FINISH,t.fullFlushFlag=Rt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Rt.Z_SYNC_FLUSH),Qa(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},um=class extends Bf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Mn](t){return this.#e?(this.#e=!1,t[9]=255,super[Mn](t)):super[Mn](t)}},hm=class extends Bf{constructor(t){super(t,"Unzip")}},zf=class extends Ec{constructor(t,e){t=t||{},t.flush=t.flush||Rt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Rt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Rt.BROTLI_OPERATION_FLUSH,super(t,e)}},xm=class extends zf{constructor(t){super(t,"BrotliCompress")}},pm=class extends zf{constructor(t){super(t,"BrotliDecompress")}},Ff=class extends Ec{constructor(t,e){t=t||{},t.flush=t.flush||Rt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Rt.ZSTD_e_end,t.fullFlushFlag=Rt.ZSTD_e_flush,super(t,e)}},gm=class extends Ff{constructor(t){super(t,"ZstdCompress")}},mm=class extends Ff{constructor(t){super(t,"ZstdDecompress")}},wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?_m(t,e):ym(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},ym=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},_m=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Uf(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Gf(o))}},Em=t=>{let e=t[0],r=e===128?vm(t.subarray(1,t.length)):e===255?bm(t):null;if(r===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(r))throw Error("parsed number outside of javascript safe integer range");return r},bm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=Uf(c):c===0?d=c:(i=!0,d=Gf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},vm=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},Uf=t=>(255^t)&255,Gf=t=>(255^t)+1&255,Sm={};Bg(Sm,{code:()=>bc,isCode:()=>Ts,isName:()=>Im,name:()=>js});var Ts=t=>js.has(t),Im=t=>bc.has(t),js=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),bc=new Map(Array.from(js).map(t=>[t[1],t[0]])),Bn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");this.path=r?.path??Rn(t,e,100),this.mode=r?.mode??i?.mode??ln(t,e+100,8),this.uid=r?.uid??i?.uid??ln(t,e+108,8),this.gid=r?.gid??i?.gid??ln(t,e+116,8),this.size=r?.size??i?.size??ln(t,e+124,12),this.mtime=r?.mtime??i?.mtime??Ba(t,e+136,12),this.cksum=ln(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Rn(t,e+156,1);if(Ts(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Rn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Rn(t,e+265,32),this.gname=r?.gname??i?.gname??Rn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??ln(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??ln(t,e+337,8)??0,t[e+475]!==0){let d=Rn(t,e+345,155);this.path=d+"/"+this.path}else{let d=Rn(t,e+345,130);d&&(this.path=d+"/"+this.path),this.atime=r?.atime??i?.atime??Ba(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ba(t,e+488,12)}let c=256;for(let d=e;d<e+148;d++)c+=t[d];for(let d=e+156;d<e+512;d++)c+=t[d];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=Am(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Cn(t,e,100,o)||this.needPax,this.needPax=fn(t,e+100,8,this.mode)||this.needPax,this.needPax=fn(t,e+108,8,this.uid)||this.needPax,this.needPax=fn(t,e+116,8,this.gid)||this.needPax,this.needPax=fn(t,e+124,12,this.size)||this.needPax,this.needPax=za(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Cn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Cn(t,e+265,32,this.uname)||this.needPax,this.needPax=Cn(t,e+297,32,this.gname)||this.needPax,this.needPax=fn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=fn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Cn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Cn(t,e+345,155,c)||this.needPax:(this.needPax=Cn(t,e+345,130,c)||this.needPax,this.needPax=za(t,e+476,12,this.atime)||this.needPax,this.needPax=za(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let f=e;f<e+148;f++)d+=t[f];for(let f=e+156;f<e+512;f++)d+=t[f];return this.cksum=d,fn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:js.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(bc.get(t));if(Ts(e)||e==="Unsupported")this.#e=e;else if(Ts(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Am=(t,e)=>{let r=t,i="",o,c=or.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=or.dirname(r),r=or.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=or.join(or.basename(i),r),i=or.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Rn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ba=(t,e,r)=>Tm(ln(t,e,r)),Tm=t=>t===void 0?void 0:new Date(t*1e3),ln=(t,e,r)=>Number(t[e])&128?Em(t.subarray(e,e+r)):Cm(t,e,r),Rm=t=>isNaN(t)?void 0:t,Cm=(t,e,r)=>Rm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Dm={12:8589934591,8:2097151},fn=(t,e,r,i)=>i===void 0?!1:i>Dm[r]||i<0?(wm(i,t.subarray(e,e+r)),!0):(km(t,e,r,i),!1),km=(t,e,r,i)=>t.write(Om(i,r),e,r,"ascii"),Om=(t,e)=>Pm(Math.floor(t).toString(8),e),Pm=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",za=(t,e,r,i)=>i===void 0?!1:fn(t,e,r,i.getTime()/1e3),Lm=new Array(156).join("\0"),Cn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Lm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Ms=class jf{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Bn({path:("PaxHeader/"+Nm(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
- `,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,r,i=!1){return new jf(Mm(Bm(e),r),i)}},Mm=(t,e)=>e?Object.assign({},e,t):t,Bm=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(zm,Object.create(null)),zm=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Fm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,J=Fm!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Hf=class extends zn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=J(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?J(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=J(t.path)),t.linkpath&&(t.linkpath=J(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Hs=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},Um=1024*1024,ec=Buffer.from([31,139]),tc=Buffer.from([40,181,47,253]),Gm=Math.max(ec.length,tc.length),st=Symbol("state"),Dn=Symbol("writeEntry"),Ft=Symbol("readEntry"),Fa=Symbol("nextEntry"),sf=Symbol("processEntry"),It=Symbol("extendedHeader"),ri=Symbol("globalExtendedHeader"),sn=Symbol("meta"),of=Symbol("emitMeta"),ue=Symbol("buffer"),Ut=Symbol("queue"),on=Symbol("ended"),Ua=Symbol("emittedEnd"),kn=Symbol("emit"),Te=Symbol("unzip"),ms=Symbol("consumeChunk"),ws=Symbol("consumeChunkSub"),Ga=Symbol("consumeBody"),af=Symbol("consumeMeta"),cf=Symbol("consumeHeader"),ii=Symbol("consuming"),ja=Symbol("bufferConcat"),ys=Symbol("maybeEnd"),ar=Symbol("writing"),an=Symbol("aborted"),_s=Symbol("onDone"),On=Symbol("sawValidEntry"),Es=Symbol("sawNullBlock"),bs=Symbol("sawEOF"),df=Symbol("closeStream"),jm=()=>!0,_i=class extends am{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ut]=[];[ue];[Ft];[Dn];[st]="begin";[sn]="";[It];[ri];[on]=!1;[Te];[an]=!1;[On];[Es]=!1;[bs]=!1;[ar]=!1;[ii]=!1;[Ua]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(_s,()=>{(this[st]==="begin"||this[On]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(_s,t.ondone):this.on(_s,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Um,this.filter=typeof t.filter=="function"?t.filter:jm;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[df]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Hs(this,t,e,r)}[cf](t,e){this[On]===void 0&&(this[On]=!1);let r;try{r=new Bn(t,e,this[It],this[ri])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Es]?(this[bs]=!0,this[st]==="begin"&&(this[st]="header"),this[kn]("eof")):(this[Es]=!0,this[kn]("nullBlock"));else if(this[Es]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Dn]=new Hf(r,this[It],this[ri]);if(!this[On])if(o.remain){let c=()=>{o.invalid||(this[On]=!0)};o.on("end",c)}else this[On]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[kn]("ignoredEntry",o),this[st]="ignore",o.resume()):o.size>0&&(this[sn]="",o.on("data",c=>this[sn]+=c),this[st]="meta"):(this[It]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[kn]("ignoredEntry",o),this[st]=o.remain?"ignore":"header",o.resume()):(o.remain?this[st]="body":(this[st]="header",o.end()),this[Ft]?this[Ut].push(o):(this[Ut].push(o),this[Fa]())))}}}[df](){queueMicrotask(()=>this.emit("close"))}[sf](t){let e=!0;if(!t)this[Ft]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ft]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Fa]()),e=!1);return e}[Fa](){do;while(this[sf](this[Ut].shift()));if(this[Ut].length===0){let t=this[Ft];!t||t.flowing||t.size===t.remain?this[ar]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ga](t,e){let r=this[Dn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[st]="header",this[Dn]=void 0,r.end()),o.length}[af](t,e){let r=this[Dn],i=this[Ga](t,e);return!this[Dn]&&r&&this[of](r),i}[kn](t,e,r){this[Ut].length===0&&!this[Ft]?this.emit(t,e,r):this[Ut].push([t,e,r])}[of](t){switch(this[kn]("meta",this[sn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[It]=Ms.parse(this[sn],this[It],!1);break;case"GlobalExtendedHeader":this[ri]=Ms.parse(this[sn],this[ri],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[It]??Object.create(null);this[It]=e,e.path=this[sn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[It]||Object.create(null);this[It]=e,e.linkpath=this[sn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[an]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[an])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[ue]&&(t=Buffer.concat([this[ue],t]),this[ue]=void 0),t.length<Gm)return this[ue]=t,r?.(),!0;for(let d=0;this[Te]===void 0&&d<ec.length;d++)t[d]!==ec[d]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<tc.length;d++)if(t[d]!==tc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[on])this.brotli=!0;else return this[ue]=t,r?.(),!0;else try{new Bn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let d=this[on];this[on]=!1,this[Te]=this[Te]===void 0?new hm({}):o?new mm({}):new pm({}),this[Te].on("data",h=>this[ms](h)),this[Te].on("error",h=>this.abort(h)),this[Te].on("end",()=>{this[on]=!0,this[ms]()}),this[ar]=!0;let f=!!this[Te][d?"end":"write"](t);return this[ar]=!1,r?.(),f}}this[ar]=!0,this[Te]?this[Te].write(t):this[ms](t),this[ar]=!1;let i=this[Ut].length>0?!1:this[Ft]?this[Ft].flowing:!0;return!i&&this[Ut].length===0&&this[Ft]?.once("drain",()=>this.emit("drain")),r?.(),i}[ja](t){t&&!this[an]&&(this[ue]=this[ue]?Buffer.concat([this[ue],t]):t)}[ys](){if(this[on]&&!this[Ua]&&!this[an]&&!this[ii]){this[Ua]=!0;let t=this[Dn];if(t&&t.blockRemain){let e=this[ue]?this[ue].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ue]&&t.write(this[ue]),t.end()}this[kn](_s)}}[ms](t){if(this[ii]&&t)this[ja](t);else if(!t&&!this[ue])this[ys]();else if(t){if(this[ii]=!0,this[ue]){this[ja](t);let e=this[ue];this[ue]=void 0,this[ws](e)}else this[ws](t);for(;this[ue]&&this[ue]?.length>=512&&!this[an]&&!this[bs];){let e=this[ue];this[ue]=void 0,this[ws](e)}this[ii]=!1}(!this[ue]||this[on])&&this[ys]()}[ws](t){let e=0,r=t.length;for(;e+512<=r&&!this[an]&&!this[bs];)switch(this[st]){case"begin":case"header":this[cf](t,e),e+=512;break;case"ignore":case"body":e+=this[Ga](t,e);break;case"meta":e+=this[af](t,e);break;default:throw new Error("invalid state: "+this[st])}e<r&&(this[ue]=this[ue]?Buffer.concat([t.subarray(e),this[ue]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[an]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[on]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[ys]())),this}},hi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},Hm=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},qf=(t,e)=>{let r=new Map(e.map(c=>[hi(c),!0])),i=t.filter,o=(c,d="")=>{let f=d||Qg(c).root||".",h;if(c===f)h=!1;else{let x=r.get(c);h=x!==void 0?x:o(Xg(c),f)}return r.set(c,h),h};t.filter=i?(c,d)=>i(c,d)&&o(hi(c)):c=>o(hi(c))},qm=t=>{let e=new _i(t),r=t.file,i;try{i=hr.openSync(r,"r");let o=hr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),f=hr.readSync(i,d,0,o.size,0);e.end(f===d.byteLength?d:d.subarray(0,f))}else{let d=0,f=Buffer.allocUnsafe(c);for(;d<o.size;){let h=hr.readSync(i,f,0,c,d);if(h===0)break;d+=h,e.write(f.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{hr.closeSync(i)}catch{}}},Wm=(t,e)=>{let r=new _i(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),hr.stat(o,(f,h)=>{if(f)d(f);else{let x=new yc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},mr=Ei(qm,Wm,t=>new _i(t),t=>new _i(t),(t,e)=>{e?.length&&qf(t,e),t.noResume||Hm(t)}),Wf=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Km,parse:ff}=$m,vc=t=>{let e="",r=ff(t);for(;Km(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=ff(t)}return[e,t]},qs=["|","<",">","?",":"],Sc=qs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Zm=new Map(qs.map((t,e)=>[t,Sc[e]])),Vm=new Map(Sc.map((t,e)=>[t,qs[e]])),uf=t=>qs.reduce((e,r)=>e.split(r).join(Zm.get(r)),t),Jm=t=>Sc.reduce((e,r)=>e.split(r).join(Vm.get(r)),t),$f=(t,e)=>e?(t=J(t).replace(/^\.(\/|$)/,""),hi(e)+"/"+t):J(t),Ym=16*1024*1024,hf=Symbol("process"),xf=Symbol("file"),pf=Symbol("directory"),nc=Symbol("symlink"),gf=Symbol("hardlink"),si=Symbol("header"),Rs=Symbol("read"),rc=Symbol("lstat"),Cs=Symbol("onlstat"),ic=Symbol("onread"),sc=Symbol("onreadlink"),oc=Symbol("openfile"),ac=Symbol("onopenfile"),un=Symbol("close"),zs=Symbol("mode"),cc=Symbol("awaitDrain"),Ha=Symbol("ondrain"),Tt=Symbol("prefix"),Kf=class extends zn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=_c(e);super(),this.path=J(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Ym,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=J(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?J(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=vc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Jm(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=J(r.absolute||lf.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Cs](o):this[rc]()}warn(t,e,r={}){return Hs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[rc](){At.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Cs](e)})}[Cs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=ew(t),this.emit("stat",t),this[hf]()}[hf](){switch(this.type){case"File":return this[xf]();case"Directory":return this[pf]();case"SymbolicLink":return this[nc]();default:return this.end()}}[zs](t){return Wf(t,this.type==="Directory",this.portable)}[Tt](t){return $f(t,this.prefix)}[si](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Bn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,mode:this[zs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Ms({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[pf](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[si](),this.end()}[nc](){At.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[sc](e)})}[sc](t){this.linkpath=J(t),this[si](),this.end()}[gf](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=J(lf.relative(this.cwd,t)),this.stat.size=0,this[si](),this.end()}[xf](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[gf](e);this.linkCache.set(t,this.absolute)}if(this[si](),this.stat.size===0)return this.end();this[oc]()}[oc](){At.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[ac](e)})}[ac](t){if(this.fd=t,this.#e)return this[un]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Rs]()}[Rs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");At.read(t,e,r,i,o,(c,d)=>{if(c)return this[un](()=>this.emit("error",c));this[ic](d)})}[un](t=()=>{}){this.fd!==void 0&&At.close(this.fd,t)}[ic](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[un](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[un](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Ha]():this[cc](()=>this[Ha]())}[cc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Ha](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[un](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Rs]()}},Xm=class extends Kf{sync=!0;[rc](){this[Cs](At.lstatSync(this.absolute))}[nc](){this[sc](At.readlinkSync(this.absolute))}[oc](){this[ac](At.openSync(this.absolute,"r"))}[Rs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=At.readSync(e,r,i,o,c);this[ic](d),t=!1}finally{if(t)try{this[un](()=>{})}catch{}}}[cc](t){t()}[un](t=()=>{}){this.fd!==void 0&&At.closeSync(this.fd),t()}},Qm=class extends zn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Hs(this,t,e,r)}constructor(t,e={}){let r=_c(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=J(t.path),this.mode=t.mode!==void 0?this[zs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?J(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,f]=vc(this.path);d&&typeof f=="string"&&(this.path=f,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Bn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new Ms({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Tt](t){return $f(t,this.prefix)}[zs](t){return Wf(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},ew=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",tw=class xr{tail;head;length=0;static create(e=[]){return new xr(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)rw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)iw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new xr;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new xr;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new xr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new xr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=nw(this,o,d);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function nw(t,e,r){let i=e,o=e?e.next:t.head,c=new Ic(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function rw(t,e){t.tail=new Ic(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function iw(t,e){t.head=new Ic(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Ic=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},wf=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},yf=Buffer.alloc(1024),Ds=Symbol("onStat"),oi=Symbol("ended"),ht=Symbol("queue"),ai=Symbol("queue"),cn=Symbol("current"),Pn=Symbol("process"),ci=Symbol("processing"),vs=Symbol("processJob"),xt=Symbol("jobs"),qa=Symbol("jobDone"),ks=Symbol("addFSEntry"),_f=Symbol("addTarEntry"),dc=Symbol("stat"),lc=Symbol("readdir"),Os=Symbol("onreaddir"),Ps=Symbol("pipe"),Ef=Symbol("entry"),Wa=Symbol("entryOpt"),Ls=Symbol("writeEntryClass"),Zf=Symbol("write"),$a=Symbol("ondrain"),Ws=class extends zn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ls];onWriteEntry;[ht];[ai]=new Map;[xt]=0;[ci]=!1;[oi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=J(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Ls]=Kf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new um(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new xm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new gm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[$a]()),this.on("resume",()=>e.resume())}else this.on("drain",this[$a]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[ht]=new tw,this[xt]=0,this.jobs=Number(t.jobs)||4,this[ci]=!1,this[oi]=!1}[Zf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[oi]=!0,this[Pn](),r&&r(),this}write(t){if(this[oi])throw new Error("write after end");return t instanceof Hf?this[_f](t):this[ks](t),this.flowing}[_f](t){let e=J(mf.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new wf(t.path,e);r.entry=new Qm(t,this[Wa](r)),r.entry.on("end",()=>this[qa](r)),this[xt]+=1,this[ht].push(r)}this[Pn]()}[ks](t){let e=J(mf.resolve(this.cwd,t));this[ht].push(new wf(t,e)),this[Pn]()}[dc](t){t.pending=!0,this[xt]+=1;let e=this.follow?"stat":"lstat";Bs[e](t.absolute,(r,i)=>{t.pending=!1,this[xt]-=1,r?this.emit("error",r):this[Ds](t,i)})}[Ds](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[cn])this[vs](t);else{let r=`${e.dev}:${e.ino}`,i=this[ai].get(r);i?i.push(t):this[ai].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Pn]()}[lc](t){t.pending=!0,this[xt]+=1,Bs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[xt]-=1,e)return this.emit("error",e);this[Os](t,r)})}[Os](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Pn]()}[Pn](){if(!this[ci]){this[ci]=!0;for(let t=this[ht].head;t&&this[xt]<this.jobs;t=t.next)if(this[vs](t.value),t.value.ignore){let e=t.next;this[ht].removeNode(t),t.next=e}this[ci]=!1,this[oi]&&this[ht].length===0&&this[xt]===0&&(this.zip?this.zip.end(yf):(super.write(yf),super.end()))}}get[cn](){return this[ht]&&this[ht].head&&this[ht].head.value}[qa](t){this[ht].shift(),this[xt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[ai].get(r);if(i){this[ai].delete(r);for(let o of i)o.pending=!1,this[vs](o)}}this[Pn]()}[vs](t){if(t.pending&&t.pendingLink&&t===this[cn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[cn]&&!t.piped&&this[Ps](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ds](t,e):this[dc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Os](t,e):this[lc](t),!t.readdir)return}if(t.entry=this[Ef](t),!t.entry){t.ignore=!0;return}t===this[cn]&&!t.piped&&this[Ps](t)}}}[Wa](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Ef](t){this[xt]+=1;try{return new this[Ls](t.path,this[Wa](t)).on("end",()=>this[qa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[$a](){this[cn]&&this[cn].entry&&this[cn].entry.resume()}[Ps](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[ks](c+i)});let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",i=>{r.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){Hs(this,t,e,r)}},Ac=class extends Ws{sync=!0;constructor(t){super(t),this[Ls]=Xm}pause(){}resume(){}[dc](t){let e=this.follow?"statSync":"lstatSync";this[Ds](t,Bs[e](t.absolute))}[lc](t){this[Os](t,Bs.readdirSync(t.absolute))}[Ps](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[ks](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[Zf](i)})}},sw=(t,e)=>{let r=new Ac(t),i=new Nf(t.file,{mode:t.mode||438});r.pipe(i),Vf(r,e)},ow=(t,e)=>{let r=new Ws(t),i=new Gs(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),r.on("error",d)});return Jf(r,e).catch(c=>r.emit("error",c)),o},Vf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?mr({file:Mf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Jf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await mr({file:Mf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},aw=(t,e)=>{let r=new Ac(t);return Vf(r,e),r},cw=(t,e)=>{let r=new Ws(t);return Jf(r,e).catch(i=>r.emit("error",i)),r},g2=Ei(sw,ow,aw,cw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),lw=process.env.__FAKE_PLATFORM__||process.platform,eu=lw==="win32",{O_CREAT:tu,O_NOFOLLOW:bf,O_TRUNC:nu,O_WRONLY:ru}=Qf.constants,iu=Number(process.env.__FAKE_FS_O_FILENAME__)||Qf.constants.UV_FS_O_FILEMAP||0,fw=eu&&!!iu,uw=512*1024,hw=iu|nu|tu|ru,vf=!eu&&typeof bf=="number"?bf|nu|tu|ru:null,su=vf!==null?()=>vf:fw?t=>t<uw?hw:"w":()=>"w",fc=(t,e,r)=>{try{return $s.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Fs=(t,e,r,i)=>{$s.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},xw=(t,e,r,i,o)=>{if(e.isDirectory())ou(xi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=xi.resolve(t,e.name);Fs(d,r,i,o)});else{let c=xi.resolve(t,e.name);Fs(c,r,i,o)}},ou=(t,e,r,i)=>{$s.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return Fs(t,e,r,i);let d=c.length,f=null,h=x=>{if(!f){if(x)return i(f=x);if(--d===0)return Fs(t,e,r,i)}};for(let x of c)xw(t,x,e,r,h)})},pw=(t,e,r,i)=>{e.isDirectory()&&au(xi.resolve(t,e.name),r,i),fc(xi.resolve(t,e.name),r,i)},au=(t,e,r)=>{let i;try{i=$s.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return fc(t,e,r);throw c}for(let o of i)pw(t,o,e,r);return fc(t,e,r)},cu=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},Ks=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},mw=(t,e)=>{et.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new cu(t,r?.code||"ENOTDIR")),e(r)})},ww=(t,e,r)=>{t=J(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,f=e.gid,h=typeof d=="number"&&typeof f=="number"&&(d!==e.processUid||f!==e.processGid),x=e.preserve,m=e.unlink,g=J(e.cwd),A=(E,I)=>{E?r(E):I&&h?ou(I,d,f,S=>A(S)):c?et.chmod(t,o,r):r()};if(t===g)return mw(t,A);if(x)return gw.mkdir(t,{mode:o,recursive:!0}).then(E=>A(null,E??void 0),A);let w=J(Us.relative(g,t)).split("/");uc(g,w,o,m,g,void 0,A)},uc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let f=e.shift(),h=J(Us.resolve(t+"/"+f));et.mkdir(h,r,du(h,e,r,i,o,c,d))},du=(t,e,r,i,o,c,d)=>f=>{f?et.lstat(t,(h,x)=>{if(h)h.path=h.path&&J(h.path),d(h);else if(x.isDirectory())uc(t,e,r,i,o,c,d);else if(i)et.unlink(t,m=>{if(m)return d(m);et.mkdir(t,r,du(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new Ks(t,t+"/"+e.join("/")));d(f)}}):(c=c||t,uc(t,e,r,i,o,c,d))},yw=t=>{let e=!1,r;try{e=et.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new cu(t,r??"ENOTDIR")}},_w=(t,e)=>{t=J(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,f=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),h=e.preserve,x=e.unlink,m=J(e.cwd),g=E=>{E&&f&&au(E,c,d),o&&et.chmodSync(t,i)};if(t===m)return yw(m),g();if(h)return g(et.mkdirSync(t,{mode:i,recursive:!0})??void 0);let A=J(Us.relative(m,t)).split("/"),w;for(let E=A.shift(),I=m;E&&(I+="/"+E);E=A.shift()){I=J(Us.resolve(I));try{et.mkdirSync(I,i),w=w||I}catch{let S=et.lstatSync(I);if(S.isDirectory())continue;if(x){et.unlinkSync(I),et.mkdirSync(I,i),w=w||I;continue}else if(S.isSymbolicLink())return new Ks(I,I+"/"+A.join("/"))}}return g(w)},Ka=Object.create(null),Sf=1e4,cr=new Set,Ew=t=>{cr.has(t)?cr.delete(t):Ka[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),cr.add(t);let e=Ka[t],r=cr.size-Sf;if(r>Sf/10){for(let i of cr)if(cr.delete(i),delete Ka[i],--r<=0)break}return e},bw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,vw=bw==="win32",Sw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=lu(i,r)),e.push(r||"/"),e},[]),Iw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=vw?["win32 parallelization disabled"]:t.map(i=>hi(lu(Ew(i))));let r=new Set(t.map(i=>Sw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let f=d[1];if(!f){this.#e.delete(c);continue}if(d.shift(),typeof f=="function")o.add(f);else for(let h of f)o.add(h)}for(let c of i){let d=this.#e.get(c),f=d?.[0];if(!(!d||!(f instanceof Set)))if(f.size===1&&d.length===1){this.#e.delete(c);continue}else if(f.size===1){d.shift();let h=d[0];typeof h=="function"&&o.add(h)}else f.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Aw=()=>process.umask(),If=Symbol("onEntry"),hc=Symbol("checkFs"),Af=Symbol("checkFs2"),xc=Symbol("isReusable"),ot=Symbol("makeFs"),pc=Symbol("file"),gc=Symbol("directory"),Ns=Symbol("link"),Tf=Symbol("symlink"),Rf=Symbol("hardlink"),fi=Symbol("ensureNoSymlink"),Cf=Symbol("unsupported"),Df=Symbol("checkPath"),Za=Symbol("stripAbsolutePath"),hn=Symbol("mkdir"),ze=Symbol("onError"),Ss=Symbol("pending"),kf=Symbol("pend"),dr=Symbol("unpend"),Va=Symbol("ended"),Ja=Symbol("maybeClose"),mc=Symbol("skip"),pi=Symbol("doChown"),gi=Symbol("uid"),mi=Symbol("gid"),wi=Symbol("checkedCwd"),Tw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,yi=Tw==="win32",Rw=1024,Cw=(t,e)=>{if(!yi)return re.unlink(t,e);let r=t+".DELETE."+Xf(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},Dw=t=>{if(!yi)return re.unlinkSync(t);let e=t+".DELETE."+Xf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Of=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Tc=class extends _i{[Va]=!1;[wi]=!1;[Ss]=0;reservations=new Iw;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[Va]=!0,this[Ja]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:Rw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||yi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=J(Pe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Aw():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[If](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[Ja](){this[Va]&&this[Ss]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Za](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=vc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||yi&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let f=Pe.posix.dirname(t.path),h=Pe.posix.normalize(Pe.posix.join(f,d.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Df](t){let e=J(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=J(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[Za](t,"path")||!this[Za](t,"linkpath"))return!1;if(t.absolute=Pe.isAbsolute(t.path)?J(Pe.resolve(t.path)):J(Pe.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:J(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Pe.win32.parse(String(t.absolute));t.absolute=i+uf(String(t.absolute).slice(i.length));let{root:o}=Pe.win32.parse(t.path);t.path=o+uf(t.path.slice(o.length))}return!0}[If](t){if(!this[Df](t))return t.resume();switch(dw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[hc](t);default:return this[Cf](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[dr](),e.resume())}[hn](t,e,r){ww(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[pi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[gi](t){return Of(this.uid,t.uid,this.processUid)}[mi](t){return Of(this.gid,t.gid,this.processGid)}[pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Gs(String(t.absolute),{flags:su(t.size),mode:r,autoClose:!1});i.on("error",f=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[ze](f,t),e()});let o=1,c=f=>{if(f){i.fd&&re.close(i.fd,()=>{}),this[ze](f,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[ze](h,t):this[dr](),e()})};i.on("finish",()=>{let f=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;re.futimes(h,x,m,g=>g?re.utimes(f,x,m,A=>c(A&&g)):c())}if(typeof h=="number"&&this[pi](t)){o++;let x=this[gi](t),m=this[mi](t);typeof x=="number"&&typeof m=="number"&&re.fchown(h,x,m,g=>g?re.chown(f,x,m,A=>c(A&&g)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",f=>{this[ze](f,t),e()}),t.pipe(d)),d.pipe(i)}[gc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[hn](String(t.absolute),r,i=>{if(i){this[ze](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[dr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[pi](t)&&(o++,re.chown(String(t.absolute),Number(this[gi](t)),Number(this[mi](t)),c)),c()})}[Cf](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Tf](t,e){let r=J(Pe.relative(this.cwd,Pe.resolve(Pe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[fi](t,this.cwd,r,()=>this[Ns](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Rf](t,e){let r=J(Pe.resolve(this.cwd,String(t.linkpath))),i=J(String(t.linkpath)).split("/");this[fi](t,this.cwd,i,()=>this[Ns](t,r,"link",e),o=>{this[ze](o,t),e()})}[fi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Pe.resolve(e,c);re.lstat(d,(f,h)=>{if(f)return i();if(h?.isSymbolicLink())return o(new Ks(d,Pe.resolve(d,r.join("/"))));this[fi](t,d,r,i,o)})}[kf](){this[Ss]++}[dr](){this[Ss]--,this[Ja]()}[mc](t){this[dr](),t.resume()}[xc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!yi}[hc](t){this[kf]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Af](t,r))}[Af](t,e){let r=d=>{e(d)},i=()=>{this[hn](this.cwd,this.dmode,d=>{if(d){this[ze](d,t),r();return}this[wi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=J(Pe.dirname(String(t.absolute)));if(d!==this.cwd)return this[hn](d,this.dmode,f=>{if(f){this[ze](f,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(d,f)=>{if(f&&(this.keep||this.newer&&f.mtime>(t.mtime??f.mtime))){this[mc](t),r();return}if(d||this[xc](t,f))return this[ot](null,t,r);if(f.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(f.mode&4095)!==t.mode,x=m=>this[ot](m??null,t,r);return h?re.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),h=>this[ot](h??null,t,r))}if(t.absolute===this.cwd)return this[ot](null,t,r);Cw(String(t.absolute),h=>this[ot](h??null,t,r))})};this[wi]?o():i()}[ot](t,e,r){if(t){this[ze](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[pc](e,r);case"Link":return this[Rf](e,r);case"SymbolicLink":return this[Tf](e,r);case"Directory":case"GNUDumpDir":return this[gc](e,r)}}[Ns](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[dr](),t.resume()),i()})}},di=t=>{try{return[null,t()]}catch(e){return[e,null]}},fu=class extends Tc{sync=!0;[ot](t,e){return super[ot](t,e,()=>{})}[hc](t){if(!this[wi]){let o=this[hn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[wi]=!0}if(t.absolute!==this.cwd){let o=J(Pe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[hn](o,this.dmode);if(c)return this[ze](c,t)}}let[e,r]=di(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[mc](t);if(e||this[xc](t,r))return this[ot](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?di(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ot](d,t)}let[o]=di(()=>re.rmdirSync(String(t.absolute)));this[ot](o,t)}let[i]=t.absolute===this.cwd?[]:di(()=>Dw(String(t.absolute)));this[ot](i,t)}[pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let f;try{re.closeSync(o)}catch(h){f=h}(d||f)&&this[ze](d||f,t),e()},o;try{o=re.openSync(String(t.absolute),su(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[ze](d,t)),t.pipe(c)),c.on("data",d=>{try{re.writeSync(o,d,0,d.length)}catch(f){i(f)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let f=t.atime||new Date,h=t.mtime;try{re.futimesSync(o,f,h)}catch(x){try{re.utimesSync(String(t.absolute),f,h)}catch{d=x}}}if(this[pi](t)){let f=this[gi](t),h=this[mi](t);try{re.fchownSync(o,Number(f),Number(h))}catch(x){try{re.chownSync(String(t.absolute),Number(f),Number(h))}catch{d=d||x}}}i(d)})}[gc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[hn](String(t.absolute),r);if(i){this[ze](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[pi](t))try{re.chownSync(String(t.absolute),Number(this[gi](t)),Number(this[mi](t)))}catch{}e(),t.resume()}[hn](t,e){try{return _w(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[fi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Pe.resolve(c,d);let[f,h]=di(()=>re.lstatSync(c));if(f)return i();if(h.isSymbolicLink())return o(new Ks(c,Pe.resolve(e,r.join("/"))))}i()}[Ns](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[ze](c,t)}}},kw=t=>{let e=new fu(t),r=t.file,i=Yf.statSync(r),o=t.maxReadSize||16*1024*1024;new Yg(r,{readSize:o,size:i.size}).pipe(e)},Ow=(t,e)=>{let r=new Tc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),Yf.stat(o,(f,h)=>{if(f)d(f);else{let x=new yc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},uu=Ei(kw,Ow,t=>new fu(t),t=>new Tc(t),(t,e)=>{e?.length&&qf(t,e)}),Pw=(t,e)=>{let r=new Ac(t),i=!0,o,c;try{try{o=Qe.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=Qe.openSync(t.file,"w+");else throw h}let d=Qe.fstatSync(o),f=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let m=0,g=0;m<512;m+=g){if(g=Qe.readSync(o,f,m,f.length-m,c+m),c===0&&f[0]===31&&f[1]===139)throw new Error("cannot append to compressed archives");if(!g)break e}let h=new Bn(f);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,Lw(t,r,c,o,e)}finally{if(i)try{Qe.closeSync(o)}catch{}}},Lw=(t,e,r,i,o)=>{let c=new Nf(t.file,{fd:i,start:r});e.pipe(c),Mw(e,o)},Nw=(t,e)=>{e=Array.from(e);let r=new Ws(t),i=(o,c,d)=>{let f=(A,w)=>{A?Qe.close(o,E=>d(A)):d(null,w)},h=0;if(c===0)return f(null,0);let x=0,m=Buffer.alloc(512),g=(A,w)=>{if(A||w===void 0)return f(A);if(x+=w,x<512&&w)return Qe.read(o,m,x,m.length-x,h+x,g);if(h===0&&m[0]===31&&m[1]===139)return f(new Error("cannot append to compressed archives"));if(x<512)return f(null,h);let E=new Bn(m);if(!E.cksumValid)return f(null,h);let I=512*Math.ceil((E.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return f(null,h);t.mtimeCache&&E.mtime&&t.mtimeCache.set(String(E.path),E.mtime),x=0,Qe.read(o,m,0,512,h,g)};Qe.read(o,m,0,512,h,g)};return new Promise((o,c)=>{r.on("error",c);let d="r+",f=(h,x)=>{if(h&&h.code==="ENOENT"&&d==="r+")return d="w+",Qe.open(t.file,d,f);if(h||!x)return c(h);Qe.fstat(x,(m,g)=>{if(m)return Qe.close(x,()=>c(m));i(x,g.size,(A,w)=>{if(A)return c(A);let E=new Gs(t.file,{fd:x,start:w});r.pipe(E),E.on("error",c),E.on("close",o),Bw(r,e)})})};Qe.open(t.file,d,f)})},Mw=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?mr({file:hu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Bw=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await mr({file:hu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},li=Ei(Pw,Nw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!sm(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")}),k2=Ei(li.syncFile,li.asyncFile,li.syncNoFile,li.asyncNoFile,(t,e=[])=>{li.validate?.(t,e),zw(t)}),zw=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};tn();var mt={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 bi(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function xu(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Rc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function pu(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function wr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}qe();ne();ke();qe();function Ht(t,e){if(bi(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Zs(t){return t.startsWith("http://")||t.startsWith("https://")}function Vs(t){return t.endsWith("/")?t.slice(0,-1):t}qe();ne();var Js="1008033",gu="1289";var mu="pbbp2",wu="https://www.coze.cn",yu="/api/coze_claw/resource/get_frontier_key",Uw="https://www.coze.cn",Gw="wss://frontier.coze.cn";function Ys(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Uw}function _u(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??Gw}function yr(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Si(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var vi=G("handshake");async function Cc(t){let e=Ys(t.endpoint),r=t.timeoutMs??1e4,i=`${Vs(e)}${yu}?aid=${encodeURIComponent(Js)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...yr(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);vi.info("frontier key handshake",{base:e});try{let f=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=f.headers.get("x-tt-logid")??"",x=f.headers.get("x-tt-trace-id")??"";if(!f.ok){let E=await f.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${f.status} logid=${h}: ${E.slice(0,200)}`)}let m=await f.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let g=m.data??{},A=typeof g.access_key=="string"&&g.access_key||typeof g.accessKey=="string"&&g.accessKey||void 0,w=typeof g.device_id=="string"&&g.device_id||typeof g.deviceId=="string"&&g.deviceId||void 0;if(!A||!w){let E=JSON.stringify(m).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${E}`)}return vi.info("handshake ok",{remoteDeviceId:w,logid:h,traceId:x}),{accessKey:A,deviceId:w}}catch(f){if(f instanceof T)throw vi.error("handshake failed (bridge error)",{base:e,message:f.message,code:f.code}),f;if(f.name==="AbortError")throw vi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:f});let h=f.cause;throw vi.error("handshake error",{base:e,message:f instanceof Error?f.message:String(f),errno:h?.code,syscall:h?.syscall,cause:String(f).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(f),{cause:f})}finally{clearTimeout(d)}}var Dc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",wt="auto",Eu=2e5;function bu(t){return{model:kc(t.model)??wt,...t.modelToken?{modelToken:t.modelToken}:{}}}function vu(t){return!t||t===wt}var jw=new Set(["auto","\u81EA\u52A8"]);function kc(t){let e=t?.trim();if(e)return jw.has(e.toLowerCase())?wt:e}function Su(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Dc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||wt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else vu(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Iu(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||wt}"`):vu(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Dc}/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"');let r=t.modelInfo?.contextWindow??Eu;e.push("-c",`model_context_window=${r}`)}return e}function Au(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Oc(t,e){let{ttEnv:r,usePpe:i}=Si(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Tu(t,e,r){if(!t.modelToken)return{};let i=Oc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
92
- `)}}function Pc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Ru(t,e,r){if(!t.modelToken)return null;let i=t.model||wt,o=Oc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Dc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Eu,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}function Cu(t,e,r){if(!t.modelToken)return[];let i=Oc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var Le=G("agent-handlers"),Du=5*1024*1024,Zw=1,Vw=6,Jw=new Set(["node_modules",".git",".coze","dist","build",".next"]),Xs=class{constructor(e){this.opts=e}opts;async listSkills(e){Ht(e._meta,"_agent/listSkills");let r=wr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],d=[];for(let f of c){let h=Ct(o,f.relPath,"SKILL.md");await Ww(h).then(m=>m.isFile()).catch(()=>!1)&&d.push(ty(f))}return{skills:d}}async addSkills(e){Ht(e._meta,"_agent/addSkills");let r=wr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((h,x)=>[h.skillId,x])),f=[];for(let h of o){let x=await Uc({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});Gc(c,d,x),f.push(h)}return await rs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:f}}async removeSkills(e){Ht(e._meta,"_agent/removeSkills");let r=wr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let f of c){if(!o.has(f.skillId)){d.push(f);continue}let h=Ct(i.workspace,f.relPath);await qw(h,{recursive:!0,force:!0}),Le.info("skill removed",{agentId:r,skillId:f.skillId,relPath:f.relPath})}return await rs(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Le.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let h=c.downstream;c.downstream=void 0,Le.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),h.stop(r).catch(x=>Le.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Le.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Ge(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Le.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await tr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Le.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ve(i),Le.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Ge(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ve(i),Le.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Le.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Ht(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=kc(e.model)??wt,i=await Ge(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ve(i),Le.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Le.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(d=>Le.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(d)}));let c=[];for(let[d,f]of o.allSessionQueues())c.push(f.enqueue(async()=>{let h=o.sessions.get(d);h?.downstream&&(await h.downstream.stop(`switchModel: ${r}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(c),Le.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(Ht(e._meta,mt.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${mt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,mt.RESET),await this.runDetailSync(e.agentId,mt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Le.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await Vr(e,o)}async clearPersistedAcpSessionIds(e){let r=await Ge(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Ve(r)}async repairAgent(e){if(Ht(e._meta,mt.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${mt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${mt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Le.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,mt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Le.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Le.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Ht(e._meta,"_agent/getFileTree");let r=e._meta,i=wr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),f=await Lc(d).catch(()=>null);if(!f)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(f.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Zr(d,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=uy(e.depth);return f.isDirectory()?{tree:await fy(o,d,c,h)}:{tree:[{name:hy(c),path:Bu(c||"."),isDir:!1,size:f.size,modifiedAt:Math.floor(f.mtimeMs)}]}}async getFileContent(e){Ht(e._meta,"_agent/getFileContent");let r=wr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Lc(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Zr(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Du)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Du})`);let d=await ku(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await Ge(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=Bc(e,r||"."),o=Fc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Ou}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Ge(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function Yw(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function Xw(t){return t==="claude-code"?Ct(".claude","skills"):Ct(".agents","skills")}var Qw=3e4,ey=50*1024*1024,_r=3e4;async function Uc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let f=Yw(o.skillName),h=Xw(i),x=Ct(h,f),m=Ct(r,x);if(await Nc(m,{recursive:!0}),c){let A=Buffer.from(o.content,"utf8");Ii(A.length),await Mc(Ct(m,"SKILL.md"),A,"utf8")}else{let A=await ny(o.downloadUrl);iy(A)?await cy(A,m):sy(A)?await oy(A,m):await Mc(Ct(m,"SKILL.md"),A.toString("utf8"),"utf8")}let g={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Le.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),g}function Gc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function ty(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function ny(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ii(e);let r=ry(t);return Ii(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await ku(e);return Ii(r.length),r}if(Zs(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),Qw);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ii(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ii(t){if(t>ey)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function ry(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function iy(t){return t.length>=2&&t[0]===31&&t[1]===139}function sy(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function zc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function oy(t,e){let r,i;try{r=new Nu.default(t),i=r.getEntries()}catch(d){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let f=d.entryName;if(!f||zc(f))continue;if(f.startsWith("/")||/^[A-Za-z]:[\\/]/.test(f))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${f}`);if(f.split(/[/\\]/).some(x=>x===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${f}`);let h=d.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${f}`)}let o=ay(i),c=Bc(e);for(let d of i){if(zc(d.entryName))continue;let f=d.entryName;if(o&&f.startsWith(o)&&(f=f.slice(o.length)),!f)continue;let h=Bc(e,f),x=Fc(c,h);if(x.startsWith("..")||x==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${f}`);if(d.isDirectory){await Nc(h,{recursive:!0});continue}await Nc($w(h),{recursive:!0});let m;try{m=d.getData()}catch(g){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${g.message}`,{cause:g})}await Mc(h,m)}}function ay(t){let e;for(let r of t){let i=r.entryName;if(!i||zc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function cy(t,e){await dy(t);let r=uu({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${_r}ms)`))},_r);try{await Lu(Pu.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${_r}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function dy(t){let e=[],r=mr({onReadEntry:c=>{let d=c.path,f=c.type;if(f!=="File"&&f!=="Directory"){e.push(`tar entry kind '${f}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${_r}ms)`))},_r);try{await Lu(Pu.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${_r}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var ly=5e3;async function fy(t,e,r,i){return Mu(t,e,r,i,{count:0})}async function Mu(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Hw(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let f of c){if(Jw.has(f.name)||f.isSymbolicLink())continue;if(o.count>=ly){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=Ct(e,f.name),x=Kw(Ct(r,f.name)),m=null;try{m=await Lc(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let g={name:f.name,path:Bu(Fc(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(g.children=await Mu(t,h,x,i-1,o)),d.push(g)}return d.sort((f,h)=>f.isDir!==h.isDir?f.isDir?-1:1:f.name.localeCompare(h.name)),d}function uy(t){return!t||t<=0?Zw:Math.min(t,Vw)}function hy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Bu(t){return t.split(Ou).join("/")}ne();import{readFileSync as GI}from"node:fs";import{dirname as HI,join as qI}from"node:path";import{fileURLToPath as $I}from"node:url";var Er="0.1.98-alpha.2";var gn=G("agent-health-reporter"),xy=1e4,Ai=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??xy}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()}),gn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),gn.info("heartbeat stopped"))}async tick(){if(this.inFlight){gn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){gn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let f=py(d);if(!f)continue;let h={agentId:d.agentId,status:f};d.patToken&&(h.patToken=d.patToken),d.accountId&&(h.accountId=d.accountId),r.push(h)}if(r.length===0)return;let i={agents:r,bridgeVersion:Er,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(d){gn.warn("heartbeat batch send failed",{count:r.length,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(gn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){gn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){gn.warn("onTickEnd hook failed",{err:String(r)})}}};function py(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}tn();import{chmod as a_,mkdir as ao,rm as c_,stat as d_,writeFile as l_}from"node:fs/promises";import{homedir as f_}from"node:os";import{join as i0}from"node:path";en();import{spawnSync as Oy}from"node:child_process";import{existsSync as Py}from"node:fs";import{release as Ly}from"node:os";import{basename as Ny,isAbsolute as My}from"node:path";function Ti(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function br(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function vr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function mn(t,e){return{jsonrpc:"2.0",id:t,error:e}}qe();var Qs=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)}},Q={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,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021};function zu(t){return"method"in t&&"id"in t&&t.id!==void 0}function Fu(t){return"method"in t&&!("id"in t)}function eo(t){return!("method"in t)&&"id"in t}var gy={AGENT_NOT_FOUND:Q.AGENT_NOT_FOUND,AGENT_BUSY:Q.AGENT_BUSY,AGENT_DISCONNECTED:Q.AGENT_DISCONNECTED,AGENT_TIMEOUT:Q.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Q.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Q.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Q.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Q.INTERNAL_ERROR,BRIDGE_INTERNAL:Q.INTERNAL_ERROR,IPC_AUTH_FAILED:Q.INTERNAL_ERROR,IPC_BAD_REQUEST:Q.INVALID_REQUEST,MODEL_TOKEN_GEN_FAILED:Q.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Q.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Q.OPERATION_NOT_ALLOWED_FOR_LOCAL,UPSTREAM_DISCONNECTED:Q.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Q.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Q.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Q.FILE_TOO_LARGE,UNSUPPORTED_MIME:Q.UNSUPPORTED_MIME,UPLOAD_FAILED:Q.UPLOAD_FAILED,UPSTREAM_NOT_READY:Q.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Q.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Q.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Q.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Q.AGENT_ENV_NOT_READY};function my(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ri(t.message)}:typeof t=="string"?Ri(t):typeof t=="object"?yy(t):t}var wy=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Ri(t){let e=t;for(let[r,i]of wy)e=e.replace(r,i);return e}function yy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ri(i):e[r]=i;return e}function Ci(t){if(t instanceof T){let e=my(t.cause),r={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(r.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(r.reason=e.reason),{code:gy[t.code]??Q.INTERNAL_ERROR,message:Ri(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Ri(t instanceof Error?t.message:String(t))}}function Uu(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...f}=e;c=f}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function ju(t){return`${JSON.stringify(t)}
93
- `}var Gu=10*1024*1024,to=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>Gu){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${Gu} bytes`)}),[]}let r=this.buffer.split(`
94
- `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var qu={"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"},rA=Object.fromEntries(Object.entries(qu).map(([t,e])=>[e,t])),_y={"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:[]},Sr=class{seq=0;next(e,r){this.seq+=1;let i=qu[e]??Ey(e),o=_y[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(h=>Hu(r?.[h]??"")),f=by(d).join(":");f&&c.push(f)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>Hu(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Ey(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Hu(t){return t.replace(/[:_\s]+/g,"-")}function by(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Kr();import{readFileSync as vy}from"node:fs";var Sy=384;async function jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await er(t.agentEnvFile,r,{mode:Sy})}function Hc(t){try{let e=JSON.parse(vy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function Wu(t,e,r={},i=o=>o){return{...i({...t,...Hc(e)}),...r}}wn();Vi();qe();ne();ke();var ky=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: Node binary not found/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed/i,message:"openclaw gateway \u672A\u8FD0\u884C (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"}];function Vu(t,e){if(!e)return null;for(let r of ky)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}var By=Mt("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),zy=200,Fy=40,Uy=Mt("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Gy=Mt("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),jy=Mt("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),Ju=500;function Hy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=Ju?t:`${e.slice(0,Ju)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Yu(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Oy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}function Xu(t){try{return Py(t)}catch{return}}function qy(t,e){return{platform:process.platform,osRelease:Ly(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:My(e.command)?Xu(e.command):void 0,cwd:e.cwd,cwdExists:Xu(e.cwd),envKeys:e.envKeys}}function Wy(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Ny(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Dt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new to({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Sr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=Wu(process.env,this.opts.agentEnvFile??Y().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=at(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>zy&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let f of this.decoder.flush())this.dispatch(f)}catch(f){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(f)})}this.failAllPending(this.buildExitError(o,c));for(let f of this.exitHandlers)f(o,c)}),i.on("error",o=>{let c=o,d=qy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new T("AGENT_SPAWN_FAILED",Wy(c,d),{cause:d}))}),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.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Yu(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Yu(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}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,r=Uy,i=Gy,o=jy){return this.call("session/prompt",e,r,i,o)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(br("session/cancel",e))}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(vr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(mn(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=By,o=0,c=0){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let d=this.idAllocator.next(e),f=Ti(d,e,r),h=(()=>{if(typeof r!="object"||r===null)return;let g=r.sessionId;return typeof g=="string"?g:void 0})(),x=i>0&&Number.isFinite(i),m=o>0&&Number.isFinite(o);return new Promise((g,A)=>{let w={resolve:g,reject:A,timer:null,firstUpdateTimer:null,onFirstUpdate:null,method:e},E=Date.now();if(x){let S=()=>{w.timer=setTimeout(()=>{let R=Date.now()-E;if(this.inflightAgentRequests.size>0&&R<c){this.log.debug("hard cap fired but agent request inflight, extending to approval cap",{id:d,method:e,elapsed:R,approvalMaxMs:c,...h?{sessionId:h}:{}}),S();return}this.pending.delete(d),w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer);let P=this.inflightAgentRequests.size>0;this.log.warn("downstream call timeout",{id:d,method:e,timeoutMs:i,approvalMaxMs:c,awaitingApproval:P,...h?{sessionId:h}:{}}),A(P?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${c}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i)};S()}let I=m?()=>{w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),w.firstUpdateTimer=setTimeout(()=>{if(this.inflightAgentRequests.size>0){this.log.debug("first-update wait fired but agent request inflight, re-arming",{id:d,method:e,inflight:this.inflightAgentRequests.size,...h?{sessionId:h}:{}}),I?.();return}w.timer&&clearTimeout(w.timer),this.pending.delete(d),this.log.warn("first session/update timeout, rejecting pending call",{id:d,method:e,firstUpdateMs:o,...h?{sessionId:h}:{}}),A(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no first session/update within ${o}ms`))},o)}:null;w.onFirstUpdate=m?()=>{w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),w.firstUpdateTimer=null,w.onFirstUpdate=null}:null,this.pending.set(d,w),I?.();try{this.writeFrame(f)}catch(S){w.timer&&clearTimeout(w.timer),w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),this.pending.delete(d),A(S)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(ju(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(eo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(Uu(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Hy(e.result)}),r.resolve(e.result));return}if(Fu(e)){if(e.method==="session/update"){for(let r of this.pending.values())r.onFirstUpdate?.();for(let r of this.updateHandlers)try{Promise.resolve(r(e.params)).catch(i=>this.log.warn("update handler failed (async)",{err:String(i)}))}catch(i){this.log.warn("update handler threw sync, swallowed",{err:String(i)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(zu(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(mn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(mn(e.id,Ci(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Fy).join(`
95
- `),o=Vu(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function $y(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var no=class extends Dt{framework="claude-code";constructor(e){let{command:r,args:i}=$r("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return $y(e)}};en();import{mkdtempSync as Ky,rmSync as Zy}from"node:fs";import{tmpdir as Vy}from"node:os";import{join as Jy}from"node:path";var ro=class extends Dt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=$r("codex",e.command,i),d=e.isolateCodexHome?Ky(Jy(Vy(),"coze-bridge-codex-home-")):void 0,f=d?{...e.env??{},CODEX_HOME:d}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...f?{env:f}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Zy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var Yy=3e4,Ir=class extends Dt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,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}`}]},Yy))}get acpSessionName(){return this.sessionName}};qe();ne();ke();function qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}en();var yn=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((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),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}get isDisposed(){return this.disposed}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 r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var io=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=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",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new yn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Di(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Di(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}wn();ne();import{constants as Qu}from"node:fs";import{access as Xy}from"node:fs/promises";import{delimiter as Qy,join as e_}from"node:path";var yt=G("framework-detector"),e0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},t_=[".exe",".cmd",".bat",".ps1"],Fn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??at,access:e.access??Xy}}async detect(e){let r=e0[e],i=await this.which(r);if(!i)return yt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),f={path:i,version:c};return d&&(f.defaultAgent=d),f}async detectAll(){let e=await Promise.all(Object.keys(e0).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(Qy).filter(Boolean),i=this.env.platform==="win32"?["",...t_]:[""];for(let o of r)for(let c of i){let d=e_(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?Qu.F_OK:Qu.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return yt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return yt.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return yt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return yt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(yt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(yt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return yt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return yt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||yt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){yt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(r_(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,f=h=>{c||(c=!0,d&&clearTimeout(d),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{h.kill("SIGKILL"),f(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>f(null)),h.on("close",x=>f({code:x,stdout:o}))}catch{f(null)}})}},n_=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function r_(t){return t.replace(n_,"")}import{homedir as i_}from"node:os";import{join as s_}from"node:path";wn();qe();Kr();ne();async function r0(){let t=s_(i_(),".openclaw/openclaw.json");return(await Qn(t))?.gateway?.auth?.token??""}var t0=G("openclaw.config"),o_=[0,5e3,5e3],n0="models.providers.",so="agents.defaults.models",oo=class{command;env;retryDelaysMs;queue=new yn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??o_}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await r()}catch(d){i=d,t0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=at(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`exit ${d}: ${c.trim().slice(0,500)}`))})})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){t0.warn(`${e} failed (best-effort)`,{configPath:r,err:String(i)})}}ensureProvider(e,r){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${n0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${n0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${so}[${e}]`,()=>this.runCli(["config","set",so,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${so}[${e}]`,`${so}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var xe=G("agent-manager"),u_=(t,e,r,i,o,c,d,f,h)=>{switch(t){case"claude-code":{let x={...o?{...Su(o),...Tu(o,d,f)}:{},...h??{},IS_SANDBOX:"1"};return new no({cwd:r,env:x,agentId:i})}case"codex":{let m=[...o?[...Iu(o),...Cu(o,d,f)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],g={...o?Au(o):{},...h??{}},A=!!o;return new ro({cwd:r,agentId:i,...m.length>0?{extraArgs:m}:{},...Object.keys(g).length>0?{env:g}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Ir({command:e,cwd:r,agentId:i,...c?{sessionName:qc(c)}:{}})}};function Wc(t){return t==="claude-code"||t==="codex"}function h_(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(x_(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return k1(t.homeDir,".coze","bridge","task.xml")},async install(t){let r=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await Cx("schtasks",["/Create","/SC","ONLOGON","/TN",ea,"/TR",r,"/RU",t.userName,"/F"]),Od.info("task scheduler entry created",{task:ea,logFile:t.logFile})},async uninstall(t){await Cx("schtasks",["/Delete","/TN",ea,"/F"]).catch(e=>Od.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Od.info("task scheduler entry removed",{task:ea})}}});var Ox={};xa(Ox,{buildContext:()=>B1,getSupervisor:()=>L1,launchdSupervisor:()=>Cd,systemdSupervisor:()=>kd,taskSchedulerSupervisor:()=>Pd});import{homedir as O1,userInfo as P1}from"node:os";function L1(t=process.platform){switch(t){case"darwin":return Cd;case"linux":return kd;case"win32":return Pd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function M1(){let t={};for(let e of N1){let r=process.env[e];r&&(t[e]=r)}return t}function B1(){let t=X();return{nodeBin:process.execPath,entry:vd(t),logFile:t.logFile,homeDir:O1(),userName:P1().username,isRoot:process.getuid?.()===0,env:M1()}}var N1,Px=Je(()=>{"use strict";Ce();qo();Tx();Rx();kx();N1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();nn();var ll=G("acp-installer-warmup"),ig=["claude-code","codex"];async function ul(t={}){let e=t.ensure??er,i=(await Promise.allSettled(ig.map(async o=>{let c=await e(o);ll.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&ll.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}rn();ne();import{readdir as gg}from"node:fs/promises";import{mkdir as ml,writeFile as wl}from"node:fs/promises";import{join as ba}from"node:path";var pg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function rr(t,e,r){await ml(t,{recursive:!0});let i=pg[e],o=ba(t,i);return await wl(o,r??"","utf8"),o}async function _l(t){let e=ba(t,".claude");await ml(e,{recursive:!0});let r=ba(e,"settings.local.json"),i=JSON.stringify({permissions:{defaultMode:"bypassPermissions"},autoCompactWindow:15e4},null,2);return await wl(r,i,"utf8"),r}var et=G("agent-detail-sync"),mg=6e4,wg=5*6e4,as=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await gg(r)}catch(o){et.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}et.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await qe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){et.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){et.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),et.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){et.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){et.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await qe(e,this.opts.paths);if(!i){et.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){et.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let h=this.retryQueue.get(e),p=h?Math.min(h.currentDelay*2,wg):mg;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});return}if(o.agentId&&o.agentId!==e){et.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;if(o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0),o.deployType&&et.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){et.debug("detail sync: no diff",{agentId:e});return}await Ye(i,this.opts.paths),et.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),l&&(await rr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var N0=It(Xl(),1);import{lstat as Mc,mkdir as Bc,readFile as k0,readdir as Ww,rm as Kw,stat as $w,writeFile as zc}from"node:fs/promises";import{dirname as Vw,join as Ot,normalize as Jw,relative as Gc,resolve as Fc,sep as O0}from"node:path";import{Readable as P0}from"node:stream";import{pipeline as L0}from"node:stream/promises";import Ug from"events";import Xe from"fs";import{EventEmitter as yc}from"node:events";import Pu from"node:stream";import{StringDecoder as Gg}from"node:string_decoder";import Mu from"node:path";import pr from"node:fs";import{dirname as em,parse as tm}from"path";import{EventEmitter as dm}from"events";import tc from"assert";import{Buffer as Bn}from"buffer";import*as ru from"zlib";import lm from"zlib";import{posix as cr}from"node:path";import{basename as Bm}from"node:path";import Fs from"fs";import Rt from"fs";import lu from"path";import{win32 as Vm}from"node:path";import mu from"path";import Yu from"node:fs";import uw from"node:assert";import{randomBytes as Xu}from"node:crypto";import re from"node:fs";import Oe from"node:path";import Qu from"fs";import Vs from"node:fs";import gi from"node:path";import it from"node:fs";import ww from"node:fs/promises";import Hs from"node:path";import{join as l0}from"node:path";import rt from"node:fs";import h0 from"node:path";var zg=Object.defineProperty,Fg=(t,e)=>{for(var r in e)zg(t,r,{get:e[r],enumerable:!0})},Ql=typeof process=="object"&&process?process:{stdout:null,stderr:null},Hg=t=>!!t&&typeof t=="object"&&(t instanceof Un||t instanceof Pu||qg(t)||jg(t)),qg=t=>!!t&&typeof t=="object"&&t instanceof yc&&typeof t.pipe=="function"&&t.pipe!==Pu.Writable.prototype.pipe,jg=t=>!!t&&typeof t=="object"&&t instanceof yc&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),fs=Symbol("emittingEnd"),Qr=Symbol("emittedError"),hs=Symbol("closed"),eu=Symbol("read"),xs=Symbol("flush"),tu=Symbol("flushChunk"),pt=Symbol("encoding"),ar=Symbol("decoder"),Ne=Symbol("flowing"),ei=Symbol("paused"),fr=Symbol("resume"),Me=Symbol("buffer"),$e=Symbol("pipes"),Be=Symbol("bufferLength"),Ta=Symbol("bufferPush"),ps=Symbol("bufferShift"),We=Symbol("objectMode"),ve=Symbol("destroyed"),Da=Symbol("error"),Ra=Symbol("emitData"),nu=Symbol("emitEnd"),Ca=Symbol("emitEnd2"),At=Symbol("async"),ka=Symbol("abort"),gs=Symbol("aborted"),ti=Symbol("signal"),Dn=Symbol("dataListeners"),nt=Symbol("discarded"),ni=t=>Promise.resolve().then(t),Wg=t=>t(),Kg=t=>t==="end"||t==="finish"||t==="prefinish",$g=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Vg=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Lu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[fr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Jg=class extends Lu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Zg=t=>!!t.objectMode,Yg=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Un=class extends yc{[Ne]=!1;[ei]=!1;[$e]=[];[Me]=[];[We];[pt];[At];[ar];[Ut]=!1;[on]=!1;[fs]=!1;[hs]=!1;[Qr]=null;[Be]=0;[ve]=!1;[ti];[gs]=!1;[Dn]=0;[nt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Zg(e)?(this[We]=!0,this[pt]=null):Yg(e)?(this[pt]=e.encoding,this[We]=!1):(this[We]=!1,this[pt]=null),this[At]=!!e.async,this[ar]=this[pt]?new Gg(this[pt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[$e]});let{signal:r}=e;r&&(this[ti]=r,r.aborted?this[ka]():r.addEventListener("abort",()=>this[ka]()))}get bufferLength(){return this[Be]}get encoding(){return this[pt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[We]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(t){this[At]=this[At]||!!t}[ka](){this[gs]=!0,this.emit("abort",this[ti]?.reason),this.destroy(this[ti]?.reason)}get aborted(){return this[gs]}set aborted(t){}write(t,e,r){if(this[gs])return!1;if(this[Ut])throw new Error("write after end");if(this[ve])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[At]?ni:Wg;if(!this[We]&&!Buffer.isBuffer(t)){if(Vg(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if($g(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[We]?(this[Ne]&&this[Be]!==0&&this[xs](!0),this[Ne]?this.emit("data",t):this[Ta](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):t.length?(typeof t=="string"&&!(e===this[pt]&&!this[ar]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[pt]&&(t=this[ar].write(t)),this[Ne]&&this[Be]!==0&&this[xs](!0),this[Ne]?this.emit("data",t):this[Ta](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne])}read(t){if(this[ve])return null;if(this[nt]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[Gt](),null;this[We]&&(t=null),this[Me].length>1&&!this[We]&&(this[Me]=[this[pt]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[eu](t||null,this[Me][0]);return this[Gt](),e}[eu](t,e){if(this[We])this[ps]();else{let r=e;t===r.length||t===null?this[ps]():typeof r=="string"?(this[Me][0]=r.slice(t),e=r.slice(0,t),this[Be]-=t):(this[Me][0]=r.subarray(t),e=r.subarray(0,t),this[Be]-=t)}return this.emit("data",e),!this[Me].length&&!this[Ut]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Ut]=!0,this.writable=!1,(this[Ne]||!this[ei])&&this[Gt](),this}[fr](){this[ve]||(!this[Dn]&&!this[$e].length&&(this[nt]=!0),this[ei]=!1,this[Ne]=!0,this.emit("resume"),this[Me].length?this[xs]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[fr]()}pause(){this[Ne]=!1,this[ei]=!0,this[nt]=!1}get destroyed(){return this[ve]}get flowing(){return this[Ne]}get paused(){return this[ei]}[Ta](t){this[We]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[ps](){return this[We]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[xs](t=!1){do;while(this[tu](this[ps]())&&this[Me].length);!t&&!this[Me].length&&!this[Ut]&&this.emit("drain")}[tu](t){return this.emit("data",t),this[Ne]}pipe(t,e){if(this[ve])return t;this[nt]=!1;let r=this[on];return e=e||{},t===Ql.stdout||t===Ql.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[$e].push(e.proxyErrors?new Jg(this,t,e):new Lu(this,t,e)),this[At]?ni(()=>this[fr]()):this[fr]()),t}unpipe(t){let e=this[$e].find(r=>r.dest===t);e&&(this[$e].length===1?(this[Ne]&&this[Dn]===0&&(this[Ne]=!1),this[$e]=[]):this[$e].splice(this[$e].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[nt]=!1,this[Dn]++,!this[$e].length&&!this[Ne]&&this[fr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(Kg(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Qr]){let i=e;this[At]?ni(()=>i.call(this,this[Qr])):i.call(this,this[Qr])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Dn]=this.listeners("data").length,this[Dn]===0&&!this[nt]&&!this[$e].length&&(this[Ne]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Dn]=0,!this[nt]&&!this[$e].length&&(this[Ne]=!1)),e}get emittedEnd(){return this[on]}[Gt](){!this[fs]&&!this[on]&&!this[ve]&&this[Me].length===0&&this[Ut]&&(this[fs]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[hs]&&this.emit("close"),this[fs]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ve&&this[ve])return!1;if(t==="data")return!this[We]&&!r?!1:this[At]?(ni(()=>this[Ra](r)),!0):this[Ra](r);if(t==="end")return this[nu]();if(t==="close"){if(this[hs]=!0,!this[on]&&!this[ve])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Qr]=r,super.emit(Da,r);let o=!this[ti]||this.listeners("error").length?super.emit("error",r):!1;return this[Gt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Gt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Gt](),i}[Ra](t){for(let r of this[$e])r.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[Gt](),e}[nu](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[At]?(ni(()=>this[Ca]()),!0):this[Ca]())}[Ca](){if(this[ar]){let e=this[ar].end();if(e){for(let r of this[$e])r.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[$e])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[We]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[We]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[We])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[pt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(ve,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[nt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Ut])return e();let i,o,c=p=>{this.off("data",l),this.off("end",f),this.off(ve,h),e(),o(p)},l=p=>{this.off("error",c),this.off("end",f),this.off(ve,h),this.pause(),i({value:p,done:!!this[Ut]})},f=()=>{this.off("error",c),this.off("data",l),this.off(ve,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((p,w)=>{o=w,i=p,this.once(ve,h),this.once("error",c),this.once("end",f),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(Da,e),this.off(ve,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Da,e),this.once(ve,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[ve])return t?this.emit("error",t):this.emit(ve),this;this[ve]=!0,this[nt]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[hs]&&e.close(),t?this.emit("error",t):this.emit(ve),this}static get isStream(){return Hg}},Xg=Xe.writev,gn=Symbol("_autoClose"),_t=Symbol("_close"),ri=Symbol("_ended"),ae=Symbol("_fd"),Oa=Symbol("_finished"),Wt=Symbol("_flags"),Pa=Symbol("_flush"),Qa=Symbol("_handleChunk"),ec=Symbol("_makeBuf"),xi=Symbol("_mode"),ms=Symbol("_needDrain"),mr=Symbol("_onerror"),wr=Symbol("_onopen"),La=Symbol("_onread"),hr=Symbol("_onwrite"),mn=Symbol("_open"),wt=Symbol("_path"),un=Symbol("_pos"),Tt=Symbol("_queue"),xr=Symbol("_read"),Na=Symbol("_readSize"),jt=Symbol("_reading"),ii=Symbol("_remain"),Ma=Symbol("_size"),Ts=Symbol("_write"),Rn=Symbol("_writing"),Ds=Symbol("_defaultFlag"),Mn=Symbol("_errored"),bc=class extends Un{[Mn]=!1;[ae];[wt];[Na];[jt]=!1;[Ma];[ii];[gn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Mn]=!1,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[wt]=t,this[Na]=e.readSize||16*1024*1024,this[jt]=!1,this[Ma]=typeof e.size=="number"?e.size:1/0,this[ii]=this[Ma],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[xr]():this[mn]()}get fd(){return this[ae]}get path(){return this[wt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[mn](){Xe.open(this[wt],"r",(t,e)=>this[wr](t,e))}[wr](t,e){t?this[mr](t):(this[ae]=e,this.emit("open",e),this[xr]())}[ec](){return Buffer.allocUnsafe(Math.min(this[Na],this[ii]))}[xr](){if(!this[jt]){this[jt]=!0;let t=this[ec]();if(t.length===0)return process.nextTick(()=>this[La](null,0,t));Xe.read(this[ae],t,0,t.length,null,(e,r,i)=>this[La](e,r,i))}}[La](t,e,r){this[jt]=!1,t?this[mr](t):this[Qa](e,r)&&this[xr]()}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[mr](t){this[jt]=!0,this[_t](),this.emit("error",t)}[Qa](t,e){let r=!1;return this[ii]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ii]<=0)&&(r=!1,this[_t](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ae]=="number"&&this[xr](),!1;case"error":return this[Mn]?!1:(this[Mn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Qg=class extends bc{[mn](){let t=!0;try{this[wr](null,Xe.openSync(this[wt],"r")),t=!1}finally{t&&this[_t]()}}[xr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[ec](),r=e.length===0?0:Xe.readSync(this[ae],e,0,e.length,null);if(!this[Qa](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[_t]()}}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.closeSync(t),this.emit("close")}}},qs=class extends Ug{readable=!1;writable=!0;[Mn]=!1;[Rn]=!1;[ri]=!1;[Tt]=[];[ms]=!1;[wt];[xi];[gn];[ae];[Ds];[Wt];[Oa]=!1;[un];constructor(t,e){e=e||{},super(e),this[wt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[xi]=e.mode===void 0?438:e.mode,this[un]=typeof e.start=="number"?e.start:void 0,this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[un]!==void 0?"r+":"w";this[Ds]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[ae]===void 0&&this[mn]()}emit(t,...e){if(t==="error"){if(this[Mn])return!1;this[Mn]=!0}return super.emit(t,...e)}get fd(){return this[ae]}get path(){return this[wt]}[mr](t){this[_t](),this[Rn]=!0,this.emit("error",t)}[mn](){Xe.open(this[wt],this[Wt],this[xi],(t,e)=>this[wr](t,e))}[wr](t,e){this[Ds]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[mn]()):t?this[mr](t):(this[ae]=e,this.emit("open",e),this[Rn]||this[Pa]())}end(t,e){return t&&this.write(t,e),this[ri]=!0,!this[Rn]&&!this[Tt].length&&typeof this[ae]=="number"&&this[hr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ri]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Rn]||this[Tt].length?(this[Tt].push(t),this[ms]=!0,!1):(this[Rn]=!0,this[Ts](t),!0)}[Ts](t){Xe.write(this[ae],t,0,t.length,this[un],(e,r)=>this[hr](e,r))}[hr](t,e){t?this[mr](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[Tt].length?this[Pa]():(this[Rn]=!1,this[ri]&&!this[Oa]?(this[Oa]=!0,this[_t](),this.emit("finish")):this[ms]&&(this[ms]=!1,this.emit("drain"))))}[Pa](){if(this[Tt].length===0)this[ri]&&this[hr](null,0);else if(this[Tt].length===1)this[Ts](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],Xg(this[ae],t,this[un],(e,r)=>this[hr](e,r))}}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Nu=class extends qs{[mn](){let t;if(this[Ds]&&this[Wt]==="r+")try{t=Xe.openSync(this[wt],this[Wt],this[xi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[mn]();throw e}else t=Xe.openSync(this[wt],this[Wt],this[xi]);this[wr](null,t)}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.closeSync(t),this.emit("close")}}[Ts](t){let e=!0;try{this[hr](null,Xe.writeSync(this[ae],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[_t]()}catch{}}}},nm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),rm=t=>!!t.sync&&!!t.file,im=t=>!t.sync&&!!t.file,sm=t=>!!t.sync&&!t.file,om=t=>!t.sync&&!t.file,am=t=>!!t.file,cm=t=>nm.get(t)||t,Ec=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=cm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},vi=(t,e,r,i,o)=>Object.assign((c=[],l,f)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(f=l,l=void 0),l=l?Array.from(l):[];let h=Ec(c);if(o?.(h,l),rm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,l)}else if(im(h)){let p=e(h,l);return f?p.then(()=>f(),f):p}else if(sm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,l)}else if(om(h)){if(typeof f=="function")throw new TypeError("callback only supported with file option");return i(h,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),um=lm.constants||{ZLIB_VERNUM:4736},kt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},um)),fm=Bn.concat,iu=Object.getOwnPropertyDescriptor(Bn,"concat"),hm=t=>t,Ba=iu?.writable===!0||iu?.set!==void 0?t=>{Bn.concat=t?hm:fm}:t=>{},zn=Symbol("_superWrite"),ws=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},za=Symbol("flushFlag"),vc=class extends Un{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof ru[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new ru[e](t)}catch(r){throw new ws(r,this.constructor)}this.#o=r=>{this.#e||(this.#e=!0,this.close(),this.emit("error",r))},this.#t?.on("error",r=>this.#o(new ws(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return tc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Bn.alloc(0),{[za]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[zn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Bn.from(t,e)),this.#e)return;tc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Ba(!0);let l;try{let h=typeof t[za]=="number"?t[za]:this.#r;l=this.#t._processChunk(t,h),Ba(!1)}catch(h){Ba(!1),this.#o(new ws(h,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new ws(h,this.write)));let f;if(l)if(Array.isArray(l)&&l.length>0){let h=l[0];f=this[zn](Bn.from(h));for(let p=1;p<l.length;p++)f=this[zn](l[p])}else f=this[zn](Bn.from(l));return r&&r(),f}},Bu=class extends vc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||kt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||kt.Z_FINISH,t.fullFlushFlag=kt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(kt.Z_SYNC_FLUSH),tc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},xm=class extends Bu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[zn](t){return this.#e?(this.#e=!1,t[9]=255,super[zn](t)):super[zn](t)}},pm=class extends Bu{constructor(t){super(t,"Unzip")}},zu=class extends vc{constructor(t,e){t=t||{},t.flush=t.flush||kt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||kt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=kt.BROTLI_OPERATION_FLUSH,super(t,e)}},gm=class extends zu{constructor(t){super(t,"BrotliCompress")}},mm=class extends zu{constructor(t){super(t,"BrotliDecompress")}},Fu=class extends vc{constructor(t,e){t=t||{},t.flush=t.flush||kt.ZSTD_e_continue,t.finishFlush=t.finishFlush||kt.ZSTD_e_end,t.fullFlushFlag=kt.ZSTD_e_flush,super(t,e)}},wm=class extends Fu{constructor(t){super(t,"ZstdCompress")}},_m=class extends Fu{constructor(t){super(t,"ZstdDecompress")}},ym=(t,e)=>{if(Number.isSafeInteger(t))t<0?Em(t,e):bm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},bm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Em=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Uu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Gu(o))}},vm=t=>{let e=t[0],r=e===128?Im(t.subarray(1,t.length)):e===255?Sm(t):null;if(r===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(r))throw Error("parsed number outside of javascript safe integer range");return r},Sm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Uu(c):c===0?l=c:(i=!0,l=Gu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Im=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},Uu=t=>(255^t)&255,Gu=t=>(255^t)+1&255,Am={};Fg(Am,{code:()=>Sc,isCode:()=>Rs,isName:()=>Tm,name:()=>js});var Rs=t=>js.has(t),Tm=t=>Sc.has(t),js=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Sc=new Map(Array.from(js).map(t=>[t[1],t[0]])),Fn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");this.path=r?.path??Cn(t,e,100),this.mode=r?.mode??i?.mode??fn(t,e+100,8),this.uid=r?.uid??i?.uid??fn(t,e+108,8),this.gid=r?.gid??i?.gid??fn(t,e+116,8),this.size=r?.size??i?.size??fn(t,e+124,12),this.mtime=r?.mtime??i?.mtime??Fa(t,e+136,12),this.cksum=fn(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Cn(t,e+156,1);if(Rs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Cn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Cn(t,e+265,32),this.gname=r?.gname??i?.gname??Cn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??fn(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let l=Cn(t,e+345,155);this.path=l+"/"+this.path}else{let l=Cn(t,e+345,130);l&&(this.path=l+"/"+this.path),this.atime=r?.atime??i?.atime??Fa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Fa(t,e+488,12)}let c=256;for(let l=e;l<e+148;l++)c+=t[l];for(let l=e+156;l<e+512;l++)c+=t[l];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=Dm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=kn(t,e,100,o)||this.needPax,this.needPax=hn(t,e+100,8,this.mode)||this.needPax,this.needPax=hn(t,e+108,8,this.uid)||this.needPax,this.needPax=hn(t,e+116,8,this.gid)||this.needPax,this.needPax=hn(t,e+124,12,this.size)||this.needPax,this.needPax=Ua(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=kn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=kn(t,e+265,32,this.uname)||this.needPax,this.needPax=kn(t,e+297,32,this.gname)||this.needPax,this.needPax=hn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=hn(t,e+337,8,this.devmin)||this.needPax,this.needPax=kn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=kn(t,e+345,155,c)||this.needPax:(this.needPax=kn(t,e+345,130,c)||this.needPax,this.needPax=Ua(t,e+476,12,this.atime)||this.needPax,this.needPax=Ua(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let f=e;f<e+148;f++)l+=t[f];for(let f=e+156;f<e+512;f++)l+=t[f];return this.cksum=l,hn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:js.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Sc.get(t));if(Rs(e)||e==="Unsupported")this.#e=e;else if(Rs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Dm=(t,e)=>{let r=t,i="",o,c=cr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=cr.dirname(r),r=cr.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=cr.join(cr.basename(i),r),i=cr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Cn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Fa=(t,e,r)=>Rm(fn(t,e,r)),Rm=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?vm(t.subarray(e,e+r)):km(t,e,r),Cm=t=>isNaN(t)?void 0:t,km=(t,e,r)=>Cm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Om={12:8589934591,8:2097151},hn=(t,e,r,i)=>i===void 0?!1:i>Om[r]||i<0?(ym(i,t.subarray(e,e+r)),!0):(Pm(t,e,r,i),!1),Pm=(t,e,r,i)=>t.write(Lm(i,r),e,r,"ascii"),Lm=(t,e)=>Nm(Math.floor(t).toString(8),e),Nm=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ua=(t,e,r,i)=>i===void 0?!1:hn(t,e,r,i.getTime()/1e3),Mm=new Array(156).join("\0"),kn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Mm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),zs=class Hu{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Fn({path:("PaxHeader/"+Bm(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
+ `,c=Buffer.byteLength(o),l=Math.floor(Math.log(c)/Math.log(10))+1;return c+l>=Math.pow(10,l)&&(l+=1),l+c+o}static parse(e,r,i=!1){return new Hu(zm(Fm(e),r),i)}},zm=(t,e)=>e?Object.assign({},e,t):t,Fm=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(Um,Object.create(null)),Um=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},Gm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Y=Gm!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),qu=class extends Un{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=Y(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?Y(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=Y(t.path)),t.linkpath&&(t.linkpath=Y(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Ws=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},Hm=1024*1024,nc=Buffer.from([31,139]),rc=Buffer.from([40,181,47,253]),qm=Math.max(nc.length,rc.length),ct=Symbol("state"),On=Symbol("writeEntry"),Ht=Symbol("readEntry"),Ga=Symbol("nextEntry"),su=Symbol("processEntry"),Dt=Symbol("extendedHeader"),si=Symbol("globalExtendedHeader"),an=Symbol("meta"),ou=Symbol("emitMeta"),fe=Symbol("buffer"),qt=Symbol("queue"),cn=Symbol("ended"),Ha=Symbol("emittedEnd"),Pn=Symbol("emit"),Ae=Symbol("unzip"),_s=Symbol("consumeChunk"),ys=Symbol("consumeChunkSub"),qa=Symbol("consumeBody"),au=Symbol("consumeMeta"),cu=Symbol("consumeHeader"),oi=Symbol("consuming"),ja=Symbol("bufferConcat"),bs=Symbol("maybeEnd"),dr=Symbol("writing"),dn=Symbol("aborted"),Es=Symbol("onDone"),Ln=Symbol("sawValidEntry"),vs=Symbol("sawNullBlock"),Ss=Symbol("sawEOF"),du=Symbol("closeStream"),jm=()=>!0,Ei=class extends dm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[qt]=[];[fe];[Ht];[On];[ct]="begin";[an]="";[Dt];[si];[cn]=!1;[Ae];[dn]=!1;[Ln];[vs]=!1;[Ss]=!1;[dr]=!1;[oi]=!1;[Ha]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Es,()=>{(this[ct]==="begin"||this[Ln]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Es,t.ondone):this.on(Es,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Hm,this.filter=typeof t.filter=="function"?t.filter:jm;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[du]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Ws(this,t,e,r)}[cu](t,e){this[Ln]===void 0&&(this[Ln]=!1);let r;try{r=new Fn(t,e,this[Dt],this[si])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[vs]?(this[Ss]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Pn]("eof")):(this[vs]=!0,this[Pn]("nullBlock"));else if(this[vs]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[On]=new qu(r,this[Dt],this[si]);if(!this[Ln])if(o.remain){let c=()=>{o.invalid||(this[Ln]=!0)};o.on("end",c)}else this[Ln]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Pn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[ct]="meta"):(this[Dt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Pn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[Ht]?this[qt].push(o):(this[qt].push(o),this[Ga]())))}}}[du](){queueMicrotask(()=>this.emit("close"))}[su](t){let e=!0;if(!t)this[Ht]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ht]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ga]()),e=!1);return e}[Ga](){do;while(this[su](this[qt].shift()));if(this[qt].length===0){let t=this[Ht];!t||t.flowing||t.size===t.remain?this[dr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[qa](t,e){let r=this[On];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[ct]="header",this[On]=void 0,r.end()),o.length}[au](t,e){let r=this[On],i=this[qa](t,e);return!this[On]&&r&&this[ou](r),i}[Pn](t,e,r){this[qt].length===0&&!this[Ht]?this.emit(t,e,r):this[qt].push([t,e,r])}[ou](t){switch(this[Pn]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Dt]=zs.parse(this[an],this[Dt],!1);break;case"GlobalExtendedHeader":this[si]=zs.parse(this[an],this[si],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Dt]??Object.create(null);this[Dt]=e,e.path=this[an].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Dt]||Object.create(null);this[Dt]=e,e.linkpath=this[an].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[dn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[dn])return r?.(),!1;if((this[Ae]===void 0||this.brotli===void 0&&this[Ae]===!1)&&t){if(this[fe]&&(t=Buffer.concat([this[fe],t]),this[fe]=void 0),t.length<qm)return this[fe]=t,r?.(),!0;for(let l=0;this[Ae]===void 0&&l<nc.length;l++)t[l]!==nc[l]&&(this[Ae]=!1);let o=!1;if(this[Ae]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<rc.length;l++)if(t[l]!==rc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ae]===!1&&c)if(t.length<512)if(this[cn])this.brotli=!0;else return this[fe]=t,r?.(),!0;else try{new Fn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ae]===void 0||this[Ae]===!1&&(this.brotli||o)){let l=this[cn];this[cn]=!1,this[Ae]=this[Ae]===void 0?new pm({}):o?new _m({}):new mm({}),this[Ae].on("data",h=>this[_s](h)),this[Ae].on("error",h=>this.abort(h)),this[Ae].on("end",()=>{this[cn]=!0,this[_s]()}),this[dr]=!0;let f=!!this[Ae][l?"end":"write"](t);return this[dr]=!1,r?.(),f}}this[dr]=!0,this[Ae]?this[Ae].write(t):this[_s](t),this[dr]=!1;let i=this[qt].length>0?!1:this[Ht]?this[Ht].flowing:!0;return!i&&this[qt].length===0&&this[Ht]?.once("drain",()=>this.emit("drain")),r?.(),i}[ja](t){t&&!this[dn]&&(this[fe]=this[fe]?Buffer.concat([this[fe],t]):t)}[bs](){if(this[cn]&&!this[Ha]&&!this[dn]&&!this[oi]){this[Ha]=!0;let t=this[On];if(t&&t.blockRemain){let e=this[fe]?this[fe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[fe]&&t.write(this[fe]),t.end()}this[Pn](Es)}}[_s](t){if(this[oi]&&t)this[ja](t);else if(!t&&!this[fe])this[bs]();else if(t){if(this[oi]=!0,this[fe]){this[ja](t);let e=this[fe];this[fe]=void 0,this[ys](e)}else this[ys](t);for(;this[fe]&&this[fe]?.length>=512&&!this[dn]&&!this[Ss];){let e=this[fe];this[fe]=void 0,this[ys](e)}this[oi]=!1}(!this[fe]||this[cn])&&this[bs]()}[ys](t){let e=0,r=t.length;for(;e+512<=r&&!this[dn]&&!this[Ss];)switch(this[ct]){case"begin":case"header":this[cu](t,e),e+=512;break;case"ignore":case"body":e+=this[qa](t,e);break;case"meta":e+=this[au](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<r&&(this[fe]=this[fe]?Buffer.concat([t.subarray(e),this[fe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[dn]||(this[Ae]?(t&&this[Ae].write(t),this[Ae].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[bs]())),this}},pi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},Wm=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},ju=(t,e)=>{let r=new Map(e.map(c=>[pi(c),!0])),i=t.filter,o=(c,l="")=>{let f=l||tm(c).root||".",h;if(c===f)h=!1;else{let p=r.get(c);h=p!==void 0?p:o(em(c),f)}return r.set(c,h),h};t.filter=i?(c,l)=>i(c,l)&&o(pi(c)):c=>o(pi(c))},Km=t=>{let e=new Ei(t),r=t.file,i;try{i=pr.openSync(r,"r");let o=pr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),f=pr.readSync(i,l,0,o.size,0);e.end(f===l.byteLength?l:l.subarray(0,f))}else{let l=0,f=Buffer.allocUnsafe(c);for(;l<o.size;){let h=pr.readSync(i,f,0,c,l);if(h===0)break;l+=h,e.write(f.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{pr.closeSync(i)}catch{}}},$m=(t,e)=>{let r=new Ei(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),pr.stat(o,(f,h)=>{if(f)l(f);else{let p=new bc(o,{readSize:i,size:h.size});p.on("error",l),p.pipe(r)}})})},_r=vi(Km,$m,t=>new Ei(t),t=>new Ei(t),(t,e)=>{e?.length&&ju(t,e),t.noResume||Wm(t)}),Wu=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Jm,parse:uu}=Vm,Ic=t=>{let e="",r=uu(t);for(;Jm(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=uu(t)}return[e,t]},Ks=["|","<",">","?",":"],Ac=Ks.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Zm=new Map(Ks.map((t,e)=>[t,Ac[e]])),Ym=new Map(Ac.map((t,e)=>[t,Ks[e]])),fu=t=>Ks.reduce((e,r)=>e.split(r).join(Zm.get(r)),t),Xm=t=>Ac.reduce((e,r)=>e.split(r).join(Ym.get(r)),t),Ku=(t,e)=>e?(t=Y(t).replace(/^\.(\/|$)/,""),pi(e)+"/"+t):Y(t),Qm=16*1024*1024,hu=Symbol("process"),xu=Symbol("file"),pu=Symbol("directory"),ic=Symbol("symlink"),gu=Symbol("hardlink"),ai=Symbol("header"),Cs=Symbol("read"),sc=Symbol("lstat"),ks=Symbol("onlstat"),oc=Symbol("onread"),ac=Symbol("onreadlink"),cc=Symbol("openfile"),dc=Symbol("onopenfile"),xn=Symbol("close"),Us=Symbol("mode"),lc=Symbol("awaitDrain"),Wa=Symbol("ondrain"),Ct=Symbol("prefix"),$u=class extends Un{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Ec(e);super(),this.path=Y(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Qm,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Y(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Y(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Ic(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Xm(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Y(r.absolute||lu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[ks](o):this[sc]()}warn(t,e,r={}){return Ws(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[sc](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[ks](e)})}[ks](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=nw(t),this.emit("stat",t),this[hu]()}[hu](){switch(this.type){case"File":return this[xu]();case"Directory":return this[pu]();case"SymbolicLink":return this[ic]();default:return this.end()}}[Us](t){return Wu(t,this.type==="Directory",this.portable)}[Ct](t){return Ku(t,this.prefix)}[ai](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Fn({path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,mode:this[Us](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new zs({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[pu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ai](),this.end()}[ic](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[ac](e)})}[ac](t){this.linkpath=Y(t),this[ai](),this.end()}[gu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Y(lu.relative(this.cwd,t)),this.stat.size=0,this[ai](),this.end()}[xu](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[gu](e);this.linkCache.set(t,this.absolute)}if(this[ai](),this.stat.size===0)return this.end();this[cc]()}[cc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[dc](e)})}[dc](t){if(this.fd=t,this.#e)return this[xn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Cs]()}[Cs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Rt.read(t,e,r,i,o,(c,l)=>{if(c)return this[xn](()=>this.emit("error",c));this[oc](l)})}[xn](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[oc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[xn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[xn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Wa]():this[lc](()=>this[Wa]())}[lc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Wa](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[xn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Cs]()}},ew=class extends $u{sync=!0;[sc](){this[ks](Rt.lstatSync(this.absolute))}[ic](){this[ac](Rt.readlinkSync(this.absolute))}[cc](){this[dc](Rt.openSync(this.absolute,"r"))}[Cs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let l=Rt.readSync(e,r,i,o,c);this[oc](l),t=!1}finally{if(t)try{this[xn](()=>{})}catch{}}}[lc](t){t()}[xn](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},tw=class extends Un{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Ws(this,t,e,r)}constructor(t,e={}){let r=Ec(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=Y(t.path),this.mode=t.mode!==void 0?this[Us](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?Y(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,f]=Ic(this.path);l&&typeof f=="string"&&(this.path=f,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Fn({path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new zs({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Ct](t){return Ku(t,this.prefix)}[Us](t){return Wu(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},nw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",rw=class gr{tail;head;length=0;static create(e=[]){return new gr(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)sw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)ow(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new gr;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new gr;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new gr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new gr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<r;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=iw(this,o,l);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function iw(t,e,r){let i=e,o=e?e.next:t.head,c=new Tc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function sw(t,e){t.tail=new Tc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function ow(t,e){t.head=new Tc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Tc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},wu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},_u=Buffer.alloc(1024),Os=Symbol("onStat"),ci=Symbol("ended"),gt=Symbol("queue"),di=Symbol("queue"),ln=Symbol("current"),Nn=Symbol("process"),li=Symbol("processing"),Is=Symbol("processJob"),mt=Symbol("jobs"),Ka=Symbol("jobDone"),Ps=Symbol("addFSEntry"),yu=Symbol("addTarEntry"),uc=Symbol("stat"),fc=Symbol("readdir"),Ls=Symbol("onreaddir"),Ns=Symbol("pipe"),bu=Symbol("entry"),$a=Symbol("entryOpt"),Ms=Symbol("writeEntryClass"),Vu=Symbol("write"),Va=Symbol("ondrain"),$s=class extends Un{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ms];onWriteEntry;[gt];[di]=new Map;[mt]=0;[li]=!1;[ci]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Y(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Ms]=$u,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new xm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new wm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[Va]()),this.on("resume",()=>e.resume())}else this.on("drain",this[Va]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[gt]=new rw,this[mt]=0,this.jobs=Number(t.jobs)||4,this[li]=!1,this[ci]=!1}[Vu](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[ci]=!0,this[Nn](),r&&r(),this}write(t){if(this[ci])throw new Error("write after end");return t instanceof qu?this[yu](t):this[Ps](t),this.flowing}[yu](t){let e=Y(mu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new wu(t.path,e);r.entry=new tw(t,this[$a](r)),r.entry.on("end",()=>this[Ka](r)),this[mt]+=1,this[gt].push(r)}this[Nn]()}[Ps](t){let e=Y(mu.resolve(this.cwd,t));this[gt].push(new wu(t,e)),this[Nn]()}[uc](t){t.pending=!0,this[mt]+=1;let e=this.follow?"stat":"lstat";Fs[e](t.absolute,(r,i)=>{t.pending=!1,this[mt]-=1,r?this.emit("error",r):this[Os](t,i)})}[Os](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[ln])this[Is](t);else{let r=`${e.dev}:${e.ino}`,i=this[di].get(r);i?i.push(t):this[di].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Nn]()}[fc](t){t.pending=!0,this[mt]+=1,Fs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[mt]-=1,e)return this.emit("error",e);this[Ls](t,r)})}[Ls](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Nn]()}[Nn](){if(!this[li]){this[li]=!0;for(let t=this[gt].head;t&&this[mt]<this.jobs;t=t.next)if(this[Is](t.value),t.value.ignore){let e=t.next;this[gt].removeNode(t),t.next=e}this[li]=!1,this[ci]&&this[gt].length===0&&this[mt]===0&&(this.zip?this.zip.end(_u):(super.write(_u),super.end()))}}get[ln](){return this[gt]&&this[gt].head&&this[gt].head.value}[Ka](t){this[gt].shift(),this[mt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[di].get(r);if(i){this[di].delete(r);for(let o of i)o.pending=!1,this[Is](o)}}this[Nn]()}[Is](t){if(t.pending&&t.pendingLink&&t===this[ln]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[ln]&&!t.piped&&this[Ns](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Os](t,e):this[uc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Ls](t,e):this[fc](t),!t.readdir)return}if(t.entry=this[bu](t),!t.entry){t.ignore=!0;return}t===this[ln]&&!t.piped&&this[Ns](t)}}}[$a](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[bu](t){this[mt]+=1;try{return new this[Ms](t.path,this[$a](t)).on("end",()=>this[Ka](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[Va](){this[ln]&&this[ln].entry&&this[ln].entry.resume()}[Ns](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ps](c+i)});let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",i=>{r.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){Ws(this,t,e,r)}},Dc=class extends $s{sync=!0;constructor(t){super(t),this[Ms]=ew}pause(){}resume(){}[uc](t){let e=this.follow?"statSync":"lstatSync";this[Os](t,Fs[e](t.absolute))}[fc](t){this[Ls](t,Fs.readdirSync(t.absolute))}[Ns](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ps](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[Vu](i)})}},aw=(t,e)=>{let r=new Dc(t),i=new Nu(t.file,{mode:t.mode||438});r.pipe(i),Ju(r,e)},cw=(t,e)=>{let r=new $s(t),i=new qs(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),r.on("error",l)});return Zu(r,e).catch(c=>r.emit("error",c)),o},Ju=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?_r({file:Mu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Zu=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await _r({file:Mu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},dw=(t,e)=>{let r=new Dc(t);return Ju(r,e),r},lw=(t,e)=>{let r=new $s(t);return Zu(r,e).catch(i=>r.emit("error",i)),r},_2=vi(aw,cw,dw,lw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),fw=process.env.__FAKE_PLATFORM__||process.platform,e0=fw==="win32",{O_CREAT:t0,O_NOFOLLOW:Eu,O_TRUNC:n0,O_WRONLY:r0}=Qu.constants,i0=Number(process.env.__FAKE_FS_O_FILENAME__)||Qu.constants.UV_FS_O_FILEMAP||0,hw=e0&&!!i0,xw=512*1024,pw=i0|n0|t0|r0,vu=!e0&&typeof Eu=="number"?Eu|n0|t0|r0:null,s0=vu!==null?()=>vu:hw?t=>t<xw?pw:"w":()=>"w",hc=(t,e,r)=>{try{return Vs.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Gs=(t,e,r,i)=>{Vs.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},gw=(t,e,r,i,o)=>{if(e.isDirectory())o0(gi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=gi.resolve(t,e.name);Gs(l,r,i,o)});else{let c=gi.resolve(t,e.name);Gs(c,r,i,o)}},o0=(t,e,r,i)=>{Vs.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return Gs(t,e,r,i);let l=c.length,f=null,h=p=>{if(!f){if(p)return i(f=p);if(--l===0)return Gs(t,e,r,i)}};for(let p of c)gw(t,p,e,r,h)})},mw=(t,e,r,i)=>{e.isDirectory()&&a0(gi.resolve(t,e.name),r,i),hc(gi.resolve(t,e.name),r,i)},a0=(t,e,r)=>{let i;try{i=Vs.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return hc(t,e,r);throw c}for(let o of i)mw(t,o,e,r);return hc(t,e,r)},c0=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},Js=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},_w=(t,e)=>{it.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new c0(t,r?.code||"ENOTDIR")),e(r)})},yw=(t,e,r)=>{t=Y(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,f=e.gid,h=typeof l=="number"&&typeof f=="number"&&(l!==e.processUid||f!==e.processGid),p=e.preserve,w=e.unlink,E=Y(e.cwd),T=(v,I)=>{v?r(v):I&&h?o0(I,l,f,S=>T(S)):c?it.chmod(t,o,r):r()};if(t===E)return _w(t,T);if(p)return ww.mkdir(t,{mode:o,recursive:!0}).then(v=>T(null,v??void 0),T);let _=Y(Hs.relative(E,t)).split("/");xc(E,_,o,w,E,void 0,T)},xc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let f=e.shift(),h=Y(Hs.resolve(t+"/"+f));it.mkdir(h,r,d0(h,e,r,i,o,c,l))},d0=(t,e,r,i,o,c,l)=>f=>{f?it.lstat(t,(h,p)=>{if(h)h.path=h.path&&Y(h.path),l(h);else if(p.isDirectory())xc(t,e,r,i,o,c,l);else if(i)it.unlink(t,w=>{if(w)return l(w);it.mkdir(t,r,d0(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new Js(t,t+"/"+e.join("/")));l(f)}}):(c=c||t,xc(t,e,r,i,o,c,l))},bw=t=>{let e=!1,r;try{e=it.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new c0(t,r??"ENOTDIR")}},Ew=(t,e)=>{t=Y(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,f=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),h=e.preserve,p=e.unlink,w=Y(e.cwd),E=v=>{v&&f&&a0(v,c,l),o&&it.chmodSync(t,i)};if(t===w)return bw(w),E();if(h)return E(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let T=Y(Hs.relative(w,t)).split("/"),_;for(let v=T.shift(),I=w;v&&(I+="/"+v);v=T.shift()){I=Y(Hs.resolve(I));try{it.mkdirSync(I,i),_=_||I}catch{let S=it.lstatSync(I);if(S.isDirectory())continue;if(p){it.unlinkSync(I),it.mkdirSync(I,i),_=_||I;continue}else if(S.isSymbolicLink())return new Js(I,I+"/"+T.join("/"))}}return E(_)},Ja=Object.create(null),Su=1e4,lr=new Set,vw=t=>{lr.has(t)?lr.delete(t):Ja[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),lr.add(t);let e=Ja[t],r=lr.size-Su;if(r>Su/10){for(let i of lr)if(lr.delete(i),delete Ja[i],--r<=0)break}return e},Sw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Iw=Sw==="win32",Aw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=l0(i,r)),e.push(r||"/"),e},[]),Tw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Iw?["win32 parallelization disabled"]:t.map(i=>pi(l0(vw(i))));let r=new Set(t.map(i=>Aw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let f=l[1];if(!f){this.#e.delete(c);continue}if(l.shift(),typeof f=="function")o.add(f);else for(let h of f)o.add(h)}for(let c of i){let l=this.#e.get(c),f=l?.[0];if(!(!l||!(f instanceof Set)))if(f.size===1&&l.length===1){this.#e.delete(c);continue}else if(f.size===1){l.shift();let h=l[0];typeof h=="function"&&o.add(h)}else f.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Dw=()=>process.umask(),Iu=Symbol("onEntry"),pc=Symbol("checkFs"),Au=Symbol("checkFs2"),gc=Symbol("isReusable"),dt=Symbol("makeFs"),mc=Symbol("file"),wc=Symbol("directory"),Bs=Symbol("link"),Tu=Symbol("symlink"),Du=Symbol("hardlink"),hi=Symbol("ensureNoSymlink"),Ru=Symbol("unsupported"),Cu=Symbol("checkPath"),Za=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),ze=Symbol("onError"),As=Symbol("pending"),ku=Symbol("pend"),ur=Symbol("unpend"),Ya=Symbol("ended"),Xa=Symbol("maybeClose"),_c=Symbol("skip"),mi=Symbol("doChown"),wi=Symbol("uid"),_i=Symbol("gid"),yi=Symbol("checkedCwd"),Rw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,bi=Rw==="win32",Cw=1024,kw=(t,e)=>{if(!bi)return re.unlink(t,e);let r=t+".DELETE."+Xu(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},Ow=t=>{if(!bi)return re.unlinkSync(t);let e=t+".DELETE."+Xu(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Ou=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Rc=class extends Ei{[Ya]=!1;[yi]=!1;[As]=0;reservations=new Tw;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[Ya]=!0,this[Xa]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:Cw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||bi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Y(Oe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Dw():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[Iu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[Xa](){this[Ya]&&this[As]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Za](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Ic(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||bi&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let f=Oe.posix.dirname(t.path),h=Oe.posix.normalize(Oe.posix.join(f,l.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Cu](t){let e=Y(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Y(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[Za](t,"path")||!this[Za](t,"linkpath"))return!1;if(t.absolute=Oe.isAbsolute(t.path)?Y(Oe.resolve(t.path)):Y(Oe.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Y(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Oe.win32.parse(String(t.absolute));t.absolute=i+fu(String(t.absolute).slice(i.length));let{root:o}=Oe.win32.parse(t.path);t.path=o+fu(t.path.slice(o.length))}return!0}[Iu](t){if(!this[Cu](t))return t.resume();switch(uw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[pc](t);default:return this[Ru](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[ur](),e.resume())}[pn](t,e,r){yw(Y(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[mi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[wi](t){return Ou(this.uid,t.uid,this.processUid)}[_i](t){return Ou(this.gid,t.gid,this.processGid)}[mc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new qs(String(t.absolute),{flags:s0(t.size),mode:r,autoClose:!1});i.on("error",f=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[ze](f,t),e()});let o=1,c=f=>{if(f){i.fd&&re.close(i.fd,()=>{}),this[ze](f,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[ze](h,t):this[ur](),e()})};i.on("finish",()=>{let f=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,w=t.mtime;re.futimes(h,p,w,E=>E?re.utimes(f,p,w,T=>c(T&&E)):c())}if(typeof h=="number"&&this[mi](t)){o++;let p=this[wi](t),w=this[_i](t);typeof p=="number"&&typeof w=="number"&&re.fchown(h,p,w,E=>E?re.chown(f,p,w,T=>c(T&&E)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",f=>{this[ze](f,t),e()}),t.pipe(l)),l.pipe(i)}[wc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[pn](String(t.absolute),r,i=>{if(i){this[ze](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[ur](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[mi](t)&&(o++,re.chown(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)),c)),c()})}[Ru](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Tu](t,e){let r=Y(Oe.relative(this.cwd,Oe.resolve(Oe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[hi](t,this.cwd,r,()=>this[Bs](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Du](t,e){let r=Y(Oe.resolve(this.cwd,String(t.linkpath))),i=Y(String(t.linkpath)).split("/");this[hi](t,this.cwd,i,()=>this[Bs](t,r,"link",e),o=>{this[ze](o,t),e()})}[hi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Oe.resolve(e,c);re.lstat(l,(f,h)=>{if(f)return i();if(h?.isSymbolicLink())return o(new Js(l,Oe.resolve(l,r.join("/"))));this[hi](t,l,r,i,o)})}[ku](){this[As]++}[ur](){this[As]--,this[Xa]()}[_c](t){this[ur](),t.resume()}[gc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!bi}[pc](t){this[ku]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Au](t,r))}[Au](t,e){let r=l=>{e(l)},i=()=>{this[pn](this.cwd,this.dmode,l=>{if(l){this[ze](l,t),r();return}this[yi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Y(Oe.dirname(String(t.absolute)));if(l!==this.cwd)return this[pn](l,this.dmode,f=>{if(f){this[ze](f,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,f)=>{if(f&&(this.keep||this.newer&&f.mtime>(t.mtime??f.mtime))){this[_c](t),r();return}if(l||this[gc](t,f))return this[dt](null,t,r);if(f.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(f.mode&4095)!==t.mode,p=w=>this[dt](w??null,t,r);return h?re.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),h=>this[dt](h??null,t,r))}if(t.absolute===this.cwd)return this[dt](null,t,r);kw(String(t.absolute),h=>this[dt](h??null,t,r))})};this[yi]?o():i()}[dt](t,e,r){if(t){this[ze](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[mc](e,r);case"Link":return this[Du](e,r);case"SymbolicLink":return this[Tu](e,r);case"Directory":case"GNUDumpDir":return this[wc](e,r)}}[Bs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[ur](),t.resume()),i()})}},ui=t=>{try{return[null,t()]}catch(e){return[e,null]}},u0=class extends Rc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[pc](t){if(!this[yi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[yi]=!0}if(t.absolute!==this.cwd){let o=Y(Oe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[pn](o,this.dmode);if(c)return this[ze](c,t)}}let[e,r]=ui(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[_c](t);if(e||this[gc](t,r))return this[dt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?ui(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](l,t)}let[o]=ui(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:ui(()=>Ow(String(t.absolute)));this[dt](i,t)}[mc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let f;try{re.closeSync(o)}catch(h){f=h}(l||f)&&this[ze](l||f,t),e()},o;try{o=re.openSync(String(t.absolute),s0(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[ze](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(f){i(f)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let f=t.atime||new Date,h=t.mtime;try{re.futimesSync(o,f,h)}catch(p){try{re.utimesSync(String(t.absolute),f,h)}catch{l=p}}}if(this[mi](t)){let f=this[wi](t),h=this[_i](t);try{re.fchownSync(o,Number(f),Number(h))}catch(p){try{re.chownSync(String(t.absolute),Number(f),Number(h))}catch{l=l||p}}}i(l)})}[wc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[pn](String(t.absolute),r);if(i){this[ze](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[mi](t))try{re.chownSync(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)))}catch{}e(),t.resume()}[pn](t,e){try{return Ew(Y(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[hi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Oe.resolve(c,l);let[f,h]=ui(()=>re.lstatSync(c));if(f)return i();if(h.isSymbolicLink())return o(new Js(c,Oe.resolve(e,r.join("/"))))}i()}[Bs](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[ze](c,t)}}},Pw=t=>{let e=new u0(t),r=t.file,i=Yu.statSync(r),o=t.maxReadSize||16*1024*1024;new Qg(r,{readSize:o,size:i.size}).pipe(e)},Lw=(t,e)=>{let r=new Rc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),Yu.stat(o,(f,h)=>{if(f)l(f);else{let p=new bc(o,{readSize:i,size:h.size});p.on("error",l),p.pipe(r)}})})},f0=vi(Pw,Lw,t=>new u0(t),t=>new Rc(t),(t,e)=>{e?.length&&ju(t,e)}),Nw=(t,e)=>{let r=new Dc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw h}let l=rt.fstatSync(o),f=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let w=0,E=0;w<512;w+=E){if(E=rt.readSync(o,f,w,f.length-w,c+w),c===0&&f[0]===31&&f[1]===139)throw new Error("cannot append to compressed archives");if(!E)break e}let h=new Fn(f);if(!h.cksumValid)break;let p=512*Math.ceil((h.size||0)/512);if(c+p+512>l.size)break;c+=p,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,Mw(t,r,c,o,e)}finally{if(i)try{rt.closeSync(o)}catch{}}},Mw=(t,e,r,i,o)=>{let c=new Nu(t.file,{fd:i,start:r});e.pipe(c),zw(e,o)},Bw=(t,e)=>{e=Array.from(e);let r=new $s(t),i=(o,c,l)=>{let f=(T,_)=>{T?rt.close(o,v=>l(T)):l(null,_)},h=0;if(c===0)return f(null,0);let p=0,w=Buffer.alloc(512),E=(T,_)=>{if(T||_===void 0)return f(T);if(p+=_,p<512&&_)return rt.read(o,w,p,w.length-p,h+p,E);if(h===0&&w[0]===31&&w[1]===139)return f(new Error("cannot append to compressed archives"));if(p<512)return f(null,h);let v=new Fn(w);if(!v.cksumValid)return f(null,h);let I=512*Math.ceil((v.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return f(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,rt.read(o,w,0,512,h,E)};rt.read(o,w,0,512,h,E)};return new Promise((o,c)=>{r.on("error",c);let l="r+",f=(h,p)=>{if(h&&h.code==="ENOENT"&&l==="r+")return l="w+",rt.open(t.file,l,f);if(h||!p)return c(h);rt.fstat(p,(w,E)=>{if(w)return rt.close(p,()=>c(w));i(p,E.size,(T,_)=>{if(T)return c(T);let v=new qs(t.file,{fd:p,start:_});r.pipe(v),v.on("error",c),v.on("close",o),Fw(r,e)})})};rt.open(t.file,l,f)})},zw=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?_r({file:h0.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Fw=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await _r({file:h0.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},fi=vi(Nw,Bw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!am(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")}),L2=vi(fi.syncFile,fi.asyncFile,fi.syncNoFile,fi.asyncNoFile,(t,e=[])=>{fi.validate?.(t,e),Uw(t)}),Uw=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};rn();var yt={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 Si(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function x0(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Cc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function p0(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function yr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Ke();ne();Ce();Ke();function Kt(t,e){if(Si(t)!=="cloud")throw new D("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Zs(t){return t.startsWith("http://")||t.startsWith("https://")}function Ys(t){return t.endsWith("/")?t.slice(0,-1):t}Ke();ne();var Xs="1008033",g0="1289";var m0="pbbp2",w0="https://www.coze.cn",_0="/api/coze_claw/resource/get_frontier_key",Hw="https://www.coze.cn",qw="wss://frontier.coze.cn";function Qs(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Hw}function y0(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??qw}function br(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Ai(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ii=G("handshake");async function kc(t){let e=Qs(t.endpoint),r=t.timeoutMs??1e4,i=`${Ys(e)}${_0}?aid=${encodeURIComponent(Xs)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...br(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ii.info("frontier key handshake",{base:e});try{let f=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=f.headers.get("x-tt-logid")??"",p=f.headers.get("x-tt-trace-id")??"";if(!f.ok){let v=await f.text().catch(()=>"");throw new D("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${f.status} logid=${h}: ${v.slice(0,200)}`)}let w=await f.json();if(w.code!==void 0&&w.code!==0)throw new D("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${w.code} msg=${w.msg??"-"} logid=${h}`);let E=w.data??{},T=typeof E.access_key=="string"&&E.access_key||typeof E.accessKey=="string"&&E.accessKey||void 0,_=typeof E.device_id=="string"&&E.device_id||typeof E.deviceId=="string"&&E.deviceId||void 0;if(!T||!_){let v=JSON.stringify(w).slice(0,500);throw new D("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Ii.info("handshake ok",{remoteDeviceId:_,logid:h,traceId:p}),{accessKey:T,deviceId:_}}catch(f){if(f instanceof D)throw Ii.error("handshake failed (bridge error)",{base:e,message:f.message,code:f.code}),f;if(f.name==="AbortError")throw Ii.warn("handshake timeout",{base:e,timeoutMs:r}),new D("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:f});let h=f.cause;throw Ii.error("handshake error",{base:e,message:f instanceof Error?f.message:String(f),errno:h?.code,syscall:h?.syscall,cause:String(f).slice(0,300)}),new D("UPSTREAM_HANDSHAKE_FAILED",String(f),{cause:f})}finally{clearTimeout(l)}}var Oc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",bt="auto",b0=15e4;function E0(t){return{model:Pc(t.model)??bt,...t.modelToken?{modelToken:t.modelToken}:{}}}function v0(t){return!t||t===bt}var jw=new Set(["auto","\u81EA\u52A8"]);function Pc(t){let e=t?.trim();if(e)return jw.has(e.toLowerCase())?bt:e}function S0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Oc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||bt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else v0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function I0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||bt}"`):v0(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Oc}/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"');let r=t.modelInfo?.contextWindow??b0;e.push("-c",`model_context_window=${r}`)}return e}function A0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Lc(t,e){let{ttEnv:r,usePpe:i}=Ai(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function T0(t,e,r){if(!t.modelToken)return{};let i=Lc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
+ `)}}function Nc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function D0(t,e,r){if(!t.modelToken)return null;let i=t.model||bt,o=Lc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Oc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??b0,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function R0(t,e,r){if(!t.modelToken)return[];let i=Lc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Pe=G("agent-handlers"),C0=5*1024*1024,Zw=1,Yw=6,Xw=new Set(["node_modules",".git",".coze","dist","build",".next"]),eo=class{constructor(e){this.opts=e}opts;async listSkills(e){Kt(e._meta,"_agent/listSkills");let r=yr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],l=[];for(let f of c){let h=Ot(o,f.relPath,"SKILL.md");await $w(h).then(w=>w.isFile()).catch(()=>!1)&&l.push(r_(f))}return{skills:l}}async addSkills(e){Kt(e._meta,"_agent/addSkills");let r=yr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((h,p)=>[h.skillId,p])),f=[];for(let h of o){let p=await Hc({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});qc(c,l,p),f.push(h)}return await ss(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:f}}async removeSkills(e){Kt(e._meta,"_agent/removeSkills");let r=yr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let f of c){if(!o.has(f.skillId)){l.push(f);continue}let h=Ot(i.workspace,f.relPath);await Kw(h,{recursive:!0,force:!0}),Pe.info("skill removed",{agentId:r,skillId:f.skillId,relPath:f.relPath})}return await ss(r,l),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Pe.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let h=c.downstream;c.downstream=void 0,Pe.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),h.stop(r).catch(p=>Pe.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(p)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Pe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await qe(r);if(!i)throw new D("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Pe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await rr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Pe.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new D("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ye(i),Pe.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new D("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await qe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ye(i),Pe.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Pe.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Kt(e._meta,"_agent/switchModel"),!e.agentId)throw new D("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Pc(e.model)??bt,i=await qe(e.agentId);if(!i)throw new D("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ye(i),Pe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Pe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Pe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,f]of o.allSessionQueues())c.push(f.enqueue(async()=>{let h=o.sessions.get(l);h?.downstream&&(await h.downstream.stop(`switchModel: ${r}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(c),Pe.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(Kt(e._meta,yt.RESET),!e.agentId)throw new D("IPC_BAD_REQUEST",`${yt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,yt.RESET),await this.runDetailSync(e.agentId,yt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Pe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await Yr(e,o)}async clearPersistedAcpSessionIds(e){let r=await qe(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Ye(r)}async repairAgent(e){if(Kt(e._meta,yt.REPAIR),!e.agentId)throw new D("IPC_BAD_REQUEST",`${yt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new D("IPC_BAD_REQUEST",`${yt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Pe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,yt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Pe.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Pe.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Kt(e._meta,"_agent/getFileTree");let r=e._meta,i=yr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),f=await Mc(l).catch(()=>null);if(!f)throw new D("IPC_BAD_REQUEST",`path not found: ${c}`);if(f.isSymbolicLink())throw new D("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Zr(l,o))throw new D("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=x_(e.depth);return f.isDirectory()?{tree:await h_(o,l,c,h)}:{tree:[{name:p_(c),path:B0(c||"."),isDir:!1,size:f.size,modifiedAt:Math.floor(f.mtimeMs)}]}}async getFileContent(e){Kt(e._meta,"_agent/getFileContent");let r=yr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new D("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Mc(o).catch(()=>null);if(!c||!c.isFile())throw new D("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new D("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Zr(o,i))throw new D("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>C0)throw new D("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${C0})`);let l=await k0(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await qe(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=Fc(e,r||"."),o=Gc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${O0}`))throw new D("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return qe(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new D("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function Qw(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new D("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new D("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function e_(t){return t==="claude-code"?Ot(".claude","skills"):Ot(".agents","skills")}var t_=3e4,n_=50*1024*1024,Er=3e4;async function Hc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new D("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new D("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let f=Qw(o.skillName),h=e_(i),p=Ot(h,f),w=Ot(r,p);if(await Bc(w,{recursive:!0}),c){let T=Buffer.from(o.content,"utf8");Ti(T.length),await zc(Ot(w,"SKILL.md"),T,"utf8")}else{let T=await i_(o.downloadUrl);o_(T)?await l_(T,w):a_(T)?await c_(T,w):await zc(Ot(w,"SKILL.md"),T.toString("utf8"),"utf8")}let E={skillId:o.skillId,skillName:o.skillName,relPath:p,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Pe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),E}function qc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function r_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function i_(t){if(!t)throw new D("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ti(e);let r=s_(t);return Ti(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await k0(e);return Ti(r.length),r}if(Zs(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),t_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new D("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ti(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new D("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ti(t){if(t>n_)throw new D("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function s_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new D("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function o_(t){return t.length>=2&&t[0]===31&&t[1]===139}function a_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Uc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function c_(t,e){let r,i;try{r=new N0.default(t),i=r.getEntries()}catch(l){throw new D("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let f=l.entryName;if(!f||Uc(f))continue;if(f.startsWith("/")||/^[A-Za-z]:[\\/]/.test(f))throw new D("IPC_BAD_REQUEST",`zip entry absolute path: ${f}`);if(f.split(/[/\\]/).some(p=>p===".."))throw new D("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${f}`);let h=l.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new D("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${f}`)}let o=d_(i),c=Fc(e);for(let l of i){if(Uc(l.entryName))continue;let f=l.entryName;if(o&&f.startsWith(o)&&(f=f.slice(o.length)),!f)continue;let h=Fc(e,f),p=Gc(c,h);if(p.startsWith("..")||p==="..")throw new D("IPC_BAD_REQUEST",`zip entry escapes destDir: ${f}`);if(l.isDirectory){await Bc(h,{recursive:!0});continue}await Bc(Vw(h),{recursive:!0});let w;try{w=l.getData()}catch(E){throw new D("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${E.message}`,{cause:E})}await zc(h,w)}}function d_(t){let e;for(let r of t){let i=r.entryName;if(!i||Uc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function l_(t,e){await u_(t);let r=f0({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new D("IPC_BAD_REQUEST",`tar extract timeout (${Er}ms)`))},Er);try{await L0(P0.from(t),r)}catch(c){throw c instanceof D?c:i?new D("IPC_BAD_REQUEST",`tar extract timeout (${Er}ms)`):new D("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function u_(t){let e=[],r=_r({onReadEntry:c=>{let l=c.path,f=c.type;if(f!=="File"&&f!=="Directory"){e.push(`tar entry kind '${f}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new D("IPC_BAD_REQUEST",`tar list timeout (${Er}ms)`))},Er);try{await L0(P0.from(t),r)}catch(c){throw i?new D("IPC_BAD_REQUEST",`tar list timeout (${Er}ms)`):new D("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new D("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var f_=5e3;async function h_(t,e,r,i){return M0(t,e,r,i,{count:0})}async function M0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Ww(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let f of c){if(Xw.has(f.name)||f.isSymbolicLink())continue;if(o.count>=f_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=Ot(e,f.name),p=Jw(Ot(r,f.name)),w=null;try{w=await Mc(h)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let E={name:f.name,path:B0(Gc(t,h)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(E.children=await M0(t,h,p,i-1,o)),l.push(E)}return l.sort((f,h)=>f.isDir!==h.isDir?f.isDir?-1:1:f.name.localeCompare(h.name)),l}function x_(t){return!t||t<=0?Zw:Math.min(t,Yw)}function p_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function B0(t){return t.split(O0).join("/")}ne();import{readFileSync as jI}from"node:fs";import{dirname as KI,join as $I}from"node:path";import{fileURLToPath as JI}from"node:url";var vr="0.1.98-alpha.4";var wn=G("agent-health-reporter"),g_=1e4,Di=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??g_}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()}),wn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),wn.info("heartbeat stopped"))}async tick(){if(this.inFlight){wn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){wn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let f=m_(l);if(!f)continue;let h={agentId:l.agentId,status:f};l.patToken&&(h.patToken=l.patToken),l.accountId&&(h.accountId=l.accountId),r.push(h)}if(r.length===0)return;let i={agents:r,bridgeVersion:vr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){wn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(wn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){wn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){wn.warn("onTickEnd hook failed",{err:String(r)})}}};function m_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as ly,mkdir as lo,rm as uy,stat as fy,writeFile as hy}from"node:fs/promises";import{homedir as xy}from"node:os";import{join as af}from"node:path";nn();import{spawnSync as L_}from"node:child_process";import{existsSync as N_}from"node:fs";import{release as M_}from"node:os";import{basename as B_,isAbsolute as z_}from"node:path";function Ri(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Sr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Ir(t,e){return{jsonrpc:"2.0",id:t,result:e}}function _n(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var to=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)}},ee={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,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021};function z0(t){return"method"in t&&"id"in t&&t.id!==void 0}function F0(t){return"method"in t&&!("id"in t)}function no(t){return!("method"in t)&&"id"in t}var w_={AGENT_NOT_FOUND:ee.AGENT_NOT_FOUND,AGENT_BUSY:ee.AGENT_BUSY,AGENT_DISCONNECTED:ee.AGENT_DISCONNECTED,AGENT_TIMEOUT:ee.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:ee.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:ee.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:ee.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:ee.INTERNAL_ERROR,BRIDGE_INTERNAL:ee.INTERNAL_ERROR,IPC_AUTH_FAILED:ee.INTERNAL_ERROR,IPC_BAD_REQUEST:ee.INVALID_REQUEST,MODEL_TOKEN_GEN_FAILED:ee.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:ee.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:ee.OPERATION_NOT_ALLOWED_FOR_LOCAL,UPSTREAM_DISCONNECTED:ee.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:ee.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:ee.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:ee.FILE_TOO_LARGE,UNSUPPORTED_MIME:ee.UNSUPPORTED_MIME,UPLOAD_FAILED:ee.UPLOAD_FAILED,UPSTREAM_NOT_READY:ee.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:ee.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:ee.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:ee.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:ee.AGENT_ENV_NOT_READY};function __(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ci(t.message)}:typeof t=="string"?Ci(t):typeof t=="object"?b_(t):t}var y_=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Ci(t){let e=t;for(let[r,i]of y_)e=e.replace(r,i);return e}function b_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ci(i):e[r]=i;return e}function ki(t){if(t instanceof D){let e=__(t.cause),r={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(r.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(r.reason=e.reason),{code:w_[t.code]??ee.INTERNAL_ERROR,message:Ci(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Ci(t instanceof Error?t.message:String(t))}}function U0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...f}=e;c=f}return new D(r,o,{retriable:e?.retriable??!1,cause:c})}function H0(t){return`${JSON.stringify(t)}
93
+ `}var G0=10*1024*1024,ro=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>G0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${G0} bytes`)}),[]}let r=this.buffer.split(`
94
+ `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(l){this.onError?.({line:c,error:l})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var j0={"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"},oA=Object.fromEntries(Object.entries(j0).map(([t,e])=>[e,t])),E_={"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:[]},Ar=class{seq=0;next(e,r){this.seq+=1;let i=j0[e]??v_(e),o=E_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(h=>q0(r?.[h]??"")),f=S_(l).join(":");f&&c.push(f)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>q0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function v_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function q0(t){return t.replace(/[:_\s]+/g,"-")}function S_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Jr();import{readFileSync as I_}from"node:fs";var A_=384;async function jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await nr(t.agentEnvFile,r,{mode:A_})}function Wc(t){try{let e=JSON.parse(I_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function W0(t,e,r={},i=o=>o){return{...i({...t,...Wc(e)}),...r}}yn();Yi();Ke();ne();Ce();var P_=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: Node binary not found/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"}];function J0(t,e){if(!e)return null;for(let r of P_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function Z0(t,e){return J0(t,e)}function Y0(t,e){return J0(t,e)}var F_=Ft("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),U_=200,G_=40,H_=Ft("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),q_=Ft("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),j_=Ft("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),X0=500;function W_(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=X0?t:`${e.slice(0,X0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function K_(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function Q0(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),L_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}function ef(t){try{return N_(t)}catch{return}}function $_(t,e){return{platform:process.platform,osRelease:M_(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:z_(e.command)?ef(e.command):void 0,cwd:e.cwd,cwdExists:ef(e.cwd),envKeys:e.envKeys}}function V_(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${B_(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new ro({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Ar;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new D("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=W0(process.env,this.opts.agentEnvFile??X().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=lt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>U_&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let f of this.decoder.flush())this.dispatch(f)}catch(f){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(f)})}this.failAllPending(this.buildExitError(o,c));for(let f of this.exitHandlers)f(o,c)}),i.on("error",o=>{let c=o,l=$_(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new D("AGENT_SPAWN_FAILED",V_(c,l),{cause:l}))}),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.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Q0(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Q0(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}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,r=H_,i=q_,o=j_){return this.call("session/prompt",e,r,i,o)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Sr("session/cancel",e))}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Ir(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(_n(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=F_,o=0,c=0){if(!this.child||this.stopped)return Promise.reject(new D("AGENT_PROTOCOL_ERROR","downstream not started"));let l=this.idAllocator.next(e),f=Ri(l,e,r),h=(()=>{if(typeof r!="object"||r===null)return;let E=r.sessionId;return typeof E=="string"?E:void 0})(),p=i>0&&Number.isFinite(i),w=o>0&&Number.isFinite(o);return new Promise((E,T)=>{let _={resolve:E,reject:T,timer:null,firstUpdateTimer:null,onFirstUpdate:null,method:e},v=Date.now();if(p){let S=()=>{_.timer=setTimeout(()=>{let R=Date.now()-v;if(this.inflightAgentRequests.size>0&&R<c){this.log.debug("hard cap fired but agent request inflight, extending to approval cap",{id:l,method:e,elapsed:R,approvalMaxMs:c,...h?{sessionId:h}:{}}),S();return}this.pending.delete(l),_.firstUpdateTimer&&clearTimeout(_.firstUpdateTimer);let L=this.inflightAgentRequests.size>0;this.log.warn("downstream call timeout",{id:l,method:e,timeoutMs:i,approvalMaxMs:c,awaitingApproval:L,...h?{sessionId:h}:{}}),T(L?new D("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${c}ms`):new D("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i)};S()}let I=w?()=>{_.firstUpdateTimer&&clearTimeout(_.firstUpdateTimer),_.firstUpdateTimer=setTimeout(()=>{if(this.inflightAgentRequests.size>0){this.log.debug("first-update wait fired but agent request inflight, re-arming",{id:l,method:e,inflight:this.inflightAgentRequests.size,...h?{sessionId:h}:{}}),I?.();return}_.timer&&clearTimeout(_.timer),this.pending.delete(l),this.log.warn("first session/update timeout, rejecting pending call",{id:l,method:e,firstUpdateMs:o,...h?{sessionId:h}:{}}),T(new D("AGENT_FRAME_IDLE_TIMEOUT",`${e} no first session/update within ${o}ms`))},o)}:null;_.onFirstUpdate=w?()=>{_.firstUpdateTimer&&clearTimeout(_.firstUpdateTimer),_.firstUpdateTimer=null,_.onFirstUpdate=null}:null,this.pending.set(l,_),I?.();try{this.writeFrame(f)}catch(S){_.timer&&clearTimeout(_.timer),_.firstUpdateTimer&&clearTimeout(_.firstUpdateTimer),this.pending.delete(l),T(S)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new D("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(H0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(no(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new D("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:W_(e.result)}),r.resolve(e.result));return}if(F0(e)){if(e.method==="session/update"){for(let r of this.pending.values())r.onFirstUpdate?.();for(let r of this.updateHandlers)try{Promise.resolve(r(e.params)).catch(i=>this.log.warn("update handler failed (async)",{err:String(i)}))}catch(i){this.log.warn("update handler threw sync, swallowed",{err:String(i)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(z0(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(_n(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(_n(e.id,ki(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=U0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=Y0(this.framework,K_(e));return i?new D(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new D("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(G_).join(`
95
+ `),o=Z0(this.framework,i);return o?new D(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new D("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function J_(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var io=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Vr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return J_(e)}};nn();import{mkdtempSync as Z_,rmSync as Y_}from"node:fs";import{tmpdir as X_}from"node:os";import{join as Q_}from"node:path";var so=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Vr("codex",e.command,i),l=e.isolateCodexHome?Z_(Q_(X_(),"coze-bridge-codex-home-")):void 0,f=l?{...e.env??{},CODEX_HOME:l}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...f?{env:f}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Y_(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var ey=3e4,Tr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,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}`}]},ey))}get acpSessionName(){return this.sessionName}};Ke();ne();Ce();function Kc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}nn();var bn=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((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),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}get isDisposed(){return this.disposed}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 r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var oo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=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",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new bn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Oi(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Oi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}yn();ne();import{constants as tf}from"node:fs";import{access as ty}from"node:fs/promises";import{delimiter as ny,join as ry}from"node:path";var Et=G("framework-detector"),nf={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},iy=[".exe",".cmd",".bat",".ps1"],Gn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??lt,access:e.access??ty}}async detect(e){let r=nf[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),f={path:i,version:c};return l&&(f.defaultAgent=l),f}async detectAll(){let e=await Promise.all(Object.keys(nf).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(ny).filter(Boolean),i=this.env.platform==="win32"?["",...iy]:[""];for(let o of r)for(let c of i){let l=ry(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?tf.F_OK:tf.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(oy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,f=h=>{c||(c=!0,l&&clearTimeout(l),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{h.kill("SIGKILL"),f(null)},15e3),h.stdout?.on("data",p=>{o+=p.toString("utf8")}),h.on("error",()=>f(null)),h.on("close",p=>f({code:p,stdout:o}))}catch{f(null)}})}},sy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function oy(t){return t.replace(sy,"")}import{homedir as ay}from"node:os";import{join as cy}from"node:path";yn();Ke();Jr();ne();async function of(){let t=cy(ay(),".openclaw/openclaw.json");return(await tr(t))?.gateway?.auth?.token??""}var rf=G("openclaw.config"),dy=[0,5e3,5e3],sf="models.providers.",ao="agents.defaults.models",co=class{command;env;retryDelaysMs;queue=new bn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??dy}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await r()}catch(l){i=l,rf.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new D("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=lt(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`exit ${l}: ${c.trim().slice(0,500)}`))})})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){rf.warn(`${e} failed (best-effort)`,{configPath:r,err:String(i)})}}ensureProvider(e,r){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${sf}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${sf}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${ao}[${e}]`,()=>this.runCli(["config","set",ao,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${ao}[${e}]`,`${ao}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var xe=G("agent-manager"),py=(t,e,r,i,o,c,l,f,h)=>{switch(t){case"claude-code":{let p={...o?{...S0(o),...T0(o,l,f)}:{},...h??{},IS_SANDBOX:"1"};return new io({cwd:r,env:p,agentId:i})}case"codex":{let w=[...o?[...I0(o),...R0(o,l,f)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],E={...o?A0(o):{},...h??{}},T=!!o;return new so({cwd:r,agentId:i,...w.length>0?{extraArgs:w}:{},...Object.keys(E).length>0?{env:E}:{},...T?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Tr({command:e,cwd:r,agentId:i,...c?{sessionName:Kc(c)}:{}})}};function $c(t){return t==="claude-code"||t==="codex"}function gy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(my(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
96
96
  `)}
97
- `}function x_(t){if(t.includes(`
98
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var p_={path:"",version:"cloud-deployed"},s0="openclaw_gateway_unavailable",g_="openclaw_default_agent_missing";function o0(t){let e=[t.port!==void 0?`port=${t.port}`:"",t.runtime?`runtime=${t.runtime}`:"",t.detail??""].filter(Boolean).join(", ");return`openclaw gateway \u672A\u8FD0\u884C/\u4E0D\u53EF\u8FBE${e?` (${e})`:""}; \u8BF7\u542F\u52A8 openclaw gateway`}var m_={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},w_=6e4,co=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??u_,this.createTimeoutMs=e.createTimeoutMs??w_,this.detectorFactory=e.detectorFactory??(()=>new Fn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new oo({command:r})),this.openclawConfigDir=e.openclawConfigDir??i0(f_(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{xe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=i0(e,".env");if(await d_(r).then(c=>c.isFile()).catch(()=>!1)){xe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await ao(e,{recursive:!0});let o=h_({...process.env,...Hc(this.paths.agentEnvFile)});if(await l_(r,o,"utf8"),process.platform!=="win32")try{await a_(r,384)}catch(c){xe.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}xe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),xe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=bi(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let o=this.registry.get(e.agentId);if(o){if(o.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${o.framework})`);if(o.status==="error")xe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(S=>xe.warn("dispose stale agent failed (ignored)",{err:String(S)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){xe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let S=await Ge(e.agentId,this.paths).catch(()=>null);S&&(S.patToken=e.patToken,await Ve(S,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){xe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let S=await Ge(e.agentId,this.paths).catch(()=>null);S&&(S.modelInfo=e.modelInfo,await Ve(S,this.paths))}return xe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:o.agentId,workspace:o.workspace,framework:o.framework}}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let d=Ze(e.agentId,this.paths),f=bi(e._meta),h=e.framework==="openclaw"&&f==="local",x;h&&!r?.revive&&(x=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let m=x??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),g=e.workspace??m??d.workspace,A=new AbortController,w=setTimeout(()=>A.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),E,I=!1;try{i&&Wc(e.framework)&&await Xn(e.framework,A.signal);let S=()=>{if(A.signal.aborted)throw A.signal.reason instanceof Error?A.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await ao(d.root,{recursive:!0}),await ao(g,{recursive:!0}),await ao(d.logs,{recursive:!0}),S(),h||await tr(g,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await wl(g),S();let R=await Ge(e.agentId,this.paths).catch(()=>null),P=bu({model:e.model??R?.model}),y=xu(e._meta)??R?.accountId,C=e.patToken??R?.patToken,D=f==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(E=new io({agentId:e.agentId,framework:e.framework,workspace:g,model:P.model??wt,deployType:f,...y?{accountId:y}:{},...C?{patToken:C}:{},...D?{modelInfo:D}:{}}),E.status="ok",R?.sessions){for(let[Z,te]of Object.entries(R.sessions))E.sessions.set(Z,{acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let K=Object.keys(R.sessions).length;K>0&&xe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:K})}this.registry.register(E),I=!0;let N={agentId:e.agentId,framework:e.framework,workspace:g,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:P.model};f==="cloud"&&(N.deployType="cloud"),y&&(N.accountId=y),C&&(N.patToken=C),D&&(N.modelInfo=D),R?.skills&&(N.skills=R.skills),R?.agentName&&(N.agentName=R.agentName),R?.description&&(N.description=R.description),e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,g)):xe.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let M=e.initialSkills??[];if(M.length>0){let K=[...N.skills??[]],Z=new Map(K.map((_e,he)=>[_e.skillId,he])),te=await Promise.allSettled(M.map(_e=>Uc({agentId:e.agentId,workspace:g,framework:e.framework,skill:_e}))),X=0;for(let[_e,he]of te.entries()){let O=M[_e];O&&(he.status==="fulfilled"?(Gc(K,Z,he.value),X++):xe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:O.skillId,skillName:O.skillName,err:String(he.reason)}))}X>0&&(N.skills=K,xe.info("initialSkills installed",{agentId:e.agentId,installed:X,requested:M.length}))}return await Ve(N,this.paths),xe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:g,framework:e.framework}}catch(S){throw xe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(S)}),I&&E&&(await E.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await c_(d.root,{recursive:!0,force:!0}).catch(R=>xe.warn("rm agent dir failed (ignored)",{err:String(R)})),S instanceof T?S:new T("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(w)}}async spawnSessionDownstream(e,r,i,o,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&Wc(e.framework))f=p_;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Wc(e.framework)&&!es(e.framework)&&(xe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await Xn(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;e.framework==="openclaw"?x=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:f.path}):x=this.factory(e.framework,f.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv());try{return await x.start(),await x.initialize(m_),x}catch(m){let g=x instanceof Dt?x.getStderrTail():[];throw g.length>0&&xe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:g}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",o0(o),{cause:{reason:s0}})}catch(o){xe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?new T(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};xe.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return xe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:g_}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new T("AGENT_ENV_NOT_READY",o0(r),{cause:{reason:s0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:f}=e,h=qc(o);if(r.deployType==="local"){let A=await this.ensureOpenclawDefaultAgent();return new Ir({command:f,cwd:A.workspace,agentId:A.id,sessionName:h})}let x=await r0(),m=i?Ru(i,c,d):null,g;if(m){let A=Pc(o),E=m.models[0]?.id??wt,I=`${A}/${E}`;if(!this.ensuredProviders.has(I)){let S=this.getOpenclawConfig();await S.ensureProvider(A,m),await S.addModelToAllowlist(I),this.ensuredProviders.add(I)}g=I}return new Ir({command:f,cwd:r.workspace,agentId:r.agentId,sessionName:h,...x?{gatewayToken:x}:{},...g?{slashModelOnStart:g}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Pc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(f){d=!1,xe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(f)})}try{await r.removeModelFromAllowlist(c)}catch(f){d=!1,xe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(f)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as f0}from"node:crypto";import{promises as A_}from"node:fs";import{basename as u0}from"node:path";qe();ne();import{promises as __}from"node:fs";import{basename as E_}from"node:path";var a0=G("file-upload"),b_="/api/coze_claw/file/agent_upload",v_=6e4;async function c0(t,e={}){let i=`${Vs(Ys(e.handshakeBase))}${b_}`,o=e.timeoutMs??v_,c=await __.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let f={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...yr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);a0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:f,body:d,signal:h.signal}),g=m.headers.get("x-tt-logid")??"";if(!m.ok){let E=await m.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${g}: ${E.slice(0,200)}`)}let A=await m.json();if(A.code!==void 0&&A.code!==0)throw new T("UPLOAD_FAILED",`upload code=${A.code} msg=${A.msg??"-"} logid=${g}`);let w=A.data?.file?.file_url;if(!w)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${g}: ${JSON.stringify(A).slice(0,200)}`);return a0.info("file upload ok",{uri:w,logid:g}),{uri:w}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${E_(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}qe();ne();import{extname as S_}from"node:path";var I_={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function d0(t){let e=S_(t).toLowerCase();return I_[e]??"application/octet-stream"}ke();var lo=G("agent-send"),l0=50*1024*1024;function h0(t,e,r){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new T("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function x0(t,e,r,i,o,c){let f;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){f=x,h<2&&(lo.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(f)}`,{cause:f})}async function p0(t,e){let{session:r,runtime:i}=h0(e.core,t.agentId,t.sessionId);if(!await Zr(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await A_.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>l0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${l0}`);let c=await d0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??u0(t.path),f;try{f=await c0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw lo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof T?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:f0(),content:{type:t.kind==="image"?"image":"resource",uri:f.uri,mimeType:c,name:d,sizeBytes:o.size,...f.fileId!==void 0?{fileId:f.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await x0(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),lo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:f.uri}),{ok:!0,uri:f.uri,bytes:o.size,mimeType:c,...f.fileId!==void 0?{fileId:f.fileId}:{}}}async function g0(t,e){let{session:r,runtime:i}=h0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??u0(t.path),c={sessionUpdate:"group_file",messageId:f0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await x0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),lo.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function m0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,f=i[c]??0;if(d<f)return!0;if(d>f)return!1}return!1}en();wn();ne();var kt=G("coze-cli-installer"),w0="@coze/cli@latest",T_="coze",y0="0.1.8",R_=5e3,C_=5e3,D_=9e4,_0=1e4,ki=null,fo=!1;async function $c(t,e={}){if(fo)return;if(ki)return ki;let r=e.exec??Zu;return ki=(async()=>{try{let i=await k_(T_,r),o=!1;if(i){let d=await O_(r);if(d===void 0)kt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(m0(d,y0))kt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:y0}),o=!0;else{kt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),fo=!0;return}}let c=o?"upgrade-only":"full";kt.info("coze-cli install start",{package:w0,mode:c});try{await r("npm",["i","-g","--prefer-online",w0],{timeout:D_,maxBuffer:10*1024*1024}),kt.info("coze-cli install ok")}catch(d){kt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){fo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:_0}),kt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){kt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:_0}),kt.info("coze auth login ok")}catch(d){kt.warn("coze auth login failed",{err:String(d)});return}fo=!0}finally{ki=null}})(),ki}async function k_(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:R_});return wa(i)}catch{return}}async function O_(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:C_});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Kr();ke();var P_=10*6e4;function E0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?P_:e}function uo(t){return Qn(t??Y().configFile)}function Oi(t,e){return er(e??Y().configFile,t)}import{randomBytes as Q_}from"node:crypto";Vi();qe();ne();import{createReadStream as L_}from"node:fs";import{mkdir as N_,readFile as M_,realpath as B_,stat as z_,writeFile as F_}from"node:fs/promises";import{basename as U_,dirname as Kc,isAbsolute as G_,join as j_,relative as H_,resolve as b0,sep as q_}from"node:path";import{createInterface as W_}from"node:readline";var S0=G("fs-rpc"),Pi=Mt("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function I0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Pi)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Pi} bytes`);let i=await T0(t.path,e);return await N_(Kc(i),{recursive:!0}),await F_(i,t.content,"utf8"),S0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function A0(t,e){let r=await T0(t.path,e),i=await z_(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Pi&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Pi} bytes`);let c;if(o&&i.size>Pi)c=await $_(r,t.line??1,t.limit);else{let d=await M_(r,"utf8");if(o){let f=d.split(`
99
- `),h=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?h+t.limit:void 0;c=f.slice(h,x).join(`
100
- `)}else c=d}return S0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function $_(t,e,r){let i=W_({input:L_(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],f=0;try{for await(let h of i)if(f>=o&&f<c&&d.push(h),f++,f>=c)break}finally{i.close()}return d.join(`
101
- `)}async function T0(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([v0(b0(e)),v0(b0(t))]),o=H_(r,i);if(K_(o,q_,G_(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function K_(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function v0(t){let e=[],r=t;for(;r!==Kc(r);)try{let i=await B_(r);return e.length?j_(i,...e.reverse()):i}catch{e.push(U_(r)),r=Kc(r)}return t}ne();var R0=G("prompt-multimodal"),C0=10*1024*1024,Z_=15e3,V_=6;async function D0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,d=t[c];d!==void 0&&(e[c]=await J_(d))}}let o=Array.from({length:Math.min(V_,t.length)},()=>i());return await Promise.all(o),e}function k0(t){return t.some(e=>e.type==="image")}async function J_(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Zs(e.uri))return t;try{let{buf:r,contentType:i}=await X_(e.uri),o=e.mimeType||Y_(i)||"application/octet-stream";return R0.info("image uri fetched and inlined",{uri:e.uri,bytes:r.length,mimeType:o}),{type:"image",data:r.toString("base64"),mimeType:o}}catch(r){return R0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Y_(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function X_(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Z_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new Error(`HTTP ${i.status} ${i.statusText}`);let o=await i.arrayBuffer();if(o.byteLength>C0)throw new Error(`image too large: ${o.byteLength} bytes (max ${C0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}tn();qe();ne();var $=G("core"),eE=3e4,tE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,nE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",rE="\u5BA1\u6279\u5DF2\u8D85\u65F6",iE=3e4,ho=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Sr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=E0(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),$.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){$.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),$.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){$.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}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)&&$.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{$.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Di(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){$.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(mn(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>$.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Q.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){$.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Q.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(eo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&tE.test(i)?this.currentCozeEnv=i:i&&$.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):$.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(vr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(vr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(vr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):$.warn("drop unknown notification",{method:e.method})}catch(o){$.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(mn(r,Ci(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,m=Rc(r._meta);return $.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,nE,x,m)}}let d=Date.now(),f=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return f=!0,h}finally{$.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:f})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=pu(i);switch(r){case"session/new":{let c=sE();return $.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return $.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let f=await this.ensureRuntime(e,d);if(f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(f.acpSessionId,h):e.activeTriggers.delete(f.acpSessionId);let x=Rc(i._meta);if(x?e.activeGroupIds.set(f.acpSessionId,x):e.activeGroupIds.delete(f.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&k0(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let m=await D0(c.prompt);try{let g=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:m});return f.lastActiveAt=Date.now(),g}catch(g){if(g instanceof T&&g.code==="AGENT_APPROVAL_TIMEOUT"){let A=f.pendingPermission;A&&(A.downstream.respondAgentRequest(A.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(A.upstreamId),f.pendingPermission=void 0);let w=f.acpSessionId,E=w?e.activeTriggers.get(w):void 0,I=w?e.activeGroupIds.get(w):void 0;return $.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,rE,E,I)}throw g}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let g=f.downstream;g&&(f.downstream=void 0,$.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),g.stop("reload-after-turn").catch(A=>$.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(A)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let f=e.sessions.get(d);if(e.hasSessionQueue(d)){let h=e.getSessionQueue(d);h.size>0&&($.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:h.size}),h.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return f?.downstream?.isAlive()&&f.acpSessionId&&await f.downstream.sessionCancel({sessionId:f.acpSessionId}),{ok:!0}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(mt.GEN_MODEL_TOKEN,i,iE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Di(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,f=i.spawnFailedAt??0;if(d>=o&&Date.now()-f<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-f))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&($.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}if(i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i),i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),$.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){$.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Di(i),this.isRuntimeBusy(e,i)){$.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){$.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}$.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>$.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let f=e.activeGroupIds.get(r.acpSessionId);f&&(c.cozeGroupId=f)}await this.upstream.send(br("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,d){let f={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(f.cozeTriggerMsgId=c),d&&(f.cozeGroupId=d),await this.upstream.send(br("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:f})).catch(h=>$.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){$.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){$.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(cE(r)){$.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(d.cozeTriggerMsgId=f);let h=e.activeGroupIds.get(i);h&&(d.cozeGroupId=h),this.upstream.send(br("session/update",{...r,sessionId:o,_meta:d})).catch(x=>$.warn("forward update failed",{agentId:e.agentId,err:String(x)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}$.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Q.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await I0(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await A0(c,o);r.respondAgentRequest(i.id,d)}}catch(o){$.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Ci(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},f=c.sessionId,h=f?e.activeTriggers.get(f):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let m=f?e.activeGroupIds.get(f):void 0;m&&(x.cozeGroupId=m);let g=f?this.reverseSessionId(e,f):void 0,A=g?e.sessions.get(g):void 0;A&&(A.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let w={...c,...g?{sessionId:g}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:g}),$.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:f,cloudSessionId:g,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(E=>({optionId:E.optionId,kind:E.kind,name:E.name}))}),this.upstream.send(Ti(o,"session/request_permission",w)).catch(E=>{this.pendingUpstream.delete(o),$.error("forward permission request failed",{agentId:e.agentId,err:String(E)}),r.respondAgentRequestError(i.id,{code:Q.INTERNAL_ERROR,message:`upstream send failed: ${String(E)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?($.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&oE(e.result,o),$.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new Qs(e.error)):i.value.resolve(e.result);return}$.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),d=e.get(c);if(d)return $.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=eE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let f=setTimeout(()=>{this.pendingBridge.delete(o),d(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:f}),this.upstream.send(Ti(o,e,r)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(h)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),r.set(i,c)}await Vr(e.agentId,r,this.paths)}catch(r){$.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(mn(e,{code:r,message:i,data:{bridgeVersion:Er}}))}};function sE(){return Q_(16).toString("hex")}function oE(t,e){if(!t||typeof t!="object"){$.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){$.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){$.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&$.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var aE=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function cE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let r=e.content;if(!r||typeof r!="object")return!1;let i=r;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return aE.some(c=>o.startsWith(c))}ne();ke();import{randomBytes as dE}from"node:crypto";import{chmod as lE,mkdir as fE,writeFile as O0}from"node:fs/promises";import{createServer as uE}from"node:http";import{dirname as hE}from"node:path";var xE=1e6,Zc=G("ipc"),xo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Y()}async start(){this.token=dE(32).toString("hex");let e=uE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),Zc.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await fE(hE(this.paths.portFile),{recursive:!0}),await O0(this.paths.portFile,String(this.port),"utf8"),await O0(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await lE(this.paths.tokenFile,384)}catch(e){Zc.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Li(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Li(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await pE(e)}catch(f){Li(r,400,{error:"invalid json",detail:String(f)});return}try{let f=await c.handler(d,e);Li(r,200,f??{ok:!0})}catch(f){Zc.error("IPC handler failed",{key:o,err:String(f)}),Li(r,500,{error:f instanceof Error?f.message:String(f)})}}};function Li(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function pE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>xE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var ex=bt(H0(),1);var Vb=bt(zh(),1),Jb=bt(Do(),1),Yb=bt(Rr(),1),Xb=bt(ad(),1),Qb=bt(ld(),1),e1=bt(gd(),1),Kh=bt(Lo(),1),t1=bt($h(),1);var Zh=Kh.default;qe();ne();var Ce=G("upstream.frontier"),Jh="application/json",Yh="none",r1=15e3;function i1(t){class e extends Zh{constructor(i){super(i,mu,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Ce.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(nl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Ce.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Ce.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Hi=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Ce.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:wu,...yr(this.opts.ppeOverride)},r=i1(e),i=_u(this.opts.urlOverride),o={url:i,ws:r,fpID:gu,aID:Js,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Jh,force:!0},payloadEncoding:{encoding:Yh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new ex.FWS(o),d=!1,f=null,h,x,m=new Promise((w,E)=>{h=w,x=E}),g=w=>{d||(d=!0,f&&(clearTimeout(f),f=null),w?x(w):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let w=this.openCount===1;Ce.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:w,openCount:this.openCount}),w&&g();for(let E of this.connectHandlers)Promise.resolve(E({initial:w})).catch(I=>Ce.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=w=>{this.opened=!1,Ce.info("frontier closed",{code:w.code,reason:w.reason,willReconnect:w.willReconnect})},c.onerror=w=>{Ce.warn("frontier error",{code:w.code,msg:w.message}),g(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${w.code} msg=${w.message??""}`))},c.onmessage=w=>this.handleMessage(w),this.fws=c;let A=this.opts.openTimeoutMs??r1;f=setTimeout(()=>{g(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${A}ms (handshake or upgrade slow)`))},A),await c.connect();try{await m}catch(w){try{c.close(1e3,"open failed")}catch(E){Ce.warn("fws close during start failure threw (ignored)",{err:String(E)})}throw this.fws=null,this.opened=!1,w}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Ce.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Ce.warn("frontier send refused: upstream not started",{method:i}),new T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let f=Date.now();throw f-this.lastSendRefusedLogAt>1e3?(Ce.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=f,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Xh(c)||Ce.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Jh,payloadEncoding:Yh})}catch(f){throw Ce.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Ce.debug("drop non-adapter frontier frame",{service:r});return}let i=a1(e);if(!i){Ce.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Ce.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Ce.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Xh(c)||Ce.info("frontier frame in",{logid:o1(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:s1(i)}),Promise.resolve(this.handler(o)).catch(d=>Ce.warn("frontier frame handler threw",{err:String(d)}))}};function Xh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Qh=2e3;function s1(t){return t.length<=Qh?t:`${t.slice(0,Qh)}...<truncated, total ${t.length} chars>`}function o1(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function a1(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ne();var wd=G("upstream.switchable"),Mo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;wd.info("swap upstream",{reason:r});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw wd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>wd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}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.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var yd=G("upstream"),Lr=class{handler=null;async start(){yd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){yd.info("NoopUpstream stopped",{reason:e})}async send(e){yd.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)}};qe();ne();ne();ke();import{promises as _d}from"node:fs";import{dirname as c1}from"node:path";var d1=G("pat-token-store");async function Bo(t=Y()){try{let r=(await _d.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&d1.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function qi(t,e=Y()){if(!t)throw new Error("writePatToken: empty patToken");await _d.mkdir(c1(e.patTokenFile),{recursive:!0}),await _d.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as zo}from"node:fs";import{join as l1}from"node:path";function f1(t,e){return`#!/bin/sh
97
+ `}function my(t){if(t.includes(`
98
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var wy={path:"",version:"cloud-deployed"},cf="openclaw_gateway_unavailable",_y="openclaw_default_agent_missing";function df(t){let e=[t.port!==void 0?`port=${t.port}`:"",t.runtime?`runtime=${t.runtime}`:"",t.detail??""].filter(Boolean).join(", ");return`openclaw gateway \u672A\u8FD0\u884C/\u4E0D\u53EF\u8FBE${e?` (${e})`:""}; \u8BF7\u542F\u52A8 openclaw gateway`}var yy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},by=6e4,uo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??py,this.createTimeoutMs=e.createTimeoutMs??by,this.detectorFactory=e.detectorFactory??(()=>new Gn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new co({command:r})),this.openclawConfigDir=e.openclawConfigDir??af(xy(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new D("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{xe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=af(e,".env");if(await fy(r).then(c=>c.isFile()).catch(()=>!1)){xe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await lo(e,{recursive:!0});let o=gy({...process.env,...Wc(this.paths.agentEnvFile)});if(await hy(r,o,"utf8"),process.platform!=="win32")try{await ly(r,384)}catch(c){xe.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}xe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),xe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new D("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new D("IPC_BAD_REQUEST","framework required");let i=Si(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let o=this.registry.get(e.agentId);if(o){if(o.framework!==e.framework)throw new D("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${o.framework})`);if(o.status==="error")xe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(S=>xe.warn("dispose stale agent failed (ignored)",{err:String(S)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){xe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let S=await qe(e.agentId,this.paths).catch(()=>null);S&&(S.patToken=e.patToken,await Ye(S,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){xe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let S=await qe(e.agentId,this.paths).catch(()=>null);S&&(S.modelInfo=e.modelInfo,await Ye(S,this.paths))}return xe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:o.agentId,workspace:o.workspace,framework:o.framework}}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new D("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let l=Ze(e.agentId,this.paths),f=Si(e._meta),h=e.framework==="openclaw"&&f==="local",p;h&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=p??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),E=e.workspace??w??l.workspace,T=new AbortController,_=setTimeout(()=>T.abort(new D("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),v,I=!1;try{i&&$c(e.framework)&&await er(e.framework,T.signal);let S=()=>{if(T.signal.aborted)throw T.signal.reason instanceof Error?T.signal.reason:new D("AGENT_TIMEOUT","_agent/create aborted")};await lo(l.root,{recursive:!0}),await lo(E,{recursive:!0}),await lo(l.logs,{recursive:!0}),S(),h||await rr(E,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await _l(E),S();let R=await qe(e.agentId,this.paths).catch(()=>null),L=E0({model:e.model??R?.model}),y=x0(e._meta)??R?.accountId,C=e.patToken??R?.patToken,O=f==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(v=new oo({agentId:e.agentId,framework:e.framework,workspace:E,model:L.model??bt,deployType:f,...y?{accountId:y}:{},...C?{patToken:C}:{},...O?{modelInfo:O}:{}}),v.status="ok",R?.sessions){for(let[J,te]of Object.entries(R.sessions))v.sessions.set(J,{acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let V=Object.keys(R.sessions).length;V>0&&xe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:V})}this.registry.register(v),I=!0;let B={agentId:e.agentId,framework:e.framework,workspace:E,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:L.model};f==="cloud"&&(B.deployType="cloud"),y&&(B.accountId=y),C&&(B.patToken=C),O&&(B.modelInfo=O),R?.skills&&(B.skills=R.skills),R?.agentName&&(B.agentName=R.agentName),R?.description&&(B.description=R.description),e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,E)):xe.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 V=[...B.skills??[]],J=new Map(V.map((ye,he)=>[ye.skillId,he])),te=await Promise.allSettled(F.map(ye=>Hc({agentId:e.agentId,workspace:E,framework:e.framework,skill:ye}))),Q=0;for(let[ye,he]of te.entries()){let P=F[ye];P&&(he.status==="fulfilled"?(qc(V,J,he.value),Q++):xe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:P.skillId,skillName:P.skillName,err:String(he.reason)}))}Q>0&&(B.skills=V,xe.info("initialSkills installed",{agentId:e.agentId,installed:Q,requested:F.length}))}return await Ye(B,this.paths),xe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:E,framework:e.framework}}catch(S){throw xe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(S)}),I&&v&&(await v.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await uy(l.root,{recursive:!0,force:!0}).catch(R=>xe.warn("rm agent dir failed (ignored)",{err:String(R)})),S instanceof D?S:new D("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(_)}}async spawnSessionDownstream(e,r,i,o,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&$c(e.framework))f=wy;else throw new D("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);$c(e.framework)&&!ns(e.framework)&&(xe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await er(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;e.framework==="openclaw"?p=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:f.path}):p=this.factory(e.framework,f.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv());try{return await p.start(),await p.initialize(yy),p}catch(w){let E=p instanceof Pt?p.getStderrTail():[];throw E.length>0&&xe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof D?w.code:"unknown",recentStderr:E}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,w)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new D("AGENT_ENV_NOT_READY",df(o),{cause:{reason:cf}})}catch(o){xe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof D?new D(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new D("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};xe.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return xe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new D("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:_y}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new D("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new D("AGENT_ENV_NOT_READY",df(r),{cause:{reason:cf}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:f}=e,h=Kc(o);if(r.deployType==="local"){let T=await this.ensureOpenclawDefaultAgent();return new Tr({command:f,cwd:T.workspace,agentId:T.id,sessionName:h})}let p=await of(),w=i?D0(i,c,l):null,E;if(w){let T=Nc(o),v=w.models[0]?.id??bt,I=`${T}/${v}`;if(!this.ensuredProviders.has(I)){let S=this.getOpenclawConfig();await S.ensureProvider(T,w),await S.addModelToAllowlist(I),this.ensuredProviders.add(I)}E=I}return new Tr({command:f,cwd:r.workspace,agentId:r.agentId,sessionName:h,...p?{gatewayToken:p}:{},...E?{slashModelOnStart:E}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Nc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(f){l=!1,xe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(f)})}try{await r.removeModelFromAllowlist(c)}catch(f){l=!1,xe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(f)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as xf}from"node:crypto";import{promises as Ry}from"node:fs";import{basename as pf}from"node:path";Ke();ne();import{promises as vy}from"node:fs";import{basename as Sy}from"node:path";var lf=G("file-upload"),Iy="/api/coze_claw/file/agent_upload",Ay=6e4;async function uf(t,e={}){let i=`${Ys(Qs(e.handshakeBase))}${Iy}`,o=e.timeoutMs??Ay,c=await vy.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let f={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...br(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,p=setTimeout(()=>h.abort(),o);lf.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let w=await fetch(i,{method:"POST",headers:f,body:l,signal:h.signal}),E=w.headers.get("x-tt-logid")??"";if(!w.ok){let v=await w.text().catch(()=>"");throw new D("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${E}: ${v.slice(0,200)}`)}let T=await w.json();if(T.code!==void 0&&T.code!==0)throw new D("UPLOAD_FAILED",`upload code=${T.code} msg=${T.msg??"-"} logid=${E}`);let _=T.data?.file?.file_url;if(!_)throw new D("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${E}: ${JSON.stringify(T).slice(0,200)}`);return lf.info("file upload ok",{uri:_,logid:E}),{uri:_}}catch(w){throw w instanceof D?w:w.name==="AbortError"?new D("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Sy(t.path)}`):new D("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(p)}}Ke();ne();import{extname as Ty}from"node:path";var Dy={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function ff(t){let e=Ty(t).toLowerCase();return Dy[e]??"application/octet-stream"}Ce();var fo=G("agent-send"),hf=50*1024*1024;function gf(t,e,r){let i=t.get(e);if(!i)throw new D("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new D("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new D("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function mf(t,e,r,i,o,c){let f;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){f=p,h<2&&(fo.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(p)}),await new Promise(w=>setTimeout(w,5e3)))}throw new D("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(f)}`,{cause:f})}async function wf(t,e){let{session:r,runtime:i}=gf(e.core,t.agentId,t.sessionId);if(!await Zr(t.path,r.workspace))throw new D("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Ry.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new D("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>hf)throw new D("FILE_TOO_LARGE",`${o.size} bytes > limit ${hf}`);let c=await ff(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new D("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new D("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??pf(t.path),f;try{f=await uf({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(p){throw fo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof D?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let h={sessionUpdate:"agent_file",messageId:xf(),content:{type:t.kind==="image"?"image":"resource",uri:f.uri,mimeType:c,name:l,sizeBytes:o.size,...f.fileId!==void 0?{fileId:f.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await mf(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),fo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:f.uri}),{ok:!0,uri:f.uri,bytes:o.size,mimeType:c,...f.fileId!==void 0?{fileId:f.fileId}:{}}}async function _f(t,e){let{session:r,runtime:i}=gf(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new D("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new D("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??pf(t.path),c={sessionUpdate:"group_file",messageId:xf(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await mf(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),fo.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function yf(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,f=i[c]??0;if(l<f)return!0;if(l>f)return!1}return!1}nn();yn();ne();var Lt=G("coze-cli-installer"),bf="@coze/cli@latest",Cy="coze",Ef="0.1.8",ky=5e3,Oy=5e3,Py=9e4,vf=1e4,Pi=null,ho=!1;async function Vc(t,e={}){if(ho)return;if(Pi)return Pi;let r=e.exec??V0;return Pi=(async()=>{try{let i=await Ly(Cy,r),o=!1;if(i){let l=await Ny(r);if(l===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(yf(l,Ef))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:Ef}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),ho=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:bf,mode:c});try{await r("npm",["i","-g","--prefer-online",bf],{timeout:Py,maxBuffer:10*1024*1024}),Lt.info("coze-cli install ok")}catch(l){Lt.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){ho=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:vf}),Lt.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Lt.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:vf}),Lt.info("coze auth login ok")}catch(l){Lt.warn("coze auth login failed",{err:String(l)});return}ho=!0}finally{Pi=null}})(),Pi}async function Ly(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:ky});return ya(i)}catch{return}}async function Ny(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Oy});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Jr();Ce();var My=10*6e4;function Sf(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?My:e}function xo(t){return tr(t??X().configFile)}function Li(t,e){return nr(e??X().configFile,t)}import{randomBytes as nb}from"node:crypto";Yi();Ke();ne();import{createReadStream as By}from"node:fs";import{mkdir as zy,readFile as Fy,realpath as Uy,stat as Gy,writeFile as Hy}from"node:fs/promises";import{basename as qy,dirname as Jc,isAbsolute as jy,join as Wy,relative as Ky,resolve as If,sep as $y}from"node:path";import{createInterface as Vy}from"node:readline";var Tf=G("fs-rpc"),Ni=Ft("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Df(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Ni)throw new D("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Ni} bytes`);let i=await Cf(t.path,e);return await zy(Jc(i),{recursive:!0}),await Hy(i,t.content,"utf8"),Tf.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Rf(t,e){let r=await Cf(t.path,e),i=await Gy(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Ni&&!o)throw new D("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Ni} bytes`);let c;if(o&&i.size>Ni)c=await Jy(r,t.line??1,t.limit);else{let l=await Fy(r,"utf8");if(o){let f=l.split(`
99
+ `),h=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?h+t.limit:void 0;c=f.slice(h,p).join(`
100
+ `)}else c=l}return Tf.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Jy(t,e,r){let i=Vy({input:By(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],f=0;try{for await(let h of i)if(f>=o&&f<c&&l.push(h),f++,f>=c)break}finally{i.close()}return l.join(`
101
+ `)}async function Cf(t,e){if(typeof t!="string"||t.length===0)throw new D("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([Af(If(e)),Af(If(t))]),o=Ky(r,i);if(Zy(o,$y,jy(o)))throw new D("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Zy(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function Af(t){let e=[],r=t;for(;r!==Jc(r);)try{let i=await Uy(r);return e.length?Wy(i,...e.reverse()):i}catch{e.push(qy(r)),r=Jc(r)}return t}ne();var kf=G("prompt-multimodal"),Of=10*1024*1024,Yy=15e3,Xy=6;async function Pf(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,l=t[c];l!==void 0&&(e[c]=await Qy(l))}}let o=Array.from({length:Math.min(Xy,t.length)},()=>i());return await Promise.all(o),e}function Lf(t){return t.some(e=>e.type==="image")}async function Qy(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Zs(e.uri))return t;try{let{buf:r,contentType:i}=await tb(e.uri),o=e.mimeType||eb(i)||"application/octet-stream";return kf.info("image uri fetched and inlined",{uri:e.uri,bytes:r.length,mimeType:o}),{type:"image",data:r.toString("base64"),mimeType:o}}catch(r){return kf.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function eb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function tb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Yy);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new Error(`HTTP ${i.status} ${i.statusText}`);let o=await i.arrayBuffer();if(o.byteLength>Of)throw new Error(`image too large: ${o.byteLength} bytes (max ${Of})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();Ke();ne();var $=G("core"),rb=3e4,ib=/^(boe|ppe)_[A-Za-z0-9_-]+$/,sb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",ob="\u5BA1\u6279\u5DF2\u8D85\u65F6",ab=3e4,po=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Ar;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=Sf(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),$.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){$.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),$.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){$.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}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)&&$.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{$.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Oi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){$.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(_n(o,{code:ee.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>$.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:ee.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){$.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:ee.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new D("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(no(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&ib.test(i)?this.currentCozeEnv=i:i&&$.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):$.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Ir(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Ir(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Ir(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):$.warn("drop unknown notification",{method:e.method})}catch(o){$.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(_n(r,ki(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new D("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new D("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new D("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new D("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let p=r._meta?.cozeTriggerMsgId,w=Cc(r._meta);return $.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,sb,p,w)}}let l=Date.now(),f=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return f=!0,h}finally{$.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:f})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=p0(i);switch(r){case"session/new":{let c=cb();return $.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return $.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new D("IPC_BAD_REQUEST","session/prompt: missing sessionId");let f=await this.ensureRuntime(e,l);if(f.replySeq=0,await this.ensureDownstream(e,l,f),!f.downstream||!f.acpSessionId)throw new D("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(f.acpSessionId,h):e.activeTriggers.delete(f.acpSessionId);let p=Cc(i._meta);if(p?e.activeGroupIds.set(f.acpSessionId,p):e.activeGroupIds.delete(f.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Lf(c.prompt))throw new D("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await Pf(c.prompt);try{let E=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:w});return f.lastActiveAt=Date.now(),E}catch(E){if(E instanceof D&&E.code==="AGENT_APPROVAL_TIMEOUT"){let T=f.pendingPermission;T&&(T.downstream.respondAgentRequest(T.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(T.upstreamId),f.pendingPermission=void 0);let _=f.acpSessionId,v=_?e.activeTriggers.get(_):void 0,I=_?e.activeGroupIds.get(_):void 0;return $.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,f,l,ob,v,I)}throw E}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let E=f.downstream;E&&(f.downstream=void 0,$.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:f.acpSessionId}),E.stop("reload-after-turn").catch(T=>$.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(T)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,l,f)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new D("IPC_BAD_REQUEST","session/cancel: missing sessionId");let f=e.sessions.get(l);if(e.hasSessionQueue(l)){let h=e.getSessionQueue(l);h.size>0&&($.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:h.size}),h.dispose(new D("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return f?.downstream?.isAlive()&&f.acpSessionId&&await f.downstream.sessionCancel({sessionId:f.acpSessionId}),{ok:!0}}default:throw new D("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(yt.GEN_MODEL_TOKEN,i,ab);if(!o?.modelToken)throw new D("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof D&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new D("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Oi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new D("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,f=i.spawnFailedAt??0;if(l>=o&&Date.now()-f<c)throw new D("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-f))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&($.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}if(i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i),i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),$.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){$.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let w=await h.sessionNew({cwd:e.workspace});i.acpSessionId=w.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let p=await h.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Oi(i),this.isRuntimeBusy(e,i)){$.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){$.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}$.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>$.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let l=e.activeTriggers.get(r.acpSessionId);l&&(c.cozeTriggerMsgId=l);let f=e.activeGroupIds.get(r.acpSessionId);f&&(c.cozeGroupId=f)}await this.upstream.send(Sr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let f={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(f.cozeTriggerMsgId=c),l&&(f.cozeGroupId=l),await this.upstream.send(Sr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:f})).catch(h=>$.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){$.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){$.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(ub(r)){$.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(l.cozeTriggerMsgId=f);let h=e.activeGroupIds.get(i);h&&(l.cozeGroupId=h),this.upstream.send(Sr("session/update",{...r,sessionId:o,_meta:l})).catch(p=>$.warn("forward update failed",{agentId:e.agentId,err:String(p)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}$.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:ee.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await Df(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await Rf(c,o);r.respondAgentRequest(i.id,l)}}catch(o){$.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,ki(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},f=c.sessionId,h=f?e.activeTriggers.get(f):void 0,p={cozeAgentId:e.agentId};h&&(p.cozeTriggerMsgId=h);let w=f?e.activeGroupIds.get(f):void 0;w&&(p.cozeGroupId=w);let E=f?this.reverseSessionId(e,f):void 0,T=E?e.sessions.get(E):void 0;T&&(T.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...E?{sessionId:E}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:E}),$.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:f,cloudSessionId:E,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Ri(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),$.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?($.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&db(e.result,o),$.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new to(e.error)):i.value.resolve(e.result);return}$.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),l=e.get(c);if(l)return $.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=rb){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let f=setTimeout(()=>{this.pendingBridge.delete(o),l(new D("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:f}),this.upstream.send(Ri(o,e,r)).catch(h=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),l(h)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),r.set(i,c)}await Yr(e.agentId,r,this.paths)}catch(r){$.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(_n(e,{code:r,message:i,data:{bridgeVersion:vr}}))}};function cb(){return nb(16).toString("hex")}function db(t,e){if(!t||typeof t!="object"){$.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){$.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){$.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&$.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var lb=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function ub(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let r=e.content;if(!r||typeof r!="object")return!1;let i=r;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return lb.some(c=>o.startsWith(c))}ne();Ce();import{randomBytes as fb}from"node:crypto";import{chmod as hb,mkdir as xb,writeFile as Nf}from"node:fs/promises";import{createServer as pb}from"node:http";import{dirname as gb}from"node:path";var mb=1e6,Zc=G("ipc"),go=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??X()}async start(){this.token=fb(32).toString("hex");let e=pb((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),Zc.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await xb(gb(this.paths.portFile),{recursive:!0}),await Nf(this.paths.portFile,String(this.port),"utf8"),await Nf(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await hb(this.paths.tokenFile,384)}catch(e){Zc.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Mi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Mi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await wb(e)}catch(f){Mi(r,400,{error:"invalid json",detail:String(f)});return}try{let f=await c.handler(l,e);Mi(r,200,f??{ok:!0})}catch(f){Zc.error("IPC handler failed",{key:o,err:String(f)}),Mi(r,500,{error:f instanceof Error?f.message:String(f)})}}};function Mi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function wb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>mb)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var rx=It(Kf(),1);var XE=It(Gh(),1),QE=It(Oo(),1),ev=It(Cr(),1),tv=It(dd(),1),nv=It(fd(),1),rv=It(wd(),1),Zh=It(Mo(),1),iv=It(Jh(),1);var Yh=Zh.default;Ke();ne();var De=G("upstream.frontier"),Qh="application/json",ex="none",ov=15e3;function av(t){class e extends Yh{constructor(i){super(i,m0,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>De.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(rl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");De.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){De.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Wi=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){De.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:w0,...br(this.opts.ppeOverride)},r=av(e),i=y0(this.opts.urlOverride),o={url:i,ws:r,fpID:g0,aID:Xs,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Qh,force:!0},payloadEncoding:{encoding:ex,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new rx.FWS(o),l=!1,f=null,h,p,w=new Promise((_,v)=>{h=_,p=v}),E=_=>{l||(l=!0,f&&(clearTimeout(f),f=null),_?p(_):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;De.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&E();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(I=>De.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,De.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{De.warn("frontier error",{code:_.code,msg:_.message}),E(new D("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let T=this.opts.openTimeoutMs??ov;f=setTimeout(()=>{E(new D("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${T}ms (handshake or upgrade slow)`))},T),await c.connect();try{await w}catch(_){try{c.close(1e3,"open failed")}catch(v){De.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){De.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw De.warn("frontier send refused: upstream not started",{method:i}),new D("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let f=Date.now();throw f-this.lastSendRefusedLogAt>1e3?(De.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=f,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new D("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;tx(c)||De.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Qh,payloadEncoding:ex})}catch(f){throw De.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new D("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){De.debug("drop non-adapter frontier frame",{service:r});return}let i=lv(e);if(!i){De.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){De.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){De.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;tx(c)||De.info("frontier frame in",{logid:dv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:cv(i)}),Promise.resolve(this.handler(o)).catch(l=>De.warn("frontier frame handler threw",{err:String(l)}))}};function tx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var nx=2e3;function cv(t){return t.length<=nx?t:`${t.slice(0,nx)}...<truncated, total ${t.length} chars>`}function dv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function lv(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ne();var yd=G("upstream.switchable"),zo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;yd.info("swap upstream",{reason:r});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw yd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>yd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}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.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var bd=G("upstream"),Mr=class{handler=null;async start(){bd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){bd.info("NoopUpstream stopped",{reason:e})}async send(e){bd.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)}};Ke();ne();ne();Ce();import{promises as Ed}from"node:fs";import{dirname as uv}from"node:path";var fv=G("pat-token-store");async function Fo(t=X()){try{let r=(await Ed.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&fv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Ki(t,e=X()){if(!t)throw new Error("writePatToken: empty patToken");await Ed.mkdir(uv(e.patTokenFile),{recursive:!0}),await Ed.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Ce();Ce();import{promises as Uo}from"node:fs";import{join as hv}from"node:path";function xv(t,e){return`#!/bin/sh
102
102
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
103
- `}function u1(t,e){return`@echo off\r
103
+ `}function pv(t,e){return`@echo off\r
104
104
  "${e}" "${t}" %*\r
105
- `}async function tx(t,e=Y()){let r=e.binDir;await zo.mkdir(r,{recursive:!0});let i=l1(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?u1(t,o):f1(t,o);return await zo.readFile(i,"utf8").catch(()=>null)===c||(await zo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await zo.chmod(i,493)),r}ne();ke();import{execSync as nx}from"node:child_process";import{readFileSync as rx,unlinkSync as h1}from"node:fs";import{mkdir as x1,readFile as ix,unlink as sx,writeFile as p1}from"node:fs/promises";import{dirname as g1}from"node:path";function Fo(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}var m1=G("single-instance"),Uo=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Y().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&&(m1.warn("removing stale pid file",{stalePid:e}),await sx(this.pidFile).catch(()=>{})),await x1(g1(this.pidFile),{recursive:!0}),await p1(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await ix(this.pidFile,"utf8")).trim()===String(process.pid)&&await sx(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await ix(this.pidFile,"utf8"),r=Number.parseInt(e.trim(),10);return Number.isFinite(r)&&r>0?r:null}catch(e){if(e.code==="ENOENT")return null;throw e}}isAlive(e){return Fo(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=rx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=nx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes("coze-bridge-daemon")||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=nx(`tasklist /FI "PID eq ${e}" /FO CSV /NH`,{stdio:["ignore","pipe","ignore"],timeout:2e3}).toString().trim();if(!i||/^(INFO|信息)[::]/.test(i))return!1;let o=i.split(",",1)[0]?.replace(/^"|"$/g,"").toLowerCase()??"";return o.includes("node")||o.includes("coze-bridge")}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{rx(this.pidFile,"utf8").trim()===String(process.pid)&&h1(this.pidFile)}catch{}})}};Go();ne();var Wn=G("daemon.upstream-watchdog"),I1=12e4,A1=9e5,T1=3e4;function bd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",I1),this.hardMs=e.hardMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",A1),this.intervalMs=e.intervalMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",T1),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),Wn.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&Wn.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&Wn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Wn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Wn.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,Wn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Wn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var q=G("daemon"),R1="coze-bridge-daemon";async function cx(){let t=Y();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&el({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Ze(O,t).logs,listAgentIds:()=>ts(t)});let e=new Uo({processTitle:R1}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await uo(),o=i??{};Qi({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");try{let O=new Fn;o.frameworksCache=await O.detectAll(),q.info("refreshed frameworks_cache",{detected:Object.keys(o.frameworksCache)})}catch(O){q.warn("framework detection failed",{err:String(O)})}await Oi(o);let c=new Mo(new Lr),d=null,f=new ho({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,j,W,ie)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(O,j,W,ie)}});await D1(t,f);let h=new co({paths:t,config:o,registry:f});d=h;let x,m,g=null,A={},w,E=null,I=null,S=null,R=new yn;function P(O,j){return R.enqueue(()=>C(O,j))}function y(){I||(I=new jo({isConnected:()=>c.isConnected(),forceReconnect:()=>S?P(S,{force:!0}):void 0,onFatal:O=>{if(process.env[Wi]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),I.start()}async function C(O,j){let W=O,ie=W?.privatecode;if(!ie)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let $e=Si(W.env),le=W.handshake_url,fe=W.frontier_url,Et=ax(W.env,le,fe);if(S=W,!j?.force&&x===ie&&m===Et){let ge=await C1(t);return f.agents.size===0&&ge?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),qo(t,h).catch(Ie=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let lt=!!x&&x!==ie,Vt=m!==void 0&&m!==Et,Nt=lt||Vt,Jt=await Cc({privatecode:ie,...le?{endpoint:le}:{},ppeOverride:$e});if(Nt){q.warn("connect config switched, resetting agents",{pcChanged:lt,envChanged:Vt,previousPc:x?Ho(x):"",nextPc:Ho(ie)});for(let ge of[...f.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),f.agents.delete(ge.agentId);f.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on connect config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Lr,"connect switch").catch(()=>{})}g=Jt.deviceId,Qi({deviceId:g,pid:process.pid}),$c({patToken:ie,env:W.env}).catch(ge=>q.warn("coze-cli setup error (ignored)",{err:String(ge)}));let Fr=new Hi({handshake:Jt,privatecode:ie,...fe?{urlOverride:fe}:{},ppeOverride:$e,getPatTokenForAgent:ge=>f.agents.get(ge)?.patToken});return await c.swap(Fr,"connect"),x=ie,m=Et,A=$e,w=le,W.mock_scenario!==void 0&&(f.setMockScenario(W.mock_scenario),q.info("mock scenario set",{scenario:W.mock_scenario})),E||(E=new Ai({core:f,getDeviceId:()=>g??"",onTickEnd:()=>M.retryPending().catch(ge=>q.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:K})),E.start(),y(),Nt&&qo(t,h).catch(ge=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),qi(ie,t).catch(ge=>q.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),q.info("/connect: WS established",{deviceId:g}),{ok:!0,note:"connected"}}f.registerExtension("_agent/create",async O=>h.createAgent(O.params)),f.registerExtension("_agent/health",async()=>({ok:!0}));let D={},N=new Xs({agents:f.agents,disposeAndMarkDisconnected:async(O,j)=>{let W=f.agents.get(O);if(W){await h.cleanupOpenclawSessionProviders(W).catch($e=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String($e)}));let ie=!0;try{await W.dispose(`disconnect: ${j}`)}catch($e){ie=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String($e)}),W.status="error"}ie&&(W.status="disconnected",f.unregister(O),f.disconnectedAgents.add(O))}else f.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!D.ref)throw new Error("agent-detail-sync not initialized yet");await D.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await h.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,j)=>{await h.openclawRepair(O,j)},isRuntimePendingPermission:O=>f.hasPendingPermissionFor(O)});f.registerExtension("_agent/listSkills",O=>N.listSkills(O.params)),f.registerExtension("_agent/addSkills",O=>N.addSkills(O.params)),f.registerExtension("_agent/removeSkills",O=>N.removeSkills(O.params)),f.registerExtension("_agent/getFileTree",O=>N.getFileTree(O.params)),f.registerExtension("_agent/getFileContent",O=>N.getFileContent(O.params)),f.registerExtension("_agent/update",O=>N.updateAgent(O.params)),f.registerExtension("_agent/disconnect",O=>N.disconnectAgent(O.params)),f.registerExtension("_agent/switchModel",O=>N.switchModel(O.params)),f.registerExtension("_agent/reset",O=>N.resetAgent(O.params)),f.registerExtension("_agent/repair",O=>N.repairAgent(O.params));let M=new ss({paths:t,handlers:N,sendDetail:O=>f.sendRequest("_agent/detail",O)});D.ref=M;let K=async O=>{await Promise.allSettled(O.map(async j=>{try{await N.disconnectAgent({agentId:j.agentId,reason:`auth_failure: code=${j.code} ${j.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:j.agentId,code:j.code,message:j.message})}catch(W){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:j.agentId,err:String(W)})}}))};c.onConnect(({initial:O})=>{q.info("frontier upstream connected, triggering detail sync",{initial:O}),M.syncAll(O?"initial-connect":"reconnect").catch(j=>q.warn("detail sync top-level error (ignored)",{err:String(j)}))});let Z=new xo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=f.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Wi]==="1"?"manual":"supervisor",agents:[...f.agents.keys()],deviceId:g??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let j=O,W=j?.privatecode,ie=j?.pairing_code;if(!W||!ie)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let $e=Si(j.env),le=j.handshake_url,fe=j.frontier_url,Et=ax(j.env,le,fe),lt=!!x&&x!==W,Vt=m!==void 0&&m!==Et,Nt=lt||Vt,Jt=await Cc({privatecode:W,...le?{endpoint:le}:{},ppeOverride:$e});if(Nt){q.warn("pair config switched, resetting agents",{pcChanged:lt,envChanged:Vt,previousPc:x?Ho(x):"",nextPc:Ho(W),previousEnvKey:m??"",nextEnvKey:Et});for(let Ie of[...f.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),f.agents.delete(Ie.agentId);f.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on pair config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Lr,"pair switch").catch(()=>{})}g=Jt.deviceId,Qi({deviceId:g,pid:process.pid}),$c({patToken:W,env:j.env}).catch(Ie=>q.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Fr=new Hi({handshake:Jt,privatecode:W,...fe?{urlOverride:fe}:{},ppeOverride:$e,getPatTokenForAgent:Ie=>f.agents.get(Ie)?.patToken});await c.swap(Fr,"pair");try{let Ie=new Fn;o.frameworksCache=await Ie.detectAll(),await Oi(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let ge=Object.keys(o.frameworksCache??{});try{let Ie=await f.sendRequest("_agent/pair",{pairCode:ie,patToken:W,frameworks:ge,_meta:{cozeDeviceId:g}});q.info("_agent/pair ok",{pairResult:Ie}),x=W,m=Et,A=$e,w=le,j.mock_scenario!==void 0&&(f.setMockScenario(j.mock_scenario),q.info("mock scenario set",{scenario:j.mock_scenario})),qi(W,t).catch(De=>q.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),E||(E=new Ai({core:f,getDeviceId:()=>g??"",onTickEnd:()=>M.retryPending().catch(De=>q.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:K})),E.start(),y(),Nt&&qo(t,h).catch(De=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let $n;return j.agent_id&&($n=await k1(j.agent_id,t,h,De=>f.sendRequest("_agent/detail",De),W).catch(De=>(q.error("--agent-id ensureAgent failed",{agentId:j.agent_id,err:String(De)}),{ok:!1,agentId:j.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...$n?{agent:$n}:{}}}catch(Ie){return q.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:O=>P(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let j=O;return{ok:!0,result:await h.createAgent(j)}}},{method:"POST",path:"/agent/send",handler:async O=>{let j=O;if(!j?.agentId||!j?.sessionId||!j?.kind||!j?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=j;return await(W.groupFile?g0:p0)(W,{core:f,patToken:x,handshakeBase:w,ppeOverride:A})}catch(W){if(W instanceof T)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async O=>{let j=O?.agent_id,W=await f.reloadAgents(j);return q.info("IPC /reload: recycled agent subprocesses",{agentId:j??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:X}=await Z.start();try{await tx(t.libEntry,t)}catch(O){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await f.start(),qo(t,h).catch(O=>q.warn("auto-revive top-level error (ignored)",{err:String(O)})),ll().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(en(),cl));for(let j of["claude-code","codex"]){let W=await O(j);W&&q.info("acp wrapper version",{framework:j,version:W})}}).catch(O=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let _e=null,he={port:te,token:X,core:f,ipc:Z,shutdown(O){return _e||(q.info("daemon shutdown",{reason:O}),_e=(async()=>{E?.stop(),I?.stop(),await f.stop(O),await Z.stop(),await e.release()})(),_e)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{he.shutdown(O).then(()=>process.exit(0))});return process.on("unhandledRejection",O=>{q.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{q.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
106
- `)}catch{}process.exit(1)}),q.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),O1({cliSpawned:process.env[Wi]==="1",readPatToken:()=>Bo(t),connect:P}).catch(O=>q.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),he}async function C1(t){return ts(t).length>0}function Ho(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function ax(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function D1(t,e){let r=ts(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(tn(),is));for(let c of r){await o(c,t).catch(d=>q.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.disconnectedAt&&(e.disconnectedAgents.add(c),q.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){q.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function k1(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(tn(),is)),d=await c(t,e);if(d){q.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let m={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{}};return await r.createAgent(m),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}q.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let f=await i({_meta:{cozeAgentId:t}});if(!f.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \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}:{},...o?{patToken:o}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await r.createAgent(h);let x=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function qo(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(tn(),is));q.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let f of i){let h;try{h=await o(f,t)}catch(x){q.warn("auto-revive: load config failed (skipping)",{agentId:f,err:String(x)}),d+=1;continue}if(!h){d+=1;continue}if(h.disconnectedAt){q.info("auto-revive: skip disconnected agent",{agentId:f,disconnectedAt:h.disconnectedAt}),d+=1;continue}try{q.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:f,framework:h.framework});let x=P1(h);await e.createAgent({agentId:h.agentId,framework:h.framework,...h.cozeIdentity?{cozeIdentity:h.cozeIdentity}:{},...h.model?{model:h.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){q.warn("auto-revive: createAgent failed (skipping)",{agentId:f,framework:h.framework,err:String(x)}),d+=1}}return q.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function O1(t){let e=t.logger??q;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function P1(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Go();ke();import{readFile as dx}from"node:fs/promises";var Zt=class{paths;constructor(e){this.paths=e??Y()}async probe(e=1e3){let r=await Wo(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:N1(i)}}}async request(e){let r=await Wo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let f=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),h=await f.text();return{status:f.status,body:L1(h)}}finally{clearTimeout(d)}}};async function Wo(t){try{let[e,r]=await Promise.all([dx(t.portFile,"utf8"),dx(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=r.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function L1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function N1(t){return t instanceof Error?t.message:String(t)}wn();ne();ke();function bn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let f of e){if(c===f){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${f}=`)){i=c.slice(f.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}en();import{chmod as M1,copyFile as lx,mkdir as ux,readFile as $o,rename as fx,rm as vd,stat as hx,writeFile as B1}from"node:fs/promises";import{homedir as x3}from"node:os";import{dirname as z1,join as Nr,resolve as Sd,sep as $i}from"node:path";import{fileURLToPath as F1}from"node:url";wn();ne();ke();var Id=G("dist-install");function U1(t){let e=F1(t),r=z1(e),i=`${$i}src${$i}`;if(r.includes(i)||r.endsWith(`${$i}src${$i}cli`))return null;let o=Sd(r,"index.js"),c=Sd(r,"..","package.json");return{dist:o,pkgJson:c}}async function Td(t={}){let e=t.paths??Y(),r=U1(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let A=JSON.parse(await $o(o,"utf8"));c=A.version??"unknown",d=A.dependencies??{}}catch(A){return Id.warn("cannot read source package.json,skip dist install",{err:String(A)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(A)}`}}let f=Wr.map(A=>`${A}@${d[A]??"latest"}`),h=await uo(e.configFile)??{},x=h.libVersion,m=await $o(e.libEntry).then(()=>!0).catch(()=>!1),g=x===c;if(g&&m&&await Ad(e))return{kind:"already-current",libVersion:c};if(!g||!m){await ux(e.libDir,{recursive:!0}),await lx(i,e.libEntry),await lx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let A=Sd(e.libDir,"package.json"),w=`${JSON.stringify({type:"module"},null,2)}
107
- `;await $o(A,"utf8").catch(()=>null)!==w&&await B1(A,w)}return(!g||!await Ad(e))&&await(t.installWrappers??G1)(e,f),h.libVersion=c,await Oi(h,e.configFile),Id.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),g&&m?{kind:"already-current",libVersion:c}:x?{kind:"version-changed",fromVersion:x,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Ad(t){for(let e of Wr){let r=Nr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await hx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function G1(t,e){await q1(t.installLock,async()=>{if(await Ad(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${$i}.staging-${process.pid}-${r}`,o=Nr(i,"node_modules"),c=Nr(t.libDir,"node_modules");try{await ux(i,{recursive:!0}),await j1(e,i),await H1(o);let d=`${c}.trash-${r}`;await fx(c,d).catch(()=>{}),await fx(o,c),await vd(d,{recursive:!0,force:!0}).catch(()=>{}),Id.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await vd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function j1(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=at("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",h=>{d.length<8192&&(d+=h.toString("utf8"))});let f=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(f),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(f),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${d.trim().slice(0,2e3)}`))})})}async function H1(t){for(let e of Wr){let r=Nr(t,...e.split("/")),i=JSON.parse(await $o(Nr(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Nr(t,".bin",o),d=await hx(c);process.platform!=="win32"&&!(d.mode&73)&&await M1(c,d.mode|73).catch(()=>{})}}async function q1(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await vd(t,{force:!0}).catch(()=>{})}}xa();ne();ke();import{closeSync as px,fstatSync as gx,openSync as mx,readFileSync as W1,readSync as $1,readdirSync as K1,statSync as Z1}from"node:fs";import{join as Ko}from"node:path";var V1=new Set(["debug","info","warn","error"]);function yx(t){let e=t,r=bn(e,"--agent-id");e=r.rest;let i=bn(e,"--date");e=i.rest;let o=bn(e,"-n","--lines");e=o.rest;let c=bn(e,"--level");e=c.rest;let d=bn(e,"--grep");e=d.rest;let f=o.value===void 0?200:Number(o.value),h=Number.isInteger(f)&&f>=0?f:200,x=c.value&&V1.has(c.value)?c.value:void 0,m={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),x&&(m.level=x),d.value&&(m.grep=d.value),m}function J1(t,e){return t.agentId?Ko(Ze(t.agentId,e).logs,Jn("agent",t.date)):Ko(e.bridgeLogsDir,Jn("bridge",t.date))}function Y1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function X1(t,e){let r;try{r=K1(t)}catch{return[]}let i=[];for(let o of r){let c=ha(o,e);if(!c)continue;let d=0;try{d=Z1(Ko(t,o)).size}catch{}i.push({file:Ko(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function _x(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let r;try{r=JSON.parse(t).level}catch{return!0}if(typeof r=="string"&&!rl(r,e.level))return!1}return!0}var xx={debug:"90",info:"36",warn:"33",error:"31"},Q1=new Set(["ts","level","module","msg"]);function ev(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Ex(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=ev(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&xx[o]&&(c=`\x1B[${xx[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",f=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([x])=>!Q1.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${d} ${f}${h}`}function tv(t,e,r){let c=W1(t,"utf8").split(`
108
- `).filter(d=>d.length>0).filter(d=>_x(d,{level:e.level,grep:e.grep}));for(let d of Y1(c,e.lines))process.stdout.write(`${Ex(d,{raw:e.raw,color:r})}
109
- `)}async function bx(t,e){let r=e.paths??Y(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,f=t.agentId?"agent":"bridge",h=X1(d,f);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
110
- `),1;for(let x of h)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
111
- `);return 0}let o=t.date??Sn(new Date),c=J1({agentId:t.agentId,date:o},r);try{tv(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
105
+ `}async function ix(t,e=X()){let r=e.binDir;await Uo.mkdir(r,{recursive:!0});let i=hv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?pv(t,o):xv(t,o);return await Uo.readFile(i,"utf8").catch(()=>null)===c||(await Uo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Uo.chmod(i,493)),r}ne();Ce();import{execSync as sx}from"node:child_process";import{readFileSync as ox,unlinkSync as gv}from"node:fs";import{mkdir as mv,readFile as ax,unlink as cx,writeFile as wv}from"node:fs/promises";import{dirname as _v}from"node:path";function Go(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}var yv=G("single-instance"),Ho=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??X().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&&(yv.warn("removing stale pid file",{stalePid:e}),await cx(this.pidFile).catch(()=>{})),await mv(_v(this.pidFile),{recursive:!0}),await wv(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await ax(this.pidFile,"utf8")).trim()===String(process.pid)&&await cx(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await ax(this.pidFile,"utf8"),r=Number.parseInt(e.trim(),10);return Number.isFinite(r)&&r>0?r:null}catch(e){if(e.code==="ENOENT")return null;throw e}}isAlive(e){return Go(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=ox(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=sx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes("coze-bridge-daemon")||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=sx(`tasklist /FI "PID eq ${e}" /FO CSV /NH`,{stdio:["ignore","pipe","ignore"],timeout:2e3}).toString().trim();if(!i||/^(INFO|信息)[::]/.test(i))return!1;let o=i.split(",",1)[0]?.replace(/^"|"$/g,"").toLowerCase()??"";return o.includes("node")||o.includes("coze-bridge")}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{ox(this.pidFile,"utf8").trim()===String(process.pid)&&gv(this.pidFile)}catch{}})}};qo();ne();var $n=G("daemon.upstream-watchdog"),Dv=12e4,Rv=9e5,Cv=3e4;function Sd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Sd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",Dv),this.hardMs=e.hardMs??Sd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Rv),this.intervalMs=e.intervalMs??Sd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",Cv),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),$n.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&$n.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&$n.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,$n.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){$n.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,$n.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>$n.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var j=G("daemon"),kv="coze-bridge-daemon";async function ux(){let t=X();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&tl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:P=>Ze(P,t).logs,listAgentIds:()=>rs(t)});let e=new Ho({processTitle:kv}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await xo(),o=i??{};ts({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");try{let P=new Gn;o.frameworksCache=await P.detectAll(),j.info("refreshed frameworks_cache",{detected:Object.keys(o.frameworksCache)})}catch(P){j.warn("framework detection failed",{err:String(P)})}await Li(o);let c=new zo(new Mr),l=null,f=new po({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(P,H,K,ie)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(P,H,K,ie)}});await Pv(t,f);let h=new uo({paths:t,config:o,registry:f});l=h;let p,w,E=null,T={},_,v=null,I=null,S=null,R=new bn;function L(P,H){return R.enqueue(()=>C(P,H))}function y(){I||(I=new jo({isConnected:()=>c.isConnected(),forceReconnect:()=>S?L(S,{force:!0}):void 0,onFatal:P=>{if(process.env[$i]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:P});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:P}),process.exit(1)}})),I.start()}async function C(P,H){let K=P,ie=K?.privatecode;if(!ie)throw new D("IPC_BAD_REQUEST","/connect requires privatecode");let Ve=Ai(K.env),le=K.handshake_url,ue=K.frontier_url,St=lx(K.env,le,ue);if(S=K,!H?.force&&p===ie&&w===St){let ge=await Ov(t);return f.agents.size===0&&ge?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Ko(t,h).catch(Se=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Se)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ht=!!p&&p!==ie,Xt=w!==void 0&&w!==St,zt=ht||Xt,Qt=await kc({privatecode:ie,...le?{endpoint:le}:{},ppeOverride:Ve});if(zt){j.warn("connect config switched, resetting agents",{pcChanged:ht,envChanged:Xt,previousPc:p?Wo(p):"",nextPc:Wo(ie)});for(let ge of[...f.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),f.agents.delete(ge.agentId);f.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Mr,"connect switch").catch(()=>{})}E=Qt.deviceId,ts({deviceId:E,pid:process.pid}),Vc({patToken:ie,env:K.env}).catch(ge=>j.warn("coze-cli setup error (ignored)",{err:String(ge)}));let Gr=new Wi({handshake:Qt,privatecode:ie,...ue?{urlOverride:ue}:{},ppeOverride:Ve,getPatTokenForAgent:ge=>f.agents.get(ge)?.patToken});return await c.swap(Gr,"connect"),p=ie,w=St,T=Ve,_=le,K.mock_scenario!==void 0&&(f.setMockScenario(K.mock_scenario),j.info("mock scenario set",{scenario:K.mock_scenario})),v||(v=new Di({core:f,getDeviceId:()=>E??"",onTickEnd:()=>F.retryPending().catch(ge=>j.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:V})),v.start(),y(),zt&&Ko(t,h).catch(ge=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),Ki(ie,t).catch(ge=>j.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),j.info("/connect: WS established",{deviceId:E}),{ok:!0,note:"connected"}}f.registerExtension("_agent/create",async P=>h.createAgent(P.params)),f.registerExtension("_agent/health",async()=>({ok:!0}));let O={},B=new eo({agents:f.agents,disposeAndMarkDisconnected:async(P,H)=>{let K=f.agents.get(P);if(K){await h.cleanupOpenclawSessionProviders(K).catch(Ve=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(Ve)}));let ie=!0;try{await K.dispose(`disconnect: ${H}`)}catch(Ve){ie=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:P,err:String(Ve)}),K.status="error"}ie&&(K.status="disconnected",f.unregister(P),f.disconnectedAgents.add(P))}else f.disconnectedAgents.add(P)},detailSyncer:async P=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(P)},cleanupOpenclawProviders:async P=>{await h.cleanupOpenclawSessionProviders(P)},openclawRepair:async(P,H)=>{await h.openclawRepair(P,H)},isRuntimePendingPermission:P=>f.hasPendingPermissionFor(P)});f.registerExtension("_agent/listSkills",P=>B.listSkills(P.params)),f.registerExtension("_agent/addSkills",P=>B.addSkills(P.params)),f.registerExtension("_agent/removeSkills",P=>B.removeSkills(P.params)),f.registerExtension("_agent/getFileTree",P=>B.getFileTree(P.params)),f.registerExtension("_agent/getFileContent",P=>B.getFileContent(P.params)),f.registerExtension("_agent/update",P=>B.updateAgent(P.params)),f.registerExtension("_agent/disconnect",P=>B.disconnectAgent(P.params)),f.registerExtension("_agent/switchModel",P=>B.switchModel(P.params)),f.registerExtension("_agent/reset",P=>B.resetAgent(P.params)),f.registerExtension("_agent/repair",P=>B.repairAgent(P.params));let F=new as({paths:t,handlers:B,sendDetail:P=>f.sendRequest("_agent/detail",P)});O.ref=F;let V=async P=>{await Promise.allSettled(P.map(async H=>{try{await B.disconnectAgent({agentId:H.agentId,reason:`auth_failure: code=${H.code} ${H.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:H.agentId,code:H.code,message:H.message})}catch(K){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:H.agentId,err:String(K)})}}))};c.onConnect(({initial:P})=>{j.info("frontier upstream connected, triggering detail sync",{initial:P}),F.syncAll(P?"initial-connect":"reconnect").catch(H=>j.warn("detail sync top-level error (ignored)",{err:String(H)}))});let J=new go({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let P=f.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[$i]==="1"?"manual":"supervisor",agents:[...f.agents.keys()],deviceId:E??"",frameworksCache:o.frameworksCache??{},...P?{mockScenario:P}:{}}}},{method:"POST",path:"/pair",handler:async P=>{let H=P,K=H?.privatecode,ie=H?.pairing_code;if(!K||!ie)throw new D("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ve=Ai(H.env),le=H.handshake_url,ue=H.frontier_url,St=lx(H.env,le,ue),ht=!!p&&p!==K,Xt=w!==void 0&&w!==St,zt=ht||Xt,Qt=await kc({privatecode:K,...le?{endpoint:le}:{},ppeOverride:Ve});if(zt){j.warn("pair config switched, resetting agents",{pcChanged:ht,envChanged:Xt,previousPc:p?Wo(p):"",nextPc:Wo(K),previousEnvKey:w??"",nextEnvKey:St});for(let Se of[...f.agents.values()])await Se.dispose("pair config switch").catch(()=>{}),f.agents.delete(Se.agentId);f.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on pair config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Mr,"pair switch").catch(()=>{})}E=Qt.deviceId,ts({deviceId:E,pid:process.pid}),Vc({patToken:K,env:H.env}).catch(Se=>j.warn("coze-cli setup error (ignored)",{err:String(Se)}));let Gr=new Wi({handshake:Qt,privatecode:K,...ue?{urlOverride:ue}:{},ppeOverride:Ve,getPatTokenForAgent:Se=>f.agents.get(Se)?.patToken});await c.swap(Gr,"pair");try{let Se=new Gn;o.frameworksCache=await Se.detectAll(),await Li(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Se){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Se)})}let ge=Object.keys(o.frameworksCache??{});try{let Se=await f.sendRequest("_agent/pair",{pairCode:ie,patToken:K,frameworks:ge,_meta:{cozeDeviceId:E}});j.info("_agent/pair ok",{pairResult:Se}),p=K,w=St,T=Ve,_=le,H.mock_scenario!==void 0&&(f.setMockScenario(H.mock_scenario),j.info("mock scenario set",{scenario:H.mock_scenario})),Ki(K,t).catch(Re=>j.warn("writePatToken after /pair failed (ignored)",{err:String(Re)})),v||(v=new Di({core:f,getDeviceId:()=>E??"",onTickEnd:()=>F.retryPending().catch(Re=>j.warn("detailSync.retryPending failed (ignored)",{err:String(Re)})),onAuthFailures:V})),v.start(),y(),zt&&Ko(t,h).catch(Re=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(Re)}));let Vn;return H.agent_id&&(Vn=await Lv(H.agent_id,t,h,Re=>f.sendRequest("_agent/detail",Re),K).catch(Re=>(j.error("--agent-id ensureAgent failed",{agentId:H.agent_id,err:String(Re)}),{ok:!1,agentId:H.agent_id??"",note:String(Re)}))),{ok:!0,note:"paired with cloud",...Vn?{agent:Vn}:{}}}catch(Se){return j.error("_agent/pair failed",{err:String(Se)}),{ok:!1,note:`pair failed: ${String(Se)}`}}}},{method:"POST",path:"/connect",handler:P=>L(P)},{method:"POST",path:"/_agent/create",handler:async P=>{let H=P;return{ok:!0,result:await h.createAgent(H)}}},{method:"POST",path:"/agent/send",handler:async P=>{let H=P;if(!H?.agentId||!H?.sessionId||!H?.kind||!H?.path)throw new D("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new D("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let K=H;return await(K.groupFile?_f:wf)(K,{core:f,patToken:p,handshakeBase:_,ppeOverride:T})}catch(K){if(K instanceof D)return{ok:!1,code:K.code,message:K.message};throw K}}},{method:"POST",path:"/reload",handler:async P=>{let H=P?.agent_id,K=await f.reloadAgents(H);return j.info("IPC /reload: recycled agent subprocesses",{agentId:H??"(all)",recycled:K}),{ok:!0,recycled:K}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Q}=await J.start();try{await ix(t.libEntry,t)}catch(P){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(P)})}await f.start(),Ko(t,h).catch(P=>j.warn("auto-revive top-level error (ignored)",{err:String(P)})),ul().then(async()=>{let{probeAcpVersion:P}=await Promise.resolve().then(()=>(nn(),dl));for(let H of["claude-code","codex"]){let K=await P(H);K&&j.info("acp wrapper version",{framework:H,version:K})}}).catch(P=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(P)}));let ye=null,he={port:te,token:Q,core:f,ipc:J,shutdown(P){return ye||(j.info("daemon shutdown",{reason:P}),ye=(async()=>{v?.stop(),I?.stop(),await f.stop(P),await J.stop(),await e.release()})(),ye)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{he.shutdown(P).then(()=>process.exit(0))});return process.on("unhandledRejection",P=>{j.error("unhandledRejection",{reason:P instanceof Error?P.message:String(P),stack:P instanceof Error?P.stack:void 0})}),process.on("uncaughtException",P=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:P.message,stack:P.stack,name:P.name});try{process.stderr.write(`FATAL uncaughtException: ${P.stack??P.message}
106
+ `)}catch{}process.exit(1)}),j.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),Nv({cliSpawned:process.env[$i]==="1",readPatToken:()=>Fo(t),connect:L}).catch(P=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(P)})),he}async function Ov(t){return rs(t).length>0}function Wo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function lx(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function Pv(t,e){let r=rs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(rn(),os));for(let c of r){await o(c,t).catch(l=>j.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),j.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){j.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function Lv(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(rn(),os)),l=await c(t,e);if(l){j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let w={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}j.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let f=await i({_meta:{cozeAgentId:t}});if(!f.framework)throw new D("AGENT_NOT_FOUND",`agent ${t} \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}:{},...o?{patToken:o}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await r.createAgent(h);let p=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function Ko(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(rn(),os));j.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let f of i){let h;try{h=await o(f,t)}catch(p){j.warn("auto-revive: load config failed (skipping)",{agentId:f,err:String(p)}),l+=1;continue}if(!h){l+=1;continue}if(h.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:f,disconnectedAt:h.disconnectedAt}),l+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:f,framework:h.framework});let p=Mv(h);await e.createAgent({agentId:h.agentId,framework:h.framework,...h.cozeIdentity?{cozeIdentity:h.cozeIdentity}:{},...h.model?{model:h.model}:{},...p?{_meta:p}:{}},{revive:!0}),c+=1}catch(p){j.warn("auto-revive: createAgent failed (skipping)",{agentId:f,framework:h.framework,err:String(p)}),l+=1}}return j.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function Nv(t){let e=t.logger??j;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Mv(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}qo();Ce();import{readFile as fx}from"node:fs/promises";var Yt=class{paths;constructor(e){this.paths=e??X()}async probe(e=1e3){let r=await $o(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:zv(i)}}}async request(e){let r=await $o(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let f=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),h=await f.text();return{status:f.status,body:Bv(h)}}finally{clearTimeout(l)}}};async function $o(t){try{let[e,r]=await Promise.all([fx(t.portFile,"utf8"),fx(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=r.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function Bv(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function zv(t){return t instanceof Error?t.message:String(t)}yn();ne();Ce();function Sn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let f of e){if(c===f){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${f}=`)){i=c.slice(f.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}nn();import{chmod as Fv,copyFile as hx,mkdir as px,readFile as Vo,rename as xx,rm as Id,stat as gx,writeFile as Uv}from"node:fs/promises";import{homedir as m3}from"node:os";import{dirname as Gv,join as Br,resolve as Ad,sep as Vi}from"node:path";import{fileURLToPath as Hv}from"node:url";yn();ne();Ce();var Td=G("dist-install");function qv(t){let e=Hv(t),r=Gv(e),i=`${Vi}src${Vi}`;if(r.includes(i)||r.endsWith(`${Vi}src${Vi}cli`))return null;let o=Ad(r,"index.js"),c=Ad(r,"..","package.json");return{dist:o,pkgJson:c}}async function Rd(t={}){let e=t.paths??X(),r=qv(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let T=JSON.parse(await Vo(o,"utf8"));c=T.version??"unknown",l=T.dependencies??{}}catch(T){return Td.warn("cannot read source package.json,skip dist install",{err:String(T)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(T)}`}}let f=$r.map(T=>`${T}@${l[T]??"latest"}`),h=await xo(e.configFile)??{},p=h.libVersion,w=await Vo(e.libEntry).then(()=>!0).catch(()=>!1),E=p===c;if(E&&w&&await Dd(e))return{kind:"already-current",libVersion:c};if(!E||!w){await px(e.libDir,{recursive:!0}),await hx(i,e.libEntry),await hx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let T=Ad(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
107
+ `;await Vo(T,"utf8").catch(()=>null)!==_&&await Uv(T,_)}return(!E||!await Dd(e))&&await(t.installWrappers??jv)(e,f),h.libVersion=c,await Li(h,e.configFile),Td.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),E&&w?{kind:"already-current",libVersion:c}:p?{kind:"version-changed",fromVersion:p,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Dd(t){for(let e of $r){let r=Br(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await gx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function jv(t,e){await $v(t.installLock,async()=>{if(await Dd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Vi}.staging-${process.pid}-${r}`,o=Br(i,"node_modules"),c=Br(t.libDir,"node_modules");try{await px(i,{recursive:!0}),await Wv(e,i),await Kv(o);let l=`${c}.trash-${r}`;await xx(c,l).catch(()=>{}),await xx(o,c),await Id(l,{recursive:!0,force:!0}).catch(()=>{}),Td.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Id(i,{recursive:!0,force:!0}).catch(()=>{})}})}function Wv(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=lt("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",h=>{l.length<8192&&(l+=h.toString("utf8"))});let f=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(f),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(f),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${l.trim().slice(0,2e3)}`))})})}async function Kv(t){for(let e of $r){let r=Br(t,...e.split("/")),i=JSON.parse(await Vo(Br(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Br(t,".bin",o),l=await gx(c);process.platform!=="win32"&&!(l.mode&73)&&await Fv(c,l.mode|73).catch(()=>{})}}async function $v(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Id(t,{force:!0}).catch(()=>{})}}ga();ne();Ce();import{closeSync as _x,fstatSync as yx,openSync as bx,readFileSync as Vv,readSync as Jv,readdirSync as Zv,statSync as Yv}from"node:fs";import{join as Jo}from"node:path";var Xv=new Set(["debug","info","warn","error"]);function Ex(t){let e=t,r=Sn(e,"--agent-id");e=r.rest;let i=Sn(e,"--date");e=i.rest;let o=Sn(e,"-n","--lines");e=o.rest;let c=Sn(e,"--level");e=c.rest;let l=Sn(e,"--grep");e=l.rest;let f=o.value===void 0?200:Number(o.value),h=Number.isInteger(f)&&f>=0?f:200,p=c.value&&Xv.has(c.value)?c.value:void 0,w={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(w.agentId=r.value),i.value&&(w.date=i.value),p&&(w.level=p),l.value&&(w.grep=l.value),w}function Qv(t,e){return t.agentId?Jo(Ze(t.agentId,e).logs,Xn("agent",t.date)):Jo(e.bridgeLogsDir,Xn("bridge",t.date))}function e1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function t1(t,e){let r;try{r=Zv(t)}catch{return[]}let i=[];for(let o of r){let c=pa(o,e);if(!c)continue;let l=0;try{l=Yv(Jo(t,o)).size}catch{}i.push({file:Jo(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function vx(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let r;try{r=JSON.parse(t).level}catch{return!0}if(typeof r=="string"&&!il(r,e.level))return!1}return!0}var mx={debug:"90",info:"36",warn:"33",error:"31"},n1=new Set(["ts","level","module","msg"]);function r1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Sx(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=r1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&mx[o]&&(c=`\x1B[${mx[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",f=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([p])=>!n1.has(p)).map(([p,w])=>` ${p}=${typeof w=="string"?w:JSON.stringify(w)}`).join("");return`${i} ${c} ${l} ${f}${h}`}function i1(t,e,r){let c=Vv(t,"utf8").split(`
108
+ `).filter(l=>l.length>0).filter(l=>vx(l,{level:e.level,grep:e.grep}));for(let l of e1(c,e.lines))process.stdout.write(`${Sx(l,{raw:e.raw,color:r})}
109
+ `)}async function Ix(t,e){let r=e.paths??X(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,f=t.agentId?"agent":"bridge",h=t1(l,f);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
110
+ `),1;for(let p of h)process.stdout.write(`${p.date} ${(p.size/1024).toFixed(1)}KB ${p.file}
111
+ `);return 0}let o=t.date??An(new Date),c=Qv({agentId:t.agentId,date:o},r);try{i1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
112
112
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
113
113
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
114
- `),1}return t.follow&&await iv(c,t,i),0}var nv=500;function rv(t){try{let e=mx(t,"r");try{return gx(e).size}finally{px(e)}}catch{return 0}}async function iv(t,e,r){let i=rv(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let f="";try{let h=mx(t,"r");try{let x=gx(h).size;if(x>i){let m=Buffer.allocUnsafe(x-i),g=$1(h,m,0,m.length,i);f=m.subarray(0,g).toString("utf8"),i+=g}}finally{px(h)}}catch{}if(f){let h=(o+f).split(`
115
- `);o=h.pop()??"";for(let x of h)x.length>0&&_x(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Ex(x,{raw:e.raw,color:r})}
116
- `)}await new Promise(h=>setTimeout(h,nv))}}finally{process.off("SIGINT",d)}}import{basename as sv,resolve as ov}from"node:path";ke();var av=9e4,cv={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function dv(t){return cv[t]??1}async function vx(t,e={}){let r=e.paths??Y();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
114
+ `),1}return t.follow&&await a1(c,t,i),0}var s1=500;function o1(t){try{let e=bx(t,"r");try{return yx(e).size}finally{_x(e)}}catch{return 0}}async function a1(t,e,r){let i=o1(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let f="";try{let h=bx(t,"r");try{let p=yx(h).size;if(p>i){let w=Buffer.allocUnsafe(p-i),E=Jv(h,w,0,w.length,i);f=w.subarray(0,E).toString("utf8"),i+=E}}finally{_x(h)}}catch{}if(f){let h=(o+f).split(`
115
+ `);o=h.pop()??"";for(let p of h)p.length>0&&vx(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${Sx(p,{raw:e.raw,color:r})}
116
+ `)}await new Promise(h=>setTimeout(h,s1))}}finally{process.off("SIGINT",l)}}import{basename as c1,resolve as d1}from"node:path";Ce();var l1=9e4,u1={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function f1(t){return u1[t]??1}async function Ax(t,e={}){let r=e.paths??X();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
117
117
  `),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
118
- `),3;let i=await Wo(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
119
- `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:ov(process.cwd(),t.path),...t.caption?{caption:t.caption}:{},...t.name?{name:t.name}:{},...t.groupFile?{groupFile:!0}:{},...t.mimeType?{mimeType:t.mimeType}:{}},c;try{c=await lv(i,"/agent/send",o,av)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
118
+ `),3;let i=await $o(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
119
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:d1(process.cwd(),t.path),...t.caption?{caption:t.caption}:{},...t.name?{name:t.name}:{},...t.groupFile?{groupFile:!0}:{},...t.mimeType?{mimeType:t.mimeType}:{}},c;try{c=await h1(i,"/agent/send",o,l1)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
120
120
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
121
- `),dv(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
122
- `);else{let d=t.name??sv(o.path);if(t.groupFile){let f=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${f})
123
- `)}else process.stdout.write(`Sent ${t.kind} ${d} (${fv(c.bytes)})
124
- `)}return 0}async function lv(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),f=await d.text(),h=f?JSON.parse(f):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${f.slice(0,200)}`}}finally{clearTimeout(c)}}function fv(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Ox=G("cli");function Ue(t,e){let{value:r,rest:i}=bn(t,e);return{value:r,rest:i}}function Qo(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
125
- `)}function Nv(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:R}=Ue(e.slice(1),"--agent-id");return R?{mode:"reload",agentId:R}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return Mv(e.slice(1));if(e[0]==="log")return{mode:"log",...yx(e.slice(1))};if(e[0]==="connect")return Bv(e.slice(1));if(e.includes("--status"))return Qo("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return Qo("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return Qo("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return Qo("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=Ue(r,"--pat-token");r=o;let{value:c,rest:d}=Ue(r,"--pair-code");r=d;let{value:f,rest:h}=Ue(r,"--env");r=h;let{value:x,rest:m}=Ue(r,"--handshake-url");r=m;let{value:g,rest:A}=Ue(r,"--frontier-url");r=A;let{value:w,rest:E}=Ue(r,"--mock-scenario");r=E;let{value:I}=Ue(r,"--agent-id");if(!i||!c)return{mode:"help"};let S={mode:"pair",privatecode:i,pairingCode:c};return f&&(S.env=f),x&&(S.handshakeUrl=x),g&&(S.frontierUrl=g),w&&(S.mockScenario=w),I&&(S.agentId=I),S}function Mv(t){let e=t[0],r=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!r||r.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=Ue(i,"--caption");i=c;let{value:d,rest:f}=Ue(i,"--name");i=f;let{value:h,rest:x}=Ue(i,"--agent-id");i=x;let{value:m,rest:g}=Ue(i,"--session-id");i=g;let{value:A,rest:w}=Ue(i,"--mime");i=w;let E=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let I=i.includes("--json"),S={mode:"send",kind:e,path:r,json:I};return o&&(S.caption=o),d&&(S.name=d),h&&(S.agentId=h),m&&(S.sessionId=m),E&&(S.groupFile=!0),A&&(S.mimeType=A),S}function Bv(t){let e=t,{value:r,rest:i}=Ue(e,"--pat-token");e=i;let{value:o,rest:c}=Ue(e,"--env");e=c;let{value:d,rest:f}=Ue(e,"--handshake-url");e=f;let{value:h,rest:x}=Ue(e,"--frontier-url");e=x;let{value:m,rest:g}=Ue(e,"--mock-scenario");e=g;let A={mode:"connect"};return r&&(A.privatecode=r),o&&(A.env=o),d&&(A.handshakeUrl=d),h&&(A.frontierUrl=h),m&&(A.mockScenario=m),A}var zv=`
121
+ `),f1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
122
+ `);else{let l=t.name??c1(o.path);if(t.groupFile){let f=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${f})
123
+ `)}else process.stdout.write(`Sent ${t.kind} ${l} (${x1(c.bytes)})
124
+ `)}return 0}async function h1(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let l=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),f=await l.text(),h=f?JSON.parse(f):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${f.slice(0,200)}`}}finally{clearTimeout(c)}}function x1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Nx=G("cli");function Ue(t,e){let{value:r,rest:i}=Sn(t,e);return{value:r,rest:i}}function ta(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
125
+ `)}function z1(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:R}=Ue(e.slice(1),"--agent-id");return R?{mode:"reload",agentId:R}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return F1(e.slice(1));if(e[0]==="log")return{mode:"log",...Ex(e.slice(1))};if(e[0]==="connect")return U1(e.slice(1));if(e.includes("--status"))return ta("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return ta("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return ta("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return ta("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=Ue(r,"--pat-token");r=o;let{value:c,rest:l}=Ue(r,"--pair-code");r=l;let{value:f,rest:h}=Ue(r,"--env");r=h;let{value:p,rest:w}=Ue(r,"--handshake-url");r=w;let{value:E,rest:T}=Ue(r,"--frontier-url");r=T;let{value:_,rest:v}=Ue(r,"--mock-scenario");r=v;let{value:I}=Ue(r,"--agent-id");if(!i||!c)return{mode:"help"};let S={mode:"pair",privatecode:i,pairingCode:c};return f&&(S.env=f),p&&(S.handshakeUrl=p),E&&(S.frontierUrl=E),_&&(S.mockScenario=_),I&&(S.agentId=I),S}function F1(t){let e=t[0],r=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!r||r.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=Ue(i,"--caption");i=c;let{value:l,rest:f}=Ue(i,"--name");i=f;let{value:h,rest:p}=Ue(i,"--agent-id");i=p;let{value:w,rest:E}=Ue(i,"--session-id");i=E;let{value:T,rest:_}=Ue(i,"--mime");i=_;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let I=i.includes("--json"),S={mode:"send",kind:e,path:r,json:I};return o&&(S.caption=o),l&&(S.name=l),h&&(S.agentId=h),w&&(S.sessionId=w),v&&(S.groupFile=!0),T&&(S.mimeType=T),S}function U1(t){let e=t,{value:r,rest:i}=Ue(e,"--pat-token");e=i;let{value:o,rest:c}=Ue(e,"--env");e=c;let{value:l,rest:f}=Ue(e,"--handshake-url");e=f;let{value:h,rest:p}=Ue(e,"--frontier-url");e=p;let{value:w,rest:E}=Ue(e,"--mock-scenario");e=E;let T={mode:"connect"};return r&&(T.privatecode=r),o&&(T.env=o),l&&(T.handshakeUrl=l),h&&(T.frontierUrl=h),w&&(T.mockScenario=w),T}var G1=`
126
126
  coze-bridge - local bridge daemon for cloud Agent Service
127
127
 
128
128
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -201,56 +201,56 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
201
201
 
202
202
  Internal:
203
203
  <node> <entry> --daemon daemon mode (OS supervisor only)
204
- `.trimStart();async function Px(t=process.argv,e={}){let r=Nv(t);switch(r.mode){case"help":return process.stdout.write(zv),0;case"version":return process.stdout.write(`${Er}
205
- `),0;case"daemon":{try{await cx()}catch(i){return Ox.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return Fv(e);case"stop":return Nx(e);case"reload":return jv(r.agentId,e);case"log":return bx(r,e);case"update":return Uv(e);case"purge":return Hv(e);case"service-install":return qv(e);case"service-uninstall":return Wv(e);case"pair":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),$v(r.privatecode,r.pairingCode,e,i,r.agentId)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),Kv(r.privatecode,e,i)}case"send":return vx({kind:r.kind,path:r.path,...r.agentId?{agentId:r.agentId}:{},...r.sessionId?{sessionId:r.sessionId}:{},...r.caption?{caption:r.caption}:{},...r.name?{name:r.name}:{},...r.groupFile?{groupFile:!0}:{},...r.mimeType?{mimeType:r.mimeType}:{},json:r.json},e)}}async function Lx(t){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(t.pidFile).catch(()=>{}),e(t.portFile).catch(()=>{}),e(t.tokenFile).catch(()=>{})])}async function Fv(t){let e=t.paths??Y(),r=new Zt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
206
- `),1;if(i.kind==="stale")return await Lx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
204
+ `.trimStart();async function Mx(t=process.argv,e={}){let r=z1(t);switch(r.mode){case"help":return process.stdout.write(G1),0;case"version":return process.stdout.write(`${vr}
205
+ `),0;case"daemon":{try{await ux()}catch(i){return Nx.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return H1(e);case"stop":return zx(e);case"reload":return W1(r.agentId,e);case"log":return Ix(r,e);case"update":return q1(e);case"purge":return K1(e);case"service-install":return $1(e);case"service-uninstall":return V1(e);case"pair":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),J1(r.privatecode,r.pairingCode,e,i,r.agentId)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),Z1(r.privatecode,e,i)}case"send":return Ax({kind:r.kind,path:r.path,...r.agentId?{agentId:r.agentId}:{},...r.sessionId?{sessionId:r.sessionId}:{},...r.caption?{caption:r.caption}:{},...r.name?{name:r.name}:{},...r.groupFile?{groupFile:!0}:{},...r.mimeType?{mimeType:r.mimeType}:{},json:r.json},e)}}async function Bx(t){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(t.pidFile).catch(()=>{}),e(t.portFile).catch(()=>{}),e(t.tokenFile).catch(()=>{})])}async function H1(t){let e=t.paths??X(),r=new Yt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
206
+ `),1;if(i.kind==="stale")return await Bx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
207
207
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
208
208
  ${JSON.stringify(o.body,null,2)}
209
- `),0}async function Nx(t){let e=t.paths??Y(),r=new Zt(e),i=await Zi(t),o=!1;if(i)try{await i.uninstall(),o=!0}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
209
+ `),0}async function zx(t){let e=t.paths??X(),r=new Yt(e),i=await Zi(t),o=!1;if(i)try{await i.uninstall(),o=!0}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
210
210
  `)}let c=await r.probe();if(c.kind==="not-running")return process.stdout.write(o?`coze-bridge: stopped
211
211
  `:`coze-bridge: not running
212
- `),0;if(c.kind==="stale")return await Lx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
212
+ `),0;if(c.kind==="stale")return await Bx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
213
213
  `),0;try{return await r.request({method:"POST",path:"/shutdown"}),process.stdout.write(`coze-bridge: stopped
214
- `),0}catch(d){return(await r.probe()).kind!=="connected"?(process.stdout.write(`coze-bridge: stopped
215
- `),0):(process.stdout.write(`coze-bridge: stop failed: ${String(d)}
216
- `),1)}}async function Uv(t){return await Nx(t),(t.spawnNpx??Gv)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function Gv(t){return new Promise(e=>{let r=at("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
217
- `),e(1)})})}async function jv(t,e){let r=new Zt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
214
+ `),0}catch(l){return(await r.probe()).kind!=="connected"?(process.stdout.write(`coze-bridge: stopped
215
+ `),0):(process.stdout.write(`coze-bridge: stop failed: ${String(l)}
216
+ `),1)}}async function q1(t){return await zx(t),(t.spawnNpx??j1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function j1(t){return new Promise(e=>{let r=lt("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
217
+ `),e(1)})})}async function W1(t,e){let r=new Yt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
218
218
  `),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
219
219
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
220
220
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
221
221
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
222
- `),1}}async function Zi(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:f=>c.install(d,f),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Dx(),Cx)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Mx(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??ox,o=t.waitTimeoutMs??15e3,c=t.sleep??Vv,d=t.paths??Y(),f=await Zi(t);if(f&&(f.platform==="darwin"||f.platform==="linux")){try{await f.install({activate:!0});let h=await kx(e,o,c);if(h.kind==="connected")return h;Hr(d.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(h){Hr(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}await f.uninstall().catch(()=>{}),await Zv(d.pidFile,c)}else f&&await f.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
222
+ `),1}}async function Zi(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:f=>c.install(l,f),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Px(),Ox)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Fx(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??dx,o=t.waitTimeoutMs??15e3,c=t.sleep??X1,l=t.paths??X(),f=await Zi(t);if(f&&(f.platform==="darwin"||f.platform==="linux")){try{await f.install({activate:!0});let h=await Lx(e,o,c);if(h.kind==="connected")return h;Wr(l.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(h){Wr(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}await f.uninstall().catch(()=>{}),await Y1(l.pidFile,c)}else f&&await f.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
223
223
  `));return process.stdout.write(`coze-bridge: starting daemon...
224
- `),await i({paths:t.paths}),kx(e,o,c)}async function Hv(t){let e=new Zt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
225
- `);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
226
- `)}await new Promise(d=>setTimeout(d,500))}let i=await Zi(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
227
- `)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
228
- `)}let o=t.paths??Y(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
229
- `)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
224
+ `),await i({paths:t.paths}),Lx(e,o,c)}async function K1(t){let e=new Yt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
225
+ `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
226
+ `)}await new Promise(l=>setTimeout(l,500))}let i=await Zi(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
227
+ `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
228
+ `)}let o=t.paths??X(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
229
+ `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
230
230
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
231
- `),0}async function qv(t){let e=await Zi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
231
+ `),0}async function $1(t){let e=await Zi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
232
232
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
233
233
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
234
- `),1}}async function Wv(t){let e=await Zi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
234
+ `),1}}async function V1(t){let e=await Zi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
235
235
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
236
- `),1}}async function $v(t,e,r,i={},o){let c=new Zt(r.paths),d=r.paths??Y();if(await jc(d).catch(x=>Hr(d.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(x)})),!r.skipDistInstall){let x=await Td({paths:r.paths});x.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${x.fromVersion} \u2192 ${x.toVersion}
237
- `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(g=>setTimeout(g,500)))):x.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${x.libVersion}
238
- `)}let f=await Mx(r,c);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
239
- `),1;let h={privatecode:t,pairing_code:e};i.env&&(h.env=i.env),i.handshakeUrl&&(h.handshake_url=i.handshakeUrl),i.frontierUrl&&(h.frontier_url=i.frontierUrl),i.mockScenario&&(h.mock_scenario=i.mockScenario),o&&(h.agent_id=o);try{let x=await c.request({method:"POST",path:"/pair",body:h,timeoutMs:35e3});if(x.status===200&&x.body?.ok){let m=x.body.agent;return m&&!m.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${m.agentId}): ${m.note}
236
+ `),1}}async function J1(t,e,r,i={},o){let c=new Yt(r.paths),l=r.paths??X();if(await jc(l).catch(p=>Wr(l.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(p)})),!r.skipDistInstall){let p=await Rd({paths:r.paths});p.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${p.fromVersion} \u2192 ${p.toVersion}
237
+ `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(E=>setTimeout(E,500)))):p.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${p.libVersion}
238
+ `)}let f=await Fx(r,c);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
239
+ `),1;let h={privatecode:t,pairing_code:e};i.env&&(h.env=i.env),i.handshakeUrl&&(h.handshake_url=i.handshakeUrl),i.frontierUrl&&(h.frontier_url=i.frontierUrl),i.mockScenario&&(h.mock_scenario=i.mockScenario),o&&(h.agent_id=o);try{let p=await c.request({method:"POST",path:"/pair",body:h,timeoutMs:35e3});if(p.status===200&&p.body?.ok){let w=p.body.agent;return w&&!w.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${w.agentId}): ${w.note}
240
240
  `),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
241
- `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(x.body)}
242
- `),1}catch(x){return process.stderr.write(`coze-bridge: pair failed: ${String(x)}
243
- `),1}}async function Kv(t,e,r={}){let i=e.paths??Y(),o=t??await Bo(i);if(!o)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let c=new Zt(e.paths);if(await jc(i).catch(h=>Hr(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(h)})),!e.skipDistInstall){let h=await Td({paths:e.paths});h.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${h.fromVersion} \u2192 ${h.toVersion}
244
- `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(m=>setTimeout(m,500)))):h.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${h.libVersion}
245
- `)}let d=await Mx(e,c);if(d.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${d.kind}
241
+ `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(p.body)}
242
+ `),1}catch(p){return process.stderr.write(`coze-bridge: pair failed: ${String(p)}
243
+ `),1}}async function Z1(t,e,r={}){let i=e.paths??X(),o=t??await Fo(i);if(!o)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let c=new Yt(e.paths);if(await jc(i).catch(h=>Wr(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(h)})),!e.skipDistInstall){let h=await Rd({paths:e.paths});h.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${h.fromVersion} \u2192 ${h.toVersion}
244
+ `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(w=>setTimeout(w,500)))):h.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${h.libVersion}
245
+ `)}let l=await Fx(e,c);if(l.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${l.kind}
246
246
  `),1;let f={privatecode:o};r.env&&(f.env=r.env),r.handshakeUrl&&(f.handshake_url=r.handshakeUrl),r.frontierUrl&&(f.frontier_url=r.frontierUrl),r.mockScenario&&(f.mock_scenario=r.mockScenario);try{let h=await c.request({method:"POST",path:"/connect",body:f,timeoutMs:35e3});return h.status===200&&h.body?.ok?(process.stdout.write(`coze-bridge: connected (${h.body.note??"ok"})
247
- `),await qi(o,i).catch(x=>Ox.warn("writePatToken after connect failed (ignored)",{err:String(x)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(h.body)}
247
+ `),await Ki(o,i).catch(p=>Nx.warn("writePatToken after connect failed (ignored)",{err:String(p)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(h.body)}
248
248
  `),1)}catch(h){return process.stderr.write(`coze-bridge: connect failed: ${String(h)}
249
- `),1}}async function kx(t,e,r){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await r(200)}return t.probe(500)}async function Zv(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let f=Number.parseInt(d.trim(),10);if(!Number.isFinite(f)||f<=0||!Fo(f))return;await e(i)}}function Vv(t){return new Promise(e=>setTimeout(e,t))}ne();function Jv(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let r=Number(e[1]),i=Number(e[2]??0);return r<18||r===18&&i<4?"fatal":r<20?"warn":"ok"}function Bx(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=Jv(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
249
+ `),1}}async function Lx(t,e,r){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await r(200)}return t.probe(500)}async function Y1(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let l;try{l=await o(t,"utf8")}catch{return}let f=Number.parseInt(l.trim(),10);if(!Number.isFinite(f)||f<=0||!Go(f))return;await e(i)}}function X1(t){return new Promise(e=>setTimeout(e,t))}ne();function Q1(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let r=Number(e[1]),i=Number(e[2]??0);return r<18||r===18&&i<4?"fatal":r<20?"warn":"ok"}function Ux(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=Q1(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
250
250
  `),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
251
251
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
252
252
  npx -y coze-bridge@latest stop
253
253
  npx -y coze-bridge@latest connect
254
254
 
255
- `)}Bx();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&tl("warn");Px(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
255
+ `)}Ux();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&nl("warn");Mx(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
256
256
  `),process.exit(1)});